ppp.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_H
  34. #define PPP_H
  35. #include "lwip/opt.h"
  36. #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
  37. #include "lwip/def.h"
  38. #include "lwip/sio.h"
  39. #include "lwip/stats.h"
  40. #include "lwip/mem.h"
  41. #include "lwip/netif.h"
  42. #include "lwip/sys.h"
  43. #include "lwip/timers.h"
  44. #ifndef __u_char_defined
  45. /* Type definitions for BSD code. */
  46. typedef unsigned long u_long;
  47. typedef unsigned int u_int;
  48. typedef unsigned short u_short;
  49. typedef unsigned char u_char;
  50. #endif
  51. /*************************
  52. *** PUBLIC DEFINITIONS ***
  53. *************************/
  54. /* Error codes. */
  55. #define PPPERR_NONE 0 /* No error. */
  56. #define PPPERR_PARAM -1 /* Invalid parameter. */
  57. #define PPPERR_OPEN -2 /* Unable to open PPP session. */
  58. #define PPPERR_DEVICE -3 /* Invalid I/O device for PPP. */
  59. #define PPPERR_ALLOC -4 /* Unable to allocate resources. */
  60. #define PPPERR_USER -5 /* User interrupt. */
  61. #define PPPERR_CONNECT -6 /* Connection lost. */
  62. #define PPPERR_AUTHFAIL -7 /* Failed authentication challenge. */
  63. #define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
  64. /*
  65. * PPP IOCTL commands.
  66. */
  67. /*
  68. * Get the up status - 0 for down, non-zero for up. The argument must
  69. * point to an int.
  70. */
  71. #define PPPCTLG_UPSTATUS 100 /* Get the up status - 0 down else up */
  72. #define PPPCTLS_ERRCODE 101 /* Set the error code */
  73. #define PPPCTLG_ERRCODE 102 /* Get the error code */
  74. #define PPPCTLG_FD 103 /* Get the fd associated with the ppp */
  75. /************************
  76. *** PUBLIC DATA TYPES ***
  77. ************************/
  78. struct ppp_addrs {
  79. ip_addr_t our_ipaddr, his_ipaddr, netmask, dns1, dns2;
  80. };
  81. /***********************
  82. *** PUBLIC FUNCTIONS ***
  83. ***********************/
  84. /* Initialize the PPP subsystem. */
  85. void pppInit(void);
  86. /* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
  87. * RFC 1994 says:
  88. *
  89. * In practice, within or associated with each PPP server, there is a
  90. * database which associates "user" names with authentication
  91. * information ("secrets"). It is not anticipated that a particular
  92. * named user would be authenticated by multiple methods. This would
  93. * make the user vulnerable to attacks which negotiate the least secure
  94. * method from among a set (such as PAP rather than CHAP). If the same
  95. * secret was used, PAP would reveal the secret to be used later with
  96. * CHAP.
  97. *
  98. * Instead, for each user name there should be an indication of exactly
  99. * one method used to authenticate that user name. If a user needs to
  100. * make use of different authentication methods under different
  101. * circumstances, then distinct user names SHOULD be employed, each of
  102. * which identifies exactly one authentication method.
  103. *
  104. */
  105. enum pppAuthType {
  106. PPPAUTHTYPE_NONE,
  107. PPPAUTHTYPE_ANY,
  108. PPPAUTHTYPE_PAP,
  109. PPPAUTHTYPE_CHAP
  110. };
  111. void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
  112. /* Link status callback function prototype */
  113. typedef void (*pppLinkStatusCB_fn)(void *ctx, int errCode, void *arg);
  114. #if PPPOS_SUPPORT
  115. /*
  116. * Open a new PPP connection using the given serial I/O device.
  117. * This initializes the PPP control block but does not
  118. * attempt to negotiate the LCP session.
  119. * Return a new PPP connection descriptor on success or
  120. * an error code (negative) on failure.
  121. */
  122. int pppOverSerialOpen(sio_fd_t fd, pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx);
  123. #endif /* PPPOS_SUPPORT */
  124. #if PPPOE_SUPPORT
  125. /*
  126. * Open a new PPP Over Ethernet (PPPOE) connection.
  127. */
  128. int pppOverEthernetOpen(struct netif *ethif, const char *service_name, const char *concentrator_name,
  129. pppLinkStatusCB_fn linkStatusCB, void *linkStatusCtx);
  130. #endif /* PPPOE_SUPPORT */
  131. /* for source code compatibility */
  132. #define pppOpen(fd,cb,ls) pppOverSerialOpen(fd,cb,ls)
  133. /*
  134. * Close a PPP connection and release the descriptor.
  135. * Any outstanding packets in the queues are dropped.
  136. * Return 0 on success, an error code on failure.
  137. */
  138. int pppClose(int pd);
  139. /*
  140. * Indicate to the PPP process that the line has disconnected.
  141. */
  142. void pppSigHUP(int pd);
  143. /*
  144. * Get and set parameters for the given connection.
  145. * Return 0 on success, an error code on failure.
  146. */
  147. int pppIOCtl(int pd, int cmd, void *arg);
  148. /*
  149. * Return the Maximum Transmission Unit for the given PPP connection.
  150. */
  151. u_short pppMTU(int pd);
  152. #if PPPOS_SUPPORT && !PPP_INPROC_OWNTHREAD
  153. /*
  154. * PPP over Serial: this is the input function to be called for received data.
  155. * If PPP_INPROC_OWNTHREAD==1, a seperate input thread using the blocking
  156. * sio_read() is used, so this is deactivated.
  157. */
  158. void pppos_input(int pd, u_char* data, int len);
  159. #endif /* PPPOS_SUPPORT && !PPP_INPROC_OWNTHREAD */
  160. #if LWIP_NETIF_STATUS_CALLBACK
  161. /* Set an lwIP-style status-callback for the selected PPP device */
  162. void ppp_set_netif_statuscallback(int pd, netif_status_callback_fn status_callback);
  163. #endif /* LWIP_NETIF_STATUS_CALLBACK */
  164. #if LWIP_NETIF_LINK_CALLBACK
  165. /* Set an lwIP-style link-callback for the selected PPP device */
  166. void ppp_set_netif_linkcallback(int pd, netif_status_callback_fn link_callback);
  167. #endif /* LWIP_NETIF_LINK_CALLBACK */
  168. #endif /* PPP_SUPPORT */
  169. #endif /* PPP_H */