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