Kernel version 0.9 : TCPIP, new RAW socket type for ICMP (cont.)

This commit is contained in:
Rémy GIBERT 2017-01-31 17:40:37 +01:00
parent 4d00562042
commit bf8ce243c5
14 changed files with 380 additions and 345 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -165,15 +165,12 @@ S.SOCKET.SRC.PORT .EQ 8
S.SOCKET.DST.ADDR .EQ 10
S.SOCKET.DST.PORT .EQ 14
* Listen type Queue
S.SOCKET.LQ.HEAD .EQ 16
S.SOCKET.LQ.TAIL .EQ 17
S.SOCKET.LQ .EQ 18
S.SOCKET.LQ.MAX .EQ 14 14 hSocket
* Raw Type Queue
* Datagram type Queue
S.SOCKET.DQ.HEAD .EQ 16
S.SOCKET.DQ.TAIL .EQ 17
S.SOCKET.DQ .EQ 18
S.SOCKET.DQ.MAX .EQ 14 14 hMem (frames)
S.SOCKET.HQ.HEAD .EQ 16
S.SOCKET.HQ.TAIL .EQ 17
S.SOCKET.HQ .EQ 18
S.SOCKET.HQ.MAX .EQ 14 14 hMem (frames)
* Stream type Queue
S.SOCKET.SQ.hInMem .EQ 16
S.SOCKET.SQ.hOutMem .EQ 17
@ -182,11 +179,6 @@ S.SOCKET.SQ.HEAD .EQ 20
S.SOCKET.SQ.TAIL .EQ 22
S.SOCKET.SQ.SEQNUM .EQ 24
S.SOCKET.SQ.ACKNUM .EQ 28
* Raw Type Queue
S.SOCKET.RQ.HEAD .EQ 16
S.SOCKET.RQ.TAIL .EQ 17
S.SOCKET.RQ .EQ 18
S.SOCKET.RQ.MAX .EQ 14 14 hMem (frames)
*
S.SOCKET .EQ 32
*--------------------------------------

View File

@ -92,7 +92,7 @@ ARP.GETCACHE >LDYA L.ARP.CACHE
ARP.IN ldy #S.ARP.TPA+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
cmp IPCFG+S.IPCFG.IP,x
bne ARP.IN.EXIT
dey
@ -100,7 +100,7 @@ ARP.IN ldy #S.ARP.TPA+3
bpl .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
@ -115,7 +115,7 @@ ARP.IN.EXIT lda hFrameIn
ARP.IN.REQ ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
sta ARP.REP.TPA,x
dey
dex
@ -124,7 +124,7 @@ ARP.IN.REQ ldy #S.ARP.SPA+3
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameInPtr),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
@ -144,7 +144,7 @@ ARP.IN.REP lda #K.ARP.TTL
ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
@ -153,7 +153,7 @@ ARP.IN.REP lda #K.ARP.TTL
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex

View File

@ -370,34 +370,34 @@ DNS.POLL lda hDNSSocket1
*--------------------------------------
DNS.DecodeMsg sta hFrameIn
>SYSCALL GetMemPtrA
>STYA ZPFrameBase
>STYA ZPFrameInPtr
ldy #S.DNS.F+1
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
and /S.DNS.F.QR
beq .9
ldy #S.DNS.ID
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.ID
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.ID+1
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
beq .9
pha save Answer count...
ldy #S.DNS.QDCOUNT+1
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
ldy #S.DNS Point to DATA
tax
beq .3 no QUERY to skip
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
beq .2
bpl .11 Pointer ?
iny yes, skip 2 bytes
@ -406,7 +406,7 @@ DNS.DecodeMsg sta hFrameIn
.11 tya
sec
adc (ZPFrameBase),y Skip LEN+1 bytes
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .1
@ -422,7 +422,7 @@ DNS.DecodeMsg sta hFrameIn
plx get back answer count
.3 lda (ZPFrameBase),y
.3 lda (ZPFrameInPtr),y
beq .32
bpl .31 Pointer ?
iny yes, skip 2 bytes
@ -431,12 +431,12 @@ DNS.DecodeMsg sta hFrameIn
.31 tya
sec
adc (ZPFrameBase),y Skip LEN+1 bytes
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .3
.32 iny skip S.DNS.QTYPE HIGH
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.DNS.QTYPE.A
beq .40
@ -445,7 +445,7 @@ DNS.DecodeMsg sta hFrameIn
adc #7 skip CLASS,TTL+DATALENHIGH
tay
sec skip DATALENLO
adc (ZPFrameBase),y add DATALEN
adc (ZPFrameInPtr),y add DATALEN
tay
dex
bne .3
@ -457,7 +457,7 @@ DNS.DecodeMsg sta hFrameIn
iny next pos
ldx #3
.4 lda (ZPFrameBase),y
.4 lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.TTL,x
iny
dex
@ -467,7 +467,7 @@ DNS.DecodeMsg sta hFrameIn
iny
ldx #0
.5 lda (ZPFrameBase),y
.5 lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.IP,x
iny
inx

View File

@ -4,77 +4,81 @@ LOMEM $A00
INC 1
AUTO 6
.LIST OFF
*/--------------------------------------
*--------------------------------------
* #FRM.NewA
* ##In:
* A = S.IP.PROTOCOL.???
* ##Out:
* Y,A = Frame PTR
* X = hMem
*\--------------------------------------
FRM.NewA sta .1+1
*--------------------------------------
FRM.NewA sta .2+1
>PUSHWI K.ETH.FRAME.LEN
>PUSHBI S.MEM.F.INIT0
>SYSCALL GetMem
bcs .9
>STYA ZPFrameBase
ldy #S.IP.PROTOCOL
.1 lda #$ff
sta (ZPFrameBase),y
stx hFrameOut
>STYA ZPFrameOutPtr
lda DevFlags
and #S.DEVSTAT.NET.FLAGS.IPOFFLOAD
bne .9
bne .1
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
lda #S.ETH.ETHERTYPE.IP
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
ldy #S.IP.V.IHL.DSCP.ECN
lda #$45
sta (ZPFrameBase),y
iny
lda #$0
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
ldy #S.IP.IDENTIFICATION
sta (ZPFrameBase),y
inc
iny
sta (ZPFrameBase),y
dec
ldy #S.IP.FRAGMENT.FLAGS
sta (ZPFrameBase),y
iny
sta (ZPFrameBase),y
* iny
* lda #$0
* sta (ZPFrameOutPtr),y
* ldy #S.IP.IDENTIFICATION
* sta (ZPFrameOutPtr),y
* inc
* iny
* sta (ZPFrameOutPtr),y
* dec
* ldy #S.IP.FRAGMENT.FLAGS
* sta (ZPFrameOutPtr),y
* iny
* sta (ZPFrameOutPtr),y
ldy #S.IP.TTL
lda #K.IP.TTL
sta (ZPFrameBase),y
>LDYA ZPFrameBase
sta (ZPFrameOutPtr),y
.1 ldy #S.IP.PROTOCOL
.2 lda #$ff
sta (ZPFrameOutPtr),y
.9 rts
*--------------------------------------
FRM.SendICMP >PUSHW ZPFrameLen
FRM.SendICMP >PUSHW ZPFrameOutLen
>PUSHWI S.ICMP.TYPE-2
ldy #S.ICMP.CHECKSUM
lda #0
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
jsr IP.ComputeChecksum
phy
ldy #S.ICMP.CHECKSUM
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
pla
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
bra FRM.SendIP
*--------------------------------------
@ -82,21 +86,24 @@ FRM.SendTCP
bra FRM.SendIP
*--------------------------------------
FRM.SendUDP ldy #S.UDP.LENGTH+1
lda ZPFrameLen
FRM.SendUDP lda ZPFrameOutLen
sec
sbc #S.IP-2
sta (ZPFrameBase),y
dey
lda ZPFrameLen+1
ldy #S.UDP.LENGTH+1
sta (ZPFrameOutPtr),y
lda ZPFrameOutLen+1
sbc /S.IP-2
sta (ZPFrameBase),y
dey
sta (ZPFrameOutPtr),y
*--------------------------------------
FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
ldy #S.IP.SRC+3 for proper UDP/TCP CRC calculation
.1 lda IPCFG+S.IPCFG.IP,x
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
dey
dex
bpl .1
@ -106,20 +113,20 @@ FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
bne .21
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameLen
lda ZPFrameOutLen
sec
sbc #S.ETH-2
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
dey
lda ZPFrameLen+1
lda ZPFrameOutLen+1
sbc /S.ETH-2
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
lda #0
ldy #S.IP.HDR.CHECKSUM
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
@ -129,12 +136,12 @@ FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
ldy #S.IP.V.IHL.DSCP.ECN
ldx #10 10 words for IP Header
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
@ -145,15 +152,15 @@ FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
lda IP.CHECKSUM
adc #0
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
adc #0
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
.21 ldy #S.IP.PROTOCOL
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
cmp #S.IP.PROTOCOL.TCP
bne .3
jsr TCP.ComputeChecksum
@ -170,10 +177,11 @@ FRM.SendIP ldx #3 Copy SRC.IP even if IP offload
jsr IP.SetDestMAC
bcs FRM.Queue
.5 >LDYA ZPFrameBase
.5 >LDYA ZPFrameOutPtr
ldx #DEVMGR.WRITEBLOCK
jsr NetDevJmp
bcs FRM.Queue
lda hFrameOut
beq .9
>SYSCALL FreeMemA
@ -211,7 +219,7 @@ FRM.Retry ldx FRM.QUEUE.Tail
beq .8 Queue is empty, exit....
lda FRM.QUEUE.hMem,x
>SYSCALL GetMemPtrA
>STYA ZPFrameBase
>STYA ZPFrameOutPtr
ldx FRM.QUEUE.Tail
lda FRM.QUEUE.State,x
@ -220,7 +228,7 @@ FRM.Retry ldx FRM.QUEUE.Tail
jsr IP.SetDestMAC Err is ARP or higher, retry getting MAC
bcs .2 still error getting dest MAC
.1 >LDYA ZPFrameBase try sending again to DRV
.1 >LDYA ZPFrameOutPtr try sending again to DRV
ldx #DEVMGR.WRITEBLOCK
jsr NetDevJmp
bcc .3
@ -244,13 +252,6 @@ FRM.Retry ldx FRM.QUEUE.Tail
.8 rts
*--------------------------------------
FRM.GetLen lda (ZPFrameBase) Get Frame Len
sta ZPFrameLen
ldy #1
lda (ZPFrameBase),y
sta ZPFrameLen+1
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.FRM
LOAD LIB/LIBTCPIP.S

View File

@ -6,17 +6,17 @@ AUTO 6
.LIST OFF
*--------------------------------------
ICMP.IN ldy #S.ICMP.TYPE
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.ICMP.TYPE.ECHOREP
beq ICMP.IN.ECHOREP
cmp #S.ICMP.TYPE.ECHOREQ
bne ICMP.IN.EXIT
*--------------------------------------
ICMP.IN.ECHOREQ ldy #S.IP.DST+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
cmp IPCFG+S.IPCFG.IP,x
bne ICMP.IN.EXIT
dey
@ -25,12 +25,12 @@ ICMP.IN.ECHOREQ ldy #S.IP.DST+3
ldy #S.ICMP.TYPE
lda #S.ICMP.TYPE.ECHOREP
sta (ZPFrameBase),y
sta (ZPFrameInPtr),y
ldy #S.IP.SRC+3
ldx #3
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
@ -40,7 +40,7 @@ ICMP.IN.ECHOREQ ldy #S.IP.DST+3
ldx #3
.3 lda ARP.TmpCache+S.ARPCACHE.IP,x
sta (ZPFrameBase),y
sta (ZPFrameInPtr),y
dey
dex
bpl .3
@ -48,7 +48,7 @@ ICMP.IN.ECHOREQ ldy #S.IP.DST+3
ldy #S.ETH.SRCMAC+5
ldx #5
.4 lda (ZPFrameBase),y
.4 lda (ZPFrameInPtr),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
@ -64,6 +64,8 @@ ICMP.IN.ECHOREQ ldy #S.IP.DST+3
lda hFrameIn
sta hFrameOut DO NOT DISCARD this frame,it is SOURCE frame!!!
>LDYA ZPFrameInPtr
>STYA ZPFrameOutPtr
jmp FRM.SendICMP
ICMP.IN.EXIT lda hFrameIn
@ -76,10 +78,10 @@ ICMP.IN.ECHOREP jsr IP.FillTmpSocketSrcDst
sta TmpSocket+S.SOCKET.RAW.PROTO
ldy #S.ICMP.IDENTIFIER
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE

View File

@ -6,7 +6,7 @@ AUTO 6
.LIST OFF
*--------------------------------------
IP.IN ldy #S.IP.PROTOCOL
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.IP.PROTOCOL.ICMP
bne .2
jmp ICMP.IN
@ -33,18 +33,18 @@ IP.IN ldy #S.IP.PROTOCOL
IP.ComputeChecksum
>PULLA
clc
adc ZPFrameBase
adc ZPFrameOutPtr
sta ZPTmpPtr1
>PULLA
adc ZPFrameBase+1
adc ZPFrameOutPtr+1
sta ZPTmpPtr1+1
>PULLA
clc
adc ZPFrameBase
adc ZPFrameOutPtr
sta TmpOffset
>PULLA
adc ZPFrameBase+1
adc ZPFrameOutPtr+1
sta TmpOffset+1
stz IP.CHECKSUM
@ -96,7 +96,7 @@ IP.ComputeChecksum
IP.FillTmpSocketSrcDst
ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
@ -104,7 +104,7 @@ IP.FillTmpSocketSrcDst
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
@ -112,10 +112,10 @@ IP.FillTmpSocketSrcDst
rts
*--------------------------------------
IP.SetDestMAC ldy #S.IP.DST
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
iny
.1 and (ZPFrameBase),y
.1 and (ZPFrameOutPtr),y
iny
cpy #S.IP.DST+4
bne .1
@ -125,7 +125,7 @@ IP.SetDestMAC ldy #S.IP.DST
ldy #S.ETH.DSTMAC
.2 sta (ZPFrameBase),y
.2 sta (ZPFrameOutPtr),y
iny
cpy #S.ETH.DSTMAC+6
bne .2
@ -136,7 +136,7 @@ IP.SetDestMAC ldy #S.IP.DST
.3 ldy #S.IP.DST+3
ldx #3
.4 lda (ZPFrameBase),y
.4 lda (ZPFrameOutPtr),y
eor IPCFG+S.IPCFG.IP,x
and IPCFG+S.IPCFG.MASK,x
bne .6
@ -147,7 +147,7 @@ IP.SetDestMAC ldy #S.IP.DST
ldy #S.IP.DST+3 Same network, query ARP for dest IP
ldx #3
.5 lda (ZPFrameBase),y
.5 lda (ZPFrameOutPtr),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
@ -167,7 +167,7 @@ IP.SetDestMAC ldy #S.IP.DST
ldx #5
ldy #S.ETH.DSTMAC+5
.11 lda ARP.TmpCache+S.ARPCACHE.MAC,x
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
dey
dex
bpl .11

View File

@ -4,13 +4,15 @@ LOMEM $A00
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* IN : PULLW = PTR to S.SOCKET template
* OUT :
* YA=PTR to new S.SOCKET
* X=hSocket
*--------------------------------------
SKT.NEW >PULLW ZPTmpPtr1
*/--------------------------------------
* #SKT.New
* ##In :
* PUSHW = PTR to S.SOCKET template
* ##Out :
* YA = PTR to new S.SOCKET
* X = hSocket
*\--------------------------------------
SKT.New >PULLW ZPTmpPtr1
ldy #S.SOCKET.SRC.PORT+1
lda (ZPTmpPtr1),y
@ -86,27 +88,27 @@ SKT.NEW >PULLW ZPTmpPtr1
sec
rts
*--------------------------------------
SKT.ACCEPTA jsr SKT.GetA
SKT.ACCEPTA jsr SKT.GetA.I
bcs .9
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
bne .99
ldy #S.SOCKET.LQ.HEAD
ldy #S.SOCKET.HQ.HEAD
lda (ZPPtrSKT),y
ldy #S.SOCKET.LQ.TAIL
ldy #S.SOCKET.HQ.TAIL
cmp (ZPPtrSKT),y Queue Empty
beq .9 CC
pha
inc
cmp #S.SOCKET.LQ.MAX
cmp #S.SOCKET.HQ.MAX
bne .1
lda #0
.1 sta (ZPPtrSKT),y
pla
clc
adc #S.SOCKET.LQ
adc #S.SOCKET.HQ
tay
lda (ZPPtrSKT),y
clc
@ -120,21 +122,21 @@ SKT.ACCEPTA jsr SKT.GetA
*--------------------------------------
SKT.Send >PULLB hSocket
pha
>PULLW ZPDataPtr
>PULLW ZPDataLen
>PULLW ZPDataInPtr
>PULLW ZPDataInLen
pla
jsr SKT.GetA
jsr SKT.GetA.I
bcs .9
cpx #S.SOCKET.SOCK.DGRAM
cmp #S.SOCKET.SOCK.DGRAM
beq SKT.SEND.UDP
cpx #S.SOCKET.SOCK.STREAM
cmp #S.SOCKET.SOCK.STREAM
bne .1
jmp SKT.SEND.TCP
.1 cpx #S.SOCKET.SOCK.RAW
.1 cmp #S.SOCKET.SOCK.RAW
bne .99
jmp SKT.SEND.RAW
@ -144,80 +146,21 @@ SKT.Send >PULLB hSocket
SKT.SEND.UDP lda #S.IP.PROTOCOL.UDP
jsr FRM.NewA
bcs .9
stx hFrameOut
lda #S.UDP-2
clc
adc ZPDataLen
sta (ZPFrameBase)
sta ZPFrameLen
>LDAXI S.UDP-2
jsr SKT.SetFrameOutLenAX
lda /S.UDP-2
adc ZPDataLen+1
ldy #1
sta (ZPFrameBase),y
sta ZPFrameLen+1
>LDAXI S.UDP
jsr SKT.SetDataOutPtrAX
jsr SKT.SetFrameOutDstIP
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.SRCPORT
sta (ZPFrameBase),y
iny
txa
sta (ZPFrameBase),y
ldy #S.SOCKET.DST.ADDR
ldx #4
.1 lda (ZPPtrSKT),y
pha
iny
dex
bne .1
ldy #S.IP.DST+3
ldx #4
.2 pla
sta (ZPFrameBase),y
dey
dex
bne .2
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.DSTPORT
sta (ZPFrameBase),y
iny
txa
sta (ZPFrameBase),y
lda #S.UDP
clc
adc ZPFrameBase
sta ZPTmpPtr1
lda /S.UDP
adc ZPFrameBase+1
sta ZPTmpPtr1+1
ldy #0
.3 jsr DecDataLen
beq .4
lda (ZPDataPtr),y
sta (ZPTmpPtr1),y
iny
bne .3
inc ZPDataPtr
inc ZPTmpPtr1
bra .3
.4 jmp FRM.SendUDP
jsr SKT.SetFrameOutPorts
jsr SKT.CopyDataInToOut
jmp FRM.SendUDP
.9 rts
*--------------------------------------
SKT.SEND.TCP
@ -232,37 +175,44 @@ SKT.SEND.RAW ldy #S.SOCKET.RAW.PROTO
jsr FRM.NewA
bcs .9
stx hFrameOut
>LDAXI S.ICMP-2
jsr SKT.SetFrameOutLenAX
>LDAXI S.ICMP
jsr SKT.SetDataOutPtrAX
jsr SKT.SetFrameOutDstIP
jsr SKT.CopyDataInToOut
jmp FRM.SendIP
.9 sec
rts
*--------------------------------------
SKT.RCVDA jsr SKT.GetA
SKT.RCVDA jsr SKT.GetA.I
bcs .9
ldy #S.SOCKET.DQ.TAIL
ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
tax
ldy #S.SOCKET.DQ.HEAD
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
beq .99
inc
cmp #S.SOCKET.DQ.MAX
cmp #S.SOCKET.HQ.MAX
bne .1
lda #0
.1 ldy #S.SOCKET.DQ.TAIL
.1 ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.DQ
adc #S.SOCKET.HQ
tay
lda (ZPPtrSKT),y
clc
@ -274,10 +224,10 @@ SKT.RCVDA jsr SKT.GetA
SKT.CLOSEA jsr SKT.GetA
bcs .9
cpx #S.SOCKET.SOCK.DGRAM
cmp #S.SOCKET.SOCK.DGRAM
beq .8
cpx #S.SOCKET.SOCK.RAW
cmp #S.SOCKET.SOCK.RAW
beq .8
ldy #S.SOCKET.SO
@ -296,7 +246,14 @@ SKT.GETTABLE >LDYA L.SKT.TABLE
clc
rts
*--------------------------------------
SKT.GetA stz ZPPtrSKT
SKT.GetA cmp #K.SKTTABLE.SIZE
bcs SKT.GetA.9
jsr SKT.GetA.I
bcs SKT.GetA.9
>LDYA ZPPtrSKT
rts
SKT.GetA.I stz ZPPtrSKT
lsr
ror ZPPtrSKT
@ -315,63 +272,34 @@ SKT.GetA stz ZPPtrSKT
sta ZPPtrSKT+1
lda (ZPPtrSKT)
beq .9
tax
>LDYA ZPPtrSKT
beq SKT.GetA.9
rts CC
.9 lda #ERR.SKT.BAD
SKT.GetA.9 lda #ERR.SKT.BAD
sec
rts
*--------------------------------------
* ZPPtrSKT -> actual socket
* A = hSocket
*--------------------------------------
SKT.AddToQueueL pha
ldy #S.SOCKET.LQ.HEAD
lda (ZPPtrSKT),y
tax
inc
cmp #S.SOCKET.LQ.MAX
bne .1
lda #0
.1 ldy #S.SOCKET.LQ.TAIL
cmp (ZPPtrSKT),y
beq .9 Queue full!!
ldy #S.SOCKET.LQ.HEAD
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.LQ
tay
pla
sta (ZPPtrSKT),y
clc
rts
.9 pla
sec
rts
* A = hSocket or hFrame
*--------------------------------------
SKT.AddToQueueA sta .2+1
ldy #S.SOCKET.DQ.HEAD
ldy #S.SOCKET.HQ.HEAD
lda (ZPPtrSKT),y
tax
inc
cmp #S.SOCKET.DQ.MAX
cmp #S.SOCKET.HQ.MAX
bne .1
lda #0
.1 ldy #S.SOCKET.DQ.TAIL
.1 ldy #S.SOCKET.HQ.TAIL
cmp (ZPPtrSKT),y
beq .9 Queue full!!
ldy #S.SOCKET.DQ.HEAD
ldy #S.SOCKET.HQ.HEAD
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.DQ
adc #S.SOCKET.HQ
tay
.2 lda #$ff
@ -389,6 +317,95 @@ SKT.AddToQueueS
.9 sec
rts
*--------------------------------------
SKT.SetFrameOutLenAX
clc
adc ZPDataInLen
sta (ZPFrameOutPtr)
sta ZPFrameOutLen
txa
adc ZPDataInLen+1
ldy #1
sta (ZPFrameOutPtr),y
sta ZPFrameOutLen+1
rts
*--------------------------------------
SKT.SetDataOutPtrAX
clc
adc ZPFrameOutPtr
sta ZPDataOutPtr
txa
adc ZPFrameOutPtr+1
sta ZPDataOutPtr+1
rts
*--------------------------------------
SKT.SetFrameOutDstIP
ldy #S.SOCKET.DST.ADDR
ldx #4
.1 lda (ZPPtrSKT),y
pha
iny
dex
bne .1
ldy #S.IP.DST+3
ldx #4
.2 pla
sta (ZPFrameOutPtr),y
dey
dex
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
*--------------------------------------
SKT.CopyDataInToOut
lda ZPDataInLen
eor #$ff
sta ZPDataInLen
lda ZPDataInLen+1
eor #$ff
tax
ldy #0
.1 inc ZPDataInLen
bne .2
inx
beq .9
.2 lda (ZPDataInPtr),y
sta (ZPDataOutPtr),y
iny
bne .1
inc ZPDataInPtr+1
inc ZPDataOutPtr+1
bne .1
.9 rts
MAN
SAVE LIB/LIBTCPIP.S.SKT
LOAD LIB/LIBTCPIP.S

View File

@ -8,32 +8,32 @@ AUTO 6
TCP.IN ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.TCP.SRCPORT
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase),y
.2 lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
ldy #S.TCP.DSTPORT
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
@ -61,7 +61,7 @@ TCP.IN ldy #S.IP.SRC+3
beq .5
ldy #S.TCP.OPTIONS yes, only accept SYN packet
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
cmp #S.TCP.OPTIONS.SYN
bne .7 not for this listening socket
jmp TCP.IN.LISTEN.NEW
@ -102,7 +102,7 @@ TCP.IN.LISTEN.NEW
sec
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
adc #0
sta TmpSocket+S.SOCKET.SQ.ACKNUM,x
dey
@ -124,7 +124,7 @@ TCP.IN.LISTEN.NEW
pha
txa
jsr SKT.AddToQueueL
jsr SKT.AddToQueueA
pla
sta ZPPtrSKT+1
@ -159,7 +159,7 @@ TCP.IN.JMP.SYNSENT
*--------------------------------------
TCP.IN.JMP.SYNRCVD
ldy #S.TCP.OPTIONS only accept ACK packet
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .8
@ -175,7 +175,7 @@ TCP.IN.JMP.SYNRCVD
ldx #3
ldy #S.TCP.ACK.NUMBER+3
.11 lda (ZPFrameBase),y
.11 lda (ZPFrameInPtr),y
cmp TmpDWord,x
bne .8
dey
@ -217,47 +217,47 @@ TCP.IN.JMP.SYNRCVD
*--------------------------------------
TCP.IN.JMP.ESTBLSH
ldy #S.TCP.OPTIONS
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.ACK
bne .3
jsr TCP.UpdateAck
.3 lda ZPFrameBase
.3 lda ZPFrameInPtr
clc
adc #S.TCP
sta ZPDataPtr
lda ZPFrameBase+1
sta ZPDataInPtr
lda ZPFrameInPtr+1
adc /S.TCP
sta ZPDataPtr+1
sta ZPDataInPtr+1
ldy #S.TCP.DATAOFFSET
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
lsr
lsr
clc
adc ZPDataPtr
sta ZPDataPtr
lda ZPDataPtr+1
adc ZPDataPtr+1
sta ZPDataPtr+1
adc ZPDataInPtr
sta ZPDataInPtr
lda ZPDataInPtr+1
adc ZPDataInPtr+1
sta ZPDataInPtr+1
lda ZPDataPtr
lda ZPDataInPtr
sec
sbc ZPFrameBase
sta ZPDataLen
lda ZPDataPtr+1
sbc ZPFrameBase+1
sta ZPDataLen+1
sbc ZPFrameInPtr
sta ZPDataInLen
lda ZPDataInPtr+1
sbc ZPFrameInPtr+1
sta ZPDataInLen+1
ldy #S.SOCKET.SQ.ACKNUM+3
lda (ZPPtrSKT),y
clc
adc ZPDataLen
adc ZPDataInLen
sta (ZPPtrSKT),y
dey
lda (ZPPtrSKT),y
adc ZPDataLen+1
adc ZPDataInLen+1
sta (ZPPtrSKT),y
dey
lda (ZPPtrSKT),y
@ -285,7 +285,7 @@ TCP.IN.JMP.TIMEWT
TCP.UpdateAck ldy #S.TCP.ACK.NUMBER
ldx #4
.1 lda (ZPFrameBase),y
.1 lda (ZPFrameInPtr),y
pha
iny
dex
@ -354,29 +354,29 @@ TCP.SendMSG sta TCP.MSG+S.TCP.OPTIONS
TCP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.TCP.CHECKSUM
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
>LDYA ZPFrameBase
>LDYA ZPFrameOutPtr
>STYA ZPTmpPtr1
lda ZPFrameLen
lda ZPFrameOutLen
sec
sbc #S.IP-2
sta ZPDataLen
sta ZPDataInLen
lda ZPFrameLen+1
lda ZPFrameOutLen+1
sbc /S.IP-2
sta ZPDataLen+1
sta ZPDataInLen+1
clc
* lda ZPDataLen+1
* lda ZPDataInLen+1
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
lda ZPDataLen
lda ZPDataInLen
adc #S.IP.PROTOCOL.TCP
sta IP.CHECKSUM+1
@ -384,11 +384,11 @@ TCP.ComputeChecksum
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameBase),y
.10 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
@ -397,7 +397,7 @@ TCP.ComputeChecksum
ldy #S.IP
.1 jsr DecDataLen
.1 jsr DecDataInLen
beq .8
lda (ZPTmpPtr1),y
@ -408,7 +408,7 @@ TCP.ComputeChecksum
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataLen
.20 jsr DecDataInLen
bne .2
lda #0
bra .21
@ -427,12 +427,12 @@ TCP.ComputeChecksum
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
MAN

View File

@ -8,17 +8,17 @@ AUTO 6
UDP.IN jsr IP.FillTmpSocketSrcDst
ldy #S.UDP.SRCPORT
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.UDP.DSTPORT
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
@ -79,31 +79,31 @@ UDP.IN jsr IP.FillTmpSocketSrcDst
UDP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.UDP.CHECKSUM
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
>LDYA ZPFrameBase
>LDYA ZPFrameOutPtr
>STYA ZPTmpPtr1
lda ZPFrameLen
lda ZPFrameOutLen
sec
sbc #S.IP-2
sta ZPDataLen
sta ZPDataInLen
lda ZPFrameLen+1
lda ZPFrameOutLen+1
sbc /S.IP-2
sta ZPDataLen+1
sta ZPDataInLen+1
clc
ldy #S.UDP.LENGTH
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
iny
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
adc #S.IP.PROTOCOL.UDP
sta IP.CHECKSUM+1
@ -111,11 +111,11 @@ UDP.ComputeChecksum
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameBase),y
.10 lda (ZPFrameOutPtr),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase),y
lda (ZPFrameOutPtr),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
@ -124,7 +124,7 @@ UDP.ComputeChecksum
ldy #S.IP
.1 jsr DecDataLen
.1 jsr DecDataInLen
beq .8
lda (ZPTmpPtr1),y
@ -135,7 +135,7 @@ UDP.ComputeChecksum
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataLen
.20 jsr DecDataInLen
bne .2
lda #0
bra .21
@ -154,12 +154,12 @@ UDP.ComputeChecksum
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase),y
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
MAN

View File

@ -12,18 +12,27 @@ AUTO 6
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/LIBTCPIP.I
*--------------------------------------
ZPFrameBase .EQ ZPLIB
ZPFrameLen .EQ ZPLIB+2
ZPDataPtr .EQ ZPLIB+4
ZPDataLen .EQ ZPLIB+6
ZPPtrIP .EQ ZPLIB+8
ZPPtrMAC .EQ ZPLIB+10
ZPPtrDNS .EQ ZPLIB+12
ZPPtrSKT .EQ ZPLIB+14
ZPCachePtr .EQ ZPLIB+16
ZPTmpPtr1 .EQ ZPLIB+18
ZPTmpPtr2 .EQ ZPLIB+20
ZPTmpPtr3 .EQ ZPLIB+22
ZPFrameInPtr .EQ ZPLIB
ZPFrameInLen .EQ ZPLIB+2
ZPDataInPtr .EQ ZPLIB+4
ZPDataInLen .EQ ZPLIB+6
ZPFrameOutPtr .EQ ZPLIB+8
ZPFrameOutLen .EQ ZPLIB+10
ZPDataOutPtr .EQ ZPLIB+12
ZPDataOutLen .EQ ZPLIB+14
ZPPtrIP .EQ ZPLIB+16
ZPPtrMAC .EQ ZPLIB+18
ZPPtrDNS .EQ ZPLIB+20
ZPPtrSKT .EQ ZPLIB+22
ZPCachePtr .EQ ZPLIB+24
ZPTmpPtr1 .EQ ZPLIB+26
ZPTmpPtr2 .EQ ZPLIB+28
ZPTmpPtr3 .EQ ZPLIB+30
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
@ -130,14 +139,19 @@ POLL ldx #DEVMGR.READBLOCK
bcs .99 No Frame
stx hFrameIn
>STYA ZPFrameBase
jsr FRM.GetLen
>STYA ZPFrameInPtr
lda (ZPFrameInPtr) Get Frame Len
sta ZPFrameInLen
ldy #1
lda (ZPFrameInPtr),y
sta ZPFrameInLen+1
ldy #S.ETH.ETHERTYPE
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
tax
iny
lda (ZPFrameBase),y
lda (ZPFrameInPtr),y
cmp #S.ETH.ETHERTYPE.ARP
bne .1
@ -194,27 +208,27 @@ GetDynPort inc DYNPORT.LAST
clc
rts
*--------------------------------------
DecDataLen lda ZPDataLen
DecDataInLen lda ZPDataInLen
bne .1
lda ZPDataLen+1
lda ZPDataInLen+1
beq .9
dec ZPDataLen+1
.1 dec ZPDataLen
dec ZPDataInLen+1
.1 dec ZPDataInLen
lda #$FF Make NZ
.9 rts
*--------------------------------------
NetDevJmp jmp *
*--------------------------------------
.INB LIB/LIBTCPIP.S.CFG
.INB LIB/LIBTCPIP.S.FRM
.INB LIB/LIBTCPIP.S.ARP
.INB LIB/LIBTCPIP.S.IP
.INB LIB/LIBTCPIP.S.ICMP
.INB LIB/LIBTCPIP.S.UDP
.INB LIB/LIBTCPIP.S.TCP
.INB LIB/LIBTCPIP.S.CFG
.INB LIB/LIBTCPIP.S.DNS
.INB LIB/LIBTCPIP.S.SKT
.INB LIB/LIBTCPIP.S.FRM
.INB LIB/LIBTCPIP.S.HST
.INB LIB/LIBTCPIP.S.ICMP
.INB LIB/LIBTCPIP.S.IP
.INB LIB/LIBTCPIP.S.SKT
.INB LIB/LIBTCPIP.S.TCP
.INB LIB/LIBTCPIP.S.UDP
*--------------------------------------
CS.END
*--------------------------------------

View File

@ -8,3 +8,12 @@
##Out:
* Y,A = Frame PTR
* X = hMem
#SKT.New
##In :
+ PUSHW = PTR to S.SOCKET template
##Out :
+ YA = PTR to new S.SOCKET
+ X = hSocket