Rev 380 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 380 | Rev 425 | ||
---|---|---|---|
- | 1 | $Revision: 425 $ |
|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
3 | ;; ;; |
3 | ;; UDP.INC ;; |
4 | ;; UDP.INC ;; |
4 | ;; ;; |
5 | ;; ;; |
5 | ;; UDP Processes for Menuet OS TCP/IP stack ;; |
6 | ;; UDP Processes for Menuet OS TCP/IP stack ;; |
6 | ;; ;; |
7 | ;; ;; |
7 | ;; Version 0.3 29 August 2002 ;; |
8 | ;; Version 0.3 29 August 2002 ;; |
8 | ;; ;; |
9 | ;; ;; |
9 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
10 | ;; Copyright 2002 Mike Hibbett, mikeh@oceanfree.net ;; |
10 | ;; ;; |
11 | ;; ;; |
11 | ;; See file COPYING for details ;; |
12 | ;; See file COPYING for details ;; |
12 | ;; ;; |
13 | ;; ;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
14 | 15 | ||
15 | 16 | ||
16 | ;******************************************************************* |
17 | ;******************************************************************* |
17 | ; Interface |
18 | ; Interface |
18 | ; |
19 | ; |
19 | ; udp_rx Handles received IP packets with the UDP protocol |
20 | ; udp_rx Handles received IP packets with the UDP protocol |
20 | ; |
21 | ; |
21 | ;******************************************************************* |
22 | ;******************************************************************* |
22 | 23 | ||
23 | 24 | ||
24 | ; |
25 | ; |
25 | ; UDP Payload ( Data field in IP datagram ) |
26 | ; UDP Payload ( Data field in IP datagram ) |
26 | ; |
27 | ; |
27 | ; 0 1 2 3 |
28 | ; 0 1 2 3 |
28 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
29 | ; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
29 | ; |
30 | ; |
30 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
31 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
31 | ; | Source Port | Destination Port | |
32 | ; | Source Port | Destination Port | |
32 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
33 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
33 | ; | Length ( UDP Header + Data ) | Checksum | |
34 | ; | Length ( UDP Header + Data ) | Checksum | |
34 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
35 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
35 | ; | UDP Data | |
36 | ; | UDP Data | |
36 | ; +-+-+-.......... -+ |
37 | ; +-+-+-.......... -+ |
37 | ; |
38 | ; |
38 | 39 | ||
39 | struc UDP_PACKET |
40 | struc UDP_PACKET |
40 | { .SourcePort dw ? ;+00 |
41 | { .SourcePort dw ? ;+00 |
41 | .DestinationPort dw ? ;+02 |
42 | .DestinationPort dw ? ;+02 |
42 | .Length dw ? ;+04 - Length of (UDP Header + Data) |
43 | .Length dw ? ;+04 - Length of (UDP Header + Data) |
43 | .Checksum dw ? ;+06 |
44 | .Checksum dw ? ;+06 |
44 | .Data db ? ;+08 |
45 | .Data db ? ;+08 |
45 | } |
46 | } |
46 | 47 | ||
47 | virtual at 0 |
48 | virtual at 0 |
48 | UDP_PACKET UDP_PACKET |
49 | UDP_PACKET UDP_PACKET |
49 | end virtual |
50 | end virtual |
50 | 51 | ||
51 | 52 | ||
52 | ;*************************************************************************** |
53 | ;*************************************************************************** |
53 | ; Function |
54 | ; Function |
54 | ; udp_rx [by Johnny_B] |
55 | ; udp_rx [by Johnny_B] |
55 | ; |
56 | ; |
56 | ; Description |
57 | ; Description |
57 | ; UDP protocol handler |
58 | ; UDP protocol handler |
58 | ; This is a kernel function, called by ip_rx |
59 | ; This is a kernel function, called by ip_rx |
59 | ; IP buffer address given in edx |
60 | ; IP buffer address given in edx |
60 | ; IP buffer number in eax |
61 | ; IP buffer number in eax |
61 | ; Free up (or re-use) IP buffer when finished |
62 | ; Free up (or re-use) IP buffer when finished |
62 | ; |
63 | ; |
63 | ;*************************************************************************** |
64 | ;*************************************************************************** |
64 | udp_rx: |
65 | udp_rx: |
65 | push eax |
66 | push eax |
66 | 67 | ||
67 | ; First validate the header & checksum. Discard buffer if error |
68 | ; First validate the header & checksum. Discard buffer if error |
68 | 69 | ||
69 | ; Look for a socket where |
70 | ; Look for a socket where |
70 | ; IP Packet UDP Destination Port = local Port |
71 | ; IP Packet UDP Destination Port = local Port |
71 | ; IP Packet SA = Remote IP |
72 | ; IP Packet SA = Remote IP |
72 | 73 | ||
73 | movzx ebx, word [edx + 22] ; get the local port from |
74 | movzx ebx, word [edx + 22] ; get the local port from |
74 | ; the IP packet's UDP header |
75 | ; the IP packet's UDP header |
75 | mov eax, SOCKETBUFFSIZE * NUM_SOCKETS |
76 | mov eax, SOCKETBUFFSIZE * NUM_SOCKETS |
76 | mov ecx, NUM_SOCKETS |
77 | mov ecx, NUM_SOCKETS |
77 | 78 | ||
78 | fs1: |
79 | fs1: |
79 | sub eax, SOCKETBUFFSIZE |
80 | sub eax, SOCKETBUFFSIZE |
80 | cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value, |
81 | cmp [eax + sockets + 12], bx ; bx will hold the 'wrong' value, |
81 | ; but the comparision is correct |
82 | ; but the comparision is correct |
82 | loopnz fs1 ; Return back if no match |
83 | loopnz fs1 ; Return back if no match |
83 | jz fs_done |
84 | jz fs_done |
84 | 85 | ||
85 | ; No match, so exit |
86 | ; No match, so exit |
86 | jmp udprx_001 |
87 | jmp udprx_001 |
87 | 88 | ||
88 | fs_done: |
89 | fs_done: |
89 | ; For dhcp, we must allow any remote server to respond. |
90 | ; For dhcp, we must allow any remote server to respond. |
90 | ; I will accept the first incoming response to be the one |
91 | ; I will accept the first incoming response to be the one |
91 | ; I bind to, if the socket is opened with a destination IP address of |
92 | ; I bind to, if the socket is opened with a destination IP address of |
92 | ; 255.255.255.255 |
93 | ; 255.255.255.255 |
93 | mov ebx, [eax + sockets + 16] |
94 | mov ebx, [eax + sockets + 16] |
94 | cmp ebx, 0xffffffff |
95 | cmp ebx, 0xffffffff |
95 | je udprx_002 |
96 | je udprx_002 |
96 | 97 | ||
97 | mov ebx, [edx + 12] ; get the Source address from the IP packet |
98 | mov ebx, [edx + 12] ; get the Source address from the IP packet |
98 | cmp [eax + sockets + 16], ebx |
99 | cmp [eax + sockets + 16], ebx |
99 | jne udprx_001 ; Quit if the source IP is not valid |
100 | jne udprx_001 ; Quit if the source IP is not valid |
100 | 101 | ||
101 | udprx_002: |
102 | udprx_002: |
102 | ; OK - we have a valid UDP packet for this socket. |
103 | ; OK - we have a valid UDP packet for this socket. |
103 | ; First, update the sockets remote port number with the incoming msg |
104 | ; First, update the sockets remote port number with the incoming msg |
104 | ; - it will have changed |
105 | ; - it will have changed |
105 | ; from the original ( 69 normally ) to allow further connects |
106 | ; from the original ( 69 normally ) to allow further connects |
106 | movzx ebx, word [edx + 20] ; get the UDP source port |
107 | movzx ebx, word [edx + 20] ; get the UDP source port |
107 | ; ( was 69, now new ) |
108 | ; ( was 69, now new ) |
108 | mov [eax + sockets + 20], bx |
109 | mov [eax + sockets + 20], bx |
109 | 110 | ||
110 | ; Now, copy data to socket. We have socket address as [eax + sockets]. |
111 | ; Now, copy data to socket. We have socket address as [eax + sockets]. |
111 | ; We have IP packet in edx |
112 | ; We have IP packet in edx |
112 | 113 | ||
113 | ; get # of bytes in ecx |
114 | ; get # of bytes in ecx |
114 | movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract |
115 | movzx ecx, byte [edx + 3] ; total length of IP packet. Subtract |
115 | mov ch, byte [edx + 2] ; 20 + 8 gives data length |
116 | mov ch, byte [edx + 2] ; 20 + 8 gives data length |
116 | sub ecx, 28 |
117 | sub ecx, 28 |
117 | 118 | ||
118 | mov ebx, eax |
119 | mov ebx, eax |
119 | add ebx, sockets ; ebx = address of actual socket |
120 | add ebx, sockets ; ebx = address of actual socket |
120 | 121 | ||
121 | mov eax, [ebx+ 4] ; get socket owner PID |
122 | mov eax, [ebx+ 4] ; get socket owner PID |
122 | push eax |
123 | push eax |
123 | 124 | ||
124 | mov eax, [ebx + 24] ; get # of bytes already in buffer |
125 | mov eax, [ebx + 24] ; get # of bytes already in buffer |
125 | add [ebx + 24], ecx ; increment the count of bytes in buffer |
126 | add [ebx + 24], ecx ; increment the count of bytes in buffer |
126 | 127 | ||
127 | ; point to the location to store the data |
128 | ; point to the location to store the data |
128 | add ebx, eax |
129 | add ebx, eax |
129 | add ebx, SOCKETHEADERSIZE |
130 | add ebx, SOCKETHEADERSIZE |
130 | 131 | ||
131 | ; ebx = location for first byte, ecx has count, |
132 | ; ebx = location for first byte, ecx has count, |
132 | ; edx points to data |
133 | ; edx points to data |
133 | 134 | ||
134 | add edx, 28 ; edx now points to the data |
135 | add edx, 28 ; edx now points to the data |
135 | mov edi, ebx |
136 | mov edi, ebx |
136 | mov esi, edx |
137 | mov esi, edx |
137 | 138 | ||
138 | cld |
139 | cld |
139 | rep movsb ; copy the data across |
140 | rep movsb ; copy the data across |
140 | 141 | ||
141 | ; flag an event to the application |
142 | ; flag an event to the application |
142 | pop eax |
143 | pop eax |
143 | mov ecx,1 |
144 | mov ecx,1 |
144 | mov esi,TASK_DATA+TASKDATA.pid |
145 | mov esi,TASK_DATA+TASKDATA.pid |
145 | 146 | ||
146 | newsearch: |
147 | newsearch: |
147 | cmp [esi],eax |
148 | cmp [esi],eax |
148 | je foundPID |
149 | je foundPID |
149 | inc ecx |
150 | inc ecx |
150 | add esi,0x20 |
151 | add esi,0x20 |
151 | cmp ecx,[TASK_COUNT] |
152 | cmp ecx,[TASK_COUNT] |
152 | jbe newsearch |
153 | jbe newsearch |
153 | 154 | ||
154 | foundPID: |
155 | foundPID: |
155 | shl ecx,8 |
156 | shl ecx,8 |
156 | or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event |
157 | or dword [ecx+SLOT_BASE+APPDATA.event_mask],dword 10000000b ; stack event |
157 | 158 | ||
158 | mov [check_idle_semaphore],200 |
159 | mov [check_idle_semaphore],200 |
159 | 160 | ||
160 | udprx_001: |
161 | udprx_001: |
161 | pop eax |
162 | pop eax |
162 | call freeBuff ; Discard the packet |
163 | call freeBuff ; Discard the packet |
163 | ret |
164 | ret |