1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5 *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6 *                           Internet Initiative Japan, Inc (IIJ)
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD$
31 */
32
33/* callback::opmask values */
34#define CALLBACK_AUTH		(0)
35#define CALLBACK_DIALSTRING	(1)	/* Don't do this */
36#define CALLBACK_LOCATION	(2)	/* Don't do this */
37#define CALLBACK_E164		(3)
38#define CALLBACK_NAME		(4)	/* Don't do this */
39#define CALLBACK_CBCP		(6)
40#define CALLBACK_NONE		(14)	/* No callback is ok */
41
42#define CALLBACK_BIT(n) ((n) < 0 ? 0 : 1 << (n))
43
44struct callback {
45  int opmask;			/* want these types of callback */
46  char msg[SCRIPT_LEN];		/* with this data (E.164) */
47};
48
49#define	REJECTED(p, x)	((p)->his_reject & (1<<(x)))
50
51struct lcp {
52  struct fsm fsm;		/* The finite state machine */
53  u_int16_t his_mru;		/* Peers maximum packet size */
54  u_int16_t his_mrru;		/* Peers maximum reassembled packet size (MP) */
55  u_int32_t his_accmap;		/* Peeers async char control map */
56  u_int32_t his_magic;		/* Peers magic number */
57  u_int32_t his_lqrperiod;	/* Peers LQR frequency (100ths of seconds) */
58  u_short his_auth;		/* Peer wants this type of authentication */
59  u_char his_authtype;		/* Fifth octet of REQ/NAK/REJ */
60  struct callback his_callback;	/* Peer wants callback ? */
61  unsigned his_shortseq : 1;	/* Peer would like only 12bit seqs (MP) */
62  unsigned his_protocomp : 1;	/* Does peer do Protocol field compression */
63  unsigned his_acfcomp : 1;	/* Does peer do addr & cntrl fld compression */
64  unsigned mru_req : 1;		/* Has the peer requested an MRU */
65
66  u_short want_mru;		/* Our maximum packet size */
67  u_short want_mrru;		/* Our maximum reassembled packet size (MP) */
68  u_int32_t want_accmap;	/* Our async char control map */
69  u_int32_t want_magic;		/* Our magic number */
70  u_int32_t want_lqrperiod;	/* Our LQR frequency (100ths of seconds) */
71  u_short want_auth;		/* We want this type of authentication */
72  u_char want_authtype;		/* Fifth octet of REQ/NAK/REJ */
73  struct callback want_callback;/* We want callback ? */
74  unsigned want_shortseq : 1;	/* I'd like only 12bit seqs (MP) */
75  unsigned want_protocomp : 1;	/* Do we do protocol field compression */
76  unsigned want_acfcomp : 1;	/* Do we do addr & cntrl fld compression */
77
78  u_int32_t his_reject;		/* Request codes rejected by peer */
79  u_int32_t my_reject;		/* Request codes I have rejected */
80
81  u_short auth_iwait;		/* I must authenticate to the peer */
82  u_short auth_ineed;		/* I require that the peer authenticates */
83
84  int LcpFailedMagic;		/* Number of `magic is same' errors */
85
86  struct {
87    u_short mru;		/* Preferred MRU value */
88    u_short max_mru;		/* Preferred MRU value */
89    u_short mtu;		/* Preferred MTU */
90    u_short max_mtu;		/* Preferred MTU */
91    u_int32_t accmap;		/* Initial ACCMAP value */
92    int openmode;		/* when to start CFG REQs */
93    u_int32_t lqrperiod;	/* LQR frequency (seconds) */
94    struct fsm_retry fsm;	/* How often/frequently to resend requests */
95    unsigned acfcomp : 2;	/* Address & Control Field Compression neg */
96    unsigned chap05 : 2;	/* Challenge Handshake Authentication proto */
97#ifndef NODES
98    unsigned chap80nt : 2;	/* Microsoft (NT) CHAP */
99    unsigned chap80lm : 2;	/* Microsoft (LANMan) CHAP */
100    unsigned chap81 : 2;	/* Microsoft CHAP v2 */
101#endif
102    unsigned lqr : 2;		/* Link Quality Report */
103    unsigned echo : 1;		/* Send echo Requests */
104    unsigned pap : 2;		/* Password Authentication protocol */
105    unsigned protocomp : 2;	/* Protocol field compression */
106    char ident[DEF_MRU - 7];	/* SendIdentification() data */
107  } cfg;
108};
109
110#define	LCP_MAXCODE	CODE_IDENT
111#define	LCP_MINMPCODE	CODE_CODEREJ
112
113#define	TY_MRU		1	/* Maximum-Receive-Unit */
114#define	TY_ACCMAP	2	/* Async-Control-Character-Map */
115#define	TY_AUTHPROTO	3	/* Authentication-Protocol */
116#define	TY_QUALPROTO	4	/* Quality-Protocol */
117#define	TY_MAGICNUM	5	/* Magic-Number */
118#define	TY_RESERVED	6	/* RESERVED */
119#define	TY_PROTOCOMP	7	/* Protocol-Field-Compression */
120#define	TY_ACFCOMP	8	/* Address-and-Control-Field-Compression */
121#define	TY_FCSALT	9	/* FCS-Alternatives */
122#define	TY_SDP		10	/* Self-Describing-Padding */
123#define	TY_CALLBACK	13	/* Callback */
124#define	TY_CFRAMES	15	/* Compound-frames */
125#define	TY_MRRU		17	/* Max Reconstructed Receive Unit (MP) */
126#define	TY_SHORTSEQ	18	/* Want short seqs (12bit) please (see mp.h) */
127#define	TY_ENDDISC	19	/* Endpoint discriminator */
128
129struct mbuf;
130struct link;
131struct bundle;
132struct cmdargs;
133
134#define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcp *)fp : NULL)
135
136extern void lcp_Init(struct lcp *, struct bundle *, struct link *,
137                     const struct fsm_parent *);
138extern void lcp_Setup(struct lcp *, int);
139
140extern void lcp_SendProtoRej(struct lcp *, u_char *, int);
141extern int lcp_SendIdentification(struct lcp *);
142extern void lcp_RecvIdentification(struct lcp *, char *);
143extern int lcp_ReportStatus(struct cmdargs const *);
144extern struct mbuf *lcp_Input(struct bundle *, struct link *, struct mbuf *);
145extern void lcp_SetupCallbacks(struct lcp *);
146