Subversion Repositories Kolibri OS

Rev

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