source: mainline/uspace/lib/net/generic/net_remote.c@ 77a69ea

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

Allow multiple tasks to register for loc category change events.
Open NIC devices via location service, discover using category change events.
Eliminate device_added driver entry point.
loc_service_get_name() should return fully qualified service name.

  • Property mode set to 100644
File size: 5.2 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 * Networking interface implementation for remote modules.
35 * @see net_interface.h
36 */
37
38#include <ipc/services.h>
39#include <ipc/net_net.h>
40#include <malloc.h>
41#include <async.h>
42#include <devman.h>
43#include <generic.h>
44#include <net/modules.h>
45#include <net/device.h>
46#include <net_interface.h>
47#include <adt/measured_strings.h>
48
49/** Connect to the networking module.
50 *
51 * @return Networking module session on success.
52 *
53 */
54async_sess_t *net_connect_module(void)
55{
56 return connect_to_service(SERVICE_NETWORKING);
57}
58
59/** Free the received settings.
60 *
61 * @param[in] settings Received settings.
62 * @param[in] data Received settings data.
63 *
64 * @see net_get_device_conf_req()
65 * @see net_get_conf_req()
66 *
67 */
68void net_free_settings(measured_string_t *settings, uint8_t *data)
69{
70 if (settings)
71 free(settings);
72 if (data)
73 free(data);
74}
75
76/** Return the global configuration.
77 *
78 * The configuration names are read and the appropriate settings are set
79 * instead. Call net_free_settings() function to release the returned
80 * configuration.
81 *
82 * @param[in] sess Networking module session.
83 * @param[in,out] configuration Requested configuration. The names are
84 * read and the appropriate settings are set
85 * instead.
86 *
87 * @param[in] count Configuration entries count.
88 * @param[in,out] data Configuration and settings data.
89 *
90 * @return EOK on success.
91 * @return EINVAL if the configuration is NULL.
92 * @return EINVAL if the count is zero.
93 * @return Other error codes as defined for the
94 * generic_translate_req() function.
95 *
96 */
97int net_get_conf_req(async_sess_t *sess, measured_string_t **configuration,
98 size_t count, uint8_t **data)
99{
100 return generic_translate_req(sess, NET_NET_GET_CONF, 0, 0,
101 *configuration, count, configuration, data);
102}
103
104/** Return the device specific configuration.
105 *
106 * Return the global configuration if the device specific is not found.
107 * The configuration names are read and the appropriate settings are set
108 * instead. Call net_free_settings() function to release the returned
109 * configuration.
110 *
111 * @param[in] sess The networking module session.
112 * @param[in] device_id Device identifier.
113 * @param[in,out] configuration Requested device configuration. The names
114 * are read and the appropriate settings are
115 * set instead.
116 * @param[in] count Configuration entries count.
117 * @param[in,out] data Configuration and settings data.
118 *
119 * @return EOK on success.
120 * @return EINVAL if the configuration is NULL.
121 * @return EINVAL if the count is zero.
122 * @return Other error codes as defined for the
123 * generic_translate_req() function.
124 *
125 */
126int net_get_device_conf_req(async_sess_t *sess, nic_device_id_t device_id,
127 measured_string_t **configuration, size_t count, uint8_t **data)
128{
129 return generic_translate_req(sess, NET_NET_GET_DEVICE_CONF,
130 device_id, 0, *configuration, count, configuration, data);
131}
132
133int net_get_devices_req(async_sess_t *sess, measured_string_t **devices,
134 size_t *count, uint8_t **data)
135{
136 if ((!devices) || (!count))
137 return EBADMEM;
138
139 async_exch_t *exch = async_exchange_begin(sess);
140
141 int rc = async_req_0_1(exch, NET_NET_GET_DEVICES_COUNT, count);
142 if (rc != EOK) {
143 async_exchange_end(exch);
144 return rc;
145 }
146
147 if (*count == 0) {
148 async_exchange_end(exch);
149 *data = NULL;
150 return EOK;
151 }
152
153 aid_t message_id = async_send_0(exch, NET_NET_GET_DEVICES, NULL);
154 rc = measured_strings_return(exch, devices, data, *count);
155
156 async_exchange_end(exch);
157
158 sysarg_t result;
159 async_wait_for(message_id, &result);
160
161 if ((rc == EOK) && (result != EOK)) {
162 free(*devices);
163 free(*data);
164 }
165
166 return (int) result;
167}
168
169/** @}
170 */
Note: See TracBrowser for help on using the repository browser.