Rev 907 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 907 | Rev 922 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | ;; ;; |
5 | ;; ;; |
6 | ;; TCP.INC ;; |
6 | ;; TCP.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; TCP Processes for Menuet OS TCP/IP stack ;; |
8 | ;; TCP Processes for Menuet OS TCP/IP stack ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Version 0.6 4th July 2004 ;; |
- | |
11 | ;; ;; |
- | |
12 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
10 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
13 | ;; ;; |
11 | ;; ;; |
14 | ;; See file COPYING for details ;; |
12 | ;; See file COPYING for details ;; |
15 | ;; v0.6 : Added reset handling in the established state ;; |
13 | ;; v0.6 : Added reset handling in the established state ;; |
16 | ;; Added a timer per socket to allow delays when ;; |
14 | ;; Added a timer per socket to allow delays when ;; |
17 | ;; rx window gets below 1KB ;; |
15 | ;; rx window gets below 1KB ;; |
18 | ;; ;; |
16 | ;; ;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 20... | Line 18... | ||
20 | 18 | ||
Line 21... | Line 19... | ||
21 | $Revision: 907 $ |
19 | $Revision: 922 $ |
22 | 20 | ||
23 | 21 | ||
Line 123... | Line 121... | ||
123 | .next_socket: |
121 | .next_socket: |
124 | mov ebx, [ebx + SOCKET.NextPtr] |
122 | mov ebx, [ebx + SOCKET.NextPtr] |
125 | or ebx, ebx |
123 | or ebx, ebx |
126 | jz .exit |
124 | jz .exit |
Line 127... | Line 125... | ||
127 | 125 | ||
Line 128... | Line 126... | ||
128 | DEBUGF 1, "K : %x: %x-%x-%x-%u\n", ebx, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState] |
126 | 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] |
129 | 127 | ||
130 | cmp [ebx + SOCKET.TCBTimer], 0 |
128 | cmp [ebx + SOCKET.TCBTimer], 0 |
131 | jne .decrement_tcb |
129 | jne .decrement_tcb |
Line 175... | Line 173... | ||
175 | mov ecx, 0 |
173 | mov ecx, 0 |
Line 176... | Line 174... | ||
176 | 174 | ||
177 | .next_resendq: |
175 | .next_resendq: |
178 | cmp ecx, NUMRESENDENTRIES |
176 | cmp ecx, NUMRESENDENTRIES |
179 | je .exit ; None left |
- | |
180 | ;cmp [esi], byte 0xFF ; XTODO: 0xff -> 0 |
177 | je .exit ; None left |
181 | cmp dword[esi + 4], 0 |
178 | cmp dword[esi + 4], 0 |
182 | jne @f ; found one |
179 | jne @f ; found one |
183 | inc ecx |
180 | inc ecx |
184 | add esi, 8 |
181 | add esi, 8 |
Line 190... | Line 187... | ||
190 | inc ecx |
187 | inc ecx |
191 | add esi, 8 |
188 | add esi, 8 |
192 | jmp .next_resendq ; Timer not zero, so move on |
189 | jmp .next_resendq ; Timer not zero, so move on |
Line 193... | Line 190... | ||
193 | 190 | ||
194 | @@: |
- | |
195 | ;mov bl, 0xff ; XTODO: bl -> ebx, 0xff -> 0 |
191 | @@: |
196 | xor ebx, ebx |
192 | xor ebx, ebx |
197 | ; restart timer, and decrement retries |
193 | ; restart timer, and decrement retries |
198 | ; After the first resend, back of on next, by a factor of 5 |
194 | ; After the first resend, back of on next, by a factor of 5 |
199 | mov [esi + 2], word TCP_TIMEOUT * 5 |
195 | mov [esi + 2], word TCP_TIMEOUT * 5 |
200 | dec byte[esi + 1] |
196 | dec byte[esi + 1] |
Line 201... | Line 197... | ||
201 | jnz @f |
197 | jnz @f |
202 | - | ||
203 | ; retries now 0, so delete from queue |
198 | |
Line 204... | Line 199... | ||
204 | ;xchg [esi], bl ; XTODO: bl -> ebx |
199 | ; retries now 0, so delete from queue |
205 | xchg [esi + 4], ebx |
200 | xchg [esi + 4], ebx |
Line 211... | Line 206... | ||
211 | call dequeue |
206 | call dequeue |
212 | cmp ax, NO_BUFFER |
207 | cmp ax, NO_BUFFER |
213 | jne .tth004z |
208 | jne .tth004z |
Line 214... | Line 209... | ||
214 | 209 | ||
215 | ; TODO - try again in 10ms. |
- | |
216 | ;cmp bl, 0xff ; XTODO: 0xff -> 0 |
210 | ; TODO - try again in 10ms. |
217 | test ebx, ebx |
211 | test ebx, ebx |
218 | jnz @f |
- | |
219 | ;mov [esi], bl ; XTODO: bl -> ebx |
212 | jnz @f |
Line 220... | Line 213... | ||
220 | mov [esi + 4], ebx |
213 | mov [esi + 4], ebx |
221 | 214 | ||
222 | @@: ; Mark it to expire in 10ms - 1 tick |
215 | @@: ; Mark it to expire in 10ms - 1 tick |
Line 308... | Line 301... | ||
308 | .next_socket.1: |
301 | .next_socket.1: |
309 | mov ebx, [ebx + SOCKET.NextPtr] |
302 | mov ebx, [ebx + SOCKET.NextPtr] |
310 | or ebx, ebx |
303 | or ebx, ebx |
311 | jz .next_socket.1.exit |
304 | jz .next_socket.1.exit |
Line 312... | Line -... | ||
312 | - | ||
313 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
314 | jne .next_socket.1 |
- | |
315 | 305 | ||
Line 316... | Line 306... | ||
316 | ; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
306 | ; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
317 | 307 | ||
318 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
308 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
Line 347... | Line 337... | ||
347 | .next_socket.2: |
337 | .next_socket.2: |
348 | mov ebx, [ebx + SOCKET.NextPtr] |
338 | mov ebx, [ebx + SOCKET.NextPtr] |
349 | or ebx, ebx |
339 | or ebx, ebx |
350 | jz .next_socket.2.exit |
340 | jz .next_socket.2.exit |
Line 351... | Line -... | ||
351 | - | ||
352 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
353 | jne .next_socket.2 |
- | |
354 | 341 | ||
Line 355... | Line 342... | ||
355 | ; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
342 | ; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
356 | 343 | ||
357 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
344 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
Line 385... | Line 372... | ||
385 | .next_socket.3: |
372 | .next_socket.3: |
386 | mov ebx, [ebx + SOCKET.NextPtr] |
373 | mov ebx, [ebx + SOCKET.NextPtr] |
387 | or ebx, ebx |
374 | or ebx, ebx |
388 | jz .next_socket.3.exit |
375 | jz .next_socket.3.exit |
Line 389... | Line -... | ||
389 | - | ||
390 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
391 | jne .next_socket.3 |
- | |
392 | 376 | ||
Line 393... | Line 377... | ||
393 | ; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
377 | ; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
394 | 378 | ||
395 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr |
379 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr |
Line 413... | Line 397... | ||
413 | 397 | ||
Line 414... | Line 398... | ||
414 | ; If we got here, we need to reject the packet |
398 | ; If we got here, we need to reject the packet |
415 | 399 | ||
416 | DEBUGF 1, "K : tcp_rx - dumped\n" |
- | |
417 | 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 |
400 | DEBUGF 1, "K : tcp_rx - dumped\n" |
418 | ; mov ebx, net_sockets |
- | |
419 | ; |
- | |
420 | ; .next_socket.4: |
- | |
421 | ; mov ebx, [ebx + SOCKET.NextPtr] |
- | |
422 | ; or ebx, ebx |
- | |
423 | ; jz .next_socket.4.exit |
- | |
424 | ; DEBUGF 1, "K : %x: %x-%x-%x-%u\n", ebx, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState] |
- | |
425 | ; jne .next_socket.4 |
- | |
426 | ; |
401 | 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 |
427 | ; .next_socket.4.exit: |
402 | |
Line 428... | Line 403... | ||
428 | inc [dumped_rx_count] |
403 | inc [dumped_rx_count] |
Line 653... | Line 628... | ||
653 | xor ecx, ecx |
628 | xor ecx, ecx |
Line 654... | Line 629... | ||
654 | 629 | ||
655 | .next_resendq: |
630 | .next_resendq: |
656 | cmp ecx, NUMRESENDENTRIES |
631 | cmp ecx, NUMRESENDENTRIES |
657 | je .call_handler ; None left |
- | |
658 | ;cmp [esi], al ; XTODO: al -> eax |
632 | je .call_handler ; None left |
659 | cmp [esi + 4], eax |
633 | cmp [esi + 4], eax |
660 | je @f ; found one |
634 | je @f ; found one |
661 | inc ecx |
635 | inc ecx |
662 | add esi, 8 |
636 | add esi, 8 |
Line 694... | Line 668... | ||
694 | 668 | ||
695 | inc ecx |
669 | inc ecx |
696 | add esi, 8 |
670 | add esi, 8 |
Line 697... | Line -... | ||
697 | jmp .next_resendq |
- | |
698 | 671 | jmp .next_resendq |
|
699 | ;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0 |
672 | |
700 | @@: mov dword[esi + 4], 0 |
673 | @@: mov dword[esi + 4], 0 |
701 | inc ecx |
674 | inc ecx |
Line 843... | Line 816... | ||
843 | proc stateTCB_SYN_RECEIVED stdcall, sockAddr:DWORD |
816 | proc stateTCB_SYN_RECEIVED stdcall, sockAddr:DWORD |
844 | ; In this case, we are expecting an ACK packet |
817 | ; In this case, we are expecting an ACK packet |
845 | ; For now, if the packet is an ACK, process it, |
818 | ; For now, if the packet is an ACK, process it, |
846 | ; If not, ignore it |
819 | ; If not, ignore it |
Line 847... | Line 820... | ||
847 | 820 | ||
848 | test [edx + 20 + TCP_PACKET.Flags], TH_RST ;xxx |
821 | test [edx + 20 + TCP_PACKET.Flags], TH_RST |
Line 849... | Line 822... | ||
849 | jz .check_ack ;xxx |
822 | jz .check_ack |
850 | 823 | ||
Line 851... | Line 824... | ||
851 | push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP] |
824 | push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP] |
852 | pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort] |
825 | pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort] |
Line 853... | Line 826... | ||
853 | 826 | ||
854 | mov [ebx + SOCKET.TCBState], TCB_LISTEN ;xxx |
827 | mov [ebx + SOCKET.TCBState], TCB_LISTEN |
855 | jmp .exit ;xxx |
828 | jmp .exit |
856 | 829 | ||
Line 857... | Line 830... | ||
857 | .check_ack: ;xxx |
830 | .check_ack: |
Line 869... | Line 842... | ||
869 | proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD |
842 | proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD |
870 | ; Here we are expecting data, or a request to close |
843 | ; Here we are expecting data, or a request to close |
871 | ; OR both... |
844 | ; OR both... |
Line 872... | Line 845... | ||
872 | 845 | ||
873 | ; Did we receive a FIN or RST? |
- | |
874 | ;xxx test [edx + 20 + TCP_PACKET.Flags], TH_FIN + TH_RST |
- | |
875 | ;xxx jz .check_ack |
846 | ; Did we receive a FIN or RST? |
876 | test [edx + 20 + TCP_PACKET.Flags], TH_FIN ;xxx |
847 | test [edx + 20 + TCP_PACKET.Flags], TH_FIN |
Line 877... | Line 848... | ||
877 | jz .check_ack ;xxx |
848 | jz .check_ack |
Line 878... | Line 849... | ||
878 | 849 | ||
879 | ; It was a fin or reset. |
850 | ; It was a fin or reset. |
Line 888... | Line 859... | ||
888 | mov ecx, 0 |
859 | mov ecx, 0 |
Line 889... | Line 860... | ||
889 | 860 | ||
890 | .next_resendq: |
861 | .next_resendq: |
891 | cmp ecx, NUMRESENDENTRIES |
862 | cmp ecx, NUMRESENDENTRIES |
892 | je .last_resendq ; None left |
- | |
893 | ;cmp [esi], al ; XTODO: al -> eax |
863 | je .last_resendq ; None left |
894 | cmp [esi + 4], eax |
864 | cmp [esi + 4], eax |
895 | je @f ; found one |
865 | je @f ; found one |
896 | inc ecx |
866 | inc ecx |
897 | add esi, 8 |
867 | add esi, 8 |
Line 898... | Line -... | ||
898 | jmp .next_resendq |
- | |
899 | 868 | jmp .next_resendq |
|
900 | ;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0 |
869 | |
901 | @@: mov dword[esi + 4], 0 |
870 | @@: mov dword[esi + 4], 0 |
902 | inc ecx |
871 | inc ecx |
Line 903... | Line 872... | ||
903 | add esi, 8 |
872 | add esi, 8 |
904 | jmp .next_resendq |
873 | jmp .next_resendq |
Line 905... | Line -... | ||
905 | - | ||
906 | .last_resendq: |
- | |
907 | popad |
- | |
908 | - | ||
909 | ;xxx ; was it a reset? |
- | |
910 | ;xxx test [edx + 20 + TCP_PACKET.Flags], TH_RST |
- | |
911 | ;xxx jz @f |
- | |
912 | 874 | ||
Line 913... | Line 875... | ||
913 | ;xxx mov [ebx + SOCKET.TCBState], TCB_CLOSED |
875 | .last_resendq: |
914 | ;xxx jmp .exit |
876 | popad |
915 | 877 | ||
Line 1156... | Line 1118... | ||
1156 | test [edx + 20 + TCP_PACKET.Flags], TH_ACK |
1118 | test [edx + 20 + TCP_PACKET.Flags], TH_ACK |
1157 | jz .exit |
1119 | jz .exit |
Line 1158... | Line 1120... | ||
1158 | 1120 | ||
1159 | ; delete the socket |
1121 | ; delete the socket |
1160 | stdcall net_socket_free, ebx |
- | |
1161 | ; mov edi, ebx |
- | |
1162 | ; xor eax, eax |
- | |
1163 | ; mov ecx, SOCKETHEADERSIZE |
- | |
1164 | ; cld |
- | |
Line 1165... | Line 1122... | ||
1165 | ; rep stosb |
1122 | stdcall net_socket_free, ebx |
1166 | 1123 | ||
1167 | .exit: |
1124 | .exit: |