Subversion Repositories Kolibri OS

Rev

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