-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Link layer] GNRC PPP #5470
[Link layer] GNRC PPP #5470
Changes from all commits
5f8e8c3
b20791f
34a6911
e1d8926
ee94688
682b21a
5a2bf1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (C) 2016 Fundación Inria Chile | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_netdev_netdev2 | ||
* @brief | ||
* @{ | ||
* | ||
* @file | ||
* @brief Definitions for netdev2 common Point to Point Protocol code | ||
* | ||
* @author José Ignacio Alamos | ||
*/ | ||
#ifndef NETDEV2_PPP_H | ||
#define NETDEV2_PPP_H | ||
|
||
#include "net/gnrc/ppp/prot.h" | ||
#include "net/gnrc/ppp/prot.h" | ||
#include "net/gnrc/ppp/lcp.h" | ||
#include "net/gnrc/ppp/pap.h" | ||
#include "net/gnrc/ppp/ipcp.h" | ||
#include "net/gnrc/nettype.h" | ||
#include "net/netopt.h" | ||
#include "net/netdev2.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if defined(MODULE_GNRC_PPP) || doxygen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* @brief class of custom driver control protocol | ||
* @extends ppp_protocol_t | ||
* | ||
* @details the DCP is in charge of monitoring the link and exchanging messages with the ppp device | ||
*/ | ||
typedef struct gnrc_ppp_dcp { | ||
gnrc_ppp_protocol_t prot; /**< base ppp_protocol_t object */ | ||
msg_t timer_msg; /**< msg struct for handling timeouts messages */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please align doc |
||
xtimer_t xtimer; /**< xtimer struct for sending timeout messages */ | ||
uint8_t dead_counter; /**< when reaches zero, the link is assumed to be dead */ | ||
} gnrc_ppp_dcp_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why define that here and not in |
||
#endif | ||
|
||
|
||
/** | ||
* @brief Extended structure to hold PPP driver state | ||
* | ||
* @extends netdev2_t | ||
* | ||
* Supposed to be extended by driver implementations. | ||
* The extended structure should contain all variable driver state. | ||
*/ | ||
typedef struct { | ||
netdev2_t netdev; /**< @ref netdev2_t base class */ | ||
#if defined(MODULE_GNRC_PPP) || doxygen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* @brief PPP specific fields | ||
* @{ | ||
*/ | ||
gnrc_ppp_dcp_t dcp; /**< Control protocol for driver */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please align doc |
||
gnrc_ppp_lcp_t lcp; /**< Link Control Protocol */ | ||
gnrc_ppp_pap_t pap; /**< Password Authentication Protocol */ | ||
gnrc_ppp_ipcp_t ipcp; /**< IPv4 Network Control Protocol */ | ||
gnrc_ppp_ipv4_t ipv4; /**< Handler for IPv4 packets */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cast these to |
||
#endif | ||
} netdev2_ppp_t; | ||
|
||
|
||
/** | ||
* @brief Fallback function for netdev2 PPP devices' _get function | ||
* | ||
* Supposed to be used by netdev2 drivers as default case. | ||
* | ||
* @param[in] dev network device descriptor | ||
* @param[in] opt option type | ||
* @param[out] value pointer to store the option's value in | ||
* @param[in] max_len maximal amount of byte that fit into @p value | ||
* | ||
* @return number of bytes written to @p value | ||
* @return <0 on error | ||
*/ | ||
int netdev2_ppp_get(netdev2_ppp_t *dev, netopt_t opt, void *value, | ||
size_t max_len); | ||
|
||
/** | ||
* @brief Fallback function for netdev2 PPP devices' _set function | ||
* | ||
* | ||
* @param[in] dev network device descriptor | ||
* @param[in] opt option type | ||
* @param[in] value value to set | ||
* @param[in] value_len the length of @p value | ||
* | ||
* @return number of bytes used from @p value | ||
* @return <0 on error | ||
*/ | ||
int netdev2_ppp_set(netdev2_ppp_t *dev, netopt_t opt, void *value, | ||
size_t value_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* NETDEV2_PPP_H */ | ||
/** @} */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (C) Fundación Inria Chile 2017 | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup driver_netdev2_ppp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This group does not exist. Also it doesn't make sense to do this in a c-file, so please remove this line |
||
* @{ | ||
* | ||
* @file | ||
* @brief Common code for netdev2 ppp drivers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this line |
||
* | ||
* @author José Ignacio Alamos <jose.alamos@inria.cl> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <errno.h> | ||
|
||
#include "net/netdev2.h" | ||
#include "net/netdev2/ppp.h" | ||
|
||
#define ENABLE_DEBUG (0) | ||
#include "debug.h" | ||
|
||
int netdev2_ppp_get(netdev2_ppp_t *dev, netopt_t opt, void *value, size_t max_len) | ||
{ | ||
int res; | ||
switch (opt) { | ||
case NETOPT_PPP_LCP_STATE: | ||
*((uint8_t *) value) = ((gnrc_ppp_protocol_t*) &dev->lcp)->state; | ||
res = 0; | ||
break; | ||
case NETOPT_PPP_AUTH_STATE: | ||
*((uint8_t *) value) = ((gnrc_ppp_protocol_t*) &dev->pap)->state; | ||
res = 0; | ||
break; | ||
case NETOPT_PPP_IPCP_STATE: | ||
*((uint8_t *) value) = ((gnrc_ppp_protocol_t*) &dev->ipcp)->state; | ||
res = 0; | ||
break; | ||
case NETOPT_PPP_IS_IPV6_READY: | ||
res = ((gnrc_ppp_protocol_t*) &dev->ipv4)->state == PROTOCOL_UP; | ||
*((uint8_t *) value) = res; | ||
break; | ||
case NETOPT_DEVICE_TYPE: | ||
*((uint16_t*) value) = NETDEV2_TYPE_PPP; | ||
res = 2; | ||
break; | ||
case NETOPT_LINK_STATE: { | ||
gnrc_ppp_protocol_t *dcp = (gnrc_ppp_protocol_t *) &dev->dcp; | ||
*((netopt_enable_t *)value) = (dcp->state == PROTOCOL_DOWN) ? | ||
NETOPT_DISABLE : NETOPT_ENABLE; | ||
res = sizeof(netopt_enable_t); | ||
}; | ||
break; | ||
default: | ||
return -ENOTSUP; | ||
break; | ||
} | ||
return res; | ||
} | ||
|
||
int netdev2_ppp_set(netdev2_ppp_t *dev, netopt_t opt, void *value, size_t value_len) | ||
{ | ||
int res; | ||
switch (opt) { | ||
case NETOPT_TUNNEL_IPV4_ADDRESS: | ||
dev->ipv4.tunnel_addr = *((ipv4_addr_t *) value); | ||
res = 0; | ||
break; | ||
case NETOPT_TUNNEL_UDP_PORT: | ||
dev->ipv4.tunnel_port = *((uint16_t *) value); | ||
res = 0; | ||
break; | ||
case NETOPT_APN_USER: | ||
memcpy(dev->pap.username, value, value_len); | ||
dev->pap.user_size = value_len; | ||
res = 0; | ||
break; | ||
case NETOPT_APN_PASS: | ||
memcpy(dev->pap.password, value, value_len); | ||
dev->pap.pass_size = value_len; | ||
res = 0; | ||
break; | ||
case NETOPT_LINK_STATE: | ||
if (*((netopt_enable_t *)value) == NETOPT_DISABLE) { | ||
/* set link down in device context | ||
* should not require dispatch_ppp_msg */ | ||
} | ||
else { | ||
/* set link up in device context | ||
* should not require dispatch_ppp_msg */ | ||
} | ||
break; | ||
default: | ||
return -ENOTSUP; | ||
break; | ||
} | ||
return res; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) Fundación Inria Chile 2017 | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @addtogroup net_gnrc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
* @{ | ||
* | ||
* @file | ||
* @brief GNRC to PPP netdev2 glue code interface | ||
* | ||
* @author José Ignacio Alamos <jose.alamos@inria.cl> | ||
*/ | ||
|
||
#ifndef GNRC_NETDEV2_PPP_H_ | ||
#define GNRC_NETDEV2_PPP_H_ | ||
|
||
#include "net/netdev2/ppp.h" | ||
#include "net/gnrc/netdev2.h" | ||
|
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Initialize GNRC handler for netdev2 PPP devices | ||
* | ||
* @param[out] gnrc_netdev2 gnrc_netdev2 struct to initialize | ||
* @param[in] dev PPP device to handle | ||
*/ | ||
void gnrc_netdev2_ppp_init(gnrc_netdev2_t *gnrc_netdev2, netdev2_ppp_t *dev); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* GNRC_NETDEV2_PPP_H_ */ | ||
/** @} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all these separate headers: may I propose a
net/gnrc/ppp.h
header that includes all these headers (there you can also@defgroup net_gnrc_ppp
instead of duplicate define it multiple times [see below])