Subversion Repositories Kolibri OS

Rev

Rev 907 | Blame | Last modification | View Log | Download | RSS feed

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