1 /***************************************************************************** 2 * ppp.h - Network Point to Point Protocol header file. 3 * 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. 5 * portions Copyright (c) 1997 Global Election Systems Inc. 6 * 7 * The authors hereby grant permission to use, copy, modify, distribute, 8 * and license this software and its documentation for any purpose, provided 9 * that existing copyright notices are retained in all copies and that this 10 * notice and the following disclaimer are included verbatim in any 11 * distributions. No written agreement, license, or royalty fee is required 12 * for any of the authorized uses. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 ****************************************************************************** 26 * REVISION HISTORY 27 * 28 * 03-01-01 Marc Boucher <marc@mbsi.ca> 29 * Ported to lwIP. 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. 31 * Original derived from BSD codes. 32 *****************************************************************************/ 33 34 #ifndef PPP_IMPL_H 35 #define PPP_IMPL_H 36 37 #include "lwip/opt.h" 38 39 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 40 41 #include "ppp.h" 42 #include "lwip/def.h" 43 #include "lwip/sio.h" 44 #include "lwip/stats.h" 45 #include "lwip/mem.h" 46 #include "lwip/netif.h" 47 #include "lwip/sys.h" 48 #include "lwip/timers.h" 49 50 /** Some defines for code we skip compared to the original pppd. 51 * These are just here to minimise the use of the ugly "#if 0". */ 52 #define PPP_ADDITIONAL_CALLBACKS 0 53 54 /** Some error checks to test for unsupported code */ 55 #if CBCP_SUPPORT 56 #error "CBCP is not supported in lwIP PPP" 57 #endif 58 #if CCP_SUPPORT 59 #error "CCP is not supported in lwIP PPP" 60 #endif 61 62 /* 63 * pppd.h - PPP daemon global declarations. 64 * 65 * Copyright (c) 1989 Carnegie Mellon University. 66 * All rights reserved. 67 * 68 * Redistribution and use in source and binary forms are permitted 69 * provided that the above copyright notice and this paragraph are 70 * duplicated in all such forms and that any documentation, 71 * advertising materials, and other materials related to such 72 * distribution and use acknowledge that the software was developed 73 * by Carnegie Mellon University. The name of the 74 * University may not be used to endorse or promote products derived 75 * from this software without specific prior written permission. 76 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 77 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 78 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 79 * 80 */ 81 /* 82 * ppp_defs.h - PPP definitions. 83 * 84 * Copyright (c) 1994 The Australian National University. 85 * All rights reserved. 86 * 87 * Permission to use, copy, modify, and distribute this software and its 88 * documentation is hereby granted, provided that the above copyright 89 * notice appears in all copies. This software is provided without any 90 * warranty, express or implied. The Australian National University 91 * makes no representations about the suitability of this software for 92 * any purpose. 93 * 94 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY 95 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 96 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 97 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY 98 * OF SUCH DAMAGE. 99 * 100 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, 101 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 102 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 103 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO 104 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 105 * OR MODIFICATIONS. 106 */ 107 108 #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) 109 #define UNTIMEOUT(f, a) sys_untimeout((f), (a)) 110 111 112 /* 113 * Constants and structures defined by the internet system, 114 * Per RFC 790, September 1981, and numerous additions. 115 */ 116 117 /* 118 * The basic PPP frame. 119 */ 120 #define PPP_HDRLEN 4 /* octets for standard ppp header */ 121 #define PPP_FCSLEN 2 /* octets for FCS */ 122 123 124 /* 125 * Significant octet values. 126 */ 127 #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ 128 #define PPP_UI 0x03 /* Unnumbered Information */ 129 #define PPP_FLAG 0x7e /* Flag Sequence */ 130 #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ 131 #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ 132 133 /* 134 * Protocol field values. 135 */ 136 #define PPP_IP 0x21 /* Internet Protocol */ 137 #define PPP_AT 0x29 /* AppleTalk Protocol */ 138 #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ 139 #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ 140 #define PPP_COMP 0xfd /* compressed packet */ 141 #define PPP_IPCP 0x8021 /* IP Control Protocol */ 142 #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ 143 #define PPP_CCP 0x80fd /* Compression Control Protocol */ 144 #define PPP_LCP 0xc021 /* Link Control Protocol */ 145 #define PPP_PAP 0xc023 /* Password Authentication Protocol */ 146 #define PPP_LQR 0xc025 /* Link Quality Report protocol */ 147 #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ 148 #define PPP_CBCP 0xc029 /* Callback Control Protocol */ 149 150 /* 151 * Values for FCS calculations. 152 */ 153 #define PPP_INITFCS 0xffff /* Initial FCS value */ 154 #define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ 155 #define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) 156 157 /* 158 * Extended asyncmap - allows any character to be escaped. 159 */ 160 typedef u_char ext_accm[32]; 161 162 /* 163 * What to do with network protocol (NP) packets. 164 */ 165 enum NPmode { 166 NPMODE_PASS, /* pass the packet through */ 167 NPMODE_DROP, /* silently drop the packet */ 168 NPMODE_ERROR, /* return an error */ 169 NPMODE_QUEUE /* save it up for later. */ 170 }; 171 172 /* 173 * Inline versions of get/put char/short/long. 174 * Pointer is advanced; we assume that both arguments 175 * are lvalues and will already be in registers. 176 * cp MUST be u_char *. 177 */ 178 #define GETCHAR(c, cp) { \ 179 (c) = *(cp)++; \ 180 } 181 #define PUTCHAR(c, cp) { \ 182 *(cp)++ = (u_char) (c); \ 183 } 184 185 186 #define GETSHORT(s, cp) { \ 187 (s) = *(cp); (cp)++; (s) <<= 8; \ 188 (s) |= *(cp); (cp)++; \ 189 } 190 #define PUTSHORT(s, cp) { \ 191 *(cp)++ = (u_char) ((s) >> 8); \ 192 *(cp)++ = (u_char) (s & 0xff); \ 193 } 194 195 #define GETLONG(l, cp) { \ 196 (l) = *(cp); (cp)++; (l) <<= 8; \ 197 (l) |= *(cp); (cp)++; (l) <<= 8; \ 198 (l) |= *(cp); (cp)++; (l) <<= 8; \ 199 (l) |= *(cp); (cp)++; \ 200 } 201 #define PUTLONG(l, cp) { \ 202 *(cp)++ = (u_char) ((l) >> 24); \ 203 *(cp)++ = (u_char) ((l) >> 16); \ 204 *(cp)++ = (u_char) ((l) >> 8); \ 205 *(cp)++ = (u_char) (l); \ 206 } 207 208 209 #define INCPTR(n, cp) ((cp) += (n)) 210 #define DECPTR(n, cp) ((cp) -= (n)) 211 212 #define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l)) 213 #define BCOPY(s, d, l) MEMCPY((d), (s), (l)) 214 #define BZERO(s, n) memset(s, 0, n) 215 216 #if PPP_DEBUG 217 #define PRINTMSG(m, l) { m[l] = '\0'; LWIP_DEBUGF(LOG_INFO, ("Remote message: %s\n", m)); } 218 #else /* PPP_DEBUG */ 219 #define PRINTMSG(m, l) 220 #endif /* PPP_DEBUG */ 221 222 /* 223 * MAKEHEADER - Add PPP Header fields to a packet. 224 */ 225 #define MAKEHEADER(p, t) { \ 226 PUTCHAR(PPP_ALLSTATIONS, p); \ 227 PUTCHAR(PPP_UI, p); \ 228 PUTSHORT(t, p); } 229 230 /************************ 231 *** PUBLIC DATA TYPES *** 232 ************************/ 233 234 /* 235 * The following struct gives the addresses of procedures to call 236 * for a particular protocol. 237 */ 238 struct protent { 239 u_short protocol; /* PPP protocol number */ 240 /* Initialization procedure */ 241 void (*init) (int unit); 242 /* Process a received packet */ 243 void (*input) (int unit, u_char *pkt, int len); 244 /* Process a received protocol-reject */ 245 void (*protrej) (int unit); 246 /* Lower layer has come up */ 247 void (*lowerup) (int unit); 248 /* Lower layer has gone down */ 249 void (*lowerdown) (int unit); 250 /* Open the protocol */ 251 void (*open) (int unit); 252 /* Close the protocol */ 253 void (*close) (int unit, char *reason); 254 #if PPP_ADDITIONAL_CALLBACKS 255 /* Print a packet in readable form */ 256 int (*printpkt) (u_char *pkt, int len, 257 void (*printer) (void *, char *, ...), 258 void *arg); 259 /* Process a received data packet */ 260 void (*datainput) (int unit, u_char *pkt, int len); 261 #endif /* PPP_ADDITIONAL_CALLBACKS */ 262 int enabled_flag; /* 0 if protocol is disabled */ 263 char *name; /* Text name of protocol */ 264 #if PPP_ADDITIONAL_CALLBACKS 265 /* Check requested options, assign defaults */ 266 void (*check_options) (u_long); 267 /* Configure interface for demand-dial */ 268 int (*demand_conf) (int unit); 269 /* Say whether to bring up link for this pkt */ 270 int (*active_pkt) (u_char *pkt, int len); 271 #endif /* PPP_ADDITIONAL_CALLBACKS */ 272 }; 273 274 /* 275 * The following structure records the time in seconds since 276 * the last NP packet was sent or received. 277 */ 278 struct ppp_idle { 279 u_short xmit_idle; /* seconds since last NP packet sent */ 280 u_short recv_idle; /* seconds since last NP packet received */ 281 }; 282 283 struct ppp_settings { 284 285 u_int disable_defaultip : 1; /* Don't use hostname for default IP addrs */ 286 u_int auth_required : 1; /* Peer is required to authenticate */ 287 u_int explicit_remote : 1; /* remote_name specified with remotename opt */ 288 u_int refuse_pap : 1; /* Don't wanna auth. ourselves with PAP */ 289 u_int refuse_chap : 1; /* Don't wanna auth. ourselves with CHAP */ 290 u_int usehostname : 1; /* Use hostname for our_name */ 291 u_int usepeerdns : 1; /* Ask peer for DNS adds */ 292 293 u_short idle_time_limit; /* Shut down link if idle for this long */ 294 int maxconnect; /* Maximum connect time (seconds) */ 295 296 char user [MAXNAMELEN + 1]; /* Username for PAP */ 297 char passwd [MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */ 298 char our_name [MAXNAMELEN + 1]; /* Our name for authentication purposes */ 299 char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ 300 }; 301 302 /***************************** 303 *** PUBLIC DATA STRUCTURES *** 304 *****************************/ 305 306 /* Buffers for outgoing packets. */ 307 extern u_char outpacket_buf[NUM_PPP][PPP_MRU+PPP_HDRLEN]; 308 309 extern struct ppp_settings ppp_settings; 310 311 extern struct protent *ppp_protocols[]; /* Table of pointers to supported protocols */ 312 313 314 /*********************** 315 *** PUBLIC FUNCTIONS *** 316 ***********************/ 317 318 /* 319 * Write n characters to a ppp link. 320 * RETURN: >= 0 Number of characters written, -1 Failed to write to device. 321 */ 322 int pppWrite(int pd, const u_char *s, int n); 323 324 void pppInProcOverEthernet(int pd, struct pbuf *pb); 325 326 struct pbuf *pppSingleBuf(struct pbuf *p); 327 328 void pppLinkTerminated(int pd); 329 330 void pppLinkDown(int pd); 331 332 /* Configure i/f transmit parameters */ 333 void ppp_send_config (int, u16_t, u32_t, int, int); 334 /* Set extended transmit ACCM */ 335 void ppp_set_xaccm (int, ext_accm *); 336 /* Configure i/f receive parameters */ 337 void ppp_recv_config (int, int, u32_t, int, int); 338 /* Find out how long link has been idle */ 339 int get_idle_time (int, struct ppp_idle *); 340 341 /* Configure VJ TCP header compression */ 342 int sifvjcomp (int, int, u8_t, u8_t); 343 /* Configure i/f down (for IP) */ 344 int sifup (int); 345 /* Set mode for handling packets for proto */ 346 int sifnpmode (int u, int proto, enum NPmode mode); 347 /* Configure i/f down (for IP) */ 348 int sifdown (int); 349 /* Configure IP addresses for i/f */ 350 int sifaddr (int, u32_t, u32_t, u32_t, u32_t, u32_t); 351 /* Reset i/f IP addresses */ 352 int cifaddr (int, u32_t, u32_t); 353 /* Create default route through i/f */ 354 int sifdefaultroute (int, u32_t, u32_t); 355 /* Delete default route through i/f */ 356 int cifdefaultroute (int, u32_t, u32_t); 357 358 /* Get appropriate netmask for address */ 359 u32_t GetMask (u32_t); 360 361 #endif /* PPP_SUPPORT */ 362 363 #endif /* PPP_IMPL_H */ 364