[14f1db0] | 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 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
| 34 | * Network interface module skeleton.
|
---|
| 35 | * The skeleton has to be part of each network interface module.
|
---|
| 36 | */
|
---|
| 37 |
|
---|
[42a9f27] | 38 | #ifndef NET_NETIF_LOCAL_H_
|
---|
| 39 | #define NET_NETIF_LOCAL_H_
|
---|
[14f1db0] | 40 |
|
---|
| 41 | #include <async.h>
|
---|
| 42 | #include <fibril_synch.h>
|
---|
| 43 | #include <ipc/ipc.h>
|
---|
| 44 | #include <ipc/services.h>
|
---|
| 45 |
|
---|
| 46 | #include <adt/measured_strings.h>
|
---|
[e526f08] | 47 | #include <net/device.h>
|
---|
[c69d327] | 48 | #include <net/packet.h>
|
---|
[14f1db0] | 49 |
|
---|
[42a9f27] | 50 | /** Network interface device specific data. */
|
---|
[14f1db0] | 51 | typedef struct {
|
---|
| 52 | device_id_t device_id; /**< Device identifier. */
|
---|
| 53 | int nil_phone; /**< Receiving network interface layer phone. */
|
---|
| 54 | device_state_t state; /**< Actual device state. */
|
---|
| 55 | void *specific; /**< Driver specific data. */
|
---|
| 56 | } netif_device_t;
|
---|
| 57 |
|
---|
| 58 | /** Device map.
|
---|
| 59 | *
|
---|
| 60 | * Maps device identifiers to the network interface device specific data.
|
---|
| 61 | * @see device.h
|
---|
| 62 | *
|
---|
| 63 | */
|
---|
| 64 | DEVICE_MAP_DECLARE(netif_device_map, netif_device_t);
|
---|
| 65 |
|
---|
[42a9f27] | 66 | /** Network interface module skeleton global data. */
|
---|
[14f1db0] | 67 | typedef struct {
|
---|
| 68 | int net_phone; /**< Networking module phone. */
|
---|
| 69 | netif_device_map_t device_map; /**< Device map. */
|
---|
| 70 | fibril_rwlock_t lock; /**< Safety lock. */
|
---|
| 71 | } netif_globals_t;
|
---|
| 72 |
|
---|
| 73 | extern netif_globals_t netif_globals;
|
---|
| 74 |
|
---|
| 75 | /** Initialize the specific module.
|
---|
| 76 | *
|
---|
| 77 | * This function has to be implemented in user code.
|
---|
| 78 | */
|
---|
| 79 | extern int netif_initialize(void);
|
---|
| 80 |
|
---|
| 81 | /** Probe the existence of the device.
|
---|
| 82 | *
|
---|
| 83 | * This has to be implemented in user code.
|
---|
| 84 | *
|
---|
[42a9f27] | 85 | * @param[in] device_id The device identifier.
|
---|
| 86 | * @param[in] irq The device interrupt number.
|
---|
| 87 | * @param[in] io The device input/output address.
|
---|
[14f1db0] | 88 | *
|
---|
[42a9f27] | 89 | * @return EOK on success.
|
---|
| 90 | * @return Other error codes as defined for the find_device()
|
---|
| 91 | * function.
|
---|
| 92 | * @return Other error codes as defined for the specific module
|
---|
| 93 | * message implementation.
|
---|
[14f1db0] | 94 | */
|
---|
| 95 | extern int netif_probe_message(device_id_t device_id, int irq, uintptr_t io);
|
---|
| 96 |
|
---|
| 97 | /** Send the packet queue.
|
---|
| 98 | *
|
---|
| 99 | * This has to be implemented in user code.
|
---|
| 100 | *
|
---|
[42a9f27] | 101 | * @param[in] device_id The device identifier.
|
---|
| 102 | * @param[in] packet The packet queue.
|
---|
| 103 | * @param[in] sender The sending module service.
|
---|
| 104 | *
|
---|
| 105 | * @return EOK on success.
|
---|
| 106 | * @return EFORWARD if the device is not active (in the
|
---|
| 107 | * NETIF_ACTIVE state).
|
---|
| 108 | * @return Other error codes as defined for the find_device()
|
---|
| 109 | * function.
|
---|
| 110 | * @return Other error codes as defined for the specific module
|
---|
| 111 | * message implementation.
|
---|
[14f1db0] | 112 | */
|
---|
[46d4d9f] | 113 | extern int netif_send_message(device_id_t device_id, packet_t *packet,
|
---|
[14f1db0] | 114 | services_t sender);
|
---|
| 115 |
|
---|
| 116 | /** Start the device.
|
---|
| 117 | *
|
---|
| 118 | * This has to be implemented in user code.
|
---|
| 119 | *
|
---|
[42a9f27] | 120 | * @param[in] device The device structure.
|
---|
[14f1db0] | 121 | *
|
---|
[42a9f27] | 122 | * @return EOK on success.
|
---|
| 123 | * @return Other error codes as defined for the find_device()
|
---|
| 124 | * function.
|
---|
| 125 | * @return Other error codes as defined for the specific module
|
---|
| 126 | * message implementation.
|
---|
[14f1db0] | 127 | */
|
---|
| 128 | extern int netif_start_message(netif_device_t *device);
|
---|
| 129 |
|
---|
| 130 | /** Stop the device.
|
---|
| 131 | *
|
---|
| 132 | * This has to be implemented in user code.
|
---|
| 133 | *
|
---|
[42a9f27] | 134 | * @param[in] device The device structure.
|
---|
[14f1db0] | 135 | *
|
---|
[42a9f27] | 136 | * @return EOK on success.
|
---|
| 137 | * @return Other error codes as defined for the find_device()
|
---|
| 138 | * function.
|
---|
| 139 | * @return Other error codes as defined for the specific module
|
---|
| 140 | * message implementation.
|
---|
[14f1db0] | 141 | */
|
---|
| 142 | extern int netif_stop_message(netif_device_t *device);
|
---|
| 143 |
|
---|
| 144 | /** Return the device local hardware address.
|
---|
| 145 | *
|
---|
| 146 | * This has to be implemented in user code.
|
---|
| 147 | *
|
---|
[42a9f27] | 148 | * @param[in] device_id The device identifier.
|
---|
| 149 | * @param[out] address The device local hardware address.
|
---|
[14f1db0] | 150 | *
|
---|
[42a9f27] | 151 | * @return EOK on success.
|
---|
| 152 | * @return EBADMEM if the address parameter is NULL.
|
---|
| 153 | * @return ENOENT if there no such device.
|
---|
| 154 | * @return Other error codes as defined for the find_device()
|
---|
| 155 | * function.
|
---|
| 156 | * @return Other error codes as defined for the specific module
|
---|
| 157 | * message implementation.
|
---|
[14f1db0] | 158 | */
|
---|
| 159 | extern int netif_get_addr_message(device_id_t device_id,
|
---|
[4eca056] | 160 | measured_string_t *address);
|
---|
[14f1db0] | 161 |
|
---|
| 162 | /** Process the netif driver specific message.
|
---|
| 163 | *
|
---|
| 164 | * This function is called for uncommon messages received by the netif
|
---|
| 165 | * skeleton. This has to be implemented in user code.
|
---|
| 166 | *
|
---|
[42a9f27] | 167 | * @param[in] callid The message identifier.
|
---|
| 168 | * @param[in] call The message parameters.
|
---|
| 169 | * @param[out] answer The message answer parameters.
|
---|
[14f1db0] | 170 | * @param[out] answer_count The last parameter for the actual answer in
|
---|
[42a9f27] | 171 | * the answer parameter.
|
---|
[14f1db0] | 172 | *
|
---|
[42a9f27] | 173 | * @return EOK on success.
|
---|
| 174 | * @return ENOTSUP if the message is not known.
|
---|
| 175 | * @return Other error codes as defined for the specific module
|
---|
| 176 | * message implementation.
|
---|
[14f1db0] | 177 | */
|
---|
| 178 | extern int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
|
---|
| 179 | ipc_call_t *answer, int *answer_count);
|
---|
| 180 |
|
---|
| 181 | /** Return the device usage statistics.
|
---|
| 182 | *
|
---|
| 183 | * This has to be implemented in user code.
|
---|
| 184 | *
|
---|
[42a9f27] | 185 | * @param[in] device_id The device identifier.
|
---|
| 186 | * @param[out] stats The device usage statistics.
|
---|
[14f1db0] | 187 | *
|
---|
[42a9f27] | 188 | * @return EOK on success.
|
---|
| 189 | * @return Other error codes as defined for the find_device()
|
---|
| 190 | * function.
|
---|
| 191 | * @return Other error codes as defined for the specific module
|
---|
| 192 | * message implementation.
|
---|
[14f1db0] | 193 | */
|
---|
| 194 | extern int netif_get_device_stats(device_id_t device_id,
|
---|
[f772bc55] | 195 | device_stats_t *stats);
|
---|
[14f1db0] | 196 |
|
---|
[4eca056] | 197 | extern int netif_get_addr_req_local(int, device_id_t, measured_string_t **,
|
---|
[854151c] | 198 | uint8_t **);
|
---|
[14f1db0] | 199 | extern int netif_probe_req_local(int, device_id_t, int, int);
|
---|
[46d4d9f] | 200 | extern int netif_send_msg_local(int, device_id_t, packet_t *, services_t);
|
---|
[14f1db0] | 201 | extern int netif_start_req_local(int, device_id_t);
|
---|
| 202 | extern int netif_stop_req_local(int, device_id_t);
|
---|
[f772bc55] | 203 | extern int netif_stats_req_local(int, device_id_t, device_stats_t *);
|
---|
[14f1db0] | 204 | extern int netif_bind_service_local(services_t, device_id_t, services_t,
|
---|
| 205 | async_client_conn_t);
|
---|
| 206 |
|
---|
| 207 | extern int find_device(device_id_t, netif_device_t **);
|
---|
[f772bc55] | 208 | extern void null_device_stats(device_stats_t *);
|
---|
[14f1db0] | 209 | extern void netif_pq_release(packet_id_t);
|
---|
[46d4d9f] | 210 | extern packet_t *netif_packet_get_1(size_t);
|
---|
[14f1db0] | 211 | extern int netif_init_module(async_client_conn_t);
|
---|
| 212 |
|
---|
| 213 | extern int netif_module_message_standalone(const char *, ipc_callid_t,
|
---|
| 214 | ipc_call_t *, ipc_call_t *, int *);
|
---|
| 215 | extern int netif_module_start_standalone(async_client_conn_t);
|
---|
| 216 |
|
---|
| 217 | #endif
|
---|
| 218 |
|
---|
| 219 | /** @}
|
---|
| 220 | */
|
---|