A2osX/SBIN/TELNETD.S.txt

254 lines
5.0 KiB
Plaintext
Raw Normal View History

2015-03-14 21:48:35 +00:00
NEW
2019-04-15 05:40:13 +00:00
AUTO 3,1
2015-03-14 21:48:35 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2019-12-04 13:46:58 +00:00
.TF sbin/telnetd
2015-03-14 21:48:35 +00:00
*--------------------------------------
2020-08-17 20:47:31 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/eth.i
.INB inc/libtcpip.i
.INB inc/net.telnet.i
2015-03-14 21:48:35 +00:00
*--------------------------------------
2019-05-05 17:15:37 +00:00
TIMEOUT.MAX .EQ 200 20 sec.
*--------------------------------------
2019-05-05 17:15:37 +00:00
.DUMMY
.OR ZPBIN
ZS.START
ZPIPCfgPtr .BS 2
ZPSktPtr .BS 2
TimeOut .BS 1
2019-10-24 14:47:28 +00:00
hSrvSocket .BS 1
hClientSocket .BS 1
ZS.END .ED
*--------------------------------------
2015-10-19 20:35:00 +00:00
* File Header (16 Bytes)
2015-03-14 21:48:35 +00:00
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-10-19 20:35:00 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-09-17 15:42:38 +00:00
.DA #S.PS.F.EVENT S.PS.F
.DA #0
2018-05-22 06:01:05 +00:00
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
2019-10-24 14:47:28 +00:00
.DA #32 SS
2019-10-17 15:20:49 +00:00
.DA #ZS.END-ZS.START Zero Page Size
2015-10-19 20:35:00 +00:00
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
2015-03-14 21:48:35 +00:00
.1 .DA CS.INIT
.DA CS.RUN
2015-10-19 20:35:00 +00:00
.DA CS.DOEVENT
2015-03-14 21:48:35 +00:00
.DA CS.QUIT
2015-10-19 20:35:00 +00:00
L.LIBTCPIP .DA LIBTCPIP
2018-10-10 15:39:22 +00:00
L.SA.LOCAL .DA SA.LOCAL
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.INCOMING .DA MSG.INCOMING
2018-11-01 08:53:47 +00:00
L.NOD.Template .DA NOD.Template
L.CMD.Template .DA CMD.Template
2019-10-03 06:25:27 +00:00
.DA 0
2015-03-14 21:48:35 +00:00
*--------------------------------------
2015-10-19 20:35:00 +00:00
CS.INIT >LDYA L.LIBTCPIP
2018-07-19 15:33:55 +00:00
>SYSCALL LoadLib
2018-11-12 09:22:06 +00:00
bcs .9
2015-10-19 20:35:00 +00:00
sta hLIBTCPIP
2018-11-12 09:22:06 +00:00
.9 rts
*--------------------------------------
2019-05-05 17:15:37 +00:00
CS.RUN lda #TIMEOUT.MAX
sta TimeOut
2019-10-17 15:20:49 +00:00
>LDYA L.MSG.TCPWAIT
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-10-17 15:20:49 +00:00
2019-03-02 20:47:58 +00:00
.1 >SLEEP
>LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
2015-10-19 20:35:00 +00:00
bcs .99
2019-10-17 15:20:49 +00:00
>STYA ZPIPCfgPtr
2019-10-17 15:20:49 +00:00
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.INIT
2019-10-17 15:20:49 +00:00
2020-08-20 13:20:33 +00:00
lda TimeOut
2019-05-05 17:15:37 +00:00
beq .99
2019-10-17 15:20:49 +00:00
2019-03-02 20:47:58 +00:00
ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-20 13:20:33 +00:00
>SYSCALL FEOF
2019-03-02 20:47:58 +00:00
bcs .9 I/O err
2019-10-17 15:20:49 +00:00
2019-03-02 20:47:58 +00:00
tay
2019-05-02 09:52:32 +00:00
bne .1
2019-10-17 15:20:49 +00:00
2018-05-22 06:01:05 +00:00
>SYSCALL GetChar
2019-03-02 20:47:58 +00:00
bcs .9
2019-10-17 15:20:49 +00:00
cmp #$03
bne .1
2019-10-24 14:47:28 +00:00
* sec
rts
2019-10-17 15:20:49 +00:00
2018-09-17 15:42:38 +00:00
.99 pha
>LDYA L.MSG.TCPIPERR
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2018-09-17 15:42:38 +00:00
pla
2021-05-19 12:44:47 +00:00
sec
2019-03-02 20:47:58 +00:00
.9 rts
2019-10-17 15:20:49 +00:00
CS.RUN.INIT ldx #3
ldy #S.IPCFG.IP+3
2019-01-05 20:33:08 +00:00
.1 lda (ZPIPCfgPtr),y
2018-10-10 15:39:22 +00:00
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
2019-10-17 15:20:49 +00:00
2019-01-05 20:33:08 +00:00
lda #1
>SYSCALL ArgV
bcs CS.RUN.PORTOK
2020-08-20 13:20:33 +00:00
>SYSCALL AToI
2019-01-05 20:33:08 +00:00
>STYA SA.LOCAL+S.SOCKADDR.PORT
2019-10-17 15:20:49 +00:00
2021-05-19 12:44:47 +00:00
CS.RUN.PORTOK >PUSHBI S.SOCKET.T.STREAM
>PUSHBI 0 no protocol
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .9
2018-09-17 15:42:38 +00:00
2019-10-24 14:47:28 +00:00
sta hSrvSocket
2021-05-19 12:44:47 +00:00
>PUSHA
2018-10-10 15:39:22 +00:00
>PUSHW L.SA.LOCAL
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcs .9
2019-10-17 15:20:49 +00:00
2019-10-24 14:47:28 +00:00
lda hSrvSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Listen
bcs .9
2019-10-17 15:20:49 +00:00
>LDYA L.MSG.INITOK
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
.2 >SLEEP
2018-09-17 15:42:38 +00:00
2019-10-24 14:47:28 +00:00
lda hSrvSocket
2019-03-02 20:47:58 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Accept
bcs .2
2019-10-24 14:47:28 +00:00
pha
jsr CS.RUN.CLIENT
pla
2021-05-19 12:44:47 +00:00
2019-03-02 20:47:58 +00:00
bcc .2
2019-10-24 14:47:28 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
bra .2
2019-10-17 15:20:49 +00:00
2018-09-17 15:42:38 +00:00
.9 pha
>LDYA L.MSG.SKTERR
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2018-09-17 15:42:38 +00:00
pla
2021-05-19 12:44:47 +00:00
sec
rts
2018-11-19 07:43:00 +00:00
*--------------------------------------
2019-03-02 20:47:58 +00:00
CS.RUN.CLIENT >SLEEP give some time for TCPIP SYN/ACK
2019-10-24 14:47:28 +00:00
sta hClientSocket
2018-10-10 15:39:22 +00:00
>SYSCALL GetMemPtr
>STYA ZPSktPtr
2020-01-31 20:26:51 +00:00
>PUSHW L.MSG.INCOMING
>PUSHB hClientSocket
ldx #3
2020-01-31 20:26:51 +00:00
ldy #S.SOCKET.REM.ADDR
2019-10-17 15:20:49 +00:00
2020-02-14 07:21:56 +00:00
.1 >PUSHB (ZPSktPtr),y
2020-01-31 20:26:51 +00:00
iny
dex
2020-02-14 07:21:56 +00:00
bpl .1
2019-10-17 15:20:49 +00:00
2018-09-17 15:42:38 +00:00
>PUSHBI 5
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-10-17 15:20:49 +00:00
2020-02-14 07:21:56 +00:00
>PUSHEA.G NodBuf
>PUSHW L.NOD.Template
2019-10-24 14:47:28 +00:00
>PUSHB hClientSocket
2018-10-10 15:39:22 +00:00
>PUSHBI 1
2020-08-20 13:20:33 +00:00
>SYSCALL SPrintF
2019-10-17 15:20:49 +00:00
2020-12-17 20:23:54 +00:00
CS.RUN.CLIENT1 >PUSHEA.G NodBuf+5
2018-10-10 15:39:22 +00:00
>PUSHW 0
2020-03-10 16:42:07 +00:00
>PUSHB hClientSocket
2020-08-20 13:20:33 +00:00
>SYSCALL MKNod
2018-11-01 08:53:47 +00:00
bcs .9
2019-10-17 15:20:49 +00:00
2020-04-07 06:01:38 +00:00
>PUSHEA.G CmdBuf
>PUSHW L.CMD.Template
2018-11-01 08:53:47 +00:00
>PUSHEA.G NodBuf
>PUSHBI 2
2020-08-20 13:20:33 +00:00
>SYSCALL SPrintF
2019-10-17 15:20:49 +00:00
2020-01-24 14:21:08 +00:00
>PUSHEA.G CmdBuf
2019-04-15 05:40:13 +00:00
>PUSHBI 0
2020-08-20 13:20:33 +00:00
>SYSCALL ExecL
2021-07-26 13:45:29 +00:00
2018-09-17 15:42:38 +00:00
.9 rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2019-05-05 17:15:37 +00:00
lda TimeOut
2018-09-17 15:42:38 +00:00
beq .9
2019-05-05 17:15:37 +00:00
dec TimeOut
2018-09-17 15:42:38 +00:00
.9 sec do not discard TIMER event
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2019-10-24 14:47:28 +00:00
CS.QUIT lda hSrvSocket
beq .3
2019-10-17 15:20:49 +00:00
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2019-10-17 15:20:49 +00:00
.3 lda hLIBTCPIP
2018-11-12 09:22:06 +00:00
beq .8
2019-10-17 15:20:49 +00:00
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
2018-11-12 09:22:06 +00:00
.8 clc
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
CS.END
2015-10-19 20:35:00 +00:00
*--------------------------------------
2018-09-17 15:42:38 +00:00
hLIBTCPIP .BS 1
2019-12-03 15:42:17 +00:00
LIBTCPIP .AZ "libtcpip"
2018-09-17 15:42:38 +00:00
MSG.TCPWAIT .AZ "TELNETD:Waiting for TCP/IP initializing..."
MSG.INITOK .AZ "TELNETD:Init Ok, Listening."
2019-03-04 07:14:31 +00:00
MSG.TCPIPERR .AZ "TELNETD:TCP/IP Not initialized properly."
2018-09-17 15:42:38 +00:00
MSG.SKTERR .AZ "TELNETD:Listen Error."
MSG.INCOMING .CZ "TELNETD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
2018-11-01 08:53:47 +00:00
*--------------------------------------
2019-12-04 13:46:58 +00:00
NOD.Template .AZ "/dev/tty%h"
2019-12-07 17:53:45 +00:00
CMD.Template .AZ "${ROOT}sbin/getty -E %s ${ROOT}sbin/login"
*--------------------------------------
2018-10-10 15:39:22 +00:00
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
.BS 1
.BS 4 S.SOCKADDR.ADDR
.DA TCP.PORT.TELNET
*--------------------------------------
.DUMMY
.OR 0
DS.START
2018-11-01 08:53:47 +00:00
NodBuf .BS 11
CmdBuf .BS 65
2019-10-17 15:20:49 +00:00
DS.END .ED
2015-10-19 20:35:00 +00:00
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
2020-08-17 20:47:31 +00:00
SAVE usr/src/sbin/telnetd.s
2015-03-14 21:48:35 +00:00
ASM