2 * WPA Supplicant / main() function for UNIX like OSes and MinGW
3 * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #endif /* __linux__ */
15 #include "wpa_supplicant_i.h"
18 extern struct wpa_driver_ops *wpa_drivers[];
21 static void usage(void)
26 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
27 "[-g<global ctrl>] \\\n"
29 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
30 "[-p<driver_param>] \\\n"
31 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
33 " [-o<override driver>] [-O<override ctrl>] \\\n"
34 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
36 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
40 wpa_supplicant_version, wpa_supplicant_license);
42 for (i = 0; wpa_drivers[i]; i++) {
45 wpa_drivers[i]->desc);
48 #ifndef CONFIG_NO_STDOUT_DEBUG
50 " -b = optional bridge interface name\n"
51 " -B = run daemon in the background\n"
52 " -c = Configuration file\n"
53 " -C = ctrl_interface parameter (only used if -c is not)\n"
54 " -i = interface name\n"
55 " -I = additional configuration file\n"
56 " -d = increase debugging verbosity (-dd even more)\n"
57 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
58 " -e = entropy file\n");
59 #ifdef CONFIG_DEBUG_FILE
60 printf(" -f = log output to debug file instead of stdout\n");
61 #endif /* CONFIG_DEBUG_FILE */
62 printf(" -g = global ctrl_interface\n"
63 " -G = global ctrl_interface group\n"
64 " -K = include keys (passwords, etc.) in debug output\n");
65 #ifdef CONFIG_DEBUG_SYSLOG
66 printf(" -s = log output to syslog instead of stdout\n");
67 #endif /* CONFIG_DEBUG_SYSLOG */
68 #ifdef CONFIG_DEBUG_LINUX_TRACING
69 printf(" -T = record to Linux tracing in addition to logging\n");
70 printf(" (records all messages regardless of debug verbosity)\n");
71 #endif /* CONFIG_DEBUG_LINUX_TRACING */
72 printf(" -t = include timestamp in debug messages\n"
73 " -h = show this help text\n"
74 " -L = show license (BSD)\n"
75 " -o = override driver parameter for new interfaces\n"
76 " -O = override ctrl_interface parameter for new interfaces\n"
77 " -p = driver parameters\n"
79 " -q = decrease debugging verbosity (-qq even less)\n");
81 printf(" -u = enable DBus control interface\n");
82 #endif /* CONFIG_DBUS */
83 printf(" -v = show version\n"
84 " -W = wait for a control interface monitor before starting\n"
85 " -N = start describing new interface\n");
88 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
89 wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
90 #endif /* CONFIG_NO_STDOUT_DEBUG */
94 static void license(void)
96 #ifndef CONFIG_NO_STDOUT_DEBUG
97 printf("%s\n\n%s%s%s%s%s\n",
98 wpa_supplicant_version,
99 wpa_supplicant_full_license1,
100 wpa_supplicant_full_license2,
101 wpa_supplicant_full_license3,
102 wpa_supplicant_full_license4,
103 wpa_supplicant_full_license5);
104 #endif /* CONFIG_NO_STDOUT_DEBUG */
108 static void wpa_supplicant_fd_workaround(int start)
111 static int fd[3] = { -1, -1, -1 };
113 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
114 * fd 0, 1, and 2 closed. This will cause some issues because many
115 * places in wpa_supplicant are still printing out to stdout. As a
116 * workaround, make sure that fd's 0, 1, and 2 are not used for other
119 for (i = 0; i < 3; i++) {
120 fd[i] = open("/dev/null", O_RDWR);
128 for (i = 0; i < 3; i++) {
135 #endif /* __linux__ */
139 int main(int argc, char *argv[])
142 struct wpa_interface *ifaces, *iface;
143 int iface_count, exitcode = -1;
144 struct wpa_params params;
145 struct wpa_global *global;
147 if (os_program_init())
150 os_memset(¶ms, 0, sizeof(params));
151 params.wpa_debug_level = MSG_INFO;
153 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
158 wpa_supplicant_fd_workaround(1);
161 c = getopt(argc, argv,
162 "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
167 iface->bridge_ifname = optarg;
173 iface->confname = optarg;
176 iface->ctrl_interface = optarg;
179 iface->driver = optarg;
182 #ifdef CONFIG_NO_STDOUT_DEBUG
183 printf("Debugging disabled with "
184 "CONFIG_NO_STDOUT_DEBUG=y build time "
187 #else /* CONFIG_NO_STDOUT_DEBUG */
188 params.wpa_debug_level--;
190 #endif /* CONFIG_NO_STDOUT_DEBUG */
192 params.entropy_file = optarg;
194 #ifdef CONFIG_DEBUG_FILE
196 params.wpa_debug_file_path = optarg;
198 #endif /* CONFIG_DEBUG_FILE */
200 params.ctrl_interface = optarg;
203 params.ctrl_interface_group = optarg;
210 iface->ifname = optarg;
213 iface->confanother = optarg;
216 params.wpa_debug_show_keys++;
223 params.override_driver = optarg;
226 params.override_ctrl_interface = optarg;
229 iface->driver_param = optarg;
232 os_free(params.pid_file);
233 params.pid_file = os_rel2abs_path(optarg);
236 params.wpa_debug_level++;
238 #ifdef CONFIG_DEBUG_SYSLOG
240 params.wpa_debug_syslog++;
242 #endif /* CONFIG_DEBUG_SYSLOG */
243 #ifdef CONFIG_DEBUG_LINUX_TRACING
245 params.wpa_debug_tracing++;
247 #endif /* CONFIG_DEBUG_LINUX_TRACING */
249 params.wpa_debug_timestamp++;
253 params.dbus_ctrl_interface = 1;
255 #endif /* CONFIG_DBUS */
257 printf("%s\n", wpa_supplicant_version);
261 params.wait_for_monitor++;
265 iface = os_realloc_array(ifaces, iface_count,
266 sizeof(struct wpa_interface));
270 iface = &ifaces[iface_count - 1];
271 os_memset(iface, 0, sizeof(*iface));
281 global = wpa_supplicant_init(¶ms);
282 if (global == NULL) {
283 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
287 wpa_printf(MSG_INFO, "Successfully initialized "
291 for (i = 0; exitcode == 0 && i < iface_count; i++) {
292 if ((ifaces[i].confname == NULL &&
293 ifaces[i].ctrl_interface == NULL) ||
294 ifaces[i].ifname == NULL) {
295 if (iface_count == 1 && (params.ctrl_interface ||
296 params.dbus_ctrl_interface))
302 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
307 exitcode = wpa_supplicant_run(global);
309 wpa_supplicant_deinit(global);
312 wpa_supplicant_fd_workaround(0);
314 os_free(params.pid_file);