Rev 2402 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1763 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2362 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
1763 | hidnplayr | 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: 2555 $ |
||
18 | |||
1733 | hidnplayr | 19 | ;----------------------------------------------------------------- |
20 | ; |
||
21 | ; TCP_output |
||
22 | ; |
||
23 | ; IN: eax = socket pointer |
||
24 | ; |
||
25 | ; OUT: / |
||
26 | ; |
||
27 | ;----------------------------------------------------------------- |
||
28 | align 4 |
||
29 | TCP_output: |
||
30 | |||
2402 | hidnplayr | 31 | DEBUGF 1,"TCP_output, socket: %x\n", eax |
1733 | hidnplayr | 32 | |
33 | |||
34 | ; We'll detect the length of the data to be transmitted, and flags to be used |
||
35 | ; If there is some data, or any critical controls to send (SYN / RST), then transmit |
||
36 | ; Otherwise, investigate further |
||
37 | |||
2402 | hidnplayr | 38 | mov ebx, [eax + TCP_SOCKET.SND_MAX] |
39 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
||
40 | jne .not_idle |
||
1733 | hidnplayr | 41 | |
2402 | hidnplayr | 42 | mov ebx, [eax + TCP_SOCKET.t_idle] |
43 | cmp ebx, [eax + TCP_SOCKET.t_rxtcur] |
||
44 | jbe .not_idle |
||
1733 | hidnplayr | 45 | |
46 | ; We have been idle for a while and no ACKS are expected to clock out any data we send.. |
||
47 | ; Slow start to get ack "clock" running again. |
||
48 | |||
2402 | hidnplayr | 49 | mov ebx, [eax + TCP_SOCKET.t_maxseg] |
50 | mov [eax + TCP_SOCKET.SND_CWND], ebx |
||
1733 | hidnplayr | 51 | |
52 | .not_idle: |
||
53 | .again: |
||
2402 | hidnplayr | 54 | mov ebx, [eax + TCP_SOCKET.SND_NXT] ; calculate offset (71) |
55 | sub ebx, [eax + TCP_SOCKET.SND_UNA] ; |
||
1733 | hidnplayr | 56 | |
2402 | hidnplayr | 57 | mov ecx, [eax + TCP_SOCKET.SND_WND] ; determine window |
58 | cmp ecx, [eax + TCP_SOCKET.SND_CWND] ; |
||
59 | jb @f ; |
||
60 | mov ecx, [eax + TCP_SOCKET.SND_CWND] ; |
||
61 | @@: ; |
||
1733 | hidnplayr | 62 | |
2402 | hidnplayr | 63 | call TCP_outflags ; flags in dl |
1733 | hidnplayr | 64 | |
1761 | hidnplayr | 65 | ;------------------------ |
66 | ; data being forced out ? |
||
67 | |||
1733 | hidnplayr | 68 | ; If in persist timeout with window of 0, send 1 byte. |
69 | ; Otherwise, if window is small but nonzero, and timer expired, |
||
70 | ; we will send what we can and go to transmit state |
||
71 | |||
2402 | hidnplayr | 72 | test [eax + TCP_SOCKET.t_force], -1 |
73 | jz .no_force |
||
1733 | hidnplayr | 74 | |
2402 | hidnplayr | 75 | test ecx, ecx |
76 | jnz .no_zero_window |
||
1733 | hidnplayr | 77 | |
2402 | hidnplayr | 78 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
79 | jae @f |
||
1733 | hidnplayr | 80 | |
2402 | hidnplayr | 81 | and dl, not (TH_FIN) ; clear the FIN flag ??? how can it be set before? |
1733 | hidnplayr | 82 | |
83 | @@: |
||
2402 | hidnplayr | 84 | inc ecx |
85 | jmp .no_force |
||
1733 | hidnplayr | 86 | |
87 | .no_zero_window: |
||
2402 | hidnplayr | 88 | mov [eax + TCP_SOCKET.timer_persist], 0 |
89 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
||
1733 | hidnplayr | 90 | |
1761 | hidnplayr | 91 | .no_force: |
1733 | hidnplayr | 92 | |
1761 | hidnplayr | 93 | ;-------------------------------- |
94 | ; Calculate how much data to send (106) |
||
1733 | hidnplayr | 95 | |
2402 | hidnplayr | 96 | mov esi, [eax + STREAM_SOCKET.snd.size] |
97 | cmp esi, ecx |
||
98 | jb @f |
||
99 | mov esi, ecx |
||
1733 | hidnplayr | 100 | @@: |
2402 | hidnplayr | 101 | sub esi, ebx |
1733 | hidnplayr | 102 | |
1761 | hidnplayr | 103 | ;------------------------ |
104 | ; check for window shrink (107) |
||
1733 | hidnplayr | 105 | |
1761 | hidnplayr | 106 | ; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1 |
1733 | hidnplayr | 107 | ; Otherwise, window shrank after we sent into it. |
108 | |||
2402 | hidnplayr | 109 | jns .not_negative |
1761 | hidnplayr | 110 | |
111 | ; enter persist state |
||
2402 | hidnplayr | 112 | xor esi, esi |
1733 | hidnplayr | 113 | |
1761 | hidnplayr | 114 | ; If window shrank to 0 |
2402 | hidnplayr | 115 | test ecx, ecx |
116 | jnz @f |
||
1733 | hidnplayr | 117 | |
1761 | hidnplayr | 118 | ; cancel pending retransmit |
2402 | hidnplayr | 119 | mov [eax + TCP_SOCKET.timer_retransmission], 0 |
1733 | hidnplayr | 120 | |
1761 | hidnplayr | 121 | ; pull SND_NXT back to (closed) window, We will enter persist state below. |
2402 | hidnplayr | 122 | push [eax + TCP_SOCKET.SND_UNA] |
123 | pop [eax + TCP_SOCKET.SND_NXT] |
||
1761 | hidnplayr | 124 | |
1733 | hidnplayr | 125 | @@: |
126 | |||
1761 | hidnplayr | 127 | ; If window didn't close completely, just wait for an ACK |
1733 | hidnplayr | 128 | |
1762 | hidnplayr | 129 | .not_negative: |
1733 | hidnplayr | 130 | |
1761 | hidnplayr | 131 | ;--------------------------- |
132 | ; Send one segment at a time (124) |
||
133 | |||
2402 | hidnplayr | 134 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
135 | jbe @f |
||
1733 | hidnplayr | 136 | |
2402 | hidnplayr | 137 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
1733 | hidnplayr | 138 | |
1761 | hidnplayr | 139 | ;;; sendalot = 1 |
140 | |||
1733 | hidnplayr | 141 | @@: |
142 | |||
1761 | hidnplayr | 143 | ;-------------------------------------------- |
144 | ; Turn of FIN flag if send buffer not emptied (128) |
||
1733 | hidnplayr | 145 | |
2402 | hidnplayr | 146 | mov edi, [eax + TCP_SOCKET.SND_NXT] |
147 | add edi, esi |
||
148 | sub edi, [eax + TCP_SOCKET.SND_UNA] |
||
149 | sub edi, [eax + STREAM_SOCKET.snd.size] |
||
150 | jns @f |
||
1761 | hidnplayr | 151 | |
2402 | hidnplayr | 152 | and dl, not (TH_FIN) |
1733 | hidnplayr | 153 | |
154 | @@: |
||
155 | |||
1761 | hidnplayr | 156 | ;------------------------------- |
157 | ; calculate window advertisement (130) |
||
1733 | hidnplayr | 158 | |
2402 | hidnplayr | 159 | mov ecx, SOCKET_MAXDATA |
160 | sub ecx, [eax + STREAM_SOCKET.rcv.size] |
||
1733 | hidnplayr | 161 | |
162 | ;------------------------------ |
||
1761 | hidnplayr | 163 | ; Sender silly window avoidance (131) |
1733 | hidnplayr | 164 | |
2402 | hidnplayr | 165 | test esi, esi |
166 | jz .len_zero |
||
1761 | hidnplayr | 167 | |
2402 | hidnplayr | 168 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
169 | je .send |
||
1733 | hidnplayr | 170 | |
2402 | hidnplayr | 171 | test [eax + TCP_SOCKET.t_flags], TF_NODELAY |
172 | jnz @f |
||
173 | ; TODO: if not 'idle', skip to next codeblock |
||
2362 | hidnplayr | 174 | @@: |
2402 | hidnplayr | 175 | add ebx, esi |
176 | cmp ebx, [eax + STREAM_SOCKET.snd.size] |
||
177 | jae .send |
||
1733 | hidnplayr | 178 | |
2402 | hidnplayr | 179 | test [eax + TCP_SOCKET.t_force], -1 ;;; |
180 | jnz .send |
||
1733 | hidnplayr | 181 | |
2402 | hidnplayr | 182 | mov ebx, [eax + TCP_SOCKET.max_sndwnd] |
183 | shr ebx, 1 |
||
184 | cmp esi, ebx |
||
185 | jae .send |
||
1733 | hidnplayr | 186 | |
2402 | hidnplayr | 187 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
188 | cmp ebx, [eax + TCP_SOCKET.SND_MAX] |
||
189 | jb .send |
||
1733 | hidnplayr | 190 | |
1761 | hidnplayr | 191 | .len_zero: |
192 | |||
1733 | hidnplayr | 193 | ;---------------------------------------- |
1761 | hidnplayr | 194 | ; Check if a window update should be sent (154) |
1733 | hidnplayr | 195 | |
2402 | hidnplayr | 196 | test ecx, ecx |
197 | jz .no_window |
||
1733 | hidnplayr | 198 | |
2402 | hidnplayr | 199 | push ecx |
200 | mov cl, [eax + TCP_SOCKET.RCV_SCALE] |
||
201 | inc cl ; we want it *2 |
||
202 | mov ebx, TCP_max_win |
||
203 | shl ebx, cl |
||
204 | pop ecx |
||
205 | cmp ebx, ecx |
||
206 | cmovb ebx, ecx |
||
1733 | hidnplayr | 207 | |
2402 | hidnplayr | 208 | ; now ebx is TWICE the amount we can increase the window |
209 | ; (with TCP_max_win shl rcv_scale as the maximum) |
||
2362 | hidnplayr | 210 | |
2402 | hidnplayr | 211 | cmp ebx, [eax + TCP_SOCKET.t_maxseg] |
212 | jae .send |
||
2362 | hidnplayr | 213 | |
214 | ;;; cmp ebx, [eax + ] ;;; TODO: check receive buffer high water mark |
||
215 | ;;; jae .send |
||
216 | |||
1733 | hidnplayr | 217 | .no_window: |
218 | |||
219 | ;-------------------------- |
||
1761 | hidnplayr | 220 | ; Should a segment be sent? (174) |
1733 | hidnplayr | 221 | |
2402 | hidnplayr | 222 | test [eax + TCP_SOCKET.t_flags], TF_ACKNOW ; we need to ACK |
223 | jnz .send |
||
1733 | hidnplayr | 224 | |
2402 | hidnplayr | 225 | test dl, TH_SYN + TH_RST ; we need to send a SYN or RST |
226 | jnz .send |
||
1733 | hidnplayr | 227 | |
2402 | hidnplayr | 228 | mov ebx, [eax + TCP_SOCKET.SND_UP] ; when urgent pointer is beyond start of send bufer |
229 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
||
230 | ja .send |
||
1733 | hidnplayr | 231 | |
2402 | hidnplayr | 232 | test dl, TH_FIN |
233 | jz .enter_persist ; no reason to send, enter persist state |
||
1733 | hidnplayr | 234 | |
1761 | hidnplayr | 235 | ; FIN was set, only send if not already sent, or on retransmit |
236 | |||
2402 | hidnplayr | 237 | test [eax + TCP_SOCKET.t_flags], TF_SENTFIN |
238 | jnz .send |
||
1733 | hidnplayr | 239 | |
2402 | hidnplayr | 240 | mov ebx, [eax + TCP_SOCKET.SND_NXT] |
241 | cmp ebx, [eax + TCP_SOCKET.SND_UNA] |
||
242 | je .send |
||
1733 | hidnplayr | 243 | |
244 | ;-------------------- |
||
1761 | hidnplayr | 245 | ; Enter persist state (191) |
1733 | hidnplayr | 246 | |
247 | .enter_persist: |
||
248 | |||
2402 | hidnplayr | 249 | cmp [eax + STREAM_SOCKET.snd.size], 0 ; Data ready to send? |
250 | jne @f |
||
251 | cmp [eax + TCP_SOCKET.timer_retransmission], 0 |
||
252 | jne @f |
||
253 | cmp [eax + TCP_SOCKET.timer_persist], 0 ; Persist timer already expired? |
||
254 | jne @f |
||
2362 | hidnplayr | 255 | |
2402 | hidnplayr | 256 | DEBUGF 1,"Entering persist state\n" |
1733 | hidnplayr | 257 | |
2402 | hidnplayr | 258 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
259 | TCP_set_persist eax |
||
2362 | hidnplayr | 260 | @@: |
1733 | hidnplayr | 261 | |
1761 | hidnplayr | 262 | ;---------------------------- |
263 | ; No reason to send a segment (219) |
||
264 | |||
2402 | hidnplayr | 265 | DEBUGF 1,"No reason to send a segment\n" |
1733 | hidnplayr | 266 | |
2402 | hidnplayr | 267 | pusha |
268 | lea ecx, [eax + SOCKET.mutex] |
||
269 | call mutex_unlock |
||
270 | popa |
||
1733 | hidnplayr | 271 | |
2402 | hidnplayr | 272 | ret |
1733 | hidnplayr | 273 | |
274 | |||
1761 | hidnplayr | 275 | |
276 | |||
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
1733 | hidnplayr | 282 | ;----------------------------------------------- |
283 | ; |
||
1761 | hidnplayr | 284 | ; Send a segment (222) |
1733 | hidnplayr | 285 | ; |
286 | ; eax = socket pointer |
||
1761 | hidnplayr | 287 | ; esi = data len |
1733 | hidnplayr | 288 | ; dl = flags |
289 | ; |
||
290 | ;----------------------------------------------- |
||
291 | |||
292 | .send: |
||
293 | |||
2402 | hidnplayr | 294 | DEBUGF 1,"Preparing to send a segment\n" |
1733 | hidnplayr | 295 | |
2402 | hidnplayr | 296 | mov edi, sizeof.TCP_header ; edi will contain headersize |
1733 | hidnplayr | 297 | |
2402 | hidnplayr | 298 | sub esp, 8 ; create some space on stack |
299 | push eax ; save socket pointer |
||
1733 | hidnplayr | 300 | |
301 | ;------------------------------------ |
||
302 | ; Send options with first SYN segment |
||
303 | |||
2402 | hidnplayr | 304 | test dl, TH_SYN |
305 | jz .options_done |
||
1733 | hidnplayr | 306 | |
2402 | hidnplayr | 307 | push [eax + TCP_SOCKET.ISS] |
308 | pop [eax + TCP_SOCKET.SND_NXT] |
||
1733 | hidnplayr | 309 | |
2402 | hidnplayr | 310 | test [eax + TCP_SOCKET.t_flags], TF_NOOPT |
311 | jnz .options_done |
||
1733 | hidnplayr | 312 | |
2402 | hidnplayr | 313 | mov ecx, 1460 ;;;; FIXME |
314 | or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16 |
||
315 | bswap ecx |
||
316 | push ecx |
||
317 | add di, 4 |
||
1733 | hidnplayr | 318 | |
2402 | hidnplayr | 319 | test [eax + TCP_SOCKET.t_flags], TF_REQ_SCALE |
320 | jz .no_syn |
||
1733 | hidnplayr | 321 | |
2402 | hidnplayr | 322 | test dl, TH_ACK |
323 | jnz .scale_opt |
||
1733 | hidnplayr | 324 | |
2402 | hidnplayr | 325 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_SCALE |
326 | jz .no_syn |
||
1733 | hidnplayr | 327 | |
328 | .scale_opt: |
||
2402 | hidnplayr | 329 | movzx ecx, byte [eax + TCP_SOCKET.request_r_scale] |
330 | or ecx, TCP_OPT_WINDOW shl 24 + 4 shl 16 + TCP_OPT_NOP shl 8 |
||
331 | bswap ecx |
||
332 | pushd ecx |
||
333 | add di, 4 |
||
1733 | hidnplayr | 334 | |
335 | .no_syn: |
||
336 | |||
337 | ;------------------------------------ |
||
338 | ; Make the timestamp option if needed |
||
339 | |||
2402 | hidnplayr | 340 | test [eax + TCP_SOCKET.t_flags], TF_REQ_TSTMP |
341 | jz .no_timestamp |
||
1733 | hidnplayr | 342 | |
2402 | hidnplayr | 343 | test dl, TH_RST |
344 | jnz .no_timestamp |
||
1733 | hidnplayr | 345 | |
2402 | hidnplayr | 346 | test dl, TH_ACK |
347 | jz .timestamp |
||
1733 | hidnplayr | 348 | |
2402 | hidnplayr | 349 | test [eax + TCP_SOCKET.t_flags], TF_RCVD_TSTMP |
350 | jz .no_timestamp |
||
1733 | hidnplayr | 351 | |
352 | .timestamp: |
||
2402 | hidnplayr | 353 | mov ebx, [timer_ticks] |
354 | bswap ebx |
||
355 | push ebx |
||
356 | pushw 0 |
||
357 | pushd TCP_OPT_TIMESTAMP + 10 shl 8 + TCP_OPT_NOP shl 16 + TCP_OPT_NOP shl 24 |
||
358 | add di, 10 |
||
1733 | hidnplayr | 359 | |
360 | .no_timestamp: |
||
361 | |||
2402 | hidnplayr | 362 | ; |
1733 | hidnplayr | 363 | |
364 | |||
1761 | hidnplayr | 365 | |
366 | |||
367 | |||
368 | |||
369 | |||
370 | |||
371 | .options_done: |
||
372 | |||
373 | ; eax = socket ptr |
||
374 | ; edx = flags |
||
375 | ; edi = header size |
||
376 | ; esi = data len |
||
377 | |||
378 | ;--------------------------------------------- |
||
379 | ; check if we dont exceed the max segment size (270) |
||
380 | |||
2402 | hidnplayr | 381 | add esi, edi ; total TCP segment size |
382 | cmp esi, [eax + TCP_SOCKET.t_maxseg] |
||
383 | jbe .no_overflow |
||
1761 | hidnplayr | 384 | |
2402 | hidnplayr | 385 | mov esi, [eax + TCP_SOCKET.t_maxseg] |
1761 | hidnplayr | 386 | |
387 | ;;; sendalot = 1 |
||
388 | |||
389 | .no_overflow: |
||
390 | |||
391 | ;----------------------------------------------------------------- |
||
1733 | hidnplayr | 392 | ; Start by pushing all TCP header values in reverse order on stack |
1761 | hidnplayr | 393 | ; (essentially, creating the tcp header on the stack!) |
1733 | hidnplayr | 394 | |
2402 | hidnplayr | 395 | pushw 0 ; .UrgentPointer dw ? |
396 | pushw 0 ; .Checksum dw ? |
||
397 | pushw 0x00a0 ; .Window dw ? ;;;;;;; FIXME |
||
398 | shl edi, 2 ; .DataOffset db ? only 4 left-most bits |
||
399 | shl dx, 8 |
||
400 | or dx, di ; .Flags db ? |
||
401 | pushw dx |
||
402 | shr edi, 2 ; .DataOffset db ? ;;;; |
||
1733 | hidnplayr | 403 | |
2402 | hidnplayr | 404 | push [eax + TCP_SOCKET.RCV_NXT] ; .AckNumber dd ? |
405 | ntohd [esp] |
||
1733 | hidnplayr | 406 | |
2402 | hidnplayr | 407 | push [eax + TCP_SOCKET.SND_NXT] ; .SequenceNumber dd ? |
408 | ntohd [esp] |
||
1733 | hidnplayr | 409 | |
2402 | hidnplayr | 410 | push [eax + TCP_SOCKET.RemotePort] ; .DestinationPort dw ? |
411 | ntohw [esp] |
||
1733 | hidnplayr | 412 | |
2402 | hidnplayr | 413 | push [eax + TCP_SOCKET.LocalPort] ; .SourcePort dw ? |
414 | ntohw [esp] |
||
1733 | hidnplayr | 415 | |
2402 | hidnplayr | 416 | push edi ; header size |
1733 | hidnplayr | 417 | |
1761 | hidnplayr | 418 | ;--------------------- |
1733 | hidnplayr | 419 | ; Create the IP packet |
1761 | hidnplayr | 420 | |
2402 | hidnplayr | 421 | mov ecx, esi |
1761 | hidnplayr | 422 | |
2402 | hidnplayr | 423 | mov ebx, [eax + IP_SOCKET.LocalIP] ; source ip |
424 | mov eax, [eax + IP_SOCKET.RemoteIP] ; dest ip |
||
425 | mov di, IP_PROTO_TCP shl 8 + 128 |
||
426 | call IPv4_output |
||
2555 | hidnplayr | 427 | jz .ip_error |
1733 | hidnplayr | 428 | |
429 | ;----------------------------------------- |
||
430 | ; Move TCP header from stack to TCP packet |
||
431 | |||
2402 | hidnplayr | 432 | push ecx |
433 | mov ecx, [esp+4] |
||
434 | lea esi, [esp+4+4] |
||
435 | shr ecx, 2 |
||
436 | rep movsd |
||
437 | pop ecx ; full TCP packet size |
||
1733 | hidnplayr | 438 | |
2402 | hidnplayr | 439 | pop esi ; headersize |
440 | add esp, esi |
||
1733 | hidnplayr | 441 | |
2402 | hidnplayr | 442 | mov [esp + 4], eax ; packet ptr |
443 | mov [esp + 4+4], edx ; packet size |
||
1733 | hidnplayr | 444 | |
2402 | hidnplayr | 445 | mov edx, edi ; begin of data |
446 | sub edx, esi ; begin of packet (edi = begin of data) |
||
447 | push ecx |
||
448 | sub ecx, esi ; data size |
||
1733 | hidnplayr | 449 | |
450 | ;-------------- |
||
451 | ; Copy the data |
||
452 | |||
453 | ; eax = ptr to ring struct |
||
454 | ; ecx = buffer size |
||
455 | ; edi = ptr to buffer |
||
456 | |||
2402 | hidnplayr | 457 | mov eax, [esp+4] ; get socket ptr |
1761 | hidnplayr | 458 | |
2402 | hidnplayr | 459 | add [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number |
1761 | hidnplayr | 460 | |
2402 | hidnplayr | 461 | add eax, STREAM_SOCKET.snd |
462 | push edx |
||
463 | call SOCKET_ring_read |
||
464 | pop esi ; begin of data |
||
465 | pop ecx ; full packet size |
||
466 | pop eax ; socket ptr |
||
1733 | hidnplayr | 467 | |
1761 | hidnplayr | 468 | ;---------------------------------- |
469 | ; update sequence number and timers (400) |
||
470 | |||
2402 | hidnplayr | 471 | test [esi + TCP_header.Flags], TH_SYN + TH_FIN |
472 | jz @f |
||
473 | inc [eax + TCP_SOCKET.SND_NXT] ; syn and fin take a sequence number |
||
474 | test [esi + TCP_header.Flags], TH_FIN |
||
475 | jz @f |
||
476 | or [eax + TCP_SOCKET.t_flags], TF_SENTFIN ; if we sent a fin, set the sentfin flag |
||
1733 | hidnplayr | 477 | @@: |
478 | |||
2402 | hidnplayr | 479 | mov edx, [eax + TCP_SOCKET.SND_NXT] |
480 | cmp edx, [eax + TCP_SOCKET.SND_MAX] |
||
481 | jbe @f |
||
482 | mov [eax + TCP_SOCKET.SND_MAX], edx |
||
1733 | hidnplayr | 483 | |
2402 | hidnplayr | 484 | ;;;; TODO: time transmission (420) |
1761 | hidnplayr | 485 | |
1733 | hidnplayr | 486 | @@: |
487 | |||
1761 | hidnplayr | 488 | ; set retransmission timer if not already set, and not doing an ACK or keepalive probe |
1733 | hidnplayr | 489 | |
2402 | hidnplayr | 490 | cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;; FIXME |
491 | jb .retransmit_set |
||
1761 | hidnplayr | 492 | |
2402 | hidnplayr | 493 | cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT] |
494 | je .retransmit_set |
||
1761 | hidnplayr | 495 | |
2402 | hidnplayr | 496 | mov edx, [eax + TCP_SOCKET.t_rxtcur] |
497 | mov [eax + TCP_SOCKET.timer_retransmission], dx |
||
1761 | hidnplayr | 498 | |
2402 | hidnplayr | 499 | cmp [eax + TCP_SOCKET.timer_persist], 0 |
500 | jne @f |
||
501 | mov [eax + TCP_SOCKET.timer_persist], 0 |
||
502 | mov [eax + TCP_SOCKET.t_rxtshift], 0 |
||
2362 | hidnplayr | 503 | @@: |
1761 | hidnplayr | 504 | |
505 | .retransmit_set: |
||
506 | |||
1733 | hidnplayr | 507 | ;-------------------- |
508 | ; Create the checksum |
||
509 | |||
2402 | hidnplayr | 510 | DEBUGF 1,"checksum: ptr=%x size=%u\n", esi, ecx |
1733 | hidnplayr | 511 | |
2402 | hidnplayr | 512 | TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP) |
513 | mov [esi + TCP_header.Checksum], dx |
||
1733 | hidnplayr | 514 | |
1761 | hidnplayr | 515 | ; unlock socket |
516 | |||
2402 | hidnplayr | 517 | pusha |
518 | lea ecx, [eax + SOCKET.mutex] |
||
519 | call mutex_unlock |
||
520 | popa |
||
1761 | hidnplayr | 521 | |
1733 | hidnplayr | 522 | ;---------------- |
523 | ; Send the packet |
||
524 | |||
2402 | hidnplayr | 525 | DEBUGF 1,"Sending TCP Packet to device %x\n", ebx |
526 | call [ebx + NET_DEVICE.transmit] |
||
527 | ret |
||
1733 | hidnplayr | 528 | |
529 | |||
2555 | hidnplayr | 530 | .ip_error: |
2402 | hidnplayr | 531 | pop ecx |
532 | add esp, ecx |
||
533 | pop eax |
||
534 | add esp, 8 |
||
1733 | hidnplayr | 535 | |
2402 | hidnplayr | 536 | pusha |
537 | lea ecx, [eax + SOCKET.mutex] |
||
538 | call mutex_unlock |
||
539 | popa |
||
1733 | hidnplayr | 540 | |
2555 | hidnplayr | 541 | DEBUGF 1,"TCP_output: IP error\n" |
2402 | hidnplayr | 542 | ret |
543 |