Rev 593 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 593 | Rev 907 | ||
---|---|---|---|
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: 907 $ |
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 -... | Line 83... | ||
- | 83 | ||
- | 84 | mov ax, [edx + 20 + UDP_PACKET.DestinationPort] ; get the local port from |
|
- | 85 | ; the IP packet's UDP header |
|
84 | ; the IP packet's UDP header |
86 | |
- | 87 | mov ebx, net_sockets_mutex |
|
85 | mov eax, SOCKETBUFFSIZE * NUM_SOCKETS |
88 | call wait_mutex |
- | 89 | mov ebx, net_sockets |
|
- | 90 | ||
86 | mov ecx, NUM_SOCKETS |
91 | .next_socket: |
87 | 92 | mov ebx, [ebx + SOCKET.NextPtr] |
|
88 | fs1: |
93 | or ebx, ebx |
89 | sub eax, SOCKETBUFFSIZE |
- | |
90 | cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value, |
- | |
91 | ; but the comparision is correct |
- | |
92 | loopnz fs1 ; Return back if no match |
- | |
Line 93... | Line -... | ||
93 | jz fs_done |
- | |
94 | 94 | jz .exit ; No match, so exit |
|
95 | ; No match, so exit |
95 | cmp [ebx + SOCKET.LocalPort], ax ; ax will hold the 'wrong' value, |
96 | jmp udprx_001 |
96 | ; but the comparision is correct |
97 | 97 | jne .next_socket ; Return back if no match |
|
98 | fs_done: |
- | |
99 | ; For dhcp, we must allow any remote server to respond. |
98 | |
100 | ; I will accept the first incoming response to be the one |
99 | ; For dhcp, we must allow any remote server to respond. |
101 | ; I bind to, if the socket is opened with a destination IP address of |
100 | ; I will accept the first incoming response to be the one |
102 | ; 255.255.255.255 |
101 | ; I bind to, if the socket is opened with a destination IP address of |
103 | mov ebx, [eax + sockets + 16] |
102 | ; 255.255.255.255 |
104 | cmp ebx, 0xffffffff |
103 | cmp [ebx + SOCKET.RemoteIP], 0xffffffff |
Line 105... | Line -... | ||
105 | je udprx_002 |
- | |
106 | 104 | je @f |
|
107 | mov ebx, [edx + 12] ; get the Source address from the IP packet |
105 | |
108 | cmp [eax + sockets + 16], ebx |
106 | 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 |
107 | cmp [ebx + SOCKET.RemoteIP], ebx |
110 | 108 | jne .exit ; Quit if the source IP is not valid |
|
111 | udprx_002: |
109 | |
112 | ; OK - we have a valid UDP packet for this socket. |
110 | @@: ; OK - we have a valid UDP packet for this socket. |
Line 113... | Line 111... | ||
113 | ; First, update the sockets remote port number with the incoming msg |
111 | ; First, update the sockets remote port number with the incoming msg |
114 | ; - it will have changed |
112 | ; - it will have changed |
Line 115... | Line 113... | ||
115 | ; from the original ( 69 normally ) to allow further connects |
113 | ; from the original ( 69 normally ) to allow further connects |
116 | movzx ebx, word [edx + 20] ; get the UDP source port |
114 | mov ax, [edx + 20 + UDP_PACKET.SourcePort] ; get the UDP source port |
117 | ; ( was 69, now new ) |
115 | ; ( was 69, now new ) |
118 | mov [eax + sockets + 20], bx |
116 | mov [ebx + SOCKET.RemotePort], ax |
Line 119... | Line -... | ||
119 | - | ||
120 | ; Now, copy data to socket. We have socket address as [eax + sockets]. |
117 | |
121 | ; We have IP packet in edx |
- | |
122 | 118 | ; Now, copy data to socket. We have socket address as [eax + sockets]. |
|
123 | ; get # of bytes in ecx |
- | |
Line 124... | Line -... | ||
124 | movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract |
- | |
125 | mov ch, byte [edx + 2] ; 20 + 8 gives data length |
- | |
126 | sub ecx, 28 |
- | |
127 | - | ||
128 | mov ebx, eax |
- | |
129 | add ebx, sockets ; ebx = address of actual socket |
- | |
130 | - | ||
131 | mov eax, [ebx+ 4] ; get socket owner PID |
- | |
132 | push eax |
119 | ; We have IP packet in edx |
Line 133... | Line 120... | ||
133 | 120 | ||
134 | mov eax, [ebx + 24] ; get # of bytes already in buffer |
121 | ; get # of bytes in ecx |
135 | add [ebx + 24], ecx ; increment the count of bytes in buffer |
122 | movzx ecx, [edx + IP_PACKET.TotalLength] ; total length of IP packet. Subtract |
Line 136... | Line 123... | ||
136 | 123 | xchg cl, ch ; 20 + 8 gives data length |
|
137 | ; point to the location to store the data |
124 | sub ecx, 28 |
Line 138... | Line 125... | ||
138 | add ebx, eax |
125 | |
139 | add ebx, SOCKETHEADERSIZE |
126 | mov eax, [ebx + SOCKET.rxDataCount] ; get # of bytes already in buffer |
140 | 127 | add [ebx + SOCKET.rxDataCount], ecx ; increment the count of bytes in buffer |
|
141 | ; ebx = location for first byte, ecx has count, |
128 | |
Line 142... | Line 129... | ||
142 | ; edx points to data |
129 | ; ecx has count, edx points to data |
143 | 130 | ||
144 | add edx, 28 ; edx now points to the data |
131 | add edx, 28 ; edx now points to the data |
145 | mov edi, ebx |
132 | lea edi, [ebx + eax + SOCKETHEADERSIZE] |
146 | mov esi, edx |
133 | mov esi, edx |
147 | 134 | ||
148 | cld |
135 | cld |
- | 136 | rep movsb ; copy the data across |
|
- | 137 | ||
Line 149... | Line 138... | ||
149 | rep movsb ; copy the data across |
138 | ; flag an event to the application |
150 | 139 | mov eax, [ebx + SOCKET.PID] ; get socket owner PID |
|
151 | ; flag an event to the application |
140 | mov ecx, 1 |
Line 152... | Line 141... | ||
152 | pop eax |
141 | mov esi, TASK_DATA + TASKDATA.pid |
Line 153... | Line 142... | ||
153 | mov ecx,1 |
142 | |
154 | mov esi,TASK_DATA+TASKDATA.pid |
143 | .next_pid: |
155 | 144 | cmp [esi], eax |
|
156 | newsearch: |
145 | je .found_pid |
- | 146 | inc ecx |