BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /***************************************************************************** |
2 | * ppp.h - Network Point to Point Protocol header file. |
||
3 | * |
||
4 | * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. |
||
5 | * portions Copyright (c) 1997 Global Election Systems Inc. |
||
6 | * |
||
7 | * The authors hereby grant permission to use, copy, modify, distribute, |
||
8 | * and license this software and its documentation for any purpose, provided |
||
9 | * that existing copyright notices are retained in all copies and that this |
||
10 | * notice and the following disclaimer are included verbatim in any |
||
11 | * distributions. No written agreement, license, or royalty fee is required |
||
12 | * for any of the authorized uses. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR |
||
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
17 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
24 | * |
||
25 | ****************************************************************************** |
||
26 | * REVISION HISTORY |
||
27 | * |
||
28 | * 03-01-01 Marc Boucher <marc@mbsi.ca> |
||
29 | * Ported to lwIP. |
||
30 | * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. |
||
31 | * Original derived from BSD codes. |
||
32 | *****************************************************************************/ |
||
33 | |||
34 | #include "netif/ppp/ppp_opts.h" |
||
35 | #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ |
||
36 | |||
37 | #ifndef PPP_H |
||
38 | #define PPP_H |
||
39 | |||
40 | #include "lwip/def.h" |
||
41 | #include "lwip/stats.h" |
||
42 | #include "lwip/mem.h" |
||
43 | #include "lwip/netif.h" |
||
44 | #include "lwip/sys.h" |
||
45 | #include "lwip/timeouts.h" |
||
46 | #if PPP_IPV6_SUPPORT |
||
47 | #include "lwip/ip6_addr.h" |
||
48 | #endif /* PPP_IPV6_SUPPORT */ |
||
49 | |||
50 | /* Disable non-working or rarely used PPP feature, so rarely that we don't want to bloat ppp_opts.h with them */ |
||
51 | #ifndef PPP_OPTIONS |
||
52 | #define PPP_OPTIONS 0 |
||
53 | #endif |
||
54 | |||
55 | #ifndef PPP_NOTIFY |
||
56 | #define PPP_NOTIFY 0 |
||
57 | #endif |
||
58 | |||
59 | #ifndef PPP_REMOTENAME |
||
60 | #define PPP_REMOTENAME 0 |
||
61 | #endif |
||
62 | |||
63 | #ifndef PPP_IDLETIMELIMIT |
||
64 | #define PPP_IDLETIMELIMIT 0 |
||
65 | #endif |
||
66 | |||
67 | #ifndef PPP_LCP_ADAPTIVE |
||
68 | #define PPP_LCP_ADAPTIVE 0 |
||
69 | #endif |
||
70 | |||
71 | #ifndef PPP_MAXCONNECT |
||
72 | #define PPP_MAXCONNECT 0 |
||
73 | #endif |
||
74 | |||
75 | #ifndef PPP_ALLOWED_ADDRS |
||
76 | #define PPP_ALLOWED_ADDRS 0 |
||
77 | #endif |
||
78 | |||
79 | #ifndef PPP_PROTOCOLNAME |
||
80 | #define PPP_PROTOCOLNAME 0 |
||
81 | #endif |
||
82 | |||
83 | #ifndef PPP_STATS_SUPPORT |
||
84 | #define PPP_STATS_SUPPORT 0 |
||
85 | #endif |
||
86 | |||
87 | #ifndef DEFLATE_SUPPORT |
||
88 | #define DEFLATE_SUPPORT 0 |
||
89 | #endif |
||
90 | |||
91 | #ifndef BSDCOMPRESS_SUPPORT |
||
92 | #define BSDCOMPRESS_SUPPORT 0 |
||
93 | #endif |
||
94 | |||
95 | #ifndef PREDICTOR_SUPPORT |
||
96 | #define PREDICTOR_SUPPORT 0 |
||
97 | #endif |
||
98 | |||
99 | /************************* |
||
100 | *** PUBLIC DEFINITIONS *** |
||
101 | *************************/ |
||
102 | |||
103 | /* |
||
104 | * The basic PPP frame. |
||
105 | */ |
||
106 | #define PPP_HDRLEN 4 /* octets for standard ppp header */ |
||
107 | #define PPP_FCSLEN 2 /* octets for FCS */ |
||
108 | |||
109 | /* |
||
110 | * Values for phase. |
||
111 | */ |
||
112 | #define PPP_PHASE_DEAD 0 |
||
113 | #define PPP_PHASE_MASTER 1 |
||
114 | #define PPP_PHASE_HOLDOFF 2 |
||
115 | #define PPP_PHASE_INITIALIZE 3 |
||
116 | #define PPP_PHASE_SERIALCONN 4 |
||
117 | #define PPP_PHASE_DORMANT 5 |
||
118 | #define PPP_PHASE_ESTABLISH 6 |
||
119 | #define PPP_PHASE_AUTHENTICATE 7 |
||
120 | #define PPP_PHASE_CALLBACK 8 |
||
121 | #define PPP_PHASE_NETWORK 9 |
||
122 | #define PPP_PHASE_RUNNING 10 |
||
123 | #define PPP_PHASE_TERMINATE 11 |
||
124 | #define PPP_PHASE_DISCONNECT 12 |
||
125 | |||
126 | /* Error codes. */ |
||
127 | #define PPPERR_NONE 0 /* No error. */ |
||
128 | #define PPPERR_PARAM 1 /* Invalid parameter. */ |
||
129 | #define PPPERR_OPEN 2 /* Unable to open PPP session. */ |
||
130 | #define PPPERR_DEVICE 3 /* Invalid I/O device for PPP. */ |
||
131 | #define PPPERR_ALLOC 4 /* Unable to allocate resources. */ |
||
132 | #define PPPERR_USER 5 /* User interrupt. */ |
||
133 | #define PPPERR_CONNECT 6 /* Connection lost. */ |
||
134 | #define PPPERR_AUTHFAIL 7 /* Failed authentication challenge. */ |
||
135 | #define PPPERR_PROTOCOL 8 /* Failed to meet protocol. */ |
||
136 | #define PPPERR_PEERDEAD 9 /* Connection timeout */ |
||
137 | #define PPPERR_IDLETIMEOUT 10 /* Idle Timeout */ |
||
138 | #define PPPERR_CONNECTTIME 11 /* Max connect time reached */ |
||
139 | #define PPPERR_LOOPBACK 12 /* Loopback detected */ |
||
140 | |||
141 | /* Whether auth support is enabled at all */ |
||
142 | #define PPP_AUTH_SUPPORT (PAP_SUPPORT || CHAP_SUPPORT || EAP_SUPPORT) |
||
143 | |||
144 | /************************ |
||
145 | *** PUBLIC DATA TYPES *** |
||
146 | ************************/ |
||
147 | |||
148 | /* |
||
149 | * Other headers require ppp_pcb definition for prototypes, but ppp_pcb |
||
150 | * require some structure definition from other headers as well, we are |
||
151 | * fixing the dependency loop here by declaring the ppp_pcb type then |
||
152 | * by including headers containing necessary struct definition for ppp_pcb |
||
153 | */ |
||
154 | typedef struct ppp_pcb_s ppp_pcb; |
||
155 | |||
156 | /* Type definitions for BSD code. */ |
||
157 | #ifndef __u_char_defined |
||
158 | typedef unsigned long u_long; |
||
159 | typedef unsigned int u_int; |
||
160 | typedef unsigned short u_short; |
||
161 | typedef unsigned char u_char; |
||
162 | #endif |
||
163 | |||
164 | #include "fsm.h" |
||
165 | #include "lcp.h" |
||
166 | #if CCP_SUPPORT |
||
167 | #include "ccp.h" |
||
168 | #endif /* CCP_SUPPORT */ |
||
169 | #if MPPE_SUPPORT |
||
170 | #include "mppe.h" |
||
171 | #endif /* MPPE_SUPPORT */ |
||
172 | #if PPP_IPV4_SUPPORT |
||
173 | #include "ipcp.h" |
||
174 | #endif /* PPP_IPV4_SUPPORT */ |
||
175 | #if PPP_IPV6_SUPPORT |
||
176 | #include "ipv6cp.h" |
||
177 | #endif /* PPP_IPV6_SUPPORT */ |
||
178 | #if PAP_SUPPORT |
||
179 | #include "upap.h" |
||
180 | #endif /* PAP_SUPPORT */ |
||
181 | #if CHAP_SUPPORT |
||
182 | #include "chap-new.h" |
||
183 | #endif /* CHAP_SUPPORT */ |
||
184 | #if EAP_SUPPORT |
||
185 | #include "eap.h" |
||
186 | #endif /* EAP_SUPPORT */ |
||
187 | #if VJ_SUPPORT |
||
188 | #include "vj.h" |
||
189 | #endif /* VJ_SUPPORT */ |
||
190 | |||
191 | /* Link status callback function prototype */ |
||
192 | typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx); |
||
193 | |||
194 | /* |
||
195 | * PPP configuration. |
||
196 | */ |
||
197 | typedef struct ppp_settings_s { |
||
198 | |||
199 | #if PPP_SERVER && PPP_AUTH_SUPPORT |
||
200 | unsigned int auth_required :1; /* Peer is required to authenticate */ |
||
201 | unsigned int null_login :1; /* Username of "" and a password of "" are acceptable */ |
||
202 | #endif /* PPP_SERVER && PPP_AUTH_SUPPORT */ |
||
203 | #if PPP_REMOTENAME |
||
204 | unsigned int explicit_remote :1; /* remote_name specified with remotename opt */ |
||
205 | #endif /* PPP_REMOTENAME */ |
||
206 | #if PAP_SUPPORT |
||
207 | unsigned int refuse_pap :1; /* Don't proceed auth. with PAP */ |
||
208 | #endif /* PAP_SUPPORT */ |
||
209 | #if CHAP_SUPPORT |
||
210 | unsigned int refuse_chap :1; /* Don't proceed auth. with CHAP */ |
||
211 | #endif /* CHAP_SUPPORT */ |
||
212 | #if MSCHAP_SUPPORT |
||
213 | unsigned int refuse_mschap :1; /* Don't proceed auth. with MS-CHAP */ |
||
214 | unsigned int refuse_mschap_v2 :1; /* Don't proceed auth. with MS-CHAPv2 */ |
||
215 | #endif /* MSCHAP_SUPPORT */ |
||
216 | #if EAP_SUPPORT |
||
217 | unsigned int refuse_eap :1; /* Don't proceed auth. with EAP */ |
||
218 | #endif /* EAP_SUPPORT */ |
||
219 | #if LWIP_DNS |
||
220 | unsigned int usepeerdns :1; /* Ask peer for DNS adds */ |
||
221 | #endif /* LWIP_DNS */ |
||
222 | unsigned int persist :1; /* Persist mode, always try to open the connection */ |
||
223 | #if PRINTPKT_SUPPORT |
||
224 | unsigned int hide_password :1; /* Hide password in dumped packets */ |
||
225 | #endif /* PRINTPKT_SUPPORT */ |
||
226 | unsigned int noremoteip :1; /* Let him have no IP address */ |
||
227 | unsigned int lax_recv :1; /* accept control chars in asyncmap */ |
||
228 | unsigned int noendpoint :1; /* don't send/accept endpoint discriminator */ |
||
229 | #if PPP_LCP_ADAPTIVE |
||
230 | unsigned int lcp_echo_adaptive :1; /* request echo only if the link was idle */ |
||
231 | #endif /* PPP_LCP_ADAPTIVE */ |
||
232 | #if MPPE_SUPPORT |
||
233 | unsigned int require_mppe :1; /* Require MPPE (Microsoft Point to Point Encryption) */ |
||
234 | unsigned int refuse_mppe_40 :1; /* Allow MPPE 40-bit mode? */ |
||
235 | unsigned int refuse_mppe_128 :1; /* Allow MPPE 128-bit mode? */ |
||
236 | unsigned int refuse_mppe_stateful :1; /* Allow MPPE stateful mode? */ |
||
237 | #endif /* MPPE_SUPPORT */ |
||
238 | |||
239 | u16_t listen_time; /* time to listen first (ms), waiting for peer to send LCP packet */ |
||
240 | |||
241 | #if PPP_IDLETIMELIMIT |
||
242 | u16_t idle_time_limit; /* Disconnect if idle for this many seconds */ |
||
243 | #endif /* PPP_IDLETIMELIMIT */ |
||
244 | #if PPP_MAXCONNECT |
||
245 | u32_t maxconnect; /* Maximum connect time (seconds) */ |
||
246 | #endif /* PPP_MAXCONNECT */ |
||
247 | |||
248 | #if PPP_AUTH_SUPPORT |
||
249 | /* auth data */ |
||
250 | const char *user; /* Username for PAP */ |
||
251 | const char *passwd; /* Password for PAP, secret for CHAP */ |
||
252 | #if PPP_REMOTENAME |
||
253 | char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ |
||
254 | #endif /* PPP_REMOTENAME */ |
||
255 | |||
256 | #if PAP_SUPPORT |
||
257 | u8_t pap_timeout_time; /* Timeout (seconds) for auth-req retrans. */ |
||
258 | u8_t pap_max_transmits; /* Number of auth-reqs sent */ |
||
259 | #if PPP_SERVER |
||
260 | u8_t pap_req_timeout; /* Time to wait for auth-req from peer */ |
||
261 | #endif /* PPP_SERVER */ |
||
262 | #endif /* PAP_SUPPPORT */ |
||
263 | |||
264 | #if CHAP_SUPPORT |
||
265 | u8_t chap_timeout_time; /* Timeout (seconds) for retransmitting req */ |
||
266 | u8_t chap_max_transmits; /* max # times to send challenge */ |
||
267 | #if PPP_SERVER |
||
268 | u8_t chap_rechallenge_time; /* Time to wait for auth-req from peer */ |
||
269 | #endif /* PPP_SERVER */ |
||
270 | #endif /* CHAP_SUPPPORT */ |
||
271 | |||
272 | #if EAP_SUPPORT |
||
273 | u8_t eap_req_time; /* Time to wait (for retransmit/fail) */ |
||
274 | u8_t eap_allow_req; /* Max Requests allowed */ |
||
275 | #if PPP_SERVER |
||
276 | u8_t eap_timeout_time; /* Time to wait (for retransmit/fail) */ |
||
277 | u8_t eap_max_transmits; /* Max Requests allowed */ |
||
278 | #endif /* PPP_SERVER */ |
||
279 | #endif /* EAP_SUPPORT */ |
||
280 | |||
281 | #endif /* PPP_AUTH_SUPPORT */ |
||
282 | |||
283 | u8_t fsm_timeout_time; /* Timeout time in seconds */ |
||
284 | u8_t fsm_max_conf_req_transmits; /* Maximum Configure-Request transmissions */ |
||
285 | u8_t fsm_max_term_transmits; /* Maximum Terminate-Request transmissions */ |
||
286 | u8_t fsm_max_nak_loops; /* Maximum number of nak loops tolerated */ |
||
287 | |||
288 | u8_t lcp_loopbackfail; /* Number of times we receive our magic number from the peer |
||
289 | before deciding the link is looped-back. */ |
||
290 | u8_t lcp_echo_interval; /* Interval between LCP echo-requests */ |
||
291 | u8_t lcp_echo_fails; /* Tolerance to unanswered echo-requests */ |
||
292 | |||
293 | } ppp_settings; |
||
294 | |||
295 | #if PPP_SERVER |
||
296 | struct ppp_addrs { |
||
297 | #if PPP_IPV4_SUPPORT |
||
298 | ip4_addr_t our_ipaddr, his_ipaddr, netmask; |
||
299 | #if LWIP_DNS |
||
300 | ip4_addr_t dns1, dns2; |
||
301 | #endif /* LWIP_DNS */ |
||
302 | #endif /* PPP_IPV4_SUPPORT */ |
||
303 | #if PPP_IPV6_SUPPORT |
||
304 | ip6_addr_t our6_ipaddr, his6_ipaddr; |
||
305 | #endif /* PPP_IPV6_SUPPORT */ |
||
306 | }; |
||
307 | #endif /* PPP_SERVER */ |
||
308 | |||
309 | /* |
||
310 | * PPP interface control block. |
||
311 | */ |
||
312 | struct ppp_pcb_s { |
||
313 | ppp_settings settings; |
||
314 | const struct link_callbacks *link_cb; |
||
315 | void *link_ctx_cb; |
||
316 | void (*link_status_cb)(ppp_pcb *pcb, int err_code, void *ctx); /* Status change callback */ |
||
317 | #if PPP_NOTIFY_PHASE |
||
318 | void (*notify_phase_cb)(ppp_pcb *pcb, u8_t phase, void *ctx); /* Notify phase callback */ |
||
319 | #endif /* PPP_NOTIFY_PHASE */ |
||
320 | void *ctx_cb; /* Callbacks optional pointer */ |
||
321 | struct netif *netif; /* PPP interface */ |
||
322 | u8_t phase; /* where the link is at */ |
||
323 | u8_t err_code; /* Code indicating why interface is down. */ |
||
324 | |||
325 | /* flags */ |
||
326 | #if PPP_IPV4_SUPPORT |
||
327 | unsigned int ask_for_local :1; /* request our address from peer */ |
||
328 | unsigned int ipcp_is_open :1; /* haven't called np_finished() */ |
||
329 | unsigned int ipcp_is_up :1; /* have called ipcp_up() */ |
||
330 | unsigned int if4_up :1; /* True when the IPv4 interface is up. */ |
||
331 | #if 0 /* UNUSED - PROXY ARP */ |
||
332 | unsigned int proxy_arp_set :1; /* Have created proxy arp entry */ |
||
333 | #endif /* UNUSED - PROXY ARP */ |
||
334 | #endif /* PPP_IPV4_SUPPORT */ |
||
335 | #if PPP_IPV6_SUPPORT |
||
336 | unsigned int ipv6cp_is_up :1; /* have called ip6cp_up() */ |
||
337 | unsigned int if6_up :1; /* True when the IPv6 interface is up. */ |
||
338 | #endif /* PPP_IPV6_SUPPORT */ |
||
339 | unsigned int lcp_echo_timer_running :1; /* set if a timer is running */ |
||
340 | #if VJ_SUPPORT |
||
341 | unsigned int vj_enabled :1; /* Flag indicating VJ compression enabled. */ |
||
342 | #endif /* VJ_SUPPORT */ |
||
343 | #if CCP_SUPPORT |
||
344 | unsigned int ccp_all_rejected :1; /* we rejected all peer's options */ |
||
345 | #endif /* CCP_SUPPORT */ |
||
346 | #if MPPE_SUPPORT |
||
347 | unsigned int mppe_keys_set :1; /* Have the MPPE keys been set? */ |
||
348 | #endif /* MPPE_SUPPORT */ |
||
349 | |||
350 | #if PPP_AUTH_SUPPORT |
||
351 | /* auth data */ |
||
352 | #if PPP_SERVER && defined(HAVE_MULTILINK) |
||
353 | char peer_authname[MAXNAMELEN + 1]; /* The name by which the peer authenticated itself to us. */ |
||
354 | #endif /* PPP_SERVER && defined(HAVE_MULTILINK) */ |
||
355 | u16_t auth_pending; /* Records which authentication operations haven't completed yet. */ |
||
356 | u16_t auth_done; /* Records which authentication operations have been completed. */ |
||
357 | |||
358 | #if PAP_SUPPORT |
||
359 | upap_state upap; /* PAP data */ |
||
360 | #endif /* PAP_SUPPORT */ |
||
361 | |||
362 | #if CHAP_SUPPORT |
||
363 | chap_client_state chap_client; /* CHAP client data */ |
||
364 | #if PPP_SERVER |
||
365 | chap_server_state chap_server; /* CHAP server data */ |
||
366 | #endif /* PPP_SERVER */ |
||
367 | #endif /* CHAP_SUPPORT */ |
||
368 | |||
369 | #if EAP_SUPPORT |
||
370 | eap_state eap; /* EAP data */ |
||
371 | #endif /* EAP_SUPPORT */ |
||
372 | #endif /* PPP_AUTH_SUPPORT */ |
||
373 | |||
374 | fsm lcp_fsm; /* LCP fsm structure */ |
||
375 | lcp_options lcp_wantoptions; /* Options that we want to request */ |
||
376 | lcp_options lcp_gotoptions; /* Options that peer ack'd */ |
||
377 | lcp_options lcp_allowoptions; /* Options we allow peer to request */ |
||
378 | lcp_options lcp_hisoptions; /* Options that we ack'd */ |
||
379 | u16_t peer_mru; /* currently negotiated peer MRU */ |
||
380 | u8_t lcp_echos_pending; /* Number of outstanding echo msgs */ |
||
381 | u8_t lcp_echo_number; /* ID number of next echo frame */ |
||
382 | |||
383 | u8_t num_np_open; /* Number of network protocols which we have opened. */ |
||
384 | u8_t num_np_up; /* Number of network protocols which have come up. */ |
||
385 | |||
386 | #if VJ_SUPPORT |
||
387 | struct vjcompress vj_comp; /* Van Jacobson compression header. */ |
||
388 | #endif /* VJ_SUPPORT */ |
||
389 | |||
390 | #if CCP_SUPPORT |
||
391 | fsm ccp_fsm; /* CCP fsm structure */ |
||
392 | ccp_options ccp_wantoptions; /* what to request the peer to use */ |
||
393 | ccp_options ccp_gotoptions; /* what the peer agreed to do */ |
||
394 | ccp_options ccp_allowoptions; /* what we'll agree to do */ |
||
395 | ccp_options ccp_hisoptions; /* what we agreed to do */ |
||
396 | u8_t ccp_localstate; /* Local state (mainly for handling reset-reqs and reset-acks). */ |
||
397 | u8_t ccp_receive_method; /* Method chosen on receive path */ |
||
398 | u8_t ccp_transmit_method; /* Method chosen on transmit path */ |
||
399 | #if MPPE_SUPPORT |
||
400 | ppp_mppe_state mppe_comp; /* MPPE "compressor" structure */ |
||
401 | ppp_mppe_state mppe_decomp; /* MPPE "decompressor" structure */ |
||
402 | #endif /* MPPE_SUPPORT */ |
||
403 | #endif /* CCP_SUPPORT */ |
||
404 | |||
405 | #if PPP_IPV4_SUPPORT |
||
406 | fsm ipcp_fsm; /* IPCP fsm structure */ |
||
407 | ipcp_options ipcp_wantoptions; /* Options that we want to request */ |
||
408 | ipcp_options ipcp_gotoptions; /* Options that peer ack'd */ |
||
409 | ipcp_options ipcp_allowoptions; /* Options we allow peer to request */ |
||
410 | ipcp_options ipcp_hisoptions; /* Options that we ack'd */ |
||
411 | #endif /* PPP_IPV4_SUPPORT */ |
||
412 | |||
413 | #if PPP_IPV6_SUPPORT |
||
414 | fsm ipv6cp_fsm; /* IPV6CP fsm structure */ |
||
415 | ipv6cp_options ipv6cp_wantoptions; /* Options that we want to request */ |
||
416 | ipv6cp_options ipv6cp_gotoptions; /* Options that peer ack'd */ |
||
417 | ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */ |
||
418 | ipv6cp_options ipv6cp_hisoptions; /* Options that we ack'd */ |
||
419 | #endif /* PPP_IPV6_SUPPORT */ |
||
420 | }; |
||
421 | |||
422 | /************************ |
||
423 | *** PUBLIC FUNCTIONS *** |
||
424 | ************************/ |
||
425 | |||
426 | /* |
||
427 | * WARNING: For multi-threads environment, all ppp_set_* functions most |
||
428 | * only be called while the PPP is in the dead phase (i.e. disconnected). |
||
429 | */ |
||
430 | |||
431 | #if PPP_AUTH_SUPPORT |
||
432 | /* |
||
433 | * Set PPP authentication. |
||
434 | * |
||
435 | * Warning: Using PPPAUTHTYPE_ANY might have security consequences. |
||
436 | * RFC 1994 says: |
||
437 | * |
||
438 | * In practice, within or associated with each PPP server, there is a |
||
439 | * database which associates "user" names with authentication |
||
440 | * information ("secrets"). It is not anticipated that a particular |
||
441 | * named user would be authenticated by multiple methods. This would |
||
442 | * make the user vulnerable to attacks which negotiate the least secure |
||
443 | * method from among a set (such as PAP rather than CHAP). If the same |
||
444 | * secret was used, PAP would reveal the secret to be used later with |
||
445 | * CHAP. |
||
446 | * |
||
447 | * Instead, for each user name there should be an indication of exactly |
||
448 | * one method used to authenticate that user name. If a user needs to |
||
449 | * make use of different authentication methods under different |
||
450 | * circumstances, then distinct user names SHOULD be employed, each of |
||
451 | * which identifies exactly one authentication method. |
||
452 | * |
||
453 | * Default is none auth type, unset (NULL) user and passwd. |
||
454 | */ |
||
455 | #define PPPAUTHTYPE_NONE 0x00 |
||
456 | #define PPPAUTHTYPE_PAP 0x01 |
||
457 | #define PPPAUTHTYPE_CHAP 0x02 |
||
458 | #define PPPAUTHTYPE_MSCHAP 0x04 |
||
459 | #define PPPAUTHTYPE_MSCHAP_V2 0x08 |
||
460 | #define PPPAUTHTYPE_EAP 0x10 |
||
461 | #define PPPAUTHTYPE_ANY 0xff |
||
462 | void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd); |
||
463 | |||
464 | /* |
||
465 | * If set, peer is required to authenticate. This is mostly necessary for PPP server support. |
||
466 | * |
||
467 | * Default is false. |
||
468 | */ |
||
469 | #define ppp_set_auth_required(ppp, boolval) (ppp->settings.auth_required = boolval) |
||
470 | #endif /* PPP_AUTH_SUPPORT */ |
||
471 | |||
472 | #if PPP_IPV4_SUPPORT |
||
473 | /* |
||
474 | * Set PPP interface "our" and "his" IPv4 addresses. This is mostly necessary for PPP server |
||
475 | * support but it can also be used on a PPP link where each side choose its own IP address. |
||
476 | * |
||
477 | * Default is unset (0.0.0.0). |
||
478 | */ |
||
479 | #define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \ |
||
480 | ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0) |
||
481 | #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) |
||
482 | #if LWIP_DNS |
||
483 | /* |
||
484 | * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary |
||
485 | * for PPP server support. |
||
486 | * |
||
487 | * Default is unset (0.0.0.0). |
||
488 | */ |
||
489 | #define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr)) |
||
490 | |||
491 | /* |
||
492 | * If set, we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are |
||
493 | * registered using the dns_setserver() function. |
||
494 | * |
||
495 | * Default is false. |
||
496 | */ |
||
497 | #define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval) |
||
498 | #endif /* LWIP_DNS */ |
||
499 | #endif /* PPP_IPV4_SUPPORT */ |
||
500 | |||
501 | #if MPPE_SUPPORT |
||
502 | /* Disable MPPE (Microsoft Point to Point Encryption). This parameter is exclusive. */ |
||
503 | #define PPP_MPPE_DISABLE 0x00 |
||
504 | /* Require the use of MPPE (Microsoft Point to Point Encryption). */ |
||
505 | #define PPP_MPPE_ENABLE 0x01 |
||
506 | /* Allow MPPE to use stateful mode. Stateless mode is still attempted first. */ |
||
507 | #define PPP_MPPE_ALLOW_STATEFUL 0x02 |
||
508 | /* Refuse the use of MPPE with 40-bit encryption. Conflict with PPP_MPPE_REFUSE_128. */ |
||
509 | #define PPP_MPPE_REFUSE_40 0x04 |
||
510 | /* Refuse the use of MPPE with 128-bit encryption. Conflict with PPP_MPPE_REFUSE_40. */ |
||
511 | #define PPP_MPPE_REFUSE_128 0x08 |
||
512 | /* |
||
513 | * Set MPPE configuration |
||
514 | * |
||
515 | * Default is disabled. |
||
516 | */ |
||
517 | void ppp_set_mppe(ppp_pcb *pcb, u8_t flags); |
||
518 | #endif /* MPPE_SUPPORT */ |
||
519 | |||
520 | /* |
||
521 | * Wait for up to intval milliseconds for a valid PPP packet from the peer. |
||
522 | * At the end of this time, or when a valid PPP packet is received from the |
||
523 | * peer, we commence negotiation by sending our first LCP packet. |
||
524 | * |
||
525 | * Default is 0. |
||
526 | */ |
||
527 | #define ppp_set_listen_time(ppp, intval) (ppp->settings.listen_time = intval) |
||
528 | |||
529 | /* |
||
530 | * If set, we will attempt to initiate a connection but if no reply is received from |
||
531 | * the peer, we will then just wait passively for a valid LCP packet from the peer. |
||
532 | * |
||
533 | * Default is false. |
||
534 | */ |
||
535 | #define ppp_set_passive(ppp, boolval) (ppp->lcp_wantoptions.passive = boolval) |
||
536 | |||
537 | /* |
||
538 | * If set, we will not transmit LCP packets to initiate a connection until a valid |
||
539 | * LCP packet is received from the peer. This is what we usually call the server mode. |
||
540 | * |
||
541 | * Default is false. |
||
542 | */ |
||
543 | #define ppp_set_silent(ppp, boolval) (ppp->lcp_wantoptions.silent = boolval) |
||
544 | |||
545 | /* |
||
546 | * If set, enable protocol field compression negotiation in both the receive and |
||
547 | * the transmit direction. |
||
548 | * |
||
549 | * Default is true. |
||
550 | */ |
||
551 | #define ppp_set_neg_pcomp(ppp, boolval) (ppp->lcp_wantoptions.neg_pcompression = \ |
||
552 | ppp->lcp_allowoptions.neg_pcompression = boolval) |
||
553 | |||
554 | /* |
||
555 | * If set, enable Address/Control compression in both the receive and the transmit |
||
556 | * direction. |
||
557 | * |
||
558 | * Default is true. |
||
559 | */ |
||
560 | #define ppp_set_neg_accomp(ppp, boolval) (ppp->lcp_wantoptions.neg_accompression = \ |
||
561 | ppp->lcp_allowoptions.neg_accompression = boolval) |
||
562 | |||
563 | /* |
||
564 | * If set, enable asyncmap negotiation. Otherwise forcing all control characters to |
||
565 | * be escaped for both the transmit and the receive direction. |
||
566 | * |
||
567 | * Default is true. |
||
568 | */ |
||
569 | #define ppp_set_neg_asyncmap(ppp, boolval) (ppp->lcp_wantoptions.neg_asyncmap = \ |
||
570 | ppp->lcp_allowoptions.neg_asyncmap = boolval) |
||
571 | |||
572 | /* |
||
573 | * This option sets the Async-Control-Character-Map (ACCM) for this end of the link. |
||
574 | * The ACCM is a set of 32 bits, one for each of the ASCII control characters with |
||
575 | * values from 0 to 31, where a 1 bit indicates that the corresponding control |
||
576 | * character should not be used in PPP packets sent to this system. The map is |
||
577 | * an unsigned 32 bits integer where the least significant bit (00000001) represents |
||
578 | * character 0 and the most significant bit (80000000) represents character 31. |
||
579 | * We will then ask the peer to send these characters as a 2-byte escape sequence. |
||
580 | * |
||
581 | * Default is 0. |
||
582 | */ |
||
583 | #define ppp_set_asyncmap(ppp, intval) (ppp->lcp_wantoptions.asyncmap = intval) |
||
584 | |||
585 | /* |
||
586 | * Set a PPP interface as the default network interface |
||
587 | * (used to output all packets for which no specific route is found). |
||
588 | */ |
||
589 | #define ppp_set_default(ppp) netif_set_default(ppp->netif) |
||
590 | |||
591 | #if PPP_NOTIFY_PHASE |
||
592 | /* |
||
593 | * Set a PPP notify phase callback. |
||
594 | * |
||
595 | * This can be used for example to set a LED pattern depending on the |
||
596 | * current phase of the PPP session. |
||
597 | */ |
||
598 | typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx); |
||
599 | void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb); |
||
600 | #endif /* PPP_NOTIFY_PHASE */ |
||
601 | |||
602 | /* |
||
603 | * Initiate a PPP connection. |
||
604 | * |
||
605 | * This can only be called if PPP is in the dead phase. |
||
606 | * |
||
607 | * Holdoff is the time to wait (in seconds) before initiating |
||
608 | * the connection. |
||
609 | * |
||
610 | * If this port connects to a modem, the modem connection must be |
||
611 | * established before calling this. |
||
612 | */ |
||
613 | err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff); |
||
614 | |||
615 | #if PPP_SERVER |
||
616 | /* |
||
617 | * Listen for an incoming PPP connection. |
||
618 | * |
||
619 | * This can only be called if PPP is in the dead phase. |
||
620 | * |
||
621 | * If this port connects to a modem, the modem connection must be |
||
622 | * established before calling this. |
||
623 | */ |
||
624 | err_t ppp_listen(ppp_pcb *pcb); |
||
625 | #endif /* PPP_SERVER */ |
||
626 | |||
627 | /* |
||
628 | * Initiate the end of a PPP connection. |
||
629 | * Any outstanding packets in the queues are dropped. |
||
630 | * |
||
631 | * Setting nocarrier to 1 close the PPP connection without initiating the |
||
632 | * shutdown procedure. Always using nocarrier = 0 is still recommended, |
||
633 | * this is going to take a little longer time if your link is down, but |
||
634 | * is a safer choice for the PPP state machine. |
||
635 | * |
||
636 | * Return 0 on success, an error code on failure. |
||
637 | */ |
||
638 | err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier); |
||
639 | |||
640 | /* |
||
641 | * Release the control block. |
||
642 | * |
||
643 | * This can only be called if PPP is in the dead phase. |
||
644 | * |
||
645 | * You must use ppp_close() before if you wish to terminate |
||
646 | * an established PPP session. |
||
647 | * |
||
648 | * Return 0 on success, an error code on failure. |
||
649 | */ |
||
650 | err_t ppp_free(ppp_pcb *pcb); |
||
651 | |||
652 | /* |
||
653 | * PPP IOCTL commands. |
||
654 | * |
||
655 | * Get the up status - 0 for down, non-zero for up. The argument must |
||
656 | * point to an int. |
||
657 | */ |
||
658 | #define PPPCTLG_UPSTATUS 0 |
||
659 | |||
660 | /* |
||
661 | * Get the PPP error code. The argument must point to an int. |
||
662 | * Returns a PPPERR_* value. |
||
663 | */ |
||
664 | #define PPPCTLG_ERRCODE 1 |
||
665 | |||
666 | /* |
||
667 | * Get the fd associated with a PPP over serial |
||
668 | */ |
||
669 | #define PPPCTLG_FD 2 |
||
670 | |||
671 | /* |
||
672 | * Get and set parameters for the given connection. |
||
673 | * Return 0 on success, an error code on failure. |
||
674 | */ |
||
675 | err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); |
||
676 | |||
677 | /* Get the PPP netif interface */ |
||
678 | #define ppp_netif(ppp) (ppp->netif) |
||
679 | |||
680 | /* Set an lwIP-style status-callback for the selected PPP device */ |
||
681 | #define ppp_set_netif_statuscallback(ppp, status_cb) \ |
||
682 | netif_set_status_callback(ppp->netif, status_cb); |
||
683 | |||
684 | /* Set an lwIP-style link-callback for the selected PPP device */ |
||
685 | #define ppp_set_netif_linkcallback(ppp, link_cb) \ |
||
686 | netif_set_link_callback(ppp->netif, link_cb); |
||
687 | |||
688 | #endif /* PPP_H */ |
||
689 | |||
690 | #endif /* PPP_SUPPORT */ |