Subversion Repositories Kolibri OS

Rev

Rev 1168 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;  STACK.INC                                                   ;;
  7. ;;                                                              ;;
  8. ;;  TCP/IP stack for Menuet OS                                  ;;
  9. ;;                                                              ;;
  10. ;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net            ;;
  11. ;;                                                              ;;
  12. ;;  See file COPYING for details                                ;;
  13. ;;                                                              ;;
  14. ;; Version 0.7                                                  ;;
  15. ;;      Added a timer per socket to allow delays when rx window ;;
  16. ;;      gets below 1KB                                          ;;
  17. ;;                                                              ;;
  18. ;;10.01.2007 Bugfix for checksum function from Paolo Franchetti ;;
  19. ;;                                                              ;;
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22. $Revision: 1369 $
  23.  
  24.  
  25. ;*******************************************************************
  26. ;   Interface
  27. ;      The interfaces defined in ETHERNET.INC plus:
  28. ;      stack_init
  29. ;      stack_handler
  30. ;      app_stack_handler
  31. ;      app_socket_handler
  32. ;      checksum
  33. ;
  34. ;*******************************************************************
  35.  
  36. uglobal
  37. StackCounters:
  38.   dumped_rx_count     dd  0
  39.   arp_tx_count:       dd  0
  40.   arp_rx_count:       dd  0
  41.   ip_rx_count:        dd  0
  42.   ip_tx_count:        dd  0
  43. endg
  44.  
  45. ; socket buffers
  46. SOCKETBUFFSIZE     equ        4096  ; state + config + buffer.
  47. SOCKETHEADERSIZE   equ        SOCKET.rxData ; thus 4096 - SOCKETHEADERSIZE bytes data
  48.  
  49. ;NUM_SOCKETS        equ        16    ; Number of open sockets supported. Was 20
  50.  
  51. ; IPBUFF status values
  52. BUFF_EMPTY         equ     0
  53. BUFF_RX_FULL       equ     1
  54. BUFF_ALLOCATED     equ     2
  55. BUFF_TX_FULL       equ     3
  56.  
  57. NUM_IPBUFFERS      equ     20    ; buffers allocated for TX/RX
  58.  
  59. NUMQUEUES          equ        4
  60.  
  61. EMPTY_QUEUE        equ        0
  62. IPIN_QUEUE         equ        1
  63. IPOUT_QUEUE        equ        2
  64. NET1OUT_QUEUE      equ        3
  65.  
  66. NO_BUFFER          equ        0xFFFF
  67. IPBUFFSIZE         equ        1500                ; MTU of an ethernet packet
  68. NUMQUEUEENTRIES    equ        NUM_IPBUFFERS
  69. NUMRESENDENTRIES    equ         18              ; Buffers for TCP resend packets
  70.  
  71. ; These are the 0x40 function codes for application access to the stack
  72. STACK_DRIVER_STATUS  equ   52
  73. SOCKET_INTERFACE     equ   53
  74.  
  75.  
  76. ; 128KB allocated for the stack and network driver buffers and other
  77. ; data requirements
  78. ;stack_data_start     equ   0x700000
  79. ;eth_data_start       equ   0x700000
  80. ;stack_data           equ   0x704000
  81. ;stack_data_end       equ   0x71ffff
  82.  
  83. ; 32 bit word
  84. stack_config         equ   stack_data
  85.  
  86. ; 32 bit word - IP Address in network format
  87. stack_ip             equ   stack_data + 4
  88.  
  89. ; 1 byte. 0 == inactive, 1 = active
  90. ethernet_active      equ   stack_data + 9
  91.  
  92.  
  93. ; TODO :: empty memory area
  94.  
  95. ; Address of selected socket
  96. ;sktAddr              equ   stack_data + 32
  97. ; Parameter to checksum routine - data ptr
  98. checkAdd1            equ   stack_data + 36
  99. ; Parameter to checksum routine - 2nd data ptr
  100. checkAdd2            equ   stack_data + 40
  101. ; Parameter to checksum routine - data size
  102. checkSize1           equ   stack_data + 44
  103. ; Parameter to checksum routine - 2nd data size
  104. checkSize2           equ   stack_data + 46
  105. ; result of checksum routine
  106. checkResult          equ   stack_data + 48
  107.  
  108. ; holds the TCP/UDP pseudo header. SA|DA|0|prot|UDP len|
  109. pseudoHeader         equ   stack_data + 50
  110.  
  111. ; receive and transmit IP buffer allocation
  112. ;sockets              equ   stack_data + 62
  113. Next_free2 equ stack_data + 62;Next_free2           equ   sockets + (SOCKETBUFFSIZE * NUM_SOCKETS)
  114. ; 1560 byte buffer for rx / tx ethernet packets
  115. Ether_buffer         equ   Next_free2
  116. Next_free3           equ   Ether_buffer + 1518
  117. last_1sTick          equ   Next_free3
  118. IPbuffs              equ   Next_free3 + 1
  119. queues               equ   IPbuffs + ( NUM_IPBUFFERS * IPBUFFSIZE )
  120. queueList            equ   queues + (2 * NUMQUEUES)
  121. last_1hsTick         equ   queueList + ( 2 * NUMQUEUEENTRIES )
  122.  
  123. ;resendQ              equ   queueList + ( 2 * NUMQUEUEENTRIES )
  124. ;resendBuffer         equ    resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP
  125. ;                    equ    resendBuffer + ( IPBUFFSIZE * NUMRESENDENTRIES )
  126.  
  127.  
  128.  
  129. ;resendQ             equ     0x770000
  130. ;resendBuffer        equ     resendQ + ( 4 * NUMRESENDENTRIES ) ; for TCP        ; XTODO: validate size
  131. resendBuffer        equ     resendQ + ( 8 * NUMRESENDENTRIES ) ; for TCP
  132.  
  133.  
  134. uglobal
  135. net_sockets rd 2
  136. endg
  137.  
  138. ; simple macro for memory set operation
  139. macro _memset_dw adr,value,amount
  140. {
  141.         mov     edi, adr
  142.         mov     ecx, amount
  143.         if value = 0
  144.                 xor     eax, eax
  145.         else
  146.                 mov     eax, value
  147.         end if
  148.         cld
  149.         rep     stosd
  150. }
  151.  
  152.  
  153. ; Below, the main network layer source code is included
  154. ;
  155. include "queue.inc"
  156. include "eth_drv/ethernet.inc"
  157. include "ip.inc"
  158. include "socket.inc"
  159.  
  160. ;***************************************************************************
  161. ;   Function
  162. ;      stack_init
  163. ;
  164. ;   Description
  165. ;      Clear all allocated memory to zero. This ensures that
  166. ;       on startup, the stack is inactive, and consumes no resources
  167. ;       This is a kernel function, called prior to the OS main loop
  168. ;       in set_variables
  169. ;
  170. ;***************************************************************************
  171.  
  172. stack_init:
  173.         ; Init two address spaces with default values
  174.         _memset_dw      stack_data_start, 0, 0x20000/4
  175.         _memset_dw      resendQ, 0, NUMRESENDENTRIES * 2
  176.  
  177.         mov     [net_sockets], 0
  178.         mov     [net_sockets + 4], 0
  179.  
  180.         ; Queries initialization
  181.         call    queueInit
  182.  
  183.         ; The following block sets up the 1s timer
  184.         mov     al, 0x0
  185.         out     0x70, al
  186.         in      al, 0x71
  187.         mov     [last_1sTick], al
  188. ret
  189.  
  190.  
  191.  
  192. ;***************************************************************************
  193. ;   Function
  194. ;      stack_handler
  195. ;
  196. ;   Description
  197. ;       The kernel loop routine for the stack
  198. ;       This is a kernel function, called in the main loop
  199. ;
  200. ;***************************************************************************
  201. align 4
  202. stack_handler:
  203.  
  204.     call    ethernet_driver
  205.     call    ip_rx
  206.  
  207.  
  208.     ; Test for 10ms tick, call tcp timer
  209.     mov     eax, [timer_ticks] ;[0xfdf0]
  210.     cmp     eax, [last_1hsTick]
  211.     je      sh_001
  212.  
  213.     mov     [last_1hsTick], eax
  214.     call    tcp_tx_handler
  215.  
  216. sh_001:
  217.  
  218.     ; Test for 1 second event, call 1s timer functions
  219.     mov     al, 0x0   ;second
  220.     out     0x70, al
  221.     in      al, 0x71
  222.     cmp     al, [last_1sTick]
  223.     je      sh_exit
  224.  
  225.     mov     [last_1sTick], al
  226.  
  227.     stdcall arp_table_manager, ARP_TABLE_TIMER, 0, 0
  228.     call    tcp_tcb_handler
  229.  
  230. sh_exit:
  231.     ret
  232.  
  233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  234. ;; Checksum [by Johnny_B]
  235. ;;  IN:
  236. ;;    buf_ptr=POINTER to buffer
  237. ;;    buf_size=SIZE of buffer
  238. ;;  OUT:
  239. ;;    AX=16-bit checksum
  240. ;;              Saves all used registers
  241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  242. proc checksum_jb stdcall uses ebx esi ecx,\
  243.      buf_ptr:DWORD, buf_size:DWORD
  244.  
  245.     xor     eax, eax
  246.     xor     ebx, ebx  ;accumulator
  247.     mov     esi, dword[buf_ptr]
  248.     mov     ecx, dword[buf_size]
  249.     shr     ecx, 1  ; ecx=ecx/2
  250.     jnc     @f      ; if CF==0 then size is even number
  251.     mov     bh, byte[esi + ecx*2]
  252.   @@:
  253.     cld
  254.  
  255.   .loop:
  256.     lodsw   ;eax=word[esi],esi=esi+2
  257.     xchg    ah,al    ;cause must be a net byte-order
  258.     add     ebx, eax
  259.     loop    .loop
  260.  
  261.     mov     eax, ebx
  262.     shr     eax, 16
  263.     add     ax, bx
  264.     not     ax
  265.  
  266.     ret
  267. endp
  268.  
  269. ;***************************************************************************
  270. ;   Function
  271. ;      checksum
  272. ;
  273. ;   Description
  274. ;       checkAdd1,checkAdd2, checkSize1, checkSize2, checkResult
  275. ;       Dont break anything; Most registers are used by the caller
  276. ;       This code is derived from the 'C' source, cksum.c, in the book
  277. ;       Internetworking with TCP/IP Volume II by D.E. Comer
  278. ;
  279. ;***************************************************************************
  280.  
  281.  
  282. checksum:
  283.     pusha
  284.     mov     eax, [checkAdd1]
  285.     xor     edx, edx                  ; edx is the accumulative checksum
  286.     xor     ebx, ebx
  287.     mov     cx, [checkSize1]
  288.     shr     cx, 1
  289.     jz      cs1_1
  290.  
  291. cs1:
  292.     mov     bh, [eax]
  293.     mov     bl, [eax + 1]
  294.  
  295.     add     eax, 2
  296.     add     edx, ebx
  297.  
  298.     loopw   cs1
  299.  
  300. cs1_1:
  301.     and     word [checkSize1], 0x01
  302.     jz      cs_test2
  303.  
  304.     mov     bh, [eax]
  305.     xor     bl, bl
  306.  
  307.     add     edx, ebx
  308.  
  309. cs_test2:
  310.     mov     cx, [checkSize2]
  311.     cmp     cx, 0
  312.     jz      cs_exit                     ; Finished if no 2nd buffer
  313.  
  314.     mov     eax, [checkAdd2]
  315.  
  316.     shr     cx, 1
  317.     jz      cs2_1
  318.  
  319. cs2:
  320.     mov     bh, [eax]
  321.     mov     bl, [eax + 1]
  322.  
  323.     add     eax, 2
  324.     add     edx, ebx
  325.  
  326.     loopw   cs2
  327.  
  328. cs2_1:
  329.     and     word [checkSize2], 0x01
  330.     jz      cs_exit
  331.  
  332.     mov     bh, [eax]
  333.     xor     bl, bl
  334.  
  335.     add     edx, ebx
  336.  
  337. cs_exit:
  338.     mov     ebx, edx
  339.  
  340.     shr     ebx, 16
  341.     and     edx, 0xffff
  342.     add     edx, ebx
  343.     mov     eax, edx
  344.     shr     eax, 16
  345.     add     edx, eax
  346.     not     dx
  347.  
  348.     mov     [checkResult], dx
  349.     popa
  350.     ret
  351.  
  352.  
  353.  
  354.  
  355. ;***************************************************************************
  356. ;   Function
  357. ;      app_stack_handler
  358. ;
  359. ;   Description
  360. ;       This is an application service, called by int 0x40, function 52
  361. ;       It provides application access to the network interface layer
  362. ;
  363. ;***************************************************************************
  364. iglobal
  365. align 4
  366. f52call:
  367.         dd      app_stack_handler.00
  368.         dd      app_stack_handler.01
  369.         dd      app_stack_handler.02
  370.         dd      app_stack_handler.03
  371.         dd      app_stack_handler.fail  ;04
  372.         dd      app_stack_handler.fail  ;05
  373.         dd      stack_insert_packet     ;app_stack_handler.06
  374.         dd      app_stack_handler.fail  ;07
  375.         dd      stack_get_packet        ;app_stack_handler.08
  376.         dd      app_stack_handler.09
  377.         dd      app_stack_handler.10
  378.         dd      app_stack_handler.11
  379.         dd      app_stack_handler.12
  380.         dd      app_stack_handler.13
  381.         dd      app_stack_handler.14
  382.         dd      app_stack_handler.15
  383. endg
  384. app_stack_handler:
  385. ;in ebx,ecx
  386. ;out eax
  387.         cmp     ebx,15
  388.         ja      .fail                   ;if more than 15 then exit
  389.  
  390.         jmp     dword [f52call+ebx*4]
  391.  
  392.  
  393. .00:
  394. ; Read the configuration word
  395.         mov     eax, [stack_config]
  396.         ret
  397.  
  398. .01:
  399. ; read the IP address
  400.         mov     eax, [stack_ip]
  401.         ret
  402.  
  403. .02:
  404. ; write the configuration word
  405.         mov     [stack_config], ecx
  406.  
  407. ; <Slip shouldn't be active anyway - thats an operational issue.>
  408. ; If ethernet now enabled, probe for the card, reset it and empty
  409. ; the packet buffer
  410. ; If all successfull, enable the card.
  411. ; If ethernet now disabled, set it as disabled. Should really
  412. ; empty the tcpip data area too.
  413.  
  414. ; ethernet interface is '3' in ls 7 bits
  415.         and     cl, 0x7f
  416.         cmp     cl, 3
  417.         je      ash_eth_enable
  418. ; Ethernet isn't enabled, so make sure that the card is disabled
  419.         mov     [ethernet_active], byte 0
  420.         ret
  421.  
  422. .03:
  423. ; write the IP Address
  424.         mov     [stack_ip], ecx
  425.         ret
  426. ;old functions was deleted
  427. ;.06:
  428. ; Insert an IP packet into the stacks received packet queue
  429. ;       call    stack_insert_packet
  430. ;       ret
  431.  
  432. ; Test for any packets queued for transmission over the network
  433.  
  434. ;.08:
  435. ;       call    stack_get_packet
  436. ; Extract a packet queued for transmission by the network
  437. ;       ret
  438.  
  439. .09:
  440. ; read the gateway IP address
  441.         mov     eax, [gateway_ip]
  442.         ret
  443.  
  444. .10:
  445. ; read the subnet mask
  446.         mov     eax, [subnet_mask]
  447.         ret
  448. .11:
  449. ; write the gateway IP Address
  450.         mov     [gateway_ip], ecx
  451.         ret
  452.  
  453. .12:
  454. ; write the subnet mask
  455.         mov     [subnet_mask], ecx
  456.         ret
  457.  
  458. .13:
  459. ; read the dns
  460.         mov     eax, [dns_ip]
  461.         ret
  462.  
  463. .14:
  464. ; write the dns IP Address
  465.         mov     [dns_ip], ecx
  466.         ret
  467.  
  468. .15:
  469. ;<added by Frank Sommer>
  470. ; in ecx we need 4 to read the last 2 bytes
  471. ; or we need 0 to read the first 4 bytes
  472.         cmp     ecx,4
  473.         ja      .param_error
  474.  
  475. ; read MAC, returned (in mirrored byte order) in eax
  476.         mov     eax, [node_addr + ecx]
  477.         ret
  478.  
  479. .param_error:
  480.         or      eax, -1         ; params not accepted
  481.         ret
  482.  
  483. .16:
  484. ; 0 -> arp_probe
  485. ; 1 -> arp_announce
  486. ; 2 -> arp_responce (not supported yet)
  487.         test    ecx,ecx
  488.         je      a_probe
  489.  
  490.         dec     ebx
  491.         jz      a_ann                   ; arp announce
  492. .fail:
  493.         or      eax, -1
  494.         ret
  495.  
  496. ;       cmp     ebx,2
  497. ;       jne     a_resp                  ; arp response
  498.  
  499. ; arp probe, sender IP must be set to 0.0.0.0, target IP is set to address being probed
  500. ; ecx: pointer to target MAC, MAC should set to 0 by application
  501. ; edx: target IP
  502. a_probe:
  503.         push    dword [stack_ip]
  504.  
  505.         mov     edx, [stack_ip]
  506.         and     [stack_ip], dword 0
  507.         mov     esi, ecx                ; pointer to target MAC address
  508.         call    arp_request
  509.  
  510.         pop     dword [stack_ip]
  511.         ret
  512.  
  513. ; arp announce, sender IP must be set to target IP
  514. ; ecx: pointer to target MAC
  515. a_ann:
  516.         mov     edx, [stack_ip]
  517.         mov     esi, ecx                ; pointer to target MAC address
  518.         call    arp_request
  519.         ret
  520.  
  521. .17:
  522. ;</added by Frank Sommer>
  523. ; modified by [smb]
  524.  
  525. ;<added by Johnny_B>
  526. ; ARPTable manager interface
  527.     ;see "proc arp_table_manager" for more details
  528.     stdcall arp_table_manager,ecx,edx,esi  ;Opcode,Index,Extra
  529.     ret
  530. ;</added by Johnny_B>
  531.  
  532. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  533. ash_eth_enable:
  534. ; Probe for the card. This will reset it and enable the interface
  535. ; if found
  536.         call    eth_probe
  537.         test    eax,eax
  538.         jz      ash_eth_done            ; Abort if no hardware found
  539.  
  540.         mov     [ethernet_active], byte 1
  541. ash_eth_done:
  542.         ret
  543. ;***************************************************************************
  544. ;   Function
  545. ;      app_socket_handler
  546. ;
  547. ;   Description
  548. ;       This is an application service, called by int 0x40, function 53
  549. ;       It provides application access to stack socket services
  550. ;       such as opening sockets
  551. ;
  552. ;***************************************************************************
  553. iglobal
  554. align 4
  555. f53call:
  556.         dd      socket_open                     ;00
  557.         dd      socket_close                    ;01
  558.         dd      socket_poll                     ;02
  559.         dd      socket_read                     ;03
  560.         dd      socket_write                    ;04
  561.         dd      socket_open_tcp                 ;05
  562.         dd      socket_status                   ;06
  563.         dd      socket_write_tcp                ;07
  564.         dd      socket_close_tcp                ;08
  565.         dd      is_localport_unused             ;09
  566.         dd      app_socket_handler.10
  567.         dd      socket_read_packet              ;11
  568. endg
  569.  
  570. app_socket_handler:
  571. ;in ebx,ecx,edx,wsi
  572. ;out eax
  573.         cmp     eax,255
  574.         je      stack_internal_status
  575.  
  576.         cmp     eax,11
  577.         ja      .fail                   ;if more than 15 then exit
  578.  
  579.         jmp     dword [f53call+eax*4]
  580.  
  581. .10:
  582.         mov     eax,dword[drvr_cable]
  583.         test    eax,eax
  584.         jnz     @f                      ; if function is not implented, return -1
  585.         or      al,-1
  586.         ret
  587. @@:
  588.         jmp    dword[drvr_cable]
  589.  
  590. .fail:
  591.         or      eax,-1
  592.         ret
  593. uglobal
  594.   ARPTmp:
  595.   times 14 db 0
  596. endg
  597.  
  598. ;***************************************************************************
  599. ;   Function
  600. ;      stack_internal_status
  601. ;
  602. ;   Description
  603. ;       Returns information about the internal status of the stack
  604. ;       This is only useful for debugging
  605. ;       It works with the ethernet driver
  606. ;       sub function in ebx
  607. ;       return requested data in eax
  608. ;
  609. ;***************************************************************************
  610. ; This sub function allows access to debugging information on the stack
  611. ; ecx holds the request:
  612. ; 100 : return length of empty queue
  613. ; 101 : return length of IPOUT QUEUE
  614. ; 102 : return length of IPIN QUEUE
  615. ; 103 : return length of NET1OUT QUEUE
  616. ; 200 : return # of ARP entries
  617. ; 201 : return size of ARP table ( max # entries )
  618. ; 202 : select ARP table entry #
  619. ; 203 : return IP of selected table entry
  620. ; 204 : return High 4 bytes of MAC address of selected table entry
  621. ; 205 : return low  2 bytes of MAC address of selected table entry
  622. ; 206 : return status word of selected table entry
  623. ; 207 : return Time to live of selected table entry
  624.  
  625.  
  626. ;  2 : return number of IP packets received
  627. ;  3 : return number of packets transmitted
  628. ;  4 : return number of received packets dumped
  629. ;  5 : return number of arp packets received
  630. ;  6 : return status of packet driver
  631. ;  ( 0 == not active, FFFFFFFF = successful )
  632.  
  633.  
  634. stack_internal_status:
  635.     cmp     ebx, 100
  636.     jnz     notsis100
  637.  
  638.     ;  100 : return length of EMPTY QUEUE
  639.     mov     ebx, EMPTY_QUEUE
  640.     call    queueSize
  641.     ret
  642.  
  643. notsis100:
  644.     cmp     ebx, 101
  645.     jnz     notsis101
  646.  
  647.     ;  101 : return length of IPOUT QUEUE
  648.     mov     ebx, IPOUT_QUEUE
  649.     call    queueSize                      
  650.     ret
  651.  
  652. notsis101:
  653.     cmp     ebx, 102
  654.     jnz     notsis102
  655.  
  656.     ;  102 : return length of IPIN QUEUE
  657.     mov     ebx, IPIN_QUEUE
  658.     call    queueSize
  659.     ret
  660.  
  661. notsis102:
  662.     cmp     ebx, 103
  663.     jnz     notsis103
  664.  
  665.     ;  103 : return length of NET1OUT QUEUE
  666.     mov     ebx, NET1OUT_QUEUE
  667.     call    queueSize
  668.     ret
  669.  
  670. notsis103:
  671.     cmp     ebx, 200
  672.     jnz     notsis200
  673.  
  674.     ; 200 : return num entries in arp table
  675.     movzx   eax, byte [NumARP]
  676.     ret
  677.  
  678. notsis200:
  679.     cmp     ebx, 201
  680.     jnz     notsis201
  681.  
  682.     ; 201 : return arp table size
  683.     mov     eax, 20 ; ARP_TABLE_SIZE
  684.     ret
  685.  
  686. notsis201:
  687.     cmp     ebx, 202
  688.     jnz     notsis202
  689.  
  690.     ; 202 - read the requested table entry
  691.     ; into a temporary buffer
  692.     ; ecx holds the entry number
  693.  
  694.     mov     eax, ecx
  695.     mov     ecx, 14 ; ARP_ENTRY_SIZE
  696.     mul     ecx
  697.  
  698.     mov     ecx, [eax + ARPTable]
  699.     mov     [ARPTmp], ecx
  700.     mov     ecx, [eax + ARPTable+4]
  701.     mov     [ARPTmp+4], ecx
  702.     mov     ecx, [eax + ARPTable+8]
  703.     mov     [ARPTmp+8], ecx
  704.     mov     cx, [eax + ARPTable+12]
  705.     mov     [ARPTmp+12], cx
  706.     ret
  707.  
  708. notsis202:
  709.     cmp     ebx, 203
  710.     jnz     notsis203
  711.  
  712.     ; 203 - return IP address
  713.     mov     eax, [ARPTmp]
  714.     ret
  715.  
  716. notsis203:
  717.     cmp     ebx, 204
  718.     jnz     notsis204
  719.  
  720.     ; 204 - return MAC high dword
  721.     mov     eax, [ARPTmp+4]
  722.     ret
  723.  
  724. notsis204:
  725.     cmp     ebx, 205
  726.     jnz     notsis205
  727.  
  728.     ; 205 - return MAC ls word
  729.     movzx   eax, word [ARPTmp+8]
  730.     ret
  731.  
  732. notsis205:
  733.     cmp     ebx, 206
  734.     jnz     notsis206
  735.  
  736.     ; 206 - return status word
  737.     movzx   eax, word [ARPTmp+10]
  738.     ret
  739.  
  740. notsis206:
  741.     cmp     ebx, 207
  742.     jnz     notsis207
  743.  
  744.     ; 207 - return ttl word
  745.     movzx   eax, word [ARPTmp+12]
  746.     ret
  747.  
  748. notsis207:
  749.     cmp     ebx, 2
  750.     jnz     notsis2
  751.  
  752.     ;  2 : return number of IP packets received
  753.     mov     eax, [ip_rx_count]
  754.     ret
  755.  
  756. notsis2:
  757.     cmp     ebx, 3
  758.     jnz     notsis3
  759.  
  760.     ;  3 : return number of packets transmitted
  761.     mov     eax, [ip_tx_count]
  762.     ret
  763.  
  764. notsis3:
  765.     cmp     ebx, 4
  766.     jnz     notsis4
  767.  
  768.     ;  4 : return number of received packets dumped
  769.     mov     eax, [dumped_rx_count]
  770.     ret
  771.  
  772. notsis4:
  773.     cmp     ebx, 5
  774.     jnz     notsis5
  775.  
  776.     ;  5 : return number of arp packets received
  777.     mov     eax, [arp_rx_count]
  778.     ret
  779.  
  780. notsis5:
  781.     cmp     ebx, 6
  782.     jnz     notsis6
  783.  
  784.     ;  6 : return status of packet driver
  785.     ;  ( 0 == not active, FFFFFFFF = successful )
  786.     mov     eax, [eth_status]
  787.     ret
  788.  
  789. notsis6:
  790.     xor     eax, eax
  791.     ret
  792.  
  793.  
  794.  
  795. ;***************************************************************************
  796. ;   Function
  797. ;      stack_get_packet
  798. ;
  799. ;   Description
  800. ;       extracts an IP packet from the NET1 output queue
  801. ;       and sends the data to the calling process
  802. ;       pointer to data in edx
  803. ;       returns number of bytes read in eax
  804. ;
  805. ;***************************************************************************
  806. stack_get_packet:
  807.     ; Look for a buffer to tx
  808.     mov     eax, NET1OUT_QUEUE
  809.     call    dequeue
  810.     cmp     ax, NO_BUFFER
  811.     je      sgp_non_exit            ; Exit if no buffer available
  812.  
  813.     push    eax                     ; Save buffer number for freeing at end
  814.  
  815.     push    edx
  816.     ; convert buffer pointer eax to the absolute address
  817.     mov     ecx, IPBUFFSIZE
  818.     mul     ecx
  819.     add     eax, IPbuffs
  820.     pop     edx
  821.  
  822.     push    eax                     ; save address of IP data
  823.     ; Get the address of the callers data
  824.     mov     edi,[TASK_BASE]
  825.     add     edi,TASKDATA.mem_start
  826.     add     edx,[edi]
  827.     mov     edi, edx
  828.     pop     eax
  829.  
  830.     mov     ecx, 1500           ; should get the actual number of bytes to write
  831.     mov     esi, eax
  832.     cld
  833.     rep     movsb               ; copy the data across
  834.  
  835.     ; And finally, return the buffer to the free queue
  836.     pop     eax
  837.     call    freeBuff
  838.  
  839.     mov     eax, 1500
  840.     ret
  841.  
  842. sgp_non_exit:
  843.     xor     eax, eax
  844.     ret
  845.  
  846.  
  847.  
  848. ;***************************************************************************
  849. ;   Function
  850. ;      stack_insert_packet
  851. ;
  852. ;   Description
  853. ;       writes an IP packet into the stacks receive queue
  854. ;       # of bytes to write in ecx
  855. ;       pointer to data in edx
  856. ;       returns 0 in eax ok, -1 == failed
  857. ;
  858. ;***************************************************************************
  859. stack_insert_packet:
  860.  
  861.     mov     eax, EMPTY_QUEUE
  862.     call    dequeue
  863.     cmp     ax, NO_BUFFER
  864.     je      sip_err_exit
  865.  
  866.     push    eax
  867.  
  868.     ; save the pointers to the data buffer & size
  869.     push    edx
  870.     push    ecx
  871.  
  872.     ; convert buffer pointer eax to the absolute address
  873.     mov     ecx, IPBUFFSIZE
  874.     mul     ecx
  875.     add     eax, IPbuffs
  876.  
  877.     mov     edx, eax
  878.  
  879.     ; So, edx holds the IPbuffer ptr
  880.  
  881.     pop     ecx                     ; count of bytes to send
  882.     mov     ebx, ecx                ; need the length later
  883.     pop     eax                     ; get callers ptr to data to send
  884.  
  885.     ; Get the address of the callers data
  886.     mov     edi,[TASK_BASE]
  887.     add     edi,TASKDATA.mem_start
  888.     add     eax,[edi]
  889.     mov     esi, eax
  890.  
  891.     mov     edi, edx
  892.     cld
  893.     rep     movsb               ; copy the data across
  894.  
  895.     pop     ebx
  896.  
  897.     mov     eax, IPIN_QUEUE
  898.     call    queue
  899.  
  900.     inc     dword [ip_rx_count]
  901.  
  902.     mov     eax, 0
  903.     ret
  904.  
  905. sip_err_exit:
  906.     mov     eax, 0xFFFFFFFF
  907.     ret
  908.  
  909.