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

This commit is contained in:
Rémy GIBERT 2017-02-17 08:20:57 +01:00
parent 5abba96786
commit b5f7300385
5 changed files with 136 additions and 64 deletions

Binary file not shown.

Binary file not shown.

View File

@ -98,6 +98,33 @@ ARP.GetCache >LDYA L.ARP.CACHE
*-------------------------------------- *--------------------------------------
* PRIVATE * PRIVATE
*-------------------------------------- *--------------------------------------
ARP.AddFromFrameInPtr
ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .1
ldy #S.ETH.SRCMAC+5
ldx #5
.2 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
bpl .2
lda #K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
lda /K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL+1
lda #S.ARPCACHE.STATUS.RESOLVED
jmp ARP.ADD.I
*--------------------------------------
ARP.IN ldy #S.ARP.TPA+3 ARP.IN ldy #S.ARP.TPA+3
ldx #3 ldx #3

View File

@ -95,18 +95,6 @@ TCP.IN.JMP.LISTEN
stz SKT.Template+S.SOCKET.SO stz SKT.Template+S.SOCKET.SO
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
sec
.1 lda (ZPFrameInPtr),y Save ACK +1 for new socket...
adc #0
sta TmpDWord,x
dey
dex
bpl .1
>PUSHW L.SKT.Template >PUSHW L.SKT.Template
jsr SKT.New jsr SKT.New
@ -130,7 +118,21 @@ TCP.IN.JMP.LISTEN
lda #ERR.SKT.OOS lda #ERR.SKT.OOS
.9 rts .9 rts
.3 ldx #3 .3 jsr ARP.AddFromFrameInPtr
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
sec
.1 lda (ZPFrameInPtr),y Set ACK=SEQ+1 for new socket...
adc #0
sta TmpDWord,x
dey
dex
bpl .1
ldx #3
ldy #S.SOCKET.SQ.ACKNUM+3 ldy #S.SOCKET.SQ.ACKNUM+3
.4 lda TmpDWord,x Update new socket with ACK number .4 lda TmpDWord,x Update new socket with ACK number
@ -170,7 +172,9 @@ TCP.IN.JMP.SYNRCVD
ldx #3 ldx #3
ldy #S.SOCKET.SQ.SEQNUM+3 ldy #S.SOCKET.SQ.SEQNUM+3
sec sec
.10 lda (ZPPtrSKT),y .10 lda (ZPPtrSKT),y
adc #0 adc #0
sta TmpDWord,x sta TmpDWord,x
@ -237,11 +241,10 @@ TCP.OUT ldy #S.SOCKET.TCP.OPTIONS
bcs .9 bcs .9
ldy #S.TCP.OPTIONS ldy #S.TCP.OPTIONS
lda (ZPFrameOutPtr),y lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
ora #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
sta (ZPFrameOutPtr),y sta (ZPFrameOutPtr),y
jsr FRM.SendIP jsr TCP.SendFrame
bcs .9 bcs .9
ldy #S.TCP.OPTIONS ldy #S.TCP.OPTIONS
@ -323,7 +326,7 @@ TCP.OUT.ESTBLSH ldy #S.SOCKET.SQ.OUTUSED
ora #S.TCP.OPTIONS.ACK ora #S.TCP.OPTIONS.ACK
sta (ZPFrameOutPtr),y sta (ZPFrameOutPtr),y
.7 jsr FRM.SendIP .7 jsr TCP.SendFrame
bcs .9 bcs .9
ldy #S.SOCKET.TCP.OPTIONS ldy #S.SOCKET.TCP.OPTIONS
@ -443,9 +446,46 @@ TCP.NewFrame ldx #S.IP.PROTOCOL.TCP
iny iny
txa txa
sta (ZPFrameOutPtr),y sta (ZPFrameOutPtr),y
ldy #S.TCP.DATAOFFSET
lda #$50 Header size = 5 DWORDS
sta (ZPFrameOutPtr),y
ldy #S.SOCKET.SQ.INFREE
lda (ZPPtrSKT),y
pha
iny
lda (ZPPtrSKT),y
ldy #S.TCP.WINDOW
sta (ZPFrameOutPtr),y
iny
pla
sta (ZPFrameOutPtr),y
clc clc
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
TCP.SendFrame ldy #S.SOCKET.SQ.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 TCP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM lda #0 RESET.TCP.CHECKSUM
ldy #S.TCP.CHECKSUM ldy #S.TCP.CHECKSUM

View File

@ -101,65 +101,29 @@ CS.RUN.INIT ldx #3
>LDYA L.MSG.INITOK >LDYA L.MSG.INITOK
>SYSCALL CPrintFYA >SYSCALL CPrintFYA
.11 >SYSCALL Sleep .2 >SYSCALL Sleep
jsr CS.RUN.SERVER
bcs CS.RUN.ERR
.12 ldy #hSrvSocket ldy #SktIndex
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.AcceptA
bcs .15
pha
ldy #hSockets
ldx #CONN.MAX
.13 lda (pData),y
beq .14
iny
dex
bne .13
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CloseA
bra .15
.14 pla
sta (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetA
>STYA ZPSktPtr
ldx #3
ldy #S.SOCKET.DST.ADDR+3
.2 >PUSHB (ZPSktPtr),y
dey
dex
bpl .2
>LDYA L.MSG.INCOMING
>SYSCALL CPrintFYA
.15 ldy #SktIndex
lda (pData),y lda (pData),y
tay tay
lda (pData),y hSockets lda (pData),y hSockets
beq .16 beq .3
jsr CS.RUN.CLIENT * jsr CS.RUN.CLIENT
.16 ldy #SktIndex .3 ldy #SktIndex
lda (pData),y lda (pData),y
inc inc
cmp #CONN.MAX cmp #CONN.MAX
bne .17 bne .4
lda #0 lda #0
.17 sta (pData),y .4 sta (pData),y
bra .11 bra .2
.9 >LDYA L.MSG.SKTERR .9 >LDYA L.MSG.SKTERR
>SYSCALL CPrintFYA >SYSCALL CPrintFYA
@ -170,9 +134,50 @@ CS.RUN.INIT ldx #3
CS.RUN.ABORT >LDYA L.MSG.ABORT CS.RUN.ABORT >LDYA L.MSG.ABORT
>SYSCALL CPrintFYA >SYSCALL CPrintFYA
lda #0 lda #0
sec
CS.RUN.ERR sec
rts rts
*-------------------------------------- *--------------------------------------
CS.RUN.SERVER ldy #hSrvSocket
lda (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.AcceptA
bcs .8
pha
ldy #hSockets
ldx #CONN.MAX
.1 lda (pData),y
beq .2
iny
dex
bne .1
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CloseA
bra .8
.2 pla
sta (pData),y
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetA
>STYA ZPSktPtr
ldx #3
ldy #S.SOCKET.DST.ADDR+3
.3 >PUSHB (ZPSktPtr),y
dey
dex
bpl .3
>LDYA L.MSG.INCOMING
>SYSCALL CPrintFYA
.8 clc
.9 rts
*--------------------------------------
CS.RUN.CLIENT >PUSHA hSocket CS.RUN.CLIENT >PUSHA hSocket
>PUSHWI UsrBuf256 >PUSHWI UsrBuf256
>PUSHWI 256 >PUSHWI 256