A2osX/LIB/LIBTCPIP.S.DNS.txt

377 lines
6.4 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
2015-03-14 21:48:35 +00:00
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
*--------------------------------------
DNS.CLEAR ldx #K.DNSCACHE.SIZE*S.DNSCACHE
.1 stz DNS.CACHE-1,x
dex
bne .1
clc
rts
*--------------------------------------
* DNS.QUERY
* In:
2015-10-19 20:35:00 +00:00
* PULLW = hostname PTR to PSTR
2015-03-14 21:48:35 +00:00
* PULLW = PTR to IP to fill with cached data
* Out:
* CC: hit: IP filled with address
* CS: missed
*--------------------------------------
2015-10-19 20:35:00 +00:00
DNS.QUERY >PULLYA Get host string
jsr PSTR2DNSHostName
2015-03-14 21:48:35 +00:00
>PULLW ZPDNSIP Get IP address to fill
ldx #0
.1 lda DNS.CACHE,x
beq .6 empty DNS cache entry?
2015-10-19 20:35:00 +00:00
phx
2015-03-14 21:48:35 +00:00
lda DNS.CACHE+S.DNSCACHE.hNAME,x
>SYSCALL SYS.GetMemPtrA
>STYA ZPQuickPtr3
2015-10-19 20:35:00 +00:00
plx
ldy #0
.2 lda DNSHostname,y
bne .21
lda (ZPQuickPtr3),y
beq .22
.21 cmp (ZPQuickPtr3),y
2015-03-14 21:48:35 +00:00
bne .6
2015-10-19 20:35:00 +00:00
iny
2015-03-14 21:48:35 +00:00
bne .2
2015-10-19 20:35:00 +00:00
.22 lda DNS.CACHE,x get back status...
2015-03-14 21:48:35 +00:00
bpl .4 Pending...
ldy #0
.3 lda DNS.CACHE+S.DNSCACHE.RDATA,x
2015-03-14 21:48:35 +00:00
sta (ZPDNSIP),y
inx
iny
cpy #4
bne .3
clc
rts
.4 sec
rts
.6 txa
clc
adc #S.DNSCACHE
tax
cmp #K.DNSCACHE.SIZE*S.DNSCACHE
bne .1
DNS.REQUEST jsr NEW.UDP.FRAME
bcc .1
bra *
rts
.1 phx
ldy #S.UDP.SRCPORT
lda /UDP.PORT.DNS
sta (ZPFrameBase1),y
iny
lda #UDP.PORT.DNS
sta (ZPFrameBase1),y
ldy #S.UDP.DSTPORT
lda /UDP.PORT.DNS
sta (ZPFrameBase1),y
iny
lda #UDP.PORT.DNS
sta (ZPFrameBase1),y
2015-09-16 20:48:59 +00:00
ldy #S.DNS.ID
lda A2osX.RANDOM16
sta (ZPFrameBase1),y
2015-10-19 20:35:00 +00:00
sta DNSMessageID
2015-09-16 20:48:59 +00:00
iny
lda A2osX.RANDOM16+1
sta (ZPFrameBase1),y
2015-10-19 20:35:00 +00:00
sta DNSMessageID+1
2015-09-16 20:48:59 +00:00
2015-10-19 20:35:00 +00:00
* ldy #S.DNS.F
* lda /S.DNS.F.RD
* sta (ZPFrameBase1),y
* iny
* lda #S.DNS.F.RD
* sta (ZPFrameBase1),y
2015-03-14 21:48:35 +00:00
ldy #S.DNS.QDCOUNT
lda /1
sta (ZPFrameBase1),y
iny
lda #1
sta (ZPFrameBase1),y
lda #S.DNS
clc
adc ZPFrameBase1
sta ZPFramePtr1
lda /S.DNS
adc ZPFrameBase1+1
sta ZPFramePtr1+1
2015-10-19 20:35:00 +00:00
ldy #0
.2 lda DNSHostname,y
2015-03-14 21:48:35 +00:00
sta (ZPFramePtr1),y
2015-10-19 20:35:00 +00:00
beq .3
2015-03-14 21:48:35 +00:00
iny
2015-10-19 20:35:00 +00:00
bne .2
.3 iny
2015-03-14 21:48:35 +00:00
lda /S.DNS.QTYPE.A
sta (ZPFramePtr1),y
iny
lda #S.DNS.QTYPE.A
sta (ZPFramePtr1),y
iny
lda /S.DNS.QCLASS.IN
sta (ZPFramePtr1),y
iny
lda #S.DNS.QCLASS.IN
sta (ZPFramePtr1),y
2015-10-19 20:35:00 +00:00
lda DNSHostnameLen Get hostname len again (QNAME)
2015-03-14 21:48:35 +00:00
clc
adc #6 (len+1) + Ending 0 + QTYPE + QCLASS
adc #S.DNS
sta ZPFrameLen1
lda #0
adc /S.DNS
sta ZPFrameLen1+1
ldx #S.IPCFG.DNS
ldy #S.IP.DST
lda IPCFG,x
beq .5
.4 lda IPCFG,x
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS+4
bne .4
jsr SEND.UDP.FRAME.I
bcs .8
.5 ldx #S.IPCFG.DNS+4
ldy #S.IP.DST
lda IPCFG,x
beq .7
.6 lda IPCFG,x
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS+8
bne .6
jsr SEND.UDP.FRAME.I
bcs .8
.7 jsr DNS.ADD.PENDING.I
.8 pla
>SYSCALL SYS.FreeMemA
sec
rts
*--------------------------------------
* DNS.ADD
* In:
2015-10-19 20:35:00 +00:00
* PULLW = hostname PSTR to Add
2015-03-14 21:48:35 +00:00
* PULLW = PTR to IP
*--------------------------------------
2015-10-19 20:35:00 +00:00
DNS.ADD >PULLYA Get host string
jsr PSTR2DNSHostName
2015-03-14 21:48:35 +00:00
>PULLW ZPDNSIP Get host IP address
2015-10-19 20:35:00 +00:00
lda #$80
sta DNSHostTTL+3
stz DNSHostTTL+2
stz DNSHostTTL+1
stz DNSHostTTL
2015-03-14 21:48:35 +00:00
lda #S.DNSCACHE.STATUS.RESOLVED
bra DNS.ADD.I
DNS.ADD.PENDING.I
lda #S.DNSCACHE.STATUS.PENDING
DNS.ADD.I sta Status
ldx #0
.1 lda DNS.CACHE,x
beq DNS.ADD.ENTRY free ?
lda DNS.CACHE+S.DNSCACHE.hNAME,x
2015-10-19 20:35:00 +00:00
phx
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.GetMemPtrA
>STYA ZPQuickPtr3
2015-10-19 20:35:00 +00:00
plx
2015-03-14 21:48:35 +00:00
2015-10-19 20:35:00 +00:00
ldy #0
.2 lda DNSHostname,y
2015-03-14 21:48:35 +00:00
cmp (ZPQuickPtr3),y
bne .4
2015-10-19 20:35:00 +00:00
and #$FF End Of String?
beq DNS.UPD.ENTRY
iny
bne .2
2015-03-14 21:48:35 +00:00
.4 txa
clc
adc #S.DNSCACHE
tax
2015-10-19 20:35:00 +00:00
cmp #K.DNSCACHE.SIZE*S.DNSCACHE
bne .1
lda DNS.CACHE+S.DNSCACHE.hNAME discard oldest entry hNAME
2015-03-14 21:48:35 +00:00
>SYSCALL SYS.FreeMemA
ldx #K.DNSCACHE.SIZE*S.DNSCACHE-S.DNSCACHE
2015-10-19 20:35:00 +00:00
2015-03-14 21:48:35 +00:00
.6 lda DNS.CACHE+S.DNSCACHE-1,x
sta DNS.CACHE-1,x
dex
bne .6
ldx #K.DNSCACHE.SIZE*S.DNSCACHE-S.DNSCACHE
DNS.ADD.ENTRY phx
2015-10-19 20:35:00 +00:00
ldy DNSHostnameLen
iny add 1 for Ending 00
2015-03-14 21:48:35 +00:00
lda #0
>PUSHYA push PSTR len
>PUSHBI 0 no option
>SYSCALL SYS.GetMem
bcc .10
plx
rts
2015-10-19 20:35:00 +00:00
.10 >STYA ZPQuickPtr4
2015-03-14 21:48:35 +00:00
txa
plx
sta DNS.CACHE+S.DNSCACHE.hNAME,x
2015-10-19 20:35:00 +00:00
ldy #0
.1 lda DNSHostname,y
sta (ZPQuickPtr4),y
iny
cpy DNSHostnameLen
2015-03-14 21:48:35 +00:00
bne .1
2015-10-19 20:35:00 +00:00
lda #0
sta (ZPQuickPtr4),y
2015-03-14 21:48:35 +00:00
DNS.UPD.ENTRY lda Status
2015-10-19 20:35:00 +00:00
sta DNS.CACHE+S.DNSCACHE.STATUS,x
bmi .1 pending?
lda DNSMessageID
sta DNS.CACHE+S.DNSCACHE.ID,x
lda DNSMessageID+1
sta DNS.CACHE+S.DNSCACHE.ID+1,x
2015-03-14 21:48:35 +00:00
2015-10-19 20:35:00 +00:00
bra .9
.1 lda DNSHostTTL
2015-03-14 21:48:35 +00:00
sta DNS.CACHE+S.DNSCACHE.TTL,x
2015-10-19 20:35:00 +00:00
lda DNSHostTTL+1
2015-03-14 21:48:35 +00:00
sta DNS.CACHE+S.DNSCACHE.TTL+1,x
2015-10-19 20:35:00 +00:00
lda DNSHostTTL+2
sta DNS.CACHE+S.DNSCACHE.TTL+2,x
lda DNSHostTTL+3
sta DNS.CACHE+S.DNSCACHE.TTL+3,x
2015-03-14 21:48:35 +00:00
ldy #0
.2 lda (ZPDNSIP),y
sta DNS.CACHE+S.DNSCACHE.RDATA,x
2015-03-14 21:48:35 +00:00
inx
iny
cpy #4
bne .2
clc
rts
.9 sec
rts
*--------------------------------------
DNS.GETCACHE >LDYA L.DNS.CACHE
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
2015-10-19 20:35:00 +00:00
PSTR2DNSHostName >STYA ZPQuickPtr1
lda (ZPQuickPtr1)
beq .9
cmp #K.DNS.MAXLEN-1
bcs .9
tay
inc
sta DNSHostNameLen
lda #0 Ending 0
sta DNSHostName+1,y
ldx #0
.1 lda (ZPQuickPtr1),y
and #$7f
cmp #'.'
beq .2
cmp #'A'
bcc .10
cmp #'Z'+1
bcs .10
adc #$20
.10 inx
bra .3
.2 txa
ldx #0
.3 sta DNSHostName,y
dey
bne .1
stx DNSHostName
clc
rts
.9 sec
rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
SAVE LIB/LIBTCPIP.S.DNS
LOAD LIB/LIBTCPIP.S
ASM