A2osX/LIB/LIBTCPIP.S.CFG.txt
2018-08-08 17:13:37 +02:00

530 lines
8.8 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
* PULLW = PTR to S.IPCFG
*--------------------------------------
CFG.Init >PUSHBI 0
>LDYA L.DEVNAME
>SYSCALL open
bcc .1
inc DEVNAME+8
lda DEVNAME+8
cmp #'8'
bne CFG.Init
>LDYA L.MSG.DEV.KO
>SYSCALL printf
lda #MLI.E.NODEV
.9 sec
rts
.1 sta IPCFG+S.IPCFG.hFD
>PUSHW L.DEVNAME
>LDYA L.MSG.DEV.OK
>SYSCALL printf
CFG.EtcFiles >LDYAI 256
>SYSCALL GetMem
bcc .1
rts
.1 >STYA ZPTmpPtr1
stx CFG.hBuf
>PUSHW L.HOSTNAME
>LDYA L.MSG.CFG
>SYSCALL printf
jsr CFG.Read.HOSTNAME
lda IPCFG+S.IPCFG.HOSTNAME
bne .4
ldy #$ff
.2 iny
lda CFG.DefaultHost,y
sta IPCFG+S.IPCFG.HOSTNAME,y
bne .2
.3 lda A2osX.TIMER16
jsr CFG.A2CharAX
sta IPCFG+S.IPCFG.HOSTNAME+6
stx IPCFG+S.IPCFG.HOSTNAME+7
lda A2osX.TIMER16+1
jsr CFG.A2CharAX
sta IPCFG+S.IPCFG.HOSTNAME+8
stx IPCFG+S.IPCFG.HOSTNAME+9
.4 >PUSHW L.TCPIP.CONF
>LDYA L.MSG.CFG
>SYSCALL printf
jsr CFG.Read.TCPIP.CONF
lda IPCFG+S.IPCFG.IP
beq .5
lda #S.IPCFG.STATUS.OK
sta IPCFG+S.IPCFG.STATUS
.5 >PUSHW L.HOSTS
>LDYA L.MSG.CFG
>SYSCALL printf
jsr CFG.Read.HOSTS
jsr SET.IPCFG.I
lda CFG.hBuf
>SYSCALL freemem
.9 rts
*--------------------------------------
CFG.Read.HOSTNAME
>LDYA L.HOSTNAME
jsr CFG.Read.Open
jsr CFG.Read.Result
bcs .9
.1 jsr CFG.Read.GetS
bcs .8
lda (ZPTmpPtr1)
beq .1 empty line...
cmp #'#
beq .1 comment...
ldy #0
.2 lda (ZPTmpPtr1),y
sta IPCFG+S.IPCFG.HOSTNAME,y
beq .8 end of name
iny
cpy #15
bne .2
.8 clc
.HS B0 BCS
.9 sec
jmp CFG.Read.Close
*--------------------------------------
CFG.Read.TCPIP.CONF
>LDYA L.TCPIP.CONF
jsr CFG.Read.Open
jsr CFG.Read.Result
bcs .9
.1 jsr CFG.Read.GetS
bcs .8
lda (ZPTmpPtr1)
beq .1 empty line...
cmp #'#
beq .1 comment...
ldy #$ff
.2 iny
lda (ZPTmpPtr1),y
beq .3
cmp #' '
bne .2
.3 lda L.CFG.Keywords
sta ZPTmpPtr2
lda L.CFG.Keywords+1
sta ZPTmpPtr2+1
ldx #0
.4 phy save keyword len
tya
cmp (ZPTmpPtr2)
bne .6
.5 lda (ZPTmpPtr2),y
dey
cmp (ZPTmpPtr1),y
bne .6
tya
bne .5
ply discard keyword len
jsr .80
bra .1
.6 lda (ZPTmpPtr2)
sec
adc ZPTmpPtr2
sta ZPTmpPtr2
bcc .7
inc ZPTmpPtr2+1
.7 inx
inx
ply reset keyword len
lda (ZPTmpPtr2)
bne .4
bra .1
.8 clc
.HS B0 BCS
.9 sec
jmp CFG.Read.Close
.80 jmp (J.CFG.Keywords,x)
*--------------------------------------
CFG.Read.address
ldx #S.IPCFG.IP+3
bra CFG.Read.IP
CFG.Read.netmask
ldx #S.IPCFG.MASK+3
bra CFG.Read.IP
CFG.Read.gateway
ldx #S.IPCFG.GW+3
bra CFG.Read.IP
CFG.Read.nameserver
ldx #S.IPCFG.DNS1+3
lda IPCFG,x
beq CFG.Read.IP
ldx #S.IPCFG.DNS2+3
CFG.Read.IP ldy #3
.1 txa
clc
adc L.IPCFG
pha
lda L.IPCFG+1
adc #0
>PUSHA @IP[3][2][1][0]
pla
>PUSHA
dex
dey
bpl .1
>PUSHBI 8 4 PTRs on stack
>PUSHW L.HST.SScanF
lda (ZPTmpPtr2)
sec
adc ZPTmpPtr1
tay
lda ZPTmpPtr1+1
adc #0
>SYSCALL SScanF
rts
CFG.Read.dnsdomain
lda (ZPTmpPtr2)
sec
adc ZPTmpPtr1
sta ZPTmpPtr1
bcc .1
inc ZPTmpPtr1+1
.1 ldy #$ff
.2 iny
lda (ZPTmpPtr1),y
sta IPCFG+S.IPCFG.DOMAIN,y
beq .8
cpy #K.DNS.MAXLEN
bne .2
lda #0
sta IPCFG+S.IPCFG.DOMAIN,y
.8 rts
*--------------------------------------
*--------------------------------------
CFG.Read.HOSTS >LDYA L.HOSTS
jsr CFG.Read.Open
jsr CFG.Read.Result
bcs .9
.1 jsr CFG.Read.GetS
bcs .8
lda (ZPTmpPtr1)
beq .1 empty line...
cmp #'#
beq .1 comment...
jsr CFG.Read.HOSTS.Scan
bcs .1
cmp #5
bcc .1 less than 5 parameters, ignore
beq .2 no alias
>LDYA L.CFG.ALIAS
jsr CFG.DNS.Add
.2 >LDYA L.CFG.HOSTNAME
jsr CFG.DNS.Add
bra .1
.8 clc
.HS B0 BCS
.9 sec
jmp CFG.Read.Close
*--------------------------------------
CFG.Read.HOSTS.Scan
>PUSHW L.CFG.ALIAS
>PUSHW L.CFG.HOSTNAME
ldx #3
.2 txa
clc
adc L.CFG.IP
tay
lda L.CFG.IP+1
adc #0
>PUSHYA @IP[3][2][1][0]
dex
bpl .2
>PUSHBI 12 6 PTRs on stack
>PUSHW L.CFG.HOSTS.SScanF
>LDYA ZPTmpPtr1
>SYSCALL SScanF
rts
*--------------------------------------
CFG.DNS.ADD >STYA ZPTmpPtr1
>LDYA L.CFG.IP
>STYA ZPTmpPtr2
>PUSHYA
>PUSHW ZPTmpPtr1
jsr DNS.Add
>PUSHW ZPTmpPtr1
ldy #3
.1 lda (ZPTmpPtr2),y
>PUSHA
dey
bpl .1
>LDYA L.MSG.DNS.ADD
bcc .8
>LDYA L.MSG.DNS.ERR
.8 >SYSCALL printf
rts
*--------------------------------------
CFG.Read.Open stz CFG.hCfgFile
stz CFG.hCfgPath
>SYSCALL ExpandStr
bcs .9
stx CFG.hCfgPath
pha
>PUSHWI 0
>PUSHBI 6 S.FI.T.TXT
>PUSHBI SYS.FOpen.R
pla
>SYSCALL fopen
bcs .9
sta CFG.hCfgFile
* clc
.9 rts
*--------------------------------------
CFG.Read.Close php
pha
lda CFG.hCfgPath
beq .1
>SYSCALL FreeMem
.1 lda CFG.hCfgFile
beq .8
>SYSCALL fclose
.8 pla
plp
rts
*--------------------------------------
CFG.Read.Result php
bcc .1
>PUSHA
>LDYA L.MSG.CFG.KO
bra .2
.1 >LDYA L.MSG.CFG.OK
.2 >SYSCALL printf
plp
rts
*--------------------------------------
CFG.Read.GetS >PUSHWI 255
>PUSHW ZPTmpPtr1
lda CFG.hCfgFile
>SYSCALL fgets
rts
*--------------------------------------
CFG.A2CharAX pha
lsr
lsr
lsr
lsr
ora #$30
cmp #'9'+1
bcc .1
adc #6
.1 tax
pla
and #$0F
ora #$30
cmp #'9'+1
bcc .8
adc #6
.8 rts
*--------------------------------------
SET.IPCFG >PULLW ZPTmpPtr1 IPCFG
ldy #0
.1 lda (ZPTmpPtr1),y
sta IPCFG,y
iny
cpy #S.IPCFG
bne .1
SET.IPCFG.I >LDYA L.DCB.NIC
>STYA IOCTL+S.IOCTL.BUFPTR
lda #S.IOCTL.STATCODE.GETDCB
sta IOCTL+S.IOCTL.STATCODE
>PUSHW L.IOCTL
>PUSHBI IOCTL.STATUS
lda IPCFG+S.IPCFG.hFD
>SYSCALL IOCTL
bcs *
ldx #5
.10 lda DCB.NIC+S.DCB.NIC.MAC,x
sta IPCFG+S.IPCFG.MAC,x
sta ARP.REQ.SRCMAC,x
sta ARP.REQ.SHA,x
sta ARP.REP.SRCMAC,x
sta ARP.REP.SHA,x
dex
bpl .10
ldx #3
.11 lda IPCFG+S.IPCFG.IP,x
sta ARP.REQ.SPA,x
sta ARP.REP.SPA,x
sta DNS.SOCKET.SA,x
dex
bpl .11
lda DCB.NIC+S.DCB.NIC.FLAGS
and #S.DCB.NIC.FLAGS.ARPOFFLOAD
beq .2
ldx #11
.1 lda IPCFG+S.IPCFG.IP,x
sta DCB.NIC+S.DCB.NIC.IP,x
dex
bpl .1
lda S.IOCTL.CTRLCODE.SETDCB
sta S.IOCTL.CTRLCODE
>PUSHW L.IOCTL
>PUSHBI IOCTL.CONTROL
lda IPCFG+S.IPCFG.hFD
>SYSCALL IOCTL
bcs .9
.2 lda hDNSSocket1
beq .3
jsr SKT.Close
stz hDNSSocket1
.3 lda hDNSSocket2
beq .4
jsr SKT.Close
stz hDNSSocket2
.4 lda IPCFG+S.IPCFG.DNS1
beq .6
ldx #3
.5 lda IPCFG+S.IPCFG.DNS1,x
sta DNS.SOCKET.DA,x
dex
bpl .5
stz DNS.SOCKET.SP
stz DNS.SOCKET.SP+1
>PUSHW L.DNS.SOCKET
jsr SKT.New
bcs .9
stx hDNSSocket1
.6 lda IPCFG+S.IPCFG.DNS2
beq .8
ldx #3
.7 lda IPCFG+S.IPCFG.DNS2,x
sta DNS.SOCKET.DA,x
dex
bpl .7
stz DNS.SOCKET.SP
stz DNS.SOCKET.SP+1
>PUSHW L.DNS.SOCKET
jsr SKT.New
bcs .9
stx hDNSSocket2
.8 clc
.9 rts
*--------------------------------------
* grab a copy on the fly for lib function
* OUT :
* Y,A = PTR to S.IPCFG
*--------------------------------------
GET.IPCFG >LDYA L.IPCFG
clc
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.CFG
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
ASM