[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 |
|
---|
[774e6d1a] | 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 | *
|
---|
[774e6d1a] | 51 | * @param[in] netif_phone Network interface phone.
|
---|
| 52 | * @param[in] device_id Device identifier.
|
---|
| 53 | * @param[out] address Device local hardware address.
|
---|
| 54 | * @param[out] data Address data.
|
---|
| 55 | *
|
---|
| 56 | * @return EOK on success.
|
---|
| 57 | * @return EBADMEM if the address parameter is NULL.
|
---|
| 58 | * @return ENOENT if there no such device.
|
---|
| 59 | * @return Other error codes as defined for the
|
---|
| 60 | * netif_get_addr_message() function.
|
---|
| 61 | *
|
---|
[42a9f27] | 62 | */
|
---|
[774e6d1a] | 63 | int netif_get_addr_req(int netif_phone, device_id_t device_id,
|
---|
[854151c] | 64 | measured_string_t **address, uint8_t **data)
|
---|
[14f1db0] | 65 | {
|
---|
| 66 | return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id,
|
---|
| 67 | address, data);
|
---|
[21580dd] | 68 | }
|
---|
| 69 |
|
---|
[42a9f27] | 70 | /** Probe the existence of the device.
|
---|
| 71 | *
|
---|
[774e6d1a] | 72 | * @param[in] netif_phone Network interface phone.
|
---|
| 73 | * @param[in] device_id Device identifier.
|
---|
| 74 | * @param[in] irq Device interrupt number.
|
---|
| 75 | * @param[in] io Device input/output address.
|
---|
| 76 | *
|
---|
| 77 | * @return EOK on success.
|
---|
| 78 | * @return Other error codes as defined for the
|
---|
| 79 | * netif_probe_message().
|
---|
| 80 | *
|
---|
[42a9f27] | 81 | */
|
---|
[774e6d1a] | 82 | int netif_probe_req(int netif_phone, device_id_t device_id, int irq, void *io)
|
---|
[14f1db0] | 83 | {
|
---|
[774e6d1a] | 84 | return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq,
|
---|
| 85 | (sysarg_t) io);
|
---|
[21580dd] | 86 | }
|
---|
| 87 |
|
---|
[42a9f27] | 88 | /** Send the packet queue.
|
---|
| 89 | *
|
---|
[774e6d1a] | 90 | * @param[in] netif_phone Network interface phone.
|
---|
| 91 | * @param[in] device_id Device identifier.
|
---|
| 92 | * @param[in] packet Packet queue.
|
---|
| 93 | * @param[in] sender Sending module service.
|
---|
| 94 | *
|
---|
| 95 | * @return EOK on success.
|
---|
| 96 | * @return Other error codes as defined for the generic_send_msg()
|
---|
| 97 | * function.
|
---|
| 98 | *
|
---|
[42a9f27] | 99 | */
|
---|
[774e6d1a] | 100 | int netif_send_msg(int netif_phone, device_id_t device_id, packet_t *packet,
|
---|
[14f1db0] | 101 | services_t sender)
|
---|
| 102 | {
|
---|
| 103 | return generic_send_msg_remote(netif_phone, NET_NETIF_SEND, device_id,
|
---|
| 104 | packet_get_id(packet), sender, 0);
|
---|
[21580dd] | 105 | }
|
---|
| 106 |
|
---|
[42a9f27] | 107 | /** Start the device.
|
---|
| 108 | *
|
---|
[774e6d1a] | 109 | * @param[in] netif_phone Network interface phone.
|
---|
| 110 | * @param[in] device_id Device identifier.
|
---|
| 111 | *
|
---|
| 112 | * @return EOK on success.
|
---|
| 113 | * @return Other error codes as defined for the find_device()
|
---|
| 114 | * function.
|
---|
| 115 | * @return Other error codes as defined for the
|
---|
| 116 | * netif_start_message() function.
|
---|
| 117 | *
|
---|
[42a9f27] | 118 | */
|
---|
[774e6d1a] | 119 | int netif_start_req(int netif_phone, device_id_t device_id)
|
---|
[14f1db0] | 120 | {
|
---|
[aadf01e] | 121 | return async_req_1_0(netif_phone, NET_NETIF_START, device_id);
|
---|
[21580dd] | 122 | }
|
---|
| 123 |
|
---|
[42a9f27] | 124 | /** Stop the device.
|
---|
| 125 | *
|
---|
[774e6d1a] | 126 | * @param[in] netif_phone Network interface phone.
|
---|
| 127 | * @param[in] device_id Device identifier.
|
---|
| 128 | *
|
---|
| 129 | * @return EOK on success.
|
---|
| 130 | * @return Other error codes as defined for the find_device()
|
---|
| 131 | * function.
|
---|
| 132 | * @return Other error codes as defined for the
|
---|
| 133 | * netif_stop_message() function.
|
---|
| 134 | *
|
---|
[42a9f27] | 135 | */
|
---|
[774e6d1a] | 136 | int netif_stop_req(int netif_phone, device_id_t device_id)
|
---|
[14f1db0] | 137 | {
|
---|
[aadf01e] | 138 | return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
|
---|
[21580dd] | 139 | }
|
---|
| 140 |
|
---|
[42a9f27] | 141 | /** Return the device usage statistics.
|
---|
| 142 | *
|
---|
[774e6d1a] | 143 | * @param[in] netif_phone Network interface phone.
|
---|
| 144 | * @param[in] device_id Device identifier.
|
---|
| 145 | * @param[out] stats Device usage statistics.
|
---|
| 146 | *
|
---|
[42a9f27] | 147 | * @return EOK on success.
|
---|
[774e6d1a] | 148 | *
|
---|
[42a9f27] | 149 | */
|
---|
[774e6d1a] | 150 | int netif_stats_req(int netif_phone, device_id_t device_id,
|
---|
[f772bc55] | 151 | device_stats_t *stats)
|
---|
[14f1db0] | 152 | {
|
---|
| 153 | if (!stats)
|
---|
[aadf01e] | 154 | return EBADMEM;
|
---|
[14f1db0] | 155 |
|
---|
| 156 | aid_t message_id = async_send_1(netif_phone, NET_NETIF_STATS,
|
---|
[96b02eb9] | 157 | (sysarg_t) device_id, NULL);
|
---|
[aadf01e] | 158 | async_data_read_start(netif_phone, stats, sizeof(*stats));
|
---|
[14f1db0] | 159 |
|
---|
[96b02eb9] | 160 | sysarg_t result;
|
---|
[aadf01e] | 161 | async_wait_for(message_id, &result);
|
---|
[14f1db0] | 162 |
|
---|
[aadf01e] | 163 | return (int) result;
|
---|
[21580dd] | 164 | }
|
---|
| 165 |
|
---|
[774e6d1a] | 166 | /** Create bidirectional connection with the network interface module
|
---|
| 167 | *
|
---|
| 168 | * Create bidirectional connection with the network interface module and
|
---|
| 169 | * register the message receiver.
|
---|
[9757512] | 170 | *
|
---|
| 171 | * @param[in] service The network interface module service.
|
---|
| 172 | * @param[in] device_id The device identifier.
|
---|
| 173 | * @param[in] me The requesting module service.
|
---|
| 174 | * @param[in] receiver The message receiver.
|
---|
| 175 | *
|
---|
[774e6d1a] | 176 | * @return The phone of the needed service.
|
---|
| 177 | * @return EOK on success.
|
---|
| 178 | * @return Other error codes as defined for the bind_service()
|
---|
| 179 | * function.
|
---|
| 180 | *
|
---|
[9757512] | 181 | */
|
---|
[774e6d1a] | 182 | int netif_bind_service(services_t service, device_id_t device_id,
|
---|
[42a9f27] | 183 | services_t me, async_client_conn_t receiver)
|
---|
[14f1db0] | 184 | {
|
---|
[aadf01e] | 185 | return bind_service(service, device_id, me, 0, receiver);
|
---|
[21580dd] | 186 | }
|
---|
| 187 |
|
---|
| 188 | /** @}
|
---|
| 189 | */
|
---|