1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25#ifndef __CCLENGINE__
26#define __CCLENGINE__
27
28
29
30/* ccl commands	*/
31enum
32{
33	cNoCmd			= 0,
34	cComment		= 1,
35	cCCLScript		= 2,
36	cOriginateLabel		= 3,
37	cAnswerLabel		= 4,
38	cHangUpLabel		= 5,
39	cScriptLabel			= 6,
40	cAsk			= 7,
41	cChrDelay		= 8,
42	cCommunicatingAt	= 9,
43	cDecTries		= 10,
44	cDTRSet			= 11,
45	cDTRClear		= 12,
46	cExit			= 13,
47	cFlush			= 14,
48	cHSReset		= 15,
49	cIfAnswer		= 16,
50	cIfOriginate		= 17,
51	cIfStr			= 18,
52	cIfTries		= 19,
53	cIncTries		= 20,
54	cJump			= 21,
55	cJSR			= 22,
56	cLBreak			= 23,
57	cLogMsg			= 24,	// undocumented.  use cNote.  KW
58	cMatchClr		= 25,
59	cMatchRead		= 26,
60	cMatchStr		= 27,
61	cNote			= 28,
62	cPause			= 29,
63	cReturn			= 30,
64	cSBreak			= 31,
65	cSerReset		= 32,
66	cSetSpeed		= 33,
67	cSetTries		= 34,
68	cUserHook		= 35,
69	cWrite			= 36,
70	cMonitorLine		= 37,
71	cDebugLevel		= 38,
72
73	cFirstCmd		= cComment,
74	cLastCmd		= cDebugLevel
75};
76
77/* ccl varStrings	*/
78enum				// for varIndex
79{
80	vsRangeStart		= 1,
81	vsDialString		= 1,		// full dial string
82	vsModemSpeaker		= 2,		// modem speaker flag
83	vsTonePulse		= 3,		// tone/pulse dialing
84	vsErrorCorrection	= 4,		// error correction
85	vsDataCompression	= 5,		// data compression
86	vsDialMode		= 6,		// dialing mode
87	vsDialString1		= 7,		// first dial string fragment
88	vsDialString2		= 8,		// second dial string fragment
89	vsDialString3		= 9,		// third dial string fragment
90	vsAsk			= 10,		// string returned from above
91	vsUserName		= 11,		// username for chat script
92	vsPassWord		= 12,		// password for chat script
93
94	//Extended varString range (^2 doesn't appear in existing dial strings)
95	vsConnectSpeed		= 20,		// for solving flakiness
96	vsInit			= 21,		// initialization AT command
97
98	//GPRS arguments
99	vsAPN	    		= 22,		// Access Point Name
100	vsCID   		= 23,		// Connection ID
101
102	//Reserved (Custom Reset? Hangup? Dial?)
103	vsReserved1		= 24,
104	vsReserved2		= 25,
105	vsReserved3		= 26,
106
107	//undefined arguments passed from plist to script
108	vsString27		= 27,
109	vsString28		= 28,
110	vsString29		= 29,
111	vsString30		= 30,
112
113	vsMax			= 30		// total number of var strings
114};
115/* parameter counts	*/
116enum
117{
118	kHSResetParamCount	= 6,
119	kIfStrParamCount	= 3,
120	kIfTriesParamCount	= 2,
121	kSerResetParamCount	= 4
122};
123
124/* miscellaneous constants	*/
125
126#define MAXLABELS		128
127// big maxMatch values slow matching when there are no matches
128// some memory is also allocated, but not a Str255 ;)
129#define maxMatch		96		// was 16 in 1.0 (MacOS 6?)
130#define	cclNestingLimit		16
131
132#define SHORTBREAK		0x000001F4	// 0.5 secs = 500 msecs = 0x000001F4
133#define LONGBREAK		0x00000DAC	// 3.5 secs = 3500 msecs = 0x00000DAC
134
135#define	DTR_SET			17		// control opcode for setting dtr
136#define DTR_CLEAR		18		// control opcode for clearing dtr
137
138#define kMaxRequeuedDataSize	64		// OT won't allocate anything less than 64
139
140/* recognized types of modem compression - all other values are	*/
141/* reserved for specific types of compression			*/
142
143#define	cclCompress_None	0		// no compression
144#define	cclCompress_Unspecified	1		// unspecified compression
145
146/* recognized types of modem error correction protocol - all other values	*/
147/* are reserved for specific protocols										*/
148
149#define	cclProtocol_None	0		// no error correction Protocol
150#define	cclProtocol_Unspecified	1		// unspecified error correction Protocol
151#define	cclProtocol_MNP10	2		// MNP-10 error correction Protocol
152
153#define ACTIVITY_LOG		1		// NOTE goes to Activity Log.
154#define STATUS_WINDOW		2		// NOTE goes to Status Window.
155
156/* ascii codes */
157enum
158{
159	ENTER			= 0x03,		/* ascii code for enter				*/
160	BACK_SPACE		= 0x08,		/* ascii code for back space			*/
161	TABUL			= 0x09,		/* ascii code for tab				*/
162	NL			= 0x0A,		/* ascii code for line feed			*/
163	CR			= 0x0D,		/* ascii code for carriage return		*/
164	PERIOD			= 0x2E,		/* ascii code for .				*/
165	DOT			= 0xA5,		/* ascii code for �				*/
166	LEFTARROW		= 0x1C,
167	RIGHTARROW		= 0x1D,
168	UPARROW			= 0x1E,
169	DOWNARROW		= 0x1F,
170
171	/* control characters	*/
172
173	chrETX			= 0x03,
174	chrBS			= 0x08,
175	chrHT			= 0x09,
176        chrNL			= 0x0A,
177        chrCR			= 0x0D,
178	chrFS			= 0x1C,
179	chrGS			= 0x1D,
180	chrRS			= 0x1E,
181	chrUS			= 0x1F,
182	chrSpace		= 0x20,
183	chrDblQuote		= 0x22,
184	chrQuote		= 0x27,
185	chrComma		= 0x2C,
186	chrSemiColon		= 0x3B,
187	chrBackSlash		= 0x5C,
188	chrCaret		= 0x5E,
189	chrPassWord		= 0xA5
190};
191
192
193/* ccl control flags	*/
194enum
195{
196	cclAsk			= 0x0001,	/* set when @ASK command is pending */
197	cclPlaying		= 0x0002,	/* script is currently playing */
198	cclWantAbort		= 0x0004,	/* available for recycling */
199	cclMatchReadAbort	= 0x0008,	/* available for recycling */
200	cclSysHeap		= 0x0010,	/* available for recycling */
201	cclAskEnable		= 0x0020,	/* Set if the Ask command is enabled */
202	cclReOriginateMode	= 0x0040,	/* set for reconnecting after disconnect */
203	cclTimerPosted		= 0x0080,	/* available for recycling */
204	cclDisabledfClientQ	= 0x0100,	/* set in DoDataIndication, reset in DoConnectResponse */
205	cclBoundToAnswer	= 0x0200,	/* set so we can return to Answering after a connection */
206	cclAnswerConnFailed	= 0x0400,	/* Set when a conn_req failed in Answer mode */
207	cclAnswerMode		= 0x0800,	/* Set when we want to answer an incoming call */
208	cclPrepScriptFailed	= 0x1000,	/* Set when pre-flight of a script fails */
209	cclMatchPending		= 0x2000,	/* Set for a pending matchread */
210	cclOriginateMode	= 0x4000,	/* Set when we want to originate an outgoing call */
211	cclHangupMode		= 0x8000	/* Set when we want to hangup the modem */
212};
213
214
215#define MAX_SCRIPT_SIZE		32000	// max number of characters in the script
216#define	MAX_SCRIPT_LINES	32000	// max number of lines in a script
217
218
219typedef struct TRMatchStrInfo
220{
221	u_int8_t		*matchStr;		// pointer to the match string
222	char		delimiterChar;		// string delimiter, " or '
223        u_int8_t		matchStrIndex;		// index of next char in match string
224	u_int8_t		*varStr;		// pointer to var string being compared
225	u_int8_t		inVarStr;		// flag when matching var string
226        u_int8_t		varStrIndex;		// index of next char in var string
227	char		varStrSize;		// size of var string
228	short		matchLine;		// line to jump to on match
229} TRMatchStrInfo, *TPMatchStrInfo;
230
231
232
233typedef struct TRScriptVars
234{
235	unsigned short	ctlFlags;		// CCL control flags
236	u_int32_t	serialSpeed;		/* the last speed the serial driver was set to	*/
237	char		maskStringId;		/* varString subject to bullet masking	*/
238	unsigned char	maskStart;		/* starting mask character position		*/
239	unsigned char	maskStop;		/* stopping mask character position		*/
240	short		theAbortErr;		/* result code for the abort			*/
241	unsigned char	modemReliability;	/* type of reliability negotiated by modem	*/
242	unsigned char	modemCompression;	/* type of compression negotiated by modem	*/
243	void		*commands;		// ptr to ccl commands
244	short		answerLine;		// index to answer entry
245	short		originateLine;		// index to originate entry
246	short		hangUpLine;		// index to hangUp entry
247	u_int32_t	pauseTimer;		// Value of the pause timer
248	u_int32_t	chrDelayValue;		// character delay value
249	u_int8_t	*script;		// ptr to CCL script
250	u_int8_t	scriptPrepped;		// true if PrepScript has been called
251	u_int8_t	scriptPrepFailed;	// true if PrepScript fails; used in Connect/Disconnect.
252	u_int32_t	scriptAllocSize;	// byte size of allocation for CCL script
253	u_int32_t	scriptSize;		// byte size of CCL script
254	u_int16_t	lineCount;		// number of lines in the script
255	u_int16_t	*indexTable;		// ptr to script line index table
256	u_int16_t	scriptLineIndex;	// index into current script line
257	u_int16_t	scriptLine;		// index to current script line
258	u_int8_t	*scriptLinePtr;		// pointer to current script line
259	u_int8_t	scriptLineSize;		// size, in bytes of current script line
260	u_int32_t	loopCounter;		// just what you think it is
261	short		labels[MAXLABELS];	// script line indices for labels
262	TRMatchStrInfo	matchStr[ maxMatch];	// match string information for each match string
263	u_int8_t	strBuf[256];		// buffer used for temorary string storage
264	u_int16_t	askLabel;		// label to jump to if user cancels ask dialog
265        ushort		stack[cclNestingLimit];	// stack used for subroutine jumps
266        u_int32_t	topOfStack;		// index of top of stack
267	u_int8_t	writeBufIndex;		// index into current write request
268	u_int8_t	logMaskOn;		// tells whether to mask sensitive varString text when logging
269} TRScriptVars, *TPScriptVars;
270
271
272#endif	/* __CCLENGINE__ */
273