Simon Cooksey / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ppp.h Source File

ppp.h

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