A2osX/LIB/LIBTCPIP.S.ARP.txt
2016-03-16 08:19:54 +01:00

350 lines
6.3 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.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 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
.9 lda #ERR.ARPPENDING
sec
rts
*--------------------------------------
ARP.REQUEST ldy #3
.1 lda (ZPPtrIP),y
sta ARP.REQ.TPA,y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .1
>PUSHW L.ARP.REQ
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
bcs .9
lda #S.ARPCACHE.STATUS.PENDING
jsr ARP.ADD.I ZPPtrIP still pointing IP
lda #ERR.ARPPENDING
sec
.9 rts
*--------------------------------------
* ARP.ADD
* In:
* PULLW PTR to IP
* PULLW PTR to MAC
*--------------------------------------
ARP.ADD >PULLW ZPPtrIP IP
>PULLW ZPPtrMAC MAC
lda #S.ARPCACHE.STATUS.RESOLVED+S.ARPCACHE.STATUS.STATIC
ARP.ADD.I sta ARP.TmpCache
jsr ARP.FIND.BY.IP
bcc .5
jsr DNS.FIND.FREE
.1 lda ARP.CACHE,x get status
beq .7 empty ARP cache entry
phx
ldy #0
.2 lda (ZPPtrIP),y
cmp ARP.CACHE+S.ARPCACHE.IP,x
bne .4
inx
iny
cpy #4
bne .2
plx
bra .7 same IP,update MAC
.4 pla get back index in ARP.CACHE
clc
adc #S.ARPCACHE
cmp #K.ARPCACHE.SIZE*S.ARPCACHE
beq .5 Cache is full ?
tax
bra .1
.5 bra *
ldx #K.ARPCACHE.SIZE*S.ARPCACHE-S.ARPCACHE
.6 lda ARP.CACHE+S.ARPCACHE-1,x
sta ARP.CACHE-1,x
dex
bne .6
ldx #K.ARPCACHE.SIZE*S.ARPCACHE-S.ARPCACHE
.7 lda Status
sta ARP.CACHE,x mark ARP entry Status
lda #K.ARP.TTL
sta ARP.CACHE+S.ARPCACHE.TTL,x
lda /K.ARP.TTL
sta ARP.CACHE+S.ARPCACHE.TTL+1,x
ldy #0
phx
.8 lda (ZPPtrIP),y store IP in cache
sta ARP.CACHE+S.ARPCACHE.IP,x
iny
inx
cpy #4
bne .8
plx
lda Status
bpl .82 no MAC if "pending"
ldy #0
.81 lda (ZPPtrMAC),y store MAC in cache
sta ARP.CACHE+S.ARPCACHE.MAC,x
iny
inx
cpy #6
bne .81
.82 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.IN ldy #S.ARP.TPA
ldx #S.IPCFG.IP
.1 lda (ZPFrameBase1),y
cmp IPCFG,x
bne .9
iny
inx
cpx #S.IPCFG.IP+4
bne .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.ETH.SRCMAC+5
ldx #5
.1 lda (ZPFrameBase1),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .1
ldy #S.ARP.SPA+3
ldx #3
.2 lda (ZPFrameBase1),y
sta ARP.REP.TPA,x
dey
dex
bpl .2
>PUSHW L.ARP.REP
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
ARP.IN.REP lda #S.ARP.SHA
clc
adc ZPFrameBase1
sta ZPPtrMAC
lda ZPFrameBase1+1
adc /S.ARP.SHA
sta ZPPtrMAC+1
lda #S.ARP.SPA
clc
adc ZPFrameBase1
sta ZPPtrIP
lda ZPFrameBase1+1
adc /S.ARP.SPA
sta ZPPtrIP+1
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
clc
rts
*--------------------------------------
ARP.EXPIRE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
ldx #K.ARPCACHE.SIZE
.1 lda (ZPCachePtr)
beq .7
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
*--------------------------------------
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
lda (ZPCachePtr),y
.7 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
.8 dec TmpOffset
bne .1
sec
rts
*--------------------------------------
ARP.FIND.FREE
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.ARP
LOAD LIB/LIBTCPIP.S
ASM