A2osX/BIN/IPCONFIG.S.DHCP.txt

379 lines
6.4 KiB
Plaintext
Raw Normal View History

2018-12-06 16:39:53 +00:00
NEW
PREFIX
AUTO 4,1
.LIST OFF
*--------------------------------------
2019-01-05 20:33:08 +00:00
DHCP.INIT lda (pIPCFG)
2018-12-06 16:39:53 +00:00
and #S.IPCFG.STATUS.OK
bne .99 Already Configured, exit
ldy #S.IPCFG.hFD
2019-01-05 20:33:08 +00:00
lda (pIPCFG),y
2018-12-06 16:39:53 +00:00
beq .98
ldy #S.IPCFG-1
2019-01-05 20:33:08 +00:00
.1 lda (pIPCFG),y
2018-12-06 16:39:53 +00:00
sta IPCFG,y
dey
bne .1
stz IPCFG+S.IPCFG.STATUS
ldx #3
.11 lda A2osX.TIMER16,x
sta DHCP.DISC.XID,x
sta DHCP.REQ.XID,x
dex
bpl .11
ldx #5
.2 lda IPCFG+S.IPCFG.MAC,x
sta DHCP.DISC.CHADDR,x
sta DHCP.REQ.CHADDR,x
dex
bpl .2
clc
.9 rts
2019-01-05 20:33:08 +00:00
.98 >LDYA L.MSG.DHCP.ND
2018-12-06 16:39:53 +00:00
bra .90
2019-01-05 20:33:08 +00:00
.99 >LDYA L.MSG.DHCP.NA
2018-12-06 16:39:53 +00:00
.90 >SYSCALL puts
lda #0
sec
rts
*--------------------------------------
2019-01-05 20:33:08 +00:00
DHCP.RUN >PUSHBI 0 no protocol
2018-12-06 16:39:53 +00:00
lda #S.SOCKET.T.DGRAM
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcc .1
2019-01-05 20:33:08 +00:00
.9 jmp DHCP.RUN.KO
2018-12-06 16:39:53 +00:00
.1 >STA.G hSocket
pha
>PUSHW L.SA.LOCAL
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcs .9
>PUSHWI S.SOCKET.O.BROADCAST
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.setsockopt
>PUSHW L.SA.REMOTE
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
bcs .9
2019-01-05 20:33:08 +00:00
>LDYA L.MSG.DHCP.CFG1
2018-12-06 16:39:53 +00:00
>SYSCALL puts
jsr Init.Timeout
2019-01-05 20:33:08 +00:00
DHCP.RUN.SDISC >PUSHWI DHCP.DISC.LEN
2018-12-06 16:39:53 +00:00
>PUSHW L.DHCP.DISC
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
bcc .1
2019-01-05 20:33:08 +00:00
jmp DHCP.RUN.KO
2018-12-06 16:39:53 +00:00
.1 lda #S.IPCFG.STATUS.SDISC
sta IPCFG
2019-01-05 20:33:08 +00:00
DHCP.RUN.ROFFER >SLEEP
2018-12-06 16:39:53 +00:00
2019-01-05 20:33:08 +00:00
jsr DHCP.RUN.SKT.RCVD
2018-12-06 16:39:53 +00:00
bcc .1
jsr Wait.Timeout
2019-01-05 20:33:08 +00:00
bne DHCP.RUN.ROFFER
2018-12-06 16:39:53 +00:00
lda #1
2019-01-05 20:33:08 +00:00
jmp DHCP.RUN.KO
2018-12-06 16:39:53 +00:00
.1 jsr CheckDHCPOffer
2019-01-05 20:33:08 +00:00
bcs DHCP.RUN.ROFFER
2018-12-06 16:39:53 +00:00
lda #S.IPCFG.STATUS.ROFFER
sta IPCFG
2019-01-05 20:33:08 +00:00
DHCP.RUN.SREQ ldx #3
2018-12-06 16:39:53 +00:00
.1 >PUSHB IPCFG+S.IPCFG.DHCPSRVR,x
dex
bpl .1
>PUSHBI 4
2019-01-05 20:33:08 +00:00
>LDYA L.MSG.DHCP.CFG2
2018-12-06 16:39:53 +00:00
>SYSCALL printf
>PUSHWI DHCP.REQ.LEN
>PUSHW L.DHCP.REQ
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
2019-01-05 20:33:08 +00:00
bcs DHCP.RUN.KO
2018-12-06 16:39:53 +00:00
lda #S.IPCFG.STATUS.SREQ
sta IPCFG
2019-01-05 20:33:08 +00:00
DHCP.RUN.RACK >SLEEP
2018-12-06 16:39:53 +00:00
2019-01-05 20:33:08 +00:00
jsr DHCP.RUN.SKT.RCVD
2018-12-06 16:39:53 +00:00
bcc .1
jsr Wait.Timeout
2019-01-05 20:33:08 +00:00
bne DHCP.RUN.RACK
2018-12-06 16:39:53 +00:00
lda #2
2019-01-05 20:33:08 +00:00
bra DHCP.RUN.KO
2018-12-06 16:39:53 +00:00
.1 jsr CheckDHCPAck
2019-01-05 20:33:08 +00:00
bcs DHCP.RUN.RACK
2018-12-06 16:39:53 +00:00
2019-01-05 20:33:08 +00:00
DHCP.RUN.OK lda #S.IPCFG.STATUS.OK
2018-12-06 16:39:53 +00:00
sta IPCFG
>PUSHW L.IPCFG
>LIBCALL hLIBTCPIP,LIBTCPIP.SET.IPCFG
ldx #3
2019-01-05 20:33:08 +00:00
2018-12-06 16:39:53 +00:00
.1 lda IPCFG+S.IPCFG.MASK,x
>PUSHA
dex
bpl .1
ldx #3
2019-01-05 20:33:08 +00:00
2018-12-06 16:39:53 +00:00
.2 lda IPCFG+S.IPCFG.IP,x
>PUSHA
dex
bpl .2
>PUSHBI 8
2019-01-05 20:33:08 +00:00
>LDYA L.MSG.DHCP.OK
2018-12-06 16:39:53 +00:00
>SYSCALL printf
lda #0 Leave with NO ERROR
sec
rts
2019-01-05 20:33:08 +00:00
DHCP.RUN.KO pha
2018-12-06 16:39:53 +00:00
>PUSHA
>PUSHBI 1
2019-01-05 20:33:08 +00:00
>LDYA L.MSG.DHCP.KO
2018-12-06 16:39:53 +00:00
>SYSCALL printf
pla
sec
rts
*--------------------------------------
2019-01-05 20:33:08 +00:00
DHCP.RUN.SKT.RCVD
>LDA.G hSocket
2018-12-06 16:39:53 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcs .9
>STA.G hFrame
>SYSCALL GetMemPtr
>STYA ZPFrameBase
.9 rts
*--------------------------------------
2019-01-05 20:33:08 +00:00
DHCP.QUIT >LDA.G hSocket
2018-12-06 16:39:53 +00:00
beq .1
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2019-01-05 20:33:08 +00:00
.1 clc
2018-12-06 16:39:53 +00:00
rts
*--------------------------------------
CheckDHCPOffer jsr CheckDHCPXID
bcs .9
lda ZPFrameBase
clc
adc #S.DHCP.OPTIONS
sta ZPFramePtr
lda ZPFrameBase+1
adc /S.DHCP.OPTIONS
sta ZPFramePtr+1
lda (ZPFramePtr)
cmp #S.DHCP.OPTIONS.MSGTYPE
bne .9
ldy #2
lda (ZPFramePtr),y
cmp #S.DHCP.OPTIONS.DHCPOffer
bne .9
ldy #S.DHCP.GIADDR+3
ldx #3
.1 lda (ZPFrameBase),y
sta DHCP.REQ.GIADDR,x
dey
dex
bpl .1
ldy #S.DHCP.YIADDR+3
ldx #3
.2 lda (ZPFrameBase),y
sta DHCP.REQ.OPT.REQIP,x
sta IPCFG+S.IPCFG.IP,x
dey
dex
bpl .2
ldy #S.IP.SRC+3
ldx #3
.3 lda (ZPFrameBase),y
sta DHCP.REQ.OPT.SVRIP,x
sta IPCFG+S.IPCFG.DHCPSRVR,x
dey
dex
bpl .3
.5 inc ZPFramePtr skip Option 53 (DHCPOffer:530102)
bne .6
inc ZPFramePtr+1
.6 lda (ZPFramePtr)
sec
adc ZPFramePtr add option len + 1
sta ZPFramePtr
bcc .7
inc ZPFramePtr+1
.7 lda (ZPFramePtr)
cmp #S.DHCP.OPTIONS.END
beq .8
jsr GetDHCPOption
bra .5
.8 jsr CS.RUN.DISCARD
clc
rts
.9 jsr CS.RUN.DISCARD
sec
rts
*--------------------------------------
GetDHCPOption cmp #S.DHCP.OPTIONS.MASK
bne .1
ldx #S.IPCFG.MASK
bra GetDHCPOption.CopyIP
.1 cmp #S.DHCP.OPTIONS.GW
bne .2
ldx #S.IPCFG.GW
bra GetDHCPOption.CopyIP
.2 cmp #S.DHCP.OPTIONS.DNS
bne .3
ldx #S.IPCFG.DNS1
bra GetDHCPOption.CopyIP
.3 cmp #S.DHCP.OPTIONS.DOMAIN
bne .9
ldy #1
lda (ZPFramePtr),y Get String len
cmp #80
bcc .4
lda #79
.4 sta IPCFG+S.IPCFG.DOMAIN store len
tax
.5 iny
lda (ZPFramePtr),y
sta IPCFG+S.IPCFG.DOMAIN-1,y
dex
bne .5
.9 rts
*--------------------------------------
GetDHCPOption.CopyIP
ldy #1
lda (ZPFramePtr),y Get Byte count
cmp #9
bcc .1
lda #8 max 8 bytes (2 DNS)
.1 iny
.2 pha
lda (ZPFramePtr),y
sta IPCFG,x
iny
inx
pla
dec
bne .2
rts
*--------------------------------------
CheckDHCPAck jsr CheckDHCPXID
bcs .9
lda ZPFrameBase
clc
adc #S.DHCP.OPTIONS
sta ZPFramePtr
lda ZPFrameBase+1
adc /S.DHCP.OPTIONS
sta ZPFramePtr+1
lda (ZPFramePtr)
cmp #S.DHCP.OPTIONS.MSGTYPE
bne .9
ldy #2
lda (ZPFramePtr),y
cmp #S.DHCP.OPTIONS.DHCPAck
bne .9
jsr CS.RUN.DISCARD
clc
rts
.9 jsr CS.RUN.DISCARD
sec
rts
*--------------------------------------
2019-01-05 20:33:08 +00:00
CS.RUN.DISCARD >LDA.G hFrame
>SYSCALL FreeMem
rts
*--------------------------------------
2018-12-06 16:39:53 +00:00
CheckDHCPXID ldy #S.DHCP.XID+3
ldx #3
.1 lda (ZPFrameBase),y
cmp DHCP.DISC.XID,x same XID ?
bne .9
dey
dex
bpl .1
clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE USR/SRC/SBIN/IPCONFIG.S.DHCP
LOAD USR/SRC/SBIN/IPCONFIG.S
ASM