Skip to content
Merged
5 changes: 3 additions & 2 deletions drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,10 @@ static int nrf5_configure(const struct device *dev,
sys_put_le16(config->ack_ie.short_addr, short_addr_le);
/**
* The extended address field passed to this function starts
* with the leftmost octet and ends with the rightmost octet.
* with the most significant octet and ends with the least
* significant octet (i.e. big endian byte order).
* The IEEE 802.15.4 transmission order mandates this order to be
* reversed in a transmitted frame.
* reversed (i.e. little endian byte order) in a transmitted frame.
*
* The nrf_802154_ack_data_set expects extended address in transmission
* order.
Expand Down
51 changes: 29 additions & 22 deletions include/zephyr/net/ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern "C" {

/* See IEEE 802.15.4-2006, section 7.2.1.4 */
#define IEEE802154_BROADCAST_ADDRESS 0xFFFF
#define IEEE802154_NO_SHORT_ADDRESS_ASSIGNED 0xFFFE
#define IEEE802154_SHORT_ADDRESS_NOT_ASSOCIATED 0x0000
#define IEEE802154_BROADCAST_PAN_ID 0xFFFF

struct ieee802154_security_ctx {
Expand All @@ -57,34 +59,39 @@ struct ieee802154_security_ctx {

/* This not meant to be used by any code but 802.15.4 L2 stack */
struct ieee802154_context {
enum net_l2_flags flags;
uint16_t pan_id;
uint16_t pan_id; /* in CPU byte order */
uint16_t channel;
struct k_sem ack_lock;
uint16_t short_addr;
uint8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
#ifdef CONFIG_NET_L2_IEEE802154_MGMT
struct ieee802154_req_params *scan_ctx;
union {
struct k_sem res_lock;
struct k_sem req_lock;
};
union {
uint8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
uint16_t short_addr;
} coord;
uint8_t coord_addr_len;
#endif
/* short address:
* 0 == not associated,
* 0xfffe == associated but no short address assigned
* see section 7.4.2
*/
uint16_t short_addr; /* in CPU byte order */
uint8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH]; /* in little endian */
struct net_linkaddr_storage linkaddr; /* in big endian */
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
struct ieee802154_security_ctx sec_ctx;
#endif
#ifdef CONFIG_NET_L2_IEEE802154_MGMT
struct ieee802154_req_params *scan_ctx; /* guarded by scan_ctx_lock */
struct k_sem scan_ctx_lock;

uint8_t coord_ext_addr[IEEE802154_MAX_ADDR_LENGTH]; /* in little endian */
uint16_t coord_short_addr; /* in CPU byte order */
#endif
int16_t tx_power;
enum net_l2_flags flags;
uint8_t sequence;
uint8_t ack_seq;
uint8_t ack_received : 1;
uint8_t ack_requested : 1;
uint8_t associated : 1;
uint8_t _unused : 5;

uint8_t ack_seq; /* guarded by ack_lock */
uint8_t ack_received : 1; /* guarded by ack_lock */
uint8_t ack_requested : 1; /* guarded by ack_lock */
uint8_t _unused : 6;
struct k_sem ack_lock;

struct k_sem ctx_lock; /* guards all mutable context attributes unless
* otherwise mentioned on attribute level
*/
};

#define IEEE802154_L2_CTX_TYPE struct ieee802154_context
Expand Down
24 changes: 12 additions & 12 deletions include/zephyr/net/ieee802154_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ enum net_request_ieee802154_cmd {
NET_REQUEST_IEEE802154_CMD_CANCEL_SCAN,
NET_REQUEST_IEEE802154_CMD_ASSOCIATE,
NET_REQUEST_IEEE802154_CMD_DISASSOCIATE,
NET_REQUEST_IEEE802154_CMD_SET_CHANNEL,
NET_REQUEST_IEEE802154_CMD_GET_CHANNEL,
NET_REQUEST_IEEE802154_CMD_SET_PAN_ID,
NET_REQUEST_IEEE802154_CMD_GET_PAN_ID,
NET_REQUEST_IEEE802154_CMD_SET_EXT_ADDR,
NET_REQUEST_IEEE802154_CMD_GET_EXT_ADDR,
NET_REQUEST_IEEE802154_CMD_SET_SHORT_ADDR,
NET_REQUEST_IEEE802154_CMD_GET_SHORT_ADDR,
NET_REQUEST_IEEE802154_CMD_SET_CHANNEL, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_GET_CHANNEL, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_SET_PAN_ID, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_GET_PAN_ID, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_SET_EXT_ADDR, /* in big endian byte order */
NET_REQUEST_IEEE802154_CMD_GET_EXT_ADDR, /* in big endian byte order */
NET_REQUEST_IEEE802154_CMD_SET_SHORT_ADDR, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_GET_SHORT_ADDR, /* in CPU byte order */
NET_REQUEST_IEEE802154_CMD_GET_TX_POWER,
NET_REQUEST_IEEE802154_CMD_SET_TX_POWER,
NET_REQUEST_IEEE802154_CMD_SET_SECURITY_SETTINGS,
Expand Down Expand Up @@ -191,14 +191,14 @@ struct ieee802154_req_params {
uint32_t duration;

/** Current channel in use as a result */
uint16_t channel;
uint16_t channel; /* in CPU byte order */
/** Current pan_id in use as a result */
uint16_t pan_id;
uint16_t pan_id; /* in CPU byte order */

/** Result address */
union {
uint8_t addr[IEEE802154_MAX_ADDR_LENGTH];
uint16_t short_addr;
uint8_t addr[IEEE802154_MAX_ADDR_LENGTH]; /* in big endian */
uint16_t short_addr; /* in CPU byte order */
};

/** length of address */
Expand Down
34 changes: 20 additions & 14 deletions include/zephyr/net/ieee802154_radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ typedef void (*ieee802154_event_cb_t)(const struct device *dev,
struct ieee802154_filter {
/** @cond ignore */
union {
uint8_t *ieee_addr;
uint16_t short_addr;
uint16_t pan_id;
uint8_t *ieee_addr; /* in little endian */
uint16_t short_addr; /* in CPU byte order */
uint16_t pan_id; /* in CPU byte order */
};
/* @endcond */
};
Expand Down Expand Up @@ -142,7 +142,7 @@ enum ieee802154_config_type {
* determine whether to set the bit or not based on the information
* provided with ``IEEE802154_CONFIG_ACK_FPB`` config and FPB address
* matching mode specified. Otherwise, Frame Pending bit should be set
* to ``1``(see IEEE Std 802.15.4-2006, 7.2.2.3.1).
* to ``1`` (see IEEE Std 802.15.4-2006, 7.2.2.3.1).
*/
IEEE802154_CONFIG_AUTO_ACK_FPB,

Expand Down Expand Up @@ -233,7 +233,7 @@ struct ieee802154_config {

/** ``IEEE802154_CONFIG_ACK_FPB`` */
struct {
uint8_t *addr;
uint8_t *addr; /* in little endian for both, short and extended address */
bool extended;
bool enabled;
} ack_fpb;
Expand Down Expand Up @@ -271,24 +271,30 @@ struct ieee802154_config {
} rx_slot;

/** ``IEEE802154_CONFIG_CSL_PERIOD`` */
uint32_t csl_period;
uint32_t csl_period; /* in CPU byte order */

/** ``IEEE802154_CONFIG_CSL_RX_TIME`` */
uint32_t csl_rx_time;
uint32_t csl_rx_time; /* in microseconds,
* based on ieee802154_radio_api.get_time()
*/

/** ``IEEE802154_CONFIG_ENH_ACK_HEADER_IE`` */
struct {
const uint8_t *data;
const uint8_t *data; /* header IEs to be added to the Enh-Ack frame in
* little endian byte order
*/
uint16_t data_len;
uint16_t short_addr;
uint16_t short_addr; /* in CPU byte order */
/**
* The extended address is expected to be passed starting
* with the leftmost octet and ending with the rightmost octet.
* with the most significant octet and ending with the
* least significant octet.
* A device with an extended address 01:23:45:67:89:ab:cd:ef
* should provide a pointer to array containing values in the
* same exact order.
* as written in the usual big-endian hex notation should
* provide a pointer to an array containing values in the
* exact same order.
*/
const uint8_t *ext_addr;
const uint8_t *ext_addr; /* in big endian */
} ack_ie;
};
};
Expand All @@ -312,7 +318,7 @@ struct ieee802154_radio_api {
/** Clear Channel Assessment - Check channel's activity */
int (*cca)(const struct device *dev);

/** Set current channel */
/** Set current channel, channel is in CPU byte order. */
int (*set_channel)(const struct device *dev, uint16_t channel);

/** Set/Unset filters (for IEEE802154_HW_FILTER ) */
Expand Down
16 changes: 16 additions & 0 deletions include/zephyr/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ static inline void net_if_flag_clear(struct net_if *iface,
atomic_clear_bit(iface->if_dev->flags, value);
}

/**
* @brief Test and clear a value in network interface flags
*
* @param iface Pointer to network interface
* @param value Flag value
*
* @return true if the bit was set, false if it wasn't.
*/
static inline bool net_if_flag_test_and_clear(struct net_if *iface,
enum net_if_flag value)
{
NET_ASSERT(iface);

return atomic_test_and_clear_bit(iface->if_dev->flags, value);
}

/**
* @brief Check if a value in network interface flags is set
*
Expand Down
30 changes: 15 additions & 15 deletions include/zephyr/net/net_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ struct sockaddr_in_ptr {

/** Socket address struct for packet socket. */
struct sockaddr_ll {
sa_family_t sll_family; /* Always AF_PACKET */
uint16_t sll_protocol; /* Physical-layer protocol */
int sll_ifindex; /* Interface number */
uint16_t sll_hatype; /* ARP hardware type */
uint8_t sll_pkttype; /* Packet type */
uint8_t sll_halen; /* Length of address */
uint8_t sll_addr[8]; /* Physical-layer address */
sa_family_t sll_family; /* Always AF_PACKET */
uint16_t sll_protocol; /* Physical-layer protocol */
int sll_ifindex; /* Interface number */
uint16_t sll_hatype; /* ARP hardware type */
uint8_t sll_pkttype; /* Packet type */
uint8_t sll_halen; /* Length of address */
uint8_t sll_addr[8]; /* Physical-layer address, big endian */
};

struct sockaddr_ll_ptr {
sa_family_t sll_family; /* Always AF_PACKET */
uint16_t sll_protocol; /* Physical-layer protocol */
int sll_ifindex; /* Interface number */
uint16_t sll_hatype; /* ARP hardware type */
uint8_t sll_pkttype; /* Packet type */
uint8_t sll_halen; /* Length of address */
uint8_t *sll_addr; /* Physical-layer address */
sa_family_t sll_family; /* Always AF_PACKET */
uint16_t sll_protocol; /* Physical-layer protocol */
int sll_ifindex; /* Interface number */
uint16_t sll_hatype; /* ARP hardware type */
uint8_t sll_pkttype; /* Packet type */
uint8_t sll_halen; /* Length of address */
uint8_t *sll_addr; /* Physical-layer address, big endian */
};

struct sockaddr_can_ptr {
Expand All @@ -233,7 +233,7 @@ struct iovec {
#endif

struct msghdr {
void *msg_name; /* optional socket address */
void *msg_name; /* optional socket address, big endian */
socklen_t msg_namelen; /* size of socket address */
struct iovec *msg_iov; /* scatter/gather array */
size_t msg_iovlen; /* number of elements in msg_iov */
Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/net/net_linkaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ enum net_link_type {
*/
struct net_linkaddr {
/** The array of byte representing the address */
uint8_t *addr;
uint8_t *addr; /* in big endian */

/** Length of that address array */
uint8_t len;
Expand All @@ -93,7 +93,7 @@ struct net_linkaddr_storage {
uint8_t len;

/** The array of bytes representing the address */
uint8_t addr[NET_LINK_ADDR_MAX_LENGTH];
uint8_t addr[NET_LINK_ADDR_MAX_LENGTH]; /* in big endian */
};

/**
Expand Down
2 changes: 1 addition & 1 deletion samples/net/wpan_serial/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static uint8_t slip_buf[1 + 2 * CONFIG_NET_BUF_DATA_SIZE];
static struct ieee802154_radio_api *radio_api;
static const struct device *const ieee802154_dev =
DEVICE_DT_GET(DT_CHOSEN(zephyr_ieee802154));
uint8_t mac_addr[8];
uint8_t mac_addr[8]; /* in little endian */

/* UART device */
static const struct device *const uart_dev =
Expand Down
6 changes: 3 additions & 3 deletions samples/net/wpanusb/src/wpanusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ struct set_channel {
} __packed;

struct set_short_addr {
uint16_t short_addr;
uint16_t short_addr; /* in CPU byte order */
} __packed;

struct set_pan_id {
uint16_t pan_id;
uint16_t pan_id; /* in CPU byte order */
} __packed;

struct set_ieee_addr {
uint64_t ieee_addr;
uint64_t ieee_addr; /* big endian */
} __packed;
3 changes: 1 addition & 2 deletions subsys/net/ip/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,7 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
} else if (IS_ENABLED(CONFIG_NET_SOCKETS_CAN) && conn_family == AF_CAN) {
best_match = conn;
}
/* loop end */
}
} /* loop end */

if (IS_ENABLED(CONFIG_NET_SOCKETS_PACKET) && pkt_family == AF_PACKET) {
if (raw_pkt_continue) {
Expand Down
21 changes: 4 additions & 17 deletions subsys/net/ip/net_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,23 +757,10 @@ int net_context_bind(struct net_context *context, const struct sockaddr *addr,
ll_addr->sll_ifindex;
net_sll_ptr(&context->local)->sll_protocol =
ll_addr->sll_protocol;
if (IS_ENABLED(CONFIG_NET_L2_IEEE802154) &&
ll_addr->sll_protocol == ETH_P_IEEE802154 &&
ll_addr->sll_halen > 0) {
if (ll_addr->sll_halen !=
IEEE802154_SHORT_ADDR_LENGTH) {
return -EINVAL;
}
net_sll_ptr(&context->local)->sll_addr =
ll_addr->sll_addr;
net_sll_ptr(&context->local)->sll_halen =
ll_addr->sll_halen;
} else {
net_sll_ptr(&context->local)->sll_addr =
net_if_get_link_addr(iface)->addr;
net_sll_ptr(&context->local)->sll_halen =
net_if_get_link_addr(iface)->len;
}
net_sll_ptr(&context->local)->sll_addr =
net_if_get_link_addr(iface)->addr;
net_sll_ptr(&context->local)->sll_halen =
net_if_get_link_addr(iface)->len;

NET_DBG("Context %p bind to type 0x%04x iface[%d] %p addr %s",
context, htons(net_context_get_proto(context)),
Expand Down
Loading