[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 |
|
---|
| 41 | #include <malloc.h>
|
---|
| 42 |
|
---|
[514ee46] | 43 | #include <generic.h>
|
---|
[c7a8442] | 44 | #include <net/modules.h>
|
---|
[e526f08] | 45 | #include <net/device.h>
|
---|
[849ed54] | 46 | #include <net_interface.h>
|
---|
| 47 | #include <adt/measured_strings.h>
|
---|
[21580dd] | 48 |
|
---|
[614d065] | 49 | /** Connects to the networking module.
|
---|
| 50 | *
|
---|
[1bfd3d3] | 51 | * @return The networking module phone on success.
|
---|
[614d065] | 52 | */
|
---|
| 53 | int net_connect_module(void)
|
---|
[2fa0ad9] | 54 | {
|
---|
[a64c64d] | 55 | return connect_to_service(SERVICE_NETWORKING);
|
---|
[21580dd] | 56 | }
|
---|
| 57 |
|
---|
[614d065] | 58 | /** Frees the received settings.
|
---|
| 59 | *
|
---|
| 60 | * @param[in] settings The received settings.
|
---|
| 61 | * @param[in] data The received settings data.
|
---|
| 62 | * @see net_get_device_conf_req()
|
---|
| 63 | * @see net_get_conf_req()
|
---|
| 64 | */
|
---|
[61bfc370] | 65 | void net_free_settings(measured_string_t *settings, uint8_t *data)
|
---|
[2fa0ad9] | 66 | {
|
---|
| 67 | if (settings)
|
---|
[aadf01e] | 68 | free(settings);
|
---|
[2fa0ad9] | 69 | if (data)
|
---|
[aadf01e] | 70 | free(data);
|
---|
[21580dd] | 71 | }
|
---|
| 72 |
|
---|
[614d065] | 73 | /** Returns the global configuration.
|
---|
| 74 | *
|
---|
| 75 | * The configuration names are read and the appropriate settings are set
|
---|
| 76 | * instead. Call net_free_settings() function to release the returned
|
---|
| 77 | * configuration.
|
---|
| 78 | *
|
---|
| 79 | * @param[in] net_phone The networking module phone.
|
---|
| 80 | * @param[in,out] configuration The requested configuration. The names are read
|
---|
| 81 | * and the appropriate settings are set instead.
|
---|
| 82 | *
|
---|
| 83 | * @param[in] count The configuration entries count.
|
---|
| 84 | * @param[in,out] data The configuration and settings data.
|
---|
[1bfd3d3] | 85 | * @return EOK on success.
|
---|
| 86 | * @return EINVAL if the configuration is NULL.
|
---|
| 87 | * @return EINVAL if the count is zero.
|
---|
| 88 | * @return Other error codes as defined for the
|
---|
[614d065] | 89 | * generic_translate_req() function.
|
---|
| 90 | */
|
---|
[2fa0ad9] | 91 | int
|
---|
[4eca056] | 92 | net_get_conf_req(int net_phone, measured_string_t **configuration,
|
---|
[61bfc370] | 93 | size_t count, uint8_t **data)
|
---|
[2fa0ad9] | 94 | {
|
---|
| 95 | return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0,
|
---|
| 96 | *configuration, count, configuration, data);
|
---|
[a64c64d] | 97 | }
|
---|
| 98 |
|
---|
[614d065] | 99 | /** Returns the device specific configuration.
|
---|
| 100 | *
|
---|
| 101 | * Returns the global configuration if the device specific is not found.
|
---|
| 102 | * The configuration names are read and the appropriate settings are set
|
---|
| 103 | * instead. Call net_free_settings() function to release the returned
|
---|
| 104 | * configuration.
|
---|
| 105 | *
|
---|
| 106 | * @param[in] net_phone The networking module phone.
|
---|
| 107 | * @param[in] device_id The device identifier.
|
---|
| 108 | * @param[in,out] configuration The requested device configuration. The names
|
---|
| 109 | * are read and the appropriate settings are set instead.
|
---|
| 110 | * @param[in] count The configuration entries count.
|
---|
| 111 | * @param[in,out] data The configuration and settings data.
|
---|
[1bfd3d3] | 112 | * @return EOK on success.
|
---|
| 113 | * @return EINVAL if the configuration is NULL.
|
---|
| 114 | * @return EINVAL if the count is zero.
|
---|
| 115 | * @return Other error codes as defined for the
|
---|
[614d065] | 116 | * generic_translate_req() function.
|
---|
| 117 | */
|
---|
[2fa0ad9] | 118 | int
|
---|
| 119 | net_get_device_conf_req(int net_phone, device_id_t device_id,
|
---|
[61bfc370] | 120 | measured_string_t **configuration, size_t count, uint8_t **data)
|
---|
[2fa0ad9] | 121 | {
|
---|
| 122 | return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF,
|
---|
| 123 | device_id, 0, *configuration, count, configuration, data);
|
---|
[21580dd] | 124 | }
|
---|
| 125 |
|
---|
| 126 | /** @}
|
---|
| 127 | */
|
---|