ppp_impl.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 LWIP_HDR_PPP_IMPL_H
  34. #define LWIP_HDR_PPP_IMPL_H
  35. #include "netif/ppp/ppp_opts.h"
  36. #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
  37. #ifdef PPP_INCLUDE_SETTINGS_HEADER
  38. #include "ppp_settings.h"
  39. #endif
  40. #ifdef PRINTF_STDLIB
  41. #include <stdio.h>
  42. #endif
  43. #ifdef PRINTF_CUSTOM
  44. #include "tinystdio.h"
  45. #endif
  46. #include <stdarg.h>
  47. #include <string.h>
  48. #include <stdlib.h> /* strtol() */
  49. #include "lwip/netif.h"
  50. #include "lwip/def.h"
  51. #include "lwip/timeouts.h"
  52. #include "ppp.h"
  53. #include "pppdebug.h"
  54. /*
  55. * Memory used for control packets.
  56. *
  57. * PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we
  58. * cannot figure out how much we are going to use before filling the buffer.
  59. */
  60. #if PPP_USE_PBUF_RAM
  61. #define PPP_CTRL_PBUF_TYPE PBUF_RAM
  62. #define PPP_CTRL_PBUF_MAX_SIZE 512
  63. #else /* PPP_USE_PBUF_RAM */
  64. #define PPP_CTRL_PBUF_TYPE PBUF_POOL
  65. #define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE
  66. #endif /* PPP_USE_PBUF_RAM */
  67. /*
  68. * The basic PPP frame.
  69. */
  70. #define PPP_ADDRESS(p) (((u_char *)(p))[0])
  71. #define PPP_CONTROL(p) (((u_char *)(p))[1])
  72. #define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
  73. /*
  74. * Significant octet values.
  75. */
  76. #define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
  77. #define PPP_UI 0x03 /* Unnumbered Information */
  78. #define PPP_FLAG 0x7e /* Flag Sequence */
  79. #define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */
  80. #define PPP_TRANS 0x20 /* Asynchronous transparency modifier */
  81. /*
  82. * Protocol field values.
  83. */
  84. #define PPP_IP 0x21 /* Internet Protocol */
  85. #if 0 /* UNUSED */
  86. #define PPP_AT 0x29 /* AppleTalk Protocol */
  87. #define PPP_IPX 0x2b /* IPX protocol */
  88. #endif /* UNUSED */
  89. #if VJ_SUPPORT
  90. #define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
  91. #define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
  92. #endif /* VJ_SUPPORT */
  93. #if PPP_IPV6_SUPPORT
  94. #define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
  95. #endif /* PPP_IPV6_SUPPORT */
  96. #if CCP_SUPPORT
  97. #define PPP_COMP 0xfd /* compressed packet */
  98. #endif /* CCP_SUPPORT */
  99. #define PPP_IPCP 0x8021 /* IP Control Protocol */
  100. #if 0 /* UNUSED */
  101. #define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
  102. #define PPP_IPXCP 0x802b /* IPX Control Protocol */
  103. #endif /* UNUSED */
  104. #if PPP_IPV6_SUPPORT
  105. #define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
  106. #endif /* PPP_IPV6_SUPPORT */
  107. #if CCP_SUPPORT
  108. #define PPP_CCP 0x80fd /* Compression Control Protocol */
  109. #endif /* CCP_SUPPORT */
  110. #if ECP_SUPPORT
  111. #define PPP_ECP 0x8053 /* Encryption Control Protocol */
  112. #endif /* ECP_SUPPORT */
  113. #define PPP_LCP 0xc021 /* Link Control Protocol */
  114. #if PAP_SUPPORT
  115. #define PPP_PAP 0xc023 /* Password Authentication Protocol */
  116. #endif /* PAP_SUPPORT */
  117. #if LQR_SUPPORT
  118. #define PPP_LQR 0xc025 /* Link Quality Report protocol */
  119. #endif /* LQR_SUPPORT */
  120. #if CHAP_SUPPORT
  121. #define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
  122. #endif /* CHAP_SUPPORT */
  123. #if CBCP_SUPPORT
  124. #define PPP_CBCP 0xc029 /* Callback Control Protocol */
  125. #endif /* CBCP_SUPPORT */
  126. #if EAP_SUPPORT
  127. #define PPP_EAP 0xc227 /* Extensible Authentication Protocol */
  128. #endif /* EAP_SUPPORT */
  129. /*
  130. * The following struct gives the addresses of procedures to call
  131. * for a particular lower link level protocol.
  132. */
  133. struct link_callbacks {
  134. /* Start a connection (e.g. Initiate discovery phase) */
  135. void (*connect) (ppp_pcb *pcb, void *ctx);
  136. #if PPP_SERVER
  137. /* Listen for an incoming connection (Passive mode) */
  138. void (*listen) (ppp_pcb *pcb, void *ctx);
  139. #endif /* PPP_SERVER */
  140. /* End a connection (i.e. initiate disconnect phase) */
  141. void (*disconnect) (ppp_pcb *pcb, void *ctx);
  142. /* Free lower protocol control block */
  143. err_t (*free) (ppp_pcb *pcb, void *ctx);
  144. /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */
  145. err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p);
  146. /* Send a packet from lwIP core (IPv4 or IPv6) */
  147. err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol);
  148. /* configure the transmit-side characteristics of the PPP interface */
  149. void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
  150. /* confire the receive-side characteristics of the PPP interface */
  151. void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp);
  152. };
  153. /*
  154. * What to do with network protocol (NP) packets.
  155. */
  156. enum NPmode {
  157. NPMODE_PASS, /* pass the packet through */
  158. NPMODE_DROP, /* silently drop the packet */
  159. NPMODE_ERROR, /* return an error */
  160. NPMODE_QUEUE /* save it up for later. */
  161. };
  162. /*
  163. * Statistics.
  164. */
  165. #if PPP_STATS_SUPPORT
  166. struct pppstat {
  167. unsigned int ppp_ibytes; /* bytes received */
  168. unsigned int ppp_ipackets; /* packets received */
  169. unsigned int ppp_ierrors; /* receive errors */
  170. unsigned int ppp_obytes; /* bytes sent */
  171. unsigned int ppp_opackets; /* packets sent */
  172. unsigned int ppp_oerrors; /* transmit errors */
  173. };
  174. #if VJ_SUPPORT
  175. struct vjstat {
  176. unsigned int vjs_packets; /* outbound packets */
  177. unsigned int vjs_compressed; /* outbound compressed packets */
  178. unsigned int vjs_searches; /* searches for connection state */
  179. unsigned int vjs_misses; /* times couldn't find conn. state */
  180. unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
  181. unsigned int vjs_compressedin; /* inbound compressed packets */
  182. unsigned int vjs_errorin; /* inbound unknown type packets */
  183. unsigned int vjs_tossed; /* inbound packets tossed because of error */
  184. };
  185. #endif /* VJ_SUPPORT */
  186. struct ppp_stats {
  187. struct pppstat p; /* basic PPP statistics */
  188. #if VJ_SUPPORT
  189. struct vjstat vj; /* VJ header compression statistics */
  190. #endif /* VJ_SUPPORT */
  191. };
  192. #if CCP_SUPPORT
  193. struct compstat {
  194. unsigned int unc_bytes; /* total uncompressed bytes */
  195. unsigned int unc_packets; /* total uncompressed packets */
  196. unsigned int comp_bytes; /* compressed bytes */
  197. unsigned int comp_packets; /* compressed packets */
  198. unsigned int inc_bytes; /* incompressible bytes */
  199. unsigned int inc_packets; /* incompressible packets */
  200. unsigned int ratio; /* recent compression ratio << 8 */
  201. };
  202. struct ppp_comp_stats {
  203. struct compstat c; /* packet compression statistics */
  204. struct compstat d; /* packet decompression statistics */
  205. };
  206. #endif /* CCP_SUPPORT */
  207. #endif /* PPP_STATS_SUPPORT */
  208. #if PPP_IDLETIMELIMIT
  209. /*
  210. * The following structure records the time in seconds since
  211. * the last NP packet was sent or received.
  212. */
  213. struct ppp_idle {
  214. time_t xmit_idle; /* time since last NP packet sent */
  215. time_t recv_idle; /* time since last NP packet received */
  216. };
  217. #endif /* PPP_IDLETIMELIMIT */
  218. /* values for epdisc.class */
  219. #define EPD_NULL 0 /* null discriminator, no data */
  220. #define EPD_LOCAL 1
  221. #define EPD_IP 2
  222. #define EPD_MAC 3
  223. #define EPD_MAGIC 4
  224. #define EPD_PHONENUM 5
  225. /*
  226. * Global variables.
  227. */
  228. #ifdef HAVE_MULTILINK
  229. extern u8_t multilink; /* enable multilink operation */
  230. extern u8_t doing_multilink;
  231. extern u8_t multilink_master;
  232. extern u8_t bundle_eof;
  233. extern u8_t bundle_terminating;
  234. #endif
  235. #ifdef MAXOCTETS
  236. extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
  237. extern int maxoctets_dir; /* Direction :
  238. 0 - in+out (default)
  239. 1 - in
  240. 2 - out
  241. 3 - max(in,out) */
  242. extern int maxoctets_timeout; /* Timeout for check of octets limit */
  243. #define PPP_OCTETS_DIRECTION_SUM 0
  244. #define PPP_OCTETS_DIRECTION_IN 1
  245. #define PPP_OCTETS_DIRECTION_OUT 2
  246. #define PPP_OCTETS_DIRECTION_MAXOVERAL 3
  247. /* same as previos, but little different on RADIUS side */
  248. #define PPP_OCTETS_DIRECTION_MAXSESSION 4
  249. #endif
  250. /* Data input may be used by CCP and ECP, remove this entry
  251. * from struct protent to save some flash
  252. */
  253. #define PPP_DATAINPUT 0
  254. /*
  255. * The following struct gives the addresses of procedures to call
  256. * for a particular protocol.
  257. */
  258. struct protent {
  259. u_short protocol; /* PPP protocol number */
  260. /* Initialization procedure */
  261. void (*init) (ppp_pcb *pcb);
  262. /* Process a received packet */
  263. void (*input) (ppp_pcb *pcb, u_char *pkt, int len);
  264. /* Process a received protocol-reject */
  265. void (*protrej) (ppp_pcb *pcb);
  266. /* Lower layer has come up */
  267. void (*lowerup) (ppp_pcb *pcb);
  268. /* Lower layer has gone down */
  269. void (*lowerdown) (ppp_pcb *pcb);
  270. /* Open the protocol */
  271. void (*open) (ppp_pcb *pcb);
  272. /* Close the protocol */
  273. void (*close) (ppp_pcb *pcb, const char *reason);
  274. #if PRINTPKT_SUPPORT
  275. /* Print a packet in readable form */
  276. int (*printpkt) (const u_char *pkt, int len,
  277. void (*printer) (void *, const char *, ...),
  278. void *arg);
  279. #endif /* PRINTPKT_SUPPORT */
  280. #if PPP_DATAINPUT
  281. /* Process a received data packet */
  282. void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len);
  283. #endif /* PPP_DATAINPUT */
  284. #if PRINTPKT_SUPPORT
  285. const char *name; /* Text name of protocol */
  286. const char *data_name; /* Text name of corresponding data protocol */
  287. #endif /* PRINTPKT_SUPPORT */
  288. #if PPP_OPTIONS
  289. option_t *options; /* List of command-line options */
  290. /* Check requested options, assign defaults */
  291. void (*check_options) (void);
  292. #endif /* PPP_OPTIONS */
  293. #if DEMAND_SUPPORT
  294. /* Configure interface for demand-dial */
  295. int (*demand_conf) (int unit);
  296. /* Say whether to bring up link for this pkt */
  297. int (*active_pkt) (u_char *pkt, int len);
  298. #endif /* DEMAND_SUPPORT */
  299. };
  300. /* Table of pointers to supported protocols */
  301. extern const struct protent* const protocols[];
  302. /* Values for auth_pending, auth_done */
  303. #if PAP_SUPPORT
  304. #define PAP_WITHPEER 0x1
  305. #define PAP_PEER 0x2
  306. #endif /* PAP_SUPPORT */
  307. #if CHAP_SUPPORT
  308. #define CHAP_WITHPEER 0x4
  309. #define CHAP_PEER 0x8
  310. #endif /* CHAP_SUPPORT */
  311. #if EAP_SUPPORT
  312. #define EAP_WITHPEER 0x10
  313. #define EAP_PEER 0x20
  314. #endif /* EAP_SUPPORT */
  315. /* Values for auth_done only */
  316. #if CHAP_SUPPORT
  317. #define CHAP_MD5_WITHPEER 0x40
  318. #define CHAP_MD5_PEER 0x80
  319. #if MSCHAP_SUPPORT
  320. #define CHAP_MS_SHIFT 8 /* LSB position for MS auths */
  321. #define CHAP_MS_WITHPEER 0x100
  322. #define CHAP_MS_PEER 0x200
  323. #define CHAP_MS2_WITHPEER 0x400
  324. #define CHAP_MS2_PEER 0x800
  325. #endif /* MSCHAP_SUPPORT */
  326. #endif /* CHAP_SUPPORT */
  327. /* Supported CHAP protocols */
  328. #if CHAP_SUPPORT
  329. #if MSCHAP_SUPPORT
  330. #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
  331. #else /* MSCHAP_SUPPORT */
  332. #define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5)
  333. #endif /* MSCHAP_SUPPORT */
  334. #else /* CHAP_SUPPORT */
  335. #define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE)
  336. #endif /* CHAP_SUPPORT */
  337. #if PPP_STATS_SUPPORT
  338. /*
  339. * PPP statistics structure
  340. */
  341. struct pppd_stats {
  342. unsigned int bytes_in;
  343. unsigned int bytes_out;
  344. unsigned int pkts_in;
  345. unsigned int pkts_out;
  346. };
  347. #endif /* PPP_STATS_SUPPORT */
  348. /*
  349. * PPP private functions
  350. */
  351. /*
  352. * Functions called from lwIP core.
  353. */
  354. /* initialize the PPP subsystem */
  355. int ppp_init(void);
  356. /*
  357. * Functions called from PPP link protocols.
  358. */
  359. /* Create a new PPP control block */
  360. ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb,
  361. ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
  362. /* Initiate LCP open request */
  363. void ppp_start(ppp_pcb *pcb);
  364. /* Called when link failed to setup */
  365. void ppp_link_failed(ppp_pcb *pcb);
  366. /* Called when link is normally down (i.e. it was asked to end) */
  367. void ppp_link_end(ppp_pcb *pcb);
  368. /* function called to process input packet */
  369. void ppp_input(ppp_pcb *pcb, struct pbuf *pb);
  370. /* helper function, merge a pbuf chain into one pbuf */
  371. struct pbuf *ppp_singlebuf(struct pbuf *p);
  372. /*
  373. * Functions called by PPP protocols.
  374. */
  375. /* function called by all PPP subsystems to send packets */
  376. err_t ppp_write(ppp_pcb *pcb, struct pbuf *p);
  377. /* functions called by auth.c link_terminated() */
  378. void ppp_link_terminated(ppp_pcb *pcb);
  379. void new_phase(ppp_pcb *pcb, int p);
  380. int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp);
  381. int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp);
  382. #if PPP_IPV4_SUPPORT
  383. int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask);
  384. int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr);
  385. #if 0 /* UNUSED - PROXY ARP */
  386. int sifproxyarp(ppp_pcb *pcb, u32_t his_adr);
  387. int cifproxyarp(ppp_pcb *pcb, u32_t his_adr);
  388. #endif /* UNUSED - PROXY ARP */
  389. #if LWIP_DNS
  390. int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
  391. int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2);
  392. #endif /* LWIP_DNS */
  393. #if VJ_SUPPORT
  394. int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid);
  395. #endif /* VJ_SUPPORT */
  396. int sifup(ppp_pcb *pcb);
  397. int sifdown (ppp_pcb *pcb);
  398. u32_t get_mask(u32_t addr);
  399. #endif /* PPP_IPV4_SUPPORT */
  400. #if PPP_IPV6_SUPPORT
  401. int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
  402. int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64);
  403. int sif6up(ppp_pcb *pcb);
  404. int sif6down (ppp_pcb *pcb);
  405. #endif /* PPP_IPV6_SUPPORT */
  406. #if DEMAND_SUPPORT
  407. int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode);
  408. #endif /* DEMAND_SUPPORt */
  409. void netif_set_mtu(ppp_pcb *pcb, int mtu);
  410. int netif_get_mtu(ppp_pcb *pcb);
  411. #if CCP_SUPPORT
  412. #if 0 /* unused */
  413. int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit);
  414. #endif /* unused */
  415. void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method);
  416. void ccp_reset_comp(ppp_pcb *pcb);
  417. void ccp_reset_decomp(ppp_pcb *pcb);
  418. #if 0 /* unused */
  419. int ccp_fatal_error(ppp_pcb *pcb);
  420. #endif /* unused */
  421. #endif /* CCP_SUPPORT */
  422. #if PPP_IDLETIMELIMIT
  423. int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip);
  424. #endif /* PPP_IDLETIMELIMIT */
  425. #if DEMAND_SUPPORT
  426. int get_loop_output(void);
  427. #endif /* DEMAND_SUPPORT */
  428. /* Optional protocol names list, to make our messages a little more informative. */
  429. #if PPP_PROTOCOLNAME
  430. const char * protocol_name(int proto);
  431. #endif /* PPP_PROTOCOLNAME */
  432. /* Optional stats support, to get some statistics on the PPP interface */
  433. #if PPP_STATS_SUPPORT
  434. void print_link_stats(void); /* Print stats, if available */
  435. void reset_link_stats(int u); /* Reset (init) stats when link goes up */
  436. void update_link_stats(int u); /* Get stats at link termination */
  437. #endif /* PPP_STATS_SUPPORT */
  438. /*
  439. * Inline versions of get/put char/short/long.
  440. * Pointer is advanced; we assume that both arguments
  441. * are lvalues and will already be in registers.
  442. * cp MUST be u_char *.
  443. */
  444. #define GETCHAR(c, cp) { \
  445. (c) = *(cp)++; \
  446. }
  447. #define PUTCHAR(c, cp) { \
  448. *(cp)++ = (u_char) (c); \
  449. }
  450. #define GETSHORT(s, cp) { \
  451. (s) = *(cp)++ << 8; \
  452. (s) |= *(cp)++; \
  453. }
  454. #define PUTSHORT(s, cp) { \
  455. *(cp)++ = (u_char) ((s) >> 8); \
  456. *(cp)++ = (u_char) (s); \
  457. }
  458. #define GETLONG(l, cp) { \
  459. (l) = *(cp)++ << 8; \
  460. (l) |= *(cp)++; (l) <<= 8; \
  461. (l) |= *(cp)++; (l) <<= 8; \
  462. (l) |= *(cp)++; \
  463. }
  464. #define PUTLONG(l, cp) { \
  465. *(cp)++ = (u_char) ((l) >> 24); \
  466. *(cp)++ = (u_char) ((l) >> 16); \
  467. *(cp)++ = (u_char) ((l) >> 8); \
  468. *(cp)++ = (u_char) (l); \
  469. }
  470. #define INCPTR(n, cp) ((cp) += (n))
  471. #define DECPTR(n, cp) ((cp) -= (n))
  472. /*
  473. * System dependent definitions for user-level 4.3BSD UNIX implementation.
  474. */
  475. #define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0)
  476. #define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0)
  477. #define UNTIMEOUT(f, a) sys_untimeout((f), (a))
  478. #define BZERO(s, n) memset(s, 0, n)
  479. #define BCMP(s1, s2, l) memcmp(s1, s2, l)
  480. #define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); }
  481. /*
  482. * MAKEHEADER - Add Header fields to a packet.
  483. */
  484. #define MAKEHEADER(p, t) { \
  485. PUTCHAR(PPP_ALLSTATIONS, p); \
  486. PUTCHAR(PPP_UI, p); \
  487. PUTSHORT(t, p); }
  488. /* Procedures exported from auth.c */
  489. void link_required(ppp_pcb *pcb); /* we are starting to use the link */
  490. void link_terminated(ppp_pcb *pcb); /* we are finished with the link */
  491. void link_down(ppp_pcb *pcb); /* the LCP layer has left the Opened state */
  492. void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */
  493. void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */
  494. void start_networks(ppp_pcb *pcb); /* start all the network control protos */
  495. void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */
  496. #if PPP_AUTH_SUPPORT
  497. #if PPP_SERVER
  498. int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int passwdlen, const char **msg, int *msglen);
  499. /* check the user name and passwd against configuration */
  500. void auth_peer_fail(ppp_pcb *pcb, int protocol);
  501. /* peer failed to authenticate itself */
  502. void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen);
  503. /* peer successfully authenticated itself */
  504. #endif /* PPP_SERVER */
  505. void auth_withpeer_fail(ppp_pcb *pcb, int protocol);
  506. /* we failed to authenticate ourselves */
  507. void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor);
  508. /* we successfully authenticated ourselves */
  509. #endif /* PPP_AUTH_SUPPORT */
  510. void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */
  511. void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */
  512. void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */
  513. #if PPP_AUTH_SUPPORT
  514. int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server);
  515. /* get "secret" for chap */
  516. #endif /* PPP_AUTH_SUPPORT */
  517. /* Procedures exported from ipcp.c */
  518. /* int parse_dotted_ip (char *, u32_t *); */
  519. /* Procedures exported from demand.c */
  520. #if DEMAND_SUPPORT
  521. void demand_conf (void); /* config interface(s) for demand-dial */
  522. void demand_block (void); /* set all NPs to queue up packets */
  523. void demand_unblock (void); /* set all NPs to pass packets */
  524. void demand_discard (void); /* set all NPs to discard packets */
  525. void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/
  526. int loop_chars (unsigned char *, int); /* process chars from loopback */
  527. int loop_frame (unsigned char *, int); /* should we bring link up? */
  528. #endif /* DEMAND_SUPPORT */
  529. /* Procedures exported from multilink.c */
  530. #ifdef HAVE_MULTILINK
  531. void mp_check_options (void); /* Check multilink-related options */
  532. int mp_join_bundle (void); /* join our link to an appropriate bundle */
  533. void mp_exit_bundle (void); /* have disconnected our link from bundle */
  534. void mp_bundle_terminated (void);
  535. char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */
  536. int str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */
  537. #else
  538. #define mp_bundle_terminated() /* nothing */
  539. #define mp_exit_bundle() /* nothing */
  540. #define doing_multilink 0
  541. #define multilink_master 0
  542. #endif
  543. /* Procedures exported from utils.c. */
  544. void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg); /* Format a string for output */
  545. int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* sprintf++ */
  546. int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */
  547. size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */
  548. size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */
  549. void ppp_dbglog(const char *fmt, ...); /* log a debug message */
  550. void ppp_info(const char *fmt, ...); /* log an informational message */
  551. void ppp_notice(const char *fmt, ...); /* log a notice-level message */
  552. void ppp_warn(const char *fmt, ...); /* log a warning message */
  553. void ppp_error(const char *fmt, ...); /* log an error message */
  554. void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */
  555. #if PRINTPKT_SUPPORT
  556. void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len);
  557. /* dump packet to debug log if interesting */
  558. #endif /* PRINTPKT_SUPPORT */
  559. #endif /* PPP_SUPPORT */
  560. #endif /* LWIP_HDR_PPP_IMPL_H */