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 * $FreeBSD: src/usr.sbin/ppp/datalink.h,v 1.12.2.2 2002/09/01 02:12:26 brian Exp $ 27 * $DragonFly: src/usr.sbin/ppp/datalink.h,v 1.2 2003/06/17 04:30:00 dillon Exp $ 28 */ 29 30 #define DATALINK_CLOSED (0) 31 #define DATALINK_OPENING (1) 32 #define DATALINK_HANGUP (2) 33 #define DATALINK_DIAL (3) 34 #define DATALINK_CARRIER (4) 35 #define DATALINK_LOGOUT (5) 36 #define DATALINK_LOGIN (6) 37 #define DATALINK_READY (7) 38 #define DATALINK_LCP (8) 39 #define DATALINK_AUTH (9) 40 #define DATALINK_CBCP (10) 41 #define DATALINK_OPEN (11) 42 43 #define DATALINK_MAXNAME (20) /* Maximum datalink::name length */ 44 45 /* How to close the link */ 46 #define CLOSE_NORMAL 0 47 #define CLOSE_STAYDOWN 1 48 #define CLOSE_LCP 2 49 50 struct iovec; 51 struct prompt; 52 struct physical; 53 struct bundle; 54 55 struct datalink { 56 struct fdescriptor desc; /* We play either a physical or a chat */ 57 unsigned state; /* Our DATALINK_* state */ 58 struct physical *physical; /* Our link */ 59 60 struct chat chat; /* For bringing the link up & down */ 61 62 unsigned stayonline : 1; /* stay online when LCP is closed ? */ 63 struct { 64 unsigned run : 1; /* run scripts ? */ 65 unsigned packetmode : 1; /* Go into packet mode after login ? */ 66 } script; 67 68 struct { 69 struct { 70 char dial[SCRIPT_LEN]; 71 char login[SCRIPT_LEN]; 72 char logout[SCRIPT_LEN]; 73 char hangup[SCRIPT_LEN]; 74 } script; /* various chat scripts */ 75 struct { 76 char list[SCRIPT_LEN]; /* Telephone Numbers */ 77 } phone; 78 struct { 79 int max; /* initially try again this number of times */ 80 int next_timeout; /* Redial next timeout value */ 81 int inc; /* Increment timeout by `inc' each time read */ 82 int maxinc; /* Maximum number of increments */ 83 int timeout; /* Redial timeout value (end of phone list) */ 84 } dial; 85 struct { 86 int max; /* initially try again this number of times */ 87 int timeout; /* Timeout before reconnect on carrier loss */ 88 } reconnect; 89 struct callback callback; /* Direction depends on physical type */ 90 struct cbcpcfg cbcp; /* Direction depends on phys type & callback */ 91 } cfg; /* All our config data is in here */ 92 93 struct { 94 char list[SCRIPT_LEN]; /* copy of cfg.list for strsep() */ 95 char *next; /* Next phone from the list */ 96 char *alt; /* Alternate (after fail) phone from the list */ 97 const char *chosen; /* Chosen phone number after DIAL */ 98 } phone; 99 100 struct cbcp cbcp; 101 102 struct { 103 struct pppTimer timer; /* For timing between close & open */ 104 int tries; /* currently try again this number of times */ 105 int incs; /* # times our timeout has been incremented */ 106 } dial; 107 108 unsigned reconnect_tries; /* currently try again this number of times */ 109 110 char *name; /* Our name */ 111 112 struct peerid peer; /* Peer identification */ 113 114 struct fsm_parent fsmp; /* Our callback functions */ 115 const struct fsm_parent *parent; /* Our parent */ 116 117 struct authinfo pap; /* Authentication using pap */ 118 struct chap chap; /* Authentication using chap */ 119 120 struct mp_link mp; /* multilink data */ 121 122 struct bundle *bundle; /* for the moment */ 123 struct datalink *next; /* Next in the list */ 124 }; 125 126 #define descriptor2datalink(d) \ 127 ((d)->type == DATALINK_DESCRIPTOR ? (struct datalink *)(d) : NULL) 128 129 extern struct datalink *datalink_Create(const char *name, struct bundle *, int); 130 extern struct datalink *datalink_Clone(struct datalink *, const char *); 131 extern struct datalink *iov2datalink(struct bundle *, struct iovec *, int *, 132 int, int, int *, int *); 133 extern int datalink2iov(struct datalink *, struct iovec *, int *, int, int *, 134 int *); 135 extern struct datalink *datalink_Destroy(struct datalink *); 136 extern void datalink_GotAuthname(struct datalink *, const char *); 137 extern void datalink_Up(struct datalink *, int, int); 138 extern void datalink_Close(struct datalink *, int); 139 extern void datalink_Down(struct datalink *, int); 140 extern void datalink_StayDown(struct datalink *); 141 extern void datalink_DontHangup(struct datalink *); 142 extern void datalink_AuthOk(struct datalink *); 143 extern void datalink_AuthNotOk(struct datalink *); 144 extern void datalink_NCPUp(struct datalink *); 145 extern void datalink_CBCPComplete(struct datalink *); 146 extern void datalink_CBCPFailed(struct datalink *); 147 extern int datalink_Show(struct cmdargs const *); 148 extern int datalink_SetRedial(struct cmdargs const *); 149 extern int datalink_SetReconnect(struct cmdargs const *); 150 extern const char *datalink_State(struct datalink *); 151 extern void datalink_Rename(struct datalink *, const char *); 152 extern char *datalink_NextName(struct datalink *); 153 extern int datalink_RemoveFromSet(struct datalink *, fd_set *, fd_set *, 154 fd_set *); 155 extern int datalink_SetMode(struct datalink *, int); 156 extern int datalink_GetDialTimeout(struct datalink *); 157 extern const char *datalink_ChoosePhoneNumber(struct datalink *); 158 extern void datalink_ComeDown(struct datalink *, int); 159