Rev 3340 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3340 | Rev 3361 | ||
---|---|---|---|
Line 237... | Line 237... | ||
237 | DEBUGF 1,"->Building request\n" |
237 | DEBUGF 1,"->Building request\n" |
Line 238... | Line 238... | ||
238 | 238 | ||
239 | stdcall mem.Alloc, BUFFER |
239 | stdcall mem.Alloc, BUFFER |
240 | mov [dhcpMsg], eax |
240 | mov [dhcpMsg], eax |
241 | test eax, eax |
241 | test eax, eax |
Line 242... | Line 242... | ||
242 | jz apipa |
242 | jz dhcp_error |
Line 243... | Line 243... | ||
243 | 243 | ||
244 | ;;; todo: skip this bullcrap |
244 | ;;; todo: skip this bullcrap |
Line 250... | Line 250... | ||
250 | 250 | ||
Line 251... | Line 251... | ||
251 | ;; todo: put this in a buffer instead of writing bytes and words! |
251 | ;; todo: put this in a buffer instead of writing bytes and words! |
Line -... | Line 252... | ||
- | 252 | ||
252 | 253 | mov edx, [dhcpMsg] |
|
253 | mov edx, [dhcpMsg] |
254 | |
254 | 255 | ; Boot protocol legacy |
|
255 | mov [edx], byte 0x01 ; Boot request |
256 | mov [edx], byte 0x01 ; Boot request |
256 | mov [edx+1], byte 0x01 ; Ethernet |
257 | mov [edx+1], byte 0x01 ; Ethernet |
Line 261... | Line 262... | ||
261 | mov [edx+10], byte 0x80 ; broadcast flag set |
262 | mov [edx+10], byte 0x80 ; broadcast flag set |
262 | mov eax, dword [MAC] ; first 4 bytes of MAC |
263 | mov eax, dword [MAC] ; first 4 bytes of MAC |
263 | mov [edx+28],dword eax |
264 | mov [edx+28],dword eax |
264 | mov ax, word [MAC+4] ; last 2 bytes of MAC |
265 | mov ax, word [MAC+4] ; last 2 bytes of MAC |
265 | mov [edx+32],word ax |
266 | mov [edx+32],word ax |
- | 267 | ||
- | 268 | ; DHCP extension |
|
266 | mov [edx+236], dword 0x63538263 ; magic cookie |
269 | mov [edx+236], dword 0x63538263 ; magic cookie |
267 | mov [edx+240], word 0x0135 ; option DHCP msg type |
270 | mov [edx+240], word 0x0135 ; option DHCP msg type |
268 | mov al, [dhcpMsgType] |
271 | mov al, [dhcpMsgType] |
269 | mov [edx+240+2], al |
272 | mov [edx+240+2], al |
270 | mov [edx+240+3], word 0x0433 ; option Lease time = infinity |
273 | mov [edx+240+3], word 0x0433 ; option Lease time = infinity |
Line 305... | Line 308... | ||
305 | mcall 75, 7, [socketNum], [dhcpMsg], BUFFER ; read data from socket |
308 | mcall 75, 7, [socketNum], [dhcpMsg], BUFFER ; read data from socket |
Line 306... | Line 309... | ||
306 | 309 | ||
Line 307... | Line 310... | ||
307 | DEBUGF 1,"->%d bytes received\n", eax |
310 | DEBUGF 1,"->%d bytes received\n", eax |
308 | 311 | ||
Line 309... | Line 312... | ||
309 | cmp eax, -1 |
312 | cmp eax, -1 |
Line 310... | Line 313... | ||
310 | je error |
313 | je dhcp_error |
311 | 314 | ||
Line 343... | Line 346... | ||
343 | mov [dhcpMsgType], 0x03 ; make it a request |
346 | mov [dhcpMsgType], 0x03 ; make it a request |
344 | jmp build_request |
347 | jmp build_request |
Line 345... | Line 348... | ||
345 | 348 | ||
346 | request: |
349 | request: |
347 | call parse_response |
- | |
Line 348... | Line 350... | ||
348 | call dhcp_end |
350 | call parse_response |
349 | 351 | ||
- | 352 | cmp [dhcpMsgType], 0x05 ; Was the response an ACK? It should be |
|
- | 353 | jne read_data ; NO - read next packets |
|
Line 350... | Line 354... | ||
350 | cmp [dhcpMsgType], 0x05 ; Was the response an ACK? It should be |
354 | |
351 | jne link_local ; NO - so we do link-local |
355 | call dhcp_end |
352 | 356 | ||
353 | mcall 76, API_IPv4 + 3, [dhcp.ip] ; ip |
357 | mcall 76, API_IPv4 + 3, [dhcp.ip] ; ip |
Line 477... | Line 481... | ||
477 | .done: |
481 | .done: |
478 | ret |
482 | ret |
Line 479... | Line 483... | ||
479 | 483 | ||
480 | - | ||
481 | 484 | ||
482 | apipa: |
- | |
Line 483... | Line 485... | ||
483 | mcall close, [socketNum] |
485 | |
484 | stdcall mem.Free, [dhcpMsg] |
486 | dhcp_error: |
485 | - | ||
486 | 487 | call dhcp_end |
|
- | 488 | ||
- | 489 | link_local: |
|
487 | link_local: |
490 | call random |
488 | call random |
491 | mov cx, ax |
489 | mov ecx, 0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 |
492 | shl ecx, 16 |
490 | mov cx, ax |
493 | mov cx, 0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 |
491 | mcall 76, API_IPv4 + 3, ecx ; mask is 255.255.0.0 |
494 | mcall 76, API_IPv4 + 3, ecx ; mask is 255.255.0.0 |
Line 492... | Line 495... | ||
492 | DEBUGF 1,"Link Local IP assinged: 169.254.%u.%u\n", [generator+2]:1, [generator+3]:1 |
495 | DEBUGF 1,"Link Local IP assinged: 169.254.%u.%u\n", [generator+2]:1, [generator+3]:1 |
Line 493... | Line 496... | ||
493 | mcall 76, API_IPv4 + 5, 0xffff |
496 | mcall 76, API_IPv4 + 7, 0xffff |
494 | mcall 76, API_IPv4 + 9, 0x0 |
497 | mcall 76, API_IPv4 + 9, 0x0 |