Rev 1473 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1473 | Rev 1482 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
Line 17... | Line 17... | ||
17 | $Revision: 1473 $ |
17 | $Revision: 1482 $ |
18 | 18 | ||
19 | 19 | ||
Line 65... | Line 65... | ||
65 | ; |
65 | ; |
66 | ; IN: Pointer to buffer in [esp] |
66 | ; IN: Pointer to buffer in [esp] |
67 | ; size of buffer in [esp+4] |
67 | ; size of buffer in [esp+4] |
68 | ; pointer to device struct in ebx |
68 | ; pointer to device struct in ebx |
69 | ; UDP Packet size in ecx |
69 | ; UDP Packet size in ecx |
70 | ; pointer to UDP Packet data in edx |
70 | ; pointer to UDP Packet in edx |
71 | ; OUT: / |
71 | ; OUT: / |
72 | ; |
72 | ; |
73 | ;----------------------------------------------------------------- |
73 | ;----------------------------------------------------------------- |
74 | align 4 |
74 | align 4 |
75 | UDP_handler: |
75 | UDP_handler: |
Line 76... | Line 76... | ||
76 | 76 | ||
Line -... | Line 77... | ||
- | 77 | DEBUGF 1,"UDP_Handler, checksum:%x\n", [edx+UDP_Packet.Checksum]:4 |
|
77 | DEBUGF 1,"UDP_Handler\n" |
78 | |
78 | 79 | ; First validate, checksum: |
|
79 | cmp [edx + UDP_Packet.Checksum], 0 |
- | |
Line 80... | Line 80... | ||
80 | jz .no_checksum |
80 | cmp [edx + UDP_Packet.Checksum], 0 |
Line 81... | Line -... | ||
81 | ; First validate, checksum: |
- | |
82 | - | ||
83 | pusha |
- | |
84 | - | ||
85 | push cx |
81 | jz .no_checksum |
86 | rol word [esp], 8 |
- | |
87 | push word IP_PROTO_UDP shl 8 |
- | |
88 | push edi |
82 | |
89 | push esi |
- | |
90 | 83 | push ecx edx |
|
91 | mov di, [edx + UDP_Packet.Checksum] |
- | |
92 | mov [edx + UDP_Packet.Checksum], 0 |
- | |
93 | - | ||
94 | mov esi, edx |
84 | |
Line 95... | Line 85... | ||
95 | xor edx, edx |
85 | push esi |
96 | call checksum_1 |
- | |
97 | call checksum_pseudoheader |
- | |
Line -... | Line 86... | ||
- | 86 | push edi |
|
- | 87 | mov esi, edx |
|
Line 98... | Line 88... | ||
98 | call checksum_2 |
88 | call UDP_checksum |
99 | - | ||
100 | cmp di, dx |
89 | |
Line 101... | Line 90... | ||
101 | popa |
90 | pop edx ecx |
102 | jne .checksum_mismatch ;dump |
91 | |
103 | 92 | cmp [edx + UDP_Packet.Checksum], 0 |
|
Line 188... | Line 177... | ||
188 | 177 | ||
Line 189... | Line 178... | ||
189 | .checksum_mismatch: |
178 | .checksum_mismatch: |
Line 190... | Line 179... | ||
190 | 179 | ||
191 | DEBUGF 2,"UDP_Handler - checksum mismatch\n" |
- | |
192 | 180 | DEBUGF 2,"UDP_Handler - checksum mismatch\n" |
|
193 | mov esi, [esp] |
181 | |
194 | mov ecx, [esp + 4] |
182 | ; mov esi, edx |
195 | @@: ; |
183 | ; @@: ; |
Line 196... | Line 184... | ||
196 | lodsb ; |
184 | ; lodsb ; |
197 | DEBUGF 2,"%x ", eax:2 ; |
185 | ; DEBUGF 2,"%x ", eax:2 ; |
198 | loop @r ; |
186 | ; loop @r ; |
199 | 187 | ||
Line 228... | Line 216... | ||
228 | mov eax, [eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP] |
216 | mov eax, [eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP] |
Line 229... | Line 217... | ||
229 | 217 | ||
Line 230... | Line 218... | ||
230 | DEBUGF 1,"Create UDP Packet (size=%u)\n",ecx |
218 | DEBUGF 1,"Create UDP Packet (size=%u)\n",ecx |
231 | 219 | ||
232 | mov di , IP_PROTO_UDP |
- | |
233 | sub esp, 8 ; reserve some place in stack for later |
- | |
234 | ; Create a part of the pseudoheader in stack, |
220 | mov di , IP_PROTO_UDP |
Line 235... | Line 221... | ||
235 | push dword IP_PROTO_UDP shl 8 |
221 | sub esp, 8 ; Data ptr and data size will be placed here |
Line 236... | Line 222... | ||
236 | add ecx, UDP_Packet.Data |
222 | add ecx, UDP_Packet.Data |
237 | 223 | ||
238 | ; TODO: fill in: dx = fragment id |
224 | ; TODO: fill in: dx = fragment id |
239 | 225 | ||
Line 240... | Line 226... | ||
240 | push edx esi |
226 | push edx esi |
241 | call IPv4_create_packet ; TODO: figure out a way to choose between IPv4 and IPv6 |
227 | call IPv4_create_packet ; TODO: figure out a way to choose between IPv4 and IPv6 |
Line 242... | Line 228... | ||
242 | cmp edi, -1 |
228 | cmp edi, -1 |
243 | je .fail |
229 | je .fail |
244 | - | ||
245 | mov [esp + 8 + 4], eax ; pointer to buffer start |
230 | |
Line 246... | Line 231... | ||
246 | mov [esp + 8 + 4 + 4], edx ; buffer size |
231 | mov [esp + 8], eax ; pointer to buffer start |
247 | 232 | mov [esp + 8 + 4], edx ; buffer size |
|
248 | rol cx, 8 |
233 | |
Line 262... | Line 247... | ||
262 | pop ecx edi |
247 | pop ecx edi |
Line 263... | Line 248... | ||
263 | 248 | ||
264 | pop dword [edi + UDP_Packet.SourcePort] ; fill in both portnumbers |
249 | pop dword [edi + UDP_Packet.SourcePort] ; fill in both portnumbers |
Line 265... | Line -... | ||
265 | mov [edi + UDP_Packet.Checksum], 0 ; set it to zero, to calculate checksum |
- | |
266 | 250 | mov [edi + UDP_Packet.Checksum], 0 ; set it to zero, to calculate checksum |
|
267 | ; Checksum for UDP header + data |
251 | |
268 | xor edx, edx |
- | |
269 | mov esi, edi |
- | |
270 | call checksum_1 |
252 | ; Checksum |
271 | ; Checksum for pseudoheader |
253 | mov esi, edi |
272 | pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options.. |
- | |
273 | pushd [edi-8] ; source address |
- | |
274 | call checksum_pseudoheader |
254 | pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options.. |
275 | ; Now create the final checksum and store it in UDP header |
- | |
Line 276... | Line 255... | ||
276 | call checksum_2 |
255 | pushd [edi-8] ; source address |
Line 277... | Line 256... | ||
277 | mov [edi + UDP_Packet.Checksum], dx |
256 | call UDP_checksum |
278 | 257 | ||
Line 279... | Line 258... | ||
279 | inc [UDP_PACKETS_TX] |
258 | inc [UDP_PACKETS_TX] |
280 | 259 | ||
281 | DEBUGF 1,"Sending UDP Packet to device %x\n", ebx ; |
260 | DEBUGF 1,"Sending UDP Packet to device %x\n", ebx |
282 | jmp ETH_sender ; |
261 | jmp ETH_sender |
Line -... | Line 262... | ||
- | 262 | ||
- | 263 | .fail: |
|
- | 264 | ; todo: queue the packet |
|
- | 265 | add esp, 8+12+8 |
|
- | 266 | ret |
|
- | 267 | ||
- | 268 | ||
- | 269 | ||
- | 270 | ||
- | 271 | ;----------------------------------------------------------------- |
|
- | 272 | ; |
|
- | 273 | ; checksum_udp |
|
- | 274 | ; |
|
- | 275 | ; This is the fast procedure to create or check a UDP header |
|
- | 276 | ; - To create a new checksum, the checksum field must be set to 0 before computation |
|
- | 277 | ; - To check an existing checksum, leave the checksum as is, |
|
- | 278 | ; and it will be 0 after this procedure, if it was correct |
|
- | 279 | ; |
|
- | 280 | ; IN: push source ip |
|
- | 281 | ; push dest ip |
|
- | 282 | ; esi = packet ptr |
|
- | 283 | ; |
|
- | 284 | ; OUT: checksum is filled in in packet! (but also in dx) |
|
- | 285 | ; |
|
- | 286 | ;----------------------------------------------------------------- |
|
- | 287 | ||
- | 288 | align 4 |
|
- | 289 | UDP_checksum: |
|
- | 290 | ||
- | 291 | ; Pseudoheader |
|
- | 292 | mov edx, IP_PROTO_UDP ; NO shl 8 here ! (it took me ages to figure this one out) |
|
- | 293 | ||
- | 294 | add dl, [esp+1+4] |
|
- | 295 | adc dh, [esp+0+4] |
|
- | 296 | adc dl, [esp+3+4] |
|
- | 297 | adc dh, [esp+2+4] |
|
- | 298 | ||
- | 299 | adc dl, [esp+1+8] |
|
- | 300 | adc dh, [esp+0+8] |
|
- | 301 | adc dl, [esp+3+8] |
|
- | 302 | adc dh, [esp+2+8] |
|
- | 303 | ||
- | 304 | adc dl, byte[esi+UDP_Packet.Length+1] |
|
- | 305 | adc dh, byte[esi+UDP_Packet.Length+0] |
|
- | 306 | ||
- | 307 | ; Done with pseudoheader, now do real header |
|
- | 308 | adc dl, byte[esi+UDP_Packet.SourcePort+1] |
|
- | 309 | adc dh, byte[esi+UDP_Packet.SourcePort+0] |
|
- | 310 | ||
- | 311 | adc dl, byte[esi+UDP_Packet.DestinationPort+1] |
|
- | 312 | adc dh, byte[esi+UDP_Packet.DestinationPort+0] |
|
- | 313 | ||
- | 314 | adc dl, byte[esi+UDP_Packet.Length+1] |
|
- | 315 | adc dh, byte[esi+UDP_Packet.Length+0] |
|
- | 316 | ||
- | 317 | adc edx, 0 |
|
- | 318 | ||
- | 319 | ; Done with header, now do data |
|
- | 320 | push esi |
|
- | 321 | movzx ecx, [esi+UDP_Packet.Length] |
|
- | 322 | rol cx , 8 |
|
- | 323 | sub cx , UDP_Packet.Data |
|
- | 324 | add esi, UDP_Packet.Data |
|
- | 325 | ||
- | 326 | call checksum_1 |
|
- | 327 | call checksum_2 |
|
- | 328 | pop esi |
|
283 | 329 | ||
284 | .fail: |
330 | neg [esi+UDP_Packet.Checksum] ; zero will stay zero so we just get the checksum |
285 | ; todo: queue the packet |
331 | add [esi+UDP_Packet.Checksum], dx ; , else we will get (new checksum - old checksum) in the end, wich should be 0 :) |
286 | add esp, 8+12+8 |
332 | |
287 | ret |
333 | ret 8 |