A2osX/SBIN/DHCPCLNT.S.txt

496 lines
9.8 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
2017-01-29 21:47:19 +00:00
LOMEM $A00
2015-03-14 21:48:35 +00:00
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
2015-06-03 18:30:57 +00:00
.TF /A2OSX.BOOT/SBIN/DHCPCLNT
2015-03-14 21:48:35 +00:00
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/LIBTCPIP.I
2017-02-10 07:29:58 +00:00
.INB /A2OSX.DEV/INC/DHCP.I
2015-03-14 21:48:35 +00:00
*--------------------------------------
TIMEOUT.MAX .EQ 100 10 sec.
*--------------------------------------
2016-03-27 21:00:19 +00:00
ZPIPCfgPtr .EQ ZPBIN
ZPFrameBase .EQ ZPBIN+2
ZPFramePtr .EQ ZPBIN+4
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-06-03 18:30:57 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
2015-03-14 21:48:35 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.IPCFG .DA IPCFG
2016-03-27 21:00:19 +00:00
L.Socket .DA Socket
L.MSG.CFG1 .DA MSG.CFG1
L.MSG.CFG2 .DA MSG.CFG2
L.MSG.CFG.KO .DA MSG.CFG.KO
L.MSG.CFG.OK .DA MSG.CFG.OK
L.MSG.CFG.ND .DA MSG.CFG.ND
L.MSG.CFG.NA .DA MSG.CFG.NA
2016-03-27 21:00:19 +00:00
L.DHCP.DISC .DA DHCP.DISC
L.DHCP.REQ .DA DHCP.REQ
2015-03-14 21:48:35 +00:00
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL LoadLibYA
2015-03-14 21:48:35 +00:00
sta hLIBTCPIP
>LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG
bcs .9
2016-03-27 21:00:19 +00:00
>STYA ZPIPCfgPtr
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
lda (ZPIPCfgPtr)
and #S.IPCFG.STATUS.OK
bne .99 Already Configured, exit
ldy #S.IPCFG.HDEV
2016-03-27 21:00:19 +00:00
lda (ZPIPCfgPtr),y
beq .98
2016-03-27 21:00:19 +00:00
ldy #S.IPCFG-1
.1 lda (ZPIPCfgPtr),y
2015-03-14 21:48:35 +00:00
sta IPCFG,y
2016-03-27 21:00:19 +00:00
dey
bne .1
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
stz IPCFG
2015-03-14 21:48:35 +00:00
>LDYA A2OSX.TIMER16
2016-03-27 21:00:19 +00:00
>STYA DHCP.DISC.XID
>STYA DHCP.REQ.XID
2015-03-14 21:48:35 +00:00
>LDYA A2OSX.RANDOM16
2016-03-27 21:00:19 +00:00
>STYA DHCP.DISC.XID+2
>STYA DHCP.REQ.XID+2
2015-03-14 21:48:35 +00:00
ldx #5
.2 lda IPCFG+S.IPCFG.MAC,x
2016-03-27 21:00:19 +00:00
sta DHCP.DISC.CHADDR,x
sta DHCP.REQ.CHADDR,x
2015-03-14 21:48:35 +00:00
dex
bpl .2
2015-06-03 18:30:57 +00:00
lda (pPs)
2015-03-14 21:48:35 +00:00
ora #S.PS.F.EVENT Now accept events
2015-06-03 18:30:57 +00:00
sta (pPs)
2015-03-14 21:48:35 +00:00
clc
.9 rts
.98 >LDYA L.MSG.CFG.ND
bra .90
.99 >LDYA L.MSG.CFG.NA
.90 >SYSCALL CPrintFYA
lda #0
sec
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-03-27 21:00:19 +00:00
CS.RUN >PUSHW L.Socket
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New
2016-03-27 21:00:19 +00:00
bcc .1
jmp CS.RUN.KO
.1 txa
ldy #hSocket
sta (pData),y
>LDYA L.MSG.CFG1
>SYSCALL CPrintFYA
2016-03-27 21:00:19 +00:00
jsr Init.Timeout
2017-02-13 07:26:18 +00:00
CS.RUN.SDISC ldy #hSocket
>PUSHB (pData),y
2016-03-27 21:00:19 +00:00
>PUSHW L.DHCP.DISC
2017-02-13 07:26:18 +00:00
>PUSHWI DHCP.DISC.LEN
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Write
2016-03-27 21:00:19 +00:00
bcc .1
jmp CS.RUN.KO
2016-03-27 21:00:19 +00:00
.1 lda #S.IPCFG.STATUS.SDISC
2015-03-14 21:48:35 +00:00
sta IPCFG
CS.RUN.ROFFER >SYSCALL Sleep
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
jsr CS.RUN.SKT.RCVD
bcc .1
jsr Wait.Timeout
2016-03-27 21:00:19 +00:00
bcc CS.RUN.ROFFER
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
lda #1
jmp CS.RUN.KO
.1 jsr CheckDHCPOffer
bcs CS.RUN.ROFFER
lda #S.IPCFG.STATUS.ROFFER
sta IPCFG
CS.RUN.SREQ ldx #3
.1 >PUSHB IPCFG+S.IPCFG.DHCPSRVR,x
dex
bpl .1
>LDYA L.MSG.CFG2
>SYSCALL CPrintFYA
2017-02-13 07:26:18 +00:00
ldy #hSocket
>PUSHB (pData),y
2016-03-27 21:00:19 +00:00
>PUSHW L.DHCP.REQ
2017-02-13 07:26:18 +00:00
>PUSHWI DHCP.REQ.LEN
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Write
2015-03-14 21:48:35 +00:00
bcs CS.RUN.KO
lda #S.IPCFG.STATUS.SREQ
sta IPCFG
CS.RUN.RACK >SYSCALL Sleep
2016-03-27 21:00:19 +00:00
jsr CS.RUN.SKT.RCVD
bcc .1
jsr Wait.Timeout
bcc CS.RUN.RACK
2015-03-14 21:48:35 +00:00
lda #2
2016-03-27 21:00:19 +00:00
bra CS.RUN.KO
2016-03-27 21:00:19 +00:00
.1 jsr CheckDHCPAck
bcs CS.RUN.RACK
2015-03-14 21:48:35 +00:00
CS.RUN.OK lda #S.IPCFG.STATUS.OK
sta IPCFG
>PUSHW L.IPCFG
>LIBCALL hLIBTCPIP,LIBTCPIP.SET.IPCFG
ldx #3
.1 lda IPCFG+S.IPCFG.MASK,x
>PUSHA
dex
bpl .1
ldx #3
.2 lda IPCFG+S.IPCFG.IP,x
>PUSHA
dex
bpl .2
>LDYA L.MSG.CFG.OK
>SYSCALL CPrintFYA
2015-03-14 21:48:35 +00:00
lda #0 Leave with NO ERROR
sec
rts
2016-03-27 21:00:19 +00:00
CS.RUN.KO pha
>PUSHA
>LDYA L.MSG.CFG.KO
>SYSCALL CPrintFYA
2016-03-27 21:00:19 +00:00
pla
sec
rts
*--------------------------------------
CS.RUN.SKT.RCVD ldy #hSocket
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.ReadA
2016-03-27 21:00:19 +00:00
bcs .9
ldy #hFrame
sta (pData),y
>SYSCALL GetMemPtrA
2016-03-27 21:00:19 +00:00
>STYA ZPFrameBase
.9 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2017-01-29 21:47:19 +00:00
CS.RUN.DISCARD ldy #hFrame
lda (pData),y
>SYSCALL FreeMemA
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
2017-01-26 21:57:35 +00:00
bpl .9 is it a TIMER event?
2015-03-14 21:48:35 +00:00
ldy #TimeOut
lda (pData),y
2015-03-14 21:48:35 +00:00
beq .9
2017-01-26 21:57:35 +00:00
2016-03-27 21:00:19 +00:00
dec
sta (pData),y
2017-01-26 21:57:35 +00:00
2016-03-27 21:00:19 +00:00
.9 sec do not discard TIMER event
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-03-27 21:00:19 +00:00
CS.QUIT ldy #hSocket
lda (pData),y
2017-02-13 07:26:18 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
2016-03-27 21:00:19 +00:00
lda hLIBTCPIP
>SYSCALL UnloadLibA
2015-03-14 21:48:35 +00:00
clc
rts
*--------------------------------------
2016-03-27 21:00:19 +00:00
CheckDHCPOffer jsr CheckDHCPXID
2015-03-14 21:48:35 +00:00
bcs .9
>LDAXI S.DHCP.OPTIONS
jsr SetFramePtr1AX
ldy #2 DHCPOffer ?
2016-03-27 21:00:19 +00:00
lda (ZPFramePtr),y
2015-03-14 21:48:35 +00:00
cmp #S.DHCP.OPTIONS.DHCPOffer
bne .9
ldy #S.DHCP.YIADDR+3
ldx #3
2016-03-27 21:00:19 +00:00
.1 lda (ZPFrameBase),y
sta DHCP.REQ.OPT.REQIP,x
2015-03-14 21:48:35 +00:00
dey
dex
bpl .1
ldx #3
ldy #S.IPCFG.IP+3
2016-03-27 21:00:19 +00:00
.2 lda DHCP.REQ.OPT.REQIP,x
2015-03-14 21:48:35 +00:00
sta IPCFG,y
dey
dex
bpl .2
ldy #S.IP.SRC+3
ldx #3
2016-03-27 21:00:19 +00:00
.3 lda (ZPFrameBase),y
sta DHCP.REQ.OPT.SVRIP,x
2015-03-14 21:48:35 +00:00
dey
dex
bpl .3
ldx #3
ldy #S.IPCFG.DHCPSRVR+3
2016-03-27 21:00:19 +00:00
.4 lda DHCP.REQ.OPT.SVRIP,x
2015-03-14 21:48:35 +00:00
sta IPCFG,y
dey
dex
bpl .4
2016-03-27 21:00:19 +00:00
.5 inc ZPFramePtr skip Option 53 (DHCPOffer:530102)
2015-03-14 21:48:35 +00:00
bne .6
2016-03-27 21:00:19 +00:00
inc ZPFramePtr+1
.6 lda (ZPFramePtr)
2015-03-14 21:48:35 +00:00
sec
2016-03-27 21:00:19 +00:00
adc ZPFramePtr add option len + 1
sta ZPFramePtr
2015-03-14 21:48:35 +00:00
bcc .7
2016-03-27 21:00:19 +00:00
inc ZPFramePtr+1
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
.7 lda (ZPFramePtr)
2015-03-14 21:48:35 +00:00
cmp #S.DHCP.OPTIONS.END
beq .8
jsr GetDHCPOption
bra .5
2017-01-29 21:47:19 +00:00
.8 jsr CS.RUN.DISCARD
clc
2015-03-14 21:48:35 +00:00
rts
2017-01-29 21:47:19 +00:00
.9 jsr CS.RUN.DISCARD
sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
GetDHCPOption cmp #S.DHCP.OPTIONS.MASK
bne .1
ldx #S.IPCFG.MASK
2015-03-14 21:48:35 +00:00
bra GetDHCPOption.CopyIP
.1 cmp #S.DHCP.OPTIONS.GW
bne .2
ldx #S.IPCFG.GW
2015-03-14 21:48:35 +00:00
bra GetDHCPOption.CopyIP
.2 cmp #S.DHCP.OPTIONS.DNS
bne .3
ldx #S.IPCFG.DNS1
2015-03-14 21:48:35 +00:00
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
2015-03-14 21:48:35 +00:00
.5 iny
lda (ZPFramePtr),y
sta IPCFG+S.IPCFG.DOMAIN-1,y
dex
bne .5
2015-03-14 21:48:35 +00:00
.9 rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
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
2015-03-14 21:48:35 +00:00
iny
inx
pla
dec
2015-03-14 21:48:35 +00:00
bne .2
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2016-03-27 21:00:19 +00:00
CheckDHCPAck jsr CheckDHCPXID
2015-03-14 21:48:35 +00:00
bcs .9
>LDAXI S.DHCP.OPTIONS
jsr SetFramePtr1AX
ldy #2 DHCPAck ?
2016-03-27 21:00:19 +00:00
lda (ZPFramePtr),y
2015-03-14 21:48:35 +00:00
cmp #S.DHCP.OPTIONS.DHCPAck
bne .9
2017-01-29 21:47:19 +00:00
jsr CS.RUN.DISCARD
2015-03-14 21:48:35 +00:00
clc
rts
2017-01-29 21:47:19 +00:00
.9 jsr CS.RUN.DISCARD
sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CheckDHCPXID ldy #S.DHCP.XID+3
ldx #3
2016-03-27 21:00:19 +00:00
.1 lda (ZPFrameBase),y
cmp DHCP.DISC.XID,x same XID ?
2015-03-14 21:48:35 +00:00
bne .9
dey
dex
bpl .1
2017-01-29 21:47:19 +00:00
2015-03-14 21:48:35 +00:00
clc
rts
2017-01-29 21:47:19 +00:00
2015-03-14 21:48:35 +00:00
.9 sec
rts
*--------------------------------------
SetFramePtr1AX clc
2016-03-27 21:00:19 +00:00
adc ZPFrameBase
sta ZPFramePtr
2015-03-14 21:48:35 +00:00
txa
2016-03-27 21:00:19 +00:00
adc ZPFrameBase+1
sta ZPFramePtr+1
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
Init.Timeout ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
clc
.9 rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
CS.END
LIBTCPIP >PSTR "libtcpip.o"
MSG.CFG1 >CSTR "DHCPCLNT:Searching for DHCP servers...\n"
MSG.CFG2 >CSTR "DHCPCLNT:Reply from DHCP Server at %d.%d.%d.%d, requesting...\n"
MSG.CFG.KO >CSTR "DHCPCLNT:Time Out [%h].\n"
MSG.CFG.OK >CSTR "DHCPCLNT:Success:[IP=%d.%d.%d.%d/%d.%d.%d.%d]\n"
MSG.CFG.ND >CSTR "DHCPCLNT:No Device, exiting.\n"
MSG.CFG.NA >CSTR "DHCPCLNT:TCPIP Already configured, exiting.\n"
hLIBTCPIP .BS 1
IPCFG .BS S.IPCFG
2016-03-27 21:00:19 +00:00
FrameLen .BS 2
*--------------------------------------
Socket .DA #S.SOCKET.SOCK.DGRAM
.BS 3
.HS 00.00.00.00 Socket.Src.Addr
.DA UDP.PORT.DHCPC Socket.Src.Port
.HS FF.FF.FF.FF Socket.Dst.Addr
.DA UDP.PORT.DHCPS Socket.Dst.Port
*--------------------------------------
DHCP.DISC .HS 01010600 OP,HTYPE,HLEN,HOPS
DHCP.DISC.XID .BS 4
.HS 0000 SECS
.HS 0000 FLAGS
.HS 00000000 CIADDR
2016-03-27 21:00:19 +00:00
DHCP.DISC.YIADDR .HS 00000000
.HS 00000000 SIADDR
.HS 00000000 GIADDR
2016-03-27 21:00:19 +00:00
DHCP.DISC.CHADDR .HS 00000000.00000000.00000000.00000000
.BS 64 SNAME
.BS 128 FILE
.HS 63825363 COOKIE
.HS 3501 OPT
2015-03-14 21:48:35 +00:00
.DA #S.DHCP.OPTIONS.DHCPDiscover
.HS 37040103060FFF
2016-03-27 21:00:19 +00:00
DHCP.DISC.LEN .EQ *-DHCP.DISC
*--------------------------------------
DHCP.REQ .HS 01010600 OP,HTYPE,HLEN,HOPS
DHCP.REQ.XID .BS 4
.HS 0000 SECS
.HS 0000 FLAGS
.HS 00000000 CIADDR
2016-03-27 21:00:19 +00:00
DHCP.REQ.YIADDR .HS 00000000
.HS 00000000 SIADDR
.HS 00000000 GIADDR
2016-03-27 21:00:19 +00:00
DHCP.REQ.CHADDR .HS 00000000.00000000.00000000.00000000
.BS 64 SNAME
.BS 128 FILE
.HS 63825363 COOKIE
.HS 3501 OPT
2015-03-14 21:48:35 +00:00
.DA #S.DHCP.OPTIONS.DHCPRequest
.HS 3204
2016-03-27 21:00:19 +00:00
DHCP.REQ.OPT.REQIP .BS 4
2015-03-14 21:48:35 +00:00
.HS 3604
2016-03-27 21:00:19 +00:00
DHCP.REQ.OPT.SVRIP .BS 4
2015-03-14 21:48:35 +00:00
.HS FF
2016-03-27 21:00:19 +00:00
DHCP.REQ.LEN .EQ *-DHCP.REQ
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-06-03 18:30:57 +00:00
DS.START
TimeOut .BS 1
2016-03-27 21:00:19 +00:00
hSocket .BS 1
hFrame .BS 1
2015-03-14 21:48:35 +00:00
DS.END
MAN
SAVE SBIN/DHCPCLNT.S
ASM