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.
18 #endif /* __linux__ */
21 #include "wpa_supplicant_i.h"
24 extern struct wpa_driver_ops *wpa_drivers[];
27 static void usage(void)
32 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
33 "[-g<global ctrl>] \\\n"
34 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
35 "[-p<driver_param>] \\\n"
36 " [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
38 " [-o<override driver>] [-O<override ctrl>] \\\n"
39 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
41 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
44 wpa_supplicant_version, wpa_supplicant_license);
46 for (i = 0; wpa_drivers[i]; i++) {
49 wpa_drivers[i]->desc);
52 #ifndef CONFIG_NO_STDOUT_DEBUG
54 " -b = optional bridge interface name\n"
55 " -B = run daemon in the background\n"
56 " -c = Configuration file\n"
57 " -C = ctrl_interface parameter (only used if -c is not)\n"
58 " -i = interface name\n"
59 " -d = increase debugging verbosity (-dd even more)\n"
60 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
61 " -e = entropy file\n");
62 #ifdef CONFIG_DEBUG_FILE
63 printf(" -f = log output to debug file instead of stdout\n");
64 #endif /* CONFIG_DEBUG_FILE */
65 printf(" -g = global ctrl_interface\n"
66 " -K = include keys (passwords, etc.) in debug output\n");
67 #ifdef CONFIG_DEBUG_SYSLOG
68 printf(" -s = log output to syslog instead of stdout\n");
69 #endif /* CONFIG_DEBUG_SYSLOG */
70 printf(" -t = include timestamp in debug messages\n"
71 " -h = show this help text\n"
72 " -L = show license (BSD)\n"
73 " -o = override driver parameter for new interfaces\n"
74 " -O = override ctrl_interface parameter for new interfaces\n"
75 " -p = driver parameters\n"
77 " -q = decrease debugging verbosity (-qq even less)\n");
79 printf(" -u = enable DBus control interface\n");
80 #endif /* CONFIG_DBUS */
81 printf(" -v = show version\n"
82 " -W = wait for a control interface monitor before starting\n"
83 " -N = start describing new interface\n");
86 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
87 wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
88 #endif /* CONFIG_NO_STDOUT_DEBUG */
92 static void license(void)
94 #ifndef CONFIG_NO_STDOUT_DEBUG
95 printf("%s\n\n%s%s%s%s%s\n",
96 wpa_supplicant_version,
97 wpa_supplicant_full_license1,
98 wpa_supplicant_full_license2,
99 wpa_supplicant_full_license3,
100 wpa_supplicant_full_license4,
101 wpa_supplicant_full_license5);
102 #endif /* CONFIG_NO_STDOUT_DEBUG */
106 static void wpa_supplicant_fd_workaround(void)
110 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
111 * fd 0, 1, and 2 closed. This will cause some issues because many
112 * places in wpa_supplicant are still printing out to stdout. As a
113 * workaround, make sure that fd's 0, 1, and 2 are not used for other
115 for (i = 0; i < 3; i++) {
116 s = open("/dev/null", O_RDWR);
122 #endif /* __linux__ */
126 int main(int argc, char *argv[])
129 struct wpa_interface *ifaces, *iface;
130 int iface_count, exitcode = -1;
131 struct wpa_params params;
132 struct wpa_global *global;
134 if (os_program_init())
137 os_memset(¶ms, 0, sizeof(params));
138 params.wpa_debug_level = MSG_INFO;
140 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
145 wpa_supplicant_fd_workaround();
148 c = getopt(argc, argv, "b:Bc:C:D:de:f:g:hi:KLNo:O:p:P:qstuvW");
153 iface->bridge_ifname = optarg;
159 iface->confname = optarg;
162 iface->ctrl_interface = optarg;
165 iface->driver = optarg;
168 #ifdef CONFIG_NO_STDOUT_DEBUG
169 printf("Debugging disabled with "
170 "CONFIG_NO_STDOUT_DEBUG=y build time "
173 #else /* CONFIG_NO_STDOUT_DEBUG */
174 params.wpa_debug_level--;
176 #endif /* CONFIG_NO_STDOUT_DEBUG */
178 params.entropy_file = optarg;
180 #ifdef CONFIG_DEBUG_FILE
182 params.wpa_debug_file_path = optarg;
184 #endif /* CONFIG_DEBUG_FILE */
186 params.ctrl_interface = optarg;
193 iface->ifname = optarg;
196 params.wpa_debug_show_keys++;
203 params.override_driver = optarg;
206 params.override_ctrl_interface = optarg;
209 iface->driver_param = optarg;
212 os_free(params.pid_file);
213 params.pid_file = os_rel2abs_path(optarg);
216 params.wpa_debug_level++;
218 #ifdef CONFIG_DEBUG_SYSLOG
220 params.wpa_debug_syslog++;
222 #endif /* CONFIG_DEBUG_SYSLOG */
224 params.wpa_debug_timestamp++;
228 params.dbus_ctrl_interface = 1;
230 #endif /* CONFIG_DBUS */
232 printf("%s\n", wpa_supplicant_version);
236 params.wait_for_monitor++;
240 iface = os_realloc(ifaces, iface_count *
241 sizeof(struct wpa_interface));
245 iface = &ifaces[iface_count - 1];
246 os_memset(iface, 0, sizeof(*iface));
256 global = wpa_supplicant_init(¶ms);
257 if (global == NULL) {
258 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
263 for (i = 0; exitcode == 0 && i < iface_count; i++) {
264 if ((ifaces[i].confname == NULL &&
265 ifaces[i].ctrl_interface == NULL) ||
266 ifaces[i].ifname == NULL) {
267 if (iface_count == 1 && (params.ctrl_interface ||
268 params.dbus_ctrl_interface))
274 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
279 exitcode = wpa_supplicant_run(global);
281 wpa_supplicant_deinit(global);
285 os_free(params.pid_file);