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 
203 #ifdef MODULE_L2FILTER
204 #include "net/l2filter.h"
205 #endif
206 
214 enum {
215  NETDEV_TYPE_UNKNOWN,
216  NETDEV_TYPE_TEST,
217  NETDEV_TYPE_RAW,
218  NETDEV_TYPE_ETHERNET,
219  NETDEV_TYPE_IEEE802154,
220  NETDEV_TYPE_BLE,
221  NETDEV_TYPE_CC110X,
222  NETDEV_TYPE_LORA,
223  NETDEV_TYPE_NRFMIN,
224  NETDEV_TYPE_SLIP,
225  NETDEV_TYPE_ESP_NOW,
226 };
233 typedef enum {
249  /* expand this list if needed */
251 
258  int16_t rssi;
259  uint8_t lqi;
260 };
261 
265 typedef struct netdev netdev_t;
266 
272 typedef void (*netdev_event_cb_t)(netdev_t *dev, netdev_event_t event);
273 
283 struct netdev {
284  const struct netdev_driver *driver;
286  void* context;
287 #ifdef MODULE_NETDEV_LAYER
288  netdev_t *lower;
289 #endif
290 #ifdef MODULE_L2FILTER
291  l2filter_t filter[L2FILTER_LISTSIZE];
292 #endif
293 };
294 
301 typedef struct netdev_driver {
317  int (*send)(netdev_t *dev, const iolist_t *iolist);
318 
354  int (*recv)(netdev_t *dev, void *buf, size_t len, void *info);
355 
366  int (*init)(netdev_t *dev);
367 
384  void (*isr)(netdev_t *dev);
385 
404  int (*get)(netdev_t *dev, netopt_t opt,
405  void *value, size_t max_len);
406 
428  int (*set)(netdev_t *dev, netopt_t opt,
429  const void *value, size_t value_len);
431 
442 static inline int netdev_get_notsup(netdev_t *dev, netopt_t opt,
443  void *value, size_t max_len)
444 {
445  (void)dev;
446  (void)opt;
447  (void)value;
448  (void)max_len;
449  return -ENOTSUP;
450 }
451 
462 static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
463  const void *value, size_t value_len)
464 {
465  (void)dev;
466  (void)opt;
467  (void)value;
468  (void)value_len;
469  return -ENOTSUP;
470 }
471 
472 
473 #ifdef __cplusplus
474 }
475 #endif
476 
477 #endif /* NET_NETDEV_H */
478 
Structure to hold driver interface -> function mapping.
Definition: netdev.h:301
iolist scatter / gather IO
driver needs it&#39;s ISR handled
Definition: netdev.h:234
#define L2FILTER_LISTSIZE
Number of slots in each filter list (filter entries per device)
Definition: l2filter.h:54
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:442
Link layer address filter interface definition.
netdev_event_t
Possible event types that are send from the device driver to the upper layer.
Definition: netdev.h:233
event structure
Definition: event.h:139
started to transfer a packet
Definition: netdev.h:237
Received packet status information for most radios.
Definition: netdev.h:257
void * context
ptr to network stack context
Definition: netdev.h:286
started to receive a packet
Definition: netdev.h:235
ACK requested but not received.
Definition: netdev.h:240
Filter list entries.
Definition: l2filter.h:64
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:272
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
channel activity detection done
Definition: netdev.h:248
Structure to hold driver state.
Definition: netdev.h:283
link established
Definition: netdev.h:242
timeout when sending
Definition: netdev.h:244
netdev_event_cb_t event_callback
callback for device events
Definition: netdev.h:285
Definition of global configuration options.
transfer packet complete and data pending flag
Definition: netdev.h:239
couldn&#39;t transfer packet
Definition: netdev.h:241
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
finished receiving a packet
Definition: netdev.h:236
uint8_t lqi
LQI of a received packet.
Definition: netdev.h:259
iolist structure definition
Definition: iolist.h:39
transfer packet complete
Definition: netdev.h:238
const struct netdev_driver * driver
ptr to that driver&#39;s interface.
Definition: netdev.h:284
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:462
timeout when receiving
Definition: netdev.h:245
int16_t rssi
RSSI of a received packet in dBm.
Definition: netdev.h:258