Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ppp_impl.h Source File

ppp_impl.h

00001 /*****************************************************************************
00002 * /@code
00003 *
00004 * ppp.h - Network Point to Point Protocol header file.
00005 *
00006 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
00007 * portions Copyright (c) 1997 Global Election Systems Inc.
00008 *
00009 * The authors hereby grant permission to use, copy, modify, distribute,
00010 * and license this software and its documentation for any purpose, provided
00011 * that existing copyright notices are retained in all copies and that this
00012 * notice and the following disclaimer are included verbatim in any
00013 * distributions. No written agreement, license, or royalty fee is required
00014 * for any of the authorized uses.
00015 *
00016 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
00017 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 *
00027 ******************************************************************************
00028 * REVISION HISTORY
00029 *
00030 * 03-01-01 Marc Boucher <marc@mbsi.ca>
00031 *   Ported to lwIP.
00032 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
00033 *   Original derived from BSD codes.
00034 *
00035 * /@endcode
00036 *****************************************************************************/
00037 #ifndef PPP_IMPL_H
00038 #define PPP_IMPL_H
00039 
00040 #include "ppp_opts.h"
00041 
00042 #if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
00043 
00044 #ifdef PPP_INCLUDE_SETTINGS_HEADER
00045 #include "ppp_settings.h"
00046 #endif
00047 
00048 #include <stdio.h> /* formats */
00049 #include <stdarg.h>
00050 #include <string.h>
00051 #include <stdlib.h> /* strtol() */
00052 
00053 #include "ppp.h"
00054 #include "pppdebug.h"
00055 
00056 #ifdef __cplusplus
00057 extern "C" {
00058 #endif
00059 
00060 /*
00061  * Endian conversion macros
00062  */
00063 #ifndef LITTLE_ENDIAN
00064 #define LITTLE_ENDIAN 1234
00065 #endif
00066 
00067 #ifndef BIG_ENDIAN
00068 #define BIG_ENDIAN 4321
00069 #endif
00070 
00071 #ifndef BYTE_ORDER
00072 #define BYTE_ORDER LITTLE_ENDIAN
00073 #endif
00074 
00075 #if BYTE_ORDER == BIG_ENDIAN
00076 #define ppp_htons(x) ((u16_t)(x))
00077 #define ppp_ntohs(x) ((u16_t)(x))
00078 #define ppp_htonl(x) ((u32_t)(x))
00079 #define ppp_ntohl(x) ((u32_t)(x))
00080 #define PP_HTONS(x)   ((u16_t)(x))
00081 #define PP_NTOHS(x)   ((u16_t)(x))
00082 #define PP_HTONL(x)   ((u32_t)(x))
00083 #define PP_NTOHL(x)   ((u32_t)(x))
00084 #else /* BYTE_ORDER != BIG_ENDIAN */
00085 #ifndef ppp_htons
00086 u16_t ppp_htons(u16_t x);
00087 #endif
00088 #define ppp_ntohs(x) ppp_htons(x)
00089 
00090 #ifndef ppp_htonl
00091 u32_t ppp_htonl(u32_t x);
00092 #endif
00093 #define ppp_ntohl(x) ppp_htonl(x)
00094 
00095 /* These macros should be calculated by the preprocessor and are used
00096    with compile-time constants only (so that there is no little-endian
00097    overhead at runtime). */
00098 #define PP_HTONS(x) ((u16_t)((((x) & (u16_t)0x00ffU) << 8) | (((x) & (u16_t)0xff00U) >> 8)))
00099 #define PP_NTOHS(x) PP_HTONS(x)
00100 #define PP_HTONL(x) ((((x) & (u32_t)0x000000ffUL) << 24) | \
00101                      (((x) & (u32_t)0x0000ff00UL) <<  8) | \
00102                      (((x) & (u32_t)0x00ff0000UL) >>  8) | \
00103                      (((x) & (u32_t)0xff000000UL) >> 24))
00104 #define PP_NTOHL(x) PP_HTONL(x)
00105 #endif /* BYTE_ORDER == BIG_ENDIAN */
00106 
00107 /*
00108  * Memory used for control packets.
00109  *
00110  * PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we
00111  * cannot figure out how much we are going to use before filling the buffer.
00112  */
00113 #if PPP_USE_PBUF_RAM
00114 #define PPP_CTRL_PBUF_TYPE       PBUF_RAM
00115 #define PPP_CTRL_PBUF_MAX_SIZE   512
00116 #else /* PPP_USE_PBUF_RAM */
00117 #define PPP_CTRL_PBUF_TYPE       PBUF_POOL
00118 #define PPP_CTRL_PBUF_MAX_SIZE   PBUF_POOL_BUFSIZE
00119 #endif /* PPP_USE_PBUF_RAM */
00120 
00121 /*
00122  * The basic PPP frame.
00123  */
00124 #define PPP_ADDRESS(p)  (((u_char *)(p))[0])
00125 #define PPP_CONTROL(p)  (((u_char *)(p))[1])
00126 #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
00127 
00128 /*
00129  * Significant octet values.
00130  */
00131 #define PPP_ALLSTATIONS 0xff    /* All-Stations broadcast address */
00132 #define PPP_UI      0x03    /* Unnumbered Information */
00133 #define PPP_FLAG    0x7e    /* Flag Sequence */
00134 #define PPP_ESCAPE  0x7d    /* Asynchronous Control Escape */
00135 #define PPP_TRANS   0x20    /* Asynchronous transparency modifier */
00136 
00137 /*
00138  * Protocol field values.
00139  */
00140 #define PPP_IP      0x21    /* Internet Protocol */
00141 #if 0 /* UNUSED */
00142 #define PPP_AT      0x29    /* AppleTalk Protocol */
00143 #define PPP_IPX     0x2b    /* IPX protocol */
00144 #endif /* UNUSED */
00145 #if VJ_SUPPORT
00146 #define PPP_VJC_COMP    0x2d    /* VJ compressed TCP */
00147 #define PPP_VJC_UNCOMP  0x2f    /* VJ uncompressed TCP */
00148 #endif /* VJ_SUPPORT */
00149 #if PPP_IPV6_SUPPORT
00150 #define PPP_IPV6    0x57    /* Internet Protocol Version 6 */
00151 #endif /* PPP_IPV6_SUPPORT */
00152 #if CCP_SUPPORT
00153 #define PPP_COMP    0xfd    /* compressed packet */
00154 #endif /* CCP_SUPPORT */
00155 #define PPP_IPCP    0x8021  /* IP Control Protocol */
00156 #if 0 /* UNUSED */
00157 #define PPP_ATCP    0x8029  /* AppleTalk Control Protocol */
00158 #define PPP_IPXCP   0x802b  /* IPX Control Protocol */
00159 #endif /* UNUSED */
00160 #if PPP_IPV6_SUPPORT
00161 #define PPP_IPV6CP  0x8057  /* IPv6 Control Protocol */
00162 #endif /* PPP_IPV6_SUPPORT */
00163 #if CCP_SUPPORT
00164 #define PPP_CCP     0x80fd  /* Compression Control Protocol */
00165 #endif /* CCP_SUPPORT */
00166 #if ECP_SUPPORT
00167 #define PPP_ECP     0x8053  /* Encryption Control Protocol */
00168 #endif /* ECP_SUPPORT */
00169 #define PPP_LCP     0xc021  /* Link Control Protocol */
00170 #if PAP_SUPPORT
00171 #define PPP_PAP     0xc023  /* Password Authentication Protocol */
00172 #endif /* PAP_SUPPORT */
00173 #if LQR_SUPPORT
00174 #define PPP_LQR     0xc025  /* Link Quality Report protocol */
00175 #endif /* LQR_SUPPORT */
00176 #if CHAP_SUPPORT
00177 #define PPP_CHAP    0xc223  /* Cryptographic Handshake Auth. Protocol */
00178 #endif /* CHAP_SUPPORT */
00179 #if CBCP_SUPPORT
00180 #define PPP_CBCP    0xc029  /* Callback Control Protocol */
00181 #endif /* CBCP_SUPPORT */
00182 #if EAP_SUPPORT
00183 #define PPP_EAP     0xc227  /* Extensible Authentication Protocol */
00184 #endif /* EAP_SUPPORT */
00185 
00186 /*
00187  * The following struct gives the addresses of procedures to call
00188  * for a particular lower link level protocol.
00189  */
00190 struct link_callbacks {
00191   /* Start a connection (e.g. Initiate discovery phase) */
00192   void (*connect) (ppp_pcb *pcb, void *ctx);
00193 #if PPP_SERVER
00194   /* Listen for an incoming connection (Passive mode) */
00195   void (*listen) (ppp_pcb *pcb, void *ctx);
00196 #endif /* PPP_SERVER */
00197   /* End a connection (i.e. initiate disconnect phase) */
00198   void (*disconnect) (ppp_pcb *pcb, void *ctx);
00199   /* Free lower protocol control block */
00200   err_t (*free) (ppp_pcb *pcb, void *ctx);
00201   /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */
00202   err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p);
00203   /* Send a packet from stack core (IPv4 or IPv6) */
00204   err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol);
00205   /* configure the transmit-side characteristics of the PPP interface */
00206   void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
00207   /* confire the receive-side characteristics of the PPP interface */
00208   void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
00209 };
00210 
00211 /*
00212  * What to do with network protocol (NP) packets.
00213  */
00214 enum NPmode {
00215     NPMODE_PASS,        /* pass the packet through */
00216     NPMODE_DROP,        /* silently drop the packet */
00217     NPMODE_ERROR,       /* return an error */
00218     NPMODE_QUEUE        /* save it up for later. */
00219 };
00220 
00221 /*
00222  * Statistics.
00223  */
00224 #if PPP_STATS_SUPPORT
00225 struct pppstat  {
00226     unsigned int ppp_ibytes;    /* bytes received */
00227     unsigned int ppp_ipackets;  /* packets received */
00228     unsigned int ppp_ierrors;   /* receive errors */
00229     unsigned int ppp_obytes;    /* bytes sent */
00230     unsigned int ppp_opackets;  /* packets sent */
00231     unsigned int ppp_oerrors;   /* transmit errors */
00232 };
00233 
00234 #if VJ_SUPPORT
00235 struct vjstat {
00236     unsigned int vjs_packets;   /* outbound packets */
00237     unsigned int vjs_compressed; /* outbound compressed packets */
00238     unsigned int vjs_searches;  /* searches for connection state */
00239     unsigned int vjs_misses;    /* times couldn't find conn. state */
00240     unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
00241     unsigned int vjs_compressedin; /* inbound compressed packets */
00242     unsigned int vjs_errorin;   /* inbound unknown type packets */
00243     unsigned int vjs_tossed;    /* inbound packets tossed because of error */
00244 };
00245 #endif /* VJ_SUPPORT */
00246 
00247 struct ppp_stats {
00248     struct pppstat p;       /* basic PPP statistics */
00249 #if VJ_SUPPORT
00250     struct vjstat vj;       /* VJ header compression statistics */
00251 #endif /* VJ_SUPPORT */
00252 };
00253 
00254 #if CCP_SUPPORT
00255 struct compstat {
00256     unsigned int unc_bytes; /* total uncompressed bytes */
00257     unsigned int unc_packets;   /* total uncompressed packets */
00258     unsigned int comp_bytes;    /* compressed bytes */
00259     unsigned int comp_packets;  /* compressed packets */
00260     unsigned int inc_bytes; /* incompressible bytes */
00261     unsigned int inc_packets;   /* incompressible packets */
00262     unsigned int ratio;     /* recent compression ratio << 8 */
00263 };
00264 
00265 struct ppp_comp_stats {
00266     struct compstat c;      /* packet compression statistics */
00267     struct compstat d;      /* packet decompression statistics */
00268 };
00269 #endif /* CCP_SUPPORT */
00270 
00271 #endif /* PPP_STATS_SUPPORT */
00272 
00273 #if PPP_IDLETIMELIMIT
00274 /*
00275  * The following structure records the time in seconds since
00276  * the last NP packet was sent or received.
00277  */
00278 struct ppp_idle {
00279     time_t xmit_idle;       /* time since last NP packet sent */
00280     time_t recv_idle;       /* time since last NP packet received */
00281 };
00282 #endif /* PPP_IDLETIMELIMIT */
00283 
00284 /* values for epdisc.class */
00285 #define EPD_NULL    0   /* null discriminator, no data */
00286 #define EPD_LOCAL   1
00287 #define EPD_IP      2
00288 #define EPD_MAC     3
00289 #define EPD_MAGIC   4
00290 #define EPD_PHONENUM    5
00291 
00292 /*
00293  * Global variables.
00294  */
00295 #ifdef HAVE_MULTILINK
00296 extern u8_t multilink;  /* enable multilink operation */
00297 extern u8_t doing_multilink;
00298 extern u8_t multilink_master;
00299 extern u8_t bundle_eof;
00300 extern u8_t bundle_terminating;
00301 #endif
00302 
00303 #ifdef MAXOCTETS
00304 extern unsigned int maxoctets;       /* Maximum octetes per session (in bytes) */
00305 extern int       maxoctets_dir;      /* Direction :
00306                       0 - in+out (default)
00307                       1 - in
00308                       2 - out
00309                       3 - max(in,out) */
00310 extern int       maxoctets_timeout;  /* Timeout for check of octets limit */
00311 #define PPP_OCTETS_DIRECTION_SUM        0
00312 #define PPP_OCTETS_DIRECTION_IN         1
00313 #define PPP_OCTETS_DIRECTION_OUT        2
00314 #define PPP_OCTETS_DIRECTION_MAXOVERAL  3
00315 /* same as previos, but little different on RADIUS side */
00316 #define PPP_OCTETS_DIRECTION_MAXSESSION 4
00317 #endif
00318 
00319 /* Data input may be used by CCP and ECP, remove this entry
00320  * from struct protent to save some flash
00321  */
00322 #define PPP_DATAINPUT 0
00323 
00324 /*
00325  * The following struct gives the addresses of procedures to call
00326  * for a particular protocol.
00327  */
00328 struct protent {
00329     u_short protocol;       /* PPP protocol number */
00330     /* Initialization procedure */
00331     void (*init) (ppp_pcb *pcb);
00332     /* Process a received packet */
00333     void (*input) (ppp_pcb *pcb, u_char *pkt, int len);
00334     /* Process a received protocol-reject */
00335     void (*protrej) (ppp_pcb *pcb);
00336     /* Lower layer has come up */
00337     void (*lowerup) (ppp_pcb *pcb);
00338     /* Lower layer has gone down */
00339     void (*lowerdown) (ppp_pcb *pcb);
00340     /* Open the protocol */
00341     void (*open) (ppp_pcb *pcb);
00342     /* Close the protocol */
00343     void (*close) (ppp_pcb *pcb, const char *reason);
00344 #if PRINTPKT_SUPPORT
00345     /* Print a packet in readable form */
00346     int  (*printpkt) (const u_char *pkt, int len,
00347               void (*printer) (void *, const char *, ...),
00348               void *arg);
00349 #endif /* PRINTPKT_SUPPORT */
00350 #if PPP_DATAINPUT
00351     /* Process a received data packet */
00352     void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len);
00353 #endif /* PPP_DATAINPUT */
00354 #if PRINTPKT_SUPPORT
00355     const char *name;       /* Text name of protocol */
00356     const char *data_name;  /* Text name of corresponding data protocol */
00357 #endif /* PRINTPKT_SUPPORT */
00358 #if PPP_OPTIONS
00359     option_t *options;      /* List of command-line options */
00360     /* Check requested options, assign defaults */
00361     void (*check_options) (void);
00362 #endif /* PPP_OPTIONS */
00363 #if DEMAND_SUPPORT
00364     /* Configure interface for demand-dial */
00365     int  (*demand_conf) (int unit);
00366     /* Say whether to bring up link for this pkt */
00367     int  (*active_pkt) (u_char *pkt, int len);
00368 #endif /* DEMAND_SUPPORT */
00369 };
00370 
00371 /* Table of pointers to supported protocols */
00372 extern const struct protent* const protocols[];
00373 
00374 
00375 /* Values for auth_pending, auth_done */
00376 #if PAP_SUPPORT
00377 #define PAP_WITHPEER    0x1
00378 #define PAP_PEER    0x2
00379 #endif /* PAP_SUPPORT */
00380 #if CHAP_SUPPORT
00381 #define CHAP_WITHPEER   0x4
00382 #define CHAP_PEER   0x8
00383 #endif /* CHAP_SUPPORT */
00384 #if EAP_SUPPORT
00385 #define EAP_WITHPEER    0x10
00386 #define EAP_PEER    0x20
00387 #endif /* EAP_SUPPORT */
00388 
00389 /* Values for auth_done only */
00390 #if CHAP_SUPPORT
00391 #define CHAP_MD5_WITHPEER   0x40
00392 #define CHAP_MD5_PEER       0x80
00393 #if MSCHAP_SUPPORT
00394 #define CHAP_MS_SHIFT       8   /* LSB position for MS auths */
00395 #define CHAP_MS_WITHPEER    0x100
00396 #define CHAP_MS_PEER        0x200
00397 #define CHAP_MS2_WITHPEER   0x400
00398 #define CHAP_MS2_PEER       0x800
00399 #endif /* MSCHAP_SUPPORT */
00400 #endif /* CHAP_SUPPORT */
00401 
00402 /* Supported CHAP protocols */
00403 #if CHAP_SUPPORT
00404 
00405 #if MSCHAP_SUPPORT
00406 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
00407 #else /* MSCHAP_SUPPORT */
00408 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5)
00409 #endif /* MSCHAP_SUPPORT */
00410 
00411 #else /* CHAP_SUPPORT */
00412 #define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE)
00413 #endif /* CHAP_SUPPORT */
00414 
00415 #if PPP_STATS_SUPPORT
00416 /*
00417  * PPP statistics structure
00418  */
00419 struct pppd_stats {
00420     unsigned int    bytes_in;
00421     unsigned int    bytes_out;
00422     unsigned int    pkts_in;
00423     unsigned int    pkts_out;
00424 };
00425 #endif /* PPP_STATS_SUPPORT */
00426 
00427 
00428 /*
00429  * PPP private functions
00430  */
00431 
00432  
00433 /*
00434  * Functions called from stack core.
00435  */
00436 
00437 /* initialize the PPP subsystem */
00438 int ppp_init(void);
00439 
00440 /*
00441  * Functions called from PPP link protocols.
00442  */
00443 
00444 /* Create a new PPP control block */
00445 ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb,
00446                  ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
00447 
00448 /* Initiate LCP open request */
00449 void ppp_start(ppp_pcb *pcb);
00450 
00451 /* Called when link failed to setup */
00452 void ppp_link_failed(ppp_pcb *pcb);
00453 
00454 /* Called when link is normally down (i.e. it was asked to end) */
00455 void ppp_link_end(ppp_pcb *pcb);
00456 
00457 /* function called to process input packet */
00458 void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
00459 
00460 
00461 /*
00462  * Functions called by PPP protocols.
00463  */
00464 
00465 /* function called by all PPP subsystems to send packets */
00466 err_t ppp_write(ppp_pcb *pcb, struct pbuf *p);
00467 
00468 /* functions called by auth.c link_terminated() */
00469 void ppp_link_terminated(ppp_pcb *pcb);
00470 
00471 void new_phase(ppp_pcb *pcb, int p);
00472 
00473 int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
00474 int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp);
00475 
00476 #if PPP_IPV4_SUPPORT
00477 int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask);
00478 int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr);
00479 #if 0 /* UNUSED - PROXY ARP */
00480 int sifproxyarp(ppp_pcb *pcb, u32_t his_adr);
00481 int cifproxyarp(ppp_pcb *pcb, u32_t his_adr);
00482 #endif /* UNUSED - PROXY ARP */
00483 #if PPP_DNS
00484 int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
00485 int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
00486 #endif /* PPP_DNS */
00487 #if VJ_SUPPORT
00488 int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid);
00489 #endif /* VJ_SUPPORT */
00490 int sifup(ppp_pcb *pcb);
00491 int sifdown (ppp_pcb *pcb);
00492 u32_t get_mask(u32_t addr);
00493 #endif /* PPP_IPV4_SUPPORT */
00494 
00495 #if PPP_IPV6_SUPPORT
00496 int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
00497 int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
00498 int sif6up(ppp_pcb *pcb);
00499 int sif6down (ppp_pcb *pcb);
00500 #endif /* PPP_IPV6_SUPPORT */
00501 
00502 #if DEMAND_SUPPORT
00503 int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode);
00504 #endif /* DEMAND_SUPPORt */
00505 
00506 void netif_set_mtu(ppp_pcb *pcb, int mtu);
00507 int netif_get_mtu(ppp_pcb *pcb);
00508 
00509 #if CCP_SUPPORT
00510 #if 0 /* unused */
00511 int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit);
00512 #endif /* unused */
00513 void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method);
00514 void ccp_reset_comp(ppp_pcb *pcb);
00515 void ccp_reset_decomp(ppp_pcb *pcb);
00516 #if 0 /* unused */
00517 int ccp_fatal_error(ppp_pcb *pcb);
00518 #endif /* unused */
00519 #endif /* CCP_SUPPORT */
00520 
00521 #if PPP_IDLETIMELIMIT
00522 int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip);
00523 #endif /* PPP_IDLETIMELIMIT */
00524 
00525 #if DEMAND_SUPPORT
00526 int get_loop_output(void);
00527 #endif /* DEMAND_SUPPORT */
00528 
00529 /* Optional protocol names list, to make our messages a little more informative. */
00530 #if PPP_PROTOCOLNAME
00531 const char * protocol_name(int proto);
00532 #endif /* PPP_PROTOCOLNAME  */
00533 
00534 /* Optional stats support, to get some statistics on the PPP interface */
00535 #if PPP_STATS_SUPPORT
00536 void print_link_stats(void); /* Print stats, if available */
00537 void reset_link_stats(int u); /* Reset (init) stats when link goes up */
00538 void update_link_stats(int u); /* Get stats at link termination */
00539 #endif /* PPP_STATS_SUPPORT */
00540 
00541 
00542 
00543 /*
00544  * Inline versions of get/put char/short/long.
00545  * Pointer is advanced; we assume that both arguments
00546  * are lvalues and will already be in registers.
00547  * cp MUST be u_char *.
00548  */
00549 #define GETCHAR(c, cp) { \
00550     (c) = *(cp)++; \
00551 }
00552 #define PUTCHAR(c, cp) { \
00553     *(cp)++ = (u_char) (c); \
00554 }
00555 #define GETSHORT(s, cp) { \
00556     (s) = *(cp)++ << 8; \
00557     (s) |= *(cp)++; \
00558 }
00559 #define PUTSHORT(s, cp) { \
00560     *(cp)++ = (u_char) ((s) >> 8); \
00561     *(cp)++ = (u_char) (s); \
00562 }
00563 #define GETLONG(l, cp) { \
00564     (l) = *(cp)++ << 8; \
00565     (l) |= *(cp)++; (l) <<= 8; \
00566     (l) |= *(cp)++; (l) <<= 8; \
00567     (l) |= *(cp)++; \
00568 }
00569 #define PUTLONG(l, cp) { \
00570     *(cp)++ = (u_char) ((l) >> 24); \
00571     *(cp)++ = (u_char) ((l) >> 16); \
00572     *(cp)++ = (u_char) ((l) >> 8); \
00573     *(cp)++ = (u_char) (l); \
00574 }
00575 
00576 #define INCPTR(n, cp)   ((cp) += (n))
00577 #define DECPTR(n, cp)   ((cp) -= (n))
00578 
00579 #define BZERO(s, n)     memset(s, 0, n)
00580 #define BCMP(s1, s2, l)     memcmp(s1, s2, l)
00581 
00582 #define PRINTMSG(m, l)      { ppp_info("Remote message: %0.*v", l, m); }
00583 
00584 /*
00585  * MAKEHEADER - Add Header fields to a packet.
00586  */
00587 #define MAKEHEADER(p, t) { \
00588     PUTCHAR(PPP_ALLSTATIONS, p); \
00589     PUTCHAR(PPP_UI, p); \
00590     PUTSHORT(t, p); }
00591 
00592 /* Procedures exported from auth.c */
00593 void link_required(ppp_pcb *pcb);     /* we are starting to use the link */
00594 void link_terminated(ppp_pcb *pcb);   /* we are finished with the link */
00595 void link_down(ppp_pcb *pcb);         /* the LCP layer has left the Opened state */
00596 void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */
00597 void link_established(ppp_pcb *pcb);  /* the link is up; authenticate now */
00598 void start_networks(ppp_pcb *pcb);    /* start all the network control protos */
00599 void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */
00600 #if PPP_AUTH_SUPPORT
00601 #if PPP_SERVER
00602 int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int passwdlen, const char **msg, int *msglen);
00603                                 /* check the user name and passwd against configuration */
00604 void auth_peer_fail(ppp_pcb *pcb, int protocol);
00605                 /* peer failed to authenticate itself */
00606 void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen);
00607                 /* peer successfully authenticated itself */
00608 #endif /* PPP_SERVER */
00609 void auth_withpeer_fail(ppp_pcb *pcb, int protocol);
00610                 /* we failed to authenticate ourselves */
00611 void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor);
00612                 /* we successfully authenticated ourselves */
00613 #endif /* PPP_AUTH_SUPPORT */
00614 void np_up(ppp_pcb *pcb, int proto);    /* a network protocol has come up */
00615 void np_down(ppp_pcb *pcb, int proto);  /* a network protocol has gone down */
00616 void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */
00617 #if PPP_AUTH_SUPPORT
00618 int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server);
00619                 /* get "secret" for chap */
00620 #endif /* PPP_AUTH_SUPPORT */
00621 
00622 /* Procedures exported from ipcp.c */
00623 /* int parse_dotted_ip (char *, u32_t *); */
00624 
00625 /* Procedures exported from demand.c */
00626 #if DEMAND_SUPPORT
00627 void demand_conf (void);    /* config interface(s) for demand-dial */
00628 void demand_block (void);   /* set all NPs to queue up packets */
00629 void demand_unblock (void); /* set all NPs to pass packets */
00630 void demand_discard (void); /* set all NPs to discard packets */
00631 void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/
00632 int  loop_chars (unsigned char *, int); /* process chars from loopback */
00633 int  loop_frame (unsigned char *, int); /* should we bring link up? */
00634 #endif /* DEMAND_SUPPORT */
00635 
00636 /* Procedures exported from multilink.c */
00637 #ifdef HAVE_MULTILINK
00638 void mp_check_options (void); /* Check multilink-related options */
00639 int  mp_join_bundle (void);  /* join our link to an appropriate bundle */
00640 void mp_exit_bundle (void);  /* have disconnected our link from bundle */
00641 void mp_bundle_terminated (void);
00642 char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */
00643 int  str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */
00644 #else
00645 #define mp_bundle_terminated()  /* nothing */
00646 #define mp_exit_bundle()    /* nothing */
00647 #define doing_multilink     0
00648 #define multilink_master    0
00649 #endif
00650 
00651 /* Procedures exported from utils.c. */
00652 void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg);   /* Format a string for output */
00653 int ppp_slprintf(char *buf, int buflen, const char *fmt, ...);            /* sprintf++ */
00654 int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args);  /* vsprintf++ */
00655 size_t ppp_strlcpy(char *dest, const char *src, size_t len);        /* safe strcpy */
00656 size_t ppp_strlcat(char *dest, const char *src, size_t len);        /* safe strncpy */
00657 void ppp_dbglog(const char *fmt, ...);    /* log a debug message */
00658 void ppp_info(const char *fmt, ...);      /* log an informational message */
00659 void ppp_notice(const char *fmt, ...);    /* log a notice-level message */
00660 void ppp_warn(const char *fmt, ...);      /* log a warning message */
00661 void ppp_error(const char *fmt, ...);     /* log an error message */
00662 void ppp_fatal(const char *fmt, ...);     /* log an error message and die(1) */
00663 #if PRINTPKT_SUPPORT
00664 void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len);
00665                                 /* dump packet to debug log if interesting */
00666 #endif /* PRINTPKT_SUPPORT */
00667 
00668 /*
00669  * Number of necessary timers analysis.
00670  *
00671  * PPP use at least one timer per each of its protocol, but not all protocols are
00672  * active at the same time, thus the number of necessary timeouts is actually
00673  * lower than enabled protocols. Here is the actual necessary timeouts based
00674  * on code analysis.
00675  *
00676  * Note that many features analysed here are not working at all and are only
00677  * there for a comprehensive analysis of necessary timers in order to prevent
00678  * having to redo that each time we add a feature.
00679  *
00680  * Timer list
00681  *
00682  * | holdoff timeout
00683  *  | low level protocol timeout (PPPoE or PPPoL2P)
00684  *   | LCP delayed UP
00685  *    | LCP retransmit (FSM)
00686  *     | LCP Echo timer
00687  *     .| PAP or CHAP or EAP authentication
00688  *     . | ECP retransmit (FSM)
00689  *     .  | CCP retransmit (FSM) when MPPE is enabled
00690  *     .   | CCP retransmit (FSM) when MPPE is NOT enabled
00691  *     .    | IPCP retransmit (FSM)
00692  *     .    .| IP6CP retransmit (FSM)
00693  *     .    . | Idle time limit
00694  *     .    .  | Max connect time
00695  *     .    .   | Max octets
00696  *     .    .    | CCP RACK timeout
00697  *     .    .    .
00698  * PPP_PHASE_DEAD
00699  * PPP_PHASE_HOLDOFF
00700  * |   .    .    .
00701  * PPP_PHASE_INITIALIZE
00702  *  |  .    .    .
00703  * PPP_PHASE_ESTABLISH
00704  *   | .    .    .
00705  *    |.    .    .
00706  *     |    .    .
00707  * PPP_PHASE_AUTHENTICATE
00708  *     |    .    .
00709  *     ||   .    .
00710  * PPP_PHASE_NETWORK
00711  *     | || .    .
00712  *     |   |||   .
00713  * PPP_PHASE_RUNNING
00714  *     |    .|||||
00715  *     |    . ||||
00716  * PPP_PHASE_TERMINATE
00717  *     |    . ||||
00718  * PPP_PHASE_NETWORK
00719  *    |.         .
00720  * PPP_PHASE_ESTABLISH
00721  * PPP_PHASE_DISCONNECT
00722  * PPP_PHASE_DEAD
00723  *
00724  * Alright, PPP basic retransmission and LCP Echo consume one timer.
00725  *  1
00726  *
00727  * If authentication is enabled one timer is necessary during authentication.
00728  *  1 + PPP_AUTH_SUPPORT
00729  *
00730  * If ECP is enabled one timer is necessary before IPCP and/or IP6CP, one more
00731  * is necessary if CCP is enabled (only with MPPE support but we don't care much
00732  * up to this detail level).
00733  *  1 + ECP_SUPPORT + CCP_SUPPORT
00734  *
00735  * If CCP is enabled it might consume a timer during IPCP or IP6CP, thus
00736  * we might use IPCP, IP6CP and CCP timers simultaneously.
00737  *  1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
00738  *
00739  * When entering running phase, IPCP or IP6CP is still running. If idle time limit
00740  * is enabled one more timer is necessary. Same for max connect time and max
00741  * octets features. Furthermore CCP RACK might be used past this point.
00742  *  1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT
00743  *
00744  * IPv4 or IPv6 must be enabled, therefore we don't need to take care the authentication
00745  * and the CCP + ECP case, thus reducing overall complexity.
00746  * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT)
00747  *
00748  * We don't support PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features
00749  * and adding those defines to ppp_opts.h just for having the value always
00750  * defined to 0 isn't worth it.
00751  * 1 + PPP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT)
00752  *
00753  * Thus, the following is enough for now.
00754  * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT
00755  */
00756 
00757 #ifdef __cplusplus
00758 }
00759 #endif
00760 
00761 #endif /* PPP_SUPPORT */
00762 #endif /* PPP_IMPL_H */