Read NTP time from Ethernet and drive six 7-segment LEDs using a MAX7221 to show time, date, month, week, year etc....

Dependencies:   NTPClient_NetServices mbed

Committer:
cheungderek
Date:
Wed Jun 22 01:31:47 2011 +0000
Revision:
0:e083abcfe7a8
First release.
Just some testing but working code to read NTP time and drive 6 LEDs to display time, date, month, year etc...

Who changed what in which revision?

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