Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 485 Rev 551
1
;
1
;
2
;    DHCP Client
2
;    DHCP Client
3
;
3
;
4
;    Compile with FASM for Menuet
4
;    Compile with FASM for Menuet
5
;
5
;
6
 
6
 
7
include 'lang.inc'
7
include 'lang.inc'
8
include '..\..\..\macros.inc'
8
include '..\..\..\macros.inc'
9
 
9
 
10
use32
10
use32
11
 
11
 
12
               org    0x0
12
               org    0x0
13
 
13
 
14
	       db     'MENUET01'	    ; 8 byte id
14
	       db     'MENUET01'	    ; 8 byte id
15
	       dd     0x01		    ; header version
15
	       dd     0x01		    ; header version
16
	       dd     START		    ; start of code
16
	       dd     START		    ; start of code
17
	       dd     I_END		    ; size of image
17
	       dd     I_END		    ; size of image
18
	       dd     I_END+0x8000	    ; memory for app
18
	       dd     I_END+0x8000	    ; memory for app
19
	       dd     I_END+0x8000	    ; esp
19
	       dd     I_END+0x8000	    ; esp
20
	       dd     0x0 , 0x0 	    ; I_Param , I_Icon
20
	       dd     0x0 , 0x0 	    ; I_Param , I_Icon
21
 
21
 
22
 
22
 
23
START:                                      ; start of execution
23
START:                                      ; start of execution
24
    mov     eax,40                          ; Report events
24
    mov     eax,40                          ; Report events
25
    mov     ebx,10000111b                   ; Stack 8 + defaults
25
    mov     ebx,10000111b                   ; Stack 8 + defaults
26
    int     0x40
26
    int     0x40
27
 
27
 
28
red:                            ; redraw
28
red:                            ; redraw
29
    call    draw_window                     ; at first, draw the window
29
    call    draw_window                     ; at first, draw the window
30
 
30
 
31
still:
31
still:
32
    mov     eax,10                          ; wait here for event
32
    mov     eax,10                          ; wait here for event
33
    mcall
33
    mcall
34
 
34
 
35
    cmp     eax,1                           ; redraw request ?
35
    cmp     eax,1                           ; redraw request ?
36
    jz      red
36
    jz      red
37
    cmp     eax,2                           ; key in buffer ?
37
    cmp     eax,2                           ; key in buffer ?
38
    jz      key
38
    jz      key
39
    cmp     eax,3                           ; button in buffer ?
39
    cmp     eax,3                           ; button in buffer ?
40
    jz      button
40
    jz      button
41
 
41
 
42
    jmp     still
42
    jmp     still
43
key:                            ; Keys are not valid at this part of the
43
key:                            ; Keys are not valid at this part of the
44
    mov     eax,2               ; loop. Just read it and ignore
44
    mov     eax,2               ; loop. Just read it and ignore
45
    mcall
45
    mcall
46
    jmp     still
46
    jmp     still
47
 
47
 
48
button:                         ; button
48
button:                         ; button
49
    mov     eax,17              ; get id
49
    mov     eax,17              ; get id
50
    mcall
50
    mcall
51
 
51
 
52
    cmp     ah,1                ; button id=1 ?
52
    cmp     ah,1                ; button id=1 ?
53
    jnz     noclose
53
    jnz     noclose
54
 
54
 
55
    ; close socket before exiting
55
    ; close socket before exiting
56
    mov     eax, 53
56
    mov     eax, 53
57
    mov     ebx, 1
57
    mov     ebx, 1
58
    mov     ecx, [socketNum]
58
    mov     ecx, [socketNum]
59
    mcall
59
    mcall
60
 
60
 
61
    mov     eax,0xffffffff      ; close this program
61
    mov     eax,0xffffffff      ; close this program
62
    mcall
62
    mcall
63
 
63
 
64
noclose:
64
noclose:
65
    cmp     ah,3                ; Resolve address?
65
    cmp     ah,3                ; Resolve address?
66
    jnz     still
66
    jnz     still
67
 
67
 
68
    call    draw_window
68
    call    draw_window
69
 
69
 
70
    call    contactDHCPServer
70
    call    contactDHCPServer
71
 
71
 
72
    jmp     still
72
    jmp     still
73
 
73
 
74
 
74
 
75
;***************************************************************************
75
;***************************************************************************
76
;   Function
76
;   Function
77
;      parseResponse
77
;      parseResponse
78
;
78
;
79
;   Description
79
;   Description
80
;      extracts the fields ( client IP address and options ) from
80
;      extracts the fields ( client IP address and options ) from
81
;      a DHCP response
81
;      a DHCP response
82
;      The values go into
82
;      The values go into
83
;       dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP,
83
;       dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP,
84
;       dhcpDNSIP, dhcpSubnet
84
;       dhcpDNSIP, dhcpSubnet
85
;      The message is stored in dhcpMsg
85
;      The message is stored in dhcpMsg
86
;
86
;
87
;***************************************************************************
87
;***************************************************************************
88
parseResponse:
88
parseResponse:
89
    mov     edx, dhcpMsg
89
    mov     edx, dhcpMsg
90
 
90
 
91
    mov     eax, [edx+16]
91
    mov     eax, [edx+16]
92
    mov     [dhcpClientIP], eax
92
    mov     [dhcpClientIP], eax
93
 
93
 
94
    ; Scan options
94
    ; Scan options
95
 
95
 
96
    add     edx, 240        ; Point to first option
96
    add     edx, 240        ; Point to first option
97
 
97
 
98
pr001:
98
pr001:
99
    ; Get option id
99
    ; Get option id
100
    mov     al, [edx]
100
    mov     al, [edx]
101
    cmp     al, 0xff        ; End of options?
101
    cmp     al, 0xff        ; End of options?
102
    je      pr_exit
102
    je      pr_exit
103
 
103
 
104
    cmp     al, 53          ; Msg type is a single byte option
104
    cmp     al, 53          ; Msg type is a single byte option
105
    jne     pr002
105
    jne     pr002
106
 
106
 
107
    mov     al, [edx+2]
107
    mov     al, [edx+2]
108
    mov     [dhcpMsgType], al
108
    mov     [dhcpMsgType], al
109
    add     edx, 3
109
    add     edx, 3
110
    jmp     pr001           ; Get next option
110
    jmp     pr001           ; Get next option
111
 
111
 
112
pr002:
112
pr002:
113
    ; All other (accepted) options are 4 bytes in length
113
    ; All other (accepted) options are 4 bytes in length
114
    inc     edx
114
    inc     edx
115
    movzx   ecx, byte [edx]
115
    movzx   ecx, byte [edx]
116
    inc     edx             ; point to data
116
    inc     edx             ; point to data
117
 
117
 
118
    cmp     al, 54          ; server id
118
    cmp     al, 54          ; server id
119
    jne     pr0021
119
    jne     pr0021
120
    mov     eax, [edx]      ; All options are 4 bytes, so get it
120
    mov     eax, [edx]      ; All options are 4 bytes, so get it
121
    mov     [dhcpServerIP], eax
121
    mov     [dhcpServerIP], eax
122
    jmp     pr003
122
    jmp     pr003
123
 
123
 
124
pr0021:
124
pr0021:
125
    cmp     al, 51          ; lease
125
    cmp     al, 51          ; lease
126
    jne     pr0022
126
    jne     pr0022
127
    mov     eax, [edx]      ; All options are 4 bytes, so get it
127
    mov     eax, [edx]      ; All options are 4 bytes, so get it
128
    mov     [dhcpLease], eax
128
    mov     [dhcpLease], eax
129
    jmp     pr003
129
    jmp     pr003
130
 
130
 
131
pr0022:
131
pr0022:
132
    cmp     al, 1           ; subnet mask
132
    cmp     al, 1           ; subnet mask
133
    jne     pr0023
133
    jne     pr0023
134
    mov     eax, [edx]      ; All options are 4 bytes, so get it
134
    mov     eax, [edx]      ; All options are 4 bytes, so get it
135
    mov     [dhcpSubnet], eax
135
    mov     [dhcpSubnet], eax
136
    jmp     pr003
136
    jmp     pr003
137
 
137
 
138
pr0023:
138
pr0023:
139
    cmp     al, 6           ; dns ip
139
    cmp     al, 6           ; dns ip
140
    jne     pr0024
140
    jne     pr0024
141
    mov     eax, [edx]      ; All options are 4 bytes, so get it
141
    mov     eax, [edx]      ; All options are 4 bytes, so get it
142
    mov     [dhcpDNSIP], eax
142
    mov     [dhcpDNSIP], eax
143
 
143
 
144
pr0024:
144
pr0024:
145
    cmp     al, 3           ; gateway ip
145
    cmp     al, 3           ; gateway ip
146
    jne     pr003
146
    jne     pr003
147
    mov     eax, [edx]      ; All options are 4 bytes, so get it
147
    mov     eax, [edx]      ; All options are 4 bytes, so get it
148
    mov     [dhcpGateway], eax
148
    mov     [dhcpGateway], eax
149
 
149
 
150
pr003:
150
pr003:
151
    add     edx, ecx
151
    add     edx, ecx
152
    jmp     pr001
152
    jmp     pr001
153
 
153
 
154
pr_exit:
154
pr_exit:
155
    ret
155
    ret
156
 
156
 
157
 
157
 
158
;***************************************************************************
158
;***************************************************************************
159
;   Function
159
;   Function
160
;      buildRequest
160
;      buildRequest
161
;
161
;
162
;   Description
162
;   Description
163
;      Creates a DHCP request packet.
163
;      Creates a DHCP request packet.
164
;
164
;
165
;***************************************************************************
165
;***************************************************************************
166
buildRequest:
166
buildRequest:
167
    ; Clear dhcpMsg to all zeros
167
    ; Clear dhcpMsg to all zeros
168
    xor     eax,eax
168
    xor     eax,eax
169
    mov     edi,dhcpMsg
169
    mov     edi,dhcpMsg
170
    mov     ecx,512
170
    mov     ecx,512
171
    cld
171
    cld
172
    rep     stosb
172
    rep     stosb
173
 
173
 
174
    mov     edx, dhcpMsg
174
    mov     edx, dhcpMsg
175
 
175
 
176
    mov     [edx], byte 0x01                ; Boot request
176
    mov     [edx], byte 0x01                ; Boot request
177
    mov     [edx+1], byte 0x01              ; Ethernet
177
    mov     [edx+1], byte 0x01              ; Ethernet
178
    mov     [edx+2], byte 0x06              ; Ethernet h/w len
178
    mov     [edx+2], byte 0x06              ; Ethernet h/w len
179
    mov     [edx+4], dword 0x11223344       ; xid
179
    mov     [edx+4], dword 0x11223344       ; xid
180
    mov     [edx+10], byte 0x80             ; broadcast flag set
180
    mov     [edx+10], byte 0x80             ; broadcast flag set
181
    mov     [edx+236], dword 0x63538263     ; magic number
181
    mov     [edx+236], dword 0x63538263     ; magic number
182
 
182
 
183
    ; option DHCP msg type
183
    ; option DHCP msg type
184
    mov     [edx+240], word 0x0135
184
    mov     [edx+240], word 0x0135
185
    mov     al, [dhcpMsgType]
185
    mov     al, [dhcpMsgType]
186
    mov     [edx+240+2], al
186
    mov     [edx+240+2], al
187
 
187
 
188
    ; option Lease time = infinity
188
    ; option Lease time = infinity
189
    mov     [edx+240+3], word 0x0433
189
    mov     [edx+240+3], word 0x0433
190
    mov     eax, [dhcpLease]
190
    mov     eax, [dhcpLease]
191
    mov     [edx+240+5], eax
191
    mov     [edx+240+5], eax
192
 
192
 
193
    ; option requested IP address
193
    ; option requested IP address
194
    mov     [edx+240+9], word 0x0432
194
    mov     [edx+240+9], word 0x0432
195
    mov     eax, [dhcpClientIP]
195
    mov     eax, [dhcpClientIP]
196
    mov     [edx+240+11], eax
196
    mov     [edx+240+11], eax
197
 
197
 
198
    ; option request list
198
    ; option request list
199
    mov     [edx+240+15], word 0x0437
199
    mov     [edx+240+15], word 0x0437
200
    mov     [edx+240+17], dword 0x0f060301
200
    mov     [edx+240+17], dword 0x0f060301
201
 
201
 
202
    ; Check which msg we are sending
202
    ; Check which msg we are sending
203
    cmp     [dhcpMsgType], byte 0x01
203
    cmp     [dhcpMsgType], byte 0x01
204
    jne     br001
204
    jne     br001
205
 
205
 
206
    ; "Discover" options
206
    ; "Discover" options
207
    ; end of options marker
207
    ; end of options marker
208
    mov     [edx+240+21], byte 0xff
208
    mov     [edx+240+21], byte 0xff
209
 
209
 
210
    mov     [dhcpMsgLen], dword 262
210
    mov     [dhcpMsgLen], dword 262
211
    jmp     br_exit
211
    jmp     br_exit
212
 
212
 
213
br001:
213
br001:
214
    ; "Request" options
214
    ; "Request" options
215
 
215
 
216
    ; server IP
216
    ; server IP
217
    mov     [edx+240+21], word 0x0436
217
    mov     [edx+240+21], word 0x0436
218
    mov     eax, [dhcpServerIP]
218
    mov     eax, [dhcpServerIP]
219
    mov     [edx+240+23], eax
219
    mov     [edx+240+23], eax
220
 
220
 
221
    ; end of options marker
221
    ; end of options marker
222
    mov     [edx+240+27], byte 0xff
222
    mov     [edx+240+27], byte 0xff
223
 
223
 
224
    mov     [dhcpMsgLen], dword 268
224
    mov     [dhcpMsgLen], dword 268
225
 
225
 
226
br_exit:
226
br_exit:
227
    ret
227
    ret
228
 
228
 
229
 
229
 
230
 
230
 
231
;***************************************************************************
231
;***************************************************************************
232
;   Function
232
;   Function
233
;      contactDHCPServer
233
;      contactDHCPServer
234
;
234
;
235
;   Description
235
;   Description
236
;       negotiates settings with a DHCP server
236
;       negotiates settings with a DHCP server
237
;
237
;
238
;***************************************************************************
238
;***************************************************************************
239
contactDHCPServer:
239
contactDHCPServer:
240
    ; First, open socket
240
    ; First, open socket
241
    mov     eax, 53
241
    mov     eax, 53
242
    mov     ebx, 0
242
    mov     ebx, 0
243
    mov     ecx, 68                 ; local port dhcp client
243
    mov     ecx, 68                 ; local port dhcp client
244
    mov     edx, 67                 ; remote port - dhcp server
244
    mov     edx, 67                 ; remote port - dhcp server
245
    mov     esi, 0xffffffff         ; broadcast
245
    mov     esi, 0xffffffff         ; broadcast
246
    mcall
246
    mcall
247
 
247
 
248
    mov     [socketNum], eax
248
    mov     [socketNum], eax
249
 
249
 
250
    ; Setup the first msg we will send
250
    ; Setup the first msg we will send
251
    mov     [dhcpMsgType], byte 0x01 ; DHCP discover
251
    mov     [dhcpMsgType], byte 0x01 ; DHCP discover
252
    mov     [dhcpLease], dword 0xffffffff
252
    mov     [dhcpLease], dword 0xffffffff
253
    mov     [dhcpClientIP], dword 0
253
    mov     [dhcpClientIP], dword 0
254
    mov     [dhcpServerIP], dword 0
254
    mov     [dhcpServerIP], dword 0
255
 
255
 
256
    call    buildRequest
256
    call    buildRequest
257
 
257
 
258
ctr000:
258
ctr000:
259
    ; write to socket ( send broadcast request )
259
    ; write to socket ( send broadcast request )
260
    mov     eax, 53
260
    mov     eax, 53
261
    mov     ebx, 4
261
    mov     ebx, 4
262
    mov     ecx, [socketNum]
262
    mov     ecx, [socketNum]
263
    mov     edx, [dhcpMsgLen]
263
    mov     edx, [dhcpMsgLen]
264
    mov     esi, dhcpMsg
264
    mov     esi, dhcpMsg
265
    mcall
265
    mcall
266
 
266
 
267
    ; Setup the DHCP buffer to receive response
267
    ; Setup the DHCP buffer to receive response
268
 
268
 
269
    mov     eax, dhcpMsg
269
    mov     eax, dhcpMsg
270
    mov     [dhcpMsgLen], eax      ; Used as a pointer to the data
270
    mov     [dhcpMsgLen], eax      ; Used as a pointer to the data
271
 
271
 
272
    ; now, we wait for
272
    ; now, we wait for
273
    ; UI redraw
273
    ; UI redraw
274
    ; UI close
274
    ; UI close
275
    ; or data from remote
275
    ; or data from remote
276
 
276
 
277
ctr001:
277
ctr001:
278
    mov     eax,10                 ; wait here for event
278
    mov     eax,10                 ; wait here for event
279
    mcall
279
    mcall
280
 
280
 
281
    cmp     eax,1                  ; redraw request ?
281
    cmp     eax,1                  ; redraw request ?
282
    je      ctr003
282
    je      ctr003
283
    cmp     eax,2                  ; key in buffer ?
283
    cmp     eax,2                  ; key in buffer ?
284
    je      ctr004
284
    je      ctr004
285
    cmp     eax,3                  ; button in buffer ?
285
    cmp     eax,3                  ; button in buffer ?
286
    je      ctr005
286
    je      ctr005
287
 
287
 
288
 
288
 
289
    ; Any data in the UDP receive buffer?
289
    ; Any data in the UDP receive buffer?
290
    mov     eax, 53
290
    mov     eax, 53
291
    mov     ebx, 2
291
    mov     ebx, 2
292
    mov     ecx, [socketNum]
292
    mov     ecx, [socketNum]
293
    mcall
293
    mcall
294
 
294
 
295
    cmp     eax, 0
295
    cmp     eax, 0
296
    je      ctr001
296
    je      ctr001
297
 
297
 
298
    ; we have data - this will be the response
298
    ; we have data - this will be the response
299
ctr002:
299
ctr002:
300
    mov     eax, 53
300
    mov     eax, 53
301
    mov     ebx, 3
301
    mov     ebx, 3
302
    mov     ecx, [socketNum]
302
    mov     ecx, [socketNum]
303
    mcall                ; read byte - block (high byte)
303
    mcall                ; read byte - block (high byte)
304
 
304
 
305
    ; Store the data in the response buffer
305
    ; Store the data in the response buffer
306
    mov     eax, [dhcpMsgLen]
306
    mov     eax, [dhcpMsgLen]
307
    mov     [eax], bl
307
    mov     [eax], bl
308
    inc     dword [dhcpMsgLen]
308
    inc     dword [dhcpMsgLen]
309
 
309
 
310
    mov     eax, 53
310
    mov     eax, 53
311
    mov     ebx, 2
311
    mov     ebx, 2
312
    mov     ecx, [socketNum]
312
    mov     ecx, [socketNum]
313
    mcall                ; any more data?
313
    mcall                ; any more data?
314
 
314
 
315
    cmp     eax, 0
315
    cmp     eax, 0
316
    jne     ctr002              ; yes, so get it
316
    jne     ctr002              ; yes, so get it
317
 
317
 
318
    ; depending on which msg we sent, handle the response
318
    ; depending on which msg we sent, handle the response
319
    ; accordingly.
319
    ; accordingly.
320
    ; If the response is to a dhcp discover, then:
320
    ; If the response is to a dhcp discover, then:
321
    ;  1) If response is DHCP OFFER then
321
    ;  1) If response is DHCP OFFER then
322
    ;  1.1) record server IP, lease time & IP address.
322
    ;  1.1) record server IP, lease time & IP address.
323
    ;  1.2) send a request packet
323
    ;  1.2) send a request packet
324
    ;  2) else exit ( display error )
324
    ;  2) else exit ( display error )
325
    ; If the response is to a dhcp request, then:
325
    ; If the response is to a dhcp request, then:
326
    ;  1) If the response is DHCP ACK then
326
    ;  1) If the response is DHCP ACK then
327
    ;  1.1) extract the DNS & subnet fields. Set them in the stack
327
    ;  1.1) extract the DNS & subnet fields. Set them in the stack
328
    ;  2) else exit ( display error )
328
    ;  2) else exit ( display error )
329
 
329
 
330
 
330
 
331
    cmp     [dhcpMsgType], byte 0x01    ; did we send a discover?
331
    cmp     [dhcpMsgType], byte 0x01    ; did we send a discover?
332
    je      ctr007
332
    je      ctr007
333
    cmp     [dhcpMsgType], byte 0x03    ; did we send a request?
333
    cmp     [dhcpMsgType], byte 0x03    ; did we send a request?
334
    je      ctr008
334
    je      ctr008
335
 
335
 
336
    ; should never get here - we only send discover or request
336
    ; should never get here - we only send discover or request
337
    jmp     ctr006
337
    jmp     ctr006
338
 
338
 
339
ctr007:
339
ctr007:
340
    call    parseResponse
340
    call    parseResponse
341
 
341
 
342
    ; Was the response an offer? It should be
342
    ; Was the response an offer? It should be
343
    cmp     [dhcpMsgType], byte 0x02
343
    cmp     [dhcpMsgType], byte 0x02
344
    jne     ctr006                  ; NO - so quit
344
    jne     ctr006                  ; NO - so quit
345
 
345
 
346
    ; send request
346
    ; send request
347
    mov     [dhcpMsgType], byte 0x03 ; DHCP request
347
    mov     [dhcpMsgType], byte 0x03 ; DHCP request
348
    call    buildRequest
348
    call    buildRequest
349
    jmp     ctr000
349
    jmp     ctr000
350
 
350
 
351
ctr008:
351
ctr008:
352
    call    parseResponse
352
    call    parseResponse
353
 
353
 
354
    ; Was the response an ACK? It should be
354
    ; Was the response an ACK? It should be
355
    cmp     [dhcpMsgType], byte 0x05
355
    cmp     [dhcpMsgType], byte 0x05
356
    jne     ctr006                  ; NO - so quit
356
    jne     ctr006                  ; NO - so quit
357
 
357
 
358
    ; Set or display addresses here...
358
    ; Set or display addresses here...
359
 
359
 
360
ctr006:
360
ctr006:
361
    ; close socket
361
    ; close socket
362
    mov     eax, 53
362
    mov     eax, 53
363
    mov     ebx, 1
363
    mov     ebx, 1
364
    mov     ecx, [socketNum]
364
    mov     ecx, [socketNum]
365
    mcall
365
    mcall
366
 
366
 
367
    mov     [socketNum], dword 0xFFFF
367
    mov     [socketNum], dword 0xFFFF
368
 
368
 
369
    call    draw_window
369
    call    draw_window
370
 
370
 
371
    jmp     ctr001
371
    jmp     ctr001
372
 
372
 
373
ctr003:                         ; redraw
373
ctr003:                         ; redraw
374
    call    draw_window
374
    call    draw_window
375
    jmp     ctr001
375
    jmp     ctr001
376
 
376
 
377
ctr004:                         ; key
377
ctr004:                         ; key
378
    mov     eax,2               ; just read it and ignore
378
    mov     eax,2               ; just read it and ignore
379
    mcall
379
    mcall
380
    jmp     ctr001
380
    jmp     ctr001
381
 
381
 
382
ctr005:                         ; button
382
ctr005:                         ; button
383
    mov     eax,17              ; get id
383
    mov     eax,17              ; get id
384
    mcall
384
    mcall
385
 
385
 
386
    ; close socket
386
    ; close socket
387
    mov     eax, 53
387
    mov     eax, 53
388
    mov     ebx, 1
388
    mov     ebx, 1
389
    mov     ecx, [socketNum]
389
    mov     ecx, [socketNum]
390
    mcall
390
    mcall
391
 
391
 
392
    mov     [socketNum], dword 0xFFFF
392
    mov     [socketNum], dword 0xFFFF
393
 
393
 
394
    call    draw_window                     ; at first, draw the window
394
    call    draw_window                     ; at first, draw the window
395
 
395
 
396
    ret
396
    ret
397
 
397
 
398
 
398
 
399
 
399
 
400
 
400
 
401
;   *********************************************
401
;   *********************************************
402
;   *******  WINDOW DEFINITIONS AND DRAW ********
402
;   *******  WINDOW DEFINITIONS AND DRAW ********
403
;   *********************************************
403
;   *********************************************
404
 
404
 
405
 
405
 
406
; Pass in the IP address in edi
406
; Pass in the IP address in edi
407
; row to display in [ya]
407
; row to display in [ya]
408
drawIP:
408
drawIP:
409
;    mov     edi,hostIP
409
;    mov     edi,hostIP
410
    mov     ecx, edi
410
    mov     ecx, edi
411
    add     ecx, 4
411
    add     ecx, 4
412
    mov     edx,[ya]
412
    mov     edx,[ya]
413
    add     edx, 97*65536
413
    add     edx, 97*65536
414
    mov     esi,0x00ffffff
414
    mov     esi,0x00ffffff
415
    mov     ebx,3*65536
415
    mov     ebx,3*65536
416
 
416
 
417
ipdisplay:
417
ipdisplay:
418
    mov     eax,47
418
    mov     eax,47
419
    push    ecx
419
    push    ecx
420
    movzx   ecx,byte [edi]
420
    movzx   ecx,byte [edi]
421
    mcall
421
    mcall
422
    pop     ecx
422
    pop     ecx
423
    add     edx,6*4*65536
423
    add     edx,6*4*65536
424
    inc     edi
424
    inc     edi
425
    cmp     edi,ecx
425
    cmp     edi,ecx
426
    jb      ipdisplay
426
    jb      ipdisplay
427
    ret
427
    ret
428
 
428
 
429
 
429
 
430
drawDHMS:
430
drawDHMS:
431
 
431
 
432
    mov     eax,[edi]
432
    mov     eax,[edi]
433
    bswap   eax
433
    bswap   eax
434
 
434
 
435
    mov     esi,dhms
435
    mov     esi,dhms
436
    mov     ecx,16
436
    mov     ecx,16
437
    mov     edi,text+40*4+12
437
    mov     edi,text+40*4+12
438
    cmp     eax,0xffffffff
438
    cmp     eax,0xffffffff
439
    jne     nforever
439
    jne     nforever
440
    mov     esi,forever
440
    mov     esi,forever
441
    cld
441
    cld
442
    rep     movsb
442
    rep     movsb
443
    ret
443
    ret
444
   nforever:
444
   nforever:
445
    cld
445
    cld
446
    rep     movsb
446
    rep     movsb
447
 
447
 
448
    mov     ecx,28
448
    mov     ecx,28
449
    xor     edx,edx
449
    xor     edx,edx
450
    mov     ebx,60
450
    mov     ebx,60
451
    div     ebx
451
    div     ebx
452
    call    displayDHMS
452
    call    displayDHMS
453
    xor     edx,edx
453
    xor     edx,edx
454
    div     ebx
454
    div     ebx
455
    call    displayDHMS
455
    call    displayDHMS
456
    xor     edx,edx
456
    xor     edx,edx
457
    mov     ebx,24
457
    mov     ebx,24
458
    div     ebx
458
    div     ebx
459
    call    displayDHMS
459
    call    displayDHMS
460
    mov     edx,eax
460
    mov     edx,eax
461
    call    displayDHMS
461
    call    displayDHMS
462
 
462
 
463
    ret
463
    ret
464
 
464
 
465
 
465
 
466
displayDHMS:
466
displayDHMS:
467
 
467
 
468
    pusha
468
    pusha
469
    mov     eax,47
469
    mov     eax,47
470
    mov     ebx,3*65536
470
    mov     ebx,3*65536
471
    mov     edx,ecx
471
    mov     edx,ecx
472
    imul    edx,6
472
    imul    edx,6
473
    shl     edx,16
473
    shl     edx,16
474
    add     edx,1*65536+99
474
    add     edx,1*65536+99
475
    mov     ecx,[esp+20]
475
    mov     ecx,[esp+20]
476
    mov     esi,0xffffff
476
    mov     esi,0xffffff
477
    mcall
477
    mcall
478
    popa
478
    popa
479
    sub     ecx,4
479
    sub     ecx,4
480
    ret
480
    ret
481
 
481
 
482
 
482
 
483
draw_window:
483
draw_window:
484
 
484
 
485
    mov     eax,12                    ; function 12:tell os about windowdraw
485
    mov     eax,12                    ; function 12:tell os about windowdraw
486
    mov     ebx,1                     ; 1, start of draw
486
    mov     ebx,1                     ; 1, start of draw
487
    mcall
487
    mcall
488
                                      ; DRAW WINDOW
488
                                      ; DRAW WINDOW
489
    mov     eax,0                     ; function 0 : define and draw window
489
    mov     eax,0                     ; function 0 : define and draw window
490
    mov     ebx,100*65536+300         ; [x start] *65536 + [x size]
490
    mov     ebx,100*65536+300         ; [x start] *65536 + [x size]
491
    mov     ecx,100*65536+156         ; [y start] *65536 + [y size]
491
    mov     ecx,100*65536+156         ; [y start] *65536 + [y size]
492
    mov     edx,0x13224466            ; color of work area RRGGBB
492
    mov     edx,0x14224466            ; color of work area RRGGBB
493
    mov     edi,title                 ; WINDOW LABEL
493
    mov     edi,title                 ; WINDOW LABEL
494
    mcall
494
    mcall
495
                                      
495
                                      
496
    mov     eax,8                     ; Resolve
496
    mov     eax,8                     ; Resolve
497
    mov     ebx,20*65536+90
497
    mov     ebx,20*65536+90
498
    mov     ecx,127*65536+15
498
    mov     ecx,127*65536+15
499
    mov     edx,3
499
    mov     edx,3
500
    mov     esi,0x557799
500
    mov     esi,0x557799
501
    mcall
501
    mcall
502
 
502
 
503
    ; Pass in the IP address in edi
503
    ; Pass in the IP address in edi
504
    ; row to display in [ya]
504
    ; row to display in [ya]
505
    mov     edi, dhcpClientIP
505
    mov     edi, dhcpClientIP
506
    mov     eax, 35
506
    mov     eax, 35
507
    mov     [ya], eax
507
    mov     [ya], eax
508
    call    drawIP
508
    call    drawIP
509
    mov     edi, dhcpGateway
509
    mov     edi, dhcpGateway
510
    mov     eax, 35 + 16
510
    mov     eax, 35 + 16
511
    mov     [ya], eax
511
    mov     [ya], eax
512
    call    drawIP
512
    call    drawIP
513
    mov     edi, dhcpSubnet
513
    mov     edi, dhcpSubnet
514
    mov     eax, 35 + 32
514
    mov     eax, 35 + 32
515
    mov     [ya], eax
515
    mov     [ya], eax
516
    call    drawIP
516
    call    drawIP
517
    mov     edi, dhcpDNSIP
517
    mov     edi, dhcpDNSIP
518
    mov     eax, 35 + 48
518
    mov     eax, 35 + 48
519
    mov     [ya], eax
519
    mov     [ya], eax
520
    call    drawIP
520
    call    drawIP
521
    mov     edi, dhcpLease
521
    mov     edi, dhcpLease
522
    call    drawDHMS
522
    call    drawDHMS
523
 
523
 
524
    ; Re-draw the screen text
524
    ; Re-draw the screen text
525
    cld
525
    cld
526
    mov     eax,4
526
    mov     eax,4
527
    mov     ebx,25*65536+35           ; draw info text with function 4
527
    mov     ebx,25*65536+35           ; draw info text with function 4
528
    mov     ecx,0xffffff
528
    mov     ecx,0xffffff
529
    mov     edx,text
529
    mov     edx,text
530
    mov     esi,40
530
    mov     esi,40
531
newline:
531
newline:
532
    mcall
532
    mcall
533
    add     ebx,16
533
    add     ebx,16
534
    add     edx,40
534
    add     edx,40
535
    cmp     [edx],byte 'x'
535
    cmp     [edx],byte 'x'
536
    jnz     newline
536
    jnz     newline
537
 
537
 
538
 
538
 
539
    mov     eax,12                    ; function 12:tell os about windowdraw
539
    mov     eax,12                    ; function 12:tell os about windowdraw
540
    mov     ebx,2                     ; 2, end of draw
540
    mov     ebx,2                     ; 2, end of draw
541
    mcall
541
    mcall
542
 
542
 
543
    ret
543
    ret
544
 
544
 
545
 
545
 
546
 
546
 
547
; DATA AREA
547
; DATA AREA
548
 
548
 
549
ya              dd  0x0
549
ya              dd  0x0
550
 
550
 
551
text:
551
text:
552
    db 'Client IP :    .   .   .                '
552
    db 'Client IP :    .   .   .                '
553
    db 'Gateway IP:    .   .   .                '
553
    db 'Gateway IP:    .   .   .                '
554
    db 'Subnet    :    .   .   .                '
554
    db 'Subnet    :    .   .   .                '
555
    db 'DNS IP    :    .   .   .                '
555
    db 'DNS IP    :    .   .   .                '
556
    db 'Lease Time:    d   h   m   s            '
556
    db 'Lease Time:    d   h   m   s            '
557
    db '                                        '
557
    db '                                        '
558
    db ' SEND REQUEST                           '
558
    db ' SEND REQUEST                           '
559
    db 'x <- END MARKER, DONT DELETE            '
559
    db 'x <- END MARKER, DONT DELETE            '
560
 
560
 
561
 
561
 
562
dhms      db   '   d   h   m   s'
562
dhms      db   '   d   h   m   s'
563
forever   db   'Forever         '
563
forever   db   'Forever         '
564
 
564
 
565
title   db   'DHCP Client Test',0
565
title   db   'DHCP Client Test',0
566
 
566
 
567
dhcpMsgType:    db  0
567
dhcpMsgType:    db  0
568
dhcpLease:      dd  0
568
dhcpLease:      dd  0
569
dhcpClientIP:   dd  0
569
dhcpClientIP:   dd  0
570
dhcpServerIP:   dd  0
570
dhcpServerIP:   dd  0
571
dhcpDNSIP:      dd  0
571
dhcpDNSIP:      dd  0
572
dhcpSubnet:     dd  0
572
dhcpSubnet:     dd  0
573
dhcpGateway:    dd  0
573
dhcpGateway:    dd  0
574
 
574
 
575
dhcpMsgLen:     dd  0
575
dhcpMsgLen:     dd  0
576
socketNum:      dd  0xFFFF
576
socketNum:      dd  0xFFFF
577
dhcpMsg:
577
dhcpMsg:
578
I_END:
578
I_END: