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