1*10465441SEvalZero /*
2*10465441SEvalZero * ecp.c - PPP Encryption Control Protocol.
3*10465441SEvalZero *
4*10465441SEvalZero * Copyright (c) 2002 Google, Inc.
5*10465441SEvalZero * All rights reserved.
6*10465441SEvalZero *
7*10465441SEvalZero * Redistribution and use in source and binary forms, with or without
8*10465441SEvalZero * modification, are permitted provided that the following conditions
9*10465441SEvalZero * are met:
10*10465441SEvalZero *
11*10465441SEvalZero * 1. Redistributions of source code must retain the above copyright
12*10465441SEvalZero * notice, this list of conditions and the following disclaimer.
13*10465441SEvalZero *
14*10465441SEvalZero * 2. Redistributions in binary form must reproduce the above copyright
15*10465441SEvalZero * notice, this list of conditions and the following disclaimer in
16*10465441SEvalZero * the documentation and/or other materials provided with the
17*10465441SEvalZero * distribution.
18*10465441SEvalZero *
19*10465441SEvalZero * 3. The name(s) of the authors of this software must not be used to
20*10465441SEvalZero * endorse or promote products derived from this software without
21*10465441SEvalZero * prior written permission.
22*10465441SEvalZero *
23*10465441SEvalZero * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
24*10465441SEvalZero * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25*10465441SEvalZero * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
26*10465441SEvalZero * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27*10465441SEvalZero * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
28*10465441SEvalZero * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
29*10465441SEvalZero * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30*10465441SEvalZero *
31*10465441SEvalZero * Derived from ccp.c, which is:
32*10465441SEvalZero *
33*10465441SEvalZero * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
34*10465441SEvalZero *
35*10465441SEvalZero * Redistribution and use in source and binary forms, with or without
36*10465441SEvalZero * modification, are permitted provided that the following conditions
37*10465441SEvalZero * are met:
38*10465441SEvalZero *
39*10465441SEvalZero * 1. Redistributions of source code must retain the above copyright
40*10465441SEvalZero * notice, this list of conditions and the following disclaimer.
41*10465441SEvalZero *
42*10465441SEvalZero * 2. The name(s) of the authors of this software must not be used to
43*10465441SEvalZero * endorse or promote products derived from this software without
44*10465441SEvalZero * prior written permission.
45*10465441SEvalZero *
46*10465441SEvalZero * 3. Redistributions of any form whatsoever must retain the following
47*10465441SEvalZero * acknowledgment:
48*10465441SEvalZero * "This product includes software developed by Paul Mackerras
49*10465441SEvalZero * <[email protected]>".
50*10465441SEvalZero *
51*10465441SEvalZero * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
52*10465441SEvalZero * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
53*10465441SEvalZero * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
54*10465441SEvalZero * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55*10465441SEvalZero * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
56*10465441SEvalZero * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
57*10465441SEvalZero * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
58*10465441SEvalZero */
59*10465441SEvalZero
60*10465441SEvalZero #include "netif/ppp/ppp_opts.h"
61*10465441SEvalZero #if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
62*10465441SEvalZero
63*10465441SEvalZero #include <string.h>
64*10465441SEvalZero
65*10465441SEvalZero #include "netif/ppp/ppp_impl.h"
66*10465441SEvalZero
67*10465441SEvalZero #include "netif/ppp/fsm.h"
68*10465441SEvalZero #include "netif/ppp/ecp.h"
69*10465441SEvalZero
70*10465441SEvalZero #if PPP_OPTIONS
71*10465441SEvalZero static option_t ecp_option_list[] = {
72*10465441SEvalZero { "noecp", o_bool, &ecp_protent.enabled_flag,
73*10465441SEvalZero "Disable ECP negotiation" },
74*10465441SEvalZero { "-ecp", o_bool, &ecp_protent.enabled_flag,
75*10465441SEvalZero "Disable ECP negotiation", OPT_ALIAS },
76*10465441SEvalZero
77*10465441SEvalZero { NULL }
78*10465441SEvalZero };
79*10465441SEvalZero #endif /* PPP_OPTIONS */
80*10465441SEvalZero
81*10465441SEvalZero /*
82*10465441SEvalZero * Protocol entry points from main code.
83*10465441SEvalZero */
84*10465441SEvalZero static void ecp_init (int unit);
85*10465441SEvalZero /*
86*10465441SEvalZero static void ecp_open (int unit);
87*10465441SEvalZero static void ecp_close (int unit, char *);
88*10465441SEvalZero static void ecp_lowerup (int unit);
89*10465441SEvalZero static void ecp_lowerdown (int);
90*10465441SEvalZero static void ecp_input (int unit, u_char *pkt, int len);
91*10465441SEvalZero static void ecp_protrej (int unit);
92*10465441SEvalZero */
93*10465441SEvalZero #if PRINTPKT_SUPPORT
94*10465441SEvalZero static int ecp_printpkt (const u_char *pkt, int len,
95*10465441SEvalZero void (*printer) (void *, char *, ...),
96*10465441SEvalZero void *arg);
97*10465441SEvalZero #endif /* PRINTPKT_SUPPORT */
98*10465441SEvalZero /*
99*10465441SEvalZero static void ecp_datainput (int unit, u_char *pkt, int len);
100*10465441SEvalZero */
101*10465441SEvalZero
102*10465441SEvalZero const struct protent ecp_protent = {
103*10465441SEvalZero PPP_ECP,
104*10465441SEvalZero ecp_init,
105*10465441SEvalZero NULL, /* ecp_input, */
106*10465441SEvalZero NULL, /* ecp_protrej, */
107*10465441SEvalZero NULL, /* ecp_lowerup, */
108*10465441SEvalZero NULL, /* ecp_lowerdown, */
109*10465441SEvalZero NULL, /* ecp_open, */
110*10465441SEvalZero NULL, /* ecp_close, */
111*10465441SEvalZero #if PRINTPKT_SUPPORT
112*10465441SEvalZero ecp_printpkt,
113*10465441SEvalZero #endif /* PRINTPKT_SUPPORT */
114*10465441SEvalZero #if PPP_DATAINPUT
115*10465441SEvalZero NULL, /* ecp_datainput, */
116*10465441SEvalZero #endif /* PPP_DATAINPUT */
117*10465441SEvalZero #if PRINTPKT_SUPPORT
118*10465441SEvalZero "ECP",
119*10465441SEvalZero "Encrypted",
120*10465441SEvalZero #endif /* PRINTPKT_SUPPORT */
121*10465441SEvalZero #if PPP_OPTIONS
122*10465441SEvalZero ecp_option_list,
123*10465441SEvalZero NULL,
124*10465441SEvalZero #endif /* PPP_OPTIONS */
125*10465441SEvalZero #if DEMAND_SUPPORT
126*10465441SEvalZero NULL,
127*10465441SEvalZero NULL
128*10465441SEvalZero #endif /* DEMAND_SUPPORT */
129*10465441SEvalZero };
130*10465441SEvalZero
131*10465441SEvalZero fsm ecp_fsm[NUM_PPP];
132*10465441SEvalZero ecp_options ecp_wantoptions[NUM_PPP]; /* what to request the peer to use */
133*10465441SEvalZero ecp_options ecp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
134*10465441SEvalZero ecp_options ecp_allowoptions[NUM_PPP]; /* what we'll agree to do */
135*10465441SEvalZero ecp_options ecp_hisoptions[NUM_PPP]; /* what we agreed to do */
136*10465441SEvalZero
137*10465441SEvalZero static const fsm_callbacks ecp_callbacks = {
138*10465441SEvalZero NULL, /* ecp_resetci, */
139*10465441SEvalZero NULL, /* ecp_cilen, */
140*10465441SEvalZero NULL, /* ecp_addci, */
141*10465441SEvalZero NULL, /* ecp_ackci, */
142*10465441SEvalZero NULL, /* ecp_nakci, */
143*10465441SEvalZero NULL, /* ecp_rejci, */
144*10465441SEvalZero NULL, /* ecp_reqci, */
145*10465441SEvalZero NULL, /* ecp_up, */
146*10465441SEvalZero NULL, /* ecp_down, */
147*10465441SEvalZero NULL,
148*10465441SEvalZero NULL,
149*10465441SEvalZero NULL,
150*10465441SEvalZero NULL,
151*10465441SEvalZero NULL, /* ecp_extcode, */
152*10465441SEvalZero "ECP"
153*10465441SEvalZero };
154*10465441SEvalZero
155*10465441SEvalZero /*
156*10465441SEvalZero * ecp_init - initialize ECP.
157*10465441SEvalZero */
158*10465441SEvalZero static void
ecp_init(unit)159*10465441SEvalZero ecp_init(unit)
160*10465441SEvalZero int unit;
161*10465441SEvalZero {
162*10465441SEvalZero fsm *f = &ecp_fsm[unit];
163*10465441SEvalZero
164*10465441SEvalZero f->unit = unit;
165*10465441SEvalZero f->protocol = PPP_ECP;
166*10465441SEvalZero f->callbacks = &ecp_callbacks;
167*10465441SEvalZero fsm_init(f);
168*10465441SEvalZero
169*10465441SEvalZero #if 0 /* Not necessary, everything is cleared in ppp_new() */
170*10465441SEvalZero memset(&ecp_wantoptions[unit], 0, sizeof(ecp_options));
171*10465441SEvalZero memset(&ecp_gotoptions[unit], 0, sizeof(ecp_options));
172*10465441SEvalZero memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options));
173*10465441SEvalZero memset(&ecp_hisoptions[unit], 0, sizeof(ecp_options));
174*10465441SEvalZero #endif /* 0 */
175*10465441SEvalZero
176*10465441SEvalZero }
177*10465441SEvalZero
178*10465441SEvalZero
179*10465441SEvalZero #if PRINTPKT_SUPPORT
180*10465441SEvalZero static int
ecp_printpkt(p,plen,printer,arg)181*10465441SEvalZero ecp_printpkt(p, plen, printer, arg)
182*10465441SEvalZero const u_char *p;
183*10465441SEvalZero int plen;
184*10465441SEvalZero void (*printer) (void *, char *, ...);
185*10465441SEvalZero void *arg;
186*10465441SEvalZero {
187*10465441SEvalZero return 0;
188*10465441SEvalZero }
189*10465441SEvalZero #endif /* PRINTPKT_SUPPORT */
190*10465441SEvalZero
191*10465441SEvalZero #endif /* PPP_SUPPORT && ECP_SUPPORT */
192