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 libnet
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file
|
---|
34 | * Network interface module skeleton.
|
---|
35 | * The skeleton has to be part of each network interface module.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef NET_NETIF_LOCAL_H_
|
---|
39 | #define NET_NETIF_LOCAL_H_
|
---|
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>
|
---|
47 | #include <net/device.h>
|
---|
48 | #include <net/packet.h>
|
---|
49 |
|
---|
50 | /** Network interface device specific data. */
|
---|
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 |
|
---|
66 | /** Network interface module skeleton global data. */
|
---|
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 | *
|
---|
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.
|
---|
88 | *
|
---|
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.
|
---|
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 | *
|
---|
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.
|
---|
112 | */
|
---|
113 | extern int netif_send_message(device_id_t device_id, packet_t *packet,
|
---|
114 | services_t sender);
|
---|
115 |
|
---|
116 | /** Start the device.
|
---|
117 | *
|
---|
118 | * This has to be implemented in user code.
|
---|
119 | *
|
---|
120 | * @param[in] device The device structure.
|
---|
121 | *
|
---|
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.
|
---|
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 | *
|
---|
134 | * @param[in] device The device structure.
|
---|
135 | *
|
---|
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.
|
---|
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 | *
|
---|
148 | * @param[in] device_id The device identifier.
|
---|
149 | * @param[out] address The device local hardware address.
|
---|
150 | *
|
---|
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.
|
---|
158 | */
|
---|
159 | extern int netif_get_addr_message(device_id_t device_id,
|
---|
160 | measured_string_t *address);
|
---|
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 | *
|
---|
167 | * @param[in] callid The message identifier.
|
---|
168 | * @param[in] call The message parameters.
|
---|
169 | * @param[out] answer The message answer parameters.
|
---|
170 | * @param[out] answer_count The last parameter for the actual answer in
|
---|
171 | * the answer parameter.
|
---|
172 | *
|
---|
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.
|
---|
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 | *
|
---|
185 | * @param[in] device_id The device identifier.
|
---|
186 | * @param[out] stats The device usage statistics.
|
---|
187 | *
|
---|
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.
|
---|
193 | */
|
---|
194 | extern int netif_get_device_stats(device_id_t device_id,
|
---|
195 | device_stats_t *stats);
|
---|
196 |
|
---|
197 | extern int netif_get_addr_req_local(int, device_id_t, measured_string_t **,
|
---|
198 | char **);
|
---|
199 | extern int netif_probe_req_local(int, device_id_t, int, int);
|
---|
200 | extern int netif_send_msg_local(int, device_id_t, packet_t *, services_t);
|
---|
201 | extern int netif_start_req_local(int, device_id_t);
|
---|
202 | extern int netif_stop_req_local(int, device_id_t);
|
---|
203 | extern int netif_stats_req_local(int, device_id_t, device_stats_t *);
|
---|
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 **);
|
---|
208 | extern void null_device_stats(device_stats_t *);
|
---|
209 | extern void netif_pq_release(packet_id_t);
|
---|
210 | extern packet_t *netif_packet_get_1(size_t);
|
---|
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 | */
|
---|