source: mainline/uspace/lib/net/netif/netif_remote.c@ 45cae6b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 45cae6b was 6b82009, checked in by Martin Decky <martin@…>, 15 years ago

networking stack: convert to the new async framework

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[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>
[21580dd]40#include <ipc/services.h>
[995689d1]41#include <ipc/netif.h>
[c7a8442]42#include <net/modules.h>
[849ed54]43#include <adt/measured_strings.h>
[c69d327]44#include <net/packet.h>
[e526f08]45#include <net/device.h>
[21580dd]46
[42a9f27]47/** Return the device local hardware address.
48 *
[6b82009]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.
[774e6d1a]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 *
[42a9f27]60 */
[6b82009]61int netif_get_addr_req(async_sess_t *sess, device_id_t device_id,
[854151c]62 measured_string_t **address, uint8_t **data)
[14f1db0]63{
[6b82009]64 return generic_get_addr_req(sess, NET_NETIF_GET_ADDR, device_id,
[14f1db0]65 address, data);
[21580dd]66}
67
[42a9f27]68/** Probe the existence of the device.
69 *
[6b82009]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.
[774e6d1a]74 *
75 * @return EOK on success.
76 * @return Other error codes as defined for the
77 * netif_probe_message().
78 *
[42a9f27]79 */
[6b82009]80int netif_probe_req(async_sess_t *sess, device_id_t device_id, int irq, void *io)
[14f1db0]81{
[6b82009]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,
[774e6d1a]84 (sysarg_t) io);
[6b82009]85 async_exchange_end(exch);
86
87 return rc;
[21580dd]88}
89
[42a9f27]90/** Send the packet queue.
91 *
[6b82009]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.
[774e6d1a]96 *
97 * @return EOK on success.
98 * @return Other error codes as defined for the generic_send_msg()
99 * function.
100 *
[42a9f27]101 */
[6b82009]102int netif_send_msg(async_sess_t *sess, device_id_t device_id, packet_t *packet,
[14f1db0]103 services_t sender)
104{
[6b82009]105 return generic_send_msg_remote(sess, NET_NETIF_SEND, device_id,
[14f1db0]106 packet_get_id(packet), sender, 0);
[21580dd]107}
108
[42a9f27]109/** Start the device.
110 *
[6b82009]111 * @param[in] sess Network interface session.
112 * @param[in] device_id Device identifier.
[774e6d1a]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 *
[42a9f27]120 */
[6b82009]121int netif_start_req(async_sess_t *sess, device_id_t device_id)
[14f1db0]122{
[6b82009]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;
[21580dd]128}
129
[42a9f27]130/** Stop the device.
131 *
[6b82009]132 * @param[in] sess Network interface session.
133 * @param[in] device_id Device identifier.
[774e6d1a]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 *
[42a9f27]141 */
[6b82009]142int netif_stop_req(async_sess_t *sess, device_id_t device_id)
[14f1db0]143{
[6b82009]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;
[21580dd]149}
150
[42a9f27]151/** Return the device usage statistics.
152 *
[6b82009]153 * @param[in] sess Network interface session.
154 * @param[in] device_id Device identifier.
155 * @param[out] stats Device usage statistics.
[774e6d1a]156 *
[42a9f27]157 * @return EOK on success.
[774e6d1a]158 *
[42a9f27]159 */
[6b82009]160int netif_stats_req(async_sess_t *sess, device_id_t device_id,
[f772bc55]161 device_stats_t *stats)
[14f1db0]162{
163 if (!stats)
[aadf01e]164 return EBADMEM;
[14f1db0]165
[6b82009]166 async_exch_t *exch = async_exchange_begin(sess);
167 aid_t message_id = async_send_1(exch, NET_NETIF_STATS,
[96b02eb9]168 (sysarg_t) device_id, NULL);
[6b82009]169 async_data_read_start(exch, stats, sizeof(*stats));
170 async_exchange_end(exch);
[14f1db0]171
[96b02eb9]172 sysarg_t result;
[aadf01e]173 async_wait_for(message_id, &result);
[14f1db0]174
[aadf01e]175 return (int) result;
[21580dd]176}
177
[774e6d1a]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.
[9757512]182 *
[6b82009]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.
[9757512]187 *
[6b82009]188 * @return Session to the needed service.
189 * @return NULL on failure.
[774e6d1a]190 *
[9757512]191 */
[6b82009]192async_sess_t *netif_bind_service(services_t service, device_id_t device_id,
[42a9f27]193 services_t me, async_client_conn_t receiver)
[14f1db0]194{
[aadf01e]195 return bind_service(service, device_id, me, 0, receiver);
[21580dd]196}
197
198/** @}
199 */
Note: See TracBrowser for help on using the repository browser.