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