source: rtems/cpukit/libnetworking/rtems/rtems_bsdnet.h @ 8d2733f

4.104.114.84.95
Last change on this file since 8d2733f was 8d2733f, checked in by Joel Sherrill <joel.sherrill@…>, on 07/25/04 at 15:04:13

2004-07-25 Till Straumann <strauman@…>

PR 620/networking

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