386BSD 0.1 development
[unix-history] / usr / src / libexec / uucp / port.h
CommitLineData
af364716
WJ
1/* port.h
2 Header file for routines which manipulate ports.
3
4 Copyright (C) 1991, 1992 Ian Lance Taylor
5
6 This file is part of the Taylor UUCP package.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 The author of the program may be contacted at ian@airs.com or
23 c/o AIRS, P.O. Box 520, Waltham, MA 02254.
24
25 $Log: port.h,v $
26 Revision 1.13 1992/03/12 19:56:10 ian
27 Debugging based on types rather than number
28
29 Revision 1.12 1992/03/10 21:47:39 ian
30 Added protocol command for ports
31
32 Revision 1.11 1992/03/08 04:56:21 ian
33 Peter da Silva: added ``lockname'' command for ports
34
35 Revision 1.10 1992/03/04 00:36:44 ian
36 Michael Richardson: better chat script debugging
37
38 Revision 1.9 1992/02/08 03:54:18 ian
39 Include <string.h> only in <uucp.h>, added 1992 copyright
40
41 Revision 1.8 1991/12/17 23:14:08 ian
42 T. William Wells: allow dialer complete and abort to be chat scripts
43
44 Revision 1.7 1991/12/15 03:42:33 ian
45 Added tprocess_chat_cmd for all chat commands, and added CMDTABTYPE_PREFIX
46
47 Revision 1.6 1991/11/14 03:20:13 ian
48 Added seven-bit and reliable commands to help when selecting protocols
49
50 Revision 1.5 1991/11/13 20:38:00 ian
51 Added TCP port type for connections over TCP
52
53 Revision 1.4 1991/11/11 23:47:24 ian
54 Added chat-program to run a program to do a chat script
55
56 Revision 1.3 1991/11/11 16:59:05 ian
57 Eliminate fread_port_info, allow NULL pflock arg to ffind_port
58
59 Revision 1.2 1991/11/11 00:39:45 ian
60 Open port in seven bit mode, added fport_set to change to eight bit
61
62 Revision 1.1 1991/09/10 19:47:55 ian
63 Initial revision
64
65 */
66
67#ifndef PORT_H
68
69#define PORT_H
70
71#include "sysdep.h"
72
73/* Information kept about using stdin as a port. */
74
75struct sstdin_port
76{
77 struct ssysdep_stdin_port s;
78};
79
80/* The smodem_port structure holds the information we keep about a modem
81 port. */
82
83struct smodem_port
84{
85 /* The device name. If NULL, use the port name instead. */
86 const char *zdevice;
87 /* The device name to output dialer instructions to. If NULL, use
88 the normal port. */
89 const char *zdial_device;
90 /* The default baud rate. */
91 long ibaud;
92 /* The low baud rate, if a range is used. */
93 long ilowbaud;
94 /* The high baud rate, if a range is used. */
95 long ihighbaud;
96 /* Whether to wait for carrier detect after dialing. */
97 boolean fcarrier;
98 /* The name of the dialer to use. */
99 const char *zdialer;
100 /* Specific dialer information, if zdialer is NULL. */
101 struct sdialer *qdialer;
102 /* System dependent modem port stuff. */
103 struct ssysdep_modem_port s;
104};
105
106/* Information kept about a direct port. */
107
108struct sdirect_port
109{
110 /* The device to use (if NULL, use the port name). */
111 const char *zdevice;
112 /* The baud rate to communicate at. */
113 long ibaud;
114 /* System dependent direct port stuff. */
115 struct ssysdep_direct_port s;
116};
117
118#if HAVE_TCP
119
120/* Information kept about a TCP port. */
121
122struct stcp_port
123{
124 /* The file descriptor. */
125 int o;
126 /* The TCP port number to use. */
127 const char *zport;
128};
129
130#endif /* HAVE_TCP */
131
132/* Types of ports. The order of this enumeration must be the same
133 as the initializer for asPortcmds and azPtype_names. */
134
135enum tporttype
136{
137 PORTTYPE_STDIN,
138 PORTTYPE_MODEM,
139 PORTTYPE_DIRECT
140#if HAVE_TCP
141 , PORTTYPE_TCP
142#endif
143};
144
145/* Port settings. Currently we only have seven bit and eight bit
146 ports. The only real difference between these is that seven bit
147 ports can do XON/XOFF. */
148
149enum tportsetting
150{
151 PORTSETTING_EIGHT,
152 PORTSETTING_SEVEN
153};
154
155/* Reliability bits. These bits are used to decide which protocol to
156 run. A given protocol will have a set of these bits, and each of
157 them must be turned on for the port before we will permit that
158 protocol to be used. Of course, this can always be overridden by
159 using the ``protocols'' command in the system file. Reliability
160 bits can be specified by both ports and dialers. */
161
162/* Whether a set of reliability bits is given (0 means no
163 information). */
164#define RELIABLE_SPECIFIED (01)
165
166/* Whether the connection is eight bit transparent. */
167#define RELIABLE_EIGHT (02)
168
169/* Whether the connection is error-free. */
170#define RELIABLE_RELIABLE (04)
171
172/* Whether the connection is end-to-end reliable (e.g. TCP). */
173#define RELIABLE_ENDTOEND (010)
174
175/* Information kept about a port. */
176
177struct sport
178{
179 /* The name of the port. */
180 const char *zname;
181 /* The type of the port. */
182 enum tporttype ttype;
183 /* The protocol string for the port. */
184 const char *zprotocols;
185 /* The number of protocol parameter entries. */
186 int cproto_params;
187 /* The protocol parameter string. */
188 struct sproto_param *qproto_params;
189 /* The set of reliability bits. */
190 int ireliable;
191 /* The lock file name to use. */
192 const char *zlockname;
193 /* The type specific information. */
194 union
195 {
196 struct sstdin_port sstdin;
197 struct smodem_port smodem;
198 struct sdirect_port sdirect;
199#if HAVE_TCP
200 struct stcp_port stcp;
201#endif
202 } u;
203};
204
205/* Information kept about a dialer. */
206
207struct sdialer
208{
209 /* The name. */
210 const char *zname;
211 /* Chat script. */
212 struct schat_info schat;
213 /* The ``wait for dialtone'' string. */
214 const char *zdialtone;
215 /* The ``pause'' string. */
216 const char *zpause;
217 /* Whether the dialer supports carrier. */
218 boolean fcarrier;
219 /* How many seconds to wait for carrier (if fcarrier TRUE). */
220 int ccarrier_wait;
221 /* Whether to toggle DTR. */
222 boolean fdtr_toggle;
223 /* Whether to wait after toggling DTR. */
224 boolean fdtr_toggle_wait;
225 /* The chat script to use when a call is complete. */
226 struct schat_info scomplete;
227 /* The chat script to use when a call is aborted. */
228 struct schat_info sabort;
229 /* Number of protocol parameters. */
230 int cproto_params;
231 /* The protocol parameters. */
232 struct sproto_param *qproto_params;
233 /* The set of reliability bits. */
234 int ireliable;
235};
236
237/* A command table holds the functions which implement actions for
238 each different kind of port. */
239
240struct sportcmds
241{
242 /* Lock the port. The fin argument is TRUE if the port is to be
243 used for an incoming call, FALSE for an outgoing call. */
244 boolean (*pflock) P((struct sport *qport, boolean fin));
245 /* Open the port. */
246 boolean (*pfopen) P((struct sport *qport, long ibaud,
247 boolean fwait));
248 /* Close the port. */
249 boolean (*pfclose) P((struct sport *qport, boolean fsuccess));
250 /* Reset the port so that another call may be accepted. */
251 boolean (*pfreset) P((struct sport *qport));
252 /* Dial a number on a port (may be NULL). This set *pcproto_params
253 and *pqproto_params to the protocol parameters of the dialer, if
254 any, and *pireliable to the reliable code of the dialer (a hack
255 to avoid reading dialer information twice). */
256 boolean (*pfdial) P((struct sport *qport, const struct ssysteminfo *qsys,
257 int *pcproto_params,
258 struct sproto_param **pqproto_params,
259 int *pireliable));
260 /* Read data from the port, with a timeout in seconds. When called
261 *pclen is the length of the buffer; on successful return *pclen
262 is the number of bytes read into the buffer. The cmin argument
263 is the minimum number of bytes to read before returning ahead
264 of a timeout. */
265 boolean (*pfread) P((struct sport *qport, char *zbuf, int *pclen,
266 int cmin, int ctimeout, boolean freport));
267 /* Write data to the port. */
268 boolean (*pfwrite) P((struct sport *qport, const char *zbuf,
269 int clen));
270 /* Read and write data to the port. This reads and writes data
271 until either all passed in data has been written or the read
272 buffer has been filled. When called *pcread is the size of
273 the read buffer and *pcwrite is the number of bytes to write;
274 on successful return *pcread is the number of bytes read and
275 *pcwrite is the number of bytes written. */
276 boolean (*pfio) P((struct sport *qport, const char *zwrite,
277 int *pcwrite, char *zread, int *pcread));
278 /* Send a break character. This may be NULL. */
279 boolean (*pfbreak) P((struct sport *qport));
280 /* Change the port setting. This may be NULL. */
281 boolean (*pfset) P((struct sport *qport, enum tportsetting tset));
282 /* Run a chat program on a port. */
283 boolean (*pfchat) P((struct sport *qport, const char *zprog));
284 /* Get the baud rate of a port. */
285 long (*pibaud) P((struct sport *qport));
286};
287
288/* Only one port can be open during an execution of uucico, and we
289 keep it in this global variable. */
290
291extern struct sport *qPort;
292
293/* The table of port functions. The order of entries in this table
294 must match the tporttype enumeration. */
295
296extern const struct sportcmds asPortcmds[];
297
298/* Port functions. */
299
300/* Process a port command. The pvar argument should point to a pointer
301 to type struct sport. */
302extern enum tcmdtabret tprocess_port_cmd P((int cargs, char **azargs,
303 pointer pvar, const char *zerr));
304
305/* Read dialer information. */
306extern boolean fread_dialer_info P((const char *zdialer,
307 struct sdialer *qdialer));
308
309#if HAVE_V2_CONFIG
310/* Read information from the V2 configuration files. */
311
312extern boolean fv2_find_port P((const char *zname, long ibaud,
313 long ihighbaud, struct sport *qport,
314 boolean (*pflock) P((struct sport *,
315 boolean fin)),
316 boolean *pffound));
317#endif /* HAVE_V2_CONFIG */
318
319#if HAVE_BNU_CONFIG
320/* Read information from the BNU configuration files. */
321
322extern boolean fbnu_find_port P((const char *zname, long ibaud,
323 long ihighbaud, struct sport *qport,
324 boolean (*pflock) P((struct sport *,
325 boolean fin)),
326 boolean *pffound));
327extern boolean fbnu_read_dialer_info P((const char *zdialer,
328 struct sdialer *qdialer));
329#endif /* HAVE_BNU_CONFIG */
330
331/* Lock a port. The fin argument is TRUE if the port is to be used
332 for an incoming call; certains type of Unix locking need this
333 information because they need to open the port. */
334extern boolean fport_lock P((struct sport *qport, boolean fin));
335
336/* Find and lock a port. If the port name is NULL, the matching is
337 done only on the baud rate. If the baud rate is 0, the matching is
338 done only on the port name. Otherwise the port must match both
339 name and baud rate. If ihighbaud is not 0, the baud rate of the
340 port must fall between ibaud and ihighbaud. */
341extern boolean ffind_port P((const char *zname, long ibaud,
342 long ihighbaud, struct sport *qport,
343 boolean (*pflock) P((struct sport *,
344 boolean fin)),
345 boolean freport));
346
347/* Open a port. If ibaud is 0, the natural baud rate of the port is
348 used. If ihighbaud is not 0, fport_open figures out what baud rate
349 to use based on the port's baud rate. */
350extern boolean fport_open P((struct sport *qport, long ibaud,
351 long ihighbaud, boolean fwait));
352
353/* Close and unlock a port. The fsuccess argument is TRUE if the
354 conversation on the port was completed normally, FALSE if it is
355 being aborted. */
356extern boolean fport_close P((boolean fsuccess));
357
358/* Reset a port such that another call may be accepted. */
359extern boolean fport_reset P((void));
360
361/* Dial out on a port. This is permitted to return a set of protocol
362 parameters and reliability bits for the dialer (yes, it's a hack;
363 this permits protocol parameters to set for particular modems). */
364extern boolean fport_dial P((const struct ssysteminfo *qsys,
365 int *pcproto_params,
366 struct sproto_param **pqproto_params,
367 int *pireliable));
368
369/* Read from a port.
370 zbuf -- buffer to read bytes into
371 *pclen on call -- length of zbuf
372 *pclen on successful return -- number of bytes read
373 cmin -- minimum number of bytes to read before returning ahead of timeout
374 ctimeout -- timeout in seconds, 0 if none
375 freport -- whether to report errors. */
376extern boolean fport_read P((char *zbuf, int *pclen, int cmin,
377 int ctimeout, boolean freport));
378
379/* Write to a port. */
380extern boolean fport_write P((const char *zbuf, int cbytes));
381
382/* Read and write to a port. This reads and writes data until either
383 all passed-in data has been written or the read buffer is full.
384
385 zwrite -- buffer to write bytes from
386 *pcwrite on call -- number of bytes to write
387 *pcwrite on successful return -- number of bytes written
388 zread -- buffer to read bytes into
389 *pcread on call -- size of read buffer
390 *pcread on successful return -- number of bytes read. */
391extern boolean fport_io P((const char *zwrite, int *pcwrite,
392 char *zread, int *pcread));
393
394/* Send a break character to a port. */
395extern boolean fport_break P((void));
396
397/* Change the settings of a port. */
398extern boolean fport_set P((enum tportsetting tset));
399
400/* Get the baud rate of a port. */
401extern long iport_baud P((void));
402
403/* Do a chat script with a system. */
404extern boolean fchat P((const struct schat_info *qchat,
405 const struct ssysteminfo *qsys,
406 const struct sdialer *qdial,
407 const char *zphone, boolean ftranslate,
408 const char *zport, long ibaud));
409
410/* Allow no carrier during a chat script. */
411extern boolean fport_no_carrier P((void));
412
413/* Require carrier during a chat script. */
414extern boolean fport_need_carrier P((void));
415
416/* Run a chat program on a port. */
417extern boolean fport_run_chat P((const char *zprog));
418
419/* Modem routines used when dialing. */
420
421/* Begin dialing out. This should open the dialer device if there is
422 one, toggle DTR if requested and possible, and tell the port to
423 ignore carrier. It should return FALSE on error. */
424extern boolean fsysdep_modem_begin_dial P((struct sport *qport,
425 struct sdialer *qdial));
426
427/* Tell the modem to ignore carrier. This is called when \M is
428 encountered in a dialer chat script. It should return FALSE on
429 error. */
430extern boolean fsysdep_modem_no_carrier P((struct sport *qport));
431
432/* Tell the modem that carrier is required. This is called when \m is
433 encountered in a dialer chat script. It should return FALSE on
434 error. */
435extern boolean fsysdep_modem_need_carrier P((struct sport *qport));
436
437/* Finish dialing out on a modem. This should close the dialer device
438 if there is one. If the dialer and the port both support carrier,
439 the port should be told to pay attention to carrier. If it is
440 possible to wait for carrier to come on, and the dialer and the
441 port both the port support carrier, it should wait until carrier
442 comes on. */
443extern boolean fsysdep_modem_end_dial P((struct sport *qport,
444 struct sdialer *qdial));
445
446/* Port routines for stdin ports. */
447
448extern boolean fsysdep_stdin_lock P((struct sport *qport, boolean fin));
449extern boolean fsysdep_stdin_open P((struct sport *qport, long ibaud,
450 boolean fwait));
451extern boolean fsysdep_stdin_close P((struct sport *qport,
452 boolean fsuccess));
453extern boolean fsysdep_stdin_reset P((struct sport *qport));
454extern boolean fsysdep_stdin_read P((struct sport *qport, char *zread,
455 int *pcread, int cmin,
456 int ctimeout, boolean freport));
457extern boolean fsysdep_stdin_write P((struct sport *qport,
458 const char *zwrite, int cwrite));
459extern boolean fsysdep_stdin_io P((struct sport *qport,
460 const char *zwrite, int *pcwrite,
461 char *zread, int *pcread));
462extern boolean fsysdep_stdin_break P((struct sport *qport));
463extern boolean fsysdep_stdin_set P((struct sport *qport,
464 enum tportsetting tset));
465extern boolean fsysdep_stdin_chat P((struct sport *qport,
466 const char *zprog));
467extern long isysdep_stdin_baud P((struct sport *qport));
468
469/* Port routines for modem ports. */
470
471extern boolean fsysdep_modem_lock P((struct sport *qport, boolean fin));
472extern boolean fsysdep_modem_open P((struct sport *qport, long ibaud,
473 boolean fwait));
474extern boolean fsysdep_modem_close P((struct sport *qport,
475 boolean fsuccess));
476extern boolean fsysdep_modem_reset P((struct sport *qport));
477extern boolean fmodem_dial P((struct sport *qport,
478 const struct ssysteminfo *qsys,
479 int *pcproto_params,
480 struct sproto_param **pqproto_params,
481 int *pireliable));
482extern boolean fsysdep_modem_read P((struct sport *qport, char *zread,
483 int *pcread, int cmin,
484 int ctimeout, boolean freport));
485extern boolean fsysdep_modem_write P((struct sport *qport,
486 const char *zwrite, int cwrite));
487extern boolean fsysdep_modem_io P((struct sport *qport,
488 const char *zwrite, int *pcwrite,
489 char *zread, int *pcread));
490extern boolean fsysdep_modem_break P((struct sport *qport));
491extern boolean fsysdep_modem_set P((struct sport *qport,
492 enum tportsetting tset));
493extern boolean fsysdep_modem_chat P((struct sport *qport,
494 const char *zprog));
495extern long isysdep_modem_baud P((struct sport *qport));
496
497/* Port routines for direct connections. */
498
499extern boolean fsysdep_direct_lock P((struct sport *qport, boolean fin));
500extern boolean fsysdep_direct_open P((struct sport *qport, long ibaud,
501 boolean fwait));
502extern boolean fsysdep_direct_close P((struct sport *qport,
503 boolean fsuccess));
504extern boolean fsysdep_direct_reset P((struct sport *qport));
505extern boolean fsysdep_direct_read P((struct sport *qport, char *zread,
506 int *pcread, int cmin,
507 int ctimeout, boolean freport));
508extern boolean fsysdep_direct_write P((struct sport *qport,
509 const char *zwrite, int cwrite));
510extern boolean fsysdep_direct_io P((struct sport *qport,
511 const char *zwrite, int *pcwrite,
512 char *zread, int *pcread));
513extern boolean fsysdep_direct_break P((struct sport *qport));
514extern boolean fsysdep_direct_set P((struct sport *qport,
515 enum tportsetting tset));
516extern boolean fsysdep_direct_chat P((struct sport *qport,
517 const char *zprog));
518extern long isysdep_direct_baud P((struct sport *qport));
519
520#if HAVE_TCP
521
522/* Port routines for TCP ports. */
523
524extern boolean ftcp_lock P((struct sport *qport, boolean fin));
525extern boolean ftcp_open P((struct sport *qport, long ibaud,
526 boolean fwait));
527extern boolean ftcp_close P((struct sport *qport, boolean fsuccess));
528extern boolean ftcp_reset P((struct sport *qport));
529extern boolean ftcp_dial P((struct sport *qport,
530 const struct ssysteminfo *qsys,
531 int *pcproto_params,
532 struct sproto_param **pqproto_params,
533 int *pireliable));
534extern boolean fsysdep_tcp_read P((struct sport *qport, char *zread,
535 int *pcread, int cmin,
536 int ctimeout, boolean freport));
537extern boolean fsysdep_tcp_write P((struct sport *qport,
538 const char *zwrite, int cwrite));
539extern boolean fsysdep_tcp_io P((struct sport *qport,
540 const char *zwrite, int *pcwrite,
541 char *zread, int *pcread));
542extern boolean fsysdep_tcp_chat P((struct sport *qport,
543 const char *zprog));
544extern long itcp_baud P((struct sport *qport));
545
546#endif /* HAVE_TCP */
547
548#endif