1 | /** |
---|
2 | * @file rtems/rtems_bsdnet.h |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * $Id$ |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef _RTEMS_BSDNET_H |
---|
10 | #define _RTEMS_BSDNET_H |
---|
11 | |
---|
12 | #ifdef __cplusplus |
---|
13 | extern "C" { |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems.h> |
---|
17 | |
---|
18 | /* |
---|
19 | * If this file is included from inside the Network Stack proper or |
---|
20 | * a device driver, then __INSIDE_RTEMS_BSD_TCPIP_STACK__ should be |
---|
21 | * defined. This triggers a number of internally used definitions. |
---|
22 | */ |
---|
23 | |
---|
24 | #if defined(__INSIDE_RTEMS_BSD_TCPIP_STACK__) |
---|
25 | #undef _COMPILING_BSD_KERNEL_ |
---|
26 | #undef _KERNEL |
---|
27 | #undef INET |
---|
28 | #undef NFS |
---|
29 | #undef DIAGNOSTIC |
---|
30 | #undef BOOTP_COMPAT |
---|
31 | #undef __BSD_VISIBLE |
---|
32 | |
---|
33 | #define _COMPILING_BSD_KERNEL_ |
---|
34 | #define _KERNEL |
---|
35 | #define INET |
---|
36 | #define NFS |
---|
37 | #define DIAGNOSTIC |
---|
38 | #define BOOTP_COMPAT |
---|
39 | #define __BSD_VISIBLE 1 |
---|
40 | #endif |
---|
41 | |
---|
42 | /* |
---|
43 | * Values that may be obtained by BOOTP |
---|
44 | */ |
---|
45 | extern struct in_addr rtems_bsdnet_bootp_server_address; |
---|
46 | extern char *rtems_bsdnet_bootp_server_name; |
---|
47 | extern char *rtems_bsdnet_bootp_boot_file_name; |
---|
48 | extern char *rtems_bsdnet_bootp_cmdline; |
---|
49 | extern int32_t rtems_bsdnet_timeoffset; |
---|
50 | |
---|
51 | /* |
---|
52 | * Manipulate routing tables |
---|
53 | */ |
---|
54 | struct sockaddr; |
---|
55 | struct rtentry; |
---|
56 | int rtems_bsdnet_rtrequest ( |
---|
57 | int req, |
---|
58 | struct sockaddr *dst, |
---|
59 | struct sockaddr *gateway, |
---|
60 | struct sockaddr *netmask, |
---|
61 | int flags, |
---|
62 | struct rtentry **net_nrt); |
---|
63 | |
---|
64 | /* |
---|
65 | * Diagnostics |
---|
66 | */ |
---|
67 | void rtems_bsdnet_show_inet_routes (void); |
---|
68 | void rtems_bsdnet_show_mbuf_stats (void); |
---|
69 | void rtems_bsdnet_show_if_stats (void); |
---|
70 | void rtems_bsdnet_show_ip_stats (void); |
---|
71 | void rtems_bsdnet_show_icmp_stats (void); |
---|
72 | void rtems_bsdnet_show_udp_stats (void); |
---|
73 | void rtems_bsdnet_show_tcp_stats (void); |
---|
74 | |
---|
75 | /* |
---|
76 | * Network configuration |
---|
77 | */ |
---|
78 | struct rtems_bsdnet_ifconfig { |
---|
79 | /* |
---|
80 | * These three entries must be supplied for each interface. |
---|
81 | */ |
---|
82 | char *name; |
---|
83 | |
---|
84 | /* |
---|
85 | * This function now handles attaching and detaching an interface. |
---|
86 | * The parameter attaching indicates the operation being invoked. |
---|
87 | * For older attach functions which do not have the extra parameter |
---|
88 | * it will be ignored. |
---|
89 | */ |
---|
90 | int (*attach)(struct rtems_bsdnet_ifconfig *conf, int attaching); |
---|
91 | |
---|
92 | /* |
---|
93 | * Link to next interface |
---|
94 | */ |
---|
95 | struct rtems_bsdnet_ifconfig *next; |
---|
96 | |
---|
97 | /* |
---|
98 | * The following entries may be obtained |
---|
99 | * from BOOTP or explicitily supplied. |
---|
100 | */ |
---|
101 | char *ip_address; |
---|
102 | char *ip_netmask; |
---|
103 | void *hardware_address; |
---|
104 | |
---|
105 | /* |
---|
106 | * The driver assigns defaults values to the following |
---|
107 | * entries if they are not explicitly supplied. |
---|
108 | */ |
---|
109 | int ignore_broadcast; |
---|
110 | int mtu; |
---|
111 | int rbuf_count; |
---|
112 | int xbuf_count; |
---|
113 | |
---|
114 | /* |
---|
115 | * For external ethernet controller board the following |
---|
116 | * parameters are needed |
---|
117 | */ |
---|
118 | unsigned int port; /* port of the board */ |
---|
119 | unsigned int irno; /* irq of the board */ |
---|
120 | unsigned int bpar; /* memory of the board */ |
---|
121 | |
---|
122 | /* |
---|
123 | * Driver control block pointer. Typcially this points to the driver's |
---|
124 | * controlling structure. You set this when you have the structure allocated |
---|
125 | * externally to the driver. |
---|
126 | */ |
---|
127 | void *drv_ctrl; |
---|
128 | |
---|
129 | }; |
---|
130 | |
---|
131 | struct rtems_bsdnet_config { |
---|
132 | /* |
---|
133 | * This entry points to the head of the ifconfig chain. |
---|
134 | */ |
---|
135 | struct rtems_bsdnet_ifconfig *ifconfig; |
---|
136 | |
---|
137 | /* |
---|
138 | * This entry should be rtems_bsdnet_do_bootp if BOOTP |
---|
139 | * is being used to configure the network, and NULL |
---|
140 | * if BOOTP is not being used. |
---|
141 | */ |
---|
142 | void (*bootp)(void); |
---|
143 | |
---|
144 | /* |
---|
145 | * The remaining items can be initialized to 0, in |
---|
146 | * which case the default value will be used. |
---|
147 | */ |
---|
148 | rtems_task_priority network_task_priority; /* 100 */ |
---|
149 | unsigned long mbuf_bytecount; /* 64 kbytes */ |
---|
150 | unsigned long mbuf_cluster_bytecount; /* 128 kbytes */ |
---|
151 | char *hostname; /* BOOTP */ |
---|
152 | char *domainname; /* BOOTP */ |
---|
153 | char *gateway; /* BOOTP */ |
---|
154 | char *log_host; /* BOOTP */ |
---|
155 | char *name_server[3]; /* BOOTP */ |
---|
156 | char *ntp_server[3]; /* BOOTP */ |
---|
157 | /* |
---|
158 | * Default "multiplier" on buffer size. This is |
---|
159 | * claimed by the TCP/IP implementation to be for |
---|
160 | * efficiency but you will have to measure the |
---|
161 | * benefit for buffering beyond double buffering |
---|
162 | * in your own application. |
---|
163 | * |
---|
164 | * The default value is 2. |
---|
165 | * |
---|
166 | * See kern/uipc_socket2.c for details. |
---|
167 | */ |
---|
168 | unsigned long sb_efficiency; |
---|
169 | /* |
---|
170 | * Default UDP buffer sizes PER SOCKET!! |
---|
171 | * |
---|
172 | * TX = 9216 -- max datagram size |
---|
173 | * RX = 40 * (1024 + sizeof(struct sockaddr_in)) |
---|
174 | * |
---|
175 | * See netinet/udp_usrreq.c for details |
---|
176 | */ |
---|
177 | unsigned long udp_tx_buf_size; |
---|
178 | unsigned long udp_rx_buf_size; |
---|
179 | /* |
---|
180 | * Default UDP buffer sizes PER SOCKET!! |
---|
181 | * |
---|
182 | * TX = 16 * 1024 |
---|
183 | * RX = 16 * 1024 |
---|
184 | * |
---|
185 | * See netinet/tcp_usrreq.c for details |
---|
186 | */ |
---|
187 | unsigned long tcp_tx_buf_size; |
---|
188 | unsigned long tcp_rx_buf_size; |
---|
189 | }; |
---|
190 | |
---|
191 | /* |
---|
192 | * Default global device configuration structure. This is scanned |
---|
193 | * by the initialize network function. Check the network demo's for |
---|
194 | * an example of the structure. Like the RTEMS configuration tables, |
---|
195 | * they are not part of RTEMS but part of your application or bsp |
---|
196 | * code. |
---|
197 | */ |
---|
198 | extern struct rtems_bsdnet_config rtems_bsdnet_config; |
---|
199 | |
---|
200 | /* |
---|
201 | * Initialise the BSD stack, attach and `up' interfaces |
---|
202 | * in the `rtems_bsdnet_config'. RTEMS must already be initialised. |
---|
203 | */ |
---|
204 | int rtems_bsdnet_initialize_network (void); |
---|
205 | |
---|
206 | /* |
---|
207 | * Dynamic interface control. Drivers must free any resources such as |
---|
208 | * memory, interrupts, io regions claimed during the `attach' and/or |
---|
209 | * `up' operations when asked to `detach'. |
---|
210 | * You must configure the interface after attaching it. |
---|
211 | */ |
---|
212 | void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifconfig); |
---|
213 | void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig); |
---|
214 | |
---|
215 | /* |
---|
216 | * Interface configuration. The commands are listed in `sys/sockio.h'. |
---|
217 | */ |
---|
218 | int rtems_bsdnet_ifconfig (const char *ifname, uint32_t cmd, void *param); |
---|
219 | |
---|
220 | void rtems_bsdnet_do_bootp (void); |
---|
221 | void rtems_bsdnet_do_bootp_and_rootfs (void); |
---|
222 | |
---|
223 | /* NTP tuning parameters */ |
---|
224 | extern int rtems_bsdnet_ntp_retry_count; |
---|
225 | extern int rtems_bsdnet_ntp_timeout_secs; |
---|
226 | extern int rtems_bsdnet_ntp_bcast_timeout_secs; |
---|
227 | |
---|
228 | |
---|
229 | struct timestamp { |
---|
230 | uint32_t integer; |
---|
231 | uint32_t fraction; |
---|
232 | }; |
---|
233 | |
---|
234 | /* Data is passed in network byte order */ |
---|
235 | struct ntpPacketSmall { |
---|
236 | uint8_t li_vn_mode; |
---|
237 | uint8_t stratum; |
---|
238 | int8_t poll_interval; |
---|
239 | int8_t precision; |
---|
240 | int32_t root_delay; |
---|
241 | int32_t root_dispersion; |
---|
242 | char reference_identifier[4]; |
---|
243 | struct timestamp reference_timestamp; |
---|
244 | struct timestamp originate_timestamp; |
---|
245 | struct timestamp receive_timestamp; |
---|
246 | struct timestamp transmit_timestamp; |
---|
247 | }; |
---|
248 | |
---|
249 | /* NOTE: packet data is *only* accessible from the callback |
---|
250 | * |
---|
251 | * 'callback' is invoked twice, once prior to sending a request |
---|
252 | * to the server and one more time after receiving a valid reply. |
---|
253 | * This allows for the user to measure round-trip times. |
---|
254 | * |
---|
255 | * Semantics of the 'state' parameter: |
---|
256 | * |
---|
257 | * state == 1: 1st call, just prior to sending request. The |
---|
258 | * packet has been set up already but may be |
---|
259 | * modified by the callback (e.g. to set the originate |
---|
260 | * timestamp). |
---|
261 | * state == -1: 1st call - no request will be sent but we'll |
---|
262 | * wait for a reply from a broadcast server. The |
---|
263 | * packet has not been set up. |
---|
264 | * state == 0: 2nd call. The user is responsible for keeping track |
---|
265 | * of the 'state' during the first call in order to |
---|
266 | * know if it makes sense to calculate 'round-trip' times. |
---|
267 | * |
---|
268 | * RETURN VALUE: the callback should return 0 if processing the packet was |
---|
269 | * successful and -1 on error in which case rtems_bsdnet_get_ntp() |
---|
270 | * may try another server. |
---|
271 | */ |
---|
272 | typedef int (*rtems_bsdnet_ntp_callback_t)( |
---|
273 | struct ntpPacketSmall *packet, |
---|
274 | int state, |
---|
275 | void *usr_data); |
---|
276 | |
---|
277 | /* Obtain time from a NTP server and call user callback to process data; |
---|
278 | * socket parameter may be -1 to request the routine to open and close its own socket. |
---|
279 | * Networking parameters as configured are used... |
---|
280 | * |
---|
281 | * It is legal to pass a NULL callback pointer. In this case, a default callback |
---|
282 | * is used which determines the current time by contacting an NTP server. The current |
---|
283 | * time is converted to a 'struct timespec' (seconds/nanoseconds) and passed into *usr_data. |
---|
284 | * The caller is responsible for providing a memory area >= sizeof(struct timespec). |
---|
285 | * |
---|
286 | * RETURNS: 0 on success, -1 on failure. |
---|
287 | */ |
---|
288 | int rtems_bsdnet_get_ntp(int socket, rtems_bsdnet_ntp_callback_t callback, void *usr_data); |
---|
289 | |
---|
290 | int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority); |
---|
291 | |
---|
292 | /* |
---|
293 | * Callback to report BSD malloc starvation. |
---|
294 | * The default implementation just prints a message but an application |
---|
295 | * can provide its own version. |
---|
296 | */ |
---|
297 | void rtems_bsdnet_malloc_starvation(void); |
---|
298 | |
---|
299 | /* |
---|
300 | * mbuf malloc interface to enable custom allocation of mbuf's |
---|
301 | * |
---|
302 | * May be declared in user code. If not, then the default is to |
---|
303 | * malloc. |
---|
304 | */ |
---|
305 | void* rtems_bsdnet_malloc_mbuf(size_t size, int type); |
---|
306 | |
---|
307 | /* |
---|
308 | * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist |
---|
309 | * in allocation of the structure. |
---|
310 | */ |
---|
311 | #define MBUF_MALLOC_NMBCLUSTERS (0) |
---|
312 | #define MBUF_MALLOC_MCLREFCNT (1) |
---|
313 | #define MBUF_MALLOC_MBUF (2) |
---|
314 | |
---|
315 | #ifdef __cplusplus |
---|
316 | } |
---|
317 | #endif |
---|
318 | |
---|
319 | #endif /* _RTEMS_BSDNET_H */ |
---|