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 #ifndef LWIP_HDR_PPP_IMPL_H 34 #define LWIP_HDR_PPP_IMPL_H 35 36 #include "netif/ppp/ppp_opts.h" 37 38 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 39 40 #ifdef PPP_INCLUDE_SETTINGS_HEADER 41 #include "ppp_settings.h" 42 #endif 43 44 #include <stdio.h> /* formats */ 45 #include <stdarg.h> 46 #include <string.h> 47 #include <stdlib.h> /* strtol() */ 48 49 #include "lwip/netif.h" 50 #include "lwip/def.h" 51 #include "lwip/timeouts.h" 52 53 #include "ppp.h" 54 #include "pppdebug.h" 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 /* 61 * Memory used for control packets. 62 * 63 * PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we 64 * cannot figure out how much we are going to use before filling the buffer. 65 */ 66 #if PPP_USE_PBUF_RAM 67 #define PPP_CTRL_PBUF_TYPE PBUF_RAM 68 #define PPP_CTRL_PBUF_MAX_SIZE 512 69 #else /* PPP_USE_PBUF_RAM */ 70 #define PPP_CTRL_PBUF_TYPE PBUF_POOL 71 #define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE 72 #endif /* PPP_USE_PBUF_RAM */ 73 74 /* 75 * The basic PPP frame. 76 */ 77 #define PPP_ADDRESS(p) (((u_char *)(p))[0]) 78 #define PPP_CONTROL(p) (((u_char *)(p))[1]) 79 #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) 80 81 /* 82 * Significant octet values. 83 */ 84 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ 85 #define PPP_UI 0x03 /* Unnumbered Information */ 86 #define PPP_FLAG 0x7e /* Flag Sequence */ 87 #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ 88 #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ 89 90 /* 91 * Protocol field values. 92 */ 93 #define PPP_IP 0x21 /* Internet Protocol */ 94 #if 0 /* UNUSED */ 95 #define PPP_AT 0x29 /* AppleTalk Protocol */ 96 #define PPP_IPX 0x2b /* IPX protocol */ 97 #endif /* UNUSED */ 98 #if VJ_SUPPORT 99 #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ 100 #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ 101 #endif /* VJ_SUPPORT */ 102 #if PPP_IPV6_SUPPORT 103 #define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ 104 #endif /* PPP_IPV6_SUPPORT */ 105 #if CCP_SUPPORT 106 #define PPP_COMP 0xfd /* compressed packet */ 107 #endif /* CCP_SUPPORT */ 108 #define PPP_IPCP 0x8021 /* IP Control Protocol */ 109 #if 0 /* UNUSED */ 110 #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ 111 #define PPP_IPXCP 0x802b /* IPX Control Protocol */ 112 #endif /* UNUSED */ 113 #if PPP_IPV6_SUPPORT 114 #define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ 115 #endif /* PPP_IPV6_SUPPORT */ 116 #if CCP_SUPPORT 117 #define PPP_CCP 0x80fd /* Compression Control Protocol */ 118 #endif /* CCP_SUPPORT */ 119 #if ECP_SUPPORT 120 #define PPP_ECP 0x8053 /* Encryption Control Protocol */ 121 #endif /* ECP_SUPPORT */ 122 #define PPP_LCP 0xc021 /* Link Control Protocol */ 123 #if PAP_SUPPORT 124 #define PPP_PAP 0xc023 /* Password Authentication Protocol */ 125 #endif /* PAP_SUPPORT */ 126 #if LQR_SUPPORT 127 #define PPP_LQR 0xc025 /* Link Quality Report protocol */ 128 #endif /* LQR_SUPPORT */ 129 #if CHAP_SUPPORT 130 #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ 131 #endif /* CHAP_SUPPORT */ 132 #if CBCP_SUPPORT 133 #define PPP_CBCP 0xc029 /* Callback Control Protocol */ 134 #endif /* CBCP_SUPPORT */ 135 #if EAP_SUPPORT 136 #define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ 137 #endif /* EAP_SUPPORT */ 138 139 /* 140 * The following struct gives the addresses of procedures to call 141 * for a particular lower link level protocol. 142 */ 143 struct link_callbacks { 144 /* Start a connection (e.g. Initiate discovery phase) */ 145 void (*connect) (ppp_pcb *pcb, void *ctx); 146 #if PPP_SERVER 147 /* Listen for an incoming connection (Passive mode) */ 148 void (*listen) (ppp_pcb *pcb, void *ctx); 149 #endif /* PPP_SERVER */ 150 /* End a connection (i.e. initiate disconnect phase) */ 151 void (*disconnect) (ppp_pcb *pcb, void *ctx); 152 /* Free lower protocol control block */ 153 err_t (*free) (ppp_pcb *pcb, void *ctx); 154 /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */ 155 err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p); 156 /* Send a packet from lwIP core (IPv4 or IPv6) */ 157 err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol); 158 /* configure the transmit-side characteristics of the PPP interface */ 159 void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp); 160 /* confire the receive-side characteristics of the PPP interface */ 161 void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp); 162 }; 163 164 /* 165 * What to do with network protocol (NP) packets. 166 */ 167 enum NPmode { 168 NPMODE_PASS, /* pass the packet through */ 169 NPMODE_DROP, /* silently drop the packet */ 170 NPMODE_ERROR, /* return an error */ 171 NPMODE_QUEUE /* save it up for later. */ 172 }; 173 174 /* 175 * Statistics. 176 */ 177 #if PPP_STATS_SUPPORT 178 struct pppstat { 179 unsigned int ppp_ibytes; /* bytes received */ 180 unsigned int ppp_ipackets; /* packets received */ 181 unsigned int ppp_ierrors; /* receive errors */ 182 unsigned int ppp_obytes; /* bytes sent */ 183 unsigned int ppp_opackets; /* packets sent */ 184 unsigned int ppp_oerrors; /* transmit errors */ 185 }; 186 187 #if VJ_SUPPORT 188 struct vjstat { 189 unsigned int vjs_packets; /* outbound packets */ 190 unsigned int vjs_compressed; /* outbound compressed packets */ 191 unsigned int vjs_searches; /* searches for connection state */ 192 unsigned int vjs_misses; /* times couldn't find conn. state */ 193 unsigned int vjs_uncompressedin; /* inbound uncompressed packets */ 194 unsigned int vjs_compressedin; /* inbound compressed packets */ 195 unsigned int vjs_errorin; /* inbound unknown type packets */ 196 unsigned int vjs_tossed; /* inbound packets tossed because of error */ 197 }; 198 #endif /* VJ_SUPPORT */ 199 200 struct ppp_stats { 201 struct pppstat p; /* basic PPP statistics */ 202 #if VJ_SUPPORT 203 struct vjstat vj; /* VJ header compression statistics */ 204 #endif /* VJ_SUPPORT */ 205 }; 206 207 #if CCP_SUPPORT 208 struct compstat { 209 unsigned int unc_bytes; /* total uncompressed bytes */ 210 unsigned int unc_packets; /* total uncompressed packets */ 211 unsigned int comp_bytes; /* compressed bytes */ 212 unsigned int comp_packets; /* compressed packets */ 213 unsigned int inc_bytes; /* incompressible bytes */ 214 unsigned int inc_packets; /* incompressible packets */ 215 unsigned int ratio; /* recent compression ratio << 8 */ 216 }; 217 218 struct ppp_comp_stats { 219 struct compstat c; /* packet compression statistics */ 220 struct compstat d; /* packet decompression statistics */ 221 }; 222 #endif /* CCP_SUPPORT */ 223 224 #endif /* PPP_STATS_SUPPORT */ 225 226 #if PPP_IDLETIMELIMIT 227 /* 228 * The following structure records the time in seconds since 229 * the last NP packet was sent or received. 230 */ 231 struct ppp_idle { 232 time_t xmit_idle; /* time since last NP packet sent */ 233 time_t recv_idle; /* time since last NP packet received */ 234 }; 235 #endif /* PPP_IDLETIMELIMIT */ 236 237 /* values for epdisc.class */ 238 #define EPD_NULL 0 /* null discriminator, no data */ 239 #define EPD_LOCAL 1 240 #define EPD_IP 2 241 #define EPD_MAC 3 242 #define EPD_MAGIC 4 243 #define EPD_PHONENUM 5 244 245 /* 246 * Global variables. 247 */ 248 #ifdef HAVE_MULTILINK 249 extern u8_t multilink; /* enable multilink operation */ 250 extern u8_t doing_multilink; 251 extern u8_t multilink_master; 252 extern u8_t bundle_eof; 253 extern u8_t bundle_terminating; 254 #endif 255 256 #ifdef MAXOCTETS 257 extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ 258 extern int maxoctets_dir; /* Direction : 259 0 - in+out (default) 260 1 - in 261 2 - out 262 3 - max(in,out) */ 263 extern int maxoctets_timeout; /* Timeout for check of octets limit */ 264 #define PPP_OCTETS_DIRECTION_SUM 0 265 #define PPP_OCTETS_DIRECTION_IN 1 266 #define PPP_OCTETS_DIRECTION_OUT 2 267 #define PPP_OCTETS_DIRECTION_MAXOVERAL 3 268 /* same as previos, but little different on RADIUS side */ 269 #define PPP_OCTETS_DIRECTION_MAXSESSION 4 270 #endif 271 272 /* Data input may be used by CCP and ECP, remove this entry 273 * from struct protent to save some flash 274 */ 275 #define PPP_DATAINPUT 0 276 277 /* 278 * The following struct gives the addresses of procedures to call 279 * for a particular protocol. 280 */ 281 struct protent { 282 u_short protocol; /* PPP protocol number */ 283 /* Initialization procedure */ 284 void (*init) (ppp_pcb *pcb); 285 /* Process a received packet */ 286 void (*input) (ppp_pcb *pcb, u_char *pkt, int len); 287 /* Process a received protocol-reject */ 288 void (*protrej) (ppp_pcb *pcb); 289 /* Lower layer has come up */ 290 void (*lowerup) (ppp_pcb *pcb); 291 /* Lower layer has gone down */ 292 void (*lowerdown) (ppp_pcb *pcb); 293 /* Open the protocol */ 294 void (*open) (ppp_pcb *pcb); 295 /* Close the protocol */ 296 void (*close) (ppp_pcb *pcb, const char *reason); 297 #if PRINTPKT_SUPPORT 298 /* Print a packet in readable form */ 299 int (*printpkt) (const u_char *pkt, int len, 300 void (*printer) (void *, const char *, ...), 301 void *arg); 302 #endif /* PRINTPKT_SUPPORT */ 303 #if PPP_DATAINPUT 304 /* Process a received data packet */ 305 void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len); 306 #endif /* PPP_DATAINPUT */ 307 #if PRINTPKT_SUPPORT 308 const char *name; /* Text name of protocol */ 309 const char *data_name; /* Text name of corresponding data protocol */ 310 #endif /* PRINTPKT_SUPPORT */ 311 #if PPP_OPTIONS 312 option_t *options; /* List of command-line options */ 313 /* Check requested options, assign defaults */ 314 void (*check_options) (void); 315 #endif /* PPP_OPTIONS */ 316 #if DEMAND_SUPPORT 317 /* Configure interface for demand-dial */ 318 int (*demand_conf) (int unit); 319 /* Say whether to bring up link for this pkt */ 320 int (*active_pkt) (u_char *pkt, int len); 321 #endif /* DEMAND_SUPPORT */ 322 }; 323 324 /* Table of pointers to supported protocols */ 325 extern const struct protent* const protocols[]; 326 327 328 /* Values for auth_pending, auth_done */ 329 #if PAP_SUPPORT 330 #define PAP_WITHPEER 0x1 331 #define PAP_PEER 0x2 332 #endif /* PAP_SUPPORT */ 333 #if CHAP_SUPPORT 334 #define CHAP_WITHPEER 0x4 335 #define CHAP_PEER 0x8 336 #endif /* CHAP_SUPPORT */ 337 #if EAP_SUPPORT 338 #define EAP_WITHPEER 0x10 339 #define EAP_PEER 0x20 340 #endif /* EAP_SUPPORT */ 341 342 /* Values for auth_done only */ 343 #if CHAP_SUPPORT 344 #define CHAP_MD5_WITHPEER 0x40 345 #define CHAP_MD5_PEER 0x80 346 #if MSCHAP_SUPPORT 347 #define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ 348 #define CHAP_MS_WITHPEER 0x100 349 #define CHAP_MS_PEER 0x200 350 #define CHAP_MS2_WITHPEER 0x400 351 #define CHAP_MS2_PEER 0x800 352 #endif /* MSCHAP_SUPPORT */ 353 #endif /* CHAP_SUPPORT */ 354 355 /* Supported CHAP protocols */ 356 #if CHAP_SUPPORT 357 358 #if MSCHAP_SUPPORT 359 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5) 360 #else /* MSCHAP_SUPPORT */ 361 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5) 362 #endif /* MSCHAP_SUPPORT */ 363 364 #else /* CHAP_SUPPORT */ 365 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE) 366 #endif /* CHAP_SUPPORT */ 367 368 #if PPP_STATS_SUPPORT 369 /* 370 * PPP statistics structure 371 */ 372 struct pppd_stats { 373 unsigned int bytes_in; 374 unsigned int bytes_out; 375 unsigned int pkts_in; 376 unsigned int pkts_out; 377 }; 378 #endif /* PPP_STATS_SUPPORT */ 379 380 381 /* 382 * PPP private functions 383 */ 384 385 386 /* 387 * Functions called from lwIP core. 388 */ 389 390 /* initialize the PPP subsystem */ 391 int ppp_init(void); 392 393 /* 394 * Functions called from PPP link protocols. 395 */ 396 397 /* Create a new PPP control block */ 398 ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb, 399 ppp_link_status_cb_fn link_status_cb, void *ctx_cb); 400 401 /* Initiate LCP open request */ 402 void ppp_start(ppp_pcb *pcb); 403 404 /* Called when link failed to setup */ 405 void ppp_link_failed(ppp_pcb *pcb); 406 407 /* Called when link is normally down (i.e. it was asked to end) */ 408 void ppp_link_end(ppp_pcb *pcb); 409 410 /* function called to process input packet */ 411 void ppp_input(ppp_pcb *pcb, struct pbuf *pb); 412 413 414 /* 415 * Functions called by PPP protocols. 416 */ 417 418 /* function called by all PPP subsystems to send packets */ 419 err_t ppp_write(ppp_pcb *pcb, struct pbuf *p); 420 421 /* functions called by auth.c link_terminated() */ 422 void ppp_link_terminated(ppp_pcb *pcb); 423 424 void new_phase(ppp_pcb *pcb, int p); 425 426 int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp); 427 int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp); 428 429 #if PPP_IPV4_SUPPORT 430 int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask); 431 int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr); 432 #if 0 /* UNUSED - PROXY ARP */ 433 int sifproxyarp(ppp_pcb *pcb, u32_t his_adr); 434 int cifproxyarp(ppp_pcb *pcb, u32_t his_adr); 435 #endif /* UNUSED - PROXY ARP */ 436 #if LWIP_DNS 437 int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); 438 int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); 439 #endif /* LWIP_DNS */ 440 #if VJ_SUPPORT 441 int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid); 442 #endif /* VJ_SUPPORT */ 443 int sifup(ppp_pcb *pcb); 444 int sifdown (ppp_pcb *pcb); 445 u32_t get_mask(u32_t addr); 446 #endif /* PPP_IPV4_SUPPORT */ 447 448 #if PPP_IPV6_SUPPORT 449 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64); 450 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64); 451 int sif6up(ppp_pcb *pcb); 452 int sif6down (ppp_pcb *pcb); 453 #endif /* PPP_IPV6_SUPPORT */ 454 455 #if DEMAND_SUPPORT 456 int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode); 457 #endif /* DEMAND_SUPPORt */ 458 459 void netif_set_mtu(ppp_pcb *pcb, int mtu); 460 int netif_get_mtu(ppp_pcb *pcb); 461 462 #if CCP_SUPPORT 463 #if 0 /* unused */ 464 int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit); 465 #endif /* unused */ 466 void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method); 467 void ccp_reset_comp(ppp_pcb *pcb); 468 void ccp_reset_decomp(ppp_pcb *pcb); 469 #if 0 /* unused */ 470 int ccp_fatal_error(ppp_pcb *pcb); 471 #endif /* unused */ 472 #endif /* CCP_SUPPORT */ 473 474 #if PPP_IDLETIMELIMIT 475 int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip); 476 #endif /* PPP_IDLETIMELIMIT */ 477 478 #if DEMAND_SUPPORT 479 int get_loop_output(void); 480 #endif /* DEMAND_SUPPORT */ 481 482 /* Optional protocol names list, to make our messages a little more informative. */ 483 #if PPP_PROTOCOLNAME 484 const char * protocol_name(int proto); 485 #endif /* PPP_PROTOCOLNAME */ 486 487 /* Optional stats support, to get some statistics on the PPP interface */ 488 #if PPP_STATS_SUPPORT 489 void print_link_stats(void); /* Print stats, if available */ 490 void reset_link_stats(int u); /* Reset (init) stats when link goes up */ 491 void update_link_stats(int u); /* Get stats at link termination */ 492 #endif /* PPP_STATS_SUPPORT */ 493 494 495 496 /* 497 * Inline versions of get/put char/short/long. 498 * Pointer is advanced; we assume that both arguments 499 * are lvalues and will already be in registers. 500 * cp MUST be u_char *. 501 */ 502 #define GETCHAR(c, cp) { \ 503 (c) = *(cp)++; \ 504 } 505 #define PUTCHAR(c, cp) { \ 506 *(cp)++ = (u_char) (c); \ 507 } 508 #define GETSHORT(s, cp) { \ 509 (s) = *(cp)++ << 8; \ 510 (s) |= *(cp)++; \ 511 } 512 #define PUTSHORT(s, cp) { \ 513 *(cp)++ = (u_char) ((s) >> 8); \ 514 *(cp)++ = (u_char) (s); \ 515 } 516 #define GETLONG(l, cp) { \ 517 (l) = *(cp)++ << 8; \ 518 (l) |= *(cp)++; (l) <<= 8; \ 519 (l) |= *(cp)++; (l) <<= 8; \ 520 (l) |= *(cp)++; \ 521 } 522 #define PUTLONG(l, cp) { \ 523 *(cp)++ = (u_char) ((l) >> 24); \ 524 *(cp)++ = (u_char) ((l) >> 16); \ 525 *(cp)++ = (u_char) ((l) >> 8); \ 526 *(cp)++ = (u_char) (l); \ 527 } 528 529 #define INCPTR(n, cp) ((cp) += (n)) 530 #define DECPTR(n, cp) ((cp) -= (n)) 531 532 /* 533 * System dependent definitions for user-level 4.3BSD UNIX implementation. 534 */ 535 #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) 536 #define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0) 537 #define UNTIMEOUT(f, a) sys_untimeout((f), (a)) 538 539 #define BZERO(s, n) memset(s, 0, n) 540 #define BCMP(s1, s2, l) memcmp(s1, s2, l) 541 542 #define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); } 543 544 /* 545 * MAKEHEADER - Add Header fields to a packet. 546 */ 547 #define MAKEHEADER(p, t) { \ 548 PUTCHAR(PPP_ALLSTATIONS, p); \ 549 PUTCHAR(PPP_UI, p); \ 550 PUTSHORT(t, p); } 551 552 /* Procedures exported from auth.c */ 553 void link_required(ppp_pcb *pcb); /* we are starting to use the link */ 554 void link_terminated(ppp_pcb *pcb); /* we are finished with the link */ 555 void link_down(ppp_pcb *pcb); /* the LCP layer has left the Opened state */ 556 void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */ 557 void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */ 558 void start_networks(ppp_pcb *pcb); /* start all the network control protos */ 559 void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */ 560 #if PPP_AUTH_SUPPORT 561 #if PPP_SERVER 562 int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int passwdlen, const char **msg, int *msglen); 563 /* check the user name and passwd against configuration */ 564 void auth_peer_fail(ppp_pcb *pcb, int protocol); 565 /* peer failed to authenticate itself */ 566 void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen); 567 /* peer successfully authenticated itself */ 568 #endif /* PPP_SERVER */ 569 void auth_withpeer_fail(ppp_pcb *pcb, int protocol); 570 /* we failed to authenticate ourselves */ 571 void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor); 572 /* we successfully authenticated ourselves */ 573 #endif /* PPP_AUTH_SUPPORT */ 574 void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */ 575 void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */ 576 void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */ 577 #if PPP_AUTH_SUPPORT 578 int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server); 579 /* get "secret" for chap */ 580 #endif /* PPP_AUTH_SUPPORT */ 581 582 /* Procedures exported from ipcp.c */ 583 /* int parse_dotted_ip (char *, u32_t *); */ 584 585 /* Procedures exported from demand.c */ 586 #if DEMAND_SUPPORT 587 void demand_conf (void); /* config interface(s) for demand-dial */ 588 void demand_block (void); /* set all NPs to queue up packets */ 589 void demand_unblock (void); /* set all NPs to pass packets */ 590 void demand_discard (void); /* set all NPs to discard packets */ 591 void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/ 592 int loop_chars (unsigned char *, int); /* process chars from loopback */ 593 int loop_frame (unsigned char *, int); /* should we bring link up? */ 594 #endif /* DEMAND_SUPPORT */ 595 596 /* Procedures exported from multilink.c */ 597 #ifdef HAVE_MULTILINK 598 void mp_check_options (void); /* Check multilink-related options */ 599 int mp_join_bundle (void); /* join our link to an appropriate bundle */ 600 void mp_exit_bundle (void); /* have disconnected our link from bundle */ 601 void mp_bundle_terminated (void); 602 char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */ 603 int str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */ 604 #else 605 #define mp_bundle_terminated() /* nothing */ 606 #define mp_exit_bundle() /* nothing */ 607 #define doing_multilink 0 608 #define multilink_master 0 609 #endif 610 611 /* Procedures exported from utils.c. */ 612 void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg); /* Format a string for output */ 613 int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* sprintf++ */ 614 int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */ 615 size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */ 616 size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */ 617 void ppp_dbglog(const char *fmt, ...); /* log a debug message */ 618 void ppp_info(const char *fmt, ...); /* log an informational message */ 619 void ppp_notice(const char *fmt, ...); /* log a notice-level message */ 620 void ppp_warn(const char *fmt, ...); /* log a warning message */ 621 void ppp_error(const char *fmt, ...); /* log an error message */ 622 void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */ 623 #if PRINTPKT_SUPPORT 624 void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); 625 /* dump packet to debug log if interesting */ 626 #endif /* PRINTPKT_SUPPORT */ 627 628 /* 629 * Number of necessary timers analysis. 630 * 631 * PPP use at least one timer per each of its protocol, but not all protocols are 632 * active at the same time, thus the number of necessary timeouts is actually 633 * lower than enabled protocols. Here is the actual necessary timeouts based 634 * on code analysis. 635 * 636 * Note that many features analysed here are not working at all and are only 637 * there for a comprehensive analysis of necessary timers in order to prevent 638 * having to redo that each time we add a feature. 639 * 640 * Timer list 641 * 642 * | holdoff timeout 643 * | low level protocol timeout (PPPoE or PPPoL2P) 644 * | LCP delayed UP 645 * | LCP retransmit (FSM) 646 * | LCP Echo timer 647 * .| PAP or CHAP or EAP authentication 648 * . | ECP retransmit (FSM) 649 * . | CCP retransmit (FSM) when MPPE is enabled 650 * . | CCP retransmit (FSM) when MPPE is NOT enabled 651 * . | IPCP retransmit (FSM) 652 * . .| IP6CP retransmit (FSM) 653 * . . | Idle time limit 654 * . . | Max connect time 655 * . . | Max octets 656 * . . | CCP RACK timeout 657 * . . . 658 * PPP_PHASE_DEAD 659 * PPP_PHASE_HOLDOFF 660 * | . . . 661 * PPP_PHASE_INITIALIZE 662 * | . . . 663 * PPP_PHASE_ESTABLISH 664 * | . . . 665 * |. . . 666 * | . . 667 * PPP_PHASE_AUTHENTICATE 668 * | . . 669 * || . . 670 * PPP_PHASE_NETWORK 671 * | || . . 672 * | ||| . 673 * PPP_PHASE_RUNNING 674 * | .||||| 675 * | . |||| 676 * PPP_PHASE_TERMINATE 677 * | . |||| 678 * PPP_PHASE_NETWORK 679 * |. . 680 * PPP_PHASE_ESTABLISH 681 * PPP_PHASE_DISCONNECT 682 * PPP_PHASE_DEAD 683 * 684 * Alright, PPP basic retransmission and LCP Echo consume one timer. 685 * 1 686 * 687 * If authentication is enabled one timer is necessary during authentication. 688 * 1 + PPP_AUTH_SUPPORT 689 * 690 * If ECP is enabled one timer is necessary before IPCP and/or IP6CP, one more 691 * is necessary if CCP is enabled (only with MPPE support but we don't care much 692 * up to this detail level). 693 * 1 + ECP_SUPPORT + CCP_SUPPORT 694 * 695 * If CCP is enabled it might consume a timer during IPCP or IP6CP, thus 696 * we might use IPCP, IP6CP and CCP timers simultaneously. 697 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT 698 * 699 * When entering running phase, IPCP or IP6CP is still running. If idle time limit 700 * is enabled one more timer is necessary. Same for max connect time and max 701 * octets features. Furthermore CCP RACK might be used past this point. 702 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT 703 * 704 * IPv4 or IPv6 must be enabled, therefore we don't need to take care the authentication 705 * and the CCP + ECP case, thus reducing overall complexity. 706 * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT) 707 * 708 * We don't support PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features 709 * and adding those defines to ppp_opts.h just for having the value always 710 * defined to 0 isn't worth it. 711 * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT) 712 * 713 * Thus, the following is enough for now. 714 * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT 715 */ 716 717 #ifdef __cplusplus 718 } 719 #endif 720 721 #endif /* PPP_SUPPORT */ 722 #endif /* LWIP_HDR_PPP_IMPL_H */ 723