diff options
author | Marvin Borner | 2020-09-27 13:17:55 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-27 13:17:55 +0200 |
commit | 9286bba7b273301dd777dd15feec40492ccd9a03 (patch) | |
tree | 680be140917394568830ef7efc14cb79b77bb671 /kernel/inc | |
parent | cac7c352a1ece2744de42128a9c69df16f05d26a (diff) |
Added UDP, DHCP, ARP
Quite awesome, IMHO
Diffstat (limited to 'kernel/inc')
-rw-r--r-- | kernel/inc/net.h | 56 | ||||
-rw-r--r-- | kernel/inc/rtl8139.h | 2 |
2 files changed, 57 insertions, 1 deletions
diff --git a/kernel/inc/net.h b/kernel/inc/net.h index 943583a..2d0dbe7 100644 --- a/kernel/inc/net.h +++ b/kernel/inc/net.h @@ -20,6 +20,17 @@ #define IP_PROT_TCP 0x06 #define IP_PROT_UDP 0x11 +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +#define DHCP_REQUEST 1 +#define DHCP_REPLY 2 +#define DHCP_TRANSACTION_IDENTIFIER 0x55555555 + +#define HARDWARE_TYPE_ETHERNET 0x01 + +// Protocol structs + struct ethernet_packet { u8 dst[6]; u8 src[6]; @@ -27,6 +38,18 @@ struct ethernet_packet { u8 data[]; } __attribute__((packed)); +struct arp_packet { + u16 hardware_type; + u16 protocol; + u8 hardware_addr_len; + u8 protocol_addr_len; + u16 opcode; + u8 src_mac[6]; + u32 src_protocol_addr; + u8 dst_mac[6]; + u32 dst_protocol_addr; +} __attribute__((packed)); + struct ip_packet { u8 version_ihl; u8 dscp_ecn; @@ -41,12 +64,45 @@ struct ip_packet { u8 data[]; } __attribute__((packed)); +struct dhcp_packet { + u8 op; + u8 hardware_type; + u8 hardware_addr_len; + u8 hops; + u32 xid; + u16 seconds; + u16 flags; + u32 client_ip; + u32 your_ip; + u32 server_ip; + u32 gateway_ip; + u8 client_hardware_addr[16]; + u8 server_name[64]; + u8 file[128]; + u8 options[64]; +} __attribute__((packed)); + +struct udp_packet { + u16 src_port; + u16 dst_port; + u16 length; + u16 checksum; + u8 data[]; +} __attribute__((packed)); + struct icmp_packet { u8 type; u8 version; u16 checksum; } __attribute__((packed)); +// Other structs + +struct arp_table_entry { + u32 ip_addr; + u64 mac_addr; +}; + void ethernet_handle_packet(struct ethernet_packet *packet, int len); void net_install(); diff --git a/kernel/inc/rtl8139.h b/kernel/inc/rtl8139.h index e12f315..d84d115 100644 --- a/kernel/inc/rtl8139.h +++ b/kernel/inc/rtl8139.h @@ -28,7 +28,7 @@ #define RTL_PORT_RXMISS 0x4C #define RTL_PORT_CONFIG 0x52 -void rtl8139_install(); +int rtl8139_install(); void rtl8139_send_packet(void *data, u32 len); u8 *rtl8139_get_mac(); |