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__ */
16 #include "wpa_supplicant_i.h"
18 #include "p2p_supplicant.h"
21 static void usage(void)
26 " wpa_supplicant [-BddhKLqq"
27 #ifdef CONFIG_DEBUG_SYSLOG
29 #endif /* CONFIG_DEBUG_SYSLOG */
33 #endif /* CONFIG_DBUS */
35 "[-g<global ctrl>] \\\n"
37 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
38 "[-p<driver_param>] \\\n"
39 " [-b<br_ifname>] [-e<entropy file>]"
40 #ifdef CONFIG_DEBUG_FILE
42 #endif /* CONFIG_DEBUG_FILE */
44 " [-o<override driver>] [-O<override ctrl>] \\\n"
45 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
48 " [-m<P2P Device config file>] \\\n"
49 #endif /* CONFIG_P2P */
50 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
54 wpa_supplicant_version, wpa_supplicant_license);
56 for (i = 0; wpa_drivers[i]; i++) {
59 wpa_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 " -d = increase debugging verbosity (-dd even more)\n"
69 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
70 " -e = entropy file\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 " -G = global ctrl_interface group\n"
76 " -h = show this help text\n"
77 " -i = interface name\n"
78 " -I = additional configuration file\n"
79 " -K = include keys (passwords, etc.) in debug output\n"
80 " -L = show license (BSD)\n"
82 " -m = Configuration file for the P2P Device interface\n"
83 #endif /* CONFIG_P2P */
84 " -N = start describing new interface\n"
85 " -o = override driver parameter for new interfaces\n"
86 " -O = override ctrl_interface parameter for new interfaces\n"
87 " -p = driver parameters\n"
89 " -q = decrease debugging verbosity (-qq even less)\n"
90 #ifdef CONFIG_DEBUG_SYSLOG
91 " -s = log output to syslog instead of stdout\n"
92 #endif /* CONFIG_DEBUG_SYSLOG */
93 " -t = include timestamp in debug messages\n"
94 #ifdef CONFIG_DEBUG_LINUX_TRACING
95 " -T = record to Linux tracing in addition to logging\n"
96 " (records all messages regardless of debug verbosity)\n"
97 #endif /* CONFIG_DEBUG_LINUX_TRACING */
99 " -u = enable DBus control interface\n"
100 #endif /* CONFIG_DBUS */
101 " -v = show version\n"
102 " -W = wait for a control interface monitor before starting\n");
105 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
106 wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
107 #endif /* CONFIG_NO_STDOUT_DEBUG */
111 static void license(void)
113 #ifndef CONFIG_NO_STDOUT_DEBUG
114 printf("%s\n\n%s%s%s%s%s\n",
115 wpa_supplicant_version,
116 wpa_supplicant_full_license1,
117 wpa_supplicant_full_license2,
118 wpa_supplicant_full_license3,
119 wpa_supplicant_full_license4,
120 wpa_supplicant_full_license5);
121 #endif /* CONFIG_NO_STDOUT_DEBUG */
125 static void wpa_supplicant_fd_workaround(int start)
128 static int fd[3] = { -1, -1, -1 };
130 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
131 * fd 0, 1, and 2 closed. This will cause some issues because many
132 * places in wpa_supplicant are still printing out to stdout. As a
133 * workaround, make sure that fd's 0, 1, and 2 are not used for other
136 for (i = 0; i < 3; i++) {
137 fd[i] = open("/dev/null", O_RDWR);
145 for (i = 0; i < 3; i++) {
152 #endif /* __linux__ */
156 int main(int argc, char *argv[])
159 struct wpa_interface *ifaces, *iface;
160 int iface_count, exitcode = -1;
161 struct wpa_params params;
162 struct wpa_global *global;
164 if (os_program_init())
167 os_memset(¶ms, 0, sizeof(params));
168 params.wpa_debug_level = MSG_INFO;
170 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
175 wpa_supplicant_fd_workaround(1);
178 c = getopt(argc, argv,
179 "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsTtuvW");
184 iface->bridge_ifname = optarg;
190 iface->confname = optarg;
193 iface->ctrl_interface = optarg;
196 iface->driver = optarg;
199 #ifdef CONFIG_NO_STDOUT_DEBUG
200 printf("Debugging disabled with "
201 "CONFIG_NO_STDOUT_DEBUG=y build time "
204 #else /* CONFIG_NO_STDOUT_DEBUG */
205 params.wpa_debug_level--;
207 #endif /* CONFIG_NO_STDOUT_DEBUG */
209 params.entropy_file = optarg;
211 #ifdef CONFIG_DEBUG_FILE
213 params.wpa_debug_file_path = optarg;
215 #endif /* CONFIG_DEBUG_FILE */
217 params.ctrl_interface = optarg;
220 params.ctrl_interface_group = optarg;
227 iface->ifname = optarg;
230 iface->confanother = optarg;
233 params.wpa_debug_show_keys++;
241 params.conf_p2p_dev = optarg;
243 #endif /* CONFIG_P2P */
245 params.override_driver = optarg;
248 params.override_ctrl_interface = optarg;
251 iface->driver_param = optarg;
254 os_free(params.pid_file);
255 params.pid_file = os_rel2abs_path(optarg);
258 params.wpa_debug_level++;
260 #ifdef CONFIG_DEBUG_SYSLOG
262 params.wpa_debug_syslog++;
264 #endif /* CONFIG_DEBUG_SYSLOG */
265 #ifdef CONFIG_DEBUG_LINUX_TRACING
267 params.wpa_debug_tracing++;
269 #endif /* CONFIG_DEBUG_LINUX_TRACING */
271 params.wpa_debug_timestamp++;
275 params.dbus_ctrl_interface = 1;
277 #endif /* CONFIG_DBUS */
279 printf("%s\n", wpa_supplicant_version);
283 params.wait_for_monitor++;
287 iface = os_realloc_array(ifaces, iface_count,
288 sizeof(struct wpa_interface));
292 iface = &ifaces[iface_count - 1];
293 os_memset(iface, 0, sizeof(*iface));
303 global = wpa_supplicant_init(¶ms);
304 if (global == NULL) {
305 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
309 wpa_printf(MSG_INFO, "Successfully initialized "
313 if (fst_global_init()) {
314 wpa_printf(MSG_ERROR, "Failed to initialize FST");
319 #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
320 if (!fst_global_add_ctrl(fst_ctrl_cli))
321 wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl");
324 for (i = 0; exitcode == 0 && i < iface_count; i++) {
325 struct wpa_supplicant *wpa_s;
327 if ((ifaces[i].confname == NULL &&
328 ifaces[i].ctrl_interface == NULL) ||
329 ifaces[i].ifname == NULL) {
330 if (iface_count == 1 && (params.ctrl_interface ||
331 params.dbus_ctrl_interface))
337 wpa_s = wpa_supplicant_add_iface(global, &ifaces[i], NULL);
345 exitcode = wpa_supplicant_run(global);
347 wpa_supplicant_deinit(global);
352 wpa_supplicant_fd_workaround(0);
354 os_free(params.pid_file);