2009-01-29 18:36:59 +01:00
|
|
|
; Zero-config
|
|
|
|
; v 1.4
|
2006-07-25 11:47:45 +02:00
|
|
|
;
|
2009-01-29 18:36:59 +01:00
|
|
|
; DHCP code is based on that by Mike Hibbet (DHCP client for menuetos)
|
2006-07-25 11:47:45 +02:00
|
|
|
;
|
2009-01-29 18:36:59 +01:00
|
|
|
; Written by HidnPlayr & Derpenguin
|
2007-02-10 15:01:21 +01:00
|
|
|
|
2006-07-25 11:47:45 +02:00
|
|
|
use32
|
|
|
|
org 0x0
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
db 'MENUET01' ; 8 byte id
|
|
|
|
dd 0x01 ; header version
|
|
|
|
dd START ; start of code
|
|
|
|
dd IM_END ; size of image
|
|
|
|
dd I_END ; memory for app
|
|
|
|
dd I_END ; esp
|
2009-01-29 18:36:59 +01:00
|
|
|
dd 0x0 , path ; I_Param , I_Icon
|
2007-02-10 20:10:48 +01:00
|
|
|
|
|
|
|
; CONFIGURATION
|
|
|
|
|
|
|
|
|
|
|
|
TIMEOUT equ 60 ; in seconds
|
|
|
|
BUFFER equ 1024 ; in bytes
|
|
|
|
__DEBUG__ equ 1 ; enable/disable
|
|
|
|
__DEBUG_LEVEL__ equ 1 ; 1 = all, 2 = errors
|
|
|
|
|
|
|
|
; CONFIGURATION FOR LINK-LOCAL
|
|
|
|
|
|
|
|
PROBE_WAIT equ 1 ; second (initial random delay)
|
|
|
|
PROBE_MIN equ 1 ; second (minimum delay till repeated probe)
|
|
|
|
PROBE_MAX equ 2 ; seconds (maximum delay till repeated probe)
|
|
|
|
PROBE_NUM equ 3 ; (number of probe packets)
|
|
|
|
|
|
|
|
ANNOUNCE_NUM equ 2 ; (number of announcement packets)
|
|
|
|
ANNOUNCE_INTERVAL equ 2 ; seconds (time between announcement packets)
|
|
|
|
ANNOUNCE_WAIT equ 2 ; seconds (delay before announcing)
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
MAX_CONFLICTS equ 10 ; (max conflicts before rate limiting)
|
|
|
|
|
|
|
|
RATE_LIMIT_INTERVAL equ 60 ; seconds (delay between successive attempts)
|
|
|
|
|
|
|
|
DEFEND_INTERVAL equ 10 ; seconds (min. wait between defensive ARPs)
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
include '../../../proc32.inc'
|
|
|
|
include '../../../macros.inc'
|
2010-12-27 13:29:39 +01:00
|
|
|
include 'ETH.INC'
|
2007-02-10 15:01:21 +01:00
|
|
|
include 'debug-fdo.inc'
|
2007-02-10 20:10:48 +01:00
|
|
|
include 'dhcp.inc'
|
2012-11-09 11:42:30 +01:00
|
|
|
include '../../../dll.inc'
|
2007-02-10 15:01:21 +01:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
START: ; start of execution
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 40, 0
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
eth.set_network_drv 0x00000383
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
DEBUGF 1,"Zero-config service:\n"
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
eth.status eax ; Read the Stack status
|
|
|
|
test eax,eax ; if eax is zero, no driver was found
|
2007-02-10 15:01:21 +01:00
|
|
|
jnz @f
|
2009-01-29 18:36:59 +01:00
|
|
|
DEBUGF 1,"No Card found!\n"
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp close
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
@@:
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Detected card: %x\n",eax
|
2007-02-10 15:01:21 +01:00
|
|
|
@@:
|
|
|
|
eth.check_cable eax
|
|
|
|
test al,al
|
|
|
|
jnz @f
|
2009-01-29 18:36:59 +01:00
|
|
|
DEBUGF 1,"Cable disconnected!\n"
|
|
|
|
mcall 5, 500 ; loop until cable is connected (check every 5 sec)
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp @r
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
@@:
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.read_mac MAC
|
2009-01-29 18:36:59 +01:00
|
|
|
DEBUGF 1,"MAC: %x-%x-%x-%x-%x-%x\n",[MAC]:2,[MAC+1]:2,[MAC+2]:2,[MAC+3]:2,[MAC+4]:2,[MAC+5]:2
|
|
|
|
|
|
|
|
cld
|
|
|
|
mov edi, path ; Calculate the length of zero-terminated string
|
|
|
|
xor al , al
|
|
|
|
mov ecx, 1024
|
|
|
|
repnz scas byte[es:edi]
|
|
|
|
dec edi
|
|
|
|
|
|
|
|
mov esi, filename
|
|
|
|
mov ecx, 5
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
mcall 68,11
|
|
|
|
|
|
|
|
stdcall dll.Load,@IMPORT
|
|
|
|
or eax,eax
|
|
|
|
jnz skip_ini
|
|
|
|
|
|
|
|
|
|
|
|
invoke ini.get_str, path, str_ipconfig, str_type, inibuf, 16, 0
|
|
|
|
|
|
|
|
mov eax,dword[inibuf]
|
|
|
|
|
|
|
|
cmp eax,'stat'
|
|
|
|
jne skip_ini
|
|
|
|
|
|
|
|
invoke ini.get_str, path, str_ipconfig, str_ip, inibuf, 16, 0
|
|
|
|
mov edx, inibuf
|
|
|
|
call Ip2dword
|
|
|
|
eth.set_IP edx
|
|
|
|
|
|
|
|
invoke ini.get_str, path, str_ipconfig, str_gateway, inibuf, 16, 0
|
|
|
|
mov edx, inibuf
|
|
|
|
call Ip2dword
|
|
|
|
eth.set_GATEWAY edx
|
|
|
|
|
|
|
|
invoke ini.get_str, path, str_ipconfig, str_dns, inibuf, 16, 0
|
|
|
|
mov edx, inibuf
|
|
|
|
call Ip2dword
|
|
|
|
eth.set_DNS edx
|
|
|
|
|
|
|
|
invoke ini.get_str, path, str_ipconfig, str_subnet, inibuf, 16, 0
|
|
|
|
mov edx, inibuf
|
|
|
|
call Ip2dword
|
|
|
|
eth.set_SUBNET edx
|
|
|
|
|
|
|
|
|
|
|
|
mcall -1
|
|
|
|
|
|
|
|
|
|
|
|
skip_ini:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
eth.check_port 68,eax ; Check if port 68 is available
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp eax,1
|
|
|
|
je @f
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Port 68 is already in use!\n"
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp close
|
|
|
|
|
|
|
|
@@:
|
2007-02-10 20:10:48 +01:00
|
|
|
eth.open_udp 68,67,-1,[socketNum] ; open socket (local,remote,ip,socket)
|
|
|
|
; Setup the first msg we will send
|
|
|
|
mov byte [dhcpMsgType], 0x01 ; DHCP discover
|
|
|
|
mov dword [dhcpLease], esi ; esi is still -1 (-1 = forever)
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 26, 9
|
2007-02-10 15:01:21 +01:00
|
|
|
imul eax,100
|
|
|
|
mov [currTime],eax
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
buildRequest: ; Creates a DHCP request packet.
|
2009-01-29 18:36:59 +01:00
|
|
|
stdcall mem.Alloc, BUFFER
|
|
|
|
mov [dhcpMsg], eax
|
|
|
|
test eax,eax
|
|
|
|
jz apipa
|
|
|
|
|
|
|
|
|
|
|
|
mov edi, eax
|
2007-02-10 15:01:21 +01:00
|
|
|
mov ecx,BUFFER
|
2009-01-29 18:36:59 +01:00
|
|
|
xor eax,eax
|
2006-07-25 11:47:45 +02:00
|
|
|
cld
|
|
|
|
rep stosb
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
mov edx,[dhcpMsg]
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
mov [edx], byte 0x01 ; Boot request
|
|
|
|
mov [edx+1], byte 0x01 ; Ethernet
|
|
|
|
mov [edx+2], byte 0x06 ; Ethernet h/w len
|
|
|
|
mov [edx+4], dword 0x11223344 ; xid
|
2007-02-10 15:01:21 +01:00
|
|
|
mov eax,[currTime]
|
|
|
|
mov [edx+8], eax ; secs, our uptime
|
2006-07-25 11:47:45 +02:00
|
|
|
mov [edx+10], byte 0x80 ; broadcast flag set
|
2007-02-10 15:01:21 +01:00
|
|
|
mov eax, dword [MAC] ; first 4 bytes of MAC
|
|
|
|
mov [edx+28],dword eax
|
|
|
|
mov ax, word [MAC+4] ; last 2 bytes of MAC
|
|
|
|
mov [edx+32],word ax
|
2006-07-25 11:47:45 +02:00
|
|
|
mov [edx+236], dword 0x63538263 ; magic number
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240], word 0x0135 ; option DHCP msg type
|
2006-07-25 11:47:45 +02:00
|
|
|
mov al, [dhcpMsgType]
|
|
|
|
mov [edx+240+2], al
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240+3], word 0x0433 ; option Lease time = infinity
|
2006-07-25 11:47:45 +02:00
|
|
|
mov eax, [dhcpLease]
|
|
|
|
mov [edx+240+5], eax
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240+9], word 0x0432 ; option requested IP address
|
|
|
|
mov eax, [dhcpClientIP]
|
|
|
|
mov [edx+240+11], eax
|
|
|
|
mov [edx+240+15], word 0x0437 ; option request list
|
2006-07-25 11:47:45 +02:00
|
|
|
mov [edx+240+17], dword 0x0f060301
|
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp [dhcpMsgType], byte 0x01 ; Check which msg we are sending
|
2007-02-10 20:10:48 +01:00
|
|
|
jne request_options
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240+21], byte 0xff ; "Discover" options
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [dhcpMsgLen], dword 262 ; end of options marker
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp send_request
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
request_options:
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240+21], word 0x0436 ; server IP
|
2006-07-25 11:47:45 +02:00
|
|
|
mov eax, [dhcpServerIP]
|
|
|
|
mov [edx+240+23], eax
|
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [edx+240+27], byte 0xff ; end of options marker
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
mov [dhcpMsgLen], dword 268
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
send_request:
|
2009-01-29 18:36:59 +01:00
|
|
|
eth.write_udp [socketNum],[dhcpMsgLen],[dhcpMsg] ; write to socket ( send broadcast request )
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
mov eax, [dhcpMsg] ; Setup the DHCP buffer to receive response
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [dhcpMsgLen], eax ; Used as a pointer to the data
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
mov eax,23 ; wait here for event (data from remote)
|
|
|
|
mov ebx,TIMEOUT*10
|
2007-05-10 15:48:35 +02:00
|
|
|
mcall
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.poll [socketNum]
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
test eax,eax
|
2007-02-10 20:10:48 +01:00
|
|
|
jnz read_data
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 2,"Timeout!\n"
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.close_udp [socketNum]
|
|
|
|
jmp apipa ; no server found, lets try zeroconf
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
read_data: ; we have data - this will be the response
|
2009-01-29 18:36:59 +01:00
|
|
|
eth.read_packet [socketNum], [dhcpMsg], BUFFER
|
2007-02-10 15:01:21 +01:00
|
|
|
mov [dhcpMsgLen], eax
|
|
|
|
eth.close_udp [socketNum]
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
; depending on which msg we sent, handle the response
|
|
|
|
; accordingly.
|
|
|
|
; If the response is to a dhcp discover, then:
|
|
|
|
; 1) If response is DHCP OFFER then
|
|
|
|
; 1.1) record server IP, lease time & IP address.
|
|
|
|
; 1.2) send a request packet
|
|
|
|
; If the response is to a dhcp request, then:
|
|
|
|
; 1) If the response is DHCP ACK then
|
|
|
|
; 1.1) extract the DNS & subnet fields. Set them in the stack
|
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp [dhcpMsgType], byte 0x01 ; did we send a discover?
|
2006-07-25 11:47:45 +02:00
|
|
|
je discover
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp [dhcpMsgType], byte 0x03 ; did we send a request?
|
2006-07-25 11:47:45 +02:00
|
|
|
je request
|
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp close ; really unknown, what we did
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
discover:
|
|
|
|
call parseResponse
|
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp [dhcpMsgType], byte 0x02 ; Was the response an offer?
|
|
|
|
jne apipa ; NO - so we do zeroconf
|
|
|
|
mov [dhcpMsgType], byte 0x03 ; DHCP request
|
2006-07-25 11:47:45 +02:00
|
|
|
jmp buildRequest
|
|
|
|
|
|
|
|
request:
|
2007-02-10 20:10:48 +01:00
|
|
|
call parseResponse
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp [dhcpMsgType], byte 0x05 ; Was the response an ACK? It should be
|
|
|
|
jne apipa ; NO - so we do zeroconf
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp close
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
;***************************************************************************
|
|
|
|
; Function
|
|
|
|
; parseResponse
|
|
|
|
;
|
|
|
|
; Description
|
|
|
|
; extracts the fields ( client IP address and options ) from
|
|
|
|
; a DHCP response
|
|
|
|
; The values go into
|
|
|
|
; dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP,
|
|
|
|
; dhcpDNSIP, dhcpSubnet
|
|
|
|
; The message is stored in dhcpMsg
|
|
|
|
;
|
|
|
|
;***************************************************************************
|
|
|
|
parseResponse:
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Data received, parsing response\n"
|
2009-01-29 18:36:59 +01:00
|
|
|
mov edx, [dhcpMsg]
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
pusha
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.set_IP [edx+16]
|
|
|
|
mov eax,[edx]
|
|
|
|
mov [dhcpClientIP],eax
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Client: %u.%u.%u.%u\n",[edx+16]:1,[edx+17]:1,[edx+18]:1,[edx+19]:1
|
2006-07-25 11:47:45 +02:00
|
|
|
popa
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
add edx, 240 ; Point to first option
|
|
|
|
xor ecx, ecx
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
next_option:
|
|
|
|
add edx, ecx
|
2006-07-25 11:47:45 +02:00
|
|
|
pr001:
|
|
|
|
mov al, [edx]
|
2007-02-10 20:10:48 +01:00
|
|
|
cmp al, 0xff ; End of options?
|
2006-07-25 11:47:45 +02:00
|
|
|
je pr_exit
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
cmp al, dhcp_msg_type ; Msg type is a single byte option
|
|
|
|
jne @f
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
mov al, [edx+2]
|
|
|
|
mov [dhcpMsgType], al
|
|
|
|
add edx, 3
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp pr001 ; Get next option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
@@:
|
2006-07-25 11:47:45 +02:00
|
|
|
inc edx
|
|
|
|
movzx ecx, byte [edx]
|
2007-02-10 20:10:48 +01:00
|
|
|
inc edx ; point to data
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
cmp al, dhcp_dhcp_server_id ; server ip
|
|
|
|
jne @f
|
|
|
|
mov eax, [edx]
|
2006-07-25 11:47:45 +02:00
|
|
|
mov [dhcpServerIP], eax
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Server: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
|
|
|
|
jmp next_option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
@@:
|
|
|
|
cmp al, dhcp_address_time
|
|
|
|
jne @f
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
pusha
|
2007-02-10 20:10:48 +01:00
|
|
|
mov eax,[edx]
|
|
|
|
bswap eax
|
|
|
|
mov [dhcpLease],eax
|
|
|
|
DEBUGF 1,"lease: %d\n",eax
|
2006-07-25 11:47:45 +02:00
|
|
|
popa
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp next_option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
@@:
|
|
|
|
cmp al, dhcp_subnet_mask
|
|
|
|
jne @f
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
pusha
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.set_SUBNET [edx]
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Subnet: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
|
2006-07-25 11:47:45 +02:00
|
|
|
popa
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp next_option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
@@:
|
|
|
|
cmp al, dhcp_router
|
|
|
|
jne @f
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
pusha
|
|
|
|
eth.set_GATEWAY [edx]
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Gateway: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
|
2006-07-25 11:47:45 +02:00
|
|
|
popa
|
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp next_option
|
|
|
|
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
@@:
|
|
|
|
cmp al, dhcp_domain_server
|
|
|
|
jne next_option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
pusha
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.set_DNS [edx]
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"DNS: %u.%u.%u.%u\n",[edx]:1,[edx+1]:1,[edx+2]:1,[edx+3]:1
|
2007-02-10 15:01:21 +01:00
|
|
|
popa
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
jmp next_option
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
pr_exit:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
; DEBUGF 1,"Sending ARP announce\n"
|
|
|
|
; eth.ARP_ANNOUNCE [dhcpClientIP] ; send an ARP announce packet
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp close
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
apipa:
|
2009-01-29 18:36:59 +01:00
|
|
|
stdcall mem.Free, [dhcpMsg]
|
|
|
|
|
|
|
|
link_local:
|
2007-02-10 15:01:21 +01:00
|
|
|
call random
|
2007-02-10 20:10:48 +01:00
|
|
|
mov ecx,0xfea9 ; IP 169.254.0.0 link local net, see RFC3927
|
2007-02-10 15:01:21 +01:00
|
|
|
mov cx,ax
|
2007-02-10 20:10:48 +01:00
|
|
|
eth.set_IP ecx ; mask is 255.255.0.0
|
2011-01-29 22:56:41 +01:00
|
|
|
DEBUGF 1,"Link Local IP assigned: 169.254.%u.%u\n",[generator+2]:1,[generator+3]:1
|
2007-02-10 15:01:21 +01:00
|
|
|
eth.set_SUBNET 0xffff
|
|
|
|
eth.set_GATEWAY 0x0
|
|
|
|
eth.set_DNS 0x0
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 5, PROBE_WAIT*100
|
2007-02-10 15:01:21 +01:00
|
|
|
|
|
|
|
xor esi,esi
|
|
|
|
probe_loop:
|
2007-02-10 20:10:48 +01:00
|
|
|
call random ; create a pseudo random number in eax (seeded by MAC)
|
2007-02-10 15:01:21 +01:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
cmp al,PROBE_MIN*100 ; check if al is bigger then PROBE_MIN
|
|
|
|
jge @f ; all ok
|
|
|
|
add al,(PROBE_MAX-PROBE_MIN)*100 ; al is too small
|
2007-02-10 15:01:21 +01:00
|
|
|
@@:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp al,PROBE_MAX*100
|
|
|
|
jle @f
|
|
|
|
sub al,(PROBE_MAX-PROBE_MIN)*100
|
|
|
|
@@:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
movzx ebx,al
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Waiting %u0ms\n",ebx
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 5
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Sending Probe\n"
|
|
|
|
; eth.ARP_PROBE MAC
|
2007-02-10 15:01:21 +01:00
|
|
|
inc esi
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp esi,PROBE_NUM
|
|
|
|
jl probe_loop
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2011-01-29 22:56:41 +01:00
|
|
|
; now we wait further ANNOUNCE_WAIT seconds and send ANNOUNCE_NUM ARP announces. If any other host has assigned
|
2007-02-10 15:01:21 +01:00
|
|
|
; IP within this time, we should create another adress, that have to be done later
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Waiting %us\n",ANNOUNCE_WAIT
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 5, ANNOUNCE_WAIT*100
|
2006-07-25 11:47:45 +02:00
|
|
|
xor esi,esi
|
2007-02-10 15:01:21 +01:00
|
|
|
announce_loop:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Sending Announce\n"
|
|
|
|
; eth.ARP_ANNOUNCE MAC
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
inc esi
|
2007-02-10 15:01:21 +01:00
|
|
|
cmp esi,ANNOUNCE_NUM
|
|
|
|
je @f
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
DEBUGF 1,"Waiting %us\n",ANNOUNCE_INTERVAL
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall 5, ANNOUNCE_INTERVAL*100
|
2007-02-10 15:01:21 +01:00
|
|
|
jmp announce_loop
|
|
|
|
@@:
|
2007-02-10 20:10:48 +01:00
|
|
|
; we should, instead of closing, detect ARP conflicts and detect if cable keeps connected ;)
|
|
|
|
|
|
|
|
close:
|
2009-01-29 18:36:59 +01:00
|
|
|
mcall -1
|
2007-02-10 20:10:48 +01:00
|
|
|
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
random: ; Pseudo random actually
|
2007-02-10 20:10:48 +01:00
|
|
|
|
2007-02-10 15:01:21 +01:00
|
|
|
mov eax,[generator]
|
|
|
|
add eax,-43ab45b5h
|
|
|
|
ror eax,1
|
|
|
|
bswap eax
|
|
|
|
xor eax,dword[MAC]
|
|
|
|
ror eax,1
|
|
|
|
xor eax,dword[MAC+2]
|
|
|
|
mov [generator],eax
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
ret
|
2006-07-25 11:47:45 +02:00
|
|
|
|
|
|
|
; DATA AREA
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
align 16
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library \
|
|
|
|
libini,'libini.obj'
|
|
|
|
|
|
|
|
import libini, \
|
2009-06-03 23:12:49 +02:00
|
|
|
ini.get_str,'ini_get_str'
|
2009-01-29 18:36:59 +01:00
|
|
|
|
2007-02-10 20:10:48 +01:00
|
|
|
include_debug_strings
|
2007-02-10 15:01:21 +01:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
filename db '.ini',0
|
|
|
|
str_ip db 'ip',0
|
|
|
|
str_subnet db 'subnet',0
|
|
|
|
str_gateway db 'gateway',0
|
|
|
|
str_dns db 'dns',0
|
|
|
|
str_ipconfig db 'ipconfig',0
|
|
|
|
str_type db 'type',0
|
|
|
|
|
|
|
|
|
2006-07-25 11:47:45 +02:00
|
|
|
IM_END:
|
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
inibuf rb 16
|
|
|
|
|
|
|
|
dhcpClientIP dd ?
|
|
|
|
dhcpMsgType db ?
|
|
|
|
dhcpLease dd ?
|
|
|
|
dhcpServerIP dd ?
|
|
|
|
|
|
|
|
dhcpMsgLen dd ?
|
|
|
|
socketNum dd ?
|
|
|
|
|
|
|
|
MAC dp ?
|
|
|
|
currTime dd ?
|
|
|
|
renewTime dd ?
|
|
|
|
generator dd ?
|
|
|
|
|
|
|
|
dhcpMsg dd ?
|
2007-02-10 15:01:21 +01:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
I_END_2:
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2009-01-29 18:36:59 +01:00
|
|
|
path rb 1024+5
|
2006-07-25 11:47:45 +02:00
|
|
|
|
2012-11-09 11:42:30 +01:00
|
|
|
I_END:
|