Rev 914 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 914 | Rev 2971 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2008. 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 | ;; 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: 914 $ |
19 | $Revision: 2971 $ |
22 | 20 | ||
23 | 21 | ||
Line 116... | Line 114... | ||
116 | 114 | ||
Line 117... | Line 115... | ||
117 | mov ebx, net_sockets |
115 | mov ebx, net_sockets |
118 | 116 | ||
119 | cmp [ebx + SOCKET.NextPtr], 0 |
117 | cmp [ebx + SOCKET.NextPtr], 0 |
Line 120... | Line 118... | ||
120 | je .exit |
118 | je .exit |
121 | DEBUGF 1, "K : sockets:\n" |
119 | ;DEBUGF 1, "K : sockets:\n" |
122 | 120 | ||
123 | .next_socket: |
121 | .next_socket: |
Line 124... | Line 122... | ||
124 | mov ebx, [ebx + SOCKET.NextPtr] |
122 | mov ebx, [ebx + SOCKET.NextPtr] |
Line 125... | Line 123... | ||
125 | or ebx, ebx |
123 | or ebx, ebx |
126 | jz .exit |
124 | jz .exit |
127 | 125 | ||
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] |
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 314... | Line 307... | ||
314 | .next_socket.1: |
307 | .next_socket.1: |
315 | mov ebx, [ebx + SOCKET.NextPtr] |
308 | mov ebx, [ebx + SOCKET.NextPtr] |
316 | or ebx, ebx |
309 | or ebx, ebx |
317 | jz .next_socket.1.exit |
310 | jz .next_socket.1.exit |
Line 318... | Line -... | ||
318 | - | ||
319 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
320 | jne .next_socket.1 |
- | |
321 | 311 | ||
Line 322... | Line 312... | ||
322 | ; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
312 | ; DEBUGF 1, "K : tcp_rx - 1.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
323 | 313 | ||
324 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
314 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
Line 353... | Line 343... | ||
353 | .next_socket.2: |
343 | .next_socket.2: |
354 | mov ebx, [ebx + SOCKET.NextPtr] |
344 | mov ebx, [ebx + SOCKET.NextPtr] |
355 | or ebx, ebx |
345 | or ebx, ebx |
356 | jz .next_socket.2.exit |
346 | jz .next_socket.2.exit |
Line 357... | Line -... | ||
357 | - | ||
358 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
359 | jne .next_socket.2 |
- | |
360 | 347 | ||
Line 361... | Line 348... | ||
361 | ; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
348 | ; DEBUGF 1, "K : tcp_rx - 2.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
362 | 349 | ||
363 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
350 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get the dest. port from the TCP hdr |
Line 391... | Line 378... | ||
391 | .next_socket.3: |
378 | .next_socket.3: |
392 | mov ebx, [ebx + SOCKET.NextPtr] |
379 | mov ebx, [ebx + SOCKET.NextPtr] |
393 | or ebx, ebx |
380 | or ebx, ebx |
394 | jz .next_socket.3.exit |
381 | jz .next_socket.3.exit |
Line 395... | Line -... | ||
395 | - | ||
396 | cmp [ebx + SOCKET.Status], SOCK_OPEN |
- | |
397 | jne .next_socket.3 |
- | |
398 | 382 | ||
Line 399... | Line 383... | ||
399 | ; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
383 | ; DEBUGF 1, "K : tcp_rx - 3.dport: %x - %x\n", [edx + 20 + TCP_PACKET.DestinationPort]:4, [ebx + SOCKET.LocalPort]:4 |
400 | 384 | ||
401 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr |
385 | mov ax, [edx + 20 + TCP_PACKET.DestinationPort] ; get destination port from the TCP hdr |
Line 419... | Line 403... | ||
419 | 403 | ||
Line 420... | Line 404... | ||
420 | ; If we got here, we need to reject the packet |
404 | ; If we got here, we need to reject the packet |
421 | 405 | ||
422 | DEBUGF 1, "K : tcp_rx - dumped\n" |
- | |
423 | 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 |
406 | DEBUGF 1, "K : tcp_rx - dumped\n" |
424 | ; mov ebx, net_sockets |
- | |
425 | ; |
- | |
426 | ; .next_socket.4: |
- | |
427 | ; mov ebx, [ebx + SOCKET.NextPtr] |
- | |
428 | ; or ebx, ebx |
- | |
429 | ; jz .next_socket.4.exit |
- | |
430 | ; DEBUGF 1, "K : %x: %x-%x-%x-%u\n", ebx, [ebx + SOCKET.LocalPort]:4, [ebx + SOCKET.RemoteIP], [ebx + SOCKET.RemotePort]:4, [ebx + SOCKET.TCBState] |
- | |
431 | ; jne .next_socket.4 |
- | |
432 | ; |
407 | 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 |
433 | ; .next_socket.4.exit: |
408 | |
Line 434... | Line 409... | ||
434 | inc [dumped_rx_count] |
409 | inc [dumped_rx_count] |
Line 659... | Line 634... | ||
659 | xor ecx, ecx |
634 | xor ecx, ecx |
Line 660... | Line 635... | ||
660 | 635 | ||
661 | .next_resendq: |
636 | .next_resendq: |
662 | cmp ecx, NUMRESENDENTRIES |
637 | cmp ecx, NUMRESENDENTRIES |
663 | je .call_handler ; None left |
- | |
664 | ;cmp [esi], al ; XTODO: al -> eax |
638 | je .call_handler ; None left |
665 | cmp [esi + 4], eax |
639 | cmp [esi + 4], eax |
666 | je @f ; found one |
640 | je @f ; found one |
667 | inc ecx |
641 | inc ecx |
668 | add esi, 8 |
642 | add esi, 8 |
Line 700... | Line 674... | ||
700 | 674 | ||
701 | inc ecx |
675 | inc ecx |
702 | add esi, 8 |
676 | add esi, 8 |
Line 703... | Line -... | ||
703 | jmp .next_resendq |
- | |
704 | 677 | jmp .next_resendq |
|
705 | ;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0 |
678 | |
706 | @@: mov dword[esi + 4], 0 |
679 | @@: mov dword[esi + 4], 0 |
707 | inc ecx |
680 | inc ecx |
Line 850... | Line 823... | ||
850 | proc stateTCB_SYN_RECEIVED stdcall, sockAddr:DWORD |
823 | proc stateTCB_SYN_RECEIVED stdcall, sockAddr:DWORD |
851 | ; In this case, we are expecting an ACK packet |
824 | ; In this case, we are expecting an ACK packet |
852 | ; For now, if the packet is an ACK, process it, |
825 | ; For now, if the packet is an ACK, process it, |
853 | ; If not, ignore it |
826 | ; If not, ignore it |
Line 854... | Line 827... | ||
854 | 827 | ||
855 | test [edx + 20 + TCP_PACKET.Flags], TH_RST ;xxx |
828 | test [edx + 20 + TCP_PACKET.Flags], TH_RST |
Line 856... | Line 829... | ||
856 | jz .check_ack ;xxx |
829 | jz .check_ack |
857 | 830 | ||
Line 858... | Line 831... | ||
858 | push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP] |
831 | push [ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP] |
859 | pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort] |
832 | pop [ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort] |
Line 860... | Line 833... | ||
860 | 833 | ||
861 | mov [ebx + SOCKET.TCBState], TCB_LISTEN ;xxx |
834 | mov [ebx + SOCKET.TCBState], TCB_LISTEN |
862 | jmp .exit ;xxx |
835 | jmp .exit |
863 | 836 | ||
Line 864... | Line 837... | ||
864 | .check_ack: ;xxx |
837 | .check_ack: |
Line 876... | Line 849... | ||
876 | proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD |
849 | proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD |
877 | ; Here we are expecting data, or a request to close |
850 | ; Here we are expecting data, or a request to close |
878 | ; OR both... |
851 | ; OR both... |
Line 879... | Line 852... | ||
879 | 852 | ||
880 | ; Did we receive a FIN or RST? |
- | |
881 | ;xxx test [edx + 20 + TCP_PACKET.Flags], TH_FIN + TH_RST |
- | |
882 | ;xxx jz .check_ack |
853 | ; Did we receive a FIN or RST? |
883 | test [edx + 20 + TCP_PACKET.Flags], TH_FIN ;xxx |
854 | test [edx + 20 + TCP_PACKET.Flags], TH_FIN |
Line 884... | Line 855... | ||
884 | jz .check_ack ;xxx |
855 | jz .check_ack |
Line 885... | Line 856... | ||
885 | 856 | ||
886 | ; It was a fin or reset. |
857 | ; It was a fin or reset. |
Line 895... | Line 866... | ||
895 | mov ecx, 0 |
866 | mov ecx, 0 |
Line 896... | Line 867... | ||
896 | 867 | ||
897 | .next_resendq: |
868 | .next_resendq: |
898 | cmp ecx, NUMRESENDENTRIES |
869 | cmp ecx, NUMRESENDENTRIES |
899 | je .last_resendq ; None left |
- | |
900 | ;cmp [esi], al ; XTODO: al -> eax |
870 | je .last_resendq ; None left |
901 | cmp [esi + 4], eax |
871 | cmp [esi + 4], eax |
902 | je @f ; found one |
872 | je @f ; found one |
903 | inc ecx |
873 | inc ecx |
904 | add esi, 8 |
874 | add esi, 8 |
Line 905... | Line -... | ||
905 | jmp .next_resendq |
- | |
906 | 875 | jmp .next_resendq |
|
907 | ;@@: mov byte[esi], 0xff ; XTODO: 0xff -> 0 |
876 | |
908 | @@: mov dword[esi + 4], 0 |
877 | @@: mov dword[esi + 4], 0 |
909 | inc ecx |
878 | inc ecx |
Line 910... | Line 879... | ||
910 | add esi, 8 |
879 | add esi, 8 |
911 | jmp .next_resendq |
880 | jmp .next_resendq |
Line 912... | Line -... | ||
912 | - | ||
913 | .last_resendq: |
- | |
914 | popad |
- | |
915 | - | ||
916 | ;xxx ; was it a reset? |
- | |
917 | ;xxx test [edx + 20 + TCP_PACKET.Flags], TH_RST |
- | |
918 | ;xxx jz @f |
- | |
919 | 881 | ||
Line 920... | Line 882... | ||
920 | ;xxx mov [ebx + SOCKET.TCBState], TCB_CLOSED |
882 | .last_resendq: |
921 | ;xxx jmp .exit |
883 | popad |
922 | 884 | ||
Line 964... | Line 926... | ||
964 | 926 | ||
965 | ; Read the data bytes, store in socket buffer |
927 | ; Read the data bytes, store in socket buffer |
966 | movzx ecx, [edx + IP_PACKET.TotalLength] |
928 | movzx ecx, [edx + IP_PACKET.TotalLength] |
967 | xchg cl, ch |
929 | xchg cl, ch |
968 | sub ecx, 40 ; Discard 40 bytes of header |
930 | sub ecx, 40 ; Discard 40 bytes of header |
Line 969... | Line 931... | ||
969 | jnz .data ; Read data, if any |
931 | ja .data ; Read data, if any |
970 | 932 | ||
971 | ; If we had received a fin, we need to ACK it. |
933 | ; If we had received a fin, we need to ACK it. |
972 | cmp [ebx + SOCKET.TCBState], TCB_CLOSE_WAIT |
934 | cmp [ebx + SOCKET.TCBState], TCB_CLOSE_WAIT |
Line 973... | Line 935... | ||
973 | je .ack |
935 | je .ack |
974 | jmp .exit |
936 | jmp .exit |
975 | - | ||
976 | .data: |
937 | |
- | 938 | .data: |
|
- | 939 | push ebx |
|
Line -... | Line 940... | ||
- | 940 | add ebx, SOCKET.lock |
|
977 | push ecx |
941 | call wait_mutex |
- | 942 | pop ebx |
|
978 | 943 | ||
- | 944 | push ecx |
|
- | 945 | push [ebx + SOCKET.PID] ; get socket owner PID |
|
Line 979... | Line 946... | ||
979 | add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer |
946 | mov eax, [ebx + SOCKET.rxDataCount] |
Line 980... | Line 947... | ||
980 | 947 | add eax, ecx |
|
981 | mov eax, [ebx + SOCKET.PID] ; get socket owner PID |
948 | cmp eax, SOCKETBUFFSIZE - SOCKETHEADERSIZE |
982 | push eax |
949 | ja .overflow |
Line 983... | Line 950... | ||
983 | 950 | ||
984 | mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer |
951 | mov [ebx + SOCKET.rxDataCount], eax ; increment the count of bytes in buffer |
Line 985... | Line 952... | ||
985 | 952 | ||
986 | ; point to the location to store the data |
953 | ; point to the location to store the data |
- | 954 | lea edi, [ebx + eax + SOCKETHEADERSIZE] |
|
Line 987... | Line 955... | ||
987 | lea edi, [ebx + eax + SOCKETHEADERSIZE] |
955 | sub edi, ecx |
988 | sub edi, ecx |
956 | |
989 | 957 | add edx, 40 ; edx now points to the data |
|
990 | add edx, 40 ; edx now points to the data |
958 | mov esi, edx |
Line 1044... | Line 1012... | ||
1044 | pop ebx |
1012 | pop ebx |
1045 | call queue |
1013 | call queue |
Line 1046... | Line 1014... | ||
1046 | 1014 | ||
1047 | .exit: |
1015 | .exit: |
- | 1016 | ret |
|
- | 1017 | .overflow: |
|
- | 1018 | ; no place in buffer |
|
- | 1019 | ; so simply restore stack and exit |
|
- | 1020 | pop eax ecx |
|
- | 1021 | mov [ebx + SOCKET.lock], 0 |
|
1048 | ret |
1022 | ret |
Line 1049... | Line 1023... | ||
1049 | endp |
1023 | endp |
1050 | 1024 | ||
Line 1165... | Line 1139... | ||
1165 | test [edx + 20 + TCP_PACKET.Flags], TH_ACK |
1139 | test [edx + 20 + TCP_PACKET.Flags], TH_ACK |
1166 | jz .exit |
1140 | jz .exit |
Line 1167... | Line 1141... | ||
1167 | 1141 | ||
1168 | ; delete the socket |
1142 | ; delete the socket |
1169 | stdcall net_socket_free, ebx |
- | |
1170 | ; mov edi, ebx |
- | |
1171 | ; xor eax, eax |
- | |
1172 | ; mov ecx, SOCKETHEADERSIZE |
- | |
1173 | ; cld |
- | |
Line 1174... | Line 1143... | ||
1174 | ; rep stosb |
1143 | stdcall net_socket_free, ebx |
1175 | 1144 | ||
1176 | .exit: |
1145 | .exit: |