source: rtems/cpukit/libnetworking/rtems/rtems_bsdnet.h @ 4ab3a29

4.104.114.84.95
Last change on this file since 4ab3a29 was 4ab3a29, checked in by Joel Sherrill <joel.sherrill@…>, on 06/21/07 at 15:32:37

2007-06-21 Joel Sherrill <joel.sherrill@…>

  • libnetworking/rtems/mkrootfs.h, libnetworking/rtems/rtems_bsdnet.h, libnetworking/rtems/rtems_bsdnet_internal.h: Add extern cplusplus.
  • Property mode set to 100644
File size: 7.9 KB
Line 
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
13extern "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 */
45extern struct in_addr rtems_bsdnet_bootp_server_address;
46extern char *rtems_bsdnet_bootp_server_name;
47extern char *rtems_bsdnet_bootp_boot_file_name;
48extern char *rtems_bsdnet_bootp_cmdline;
49extern int32_t rtems_bsdnet_timeoffset;
50
51/*
52 * Manipulate routing tables
53 */
54struct sockaddr;
55struct rtentry;
56int 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 */
67void rtems_bsdnet_show_inet_routes (void);
68void rtems_bsdnet_show_mbuf_stats (void);
69void rtems_bsdnet_show_if_stats (void);
70void rtems_bsdnet_show_ip_stats (void);
71void rtems_bsdnet_show_icmp_stats (void);
72void rtems_bsdnet_show_udp_stats (void);
73void rtems_bsdnet_show_tcp_stats (void);
74
75/*
76 * Network configuration
77 */
78struct 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
131struct 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
159/*
160 * Default global device configuration structure. This is scanned
161 * by the initialize network function. Check the network demo's for
162 * an example of the structure. Like the RTEMS configuration tables,
163 * they are not part of RTEMS but part of your application or bsp
164 * code.
165 */
166extern struct rtems_bsdnet_config rtems_bsdnet_config;
167
168/*
169 * Initialise the BSD stack, attach and `up' interfaces
170 * in the `rtems_bsdnet_config'. RTEMS must already be initialised.
171 */
172int rtems_bsdnet_initialize_network (void);
173
174/*
175 * Dynamic interface control. Drivers must free any resources such as
176 * memory, interrupts, io regions claimed during the `attach' and/or
177 * `up' operations when asked to `detach'.
178 * You must configure the interface after attaching it.
179 */
180void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifconfig);
181void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig);
182
183/*
184 * Interface configuration. The commands are listed in `sys/sockio.h'.
185 */
186int rtems_bsdnet_ifconfig (const char *ifname, uint32_t   cmd, void *param);
187
188void rtems_bsdnet_do_bootp (void);
189void rtems_bsdnet_do_bootp_and_rootfs (void);
190
191/* NTP tuning parameters */
192extern int rtems_bsdnet_ntp_retry_count;
193extern int rtems_bsdnet_ntp_timeout_secs;
194extern int rtems_bsdnet_ntp_bcast_timeout_secs;
195
196
197struct timestamp {
198        uint32_t        integer;
199        uint32_t        fraction;
200};
201
202/* Data is passed in network byte order */
203struct ntpPacketSmall {
204        uint8_t         li_vn_mode;
205        uint8_t         stratum;
206        int8_t          poll_interval;
207        int8_t          precision;
208        int32_t         root_delay;
209        int32_t         root_dispersion;
210        char                    reference_identifier[4];
211        struct timestamp        reference_timestamp;
212        struct timestamp        originate_timestamp;
213        struct timestamp        receive_timestamp;
214        struct timestamp        transmit_timestamp;
215};
216
217/* NOTE: packet data is *only* accessible from the callback
218 *
219 * 'callback' is invoked twice, once prior to sending a request
220 * to the server and one more time after receiving a valid reply.
221 * This allows for the user to measure round-trip times.
222 *
223 * Semantics of the 'state' parameter:
224 *
225 *    state ==  1:  1st call, just prior to sending request. The
226 *                  packet has been set up already but may be
227 *                  modified by the callback (e.g. to set the originate
228 *                  timestamp).
229 *    state == -1:  1st call - no request will be sent but we'll
230 *                  wait for a reply from a broadcast server. The
231 *                  packet has not been set up.
232 *    state ==  0:  2nd call. The user is responsible for keeping track
233 *                  of the 'state' during the first call in order to
234 *                  know if it makes sense to calculate 'round-trip' times.
235 *
236 * RETURN VALUE: the callback should return 0 if processing the packet was
237 *               successful and -1 on error in which case rtems_bsdnet_get_ntp()
238 *                               may try another server.
239 */
240typedef int (*rtems_bsdnet_ntp_callback_t)(
241        struct ntpPacketSmall  *packet,
242        int                     state,
243        void                   *usr_data);
244
245/* Obtain time from a NTP server and call user callback to process data;
246 * socket parameter may be -1 to request the routine to open and close its own socket.
247 * Networking parameters as configured are used...
248 *
249 * It is legal to pass a NULL callback pointer. In this case, a default callback
250 * is used which determines the current time by contacting an NTP server. The current
251 * time is converted to a 'struct timespec' (seconds/nanoseconds) and passed into *usr_data.
252 * The caller is responsible for providing a memory area >= sizeof(struct timespec).
253 *
254 * RETURNS: 0 on success, -1 on failure.
255 */
256int rtems_bsdnet_get_ntp(int socket, rtems_bsdnet_ntp_callback_t callback, void *usr_data);
257
258int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority);
259
260/*
261 * Callback to report BSD malloc starvation.
262 * The default implementation just prints a message but an application
263 * can provide its own version.
264 */
265void rtems_bsdnet_malloc_starvation(void);
266
267/*
268 * mbuf malloc interface to enable custom allocation of mbuf's
269 *
270 * May be declared in user code.  If not, then the default is to
271 * malloc.
272 */
273void* rtems_bsdnet_malloc_mbuf(size_t size, int type);
274
275/*
276 * Possible values of the type parameter to rtems_bsdnet_malloc_mbuf to assist
277 * in allocation of the structure.
278 */
279#define MBUF_MALLOC_NMBCLUSTERS (0)
280#define MBUF_MALLOC_MCLREFCNT   (1)
281#define MBUF_MALLOC_MBUF        (2)
282
283#ifdef __cplusplus
284}
285#endif
286
287#endif /* _RTEMS_BSDNET_H */
Note: See TracBrowser for help on using the repository browser.