mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-16 23:21:24 +00:00
302 lines
5.9 KiB
Plaintext
302 lines
5.9 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF /A2OSX.BUILD/SBIN/TELNETD
|
||
*--------------------------------------
|
||
.INB /A2OSX.BUILD/INC/MACROS.I
|
||
.INB /A2OSX.BUILD/INC/A2OSX.I
|
||
.INB /A2OSX.BUILD/INC/LIBTCPIP.I
|
||
*--------------------------------------
|
||
TIMEOUT.MAX .EQ 30 30 sec.
|
||
CONN.MAX .EQ 16
|
||
*--------------------------------------
|
||
ZPIPCfgPtr .EQ ZPBIN
|
||
ZPSktPtr .EQ ZPBIN+2
|
||
*--------------------------------------
|
||
* File Header (16 Bytes)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp (.1,x)
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 BIN Layout Version 1
|
||
.DA 0
|
||
.DA CS.END-CS.START Code Length To Relocate
|
||
.DA DS.END-DS.START Data Segment to Allocate
|
||
.DA 0
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
.1 .DA CS.INIT
|
||
.DA CS.RUN
|
||
.DA CS.DOEVENT
|
||
.DA CS.QUIT
|
||
L.LIBTCPIP .DA LIBTCPIP
|
||
L.Socket .DA Socket
|
||
L.MSG.TCPWAIT .DA MSG.TCPWAIT
|
||
L.MSG.INITOK .DA MSG.INITOK
|
||
L.MSG.TCPIPERR .DA MSG.TCPIPERR
|
||
L.MSG.SKTERR .DA MSG.SKTERR
|
||
L.MSG.ABORT .DA MSG.ABORT
|
||
L.MSG.INCOMING .DA MSG.INCOMING
|
||
L.MSG.BYTE .DA MSG.BYTE
|
||
.DA 0
|
||
*--------------------------------------
|
||
CS.INIT >LDYA L.LIBTCPIP
|
||
>SYSCALL LoadLibYA
|
||
sta hLIBTCPIP
|
||
|
||
lda (pPs)
|
||
ora #S.PS.F.EVENT Now accept events
|
||
sta (pPs)
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN jsr Init.Timeout
|
||
|
||
>LDYA L.MSG.TCPWAIT
|
||
>SYSCALL PrintF.YA
|
||
|
||
.1 >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ?
|
||
bcs .99
|
||
>STYA ZPIPCfgPtr
|
||
|
||
lda (ZPIPCfgPtr) Configured ?
|
||
bmi CS.RUN.INIT
|
||
|
||
>SYSCALL Sleep
|
||
jsr Wait.Timeout
|
||
bcc .1
|
||
>SYSCALL GetC
|
||
bcs .1
|
||
cmp #$03
|
||
bne .1
|
||
jmp CS.RUN.ABORT
|
||
|
||
.99 >LDYA L.MSG.TCPIPERR
|
||
>SYSCALL PrintF.YA
|
||
lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
|
||
CS.RUN.INIT ldx #3
|
||
ldy #S.IPCFG.IP+3
|
||
.1 lda (ZPIPCfgPtr),y
|
||
sta Socket.Src.Addr,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
>PUSHW L.Socket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New
|
||
bcs .9
|
||
txa
|
||
ldy #hSrvSocket
|
||
sta (pData),y
|
||
|
||
>LDYA L.MSG.INITOK
|
||
>SYSCALL PrintF.YA
|
||
|
||
.2 >SYSCALL Sleep
|
||
jsr CS.RUN.SERVER
|
||
bcs CS.RUN.ERR
|
||
|
||
jsr CS.RUN.CLIENT
|
||
bra .2
|
||
|
||
.9 >LDYA L.MSG.SKTERR
|
||
>SYSCALL PrintF.YA
|
||
lda #SYSMGR.ERRSYN
|
||
sec
|
||
rts
|
||
|
||
CS.RUN.ABORT >LDYA L.MSG.ABORT
|
||
>SYSCALL PrintF.YA
|
||
lda #0
|
||
|
||
CS.RUN.ERR sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.SERVER ldy #hSrvSocket
|
||
lda (pData),y
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.AcceptA
|
||
bcs .8
|
||
pha
|
||
|
||
ldy #hSockets
|
||
ldx #CONN.MAX
|
||
|
||
.1 lda (pData),y
|
||
beq .2
|
||
iny
|
||
dex
|
||
bne .1
|
||
|
||
pla
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CloseA
|
||
bra .8
|
||
|
||
.2 pla
|
||
sta (pData),y
|
||
sta .4+1
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetA
|
||
>STYA ZPSktPtr
|
||
|
||
ldx #3
|
||
ldy #S.SOCKET.DST.ADDR+3
|
||
|
||
.3 >PUSHB (ZPSktPtr),y
|
||
dey
|
||
dex
|
||
bpl .3
|
||
|
||
.4 lda #$ff
|
||
>PUSHA
|
||
|
||
>LDYA L.MSG.INCOMING
|
||
>SYSCALL PrintF.YA
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN.CLIENT ldy #SktIndex
|
||
lda (pData),y
|
||
tay
|
||
lda (pData),y hSockets
|
||
beq .8
|
||
|
||
sta .1+1 hSocket
|
||
sta .3+1
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.GetC.A
|
||
bcc .10
|
||
|
||
tax
|
||
beq .8 NO DATA
|
||
cmp #ERR.SKT.BAD
|
||
bne .8
|
||
|
||
ldy #SktIndex
|
||
lda (pData),y
|
||
tay
|
||
lda #0
|
||
sta (pData),y
|
||
bra .8
|
||
|
||
.10 sta .2+1
|
||
>PUSHA
|
||
>LDYA L.MSG.BYTE
|
||
>SYSCALL PrintF.YA
|
||
|
||
.1 lda #$ff hSocket
|
||
>PUSHA
|
||
|
||
.2 lda #$ff data
|
||
and #$7F
|
||
ora #$20
|
||
>PUSHA
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.PutC
|
||
|
||
.3 lda #$ff hSocket
|
||
>PUSHA
|
||
|
||
lda #'/'
|
||
>PUSHA
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.PutC
|
||
|
||
.8 ldy #SktIndex
|
||
lda (pData),y
|
||
inc
|
||
cmp #CONN.MAX
|
||
bne .81
|
||
lda #0
|
||
|
||
.81 sta (pData),y
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.DOEVENT sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.QUIT ldx #CONN.MAX
|
||
ldy #hSockets
|
||
|
||
.1 lda (pData),y
|
||
beq .2
|
||
|
||
phx
|
||
phy
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
|
||
ply
|
||
plx
|
||
|
||
.2 iny
|
||
dex
|
||
bne .1
|
||
|
||
ldy #hSrvSocket
|
||
lda (pData),y
|
||
beq .3
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.CLOSEA
|
||
|
||
.3 lda hLIBTCPIP
|
||
>SYSCALL UnloadLibA
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
Init.Timeout ldy #TimeOut
|
||
lda #TIMEOUT.MAX
|
||
sta (pData),y
|
||
rts
|
||
*--------------------------------------
|
||
Wait.TimeOut sec
|
||
ldy #TimeOut
|
||
lda (pData),y
|
||
beq .9
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
LIBTCPIP >PSTR "libtcpip.o"
|
||
MSG.TCPWAIT >CSTR "TELNETD:Waiting for TCP/IP initializing...\r\n"
|
||
MSG.INITOK >CSTR "TELNETD:Init Ok, Listening.\r\n"
|
||
MSG.TCPIPERR >CSTR "TELNETD:TCP/IP Not initialized properly\r\n"
|
||
MSG.SKTERR >CSTR "TELNETD:Listen Error\r\n"
|
||
MSG.ABORT >CSTR "TELNETD:User Aborted\r\n"
|
||
MSG.INCOMING >CSTR "TELNETD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
|
||
MSG.BYTE >CSTR "[%h]"
|
||
hLIBTCPIP .BS 1
|
||
*--------------------------------------
|
||
Socket .DA #S.SOCKET.SOCK.STREAM
|
||
.DA #S.SOCKET.SO.ACCEPTCONN
|
||
.DA #S.SOCKET.TCP.STATUS.LISTEN
|
||
.BS 1
|
||
Socket.Src.Addr .BS 4
|
||
Socket.Src.Port .DA 23
|
||
Socket.Dst.Addr .BS 4
|
||
Socket.Dst.Port .BS 2
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
hSockets .BS CONN.MAX pData
|
||
SktIndex .BS 1
|
||
hSrvSocket .BS 1
|
||
TimeOut .BS 1
|
||
DS.END
|
||
.ED
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SBIN/TELNETD.S
|
||
ASM
|