A2osX/LIB/LIBTCPIP.S.ARP.txt

325 lines
5.6 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
*--------------------------------------
ARP.CLEAR ldx #K.ARPCACHE.SIZE*S.ARPCACHE
.1 dex
stz ARP.CACHE,x
txa
bne .1
clc
rts
*--------------------------------------
* ARP.QUERY
* In:
* PULLW PTR to IP
* PULLW PTR to MAC (to fill)
* Out:
* CC: hit: MAC filled
* CS: missed
*--------------------------------------
ARP.QUERY >PULLW ZPPtrIP IP
>PULLW ZPPtrMAC MAC
ldy #3
.1 lda (ZPPtrIP),y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .1
jsr ARP.QUERY.I
bcs .9
ldy #5
.2 lda ARP.TmpCache+S.ARPCACHE.MAC,y
sta (ZPPtrMAC),y
dey
bpl .2
clc
.9 rts
*--------------------------------------
* ARP.ADD
* In:
* PULLW PTR to IP
* PULLW PTR to MAC
*--------------------------------------
ARP.ADD >PULLW ZPPtrIP IP
>PULLW ZPPtrMAC MAC
stz ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1
ldy #3
.1 lda (ZPPtrIP),y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .1
ldy #5
.2 lda (ZPPtrMAC),y
sta ARP.TmpCache+S.ARPCACHE.MAC,y
dey
bpl .2
lda #S.ARPCACHE.STATUS.RESOLVED+S.ARPCACHE.STATUS.STATIC
ARP.ADD.I sta ARP.TmpCache
jsr ARP.FIND.BY.IP
bcc .1
jsr ARP.FIND.FREE
.1 ldy #S.ARPCACHE-1
.2 lda ARP.TmpCache,y
sta (ZPCachePtr),y
dey
bpl .2
clc
rts
*--------------------------------------
* ARP.GETCACHE
* Out:
* Y,A = PTR to ARP.CACHE
*--------------------------------------
ARP.GETCACHE >LDYA L.ARP.CACHE
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
2016-03-16 16:37:02 +00:00
ARP.IN ldy #S.ARP.TPA+3
ldx #3
.1 lda (ZPFrameBase1),y
cmp IPCFG+S.IPCFG.IP,x
bne .9
dey
dex
bpl .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameBase1),y
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
cmp #S.ARP.OPERATION.REP
beq ARP.IN.REP
.9 clc Discard any other ARP frames
rts
ARP.IN.REQ ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase1),y
sta ARP.REP.TPA,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase1),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .2
>PUSHW L.ARP.REP
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
ARP.IN.REP lda #K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
lda /K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL+1
ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase1),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase1),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
bpl .2
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
clc
rts
*--------------------------------------
2016-03-16 07:19:54 +00:00
ARP.QUERY.I jsr ARP.FIND.BY.IP
2016-03-16 16:37:02 +00:00
bcs .3 send an ARP request
2016-03-16 07:19:54 +00:00
lda (ZPCachePtr) get status...
bpl .9 Pending...
ldy #S.ARPCACHE.MAC
2016-03-16 07:19:54 +00:00
.2 lda (ZPCachePtr),y
sta ARP.TmpCache,y
iny
cpy #S.ARPCACHE.MAC+6
bne .2
2016-03-16 07:19:54 +00:00
clc
rts
.3 ldx #3
2016-03-16 16:37:02 +00:00
.4 lda ARP.TmpCache+S.ARPCACHE.IP,x
sta ARP.REQ.TPA,x
dex
2016-03-16 16:37:02 +00:00
bpl .4
2016-03-16 07:19:54 +00:00
>PUSHW L.ARP.REQ
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
2016-03-16 16:37:02 +00:00
bcs .99
lda #K.ARP.PENDING.TTL
2016-03-16 16:37:02 +00:00
sta ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1
2016-03-16 07:19:54 +00:00
lda #S.ARPCACHE.STATUS.PENDING
2016-03-16 16:37:02 +00:00
jsr ARP.ADD.I
2016-03-16 07:19:54 +00:00
.9 lda #ERR.ARP.PENDING
2016-03-16 07:19:54 +00:00
sec
2016-03-16 16:37:02 +00:00
.99 rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-03-16 16:37:02 +00:00
ARP.FIND.BY.IP >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #K.ARPCACHE.SIZE
sta TmpOffset
2015-03-14 21:48:35 +00:00
2016-03-16 16:37:02 +00:00
.1 lda (ZPCachePtr)
beq .3
2016-03-16 16:37:02 +00:00
ldx #3
2016-03-16 16:37:02 +00:00
ldy #S.ARPCACHE.IP+3
.2 lda ARP.TmpCache+S.ARPCACHE.IP,x
cmp (ZPCachePtr),y
bne .3
dey
dex
bpl .2
2016-03-16 16:37:02 +00:00
clc
rts
2015-03-14 21:48:35 +00:00
.3 lda ZPCachePtr
2016-03-16 16:37:02 +00:00
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
2016-03-16 07:19:54 +00:00
.8 dec TmpOffset
2016-03-16 16:37:02 +00:00
bne .1
sec
2015-03-14 21:48:35 +00:00
rts
2016-03-16 16:37:02 +00:00
*--------------------------------------
ARP.FIND.FREE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
2016-03-16 07:19:54 +00:00
2016-03-16 16:37:02 +00:00
lda #$ff
sta TmpDWord
sta TmpDWord+1
ldx #K.ARPCACHE.SIZE
2015-03-14 21:48:35 +00:00
2016-03-16 16:37:02 +00:00
.1 lda (ZPCachePtr)
beq .8
bpl .6
2015-03-14 21:48:35 +00:00
2016-03-16 16:37:02 +00:00
ldy #S.ARPCACHE.TTL
lda (ZPCachePtr),y
sec
sbc TmpDWord
iny
lda (ZPCachePtr),y
sbc TmpDWord+1
bcc .6
2016-03-16 07:19:54 +00:00
2016-03-16 16:37:02 +00:00
lda (ZPCachePtr),y
sta TmpDWord+1
2016-03-16 07:19:54 +00:00
dey
2016-03-16 16:37:02 +00:00
lda (ZPCachePtr),y
sta TmpDWord
2016-03-16 07:19:54 +00:00
2016-03-16 16:37:02 +00:00
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
2015-09-11 18:48:12 +00:00
2016-03-16 16:37:02 +00:00
.6 lda ZPCachePtr
2016-03-16 07:19:54 +00:00
clc
2016-03-16 16:37:02 +00:00
adc #S.ARPCACHE
sta ZPCachePtr
bcc .7
inc ZPCachePtr+1
2015-03-14 21:48:35 +00:00
2016-03-16 16:37:02 +00:00
.7 dex
bne .1
2015-03-14 21:48:35 +00:00
2016-03-16 16:37:02 +00:00
>LDYA ZPTmpPtr1
>STYA ZPCachePtr
lda #0
sta (ZPCachePtr)
.8 clc
2016-03-16 07:19:54 +00:00
rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2016-03-16 07:19:54 +00:00
ARP.EXPIRE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
2015-03-14 21:48:35 +00:00
2016-03-16 07:19:54 +00:00
ldx #K.ARPCACHE.SIZE
2015-03-14 21:48:35 +00:00
2016-03-16 07:19:54 +00:00
.1 lda (ZPCachePtr)
2016-03-29 06:28:28 +00:00
beq .2
2016-03-16 07:19:54 +00:00
ldy #S.ARPCACHE.TTL
sec
lda (ZPCachePtr),y
sbc #1
sta (ZPCachePtr),y
2015-03-14 21:48:35 +00:00
iny
2016-03-16 07:19:54 +00:00
lda (ZPCachePtr),y
sbc #0
sta (ZPCachePtr),y
bcs .2
2015-03-14 21:48:35 +00:00
2016-03-16 07:19:54 +00:00
lda #0
sta (ZPCachePtr)
.2 lda ZPCachePtr
2015-03-14 21:48:35 +00:00
clc
adc #S.ARPCACHE
2016-03-16 07:19:54 +00:00
sta ZPCachePtr
bcc .3
inc ZPCachePtr+1
2015-03-14 21:48:35 +00:00
2016-03-16 07:19:54 +00:00
.3 dex
bne .1
rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
SAVE LIB/LIBTCPIP.S.ARP
LOAD LIB/LIBTCPIP.S
ASM