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