Rev 523 | Rev 739 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ha | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
431 | serge | 3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
1 | ha | 6 | ;; ETHERNET.INC ;; |
7 | ;; ;; |
||
8 | ;; Ethernet network layer for Menuet OS ;; |
||
9 | ;; ;; |
||
10 | ;; Version 0.4 22 September 2003 ;; |
||
11 | ;; ;; |
||
12 | ;; This file contains the following: ;; |
||
13 | ;; PCI bus scanning for valid devices ;; |
||
14 | ;; Table of supported ethernet drivers ;; |
||
15 | ;; Code to identify and activate a supported driver ;; |
||
16 | ;; ARP handler ;; |
||
17 | ;; Driver interface to the IP layer ;; |
||
18 | ;; Gateway support ;; |
||
19 | ;; ;; |
||
20 | ;; Individual driver files are included here ;; |
||
21 | ;; ;; |
||
22 | ;; The PCI bus scanning code was ported from the etherboot ;; |
||
23 | ;; 5.0.6 project. The copyright statement for that code is ;; |
||
24 | ;; ;; |
||
25 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
26 | ;; Version 2, June 1991 ;; |
||
27 | ;; ;; |
||
28 | ;; remaining parts Copyright 2002 Mike Hibbett ;; |
||
29 | ;; mikeh@oceanfree.net ;; |
||
30 | ;; ;; |
||
31 | ;; See file COPYING for details ;; |
||
32 | ;; ;; |
||
33 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
34 | |||
593 | mikedld | 35 | $Revision: 593 $ |
36 | |||
37 | |||
1 | ha | 38 | ;******************************************************************** |
39 | ; Interface |
||
40 | ; ethernet_driver called by stack_handler in stack.inc |
||
41 | ; eth_probe called by app_stack_handler in stack.inc |
||
42 | ; |
||
43 | ;******************************************************************** |
||
44 | |||
302 | hidnplayr | 45 | ETHER_IP equ 0x0008 ; Reversed from 0800 for intel |
46 | ETHER_ARP equ 0x0608 ; Reversed from 0806 for intel |
||
47 | ETHER_RARP equ 0x3580 |
||
261 | hidnplayr | 48 | |
49 | struc ETH_FRAME |
||
302 | hidnplayr | 50 | { .DstMAC dp ? ;destination MAC-address [6 bytes] |
51 | .SrcMAC dp ? ;source MAC-address [6 bytes] |
||
52 | .Type dw ? ;type of the upper-layer protocol [2 bytes] |
||
53 | .Data db ? ;data [46-1500 bytes] |
||
261 | hidnplayr | 54 | } |
55 | |||
56 | virtual at Ether_buffer |
||
57 | ETH_FRAME ETH_FRAME |
||
58 | end virtual |
||
59 | |||
60 | |||
1 | ha | 61 | ; Some useful information on data structures |
62 | |||
63 | ; Ethernet Packet - ARP Request example |
||
64 | ; |
||
65 | ; 0 1 2 3 |
||
66 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
||
67 | ; |
||
68 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
69 | ; | Dest H/W Address | |
||
70 | ; | ( 14 byte header ) | |
||
71 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
72 | ; | | Source H/W Address | |
||
73 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
74 | ; | | |
||
75 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
76 | ; | Protocol - ARP 08 06 | |
||
77 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
78 | |||
79 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
80 | ; | H/W Type 00 01 | Protocol Type 08 00 | |
||
81 | ; | ( ARP Request packet ) | |
||
82 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
83 | ; | HLen 0x06 | PLen 0x04 | OpCode 00 01 | |
||
84 | ; | ( 0001 for request, 0002 for reply ) | |
||
85 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
86 | ; | Source Hardware Address ( MAC Address ) | |
||
87 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
88 | ; | | Source IP Address | |
||
89 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
90 | ; | | Destination Hardware Address | |
||
91 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
92 | ; | | |
||
93 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
94 | ; | Destination IP Address | |
||
95 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
||
96 | |||
97 | ; Include individual drivers source files at this point. |
||
98 | ; If you create a new driver, include it below. |
||
99 | |||
261 | hidnplayr | 100 | include "drivers/rtl8029.inc" |
101 | include "drivers/i8255x.inc" |
||
102 | include "drivers/rtl8139.inc" |
||
103 | include "drivers/3c59x.inc" |
||
104 | include "drivers/sis900.inc" |
||
105 | include "drivers/pcnet32.inc" |
||
373 | mikedld | 106 | include "drivers/rtl8169.inc" |
1 | ha | 107 | |
108 | ; PCICards |
||
109 | ; ======== |
||
110 | ; PCI vendor and hardware types for hardware supported by the above drivers |
||
111 | ; If you add a driver, ensure you update this datastructure, otherwise the |
||
112 | ; card will not be probed. |
||
113 | ; Each driver is defined by 4 double words. These are |
||
114 | ; PCIVendorDevice probeFunction ResetFunction PollFunction transmitFunction |
||
115 | ; The last entry must be kept at all zeros, to indicate the end of the list |
||
116 | ; As a PCI driver may support more than one hardware implementation, there may |
||
117 | ; be several lines which refer to the same functions. |
||
118 | ; The first driver found on the PCI bus will be the one used. |
||
119 | |||
302 | hidnplayr | 120 | PCICARDS_ENTRY_SIZE equ 24 ; Size of each PCICARDS entry |
1 | ha | 121 | |
122 | iglobal |
||
123 | PCICards: |
||
302 | hidnplayr | 124 | dd 0x12098086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0 |
125 | dd 0x10298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0 |
||
126 | dd 0x12298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0 |
||
127 | dd 0x10308086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0 |
||
128 | dd 0x24498086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0 |
||
505 | hidnplayr | 129 | |
302 | hidnplayr | 130 | dd 0x802910ec, rtl8029_probe, rtl8029_reset, rtl8029_poll, rtl8029_transmit, 0 |
131 | |||
505 | hidnplayr | 132 | dd 0x813910ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable ; tested by hidnplayr: works ok |
302 | hidnplayr | 133 | dd 0x813810ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
505 | hidnplayr | 134 | dd 0x12111113, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable ; tested by hidnplayr: works ok |
302 | hidnplayr | 135 | dd 0x13601500, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
136 | dd 0x13604033, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
137 | dd 0x13001186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
138 | dd 0x13401186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
139 | dd 0xab0613d1, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
140 | dd 0xa1171259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
141 | dd 0xa11e1259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
142 | dd 0xab0614ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
143 | dd 0xab0714ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
144 | dd 0x123411db, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
145 | dd 0x91301432, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
146 | dd 0x101202ac, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
147 | dd 0x0106018a, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
148 | dd 0x1211126c, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
149 | dd 0x81391743, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
150 | dd 0x8139021b, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable |
||
151 | |||
373 | mikedld | 152 | dd 0x816810ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0 |
153 | dd 0x816910ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0 |
||
154 | dd 0x011616ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0 |
||
155 | dd 0x43001186, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0 |
||
156 | |||
302 | hidnplayr | 157 | dd 0x590010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
158 | dd 0x592010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
159 | dd 0x597010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
160 | dd 0x595010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
161 | dd 0x595110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
162 | dd 0x595210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
163 | dd 0x900010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
164 | dd 0x900110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
523 | diamond | 165 | dd 0x900410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
302 | hidnplayr | 166 | dd 0x900510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
167 | dd 0x900610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
168 | dd 0x900A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
169 | dd 0x905010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
170 | dd 0x905110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
171 | dd 0x905510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
172 | dd 0x905810b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
173 | dd 0x905A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
174 | dd 0x920010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
175 | dd 0x980010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
176 | dd 0x980510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
177 | dd 0x764610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
178 | dd 0x505510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
179 | dd 0x605510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
180 | dd 0x605610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
181 | dd 0x5b5710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
182 | dd 0x505710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
183 | dd 0x515710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
184 | dd 0x525710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
185 | dd 0x656010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
186 | dd 0x656210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
187 | dd 0x656410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
188 | dd 0x450010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0 |
||
189 | |||
190 | dd 0x09001039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0 |
||
191 | |||
192 | dd 0x20001022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0 |
||
193 | dd 0x26251022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0 |
||
194 | dd 0x20011022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0 |
||
323 | hidnplayr | 195 | |
196 | ;dd 0x08031516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable |
||
197 | |||
198 | ; following cards are untested |
||
302 | hidnplayr | 199 | dd 0x70161039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0 |
323 | hidnplayr | 200 | ;dd 0x08001516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable |
201 | ;dd 0x08911516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable |
||
202 | |||
302 | hidnplayr | 203 | rb PCICARDS_ENTRY_SIZE ; end of list marker, do not remove |
1 | ha | 204 | endg |
205 | |||
206 | uglobal |
||
261 | hidnplayr | 207 | ;Net-stack's interface's settings |
302 | hidnplayr | 208 | node_addr: db 0,0,0,0,0,0 |
209 | gateway_ip: dd 0 |
||
210 | dns_ip: dd 0 |
||
261 | hidnplayr | 211 | |
1 | ha | 212 | eth_rx_data_len: dw 0 |
302 | hidnplayr | 213 | eth_status: dd 0 |
214 | io_addr: dd 0 |
||
215 | hdrtype: db 0 |
||
1 | ha | 216 | vendor_device: dd 0 |
302 | hidnplayr | 217 | pci_data: dd 0 |
218 | pci_dev: dd 0 |
||
219 | pci_bus: dd 0 |
||
1 | ha | 220 | |
221 | ; These will hold pointers to the selected driver functions |
||
302 | hidnplayr | 222 | drvr_probe: dd 0 |
223 | drvr_reset: dd 0 |
||
224 | drvr_poll: dd 0 |
||
1 | ha | 225 | drvr_transmit: dd 0 |
302 | hidnplayr | 226 | drvr_cable: dd 0 |
1 | ha | 227 | |
228 | endg |
||
229 | |||
230 | iglobal |
||
231 | broadcast_add: db 0xff,0xff,0xff,0xff,0xff,0xff |
||
302 | hidnplayr | 232 | subnet_mask: dd 0x00ffffff ; 255.255.255.0 |
1 | ha | 233 | endg |
234 | |||
261 | hidnplayr | 235 | include "arp.inc" ;arp-protocol functions |
236 | include "pci.inc" ;PCI bus access functions |
||
1 | ha | 237 | |
238 | |||
239 | ;*************************************************************************** |
||
240 | ; Function |
||
241 | ; eth_tx |
||
242 | ; |
||
243 | ; Description |
||
244 | ; Looks at the NET1OUT_QUEUE for data to send. |
||
245 | ; Stores that destination IP in a location used by the tx routine |
||
246 | ; Looks up the MAC address in the ARP table; stores that where |
||
247 | ; the tx routine can get it |
||
248 | ; Get the length of the data. Store that where the tx routine wants it |
||
249 | ; Call tx |
||
250 | ; Places buffer on empty queue when the tx routine finished |
||
251 | ; |
||
252 | ;*************************************************************************** |
||
261 | hidnplayr | 253 | proc eth_tx stdcall uses ebx esi edi |
254 | local MACAddress dp ? ;allocate 6 bytes in the stack |
||
255 | |||
1 | ha | 256 | ; Look for a buffer to tx |
257 | mov eax, NET1OUT_QUEUE |
||
258 | call dequeue |
||
259 | cmp ax, NO_BUFFER |
||
302 | hidnplayr | 260 | je .exit ; Exit if no buffer available |
1 | ha | 261 | |
261 | hidnplayr | 262 | push eax ;save buffer number |
1 | ha | 263 | |
264 | ; convert buffer pointer eax to the absolute address |
||
261 | hidnplayr | 265 | imul eax, IPBUFFSIZE |
1 | ha | 266 | add eax, IPbuffs |
267 | |||
268 | ; Extract the destination IP |
||
269 | ; find the destination IP in the ARP table, get MAC |
||
270 | ; store this MAC in 'MACAddress' |
||
302 | hidnplayr | 271 | mov ebx, eax ; Save buffer address |
272 | mov edx, [ebx + 16] ; get destination address |
||
1 | ha | 273 | |
274 | ; If the destination address is 255.255.255.255, |
||
275 | ; set the MACAddress to all ones ( broadcast ) |
||
261 | hidnplayr | 276 | cld |
277 | mov esi, broadcast_add |
||
278 | lea edi, [MACAddress] |
||
279 | movsd |
||
280 | movsw |
||
1 | ha | 281 | cmp edx, 0xffffffff |
302 | hidnplayr | 282 | je .send ; If it is broadcast, just send |
1 | ha | 283 | |
511 | heavyiron | 284 | ; first, check destination IP to see if it is on 'this' network. |
285 | ; The test is: |
||
286 | ; if ( destIP & subnet_mask == stack_ip & subnet_mask ) |
||
287 | ; destination is local |
||
288 | ; else |
||
289 | ; destination is remote, so pass to gateway |
||
290 | |||
291 | mov eax, edx |
||
292 | and eax, [subnet_mask] |
||
293 | mov ecx, [stack_ip] |
||
294 | and ecx, [subnet_mask] |
||
295 | cmp eax, ecx |
||
296 | je .local |
||
297 | |||
298 | mov edx, [gateway_ip] |
||
299 | .local: |
||
300 | |||
302 | hidnplayr | 301 | lea eax, [MACAddress] ;cause this is local variable |
261 | hidnplayr | 302 | stdcall arp_table_manager, ARP_TABLE_IP_TO_MAC, edx, eax ;opcode,IP,MAC_ptr - Get the MAC address. |
1 | ha | 303 | |
304 | cmp eax, ARP_VALID_MAPPING |
||
302 | hidnplayr | 305 | je .send |
1 | ha | 306 | |
261 | hidnplayr | 307 | ; No valid entry. Has the request been sent, but timed out? |
1 | ha | 308 | cmp eax, ARP_RESPONSE_TIMEOUT |
302 | hidnplayr | 309 | je .freebuf |
1 | ha | 310 | |
302 | hidnplayr | 311 | .wait_response: ;we wait arp-response |
312 | ; Re-queue the packet, and exit |
||
1 | ha | 313 | pop ebx |
314 | mov eax, NET1OUT_QUEUE |
||
302 | hidnplayr | 315 | call queue ; Get the buffer back |
261 | hidnplayr | 316 | jmp .exit |
1 | ha | 317 | |
261 | hidnplayr | 318 | .send: ;if ARP_VALID_MAPPING then send the packet |
302 | hidnplayr | 319 | lea edi, [MACAddress] ; Pointer to 48 bit destination address |
320 | movzx ecx, word[ebx+2] ; Size of IP packet to send |
||
321 | xchg ch, cl ; because mirror byte-order |
||
322 | mov esi, ebx ; Pointer to packet data |
||
323 | mov bx, ETHER_IP ; Type of packet |
||
523 | diamond | 324 | push ebp |
261 | hidnplayr | 325 | call dword [drvr_transmit] ; Call the drivers transmit function |
523 | diamond | 326 | pop ebp |
1 | ha | 327 | |
328 | ; OK, we have sent a packet, so increment the count |
||
329 | inc dword [ip_tx_count] |
||
330 | |||
331 | ; And finally, return the buffer to the free queue |
||
261 | hidnplayr | 332 | .freebuf: |
1 | ha | 333 | pop eax |
334 | call freeBuff |
||
335 | |||
261 | hidnplayr | 336 | .exit: |
1 | ha | 337 | ret |
261 | hidnplayr | 338 | endp |
1 | ha | 339 | |
340 | ;*************************************************************************** |
||
341 | ; Function |
||
342 | ; ether_IP_handler |
||
343 | ; |
||
344 | ; Description |
||
345 | ; Called when an IP ethernet packet is received on the ethernet |
||
346 | ; Header + Data is in Ether_buffer[] |
||
347 | ; We just need to get a buffer from the 'free' queue, and |
||
348 | ; store the packet in it, then insert the packet number into the |
||
349 | ; IPRX queue. |
||
350 | ; If no queue entry is available, the packet is silently discarded |
||
351 | ; All registers may be destroyed |
||
352 | ; |
||
353 | ;*************************************************************************** |
||
354 | ether_IP_handler: |
||
355 | mov eax, EMPTY_QUEUE |
||
356 | call dequeue |
||
357 | cmp ax, NO_BUFFER |
||
302 | hidnplayr | 358 | je eiph00x |
1 | ha | 359 | |
360 | ; convert buffer pointer eax to the absolute address |
||
361 | push eax |
||
362 | mov ecx, IPBUFFSIZE |
||
363 | mul ecx |
||
364 | add eax, IPbuffs |
||
365 | |||
366 | mov edi, eax |
||
367 | |||
368 | ; get a pointer to the start of the DATA |
||
261 | hidnplayr | 369 | mov esi, ETH_FRAME.Data |
1 | ha | 370 | |
371 | ; Now store it all away |
||
372 | mov ecx, IPBUFFSIZE / 4 ; Copy all of the available |
||
302 | hidnplayr | 373 | ; data across - worse case |
1 | ha | 374 | cld |
375 | rep movsd |
||
376 | |||
377 | ; And finally, place the buffer in the IPRX queue |
||
378 | pop ebx |
||
379 | mov eax, IPIN_QUEUE |
||
380 | call queue |
||
381 | |||
382 | eiph00x: |
||
383 | ret |
||
384 | |||
385 | ;*************************************************************************** |
||
386 | ; Function |
||
261 | hidnplayr | 387 | ; eth_probe |
1 | ha | 388 | ; Description |
261 | hidnplayr | 389 | ; Searches for an ethernet card. If found, the card is enabled and |
390 | ; the ethernet -> IP link established |
||
1 | ha | 391 | ; |
261 | hidnplayr | 392 | ; This function scans the PCI bus looking for a supported device. |
393 | ; ISA bus is currently not supported. |
||
1 | ha | 394 | ; |
261 | hidnplayr | 395 | ; eax is 0 if no hardware found |
1 | ha | 396 | ;*************************************************************************** |
261 | hidnplayr | 397 | eth_probe: |
398 | ; Find a card on the PCI bus, and get it's address |
||
302 | hidnplayr | 399 | call scan_bus ; Find the ethernet cards PIC address |
1 | ha | 400 | xor eax, eax |
261 | hidnplayr | 401 | cmp [io_addr], eax |
302 | hidnplayr | 402 | je ep_00x ; Return 0 in eax if no cards found |
1 | ha | 403 | |
302 | hidnplayr | 404 | call dword [drvr_probe] ; Call the drivers probe function |
1 | ha | 405 | |
302 | hidnplayr | 406 | mov eax, [io_addr] ; return a non zero value |
1 | ha | 407 | |
261 | hidnplayr | 408 | ep_00x: |
1 | ha | 409 | ret |
410 | |||
411 | ;*************************************************************************** |
||
412 | ; Function |
||
261 | hidnplayr | 413 | ; ethernet_driver |
1 | ha | 414 | ; |
415 | ; Description |
||
261 | hidnplayr | 416 | ; The ethernet RX and TX handler |
417 | ; This is a kernel function, called by stack_handler |
||
1 | ha | 418 | ; |
419 | ;*************************************************************************** |
||
261 | hidnplayr | 420 | ethernet_driver: |
421 | ; Do nothing if the driver is inactive |
||
422 | cmp [ethernet_active], byte 0 |
||
302 | hidnplayr | 423 | je eth_exit |
1 | ha | 424 | |
261 | hidnplayr | 425 | call eth_rx |
426 | call eth_tx |
||
1 | ha | 427 | |
261 | hidnplayr | 428 | eth_exit: |
1 | ha | 429 | ret |
430 | |||
431 | ;*************************************************************************** |
||
432 | ; Function |
||
261 | hidnplayr | 433 | ; eth_rx |
1 | ha | 434 | ; |
435 | ; Description |
||
261 | hidnplayr | 436 | ; Polls the ethernet card for received data. Extracts if present |
437 | ; Depending on the Protocol within the packet: |
||
438 | ; ARP : Pass to ARP_handler. This may result in an ARP reply |
||
439 | ; being tx'ed |
||
440 | ; IP : Store in an IP buffer |
||
1 | ha | 441 | ; |
442 | ;*************************************************************************** |
||
261 | hidnplayr | 443 | eth_rx: |
444 | xor ax, ax |
||
445 | mov [eth_rx_data_len], ax |
||
302 | hidnplayr | 446 | call dword [drvr_poll] ; Call the drivers poll function |
1 | ha | 447 | |
261 | hidnplayr | 448 | mov ax, [eth_rx_data_len] |
449 | cmp ax, 0 |
||
302 | hidnplayr | 450 | je .exit |
1 | ha | 451 | |
452 | |||
261 | hidnplayr | 453 | ; Check the protocol. Call appropriate handler |
1 | ha | 454 | |
261 | hidnplayr | 455 | mov ax, [ETH_FRAME.Type] ; The address of the protocol word |
1 | ha | 456 | |
261 | hidnplayr | 457 | cmp ax, ETHER_IP |
302 | hidnplayr | 458 | je .is_ip ; It's IP |
1 | ha | 459 | |
261 | hidnplayr | 460 | cmp ax, ETHER_ARP |
302 | hidnplayr | 461 | je .is_arp ; It is ARP |
1 | ha | 462 | |
302 | hidnplayr | 463 | jmp .exit ; If not IP or ARP, ignore |
1 | ha | 464 | |
261 | hidnplayr | 465 | .is_ip: |
373 | mikedld | 466 | DEBUGF 1,"K : eth_rx - IP packet\n" |
261 | hidnplayr | 467 | inc dword [ip_rx_count] |
468 | call ether_IP_handler |
||
469 | jmp .exit |
||
1 | ha | 470 | |
261 | hidnplayr | 471 | .is_arp: |
373 | mikedld | 472 | DEBUGF 1,"K : eth_rx - ARP packet\n" |
261 | hidnplayr | 473 | ; At this point, the packet is still in the Ether_buffer |
474 | call arp_handler |
||
1 | ha | 475 | |
261 | hidnplayr | 476 | .exit: |
302 | hidnplayr | 477 | ret |