Subversion Repositories Kolibri OS

Rev

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

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