| 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 |
|
|---|
| 29 | /** @addtogroup libnet
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /** @file
|
|---|
| 34 | * Network interface module interface implementation for remote modules.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <netif_remote.h>
|
|---|
| 38 | #include <packet_client.h>
|
|---|
| 39 | #include <generic.h>
|
|---|
| 40 | #include <ipc/services.h>
|
|---|
| 41 | #include <ipc/netif.h>
|
|---|
| 42 | #include <net/modules.h>
|
|---|
| 43 | #include <adt/measured_strings.h>
|
|---|
| 44 | #include <net/packet.h>
|
|---|
| 45 | #include <net/device.h>
|
|---|
| 46 |
|
|---|
| 47 | /** Return the device local hardware address.
|
|---|
| 48 | *
|
|---|
| 49 | * @param[in] sess Network interface session.
|
|---|
| 50 | * @param[in] device_id Device identifier.
|
|---|
| 51 | * @param[out] address Device local hardware address.
|
|---|
| 52 | * @param[out] data Address data.
|
|---|
| 53 | *
|
|---|
| 54 | * @return EOK on success.
|
|---|
| 55 | * @return EBADMEM if the address parameter is NULL.
|
|---|
| 56 | * @return ENOENT if there no such device.
|
|---|
| 57 | * @return Other error codes as defined for the
|
|---|
| 58 | * netif_get_addr_message() function.
|
|---|
| 59 | *
|
|---|
| 60 | */
|
|---|
| 61 | int netif_get_addr_req(async_sess_t *sess, device_id_t device_id,
|
|---|
| 62 | measured_string_t **address, uint8_t **data)
|
|---|
| 63 | {
|
|---|
| 64 | return generic_get_addr_req(sess, NET_NETIF_GET_ADDR, device_id,
|
|---|
| 65 | address, data);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /** Probe the existence of the device.
|
|---|
| 69 | *
|
|---|
| 70 | * @param[in] sess Network interface session.
|
|---|
| 71 | * @param[in] device_id Device identifier.
|
|---|
| 72 | * @param[in] irq Device interrupt number.
|
|---|
| 73 | * @param[in] io Device input/output address.
|
|---|
| 74 | *
|
|---|
| 75 | * @return EOK on success.
|
|---|
| 76 | * @return Other error codes as defined for the
|
|---|
| 77 | * netif_probe_message().
|
|---|
| 78 | *
|
|---|
| 79 | */
|
|---|
| 80 | int netif_probe_req(async_sess_t *sess, device_id_t device_id, int irq, void *io)
|
|---|
| 81 | {
|
|---|
| 82 | async_exch_t *exch = async_exchange_begin(sess);
|
|---|
| 83 | int rc = async_req_3_0(exch, NET_NETIF_PROBE, device_id, (sysarg_t) irq,
|
|---|
| 84 | (sysarg_t) io);
|
|---|
| 85 | async_exchange_end(exch);
|
|---|
| 86 |
|
|---|
| 87 | return rc;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | /** Send the packet queue.
|
|---|
| 91 | *
|
|---|
| 92 | * @param[in] sess Network interface session.
|
|---|
| 93 | * @param[in] device_id Device identifier.
|
|---|
| 94 | * @param[in] packet Packet queue.
|
|---|
| 95 | * @param[in] sender Sending module service.
|
|---|
| 96 | *
|
|---|
| 97 | * @return EOK on success.
|
|---|
| 98 | * @return Other error codes as defined for the generic_send_msg()
|
|---|
| 99 | * function.
|
|---|
| 100 | *
|
|---|
| 101 | */
|
|---|
| 102 | int netif_send_msg(async_sess_t *sess, device_id_t device_id, packet_t *packet,
|
|---|
| 103 | services_t sender)
|
|---|
| 104 | {
|
|---|
| 105 | return generic_send_msg_remote(sess, NET_NETIF_SEND, device_id,
|
|---|
| 106 | packet_get_id(packet), sender, 0);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /** Start the device.
|
|---|
| 110 | *
|
|---|
| 111 | * @param[in] sess Network interface session.
|
|---|
| 112 | * @param[in] device_id Device identifier.
|
|---|
| 113 | *
|
|---|
| 114 | * @return EOK on success.
|
|---|
| 115 | * @return Other error codes as defined for the find_device()
|
|---|
| 116 | * function.
|
|---|
| 117 | * @return Other error codes as defined for the
|
|---|
| 118 | * netif_start_message() function.
|
|---|
| 119 | *
|
|---|
| 120 | */
|
|---|
| 121 | int netif_start_req(async_sess_t *sess, device_id_t device_id)
|
|---|
| 122 | {
|
|---|
| 123 | async_exch_t *exch = async_exchange_begin(sess);
|
|---|
| 124 | int rc = async_req_1_0(exch, NET_NETIF_START, device_id);
|
|---|
| 125 | async_exchange_end(exch);
|
|---|
| 126 |
|
|---|
| 127 | return rc;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | /** Stop the device.
|
|---|
| 131 | *
|
|---|
| 132 | * @param[in] sess Network interface session.
|
|---|
| 133 | * @param[in] device_id Device identifier.
|
|---|
| 134 | *
|
|---|
| 135 | * @return EOK on success.
|
|---|
| 136 | * @return Other error codes as defined for the find_device()
|
|---|
| 137 | * function.
|
|---|
| 138 | * @return Other error codes as defined for the
|
|---|
| 139 | * netif_stop_message() function.
|
|---|
| 140 | *
|
|---|
| 141 | */
|
|---|
| 142 | int netif_stop_req(async_sess_t *sess, device_id_t device_id)
|
|---|
| 143 | {
|
|---|
| 144 | async_exch_t *exch = async_exchange_begin(sess);
|
|---|
| 145 | int rc = async_req_1_0(exch, NET_NETIF_STOP, device_id);
|
|---|
| 146 | async_exchange_end(exch);
|
|---|
| 147 |
|
|---|
| 148 | return rc;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /** Return the device usage statistics.
|
|---|
| 152 | *
|
|---|
| 153 | * @param[in] sess Network interface session.
|
|---|
| 154 | * @param[in] device_id Device identifier.
|
|---|
| 155 | * @param[out] stats Device usage statistics.
|
|---|
| 156 | *
|
|---|
| 157 | * @return EOK on success.
|
|---|
| 158 | *
|
|---|
| 159 | */
|
|---|
| 160 | int netif_stats_req(async_sess_t *sess, device_id_t device_id,
|
|---|
| 161 | device_stats_t *stats)
|
|---|
| 162 | {
|
|---|
| 163 | if (!stats)
|
|---|
| 164 | return EBADMEM;
|
|---|
| 165 |
|
|---|
| 166 | async_exch_t *exch = async_exchange_begin(sess);
|
|---|
| 167 | aid_t message_id = async_send_1(exch, NET_NETIF_STATS,
|
|---|
| 168 | (sysarg_t) device_id, NULL);
|
|---|
| 169 | async_data_read_start(exch, stats, sizeof(*stats));
|
|---|
| 170 | async_exchange_end(exch);
|
|---|
| 171 |
|
|---|
| 172 | sysarg_t result;
|
|---|
| 173 | async_wait_for(message_id, &result);
|
|---|
| 174 |
|
|---|
| 175 | return (int) result;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | /** Create bidirectional connection with the network interface module
|
|---|
| 179 | *
|
|---|
| 180 | * Create bidirectional connection with the network interface module and
|
|---|
| 181 | * register the message receiver.
|
|---|
| 182 | *
|
|---|
| 183 | * @param[in] service Network interface module service.
|
|---|
| 184 | * @param[in] device_id Device identifier.
|
|---|
| 185 | * @param[in] me Requesting module service.
|
|---|
| 186 | * @param[in] receiver Message receiver.
|
|---|
| 187 | *
|
|---|
| 188 | * @return Session to the needed service.
|
|---|
| 189 | * @return NULL on failure.
|
|---|
| 190 | *
|
|---|
| 191 | */
|
|---|
| 192 | async_sess_t *netif_bind_service(services_t service, device_id_t device_id,
|
|---|
| 193 | services_t me, async_client_conn_t receiver)
|
|---|
| 194 | {
|
|---|
| 195 | return bind_service(service, device_id, me, 0, receiver);
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | /** @}
|
|---|
| 199 | */
|
|---|