A2osX/SBIN/CIFSD.S.txt

651 lines
13 KiB
Plaintext
Raw Normal View History

2019-06-13 15:30:28 +00:00
NEW
AUTO 3,1 Enable MASM3 auto line num
.LIST OFF
.OP 65C02 Target CPU, must match CPU level in header
.OR $2000 usualy $2000, but any value > $100 allowed
2020-06-13 19:27:06 +00:00
.TF sbin/cifsd
2019-06-13 15:30:28 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/mli.e.i
.INB inc/eth.i
.INB inc/libtcpip.i
.INB inc/net.smb.i
2019-06-14 15:16:48 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
TIMEOUT.MAX .EQ 100 20 sec.
2019-06-13 15:30:28 +00:00
*--------------------------------------
* Zero Page Segment, up to 32 bytes
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPIPCfgPtr .BS 2
2020-06-13 19:27:06 +00:00
hResp .BS 1
ZPRespPtr .BS 2
2019-06-14 15:16:48 +00:00
TimeOut .BS 1
2019-06-13 15:30:28 +00:00
ZS.END
.ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2019-06-14 15:16:48 +00:00
.DA #S.PS.F.EVENT
2019-06-13 15:30:28 +00:00
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DA #64 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
2019-06-13 15:30:28 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2019-06-14 15:16:48 +00:00
L.LIBTCPIP .DA LIBTCPIP
2020-06-13 19:27:06 +00:00
L.MSG.TCPIPERR .DA MSG.TCPIPERR
2019-06-14 15:16:48 +00:00
L.MSG.USAGE .DA MSG.USAGE
L.MSG.UNKNOWN .DA MSG.UNKNOWN
2020-06-17 19:05:36 +00:00
L.MSG.SESSION .DA MSG.SESSION
2020-06-13 19:27:06 +00:00
L.SMB.NegReq .DA SMB.NegReq
L.SMB.SessSetup .DA SMB.SessSetup
L.SMB.TreeConnReq .DA SMB.TreeConnReq
2020-06-17 19:05:36 +00:00
L.SMB.FindFirstReq .DA SMB.FindFirstReq
2019-06-13 15:30:28 +00:00
.DA 0
*--------------------------------------
* Called once at process creation
* Put code for loading LIB here
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL LoadLib
2019-07-07 20:48:57 +00:00
bcs .9
2019-06-13 15:30:28 +00:00
sta hLIBTCPIP
2020-06-13 19:27:06 +00:00
clc
.9 rts
*--------------------------------------
* Called until exit with CS
* if RUN exits with CC, RUN entered again
*--------------------------------------
2020-06-17 19:05:36 +00:00
CS.RUN >LDA.G hSocket
bne .8
>LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
2019-07-07 20:48:57 +00:00
bcs .9
2020-06-13 19:27:06 +00:00
2019-06-13 15:30:28 +00:00
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
2020-06-13 19:27:06 +00:00
bmi .1
>LDYA L.MSG.TCPIPERR
>SYSCALL PutS
2019-06-13 15:30:28 +00:00
lda #E.SYN
sec
rts
2019-06-14 15:16:48 +00:00
2020-06-13 19:27:06 +00:00
.1 jsr CS.RUN.CheckArgs
2019-06-13 15:30:28 +00:00
bcs .90
2019-07-12 06:22:32 +00:00
2019-07-07 20:48:57 +00:00
jsr CS.RUN.Connect
2020-06-13 19:27:06 +00:00
>SLEEP
2019-07-07 20:48:57 +00:00
jsr CS.RUN.Negotiate
2020-06-13 19:27:06 +00:00
bcs .9
2020-06-17 19:05:36 +00:00
>SLEEP
2020-06-13 19:27:06 +00:00
jsr CS.RUN.SessSetup
bcs .9
2020-06-17 19:05:36 +00:00
>SLEEP
jsr CS.RUN.TreeConn
bcs .9
>SLEEP
jsr CIFS.OpenDir
bcs .9
.8 lda #0
2020-06-13 19:27:06 +00:00
clc
2019-07-07 20:48:57 +00:00
.9 rts
2020-06-13 19:27:06 +00:00
2019-06-13 15:30:28 +00:00
.90 >LDYA L.MSG.USAGE
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-06-13 15:30:28 +00:00
lda #E.SYN
sec
rts
*--------------------------------------
CS.RUN.CheckArgs
ldy #S.PS.ARGC
2020-02-28 07:21:46 +00:00
lda (pPS),y
2019-06-13 15:30:28 +00:00
cmp #3
bcc .9
2019-06-14 15:16:48 +00:00
lda #TIMEOUT.MAX
sta TimeOut
2020-06-13 19:27:06 +00:00
2019-06-14 15:16:48 +00:00
.1 >PUSHEA.G SA.REMOTE+S.SOCKADDR.ADDR
lda #1
>SYSCALL ArgV
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc .2
2020-06-13 19:27:06 +00:00
2019-06-14 15:16:48 +00:00
>SLEEP
lda TimeOut
bne .1
2020-06-13 19:27:06 +00:00
>PUSHW L.MSG.UNKNOWN
2019-06-14 15:16:48 +00:00
lda #1
>SYSCALL ArgV
>PUSHYA
>PUSHBI 2
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-06-14 15:16:48 +00:00
sec
2019-07-07 20:48:57 +00:00
.9 rts
2020-06-13 19:27:06 +00:00
2019-07-07 20:48:57 +00:00
.2 lda #AF.INET
>STA.G SA.LOCAL
>STA.G SA.REMOTE
ldy #S.IPCFG.IP+3
2020-06-13 19:27:06 +00:00
2019-07-07 20:48:57 +00:00
.3 lda (ZPIPCfgPtr),y
pha
dey
cpy #S.IPCFG.IP-1
bne .3
2020-06-13 19:27:06 +00:00
2019-07-07 20:48:57 +00:00
ldy #SA.REMOTE+S.SOCKADDR.PORT
.4 pla
sta (pData),y
iny
cpy #SA.REMOTE+S.SOCKADDR.PORT+4
bne .4
2020-06-13 19:27:06 +00:00
2019-07-07 20:48:57 +00:00
lda #TCP.PORT.CIFS
>STA.G SA.REMOTE+S.SOCKADDR.PORT
iny
lda /TCP.PORT.CIFS
sta (pData),y
2019-06-14 15:16:48 +00:00
clc
rts
2019-06-13 15:30:28 +00:00
*--------------------------------------
2019-06-14 15:16:48 +00:00
CS.RUN.Connect >PUSHBI 0 no protocol
2020-06-13 19:27:06 +00:00
lda #S.SOCKET.T.SEQPKT
2019-06-14 15:16:48 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .9
>STA.G hSocket
2019-07-07 20:48:57 +00:00
>PUSHEA.G SA.LOCAL
2019-06-14 15:16:48 +00:00
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcs .9
2020-06-13 19:27:06 +00:00
2019-07-07 20:48:57 +00:00
>PUSHEA.G SA.REMOTE
2019-06-14 15:16:48 +00:00
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
.9 rts
*--------------------------------------
2019-07-07 20:48:57 +00:00
CS.RUN.Negotiate
2020-06-13 19:27:06 +00:00
lda #TIMEOUT.MAX
sta TimeOut
.1 >PUSHWI SMB.NegReq.end-SMB.NegReq
>PUSHW L.SMB.NegReq
2019-07-07 20:48:57 +00:00
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
2020-06-13 19:27:06 +00:00
bcc .2
>SLEEP
ldx TimeOut
bne .1
bra .99
.2 >SLEEP
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcc .3
tay
beq .2
bra .99
2020-06-17 19:05:36 +00:00
.3 sta hResp
>SYSCALL GetMemPtr
2020-06-13 19:27:06 +00:00
>STYA ZPRespPtr
ldy #$3f
lda (ZPRespPtr),y
bne .9
ldy #$5B
lda (ZPRespPtr),y
cmp #5
bne .9
lda hResp
>SYSCALL FreeMem
* clc
rts
.9 lda hResp
>SYSCALL FreeMem
.99 lda #MLI.E.INVPATH
sec
2019-07-07 20:48:57 +00:00
rts
*--------------------------------------
2020-06-13 19:27:06 +00:00
CS.RUN.SessSetup
2020-06-17 19:05:36 +00:00
lda #TIMEOUT.MAX
sta TimeOut
.1 >PUSHWI SMB.SessSetup.end-SMB.SessSetup
>PUSHW L.SMB.SessSetup
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
bcc .2
>SLEEP
ldx TimeOut
bne .1
bra .99
.2 >SLEEP
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcc .3
tay
beq .2
bra .99
2020-06-13 19:27:06 +00:00
2020-06-17 19:05:36 +00:00
.3 sta hResp
>SYSCALL GetMemPtr
>STYA ZPRespPtr
ldy #$3f
lda (ZPRespPtr),y
bne .9
ldy #$56
lda (ZPRespPtr),y
sta SMB.TreeConnReq.UID
iny
lda (ZPRespPtr),y
sta SMB.TreeConnReq.UID+1
>PUSHW L.MSG.SESSION
lda #$63
2020-06-13 19:27:06 +00:00
clc
2020-06-17 19:05:36 +00:00
adc ZPRespPtr
tay
lda #0
adc ZPRespPtr+1
>PUSHYA
>PUSHBI 2
>SYSCALL Printf
lda hResp
>SYSCALL FreeMem
* clc
rts
.9 lda hResp
>SYSCALL FreeMem
.99 lda #MLI.E.INVPATH
sec
rts
*--------------------------------------
CS.RUN.TreeConn lda #TIMEOUT.MAX
sta TimeOut
.1 >PUSHWI SMB.TreeConnReq.end-SMB.TreeConnReq
>PUSHW L.SMB.TreeConnReq
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
bcc .2
>SLEEP
ldx TimeOut
bne .1
bra .99
.2 >SLEEP
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcc .3
tay
beq .2
bra .99
.3 sta hResp
>SYSCALL GetMemPtr
>STYA ZPRespPtr
ldy #$3f
lda (ZPRespPtr),y
bne .9
2020-06-19 06:33:47 +00:00
ldy #$52
lda (ZPRespPtr),y
sta SMB.FindFirstReq.TID
iny
lda (ZPRespPtr),y
sta SMB.FindFirstReq.TID+1
ldy #$56
lda (ZPRespPtr),y
sta SMB.FindFirstReq.UID
iny
lda (ZPRespPtr),y
sta SMB.FindFirstReq.UID+1
2020-06-17 19:05:36 +00:00
lda hResp
>SYSCALL FreeMem
* clc
rts
.9 lda hResp
>SYSCALL FreeMem
.99 lda #MLI.E.INVPATH
sec
2020-06-13 19:27:06 +00:00
rts
2019-06-13 15:30:28 +00:00
*--------------------------------------
2019-06-14 15:16:48 +00:00
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
lda TimeOut
beq .9
dec TimeOut
.9 sec do not discard TIMER event
2019-06-13 15:30:28 +00:00
rts
*--------------------------------------
* Called once, when RUN exited with CS
* Put code for unloading LIB here
*--------------------------------------
2020-06-13 19:27:06 +00:00
CS.QUIT >LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
lda hLIBTCPIP
2019-06-13 15:30:28 +00:00
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
2020-06-17 19:05:36 +00:00
CIFS.OpenDir lda #TIMEOUT.MAX
sta TimeOut
.1 >PUSHWI SMB.FindFirstReq.end-SMB.FindFirstReq
>PUSHW L.SMB.FindFirstReq
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
bcc .2
>SLEEP
ldx TimeOut
bne .1
bra .99
.2 >SLEEP
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
bcc .3
tay
beq .2
bra .99
.3 sta hResp
>SYSCALL GetMemPtr
>STYA ZPRespPtr
ldy #$3f
lda (ZPRespPtr),y
bne .9
lda hResp
>SYSCALL FreeMem
* clc
rts
.9 lda hResp
>SYSCALL FreeMem
.99 lda #MLI.E.INVPATH
sec
rts
*--------------------------------------
CIFS.ReadDir
*--------------------------------------
CIFS.CloseDir
clc
rts
*--------------------------------------
2019-06-13 15:30:28 +00:00
CS.END
*--------------------------------------
* Initialized DATA
*--------------------------------------
2020-06-13 19:27:06 +00:00
LIBTCPIP .AZ "libtcpip"
2019-06-13 15:30:28 +00:00
hLIBTCPIP .BS 1
2020-06-13 19:27:06 +00:00
MSG.TCPIPERR .AZ "HTTPD:TCP/IP Not initialized properly."
2019-06-14 15:16:48 +00:00
MSG.USAGE .AZ "Usage : CIFSD <ip|host> sharename mountpoint"
MSG.UNKNOWN .AZ "%s: Unknown host\r\n"
2020-06-17 19:05:36 +00:00
MSG.SESSION .AZ "Connected to: %s\r\n"
2019-06-13 15:30:28 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
SMB.NegReq .DA #0 DIRECT TCP TRANSPORT
.DA #0 24 BITS LENGTH
.DA /SMB.NegReq.end-1-*
.DA #SMB.NegReq.end-1-*
.DA #$FF
2019-07-07 20:48:57 +00:00
.AS "SMB"
2020-06-17 19:05:36 +00:00
.DA #S.SMB.H.CMD.NEGOTIATE
2019-07-07 20:48:57 +00:00
.HS 00000000
2020-06-17 19:05:36 +00:00
.DA #0 S.SMB.H.FLAGS
.DA S.SMB.H.FLAGS2.LONGNAMES
2019-07-07 20:48:57 +00:00
.DA 0 PIDHI
.HS 0000000000000000 SECFEAT
.DA 0 RSVD
.DA $FFFF TID
.DA $FEFF PIDLO
.DA 0 UID
.DA 0 MID
2020-06-17 19:05:36 +00:00
2019-07-07 20:48:57 +00:00
.DA #0 WORD COUNT
2020-06-17 19:05:36 +00:00
2020-06-13 19:27:06 +00:00
.DA #SMB.NegReq.end-2-*
.DA /SMB.NegReq.end-2-*
2020-06-17 19:05:36 +00:00
2020-06-13 19:27:06 +00:00
.DA #2
.AZ "PC NETWORK PROGRAM 1.0"
.DA #2
.AZ "LANMAN1.0"
.DA #2
.AZ "Windows for Workgroups 3.1a"
.DA #2
.AZ "LM1.2X002"
.DA #2
.AZ "LANMAN2.1"
2019-07-07 20:48:57 +00:00
.DA #2
.AZ "NT LM 0.12"
2020-06-13 19:27:06 +00:00
.DA #2
.AZ "SMB 2.002"
.DA #2
.AZ "SMB 2.???"
SMB.NegReq.end .EQ *
2019-07-07 20:48:57 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
SMB.SessSetup .DA #0 DIRECT TCP TRANSPORT
.DA #0 24 BITS LENGTH
.DA /SMB.SessSetup.end-1-*
.DA #SMB.SessSetup.end-1-*
.DA #$FF
.AS "SMB"
2020-06-17 19:05:36 +00:00
.DA #S.SMB.H.CMD.SESSION.SETUP.ANDX
.HS 00000000
.DA #0 S.SMB.H.FLAGS
.DA S.SMB.H.FLAGS2.LONGNAMES
.DA 0 PIDHI
.HS 0000000000000000 SECFEAT
.DA 0 RSVD
.DA $FFFF TID
.DA $FEFF PIDLO
.DA 0 UID
.DA 0 MID
.DA #13 WORD COUNT
2020-06-13 19:27:06 +00:00
2020-06-17 19:05:36 +00:00
.HS FF000000 NO MORE CMD
.DA 1280 MAX BUFFER
.DA 2 MAX MPX COUNT
.HS 0000 VC NUMBER
.HS 00000000 SESSION KEY
.DA 0 CI PASS LEN
.DA 0 CS PASS LEN
.HS 00000000
.HS 00000000 CAPABILITIES
.DA #SMB.SessSetup.end-2-*
.DA /SMB.SessSetup.end-2-*
SMB.SessSetup.SecBlob
* .AZ "" Password
.AZ "GUEST" Account Name
.AZ "?" Primary Domain
SMB.SessSetup.SecBlob.LEN .EQ *-SMB.SessSetup.SecBlob
.AZ "A2osX" Native OS
.AZ "A2osX-CIFSD" Native LANMAN
2020-06-13 19:27:06 +00:00
SMB.SessSetup.end .EQ *
*--------------------------------------
SMB.TreeConnReq .DA #0 DIRECT TCP TRANSPORT
.DA #0 24 BITS LENGTH
.DA /SMB.TreeConnReq.end-1-*
.DA #SMB.TreeConnReq.end-1-*
.DA #$FF
.AS "SMB"
2020-06-17 19:05:36 +00:00
.DA #S.SMB.H.CMD.TREE.CONNECT.ANDX
.HS 00000000
.DA #0 S.SMB.H.FLAGS
.DA S.SMB.H.FLAGS2.LONGNAMES
.DA 0 PIDHI
.HS 0000000000000000 SECFEAT
.DA 0 RSVD
2020-06-19 06:33:47 +00:00
SMB.TreeConnReq.TID
2020-06-17 19:05:36 +00:00
.DA $FFFF TID
.DA $FEFF PIDLO
SMB.TreeConnReq.UID
.DA 0 UID
.DA 0 MID
2020-06-13 19:27:06 +00:00
2020-06-17 19:05:36 +00:00
.DA #4 WORD COUNT
.HS FF000000 NO MORE CMD
.DA 0
.DA 1 PASSWORD LEN
.DA #SMB.TreeConnReq.end-2-*
.DA /SMB.TreeConnReq.end-2-*
.AZ "" PASSWORD
.AZ "\\SV-W2K-3\Apple" PATH
.AZ "?????"
2020-06-13 19:27:06 +00:00
SMB.TreeConnReq.end .EQ *
2020-06-17 19:05:36 +00:00
*--------------------------------------
SMB.FindFirstReq
.DA #0 DIRECT TCP TRANSPORT
.DA #0 24 BITS LENGTH
.DA /SMB.TreeConnReq.end-1-*
.DA #SMB.TreeConnReq.end-1-*
.DA #$FF
.AS "SMB"
.DA #S.SMB.H.CMD.TRANSACTION2
.HS 00000000
.DA #0 S.SMB.H.FLAGS
.DA S.SMB.H.FLAGS2.LONGNAMES
.DA 0 PIDHI
.HS 0000000000000000 SECFEAT
.DA 0 RSVD
2020-06-19 06:33:47 +00:00
SMB.FindFirstReq.TID
2020-06-17 19:05:36 +00:00
.DA $FFFF TID
.DA $FEFF PIDLO
2020-06-19 06:33:47 +00:00
SMB.FindFirstReq.UID
2020-06-17 19:05:36 +00:00
.DA 0 UID
.DA 0 MID
.DA #$0F WORD COUNT
.DA 0 TotalParamCount
.DA 0 TotalDataCount
.DA 256 MaxParameterCount
.DA 1024 MaxDataCount
.DA #1 MaxSetupCount
.HS 00 Reserved1
.DA 0 Flags
.HS 00000000 Timeout
.HS 0000 Reserved2
2020-06-19 06:33:47 +00:00
.DA 18 ParameterCount
.DA 68 ParameterOffset
.HS 0000 DataCount
2020-06-17 19:05:36 +00:00
.HS 0000 DataOffset
.DA #1 SetupCount
.HS 00 Reserved3
.DA 1 TRANS2_FIND_FIRST2
.DA SMB.FindFirstReq.end-2-*
2020-06-19 06:33:47 +00:00
.HS 000000 Padding
2020-06-17 19:05:36 +00:00
.DA $373E SearchAttributes
2020-06-19 06:33:47 +00:00
.DA 1024 SearchCount
2020-06-17 19:05:36 +00:00
.DA 0 Flags
.DA $0104 InformationLevel
.HS 00000000 SearchStorageType
2020-06-19 06:33:47 +00:00
.DA "\*" FileName
2020-06-17 19:05:36 +00:00
SMB.FindFirstReq.end
2019-06-13 15:30:28 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
2019-06-14 15:16:48 +00:00
SA.LOCAL .BS 1 S.SOCKADDR.AF
2019-06-13 15:30:28 +00:00
.BS 1
.BS 4 S.SOCKADDR.ADDR
.BS 2 S.SOCKADDR.PORT
2019-06-14 15:16:48 +00:00
SA.REMOTE .BS 1 S.SOCKADDR.AF
2019-06-13 15:30:28 +00:00
.BS 1
.BS 4 S.SOCKADDR.ADDR
2019-06-14 15:16:48 +00:00
.BS 2 S.SOCKADDR.PORT
2019-10-03 06:25:27 +00:00
hSocket .BS 1
2019-06-13 15:30:28 +00:00
DS.END
.ED
*--------------------------------------
MAN
2020-06-13 19:27:06 +00:00
SAVE usr/src/sbin/cifsd
2019-06-13 15:30:28 +00:00
ASM