[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 |
|
---|
[42a9f27] | 29 | /** @addtogroup libnet
|
---|
[14f1db0] | 30 | * @{
|
---|
[21580dd] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
[14f1db0] | 34 | * Network interface module interface implementation for remote modules.
|
---|
[21580dd] | 35 | */
|
---|
| 36 |
|
---|
[42a9f27] | 37 | #include <netif_remote.h>
|
---|
| 38 | #include <packet_client.h>
|
---|
| 39 | #include <generic.h>
|
---|
| 40 |
|
---|
[21580dd] | 41 | #include <ipc/services.h>
|
---|
[995689d1] | 42 | #include <ipc/netif.h>
|
---|
[21580dd] | 43 |
|
---|
[c7a8442] | 44 | #include <net/modules.h>
|
---|
[849ed54] | 45 | #include <adt/measured_strings.h>
|
---|
[c69d327] | 46 | #include <net/packet.h>
|
---|
[e526f08] | 47 | #include <net/device.h>
|
---|
[21580dd] | 48 |
|
---|
[42a9f27] | 49 | /** Return the device local hardware address.
|
---|
| 50 | *
|
---|
| 51 | * @param[in] netif_phone The network interface phone.
|
---|
| 52 | * @param[in] device_id The device identifier.
|
---|
| 53 | * @param[out] address The device local hardware address.
|
---|
| 54 | * @param[out] data The address data.
|
---|
| 55 | * @return EOK on success.
|
---|
| 56 | * @return EBADMEM if the address parameter is NULL.
|
---|
| 57 | * @return ENOENT if there no such device.
|
---|
| 58 | * @return Other error codes as defined for the
|
---|
| 59 | * netif_get_addr_message() function.
|
---|
| 60 | */
|
---|
[14f1db0] | 61 | int netif_get_addr_req_remote(int netif_phone, device_id_t device_id,
|
---|
[854151c] | 62 | measured_string_t **address, uint8_t **data)
|
---|
[14f1db0] | 63 | {
|
---|
| 64 | return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id,
|
---|
| 65 | address, data);
|
---|
[21580dd] | 66 | }
|
---|
| 67 |
|
---|
[42a9f27] | 68 | /** Probe the existence of the device.
|
---|
| 69 | *
|
---|
| 70 | * @param[in] netif_phone The network interface phone.
|
---|
| 71 | * @param[in] device_id The device identifier.
|
---|
| 72 | * @param[in] irq The device interrupt number.
|
---|
| 73 | * @param[in] io The device input/output address.
|
---|
| 74 | * @return EOK on success.
|
---|
| 75 | * @return Other error codes as defined for the
|
---|
| 76 | * netif_probe_message().
|
---|
| 77 | */
|
---|
| 78 | int
|
---|
| 79 | netif_probe_req_remote(int netif_phone, device_id_t device_id, int irq, int io)
|
---|
[14f1db0] | 80 | {
|
---|
[aadf01e] | 81 | return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq, io);
|
---|
[21580dd] | 82 | }
|
---|
| 83 |
|
---|
[42a9f27] | 84 | /** Send the packet queue.
|
---|
| 85 | *
|
---|
| 86 | * @param[in] netif_phone The network interface phone.
|
---|
| 87 | * @param[in] device_id The device identifier.
|
---|
| 88 | * @param[in] packet The packet queue.
|
---|
| 89 | * @param[in] sender The sending module service.
|
---|
| 90 | * @return EOK on success.
|
---|
| 91 | * @return Other error codes as defined for the generic_send_msg()
|
---|
| 92 | * function.
|
---|
| 93 | */
|
---|
| 94 | int
|
---|
[46d4d9f] | 95 | netif_send_msg_remote(int netif_phone, device_id_t device_id, packet_t *packet,
|
---|
[14f1db0] | 96 | services_t sender)
|
---|
| 97 | {
|
---|
| 98 | return generic_send_msg_remote(netif_phone, NET_NETIF_SEND, device_id,
|
---|
| 99 | packet_get_id(packet), sender, 0);
|
---|
[21580dd] | 100 | }
|
---|
| 101 |
|
---|
[42a9f27] | 102 | /** Start the device.
|
---|
| 103 | *
|
---|
| 104 | * @param[in] netif_phone The network interface phone.
|
---|
| 105 | * @param[in] device_id The device identifier.
|
---|
| 106 | * @return EOK on success.
|
---|
| 107 | * @return Other error codes as defined for the find_device()
|
---|
| 108 | * function.
|
---|
| 109 | * @return Other error codes as defined for the
|
---|
| 110 | * netif_start_message() function.
|
---|
| 111 | */
|
---|
[14f1db0] | 112 | int netif_start_req_remote(int netif_phone, device_id_t device_id)
|
---|
| 113 | {
|
---|
[aadf01e] | 114 | return async_req_1_0(netif_phone, NET_NETIF_START, device_id);
|
---|
[21580dd] | 115 | }
|
---|
| 116 |
|
---|
[42a9f27] | 117 | /** Stop the device.
|
---|
| 118 | *
|
---|
| 119 | * @param[in] netif_phone The network interface phone.
|
---|
| 120 | * @param[in] device_id The device identifier.
|
---|
| 121 | * @return EOK on success.
|
---|
| 122 | * @return Other error codes as defined for the find_device()
|
---|
| 123 | * function.
|
---|
| 124 | * @return Other error codes as defined for the
|
---|
| 125 | * netif_stop_message() function.
|
---|
| 126 | */
|
---|
[14f1db0] | 127 | int netif_stop_req_remote(int netif_phone, device_id_t device_id)
|
---|
| 128 | {
|
---|
[aadf01e] | 129 | return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
|
---|
[21580dd] | 130 | }
|
---|
| 131 |
|
---|
[42a9f27] | 132 | /** Return the device usage statistics.
|
---|
| 133 | *
|
---|
| 134 | * @param[in] netif_phone The network interface phone.
|
---|
| 135 | * @param[in] device_id The device identifier.
|
---|
| 136 | * @param[out] stats The device usage statistics.
|
---|
| 137 | * @return EOK on success.
|
---|
| 138 | */
|
---|
[14f1db0] | 139 | int netif_stats_req_remote(int netif_phone, device_id_t device_id,
|
---|
[f772bc55] | 140 | device_stats_t *stats)
|
---|
[14f1db0] | 141 | {
|
---|
| 142 | if (!stats)
|
---|
[aadf01e] | 143 | return EBADMEM;
|
---|
[14f1db0] | 144 |
|
---|
| 145 | aid_t message_id = async_send_1(netif_phone, NET_NETIF_STATS,
|
---|
[96b02eb9] | 146 | (sysarg_t) device_id, NULL);
|
---|
[aadf01e] | 147 | async_data_read_start(netif_phone, stats, sizeof(*stats));
|
---|
[14f1db0] | 148 |
|
---|
[96b02eb9] | 149 | sysarg_t result;
|
---|
[aadf01e] | 150 | async_wait_for(message_id, &result);
|
---|
[14f1db0] | 151 |
|
---|
[aadf01e] | 152 | return (int) result;
|
---|
[21580dd] | 153 | }
|
---|
| 154 |
|
---|
[9757512] | 155 | /** Create bidirectional connection with the network interface module and
|
---|
| 156 | * registers the message receiver.
|
---|
| 157 | *
|
---|
| 158 | * @param[in] service The network interface module service.
|
---|
| 159 | * @param[in] device_id The device identifier.
|
---|
| 160 | * @param[in] me The requesting module service.
|
---|
| 161 | * @param[in] receiver The message receiver.
|
---|
| 162 | *
|
---|
[42a9f27] | 163 | * @return The phone of the needed service.
|
---|
| 164 | * @return EOK on success.
|
---|
| 165 | * @return Other error codes as defined for the bind_service()
|
---|
| 166 | * function.
|
---|
[9757512] | 167 | */
|
---|
[42a9f27] | 168 | int
|
---|
| 169 | netif_bind_service_remote(services_t service, device_id_t device_id,
|
---|
| 170 | services_t me, async_client_conn_t receiver)
|
---|
[14f1db0] | 171 | {
|
---|
[aadf01e] | 172 | return bind_service(service, device_id, me, 0, receiver);
|
---|
[21580dd] | 173 | }
|
---|
| 174 |
|
---|
| 175 | /** @}
|
---|
| 176 | */
|
---|