netif.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef NET_GNRC_NETIF_H
25 #define NET_GNRC_NETIF_H
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 #include <stdbool.h>
30 
31 #include "kernel_types.h"
32 #include "msg.h"
33 #include "net/ipv6/addr.h"
34 #include "net/gnrc/netapi.h"
35 #include "net/gnrc/pkt.h"
36 #include "net/gnrc/netif/conf.h"
37 #ifdef MODULE_GNRC_LORAWAN
38 #include "net/gnrc/netif/lorawan.h"
39 #endif
40 #ifdef MODULE_GNRC_SIXLOWPAN
41 #include "net/gnrc/netif/6lo.h"
42 #endif
43 #if defined(MODULE_GNRC_NETIF_DEDUP) && (GNRC_NETIF_L2ADDR_MAXLEN > 0)
44 #include "net/gnrc/netif/dedup.h"
45 #endif
46 #include "net/gnrc/netif/flags.h"
47 #ifdef MODULE_GNRC_IPV6
48 #include "net/gnrc/netif/ipv6.h"
49 #endif
50 #ifdef MODULE_GNRC_MAC
51 #include "net/gnrc/netif/mac.h"
52 #endif
53 #include "net/ndp.h"
54 #include "net/netdev.h"
55 #include "net/netopt.h"
56 #ifdef MODULE_NETSTATS_L2
57 #include "net/netstats.h"
58 #endif
59 #include "rmutex.h"
60 #include "net/netif.h"
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
70 
74 typedef struct {
79 #ifdef MODULE_NETSTATS_L2
80  netstats_t stats;
81 #endif
82 #if defined(MODULE_GNRC_LORAWAN) || DOXYGEN
84 #endif
85 #if defined(MODULE_GNRC_IPV6) || DOXYGEN
87 #endif
88 #if defined(MODULE_GNRC_MAC) || DOXYGEN
90 #endif /* MODULE_GNRC_MAC */
91 
96  uint32_t flags;
97 #if (GNRC_NETIF_L2ADDR_MAXLEN > 0) || DOXYGEN
98 
104  uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN];
105 
111  uint8_t l2addr_len;
112 #if defined(MODULE_GNRC_NETIF_DEDUP) || DOXYGEN
113 
119 #endif
120 #endif
121 #if defined(MODULE_GNRC_SIXLOWPAN) || DOXYGEN
123 #endif
124  uint8_t cur_hl;
125  uint8_t device_type;
127 } gnrc_netif_t;
128 
148  void (*init)(gnrc_netif_t *netif);
149 
170  int (*send)(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
171 
188  gnrc_pktsnip_t *(*recv)(gnrc_netif_t *netif);
189 
204  int (*get)(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt);
205 
221  int (*set)(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt);
222 
233  void (*msg_handler)(gnrc_netif_t *netif, msg_t *msg);
234 };
235 
255 gnrc_netif_t *gnrc_netif_create(char *stack, int stacksize, char priority,
256  const char *name, netdev_t *dev,
257  const gnrc_netif_ops_t *ops);
258 
264 unsigned gnrc_netif_numof(void);
265 
275 
285 
306 static inline int gnrc_netif_ipv6_addrs_get(const gnrc_netif_t *netif,
307  ipv6_addr_t *addrs,
308  size_t max_len)
309 {
310  assert(netif != NULL);
311  assert(addrs != NULL);
312  assert(max_len >= sizeof(ipv6_addr_t));
313  return gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR, 0, addrs, max_len);
314 }
315 
337 static inline int gnrc_netif_ipv6_addr_add(const gnrc_netif_t *netif,
338  ipv6_addr_t *addr, unsigned pfx_len,
339  uint8_t flags)
340 {
341  assert(netif != NULL);
342  assert(addr != NULL);
343  assert((pfx_len > 0) && (pfx_len <= 128));
344  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_ADDR,
345  ((pfx_len << 8U) | flags), addr,
346  sizeof(ipv6_addr_t));
347 }
348 
362 static inline int gnrc_netif_ipv6_addr_remove(const gnrc_netif_t *netif,
363  ipv6_addr_t *addr)
364 {
365  assert(netif != NULL);
366  assert(addr != NULL);
368  0, addr, sizeof(ipv6_addr_t));
369 }
370 
391 static inline int gnrc_netif_ipv6_groups_get(const gnrc_netif_t *netif,
392  ipv6_addr_t *groups,
393  size_t max_len)
394 {
395  assert(netif != NULL);
396  assert(groups != NULL);
397  assert(max_len >= sizeof(ipv6_addr_t));
398  return gnrc_netapi_get(netif->pid, NETOPT_IPV6_GROUP, 0, groups, max_len);
399 }
400 
415 static inline int gnrc_netif_ipv6_group_join(const gnrc_netif_t *netif,
416  ipv6_addr_t *group)
417 {
418  assert(netif != NULL);
419  assert(group != NULL);
420  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_GROUP, 0, group,
421  sizeof(ipv6_addr_t));
422 }
423 
437 static inline int gnrc_netif_ipv6_group_leave(const gnrc_netif_t *netif,
438  ipv6_addr_t *group)
439 {
440  assert(netif != NULL);
441  assert(group != NULL);
442  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_GROUP_LEAVE, 0, group,
443  sizeof(ipv6_addr_t));
444 }
445 
454 
467 
480  const gnrc_netapi_opt_t *opt);
481 
498 char *gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
499 
518 size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out);
519 
520 #ifdef __cplusplus
521 }
522 #endif
523 
524 #endif /* NET_GNRC_NETIF_H */
525 
static int gnrc_netif_ipv6_group_leave(const gnrc_netif_t *netif, ipv6_addr_t *group)
Leaves an IPv6 multicast group on an interface (if IPv6 is supported)
Definition: netif.h:437
Types used by the kernel.
Definition of net statistics.
uint8_t cur_hl
Current hop-limit for out-going packets.
Definition: netif.h:124
void(* msg_handler)(gnrc_netif_t *netif, msg_t *msg)
Message handler for network interface.
Definition: netif.h:233
gnrc_netif_t * gnrc_netif_create(char *stack, int stacksize, char priority, const char *name, netdev_t *dev, const gnrc_netif_ops_t *ops)
Creates a network interface.
6Lo component of gnrc_netif_t
Definition: 6lo.h:30
Definitions for IPv6 addresses.
size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out)
Parses a string of colon-separated hexadecimals to a hardware address.
uint32_t flags
Flags for the interface.
Definition: netif.h:96
int(* send)(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
Send a packet over the network interface.
Definition: netif.h:170
General definitions for network packets and their helper functions.
int gnrc_netif_set_from_netdev(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt)
Default operation for gnrc_netif_ops_t::set()
netif_t netif
network interface descriptor
Definition: netif.h:75
Data structure to be send for setting (GNRC_NETAPI_MSG_TYPE_SET) and getting (GNRC_NETAPI_MSG_TYPE_GE...
Definition: netapi.h:100
6LoWPAN definitions for Network interface API
Network interface descriptor.
Definition: netif.h:57
Configuration macros for Network interface API.
static int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt, uint16_t context, const void *data, size_t data_len)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_SET messages and parsing the returned GNRC_NETAPI_...
Definition: netapi.h:255
Definitions low-level network driver interface.
Common MAC module definitions for Network interface API
Generic interface to communicate with GNRC modules.
const gnrc_netif_ops_t * ops
Operations of the network interface.
Definition: netif.h:76
Mutex structure.
Definition: rmutex.h:43
IPv6 definitions for Network interface API.
Global statistics struct.
Definition: netstats.h:43
uint8_t device_type
Device type.
Definition: netif.h:125
static int gnrc_netif_ipv6_addr_add(const gnrc_netif_t *netif, ipv6_addr_t *addr, unsigned pfx_len, uint8_t flags)
Adds an (unicast or anycast) IPv6 address to an interface (if IPv6 is supported)
Definition: netif.h:337
Common MAC module component of gnrc_netif_mac_t
Definition: mac.h:72
int gnrc_netif_get_from_netdev(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt)
Default operation for gnrc_netif_ops_t::get()
gnrc_netif_6lo_t sixlo
6Lo component
Definition: netif.h:122
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
static int gnrc_netif_ipv6_addr_remove(const gnrc_netif_t *netif, ipv6_addr_t *addr)
Removes a (unicast or anycast) IPv6 address from an interface (if IPv6 is supported) ...
Definition: netif.h:362
uint8_t l2addr_len
Length in bytes of gnrc_netif_t::l2addr.
Definition: netif.h:111
netdev_t * dev
Network device of the network interface.
Definition: netif.h:77
IPv6 component for gnrc_netif_t.
Definition: ipv6.h:78
static int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt, uint16_t context, void *data, size_t max_len)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_GET messages and parsing the returned GNRC_NETAPI_...
Definition: netapi.h:233
Common network interface API definitions.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Messaging API for inter process communication.
gnrc_netif_ipv6_t ipv6
IPv6 component.
Definition: netif.h:86
void(* init)(gnrc_netif_t *netif)
Initializes network interface beyond the default settings.
Definition: netif.h:148
rmutex_t mutex
Mutex of the interface.
Definition: netif.h:78
Structure to hold driver state.
Definition: netdev.h:289
Describes a message object which can be sent between threads.
Definition: msg.h:184
Recursive Mutex for thread synchronization.
(ipv6_addr_t) Removes an IPv6 address from an interface
Definition: netopt.h:154
void gnrc_netif_default_init(gnrc_netif_t *netif)
Default operation for gnrc_netif_ops_t::init()
(ipv6_addr_t[]) get IPv6 addresses of an interface as array of ipv6_addr_t or add an IPv6 address as ...
Definition: netopt.h:150
unsigned gnrc_netif_numof(void)
Get number of network interfaces actually allocated.
(ipv6_addr_t) Leave an IPv6 multicast group on an interface
Definition: netopt.h:182
static int gnrc_netif_ipv6_addrs_get(const gnrc_netif_t *netif, ipv6_addr_t *addrs, size_t max_len)
Gets the (unicast on anycast) IPv6 address of an interface (if IPv6 is supported) ...
Definition: netif.h:306
kernel_pid_t pid
PID of the network interface&#39;s thread.
Definition: netif.h:126
GNRC LoRaWAN interface descriptor.
Definition: lorawan.h:35
#define GNRC_NETIF_L2ADDR_MAXLEN
Maximum length of the link-layer address.
Definition: conf.h:132
Representation of a network interface.
Definition: netif.h:74
Definition of global configuration options.
static int gnrc_netif_ipv6_group_join(const gnrc_netif_t *netif, ipv6_addr_t *group)
Joins an IPv6 multicast group on an interface (if IPv6 is supported)
Definition: netif.h:415
gnrc_netif_t * gnrc_netif_get_by_pid(kernel_pid_t pid)
Get network interface by PID.
char * gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out)
Converts a hardware address to a human readable string.
LoRaWAN adaption for Network interface API.
gnrc_netif_mac_t mac
Common MAC module component
Definition: netif.h:89
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:107
Data type to represent an IPv6 address.
Definition: addr.h:74
gnrc_netif_lorawan_t lorawan
LoRaWAN component.
Definition: netif.h:83
Flag definitions for Network interface API.
IPv6 neighbor discovery message type definitions.
gnrc_netif_dedup_t last_pkt
Last received packet information.
Definition: netif.h:118
Structure to store information on the last broadcast packet received.
Definition: dedup.h:41
static int gnrc_netif_ipv6_groups_get(const gnrc_netif_t *netif, ipv6_addr_t *groups, size_t max_len)
Gets the IPv6 multicast groups an interface is joined to (if IPv6 is supported)
Definition: netif.h:391
(ipv6_addr_t) get IPv6 multicast groups of an interface as array of ipv6_addr_t or join an IPv6 multi...
Definition: netopt.h:178
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.