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