178189Sbrian/*-
278189Sbrian * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
378189Sbrian *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
478189Sbrian *                           Internet Initiative Japan, Inc (IIJ)
578189Sbrian * All rights reserved.
66059Samurai *
778189Sbrian * Redistribution and use in source and binary forms, with or without
878189Sbrian * modification, are permitted provided that the following conditions
978189Sbrian * are met:
1078189Sbrian * 1. Redistributions of source code must retain the above copyright
1178189Sbrian *    notice, this list of conditions and the following disclaimer.
1278189Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1378189Sbrian *    notice, this list of conditions and the following disclaimer in the
1478189Sbrian *    documentation and/or other materials provided with the distribution.
156059Samurai *
1678189Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1778189Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1878189Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1978189Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2078189Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2178189Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2278189Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2378189Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2478189Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2578189Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2678189Sbrian * SUCH DAMAGE.
276059Samurai *
2850479Speter * $FreeBSD$
296059Samurai */
306059Samurai
3138174Sbrian/* callback::opmask values */
3238174Sbrian#define CALLBACK_AUTH		(0)
3338174Sbrian#define CALLBACK_DIALSTRING	(1)	/* Don't do this */
3438174Sbrian#define CALLBACK_LOCATION	(2)	/* Don't do this */
3538174Sbrian#define CALLBACK_E164		(3)
3638174Sbrian#define CALLBACK_NAME		(4)	/* Don't do this */
3738174Sbrian#define CALLBACK_CBCP		(6)
3838174Sbrian#define CALLBACK_NONE		(14)	/* No callback is ok */
3938174Sbrian
4038174Sbrian#define CALLBACK_BIT(n) ((n) < 0 ? 0 : 1 << (n))
4138174Sbrian
4238174Sbrianstruct callback {
4338174Sbrian  int opmask;			/* want these types of callback */
4438174Sbrian  char msg[SCRIPT_LEN];		/* with this data (E.164) */
4538174Sbrian};
4638174Sbrian
4731538Sbrian#define	REJECTED(p, x)	((p)->his_reject & (1<<(x)))
4831514Sbrian
4936285Sbrianstruct lcp {
5036285Sbrian  struct fsm fsm;		/* The finite state machine */
5136285Sbrian  u_int16_t his_mru;		/* Peers maximum packet size */
5236285Sbrian  u_int16_t his_mrru;		/* Peers maximum reassembled packet size (MP) */
5336285Sbrian  u_int32_t his_accmap;		/* Peeers async char control map */
5436285Sbrian  u_int32_t his_magic;		/* Peers magic number */
5537210Sbrian  u_int32_t his_lqrperiod;	/* Peers LQR frequency (100ths of seconds) */
5636285Sbrian  u_short his_auth;		/* Peer wants this type of authentication */
5744106Sbrian  u_char his_authtype;		/* Fifth octet of REQ/NAK/REJ */
5838174Sbrian  struct callback his_callback;	/* Peer wants callback ? */
5936285Sbrian  unsigned his_shortseq : 1;	/* Peer would like only 12bit seqs (MP) */
6036285Sbrian  unsigned his_protocomp : 1;	/* Does peer do Protocol field compression */
6136285Sbrian  unsigned his_acfcomp : 1;	/* Does peer do addr & cntrl fld compression */
6285094Sbrian  unsigned mru_req : 1;		/* Has the peer requested an MRU */
636059Samurai
6436285Sbrian  u_short want_mru;		/* Our maximum packet size */
6536285Sbrian  u_short want_mrru;		/* Our maximum reassembled packet size (MP) */
6636285Sbrian  u_int32_t want_accmap;	/* Our async char control map */
6736285Sbrian  u_int32_t want_magic;		/* Our magic number */
6837210Sbrian  u_int32_t want_lqrperiod;	/* Our LQR frequency (100ths of seconds) */
6936285Sbrian  u_short want_auth;		/* We want this type of authentication */
7044106Sbrian  u_char want_authtype;		/* Fifth octet of REQ/NAK/REJ */
7138174Sbrian  struct callback want_callback;/* We want callback ? */
7236285Sbrian  unsigned want_shortseq : 1;	/* I'd like only 12bit seqs (MP) */
7336285Sbrian  unsigned want_protocomp : 1;	/* Do we do protocol field compression */
7436285Sbrian  unsigned want_acfcomp : 1;	/* Do we do addr & cntrl fld compression */
756059Samurai
7632439Sbrian  u_int32_t his_reject;		/* Request codes rejected by peer */
7732439Sbrian  u_int32_t my_reject;		/* Request codes I have rejected */
786059Samurai
7936285Sbrian  u_short auth_iwait;		/* I must authenticate to the peer */
8036285Sbrian  u_short auth_ineed;		/* I require that the peer authenticates */
8136285Sbrian
8236285Sbrian  int LcpFailedMagic;		/* Number of `magic is same' errors */
8336285Sbrian
8436285Sbrian  struct {
8536285Sbrian    u_short mru;		/* Preferred MRU value */
8678410Sbrian    u_short max_mru;		/* Preferred MRU value */
8778410Sbrian    u_short mtu;		/* Preferred MTU */
8878410Sbrian    u_short max_mtu;		/* Preferred MTU */
8936285Sbrian    u_int32_t accmap;		/* Initial ACCMAP value */
9036285Sbrian    int openmode;		/* when to start CFG REQs */
9137210Sbrian    u_int32_t lqrperiod;	/* LQR frequency (seconds) */
9244305Sbrian    struct fsm_retry fsm;	/* How often/frequently to resend requests */
9336285Sbrian    unsigned acfcomp : 2;	/* Address & Control Field Compression neg */
9444106Sbrian    unsigned chap05 : 2;	/* Challenge Handshake Authentication proto */
9593418Sbrian#ifndef NODES
9644106Sbrian    unsigned chap80nt : 2;	/* Microsoft (NT) CHAP */
9744106Sbrian    unsigned chap80lm : 2;	/* Microsoft (LANMan) CHAP */
9867910Sbrian    unsigned chap81 : 2;	/* Microsoft CHAP v2 */
9944106Sbrian#endif
10036285Sbrian    unsigned lqr : 2;		/* Link Quality Report */
101138799Sbrian    unsigned echo : 1;		/* Send echo Requests */
10236285Sbrian    unsigned pap : 2;		/* Password Authentication protocol */
10336285Sbrian    unsigned protocomp : 2;	/* Protocol field compression */
10463484Sbrian    char ident[DEF_MRU - 7];	/* SendIdentification() data */
10536285Sbrian  } cfg;
1066059Samurai};
1076059Samurai
10863484Sbrian#define	LCP_MAXCODE	CODE_IDENT
10936285Sbrian#define	LCP_MINMPCODE	CODE_CODEREJ
1106059Samurai
1116059Samurai#define	TY_MRU		1	/* Maximum-Receive-Unit */
1126059Samurai#define	TY_ACCMAP	2	/* Async-Control-Character-Map */
1136059Samurai#define	TY_AUTHPROTO	3	/* Authentication-Protocol */
1146059Samurai#define	TY_QUALPROTO	4	/* Quality-Protocol */
1156059Samurai#define	TY_MAGICNUM	5	/* Magic-Number */
1166059Samurai#define	TY_RESERVED	6	/* RESERVED */
1176059Samurai#define	TY_PROTOCOMP	7	/* Protocol-Field-Compression */
1186059Samurai#define	TY_ACFCOMP	8	/* Address-and-Control-Field-Compression */
1196059Samurai#define	TY_FCSALT	9	/* FCS-Alternatives */
12031171Sbrian#define	TY_SDP		10	/* Self-Describing-Padding */
12138174Sbrian#define	TY_CALLBACK	13	/* Callback */
12238174Sbrian#define	TY_CFRAMES	15	/* Compound-frames */
12336285Sbrian#define	TY_MRRU		17	/* Max Reconstructed Receive Unit (MP) */
12436285Sbrian#define	TY_SHORTSEQ	18	/* Want short seqs (12bit) please (see mp.h) */
12536285Sbrian#define	TY_ENDDISC	19	/* Endpoint discriminator */
1266059Samurai
12736285Sbrianstruct mbuf;
12836285Sbrianstruct link;
12936285Sbrianstruct bundle;
13036285Sbrianstruct cmdargs;
1316059Samurai
13236285Sbrian#define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcp *)fp : NULL)
13336285Sbrian
13436285Sbrianextern void lcp_Init(struct lcp *, struct bundle *, struct link *,
13536285Sbrian                     const struct fsm_parent *);
13636285Sbrianextern void lcp_Setup(struct lcp *, int);
13736285Sbrian
13836285Sbrianextern void lcp_SendProtoRej(struct lcp *, u_char *, int);
13963484Sbrianextern int lcp_SendIdentification(struct lcp *);
14063484Sbrianextern void lcp_RecvIdentification(struct lcp *, char *);
14136285Sbrianextern int lcp_ReportStatus(struct cmdargs const *);
14246686Sbrianextern struct mbuf *lcp_Input(struct bundle *, struct link *, struct mbuf *);
14336285Sbrianextern void lcp_SetupCallbacks(struct lcp *);
144