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