1 /*	$Id$ */
2 /*
3  * Copyright (c) 1990-1996 Sam Leffler
4  * Copyright (c) 1991-1996 Silicon Graphics, Inc.
5  * HylaFAX is a trademark of Silicon Graphics
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and
8  * its documentation for any purpose is hereby granted without fee, provided
9  * that (i) the above copyright notices and this permission notice appear in
10  * all copies of the software and related documentation, and (ii) the names of
11  * Sam Leffler and Silicon Graphics may not be used in any advertising or
12  * publicity relating to the software without the specific, prior written
13  * permission of Sam Leffler and Silicon Graphics.
14  *
15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  */
26 #ifndef _CLASS2_
27 #define	_CLASS2_
28 /*
29  * Base class for a Class 2 and Class 2.0 Modem Drivers.
30  */
31 #include "FaxModem.h"
32 #include <stdarg.h>
33 
34 class Class2Modem : public FaxModem {
35 protected:
36     fxStr	classCmd;		// set class command
37     fxStr	cqCmds;			// copy quality setup commands
38     fxStr	tbcCmd;			// modem-host communication mode command
39     fxStr	crCmd;			// enable receiving command
40     fxStr	phctoCmd;		// set Phase C timeout command
41     fxStr	bugCmd;			// enable HDLC tracing command
42     fxStr	lidCmd;			// set local ID command
43     fxStr	dccCmd;			// set configuration parameters command
44     fxStr	dccQueryCmd;		// modem capabilities query command
45     fxStr	disCmd;			// set session parameters command
46     fxStr	cigCmd;			// set polling ID string command
47     fxStr	splCmd;			// set polling request command
48     fxStr	nrCmd;			// negotiation message reporting control
49     fxStr	pieCmd;			// procedure interrupt enable control
50     fxStr	borCmd;			// set bit order command
51     fxStr	abortCmd;		// abort session command
52     fxStr	ptsCmd;			// set page status command
53     fxStr	ptsQueryCmd;		// query page status command
54     fxStr	minspCmd;		// set minimum transmit speed command
55     fxStr	apCmd;			// set address&polling caps. command
56     fxStr	saCmd;			// set subaddress command
57     fxStr	paCmd;			// set selective polling address command
58     fxStr	pwCmd;			// set password command
59     fxStr	noFlowCmd;		// no flow control command
60     fxStr	softFlowCmd;		// software flow control command
61     fxStr	hardFlowCmd;		// hardware flow control command
62     u_int	serviceType;		// modem service required
63     u_int	modemCQ;		// copy quality capabilities mask
64     u_int	sendCQ;			// sending copy quality capabilities mask
65 
66     bool	xmitWaitForXON;		// if true, wait for XON when sending
67     bool	hostDidCQ;		// if true, copy quality done on host
68     bool	hasPolling;		// if true, modem does polled recv
69     bool	useExtendedDF;		// if true, modem has T.32-A data format extension
70     bool	useJP;			// if true, modem has JP +FCC parameter option
71     char	recvDataTrigger;	// char to send to start recv'ing data
72     char	hangupCode[5];		// hangup reason (from modem)
73     bool	hadHangup;		// true if +FHNG:/+FHS: received
74     fxStr	lid;			// prepared local identifier string
75     int		imagefd;		// file descriptor for raw image data
76 
77 // modem setup stuff
78     virtual bool setupModem(bool isSend = true);
79     virtual bool setupModel(fxStr& model);
80     virtual bool setupRevision(fxStr& rev);
81     virtual bool setupDCC(bool enableV34 = true, bool enableV17 = true);
82     virtual bool setupClass2Parameters(bool enableV34 = true, bool enableV17 = true);
83     virtual bool setupFlowControl(FlowControl fc);
84 // transmission support
85     bool	dataTransfer();
86     bool	sendRTC(Class2Params params);
87     bool	sendPageData(TIFF* tif, u_int pageChop, bool cover);
88 
89     virtual bool sendPage(TIFF* tif, u_int pageChop, bool cover) = 0;
90     virtual bool pageDone(u_int ppm, u_int& ppr) = 0;
91 // reception support
92     const AnswerMsg* findAnswer(const char*);
93     bool	recvDCS(const char*);
94     bool	recvPageData(TIFF*, Status& eresult);
95     bool	recvPPM(TIFF*, int& ppr);
96     bool	parseFPTS(TIFF*, const char* cp, int& ppr);
97     void	abortPageRecv();
98 // miscellaneous
99     enum {			// Class 2-specific AT responses
100 	AT_FHNG		= 100,	// remote hangup
101 	AT_FCON		= 101,	// fax connection status
102 	AT_FPOLL	= 102,	// document available for polling status
103 	AT_FDIS		= 103,	// DIS received status
104 	AT_FNSF		= 104,	// NSF received status
105 	AT_FCSI		= 105,	// CSI received status
106 	AT_FPTS		= 106,	// post-page status
107 	AT_FDCS		= 107,	// DCS received status
108 	AT_FNSS		= 108,	// NSS received status
109 	AT_FTSI		= 109,	// TSI received status
110 	AT_FET		= 110,	// post-page-response status
111 	AT_FVO		= 111,	// voice transition status
112 	AT_FSA		= 112,	// subaddress status
113 	AT_FPA		= 113,  // polling address status
114 	AT_FPW		= 114	// password status
115     };
116     virtual ATResponse atResponse(char* buf, long ms = 30*1000) = 0;
117     bool	waitFor(ATResponse wanted, long ms = 30*1000);
118     fxStr	stripQuotes(const char*);
119 // hangup processing
120     void	processHangup(const char*);
121     bool	isNormalHangup();
122     const char*	hangupCause(const char* code);
123     const Status&	hangupStatus(const char* code);
124     void	tracePPR(const char* dir, u_int ppr);
125     void	tracePPM(const char* dir, u_int ppm);
126 // class 2 command support routines
127     bool	class2Cmd(const fxStr& cmd, int a0,
128 		    ATResponse = AT_OK, long ms = 30*1000);
129     bool	class2Cmd(const fxStr& cmd, const fxStr& a0,
130 		    ATResponse = AT_OK, long ms = 30*1000);
131     bool	class2Cmd(const fxStr& cmd, const Class2Params&, bool isDCC,
132 		    ATResponse =AT_OK, long ms = 30*1000);
133 // parsing routines for capability&parameter strings
134     bool	parseClass2Capabilities(const char* cap, Class2Params&, bool isDIS);
135     bool	parseRange(const char*, Class2Params&);
136     const char* skipStatus(const char*);
137 
138     Class2Modem(FaxServer&, const ModemConfig&);
139 public:
140     virtual ~Class2Modem();
141 
142 // send support
143     bool	sendSetup(FaxRequest&, const Class2Params&, Status& eresult);
144     CallStatus	dialResponse(Status& eresult);
145     FaxSendStatus getPrologue(Class2Params&, bool&, Status& eresult, u_int&);
146     FaxSendStatus sendPhaseB(TIFF* tif, Class2Params&, FaxMachineInfo&,
147 		    fxStr& pph, Status& eresult, u_int& batched, PageType pt);
148     void	sendAbort();
149 
150 // receive support
151     bool	setupReceive();
152     bool	recvBegin(Status& eresult);
153     bool	recvEOMBegin(Status& eresult);
154     bool	recvPage(TIFF*, u_int& ppm, Status& eresult, const fxStr& id);
155     bool	recvEnd(Status& eresult);
156     void	recvAbort();
157     void	pokeConfig(bool isSend);
158 
159 // polling support
160     bool	requestToPoll(Status& eresult);
161     bool	pollBegin(const fxStr& cig, const fxStr& sep, const fxStr& pwd,
162 		    Status& eresult);
163 
164 // miscellaneous
165     bool	faxService(bool enableV34, bool enableV17);	// switch to fax mode (send)
166     bool	reset(long ms);			// reset modem
167     void	setLID(const fxStr& number);	// set local id string
168     bool	supportsPolling() const;	// modem capability
169 };
170 #endif /* _CLASS2_ */
171