Subversion Repositories Kolibri OS

Rev

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

Rev 1161 Rev 1196
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2009. 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
;;  TCP.INC                                                     ;;
6
;;  TCP.INC                                                        ;;
7
;;                                                              ;;
7
;;                                                                 ;;
8
;;  TCP Processes for Menuet OS  TCP/IP stack                   ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
9
;;                                                              ;;
9
;;                                                                 ;;
10
;;  Copyright 2002 Mike Hibbett, mikeh@oceanfree.net            ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                              ;;
11
;;                                                                 ;;
12
;;  See file COPYING for details                                ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;  v0.6 : Added reset handling in the established state        ;;
-
 
14
;;         Added a timer per socket to allow delays when        ;;
-
 
15
;;         rx window gets below 1KB                             ;;
13
;;             Version 2, June 1991                                ;;
16
;;                                                              ;;
14
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
16
 
Line 18... Line 17...
18
 
17
 
Line 19... Line 18...
19
$Revision: 1019 $
18
$Revision: 1019 $
Line 42... Line 41...
42
TWOMSL			equ 10	    ; # of secs to wait before closing socket
41
TWOMSL			equ 10		; # of secs to wait before closing socket
Line 43... Line 42...
43
 
42
 
44
TCP_RETRIES		equ 5		    ; Number of times to resend a Packet
43
TCP_RETRIES		equ 5		; Number of times to resend a Packet
Line -... Line 44...
-
 
44
TCP_TIMEOUT		equ 10		; resend if not replied to in x hs
-
 
45
 
45
TCP_TIMEOUT		equ 10		    ; resend if not replied to in x hs
46
TCP_QUEUE_SIZE		equ 16
46
 
47
 
47
struct	TCP_Packet
48
struct	TCP_Packet
48
	.SourcePort		dw ?
49
	.SourcePort		dw ?
49
	.DestinationPort	dw ?
50
	.DestinationPort	dw ?
Line 57... Line 58...
57
	.Options		rb 3
58
	.Options		rb 3
58
	.Padding		db ?
59
	.Padding		db ?
59
	.Data:
60
	.Data:
60
ends
61
ends
Line -... Line 62...
-
 
62
 
-
 
63
align 4
-
 
64
uglobal
-
 
65
	TCP_PACKETS_TX		rd  MAX_IP
Line -... Line 66...
-
 
66
	TCP_PACKETS_RX		rd  MAX_IP
-
 
67
 
-
 
68
	TCP_IN_QUEUE	rd  3*TCP_QUEUE_SIZE+3
-
 
69
	TCP_OUT_QUEUE	rd  3*TCP_QUEUE_SIZE+3
-
 
70
endg
-
 
71
 
-
 
72
 
-
 
73
 
61
 
74
 
-
 
75
 
62
 
76
;-----------------------------------------------------------------
-
 
77
;
-
 
78
; TCP_init
-
 
79
;
-
 
80
;  This function resets all TCP variables
-
 
81
;
-
 
82
;  IN:  /
-
 
83
;  OUT: /
-
 
84
;
-
 
85
;-----------------------------------------------------------------
-
 
86
 
-
 
87
align 4
-
 
88
TCP_init:
-
 
89
 
-
 
90
	xor	eax, eax
-
 
91
	mov	edi, TCP_PACKETS_TX
-
 
92
	mov	ecx, 2*MAX_IP
-
 
93
	rep	stosd
-
 
94
 
-
 
95
	mov	dword [TCP_IN_QUEUE], TCP_QUEUE_SIZE
-
 
96
	mov	dword [TCP_IN_QUEUE+4], TCP_IN_QUEUE + queue.data
-
 
97
	mov	dword [TCP_IN_QUEUE+8], TCP_IN_QUEUE + queue.data
-
 
98
 
-
 
99
	mov	dword [TCP_OUT_QUEUE], TCP_QUEUE_SIZE
-
 
100
	mov	dword [TCP_OUT_QUEUE+4], TCP_OUT_QUEUE + queue.data
-
 
101
	mov	dword [TCP_OUT_QUEUE+8], TCP_OUT_QUEUE + queue.data
-
 
102
 
-
 
103
	ret
-
 
104
 
-
 
105
 
63
;***************************************************************************
106
;-----------------------------------------------------------------
64
;   Function
107
;
65
;      tcp_tcb_handler
-
 
66
;
108
;      tcp_tcb_handler
67
;   Description
109
;
68
;       Handles sockets in the timewait state, closing them
110
;       Handles sockets in the timewait state, closing them
69
;       when the TCB timer expires
111
;       when the TCB timer expires
Line -... Line 112...
-
 
112
;
70
;
113
;-----------------------------------------------------------------
71
;***************************************************************************
114
 
Line 72... Line 115...
72
 
115
align 4
Line 82... Line 125...
82
  .next_socket:
125
  .next_socket:
83
	mov	ebx, [ebx + SOCKET.NextPtr]
126
	mov	ebx, [ebx + SOCKET.NextPtr]
84
	or	ebx, ebx
127
	or	ebx, ebx
85
	jz	.exit
128
	jz	.exit
Line 86... Line 129...
86
 
129
 
Line 87... Line 130...
87
	DEBUGF	1, "K :   %x-%x: %x-%x-%x-%u\n", [ebx + SOCKET.PID]:2, [ebx + SOCKET.Number]:2, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState]
130
;        DEBUGF  1, "K :   %x-%x: %x-%x-%x-%u\n", [ebx + SOCKET.PID]:2, [ebx + SOCKET.Number]:2, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState]
88
 
131
 
89
	cmp	[ebx + SOCKET.TCBTimer], 0
132
	cmp	[ebx + SOCKET.TCBTimer], 0
90
	jne	.decrement_tcb
133
	jne	.decrement_tcb
Line 122... Line 165...
122
;       Handles queued TCP data
165
;       Handles queued TCP data
123
;       This is a kernel function, called by stack_handler
166
;       This is a kernel function, called by stack_handler
124
;
167
;
125
;***************************************************************************
168
;***************************************************************************
Line -... Line 169...
-
 
169
 
126
 
170
align 4
127
proc tcp_tx_handler stdcall
171
tcp_tx_handler:
128
    ; decrement all resend buffers timers. If they
172
    ; decrement all resend buffers timers. If they
129
    ; expire, queue them for sending, and restart the timer.
173
    ; expire, queue them for sending, and restart the timer.
Line 130... Line 174...
130
    ; If the retries counter reach 0, delete the entry
174
    ; If the retries counter reach 0, delete the entry
131
 
175
 
Line 132... Line 176...
132
	mov	esi, resendQ
176
	mov	esi, resendQ
133
	mov	ecx, 0
177
	mov	ecx, 0
134
 
178
 
135
  .next_resendq:
179
  .next_resendq:
136
	cmp	ecx, NUMRESENDENTRIES
180
;        cmp     ecx, NUMRESENDENTRIES
137
	je	.exit		    ; None left
181
	je	.exit		    ; None left
138
	cmp	dword[esi + 4], 0
182
	cmp	dword[esi + 4], 0
Line 160... Line 204...
160
	xchg	 [esi + 4], ebx
204
	xchg	 [esi + 4], ebx
Line 161... Line 205...
161
 
205
 
162
    @@: ; resend Packet
206
    @@: ; resend Packet
Line 163... Line 207...
163
	pushad
207
	pushad
164
 
208
 
165
	mov	eax, EMPTY_QUEUE
209
;        mov     eax, EMPTY_QUEUE
166
	call	dequeue
210
;        call    dequeue
Line 167... Line 211...
167
	cmp	ax, NO_BUFFER
211
;        cmp     ax, NO_BUFFER
168
	jne	.tth004z
212
	jne	.tth004z
169
 
213
 
Line 177... Line 221...
177
	mov	word[esi + 2], 1
221
	mov	word[esi + 2], 1
178
	jmp	.tth005
222
	jmp	.tth005
Line 179... Line 223...
179
 
223
 
180
  .tth004z:
224
  .tth004z:
181
	; we have a buffer # in ax
225
	; we have a buffer # in ax
182
	push	eax ecx
226
;        push    eax ecx
183
	mov	ecx, IPBUFFSIZE
227
;        mov     ecx, IPBUFFSIZE
184
	mul	ecx
228
;        mul     ecx
Line 185... Line 229...
185
	add	eax, IPbuffs
229
;        add     eax, IPbuffs
186
 
230
 
187
	; we have the buffer address in eax
231
	; we have the buffer address in eax
188
	mov	edi, eax
232
	mov	edi, eax
189
	pop	ecx
233
	pop	ecx
190
	; Now get buffer location, and copy buffer across. argh! more copying,,
234
	; Now get buffer location, and copy buffer across. argh! more copying,,
191
	mov	esi, resendBuffer
235
;        mov     esi, resendBuffer
Line 192... Line 236...
192
    @@: add	esi, IPBUFFSIZE
236
;    @@: add     esi, IPBUFFSIZE
193
	loop	@b
237
	loop	@b
Line 194... Line 238...
194
 
238
 
195
	; we have resend buffer location in esi
239
	; we have resend buffer location in esi
196
	mov	ecx, IPBUFFSIZE
240
;        mov     ecx, IPBUFFSIZE
197
 
241
 
198
	; copy data across
242
	; copy data across
Line 199... Line 243...
199
	push	edi
243
	push	edi
200
	cld
244
	cld
201
	rep	movsb
245
	rep	movsb
202
	pop	edi
246
	pop	edi
203
 
247
 
204
	; queue Packet
248
	; queue Packet
Line 205... Line 249...
205
	mov	eax, NET1OUT_QUEUE
249
;        mov     eax, NET1OUT_QUEUE
206
	mov	edx, [IP_LIST]
250
;        mov     edx, [IP_LIST]
207
	cmp	edx, [edi + IP_Packet.DestinationAddress]
251
;        cmp     edx, [edi + IP_Packet.DestinationAddress]
Line 208... Line 252...
208
	jne	.not_local
252
;        jne     .not_local
209
	mov	eax, IPIN_QUEUE
253
;        mov     eax, IPIN_QUEUE
Line 210... Line 254...
210
 
254
 
211
  .not_local:
255
  .not_local:
212
	pop	ebx
256
	pop	ebx
Line 213... Line 257...
213
	call	queue
257
;        call    queue
214
 
258
 
215
  .tth005:
-
 
Line -... Line 259...
-
 
259
  .tth005:
216
	popad
260
	popad
217
 
-
 
218
	inc	ecx
-
 
219
	add	esi, 8
261
 
220
	jmp	.next_resendq
-
 
221
 
262
	inc	ecx
222
  .exit:
-
 
223
	ret
-
 
224
endp
-
 
225
 
-
 
226
 
263
	add	esi, 8
-
 
264
	jmp	.next_resendq
227
;***************************************************************************
265
 
-
 
266
  .exit:
-
 
267
	ret
-
 
268
 
-
 
269
 
-
 
270
 
-
 
271
;-----------------------------------------------------------------
-
 
272
;
-
 
273
; TCP_Handler:
-
 
274
;
-
 
275
;  Called by IPv4_handler,
Line 228... Line -...
228
;   Function
-
 
229
;      tcp_rx
-
 
230
;
-
 
231
;   Description
-
 
232
;       TCP protocol handler
-
 
233
;       This is a kernel function, called by ip_rx
276
;  this procedure will inject the tcp data diagrams in the application sockets.
234
;       IP buffer address given in edx
-
 
235
;          IP buffer number in eax
-
 
236
;          Free up (or re-use) IP buffer when finished
-
 
237
;
-
 
238
;***************************************************************************
-
 
Line -... Line 277...
-
 
277
;
-
 
278
;  IN:  Pointer to buffer in [esp]
-
 
279
;       size of buffer in [esp+4]
239
 
280
;       pointer to device struct in ebx
Line 240... Line 281...
240
proc tcp_rx stdcall uses ebx
281
;       TCP Packet size in ecx
241
	; The process is as follows.
282
;       pointer to TCP Packet data in edx
242
	; Look for a socket with matching remote IP, remote port, local port
283
;       SourceAddres in esi
243
	; if not found, then
284
;  OUT: /
Line 263... Line 304...
263
	or	ebx, ebx
304
	or	ebx, ebx
264
	jz	.next_socket.1.exit
305
	jz	.next_socket.1.exit
Line 265... Line 306...
265
 
306
 
Line 266... Line 307...
266
;        DEBUGF  1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
307
;        DEBUGF  1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
267
 
308
 
268
	mov	ax, [edx + 20 + TCP_Packet.DestinationPort]  ; get the dest. port from the TCP hdr
309
	mov	ax, [edx + TCP_Packet.DestinationPort]	; get the dest. port from the TCP hdr
Line 269... Line 310...
269
	cmp	[ebx + SOCKET.LocalPort], ax		; get the dest. port from the TCP hdr
310
	cmp	[ebx + SOCKET.LocalPort], ax		; get the dest. port from the TCP hdr
Line 270... Line 311...
270
	jne	.next_socket.1				; different - try next socket
311
	jne	.next_socket.1				; different - try next socket
271
 
312
 
272
;        DEBUGF  1, "K : tcp_rx - 1.addr: %x - %x\n", [edx + IP_Packet.SourceAddress], [ebx + SOCKET.RemoteIP]
313
;        DEBUGF  1, "K : tcp_rx - 1.addr: %x - %x\n", [edx + IP_Packet.SourceAddress], [ebx + SOCKET.RemoteIP]
Line 273... Line 314...
273
 
314
 
Line 274... Line 315...
274
	mov	eax, [edx + IP_Packet.SourceAddress]	; get the source IP Addr from the IP hdr
315
	mov	eax, esi ;[edx + IP_Packet.SourceAddress]    ; get the source IP Addr from the IP hdr
275
	cmp	[ebx + SOCKET.RemoteIP], eax		; compare with socket's remote IP
316
	cmp	[ebx + SOCKET.RemoteIP], eax		; compare with socket's remote IP
276
	jne	.next_socket.1				; different - try next socket
317
	jne	.next_socket.1				; different - try next socket
Line 277... Line 318...
277
 
318
 
278
;        DEBUGF  1, "K : tcp_rx - 1.sport: %x - %x\n", [edx + 20 + TCP_Packet.SourcePort]:4, [ebx + SOCKET.RemotePort]:4
319
;        DEBUGF  1, "K : tcp_rx - 1.sport: %x - %x\n", [edx + 20 + TCP_Packet.SourcePort]:4, [ebx + SOCKET.RemotePort]:4
Line 299... Line 340...
299
	or	ebx, ebx
340
	or	ebx, ebx
300
	jz	.next_socket.2.exit
341
	jz	.next_socket.2.exit
Line 301... Line 342...
301
 
342
 
Line 302... Line 343...
302
;        DEBUGF  1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
343
;        DEBUGF  1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
303
 
344
 
304
	mov	ax, [edx + 20 + TCP_Packet.DestinationPort]  ; get the dest. port from the TCP hdr
345
	mov	ax, [edx + TCP_Packet.DestinationPort]	; get the dest. port from the TCP hdr
Line 305... Line 346...
305
	cmp	[ebx + SOCKET.LocalPort], ax		; compare with socket's local port
346
	cmp	[ebx + SOCKET.LocalPort], ax		; compare with socket's local port
Line 306... Line 347...
306
	jne	.next_socket.2				; different - try next socket
347
	jne	.next_socket.2				; different - try next socket
307
 
348
 
308
;        DEBUGF  1, "K : tcp_rx - 2.addr: %x - %x\n", [edx + IP_Packet.SourceAddress], [ebx + SOCKET.RemoteIP]
349
;        DEBUGF  1, "K : tcp_rx - 2.addr: %x - %x\n", [edx + IP_Packet.SourceAddress], [ebx + SOCKET.RemoteIP]
Line 309... Line 350...
309
 
350
 
Line 310... Line 351...
310
	mov	eax, [edx + IP_Packet.SourceAddress]	; get the source IP Addr from the IP hdr
351
;        mov     eax, esi ;[edx + IP_Packet.SourceAddress]    ; get the source IP Addr from the IP hdr
Line 334... Line 375...
334
	or	ebx, ebx
375
	or	ebx, ebx
335
	jz	.next_socket.3.exit
376
	jz	.next_socket.3.exit
Line 336... Line 377...
336
 
377
 
Line 337... Line 378...
337
;        DEBUGF  1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
378
;        DEBUGF  1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4
338
 
379
 
339
	mov	ax, [edx + 20 + TCP_Packet.DestinationPort]  ; get destination port from the TCP hdr
380
	mov	ax, [edx + TCP_Packet.DestinationPort]	; get destination port from the TCP hdr
Line 340... Line 381...
340
	cmp	[ebx + SOCKET.LocalPort], ax		; compare with socket's local port
381
	cmp	[ebx + SOCKET.LocalPort], ax		; compare with socket's local port
Line 356... Line 397...
356
  .next_socket.3.exit:
397
  .next_socket.3.exit:
Line 357... Line 398...
357
 
398
 
Line 358... Line 399...
358
	; If we got here, we need to reject the Packet
399
	; If we got here, we need to reject the Packet
359
 
400
 
Line 360... Line 401...
360
	DEBUGF	1, "K : tcp_rx - dumped\n"
401
	DEBUGF	1, "K : tcp_rx - dumped\n"
361
	DEBUGF	1, "K :   --------: %x-%x-%x (flags: %x)\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [edx + IP_Packet.SourceAddress], [edx + 20 + TCP_Packet.SourcePort]:4, [edx + 20 + TCP_Packet.Flags]:2
402
;        DEBUGF  1, "K :   --------: %x-%x-%x (flags: %x)\n", [edx + 20 + TCP_Packet.DestinationPort]:4, [edx + IP_Packet.SourceAddress], [edx + 20 + TCP_Packet.SourcePort]:4, [edx + 20 + TCP_Packet.Flags]:2
Line 362... Line 403...
362
 
403
 
Line 363... Line 404...
363
	inc	[dumped_rx_count]
404
;        inc     [dumped_rx_count]
Line 371... Line 412...
371
	; IP buffer number is on stack ( it will be popped at the end)
412
	; IP buffer number is on stack ( it will be popped at the end)
Line 372... Line 413...
372
 
413
 
Line 373... Line 414...
373
	stdcall tcpStateMachine, ebx
414
	stdcall tcpStateMachine, ebx
374
 
415
 
375
  .exit:
416
  .exit:
-
 
417
 
-
 
418
	call	kernel_free
376
	pop	eax
419
	add	esp, 4 ; pop (balance stack)
377
	call	freeBuff
-
 
Line -... Line 420...
-
 
420
 
-
 
421
ret
-
 
422
 
-
 
423
 
-
 
424
 
-
 
425
;-----------------------------------------------------------------
-
 
426
;
-
 
427
; IN: eax = dest ip
-
 
428
;     ebx = source ip
-
 
429
;     ecx = data length
-
 
430
;     edx = remote port shl 16 + local port
-
 
431
;     esi = data offset
-
 
432
;
-
 
433
;-----------------------------------------------------------------
378
	ret
434
 
379
endp
435
TCP_create_Packet:
380
 
436
 
381
 
437
	DEBUGF 1,"Create TCP Packet\n"
382
;***************************************************************************
438
;***************************************************************************
Line 392... Line 448...
392
;       Data length in ecx
448
;       Data length in ecx
393
;          Transmit buffer number in eax
449
;          Transmit buffer number in eax
394
;
450
;
395
;***************************************************************************
451
;***************************************************************************
Line 396... Line -...
396
 
-
 
397
proc build_tcp_Packet stdcall, sockAddr:DWORD
452
 
Line 398... Line -...
398
	push	ecx			   ; Save data length
-
 
399
 
453
	push	ecx			   ; Save data length
400
	; convert buffer pointer eax to the absolute address
-
 
401
	mov	ecx, IPBUFFSIZE
454
 
Line -... Line 455...
-
 
455
	add	ecx, UDP_Packet.Data
-
 
456
	mov	di , IP_PROTO_UDP
-
 
457
 
402
	mul	ecx
458
;       dx  = fragment id
-
 
459
 
Line 403... Line 460...
403
	add	eax, IPbuffs
460
	call	IPv4_create_Packet				; TODO: figure out a way to choose between IPv4 and IPv6
Line 404... Line 461...
404
 
461
	cmp	edi, -1
Line 405... Line 462...
405
	mov	edx, eax
462
	je	.exit
Line 406... Line 463...
406
 
463
 
407
	mov	[edx + 20 + TCP_Packet.Flags], bl		; TCP flags
464
	mov	[edi + TCP_Packet.Flags], bl		   ; TCP flags
408
 
465
 
409
	mov	ebx, [sockAddr]
466
;        mov     ebx, [sockAddr];---------------------------------------------------------- eof
410
 
467
 
Line 411... Line 468...
411
	; So, ebx holds the socket ptr, edx holds the IPbuffer ptr
468
	; So, ebx holds the socket ptr, edx holds the IPbuffer ptr
412
 
469
 
Line 413... Line 470...
413
	; Fill in the IP header ( some data is in the socket descriptor)
470
	; Fill in the IP header ( some data is in the socket descriptor)
414
	mov	eax, [ebx + SOCKET.LocalIP]
471
	mov	eax, [ebx + SOCKET.LocalIP]
Line 415... Line 472...
415
	mov	[edx + IP_Packet.SourceAddress], eax
472
;        mov     [edx + IP_Packet.SourceAddress], eax
416
	mov	eax, [ebx + SOCKET.RemoteIP]
473
	mov	eax, [ebx + SOCKET.RemoteIP]
417
	mov	[edx + IP_Packet.DestinationAddress], eax
474
;        mov     [edx + IP_Packet.DestinationAddress], eax
418
 
475
 
419
	mov	[edx + IP_Packet.VersionAndIHL], 0x45
476
;        mov     [edx + IP_Packet.VersionAndIHL], 0x45
420
	mov	[edx + IP_Packet.TypeOfService], 0
477
;        mov     [edx + IP_Packet.TypeOfService], 0
421
 
478
 
Line 422... Line 479...
422
	pop	eax		      ; Get the TCP data length
479
	pop	eax		      ; Get the TCP data length
423
	push	eax
480
	push	eax
Line 424... Line 481...
424
 
481
 
425
	add	eax, 20 + 20	       ; add IP header and TCP header lengths
482
	add	eax, 20 + 20	       ; add IP header and TCP header lengths
426
	rol	ax, 8
483
	rol	ax, 8
Line 473... Line 530...
473
	rep	movsb		    ; copy the data across
530
	rep	movsb		    ; copy the data across
Line 474... Line 531...
474
 
531
 
475
    @@: ; we have edx as IPbuffer ptr.
532
    @@: ; we have edx as IPbuffer ptr.
476
	; Fill in the TCP checksum
533
	; Fill in the TCP checksum
477
	; First, fill in pseudoheader
534
	; First, fill in pseudoheader
478
	mov	eax, [edx + IP_Packet.SourceAddress]
535
;        mov     eax, [edx + IP_Packet.SourceAddress]
479
	mov	[pseudoHeader], eax
536
;        mov     [pseudoHeader], eax
480
	mov	eax, [edx + IP_Packet.DestinationAddress]
537
;        mov     eax, [edx + IP_Packet.DestinationAddress]
481
	mov	[pseudoHeader + 4], eax
538
;        mov     [pseudoHeader + 4], eax
482
	mov	word[pseudoHeader + 8], PROTOCOL_TCP shl 8 + 0
539
;        mov     word[pseudoHeader + 8], PROTOCOL_TCP shl 8 + 0
483
	add	ebx, 20
540
;        add     ebx, 20
484
	mov	[pseudoHeader + 10], bh
541
;        mov     [pseudoHeader + 10], bh
485
	mov	[pseudoHeader + 11], bl
542
;        mov     [pseudoHeader + 11], bl
486
 
543
;
487
	mov	eax, pseudoHeader
544
;        mov     eax, pseudoHeader
488
	mov	[checkAdd1], eax
545
;        mov     [checkAdd1], eax
489
	mov	word[checkSize1], 12
546
;        mov     word[checkSize1], 12
490
	mov	eax, edx
547
;        mov     eax, edx
491
	add	eax, 20
548
;        add     eax, 20
492
	mov	[checkAdd2], eax
549
;        mov     [checkAdd2], eax
493
	mov	eax, ebx
550
;        mov     eax, ebx
494
	mov	[checkSize2], ax
551
;        mov     [checkSize2], ax
495
 
552
;
Line 496... Line 553...
496
	call	checksum
553
;        call    checksum
497
 
554
 
498
	; store it in the TCP checksum ( in the correct order! )
555
	; store it in the TCP checksum ( in the correct order! )
499
	mov	ax, [checkResult]
556
;        mov     ax, [checkResult]
Line 500... Line 557...
500
	rol	ax, 8
557
;        rol     ax, 8
501
	mov	[edx + 20 + TCP_Packet.Checksum], ax
558
;        mov     [edx + 20 + TCP_Packet.Checksum], ax
502
 
559
 
503
	; Fill in the IP header checksum
560
	; Fill in the IP header checksum
504
    movzx   eax, byte [edx + IP_Packet.VersionAndIHL]  ; Calculate Header length by using IHL field
561
;    movzx   eax, byte [edx + IP_Packet.VersionAndIHL]  ; Calculate Header length by using IHL field
505
    and     eax, 0x0000000F  ;
562
;    and     eax, 0x0000000F  ;
506
    shl     eax, 2	     ;
563
;    shl     eax, 2           ;
507
 
564
;
-
 
565
	stdcall checksum_jb, edx, eax  ; buf_ptr, buf_size
-
 
566
	rol	ax, 8
-
 
567
;        mov     [edx + IP_Packet.HeaderChecksum], ax
-
 
568
 
-
 
569
 
-
 
570
       .exit:
Line 508... Line 571...
508
	stdcall checksum_jb, edx, eax  ; buf_ptr, buf_size
571
 
509
	rol	ax, 8
572
	call	kernel_free
Line 510... Line 573...
510
	mov	[edx + IP_Packet.HeaderChecksum], ax
573
	add	esp, 4 ; pop (balance stack)
511
 
574
 
512
	ret
575
	ret
513
endp
576
;endp
514
 
577
 
515
 
578
 
516
; Increments the 32 bit value pointed to by esi in internet order
579
; Increments the 32 bit value pointed to by esi in internet order
517
proc inc_inet_esi stdcall
580
proc inc_inet_esi stdcall
518
	push	eax
581
;        push    eax
519
	mov	eax, [esi]
582
;        mov     eax, [esi]
-
 
583
;        bswap   eax
-
 
584
;        inc     eax
-
 
585
;        bswap   eax
-
 
586
;        mov     [esi], eax
520
	bswap	eax
587
;        pop     eax
Line 521... Line 588...
521
	inc	eax
588
;        ret
522
	bswap	eax
589
	inc	byte[esi+0]
Line 589... Line 656...
589
 
656
 
590
	mov	esi, resendQ
657
	mov	esi, resendQ
Line 591... Line 658...
591
	xor	ecx, ecx
658
	xor	ecx, ecx
592
 
659
 
593
  .next_resendq:
660
  .next_resendq:
594
	cmp	ecx, NUMRESENDENTRIES
661
;        cmp     ecx, NUMRESENDENTRIES
595
	je	.call_handler	  ; None left
662
	je	.call_handler	  ; None left
596
	cmp	[esi + 4], eax
663
	cmp	[esi + 4], eax
597
	je	@f		  ; found one
664
	je	@f		  ; found one
Line 604... Line 671...
604
			  ; If yes, goto @@. No, goto .next_resendq
671
			  ; If yes, goto @@. No, goto .next_resendq
605
	; Get Packet data address
672
	; Get Packet data address
Line 606... Line 673...
606
 
673
 
607
	push	ecx
674
	push	ecx
608
	; Now get buffer location, and copy buffer across. argh! more copying,,
675
	; Now get buffer location, and copy buffer across. argh! more copying,,
609
	imul	edi, ecx, IPBUFFSIZE
676
;        imul    edi, ecx, IPBUFFSIZE
Line 610... Line 677...
610
	add	edi, resendBuffer
677
;        add     edi, resendBuffer
611
 
678
 
612
	; we have dest buffer location in edi. incoming Packet in edx.
679
	; we have dest buffer location in edi. incoming Packet in edx.
613
	; Get this Packets sequence number
680
	; Get this Packets sequence number
Line 666... Line 733...
666
	jz	.exit
733
	jz	.exit
Line 667... Line 734...
667
 
734
 
668
	; We have a SYN. update the socket with this IP Packets details,
735
	; We have a SYN. update the socket with this IP Packets details,
Line 669... Line 736...
669
	; And send a response
736
	; And send a response
670
 
737
 
671
	mov	eax, [edx + IP_Packet.SourceAddress]
738
;        mov     eax, [edx + IP_Packet.SourceAddress]
672
	mov	[ebx + SOCKET.RemoteIP], eax
739
 ;       mov     [ebx + SOCKET.RemoteIP], eax
673
	mov	ax, [edx + 20 + TCP_Packet.SourcePort]
740
;        mov     ax, [edx + 20 + TCP_Packet.SourcePort]
674
	mov	[ebx + SOCKET.RemotePort], ax
741
;        mov     [ebx + SOCKET.RemotePort], ax
675
	mov	eax, [edx + 20 + TCP_Packet.SequenceNumber]
742
;        mov     eax, [edx + 20 + TCP_Packet.SequenceNumber]
676
	mov	[ebx + SOCKET.IRS], eax
743
;        mov     [ebx + SOCKET.IRS], eax
677
	mov	[ebx + SOCKET.RCV_NXT], eax
744
;        mov     [ebx + SOCKET.RCV_NXT], eax
678
	lea	esi, [ebx + SOCKET.RCV_NXT]
745
;        lea     esi, [ebx + SOCKET.RCV_NXT]
679
	call	inc_inet_esi ; RCV.NXT
746
;        call    inc_inet_esi ; RCV.NXT
680
	mov	eax, [ebx + SOCKET.ISS]
747
;        mov     eax, [ebx + SOCKET.ISS]
681
	mov	[ebx + SOCKET.SND_NXT], eax
748
;        mov     [ebx + SOCKET.SND_NXT], eax
682
 
749
;
683
	; Now construct the response, and queue for sending by IP
750
	; Now construct the response, and queue for sending by IP
684
	mov	eax, EMPTY_QUEUE
751
;        mov     eax, EMPTY_QUEUE
685
	call	dequeue
752
;        call    dequeue
Line 686... Line 753...
686
	cmp	ax, NO_BUFFER
753
;        cmp     ax, NO_BUFFER
687
	je	.exit
754
 ;       je      .exit
688
 
755
 
689
	push	eax
756
	push	eax
690
	mov	bl, TH_SYN + TH_ACK
757
	mov	bl, TH_SYN + TH_ACK
Line 691... Line 758...
691
	xor	ecx, ecx
758
	xor	ecx, ecx
692
	xor	esi, esi
759
	xor	esi, esi
693
	stdcall build_tcp_Packet, [sockAddr]
760
;        stdcall build_tcp_Packet, [sockAddr]
694
 
761
 
695
	mov	eax, NET1OUT_QUEUE
762
;        mov     eax, NET1OUT_QUEUE
696
;;;        mov     edx, [stack_ip]
763
;;;        mov     edx, [stack_ip]
Line 697... Line 764...
697
	mov	ecx, [sockAddr]
764
	mov	ecx, [sockAddr]
698
	cmp	edx, [ecx + SOCKET.RemoteIP]
765
	cmp	edx, [ecx + SOCKET.RemoteIP]
699
	jne	.not_local
766
	jne	.not_local
700
	mov	eax, IPIN_QUEUE
767
;        mov     eax, IPIN_QUEUE
Line 701... Line 768...
701
 
768
 
702
  .not_local:
769
  .not_local:
Line 703... Line 770...
703
	; Send it.
770
	; Send it.
Line 745... Line 812...
745
	lea	esi, [ebx + SOCKET.RCV_NXT]
812
	lea	esi, [ebx + SOCKET.RCV_NXT]
746
	call	inc_inet_esi
813
	call	inc_inet_esi
Line 747... Line 814...
747
 
814
 
748
	; Send an ACK
815
	; Send an ACK
749
	; Now construct the response, and queue for sending by IP
816
	; Now construct the response, and queue for sending by IP
750
	mov	eax, EMPTY_QUEUE
817
;        mov     eax, EMPTY_QUEUE
751
	call	dequeue
818
;        call    dequeue
752
	cmp	ax, NO_BUFFER
819
 ;       cmp     ax, NO_BUFFER
753
	pop	ebx
820
	pop	ebx
Line 754... Line 821...
754
	je	.exit
821
	je	.exit
Line 755... Line 822...
755
 
822
 
756
	push	eax
823
	push	eax
757
 
824
 
Line 758... Line 825...
758
	xor	ecx, ecx
825
	xor	ecx, ecx
759
	xor	esi, esi
826
	xor	esi, esi
760
	stdcall build_tcp_Packet, [sockAddr]
827
;        stdcall build_tcp_Packet, [sockAddr]
761
 
828
 
762
	mov	eax, NET1OUT_QUEUE
829
;        mov     eax, NET1OUT_QUEUE
763
;;;        mov     edx, [stack_ip]
830
;;;        mov     edx, [stack_ip]
Line 764... Line 831...
764
	mov	ecx, [sockAddr]
831
;        mov     ecx, [sockAddr]
765
	cmp	edx, [ecx + SOCKET.RemoteIP]
832
 ;       cmp     edx, [ecx + SOCKET.RemoteIP]
766
	jne	.not_local
833
  ;      jne     .not_local
767
	mov	eax, IPIN_QUEUE
834
   ;     mov     eax, IPIN_QUEUE
Line 768... Line 835...
768
 
835
 
769
  .not_local:
836
  .not_local:
770
	; Send it.
837
	; Send it.
Line 820... Line 887...
820
 
887
 
821
	mov	esi, resendQ
888
	mov	esi, resendQ
Line 822... Line 889...
822
	mov	ecx, 0
889
	mov	ecx, 0
823
 
890
 
824
  .next_resendq:
891
  .next_resendq:
825
	cmp	ecx, NUMRESENDENTRIES
892
;        cmp     ecx, NUMRESENDENTRIES
826
	je	.last_resendq	    ; None left
893
;        je      .last_resendq       ; None left
827
	cmp	[esi + 4], eax
894
;        cmp     [esi + 4], eax
828
	je	@f		    ; found one
895
;        je      @f                  ; found one
829
	inc	ecx
896
;        inc     ecx
Line 830... Line 897...
830
	add	esi, 8
897
;        add     esi, 8
831
	jmp	.next_resendq
898
;        jmp     .next_resendq
832
 
899
 
833
    @@: mov	dword[esi + 4], 0
900
    @@: mov	dword[esi + 4], 0
Line 879... Line 946...
879
    @@: cmp	ecx, [edx + 20 + TCP_Packet.SequenceNumber]
946
    @@: cmp	ecx, [edx + 20 + TCP_Packet.SequenceNumber]
880
	jne	.ack
947
	jne	.ack
Line 881... Line 948...
881
 
948
 
882
 
949
 
883
	; Read the data bytes, store in socket buffer
950
	; Read the data bytes, store in socket buffer
884
	movzx	ecx, [edx + IP_Packet.TotalLength]
951
;        movzx   ecx, [edx + IP_Packet.TotalLength]
885
	xchg	cl, ch
952
	xchg	cl, ch
Line 886... Line 953...
886
	sub	ecx, 40 		   ; Discard 40 bytes of header
953
	sub	ecx, 40 		   ; Discard 40 bytes of header
Line 941... Line 1008...
941
	call	add_inet_esi
1008
	call	add_inet_esi
Line 942... Line 1009...
942
 
1009
 
943
  .ack:
1010
  .ack:
944
	; Send an ACK
1011
	; Send an ACK
945
	; Now construct the response, and queue for sending by IP
1012
	; Now construct the response, and queue for sending by IP
946
	mov	eax, EMPTY_QUEUE
1013
;        mov     eax, EMPTY_QUEUE
947
	call	dequeue
1014
;        call    dequeue
948
	cmp	ax, NO_BUFFER
1015
;        cmp     ax, NO_BUFFER
Line 949... Line 1016...
949
	je	.exit
1016
	je	.exit
Line 950... Line 1017...
950
 
1017
 
951
	push	eax
1018
	push	eax
952
 
1019
 
953
	mov	bl, TH_ACK
1020
	mov	bl, TH_ACK
Line 954... Line 1021...
954
	xor	ecx, ecx
1021
	xor	ecx, ecx
Line 955... Line 1022...
955
	xor	esi, esi
1022
	xor	esi, esi
956
	stdcall build_tcp_Packet, [sockAddr]
1023
;        stdcall build_tcp_Packet, [sockAddr]
957
 
1024
 
958
	mov	eax, NET1OUT_QUEUE
1025
;        mov     eax, NET1OUT_QUEUE
959
 
1026
 
Line 960... Line 1027...
960
;;;        mov     edx, [stack_ip]
1027
;;;        mov     edx, [stack_ip]
961
	mov	ecx, [sockAddr]
1028
;        mov     ecx, [sockAddr]
962
	cmp	edx, [ecx + SOCKET.RemoteIP]
1029
;        cmp     edx, [ecx + SOCKET.RemoteIP]
963
	jne	.not_local
1030
;        jne     .not_local
Line 964... Line 1031...
964
	mov	eax, IPIN_QUEUE
1031
 ;       mov     eax, IPIN_QUEUE
965
 
1032
 
966
  .not_local:
1033
  .not_local:
967
	; Send it.
1034
	; Send it.
Line 998... Line 1065...
998
 
1065
 
999
    @@: lea	esi, [ebx + SOCKET.RCV_NXT]
1066
    @@: lea	esi, [ebx + SOCKET.RCV_NXT]
Line 1000... Line 1067...
1000
	call	inc_inet_esi
1067
	call	inc_inet_esi
1001
 
1068
 
1002
	; Send an ACK
1069
	; Send an ACK
1003
	mov	eax, EMPTY_QUEUE
1070
;        mov     eax, EMPTY_QUEUE
1004
	call	dequeue
1071
;        call    dequeue
Line 1005... Line 1072...
1005
	cmp	ax, NO_BUFFER
1072
;        cmp     ax, NO_BUFFER
Line 1006... Line 1073...
1006
	je	.exit
1073
	je	.exit
1007
 
1074
 
1008
	push	eax
1075
	push	eax
1009
 
1076
 
Line 1010... Line 1077...
1010
	mov	bl, TH_ACK
1077
	mov	bl, TH_ACK
1011
	xor	ecx, ecx
1078
	xor	ecx, ecx
1012
	xor	esi, esi
1079
	xor	esi, esi
1013
	stdcall build_tcp_Packet, [sockAddr]
1080
;        stdcall build_tcp_Packet, [sockAddr]
1014
 
1081
 
1015
	mov	eax, NET1OUT_QUEUE
1082
;        mov     eax, NET1OUT_QUEUE
Line 1016... Line 1083...
1016
;;;        mov     edx, [stack_ip]
1083
;;;        mov     edx, [stack_ip]
1017
	mov	ecx, [sockAddr]
1084
;        mov     ecx, [sockAddr]
1018
	cmp	edx, [ecx + SOCKET.RemoteIP]
1085
 ;       cmp     edx, [ecx + SOCKET.RemoteIP]
1019
	jne	.not_local
1086
 ;       jne     .not_local
Line 1020... Line 1087...
1020
	mov	eax, IPIN_QUEUE
1087
;        mov     eax, IPIN_QUEUE
1021
 
1088
 
1022
  .not_local:
1089
  .not_local:
Line 1038... Line 1105...
1038
 
1105
 
1039
	lea	esi, [ebx + SOCKET.RCV_NXT]
1106
	lea	esi, [ebx + SOCKET.RCV_NXT]
Line 1040... Line 1107...
1040
	call	inc_inet_esi
1107
	call	inc_inet_esi
1041
 
1108
 
1042
	; Send an ACK
1109
	; Send an ACK
1043
	mov	eax, EMPTY_QUEUE
1110
;        mov     eax, EMPTY_QUEUE
1044
	call	dequeue
1111
;        call    dequeue
Line 1045... Line 1112...
1045
	cmp	ax, NO_BUFFER
1112
 ;;       cmp     ax, NO_BUFFER
Line 1046... Line 1113...
1046
	je	.exit
1113
  ;      je      .exit
1047
 
1114
 
1048
	push	eax
1115
	push	eax
1049
 
1116
 
Line 1050... Line 1117...
1050
	mov	bl, TH_ACK
1117
	mov	bl, TH_ACK
1051
	xor	ecx, ecx
1118
	xor	ecx, ecx
1052
	xor	esi, esi
1119
	xor	esi, esi
1053
	stdcall build_tcp_Packet, [sockAddr]
1120
;        stdcall build_tcp_Packet, [sockAddr]
1054
 
1121
 
1055
	mov	eax, NET1OUT_QUEUE
1122
;        mov     eax, NET1OUT_QUEUE
Line 1056... Line 1123...
1056
;;;        mov     edx, [stack_ip]
1123
;;;        mov     edx, [stack_ip]
1057
	mov	ecx, [sockAddr]
1124
	mov	ecx, [sockAddr]
1058
	cmp	edx, [ecx + SOCKET.RemoteIP]
1125
	cmp	edx, [ecx + SOCKET.RemoteIP]
1059
	jne	.not_local
1126
	jne	.not_local
Line 1060... Line 1127...
1060
	mov	eax, IPIN_QUEUE
1127
;        mov     eax, IPIN_QUEUE
1061
 
1128
 
1062
  .not_local:
1129
  .not_local:
Line 1117... Line 1184...
1117
; @param EBX is socket number
1184
; @param EBX is socket number
1118
; @param ECX is application data size (number of bytes to send)
1185
; @param ECX is application data size (number of bytes to send)
1119
; @param EDX is pointer to application data buffer
1186
; @param EDX is pointer to application data buffer
1120
; @return 0 (sent successfully) or -1 (error) in EAX
1187
; @return 0 (sent successfully) or -1 (error) in EAX
1121
;;
1188
;;
1122
proc socket_write_tcp stdcall
1189
;proc socket_write_tcp stdcall
1123
local sockAddr dd ?
1190
;local sockAddr dd ?
Line 1124... Line 1191...
1124
 
1191
 
1125
;        DEBUGF  1, "socket_write_tcp(0x%x)\n", ebx
1192
;        DEBUGF  1, "socket_write_tcp(0x%x)\n", ebx
1126
	stdcall net_socket_num_to_addr, ebx
1193
	stdcall net_socket_num_to_addr, ebx
1127
	or	eax, eax
1194
	or	eax, eax
Line 1128... Line 1195...
1128
	jz	.error
1195
	jz	.error
1129
 
1196
 
Line 1130... Line 1197...
1130
	mov	ebx, eax
1197
	mov	ebx, eax
1131
	mov	[sockAddr], ebx
1198
;        mov     [sockAddr], ebx
1132
 
1199
 
Line 1133... Line 1200...
1133
	; If the sockets window timer is nonzero, do not queue Packet
1200
	; If the sockets window timer is nonzero, do not queue Packet
1134
	cmp	[ebx + SOCKET.wndsizeTimer], 0
1201
	cmp	[ebx + SOCKET.wndsizeTimer], 0
1135
	jne	.error
1202
	jne	.error
1136
 
1203
 
Line 1137... Line 1204...
1137
	mov	eax, EMPTY_QUEUE
1204
;        mov     eax, EMPTY_QUEUE
Line 1138... Line 1205...
1138
	call	dequeue
1205
;        call    dequeue
1139
	cmp	ax, NO_BUFFER
1206
;        cmp     ax, NO_BUFFER
Line 1150... Line 1217...
1150
	pop	eax
1217
	pop	eax
1151
	push	eax
1218
	push	eax
Line 1152... Line 1219...
1152
 
1219
 
1153
	push	ecx
1220
	push	ecx
1154
	mov	bl, TH_ACK
1221
	mov	bl, TH_ACK
1155
	stdcall build_tcp_Packet, [sockAddr]
1222
;        stdcall build_tcp_Packet, [sockAddr]
Line 1156... Line 1223...
1156
	pop	ecx
1223
	pop	ecx
1157
 
1224
 
Line 1158... Line 1225...
1158
	; Check destination IP address.
1225
	; Check destination IP address.
1159
	; If it is the local host IP, route it back to IP_RX
1226
	; If it is the local host IP, route it back to IP_RX
Line 1160... Line 1227...
1160
 
1227
 
1161
	pop	ebx
1228
	pop	ebx
1162
	push	ecx
1229
	push	ecx
Line 1163... Line 1230...
1163
 
1230
 
1164
	mov	eax, NET1OUT_QUEUE
1231
;        mov     eax, NET1OUT_QUEUE
1165
;;; TODO: get device id in edx
1232
;;; TODO: get device id in edx
1166
	xor	edx, edx
1233
	xor	edx, edx
1167
 
1234
 
1168
	shl	edx, 2
1235
	shl	edx, 2
Line 1169... Line 1236...
1169
	mov	edx, [IP_LIST+edx]
1236
	mov	edx, [IP_LIST+edx]
1170
	mov	ecx, [sockAddr]
1237
;        mov     ecx, [sockAddr]
1171
	cmp	edx, [ecx + SOCKET.RemoteIP]
1238
 ;       cmp     edx, [ecx + SOCKET.RemoteIP]
Line 1172... Line 1239...
1172
	jne	.not_local
1239
  ;      jne     .not_local
Line 1173... Line 1240...
1173
	mov	eax, IPIN_QUEUE
1240
   ;     mov     eax, IPIN_QUEUE
Line 1174... Line 1241...
1174
 
1241
 
1175
  .not_local:
1242
  .not_local:
1176
	pop	ecx
1243
	pop	ecx
1177
	push	ebx		    ; save ipbuffer number
1244
	push	ebx		    ; save ipbuffer number
Line 1191... Line 1258...
1191
	; If there isn't one, dont worry about it for now
1258
	; If there isn't one, dont worry about it for now
1192
	mov	esi, resendQ
1259
	mov	esi, resendQ
1193
	mov	ecx, 0
1260
	mov	ecx, 0
Line 1194... Line 1261...
1194
 
1261
 
1195
  .next_resendq:
1262
  .next_resendq:
1196
	cmp	ecx, NUMRESENDENTRIES
1263
;        cmp     ecx, NUMRESENDENTRIES
1197
	je	.exit		   ; None found
1264
	je	.exit		   ; None found
1198
	cmp	dword[esi + 4], 0
1265
	cmp	dword[esi + 4], 0
1199
	je	@f		   ; found one
1266
	je	@f		   ; found one
1200
	inc	ecx
1267
	inc	ecx
Line 1209... Line 1276...
1209
	;  socket #
1276
	;  socket #
1210
	;  retries count
1277
	;  retries count
1211
	;  retry time
1278
	;  retry time
1212
	;  fill IP buffer associated with this descriptor
1279
	;  fill IP buffer associated with this descriptor
Line 1213... Line 1280...
1213
 
1280
 
1214
	stdcall net_socket_addr_to_num, [sockAddr]
1281
;        stdcall net_socket_addr_to_num, [sockAddr]
1215
	mov	[esi + 4], eax
1282
	mov	[esi + 4], eax
1216
	mov	byte[esi + 1], TCP_RETRIES
1283
	mov	byte[esi + 1], TCP_RETRIES
Line 1217... Line 1284...
1217
	mov	word[esi + 2], TCP_TIMEOUT
1284
	mov	word[esi + 2], TCP_TIMEOUT
1218
 
1285
 
1219
	inc	ecx
1286
	inc	ecx
Line 1220... Line 1287...
1220
	; Now get buffer location, and copy buffer across. argh! more copying,,
1287
	; Now get buffer location, and copy buffer across. argh! more copying,,
1221
	mov	edi, resendBuffer - IPBUFFSIZE
1288
;        mov     edi, resendBuffer - IPBUFFSIZE
Line 1222... Line 1289...
1222
 
1289
 
1223
    @@: add	edi, IPBUFFSIZE
1290
;    @@: add     edi, IPBUFFSIZE
1224
	loop	@b
1291
	loop	@b
1225
 
1292
 
1226
	; we have dest buffer location in edi
1293
	; we have dest buffer location in edi
1227
	pop	eax
1294
	pop	eax
1228
	; convert source buffer pointer eax to the absolute address
1295
	; convert source buffer pointer eax to the absolute address
Line 1229... Line 1296...
1229
	mov	ecx, IPBUFFSIZE
1296
;        mov     ecx, IPBUFFSIZE
1230
	mul	ecx
1297
;        mul     ecx
1231
	add	eax, IPbuffs
1298
;        add     eax, IPbuffs
1232
	mov	esi, eax
1299
;        mov     esi, eax
Line 1233... Line 1300...
1233
 
1300
 
1234
	; do copy
1301
	; do copy
1235
	mov	ecx, IPBUFFSIZE
1302
;        mov     ecx, IPBUFFSIZE
Line 1236... Line 1303...
1236
;        cld
1303
;        cld
1237
	rep	movsb
1304
	rep	movsb
1238
 
1305
 
1239
  .exit:
1306
  .exit:
Line 1240... Line 1307...
1240
	xor	eax, eax
1307
	xor	eax, eax
1241
	ret
1308
	ret
Line 1260... Line 1327...
1260
;***************************************************************************
1327
;***************************************************************************
Line 1261... Line 1328...
1261
 
1328
 
1262
 
1329
 
1263
checksum:
1330
checksum:
1264
    pusha
1331
    pusha
1265
    mov     eax, [checkAdd1]
1332
;    mov     eax, [checkAdd1]
1266
    xor     edx, edx		      ; edx is the accumulative checksum
1333
    xor     edx, edx		      ; edx is the accumulative checksum
1267
    xor     ebx, ebx
1334
    xor     ebx, ebx
1268
    mov     cx, [checkSize1]
1335
;    mov     cx, [checkSize1]
Line 1269... Line 1336...
1269
    shr     cx, 1
1336
    shr     cx, 1
1270
    jz	    cs1_1
1337
    jz	    cs1_1
Line 1277... Line 1344...
1277
    add     edx, ebx
1344
    add     edx, ebx
Line 1278... Line 1345...
1278
 
1345
 
Line 1279... Line 1346...
1279
    loopw   cs1
1346
    loopw   cs1
1280
 
1347
 
1281
cs1_1:
1348
cs1_1:
Line 1282... Line 1349...
1282
    and     word [checkSize1], 0x01
1349
;    and     word [checkSize1], 0x01
1283
    jz	    cs_test2
1350
    jz	    cs_test2
Line 1284... Line 1351...
1284
 
1351
 
Line 1285... Line 1352...
1285
    mov     bh, [eax]
1352
    mov     bh, [eax]
1286
    xor     bl, bl
1353
    xor     bl, bl
1287
 
1354
 
1288
    add     edx, ebx
1355
    add     edx, ebx
Line 1289... Line 1356...
1289
 
1356
 
Line 1290... Line 1357...
1290
cs_test2:
1357
cs_test2:
1291
    mov     cx, [checkSize2]
1358
;    mov     cx, [checkSize2]
Line 1292... Line 1359...
1292
    cmp     cx, 0
1359
    cmp     cx, 0
Line 1305... Line 1372...
1305
    add     edx, ebx
1372
    add     edx, ebx
Line 1306... Line 1373...
1306
 
1373
 
Line 1307... Line 1374...
1307
    loopw   cs2
1374
    loopw   cs2
1308
 
1375
 
1309
cs2_1:
1376
cs2_1:
Line 1310... Line 1377...
1310
    and     word [checkSize2], 0x01
1377
;    and     word [checkSize2], 0x01
1311
    jz	    cs_exit
1378
    jz	    cs_exit
Line 1324... Line 1391...
1324
    mov     eax, edx
1391
    mov     eax, edx
1325
    shr     eax, 16
1392
    shr     eax, 16
1326
    add     edx, eax
1393
    add     edx, eax
1327
    not     dx
1394
    not     dx
Line 1328... Line 1395...
1328
 
1395
 
1329
    mov     [checkResult], dx
1396
;    mov     [checkResult], dx
1330
    popa
1397
    popa
Line 1331... Line -...
1331
    ret
-
 
1332
 
-
 
1333
 
-
 
1334
 
-
 
1335
 
-
 
1336
 
-
 
1337
TCP_HANDLER:
-
 
1338
;;; TODO: write code here
-
 
1339
 
-
 
1340
    call    kernel_free
-
 
1341
    add     esp, 4 ; pop (balance stack)
-
 
1342
 
-
 
1343
ret
-
 
1344
-