1 | /*
|
---|
2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup net
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file
|
---|
34 | * Networking common message definitions.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef __NET_MESSAGES_H__
|
---|
38 | #define __NET_MESSAGES_H__
|
---|
39 |
|
---|
40 | #include <async.h>
|
---|
41 | #include <ipc/ipc.h>
|
---|
42 | #include <ipc/services.h>
|
---|
43 |
|
---|
44 | #include <net_device.h>
|
---|
45 | #include <adt/measured_strings.h>
|
---|
46 | #include <net/packet.h>
|
---|
47 |
|
---|
48 | /** @name Networking specific message arguments definitions
|
---|
49 | */
|
---|
50 | /*@{*/
|
---|
51 |
|
---|
52 | /** @name First arguments
|
---|
53 | */
|
---|
54 | /*@{*/
|
---|
55 |
|
---|
56 | /** Returns the device identifier message argument.
|
---|
57 | * @param[in] call The message call structure.
|
---|
58 | */
|
---|
59 | #define IPC_GET_DEVICE(call) \
|
---|
60 | ({device_id_t device_id = (device_id_t) IPC_GET_ARG1(*call); device_id;})
|
---|
61 |
|
---|
62 | /*@;})*/
|
---|
63 |
|
---|
64 | /** @name Second arguments
|
---|
65 | */
|
---|
66 | /*@({*/
|
---|
67 |
|
---|
68 | /** Returns the packet identifier message argument.
|
---|
69 | * @param[in] call The message call structure.
|
---|
70 | */
|
---|
71 | #define IPC_GET_PACKET(call) \
|
---|
72 | ({packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call); packet_id;})
|
---|
73 |
|
---|
74 | /** Returns the count message argument.
|
---|
75 | * @param[in] call The message call structure.
|
---|
76 | */
|
---|
77 | #define IPC_GET_COUNT(call) \
|
---|
78 | ({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
|
---|
79 |
|
---|
80 | /** Returns the device state message argument.
|
---|
81 | * @param[in] call The message call structure.
|
---|
82 | */
|
---|
83 | #define IPC_GET_STATE(call) \
|
---|
84 | ({device_state_t device_state = (device_state_t) IPC_GET_ARG2(*call); device_state;})
|
---|
85 |
|
---|
86 | /** Returns the maximum transmission unit message argument.
|
---|
87 | * @param[in] call The message call structure.
|
---|
88 | */
|
---|
89 | #define IPC_GET_MTU(call) \
|
---|
90 | ({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
|
---|
91 |
|
---|
92 | /*@;})*/
|
---|
93 |
|
---|
94 | /** @name Third arguments
|
---|
95 | */
|
---|
96 | /*@({*/
|
---|
97 |
|
---|
98 | /** Returns the device driver service message argument.
|
---|
99 | * @param[in] call The message call structure.
|
---|
100 | */
|
---|
101 | #define IPC_GET_SERVICE(call) \
|
---|
102 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
103 |
|
---|
104 | /** Returns the target service message argument.
|
---|
105 | * @param[in] call The message call structure.
|
---|
106 | */
|
---|
107 | #define IPC_GET_TARGET(call) \
|
---|
108 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
109 |
|
---|
110 | /** Returns the sender service message argument.
|
---|
111 | * @param[in] call The message call structure.
|
---|
112 | */
|
---|
113 | #define IPC_GET_SENDER(call) \
|
---|
114 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
115 |
|
---|
116 | /*@;})*/
|
---|
117 |
|
---|
118 | /** @name Fourth arguments
|
---|
119 | */
|
---|
120 | /*@({*/
|
---|
121 |
|
---|
122 | /** Returns the error service message argument.
|
---|
123 | * @param[in] call The message call structure.
|
---|
124 | */
|
---|
125 | #define IPC_GET_ERROR(call) \
|
---|
126 | ({services_t service = (services_t) IPC_GET_ARG4(*call); service;})
|
---|
127 |
|
---|
128 | /*@;})*/
|
---|
129 |
|
---|
130 | /** @name Fifth arguments
|
---|
131 | */
|
---|
132 | /*@({*/
|
---|
133 |
|
---|
134 | /** Returns the phone message argument.
|
---|
135 | * @param[in] call The message call structure.
|
---|
136 | */
|
---|
137 | #define IPC_GET_PHONE(call) \
|
---|
138 | ({int phone = (int) IPC_GET_ARG5(*call); phone;})
|
---|
139 |
|
---|
140 | /*@}*/
|
---|
141 |
|
---|
142 | /** @name First answers
|
---|
143 | */
|
---|
144 | /*@{*/
|
---|
145 |
|
---|
146 | /** Sets the device identifier in the message answer.
|
---|
147 | * @param[out] answer The message answer structure.
|
---|
148 | */
|
---|
149 | #define IPC_SET_DEVICE(answer, value) \
|
---|
150 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
|
---|
151 |
|
---|
152 | /** Sets the minimum address length in the message answer.
|
---|
153 | * @param[out] answer The message answer structure.
|
---|
154 | */
|
---|
155 | #define IPC_SET_ADDR(answer, value) \
|
---|
156 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
|
---|
157 |
|
---|
158 | /*@}*/
|
---|
159 |
|
---|
160 | /** @name Second answers
|
---|
161 | */
|
---|
162 | /*@{*/
|
---|
163 |
|
---|
164 | /** Sets the minimum prefix size in the message answer.
|
---|
165 | * @param[out] answer The message answer structure.
|
---|
166 | */
|
---|
167 | #define IPC_SET_PREFIX(answer, value) \
|
---|
168 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(*answer, argument);}
|
---|
169 |
|
---|
170 | /*@}*/
|
---|
171 |
|
---|
172 | /** @name Third answers
|
---|
173 | */
|
---|
174 | /*@{*/
|
---|
175 |
|
---|
176 | /** Sets the maximum content size in the message answer.
|
---|
177 | * @param[out] answer The message answer structure.
|
---|
178 | */
|
---|
179 | #define IPC_SET_CONTENT(answer, value) \
|
---|
180 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG3(*answer, argument);}
|
---|
181 |
|
---|
182 | /*@}*/
|
---|
183 |
|
---|
184 | /** @name Fourth answers
|
---|
185 | */
|
---|
186 | /*@{*/
|
---|
187 |
|
---|
188 | /** Sets the minimum suffix size in the message answer.
|
---|
189 | * @param[out] answer The message answer structure.
|
---|
190 | */
|
---|
191 | #define IPC_SET_SUFFIX(answer, value) \
|
---|
192 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG4(*answer, argument);}
|
---|
193 |
|
---|
194 | /*@}*/
|
---|
195 |
|
---|
196 | /*@}*/
|
---|
197 |
|
---|
198 | /** Notify the module about the device state change.
|
---|
199 | *
|
---|
200 | * @param[in] phone The service module phone.
|
---|
201 | * @param[in] message The service specific message.
|
---|
202 | * @param[in] device_id The device identifier.
|
---|
203 | * @param[in] state The new device state.
|
---|
204 | * @param[in] target The target module service.
|
---|
205 | *
|
---|
206 | * @return EOK on success.
|
---|
207 | *
|
---|
208 | */
|
---|
209 | static inline int generic_device_state_msg_remote(int phone, int message,
|
---|
210 | device_id_t device_id, int state, services_t target)
|
---|
211 | {
|
---|
212 | async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
213 | (ipcarg_t) state, target);
|
---|
214 |
|
---|
215 | return EOK;
|
---|
216 | }
|
---|
217 |
|
---|
218 | /** Notify a module about the device.
|
---|
219 | *
|
---|
220 | * @param[in] phone The service module phone.
|
---|
221 | * @param[in] message The service specific message.
|
---|
222 | * @param[in] device_id The device identifier.
|
---|
223 | * @param[in] arg2 The second argument of the message.
|
---|
224 | * @param[in] service The device module service.
|
---|
225 | *
|
---|
226 | * @return EOK on success.
|
---|
227 | * @return Other error codes as defined for the specific service message.
|
---|
228 | *
|
---|
229 | */
|
---|
230 | static inline int generic_device_req_remote(int phone, int message,
|
---|
231 | device_id_t device_id, int arg2, services_t service)
|
---|
232 | {
|
---|
233 | return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
234 | (ipcarg_t) arg2, (ipcarg_t) service);
|
---|
235 | }
|
---|
236 |
|
---|
237 | /** Returns the address.
|
---|
238 | * @param[in] phone The service module phone.
|
---|
239 | * @param[in] message The service specific message.
|
---|
240 | * @param[in] device_id The device identifier.
|
---|
241 | * @param[out] address The desired address.
|
---|
242 | * @param[out] data The address data container.
|
---|
243 | * @returns EOK on success.
|
---|
244 | * @returns EBADMEM if the address parameter and/or the data parameter is NULL.
|
---|
245 | * @returns Other error codes as defined for the specific service message.
|
---|
246 | */
|
---|
247 | static inline int generic_get_addr_req(int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data){
|
---|
248 | aid_t message_id;
|
---|
249 | ipcarg_t result;
|
---|
250 | int string;
|
---|
251 |
|
---|
252 | if(!(address && data)){
|
---|
253 | return EBADMEM;
|
---|
254 | }
|
---|
255 |
|
---|
256 | // request the address
|
---|
257 | message_id = async_send_1(phone, (ipcarg_t) message, (ipcarg_t) device_id, NULL);
|
---|
258 | string = measured_strings_return(phone, address, data, 1);
|
---|
259 | async_wait_for(message_id, &result);
|
---|
260 |
|
---|
261 | // if not successful
|
---|
262 | if((string == EOK) && (result != EOK)){
|
---|
263 | // clear the data
|
---|
264 | free(*address);
|
---|
265 | free(*data);
|
---|
266 | }
|
---|
267 | return (int) result;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /** Return the device packet dimension for sending.
|
---|
271 | *
|
---|
272 | * @param[in] phone The service module phone.
|
---|
273 | * @param[in] message The service specific message.
|
---|
274 | * @param[in] device_id The device identifier.
|
---|
275 | * @param[out] packet_dimension The packet dimension.
|
---|
276 | *
|
---|
277 | * @return EOK on success.
|
---|
278 | * @return EBADMEM if the packet_dimension parameter is NULL.
|
---|
279 | * @return Other error codes as defined for the specific service message.
|
---|
280 | *
|
---|
281 | */
|
---|
282 | static inline int generic_packet_size_req_remote(int phone, int message,
|
---|
283 | device_id_t device_id, packet_dimension_ref packet_dimension)
|
---|
284 | {
|
---|
285 | if (!packet_dimension)
|
---|
286 | return EBADMEM;
|
---|
287 |
|
---|
288 | ipcarg_t addr_len;
|
---|
289 | ipcarg_t prefix;
|
---|
290 | ipcarg_t content;
|
---|
291 | ipcarg_t suffix;
|
---|
292 |
|
---|
293 | ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message,
|
---|
294 | (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
|
---|
295 |
|
---|
296 | packet_dimension->prefix = (size_t) prefix;
|
---|
297 | packet_dimension->content = (size_t) content;
|
---|
298 | packet_dimension->suffix = (size_t) suffix;
|
---|
299 | packet_dimension->addr_len = (size_t) addr_len;
|
---|
300 |
|
---|
301 | return (int) result;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /** Pass the packet queue to the module.
|
---|
305 | *
|
---|
306 | * @param[in] phone The service module phone.
|
---|
307 | * @param[in] message The service specific message.
|
---|
308 | * @param[in] device_id The device identifier.
|
---|
309 | * @param[in] packet_id The received packet or the received packet queue
|
---|
310 | * identifier.
|
---|
311 | * @param[in] target The target module service.
|
---|
312 | * @param[in] error The error module service.
|
---|
313 | *
|
---|
314 | * @return EOK on success.
|
---|
315 | *
|
---|
316 | */
|
---|
317 | static inline int generic_received_msg_remote(int phone, int message,
|
---|
318 | device_id_t device_id, packet_id_t packet_id, services_t target,
|
---|
319 | services_t error)
|
---|
320 | {
|
---|
321 | if (error)
|
---|
322 | async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
323 | (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
|
---|
324 | else
|
---|
325 | async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
326 | (ipcarg_t) packet_id, (ipcarg_t) target);
|
---|
327 |
|
---|
328 | return EOK;
|
---|
329 | }
|
---|
330 |
|
---|
331 | /** Send the packet queue.
|
---|
332 | *
|
---|
333 | * @param[in] phone The service module phone.
|
---|
334 | * @param[in] message The service specific message.
|
---|
335 | * @param[in] device_id The device identifier.
|
---|
336 | * @param[in] packet_id The packet or the packet queue identifier.
|
---|
337 | * @param[in] sender The sending module service.
|
---|
338 | * @param[in] error The error module service.
|
---|
339 | *
|
---|
340 | * @return EOK on success.
|
---|
341 | *
|
---|
342 | */
|
---|
343 | static inline int generic_send_msg_remote(int phone, int message,
|
---|
344 | device_id_t device_id, packet_id_t packet_id, services_t sender,
|
---|
345 | services_t error)
|
---|
346 | {
|
---|
347 | if (error)
|
---|
348 | async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
349 | (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
|
---|
350 | else
|
---|
351 | async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
|
---|
352 | (ipcarg_t) packet_id, (ipcarg_t) sender);
|
---|
353 |
|
---|
354 | return EOK;
|
---|
355 | }
|
---|
356 |
|
---|
357 | /** Translates the given strings.
|
---|
358 | * Allocates and returns the needed memory block as the data parameter.
|
---|
359 | * @param[in] phone The service module phone.
|
---|
360 | * @param[in] message The service specific message.
|
---|
361 | * @param[in] device_id The device identifier.
|
---|
362 | * @param[in] service The module service.
|
---|
363 | * @param[in] configuration The key strings.
|
---|
364 | * @param[in] count The number of configuration keys.
|
---|
365 | * @param[out] translation The translated values.
|
---|
366 | * @param[out] data The translation data container.
|
---|
367 | * @returns EOK on success.
|
---|
368 | * @returns EINVAL if the configuration parameter is NULL.
|
---|
369 | * @returns EINVAL if the count parameter is zero (0).
|
---|
370 | * @returns EBADMEM if the translation or the data parameters are NULL.
|
---|
371 | * @returns Other error codes as defined for the specific service message.
|
---|
372 | */
|
---|
373 | static inline int generic_translate_req(int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data){
|
---|
374 | aid_t message_id;
|
---|
375 | ipcarg_t result;
|
---|
376 | int string;
|
---|
377 |
|
---|
378 | if(!(configuration && (count > 0))){
|
---|
379 | return EINVAL;
|
---|
380 | }
|
---|
381 | if(!(translation && data)){
|
---|
382 | return EBADMEM;
|
---|
383 | }
|
---|
384 |
|
---|
385 | // request the translation
|
---|
386 | message_id = async_send_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) count, (ipcarg_t) service, NULL);
|
---|
387 | measured_strings_send(phone, configuration, count);
|
---|
388 | string = measured_strings_return(phone, translation, data, count);
|
---|
389 | async_wait_for(message_id, &result);
|
---|
390 |
|
---|
391 | // if not successful
|
---|
392 | if((string == EOK) && (result != EOK)){
|
---|
393 | // clear the data
|
---|
394 | free(*translation);
|
---|
395 | free(*data);
|
---|
396 | }
|
---|
397 |
|
---|
398 | return (int) result;
|
---|
399 | }
|
---|
400 |
|
---|
401 | #endif
|
---|
402 |
|
---|
403 | /** @}
|
---|
404 | */
|
---|