mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
@ -25,82 +25,82 @@
|
||||
|
||||
namespace NetworkARP
|
||||
{
|
||||
enum ARPOperation
|
||||
{
|
||||
REQUEST = 0x1,
|
||||
REPLY = 0x2
|
||||
};
|
||||
enum ARPOperation
|
||||
{
|
||||
REQUEST = 0x1,
|
||||
REPLY = 0x2
|
||||
};
|
||||
|
||||
enum ARPHardwareType
|
||||
{
|
||||
HTYPE_ETHERNET = 1,
|
||||
HTYPE_802_3 = 6,
|
||||
HTYPE_ARCNET = 7,
|
||||
HTYPE_FRAME_RELAY = 15,
|
||||
HTYPE_ATM = 16,
|
||||
HTYPE_HDLC = 17,
|
||||
HTYPE_FIBRE_CHANNEL = 18,
|
||||
HTYPE_ATM_2 = 19,
|
||||
HTYPE_SERIAL_LINE = 20
|
||||
};
|
||||
enum ARPHardwareType
|
||||
{
|
||||
HTYPE_ETHERNET = 1,
|
||||
HTYPE_802_3 = 6,
|
||||
HTYPE_ARCNET = 7,
|
||||
HTYPE_FRAME_RELAY = 15,
|
||||
HTYPE_ATM = 16,
|
||||
HTYPE_HDLC = 17,
|
||||
HTYPE_FIBRE_CHANNEL = 18,
|
||||
HTYPE_ATM_2 = 19,
|
||||
HTYPE_SERIAL_LINE = 20
|
||||
};
|
||||
|
||||
struct ARPHeader
|
||||
{
|
||||
uint16_t HardwareType;
|
||||
uint16_t ProtocolType;
|
||||
uint8_t HardwareSize;
|
||||
uint8_t ProtocolSize;
|
||||
uint16_t Operation;
|
||||
uint48_t SenderMAC : 48;
|
||||
uint32_t SenderIP;
|
||||
uint48_t TargetMAC : 48;
|
||||
uint32_t TargetIP;
|
||||
} __packed;
|
||||
struct ARPHeader
|
||||
{
|
||||
uint16_t HardwareType;
|
||||
uint16_t ProtocolType;
|
||||
uint8_t HardwareSize;
|
||||
uint8_t ProtocolSize;
|
||||
uint16_t Operation;
|
||||
uint48_t SenderMAC : 48;
|
||||
uint32_t SenderIP;
|
||||
uint48_t TargetMAC : 48;
|
||||
uint32_t TargetIP;
|
||||
} __packed;
|
||||
|
||||
struct DiscoveredAddress
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
InternetProtocol IP;
|
||||
};
|
||||
struct DiscoveredAddress
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
InternetProtocol IP;
|
||||
};
|
||||
|
||||
class ARP : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
class ARP : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
|
||||
enum DAType
|
||||
{
|
||||
DA_ADD = 1,
|
||||
DA_DEL = 2,
|
||||
DA_SEARCH = 3,
|
||||
DA_UPDATE = 4
|
||||
};
|
||||
enum DAType
|
||||
{
|
||||
DA_ADD = 1,
|
||||
DA_DEL = 2,
|
||||
DA_SEARCH = 3,
|
||||
DA_UPDATE = 4
|
||||
};
|
||||
|
||||
std::vector<NetworkARP::DiscoveredAddress *> DiscoveredAddresses;
|
||||
DiscoveredAddress *ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC);
|
||||
DiscoveredAddress *Search(InternetProtocol TargetIP);
|
||||
DiscoveredAddress *Update(InternetProtocol TargetIP, MediaAccessControl TargetMAC);
|
||||
bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
std::vector<NetworkARP::DiscoveredAddress *> DiscoveredAddresses;
|
||||
DiscoveredAddress *ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC);
|
||||
DiscoveredAddress *Search(InternetProtocol TargetIP);
|
||||
DiscoveredAddress *Update(InternetProtocol TargetIP, MediaAccessControl TargetMAC);
|
||||
bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
ARP(NetworkEthernet::Ethernet *Ethernet);
|
||||
~ARP();
|
||||
public:
|
||||
ARP(NetworkEthernet::Ethernet *Ethernet);
|
||||
~ARP();
|
||||
|
||||
/**
|
||||
* @brief Resolve an IP address to a MAC address.
|
||||
*
|
||||
* @param IP The IP address to resolve. (Little-endian)
|
||||
* @return uint48_t The MAC address of the IP address.
|
||||
*/
|
||||
uint48_t Resolve(InternetProtocol IP);
|
||||
/**
|
||||
* @brief Resolve an IP address to a MAC address.
|
||||
*
|
||||
* @param IP The IP address to resolve. (Little-endian)
|
||||
* @return uint48_t The MAC address of the IP address.
|
||||
*/
|
||||
uint48_t Resolve(InternetProtocol IP);
|
||||
|
||||
/**
|
||||
* @brief Broadcast an ARP packet.
|
||||
*
|
||||
* @param IP The IP address to broadcast.
|
||||
*/
|
||||
void Broadcast(InternetProtocol IP);
|
||||
};
|
||||
/**
|
||||
* @brief Broadcast an ARP packet.
|
||||
*
|
||||
* @param IP The IP address to broadcast.
|
||||
*/
|
||||
void Broadcast(InternetProtocol IP);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_ARP_H__
|
||||
|
@ -25,158 +25,158 @@
|
||||
|
||||
namespace NetworkDHCP
|
||||
{
|
||||
struct DHCPHeader
|
||||
{
|
||||
uint8_t Opcode;
|
||||
uint8_t HardwareType;
|
||||
uint8_t HardwareAddressLength;
|
||||
uint8_t Hops;
|
||||
uint32_t TransactionID;
|
||||
uint16_t Seconds;
|
||||
uint16_t Flags;
|
||||
uint32_t ClientIP;
|
||||
uint32_t YourIP;
|
||||
uint32_t ServerIP;
|
||||
uint32_t GatewayIP;
|
||||
uint8_t ClientHardwareAddress[16];
|
||||
uint8_t ServerHostName[64];
|
||||
uint8_t BootFileName[128];
|
||||
uint8_t Options[64];
|
||||
} __packed;
|
||||
struct DHCPHeader
|
||||
{
|
||||
uint8_t Opcode;
|
||||
uint8_t HardwareType;
|
||||
uint8_t HardwareAddressLength;
|
||||
uint8_t Hops;
|
||||
uint32_t TransactionID;
|
||||
uint16_t Seconds;
|
||||
uint16_t Flags;
|
||||
uint32_t ClientIP;
|
||||
uint32_t YourIP;
|
||||
uint32_t ServerIP;
|
||||
uint32_t GatewayIP;
|
||||
uint8_t ClientHardwareAddress[16];
|
||||
uint8_t ServerHostName[64];
|
||||
uint8_t BootFileName[128];
|
||||
uint8_t Options[64];
|
||||
} __packed;
|
||||
|
||||
enum DHCPOperation
|
||||
{
|
||||
DHCP_OP_BOOTREQUEST = 1,
|
||||
DHCP_OP_BOOTREPLY = 2
|
||||
};
|
||||
enum DHCPOperation
|
||||
{
|
||||
DHCP_OP_BOOTREQUEST = 1,
|
||||
DHCP_OP_BOOTREPLY = 2
|
||||
};
|
||||
|
||||
/* TODO: Complete list from https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol#Options */
|
||||
enum DHCPOption
|
||||
{
|
||||
DHCP_OPTION_PAD = 0,
|
||||
DHCP_OPTION_SUBNETMASK = 1,
|
||||
DHCP_OPTION_TIME_OFFSET = 2,
|
||||
DHCP_OPTION_ROUTER = 3,
|
||||
DHCP_OPTION_TIME_SERVER = 4,
|
||||
DHCP_OPTION_NAME_SERVER = 5,
|
||||
DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
|
||||
DHCP_OPTION_LOG_SERVER = 7,
|
||||
DHCP_OPTION_COOKIE_SERVER = 8,
|
||||
DHCP_OPTION_LPR_SERVER = 9,
|
||||
DHCP_OPTION_IMPRESS_SERVER = 10,
|
||||
DHCP_OPTION_RESOURCE_LOCATION_SERVER = 11,
|
||||
DHCP_OPTION_HOST_NAME = 12,
|
||||
DHCP_OPTION_BOOT_FILE_SIZE = 13,
|
||||
DHCP_OPTION_MERIT_DUMP_FILE = 14,
|
||||
DHCP_OPTION_DOMAIN_NAME = 15,
|
||||
DHCP_OPTION_SWAP_SERVER = 16,
|
||||
DHCP_OPTION_ROOT_PATH = 17,
|
||||
DHCP_OPTION_EXTENSION_PATH = 18,
|
||||
/* TODO: Complete list from https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol#Options */
|
||||
enum DHCPOption
|
||||
{
|
||||
DHCP_OPTION_PAD = 0,
|
||||
DHCP_OPTION_SUBNETMASK = 1,
|
||||
DHCP_OPTION_TIME_OFFSET = 2,
|
||||
DHCP_OPTION_ROUTER = 3,
|
||||
DHCP_OPTION_TIME_SERVER = 4,
|
||||
DHCP_OPTION_NAME_SERVER = 5,
|
||||
DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
|
||||
DHCP_OPTION_LOG_SERVER = 7,
|
||||
DHCP_OPTION_COOKIE_SERVER = 8,
|
||||
DHCP_OPTION_LPR_SERVER = 9,
|
||||
DHCP_OPTION_IMPRESS_SERVER = 10,
|
||||
DHCP_OPTION_RESOURCE_LOCATION_SERVER = 11,
|
||||
DHCP_OPTION_HOST_NAME = 12,
|
||||
DHCP_OPTION_BOOT_FILE_SIZE = 13,
|
||||
DHCP_OPTION_MERIT_DUMP_FILE = 14,
|
||||
DHCP_OPTION_DOMAIN_NAME = 15,
|
||||
DHCP_OPTION_SWAP_SERVER = 16,
|
||||
DHCP_OPTION_ROOT_PATH = 17,
|
||||
DHCP_OPTION_EXTENSION_PATH = 18,
|
||||
|
||||
DHCP_OPTION_IP_FORWARDING = 19,
|
||||
DHCP_OPTION_NON_LOCAL_SOURCE_ROUTING = 20,
|
||||
DHCP_OPTION_POLICY_FILTER = 21,
|
||||
DHCP_OPTION_MAX_DATAGRAM_REASSEMBLY_SIZE = 22,
|
||||
DHCP_OPTION_DEFAULT_IP_TTL = 23,
|
||||
DHCP_OPTION_PATH_MTU_AGING_TIMEOUT = 24,
|
||||
DHCP_OPTION_PATH_MTU_PLATEAU_TABLE = 25,
|
||||
DHCP_OPTION_IP_FORWARDING = 19,
|
||||
DHCP_OPTION_NON_LOCAL_SOURCE_ROUTING = 20,
|
||||
DHCP_OPTION_POLICY_FILTER = 21,
|
||||
DHCP_OPTION_MAX_DATAGRAM_REASSEMBLY_SIZE = 22,
|
||||
DHCP_OPTION_DEFAULT_IP_TTL = 23,
|
||||
DHCP_OPTION_PATH_MTU_AGING_TIMEOUT = 24,
|
||||
DHCP_OPTION_PATH_MTU_PLATEAU_TABLE = 25,
|
||||
|
||||
DHCP_OPTION_INTERFACE_MTU = 26,
|
||||
DHCP_OPTION_ALL_SUBNETS_ARE_LOCAL = 27,
|
||||
DHCP_OPTION_BROADCAST_ADDRESS = 28,
|
||||
DHCP_OPTION_PERFORM_MASK_DISCOVERY = 29,
|
||||
DHCP_OPTION_MASK_SUPPLIER = 30,
|
||||
DHCP_OPTION_ROUTER_DISCOVERY = 31,
|
||||
DHCP_OPTION_ROUTER_SOLICITATION_ADDRESS = 32,
|
||||
DHCP_OPTION_STATIC_ROUTE = 33,
|
||||
DHCP_OPTION_INTERFACE_MTU = 26,
|
||||
DHCP_OPTION_ALL_SUBNETS_ARE_LOCAL = 27,
|
||||
DHCP_OPTION_BROADCAST_ADDRESS = 28,
|
||||
DHCP_OPTION_PERFORM_MASK_DISCOVERY = 29,
|
||||
DHCP_OPTION_MASK_SUPPLIER = 30,
|
||||
DHCP_OPTION_ROUTER_DISCOVERY = 31,
|
||||
DHCP_OPTION_ROUTER_SOLICITATION_ADDRESS = 32,
|
||||
DHCP_OPTION_STATIC_ROUTE = 33,
|
||||
|
||||
DHCP_OPTION_TRAILER_ENCAPSULATION = 34,
|
||||
DHCP_OPTION_ARP_CACHE_TIMEOUT = 35,
|
||||
DHCP_OPTION_ETHERNET_ENCAPSULATION = 36,
|
||||
DHCP_OPTION_TRAILER_ENCAPSULATION = 34,
|
||||
DHCP_OPTION_ARP_CACHE_TIMEOUT = 35,
|
||||
DHCP_OPTION_ETHERNET_ENCAPSULATION = 36,
|
||||
|
||||
DHCP_OPTION_DEFAULT_TCP_TTL = 37,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_INTERVAL = 38,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_GARBAGE = 39,
|
||||
DHCP_OPTION_DEFAULT_TCP_TTL = 37,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_INTERVAL = 38,
|
||||
DHCP_OPTION_TCP_KEEPALIVE_GARBAGE = 39,
|
||||
|
||||
DHCP_OPTION_NIS_DOMAIN = 40,
|
||||
DHCP_OPTION_NIS_SERVERS = 41,
|
||||
DHCP_OPTION_NTP_SERVERS = 42,
|
||||
DHCP_OPTION_VENDOR_SPECIFIC = 43,
|
||||
DHCP_OPTION_NETBIOS_NAME_SERVERS = 44,
|
||||
DHCP_OPTION_NETBIOS_DD_SERVER = 45,
|
||||
DHCP_OPTION_NETBIOS_NODE_TYPE = 46,
|
||||
DHCP_OPTION_NETBIOS_SCOPE = 47,
|
||||
DHCP_OPTION_X_FONT_SERVERS = 48,
|
||||
DHCP_OPTION_X_DISPLAY_MANAGER = 49,
|
||||
DHCP_OPTION_NIS_DOMAIN = 40,
|
||||
DHCP_OPTION_NIS_SERVERS = 41,
|
||||
DHCP_OPTION_NTP_SERVERS = 42,
|
||||
DHCP_OPTION_VENDOR_SPECIFIC = 43,
|
||||
DHCP_OPTION_NETBIOS_NAME_SERVERS = 44,
|
||||
DHCP_OPTION_NETBIOS_DD_SERVER = 45,
|
||||
DHCP_OPTION_NETBIOS_NODE_TYPE = 46,
|
||||
DHCP_OPTION_NETBIOS_SCOPE = 47,
|
||||
DHCP_OPTION_X_FONT_SERVERS = 48,
|
||||
DHCP_OPTION_X_DISPLAY_MANAGER = 49,
|
||||
|
||||
DHCP_OPTION_REQUESTED_IP = 50,
|
||||
DHCP_OPTION_IP_LEASE_TIME = 51,
|
||||
DHCP_OPTION_OPTION_OVERLOAD = 52,
|
||||
DHCP_OPTION_MESSAGE_TYPE = 53,
|
||||
DHCP_OPTION_SERVER_IDENTIFIER = 54,
|
||||
DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
|
||||
DHCP_OPTION_MESSAGE = 56,
|
||||
DHCP_OPTION_MAX_MESSAGE_SIZE = 57,
|
||||
DHCP_OPTION_T1_TIMEOUT = 58,
|
||||
DHCP_OPTION_T2_TIMEOUT = 59,
|
||||
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
|
||||
DHCP_OPTION_CLIENT_IDENTIFIER = 61,
|
||||
DHCP_OPTION_REQUESTED_IP = 50,
|
||||
DHCP_OPTION_IP_LEASE_TIME = 51,
|
||||
DHCP_OPTION_OPTION_OVERLOAD = 52,
|
||||
DHCP_OPTION_MESSAGE_TYPE = 53,
|
||||
DHCP_OPTION_SERVER_IDENTIFIER = 54,
|
||||
DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
|
||||
DHCP_OPTION_MESSAGE = 56,
|
||||
DHCP_OPTION_MAX_MESSAGE_SIZE = 57,
|
||||
DHCP_OPTION_T1_TIMEOUT = 58,
|
||||
DHCP_OPTION_T2_TIMEOUT = 59,
|
||||
DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
|
||||
DHCP_OPTION_CLIENT_IDENTIFIER = 61,
|
||||
|
||||
DHCP_OPTION_NETWORK_TIME_SERVER = 62,
|
||||
DHCP_OPTION_NETWORK_TIME_SERVER = 62,
|
||||
|
||||
DHCP_OPTION_END = 255
|
||||
};
|
||||
DHCP_OPTION_END = 255
|
||||
};
|
||||
|
||||
enum DHCPMessageType
|
||||
{
|
||||
DHCP_MESSAGE_TYPE_DISCOVER = 1,
|
||||
DHCP_MESSAGE_TYPE_OFFER = 2,
|
||||
DHCP_MESSAGE_TYPE_REQUEST = 3,
|
||||
DHCP_MESSAGE_TYPE_DECLINE = 4,
|
||||
DHCP_MESSAGE_TYPE_ACK = 5,
|
||||
DHCP_MESSAGE_TYPE_NAK = 6,
|
||||
DHCP_MESSAGE_TYPE_RELEASE = 7,
|
||||
DHCP_MESSAGE_TYPE_INFORM = 8,
|
||||
DHCP_MESSAGE_TYPE_FORCERENEW = 9,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERY = 10,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNASSIGNED = 11,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNKNOWN = 12,
|
||||
DHCP_MESSAGE_TYPE_LEASEACTIVE = 13,
|
||||
DHCP_MESSAGE_TYPE_BULKLEASEQUERY = 14,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYDONE = 15,
|
||||
DHCP_MESSAGE_TYPE_ACTIVELEASEQUERY = 16,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYSTATUS = 17,
|
||||
DHCP_MESSAGE_TYPE_DHCPTLS = 18
|
||||
};
|
||||
enum DHCPMessageType
|
||||
{
|
||||
DHCP_MESSAGE_TYPE_DISCOVER = 1,
|
||||
DHCP_MESSAGE_TYPE_OFFER = 2,
|
||||
DHCP_MESSAGE_TYPE_REQUEST = 3,
|
||||
DHCP_MESSAGE_TYPE_DECLINE = 4,
|
||||
DHCP_MESSAGE_TYPE_ACK = 5,
|
||||
DHCP_MESSAGE_TYPE_NAK = 6,
|
||||
DHCP_MESSAGE_TYPE_RELEASE = 7,
|
||||
DHCP_MESSAGE_TYPE_INFORM = 8,
|
||||
DHCP_MESSAGE_TYPE_FORCERENEW = 9,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERY = 10,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNASSIGNED = 11,
|
||||
DHCP_MESSAGE_TYPE_LEASEUNKNOWN = 12,
|
||||
DHCP_MESSAGE_TYPE_LEASEACTIVE = 13,
|
||||
DHCP_MESSAGE_TYPE_BULKLEASEQUERY = 14,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYDONE = 15,
|
||||
DHCP_MESSAGE_TYPE_ACTIVELEASEQUERY = 16,
|
||||
DHCP_MESSAGE_TYPE_LEASEQUERYSTATUS = 17,
|
||||
DHCP_MESSAGE_TYPE_DHCPTLS = 18
|
||||
};
|
||||
|
||||
#define DHCP_TRANSACTION_ID 0xFE2EC005
|
||||
|
||||
class DHCP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
bool Received = false;
|
||||
class DHCP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
bool Received = false;
|
||||
|
||||
void CreatePacket(DHCPHeader *Packet, uint8_t MessageType, uint32_t RequestIP);
|
||||
void *GetOption(DHCPHeader *Packet, uint8_t Type);
|
||||
void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
void CreatePacket(DHCPHeader *Packet, uint8_t MessageType, uint32_t RequestIP);
|
||||
void *GetOption(DHCPHeader *Packet, uint8_t Type);
|
||||
void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
/** @brief IP address (Little-endian) */
|
||||
InternetProtocol IP = {};
|
||||
/** @brief Gateway address (Little-endian) */
|
||||
InternetProtocol Gateway = {};
|
||||
/** @brief Subnet mask (Little-endian) */
|
||||
InternetProtocol SubNetworkMask = {};
|
||||
/** @brief DNS server address (Little-endian) */
|
||||
InternetProtocol DomainNameSystem = {};
|
||||
public:
|
||||
/** @brief IP address (Little-endian) */
|
||||
InternetProtocol IP = {};
|
||||
/** @brief Gateway address (Little-endian) */
|
||||
InternetProtocol Gateway = {};
|
||||
/** @brief Subnet mask (Little-endian) */
|
||||
InternetProtocol SubNetworkMask = {};
|
||||
/** @brief DNS server address (Little-endian) */
|
||||
InternetProtocol DomainNameSystem = {};
|
||||
|
||||
DHCP(NetworkUDP::Socket *Socket, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~DHCP();
|
||||
void Request();
|
||||
void Request(InternetProtocol IP);
|
||||
};
|
||||
DHCP(NetworkUDP::Socket *Socket, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~DHCP();
|
||||
void Request();
|
||||
void Request(InternetProtocol IP);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DHCP_H__
|
||||
|
@ -23,15 +23,15 @@
|
||||
|
||||
namespace NetworkDNS
|
||||
{
|
||||
class DNS : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
class DNS : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
|
||||
public:
|
||||
DNS(NetworkUDP::Socket *Socket);
|
||||
~DNS();
|
||||
};
|
||||
public:
|
||||
DNS(NetworkUDP::Socket *Socket);
|
||||
~DNS();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DNS_H__
|
||||
|
@ -23,86 +23,86 @@
|
||||
|
||||
namespace NetworkEthernet
|
||||
{
|
||||
enum FrameType
|
||||
{
|
||||
TYPE_IPV4 = 0x0800,
|
||||
TYPE_ARP = 0x0806,
|
||||
TYPE_RARP = 0x8035,
|
||||
TYPE_IPV6 = 0x86DD
|
||||
};
|
||||
enum FrameType
|
||||
{
|
||||
TYPE_IPV4 = 0x0800,
|
||||
TYPE_ARP = 0x0806,
|
||||
TYPE_RARP = 0x8035,
|
||||
TYPE_IPV6 = 0x86DD
|
||||
};
|
||||
|
||||
struct EthernetHeader
|
||||
{
|
||||
uint48_t DestinationMAC : 48;
|
||||
uint48_t SourceMAC : 48;
|
||||
uint16_t Type;
|
||||
} __packed;
|
||||
struct EthernetHeader
|
||||
{
|
||||
uint48_t DestinationMAC : 48;
|
||||
uint48_t SourceMAC : 48;
|
||||
uint16_t Type;
|
||||
} __packed;
|
||||
|
||||
struct EthernetPacket
|
||||
{
|
||||
EthernetHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct EthernetPacket
|
||||
{
|
||||
EthernetHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class EthernetEvents
|
||||
{
|
||||
private:
|
||||
FrameType FType;
|
||||
class EthernetEvents
|
||||
{
|
||||
private:
|
||||
FrameType FType;
|
||||
|
||||
protected:
|
||||
EthernetEvents(FrameType Type);
|
||||
~EthernetEvents();
|
||||
protected:
|
||||
EthernetEvents(FrameType Type);
|
||||
~EthernetEvents();
|
||||
|
||||
public:
|
||||
FrameType GetFrameType() { return FType; }
|
||||
virtual void OnEthernetPacketSent(EthernetPacket *Packet)
|
||||
{
|
||||
UNUSED(Packet);
|
||||
netdbg("Event not handled. [%p]", Packet);
|
||||
}
|
||||
public:
|
||||
FrameType GetFrameType() { return FType; }
|
||||
virtual void OnEthernetPacketSent(EthernetPacket *Packet)
|
||||
{
|
||||
UNUSED(Packet);
|
||||
netdbg("Event not handled. [%p]", Packet);
|
||||
}
|
||||
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event not handled. [%p, %d]", Data, Length);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event not handled. [%p, %d]", Data, Length);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Ethernet : public NetworkInterfaceManager::Events
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
void Receive(uint8_t *Data, size_t Length);
|
||||
void OnInterfaceReceived(NetworkInterfaceManager::DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
class Ethernet : public NetworkInterfaceManager::Events
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
void Receive(uint8_t *Data, size_t Length);
|
||||
void OnInterfaceReceived(NetworkInterfaceManager::DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
/** @brief Get driver interface
|
||||
* @return Module interface
|
||||
*/
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface()
|
||||
{
|
||||
netdbg("Interface: %#lx (MAC: %s; IPv4: %s; IPv6: %s)", this->Interface,
|
||||
this->Interface->MAC.ToString(),
|
||||
this->Interface->IP.v4.ToStringLittleEndian(),
|
||||
this->Interface->IP.v6.ToStringLittleEndian());
|
||||
return this->Interface;
|
||||
}
|
||||
public:
|
||||
/** @brief Get driver interface
|
||||
* @return Driver interface
|
||||
*/
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface()
|
||||
{
|
||||
netdbg("Interface: %#lx (MAC: %s; IPv4: %s; IPv6: %s)", this->Interface,
|
||||
this->Interface->MAC.ToString(),
|
||||
this->Interface->IP.v4.ToStringLittleEndian(),
|
||||
this->Interface->IP.v6.ToStringLittleEndian());
|
||||
return this->Interface;
|
||||
}
|
||||
|
||||
Ethernet(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~Ethernet();
|
||||
Ethernet(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~Ethernet();
|
||||
|
||||
/**
|
||||
* @brief Send an Ethernet packet.
|
||||
*
|
||||
* @param MAC The MAC address of the destination. (Big-endian)
|
||||
* @param Type The type of the packet.
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
*/
|
||||
void Send(MediaAccessControl MAC, FrameType Type, uint8_t *Data, size_t Length);
|
||||
};
|
||||
/**
|
||||
* @brief Send an Ethernet packet.
|
||||
*
|
||||
* @param MAC The MAC address of the destination. (Big-endian)
|
||||
* @param Type The type of the packet.
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
*/
|
||||
void Send(MediaAccessControl MAC, FrameType Type, uint8_t *Data, size_t Length);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_ETHERNET_H__
|
||||
|
@ -23,49 +23,49 @@
|
||||
|
||||
namespace NetworkICMPv4
|
||||
{
|
||||
enum ICMPv4Type
|
||||
{
|
||||
TYPE_ECHO_REPLY = 0,
|
||||
TYPE_DESTINATION_UNREACHABLE = 3,
|
||||
TYPE_SOURCE_QUENCH = 4,
|
||||
TYPE_REDIRECT = 5,
|
||||
TYPE_ECHO = 8,
|
||||
TYPE_ROUTER_ADVERTISEMENT = 9,
|
||||
TYPE_ROUTER_SELECTION = 10,
|
||||
TYPE_TIME_EXCEEDED = 11,
|
||||
TYPE_PARAMETER_PROBLEM = 12,
|
||||
TYPE_TIMESTAMP = 13,
|
||||
TYPE_TIMESTAMP_REPLY = 14
|
||||
};
|
||||
enum ICMPv4Type
|
||||
{
|
||||
TYPE_ECHO_REPLY = 0,
|
||||
TYPE_DESTINATION_UNREACHABLE = 3,
|
||||
TYPE_SOURCE_QUENCH = 4,
|
||||
TYPE_REDIRECT = 5,
|
||||
TYPE_ECHO = 8,
|
||||
TYPE_ROUTER_ADVERTISEMENT = 9,
|
||||
TYPE_ROUTER_SELECTION = 10,
|
||||
TYPE_TIME_EXCEEDED = 11,
|
||||
TYPE_PARAMETER_PROBLEM = 12,
|
||||
TYPE_TIMESTAMP = 13,
|
||||
TYPE_TIMESTAMP_REPLY = 14
|
||||
};
|
||||
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class ICMPv4
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class ICMPv4
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
ICMPv4(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv4();
|
||||
void Send(/* ???? */);
|
||||
void Receive(ICMPPacket *Packet);
|
||||
};
|
||||
ICMPv4(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv4();
|
||||
void Send(/* ???? */);
|
||||
void Receive(ICMPPacket *Packet);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ICMPv4_H__
|
||||
|
@ -23,34 +23,34 @@
|
||||
|
||||
namespace NetworkICMPv6
|
||||
{
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
struct ICMPHeader
|
||||
{
|
||||
uint8_t Type;
|
||||
uint8_t Code;
|
||||
uint16_t Checksum;
|
||||
uint16_t Identifier;
|
||||
uint16_t SequenceNumber;
|
||||
};
|
||||
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct ICMPPacket
|
||||
{
|
||||
ICMPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class ICMPv6
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class ICMPv6
|
||||
{
|
||||
private:
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
ICMPv6(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv6();
|
||||
void Send(uint8_t *Data, size_t Length);
|
||||
void Receive(uint8_t *Data);
|
||||
};
|
||||
ICMPv6(NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~ICMPv6();
|
||||
void Send(uint8_t *Data, size_t Length);
|
||||
void Receive(uint8_t *Data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_ICMPv6_H__
|
||||
|
@ -25,113 +25,113 @@
|
||||
|
||||
namespace NetworkIPv4
|
||||
{
|
||||
struct IPv4Header
|
||||
{
|
||||
uint8_t IHL : 4;
|
||||
uint8_t Version : 4;
|
||||
uint8_t TypeOfService;
|
||||
uint16_t TotalLength;
|
||||
uint16_t Identification;
|
||||
uint8_t Flags;
|
||||
uint8_t FragmentOffset;
|
||||
uint8_t TimeToLive;
|
||||
uint8_t Protocol;
|
||||
uint16_t HeaderChecksum;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
struct IPv4Header
|
||||
{
|
||||
uint8_t IHL : 4;
|
||||
uint8_t Version : 4;
|
||||
uint8_t TypeOfService;
|
||||
uint16_t TotalLength;
|
||||
uint16_t Identification;
|
||||
uint8_t Flags;
|
||||
uint8_t FragmentOffset;
|
||||
uint8_t TimeToLive;
|
||||
uint8_t Protocol;
|
||||
uint16_t HeaderChecksum;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
|
||||
/* On wikipedia page we have this: https://en.wikipedia.org/wiki/File:IPv4_Packet-en.svg
|
||||
but only the code above works... */
|
||||
// uint8_t Version : 4;
|
||||
// uint8_t IHL : 4;
|
||||
// uint16_t TypeOfService : 8;
|
||||
// uint16_t TotalLength : 12;
|
||||
// uint16_t Identification : 16;
|
||||
// uint16_t Flags : 3;
|
||||
// uint16_t FragmentOffset : 13;
|
||||
// uint8_t TimeToLive : 8;
|
||||
// uint8_t Protocol : 8;
|
||||
// uint16_t HeaderChecksum;
|
||||
// uint32_t SourceIP;
|
||||
// uint32_t DestinationIP;
|
||||
};
|
||||
/* On wikipedia page we have this: https://en.wikipedia.org/wiki/File:IPv4_Packet-en.svg
|
||||
but only the code above works... */
|
||||
// uint8_t Version : 4;
|
||||
// uint8_t IHL : 4;
|
||||
// uint16_t TypeOfService : 8;
|
||||
// uint16_t TotalLength : 12;
|
||||
// uint16_t Identification : 16;
|
||||
// uint16_t Flags : 3;
|
||||
// uint16_t FragmentOffset : 13;
|
||||
// uint8_t TimeToLive : 8;
|
||||
// uint8_t Protocol : 8;
|
||||
// uint16_t HeaderChecksum;
|
||||
// uint32_t SourceIP;
|
||||
// uint32_t DestinationIP;
|
||||
};
|
||||
|
||||
struct IPv4Packet
|
||||
{
|
||||
IPv4Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct IPv4Packet
|
||||
{
|
||||
IPv4Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
enum IPv4Protocols
|
||||
{
|
||||
PROTOCOL_ICMP = 1,
|
||||
PROTOCOL_IGMP = 2,
|
||||
PROTOCOL_TCP = 6,
|
||||
PROTOCOL_UDP = 17,
|
||||
PROTOCOL_IPV6 = 41,
|
||||
PROTOCOL_ROUTING = 43,
|
||||
PROTOCOL_FRAGMENT = 44,
|
||||
PROTOCOL_ESP = 50,
|
||||
PROTOCOL_AH = 51,
|
||||
PROTOCOL_ICMPV6 = 58,
|
||||
PROTOCOL_NONE = 59,
|
||||
PROTOCOL_DSTOPTS = 60,
|
||||
PROTOCOL_ND = 77,
|
||||
PROTOCOL_ICLFXBM = 78,
|
||||
PROTOCOL_PIM = 103,
|
||||
PROTOCOL_COMP = 108,
|
||||
PROTOCOL_SCTP = 132,
|
||||
PROTOCOL_UDPLITE = 136,
|
||||
PROTOCOL_RAW = 255
|
||||
};
|
||||
enum IPv4Protocols
|
||||
{
|
||||
PROTOCOL_ICMP = 1,
|
||||
PROTOCOL_IGMP = 2,
|
||||
PROTOCOL_TCP = 6,
|
||||
PROTOCOL_UDP = 17,
|
||||
PROTOCOL_IPV6 = 41,
|
||||
PROTOCOL_ROUTING = 43,
|
||||
PROTOCOL_FRAGMENT = 44,
|
||||
PROTOCOL_ESP = 50,
|
||||
PROTOCOL_AH = 51,
|
||||
PROTOCOL_ICMPV6 = 58,
|
||||
PROTOCOL_NONE = 59,
|
||||
PROTOCOL_DSTOPTS = 60,
|
||||
PROTOCOL_ND = 77,
|
||||
PROTOCOL_ICLFXBM = 78,
|
||||
PROTOCOL_PIM = 103,
|
||||
PROTOCOL_COMP = 108,
|
||||
PROTOCOL_SCTP = 132,
|
||||
PROTOCOL_UDPLITE = 136,
|
||||
PROTOCOL_RAW = 255
|
||||
};
|
||||
|
||||
class IPv4 : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkARP::ARP *ARP;
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
class IPv4 : public NetworkEthernet::EthernetEvents
|
||||
{
|
||||
private:
|
||||
NetworkARP::ARP *ARP;
|
||||
NetworkEthernet::Ethernet *Ethernet;
|
||||
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
virtual bool OnEthernetPacketReceived(uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
InternetProtocol GatewayIP;
|
||||
InternetProtocol SubNetworkMaskIP;
|
||||
IPv4(NetworkARP::ARP *ARP, NetworkEthernet::Ethernet *Ethernet);
|
||||
~IPv4();
|
||||
public:
|
||||
InternetProtocol GatewayIP;
|
||||
InternetProtocol SubNetworkMaskIP;
|
||||
IPv4(NetworkARP::ARP *ARP, NetworkEthernet::Ethernet *Ethernet);
|
||||
~IPv4();
|
||||
|
||||
/**
|
||||
* @brief Send an IPv4 packet.
|
||||
*
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
* @param Protocol The protocol of the packet.
|
||||
* @param DestinationIP The IP address of the destination. (Big-endian)
|
||||
*/
|
||||
void Send(uint8_t *Data, size_t Length, uint8_t Protocol, InternetProtocol DestinationIP);
|
||||
};
|
||||
/**
|
||||
* @brief Send an IPv4 packet.
|
||||
*
|
||||
* @param Data The data to send.
|
||||
* @param Length The length of the data.
|
||||
* @param Protocol The protocol of the packet.
|
||||
* @param DestinationIP The IP address of the destination. (Big-endian)
|
||||
*/
|
||||
void Send(uint8_t *Data, size_t Length, uint8_t Protocol, InternetProtocol DestinationIP);
|
||||
};
|
||||
|
||||
class IPv4Events
|
||||
{
|
||||
private:
|
||||
uint8_t Protocol;
|
||||
class IPv4Events
|
||||
{
|
||||
private:
|
||||
uint8_t Protocol;
|
||||
|
||||
protected:
|
||||
IPv4Events(IPv4Protocols Protocol);
|
||||
~IPv4Events();
|
||||
protected:
|
||||
IPv4Events(IPv4Protocols Protocol);
|
||||
~IPv4Events();
|
||||
|
||||
public:
|
||||
uint8_t GetProtocol() { return Protocol; }
|
||||
public:
|
||||
uint8_t GetProtocol() { return Protocol; }
|
||||
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(SourceIP);
|
||||
UNUSED(DestinationIP);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(SourceIP);
|
||||
UNUSED(DestinationIP);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IPv4_H__
|
||||
|
@ -22,23 +22,23 @@
|
||||
|
||||
namespace NetworkIPv6
|
||||
{
|
||||
struct IPv6Header
|
||||
{
|
||||
uint32_t Version;
|
||||
uint8_t TrafficClass;
|
||||
uint16_t FlowLabel;
|
||||
uint16_t PayloadLength;
|
||||
uint8_t NextHeader;
|
||||
uint8_t HopLimit;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
};
|
||||
struct IPv6Header
|
||||
{
|
||||
uint32_t Version;
|
||||
uint8_t TrafficClass;
|
||||
uint16_t FlowLabel;
|
||||
uint16_t PayloadLength;
|
||||
uint8_t NextHeader;
|
||||
uint8_t HopLimit;
|
||||
uint32_t SourceIP;
|
||||
uint32_t DestinationIP;
|
||||
};
|
||||
|
||||
struct IPv6Packet
|
||||
{
|
||||
IPv6Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct IPv6Packet
|
||||
{
|
||||
IPv6Header Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_IPv6_H__
|
||||
|
@ -27,90 +27,90 @@
|
||||
|
||||
namespace NetworkInterfaceManager
|
||||
{
|
||||
struct DeviceInterface
|
||||
{
|
||||
/** @brief Device interface name */
|
||||
char Name[128];
|
||||
struct DeviceInterface
|
||||
{
|
||||
/** @brief Device interface name */
|
||||
char Name[128];
|
||||
|
||||
/** @brief Device interface index */
|
||||
uint64_t ID;
|
||||
/** @brief Device interface index */
|
||||
uint64_t ID;
|
||||
|
||||
/** @brief Device interface MAC address (Big-endian) */
|
||||
MediaAccessControl MAC;
|
||||
/** @brief Device interface MAC address (Big-endian) */
|
||||
MediaAccessControl MAC;
|
||||
|
||||
/** @brief Device interface IP address (Big-endian) */
|
||||
InternetProtocol IP;
|
||||
/** @brief Device interface IP address (Big-endian) */
|
||||
InternetProtocol IP;
|
||||
|
||||
/** @brief Reserved */
|
||||
unsigned long DriverID;
|
||||
};
|
||||
/** @brief Reserved */
|
||||
unsigned long DriverID;
|
||||
};
|
||||
|
||||
class Events
|
||||
{
|
||||
protected:
|
||||
Events(DeviceInterface *Interface);
|
||||
~Events();
|
||||
class Events
|
||||
{
|
||||
protected:
|
||||
Events(DeviceInterface *Interface);
|
||||
~Events();
|
||||
|
||||
public:
|
||||
virtual void OnInterfaceAdded(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
public:
|
||||
virtual void OnInterfaceAdded(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceRemoved(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceRemoved(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceChanged(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceChanged(DeviceInterface *Interface)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceReceived(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
virtual void OnInterfaceReceived(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
|
||||
virtual void OnInterfaceSent(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
};
|
||||
virtual void OnInterfaceSent(DeviceInterface *Interface, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Interface);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
netdbg("Event for %s not handled.", Interface->Name);
|
||||
}
|
||||
};
|
||||
|
||||
class NetworkInterface
|
||||
{
|
||||
private:
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
int CardIDs = 0;
|
||||
std::vector<DeviceInterface *> Interfaces;
|
||||
class NetworkInterface
|
||||
{
|
||||
private:
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
int CardIDs = 0;
|
||||
std::vector<DeviceInterface *> Interfaces;
|
||||
|
||||
Tasking::TCB *NetSvcThread;
|
||||
void StopNetworkStack();
|
||||
void FetchNetworkCards(unsigned long modUniqueID);
|
||||
Tasking::TCB *NetSvcThread;
|
||||
void StopNetworkStack();
|
||||
void FetchNetworkCards(unsigned long modUniqueID);
|
||||
|
||||
public:
|
||||
NetworkInterface();
|
||||
~NetworkInterface();
|
||||
public:
|
||||
NetworkInterface();
|
||||
~NetworkInterface();
|
||||
|
||||
void StartService();
|
||||
void StartService();
|
||||
|
||||
void Send(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Receive(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Send(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
void Receive(DeviceInterface *Interface, uint8_t *Data, size_t Length);
|
||||
|
||||
void DrvSend(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void DrvReceive(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void StartNetworkStack();
|
||||
};
|
||||
void DrvSend(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void DrvReceive(unsigned int DriverID, unsigned char *Data, unsigned short Size);
|
||||
void StartNetworkStack();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NETWORK_CONTROLLER_H__
|
||||
|
@ -32,199 +32,199 @@ void DbgDumpData(const char *Description, void *Address, unsigned long Length);
|
||||
static inline void DbgNetwork() { return; }
|
||||
static inline void DbgDumpData(const char *Description, void *Address, unsigned long Length)
|
||||
{
|
||||
UNUSED(Description);
|
||||
UNUSED(Address);
|
||||
UNUSED(Length);
|
||||
return;
|
||||
UNUSED(Description);
|
||||
UNUSED(Address);
|
||||
UNUSED(Length);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum Endianness
|
||||
{
|
||||
LITTLE_ENDIAN,
|
||||
BIG_ENDIAN
|
||||
LITTLE_ENDIAN,
|
||||
BIG_ENDIAN
|
||||
};
|
||||
|
||||
struct MediaAccessControl
|
||||
{
|
||||
uint8_t Address[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
uint8_t Address[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
inline bool operator==(const MediaAccessControl &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3] &&
|
||||
lhs.Address[4] == this->Address[4] &&
|
||||
lhs.Address[5] == this->Address[5];
|
||||
}
|
||||
inline bool operator==(const MediaAccessControl &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3] &&
|
||||
lhs.Address[4] == this->Address[4] &&
|
||||
lhs.Address[5] == this->Address[5];
|
||||
}
|
||||
|
||||
inline bool operator==(const uint48_t &lhs) const
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
MAC.Address[0] = (uint8_t)((lhs >> 40) & 0xFF);
|
||||
MAC.Address[1] = (uint8_t)((lhs >> 32) & 0xFF);
|
||||
MAC.Address[2] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
MAC.Address[3] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
MAC.Address[4] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
MAC.Address[5] = (uint8_t)(lhs & 0xFF);
|
||||
return MAC.Address[0] == this->Address[0] &&
|
||||
MAC.Address[1] == this->Address[1] &&
|
||||
MAC.Address[2] == this->Address[2] &&
|
||||
MAC.Address[3] == this->Address[3] &&
|
||||
MAC.Address[4] == this->Address[4] &&
|
||||
MAC.Address[5] == this->Address[5];
|
||||
}
|
||||
inline bool operator==(const uint48_t &lhs) const
|
||||
{
|
||||
MediaAccessControl MAC;
|
||||
MAC.Address[0] = (uint8_t)((lhs >> 40) & 0xFF);
|
||||
MAC.Address[1] = (uint8_t)((lhs >> 32) & 0xFF);
|
||||
MAC.Address[2] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
MAC.Address[3] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
MAC.Address[4] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
MAC.Address[5] = (uint8_t)(lhs & 0xFF);
|
||||
return MAC.Address[0] == this->Address[0] &&
|
||||
MAC.Address[1] == this->Address[1] &&
|
||||
MAC.Address[2] == this->Address[2] &&
|
||||
MAC.Address[3] == this->Address[3] &&
|
||||
MAC.Address[4] == this->Address[4] &&
|
||||
MAC.Address[5] == this->Address[5];
|
||||
}
|
||||
|
||||
inline bool operator!=(const MediaAccessControl &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint48_t &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const MediaAccessControl &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint48_t &lhs) const { return !(*this == lhs); }
|
||||
|
||||
inline uint48_t ToHex()
|
||||
{
|
||||
return ((uint48_t)this->Address[0] << 40) |
|
||||
((uint48_t)this->Address[1] << 32) |
|
||||
((uint48_t)this->Address[2] << 24) |
|
||||
((uint48_t)this->Address[3] << 16) |
|
||||
((uint48_t)this->Address[4] << 8) |
|
||||
((uint48_t)this->Address[5]);
|
||||
}
|
||||
inline uint48_t ToHex()
|
||||
{
|
||||
return ((uint48_t)this->Address[0] << 40) |
|
||||
((uint48_t)this->Address[1] << 32) |
|
||||
((uint48_t)this->Address[2] << 24) |
|
||||
((uint48_t)this->Address[3] << 16) |
|
||||
((uint48_t)this->Address[4] << 8) |
|
||||
((uint48_t)this->Address[5]);
|
||||
}
|
||||
|
||||
inline MediaAccessControl FromHex(uint48_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 40) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 32) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[3] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[4] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[5] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
inline MediaAccessControl FromHex(uint48_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 40) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 32) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[3] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[4] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[5] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool Valid()
|
||||
{
|
||||
// TODO: More complex MAC validation
|
||||
return (this->Address[0] != 0 ||
|
||||
this->Address[1] != 0 ||
|
||||
this->Address[2] != 0 ||
|
||||
this->Address[3] != 0 ||
|
||||
this->Address[4] != 0 ||
|
||||
this->Address[5] != 0) &&
|
||||
(this->Address[0] != 0xFF ||
|
||||
this->Address[1] != 0xFF ||
|
||||
this->Address[2] != 0xFF ||
|
||||
this->Address[3] != 0xFF ||
|
||||
this->Address[4] != 0xFF ||
|
||||
this->Address[5] != 0xFF);
|
||||
}
|
||||
inline bool Valid()
|
||||
{
|
||||
// TODO: More complex MAC validation
|
||||
return (this->Address[0] != 0 ||
|
||||
this->Address[1] != 0 ||
|
||||
this->Address[2] != 0 ||
|
||||
this->Address[3] != 0 ||
|
||||
this->Address[4] != 0 ||
|
||||
this->Address[5] != 0) &&
|
||||
(this->Address[0] != 0xFF ||
|
||||
this->Address[1] != 0xFF ||
|
||||
this->Address[2] != 0xFF ||
|
||||
this->Address[3] != 0xFF ||
|
||||
this->Address[4] != 0xFF ||
|
||||
this->Address[5] != 0xFF);
|
||||
}
|
||||
|
||||
char *ToString()
|
||||
{
|
||||
static char Buffer[18];
|
||||
sprintf(Buffer, "%02X:%02X:%02X:%02X:%02X:%02X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToString()
|
||||
{
|
||||
static char Buffer[18];
|
||||
sprintf(Buffer, "%02X:%02X:%02X:%02X:%02X:%02X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5]);
|
||||
return Buffer;
|
||||
}
|
||||
};
|
||||
|
||||
/* There's a confusion between LSB and MSB. Not sure if "ToStringLittleEndian" and "ToStringBigEndian" are implemented correctly.
|
||||
Because x86 is a LSB architecture, I'm assuming that the "ToStringLittleEndian" is correct? */
|
||||
struct InternetProtocol
|
||||
{
|
||||
struct Version4
|
||||
{
|
||||
uint8_t Address[4] = {255, 255, 255, 255};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
struct Version4
|
||||
{
|
||||
uint8_t Address[4] = {255, 255, 255, 255};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
inline bool operator==(const InternetProtocol::Version4 &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3];
|
||||
}
|
||||
inline bool operator==(const InternetProtocol::Version4 &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3];
|
||||
}
|
||||
|
||||
inline bool operator==(const uint32_t &lhs) const
|
||||
{
|
||||
InternetProtocol::Version4 IP;
|
||||
IP.Address[0] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
IP.Address[1] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
IP.Address[2] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
IP.Address[3] = (uint8_t)(lhs & 0xFF);
|
||||
inline bool operator==(const uint32_t &lhs) const
|
||||
{
|
||||
InternetProtocol::Version4 IP;
|
||||
IP.Address[0] = (uint8_t)((lhs >> 24) & 0xFF);
|
||||
IP.Address[1] = (uint8_t)((lhs >> 16) & 0xFF);
|
||||
IP.Address[2] = (uint8_t)((lhs >> 8) & 0xFF);
|
||||
IP.Address[3] = (uint8_t)(lhs & 0xFF);
|
||||
|
||||
return IP.Address[0] == this->Address[0] &&
|
||||
IP.Address[1] == this->Address[1] &&
|
||||
IP.Address[2] == this->Address[2] &&
|
||||
IP.Address[3] == this->Address[3];
|
||||
}
|
||||
return IP.Address[0] == this->Address[0] &&
|
||||
IP.Address[1] == this->Address[1] &&
|
||||
IP.Address[2] == this->Address[2] &&
|
||||
IP.Address[3] == this->Address[3];
|
||||
}
|
||||
|
||||
inline bool operator!=(const InternetProtocol::Version4 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint32_t &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const InternetProtocol::Version4 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const uint32_t &lhs) const { return !(*this == lhs); }
|
||||
|
||||
inline uint32_t ToHex()
|
||||
{
|
||||
return ((uint32_t)this->Address[0] << 24) |
|
||||
((uint32_t)this->Address[1] << 16) |
|
||||
((uint32_t)this->Address[2] << 8) |
|
||||
((uint32_t)this->Address[3]);
|
||||
}
|
||||
inline uint32_t ToHex()
|
||||
{
|
||||
return ((uint32_t)this->Address[0] << 24) |
|
||||
((uint32_t)this->Address[1] << 16) |
|
||||
((uint32_t)this->Address[2] << 8) |
|
||||
((uint32_t)this->Address[3]);
|
||||
}
|
||||
|
||||
inline InternetProtocol::Version4 FromHex(uint32_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[3] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
inline InternetProtocol::Version4 FromHex(uint32_t Hex)
|
||||
{
|
||||
this->Address[0] = (uint8_t)((Hex >> 24) & 0xFF);
|
||||
this->Address[1] = (uint8_t)((Hex >> 16) & 0xFF);
|
||||
this->Address[2] = (uint8_t)((Hex >> 8) & 0xFF);
|
||||
this->Address[3] = (uint8_t)(Hex & 0xFF);
|
||||
return *this;
|
||||
}
|
||||
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[0], this->Address[1], this->Address[2], this->Address[3]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[0], this->Address[1], this->Address[2], this->Address[3]);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v4;
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[16];
|
||||
sprintf(Buffer, "%d.%d.%d.%d", this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v4;
|
||||
|
||||
struct Version6
|
||||
{
|
||||
uint16_t Address[8] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
struct Version6
|
||||
{
|
||||
uint16_t Address[8] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
||||
Endianness Endianess = LITTLE_ENDIAN;
|
||||
|
||||
inline bool operator==(const InternetProtocol::Version6 &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3] &&
|
||||
lhs.Address[4] == this->Address[4] &&
|
||||
lhs.Address[5] == this->Address[5] &&
|
||||
lhs.Address[6] == this->Address[6] &&
|
||||
lhs.Address[7] == this->Address[7];
|
||||
}
|
||||
inline bool operator==(const InternetProtocol::Version6 &lhs) const
|
||||
{
|
||||
return lhs.Address[0] == this->Address[0] &&
|
||||
lhs.Address[1] == this->Address[1] &&
|
||||
lhs.Address[2] == this->Address[2] &&
|
||||
lhs.Address[3] == this->Address[3] &&
|
||||
lhs.Address[4] == this->Address[4] &&
|
||||
lhs.Address[5] == this->Address[5] &&
|
||||
lhs.Address[6] == this->Address[6] &&
|
||||
lhs.Address[7] == this->Address[7];
|
||||
}
|
||||
|
||||
inline bool operator!=(const InternetProtocol::Version6 &lhs) const { return !(*this == lhs); }
|
||||
inline bool operator!=(const InternetProtocol::Version6 &lhs) const { return !(*this == lhs); }
|
||||
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5], this->Address[6], this->Address[7]);
|
||||
return Buffer;
|
||||
}
|
||||
char *ToStringLittleEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[0], this->Address[1], this->Address[2], this->Address[3], this->Address[4], this->Address[5], this->Address[6], this->Address[7]);
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[7], this->Address[6], this->Address[5], this->Address[4], this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v6;
|
||||
char *ToStringBigEndian()
|
||||
{
|
||||
static char Buffer[40];
|
||||
sprintf(Buffer, "%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X", this->Address[7], this->Address[6], this->Address[5], this->Address[4], this->Address[3], this->Address[2], this->Address[1], this->Address[0]);
|
||||
return Buffer;
|
||||
}
|
||||
} v6;
|
||||
};
|
||||
|
||||
uint16_t CalculateChecksum(uint16_t *Data, size_t Length);
|
||||
|
@ -23,144 +23,144 @@
|
||||
|
||||
namespace NetworkNTP
|
||||
{
|
||||
struct NTPHeader
|
||||
{
|
||||
/** @brief Leap indicator
|
||||
* 00 - no warning
|
||||
* 01 - last minute has 61 seconds
|
||||
* 10 - last minute has 59 seconds
|
||||
* 11 - alarm condition (clock not synchronized)
|
||||
*/
|
||||
uint8_t LeapIndicator : 2;
|
||||
/** @brief Version number of the protocol
|
||||
* 3 - IPv4 only
|
||||
* 4 - IPv4, IPv6 and OSI
|
||||
* 5 - IPv4, IPv6 and OSI
|
||||
* 6 - IPv4, IPv6 and OSI
|
||||
* 7 - IPv4, IPv6 and OSI
|
||||
*/
|
||||
uint8_t VersionNumber : 3;
|
||||
/** @brief Mode
|
||||
* 0 - reserved
|
||||
* 1 - symmetric active
|
||||
* 2 - symmetric passive
|
||||
* 3 - client
|
||||
* 4 - server
|
||||
* 5 - broadcast
|
||||
* 6 - reserved for NTP control message
|
||||
* 7 - reserved for private use
|
||||
*/
|
||||
uint8_t Mode : 3;
|
||||
/** @brief Stratum
|
||||
* 0 - unspecified or unavailable
|
||||
* 1 - primary reference (e.g. radio clock)
|
||||
* 2-15 - secondary reference (via NTP or SNTP)
|
||||
* 16 - unsynchronized
|
||||
* 17-255 - reserved
|
||||
*/
|
||||
uint8_t Stratum;
|
||||
/** @brief Polling interval
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
* 8 - 256 seconds
|
||||
* 9 - 512 seconds
|
||||
* 10 - 1024 seconds
|
||||
* 11 - 2048 seconds
|
||||
* 12 - 4096 seconds
|
||||
* 13 - 8192 seconds
|
||||
* 14 - 16384 seconds
|
||||
* 15 - 32768 seconds
|
||||
*/
|
||||
uint8_t Poll;
|
||||
/** @brief Precision
|
||||
* -6 - 0.015625 seconds
|
||||
* -5 - 0.03125 seconds
|
||||
* -4 - 0.0625 seconds
|
||||
* -3 - 0.125 seconds
|
||||
* -2 - 0.25 seconds
|
||||
* -1 - 0.5 seconds
|
||||
* 0 - 1 second
|
||||
* 1 - 2 seconds
|
||||
* 2 - 4 seconds
|
||||
* 3 - 8 seconds
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
*/
|
||||
uint8_t Precision;
|
||||
/** @brief Root delay
|
||||
* Total round trip delay to the primary reference source
|
||||
*/
|
||||
uint32_t RootDelay;
|
||||
/** @brief Root dispersion
|
||||
* Nominal error relative to the primary reference source
|
||||
*/
|
||||
uint32_t RootDispersion;
|
||||
/** @brief Reference identifier
|
||||
* 0x00000000 - unspecified
|
||||
* 0x00000001 - radio clock
|
||||
* 0x00000002 - atomic clock
|
||||
* 0x00000003 - GPS receiver
|
||||
* 0x00000004 - local oscillator
|
||||
* 0x00000005 - LORAN-C receiver
|
||||
* 0x00000006 - microprocessor
|
||||
* 0x00000007 - internet
|
||||
* 0x00000008 - FLL
|
||||
* 0x00000009 - other
|
||||
* 0x0000000A - WWV
|
||||
* 0x0000000B - WWVB
|
||||
* 0x0000000C - WWVH
|
||||
* 0x0000000D - NIST dialup
|
||||
* 0x0000000E - telephone
|
||||
* 0x0000000F - reserved
|
||||
*/
|
||||
uint32_t ReferenceIdentifier;
|
||||
/** @brief Reference timestamp
|
||||
* The time at which the clock was last set or corrected
|
||||
*/
|
||||
uint32_t ReferenceTimestamp[2];
|
||||
/** @brief Originate timestamp
|
||||
* The time at which the request departed the client for the server
|
||||
*/
|
||||
uint32_t OriginateTimestamp[2];
|
||||
/** @brief Receive timestamp
|
||||
* The time at which the request arrived at the server
|
||||
*/
|
||||
uint32_t ReceiveTimestamp[2];
|
||||
/** @brief Transmit timestamp
|
||||
* The time at which the reply departed the server for the client
|
||||
*/
|
||||
uint32_t TransmitTimestamp[2];
|
||||
/** @brief Message authentication code
|
||||
* Key identifier
|
||||
* @note Only when the NTP authentication scheme is used
|
||||
*/
|
||||
// uint32_t MessageAuthenticationCode;
|
||||
} __packed;
|
||||
struct NTPHeader
|
||||
{
|
||||
/** @brief Leap indicator
|
||||
* 00 - no warning
|
||||
* 01 - last minute has 61 seconds
|
||||
* 10 - last minute has 59 seconds
|
||||
* 11 - alarm condition (clock not synchronized)
|
||||
*/
|
||||
uint8_t LeapIndicator : 2;
|
||||
/** @brief Version number of the protocol
|
||||
* 3 - IPv4 only
|
||||
* 4 - IPv4, IPv6 and OSI
|
||||
* 5 - IPv4, IPv6 and OSI
|
||||
* 6 - IPv4, IPv6 and OSI
|
||||
* 7 - IPv4, IPv6 and OSI
|
||||
*/
|
||||
uint8_t VersionNumber : 3;
|
||||
/** @brief Mode
|
||||
* 0 - reserved
|
||||
* 1 - symmetric active
|
||||
* 2 - symmetric passive
|
||||
* 3 - client
|
||||
* 4 - server
|
||||
* 5 - broadcast
|
||||
* 6 - reserved for NTP control message
|
||||
* 7 - reserved for private use
|
||||
*/
|
||||
uint8_t Mode : 3;
|
||||
/** @brief Stratum
|
||||
* 0 - unspecified or unavailable
|
||||
* 1 - primary reference (e.g. radio clock)
|
||||
* 2-15 - secondary reference (via NTP or SNTP)
|
||||
* 16 - unsynchronized
|
||||
* 17-255 - reserved
|
||||
*/
|
||||
uint8_t Stratum;
|
||||
/** @brief Polling interval
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
* 8 - 256 seconds
|
||||
* 9 - 512 seconds
|
||||
* 10 - 1024 seconds
|
||||
* 11 - 2048 seconds
|
||||
* 12 - 4096 seconds
|
||||
* 13 - 8192 seconds
|
||||
* 14 - 16384 seconds
|
||||
* 15 - 32768 seconds
|
||||
*/
|
||||
uint8_t Poll;
|
||||
/** @brief Precision
|
||||
* -6 - 0.015625 seconds
|
||||
* -5 - 0.03125 seconds
|
||||
* -4 - 0.0625 seconds
|
||||
* -3 - 0.125 seconds
|
||||
* -2 - 0.25 seconds
|
||||
* -1 - 0.5 seconds
|
||||
* 0 - 1 second
|
||||
* 1 - 2 seconds
|
||||
* 2 - 4 seconds
|
||||
* 3 - 8 seconds
|
||||
* 4 - 16 seconds
|
||||
* 5 - 32 seconds
|
||||
* 6 - 64 seconds
|
||||
* 7 - 128 seconds
|
||||
*/
|
||||
uint8_t Precision;
|
||||
/** @brief Root delay
|
||||
* Total round trip delay to the primary reference source
|
||||
*/
|
||||
uint32_t RootDelay;
|
||||
/** @brief Root dispersion
|
||||
* Nominal error relative to the primary reference source
|
||||
*/
|
||||
uint32_t RootDispersion;
|
||||
/** @brief Reference identifier
|
||||
* 0x00000000 - unspecified
|
||||
* 0x00000001 - radio clock
|
||||
* 0x00000002 - atomic clock
|
||||
* 0x00000003 - GPS receiver
|
||||
* 0x00000004 - local oscillator
|
||||
* 0x00000005 - LORAN-C receiver
|
||||
* 0x00000006 - microprocessor
|
||||
* 0x00000007 - internet
|
||||
* 0x00000008 - FLL
|
||||
* 0x00000009 - other
|
||||
* 0x0000000A - WWV
|
||||
* 0x0000000B - WWVB
|
||||
* 0x0000000C - WWVH
|
||||
* 0x0000000D - NIST dialup
|
||||
* 0x0000000E - telephone
|
||||
* 0x0000000F - reserved
|
||||
*/
|
||||
uint32_t ReferenceIdentifier;
|
||||
/** @brief Reference timestamp
|
||||
* The time at which the clock was last set or corrected
|
||||
*/
|
||||
uint32_t ReferenceTimestamp[2];
|
||||
/** @brief Originate timestamp
|
||||
* The time at which the request departed the client for the server
|
||||
*/
|
||||
uint32_t OriginateTimestamp[2];
|
||||
/** @brief Receive timestamp
|
||||
* The time at which the request arrived at the server
|
||||
*/
|
||||
uint32_t ReceiveTimestamp[2];
|
||||
/** @brief Transmit timestamp
|
||||
* The time at which the reply departed the server for the client
|
||||
*/
|
||||
uint32_t TransmitTimestamp[2];
|
||||
/** @brief Message authentication code
|
||||
* Key identifier
|
||||
* @note Only when the NTP authentication scheme is used
|
||||
*/
|
||||
// uint32_t MessageAuthenticationCode;
|
||||
} __packed;
|
||||
|
||||
class NTP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
bool TimeReceived = false;
|
||||
NTPHeader NTPPacket;
|
||||
class NTP : public NetworkUDP::UDPEvents
|
||||
{
|
||||
private:
|
||||
NetworkUDP::Socket *UDPSocket;
|
||||
bool TimeReceived = false;
|
||||
NTPHeader NTPPacket;
|
||||
|
||||
virtual void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void OnUDPPacketReceived(NetworkUDP::Socket *Socket, uint8_t *Data, size_t Length);
|
||||
|
||||
public:
|
||||
NTP(NetworkUDP::Socket *Socket);
|
||||
~NTP();
|
||||
public:
|
||||
NTP(NetworkUDP::Socket *Socket);
|
||||
~NTP();
|
||||
|
||||
/**
|
||||
* @brief Get the time from the NTP server
|
||||
*
|
||||
* @return Unix Timestamp
|
||||
*/
|
||||
int ReadTime();
|
||||
};
|
||||
/**
|
||||
* @brief Get the time from the NTP server
|
||||
*
|
||||
* @return Unix Timestamp
|
||||
*/
|
||||
int ReadTime();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_NTP_H__
|
||||
|
@ -25,73 +25,73 @@
|
||||
|
||||
namespace NetworkUDP
|
||||
{
|
||||
struct UDPHeader
|
||||
{
|
||||
uint16_t SourcePort;
|
||||
uint16_t DestinationPort;
|
||||
uint16_t Length;
|
||||
uint16_t Checksum;
|
||||
} __packed;
|
||||
struct UDPHeader
|
||||
{
|
||||
uint16_t SourcePort;
|
||||
uint16_t DestinationPort;
|
||||
uint16_t Length;
|
||||
uint16_t Checksum;
|
||||
} __packed;
|
||||
|
||||
struct UDPPacket
|
||||
{
|
||||
UDPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
struct UDPPacket
|
||||
{
|
||||
UDPHeader Header;
|
||||
uint8_t Data[];
|
||||
};
|
||||
|
||||
class Socket;
|
||||
class Socket;
|
||||
|
||||
class UDPEvents
|
||||
{
|
||||
protected:
|
||||
UDPEvents();
|
||||
~UDPEvents();
|
||||
class UDPEvents
|
||||
{
|
||||
protected:
|
||||
UDPEvents();
|
||||
~UDPEvents();
|
||||
|
||||
public:
|
||||
virtual void OnUDPPacketReceived(Socket *Socket, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Socket);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
}
|
||||
};
|
||||
public:
|
||||
virtual void OnUDPPacketReceived(Socket *Socket, uint8_t *Data, size_t Length)
|
||||
{
|
||||
UNUSED(Socket);
|
||||
UNUSED(Data);
|
||||
UNUSED(Length);
|
||||
warn("Not implemented.");
|
||||
}
|
||||
};
|
||||
|
||||
class UDP : public NetworkIPv4::IPv4Events
|
||||
{
|
||||
private:
|
||||
NetworkIPv4::IPv4 *ipv4;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
class UDP : public NetworkIPv4::IPv4Events
|
||||
{
|
||||
private:
|
||||
NetworkIPv4::IPv4 *ipv4;
|
||||
NetworkInterfaceManager::DeviceInterface *Interface;
|
||||
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
public:
|
||||
NetworkInterfaceManager::DeviceInterface *GetInterface() { return this->Interface; }
|
||||
|
||||
UDP(NetworkIPv4::IPv4 *ipv4, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~UDP();
|
||||
UDP(NetworkIPv4::IPv4 *ipv4, NetworkInterfaceManager::DeviceInterface *Interface);
|
||||
~UDP();
|
||||
|
||||
virtual Socket *Connect(InternetProtocol IP, uint16_t Port);
|
||||
virtual Socket *Listen(uint16_t Port);
|
||||
virtual void Disconnect(Socket *Socket);
|
||||
virtual void Send(Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void Bind(Socket *Socket, UDPEvents *EventHandler);
|
||||
virtual Socket *Connect(InternetProtocol IP, uint16_t Port);
|
||||
virtual Socket *Listen(uint16_t Port);
|
||||
virtual void Disconnect(Socket *Socket);
|
||||
virtual void Send(Socket *Socket, uint8_t *Data, size_t Length);
|
||||
virtual void Bind(Socket *Socket, UDPEvents *EventHandler);
|
||||
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length);
|
||||
};
|
||||
virtual bool OnIPv4PacketReceived(InternetProtocol SourceIP, InternetProtocol DestinationIP, uint8_t *Data, size_t Length);
|
||||
};
|
||||
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
InternetProtocol LocalIP;
|
||||
uint16_t LocalPort = 0;
|
||||
InternetProtocol RemoteIP;
|
||||
uint16_t RemotePort = 0;
|
||||
bool Listening = false;
|
||||
UDPEvents *EventHandler = nullptr;
|
||||
UDP *SocketUDP = nullptr;
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
InternetProtocol LocalIP;
|
||||
uint16_t LocalPort = 0;
|
||||
InternetProtocol RemoteIP;
|
||||
uint16_t RemotePort = 0;
|
||||
bool Listening = false;
|
||||
UDPEvents *EventHandler = nullptr;
|
||||
UDP *SocketUDP = nullptr;
|
||||
|
||||
Socket(UDP *_UDP);
|
||||
~Socket();
|
||||
};
|
||||
Socket(UDP *_UDP);
|
||||
~Socket();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_UDP_H__
|
||||
|
Reference in New Issue
Block a user