diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
| commit | f3d931aa7cfaf96baef8383b59a8938779541ee7 (patch) | |
| tree | fdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/NetworkKit | |
| parent | 86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff) | |
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/NetworkKit')
| -rw-r--r-- | dev/Kernel/NetworkKit/IP.hxx | 83 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/IPC.hxx | 80 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/LTE.hxx | 16 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/MAC.hxx | 29 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/NetworkDevice.hxx | 80 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/NetworkDevice.inl | 32 | ||||
| -rw-r--r-- | dev/Kernel/NetworkKit/compile_flags.txt | 6 |
7 files changed, 326 insertions, 0 deletions
diff --git a/dev/Kernel/NetworkKit/IP.hxx b/dev/Kernel/NetworkKit/IP.hxx new file mode 100644 index 00000000..6003021e --- /dev/null +++ b/dev/Kernel/NetworkKit/IP.hxx @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <KernelKit/DebugOutput.hxx> +#include <NewKit/Defines.hxx> +#include <NewKit/Ref.hxx> +#include <NewKit/String.hxx> + +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/Kernel/NetworkKit/IPC.hxx b/dev/Kernel/NetworkKit/IPC.hxx new file mode 100644 index 00000000..2a5ae452 --- /dev/null +++ b/dev/Kernel/NetworkKit/IPC.hxx @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies.. + + File: IPC.hxx. + Purpose: IPC protocol. + +------------------------------------------- */ + +#ifndef _INC_IPC_ENDPOINT_HXX_ +#define _INC_IPC_ENDPOINT_HXX_ + +#include <NewKit/Defines.hxx> +#include <NewKit/String.hxx> + +/// @file IPC.hxx +/// @brief IPC protocol. + +/// IA separator. +#define cRemoteSeparator "." + +/// Interchange address, consists of PID:TEAM. +#define cRemoteInvalid "00:00" + +#define cRemoteHeaderMagic (0x4950434) + +namespace Kernel +{ + /// @brief 128-bit IPC address. + struct PACKED IPC_ADDRESS_STRUCT final + { + UInt64 ProcessID; + UInt64 ProcessTeam; + + //////////////////////////////////// + // some operators. + //////////////////////////////////// + + bool operator==(const IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } + + bool operator==(IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } + }; + + typedef struct IPC_ADDRESS_STRUCT IPCEPAddressKind; + + enum + { + eIPCEPLittleEndian = 0, + eIPCEPBigEndian = 1 + }; + + constexpr auto cIPCEPMsgSize = 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[cIPCEPMsgSize]; + } 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(IPC_MESSAGE_STRUCT* pckt); +} // namespace Kernel + +#endif // _INC_IPC_ENDPOINT_HXX_ diff --git a/dev/Kernel/NetworkKit/LTE.hxx b/dev/Kernel/NetworkKit/LTE.hxx new file mode 100644 index 00000000..2c390163 --- /dev/null +++ b/dev/Kernel/NetworkKit/LTE.hxx @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies.. + + File: LTE.hxx. + Purpose: LTE protocol classes. + +------------------------------------------- */ + +#ifndef _INC_NETWORK_LTE_HXX_ +#define _INC_NETWORK_LTE_HXX_ + +#include <NewKit/Defines.hxx> +#include <NewKit/String.hxx> + +#endif // ifndef _INC_NETWORK_LTE_HXX_ diff --git a/dev/Kernel/NetworkKit/MAC.hxx b/dev/Kernel/NetworkKit/MAC.hxx new file mode 100644 index 00000000..8a7b141e --- /dev/null +++ b/dev/Kernel/NetworkKit/MAC.hxx @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Array.hxx> +#include <NewKit/Defines.hxx> +#include <NewKit/String.hxx> + +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/Kernel/NetworkKit/NetworkDevice.hxx b/dev/Kernel/NetworkKit/NetworkDevice.hxx new file mode 100644 index 00000000..79c74459 --- /dev/null +++ b/dev/Kernel/NetworkKit/NetworkDevice.hxx @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __INC_NETWORK_DEVICE_HPP__ +#define __INC_NETWORK_DEVICE_HPP__ + +#include <KernelKit/DeviceManager.hxx> +#include <NetworkKit/IP.hxx> + +/// @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* 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 <NetworkKit/NetworkDevice.inl> + +#endif // !__INC_NETWORK_DEVICE_HPP__ diff --git a/dev/Kernel/NetworkKit/NetworkDevice.inl b/dev/Kernel/NetworkKit/NetworkDevice.inl new file mode 100644 index 00000000..5579eba3 --- /dev/null +++ b/dev/Kernel/NetworkKit/NetworkDevice.inl @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +/*** + 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 << "newoskrnl: NetworkDevice initialized.\r"; + + MUST_PASS(out && in && on_cleanup); + } + + NetworkDevice::~NetworkDevice() + { + MUST_PASS(fCleanup); + + kcout << "newoskrnl: NetworkDevice cleanup.\r"; + + if (fCleanup) + fCleanup(); + } +} // namespace Kernel diff --git a/dev/Kernel/NetworkKit/compile_flags.txt b/dev/Kernel/NetworkKit/compile_flags.txt new file mode 100644 index 00000000..39b236a9 --- /dev/null +++ b/dev/Kernel/NetworkKit/compile_flags.txt @@ -0,0 +1,6 @@ +-nostdlib +-ffreestanding +-std=c++20 +-I./ +-I../ +-D__ED__ |
