A2osX/LIB/LIBTCPIP.S.FRM.txt

352 lines
6.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
*--------------------------------------
2018-10-08 15:41:00 +00:00
FRM.GetTargetSKT.TCPUDP
2018-10-01 05:48:42 +00:00
ldy #S.TCPUDP.SRCPORT
lda (ZPFrameInPtr),y
sta SKT.REM.ADDR+S.SOCKADDR.PORT+1
iny
lda (ZPFrameInPtr),y
sta SKT.REM.ADDR+S.SOCKADDR.PORT
iny #S.TCPUDP.DSTPORT
lda (ZPFrameInPtr),y
sta SKT.LOC.ADDR+S.SOCKADDR.PORT+1
iny
lda (ZPFrameInPtr),y
sta SKT.LOC.ADDR+S.SOCKADDR.PORT
2018-10-08 15:41:00 +00:00
FRM.GetTargetSKT.RAW
2018-10-01 05:48:42 +00:00
ldy #S.IP.SRC+3
ldx #3
2019-12-07 17:53:45 +00:00
2018-10-01 05:48:42 +00:00
.1 lda (ZPFrameInPtr),y
sta SKT.REM.ADDR+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
2019-12-07 17:53:45 +00:00
2018-10-01 05:48:42 +00:00
ldy #S.IP.DST+3
ldx #3
2019-12-07 17:53:45 +00:00
2018-10-01 05:48:42 +00:00
.2 lda (ZPFrameInPtr),y
sta SKT.LOC.ADDR+S.SOCKADDR.ADDR,x
dey
dex
bpl .2
2019-12-07 17:53:45 +00:00
2019-10-03 06:25:27 +00:00
rts
2018-10-01 05:48:42 +00:00
*--------------------------------------
2018-09-21 15:28:46 +00:00
* FRM.NewIP
2017-02-13 07:26:18 +00:00
* In:
* Y,A = DataLen
* X = S.IP.PROTOCOL.xxx
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
2017-02-13 07:26:18 +00:00
FRM.NewIP stx .8+1
>STYA ZPDataOutLen
cpx #S.IP.PROTOCOL.TCP
2017-02-13 07:26:18 +00:00
bne .1
2019-10-23 15:12:58 +00:00
2018-07-23 06:28:47 +00:00
lda #S.TCP
2017-02-13 07:26:18 +00:00
bra .4
2019-10-23 15:12:58 +00:00
2017-02-13 07:26:18 +00:00
.1 cpx #S.IP.PROTOCOL.UDP
bne .2
2019-10-23 15:12:58 +00:00
2018-07-23 06:28:47 +00:00
lda #S.UDP
2017-02-13 07:26:18 +00:00
bra .4
2019-10-23 15:12:58 +00:00
2018-07-23 06:28:47 +00:00
.2 lda #S.IP
2019-10-23 15:12:58 +00:00
2018-07-24 06:24:23 +00:00
.4 sta .5+1 save Header len for reset later
2017-02-13 07:26:18 +00:00
clc
adc ZPDataOutLen
sta ZPFrameOutLen
2018-07-23 06:28:47 +00:00
tay
2017-02-13 07:26:18 +00:00
lda #0
adc ZPDataOutLen+1
sta ZPFrameOutLen+1
2019-05-05 17:15:37 +00:00
>SYSCALL2 getmem
bcs .9
2019-10-23 15:12:58 +00:00
stx hFrameOut
>STYA ZPFrameOutPtr
2018-07-23 06:28:47 +00:00
ldy #0
2017-02-13 07:26:18 +00:00
.5 ldx #$ff Self Modified, header length
lda #0
.6 sta (ZPFrameOutPtr),y
iny
dex
bne .6
2019-10-23 15:12:58 +00:00
2017-02-13 07:26:18 +00:00
tya
* clc
adc ZPFrameOutPtr
sta ZPDataOutPtr
lda #0
adc ZPFrameOutPtr+1
sta ZPDataOutPtr+1
2019-01-17 15:05:48 +00:00
lda IPCFG+S.NETCFG.DevFlags
2018-07-23 06:28:47 +00:00
and #S.DCB.NIC.FLAGS.IPOFFLOAD
2017-02-13 07:26:18 +00:00
bne .7
2019-10-23 15:12:58 +00:00
2018-11-06 16:31:13 +00:00
ldy #S.ETH.EII.TYPE
lda /S.ETH.EII.TYPE.IP
2021-05-19 12:44:47 +00:00
sta (ZPFrameOutPtr),y
iny
2018-11-06 16:31:13 +00:00
lda #S.ETH.EII.TYPE.IP
sta (ZPFrameOutPtr),y
ldy #S.IP.V.IHL.DSCP.ECN
lda #$45
sta (ZPFrameOutPtr),y
* iny
* lda #$0
* sta (ZPFrameOutPtr),y
2017-02-13 07:26:18 +00:00
2021-05-19 12:44:47 +00:00
* ldy #S.IP.FRAGMENT.FLAGS
* sta (ZPFrameOutPtr),y
* iny
* sta (ZPFrameOutPtr),y
2017-02-13 07:26:18 +00:00
ldy #S.IP.IDENTIFICATION+1
lda IP.ID
ldx IP.ID+1
inc
bne .61
2019-10-23 15:12:58 +00:00
2017-02-13 07:26:18 +00:00
inx
2019-10-23 15:12:58 +00:00
2017-02-13 07:26:18 +00:00
stx IP.ID+1
2019-10-23 15:12:58 +00:00
2017-02-13 07:26:18 +00:00
.61 sta IP.ID
sta (ZPFrameOutPtr),y
dey
txa
sta (ZPFrameOutPtr),y
ldy #S.IP.TTL
lda #K.IP.TTL
sta (ZPFrameOutPtr),y
2021-05-19 12:44:47 +00:00
2017-02-13 07:26:18 +00:00
.7 ldy #S.IP.PROTOCOL
.8 lda #$ff
sta (ZPFrameOutPtr),y
.9 rts
*--------------------------------------
2019-07-07 20:48:57 +00:00
* clc Queue if fail
* sec DONT Queue if fail
*--------------------------------------
FRM.SendIP php
ldx #3 Copy SRC.IP even if IP offload
2016-04-18 20:16:54 +00:00
ldy #S.IP.SRC+3 for proper UDP/TCP CRC calculation
2019-10-05 17:24:41 +00:00
.1 lda IPCFG+S.IPCFG.IP,x
2021-05-19 12:44:47 +00:00
sta (ZPFrameOutPtr),y
dey
dex
bpl .1
2019-10-05 17:24:41 +00:00
2019-01-17 15:05:48 +00:00
lda IPCFG+S.NETCFG.DevFlags
2018-07-23 06:28:47 +00:00
and #S.DCB.NIC.FLAGS.IPOFFLOAD
2016-04-18 20:16:54 +00:00
bne .21
2019-10-05 17:24:41 +00:00
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameOutLen
sec
2018-11-06 16:31:13 +00:00
sbc #S.ETH.EII
sta (ZPFrameOutPtr),y
dey
lda ZPFrameOutLen+1
2018-11-06 16:31:13 +00:00
sbc /S.ETH.EII
sta (ZPFrameOutPtr),y
lda #0
ldy #S.IP.HDR.CHECKSUM
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameOutPtr),y
2018-09-25 06:25:32 +00:00
stz IP.CHECKSUM RESET IP CHECKSUM
stz IP.CHECKSUM+1
clc
ldy #S.IP.V.IHL.DSCP.ECN
2019-10-05 17:24:41 +00:00
ldx #10 10 words for IP Header
2019-10-05 17:24:41 +00:00
.2 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .2
2019-10-05 17:24:41 +00:00
ldy #S.IP.HDR.CHECKSUM
lda IP.CHECKSUM
adc #0
eor #$FF
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
adc #0
eor #$FF
sta (ZPFrameOutPtr),y
2016-04-18 20:16:54 +00:00
.21 ldy #S.IP.PROTOCOL
lda (ZPFrameOutPtr),y
cmp #S.IP.PROTOCOL.TCP
bne .3
2019-10-05 17:24:41 +00:00
2018-09-21 15:28:46 +00:00
jsr IP.ComputeTCPChecksum
2017-02-13 07:26:18 +00:00
bra .5
2019-10-05 17:24:41 +00:00
.3 cmp #S.IP.PROTOCOL.UDP
bne .4
2019-10-05 17:24:41 +00:00
lda ZPFrameOutLen
sec
2018-07-23 06:28:47 +00:00
sbc #S.IP
ldy #S.UDP.LENGTH+1
sta (ZPFrameOutPtr),y
lda ZPFrameOutLen+1
2018-07-23 06:28:47 +00:00
sbc /S.IP
dey
2019-07-07 20:48:57 +00:00
sta (ZPFrameOutPtr),y
2018-09-21 15:28:46 +00:00
jsr IP.ComputeUDPChecksum
2017-02-13 07:26:18 +00:00
bra .5
2019-10-05 17:24:41 +00:00
2017-02-13 07:26:18 +00:00
.4 cmp #S.IP.PROTOCOL.ICMP
bne .5
2019-10-05 17:24:41 +00:00
2018-09-21 15:28:46 +00:00
jsr IP.ComputeICMPChecksum
2019-10-05 17:24:41 +00:00
2019-01-17 15:05:48 +00:00
.5 lda IPCFG+S.NETCFG.DevFlags
2018-07-23 06:28:47 +00:00
and #S.DCB.NIC.FLAGS.ARPOFFLOAD
2017-02-13 07:26:18 +00:00
bne .6
jsr IP.SetDestMAC
bcs FRM.Queue
2021-05-19 12:44:47 +00:00
2018-08-08 15:13:37 +00:00
.6 jsr FRM.Send
bcs FRM.Queue
2019-10-05 17:24:41 +00:00
2019-06-17 06:35:54 +00:00
jsr FRM.Discard
2019-07-07 20:48:57 +00:00
plp
2019-06-17 06:35:54 +00:00
clc
rts
*--------------------------------------
2019-07-07 20:48:57 +00:00
FRM.Queue plp
2019-10-05 17:24:41 +00:00
bcs FRM.Discard DONT queue
2019-07-07 20:48:57 +00:00
ldy hFrameOut no hFrame, cannot queue for retry
beq FRM.Discard.9
ldx FRM.QUEUE.Head
inx
cpx #K.FRMQUEUE.SIZE
bne .1
2021-05-19 12:44:47 +00:00
ldx #0
2019-10-05 17:24:41 +00:00
.1 cpx FRM.QUEUE.Tail
2019-07-07 20:48:57 +00:00
beq FRM.Discard CS
ldy FRM.QUEUE.Head
stx FRM.QUEUE.Head
sta FRM.QUEUE.State,y
lda #K.FRMSEND.RETRY
sta FRM.QUEUE.Retry,y
2017-01-29 21:47:19 +00:00
lda hFrameOut
sta FRM.QUEUE.hMem,y
2018-07-23 15:28:42 +00:00
lda ZPFrameOutLen
2018-09-03 06:01:07 +00:00
sta FRM.QUEUE.LenL,y
2018-07-23 15:28:42 +00:00
lda ZPFrameOutLen+1
2018-09-03 06:01:07 +00:00
sta FRM.QUEUE.LenH,y
2019-07-07 20:48:57 +00:00
clc
.9 rts
*--------------------------------------
2019-06-17 06:35:54 +00:00
FRM.Discard lda hFrameOut
2019-07-07 20:48:57 +00:00
beq FRM.Discard.9
2019-10-05 17:24:41 +00:00
2019-06-17 06:35:54 +00:00
stz hFrameOut
2019-11-17 14:39:55 +00:00
>SYSCALL2 FreeMem
2019-10-05 17:24:41 +00:00
2019-07-07 20:48:57 +00:00
FRM.Discard.9 sec
2019-06-17 06:35:54 +00:00
rts
*--------------------------------------
FRM.Retry ldx FRM.QUEUE.Tail
2019-07-07 20:48:57 +00:00
.1 cpx FRM.QUEUE.Head
2018-07-24 06:24:23 +00:00
beq .8 Queue is empty, exit...
2019-07-07 20:48:57 +00:00
lda FRM.QUEUE.LenL,x
sta ZPFrameOutLen
lda FRM.QUEUE.LenH,x
sta ZPFrameOutLen+1
lda FRM.QUEUE.hMem,x
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
>STYA ZPFrameOutPtr
ldx FRM.QUEUE.Tail
lda FRM.QUEUE.State,x
2018-09-03 06:01:07 +00:00
cmp #ERR.ARP.PENDING
2019-07-07 20:48:57 +00:00
bne .2
2018-09-03 06:01:07 +00:00
jsr IP.SetDestMAC Err is ARP or higher, retry getting MAC
2019-07-07 20:48:57 +00:00
bcs .3 still error getting dest MAC
.2 jsr FRM.Send try sending again to DRV
bcc .4
.3 ldx FRM.QUEUE.Tail
sta FRM.QUEUE.State,x save error...
2021-05-19 12:44:47 +00:00
dec FRM.QUEUE.Retry,x
bne .8 exit....until next run!
2021-05-19 12:44:47 +00:00
2019-07-07 20:48:57 +00:00
.4 ldx FRM.QUEUE.Tail
lda FRM.QUEUE.hMem,x Success,or max retry, discard entry
inx
cpx #K.FRMQUEUE.SIZE
bne .5
2019-11-17 14:39:55 +00:00
ldx #0
.5 stx FRM.QUEUE.Tail
2019-07-07 20:48:57 +00:00
>SYSCALL2 FreeMem
bra FRM.Retry
.8 rts
*--------------------------------------
2019-01-16 14:37:21 +00:00
FRM.Send ldx #3
2019-10-05 17:24:41 +00:00
2019-01-16 14:37:21 +00:00
.1 lda ZPFrameOutPtr,x Get Frame Ptr & Len
sta IOCTL+S.IOCTL.BUFPTR,x
dex
bpl .1
2021-05-19 12:44:47 +00:00
2020-03-23 07:08:27 +00:00
FRM.Send.IOCTL >PUSHB IPCFG+S.NETCFG.DevID
2019-01-16 14:37:21 +00:00
>PUSHBI IOCTL.WRITE
2020-03-23 07:08:27 +00:00
>PUSHW L.IOCTL
2019-05-05 17:15:37 +00:00
>SYSCALL2 IOCTL
rts
*--------------------------------------
2019-11-17 14:39:55 +00:00
FRM.DiscardIn lda hFrameIn
beq .8
stz hFrameIn
>SYSCALL2 FreeMem
.8 clc
rts
*--------------------------------------
MAN
2020-06-07 08:06:51 +00:00
SAVE usr/src/lib/libtcpip.s.frm
LOAD usr/src/lib/libtcpip.s
ASM