Daiki Kato / mbed-os-lychee

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

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_MASTER        1
00114 #define PPP_PHASE_HOLDOFF       2
00115 #define PPP_PHASE_INITIALIZE    3
00116 #define PPP_PHASE_SERIALCONN    4
00117 #define PPP_PHASE_DORMANT       5
00118 #define PPP_PHASE_ESTABLISH     6
00119 #define PPP_PHASE_AUTHENTICATE  7
00120 #define PPP_PHASE_CALLBACK      8
00121 #define PPP_PHASE_NETWORK       9
00122 #define PPP_PHASE_RUNNING       10
00123 #define PPP_PHASE_TERMINATE     11
00124 #define PPP_PHASE_DISCONNECT    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 ask_for_local           :1; /* request our address from peer */
00328   unsigned int ipcp_is_open            :1; /* haven't called np_finished() */
00329   unsigned int ipcp_is_up              :1; /* have called ipcp_up() */
00330   unsigned int if4_up                  :1; /* True when the IPv4 interface is up. */
00331 #if 0 /* UNUSED - PROXY ARP */
00332   unsigned int proxy_arp_set           :1; /* Have created proxy arp entry */
00333 #endif /* UNUSED - PROXY ARP */
00334 #endif /* PPP_IPV4_SUPPORT */
00335 #if PPP_IPV6_SUPPORT
00336   unsigned int ipv6cp_is_up            :1; /* have called ip6cp_up() */
00337   unsigned int if6_up                  :1; /* True when the IPv6 interface is up. */
00338 #endif /* PPP_IPV6_SUPPORT */
00339   unsigned int lcp_echo_timer_running  :1; /* set if a timer is running */
00340 #if VJ_SUPPORT
00341   unsigned int vj_enabled              :1; /* Flag indicating VJ compression enabled. */
00342 #endif /* VJ_SUPPORT */
00343 #if CCP_SUPPORT
00344   unsigned int ccp_all_rejected        :1; /* we rejected all peer's options */
00345 #endif /* CCP_SUPPORT */
00346 #if MPPE_SUPPORT
00347   unsigned int mppe_keys_set           :1; /* Have the MPPE keys been set? */
00348 #endif /* MPPE_SUPPORT */
00349 
00350 #if PPP_AUTH_SUPPORT
00351   /* auth data */
00352 #if PPP_SERVER && defined(HAVE_MULTILINK)
00353   char peer_authname[MAXNAMELEN + 1]; /* The name by which the peer authenticated itself to us. */
00354 #endif /* PPP_SERVER && defined(HAVE_MULTILINK) */
00355   u16_t auth_pending;        /* Records which authentication operations haven't completed yet. */
00356   u16_t auth_done;           /* Records which authentication operations have been completed. */
00357 
00358 #if PAP_SUPPORT
00359   upap_state upap;           /* PAP data */
00360 #endif /* PAP_SUPPORT */
00361 
00362 #if CHAP_SUPPORT
00363   chap_client_state chap_client;  /* CHAP client data */
00364 #if PPP_SERVER
00365   chap_server_state chap_server;  /* CHAP server data */
00366 #endif /* PPP_SERVER */
00367 #endif /* CHAP_SUPPORT */
00368 
00369 #if EAP_SUPPORT
00370   eap_state eap;            /* EAP data */
00371 #endif /* EAP_SUPPORT */
00372 #endif /* PPP_AUTH_SUPPORT */
00373 
00374   fsm lcp_fsm;                   /* LCP fsm structure */
00375   lcp_options lcp_wantoptions;   /* Options that we want to request */
00376   lcp_options lcp_gotoptions;    /* Options that peer ack'd */
00377   lcp_options lcp_allowoptions;  /* Options we allow peer to request */
00378   lcp_options lcp_hisoptions;    /* Options that we ack'd */
00379   u16_t peer_mru;                /* currently negotiated peer MRU */
00380   u8_t lcp_echos_pending;        /* Number of outstanding echo msgs */
00381   u8_t lcp_echo_number;          /* ID number of next echo frame */
00382 
00383   u8_t num_np_open;              /* Number of network protocols which we have opened. */
00384   u8_t num_np_up;                /* Number of network protocols which have come up. */
00385 
00386 #if VJ_SUPPORT
00387   struct vjcompress vj_comp;     /* Van Jacobson compression header. */
00388 #endif /* VJ_SUPPORT */
00389 
00390 #if CCP_SUPPORT
00391   fsm ccp_fsm;                   /* CCP fsm structure */
00392   ccp_options ccp_wantoptions;   /* what to request the peer to use */
00393   ccp_options ccp_gotoptions;    /* what the peer agreed to do */
00394   ccp_options ccp_allowoptions;  /* what we'll agree to do */
00395   ccp_options ccp_hisoptions;    /* what we agreed to do */
00396   u8_t ccp_localstate;           /* Local state (mainly for handling reset-reqs and reset-acks). */
00397   u8_t ccp_receive_method;       /* Method chosen on receive path */
00398   u8_t ccp_transmit_method;      /* Method chosen on transmit path */
00399 #if MPPE_SUPPORT
00400   ppp_mppe_state mppe_comp;      /* MPPE "compressor" structure */
00401   ppp_mppe_state mppe_decomp;    /* MPPE "decompressor" structure */
00402 #endif /* MPPE_SUPPORT */
00403 #endif /* CCP_SUPPORT */
00404 
00405 #if PPP_IPV4_SUPPORT
00406   fsm ipcp_fsm;                   /* IPCP fsm structure */
00407   ipcp_options ipcp_wantoptions;  /* Options that we want to request */
00408   ipcp_options ipcp_gotoptions;   /* Options that peer ack'd */
00409   ipcp_options ipcp_allowoptions; /* Options we allow peer to request */
00410   ipcp_options ipcp_hisoptions;   /* Options that we ack'd */
00411 #endif /* PPP_IPV4_SUPPORT */
00412 
00413 #if PPP_IPV6_SUPPORT
00414   fsm ipv6cp_fsm;                     /* IPV6CP fsm structure */
00415   ipv6cp_options ipv6cp_wantoptions;  /* Options that we want to request */
00416   ipv6cp_options ipv6cp_gotoptions;   /* Options that peer ack'd */
00417   ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */
00418   ipv6cp_options ipv6cp_hisoptions;   /* Options that we ack'd */
00419 #endif /* PPP_IPV6_SUPPORT */
00420 };
00421 
00422 /************************
00423  *** PUBLIC FUNCTIONS ***
00424  ************************/
00425 
00426 /*
00427  * WARNING: For multi-threads environment, all ppp_set_* functions most
00428  * only be called while the PPP is in the dead phase (i.e. disconnected).
00429  */
00430 
00431 #if PPP_AUTH_SUPPORT
00432 /*
00433  * Set PPP authentication.
00434  *
00435  * Warning: Using PPPAUTHTYPE_ANY might have security consequences.
00436  * RFC 1994 says:
00437  *
00438  * In practice, within or associated with each PPP server, there is a
00439  * database which associates "user" names with authentication
00440  * information ("secrets").  It is not anticipated that a particular
00441  * named user would be authenticated by multiple methods.  This would
00442  * make the user vulnerable to attacks which negotiate the least secure
00443  * method from among a set (such as PAP rather than CHAP).  If the same
00444  * secret was used, PAP would reveal the secret to be used later with
00445  * CHAP.
00446  *
00447  * Instead, for each user name there should be an indication of exactly
00448  * one method used to authenticate that user name.  If a user needs to
00449  * make use of different authentication methods under different
00450  * circumstances, then distinct user names SHOULD be employed, each of
00451  * which identifies exactly one authentication method.
00452  *
00453  * Default is none auth type, unset (NULL) user and passwd.
00454  */
00455 #define PPPAUTHTYPE_NONE      0x00
00456 #define PPPAUTHTYPE_PAP       0x01
00457 #define PPPAUTHTYPE_CHAP      0x02
00458 #define PPPAUTHTYPE_MSCHAP    0x04
00459 #define PPPAUTHTYPE_MSCHAP_V2 0x08
00460 #define PPPAUTHTYPE_EAP       0x10
00461 #define PPPAUTHTYPE_ANY       0xff
00462 void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd);
00463 
00464 /*
00465  * If set, peer is required to authenticate. This is mostly necessary for PPP server support.
00466  *
00467  * Default is false.
00468  */
00469 #define ppp_set_auth_required(ppp, boolval) (ppp->settings.auth_required = boolval)
00470 #endif /* PPP_AUTH_SUPPORT */
00471 
00472 #if PPP_IPV4_SUPPORT
00473 /*
00474  * Set PPP interface "our" and "his" IPv4 addresses. This is mostly necessary for PPP server
00475  * support but it can also be used on a PPP link where each side choose its own IP address.
00476  *
00477  * Default is unset (0.0.0.0).
00478  */
00479 #define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \
00480                                              ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0)
00481 #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr))
00482 #if LWIP_DNS
00483 /*
00484  * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary
00485  * for PPP server support.
00486  *
00487  * Default is unset (0.0.0.0).
00488  */
00489 #define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr))
00490 
00491 /*
00492  * If set, we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are
00493  * registered using the dns_setserver() function.
00494  *
00495  * Default is false.
00496  */
00497 #define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval)
00498 #endif /* LWIP_DNS */
00499 #endif /* PPP_IPV4_SUPPORT */
00500 
00501 #if MPPE_SUPPORT
00502 /* Disable MPPE (Microsoft Point to Point Encryption). This parameter is exclusive. */
00503 #define PPP_MPPE_DISABLE           0x00
00504 /* Require the use of MPPE (Microsoft Point to Point Encryption). */
00505 #define PPP_MPPE_ENABLE            0x01
00506 /* Allow MPPE to use stateful mode. Stateless mode is still attempted first. */
00507 #define PPP_MPPE_ALLOW_STATEFUL    0x02
00508 /* Refuse the use of MPPE with 40-bit encryption. Conflict with PPP_MPPE_REFUSE_128. */
00509 #define PPP_MPPE_REFUSE_40         0x04
00510 /* Refuse the use of MPPE with 128-bit encryption. Conflict with PPP_MPPE_REFUSE_40. */
00511 #define PPP_MPPE_REFUSE_128        0x08
00512 /*
00513  * Set MPPE configuration
00514  *
00515  * Default is disabled.
00516  */
00517 void ppp_set_mppe(ppp_pcb *pcb, u8_t flags);
00518 #endif /* MPPE_SUPPORT */
00519 
00520 /*
00521  * Wait for up to intval milliseconds for a valid PPP packet from the peer.
00522  * At the end of this  time, or when a valid PPP packet is received from the
00523  * peer, we commence negotiation by sending our first LCP packet.
00524  *
00525  * Default is 0.
00526  */
00527 #define ppp_set_listen_time(ppp, intval) (ppp->settings.listen_time = intval)
00528 
00529 /*
00530  * If set, we will attempt to initiate a connection but if no reply is received from
00531  * the peer, we will then just wait passively for a valid LCP packet from the peer.
00532  *
00533  * Default is false.
00534  */
00535 #define ppp_set_passive(ppp, boolval) (ppp->lcp_wantoptions.passive = boolval)
00536 
00537 /*
00538  * If set, we will not transmit LCP packets to initiate a connection until a valid
00539  * LCP packet is received from the peer. This is what we usually call the server mode.
00540  *
00541  * Default is false.
00542  */
00543 #define ppp_set_silent(ppp, boolval) (ppp->lcp_wantoptions.silent = boolval)
00544 
00545 /*
00546  * If set, enable protocol field compression negotiation in both the receive and
00547  * the transmit direction.
00548  *
00549  * Default is true.
00550  */
00551 #define ppp_set_neg_pcomp(ppp, boolval) (ppp->lcp_wantoptions.neg_pcompression = \
00552                                          ppp->lcp_allowoptions.neg_pcompression = boolval)
00553 
00554 /*
00555  * If set, enable Address/Control compression in both the receive and the transmit
00556  * direction.
00557  *
00558  * Default is true.
00559  */
00560 #define ppp_set_neg_accomp(ppp, boolval) (ppp->lcp_wantoptions.neg_accompression = \
00561                                           ppp->lcp_allowoptions.neg_accompression = boolval)
00562 
00563 /*
00564  * If set, enable asyncmap negotiation. Otherwise forcing all control characters to
00565  * be escaped for both the transmit and the receive direction.
00566  *
00567  * Default is true.
00568  */
00569 #define ppp_set_neg_asyncmap(ppp, boolval) (ppp->lcp_wantoptions.neg_asyncmap = \
00570                                             ppp->lcp_allowoptions.neg_asyncmap = boolval)
00571 
00572 /*
00573  * This option sets the Async-Control-Character-Map (ACCM) for this end of the link.
00574  * The ACCM is a set of 32 bits, one for each of the ASCII control characters with
00575  * values from 0 to 31, where a 1 bit  indicates that the corresponding control
00576  * character should not be used in PPP packets sent to this system. The map is
00577  * an unsigned 32 bits integer where the least significant bit (00000001) represents
00578  * character 0 and the most significant bit (80000000) represents character 31.
00579  * We will then ask the peer to send these characters as a 2-byte escape sequence.
00580  *
00581  * Default is 0.
00582  */
00583 #define ppp_set_asyncmap(ppp, intval) (ppp->lcp_wantoptions.asyncmap = intval)
00584 
00585 /*
00586  * Set a PPP interface as the default network interface
00587  * (used to output all packets for which no specific route is found).
00588  */
00589 #define ppp_set_default(ppp)         netif_set_default(ppp->netif)
00590 
00591 #if PPP_NOTIFY_PHASE
00592 /*
00593  * Set a PPP notify phase callback.
00594  *
00595  * This can be used for example to set a LED pattern depending on the
00596  * current phase of the PPP session.
00597  */
00598 typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx);
00599 void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb);
00600 #endif /* PPP_NOTIFY_PHASE */
00601 
00602 /*
00603  * Initiate a PPP connection.
00604  *
00605  * This can only be called if PPP is in the dead phase.
00606  *
00607  * Holdoff is the time to wait (in seconds) before initiating
00608  * the connection.
00609  *
00610  * If this port connects to a modem, the modem connection must be
00611  * established before calling this.
00612  */
00613 err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff);
00614 
00615 #if PPP_SERVER
00616 /*
00617  * Listen for an incoming PPP connection.
00618  *
00619  * This can only be called if PPP is in the dead phase.
00620  *
00621  * If this port connects to a modem, the modem connection must be
00622  * established before calling this.
00623  */
00624 err_t ppp_listen(ppp_pcb *pcb);
00625 #endif /* PPP_SERVER */
00626 
00627 /*
00628  * Initiate the end of a PPP connection.
00629  * Any outstanding packets in the queues are dropped.
00630  *
00631  * Setting nocarrier to 1 close the PPP connection without initiating the
00632  * shutdown procedure. Always using nocarrier = 0 is still recommended,
00633  * this is going to take a little longer time if your link is down, but
00634  * is a safer choice for the PPP state machine.
00635  *
00636  * Return 0 on success, an error code on failure.
00637  */
00638 err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier);
00639 
00640 /*
00641  * Release the control block.
00642  *
00643  * This can only be called if PPP is in the dead phase.
00644  *
00645  * You must use ppp_close() before if you wish to terminate
00646  * an established PPP session.
00647  *
00648  * Return 0 on success, an error code on failure.
00649  */
00650 err_t ppp_free(ppp_pcb *pcb);
00651 
00652 /*
00653  * PPP IOCTL commands.
00654  *
00655  * Get the up status - 0 for down, non-zero for up.  The argument must
00656  * point to an int.
00657  */
00658 #define PPPCTLG_UPSTATUS 0
00659 
00660 /*
00661  * Get the PPP error code.  The argument must point to an int.
00662  * Returns a PPPERR_* value.
00663  */
00664 #define PPPCTLG_ERRCODE  1
00665 
00666 /*
00667  * Get the fd associated with a PPP over serial
00668  */
00669 #define PPPCTLG_FD       2
00670 
00671 /*
00672  * Get and set parameters for the given connection.
00673  * Return 0 on success, an error code on failure.
00674  */
00675 err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg);
00676 
00677 /* Get the PPP netif interface */
00678 #define ppp_netif(ppp)               (ppp->netif)
00679 
00680 /* Set an lwIP-style status-callback for the selected PPP device */
00681 #define ppp_set_netif_statuscallback(ppp, status_cb)       \
00682         netif_set_status_callback(ppp->netif, status_cb);
00683 
00684 /* Set an lwIP-style link-callback for the selected PPP device */
00685 #define ppp_set_netif_linkcallback(ppp, link_cb)           \
00686         netif_set_link_callback(ppp->netif, link_cb);
00687 
00688 #endif /* PPP_H */
00689 
00690 #endif /* PPP_SUPPORT */