ppp_impl.h 12 KB

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