[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 |
|
---|
[faa3588] | 29 | /** @addtogroup libnet
|
---|
| 30 | * @{
|
---|
[21580dd] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
[faa3588] | 34 | * ARP interface implementation for remote modules.
|
---|
| 35 | * @see arp_interface.h
|
---|
[21580dd] | 36 | */
|
---|
| 37 |
|
---|
[514ee46] | 38 | #include <arp_interface.h>
|
---|
| 39 | #include <generic.h>
|
---|
| 40 |
|
---|
[21580dd] | 41 | #include <async.h>
|
---|
| 42 | #include <errno.h>
|
---|
| 43 | #include <ipc/ipc.h>
|
---|
| 44 | #include <ipc/services.h>
|
---|
[f87ec535] | 45 | #include <ipc/arp.h>
|
---|
[21580dd] | 46 |
|
---|
[c7a8442] | 47 | #include <net/modules.h>
|
---|
[e526f08] | 48 | #include <net/device.h>
|
---|
[849ed54] | 49 | #include <adt/measured_strings.h>
|
---|
[21580dd] | 50 |
|
---|
[faa3588] | 51 | /** Connects to the ARP module.
|
---|
| 52 | *
|
---|
| 53 | * @param service The ARP module service. Ignored parameter.
|
---|
[1bfd3d3] | 54 | * @return The ARP module phone on success.
|
---|
[faa3588] | 55 | */
|
---|
| 56 | int arp_connect_module(services_t service)
|
---|
| 57 | {
|
---|
| 58 | if (service != SERVICE_ARP)
|
---|
[a64c64d] | 59 | return EINVAL;
|
---|
[faa3588] | 60 |
|
---|
[a64c64d] | 61 | return connect_to_service(SERVICE_ARP);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[faa3588] | 64 | /** Cleans the cache.
|
---|
| 65 | *
|
---|
| 66 | * @param[in] arp_phone The ARP module phone used for (semi)remote calls.
|
---|
[1bfd3d3] | 67 | * @return EOK on success.
|
---|
[faa3588] | 68 | */
|
---|
| 69 | int arp_clean_cache_req(int arp_phone)
|
---|
| 70 | {
|
---|
[a64c64d] | 71 | return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[faa3588] | 74 | /** Clears the given protocol address from the cache.
|
---|
| 75 | *
|
---|
| 76 | * @param[in] arp_phone The ARP module phone used for (semi)remote calls.
|
---|
| 77 | * @param[in] device_id The device identifier.
|
---|
| 78 | * @param[in] protocol The requesting protocol service.
|
---|
| 79 | * @param[in] address The protocol address to be cleared.
|
---|
[1bfd3d3] | 80 | * @return EOK on success.
|
---|
| 81 | * @return ENOENT if the mapping is not found.
|
---|
[faa3588] | 82 | */
|
---|
| 83 | int
|
---|
| 84 | arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol,
|
---|
[4eca056] | 85 | measured_string_t *address)
|
---|
[faa3588] | 86 | {
|
---|
[aadf01e] | 87 | aid_t message_id;
|
---|
[96b02eb9] | 88 | sysarg_t result;
|
---|
[aadf01e] | 89 |
|
---|
[faa3588] | 90 | message_id = async_send_2(arp_phone, NET_ARP_CLEAR_ADDRESS,
|
---|
[96b02eb9] | 91 | (sysarg_t) device_id, protocol, NULL);
|
---|
[aadf01e] | 92 | measured_strings_send(arp_phone, address, 1);
|
---|
| 93 | async_wait_for(message_id, &result);
|
---|
[faa3588] | 94 |
|
---|
[aadf01e] | 95 | return (int) result;
|
---|
[21580dd] | 96 | }
|
---|
| 97 |
|
---|
[faa3588] | 98 | /** Clears the device cache.
|
---|
| 99 | *
|
---|
| 100 | * @param[in] arp_phone The ARP module phone used for (semi)remote calls.
|
---|
| 101 | * @param[in] device_id The device identifier.
|
---|
[1bfd3d3] | 102 | * @return EOK on success.
|
---|
| 103 | * @return ENOENT if the device is not found.
|
---|
[faa3588] | 104 | */
|
---|
| 105 | int arp_clear_device_req(int arp_phone, device_id_t device_id)
|
---|
| 106 | {
|
---|
| 107 | return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE,
|
---|
[96b02eb9] | 108 | (sysarg_t) device_id);
|
---|
[21580dd] | 109 | }
|
---|
| 110 |
|
---|
[faa3588] | 111 | /** Registers the new device and the requesting protocol service.
|
---|
| 112 | *
|
---|
| 113 | * Connects to the network interface layer service.
|
---|
| 114 | * Determines the device broadcast address, its address lengths and packet size.
|
---|
| 115 | *
|
---|
| 116 | * @param[in] arp_phone The ARP module phone used for (semi)remote calls.
|
---|
| 117 | * @param[in] device_id The new device identifier.
|
---|
| 118 | * @param[in] protocol The requesting protocol service.
|
---|
| 119 | * @param[in] netif The underlying device network interface layer service.
|
---|
| 120 | * @param[in] address The local requesting protocol address of the device.
|
---|
[1bfd3d3] | 121 | * @return EOK on success.
|
---|
| 122 | * @return EEXIST if the device is already used.
|
---|
| 123 | * @return ENOMEM if there is not enough memory left.
|
---|
| 124 | * @return ENOENT if the network interface service is not known.
|
---|
| 125 | * @return EREFUSED if the network interface service is not
|
---|
[faa3588] | 126 | * responding.
|
---|
[1bfd3d3] | 127 | * @return Other error codes as defined for the
|
---|
[faa3588] | 128 | * nil_packet_get_size() function.
|
---|
[1bfd3d3] | 129 | * @return Other error codes as defined for the nil_get_addr()
|
---|
[faa3588] | 130 | * function.
|
---|
[1bfd3d3] | 131 | * @return Other error codes as defined for the
|
---|
[faa3588] | 132 | * nil_get_broadcast_addr() function.
|
---|
| 133 | */
|
---|
| 134 | int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol,
|
---|
[4eca056] | 135 | services_t netif, measured_string_t *address)
|
---|
[faa3588] | 136 | {
|
---|
[aadf01e] | 137 | aid_t message_id;
|
---|
[96b02eb9] | 138 | sysarg_t result;
|
---|
[21580dd] | 139 |
|
---|
[faa3588] | 140 | message_id = async_send_3(arp_phone, NET_ARP_DEVICE,
|
---|
[96b02eb9] | 141 | (sysarg_t) device_id, protocol, netif, NULL);
|
---|
[aadf01e] | 142 | measured_strings_send(arp_phone, address, 1);
|
---|
| 143 | async_wait_for(message_id, &result);
|
---|
[faa3588] | 144 |
|
---|
[aadf01e] | 145 | return (int) result;
|
---|
[21580dd] | 146 | }
|
---|
| 147 |
|
---|
[faa3588] | 148 | /** Translates the given protocol address to the network interface address.
|
---|
| 149 | *
|
---|
| 150 | * Broadcasts the ARP request if the mapping is not found.
|
---|
| 151 | * Allocates and returns the needed memory block as the data parameter.
|
---|
| 152 | *
|
---|
| 153 | * @param[in] arp_phone The ARP module phone used for (semi)remote calls.
|
---|
| 154 | * @param[in] device_id The device identifier.
|
---|
| 155 | * @param[in] protocol The requesting protocol service.
|
---|
| 156 | * @param[in] address The local requesting protocol address.
|
---|
| 157 | * @param[out] translation The translation of the local protocol address.
|
---|
| 158 | * @param[out] data The allocated raw translation data container.
|
---|
[1bfd3d3] | 159 | * @return EOK on success.
|
---|
| 160 | * @return EINVAL if the address parameter is NULL.
|
---|
| 161 | * @return EBADMEM if the translation or the data parameters are
|
---|
[faa3588] | 162 | * NULL.
|
---|
[1bfd3d3] | 163 | * @return ENOENT if the mapping is not found.
|
---|
[faa3588] | 164 | */
|
---|
| 165 | int
|
---|
| 166 | arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol,
|
---|
[4eca056] | 167 | measured_string_t *address, measured_string_t **translation, char **data)
|
---|
[faa3588] | 168 | {
|
---|
| 169 | return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id,
|
---|
| 170 | protocol, address, 1, translation, data);
|
---|
[a64c64d] | 171 | }
|
---|
| 172 |
|
---|
[21580dd] | 173 | /** @}
|
---|
| 174 | */
|
---|