Blame view

RIOT/sys/include/net/gnrc/netif.h 3.82 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  /*
   * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    net_gnrc_netif    Network interfaces
   * @ingroup     net_gnrc
   * @brief       Abstraction layer for GNRC's network interfaces
   *
   * Network interfaces in the context of GNRC are threads for protocols that are
   * below the network layer.
   *
   * @{
   *
   * @file
   * @brief   Definitions for GNRC's network interfaces
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   * @author  Oliver Hahm <oliver.hahm@inria.fr>
   */
  #ifndef NET_GNRC_NETIF_H
  #define NET_GNRC_NETIF_H
  
  #include <stdlib.h>
  #include <stdbool.h>
  #include "kernel_types.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Maximum number of network interfaces
   */
  #ifndef GNRC_NETIF_NUMOF
  #define GNRC_NETIF_NUMOF    (1)
  #endif
  
  /**
   * @brief   The add/remove operation to set network layer protocol
   *          specific options for an interface.
   *
   * @param[in] pid   The PID to the new interface.
   */
  typedef void (*gnrc_netif_op_t)(kernel_pid_t pid);
  
  /**
   * @brief   The add and remove handlers to set network layer protocol
   *          specific options for an interface.
   *
   * @details If you implement a pair, please add it to the list in gnrc_netif.c
   *          statically.
   */
  typedef struct {
      gnrc_netif_op_t add;    /**< The add operation */
      gnrc_netif_op_t remove; /**< The remove operation */
  } gnrc_netif_handler_t;
  
  /**
   * @brief   Initializes module.
   */
  void gnrc_netif_init(void);
  
  /**
   * @brief   Adds a thread as interface.
   *
   * @param[in] pid   PID of the added thread.
   *
   * @return  0, on success,
   * @return  -ENOMEM, if maximum number of interfaces has been exceeded.
   */
  int gnrc_netif_add(kernel_pid_t pid);
  
  /**
   * @brief   Removes a thread as interface.
   *
   * @param[in] pid   PID of the removed thread.
   */
  void gnrc_netif_remove(kernel_pid_t pid);
  
  /**
   * @brief   Get all active interfaces.
   *
   * @param[out] netifs   List of all active interfaces. There is no order ensured.
   *                      It must at least fit @ref GNRC_NETIF_NUMOF elements.
   *
   * @return  The number of active interfaces.
   */
  size_t gnrc_netif_get(kernel_pid_t *netifs);
  
  /**
   * @brief   Check if an interface exist.
   *
   * @param[in] pid   The PID to be checked.
   *
   * @return  True, if an interface @p pid exists.
   * @return  False, otherwise
   */
  bool gnrc_netif_exist(kernel_pid_t pid);
  
  /**
   * @brief   Converts a hardware address to a human readable string.
   *
   * @details The format will be like `xx:xx:xx:xx` where `xx` are the bytes
   *          of @p addr in hexadecimal representation.
   *
   * @pre @p out_len >= 3 * @p addr_len
   *
   * @param[out] out      A string to store the output in.
   * @param[out] out_len  Length of @p out. Must be at least
   *                      3 * @p addr_len long.
   * @param[in] addr      A hardware address.
   * @param[in] addr_len  Length of @p addr.
   *
   * @return  Copy of @p out on success.
   * @return  NULL, if @p out_len < 3 * @p addr_len.
   */
  char *gnrc_netif_addr_to_str(char *out, size_t out_len, const uint8_t *addr,
                               size_t addr_len);
  
  /**
   * @brief   Parses a string of colon-separated hexadecimals to a hardware
   *          address.
   *
   * @details The input format must be like `xx:xx:xx:xx` where `xx` will be the
   *          bytes of @p addr in hexadecimal representation.
   *
   * @param[out] out      The resulting hardware address.
   * @param[out] out_len  Length of @p out.
   * @param[in] str       A string of colon-separated hexadecimals.
   *
   * @return  Actual length of @p out on success.
   * @return  0, on failure.
   */
  size_t gnrc_netif_addr_from_str(uint8_t *out, size_t out_len, const char *str);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* NET_GNRC_NETIF_H */
  /** @} */