A2osX/SBIN/DHCPCLNT.S.txt

514 lines
10 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
LOMEM $C00
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
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
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
CS.RUN.SDISC >PUSHWI DHCP.DISC.LEN
>PUSHW L.DHCP.DISC
jsr CS.RUN.SKT.SEND
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
2016-03-27 21:00:19 +00:00
>PUSHWI DHCP.REQ.LEN
>PUSHW L.DHCP.REQ
jsr CS.RUN.SKT.SEND
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.SEND ldy #hSocket
>PUSHB (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.SEND
rts
*--------------------------------------
CS.RUN.SKT.RCVD ldy #hSocket
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.RCVDA
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
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
bpl .1 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
2016-03-27 21:00:19 +00:00
dec
sta (pData),y
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
.1 bit #S.EVT.F.KEY is it a KEY event?
beq .8
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
ldy #S.EVT.hDEV is Event from active IN device?
2015-03-14 21:48:35 +00:00
lda (pEvent),y
2017-01-12 17:43:45 +00:00
ldy #S.PS.hStdIn
2016-03-27 21:00:19 +00:00
cmp (pPs),y
bne .9
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .8
2015-03-14 21:48:35 +00:00
2016-03-27 21:00:19 +00:00
lda #$FF
ldy #bCTRLC
sta (pData),y
bra .8
2015-06-03 18:30:57 +00:00
2016-03-27 21:00:19 +00:00
.8 clc
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-03-27 21:00:19 +00:00
CS.QUIT ldy #hSocket
lda (pData),y
beq .1
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
.1 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
.8 clc
rts
.9 sec
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
clc
rts
.9 sec
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
clc
rts
.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
ldy #bCTRLC
lda (pData),y
bmi .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
.BS 16
*--------------------------------------
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
bCTRLC .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