1195972f6Sopenharmony_ci/*
2195972f6Sopenharmony_ci * ecp.c - PPP Encryption Control Protocol.
3195972f6Sopenharmony_ci *
4195972f6Sopenharmony_ci * Copyright (c) 2002 Google, Inc.
5195972f6Sopenharmony_ci * All rights reserved.
6195972f6Sopenharmony_ci *
7195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
8195972f6Sopenharmony_ci * modification, are permitted provided that the following conditions
9195972f6Sopenharmony_ci * are met:
10195972f6Sopenharmony_ci *
11195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
12195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
13195972f6Sopenharmony_ci *
14195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
15195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
16195972f6Sopenharmony_ci *    the documentation and/or other materials provided with the
17195972f6Sopenharmony_ci *    distribution.
18195972f6Sopenharmony_ci *
19195972f6Sopenharmony_ci * 3. The name(s) of the authors of this software must not be used to
20195972f6Sopenharmony_ci *    endorse or promote products derived from this software without
21195972f6Sopenharmony_ci *    prior written permission.
22195972f6Sopenharmony_ci *
23195972f6Sopenharmony_ci * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
24195972f6Sopenharmony_ci * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25195972f6Sopenharmony_ci * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
26195972f6Sopenharmony_ci * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27195972f6Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
28195972f6Sopenharmony_ci * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
29195972f6Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30195972f6Sopenharmony_ci *
31195972f6Sopenharmony_ci * Derived from ccp.c, which is:
32195972f6Sopenharmony_ci *
33195972f6Sopenharmony_ci * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
34195972f6Sopenharmony_ci *
35195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
36195972f6Sopenharmony_ci * modification, are permitted provided that the following conditions
37195972f6Sopenharmony_ci * are met:
38195972f6Sopenharmony_ci *
39195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
40195972f6Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
41195972f6Sopenharmony_ci *
42195972f6Sopenharmony_ci * 2. The name(s) of the authors of this software must not be used to
43195972f6Sopenharmony_ci *    endorse or promote products derived from this software without
44195972f6Sopenharmony_ci *    prior written permission.
45195972f6Sopenharmony_ci *
46195972f6Sopenharmony_ci * 3. Redistributions of any form whatsoever must retain the following
47195972f6Sopenharmony_ci *    acknowledgment:
48195972f6Sopenharmony_ci *    "This product includes software developed by Paul Mackerras
49195972f6Sopenharmony_ci *     <paulus@samba.org>".
50195972f6Sopenharmony_ci *
51195972f6Sopenharmony_ci * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
52195972f6Sopenharmony_ci * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
53195972f6Sopenharmony_ci * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
54195972f6Sopenharmony_ci * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55195972f6Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
56195972f6Sopenharmony_ci * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
57195972f6Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
58195972f6Sopenharmony_ci */
59195972f6Sopenharmony_ci
60195972f6Sopenharmony_ci#include "netif/ppp/ppp_opts.h"
61195972f6Sopenharmony_ci#if PPP_SUPPORT && ECP_SUPPORT  /* don't build if not configured for use in lwipopts.h */
62195972f6Sopenharmony_ci
63195972f6Sopenharmony_ci#include <string.h>
64195972f6Sopenharmony_ci
65195972f6Sopenharmony_ci#include "netif/ppp/ppp_impl.h"
66195972f6Sopenharmony_ci
67195972f6Sopenharmony_ci#include "netif/ppp/fsm.h"
68195972f6Sopenharmony_ci#include "netif/ppp/ecp.h"
69195972f6Sopenharmony_ci
70195972f6Sopenharmony_ci#if PPP_OPTIONS
71195972f6Sopenharmony_cistatic option_t ecp_option_list[] = {
72195972f6Sopenharmony_ci    { "noecp", o_bool, &ecp_protent.enabled_flag,
73195972f6Sopenharmony_ci      "Disable ECP negotiation" },
74195972f6Sopenharmony_ci    { "-ecp", o_bool, &ecp_protent.enabled_flag,
75195972f6Sopenharmony_ci      "Disable ECP negotiation", OPT_ALIAS },
76195972f6Sopenharmony_ci
77195972f6Sopenharmony_ci    { NULL }
78195972f6Sopenharmony_ci};
79195972f6Sopenharmony_ci#endif /* PPP_OPTIONS */
80195972f6Sopenharmony_ci
81195972f6Sopenharmony_ci/*
82195972f6Sopenharmony_ci * Protocol entry points from main code.
83195972f6Sopenharmony_ci */
84195972f6Sopenharmony_cistatic void ecp_init (int unit);
85195972f6Sopenharmony_ci/*
86195972f6Sopenharmony_cistatic void ecp_open (int unit);
87195972f6Sopenharmony_cistatic void ecp_close (int unit, char *);
88195972f6Sopenharmony_cistatic void ecp_lowerup (int unit);
89195972f6Sopenharmony_cistatic void ecp_lowerdown (int);
90195972f6Sopenharmony_cistatic void ecp_input (int unit, u_char *pkt, int len);
91195972f6Sopenharmony_cistatic void ecp_protrej (int unit);
92195972f6Sopenharmony_ci*/
93195972f6Sopenharmony_ci#if PRINTPKT_SUPPORT
94195972f6Sopenharmony_cistatic int  ecp_printpkt (const u_char *pkt, int len,
95195972f6Sopenharmony_ci			      void (*printer) (void *, char *, ...),
96195972f6Sopenharmony_ci			      void *arg);
97195972f6Sopenharmony_ci#endif /* PRINTPKT_SUPPORT */
98195972f6Sopenharmony_ci/*
99195972f6Sopenharmony_cistatic void ecp_datainput (int unit, u_char *pkt, int len);
100195972f6Sopenharmony_ci*/
101195972f6Sopenharmony_ci
102195972f6Sopenharmony_ciconst struct protent ecp_protent = {
103195972f6Sopenharmony_ci    PPP_ECP,
104195972f6Sopenharmony_ci    ecp_init,
105195972f6Sopenharmony_ci    NULL, /* ecp_input, */
106195972f6Sopenharmony_ci    NULL, /* ecp_protrej, */
107195972f6Sopenharmony_ci    NULL, /* ecp_lowerup, */
108195972f6Sopenharmony_ci    NULL, /* ecp_lowerdown, */
109195972f6Sopenharmony_ci    NULL, /* ecp_open, */
110195972f6Sopenharmony_ci    NULL, /* ecp_close, */
111195972f6Sopenharmony_ci#if PRINTPKT_SUPPORT
112195972f6Sopenharmony_ci    ecp_printpkt,
113195972f6Sopenharmony_ci#endif /* PRINTPKT_SUPPORT */
114195972f6Sopenharmony_ci#if PPP_DATAINPUT
115195972f6Sopenharmony_ci    NULL, /* ecp_datainput, */
116195972f6Sopenharmony_ci#endif /* PPP_DATAINPUT */
117195972f6Sopenharmony_ci#if PRINTPKT_SUPPORT
118195972f6Sopenharmony_ci    "ECP",
119195972f6Sopenharmony_ci    "Encrypted",
120195972f6Sopenharmony_ci#endif /* PRINTPKT_SUPPORT */
121195972f6Sopenharmony_ci#if PPP_OPTIONS
122195972f6Sopenharmony_ci    ecp_option_list,
123195972f6Sopenharmony_ci    NULL,
124195972f6Sopenharmony_ci#endif /* PPP_OPTIONS */
125195972f6Sopenharmony_ci#if DEMAND_SUPPORT
126195972f6Sopenharmony_ci    NULL,
127195972f6Sopenharmony_ci    NULL
128195972f6Sopenharmony_ci#endif /* DEMAND_SUPPORT */
129195972f6Sopenharmony_ci};
130195972f6Sopenharmony_ci
131195972f6Sopenharmony_cifsm ecp_fsm[NUM_PPP];
132195972f6Sopenharmony_ciecp_options ecp_wantoptions[NUM_PPP];	/* what to request the peer to use */
133195972f6Sopenharmony_ciecp_options ecp_gotoptions[NUM_PPP];	/* what the peer agreed to do */
134195972f6Sopenharmony_ciecp_options ecp_allowoptions[NUM_PPP];	/* what we'll agree to do */
135195972f6Sopenharmony_ciecp_options ecp_hisoptions[NUM_PPP];	/* what we agreed to do */
136195972f6Sopenharmony_ci
137195972f6Sopenharmony_cistatic const fsm_callbacks ecp_callbacks = {
138195972f6Sopenharmony_ci    NULL, /* ecp_resetci, */
139195972f6Sopenharmony_ci    NULL, /* ecp_cilen, */
140195972f6Sopenharmony_ci    NULL, /* ecp_addci, */
141195972f6Sopenharmony_ci    NULL, /* ecp_ackci, */
142195972f6Sopenharmony_ci    NULL, /* ecp_nakci, */
143195972f6Sopenharmony_ci    NULL, /* ecp_rejci, */
144195972f6Sopenharmony_ci    NULL, /* ecp_reqci, */
145195972f6Sopenharmony_ci    NULL, /* ecp_up, */
146195972f6Sopenharmony_ci    NULL, /* ecp_down, */
147195972f6Sopenharmony_ci    NULL,
148195972f6Sopenharmony_ci    NULL,
149195972f6Sopenharmony_ci    NULL,
150195972f6Sopenharmony_ci    NULL,
151195972f6Sopenharmony_ci    NULL, /* ecp_extcode, */
152195972f6Sopenharmony_ci    "ECP"
153195972f6Sopenharmony_ci};
154195972f6Sopenharmony_ci
155195972f6Sopenharmony_ci/*
156195972f6Sopenharmony_ci * ecp_init - initialize ECP.
157195972f6Sopenharmony_ci */
158195972f6Sopenharmony_cistatic void
159195972f6Sopenharmony_ciecp_init(unit)
160195972f6Sopenharmony_ci    int unit;
161195972f6Sopenharmony_ci{
162195972f6Sopenharmony_ci    fsm *f = &ecp_fsm[unit];
163195972f6Sopenharmony_ci
164195972f6Sopenharmony_ci    f->unit = unit;
165195972f6Sopenharmony_ci    f->protocol = PPP_ECP;
166195972f6Sopenharmony_ci    f->callbacks = &ecp_callbacks;
167195972f6Sopenharmony_ci    fsm_init(f);
168195972f6Sopenharmony_ci
169195972f6Sopenharmony_ci#if 0 /* Not necessary, everything is cleared in ppp_new() */
170195972f6Sopenharmony_ci    memset(&ecp_wantoptions[unit],  0, sizeof(ecp_options));
171195972f6Sopenharmony_ci    memset(&ecp_gotoptions[unit],   0, sizeof(ecp_options));
172195972f6Sopenharmony_ci    memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options));
173195972f6Sopenharmony_ci    memset(&ecp_hisoptions[unit],   0, sizeof(ecp_options));
174195972f6Sopenharmony_ci#endif /* 0 */
175195972f6Sopenharmony_ci
176195972f6Sopenharmony_ci}
177195972f6Sopenharmony_ci
178195972f6Sopenharmony_ci
179195972f6Sopenharmony_ci#if PRINTPKT_SUPPORT
180195972f6Sopenharmony_cistatic int
181195972f6Sopenharmony_ciecp_printpkt(p, plen, printer, arg)
182195972f6Sopenharmony_ci    const u_char *p;
183195972f6Sopenharmony_ci    int plen;
184195972f6Sopenharmony_ci    void (*printer) (void *, char *, ...);
185195972f6Sopenharmony_ci    void *arg;
186195972f6Sopenharmony_ci{
187195972f6Sopenharmony_ci    return 0;
188195972f6Sopenharmony_ci}
189195972f6Sopenharmony_ci#endif /* PRINTPKT_SUPPORT */
190195972f6Sopenharmony_ci
191195972f6Sopenharmony_ci#endif /* PPP_SUPPORT && ECP_SUPPORT */
192