mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Add L2 PPP and PPPoE
This commit is contained in:
1 parent
ae5a2263ac
commit
70650fedcf
23 files changed
+2019
-909
No files matched your search
@@ -5,11 +5,11 @@
|
||||
#if MG_ENABLE_TCPIP
|
||||
|
||||
// L2 API
|
||||
void mg_l2_init(enum mg_l2type type, uint8_t *addr, uint16_t *mtu,
|
||||
uint16_t *framesize);
|
||||
void mg_l2_init(struct mg_tcpip_if *ifp);
|
||||
bool mg_l2_poll(struct mg_tcpip_if *ifp, bool expired_1000ms);
|
||||
uint8_t *mg_l2_header(enum mg_l2type type, enum mg_l2proto proto, uint8_t *src,
|
||||
uint8_t *dst, uint8_t *frame);
|
||||
size_t mg_l2_footer(enum mg_l2type type, size_t len, uint8_t *frame);
|
||||
size_t mg_l2_footer(enum mg_l2type type, size_t len, uint8_t *cur);
|
||||
bool mg_l2_rx(struct mg_tcpip_if *ifp, enum mg_l2proto *proto,
|
||||
struct mg_str *pay, struct mg_str *raw);
|
||||
// TODO(): ? bool mg_l2_rx(enum mg_l2type type, struct mg_l2opts *opts, uint8_t
|
||||
@@ -17,24 +17,31 @@ bool mg_l2_rx(struct mg_tcpip_if *ifp, enum mg_l2proto *proto,
|
||||
uint8_t *mg_l2_getaddr(enum mg_l2type type, uint8_t *frame);
|
||||
uint8_t *mg_l2_mapip(enum mg_l2type type, enum mg_l2addrtype addrtype,
|
||||
struct mg_addr *ip);
|
||||
#if MG_ENABLE_IPV6
|
||||
bool mg_l2_genip6(enum mg_l2type type, uint64_t *ip6, uint8_t prefix_len,
|
||||
uint8_t *addr);
|
||||
bool mg_l2_ip6get(enum mg_l2type type, uint8_t *addr, uint8_t *opts,
|
||||
uint8_t len);
|
||||
uint8_t mg_l2_ip6put(enum mg_l2type type, uint8_t *addr, uint8_t *opts);
|
||||
#endif
|
||||
size_t mg_l2_driver_output(struct mg_tcpip_if *ifp, size_t len);
|
||||
|
||||
// clang-format off
|
||||
extern void mg_l2_eth_init(struct mg_l2addr *, uint16_t *, uint16_t *);
|
||||
extern void mg_l2_eth_init(struct mg_tcpip_if *);
|
||||
extern bool mg_l2_eth_poll(struct mg_tcpip_if *, bool);
|
||||
extern uint8_t *mg_l2_eth_header(enum mg_l2proto, struct mg_l2addr *, struct mg_l2addr *, uint8_t *);
|
||||
extern size_t mg_l2_eth_footer(size_t, uint8_t *);
|
||||
extern bool mg_l2_eth_rx(struct mg_tcpip_if *, enum mg_l2proto *, struct mg_str *, struct mg_str *);
|
||||
extern struct mg_l2addr *mg_l2_eth_getaddr(uint8_t *);
|
||||
extern struct mg_l2addr *mg_l2_eth_mapip(enum mg_l2addrtype, struct mg_addr *);
|
||||
#if MG_ENABLE_IPV6
|
||||
extern bool mg_l2_eth_genip6(uint64_t *, uint8_t, struct mg_l2addr *);
|
||||
extern bool mg_l2_eth_ip6get(struct mg_l2addr *, uint8_t *, uint8_t);
|
||||
extern uint8_t mg_l2_eth_ip6put(struct mg_l2addr *, uint8_t *);
|
||||
#endif
|
||||
|
||||
extern void mg_l2_ppp_init(struct mg_l2addr *, uint16_t *, uint16_t *);
|
||||
extern void mg_l2_ppp_init(struct mg_tcpip_if *);
|
||||
extern bool mg_l2_ppp_poll(struct mg_tcpip_if *, bool);
|
||||
extern uint8_t *mg_l2_ppp_header(enum mg_l2proto, struct mg_l2addr *, struct mg_l2addr *, uint8_t *);
|
||||
extern size_t mg_l2_ppp_footer(size_t, uint8_t *);
|
||||
extern bool mg_l2_ppp_rx(struct mg_tcpip_if *, enum mg_l2proto *, struct mg_str *, struct mg_str *);
|
||||
@@ -45,8 +52,14 @@ extern bool mg_l2_ppp_genip6(uint64_t *, uint8_t, struct mg_l2addr *);
|
||||
extern bool mg_l2_ppp_ip6get(struct mg_l2addr *, uint8_t *, uint8_t);
|
||||
extern uint8_t mg_l2_ppp_ip6put(struct mg_l2addr *, uint8_t *);
|
||||
#endif
|
||||
extern void mg_l2_pppoe_init(struct mg_tcpip_if *);
|
||||
extern bool mg_l2_pppoe_poll(struct mg_tcpip_if *, bool);
|
||||
extern uint8_t *mg_l2_pppoe_header(enum mg_l2proto, struct mg_l2addr *, struct mg_l2addr *, uint8_t *);
|
||||
extern size_t mg_l2_pppoe_footer(size_t, uint8_t *);
|
||||
extern bool mg_l2_pppoe_rx(struct mg_tcpip_if *, enum mg_l2proto *, struct mg_str *, struct mg_str *);
|
||||
|
||||
typedef void (*l2_init_fn)(struct mg_l2addr *, uint16_t *, uint16_t *);
|
||||
typedef void (*l2_init_fn)(struct mg_tcpip_if *);
|
||||
typedef bool (*l2_poll_fn)(struct mg_tcpip_if *, bool);
|
||||
typedef uint8_t *((*l2_header_fn)(enum mg_l2proto, struct mg_l2addr *, struct mg_l2addr *, uint8_t *));
|
||||
typedef size_t (*l2_footer_fn)(size_t, uint8_t *);
|
||||
typedef bool (*l2_rx_fn)(struct mg_tcpip_if *, enum mg_l2proto *, struct mg_str *, struct mg_str *);
|
||||
@@ -59,22 +72,25 @@ typedef uint8_t (*l2_ip6put_fn)(struct mg_l2addr *, uint8_t *);
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
static const l2_init_fn l2_init[] = {mg_l2_eth_init, mg_l2_ppp_init};
|
||||
static const l2_header_fn l2_header[] = {mg_l2_eth_header, mg_l2_ppp_header};
|
||||
static const l2_footer_fn l2_footer[] = {mg_l2_eth_footer, mg_l2_ppp_footer};
|
||||
static const l2_rx_fn l2_rx[] = {mg_l2_eth_rx, mg_l2_ppp_rx};
|
||||
static const l2_getaddr_fn l2_getaddr[] = {mg_l2_eth_getaddr,
|
||||
mg_l2_ppp_getaddr};
|
||||
static const l2_mapip_fn l2_mapip[] = {mg_l2_eth_mapip, mg_l2_ppp_mapip};
|
||||
static const l2_init_fn l2_init[] = {mg_l2_eth_init, mg_l2_ppp_init, mg_l2_pppoe_init};
|
||||
static const l2_poll_fn l2_poll[] = {mg_l2_eth_poll, mg_l2_ppp_poll, mg_l2_pppoe_poll};
|
||||
static const l2_header_fn l2_header[] = {mg_l2_eth_header, mg_l2_ppp_header, mg_l2_pppoe_header};
|
||||
static const l2_footer_fn l2_footer[] = {mg_l2_eth_footer, mg_l2_ppp_footer, mg_l2_pppoe_footer};
|
||||
static const l2_rx_fn l2_rx[] = {mg_l2_eth_rx, mg_l2_ppp_rx, mg_l2_pppoe_rx};
|
||||
static const l2_getaddr_fn l2_getaddr[] = {mg_l2_eth_getaddr, mg_l2_ppp_getaddr, mg_l2_ppp_getaddr};
|
||||
static const l2_mapip_fn l2_mapip[] = {mg_l2_eth_mapip, mg_l2_ppp_mapip, mg_l2_ppp_mapip};
|
||||
#if MG_ENABLE_IPV6
|
||||
static const l2_genip6_fn l2_genip6[] = {mg_l2_eth_genip6, mg_l2_ppp_genip6};
|
||||
static const l2_ip6get_fn l2_ip6get[] = {mg_l2_eth_ip6get, mg_l2_ppp_ip6get};
|
||||
static const l2_ip6put_fn l2_ip6put[] = {mg_l2_eth_ip6put, mg_l2_ppp_ip6put};
|
||||
static const l2_genip6_fn l2_genip6[] = {mg_l2_eth_genip6, mg_l2_ppp_genip6, mg_l2_ppp_genip6};
|
||||
static const l2_ip6get_fn l2_ip6get[] = {mg_l2_eth_ip6get, mg_l2_ppp_ip6get, mg_l2_ppp_ip6get};
|
||||
static const l2_ip6put_fn l2_ip6put[] = {mg_l2_eth_ip6put, mg_l2_ppp_ip6put, mg_l2_ppp_ip6put};
|
||||
#endif
|
||||
|
||||
void mg_l2_init(enum mg_l2type type, uint8_t *addr, uint16_t *mtu,
|
||||
uint16_t *framesize) {
|
||||
l2_init[type]((struct mg_l2addr *) addr, mtu, framesize);
|
||||
void mg_l2_init(struct mg_tcpip_if *ifp) {
|
||||
l2_init[ifp->l2type](ifp);
|
||||
}
|
||||
|
||||
bool mg_l2_poll(struct mg_tcpip_if *ifp, bool expired_1000ms) {
|
||||
return l2_poll[ifp->l2type](ifp, expired_1000ms);
|
||||
}
|
||||
|
||||
uint8_t *mg_l2_header(enum mg_l2type type, enum mg_l2proto proto, uint8_t *src,
|
||||
@@ -118,4 +134,10 @@ uint8_t mg_l2_ip6put(enum mg_l2type type, uint8_t *addr, uint8_t *opts) {
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t mg_l2_driver_output(struct mg_tcpip_if *ifp, size_t len) {
|
||||
size_t n = ifp->driver->tx(ifp->tx.buf, len, ifp);
|
||||
if (n == len) ifp->nsent++;
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user