	.title	k11ser	server for KERMIT-11
	.ident	/8.0.01/



;	Brian Nelson  22-Dec-83  12:16:59
;
;	This is the server module for KERMIT-11
;	it also has the modules to talk to a remote kermit


	.include	/IN:K11MAC.MAC/
	.iif ndf	,k11inc	,.error	; missing INCLUDE for K11MAC.MAC


	rodata

notimp:	.asciz	/?Kermit-11  Unimplemented server command/
notgen:	.asciz	/?Kermit-11  Unimplemented server generic command/
kertmp:	.asciz	/KERMIT.TMP/
invarg:	.asciz	/?Kermit-11  Invalid arguments for remote server command/
crlf:	.byte	cr,lf,0
	.even

	global	<null>

	code

	serwait	=	60.		; timeout while waiting for a command

	.sbttl	the main server loop
	code


server::mov	remote	,-(sp)		; save the local/remote flag
	mov	sp	,remote		; if a server we are always remote
	mov	sp	,inserv		; global flag to say we are a server

10$:	clr	paknum			; packetnumber := 0
	clr	numtry			; number_of_retrys := 0
	clr	oldtry			; oldtries := 0
	mov	#defchk	,chktyp		; checksum_type := type_1
	mov	#1	,chksiz		; checksum_len  := 1
	mov	$image	,image		; insure correct default is set
	call	fixchk			; sendpar_checktype := set_checktype
	mov	#serwai	,sertim		; set a new timeout please
	rpack	r2,r3,#packet		; loop forever
	clr	sertim			; normal timeouts now
	scan	r1,#200$		; and dispatch based on packet type
	asl	r0			; word offset into dispatch table
	jsr	pc	,@210$(r0)	; simple
	tst	r0			; done flag ?
	beq	10$			; next server command please
100$:	calls	suspend	,<#2>		; sleep a moment please
	clr	inserv			; no longer a server
	mov	(sp)+	,remote		; save the local/remote flag
	return


200$:	.byte	'S&137	,'R&137	,'G&137	,'I&137	,timout	,badchk
	.byte	'N&137	,'Y&137	,'C&137
	.byte	0
	.even
210$:	.word	serv.$
	.word	serv.s	,serv.r	,serv.g	,serv.i	,serv$$	,serchk
	.word	serv$$	,serv$$	,serv.c

	global	<badchk	,numtry	,oldtry	,paknum	,packet	,sertim>
	global	<chksiz	,chktyp	,inserv	,fixchk	,$image>


	.sbttl	routines for server


serv.$:	strlen	#notimp
	spack	#'E,paknum,r0,#notimp	; ignore unrecognized packet type
	clr	r0			; not done yet
	return


serv$$:	call	serchk			; timeout, send a NAK please
	clr	r0			; not yet done
	return				; ignore timeouts, ACKS and NAKS


serchk:	mov	r3	,paknum		; nak checksum errors
	spack	#'N,paknum		; send the NAK out please
	clr	r0			; we are not done
	return


serv.i:	mov	r3	,paknum		; we got an init packet. respond in
	calls	rpar	,<#packet,r2>	; kind please
	calls	spar	,<#packet>	; get our parameters and send them to
	spack	#'Y,paknum,sparsz,#packet; the other kermit
	clr	r0			; not done
	return				; bye



serv.s:	mov	pauset	,oldpau		; save the old pause time please
	call	throtl			; and throttle the line speed
	mov	r3	,paknum		; got a SINIT, initialize packet number
	calls	rpar	,<#packet,r2>	; store there send init info away
	calls	spar	,<#packet>	; and send them ours for the ACK
	spack	#'Y,paknum,sparsz,#packet
	mov	numtry	,oldtry		; save the retry count
	clr	numtry			; retrycount := 0
	incm64	paknum			; paknum := ( paknum+1 ) mod 64
	calls	rec.sw	,<#'F>		; and get set to receive a filename
	clr	r0			; not done
	mov	oldpau	,pauset		; restore old pause time
	return				; next server command please



serv.r:	copyz	#packet,#srcnam		; copy the .asciz packet
	clr	index			; first file in directory please
	call	getnxt			; get the first filename please
	tst	r0			; did it work ?
	bne	100$			; no. Getnxt will send the error pak
	calls	sen.sw	,<#'S>
100$:	clr	r0			; not done
	return


serv.c:	call	cretmp			; create the temp file please
	bcs	100$			; oops
	calls	sercmd	,<#packet,#lun.ou>; it worked
	cmpb	r0	,#377		; normal exit on KMON wait?
	beq	10$			; yes
	tst	r0			; zero (?)
	beq	10$			; yes
	calls	syserr	,<r0,#errtxt>	; no, send the error over
	strlen	#errtxt			; the length
	spack	#'E,paknum,r0,#errtxt	; ignore unrecognized packet type
	call	clotmp			; no, send error over
	br	100$			; bye
10$:	call	clotmp			; close it and send the file over
	mov	#kertmp	,r0		; as a text reply
	call	xreply
100$:	clr	r0
	return

200$:	.asciz	/Spawned job failed due to timeout or TT read wait/<cr><lf>
	.even


serv.g:	calls	bufunp	,<#packet,#packet>
	movb	packet+0,r1		; get the first data byte which
	scan	r1,#200$		; is the generic command type
	asl	r0			; index into dispatch table
	jsr	pc	,@210$(r0)	; simple
	return


200$:	.byte	'L&137	,'F&137	,'U&137	,'D&137	,'H&137	,'E&137
	.byte	'T&137	,'W&137
	.byte	'K&137	,'R&137
	.byte	0
	.even
210$:	.word	gen.$
	.word	gen.l	,gen.f	,gen.u	,gen.d	,gen.h	,gen.e
	.word	gen.t	,gen.w	,gen.k	,gen.r


	global	<getnxt	,index	,numtry	,oldtry	,paknum	,packet>
	global	<srcnam	,sparsz	,pauset	,oldpau	,throtl>


	.sbttl	generic kermit routines


gen.$:	strlen	#notgen			; NO-OP for unimplemented generic
	spack	#'E,paknum,r0,#notgen	; send an error packet back please
	clr	r0			; not done
	return


gen.f:	spack	#'Y,paknum		; send a simple ACK
	call	clostt			; close the terminal up and exit
	mov	sp	,r0		; all done, return
	return



gen.l:	call	quochk			; see if they will be able to logout
	tst	r0			; well ?
	bne	10$			; not likely, but try anyway
	spack	#'Y,paknum		; assume we can log out
10$:	call	clostt			; close the terminal please
	bit	#log$op	,trace		; a logfile open now ?
	beq	20$			; no
	calls	close	,<#lun.lo>	; yes, close it please
20$:	call	logout			; and log out of the system
	call	opentt			; get the terminal back
	strlen	#200$			; logout failed
	spack	#'E,paknum,r0,#200$	; send an error message back then
	clr	r0			; not yet done
	return				; oops

	.enabl	lc
200$:	.asciz	/Logout failed - Quota exceeded/
	.even



gen.u:	sub	#120	,sp		; allocate a buffer for string
	mov	sp	,r1		; and point to it
	calls	dskuse	,<r1>		; get the string to print
	strlen	r1			; get the string length
	add	r1	,r0		; stuff a cr/lf in please
	movb	#cr	,(r0)+		; simple
	movb	#lf	,(r0)+		; ditto...
	clrb	@r0			; make it .asciz
	strlen	r1			; the new length
	spack	#'Y,paknum,r0,r1	; and send the data back
	add	#120	,sp		; and exit
	clr	r0			; not yet done
	return

	.sbttl	handle the request for erase (delete) and directory

gen.e:	mov	#packet+1,r1		; get the packet address
	unchar	(r1)+	,r2		; get the arguement length
	bne	10$			; non zero
	clrb	@r1			; zero, make the string null
10$:	call	cretmp			; create temporary log file
	bcs	100$			; oops
	calls	delete	,<r1,#lun.ou>	; do it
	save	<r0>			; save the error code please
	call	clotmp			; close the temp file up
	unsave	<r0>			; restore delete's error code
	tst	r0			; did it work ?
	beq	80$			; yes
	call	generr			; no, send the RMS error code over
	br	100$

80$:	dec	r1			; only delete one file ?
	bne	90$			; no, set up for extended reply
	copyz	#<packet+2>,#errtxt	; a simple reply for one file deleted
	strlen	#errtxt			; get the length so far
	add	#errtxt	,r0		; point to the end of it please
	copyz	#200$	,r0		; and copy some informative text
	strlen	#errtxt			; get the total length now
	spack	#'Y,paknum,r0,#errtxt	; and send a simple ACK packet
	br	100$			; bye

90$:	mov	#kertmp	,r0		; send over the delete log file
	call	xreply
100$:	clr	r0			; not done with the server yet
	return

200$:	.asciz	/ deleted/<cr><lf>	; some text to send
	.even



gen.d:	mov	#packet+1,r1		; get the packet address
	unchar	(r1)+	,r2		; get the arguement length
	bne	5$			; something was there
	clrb	@r1			; nothing was there, insure .asciz
5$:	call	cretmp			; create the temp file please
	bcs	100$			; oops
	calls	dodir	,<r1,#lun.ou>	; it worked
	call	clotmp			; close it and send the file over
	mov	#kertmp	,r0		; as a text reply
	call	xreply
100$:	clr	r0
	return





	.sbttl	do remote help command


gen.h:	call	cretmp			; create the temp listing file
	bcs	100$			; oops
	mov	#200$	,r2
10$:	tstb	@r2			; end of the text as of yet?
	beq	20$
	mov	#lun.ou	,r1		; no, set a unit number for putcr0
	movb	(r2)+	,r0		; and the character to send over
	call	putcr0			; write it to kermit.tmp
	br	10$			; next character for help text please
20$:	call	clotmp			; close the temporary file up now
	mov	#kertmp	,r0		; now send the extended reply over
	call	xreply			; do it
100$:	clr	r0			; not done with the server yet
	return


200$:	.ascii	/The following commands are available for the Kermit-11/<cr><lf>
	.ascii	/server.  To avoid ambiguity with local Kermit commands/<cr><lf>
	.ascii	/some of the  server commands will  need to be prefixed/<cr><lf>
	.ascii	/with the REMOTE keyword./<cr><lf>
	.byte	cr,lf
	.ascii	/BYE		Logout Kermit-11/<cr><lf>
	.ascii	/REMOTE COPY	Copy a file to another/<cr><lf>
	.ascii	/REMOTE DIR 	Prints a directory out/<cr><lf>
	.ascii	/REMOTE DISK	Prints the disk  space/<cr><lf>
	.ascii	/REMOTE ERASE	Delete the filename(s)/<cr><lf>
	.ascii	/FINISH		Exits Kermit-11 server/<cr><lf>
	.ascii	/GET 		Sends  the filename(s)/<cr><lf>
	.ascii	/REMOTE HELP	Prints this  help text/<cr><lf>
	.ascii	/REMOTE HOST	Execute a host command/<cr><lf>
	.ascii	/REMOTE RENAME	Rename old file to new/<cr><lf>
	.ascii	/REMOTE SPACE	Prints the disk  space/<cr><lf>
	.ascii	/REMOTE TYPE	Prints the filename(s)/<cr><lf>
	.ascii	/REMOTE WHO	Shows users logged  in/<cr><lf>
	.byte	cr,lf,0
	.even


	global	<clostt	,exit	,logout	,opentt	,paknum	,quochk>
	global	<lun.lo	,trace>




	.sbttl	the remote type command and who commands



gen.t:	mov	#packet+1,r1		; get the packet address
	tstb	@r1			; anything there ?
	beq	5$			; no, thats an error
	unchar	(r1)+	,r2		; get the arguement length
	bne	10$			; something was there
5$:	calls	error	,<#1,#200$>	; have to have something to type
	br	100$			; bye
10$:	mov	r1	,r0		; send the file over now
	call	xreply			; simple to do
100$:	clr	r0			; not done yet
	return

200$:	.asciz	/I need a filename to TYPE/<cr><lf>
	.even


gen.w:	call	cretmp			; get the temp file created  first
	bcs	100$			; oops
	calls	systat	,<#lun.ou>	; dump the systat out to disk now.
	tst	r0			; did it work ?
	beq	10$			; yes
	calls	error	,<#1,#200$>	; no, send an error packet over
	call	clotmp			; insure temp file is closed
	br	100$			; bye
10$:	call	clotmp			; close the temp file now
	mov	#kertmp	,r0		; and send an extended reply
	call	xreply			; simple to do
100$:	clr	r0			; not done yet
	return				; bye

200$:	.asciz	/SYSTAT failed/<cr><lf>


	.sbttl	do the server copy and rename functions



gen.k:	call	get2ar			; get pointers to 'from' and 'to'
	bcs	90$			; oops, send an error packet over
	calls	copy	,<r1,r2,#-1>	; copy the file now
	tst	r0			; did it work out ok ?
	bne	80$			; no
	sub	#50	,sp		; yes, formulate a simple ack
	mov	sp	,r2		; response telling them how many
	deccvt	r1,r2,#5		; blocks that we copied over
	add	#5	,r2		; point past the block count
	copyz	#200$	,r2		; copy a message and then ack it
	mov	sp	,r2		; point back to the start of buffer
	strlen	r2			; get the string length now
	spack	#'Y,paknum,r0,r2	; send the ack over
	add	#50	,sp		; pop the local buffer and exit
	br	100$			; bye

80$:	call	generr			; error, send RMS (sys) error text
	br	100$			; bye

90$:	calls	error	,<#1,#invarg>	; invalid arguments

100$:	clr	r0			; exit
	return				; bye

200$:	.asciz	/ blocks copied/<cr><lf>
	.even



;	RENAME

gen.r:	call	get2ar			; get pointers to 'from' and 'to'
	bcs	90$			; oops, send an error packet over
	calls	rename	,<r1,r2,#-1>	; rename the file(s) now
	tst	r0			; did it work out ok ?
	bne	80$			; no
	sub	#50	,sp		; yes, formulate a simple ack
	mov	sp	,r2		; response telling them how many
	deccvt	r1,r2,#5		; number of files that were renamed
	add	#5	,r2		; point past the block count
	copyz	#200$	,r2		; copy a message and then ack it
	mov	sp	,r2		; point back to the start of buffer
	strlen	r2			; get the string length now
	spack	#'Y,paknum,r0,r2	; send the ack over
	add	#50	,sp		; pop the local buffer and exit
	br	100$			; bye

80$:	call	generr			; error, send RMS (sys) error text
	br	100$			; bye

90$:	calls	error	,<#1,#invarg>	; invalid arguments

100$:	clr	r0			; exit
	return				; bye

200$:	.asciz	/ file(s) renamed/<cr><lf>
	.even



	.sbttl	create the server temp file


cretmp:	calls	create	,<#kertmp,#lun.ou,#text>
	tst	r0			; did the create for the temp
	beq	100$			; file work
	save	<r0>			; save the error number
	calls	syserr	,<r0,#errtxt>	; no
	calls	error	,<#2,#200$,#errtxt>; get the error text and send it
	unsave	<r0>			; keep the RMS error number around
	sec				; say it did not work
	return				; bye

100$:	clr	r0			; clc and clear r0 both
	clc
	return

200$:	.asciz	/Can't create KERMIT.TMP /
	.even

clotmp:	calls	close	,<#lun.ou>
	clr	r0
	return



generr:	calls	syserr	,<r0,#errtxt>	; send a system error E packet over
	calls	error	,<#1,#errtxt>	; simple to do
	clr	r0			; assume no errors and exit
	return



	.sbttl	get pointer for a two argument server command

;	input:	packet	what we just read as a server
;	output:	r1	first  argument address (in 'packet'), .asciz
;		r2	second argument address (in 'packet'), .asciz
;		carry	set on missing arg, clear if all is well and good
;
;	assumptions: the packet received is .asciz


get2ar:	save	<r3,r4>			; save work registers please
	mov	#packet+1,r3		; get the address of our parameters
	tstb	@r3			; a null. if so, thats an error
	beq	90$			; exit with carry set
	unchar	(r3)+	,r4		; get the length of the first arg
	beq	90$			; a null string, exit with error
	mov	r3	,r1		; not null, point to the first one
	add	r4	,r3		; point to the length field for 2nd
	tstb	@r3			; must not be null or zero
	beq	90$			; null, missing second argument
	unchar	(r3)+	,r4		; get the length of the last field
	beq	90$			; nothing is there, abort please
	mov	r3	,r2		; return a pointer to the second arg
	clrb	-(r3)			; insure the first argument is .asciz
	clc				; success at last
	br	100$			; exit please

90$:	sec				; failure, to try again someday
100$:	unsave	<r4,r3>			; pop the registers we used and exit
	return				; good bye




	.sbttl	talk to a remote server


remfin::clr	paknum			; packetnumber := 0
	call	seropn			; get the link line intialzied
	spack	#'G,paknum,#1,#200$	; send a generic F command
	rpack	r2,r3,#packet		; get an ack for it please
	cmpb	r1	,#'Y&137	; did the server like it
	beq	100$			; yes
	calls	error	,<#1,#210$>	; no, say so
100$:	call	clostt			; close up the remote link now
	return				; and back please


200$:	.byte	'F&137	,0
210$:	.asciz	/Can't get the remote KERMIT to FINISH/<cr><lf>
	.even



rembye::clr	paknum			; packetnumber := 0
	call	seropn			; get the link line intialzied
	spack	#'G,paknum,#1,#200$	; send a generic F command
	rpack	r2,r3,#packet		; get an ack for it please
	cmpb	r1	,#'Y&137	; did the server like it
	beq	100$			; yes
	cmpb	r1	,#'E&137	; what about an error packet
	bne	10$			; no
	calls	error	,<#1,#packet>	; yes, print the response
	br	100$			; exit
10$:	calls	error	,<#1,#210$>	; other error
100$:	call	clostt			; close up the remote link now
	return


200$:	.byte	'L&137	,0
210$:	.asciz	/Can't get the remote KERMIT to LOGOUT/<cr><lf>
	.even



remget::call	seropn			; get the link line intialzied
	call	sinfo			; exchange information please
	clr	paknum			; packet_number := 0
	strlen	#argbuf			; get the length of the filename
	spack	#'R,paknum,r0,#argbuf	; get the server to send this file
	calls	recsw	,<#'R>		; and call the receiver
10$:	call	clostt			; close up the remote link now
	return				; bye



remhos::call	seropn			; get the link line intialzied
	call	sinfo			; exchange information please
	clr	paknum			; packet_number := 0
	strlen	#argbuf			; get the length of the filename
	spack	#'C,paknum,r0,#argbuf	; get the server to send this file
	call	getres			; off to common code
;-	call	clostt			; insure closed
	return


	.sbttl	the remote space, dir, erase and help commands


remspa::calls	doremo	,<#'U,#1,#null>
	clr	r0
	return



remdir::calls	doremo	,<#'D,#1,@r5>
	clr	r0
	return


remtyp::calls	doremo	,<#'T,#1,@r5>
	clr	r0
	return


remwho::calls	doremo	,<#'W,#1,#null>
	clr	r0
	return


remera::calls	doremo	,<#'E,#1,@r5>
	clr	r0
	return


remhlp::calls	doremo	,<#'H,#1,#null>
	clr	r0
	return

remren::calls	doremo	,<#'R,#2,@r5,2(r5)>
	clr	r0
	return

remcop::calls	doremo	,<#'K,#2,@r5,2(r5)>
	clr	r0
	return


	global	<sinfo>


	.sbttl	carry out the remote command please

;	DOREMOTE handles most generic commands that may have
;	a variable response, such as a simple ACK ("Y") with
;	the  response in the data packet, an SINIT or an "X"
;	packet.


doremo:	clr	paknum			; generic command
	sub	#130	,sp		; allocate a buffer please
	mov	sp	,r2		; point to it
	movb	@r5	,@r2		; the generic command to execute
	bicb	#40	,(r2)+		; insure command is upper case
	mov	4(r5)	,r1		; get the first command argument
	strlen	r1			; get the length of it please
	tochar	r0	,(r2)+		; followed by len of first arg
	copyz	r1	,r2,#40		; copy the arglist over please
	cmp	2(r5)	,#1		; one or two arguments passed ?
	beq	30$			; only one
10$:	tstb	(r2)+			; two, so find the end so far
	bne	10$			; not yet
	strlen	6(r5)			; get the length of the second arg
	dec	r2			; point back to the null please
	tochar	r0	,(r2)+		; and copy the new length over
	copyz	6(r5)	,r2,#40		; copy the second arg over now

30$:	mov	sp	,r0		; point back to the command buffer
	calls	bufpak	,<r0,#cmdbuf>	; encoding the data as normal
	mov	r1	,r5		; save the encoded packet length
	add	#130	,sp		; pop the local buffer and exit
	call	seropn			; initialize the link first
	call	sinfo			; exchange things first
	clr	paknum			; start over now
	clr	numtry			; clear the retry counter please

	spack	#'G,paknum,r5,#cmdbuf	; send the command over please

getres:
50$:	rpack	r2,r3,#packet		; get the response from remote
	mov	r3	,paknum		; save the packet number please
	scan	r1	,#remrsp	; what to do with the response
	asl	r0			; get the index times 2
	jsr	pc	,@remdsp(r0)	; and dispatch on the response
	tst	r0			; try to read again ?
	bne	50$			; yes, we must have gotten a NAK
	call	clostt			; close the link for now
	clr	xmode			; no extended reply stuff now
	clr	xgottn			; we don't have any X packets
	clr	r0			; don't exit the server yet
	return				; or a timeout

remrsp:	.byte	'E&137	,'N&137	,'S&137	,'Y&137	,'X&137
	.byte	timout	,badchk	,0
	.even

remdsp:	.word	rem.$
	.word	rem.e	,rem.n	,rem.s	,rem.y	,rem.x
	.word	rem.t	,rem.ck




	.sbttl	routines for doremote


rem.t:	inc	numtry			; timeout error
	cmp	numtry	,#10		; been trying too hard ?
	bhi	10$			; yes, abort please
	mov	#1	,r0		; no, return code to do rpack again
	return
10$:	message	<Remote fails to respond to the command>,cr
	clr	r0			; ok
	return


rem.n:	inc	numtry			; got a NAK back from remote
	cmp	numtry	,#5		; been trying too hard ?
	bhi	10$			; yes, abort please
	spack	#'G,paknum,r5,#cmdbuf	; send the command over again please
	mov	#1	,r0		; no, return code to do rpack again
	return
10$:	message	<Remote NAK'ed the command 5 times>,cr
	clr	r0			; ok
	return


rem.ck:	inc	numtry			; got a NAK back from remote
	cmp	numtry	,#5		; been trying too hard ?
	bhi	10$			; yes, abort please
	spack	#'G,paknum,r5,#cmdbuf	; send the command over again please
	mov	#1	,r0		; no, return code to do rpack again
	return
10$:	message	<Bad checksum retry abort>,cr
	clr	r0			; ok
	return


rem.x:	mov	sp	,xmode		; set a global flag for this
	mov	sp	,xgottn		; we already have the x packet
	message	<Remote server response>,cr
	calls	rec.sw	,<#'F>		; yes, switch to receive DATA
	clr	xmode			; no longer want output to TI:
	clr	xgottn			; we don't have any X packets
	message				; a cr/lf
	tst	r0			; did the receive succeed ?
	beq	rxend			; yes
	message	<Receive data failed>,cr; no, please say so then
rxend:	clr	r0			; all done
	return


rem.s:	calls	rpar	,<#packet,r2>	; yes, handle the SINIT now
	calls	spar	,<#packet>	; and send my init things over
	spack	#'Y,paknum,sparsz,#packet
	incm64	paknum			; bump the packet number up mod 64
	calls	rec.sw	,<#'F>		; switch to get fileheader state
	clr	r0			; all done
	return


rem.y:	strlen	#packet			; any data in the field ?
	tst	r0			; if so, simply print it out
	bne	10$			; no, just exit
	return
10$:	message	<Remote ack: >
	print	#packet			; yes, print the text out please
	print	#crlf			; a cr/lf perhaps ?
	clr	r0			; all done
	return


rem.e:	calls	error	,<#1,#packet>	; yes, print the error text out
	clr	r0			; all done
	return				; and exit please

rem.$:	calls	error	,<#1,#200$>	; otherwise say they did not respond
	clr	r0
	return				; and exit please

200$:	.asciz	/Can't get the remote KERMIT to respond/
	.even


	global	<clostt	,seropn	,packet	,paknum	,sparsz	,xmode>
	global	<xgottn>



	.sbttl	initialize for a long (X) response for generic command


;	 Here is where we send an X packet back to the requesting Kermit
;	to  say that we are going to send an extended reply to it.  This
;	reply takes the form of a  normal file transfer but we will want
;	it to be printed on the user's terminal rather than go to a disk
;	file. Thus the use of the 'X' packet to start things off.


xreply:	copyz	r0	,#srcnam	; copy the filename to be sent
	clr	index			; wildcard filenumber := 0
	call	getnxt			; go do a directory lookup please
	tst	r0			; well, did the lookup work out ?
	beq	20$
5$:	call	generr			; no, send the error text over
	br	100$			; and abort
20$:	mov	sp	,xmode
	calls	sen.sw	,<#'F>		; and switch to senddata state
	clr	xmode			; no longer XTENDED reply mode
	clr	xgottn			; we don't have any X packets (?)
	clr	r0			; success (?)
100$:	return				; bye





	global	<getnxt	,index	,inopn	,lun.in	,size>


seropn:	save	<r1>
	call	opentt			; open the link for a server command
	tst	r0			; did it work ?
	beq	10$			; yes
	strlen	#200$			; no
	spack	#'E,paknum,r0,#200$	; try to send an error packet
	clr	r0			; no errors now
10$:	calls	cantyp	,<#ttname,#lun.ti>; flush any accumulated NAKS
	unsave	<r1>
	return				; bye


200$:	.asciz	/Init failed for link/
	.even


	global	<lun.ti	,paknum	,ttname>


	.end
