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  */
24 #ifndef NET_GNRC_NETIF_H
25 #define NET_GNRC_NETIF_H
27 #include <stddef.h>
28 #include <stdint.h>
29 #include <stdbool.h>
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"
38 #include "net/gnrc/netif/6lo.h"
39 #endif
40 #include "net/gnrc/netif/flags.h"
41 #ifdef MODULE_GNRC_IPV6
42 #include "net/gnrc/netif/ipv6.h"
43 #endif
45 #include "net/gnrc/netif/mac.h"
46 #endif
47 #include "net/netdev.h"
48 #include "rmutex.h"
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
62 typedef struct {
66 #if defined(MODULE_GNRC_IPV6) || DOXYGEN
68 #endif
69 #if defined(MODULE_GNRC_MAC) || DOXYGEN
71 #endif /* MODULE_GNRC_MAC */
77  uint32_t flags;
85  uint8_t l2addr[GNRC_NETIF_L2ADDR_MAXLEN];
92  uint8_t l2addr_len;
93 #endif
96 #endif
97  uint8_t cur_hl;
98  uint8_t device_type;
100 } gnrc_netif_t;
118  void (*init)(gnrc_netif_t *netif);
140  int (*send)(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt);
158  gnrc_pktsnip_t *(*recv)(gnrc_netif_t *netif);
174  int (*get)(gnrc_netif_t *netif, gnrc_netapi_opt_t *opt);
191  int (*set)(gnrc_netif_t *netif, const gnrc_netapi_opt_t *opt);
203  void (*msg_handler)(gnrc_netif_t *netif, msg_t *msg);
204 };
225 gnrc_netif_t *gnrc_netif_create(char *stack, int stacksize, char priority,
226  const char *name, netdev_t *dev,
227  const gnrc_netif_ops_t *ops);
234 unsigned gnrc_netif_numof(void);
276 static inline int gnrc_netif_ipv6_addrs_get(const gnrc_netif_t *netif,
277  ipv6_addr_t *addrs,
278  size_t max_len)
279 {
280  assert(netif != NULL);
281  assert(addrs != NULL);
282  assert(max_len >= sizeof(ipv6_addr_t));
283  return gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR, 0, addrs, max_len);
284 }
307 static inline int gnrc_netif_ipv6_addr_add(const gnrc_netif_t *netif,
308  ipv6_addr_t *addr, unsigned pfx_len,
309  uint8_t flags)
310 {
311  assert(netif != NULL);
312  assert(addr != NULL);
313  assert((pfx_len > 0) && (pfx_len <= 128));
314  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_ADDR,
315  ((pfx_len << 8U) | flags), addr,
316  sizeof(ipv6_addr_t));
317 }
332 static inline int gnrc_netif_ipv6_addr_remove(const gnrc_netif_t *netif,
333  ipv6_addr_t *addr)
334 {
335  assert(netif != NULL);
336  assert(addr != NULL);
338  0, addr, sizeof(ipv6_addr_t));
339 }
361 static inline int gnrc_netif_ipv6_groups_get(const gnrc_netif_t *netif,
362  ipv6_addr_t *groups,
363  size_t max_len)
364 {
365  assert(netif != NULL);
366  assert(groups != NULL);
367  assert(max_len >= sizeof(ipv6_addr_t));
368  return gnrc_netapi_get(netif->pid, NETOPT_IPV6_GROUP, 0, groups, max_len);
369 }
385 static inline int gnrc_netif_ipv6_group_join(const gnrc_netif_t *netif,
386  ipv6_addr_t *group)
387 {
388  assert(netif != NULL);
389  assert(group != NULL);
390  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_GROUP, 0, group,
391  sizeof(ipv6_addr_t));
392 }
407 static inline int gnrc_netif_ipv6_group_leave(const gnrc_netif_t *netif,
408  ipv6_addr_t *group)
409 {
410  assert(netif != NULL);
411  assert(group != NULL);
412  return gnrc_netapi_set(netif->pid, NETOPT_IPV6_GROUP_LEAVE, 0, group,
413  sizeof(ipv6_addr_t));
414 }
441  const gnrc_netapi_opt_t *opt);
459 char *gnrc_netif_addr_to_str(const uint8_t *addr, size_t addr_len, char *out);
479 size_t gnrc_netif_addr_from_str(const char *str, uint8_t *out);
481 #ifdef __cplusplus
482 }
483 #endif
485 #endif /* NET_GNRC_NETIF_H */
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:407
Types used by the kernel.
Definitions low-level network driver interface.
uint8_t cur_hl
Current hop-limit for out-going packets.
Definition: netif.h:97
void(* msg_handler)(gnrc_netif_t *netif, msg_t *msg)
Message handler for network interface.
Definition: netif.h:203
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:77
int(* send)(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
Send a packet over the network interface.
Definition: netif.h:140
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
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()
Data structure to be send for setting (GNRC_NETAPI_MSG_TYPE_SET) and getting (GNRC_NETAPI_MSG_TYPE_GE...
Definition: netapi.h:99
6LoWPAN definitions for New network interface API
Configuration macros for New network interface API.
Common MAC module definitions for New network interface API
Generic interface to communicate with GNRC modules.
const gnrc_netif_ops_t * ops
Operations of the network interface.
Definition: netif.h:63
Mutex structure.
Definition: rmutex.h:36
IPv6 defintions for New network interface API.
uint8_t device_type
Device type.
Definition: netif.h:98
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:307
Common MAC module component of gnrc_netif_mac_t
Definition: netif/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:95
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:332
netdev_t * dev
Network device of the network interface.
Definition: netif.h:64
IPv6 component for gnrc_netif_t.
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_...
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
Messaging API for inter process communication.
Maximum length of the link-layer address.
Definition: netif/conf.h:113
gnrc_netif_ipv6_t ipv6
IPv6 component.
Definition: netif.h:67
void(* init)(gnrc_netif_t *netif)
Initializes network interface beyond the default settings.
Definition: netif.h:118
rmutex_t mutex
Mutex of the interface.
Definition: netif.h:65
Structure to hold driver state.
Definition: netdev.h:274
Describes a message object which can be sent between threads.
Definition: msg.h:184
Recursive Mutex for thread synchronization.
Removes an IPv6 address as ipv6_addr_t from an interface.
Definition: netopt.h:99
get IPv6 addresses of an interface as array of ipv6_addr_t or add an IPv6 address as ipv6_addr_t to a...
Definition: netopt.h:95
unsigned gnrc_netif_numof(void)
Get number of network interfaces actually allocated.
Leaves an IPv6 multicast group as ipv6_addr_t on an interface.
Definition: netopt.h:128
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 addresss of an interface (if IPv6 is supported) ...
Definition: netif.h:276
kernel_pid_t pid
PID of the network interface&#39;s thread.
Definition: netif.h:99
Representation of a network interface.
Definition: netif.h:62
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:385
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.
gnrc_netif_mac_t mac
Common MAC module component
Definition: netif.h:70
Type to represent parts (either headers or payload) of a packet, called snips.
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
Flag definitions for New network interface API.
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:361
get IPv6 multicast groups of an interface as array of ipv6_addr_t or join an IPv6 multicast group as ...
Definition: netopt.h:123
int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt, uint16_t context, void *data, size_t data_len)
Shortcut function for sending GNRC_NETAPI_MSG_TYPE_SET messages and parsing the returned GNRC_NETAPI_...
gnrc_netif_t * gnrc_netif_iter(const gnrc_netif_t *prev)
Iterate over all network interfaces.