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"
19 extern struct wpa_driver_ops *wpa_drivers[];
22 static void usage(void)
27 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
28 "[-g<global ctrl>] \\\n"
30 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
31 "[-p<driver_param>] \\\n"
32 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
34 " [-o<override driver>] [-O<override ctrl>] \\\n"
35 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
37 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
41 wpa_supplicant_version, wpa_supplicant_license);
43 for (i = 0; wpa_drivers[i]; i++) {
46 wpa_drivers[i]->desc);
49 #ifndef CONFIG_NO_STDOUT_DEBUG
51 " -b = optional bridge interface name\n"
52 " -B = run daemon in the background\n"
53 " -c = Configuration file\n"
54 " -C = ctrl_interface parameter (only used if -c is not)\n"
55 " -i = interface name\n"
56 " -I = additional configuration file\n"
57 " -d = increase debugging verbosity (-dd even more)\n"
58 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
59 " -e = entropy file\n");
60 #ifdef CONFIG_DEBUG_FILE
61 printf(" -f = log output to debug file instead of stdout\n");
62 #endif /* CONFIG_DEBUG_FILE */
63 printf(" -g = global ctrl_interface\n"
64 " -G = global ctrl_interface group\n"
65 " -K = include keys (passwords, etc.) in debug output\n");
66 #ifdef CONFIG_DEBUG_SYSLOG
67 printf(" -s = log output to syslog instead of stdout\n");
68 #endif /* CONFIG_DEBUG_SYSLOG */
69 #ifdef CONFIG_DEBUG_LINUX_TRACING
70 printf(" -T = record to Linux tracing in addition to logging\n");
71 printf(" (records all messages regardless of debug verbosity)\n");
72 #endif /* CONFIG_DEBUG_LINUX_TRACING */
73 printf(" -t = include timestamp in debug messages\n"
74 " -h = show this help text\n"
75 " -L = show license (BSD)\n"
76 " -o = override driver parameter for new interfaces\n"
77 " -O = override ctrl_interface parameter for new interfaces\n"
78 " -p = driver parameters\n"
80 " -q = decrease debugging verbosity (-qq even less)\n");
82 printf(" -u = enable DBus control interface\n");
83 #endif /* CONFIG_DBUS */
84 printf(" -v = show version\n"
85 " -W = wait for a control interface monitor before starting\n"
86 " -N = start describing new interface\n");
89 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
90 wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
91 #endif /* CONFIG_NO_STDOUT_DEBUG */
95 static void license(void)
97 #ifndef CONFIG_NO_STDOUT_DEBUG
98 printf("%s\n\n%s%s%s%s%s\n",
99 wpa_supplicant_version,
100 wpa_supplicant_full_license1,
101 wpa_supplicant_full_license2,
102 wpa_supplicant_full_license3,
103 wpa_supplicant_full_license4,
104 wpa_supplicant_full_license5);
105 #endif /* CONFIG_NO_STDOUT_DEBUG */
109 static void wpa_supplicant_fd_workaround(int start)
112 static int fd[3] = { -1, -1, -1 };
114 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
115 * fd 0, 1, and 2 closed. This will cause some issues because many
116 * places in wpa_supplicant are still printing out to stdout. As a
117 * workaround, make sure that fd's 0, 1, and 2 are not used for other
120 for (i = 0; i < 3; i++) {
121 fd[i] = open("/dev/null", O_RDWR);
129 for (i = 0; i < 3; i++) {
136 #endif /* __linux__ */
140 int main(int argc, char *argv[])
143 struct wpa_interface *ifaces, *iface;
144 int iface_count, exitcode = -1;
145 struct wpa_params params;
146 struct wpa_global *global;
148 if (os_program_init())
151 os_memset(¶ms, 0, sizeof(params));
152 params.wpa_debug_level = MSG_INFO;
154 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
159 wpa_supplicant_fd_workaround(1);
162 c = getopt(argc, argv,
163 "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
168 iface->bridge_ifname = optarg;
174 iface->confname = optarg;
177 iface->ctrl_interface = optarg;
180 iface->driver = optarg;
183 #ifdef CONFIG_NO_STDOUT_DEBUG
184 printf("Debugging disabled with "
185 "CONFIG_NO_STDOUT_DEBUG=y build time "
188 #else /* CONFIG_NO_STDOUT_DEBUG */
189 params.wpa_debug_level--;
191 #endif /* CONFIG_NO_STDOUT_DEBUG */
193 params.entropy_file = optarg;
195 #ifdef CONFIG_DEBUG_FILE
197 params.wpa_debug_file_path = optarg;
199 #endif /* CONFIG_DEBUG_FILE */
201 params.ctrl_interface = optarg;
204 params.ctrl_interface_group = optarg;
211 iface->ifname = optarg;
214 iface->confanother = optarg;
217 params.wpa_debug_show_keys++;
224 params.override_driver = optarg;
227 params.override_ctrl_interface = optarg;
230 iface->driver_param = optarg;
233 os_free(params.pid_file);
234 params.pid_file = os_rel2abs_path(optarg);
237 params.wpa_debug_level++;
239 #ifdef CONFIG_DEBUG_SYSLOG
241 params.wpa_debug_syslog++;
243 #endif /* CONFIG_DEBUG_SYSLOG */
244 #ifdef CONFIG_DEBUG_LINUX_TRACING
246 params.wpa_debug_tracing++;
248 #endif /* CONFIG_DEBUG_LINUX_TRACING */
250 params.wpa_debug_timestamp++;
254 params.dbus_ctrl_interface = 1;
256 #endif /* CONFIG_DBUS */
258 printf("%s\n", wpa_supplicant_version);
262 params.wait_for_monitor++;
266 iface = os_realloc_array(ifaces, iface_count,
267 sizeof(struct wpa_interface));
271 iface = &ifaces[iface_count - 1];
272 os_memset(iface, 0, sizeof(*iface));
282 global = wpa_supplicant_init(¶ms);
283 if (global == NULL) {
284 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
288 wpa_printf(MSG_INFO, "Successfully initialized "
292 for (i = 0; exitcode == 0 && i < iface_count; i++) {
293 struct wpa_supplicant *wpa_s;
295 if ((ifaces[i].confname == NULL &&
296 ifaces[i].ctrl_interface == NULL) ||
297 ifaces[i].ifname == NULL) {
298 if (iface_count == 1 && (params.ctrl_interface ||
299 params.dbus_ctrl_interface))
305 wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]);
310 if (wpa_s->global->p2p == NULL &&
312 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
313 wpas_p2p_add_p2pdev_interface(wpa_s) < 0)
318 exitcode = wpa_supplicant_run(global);
320 wpa_supplicant_deinit(global);
323 wpa_supplicant_fd_workaround(0);
325 os_free(params.pid_file);