source: mainline/uspace/lib/net/generic/generic.c@ 5fe7692

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5fe7692 was ffa2c8ef, checked in by Martin Decky <martin@…>, 14 years ago

do not intermix low-level IPC methods with async framework methods

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