2 * WPA Supplicant / main() function for UNIX like OSes and MinGW
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
20 #endif /* __linux__ */
23 #include "wpa_supplicant_i.h"
26 extern const char *wpa_supplicant_version;
27 extern const char *wpa_supplicant_license;
28 #ifndef CONFIG_NO_STDOUT_DEBUG
29 extern const char *wpa_supplicant_full_license1;
30 extern const char *wpa_supplicant_full_license2;
31 extern const char *wpa_supplicant_full_license3;
32 extern const char *wpa_supplicant_full_license4;
33 extern const char *wpa_supplicant_full_license5;
34 #endif /* CONFIG_NO_STDOUT_DEBUG */
36 extern struct wpa_driver_ops *wpa_supplicant_drivers[];
39 static void usage(void)
44 " wpa_supplicant [-BddhKLqqstuvwW] [-P<pid file>] "
45 "[-g<global ctrl>] \\\n"
46 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
47 "[-p<driver_param>] \\\n"
48 " [-b<br_ifname>] [-f<debug file>] \\\n"
49 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
51 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
54 wpa_supplicant_version, wpa_supplicant_license);
56 for (i = 0; wpa_supplicant_drivers[i]; i++) {
58 wpa_supplicant_drivers[i]->name,
59 wpa_supplicant_drivers[i]->desc);
62 #ifndef CONFIG_NO_STDOUT_DEBUG
64 " -b = optional bridge interface name\n"
65 " -B = run daemon in the background\n"
66 " -c = Configuration file\n"
67 " -C = ctrl_interface parameter (only used if -c is not)\n"
68 " -i = interface name\n"
69 " -d = increase debugging verbosity (-dd even more)\n"
71 #ifdef CONFIG_DEBUG_FILE
72 " -f = log output to debug file instead of stdout\n"
73 #endif /* CONFIG_DEBUG_FILE */
74 " -g = global ctrl_interface\n"
75 " -K = include keys (passwords, etc.) in debug output\n"
76 " -t = include timestamp in debug messages\n"
77 " -h = show this help text\n"
78 " -L = show license (GPL and BSD)\n");
79 printf(" -p = driver parameters\n"
81 " -q = decrease debugging verbosity (-qq even less)\n"
82 #ifdef CONFIG_DEBUG_SYSLOG
83 " -s = log output to syslog instead of stdout\n"
84 #endif /* CONFIG_DEBUG_SYSLOG */
85 #ifdef CONFIG_CTRL_IFACE_DBUS
86 " -u = enable DBus control interface\n"
87 #endif /* CONFIG_CTRL_IFACE_DBUS */
88 " -v = show version\n"
89 " -w = wait for interface to be added, if needed\n"
90 " -W = wait for a control interface monitor before starting\n"
91 " -N = start describing new interface\n");
94 " wpa_supplicant -Dbsd -iwlan0 -c/etc/wpa_supplicant.conf\n");
95 #endif /* CONFIG_NO_STDOUT_DEBUG */
99 static void license(void)
101 #ifndef CONFIG_NO_STDOUT_DEBUG
102 printf("%s\n\n%s%s%s%s%s\n",
103 wpa_supplicant_version,
104 wpa_supplicant_full_license1,
105 wpa_supplicant_full_license2,
106 wpa_supplicant_full_license3,
107 wpa_supplicant_full_license4,
108 wpa_supplicant_full_license5);
109 #endif /* CONFIG_NO_STDOUT_DEBUG */
113 static void wpa_supplicant_fd_workaround(void)
117 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
118 * fd 0, 1, and 2 closed. This will cause some issues because many
119 * places in wpa_supplicant are still printing out to stdout. As a
120 * workaround, make sure that fd's 0, 1, and 2 are not used for other
122 for (i = 0; i < 3; i++) {
123 s = open("/dev/null", O_RDWR);
129 #endif /* __linux__ */
133 int main(int argc, char *argv[])
136 struct wpa_interface *ifaces, *iface;
137 int iface_count, exitcode = -1;
138 struct wpa_params params;
139 struct wpa_global *global;
141 if (os_program_init())
144 os_memset(¶ms, 0, sizeof(params));
145 params.wpa_debug_level = MSG_INFO;
147 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
152 wpa_supplicant_fd_workaround();
155 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qstuvwW");
160 iface->bridge_ifname = optarg;
166 iface->confname = optarg;
169 iface->ctrl_interface = optarg;
172 iface->driver = optarg;
175 #ifdef CONFIG_NO_STDOUT_DEBUG
176 printf("Debugging disabled with "
177 "CONFIG_NO_STDOUT_DEBUG=y build time "
180 #else /* CONFIG_NO_STDOUT_DEBUG */
181 params.wpa_debug_level--;
183 #endif /* CONFIG_NO_STDOUT_DEBUG */
184 #ifdef CONFIG_DEBUG_FILE
186 params.wpa_debug_file_path = optarg;
188 #endif /* CONFIG_DEBUG_FILE */
190 params.ctrl_interface = optarg;
197 iface->ifname = optarg;
200 params.wpa_debug_show_keys++;
207 iface->driver_param = optarg;
210 os_free(params.pid_file);
211 params.pid_file = os_rel2abs_path(optarg);
214 params.wpa_debug_level++;
216 #ifdef CONFIG_DEBUG_SYSLOG
218 params.wpa_debug_syslog++;
220 #endif /* CONFIG_DEBUG_SYSLOG */
222 params.wpa_debug_timestamp++;
224 #ifdef CONFIG_CTRL_IFACE_DBUS
226 params.dbus_ctrl_interface = 1;
228 #endif /* CONFIG_CTRL_IFACE_DBUS */
230 printf("%s\n", wpa_supplicant_version);
234 params.wait_for_interface++;
237 params.wait_for_monitor++;
241 iface = os_realloc(ifaces, iface_count *
242 sizeof(struct wpa_interface));
246 iface = &ifaces[iface_count - 1];
247 os_memset(iface, 0, sizeof(*iface));
257 global = wpa_supplicant_init(¶ms);
258 if (global == NULL) {
259 printf("Failed to initialize wpa_supplicant\n");
264 for (i = 0; exitcode == 0 && i < iface_count; i++) {
265 if ((ifaces[i].confname == NULL &&
266 ifaces[i].ctrl_interface == NULL) ||
267 ifaces[i].ifname == NULL) {
268 if (iface_count == 1 && (params.ctrl_interface ||
269 params.dbus_ctrl_interface))
275 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
280 exitcode = wpa_supplicant_run(global);
282 wpa_supplicant_deinit(global);
286 os_free(params.pid_file);