Subversion Repositories Kolibri OS

Rev

Rev 323 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  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
  42.  
  43. struc ETH_FRAME
  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]
  48. }
  49.  
  50. virtual at Ether_buffer
  51.   ETH_FRAME ETH_FRAME
  52. end virtual
  53.  
  54.  
  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.  
  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"
  100. ;include "drivers/mtd80x.inc"
  101. include "drivers/rtl8169.inc"
  102.  
  103. ; PCICards
  104. ; ========
  105. ; PCI vendor and hardware types for hardware supported by the above drivers
  106. ; If you add a driver, ensure you update this datastructure, otherwise the
  107. ; card will not be probed.
  108. ; Each driver is defined by 4 double words. These are
  109. ;   PCIVendorDevice  probeFunction ResetFunction PollFunction transmitFunction
  110. ; The last entry must be kept at all zeros, to indicate the end of the list
  111. ; As a PCI driver may support more than one hardware implementation, there may
  112. ; be several lines which refer to the same functions.
  113. ; The first driver found on the PCI bus will be the one used.
  114.  
  115. PCICARDS_ENTRY_SIZE         equ     24    ; Size of each PCICARDS entry
  116.  
  117. iglobal
  118. PCICards:
  119. dd  0x12098086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
  120. dd  0x10298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
  121. dd  0x12298086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
  122. dd  0x10308086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
  123. dd  0x24498086, I8255x_probe, I8255x_reset, I8255x_poll, I8255x_transmit, 0
  124. dd  0x802910ec, rtl8029_probe, rtl8029_reset, rtl8029_poll, rtl8029_transmit, 0
  125. dd  0x12111113, rtl8029_probe, rtl8029_reset, rtl8029_poll, rtl8029_transmit, 0
  126.  
  127. dd  0x813910ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  128. dd  0x813810ec, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  129. dd  0x12111113, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  130. dd  0x13601500, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  131. dd  0x13604033, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  132. dd  0x13001186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  133. dd  0x13401186, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  134. dd  0xab0613d1, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  135. dd  0xa1171259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  136. dd  0xa11e1259, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  137. dd  0xab0614ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  138. dd  0xab0714ea, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  139. dd  0x123411db, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  140. dd  0x91301432, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  141. dd  0x101202ac, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  142. dd  0x0106018a, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  143. dd  0x1211126c, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  144. dd  0x81391743, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  145. dd  0x8139021b, rtl8139_probe, rtl8139_reset, rtl8139_poll, rtl8139_transmit, rtl8139_cable
  146.  
  147. dd  0x816810ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
  148. dd  0x816910ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
  149. dd  0x011616ec, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
  150. dd  0x43001186, rtl8169_probe, rtl8169_reset, rtl8169_poll, rtl8169_transmit, 0
  151.  
  152. dd  0x590010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  153. dd  0x592010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  154. dd  0x597010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  155. dd  0x595010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  156. dd  0x595110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  157. dd  0x595210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  158. dd  0x900010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  159. dd  0x900110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  160. dd  0x900410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  161. dd  0x900510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  162. dd  0x900610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  163. dd  0x900A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  164. dd  0x905010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  165. dd  0x905110b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  166. dd  0x905510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  167. dd  0x905810b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  168. dd  0x905A10b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  169. dd  0x920010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  170. dd  0x980010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  171. dd  0x980510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  172. dd  0x764610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  173. dd  0x505510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  174. dd  0x605510b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  175. dd  0x605610b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  176. dd  0x5b5710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  177. dd  0x505710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  178. dd  0x515710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  179. dd  0x525710b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  180. dd  0x656010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  181. dd  0x656210b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  182. dd  0x656410b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  183. dd  0x450010b7, e3c59x_probe, e3c59x_reset, e3c59x_poll, e3c59x_transmit, 0
  184.  
  185. dd  0x09001039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0
  186.  
  187. dd  0x20001022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
  188. dd  0x26251022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
  189. dd  0x20011022, pcnet32_probe, pcnet32_reset, pcnet32_poll, pcnet32_xmit, 0
  190.  
  191. ;dd  0x08031516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
  192.  
  193. ; following cards are untested
  194. dd  0x70161039, SIS900_probe, SIS900_reset, SIS900_poll, SIS900_transmit, 0
  195. ;dd  0x08001516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
  196. ;dd  0x08911516, mtd80x_probe, mtd80x_reset, mtd80x_poll, mtd80x_transmit, mtd80x_cable
  197.  
  198. rb PCICARDS_ENTRY_SIZE  ; end of list marker, do not remove
  199. endg
  200.  
  201. uglobal
  202. ;Net-stack's interface's settings
  203.   node_addr:          db  0,0,0,0,0,0
  204.   gateway_ip:         dd  0
  205.   dns_ip:             dd  0
  206.  
  207.   eth_rx_data_len:    dw  0
  208.   eth_status:         dd  0
  209.   io_addr:            dd  0
  210.   hdrtype:            db  0
  211.   vendor_device:      dd  0
  212.   pci_data:           dd  0
  213.   pci_dev:            dd  0
  214.   pci_bus:            dd  0
  215.  
  216.   ; These will hold pointers to the selected driver functions
  217.   drvr_probe:         dd  0
  218.   drvr_reset:         dd  0
  219.   drvr_poll:          dd  0
  220.   drvr_transmit:      dd  0
  221.   drvr_cable:         dd  0
  222.  
  223. endg
  224.  
  225. iglobal
  226.   broadcast_add:      db  0xff,0xff,0xff,0xff,0xff,0xff
  227.   subnet_mask:        dd  0x00ffffff   ; 255.255.255.0
  228. endg
  229.  
  230. include "arp.inc"    ;arp-protocol functions
  231. include "pci.inc"    ;PCI bus access functions
  232.  
  233.  
  234. ;***************************************************************************
  235. ;   Function
  236. ;      eth_tx
  237. ;
  238. ;   Description
  239. ;      Looks at the NET1OUT_QUEUE for data to send.
  240. ;      Stores that destination IP in a location used by the tx routine
  241. ;      Looks up the MAC address in the ARP table; stores that where
  242. ;      the tx routine can get it
  243. ;      Get the length of the data. Store that where the tx routine wants it
  244. ;      Call tx
  245. ;      Places buffer on empty queue when the tx routine finished
  246. ;
  247. ;***************************************************************************
  248. proc eth_tx stdcall uses ebx esi edi
  249. local MACAddress  dp  ?  ;allocate 6 bytes in the stack
  250.  
  251.     ; Look for a buffer to tx
  252.     mov     eax, NET1OUT_QUEUE
  253.     call    dequeue
  254.     cmp     ax, NO_BUFFER
  255.     je      .exit            ; Exit if no buffer available
  256.  
  257.     push    eax  ;save buffer number
  258.  
  259.     ; convert buffer pointer eax to the absolute address
  260.     imul    eax, IPBUFFSIZE
  261.     add     eax, IPbuffs
  262.  
  263.     ; Extract the destination IP
  264.     ; find the destination IP in the ARP table, get MAC
  265.     ; store this MAC in 'MACAddress'
  266.     mov     ebx, eax               ; Save buffer address
  267.     mov     edx, [ebx + 16]        ; get destination address
  268.  
  269.     ; If the destination address is 255.255.255.255,
  270.     ; set the MACAddress to all ones ( broadcast )
  271.     cld
  272.     mov     esi, broadcast_add
  273.     lea     edi, [MACAddress]
  274.     movsd
  275.     movsw
  276.     cmp     edx, 0xffffffff
  277.     je      .send                ; If it is broadcast, just send
  278.  
  279.     lea     eax, [MACAddress]    ;cause this is local variable
  280.     stdcall arp_table_manager, ARP_TABLE_IP_TO_MAC, edx, eax ;opcode,IP,MAC_ptr - Get the MAC address.
  281.  
  282.     cmp     eax, ARP_VALID_MAPPING
  283.     je      .send
  284.  
  285.     ; No valid entry. Has the request been sent, but timed out?
  286.     cmp     eax, ARP_RESPONSE_TIMEOUT
  287.     je      .freebuf
  288.  
  289.   .wait_response:                   ;we wait arp-response
  290.                                     ; Re-queue the packet, and exit
  291.     pop     ebx
  292.     mov     eax, NET1OUT_QUEUE
  293.     call    queue                        ; Get the buffer back
  294.     jmp     .exit
  295.  
  296.   .send:    ;if ARP_VALID_MAPPING then send the packet
  297.     lea     edi, [MACAddress]     ; Pointer to 48 bit destination address
  298.     movzx   ecx, word[ebx+2]      ; Size of IP packet to send
  299.     xchg    ch, cl                ; because mirror byte-order
  300.     mov     esi, ebx              ; Pointer to packet data
  301.     mov     bx, ETHER_IP          ; Type of packet
  302.     call    dword [drvr_transmit] ; Call the drivers transmit function
  303.  
  304.     ; OK, we have sent a packet, so increment the count
  305.     inc     dword [ip_tx_count]
  306.  
  307.     ; And finally, return the buffer to the free queue
  308.   .freebuf:
  309.     pop     eax
  310.     call    freeBuff
  311.  
  312.   .exit:
  313.     ret
  314. endp
  315.  
  316. ;***************************************************************************
  317. ;   Function
  318. ;      ether_IP_handler
  319. ;
  320. ;   Description
  321. ;      Called when an IP ethernet packet is received on the ethernet
  322. ;      Header + Data is in Ether_buffer[]
  323. ;      We just need to get a buffer from the 'free' queue, and
  324. ;      store the packet in it, then insert the packet number into the
  325. ;      IPRX queue.
  326. ;      If no queue entry is available, the packet is silently discarded
  327. ;      All registers may be destroyed
  328. ;
  329. ;***************************************************************************
  330. ether_IP_handler:
  331.     mov     eax, EMPTY_QUEUE
  332.     call    dequeue
  333.     cmp     ax, NO_BUFFER
  334.     je      eiph00x
  335.  
  336.     ; convert buffer pointer eax to the absolute address
  337.     push    eax
  338.     mov     ecx, IPBUFFSIZE
  339.     mul     ecx
  340.     add     eax, IPbuffs
  341.  
  342.     mov     edi, eax
  343.  
  344.     ; get a pointer to the start of the DATA
  345.     mov     esi, ETH_FRAME.Data
  346.  
  347.     ; Now store it all away
  348.     mov     ecx, IPBUFFSIZE / 4     ; Copy all of the available
  349.                               ; data across - worse case
  350.     cld
  351.     rep     movsd
  352.  
  353.     ; And finally, place the buffer in the IPRX queue
  354.     pop     ebx
  355.     mov     eax, IPIN_QUEUE
  356.     call    queue
  357.  
  358. eiph00x:
  359.     ret
  360.  
  361. ;***************************************************************************
  362. ;   Function
  363. ;      eth_probe
  364. ;   Description
  365. ;      Searches for an ethernet card. If found, the card is enabled and
  366. ;      the ethernet -> IP link established
  367. ;
  368. ;      This function scans the PCI bus looking for a supported device.
  369. ;      ISA bus is currently not supported.
  370. ;
  371. ;        eax is 0 if no hardware found
  372. ;***************************************************************************
  373. eth_probe:
  374.     ; Find a card on the PCI bus, and get it's address
  375.     call    scan_bus                    ; Find the ethernet cards PIC address
  376.     xor     eax, eax
  377.     cmp     [io_addr], eax
  378.     je      ep_00x                      ; Return 0 in eax if no cards found
  379.  
  380.     call    dword [drvr_probe]          ; Call the drivers probe function
  381.  
  382.     mov     eax, [io_addr]              ; return a non zero value
  383.  
  384. ep_00x:
  385.     ret
  386.  
  387. ;***************************************************************************
  388. ;   Function
  389. ;      ethernet_driver
  390. ;
  391. ;   Description
  392. ;       The ethernet RX and TX handler
  393. ;       This is a kernel function, called by stack_handler
  394. ;
  395. ;***************************************************************************
  396. ethernet_driver:
  397.     ; Do nothing if the driver is inactive
  398.     cmp     [ethernet_active], byte 0
  399.     je      eth_exit
  400.  
  401.     call    eth_rx
  402.     call    eth_tx
  403.  
  404. eth_exit:
  405.     ret
  406.  
  407. ;***************************************************************************
  408. ;   Function
  409. ;      eth_rx
  410. ;
  411. ;   Description
  412. ;      Polls the ethernet card for received data. Extracts if present
  413. ;       Depending on the Protocol within the packet:
  414. ;         ARP : Pass to ARP_handler. This may result in an ARP reply
  415. ;               being tx'ed
  416. ;         IP  : Store in an IP buffer
  417. ;
  418. ;***************************************************************************
  419. eth_rx:
  420.     xor     ax, ax
  421.     mov     [eth_rx_data_len], ax
  422.     call    dword [drvr_poll]       ; Call the drivers poll function
  423.  
  424.     mov     ax, [eth_rx_data_len]
  425.     cmp     ax, 0
  426.     je      .exit
  427.  
  428.  
  429.     ; Check the protocol. Call appropriate handler
  430.  
  431.     mov     ax, [ETH_FRAME.Type]    ; The address of the protocol word
  432.  
  433.     cmp     ax, ETHER_IP
  434.     je      .is_ip                   ; It's IP
  435.  
  436.     cmp     ax, ETHER_ARP
  437.     je      .is_arp                  ; It is ARP
  438.  
  439.     jmp     .exit               ; If not IP or ARP, ignore
  440.  
  441.   .is_ip:
  442.     DEBUGF  1,"K : eth_rx - IP packet\n"
  443.     inc     dword [ip_rx_count]
  444.     call    ether_IP_handler
  445.     jmp     .exit
  446.  
  447.   .is_arp:
  448.     DEBUGF  1,"K : eth_rx - ARP packet\n"
  449.     ; At this point, the packet is still in the Ether_buffer
  450.     call    arp_handler
  451.  
  452.   .exit:
  453.     ret
  454.