source: mainline/uspace/lib/net/generic/generic.c@ 609243f4

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

cherrypick general networking improvements from lp:~helenos-nicf/helenos/nicf (after sanitization)
remove obsolete networking drivers
this renders the networking non-functional for the time being

  • Property mode set to 100644
File size: 8.4 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] sess Service module session.
47 * @param[in] message Service specific message.
48 * @param[in] device_id Device identifier.
49 * @param[in] state New device state.
50 * @param[in] target Target module service.
51 *
52 * @return EOK on success.
53 *
54 */
55int generic_device_state_msg_remote(async_sess_t *sess, sysarg_t message,
56 nic_device_id_t device_id, sysarg_t state, services_t target)
57{
58 async_exch_t *exch = async_exchange_begin(sess);
59 async_msg_3(exch, message, (sysarg_t) device_id, state, target);
60 async_exchange_end(exch);
61
62 return EOK;
63}
64
65/** Notify a module about the device.
66 *
67 * @param[in] sess Service module session.
68 * @param[in] message Service specific message.
69 * @param[in] device_id Device identifier.
70 * @param[in] service Device module service.
71 *
72 * @return EOK on success.
73 * @return Other error codes as defined for the specific service
74 * message.
75 *
76 */
77int generic_device_req_remote(async_sess_t *sess, sysarg_t message,
78 nic_device_id_t device_id, services_t service)
79{
80 async_exch_t *exch = async_exchange_begin(sess);
81 int rc = async_req_2_0(exch, message, (sysarg_t) device_id,
82 (sysarg_t) service);
83 async_exchange_end(exch);
84
85 return rc;
86}
87
88/** Returns the address.
89 *
90 * @param[in] sess Service module session.
91 * @param[in] message Service specific message.
92 * @param[in] device_id Device identifier.
93 * @param[out] address Desired address.
94 * @param[out] data Address data container.
95 *
96 * @return EOK on success.
97 * @return EBADMEM if the address parameter and/or the data
98 * parameter is NULL.
99 * @return Other error codes as defined for the specific service
100 * message.
101 *
102 */
103int generic_get_addr_req(async_sess_t *sess, sysarg_t message,
104 nic_device_id_t device_id, uint8_t *address, size_t max_len)
105{
106 if (!address)
107 return EBADMEM;
108
109 /* Request the address */
110 async_exch_t *exch = async_exchange_begin(sess);
111 aid_t aid = async_send_1(exch, message, (sysarg_t) device_id,
112 NULL);
113 int rc = async_data_read_start(exch, address, max_len);
114 async_exchange_end(exch);
115
116 sysarg_t result;
117 async_wait_for(aid, &result);
118
119 if (rc != EOK)
120 return rc;
121
122 return (int) result;
123}
124
125/** Return the device packet dimension for sending.
126 *
127 * @param[in] sess Service module session.
128 * @param[in] message Service specific message.
129 * @param[in] device_id Device identifier.
130 * @param[out] packet_dimension Packet dimension.
131 *
132 * @return EOK on success.
133 * @return EBADMEM if the packet_dimension parameter is NULL.
134 * @return Other error codes as defined for the specific service
135 * message.
136 *
137 */
138int generic_packet_size_req_remote(async_sess_t *sess, sysarg_t message,
139 nic_device_id_t device_id, packet_dimension_t *packet_dimension)
140{
141 if (!packet_dimension)
142 return EBADMEM;
143
144 sysarg_t addr_len;
145 sysarg_t prefix;
146 sysarg_t content;
147 sysarg_t suffix;
148
149 async_exch_t *exch = async_exchange_begin(sess);
150 sysarg_t result = async_req_1_4(exch, message, (sysarg_t) device_id,
151 &addr_len, &prefix, &content, &suffix);
152 async_exchange_end(exch);
153
154 packet_dimension->prefix = (size_t) prefix;
155 packet_dimension->content = (size_t) content;
156 packet_dimension->suffix = (size_t) suffix;
157 packet_dimension->addr_len = (size_t) addr_len;
158
159 return (int) result;
160}
161
162/** Pass the packet queue to the module.
163 *
164 * @param[in] sess Service module session.
165 * @param[in] message Service specific message.
166 * @param[in] device_id Device identifier.
167 * @param[in] packet_id Received packet or the received packet queue
168 * identifier.
169 * @param[in] target Target module service.
170 * @param[in] error Error module service.
171 *
172 * @return EOK on success.
173 *
174 */
175int generic_received_msg_remote(async_sess_t *sess, sysarg_t message,
176 nic_device_id_t device_id, packet_id_t packet_id, services_t target,
177 services_t error)
178{
179 async_exch_t *exch = async_exchange_begin(sess);
180
181 if (error) {
182 async_msg_4(exch, message, (sysarg_t) device_id,
183 (sysarg_t) packet_id, (sysarg_t) target, (sysarg_t) error);
184 } else {
185 async_msg_3(exch, message, (sysarg_t) device_id,
186 (sysarg_t) packet_id, (sysarg_t) target);
187 }
188
189 async_exchange_end(exch);
190
191 return EOK;
192}
193
194/** Send the packet queue.
195 *
196 * @param[in] sess Service module session.
197 * @param[in] message Service specific message.
198 * @param[in] device_id Device identifier.
199 * @param[in] packet_id Packet or the packet queue identifier.
200 * @param[in] sender Sending module service.
201 * @param[in] error Error module service.
202 *
203 * @return EOK on success.
204 *
205 */
206int generic_send_msg_remote(async_sess_t *sess, sysarg_t message,
207 nic_device_id_t device_id, packet_id_t packet_id, services_t sender,
208 services_t error)
209{
210 async_exch_t *exch = async_exchange_begin(sess);
211
212 if (error) {
213 async_msg_4(exch, message, (sysarg_t) device_id,
214 (sysarg_t) packet_id, (sysarg_t) sender, (sysarg_t) error);
215 } else {
216 async_msg_3(exch, message, (sysarg_t) device_id,
217 (sysarg_t) packet_id, (sysarg_t) sender);
218 }
219
220 async_exchange_end(exch);
221
222 return EOK;
223}
224
225/** Translates the given strings.
226 *
227 * Allocates and returns the needed memory block as the data parameter.
228 *
229 * @param[in] sess Service module session.
230 * @param[in] message Service specific message.
231 * @param[in] device_id Device identifier.
232 * @param[in] service Module service.
233 * @param[in] configuration Key strings.
234 * @param[in] count Number of configuration keys.
235 * @param[out] translation Translated values.
236 * @param[out] data Translation data container.
237 *
238 * @return EOK on success.
239 * @return EINVAL if the configuration parameter is NULL.
240 * @return EINVAL if the count parameter is zero.
241 * @return EBADMEM if the translation or the data parameters are
242 * NULL.
243 * @return Other error codes as defined for the specific service
244 * message.
245 *
246 */
247int generic_translate_req(async_sess_t *sess, sysarg_t message,
248 nic_device_id_t device_id, services_t service,
249 measured_string_t *configuration, size_t count,
250 measured_string_t **translation, uint8_t **data)
251{
252 if ((!configuration) || (count == 0))
253 return EINVAL;
254
255 if ((!translation) || (!data))
256 return EBADMEM;
257
258 /* Request the translation */
259 async_exch_t *exch = async_exchange_begin(sess);
260 aid_t message_id = async_send_3(exch, message, (sysarg_t) device_id,
261 (sysarg_t) count, (sysarg_t) service, NULL);
262 measured_strings_send(exch, configuration, count);
263 int rc = measured_strings_return(exch, translation, data, count);
264 async_exchange_end(exch);
265
266 sysarg_t result;
267 async_wait_for(message_id, &result);
268
269 /* If not successful */
270 if ((rc == EOK) && (result != EOK)) {
271 /* Clear the data */
272 free(*translation);
273 free(*data);
274 }
275
276 return (int) result;
277}
278
279/** @}
280 */
Note: See TracBrowser for help on using the repository browser.