A2osX/LIB/LIBTCPIP.S.FRM.txt

309 lines
5.5 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.SRC
LOMEM $A00
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
2017-02-13 07:26:18 +00:00
* FRM.New
* 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
lda #S.TCP-2
2017-02-13 07:26:18 +00:00
bra .4
.1 cpx #S.IP.PROTOCOL.UDP
bne .2
lda #S.UDP-2
bra .4
.2 lda #S.IP-2
2017-02-13 07:26:18 +00:00
bra .4
.4 sta .5+1 save Header len for reset later
clc
adc ZPDataOutLen
sta ZPFrameOutLen
pha
lda #0
adc ZPDataOutLen+1
sta ZPFrameOutLen+1
tax
pla
adc #2
tay
txa
adc #0
>PUSHYA
>PUSHBI 0
>SYSCALL GetMem
bcs .9
stx hFrameOut
>STYA ZPFrameOutPtr
2017-02-13 07:26:18 +00:00
lda ZPFrameOutLen
sta (ZPFrameOutPtr)
ldy #1
lda ZPFrameOutLen+1
sta (ZPFrameOutPtr),y
iny
.5 ldx #$ff Self Modified, header length
lda #0
.6 sta (ZPFrameOutPtr),y
iny
dex
bne .6
tya
* clc
adc ZPFrameOutPtr
sta ZPDataOutPtr
lda #0
adc ZPFrameOutPtr+1
sta ZPDataOutPtr+1
2016-04-18 20:16:54 +00:00
lda DevFlags
2017-01-26 21:57:35 +00:00
and #S.DEVSTAT.NET.FLAGS.IPOFFLOAD
2017-02-13 07:26:18 +00:00
bne .7
2016-04-18 20:16:54 +00:00
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP
sta (ZPFrameOutPtr),y
iny
lda #S.ETH.ETHERTYPE.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
* 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
inx
stx IP.ID+1
.61 sta IP.ID
sta (ZPFrameOutPtr),y
dey
txa
sta (ZPFrameOutPtr),y
ldy #S.IP.TTL
lda #K.IP.TTL
sta (ZPFrameOutPtr),y
2017-02-13 07:26:18 +00:00
.7 ldy #S.IP.PROTOCOL
.8 lda #$ff
sta (ZPFrameOutPtr),y
.9 rts
*--------------------------------------
FRM.SendIP 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
.1 lda IPCFG+S.IPCFG.IP,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .1
2016-04-18 20:16:54 +00:00
lda DevFlags
2017-01-26 21:57:35 +00:00
and #S.DEVSTAT.NET.FLAGS.IPOFFLOAD
2016-04-18 20:16:54 +00:00
bne .21
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameOutLen
sec
sbc #S.ETH-2
sta (ZPFrameOutPtr),y
dey
lda ZPFrameOutLen+1
sbc /S.ETH-2
sta (ZPFrameOutPtr),y
lda #0
ldy #S.IP.HDR.CHECKSUM
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameOutPtr),y
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
clc
ldy #S.IP.V.IHL.DSCP.ECN
ldx #10 10 words for IP Header
.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
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
jsr TCP.ComputeChecksum
2017-02-13 07:26:18 +00:00
bra .5
.3 cmp #S.IP.PROTOCOL.UDP
bne .4
lda ZPFrameOutLen
sec
sbc #S.IP-2
ldy #S.UDP.LENGTH+1
sta (ZPFrameOutPtr),y
lda ZPFrameOutLen+1
sbc /S.IP-2
dey
sta (ZPFrameOutPtr),y
jsr UDP.ComputeChecksum
2017-02-13 07:26:18 +00:00
bra .5
2017-02-13 07:26:18 +00:00
.4 cmp #S.IP.PROTOCOL.ICMP
bne .5
2017-02-13 07:26:18 +00:00
jsr ICMP.ComputeChecksum
.5 lda DevFlags
and #S.DEVSTAT.NET.FLAGS.ARPOFFLOAD
bne .6
jsr IP.SetDestMAC
bcs FRM.Queue
2017-02-13 07:26:18 +00:00
.6 >LDYA ZPFrameOutPtr
2017-01-26 21:57:35 +00:00
ldx #DEVMGR.WRITEBLOCK
jsr NetDevJmp
bcs FRM.Queue
2017-01-29 21:47:19 +00:00
lda hFrameOut
beq .9
>SYSCALL FreeMemA
clc
.9 rts
*--------------------------------------
2017-01-29 21:47:19 +00:00
FRM.Queue ldy hFrameOut no hFrame, cannot queue for retry
beq .9
ldx FRM.QUEUE.Head
inx
cpx #K.FRMQUEUE.SIZE
bne .1
ldx #0
.1 cpx FRM.QUEUE.Tail
beq .9
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
clc
rts
.9 sec
rts
*--------------------------------------
FRM.Retry ldx FRM.QUEUE.Tail
.10 cpx FRM.QUEUE.Head
beq .8 Queue is empty, exit....
lda FRM.QUEUE.hMem,x
>SYSCALL GetMemPtrA
>STYA ZPFrameOutPtr
ldx FRM.QUEUE.Tail
lda FRM.QUEUE.State,x
cmp #ERR.DEV+1 Device error ?
bcc .1 yes, retry sending...
jsr IP.SetDestMAC Err is ARP or higher, retry getting MAC
bcs .2 still error getting dest MAC
.1 >LDYA ZPFrameOutPtr try sending again to DRV
2017-01-26 21:57:35 +00:00
ldx #DEVMGR.WRITEBLOCK
jsr NetDevJmp
bcc .3
.2 ldx FRM.QUEUE.Tail save error...
sta FRM.QUEUE.State,x
dec FRM.QUEUE.Retry,x
bne .8 exit....until next run!
.3 ldx FRM.QUEUE.Tail Success,or max retry, discard entry
lda FRM.QUEUE.hMem,x
>SYSCALL FreeMemA
.4 ldx FRM.QUEUE.Tail
inx
cpx #K.FRMQUEUE.SIZE
bne .5
ldx #0
.5 stx FRM.QUEUE.Tail
bra .10
2016-03-16 16:37:02 +00:00
.8 rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.FRM
LOAD LIB/LIBTCPIP.S
ASM