1 /*- 2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org> 3 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp> 4 * Internet Initiative Japan, Inc (IIJ) 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 * $FreeBSD$ 29 */ 30 31 /* callback::opmask values */ 32 #define CALLBACK_AUTH (0) 33 #define CALLBACK_DIALSTRING (1) /* Don't do this */ 34 #define CALLBACK_LOCATION (2) /* Don't do this */ 35 #define CALLBACK_E164 (3) 36 #define CALLBACK_NAME (4) /* Don't do this */ 37 #define CALLBACK_CBCP (6) 38 #define CALLBACK_NONE (14) /* No callback is ok */ 39 40 #define CALLBACK_BIT(n) ((n) < 0 ? 0 : 1 << (n)) 41 42 struct callback { 43 int opmask; /* want these types of callback */ 44 char msg[SCRIPT_LEN]; /* with this data (E.164) */ 45 }; 46 47 #define REJECTED(p, x) ((p)->his_reject & (1<<(x))) 48 49 struct lcp { 50 struct fsm fsm; /* The finite state machine */ 51 u_int16_t his_mru; /* Peers maximum packet size */ 52 u_int16_t his_mrru; /* Peers maximum reassembled packet size (MP) */ 53 u_int32_t his_accmap; /* Peeers async char control map */ 54 u_int32_t his_magic; /* Peers magic number */ 55 u_int32_t his_lqrperiod; /* Peers LQR frequency (100ths of seconds) */ 56 u_short his_auth; /* Peer wants this type of authentication */ 57 u_char his_authtype; /* Fifth octet of REQ/NAK/REJ */ 58 struct callback his_callback; /* Peer wants callback ? */ 59 unsigned his_shortseq : 1; /* Peer would like only 12bit seqs (MP) */ 60 unsigned his_protocomp : 1; /* Does peer do Protocol field compression */ 61 unsigned his_acfcomp : 1; /* Does peer do addr & cntrl fld compression */ 62 63 u_short want_mru; /* Our maximum packet size */ 64 u_short want_mrru; /* Our maximum reassembled packet size (MP) */ 65 u_int32_t want_accmap; /* Our async char control map */ 66 u_int32_t want_magic; /* Our magic number */ 67 u_int32_t want_lqrperiod; /* Our LQR frequency (100ths of seconds) */ 68 u_short want_auth; /* We want this type of authentication */ 69 u_char want_authtype; /* Fifth octet of REQ/NAK/REJ */ 70 struct callback want_callback;/* We want callback ? */ 71 unsigned want_shortseq : 1; /* I'd like only 12bit seqs (MP) */ 72 unsigned want_protocomp : 1; /* Do we do protocol field compression */ 73 unsigned want_acfcomp : 1; /* Do we do addr & cntrl fld compression */ 74 75 u_int32_t his_reject; /* Request codes rejected by peer */ 76 u_int32_t my_reject; /* Request codes I have rejected */ 77 78 u_short auth_iwait; /* I must authenticate to the peer */ 79 u_short auth_ineed; /* I require that the peer authenticates */ 80 81 int LcpFailedMagic; /* Number of `magic is same' errors */ 82 83 struct { 84 u_short mru; /* Preferred MRU value */ 85 u_short max_mru; /* Preferred MRU value */ 86 u_short mtu; /* Preferred MTU */ 87 u_short max_mtu; /* Preferred MTU */ 88 u_int32_t accmap; /* Initial ACCMAP value */ 89 int openmode; /* when to start CFG REQs */ 90 u_int32_t lqrperiod; /* LQR frequency (seconds) */ 91 struct fsm_retry fsm; /* How often/frequently to resend requests */ 92 unsigned acfcomp : 2; /* Address & Control Field Compression neg */ 93 unsigned chap05 : 2; /* Challenge Handshake Authentication proto */ 94 #ifdef HAVE_DES 95 unsigned chap80nt : 2; /* Microsoft (NT) CHAP */ 96 unsigned chap80lm : 2; /* Microsoft (LANMan) CHAP */ 97 unsigned chap81 : 2; /* Microsoft CHAP v2 */ 98 #endif 99 unsigned lqr : 2; /* Link Quality Report */ 100 unsigned pap : 2; /* Password Authentication protocol */ 101 unsigned protocomp : 2; /* Protocol field compression */ 102 char ident[DEF_MRU - 7]; /* SendIdentification() data */ 103 } cfg; 104 }; 105 106 #define LCP_MAXCODE CODE_IDENT 107 #define LCP_MINMPCODE CODE_CODEREJ 108 109 #define TY_MRU 1 /* Maximum-Receive-Unit */ 110 #define TY_ACCMAP 2 /* Async-Control-Character-Map */ 111 #define TY_AUTHPROTO 3 /* Authentication-Protocol */ 112 #define TY_QUALPROTO 4 /* Quality-Protocol */ 113 #define TY_MAGICNUM 5 /* Magic-Number */ 114 #define TY_RESERVED 6 /* RESERVED */ 115 #define TY_PROTOCOMP 7 /* Protocol-Field-Compression */ 116 #define TY_ACFCOMP 8 /* Address-and-Control-Field-Compression */ 117 #define TY_FCSALT 9 /* FCS-Alternatives */ 118 #define TY_SDP 10 /* Self-Describing-Padding */ 119 #define TY_CALLBACK 13 /* Callback */ 120 #define TY_CFRAMES 15 /* Compound-frames */ 121 #define TY_MRRU 17 /* Max Reconstructed Receive Unit (MP) */ 122 #define TY_SHORTSEQ 18 /* Want short seqs (12bit) please (see mp.h) */ 123 #define TY_ENDDISC 19 /* Endpoint discriminator */ 124 125 #define MAX_LCP_OPT_LEN 20 126 struct lcp_opt { 127 u_char id; 128 u_char len; 129 u_char data[MAX_LCP_OPT_LEN-2]; 130 }; 131 132 #define INC_LCP_OPT(ty, length, o) \ 133 do { \ 134 (o)->id = (ty); \ 135 (o)->len = (length); \ 136 (o) = (struct lcp_opt *)((char *)(o) + (length)); \ 137 } while (0) 138 139 struct mbuf; 140 struct link; 141 struct bundle; 142 struct cmdargs; 143 144 #define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcp *)fp : NULL) 145 146 extern void lcp_Init(struct lcp *, struct bundle *, struct link *, 147 const struct fsm_parent *); 148 extern void lcp_Setup(struct lcp *, int); 149 150 extern void lcp_SendProtoRej(struct lcp *, u_char *, int); 151 extern int lcp_SendIdentification(struct lcp *); 152 extern void lcp_RecvIdentification(struct lcp *, char *); 153 extern int lcp_ReportStatus(struct cmdargs const *); 154 extern struct mbuf *lcp_Input(struct bundle *, struct link *, struct mbuf *); 155 extern void lcp_SetupCallbacks(struct lcp *); 156