Rev 5976 | Rev 6413 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5976 | Rev 6011 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Based on the code of 4.4BSD ;; |
10 | ;; Based on the code of 4.4BSD ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | 16 | ||
17 | $Revision: 5976 $ |
17 | $Revision: 6011 $ |
18 | 18 | ||
19 | ;-----------------------------------------------------------------; |
19 | ;-----------------------------------------------------------------; |
20 | ; ; |
20 | ; ; |
21 | ; TCP_output ; |
21 | ; tcp_output ; |
22 | ; ; |
22 | ; ; |
23 | ; IN: eax = socket pointer ; |
23 | ; IN: eax = socket pointer ; |
24 | ; ; |
24 | ; ; |
25 | ; OUT: eax = 0 on success/errorcode ; |
25 | ; OUT: eax = 0 on success/errorcode ; |
26 | ; ; |
26 | ; ; |
27 | ;-----------------------------------------------------------------; |
27 | ;-----------------------------------------------------------------; |
28 | align 4 |
28 | align 4 |
29 | proc TCP_output |
29 | proc tcp_output |
30 | 30 | ||
31 | locals |
31 | locals |
32 | temp_bits db ? |
32 | temp_bits db ? |
33 | endl |
33 | endl |
34 | 34 | ||
35 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket=%x state=%u\n", eax, [eax + TCP_SOCKET.t_state] |
35 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket=%x state=%u\n", eax, [eax + TCP_SOCKET.t_state] |
36 | 36 | ||
37 | push eax |
37 | push eax |
38 | lea ecx, [eax + SOCKET.mutex] |
38 | lea ecx, [eax + SOCKET.mutex] |
39 | call mutex_lock |
39 | call mutex_lock |
40 | pop eax |
40 | pop eax |
41 | 41 | ||
42 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket locked\n" |
42 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket locked\n" |
43 | 43 | ||
44 | ; We'll detect the length of the data to be transmitted, and flags to be used |
44 | ; We'll detect the length of the data to be transmitted, and flags to be used |
45 | ; If there is some data, or any critical controls to send (SYN / RST), then transmit |
45 | ; If there is some data, or any critical controls to send (SYN / RST), then transmit |
46 | ; Otherwise, investigate further |
46 | ; Otherwise, investigate further |
47 | 47 | ||
48 | mov ebx, [eax + TCP_SOCKET.SND_MAX] |
48 | mov ebx, [eax + TCP_SOCKET.SND_MAX] |
49 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
49 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
50 | jbe .not_idle |
50 | jbe .not_idle |
51 | 51 | ||
52 | mov ebx, [eax + TCP_SOCKET.t_idle] |
52 | mov ebx, [eax + TCP_SOCKET.t_idle] |
53 | cmp ebx, [eax + TCP_SOCKET.t_rxtcur] |
53 | cmp ebx, [eax + TCP_SOCKET.t_rxtcur] |
54 | jbe .not_idle |
54 | jbe .not_idle |
55 | 55 | ||
56 | ; We have been idle for a while and no ACKS are expected to clock out any data we send.. |
56 | ; We have been idle for a while and no ACKS are expected to clock out any data we send.. |
57 | ; Slow start to get ack "clock" running again. |
57 | ; Slow start to get ack "clock" running again. |
58 | 58 | ||
59 | mov ebx, [eax + TCP_SOCKET.t_maxseg] |
59 | mov ebx, [eax + TCP_SOCKET.t_maxseg] |
60 | mov [eax + TCP_SOCKET.SND_CWND], ebx |
60 | mov [eax + TCP_SOCKET.SND_CWND], ebx |
61 | 61 | ||
62 | .not_idle: |
62 | .not_idle: |
63 | .again: |
63 | .again: |
64 | mov [temp_bits], 0 |
64 | mov [temp_bits], 0 |
65 | 65 | ||
66 | mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71) |
66 | mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71) |
67 | sub ebx, [eax + TCP_SOCKET.SND_UNA] ; |
67 | sub ebx, [eax + TCP_SOCKET.SND_UNA] ; |
68 | 68 | ||
69 | mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window |
69 | mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window |
70 | cmp ecx, [eax + TCP_SOCKET.SND_CWND] ; |
70 | cmp ecx, [eax + TCP_SOCKET.SND_CWND] ; |
71 | jb @f ; |
71 | jb @f ; |
72 | mov ecx, [eax + TCP_SOCKET.SND_CWND] ; |
72 | mov ecx, [eax + TCP_SOCKET.SND_CWND] ; |
73 | @@: ; |
73 | @@: ; |
74 | 74 | ||
75 | call TCP_outflags ; flags in dl |
75 | call tcp_outflags ; flags in dl |
76 | 76 | ||
77 | ;------------------------ |
77 | ;------------------------ |
78 | ; data being forced out ? |
78 | ; data being forced out ? |
79 | 79 | ||
80 | ; If in persist timeout with window of 0, send 1 byte. |
80 | ; If in persist timeout with window of 0, send 1 byte. |
81 | ; Otherwise, if window is small but nonzero, and timer expired, |
81 | ; Otherwise, if window is small but nonzero, and timer expired, |
82 | ; we will send what we can and go to transmit state |
82 | ; we will send what we can and go to transmit state |
83 | 83 | ||
84 | cmp [eax + TCP_SOCKET.t_force], 0 |
84 | cmp [eax + TCP_SOCKET.t_force], 0 |
85 | je .no_force |
85 | je .no_force |
86 | 86 | ||
87 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: forcing data out\n" |
87 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: forcing data out\n" |
88 | 88 | ||
89 | test ecx, ecx |
89 | test ecx, ecx |
90 | jnz .no_zero_window |
90 | jnz .no_zero_window |
91 | 91 | ||
92 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
92 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
93 | jae @f |
93 | jae @f |
94 | and dl, not (TH_FIN) |
94 | and dl, not (TH_FIN) |
95 | @@: |
95 | @@: |
96 | 96 | ||
97 | inc ecx |
97 | inc ecx |
98 | jmp .no_force |
98 | jmp .no_force |
99 | 99 | ||
100 | .no_zero_window: |
100 | .no_zero_window: |
101 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_persist |
101 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_persist |
102 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
102 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
103 | 103 | ||
104 | .no_force: |
104 | .no_force: |
105 | 105 | ||
106 | ;-------------------------------- |
106 | ;-------------------------------- |
107 | ; Calculate how much data to send (106) |
107 | ; Calculate how much data to send (106) |
108 | 108 | ||
109 | mov esi, [eax + STREAM_SOCKET.snd.size] |
109 | mov esi, [eax + STREAM_SOCKET.snd.size] |
110 | cmp esi, ecx |
110 | cmp esi, ecx |
111 | jb @f |
111 | jb @f |
112 | mov esi, ecx |
112 | mov esi, ecx |
113 | @@: |
113 | @@: |
114 | sub esi, ebx |
114 | sub esi, ebx |
115 | 115 | ||
116 | ;------------------------ |
116 | ;------------------------ |
117 | ; check for window shrink (107) |
117 | ; check for window shrink (107) |
118 | 118 | ||
119 | ; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1 |
119 | ; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1 |
120 | ; Otherwise, window shrank after we sent into it. |
120 | ; Otherwise, window shrank after we sent into it. |
121 | 121 | ||
122 | jae .not_persist |
122 | jae .not_persist |
123 | 123 | ||
124 | ; enter persist state |
124 | ; enter persist state |
125 | xor esi, esi |
125 | xor esi, esi |
126 | 126 | ||
127 | ; If window shrank to 0 |
127 | ; If window shrank to 0 |
128 | test ecx, ecx |
128 | test ecx, ecx |
129 | jnz @f |
129 | jnz @f |
130 | 130 | ||
131 | ; cancel pending retransmit |
131 | ; cancel pending retransmit |
132 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
132 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
133 | 133 | ||
134 | ; pull SND_NXT back to (closed) window, We will enter persist state below. |
134 | ; pull SND_NXT back to (closed) window, We will enter persist state below. |
135 | push [eax + TCP_SOCKET.SND_UNA] |
135 | push [eax + TCP_SOCKET.SND_UNA] |
136 | pop [eax + TCP_SOCKET.SND_NXT] |
136 | pop [eax + TCP_SOCKET.SND_NXT] |
137 | @@: |
137 | @@: |
138 | 138 | ||
139 | ; If window didn't close completely, just wait for an ACK |
139 | ; If window didn't close completely, just wait for an ACK |
140 | 140 | ||
141 | .not_persist: |
141 | .not_persist: |
142 | 142 | ||
143 | ;--------------------------- |
143 | ;--------------------------- |
144 | ; Send one segment at a time (124) |
144 | ; Send one segment at a time (124) |
145 | 145 | ||
146 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
146 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
147 | jbe @f |
147 | jbe @f |
148 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
148 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
149 | or [temp_bits], TCP_BIT_SENDALOT |
149 | or [temp_bits], TCP_BIT_SENDALOT |
150 | @@: |
150 | @@: |
151 | 151 | ||
152 | ;-------------------------------------------- |
152 | ;-------------------------------------------- |
153 | ; Turn of FIN flag if send buffer not emptied (128) |
153 | ; Turn of FIN flag if send buffer not emptied (128) |
154 | 154 | ||
155 | mov edi, [eax + TCP_SOCKET.SND_NXT] |
155 | mov edi, [eax + TCP_SOCKET.SND_NXT] |
156 | add edi, esi |
156 | add edi, esi |
157 | sub edi, [eax + TCP_SOCKET.SND_UNA] |
157 | sub edi, [eax + TCP_SOCKET.SND_UNA] |
158 | cmp edi, [eax + STREAM_SOCKET.snd.size] |
158 | cmp edi, [eax + STREAM_SOCKET.snd.size] |
159 | jae @f |
159 | jae @f |
160 | and dl, not (TH_FIN) |
160 | and dl, not (TH_FIN) |
161 | @@: |
161 | @@: |
162 | 162 | ||
163 | ;------------------------------- |
163 | ;------------------------------- |
164 | ; calculate window advertisement (130) |
164 | ; calculate window advertisement (130) |
165 | 165 | ||
166 | mov ecx, SOCKET_MAXDATA |
166 | mov ecx, SOCKET_MAXDATA |
167 | sub ecx, [eax + STREAM_SOCKET.rcv.size] |
167 | sub ecx, [eax + STREAM_SOCKET.rcv.size] |
168 | 168 | ||
169 | ;------------------------------ |
169 | ;------------------------------ |
170 | ; Sender silly window avoidance (131) |
170 | ; Sender silly window avoidance (131) |
171 | 171 | ||
172 | test esi, esi |
172 | test esi, esi |
173 | jz .len_zero |
173 | jz .len_zero |
174 | 174 | ||
175 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
175 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
176 | je .send |
176 | je .send |
177 | 177 | ||
178 | add ebx, esi ; offset + length |
178 | add ebx, esi ; offset + length |
179 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
179 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
180 | jb @f |
180 | jb @f |
181 | 181 | ||
182 | test [eax + TCP_SOCKET.t_flags], TF_NODELAY |
182 | test [eax + TCP_SOCKET.t_flags], TF_NODELAY |
183 | jnz .send |
183 | jnz .send |
184 | 184 | ||
185 | mov ebx, [eax + TCP_SOCKET.SND_MAX] |
185 | mov ebx, [eax + TCP_SOCKET.SND_MAX] |
186 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
186 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
187 | je .send |
187 | je .send |
188 | @@: |
188 | @@: |
189 | 189 | ||
190 | test [eax + TCP_SOCKET.t_force], -1 ;;; |
190 | test [eax + TCP_SOCKET.t_force], -1 ;;; |
191 | jnz .send |
191 | jnz .send |
192 | 192 | ||
193 | mov ebx, [eax + TCP_SOCKET.max_sndwnd] |
193 | mov ebx, [eax + TCP_SOCKET.max_sndwnd] |
194 | shr ebx, 1 |
194 | shr ebx, 1 |
195 | cmp esi, ebx |
195 | cmp esi, ebx |
196 | jae .send |
196 | jae .send |
197 | 197 | ||
198 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
198 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
199 | cmp ebx, [eax + TCP_SOCKET.SND_MAX] |
199 | cmp ebx, [eax + TCP_SOCKET.SND_MAX] |
200 | jb .send |
200 | jb .send |
201 | 201 | ||
202 | .len_zero: |
202 | .len_zero: |
203 | 203 | ||
204 | ;---------------------------------------- |
204 | ;---------------------------------------- |
205 | ; Check if a window update should be sent (154) |
205 | ; Check if a window update should be sent (154) |
206 | 206 | ||
207 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: window=%d\n", ecx |
207 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: window=%d\n", ecx |
208 | 208 | ||
209 | ; Compare available window to amount of window known to peer (as advertised window less next expected input) |
209 | ; Compare available window to amount of window known to peer (as advertised window less next expected input) |
210 | ; If the difference is at least two max size segments, or at least 50% of the maximum possible window, |
210 | ; If the difference is at least two max size segments, or at least 50% of the maximum possible window, |
211 | ; Then we want to send a window update to the peer. |
211 | ; Then we want to send a window update to the peer. |
212 | 212 | ||
213 | test ecx, ecx |
213 | test ecx, ecx |
214 | jz .no_window |
214 | jz .no_window |
215 | 215 | ||
216 | push ecx |
216 | push ecx |
217 | mov cl, [eax + TCP_SOCKET.RCV_SCALE] |
217 | mov cl, [eax + TCP_SOCKET.RCV_SCALE] |
218 | mov ebx, TCP_max_win |
218 | mov ebx, TCP_max_win |
219 | shl ebx, cl |
219 | shl ebx, cl |
220 | pop ecx |
220 | pop ecx |
221 | 221 | ||
222 | cmp ebx, ecx |
222 | cmp ebx, ecx |
223 | jb @f |
223 | jb @f |
224 | mov ebx, ecx |
224 | mov ebx, ecx |
225 | @@: |
225 | @@: |
226 | sub ebx, [eax + TCP_SOCKET.RCV_ADV] |
226 | sub ebx, [eax + TCP_SOCKET.RCV_ADV] |
227 | add ebx, [eax + TCP_SOCKET.RCV_NXT] |
227 | add ebx, [eax + TCP_SOCKET.RCV_NXT] |
228 | 228 | ||
229 | mov edi, [eax + TCP_SOCKET.t_maxseg] |
229 | mov edi, [eax + TCP_SOCKET.t_maxseg] |
230 | shl edi, 1 |
230 | shl edi, 1 |
231 | 231 | ||
232 | cmp ebx, edi |
232 | cmp ebx, edi |
233 | jae .send |
233 | jae .send |
234 | 234 | ||
235 | shl ebx, 1 |
235 | shl ebx, 1 |
236 | ; cmp ebx, [eax + TCP_SOCKET.] ;;; TODO: check with receive buffer high water mark |
236 | ; cmp ebx, [eax + TCP_SOCKET.] ;;; TODO: check with receive buffer high water mark |
237 | ; jae TCP_send |
237 | ; jae TCP_send |
238 | 238 | ||
239 | .no_window: |
239 | .no_window: |
240 | 240 | ||
241 | ;-------------------------- |
241 | ;-------------------------- |
242 | ; Should a segment be sent? (174) |
242 | ; Should a segment be sent? (174) |
243 | 243 | ||
244 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK |
244 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK |
245 | jnz .send |
245 | jnz .send |
246 | 246 | ||
247 | test dl, TH_SYN + TH_RST ; we need to send a SYN or RST |
247 | test dl, TH_SYN + TH_RST ; we need to send a SYN or RST |
248 | jnz .send |
248 | jnz .send |
249 | 249 | ||
250 | mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer |
250 | mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer |
251 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
251 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
252 | ja .send |
252 | ja .send |
253 | 253 | ||
254 | test dl, TH_FIN |
254 | test dl, TH_FIN |
255 | jz .enter_persist ; no reason to send, enter persist state |
255 | jz .enter_persist ; no reason to send, enter persist state |
256 | 256 | ||
257 | ; FIN was set, only send if not already sent, or on retransmit |
257 | ; FIN was set, only send if not already sent, or on retransmit |
258 | 258 | ||
259 | test [eax + TCP_SOCKET.t_flags], TF_SENTFIN |
259 | test [eax + TCP_SOCKET.t_flags], TF_SENTFIN |
260 | jz .send |
260 | jz .send |
261 | 261 | ||
262 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
262 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
263 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
263 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
264 | je .send |
264 | je .send |
265 | 265 | ||
266 | ;-------------------- |
266 | ;-------------------- |
267 | ; Enter persist state (191) |
267 | ; Enter persist state (191) |
268 | 268 | ||
269 | .enter_persist: |
269 | .enter_persist: |
270 | 270 | ||
271 | cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send? |
271 | cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send? |
272 | jne @f |
272 | jne @f |
273 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
273 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_retransmission |
274 | jne @f |
274 | jne @f |
275 | 275 | ||
276 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist ; Persist timer already expired? |
276 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist ; Persist timer already expired? |
277 | jnz @f |
277 | jnz @f |
278 | 278 | ||
279 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: Entering persist state\n" |
279 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: Entering persist state\n" |
280 | 280 | ||
281 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
281 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
282 | call TCP_set_persist |
282 | call tcp_set_persist |
283 | @@: |
283 | @@: |
284 | 284 | ||
285 | ;---------------------------- |
285 | ;---------------------------- |
286 | ; No reason to send a segment (219) |
286 | ; No reason to send a segment (219) |
287 | 287 | ||
288 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: No reason to send a segment\n" |
288 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: No reason to send a segment\n" |
289 | 289 | ||
290 | pusha |
290 | pusha |
291 | lea ecx, [eax + SOCKET.mutex] |
291 | lea ecx, [eax + SOCKET.mutex] |
292 | call mutex_unlock |
292 | call mutex_unlock |
293 | popa |
293 | popa |
294 | 294 | ||
295 | ; Fixme: returnvalue? |
295 | ; Fixme: returnvalue? |
296 | 296 | ||
297 | ret |
297 | ret |
298 | 298 | ||
299 | 299 | ||
300 | ;----------------------------------------------- |
300 | ;----------------------------------------------- |
301 | ; |
301 | ; |
302 | ; Send a segment (222) |
302 | ; Send a segment (222) |
303 | ; |
303 | ; |
304 | ; eax = socket pointer |
304 | ; eax = socket pointer |
305 | ; esi = data len |
305 | ; esi = data len |
306 | ; dl = flags |
306 | ; dl = flags |
307 | ; |
307 | ; |
308 | ;----------------------------------------------- |
308 | ;----------------------------------------------- |
309 | .send: |
309 | .send: |
310 | 310 | ||
311 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: socket=%x length=%u flags=%x\n", eax, esi, dl |
311 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: socket=%x length=%u flags=%x\n", eax, esi, dl |
312 | 312 | ||
313 | push eax ; save socket ptr |
313 | push eax ; save socket ptr |
314 | push esi ; and data length too |
314 | push esi ; and data length too |
315 | mov edi, sizeof.TCP_header ; edi will contain headersize |
315 | mov edi, sizeof.TCP_header ; edi will contain headersize |
316 | 316 | ||
317 | ;------------------------------------ |
317 | ;------------------------------------ |
318 | ; Send options with first SYN segment |
318 | ; Send options with first SYN segment |
319 | 319 | ||
320 | test dl, TH_SYN |
320 | test dl, TH_SYN |
321 | jz .options_done |
321 | jz .options_done |
322 | 322 | ||
323 | push [eax + TCP_SOCKET.ISS] |
323 | push [eax + TCP_SOCKET.ISS] |
324 | pop [eax + TCP_SOCKET.SND_NXT] |
324 | pop [eax + TCP_SOCKET.SND_NXT] |
325 | 325 | ||
326 | test [eax + TCP_SOCKET.t_flags], TF_NOOPT |
326 | test [eax + TCP_SOCKET.t_flags], TF_NOOPT |
327 | jnz .options_done |
327 | jnz .options_done |
328 | 328 | ||
329 | mov ecx, 1460 ;;;; FIXME: use routing blablabla to determine MSS |
329 | mov ecx, 1460 ;;;; FIXME: use routing blablabla to determine MSS |
330 | or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16 |
330 | or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16 |
331 | bswap ecx |
331 | bswap ecx |
332 | push ecx |
332 | push ecx |
333 | add di, 4 |
333 | add di, 4 |
334 | 334 | ||
335 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added maxseg option\n" |
335 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added maxseg option\n" |
336 | 336 | ||
337 | test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE |
337 | test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE |
338 | jz .no_scale |
338 | jz .no_scale |
339 | 339 | ||
340 | test dl, TH_ACK |
340 | test dl, TH_ACK |
341 | jz .scale_opt |
341 | jz .scale_opt |
342 | 342 | ||
343 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE |
343 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE |
344 | jz .no_scale |
344 | jz .no_scale |
345 | 345 | ||
346 | .scale_opt: |
346 | .scale_opt: |
347 | mov cl, [eax + TCP_SOCKET.request_r_scale] |
347 | mov cl, [eax + TCP_SOCKET.request_r_scale] |
348 | mov ch, TCP_OPT_NOP |
348 | mov ch, TCP_OPT_NOP |
349 | pushw cx |
349 | pushw cx |
350 | pushw TCP_OPT_WINDOW + 3 shl 8 |
350 | pushw TCP_OPT_WINDOW + 3 shl 8 |
351 | add di, 4 |
351 | add di, 4 |
352 | 352 | ||
353 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added scale option\n" |
353 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added scale option\n" |
354 | 354 | ||
355 | .no_scale: |
355 | .no_scale: |
356 | .no_syn: |
356 | .no_syn: |
357 | 357 | ||
358 | ;------------------------------------ |
358 | ;------------------------------------ |
359 | ; Make the timestamp option if needed |
359 | ; Make the timestamp option if needed |
360 | 360 | ||
361 | test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP |
361 | test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP |
362 | jz .no_timestamp |
362 | jz .no_timestamp |
363 | 363 | ||
364 | test dl, TH_RST |
364 | test dl, TH_RST |
365 | jnz .no_timestamp |
365 | jnz .no_timestamp |
366 | 366 | ||
367 | test dl, TH_ACK |
367 | test dl, TH_ACK |
368 | jz .timestamp |
368 | jz .timestamp |
369 | 369 | ||
370 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP |
370 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP |
371 | jz .no_timestamp |
371 | jz .no_timestamp |
372 | 372 | ||
373 | .timestamp: |
373 | .timestamp: |
374 | pushd 0 |
374 | pushd 0 |
375 | pushd [timer_ticks] |
375 | pushd [timer_ticks] |
376 | pushd TCP_OPT_NOP + TCP_OPT_NOP shl 8 + TCP_OPT_TIMESTAMP shl 16 + 10 shl 24 |
376 | pushd TCP_OPT_NOP + TCP_OPT_NOP shl 8 + TCP_OPT_TIMESTAMP shl 16 + 10 shl 24 |
377 | add di, 12 |
377 | add di, 12 |
378 | 378 | ||
379 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added timestamp\n" |
379 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: added timestamp\n" |
380 | 380 | ||
381 | .no_timestamp: |
381 | .no_timestamp: |
382 | 382 | ||
383 | ; |
383 | ; |
384 | 384 | ||
385 | .options_done: |
385 | .options_done: |
386 | 386 | ||
387 | ; eax = socket ptr |
387 | ; eax = socket ptr |
388 | ; edx = flags |
388 | ; edx = flags |
389 | ; edi = header size |
389 | ; edi = header size |
390 | ; esi = data len |
390 | ; esi = data len |
391 | 391 | ||
392 | ;--------------------------------------------- |
392 | ;--------------------------------------------- |
393 | ; check if we dont exceed the max segment size (270) |
393 | ; check if we dont exceed the max segment size (270) |
394 | 394 | ||
395 | add esi, edi ; total TCP segment size |
395 | add esi, edi ; total TCP segment size |
396 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
396 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
397 | jbe .no_overflow |
397 | jbe .no_overflow |
398 | 398 | ||
399 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
399 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
400 | or [temp_bits], TCP_BIT_SENDALOT |
400 | or [temp_bits], TCP_BIT_SENDALOT |
401 | .no_overflow: |
401 | .no_overflow: |
402 | 402 | ||
403 | ; Update stats |
403 | ; Update stats |
404 | test esi, esi |
404 | test esi, esi |
405 | jz .zero_data |
405 | jz .zero_data |
406 | 406 | ||
407 | cmp [eax + TCP_SOCKET.t_force], 1 |
407 | cmp [eax + TCP_SOCKET.t_force], 1 |
408 | jne @f |
408 | jne @f |
409 | cmp esi, 1 |
409 | cmp esi, 1 |
410 | jne @f |
410 | jne @f |
411 | inc [TCPS_sndprobe] |
411 | inc [TCPS_sndprobe] |
412 | jmp .eos |
412 | jmp .eos |
413 | @@: |
413 | @@: |
414 | 414 | ||
415 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
415 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
416 | cmp ebx, [eax + TCP_SOCKET.SND_MAX] |
416 | cmp ebx, [eax + TCP_SOCKET.SND_MAX] |
417 | jae @f |
417 | jae @f |
418 | inc [TCPS_sndrexmitpack] |
418 | inc [TCPS_sndrexmitpack] |
419 | add [TCPS_sndrexmitbyte], esi |
419 | add [TCPS_sndrexmitbyte], esi |
420 | jmp .eos |
420 | jmp .eos |
421 | @@: |
421 | @@: |
422 | inc [TCPS_sndpack] |
422 | inc [TCPS_sndpack] |
423 | add [TCPS_sndbyte], esi |
423 | add [TCPS_sndbyte], esi |
424 | jmp .eos |
424 | jmp .eos |
425 | 425 | ||
426 | .zero_data: |
426 | .zero_data: |
427 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW |
427 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW |
428 | jz @f |
428 | jz @f |
429 | inc [TCPS_sndacks] |
429 | inc [TCPS_sndacks] |
430 | jmp .eos |
430 | jmp .eos |
431 | @@: |
431 | @@: |
432 | test dl, TH_SYN + TH_FIN + TH_RST |
432 | test dl, TH_SYN + TH_FIN + TH_RST |
433 | jz @f |
433 | jz @f |
434 | inc [TCPS_sndctrl] |
434 | inc [TCPS_sndctrl] |
435 | jmp .eos |
435 | jmp .eos |
436 | @@: |
436 | @@: |
437 | mov ebx, [eax + TCP_SOCKET.SND_UP] |
437 | mov ebx, [eax + TCP_SOCKET.SND_UP] |
438 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
438 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
439 | jb @f |
439 | jb @f |
440 | inc [TCPS_sndurg] |
440 | inc [TCPS_sndurg] |
441 | jmp .eos |
441 | jmp .eos |
442 | @@: |
442 | @@: |
443 | inc [TCPS_sndwinup] |
443 | inc [TCPS_sndwinup] |
444 | 444 | ||
445 | .eos: |
445 | .eos: |
446 | 446 | ||
447 | ;---------------------------------------------------- |
447 | ;---------------------------------------------------- |
448 | ; Calculate the receive window. |
448 | ; Calculate the receive window. |
449 | ; Dont shrink window, but avoid silly window syndrome |
449 | ; Dont shrink window, but avoid silly window syndrome |
450 | 450 | ||
451 | mov ebx, SOCKET_MAXDATA |
451 | mov ebx, SOCKET_MAXDATA |
452 | sub ebx, [eax + STREAM_SOCKET.rcv.size] |
452 | sub ebx, [eax + STREAM_SOCKET.rcv.size] |
453 | 453 | ||
454 | cmp ebx, SOCKET_MAXDATA/4 |
454 | cmp ebx, SOCKET_MAXDATA/4 |
455 | jae @f |
455 | jae @f |
456 | cmp ebx, [eax + TCP_SOCKET.t_maxseg] |
456 | cmp ebx, [eax + TCP_SOCKET.t_maxseg] |
457 | jae @f |
457 | jae @f |
458 | xor ebx, ebx |
458 | xor ebx, ebx |
459 | @@: |
459 | @@: |
460 | 460 | ||
461 | cmp ebx, TCP_max_win |
461 | cmp ebx, TCP_max_win |
462 | jbe @f |
462 | jbe @f |
463 | mov ebx, TCP_max_win |
463 | mov ebx, TCP_max_win |
464 | @@: |
464 | @@: |
465 | 465 | ||
466 | mov ecx, [eax + TCP_SOCKET.RCV_ADV] |
466 | mov ecx, [eax + TCP_SOCKET.RCV_ADV] |
467 | sub ecx, [eax + TCP_SOCKET.RCV_NXT] |
467 | sub ecx, [eax + TCP_SOCKET.RCV_NXT] |
468 | cmp ebx, ecx |
468 | cmp ebx, ecx |
469 | ja @f |
469 | ja @f |
470 | mov ebx, ecx |
470 | mov ebx, ecx |
471 | @@: |
471 | @@: |
472 | 472 | ||
473 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: window = %u\n", ebx |
473 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: window = %u\n", ebx |
474 | 474 | ||
475 | mov cl, [eax + TCP_SOCKET.RCV_SCALE] |
475 | mov cl, [eax + TCP_SOCKET.RCV_SCALE] |
476 | shr ebx, cl |
476 | shr ebx, cl |
477 | xchg bl, bh |
477 | xchg bl, bh |
478 | 478 | ||
479 | ;----------------------------------------------------------------- |
479 | ;----------------------------------------------------------------- |
480 | ; Start by pushing all TCP header values in reverse order on stack |
480 | ; Start by pushing all TCP header values in reverse order on stack |
481 | ; (essentially, creating the tcp header on the stack!) |
481 | ; (essentially, creating the tcp header on the stack!) |
482 | 482 | ||
483 | pushw 0 ; .UrgentPointer dw ? |
483 | pushw 0 ; .UrgentPointer dw ? |
484 | pushw 0 ; .Checksum dw ? |
484 | pushw 0 ; .Checksum dw ? |
485 | pushw bx ; .Window dw ? |
485 | pushw bx ; .Window dw ? |
486 | shl edi, 2 ; .DataOffset db ? only 4 left-most bits |
486 | shl edi, 2 ; .DataOffset db ? only 4 left-most bits |
487 | shl dx, 8 |
487 | shl dx, 8 |
488 | or dx, di ; .Flags db ? |
488 | or dx, di ; .Flags db ? |
489 | pushw dx |
489 | pushw dx |
490 | shr edi, 2 ; .DataOffset db ? |
490 | shr edi, 2 ; .DataOffset db ? |
491 | 491 | ||
492 | push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ? |
492 | push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ? |
493 | ntohd [esp] |
493 | ntohd [esp] |
494 | 494 | ||
495 | push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ? |
495 | push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ? |
496 | ntohd [esp] |
496 | ntohd [esp] |
497 | 497 | ||
498 | push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ? |
498 | push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ? |
499 | push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ? |
499 | push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ? |
500 | 500 | ||
501 | push edi ; header size |
501 | push edi ; header size |
502 | 502 | ||
503 | ;--------------------- |
503 | ;--------------------- |
504 | ; Create the IP packet |
504 | ; Create the IP packet |
505 | 505 | ||
506 | mov ecx, esi |
506 | mov ecx, esi |
507 | mov ebx, [eax + IP_SOCKET.device] |
507 | mov ebx, [eax + IP_SOCKET.device] |
508 | mov edx, [eax + IP_SOCKET.LocalIP] ; source ip |
508 | mov edx, [eax + IP_SOCKET.LocalIP] ; source ip |
509 | mov edi, [eax + IP_SOCKET.RemoteIP] ; dest ip |
509 | mov edi, [eax + IP_SOCKET.RemoteIP] ; dest ip |
510 | mov al, [eax + IP_SOCKET.ttl] |
510 | mov al, [eax + IP_SOCKET.ttl] |
511 | mov ah, IP_PROTO_TCP |
511 | mov ah, IP_PROTO_TCP |
512 | call IPv4_output |
512 | call ipv4_output |
513 | jz .ip_error |
513 | jz .ip_error |
514 | 514 | ||
515 | ;------------------------------------------ |
515 | ;------------------------------------------ |
516 | ; Move TCP header from stack to TCP segment |
516 | ; Move TCP header from stack to TCP segment |
517 | 517 | ||
518 | push ecx |
518 | push ecx |
519 | mov ecx, [esp + 4] |
519 | mov ecx, [esp + 4] |
520 | lea esi, [esp + 8] |
520 | lea esi, [esp + 8] |
521 | shr ecx, 2 ; count is in bytes, we will work with dwords |
521 | shr ecx, 2 ; count is in bytes, we will work with dwords |
522 | rep movsd |
522 | rep movsd |
523 | pop ecx ; full TCP packet size |
523 | pop ecx ; full TCP packet size |
524 | 524 | ||
525 | pop esi ; headersize |
525 | pop esi ; headersize |
526 | add esp, esi ; remove it from stack |
526 | add esp, esi ; remove it from stack |
527 | 527 | ||
528 | push eax ; packet ptr for send proc |
528 | push eax ; packet ptr for send proc |
529 | 529 | ||
530 | mov edx, edi ; begin of data |
530 | mov edx, edi ; begin of data |
531 | sub edx, esi ; begin of packet (edi = begin of data) |
531 | sub edx, esi ; begin of packet (edi = begin of data) |
532 | push ecx |
532 | push ecx |
533 | sub ecx, esi ; data size |
533 | sub ecx, esi ; data size |
534 | 534 | ||
535 | ;-------------- |
535 | ;-------------- |
536 | ; Copy the data |
536 | ; Copy the data |
537 | 537 | ||
538 | ; eax = ptr to ring struct |
538 | ; eax = ptr to ring struct |
539 | ; ecx = buffer size |
539 | ; ecx = buffer size |
540 | ; edi = ptr to buffer |
540 | ; edi = ptr to buffer |
541 | 541 | ||
542 | mov eax, [esp + 12] ; get socket ptr |
542 | mov eax, [esp + 12] ; get socket ptr |
543 | 543 | ||
544 | push edx |
544 | push edx |
545 | push [eax + TCP_SOCKET.SND_NXT] ; we'll need this for timing the transmission |
545 | push [eax + TCP_SOCKET.SND_NXT] ; we'll need this for timing the transmission |
546 | test ecx, ecx |
546 | test ecx, ecx |
547 | jz .nodata |
547 | jz .nodata |
548 | mov edx, [eax + TCP_SOCKET.SND_NXT] |
548 | mov edx, [eax + TCP_SOCKET.SND_NXT] |
549 | add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number |
549 | add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number |
550 | sub edx, [eax + TCP_SOCKET.SND_UNA] ; offset |
550 | sub edx, [eax + TCP_SOCKET.SND_UNA] ; offset |
551 | add eax, STREAM_SOCKET.snd |
551 | add eax, STREAM_SOCKET.snd |
552 | call SOCKET_ring_read |
552 | call socket_ring_read |
553 | .nodata: |
553 | .nodata: |
554 | pop edi |
554 | pop edi |
555 | pop esi ; begin of data |
555 | pop esi ; begin of data |
556 | pop ecx ; full packet size |
556 | pop ecx ; full packet size |
557 | mov eax, [esp + 8] ; socket ptr |
557 | mov eax, [esp + 8] ; socket ptr |
558 | 558 | ||
559 | ;---------------------------------- |
559 | ;---------------------------------- |
560 | ; initialize retransmit timer (400) |
560 | ; initialize retransmit timer (400) |
561 | 561 | ||
562 | ;TODO: check t_force and persist |
562 | ;TODO: check t_force and persist |
563 | 563 | ||
564 | test [esi + TCP_header.Flags], TH_SYN + TH_FIN ; syn and fin take a sequence number |
564 | test [esi + TCP_header.Flags], TH_SYN + TH_FIN ; syn and fin take a sequence number |
565 | jz @f |
565 | jz @f |
566 | inc [eax + TCP_SOCKET.SND_NXT] |
566 | inc [eax + TCP_SOCKET.SND_NXT] |
567 | test [esi + TCP_header.Flags], TH_FIN |
567 | test [esi + TCP_header.Flags], TH_FIN |
568 | jz @f |
568 | jz @f |
569 | or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag |
569 | or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag |
570 | @@: |
570 | @@: |
571 | 571 | ||
572 | mov edx, [eax + TCP_SOCKET.SND_NXT] |
572 | mov edx, [eax + TCP_SOCKET.SND_NXT] |
573 | cmp edx, [eax + TCP_SOCKET.SND_MAX] ; is this a retransmission? |
573 | cmp edx, [eax + TCP_SOCKET.SND_MAX] ; is this a retransmission? |
574 | jbe @f |
574 | jbe @f |
575 | mov [eax + TCP_SOCKET.SND_MAX], edx ; [eax + TCP_SOCKET.SND_NXT] from before we updated it |
575 | mov [eax + TCP_SOCKET.SND_MAX], edx ; [eax + TCP_SOCKET.SND_NXT] from before we updated it |
576 | 576 | ||
577 | cmp [eax + TCP_SOCKET.t_rtt], 0 ; are we currently timing anything? |
577 | cmp [eax + TCP_SOCKET.t_rtt], 0 ; are we currently timing anything? |
578 | je @f |
578 | je @f |
579 | mov [eax + TCP_SOCKET.t_rtt], 1 ; nope, start transmission timer |
579 | mov [eax + TCP_SOCKET.t_rtt], 1 ; nope, start transmission timer |
580 | mov [eax + TCP_SOCKET.t_rtseq], edi |
580 | mov [eax + TCP_SOCKET.t_rtseq], edi |
581 | inc [TCPS_segstimed] |
581 | inc [TCPS_segstimed] |
582 | @@: |
582 | @@: |
583 | 583 | ||
584 | ; set retransmission timer if not already set, and not doing an ACK or keepalive probe |
584 | ; set retransmission timer if not already set, and not doing an ACK or keepalive probe |
585 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
585 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
586 | jnz .retransmit_set |
586 | jnz .retransmit_set |
587 | 587 | ||
588 | cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx is still [eax + TCP_SOCKET.SND_NXT] |
588 | cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx is still [eax + TCP_SOCKET.SND_NXT] |
589 | je .retransmit_set |
589 | je .retransmit_set |
590 | 590 | ||
591 | mov edx, [eax + TCP_SOCKET.t_rxtcur] |
591 | mov edx, [eax + TCP_SOCKET.t_rxtcur] |
592 | mov [eax + TCP_SOCKET.timer_retransmission], edx |
592 | mov [eax + TCP_SOCKET.timer_retransmission], edx |
593 | or [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
593 | or [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
594 | 594 | ||
595 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
595 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
596 | jz .retransmit_set |
596 | jz .retransmit_set |
597 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_persist |
597 | and [eax + TCP_SOCKET.timer_flags], not timer_flag_persist |
598 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
598 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
599 | 599 | ||
600 | .retransmit_set: |
600 | .retransmit_set: |
601 | 601 | ||
602 | ;-------------------- |
602 | ;-------------------- |
603 | ; Create the checksum |
603 | ; Create the checksum |
604 | 604 | ||
605 | xor dx, dx |
605 | xor dx, dx |
606 | test [ebx + NET_DEVICE.hwacc], NET_HWACC_TCP_IPv4_OUT |
606 | test [ebx + NET_DEVICE.hwacc], NET_HWACC_TCP_IPv4_OUT |
607 | jnz .checksum_ok |
607 | jnz .checksum_ok |
608 | 608 | ||
609 | TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP) |
609 | tcp_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP) |
610 | 610 | ||
611 | .checksum_ok: |
611 | .checksum_ok: |
612 | mov [esi + TCP_header.Checksum], dx |
612 | mov [esi + TCP_header.Checksum], dx |
613 | 613 | ||
614 | ;---------------- |
614 | ;---------------- |
615 | ; Send the packet |
615 | ; Send the packet |
616 | 616 | ||
617 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: Sending with device %x\n", ebx |
617 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: Sending with device %x\n", ebx |
618 | call [ebx + NET_DEVICE.transmit] |
618 | call [ebx + NET_DEVICE.transmit] |
619 | jnz .send_error |
619 | jnz .send_error |
620 | 620 | ||
621 | ;--------------- |
621 | ;--------------- |
622 | ; Ok, data sent! |
622 | ; Ok, data sent! |
623 | 623 | ||
624 | pop ecx |
624 | pop ecx |
625 | pop eax |
625 | pop eax |
626 | 626 | ||
627 | call NET_ptr_to_num4 |
627 | call net_ptr_to_num4 |
628 | inc [TCP_segments_tx + edi] |
628 | inc [TCP_segments_tx + edi] |
629 | inc [TCPS_sndtotal] |
629 | inc [TCPS_sndtotal] |
630 | 630 | ||
631 | ; update advertised receive window |
631 | ; update advertised receive window |
632 | test ecx, ecx |
632 | test ecx, ecx |
633 | jz @f |
633 | jz @f |
634 | add ecx, [eax + TCP_SOCKET.RCV_NXT] |
634 | add ecx, [eax + TCP_SOCKET.RCV_NXT] |
635 | cmp ecx, [eax + TCP_SOCKET.RCV_ADV] |
635 | cmp ecx, [eax + TCP_SOCKET.RCV_ADV] |
636 | jbe @f |
636 | jbe @f |
637 | mov [eax + TCP_SOCKET.RCV_ADV], ecx |
637 | mov [eax + TCP_SOCKET.RCV_ADV], ecx |
638 | @@: |
638 | @@: |
639 | 639 | ||
640 | ; update last ack sent |
640 | ; update last ack sent |
641 | push [eax + TCP_SOCKET.RCV_NXT] |
641 | push [eax + TCP_SOCKET.RCV_NXT] |
642 | pop [eax + TCP_SOCKET.last_ack_sent] |
642 | pop [eax + TCP_SOCKET.last_ack_sent] |
643 | 643 | ||
644 | ; clear the ACK flags |
644 | ; clear the ACK flags |
645 | and [eax + TCP_SOCKET.t_flags], not (TF_ACKNOW + TF_DELACK) |
645 | and [eax + TCP_SOCKET.t_flags], not (TF_ACKNOW + TF_DELACK) |
646 | 646 | ||
647 | ;-------------- |
647 | ;-------------- |
648 | ; unlock socket |
648 | ; unlock socket |
649 | 649 | ||
650 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: unlocking socket 0x%x\n", eax |
650 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: unlocking socket 0x%x\n", eax |
651 | 651 | ||
652 | push eax |
652 | push eax |
653 | lea ecx, [eax + SOCKET.mutex] |
653 | lea ecx, [eax + SOCKET.mutex] |
654 | call mutex_unlock |
654 | call mutex_unlock |
655 | pop eax |
655 | pop eax |
656 | 656 | ||
657 | ;----------------------------- |
657 | ;----------------------------- |
658 | ; Check if we need more output |
658 | ; Check if we need more output |
659 | 659 | ||
660 | test [temp_bits], TCP_BIT_SENDALOT |
660 | test [temp_bits], TCP_BIT_SENDALOT |
661 | jnz TCP_output.again |
661 | jnz tcp_output.again |
662 | 662 | ||
663 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: success!\n" |
663 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: success!\n" |
664 | 664 | ||
665 | xor eax, eax |
665 | xor eax, eax |
666 | ret |
666 | ret |
667 | 667 | ||
668 | 668 | ||
669 | .ip_error: |
669 | .ip_error: |
670 | pop ecx |
670 | pop ecx |
671 | add esp, ecx |
671 | add esp, ecx |
672 | add esp, 4 |
672 | add esp, 4 |
673 | pop eax |
673 | pop eax |
674 | 674 | ||
675 | mov [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min |
675 | mov [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min |
676 | or [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
676 | or [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
677 | 677 | ||
678 | lea ecx, [eax + SOCKET.mutex] |
678 | lea ecx, [eax + SOCKET.mutex] |
679 | call mutex_unlock |
679 | call mutex_unlock |
680 | 680 | ||
681 | DEBUGF DEBUG_NETWORK_ERROR, "TCP_send: IP error\n" |
681 | DEBUGF DEBUG_NETWORK_ERROR, "TCP_send: IP error\n" |
682 | 682 | ||
683 | or eax, -1 |
683 | or eax, -1 |
684 | ret |
684 | ret |
685 | 685 | ||
686 | 686 | ||
687 | .send_error: |
687 | .send_error: |
688 | add esp, 4 |
688 | add esp, 4 |
689 | pop eax |
689 | pop eax |
690 | 690 | ||
691 | lea ecx, [eax + SOCKET.mutex] |
691 | lea ecx, [eax + SOCKET.mutex] |
692 | call mutex_unlock |
692 | call mutex_unlock |
693 | 693 | ||
694 | DEBUGF DEBUG_NETWORK_ERROR, "TCP_send: sending failed\n" |
694 | DEBUGF DEBUG_NETWORK_ERROR, "TCP_send: sending failed\n" |
695 | 695 | ||
696 | or eax, -2 |
696 | or eax, -2 |
697 | ret |
697 | ret |
698 | 698 | ||
699 | 699 | ||
700 | endp |
700 | endp |