Subversion Repositories Kolibri OS

Rev

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