Moved All TCPIP Code from TCPIP.DRV to LIBTCPIP

This commit is contained in:
Rémy GIBERT 2016-01-16 23:04:22 +01:00
parent 089fd82dc0
commit 8d4759f663
9 changed files with 980 additions and 430 deletions

View File

@ -5,6 +5,94 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
ARP.IN >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
ldy #S.ARP.TPA
ldx #S.IPCFG.IP
.1 lda (ZPFrameBase1),y
cmp IPCFG,x
bne .9
iny
inx
cpx #S.IPCFG.IP+4
bne .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameBase1),y
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
cmp #S.ARP.OPERATION.REP
beq ARP.IN.REP
.9 clc Discard any other ARP frames
rts
ARP.IN.REP >LDAXI S.ARP.SHA
jsr SetFramePtr1AX
>PUSHW ZPFramePtr1
>LDAXI S.ARP.SPA
jsr SetFramePtr1AX
>PUSHW ZPFramePtr1
jsr ARP.ADD
clc
ARP.IN.RTS rts
ARP.IN.REQ jsr NEW.ARP.FRAME
bcs ARP.IN.RTS
phx
>STYA ZPFrameBase2
ldy #S.ARP.OPERATION+1
lda #S.ARP.OPERATION.REP
sta (ZPFrameBase2),y
>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
>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
*--------------------------------------
* ARP.CLEAR
*--------------------------------------
ARP.CLEAR ldx #K.ARPCACHE.SIZE*S.ARPCACHE

View File

@ -5,6 +5,42 @@ 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
@ -155,7 +191,7 @@ DNS.REQUEST jsr NEW.UDP.FRAME
adc /S.DNS
sta ZPFrameLen1+1
ldx #S.IPCFG.DNS
ldx #S.IPCFG.DNS1
ldy #S.IP.DST
lda IPCFG,x
@ -165,12 +201,12 @@ DNS.REQUEST jsr NEW.UDP.FRAME
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS+4
cpx #S.IPCFG.DNS1+4
bne .4
jsr SEND.UDP.FRAME.I
bcs .8
.5 ldx #S.IPCFG.DNS+4
.5 ldx #S.IPCFG.DNS2
ldy #S.IP.DST
lda IPCFG,x
@ -180,7 +216,7 @@ DNS.REQUEST jsr NEW.UDP.FRAME
sta (ZPFrameBase1),y
iny
inx
cpx #S.IPCFG.DNS+8
cpx #S.IPCFG.DNS2+4
bne .6
jsr SEND.UDP.FRAME.I
bcs .8
@ -320,54 +356,6 @@ DNS.GETCACHE >LDYA L.DNS.CACHE
clc
rts
*--------------------------------------
* PRIVATE
*--------------------------------------
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
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.DNS

269
LIB/LIBTCPIP.S.FRM.txt Normal file
View File

@ -0,0 +1,269 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ICMP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.ICMP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.TCP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.TCP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.UDP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.UDP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.IP.FRAME jsr NEW.ETH.FRAME
bcs .9
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP
sta (ZPFrameBase1),y
iny
lda #S.ETH.ETHERTYPE.IP
sta (ZPFrameBase1),y
ldy #S.IP.V.IHL.DSCP.ECN
lda #$45
sta (ZPFrameBase1),y
iny
lda #$0
sta (ZPFrameBase1),y
ldy #S.IP.IDENTIFICATION
sta (ZPFrameBase1),y
inc
iny
sta (ZPFrameBase1),y
dec
ldy #S.IP.FRAGMENT.FLAGS
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
ldy #S.IP.TTL
lda #K.IP.TTL
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ARP.FRAME jsr NEW.ETH.FRAME
bcs .9
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
iny
lda #S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
ldy #S.ARP.HTYPE
lda #0
sta (ZPFrameBase1),y
iny
lda #1
sta (ZPFrameBase1),y
iny
lda #8
sta (ZPFrameBase1),y
iny
lda #0
sta (ZPFrameBase1),y
iny
lda #6
sta (ZPFrameBase1),y
iny
lda #4
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
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
bcs .9
>STYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.ICMP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
>PUSHW ZPFrameLen1
>PUSHWI S.ICMP.TYPE
jsr IP.ComputeChecksum
phy
ldy #S.ICMP.CHECKSUM
sta (ZPFrameBase1),y
iny
pla
sta (ZPFrameBase1),y
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.TCP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.UDP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
SEND.UDP.FRAME.I
ldy #S.UDP.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.IP
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
sta (ZPFrameBase1),y
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.IP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
SEND.IP.FRAME.I ldx #S.IPCFG.IP
ldy #S.IP.SRC
.10 lda IPCFG,x
sta (ZPFrameBase1),y
inx
iny
cpy #S.IP.SRC+4
bne .10
jsr ARP.RESOLVE
bcs .9
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.ETH
sta (ZPFrameBase1),y
dey
lda ZPFrameLen1+1
sbc /S.ETH
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
ldy #S.IP.V.IHL.DSCP.ECN
.1 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
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
*--------------------------------------
* 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
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.FRM
LOAD LIB/LIBTCPIP.S
ASM

54
LIB/LIBTCPIP.S.ICMP.txt Normal file
View File

@ -0,0 +1,54 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
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
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
pla
>SYSCALL SYS.FreeMemA
clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.ICMP
LOAD LIB/LIBTCPIP.S
ASM

101
LIB/LIBTCPIP.S.IP.txt Normal file
View File

@ -0,0 +1,101 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
IP.IN >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
ldy #S.IP.PROTOCOL
lda (ZPFrameBase1),y
cmp #S.IP.PROTOCOL.ICMP
bne .2
jmp ICMP.IN
.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
.3 cmp #S.IP.PROTOCOL.TCP
bne .9
jmp TCP.IN
.9 sec
rts
*--------------------------------------
* In:
* PULLW = Start Offset
* PULLW = End Offset
* Out:
* Y,A = CheckSum
*--------------------------------------
IP.ComputeChecksum
>PULLA
clc
adc ZPFrameBase1
sta ZPTmpPtr1
>PULLA
adc ZPFrameBase1+1
sta ZPTmpPtr1+1
>PULLA
clc
adc ZPFrameBase1
sta TmpOffset
>PULLA
adc ZPFrameBase1+1
sta TmpOffset+1
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
stz IP.CHECKSUM+2
stz IP.CHECKSUM+3
ldy #1
.1 lda (ZPTmpPtr1),y
clc
adc IP.CHECKSUM
sta IP.CHECKSUM
lda (ZPTmpPtr1)
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
sta ZPTmpPtr1
bcc .4
inc ZPTmpPtr1+1
.4 cmp TmpOffset
bne .1
lda ZPTmpPtr1+1
cmp TmpOffset+1
bne .1
lda IP.CHECKSUM
clc
adc IP.CHECKSUM+2
eor #$FF
tay
lda IP.CHECKSUM+1
adc IP.CHECKSUM+3
eor #$FF
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.IP
LOAD LIB/LIBTCPIP.S
ASM

224
LIB/LIBTCPIP.S.SKT.txt Normal file
View File

@ -0,0 +1,224 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
SKT.NEW >PULLW ZPPtrSKT
stz bFound
ldy #S.SOCKET.SRC.PORT+1
lda (ZPPtrSKT),y
dey
ora (ZPPtrSKT),y
bne .1
jsr GetDynPort
sta (ZPPtrSKT),y
txa
iny
sta (ZPPtrSKT),y
.1 >LDYA L.SKT.TABLE
>STYA ZPTmpPtr1
ldx #0
.2 lda (ZPTmpPtr1)
beq .4
ldy #S.SOCKET.SRC.PORT+1
.3 lda (ZPPtrSKT),y
cmp (ZPTmpPtr1),y
bne .5
dey
bpl .3
lda ERR.SBUSY
sec
rts
.4 bit bFound
bmi .5
sec
ror bFound
stx hSocket
>LDYA ZPTmpPtr1
>STYA ZPTmpPtr2
.5 lda ZPTmpPtr1
clc
adc #S.SOCKET
sta ZPTmpPtr1
bcc .6
inc ZPTmpPtr1+1
.6 inx
cpx #K.SKTTABLE.SIZE
bne .2
bit bFound
bpl .9
ldy #S.SOCKET-1
.7 lda (ZPPtrSKT),y
sta (ZPTmpPtr2),y
dey
bpl .7
lda hSocket
clc
rts
.9 lda ERR.OOS
sec
rts
*--------------------------------------
SKT.LISTEN
sec
rts
*--------------------------------------
SKT.ACCEPT
sec
rts
*--------------------------------------
SKT.SENDA
sec
rts
*--------------------------------------
SKT.SEND >PULLB hSocket
pha
>PULLW ZPDataPtr
>PULLW ZPDataLen
pla
jsr SKT.GetA
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
beq SKT.SEND.UDP
bra *
sec
.9 rts
*--------------------------------------
SKT.SEND.UDP jsr NEW.UDP.FRAME
bcs .9
>STYA ZPFrameBase1
lda #S.UDP
clc
adc ZPDataLen
sta ZPFrameLen1
lda /S.UDP
adc ZPDataLen+1
sta ZPFrameLen1+1
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.SRCPORT
sta (ZPFrameBase1),y
iny
txa
sta (ZPFrameBase1),y
ldy #S.SOCKET.SRC.ADDR
ldx #4
.1 lda (ZPPtrSKT),y
pha
iny
dex
bne .1
ldy #S.IP.DST+3
ldx #4
.2 pla
sta (ZPFrameBase1),y
dey
dex
bne .2
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.DSTPORT
sta (ZPFrameBase1),y
iny
txa
sta (ZPFrameBase1),y
lda #S.UDP
clc
adc ZPFrameBase1
sta ZPTmpPtr1
lda /S.UDP
adc ZPFrameBase1+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 SEND.UDP.FRAME.I
.9 rts
*--------------------------------------
SKT.RCVDA
sec
rts
*--------------------------------------
SKT.RCVD
sec
rts
*--------------------------------------
SKT.CLOSE
sec
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
adc L.SKT.TABLE
sta ZPPtrSKT
lda ZPPtrSKT+1
adc L.SKT.TABLE+1
sta ZPPtrSKT+1
lda (ZPPtrSKT)
beq .9
rts CC
.9 lda #ERR.SBAD
sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.SKT
LOAD LIB/LIBTCPIP.S
ASM

16
LIB/LIBTCPIP.S.TCP.txt Normal file
View File

@ -0,0 +1,16 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
TCP.IN clc
rts
.9 sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.TCP
LOAD LIB/LIBTCPIP.S
ASM

15
LIB/LIBTCPIP.S.UDP.txt Normal file
View File

@ -0,0 +1,15 @@
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
UDP.IN
.9 sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.UDP
LOAD LIB/LIBTCPIP.S
ASM

View File

@ -15,11 +15,17 @@ AUTO 6
ZPFrameBase1 .EQ ZPLIB
ZPFrameLen1 .EQ ZPLIB+2
ZPFramePtr1 .EQ ZPLIB+4
ZPPtrIP .EQ ZPLIB+6
ZPPtrMAC .EQ ZPLIB+8
ZPPtrDNS .EQ ZPLIB+10
ZPTmpPtr1 .EQ ZPLIB+12
ZPTmpPtr2 .EQ ZPLIB+14
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
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
@ -65,21 +71,31 @@ CS.START cld
.DA DNS.ADD
.DA DNS.GETCACHE
.DA UDP.LISTENER
.DA TCP.LISTENER
.DA ADD.LISTENER
.DA REM.LISTENER
.DA ARP.IN
.DA IP.IN
.DA SKT.NEW
.DA SKT.LISTEN
.DA SKT.ACCEPT
.DA SKT.SENDA
.DA SKT.SEND
.DA SKT.RCVDA
.DA SKT.RCVD
.DA SKT.CLOSE
.DA SKT.GETTABLE
*--------------------------------------
L.IPCFG .DA IPCFG
L.ARP.CACHE .DA ARP.CACHE
L.DNS.CACHE .DA DNS.CACHE
L.SKT.TABLE .DA SKT.TABLE
.DA 0
*--------------------------------------
LIB.LOAD lda bFirstLoad
bne .8
jsr ARP.CLEAR
jsr DNS.CLEAR
jsr DYN.CLEAR
>LDYA K.DYNPORT.START
>STYA DYNPORT.LAST
inc bFirstLoad
.8 clc
rts
@ -89,27 +105,16 @@ LIB.UNLOAD clc
*--------------------------------------
* PULLW = PTR to S.IPCFG
*--------------------------------------
SET.IPCFG >PUSHBI K.PROTOID.IP
>SYSCALL SYS.SetNetCfg
bcs GET.IPCFG.RTS
*--------------------------------------
* grab a copy on the fly for lib function
* OUT :
* Y,A = PTR to S.IPCFG
*--------------------------------------
GET.IPCFG lda #K.PROTOID.IP
>SYSCALL SYS.GetNetCfgA
bcs GET.IPCFG.RTS
>STYA ZPTmpPtr1
ldy #S.IPCFG
.1 dey
lda (ZPTmpPtr1),y
SET.IPCFG >PULLW ZPTmpPtr1
ldy #0
.1 lda (ZPTmpPtr1),y
sta IPCFG,y
tya
iny
cpy #S.IPCFG
bne .1
ldx #S.IPCFG.HDEV
lda IPCFG,x
lda IPCFG+S.IPCFG.HDEV
>SYSCALL SYS.GetDevByIDA
>STYA NetDevJmp+1
@ -128,296 +133,16 @@ GET.IPCFG lda #K.PROTOID.IP
jsr NetDevJmp
.2 >LDYA ZPTmpPtr1
clc
GET.IPCFG.RTS rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ICMP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.ICMP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.TCP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.TCP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.UDP.FRAME jsr NEW.IP.FRAME
bcs .9
ldy #S.IP.PROTOCOL
lda #S.IP.PROTOCOL.UDP
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.IP.FRAME jsr NEW.ETH.FRAME
bcs .9
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP
sta (ZPFrameBase1),y
iny
lda #S.ETH.ETHERTYPE.IP
sta (ZPFrameBase1),y
ldy #S.IP.V.IHL.DSCP.ECN
lda #$45
sta (ZPFrameBase1),y
iny
lda #$0
sta (ZPFrameBase1),y
ldy #S.IP.IDENTIFICATION
sta (ZPFrameBase1),y
inc
iny
sta (ZPFrameBase1),y
dec
ldy #S.IP.FRAGMENT.FLAGS
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
ldy #S.IP.TTL
lda #K.IP.TTL
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ARP.FRAME jsr NEW.ETH.FRAME
bcs .9
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
iny
lda #S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
ldy #S.ARP.HTYPE
lda #0
sta (ZPFrameBase1),y
iny
lda #1
sta (ZPFrameBase1),y
iny
lda #8
sta (ZPFrameBase1),y
iny
lda #0
sta (ZPFrameBase1),y
iny
lda #6
sta (ZPFrameBase1),y
iny
lda #4
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
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
bcs .9
>STYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.ICMP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
>PUSHW ZPFrameLen1
>PUSHWI S.ICMP.TYPE
jsr ComputeChecksum
phy
ldy #S.ICMP.CHECKSUM
sta (ZPFrameBase1),y
iny
pla
sta (ZPFrameBase1),y
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.TCP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.UDP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
SEND.UDP.FRAME.I
ldy #S.UDP.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.IP
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
sta (ZPFrameBase1),y
bra SEND.IP.FRAME.I
*--------------------------------------
* In:
* Out:
*--------------------------------------
SEND.IP.FRAME >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
SEND.IP.FRAME.I ldx #S.IPCFG.IP
ldy #S.IP.SRC
.10 lda IPCFG,x
sta (ZPFrameBase1),y
inx
iny
cpy #S.IP.SRC+4
bne .10
jsr ARP.RESOLVE
bcs .9
ldy #S.IP.TOTAL.LENGTH+1
lda ZPFrameLen1
sec
sbc #S.ETH
sta (ZPFrameBase1),y
dey
lda ZPFrameLen1+1
sbc /S.ETH
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
ldy #S.IP.V.IHL.DSCP.ECN
.1 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
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
*--------------------------------------
* 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
rts
*--------------------------------------
UDP.LISTENER >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
sec
* grab a copy on the fly for lib function
* OUT :
* Y,A = PTR to S.IPCFG
*--------------------------------------
GET.IPCFG >LDYA L.IPCFG
clc
rts
*--------------------------------------
TCP.LISTENER >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
sec
rts
*--------------------------------------
ADD.LISTENER sec
rts
*--------------------------------------
REM.LISTENER sec
rts
*--------------------------------------
DYN.CLEAR
*--------------------------------------
DYN.GET
*--------------------------------------
DYN.RELEASE
*--------------------------------------
.INB LIB/LIBTCPIP.S.ARP
.INB LIB/LIBTCPIP.S.DNS
*--------------------------------------
* PRIVATE
*--------------------------------------
*--------------------------------------
ToLowerCaseA cmp #'A'
bcc .1
@ -426,67 +151,139 @@ ToLowerCaseA cmp #'A'
adc #$20
.1 rts
*--------------------------------------
* In:
* PULLW = Start Offset
* PULLW = End Offset
* Out:
* Y,A = CheckSum
*--------------------------------------
ComputeChecksum >PULLA
clc
adc ZPFrameBase1
sta ZPTmpPtr1
>PULLA
adc ZPFrameBase1+1
sta ZPTmpPtr1+1
>PULLA
clc
adc ZPFrameBase1
sta TmpOffset
>PULLA
adc ZPFrameBase1+1
sta TmpOffset+1
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
stz IP.CHECKSUM+2
stz IP.CHECKSUM+3
MakeIPReply >LDAXI S.IP.SRC
jsr SetFramePtr1AX
>LDAXI S.IP.DST
jsr SetFramePtr2AX
ldy #4
jsr CopyFramePtr12
ldy #1
.1 lda (ZPTmpPtr1),y
clc
adc IP.CHECKSUM
sta IP.CHECKSUM
lda (ZPTmpPtr1)
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
sta ZPTmpPtr1
bcc .4
inc ZPTmpPtr1+1
.4 cmp TmpOffset
bne .1
lda ZPTmpPtr1+1
cmp TmpOffset+1
bne .1
lda IP.CHECKSUM
clc
adc IP.CHECKSUM+2
eor #$FF
tay
lda IP.CHECKSUM+1
adc IP.CHECKSUM+3
eor #$FF
>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
adc ZPFrameBase1
sta ZPFramePtr1
txa
adc ZPFrameBase1+1
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
lda DYNPORT.LAST
sec
sbc #K.DYNPORT.END
lda DYNPORT.LAST+1
sbc /K.DYNPORT.END
bcs .1
>LDAXI K.DYNPORT.END
>STAX DYNPORT.LAST
rts CC
.1 >LDAX 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
beq .9
dec ZPDataLen+1
.1 dec ZPDataLen
lda #$FF Make NZ
.9 rts
*--------------------------------------
NetDevJmp jmp *
*--------------------------------------
.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.DNS
.INB LIB/LIBTCPIP.S.SKT
*--------------------------------------
CS.END
*--------------------------------------
@ -502,12 +299,10 @@ IP.CHECKSUM .BS 4
IPCFG .BS S.IPCFG
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
UDP.TABLE .BS K.UDPTABLE.SIZE*S.LISTENER
TCP.TABLE .BS K.TCPTABLE.SIZE*S.LISTENER
DYNPORT.UDP.LAST .BS 2
DYNPORT.TCP.LAST .BS 2
DYNPORT.UDP .BS K.DYNPORT.MAX*4
DYNPORT.TCP .BS K.DYNPORT.MAX*4
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET
hSocket .BS 1
bFound .BS 1
DYNPORT.LAST .BS 2
*TmpCounter .BS 2
TmpOffset .BS 2
*--------------------------------------