Subversion Repositories Kolibri OS

Rev

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

Rev 6011 Rev 6912
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2017. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
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: 6011 $
17
$Revision: 6912 $
18
 
18
 
19
 
19
 
Line 87... Line 87...
87
tcp_connect:
87
tcp_connect:
Line 88... Line 88...
88
 
88
 
89
        test    [eax + SOCKET.state], SS_ISCONNECTED
89
        test    [eax + SOCKET.state], SS_ISCONNECTED
Line 90... Line -...
90
        jnz     .eisconn
-
 
91
 
-
 
92
        inc     [TCPS_connattempt]                      ; update stats
90
        jnz     .eisconn
93
 
91
 
94
        push    eax edx
92
        push    eax edx
95
        lea     ecx, [eax + SOCKET.mutex]
-
 
Line 96... Line 93...
96
        call    mutex_lock
93
        lea     ecx, [eax + SOCKET.mutex]
97
        pop     edx eax
94
        call    mutex_lock
-
 
95
 
-
 
96
        mov     ebx, eax
98
 
97
        lea     eax, [ebx + STREAM_SOCKET.snd]
-
 
98
        call    socket_ring_create
99
; Fill in local IP
99
        test    eax, eax
-
 
100
        jz      .nomem
-
 
101
 
-
 
102
        lea     eax, [ebx + STREAM_SOCKET.rcv]
100
        cmp     [eax + IP_SOCKET.LocalIP], 0
103
        call    socket_ring_create
Line 101... Line 104...
101
        jne     @f
104
        test    eax, eax
102
        push    [IP_LIST + 4]                                   ; FIXME: use correct local IP
105
        jz      .nomem
103
        pop     [eax + IP_SOCKET.LocalIP]
106
        pop     edx eax
Line 104... Line 107...
104
 
107
 
105
; Fill in remote port and IP
108
; Fill in remote port and IP
-
 
109
        pushw   [edx + 2]
-
 
110
        pop     [eax + TCP_SOCKET.RemotePort]
-
 
111
 
-
 
112
        pushd   [edx + 4]
-
 
113
        pop     [eax + TCP_SOCKET.RemoteIP]
-
 
114
 
-
 
115
; Find route to host
-
 
116
        pusha
-
 
117
        push    eax
-
 
118
        mov     ebx, [eax + TCP_SOCKET.device]
-
 
119
        mov     edx, [eax + TCP_SOCKET.LocalIP]
-
 
120
        mov     eax, [eax + TCP_SOCKET.RemoteIP]
-
 
121
        call    ipv4_route
-
 
122
        test    eax, eax
-
 
123
        jz      .enoroute
Line 106... Line 124...
106
        pushw   [edx + 2]
124
        pop     eax
107
        pop     [eax + TCP_SOCKET.RemotePort]
125
        mov     ebx, [NET_DRV_LIST + edi]
108
 
126
        mov     [eax + TCP_SOCKET.device], ebx
109
        pushd   [edx + 4]
127
        mov     [eax + TCP_SOCKET.LocalIP], edx
110
        pop     [eax + IP_SOCKET.RemoteIP]
128
        popa
Line -... Line 129...
-
 
129
 
-
 
130
; Find a local port, if user didnt define one
-
 
131
        cmp     [eax + TCP_SOCKET.LocalPort], 0
-
 
132
        jne     @f
-
 
133
        call    socket_find_port
-
 
134
       @@:
-
 
135
 
111
 
136
; Compute window scaling factor
-
 
137
        push    ecx
-
 
138
        xor     ecx, ecx
-
 
139
        mov     ebx, TCP_max_win
-
 
140
  @@:
-
 
141
        cmp     ebx, SOCKET_BUFFER_SIZE
-
 
142
        ja      @f
-
 
143
        shl     ebx, 1
-
 
144
        inc     ecx
-
 
145
        cmp     ecx, TCP_max_winshift
-
 
146
        jb      @r
112
; Find a local port, if user didnt define one
147
  @@:
113
        cmp     [eax + TCP_SOCKET.LocalPort], 0
148
        mov     [eax + TCP_SOCKET.request_r_scale], cl
Line -... Line 149...
-
 
149
        pop     ecx
-
 
150
 
114
        jne     @f
151
        call    socket_is_connecting
115
        call    socket_find_port
152
        inc     [TCPS_connattempt]
116
       @@:
153
 
117
 
-
 
Line 118... Line 154...
118
; Start the TCP sequence
154
        mov     [eax + TCP_SOCKET.timer_persist], 0
Line 119... Line -...
119
        mov     [eax + TCP_SOCKET.timer_persist], 0
-
 
120
        mov     [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
-
 
121
 
-
 
122
        push    [TCP_sequence_num]
-
 
123
        add     [TCP_sequence_num], 6400
-
 
124
        pop     [eax + TCP_SOCKET.ISS]
-
 
125
        mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
-
 
126
 
-
 
127
        tcp_sendseqinit eax
-
 
128
 
-
 
129
        mov     ebx, eax
-
 
130
        lea     eax, [ebx + STREAM_SOCKET.snd]
155
        mov     [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
131
        call    socket_ring_create
156
 
132
        test    eax, eax
157
        mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
133
        jz      .nomem
158
 
Line 134... Line -...
134
 
-
 
135
        lea     eax, [ebx + STREAM_SOCKET.rcv]
-
 
136
        call    socket_ring_create
159
        push    [TCP_sequence_num]
137
        test    eax, eax
160
        add     [TCP_sequence_num], TCP_ISSINCR/2
138
        jz      .nomem
161
        pop     [eax + TCP_SOCKET.ISS]
139
 
162
 
Line 140... Line -...
140
        push    ebx
-
 
141
        lea     ecx, [ebx + SOCKET.mutex]
163
        tcp_sendseqinit eax
142
        call    mutex_unlock
164
 
Line 143... Line 165...
143
        pop     eax
165
        push    eax
144
 
166
        lea     ecx, [eax + SOCKET.mutex]
145
        call    socket_is_connecting
167
        call    mutex_unlock
146
 
168
        pop     eax
Line 147... Line 169...
147
; Now send the SYN packet to remote end
169
 
-
 
170
; Now send the SYN packet to remote end
148
        push    eax
171
        push    eax
149
        call    tcp_output
172
        call    tcp_output
150
        pop     eax
173
        pop     eax
151
 
174
 
Line 168... Line 191...
168
        xor     eax, eax
191
        xor     eax, eax
169
        dec     eax
192
        dec     eax
170
        mov     ebx, EISCONN
193
        mov     ebx, EISCONN
171
        ret
194
        ret
Line -... Line 195...
-
 
195
 
-
 
196
  .enoroute:
-
 
197
        pop     eax
-
 
198
        popa
-
 
199
        xor     eax, eax
-
 
200
        dec     eax
-
 
201
        mov     ebx, EADDRNOTAVAIL
-
 
202
        ret
172
 
203
 
173
  .waitforit:
204
  .waitforit:
174
        push    eax
205
        push    eax
175
        stdcall timer_hs, TCP_time_connect, 0, .timeout, eax
206
        stdcall timer_hs, TCP_time_connect, 0, .timeout, eax
176
        pop     ebx
207
        pop     ebx
Line 200... Line 231...
200
        dec     eax
231
        dec     eax
201
        ret
232
        ret
Line 202... Line 233...
202
 
233
 
203
  .established:
234
  .established:
204
        stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect]
-
 
205
 
235
        stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect]
206
        xor     eax, eax
236
        xor     eax, eax
207
        ret
237
        ret