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 ipcp_is_open :1; /* haven't called np_finished() */ 328 unsigned int ipcp_is_up :1; /* have called ipcp_up() */ 329 unsigned int if4_up :1; /* True when the IPv4 interface is up. */ 330 #if 0 /* UNUSED - PROXY ARP */ 331 unsigned int proxy_arp_set :1; /* Have created proxy arp entry */ 332 #endif /* UNUSED - PROXY ARP */ 333 #endif /* PPP_IPV4_SUPPORT */ 334 #if PPP_IPV6_SUPPORT 335 unsigned int ipv6cp_is_up :1; /* have called ip6cp_up() */ 336 unsigned int if6_up :1; /* True when the IPv6 interface is up. */ 337 #endif /* PPP_IPV6_SUPPORT */ 338 unsigned int lcp_echo_timer_running :1; /* set if a timer is running */ 339 #if VJ_SUPPORT 340 unsigned int vj_enabled :1; /* Flag indicating VJ compression enabled. */ 341 #endif /* VJ_SUPPORT */ 342 #if CCP_SUPPORT 343 unsigned int ccp_all_rejected :1; /* we rejected all peer's options */ 344 #endif /* CCP_SUPPORT */ 345 #if MPPE_SUPPORT 346 unsigned int mppe_keys_set :1; /* Have the MPPE keys been set? */ 347 #endif /* MPPE_SUPPORT */ 348 349 #if PPP_AUTH_SUPPORT 350 /* auth data */ 351 #if PPP_SERVER && defined(HAVE_MULTILINK) 352 char peer_authname[MAXNAMELEN + 1]; /* The name by which the peer authenticated itself to us. */ 353 #endif /* PPP_SERVER && defined(HAVE_MULTILINK) */ 354 u16_t auth_pending; /* Records which authentication operations haven't completed yet. */ 355 u16_t auth_done; /* Records which authentication operations have been completed. */ 356 357 #if PAP_SUPPORT 358 upap_state upap; /* PAP data */ 359 #endif /* PAP_SUPPORT */ 360 361 #if CHAP_SUPPORT 362 chap_client_state chap_client; /* CHAP client data */ 363 #if PPP_SERVER 364 chap_server_state chap_server; /* CHAP server data */ 365 #endif /* PPP_SERVER */ 366 #endif /* CHAP_SUPPORT */ 367 368 #if EAP_SUPPORT 369 eap_state eap; /* EAP data */ 370 #endif /* EAP_SUPPORT */ 371 #endif /* PPP_AUTH_SUPPORT */ 372 373 fsm lcp_fsm; /* LCP fsm structure */ 374 lcp_options lcp_wantoptions; /* Options that we want to request */ 375 lcp_options lcp_gotoptions; /* Options that peer ack'd */ 376 lcp_options lcp_allowoptions; /* Options we allow peer to request */ 377 lcp_options lcp_hisoptions; /* Options that we ack'd */ 378 u16_t peer_mru; /* currently negotiated peer MRU */ 379 u8_t lcp_echos_pending; /* Number of outstanding echo msgs */ 380 u8_t lcp_echo_number; /* ID number of next echo frame */ 381 382 u8_t num_np_open; /* Number of network protocols which we have opened. */ 383 u8_t num_np_up; /* Number of network protocols which have come up. */ 384 385 #if VJ_SUPPORT 386 struct vjcompress vj_comp; /* Van Jacobson compression header. */ 387 #endif /* VJ_SUPPORT */ 388 389 #if CCP_SUPPORT 390 fsm ccp_fsm; /* CCP fsm structure */ 391 ccp_options ccp_wantoptions; /* what to request the peer to use */ 392 ccp_options ccp_gotoptions; /* what the peer agreed to do */ 393 ccp_options ccp_allowoptions; /* what we'll agree to do */ 394 ccp_options ccp_hisoptions; /* what we agreed to do */ 395 u8_t ccp_localstate; /* Local state (mainly for handling reset-reqs and reset-acks). */ 396 u8_t ccp_receive_method; /* Method chosen on receive path */ 397 u8_t ccp_transmit_method; /* Method chosen on transmit path */ 398 #if MPPE_SUPPORT 399 ppp_mppe_state mppe_comp; /* MPPE "compressor" structure */ 400 ppp_mppe_state mppe_decomp; /* MPPE "decompressor" structure */ 401 #endif /* MPPE_SUPPORT */ 402 #endif /* CCP_SUPPORT */ 403 404 #if PPP_IPV4_SUPPORT 405 fsm ipcp_fsm; /* IPCP fsm structure */ 406 ipcp_options ipcp_wantoptions; /* Options that we want to request */ 407 ipcp_options ipcp_gotoptions; /* Options that peer ack'd */ 408 ipcp_options ipcp_allowoptions; /* Options we allow peer to request */ 409 ipcp_options ipcp_hisoptions; /* Options that we ack'd */ 410 #endif /* PPP_IPV4_SUPPORT */ 411 412 #if PPP_IPV6_SUPPORT 413 fsm ipv6cp_fsm; /* IPV6CP fsm structure */ 414 ipv6cp_options ipv6cp_wantoptions; /* Options that we want to request */ 415 ipv6cp_options ipv6cp_gotoptions; /* Options that peer ack'd */ 416 ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */ 417 ipv6cp_options ipv6cp_hisoptions; /* Options that we ack'd */ 418 #endif /* PPP_IPV6_SUPPORT */ 419 }; 420 421 /************************ 422 *** PUBLIC FUNCTIONS *** 423 ************************/ 424 425 /* 426 * WARNING: For multi-threads environment, all ppp_set_* functions most 427 * only be called while the PPP is in the dead phase (i.e. disconnected). 428 */ 429 430 #if PPP_AUTH_SUPPORT 431 /* 432 * Set PPP authentication. 433 * 434 * Warning: Using PPPAUTHTYPE_ANY might have security consequences. 435 * RFC 1994 says: 436 * 437 * In practice, within or associated with each PPP server, there is a 438 * database which associates "user" names with authentication 439 * information ("secrets"). It is not anticipated that a particular 440 * named user would be authenticated by multiple methods. This would 441 * make the user vulnerable to attacks which negotiate the least secure 442 * method from among a set (such as PAP rather than CHAP). If the same 443 * secret was used, PAP would reveal the secret to be used later with 444 * CHAP. 445 * 446 * Instead, for each user name there should be an indication of exactly 447 * one method used to authenticate that user name. If a user needs to 448 * make use of different authentication methods under different 449 * circumstances, then distinct user names SHOULD be employed, each of 450 * which identifies exactly one authentication method. 451 * 452 * Default is none auth type, unset (NULL) user and passwd. 453 */ 454 #define PPPAUTHTYPE_NONE 0x00 455 #define PPPAUTHTYPE_PAP 0x01 456 #define PPPAUTHTYPE_CHAP 0x02 457 #define PPPAUTHTYPE_MSCHAP 0x04 458 #define PPPAUTHTYPE_MSCHAP_V2 0x08 459 #define PPPAUTHTYPE_EAP 0x10 460 #define PPPAUTHTYPE_ANY 0xff 461 void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd); 462 463 /* 464 * If set, peer is required to authenticate. This is mostly necessary for PPP server support. 465 * 466 * Default is false. 467 */ 468 #define ppp_set_auth_required(ppp, boolval) (ppp->settings.auth_required = boolval) 469 #endif /* PPP_AUTH_SUPPORT */ 470 471 #if PPP_IPV4_SUPPORT 472 /* 473 * Set PPP interface "our" and "his" IPv4 addresses. This is mostly necessary for PPP server 474 * support but it can also be used on a PPP link where each side choose its own IP address. 475 * 476 * Default is unset (0.0.0.0). 477 */ 478 #define ppp_set_ipcp_ouraddr(ppp, addr) (ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr)) 479 #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) 480 #if LWIP_DNS 481 /* 482 * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary 483 * for PPP server support. 484 * 485 * Default is unset (0.0.0.0). 486 */ 487 #define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr)) 488 489 /* 490 * If set, we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are 491 * registered using the dns_setserver() function. 492 * 493 * Default is false. 494 */ 495 #define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval) 496 #endif /* LWIP_DNS */ 497 #endif /* PPP_IPV4_SUPPORT */ 498 499 #if MPPE_SUPPORT 500 /* Disable MPPE (Microsoft Point to Point Encryption). This parameter is exclusive. */ 501 #define PPP_MPPE_DISABLE 0x00 502 /* Require the use of MPPE (Microsoft Point to Point Encryption). */ 503 #define PPP_MPPE_ENABLE 0x01 504 /* Allow MPPE to use stateful mode. Stateless mode is still attempted first. */ 505 #define PPP_MPPE_ALLOW_STATEFUL 0x02 506 /* Refuse the use of MPPE with 40-bit encryption. Conflict with PPP_MPPE_REFUSE_128. */ 507 #define PPP_MPPE_REFUSE_40 0x04 508 /* Refuse the use of MPPE with 128-bit encryption. Conflict with PPP_MPPE_REFUSE_40. */ 509 #define PPP_MPPE_REFUSE_128 0x08 510 /* 511 * Set MPPE configuration 512 * 513 * Default is disabled. 514 */ 515 void ppp_set_mppe(ppp_pcb *pcb, u8_t flags); 516 #endif /* MPPE_SUPPORT */ 517 518 /* 519 * Wait for up to intval milliseconds for a valid PPP packet from the peer. 520 * At the end of this time, or when a valid PPP packet is received from the 521 * peer, we commence negotiation by sending our first LCP packet. 522 * 523 * Default is 0. 524 */ 525 #define ppp_set_listen_time(ppp, intval) (ppp->settings.listen_time = intval) 526 527 /* 528 * If set, we will attempt to initiate a connection but if no reply is received from 529 * the peer, we will then just wait passively for a valid LCP packet from the peer. 530 * 531 * Default is false. 532 */ 533 #define ppp_set_passive(ppp, boolval) (ppp->lcp_wantoptions.passive = boolval) 534 535 /* 536 * If set, we will not transmit LCP packets to initiate a connection until a valid 537 * LCP packet is received from the peer. This is what we usually call the server mode. 538 * 539 * Default is false. 540 */ 541 #define ppp_set_silent(ppp, boolval) (ppp->lcp_wantoptions.silent = boolval) 542 543 /* 544 * If set, enable protocol field compression negotiation in both the receive and 545 * the transmit direction. 546 * 547 * Default is true. 548 */ 549 #define ppp_set_neg_pcomp(ppp, boolval) (ppp->lcp_wantoptions.neg_pcompression = \ 550 ppp->lcp_allowoptions.neg_pcompression = boolval) 551 552 /* 553 * If set, enable Address/Control compression in both the receive and the transmit 554 * direction. 555 * 556 * Default is true. 557 */ 558 #define ppp_set_neg_accomp(ppp, boolval) (ppp->lcp_wantoptions.neg_accompression = \ 559 ppp->lcp_allowoptions.neg_accompression = boolval) 560 561 /* 562 * If set, enable asyncmap negotiation. Otherwise forcing all control characters to 563 * be escaped for both the transmit and the receive direction. 564 * 565 * Default is true. 566 */ 567 #define ppp_set_neg_asyncmap(ppp, boolval) (ppp->lcp_wantoptions.neg_asyncmap = \ 568 ppp->lcp_allowoptions.neg_asyncmap = boolval) 569 570 /* 571 * This option sets the Async-Control-Character-Map (ACCM) for this end of the link. 572 * The ACCM is a set of 32 bits, one for each of the ASCII control characters with 573 * values from 0 to 31, where a 1 bit indicates that the corresponding control 574 * character should not be used in PPP packets sent to this system. The map is 575 * an unsigned 32 bits integer where the least significant bit (00000001) represents 576 * character 0 and the most significant bit (80000000) represents character 31. 577 * We will then ask the peer to send these characters as a 2-byte escape sequence. 578 * 579 * Default is 0. 580 */ 581 #define ppp_set_asyncmap(ppp, intval) (ppp->lcp_wantoptions.asyncmap = intval) 582 583 /* 584 * Set a PPP interface as the default network interface 585 * (used to output all packets for which no specific route is found). 586 */ 587 #define ppp_set_default(ppp) netif_set_default(ppp->netif) 588 589 #if PPP_NOTIFY_PHASE 590 /* 591 * Set a PPP notify phase callback. 592 * 593 * This can be used for example to set a LED pattern depending on the 594 * current phase of the PPP session. 595 */ 596 typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx); 597 void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb); 598 #endif /* PPP_NOTIFY_PHASE */ 599 600 /* 601 * Initiate a PPP connection. 602 * 603 * This can only be called if PPP is in the dead phase. 604 * 605 * Holdoff is the time to wait (in seconds) before initiating 606 * the connection. 607 * 608 * If this port connects to a modem, the modem connection must be 609 * established before calling this. 610 */ 611 err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff); 612 613 #if PPP_SERVER 614 /* 615 * Listen for an incoming PPP connection. 616 * 617 * This can only be called if PPP is in the dead phase. 618 * 619 * If this port connects to a modem, the modem connection must be 620 * established before calling this. 621 */ 622 err_t ppp_listen(ppp_pcb *pcb); 623 #endif /* PPP_SERVER */ 624 625 /* 626 * Initiate the end of a PPP connection. 627 * Any outstanding packets in the queues are dropped. 628 * 629 * Setting nocarrier to 1 close the PPP connection without initiating the 630 * shutdown procedure. Always using nocarrier = 0 is still recommended, 631 * this is going to take a little longer time if your link is down, but 632 * is a safer choice for the PPP state machine. 633 * 634 * Return 0 on success, an error code on failure. 635 */ 636 err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier); 637 638 /* 639 * Release the control block. 640 * 641 * This can only be called if PPP is in the dead phase. 642 * 643 * You must use ppp_close() before if you wish to terminate 644 * an established PPP session. 645 * 646 * Return 0 on success, an error code on failure. 647 */ 648 err_t ppp_free(ppp_pcb *pcb); 649 650 /* 651 * PPP IOCTL commands. 652 * 653 * Get the up status - 0 for down, non-zero for up. The argument must 654 * point to an int. 655 */ 656 #define PPPCTLG_UPSTATUS 0 657 658 /* 659 * Get the PPP error code. The argument must point to an int. 660 * Returns a PPPERR_* value. 661 */ 662 #define PPPCTLG_ERRCODE 1 663 664 /* 665 * Get the fd associated with a PPP over serial 666 */ 667 #define PPPCTLG_FD 2 668 669 /* 670 * Get and set parameters for the given connection. 671 * Return 0 on success, an error code on failure. 672 */ 673 err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); 674 675 /* Get the PPP netif interface */ 676 #define ppp_netif(ppp) (ppp->netif) 677 678 /* Set an lwIP-style status-callback for the selected PPP device */ 679 #define ppp_set_netif_statuscallback(ppp, status_cb) \ 680 netif_set_status_callback(ppp->netif, status_cb); 681 682 /* Set an lwIP-style link-callback for the selected PPP device */ 683 #define ppp_set_netif_linkcallback(ppp, link_cb) \ 684 netif_set_link_callback(ppp->netif, link_cb); 685 686 #endif /* PPP_H */ 687 688 #endif /* PPP_SUPPORT */ 689