Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1196 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2362 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
1196 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
7
;;                                                                 ;;
1514 hidnplayr 8
;;   Written by hidnplayr@kolibrios.org                            ;;
1196 hidnplayr 9
;;                                                                 ;;
1514 hidnplayr 10
;;    Based on the code of 4.4BSD                                  ;;
11
;;                                                                 ;;
1196 hidnplayr 12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1159 hidnplayr 16
 
1206 hidnplayr 17
$Revision: 2953 $
1159 hidnplayr 18
 
1514 hidnplayr 19
; Socket states
2614 hidnplayr 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
1196 hidnplayr 31
 
1514 hidnplayr 32
; Socket Flags
2614 hidnplayr 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
1249 hidnplayr 43
 
1514 hidnplayr 44
; Segment flags
2614 hidnplayr 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
1318 hidnplayr 51
 
1514 hidnplayr 52
; Segment header options
2614 hidnplayr 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
2953 hidnplayr 57
TCP_OPT_SACK_PERMIT     = 4           ; Selective Acknowledgement
58
TCP_OPT_SACK            = 5
2614 hidnplayr 59
TCP_OPT_TIMESTAMP       = 8
1514 hidnplayr 60
 
1519 hidnplayr 61
; Fundamental timer values
2614 hidnplayr 62
TCP_time_MSL            = 47          ; max segment lifetime (30s)
63
TCP_time_re_min         = 2           ; min retransmission (1,28s)
64
TCP_time_re_max         = 100         ; max retransmission (64s)
65
TCP_time_pers_min       = 8           ; min persist (5,12s)
66
TCP_time_pers_max       = 94          ; max persist (60,16s)
67
TCP_time_keep_init      = 118         ; connectione stablishment (75,52s)
68
TCP_time_keep_idle      = 4608        ; idle time before 1st probe (2h)
69
TCP_time_keep_interval  = 118         ; between probes when no response (75,52s)
70
TCP_time_rtt_default    = 5           ; default Round Trip Time (3,2s)
71
TCP_time_srtt_default   = 0           ;
2937 hidnplayr 72
TCP_time_max_idle       = 8*TCP_time_keep_interval      ; FIXME
1519 hidnplayr 73
 
74
; timer constants
2614 hidnplayr 75
TCP_max_rxtshift        = 12          ; max retransmissions waiting for ACK
76
TCP_max_keepcnt         = 8           ; max keepalive probes
1519 hidnplayr 77
 
1529 hidnplayr 78
;
2614 hidnplayr 79
TCP_max_winshift        = 14
80
TCP_max_win             = 65535
1519 hidnplayr 81
 
2614 hidnplayr 82
TCP_re_xmit_thresh      = 3
1763 hidnplayr 83
 
2614 hidnplayr 84
TCP_mss_default         = 1480        ; default max segment size
2305 hidnplayr 85
 
2937 hidnplayr 86
; smoothed round trip time and estimated variance are stored as fixed point numbers,
87
; shifted by the value below.
88
; With these scales, srtt has 3 bits to the right of the binary point, and thus an "alpha"
89
; of .875. rttvar has 2 bits to the right and thus "alpha" of 0.75
90
TCP_RTT_SHIFT           = 3
91
TCP_RTTVAR_SHIFT        = 2
92
 
93
; bits used by tcp_input and tcp_output
94
TCP_BIT_NEEDOUTPUT      = 1 shl 0
95
TCP_BIT_TIMESTAMP       = 1 shl 1
96
TCP_BIT_DROPSOCKET      = 1 shl 2
97
 
98
TCP_BIT_SENDALOT        = 1 shl 0
99
 
2947 hidnplayr 100
TCP_PAWS_IDLE           = 24*24*60*60*100       ; 24 days, in 1/100 seconds
101
 
2612 hidnplayr 102
struct  TCP_header
2305 hidnplayr 103
 
2612 hidnplayr 104
        SourcePort              dw ?
105
        DestinationPort         dw ?
106
        SequenceNumber          dd ?
107
        AckNumber               dd ?
108
        DataOffset              db ?    ; DataOffset[0-3 bits] and Reserved[4-7]
109
        Flags                   db ?    ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN
110
        Window                  dw ?
111
        Checksum                dw ?
112
        UrgentPointer           dw ?
113
 
1159 hidnplayr 114
ends
115
 
1196 hidnplayr 116
align 4
117
uglobal
2924 hidnplayr 118
        TCP_segments_tx         rd MAX_NET_DEVICES
119
        TCP_segments_rx         rd MAX_NET_DEVICES
120
        TCP_bytes_rx            rq MAX_NET_DEVICES
121
        TCP_bytes_tx            rq MAX_NET_DEVICES
2612 hidnplayr 122
        TCP_sequence_num        dd ?
1196 hidnplayr 123
endg
124
 
125
 
126
;-----------------------------------------------------------------
127
;
128
; TCP_init
129
;
130
;  This function resets all TCP variables
131
;
132
;-----------------------------------------------------------------
2612 hidnplayr 133
macro   TCP_init {
1196 hidnplayr 134
 
2612 hidnplayr 135
        xor     eax, eax
2614 hidnplayr 136
        mov     edi, TCP_segments_tx
2924 hidnplayr 137
        mov     ecx, (6*MAX_NET_DEVICES)
2612 hidnplayr 138
        rep     stosd
1196 hidnplayr 139
 
2612 hidnplayr 140
        pseudo_random   eax
141
        mov     [TCP_sequence_num], eax
1196 hidnplayr 142
 
1529 hidnplayr 143
}
1196 hidnplayr 144
 
145
 
1733 hidnplayr 146
include 'tcp_timer.inc'
147
include 'tcp_subr.inc'
148
include 'tcp_input.inc'
149
include 'tcp_output.inc'
1159 hidnplayr 150
 
1529 hidnplayr 151
 
1254 hidnplayr 152
;---------------------------------------------------------------------------
153
;
154
; TCP_API
155
;
2866 hidnplayr 156
; This function is called by system function 76
1254 hidnplayr 157
;
158
; IN:  subfunction number in bl
159
;      device number in bh
160
;      ecx, edx, .. depends on subfunction
161
;
162
; OUT:
163
;
164
;---------------------------------------------------------------------------
165
align 4
2614 hidnplayr 166
TCP_api:
1254 hidnplayr 167
 
2612 hidnplayr 168
        movzx   eax, bh
169
        shl     eax, 2
1254 hidnplayr 170
 
2612 hidnplayr 171
        test    bl, bl
172
        jz      .packets_tx     ; 0
173
        dec     bl
174
        jz      .packets_rx     ; 1
1254 hidnplayr 175
 
2614 hidnplayr 176
  .error:
2612 hidnplayr 177
        mov     eax, -1
178
        ret
1254 hidnplayr 179
 
2614 hidnplayr 180
  .packets_tx:
181
        mov     eax, [TCP_segments_tx + eax]
2612 hidnplayr 182
        ret
1254 hidnplayr 183
 
2614 hidnplayr 184
  .packets_rx:
185
        mov     eax, [TCP_segments_rx + eax]
2612 hidnplayr 186
        ret