Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 336
Line 1... Line -...
1
;
-
 
2
; Automated dhcp client
1
; Automated dhcp client
-
 
2
; v 1.3
3
;
3
;
4
; v 1.1
-
 
5
;
-
 
6
; by the hidden player
4
; with thanks to authors of DHCP client for menuetos: Mike Hibbet
7
;
5
;
-
 
6
; by HidnPlayr & Derpenguin
-
 
7
 
Line 8... Line -...
8
 
-
 
9
DEBUG equ 1
8
 
-
 
9
TIMEOUT equ 60 ; in seconds
-
 
10
BUFFER	equ 1024
-
 
11
__DEBUG__ equ 1
Line 10... Line 12...
10
TIMEOUT equ 60 ; in seconds
12
__DEBUG_LEVEL__ equ 1; 1 = all, 2 = errors
11
 
-
 
12
use32
13
 
Line 13... Line 14...
13
 
14
use32
14
	       org    0x0
15
	       org    0x0
15
 
16
 
16
	       db     'MENUET01'	      ; 8 byte id
17
	       db     'MENUET01'	      ; 8 byte id
17
	       dd     0x01		      ; header version
18
	       dd     0x01		      ; header version
18
	       dd     START		      ; start of code
19
	       dd     START		      ; start of code
19
	       dd     IM_END		      ; size of image
20
	       dd     IM_END		      ; size of image
Line 20... Line 21...
20
	       dd     I_END		      ; memory for app
21
	       dd     I_END		      ; memory for app
-
 
22
	       dd     I_END		      ; esp
-
 
23
	       dd     0x0 , 0x0 	      ; I_Param , I_Icon
-
 
24
 
-
 
25
;include 'macros.inc'
-
 
26
include 'eth.inc'
-
 
27
include 'debug-fdo.inc'
-
 
28
 
-
 
29
 
-
 
30
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
31
; CONFIGURATION FOR LINK-LOCAL                                                         ;
-
 
32
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
33
				       ;                                               ;
-
 
34
PROBE_WAIT	    equ 1	       ; second  (initial random delay)                ;
-
 
35
PROBE_MIN	    equ 1	       ; second  (minimum delay till repeated probe)   ;
-
 
36
PROBE_MAX	    equ 2	       ; seconds (maximum delay till repeated probe)   ;
-
 
37
PROBE_NUM	    equ 3	       ;         (number of probe packets)             ;
-
 
38
				       ;                                               ;
-
 
39
ANNOUNCE_NUM	    equ 2	       ;         (number of announcement packets)      ;
-
 
40
ANNOUNCE_INTERVAL   equ 2	       ; seconds (time between announcement packets)   ;
-
 
41
ANNOUNCE_WAIT	    equ 2	       ; seconds (delay before announcing)             ;
-
 
42
				       ;                                               ;
-
 
43
MAX_CONFLICTS	    equ 10	       ;         (max conflicts before rate limiting)  ;
-
 
44
				       ;                                               ;
-
 
45
RATE_LIMIT_INTERVAL equ 60	       ; seconds (delay between successive attempts)   ;
Line 21... Line -...
21
	       dd     I_END		      ; esp
-
 
22
	       dd     0x0 , 0x0 	      ; I_Param , I_Icon
-
 
23
 
-
 
Line -... Line 46...
-
 
46
				       ;                                               ;
Line 24... Line -...
24
include 'macros.inc'
-
 
25
 
-
 
26
if DEBUG = 1
47
DEFEND_INTERVAL     equ 10	       ; seconds (min. wait between defensive ARPs)    ;
27
include 'debug.inc'
48
				       ;                                               ;
28
end if
49
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 29... Line 50...
29
 
50
 
30
 
51
 
31
START:				; start of execution
52
START:				       ; start of execution
32
 
53
 
Line 33... Line -...
33
    mov     eax,40		   ; Report events
-
 
34
    mov     ebx,10000000b	   ; Only Stack
-
 
35
    int     0x40
54
    mov     eax,40		       ; Report events
36
 
-
 
37
    mov     eax,52		   ; first, enable the stack
-
 
38
    mov     ebx,2
55
    mov     ebx,10000000b	       ; Only Stack
39
    mov     ecx,0x00000383
56
    int     0x40
-
 
57
 
40
    int     0x40
58
    mov     eax,52		       ; first, enable the stack (packet driver)
41
 
59
    mov     ebx,2
42
if DEBUG = 1
60
    mov     ecx,0x00000383
Line -... Line 61...
-
 
61
    int     0x40
43
    newline
62
 
-
 
63
    DEBUGF  1,"DHCP: Stack Initialized.\n"
-
 
64
 
-
 
65
    eth.status eax		       ; Read the Stack status
44
    dps  "DHCP: Stack Initialized"
66
    test    eax,eax		       ; if eax is zero, no driver was found
-
 
67
    jnz     @f
Line 45... Line 68...
45
    newline
68
    DEBUGF  1,"DHCP: No Card detected\n"
46
end if
69
    jmp     close
47
 
70
 
48
    mov     eax, 53		   ; then, read in the status
-
 
Line 49... Line 71...
49
    mov     ebx, 255
71
   @@:
Line 50... Line 72...
50
    mov     ecx, 6
72
    DEBUGF  1,"DHCP: Detected card: %x\n",eax
51
    int     0x40
-
 
52
 
73
   @@:
53
    cmp     eax,0		   ; if eax is zero, no driver was found
-
 
54
    jne     @f
-
 
55
 
-
 
56
if DEBUG = 1
74
    eth.check_cable eax
-
 
75
    test    al,al
57
    dps  "DHCP: No Card detected"
76
    jnz     @f
58
    newline
77
    DEBUGF  1,"DHCP: Ethernet Cable not connected\n"
59
end if
-
 
60
 
-
 
61
    jmp  close
-
 
62
 
78
 
63
   @@:
-
 
64
if DEBUG = 1
-
 
65
    dps  "DHCP: Detected card: "
-
 
Line -... Line 79...
-
 
79
    mov     eax,5
-
 
80
    mov     ebx,500		       ; loop until cable is connected (check every 5 sec)
-
 
81
    int     0x40
-
 
82
 
-
 
83
    jmp     @r
-
 
84
 
-
 
85
   @@:
-
 
86
    DEBUGF  1,"DHCP: Ethernet Cable status: %d\n",al
-
 
87
 
66
    dph  eax
88
    eth.read_mac MAC
-
 
89
    DEBUGF  1,"DHCP: MAC address: %x-%x-%x-%x-%x-%x\n",[MAC]:2,[MAC+1]:2,[MAC+2]:2,[MAC+3]:2,[MAC+4]:2,[MAC+5]:2
Line 67... Line -...
67
    newline
-
 
68
end if
90
 
69
 
91
;    jmp     apipa   ; comment this out if you want to skip DHCP and continue with link-local
70
    ; now that the stack is running, lets start the dhcp request
-
 
71
 
-
 
72
    ; First, open socket
92
 
-
 
93
;***************************************************************************
-
 
94
;
-
 
95
;  DHCP rubish starts here
73
    mov     eax, 53
96
;
74
    mov     ebx, 0
97
;***************************************************************************
75
    mov     ecx, 68		    ; local port dhcp client
98
 
-
 
99
 
-
 
100
 
-
 
101
    eth.check_port 68,eax	       ; Check if port 68 is available
-
 
102
    cmp     eax,1
-
 
103
    je	    @f
-
 
104
 
Line 76... Line 105...
76
    mov     edx, 67		    ; remote port - dhcp server
105
    DEBUGF  1,"DHCP: Port 68 is already in use.\n"
77
    mov     esi, -1		    ; broadcast
106
    jmp     close
78
    int     0x40
107
 
79
 
108
   @@:
80
    mov     [socketNum], eax
109
    eth.open_udp 68,67,-1,[socketNum]  ; open socket (local,remote,ip,socket)
81
 
110
    DEBUGF  1,"DHCP: Socket opened: %d\n",eax
82
if DEBUG = 1
111
				       ; Setup the first msg we will send
83
    dps   "DHCP: Socket opened: "
112
    mov     byte [dhcpMsgType], 0x01   ; DHCP discover
84
    dpd   eax
113
    mov     dword [dhcpLease], esi     ; esi is still -1 (-1 = forever)
85
    newline
114
 
86
end if
-
 
87
 
115
    mov     eax,26
88
    ; Setup the first msg we will send
116
    mov     ebx,9
89
    mov     byte [dhcpMsgType], 0x01 ; DHCP discover
117
    int     0x40
90
    mov     dword [dhcpLease], esi   ; esi is still -1 (-1 = forever)
118
    imul    eax,100
Line 91... Line 119...
91
 
119
    mov     [currTime],eax
Line 92... Line 120...
92
;***************************************************************************
120
 
93
;   Function
121
;***************************************************************************
94
;      buildRequest
122
;   Function
95
;
123
;      buildRequest
-
 
124
;
-
 
125
;   Description
96
;   Description
126
;      Creates a DHCP request packet.
-
 
127
;
-
 
128
;***************************************************************************
-
 
129
buildRequest:
-
 
130
    xor     eax,eax			    ; Clear dhcpMsg to all zeros
-
 
131
    mov     edi,dhcpMsg
-
 
132
    mov     ecx,BUFFER
97
;      Creates a DHCP request packet.
133
    cld
Line 98... Line -...
98
;
-
 
99
;***************************************************************************
134
    rep     stosb
100
buildRequest:
135
 
101
    ; Clear dhcpMsg to all zeros
136
    mov     edx, dhcpMsg
Line 102... Line -...
102
    xor     eax,eax
-
 
103
    mov     edi,dhcpMsg
137
 
104
    mov     ecx,512
138
    mov     [edx], byte 0x01		    ; Boot request
105
    cld
139
    mov     [edx+1], byte 0x01		    ; Ethernet
Line 106... Line -...
106
    rep     stosb
-
 
107
 
140
    mov     [edx+2], byte 0x06		    ; Ethernet h/w len
108
    mov     edx, dhcpMsg
141
    mov     [edx+4], dword 0x11223344	    ; xid
109
 
142
    mov     eax,[currTime]
Line 110... Line -...
110
    mov     [edx], byte 0x01		    ; Boot request
-
 
111
    mov     [edx+1], byte 0x01		    ; Ethernet
143
    mov     [edx+8], eax		    ; secs, our uptime
112
    mov     [edx+2], byte 0x06		    ; Ethernet h/w len
144
    mov     [edx+10], byte 0x80 	    ; broadcast flag set
Line 113... Line -...
113
    mov     [edx+4], dword 0x11223344	    ; xid
-
 
114
    mov     [edx+10], byte 0x80 	    ; broadcast flag set
145
 
115
    mov     [edx+236], dword 0x63538263     ; magic number
146
    mov     eax, dword [MAC]		    ; first 4 bytes of MAC
Line 116... Line -...
116
 
-
 
117
    ; option DHCP msg type
-
 
118
    mov     [edx+240], word 0x0135
147
    mov     [edx+28],dword eax
Line 119... Line 148...
119
    mov     al, [dhcpMsgType]
148
    mov     ax, word [MAC+4]		    ; last 2 bytes of MAC
120
    mov     [edx+240+2], al
149
    mov     [edx+32],word ax
Line 121... Line -...
121
 
-
 
122
    ; option Lease time = infinity
150
 
Line 123... Line -...
123
    mov     [edx+240+3], word 0x0433
-
 
124
    mov     eax, [dhcpLease]
151
    mov     [edx+236], dword 0x63538263     ; magic number
125
    mov     [edx+240+5], eax
152
 
126
 
153
    mov     [edx+240], word 0x0135	    ; option DHCP msg type
Line 127... Line -...
127
;    ; option requested IP address
-
 
128
    mov     [edx+240+9], word 0x0432
154
    mov     al, [dhcpMsgType]
Line 129... Line 155...
129
;    mov     eax, [dhcpClientIP]
155
    mov     [edx+240+2], al
Line 130... Line 156...
130
;    mov     [edx+240+11], eax
156
 
Line 131... Line 157...
131
 
157
    mov     [edx+240+3], word 0x0433	    ; option Lease time = infinity
132
    ; option request list
-
 
133
    mov     [edx+240+15], word 0x0437
-
 
134
    mov     [edx+240+17], dword 0x0f060301
-
 
135
 
-
 
136
    ; Check which msg we are sending
-
 
137
    cmp     [dhcpMsgType], byte 0x01
-
 
138
    jne     br001
-
 
139
 
-
 
Line 140... Line 158...
140
    ; "Discover" options
158
    mov     eax, [dhcpLease]
141
    ; end of options marker
159
    mov     [edx+240+5], eax
Line 142... Line -...
142
    mov     [edx+240+21], byte 0xff
-
 
143
 
-
 
144
    mov     [dhcpMsgLen], dword 262
-
 
145
    jmp     ctr000
160
 
146
 
161
    mov     [edx+240+9], word 0x0432	    ; option requested IP address
147
br001:
162
    mov     eax, [dhcpClientIP]
Line 148... Line -...
148
    ; "Request" options
-
 
149
 
-
 
150
    ; server IP
-
 
151
    mov     [edx+240+21], word 0x0436
163
    mov     [edx+240+11], eax
152
    mov     eax, [dhcpServerIP]
-
 
Line 153... Line 164...
153
    mov     [edx+240+23], eax
164
 
154
 
165
    mov     [edx+240+15], word 0x0437	    ; option request list
Line 155... Line -...
155
    ; end of options marker
-
 
156
    mov     [edx+240+27], byte 0xff
166
    mov     [edx+240+17], dword 0x0f060301
157
 
-
 
158
    mov     [dhcpMsgLen], dword 268
-
 
159
 
-
 
160
ctr000:
-
 
161
 
-
 
162
    ; write to socket ( send broadcast request )
-
 
163
    mov     eax, 53
-
 
164
    mov     ebx, 4
-
 
165
    mov     ecx, [socketNum]
-
 
166
    mov     edx, [dhcpMsgLen]
-
 
167
    mov     esi, dhcpMsg
167
 
168
    int     0x40
168
    cmp     [dhcpMsgType], byte 0x01	    ; Check which msg we are sending
169
 
-
 
170
    ; Setup the DHCP buffer to receive response
-
 
171
 
-
 
172
    mov     eax, dhcpMsg
-
 
173
    mov     [dhcpMsgLen], eax	   ; Used as a pointer to the data
-
 
174
 
-
 
175
    ; now, we wait for data from remote
-
 
176
 
-
 
177
wait_for_data:
-
 
178
    mov     eax,23		   ; wait here for event   NOTE a TIME-OUT should be placed here
-
 
Line -... Line 169...
-
 
169
    jne     br001
-
 
170
 
-
 
171
    mov     [edx+240+21], byte 0xff	    ; "Discover" options
179
    mov     ebx,TIMEOUT*100
172
 
180
    int     0x40
173
    mov     [dhcpMsgLen], dword 262	    ; end of options marker
Line 181... Line 174...
181
 
174
    jmp     ctr000
182
    ; Any data in the UDP receive buffer?
175
 
183
    mov     eax, 53
176
br001:					    ; "Request" options
184
    mov     ebx, 2
177
 
185
    mov     ecx, [socketNum]
178
    mov     [edx+240+21], word 0x0436	    ; server IP
186
    int     0x40
179
    mov     eax, [dhcpServerIP]
187
 
-
 
188
    cmp     eax, 0
180
    mov     [edx+240+23], eax
189
    jne     ctr002
181
 
190
 
182
    mov     [edx+240+27], byte 0xff	    ; end of options marker
191
if DEBUG = 1
-
 
192
    dps  "DHCP: Timeout!"
-
 
Line 193... Line 183...
193
    newline
183
 
194
end if
184
    mov     [dhcpMsgLen], dword 268
195
 
185
 
196
    jmp    close
186
ctr000:
Line 197... Line 187...
197
 
187
 
198
    ; we have data - this will be the response
-
 
Line 199... Line 188...
199
ctr002:
188
    eth.write_udp [socketNum],[dhcpMsgLen],dhcpMsg    ; write to socket ( send broadcast request )
200
 
-
 
201
    mov     eax, 53
189
 
Line 202... Line -...
202
    mov     ebx, 3
-
 
203
    mov     ecx, [socketNum]
190
    mov     eax, dhcpMsg		    ; Setup the DHCP buffer to receive response
204
    int     0x40		; read byte - block (high byte)
191
    mov     [dhcpMsgLen], eax		    ; Used as a pointer to the data
205
 
-
 
206
    ; Store the data in the response buffer
-
 
207
    mov     eax, [dhcpMsgLen]
192
 
208
    mov     [eax], bl
193
    mov     eax,23			    ; wait here for event (data from remote)
Line 209... Line 194...
209
    inc     dword [dhcpMsgLen]
194
    mov     ebx,TIMEOUT*10
-
 
195
    int     0x40
Line 210... Line -...
210
 
-
 
211
    mov     eax, 53
-
 
212
    mov     ebx, 2
196
 
213
    mov     ecx, [socketNum]
-
 
214
    int     0x40		; any more data?
197
    eth.poll [socketNum]
Line 215... Line 198...
215
 
198
 
-
 
199
    test    eax,eax
Line 216... Line -...
216
    cmp     eax, 0
-
 
217
    jne     ctr002		; yes, so get it
-
 
218
 
-
 
219
    ; depending on which msg we sent, handle the response
-
 
220
    ; accordingly.
-
 
221
    ; If the response is to a dhcp discover, then:
-
 
222
    ;  1) If response is DHCP OFFER then
-
 
223
    ;  1.1) record server IP, lease time & IP address.
-
 
224
    ;  1.2) send a request packet
-
 
225
    ;  2) else exit ( display error )
-
 
226
    ; If the response is to a dhcp request, then:
-
 
227
    ;  1) If the response is DHCP ACK then
200
    jnz     ctr002
228
    ;  1.1) extract the DNS & subnet fields. Set them in the stack
201
 
Line 229... Line 202...
229
    ;  2) else exit ( display error )
202
    DEBUGF  2,"DHCP: Timeout!\n"
230
 
203
    eth.close_udp [socketNum]
Line 286... Line 259...
286
;       dhcpDNSIP, dhcpSubnet
259
;       dhcpDNSIP, dhcpSubnet
287
;      The message is stored in dhcpMsg
260
;      The message is stored in dhcpMsg
288
;
261
;
289
;***************************************************************************
262
;***************************************************************************
290
parseResponse:
263
parseResponse:
291
 
-
 
292
if DEBUG = 1
-
 
293
    dps  "DHCP: Data received, parsing response"
264
    DEBUGF  1,"DHCP: Data received, parsing response\n"
294
    newline
-
 
295
end if
-
 
296
 
-
 
297
    mov     edx, dhcpMsg
265
    mov     edx, dhcpMsg
Line 298... Line 266...
298
 
266
 
299
    pusha
-
 
300
 
-
 
301
    mov     eax,52	    ; Set Client IP
267
    pusha
302
    mov     ebx,3
268
    eth.set_IP [edx+16]
303
    mov     ecx, [edx+16]
-
 
304
    int     0x40
-
 
305
 
-
 
306
if DEBUG = 1
269
    mov     eax,[edx]
307
    dps  "DHCP: Client: "
-
 
308
 
-
 
309
    xor   esi,esi
-
 
310
   .loop:
-
 
311
 
-
 
312
    pusha
270
    mov     [dhcpClientIP],eax
313
    movzx eax,byte[edx+esi+16]
-
 
314
    call  debug_outdec
-
 
315
    popa
-
 
316
 
-
 
317
    inc   esi
-
 
318
    cmp   esi,4
-
 
319
    jne   .loop
-
 
320
 
-
 
321
    newline
-
 
322
end if
-
 
323
 
271
    DEBUGF  1,"DHCP: Client: %u.%u.%u.%u\n",[edx+16]:1,[edx+17]:1,[edx+18]:1,[edx+19]:1
Line 324... Line -...
324
    popa
-
 
325
 
-
 
326
    ; Scan options
272
    popa
Line 327... Line 273...
327
 
273
 
328
    add     edx, 240	    ; Point to first option
-
 
329
 
274
    add     edx, 240	    ; Point to first option
330
pr001:
275
 
331
    ; Get option id
276
pr001:
Line 332... Line 277...
332
    mov     al, [edx]
277
    mov     al, [edx]
Line 340... Line 285...
340
    mov     [dhcpMsgType], al
285
    mov     [dhcpMsgType], al
341
    add     edx, 3
286
    add     edx, 3
342
    jmp     pr001	    ; Get next option
287
    jmp     pr001	    ; Get next option
Line 343... Line 288...
343
 
288
 
344
pr002:
-
 
345
    ; All other (accepted) options are 4 bytes in length
289
pr002:
346
    inc     edx
290
    inc     edx
347
    movzx   ecx, byte [edx]
291
    movzx   ecx, byte [edx]
Line 348... Line 292...
348
    inc     edx 	    ; point to data
292
    inc     edx 	    ; point to data
349
 
293
 
350
    cmp     al, 54	    ; server id
294
    cmp     al, 54	    ; server id
351
    jne     pr0021
295
    jne     pr0021
-
 
296
    mov     eax, [edx]	    ; All options are 4 bytes, so get it
352
    mov     eax, [edx]	    ; All options are 4 bytes, so get it
297
    mov     [dhcpServerIP], eax
Line 353... Line 298...
353
    mov     [dhcpServerIP], eax
298
    DEBUGF  1,"DHCP: Server: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
354
    jmp     pr003
299
    jmp     pr003
355
 
300
 
Line 356... Line -...
356
pr0021:
-
 
357
    cmp     al, 51	    ; lease
301
pr0021:
358
    jne     pr0022
302
    cmp     al, 51	    ; lease
359
 
-
 
360
if DEBUG = 1
303
    jne     pr0022
-
 
304
 
-
 
305
    pusha
-
 
306
    DEBUGF  1,"DHCP: lease: "
361
    pusha
307
    mov eax,[edx]
362
    dps  "DHCP: lease:  "
308
    bswap eax
363
 
309
    mov  [dhcpLease],eax
364
    cmp  dword[edx],-1
310
    cmp  dword[edx],-1	    ; i really don't know, how to test it
365
    jne  no_lease_forever
311
    jne  no_lease_forever
366
    dps  "forever"
-
 
367
    jmp  lease_newline
312
    DEBUGF  1,"forever\n"
368
   no_lease_forever:
313
    jmp  @f
369
    dpd  [edx]
-
 
Line 370... Line 314...
370
   lease_newline:
314
   no_lease_forever:
Line 371... Line 315...
371
    newline
315
    DEBUGF  1,"%d\n",eax
372
    popa
316
   @@:
373
end if
317
    popa
Line 374... Line 318...
374
 
318
 
375
    jmp     pr003
-
 
376
 
-
 
377
pr0022:
319
    jmp     pr003
378
    cmp     al, 1	    ; subnet mask
-
 
379
    jne     pr0023
-
 
380
 
-
 
381
    pusha
-
 
382
    mov     eax,52
320
 
383
    mov     ebx,12
-
 
384
    mov     ecx,[edx]
-
 
385
    int     0x40
-
 
386
 
-
 
387
 
-
 
388
if DEBUG = 1
-
 
389
    dps  "DHCP: Subnet: "
-
 
390
 
321
pr0022:
Line 391... Line -...
391
    xor   esi,esi
-
 
392
   .loop:
322
    cmp     al, 1	    ; subnet mask
393
 
-
 
Line 394... Line 323...
394
    pusha
323
    jne     pr0023
-
 
324
 
395
    movzx eax,byte[edx+esi]
325
    pusha
Line -... Line 326...
-
 
326
    eth.set_SUBNET [edx]
-
 
327
    DEBUGF  1,"DHCP: Subnet: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
-
 
328
    popa
396
    call  debug_outdec
329
 
Line 397... Line -...
397
    popa
-
 
Line 398... Line 330...
398
 
330
    jmp     pr003
399
    inc   esi
331
 
400
    cmp   esi,4
332
pr0023:
Line 401... Line 333...
401
    jne   .loop
333
    cmp     al, 3	    ; gateway ip
402
 
-
 
403
    newline
-
 
404
end if
334
    jne     pr0024
405
 
335
 
406
    popa
336
    pusha
Line -... Line 337...
-
 
337
    eth.set_GATEWAY [edx]
407
 
338
    DEBUGF  1,"DHCP: Gateway: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
408
    jmp     pr003
339
    popa
Line 409... Line -...
409
 
-
 
410
pr0023:
340
 
Line 411... Line -...
411
    cmp     al, 6	    ; dns ip
-
 
412
    jne     pr0024
341
 
413
 
342
pr0024:
414
    pusha
-
 
Line -... Line 343...
-
 
343
    cmp     al, 6	    ; dns ip
415
 
344
    jne     pr003
416
    mov     eax,52
345
 
-
 
346
    pusha
417
    mov     ebx,14
347
    eth.set_DNS [edx]
Line -... Line 348...
-
 
348
    DEBUGF  1,"DHCP: DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
418
    mov     ecx,[edx]
349
    popa
-
 
350
 
-
 
351
 
-
 
352
pr003:
-
 
353
    add     edx, ecx
-
 
354
    jmp     pr001
-
 
355
 
-
 
356
pr_exit:
-
 
357
 
-
 
358
;    DEBUGF  1,"DHCP: Sending ARP probe\n"
-
 
359
;    eth.ARP_ANNOUNCE [dhcpClientIP]      ; send an ARP announc packet
-
 
360
 
-
 
361
    eth.get_GATEWAY eax 		  ; if gateway was not set, set it to the DHCP SERVER IP
-
 
362
    test  eax,eax
-
 
363
    jnz   close
-
 
364
    eth.set_GATEWAY [dhcpServerIP]
-
 
365
    jmp close
-
 
366
 
-
 
367
apipa:
-
 
368
    call random
419
    int     0x40
369
    mov  ecx,0xfea9			 ; IP 169.254.0.0 link local net, see RFC3927
Line -... Line 370...
-
 
370
    mov  cx,ax
-
 
371
    eth.set_IP ecx			 ; mask is 255.255.0.0
-
 
372
    DEBUGF 1,"ZeroConf: Link Local IP assinged: 169.254.%u.%u\n",[generator+2]:1,[generator+3]:1
420
 
373
    eth.set_SUBNET 0xffff
Line 421... Line 374...
421
 
374
    eth.set_GATEWAY 0x0
422
if DEBUG = 1
375
    eth.set_DNS 0x0
-
 
376
 
423
    dps  "DHCP: DNS IP: "
377
    mov   eax,5
Line -... Line 378...
-
 
378
    mov   ebx,PROBE_WAIT*100
-
 
379
    int   0x40
424
 
380
 
Line 425... Line 381...
425
    xor   esi,esi
381
    xor esi,esi
426
   .loop:
382
   probe_loop:
427
 
-
 
428
    pusha
-
 
Line -... Line 383...
-
 
383
    call  random		       ; create a pseudo random number in eax (seeded by MAC)
-
 
384
 
Line -... Line 385...
-
 
385
    cmp   al,PROBE_MIN*100	       ; check if al is bigger then PROBE_MIN
429
    movzx eax,byte[edx+esi]
386
    jge   @f			       ; all ok
430
    call  debug_outdec
387
    add   al,(PROBE_MAX-PROBE_MIN)*100 ; al is too small
-
 
388
   @@:
Line 431... Line 389...
431
    popa
389
 
432
 
390
    cmp   al,PROBE_MAX*100
Line 433... Line -...
433
    inc   esi
-
 
434
    cmp   esi,4
391
    jle   @f
435
    jne   .loop
392
    sub   al,(PROBE_MAX-PROBE_MIN)*100
436
 
-
 
Line 437... Line 393...
437
    newline
393
   @@:
438
end if
394
 
439
 
395
    movzx ebx,al
Line -... Line 396...
-
 
396
    DEBUGF  1,"ZeroConf: Waiting %u0ms\n",ebx
440
    popa
397
    mov   eax,5
-
 
398
    int   0x40
441
 
399
 
Line 442... Line -...
442
pr0024:
-
 
443
    cmp     al, 3	    ; gateway ip
-
 
444
    jne     pr003
-
 
445
 
-
 
446
    pusha
400
    DEBUGF  1,"ZeroConf: Sending Probe\n"
447
 
-
 
448
    mov     eax,52
401
;    eth.ARP_PROBE MAC2
-
 
402
    inc   esi
Line -... Line 403...
-
 
403
 
-
 
404
    cmp   esi,PROBE_NUM
-
 
405
    jl	  probe_loop
-
 
406
 
449
    mov     ebx,11
407
; now we wait further ANNOUNCE_WAIT seconds and send ANNOUNCE_NUM ARP announces. If any other host has assingnd
450
    mov     ecx,[edx]
408
; IP within this time, we should create another adress, that have to be done later
451
    int     0x40
409
 
-
 
410
    DEBUGF  1,"ZeroConf: Waiting %us\n",ANNOUNCE_WAIT
-
 
411
    mov   eax,5
452
 
412
    mov   ebx,ANNOUNCE_WAIT*100
Line 453... Line -...
453
 
-
 
Line 454... Line 413...
454
if DEBUG = 1
413
    int   0x40
Line -... Line 414...
-
 
414
 
-
 
415
    xor   esi,esi
455
    dps  "DHCP: Gateway:"
416
   announce_loop:
Line 456... Line 417...
456
 
417
 
457
    xor   esi,esi
418
    DEBUGF  1,"ZeroConf: Sending Announce\n"
458
   .loop:
419
;    eth.ARP_ANNOUNCE MAC2
459
 
420
 
460
    pusha
421
    inc   esi
461
    movzx eax,byte[edx+esi]
422
    cmp   esi,ANNOUNCE_NUM
462
    call  debug_outdec
423
    je	  @f
-
 
424
 
463
    popa
425
    DEBUGF  1,"ZeroConf: Waiting %us\n",ANNOUNCE_INTERVAL
-
 
426
    mov   eax,5
-
 
427
    mov   ebx,ANNOUNCE_INTERVAL*100
-
 
428
    int   0x40
Line -... Line 429...
-
 
429
 
464
 
430
    jmp   announce_loop
465
    inc   esi
431
   @@: