1 /*
2   Copyright (C) 1997-2005  Dimitrios P. Bouras
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18    For author contact information, look in the README file.
19 */
20 
21 /* Constants for xisp, xispdial, rcio.c and xisprccv.c */
22 
23 #define MAXLEN_DESCR     32	/* configuration description string length */
24 #define MAXLEN_PHONE     64	/* phone string length */
25 #define MAXNUM_TELS       8	/* maximum telephone numbers in options */
26 #define MAXLEN_ACCOUNT   64	/* account number of characters */
27 #define MAXLEN_PASSWD    64	/* password characters */
28 #define MAXLEN_UNR       64	/* name/user/remote pppd opt arg maximum chars */
29 #define MAXDIG_RETRY      3	/* number of retries maximum digits */
30 #define MAXDIG_DELAY      3	/* inter-dialing delay seconds # maximum digits */
31 #define MAXDIG_CNWAIT     3	/* modem connection wait seconds # of digits */
32 #define MAXDIG_LCPWAIT    3	/* network connection wait seconds # of digits */
33 #define MAXDIG_CBDELAY    3	/* call-back delay seconds # maximum digits */
34 #define MAXNUM_SLINES    16	/* maximum number of saved script lines */
35 #define MAXLEN_SLINE     64	/* characters in each script line */
36 #define MAXLEN_MDMCMD    64	/* modem commands maximum length */
37 #define MAXLEN_MDMSTR    16	/* modem result strings maximum length */
38 #define MAXLEN_DEVICE    32	/* modem device name string length */
39 #define MAXDIG_BSDCOMP    2	/* BSD compression level number digits */
40 #define MAXLEN_DIALEXTRA  8	/* extra chars between "AT" and "D" commands */
41 #define MAXDIG_ASYNCMAP   8	/* pppd asyncmap number of digits */
42 #define MAXLEN_ESCAPE    16	/* pppd escape character list length */
43 #define MAXLEN_IP        15	/* all IP input strings length */
44 #define MAXDIG_MTRU       4	/* MTU and MRU maximum number of digits */
45 #define MAXLEN_TTPARM    64	/* xispterm parameter string maximum length */
46 #define MAXBUF_CHILD    128	/* buffer size for dialer output reads by xISP */
47 #define MAXNUM_RETRY     10	/* default total number of dialing tries */
48 #define MAXSEC_DELAY      5	/* default delay between dials */
49 #define MAXSEC_CBDELAY   60	/* default delay for call-back wait */
50 #define MAXSEC_CNWAIT    50	/* default maximum wait for modem connection */
51 #define MAXSEC_LCPWAIT   30	/* default maximum wait for network connection */
52 #define MINSEC_MODEM_TO  10	/* minimum timeout for modem connection */
53 #define MINSEC_LINK_TO   15 /* minimum timeout for link connection */
54 #define MAXLEN_PATH     256 /* maximum path length for all program paths */
55 #define MAXLEN_FNAME    512	/* maximum complete file-name string length */
56 #define MAXLEN_DNNAME    64	/* default domain name maximum string length */
57 #define MAXDIG_BAUDRATE   7 /* modem speed maximum digits */
58 #define MIN_COMPLEVEL     8 /* minimum (usefull) S/W compression level */
59 #define MAX_COMPLEVEL    15 /* maximum S/W compression level */
60 
61 /* xISP file names */
62 
63 #define RCFNAME      ".xisprc"		/* for all program options */
64 #define PIPEFNAME    ".xisppipe"	/* named pipe for reporting */
65 #ifdef ISPENV_USEVARS
66  #define ENVVAR      "XISPDIAL"		/* generated dialer environment var */
67 #else
68  #define ENVFNAME    ".xispenv"		/* generated dialer environment file */
69 #endif
70 #define SCRIPTFNAME  ".xispscript"	/* generated dialing script */
71 #define PAPFNAME     ".xisppap"		/* the login data file for PAP */
72 #define LOGDIRNAME   ".xisplogs"	/* directory holding xisp logs */
73 #define LOGFNROOT    "xisplog"		/* root-name for xisp log files */
74 #define COSTFNROOT   "xispcost"		/* root-name for xisp total cost files */
75 #define PTTFNAME     "xispPTTs"		/* the PTT data base file */
76 #define XISPUPNAME   ".xisp-up"		/* user's "ip-up" file */
77 #define XISPDOWNNAME ".xisp-down"	/* user's "ip-down" file */
78 #define XISPPIDFNAME ".xisppid"		/* file containing PID of running xisp */
79 
80 /* xISP/xispdial default paths and files. System defaults for
81    BINPATH, RUNDIR LIBPATH and OPTPATH are defined in Makefile */
82 
83 #ifndef PPPD_PATH
84  #define PPPD_PATH	 BINPATH					/* pppd executable */
85 #endif
86 #define PPPD         "/pppd"
87 #ifdef RUNDIR
88  #define RUN_PATH	 RUNDIR						/* pppd PID files */
89 #else
90  #define RUN_PATH	 ""
91 #endif
92 #ifndef LOCK_PATH
93  #define LOCK_PATH   PPPDLCKDIR					/* modem device lock file */
94 #endif
95 #ifndef CHAT_PATH
96  #define CHAT_PATH	 BINPATH					/* chat executable */
97 #endif
98 #define CHAT		 "/chat"
99 #define UTILS_PATH	 LIBPATH					/* xispterm and xispdial */
100 #define PPPD_CONNECT "/xispdial"				/* pppd connect prog */
101 #define TERMINAL     "/xispterm"				/* manual login terminal */
102 #define PIPE_PATH	 "/tmp"						/* named-pipe node */
103 #define PPPD_OPTIONS OPTPATH "/options.xisp"	/* default options file */
104 
105 /* Modem and communication defines */
106 
107 #ifndef MODEM_PATH
108  #define MODEM_PATH    "/dev/modem"			/* default modem device */
109 #endif
110 #define MAXNUM_SPEEDS   8					/* DTE<->DCE speeds: a subset */
111 #define MS_0            1200				/* of the "standard" ones */
112 #define MS_1            2400
113 #define MS_2            4800
114 #define MS_3            9600
115 #define MS_4            19200
116 #define MS_5            38400
117 #define MS_6            57600
118 #define MS_7            115200
119 #define MODEM_SPEED     MS_5				/* 38400 Baud set by default */
120 #define MIN_BAUDRATE    150					/* min and max custom */
121 #define MAX_BAUDRATE    1024000				/* Baud rates */
122 #define MODEM_INIT	    "AT"				/* default init string */
123 #define MODEM_RESET	    "ATZ"				/* default reset string */
124 #define MODEM_CONNECT   "CONNECT"			/* default connect string */
125 #define BSDCOMP         "bsdcomp"			/* pppd BSD compression option */
126 #define DIAL_EXTRA      ""					/* default extra dialing chars */
127 #define COMP_LEVEL      12					/* default S/W compression level */
128 #define PPPD_SASYNCMAP  "20A0000"			/* pppd asyncmap for software */
129 #define PPPD_HASYNCMAP  "00"				/* and hardware flow contol */
130 #define PPPD_ESCAPE     "FF"				/* default pppd escape list */
131 #define DEFLCOMP        "deflate"			/* pppd deflate compression opt */
132 
133 /* Manual terminal size defines */
134 
135 #define TERMW         30
136 #define MINCHAR_TERMW 20
137 #define TERMH         12
138 #define MINCHAR_TERMH  6
139 
140 /* TCP/IP defines */
141 
142 #define LOCAL_IP     "\x00\x00\x00\x00"		/* default local IP address */
143 #define LOCAL_IPSTR  "0.0.0.0"
144 #define REMOTE_IP    "\x00\x00\x00\x00"		/* default remote IP address */
145 #define REMOTE_IPSTR "0.0.0.0"
146 #define NETMASK      "\xFF\xFF\xFF\x00"		/* default netmask */
147 #define NETMASKSTR   "255.255.255.0"
148 #define DNS          "\x00\x00\x00\x00"		/* default DNS address */
149 #define DNS_IPSTR    "0.0.0.0"
150 #define MTU          1500					/* MTU and MRU defaults */
151 #define MRU          1500
152 
153 /* Operating mode options flags */
154 
155 #define MODEM_TONEDIAL	0x00000001
156 #define BSD_COMPRESS	0x00000002
157 #define HW_FLOWCTRL		0x00000004
158 #define ACCEPT_LOCALIP	0x00000008
159 #define ACCEPT_REMOTEIP	0x00000010
160 #define DEFAULT_ROUTE	0x00000020
161 #define MANUAL_LOGIN	0x00000040
162 #define PAP_LOGIN		0x00000080
163 #define AUTO_REDIAL		0x00000100
164 #define CALL_BACK		0x00000200
165 #define ESCAPE_ON		0x00000400
166 #define IP_UPDOWN		0x00000800
167 #define PAPS_LOGIN		0x00001000
168 #define CHAPS_LOGIN		0x00002000
169 #define CONNECT_BELL	0x00004000
170 #define STARTUP_DIAL    0x00008000
171 #define CBMAN_LOGIN		0x00010000
172 #define CB_NT_RAS		0x00020000
173 #define DEFL_COMPRESS	0x00040000
174 #define MODEM_ISDNDIAL	0x00080000
175 #define AUTO_DNS		0x00100000
176 #define DEFAULT_DOMAIN	0x00200000
177 
178 /* Default operating mode */
179 
180 #define OPER_OPTS (MODEM_TONEDIAL|BSD_COMPRESS|HW_FLOWCTRL| \
181 				   ACCEPT_LOCALIP|ACCEPT_REMOTEIP|DEFAULT_ROUTE)
182 
183 /* The data file structure for all xisp options */
184 
185 typedef struct {
186 	char descr[MAXLEN_DESCR+1];					/* ISP entry description */
187 	char account[MAXLEN_ACCOUNT+1];				/* user account name */
188 	char passwd[MAXLEN_PASSWD+1];				/* and password */
189 	char name[MAXLEN_UNR+1];					/* name/user pppd arg */
190 	char rname[MAXLEN_UNR+1];					/* and remotename pppd arg */
191 	unsigned char maxAttempts;					/* maximum dialing attempts */
192 	unsigned char sleepDelay;					/* delay between dials */
193 	unsigned char connectWait;					/* modem connection timeout */
194 	unsigned char LCPWait;						/* net connection timeout */
195 	unsigned char numPhones;					/* # of phone-number entries */
196 	char phone[MAXNUM_TELS][MAXLEN_PHONE+1];	/* phone number table */
197 	unsigned char numSlines;					/* # of script lines */
198 	char sline[2*MAXNUM_SLINES][MAXLEN_SLINE+1];/* script line table */
199 	unsigned char CBDelay;						/* delay for call-back dials */
200 	unsigned char numCBSlns;					/* # call-back script lines */
201 	char CBsln[2*MAXNUM_SLINES][MAXLEN_SLINE+1];/* call-back script table */
202 	unsigned char termW;						/* manual terminal width */
203 	unsigned char termH;						/* and height in characters */
204 	unsigned char CBtermW;						/* manual terminal size */
205 	unsigned char CBtermH;						/* for call-back connections */
206 	char CBphone[MAXLEN_PHONE+1];				/* NT-RAS call-back phone # */
207 	char modemDevice[MAXLEN_DEVICE+1];			/* modem device path */
208 	unsigned int modemSpeed;					/* DTE<->DCE Baud rate */
209 	char modemReset[MAXLEN_MDMCMD+1];			/* modem reset command */
210 	char modemInit[MAXLEN_MDMCMD+1];			/* modem init command */
211 	char modemConnect[MAXLEN_MDMCMD+1];			/* modem connect string */
212 	unsigned long operOpts;						/* operating options flags */
213 	char dialExtra[MAXLEN_DIALEXTRA+1];			/* dialing command char(s) */
214 	unsigned char compLevel;					/* SW compression level */
215 	char asyncmap[MAXDIG_ASYNCMAP+1];			/* pppd asyncmap */
216 	char escape[MAXLEN_ESCAPE+1];				/* and escape options */
217 	unsigned char localIP[4];					/* local IP entry */
218 	unsigned char remoteIP[4];					/* remote IP entry */
219 	unsigned char netmask[4];					/* netmask entry */
220 	unsigned char dns1[4];						/* primary DNS entry */
221 	unsigned char dns2[4];						/* secondary DNS entry */
222 	unsigned int mtu;							/* the MTU */
223 	unsigned int mru;							/* and the MRU */
224 	char domainname[MAXLEN_DNNAME+1];			/* default domain name */
225 	unsigned char ispPTT;						/* PTT selected for ISP */
226 	unsigned char ispZone;						/* and its default zone */
227 } xisprc_t;
228 
229 #define XISPRC_DEFAULT {{0},{0},{0},{0},{0},MAXNUM_RETRY,MAXSEC_DELAY,\
230 						MAXSEC_CNWAIT,MAXSEC_LCPWAIT,0,{{0}},0,{{0}},\
231 						MAXSEC_CBDELAY,TERMW,TERMH,MODEM_DEVICE,\
232 						MODEM_SPEED,MODEM_RESET,MODEM_INIT,OPER_OPTS,\
233 						DIAL_EXTRA,COMP_LEVEL,PPPD_HASYNCMAP,PPPD_ESCAPE,\
234 						LOCAL_IP,REMOTE_IP,NETMASK,DNS,DNS,MTU,MRU,{0},\
235 						PTT_GR_EPAK,0}
236 
237 /* Logging mode options flags */
238 
239 #define LOG_NONE		0x0001
240 #define LOG_WEEKLY 		0x0002
241 #define LOG_MONTHLY		0x0004
242 #define LOG_BIMONTHLY	0x0008
243 #define COST_READOUT	0x0010
244 #define LOG_HINTS		0x1000
245 
246 /* Default logging mode */
247 
248 #define LOG_OPTS (LOG_NONE|LOG_HINTS)
249 
250 /* Associated strings */
251 
252 #define RTIME_STR		" Time\n On-Line:"
253 #define RCOST_STR		" Cost\n Charged:"
254 #define CUNIT_STR		"(seconds per unit)"
255 #define CTIME_STR		"(%s per minute)"
256 
257 /* The global information structure */
258 
259 typedef struct {
260 	unsigned char numISPs;			/* number of ISPs in .xisprc */
261 	unsigned char dfltISP;			/* default ISP to select after startup */
262 	unsigned char numPTTs;			/* total number of PTTs in database */
263 	unsigned char costPTT;			/* total cost currency def'ed in this PTT */
264 	unsigned short logOpts;			/* logging options flags */
265 	char pppdPath[MAXLEN_PATH+1];	/* path to the pppd daemon */
266 	char runPath[MAXLEN_PATH+1];	/* path to the pppd process ID files */
267 	char lockPath[MAXLEN_PATH+1];	/* path to the modem device lock file */
268 	char chatPath[MAXLEN_PATH+1];	/* path to the chat utility */
269 	char utilsPath[MAXLEN_PATH+1];	/* path to xispdial and xispterm */
270 	char pipePath[MAXLEN_PATH+1];	/* path to the xisp named-pipe node */
271 } glob_t;
272 
273 #define GLOB_DEFAULT {0, 0, MAXNUM_PTT, PTT_GR_EPAK, LOG_OPTS, PPPD_PATH, \
274 					  RUN_PATH, LOCK_PATH, CHAT_PATH, UTILS_PATH, PIPE_PATH};
275 
276 /* Connection mode basic types (ORed for combinations) */
277 
278 #define SCRIPT_DIALIN		0x01
279 #define SCRIPT_CALLBACK		0x02
280 #define MANUAL_DIALIN		0x04
281 #define MANUAL_CALLBACK		0x08
282 #define AUTH_DIALIN			0x10
283 #define AUTH_CALLBACK		0x20
284 #define NT_RAS_DIALIN		0x40
285 #define NT_RAS_CALLBACK		0x80
286 
287