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_SKEL_H_
|
---|
39 | #define NET_NETIF_SKEL_H_
|
---|
40 |
|
---|
41 | #include <async.h>
|
---|
42 | #include <fibril_synch.h>
|
---|
43 | #include <ipc/services.h>
|
---|
44 |
|
---|
45 | #include <adt/measured_strings.h>
|
---|
46 | #include <net/device.h>
|
---|
47 | #include <net/packet.h>
|
---|
48 |
|
---|
49 | /** Network interface device specific data. */
|
---|
50 | typedef struct {
|
---|
51 | device_id_t device_id; /**< Device identifier. */
|
---|
52 | int nil_phone; /**< Receiving network interface layer phone. */
|
---|
53 | device_state_t state; /**< Actual device state. */
|
---|
54 | void *specific; /**< Driver specific data. */
|
---|
55 | } netif_device_t;
|
---|
56 |
|
---|
57 | /** Device map.
|
---|
58 | *
|
---|
59 | * Maps device identifiers to the network interface device specific data.
|
---|
60 | * @see device.h
|
---|
61 | *
|
---|
62 | */
|
---|
63 | DEVICE_MAP_DECLARE(netif_device_map, netif_device_t);
|
---|
64 |
|
---|
65 | /** Network interface module skeleton global data. */
|
---|
66 | typedef struct {
|
---|
67 | int net_phone; /**< Networking module phone. */
|
---|
68 | netif_device_map_t device_map; /**< Device map. */
|
---|
69 | fibril_rwlock_t lock; /**< Safety lock. */
|
---|
70 | } netif_globals_t;
|
---|
71 |
|
---|
72 | extern netif_globals_t netif_globals;
|
---|
73 |
|
---|
74 | /** Initialize the specific module.
|
---|
75 | *
|
---|
76 | * This function has to be implemented in user code.
|
---|
77 | *
|
---|
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 Device identifier.
|
---|
86 | * @param[in] irq Device interrupt number.
|
---|
87 | * @param[in] io 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 | */
|
---|
96 | extern int netif_probe_message(device_id_t device_id, int irq, void *io);
|
---|
97 |
|
---|
98 | /** Send the packet queue.
|
---|
99 | *
|
---|
100 | * This has to be implemented in user code.
|
---|
101 | *
|
---|
102 | * @param[in] device_id Device identifier.
|
---|
103 | * @param[in] packet Packet queue.
|
---|
104 | * @param[in] sender Sending module service.
|
---|
105 | *
|
---|
106 | * @return EOK on success.
|
---|
107 | * @return EFORWARD if the device is not active (in the
|
---|
108 | * NETIF_ACTIVE state).
|
---|
109 | * @return Other error codes as defined for the find_device()
|
---|
110 | * function.
|
---|
111 | * @return Other error codes as defined for the specific module
|
---|
112 | * message implementation.
|
---|
113 | *
|
---|
114 | */
|
---|
115 | extern int netif_send_message(device_id_t device_id, packet_t *packet,
|
---|
116 | services_t sender);
|
---|
117 |
|
---|
118 | /** Start the device.
|
---|
119 | *
|
---|
120 | * This has to be implemented in user code.
|
---|
121 | *
|
---|
122 | * @param[in] device Device structure.
|
---|
123 | *
|
---|
124 | * @return New network interface state (non-negative values).
|
---|
125 | * @return Other error codes as defined for the find_device()
|
---|
126 | * function.
|
---|
127 | * @return Other error codes as defined for the specific module
|
---|
128 | * message implementation.
|
---|
129 |
|
---|
130 | *
|
---|
131 | */
|
---|
132 | extern int netif_start_message(netif_device_t *device);
|
---|
133 |
|
---|
134 | /** Stop the device.
|
---|
135 | *
|
---|
136 | * This has to be implemented in user code.
|
---|
137 | *
|
---|
138 | * @param[in] device Device structure.
|
---|
139 | *
|
---|
140 | * @return EOK on success.
|
---|
141 | * @return Other error codes as defined for the find_device()
|
---|
142 | * function.
|
---|
143 | * @return Other error codes as defined for the specific module
|
---|
144 | * message implementation.
|
---|
145 | *
|
---|
146 | */
|
---|
147 | extern int netif_stop_message(netif_device_t *device);
|
---|
148 |
|
---|
149 | /** Return the device local hardware address.
|
---|
150 | *
|
---|
151 | * This has to be implemented in user code.
|
---|
152 | *
|
---|
153 | * @param[in] device_id Device identifier.
|
---|
154 | * @param[out] address Device local hardware address.
|
---|
155 | *
|
---|
156 | * @return EOK on success.
|
---|
157 | * @return EBADMEM if the address parameter is NULL.
|
---|
158 | * @return ENOENT if there no such device.
|
---|
159 | * @return Other error codes as defined for the find_device()
|
---|
160 | * function.
|
---|
161 | * @return Other error codes as defined for the specific module
|
---|
162 | * message implementation.
|
---|
163 | *
|
---|
164 | */
|
---|
165 | extern int netif_get_addr_message(device_id_t device_id,
|
---|
166 | measured_string_t *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 Message identifier.
|
---|
174 | * @param[in] call Message.
|
---|
175 | * @param[out] answer Answer.
|
---|
176 | * @param[out] count Number of answer arguments.
|
---|
177 | *
|
---|
178 | * @return EOK on success.
|
---|
179 | * @return ENOTSUP if the message is not known.
|
---|
180 | * @return Other error codes as defined for the specific module
|
---|
181 | * message implementation.
|
---|
182 | *
|
---|
183 | */
|
---|
184 | extern int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
|
---|
185 | ipc_call_t *answer, size_t *count);
|
---|
186 |
|
---|
187 | /** Return the device usage statistics.
|
---|
188 | *
|
---|
189 | * This has to be implemented in user code.
|
---|
190 | *
|
---|
191 | * @param[in] device_id Device identifier.
|
---|
192 | * @param[out] stats Device usage statistics.
|
---|
193 | *
|
---|
194 | * @return EOK on success.
|
---|
195 | * @return Other error codes as defined for the find_device()
|
---|
196 | * function.
|
---|
197 | * @return Other error codes as defined for the specific module
|
---|
198 | * message implementation.
|
---|
199 | *
|
---|
200 | */
|
---|
201 | extern int netif_get_device_stats(device_id_t device_id,
|
---|
202 | device_stats_t *stats);
|
---|
203 |
|
---|
204 | extern int find_device(device_id_t, netif_device_t **);
|
---|
205 | extern void null_device_stats(device_stats_t *);
|
---|
206 | extern void netif_pq_release(packet_id_t);
|
---|
207 | extern packet_t *netif_packet_get_1(size_t);
|
---|
208 |
|
---|
209 | extern int netif_module_start(void);
|
---|
210 |
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | /** @}
|
---|
214 | */
|
---|