A2osX/LIB/LIBTCPIP.S.ARP.txt
2016-03-16 17:37:02 +01:00

382 lines
6.6 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.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
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
*--------------------------------------
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
ARP.QUERY.I jsr ARP.FIND.BY.IP
bcs .3 send an ARP request
lda (ZPCachePtr) get status...
bpl .9 Pending...
lda ZPCachePtr
clc
adc S.ARPCACHE.MAC
sta ZPCachePtr
bcc .1
inc ZPCachePtr+1
.1 ldy #5
.2 lda (ZPCachePtr),y
sta (ZPPtrMAC),y
dey
bpl .2
clc
rts
.3 ldy #3
.4 lda (ZPPtrIP),y
sta ARP.REQ.TPA,y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .4
>PUSHW L.ARP.REQ
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
bcs .99
lda #5
sta ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1
lda #S.ARPCACHE.STATUS.PENDING
jsr ARP.ADD.I
.9 lda #ERR.ARPPENDING
sec
.99 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
*--------------------------------------
ARP.RESOLVE ldy #S.IP.DST
lda (ZPFrameBase1),y
iny
.1 and (ZPFrameBase1),y
iny
cpy #S.IP.DST+4
bne .1
cmp #$FF
bne .3 not a broadcast....
ldy #S.ETH.DSTMAC
.2 sta (ZPFrameBase1),y
iny
cpy #S.ETH.DSTMAC+6
bne .2
clc
rts
.3 ldy #S.IP.DST+3
ldx #3
.4 lda (ZPFrameBase1),y
eor IPCFG+S.IPCFG.IP,x
and IPCFG+S.IPCFG.MASK,x
bne .5
dey
dex
bpl .4
lda ZPFrameBase1 Same network, query ARP for dest IP
clc
adc #S.IP.DST
sta ZPPtrIP
lda ZPFrameBase1+1
adc /S.IP.DST
sta ZPPtrIP+1
bra .6
.5 lda L.IPCFG Not Same network, query ARP for GW
clc
adc #S.IPCFG.GW
sta ZPPtrIP
lda L.IPCFG+1
adc /S.IPCFG.GW
sta ZPPtrIP+1
.6 lda ZPFrameBase1
clc
adc #S.ETH.DSTMAC
sta ZPPtrMAC
lda ZPFrameBase1+1
adc /S.ETH.DSTMAC
sta ZPPtrMAC+1
*--------------------------------------
ARP.FIND.BY.IP >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #K.ARPCACHE.SIZE
sta TmpOffset
.1 lda (ZPCachePtr)
beq .7
ldy #S.ARPCACHE.IP+3
ldx #3
lda (ZPCachePtr),y
cmp (ZPPtrIP)
bne .7
ldy #S.ARPCACHE.IP+1
lda (ZPCachePtr),y
ldy #1
cmp (ZPPtrIP),y
bne .7
ldy #S.ARPCACHE.IP+2
lda (ZPCachePtr),y
ldy #2
cmp (ZPPtrIP),y
bne .7
ldy #S.ARPCACHE.IP+3
lda (ZPCachePtr),y
ldy #3
cmp (ZPPtrIP),y
bne .7
clc
rts
.7 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
.8 dec TmpOffset
bne .1
sec
rts
*--------------------------------------
ARP.FIND.FREE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #$ff
sta TmpDWord
sta TmpDWord+1
ldx #K.ARPCACHE.SIZE
.1 lda (ZPCachePtr)
beq .8
bpl .6
ldy #S.ARPCACHE.TTL
lda (ZPCachePtr),y
sec
sbc TmpDWord
iny
lda (ZPCachePtr),y
sbc TmpDWord+1
bcc .6
lda (ZPCachePtr),y
sta TmpDWord+1
dey
lda (ZPCachePtr),y
sta TmpDWord
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
.6 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .7
inc ZPCachePtr+1
.7 dex
bne .1
>LDYA ZPTmpPtr1
>STYA ZPCachePtr
lda #0
sta (ZPCachePtr)
.8 clc
rts
*--------------------------------------
ARP.EXPIRE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
ldx #K.ARPCACHE.SIZE
.1 lda (ZPCachePtr)
beq .3
ldy #S.ARPCACHE.TTL
sec
lda (ZPCachePtr),y
sbc #1
sta (ZPCachePtr),y
iny
lda (ZPCachePtr),y
sbc #0
sta (ZPCachePtr),y
bcs .2
lda #0
sta (ZPCachePtr)
.2 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .3
inc ZPCachePtr+1
.3 dex
bne .1
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.ARP
LOAD LIB/LIBTCPIP.S
ASM