Subversion Repositories Kolibri OS

Rev

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

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