A2osX/LIB/LIBTCPIP.S.TCP.txt

453 lines
9.5 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
.LIST OFF
*--------------------------------------
2018-10-08 15:41:00 +00:00
TCP.IN jsr FRM.GetTargetSKT.TCPUDP
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
jsr SKT.FindMatchingLocRem
bcs TCP.IN.JMP.CLOSED no socket, go discard
2018-10-01 05:48:42 +00:00
>STYA ZPPtrSKT
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.PROTO
lda (ZPPtrSKT),y
2018-10-08 15:41:00 +00:00
cmp #S.IP.PROTOCOL.TCP
2018-10-01 05:48:42 +00:00
bne TCP.IN.JMP.CLOSED wrong protocol, go discard
ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
2018-10-01 05:48:42 +00:00
and #S.TCP.OPTIONS.RST RST ? go Kill this socket...
bne TCP.IN.RST ...and discard frame
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.S
lda (ZPPtrSKT),y
asl
tax
2018-09-27 15:34:38 +00:00
jmp (J.TCP.IN,x)
*--------------------------------------
2018-10-01 05:48:42 +00:00
TCP.IN.RST jsr SKT.Destroy
*--------------------------------------
TCP.IN.JMP.CLOSED
2018-10-11 06:09:35 +00:00
* lda hFrameIn
* >SYSCALL FreeMem
2018-10-01 05:48:42 +00:00
rts
*--------------------------------------
TCP.IN.JMP.LISTEN
2018-10-01 15:52:58 +00:00
ldy #S.SOCKET.T Create a new client socket
lda (ZPPtrSKT),y
tax Same type a listening socket
2018-11-01 08:53:47 +00:00
iny #S.SOCKET.PROTO
lda (ZPPtrSKT),y
2018-10-01 15:52:58 +00:00
jsr SKT.Socket.I get new socket in ZPTmpPtr1
bcs TCP.IN.JMP.CLOSED
2018-10-01 15:52:58 +00:00
jsr SKT.AddToQueueA Queued successfully ?
2016-04-09 09:15:11 +00:00
2018-10-01 15:52:58 +00:00
bcs TCP.IN.JMP.CLOSED no, discard frame and new socket
2018-10-01 05:48:42 +00:00
jsr ARP.AddFromFrameInPtr
2018-10-01 15:52:58 +00:00
lda ZPTmpPtr1
sta ZPPtrSKT
2018-11-01 08:53:47 +00:00
lda ZPTmpPtr1+1
sta ZPPtrSKT+1
2018-11-01 08:53:47 +00:00
jsr SKT.SetLocAddr
jsr SKT.SetRemAddr
jsr SKT.NewTCB
bcs .99
2018-11-01 08:53:47 +00:00
jsr TCP.IN.ACKTheSYN
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
2018-09-21 15:28:46 +00:00
jsr TCP.OUT.SendOptA SYN received, Send SYN.ACK
bcs .9
2018-09-28 15:24:44 +00:00
lda #S.SOCKET.TCP.S.SYNRCVD
2018-11-01 08:53:47 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.S
jmp SKT.StoreTCB
2018-11-01 08:53:47 +00:00
.9 lda #ERR.SKT.OOS
.99 rts
*--------------------------------------
TCP.IN.JMP.SYNSENT
ldy #S.TCP.OPTIONS SYN Send, only accept SYN.ACK packet, then Send ACK
lda (ZPFrameInPtr),y
2018-09-12 15:27:00 +00:00
and #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
cmp #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
bne .9
jsr SKT.GetTCB
ldx #3
ldy #S.TCP.ACKNUM+3
sec Check if ACK=OUTNEXTSEQ+1
2018-10-08 15:41:00 +00:00
.1 lda SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ,x
adc #0
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ,x
eor (ZPFrameInPtr),y
2018-09-12 15:27:00 +00:00
bne .9
dey
dex
bpl .1
2018-09-21 15:28:46 +00:00
jsr TCP.IN.ACKTheSYN
2018-09-03 06:01:07 +00:00
lda #S.TCP.OPTIONS.ACK
jsr TCP.OUT.SendOptA SYN.ACK recieved, Send, ACK
bcs .9
2018-09-28 15:24:44 +00:00
lda #S.SOCKET.TCP.S.ESTBLSH
2018-11-01 08:53:47 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.S
2018-09-04 15:29:15 +00:00
jmp SKT.StoreTCB
2018-09-12 15:27:00 +00:00
.9 lda #S.TCP.OPTIONS.RST
jsr TCP.OUT.SendOptA
jmp SKT.Destroy
*--------------------------------------
TCP.IN.JMP.SYNRCVD
2018-09-21 15:28:46 +00:00
ldy #S.TCP.OPTIONS SYN Received, SYN.ACK Sent, only accept ACK packet
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .8
jsr SKT.GetTCB
ldx #3
ldy #S.TCP.ACKNUM+3
sec
2018-10-08 15:41:00 +00:00
.1 lda SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ,x Check if ACK=OUTNEXTSEQ+1
adc #0
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.OUTSEQNUM,x setup SEQNUM
sta SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ,x ...and update NEXTSEQ
eor (ZPFrameInPtr),y
bne .8
dey
dex
bpl .1
2018-09-28 15:24:44 +00:00
lda #S.SOCKET.TCP.S.ESTBLSH
2018-11-01 08:53:47 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.S
2018-09-04 15:29:15 +00:00
jmp SKT.StoreTCB
.8 clc
.9 rts
*--------------------------------------
TCP.IN.JMP.ESTBLSH
jsr SKT.GetTCB
ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
and #S.TCP.OPTIONS.ACK Remote side ACKed data ?
beq .1
jsr SKT.AckDataToSktOut Yes, Discard sent data
jsr SKT.StoreTCB and update SKT
.1 jsr TCP.IN.SetDataInPtrAndLen
lda ZPDataInLen Incoming Data in this frame ?
ora ZPDataInLen+1
beq .2 No data, ...
jsr SKT.AddDataToSktIn yes, queue data if there is room for....
bcs .2
jsr SKT.StoreTCB success, update socket
.2 ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
and #S.TCP.OPTIONS.FIN
beq .8
2018-09-09 08:11:42 +00:00
2018-09-13 15:29:02 +00:00
jsr TCP.IN.ACKTheFIN
2018-09-09 08:11:42 +00:00
bcs .9
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.S
lda #S.SOCKET.TCP.S.CLWAIT
sta (ZPPtrSKT),y
2018-11-01 08:53:47 +00:00
jmp SKT.StoreTCB
.8 clc
.9 rts
*--------------------------------------
TCP.IN.JMP.CLWAIT
2018-11-01 08:53:47 +00:00
clc Wait for SKT.shutdown
rts
*--------------------------------------
TCP.IN.JMP.LASTACK
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameInPtr),y
2018-09-09 08:11:42 +00:00
bit #S.TCP.OPTIONS.ACK
beq .8
jmp SKT.Destroy
.8 clc
rts
*--------------------------------------
TCP.IN.JMP.FINWT1
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameInPtr),y
2018-09-05 11:31:49 +00:00
bit #S.TCP.OPTIONS.ACK
beq TCP.IN.JMP.FINWT2.1
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.S
lda #S.SOCKET.TCP.S.FINWT2
sta (ZPPtrSKT),y
*--------------------------------------
TCP.IN.JMP.FINWT2
ldy #S.TCP.OPTIONS only accept FIN packet
lda (ZPFrameInPtr),y
2018-09-05 11:31:49 +00:00
TCP.IN.JMP.FINWT2.1
bit #S.TCP.OPTIONS.FIN
bne .8
2018-09-13 15:29:02 +00:00
jsr TCP.IN.ACKTheFIN
bcs .9
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.S
lda #S.SOCKET.TCP.S.TIMEWT
sta (ZPPtrSKT),y
.8 clc
.9 rts
*--------------------------------------
TCP.IN.JMP.CLOSING
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameInPtr),y
2018-09-09 08:11:42 +00:00
bit #S.TCP.OPTIONS.ACK
beq .1
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.S
lda #S.SOCKET.TCP.S.TIMEWT
sta (ZPPtrSKT),y
.1 clc
rts
*--------------------------------------
TCP.IN.JMP.TIMEWT
*--------------------------------------
2018-09-21 15:28:46 +00:00
TCP.IN.ACKTheSYN
ldy #S.TCP.SEQNUM+3 Get Remote SEQ
ldx #3
sec
.3 lda (ZPFrameInPtr),y Set OUTACK=SEQ+1 for new socket...
adc #0
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.INLASTSEQNUM,x
sta SKT.TmpCache+S.SOCKET.TCP.OUTACKNUM,x
2018-09-21 15:28:46 +00:00
dey
dex
bpl .3
rts
*--------------------------------------
2018-09-13 15:29:02 +00:00
TCP.IN.ACKTheFIN
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.O
2018-09-13 15:29:02 +00:00
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
jsr SKT.GetTCB
ldx #3
ldy #S.TCP.ACKNUM+3
sec
2018-10-08 15:41:00 +00:00
.3 lda SKT.TmpCache+S.SOCKET.TCP.OUTACKNUM,x
2018-09-13 15:29:02 +00:00
adc #0
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.OUTACKNUM,x
2018-09-13 15:29:02 +00:00
dey
dex
bpl .3
2018-09-13 18:43:39 +00:00
jmp TCP.OUT.I ACK the FIN
2018-09-13 15:29:02 +00:00
*--------------------------------------
TCP.IN.SetDataInPtrAndLen
ldy #S.IP.TOTAL.LENGTH+1
lda (ZPFrameInPtr),y
sec
sbc #S.IP-S.ETH
sta ZPDataInLen
dey
lda (ZPFrameInPtr),y
sbc /S.IP-S.ETH
sta ZPDataInLen+1
ldy #S.TCP.DATAOFFSET
lda (ZPFrameInPtr),y
and #$F0 Get TCP Header len in DWORD
lsr
lsr
sta TmpOffset
lda ZPDataInLen
sec
sbc TmpOffset
sta ZPDataInLen
bcs .1
dec ZPDataInLen+1
.1 lda ZPFrameInPtr
clc
adc #S.IP
pha
lda ZPFrameInPtr+1
adc /S.IP
tax
pla
clc
adc TmpOffset
bcc .2
inx
.2 sta ZPDataInPtr
stx ZPDataInPtr+1
rts
*--------------------------------------
TCP.OUT jsr SKT.GetTCB
2018-10-08 15:41:00 +00:00
TCP.OUT.I lda SKT.TmpCache+S.SOCKET.TCP.OUTTOSEND+1
ldy SKT.TmpCache+S.SOCKET.TCP.OUTTOSEND
2017-02-13 07:26:18 +00:00
bne .1
tax
bne .1
* Y,A=0 : no data to send
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.O
lda (ZPPtrSKT),y
bne TCP.OUT.SendOptA a least an option...
clc No, data, no flag....exit
rts
2017-02-13 07:26:18 +00:00
.1 cpy #K.TCP.MSS
pha
sbc /K.TCP.MSS OUTDATA > MSS ?
pla
bcc .2 no....keep data len
2017-02-13 07:26:18 +00:00
>LDYAI K.TCP.MSS yes send only MSS
.2 jsr TCP.NewFrame
bcs TCP.OUT.9
jsr SKT.GetDataFromSktOut
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.O
lda (ZPPtrSKT),y
2018-09-05 11:31:49 +00:00
ora #S.TCP.OPTIONS.ACK
jsr TCP.OUT.SendOptA.1
bcs TCP.OUT.9
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ+3
clc
adc ZPDataOutLen
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ+3
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ+2
adc ZPDataOutLen+1
2018-10-08 15:41:00 +00:00
sta SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ+2
bcc .80
2018-10-08 15:41:00 +00:00
inc SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ+1
bne .80
2018-10-08 15:41:00 +00:00
inc SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ
2018-09-04 15:29:15 +00:00
.80 jmp SKT.StoreTCB exits with CC
TCP.OUT.9 rts
*--------------------------------------
TCP.OUT.SendOptA
sta .1+1
>LDYAI 0
jsr TCP.NewFrame
bcs TCP.OUT.9
.1 lda #$ff
TCP.OUT.SendOptA.1
ldy #S.TCP.OPTIONS
sta (ZPFrameOutPtr),y
2018-09-05 11:31:49 +00:00
bit #S.TCP.OPTIONS.ACK
beq .10
ldx #3
ldy #S.TCP.ACKNUM+3
2018-10-08 15:41:00 +00:00
.1 lda SKT.TmpCache+S.SOCKET.TCP.OUTACKNUM,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .1
2018-09-13 15:29:02 +00:00
.10 ldx #3
ldy #S.TCP.SEQNUM+3
2018-10-08 15:41:00 +00:00
.2 lda SKT.TmpCache+S.SOCKET.TCP.OUTNEXTSEQ,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .2
ldy #S.TCP.WINDOW
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.INFREE+1
sta (ZPFrameOutPtr),y
iny
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.INFREE
sta (ZPFrameOutPtr),y
jsr FRM.SendIP
bcs .9
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.TCP.O
2017-03-09 07:11:44 +00:00
lda #0
sta (ZPPtrSKT),y
2018-09-13 15:29:02 +00:00
* clc
.9 rts
2017-02-13 07:26:18 +00:00
*--------------------------------------
TCP.NewFrame ldx #S.IP.PROTOCOL.TCP
jsr FRM.NewIP
bcs .9
jsr SKT.SetFrameOutDstIP
2018-09-17 15:42:38 +00:00
jsr SKT.SetFrameOutTCPUDPPorts
ldy #S.TCP.DATAOFFSET
lda #$50 Header size = 5 DWORDS
sta (ZPFrameOutPtr),y
ldy #S.TCP.WINDOW
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.INFREE+1
sta (ZPFrameOutPtr),y
iny
2018-10-08 15:41:00 +00:00
lda SKT.TmpCache+S.SOCKET.TCP.INFREE
sta (ZPFrameOutPtr),y
2016-04-09 09:15:11 +00:00
clc
.9 rts
2016-04-09 09:15:11 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.TCP
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
ASM