LIBTCPIP:Started implementing Socket API

This commit is contained in:
Rémy GIBERT 2016-03-13 23:09:00 +01:00
parent f1f09b937d
commit 6dc3efd617
13 changed files with 1339 additions and 555 deletions

Binary file not shown.

Binary file not shown.

View File

@ -53,7 +53,7 @@ LIBTCPIP.SKT.ACCEPTA .EQ 56
LIBTCPIP.SKT.SENDA .EQ 58
LIBTCPIP.SKT.SEND .EQ 60
LIBTCPIP.SKT.RCVDA .EQ 62
LIBTCPIP.SKT.RCVD .EQ 64
*LIBTCPIP.SKT.RCVD .EQ 64
LIBTCPIP.SKT.CLOSEA .EQ 66
LIBTCPIP.SKT.GETTABLE .EQ 68
LIBTCPIP.SKT.GETA .EQ 70

View File

@ -5,9 +5,7 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
ARP.IN >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
ldy #S.ARP.TPA
ARP.IN ldy #S.ARP.TPA
ldx #S.IPCFG.IP
.1 lda (ZPFrameBase1),y
@ -39,59 +37,36 @@ ARP.IN.REP >LDAXI S.ARP.SHA
clc
ARP.IN.RTS rts
ARP.IN.REQ jsr NEW.ARP.FRAME
bcs ARP.IN.RTS
ARP.IN.REQ ldy #S.ETH.SRCMAC+5
ldx #5
phx
>STYA ZPFrameBase2
ldy #S.ARP.OPERATION+1
lda #S.ARP.OPERATION.REP
sta (ZPFrameBase2),y
.1 lda (ZPFrameBase1),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .1
ldy #S.ARP.SPA+3
ldx #3
.2 lda (ZPFrameBase1),y
sta ARP.REP.TPA,x
dey
dex
bpl .2
>LDAXI S.ARP.SHA
jsr SetFramePtr1AX
>LDAXI S.ETH.DSTMAC
jsr SetFramePtr2AX
ldy #6
jsr CopyFramePtr12
>LDAXI S.ARP.THA
jsr SetFramePtr2AX
ldy #10 IP(4) + MAC(6)
jsr CopyFramePtr12
>PUSHW ZPFramePtr1 still point to SHA
>PUSHW ZPFramePtr1
>LDAXI S.ARP.SPA
jsr SetFramePtr1AX
>PUSHW ZPFramePtr1
jsr ARP.ADD
ldx #5
ldy #S.ARP.SHA+5
.4 lda IPCFG+S.IPCFG.MAC,x
sta (ZPFrameBase2),y
dey
dex
bpl .4
ldx #3
ldy #S.ARP.SPA+3
.5 lda IPCFG+S.IPCFG.IP,x
sta (ZPFrameBase2),y
dey
dex
bpl .5
>PUSHW ZPFrameBase2
jsr SEND.ARP.FRAME
pla
>SYSCALL SYS.FreeMemA
clc
rts
>PUSHW L.ARP.REP
ldx #DEVMGR.NET.SEND
jmp NetDevJmp
*--------------------------------------
* ARP.CLEAR
*--------------------------------------
@ -228,60 +203,21 @@ ARP.QUERY.I ldx #0
tax
cmp #K.ARPCACHE.SIZE*S.ARPCACHE
bne .1
*--------------------------------------
ARP.REQUEST.I ldy #3
.1 lda (ZPPtrIP),y
sta ARP.REQ.TPA,y
dey
bpl .1
>PUSHW L.ARP.REQ
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
jsr NEW.ARP.FRAME nothing in ARP cache, send ARP request
bcs .9
phx
ldy #S.ARP.OPERATION+1
lda #S.ARP.OPERATION.REQ
sta (ZPFrameBase1),y
jsr ARP.ADD.PENDING ZPPtrIP still pointing IP
ldx #5
ldy #S.ARP.SHA+5
.71 lda IPCFG+S.IPCFG.MAC,x
sta (ZPFrameBase1),y
dey
dex
bpl .71
ldx #3
ldy #S.ARP.SPA+3
.72 lda IPCFG+S.IPCFG.IP,x
sta (ZPFrameBase1),y
dey
dex
bpl .72
ldy #3
.73 lda (ZPPtrIP),y
pha
dey
bpl .73
ldy #S.ARP.TPA
.74 pla
sta (ZPFrameBase1),y
iny
cpy #S.ARP.TPA+4
bne .74
lda #255
ldy #S.ETH.DSTMAC
.75 sta (ZPFrameBase1),y
iny
cpy #S.ETH.DSTMAC+6
bne .75
jsr SEND.ARP.FRAME.I
bcs .76
jsr ARP.ADD.PENDING ZPARPIP still pointing IP
.76 pla
>SYSCALL SYS.FreeMemA
sec
.9 rts
*--------------------------------------

View File

@ -5,42 +5,6 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
DNS.IN ldy #S.DNS.F+1
lda (ZPFrameBase1),y
and /S.DNS.F.QR
beq .9
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameBase1),y
beq .9
ldy #S.DNS.QDCOUNT+1
lda (ZPFrameBase1),y
tax
beq .3 no QUERY to skip
ldy #S.DNS Read query
.1 lda (ZPFrameBase1),y
beq .2
iny
bne .1
.2 tya
clc
adc #4 Skip QTYPE & QCLASS
tay
dex skip another QUERY ?
bne .1
.3 iny skip high byte of offset
iny skip lo byte of offset
clc
rts
.9 sec
rts
*--------------------------------------
DNS.CLEAR ldx #K.DNSCACHE.SIZE*S.DNSCACHE
.1 stz DNS.CACHE-1,x
dex
@ -56,11 +20,10 @@ DNS.CLEAR ldx #K.DNSCACHE.SIZE*S.DNSCACHE
* CC: hit: IP filled with address
* CS: missed
*--------------------------------------
DNS.QUERY >PULLYA Get host string
jsr PSTR2DNSHostName
DNS.QUERY >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get IP address to fill
DNS.QUERY.I jsr HST.PSTR2DNS.I
ldx #0
.1 lda DNS.CACHE,x
@ -106,126 +69,60 @@ DNS.QUERY >PULLYA Get host string
tax
cmp #K.DNSCACHE.SIZE*S.DNSCACHE
bne .1
*--------------------------------------
DNS.REQUEST ldx #0
ldy #12
DNS.REQUEST jsr NEW.UDP.FRAME
bcc .1
bra *
rts
.1 phx
ldy #S.UDP.SRCPORT
lda /UDP.PORT.DNS
sta (ZPFrameBase1),y
.1 lda DNSHostname,x
sta DNS.MSG,y
beq .2
inx
iny
lda #UDP.PORT.DNS
sta (ZPFrameBase1),y
bne .1
ldy #S.UDP.DSTPORT
lda /UDP.PORT.DNS
sta (ZPFrameBase1),y
iny
lda #UDP.PORT.DNS
sta (ZPFrameBase1),y
ldy #S.DNS.ID
lda A2osX.RANDOM16
sta (ZPFrameBase1),y
sta DNSMessageID
iny
lda A2osX.RANDOM16+1
sta (ZPFrameBase1),y
sta DNSMessageID+1
* ldy #S.DNS.F
* lda /S.DNS.F.RD
* sta (ZPFrameBase1),y
* iny
* lda #S.DNS.F.RD
* sta (ZPFrameBase1),y
ldy #S.DNS.QDCOUNT
lda /1
sta (ZPFrameBase1),y
iny
lda #1
sta (ZPFrameBase1),y
lda #S.DNS
clc
adc ZPFrameBase1
sta ZPFramePtr1
lda /S.DNS
adc ZPFrameBase1+1
sta ZPFramePtr1+1
ldy #0
.2 lda DNSHostname,y
sta (ZPFramePtr1),y
beq .3
iny
bne .2
.3 iny
.2 iny
lda /S.DNS.QTYPE.A
sta (ZPFramePtr1),y
sta DNS.MSG,y
iny
lda #S.DNS.QTYPE.A
sta (ZPFramePtr1),y
sta DNS.MSG,y
iny
lda /S.DNS.QCLASS.IN
sta (ZPFramePtr1),y
sta DNS.MSG,y
iny
lda #S.DNS.QCLASS.IN
sta (ZPFramePtr1),y
lda DNSHostnameLen Get hostname len again (QNAME)
clc
adc #6 (len+1) + Ending 0 + QTYPE + QCLASS
adc #S.DNS
sta ZPFrameLen1
sta DNS.MSG,y
iny
tya
sta DNS.MSG.LEN
lda #0
adc /S.DNS
sta ZPFrameLen1+1
sta DNS.MSG.LEN+1
ldx #S.IPCFG.DNS1
ldy #S.IP.DST
lda hDNSSocket1
beq .9
>LDYA A2osX.RANDOM16
>STYA DNS.MSG
>PUSHW DNS.MSG.LEN
>PUSHW L.DNS.MSG
>PUSHB hDNSSocket1
jsr SKT.SEND
lda IPCFG,x
beq .5
lda hDNSSocket2
beq .9
.4 lda IPCFG,x
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS1+4
bne .4
jsr SEND.UDP.FRAME.I
bcs .8
>LDYA A2osX.RANDOM16
>STYA DNS.MSG+S.DNS.ID
>PUSHW DNS.MSG.LEN
>PUSHW L.DNS.MSG
>PUSHB hDNSSocket2
jsr SKT.SEND
.5 ldx #S.IPCFG.DNS2
ldy #S.IP.DST
lda IPCFG,x
beq .7
.6 lda IPCFG,x
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS2+4
bne .6
jsr SEND.UDP.FRAME.I
bcs .8
.7 jsr DNS.ADD.PENDING.I
.8 pla
>SYSCALL SYS.FreeMemA
sec
.9 sec
rts
*--------------------------------------
* DNS.ADD
@ -233,10 +130,11 @@ DNS.REQUEST jsr NEW.UDP.FRAME
* PULLW = hostname PSTR to Add
* PULLW = PTR to IP
*--------------------------------------
DNS.ADD >PULLYA Get host string
jsr PSTR2DNSHostName
DNS.ADD >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get host IP address
jsr HST.PSTR2DNS.I
lda #$80
sta DNSHostTTL+3
stz DNSHostTTL+2
@ -323,10 +221,10 @@ DNS.UPD.ENTRY lda Status
sta DNS.CACHE+S.DNSCACHE.STATUS,x
bmi .1 pending?
lda DNSMessageID
sta DNS.CACHE+S.DNSCACHE.ID,x
lda DNSMessageID+1
sta DNS.CACHE+S.DNSCACHE.ID+1,x
* lda DNSMessageID
* sta DNS.CACHE+S.DNSCACHE.ID,x
* lda DNSMessageID+1
* sta DNS.CACHE+S.DNSCACHE.ID+1,x
bra .9
@ -356,7 +254,51 @@ DNS.GETCACHE >LDYA L.DNS.CACHE
clc
rts
*--------------------------------------
DNS.SKTPOLL lda hDNSSocket1
beq .8
jsr SKT.RCVDA
bcs .8
bra *
.8 clc
rts
.9 sec
rts
*--------------------------------------
ldy #S.DNS.F+1
lda (ZPFrameBase1),y
and /S.DNS.F.QR
beq .9
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameBase1),y
beq .9
ldy #S.DNS.QDCOUNT+1
lda (ZPFrameBase1),y
tax
beq .3 no QUERY to skip
ldy #S.DNS Read query
.1 lda (ZPFrameBase1),y
beq .2
iny
bne .1
.2 tya
clc
adc #4 Skip QTYPE & QCLASS
tay
dex skip another QUERY ?
bne .1
.3 iny skip high byte of offset
iny skip lo byte of offset
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.DNS
LOAD LIB/LIBTCPIP.S

View File

@ -119,10 +119,6 @@ NEW.ARP.FRAME jsr NEW.ETH.FRAME
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ETH.FRAME >PUSHWI K.ETH.FRAME.LEN
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem
@ -131,14 +127,18 @@ NEW.ETH.FRAME >PUSHWI K.ETH.FRAME.LEN
clc
.9 rts
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.ICMP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
jsr FRM.GetLen1
SEND.ICMP.FRAME.I
>PUSHW ZPFrameLen1
>PUSHWI S.ICMP.TYPE
>PUSHWI S.ICMP.TYPE-2
ldy #S.ICMP.CHECKSUM
lda #0
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
jsr IP.ComputeChecksum
phy
@ -150,117 +150,154 @@ SEND.ICMP.FRAME >PULLW ZPFrameBase1
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.TCP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
jsr FRM.GetLen1
SEND.TCP.FRAME.I
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.UDP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
jsr FRM.GetLen1
SEND.UDP.FRAME.I
ldy #S.UDP.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.IP
sbc #S.IP-2
sta (ZPFrameBase1),y
dey
lda ZPFrameLen1+1
sbc /S.IP
sta (ZPFrameBase1),y
lda #0 SET.UDP.CHECKSUM
ldy #S.UDP.CHECKSUM (0 = Disable UDP Checksum)
sta (ZPFrameBase1),y
iny
sbc /S.IP-2
sta (ZPFrameBase1),y
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.IP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
jsr FRM.GetLen1
SEND.IP.FRAME.I ldx #S.IPCFG.IP
ldy #S.IP.SRC
SEND.IP.FRAME.I ldx #3
ldy #S.IP.SRC+3
.10 lda IPCFG,x
.10 lda IPCFG+S.IPCFG.IP,x
sta (ZPFrameBase1),y
inx
iny
cpy #S.IP.SRC+4
bne .10
dey
dex
bpl .10
jsr ARP.RESOLVE
bcs .9
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.ETH
sbc #S.ETH-2
sta (ZPFrameBase1),y
dey
lda ZPFrameLen1+1
sbc /S.ETH
sbc /S.ETH-2
sta (ZPFrameBase1),y
lda #0
ldy #S.IP.HDR.CHECKSUM
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
stz IP.CHECKSUM+2
* stz IP.CHECKSUM+3 Optimized for IP Header
clc
ldy #S.IP.V.IHL.DSCP.ECN
ldx #10 10 words for IP Header
.1 lda (ZPFrameBase1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .1
ldy #S.IP.HDR.CHECKSUM
lda IP.CHECKSUM
adc #0
eor #$FF
sta (ZPFrameBase1),y
iny
lda IP.CHECKSUM+1
adc #0
eor #$FF
sta (ZPFrameBase1),y
ldy #S.IP.PROTOCOL
lda (ZPFrameBase1),y
cmp #S.IP.PROTOCOL.TCP
bne .3
jsr TCP.ComputeChecksum
bra .8
.3 cmp #S.IP.PROTOCOL.UDP
bne .8
jsr UDP.ComputeChecksum
.8 lda DevFlags
and #S.DEVINFO.NET.FLAGS.ARPOFFLOAD
bne .81
jsr ARP.RESOLVE
bcs .9
.81 >PUSHW ZPFrameBase1
ldx #DEVMGR.NET.SEND
jmp NetDevJmp
.9 rts
*--------------------------------------
SEND.ARP.FRAME >PUSHW ZPFrameBase1
ldx #DEVMGR.NET.SEND
jmp NetDevJmp
*--------------------------------------
SEND.ETH.FRAME >PUSHW ZPFrameBase1
ldx #DEVMGR.NET.SEND
jmp NetDevJmp
*--------------------------------------
RCVD.FRAME >PULLW ZPFrameBase1
bra *
*--------------------------------------
RCVD.FRAMEA sta hFrame1
>SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1
jsr FRM.GetLen1
ldy #S.ETH.ETHERTYPE
lda (ZPFrameBase1),y
tax
iny
lda (ZPFrameBase1),y
iny
clc
adc IP.CHECKSUM
sta IP.CHECKSUM
txa
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
bcc .2
inc IP.CHECKSUM+2
*.2 bne .3 Optimized for IP Header
* inc IP.CHECKSUM+3 Optimized for IP Header
.2 cpy #S.IP
cmp #S.ETH.ETHERTYPE.ARP
bne .1
cpx /S.ETH.ETHERTYPE.ARP
bne .1
lda IP.CHECKSUM
clc
adc IP.CHECKSUM+2
eor #$FF
ldy #S.IP.HDR.CHECKSUM+1
sta (ZPFrameBase1),y
dey
lda IP.CHECKSUM+1
* adc IP.CHECKSUM+3 Optimized for IP Header
adc #0 Optimized for IP Header
eor #$FF
sta (ZPFrameBase1),y
bra SEND.ETH.FRAME
.9 rts
jmp ARP.IN
.1 cmp #S.ETH.ETHERTYPE.IP
bne .9
cpx /S.ETH.ETHERTYPE.IP
bne .9
jsr IP.IN
bcs .9
jmp DNS.SKTPOLL
.9 sec
rts
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.ARP.FRAME >PULLW ZPFrameBase1
SEND.ARP.FRAME.I
>LDYAI S.ARP default ARP Frame length
>STYA ZPFrameLen1
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.ETH.FRAME >PUSHW ZPFrameLen1
>PUSHW ZPFrameBase1
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
FRM.GetLen1 lda (ZPFrameBase1) Get Frame Len
sta ZPFrameLen1
ldy #1
lda (ZPFrameBase1),y
sta ZPFrameLen1+1
rts
*--------------------------------------
MAN

176
LIB/LIBTCPIP.S.HST.txt Normal file
View File

@ -0,0 +1,176 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
HST.GETBYNAME >PULLW ZPPtrDNS
>PULLW ZPPtrIP
jsr HST.ScanIP
bcc .1
jsr DNS.QUERY.I
bcs .9
.1 jmp ARP.REQUEST.I
.9 rts
*--------------------------------------
HST.GETBYADDR >PULLW ZPPtrIP
>PULLW ZPPtrDNS
sec
rts
*--------------------------------------
HST.DNS2PSTR >PULLW ZPPtrDNS
sec
rts
*--------------------------------------
HST.PSTR2DNS >PULLW ZPPtrDNS
HST.PSTR2DNS.I lda (ZPPtrDNS)
beq .9
cmp #K.DNS.MAXLEN-1
bcs .9
tay
inc
sta DNSHostNameLen
lda #0 Ending 0
sta DNSHostName+1,y
ldx #0
.1 lda (ZPPtrDNS),y
and #$7f
cmp #'.'
beq .2
cmp #'A'
bcc .10
cmp #'Z'+1
bcs .10
adc #$20
.10 inx
bra .3
.2 txa
ldx #0
.3 sta DNSHostName,y
dey
bne .1
stx DNSHostName
clc
rts
.9 sec
rts
*--------------------------------------
HST.ScanIP stz HST.IP
lda (ZPPtrDNS)
beq .9
ldy #0
.1 ldx #0
stx HST.DecStr
.2 tya
cmp (ZPPtrDNS)
beq .4
iny
lda (ZPPtrDNS),y
cmp #'.'
beq .3
cmp #'0'
bcc .9
cmp #'9'+1
bcs .9
cpx #3
beq .9
inx
sta HST.DecStr,x
bra .2
.3 stx HST.DecStr
phy
jsr HST.Dec2Hex
ply
bcc .1
rts
.4 txa
beq .5
stx HST.DecStr
jsr HST.Dec2Hex
bcs .9
.5 ldx HST.IP
cpx #4
bne .9
ldy #3
.6 lda HST.IP,x
sta (ZPPtrIP),y
dex
dey
bpl .6
clc
rts
.9 sec
rts
*--------------------------------------
HST.Dec2Hex ldy HST.DecStr
beq .9
ldx HST.IP
cpx #4
beq .9
inx
lda HST.DecStr+1
and #$0f
sta HST.IP,x
ldy #1
.1 cpy HST.DecStr
beq .8
iny
lda HST.IP,x
asl HST.IP,x
bcs .9
asl HST.IP,x
bcs .9
adc HST.IP,x
bcs .9
asl
bcs .9
sta HST.IP,x
lda HST.DecStr,y
and #$0f
adc HST.IP,x
sta HST.IP,x
bcc .1
.9 sec
rts
.8 stx HST.IP
clc
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.HST
LOAD LIB/LIBTCPIP.S
ASM

View File

@ -9,44 +9,55 @@ ICMP.IN ldy #S.ICMP.TYPE
lda (ZPFrameBase1),y
cmp #S.ICMP.TYPE.ECHOREQ
bne .9
ldy #S.IP.DST
ldx #S.IPCFG.IP
.10 lda (ZPFrameBase1),y
.1 lda (ZPFrameBase1),y
cmp IPCFG,x
bne .9
iny
inx
cpx #S.IPCFG.IP+4
bne .10
jsr NEW.ICMP.FRAME
bcs .9
phx
>STYA ZPFrameBase2
ldy #S.ICMP.TYPE
lda #S.ICMP.TYPE.ECHOREP
sta (ZPFrameBase2),y
jsr MakeIPReply
ldy #S.ICMP.IDENTIFIER
.1 lda (ZPFrameBase1),y
sta (ZPFrameBase2),y
iny
cpy #ZPFrameLen1
bne .1
>PUSHW ZPFrameLen1
>PUSHW ZPFrameBase2
jsr SEND.ICMP.FRAME
ldy #S.ICMP.TYPE
lda #S.ICMP.TYPE.ECHOREP
sta (ZPFrameBase1),y
ldy #S.IP.SRC+3
ldx #3
pla
>SYSCALL SYS.FreeMemA
clc
rts
.2 lda (ZPFrameBase1),y
sta TmpIP,x
dey
dex
bpl .2
ldy #S.IP.DST+3
ldx #3
.3 lda TmpIP,x
sta (ZPFrameBase1),y
dey
dex
bpl .3
ldy #S.ETH.SRCMAC+5
ldx #5
.4 lda (ZPFrameBase1),y
sta TmpMAC,x
dey
dex
bpl .4
>PUSHW L.TmpMAC
>PUSHW L.TmpIP
jsr ARP.ADD
jmp SEND.ICMP.FRAME.I
.9 sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.ICMP

View File

@ -5,9 +5,7 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
IP.IN >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
ldy #S.IP.PROTOCOL
IP.IN ldy #S.IP.PROTOCOL
lda (ZPFrameBase1),y
cmp #S.IP.PROTOCOL.ICMP
bne .2
@ -16,16 +14,7 @@ IP.IN >PULLW ZPFrameBase1
.2 cmp #S.IP.PROTOCOL.UDP
bne .3
ldy #S.UDP.DSTPORT
lda /UDP.PORT.DNS
cmp (ZPFrameBase1),y
bne .21
iny
lda #UDP.PORT.DNS
cmp (ZPFrameBase1),y
bne .21
jmp DNS.IN
.21 jmp UDP.IN
jmp UDP.IN
.3 cmp #S.IP.PROTOCOL.TCP
bne .9
@ -57,23 +46,30 @@ IP.ComputeChecksum
adc ZPFrameBase1+1
sta TmpOffset+1
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM
stz IP.CHECKSUM+1
stz IP.CHECKSUM+2
stz IP.CHECKSUM+3
ldy #1
.1 lda (ZPTmpPtr1),y
clc
ldy #2
.1 clc
iny
lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
lda (ZPTmpPtr1)
dey
lda (ZPTmpPtr1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
bcc .3
inc IP.CHECKSUM+2
bne .3
inc IP.CHECKSUM+3
.3 lda ZPTmpPtr1
clc
adc #2
@ -85,6 +81,7 @@ IP.ComputeChecksum
lda ZPTmpPtr1+1
cmp TmpOffset+1
bne .1
lda IP.CHECKSUM
clc
adc IP.CHECKSUM+2

View File

@ -5,84 +5,127 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
SKT.NEW >PULLW ZPPtrSKT
* IN : PULLW = PTR to S.SOCKET template
* OUT :
* YA=PTR to new S.SOCKET
* X hSocket 128<x<255
*--------------------------------------
SKT.NEW >PULLW ZPTmpPtr1
stz bFound
ldy #S.SOCKET.SRC.PORT+1
lda (ZPPtrSKT),y
lda (ZPTmpPtr1),y
dey
ora (ZPPtrSKT),y
ora (ZPTmpPtr1),y
bne .1
jsr GetDynPort
sta (ZPPtrSKT),y
sta (ZPTmpPtr1),y
txa
iny
sta (ZPPtrSKT),y
sta (ZPTmpPtr1),y
.1 >LDYA L.SKT.TABLE
>STYA ZPTmpPtr1
>STYA ZPTmpPtr2
stz TmpOffset to keep track of any free slot
ldx #0
.2 lda (ZPTmpPtr1)
.2 lda (ZPTmpPtr2)
beq .4
ldy #S.SOCKET.SRC.PORT+1
.3 lda (ZPPtrSKT),y
cmp (ZPTmpPtr1),y
cmp (ZPTmpPtr1)
bne .5
dey
bpl .3
ldy #S.SOCKET.SRC.ADDR
.3 lda (ZPTmpPtr1),y
cmp (ZPTmpPtr2),y
bne .5
iny
cpy #S.SOCKET.DST.PORT+2
bne .3
lda ERR.SBUSY
sec
rts
.4 bit bFound
bmi .5
sec
ror bFound
stx hSocket
>LDYA ZPTmpPtr1
>STYA ZPTmpPtr2
.4 bit TmpOffset
bmi .5 Already found an empty slot
>LDYA ZPTmpPtr2
>STYA ZPTmpPtr3
txa
ora #$80
sta TmpOffset
.5 lda ZPTmpPtr1
.5 lda ZPTmpPtr2
clc
adc #S.SOCKET
sta ZPTmpPtr1
sta ZPTmpPtr2
bcc .6
inc ZPTmpPtr1+1
inc ZPTmpPtr2+1
.6 inx
cpx #K.SKTTABLE.SIZE
bne .2
bit bFound
bit TmpOffset Did we found an empty slot ?
bpl .9
ldy #S.SOCKET-1
.7 lda (ZPPtrSKT),y
sta (ZPTmpPtr2),y
.7 lda (ZPTmpPtr1),y
sta (ZPTmpPtr3),y
dey
bpl .7
lda hSocket
lda ZPTmpPtr1
clc
adc #S.SOCKET.DST.ADDR
sta ZPPtrIP
lda ZPTmpPtr1+1
adc /S.SOCKET.DST.ADDR
sta ZPPtrIP+1
lda (ZPPtrIP)
beq .8
jsr ARP.REQUEST.I
.8 ldx TmpOffset
>LDYA ZPTmpPtr3
clc
rts
.9 lda ERR.OOS
.9 lda #ERR.OOS
sec
rts
*--------------------------------------
SKT.LISTEN
sec
SKT.ACCEPTA jsr SKT.GetA
bcs .9
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
bne .99
ldy #S.SOCKET.LQ.HEAD
lda (ZPPtrSKT),y
ldy #S.SOCKET.LQ.TAIL
cmp (ZPPtrSKT),y Queue Empty
beq .9 CC
pha
inc
cmp #S.SOCKET.LQ.MAX
bne .1
lda #0
.1 sta (ZPPtrSKT),y
pla
clc
adc #S.SOCKET.LQ
tay
lda (ZPPtrSKT),y
clc
rts
*--------------------------------------
SKT.ACCEPT
.99 lda #ERR.SBAD
sec
rts
.9 rts
*--------------------------------------
SKT.SENDA
sec
@ -97,25 +140,30 @@ SKT.SEND >PULLB hSocket
jsr SKT.GetA
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
cpx #S.SOCKET.SOCK.DGRAM
beq SKT.SEND.UDP
bra *
cpx #S.SOCKET.SOCK.STREAM
bne .99
jmp SKT.SEND.TCP
sec
.99 sec
.9 rts
*--------------------------------------
SKT.SEND.UDP jsr NEW.UDP.FRAME
bcs .9
>STYA ZPFrameBase1
lda #S.UDP
stx hFrame1
lda #S.UDP-2
clc
adc ZPDataLen
sta (ZPFrameBase1)
sta ZPFrameLen1
lda /S.UDP
lda /S.UDP-2
adc ZPDataLen+1
ldy #1
sta (ZPFrameBase1),y
sta ZPFrameLen1+1
ldy #S.SOCKET.SRC.PORT
@ -129,7 +177,7 @@ SKT.SEND.UDP jsr NEW.UDP.FRAME
txa
sta (ZPFrameBase1),y
ldy #S.SOCKET.SRC.ADDR
ldy #S.SOCKET.DST.ADDR
ldx #4
.1 lda (ZPPtrSKT),y
@ -161,63 +209,224 @@ SKT.SEND.UDP jsr NEW.UDP.FRAME
lda #S.UDP
clc
adc ZPFrameBase1
sta ZPTmpPtr1
sta ZPFramePtr1
lda /S.UDP
adc ZPFrameBase1+1
sta ZPTmpPtr1+1
sta ZPFramePtr1+1
ldy #0
.3 jsr DecDataLen
beq .4
lda (ZPDataPtr),y
sta (ZPTmpPtr1),y
sta (ZPFramePtr1),y
iny
bne .3
inc ZPDataPtr
inc ZPTmpPtr1
inc ZPFramePtr1
bra .3
.4 jmp SEND.UDP.FRAME.I
.4 jsr SEND.UDP.FRAME.I
bcc .9
lda hFrame1
>SYSCALL SYS.FreeMemA
sec
.9 rts
*--------------------------------------
SKT.RCVDA
SKT.SEND.TCP
bra *
sec
rts
*--------------------------------------
SKT.RCVD
sec
SKT.RCVDA jsr SKT.GetA
bcs .9
ldy #S.SOCKET.DQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.DQ.HEAD
cmp (ZPPtrSKT),y
beq .99
pha
inc
cmp #S.SOCKET.DQ.MAX
bne .1
lda #0
.1 sta (ZPPtrSKT),y
pla
clc
adc #S.SOCKET.DQ
tay
lda (ZPPtrSKT),y
clc
rts
.99 sec
.9 rts
*--------------------------------------
SKT.CLOSE
sec
rts
SKT.CLOSEA jsr SKT.GetA
bcs .9
cpx #S.SOCKET.SOCK.DGRAM
beq .8
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
bit #S.SOCKET.SO.ACCEPTCONN
beq *
.8 lda #0
sta (ZPPtrSKT)
clc
.9 rts
*--------------------------------------
SKT.GETTABLE >LDYA L.SKT.TABLE
clc
rts
*--------------------------------------
SKT.GetA stz ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
SKT.GetA stz ZPPtrSKT
and #$7f Strip off msb
lsr
ror ZPPtrSKT
lsr
ror ZPPtrSKT
lsr
ror ZPPtrSKT
pha
lda ZPPtrSKT
adc L.SKT.TABLE
sta ZPPtrSKT
lda ZPPtrSKT+1
pla
adc L.SKT.TABLE+1
sta ZPPtrSKT+1
lda (ZPPtrSKT)
beq .9
tax
>LDYA ZPPtrSKT
rts CC
.9 lda #ERR.SBAD
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
*--------------------------------------
SKT.AddToQueueD ldy #S.SOCKET.DQ.HEAD
lda (ZPPtrSKT),y
tax
inc
cmp #S.SOCKET.DQ.MAX
bne .1
lda #0
.1 ldy #S.SOCKET.DQ.TAIL
cmp (ZPPtrSKT),y
beq .9 Queue full!!
ldy #S.SOCKET.DQ.HEAD
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.DQ
tay
lda hFrame1
sta (ZPPtrSKT),y
clc
rts
.9 sec
rts
*--------------------------------------
SKT.AddToQueueS
clc
rts
.9 sec
rts
*--------------------------------------
SKT.TCPSendSYNACKA
jsr SKT.GetA
ldy #S.SOCKET.SRC.ADDR+3
ldx #3
.1 lda (ZPPtrSKT),y
sta TCP.MSG+S.IP.SRC,x
dey
dex
bpl .1
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.SRCPORT+1
iny
lda (ZPPtrSKT),y
sta TCP.MSG+S.TCP.SRCPORT
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
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
lda #S.TCP.OPTIONS.SYN+S.TCP.OPTIONS.ACK
sta TCP.MSG+S.TCP.OPTIONS
>PUSHW L.TCP.MSG
jsr SEND.TCP.FRAME
clc
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.SKT
LOAD LIB/LIBTCPIP.S

View File

@ -5,9 +5,278 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
TCP.IN clc
TCP.IN ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.TCP.SRCPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
ldy #S.TCP.DSTPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
>STYA ZPPtrSKT
ldx #0
.3 lda (ZPPtrSKT)
beq .7
cmp #S.SOCKET.SOCK.STREAM
bne .7
ldy #S.SOCKET.SRC.ADDR
.4 lda TmpSocket,y
cmp (ZPPtrSKT),y
bne .7 Not for this socket...
iny
cpy #S.SOCKET.SRC.PORT+2
bne .4
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN Listening socket?
beq .5
ldy #S.TCP.OPTIONS yes, only accept SYN packet
lda (ZPFrameBase1),y
cmp #S.TCP.OPTIONS.SYN
bne .7 not for this listening socket
jmp TCP.IN.LISTEN.NEW
.5 ldy #S.SOCKET.DST.ADDR
.6 lda TmpSocket,y regular socket, check remote ADDR/PORT
cmp (ZPPtrSKT),y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .6
jmp TCP.IN.ESTABLISHED
.7 lda ZPPtrSKT
clc
adc #S.SOCKET
sta ZPPtrSKT
bcc .8
inc ZPPtrSKT+1
.8 inx
cpx #K.SKTTABLE.SIZE
bne .3
clc Discard frame
rts
.9 sec
*--------------------------------------
TCP.IN.LISTEN.NEW
lda #S.SOCKET.SOCK.STREAM
sta TmpSocket
stz TmpSocket+S.SOCKET.SO
ldy #S.TCP.SEQ.NUMBER+3
ldx #3
sec
.1 lda (ZPFrameBase1),y
adc #0
sta TmpSocket+S.SOCKET.SQ.ACKNUM,x
dey
dex
bpl .1
ldx #3
.2 lda A2osX.TIMER16,x
sta TmpSocket+S.SOCKET.SQ.SEQNUM,x
dex
bpl .2
>PUSHW L.TmpSocket
jsr SKT.NEW
bcs .9
txa
ldy #S.SOCKET.PARENT
sta (ZPPtrSKT),y
jsr SKT.TCPSendSYNACKA
ldy #S.SOCKET.STATUS
lda #S.SOCKET.STATUS.SYNRCVD
sta (ZPPtrSKT),y
clc
.9 rts
*--------------------------------------
TCP.IN.ESTABLISHED
stx hSocket
ldy #S.SOCKET.STATUS
lda (ZPPtrSKT),y
cmp #S.SOCKET.STATUS.SYNRCVD Waiting for ACK to establish?
bne .1
ldy #S.TCP.OPTIONS yes, only accept ACK packet
lda (ZPFrameBase1),y
cmp #S.TCP.OPTIONS.ACK
bne .8
ldx #3
ldy #S.SOCKET.SQ.SEQNUM+3
sec
.10 lda (ZPPtrSKT),y
adc #0
sta TmpDWord,x
dey
dex
bpl .10
ldx #3
ldy #S.TCP.ACK.NUMBER+3
.11 lda (ZPFrameBase1),y
cmp TmpDWord,x
bne .8
dey
dex
bpl .11
ldx #3
ldy #S.SOCKET.SQ.SEQNUM+3
.12 lda TmpDWord,x
sta (ZPPtrSKT),y
dey
dex
bpl .12
ldy #S.SOCKET.STATUS
lda #S.SOCKET.STATUS.ESTBLSH
sta (ZPPtrSKT),y
ldy #S.SOCKET.PARENT
lda (ZPPtrSKT),y
jsr SKT.GetA
lda hSocket
jsr SKT.AddToQueueL
.8 clc
rts
.1 cmp #S.SOCKET.STATUS.ESTBLSH
bne .99
bra *
.99 clc
rts
*--------------------------------------
TCP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.TCP.CHECKSUM
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
>STYA ZPTmpPtr1
lda ZPFrameLen1
sec
sbc #S.IP-2
sta ZPDataLen
lda ZPFrameLen1+1
sbc /S.IP-2
sta ZPDataLen+1
clc
* lda ZPDataLen+1
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
lda ZPDataLen
adc #S.IP.PROTOCOL.TCP
sta IP.CHECKSUM+1
ldy #S.IP.SRC
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameBase1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .10
ldy #S.IP
.1 jsr DecDataLen
beq .8
lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataLen
bne .2
lda #0
bra .21
.2 lda (ZPTmpPtr1),y
.21 adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
bne .1
inc ZPTmpPtr1+1
bra .1
.8 ldy #S.TCP.CHECKSUM
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
rts
*--------------------------------------
MAN

View File

@ -5,8 +5,161 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
UDP.IN
UDP.IN ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.UDP.SRCPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
ldy #S.UDP.DSTPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
>STYA ZPPtrSKT
ldx #0
.3 lda (ZPPtrSKT)
beq .7
cmp #S.SOCKET.SOCK.DGRAM
bne .7
ldy #S.SOCKET.SRC.ADDR
.4 lda TmpSocket,y
cmp (ZPPtrSKT),y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .4
jsr SKT.AddToQueueD
bcs .99
lda (pEvent) Make sure kernel not discard frame...
and #$FF^S.EVT.F.hMEM1
sta (pEvent)
clc ...when clearing event!!!!
rts
.7 lda ZPPtrSKT
clc
adc #S.SOCKET
sta ZPPtrSKT
bcc .8
inc ZPPtrSKT+1
.8 inx
cpx #K.SKTTABLE.SIZE
bne .3
.9 sec
.99 rts
*--------------------------------------
UDP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.UDP.CHECKSUM
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
>STYA ZPTmpPtr1
lda ZPFrameLen1
sec
sbc #S.IP-2
sta ZPDataLen
lda ZPFrameLen1+1
sbc /S.IP-2
sta ZPDataLen+1
clc
ldy #S.UDP.LENGTH
lda (ZPFrameBase1),y
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc #S.IP.PROTOCOL.UDP
sta IP.CHECKSUM+1
ldy #S.IP.SRC
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameBase1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .10
ldy #S.IP
.1 jsr DecDataLen
beq .8
lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataLen
bne .2
lda #0
bra .21
.2 lda (ZPTmpPtr1),y
.21 adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
bne .1
inc ZPTmpPtr1+1
bra .1
.8 ldy #S.UDP.CHECKSUM
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
rts
*--------------------------------------
MAN

View File

@ -15,17 +15,15 @@ AUTO 6
ZPFrameBase1 .EQ ZPLIB
ZPFrameLen1 .EQ ZPLIB+2
ZPFramePtr1 .EQ ZPLIB+4
ZPFrameBase2 .EQ ZPBIN+6
ZPFrameLen2 .EQ ZPBIN+8
ZPFramePtr2 .EQ ZPBIN+10
ZPPtrIP .EQ ZPLIB+12
ZPPtrMAC .EQ ZPLIB+14
ZPPtrDNS .EQ ZPLIB+16
ZPPtrSKT .EQ ZPLIB+18
ZPTmpPtr1 .EQ ZPLIB+20
ZPTmpPtr2 .EQ ZPLIB+22
ZPDataPtr .EQ ZPLIB+24
ZPDataLen .EQ ZPLIB+26
ZPTmpPtr3 .EQ ZPLIB+24
ZPDataPtr .EQ ZPLIB+26
ZPDataLen .EQ ZPLIB+28
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
@ -71,32 +69,47 @@ CS.START cld
.DA DNS.ADD
.DA DNS.GETCACHE
.DA ARP.IN
.DA IP.IN
.DA RCVD.FRAMEA
.DA RCVD.FRAME
.DA SKT.NEW
.DA SKT.LISTEN
.DA SKT.ACCEPT
.DA $FFFF
.DA SKT.ACCEPTA
.DA SKT.SENDA
.DA SKT.SEND
.DA SKT.RCVDA
.DA SKT.RCVD
.DA SKT.CLOSE
.DA $FFFF
.DA SKT.CLOSEA
.DA SKT.GETTABLE
.DA SKT.GETA
.DA HST.GETBYNAME
.DA HST.GETBYADDR
*--------------------------------------
L.IPCFG .DA IPCFG
L.ARP.REQ .DA ARP.REQ
L.ARP.REP .DA ARP.REP
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.SKT.TABLE .DA SKT.TABLE
L.TmpMAC .DA TmpMAC
L.TmpIP .DA TmpIP
L.TmpSocket .DA TmpSocket
L.TCP.MSG .DA TCP.MSG
.DA 0
*--------------------------------------
LIB.LOAD lda bFirstLoad
bne .8
jsr ARP.CLEAR
jsr DNS.CLEAR
>LDYA K.DYNPORT.START
>LDYAI K.DYNPORT.START
>STYA DYNPORT.LAST
inc bFirstLoad
.8 clc
rts
*--------------------------------------
@ -113,6 +126,23 @@ SET.IPCFG >PULLW ZPTmpPtr1
cpy #S.IPCFG
bne .1
ldx #5
.2 lda IPCFG+S.IPCFG.MAC,x
sta ARP.REQ.SRCMAC,x
sta ARP.REQ.SHA,x
sta ARP.REP.SRCMAC,x
sta ARP.REP.SHA,x
dex
bpl .2
ldx #3
.3 lda IPCFG+S.IPCFG.IP,x
sta ARP.REQ.SPA,x
sta ARP.REP.SPA,x
sta DNS.SOCKET.SA,x
dex
bpl .3
lda IPCFG+S.IPCFG.HDEV
>SYSCALL SYS.GetDevByIDA
@ -125,16 +155,54 @@ SET.IPCFG >PULLW ZPTmpPtr1
ldy #S.DEVINFO.FLAGS
lda (ZPTmpPtr2),y
sta DevFlags
and #S.DEVINFO.FLAGS.ARPOFFLOAD
beq .2
and #S.DEVINFO.NET.FLAGS.ARPOFFLOAD
beq .4
>LDYA ZPTmpPtr1
ldx #DEVMGR.SETIPCFG
jsr NetDevJmp
.2 >LDYA ZPTmpPtr1
.4 lda hDNSSocket1
beq .41
jsr SKT.CLOSEA
.41 lda hDNSSocket2
beq .42
jsr SKT.CLOSEA
.42 lda IPCFG+S.IPCFG.DNS1
beq .6
ldx #3
.5 lda IPCFG+S.IPCFG.DNS1,x
sta DNS.SOCKET.DA,x
dex
bpl .5
>PUSHW L.DNS.SOCKET
jsr SKT.NEW
bcs .9
stx hDNSSocket1
.6 lda IPCFG+S.IPCFG.DNS2
beq .8
ldx #3
.7 lda IPCFG+S.IPCFG.DNS2,x
sta DNS.SOCKET.DA,x
dex
bpl .7
>PUSHW L.DNS.SOCKET
jsr SKT.NEW
bcs .9
stx hDNSSocket2
.8 >LDYA ZPTmpPtr1
clc
rts
.9 rts
*--------------------------------------
* grab a copy on the fly for lib function
* OUT :
@ -151,28 +219,6 @@ ToLowerCaseA cmp #'A'
adc #$20
.1 rts
*--------------------------------------
MakeIPReply >LDAXI S.IP.SRC
jsr SetFramePtr1AX
>LDAXI S.IP.DST
jsr SetFramePtr2AX
ldy #4
jsr CopyFramePtr12
>LDAXI S.IP.DST
jsr SetFramePtr1AX
>LDAXI S.IP.SRC
jsr SetFramePtr2AX
ldy #4
jsr CopyFramePtr12
>LDAXI S.ETH.SRCMAC
jsr SetFramePtr1AX
>LDAXI S.ETH.DSTMAC
jsr SetFramePtr2AX
ldy #6
jsr CopyFramePtr12
rts
*--------------------------------------
* A,X = Frame PTR
*--------------------------------------
SetFramePtr1AX clc
@ -183,25 +229,6 @@ SetFramePtr1AX clc
sta ZPFramePtr1+1
rts
*--------------------------------------
* A,X = Frame PTR
*--------------------------------------
SetFramePtr2AX clc
adc ZPFrameBase2
sta ZPFramePtr2
txa
adc ZPFrameBase2+1
sta ZPFramePtr2+1
rts
*--------------------------------------
* Y = bytes to copy from ZPFramePtr1 to ZPFramePtr2
*--------------------------------------
CopyFramePtr12 dey
lda (ZPFramePtr1),y
sta (ZPFramePtr2),y
tya
bne CopyFramePtr12
rts
*--------------------------------------
GetDynPort inc DYNPORT.LAST
bne .1
inc DYNPORT.LAST+1
@ -211,7 +238,7 @@ GetDynPort inc DYNPORT.LAST
lda DYNPORT.LAST+1
sbc /K.DYNPORT.END
bcs .1
>LDAXI K.DYNPORT.END
>LDAXI K.DYNPORT.START
>STAX DYNPORT.LAST
rts CC
@ -219,52 +246,6 @@ GetDynPort inc DYNPORT.LAST
clc
rts
*--------------------------------------
PSTR2DNSHostName >STYA ZPTmpPtr1
lda (ZPTmpPtr1)
beq .9
cmp #K.DNS.MAXLEN-1
bcs .9
tay
inc
sta DNSHostNameLen
lda #0 Ending 0
sta DNSHostName+1,y
ldx #0
.1 lda (ZPTmpPtr1),y
and #$7f
cmp #'.'
beq .2
cmp #'A'
bcc .10
cmp #'Z'+1
bcs .10
adc #$20
.10 inx
bra .3
.2 txa
ldx #0
.3 sta DNSHostName,y
dey
bne .1
stx DNSHostName
clc
rts
.9 sec
rts
*--------------------------------------
DecDataLen lda ZPDataLen
bne .1
lda ZPDataLen+1
@ -284,27 +265,100 @@ NetDevJmp jmp *
.INB LIB/LIBTCPIP.S.TCP
.INB LIB/LIBTCPIP.S.DNS
.INB LIB/LIBTCPIP.S.SKT
.INB LIB/LIBTCPIP.S.HST
*--------------------------------------
CS.END
*--------------------------------------
IPCFG .BS S.IPCFG
*--------------------------------------
ARP.REQ .DA S.ARP-2 Frame size
ARP.REQ.DSTMAC .HS FFFFFFFFFFFF
ARP.REQ.SRCMAC .BS 6
ARP.REQ.ETYPE .DA /S.ETH.ETHERTYPE.ARP
.DA #S.ETH.ETHERTYPE.ARP
.HS 0001.0800.06.04
ARP.REQ.OP .DA /S.ARP.OPERATION.REQ
.DA #S.ARP.OPERATION.REQ
ARP.REQ.SHA .BS 6
ARP.REQ.SPA .BS 4
ARP.REQ.THA .BS 6
ARP.REQ.TPA .BS 4
*--------------------------------------
ARP.REP .DA S.ARP-2 Frame size
ARP.REP.DSTMAC .BS 6
ARP.REP.SRCMAC .BS 6
ARP.REP.ETYPE .DA /S.ETH.ETHERTYPE.ARP
.DA #S.ETH.ETHERTYPE.ARP
.HS 0001.0800.06.04
ARP.REP.OP .DA /S.ARP.OPERATION.REP
.DA #S.ARP.OPERATION.REP
ARP.REP.SHA .BS 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
DNS.SOCKET.SP .DA 0 Dynamic
DNS.SOCKET.DA .BS 4
DNS.SOCKET.DP .DA UDP.PORT.DNS
.BS 16
*--------------------------------------
DNS.MSG.LEN .BS 2
DNS.MSG .BS 2 ID
.DA /S.DNS.F.RD Flags=query
.DA #S.DNS.F.RD Flags=query
.DA $100 QDCOUNT
.BS 6 ANCOUNT,NSCOUNT,ARCOUNT
.BS K.DNS.MAXLEN+6 DNS.MSG+12
*--------------------------------------
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET
*--------------------------------------
bFirstLoad .DA #0
Status .BS 1
DevFlags .BS 1
DNSMessageID .BS 2
DNSDynamicPort .BS 2
hDNSSocket1 .BS 1
hDNSSocket2 .BS 1
DNSHostTTL .BS 4
DNSHostName .BS K.DNS.MAXLEN+1
DNSHostNameLen .BS 1
DNSHostName .BS K.DNS.MAXLEN+1
IP.CHECKSUM .BS 4
IPCFG .BS S.IPCFG
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET
TmpMAC .BS 6
TmpIP .BS 4
TmpDWord .BS 4
TmpSocket .BS S.SOCKET
hFrame1 .BS 1
hSocket .BS 1
bFound .BS 1
DYNPORT.LAST .BS 2
*TmpCounter .BS 2
TmpOffset .BS 2
HST.DecStr .BS 4
HST.IP .BS 5
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S