mbed-os for GR-LYCHEE

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

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 PPP interface for lwIP
dkato 0:f782d9c66c49 2
dkato 0:f782d9c66c49 3 Author: Sylvain Rochet
dkato 0:f782d9c66c49 4
dkato 0:f782d9c66c49 5 Table of Contents:
dkato 0:f782d9c66c49 6
dkato 0:f782d9c66c49 7 1 - Supported PPP protocols and features
dkato 0:f782d9c66c49 8 2 - Raw API PPP example for all protocols
dkato 0:f782d9c66c49 9 3 - PPPoS input path (raw API, IRQ safe API, TCPIP API)
dkato 0:f782d9c66c49 10 4 - Thread safe PPP API (PPPAPI)
dkato 0:f782d9c66c49 11 5 - Notify phase callback (PPP_NOTIFY_PHASE)
dkato 0:f782d9c66c49 12 6 - Upgrading from lwIP <= 1.4.x to lwIP >= 2.0.x
dkato 0:f782d9c66c49 13
dkato 0:f782d9c66c49 14
dkato 0:f782d9c66c49 15
dkato 0:f782d9c66c49 16 1 Supported PPP protocols and features
dkato 0:f782d9c66c49 17 ======================================
dkato 0:f782d9c66c49 18
dkato 0:f782d9c66c49 19 Supported Low level protocols:
dkato 0:f782d9c66c49 20 * PPP over serial using HDLC-like framing, such as wired dialup modems
dkato 0:f782d9c66c49 21 or mobile telecommunications GPRS/EDGE/UMTS/HSPA+/LTE modems
dkato 0:f782d9c66c49 22 * PPP over Ethernet, such as xDSL modems
dkato 0:f782d9c66c49 23 * PPP over L2TP (Layer 2 Tunneling Protocol) LAC (L2TP Access Concentrator),
dkato 0:f782d9c66c49 24 IP tunnel over UDP, such as VPN access
dkato 0:f782d9c66c49 25
dkato 0:f782d9c66c49 26 Supported auth protocols:
dkato 0:f782d9c66c49 27 * PAP, Password Authentication Protocol
dkato 0:f782d9c66c49 28 * CHAP, Challenge-Handshake Authentication Protocol, also known as CHAP-MD5
dkato 0:f782d9c66c49 29 * MSCHAPv1, Microsoft version of CHAP, version 1
dkato 0:f782d9c66c49 30 * MSCHAPv2, Microsoft version of CHAP, version 2
dkato 0:f782d9c66c49 31 * EAP, Extensible Authentication Protocol
dkato 0:f782d9c66c49 32
dkato 0:f782d9c66c49 33 Supported address protocols:
dkato 0:f782d9c66c49 34 * IPCP, IP Control Protocol, IPv4 addresses negotiation
dkato 0:f782d9c66c49 35 * IP6CP, IPv6 Control Protocol, IPv6 link-local addresses negotiation
dkato 0:f782d9c66c49 36
dkato 0:f782d9c66c49 37 Supported encryption protocols:
dkato 0:f782d9c66c49 38 * MPPE, Microsoft Point-to-Point Encryption
dkato 0:f782d9c66c49 39
dkato 0:f782d9c66c49 40 Supported compression or miscellaneous protocols, for serial links only:
dkato 0:f782d9c66c49 41 * PFC, Protocol Field Compression
dkato 0:f782d9c66c49 42 * ACFC, Address-and-Control-Field-Compression
dkato 0:f782d9c66c49 43 * ACCM, Asynchronous-Control-Character-Map
dkato 0:f782d9c66c49 44 * VJ, Van Jacobson TCP/IP Header Compression
dkato 0:f782d9c66c49 45
dkato 0:f782d9c66c49 46
dkato 0:f782d9c66c49 47
dkato 0:f782d9c66c49 48 2 Raw API PPP example for all protocols
dkato 0:f782d9c66c49 49 =======================================
dkato 0:f782d9c66c49 50
dkato 0:f782d9c66c49 51 As usual, raw API for lwIP means the lightweight API which *MUST* only be used
dkato 0:f782d9c66c49 52 for NO_SYS=1 systems or called inside lwIP core thread for NO_SYS=0 systems.
dkato 0:f782d9c66c49 53
dkato 0:f782d9c66c49 54 /*
dkato 0:f782d9c66c49 55 * Globals
dkato 0:f782d9c66c49 56 * =======
dkato 0:f782d9c66c49 57 */
dkato 0:f782d9c66c49 58
dkato 0:f782d9c66c49 59 /* The PPP control block */
dkato 0:f782d9c66c49 60 ppp_pcb *ppp;
dkato 0:f782d9c66c49 61
dkato 0:f782d9c66c49 62 /* The PPP IP interface */
dkato 0:f782d9c66c49 63 struct netif ppp_netif;
dkato 0:f782d9c66c49 64
dkato 0:f782d9c66c49 65
dkato 0:f782d9c66c49 66 /*
dkato 0:f782d9c66c49 67 * PPP status callback
dkato 0:f782d9c66c49 68 * ===================
dkato 0:f782d9c66c49 69 *
dkato 0:f782d9c66c49 70 * PPP status callback is called on PPP status change (up, down, …) from lwIP
dkato 0:f782d9c66c49 71 * core thread
dkato 0:f782d9c66c49 72 */
dkato 0:f782d9c66c49 73
dkato 0:f782d9c66c49 74 /* PPP status callback example */
dkato 0:f782d9c66c49 75 static void status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
dkato 0:f782d9c66c49 76 struct netif *pppif = ppp_netif(pcb);
dkato 0:f782d9c66c49 77 LWIP_UNUSED_ARG(ctx);
dkato 0:f782d9c66c49 78
dkato 0:f782d9c66c49 79 switch(err_code) {
dkato 0:f782d9c66c49 80 case PPPERR_NONE: {
dkato 0:f782d9c66c49 81 #if LWIP_DNS
dkato 0:f782d9c66c49 82 const ip_addr_t *ns;
dkato 0:f782d9c66c49 83 #endif /* LWIP_DNS */
dkato 0:f782d9c66c49 84 printf("status_cb: Connected\n");
dkato 0:f782d9c66c49 85 #if PPP_IPV4_SUPPORT
dkato 0:f782d9c66c49 86 printf(" our_ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr));
dkato 0:f782d9c66c49 87 printf(" his_ipaddr = %s\n", ipaddr_ntoa(&pppif->gw));
dkato 0:f782d9c66c49 88 printf(" netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
dkato 0:f782d9c66c49 89 #if LWIP_DNS
dkato 0:f782d9c66c49 90 ns = dns_getserver(0);
dkato 0:f782d9c66c49 91 printf(" dns1 = %s\n", ipaddr_ntoa(ns));
dkato 0:f782d9c66c49 92 ns = dns_getserver(1);
dkato 0:f782d9c66c49 93 printf(" dns2 = %s\n", ipaddr_ntoa(ns));
dkato 0:f782d9c66c49 94 #endif /* LWIP_DNS */
dkato 0:f782d9c66c49 95 #endif /* PPP_IPV4_SUPPORT */
dkato 0:f782d9c66c49 96 #if PPP_IPV6_SUPPORT
dkato 0:f782d9c66c49 97 printf(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
dkato 0:f782d9c66c49 98 #endif /* PPP_IPV6_SUPPORT */
dkato 0:f782d9c66c49 99 break;
dkato 0:f782d9c66c49 100 }
dkato 0:f782d9c66c49 101 case PPPERR_PARAM: {
dkato 0:f782d9c66c49 102 printf("status_cb: Invalid parameter\n");
dkato 0:f782d9c66c49 103 break;
dkato 0:f782d9c66c49 104 }
dkato 0:f782d9c66c49 105 case PPPERR_OPEN: {
dkato 0:f782d9c66c49 106 printf("status_cb: Unable to open PPP session\n");
dkato 0:f782d9c66c49 107 break;
dkato 0:f782d9c66c49 108 }
dkato 0:f782d9c66c49 109 case PPPERR_DEVICE: {
dkato 0:f782d9c66c49 110 printf("status_cb: Invalid I/O device for PPP\n");
dkato 0:f782d9c66c49 111 break;
dkato 0:f782d9c66c49 112 }
dkato 0:f782d9c66c49 113 case PPPERR_ALLOC: {
dkato 0:f782d9c66c49 114 printf("status_cb: Unable to allocate resources\n");
dkato 0:f782d9c66c49 115 break;
dkato 0:f782d9c66c49 116 }
dkato 0:f782d9c66c49 117 case PPPERR_USER: {
dkato 0:f782d9c66c49 118 printf("status_cb: User interrupt\n");
dkato 0:f782d9c66c49 119 break;
dkato 0:f782d9c66c49 120 }
dkato 0:f782d9c66c49 121 case PPPERR_CONNECT: {
dkato 0:f782d9c66c49 122 printf("status_cb: Connection lost\n");
dkato 0:f782d9c66c49 123 break;
dkato 0:f782d9c66c49 124 }
dkato 0:f782d9c66c49 125 case PPPERR_AUTHFAIL: {
dkato 0:f782d9c66c49 126 printf("status_cb: Failed authentication challenge\n");
dkato 0:f782d9c66c49 127 break;
dkato 0:f782d9c66c49 128 }
dkato 0:f782d9c66c49 129 case PPPERR_PROTOCOL: {
dkato 0:f782d9c66c49 130 printf("status_cb: Failed to meet protocol\n");
dkato 0:f782d9c66c49 131 break;
dkato 0:f782d9c66c49 132 }
dkato 0:f782d9c66c49 133 case PPPERR_PEERDEAD: {
dkato 0:f782d9c66c49 134 printf("status_cb: Connection timeout\n");
dkato 0:f782d9c66c49 135 break;
dkato 0:f782d9c66c49 136 }
dkato 0:f782d9c66c49 137 case PPPERR_IDLETIMEOUT: {
dkato 0:f782d9c66c49 138 printf("status_cb: Idle Timeout\n");
dkato 0:f782d9c66c49 139 break;
dkato 0:f782d9c66c49 140 }
dkato 0:f782d9c66c49 141 case PPPERR_CONNECTTIME: {
dkato 0:f782d9c66c49 142 printf("status_cb: Max connect time reached\n");
dkato 0:f782d9c66c49 143 break;
dkato 0:f782d9c66c49 144 }
dkato 0:f782d9c66c49 145 case PPPERR_LOOPBACK: {
dkato 0:f782d9c66c49 146 printf("status_cb: Loopback detected\n");
dkato 0:f782d9c66c49 147 break;
dkato 0:f782d9c66c49 148 }
dkato 0:f782d9c66c49 149 default: {
dkato 0:f782d9c66c49 150 printf("status_cb: Unknown error code %d\n", err_code);
dkato 0:f782d9c66c49 151 break;
dkato 0:f782d9c66c49 152 }
dkato 0:f782d9c66c49 153 }
dkato 0:f782d9c66c49 154
dkato 0:f782d9c66c49 155 /*
dkato 0:f782d9c66c49 156 * This should be in the switch case, this is put outside of the switch
dkato 0:f782d9c66c49 157 * case for example readability.
dkato 0:f782d9c66c49 158 */
dkato 0:f782d9c66c49 159
dkato 0:f782d9c66c49 160 if (err_code == PPPERR_NONE) {
dkato 0:f782d9c66c49 161 return;
dkato 0:f782d9c66c49 162 }
dkato 0:f782d9c66c49 163
dkato 0:f782d9c66c49 164 /* ppp_close() was previously called, don't reconnect */
dkato 0:f782d9c66c49 165 if (err_code == PPPERR_USER) {
dkato 0:f782d9c66c49 166 /* ppp_free(); -- can be called here */
dkato 0:f782d9c66c49 167 return;
dkato 0:f782d9c66c49 168 }
dkato 0:f782d9c66c49 169
dkato 0:f782d9c66c49 170 /*
dkato 0:f782d9c66c49 171 * Try to reconnect in 30 seconds, if you need a modem chatscript you have
dkato 0:f782d9c66c49 172 * to do a much better signaling here ;-)
dkato 0:f782d9c66c49 173 */
dkato 0:f782d9c66c49 174 ppp_connect(pcb, 30);
dkato 0:f782d9c66c49 175 /* OR ppp_listen(pcb); */
dkato 0:f782d9c66c49 176 }
dkato 0:f782d9c66c49 177
dkato 0:f782d9c66c49 178
dkato 0:f782d9c66c49 179 /*
dkato 0:f782d9c66c49 180 * Creating a new PPPoS session
dkato 0:f782d9c66c49 181 * ============================
dkato 0:f782d9c66c49 182 *
dkato 0:f782d9c66c49 183 * In lwIP, PPPoS is not PPPoSONET, in lwIP PPPoS is PPPoSerial.
dkato 0:f782d9c66c49 184 */
dkato 0:f782d9c66c49 185
dkato 0:f782d9c66c49 186 #include "netif/ppp/pppos.h"
dkato 0:f782d9c66c49 187
dkato 0:f782d9c66c49 188 /*
dkato 0:f782d9c66c49 189 * PPPoS serial output callback
dkato 0:f782d9c66c49 190 *
dkato 0:f782d9c66c49 191 * ppp_pcb, PPP control block
dkato 0:f782d9c66c49 192 * data, buffer to write to serial port
dkato 0:f782d9c66c49 193 * len, length of the data buffer
dkato 0:f782d9c66c49 194 * ctx, optional user-provided callback context pointer
dkato 0:f782d9c66c49 195 *
dkato 0:f782d9c66c49 196 * Return value: len if write succeed
dkato 0:f782d9c66c49 197 */
dkato 0:f782d9c66c49 198 static u32_t output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) {
dkato 0:f782d9c66c49 199 return uart_write(UART, data, len);
dkato 0:f782d9c66c49 200 }
dkato 0:f782d9c66c49 201
dkato 0:f782d9c66c49 202 /*
dkato 0:f782d9c66c49 203 * Create a new PPPoS interface
dkato 0:f782d9c66c49 204 *
dkato 0:f782d9c66c49 205 * ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
dkato 0:f782d9c66c49 206 * output_cb, PPPoS serial output callback
dkato 0:f782d9c66c49 207 * status_cb, PPP status callback, called on PPP status change (up, down, …)
dkato 0:f782d9c66c49 208 * ctx_cb, optional user-provided callback context pointer
dkato 0:f782d9c66c49 209 */
dkato 0:f782d9c66c49 210 ppp = pppos_create(&ppp_netif,
dkato 0:f782d9c66c49 211 output_cb, status_cb, ctx_cb);
dkato 0:f782d9c66c49 212
dkato 0:f782d9c66c49 213
dkato 0:f782d9c66c49 214 /*
dkato 0:f782d9c66c49 215 * Creating a new PPPoE session
dkato 0:f782d9c66c49 216 * ============================
dkato 0:f782d9c66c49 217 */
dkato 0:f782d9c66c49 218
dkato 0:f782d9c66c49 219 #include "netif/ppp/pppoe.h"
dkato 0:f782d9c66c49 220
dkato 0:f782d9c66c49 221 /*
dkato 0:f782d9c66c49 222 * Create a new PPPoE interface
dkato 0:f782d9c66c49 223 *
dkato 0:f782d9c66c49 224 * ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
dkato 0:f782d9c66c49 225 * ethif, already existing and setup Ethernet interface to use
dkato 0:f782d9c66c49 226 * service_name, PPPoE service name discriminator (not supported yet)
dkato 0:f782d9c66c49 227 * concentrator_name, PPPoE concentrator name discriminator (not supported yet)
dkato 0:f782d9c66c49 228 * status_cb, PPP status callback, called on PPP status change (up, down, …)
dkato 0:f782d9c66c49 229 * ctx_cb, optional user-provided callback context pointer
dkato 0:f782d9c66c49 230 */
dkato 0:f782d9c66c49 231 ppp = pppoe_create(&ppp_netif,
dkato 0:f782d9c66c49 232 &ethif,
dkato 0:f782d9c66c49 233 service_name, concentrator_name,
dkato 0:f782d9c66c49 234 status_cb, ctx_cb);
dkato 0:f782d9c66c49 235
dkato 0:f782d9c66c49 236
dkato 0:f782d9c66c49 237 /*
dkato 0:f782d9c66c49 238 * Creating a new PPPoL2TP session
dkato 0:f782d9c66c49 239 * ===============================
dkato 0:f782d9c66c49 240 */
dkato 0:f782d9c66c49 241
dkato 0:f782d9c66c49 242 #include "netif/ppp/pppol2tp.h"
dkato 0:f782d9c66c49 243
dkato 0:f782d9c66c49 244 /*
dkato 0:f782d9c66c49 245 * Create a new PPPoL2TP interface
dkato 0:f782d9c66c49 246 *
dkato 0:f782d9c66c49 247 * ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
dkato 0:f782d9c66c49 248 * netif, optional already existing and setup output netif, necessary if you
dkato 0:f782d9c66c49 249 * want to set this interface as default route to settle the chicken
dkato 0:f782d9c66c49 250 * and egg problem with VPN links
dkato 0:f782d9c66c49 251 * ipaddr, IP to connect to
dkato 0:f782d9c66c49 252 * port, UDP port to connect to (usually 1701)
dkato 0:f782d9c66c49 253 * secret, L2TP secret to use
dkato 0:f782d9c66c49 254 * secret_len, size in bytes of the L2TP secret
dkato 0:f782d9c66c49 255 * status_cb, PPP status callback, called on PPP status change (up, down, …)
dkato 0:f782d9c66c49 256 * ctx_cb, optional user-provided callback context pointer
dkato 0:f782d9c66c49 257 */
dkato 0:f782d9c66c49 258 ppp = pppol2tp_create(&ppp_netif,
dkato 0:f782d9c66c49 259 struct netif *netif, ip_addr_t *ipaddr, u16_t port,
dkato 0:f782d9c66c49 260 u8_t *secret, u8_t secret_len,
dkato 0:f782d9c66c49 261 ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
dkato 0:f782d9c66c49 262
dkato 0:f782d9c66c49 263
dkato 0:f782d9c66c49 264 /*
dkato 0:f782d9c66c49 265 * Initiate PPP client connection
dkato 0:f782d9c66c49 266 * ==============================
dkato 0:f782d9c66c49 267 */
dkato 0:f782d9c66c49 268
dkato 0:f782d9c66c49 269 /* Set this interface as default route */
dkato 0:f782d9c66c49 270 ppp_set_default(ppp);
dkato 0:f782d9c66c49 271
dkato 0:f782d9c66c49 272 /*
dkato 0:f782d9c66c49 273 * Basic PPP client configuration. Can only be set if PPP session is in the
dkato 0:f782d9c66c49 274 * dead state (i.e. disconnected). We don't need to provide thread-safe
dkato 0:f782d9c66c49 275 * equivalents through PPPAPI because those helpers are only changing
dkato 0:f782d9c66c49 276 * structure members while session is inactive for lwIP core. Configuration
dkato 0:f782d9c66c49 277 * only need to be done once.
dkato 0:f782d9c66c49 278 */
dkato 0:f782d9c66c49 279
dkato 0:f782d9c66c49 280 /* Ask the peer for up to 2 DNS server addresses. */
dkato 0:f782d9c66c49 281 ppp_set_usepeerdns(ppp, 1);
dkato 0:f782d9c66c49 282
dkato 0:f782d9c66c49 283 /* Auth configuration, this is pretty self-explanatory */
dkato 0:f782d9c66c49 284 ppp_set_auth(ppp, PPPAUTHTYPE_ANY, "login", "password");
dkato 0:f782d9c66c49 285
dkato 0:f782d9c66c49 286 /*
dkato 0:f782d9c66c49 287 * Initiate PPP negotiation, without waiting (holdoff=0), can only be called
dkato 0:f782d9c66c49 288 * if PPP session is in the dead state (i.e. disconnected).
dkato 0:f782d9c66c49 289 */
dkato 0:f782d9c66c49 290 u16_t holdoff = 0;
dkato 0:f782d9c66c49 291 ppp_connect(ppp, holdoff);
dkato 0:f782d9c66c49 292
dkato 0:f782d9c66c49 293
dkato 0:f782d9c66c49 294 /*
dkato 0:f782d9c66c49 295 * Initiate PPP server listener
dkato 0:f782d9c66c49 296 * ============================
dkato 0:f782d9c66c49 297 */
dkato 0:f782d9c66c49 298
dkato 0:f782d9c66c49 299 /*
dkato 0:f782d9c66c49 300 * Basic PPP server configuration. Can only be set if PPP session is in the
dkato 0:f782d9c66c49 301 * dead state (i.e. disconnected). We don't need to provide thread-safe
dkato 0:f782d9c66c49 302 * equivalents through PPPAPI because those helpers are only changing
dkato 0:f782d9c66c49 303 * structure members while session is inactive for lwIP core. Configuration
dkato 0:f782d9c66c49 304 * only need to be done once.
dkato 0:f782d9c66c49 305 */
dkato 0:f782d9c66c49 306 ip4_addr_t addr;
dkato 0:f782d9c66c49 307
dkato 0:f782d9c66c49 308 /* Set our address */
dkato 0:f782d9c66c49 309 IP4_ADDR(&addr, 192,168,0,1);
dkato 0:f782d9c66c49 310 ppp_set_ipcp_ouraddr(ppp, &addr);
dkato 0:f782d9c66c49 311
dkato 0:f782d9c66c49 312 /* Set peer(his) address */
dkato 0:f782d9c66c49 313 IP4_ADDR(&addr, 192,168,0,2);
dkato 0:f782d9c66c49 314 ppp_set_ipcp_hisaddr(ppp, &addr);
dkato 0:f782d9c66c49 315
dkato 0:f782d9c66c49 316 /* Set primary DNS server */
dkato 0:f782d9c66c49 317 IP4_ADDR(&addr, 192,168,10,20);
dkato 0:f782d9c66c49 318 ppp_set_ipcp_dnsaddr(ppp, 0, &addr);
dkato 0:f782d9c66c49 319
dkato 0:f782d9c66c49 320 /* Set secondary DNS server */
dkato 0:f782d9c66c49 321 IP4_ADDR(&addr, 192,168,10,21);
dkato 0:f782d9c66c49 322 ppp_set_ipcp_dnsaddr(ppp, 1, &addr);
dkato 0:f782d9c66c49 323
dkato 0:f782d9c66c49 324 /* Auth configuration, this is pretty self-explanatory */
dkato 0:f782d9c66c49 325 ppp_set_auth(ppp, PPPAUTHTYPE_ANY, "login", "password");
dkato 0:f782d9c66c49 326
dkato 0:f782d9c66c49 327 /* Require peer to authenticate */
dkato 0:f782d9c66c49 328 ppp_set_auth_required(ppp, 1);
dkato 0:f782d9c66c49 329
dkato 0:f782d9c66c49 330 /*
dkato 0:f782d9c66c49 331 * Only for PPPoS, the PPP session should be up and waiting for input.
dkato 0:f782d9c66c49 332 *
dkato 0:f782d9c66c49 333 * Note: for PPPoS, ppp_connect() and ppp_listen() are actually the same thing.
dkato 0:f782d9c66c49 334 * The listen call is meant for future support of PPPoE and PPPoL2TP server
dkato 0:f782d9c66c49 335 * mode, where we will need to negotiate the incoming PPPoE session or L2TP
dkato 0:f782d9c66c49 336 * session before initiating PPP itself. We need this call because there is
dkato 0:f782d9c66c49 337 * two passive modes for PPPoS, ppp_set_passive and ppp_set_silent.
dkato 0:f782d9c66c49 338 */
dkato 0:f782d9c66c49 339 ppp_set_silent(pppos, 1);
dkato 0:f782d9c66c49 340
dkato 0:f782d9c66c49 341 /*
dkato 0:f782d9c66c49 342 * Initiate PPP listener (i.e. wait for an incoming connection), can only
dkato 0:f782d9c66c49 343 * be called if PPP session is in the dead state (i.e. disconnected).
dkato 0:f782d9c66c49 344 */
dkato 0:f782d9c66c49 345 ppp_listen(ppp);
dkato 0:f782d9c66c49 346
dkato 0:f782d9c66c49 347
dkato 0:f782d9c66c49 348 /*
dkato 0:f782d9c66c49 349 * Closing PPP connection
dkato 0:f782d9c66c49 350 * ======================
dkato 0:f782d9c66c49 351 */
dkato 0:f782d9c66c49 352
dkato 0:f782d9c66c49 353 /*
dkato 0:f782d9c66c49 354 * Initiate the end of the PPP session, without carrier lost signal
dkato 0:f782d9c66c49 355 * (nocarrier=0), meaning a clean shutdown of PPP protocols.
dkato 0:f782d9c66c49 356 * You can call this function at anytime.
dkato 0:f782d9c66c49 357 */
dkato 0:f782d9c66c49 358 u8_t nocarrier = 0;
dkato 0:f782d9c66c49 359 ppp_close(ppp, nocarrier);
dkato 0:f782d9c66c49 360 /*
dkato 0:f782d9c66c49 361 * Then you must wait your status_cb() to be called, it may takes from a few
dkato 0:f782d9c66c49 362 * seconds to several tens of seconds depending on the current PPP state.
dkato 0:f782d9c66c49 363 */
dkato 0:f782d9c66c49 364
dkato 0:f782d9c66c49 365 /*
dkato 0:f782d9c66c49 366 * Freeing a PPP connection
dkato 0:f782d9c66c49 367 * ========================
dkato 0:f782d9c66c49 368 */
dkato 0:f782d9c66c49 369
dkato 0:f782d9c66c49 370 /*
dkato 0:f782d9c66c49 371 * Free the PPP control block, can only be called if PPP session is in the
dkato 0:f782d9c66c49 372 * dead state (i.e. disconnected). You need to call ppp_close() before.
dkato 0:f782d9c66c49 373 */
dkato 0:f782d9c66c49 374 ppp_free(ppp);
dkato 0:f782d9c66c49 375
dkato 0:f782d9c66c49 376
dkato 0:f782d9c66c49 377
dkato 0:f782d9c66c49 378 3 PPPoS input path (raw API, IRQ safe API, TCPIP API)
dkato 0:f782d9c66c49 379 =====================================================
dkato 0:f782d9c66c49 380
dkato 0:f782d9c66c49 381 Received data on serial port should be sent to lwIP using the pppos_input()
dkato 0:f782d9c66c49 382 function or the pppos_input_tcpip() function.
dkato 0:f782d9c66c49 383
dkato 0:f782d9c66c49 384 If NO_SYS is 1 and if PPP_INPROC_IRQ_SAFE is 0 (the default), pppos_input()
dkato 0:f782d9c66c49 385 is not IRQ safe and then *MUST* only be called inside your main loop.
dkato 0:f782d9c66c49 386
dkato 0:f782d9c66c49 387 Whatever the NO_SYS value, if PPP_INPROC_IRQ_SAFE is 1, pppos_input() is IRQ
dkato 0:f782d9c66c49 388 safe and can be safely called from an interrupt context, using that is going
dkato 0:f782d9c66c49 389 to reduce your need of buffer if pppos_input() is called byte after byte in
dkato 0:f782d9c66c49 390 your rx serial interrupt.
dkato 0:f782d9c66c49 391
dkato 0:f782d9c66c49 392 if NO_SYS is 0, the thread safe way outside an interrupt context is to use
dkato 0:f782d9c66c49 393 the pppos_input_tcpip() function to pass input data to the lwIP core thread
dkato 0:f782d9c66c49 394 using the TCPIP API. This is thread safe in all cases but you should avoid
dkato 0:f782d9c66c49 395 passing data byte after byte because it uses heavy locking (mailbox) and it
dkato 0:f782d9c66c49 396 allocates pbuf, better fill them !
dkato 0:f782d9c66c49 397
dkato 0:f782d9c66c49 398 if NO_SYS is 0 and if PPP_INPROC_IRQ_SAFE is 1, you may also use pppos_input()
dkato 0:f782d9c66c49 399 from an RX thread, however pppos_input() is not thread safe by itself. You can
dkato 0:f782d9c66c49 400 do that *BUT* you should NEVER call pppos_connect(), pppos_listen() and
dkato 0:f782d9c66c49 401 ppp_free() if pppos_input() can still be running, doing this is NOT thread safe
dkato 0:f782d9c66c49 402 at all. Using PPP_INPROC_IRQ_SAFE from an RX thread is discouraged unless you
dkato 0:f782d9c66c49 403 really know what you are doing, your move ;-)
dkato 0:f782d9c66c49 404
dkato 0:f782d9c66c49 405
dkato 0:f782d9c66c49 406 /*
dkato 0:f782d9c66c49 407 * Fonction to call for received data
dkato 0:f782d9c66c49 408 *
dkato 0:f782d9c66c49 409 * ppp, PPP control block
dkato 0:f782d9c66c49 410 * buffer, input buffer
dkato 0:f782d9c66c49 411 * buffer_len, buffer length in bytes
dkato 0:f782d9c66c49 412 */
dkato 0:f782d9c66c49 413 void pppos_input(ppp, buffer, buffer_len);
dkato 0:f782d9c66c49 414
dkato 0:f782d9c66c49 415 or
dkato 0:f782d9c66c49 416
dkato 0:f782d9c66c49 417 void pppos_input_tcpip(ppp, buffer, buffer_len);
dkato 0:f782d9c66c49 418
dkato 0:f782d9c66c49 419
dkato 0:f782d9c66c49 420
dkato 0:f782d9c66c49 421 4 Thread safe PPP API (PPPAPI)
dkato 0:f782d9c66c49 422 ==============================
dkato 0:f782d9c66c49 423
dkato 0:f782d9c66c49 424 There is a thread safe API for all corresponding ppp_* functions, you have to
dkato 0:f782d9c66c49 425 enable LWIP_PPP_API in your lwipopts.h file, then see
dkato 0:f782d9c66c49 426 include/netif/ppp/pppapi.h, this is actually pretty obvious.
dkato 0:f782d9c66c49 427
dkato 0:f782d9c66c49 428
dkato 0:f782d9c66c49 429
dkato 0:f782d9c66c49 430 5 Notify phase callback (PPP_NOTIFY_PHASE)
dkato 0:f782d9c66c49 431 ==========================================
dkato 0:f782d9c66c49 432
dkato 0:f782d9c66c49 433 Notify phase callback, enabled using the PPP_NOTIFY_PHASE config option, let
dkato 0:f782d9c66c49 434 you configure a callback that is called on each PPP internal state change.
dkato 0:f782d9c66c49 435 This is different from the status callback which only warns you about
dkato 0:f782d9c66c49 436 up(running) and down(dead) events.
dkato 0:f782d9c66c49 437
dkato 0:f782d9c66c49 438 Notify phase callback can be used, for example, to set a LED pattern depending
dkato 0:f782d9c66c49 439 on the current phase of the PPP session. Here is a callback example which
dkato 0:f782d9c66c49 440 tries to mimic what we usually see on xDSL modems while they are negotiating
dkato 0:f782d9c66c49 441 the link, which should be self-explanatory:
dkato 0:f782d9c66c49 442
dkato 0:f782d9c66c49 443 static void ppp_notify_phase_cb(ppp_pcb *pcb, u8_t phase, void *ctx) {
dkato 0:f782d9c66c49 444 switch (phase) {
dkato 0:f782d9c66c49 445
dkato 0:f782d9c66c49 446 /* Session is down (either permanently or briefly) */
dkato 0:f782d9c66c49 447 case PPP_PHASE_DEAD:
dkato 0:f782d9c66c49 448 led_set(PPP_LED, LED_OFF);
dkato 0:f782d9c66c49 449 break;
dkato 0:f782d9c66c49 450
dkato 0:f782d9c66c49 451 /* We are between two sessions */
dkato 0:f782d9c66c49 452 case PPP_PHASE_HOLDOFF:
dkato 0:f782d9c66c49 453 led_set(PPP_LED, LED_SLOW_BLINK);
dkato 0:f782d9c66c49 454 break;
dkato 0:f782d9c66c49 455
dkato 0:f782d9c66c49 456 /* Session just started */
dkato 0:f782d9c66c49 457 case PPP_PHASE_INITIALIZE:
dkato 0:f782d9c66c49 458 led_set(PPP_LED, LED_FAST_BLINK);
dkato 0:f782d9c66c49 459 break;
dkato 0:f782d9c66c49 460
dkato 0:f782d9c66c49 461 /* Session is running */
dkato 0:f782d9c66c49 462 case PPP_PHASE_RUNNING:
dkato 0:f782d9c66c49 463 led_set(PPP_LED, LED_ON);
dkato 0:f782d9c66c49 464 break;
dkato 0:f782d9c66c49 465
dkato 0:f782d9c66c49 466 default:
dkato 0:f782d9c66c49 467 break;
dkato 0:f782d9c66c49 468 }
dkato 0:f782d9c66c49 469 }
dkato 0:f782d9c66c49 470
dkato 0:f782d9c66c49 471
dkato 0:f782d9c66c49 472
dkato 0:f782d9c66c49 473 6 Upgrading from lwIP <= 1.4.x to lwIP >= 2.0.x
dkato 0:f782d9c66c49 474 ===============================================
dkato 0:f782d9c66c49 475
dkato 0:f782d9c66c49 476 PPP API was fully reworked between 1.4.x and 2.0.x releases. However porting
dkato 0:f782d9c66c49 477 from previous lwIP version is pretty easy:
dkato 0:f782d9c66c49 478
dkato 0:f782d9c66c49 479 * Previous PPP API used an integer to identify PPP sessions, we are now
dkato 0:f782d9c66c49 480 using ppp_pcb* control block, therefore all functions changed from "int ppp"
dkato 0:f782d9c66c49 481 to "ppp_pcb *ppp"
dkato 0:f782d9c66c49 482
dkato 0:f782d9c66c49 483 * struct netif was moved outside the PPP structure, you have to provide a netif
dkato 0:f782d9c66c49 484 for PPP interface in pppoX_create() functions
dkato 0:f782d9c66c49 485
dkato 0:f782d9c66c49 486 * PPP session are not started automatically after you created them anymore,
dkato 0:f782d9c66c49 487 you have to call ppp_connect(), this way you can configure the session before
dkato 0:f782d9c66c49 488 starting it.
dkato 0:f782d9c66c49 489
dkato 0:f782d9c66c49 490 * Previous PPP API used CamelCase, we are now using snake_case.
dkato 0:f782d9c66c49 491
dkato 0:f782d9c66c49 492 * Previous PPP API mixed PPPoS and PPPoE calls, this isn't the case anymore,
dkato 0:f782d9c66c49 493 PPPoS functions are now prefixed pppos_ and PPPoE functions are now prefixed
dkato 0:f782d9c66c49 494 pppoe_, common functions are now prefixed ppp_.
dkato 0:f782d9c66c49 495
dkato 0:f782d9c66c49 496 * New PPPERR_ error codes added, check you have all of them in your status
dkato 0:f782d9c66c49 497 callback function
dkato 0:f782d9c66c49 498
dkato 0:f782d9c66c49 499 * Only the following include files should now be used in user application:
dkato 0:f782d9c66c49 500 #include "netif/ppp/pppapi.h"
dkato 0:f782d9c66c49 501 #include "netif/ppp/pppos.h"
dkato 0:f782d9c66c49 502 #include "netif/ppp/pppoe.h"
dkato 0:f782d9c66c49 503 #include "netif/ppp/pppol2tp.h"
dkato 0:f782d9c66c49 504
dkato 0:f782d9c66c49 505 Functions from ppp.h can be used, but you don't need to include this header
dkato 0:f782d9c66c49 506 file as it is already included by above header files.
dkato 0:f782d9c66c49 507
dkato 0:f782d9c66c49 508 * PPP_INPROC_OWNTHREAD was broken by design and was removed, you have to create
dkato 0:f782d9c66c49 509 your own serial rx thread
dkato 0:f782d9c66c49 510
dkato 0:f782d9c66c49 511 * PPP_INPROC_MULTITHREADED option was misnamed and confusing and was renamed
dkato 0:f782d9c66c49 512 PPP_INPROC_IRQ_SAFE, please read the "PPPoS input path" documentation above
dkato 0:f782d9c66c49 513 because you might have been fooled by that
dkato 0:f782d9c66c49 514
dkato 0:f782d9c66c49 515 * If you used tcpip_callback_with_block() on ppp_ functions you may wish to use
dkato 0:f782d9c66c49 516 the PPPAPI API instead.
dkato 0:f782d9c66c49 517
dkato 0:f782d9c66c49 518 * ppp_sighup and ppp_close functions were merged using an optional argument
dkato 0:f782d9c66c49 519 "nocarrier" on ppp_close.
dkato 0:f782d9c66c49 520
dkato 0:f782d9c66c49 521 * DNS servers are now only remotely asked if LWIP_DNS is set and if
dkato 0:f782d9c66c49 522 ppp_set_usepeerdns() is set to true, they are now automatically registered
dkato 0:f782d9c66c49 523 using the dns_setserver() function so you don't need to do that in the PPP
dkato 0:f782d9c66c49 524 callback anymore.
dkato 0:f782d9c66c49 525
dkato 0:f782d9c66c49 526 * PPPoS does not use the SIO API anymore, as such it now requires a serial
dkato 0:f782d9c66c49 527 output callback in place of sio_write
dkato 0:f782d9c66c49 528
dkato 0:f782d9c66c49 529 * PPP_MAXIDLEFLAG is now in ms instead of jiffies