fb11e647
vrobic
reseau statique a...
|
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* Copyright (C) 2015 Freie Universitรคt Berlin
*
* 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_netapi GNRC communication interface
* @ingroup net_gnrc
* @brief Generic interface for IPC communication between GNRC modules
*
* @details The idea of this interface is that it provides every network
* module with a basic set of commands to communicate with its
* neighboring modules. In this model every module runs in its own
* thread and communication is done using the @ref net_gnrc_netapi.
*
* @{
*
* @file
* @brief Generic interface to communicate with GNRC modules
*
* @defgroup net_gnrc_netapi_mbox Mailbox IPC extension
* @ingroup net_gnrc_netapi
* @brief @ref core_mbox "Mailbox IPC" extension for @ref net_gnrc_netapi
* @{
*
* @details The submodule `gnrc_netapi_mbox` provides an extension for
* @ref core_mbox "Mailbox IPC".
*
* To use, add the module `gnrc_netapi_mbox` to the `USEMODULE` macro in your
* application's Makefile:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* USEMODULE += gnrc_netapi_mbox
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
*
* @defgroup net_gnrc_netapi_callbacks Callback extension
* @ingroup net_gnrc_netapi
* @brief Callback extension for @ref net_gnrc_netapi
* @{
* @details The submodule `gnrc_netapi_callbacks` provides an extension for
* callbacks to run GNRC thread-less.
*
* To use, add the module `gnrc_netapi_callbacks` to the `USEMODULE` macro in
* your application's Makefile:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* USEMODULE += gnrc_netapi_callbacks
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @}
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef GNRC_NETAPI_H_
#define GNRC_NETAPI_H_
#include "thread.h"
#include "net/netopt.h"
#include "net/gnrc/nettype.h"
#include "net/gnrc/pkt.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief @ref core_msg type for passing a @ref net_gnrc_pkt up the network stack
*/
#define GNRC_NETAPI_MSG_TYPE_RCV (0x0201)
/**
* @brief @ref core_msg type for passing a @ref net_gnrc_pkt down the network stack
*/
#define GNRC_NETAPI_MSG_TYPE_SND (0x0202)
/**
* @brief @ref core_msg type for setting options of network modules
*/
#define GNRC_NETAPI_MSG_TYPE_SET (0x0203)
/**
* @brief @ref core_msg type for getting options from network modules
*/
#define GNRC_NETAPI_MSG_TYPE_GET (0x0204)
/**
* @brief @ref core_msg type for replying to get and set option messages
*/
#define GNRC_NETAPI_MSG_TYPE_ACK (0x0205)
/**
* @brief Data structure to be send for setting (@ref GNRC_NETAPI_MSG_TYPE_SET)
* and getting (@ref GNRC_NETAPI_MSG_TYPE_GET) options
*/
typedef struct {
netopt_t opt; /**< the option to get/set */
uint16_t context; /**< (optional) context for that option */
void *data; /**< data to set or buffer to read into */
uint16_t data_len; /**< size of the data / the buffer */
} gnrc_netapi_opt_t;
/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_SND messages
*
* @param[in] pid PID of the targeted network module
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return 1 if packet was successfully delivered
* @return -1 on error (invalid PID or no space in queue)
*/
int gnrc_netapi_send(kernel_pid_t pid, gnrc_pktsnip_t *pkt);
/**
* @brief Sends @p cmd to all subscribers to (@p type, @p demux_ctx).
*
* @param[in] type type of the targeted network module.
* @param[in] demux_ctx demultiplexing context for @p type.
* @param[in] cmd command for all subscribers
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
int gnrc_netapi_dispatch(gnrc_nettype_t type, uint32_t demux_ctx, uint16_t cmd,
gnrc_pktsnip_t *pkt);
/**
* @brief Sends a @ref GNRC_NETAPI_MSG_TYPE_SND command to all subscribers to
* (@p type, @p demux_ctx).
*
* @param[in] type type of the targeted network module.
* @param[in] demux_ctx demultiplexing context for @p type.
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
static inline int gnrc_netapi_dispatch_send(gnrc_nettype_t type, uint32_t demux_ctx,
gnrc_pktsnip_t *pkt)
{
return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_SND, pkt);
}
/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_RCV messages
*
* @param[in] pid PID of the targeted network module
* @param[in] pkt pointer into the packet buffer holding the received data
*
* @return 1 if packet was successfully delivered
* @return -1 on error (invalid PID or no space in queue)
*/
int gnrc_netapi_receive(kernel_pid_t pid, gnrc_pktsnip_t *pkt);
/**
* @brief Sends a @ref GNRC_NETAPI_MSG_TYPE_RCV command to all subscribers to
* (@p type, @p demux_ctx).
*
* @param[in] type type of the targeted network module.
* @param[in] demux_ctx demultiplexing context for @p type.
* @param[in] pkt pointer into the packet buffer holding the data to send
*
* @return Number of subscribers to (@p type, @p demux_ctx).
*/
static inline int gnrc_netapi_dispatch_receive(gnrc_nettype_t type, uint32_t demux_ctx,
gnrc_pktsnip_t *pkt)
{
return gnrc_netapi_dispatch(type, demux_ctx, GNRC_NETAPI_MSG_TYPE_RCV, pkt);
}
/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_GET messages and
* parsing the returned @ref GNRC_NETAPI_MSG_TYPE_ACK message
*
* @param[in] pid PID of the targeted network module
* @param[in] opt option to get
* @param[in] context (optional) context to the given option
* @param[in] data pointer to buffer for reading the option's value
* @param[in] max_len maximum number of bytes that fit into @p data
*
* @return value returned by the @ref GNRC_NETAPI_MSG_TYPE_ACK message i.e. the actual
* length of the resulting data on success, a negative errno on error. The
* actual error value is for the implementation to decide but should be
* sensible to indicate what went wrong.
*/
int gnrc_netapi_get(kernel_pid_t pid, netopt_t opt, uint16_t context,
void *data, size_t max_len);
/**
* @brief Shortcut function for sending @ref GNRC_NETAPI_MSG_TYPE_SET messages and
* parsing the returned @ref GNRC_NETAPI_MSG_TYPE_ACK message
*
* @param[in] pid PID of the targeted network module
* @param[in] opt option to set
* @param[in] context (optional) context to the given option
* @param[in] data data to set the given option to
* @param[in] data_len size of @p data
*
* @return value returned by the @ref GNRC_NETAPI_MSG_TYPE_ACK message i.e. 0 on
* success, a negative errno on error. The actual error value is for the
* implementation to decide but should be sensible to indicate what went
* wrong.
*/
int gnrc_netapi_set(kernel_pid_t pid, netopt_t opt, uint16_t context,
void *data, size_t data_len);
#ifdef __cplusplus
}
#endif
#endif /* GNRC_NETAPI_H_ */
/**
* @}^
*/
|