1174199Srwatson/*- 2224859Srwatson * SPDX-License-Identifier: BSD-2-Clause 3174199Srwatson * 4174199Srwatson * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org> 5174199Srwatson * based on work by Toshiharu OHNO <tony-o@iij.ad.jp> 6174199Srwatson * Internet Initiative Japan, Inc (IIJ) 7174199Srwatson * All rights reserved. 8174199Srwatson * 9174199Srwatson * Redistribution and use in source and binary forms, with or without 10174199Srwatson * modification, are permitted provided that the following conditions 11174199Srwatson * are met: 12174199Srwatson * 1. Redistributions of source code must retain the above copyright 13174199Srwatson * notice, this list of conditions and the following disclaimer. 14174199Srwatson * 2. Redistributions in binary form must reproduce the above copyright 15174199Srwatson * notice, this list of conditions and the following disclaimer in the 16174199Srwatson * documentation and/or other materials provided with the distribution. 17174199Srwatson * 18174199Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19174199Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20174199Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21174199Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22174199Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23174199Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24174199Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25174199Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26174199Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27174199Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28174199Srwatson * SUCH DAMAGE. 29186567Srwatson */ 30280250Srwatson 31174199Srwatson/* callback::opmask values */ 32174199Srwatson#define CALLBACK_AUTH (0) 33174199Srwatson#define CALLBACK_DIALSTRING (1) /* Don't do this */ 34174199Srwatson#define CALLBACK_LOCATION (2) /* Don't do this */ 35174199Srwatson#define CALLBACK_E164 (3) 36174199Srwatson#define CALLBACK_NAME (4) /* Don't do this */ 37174199Srwatson#define CALLBACK_CBCP (6) 38174199Srwatson#define CALLBACK_NONE (14) /* No callback is ok */ 39174199Srwatson 40200462Sdelphij#define CALLBACK_BIT(n) ((n) < 0 ? 0 : 1 << (n)) 41221807Sstas 42174199Srwatsonstruct callback { 43174199Srwatson int opmask; /* want these types of callback */ 44174199Srwatson char msg[SCRIPT_LEN]; /* with this data (E.164) */ 45174199Srwatson}; 46174199Srwatson 47174199Srwatson#define REJECTED(p, x) ((p)->his_reject & (1<<(x))) 48174199Srwatson 49174199Srwatsonstruct lcp { 50174199Srwatson struct fsm fsm; /* The finite state machine */ 51174199Srwatson u_int16_t his_mru; /* Peers maximum packet size */ 52174199Srwatson u_int16_t his_mrru; /* Peers maximum reassembled packet size (MP) */ 53174199Srwatson u_int32_t his_accmap; /* Peeers async char control map */ 54174199Srwatson u_int32_t his_magic; /* Peers magic number */ 55174199Srwatson u_int32_t his_lqrperiod; /* Peers LQR frequency (100ths of seconds) */ 56174199Srwatson u_short his_auth; /* Peer wants this type of authentication */ 57174199Srwatson u_char his_authtype; /* Fifth octet of REQ/NAK/REJ */ 58174199Srwatson struct callback his_callback; /* Peer wants callback ? */ 59174199Srwatson unsigned his_shortseq : 1; /* Peer would like only 12bit seqs (MP) */ 60174199Srwatson unsigned his_protocomp : 1; /* Does peer do Protocol field compression */ 61174199Srwatson unsigned his_acfcomp : 1; /* Does peer do addr & cntrl fld compression */ 62174530Srwatson unsigned mru_req : 1; /* Has the peer requested an MRU */ 63174199Srwatson 64174199Srwatson u_short want_mru; /* Our maximum packet size */ 65174199Srwatson u_short want_mrru; /* Our maximum reassembled packet size (MP) */ 66174530Srwatson u_int32_t want_accmap; /* Our async char control map */ 67174530Srwatson u_int32_t want_magic; /* Our magic number */ 68174530Srwatson u_int32_t want_lqrperiod; /* Our LQR frequency (100ths of seconds) */ 69174199Srwatson u_short want_auth; /* We want this type of authentication */ 70174530Srwatson u_char want_authtype; /* Fifth octet of REQ/NAK/REJ */ 71174199Srwatson struct callback want_callback;/* We want callback ? */ 72174199Srwatson unsigned want_shortseq : 1; /* I'd like only 12bit seqs (MP) */ 73174199Srwatson unsigned want_protocomp : 1; /* Do we do protocol field compression */ 74174199Srwatson unsigned want_acfcomp : 1; /* Do we do addr & cntrl fld compression */ 75174199Srwatson 76174530Srwatson u_int32_t his_reject; /* Request codes rejected by peer */ 77174199Srwatson u_int32_t my_reject; /* Request codes I have rejected */ 78174530Srwatson 79174199Srwatson u_short auth_iwait; /* I must authenticate to the peer */ 80174530Srwatson u_short auth_ineed; /* I require that the peer authenticates */ 81174199Srwatson 82174199Srwatson int LcpFailedMagic; /* Number of `magic is same' errors */ 83174530Srwatson 84174199Srwatson struct { 85174199Srwatson u_short mru; /* Preferred MRU value */ 86174199Srwatson u_short max_mru; /* Preferred MRU value */ 87174199Srwatson u_short mtu; /* Preferred MTU */ 88174199Srwatson u_short max_mtu; /* Preferred MTU */ 89174199Srwatson u_int32_t accmap; /* Initial ACCMAP value */ 90174199Srwatson int openmode; /* when to start CFG REQs */ 91174199Srwatson u_int32_t lqrperiod; /* LQR frequency (seconds) */ 92174199Srwatson struct fsm_retry fsm; /* How often/frequently to resend requests */ 93174199Srwatson unsigned acfcomp : 2; /* Address & Control Field Compression neg */ 94174199Srwatson unsigned chap05 : 2; /* Challenge Handshake Authentication proto */ 95174199Srwatson#ifndef NODES 96174199Srwatson unsigned chap80nt : 2; /* Microsoft (NT) CHAP */ 97174199Srwatson unsigned chap80lm : 2; /* Microsoft (LANMan) CHAP */ 98174199Srwatson unsigned chap81 : 2; /* Microsoft CHAP v2 */ 99174199Srwatson#endif 100174199Srwatson unsigned lqr : 2; /* Link Quality Report */ 101174199Srwatson unsigned echo : 1; /* Send echo Requests */ 102174199Srwatson unsigned pap : 2; /* Password Authentication protocol */ 103174199Srwatson unsigned protocomp : 2; /* Protocol field compression */ 104174199Srwatson char ident[DEF_MRU - 7]; /* SendIdentification() data */ 105174199Srwatson } cfg; 106174199Srwatson}; 107174199Srwatson 108174199Srwatson#define LCP_MAXCODE CODE_IDENT 109174199Srwatson#define LCP_MINMPCODE CODE_CODEREJ 110174199Srwatson 111174199Srwatson#define TY_MRU 1 /* Maximum-Receive-Unit */ 112174199Srwatson#define TY_ACCMAP 2 /* Async-Control-Character-Map */ 113174199Srwatson#define TY_AUTHPROTO 3 /* Authentication-Protocol */ 114174199Srwatson#define TY_QUALPROTO 4 /* Quality-Protocol */ 115174199Srwatson#define TY_MAGICNUM 5 /* Magic-Number */ 116174199Srwatson#define TY_RESERVED 6 /* RESERVED */ 117268517Sdelphij#define TY_PROTOCOMP 7 /* Protocol-Field-Compression */ 118174199Srwatson#define TY_ACFCOMP 8 /* Address-and-Control-Field-Compression */ 119174199Srwatson#define TY_FCSALT 9 /* FCS-Alternatives */ 120174199Srwatson#define TY_SDP 10 /* Self-Describing-Padding */ 121174199Srwatson#define TY_CALLBACK 13 /* Callback */ 122174199Srwatson#define TY_CFRAMES 15 /* Compound-frames */ 123174199Srwatson#define TY_MRRU 17 /* Max Reconstructed Receive Unit (MP) */ 124174199Srwatson#define TY_SHORTSEQ 18 /* Want short seqs (12bit) please (see mp.h) */ 125174199Srwatson#define TY_ENDDISC 19 /* Endpoint discriminator */ 126174199Srwatson 127174199Srwatsonstruct mbuf; 128174199Srwatsonstruct link; 129174199Srwatsonstruct bundle; 130174199Srwatsonstruct cmdargs; 131174199Srwatson 132174530Srwatson#define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcp *)fp : NULL) 133174199Srwatson 134174199Srwatsonextern void lcp_Init(struct lcp *, struct bundle *, struct link *, 135224859Srwatson const struct fsm_parent *); 136255219Spjdextern void lcp_Setup(struct lcp *, int); 137224859Srwatson 138224859Srwatsonextern void lcp_SendProtoRej(struct lcp *, u_char *, int); 139224859Srwatsonextern int lcp_SendIdentification(struct lcp *); 140224859Srwatsonextern void lcp_RecvIdentification(struct lcp *, char *); 141224859Srwatsonextern int lcp_ReportStatus(struct cmdargs const *); 142247602Spjdextern struct mbuf *lcp_Input(struct bundle *, struct link *, struct mbuf *); 143224859Srwatsonextern void lcp_SetupCallbacks(struct lcp *); 144247602Spjd