A2osX/LIB/LIBTCPIP.S.ARP.txt

373 lines
6.6 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
2015-03-14 21:48:35 +00:00
.LIST OFF
*/--------------------------------------
* # ARP.Clear
* Clear ARP Cache
2018-06-18 08:44:02 +00:00
* **In:**
* **Out:**
*\--------------------------------------
ARP.Clear ldx #K.ARPCACHE.SIZE*S.ARPCACHE
2017-01-29 21:47:19 +00:00
.1 stz ARP.CACHE-1,x
dex
bne .1
clc
rts
*/--------------------------------------
* # ARP.Query
* Query ARP Cache and returns HW address
2018-06-14 15:31:36 +00:00
* **In:**
* PUSHW PTR to MAC (to fill)
* PUSHW PTR to IP
2018-06-14 15:31:36 +00:00
* **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
* Add a static ARP cache record
2018-06-14 15:31:36 +00:00
* **In:**
* PUSHW PTR to MAC
* PUSHW PTR to IP
*\--------------------------------------
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
* Return a Ptr to ARP Cache Table
2018-06-14 15:31:36 +00:00
* **In:**
* **Out:**
* Y,A = PTR to ARP.CACHE
*\--------------------------------------
ARP.GetCAche >LDYA L.ARP.CACHE
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
ARP.AddFromFrameInPtr
ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .1
ldy #S.ETH.SRCMAC+5
ldx #5
.2 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
bpl .2
lda #K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
lda /K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL+1
lda #S.ARPCACHE.STATUS.RESOLVED
jmp ARP.ADD.I
*--------------------------------------
2016-03-16 16:37:02 +00:00
ARP.IN ldy #S.ARP.TPA+3
ldx #3
2018-08-08 15:13:37 +00:00
.1 lda (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
cmp IPCFG+S.IPCFG.IP,x
2017-01-29 21:47:19 +00:00
bne ARP.IN.EXIT
2016-03-16 16:37:02 +00:00
dey
dex
bpl .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
cmp #S.ARP.OPERATION.REP
beq ARP.IN.REP
2017-01-29 21:47:19 +00:00
ARP.IN.EXIT lda hFrameIn
2018-08-08 15:13:37 +00:00
beq .8
stz hFrameIn
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-08-08 15:13:37 +00:00
.8 clc
2016-03-16 16:37:02 +00:00
rts
2017-01-29 21:47:19 +00:00
2016-03-16 16:37:02 +00:00
ARP.IN.REQ ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
sta ARP.REP.TPA,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .2
2018-08-08 15:13:37 +00:00
>PUSHWI S.ARP
>PUSHW L.ARP.REP
lda IPCFG+S.IPCFG.hFD
>SYSCALL write
2018-07-23 15:28:42 +00:00
2017-01-29 21:47:19 +00:00
bra ARP.IN.EXIT
2016-03-16 16:37:02 +00:00
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 (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameInPtr),y
2016-03-16 16:37:02 +00:00
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
bpl .2
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
2017-01-29 21:47:19 +00:00
jmp ARP.IN.EXIT
2016-03-16 16:37:02 +00:00
*--------------------------------------
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
2018-09-03 06:01:07 +00:00
2018-09-04 15:29:15 +00:00
ldy #S.ARPCACHE.TTL
lda #K.ARP.TTL
sta (ZPCachePtr),y
iny
lda /K.ARP.TTL
sta (ZPCachePtr),y
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
2018-08-08 15:13:37 +00:00
>PUSHWI S.ARP
>PUSHW L.ARP.REQ
lda IPCFG+S.IPCFG.hFD
>SYSCALL write
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
2018-09-04 15:29:15 +00:00
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 /A2OSX.SRC/LIB/LIBTCPIP.S.ARP
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
2015-03-14 21:48:35 +00:00
ASM