diff --git a/sys/include/net/gnrc/mac/internal.h b/sys/include/net/gnrc/mac/internal.h index 538300690d20982029051efba28daf209855510b..a9dd8924e39c0f98f3a32b51614b451dfbb56cf6 100644 --- a/sys/include/net/gnrc/mac/internal.h +++ b/sys/include/net/gnrc/mac/internal.h @@ -22,8 +22,9 @@ #define NET_GNRC_MAC_INTERNAL_H #include <stdint.h> -#include <net/ieee802154.h> -#include <net/gnrc/mac/types.h> + +#include "net/ieee802154.h" +#include "net/gnrc/mac/types.h" #ifdef __cplusplus extern "C" { @@ -47,7 +48,7 @@ extern "C" { * * @return true if queued successfully, otherwise false. */ -bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip_t* pkt); +bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t *tx, uint32_t priority, gnrc_pktsnip_t *pkt); #endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ #if (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) @@ -60,7 +61,7 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip * * @return true if queued successfully, otherwise false. */ -bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t* rx, uint32_t priority, gnrc_pktsnip_t* pkt); +bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t *rx, uint32_t priority, gnrc_pktsnip_t *pkt); #endif /* (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ #if (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) @@ -69,7 +70,7 @@ bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t* rx, uint32_t priority, gnrc_pktsnip * * @param[in,out] rx gnrc_mac reception management object */ -void gnrc_mac_dispatch(gnrc_mac_rx_t* rx); +void gnrc_mac_dispatch(gnrc_mac_rx_t *rx); #endif /* (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) */ #ifdef __cplusplus diff --git a/sys/include/net/gnrc/mac/types.h b/sys/include/net/gnrc/mac/types.h index c18e2ffdb5ee1642c833169a589bc35a7779a92e..63ac0e25dccf7283494797692ab1ad3a2dab8e9f 100644 --- a/sys/include/net/gnrc/mac/types.h +++ b/sys/include/net/gnrc/mac/types.h @@ -23,11 +23,12 @@ #include <stdint.h> #include <stdbool.h> -#include <kernel_types.h> -#include <net/gnrc.h> -#include <net/gnrc/priority_pktqueue.h> -#include <net/ieee802154.h> -#include <net/gnrc/mac/mac.h> + +#include "kernel_types.h" +#include "net/gnrc.h" +#include "net/gnrc/priority_pktqueue.h" +#include "net/ieee802154.h" +#include "net/gnrc/mac/mac.h" #ifdef __cplusplus extern "C" { @@ -37,10 +38,10 @@ extern "C" { * @brief definition for device transmission feedback types */ typedef enum { - TX_FEEDBACK_UNDEF = 0, /**< Transmission just start, no Tx feedback yet */ - TX_FEEDBACK_SUCCESS, /**< Transmission succeeded */ - TX_FEEDBACK_NOACK, /**< No ACK for the transmitted packet */ - TX_FEEDBACK_BUSY /**< found medium busy when doing transmission */ + TX_FEEDBACK_UNDEF = 0, /**< Transmission just start, no Tx feedback yet */ + TX_FEEDBACK_SUCCESS, /**< Transmission succeeded */ + TX_FEEDBACK_NOACK, /**< No ACK for the transmitted packet */ + TX_FEEDBACK_BUSY /**< found medium busy when doing transmission */ } gnrc_mac_tx_feedback_t; /** @@ -58,12 +59,12 @@ typedef enum { */ typedef struct { #if (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) - gnrc_priority_pktqueue_t queue; /**< RX packet queue */ - gnrc_priority_pktqueue_node_t _queue_nodes[GNRC_MAC_RX_QUEUE_SIZE]; /**< RX queue nodes */ + gnrc_priority_pktqueue_t queue; /**< RX packet queue */ + gnrc_priority_pktqueue_node_t _queue_nodes[GNRC_MAC_RX_QUEUE_SIZE]; /**< RX queue nodes */ #endif /* (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ #if (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) - gnrc_pktsnip_t* dispatch_buffer[GNRC_MAC_DISPATCH_BUFFER_SIZE]; /**< dispatch packet buffer */ + gnrc_pktsnip_t *dispatch_buffer[GNRC_MAC_DISPATCH_BUFFER_SIZE]; /**< dispatch packet buffer */ #endif /* (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) */ } gnrc_mac_rx_t; @@ -72,30 +73,30 @@ typedef struct { */ #if ((GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) #define GNRC_MAC_RX_INIT { \ - PRIORITY_PKTQUEUE_INIT, \ - { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ - { NULL }, \ + PRIORITY_PKTQUEUE_INIT, \ + { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ + { NULL }, \ } #elif (GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE == 0) || defined(DOXYGEN) #define GNRC_MAC_RX_INIT { \ - PRIORITY_PKTQUEUE_INIT, \ - { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ + PRIORITY_PKTQUEUE_INIT, \ + { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ } #elif (GNRC_MAC_RX_QUEUE_SIZE == 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) #define GNRC_MAC_RX_INIT { \ - { NULL }, \ + { NULL }, \ } -#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */ -#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */ +#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */ +#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */ #if (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) /** * @brief type for storing states of TX neighbor node. */ typedef struct { - uint8_t l2_addr[IEEE802154_LONG_ADDRESS_LEN]; /**< Address of neighbor node */ - uint8_t l2_addr_len; /**< Neighbor address length */ - uint32_t phase; /**< Neighbor's wake-up Phase */ + uint8_t l2_addr[IEEE802154_LONG_ADDRESS_LEN]; /**< Address of neighbor node */ + uint8_t l2_addr_len; /**< Neighbor address length */ + uint32_t phase; /**< Neighbor's wake-up Phase */ #if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) gnrc_priority_pktqueue_t queue; /**< TX queue for this particular Neighbor */ @@ -117,19 +118,19 @@ typedef struct { */ #if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) #define GNRC_MAC_TX_NEIGHBOR_INIT { \ - { 0 }, \ - 0, \ - GNRC_MAC_PHASE_UNINITIALIZED, \ - PRIORITY_PKTQUEUE_INIT, \ + { 0 }, \ + 0, \ + GNRC_MAC_PHASE_UNINITIALIZED, \ + PRIORITY_PKTQUEUE_INIT, \ } #else #define GNRC_MAC_TX_NEIGHBOR_INIT { \ - { 0 }, \ - 0, \ - GNRC_MAC_PHASE_UNINITIALIZED, \ + { 0 }, \ + 0, \ + GNRC_MAC_PHASE_UNINITIALIZED, \ } -#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ -#endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ +#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ +#endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ #if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) /** @@ -143,7 +144,7 @@ typedef struct { #if (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) gnrc_mac_tx_neighbor_t neighbors[GNRC_MAC_NEIGHBOR_COUNT + 1]; /**< Neighbor information units for one-hop neighbors. First unit is for broadcast (+1) */ - gnrc_mac_tx_neighbor_t* current_neighbor; /**< Neighbor information unit of destination node to which + gnrc_mac_tx_neighbor_t *current_neighbor; /**< Neighbor information unit of destination node to which the current packet will be sent */ #endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ @@ -154,7 +155,7 @@ typedef struct { #endif /* (GNRC_MAC_NEIGHBOR_COUNT == 0) || defined(DOXYGEN) */ gnrc_priority_pktqueue_node_t _queue_nodes[GNRC_MAC_TX_QUEUE_SIZE]; /**< Shared buffer for TX queue nodes */ - gnrc_pktsnip_t* packet; /**< currently scheduled packet for sending */ + gnrc_pktsnip_t *packet; /**< currently scheduled packet for sending */ #endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ } gnrc_mac_tx_t; @@ -163,24 +164,24 @@ typedef struct { */ #if ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) #define GNRC_MAC_TX_INIT { \ - { GNRC_MAC_TX_NEIGHBOR_INIT }, \ - NULL, \ - { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ - NULL, \ + { GNRC_MAC_TX_NEIGHBOR_INIT }, \ + NULL, \ + { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ + NULL, \ } #elif ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT == 0)) || defined(DOXYGEN) #define GNRC_MAC_TX_INIT { \ - PRIORITY_PKTQUEUE_INIT, \ - { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ - NULL, \ + PRIORITY_PKTQUEUE_INIT, \ + { PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \ + NULL, \ } #elif ((GNRC_MAC_TX_QUEUE_SIZE == 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) #define GNRC_MAC_TX_INIT { \ - { GNRC_MAC_TX_NEIGHBOR_INIT }, \ - NULL, \ + { GNRC_MAC_TX_NEIGHBOR_INIT }, \ + NULL, \ } -#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ -#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ +#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ +#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ #ifdef __cplusplus } diff --git a/sys/net/gnrc/link_layer/gnrc_mac/internal.c b/sys/net/gnrc/link_layer/gnrc_mac/internal.c index 88aafc743b132f7b224c354337d875d4da5dca66..1279438e254fb4e7309ce7041fcbdc388ae16a0e 100644 --- a/sys/net/gnrc/link_layer/gnrc_mac/internal.c +++ b/sys/net/gnrc/link_layer/gnrc_mac/internal.c @@ -20,14 +20,16 @@ */ #include <stdbool.h> -#include <net/gnrc.h> -#include <net/gnrc/mac/internal.h> + +#include "net/gnrc.h" +#include "net/gnrc/mac/internal.h" #define ENABLE_DEBUG (0) #include "debug.h" #if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_RX_QUEUE_SIZE != 0)) -gnrc_priority_pktqueue_node_t* _alloc_pktqueue_node(gnrc_priority_pktqueue_node_t* nodes, uint32_t size) +gnrc_priority_pktqueue_node_t *_alloc_pktqueue_node(gnrc_priority_pktqueue_node_t *nodes, + uint32_t size) { assert(nodes != NULL); assert(size > 0); @@ -47,13 +49,13 @@ gnrc_priority_pktqueue_node_t* _alloc_pktqueue_node(gnrc_priority_pktqueue_node_ #if GNRC_MAC_TX_QUEUE_SIZE != 0 #if GNRC_MAC_NEIGHBOR_COUNT != 0 /* Find the neighbor's id based on the given address */ -int _gnrc_mac_find_neighbor(gnrc_mac_tx_t* tx, const uint8_t* dst_addr, int addr_len) +int _gnrc_mac_find_neighbor(gnrc_mac_tx_t *tx, const uint8_t *dst_addr, int addr_len) { assert(tx != NULL); assert(dst_addr != NULL); assert(addr_len > 0); - gnrc_mac_tx_neighbor_t* neighbors; + gnrc_mac_tx_neighbor_t *neighbors; neighbors = tx->neighbors; /* Don't attempt to find broadcast neighbor, so start at index 1 */ @@ -68,11 +70,11 @@ int _gnrc_mac_find_neighbor(gnrc_mac_tx_t* tx, const uint8_t* dst_addr, int addr } /* Free first empty queue (neighbor) that is not active */ -int _gnrc_mac_free_neighbor(gnrc_mac_tx_t* tx) +int _gnrc_mac_free_neighbor(gnrc_mac_tx_t *tx) { assert(tx != NULL); - gnrc_mac_tx_neighbor_t* neighbors; + gnrc_mac_tx_neighbor_t *neighbors; neighbors = tx->neighbors; /* Don't attempt to free broadcast neighbor, so start at index 1 */ @@ -88,11 +90,11 @@ int _gnrc_mac_free_neighbor(gnrc_mac_tx_t* tx) } /* Allocate first unused queue (neighbor) */ -int _gnrc_mac_alloc_neighbor(gnrc_mac_tx_t* tx) +int _gnrc_mac_alloc_neighbor(gnrc_mac_tx_t *tx) { assert(tx != NULL); - gnrc_mac_tx_neighbor_t* neighbors; + gnrc_mac_tx_neighbor_t *neighbors; neighbors = tx->neighbors; /* Don't attempt to allocate broadcast neighbor, so start at index 1 */ @@ -106,7 +108,7 @@ int _gnrc_mac_alloc_neighbor(gnrc_mac_tx_t* tx) } /* Initialize the neighbor */ -void _gnrc_mac_init_neighbor(gnrc_mac_tx_neighbor_t* neighbor, const uint8_t* addr, int len) +void _gnrc_mac_init_neighbor(gnrc_mac_tx_neighbor_t *neighbor, const uint8_t *addr, int len) { assert(neighbor != NULL); assert(addr != NULL); @@ -118,14 +120,14 @@ void _gnrc_mac_init_neighbor(gnrc_mac_tx_neighbor_t* neighbor, const uint8_t* ad } #endif /* GNRC_MAC_NEIGHBOR_COUNT != 0 */ -bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip_t* pkt) +bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t *tx, uint32_t priority, gnrc_pktsnip_t *pkt) { assert(tx != NULL); assert(pkt != NULL); #if GNRC_MAC_NEIGHBOR_COUNT == 0 - gnrc_priority_pktqueue_node_t* node; + gnrc_priority_pktqueue_node_t *node; node = _alloc_pktqueue_node(tx->_queue_nodes, GNRC_MAC_TX_QUEUE_SIZE); if (node) { @@ -139,17 +141,19 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip #else - gnrc_mac_tx_neighbor_t* neighbor; + gnrc_mac_tx_neighbor_t *neighbor; int neighbor_id; /* Check whether the packet it for broadcast or multicast */ - if (gnrc_netif_hdr_get_flag(pkt) & (GNRC_NETIF_HDR_FLAGS_MULTICAST | GNRC_NETIF_HDR_FLAGS_BROADCAST)) { + if (gnrc_netif_hdr_get_flag(pkt) & + (GNRC_NETIF_HDR_FLAGS_MULTICAST | GNRC_NETIF_HDR_FLAGS_BROADCAST)) { /* Broadcast/multicast queue is neighbor 0 by definition */ neighbor_id = 0; neighbor = &tx->neighbors[neighbor_id]; - } else { - uint8_t* addr; + } + else { + uint8_t *addr; int addr_len; bool neighbor_known = true; @@ -193,7 +197,7 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip } } - gnrc_priority_pktqueue_node_t* node; + gnrc_priority_pktqueue_node_t *node; node = _alloc_pktqueue_node(tx->_queue_nodes, GNRC_MAC_TX_QUEUE_SIZE); if (node) { gnrc_priority_pktqueue_node_init(node, priority, pkt); @@ -203,20 +207,20 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip } DEBUG("[gnrc_mac-int] Can't push to neighbor #%d's queue, no entries left\n", - neighbor_id); + neighbor_id); return false; -#endif /* GNRC_MAC_NEIGHBOR_COUNT == 0 */ +#endif /* GNRC_MAC_NEIGHBOR_COUNT == 0 */ } -#endif /* GNRC_MAC_TX_QUEUE_SIZE != 0 */ +#endif /* GNRC_MAC_TX_QUEUE_SIZE != 0 */ #if GNRC_MAC_RX_QUEUE_SIZE != 0 -bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t* rx, uint32_t priority, gnrc_pktsnip_t* pkt) +bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t *rx, uint32_t priority, gnrc_pktsnip_t *pkt) { assert(rx != NULL); assert(pkt != NULL); - gnrc_priority_pktqueue_node_t* node; + gnrc_priority_pktqueue_node_t *node; node = _alloc_pktqueue_node(rx->_queue_nodes, GNRC_MAC_RX_QUEUE_SIZE); if (node) { @@ -231,13 +235,15 @@ bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t* rx, uint32_t priority, gnrc_pktsnip #endif /* GNRC_MAC_RX_QUEUE_SIZE != 0 */ #if GNRC_MAC_DISPATCH_BUFFER_SIZE != 0 -void gnrc_mac_dispatch(gnrc_mac_rx_t* rx) +void gnrc_mac_dispatch(gnrc_mac_rx_t *rx) { assert(rx != NULL); for (unsigned i = 0; i < GNRC_MAC_DISPATCH_BUFFER_SIZE; i++) { if (rx->dispatch_buffer[i]) { - if (!gnrc_netapi_dispatch_receive(rx->dispatch_buffer[i]->type, GNRC_NETREG_DEMUX_CTX_ALL, rx->dispatch_buffer[i])) { + if (!gnrc_netapi_dispatch_receive(rx->dispatch_buffer[i]->type, + GNRC_NETREG_DEMUX_CTX_ALL, + rx->dispatch_buffer[i])) { DEBUG("Unable to forward packet of type %i\n", buffer[i]->type); gnrc_pktbuf_release(rx->dispatch_buffer[i]); }