ppp_oe.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*****************************************************************************
  2. * ppp_oe.h - PPP Over Ethernet implementation for lwIP.
  3. *
  4. * Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
  5. *
  6. * The authors hereby grant permission to use, copy, modify, distribute,
  7. * and license this software and its documentation for any purpose, provided
  8. * that existing copyright notices are retained in all copies and that this
  9. * notice and the following disclaimer are included verbatim in any
  10. * distributions. No written agreement, license, or royalty fee is required
  11. * for any of the authorized uses.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
  14. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. ******************************************************************************
  25. * REVISION HISTORY
  26. *
  27. * 06-01-01 Marc Boucher <marc@mbsi.ca>
  28. * Ported to lwIP.
  29. *****************************************************************************/
  30. /* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
  31. /*-
  32. * Copyright (c) 2002 The NetBSD Foundation, Inc.
  33. * All rights reserved.
  34. *
  35. * This code is derived from software contributed to The NetBSD Foundation
  36. * by Martin Husemann <martin@NetBSD.org>.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. * 1. Redistributions of source code must retain the above copyright
  42. * notice, this list of conditions and the following disclaimer.
  43. * 2. Redistributions in binary form must reproduce the above copyright
  44. * notice, this list of conditions and the following disclaimer in the
  45. * documentation and/or other materials provided with the distribution.
  46. * 3. All advertising materials mentioning features or use of this software
  47. * must display the following acknowledgement:
  48. * This product includes software developed by the NetBSD
  49. * Foundation, Inc. and its contributors.
  50. * 4. Neither the name of The NetBSD Foundation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  55. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  56. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  57. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  58. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  59. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  60. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  61. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  62. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  63. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  64. * POSSIBILITY OF SUCH DAMAGE.
  65. */
  66. #ifndef PPP_OE_H
  67. #define PPP_OE_H
  68. #include "lwip/opt.h"
  69. #if PPPOE_SUPPORT > 0
  70. #include "netif/etharp.h"
  71. #ifdef PACK_STRUCT_USE_INCLUDES
  72. # include "arch/bpstruct.h"
  73. #endif
  74. PACK_STRUCT_BEGIN
  75. struct pppoehdr {
  76. PACK_STRUCT_FIELD(u8_t vertype);
  77. PACK_STRUCT_FIELD(u8_t code);
  78. PACK_STRUCT_FIELD(u16_t session);
  79. PACK_STRUCT_FIELD(u16_t plen);
  80. } PACK_STRUCT_STRUCT;
  81. PACK_STRUCT_END
  82. #ifdef PACK_STRUCT_USE_INCLUDES
  83. # include "arch/epstruct.h"
  84. #endif
  85. #ifdef PACK_STRUCT_USE_INCLUDES
  86. # include "arch/bpstruct.h"
  87. #endif
  88. PACK_STRUCT_BEGIN
  89. struct pppoetag {
  90. PACK_STRUCT_FIELD(u16_t tag);
  91. PACK_STRUCT_FIELD(u16_t len);
  92. } PACK_STRUCT_STRUCT;
  93. PACK_STRUCT_END
  94. #ifdef PACK_STRUCT_USE_INCLUDES
  95. # include "arch/epstruct.h"
  96. #endif
  97. #define PPPOE_STATE_INITIAL 0
  98. #define PPPOE_STATE_PADI_SENT 1
  99. #define PPPOE_STATE_PADR_SENT 2
  100. #define PPPOE_STATE_SESSION 3
  101. #define PPPOE_STATE_CLOSING 4
  102. /* passive */
  103. #define PPPOE_STATE_PADO_SENT 1
  104. #define PPPOE_HEADERLEN sizeof(struct pppoehdr)
  105. #define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
  106. #define PPPOE_TAG_EOL 0x0000 /* end of list */
  107. #define PPPOE_TAG_SNAME 0x0101 /* service name */
  108. #define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */
  109. #define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */
  110. #define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */
  111. #define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */
  112. #define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */
  113. #define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */
  114. #define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
  115. #define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */
  116. #define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
  117. #define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
  118. #define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
  119. #define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
  120. #define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
  121. #ifndef ETHERMTU
  122. #define ETHERMTU 1500
  123. #endif
  124. /* two byte PPP protocol discriminator, then IP data */
  125. #define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2)
  126. #ifndef PPPOE_MAX_AC_COOKIE_LEN
  127. #define PPPOE_MAX_AC_COOKIE_LEN 64
  128. #endif
  129. struct pppoe_softc {
  130. struct pppoe_softc *next;
  131. struct netif *sc_ethif; /* ethernet interface we are using */
  132. int sc_pd; /* ppp unit number */
  133. void (*sc_linkStatusCB)(int pd, int up);
  134. int sc_state; /* discovery phase or session connected */
  135. struct eth_addr sc_dest; /* hardware address of concentrator */
  136. u16_t sc_session; /* PPPoE session id */
  137. #ifdef PPPOE_TODO
  138. char *sc_service_name; /* if != NULL: requested name of service */
  139. char *sc_concentrator_name; /* if != NULL: requested concentrator id */
  140. #endif /* PPPOE_TODO */
  141. u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */
  142. size_t sc_ac_cookie_len; /* length of cookie data */
  143. #ifdef PPPOE_SERVER
  144. u8_t *sc_hunique; /* content of host unique we must echo back */
  145. size_t sc_hunique_len; /* length of host unique */
  146. #endif
  147. int sc_padi_retried; /* number of PADI retries already done */
  148. int sc_padr_retried; /* number of PADR retries already done */
  149. };
  150. #define pppoe_init() /* compatibility define, no initialization needed */
  151. err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr);
  152. err_t pppoe_destroy(struct netif *ifp);
  153. int pppoe_connect(struct pppoe_softc *sc);
  154. void pppoe_disconnect(struct pppoe_softc *sc);
  155. void pppoe_disc_input(struct netif *netif, struct pbuf *p);
  156. void pppoe_data_input(struct netif *netif, struct pbuf *p);
  157. err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb);
  158. /** used in ppp.c */
  159. #define PPPOE_HDRLEN (sizeof(struct eth_hdr) + PPPOE_HEADERLEN)
  160. #endif /* PPPOE_SUPPORT */
  161. #endif /* PPP_OE_H */