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 
199 #include "iolist.h"
200 #include "net/netopt.h"
201 
202 #ifdef MODULE_NETSTATS_L2
203 #include "net/netstats.h"
204 #endif
205 #ifdef MODULE_L2FILTER
206 #include "net/l2filter.h"
207 #endif
208 
209 enum {
210  NETDEV_TYPE_UNKNOWN,
211  NETDEV_TYPE_RAW,
212  NETDEV_TYPE_ETHERNET,
213  NETDEV_TYPE_IEEE802154,
214  NETDEV_TYPE_BLE,
215  NETDEV_TYPE_CC110X,
216  NETDEV_TYPE_LORA,
217  NETDEV_TYPE_NRFMIN,
218  NETDEV_TYPE_SLIP,
219 };
220 
225 typedef enum {
241  /* expand this list if needed */
243 
250  int16_t rssi;
251  uint8_t lqi;
252 };
253 
257 typedef struct netdev netdev_t;
258 
264 typedef void (*netdev_event_cb_t)(netdev_t *dev, netdev_event_t event);
265 
275 struct netdev {
276  const struct netdev_driver *driver;
278  void* context;
279 #ifdef MODULE_NETDEV_LAYER
280  netdev_t *lower;
281 #endif
282 #ifdef MODULE_NETSTATS_L2
283  netstats_t stats;
284 #endif
285 #ifdef MODULE_L2FILTER
286  l2filter_t filter[L2FILTER_LISTSIZE];
287 #endif
288 };
289 
296 typedef struct netdev_driver {
307  int (*send)(netdev_t *dev, const iolist_t *iolist);
308 
332  int (*recv)(netdev_t *dev, void *buf, size_t len, void *info);
333 
341  int (*init)(netdev_t *dev);
342 
359  void (*isr)(netdev_t *dev);
360 
374  int (*get)(netdev_t *dev, netopt_t opt,
375  void *value, size_t max_len);
376 
390  int (*set)(netdev_t *dev, netopt_t opt,
391  const void *value, size_t value_len);
393 
394 #ifdef __cplusplus
395 }
396 #endif
397 
398 #endif /* NET_NETDEV_H */
399 
Definition of net statistics.
Structure to hold driver interface -> function mapping.
Definition: netdev.h:296
iolist scatter / gather IO
driver needs it&#39;s ISR handled
Definition: netdev.h:226
#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
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:225
event structure
Definition: event.h:127
Global statistics struct.
started to transfer a packet
Definition: netdev.h:229
Received packet status information for most radios.
Definition: netdev.h:249
void * context
ptr to network stack context
Definition: netdev.h:278
started to receive a packet
Definition: netdev.h:227
ACK requested but not received.
Definition: netdev.h:232
Filter list entries.
Definition: l2filter.h:64
netopt_t
Global list of configuration options available throughout the network stack, e.g. ...
Definition: netopt.h:42
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition: netdev.h:264
channel activity detection done
Definition: netdev.h:240
Structure to hold driver state.
Definition: netdev.h:275
link established
Definition: netdev.h:234
timeout when sending
Definition: netdev.h:236
netdev_event_cb_t event_callback
callback for device events
Definition: netdev.h:277
Definition of global configuration options.
transfer packet complete and data pending flag
Definition: netdev.h:231
couldn&#39;t transfer packet
Definition: netdev.h:233
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:228
uint8_t lqi
LQI of a received packet.
Definition: netdev.h:251
iolist structure definition
Definition: iolist.h:37
transfer packet complete
Definition: netdev.h:230
const struct netdev_driver * driver
ptr to that driver&#39;s interface.
Definition: netdev.h:276
timeout when receiving
Definition: netdev.h:237
int16_t rssi
RSSI of a received packet in dBm.
Definition: netdev.h:250