Subversion Repositories Kolibri OS

Rev

Rev 302 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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