Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1159 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3185 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2013. 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: 3346 $ |
1159 | hidnplayr | 18 | |
2731 | hidnplayr | 19 | ETH_FRAME_MINIMUM = 60 |
20 | |||
2311 | hidnplayr | 21 | struct ETH_header |
2305 | hidnplayr | 22 | |
2311 | hidnplayr | 23 | DstMAC dp ? ; destination MAC-address |
24 | SrcMAC dp ? ; source MAC-address |
||
25 | Type dw ? ; type of the upper-layer protocol |
||
2305 | hidnplayr | 26 | |
1159 | hidnplayr | 27 | ends |
28 | |||
2311 | hidnplayr | 29 | struct ETH_DEVICE NET_DEVICE |
1514 | hidnplayr | 30 | |
2311 | hidnplayr | 31 | mac dp ? |
1519 | hidnplayr | 32 | |
2305 | hidnplayr | 33 | ends |
1159 | hidnplayr | 34 | |
35 | align 4 |
||
1196 | hidnplayr | 36 | iglobal |
37 | |||
2311 | hidnplayr | 38 | ETH_BROADCAST dp 0xffffffffffff |
1196 | hidnplayr | 39 | endg |
40 | |||
1257 | hidnplayr | 41 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 42 | ; |
1529 | hidnplayr | 43 | ; ETH_input |
1159 | hidnplayr | 44 | ; |
45 | ; This function is called by ethernet drivers, |
||
46 | ; It pushes the received ethernet packets onto the eth_in_queue |
||
47 | ; |
||
1514 | hidnplayr | 48 | ; IN: [esp] = Pointer to buffer |
1529 | hidnplayr | 49 | ; [esp+4] = size of buffer |
1514 | hidnplayr | 50 | ; ebx = pointer to eth_device |
1159 | hidnplayr | 51 | ; OUT: / |
52 | ; |
||
1257 | hidnplayr | 53 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 54 | align 4 |
1529 | hidnplayr | 55 | ETH_input: |
2311 | hidnplayr | 56 | mov eax, [esp] |
57 | mov ecx, [esp+4] |
||
1249 | hidnplayr | 58 | |
2891 | hidnplayr | 59 | DEBUGF 1,"ETH_input: size=%u\n", ecx |
2311 | hidnplayr | 60 | cmp ecx, ETH_FRAME_MINIMUM |
61 | jb .dump |
||
62 | sub ecx, sizeof.ETH_header |
||
1159 | hidnplayr | 63 | |
2311 | hidnplayr | 64 | lea edx, [eax + sizeof.ETH_header] |
2731 | hidnplayr | 65 | mov ax, [eax + ETH_header.Type] |
1159 | hidnplayr | 66 | |
2311 | hidnplayr | 67 | cmp ax, ETHER_IPv4 |
68 | je IPv4_input |
||
1159 | hidnplayr | 69 | |
2311 | hidnplayr | 70 | cmp ax, ETHER_ARP |
71 | je ARP_input |
||
1159 | hidnplayr | 72 | |
3185 | hidnplayr | 73 | cmp ax, ETHER_IPv6 |
74 | je IPv6_input |
||
2731 | hidnplayr | 75 | |
2931 | hidnplayr | 76 | cmp ax, ETHER_PPP_DISCOVERY |
77 | je PPPoE_discovery_input |
||
1519 | hidnplayr | 78 | |
2931 | hidnplayr | 79 | cmp ax, ETHER_PPP_SESSION |
80 | je PPPoE_session_input |
||
2731 | hidnplayr | 81 | |
2891 | hidnplayr | 82 | DEBUGF 2,"ETH_input: Unknown packet type=%x\n", ax |
1159 | hidnplayr | 83 | |
84 | .dump: |
||
2891 | hidnplayr | 85 | DEBUGF 2,"ETH_input: dumping\n" |
2311 | hidnplayr | 86 | call kernel_free |
87 | add esp, 4 |
||
88 | ret |
||
1159 | hidnplayr | 89 | |
1249 | hidnplayr | 90 | ;----------------------------------------------------------------- |
91 | ; |
||
1529 | hidnplayr | 92 | ; ETH_output |
1159 | hidnplayr | 93 | ; |
1514 | hidnplayr | 94 | ; IN: eax = pointer to source mac |
1529 | hidnplayr | 95 | ; ebx = device ptr |
1514 | hidnplayr | 96 | ; ecx = packet size |
1529 | hidnplayr | 97 | ; edx = pointer to destination mac |
1514 | hidnplayr | 98 | ; di = protocol |
1159 | hidnplayr | 99 | ; |
1514 | hidnplayr | 100 | ; OUT: edi = 0 on error, pointer to buffer otherwise |
101 | ; eax = buffer start |
||
102 | ; ebx = to device structure |
||
103 | ; ecx = unchanged (packet size of embedded data) |
||
104 | ; edx = size of complete buffer |
||
1159 | hidnplayr | 105 | ; |
1257 | hidnplayr | 106 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 107 | align 4 |
1529 | hidnplayr | 108 | ETH_output: |
1159 | hidnplayr | 109 | |
2891 | hidnplayr | 110 | DEBUGF 1,"ETH_output: size=%u device=%x\n", ecx, ebx |
1159 | hidnplayr | 111 | |
2311 | hidnplayr | 112 | cmp ecx, [ebx + NET_DEVICE.mtu] |
113 | ja .exit |
||
1159 | hidnplayr | 114 | |
2311 | hidnplayr | 115 | push ecx |
116 | push di eax edx |
||
1159 | hidnplayr | 117 | |
2311 | hidnplayr | 118 | add ecx, sizeof.ETH_header |
119 | stdcall kernel_alloc, ecx |
||
120 | test eax, eax |
||
121 | jz .out_of_ram |
||
122 | mov edi, eax |
||
1529 | hidnplayr | 123 | |
2311 | hidnplayr | 124 | pop esi |
125 | movsd |
||
126 | movsw |
||
127 | pop esi |
||
128 | movsd |
||
129 | movsw |
||
130 | pop ax |
||
131 | stosw |
||
1159 | hidnplayr | 132 | |
2311 | hidnplayr | 133 | lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start |
134 | pop ecx |
||
135 | lea edx, [ecx + sizeof.ETH_header] ; Set edx to complete buffer size |
||
1159 | hidnplayr | 136 | |
2311 | hidnplayr | 137 | cmp edx, ETH_FRAME_MINIMUM |
2607 | hidnplayr | 138 | jbe .adjust_size |
139 | .done: |
||
2891 | hidnplayr | 140 | DEBUGF 1,"ETH_output: ptr=%x size=%u\n", eax, edx |
2311 | hidnplayr | 141 | ret |
1159 | hidnplayr | 142 | |
1529 | hidnplayr | 143 | .adjust_size: |
2311 | hidnplayr | 144 | mov edx, ETH_FRAME_MINIMUM |
145 | test edx, edx ; clear zero flag |
||
2607 | hidnplayr | 146 | jmp .done |
1159 | hidnplayr | 147 | |
1529 | hidnplayr | 148 | .out_of_ram: |
2891 | hidnplayr | 149 | DEBUGF 2,"ETH_output: Out of ram!\n" |
2311 | hidnplayr | 150 | add esp, 4+4+2+4 |
151 | sub edi, edi |
||
152 | ret |
||
1206 | hidnplayr | 153 | |
1159 | hidnplayr | 154 | .exit: |
2311 | hidnplayr | 155 | DEBUGF 2,"ETH_output: Packet too large!\n" |
156 | sub edi, edi |
||
157 | ret |
||
1159 | hidnplayr | 158 | |
159 | |||
160 | |||
1257 | hidnplayr | 161 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 162 | ; |
163 | ; ETH_API |
||
164 | ; |
||
165 | ; This function is called by system function 75 |
||
166 | ; |
||
167 | ; IN: subfunction number in bl |
||
168 | ; device number in bh |
||
169 | ; ecx, edx, .. depends on subfunction |
||
170 | ; |
||
171 | ; OUT: |
||
172 | ; |
||
1257 | hidnplayr | 173 | ;----------------------------------------------------------------- |
1159 | hidnplayr | 174 | align 4 |
2614 | hidnplayr | 175 | ETH_api: |
1159 | hidnplayr | 176 | |
2311 | hidnplayr | 177 | cmp bh, MAX_NET_DEVICES |
178 | ja .error |
||
179 | movzx eax, bh |
||
2614 | hidnplayr | 180 | mov eax, dword [NET_DRV_LIST + 4*eax] |
2311 | hidnplayr | 181 | cmp [eax + NET_DEVICE.type], NET_TYPE_ETH |
182 | jne .error |
||
1514 | hidnplayr | 183 | |
2614 | hidnplayr | 184 | and ebx, 0xff |
185 | cmp ebx, .number |
||
186 | ja .error |
||
187 | jmp dword [.table + 4*ebx] |
||
1159 | hidnplayr | 188 | |
2614 | hidnplayr | 189 | .table: |
190 | dd .packets_tx ; 0 |
||
191 | dd .packets_rx ; 1 |
||
192 | dd .bytes_tx ; 2 |
||
193 | dd .bytes_rx ; 3 |
||
194 | dd .read_mac ; 4 |
||
3346 | hidnplayr | 195 | dd .state ; 5 |
2614 | hidnplayr | 196 | .number = ($ - .table) / 4 - 1 |
197 | |||
1514 | hidnplayr | 198 | .error: |
2311 | hidnplayr | 199 | or eax, -1 |
200 | ret |
||
1159 | hidnplayr | 201 | |
2614 | hidnplayr | 202 | .packets_tx: |
2311 | hidnplayr | 203 | mov eax, [eax + NET_DEVICE.packets_tx] |
1171 | hidnplayr | 204 | |
2311 | hidnplayr | 205 | ret |
1159 | hidnplayr | 206 | |
2614 | hidnplayr | 207 | .packets_rx: |
2311 | hidnplayr | 208 | mov eax, [eax + NET_DEVICE.packets_rx] |
209 | ret |
||
1159 | hidnplayr | 210 | |
2614 | hidnplayr | 211 | .bytes_tx: |
2311 | hidnplayr | 212 | mov ebx, dword [eax + NET_DEVICE.bytes_tx + 4] |
213 | mov eax, dword [eax + NET_DEVICE.bytes_tx] |
||
214 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
||
215 | ret |
||
1159 | hidnplayr | 216 | |
2614 | hidnplayr | 217 | .bytes_rx: |
2311 | hidnplayr | 218 | mov ebx, dword [eax + NET_DEVICE.bytes_rx + 4] |
219 | mov eax, dword [eax + NET_DEVICE.bytes_rx] |
||
220 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
||
221 | ret |
||
1159 | hidnplayr | 222 | |
1174 | hidnplayr | 223 | |
2614 | hidnplayr | 224 | .read_mac: |
2311 | hidnplayr | 225 | movzx ebx, word [eax + ETH_DEVICE.mac] |
226 | mov eax, dword [eax + ETH_DEVICE.mac + 2] |
||
227 | mov [esp+20+4], ebx ; TODO: fix this ugly code |
||
228 | ret |
||
1159 | hidnplayr | 229 | |
3346 | hidnplayr | 230 | .state: |
231 | mov eax, [eax + NET_DEVICE.state] |
||
2311 | hidnplayr | 232 | ret |
1159 | hidnplayr | 233 |