Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1733 hidnplayr 1
 
2
 
3
 
4
; Pseudoheader
5
 
6
	; protocol type
7
	mov	edx, IP_PROTO_TCP
8
 
9
	; source address
10
	add	dl, byte [IP1+1]
11
 
12
	adc	dl, byte [IP1+3]
13
	adc	dh, byte [IP1+2]
14
15
	; destination address
16
	adc	dl, byte [IP2+1]
17
 
18
	adc	dl, byte [IP2+3]
19
	adc	dh, byte [IP2+2]
20
21
	; size
22
	adc	dl, cl
23
 
24
25
;---------------------
26
; Real header and data
27
 
28
	push	esi
29
	call	checksum_1
30
 
31
	pop	esi
32
33
}	; returns in dx only
34
35
 
36
37
 
38
 
39
 
40
 
41
	mov	edi, [ptr + TCP_SOCKET.ISS]
42
 
43
	mov	[ptr + TCP_SOCKET.SND_MAX], edi
44
	mov	[ptr + TCP_SOCKET.SND_NXT], edi
45
	mov	[ptr + TCP_SOCKET.SND_UNA], edi
46
	pop	edi
47
48
}
49
50
 
51
52
 
53
 
54
 
55
	mov	edi, [ptr + TCP_SOCKET.IRS]
56
 
57
	mov	[ptr + TCP_SOCKET.RCV_NXT], edi
58
	mov	[ptr + TCP_SOCKET.RCV_ADV], edi
59
	pop	edi
60
61
}
62
63
 
64
65
 
66
 
67
 
68
 
69
 
70
 
71
 
72
 
73
 
74
 
75
;
76
; IN:  eax =
77
;      ebx = socket ptr
78
;      edx = tcp packet ptr
79
;
80
; OUT: /
81
;
82
;---------------------------
83
84
align 4
85
TCP_pull_out_of_band:
86
 
87
	DEBUGF	1,"TCP_pull_out_of_band\n"
88
89
 
90
91
 
92
93
 
94
95
 
96
 
97
 
98
 
99
 
100
 
101
 
102
 
103
;
104
;  IN:  eax = socket ptr
105
;       ebx = error number
106
;
107
;  OUT: eax = socket ptr
108
;
109
;-------------------------
110
align 4
111
TCP_drop:
112
113
	DEBUGF	1,"TCP_drop\n"
114
115
 
116
	jl	.no_syn_received
117
 
118
	mov	[eax + TCP_SOCKET.t_state], TCB_CLOSED
119
120
 
121
122
 
123
124
 
125
126
 
127
128
 
129
130
 
131
132
 
133
134
 
135
136
 
137
 
138
 
139
 
140
 
141
 
142
 
143
 
144
;
145
;  IN:  eax = socket ptr
146
;  OUT: eax = socket ptr
147
;
148
;-------------------------
149
align 4
150
TCP_close:
151
152
	DEBUGF	1,"TCP_close\n"
153
154
 
155
;;; TODO: update slow start threshold
156
 
157
158
; Now, mark the socket as being disconnected
159
160
 
161
162
 
163
164
 
165
166
 
167
 
168
 
169
 
170
 
171
 
172
 
173
 
174
 
175
 
176
;
177
;  IN:  eax = socket ptr
178
;
179
;  OUT: edx = flags
180
;
181
;-------------------------
182
align 4
183
TCP_outflags:
184
185
	mov	edx, [eax + TCP_SOCKET.t_state]
186
	movzx	edx, byte [edx + .flaglist]
187
 
188
	DEBUGF	1,"TCP_outflags, socket: %x, flags: %x\n", eax, dl
189
190
 
191
192
 
193
194
 
195
	db	0			; TCB_LISTEN
196
 
197
	db	TH_SYN + TH_ACK 	; TCB_SYN_RECEIVED
198
	db		 TH_ACK 	; TCB_ESTABLISHED
199
	db		 TH_ACK 	; TCB_CLOSE_WAIT
200
	db	TH_SYN + TH_ACK 	; TCB_FIN_WAIT_1
201
	db	TH_SYN + TH_ACK 	; TCB_CLOSING
202
	db	TH_SYN + TH_ACK 	; TCB_LAST_ACK
203
	db		 TH_ACK 	; TCB_FIN_WAIT_2
204
	db		 TH_ACK 	; TCB_TIMED_WAIT
205
206
207
208
 
209
 
210
 
211
 
212
 
213
 
214
;
215
; TCP_respond_socket:
216
;
217
;  IN:  ebx = socket ptr
218
;        cl = flags
219
;
220
;--------------------------------------
221
align 4
222
TCP_respond_socket:
223
224
	DEBUGF	1,"TCP_respond_socket\n"
225
226
 
227
; Create the IP packet
228
 
229
	push	cx ebx
230
	mov	eax, [ebx + IP_SOCKET.RemoteIP]
231
 
232
	mov	ecx, TCP_segment.Data
233
	mov	di , IP_PROTO_TCP shl 8 + 128
234
	call	IPv4_output
235
	test	edi, edi
236
	jz	.error
237
	pop	esi cx
238
	push	edx eax
239
240
;-----------------------------------------------
241
; Fill in the TCP header by using the socket ptr
242
 
243
	mov	ax, [esi + TCP_SOCKET.LocalPort]
244
	rol	ax, 8
245
 
246
	mov	ax, [esi + TCP_SOCKET.RemotePort]
247
	rol	ax, 8
248
	stosw
249
	mov	eax, [esi + TCP_SOCKET.SND_NXT]
250
	bswap	eax
251
	stosd
252
	mov	eax, [esi + TCP_SOCKET.RCV_NXT]
253
	bswap	eax
254
	stosd
255
	mov	al, 0x50	; Dataoffset: 20 bytes
256
	stosb
257
	mov	al, cl
258
	stosb
259
	mov	ax, [esi + TCP_SOCKET.RCV_WND]
260
	rol	ax, 8
261
	stosw			; window
262
	xor	eax, eax
263
	stosd			; checksum + urgentpointer
264
265
;---------------------
266
; Fill in the checksum
267
 
268
  .checksum:
269
	sub	edi, TCP_segment.Data
270
 
271
	xchg	esi, edi
272
	TCP_checksum (edi + IP_SOCKET.LocalIP), (esi + IP_SOCKET.RemoteIP)
273
	mov	[esi+TCP_segment.Checksum], dx
274
275
;--------------------
276
; And send the segment
277
 
278
	call	[ebx + NET_DEVICE.transmit]
279
	ret
280
 
281
  .error:
282
	DEBUGF	1,"TCP_respond failed\n"
283
 
284
285
	ret
286
287
 
288
289
 
290
 
291
 
292
 
293
 
294
 
295
 
296
 
297
;  IN:  edx = segment ptr (a previously received segment)
298
;        cl = flags
299
300
align 4
301
TCP_respond_segment:
302
 
303
	DEBUGF	1,"TCP_respond_segment\n"
304
305
 
306
; Create the IP packet
307
 
308
	push	cx edx
309
	mov	ebx, [edx - 20 + IPv4_Packet.SourceAddress]	 ;;;; and what if ip packet had options?!
310
 
311
	mov	ecx, TCP_segment.Data
312
	mov	di , IP_PROTO_TCP shl 8 + 128
313
	call	IPv4_output
314
	jz	.error
315
	pop	esi cx
316
317
	push	edx eax
318
319
 
320
; Fill in the TCP header by using a received segment
321
 
322
	mov	ax, [esi + TCP_segment.DestinationPort]
323
	rol	ax, 8
324
 
325
	mov	ax, [esi + TCP_segment.SourcePort]
326
	rol	ax, 8
327
	stosw
328
	mov	eax, [esi + TCP_segment.AckNumber]
329
	bswap	eax
330
	stosd
331
	xor	eax, eax
332
	stosd
333
	mov	al, 0x50	; Dataoffset: 20 bytes
334
	stosb
335
	mov	al, cl
336
	stosb
337
	mov	ax, 1280
338
	rol	ax, 8
339
	stosw			; window
340
	xor	eax, eax
341
	stosd			; checksum + urgentpointer
342
343
;---------------------
344
; Fill in the checksum
345
 
346
  .checksum:
347
	lea	esi, [edi - TCP_segment.Data]
348
 
349
	TCP_checksum (esi - 20 + IPv4_Packet.DestinationAddress), (esi - 20 + IPv4_Packet.DestinationAddress)
350
	mov	[esi+TCP_segment.Checksum], dx
351
352
;--------------------
353
; And send the segment
354
 
355
	call	[ebx + NET_DEVICE.transmit]
356
	ret
357
 
358
  .error:
359
	DEBUGF	1,"TCP_respond failed\n"
360
 
361
362
	ret
363