Subversion Repositories Kolibri OS

Rev

Rev 5976 | Rev 6476 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5976 Rev 6011
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: 5976 $
17
$Revision: 6011 $
18
 
18
 
19
align 4
19
align 4
20
iglobal
20
iglobal
Line 21... Line 21...
21
        TCP_backoff     db 0,1,2,3,4,5,6,6,6,6,6,6,6
21
        TCP_backoff     db 0,1,2,3,4,5,6,6,6,6,6,6,6
Line 22... Line 22...
22
endg
22
endg
23
 
23
 
Line 24... Line 24...
24
macro   TCP_checksum IP1, IP2 {
24
macro   tcp_checksum IP1, IP2 {
Line 58... Line 58...
58
}       ; returns in dx only
58
}       ; returns in dx only
Line 59... Line 59...
59
 
59
 
Line 60... Line 60...
60
 
60
 
61
 
61
 
62
 
62
 
63
macro   TCP_sendseqinit ptr {
63
macro   tcp_sendseqinit ptr {
64
 
64
 
65
        push    edi                     ;;;; i dont like this static use of edi
65
        push    edi                     ;;;; FIXME: i dont like this static use of edi
Line 72... Line 72...
72
 
72
 
Line 73... Line 73...
73
}
73
}
Line 74... Line 74...
74
 
74
 
75
 
75
 
76
 
76
 
77
macro   TCP_rcvseqinit ptr {
77
macro   tcp_rcvseqinit ptr {
Line 85... Line 85...
85
 
85
 
Line 86... Line 86...
86
}
86
}
Line 87... Line 87...
87
 
87
 
88
 
88
 
Line 89... Line 89...
89
 
89
 
Line 104... Line 104...
104
}
104
}
Line 105... Line 105...
105
 
105
 
106
 
106
 
107
;-----------------------------------------------------------------;
107
;-----------------------------------------------------------------;
108
;                                                                 ;
108
;                                                                 ;
109
; TCP_pull_out_of_band                                            ;
109
; tcp_pull_out_of_band                                            ;
110
;                                                                 ;
110
;                                                                 ;
111
;  IN:  eax = ?                                                   ;
111
;  IN:  eax = ?                                                   ;
112
;       ebx = socket ptr                                          ;
112
;       ebx = socket ptr                                          ;
113
;       edx = tcp packet ptr                                      ;
113
;       edx = tcp packet ptr                                      ;
114
;                                                                 ;
114
;                                                                 ;
115
; OUT:  /                                                         ;
115
; OUT:  /                                                         ;
116
;                                                                 ;
116
;                                                                 ;
117
;-----------------------------------------------------------------;
117
;-----------------------------------------------------------------;
Line 118... Line 118...
118
align 4
118
align 4
Line 119... Line 119...
119
TCP_pull_out_of_band:
119
tcp_pull_out_of_band:
Line 120... Line 120...
120
 
120
 
Line 121... Line 121...
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_pull_out_of_band\n"
121
        DEBUGF  DEBUG_NETWORK_VERBOSE, "tcp_pull_out_of_band\n"
122
 
122
 
123
        ;;;; 1282-1305
123
        ;;;; 1282-1305
124
 
124
 
125
        ret
125
        ret
126
 
126
 
127
 
127
 
128
 
128
 
129
;-----------------------------------------------------------------;
129
;-----------------------------------------------------------------;
130
;                                                                 ;
130
;                                                                 ;
131
; TCP_drop                                                        ;
131
; tcp_drop                                                        ;
132
;                                                                 ;
132
;                                                                 ;
Line 133... Line 133...
133
;  IN:  eax = socket ptr                                          ;
133
;  IN:  eax = socket ptr                                          ;
Line 134... Line 134...
134
;       ebx = error number                                        ;
134
;       ebx = error number                                        ;
135
;                                                                 ;
135
;                                                                 ;
Line 136... Line 136...
136
;  OUT: eax = socket ptr                                          ;
136
;  OUT: eax = socket ptr                                          ;
Line 137... Line 137...
137
;                                                                 ;
137
;                                                                 ;
138
;-----------------------------------------------------------------;
138
;-----------------------------------------------------------------;
139
align 4
139
align 4
Line 140... Line 140...
140
TCP_drop:    ; FIXME CHECKME TODO
140
tcp_drop:    ; FIXME CHECKME TODO
Line 141... Line 141...
141
 
141
 
Line 142... Line 142...
142
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_drop: %x\n", eax
142
        DEBUGF  DEBUG_NETWORK_VERBOSE, "tcp_drop: %x\n", eax
Line 143... Line 143...
143
 
143
 
Line 165... Line 165...
165
 
165
 
166
 
166
 
167
 
167
 
168
;-----------------------------------------------------------------;
168
;-----------------------------------------------------------------;
169
;                                                                 ;
169
;                                                                 ;
170
; TCP_disconnect                                                  ;
170
; tcp_disconnect                                                  ;
171
;                                                                 ;
171
;                                                                 ;
172
;  IN:  eax = socket ptr                                          ;
172
;  IN:  eax = socket ptr                                          ;
173
;                                                                 ;
173
;                                                                 ;
174
;  OUT: eax = socket ptr / 0                                      ;
174
;  OUT: eax = socket ptr / 0                                      ;
175
;                                                                 ;
175
;                                                                 ;
Line 176... Line 176...
176
;-----------------------------------------------------------------;
176
;-----------------------------------------------------------------;
Line 177... Line 177...
177
align 4
177
align 4
178
TCP_disconnect:
178
tcp_disconnect:
Line 179... Line 179...
179
 
179
 
Line 180... Line 180...
180
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_disconnect: %x\n", eax
180
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_disconnect: %x\n", eax
181
 
181
 
Line 182... Line 182...
182
        cmp     [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
182
        cmp     [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
183
        jb      TCP_close       ; Connection not yet synchronised, just get rid of the socket
183
        jb      tcp_close       ; Connection not yet synchronised, just get rid of the socket
184
 
184
 
185
; TODO: implement LINGER
185
; TODO: implement LINGER
186
 
186
 
187
        call    SOCKET_is_disconnecting
187
        call    socket_is_disconnecting
188
        call    TCP_usrclosed
188
        call    tcp_usrclosed
Line 189... Line 189...
189
 
189
 
190
        test    eax, eax
190
        test    eax, eax
191
        jz      @f
191
        jz      @f
192
        push    eax
192
        push    eax
193
        call    TCP_output
193
        call    tcp_output
194
        pop     eax
194
        pop     eax
195
  @@:
195
  @@:
196
        ret
196
        ret
197
 
197
 
198
 
198
 
199
;-----------------------------------------------------------------;
199
;-----------------------------------------------------------------;
Line 200... Line 200...
200
;                                                                 ;
200
;                                                                 ;
Line 201... Line 201...
201
; TCP_close                                                       ;
201
; tcp_close                                                       ;
202
;                                                                 ;
202
;                                                                 ;
Line 203... Line 203...
203
;  IN:  eax = socket ptr                                          ;
203
;  IN:  eax = socket ptr                                          ;
204
;                                                                 ;
204
;                                                                 ;
Line 205... Line 205...
205
;  OUT: /                                                         ;
205
;  OUT: /                                                         ;
206
;                                                                 ;
206
;                                                                 ;
Line 207... Line 207...
207
;-----------------------------------------------------------------;
207
;-----------------------------------------------------------------;
208
align 4
208
align 4
209
TCP_close:
209
tcp_close:
210
 
210
 
211
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_close: %x\n", eax
211
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_close: %x\n", eax
212
 
212
 
213
;;; TODO: update RTT and mean deviation
213
;;; TODO: update RTT and mean deviation
214
;;; TODO: update slow start threshold
214
;;; TODO: update slow start threshold
215
 
215
 
216
        call    SOCKET_is_disconnected
216
        call    socket_is_disconnected
217
        call    SOCKET_free
217
        call    socket_free
Line 218... Line 218...
218
 
218
 
219
        xor     eax, eax
219
        xor     eax, eax
Line 220... Line 220...
220
        ret
220
        ret
Line 221... Line 221...
221
 
221
 
Line 268... Line 268...
268
;                                                                 ;
268
;                                                                 ;
269
; OUT:  /                                                         ;
269
; OUT:  /                                                         ;
270
;                                                                 ;
270
;                                                                 ;
271
;-----------------------------------------------------------------;
271
;-----------------------------------------------------------------;
272
align 4
272
align 4
273
TCP_respond:
273
tcp_respond:
Line 274... Line 274...
274
 
274
 
Line 275... Line 275...
275
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_respond_socket: socket=%x flags=%x\n", ebx, cl
275
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_respond_socket: socket=%x flags=%x\n", ebx, cl
276
 
276
 
Line 282... Line 282...
282
        mov     edi, [ebx + IP_SOCKET.RemoteIP]
282
        mov     edi, [ebx + IP_SOCKET.RemoteIP]
283
        mov     al, [ebx + IP_SOCKET.ttl]
283
        mov     al, [ebx + IP_SOCKET.ttl]
284
        mov     ah, IP_PROTO_TCP
284
        mov     ah, IP_PROTO_TCP
285
        mov     ecx, sizeof.TCP_header
285
        mov     ecx, sizeof.TCP_header
286
        mov     ebx, [ebx + IP_SOCKET.device]
286
        mov     ebx, [ebx + IP_SOCKET.device]
287
        call    IPv4_output
287
        call    ipv4_output
288
        jz      .error
288
        jz      .error
289
        pop     esi cx
289
        pop     esi cx
290
        push    eax
290
        push    eax
Line 291... Line 291...
291
 
291
 
Line 318... Line 318...
318
 
318
 
319
  .checksum:
319
  .checksum:
320
        sub     edi, sizeof.TCP_header
320
        sub     edi, sizeof.TCP_header
321
        mov     ecx, sizeof.TCP_header
321
        mov     ecx, sizeof.TCP_header
322
        xchg    esi, edi
322
        xchg    esi, edi
323
        TCP_checksum (edi + IP_SOCKET.LocalIP), (edi + IP_SOCKET.RemoteIP)
323
        tcp_checksum (edi + IP_SOCKET.LocalIP), (edi + IP_SOCKET.RemoteIP)
Line 324... Line 324...
324
        mov     [esi+TCP_header.Checksum], dx
324
        mov     [esi+TCP_header.Checksum], dx
325
 
325
 
Line 326... Line 326...
326
;--------------------
326
;--------------------
327
; And send the segment
327
; And send the segment
328
 
328
 
329
        call    [ebx + NET_DEVICE.transmit]
329
        call    [ebx + NET_DEVICE.transmit]
330
        test    eax, eax
330
        test    eax, eax
331
        jnz     @f
331
        jnz     @f
332
        call    NET_ptr_to_num4
332
        call    net_ptr_to_num4
Line 333... Line 333...
333
        inc     [TCP_segments_tx + edi]
333
        inc     [TCP_segments_tx + edi]
Line 341... Line 341...
341
        ret
341
        ret
Line 342... Line 342...
342
 
342
 
343
 
343
 
344
;-----------------------------------------------------------------;
344
;-----------------------------------------------------------------;
345
;                                                                 ;
345
;                                                                 ;
346
; TCP_respond_segment                                             ;
346
; tcp_respond_segment                                             ;
347
;                                                                 ;
347
;                                                                 ;
348
;  IN:  ebx = device ptr                                          ;
348
;  IN:  ebx = device ptr                                          ;
349
;       edx = segment ptr (a previously received segment)         ;
349
;       edx = segment ptr (a previously received segment)         ;
350
;       edi = ptr to IPv4 header                                  ;
350
;       edi = ptr to IPv4 header                                  ;
351
;        cl = flags                                               ;
351
;        cl = flags                                               ;
352
;                                                                 ;
352
;                                                                 ;
353
;  OUT: /                                                         ;
353
;  OUT: /                                                         ;
354
;                                                                 ;
354
;                                                                 ;
355
;-----------------------------------------------------------------;
355
;-----------------------------------------------------------------;
Line 356... Line 356...
356
align 4
356
align 4
Line 357... Line 357...
357
TCP_respond_segment:
357
tcp_respond_segment:
358
 
358
 
Line 364... Line 364...
364
        push    cx edx
364
        push    cx edx
365
        mov     edx, [edi + IPv4_header.DestinationAddress]
365
        mov     edx, [edi + IPv4_header.DestinationAddress]
366
        mov     edi, [edi + IPv4_header.SourceAddress]
366
        mov     edi, [edi + IPv4_header.SourceAddress]
367
        mov     ecx, sizeof.TCP_header
367
        mov     ecx, sizeof.TCP_header
368
        mov     ax, IP_PROTO_TCP shl 8 + 128
368
        mov     ax, IP_PROTO_TCP shl 8 + 128
369
        call    IPv4_output
369
        call    ipv4_output
370
        jz      .error
370
        jz      .error
371
        pop     esi cx
371
        pop     esi cx
Line 372... Line 372...
372
 
372
 
Line 397... Line 397...
397
;---------------------
397
;---------------------
398
; Fill in the checksum
398
; Fill in the checksum
Line 399... Line 399...
399
 
399
 
400
        lea     esi, [edi - sizeof.TCP_header]
400
        lea     esi, [edi - sizeof.TCP_header]
401
        mov     ecx, sizeof.TCP_header
401
        mov     ecx, sizeof.TCP_header
402
        TCP_checksum (esi - sizeof.IPv4_header + IPv4_header.DestinationAddress),\      ; FIXME
402
        tcp_checksum (esi - sizeof.IPv4_header + IPv4_header.DestinationAddress),\      ; FIXME
403
                     (esi - sizeof.IPv4_header + IPv4_header.SourceAddress)
403
                     (esi - sizeof.IPv4_header + IPv4_header.SourceAddress)
Line 404... Line 404...
404
        mov     [esi + TCP_header.Checksum], dx
404
        mov     [esi + TCP_header.Checksum], dx
405
 
405
 
Line 406... Line 406...
406
;--------------------
406
;--------------------
407
; And send the segment
407
; And send the segment
408
 
408
 
409
        call    [ebx + NET_DEVICE.transmit]
409
        call    [ebx + NET_DEVICE.transmit]
410
        test    eax, eax
410
        test    eax, eax
411
        jnz     @f
411
        jnz     @f
412
        call    NET_ptr_to_num4
412
        call    net_ptr_to_num4
Line 413... Line 413...
413
        inc     [TCP_segments_tx + edi]
413
        inc     [TCP_segments_tx + edi]
Line 419... Line 419...
419
        add     esp, 2+4
419
        add     esp, 2+4
Line 420... Line 420...
420
 
420
 
Line 421... Line 421...
421
        ret
421
        ret
Line 422... Line 422...
422
 
422
 
423
 
423
 
424
macro   TCPT_RANGESET   timer, value, min, max {
424
macro   tcpt_rangeset   timer, value, min, max {
Line 446... Line 446...
446
  .done:
446
  .done:
447
}
447
}
Line 448... Line 448...
448
 
448
 
449
;-----------------------------------------------------------------;
449
;-----------------------------------------------------------------;
450
;                                                                 ;
450
;                                                                 ;
451
; TCP_set_persist                                                 ;
451
; tcp_set_persist                                                 ;
452
;                                                                 ;
452
;                                                                 ;
453
;-----------------------------------------------------------------;
453
;-----------------------------------------------------------------;
454
align 4
454
align 4
Line 455... Line 455...
455
TCP_set_persist:
455
tcp_set_persist:
Line 456... Line 456...
456
 
456
 
Line 471... Line 471...
471
        mov     cl, [eax + TCP_SOCKET.t_rxtshift]
471
        mov     cl, [eax + TCP_SOCKET.t_rxtshift]
472
        shl     ebx, cl
472
        shl     ebx, cl
Line 473... Line 473...
473
 
473
 
Line 474... Line 474...
474
; Start/restart persistance timer.
474
; Start/restart persistance timer.
475
 
475
 
476
        TCPT_RANGESET   [eax + TCP_SOCKET.timer_persist], ebx, TCP_time_pers_min, TCP_time_pers_max
476
        tcpt_rangeset [eax + TCP_SOCKET.timer_persist], ebx, TCP_time_pers_min, TCP_time_pers_max
Line 477... Line 477...
477
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_persist
477
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_persist
478
        pop     ebx
478
        pop     ebx
Line 487... Line 487...
487
 
487
 
488
 
488
 
489
 
489
 
490
;-----------------------------------------------------------------;
490
;-----------------------------------------------------------------;
491
;                                                                 ;
491
;                                                                 ;
492
; TCP_xmit_timer: Calculate new smoothed RTT.                     ;
492
; tcp_xmit_timer: Calculate new smoothed RTT.                     ;
493
;                                                                 ;
493
;                                                                 ;
494
;   IN: eax = rtt                                                 ;
494
;   IN: eax = rtt                                                 ;
495
;       ebx = socket ptr                                          ;
495
;       ebx = socket ptr                                          ;
496
;                                                                 ;
496
;                                                                 ;
497
;  OUT: /                                                         ;
497
;  OUT: /                                                         ;
498
;                                                                 ;
498
;                                                                 ;
Line 499... Line 499...
499
;-----------------------------------------------------------------;
499
;-----------------------------------------------------------------;
Line 500... Line 500...
500
align 4
500
align 4
Line 561... Line 561...
561
        ret
561
        ret
Line 562... Line 562...
562
 
562
 
563
 
563
 
564
;-----------------------------------------------------------------;
564
;-----------------------------------------------------------------;
565
;                                                                 ;
565
;                                                                 ;
566
; TCP_mss: Update maximum segment size                            ;
566
; tcp_mss: Update maximum segment size                            ;
567
;                                                                 ;
567
;                                                                 ;
568
;  IN:  eax = max segment size                                    ;
568
;  IN:  eax = max segment size                                    ;
569
;       ebx = socket ptr                                          ;
569
;       ebx = socket ptr                                          ;
570
;                                                                 ;
570
;                                                                 ;
571
;  OUT: /                                                         ;
571
;  OUT: /                                                         ;
572
;                                                                 ;
572
;                                                                 ;
573
;-----------------------------------------------------------------;
573
;-----------------------------------------------------------------;
Line 574... Line 574...
574
align 4
574
align 4
575
TCP_mss:
575
tcp_mss:
576
 
576
 
577
        cmp     eax, 1420       ; FIXME
577
        cmp     eax, 1420       ; FIXME
Line 585... Line 585...
585
 
585
 
586
 
586
 
587
 
587
 
588
;-----------------------------------------------------------------;
588
;-----------------------------------------------------------------;
589
;                                                                 ;
589
;                                                                 ;
590
; TCP_reassemble                                                  ;
590
; tcp_reassemble                                                  ;
591
;                                                                 ;
591
;                                                                 ;
592
;   IN: ebx = socket ptr                                          ;
592
;   IN: ebx = socket ptr                                          ;
593
;       edx = segment ptr                                         ;
593
;       edx = segment ptr                                         ;
594
;                                                                 ;
594
;                                                                 ;
595
;  OUT: /                                                         ;
595
;  OUT: /                                                         ;
596
;                                                                 ;
596
;                                                                 ;
Line 597... Line 597...
597
;-----------------------------------------------------------------;
597
;-----------------------------------------------------------------;
Line 598... Line 598...
598
align 4
598
align 4