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"
17 #include "p2p_supplicant.h"
20 static void usage(void)
25 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
26 "[-g<global ctrl>] \\\n"
28 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
29 "[-p<driver_param>] \\\n"
30 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
32 " [-o<override driver>] [-O<override ctrl>] \\\n"
33 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
35 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
39 wpa_supplicant_version, wpa_supplicant_license);
41 for (i = 0; wpa_drivers[i]; i++) {
44 wpa_drivers[i]->desc);
47 #ifndef CONFIG_NO_STDOUT_DEBUG
49 " -b = optional bridge interface name\n"
50 " -B = run daemon in the background\n"
51 " -c = Configuration file\n"
52 " -C = ctrl_interface parameter (only used if -c is not)\n"
53 " -i = interface name\n"
54 " -I = additional configuration file\n"
55 " -d = increase debugging verbosity (-dd even more)\n"
56 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
57 " -e = entropy file\n");
58 #ifdef CONFIG_DEBUG_FILE
59 printf(" -f = log output to debug file instead of stdout\n");
60 #endif /* CONFIG_DEBUG_FILE */
61 printf(" -g = global ctrl_interface\n"
62 " -G = global ctrl_interface group\n"
63 " -K = include keys (passwords, etc.) in debug output\n");
64 #ifdef CONFIG_DEBUG_SYSLOG
65 printf(" -s = log output to syslog instead of stdout\n");
66 #endif /* CONFIG_DEBUG_SYSLOG */
67 #ifdef CONFIG_DEBUG_LINUX_TRACING
68 printf(" -T = record to Linux tracing in addition to logging\n");
69 printf(" (records all messages regardless of debug verbosity)\n");
70 #endif /* CONFIG_DEBUG_LINUX_TRACING */
71 printf(" -t = include timestamp in debug messages\n"
72 " -h = show this help text\n"
73 " -L = show license (BSD)\n"
74 " -o = override driver parameter for new interfaces\n"
75 " -O = override ctrl_interface parameter for new interfaces\n"
76 " -p = driver parameters\n"
78 " -q = decrease debugging verbosity (-qq even less)\n");
80 printf(" -u = enable DBus control interface\n");
81 #endif /* CONFIG_DBUS */
82 printf(" -v = show version\n"
83 " -W = wait for a control interface monitor before starting\n"
84 " -N = start describing new interface\n");
87 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
88 wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
89 #endif /* CONFIG_NO_STDOUT_DEBUG */
93 static void license(void)
95 #ifndef CONFIG_NO_STDOUT_DEBUG
96 printf("%s\n\n%s%s%s%s%s\n",
97 wpa_supplicant_version,
98 wpa_supplicant_full_license1,
99 wpa_supplicant_full_license2,
100 wpa_supplicant_full_license3,
101 wpa_supplicant_full_license4,
102 wpa_supplicant_full_license5);
103 #endif /* CONFIG_NO_STDOUT_DEBUG */
107 static void wpa_supplicant_fd_workaround(int start)
110 static int fd[3] = { -1, -1, -1 };
112 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
113 * fd 0, 1, and 2 closed. This will cause some issues because many
114 * places in wpa_supplicant are still printing out to stdout. As a
115 * workaround, make sure that fd's 0, 1, and 2 are not used for other
118 for (i = 0; i < 3; i++) {
119 fd[i] = open("/dev/null", O_RDWR);
127 for (i = 0; i < 3; i++) {
134 #endif /* __linux__ */
138 int main(int argc, char *argv[])
141 struct wpa_interface *ifaces, *iface;
142 int iface_count, exitcode = -1;
143 struct wpa_params params;
144 struct wpa_global *global;
146 if (os_program_init())
149 os_memset(¶ms, 0, sizeof(params));
150 params.wpa_debug_level = MSG_INFO;
152 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
157 wpa_supplicant_fd_workaround(1);
160 c = getopt(argc, argv,
161 "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
166 iface->bridge_ifname = optarg;
172 iface->confname = optarg;
175 iface->ctrl_interface = optarg;
178 iface->driver = optarg;
181 #ifdef CONFIG_NO_STDOUT_DEBUG
182 printf("Debugging disabled with "
183 "CONFIG_NO_STDOUT_DEBUG=y build time "
186 #else /* CONFIG_NO_STDOUT_DEBUG */
187 params.wpa_debug_level--;
189 #endif /* CONFIG_NO_STDOUT_DEBUG */
191 params.entropy_file = optarg;
193 #ifdef CONFIG_DEBUG_FILE
195 params.wpa_debug_file_path = optarg;
197 #endif /* CONFIG_DEBUG_FILE */
199 params.ctrl_interface = optarg;
202 params.ctrl_interface_group = optarg;
209 iface->ifname = optarg;
212 iface->confanother = optarg;
215 params.wpa_debug_show_keys++;
222 params.override_driver = optarg;
225 params.override_ctrl_interface = optarg;
228 iface->driver_param = optarg;
231 os_free(params.pid_file);
232 params.pid_file = os_rel2abs_path(optarg);
235 params.wpa_debug_level++;
237 #ifdef CONFIG_DEBUG_SYSLOG
239 params.wpa_debug_syslog++;
241 #endif /* CONFIG_DEBUG_SYSLOG */
242 #ifdef CONFIG_DEBUG_LINUX_TRACING
244 params.wpa_debug_tracing++;
246 #endif /* CONFIG_DEBUG_LINUX_TRACING */
248 params.wpa_debug_timestamp++;
252 params.dbus_ctrl_interface = 1;
254 #endif /* CONFIG_DBUS */
256 printf("%s\n", wpa_supplicant_version);
260 params.wait_for_monitor++;
264 iface = os_realloc_array(ifaces, iface_count,
265 sizeof(struct wpa_interface));
269 iface = &ifaces[iface_count - 1];
270 os_memset(iface, 0, sizeof(*iface));
280 global = wpa_supplicant_init(¶ms);
281 if (global == NULL) {
282 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
286 wpa_printf(MSG_INFO, "Successfully initialized "
290 for (i = 0; exitcode == 0 && i < iface_count; i++) {
291 struct wpa_supplicant *wpa_s;
293 if ((ifaces[i].confname == NULL &&
294 ifaces[i].ctrl_interface == NULL) ||
295 ifaces[i].ifname == NULL) {
296 if (iface_count == 1 && (params.ctrl_interface ||
297 params.dbus_ctrl_interface))
303 wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]);
309 if (wpa_s->global->p2p == NULL &&
311 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
312 wpas_p2p_add_p2pdev_interface(wpa_s) < 0)
314 #endif /* CONFIG_P2P */
318 exitcode = wpa_supplicant_run(global);
320 wpa_supplicant_deinit(global);
323 wpa_supplicant_fd_workaround(0);
325 os_free(params.pid_file);