netdev.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3 * 2015 Ell-i open source co-operative
4 * 2015-2017 Freie Universit├Ąt Berlin
5 * 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
6 *
7 * This file is subject to the terms and conditions of the GNU Lesser General
8 * Public License v2.1. See the file LICENSE in the top level directory for
9 * more details.
10 */
11
190#ifndef NET_NETDEV_H
191#define NET_NETDEV_H
192
193#ifdef __cplusplus
194extern "C" {
195#endif
196
197#include <stdint.h>
198#include <errno.h>
199
200#include "iolist.h"
201#include "net/netopt.h"
202#include "kernel_defines.h"
203
204#ifdef MODULE_L2FILTER
205#include "net/l2filter.h"
206#endif
207
215enum {
216 NETDEV_TYPE_UNKNOWN,
217 NETDEV_TYPE_TEST,
218 NETDEV_TYPE_RAW,
219 NETDEV_TYPE_ETHERNET,
220 NETDEV_TYPE_IEEE802154,
221 NETDEV_TYPE_BLE,
222 NETDEV_TYPE_CC110X,
223 NETDEV_TYPE_LORA,
224 NETDEV_TYPE_NRFMIN,
225 NETDEV_TYPE_NRF24L01P_NG,
226 NETDEV_TYPE_SLIP,
227 NETDEV_TYPE_ESP_NOW,
228};
235typedef enum {
271 /* expand this list if needed */
273
280 int16_t rssi;
281 uint8_t lqi;
282};
283
287typedef struct netdev netdev_t;
288
296
305typedef enum {
307 NETDEV_AT86RF215,
308 NETDEV_AT86RF2XX,
309 NETDEV_CC2538,
310 NETDEV_DOSE,
311 NETDEV_ENC28J60,
312 NETDEV_KW41ZRF,
313 NETDEV_MRF24J40,
314 NETDEV_NRF802154,
315 NETDEV_STM32_ETH,
316 NETDEV_CC110X,
317 NETDEV_SX127X,
318 NETDEV_SAM0_ETH,
319 NETDEV_ESP_NOW,
320 NETDEV_NRF24L01P_NG,
321 NETDEV_SOCKET_ZEP,
322 NETDEV_SX126X,
323 NETDEV_SX1280,
324 NETDEV_CC2420,
325 NETDEV_ETHOS,
326 NETDEV_SLIPDEV,
327 NETDEV_TAP,
328 NETDEV_W5100,
329 NETDEV_ENCX24J600,
330 NETDEV_ATWINC15X0,
331 NETDEV_KW2XRF,
332 NETDEV_ESP_ETH,
333 NETDEV_ESP_WIFI,
334 NETDEV_CDC_ECM,
335 NETDEV_TINYUSB,
336 /* add more if needed */
343#define NETDEV_INDEX_ANY (0xFF)
344
345#if DOXYGEN
350#define CONFIG_NETDEV_REGISTER_SIGNAL 0
351#endif
352
362struct netdev {
363 const struct netdev_driver *driver;
365 void *context;
366#ifdef MODULE_NETDEV_LAYER
367 netdev_t *lower;
368#endif
369#ifdef MODULE_L2FILTER
371#endif
372#ifdef MODULE_NETDEV_REGISTER
373 netdev_type_t type;
374 uint8_t index;
375#endif
376};
377
391void netdev_register_signal(struct netdev *dev, netdev_type_t type, uint8_t index);
392
401static inline void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
402{
403#ifdef MODULE_NETDEV_REGISTER
404 dev->type = type;
405 dev->index = index;
406#else
407 (void) dev;
408 (void) type;
409 (void) index;
410#endif
411
413 netdev_register_signal(dev, type, index);
414 }
415}
416
423typedef struct netdev_driver {
453 int (*send)(netdev_t *dev, const iolist_t *iolist);
454
483 int (*confirm_send)(netdev_t *dev, void *info);
484
520 int (*recv)(netdev_t *dev, void *buf, size_t len, void *info);
521
532 int (*init)(netdev_t *dev);
533
550 void (*isr)(netdev_t *dev);
551
573 int (*get)(netdev_t *dev, netopt_t opt,
574 void *value, size_t max_len);
575
599 int (*set)(netdev_t *dev, netopt_t opt,
600 const void *value, size_t value_len);
602
613static inline int netdev_get_notsup(netdev_t *dev, netopt_t opt,
614 void *value, size_t max_len)
615{
616 (void)dev;
617 (void)opt;
618 (void)value;
619 (void)max_len;
620 return -ENOTSUP;
621}
622
633static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
634 const void *value, size_t value_len)
635{
636 (void)dev;
637 (void)opt;
638 (void)value;
639 (void)value_len;
640 return -ENOTSUP;
641}
642
652{
653 if (netdev->event_callback) {
655 }
656}
657#ifdef __cplusplus
658}
659#endif
660
661#endif /* NET_NETDEV_H */
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
static void netdev_trigger_event_isr(netdev_t *netdev)
Informs netdev there was an interrupt request from the network device.
Definition: netdev.h:651
void netdev_register_signal(struct netdev *dev, netdev_type_t type, uint8_t index)
Signal that the netdev_register function registered the device.
static int netdev_get_notsup(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
Convenience function for declaring get() as not supported in general.
Definition: netdev.h:613
#define CONFIG_NETDEV_REGISTER_SIGNAL
Call netdev_register_signal when the netdev device is registered.
Definition: netdev.h:350
static void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
Register a device with netdev.
Definition: netdev.h:401
netdev_type_t
Driver types for netdev.
Definition: netdev.h:305
struct netdev_driver netdev_driver_t
Structure to hold driver interface -> function mapping.
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition: netdev.h:295
static int netdev_set_notsup(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
Convenience function for declaring set() as not supported in general.
Definition: netdev.h:633
netdev_event_t
Possible event types that are send from the device driver to the upper layer.
Definition: netdev.h:235
@ NETDEV_ANY
Will match any device type.
Definition: netdev.h:306
@ NETDEV_EVENT_TX_STARTED
started to transfer a frame
Definition: netdev.h:239
@ NETDEV_EVENT_ISR
driver needs it's ISR handled
Definition: netdev.h:236
@ NETDEV_EVENT_LINK_UP
link established
Definition: netdev.h:264
@ NETDEV_EVENT_TX_NOACK
ACK requested but not received.
Definition: netdev.h:256
@ NETDEV_EVENT_RX_COMPLETE
finished receiving a frame
Definition: netdev.h:238
@ NETDEV_EVENT_CRC_ERROR
wrong CRC
Definition: netdev.h:268
@ NETDEV_EVENT_TX_MEDIUM_BUSY
couldn't transfer frame
Definition: netdev.h:263
@ NETDEV_EVENT_TX_TIMEOUT
timeout when sending
Definition: netdev.h:266
@ NETDEV_EVENT_FHSS_CHANGE_CHANNEL
channel changed
Definition: netdev.h:269
@ NETDEV_EVENT_RX_STARTED
started to receive a frame
Definition: netdev.h:237
@ NETDEV_EVENT_TX_COMPLETE_DATA_PENDING
transfer frame complete and data pending flag
Definition: netdev.h:248
@ NETDEV_EVENT_TX_COMPLETE
transfer frame complete
Definition: netdev.h:240
@ NETDEV_EVENT_RX_TIMEOUT
timeout when receiving
Definition: netdev.h:267
@ NETDEV_EVENT_LINK_DOWN
link gone
Definition: netdev.h:265
@ NETDEV_EVENT_CAD_DONE
channel activity detection done
Definition: netdev.h:270
#define CONFIG_L2FILTER_LISTSIZE
Number of slots in each filter list (filter entries per device)
Definition: l2filter.h:59
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:45
iolist scatter / gather IO
Common macros and compiler attributes/pragmas configuration.
Link layer address filter interface definition.
#define IS_ACTIVE(macro)
Allows to verify a macro definition outside the preprocessor.
Definition: modules.h:60
Definition of global configuration options.
event structure
Definition: event.h:148
iolist structure definition
Definition: iolist.h:39
Filter list entries.
Definition: l2filter.h:70
Structure to hold driver interface -> function mapping.
Definition: netdev.h:423
int(* get)(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
Get an option value from a given network device.
Definition: netdev.h:573
int(* send)(netdev_t *dev, const iolist_t *iolist)
Start transmission of the given frame and return directly.
Definition: netdev.h:453
int(* confirm_send)(netdev_t *dev, void *info)
Fetch the status of a transmission and perform any potential cleanup.
Definition: netdev.h:483
int(* set)(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
Set an option value for a given network device.
Definition: netdev.h:599
int(* recv)(netdev_t *dev, void *buf, size_t len, void *info)
Drop a received frame, OR get the length of a received frame, OR get a received frame.
Definition: netdev.h:520
int(* init)(netdev_t *dev)
the driver's initialization function
Definition: netdev.h:532
void(* isr)(netdev_t *dev)
a driver's user-space ISR handler
Definition: netdev.h:550
Received frame status information for most radios.
Definition: netdev.h:279
uint8_t lqi
LQI of a received frame.
Definition: netdev.h:281
int16_t rssi
RSSI of a received frame in dBm.
Definition: netdev.h:280
Structure to hold driver state.
Definition: netdev.h:362
const struct netdev_driver * driver
ptr to that driver's interface.
Definition: netdev.h:363
void * context
ptr to network stack context
Definition: netdev.h:365
netdev_event_cb_t event_callback
callback for device events
Definition: netdev.h:364