Rev 109 | Go to most recent revision | Show entire file | Regard 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 |
21 | dd I_END ; esp |
- | |
22 | dd 0x0 , 0x0 ; I_Param , I_Icon |
22 | dd I_END ; esp |
23 | 23 | dd 0x0 , 0x0 ; I_Param , I_Icon |
|
- | 24 | ||
24 | include 'macros.inc' |
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 25... | Line 46... | ||
25 | 46 | ; ; |
|
Line 26... | Line 47... | ||
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 |
- | |
39 | mov ecx,0x00000383 |
- | |
40 | int 0x40 |
- | |
41 | - | ||
42 | if DEBUG = 1 |
- | |
43 | newline |
- | |
44 | dps "DHCP: Stack Initialized" |
- | |
45 | newline |
- | |
46 | end if |
- | |
47 | - | ||
48 | mov eax, 53 ; then, read in the status |
- | |
49 | mov ebx, 255 |
- | |
50 | mov ecx, 6 |
- | |
Line -... | Line 55... | ||
- | 55 | mov ebx,10000000b ; Only Stack |
|
- | 56 | int 0x40 |
|
- | 57 | ||
- | 58 | mov eax,52 ; first, enable the stack (packet driver) |
|
51 | int 0x40 |
59 | mov ebx,2 |
Line 52... | Line 60... | ||
52 | 60 | mov ecx,0x00000383 |
|
53 | cmp eax,0 ; if eax is zero, no driver was found |
- | |
54 | jne @f |
61 | int 0x40 |
- | 62 | ||
55 | 63 | DEBUGF 1,"DHCP: Stack Initialized.\n" |
|
56 | if DEBUG = 1 |
64 | |
57 | dps "DHCP: No Card detected" |
65 | eth.status eax ; Read the Stack status |
58 | newline |
- | |
59 | end if |
66 | test eax,eax ; if eax is zero, no driver was found |
60 | 67 | jnz @f |
|
61 | jmp close |
- | |
62 | 68 | DEBUGF 1,"DHCP: No Card detected\n" |
|
63 | @@: |
- | |
64 | if DEBUG = 1 |
69 | jmp close |
65 | dps "DHCP: Detected card: " |
- | |
66 | dph eax |
- | |
67 | newline |
70 | |
Line 68... | Line 71... | ||
68 | end if |
71 | @@: |
- | 72 | DEBUGF 1,"DHCP: Detected card: %x\n",eax |
|
- | 73 | @@: |
|
- | 74 | eth.check_cable eax |
|
Line 69... | Line 75... | ||
69 | 75 | test al,al |
|
70 | ; now that the stack is running, lets start the dhcp request |
76 | jnz @f |
71 | - | ||
72 | ; First, open socket |
- | |
73 | mov eax, 53 |
- | |
Line -... | Line 77... | ||
- | 77 | DEBUGF 1,"DHCP: Ethernet Cable not connected\n" |
|
- | 78 | ||
- | 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 | ||
- | 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 |
|
- | 90 | ||
- | 91 | ; jmp apipa ; comment this out if you want to skip DHCP and continue with link-local |
|
- | 92 | ||
- | 93 | ;*************************************************************************** |
|
- | 94 | ; |
|
- | 95 | ; DHCP rubish starts here |
|
- | 96 | ; |
|
74 | mov ebx, 0 |
97 | ;*************************************************************************** |
75 | mov ecx, 68 ; local port dhcp client |
98 | |
76 | mov edx, 67 ; remote port - dhcp server |
99 | |
Line -... | Line 100... | ||
- | 100 | ||
- | 101 | eth.check_port 68,eax ; Check if port 68 is available |
|
- | 102 | cmp eax,1 |
|
- | 103 | je @f |
|
- | 104 | ||
- | 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 |
115 | mov eax,26 |
87 | - | ||
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 |
91 | 119 | mov [currTime],eax |
|
Line 92... | Line 120... | ||
92 | ;*************************************************************************** |
120 | |
Line 93... | Line 121... | ||
93 | ; Function |
121 | ;*************************************************************************** |
94 | ; buildRequest |
122 | ; Function |
95 | ; |
123 | ; buildRequest |
96 | ; Description |
124 | ; |
- | 125 | ; Description |
|
- | 126 | ; Creates a DHCP request packet. |
|
97 | ; 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 |
|
- | 133 | cld |
|
98 | ; |
134 | rep stosb |
Line 99... | Line -... | ||
99 | ;*************************************************************************** |
- | |
100 | buildRequest: |
135 | |
101 | ; Clear dhcpMsg to all zeros |
136 | mov edx, dhcpMsg |
102 | xor eax,eax |
137 | |
Line 103... | Line -... | ||
103 | mov edi,dhcpMsg |
- | |
104 | mov ecx,512 |
138 | mov [edx], byte 0x01 ; Boot request |
105 | cld |
139 | mov [edx+1], byte 0x01 ; Ethernet |
106 | rep stosb |
140 | mov [edx+2], byte 0x06 ; Ethernet h/w len |
Line 107... | Line -... | ||
107 | - | ||
108 | mov edx, dhcpMsg |
141 | mov [edx+4], dword 0x11223344 ; xid |
109 | 142 | mov eax,[currTime] |
|
110 | mov [edx], byte 0x01 ; Boot request |
143 | mov [edx+8], eax ; secs, our uptime |
Line 111... | Line -... | ||
111 | mov [edx+1], byte 0x01 ; Ethernet |
- | |
112 | mov [edx+2], byte 0x06 ; Ethernet h/w len |
144 | mov [edx+10], byte 0x80 ; broadcast flag set |
113 | mov [edx+4], dword 0x11223344 ; xid |
145 | |
Line 114... | Line -... | ||
114 | mov [edx+10], byte 0x80 ; broadcast flag set |
- | |
115 | mov [edx+236], dword 0x63538263 ; magic number |
146 | mov eax, dword [MAC] ; first 4 bytes of MAC |
116 | 147 | mov [edx+28],dword eax |
|
Line 117... | Line -... | ||
117 | ; option DHCP msg type |
- | |
118 | mov [edx+240], word 0x0135 |
- | |
119 | mov al, [dhcpMsgType] |
148 | mov ax, word [MAC+4] ; last 2 bytes of MAC |
Line 120... | Line 149... | ||
120 | mov [edx+240+2], al |
149 | mov [edx+32],word ax |
121 | 150 | ||
Line 122... | Line -... | ||
122 | ; option Lease time = infinity |
- | |
123 | mov [edx+240+3], word 0x0433 |
151 | mov [edx+236], dword 0x63538263 ; magic number |
Line 124... | Line -... | ||
124 | mov eax, [dhcpLease] |
- | |
125 | mov [edx+240+5], eax |
152 | |
126 | 153 | mov [edx+240], word 0x0135 ; option DHCP msg type |
|
127 | ; ; option requested IP address |
154 | mov al, [dhcpMsgType] |
Line 128... | Line -... | ||
128 | mov [edx+240+9], word 0x0432 |
- | |
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 |
|
Line 132... | Line 158... | ||
132 | ; option request list |
158 | mov eax, [dhcpLease] |
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 | - | ||
140 | ; "Discover" options |
- | |
Line 141... | Line 159... | ||
141 | ; end of options marker |
159 | mov [edx+240+5], eax |
142 | mov [edx+240+21], byte 0xff |
160 | |
Line 143... | Line -... | ||
143 | - | ||
144 | mov [dhcpMsgLen], dword 262 |
- | |
145 | jmp ctr000 |
- | |
146 | 161 | mov [edx+240+9], word 0x0432 ; option requested IP address |
|
147 | br001: |
162 | mov eax, [dhcpClientIP] |
148 | ; "Request" options |
- | |
149 | - | ||
150 | ; server IP |
- | |
151 | mov [edx+240+21], word 0x0436 |
- | |
152 | mov eax, [dhcpServerIP] |
- | |
153 | mov [edx+240+23], eax |
- | |
154 | 163 | mov [edx+240+11], eax |
|
Line 155... | Line -... | ||
155 | ; end of options marker |
- | |
156 | mov [edx+240+27], byte 0xff |
164 | |
157 | - | ||
158 | mov [dhcpMsgLen], dword 268 |
- | |
159 | - | ||
160 | ctr000: |
- | |
161 | - | ||
Line -... | Line 165... | ||
- | 165 | mov [edx+240+15], word 0x0437 ; option request list |
|
162 | ; write to socket ( send broadcast request ) |
166 | mov [edx+240+17], dword 0x0f060301 |
Line 163... | Line 167... | ||
163 | mov eax, 53 |
167 | |
164 | mov ebx, 4 |
168 | cmp [dhcpMsgType], byte 0x01 ; Check which msg we are sending |
- | 169 | jne br001 |
|
Line 165... | Line -... | ||
165 | mov ecx, [socketNum] |
- | |
166 | mov edx, [dhcpMsgLen] |
- | |
167 | mov esi, dhcpMsg |
- | |
168 | int 0x40 |
- | |
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 |
- | |
Line 174... | Line 170... | ||
174 | 170 | ||
175 | ; now, we wait for data from remote |
- | |
176 | 171 | mov [edx+240+21], byte 0xff ; "Discover" options |
|
177 | wait_for_data: |
- | |
178 | mov eax,23 ; wait here for event NOTE a TIME-OUT should be placed here |
- | |
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 |
210 | - | ||
211 | mov eax, 53 |
195 | int 0x40 |
Line 212... | Line 196... | ||
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 | ||
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 |
199 | test eax,eax |
225 | ; 2) else exit ( display error ) |
- | |
226 | ; If the response is to a dhcp request, then: |
- | |
Line 227... | Line 200... | ||
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 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 | 319 | jmp pr003 |
|
377 | pr0022: |
320 | |
378 | cmp al, 1 ; subnet mask |
321 | pr0022: |
379 | jne pr0023 |
- | |
Line 380... | Line -... | ||
380 | - | ||
381 | pusha |
322 | cmp al, 1 ; subnet mask |
Line -... | Line 323... | ||
- | 323 | jne pr0023 |
|
382 | mov eax,52 |
324 | |
383 | mov ebx,12 |
325 | pusha |
Line 384... | Line 326... | ||
384 | mov ecx,[edx] |
326 | eth.set_SUBNET [edx] |
385 | int 0x40 |
327 | DEBUGF 1,"DHCP: Subnet: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
386 | 328 | popa |
|
387 | 329 | ||
Line 388... | Line -... | ||
388 | if DEBUG = 1 |
- | |
389 | dps "DHCP: Subnet: " |
- | |
390 | - | ||
Line 391... | Line 330... | ||
391 | xor esi,esi |
330 | jmp pr003 |
- | 331 | ||
392 | .loop: |
332 | pr0023: |
Line -... | Line 333... | ||
- | 333 | cmp al, 3 ; gateway ip |
|
- | 334 | jne pr0024 |
|
- | 335 | ||
393 | 336 | pusha |
|
Line 394... | Line -... | ||
394 | pusha |
- | |
Line 395... | Line 337... | ||
395 | movzx eax,byte[edx+esi] |
337 | eth.set_GATEWAY [edx] |
396 | call debug_outdec |
338 | DEBUGF 1,"DHCP: Gateway: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
397 | popa |
339 | popa |
Line 398... | Line 340... | ||
398 | 340 | ||
Line -... | Line 341... | ||
- | 341 | ||
- | 342 | pr0024: |
|
- | 343 | cmp al, 6 ; dns ip |
|
- | 344 | jne pr003 |
|
399 | inc esi |
345 | |
400 | cmp esi,4 |
346 | pusha |
401 | jne .loop |
347 | eth.set_DNS [edx] |
402 | 348 | DEBUGF 1,"DHCP: DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1 |
|
Line -... | Line 349... | ||
- | 349 | popa |
|
- | 350 | ||
- | 351 | ||
- | 352 | pr003: |
|
- | 353 | add edx, ecx |
|
- | 354 | jmp pr001 |
|
- | 355 | ||
- | 356 | pr_exit: |
|
- | 357 | ||
Line 403... | Line 358... | ||
403 | newline |
358 | ; DEBUGF 1,"DHCP: Sending ARP probe\n" |
404 | end if |
359 | ; eth.ARP_ANNOUNCE [dhcpClientIP] ; send an ARP announc packet |
- | 360 | ||
Line 405... | Line 361... | ||
405 | 361 | eth.get_GATEWAY eax ; if gateway was not set, set it to the DHCP SERVER IP |
|
406 | popa |
362 | test eax,eax |
- | 363 | jnz close |
|
Line 407... | Line 364... | ||
407 | 364 | eth.set_GATEWAY [dhcpServerIP] |
|
408 | jmp pr003 |
365 | jmp close |
409 | 366 | ||
410 | pr0023: |
367 | apipa: |
Line 411... | Line 368... | ||
411 | cmp al, 6 ; dns ip |
368 | call random |
412 | jne pr0024 |
369 | mov ecx,0xfea9 ; IP 169.254.0.0 link local net, see RFC3927 |
- | 370 | mov cx,ax |
|
413 | 371 | eth.set_IP ecx ; mask is 255.255.0.0 |
|
Line -... | Line 372... | ||
- | 372 | DEBUGF 1,"ZeroConf: Link Local IP assinged: 169.254.%u.%u\n",[generator+2]:1,[generator+3]:1 |
|
- | 373 | eth.set_SUBNET 0xffff |
|
414 | pusha |
374 | eth.set_GATEWAY 0x0 |
415 | 375 | eth.set_DNS 0x0 |
|
Line -... | Line 376... | ||
- | 376 | ||
- | 377 | mov eax,5 |
|
416 | mov eax,52 |
378 | mov ebx,PROBE_WAIT*100 |
Line 417... | Line -... | ||
417 | mov ebx,14 |
- | |
418 | mov ecx,[edx] |
379 | int 0x40 |
419 | int 0x40 |
380 | |
Line -... | Line 381... | ||
- | 381 | xor esi,esi |
|
420 | 382 | probe_loop: |
|
Line 421... | Line 383... | ||
421 | 383 | call random ; create a pseudo random number in eax (seeded by MAC) |
|
422 | if DEBUG = 1 |
384 | |
423 | dps "DHCP: DNS IP: " |
385 | cmp al,PROBE_MIN*100 ; check if al is bigger then PROBE_MIN |
424 | 386 | jge @f ; all ok |
|
Line 425... | Line -... | ||
425 | xor esi,esi |
- | |
426 | .loop: |
- | |
427 | - | ||
428 | pusha |
- | |
429 | movzx eax,byte[edx+esi] |
387 | add al,(PROBE_MAX-PROBE_MIN)*100 ; al is too small |
430 | call debug_outdec |
388 | @@: |
Line 431... | Line -... | ||
431 | popa |
- | |
432 | 389 | ||
433 | inc esi |
390 | cmp al,PROBE_MAX*100 |
434 | cmp esi,4 |
- | |
Line 435... | Line 391... | ||
435 | jne .loop |
391 | jle @f |
436 | 392 | sub al,(PROBE_MAX-PROBE_MIN)*100 |
|
437 | newline |
- | |
438 | end if |
- | |
439 | 393 | @@: |
|
440 | popa |
- | |
Line -... | Line 394... | ||
- | 394 | ||
441 | 395 | movzx ebx,al |
|
442 | pr0024: |
- | |
443 | cmp al, 3 ; gateway ip |
- | |
444 | jne pr003 |
396 | DEBUGF 1,"ZeroConf: Waiting %u0ms\n",ebx |
445 | 397 | mov eax,5 |
|
Line -... | Line 398... | ||
- | 398 | int 0x40 |
|
446 | pusha |
399 | |
- | 400 | DEBUGF 1,"ZeroConf: Sending Probe\n" |
|
Line -... | Line 401... | ||
- | 401 | ; eth.ARP_PROBE MAC2 |
|
- | 402 | inc esi |
|
- | 403 | ||
- | 404 | cmp esi,PROBE_NUM |
|
447 | 405 | jl probe_loop |
|
448 | mov eax,52 |
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 |
- | 408 | ; IP within this time, we should create another adress, that have to be done later |
|
- | 409 | ||
450 | mov ecx,[edx] |
410 | DEBUGF 1,"ZeroConf: Waiting %us\n",ANNOUNCE_WAIT |
Line 451... | Line -... | ||
451 | int 0x40 |
- | |
Line 452... | Line 411... | ||
452 | 411 | mov eax,5 |
|
Line -... | Line 412... | ||
- | 412 | mov ebx,ANNOUNCE_WAIT*100 |
|
- | 413 | int 0x40 |
|
453 | 414 | ||
Line 454... | Line 415... | ||
454 | if DEBUG = 1 |
415 | xor esi,esi |
455 | dps "DHCP: Gateway:" |
416 | announce_loop: |
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 |
- | 422 | cmp esi,ANNOUNCE_NUM |
|
461 | movzx eax,byte[edx+esi] |
423 | je @f |
- | 424 | ||
- | 425 | DEBUGF 1,"ZeroConf: Waiting %us\n",ANNOUNCE_INTERVAL |
|
- | 426 | mov eax,5 |
|
Line -... | Line 427... | ||
- | 427 | mov ebx,ANNOUNCE_INTERVAL*100 |
|
462 | call debug_outdec |
428 | int 0x40 |
463 | popa |
429 |