source: rtems/cpukit/libnetworking/rtems/rtems_bsdnet.h @ 3f10bb3

4.104.114.84.95
Last change on this file since 3f10bb3 was c58c2ca, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/02/05 at 10:11:10

New header guards.

  • Property mode set to 100644
File size: 7.5 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#include <rtems.h>
13
14/*
15 *  If this file is included from inside the Network Stack proper or
16 *  a device driver, then __INSIDE_RTEMS_BSD_TCPIP_STACK__ should be
17 *  defined.  This triggers a number of internally used definitions.
18 */
19
20#if defined(__INSIDE_RTEMS_BSD_TCPIP_STACK__)
21#undef _COMPILING_BSD_KERNEL_
22#undef _KERNEL
23#undef INET
24#undef NFS
25#undef DIAGNOSTIC
26#undef BOOTP_COMPAT
27
28#define _COMPILING_BSD_KERNEL_
29#define _KERNEL
30#define INET
31#define NFS
32#define DIAGNOSTIC
33#define BOOTP_COMPAT
34#endif
35
36/*
37 * Values that may be obtained by BOOTP
38 */
39extern struct in_addr rtems_bsdnet_bootp_server_address;
40extern char *rtems_bsdnet_bootp_server_name;
41extern char *rtems_bsdnet_bootp_boot_file_name;
42extern char *rtems_bsdnet_bootp_cmdline;
43extern struct in_addr rtems_bsdnet_ntpserver[];
44extern int rtems_bsdnet_ntpserver_count;
45extern long 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
155/*
156 * Default global device configuration structure. This is scanned
157 * by the initialize network function. Check the network demo's for
158 * an example of the structure. Like the RTEMS configuration tables,
159 * they are not part of RTEMS but part of your application or bsp
160 * code.
161 */
162extern struct rtems_bsdnet_config rtems_bsdnet_config;
163
164/*
165 * Initialise the BSD stack, attach and `up' interfaces
166 * in the `rtems_bsdnet_config'. RTEMS must already be initialised.
167 */
168int rtems_bsdnet_initialize_network (void);
169
170/*
171 * Dynamic interface control. Drivers must free any resources such as
172 * memory, interrupts, io regions claimed during the `attach' and/or
173 * `up' operations when asked to `detach'.
174 * You must configure the interface after attaching it.
175 */
176void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifconfig);
177void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig);
178
179/*
180 * Interface configuration. The commands are listed in `sys/sockio.h'.
181 */
182int rtems_bsdnet_ifconfig (const char *ifname, uint32_t   cmd, void *param);
183
184void rtems_bsdnet_do_bootp (void);
185void rtems_bsdnet_do_bootp_and_rootfs (void);
186
187/* NTP tuning parameters */
188extern int rtems_bsdnet_ntp_retry_count;
189extern int rtems_bsdnet_ntp_timeout_secs;
190extern int rtems_bsdnet_ntp_bcast_timeout_secs;
191
192
193struct timestamp {
194        rtems_unsigned32        integer;
195        rtems_unsigned32        fraction;
196};
197
198/* Data is passed in network byte order */
199struct ntpPacketSmall {
200        rtems_unsigned8         li_vn_mode;
201        rtems_unsigned8         stratum;
202        rtems_signed8           poll_interval;
203        rtems_signed8           precision;
204        rtems_signed32          root_delay;
205        rtems_signed32          root_dispersion;
206        char                    reference_identifier[4];
207        struct timestamp        reference_timestamp;
208        struct timestamp        originate_timestamp;
209        struct timestamp        receive_timestamp;
210        struct timestamp        transmit_timestamp;
211};
212
213/* NOTE: packet data is *only* accessible from the callback
214 *
215 * 'callback' is invoked twice, once prior to sending a request
216 * to the server and one more time after receiving a valid reply.
217 * This allows for the user to measure round-trip times.
218 *
219 * Semantics of the 'state' parameter:
220 *
221 *    state ==  1:  1st call, just prior to sending request. The
222 *                  packet has been set up already but may be
223 *                  modified by the callback (e.g. to set the originate
224 *                  timestamp).
225 *    state == -1:  1st call - no request will be sent but we'll
226 *                  wait for a reply from a broadcast server. The
227 *                  packet has not been set up.
228 *    state ==  0:  2nd call. The user is responsible for keeping track
229 *                  of the 'state' during the first call in order to
230 *                  know if it makes sense to calculate 'round-trip' times.
231 *
232 * RETURN VALUE: the callback should return 0 if processing the packet was
233 *               successful and -1 on error in which case rtems_bsdnet_get_ntp()
234 *                               may try another server.
235 */
236typedef int (*rtems_bsdnet_ntp_callback_t)(
237        struct ntpPacketSmall  *packet,
238        int                     state,
239        void                   *usr_data);
240
241/* Obtain time from a NTP server and call user callback to process data;
242 * socket parameter may be -1 to request the routine to open and close its own socket.
243 * Networking parameters as configured are used...
244 *
245 * It is legal to pass a NULL callback pointer. In this case, a default callback
246 * is used which determines the current time by contacting an NTP server. The current
247 * time is converted to a 'struct timespec' (seconds/nanoseconds) and passed into *usr_data.
248 * The caller is responsible for providing a memory area >= sizeof(struct timespec).
249 *
250 * RETURNS: 0 on success, -1 on failure.
251 */
252int rtems_bsdnet_get_ntp(int socket, rtems_bsdnet_ntp_callback_t callback, void *usr_data);
253
254int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority);
255
256/*
257 * Callback to report BSD malloc starvation.
258 * The default implementation just prints a message but an application
259 * can provide its own version.
260 */
261void rtems_bsdnet_malloc_starvation(void);
262
263#endif /* _RTEMS_BSDNET_H */
Note: See TracBrowser for help on using the repository browser.