Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/connectivity/networking/api/net_pkt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ chosen).
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(ipv4_access, struct net_ipv4_hdr);
struct net_ipv4_hdr *ipv4_hdr;

ipv4_hdr = (struct net_ipv4_hdr *)net_pkt_get_data(pkt, &ipv4_acess);
ipv4_hdr = (struct net_ipv4_hdr *)net_pkt_get_data(pkt, &ipv4_access);

It would be the same for struct net_ipv4_hdr. For a UDP header it
is likely not to be in a contiguous area in IPv6
Expand Down
6 changes: 3 additions & 3 deletions drivers/ieee802154/ieee802154_b91.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ static void b91_handle_ack(void)
struct net_pkt *ack_pkt;

/* allocate ack packet */
ack_pkt = net_pkt_alloc_with_buffer(data.iface, B91_ACK_FRAME_LEN,
AF_UNSPEC, 0, K_NO_WAIT);
ack_pkt = net_pkt_rx_alloc_with_buffer(data.iface, B91_ACK_FRAME_LEN,
AF_UNSPEC, 0, K_NO_WAIT);
if (!ack_pkt) {
LOG_ERR("No free packet available.");
return;
Expand Down Expand Up @@ -300,7 +300,7 @@ static void b91_rf_rx_isr(void)
}

/* get packet pointer from NET stack */
pkt = net_pkt_alloc_with_buffer(data.iface, length, AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(data.iface, length, AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No pkt available");
goto exit;
Expand Down
4 changes: 2 additions & 2 deletions drivers/ieee802154/ieee802154_cc1200.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ static void cc1200_rx(void *arg)
goto flush;
}

pkt = net_pkt_alloc_with_buffer(cc1200->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(cc1200->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No free pkt available");
goto flush;
Expand Down
4 changes: 2 additions & 2 deletions drivers/ieee802154/ieee802154_cc2520.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,8 @@ static void cc2520_rx(void *arg)
goto flush;
}

pkt = net_pkt_alloc_with_buffer(cc2520->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(cc2520->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No pkt available");
goto flush;
Expand Down
4 changes: 2 additions & 2 deletions drivers/ieee802154/ieee802154_dw1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ static inline void dwt_irq_handle_rx(const struct device *dev, uint32_t sys_stat
pkt_len -= DWT_FCS_LENGTH;
}

pkt = net_pkt_alloc_with_buffer(ctx->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No buf available");
goto rx_out_enable_rx;
Expand Down
8 changes: 4 additions & 4 deletions drivers/ieee802154/ieee802154_kw41z.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ static inline void kw41z_rx(struct kw41z_context *kw41z, uint8_t len)
pkt_len = len - KW41Z_FCS_LENGTH;
#endif

pkt = net_pkt_alloc_with_buffer(kw41z->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(kw41z->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No buf available");
goto out;
Expand Down Expand Up @@ -582,8 +582,8 @@ static void handle_ack(struct kw41z_context *kw41z, uint8_t seq_number)
struct net_pkt *ack_pkt;
uint8_t ack_psdu[ACK_FRAME_LEN];

ack_pkt = net_pkt_alloc_with_buffer(kw41z->iface, ACK_FRAME_LEN,
AF_UNSPEC, 0, K_NO_WAIT);
ack_pkt = net_pkt_rx_alloc_with_buffer(kw41z->iface, ACK_FRAME_LEN,
AF_UNSPEC, 0, K_NO_WAIT);
if (!ack_pkt) {
LOG_ERR("No free packet available.");
return;
Expand Down
4 changes: 2 additions & 2 deletions drivers/ieee802154/ieee802154_mcr20a.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ static inline void mcr20a_rx(const struct device *dev, uint8_t len)

pkt_len = len - MCR20A_FCS_LENGTH;

pkt = net_pkt_alloc_with_buffer(mcr20a->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(mcr20a->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!pkt) {
LOG_ERR("No buf available");
goto out;
Expand Down
22 changes: 11 additions & 11 deletions drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ static int handle_ack(struct nrf5_802154_data *nrf5_radio)
ack_len = nrf5_radio->ack_frame.psdu[0] - NRF5_FCS_LENGTH;
}

ack_pkt = net_pkt_alloc_with_buffer(nrf5_radio->iface, ack_len,
AF_UNSPEC, 0, K_NO_WAIT);
ack_pkt = net_pkt_rx_alloc_with_buffer(nrf5_radio->iface, ack_len,
AF_UNSPEC, 0, K_NO_WAIT);
if (!ack_pkt) {
LOG_ERR("No free packet available.");
err = -ENOMEM;
Expand Down Expand Up @@ -441,14 +441,14 @@ static bool nrf5_tx_immediate(struct net_pkt *pkt, uint8_t *payload, bool cca)
{
nrf_802154_transmit_metadata_t metadata = {
.frame_props = {
.is_secured = pkt->ieee802154_frame_secured,
.dynamic_data_is_set = pkt->ieee802154_mac_hdr_rdy,
.is_secured = net_pkt_ieee802154_frame_secured(pkt),
.dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt),
},
.cca = cca,
.tx_power = {
.use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER),
#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER)
.power = pkt->ieee802154_txpwr,
.power = net_pkt_ieee802154_txpwr(pkt),
#endif
},
};
Expand All @@ -461,13 +461,13 @@ static bool nrf5_tx_csma_ca(struct net_pkt *pkt, uint8_t *payload)
{
nrf_802154_transmit_csma_ca_metadata_t metadata = {
.frame_props = {
.is_secured = pkt->ieee802154_frame_secured,
.dynamic_data_is_set = pkt->ieee802154_mac_hdr_rdy,
.is_secured = net_pkt_ieee802154_frame_secured(pkt),
.dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt),
},
.tx_power = {
.use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER),
#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER)
.power = pkt->ieee802154_txpwr,
.power = net_pkt_ieee802154_txpwr(pkt),
#endif
},
};
Expand Down Expand Up @@ -548,15 +548,15 @@ static bool nrf5_tx_at(struct net_pkt *pkt, uint8_t *payload, bool cca)
{
nrf_802154_transmit_at_metadata_t metadata = {
.frame_props = {
.is_secured = pkt->ieee802154_frame_secured,
.dynamic_data_is_set = pkt->ieee802154_mac_hdr_rdy,
.is_secured = net_pkt_ieee802154_frame_secured(pkt),
.dynamic_data_is_set = net_pkt_ieee802154_mac_hdr_rdy(pkt),
},
.cca = cca,
.channel = nrf_802154_channel_get(),
.tx_power = {
.use_metadata_value = IS_ENABLED(CONFIG_IEEE802154_SELECTIVE_TXPOWER),
#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER)
.power = pkt->ieee802154_txpwr,
.power = net_pkt_ieee802154_txpwr(pkt),
#endif
},
};
Expand Down
12 changes: 7 additions & 5 deletions drivers/ieee802154/ieee802154_rf2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ static struct net_buf rf2xx_ack_frame = {
};
static struct net_pkt rf2xx_ack_pkt = {
.buffer = &rf2xx_ack_frame,
.ieee802154_lqi = 80,
.ieee802154_rssi = -40,
.cb = {
.lqi = 80,
.rssi = -40,
}
};
#endif /* CONFIG_NET_L2_OPENTHREAD */

Expand Down Expand Up @@ -165,7 +167,7 @@ static void rf2xx_trx_rx(const struct device *dev)

/*
* The rf2xx frame buffer can have length > 128 bytes. The
* net_pkt_alloc_with_buffer allocates max value of 128 bytes.
* net_pkt_rx_alloc_with_buffer allocates max value of 128 bytes.
*
* This obligate the driver to have rx_buf statically allocated with
* RX2XX_MAX_FRAME_SIZE.
Expand Down Expand Up @@ -204,8 +206,8 @@ static void rf2xx_trx_rx(const struct device *dev)
pkt_len -= RX2XX_FRAME_FCS_LENGTH;
}

pkt = net_pkt_alloc_with_buffer(ctx->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len,
AF_UNSPEC, 0, K_NO_WAIT);

if (!pkt) {
LOG_ERR("No buf available");
Expand Down
195 changes: 195 additions & 0 deletions include/zephyr/net/ieee802154_pkt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2022 Florian Grandel.
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Packet data common to all IEEE 802.15.4 L2 layers
*/

#ifndef ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_
#define ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_

#include <string.h>

#include <zephyr/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @cond ignore */

#ifndef NET_PKT_HAS_CONTROL_BLOCK
#define NET_PKT_HAS_CONTROL_BLOCK
#endif

struct net_pkt_cb_ieee802154 {
#if defined(CONFIG_IEEE802154_2015)
uint32_t ack_fc; /* Frame counter set in the ACK */
uint8_t ack_keyid; /* Key index set in the ACK */
#endif
union {
/* RX packets */
struct {
uint8_t lqi; /* Link Quality Indicator */
uint8_t rssi; /* Received Signal Strength Indication */
};
#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER)
/* TX packets */
struct {
int8_t txpwr; /* TX power in dBm. */
};
#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */
};

/* Flags */
uint8_t arb : 1; /* ACK Request Bit is set in the frame */
uint8_t ack_fpb : 1; /* Frame Pending Bit was set in the ACK */
uint8_t frame_secured : 1; /* Frame is authenticated and
* encrypted according to its
* Auxiliary Security Header
*/
uint8_t mac_hdr_rdy : 1; /* Indicates if frame's MAC header
* is ready to be transmitted or if
* it requires further modifications,
* e.g. Frame Counter injection.
*/
#if defined(CONFIG_IEEE802154_2015)
uint8_t fv2015 : 1; /* Frame version is IEEE 802.15.4-2015 or later */
uint8_t ack_seb : 1; /* Security Enabled Bit was set in the ACK */
#endif
};

struct net_pkt;
static inline void *net_pkt_cb(struct net_pkt *pkt);

static inline struct net_pkt_cb_ieee802154 *net_pkt_cb_ieee802154(struct net_pkt *pkt)
{
return net_pkt_cb(pkt);
};

static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->lqi;
}

static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt, uint8_t lqi)
{
net_pkt_cb_ieee802154(pkt)->lqi = lqi;
}

static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->rssi;
}

static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt, uint8_t rssi)
{
net_pkt_cb_ieee802154(pkt)->rssi = rssi;
}

#if defined(CONFIG_IEEE802154_SELECTIVE_TXPOWER)
static inline int8_t net_pkt_ieee802154_txpwr(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->txpwr;
}

static inline void net_pkt_set_ieee802154_txpwr(struct net_pkt *pkt, int8_t txpwr)
{
net_pkt_cb_ieee802154(pkt)->txpwr = txpwr;
}
#endif /* CONFIG_IEEE802154_SELECTIVE_TXPOWER */

static inline bool net_pkt_ieee802154_arb(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->arb;
}

static inline void net_pkt_set_ieee802154_arb(struct net_pkt *pkt, bool arb)
{
net_pkt_cb_ieee802154(pkt)->arb = arb;
}

static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->ack_fpb;
}

static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt, bool fpb)
{
net_pkt_cb_ieee802154(pkt)->ack_fpb = fpb;
}

static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->frame_secured;
}

static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt, bool secured)
{
net_pkt_cb_ieee802154(pkt)->frame_secured = secured;
}

static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy;
}

static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt, bool rdy)
{
net_pkt_cb_ieee802154(pkt)->mac_hdr_rdy = rdy;
}

#if defined(CONFIG_IEEE802154_2015)
static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->ack_fc;
}

static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt, uint32_t fc)
{
net_pkt_cb_ieee802154(pkt)->ack_fc = fc;
}

static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->ack_keyid;
}

static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt, uint8_t keyid)
{
net_pkt_cb_ieee802154(pkt)->ack_keyid = keyid;
}

static inline bool net_pkt_ieee802154_fv2015(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->fv2015;
}

static inline void net_pkt_set_ieee802154_fv2015(struct net_pkt *pkt, bool fv2015)
{
net_pkt_cb_ieee802154(pkt)->fv2015 = fv2015;
}

static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
{
return net_pkt_cb_ieee802154(pkt)->ack_seb;
}

static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
{
net_pkt_cb_ieee802154(pkt)->ack_seb = seb;
}
#endif /* CONFIG_IEEE802154_2015 */

/** @endcond */

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_INCLUDE_NET_IEEE802154_PKT_H_ */
2 changes: 1 addition & 1 deletion include/zephyr/net/net_l2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum net_l2_flags {
/** IP multicast supported */
NET_L2_MULTICAST = BIT(0),

/** Do not joint solicited node multicast group */
/** Do not join solicited node multicast group */
NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE = BIT(1),

/** Is promiscuous mode supported */
Expand Down
Loading