Subversion Repositories Kolibri OS

Rev

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

Rev 5391 Rev 5419
Line 197... Line 197...
197
        cmp     eax, -1
197
        cmp     eax, -1
198
        je      socket_error
198
        je      socket_error
Line 199... Line 199...
199
 
199
 
Line 200... Line 200...
200
        DEBUGF  1,"Connected to 255.255.255.255 on port 67\n"
200
        DEBUGF  1,"Connected to 255.255.255.255 on port 67\n"
201
 
201
 
Line -... Line 202...
-
 
202
        mov     [dhcpMsgType_tx], 0x01                  ; DHCP discover
-
 
203
        mov     [dhcpLease], esi                        ; esi is still -1 (-1 = forever)
-
 
204
 
-
 
205
        call    random
-
 
206
        mov     [dhcpXID], eax
-
 
207
 
-
 
208
build_request:                                          ; Creates a DHCP request packet.
202
        mov     [dhcpMsgType], 0x01                     ; DHCP discover
209
 
203
        mov     [dhcpLease], esi                        ; esi is still -1 (-1 = forever)
210
        DEBUGF  1,"Building request\n"
204
 
211
 
Line 205... Line -...
205
        mcall   26, 9                                   ; Get system time
-
 
206
        imul    eax, 100
-
 
207
        mov     [currTime], eax
212
        mcall   26, 9                                   ; Get system time
Line 208... Line -...
208
 
-
 
209
build_request:                                          ; Creates a DHCP request packet.
-
 
210
 
213
        imul    eax, 100
211
        mov     [tries], DHCP_TRIES
214
        mov     [currTime], eax
212
 
215
 
213
        DEBUGF  1,"Building request\n"
216
        mov     [tries], DHCP_TRIES
Line -... Line 217...
-
 
217
 
214
 
218
        stdcall mem.Alloc, BUFFER
215
        stdcall mem.Alloc, BUFFER
219
        test    eax, eax
216
        test    eax, eax
220
        jz      dhcp_fail2
217
        jz      dhcp_fail2
221
        mov     [dhcpMsg], eax
Line 218... Line -...
218
        mov     [dhcpMsg], eax
-
 
219
 
-
 
220
        mov     edi, eax
222
 
Line 221... Line 223...
221
        mov     ecx, BUFFER
223
        ; Fill buffer with zeros
222
        xor     eax, eax
224
        mov     edi, eax
223
        rep     stosb
225
        mov     ecx, BUFFER
224
 
226
        xor     eax, eax
-
 
227
        rep     stosb
225
            ;; todo: put this in one buffer we can copy, instead of writing bytes and words!
228
 
226
 
229
        mov     edx, [dhcpMsg]
227
        mov     edx, [dhcpMsg]
230
 
228
 
231
        ; Boot protocol legacy
229
        ; Boot protocol legacy
232
        mov     [edx], byte 0x01                ; Boot request
230
        mov     [edx], byte 0x01                ; Boot request
233
        mov     [edx+1], byte 0x01              ; Ethernet
Line 240... Line 243...
240
        mov     [edx+32],word ax
243
        mov     [edx+32],word ax
Line 241... Line 244...
241
 
244
 
242
        ; DHCP extension
245
        ; DHCP extension
243
        mov     [edx+236], dword 0x63538263     ; magic cookie
246
        mov     [edx+236], dword 0x63538263     ; magic cookie
244
        mov     [edx+240], word 0x0135          ; option DHCP msg type
247
        mov     [edx+240], word 0x0135          ; option DHCP msg type
245
        mov     al, [dhcpMsgType]
248
        mov     al, [dhcpMsgType_tx]
246
        mov     [edx+240+2], al
249
        mov     [edx+240+2], al
247
        mov     [edx+240+3], word 0x0433        ; option Lease time = infinity
250
        mov     [edx+240+3], word 0x0433        ; option Lease time = infinity
248
        mov     eax, [dhcpLease]
251
        mov     eax, [dhcpLease]
249
        mov     [edx+240+5], eax
252
        mov     [edx+240+5], eax
250
        mov     [edx+240+9], word 0x0432        ; option requested IP address
253
        mov     [edx+240+9], word 0x0432        ; option requested IP address
251
        mov     eax, [dhcp.ip]
254
        mov     eax, [dhcp.ip]
252
        mov     [edx+240+11], eax
255
        mov     [edx+240+11], eax
253
        mov     [edx+240+15], word 0x0437       ; option request list
256
        mov     [edx+240+15], word 0x0437       ; option request list
Line 254... Line 257...
254
        mov     [edx+240+17], dword 0x0f060301
257
        mov     [edx+240+17], dword 0x0f060301
255
 
258
 
Line 256... Line 259...
256
        cmp     [dhcpMsgType], 0x01             ; Check which msg we are sending
259
        cmp     [dhcpMsgType_tx], 0x01          ; Check which msg we are sending
Line 257... Line 260...
257
        jne     request_options
260
        jne     .options
258
 
261
 
Line 259... Line 262...
259
        mov     [edx+240+21], byte 0xff         ; end of options marker
262
        mov     [edx+240+21], byte 0xff         ; end of options marker
260
 
263
 
261
        mov     [dhcpMsgLen], 262               ; length
264
        mov     [dhcpMsgLen], 262               ; length
262
        jmp     send_dhcpmsg
265
        jmp     send_dhcpmsg
Line 263... Line 266...
263
 
266
 
Line 271... Line 274...
271
        mov     [dhcpMsgLen], 268               ; length
274
        mov     [dhcpMsgLen], 268               ; length
Line 272... Line 275...
272
 
275
 
273
send_dhcpmsg:
276
send_dhcpmsg:
274
        DEBUGF  1,"Sending DHCP discover/request\n"
277
        DEBUGF  1,"Sending DHCP discover/request\n"
-
 
278
        mcall   75, 6, [socketNum], [dhcpMsg], [dhcpMsgLen]             ; write to socket (send broadcast request)
-
 
279
 
275
        mcall   75, 6, [socketNum], [dhcpMsg], [dhcpMsgLen]             ; write to socket (send broadcast request)
280
; Wait for data
276
        mcall   26, 9
281
        mcall   26, 9
277
        add     eax, TIMEOUT*100
282
        add     eax, TIMEOUT*100
278
        mov     [timeout], eax
283
        mov     [timeout], eax
279
  .wait:
284
  .wait:
Line 280... Line 285...
280
        mcall   23, TIMEOUT                                             ; wait for data (with timeout)
285
        mcall   23, TIMEOUT
281
 
286
 
282
read_data:                                                              ; we have data - this will be the response
287
read_data:                                                              ; we have data - this will be the response
283
        mcall   75, 7, [socketNum], [dhcpMsg], BUFFER, MSG_DONTWAIT     ; read data from socket
288
        mcall   75, 7, [socketNum], [dhcpMsg], BUFFER, MSG_DONTWAIT     ; read data from socket
Line 284... Line 289...
284
        cmp     eax, -1
289
        cmp     eax, -1
285
        jne     @f
290
        jne     .got_data
286
 
291
 
Line 287... Line 292...
287
        mcall   26, 9
292
        mcall   26, 9
288
        cmp     eax, [timeout]
293
        cmp     eax, [timeout]
289
        jb      send_dhcpmsg.wait
294
        jb      send_dhcpmsg.wait
-
 
295
 
290
 
296
        DEBUGF  2,"No answer from DHCP server\n"
Line 291... Line 297...
291
        DEBUGF  2,"No answer from DHCP server\n"
297
        dec     [tries]
292
        dec     [tries]
298
        jnz     send_dhcpmsg                    ; try again
293
        jnz     send_dhcpmsg                    ; try again
299
        stdcall mem.Free, [dhcpMsg]
Line 294... Line 300...
294
        jmp     dhcp_fail
300
        jmp     dhcp_fail
295
 
301
 
Line 305... Line 311...
305
;  1.2) send a request packet
311
;  1.2) send a request packet
306
; If the response is to a dhcp request, then:
312
; If the response is to a dhcp request, then:
307
;  1) If the response is DHCP ACK then
313
;  1) If the response is DHCP ACK then
308
;  1.1) extract the DNS & subnet fields. Set them in the stack
314
;  1.1) extract the DNS & subnet fields. Set them in the stack
Line 309... Line 315...
309
 
315
 
310
        cmp     [dhcpMsgType], 0x01             ; did we send a discover?
316
        cmp     [dhcpMsgType_tx], 0x01          ; did we send a discover?
Line 311... Line 317...
311
        je      discover
317
        je      discover_sent
312
 
318
 
Line 313... Line 319...
313
        cmp     [dhcpMsgType], 0x03             ; did we send a request?
319
        cmp     [dhcpMsgType_tx], 0x03          ; did we send a request?
-
 
320
        je      request_sent
314
        je      request
321
 
Line 315... Line 322...
315
 
322
        ; we should never reach here ;)
316
        ; we should never reach here ;)
323
        stdcall mem.Free, [dhcpMsg]
317
        jmp     fail
-
 
318
 
324
        jmp     fail
319
discover:
325
 
Line 320... Line 326...
320
        call    parse_response
326
discover_sent:
321
 
327
        call    parse_response
322
        cmp     [dhcpMsgType2], 0x02            ; Was the response an offer?
328
        cmp     [dhcpMsgType_rx], 0x02          ; Was the response an offer?
Line 323... Line 329...
323
        jne     dhcp_fail
329
        jne     read_data
324
 
330
 
325
        DEBUGF  1, "Got offer, making request\n"
-
 
326
        mov     [dhcpMsgType], 0x03             ; make it a request
331
        DEBUGF  1, "Got offer, making request\n"
327
        jmp     build_request
332
        mov     [dhcpMsgType_tx], 0x03          ; make it a request
Line 328... Line 333...
328
 
333
        jmp     build_request
Line 329... Line 334...
329
request:
334
 
330
        call    parse_response
335
request_sent:
-
 
336
        call    parse_response
331
 
337
        cmp     [dhcpMsgType_rx], 0x05          ; Was the response an ACK? It should be
Line 332... Line 338...
332
        cmp     [dhcpMsgType2], 0x05            ; Was the response an ACK? It should be
338
        jne     read_data                       ; NO - read next packets
333
        jne     read_data                       ; NO - read next packets
339
 
334
 
340
        DEBUGF  2, "IP assigned by DHCP server successfully\n"
335
        DEBUGF  2, "IP assigned by DHCP server successfully\n"
341
 
Line 364... Line 370...
364
;      The message is stored in dhcpMsg
370
;      The message is stored in dhcpMsg
365
;
371
;
366
;***************************************************************************
372
;***************************************************************************
367
parse_response:
373
parse_response:
Line 368... Line 374...
368
 
374
 
369
        DEBUGF  1,"Data received, parsing response\n"
375
        DEBUGF  1,"Parsing response\n"
370
        mov     edx, [dhcpMsg]
376
        mov     edx, [dhcpMsg]
-
 
377
        mov     [dhcpMsgType_rx], 0
-
 
378
 
-
 
379
; Verify if session ID matches
-
 
380
        mov     eax, [dhcpXID]
-
 
381
        cmp     dword[edx+4], eax
Line 371... Line 382...
371
        mov     [dhcpMsgType2], 0
382
        jne     .done
372
 
383
 
373
        push    dword [edx+16]
384
        push    dword [edx+16]
Line 423... Line 434...
423
        inc     ecx
434
        inc     ecx
424
        jmp     .next_option
435
        jmp     .next_option
Line 425... Line 436...
425
 
436
 
426
  .msgtype:
437
  .msgtype:
427
        mov     al, [edx]
438
        mov     al, [edx]
Line 428... Line 439...
428
        mov     [dhcpMsgType2], al
439
        mov     [dhcpMsgType_rx], al
429
 
440
 
Line 430... Line 441...
430
        DEBUGF  1,"DHCP Msg type: %u\n", al
441
        DEBUGF  1,"DHCP Msg type: %u\n", al
Line 462... Line 473...
462
        pop     [dhcp.dns]
473
        pop     [dhcp.dns]
463
        DEBUGF  1,"DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
474
        DEBUGF  1,"DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
464
        jmp     .next_option
475
        jmp     .next_option
Line 465... Line 476...
465
 
476
 
-
 
477
  .done:
466
  .done:
478
        stdcall mem.Free, [dhcpMsg]
Line -... Line 479...
-
 
479
        ret
467
        ret
480
 
Line 468... Line 481...
468
 
481
 
469
dhcp_fail:
-
 
Line 470... Line 482...
470
 
482
dhcp_fail:
471
        mcall   close, [socketNum]
483
 
Line -... Line 484...
-
 
484
        mcall   close, [socketNum]
472
        stdcall mem.Free, [dhcpMsg]
485
 
473
 
486
dhcp_fail2:
474
dhcp_fail2:
487
        DEBUGF  1,"DHCP failed\n"
475
        DEBUGF  1,"DHCP failed\n"
488
 
476
 
489
 
Line 678... Line 691...
678
        dd 0
691
        dd 0
679
        dd 0
692
        dd 0
680
        db '/sys/@notify', 0
693
        db '/sys/@notify', 0
Line 681... Line 694...
681
 
694
 
-
 
695
str_connected   db '"You are now connected to the network." -N', 0
682
str_connected   db '"You are now connected to the network." -N', 0
696
 
Line 683... Line 697...
683
path            db '/sys/settings/network.ini',0
697
path            db '/sys/settings/network.ini',0
Line 684... Line 698...
684
 
698
 
685
IM_END:
699
IM_END:
686
 
700
 
Line 687... Line 701...
687
device          db 1
701
device          db 1
688
inibuf          rb 16
702
inibuf          rb 16
-
 
703
tries           db ?
689
tries           db ?
704
 
690
 
705
dhcpMsgType_tx  db ?    ; sent
Line 691... Line 706...
691
dhcpMsgType     db ?    ; sent
706
dhcpMsgType_rx  db ?    ; received
692
dhcpMsgType2    db ?    ; received
707
dhcpXID         dd ?