netdev_test.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
78 #include "mutex.h"
79 
80 #include "net/netdev/ieee802154.h"
81 #include "net/netdev.h"
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
96 typedef int (*netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist);
97 
112 typedef int (*netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len,
113  void *info);
114 
123 typedef int (*netdev_test_init_cb_t)(netdev_t *dev);
124 
130 typedef void (*netdev_test_isr_cb_t)(netdev_t *dev);
131 
142 typedef int (*netdev_test_get_cb_t)(netdev_t *dev, void *value,
143  size_t max_len);
144 
155 typedef int (*netdev_test_set_cb_t)(netdev_t *dev, const void *value,
156  size_t value_len);
157 
163 typedef struct {
181  void *state;
184 } netdev_test_t;
185 
192 static inline void netdev_test_set_send_cb(netdev_test_t *dev,
193  netdev_test_send_cb_t send_cb)
194 {
195  mutex_lock(&dev->mutex);
196  dev->send_cb = send_cb;
197  mutex_unlock(&dev->mutex);
198 }
199 
206 static inline void netdev_test_set_recv_cb(netdev_test_t *dev,
207  netdev_test_recv_cb_t recv_cb)
208 {
209  mutex_lock(&dev->mutex);
210  dev->recv_cb = recv_cb;
211  mutex_unlock(&dev->mutex);
212 }
213 
220 static inline void netdev_test_set_init_cb(netdev_test_t *dev,
221  netdev_test_init_cb_t init_cb)
222 {
223  mutex_lock(&dev->mutex);
224  dev->init_cb = init_cb;
225  mutex_unlock(&dev->mutex);
226 }
227 
234 static inline void netdev_test_set_isr_cb(netdev_test_t *dev,
235  netdev_test_isr_cb_t isr_cb)
236 {
237  mutex_lock(&dev->mutex);
238  dev->isr_cb = isr_cb;
239  mutex_unlock(&dev->mutex);
240 }
241 
249 static inline void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt,
250  netdev_test_get_cb_t get_cb)
251 {
252  mutex_lock(&dev->mutex);
253  dev->get_cbs[opt] = get_cb;
254  mutex_unlock(&dev->mutex);
255 }
256 
264 static inline void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt,
265  netdev_test_set_cb_t set_cb)
266 {
267  mutex_lock(&dev->mutex);
268  dev->set_cbs[opt] = set_cb;
269  mutex_unlock(&dev->mutex);
270 }
271 
278 void netdev_test_setup(netdev_test_t *dev, void *state);
279 
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
void mutex_unlock(mutex_t *mutex)
Unlocks the mutex.
static void mutex_lock(mutex_t *mutex)
Locks a mutex, blocking.
Definition: mutex.h:202
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:41
@ NETOPT_NUMOF
maximum number of options defined here.
Definition: netopt.h:875
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:206
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:249
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:155
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:112
int(* netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist)
Callback type to handle send command.
Definition: netdev_test.h:96
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:220
int(* netdev_test_init_cb_t)(netdev_t *dev)
Callback type to handle device initialization.
Definition: netdev_test.h:123
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:142
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:234
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:130
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:264
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:192
Mutex for thread synchronization.
iolist structure definition
Definition: iolist.h:35
Mutex structure.
Definition: mutex.h:36
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:163
netdev_ieee802154_t netdev
netdev fields
Definition: netdev_test.h:168
netdev_test_get_cb_t get_cbs[NETOPT_NUMOF]
callback to handle get command
Definition: netdev_test.h:179
mutex_t mutex
mutex for the device
Definition: netdev_test.h:182
netdev_test_send_cb_t send_cb
device specific fields
Definition: netdev_test.h:175
netdev_test_set_cb_t set_cbs[NETOPT_NUMOF]
callback to handle set command
Definition: netdev_test.h:180
netdev_test_isr_cb_t isr_cb
callback to handle ISR events
Definition: netdev_test.h:178
netdev_test_recv_cb_t recv_cb
callback to handle receive command
Definition: netdev_test.h:176
void * state
external state for the device
Definition: netdev_test.h:181
netdev_test_init_cb_t init_cb
callback to handle initialization events
Definition: netdev_test.h:177
Structure to hold driver state.
Definition: netdev.h:365