1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * WPA Supplicant / main() function for UNIX like OSes and MinGW |
---|
5 | * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi> |
---|
6 | * |
---|
7 | * This software may be distributed under the terms of the BSD license. |
---|
8 | * See README for more details. |
---|
9 | */ |
---|
10 | |
---|
11 | #include "includes.h" |
---|
12 | #ifdef __linux__ |
---|
13 | #include <fcntl.h> |
---|
14 | #endif /* __linux__ */ |
---|
15 | |
---|
16 | #include "common.h" |
---|
17 | #include "fst/fst.h" |
---|
18 | #include "wpa_supplicant_i.h" |
---|
19 | #include "driver_i.h" |
---|
20 | #include "p2p_supplicant.h" |
---|
21 | |
---|
22 | #ifdef __rtems__ |
---|
23 | #include <assert.h> |
---|
24 | #include <sys/mutex.h> |
---|
25 | #include <machine/rtems-bsd-program.h> |
---|
26 | #endif /* __rtems__ */ |
---|
27 | |
---|
28 | static void usage(void) |
---|
29 | { |
---|
30 | int i; |
---|
31 | printf("%s\n\n%s\n" |
---|
32 | "usage:\n" |
---|
33 | " wpa_supplicant [-BddhKLqq" |
---|
34 | #ifdef CONFIG_DEBUG_SYSLOG |
---|
35 | "s" |
---|
36 | #endif /* CONFIG_DEBUG_SYSLOG */ |
---|
37 | "t" |
---|
38 | #ifdef CONFIG_DBUS |
---|
39 | "u" |
---|
40 | #endif /* CONFIG_DBUS */ |
---|
41 | "vW] [-P<pid file>] " |
---|
42 | "[-g<global ctrl>] \\\n" |
---|
43 | " [-G<group>] \\\n" |
---|
44 | " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] " |
---|
45 | "[-p<driver_param>] \\\n" |
---|
46 | " [-b<br_ifname>] [-e<entropy file>]" |
---|
47 | #ifdef CONFIG_DEBUG_FILE |
---|
48 | " [-f<debug file>]" |
---|
49 | #endif /* CONFIG_DEBUG_FILE */ |
---|
50 | " \\\n" |
---|
51 | " [-o<override driver>] [-O<override ctrl>] \\\n" |
---|
52 | " [-N -i<ifname> -c<conf> [-C<ctrl>] " |
---|
53 | "[-D<driver>] \\\n" |
---|
54 | #ifdef CONFIG_P2P |
---|
55 | " [-m<P2P Device config file>] \\\n" |
---|
56 | #endif /* CONFIG_P2P */ |
---|
57 | " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] " |
---|
58 | "...]\n" |
---|
59 | "\n" |
---|
60 | "drivers:\n", |
---|
61 | wpa_supplicant_version, wpa_supplicant_license); |
---|
62 | |
---|
63 | for (i = 0; wpa_drivers[i]; i++) { |
---|
64 | printf(" %s = %s\n", |
---|
65 | wpa_drivers[i]->name, |
---|
66 | wpa_drivers[i]->desc); |
---|
67 | } |
---|
68 | |
---|
69 | #ifndef CONFIG_NO_STDOUT_DEBUG |
---|
70 | printf("options:\n" |
---|
71 | " -b = optional bridge interface name\n" |
---|
72 | " -B = run daemon in the background\n" |
---|
73 | " -c = Configuration file\n" |
---|
74 | " -C = ctrl_interface parameter (only used if -c is not)\n" |
---|
75 | " -i = interface name\n" |
---|
76 | " -I = additional configuration file\n" |
---|
77 | " -d = increase debugging verbosity (-dd even more)\n" |
---|
78 | " -D = driver name (can be multiple drivers: nl80211,wext)\n" |
---|
79 | " -e = entropy file\n"); |
---|
80 | #ifdef CONFIG_DEBUG_FILE |
---|
81 | printf(" -f = log output to debug file instead of stdout\n"); |
---|
82 | #endif /* CONFIG_DEBUG_FILE */ |
---|
83 | printf(" -g = global ctrl_interface\n" |
---|
84 | " -G = global ctrl_interface group\n" |
---|
85 | " -K = include keys (passwords, etc.) in debug output\n"); |
---|
86 | #ifdef CONFIG_DEBUG_SYSLOG |
---|
87 | printf(" -s = log output to syslog instead of stdout\n"); |
---|
88 | #endif /* CONFIG_DEBUG_SYSLOG */ |
---|
89 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
---|
90 | printf(" -T = record to Linux tracing in addition to logging\n"); |
---|
91 | printf(" (records all messages regardless of debug verbosity)\n"); |
---|
92 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
---|
93 | printf(" -t = include timestamp in debug messages\n" |
---|
94 | " -h = show this help text\n" |
---|
95 | " -L = show license (BSD)\n" |
---|
96 | " -o = override driver parameter for new interfaces\n" |
---|
97 | " -O = override ctrl_interface parameter for new interfaces\n" |
---|
98 | " -p = driver parameters\n" |
---|
99 | " -P = PID file\n" |
---|
100 | " -q = decrease debugging verbosity (-qq even less)\n"); |
---|
101 | #ifdef CONFIG_DBUS |
---|
102 | printf(" -u = enable DBus control interface\n"); |
---|
103 | #endif /* CONFIG_DBUS */ |
---|
104 | printf(" -v = show version\n" |
---|
105 | " -W = wait for a control interface monitor before starting\n" |
---|
106 | #ifdef CONFIG_P2P |
---|
107 | " -m = Configuration file for the P2P Device interface\n" |
---|
108 | #endif /* CONFIG_P2P */ |
---|
109 | " -N = start describing new interface\n"); |
---|
110 | |
---|
111 | printf("example:\n" |
---|
112 | " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n", |
---|
113 | wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211"); |
---|
114 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | static void license(void) |
---|
119 | { |
---|
120 | #ifndef CONFIG_NO_STDOUT_DEBUG |
---|
121 | printf("%s\n\n%s%s%s%s%s\n", |
---|
122 | wpa_supplicant_version, |
---|
123 | wpa_supplicant_full_license1, |
---|
124 | wpa_supplicant_full_license2, |
---|
125 | wpa_supplicant_full_license3, |
---|
126 | wpa_supplicant_full_license4, |
---|
127 | wpa_supplicant_full_license5); |
---|
128 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | static void wpa_supplicant_fd_workaround(int start) |
---|
133 | { |
---|
134 | #ifdef __linux__ |
---|
135 | static int fd[3] = { -1, -1, -1 }; |
---|
136 | int i; |
---|
137 | /* When started from pcmcia-cs scripts, wpa_supplicant might start with |
---|
138 | * fd 0, 1, and 2 closed. This will cause some issues because many |
---|
139 | * places in wpa_supplicant are still printing out to stdout. As a |
---|
140 | * workaround, make sure that fd's 0, 1, and 2 are not used for other |
---|
141 | * sockets. */ |
---|
142 | if (start) { |
---|
143 | for (i = 0; i < 3; i++) { |
---|
144 | fd[i] = open("/dev/null", O_RDWR); |
---|
145 | if (fd[i] > 2) { |
---|
146 | close(fd[i]); |
---|
147 | fd[i] = -1; |
---|
148 | break; |
---|
149 | } |
---|
150 | } |
---|
151 | } else { |
---|
152 | for (i = 0; i < 3; i++) { |
---|
153 | if (fd[i] >= 0) { |
---|
154 | close(fd[i]); |
---|
155 | fd[i] = -1; |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | #endif /* __linux__ */ |
---|
160 | } |
---|
161 | |
---|
162 | #ifdef __rtems__ |
---|
163 | #include <rtems/libio.h> |
---|
164 | |
---|
165 | static int |
---|
166 | main(int argc, char **argv); |
---|
167 | |
---|
168 | int rtems_bsd_command_wpa_supplicant(int argc, char **argv) |
---|
169 | { |
---|
170 | int exit_code; |
---|
171 | rtems_status_code sc; |
---|
172 | |
---|
173 | exit_code = rtems_bsd_program_call_main("wpa_supplicant", main, argc, argv); |
---|
174 | |
---|
175 | return exit_code; |
---|
176 | } |
---|
177 | #endif /* __rtems__ */ |
---|
178 | |
---|
179 | int main(int argc, char *argv[]) |
---|
180 | { |
---|
181 | int c, i; |
---|
182 | struct wpa_interface *ifaces, *iface; |
---|
183 | int iface_count, exitcode = -1; |
---|
184 | struct wpa_params params; |
---|
185 | struct wpa_global *global; |
---|
186 | |
---|
187 | if (os_program_init()) |
---|
188 | return -1; |
---|
189 | |
---|
190 | os_memset(¶ms, 0, sizeof(params)); |
---|
191 | params.wpa_debug_level = MSG_INFO; |
---|
192 | |
---|
193 | iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); |
---|
194 | if (ifaces == NULL) |
---|
195 | return -1; |
---|
196 | iface_count = 1; |
---|
197 | |
---|
198 | wpa_supplicant_fd_workaround(1); |
---|
199 | |
---|
200 | for (;;) { |
---|
201 | c = getopt(argc, argv, |
---|
202 | "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsTtuvW"); |
---|
203 | if (c < 0) |
---|
204 | break; |
---|
205 | switch (c) { |
---|
206 | case 'b': |
---|
207 | iface->bridge_ifname = optarg; |
---|
208 | break; |
---|
209 | case 'B': |
---|
210 | params.daemonize++; |
---|
211 | break; |
---|
212 | case 'c': |
---|
213 | iface->confname = optarg; |
---|
214 | break; |
---|
215 | case 'C': |
---|
216 | iface->ctrl_interface = optarg; |
---|
217 | break; |
---|
218 | case 'D': |
---|
219 | iface->driver = optarg; |
---|
220 | break; |
---|
221 | case 'd': |
---|
222 | #ifdef CONFIG_NO_STDOUT_DEBUG |
---|
223 | printf("Debugging disabled with " |
---|
224 | "CONFIG_NO_STDOUT_DEBUG=y build time " |
---|
225 | "option.\n"); |
---|
226 | goto out; |
---|
227 | #else /* CONFIG_NO_STDOUT_DEBUG */ |
---|
228 | params.wpa_debug_level--; |
---|
229 | break; |
---|
230 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
---|
231 | case 'e': |
---|
232 | params.entropy_file = optarg; |
---|
233 | break; |
---|
234 | #ifdef CONFIG_DEBUG_FILE |
---|
235 | case 'f': |
---|
236 | params.wpa_debug_file_path = optarg; |
---|
237 | break; |
---|
238 | #endif /* CONFIG_DEBUG_FILE */ |
---|
239 | case 'g': |
---|
240 | params.ctrl_interface = optarg; |
---|
241 | break; |
---|
242 | case 'G': |
---|
243 | params.ctrl_interface_group = optarg; |
---|
244 | break; |
---|
245 | case 'h': |
---|
246 | usage(); |
---|
247 | exitcode = 0; |
---|
248 | goto out; |
---|
249 | case 'i': |
---|
250 | iface->ifname = optarg; |
---|
251 | break; |
---|
252 | case 'I': |
---|
253 | iface->confanother = optarg; |
---|
254 | break; |
---|
255 | case 'K': |
---|
256 | params.wpa_debug_show_keys++; |
---|
257 | break; |
---|
258 | case 'L': |
---|
259 | license(); |
---|
260 | exitcode = 0; |
---|
261 | goto out; |
---|
262 | #ifdef CONFIG_P2P |
---|
263 | case 'm': |
---|
264 | params.conf_p2p_dev = optarg; |
---|
265 | break; |
---|
266 | #endif /* CONFIG_P2P */ |
---|
267 | case 'o': |
---|
268 | params.override_driver = optarg; |
---|
269 | break; |
---|
270 | case 'O': |
---|
271 | params.override_ctrl_interface = optarg; |
---|
272 | break; |
---|
273 | case 'p': |
---|
274 | iface->driver_param = optarg; |
---|
275 | break; |
---|
276 | case 'P': |
---|
277 | os_free(params.pid_file); |
---|
278 | params.pid_file = os_rel2abs_path(optarg); |
---|
279 | break; |
---|
280 | case 'q': |
---|
281 | params.wpa_debug_level++; |
---|
282 | break; |
---|
283 | #ifdef CONFIG_DEBUG_SYSLOG |
---|
284 | case 's': |
---|
285 | params.wpa_debug_syslog++; |
---|
286 | break; |
---|
287 | #endif /* CONFIG_DEBUG_SYSLOG */ |
---|
288 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
---|
289 | case 'T': |
---|
290 | params.wpa_debug_tracing++; |
---|
291 | break; |
---|
292 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
---|
293 | case 't': |
---|
294 | params.wpa_debug_timestamp++; |
---|
295 | break; |
---|
296 | #ifdef CONFIG_DBUS |
---|
297 | case 'u': |
---|
298 | params.dbus_ctrl_interface = 1; |
---|
299 | break; |
---|
300 | #endif /* CONFIG_DBUS */ |
---|
301 | case 'v': |
---|
302 | printf("%s\n", wpa_supplicant_version); |
---|
303 | exitcode = 0; |
---|
304 | goto out; |
---|
305 | case 'W': |
---|
306 | params.wait_for_monitor++; |
---|
307 | break; |
---|
308 | case 'N': |
---|
309 | iface_count++; |
---|
310 | iface = os_realloc_array(ifaces, iface_count, |
---|
311 | sizeof(struct wpa_interface)); |
---|
312 | if (iface == NULL) |
---|
313 | goto out; |
---|
314 | ifaces = iface; |
---|
315 | iface = &ifaces[iface_count - 1]; |
---|
316 | os_memset(iface, 0, sizeof(*iface)); |
---|
317 | break; |
---|
318 | default: |
---|
319 | usage(); |
---|
320 | exitcode = 0; |
---|
321 | goto out; |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | exitcode = 0; |
---|
326 | global = wpa_supplicant_init(¶ms); |
---|
327 | if (global == NULL) { |
---|
328 | wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant"); |
---|
329 | exitcode = -1; |
---|
330 | goto out; |
---|
331 | } else { |
---|
332 | wpa_printf(MSG_INFO, "Successfully initialized " |
---|
333 | "wpa_supplicant"); |
---|
334 | } |
---|
335 | |
---|
336 | if (fst_global_init()) { |
---|
337 | wpa_printf(MSG_ERROR, "Failed to initialize FST"); |
---|
338 | exitcode = -1; |
---|
339 | goto out; |
---|
340 | } |
---|
341 | |
---|
342 | #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE) |
---|
343 | if (!fst_global_add_ctrl(fst_ctrl_cli)) |
---|
344 | wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl"); |
---|
345 | #endif |
---|
346 | |
---|
347 | for (i = 0; exitcode == 0 && i < iface_count; i++) { |
---|
348 | struct wpa_supplicant *wpa_s; |
---|
349 | |
---|
350 | if ((ifaces[i].confname == NULL && |
---|
351 | ifaces[i].ctrl_interface == NULL) || |
---|
352 | ifaces[i].ifname == NULL) { |
---|
353 | if (iface_count == 1 && (params.ctrl_interface || |
---|
354 | params.dbus_ctrl_interface)) |
---|
355 | break; |
---|
356 | usage(); |
---|
357 | exitcode = -1; |
---|
358 | break; |
---|
359 | } |
---|
360 | wpa_s = wpa_supplicant_add_iface(global, &ifaces[i], NULL); |
---|
361 | if (wpa_s == NULL) { |
---|
362 | exitcode = -1; |
---|
363 | break; |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | if (exitcode == 0) |
---|
368 | exitcode = wpa_supplicant_run(global); |
---|
369 | |
---|
370 | wpa_supplicant_deinit(global); |
---|
371 | |
---|
372 | fst_global_deinit(); |
---|
373 | |
---|
374 | out: |
---|
375 | wpa_supplicant_fd_workaround(0); |
---|
376 | os_free(ifaces); |
---|
377 | os_free(params.pid_file); |
---|
378 | |
---|
379 | os_program_deinit(); |
---|
380 | |
---|
381 | return exitcode; |
---|
382 | } |
---|