Subversion Repositories Kolibri OS

Rev

Rev 2888 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2888 Rev 2890
Line 12... Line 12...
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
$Revision: 2888 $
17
$Revision: 2890 $
18
 
18
 
19
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
20
;
20
;
Line 24... Line 24...
24
;
24
;
25
; OUT: /
25
; OUT: /
26
;
26
;
27
;-----------------------------------------------------------------
27
;-----------------------------------------------------------------
28
align 4
28
align 4
29
TCP_sendalot:
-
 
30
        DEBUGF 1,"TCP_sendalot\n"
-
 
31
        pop     eax
-
 
32
;align 4
-
 
33
TCP_output:
29
TCP_output:
Line 34... Line 30...
34
 
30
 
Line 35... Line -...
35
        DEBUGF 1,"TCP_output, socket: %x\n", eax
-
 
36
 
31
        DEBUGF 1,"TCP_output, socket: %x\n", eax
37
 
32
 
38
; We'll detect the length of the data to be transmitted, and flags to be used
33
; We'll detect the length of the data to be transmitted, and flags to be used
Line 39... Line 34...
39
; If there is some data, or any critical controls to send (SYN / RST), then transmit
34
; If there is some data, or any critical controls to send (SYN / RST), then transmit
Line 53... Line 48...
53
        mov     ebx, [eax + TCP_SOCKET.t_maxseg]
48
        mov     ebx, [eax + TCP_SOCKET.t_maxseg]
54
        mov     [eax + TCP_SOCKET.SND_CWND], ebx
49
        mov     [eax + TCP_SOCKET.SND_CWND], ebx
Line 55... Line 50...
55
 
50
 
56
  .not_idle:
51
  .not_idle:
-
 
52
  .again:
-
 
53
        mov     [eax + TCP_SOCKET.sendalot], 0
57
  .again:
54
 
58
        mov     ebx, [eax + TCP_SOCKET.SND_NXT]         ; calculate offset (71)
55
        mov     ebx, [eax + TCP_SOCKET.SND_NXT]         ; calculate offset (71)
Line 59... Line 56...
59
        sub     ebx, [eax + TCP_SOCKET.SND_UNA]         ;
56
        sub     ebx, [eax + TCP_SOCKET.SND_UNA]         ;
60
 
57
 
Line 80... Line 77...
80
        jnz     .no_zero_window
77
        jnz     .no_zero_window
Line 81... Line 78...
81
 
78
 
82
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
79
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
Line 83... Line 80...
83
        jae     @f
80
        jae     @f
Line 84... Line 81...
84
 
81
 
85
        and     dl, not (TH_FIN)          ; clear the FIN flag    ??? how can it be set before?
82
        and     dl, not (TH_FIN)
86
 
83
 
Line 137... Line 134...
137
 
134
 
138
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
135
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
Line 139... Line 136...
139
        jbe     @f
136
        jbe     @f
140
 
-
 
141
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
137
 
142
        push    eax
138
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
Line 143... Line 139...
143
        push    dword TCP_sendalot
139
        inc     [eax + TCP_SOCKET.sendalot]
144
       @@:
140
       @@:
Line 145... Line 141...
145
 
141
 
146
;--------------------------------------------
142
;--------------------------------------------
147
; Turn of FIN flag if send buffer not emptied (128)
143
; Turn of FIN flag if send buffer not emptied (128)
148
 
144
 
149
        mov     edi, [eax + TCP_SOCKET.SND_NXT]
145
        mov     edi, [eax + TCP_SOCKET.SND_NXT]
150
        add     edi, esi
-
 
151
        sub     edi, [eax + TCP_SOCKET.SND_UNA]
146
        add     edi, esi
Line 152... Line 147...
152
        sub     edi, [eax + STREAM_SOCKET.snd.size]
147
        sub     edi, [eax + TCP_SOCKET.SND_UNA]
Line 153... Line 148...
153
        jns     @f
148
        cmp     edi, [eax + STREAM_SOCKET.snd.size]
Line 169... Line 164...
169
        jz      .len_zero
164
        jz      .len_zero
Line 170... Line 165...
170
 
165
 
171
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
166
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
Line -... Line 167...
-
 
167
        je      TCP_send
-
 
168
 
-
 
169
        add     ebx, esi                                ; offset + length
-
 
170
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
172
        je      TCP_send
171
        jb      @f
173
 
172
 
-
 
173
        test    [eax + TCP_SOCKET.t_flags], TF_NODELAY
-
 
174
        jnz     TCP_send
174
        test    [eax + TCP_SOCKET.t_flags], TF_NODELAY
175
 
-
 
176
        mov     ebx, [eax + TCP_SOCKET.SND_MAX]
175
        jnz     @f
177
        cmp     ebx, [eax + TCP_SOCKET.SND_UNA]
176
        ; TODO: if not 'idle', skip to next codeblock
-
 
177
       @@:
-
 
178
        add     ebx, esi
-
 
Line 179... Line 178...
179
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
178
        je      TCP_send
180
        jae     TCP_send
179
       @@:
Line 181... Line 180...
181
 
180
 
Line 236... Line 235...
236
        jz      .enter_persist  ; no reason to send, enter persist state
235
        jz      .enter_persist  ; no reason to send, enter persist state
Line 237... Line 236...
237
 
236
 
Line 238... Line 237...
238
; FIN was set, only send if not already sent, or on retransmit
237
; FIN was set, only send if not already sent, or on retransmit
239
 
238
 
Line 240... Line 239...
240
        test    [eax + TCP_SOCKET.t_flags], TF_SENTFIN
239
        test    [eax + TCP_SOCKET.t_flags], TF_SENTFIN
241
        jnz     TCP_send
240
        jz      TCP_send
242
 
241
 
Line 294... Line 293...
294
align 4
293
align 4
295
TCP_send:
294
TCP_send:
Line 296... Line 295...
296
 
295
 
Line -... Line 296...
-
 
296
        DEBUGF  1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl
297
        DEBUGF  1,"TCP_send socket=%x length=%u flags=%x\n", eax, esi, dl
297
 
Line 298... Line -...
298
 
-
 
299
        mov     edi, sizeof.TCP_header  ; edi will contain headersize
-
 
300
 
-
 
301
        sub     esp, 8                  ; create some space on stack
298
        push    eax                     ; save socket ptr
302
        push    eax                     ; save socket pointer
299
        mov     edi, sizeof.TCP_header  ; edi will contain headersize
Line 303... Line 300...
303
 
300
 
304
;------------------------------------
301
;------------------------------------
Line 377... Line 374...
377
        add     esi, edi                        ; total TCP segment size
374
        add     esi, edi                        ; total TCP segment size
378
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
375
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
379
        jbe     .no_overflow
376
        jbe     .no_overflow
Line 380... Line 377...
380
 
377
 
381
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
-
 
382
;;        push    eax
378
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
383
;;        push    dword TCP_sendalot
-
 
384
 
379
        inc     [eax + TCP_SOCKET.sendalot]
Line 385... Line 380...
385
  .no_overflow:
380
  .no_overflow:
386
 
381
 
387
;-----------------------------------------------------------------
382
;-----------------------------------------------------------------
Line 426... Line 421...
426
;-----------------------------------------
421
;-----------------------------------------
427
; Move TCP header from stack to TCP packet
422
; Move TCP header from stack to TCP packet
Line 428... Line 423...
428
 
423
 
429
        push    ecx
424
        push    ecx
430
        mov     ecx, [esp+4]
425
        mov     ecx, [esp + 4]
431
        lea     esi, [esp+4+4]
426
        lea     esi, [esp + 8]
432
        shr     ecx, 2
427
        shr     ecx, 2                  ; count is in bytes, we will work with dwords
433
        rep     movsd
428
        rep     movsd
Line 434... Line 429...
434
        pop     ecx             ; full TCP packet size
429
        pop     ecx                     ; full TCP packet size
435
 
430
 
Line 436... Line 431...
436
        pop     esi             ; headersize
431
        pop     esi                     ; headersize
437
        add     esp, esi
432
        add     esp, esi                ; remove it from stack
Line 438... Line 433...
438
 
433
 
439
        mov     [esp + 4], eax          ; packet ptr
434
        push    edx                     ; packet size for send proc
440
        mov     [esp + 4+4], edx        ; packet size
435
        push    eax                     ; packet ptr for send proc
441
 
436
 
Line 449... Line 444...
449
 
444
 
450
; eax = ptr to ring struct
445
; eax = ptr to ring struct
451
; ecx = buffer size
446
; ecx = buffer size
Line 452... Line 447...
452
; edi = ptr to buffer
447
; edi = ptr to buffer
453
 
448
 
Line 454... Line 449...
454
        mov     eax, [esp + 4]                  ; get socket ptr
449
        mov     eax, [esp + 12]                 ; get socket ptr
455
        add     [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
450
        add     [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
456
 
451
 
457
        push    edx
452
        push    edx
458
        test    ecx, ecx
453
        test    ecx, ecx
459
        jz      .nodata
454
        jz      .nodata
460
        add     eax, STREAM_SOCKET.snd
455
        add     eax, STREAM_SOCKET.snd
461
        call    SOCKET_ring_read
456
        call    SOCKET_ring_read
462
  .nodata:
457
  .nodata:
-
 
458
        pop     esi                             ; begin of data
Line 463... Line 459...
463
        pop     esi                             ; begin of data
459
        pop     ecx                             ; full packet size
464
        pop     ecx                             ; full packet size
460
        mov     eax, [esp + 8]
Line 465... Line 461...
465
        pop     eax                             ; socket ptr
461
 
Line 494... Line 490...
494
 
490
 
495
        mov     edx, [eax + TCP_SOCKET.t_rxtcur]
491
        mov     edx, [eax + TCP_SOCKET.t_rxtcur]
Line 496... Line 492...
496
        mov     [eax + TCP_SOCKET.timer_retransmission], dx
492
        mov     [eax + TCP_SOCKET.timer_retransmission], dx
497
 
493
 
498
        cmp     [eax + TCP_SOCKET.timer_persist], 0
494
        cmp     [eax + TCP_SOCKET.timer_persist], 0
499
        jne     @f
495
        jne     .retransmit_set
500
        mov     [eax + TCP_SOCKET.timer_persist], 0
-
 
Line 501... Line 496...
501
        mov     [eax + TCP_SOCKET.t_rxtshift], 0
496
        mov     [eax + TCP_SOCKET.timer_persist], 0
Line 502... Line 497...
502
       @@:
497
        mov     [eax + TCP_SOCKET.t_rxtshift], 0
503
 
498
 
Line 509... Line 504...
509
        DEBUGF  1,"checksum: ptr=%x size=%u\n", esi, ecx
504
        DEBUGF  1,"checksum: ptr=%x size=%u\n", esi, ecx
Line 510... Line 505...
510
 
505
 
511
        TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP)
506
        TCP_checksum (eax + IP_SOCKET.LocalIP), (eax + IP_SOCKET.RemoteIP)
Line 512... Line -...
512
        mov     [esi + TCP_header.Checksum], dx
-
 
513
 
-
 
514
; unlock socket
-
 
515
 
-
 
516
        pusha
-
 
517
        lea     ecx, [eax + SOCKET.mutex]
-
 
518
        call    mutex_unlock
-
 
519
        popa
507
        mov     [esi + TCP_header.Checksum], dx
520
 
508
 
Line 521... Line 509...
521
;----------------
509
;----------------
522
; Send the packet
510
; Send the packet
-
 
511
 
-
 
512
        DEBUGF  1,"Sending TCP Packet to device %x\n", ebx
-
 
513
        call    [ebx + NET_DEVICE.transmit]
-
 
514
        jnz     .send_error
-
 
515
        pop     eax
-
 
516
 
-
 
517
        inc     [TCP_segments_tx]       ; FIXME: correct interface?
-
 
518
 
-
 
519
;;; TODO: (485)
-
 
520
 
-
 
521
        push    [eax + TCP_SOCKET.RCV_NXT]
-
 
522
        pop     [eax + TCP_SOCKET.last_ack_sent]
-
 
523
 
-
 
524
        and     [eax + TCP_SOCKET.t_flags], not (TF_ACKNOW + TF_DELACK)
-
 
525
 
-
 
526
        cmp     [eax + TCP_SOCKET.sendalot], 0
-
 
527
        jne     TCP_output.again
-
 
528
 
-
 
529
; unlock socket
-
 
530
        lea     ecx, [eax + SOCKET.mutex]
-
 
531
        call    mutex_unlock
523
 
532
        DEBUGF 1,"TCP_output: success!\n"
Line 524... Line 533...
524
        DEBUGF  1,"Sending TCP Packet to device %x\n", ebx
533
 
525
        call    [ebx + NET_DEVICE.transmit]
534
        xor     eax, eax
526
        ret
535
        ret
527
 
536
 
528
 
-
 
Line 529... Line 537...
529
  .ip_error:
537
 
Line 530... Line 538...
530
        pop     ecx
538
  .ip_error:
531
        add     esp, ecx
539
        pop     ecx
532
        pop     eax
540
        add     esp, ecx
533
        add     esp, 8
-
 
534
 
-
 
535
        mov     [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min
541
        pop     eax
-
 
542
 
-
 
543
        mov     [eax + TCP_SOCKET.timer_retransmission], TCP_time_re_min
536
 
544
 
Line -... Line 545...
-
 
545
; unlock socket
-
 
546
        lea     ecx, [eax + SOCKET.mutex]
-
 
547
        call    mutex_unlock
-
 
548
        DEBUGF 1,"TCP_output: IP error\n"
-
 
549
 
-
 
550
        or      eax, -1
-
 
551
        ret
-
 
552
 
-
 
553
  .send_error:
-
 
554
        pop     eax
-
 
555
; unlock socket