1 | @c |
---|
2 | @c Written by Eric Norum |
---|
3 | @c |
---|
4 | @c COPYRIGHT (c) 1988-1998. |
---|
5 | @c On-Line Applications Research Corporation (OAR). |
---|
6 | @c All rights reserved. |
---|
7 | @c |
---|
8 | @c $Id$ |
---|
9 | @c |
---|
10 | |
---|
11 | @chapter Using Networking in an RTEMS Application |
---|
12 | |
---|
13 | @section Makefile changes |
---|
14 | @subsection Including the required managers |
---|
15 | The FreeBSD networking code requires several RTEMS managers |
---|
16 | in the application: |
---|
17 | |
---|
18 | @example |
---|
19 | MANAGERS = io event semaphore |
---|
20 | @end example |
---|
21 | |
---|
22 | @subsection Increasing the size of the heap |
---|
23 | The networking tasks allocate a lot of memory. For most applications |
---|
24 | the heap should be at least 256 kbytes. |
---|
25 | The amount of memory set aside for the heap can be adjusted by setting |
---|
26 | the @code{CFLAGS_LD} definition as shown below: |
---|
27 | |
---|
28 | @example |
---|
29 | CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0x80000 |
---|
30 | @end example |
---|
31 | |
---|
32 | This sets aside 512 kbytes of memory for the heap. |
---|
33 | |
---|
34 | @section System Configuration |
---|
35 | |
---|
36 | The networking tasks allocate some RTEMS objects. These |
---|
37 | must be accounted for in the application configuration table. The following |
---|
38 | lists the requirements. |
---|
39 | |
---|
40 | @table @b |
---|
41 | @item TASKS |
---|
42 | One network task plus a receive and transmit task for each device. |
---|
43 | |
---|
44 | @item SEMAPHORES |
---|
45 | One network semaphore plus one syslog mutex semaphore if the application uses |
---|
46 | openlog/syslog. |
---|
47 | |
---|
48 | @item EVENTS |
---|
49 | The network stack uses @code{RTEMS_EVENT_24} and @code{RTEMS_EVENT_25}. |
---|
50 | This has no effect on the application configuration, but |
---|
51 | application tasks which call the network functions should not |
---|
52 | use these events for other purposes. |
---|
53 | |
---|
54 | @end table |
---|
55 | |
---|
56 | @section Initialization |
---|
57 | @subsection Additional include files |
---|
58 | The source file which declares the network configuration |
---|
59 | structures and calls the network initialization function must include |
---|
60 | |
---|
61 | @example |
---|
62 | #include <rtems/rtems_bsdnet.h> |
---|
63 | @end example |
---|
64 | |
---|
65 | @subsection Network configuration |
---|
66 | The network configuration is specified by declaring |
---|
67 | and initializing the @code{rtems_bsdnet_configuration} |
---|
68 | structure. |
---|
69 | |
---|
70 | The structure entries are described in the following table. |
---|
71 | If your application uses BOOTP to obtain network configuration |
---|
72 | information and if you are happy with the default values described |
---|
73 | below, you need to provide only the first two entries in this structure. |
---|
74 | |
---|
75 | @table @code |
---|
76 | |
---|
77 | @item struct rtems_bsdnet_ifconfig *ifconfig |
---|
78 | A pointer to the first configuration structure of the first network |
---|
79 | device. This structure is described in the following section. |
---|
80 | You must provide a value for this entry since there is no default value for it. |
---|
81 | |
---|
82 | |
---|
83 | @item void (*bootp)(void) |
---|
84 | This entry should be set to @code{rtems_bsdnet_do_bootp} |
---|
85 | if your application will use BOOTP to obtain network configuration information. |
---|
86 | It should be set to @code{NULL} |
---|
87 | if your application does not use BOOTP. |
---|
88 | |
---|
89 | |
---|
90 | @item int network_task_priority |
---|
91 | The priority at which the network task and network device |
---|
92 | receive and transmit tasks will run. |
---|
93 | If a value of 0 is specified the tasks will run at priority 100. |
---|
94 | |
---|
95 | @item unsigned long mbuf_bytecount |
---|
96 | The number of bytes to allocate from the heap for use as mbufs. |
---|
97 | If a value of 0 is specified, 64 kbytes will be allocated. |
---|
98 | |
---|
99 | @item unsigned long mbuf_cluster_bytecount |
---|
100 | The number of bytes to allocate from the heap for use as mbuf clusters. |
---|
101 | If a value of 0 is specified, 128 kbytes will be allocated. |
---|
102 | |
---|
103 | @item char *hostname |
---|
104 | The host name of the system. |
---|
105 | If this, or any of the following, entries are @code{NULL} the value |
---|
106 | may be obtained from a BOOTP server. |
---|
107 | |
---|
108 | @item char *domainname |
---|
109 | The name of the Internet domain to which the system belongs. |
---|
110 | |
---|
111 | @item char *gateway |
---|
112 | The Internet host number of the network gateway machine, |
---|
113 | specified in `dotted decimal' (@code{129.128.4.1}) form. |
---|
114 | |
---|
115 | @item char *log_host |
---|
116 | The Internet host number of the machine to which @code{syslog} messages |
---|
117 | will be sent. |
---|
118 | |
---|
119 | @item char *name_server[3] |
---|
120 | The Internet host numbers of up to three machines to be used as |
---|
121 | Internet Domain Name Servers. |
---|
122 | |
---|
123 | @item int port |
---|
124 | The I/O port number (ex: 0x240) on which the external Ethernet |
---|
125 | can be accessed. |
---|
126 | |
---|
127 | @item int irno |
---|
128 | The interrupt number of the external Ethernet controller. |
---|
129 | |
---|
130 | @item int bpar |
---|
131 | The address of the shared memory on the external Ethernet controller. |
---|
132 | |
---|
133 | |
---|
134 | @end table |
---|
135 | |
---|
136 | @subsection Network device configuration |
---|
137 | Network devices are specified and configured by declaring and initializing a |
---|
138 | @code{struct rtems_bsdnet_ifcontig} structure for each network device. |
---|
139 | |
---|
140 | The structure entries are described in the following table. An application |
---|
141 | which uses a single network interface, gets network configuration information |
---|
142 | from a BOOTP server, and uses the default values for all driver |
---|
143 | parameters needs to initialize only the first two entries in the |
---|
144 | structure. |
---|
145 | |
---|
146 | @table @code |
---|
147 | @item char *name |
---|
148 | The full name of the network device. This name consists of the |
---|
149 | driver name and the unit number (e.g. @code{"scc1"}). |
---|
150 | The @code{bsp.h} include file usually defines RTEMS_BSP_NETWORK_DRIVER_NAME as |
---|
151 | the name of the primary (or only) network driver. |
---|
152 | |
---|
153 | @item int (*attach)(struct rtems_bsdnet_ifconfig *conf) |
---|
154 | The address of the driver @code{attach} function. The network |
---|
155 | initialization function calls this function to configure the driver and |
---|
156 | attach it to the network stack. |
---|
157 | The @code{bsp.h} include file usually defines RTEMS_BSP_NETWORK_DRIVER_ATTACH as |
---|
158 | the name of the attach function of the primary (or only) network driver. |
---|
159 | |
---|
160 | @item struct rtems_bsdnet_ifconfig *next |
---|
161 | A pointer to the network device configuration structure for the next network |
---|
162 | interface, or @code{NULL} if this is the configuration structure of the |
---|
163 | last network interface. |
---|
164 | |
---|
165 | @item char *ip_address |
---|
166 | The Internet address of the device, |
---|
167 | specified in `dotted decimal' (@code{129.128.4.2}) form, or @code{NULL} |
---|
168 | if the device configuration information is being obtained from a |
---|
169 | BOOTP server. |
---|
170 | |
---|
171 | @item char *ip_netmask |
---|
172 | The Internet inetwork mask of the device, |
---|
173 | specified in `dotted decimal' (@code{255.255.255.0}) form, or @code{NULL} |
---|
174 | if the device configuration information is being obtained from a |
---|
175 | BOOTP server. |
---|
176 | |
---|
177 | |
---|
178 | @item void *hardware_address |
---|
179 | The hardware address of the device, or @code{NULL} if the driver is |
---|
180 | to obtain the hardware address in some other way (usually by reading |
---|
181 | it from the device or from the bootstrap ROM). |
---|
182 | |
---|
183 | @item int ignore_broadcast |
---|
184 | Zero if the device is to accept broadcast packets, non-zero if the device |
---|
185 | is to ignore broadcast packets. |
---|
186 | |
---|
187 | @item int mtu |
---|
188 | The maximum transmission unit of the device, or zero if the driver |
---|
189 | is to choose a default value (typically 1500 for Ethernet devices). |
---|
190 | |
---|
191 | @item int rbuf_count |
---|
192 | The number of receive buffers to use, or zero if the driver is to |
---|
193 | choose a default value |
---|
194 | |
---|
195 | @item int xbuf_count |
---|
196 | The number of transmit buffers to use, or zero if the driver is to |
---|
197 | choose a default value |
---|
198 | Keep in mind that some network devices may use 4 or more |
---|
199 | transmit descriptors for a single transmit buffer. |
---|
200 | |
---|
201 | @end table |
---|
202 | |
---|
203 | A complete network configuration specification can be as simple as the one |
---|
204 | shown in the following example. |
---|
205 | This configuration uses a single network interface, gets |
---|
206 | network configuration information |
---|
207 | from a BOOTP server, and uses the default values for all driver |
---|
208 | parameters. |
---|
209 | |
---|
210 | @example |
---|
211 | static struct rtems_bsdnet_ifconfig netdriver_config = @{ |
---|
212 | RTEMS_BSP_NETWORK_DRIVER_NAME, |
---|
213 | RTEMS_BSP_NETWORK_DRIVER_ATTACH |
---|
214 | @}; |
---|
215 | struct rtems_bsdnet_config rtems_bsdnet_config = @{ |
---|
216 | &netdriver_config, |
---|
217 | rtems_bsdnet_do_bootp, |
---|
218 | @}; |
---|
219 | @end example |
---|
220 | |
---|
221 | |
---|
222 | @subsection Network initialization |
---|
223 | The networking tasks must be started before any |
---|
224 | network I/O operations can be performed. This is done by calling: |
---|
225 | @example |
---|
226 | rtems_bsdnet_initialize_network (); |
---|
227 | @end example |
---|
228 | |
---|
229 | This function is declared in @code{rtems/rtems_bsdnet.h}. |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | @section Application code |
---|
234 | The RTEMS network package provides almost a complete set of BSD network |
---|
235 | services. The network functions work like their BSD counterparts |
---|
236 | with the following exceptions: |
---|
237 | |
---|
238 | @itemize @bullet |
---|
239 | @item A given socket can be read or written by only one task at a time. |
---|
240 | @item There is no @code{select} function. |
---|
241 | @item You must call @code{openlog} before calling any of the @code{syslog} functions. |
---|
242 | @item @b{Some of the network functions are not thread-safe.} |
---|
243 | For example the following functions return a pointer to a static |
---|
244 | buffer which remains valid only until the next call: |
---|
245 | |
---|
246 | @table @code |
---|
247 | @item gethostbyaddr |
---|
248 | @item gethostbyname |
---|
249 | @item inet_ntoa |
---|
250 | (@code{inet_ntop} is thread-safe, though). |
---|
251 | @end table |
---|
252 | @end itemize |
---|
253 | |
---|
254 | @subsection Network Statistics |
---|
255 | There are a number of functions to print statistics gathered by the network stack. |
---|
256 | These function are declared in @code{rtems/rtems_bsdnet.h}. |
---|
257 | @table @code |
---|
258 | @item rtems_bsdnet_show_if_stats |
---|
259 | Display statistics gathered by network interfaces. |
---|
260 | |
---|
261 | @item rtems_bsdnet_show_ip_stats |
---|
262 | Display IP packet statistics. |
---|
263 | |
---|
264 | @item rtems_bsdnet_show_icmp_stats |
---|
265 | Display ICMP packet statistics. |
---|
266 | |
---|
267 | @item rtems_bsdnet_show_tcp_stats |
---|
268 | Display TCP packet statistics. |
---|
269 | |
---|
270 | @item rtems_bsdnet_show_udp_stats |
---|
271 | Display UDP packet statistics. |
---|
272 | |
---|
273 | @item rtems_bsdnet_show_mbuf_stats |
---|
274 | Display mbuf statistics. |
---|
275 | |
---|
276 | @item rtems_bsdnet_show_inet_routes |
---|
277 | Display the routing table. |
---|
278 | |
---|
279 | @end table |
---|