source: rtems/cpukit/libnetworking/rtems/rtems_bsdnet.h @ e79a0ca7

5
Last change on this file since e79a0ca7 was e79a0ca7, checked in by Sebastian Huber <sebastian.huber@…>, on 06/28/16 at 05:50:59

libnetworking: Move RTEMS-specific socket wake-up

Close #2748.

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