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  */
78 #ifndef NET_NETDEV_TEST_H
79 #define NET_NETDEV_TEST_H
81 #include "mutex.h"
83 #include "net/netdev/ieee802154.h"
84 #include "net/netdev.h"
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
99 typedef int (*netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist);
115 typedef int (*netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len,
116  void *info);
126 typedef int (*netdev_test_init_cb_t)(netdev_t *dev);
133 typedef void (*netdev_test_isr_cb_t)(netdev_t *dev);
145 typedef int (*netdev_test_get_cb_t)(netdev_t *dev, void *value,
146  size_t max_len);
158 typedef int (*netdev_test_set_cb_t)(netdev_t *dev, const void *value,
159  size_t value_len);
166 typedef struct {
184  void *state;
187 } netdev_test_t;
195 static inline void netdev_test_set_send_cb(netdev_test_t *dev,
196  netdev_test_send_cb_t send_cb)
197 {
198  mutex_lock(&dev->mutex);
199  dev->send_cb = send_cb;
200  mutex_unlock(&dev->mutex);
201 }
209 static inline void netdev_test_set_recv_cb(netdev_test_t *dev,
210  netdev_test_recv_cb_t recv_cb)
211 {
212  mutex_lock(&dev->mutex);
213  dev->recv_cb = recv_cb;
214  mutex_unlock(&dev->mutex);
215 }
223 static inline void netdev_test_set_init_cb(netdev_test_t *dev,
224  netdev_test_init_cb_t init_cb)
225 {
226  mutex_lock(&dev->mutex);
227  dev->init_cb = init_cb;
228  mutex_unlock(&dev->mutex);
229 }
237 static inline void netdev_test_set_isr_cb(netdev_test_t *dev,
238  netdev_test_isr_cb_t isr_cb)
239 {
240  mutex_lock(&dev->mutex);
241  dev->isr_cb = isr_cb;
242  mutex_unlock(&dev->mutex);
243 }
252 static inline void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt,
253  netdev_test_get_cb_t get_cb)
254 {
255  mutex_lock(&dev->mutex);
256  dev->get_cbs[opt] = get_cb;
257  mutex_unlock(&dev->mutex);
258 }
267 static inline void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt,
268  netdev_test_set_cb_t set_cb)
269 {
270  mutex_lock(&dev->mutex);
271  dev->set_cbs[opt] = set_cb;
272  mutex_unlock(&dev->mutex);
273 }
281 void netdev_test_setup(netdev_test_t *dev, void *state);
290 #ifdef __cplusplus
291 }
292 #endif
294 #endif /* NET_NETDEV_TEST_H */
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:42
maximum number of options defined here.
Definition: netopt.h:815
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:209
void netdev_test_reset(netdev_test_t *dev)
Resets all callbacks for the device to NULL.
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:252
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:158
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:115
int(* netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist)
Callback type to handle send command.
Definition: netdev_test.h:99
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:223
int(* netdev_test_init_cb_t)(netdev_t *dev)
Callback type to handle device initialization.
Definition: netdev_test.h:126
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:145
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:237
void netdev_test_setup(netdev_test_t *dev, void *state)
Setup a given netdev dummy test driver device.
void(* netdev_test_isr_cb_t)(netdev_t *dev)
Callback type to handle user-space ISR events.
Definition: netdev_test.h:133
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:267
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:195
Mutex for thread synchronization.
iolist structure definition
Definition: iolist.h:39
Mutex structure.
Definition: mutex.h:123
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:100
Device descriptor for netdev dummy test driver devices.
Definition: netdev_test.h:166
netdev_ieee802154_t netdev
netdev fields
Definition: netdev_test.h:171
netdev_test_get_cb_t get_cbs[NETOPT_NUMOF]
callback to handle get command
Definition: netdev_test.h:182
mutex_t mutex
mutex for the device
Definition: netdev_test.h:185
netdev_test_send_cb_t send_cb
device specific fields
Definition: netdev_test.h:178
netdev_test_set_cb_t set_cbs[NETOPT_NUMOF]
callback to handle set command
Definition: netdev_test.h:183
netdev_test_isr_cb_t isr_cb
callback to handle ISR events
Definition: netdev_test.h:181
netdev_test_recv_cb_t recv_cb
callback to handle receive command
Definition: netdev_test.h:179
void * state
external state for the device
Definition: netdev_test.h:184
netdev_test_init_cb_t init_cb
callback to handle initialization events
Definition: netdev_test.h:180
Structure to hold driver state.
Definition: netdev.h:351