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