source: mainline/uspace/lib/net/generic/generic.c@ 30413b31

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 30413b31 was c3887ad, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Fix Ethernet. Missed change in generic_send_msg_remote() was causing arp module to see device address length as 0.

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