Subversion Repositories Kolibri OS

Rev

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

Rev 5565 Rev 5984
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
 
17
$Revision: 5522 $
-
 
18
 
-
 
19
;-----------------------------------------------------------------
-
 
20
;
-
 
21
; TCP_input:
-
 
22
;
-
 
23
;       Add a segment to the incoming TCP queue
-
 
24
;
-
 
25
;  IN:  [esp] = ptr to buffer
-
 
26
;       ebx = ptr to device struct
-
 
27
;       ecx = segment size
-
 
28
;       esi = ptr to TCP segment
-
 
29
;       edi = ptr to ipv4 source address, followed by ipv4 dest address
-
 
30
;
-
 
31
;  OUT: /
-
 
32
;
-
 
Line -... Line 17...
-
 
17
$Revision: 5976 $
-
 
18
 
-
 
19
;-----------------------------------------------------------------;
-
 
20
;                                                                 ;
-
 
21
; TCP_input: Add a segment to the incoming TCP queue.             ;
-
 
22
;                                                                 ;
-
 
23
;  IN:  [esp] = ptr to buffer                                     ;
-
 
24
;       ebx = ptr to device struct                                ;
-
 
25
;       ecx = TCP segment size                                    ;
-
 
26
;       edx = ptr to IPv4 header                                  ;
-
 
27
;       esi = ptr to TCP segment                                  ;
-
 
28
;       edi = interface number*4                                  ;
-
 
29
;                                                                 ;
-
 
30
;  OUT: /                                                         ;
33
;-----------------------------------------------------------------
31
;                                                                 ;
34
 
32
;-----------------------------------------------------------------;
Line 35... Line 33...
35
align 4
33
align 4
36
TCP_input:
34
TCP_input:
37
 
35
 
38
; record the current time
36
; record the current time
Line -... Line 37...
-
 
37
        push    [timer_ticks]           ; in 1/100 seconds
39
        push    [timer_ticks]           ; in 1/100 seconds
38
        push    ebx ecx esi edx         ; mind the order (see TCP_queue_entry struct)
-
 
39
        mov     esi, esp
40
        push    ebx ecx esi edi         ; mind the order (see TCP_queue_entry struct)
40
 
Line 41... Line -...
41
        mov     esi, esp
-
 
42
 
41
        push    edi
Line 43... Line 42...
43
        add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail
42
        add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail
44
        add     esp, sizeof.TCP_queue_entry
43
        pop     edi
45
 
44
        add     esp, sizeof.TCP_queue_entry
Line 53... Line 52...
53
        call    raise_event
52
        call    raise_event
Line 54... Line 53...
54
 
53
 
Line 55... Line 54...
55
        ret
54
        ret
-
 
55
 
56
 
56
  .fail:
Line 57... Line 57...
57
  .fail:
57
        pop     edi
58
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP incoming queue is full, discarding packet!\n"
58
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP incoming queue is full, discarding packet!\n"
Line 59... Line 59...
59
 
59
 
60
        call    NET_ptr_to_num4
60
        call    NET_ptr_to_num4
61
        inc     [TCP_segments_missed + edi]
61
        inc     [TCP_segments_missed + edi]
Line 92... Line 92...
92
        pop     [timestamp]
92
        pop     [timestamp]
93
        push    [esi + TCP_queue_entry.buffer_ptr]
93
        push    [esi + TCP_queue_entry.buffer_ptr]
Line 94... Line 94...
94
 
94
 
95
        mov     ebx, [esi + TCP_queue_entry.device_ptr]
95
        mov     ebx, [esi + TCP_queue_entry.device_ptr]
96
        mov     ecx, [esi + TCP_queue_entry.segment_size]
96
        mov     ecx, [esi + TCP_queue_entry.segment_size]
97
        mov     edi, [esi + TCP_queue_entry.ip_ptr]                     ; ptr to ipv4 source address, followed by ipv4 destination address
97
        mov     edi, [esi + TCP_queue_entry.ip_ptr]                     ; ptr to ipv4 header
Line 98... Line 98...
98
        mov     esi, [esi + TCP_queue_entry.segment_ptr]                ; change esi last
98
        mov     esi, [esi + TCP_queue_entry.segment_ptr]                ; change esi last
Line 99... Line 99...
99
 
99
 
Line 109... Line 109...
109
        jnz     .checksum_ok
109
        jnz     .checksum_ok
Line 110... Line 110...
110
 
110
 
111
        push    ecx esi
111
        push    ecx esi
112
        pushw   [esi + TCP_header.Checksum]
112
        pushw   [esi + TCP_header.Checksum]
113
        mov     [esi + TCP_header.Checksum], 0
113
        mov     [esi + TCP_header.Checksum], 0
114
        TCP_checksum (edi), (edi+4)
114
        TCP_checksum (edi+IPv4_header.SourceAddress), (edi+IPv4_header.DestinationAddress)
115
        pop     cx                      ; previous checksum
115
        pop     cx                              ; previous checksum
116
        cmp     cx, dx
116
        cmp     cx, dx
117
        pop     edx ecx
117
        pop     edx ecx
118
        jne     .drop_no_socket
118
        jne     .drop_no_socket
Line 168... Line 168...
168
 
168
 
169
        cmp     [ebx + TCP_SOCKET.LocalPort], si
169
        cmp     [ebx + TCP_SOCKET.LocalPort], si
Line 170... Line 170...
170
        jne     .socket_loop
170
        jne     .socket_loop
171
 
171
 
172
        mov     eax, [ebx + IP_SOCKET.RemoteIP]
172
        mov     eax, [ebx + IP_SOCKET.RemoteIP]
173
        cmp     eax, [edi]                              ; Ipv4 source address
173
        cmp     eax, [edi + IPv4_header.SourceAddress]
174
        je      @f
174
        je      @f
175
        test    eax, eax
175
        test    eax, eax
Line 231... Line 231...
231
        pusha
231
        pusha
232
        lea     ecx, [ebx + SOCKET.mutex]
232
        lea     ecx, [ebx + SOCKET.mutex]
233
        call    mutex_unlock
233
        call    mutex_unlock
234
        popa
234
        popa
Line 235... Line 235...
235
 
235
 
236
        push    ecx edx esi edi         ;;;
236
        push    ecx edx esi edi
237
        call    SOCKET_fork
237
        call    SOCKET_fork
Line 238... Line 238...
238
        pop     edi esi edx ecx
238
        pop     edi esi edx ecx
239
 
239
 
Line 240... Line 240...
240
        test    eax, eax
240
        test    eax, eax
Line 241... Line 241...
241
        jz      .drop_no_socket
241
        jz      .drop_no_socket
Line 242... Line 242...
242
 
242
 
243
        mov     ebx, eax
243
        mov     ebx, eax
Line 244... Line 244...
244
 
244
 
245
        mov     [temp_bits], TCP_BIT_DROPSOCKET
245
        mov     [temp_bits], TCP_BIT_DROPSOCKET
Line 483... Line 483...
483
        mov     eax, [timestamp]
483
        mov     eax, [timestamp]
484
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
484
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
485
        inc     eax
485
        inc     eax
486
        call    TCP_xmit_timer
486
        call    TCP_xmit_timer
487
        jmp     .rtt_done
487
        jmp     .rtt_done
488
 
-
 
489
  .no_timestamp_rtt:
488
  .no_timestamp_rtt:
-
 
489
 
490
        cmp     [ebx + TCP_SOCKET.t_rtt], 0
490
        cmp     [ebx + TCP_SOCKET.t_rtt], 0
491
        je      .rtt_done
491
        je      .rtt_done
492
        mov     eax, [edx + TCP_header.AckNumber]
492
        mov     eax, [edx + TCP_header.AckNumber]
493
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
493
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
494
        jbe     .rtt_done
494
        jbe     .rtt_done
495
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
495
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
496
        call    TCP_xmit_timer
496
        call    TCP_xmit_timer
497
 
-
 
498
  .rtt_done:
497
  .rtt_done:
Line 499... Line 498...
499
 
498
 
500
; update window pointers
499
; update window pointers
501
        mov     eax, [edx + TCP_header.AckNumber]
500
        mov     eax, [edx + TCP_header.AckNumber]
Line 1209... Line 1208...
1209
 
1208
 
Line 1210... Line 1209...
1210
        inc     [TCPS_accepts]                          ; update stats
1209
        inc     [TCPS_accepts]                          ; update stats
Line 1211... Line 1210...
1211
 
1210
 
1212
;;; TODO: check if it's a broadcast or multicast, and drop if so
1211
;;; TODO: check if it's a broadcast or multicast, and drop if so
Line 1213... Line 1212...
1213
 
1212
 
1214
        push    dword [edi]                             ; Ipv4 source addres
1213
        push    [edi + IPv4_header.SourceAddress]
Line 1671... Line 1670...
1671
 
1670
 
Line 1672... Line 1671...
1672
        jmp     .drop_no_socket
1671
        jmp     .drop_no_socket
1673
 
1672
 
-
 
1673
  .respond_seg_ack:
1674
  .respond_seg_ack:
1674
        mov     cl, TH_RST
1675
        mov     cl, TH_RST
1675
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
Line 1676... Line 1676...
1676
        call    TCP_respond_segment
1676
        call    TCP_respond_segment
1677
        jmp     .drop_no_socket
1677
        jmp     .drop_no_socket
-
 
1678
 
1678
 
1679
  .respond_seg_syn:
1679
  .respond_seg_syn:
1680
        mov     cl, TH_RST + TH_ACK
Line 1680... Line 1681...
1680
        mov     cl, TH_RST + TH_ACK
1681
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
1681
        call    TCP_respond_segment
1682
        call    TCP_respond_segment