Kernel version 0.9 : TCP & Sockets, bugfix session #2

This commit is contained in:
Rémy GIBERT 2017-02-16 17:26:11 +01:00
parent 2f2529f8ab
commit 5abba96786
8 changed files with 158 additions and 156 deletions

Binary file not shown.

Binary file not shown.

View File

@ -72,17 +72,17 @@ ICMP.IN.EXIT lda hFrameIn
>SYSCALL FreeMemA
rts
*--------------------------------------
ICMP.IN.ECHOREP jsr IP.FillTmpSocketSrcDst
ICMP.IN.ECHOREP jsr IP.FillSKT.TemplateSrcDst
lda #S.IP.PROTOCOL.ICMP
sta TmpSocket+S.SOCKET.RAW.PROTO
sta SKT.Template+S.SOCKET.RAW.PROTO
ldy #S.ICMP.IDENTIFIER
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT+1
sta SKT.Template+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT
sta SKT.Template+S.SOCKET.DST.PORT
lda hSocketTable
>SYSCALL GetMemPtrA
@ -98,7 +98,7 @@ ICMP.IN.ECHOREP jsr IP.FillTmpSocketSrcDst
ldy #S.SOCKET.SRC.ADDR
.4 lda (ZPPtrSKT),y
cmp TmpSocket,y
cmp SKT.Template,y
bne .7
iny
cpy #S.SOCKET.SRC.PORT

View File

@ -93,11 +93,11 @@ IP.ComputeChecksum
eor #$FF
rts
*--------------------------------------
IP.FillTmpSocketSrcDst
IP.FillSKT.TemplateSrcDst
ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
sta SKT.Template+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
@ -105,7 +105,7 @@ IP.FillTmpSocketSrcDst
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
sta SKT.Template+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2

View File

@ -327,7 +327,27 @@ SKT.Write.UDP ldx #S.IP.PROTOCOL.UDP
jsr SKT.SetFrameOutDstIP
jsr SKT.SetFrameOutPorts
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.SRCPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.DSTPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
jsr SKT.CopyDataInToOut
@ -960,30 +980,6 @@ SKT.SetFrameOutDstIP
bne .2
rts
*--------------------------------------
SKT.SetFrameOutPorts
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.SRCPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.DSTPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
SKT.CopyDataInToOut
lda ZPDataInPtr+1
pha

View File

@ -5,21 +5,21 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
TCP.IN jsr IP.FillTmpSocketSrcDst
TCP.IN jsr IP.FillSKT.TemplateSrcDst
ldy #S.TCP.SRCPORT
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT+1
sta SKT.Template+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT
sta SKT.Template+S.SOCKET.DST.PORT
ldy #S.TCP.DSTPORT
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
sta SKT.Template+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT
sta SKT.Template+S.SOCKET.SRC.PORT
lda hSocketTable
>SYSCALL GetMemPtrA
@ -34,7 +34,7 @@ TCP.IN jsr IP.FillTmpSocketSrcDst
ldy #S.SOCKET.SRC.ADDR
.4 lda TmpSocket,y
.4 lda SKT.Template,y
cmp (ZPPtrSKT),y
bne .7 Not for this socket...
@ -45,25 +45,31 @@ TCP.IN jsr IP.FillTmpSocketSrcDst
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN Listening socket?
beq .5
beq .5 no, go check if Dst Match
ldy #S.TCP.OPTIONS yes, only accept SYN packet
ldy #S.TCP.OPTIONS yes, only accept SYN packet
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.SYN
bne .7 not for this listening socket
jmp TCP.IN.LISTEN.NEW
and #S.TCP.OPTIONS.SYN
beq .7 maybe a regular frame for a regular socket
jmp TCP.IN.JMP.LISTEN
.5 ldy #S.SOCKET.DST.ADDR
.6 lda TmpSocket,y regular socket, check remote ADDR/PORT
.6 lda SKT.Template,y regular socket, check remote ADDR/PORT
cmp (ZPPtrSKT),y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .6
jmp TCP.IN.REGULAR
stx hSocket
ldy #S.SOCKET.TCP.STATUS
lda (ZPPtrSKT),y
asl
tax
jmp (L.TCP.IN.JMP,x)
.7 lda ZPPtrSKT
clc
@ -76,28 +82,32 @@ TCP.IN jsr IP.FillTmpSocketSrcDst
cpx #K.SKTTABLE.SIZE
bne .3
clc Discard frame
.9 clc Discard frame
rts
*--------------------------------------
TCP.IN.LISTEN.NEW
TCP.IN.JMP.CLOSED
clc
rts
*--------------------------------------
TCP.IN.JMP.LISTEN
lda #S.SOCKET.SOCK.STREAM
sta TmpSocket
sta SKT.Template+S.SOCKET.SOCK
stz TmpSocket+S.SOCKET.SO
stz SKT.Template+S.SOCKET.SO
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
sec
.1 lda (ZPFrameInPtr),y
.1 lda (ZPFrameInPtr),y Save ACK +1 for new socket...
adc #0
sta TmpSocket+S.SOCKET.SQ.ACKNUM,x
sta TmpDWord,x
dey
dex
bpl .1
>PUSHW L.TmpSocket
>PUSHW L.SKT.Template
jsr SKT.New
bcs .9
@ -120,24 +130,34 @@ TCP.IN.LISTEN.NEW
lda #ERR.SKT.OOS
.9 rts
.3 ldy #S.SOCKET.TCP.STATUS
.3 ldx #3
ldy #S.SOCKET.SQ.ACKNUM+3
.4 lda TmpDWord,x Update new socket with ACK number
sta (ZPPtrSKT),y
dey
dex
bpl .4
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNRCVD
sta (ZPPtrSKT),y
ldy #S.SOCKET.TCP.OPTIONS
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
jmp TCP.Out
*--------------------------------------
TCP.IN.REGULAR stx hSocket
jsr TCP.Out
bcs .9
ldy #S.SOCKET.TCP.STATUS
lda (ZPPtrSKT),y
asl
tax
jmp (L.TCP.IN.JMP,x)
lda #S.SOCKET.TCP.STATUS.SYNSENT
sta (ZPPtrSKT),y
clc
rts
*--------------------------------------
TCP.IN.JMP.CLOSED
TCP.IN.JMP.LISTEN
TCP.IN.JMP.SYNSENT
clc
rts
@ -186,8 +206,8 @@ TCP.IN.JMP.SYNRCVD
TCP.IN.JMP.ESTBLSH
ldy #S.TCP.OPTIONS
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .1
bit #S.TCP.OPTIONS.ACK
beq .1
jsr TCP.UpdateSktAckNum
@ -207,7 +227,35 @@ TCP.IN.JMP.TIMEWT
clc
rts
*--------------------------------------
TCP.OUT ldy #S.SOCKET.SQ.OUTUSED
TCP.OUT ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
bit #S.TCP.OPTIONS.SYN
beq TCP.OUT.ESTBLSH
>LDYAI 0
jsr TCP.NewFrame
bcs .9
ldy #S.TCP.OPTIONS
lda (ZPFrameOutPtr),y
ora #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
sta (ZPFrameOutPtr),y
jsr FRM.SendIP
bcs .9
ldy #S.TCP.OPTIONS
lda #0
sta (ZPFrameOutPtr),y
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNSENT
sta (ZPFrameOutPtr),y
clc
.9 rts
*--------------------------------------
TCP.OUT.ESTBLSH ldy #S.SOCKET.SQ.OUTUSED
lda (ZPPtrSKT),y
pha
@ -230,8 +278,7 @@ TCP.OUT ldy #S.SOCKET.SQ.OUTUSED
.2 >STYA TmpOffset
ldx #S.IP.PROTOCOL.TCP
jsr FRM.NewIP
jsr TCP.NewFrame
bcs .9
jsr SKT.GetDataFromSktOut
@ -296,6 +343,26 @@ TCP.OUT ldy #S.SOCKET.SQ.OUTUSED
.8 clc
.9 rts
*--------------------------------------
TCP.GetSktAckNum
ldy #S.TCP.ACK.NUMBER
ldx #4
.1 lda (ZPFrameInPtr),y
pha
iny
dex
bne .1
ldy #S.SOCKET.SQ.ACKNUM+3
ldx #4
.2 pla
sta (ZPPtrSKT),y
dey
dex
bne .2
rts
*--------------------------------------
TCP.UpdateSktAckNum
ldy #S.SOCKET.SQ.ACKNUM+3
lda (ZPPtrSKT),y
@ -315,25 +382,6 @@ TCP.UpdateSktAckNum
adc #0
sta (ZPPtrSKT),y
rts
*--------------------------------------
ldy #S.TCP.ACK.NUMBER
ldx #4
.1 lda (ZPFrameInPtr),y
pha
iny
dex
bne .1
ldy #S.SOCKET.SQ.ACKNUM+3
ldx #4
.2 pla
sta (ZPPtrSKT),y
dey
dex
bne .2
rts
*--------------------------------------
TCP.SetDataInPtrAndLen
ldy #S.TCP.DATAOFFSET
@ -368,53 +416,35 @@ TCP.SetDataInPtrAndLen
sta ZPDataInLen+1
rts
*--------------------------------------
TCP.SendSYNACK lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
TCP.NewFrame ldx #S.IP.PROTOCOL.TCP
jsr FRM.NewIP
bcs .9
sta TCP.MSG+S.TCP.OPTIONS
ldy #S.SOCKET.SRC.ADDR+3
ldx #3
.1 lda (ZPPtrSKT),y
sta TCP.MSG+S.IP.SRC,x
dey
dex
bpl .1
jsr SKT.SetFrameOutDstIP
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.SRCPORT+1
tax
iny
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.SRCPORT
ldy #S.TCP.SRCPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
ldy #S.SOCKET.DST.ADDR+3
ldx #3
.2 lda (ZPPtrSKT),y
sta TCP.MSG+S.IP.DST,x
dey
dex
bpl .2
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.DSTPORT+1
tax
iny
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.DSTPORT
ldy #S.SOCKET.SQ.SEQNUM+7
ldx #7
.3 lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.SEQ.NUMBER,x
dey
dex
bpl .3
>PUSHW L.TCP.MSG
* jsr FRM.SendTCP
ldy #S.TCP.DSTPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
clc
rts
.9 rts
*--------------------------------------
TCP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM

View File

@ -5,21 +5,21 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
UDP.IN jsr IP.FillTmpSocketSrcDst
UDP.IN jsr IP.FillSKT.TemplateSrcDst
ldy #S.UDP.SRCPORT
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT+1
sta SKT.Template+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT
sta SKT.Template+S.SOCKET.DST.PORT
ldy #S.UDP.DSTPORT
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
sta SKT.Template+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT
sta SKT.Template+S.SOCKET.SRC.PORT
lda hSocketTable
>SYSCALL GetMemPtrA
@ -38,7 +38,7 @@ UDP.IN jsr IP.FillTmpSocketSrcDst
ldy #S.SOCKET.SRC.PORT yes, do not check if IP match
.4 lda (ZPPtrSKT),y
.41 cmp TmpSocket,y
.41 cmp SKT.Template,y
bne .7
iny
cpy #S.SOCKET.DST.ADDR
@ -50,7 +50,7 @@ UDP.IN jsr IP.FillTmpSocketSrcDst
ldy #S.SOCKET.DST.PORT yes, do not check if IP match
.5 lda (ZPPtrSKT),y
.51 cmp TmpSocket,y
.51 cmp SKT.Template,y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2

View File

@ -94,8 +94,7 @@ L.DNS.SOCKET .DA DNS.SOCKET
L.DNS.MSG .DA DNS.MSG
L.ARP.CACHE .DA ARP.CACHE
L.DNS.CACHE .DA DNS.CACHE
L.TmpSocket .DA TmpSocket
L.TCP.MSG .DA TCP.MSG
L.SKT.Template .DA SKT.Template
L.TCP.IN.JMP .DA TCP.IN.JMP.CLOSED
.DA TCP.IN.JMP.LISTEN
.DA TCP.IN.JMP.SYNSENT
@ -258,29 +257,6 @@ ARP.REP.SPA .BS 4
ARP.REP.THA .BS 6
ARP.REP.TPA .BS 4
*--------------------------------------
TCP.MSG .DA S.TCP-2+4 +4 bytes for MSS option
.BS 12 ETH:MAC+MAC
.DA /S.ETH.ETHERTYPE.IP
.DA #S.ETH.ETHERTYPE.IP
.DA $0045 IP:
.BS 6 LEN+ID+Frag
.DA #K.IP.TTL
.DA #S.IP.PROTOCOL.TCP
.BS 2 Checksum
.BS 8 IP:DST,SRC
.BS 4 TCP:Ports
.BS 8 SEQ,ACK
.DA #$60 6 DWORD
.BS 1 Options
.DA /K.TCP.WSIZE
.DA #K.TCP.WSIZE
.BS 4 CHK,URG
.HS 0204 MSS option
.DA /K.TCP.MSS
.DA #K.TCP.MSS
*--------------------------------------
DNS.SOCKET .DA #S.SOCKET.SOCK.DGRAM
.BS 3
DNS.SOCKET.SA .BS 4
@ -316,9 +292,9 @@ DNS.HostNameLen .BS 1
DNS.HostName .BS K.DNS.MAXLEN+1
DNS.TmpCache .BS S.DNSCACHE
ARP.TmpCache .BS S.ARP
SKT.Template .BS S.SOCKET.TEMPLATE
SKT.TmpCache .BS S.SOCKET
TmpDWord .BS 4
TmpSocket .BS S.SOCKET
hFrameIn .BS 1
hFrameOut .BS 1
hSocket .BS 1