source: mainline/uspace/lib/net/include/netif_skel.h@ 774e6d1a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 774e6d1a was 774e6d1a, checked in by martin@…>, 14 years ago

partial networking stack overhaul

  • a lot of coding style changes (comments, indentation, etc.)
  • convert several ints to unsigned ints or size_t values
  • streamline many of the IPC-related macros (they no longer dereference the call structure by themselves)
  • get rid of netif_interface.h (containing only aliases for remote functions and not serving any purpose)
  • rename netif_local.{c|h} to netif_skel.{c|h} (it is really just a skeleton)
  • drop the "_remote" and "_standalone" suffixes from most of the netif_ functions (they do not serve any purpose anymore)
  • implement netif_client_connection() as a common framework function for all netif modules
    • update the lo module accordingly
  • ip module now reports the default gateway to the user whenever it is being set
  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[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 <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]51typedef 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 */
64DEVICE_MAP_DECLARE(netif_device_map, netif_device_t);
65
[42a9f27]66/** Network interface module skeleton global data. */
[14f1db0]67typedef 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
73extern netif_globals_t netif_globals;
74
75/** Initialize the specific module.
76 *
77 * This function has to be implemented in user code.
[774e6d1a]78 *
[14f1db0]79 */
80extern int netif_initialize(void);
81
82/** Probe the existence of the device.
83 *
84 * This has to be implemented in user code.
85 *
[774e6d1a]86 * @param[in] device_id Device identifier.
87 * @param[in] irq Device interrupt number.
88 * @param[in] io Device input/output address.
89 *
90 * @return EOK on success.
91 * @return Other error codes as defined for the find_device()
92 * function.
93 * @return Other error codes as defined for the specific module
94 * message implementation.
[14f1db0]95 *
96 */
[774e6d1a]97extern int netif_probe_message(device_id_t device_id, int irq, void *io);
[14f1db0]98
99/** Send the packet queue.
100 *
101 * This has to be implemented in user code.
102 *
[774e6d1a]103 * @param[in] device_id Device identifier.
104 * @param[in] packet Packet queue.
105 * @param[in] sender Sending module service.
106 *
107 * @return EOK on success.
108 * @return EFORWARD if the device is not active (in the
109 * NETIF_ACTIVE state).
110 * @return Other error codes as defined for the find_device()
111 * function.
112 * @return Other error codes as defined for the specific module
113 * message implementation.
114 *
[14f1db0]115 */
[46d4d9f]116extern int netif_send_message(device_id_t device_id, packet_t *packet,
[14f1db0]117 services_t sender);
118
119/** Start the device.
120 *
121 * This has to be implemented in user code.
122 *
[774e6d1a]123 * @param[in] device Device structure.
124 *
125 * @return New network interface state (non-negative values).
126 * @return Other error codes as defined for the find_device()
127 * function.
128 * @return Other error codes as defined for the specific module
129 * message implementation.
130
[14f1db0]131 *
132 */
133extern int netif_start_message(netif_device_t *device);
134
135/** Stop the device.
136 *
137 * This has to be implemented in user code.
138 *
[774e6d1a]139 * @param[in] device Device structure.
140 *
141 * @return EOK on success.
142 * @return Other error codes as defined for the find_device()
143 * function.
144 * @return Other error codes as defined for the specific module
145 * message implementation.
[14f1db0]146 *
147 */
148extern int netif_stop_message(netif_device_t *device);
149
150/** Return the device local hardware address.
151 *
152 * This has to be implemented in user code.
153 *
[774e6d1a]154 * @param[in] device_id Device identifier.
155 * @param[out] address Device local hardware address.
156 *
157 * @return EOK on success.
158 * @return EBADMEM if the address parameter is NULL.
159 * @return ENOENT if there no such device.
160 * @return Other error codes as defined for the find_device()
161 * function.
162 * @return Other error codes as defined for the specific module
163 * message implementation.
[14f1db0]164 *
165 */
166extern int netif_get_addr_message(device_id_t device_id,
[4eca056]167 measured_string_t *address);
[14f1db0]168
169/** Process the netif driver specific message.
170 *
171 * This function is called for uncommon messages received by the netif
172 * skeleton. This has to be implemented in user code.
173 *
[774e6d1a]174 * @param[in] callid Message identifier.
175 * @param[in] call Message.
176 * @param[out] answer Answer.
177 * @param[out] count Number of answer arguments.
178 *
179 * @return EOK on success.
180 * @return ENOTSUP if the message is not known.
181 * @return Other error codes as defined for the specific module
182 * message implementation.
[14f1db0]183 *
184 */
185extern int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
[774e6d1a]186 ipc_call_t *answer, size_t *count);
[14f1db0]187
188/** Return the device usage statistics.
189 *
190 * This has to be implemented in user code.
191 *
[774e6d1a]192 * @param[in] device_id Device identifier.
193 * @param[out] stats Device usage statistics.
194 *
195 * @return EOK on success.
196 * @return Other error codes as defined for the find_device()
197 * function.
198 * @return Other error codes as defined for the specific module
199 * message implementation.
[14f1db0]200 *
201 */
202extern int netif_get_device_stats(device_id_t device_id,
[f772bc55]203 device_stats_t *stats);
[14f1db0]204
205extern int find_device(device_id_t, netif_device_t **);
[f772bc55]206extern void null_device_stats(device_stats_t *);
[14f1db0]207extern void netif_pq_release(packet_id_t);
[46d4d9f]208extern packet_t *netif_packet_get_1(size_t);
[14f1db0]209
[774e6d1a]210extern int netif_module_start(void);
[14f1db0]211
212#endif
213
214/** @}
215 */
Note: See TracBrowser for help on using the repository browser.