summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NetworkKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-02 19:38:46 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:46 +0200
commit997be16e5ac9a68d54882ab69529815860d62955 (patch)
tree19d6129c2d776bb1edc5d4a7325e39ca176c3403 /dev/kernel/NetworkKit
parent618104e74c195d7508a18450524f8ed7f9af8cc6 (diff)
parentb3b4b1ebdcd6adeac914869017c86d892b7a8ced (diff)
Merge pull request #28 from nekernel-org/dev
0.0.2
Diffstat (limited to 'dev/kernel/NetworkKit')
-rw-r--r--dev/kernel/NetworkKit/IP.h137
-rw-r--r--dev/kernel/NetworkKit/IPC.h130
-rw-r--r--dev/kernel/NetworkKit/LTE.h8
-rw-r--r--dev/kernel/NetworkKit/MAC.h34
-rw-r--r--dev/kernel/NetworkKit/NetworkDevice.h101
-rw-r--r--dev/kernel/NetworkKit/NetworkDevice.inl37
6 files changed, 214 insertions, 233 deletions
diff --git a/dev/kernel/NetworkKit/IP.h b/dev/kernel/NetworkKit/IP.h
index 5df23dc3..bf3b24ff 100644
--- a/dev/kernel/NetworkKit/IP.h
+++ b/dev/kernel/NetworkKit/IP.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -8,76 +8,69 @@
#include <KernelKit/DebugOutput.h>
#include <NewKit/Defines.h>
-#include <NewKit/Ref.h>
#include <NewKit/KString.h>
+#include <NewKit/Ref.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;
+};
-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<KString> ToKString(Ref<RawIPAddress6>& ipv6);
- static ErrorOr<KString> ToKString(Ref<RawIPAddress>& ipv4);
- static bool IpCheckVersion4(const Char* ip);
- };
-} // namespace Kernel
+/**
+ * @brief IP Creation helpers
+ */
+class IPFactory final {
+ public:
+ static ErrorOr<KString> ToKString(Ref<RawIPAddress6>& ipv6);
+ static ErrorOr<KString> ToKString(Ref<RawIPAddress>& ipv4);
+ static bool IpCheckVersion4(const Char* ip);
+};
+} // namespace Kernel
diff --git a/dev/kernel/NetworkKit/IPC.h b/dev/kernel/NetworkKit/IPC.h
index 6304740c..43b58d35 100644
--- a/dev/kernel/NetworkKit/IPC.h
+++ b/dev/kernel/NetworkKit/IPC.h
@@ -1,9 +1,9 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved..
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved..
- File: IPC.h.
- Purpose: IPC protocol.
+ File: IPC.h.
+ Purpose: IPC protocol.
------------------------------------------- */
@@ -25,67 +25,63 @@
#define kIPCHeaderMagic (0x4950434)
-namespace Kernel
-{
- struct IPC_ADDR;
- struct IPC_MSG;
-
- /// @brief 128-bit IPC address.
- struct PACKED IPC_ADDR final
- {
- UInt64 UserProcessID;
- UInt64 ProcessTeam;
-
- ////////////////////////////////////
- // some operators.
- ////////////////////////////////////
-
- bool operator==(const IPC_ADDR& addr) noexcept;
-
- bool operator==(IPC_ADDR& addr) noexcept;
-
- bool operator!=(const IPC_ADDR& addr) noexcept;
-
- bool operator!=(IPC_ADDR& addr) noexcept;
- };
-
- typedef struct IPC_ADDR IPC_ADDR;
-
- enum
- {
- kIPCLittleEndian = 0,
- kIPCBigEndian = 1,
- kIPCMixedEndian = 2,
- };
-
- constexpr inline auto kIPCMsgSize = 6094U;
-
- /// @brief IPC connection header, message cannot be greater than 6K.
- typedef struct IPC_MSG final
- {
- UInt32 IpcHeaderMagic; // cRemoteHeaderMagic
- UInt8 IpcEndianess; // 0 : LE, 1 : BE
- SizeT IpcPacketSize;
- IPC_ADDR IpcFrom;
- IPC_ADDR IpcTo;
- UInt32 IpcCRC32;
- UInt32 IpcMsg;
- UInt32 IpcMsgSz;
- UInt8 IpcData[kIPCMsgSize];
-
- /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever.
- static Bool Pass(IPC_MSG* self, IPC_MSG* target) noexcept;
- } PACKED IPC_MSG;
-
- /// @brief Sanitize packet function
- /// @retval true packet is correct.
- /// @retval false packet is incorrect and process has crashed.
- Bool ipc_sanitize_packet(_Input IPC_MSG* 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 _Input IPC_MSG** pckt_in);
-} // namespace Kernel
-
-#endif // INC_IPC_H
+namespace Kernel {
+struct IPC_ADDR;
+struct IPC_MSG;
+
+/// @brief 128-bit IPC address.
+struct PACKED IPC_ADDR final {
+ UInt64 UserProcessID;
+ UInt64 UserProcessTeam;
+
+ ////////////////////////////////////
+ // some operators.
+ ////////////////////////////////////
+
+ bool operator==(const IPC_ADDR& addr) noexcept;
+
+ bool operator==(IPC_ADDR& addr) noexcept;
+
+ bool operator!=(const IPC_ADDR& addr) noexcept;
+
+ bool operator!=(IPC_ADDR& addr) noexcept;
+};
+
+typedef struct IPC_ADDR IPC_ADDR;
+
+enum {
+ kIPCLittleEndian = 0,
+ kIPCBigEndian = 1,
+ kIPCMixedEndian = 2,
+};
+
+constexpr inline auto kIPCMsgSize = 6094U;
+
+/// @brief IPC connection header, message cannot be greater than 6K.
+typedef struct IPC_MSG final {
+ UInt32 IpcHeaderMagic; // cRemoteHeaderMagic
+ UInt8 IpcEndianess; // 0 : LE, 1 : BE
+ SizeT IpcPacketSize;
+ IPC_ADDR IpcFrom;
+ IPC_ADDR IpcTo;
+ UInt32 IpcCRC32;
+ UInt32 IpcMsg;
+ UInt32 IpcMsgSz;
+ UInt8 IpcData[kIPCMsgSize];
+
+ /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever.
+ static Bool Pass(IPC_MSG* self, IPC_MSG* target) noexcept;
+} PACKED IPC_MSG;
+
+/// @brief Sanitize packet function
+/// @retval true packet is correct.
+/// @retval false packet is incorrect and process has crashed.
+Bool ipc_sanitize_packet(_Input IPC_MSG* 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 _Input IPC_MSG** pckt_in);
+} // namespace Kernel
+
+#endif // INC_IPC_H
diff --git a/dev/kernel/NetworkKit/LTE.h b/dev/kernel/NetworkKit/LTE.h
index c44841de..71254cbf 100644
--- a/dev/kernel/NetworkKit/LTE.h
+++ b/dev/kernel/NetworkKit/LTE.h
@@ -1,9 +1,9 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved..
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved..
- File: LTE.h.
- Purpose: LTE protocol classes.
+ File: LTE.h.
+ Purpose: LTE protocol classes.
------------------------------------------- */
@@ -13,4 +13,4 @@
#include <NewKit/Defines.h>
#include <NewKit/KString.h>
-#endif // ifndef _INC_NETWORK_LTE_H_
+#endif // ifndef _INC_NETWORK_LTE_H_
diff --git a/dev/kernel/NetworkKit/MAC.h b/dev/kernel/NetworkKit/MAC.h
index 0509fed4..8520037e 100644
--- a/dev/kernel/NetworkKit/MAC.h
+++ b/dev/kernel/NetworkKit/MAC.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -12,25 +12,23 @@
#define kMACAddrLen (32)
-namespace Kernel
-{
- class MacAddressGetter;
+namespace Kernel {
+class MacAddressGetter;
- /// \brief This retrieves the MAC address of the device.
- /// \note Listens for the current NIC.
- class MacAddressGetter final
- {
- public:
- MacAddressGetter() = default;
- ~MacAddressGetter() = default;
+/// \brief This retrieves the MAC address of the device.
+/// \note Listens for the current NIC.
+class MacAddressGetter final {
+ public:
+ MacAddressGetter() = default;
+ ~MacAddressGetter() = default;
- NE_COPY_DEFAULT(MacAddressGetter)
+ NE_COPY_DEFAULT(MacAddressGetter)
- public:
- Array<UInt8, kMACAddrLen>& AsBytes();
+ public:
+ Array<UInt8, kMACAddrLen>& AsBytes();
- private:
- Array<UInt8, kMACAddrLen> fMacAddress;
- };
+ private:
+ Array<UInt8, kMACAddrLen> fMacAddress;
+};
-} // namespace Kernel
+} // namespace Kernel
diff --git a/dev/kernel/NetworkKit/NetworkDevice.h b/dev/kernel/NetworkKit/NetworkDevice.h
index 48e4e883..7ed67bab 100644
--- a/dev/kernel/NetworkKit/NetworkDevice.h
+++ b/dev/kernel/NetworkKit/NetworkDevice.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -12,72 +12,69 @@
/// @note Can either work with: Ethernet, GPRS, WiFi
-namespace Kernel
-{
- struct NetworkDeviceCommand;
- class NetworkDevice;
+namespace Kernel {
+struct NetworkDeviceCommand;
+class NetworkDevice;
- /**
- * \brief Network device interface, establishes a connection to the NIC.
- */
- class NetworkDevice final : public IDeviceObject<NetworkDeviceCommand>
- {
- public:
- NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
- void (*in)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
- void (*onCleanup)(void) = nullptr);
+/**
+ * \brief Network device interface, establishes a connection to the NIC.
+ */
+class NetworkDevice final : public IDeviceObject<NetworkDeviceCommand> {
+ public:
+ NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
+ void (*in)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
+ void (*onCleanup)(void) = nullptr);
- ~NetworkDevice() override;
+ ~NetworkDevice() override;
- public:
- NetworkDevice& operator=(const NetworkDevice&) = default;
- NetworkDevice(const NetworkDevice&) = default;
+ public:
+ NetworkDevice& operator=(const NetworkDevice&) = default;
+ NetworkDevice(const NetworkDevice&) = default;
- public:
- const Char* Name() const override;
- Boolean Name(const Char* newStr);
+ public:
+ const Char* Name() const override;
+ Boolean Name(const Char* newStr);
- private:
- static constexpr auto cNetworkNameLen = 512;
+ private:
+ static constexpr auto cNetworkNameLen = 512;
- Void (*fCleanup)(void);
- Char fNetworkName[cNetworkNameLen];
- };
+ Void (*fCleanup)(void);
+ Char fNetworkName[cNetworkNameLen];
+};
- struct NetworkDeviceCommand final
- {
- UInt32 CommandName;
- UInt32 CommandType;
- UInt32 CommandFlags;
- VoidPtr CommandBuffer;
- SizeT CommandSizeBuffer;
- };
+struct NetworkDeviceCommand final {
+ UInt32 CommandName;
+ UInt32 CommandType;
+ UInt32 CommandFlags;
+ VoidPtr CommandBuffer;
+ SizeT CommandSizeBuffer;
+};
- /// @brief TCP device.
- using TCPNetworkDevice = NetworkDevice;
+/// @brief TCP device.
+using TCPNetworkDevice = NetworkDevice;
- /// @brief UDP device.
- using UDPNetworkDevice = NetworkDevice;
+/// @brief UDP device.
+using UDPNetworkDevice = NetworkDevice;
- /// @brief PPP device.
- using PPPNetworkDevice = NetworkDevice;
+/// @brief PPP device.
+using PPPNetworkDevice = NetworkDevice;
- /// @brief IPC device.
- using IPCNetworkDevice = NetworkDevice;
+/// @brief IPC device.
+using IPCNetworkDevice = NetworkDevice;
- /// @brief GRPS device.
- using GPRSNetworkDevice = NetworkDevice;
+/// @brief GRPS device.
+using GPRSNetworkDevice = NetworkDevice;
- /// @brief GSM device.
- using GSMNetworkDevice = NetworkDevice;
+/// @brief GSM device.
+using GSMNetworkDevice = NetworkDevice;
- /// @brief Bluetooth device.
- using BTNetworkDevice = NetworkDevice;
+/// @brief Bluetooth device.
+using BTNetworkDevice = NetworkDevice;
- /// @brief LTE device.
- using LTENetworkDevice = NetworkDevice;
-} // namespace Kernel
+/// @brief LTE device.
+using LTENetworkDevice = NetworkDevice;
+} // namespace Kernel
#include <NetworkKit/NetworkDevice.inl>
-#endif // !__INC_NETWORK_DEVICE_H__
+#endif // !__INC_NETWORK_DEVICE_H__
diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl
index c16756b1..797b8adc 100644
--- a/dev/kernel/NetworkKit/NetworkDevice.inl
+++ b/dev/kernel/NetworkKit/NetworkDevice.inl
@@ -1,32 +1,29 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
/***
- Dtor and ctors.
+ Dtor and ctors.
*/
-namespace Kernel
-{
- NetworkDevice::NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
- void (*in)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
- void (*on_cleanup)(void))
- : IDeviceObject<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup)
- {
- kout << "NetworkDevice initialized.\r";
+namespace Kernel {
+NetworkDevice::NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*,
+ NetworkDeviceCommand),
+ void (*in)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand),
+ void (*on_cleanup)(void))
+ : IDeviceObject<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) {
+ kout << "NetworkDevice initialized.\r";
- MUST_PASS(out && in && on_cleanup);
- }
+ MUST_PASS(out && in && on_cleanup);
+}
- NetworkDevice::~NetworkDevice()
- {
- MUST_PASS(fCleanup);
+NetworkDevice::~NetworkDevice() {
+ MUST_PASS(fCleanup);
- kout << "NetworkDevice cleanup.\r";
+ kout << "NetworkDevice cleanup.\r";
- if (fCleanup)
- fCleanup();
- }
-} // namespace Kernel
+ if (fCleanup) fCleanup();
+}
+} // namespace Kernel