Loading...
Searching...
No Matches
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
78#ifndef NET_NETDEV_TEST_H
79#define NET_NETDEV_TEST_H
80
81#include "mutex.h"
82
84#include "net/netdev.h"
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
99typedef int (*netdev_test_send_cb_t)(netdev_t *dev, const iolist_t *iolist);
100
115typedef int (*netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len,
116 void *info);
117
126typedef int (*netdev_test_init_cb_t)(netdev_t *dev);
127
133typedef void (*netdev_test_isr_cb_t)(netdev_t *dev);
134
145typedef int (*netdev_test_get_cb_t)(netdev_t *dev, void *value,
146 size_t max_len);
147
158typedef int (*netdev_test_set_cb_t)(netdev_t *dev, const void *value,
159 size_t value_len);
160
188
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}
202
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}
216
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}
230
237static inline void netdev_test_set_isr_cb(netdev_test_t *dev,
239{
240 mutex_lock(&dev->mutex);
241 dev->isr_cb = isr_cb;
242 mutex_unlock(&dev->mutex);
243}
244
252static inline void netdev_test_set_get_cb(netdev_test_t *dev, netopt_t opt,
254{
255 mutex_lock(&dev->mutex);
256 dev->get_cbs[opt] = get_cb;
257 mutex_unlock(&dev->mutex);
258}
259
267static inline void netdev_test_set_set_cb(netdev_test_t *dev, netopt_t opt,
269{
270 mutex_lock(&dev->mutex);
271 dev->set_cbs[opt] = set_cb;
272 mutex_unlock(&dev->mutex);
273}
274
281void netdev_test_setup(netdev_test_t *dev, void *state);
282
289
290#ifdef __cplusplus
291}
292#endif
293
294#endif /* NET_NETDEV_TEST_H */
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:312
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition netopt.h:45
@ NETOPT_NUMOF
maximum number of options defined here.
Definition netopt.h:879
static void netdev_test_set_recv_cb(netdev_test_t *dev, netdev_test_recv_cb_t recv_cb)
override receive callback
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
int(* netdev_test_set_cb_t)(netdev_t *dev, const void *value, size_t value_len)
Callback type to handle set commands.
int(* netdev_test_recv_cb_t)(netdev_t *dev, char *buf, int len, void *info)
Callback type to handle receive command.
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
int(* netdev_test_init_cb_t)(netdev_t *dev)
Callback type to handle device initialization.
int(* netdev_test_get_cb_t)(netdev_t *dev, void *value, size_t max_len)
Callback type to handle get commands.
static void netdev_test_set_isr_cb(netdev_test_t *dev, netdev_test_isr_cb_t isr_cb)
override ISR event handler callback
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.
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
static void netdev_test_set_send_cb(netdev_test_t *dev, netdev_test_send_cb_t send_cb)
override send callback
Mutex for thread synchronization.
iolist structure definition
Definition iolist.h:39
Mutex structure.
Definition mutex.h:146
Extended structure to hold IEEE 802.15.4 driver state.
Definition ieee802154.h:100
Device descriptor for netdev dummy test driver devices.
netdev_ieee802154_t netdev
netdev fields
netdev_test_get_cb_t get_cbs[NETOPT_NUMOF]
callback to handle get command
mutex_t mutex
mutex for the device
netdev_test_send_cb_t send_cb
device specific fields
netdev_test_set_cb_t set_cbs[NETOPT_NUMOF]
callback to handle set command
netdev_test_isr_cb_t isr_cb
callback to handle ISR events
netdev_test_recv_cb_t recv_cb
callback to handle receive command
void * state
external state for the device
netdev_test_init_cb_t init_cb
callback to handle initialization events
Structure to hold driver state.
Definition netdev.h:363