From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/zka/NetworkKit/IP.h | 83 ++++++++++++++++++++++++++++++++ dev/zka/NetworkKit/IP.hxx | 83 -------------------------------- dev/zka/NetworkKit/IPC.h | 91 ++++++++++++++++++++++++++++++++++++ dev/zka/NetworkKit/IPC.hxx | 91 ------------------------------------ dev/zka/NetworkKit/LTE.h | 16 +++++++ dev/zka/NetworkKit/LTE.hxx | 16 ------- dev/zka/NetworkKit/MAC.h | 29 ++++++++++++ dev/zka/NetworkKit/MAC.hxx | 29 ------------ dev/zka/NetworkKit/NetworkDevice.h | 80 +++++++++++++++++++++++++++++++ dev/zka/NetworkKit/NetworkDevice.hxx | 80 ------------------------------- 10 files changed, 299 insertions(+), 299 deletions(-) create mode 100644 dev/zka/NetworkKit/IP.h delete mode 100644 dev/zka/NetworkKit/IP.hxx create mode 100644 dev/zka/NetworkKit/IPC.h delete mode 100644 dev/zka/NetworkKit/IPC.hxx create mode 100644 dev/zka/NetworkKit/LTE.h delete mode 100644 dev/zka/NetworkKit/LTE.hxx create mode 100644 dev/zka/NetworkKit/MAC.h delete mode 100644 dev/zka/NetworkKit/MAC.hxx create mode 100644 dev/zka/NetworkKit/NetworkDevice.h delete mode 100644 dev/zka/NetworkKit/NetworkDevice.hxx (limited to 'dev/zka/NetworkKit') diff --git a/dev/zka/NetworkKit/IP.h b/dev/zka/NetworkKit/IP.h new file mode 100644 index 00000000..6853ad6a --- /dev/null +++ b/dev/zka/NetworkKit/IP.h @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +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 ToStringView(Ref& ipv6); + static ErrorOr ToStringView(Ref& ipv4); + static bool IpCheckVersion4(const Char* ip); + }; +} // namespace Kernel diff --git a/dev/zka/NetworkKit/IP.hxx b/dev/zka/NetworkKit/IP.hxx deleted file mode 100644 index 77848d76..00000000 --- a/dev/zka/NetworkKit/IP.hxx +++ /dev/null @@ -1,83 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include - -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 ToStringView(Ref& ipv6); - static ErrorOr ToStringView(Ref& ipv4); - static bool IpCheckVersion4(const Char* ip); - }; -} // namespace Kernel diff --git a/dev/zka/NetworkKit/IPC.h b/dev/zka/NetworkKit/IPC.h new file mode 100644 index 00000000..25ececea --- /dev/null +++ b/dev/zka/NetworkKit/IPC.h @@ -0,0 +1,91 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co.. + + File: IPC.h. + Purpose: IPC protocol. + +------------------------------------------- */ + +#ifndef _INC_IPC_ENDPOINT_HXX_ +#define _INC_IPC_ENDPOINT_HXX_ + +#include +#include +#include +#include + +/// @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_HXX_ diff --git a/dev/zka/NetworkKit/IPC.hxx b/dev/zka/NetworkKit/IPC.hxx deleted file mode 100644 index 11b04990..00000000 --- a/dev/zka/NetworkKit/IPC.hxx +++ /dev/null @@ -1,91 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co.. - - File: IPC.hxx. - Purpose: IPC protocol. - -------------------------------------------- */ - -#ifndef _INC_IPC_ENDPOINT_HXX_ -#define _INC_IPC_ENDPOINT_HXX_ - -#include -#include -#include -#include - -/// @file IPC.hxx -/// @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_HXX_ diff --git a/dev/zka/NetworkKit/LTE.h b/dev/zka/NetworkKit/LTE.h new file mode 100644 index 00000000..1d356acc --- /dev/null +++ b/dev/zka/NetworkKit/LTE.h @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co.. + + File: LTE.h. + Purpose: LTE protocol classes. + +------------------------------------------- */ + +#ifndef _INC_NETWORK_LTE_HXX_ +#define _INC_NETWORK_LTE_HXX_ + +#include +#include + +#endif // ifndef _INC_NETWORK_LTE_HXX_ diff --git a/dev/zka/NetworkKit/LTE.hxx b/dev/zka/NetworkKit/LTE.hxx deleted file mode 100644 index 36f76324..00000000 --- a/dev/zka/NetworkKit/LTE.hxx +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co.. - - File: LTE.hxx. - Purpose: LTE protocol classes. - -------------------------------------------- */ - -#ifndef _INC_NETWORK_LTE_HXX_ -#define _INC_NETWORK_LTE_HXX_ - -#include -#include - -#endif // ifndef _INC_NETWORK_LTE_HXX_ diff --git a/dev/zka/NetworkKit/MAC.h b/dev/zka/NetworkKit/MAC.h new file mode 100644 index 00000000..8794c068 --- /dev/null +++ b/dev/zka/NetworkKit/MAC.h @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +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& AsBytes(); + }; + +} // namespace Kernel diff --git a/dev/zka/NetworkKit/MAC.hxx b/dev/zka/NetworkKit/MAC.hxx deleted file mode 100644 index bd4c0014..00000000 --- a/dev/zka/NetworkKit/MAC.hxx +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -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& AsBytes(); - }; - -} // namespace Kernel diff --git a/dev/zka/NetworkKit/NetworkDevice.h b/dev/zka/NetworkKit/NetworkDevice.h new file mode 100644 index 00000000..2692b14e --- /dev/null +++ b/dev/zka/NetworkKit/NetworkDevice.h @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __INC_NETWORK_DEVICE_HPP__ +#define __INC_NETWORK_DEVICE_HPP__ + +#include +#include + +/// @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 + { + 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* strView); + + 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 LTE device. + using LTENetworkDevice = NetworkDevice; +} // namespace Kernel + +#include + +#endif // !__INC_NETWORK_DEVICE_HPP__ diff --git a/dev/zka/NetworkKit/NetworkDevice.hxx b/dev/zka/NetworkKit/NetworkDevice.hxx deleted file mode 100644 index 4f05d4b2..00000000 --- a/dev/zka/NetworkKit/NetworkDevice.hxx +++ /dev/null @@ -1,80 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#ifndef __INC_NETWORK_DEVICE_HPP__ -#define __INC_NETWORK_DEVICE_HPP__ - -#include -#include - -/// @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 - { - 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* strView); - - 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 LTE device. - using LTENetworkDevice = NetworkDevice; -} // namespace Kernel - -#include - -#endif // !__INC_NETWORK_DEVICE_HPP__ -- cgit v1.2.3