source: mainline/uspace/lib/net/generic/generic.c@ a676574

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a676574 was 61bfc370, checked in by Martin Decky <martin@…>, 14 years ago
  • make measured_string and other network-related data types binary-safe
  • fix several network-related routines binary-safe (replace clearly suspicious use of str_lcmp() with bcmp())
  • rename spawn() to net_spawn()
  • Property mode set to 100644
File size: 8.1 KB
RevLine 
[514ee46]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
[b01f878]29/** @addtogroup libnet
[514ee46]30 * @{
31 */
32
33/** @file
34 * Generic communication interfaces for networking.
35 */
36
37#include <generic.h>
38
39#include <async.h>
40#include <ipc/ipc.h>
41#include <ipc/services.h>
42
43#include <net/device.h>
44#include <adt/measured_strings.h>
45#include <net/packet.h>
46
47/** Notify the module about the device state change.
48 *
49 * @param[in] phone The service module phone.
50 * @param[in] message The service specific message.
51 * @param[in] device_id The device identifier.
52 * @param[in] state The new device state.
53 * @param[in] target The target module service.
54 * @return EOK on success.
55 *
56 */
57int
58generic_device_state_msg_remote(int phone, int message, device_id_t device_id,
59 int state, services_t target)
60{
[96b02eb9]61 async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
62 (sysarg_t) state, target);
[514ee46]63
64 return EOK;
65}
66
67/** Notify a module about the device.
68 *
69 * @param[in] phone The service module phone.
70 * @param[in] message The service specific message.
71 * @param[in] device_id The device identifier.
72 * @param[in] arg2 The second argument of the message.
73 * @param[in] service The device module service.
74 * @return EOK on success.
75 * @return Other error codes as defined for the specific service
76 * message.
77 *
78 */
79int
80generic_device_req_remote(int phone, int message, device_id_t device_id,
81 int arg2, services_t service)
82{
[96b02eb9]83 return (int) async_req_3_0(phone, (sysarg_t) message,
84 (sysarg_t) device_id, (sysarg_t) arg2, (sysarg_t) service);
[514ee46]85}
86
87/** Returns the address.
88 *
89 * @param[in] phone The service module phone.
90 * @param[in] message The service specific message.
91 * @param[in] device_id The device identifier.
92 * @param[out] address The desired address.
93 * @param[out] data The address data container.
[1bfd3d3]94 * @return EOK on success.
95 * @return EBADMEM if the address parameter and/or the data
[514ee46]96 * parameter is NULL.
[1bfd3d3]97 * @return Other error codes as defined for the specific service
[514ee46]98 * message.
99 */
100int
101generic_get_addr_req(int phone, int message, device_id_t device_id,
[854151c]102 measured_string_t **address, uint8_t **data)
[514ee46]103{
104 aid_t message_id;
[96b02eb9]105 sysarg_t result;
[514ee46]106 int string;
107
108 if (!address || !data)
109 return EBADMEM;
110
111 // request the address
[96b02eb9]112 message_id = async_send_1(phone, (sysarg_t) message,
113 (sysarg_t) device_id, NULL);
[61bfc370]114 string = measured_strings_return(phone, address, data, 1);
[514ee46]115 async_wait_for(message_id, &result);
116
117 // if not successful
118 if ((string == EOK) && (result != EOK)) {
119 // clear the data
120 free(*address);
121 free(*data);
122 }
123
124 return (int) result;
125}
126
127/** Return the device packet dimension for sending.
128 *
129 * @param[in] phone The service module phone.
130 * @param[in] message The service specific message.
131 * @param[in] device_id The device identifier.
132 * @param[out] packet_dimension The packet dimension.
133 * @return EOK on success.
134 * @return EBADMEM if the packet_dimension parameter is NULL.
135 * @return Other error codes as defined for the specific service
136 * message.
137 */
138int
139generic_packet_size_req_remote(int phone, int message, device_id_t device_id,
[f772bc55]140 packet_dimension_t *packet_dimension)
[514ee46]141{
142 if (!packet_dimension)
143 return EBADMEM;
144
[96b02eb9]145 sysarg_t addr_len;
146 sysarg_t prefix;
147 sysarg_t content;
148 sysarg_t suffix;
[514ee46]149
[96b02eb9]150 sysarg_t result = async_req_1_4(phone, (sysarg_t) message,
151 (sysarg_t) device_id, &addr_len, &prefix, &content, &suffix);
[514ee46]152
153 packet_dimension->prefix = (size_t) prefix;
154 packet_dimension->content = (size_t) content;
155 packet_dimension->suffix = (size_t) suffix;
156 packet_dimension->addr_len = (size_t) addr_len;
157
158 return (int) result;
159}
160
161/** Pass the packet queue to the module.
162 *
163 * @param[in] phone The service module phone.
164 * @param[in] message The service specific message.
165 * @param[in] device_id The device identifier.
166 * @param[in] packet_id The received packet or the received packet queue
167 * identifier.
168 * @param[in] target The target module service.
169 * @param[in] error The error module service.
170 * @return EOK on success.
171 */
172int
173generic_received_msg_remote(int phone, int message, device_id_t device_id,
174 packet_id_t packet_id, services_t target, services_t error)
175{
176 if (error) {
[96b02eb9]177 async_msg_4(phone, (sysarg_t) message, (sysarg_t) device_id,
178 (sysarg_t) packet_id, (sysarg_t) target, (sysarg_t) error);
[514ee46]179 } else {
[96b02eb9]180 async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
181 (sysarg_t) packet_id, (sysarg_t) target);
[514ee46]182 }
183
184 return EOK;
185}
186
187/** Send the packet queue.
188 *
189 * @param[in] phone The service module phone.
190 * @param[in] message The service specific message.
191 * @param[in] device_id The device identifier.
192 * @param[in] packet_id The packet or the packet queue identifier.
193 * @param[in] sender The sending module service.
194 * @param[in] error The error module service.
195 * @return EOK on success.
196 *
197 */
198int
199generic_send_msg_remote(int phone, int message, device_id_t device_id,
200 packet_id_t packet_id, services_t sender, services_t error)
201{
202 if (error) {
[96b02eb9]203 async_msg_4(phone, (sysarg_t) message, (sysarg_t) device_id,
204 (sysarg_t) packet_id, (sysarg_t) sender, (sysarg_t) error);
[514ee46]205 } else {
[96b02eb9]206 async_msg_3(phone, (sysarg_t) message, (sysarg_t) device_id,
207 (sysarg_t) packet_id, (sysarg_t) sender);
[514ee46]208 }
209
210 return EOK;
211}
212
213/** Translates the given strings.
214 *
215 * Allocates and returns the needed memory block as the data parameter.
216 *
217 * @param[in] phone The service module phone.
218 * @param[in] message The service specific message.
219 * @param[in] device_id The device identifier.
220 * @param[in] service The module service.
221 * @param[in] configuration The key strings.
222 * @param[in] count The number of configuration keys.
223 * @param[out] translation The translated values.
224 * @param[out] data The translation data container.
[1bfd3d3]225 * @return EOK on success.
226 * @return EINVAL if the configuration parameter is NULL.
227 * @return EINVAL if the count parameter is zero.
228 * @return EBADMEM if the translation or the data parameters are
[514ee46]229 * NULL.
[1bfd3d3]230 * @return Other error codes as defined for the specific service
[514ee46]231 * message.
232 */
233int
234generic_translate_req(int phone, int message, device_id_t device_id,
[4eca056]235 services_t service, measured_string_t *configuration, size_t count,
[61bfc370]236 measured_string_t **translation, uint8_t **data)
[514ee46]237{
238 aid_t message_id;
[96b02eb9]239 sysarg_t result;
[514ee46]240 int string;
241
242 if (!configuration || (count == 0))
243 return EINVAL;
244 if (!translation || !data)
245 return EBADMEM;
246
247 // request the translation
[96b02eb9]248 message_id = async_send_3(phone, (sysarg_t) message,
249 (sysarg_t) device_id, (sysarg_t) count, (sysarg_t) service, NULL);
[514ee46]250 measured_strings_send(phone, configuration, count);
251 string = measured_strings_return(phone, translation, data, count);
252 async_wait_for(message_id, &result);
253
254 // if not successful
255 if ((string == EOK) && (result != EOK)) {
256 // clear the data
257 free(*translation);
258 free(*data);
259 }
260
261 return (int) result;
262}
263
264/** @}
265 */
Note: See TracBrowser for help on using the repository browser.