Details | 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: 1733 $ |
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 | |||
1514 | hidnplayr | 26 | virtual at NET_DEVICE.end |
27 | |||
28 | ETH_DEVICE: |
||
1519 | hidnplayr | 29 | |
1159 | hidnplayr | 30 | .set_mode dd ? |
31 | .get_mode dd ? |
||
32 | |||
1519 | hidnplayr | 33 | .set_MAC dd ? |
34 | .get_MAC dd ? |
||
35 | |||
1514 | hidnplayr | 36 | .mode dd ? |
1159 | hidnplayr | 37 | .mac dp ? |
38 | |||
1514 | hidnplayr | 39 | end virtual |
1159 | hidnplayr | 40 | |
41 | align 4 |
||
1196 | hidnplayr | 42 | iglobal |
43 | |||
44 | ETH_BROADCAST dp 0xffffffffffff |
||
45 | endg |
||
46 | |||
47 | align 4 |
||
1159 | hidnplayr | 48 | uglobal |
49 | ETH_RUNNING dd ? |
||
50 | endg |
||
51 | |||
52 | |||
1257 | hidnplayr | 53 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 54 | ; |
55 | ; ETH_init |
||
56 | ; |
||
57 | ; This function resets all ethernet variables |
||
58 | ; |
||
1257 | hidnplayr | 59 | ;----------------------------------------------------------------- |
1529 | hidnplayr | 60 | macro ETH_init { |
1159 | hidnplayr | 61 | |
1514 | hidnplayr | 62 | mov [ETH_RUNNING], 0 |
1159 | hidnplayr | 63 | |
1529 | hidnplayr | 64 | } |
1159 | hidnplayr | 65 | |
66 | |||
1257 | hidnplayr | 67 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 68 | ; |
1529 | hidnplayr | 69 | ; ETH_input |
1159 | hidnplayr | 70 | ; |
71 | ; This function is called by ethernet drivers, |
||
72 | ; It pushes the received ethernet packets onto the eth_in_queue |
||
73 | ; |
||
1514 | hidnplayr | 74 | ; IN: [esp] = Pointer to buffer |
1529 | hidnplayr | 75 | ; [esp+4] = size of buffer |
1514 | hidnplayr | 76 | ; ebx = pointer to eth_device |
1159 | hidnplayr | 77 | ; OUT: / |
78 | ; |
||
1257 | hidnplayr | 79 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 80 | align 4 |
1529 | hidnplayr | 81 | ETH_input: |
1473 | hidnplayr | 82 | mov eax, [esp] |
83 | mov ecx, [esp+4] |
||
1249 | hidnplayr | 84 | |
1529 | hidnplayr | 85 | DEBUGF 1,"ETH_input - size: %u\n", ecx |
1159 | hidnplayr | 86 | cmp ecx, 60 ; check packet length |
87 | jl .dump |
||
88 | sub ecx, ETH_FRAME.Data |
||
89 | |||
90 | lea edx, [eax + ETH_FRAME.Data] |
||
91 | mov ax , [eax + ETH_FRAME.Type] |
||
92 | |||
93 | cmp ax, ETHER_IPv4 |
||
1529 | hidnplayr | 94 | je IPv4_input |
1159 | hidnplayr | 95 | |
96 | cmp ax, ETHER_ARP |
||
1529 | hidnplayr | 97 | je ARP_input |
1159 | hidnplayr | 98 | |
1519 | hidnplayr | 99 | ; cmp ax, ETHER_PPP_DISCOVERY |
100 | ; je PPPOE_discovery |
||
101 | |||
1473 | hidnplayr | 102 | DEBUGF 2,"Unknown ethernet packet type %x\n", ax |
1159 | hidnplayr | 103 | |
104 | .dump: |
||
1529 | hidnplayr | 105 | DEBUGF 2,"ETH_input - dumping\n" |
1159 | hidnplayr | 106 | call kernel_free |
107 | add esp, 4 |
||
1249 | hidnplayr | 108 | ret |
1159 | hidnplayr | 109 | |
1249 | hidnplayr | 110 | ;----------------------------------------------------------------- |
111 | ; |
||
1529 | hidnplayr | 112 | ; ETH_output |
1159 | hidnplayr | 113 | ; |
1514 | hidnplayr | 114 | ; IN: eax = pointer to source mac |
1529 | hidnplayr | 115 | ; ebx = device ptr |
1514 | hidnplayr | 116 | ; ecx = packet size |
1529 | hidnplayr | 117 | ; edx = pointer to destination mac |
1514 | hidnplayr | 118 | ; di = protocol |
1159 | hidnplayr | 119 | ; |
1514 | hidnplayr | 120 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
121 | ; eax = buffer start |
||
122 | ; ebx = to device structure |
||
123 | ; ecx = unchanged (packet size of embedded data) |
||
124 | ; edx = size of complete buffer |
||
1159 | hidnplayr | 125 | ; |
1257 | hidnplayr | 126 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 127 | align 4 |
1529 | hidnplayr | 128 | ETH_output: |
1159 | hidnplayr | 129 | |
1529 | hidnplayr | 130 | DEBUGF 1,"ETH_output: size=%u device:%x\n", ecx, ebx |
1159 | hidnplayr | 131 | |
1529 | hidnplayr | 132 | cmp ecx, [ebx + NET_DEVICE.mtu] |
1159 | hidnplayr | 133 | jg .exit |
134 | |||
1529 | hidnplayr | 135 | push ecx ; << 1 |
136 | push di eax edx ; << 2 |
||
137 | add ecx, ETH_FRAME.Data |
||
1159 | hidnplayr | 138 | |
1529 | hidnplayr | 139 | push ecx ; << 3 |
140 | |||
141 | push ecx ; << 4 |
||
142 | call kernel_alloc ; >> 4 |
||
143 | test eax, eax |
||
144 | jz .out_of_ram |
||
1514 | hidnplayr | 145 | mov edi, eax |
1159 | hidnplayr | 146 | |
1529 | hidnplayr | 147 | pop ecx ; >> 3 |
1159 | hidnplayr | 148 | |
1529 | hidnplayr | 149 | pop esi ; >> 2 |
1159 | hidnplayr | 150 | movsd |
151 | movsw |
||
1529 | hidnplayr | 152 | pop esi ; >> 2 |
1159 | hidnplayr | 153 | movsd |
154 | movsw |
||
1529 | hidnplayr | 155 | pop ax ; >> 2 |
1159 | hidnplayr | 156 | stosw |
157 | |||
158 | lea eax, [edi - ETH_FRAME.Data] ; Set eax to buffer start |
||
1529 | hidnplayr | 159 | mov edx, ecx ; Set edx to complete buffer size |
1159 | hidnplayr | 160 | |
1529 | hidnplayr | 161 | pop ecx ; >> 1 |
1159 | hidnplayr | 162 | |
1529 | hidnplayr | 163 | cmp edx, 60-1 ; minimum ethernet packet size |
164 | jle .adjust_size |
||
165 | DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx |
||
166 | ret |
||
1206 | hidnplayr | 167 | |
1529 | hidnplayr | 168 | .adjust_size: |
169 | mov edx, 60 |
||
1536 | hidnplayr | 170 | test edx, edx ; clear zero flag |
1159 | hidnplayr | 171 | ret |
172 | |||
1529 | hidnplayr | 173 | .out_of_ram: |
174 | DEBUGF 2,"ETH_output: Out of ram space!!\n" |
||
175 | add esp, 3*4+2+4 |
||
176 | sub edi, edi |
||
1206 | hidnplayr | 177 | ret |
178 | |||
1159 | hidnplayr | 179 | .exit: |
1529 | hidnplayr | 180 | DEBUGF 2,"ETH_output: Packet too large!\n" |
181 | sub edi, edi |
||
182 | ;;; dec edi |
||
1159 | hidnplayr | 183 | ret |
184 | |||
185 | |||
186 | |||
1257 | hidnplayr | 187 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 188 | ; |
189 | ; ETH_API |
||
190 | ; |
||
191 | ; This function is called by system function 75 |
||
192 | ; |
||
193 | ; IN: subfunction number in bl |
||
194 | ; device number in bh |
||
195 | ; ecx, edx, .. depends on subfunction |
||
196 | ; |
||
197 | ; OUT: |
||
198 | ; |
||
1257 | hidnplayr | 199 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 200 | align 4 |
201 | ETH_API: |
||
202 | |||
1514 | hidnplayr | 203 | cmp bh, MAX_NET_DEVICES |
204 | jg .error |
||
1159 | hidnplayr | 205 | movzx eax, bh |
206 | shl eax, 2 |
||
207 | |||
1514 | hidnplayr | 208 | mov eax, dword [NET_DRV_LIST + eax] |
209 | cmp [eax + NET_DEVICE.type], NET_TYPE_ETH |
||
210 | jne .error |
||
211 | |||
1159 | hidnplayr | 212 | test bl, bl |
213 | jz .packets_tx ; 0 |
||
214 | dec bl |
||
215 | jz .packets_rx ; 1 |
||
216 | dec bl |
||
217 | jz .bytes_tx ; 2 |
||
218 | dec bl |
||
219 | jz .bytes_rx ; 3 |
||
220 | dec bl |
||
221 | jz .read_mac ; 4 |
||
222 | dec bl |
||
223 | jz .write_mac ; 5 |
||
224 | |||
1514 | hidnplayr | 225 | .error: |
226 | DEBUGF 2,"Device is not ethernet type\n" |
||
227 | or eax, -1 |
||
1159 | hidnplayr | 228 | ret |
229 | |||
230 | .packets_tx: |
||
1519 | hidnplayr | 231 | mov eax, dword [eax + NET_DEVICE.packets_tx] |
1171 | hidnplayr | 232 | |
1159 | hidnplayr | 233 | ret |
234 | |||
235 | .packets_rx: |
||
1519 | hidnplayr | 236 | mov eax, dword [eax + NET_DEVICE.packets_rx] |
1159 | hidnplayr | 237 | ret |
238 | |||
239 | .bytes_tx: |
||
1519 | hidnplayr | 240 | mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4] |
241 | mov eax, dword [eax + NET_DEVICE.bytes_tx] |
||
1174 | hidnplayr | 242 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 243 | ret |
244 | |||
245 | .bytes_rx: |
||
1519 | hidnplayr | 246 | mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4] |
247 | mov eax, dword [eax + NET_DEVICE.bytes_rx] |
||
1174 | hidnplayr | 248 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 249 | ret |
250 | |||
1174 | hidnplayr | 251 | |
1159 | hidnplayr | 252 | .read_mac: |
253 | movzx ebx, word [eax + ETH_DEVICE.mac] |
||
254 | mov eax, dword [eax + ETH_DEVICE.mac + 2] |
||
1171 | hidnplayr | 255 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
1159 | hidnplayr | 256 | ret |
257 | |||
258 | .write_mac: |
||
259 | push ecx |
||
260 | push dx |
||
1519 | hidnplayr | 261 | call [eax + ETH_DEVICE.set_MAC] |
1159 | hidnplayr | 262 | ret><>><>><>><> |
263 |