A2osX/LIB/LIBTCPIP.S.txt
2015-03-15 23:00:40 +01:00

483 lines
10 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF LIB/LIBTCPIP.O
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/KERNEL.I
.INB INC/LIBTCPIP.I
*--------------------------------------
ZPFrameBase1 .EQ ZPLIB
ZPFrameLen1 .EQ ZPLIB+2
ZPFramePtr1 .EQ ZPLIB+4
ZPARPIP .EQ ZPLIB+6
ZPARPMAC .EQ ZPLIB+8
ZPDNSHostname .EQ ZPLIB+10
ZPDNSIP .EQ ZPLIB+12
*--------------------------------------
* Main entry point
* input :
* X = Function
*--------------------------------------
* Code signature and relocation table
*--------------------------------------
* CLD $D8
* JMP (*,x) $7C
* #JMPTABLE
* /JMPTABLE
*--------------------------------------
CS.START cld
jmp (.1,x)
.1 .DA LIB.LOAD
.DA LIB.UNLOAD
.DA SET.IPCFG
.DA GET.IPCFG
.DA NEW.ICMP.FRAME
.DA NEW.TCP.FRAME
.DA NEW.UDP.FRAME
.DA NEW.IP.FRAME
.DA NEW.ARP.FRAME
.DA NEW.ETH.FRAME
.DA SEND.ICMP.FRAME
.DA SEND.TCP.FRAME
.DA SEND.UDP.FRAME
.DA SEND.IP.FRAME
.DA SEND.ARP.FRAME
.DA SEND.ETH.FRAME
.DA ARP.CLEAR
.DA ARP.QUERY
.DA ARP.ADD
.DA ARP.GETCACHE
.DA DNS.CLEAR
.DA DNS.QUERY
.DA DNS.ADD
.DA DNS.GETCACHE
.DA UDP.LISTENER
.DA TCP.LISTENER
.DA ADD.LISTENER
.DA REM.LISTENER
*--------------------------------------
L.IPCFG .DA IPCFG
L.ARP.CACHE .DA ARP.CACHE
L.DNS.CACHE .DA DNS.CACHE
.DA 0
.DA CS.END-CS.START
.DA DS.END-DS.START
*--------------------------------------
LIB.LOAD lda bFirstLoad
bne .8
jsr ARP.CLEAR
jsr DNS.CLEAR
inc bFirstLoad
.8 clc
rts
*--------------------------------------
LIB.UNLOAD clc
rts
*--------------------------------------
* 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 ZPQuickPtr1
ldy #S.IPCFG
.1 dey
lda (ZPQuickPtr1),y
sta IPCFG,y
tya
bne .1
>LDYA ZPQuickPtr1
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 0
>SYSCALL SYS.GetMem
bcs .9
>STYA ZPFrameBase1
phx
txa
>SYSCALL SYS.ClrMemA
plx
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 #S.IPCFG.HDEV
lda IPCFG,x
>SYSCALL SYS.DevOutA
rts
*--------------------------------------
UDP.LISTENER >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
sec
rts
*--------------------------------------
TCP.LISTENER >PULLW ZPFrameBase1
>PULLW ZPFrameLen1
sec
rts
*--------------------------------------
ADD.LISTENER sec
rts
*--------------------------------------
REM.LISTENER sec
rts
*--------------------------------------
.INB LIB/LIBTCPIP.S.ARP
.INB LIB/LIBTCPIP.S.DNS
*--------------------------------------
* PRIVATE
*--------------------------------------
ToLowerCaseA cmp #'A'
bcc .1
cmp #'Z'+1
bcs .1
adc #$20
.1 rts
*--------------------------------------
* In:
* PULLW = Start Offset
* PULLW = End Offset
* Out:
* Y,A = CheckSum
*--------------------------------------
ComputeChecksum >PULLA
clc
adc ZPFrameBase1
sta ZPQuickPtr1
>PULLA
adc ZPFrameBase1+1
sta ZPQuickPtr1+1
>PULLA
clc
adc ZPFrameBase1
sta ZPQuickPtr2
>PULLA
adc ZPFrameBase1+1
sta ZPQuickPtr2+1
stz IP.CHECKSUM RESET.IP.CHECKSUM
stz IP.CHECKSUM+1
stz IP.CHECKSUM+2
stz IP.CHECKSUM+3
ldy #1
.1 lda (ZPQuickPtr1),y
clc
adc IP.CHECKSUM
sta IP.CHECKSUM
lda (ZPQuickPtr1)
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
bcc .3
inc IP.CHECKSUM+2
bne .3
inc IP.CHECKSUM+3
.3 lda ZPQuickPtr1
clc
adc #2
sta ZPQuickPtr1
bcc .4
inc ZPQuickPtr1+1
.4 cmp ZPQuickPtr2
bne .1
lda ZPQuickPtr1+1
cmp ZPQuickPtr2+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
*--------------------------------------
CS.END
*--------------------------------------
bFirstLoad .DA #0
Status .BS 1
hHOST .BS 1 for DNS Cache functions
HOST.TTL .BS 2 for DNS Cache functions
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
*--------------------------------------
DS.START
DS.END
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S
ASM