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.h Source File

ppp.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 
00038 #include "ppp_opts.h"
00039 #if PPP_SUPPORT /* don't build if not configured for use in ppp_opts.h */
00040 
00041 #ifndef PPP_H
00042 #define PPP_H
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 /* Disable non-working or rarely used PPP feature, so rarely that we don't want to bloat ppp_opts.h with them */
00049 #ifndef PPP_OPTIONS
00050 #define PPP_OPTIONS         0
00051 #endif
00052 
00053 #ifndef PPP_NOTIFY
00054 #define PPP_NOTIFY          0
00055 #endif
00056 
00057 #ifndef PPP_REMOTENAME
00058 #define PPP_REMOTENAME      0
00059 #endif
00060 
00061 #ifndef PPP_IDLETIMELIMIT
00062 #define PPP_IDLETIMELIMIT   0
00063 #endif
00064 
00065 #ifndef PPP_LCP_ADAPTIVE
00066 #define PPP_LCP_ADAPTIVE    0
00067 #endif
00068 
00069 #ifndef PPP_MAXCONNECT
00070 #define PPP_MAXCONNECT      0
00071 #endif
00072 
00073 #ifndef PPP_ALLOWED_ADDRS
00074 #define PPP_ALLOWED_ADDRS   0
00075 #endif
00076 
00077 #ifndef PPP_PROTOCOLNAME
00078 #define PPP_PROTOCOLNAME    0
00079 #endif
00080 
00081 #ifndef PPP_STATS_SUPPORT
00082 #define PPP_STATS_SUPPORT   0
00083 #endif
00084 
00085 #ifndef DEFLATE_SUPPORT
00086 #define DEFLATE_SUPPORT     0
00087 #endif
00088 
00089 #ifndef BSDCOMPRESS_SUPPORT
00090 #define BSDCOMPRESS_SUPPORT 0
00091 #endif
00092 
00093 #ifndef PREDICTOR_SUPPORT
00094 #define PREDICTOR_SUPPORT   0
00095 #endif
00096 
00097 /*************************
00098 *** PUBLIC DEFINITIONS ***
00099 *************************/
00100 
00101 /*
00102  * The basic PPP frame.
00103  */
00104 #define PPP_HDRLEN  4   /* octets for standard ppp header */
00105 #define PPP_FCSLEN  2   /* octets for FCS */
00106 
00107 /*
00108  * Values for phase.
00109  */
00110 #define PPP_PHASE_DEAD          0
00111 #define PPP_PHASE_MASTER        1
00112 #define PPP_PHASE_HOLDOFF       2
00113 #define PPP_PHASE_INITIALIZE    3
00114 #define PPP_PHASE_SERIALCONN    4
00115 #define PPP_PHASE_DORMANT       5
00116 #define PPP_PHASE_ESTABLISH     6
00117 #define PPP_PHASE_AUTHENTICATE  7
00118 #define PPP_PHASE_CALLBACK      8
00119 #define PPP_PHASE_NETWORK       9
00120 #define PPP_PHASE_RUNNING       10
00121 #define PPP_PHASE_TERMINATE     11
00122 #define PPP_PHASE_DISCONNECT    12
00123 
00124 /* Error codes. */
00125 #define PPPERR_NONE         0  /* No error. */
00126 #define PPPERR_PARAM        1  /* Invalid parameter. */
00127 #define PPPERR_OPEN         2  /* Unable to open PPP session. */
00128 #define PPPERR_DEVICE       3  /* Invalid I/O device for PPP. */
00129 #define PPPERR_ALLOC        4  /* Unable to allocate resources. */
00130 #define PPPERR_USER         5  /* User interrupt. */
00131 #define PPPERR_CONNECT      6  /* Connection lost. */
00132 #define PPPERR_AUTHFAIL     7  /* Failed authentication challenge. */
00133 #define PPPERR_PROTOCOL     8  /* Failed to meet protocol. */
00134 #define PPPERR_PEERDEAD     9  /* Connection timeout */
00135 #define PPPERR_IDLETIMEOUT  10 /* Idle Timeout */
00136 #define PPPERR_CONNECTTIME  11 /* Max connect time reached */
00137 #define PPPERR_LOOPBACK     12 /* Loopback detected */
00138 
00139 /* Whether auth support is enabled at all */
00140 #define PPP_AUTH_SUPPORT (PAP_SUPPORT || CHAP_SUPPORT || EAP_SUPPORT)
00141 
00142 /************************
00143 *** PUBLIC DATA TYPES ***
00144 ************************/
00145 
00146 /*
00147  * Other headers require ppp_pcb definition for prototypes, but ppp_pcb
00148  * require some structure definition from other headers as well, we are
00149  * fixing the dependency loop here by declaring the ppp_pcb type then
00150  * by including headers containing necessary struct definition for ppp_pcb
00151  */
00152 typedef struct ppp_pcb_s ppp_pcb;
00153 
00154 /* Type definitions for BSD code. */
00155 #ifndef __u_char_defined
00156 typedef unsigned long  u_long;
00157 typedef unsigned int   u_int;
00158 typedef unsigned short u_short;
00159 typedef unsigned char  u_char;
00160 #endif
00161 
00162 #include "fsm.h"
00163 #include "lcp.h"
00164 #if CCP_SUPPORT
00165 #include "ccp.h"
00166 #endif /* CCP_SUPPORT */
00167 #if MPPE_SUPPORT
00168 #include "mppe.h"
00169 #endif /* MPPE_SUPPORT */
00170 #if PPP_IPV4_SUPPORT
00171 #include "ipcp.h"
00172 #endif /* PPP_IPV4_SUPPORT */
00173 #if PPP_IPV6_SUPPORT
00174 #include "ipv6cp.h"
00175 #endif /* PPP_IPV6_SUPPORT */
00176 #if PAP_SUPPORT
00177 #include "upap.h"
00178 #endif /* PAP_SUPPORT */
00179 #if CHAP_SUPPORT
00180 #include "chap-new.h"
00181 #endif /* CHAP_SUPPORT */
00182 #if EAP_SUPPORT
00183 #include "eap.h"
00184 #endif /* EAP_SUPPORT */
00185 #if VJ_SUPPORT
00186 #include "vj.h"
00187 #endif /* VJ_SUPPORT */
00188 
00189 /* Link status callback function prototype */
00190 typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
00191 
00192 /*
00193  * PPP configuration.
00194  */
00195 typedef struct ppp_settings_s {
00196 
00197 #if PPP_SERVER && PPP_AUTH_SUPPORT
00198   unsigned int  auth_required       :1;      /* Peer is required to authenticate */
00199   unsigned int  null_login          :1;      /* Username of "" and a password of "" are acceptable */
00200 #endif /* PPP_SERVER && PPP_AUTH_SUPPORT */
00201 #if PPP_REMOTENAME
00202   unsigned int  explicit_remote     :1;      /* remote_name specified with remotename opt */
00203 #endif /* PPP_REMOTENAME */
00204 #if PAP_SUPPORT
00205   unsigned int  refuse_pap          :1;      /* Don't proceed auth. with PAP */
00206 #endif /* PAP_SUPPORT */
00207 #if CHAP_SUPPORT
00208   unsigned int  refuse_chap         :1;      /* Don't proceed auth. with CHAP */
00209 #endif /* CHAP_SUPPORT */
00210 #if MSCHAP_SUPPORT
00211   unsigned int  refuse_mschap       :1;      /* Don't proceed auth. with MS-CHAP */
00212   unsigned int  refuse_mschap_v2    :1;      /* Don't proceed auth. with MS-CHAPv2 */
00213 #endif /* MSCHAP_SUPPORT */
00214 #if EAP_SUPPORT
00215   unsigned int  refuse_eap          :1;      /* Don't proceed auth. with EAP */
00216 #endif /* EAP_SUPPORT */
00217 #if PPP_DNS
00218   unsigned int  usepeerdns          :1;      /* Ask peer for DNS adds */
00219 #endif /* PPP_DNS */
00220   unsigned int  persist             :1;      /* Persist mode, always try to open the connection */
00221 #if PRINTPKT_SUPPORT
00222   unsigned int  hide_password       :1;      /* Hide password in dumped packets */
00223 #endif /* PRINTPKT_SUPPORT */
00224   unsigned int  noremoteip          :1;      /* Let him have no IP address */
00225   unsigned int  lax_recv            :1;      /* accept control chars in asyncmap */
00226   unsigned int  noendpoint          :1;      /* don't send/accept endpoint discriminator */
00227 #if PPP_LCP_ADAPTIVE
00228   unsigned int lcp_echo_adaptive    :1;      /* request echo only if the link was idle */
00229 #endif /* PPP_LCP_ADAPTIVE */
00230 #if MPPE_SUPPORT
00231   unsigned int require_mppe         :1;      /* Require MPPE (Microsoft Point to Point Encryption) */
00232   unsigned int refuse_mppe_40       :1;      /* Allow MPPE 40-bit mode? */
00233   unsigned int refuse_mppe_128      :1;      /* Allow MPPE 128-bit mode? */
00234   unsigned int refuse_mppe_stateful :1;      /* Allow MPPE stateful mode? */
00235 #endif /* MPPE_SUPPORT */
00236 
00237   u16_t  listen_time;                 /* time to listen first (ms), waiting for peer to send LCP packet */
00238 
00239 #if PPP_IDLETIMELIMIT
00240   u16_t  idle_time_limit;             /* Disconnect if idle for this many seconds */
00241 #endif /* PPP_IDLETIMELIMIT */
00242 #if PPP_MAXCONNECT
00243   u32_t  maxconnect;                  /* Maximum connect time (seconds) */
00244 #endif /* PPP_MAXCONNECT */
00245 
00246 #if PPP_AUTH_SUPPORT
00247   /* auth data */
00248   const char  *user;                   /* Username for PAP */
00249   const char  *passwd;                 /* Password for PAP, secret for CHAP */
00250 #if PPP_REMOTENAME
00251   char  remote_name[MAXNAMELEN   + 1]; /* Peer's name for authentication */
00252 #endif /* PPP_REMOTENAME */
00253 
00254 #if PAP_SUPPORT
00255   u8_t  pap_timeout_time;        /* Timeout (seconds) for auth-req retrans. */
00256   u8_t  pap_max_transmits;       /* Number of auth-reqs sent */
00257 #if PPP_SERVER
00258   u8_t  pap_req_timeout;         /* Time to wait for auth-req from peer */
00259 #endif /* PPP_SERVER */
00260 #endif /* PAP_SUPPPORT */
00261 
00262 #if CHAP_SUPPORT
00263   u8_t  chap_timeout_time;       /* Timeout (seconds) for retransmitting req */
00264   u8_t  chap_max_transmits;      /* max # times to send challenge */
00265 #if PPP_SERVER
00266   u8_t  chap_rechallenge_time;   /* Time to wait for auth-req from peer */
00267 #endif /* PPP_SERVER */
00268 #endif /* CHAP_SUPPPORT */
00269 
00270 #if EAP_SUPPORT
00271   u8_t  eap_req_time;            /* Time to wait (for retransmit/fail) */
00272   u8_t  eap_allow_req;           /* Max Requests allowed */
00273 #if PPP_SERVER
00274   u8_t  eap_timeout_time;        /* Time to wait (for retransmit/fail) */
00275   u8_t  eap_max_transmits;       /* Max Requests allowed */
00276 #endif /* PPP_SERVER */
00277 #endif /* EAP_SUPPORT */
00278 
00279 #endif /* PPP_AUTH_SUPPORT */
00280 
00281   u8_t  fsm_timeout_time;            /* Timeout time in seconds */
00282   u8_t  fsm_max_conf_req_transmits;  /* Maximum Configure-Request transmissions */
00283   u8_t  fsm_max_term_transmits;      /* Maximum Terminate-Request transmissions */
00284   u8_t  fsm_max_nak_loops;           /* Maximum number of nak loops tolerated */
00285 
00286   u8_t  lcp_loopbackfail;     /* Number of times we receive our magic number from the peer
00287                                  before deciding the link is looped-back. */
00288   u8_t  lcp_echo_interval;    /* Interval between LCP echo-requests */
00289   u8_t  lcp_echo_fails;       /* Tolerance to unanswered echo-requests */
00290 
00291 } ppp_settings;
00292 
00293 #if PPP_SERVER
00294 struct ppp_addrs {
00295 #if PPP_IPV4_SUPPORT
00296   ip4_addr_t our_ipaddr, his_ipaddr, netmask;
00297 #if PPP_DNS
00298   ip4_addr_t dns1, dns2;
00299 #endif /* PPP_DNS */
00300 #endif /* PPP_IPV4_SUPPORT */
00301 #if PPP_IPV6_SUPPORT
00302   ip6_addr_t our6_ipaddr, his6_ipaddr;
00303 #endif /* PPP_IPV6_SUPPORT */
00304 };
00305 #endif /* PPP_SERVER */
00306 
00307 /*
00308  * PPP interface control block.
00309  */
00310 struct ppp_pcb_s {
00311   ppp_settings settings;
00312   const struct link_callbacks *link_cb;
00313   void *link_ctx_cb;
00314   void (*link_status_cb)(ppp_pcb *pcb, int err_code, void *ctx);  /* Status change callback */
00315 #if PPP_NOTIFY_PHASE
00316   void (*notify_phase_cb)(ppp_pcb *pcb, u8_t phase, void *ctx);   /* Notify phase callback */
00317 #endif /* PPP_NOTIFY_PHASE */
00318   void *ctx_cb;                  /* Callbacks optional pointer */
00319   struct netif *netif;           /* PPP interface */
00320   u8_t phase;                    /* where the link is at */
00321   u8_t err_code;                 /* Code indicating why interface is down. */
00322 
00323   /* flags */
00324 #if PPP_IPV4_SUPPORT
00325   unsigned int ask_for_local           :1; /* request our address from peer */
00326   unsigned int ipcp_is_open            :1; /* haven't called np_finished() */
00327   unsigned int ipcp_is_up              :1; /* have called ipcp_up() */
00328   unsigned int if4_up                  :1; /* True when the IPv4 interface is up. */
00329 #if 0 /* UNUSED - PROXY ARP */
00330   unsigned int proxy_arp_set           :1; /* Have created proxy arp entry */
00331 #endif /* UNUSED - PROXY ARP */
00332 #endif /* PPP_IPV4_SUPPORT */
00333 #if PPP_IPV6_SUPPORT
00334   unsigned int ipv6cp_is_up            :1; /* have called ip6cp_up() */
00335   unsigned int if6_up                  :1; /* True when the IPv6 interface is up. */
00336 #endif /* PPP_IPV6_SUPPORT */
00337 #if PPP_IPV4_SUPPORT && PPP_IPV6_SUPPORT
00338   unsigned int ipcp_disabled           :1; /* disable ipcp */
00339   unsigned int ipv6cp_disabled         :1; /* disable ipv6cp */
00340 #endif
00341   unsigned int lcp_echo_timer_running  :1; /* set if a timer is running */
00342 #if VJ_SUPPORT
00343   unsigned int vj_enabled              :1; /* Flag indicating VJ compression enabled. */
00344 #endif /* VJ_SUPPORT */
00345 #if CCP_SUPPORT
00346   unsigned int ccp_all_rejected        :1; /* we rejected all peer's options */
00347 #endif /* CCP_SUPPORT */
00348 #if MPPE_SUPPORT
00349   unsigned int mppe_keys_set           :1; /* Have the MPPE keys been set? */
00350 #endif /* MPPE_SUPPORT */
00351 
00352 #if PPP_AUTH_SUPPORT
00353   /* auth data */
00354 #if PPP_SERVER && defined(HAVE_MULTILINK)
00355   char peer_authname[MAXNAMELEN + 1]; /* The name by which the peer authenticated itself to us. */
00356 #endif /* PPP_SERVER && defined(HAVE_MULTILINK) */
00357   u16_t auth_pending;        /* Records which authentication operations haven't completed yet. */
00358   u16_t auth_done;           /* Records which authentication operations have been completed. */
00359 
00360 #if PAP_SUPPORT
00361   upap_state upap;           /* PAP data */
00362 #endif /* PAP_SUPPORT */
00363 
00364 #if CHAP_SUPPORT
00365   chap_client_state chap_client;  /* CHAP client data */
00366 #if PPP_SERVER
00367   chap_server_state chap_server;  /* CHAP server data */
00368 #endif /* PPP_SERVER */
00369 #endif /* CHAP_SUPPORT */
00370 
00371 #if EAP_SUPPORT
00372   eap_state eap;            /* EAP data */
00373 #endif /* EAP_SUPPORT */
00374 #endif /* PPP_AUTH_SUPPORT */
00375 
00376   fsm lcp_fsm;                   /* LCP fsm structure */
00377   lcp_options lcp_wantoptions;   /* Options that we want to request */
00378   lcp_options lcp_gotoptions;    /* Options that peer ack'd */
00379   lcp_options lcp_allowoptions;  /* Options we allow peer to request */
00380   lcp_options lcp_hisoptions;    /* Options that we ack'd */
00381   u16_t peer_mru;                /* currently negotiated peer MRU */
00382   u8_t lcp_echos_pending;        /* Number of outstanding echo msgs */
00383   u8_t lcp_echo_number;          /* ID number of next echo frame */
00384 
00385   u8_t num_np_open;              /* Number of network protocols which we have opened. */
00386   u8_t num_np_up;                /* Number of network protocols which have come up. */
00387 
00388 #if VJ_SUPPORT
00389   struct vjcompress vj_comp;     /* Van Jacobson compression header. */
00390 #endif /* VJ_SUPPORT */
00391 
00392 #if CCP_SUPPORT
00393   fsm ccp_fsm;                   /* CCP fsm structure */
00394   ccp_options ccp_wantoptions;   /* what to request the peer to use */
00395   ccp_options ccp_gotoptions;    /* what the peer agreed to do */
00396   ccp_options ccp_allowoptions;  /* what we'll agree to do */
00397   ccp_options ccp_hisoptions;    /* what we agreed to do */
00398   u8_t ccp_localstate;           /* Local state (mainly for handling reset-reqs and reset-acks). */
00399   u8_t ccp_receive_method;       /* Method chosen on receive path */
00400   u8_t ccp_transmit_method;      /* Method chosen on transmit path */
00401 #if MPPE_SUPPORT
00402   ppp_mppe_state mppe_comp;      /* MPPE "compressor" structure */
00403   ppp_mppe_state mppe_decomp;    /* MPPE "decompressor" structure */
00404 #endif /* MPPE_SUPPORT */
00405 #endif /* CCP_SUPPORT */
00406 
00407 #if PPP_IPV4_SUPPORT
00408   fsm ipcp_fsm;                   /* IPCP fsm structure */
00409   ipcp_options ipcp_wantoptions;  /* Options that we want to request */
00410   ipcp_options ipcp_gotoptions;   /* Options that peer ack'd */
00411   ipcp_options ipcp_allowoptions; /* Options we allow peer to request */
00412   ipcp_options ipcp_hisoptions;   /* Options that we ack'd */
00413 #endif /* PPP_IPV4_SUPPORT */
00414 
00415 #if PPP_IPV6_SUPPORT
00416   fsm ipv6cp_fsm;                     /* IPV6CP fsm structure */
00417   ipv6cp_options ipv6cp_wantoptions;  /* Options that we want to request */
00418   ipv6cp_options ipv6cp_gotoptions;   /* Options that peer ack'd */
00419   ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */
00420   ipv6cp_options ipv6cp_hisoptions;   /* Options that we ack'd */
00421 #endif /* PPP_IPV6_SUPPORT */
00422 };
00423 
00424 /************************
00425  *** PUBLIC FUNCTIONS ***
00426  ************************/
00427 
00428 /*
00429  * WARNING: For multi-threads environment, all ppp_set_* functions most
00430  * only be called while the PPP is in the dead phase (i.e. disconnected).
00431  */
00432 
00433 #if PPP_AUTH_SUPPORT
00434 /*
00435  * Set PPP authentication.
00436  *
00437  * Warning: Using PPPAUTHTYPE_ANY might have security consequences.
00438  * RFC 1994 says:
00439  *
00440  * In practice, within or associated with each PPP server, there is a
00441  * database which associates "user" names with authentication
00442  * information ("secrets").  It is not anticipated that a particular
00443  * named user would be authenticated by multiple methods.  This would
00444  * make the user vulnerable to attacks which negotiate the least secure
00445  * method from among a set (such as PAP rather than CHAP).  If the same
00446  * secret was used, PAP would reveal the secret to be used later with
00447  * CHAP.
00448  *
00449  * Instead, for each user name there should be an indication of exactly
00450  * one method used to authenticate that user name.  If a user needs to
00451  * make use of different authentication methods under different
00452  * circumstances, then distinct user names SHOULD be employed, each of
00453  * which identifies exactly one authentication method.
00454  *
00455  * Default is none auth type, unset (NULL) user and passwd.
00456  */
00457 #define PPPAUTHTYPE_NONE      0x00
00458 #define PPPAUTHTYPE_PAP       0x01
00459 #define PPPAUTHTYPE_CHAP      0x02
00460 #define PPPAUTHTYPE_MSCHAP    0x04
00461 #define PPPAUTHTYPE_MSCHAP_V2 0x08
00462 #define PPPAUTHTYPE_EAP       0x10
00463 #define PPPAUTHTYPE_ANY       0xff
00464 void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd);
00465 
00466 /*
00467  * If set, peer is required to authenticate. This is mostly necessary for PPP server support.
00468  *
00469  * Default is false.
00470  */
00471 #define ppp_set_auth_required(ppp, boolval) (ppp->settings.auth_required = boolval)
00472 #endif /* PPP_AUTH_SUPPORT */
00473 
00474 #if PPP_IPV4_SUPPORT
00475 /*
00476  * Set PPP interface "our" and "his" IPv4 addresses. This is mostly necessary for PPP server
00477  * support but it can also be used on a PPP link where each side choose its own IP address.
00478  *
00479  * Default is unset (0.0.0.0).
00480  */
00481 #define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \
00482                                              ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0)
00483 #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr))
00484 #if PPP_DNS
00485 /*
00486  * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary
00487  * for PPP server support.
00488  *
00489  * Default is unset (0.0.0.0).
00490  */
00491 #define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr))
00492 
00493 /*
00494  * If set, we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are
00495  * registered using the dns_setserver() function.
00496  *
00497  * Default is false.
00498  */
00499 #define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval)
00500 #endif /* PPP_DNS */
00501 #endif /* PPP_IPV4_SUPPORT */
00502 
00503 #if MPPE_SUPPORT
00504 /* Disable MPPE (Microsoft Point to Point Encryption). This parameter is exclusive. */
00505 #define PPP_MPPE_DISABLE           0x00
00506 /* Require the use of MPPE (Microsoft Point to Point Encryption). */
00507 #define PPP_MPPE_ENABLE            0x01
00508 /* Allow MPPE to use stateful mode. Stateless mode is still attempted first. */
00509 #define PPP_MPPE_ALLOW_STATEFUL    0x02
00510 /* Refuse the use of MPPE with 40-bit encryption. Conflict with PPP_MPPE_REFUSE_128. */
00511 #define PPP_MPPE_REFUSE_40         0x04
00512 /* Refuse the use of MPPE with 128-bit encryption. Conflict with PPP_MPPE_REFUSE_40. */
00513 #define PPP_MPPE_REFUSE_128        0x08
00514 /*
00515  * Set MPPE configuration
00516  *
00517  * Default is disabled.
00518  */
00519 void ppp_set_mppe(ppp_pcb *pcb, u8_t flags);
00520 #endif /* MPPE_SUPPORT */
00521 
00522 /*
00523  * Wait for up to intval milliseconds for a valid PPP packet from the peer.
00524  * At the end of this  time, or when a valid PPP packet is received from the
00525  * peer, we commence negotiation by sending our first LCP packet.
00526  *
00527  * Default is 0.
00528  */
00529 #define ppp_set_listen_time(ppp, intval) (ppp->settings.listen_time = intval)
00530 
00531 /*
00532  * If set, we will attempt to initiate a connection but if no reply is received from
00533  * the peer, we will then just wait passively for a valid LCP packet from the peer.
00534  *
00535  * Default is false.
00536  */
00537 #define ppp_set_passive(ppp, boolval) (ppp->lcp_wantoptions.passive = boolval)
00538 
00539 /*
00540  * If set, we will not transmit LCP packets to initiate a connection until a valid
00541  * LCP packet is received from the peer. This is what we usually call the server mode.
00542  *
00543  * Default is false.
00544  */
00545 #define ppp_set_silent(ppp, boolval) (ppp->lcp_wantoptions.silent = boolval)
00546 
00547 /*
00548  * If set, enable protocol field compression negotiation in both the receive and
00549  * the transmit direction.
00550  *
00551  * Default is true.
00552  */
00553 #define ppp_set_neg_pcomp(ppp, boolval) (ppp->lcp_wantoptions.neg_pcompression = \
00554                                          ppp->lcp_allowoptions.neg_pcompression = boolval)
00555 
00556 /*
00557  * If set, enable Address/Control compression in both the receive and the transmit
00558  * direction.
00559  *
00560  * Default is true.
00561  */
00562 #define ppp_set_neg_accomp(ppp, boolval) (ppp->lcp_wantoptions.neg_accompression = \
00563                                           ppp->lcp_allowoptions.neg_accompression = boolval)
00564 
00565 /*
00566  * If set, enable asyncmap negotiation. Otherwise forcing all control characters to
00567  * be escaped for both the transmit and the receive direction.
00568  *
00569  * Default is true.
00570  */
00571 #define ppp_set_neg_asyncmap(ppp, boolval) (ppp->lcp_wantoptions.neg_asyncmap = \
00572                                             ppp->lcp_allowoptions.neg_asyncmap = boolval)
00573 
00574 /*
00575  * This option sets the Async-Control-Character-Map (ACCM) for this end of the link.
00576  * The ACCM is a set of 32 bits, one for each of the ASCII control characters with
00577  * values from 0 to 31, where a 1 bit  indicates that the corresponding control
00578  * character should not be used in PPP packets sent to this system. The map is
00579  * an unsigned 32 bits integer where the least significant bit (00000001) represents
00580  * character 0 and the most significant bit (80000000) represents character 31.
00581  * We will then ask the peer to send these characters as a 2-byte escape sequence.
00582  *
00583  * Default is 0.
00584  */
00585 #define ppp_set_asyncmap(ppp, intval) (ppp->lcp_wantoptions.asyncmap = intval)
00586 
00587 /*
00588  * Set a PPP interface as the default network interface
00589  * (used to output all packets for which no specific route is found).
00590  */
00591 #define ppp_set_default(ppp)         netif_set_default(ppp->netif)
00592 
00593 #if PPP_NOTIFY_PHASE
00594 /*
00595  * Set a PPP notify phase callback.
00596  *
00597  * This can be used for example to set a LED pattern depending on the
00598  * current phase of the PPP session.
00599  */
00600 typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx);
00601 void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb);
00602 #endif /* PPP_NOTIFY_PHASE */
00603 
00604 /*
00605  * Initiate a PPP connection.
00606  *
00607  * This can only be called if PPP is in the dead phase.
00608  *
00609  * Holdoff is the time to wait (in seconds) before initiating
00610  * the connection.
00611  *
00612  * If this port connects to a modem, the modem connection must be
00613  * established before calling this.
00614  */
00615 err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff);
00616 
00617 #if PPP_SERVER
00618 /*
00619  * Listen for an incoming PPP connection.
00620  *
00621  * This can only be called if PPP is in the dead phase.
00622  *
00623  * If this port connects to a modem, the modem connection must be
00624  * established before calling this.
00625  */
00626 err_t ppp_listen(ppp_pcb *pcb);
00627 #endif /* PPP_SERVER */
00628 
00629 /*
00630  * Initiate the end of a PPP connection.
00631  * Any outstanding packets in the queues are dropped.
00632  *
00633  * Setting nocarrier to 1 close the PPP connection without initiating the
00634  * shutdown procedure. Always using nocarrier = 0 is still recommended,
00635  * this is going to take a little longer time if your link is down, but
00636  * is a safer choice for the PPP state machine.
00637  *
00638  * Return 0 on success, an error code on failure.
00639  */
00640 err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier);
00641 
00642 /*
00643  * Release the control block.
00644  *
00645  * This can only be called if PPP is in the dead phase.
00646  *
00647  * You must use ppp_close() before if you wish to terminate
00648  * an established PPP session.
00649  *
00650  * Return 0 on success, an error code on failure.
00651  */
00652 err_t ppp_free(ppp_pcb *pcb);
00653 
00654 /*
00655  * PPP IOCTL commands.
00656  *
00657  * Get the up status - 0 for down, non-zero for up.  The argument must
00658  * point to an int.
00659  */
00660 #define PPPCTLG_UPSTATUS 0
00661 
00662 /*
00663  * Get the PPP error code.  The argument must point to an int.
00664  * Returns a PPPERR_* value.
00665  */
00666 #define PPPCTLG_ERRCODE  1
00667 
00668 /*
00669  * Get the fd associated with a PPP over serial
00670  */
00671 #define PPPCTLG_FD       2
00672 
00673 /*
00674  * Get and set parameters for the given connection.
00675  * Return 0 on success, an error code on failure.
00676  */
00677 err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg);
00678 
00679 /* Get the PPP netif interface */
00680 #define ppp_netif(ppp)               (ppp->netif)
00681 
00682 /* Set a status-callback for the selected PPP device */
00683 #define ppp_set_netif_statuscallback(ppp, status_cb)       \
00684         netif_set_status_callback(ppp->netif, status_cb);
00685 
00686 /* Set a link-callback for the selected PPP device */
00687 #define ppp_set_netif_linkcallback(ppp, link_cb)           \
00688         netif_set_link_callback(ppp->netif, link_cb);
00689 
00690 #ifdef __cplusplus
00691 }
00692 #endif
00693 
00694 #endif /* PPP_H */
00695 
00696 #endif /* PPP_SUPPORT */