Subversion Repositories Kolibri OS

Rev

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

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