From:	CSBVAX::MRGATE!info-vax-request@kl.sri.com@SMTP 25-APR-1988 20:39
To:	ARISIA::EVERHART
Subj:	DTE_HAYES driver for SET HOST


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri 22 Apr 88 13:05:00-PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.28)
	id AA27442; Fri, 22 Apr 88 04:10:47 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 21 Apr 88 02:04:24 GMT
From: unmvax!charon!sdowdy@ucbvax.Berkeley.EDU  (Stephen Dowdy)
Organization: University of New Mexico, Albuquerque, NM
Subject: DTE_HAYES driver for SET HOST
Message-Id: <2886@charon.unm.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

I have seen several requests for DTE_HAYES drivers in the past, and
decided to post this one.  There are some flaky things with getting
a hayes to work on a vax, but it does work. (mostly)

Some of the original DTE_DF03.MAR and modifications got chopped off.
I originally got a copy from J Hobbs and modified it to do some other stuff
including supporting multiple dial etc.  I really wanted to do some more
stuff, but i didn't know MACRO, and spent quite some time getting it all
to work (while trying to figure out Vax Macro)... (and having fun with the
following problem) (don't rag on me for crummy macro coding, this was my
first attempt at vms system coding., and it works even!)

There are some important things to note when getting this to work.
The hayes will do something pretty bizzarre if it is in a certain mode.
If you have response codes enabled, as soon as the Hayes gets a DTR drop
from the vax, it sends "Hey, I lost the connection", which the VAX sees
as "Oh, Login request!" , after which it times out (30 seconds or so), and
the cycle repeats.  So Disable response codes in the dip switch settings.
They get turned on by the software during the connection, but the modem
appears to get reset to initial settings when the connection is closed.

So be careful how you set the dip switches.  This driver works fairly well,
in general, though i have seen the terminal port go into the endless
"hello/goodbye" cycle occasionally.

I didn't get a chance to clean it up and include some things i wanted to,
so take it as it is...

--stephen dowdy

................ Cut Here ......................
	.TITLE DTE_MT224 - SET HOST/DTE dialer module (MT224 Hayes Compatible)
	.IDENT	'X-1'
;++
;
; FACILITY:
;
;	SET HOST/DTE
;
; ABSTRACT:
;
;	Provide modem-specific support for autodialing on a MultiTech 224
;	Activated as a sharable image when
;		SET HOST ttcn: /DTE/DIAL=(number:string,MODEM_TYPE=MT224) 
;	is run.
;
; ENVIRONMENT:
;
;	VAX/VMS, user mode.
;
;--
;
;       Jake VanNoy, : 11-Apr-1984
;
; taken from DTE_DF03.MAR, modified by
;	J Hobbs 10-Jun-1985
;
;	Stephen Dowdy (UNM CIRT ACS ApSys)
;		added P,W,T to list of valid parameters, check on return
;		status, loops for checking status' on multi-dialtone
;		requests, etc...
;
; Installation / Assembly instructions:
;	MACRO DTE_MT224
;	LINK/SHARE DTE_MT224
;	COPY DTE_MT224.EXE SYS$SHARE:
;	INSTALL CREATE SYS$SHARE:DTE_MT224/OPEN/SHARE
;**

	.SBTTL	DECLARATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                            Include Files:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	$SHRDEF				; shared messages
	$STSDEF				; status fields

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                               Macros:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                           Equated Symbols:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

REM$_FACILITY	= ^X1FE
REM$_BADVALUE	= SHR$_BADVALUE!<REM$_FACILITY@16>
CR = 13
LF = 10

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                            Common Storage:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The MT224 command buffer allows 40 chars + "AT".
;; Several additional settings are invoked to force the MT224 to act in
;; a known fashion.
;; T   - Tone Dial
;; B1  - Force waits for Dial Tone
;; V0  - Enable digit response codes
;; X0  - Basic response set
;; Q0  - Enable response code emissions (temporarily)
;; It should be ensured that the modem is in a state where no spurious 
;; characters will be sent to the driver
;;

dial_string_desc:	.long	dial_string_str_len
			.long	0
dial_string_str:	.ascii	/ATTB1V0X0Q0D000000000000000000000000000000/<cr>
dial_string_str_len = .-dial_string_str

CONN_DESC:	.LONG		CONN_STR_LEN	; length
		.LONG		0		; will get filled in by code
CONN_STR:	.ASCII		<CR><LF>/Connection made to remote port/<CR><LF>
CONN_STR_LEN = .-CONN_STR

FAIL_DESC:	.LONG		FAIL_STR_LEN	; length
		.LONG		0		; will get filled in by code
FAIL_STR:	.ASCII		<CR><LF>/Failed to connect to remote port/<CR><LF>
FAIL_STR_LEN = .-FAIL_STR

read_desc:	.long	read_length
		.long	0
READ_BUFFER:	.BLKB	2			; read buffer
read_length = .-read_buffer

IOSB:		.LONG		0,0		; I/O status
READ_STATUS:	.LONG		0		; completion status

USER_CHAN:	.LONG		0		; command channel own storage


	.SBTTL	DTE_HAYES - autodial routine

;++
;
; FUNCTIONAL DESCRIPTION:
;
;	perform the necessary autodial protocol on an autodial modem
;
; CALLING SEQUENCE:
;
;	DIAL_ROUTINE (number_desc, port_chan, command_chan)
;
; INPUT PARAMETERS:
;
;	4(AP)	- descriptor of string specified in NUMBER:string
;	8(AP)	- channel number of port MODEM is connected to
;      12(AP)	- channel number of user's terminal
;
; IMPLICIT INPUTS:
;	NONE
;
; OUTPUT PARAMETERS:
;	NONE
;
; IMPLICIT OUTPUTS:
;	NONE
;
; COMPLETION CODES:
;
;	R0 - status
;
; SIDE EFFECTS:
;	NONE
;
;--

number 		= 4
port_chan	= 8
command_chan 	= 12

	.TRANSFER	DIAL_ROUTINE
	.MASK		DIAL_ROUTINE
	BRW	DIAL_ROUTINE+2

	.ENTRY	DIAL_ROUTINE,^M<R2,R3,R4>

	MOVZWL	command_chan(AP),user_chan	; save for later
	MOVL	number(AP),R2			; fetch address of descriptor
	MOVZWL	(R2),R3				; length of string
	MOVL	4(R2),R4			; address
	;
	; Loop through string to check for illegal characters
	;	
10$:
	CMPB	#^A/,/,(R4)			; "," is pause character
	BEQL	20$				; branch if match
	CMPB	#^A/P/,(R4)			; "P" is Pulse Dial
	BEQL	20$				; branch if match
	CMPB	#^A/T/,(R4)			; "T" is Tone Dial
	BEQL	20$				; branch if match
	CMPB	#^A/W/,(R4)			; "W" is Wait for Dial Tone
	BEQL	20$				; branch if match
;
	CMPB	#^A/0/,(R4)			; check for number
	BGTRU	30$				; Branch if less than legal
	CMPB	#^A/9/,(R4)			; check for number
	BLSSU	30$				; Branch if more than legal
20$:	INCL	R4				; next character
	SOBGTR	R3,10$				; legal character, loop
	BRB	40$				; continue, number ok
	; 
	; error in number string
	; 
30$:	PUSHL	number(AP)			; signal error
	PUSHL	#1				; number of FAO args
	PUSHL	#REM$_BADVALUE			; error type
	CALLS	#3,G^LIB$SIGNAL			; error
	MOVL	#REM$_BADVALUE!STS$M_INHIB_MSG,R0 ; return status
	RET					; return
40$:
	;
	; number string ok, continue.
	; queue read for status string
	;	
; first read for dialtone notification
	BSBW	READ_STR			; read status string
	BLBC	R0,100$				; exit on error
	;
	; Write string to modem
	;

	MOVL	number(AP), R2			; fetch descriptor address
	movzwl	(R2),r3
	movc5	r3,@4(r2),#^A/ /,#30,dial_string_str+12
	movab	dial_string_str,dial_string_desc+4
	movab	dial_string_desc,r2
	bsbw	write_str
	blbc	r0,100$

50$:
	$HIBER_S				; wait for read to complete

	MOVL	READ_STATUS,R0			; set status
	MOVZWL	#SS$_RETRY,R3			; load register
	CMPL	R3,R0				; check if another status needed
	BNEQ	100$				; Connected or failure

	BSBW	READ_STR			; read status string
	BLBC	R0,100$				; exit on error

	BRB	50$				; check on next status

100$:
	RET


..SBTTL	WRITE_STR - write string to port channel
;++
;
; FUNCTIONAL DESCRIPTION:
;
;	write a string to the DTE port
;
; CALLING SEQUENCE:
;
;	BSBW	WRITE_STR
;
; INPUT PARAMETERS:
;
;	R2 - address of descriptor to write
;
; COMPLETION CODES:
;
;	R0 - status
;
;--

WRITE_STR:

	$QIOW_S	-
		CHAN = port_chan(AP),-			; channel
		FUNC = #IO$_WRITEVBLK!IO$M_NOFORMAT,-	; write no format
		P1   = @4(R2),-				; address
		P2   = (R2)				; length
	RSB

..SBTTL	READ_STR - read status string from port
;++
;
; FUNCTIONAL DESCRIPTION:
;
;	Read the status string from the MODEM, allowing a maximum
;	of 60 seconds for the event to occur.
;	(sed) i changed this to 30, who wants to wait for a full
;	minute to find out it failed?
;
; CALLING SEQUENCE:
;
;	BSBW	READ_STR
;
; INPUT PARAMETERS:
;	NONE
;
; COMPLETION CODES:
;
;	R0 - status
;
;--
;	FUNC = #IO$_READVBLK!IO$M_TIMED!IO$M_PURGE!IO$M_NOECHO!IO$M_TRMNOECHO, -

READ_STR:

	$QIO_S -
		CHAN = port_chan(AP),-			; channel
	FUNC = #IO$_READVBLK!IO$M_TIMED!IO$M_PURGE!IO$M_NOECHO!IO$M_TRMNOECHO, -
		- ; read timed, purge
		IOSB = IOSB,-				; I/O status
		ASTADR = READ_DONE,-			; ast routine
		P1   = READ_BUFFER,-			; address
		P2   = #2,-				; length
		P3   = #30				; timeout
	RSB						; exit with status

..SBTTL	READ_DONE - ast for read completion
;++
;
; FUNCTIONAL DESCRIPTION:
;
;	Check for timeout or status character
;
; CALLING SEQUENCE:
;
;	CALLed as AST routine
;
; INPUT PARAMETERS:
;	NONE
;
; COMPLETION CODES:
;
;	R0 - status
;
;--

	.ENTRY	READ_DONE,^M<R2>

	MOVZWL	IOSB,R0			; get status of read
	BLBC	R0,100$			; branch if timeout

	MOVZWL	#SS$_RETRY, R0		; set for dialtone, retry status later

	MOVZBL	READ_BUFFER,R2		; fetch data

	CMPB	#^A/6/,R2		; DIALTONE detected?
	BEQL	100$			; wake up to queue next read

	CMPB	#^A/1/,R2		; CONNECT detected?
	BNEQ	10$			; branch if not

	MOVAB	conn_desc,R2		; set up string
	MOVAB	conn_str,4(R2)		; set up string
	BSBW	WRITE_STR_TO_USER	; tell user, ready
	BLBC	R0,100$			; exit on error
	MOVL	#SS$_NORMAL,R0		; ready
	BRB	100$			; exit
10$:
	MOVAB	fail_desc,R2		; set up string
	MOVAB	fail_str,4(R2)		; set up string
	BSBW	WRITE_STR_TO_USER	; tell user, ready
	MOVZWL	#SS$_HANGUP,R0		; status

100$:	MOVL	R0,READ_STATUS		; save status
	$WAKE_S				; wake main stream

	RET

..SBTTL	WRITE_STR_TO_USER - write string to command channel
;++
;
; FUNCTIONAL DESCRIPTION:
;
;	write a string to the user terminal channel
;
; CALLING SEQUENCE:
;
;	BSBW	WRITE_STR_TO_USER
;
; INPUT PARAMETERS:
;
;	R2 - address of descriptor to write
;
; COMPLETION CODES:
;
;	R0 - status
;
;--

WRITE_STR_TO_USER:

	$QIOW_S	-
		CHAN = user_chan,-			; channel
		FUNC = #IO$_WRITEVBLK,-			; write 
		P1   = @4(R2),-				; address
		P2   = (R2)				; length
	RSB

	.END
-- 
$!#######################################################################
$! stephen dowdy (UNM CIRT) Albuquerque, New Mexico, 87131 (505) 277-8044
$! Usenet:   {convex,ucbvax,gatech,csu-cs,anl-mcs}!unmvax!charon!sdowdy
$! BITNET:   sdowdy@unmb
$! Internet: sdowdy@charon.UNM.EDU
$!      Team SPAM in '87!            SPAAAAAAAAAAAAAAAAAAAAMMMMMMM!
$!#######################################################################
