Subversion Repositories Kolibri OS

Rev

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

Rev 1095 Rev 1181
Line 14... Line 14...
14
;;         Added a timer per socket to allow delays when        ;;
14
;;         Added a timer per socket to allow delays when        ;;
15
;;         rx window gets below 1KB                             ;;
15
;;         rx window gets below 1KB                             ;;
16
;;                                                              ;;
16
;;                                                              ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
$Revision: 1095 $
19
$Revision: 1181 $
20
 
20
 
21
 
21
 
Line 690... Line 690...
690
 
690
 
691
  .exit:
691
  .exit:
692
	ret
692
	ret
Line -... Line 693...
-
 
693
endp
-
 
694
 
-
 
695
;***************************************************************************
-
 
696
;   Function
-
 
697
;      signal_network_event
-
 
698
;
-
 
699
;   Description
-
 
700
;       Signals about network event to socket owner
-
 
701
;       This is a kernel function, called from TCP handler 
-
 
702
;
-
 
703
;          Socket/TCB address in ebx
-
 
704
;***************************************************************************
-
 
705
proc signal_network_event
-
 
706
	push	ecx esi eax
-
 
707
	mov	eax, [ebx + SOCKET.PID]
-
 
708
	mov	ecx, 1
-
 
709
	mov	esi, TASK_DATA + TASKDATA.pid
-
 
710
 
-
 
711
  .next_pid:
-
 
712
	cmp	[esi], eax
-
 
713
	je	.found_pid
-
 
714
	inc	ecx
-
 
715
	add	esi, 0x20
-
 
716
	cmp	ecx, [TASK_COUNT]
-
 
717
	jbe	.next_pid
-
 
718
 
-
 
719
  .found_pid:
-
 
720
	shl	ecx, 8
-
 
721
	or	[ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
-
 
722
	pop	eax esi ecx
Line 693... Line 723...
693
endp
723
	ret
694
 
724
endp
695
 
725
 
696
proc stateTCB_LISTEN stdcall, sockAddr:DWORD
726
proc stateTCB_LISTEN stdcall, sockAddr:DWORD
Line 721... Line 751...
721
	mov	eax, EMPTY_QUEUE
751
	mov	eax, EMPTY_QUEUE
722
	call	dequeue
752
	call	dequeue
723
	cmp	ax, NO_BUFFER
753
	cmp	ax, NO_BUFFER
724
	je	.exit
754
	je	.exit
Line -... Line 755...
-
 
755
 
725
 
756
	push	ebx
726
	push	eax
757
	push	eax
727
	mov	bl, TH_SYN + TH_ACK
758
	mov	bl, TH_SYN + TH_ACK
728
	xor	ecx, ecx
759
	xor	ecx, ecx
729
	xor	esi, esi
760
	xor	esi, esi
Line 739... Line 770...
739
  .not_local:
770
  .not_local:
740
	; Send it.
771
	; Send it.
741
	pop	ebx
772
	pop	ebx
742
	call	queue
773
	call	queue
Line -... Line 774...
-
 
774
 
743
 
775
	pop	ebx
744
	mov	esi, [sockAddr]
776
	mov	esi, [sockAddr]
-
 
777
	mov	[esi + SOCKET.TCBState], TCB_SYN_RECEIVED
Line 745... Line 778...
745
	mov	[esi + SOCKET.TCBState], TCB_SYN_RECEIVED
778
	call	signal_network_event
746
 
779
 
747
	; increment SND.NXT in socket
780
	; increment SND.NXT in socket
Line 772... Line 805...
772
  .syn_ack:
805
  .syn_ack:
773
	mov	[ebx + SOCKET.TCBState], TCB_ESTABLISHED
806
	mov	[ebx + SOCKET.TCBState], TCB_ESTABLISHED
774
	push	TH_ACK
807
	push	TH_ACK
Line 775... Line 808...
775
 
808
 
-
 
809
  .send:
776
  .send:
810
	call	signal_network_event
777
	; Store the recv.nxt field
811
	; Store the recv.nxt field
Line 778... Line 812...
778
	mov	eax, [edx + 20 + TCP_PACKET.SequenceNumber]
812
	mov	eax, [edx + 20 + TCP_PACKET.SequenceNumber]
779
 
813
 
Line 823... Line 857...
823
 
857
 
824
	push	[ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP]
858
	push	[ebx + SOCKET.OrigRemotePort] [ebx + SOCKET.OrigRemoteIP]
Line 825... Line 859...
825
	pop	[ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort]
859
	pop	[ebx + SOCKET.RemoteIP] [ebx + SOCKET.RemotePort]
826
 
860
 
Line 827... Line 861...
827
	mov	[ebx + SOCKET.TCBState], TCB_LISTEN
861
	mov	[ebx + SOCKET.TCBState], TCB_LISTEN
828
	jmp	.exit
862
	jmp	.signal
829
 
863
 
830
  .check_ack:
864
  .check_ack:
Line 831... Line 865...
831
	; Look at control flags - expecting an ACK
865
	; Look at control flags - expecting an ACK
-
 
866
	test	[edx + 20 + TCP_PACKET.Flags], TH_ACK
-
 
867
	jz	.exit
Line 832... Line 868...
832
	test	[edx + 20 + TCP_PACKET.Flags], TH_ACK
868
 
833
	jz	.exit
869
	mov	[ebx + SOCKET.TCBState], TCB_ESTABLISHED
834
 
870
  .signal:
Line 835... Line 871...
835
	mov	[ebx + SOCKET.TCBState], TCB_ESTABLISHED
871
	call	signal_network_event
836
 
872
 
837
  .exit:
873
  .exit:
Line -... Line 874...
-
 
874
	ret
-
 
875
endp
-
 
876
 
-
 
877
 
-
 
878
proc stateTCB_ESTABLISHED stdcall, sockAddr:DWORD
-
 
879
	; Here we are expecting data, or a request to close
-
 
880
	; OR both...
-
 
881
 
-
 
882
	; Ignore all packets with sequnce number other than next expected
838
	ret
883
 
839
endp
884
	; recv.nxt is in dword [edx+24], in inet format
840
 
885
	; recv seq is in [sktAddr]+56, in inet format
Line 841... Line 886...
841
 
886
	; just do a comparision
Line 876... Line 921...
876
	popad
921
	popad
Line 877... Line 922...
877
 
922
 
Line 878... Line 923...
878
    @@: ; Send an ACK to that fin, and enter closewait state
923
    @@: ; Send an ACK to that fin, and enter closewait state
-
 
924
 
879
 
925
	mov	[ebx + SOCKET.TCBState], TCB_CLOSE_WAIT
880
	mov	[ebx + SOCKET.TCBState], TCB_CLOSE_WAIT
926
	call	signal_network_event
881
	lea	esi, [ebx + SOCKET.RCV_NXT]
927
	lea	esi, [ebx + SOCKET.RCV_NXT]
882
	mov	eax, [esi]		; save original
928
	mov	eax, [esi]		; save original
Line 898... Line 944...
898
	ja	@f
944
	ja	@f
Line 899... Line 945...
899
 
945
 
Line 900... Line 946...
900
	mov	[ebx + SOCKET.wndsizeTimer], 1
946
	mov	[ebx + SOCKET.wndsizeTimer], 1
901
 
-
 
902
    @@: ; OK, here is the deal
-
 
903
	; My recv.nct field holds the seq of the expected next rec byte
-
 
904
	; if the recevied sequence number is not equal to this, do not
-
 
905
	; increment the recv.nxt field, do not copy data - just send a
-
 
906
	; repeat ack.
-
 
907
 
-
 
908
	; recv.nxt is in dword [edx+24], in inet format
-
 
909
	; recv seq is in [sktAddr]+56, in inet format
-
 
910
	; just do a comparision
-
 
911
	mov	ecx, [ebx + SOCKET.RCV_NXT]
-
 
912
	cmp	[ebx + SOCKET.TCBState], TCB_CLOSE_WAIT
-
 
913
	jne	@f
-
 
914
	mov	ecx, eax
-
 
915
 
-
 
Line 916... Line 947...
916
    @@: cmp	ecx, [edx + 20 + TCP_PACKET.SequenceNumber]
947
 
917
	jne	.ack
948
    @@: ; OK, here is the deal
918
 
949
 
Line 933... Line 964...
933
	add	ebx, SOCKET.lock
964
	add	ebx, SOCKET.lock
934
	call	wait_mutex
965
	call	wait_mutex
935
	pop	ebx
966
	pop	ebx
Line 936... Line 967...
936
 
967
 
937
	push	ecx
968
	push	ecx
938
	push	[ebx + SOCKET.PID]	; get socket owner PID
969
	push	ebx
939
	mov	eax, [ebx + SOCKET.rxDataCount]
970
	mov	eax, [ebx + SOCKET.rxDataCount]
940
	add	eax, ecx
971
	add	eax, ecx
941
	cmp	eax, SOCKETBUFFSIZE - SOCKETHEADERSIZE
972
	cmp	eax, SOCKETBUFFSIZE - SOCKETHEADERSIZE
Line 953... Line 984...
953
	cld
984
	cld
954
	rep	movsb	       ; copy the data across
985
	rep	movsb	       ; copy the data across
955
	mov	[ebx + SOCKET.lock], 0	; release mutex
986
	mov	[ebx + SOCKET.lock], 0	; release mutex
Line 956... Line 987...
956
 
987
 
957
	; flag an event to the application
988
	; flag an event to the application
958
	pop	eax
-
 
959
	mov	ecx, 1
-
 
960
	mov	esi, TASK_DATA + TASKDATA.pid
-
 
961
 
-
 
962
  .next_pid:
-
 
963
	cmp	[esi], eax
-
 
964
	je	.found_pid
-
 
965
	inc	ecx
-
 
966
	add	esi, 0x20
989
	pop	ebx
967
	cmp	ecx, [TASK_COUNT]
-
 
968
	jbe	.next_pid
-
 
969
 
-
 
970
  .found_pid:
-
 
971
	shl	ecx, 8
-
 
Line 972... Line 990...
972
	or	[ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK ; stack event
990
	call	signal_network_event
Line 973... Line 991...
973
 
991
 
974
	pop	ecx
992
	pop	ecx