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