netdev_test.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universit├Ąt Berlin
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 
79 #ifndef NET_NETDEV_TEST_H
80 #define NET_NETDEV_TEST_H
81 
82 #include "mutex.h"
83 
84 #ifdef MODULE_NETDEV_IEEE802154
85 #include "net/netdev/ieee802154.h"
86 #endif
87 
88 #include "net/netdev.h"
89 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
104 typedef int (*netdev_test_send_cb_t)(netdev_t *dev,
105  const struct iovec *vector,
106  int count);
107 
122 typedef int (*netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len,
123  void *info);
124 
133 typedef int (*netdev_test_init_cb_t)(netdev_t *dev);
134 
140 typedef void (*netdev_test_isr_cb_t)(netdev_t *dev);
141 
152 typedef int (*netdev_test_get_cb_t)(netdev_t *dev, void *value,
153  size_t max_len);
154 
165 typedef int (*netdev_test_set_cb_t)(netdev_t *dev, const void *value,
166  size_t value_len);
167 
173 typedef struct {
178 #ifdef MODULE_NETDEV_IEEE802154
180 #else /* MODULE_NETDEV_IEEE802154 */
182 #endif /* MODULE_NETDEV_IEEE802154 */
183 
195  void *state;
198 } netdev_test_t;
199 
206 static inline void netdev_test_set_send_cb(netdev_test_t *dev,
207  netdev_test_send_cb_t send_cb)
208 {
209  mutex_lock(&dev->mutex);
210  dev->send_cb = send_cb;
211  mutex_unlock(&dev->mutex);
212 }
213 
220 static inline void netdev_test_set_recv_cb(netdev_test_t *dev,
221  netdev_test_recv_cb_t recv_cb)
222 {
223  mutex_lock(&dev->mutex);
224  dev->recv_cb = recv_cb;
225  mutex_unlock(&dev->mutex);
226 }
227 
234 static inline void netdev_test_set_init_cb(netdev_test_t *dev,
235  netdev_test_init_cb_t init_cb)
236 {
237  mutex_lock(&dev->mutex);
238  dev->init_cb = init_cb;
239  mutex_unlock(&dev->mutex);
240 }
241 
248 static inline void netdev_test_set_isr_cb(netdev_test_t *dev,
249  netdev_test_isr_cb_t isr_cb)
250 {
251  mutex_lock(&dev->mutex);
252  dev->isr_cb = isr_cb;
253  mutex_unlock(&dev->mutex);
254 }
255 
263 static inline void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt,
264  netdev_test_get_cb_t get_cb)
265 {
266  mutex_lock(&dev->mutex);
267  dev->get_cbs[opt] = get_cb;
268  mutex_unlock(&dev->mutex);
269 }
270 
278 static inline void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt,
279  netdev_test_set_cb_t set_cb)
280 {
281  mutex_lock(&dev->mutex);
282  dev->set_cbs[opt] = set_cb;
283  mutex_unlock(&dev->mutex);
284 }
285 
292 void netdev_test_setup(netdev_test_t *dev, void *state);
293 
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 #endif /* NET_NETDEV_TEST_H */
306 
int(* netdev_test_send_cb_t)(netdev_t *dev, const struct iovec *vector, int count)
Callback type to handle send command.
Definition: netdev_test.h:104
void * state
external state for the device
Definition: netdev_test.h:195
netdev_test_set_cb_t set_cbs[NETOPT_NUMOF]
callback to handle set command
Definition: netdev_test.h:194
static void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt, netdev_test_get_cb_t get_cb)
override get callback for a certain option type
Definition: netdev_test.h:263
netdev_t netdev
netdev fields
Definition: netdev_test.h:181
mutex_t mutex
mutex for the device
Definition: netdev_test.h:196
netdev_test_recv_cb_t recv_cb
callback to handle receive command
Definition: netdev_test.h:190
int(* netdev_test_get_cb_t)(netdev_t *dev, void *value, size_t max_len)
Callback type to handle get commands.
Definition: netdev_test.h:152
Device descriptor for netdev dummy test driver devices.
Definition: netdev_test.h:173
void netdev_test_reset(netdev_test_t *dev)
Resets all callbacks for the device to NULL.
netdev_test_get_cb_t get_cbs[NETOPT_NUMOF]
callback to handle get command
Definition: netdev_test.h:193
netdev_test_init_cb_t init_cb
callback to handle initialization events
Definition: netdev_test.h:191
static void netdev_test_set_init_cb(netdev_test_t *dev, netdev_test_init_cb_t init_cb)
override initialization callback
Definition: netdev_test.h:234
Definitions low-level network driver interface.
netdev_test_isr_cb_t isr_cb
callback to handle ISR events
Definition: netdev_test.h:192
netdev_test_send_cb_t send_cb
device specific fields
Definition: netdev_test.h:189
static void netdev_test_set_send_cb(netdev_test_t *dev, netdev_test_send_cb_t send_cb)
override send callback
Definition: netdev_test.h:206
static void netdev_test_set_recv_cb(netdev_test_t *dev, netdev_test_recv_cb_t recv_cb)
override receive callback
Definition: netdev_test.h:220
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:36
Structure to hold driver state.
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
Definitions for netdev common IEEE 802.15.4 code.
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
Definition: mutex.h:111
maximum number of options defined here.
Definition: netopt.h:388
Structure for scatter/gather I/O.
Definition: uio.h:33
RIOT synchronization API.
int(* netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len, void *info)
Callback type to handle receive command.
Definition: netdev_test.h:122
void netdev_test_setup(netdev_test_t *dev, void *state)
Setup a given netdev dummy test driver device.
Mutex structure.
Definition: mutex.h:36
Extended structure to hold IEEE 802.15.4 driver state.
static void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt, netdev_test_set_cb_t set_cb)
override get callback for a certain option type
Definition: netdev_test.h:278
int(* netdev_test_init_cb_t)(netdev_t *dev)
Callback type to handle device initialization.
Definition: netdev_test.h:133
void(* netdev_test_isr_cb_t)(netdev_t *dev)
Callback type to handle user-space ISR events.
Definition: netdev_test.h:140
static void netdev_test_set_isr_cb(netdev_test_t *dev, netdev_test_isr_cb_t isr_cb)
override ISR event handler callback
Definition: netdev_test.h:248
int(* netdev_test_set_cb_t)(netdev_t *dev, const void *value, size_t value_len)
Callback type to handle set commands.
Definition: netdev_test.h:165