sys/include/net/gnrc/netdev.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
29 #ifndef NET_GNRC_NETDEV_H
30 #define NET_GNRC_NETDEV_H
31 
32 #include <assert.h>
33 #include <stdint.h>
34 
35 #include "kernel_types.h"
36 #include "net/netdev.h"
37 #include "net/gnrc.h"
38 #include "net/gnrc/mac/types.h"
39 #include "net/ieee802154.h"
40 #include "net/gnrc/mac/mac.h"
41 #ifdef MODULE_GNRC_MAC
42 #include "net/csma_sender.h"
43 #endif
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
52 #ifndef GNRC_NETDEV_MAC_PRIO
53 #define GNRC_NETDEV_MAC_PRIO (THREAD_PRIORITY_MAIN - 5)
54 #endif
55 
59 #define NETDEV_MSG_TYPE_EVENT 0x1234
60 
64 #define GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK (0x0003U)
65 
70 #define GNRC_NETDEV_MAC_INFO_RX_STARTED (0x0004U)
71 
81 #define GNRC_NETDEV_MAC_INFO_CSMA_ENABLED (0x0100U)
82 
91 typedef struct gnrc_netdev {
98  int (*send)(struct gnrc_netdev *dev, gnrc_pktsnip_t *snip);
99 
107  gnrc_pktsnip_t * (*recv)(struct gnrc_netdev *dev);
108 
113 
118 
119 #ifdef MODULE_GNRC_MAC
120 
123  uint16_t mac_info;
124 
128  uint8_t l2_addr[IEEE802154_LONG_ADDRESS_LEN];
129 
133  uint8_t l2_addr_len;
134 
138  csma_sender_conf_t csma_conf;
139 
140 #if ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN)
141 
145  gnrc_mac_rx_t rx;
146 #endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */
147 
148 #if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
149 
153  gnrc_mac_tx_t tx;
154 #endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT == 0)) || defined(DOXYGEN) */
155 
156 #ifdef MODULE_GNRC_LWMAC
157 
161 #endif
162 
163 #endif /* MODULE_GNRC_MAC */
164 } gnrc_netdev_t;
165 
166 #ifdef MODULE_GNRC_MAC
167 
177 static inline bool gnrc_netdev_get_rx_started(gnrc_netdev_t *dev)
178 {
179  return (dev->mac_info & GNRC_NETDEV_MAC_INFO_RX_STARTED);
180 }
181 
190 static inline void gnrc_netdev_set_rx_started(gnrc_netdev_t *dev, bool rx_started)
191 {
192  if (rx_started) {
193  dev->mac_info |= GNRC_NETDEV_MAC_INFO_RX_STARTED;
194  }
195  else {
196  dev->mac_info &= ~GNRC_NETDEV_MAC_INFO_RX_STARTED;
197  }
198 }
199 
207 static inline gnrc_mac_tx_feedback_t gnrc_netdev_get_tx_feedback(gnrc_netdev_t *dev)
208 {
209  return (gnrc_mac_tx_feedback_t)(dev->mac_info &
211 }
212 
221 static inline void gnrc_netdev_set_tx_feedback(gnrc_netdev_t *dev,
223 {
224  /* check if gnrc_mac_tx_feedback does not collide with
225  * GNRC_NETDEV_MAC_INFO_RX_STARTED */
227  /* unset previous value */
228  dev->mac_info &= ~GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK;
229  dev->mac_info |= (uint16_t)(txf & GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK);
230 }
231 #endif
232 
245 kernel_pid_t gnrc_netdev_init(char *stack, int stacksize, char priority,
246  const char *name, gnrc_netdev_t *gnrc_netdev);
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif /* NET_GNRC_NETDEV_H */
253 
gnrc_mac_tx_feedback_t
definition for device transmission feedback types
Definition: mac/types.h:41
Types used by the kernel.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
Interface definition for the CSMA/CA helper.
struct gnrc_netdev gnrc_netdev_t
Structure holding GNRC netdev adapter state.
Definitions low-level network driver interface.
kernel_pid_t pid
PID of this adapter for netapi messages.
netdev_t * dev
netdev handle this adapter is working with
Structure holding GNRC netdev adapter state.
IEEE 802.15.4 header definitions.
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
kernel_pid_t gnrc_netdev_init(char *stack, int stacksize, char priority, const char *name, gnrc_netdev_t *gnrc_netdev)
Initialize GNRC netdev handler thread.
Includes all essential GNRC network stack base modules.
Configuration type for backoff.
Definition: csma_sender.h:69
int(* send)(struct gnrc_netdev *dev, gnrc_pktsnip_t *snip)
Send a pktsnip using this device.
Structure to hold driver state.
#define GNRC_NETDEV_MAC_INFO_RX_STARTED
Flag to track if a transmission might have corrupted a received packet.
MAC internal type for storing reception state parameters and state machines.
Definition: mac/types.h:61
Internal data types used by GNRC_MAC.
#define GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK
Mask for gnrc_mac_tx_feedback_t.
Type to represent parts (either headers or payload) of a packet, called snips.
LWMAC specific structure for storing internal states.
Definition: lwmac/types.h:201
MAC internal type for storing transmission state parameters and state machines.
Definition: mac/types.h:150
#define IEEE802154_LONG_ADDRESS_LEN
long address (EUI-64)
Definitions of GNRC_MAC.