-
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
gnrc_netif2: provide raw adaption layer (for e.g. SLIP) #7462
Merged
miri64
merged 2 commits into
RIOT-OS:gnrc_netif2_integration/master
from
miri64:gnrc_netif2/feat/raw
Nov 15, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2017 Freie Universität Berlin | ||
* | ||
* 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 net_gnrc_netif2 | ||
* @{ | ||
* | ||
* @file | ||
* @brief Raw (i.e. raw IP packets without link-layer information) adaptation | ||
* for @ref net_gnrc_netif2 | ||
* | ||
* @author Martine Lenders <[email protected]> | ||
*/ | ||
#ifndef NET_GNRC_NETIF2_RAW_H | ||
#define NET_GNRC_NETIF2_RAW_H | ||
|
||
#include "net/gnrc/netif2.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Creates a raw network interface | ||
* | ||
* @param[in] stack The stack for the network interface's thread. | ||
* @param[in] stacksize Size of @p stack. | ||
* @param[in] priority Priority for the network interface's thread. | ||
* @param[in] name Name for the network interface. May be NULL. | ||
* @param[in] dev Device for the interface. | ||
* | ||
* @see @ref gnrc_netif2_create() | ||
* | ||
* @return The network interface on success. | ||
* @return NULL, on error. | ||
*/ | ||
gnrc_netif2_t *gnrc_netif2_raw_create(char *stack, int stacksize, char priority, | ||
char *name, netdev_t *dev); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* NET_GNRC_NETIF2_RAW_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2017 Freie Universität Berlin | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @{ | ||
* | ||
* @file | ||
* @author Martine Lenders <[email protected]> | ||
*/ | ||
|
||
#include "net/gnrc/pktbuf.h" | ||
#include "net/gnrc/netif2/raw.h" | ||
|
||
#define ENABLE_DEBUG (0) | ||
#include "debug.h" | ||
|
||
#define IP_VERSION_MASK (0xf0U) | ||
#define IP_VERSION4 (0x40U) | ||
#define IP_VERSION6 (0x60U) | ||
|
||
|
||
static int _send(gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt); | ||
static gnrc_pktsnip_t *_recv(gnrc_netif2_t *netif); | ||
|
||
static const gnrc_netif2_ops_t raw_ops = { | ||
.send = _send, | ||
.recv = _recv, | ||
.get = gnrc_netif2_get_from_netdev, | ||
.set = gnrc_netif2_set_from_netdev, | ||
}; | ||
|
||
gnrc_netif2_t *gnrc_netif2_raw_create(char *stack, int stacksize, | ||
char priority, char *name, | ||
netdev_t *dev) | ||
{ | ||
return gnrc_netif2_create(stack, stacksize, priority, name, dev, | ||
&raw_ops); | ||
} | ||
|
||
static inline uint8_t _get_version(uint8_t *data) | ||
{ | ||
return (data[0] & IP_VERSION_MASK); | ||
} | ||
|
||
static gnrc_pktsnip_t *_recv(gnrc_netif2_t *netif) | ||
{ | ||
netdev_t *dev = netif->dev; | ||
int bytes_expected = dev->driver->recv(dev, NULL, 0, NULL); | ||
gnrc_pktsnip_t *pkt = NULL; | ||
|
||
if (bytes_expected > 0) { | ||
int nread; | ||
|
||
pkt = gnrc_pktbuf_add(NULL, NULL, bytes_expected, GNRC_NETTYPE_UNDEF); | ||
|
||
if (!pkt) { | ||
DEBUG("gnrc_netif_raw: cannot allocate pktsnip.\n"); | ||
/* drop packet */ | ||
dev->driver->recv(dev, NULL, bytes_expected, NULL); | ||
return pkt; | ||
} | ||
nread = dev->driver->recv(dev, pkt->data, bytes_expected, NULL); | ||
if (nread <= 1) { /* we need at least 1 byte to identify IP version */ | ||
DEBUG("gnrc_netif_raw: read error.\n"); | ||
gnrc_pktbuf_release(pkt); | ||
return NULL; | ||
} | ||
if (nread < bytes_expected) { | ||
/* we've got less then the expected packet size, | ||
* so free the unused space.*/ | ||
DEBUG("gnrc_netif_raw: reallocating.\n"); | ||
gnrc_pktbuf_realloc_data(pkt, nread); | ||
} | ||
switch (_get_version(pkt->data)) { | ||
#ifdef MODULE_GNRC_IPV6 | ||
case IP_VERSION6: | ||
pkt->type = GNRC_NETTYPE_IPV6; | ||
break; | ||
#endif | ||
default: | ||
/* leave UNDEF */ | ||
break; | ||
} | ||
} | ||
return pkt; | ||
} | ||
|
||
static int _send(gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt) | ||
{ | ||
gnrc_pktsnip_t *vector; | ||
int res = -ENOBUFS; | ||
size_t n; | ||
|
||
if (pkt->type == GNRC_NETTYPE_NETIF) { | ||
/* we don't need the netif snip: remove it */ | ||
pkt = gnrc_pktbuf_remove_snip(pkt, pkt); | ||
} | ||
vector = gnrc_pktbuf_get_iovec(pkt, &n); | ||
if (vector != NULL) { | ||
struct iovec *v = (struct iovec *)vector->data; | ||
netdev_t *dev = netif->dev; | ||
|
||
#ifdef MODULE_NETSTATS_L2 | ||
dev->stats.tx_unicast_count++; | ||
#endif | ||
res = dev->driver->send(dev, v, n); | ||
} | ||
return res; | ||
} | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 the embargo and the plans to not support any legacy driver belonging to "netif1", is there a reason to keep this called "netif2"?
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.
The embargo is against master. Not against the branch the embargo is up in the first place ;-). And the rename is definitely planned (but only after everything is merged and definitely not in this only marginally related PR) ;-).
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.
It just came to my mind because I saw it here, not because this PR would be the one where to do the renaming.
I'll test asap.