[21580dd] | 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 |
|
---|
[849ed54] | 44 | #include <net_device.h>
|
---|
| 45 | #include <adt/measured_strings.h>
|
---|
[c69d327] | 46 | #include <net/packet.h>
|
---|
[21580dd] | 47 |
|
---|
[a64c64d] | 48 | /** @name Networking specific message arguments definitions
|
---|
[21580dd] | 49 | */
|
---|
| 50 | /*@{*/
|
---|
| 51 |
|
---|
[a64c64d] | 52 | /** @name First arguments
|
---|
| 53 | */
|
---|
| 54 | /*@{*/
|
---|
| 55 |
|
---|
| 56 | /** Returns the device identifier message argument.
|
---|
[21580dd] | 57 | * @param[in] call The message call structure.
|
---|
| 58 | */
|
---|
[e417b96] | 59 | #define IPC_GET_DEVICE(call) \
|
---|
| 60 | ({device_id_t device_id = (device_id_t) IPC_GET_ARG1(*call); device_id;})
|
---|
[21580dd] | 61 |
|
---|
[e417b96] | 62 | /*@;})*/
|
---|
[a64c64d] | 63 |
|
---|
| 64 | /** @name Second arguments
|
---|
| 65 | */
|
---|
[e417b96] | 66 | /*@({*/
|
---|
[a64c64d] | 67 |
|
---|
| 68 | /** Returns the packet identifier message argument.
|
---|
[21580dd] | 69 | * @param[in] call The message call structure.
|
---|
| 70 | */
|
---|
[e417b96] | 71 | #define IPC_GET_PACKET(call) \
|
---|
| 72 | ({packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call); packet_id;})
|
---|
[21580dd] | 73 |
|
---|
[a64c64d] | 74 | /** Returns the count message argument.
|
---|
[21580dd] | 75 | * @param[in] call The message call structure.
|
---|
| 76 | */
|
---|
[e417b96] | 77 | #define IPC_GET_COUNT(call) \
|
---|
| 78 | ({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
|
---|
[21580dd] | 79 |
|
---|
[a64c64d] | 80 | /** Returns the device state message argument.
|
---|
[21580dd] | 81 | * @param[in] call The message call structure.
|
---|
| 82 | */
|
---|
[e417b96] | 83 | #define IPC_GET_STATE(call) \
|
---|
| 84 | ({device_state_t device_state = (device_state_t) IPC_GET_ARG2(*call); device_state;})
|
---|
[21580dd] | 85 |
|
---|
[a64c64d] | 86 | /** Returns the maximum transmission unit message argument.
|
---|
[21580dd] | 87 | * @param[in] call The message call structure.
|
---|
| 88 | */
|
---|
[e417b96] | 89 | #define IPC_GET_MTU(call) \
|
---|
| 90 | ({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
|
---|
[21580dd] | 91 |
|
---|
[e417b96] | 92 | /*@;})*/
|
---|
[a64c64d] | 93 |
|
---|
| 94 | /** @name Third arguments
|
---|
| 95 | */
|
---|
[e417b96] | 96 | /*@({*/
|
---|
[a64c64d] | 97 |
|
---|
| 98 | /** Returns the device driver service message argument.
|
---|
[21580dd] | 99 | * @param[in] call The message call structure.
|
---|
| 100 | */
|
---|
[e417b96] | 101 | #define IPC_GET_SERVICE(call) \
|
---|
| 102 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
[21580dd] | 103 |
|
---|
[a64c64d] | 104 | /** Returns the target service message argument.
|
---|
[21580dd] | 105 | * @param[in] call The message call structure.
|
---|
| 106 | */
|
---|
[e417b96] | 107 | #define IPC_GET_TARGET(call) \
|
---|
| 108 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
[21580dd] | 109 |
|
---|
[a64c64d] | 110 | /** Returns the sender service message argument.
|
---|
[21580dd] | 111 | * @param[in] call The message call structure.
|
---|
| 112 | */
|
---|
[e417b96] | 113 | #define IPC_GET_SENDER(call) \
|
---|
| 114 | ({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
|
---|
[21580dd] | 115 |
|
---|
[e417b96] | 116 | /*@;})*/
|
---|
[a64c64d] | 117 |
|
---|
| 118 | /** @name Fourth arguments
|
---|
| 119 | */
|
---|
[e417b96] | 120 | /*@({*/
|
---|
[a64c64d] | 121 |
|
---|
| 122 | /** Returns the error service message argument.
|
---|
[21580dd] | 123 | * @param[in] call The message call structure.
|
---|
| 124 | */
|
---|
[e417b96] | 125 | #define IPC_GET_ERROR(call) \
|
---|
| 126 | ({services_t service = (services_t) IPC_GET_ARG4(*call); service;})
|
---|
[21580dd] | 127 |
|
---|
[e417b96] | 128 | /*@;})*/
|
---|
[a64c64d] | 129 |
|
---|
| 130 | /** @name Fifth arguments
|
---|
| 131 | */
|
---|
[e417b96] | 132 | /*@({*/
|
---|
[a64c64d] | 133 |
|
---|
| 134 | /** Returns the phone message argument.
|
---|
[21580dd] | 135 | * @param[in] call The message call structure.
|
---|
| 136 | */
|
---|
[e417b96] | 137 | #define IPC_GET_PHONE(call) \
|
---|
| 138 | ({int phone = (int) IPC_GET_ARG5(*call); phone;})
|
---|
[21580dd] | 139 |
|
---|
[a64c64d] | 140 | /*@}*/
|
---|
| 141 |
|
---|
| 142 | /** @name First answers
|
---|
| 143 | */
|
---|
| 144 | /*@{*/
|
---|
| 145 |
|
---|
[21580dd] | 146 | /** Sets the device identifier in the message answer.
|
---|
| 147 | * @param[out] answer The message answer structure.
|
---|
| 148 | */
|
---|
[e417b96] | 149 | #define IPC_SET_DEVICE(answer, value) \
|
---|
[3db8889] | 150 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
|
---|
[21580dd] | 151 |
|
---|
| 152 | /** Sets the minimum address length in the message answer.
|
---|
| 153 | * @param[out] answer The message answer structure.
|
---|
| 154 | */
|
---|
[e417b96] | 155 | #define IPC_SET_ADDR(answer, value) \
|
---|
[3db8889] | 156 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
|
---|
[21580dd] | 157 |
|
---|
[a64c64d] | 158 | /*@}*/
|
---|
| 159 |
|
---|
| 160 | /** @name Second answers
|
---|
| 161 | */
|
---|
| 162 | /*@{*/
|
---|
| 163 |
|
---|
[21580dd] | 164 | /** Sets the minimum prefix size in the message answer.
|
---|
| 165 | * @param[out] answer The message answer structure.
|
---|
| 166 | */
|
---|
[e417b96] | 167 | #define IPC_SET_PREFIX(answer, value) \
|
---|
[3db8889] | 168 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(*answer, argument);}
|
---|
[21580dd] | 169 |
|
---|
[a64c64d] | 170 | /*@}*/
|
---|
| 171 |
|
---|
| 172 | /** @name Third answers
|
---|
| 173 | */
|
---|
| 174 | /*@{*/
|
---|
| 175 |
|
---|
[21580dd] | 176 | /** Sets the maximum content size in the message answer.
|
---|
| 177 | * @param[out] answer The message answer structure.
|
---|
| 178 | */
|
---|
[e417b96] | 179 | #define IPC_SET_CONTENT(answer, value) \
|
---|
[3db8889] | 180 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG3(*answer, argument);}
|
---|
[21580dd] | 181 |
|
---|
[a64c64d] | 182 | /*@}*/
|
---|
| 183 |
|
---|
| 184 | /** @name Fourth answers
|
---|
| 185 | */
|
---|
| 186 | /*@{*/
|
---|
| 187 |
|
---|
[21580dd] | 188 | /** Sets the minimum suffix size in the message answer.
|
---|
| 189 | * @param[out] answer The message answer structure.
|
---|
| 190 | */
|
---|
[e417b96] | 191 | #define IPC_SET_SUFFIX(answer, value) \
|
---|
[3db8889] | 192 | {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG4(*answer, argument);}
|
---|
[21580dd] | 193 |
|
---|
| 194 | /*@}*/
|
---|
| 195 |
|
---|
[a64c64d] | 196 | /*@}*/
|
---|
| 197 |
|
---|
[14f1db0] | 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 | *
|
---|
[a64c64d] | 208 | */
|
---|
[14f1db0] | 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 |
|
---|
[a64c64d] | 215 | return EOK;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[14f1db0] | 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 | *
|
---|
[a64c64d] | 229 | */
|
---|
[14f1db0] | 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);
|
---|
[a64c64d] | 235 | }
|
---|
| 236 |
|
---|
[21580dd] | 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 | */
|
---|
[aadf01e] | 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 | }
|
---|
[a64c64d] | 255 |
|
---|
| 256 | // request the address
|
---|
[aadf01e] | 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 |
|
---|
[a64c64d] | 261 | // if not successful
|
---|
[aadf01e] | 262 | if((string == EOK) && (result != EOK)){
|
---|
[a64c64d] | 263 | // clear the data
|
---|
| 264 | free(*address);
|
---|
[aadf01e] | 265 | free(*data);
|
---|
| 266 | }
|
---|
| 267 | return (int) result;
|
---|
[21580dd] | 268 | }
|
---|
| 269 |
|
---|
[14f1db0] | 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 | *
|
---|
[21580dd] | 281 | */
|
---|
[14f1db0] | 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;
|
---|
[aadf01e] | 289 | ipcarg_t prefix;
|
---|
| 290 | ipcarg_t content;
|
---|
| 291 | ipcarg_t suffix;
|
---|
[14f1db0] | 292 |
|
---|
| 293 | ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message,
|
---|
| 294 | (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
|
---|
| 295 |
|
---|
[aadf01e] | 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;
|
---|
[14f1db0] | 300 |
|
---|
[aadf01e] | 301 | return (int) result;
|
---|
[21580dd] | 302 | }
|
---|
| 303 |
|
---|
[14f1db0] | 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 | *
|
---|
[21580dd] | 316 | */
|
---|
[14f1db0] | 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 |
|
---|
[21580dd] | 328 | return EOK;
|
---|
| 329 | }
|
---|
| 330 |
|
---|
[14f1db0] | 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 | *
|
---|
[21580dd] | 342 | */
|
---|
[14f1db0] | 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 |
|
---|
[21580dd] | 354 | return EOK;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
[a64c64d] | 357 | /** Translates the given strings.
|
---|
| 358 | * Allocates and returns the needed memory block as the data parameter.
|
---|
[21580dd] | 359 | * @param[in] phone The service module phone.
|
---|
| 360 | * @param[in] message The service specific message.
|
---|
| 361 | * @param[in] device_id The device identifier.
|
---|
[a64c64d] | 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.
|
---|
[21580dd] | 367 | * @returns EOK on success.
|
---|
[a64c64d] | 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.
|
---|
[21580dd] | 371 | * @returns Other error codes as defined for the specific service message.
|
---|
| 372 | */
|
---|
[a64c64d] | 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;
|
---|
[21580dd] | 399 | }
|
---|
| 400 |
|
---|
| 401 | #endif
|
---|
| 402 |
|
---|
| 403 | /** @}
|
---|
| 404 | */
|
---|