Subversion Repositories Kolibri OS

Rev

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

Rev 837 Rev 914
Line 18... Line 18...
18
;;                                                              ;;
18
;;                                                              ;;
19
;;  See file COPYING for details                                ;;
19
;;  See file COPYING for details                                ;;
20
;;                                                              ;;
20
;;                                                              ;;
21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 22... Line 22...
22
 
22
 
Line 23... Line 23...
23
$Revision: 593 $
23
$Revision: 914 $
24
 
24
 
25
 
25
 
Line 69... Line 69...
69
;       IP buffer address given in edx
69
;       IP buffer address given in edx
70
;          IP buffer number in eax
70
;          IP buffer number in eax
71
;          Free up (or re-use) IP buffer when finished
71
;          Free up (or re-use) IP buffer when finished
72
;
72
;
73
;***************************************************************************
73
;***************************************************************************
-
 
74
 
74
udp_rx:
75
proc udp_rx stdcall
75
    push    eax
76
    push    eax
Line 76... Line 77...
76
 
77
 
Line 77... Line 78...
77
    ; First validate the header & checksum. Discard buffer if error
78
    ; First validate the header & checksum. Discard buffer if error
78
 
79
 
79
    ; Look for a socket where
80
    ; Look for a socket where
Line 80... Line 81...
80
    ; IP Packet UDP Destination Port = local Port
81
    ; IP Packet UDP Destination Port = local Port
81
    ; IP Packet SA = Remote IP
82
    ; IP Packet SA = Remote IP
82
 
-
 
83
    movzx   ebx, word [edx + 22]   ; get the local port from
-
 
Line 84... Line -...
84
                                  ; the IP packet's UDP header
-
 
85
    mov     eax, SOCKETBUFFSIZE * NUM_SOCKETS
-
 
86
    mov     ecx, NUM_SOCKETS
-
 
87
 
-
 
88
fs1:
-
 
89
    sub     eax, SOCKETBUFFSIZE
83
 
Line -... Line 84...
-
 
84
	mov	ax, [edx + 20 + UDP_PACKET.DestinationPort]   ; get the local port from
-
 
85
                                  ; the IP packet's UDP header
-
 
86
 
90
    cmp     [eax + sockets + 12], bx ; bx will hold the 'wrong' value,
87
	mov	ebx, net_sockets
-
 
88
 
91
                                    ; but the comparision is correct
89
  .next_socket:
-
 
90
	mov	ebx, [ebx + SOCKET.NextPtr]
Line 92... Line -...
92
    loopnz  fs1                     ; Return back if no match
-
 
93
    jz      fs_done
91
	or	ebx, ebx
94
 
92
	jz	.exit					; No match, so exit
95
    ; No match, so exit
93
	cmp	[ebx + SOCKET.LocalPort], ax		; ax will hold the 'wrong' value,
96
    jmp     udprx_001
94
                                    ; but the comparision is correct
97
 
-
 
98
fs_done:
95
	jne	.next_socket				; Return back if no match
99
    ; For dhcp, we must allow any remote server to respond.
-
 
100
    ; I will accept the first incoming response to be the one
96
 
101
    ; I bind to, if the socket is opened with a destination IP address of
-
 
102
    ; 255.255.255.255
-
 
103
    mov     ebx, [eax + sockets + 16]
-
 
Line -... Line 97...
-
 
97
    ; For dhcp, we must allow any remote server to respond.
104
    cmp     ebx, 0xffffffff
98
    ; I will accept the first incoming response to be the one
-
 
99
    ; I bind to, if the socket is opened with a destination IP address of
-
 
100
    ; 255.255.255.255
105
    je      udprx_002
101
	cmp	[ebx + SOCKET.RemoteIP], 0xffffffff
106
 
102
	je	@f
107
    mov     ebx, [edx + 12]    ; get the Source address from the IP packet
103
 
108
    cmp     [eax + sockets + 16], ebx
104
	mov	eax, [edx + IP_PACKET.SourceAddress]	; get the Source address from the IP packet
109
    jne     udprx_001          ; Quit if the source IP is not valid
105
	cmp	[ebx + SOCKET.RemoteIP], ebx
110
 
106
	jne	.exit		   ; Quit if the source IP is not valid
111
udprx_002:
107
 
Line 112... Line 108...
112
    ; OK - we have a valid UDP packet for this socket.
108
    @@: ; OK - we have a valid UDP packet for this socket.
113
    ; First, update the sockets remote port number with the incoming msg
109
    ; First, update the sockets remote port number with the incoming msg
Line 114... Line 110...
114
    ; - it will have changed
110
    ; - it will have changed
115
    ; from the original ( 69 normally ) to allow further connects
111
    ; from the original ( 69 normally ) to allow further connects
116
    movzx   ebx, word [edx + 20]      ; get the UDP source port
112
	mov	ax, [edx + 20 + UDP_PACKET.SourcePort]		; get the UDP source port
117
                                     ; ( was 69, now new )
113
                                     ; ( was 69, now new )
Line 118... Line -...
118
    mov     [eax + sockets + 20], bx
-
 
119
 
-
 
120
    ; Now, copy data to socket. We have socket address as [eax + sockets].
-
 
121
    ; We have IP packet in edx
-
 
122
 
-
 
123
    ; get # of bytes in ecx
-
 
124
    movzx   ecx, byte [edx + 3]  ; total length of IP packet. Subtract
114
	mov	[ebx + SOCKET.RemotePort], ax
125
    mov     ch, byte [edx + 2]   ; 20 + 8 gives data length
115
 
126
    sub     ecx, 28
-
 
127
 
-
 
128
    mov     ebx, eax
-
 
129
    add     ebx, sockets         ; ebx = address of actual socket
-
 
Line 130... Line -...
130
 
-
 
131
    mov     eax, [ebx+ 4]       ; get socket owner PID
116
    ; Now, copy data to socket. We have socket address as [eax + sockets].
Line 132... Line 117...
132
    push    eax
117
    ; We have IP packet in edx
133
 
118
 
134
    mov     eax, [ebx + 24]      ; get # of bytes already in buffer
119
    ; get # of bytes in ecx
Line 135... Line 120...
135
    add     [ebx + 24], ecx      ; increment the count of bytes in buffer
120
	movzx	ecx, [edx + IP_PACKET.TotalLength]	; total length of IP packet. Subtract
136
 
121
	xchg	cl, ch					; 20 + 8 gives data length
Line 137... Line 122...
137
    ; point to the location to store the data
122
    sub     ecx, 28
138
    add     ebx, eax
123
 
139
    add     ebx, SOCKETHEADERSIZE
124
	mov	eax, [ebx + SOCKET.rxDataCount] 	; get # of bytes already in buffer
140
 
125
	add	[ebx + SOCKET.rxDataCount], ecx 	; increment the count of bytes in buffer
Line 141... Line 126...
141
    ; ebx = location for first byte, ecx has count,
126
 
142
    ; edx points to data
127
	; ecx has count, edx points to data
143
 
128
 
144
    add     edx, 28        ; edx now points to the data
129
    add     edx, 28        ; edx now points to the data
145
    mov     edi, ebx
130
	lea	edi, [ebx + eax + SOCKETHEADERSIZE]
146
    mov     esi, edx
131
    mov     esi, edx
147
 
132
 
-
 
133
    cld
-
 
134
    rep     movsb          ; copy the data across
Line 148... Line 135...
148
    cld
135
 
149
    rep     movsb          ; copy the data across
136
    ; flag an event to the application
150
 
137
	mov	eax, [ebx + SOCKET.PID] 		; get socket owner PID
Line 151... Line 138...
151
    ; flag an event to the application
138
	mov	ecx, 1
Line 152... Line 139...
152
    pop     eax
139
	mov	esi, TASK_DATA + TASKDATA.pid
153
    mov     ecx,1
140
 
154
    mov     esi,TASK_DATA+TASKDATA.pid
141
  .next_pid:
155
 
142
	cmp	[esi], eax
-
 
143
	je	.found_pid