net/ieee802154: Switch to L2 sending path

As for Ethernet, up to ieee802154 L2's send to actually sent the packet.
It's currently unoptimized as 6lo compression, 15.4 fragmentation and so
on will reallocate net_buf etc... but it's the first step towards
removing ll reserve space and more.

Applying changes to Openthread L2 as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-10-09 11:50:47 +02:00 committed by Anas Nashif
parent 7f2cb02720
commit ebb40ba338
13 changed files with 49 additions and 105 deletions

View file

@ -833,7 +833,6 @@ static struct cc1200_context cc1200_context_data;
static struct ieee802154_radio_api cc1200_radio_api = {
.iface_api.init = cc1200_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = cc1200_get_capabilities,
.cca = cc1200_cca,

View file

@ -1072,7 +1072,6 @@ static struct cc2520_context cc2520_context_data;
static struct ieee802154_radio_api cc2520_radio_api = {
.iface_api.init = cc2520_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = cc2520_get_capabilities,
.cca = cc2520_cca,

View file

@ -1008,7 +1008,6 @@ static void kw41z_iface_init(struct net_if *iface)
static struct ieee802154_radio_api kw41z_radio_api = {
.iface_api.init = kw41z_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = kw41z_get_capabilities,
.cca = kw41z_cca,

View file

@ -1462,7 +1462,6 @@ static struct mcr20a_context mcr20a_context_data;
static struct ieee802154_radio_api mcr20a_radio_api = {
.iface_api.init = mcr20a_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = mcr20a_get_capabilities,
.cca = mcr20a_cca,

View file

@ -424,7 +424,6 @@ static const struct nrf5_802154_config nrf5_radio_cfg = {
static struct ieee802154_radio_api nrf5_radio_api = {
.iface_api.init = nrf5_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = nrf5_get_capabilities,
.cca = nrf5_cca,

View file

@ -370,7 +370,6 @@ static struct upipe_context upipe_context_data;
static struct ieee802154_radio_api upipe_radio_api = {
.iface_api.init = upipe_iface_init,
.iface_api.send = ieee802154_radio_send,
.get_capabilities = upipe_get_capabilities,
.cca = upipe_cca,

View file

@ -128,20 +128,6 @@ static inline bool ieee802154_is_ar_flag_set(struct net_pkt *pkt)
#ifndef CONFIG_IEEE802154_RAW_MODE
/**
* @brief Radio driver sending function that hw drivers should use
*
* @details This function should be used to fill in struct net_if's send
* pointer.
*
* @param iface A valid pointer on a network interface to send from
* @param pkt A valid pointer on a packet to send
*
* @return 0 on success, negative value otherwise
*/
extern int ieee802154_radio_send(struct net_if *iface,
struct net_pkt *pkt);
/**
* @brief Radio driver ACK handling function that hw drivers should use
*
@ -165,12 +151,6 @@ void ieee802154_init(struct net_if *iface);
#else /* CONFIG_IEEE802154_RAW_MODE */
static inline int ieee802154_radio_send(struct net_if *iface,
struct net_pkt *pkt)
{
return 0;
}
static inline enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
struct net_pkt *pkt)
{

View file

@ -28,6 +28,7 @@
#include "ieee802154_mgmt_priv.h"
#include "ieee802154_security.h"
#include "ieee802154_utils.h"
#include "ieee802154_radio_utils.h"
#define BUF_TIMEOUT K_MSEC(50)
@ -244,42 +245,57 @@ static enum net_verdict ieee802154_recv(struct net_if *iface,
return ieee802154_manage_recv_packet(iface, pkt);
}
static enum net_verdict ieee802154_send(struct net_if *iface,
struct net_pkt *pkt)
static int ieee802154_send(struct net_if *iface, struct net_pkt *pkt)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
u8_t reserved_space = net_pkt_ll_reserve(pkt);
struct net_buf *frag;
int len;
if (net_pkt_family(pkt) != AF_INET6) {
return NET_DROP;
return -EINVAL;
}
if (!ieee802154_manage_send_packet(iface, pkt)) {
return NET_DROP;
return -ENOBUFS;
}
len = 0;
frag = pkt->frags;
while (frag) {
int ret;
if (frag->len > IEEE802154_MTU) {
NET_ERR("Frag %p as too big length %u",
frag, frag->len);
return NET_DROP;
return -EINVAL;
}
if (!ieee802154_create_data_frame(ctx, net_pkt_lladdr_dst(pkt),
frag, reserved_space)) {
return NET_DROP;
return -EINVAL;
}
if (IS_ENABLED(CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA) &&
ieee802154_get_hw_capabilities(iface) &
IEEE802154_HW_CSMA) {
ret = ieee802154_tx(iface, pkt, frag);
} else {
ret = ieee802154_radio_send(iface, pkt, frag);
}
if (ret) {
return ret;
}
len += frag->len;
frag = frag->frags;
}
pkt_hexdump(TX_PKT_TITLE " (with ll)", pkt, false, true);
net_pkt_unref(pkt);
net_if_queue_tx(iface, pkt);
return NET_OK;
return len;
}
static u16_t ieee802154_reserve(struct net_if *iface, void *data)

View file

@ -20,6 +20,7 @@
#include "ieee802154_mgmt_priv.h"
#include "ieee802154_security.h"
#include "ieee802154_utils.h"
#include "ieee802154_radio_utils.h"
enum net_verdict ieee802154_handle_beacon(struct net_if *iface,
struct ieee802154_mpdu *mpdu,
@ -138,7 +139,7 @@ static int ieee802154_scan(u32_t mgmt_request, struct net_if *iface,
net_pkt_ref(pkt);
net_pkt_frag_ref(pkt->frags);
ret = ieee802154_radio_send(iface, pkt);
ret = ieee802154_radio_send(iface, pkt, pkt->frags);
if (ret) {
NET_DBG("Could not send Beacon Request (%d)",
ret);

View file

@ -16,9 +16,9 @@
#include "ieee802154_utils.h"
#include "ieee802154_radio_utils.h"
static inline int aloha_tx_fragment(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag)
static inline int aloha_radio_send(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag)
{
u8_t retries = CONFIG_NET_L2_IEEE802154_RADIO_TX_RETRIES;
struct ieee802154_context *ctx = net_if_l2_data(iface);
@ -44,13 +44,6 @@ static inline int aloha_tx_fragment(struct net_if *iface,
return ret;
}
static int aloha_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
NET_DBG("pkt %p (frags %p)", pkt, pkt->frags);
return tx_packet_fragments(iface, pkt, aloha_tx_fragment);
}
static enum net_verdict aloha_radio_handle_ack(struct net_if *iface,
struct net_pkt *pkt)
{

View file

@ -19,9 +19,9 @@
#include "ieee802154_utils.h"
#include "ieee802154_radio_utils.h"
static inline int csma_ca_tx_fragment(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag)
static inline int csma_ca_radio_send(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag)
{
const u8_t max_bo = CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA_MAX_BO;
const u8_t max_be = CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA_MAX_BE;
@ -71,13 +71,6 @@ loop:
return ret;
}
static int csma_ca_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
NET_DBG("pkt %p (frags %p)", pkt, pkt->frags);
return tx_packet_fragments(iface, pkt, csma_ca_tx_fragment);
}
static enum net_verdict csma_ca_radio_handle_ack(struct net_if *iface,
struct net_pkt *pkt)
{

View file

@ -9,9 +9,17 @@
#include "ieee802154_utils.h"
typedef int (ieee802154_radio_tx_frag_t)(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag);
/**
* @brief Radio driver sending function that radio drivers should implement
*
* @param iface A valid pointer on a network interface to send from
* @param pkt A valid pointer on a packet to send
*
* @return 0 on success, negative value otherwise
*/
extern int ieee802154_radio_send(struct net_if *iface,
struct net_pkt *pkt,
struct net_buf *frag);
static inline bool prepare_for_ack(struct ieee802154_context *ctx,
struct net_pkt *pkt,
@ -76,35 +84,4 @@ static inline int handle_ack(struct ieee802154_context *ctx,
return NET_CONTINUE;
}
static inline int tx_packet_fragments(struct net_if *iface,
struct net_pkt *pkt,
ieee802154_radio_tx_frag_t *tx_func)
{
int ret = 0;
struct net_buf *frag;
frag = pkt->frags;
while (frag) {
if (IS_ENABLED(CONFIG_NET_L2_IEEE802154_RADIO_CSMA_CA) &&
ieee802154_get_hw_capabilities(iface) &
IEEE802154_HW_CSMA) {
ret = ieee802154_tx(iface, pkt, frag);
} else {
ret = tx_func(iface, pkt, frag);
}
if (ret) {
break;
}
frag = frag->frags;
}
if (!ret) {
net_pkt_unref(pkt);
}
return ret;
}
#endif /* __IEEE802154_RADIO_UTILS_H__ */

View file

@ -229,11 +229,12 @@ static enum net_verdict openthread_recv(struct net_if *iface,
return NET_OK;
}
enum net_verdict openthread_send(struct net_if *iface, struct net_pkt *pkt)
int openthread_send(struct net_if *iface, struct net_pkt *pkt)
{
struct openthread_context *ot_context = net_if_l2_data(iface);
otMessage *message;
int len = net_pkt_get_len(pkt);
struct net_buf *frag;
otMessage *message;
NET_DBG("Sending Ip6 packet to ot stack");
@ -264,7 +265,7 @@ enum net_verdict openthread_send(struct net_if *iface, struct net_pkt *pkt)
exit:
net_pkt_unref(pkt);
return NET_OK;
return len;
}
static u16_t openthread_reserve(struct net_if *iface, void *arg)
@ -345,17 +346,6 @@ void ieee802154_init(struct net_if *iface)
openthread_init(iface);
}
int ieee802154_radio_send(struct net_if *iface, struct net_pkt *pkt)
{
ARG_UNUSED(iface);
ARG_UNUSED(pkt);
/* Shouldn't be here */
__ASSERT(false, "OpenThread L2 should never reach here");
return -EIO;
}
static enum net_l2_flags openthread_flags(struct net_if *iface)
{
return NET_L2_MULTICAST;