summaryrefslogtreecommitdiffhomepage
path: root/NewKernel/NetworkKit
diff options
context:
space:
mode:
Diffstat (limited to 'NewKernel/NetworkKit')
-rw-r--r--NewKernel/NetworkKit/IP.hpp83
-rw-r--r--NewKernel/NetworkKit/IPCEP.hxx57
-rw-r--r--NewKernel/NetworkKit/MAC.hxx29
-rw-r--r--NewKernel/NetworkKit/NetworkDevice.hpp65
-rw-r--r--NewKernel/NetworkKit/NetworkDevice.inl27
-rw-r--r--NewKernel/NetworkKit/compile_flags.txt5
6 files changed, 266 insertions, 0 deletions
diff --git a/NewKernel/NetworkKit/IP.hpp b/NewKernel/NetworkKit/IP.hpp
new file mode 100644
index 00000000..f61bbdfd
--- /dev/null
+++ b/NewKernel/NetworkKit/IP.hpp
@@ -0,0 +1,83 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DebugOutput.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/Ref.hpp>
+#include <NewKit/String.hpp>
+
+namespace NewOS
+{
+ 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 NewOS
diff --git a/NewKernel/NetworkKit/IPCEP.hxx b/NewKernel/NetworkKit/IPCEP.hxx
new file mode 100644
index 00000000..705d1ad1
--- /dev/null
+++ b/NewKernel/NetworkKit/IPCEP.hxx
@@ -0,0 +1,57 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic.
+
+ File: IPCEP.hxx, Purpose: Common IPC protocol.
+
+------------------------------------------- */
+
+#ifndef _INC_IPC_ENDPOINT_HXX_
+#define _INC_IPC_ENDPOINT_HXX_
+
+#include <NewKit/Defines.hpp>
+#include <NewKit/String.hpp>
+
+/// @brief Common IPC Endpoint Protocol (Common IPC for short).
+
+/// IA separator.
+#define kRemoteSeparator "."
+
+/// Interchange address, consists of domain:namespace.
+#define kRemoteInvalid "00.00.00.00:0000"
+#define kRemoteBitWidth 96 /* 96-bit address space. */
+
+#define kRemoteHeaderMagic 0xFEEDFACE
+
+namespace NewOS
+{
+ /// @brief 96-bit number to represent the domain and namespace
+ struct PACKED IPCEPAddress
+ {
+ UInt32 RemoteAddress;
+ UInt64 RemoteNamespace;
+ };
+
+ typedef struct IPCEPAddress IPCEPAddressType;
+
+ enum
+ {
+ kIPCEPLittleEndian = 0,
+ kIPCEPBigEndian = 1
+ };
+
+ /// @brief IPCEP connection header
+ typedef struct IPCEPConnectionHeader
+ {
+ UInt32 IpcHeader; // kRemoteHeaderMagic
+ UInt8 IpcEndianess; // 0 : LE, 1 : BE
+ SizeT IpcPacketSize;
+ IPCEPAddressType IpcFrom;
+ IPCEPAddressType IpcTo;
+ UInt32 IpcCRC32;
+ SizeT IpcDataSize;
+ Char IpcData[];
+ } PACKED IPCEPConnectionHeader;
+} // namespace NewOS
+
+#endif // _INC_IPC_ENDPOINT_HXX_
diff --git a/NewKernel/NetworkKit/MAC.hxx b/NewKernel/NetworkKit/MAC.hxx
new file mode 100644
index 00000000..1198c1f1
--- /dev/null
+++ b/NewKernel/NetworkKit/MAC.hxx
@@ -0,0 +1,29 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Array.hpp>
+#include <NewKit/Defines.hpp>
+#include <NewKit/String.hpp>
+
+namespace NewOS
+{
+ 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 NewOS
diff --git a/NewKernel/NetworkKit/NetworkDevice.hpp b/NewKernel/NetworkKit/NetworkDevice.hpp
new file mode 100644
index 00000000..c51de978
--- /dev/null
+++ b/NewKernel/NetworkKit/NetworkDevice.hpp
@@ -0,0 +1,65 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#ifndef __NETWORK_DEVICE__
+#define __NETWORK_DEVICE__
+
+#include <KernelKit/DeviceManager.hpp>
+#include <NetworkKit/IP.hpp>
+
+namespace NewOS
+{
+ 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;
+
+ private:
+ void (*fCleanup)(void);
+ };
+
+ struct PACKED 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 HPC device.
+ using HPCNetworkDevice = NetworkDevice;
+} // namespace NewOS
+
+#include <NetworkKit/NetworkDevice.inl>
+
+#endif // !__NETWORK_DEVICE__
diff --git a/NewKernel/NetworkKit/NetworkDevice.inl b/NewKernel/NetworkKit/NetworkDevice.inl
new file mode 100644
index 00000000..6c5b88ee
--- /dev/null
+++ b/NewKernel/NetworkKit/NetworkDevice.inl
@@ -0,0 +1,27 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+/***
+ Dtor and ctors.
+*/
+
+namespace NewOS {
+NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand),
+ void (*in)(NetworkDeviceCommand),
+ void (*on_cleanup)(void))
+ : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) {
+ kcout << "NK: NetworkDevice initialize.\r";
+
+ MUST_PASS(out && in && on_cleanup);
+}
+
+NetworkDevice::~NetworkDevice() {
+ MUST_PASS(fCleanup);
+
+ kcout << "NK: NetworkDevice cleanup.\r";
+ if (fCleanup) fCleanup();
+}
+} // namespace NewOS
diff --git a/NewKernel/NetworkKit/compile_flags.txt b/NewKernel/NetworkKit/compile_flags.txt
new file mode 100644
index 00000000..a37ae6bf
--- /dev/null
+++ b/NewKernel/NetworkKit/compile_flags.txt
@@ -0,0 +1,5 @@
+-nostdlib
+-ffreestanding
+-std=c++20
+-I./
+-I../