Contains example code to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service via ethernet.

Dependencies:   C12832 MQTT LM75B MMA7660

Dependents:   MFT_IoT_demo_USB400 IBM_RFID

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samdanbury 6:37b6d0d56190 1 /*****************************************************************************
samdanbury 6:37b6d0d56190 2 * ppp.h - Network Point to Point Protocol header file.
samdanbury 6:37b6d0d56190 3 *
samdanbury 6:37b6d0d56190 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
samdanbury 6:37b6d0d56190 5 * portions Copyright (c) 1997 Global Election Systems Inc.
samdanbury 6:37b6d0d56190 6 *
samdanbury 6:37b6d0d56190 7 * The authors hereby grant permission to use, copy, modify, distribute,
samdanbury 6:37b6d0d56190 8 * and license this software and its documentation for any purpose, provided
samdanbury 6:37b6d0d56190 9 * that existing copyright notices are retained in all copies and that this
samdanbury 6:37b6d0d56190 10 * notice and the following disclaimer are included verbatim in any
samdanbury 6:37b6d0d56190 11 * distributions. No written agreement, license, or royalty fee is required
samdanbury 6:37b6d0d56190 12 * for any of the authorized uses.
samdanbury 6:37b6d0d56190 13 *
samdanbury 6:37b6d0d56190 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
samdanbury 6:37b6d0d56190 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
samdanbury 6:37b6d0d56190 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
samdanbury 6:37b6d0d56190 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
samdanbury 6:37b6d0d56190 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
samdanbury 6:37b6d0d56190 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
samdanbury 6:37b6d0d56190 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
samdanbury 6:37b6d0d56190 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
samdanbury 6:37b6d0d56190 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
samdanbury 6:37b6d0d56190 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
samdanbury 6:37b6d0d56190 24 *
samdanbury 6:37b6d0d56190 25 ******************************************************************************
samdanbury 6:37b6d0d56190 26 * REVISION HISTORY
samdanbury 6:37b6d0d56190 27 *
samdanbury 6:37b6d0d56190 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
samdanbury 6:37b6d0d56190 29 * Ported to lwIP.
samdanbury 6:37b6d0d56190 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
samdanbury 6:37b6d0d56190 31 * Original derived from BSD codes.
samdanbury 6:37b6d0d56190 32 *****************************************************************************/
samdanbury 6:37b6d0d56190 33
samdanbury 6:37b6d0d56190 34 #ifndef PPP_H
samdanbury 6:37b6d0d56190 35 #define PPP_H
samdanbury 6:37b6d0d56190 36
samdanbury 6:37b6d0d56190 37 #include "lwip/opt.h"
samdanbury 6:37b6d0d56190 38
samdanbury 6:37b6d0d56190 39 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
samdanbury 6:37b6d0d56190 40
samdanbury 6:37b6d0d56190 41 #include "lwip/def.h"
samdanbury 6:37b6d0d56190 42 #include "lwip/sio.h"
samdanbury 6:37b6d0d56190 43 #include "lwip/stats.h"
samdanbury 6:37b6d0d56190 44 #include "lwip/mem.h"
samdanbury 6:37b6d0d56190 45 #include "lwip/netif.h"
samdanbury 6:37b6d0d56190 46 #include "lwip/sys.h"
samdanbury 6:37b6d0d56190 47 #include "lwip/timers.h"
samdanbury 6:37b6d0d56190 48
samdanbury 6:37b6d0d56190 49 /** Some defines for code we skip compared to the original pppd.
samdanbury 6:37b6d0d56190 50 * These are just here to minimise the use of the ugly "#if 0". */
samdanbury 6:37b6d0d56190 51 #define PPP_ADDITIONAL_CALLBACKS 0
samdanbury 6:37b6d0d56190 52
samdanbury 6:37b6d0d56190 53 /** Some error checks to test for unsupported code */
samdanbury 6:37b6d0d56190 54 #if CBCP_SUPPORT
samdanbury 6:37b6d0d56190 55 #error "CBCP is not supported in lwIP PPP"
samdanbury 6:37b6d0d56190 56 #endif
samdanbury 6:37b6d0d56190 57 #if CCP_SUPPORT
samdanbury 6:37b6d0d56190 58 #error "CCP is not supported in lwIP PPP"
samdanbury 6:37b6d0d56190 59 #endif
samdanbury 6:37b6d0d56190 60
samdanbury 6:37b6d0d56190 61 /*
samdanbury 6:37b6d0d56190 62 * pppd.h - PPP daemon global declarations.
samdanbury 6:37b6d0d56190 63 *
samdanbury 6:37b6d0d56190 64 * Copyright (c) 1989 Carnegie Mellon University.
samdanbury 6:37b6d0d56190 65 * All rights reserved.
samdanbury 6:37b6d0d56190 66 *
samdanbury 6:37b6d0d56190 67 * Redistribution and use in source and binary forms are permitted
samdanbury 6:37b6d0d56190 68 * provided that the above copyright notice and this paragraph are
samdanbury 6:37b6d0d56190 69 * duplicated in all such forms and that any documentation,
samdanbury 6:37b6d0d56190 70 * advertising materials, and other materials related to such
samdanbury 6:37b6d0d56190 71 * distribution and use acknowledge that the software was developed
samdanbury 6:37b6d0d56190 72 * by Carnegie Mellon University. The name of the
samdanbury 6:37b6d0d56190 73 * University may not be used to endorse or promote products derived
samdanbury 6:37b6d0d56190 74 * from this software without specific prior written permission.
samdanbury 6:37b6d0d56190 75 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
samdanbury 6:37b6d0d56190 76 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
samdanbury 6:37b6d0d56190 77 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
samdanbury 6:37b6d0d56190 78 *
samdanbury 6:37b6d0d56190 79 */
samdanbury 6:37b6d0d56190 80 /*
samdanbury 6:37b6d0d56190 81 * ppp_defs.h - PPP definitions.
samdanbury 6:37b6d0d56190 82 *
samdanbury 6:37b6d0d56190 83 * Copyright (c) 1994 The Australian National University.
samdanbury 6:37b6d0d56190 84 * All rights reserved.
samdanbury 6:37b6d0d56190 85 *
samdanbury 6:37b6d0d56190 86 * Permission to use, copy, modify, and distribute this software and its
samdanbury 6:37b6d0d56190 87 * documentation is hereby granted, provided that the above copyright
samdanbury 6:37b6d0d56190 88 * notice appears in all copies. This software is provided without any
samdanbury 6:37b6d0d56190 89 * warranty, express or implied. The Australian National University
samdanbury 6:37b6d0d56190 90 * makes no representations about the suitability of this software for
samdanbury 6:37b6d0d56190 91 * any purpose.
samdanbury 6:37b6d0d56190 92 *
samdanbury 6:37b6d0d56190 93 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
samdanbury 6:37b6d0d56190 94 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
samdanbury 6:37b6d0d56190 95 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
samdanbury 6:37b6d0d56190 96 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
samdanbury 6:37b6d0d56190 97 * OF SUCH DAMAGE.
samdanbury 6:37b6d0d56190 98 *
samdanbury 6:37b6d0d56190 99 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
samdanbury 6:37b6d0d56190 100 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
samdanbury 6:37b6d0d56190 101 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
samdanbury 6:37b6d0d56190 102 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
samdanbury 6:37b6d0d56190 103 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
samdanbury 6:37b6d0d56190 104 * OR MODIFICATIONS.
samdanbury 6:37b6d0d56190 105 */
samdanbury 6:37b6d0d56190 106
samdanbury 6:37b6d0d56190 107 #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
samdanbury 6:37b6d0d56190 108 #define UNTIMEOUT(f, a) sys_untimeout((f), (a))
samdanbury 6:37b6d0d56190 109
samdanbury 6:37b6d0d56190 110
samdanbury 6:37b6d0d56190 111 #ifndef __u_char_defined
samdanbury 6:37b6d0d56190 112
samdanbury 6:37b6d0d56190 113 /* Type definitions for BSD code. */
samdanbury 6:37b6d0d56190 114 typedef unsigned long u_long;
samdanbury 6:37b6d0d56190 115 typedef unsigned int u_int;
samdanbury 6:37b6d0d56190 116 typedef unsigned short u_short;
samdanbury 6:37b6d0d56190 117 typedef unsigned char u_char;
samdanbury 6:37b6d0d56190 118
samdanbury 6:37b6d0d56190 119 #endif
samdanbury 6:37b6d0d56190 120
samdanbury 6:37b6d0d56190 121 /*
samdanbury 6:37b6d0d56190 122 * Constants and structures defined by the internet system,
samdanbury 6:37b6d0d56190 123 * Per RFC 790, September 1981, and numerous additions.
samdanbury 6:37b6d0d56190 124 */
samdanbury 6:37b6d0d56190 125
samdanbury 6:37b6d0d56190 126 /*
samdanbury 6:37b6d0d56190 127 * The basic PPP frame.
samdanbury 6:37b6d0d56190 128 */
samdanbury 6:37b6d0d56190 129 #define PPP_HDRLEN 4 /* octets for standard ppp header */
samdanbury 6:37b6d0d56190 130 #define PPP_FCSLEN 2 /* octets for FCS */
samdanbury 6:37b6d0d56190 131
samdanbury 6:37b6d0d56190 132
samdanbury 6:37b6d0d56190 133 /*
samdanbury 6:37b6d0d56190 134 * Significant octet values.
samdanbury 6:37b6d0d56190 135 */
samdanbury 6:37b6d0d56190 136 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
samdanbury 6:37b6d0d56190 137 #define PPP_UI 0x03 /* Unnumbered Information */
samdanbury 6:37b6d0d56190 138 #define PPP_FLAG 0x7e /* Flag Sequence */
samdanbury 6:37b6d0d56190 139 #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
samdanbury 6:37b6d0d56190 140 #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
samdanbury 6:37b6d0d56190 141
samdanbury 6:37b6d0d56190 142 /*
samdanbury 6:37b6d0d56190 143 * Protocol field values.
samdanbury 6:37b6d0d56190 144 */
samdanbury 6:37b6d0d56190 145 #define PPP_IP 0x21 /* Internet Protocol */
samdanbury 6:37b6d0d56190 146 #define PPP_AT 0x29 /* AppleTalk Protocol */
samdanbury 6:37b6d0d56190 147 #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
samdanbury 6:37b6d0d56190 148 #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
samdanbury 6:37b6d0d56190 149 #define PPP_COMP 0xfd /* compressed packet */
samdanbury 6:37b6d0d56190 150 #define PPP_IPCP 0x8021 /* IP Control Protocol */
samdanbury 6:37b6d0d56190 151 #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
samdanbury 6:37b6d0d56190 152 #define PPP_CCP 0x80fd /* Compression Control Protocol */
samdanbury 6:37b6d0d56190 153 #define PPP_LCP 0xc021 /* Link Control Protocol */
samdanbury 6:37b6d0d56190 154 #define PPP_PAP 0xc023 /* Password Authentication Protocol */
samdanbury 6:37b6d0d56190 155 #define PPP_LQR 0xc025 /* Link Quality Report protocol */
samdanbury 6:37b6d0d56190 156 #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
samdanbury 6:37b6d0d56190 157 #define PPP_CBCP 0xc029 /* Callback Control Protocol */
samdanbury 6:37b6d0d56190 158
samdanbury 6:37b6d0d56190 159 /*
samdanbury 6:37b6d0d56190 160 * Values for FCS calculations.
samdanbury 6:37b6d0d56190 161 */
samdanbury 6:37b6d0d56190 162 #define PPP_INITFCS 0xffff /* Initial FCS value */
samdanbury 6:37b6d0d56190 163 #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */
samdanbury 6:37b6d0d56190 164 #define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
samdanbury 6:37b6d0d56190 165
samdanbury 6:37b6d0d56190 166 /*
samdanbury 6:37b6d0d56190 167 * Extended asyncmap - allows any character to be escaped.
samdanbury 6:37b6d0d56190 168 */
samdanbury 6:37b6d0d56190 169 typedef u_char ext_accm[32];
samdanbury 6:37b6d0d56190 170
samdanbury 6:37b6d0d56190 171 /*
samdanbury 6:37b6d0d56190 172 * What to do with network protocol (NP) packets.
samdanbury 6:37b6d0d56190 173 */
samdanbury 6:37b6d0d56190 174 enum NPmode {
samdanbury 6:37b6d0d56190 175 NPMODE_PASS, /* pass the packet through */
samdanbury 6:37b6d0d56190 176 NPMODE_DROP, /* silently drop the packet */
samdanbury 6:37b6d0d56190 177 NPMODE_ERROR, /* return an error */
samdanbury 6:37b6d0d56190 178 NPMODE_QUEUE /* save it up for later. */
samdanbury 6:37b6d0d56190 179 };
samdanbury 6:37b6d0d56190 180
samdanbury 6:37b6d0d56190 181 /*
samdanbury 6:37b6d0d56190 182 * Inline versions of get/put char/short/long.
samdanbury 6:37b6d0d56190 183 * Pointer is advanced; we assume that both arguments
samdanbury 6:37b6d0d56190 184 * are lvalues and will already be in registers.
samdanbury 6:37b6d0d56190 185 * cp MUST be u_char *.
samdanbury 6:37b6d0d56190 186 */
samdanbury 6:37b6d0d56190 187 #define GETCHAR(c, cp) { \
samdanbury 6:37b6d0d56190 188 (c) = *(cp)++; \
samdanbury 6:37b6d0d56190 189 }
samdanbury 6:37b6d0d56190 190 #define PUTCHAR(c, cp) { \
samdanbury 6:37b6d0d56190 191 *(cp)++ = (u_char) (c); \
samdanbury 6:37b6d0d56190 192 }
samdanbury 6:37b6d0d56190 193
samdanbury 6:37b6d0d56190 194
samdanbury 6:37b6d0d56190 195 #define GETSHORT(s, cp) { \
samdanbury 6:37b6d0d56190 196 (s) = *(cp); (cp)++; (s) <<= 8; \
samdanbury 6:37b6d0d56190 197 (s) |= *(cp); (cp)++; \
samdanbury 6:37b6d0d56190 198 }
samdanbury 6:37b6d0d56190 199 #define PUTSHORT(s, cp) { \
samdanbury 6:37b6d0d56190 200 *(cp)++ = (u_char) ((s) >> 8); \
samdanbury 6:37b6d0d56190 201 *(cp)++ = (u_char) (s & 0xff); \
samdanbury 6:37b6d0d56190 202 }
samdanbury 6:37b6d0d56190 203
samdanbury 6:37b6d0d56190 204 #define GETLONG(l, cp) { \
samdanbury 6:37b6d0d56190 205 (l) = *(cp); (cp)++; (l) <<= 8; \
samdanbury 6:37b6d0d56190 206 (l) |= *(cp); (cp)++; (l) <<= 8; \
samdanbury 6:37b6d0d56190 207 (l) |= *(cp); (cp)++; (l) <<= 8; \
samdanbury 6:37b6d0d56190 208 (l) |= *(cp); (cp)++; \
samdanbury 6:37b6d0d56190 209 }
samdanbury 6:37b6d0d56190 210 #define PUTLONG(l, cp) { \
samdanbury 6:37b6d0d56190 211 *(cp)++ = (u_char) ((l) >> 24); \
samdanbury 6:37b6d0d56190 212 *(cp)++ = (u_char) ((l) >> 16); \
samdanbury 6:37b6d0d56190 213 *(cp)++ = (u_char) ((l) >> 8); \
samdanbury 6:37b6d0d56190 214 *(cp)++ = (u_char) (l); \
samdanbury 6:37b6d0d56190 215 }
samdanbury 6:37b6d0d56190 216
samdanbury 6:37b6d0d56190 217
samdanbury 6:37b6d0d56190 218 #define INCPTR(n, cp) ((cp) += (n))
samdanbury 6:37b6d0d56190 219 #define DECPTR(n, cp) ((cp) -= (n))
samdanbury 6:37b6d0d56190 220
samdanbury 6:37b6d0d56190 221 #define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
samdanbury 6:37b6d0d56190 222 #define BCOPY(s, d, l) MEMCPY((d), (s), (l))
samdanbury 6:37b6d0d56190 223 #define BZERO(s, n) memset(s, 0, n)
samdanbury 6:37b6d0d56190 224
samdanbury 6:37b6d0d56190 225 #if PPP_DEBUG
samdanbury 6:37b6d0d56190 226 #define PRINTMSG(m, l) { m[l] = '\0'; LWIP_DEBUGF(LOG_INFO, ("Remote message: %s\n", m)); }
samdanbury 6:37b6d0d56190 227 #else /* PPP_DEBUG */
samdanbury 6:37b6d0d56190 228 #define PRINTMSG(m, l)
samdanbury 6:37b6d0d56190 229 #endif /* PPP_DEBUG */
samdanbury 6:37b6d0d56190 230
samdanbury 6:37b6d0d56190 231 /*
samdanbury 6:37b6d0d56190 232 * MAKEHEADER - Add PPP Header fields to a packet.
samdanbury 6:37b6d0d56190 233 */
samdanbury 6:37b6d0d56190 234 #define MAKEHEADER(p, t) { \
samdanbury 6:37b6d0d56190 235 PUTCHAR(PPP_ALLSTATIONS, p); \
samdanbury 6:37b6d0d56190 236 PUTCHAR(PPP_UI, p); \
samdanbury 6:37b6d0d56190 237 PUTSHORT(t, p); }
samdanbury 6:37b6d0d56190 238
samdanbury 6:37b6d0d56190 239 /*************************
samdanbury 6:37b6d0d56190 240 *** PUBLIC DEFINITIONS ***
samdanbury 6:37b6d0d56190 241 *************************/
samdanbury 6:37b6d0d56190 242
samdanbury 6:37b6d0d56190 243 /* Error codes. */
samdanbury 6:37b6d0d56190 244 #define PPPERR_NONE 0 /* No error. */
samdanbury 6:37b6d0d56190 245 #define PPPERR_PARAM -1 /* Invalid parameter. */
samdanbury 6:37b6d0d56190 246 #define PPPERR_OPEN -2 /* Unable to open PPP session. */
samdanbury 6:37b6d0d56190 247 #define PPPERR_DEVICE -3 /* Invalid I/O device for PPP. */
samdanbury 6:37b6d0d56190 248 #define PPPERR_ALLOC -4 /* Unable to allocate resources. */
samdanbury 6:37b6d0d56190 249 #define PPPERR_USER -5 /* User interrupt. */
samdanbury 6:37b6d0d56190 250 #define PPPERR_CONNECT -6 /* Connection lost. */
samdanbury 6:37b6d0d56190 251 #define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
samdanbury 6:37b6d0d56190 252 #define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
samdanbury 6:37b6d0d56190 253
samdanbury 6:37b6d0d56190 254 /*
samdanbury 6:37b6d0d56190 255 * PPP IOCTL commands.
samdanbury 6:37b6d0d56190 256 */
samdanbury 6:37b6d0d56190 257 /*
samdanbury 6:37b6d0d56190 258 * Get the up status - 0 for down, non-zero for up. The argument must
samdanbury 6:37b6d0d56190 259 * point to an int.
samdanbury 6:37b6d0d56190 260 */
samdanbury 6:37b6d0d56190 261 #define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
samdanbury 6:37b6d0d56190 262 #define PPPCTLS_ERRCODE 101 /* Set the error code */
samdanbury 6:37b6d0d56190 263 #define PPPCTLG_ERRCODE 102 /* Get the error code */
samdanbury 6:37b6d0d56190 264 #define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
samdanbury 6:37b6d0d56190 265
samdanbury 6:37b6d0d56190 266 /************************
samdanbury 6:37b6d0d56190 267 *** PUBLIC DATA TYPES ***
samdanbury 6:37b6d0d56190 268 ************************/
samdanbury 6:37b6d0d56190 269
samdanbury 6:37b6d0d56190 270 /*
samdanbury 6:37b6d0d56190 271 * The following struct gives the addresses of procedures to call
samdanbury 6:37b6d0d56190 272 * for a particular protocol.
samdanbury 6:37b6d0d56190 273 */
samdanbury 6:37b6d0d56190 274 struct protent {
samdanbury 6:37b6d0d56190 275 u_short protocol; /* PPP protocol number */
samdanbury 6:37b6d0d56190 276 /* Initialization procedure */
samdanbury 6:37b6d0d56190 277 void (*init) (int unit);
samdanbury 6:37b6d0d56190 278 /* Process a received packet */
samdanbury 6:37b6d0d56190 279 void (*input) (int unit, u_char *pkt, int len);
samdanbury 6:37b6d0d56190 280 /* Process a received protocol-reject */
samdanbury 6:37b6d0d56190 281 void (*protrej) (int unit);
samdanbury 6:37b6d0d56190 282 /* Lower layer has come up */
samdanbury 6:37b6d0d56190 283 void (*lowerup) (int unit);
samdanbury 6:37b6d0d56190 284 /* Lower layer has gone down */
samdanbury 6:37b6d0d56190 285 void (*lowerdown) (int unit);
samdanbury 6:37b6d0d56190 286 /* Open the protocol */
samdanbury 6:37b6d0d56190 287 void (*open) (int unit);
samdanbury 6:37b6d0d56190 288 /* Close the protocol */
samdanbury 6:37b6d0d56190 289 void (*close) (int unit, char *reason);
samdanbury 6:37b6d0d56190 290 #if PPP_ADDITIONAL_CALLBACKS
samdanbury 6:37b6d0d56190 291 /* Print a packet in readable form */
samdanbury 6:37b6d0d56190 292 int (*printpkt) (u_char *pkt, int len,
samdanbury 6:37b6d0d56190 293 void (*printer) (void *, char *, ...),
samdanbury 6:37b6d0d56190 294 void *arg);
samdanbury 6:37b6d0d56190 295 /* Process a received data packet */
samdanbury 6:37b6d0d56190 296 void (*datainput) (int unit, u_char *pkt, int len);
samdanbury 6:37b6d0d56190 297 #endif /* PPP_ADDITIONAL_CALLBACKS */
samdanbury 6:37b6d0d56190 298 int enabled_flag; /* 0 if protocol is disabled */
samdanbury 6:37b6d0d56190 299 char *name; /* Text name of protocol */
samdanbury 6:37b6d0d56190 300 #if PPP_ADDITIONAL_CALLBACKS
samdanbury 6:37b6d0d56190 301 /* Check requested options, assign defaults */
samdanbury 6:37b6d0d56190 302 void (*check_options) (u_long);
samdanbury 6:37b6d0d56190 303 /* Configure interface for demand-dial */
samdanbury 6:37b6d0d56190 304 int (*demand_conf) (int unit);
samdanbury 6:37b6d0d56190 305 /* Say whether to bring up link for this pkt */
samdanbury 6:37b6d0d56190 306 int (*active_pkt) (u_char *pkt, int len);
samdanbury 6:37b6d0d56190 307 #endif /* PPP_ADDITIONAL_CALLBACKS */
samdanbury 6:37b6d0d56190 308 };
samdanbury 6:37b6d0d56190 309
samdanbury 6:37b6d0d56190 310 /*
samdanbury 6:37b6d0d56190 311 * The following structure records the time in seconds since
samdanbury 6:37b6d0d56190 312 * the last NP packet was sent or received.
samdanbury 6:37b6d0d56190 313 */
samdanbury 6:37b6d0d56190 314 struct ppp_idle {
samdanbury 6:37b6d0d56190 315 u_short xmit_idle; /* seconds since last NP packet sent */
samdanbury 6:37b6d0d56190 316 u_short recv_idle; /* seconds since last NP packet received */
samdanbury 6:37b6d0d56190 317 };
samdanbury 6:37b6d0d56190 318
samdanbury 6:37b6d0d56190 319 struct ppp_settings {
samdanbury 6:37b6d0d56190 320
samdanbury 6:37b6d0d56190 321 u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */
samdanbury 6:37b6d0d56190 322 u_int auth_required : 1; /* Peer is required to authenticate */
samdanbury 6:37b6d0d56190 323 u_int explicit_remote : 1; /* remote_name specified with remotename opt */
samdanbury 6:37b6d0d56190 324 u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */
samdanbury 6:37b6d0d56190 325 u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */
samdanbury 6:37b6d0d56190 326 u_int usehostname : 1; /* Use hostname for our_name */
samdanbury 6:37b6d0d56190 327 u_int usepeerdns : 1; /* Ask peer for DNS adds */
samdanbury 6:37b6d0d56190 328
samdanbury 6:37b6d0d56190 329 u_short idle_time_limit; /* Shut down link if idle for this long */
samdanbury 6:37b6d0d56190 330 int maxconnect; /* Maximum connect time (seconds) */
samdanbury 6:37b6d0d56190 331
samdanbury 6:37b6d0d56190 332 char user [MAXNAMELEN + 1]; /* Username for PAP */
samdanbury 6:37b6d0d56190 333 char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */
samdanbury 6:37b6d0d56190 334 char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */
samdanbury 6:37b6d0d56190 335 char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */
samdanbury 6:37b6d0d56190 336 };
samdanbury 6:37b6d0d56190 337
samdanbury 6:37b6d0d56190 338 struct ppp_addrs {
samdanbury 6:37b6d0d56190 339 ip_addr_t our_ipaddr, his_ipaddr, netmask, dns1, dns2;
samdanbury 6:37b6d0d56190 340 };
samdanbury 6:37b6d0d56190 341
samdanbury 6:37b6d0d56190 342 /*****************************
samdanbury 6:37b6d0d56190 343 *** PUBLIC DATA STRUCTURES ***
samdanbury 6:37b6d0d56190 344 *****************************/
samdanbury 6:37b6d0d56190 345
samdanbury 6:37b6d0d56190 346 /* Buffers for outgoing packets. */
samdanbury 6:37b6d0d56190 347 extern u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN];
samdanbury 6:37b6d0d56190 348
samdanbury 6:37b6d0d56190 349 extern struct ppp_settings ppp_settings;
samdanbury 6:37b6d0d56190 350
samdanbury 6:37b6d0d56190 351 extern struct protent *ppp_protocols[]; /* Table of pointers to supported protocols */
samdanbury 6:37b6d0d56190 352
samdanbury 6:37b6d0d56190 353
samdanbury 6:37b6d0d56190 354 /***********************
samdanbury 6:37b6d0d56190 355 *** PUBLIC FUNCTIONS ***
samdanbury 6:37b6d0d56190 356 ***********************/
samdanbury 6:37b6d0d56190 357
samdanbury 6:37b6d0d56190 358 /* Initialize the PPP subsystem. */
samdanbury 6:37b6d0d56190 359 void pppInit(void);
samdanbury 6:37b6d0d56190 360
samdanbury 6:37b6d0d56190 361 /* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
samdanbury 6:37b6d0d56190 362 * RFC 1994 says:
samdanbury 6:37b6d0d56190 363 *
samdanbury 6:37b6d0d56190 364 * In practice, within or associated with each PPP server, there is a
samdanbury 6:37b6d0d56190 365 * database which associates "user" names with authentication
samdanbury 6:37b6d0d56190 366 * information ("secrets"). It is not anticipated that a particular
samdanbury 6:37b6d0d56190 367 * named user would be authenticated by multiple methods. This would
samdanbury 6:37b6d0d56190 368 * make the user vulnerable to attacks which negotiate the least secure
samdanbury 6:37b6d0d56190 369 * method from among a set (such as PAP rather than CHAP). If the same
samdanbury 6:37b6d0d56190 370 * secret was used, PAP would reveal the secret to be used later with
samdanbury 6:37b6d0d56190 371 * CHAP.
samdanbury 6:37b6d0d56190 372 *
samdanbury 6:37b6d0d56190 373 * Instead, for each user name there should be an indication of exactly
samdanbury 6:37b6d0d56190 374 * one method used to authenticate that user name. If a user needs to
samdanbury 6:37b6d0d56190 375 * make use of different authentication methods under different
samdanbury 6:37b6d0d56190 376 * circumstances, then distinct user names SHOULD be employed, each of
samdanbury 6:37b6d0d56190 377 * which identifies exactly one authentication method.
samdanbury 6:37b6d0d56190 378 *
samdanbury 6:37b6d0d56190 379 */
samdanbury 6:37b6d0d56190 380 enum pppAuthType {
samdanbury 6:37b6d0d56190 381 PPPAUTHTYPE_NONE,
samdanbury 6:37b6d0d56190 382 PPPAUTHTYPE_ANY,
samdanbury 6:37b6d0d56190 383 PPPAUTHTYPE_PAP,
samdanbury 6:37b6d0d56190 384 PPPAUTHTYPE_CHAP
samdanbury 6:37b6d0d56190 385 };
samdanbury 6:37b6d0d56190 386
samdanbury 6:37b6d0d56190 387 void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
samdanbury 6:37b6d0d56190 388
samdanbury 6:37b6d0d56190 389 /*
samdanbury 6:37b6d0d56190 390 * Open a new PPP connection using the given serial I/O device.
samdanbury 6:37b6d0d56190 391 * This initializes the PPP control block but does not
samdanbury 6:37b6d0d56190 392 * attempt to negotiate the LCP session.
samdanbury 6:37b6d0d56190 393 * Return a new PPP connection descriptor on success or
samdanbury 6:37b6d0d56190 394 * an error code (negative) on failure.
samdanbury 6:37b6d0d56190 395 */
samdanbury 6:37b6d0d56190 396 int pppOverSerialOpen(sio_fd_t fd, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
samdanbury 6:37b6d0d56190 397
samdanbury 6:37b6d0d56190 398 /*
samdanbury 6:37b6d0d56190 399 * Open a new PPP Over Ethernet (PPPOE) connection.
samdanbury 6:37b6d0d56190 400 */
samdanbury 6:37b6d0d56190 401 int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name, void (*linkStatusCB)(void *ctx, int errCode, void *arg), void *linkStatusCtx);
samdanbury 6:37b6d0d56190 402
samdanbury 6:37b6d0d56190 403 /* for source code compatibility */
samdanbury 6:37b6d0d56190 404 #define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls)
samdanbury 6:37b6d0d56190 405
samdanbury 6:37b6d0d56190 406 /*
samdanbury 6:37b6d0d56190 407 * Close a PPP connection and release the descriptor.
samdanbury 6:37b6d0d56190 408 * Any outstanding packets in the queues are dropped.
samdanbury 6:37b6d0d56190 409 * Return 0 on success, an error code on failure.
samdanbury 6:37b6d0d56190 410 */
samdanbury 6:37b6d0d56190 411 int pppClose(int pd);
samdanbury 6:37b6d0d56190 412
samdanbury 6:37b6d0d56190 413 /*
samdanbury 6:37b6d0d56190 414 * Indicate to the PPP process that the line has disconnected.
samdanbury 6:37b6d0d56190 415 */
samdanbury 6:37b6d0d56190 416 void pppSigHUP(int pd);
samdanbury 6:37b6d0d56190 417
samdanbury 6:37b6d0d56190 418 /*
samdanbury 6:37b6d0d56190 419 * Get and set parameters for the given connection.
samdanbury 6:37b6d0d56190 420 * Return 0 on success, an error code on failure.
samdanbury 6:37b6d0d56190 421 */
samdanbury 6:37b6d0d56190 422 int pppIOCtl(int pd, int cmd, void *arg);
samdanbury 6:37b6d0d56190 423
samdanbury 6:37b6d0d56190 424 /*
samdanbury 6:37b6d0d56190 425 * Return the Maximum Transmission Unit for the given PPP connection.
samdanbury 6:37b6d0d56190 426 */
samdanbury 6:37b6d0d56190 427 u_short pppMTU(int pd);
samdanbury 6:37b6d0d56190 428
samdanbury 6:37b6d0d56190 429 /*
samdanbury 6:37b6d0d56190 430 * Write n characters to a ppp link.
samdanbury 6:37b6d0d56190 431 * RETURN: >= 0 Number of characters written, -1 Failed to write to device.
samdanbury 6:37b6d0d56190 432 */
samdanbury 6:37b6d0d56190 433 int pppWrite(int pd, const u_char *s, int n);
samdanbury 6:37b6d0d56190 434
samdanbury 6:37b6d0d56190 435 void pppInProcOverEthernet(int pd, struct pbuf *pb);
samdanbury 6:37b6d0d56190 436
samdanbury 6:37b6d0d56190 437 struct pbuf *pppSingleBuf(struct pbuf *p);
samdanbury 6:37b6d0d56190 438
samdanbury 6:37b6d0d56190 439 void pppLinkTerminated(int pd);
samdanbury 6:37b6d0d56190 440
samdanbury 6:37b6d0d56190 441 void pppLinkDown(int pd);
samdanbury 6:37b6d0d56190 442
samdanbury 6:37b6d0d56190 443 void pppos_input(int pd, u_char* data, int len);
samdanbury 6:37b6d0d56190 444
samdanbury 6:37b6d0d56190 445 /* Configure i/f transmit parameters */
samdanbury 6:37b6d0d56190 446 void ppp_send_config (int, u16_t, u32_t, int, int);
samdanbury 6:37b6d0d56190 447 /* Set extended transmit ACCM */
samdanbury 6:37b6d0d56190 448 void ppp_set_xaccm (int, ext_accm *);
samdanbury 6:37b6d0d56190 449 /* Configure i/f receive parameters */
samdanbury 6:37b6d0d56190 450 void ppp_recv_config (int, int, u32_t, int, int);
samdanbury 6:37b6d0d56190 451 /* Find out how long link has been idle */
samdanbury 6:37b6d0d56190 452 int get_idle_time (int, struct ppp_idle *);
samdanbury 6:37b6d0d56190 453
samdanbury 6:37b6d0d56190 454 /* Configure VJ TCP header compression */
samdanbury 6:37b6d0d56190 455 int sifvjcomp (int, int, u8_t, u8_t);
samdanbury 6:37b6d0d56190 456 /* Configure i/f down (for IP) */
samdanbury 6:37b6d0d56190 457 int sifup (int);
samdanbury 6:37b6d0d56190 458 /* Set mode for handling packets for proto */
samdanbury 6:37b6d0d56190 459 int sifnpmode (int u, int proto, enum NPmode mode);
samdanbury 6:37b6d0d56190 460 /* Configure i/f down (for IP) */
samdanbury 6:37b6d0d56190 461 int sifdown (int);
samdanbury 6:37b6d0d56190 462 /* Configure IP addresses for i/f */
samdanbury 6:37b6d0d56190 463 int sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t);
samdanbury 6:37b6d0d56190 464 /* Reset i/f IP addresses */
samdanbury 6:37b6d0d56190 465 int cifaddr (int, u32_t, u32_t);
samdanbury 6:37b6d0d56190 466 /* Create default route through i/f */
samdanbury 6:37b6d0d56190 467 int sifdefaultroute (int, u32_t, u32_t);
samdanbury 6:37b6d0d56190 468 /* Delete default route through i/f */
samdanbury 6:37b6d0d56190 469 int cifdefaultroute (int, u32_t, u32_t);
samdanbury 6:37b6d0d56190 470
samdanbury 6:37b6d0d56190 471 /* Get appropriate netmask for address */
samdanbury 6:37b6d0d56190 472 u32_t GetMask (u32_t);
samdanbury 6:37b6d0d56190 473
samdanbury 6:37b6d0d56190 474 #if LWIP_NETIF_STATUS_CALLBACK
samdanbury 6:37b6d0d56190 475 void ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback);
samdanbury 6:37b6d0d56190 476 #endif /* LWIP_NETIF_STATUS_CALLBACK */
samdanbury 6:37b6d0d56190 477 #if LWIP_NETIF_LINK_CALLBACK
samdanbury 6:37b6d0d56190 478 void ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback);
samdanbury 6:37b6d0d56190 479 #endif /* LWIP_NETIF_LINK_CALLBACK */
samdanbury 6:37b6d0d56190 480
samdanbury 6:37b6d0d56190 481 #endif /* PPP_SUPPORT */
samdanbury 6:37b6d0d56190 482
samdanbury 6:37b6d0d56190 483 #endif /* PPP_H */