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 
273 typedef void (*netdev_event_cb_t)(netdev_t *dev, netdev_event_t event);
274 
279 typedef enum {
281  NETDEV_AT86RF215,
282  NETDEV_AT86RF2XX,
283  NETDEV_CC2538,
284  NETDEV_DOSE,
285  NETDEV_ENC28J60,
286  NETDEV_MRF24J40,
287  NETDEV_NRF802154,
288  /* add more if needed */
289 } netdev_type_t;
301 struct netdev {
302  const struct netdev_driver *driver;
304  void *context;
305 #ifdef MODULE_NETDEV_LAYER
306  netdev_t *lower;
307 #endif
308 #ifdef MODULE_L2FILTER
310 #endif
311 #ifdef MODULE_NETDEV_REGISTER
312  netdev_type_t type;
313  uint8_t index;
314 #endif
315 };
316 
325 static inline void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
326 {
327 #ifdef MODULE_NETDEV_REGISTER
328  dev->type = type;
329  dev->index = index;
330 #else
331  (void) dev;
332  (void) type;
333  (void) index;
334 #endif
335 }
336 
343 typedef struct netdev_driver {
359  int (*send)(netdev_t *dev, const iolist_t *iolist);
360 
396  int (*recv)(netdev_t *dev, void *buf, size_t len, void *info);
397 
408  int (*init)(netdev_t *dev);
409 
426  void (*isr)(netdev_t *dev);
427 
449  int (*get)(netdev_t *dev, netopt_t opt,
450  void *value, size_t max_len);
451 
475  int (*set)(netdev_t *dev, netopt_t opt,
476  const void *value, size_t value_len);
478 
489 static inline int netdev_get_notsup(netdev_t *dev, netopt_t opt,
490  void *value, size_t max_len)
491 {
492  (void)dev;
493  (void)opt;
494  (void)value;
495  (void)max_len;
496  return -ENOTSUP;
497 }
498 
509 static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
510  const void *value, size_t value_len)
511 {
512  (void)dev;
513  (void)opt;
514  (void)value;
515  (void)value_len;
516  return -ENOTSUP;
517 }
518 
528 {
529  if (netdev->event_callback) {
530  netdev->event_callback(netdev, NETDEV_EVENT_ISR);
531  }
532 }
533 #ifdef __cplusplus
534 }
535 #endif
536 
537 #endif /* NET_NETDEV_H */
538 
Structure to hold driver interface -> function mapping.
Definition: netdev.h:343
iolist scatter / gather IO
driver needs it&#39;s ISR handled
Definition: netdev.h:235
static ssize_t recv(int socket, void *buffer, size_t length, int flags)
Receive a message from a connected socket.
Definition: socket.h:380
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:489
Link layer address filter interface definition.
Will match any device type.
Definition: netdev.h:280
netdev_event_t
Possible event types that are send from the device driver to the upper layer.
Definition: netdev.h:234
event structure
Definition: event.h:142
#define CONFIG_L2FILTER_LISTSIZE
Number of slots in each filter list (filter entries per device)
Definition: l2filter.h:59
netdev_type_t
Driver types for netdev.
Definition: netdev.h:279
started to transfer a frame
Definition: netdev.h:238
Received frame status information for most radios.
Definition: netdev.h:258
void * context
ptr to network stack context
Definition: netdev.h:304
started to receive a frame
Definition: netdev.h:236
ACK requested but not received.
Definition: netdev.h:241
Filter list entries.
Definition: l2filter.h:70
static void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
Register a device with netdev.
Definition: netdev.h:325
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:50
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition: netdev.h:273
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
channel activity detection done
Definition: netdev.h:249
static void netdev_trigger_event_isr(netdev_t *netdev)
Informs netdev there was an interrupt request from the network device.
Definition: netdev.h:527
Structure to hold driver state.
Definition: netdev.h:301
link established
Definition: netdev.h:243
timeout when sending
Definition: netdev.h:245
netdev_event_cb_t event_callback
callback for device events
Definition: netdev.h:303
Definition of global configuration options.
transfer frame complete and data pending flag
Definition: netdev.h:240
couldn&#39;t transfer frame
Definition: netdev.h:242
struct netdev_driver netdev_driver_t
Structure to hold driver interface -> function mapping.
static ssize_t send(int socket, const void *buffer, size_t length, int flags)
Send a message on a socket.
Definition: socket.h:450
Common macros and compiler attributes/pragmas configuration.
finished receiving a frame
Definition: netdev.h:237
uint8_t lqi
LQI of a received frame.
Definition: netdev.h:260
iolist structure definition
Definition: iolist.h:39
transfer frame complete
Definition: netdev.h:239
const struct netdev_driver * driver
ptr to that driver&#39;s interface.
Definition: netdev.h:302
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:509
timeout when receiving
Definition: netdev.h:246
int16_t rssi
RSSI of a received frame in dBm.
Definition: netdev.h:259