Rev 3725 | Rev 4423 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3555 | Serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2013. 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 16 | |
593 | mikedld | 17 | $Revision: 4265 $ |
18 | |||
3555 | Serge | 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 |
||
593 | mikedld | 31 | |
3555 | Serge | 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 |
||
1 | ha | 43 | |
3555 | Serge | 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 |
||
261 | hidnplayr | 51 | |
3555 | Serge | 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_SACK_PERMIT = 4 ; Selective Acknowledgement |
||
58 | TCP_OPT_SACK = 5 |
||
59 | TCP_OPT_TIMESTAMP = 8 |
||
261 | hidnplayr | 60 | |
3555 | Serge | 61 | ; Fundamental timer values |
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 ; connection establishment (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 ; |
||
72 | TCP_time_max_idle = 8*TCP_time_keep_interval ; FIXME |
||
907 | mikedld | 73 | |
4265 | Serge | 74 | TCP_time_connect = 300 ; in 1/100s (default=3s) |
75 | |||
3555 | Serge | 76 | ; timer constants |
77 | TCP_max_rxtshift = 12 ; max retransmissions waiting for ACK |
||
78 | TCP_max_keepcnt = 8 ; max keepalive probes |
||
1 | ha | 79 | |
261 | hidnplayr | 80 | ; |
3555 | Serge | 81 | TCP_max_winshift = 14 |
82 | TCP_max_win = 65535 |
||
1 | ha | 83 | |
3555 | Serge | 84 | TCP_re_xmit_thresh = 3 |
261 | hidnplayr | 85 | |
3555 | Serge | 86 | TCP_mss_default = 1480 ; default max segment size |
261 | hidnplayr | 87 | |
3555 | Serge | 88 | ; smoothed round trip time and estimated variance are stored as fixed point numbers, |
89 | ; shifted by the value below. |
||
90 | ; With these scales, srtt has 3 bits to the right of the binary point, and thus an "alpha" |
||
91 | ; of .875. rttvar has 2 bits to the right and thus "alpha" of 0.75 |
||
92 | TCP_RTT_SHIFT = 3 |
||
93 | TCP_RTTVAR_SHIFT = 2 |
||
261 | hidnplayr | 94 | |
3555 | Serge | 95 | ; bits used by tcp_input and tcp_output |
96 | TCP_BIT_NEEDOUTPUT = 1 shl 0 |
||
97 | TCP_BIT_TIMESTAMP = 1 shl 1 |
||
98 | TCP_BIT_DROPSOCKET = 1 shl 2 |
||
261 | hidnplayr | 99 | |
3555 | Serge | 100 | TCP_BIT_SENDALOT = 1 shl 0 |
261 | hidnplayr | 101 | |
3555 | Serge | 102 | TCP_PAWS_IDLE = 24*24*60*60*100 ; 24 days, in 1/100 seconds |
1 | ha | 103 | |
3555 | Serge | 104 | TCP_QUEUE_SIZE = 50 |
1 | ha | 105 | |
3555 | Serge | 106 | struct TCP_header |
1 | ha | 107 | |
3555 | Serge | 108 | SourcePort dw ? |
109 | DestinationPort dw ? |
||
110 | SequenceNumber dd ? |
||
111 | AckNumber dd ? |
||
112 | DataOffset db ? ; DataOffset[0-3 bits] and Reserved[4-7] |
||
113 | Flags db ? ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN |
||
114 | Window dw ? |
||
115 | Checksum dw ? |
||
116 | UrgentPointer dw ? |
||
1 | ha | 117 | |
3555 | Serge | 118 | ends |
1 | ha | 119 | |
3555 | Serge | 120 | struct TCP_queue_entry |
1 | ha | 121 | |
3555 | Serge | 122 | ip_ptr dd ? |
123 | segment_ptr dd ? |
||
124 | segment_size dd ? |
||
125 | device_ptr dd ? |
||
1 | ha | 126 | |
3555 | Serge | 127 | buffer_ptr dd ? |
128 | timestamp dd ? |
||
1 | ha | 129 | |
3555 | Serge | 130 | ends |
1 | ha | 131 | |
3725 | Serge | 132 | uglobal |
3555 | Serge | 133 | align 4 |
3725 | Serge | 134 | |
3626 | Serge | 135 | TCP_segments_tx rd NET_DEVICES_MAX |
136 | TCP_segments_rx rd NET_DEVICES_MAX |
||
137 | TCP_segments_missed rd NET_DEVICES_MAX |
||
138 | TCP_segments_dumped rd NET_DEVICES_MAX |
||
139 | ; TCP_bytes_rx rq NET_DEVICES_MAX |
||
140 | ; TCP_bytes_tx rq NET_DEVICES_MAX |
||
3555 | Serge | 141 | TCP_sequence_num dd ? |
3725 | Serge | 142 | TCP_queue rd (TCP_QUEUE_SIZE*sizeof.TCP_queue_entry + sizeof.queue)/4 |
3555 | Serge | 143 | TCP_input_event dd ? |
144 | endg |
||
1 | ha | 145 | |
146 | |||
3555 | Serge | 147 | ;----------------------------------------------------------------- |
1 | ha | 148 | ; |
3555 | Serge | 149 | ; TCP_init |
1 | ha | 150 | ; |
3555 | Serge | 151 | ; This function resets all TCP variables |
152 | ; |
||
153 | ;----------------------------------------------------------------- |
||
154 | macro TCP_init { |
||
907 | mikedld | 155 | |
3555 | Serge | 156 | xor eax, eax |
157 | mov edi, TCP_segments_tx |
||
3626 | Serge | 158 | mov ecx, (6*NET_DEVICES_MAX) |
3725 | Serge | 159 | rep stosd |
1 | ha | 160 | |
3555 | Serge | 161 | pseudo_random eax |
162 | mov [TCP_sequence_num], eax |
||
1 | ha | 163 | |
3555 | Serge | 164 | init_queue TCP_queue |
1 | ha | 165 | |
3626 | Serge | 166 | movi ebx, 1 |
3555 | Serge | 167 | mov ecx, TCP_process_input |
168 | call new_sys_threads |
||
3725 | Serge | 169 | test eax, eax |
170 | jns @f |
||
171 | DEBUGF DEBUG_NETWORK_ERROR,'K : cannot create kernel thread for TCP, error %d\n', eax |
||
172 | @@: |
||
1 | ha | 173 | |
3555 | Serge | 174 | } |
1 | ha | 175 | |
176 | |||
3555 | Serge | 177 | include 'tcp_timer.inc' |
178 | include 'tcp_subr.inc' |
||
179 | include 'tcp_usreq.inc' |
||
180 | include 'tcp_input.inc' |
||
181 | include 'tcp_output.inc' |
||
1 | ha | 182 | |
183 | |||
3555 | Serge | 184 | ;--------------------------------------------------------------------------- |
1 | ha | 185 | ; |
3555 | Serge | 186 | ; TCP_API |
1 | ha | 187 | ; |
3555 | Serge | 188 | ; This function is called by system function 76 |
1 | ha | 189 | ; |
3555 | Serge | 190 | ; IN: subfunction number in bl |
191 | ; device number in bh |
||
192 | ; ecx, edx, .. depends on subfunction |
||
1 | ha | 193 | ; |
3555 | Serge | 194 | ; OUT: |
1 | ha | 195 | ; |
3555 | Serge | 196 | ;--------------------------------------------------------------------------- |
197 | align 4 |
||
198 | TCP_api: |
||
1 | ha | 199 | |
3555 | Serge | 200 | movzx eax, bh |
201 | shl eax, 2 |
||
1 | ha | 202 | |
3555 | Serge | 203 | test bl, bl |
204 | jz .packets_tx ; 0 |
||
205 | dec bl |
||
206 | jz .packets_rx ; 1 |
||
207 | dec bl |
||
208 | jz .packets_missed ; 2 |
||
209 | dec bl |
||
210 | jz .packets_dumped ; 3 |
||
1 | ha | 211 | |
3555 | Serge | 212 | .error: |
213 | mov eax, -1 |
||
2434 | Serge | 214 | ret |
1 | ha | 215 | |
3555 | Serge | 216 | .packets_tx: |
217 | mov eax, [TCP_segments_tx + eax] |
||
2434 | Serge | 218 | ret |
1181 | clevermous | 219 | |
3555 | Serge | 220 | .packets_rx: |
221 | mov eax, [TCP_segments_rx + eax] |
||
2434 | Serge | 222 | ret |
1 | ha | 223 | |
3555 | Serge | 224 | .packets_missed: |
225 | mov eax, [TCP_segments_missed + eax] |
||
2434 | Serge | 226 | ret |
1 | ha | 227 | |
3555 | Serge | 228 | .packets_dumped: |
229 | mov eax, [TCP_segments_dumped + eax] |
||
2434 | Serge | 230 | ret |