diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
| commit | e0024d9ea688ee91a77abc0e28c5ea24b13ca67d (patch) | |
| tree | a4e29bd919cbeccf2689e81a5d52bfc02f2a8b77 /dev/ZKAKit/NetworkKit | |
| parent | 36a3600ff7fc65a63b7386b7a680dbe8e647bd8f (diff) | |
IMP: Refactor whole source code to make it even.
- That is because previously the source was both in lowercase and lettercase.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/NetworkKit')
| -rw-r--r-- | dev/ZKAKit/NetworkKit/IP.h | 83 | ||||
| -rw-r--r-- | dev/ZKAKit/NetworkKit/IPC.h | 91 | ||||
| -rw-r--r-- | dev/ZKAKit/NetworkKit/LTE.h | 16 | ||||
| -rw-r--r-- | dev/ZKAKit/NetworkKit/MAC.h | 29 | ||||
| -rw-r--r-- | dev/ZKAKit/NetworkKit/NetworkDevice.h | 83 | ||||
| -rw-r--r-- | dev/ZKAKit/NetworkKit/NetworkDevice.inl | 32 |
6 files changed, 334 insertions, 0 deletions
diff --git a/dev/ZKAKit/NetworkKit/IP.h b/dev/ZKAKit/NetworkKit/IP.h new file mode 100644 index 00000000..6853ad6a --- /dev/null +++ b/dev/ZKAKit/NetworkKit/IP.h @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include <KernelKit/DebugOutput.h> +#include <NewKit/Defines.h> +#include <NewKit/Ref.h> +#include <NewKit/String.h> + +namespace Kernel +{ + class RawIPAddress6; + class RawIPAddress; + class IPFactory; + + class RawIPAddress final + { + private: + explicit RawIPAddress(char bytes[4]); + ~RawIPAddress() = default; + + RawIPAddress& operator=(const RawIPAddress&) = delete; + RawIPAddress(const RawIPAddress&) = default; + + public: + char* Address(); + + char& operator[](const Size& index); + + bool operator==(const RawIPAddress& ipv6); + bool operator!=(const RawIPAddress& ipv6); + + private: + char fAddr[4]; + + friend IPFactory; // it is the one creating these addresses, thus this + // is why the constructors are private. + }; + + /** + * @brief IPv6 address. + */ + class RawIPAddress6 final + { + private: + explicit RawIPAddress6(char Bytes[8]); + ~RawIPAddress6() = default; + + RawIPAddress6& operator=(const RawIPAddress6&) = delete; + RawIPAddress6(const RawIPAddress6&) = default; + + public: + char* Address() + { + return fAddr; + } + + char& operator[](const Size& index); + + bool operator==(const RawIPAddress6& ipv6); + bool operator!=(const RawIPAddress6& ipv6); + + private: + char fAddr[8]; + + friend IPFactory; + }; + + /** + * @brief IP Creation helpers + */ + class IPFactory final + { + public: + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6>& ipv6); + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress>& ipv4); + static bool IpCheckVersion4(const Char* ip); + }; +} // namespace Kernel diff --git a/dev/ZKAKit/NetworkKit/IPC.h b/dev/ZKAKit/NetworkKit/IPC.h new file mode 100644 index 00000000..a2fa2ead --- /dev/null +++ b/dev/ZKAKit/NetworkKit/IPC.h @@ -0,0 +1,91 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co.. + + File: IPC.h. + Purpose: IPC protocol. + +------------------------------------------- */ + +#ifndef _INC_IPC_ENDPOINT_H_ +#define _INC_IPC_ENDPOINT_H_ + +#include <NewKit/Defines.h> +#include <NewKit/String.h> +#include <HintKit/CompilerHint.h> +#include <CompressKit/RLE.h> + +/// @file IPC.h +/// @brief IPC EP protocol. + +/// IA separator. +#define cXPCOMRemoteSeparator ":" + +/// Interchange address, consists of PID:TEAM. +#define cXPCOMRemoteInvalid "00:00" + +#define cXPCOMHeaderMagic (0x4950434) + +namespace Kernel +{ + struct IPC_ADDRESS_STRUCT; + struct IPC_MESSAGE_STRUCT; + + /// @brief 128-bit IPC address. + struct PACKED IPC_ADDRESS_STRUCT final + { + UInt64 UserProcessID; + UInt64 UserProcessTeam; + + //////////////////////////////////// + // some operators. + //////////////////////////////////// + + bool operator==(const IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam; + } + + bool operator==(IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam; + } + }; + + typedef struct IPC_ADDRESS_STRUCT IPCEPAddressKind; + + enum + { + eIPCEPLittleEndian = 0, + eIPCEPBigEndian = 1, + eIPCEPMixedEndian = 2, + }; + + constexpr auto cXPCOMMsgSize = 6094U; + + /// @brief IPC connection header, message cannot be greater than 6K. + typedef struct IPC_MESSAGE_STRUCT final + { + UInt32 IpcHeaderMagic; // cRemoteHeaderMagic + UInt8 IpcEndianess; // 0 : LE, 1 : BE + SizeT IpcPacketSize; + IPCEPAddressKind IpcFrom; + IPCEPAddressKind IpcTo; + UInt32 IpcCRC32; + UInt32 IpcMsg; + UInt32 IpcMsgSz; + UInt8 IpcData[cXPCOMMsgSize]; + } PACKED IPC_MESSAGE_STRUCT; + + /// @brief Sanitize packet function + /// @retval true packet is correct. + /// @retval false packet is incorrect and process has crashed. + Bool ipc_sanitize_packet(_Input IPC_MESSAGE_STRUCT* pckt_in); + + /// @brief Construct packet function + /// @retval true packet is correct. + /// @retval false packet is incorrect and process has crashed. + Bool ipc_construct_packet(_Output IPC_MESSAGE_STRUCT** pckt_in); +} // namespace Kernel + +#endif // _INC_IPC_ENDPOINT_H_ diff --git a/dev/ZKAKit/NetworkKit/LTE.h b/dev/ZKAKit/NetworkKit/LTE.h new file mode 100644 index 00000000..3be9f1bd --- /dev/null +++ b/dev/ZKAKit/NetworkKit/LTE.h @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co.. + + File: LTE.h. + Purpose: LTE protocol classes. + +------------------------------------------- */ + +#ifndef _INC_NETWORK_LTE_H_ +#define _INC_NETWORK_LTE_H_ + +#include <NewKit/Defines.h> +#include <NewKit/String.h> + +#endif // ifndef _INC_NETWORK_LTE_H_ diff --git a/dev/ZKAKit/NetworkKit/MAC.h b/dev/ZKAKit/NetworkKit/MAC.h new file mode 100644 index 00000000..8794c068 --- /dev/null +++ b/dev/ZKAKit/NetworkKit/MAC.h @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Array.h> +#include <NewKit/Defines.h> +#include <NewKit/String.h> + +namespace Kernel +{ + class MacAddressGetter; + + /// \brief This retrieves the MAC address of the device. + /// \note Listens for the current NIC. + class MacAddressGetter final + { + public: + explicit MacAddressGetter() = default; + + public: + StringView& AsString(); + Array<WideChar, 12>& AsBytes(); + }; + +} // namespace Kernel diff --git a/dev/ZKAKit/NetworkKit/NetworkDevice.h b/dev/ZKAKit/NetworkKit/NetworkDevice.h new file mode 100644 index 00000000..d043d0d2 --- /dev/null +++ b/dev/ZKAKit/NetworkKit/NetworkDevice.h @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __INC_NETWORK_DEVICE_H__ +#define __INC_NETWORK_DEVICE_H__ + +#include <KernelKit/DeviceMgr.h> +#include <NetworkKit/IP.h> + +/// @note Can either work with: Ethernet, GPRS, WiFi + +namespace Kernel +{ + struct NetworkDeviceCommand; + class NetworkDevice; + + /** + * \brief Network device interface, establishes a connection to the NIC. + */ + class NetworkDevice final : public DeviceInterface<NetworkDeviceCommand> + { + public: + NetworkDevice(void (*out)(NetworkDeviceCommand), + void (*in)(NetworkDeviceCommand), + void (*onCleanup)(void) = nullptr); + + ~NetworkDevice() override; + + public: + NetworkDevice& operator=(const NetworkDevice&) = default; + NetworkDevice(const NetworkDevice&) = default; + + public: + const Char* Name() const override; + Boolean Name(const Char* newStr); + + private: + static constexpr auto cNetworkNameLen = 512; + + Void (*fCleanup)(void); + Char fNetworkName[cNetworkNameLen]; + }; + + struct NetworkDeviceCommand final + { + UInt32 CommandName; + UInt32 CommandType; + UInt32 CommandFlags; + VoidPtr CommandBuffer; + SizeT CommandSizeBuffer; + }; + + /// @brief TCP device. + using TCPNetworkDevice = NetworkDevice; + + /// @brief UDP device. + using UDPNetworkDevice = NetworkDevice; + + /// @brief PPP device. + using PPPNetworkDevice = NetworkDevice; + + /// @brief IPC device. + using IPCEPNetworkDevice = NetworkDevice; + + /// @brief GRPS device. + using GPRSNetworkDevice = NetworkDevice; + + /// @brief GSM device. + using GSMNetworkDevice = NetworkDevice; + + /// @brief Bluetooth device. + using BTNetworkDevice = NetworkDevice; + + /// @brief LTE device. + using LTENetworkDevice = NetworkDevice; +} // namespace Kernel + +#include <NetworkKit/NetworkDevice.inl> + +#endif // !__INC_NETWORK_DEVICE_H__ diff --git a/dev/ZKAKit/NetworkKit/NetworkDevice.inl b/dev/ZKAKit/NetworkKit/NetworkDevice.inl new file mode 100644 index 00000000..d718b226 --- /dev/null +++ b/dev/ZKAKit/NetworkKit/NetworkDevice.inl @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +/*** + Dtor and ctors. +*/ + +namespace Kernel +{ + NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), + void (*in)(NetworkDeviceCommand), + void (*on_cleanup)(void)) + : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) + { + kcout << "NetworkDevice initialized.\r"; + + MUST_PASS(out && in && on_cleanup); + } + + NetworkDevice::~NetworkDevice() + { + MUST_PASS(fCleanup); + + kcout << "NetworkDevice cleanup.\r"; + + if (fCleanup) + fCleanup(); + } +} // namespace Kernel |
