simple tester example >>> osc destination & receive

Dependencies:   mbed

Fork of myOSC_test by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Sat Oct 15 14:15:55 2011 +0000
Revision:
0:f76708a93fb3
First working test of this simple OSC library.

Who changed what in which revision?

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