xref: /freebsd/usr.sbin/ppp/datalink.h (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
1 /*-
2  * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *	$Id: datalink.h,v 1.7 1999/03/04 17:42:15 brian Exp $
27  */
28 
29 #define DATALINK_CLOSED  (0)
30 #define DATALINK_OPENING (1)
31 #define DATALINK_HANGUP  (2)
32 #define DATALINK_DIAL    (3)
33 #define DATALINK_CARRIER (4)
34 #define DATALINK_LOGIN   (5)
35 #define DATALINK_READY   (6)
36 #define DATALINK_LCP     (7)
37 #define DATALINK_AUTH    (8)
38 #define DATALINK_CBCP    (9)
39 #define DATALINK_OPEN    (10)
40 
41 #define DATALINK_MAXNAME (20)   /* Maximum datalink::name length */
42 
43 /* How to close the link */
44 #define CLOSE_NORMAL		0
45 #define CLOSE_STAYDOWN		1
46 #define CLOSE_LCP		2
47 
48 struct iovec;
49 struct prompt;
50 struct physical;
51 struct bundle;
52 
53 struct datalink {
54   struct descriptor desc;       /* We play either a physical or a chat */
55   int state;			/* Our DATALINK_* state */
56   struct physical *physical;	/* Our link */
57 
58   struct chat chat;		/* For bringing the link up & down */
59 
60   unsigned stayonline : 1;	/* stay online when LCP is closed ? */
61   struct {
62     unsigned run : 1;		/* run scripts ? */
63     unsigned packetmode : 1;	/* Go into packet mode after login ? */
64   } script;
65 
66   struct {
67     struct {
68       char dial[SCRIPT_LEN];	/* dial */
69       char login[SCRIPT_LEN];	/* login */
70       char hangup[SCRIPT_LEN];	/* hangup */
71     } script;
72     struct {
73       char list[SCRIPT_LEN];	/* Telephone Numbers */
74     } phone;
75     struct {
76       int max;			/* initially try again this number of times */
77       int next_timeout;		/* Redial next timeout value */
78       int inc;			/* Increment timeout by `inc' each time read */
79       int maxinc;		/* Maximum number of increments */
80       int timeout;		/* Redial timeout value (end of phone list) */
81     } dial;
82     struct {
83       int max;			/* initially try again this number of times */
84       int timeout;		/* Timeout before reconnect on carrier loss */
85     } reconnect;
86     struct callback callback;	/* Direction depends on physical type */
87     struct cbcpcfg cbcp;	/* Direction depends on phys type & callback */
88   } cfg;			/* All our config data is in here */
89 
90   struct {
91     char list[SCRIPT_LEN];	/* copy of cfg.list for strsep() */
92     char *next;			/* Next phone from the list */
93     char *alt;			/* Alternate (after fail) phone from the list */
94     const char *chosen;		/* Chosen phone number after DIAL */
95   } phone;
96 
97   struct cbcp cbcp;
98 
99   struct {
100     struct pppTimer timer;	/* For timing between close & open */
101     int tries;			/* currently try again this number of times */
102     int incs;			/* # times our timeout has been incremented */
103   } dial;
104 
105   unsigned reconnect_tries;	/* currently try again this number of times */
106 
107   char *name;			/* Our name */
108 
109   struct peerid peer;		/* Peer identification */
110 
111   struct fsm_parent fsmp;	   /* Our callback functions */
112   const struct fsm_parent *parent; /* Our parent */
113 
114   struct authinfo pap;             /* Authentication using pap */
115   struct chap chap;                /* Authentication using chap */
116 
117   struct mp_link mp;               /* multilink data */
118 
119   struct bundle *bundle;	   /* for the moment */
120   struct datalink *next;	   /* Next in the list */
121 };
122 
123 #define descriptor2datalink(d) \
124   ((d)->type == DATALINK_DESCRIPTOR ? (struct datalink *)(d) : NULL)
125 
126 extern struct datalink *datalink_Create(const char *name, struct bundle *, int);
127 extern struct datalink *datalink_Clone(struct datalink *, const char *);
128 extern struct datalink *iov2datalink(struct bundle *, struct iovec *, int *,
129                                      int, int);
130 extern int datalink2iov(struct datalink *, struct iovec *, int *, int, pid_t);
131 extern struct datalink *datalink_Destroy(struct datalink *);
132 extern void datalink_GotAuthname(struct datalink *, const char *);
133 extern void datalink_Up(struct datalink *, int, int);
134 extern void datalink_Close(struct datalink *, int);
135 extern void datalink_Down(struct datalink *, int);
136 extern void datalink_StayDown(struct datalink *);
137 extern void datalink_DontHangup(struct datalink *);
138 extern void datalink_AuthOk(struct datalink *);
139 extern void datalink_AuthNotOk(struct datalink *);
140 extern void datalink_NCPUp(struct datalink *);
141 extern void datalink_CBCPComplete(struct datalink *);
142 extern void datalink_CBCPFailed(struct datalink *);
143 extern int datalink_Show(struct cmdargs const *);
144 extern int datalink_SetRedial(struct cmdargs const *);
145 extern int datalink_SetReconnect(struct cmdargs const *);
146 extern const char *datalink_State(struct datalink *);
147 extern void datalink_Rename(struct datalink *, const char *);
148 extern char *datalink_NextName(struct datalink *);
149 extern int datalink_RemoveFromSet(struct datalink *, fd_set *, fd_set *,
150                                   fd_set *);
151 extern int datalink_SetMode(struct datalink *, int);
152 extern int datalink_GetDialTimeout(struct datalink *);
153 extern const char *datalink_ChoosePhoneNumber(struct datalink *);
154