Rev 2300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1159 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
1514 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; |
1159 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; ETHERNET.INC ;; |
||
7 | ;; ;; |
||
8 | ;; Ethernet network layer for KolibriOS ;; |
||
9 | ;; ;; |
||
10 | ;; Written by hidnplayr@kolibrios.org ;; |
||
11 | ;; ;; |
||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
13 | ;; Version 2, June 1991 ;; |
||
14 | ;; ;; |
||
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
16 | |||
1206 | hidnplayr | 17 | $Revision: 2301 $ |
1159 | hidnplayr | 18 | |
19 | struct ETH_FRAME |
||
1514 | hidnplayr | 20 | .DstMAC dp ? ; destination MAC-address |
21 | .SrcMAC dp ? ; source MAC-address |
||
22 | .Type dw ? ; type of the upper-layer protocol |
||
23 | .Data: ; data (46-1500 bytes for a normal packet) |
||
1159 | hidnplayr | 24 | ends |
25 | |||
2301 | hidnplayr | 26 | ETH_FRAME_MINIMUM equ 60 |
27 | |||
1514 | hidnplayr | 28 | virtual at NET_DEVICE.end |
29 | |||
30 | ETH_DEVICE: |
||
1519 | hidnplayr | 31 | |
1159 | hidnplayr | 32 | .set_mode dd ? |
33 | .get_mode dd ? |
||
34 | |||
1519 | hidnplayr | 35 | .set_MAC dd ? |
36 | .get_MAC dd ? |
||
37 | |||
1514 | hidnplayr | 38 | .mode dd ? |
1159 | hidnplayr | 39 | .mac dp ? |
40 | |||
1514 | hidnplayr | 41 | end virtual |
1159 | hidnplayr | 42 | |
43 | align 4 |
||
1196 | hidnplayr | 44 | iglobal |
45 | |||
46 | ETH_BROADCAST dp 0xffffffffffff |
||
47 | endg |
||
48 | |||
1257 | hidnplayr | 49 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 50 | ; |
1529 | hidnplayr | 51 | ; ETH_input |
1159 | hidnplayr | 52 | ; |
53 | ; This function is called by ethernet drivers, |
||
54 | ; It pushes the received ethernet packets onto the eth_in_queue |
||
55 | ; |
||
1514 | hidnplayr | 56 | ; IN: [esp] = Pointer to buffer |
1529 | hidnplayr | 57 | ; [esp+4] = size of buffer |
1514 | hidnplayr | 58 | ; ebx = pointer to eth_device |
1159 | hidnplayr | 59 | ; OUT: / |
60 | ; |
||
1257 | hidnplayr | 61 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 62 | align 4 |
1529 | hidnplayr | 63 | ETH_input: |
1473 | hidnplayr | 64 | mov eax, [esp] |
65 | mov ecx, [esp+4] |
||
1249 | hidnplayr | 66 | |
1529 | hidnplayr | 67 | DEBUGF 1,"ETH_input - size: %u\n", ecx |
2301 | hidnplayr | 68 | cmp ecx, ETH_FRAME_MINIMUM |
2300 | hidnplayr | 69 | jb .dump |
1159 | hidnplayr | 70 | sub ecx, ETH_FRAME.Data |
71 | |||
72 | lea edx, [eax + ETH_FRAME.Data] |
||
73 | mov ax , [eax + ETH_FRAME.Type] |
||
74 | |||
75 | cmp ax, ETHER_IPv4 |
||
1529 | hidnplayr | 76 | je IPv4_input |
1159 | hidnplayr | 77 | |
78 | cmp ax, ETHER_ARP |
||
1529 | hidnplayr | 79 | je ARP_input |
1159 | hidnplayr | 80 | |
1519 | hidnplayr | 81 | ; cmp ax, ETHER_PPP_DISCOVERY |
82 | ; je PPPOE_discovery |
||
83 | |||
1473 | hidnplayr | 84 | DEBUGF 2,"Unknown ethernet packet type %x\n", ax |
1159 | hidnplayr | 85 | |
86 | .dump: |
||
1529 | hidnplayr | 87 | DEBUGF 2,"ETH_input - dumping\n" |
1159 | hidnplayr | 88 | call kernel_free |
89 | add esp, 4 |
||
1249 | hidnplayr | 90 | ret |
1159 | hidnplayr | 91 | |
1249 | hidnplayr | 92 | ;----------------------------------------------------------------- |
93 | ; |
||
1529 | hidnplayr | 94 | ; ETH_output |
1159 | hidnplayr | 95 | ; |
1514 | hidnplayr | 96 | ; IN: eax = pointer to source mac |
1529 | hidnplayr | 97 | ; ebx = device ptr |
1514 | hidnplayr | 98 | ; ecx = packet size |
1529 | hidnplayr | 99 | ; edx = pointer to destination mac |
1514 | hidnplayr | 100 | ; di = protocol |
1159 | hidnplayr | 101 | ; |
1514 | hidnplayr | 102 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
103 | ; eax = buffer start |
||
104 | ; ebx = to device structure |
||
105 | ; ecx = unchanged (packet size of embedded data) |
||
106 | ; edx = size of complete buffer |
||
1159 | hidnplayr | 107 | ; |
1257 | hidnplayr | 108 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 109 | align 4 |
1529 | hidnplayr | 110 | ETH_output: |
1159 | hidnplayr | 111 | |
1529 | hidnplayr | 112 | DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx |
1159 | hidnplayr | 113 | |
1529 | hidnplayr | 114 | cmp ecx, [ebx + NET_DEVICE.mtu] |
2300 | hidnplayr | 115 | ja .exit |
1159 | hidnplayr | 116 | |
1529 | hidnplayr | 117 | push ecx ; << 1 |
118 | push di eax edx ; << 2 |
||
119 | add ecx, ETH_FRAME.Data |
||
1159 | hidnplayr | 120 | |
1529 | hidnplayr | 121 | push ecx ; << 3 |
122 | |||
123 | push ecx ; << 4 |
||
124 | call kernel_alloc ; >> 4 |
||
125 | test eax, eax |
||
126 | jz .out_of_ram |
||
1514 | hidnplayr | 127 | mov edi, eax |
1159 | hidnplayr | 128 | |
1529 | hidnplayr | 129 | pop ecx ; >> 3 |
1159 | hidnplayr | 130 | |
1529 | hidnplayr | 131 | pop esi ; >> 2 |
1159 | hidnplayr | 132 | movsd |
133 | movsw |
||
1529 | hidnplayr | 134 | pop esi ; >> 2 |
1159 | hidnplayr | 135 | movsd |
136 | movsw |
||
1529 | hidnplayr | 137 | pop ax ; >> 2 |
1159 | hidnplayr | 138 | stosw |
139 | |||
140 | lea eax, [edi - ETH_FRAME.Data] ; Set eax to buffer start |
||
1529 | hidnplayr | 141 | mov edx, ecx ; Set edx to complete buffer size |
1159 | hidnplayr | 142 | |
1529 | hidnplayr | 143 | pop ecx ; >> 1 |
1159 | hidnplayr | 144 | |
2301 | hidnplayr | 145 | cmp edx, ETH_FRAME_MINIMUM |
2300 | hidnplayr | 146 | jb .adjust_size |
1529 | hidnplayr | 147 | DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx |
148 | ret |
||
1206 | hidnplayr | 149 | |
1529 | hidnplayr | 150 | .adjust_size: |
2301 | hidnplayr | 151 | mov edx, ETH_FRAME_MINIMUM |
1536 | hidnplayr | 152 | test edx, edx ; clear zero flag |
1159 | hidnplayr | 153 | ret |
154 | |||
1529 | hidnplayr | 155 | .out_of_ram: |
156 | DEBUGF 2,"ETH_output: Out of ram space!!\n" |
||
157 | add esp, 3*4+2+4 |
||
158 | sub edi, edi |
||
1206 | hidnplayr | 159 | ret |
160 | |||
1159 | hidnplayr | 161 | .exit: |
1529 | hidnplayr | 162 | DEBUGF 2,"ETH_output: Packet too large!\n" |
163 | sub edi, edi |
||
164 | ;;; dec edi |
||
1159 | hidnplayr | 165 | ret |
166 | |||
167 | |||
168 | |||
1257 | hidnplayr | 169 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 170 | ; |
171 | ; ETH_API |
||
172 | ; |
||
173 | ; This function is called by system function 75 |
||
174 | ; |
||
175 | ; IN: subfunction number in bl |
||
176 | ; device number in bh |
||
177 | ; ecx, edx, .. depends on subfunction |
||
178 | ; |
||
179 | ; OUT: |
||
180 | ; |
||
1257 | hidnplayr | 181 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 182 | align 4 |
183 | ETH_API: |
||
184 | |||
1514 | hidnplayr | 185 | cmp bh, MAX_NET_DEVICES |
2300 | hidnplayr | 186 | ja .error |
1159 | hidnplayr | 187 | movzx eax, bh |
188 | shl eax, 2 |
||
189 | |||
1514 | hidnplayr | 190 | mov eax, dword [NET_DRV_LIST + eax] |
191 | cmp [eax + NET_DEVICE.type], NET_TYPE_ETH |
||
192 | jne .error |
||
193 | |||
1159 | hidnplayr | 194 | test bl, bl |
195 | jz .packets_tx ; 0 |
||
196 | dec bl |
||
197 | jz .packets_rx ; 1 |
||
198 | dec bl |
||
199 | jz .bytes_tx ; 2 |
||
200 | dec bl |
||
201 | jz .bytes_rx ; 3 |
||
202 | dec bl |
||
203 | jz .read_mac ; 4 |
||
204 | dec bl |
||
205 | jz .write_mac ; 5 |
||
206 | |||
1514 | hidnplayr | 207 | .error: |
208 | DEBUGF 2,"Device is not ethernet type\n" |
||
209 | or eax, -1 |
||
1159 | hidnplayr | 210 | ret |
211 | |||
212 | .packets_tx: |
||
1519 | hidnplayr | 213 | mov eax, dword [eax + NET_DEVICE.packets_tx] |
1171 | hidnplayr | 214 | |
1159 | hidnplayr | 215 | ret |
216 | |||
217 | .packets_rx: |
||
1519 | hidnplayr | 218 | mov eax, dword [eax + NET_DEVICE.packets_rx] |
1159 | hidnplayr | 219 | ret |
220 | |||
221 | .bytes_tx: |
||
1519 | hidnplayr | 222 | mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4] |
223 | mov eax, dword [eax + NET_DEVICE.bytes_tx] |
||
1174 | hidnplayr | 224 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 225 | ret |
226 | |||
227 | .bytes_rx: |
||
1519 | hidnplayr | 228 | mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4] |
229 | mov eax, dword [eax + NET_DEVICE.bytes_rx] |
||
1174 | hidnplayr | 230 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 231 | ret |
232 | |||
1174 | hidnplayr | 233 | |
1159 | hidnplayr | 234 | .read_mac: |
235 | movzx ebx, word [eax + ETH_DEVICE.mac] |
||
236 | mov eax, dword [eax + ETH_DEVICE.mac + 2] |
||
1171 | hidnplayr | 237 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 238 | ret |
239 | |||
240 | .write_mac: |
||
241 | push ecx |
||
242 | push dx |
||
1519 | hidnplayr | 243 | call [eax + ETH_DEVICE.set_MAC] |
1159 | hidnplayr | 244 | ret><>><>><>><> |
245 |