Kernel version 0.9 : TCP, more rewrite & bugfix

This commit is contained in:
Rémy GIBERT 2017-03-10 17:35:54 +01:00
parent 18a554a9d7
commit eb7b12f642
7 changed files with 303 additions and 319 deletions

Binary file not shown.

Binary file not shown.

View File

@ -64,8 +64,6 @@ CS.RUN >SYSCALL GetArgC
>SYSCALL GetArgA
>PUSHYA
>DEBUG
>SYSCALL SSCANF
bcc CS.RUN.QUERY
@ -117,7 +115,7 @@ CS.RUN.DUMP >LIBCALL hLIBTCPIP,LIBTCPIP.ARP.GETCACHE
ldx #K.ARPCACHE.SIZE
.1 lda (ZPPTR1)
* beq .4
beq .4
ldy #S.ARPCACHE.IP+4
.2 dey

View File

@ -107,43 +107,33 @@ SKT.New.TCP >PUSHW S.TCB
>SYSCALL GetMem
bcs .9
>STYA ZPTmpPtr2
txa
ldy #S.SOCKET.SQ.hTCB
sta (ZPTmpPtr3),y
ldy #S.TCB.INFREE
ldx #S.TCB.OUTTAIL+1
.10 stz SKT.TCBCache,x
dex
bpl .10
lda #K.TCP.WSIZE
sta (ZPTmpPtr2),y
iny
sta SKT.TCBCache+S.TCB.INFREE
sta SKT.TCBCache+S.TCB.OUTFREE
lda /K.TCP.WSIZE
sta (ZPTmpPtr2),y
sta SKT.TCBCache+S.TCB.INFREE+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
ldy #S.TCB.OUTFREE
lda #K.TCP.WSIZE
sta (ZPTmpPtr2),y
iny
lda /K.TCP.WSIZE
sta (ZPTmpPtr2),y
lda #0
ldy #S.TCB.INUSED
sta (ZPTmpPtr2),y
iny
sta (ZPTmpPtr2),y
ldy #S.TCB.OUTUSED
sta (ZPTmpPtr2),y
iny
sta (ZPTmpPtr2),y
stz SKT.TCBCache+S.TCB.INUSED
stz SKT.TCBCache+S.TCB.INUSED+1
stz SKT.TCBCache+S.TCB.OUTUSED
stz SKT.TCBCache+S.TCB.OUTUSED+1
ldx #3
ldy #S.TCB.SEQNUM+3
.1 lda A2osX.TIMER16,x
sta (ZPTmpPtr2),y
dey
sta SKT.TCBCache+S.TCB.SEQNUM,x
dex
bpl .1
@ -165,6 +155,10 @@ SKT.New.TCP >PUSHW S.TCB
ldy #S.SOCKET.SQ.hOutMem
sta (ZPTmpPtr3),y
jsr SKT.StoreTCB
jsr TCP.OUT.SYN
clc
.9 rts
*/--------------------------------------
@ -175,19 +169,19 @@ SKT.New.TCP >PUSHW S.TCB
* ##Out :
*\--------------------------------------
SKT.CloseA cmp #K.SKTTABLE.SIZE
bcs SKT.GetA.9
bcs .9
jsr SKT.GetA.I
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
beq .8
beq .1
cmp #S.SOCKET.SOCK.RAW
beq .8
beq .1
cmp #S.SOCKET.SOCK.STREAM
bne SKT.GetA.9
bne .9
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
@ -199,13 +193,44 @@ SKT.CloseA cmp #K.SKTTABLE.SIZE
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.FIN
sta (ZPPtrSKT),y
jsr TCP.OUT Try to push FIN
clc
rts
.9 lda #ERR.SKT.BAD
sec
rts
.1 ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
beq .8
pha
clc
adc #S.SOCKET.HQ
tax
pla
inx
cmp #S.SOCKET.HQ.MAX
beq .2
lda #0
.2
ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
txa
>SYSCALL FreeMemA
bra .1
.8 lda #0
sta (ZPPtrSKT)
clc
.9 rts
rts
*/--------------------------------------
* #SKT.GetA
* Get Ptr to socket
@ -402,8 +427,7 @@ SKT.Write.RAW ldy #S.SOCKET.RAW.PROTO
jmp FRM.SendIP
.9 sec
rts
.9 rts
*--------------------------------------
SKT.Write.TCP ldy #S.SOCKET.TCP.STATUS
lda (ZPPtrSKT),y
@ -413,7 +437,7 @@ SKT.Write.TCP ldy #S.SOCKET.TCP.STATUS
jsr SKT.AddDataToSktOut
bcs .90
jsr TCP.OUT.ESTBLSH try to push, ignore error....
jsr TCP.OUT try to push, ignore error....
clc
rts
@ -566,37 +590,7 @@ SKT.Read.I jsr SKT.GetA.I
bne .91 IO err
jsr SKT.GetDataFromSktIn
bcs .99 No data...
>STYA TmpOffset
ldy #S.TCB.ACKNUM
lda (ZPPtrSKT),y
clc
adc TmpOffset
sta (ZPPtrSKT),y
iny
lda (ZPPtrSKT),y
adc TmpOffset+1
sta (ZPPtrSKT),y
iny
lda (ZPPtrSKT),y
adc #0
sta (ZPPtrSKT),y
iny
lda (ZPPtrSKT),y
adc #0
sta (ZPPtrSKT),y
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
>LDYA TmpOffset
clc
rts
rts if CS, No data...
.90 lda #ERR.SKT.BAD
sec
@ -642,45 +636,54 @@ SKT.AddToQueueA sta .2+1
* Src : A,X
* Dst : hOutMem/OUTTAIL
*--------------------------------------
SKT.FreeDataFromSktOutAX
pha
ldy #S.TCB.OUTTAIL
clc
adc (ZPPtrSKT),y
sta (ZPPtrSKT),y
iny
txa
adc (ZPPtrSKT),y
and /K.TCP.WSIZE-1
sta (ZPPtrSKT),y
SKT.AckDataToSktOut
jsr SKT.GetTCB
pla
sta .1+1
stx .2+1
ldy #S.TCB.OUTFREE
clc
adc (ZPPtrSKT),y
sta (ZPPtrSKT),y
iny
txa
adc (ZPPtrSKT),y
sta (ZPPtrSKT),y
ldy #S.TCP.ACK.NUMBER+3 Get new ACK number from FrameIn...
ldx #0 Substract old Ack from socket
ldy #S.TCB.OUTUSED
sec
lda (ZPPtrSKT),y
.1 sbc #$ff
sta (ZPPtrSKT),y
iny
adc (ZPPtrSKT),y
.2 sbc #$ff
sta (ZPPtrSKT),y
.1 lda (ZPFrameInPtr),y
pha
sbc SKT.TCBCache+S.TCB.ACKNUM,x
sta TmpDWord,x
pla
sta SKT.TCBCache+S.TCB.ACKNUM,x
dey
inx
cpx #4
bpl .1
rts
lda SKT.TCBCache+S.TCB.OUTTAIL
clc
adc TmpDWord
sta SKT.TCBCache+S.TCB.OUTTAIL
lda SKT.TCBCache+S.TCB.OUTTAIL+1
adc TmpDWord+1
and /K.TCP.WSIZE-1
sta SKT.TCBCache+S.TCB.OUTTAIL+1
lda SKT.TCBCache+S.TCB.OUTFREE
clc
adc TmpDWord
sta SKT.TCBCache+S.TCB.OUTFREE
lda SKT.TCBCache+S.TCB.OUTFREE+1
adc TmpDWord+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
lda SKT.TCBCache+S.TCB.OUTUSED
sec
sbc TmpDWord
sta SKT.TCBCache+S.TCB.OUTUSED
lda SKT.TCBCache+S.TCB.OUTUSED+1
sbc TmpDWord+1
sta SKT.TCBCache+S.TCB.OUTUSED+1
jmp SKT.StoreTCB
*--------------------------------------
* From TCP.IN
* Src : ZPDataInPtr/ZPDataInLen
@ -856,15 +859,25 @@ SKT.AddDataToSktOut
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTUSED+1
jmp SKT.StoreTCB
lda SKT.TCBCache+S.TCB.SEQNUM
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.SEQNUM
lda SKT.TCBCache+S.TCB.SEQNUM+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.SEQNUM+1
bcc .80
inc SKT.TCBCache+S.TCB.SEQNUM+2
bne .80
inc SKT.TCBCache+S.TCB.SEQNUM+3
.80 jmp SKT.StoreTCB
*--------------------------------------
* From TCP.OUT
* Src : hOutMem/OUTTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
*--------------------------------------
SKT.GetDataFromSktOut
jsr SKT.GetTCB
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
@ -920,7 +933,8 @@ SKT.GetDataFromSktOut
sta ZPTmpPtr2+1
bra .1
.8 jmp SKT.StoreTCB
.8 clc
rts
*--------------------------------------
* From SKT.Read
* In:
@ -1043,7 +1057,27 @@ SKT.GetDataFromSktIn
sbc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.INUSED+1
jsr SKT.StoreTCB
lda SKT.TCBCache+S.TCB.ACKNUM
clc
adc ZPTmpPtr3
sta SKT.TCBCache+S.TCB.ACKNUM
lda SKT.TCBCache+S.TCB.ACKNUM+1
adc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.ACKNUM+1
bcc .80
inc SKT.TCBCache+S.TCB.ACKNUM+2
bne .80
inc SKT.TCBCache+S.TCB.ACKNUM+3
.80 jsr SKT.StoreTCB
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
>LDYA ZPTmpPtr3
clc
rts

View File

@ -131,34 +131,29 @@ TCP.IN.JMP.LISTEN
lda #ERR.SKT.OOS
.9 rts
.3 jsr ARP.AddFromFrameInPtr
.3 jsr SKT.GetTCB
ldy #S.TCP.SEQ.NUMBER+3
ldy #S.TCP.SEQ.NUMBER
ldx #3
sec
.1 lda (ZPFrameInPtr),y Set ACK=SEQ+1 for new socket...
adc #0
sta TmpDWord,x
dey
sta SKT.TCBCache+S.TCB.ACKNUM,x
iny
dex
bpl .1
ldx #3
ldy #S.TCB.ACKNUM+3
.4 lda TmpDWord,x Update new socket with ACK number
sta (ZPPtrSKT),y
dey
dex
bpl .4
jsr SKT.StoreTCB
jsr ARP.AddFromFrameInPtr
jsr TCP.OUT.SYNACK
bcs .9
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNSENT
lda #S.SOCKET.TCP.STATUS.SYNRCVD
sta (ZPPtrSKT),y
@ -166,144 +161,161 @@ TCP.IN.JMP.LISTEN
rts
*--------------------------------------
TCP.IN.JMP.SYNSENT
ldy #S.TCP.OPTIONS only accept SYN.ACK packet
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
bne .8
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.ESTBLSH
sta (ZPPtrSKT),y
.8 clc
rts
*--------------------------------------
TCP.IN.JMP.SYNRCVD
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .8
jsr SKT.GetTCB
ldx #3
ldy #S.TCB.SEQNUM+3
ldy #S.TCP.ACK.NUMBER
sec
.10 lda (ZPPtrSKT),y
.1 lda SKT.TCBCache+S.TCB.SEQNUM,x
adc #0
sta TmpDWord,x
dey
dex
bpl .10
ldx #3
ldy #S.TCP.ACK.NUMBER+3
.11 lda (ZPFrameInPtr),y
cmp TmpDWord,x
sta SKT.TCBCache+S.TCB.SEQNUM,x
eor (ZPFrameInPtr),y
bne .8
dey
iny
dex
bpl .11
bpl .1
ldx #3
ldy #S.TCB.SEQNUM+3
.12 lda TmpDWord,x
sta (ZPPtrSKT),y
dey
dex
bpl .12
jsr SKT.StoreTCB
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.ESTBLSH
sta (ZPPtrSKT),y
sta (ZPPtrSKT),y
.8 clc
rts
*--------------------------------------
TCP.IN.JMP.SYNRCVD
clc
rts
*--------------------------------------
TCP.IN.JMP.ESTBLSH
jsr SKT.GetTCB
ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
bit #S.TCP.OPTIONS.ACK
beq .2
beq .1
ldy #S.TCP.ACK.NUMBER+3 Get new ACK number from FrameIn...
ldx #3
.1 lda (ZPFrameInPtr),y
sta TmpDWord,x
dey
dex
bpl .1
ldy #S.TCB.ACKNUM Substract old Ack from socket
sec
lda (ZPPtrSKT),y
sbc TmpDWord
pha save result LO for FreeData
jsr SKT.AckDataToSktOut
lda TmpDWord
sta (ZPPtrSKT),y and store new ACK in skt
iny
lda (ZPPtrSKT),y
sbc TmpDWord+1
tax save result HI for FreeData
lda TmpDWord+1 we stop here, will never be more than K.TCP.WSIZE
sta (ZPPtrSKT),y
iny
lda TmpDWord+2
sta (ZPPtrSKT),y
iny
lda TmpDWord+3
sta (ZPPtrSKT),y
pla
jsr SKT.FreeDataFromSktOutAX
*----------
.2 lda ZPDataInLen
.1 lda ZPDataInLen
ora ZPDataInLen+1
beq .8 No data in this incoming frame...
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
.3 lda (ZPFrameInPtr),y
sta TmpDWord,x
dey
dex
bpl .3
beq .2 No data in this incoming frame...
jsr TCP.SetDataInPtrAndLen
jsr SKT.AddDataToSktIn
bcs .9
.2 ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
bit #S.TCP.OPTIONS.FIN
beq .1
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.CLWAIT
sta (ZPPtrSKT),y
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
.8 jsr SKT.StoreTCB
clc
.9 rts
*--------------------------------------
TCP.IN.JMP.CLWAIT
clc
rts
*--------------------------------------
TCP.IN.JMP.LASTACK
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .8
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
beq .1
>SYSCALL FreeMemA
.1 ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
beq .2
>SYSCALL FreeMemA
.2 ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
beq .3
>SYSCALL FreeMemA
.3 lda #0
sta (ZPPtrSKT)
.8 clc
rts
*--------------------------------------
TCP.IN.JMP.CLWAIT
TCP.IN.JMP.LASTACK
TCP.IN.JMP.FINWT1
*--------------------------------------
TCP.IN.JMP.FINWT2
*--------------------------------------
TCP.IN.JMP.CLOSING
*--------------------------------------
TCP.IN.JMP.TIMEWT
clc
rts
*--------------------------------------
TCP.OUT.SYNACK >LDYAI 0
TCP.OUT.SYN >LDYAI 0
jsr TCP.NewFrame
bcs .9
ldx #3
ldy #S.TCP.ACK.NUMBER+3
ldy #S.TCP.SEQ.NUMBER
.1 lda TmpDWord,x
.1 lda SKT.TCBCache+S.TCB.SEQNUM,x
sta (ZPFrameOutPtr),y
dey
iny
dex
bpl .1
ldy #S.TCP.OPTIONS
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
lda #S.TCP.OPTIONS.SYN
sta (ZPFrameOutPtr),y
jsr TCP.SendFrame
iny S.TCP.WINDOW
lda /K.TCP.WSIZE
sta (ZPFrameOutPtr),y
iny
lda #K.TCP.WSIZE
sta (ZPFrameOutPtr),y
ldy #S.TCP.SEQ.NUMBER
ldx #3
jsr FRM.SendIP
bcs .9
ldy #S.SOCKET.TCP.OPTIONS
@ -317,14 +329,58 @@ TCP.OUT.SYNACK >LDYAI 0
clc
.9 rts
*--------------------------------------
TCP.OUT.ESTBLSH ldy #S.TCB.OUTUSED
lda (ZPPtrSKT),y
TCP.OUT.SYNACK >LDYAI 0
jsr TCP.NewFrame
bcs .9
pha
ldx #3
ldy #S.TCP.SEQ.NUMBER
.1 lda SKT.TCBCache+S.TCB.SEQNUM,x
sta (ZPFrameOutPtr),y
iny
lda (ZPPtrSKT),y
ply
dex
bpl .1
ldy #S.TCP.ACK.NUMBER
ldx #3
.3 lda SKT.TCBCache+S.TCB.ACKNUM,x
sta (ZPFrameOutPtr),y
iny
dex
bpl .3
ldy #S.TCP.OPTIONS
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
sta (ZPFrameOutPtr),y
iny S.TCP.WINDOW
lda /K.TCP.WSIZE
sta (ZPFrameOutPtr),y
iny
lda #K.TCP.WSIZE
sta (ZPFrameOutPtr),y
jsr FRM.SendIP
bcs .9
ldy #S.SOCKET.TCP.OPTIONS
lda #0
sta (ZPPtrSKT),y
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNSENT
sta (ZPPtrSKT),y
clc
.9 rts
*--------------------------------------
TCP.OUT jsr SKT.GetTCB
lda SKT.TCBCache+S.TCB.OUTUSED+1
ldy SKT.TCBCache+S.TCB.OUTUSED
bne .1
tax
@ -344,110 +400,32 @@ TCP.OUT.ESTBLSH ldy #S.TCB.OUTUSED
bcs .9
jsr SKT.GetDataFromSktOut
ldy #S.TCB.SEQNUM compute new SEQ.NUM
lda (ZPPtrSKT),y
clc
adc TmpOffset
sta TmpDWord
iny
lda (ZPPtrSKT),y
adc TmpOffset+1
sta TmpDWord+1
iny
lda (ZPPtrSKT),y
adc #0
sta TmpDWord+2
iny
lda (ZPPtrSKT),y
adc #0
sta TmpDWord+3
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
.3 lda TmpDWord,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .3
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ldy #S.TCP.OPTIONS
sta (ZPFrameOutPtr),y
.7 jsr TCP.SendFrame
.7 jsr FRM.SendIP
bcs .9
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
bit #S.TCP.OPTIONS.FIN
beq .70
beq .8
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.FINWT1
sta (ZPPtrSKT),y
.70 ldy #S.SOCKET.TCP.OPTIONS
.8 ldy #S.SOCKET.TCP.OPTIONS
lda #0
sta (ZPPtrSKT),y
ldx #3
ldy #S.TCB.SEQNUM+3
jmp SKT.StoreTCB
.71 lda TmpDWord,x
sta (ZPPtrSKT),y
dey
dex
bpl .71
.8 clc
.9 rts
*--------------------------------------
TCP.GetSktAckNum
ldy #S.TCP.ACK.NUMBER
ldx #4
.1 lda (ZPFrameInPtr),y
pha
iny
dex
bne .1
ldy #S.TCB.ACKNUM+3
ldx #4
.2 pla
sta (ZPPtrSKT),y
dey
dex
bne .2
rts
*--------------------------------------
TCP.UpdateSktAckNum
ldy #S.TCB.ACKNUM+3
lda (ZPPtrSKT),y
clc
adc ZPDataInLen
sta (ZPPtrSKT),y
dey
lda (ZPPtrSKT),y
adc ZPDataInLen+1
sta (ZPPtrSKT),y
dey
lda (ZPPtrSKT),y
adc #0
sta (ZPPtrSKT),y
dey
lda (ZPPtrSKT),y
adc #0
sta (ZPPtrSKT),y
rts
*--------------------------------------
TCP.SetDataInPtrAndLen
ldy #S.TCP.DATAOFFSET
lda (ZPFrameInPtr),y
@ -529,25 +507,6 @@ TCP.NewFrame ldx #S.IP.PROTOCOL.TCP
clc
.9 rts
*--------------------------------------
TCP.SendFrame ldy #S.TCB.SEQNUM+7
ldx #7
.1 lda (ZPPtrSKT),y
pha
dey
dex
bpl .1
ldy #S.TCP.SEQ.NUMBER
.2 pla
sta (ZPFrameOutPtr),y
iny
cpy #S.TCP.SEQ.NUMBER+8
bne .2
jmp FRM.SendIP
*--------------------------------------
TCP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.TCP.CHECKSUM

View File

@ -182,13 +182,6 @@ PULSEA and #S.EVT.F.T1SEC
.1 jsr DNS.POLL
jmp FRM.RETRY
*--------------------------------------
ToLowerCaseA cmp #'A'
bcc .1
cmp #'Z'+1
bcs .1
adc #$20
.1 rts
*--------------------------------------
GetDynPort inc DYNPORT.LAST
bne .1
inc DYNPORT.LAST+1

View File

@ -458,7 +458,7 @@ Socket .DA #S.SOCKET.SOCK.DGRAM
DHCP.DISC .HS 01010600 OP,HTYPE,HLEN,HOPS
DHCP.DISC.XID .BS 4
.HS 0000 SECS
.DA S.DHCP.FLAGS.BRDCST
.DA 0000 S.DHCP.FLAGS.BRDCST
.HS 00000000 CIADDR
DHCP.DISC.YIADDR .HS 00000000
.HS 00000000 SIADDR
@ -475,7 +475,7 @@ DHCP.DISC.LEN .EQ *-DHCP.DISC
DHCP.REQ .HS 01010600 OP,HTYPE,HLEN,HOPS
DHCP.REQ.XID .BS 4
.HS 0000 SECS
.DA S.DHCP.FLAGS.BRDCST
.DA 0000 S.DHCP.FLAGS.BRDCST
.HS 00000000 CIADDR
DHCP.REQ.YIADDR .HS 00000000
.HS 00000000 SIADDR