SayoriOS  0.3.3
ethernet.h
1 #pragma once
2 
3 #include "common.h"
4 #include "net/cards.h"
5 
6 #define ETHERNET_TYPE_IPV4 0x0800
7 #define ETHERNET_TYPE_ARP 0x0806
8 #define ETHERNET_TYPE_WoL 0x0842
9 #define ETHERNET_TYPE_SRP 0x22EA
10 #define ETHERNET_TYPE_AVTP 0x22F0
11 #define ETHERNET_TYPE_IETF 0x22F3
12 #define ETHERNET_TYPE_DECMOP 0x6002
13 #define ETHERNET_TYPE_DECNET 0x6003
14 #define ETHERNET_TYPE_DECLAT 0x6004
15 #define ETHERNET_TYPE_RASP 0x8035
16 #define ETHERNET_TYPE_ATE 0x809B
17 #define ETHERNET_TYPE_ATARP 0x80F3
18 #define ETHERNET_TYPE_VLAN 0x8100
19 #define ETHERNET_TYPE_SLPP 0x8102
20 #define ETHERNET_TYPE_VLACP 0x8103
21 #define ETHERNET_TYPE_IPX 0x8137
22 #define ETHERNET_TYPE_QNX 0x8204
23 #define ETHERNET_TYPE_IPV6 0x86DD
24 #define ETHERNET_TYPE_EFC 0x8808
25 #define ETHERNET_TYPE_ESP 0x8809
27 #define ETHERNET_TYPE_COBRA 0x8819
28 #define ETHERNET_TYPE_MPLSU 0x8847
29 #define ETHERNET_TYPE_MPLSM 0x8848
30 #define ETHERNET_TYPE_PPPoEDS 0x8863
31 #define ETHERNET_TYPE_PPPoESS 0x8864
32 #define ETHERNET_TYPE_HP1MME 0x887B
33 #define ETHERNET_TYPE_EAPoLAN 0x888E
34 #define ETHERNET_TYPE_PROFINET 0x8892
35 #define ETHERNET_TYPE_HYPERSCSI 0x889A
36 #define ETHERNET_TYPE_ATAoE 0x88A2
37 #define ETHERNET_TYPE_ECAT 0x88A4
38 #define ETHERNET_TYPE_SVLAN 0x88A8
39 #define ETHERNET_TYPE_POWLINK 0x88AB
40 #define ETHERNET_TYPE_GOOSE 0x88B8
41 #define ETHERNET_TYPE_GSE 0x88B9
42 #define ETHERNET_TYPE_SV 0x88BA
43 #define ETHERNET_TYPE_MTRMN 0x88BA
44 #define ETHERNET_TYPE_LLDP 0x88CC
45 #define ETHERNET_TYPE_SCSIII 0x88CD
46 #define ETHERNET_TYPE_HPGPHY 0x88E1
47 #define ETHERNET_TYPE_MRP 0x88E3
48 #define ETHERNET_TYPE_MACSEC 0x88E5
49 #define ETHERNET_TYPE_PBB 0x88E7
50 #define ETHERNET_TYPE_PTP 0x88F7
51 #define ETHERNET_TYPE_NCSI 0x88F8
52 #define ETHERNET_TYPE_PRP 0x88FB
53 #define ETHERNET_TYPE_CFM 0x8902
54 #define ETHERNET_TYPE_FCoE 0x8906
55 #define ETHERNET_TYPE_FCoEI 0x8914
56 #define ETHERNET_TYPE_RoCE 0x8915
57 #define ETHERNET_TYPE_TTE 0x891D
58 #define ETHERNET_TYPE_1905 0x893A
59 #define ETHERNET_TYPE_HSR 0x892F
60 #define ETHERNET_TYPE_ECTP 0x9000
61 #define ETHERNET_TYPE_RT 0xF1C1
62 
63 #define ETH_IPv6_HEAD_ICMPv6 0x3a
64 #define ETH_IPv6_HEAD_UDP 0x11
65 
66 #define ETH_IPv4_HEAD_ICMPv4 1
67 #define ETH_IPv4_HEAD_UDP 0x11
68 #define ETH_IPv4_HEAD_TCP 6
69 
70 #define ETH_ICMPv4_TYPE_PING 8
71 #define ETH_ICMPv6_TYPE_PING 128
72 
73 #define HARDWARE_TYPE_ETHERNET 0x01
74 
75 typedef struct ethernet_frame {
76  uint8_t dest_mac[6];
77  uint8_t src_mac[6];
78  uint16_t type;
79  uint8_t data[];
80 } __attribute__((packed)) ethernet_frame_t;
81 
82 typedef struct {
83  uint8_t Type;
84  uint8_t Size;
85  uint8_t MAC[6];
86 } __attribute__((packed)) ETH_IPv6_OPT_PKG;
87 
88 typedef struct {
89  uint8_t Version;
90  uint8_t Flow[3];
91  uint16_t PayLoad;
92  uint8_t NextHead;
93  uint8_t HopLimit;
94  uint16_t Source[8];
95  uint16_t Destination[8];
96 } __attribute__((packed)) ETH_IPv6_PKG;
97 
98 
99 typedef struct {
100  uint8_t Type;
101  uint8_t Code;
102  uint16_t CheckSum;
103  uint32_t Reserved;
104  ETH_IPv6_OPT_PKG Opt;
105 } __attribute__((packed)) ETH_ICMPv6_PKG;
106 
107 typedef struct {
108  uint8_t HeaderLength : 4;
109  uint8_t Version : 4;
110  uint8_t DSF;
111  uint16_t TotalLength;
112  uint16_t ID;
113  uint16_t Flags;
114  uint8_t TimeLife;
115  uint8_t Protocol;
116  uint16_t Checksum;
117  uint8_t Source[4];
118  uint8_t Destination[4];
119 } __attribute__((packed)) ETH_IPv4_PKG;
120 
121 
122 typedef struct {
123  uint16_t SourcePort;
124  uint16_t DestinationPort;
125  uint16_t Length;
126  uint16_t CheckSum;
127 } __attribute__((packed)) ETH_UDP_PKG;
128 
129 
130 typedef struct {
131  uint8_t Type;
132  uint8_t Code;
133  uint16_t CheckSum;
134  uint16_t IDBE;
135  uint16_t SNBE;
136  uint8_t Timestamp[8];
137 } __attribute__((packed)) ETH_ICMPv4_PKG;
138 
139 
140 void ethernet_send_packet(netcard_entry_t* card, uint8_t* dest_mac, uint8_t* data, size_t len, uint16_t type);
141 void ethernet_handle_packet(netcard_entry_t *card, ethernet_frame_t *packet, size_t len);
Основные определения ядра
struct registers __attribute__((packed))
Структура данных пакета от мыши
Definition: psf.h:19
Definition: cards.h:5