-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[POC]: netif rework #12741
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
[POC]: netif rework #12741
Changes from all commits
3db4338
f04e546
8ec3ba2
2eb4b52
f21f8e3
567624f
ee1b95f
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 |
|---|---|---|
|
|
@@ -194,6 +194,31 @@ int netdev_ieee802154_set(netdev_ieee802154_t *dev, netopt_t opt, const void *va | |
| */ | ||
| int netdev_ieee802154_dst_filter(netdev_ieee802154_t *dev, const uint8_t *mhr); | ||
|
|
||
| typedef struct { | ||
| uint8_t *psdu; | ||
| size_t psdu_len; | ||
| uint8_t lqi; | ||
| int16_t rssi; | ||
| void *ctx; | ||
| } ieee802154_phy_ind_t; | ||
|
|
||
| typedef struct { | ||
| iolist_t msdu; | ||
| uint8_t *src; | ||
| size_t src_len; | ||
| uint8_t *dst; | ||
| size_t dst_len; | ||
| uint8_t frame_pending; | ||
| } ieee802154_mac_ind_t; | ||
|
|
||
| void ieee802154_rf_rx_done(netdev_t *netdev); | ||
| void ieee802154_mac_recv(netdev_ieee802154_t *dev, ieee802154_phy_ind_t *ind); | ||
| void ieee802154_mac_ind(netdev_ieee802154_t *netdev, ieee802154_mac_ind_t *ind, ieee802154_phy_ind_t *phy_ind); | ||
| void ieee802154_phy_ind(netdev_t *netdev, ieee802154_phy_ind_t *ind); | ||
| int ieee802154_mac_send(netdev_ieee802154_t *netdev, iolist_t *msdu, int frame_pending, | ||
| uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len); | ||
|
Comment on lines
+214
to
+219
Member
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. Given that these functions are implemented in
Member
Author
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. exactly. I think I added a comment somewhere that I added it in the netdev files because there were some circular dependencies :(. But the idea is to put them exactly where you describe |
||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright (C) 2019 HAW Hamburg | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| /** | ||
| * @defgroup net_netbuf Network buffer abstraction | ||
| * @ingroup net | ||
| * @brief Provides an abstraction for network stack buffers | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Network buffer abstraction definition | ||
| * | ||
| * @author Jose I. Alamos <jose.alamos@haw-hamburg.de> | ||
| */ | ||
| #ifndef NET_NETBUF_H | ||
| #define NET_NETBUF_H | ||
|
|
||
| #include <stdbool.h> | ||
| #include "iolist.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Get a network buffer with a given size. | ||
| * | ||
| * @note Supposed to be implemented by the networking module. | ||
| * | ||
| * @param[in] size size of the buffer to be allocated. | ||
| * @param[out] ctx allocation context. | ||
| * | ||
| * @return pointer to the buffer. | ||
| * @return packet context in @p ctx. | ||
| * @return NULL on failure (e.g there's not enough memory for allocation) | ||
| */ | ||
| void *netbuf_get(size_t size, void **ctx); | ||
|
|
||
| /** | ||
| * @brief Free the resources of a network buffer | ||
| * | ||
| * @note Supposed to be implemented by the networking module. | ||
| * | ||
| * @param[in] ctx pointer to the allocation context. | ||
| */ | ||
| void netbuf_free(void *ctx); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* NET_NETBUF_H */ | ||
| /** @} */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
|
|
||
| #include "list.h" | ||
| #include "net/netopt.h" | ||
| #include "net/netbuf.h" | ||
|
Member
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 include shouldn't be needed. |
||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
|
|
@@ -58,6 +59,21 @@ typedef struct { | |
| list_node_t node; /**< Pointer to the next interface */ | ||
| } netif_t; | ||
|
|
||
| typedef struct { | ||
| iolist_t msdu; | ||
| void *ctx; | ||
| uint8_t *src_l2addr; | ||
| uint8_t *dst_l2addr; | ||
| int16_t rssi; | ||
| uint8_t lqi; | ||
| uint8_t src_l2addr_len; | ||
| uint8_t dst_l2addr_len; | ||
| uint8_t flags; | ||
| } netif_pkt_t; | ||
|
|
||
|
|
||
| int netif_recv(netif_t *netif, netif_pkt_t *pkt); | ||
|
Comment on lines
+62
to
+75
Member
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. It's a POC, I know, but I'm missing some doc. |
||
|
|
||
| /** | ||
| * @brief Iterator for the interfaces | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,78 @@ | |
| #include <string.h> | ||
|
|
||
| #include "fmt.h" | ||
| #include "net/gnrc.h" | ||
| #include "net/gnrc/netapi.h" | ||
| #include "net/gnrc/netif/internal.h" | ||
|
|
||
| #include "net/netif.h" | ||
|
|
||
| #define ENABLE_DEBUG (0) | ||
| #include "debug.h" | ||
|
|
||
| /* GNRC implementation of netif_recv. | ||
| * | ||
| * This function converts the `netif_pkt` representation | ||
| * into a `gnrc_pkt` representation. Note that the | ||
| * netbuf implementation of GNRC uses the gnrc_pktsnip_t | ||
| * pointer as netbuf context, so we can get fetch the packet | ||
| * from there. | ||
| * | ||
| * Also, we need to create the gnrc_netif_hdr to pass the | ||
| * L2 metadata to the upper layers. And also remove the | ||
| * L2 header. | ||
| * | ||
| * Note that if a PHY layer didn't call the netbuf allocation | ||
| * function (e.g the PHY layer had a static framebuffer like | ||
| * the ESP-WIFI implementation), it's possible to set the | ||
| * allocation context (netif_pkt->ctx) to NULL. | ||
| * So, it's possible to only allocate the MSDU | ||
| * and not the full packet!! This would reduce the number | ||
| * of memcpy in those cases. | ||
| */ | ||
| int netif_recv(netif_t *netif, netif_pkt_t *pkt) | ||
| { | ||
| gnrc_pktsnip_t *gnrc_pkt = pkt->ctx; | ||
| gnrc_netif_t *gnrc_netif = (gnrc_netif_t*) netif; | ||
| netdev_t *dev = gnrc_netif->dev; | ||
|
|
||
| gnrc_pktsnip_t *netif_snip = gnrc_netif_hdr_build(pkt->src_l2addr, pkt->src_l2addr_len, pkt->dst_l2addr, pkt->dst_l2addr_len); | ||
|
|
||
| if (netif_snip == NULL) { | ||
| DEBUG("_recv_ieee802154: no space left in packet buffer\n"); | ||
| gnrc_pktbuf_release(gnrc_pkt); | ||
| return 0; | ||
| } | ||
|
|
||
| /* We can avoid the following logic if we know the PHY layer | ||
| * didn't allocate the packet (see the description of this function). | ||
| * | ||
| * In that case, we would need to call | ||
| * `gnrc_pktbuf_add(pkt->msdu.iol_base, pkt->msdu.iol_len, GNRC_NETTYPE_UNDEF)` | ||
| * instead of removing the snip and reallocating data. | ||
| */ | ||
| gnrc_pktsnip_t *ieee802154_hdr = gnrc_pktbuf_mark(gnrc_pkt, ((uint8_t*) pkt->msdu.iol_base) - ((uint8_t*) gnrc_pkt->data), GNRC_NETTYPE_UNDEF); | ||
|
Member
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. Not sure what is happening here... Why the pointer arithmetic? Please add at least a comment about that.
Member
Author
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. The indication contains a pointer to the MSDU (and length). However, in GNRC it's required to mark the pkt before passing it to the network stack.
Member
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. Ok, this seems like a misuse of
Member
Author
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.
|
||
|
|
||
| gnrc_pktbuf_remove_snip(gnrc_pkt, ieee802154_hdr); | ||
| gnrc_pktbuf_realloc_data(gnrc_pkt, pkt->msdu.iol_len); | ||
|
Member
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 is a reallocation necessary here?
Member
Author
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. some radios don't process FCS. Thus, it's necessary to remove it before passing it to the stack.
Member
Author
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. does it make sense to add functions like
Member
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.
Ok. If it is just removing the trailing FCS, this is the correct usage. No need to add extra functions for that.
Member
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. (But maybe a comment would be nice ;-)). |
||
| gnrc_netif_hdr_t *hdr = netif_snip->data; | ||
| hdr->lqi = pkt->lqi; | ||
| hdr->rssi = pkt->rssi; | ||
| gnrc_netif_hdr_set_netif(hdr, (gnrc_netif_t*) netif); | ||
| dev->driver->get(dev, NETOPT_PROTO, &gnrc_pkt->type, sizeof(gnrc_pkt->type)); | ||
|
|
||
| hdr->flags |= pkt->flags; | ||
|
Member
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. Are the flags guaranteed to be transparent? If yes, what's the reasoning for that? |
||
|
|
||
| LL_APPEND(gnrc_pkt, netif_snip); | ||
|
|
||
| if (!gnrc_netapi_dispatch_receive(gnrc_pkt->type, GNRC_NETREG_DEMUX_CTX_ALL, gnrc_pkt)) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| int netif_get_name(netif_t *iface, char *name) | ||
| { | ||
| gnrc_netif_t *netif = (gnrc_netif_t*) iface; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| #include "sched.h" | ||
| #include "xtimer.h" | ||
|
|
||
| #include "net/netbuf.h" | ||
| #include "net/gnrc/netif.h" | ||
| #include "net/gnrc/netif/internal.h" | ||
|
|
||
|
|
@@ -46,6 +47,25 @@ static void _configure_netdev(netdev_t *dev); | |
| static void *_gnrc_netif_thread(void *args); | ||
| static void _event_cb(netdev_t *dev, netdev_event_t event); | ||
|
|
||
| /* GNRC implementation of the netbuf_get function */ | ||
| void *netbuf_get(size_t size, void **ctx) | ||
| { | ||
| gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, NULL, size, GNRC_NETTYPE_UNDEF); | ||
|
|
||
| if(pkt) { | ||
| *ctx = pkt; | ||
| return pkt->data; | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| /* GNRC implementation of the netbuf_free function */ | ||
| void netbuf_free(void *netbuf) | ||
| { | ||
| gnrc_pktbuf_release(netbuf); | ||
| } | ||
|
|
||
| gnrc_netif_t *gnrc_netif_create(char *stack, int stacksize, char priority, | ||
| const char *name, netdev_t *netdev, | ||
| const gnrc_netif_ops_t *ops) | ||
|
|
@@ -1332,6 +1352,7 @@ void gnrc_netif_default_init(gnrc_netif_t *netif) | |
| #endif | ||
| } | ||
|
|
||
| extern int gnrc_netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); | ||
|
Member
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 not move the function here proper and add its declaration to
Member
Author
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. I was too lazy for doing that :). But of course in the final version that would be in the right header |
||
| static void *_gnrc_netif_thread(void *args) | ||
| { | ||
| gnrc_netapi_opt_t *opt; | ||
|
|
@@ -1388,7 +1409,7 @@ static void *_gnrc_netif_thread(void *args) | |
| break; | ||
| case GNRC_NETAPI_MSG_TYPE_SND: | ||
| DEBUG("gnrc_netif: GNRC_NETDEV_MSG_TYPE_SND received\n"); | ||
| res = netif->ops->send(netif, msg.content.ptr); | ||
| res = gnrc_netif_send(netif, msg.content.ptr); | ||
| if (res < 0) { | ||
| DEBUG("gnrc_netif: error sending packet %p (code: %i)\n", | ||
| msg.content.ptr, res); | ||
|
|
||
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.
Also missing doc here ;-)