A2osX/LIB/LIBTCPIP.S.IP.txt

264 lines
4.5 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-05 17:15:37 +00:00
AUTO 3,1
.LIST OFF
*--------------------------------------
2019-07-07 20:48:57 +00:00
IP.IN ldy #S.IP.PROTOCOL
lda (ZPFrameInPtr),y
cmp #S.IP.PROTOCOL.ICMP
bne .2
2019-07-07 20:48:57 +00:00
jmp ICMP.IN
.2 cmp #S.IP.PROTOCOL.UDP
bne .3
2019-06-17 15:40:26 +00:00
2019-07-07 20:48:57 +00:00
jsr FRM.GetTargetSKT.TCPUDP
2019-06-17 15:40:26 +00:00
jsr SKT.FindMatchingLocRem
bcs .9
lda hFrameIn
jsr SKT.AddToQueueA
bcs .9 Q full, discard...
rts
.3 cmp #S.IP.PROTOCOL.TCP
bne .9
2019-07-07 20:48:57 +00:00
jsr TCP.IN TCP may NOT discard FrameIn
2017-01-29 21:47:19 +00:00
.9 lda hFrameIn
2018-09-25 06:25:32 +00:00
beq .8
2019-05-05 17:15:37 +00:00
>SYSCALL2 FreeMem
2018-09-25 06:25:32 +00:00
.8 clc
rts
*--------------------------------------
2018-09-21 15:28:46 +00:00
IP.ComputeICMPChecksum
stz IP.CHECKSUM
stz IP.CHECKSUM+1
lda ZPFrameOutLen
sec
2018-09-25 06:25:32 +00:00
sbc #S.IP
2018-09-21 15:28:46 +00:00
eor #$ff
tax
lda ZPFrameOutLen+1
2018-09-25 06:25:32 +00:00
sbc /S.IP
2018-09-21 15:28:46 +00:00
eor #$ff
ldy #S.ICMP.CHECKSUM
2018-09-25 06:25:32 +00:00
clc
2018-09-21 15:28:46 +00:00
jmp IP.ComputeChecksum
*--------------------------------------
2018-09-25 06:25:32 +00:00
IP.ComputeUDPChecksum
clc
2018-09-25 06:25:32 +00:00
ldy #S.UDP.LENGTH+1
2018-09-21 15:28:46 +00:00
lda (ZPFrameOutPtr),y
2018-09-25 06:25:32 +00:00
2018-09-21 15:28:46 +00:00
adc #S.IP.PROTOCOL.UDP
sta IP.CHECKSUM+1
2018-09-25 06:25:32 +00:00
dey
lda (ZPFrameOutPtr),y
adc /S.IP.PROTOCOL.UDP (all zero)
sta IP.CHECKSUM
2018-09-21 15:28:46 +00:00
jsr IP.AddSrcDstIPToChecksum
2018-09-25 06:25:32 +00:00
ldy #S.UDP.LENGTH+1
lda (ZPFrameOutPtr),y
2018-09-21 15:28:46 +00:00
eor #$ff
tax
2018-09-25 06:25:32 +00:00
dey
lda (ZPFrameOutPtr),y
2018-09-21 15:28:46 +00:00
eor #$ff
ldy #S.UDP.CHECKSUM
bra IP.ComputeChecksum
*--------------------------------------
IP.ComputeTCPChecksum
lda ZPFrameOutLen
sec
sbc #S.IP
2019-06-10 08:19:13 +00:00
sta IP.CHECKSUM.TMP
2018-09-21 15:28:46 +00:00
lda ZPFrameOutLen+1
sbc /S.IP
2019-06-10 08:19:13 +00:00
sta IP.CHECKSUM.TMP+1
2018-09-21 15:28:46 +00:00
clc
2018-09-21 15:28:46 +00:00
2019-06-10 08:19:13 +00:00
* lda IP.CHECKSUM.TMP+1
2018-09-21 15:28:46 +00:00
* adc /S.IP.PROTOCOL.TCP (all zero)
sta IP.CHECKSUM
2019-06-10 08:19:13 +00:00
lda IP.CHECKSUM.TMP
2018-09-21 15:28:46 +00:00
adc #S.IP.PROTOCOL.TCP
sta IP.CHECKSUM+1
2018-09-21 15:28:46 +00:00
jsr IP.AddSrcDstIPToChecksum
2019-06-10 08:19:13 +00:00
lda IP.CHECKSUM.TMP
2018-09-21 15:28:46 +00:00
eor #$ff
tax
2019-06-10 08:19:13 +00:00
lda IP.CHECKSUM.TMP+1
2018-09-21 15:28:46 +00:00
eor #$ff
2018-09-21 15:28:46 +00:00
ldy #S.TCP.CHECKSUM
*--------------------------------------
* X,A = !ByteCount, Y = Offset in Frame
*--------------------------------------
IP.ComputeChecksum
phy Save Offset
pha Save !ByteCount.HI
lda #0 Reset Checksum
sta (ZPFrameOutPtr),y
iny
2018-09-21 15:28:46 +00:00
sta (ZPFrameOutPtr),y
>LDYA ZPFrameOutPtr
>STYA ZPTmpPtr1
ldy #S.IP
.1 inx
bne .11
pla
inc
beq .8
pha
.11 lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
2018-09-21 15:28:46 +00:00
iny
bne .20
inc ZPTmpPtr1+1
2018-09-21 15:28:46 +00:00
.20 inx
bne .2
pla
inc
beq .7
pha
.2 lda (ZPTmpPtr1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
2018-09-21 15:28:46 +00:00
iny
bne .1
2018-09-21 15:28:46 +00:00
inc ZPTmpPtr1+1
bra .1
2018-09-21 15:28:46 +00:00
.7 adc IP.CHECKSUM+1 A=0 from beq .7
sta IP.CHECKSUM+1
.8 ply
lda IP.CHECKSUM
2018-09-21 15:28:46 +00:00
adc #0 Don't forget to add last carry!!!
eor #$FF
2018-09-21 15:28:46 +00:00
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
2018-09-21 15:28:46 +00:00
adc #0 Don't forget to add last carry!!!
eor #$FF
2018-09-21 15:28:46 +00:00
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
IP.AddSrcDstIPToChecksum
ldy #S.IP.SRC
ldx #4 4 words for SRC & DST IP
.1 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .1
2018-09-25 06:25:32 +00:00
rts
*--------------------------------------
IP.SetDestMAC ldy #S.IP.DST
lda (ZPFrameOutPtr),y
iny
.1 and (ZPFrameOutPtr),y
iny
cpy #S.IP.DST+4
bne .1
cmp #$FF
bne .3 not a broadcast....
ldy #S.ETH.DSTMAC
.2 sta (ZPFrameOutPtr),y
iny
cpy #S.ETH.DSTMAC+6
bne .2
clc
rts
.3 ldy #S.IP.DST+3
ldx #3
.4 lda (ZPFrameOutPtr),y
eor IPCFG+S.IPCFG.IP,x
and IPCFG+S.IPCFG.MASK,x
bne .6
dey
dex
bpl .4
ldy #S.IP.DST+3 Same network, query ARP for dest IP
ldx #3
.5 lda (ZPFrameOutPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .5
bra .8
.6 ldx #3 Not Same network, query ARP for GW
.7 lda IPCFG+S.IPCFG.GW,x
sta ARP.TmpCache+S.ARPCACHE.IP,x
dex
bpl .7
.8 jsr ARP.QUERY.I
bcs .99
ldx #5
ldy #S.ETH.DSTMAC+5
2018-09-21 15:28:46 +00:00
.11 lda ARP.TmpCache+S.ARPCACHE.MAC,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .11
2018-09-21 15:28:46 +00:00
clc
.99 rts
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/LIB/LIBTCPIP.S.IP
LOAD USR/SRC/LIB/LIBTCPIP.S
ASM