Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  Part of the tcp/ip network stack for KolibriOS                 ;;
  7. ;;                                                                 ;;
  8. ;;   Written by hidnplayr@kolibrios.org                            ;;
  9. ;;                                                                 ;;
  10. ;;    Based on the code of 4.4BSD                                  ;;
  11. ;;                                                                 ;;
  12. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  13. ;;             Version 2, June 1991                                ;;
  14. ;;                                                                 ;;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. $Revision: 2947 $
  18.  
  19. ; Socket states
  20. TCPS_CLOSED             = 0
  21. TCPS_LISTEN             = 1
  22. TCPS_SYN_SENT           = 2
  23. TCPS_SYN_RECEIVED       = 3
  24. TCPS_ESTABLISHED        = 4
  25. TCPS_CLOSE_WAIT         = 5
  26. TCPS_FIN_WAIT_1         = 6
  27. TCPS_CLOSING            = 7
  28. TCPS_LAST_ACK           = 8
  29. TCPS_FIN_WAIT_2         = 9
  30. TCPS_TIMED_WAIT         = 10
  31.  
  32. ; Socket Flags
  33. TF_ACKNOW               = 1 shl 0     ; ack peer immediately
  34. TF_DELACK               = 1 shl 1     ; ack, but try to delay it
  35. TF_NODELAY              = 1 shl 2     ; don't delay packets to coalesce
  36. TF_NOOPT                = 1 shl 3     ; don't use tcp options
  37. TF_SENTFIN              = 1 shl 4     ; have sent FIN
  38. TF_REQ_SCALE            = 1 shl 5     ; have/will request window scaling
  39. TF_RCVD_SCALE           = 1 shl 6     ; other side has requested scaling
  40. TF_REQ_TSTMP            = 1 shl 7     ; have/will request timestamps
  41. TF_RCVD_TSTMP           = 1 shl 8     ; a timestamp was received in SYN
  42. TF_SACK_PERMIT          = 1 shl 9     ; other side said I could SACK
  43.  
  44. ; Segment flags
  45. TH_FIN                  = 1 shl 0
  46. TH_SYN                  = 1 shl 1
  47. TH_RST                  = 1 shl 2
  48. TH_PUSH                 = 1 shl 3
  49. TH_ACK                  = 1 shl 4
  50. TH_URG                  = 1 shl 5
  51.  
  52. ; Segment header options
  53. TCP_OPT_EOL             = 0           ; End of option list.
  54. TCP_OPT_NOP             = 1           ; No-Operation.
  55. TCP_OPT_MAXSEG          = 2           ; Maximum Segment Size.
  56. TCP_OPT_WINDOW          = 3           ; window scale
  57. TCP_OPT_TIMESTAMP       = 8
  58.  
  59. ; Fundamental timer values
  60. TCP_time_MSL            = 47          ; max segment lifetime (30s)
  61. TCP_time_re_min         = 2           ; min retransmission (1,28s)
  62. TCP_time_re_max         = 100         ; max retransmission (64s)
  63. TCP_time_pers_min       = 8           ; min persist (5,12s)
  64. TCP_time_pers_max       = 94          ; max persist (60,16s)
  65. TCP_time_keep_init      = 118         ; connectione stablishment (75,52s)
  66. TCP_time_keep_idle      = 4608        ; idle time before 1st probe (2h)
  67. TCP_time_keep_interval  = 118         ; between probes when no response (75,52s)
  68. TCP_time_rtt_default    = 5           ; default Round Trip Time (3,2s)
  69. TCP_time_srtt_default   = 0           ;
  70. TCP_time_max_idle       = 8*TCP_time_keep_interval      ; FIXME
  71.  
  72. ; timer constants
  73. TCP_max_rxtshift        = 12          ; max retransmissions waiting for ACK
  74. TCP_max_keepcnt         = 8           ; max keepalive probes
  75.  
  76. ;
  77. TCP_max_winshift        = 14
  78. TCP_max_win             = 65535
  79.  
  80. TCP_re_xmit_thresh      = 3
  81.  
  82. TCP_mss_default         = 1480        ; default max segment size
  83.  
  84. ; smoothed round trip time and estimated variance are stored as fixed point numbers,
  85. ; shifted by the value below.
  86. ; With these scales, srtt has 3 bits to the right of the binary point, and thus an "alpha"
  87. ; of .875. rttvar has 2 bits to the right and thus "alpha" of 0.75
  88. TCP_RTT_SHIFT           = 3
  89. TCP_RTTVAR_SHIFT        = 2
  90.  
  91. ; bits used by tcp_input and tcp_output
  92. TCP_BIT_NEEDOUTPUT      = 1 shl 0
  93. TCP_BIT_TIMESTAMP       = 1 shl 1
  94. TCP_BIT_DROPSOCKET      = 1 shl 2
  95.  
  96. TCP_BIT_SENDALOT        = 1 shl 0
  97.  
  98. TCP_PAWS_IDLE           = 24*24*60*60*100       ; 24 days, in 1/100 seconds
  99.  
  100. struct  TCP_header
  101.  
  102.         SourcePort              dw ?
  103.         DestinationPort         dw ?
  104.         SequenceNumber          dd ?
  105.         AckNumber               dd ?
  106.         DataOffset              db ?    ; DataOffset[0-3 bits] and Reserved[4-7]
  107.         Flags                   db ?    ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN
  108.         Window                  dw ?
  109.         Checksum                dw ?
  110.         UrgentPointer           dw ?
  111.  
  112. ends
  113.  
  114. align 4
  115. uglobal
  116.         TCP_segments_tx         rd MAX_NET_DEVICES
  117.         TCP_segments_rx         rd MAX_NET_DEVICES
  118.         TCP_bytes_rx            rq MAX_NET_DEVICES
  119.         TCP_bytes_tx            rq MAX_NET_DEVICES
  120.         TCP_sequence_num        dd ?
  121. endg
  122.  
  123.  
  124. ;-----------------------------------------------------------------
  125. ;
  126. ; TCP_init
  127. ;
  128. ;  This function resets all TCP variables
  129. ;
  130. ;-----------------------------------------------------------------
  131. macro   TCP_init {
  132.  
  133.         xor     eax, eax
  134.         mov     edi, TCP_segments_tx
  135.         mov     ecx, (6*MAX_NET_DEVICES)
  136.         rep     stosd
  137.  
  138.         pseudo_random   eax
  139.         mov     [TCP_sequence_num], eax
  140.  
  141. }
  142.  
  143.  
  144. include 'tcp_timer.inc'
  145. include 'tcp_subr.inc'
  146. include 'tcp_input.inc'
  147. include 'tcp_output.inc'
  148.  
  149.  
  150. ;---------------------------------------------------------------------------
  151. ;
  152. ; TCP_API
  153. ;
  154. ; This function is called by system function 76
  155. ;
  156. ; IN:  subfunction number in bl
  157. ;      device number in bh
  158. ;      ecx, edx, .. depends on subfunction
  159. ;
  160. ; OUT:
  161. ;
  162. ;---------------------------------------------------------------------------
  163. align 4
  164. TCP_api:
  165.  
  166.         movzx   eax, bh
  167.         shl     eax, 2
  168.  
  169.         test    bl, bl
  170.         jz      .packets_tx     ; 0
  171.         dec     bl
  172.         jz      .packets_rx     ; 1
  173.  
  174.   .error:
  175.         mov     eax, -1
  176.         ret
  177.  
  178.   .packets_tx:
  179.         mov     eax, [TCP_segments_tx + eax]
  180.         ret
  181.  
  182.   .packets_rx:
  183.         mov     eax, [TCP_segments_rx + eax]
  184.         ret
  185.