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
194 extern "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 
215 enum {
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_SLIP,
226  NETDEV_TYPE_ESP_NOW,
227 };
234 typedef enum {
250  /* expand this list if needed */
252 
259  int16_t rssi;
260  uint8_t lqi;
261 };
262 
266 typedef struct netdev netdev_t;
267 
274 
279 typedef enum {
281  NETDEV_AT86RF215,
282  NETDEV_AT86RF2XX,
283  NETDEV_CC2538,
284  NETDEV_DOSE,
285  NETDEV_ENC28J60,
286  NETDEV_KW41ZRF,
287  NETDEV_MRF24J40,
288  NETDEV_NRF802154,
289  /* add more if needed */
290 } netdev_type_t;
302 struct netdev {
303  const struct netdev_driver *driver;
305  void *context;
306 #ifdef MODULE_NETDEV_LAYER
307  netdev_t *lower;
308 #endif
309 #ifdef MODULE_L2FILTER
311 #endif
312 #ifdef MODULE_NETDEV_REGISTER
313  netdev_type_t type;
314  uint8_t index;
315 #endif
316 };
317 
326 static inline void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
327 {
328 #ifdef MODULE_NETDEV_REGISTER
329  dev->type = type;
330  dev->index = index;
331 #else
332  (void) dev;
333  (void) type;
334  (void) index;
335 #endif
336 }
337 
344 typedef struct netdev_driver {
360  int (*send)(netdev_t *dev, const iolist_t *iolist);
361 
397  int (*recv)(netdev_t *dev, void *buf, size_t len, void *info);
398 
409  int (*init)(netdev_t *dev);
410 
427  void (*isr)(netdev_t *dev);
428 
450  int (*get)(netdev_t *dev, netopt_t opt,
451  void *value, size_t max_len);
452 
476  int (*set)(netdev_t *dev, netopt_t opt,
477  const void *value, size_t value_len);
479 
490 static inline int netdev_get_notsup(netdev_t *dev, netopt_t opt,
491  void *value, size_t max_len)
492 {
493  (void)dev;
494  (void)opt;
495  (void)value;
496  (void)max_len;
497  return -ENOTSUP;
498 }
499 
510 static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
511  const void *value, size_t value_len)
512 {
513  (void)dev;
514  (void)opt;
515  (void)value;
516  (void)value_len;
517  return -ENOTSUP;
518 }
519 
529 {
530  if (netdev->event_callback) {
532  }
533 }
534 #ifdef __cplusplus
535 }
536 #endif
537 
538 #endif /* NET_NETDEV_H */
539 
NETDEV_EVENT_FHSS_CHANGE_CHANNEL
@ NETDEV_EVENT_FHSS_CHANGE_CHANNEL
channel changed
Definition: netdev.h:248
netdev_driver
Structure to hold driver interface -> function mapping.
Definition: netdev.h:344
netdev_driver::send
int(* send)(netdev_t *dev, const iolist_t *iolist)
Send frame.
Definition: netdev.h:360
netopt_t
netopt_t
Global list of configuration options available throughout the network stack, e.g.
Definition: netopt.h:50
netdev::driver
const struct netdev_driver * driver
ptr to that driver's interface.
Definition: netdev.h:303
netdev::event_callback
netdev_event_cb_t event_callback
callback for device events
Definition: netdev.h:304
ENOTSUP
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
netdev_driver::isr
void(* isr)(netdev_t *dev)
a driver's user-space ISR handler
Definition: netdev.h:427
netdev_get_notsup
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:490
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
l2filter_t
Filter list entries.
Definition: l2filter.h:70
netdev_event_t
netdev_event_t
Possible event types that are send from the device driver to the upper layer.
Definition: netdev.h:234
netopt.h
Definition of global configuration options.
netdev_driver::set
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:476
event
event structure
Definition: event.h:142
NETDEV_EVENT_TX_NOACK
@ NETDEV_EVENT_TX_NOACK
ACK requested but not received.
Definition: netdev.h:241
netdev_radio_rx_info::rssi
int16_t rssi
RSSI of a received frame in dBm.
Definition: netdev.h:259
NETDEV_ANY
@ NETDEV_ANY
Will match any device type.
Definition: netdev.h:280
netdev_driver::recv
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:397
netdev_type_t
netdev_type_t
Driver types for netdev.
Definition: netdev.h:279
NETDEV_EVENT_TX_TIMEOUT
@ NETDEV_EVENT_TX_TIMEOUT
timeout when sending
Definition: netdev.h:245
netdev_register
static void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
Register a device with netdev.
Definition: netdev.h:326
iolist.h
iolist scatter / gather IO
NETDEV_EVENT_LINK_DOWN
@ NETDEV_EVENT_LINK_DOWN
link gone
Definition: netdev.h:244
NETDEV_EVENT_CAD_DONE
@ NETDEV_EVENT_CAD_DONE
channel activity detection done
Definition: netdev.h:249
netdev_driver_t
struct netdev_driver netdev_driver_t
Structure to hold driver interface -> function mapping.
netdev_event_cb_t
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition: netdev.h:273
NETDEV_EVENT_RX_COMPLETE
@ NETDEV_EVENT_RX_COMPLETE
finished receiving a frame
Definition: netdev.h:237
netdev::context
void * context
ptr to network stack context
Definition: netdev.h:305
NETDEV_EVENT_RX_STARTED
@ NETDEV_EVENT_RX_STARTED
started to receive a frame
Definition: netdev.h:236
iolist
iolist structure definition
Definition: iolist.h:39
netdev_trigger_event_isr
static void netdev_trigger_event_isr(netdev_t *netdev)
Informs netdev there was an interrupt request from the network device.
Definition: netdev.h:528
NETDEV_EVENT_TX_STARTED
@ NETDEV_EVENT_TX_STARTED
started to transfer a frame
Definition: netdev.h:238
netdev
Structure to hold driver state.
Definition: netdev.h:302
netdev_radio_rx_info::lqi
uint8_t lqi
LQI of a received frame.
Definition: netdev.h:260
NETDEV_EVENT_RX_TIMEOUT
@ NETDEV_EVENT_RX_TIMEOUT
timeout when receiving
Definition: netdev.h:246
NETDEV_EVENT_TX_MEDIUM_BUSY
@ NETDEV_EVENT_TX_MEDIUM_BUSY
couldn't transfer frame
Definition: netdev.h:242
NETDEV_EVENT_ISR
@ NETDEV_EVENT_ISR
driver needs it's ISR handled
Definition: netdev.h:235
NETDEV_EVENT_CRC_ERROR
@ NETDEV_EVENT_CRC_ERROR
wrong CRC
Definition: netdev.h:247
netdev_driver::init
int(* init)(netdev_t *dev)
the driver's initialization function
Definition: netdev.h:409
NETDEV_EVENT_LINK_UP
@ NETDEV_EVENT_LINK_UP
link established
Definition: netdev.h:243
netdev_set_notsup
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:510
CONFIG_L2FILTER_LISTSIZE
#define CONFIG_L2FILTER_LISTSIZE
Number of slots in each filter list (filter entries per device)
Definition: l2filter.h:59
netdev_radio_rx_info
Received frame status information for most radios.
Definition: netdev.h:258
l2filter.h
Link layer address filter interface definition.
NETDEV_EVENT_TX_COMPLETE
@ NETDEV_EVENT_TX_COMPLETE
transfer frame complete
Definition: netdev.h:239
netdev_driver::get
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:450
errno.h
NETDEV_EVENT_TX_COMPLETE_DATA_PENDING
@ NETDEV_EVENT_TX_COMPLETE_DATA_PENDING
transfer frame complete and data pending flag
Definition: netdev.h:240