2 * WPA Supplicant / main() function for UNIX like OSes and MinGW
3 * Copyright (c) 2003-2007, 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"
18 extern struct wpa_driver_ops *wpa_drivers[];
21 static void usage(void)
26 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
27 "[-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>] ...]\n"
38 wpa_supplicant_version, wpa_supplicant_license);
40 for (i = 0; wpa_drivers[i]; i++) {
43 wpa_drivers[i]->desc);
46 #ifndef CONFIG_NO_STDOUT_DEBUG
48 " -b = optional bridge interface name\n"
49 " -B = run daemon in the background\n"
50 " -c = Configuration file\n"
51 " -C = ctrl_interface parameter (only used if -c is not)\n"
52 " -i = interface name\n"
53 " -d = increase debugging verbosity (-dd even more)\n"
54 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
55 " -e = entropy file\n");
56 #ifdef CONFIG_DEBUG_FILE
57 printf(" -f = log output to debug file instead of stdout\n");
58 #endif /* CONFIG_DEBUG_FILE */
59 printf(" -g = global ctrl_interface\n"
60 " -K = include keys (passwords, etc.) in debug output\n");
61 #ifdef CONFIG_DEBUG_SYSLOG
62 printf(" -s = log output to syslog instead of stdout\n");
63 #endif /* CONFIG_DEBUG_SYSLOG */
64 #ifdef CONFIG_DEBUG_LINUX_TRACING
65 printf(" -T = record to Linux tracing in addition to logging\n");
66 printf(" (records all messages regardless of debug verbosity)\n");
67 #endif /* CONFIG_DEBUG_LINUX_TRACING */
68 printf(" -t = include timestamp in debug messages\n"
69 " -h = show this help text\n"
70 " -L = show license (BSD)\n"
71 " -o = override driver parameter for new interfaces\n"
72 " -O = override ctrl_interface parameter for new interfaces\n"
73 " -p = driver parameters\n"
75 " -q = decrease debugging verbosity (-qq even less)\n");
77 printf(" -u = enable DBus control interface\n");
78 #endif /* CONFIG_DBUS */
79 printf(" -v = show version\n"
80 " -W = wait for a control interface monitor before starting\n"
81 " -N = start describing new interface\n");
84 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
85 wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
86 #endif /* CONFIG_NO_STDOUT_DEBUG */
90 static void license(void)
92 #ifndef CONFIG_NO_STDOUT_DEBUG
93 printf("%s\n\n%s%s%s%s%s\n",
94 wpa_supplicant_version,
95 wpa_supplicant_full_license1,
96 wpa_supplicant_full_license2,
97 wpa_supplicant_full_license3,
98 wpa_supplicant_full_license4,
99 wpa_supplicant_full_license5);
100 #endif /* CONFIG_NO_STDOUT_DEBUG */
104 static void wpa_supplicant_fd_workaround(int start)
107 static int fd[3] = { -1, -1, -1 };
109 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
110 * fd 0, 1, and 2 closed. This will cause some issues because many
111 * places in wpa_supplicant are still printing out to stdout. As a
112 * workaround, make sure that fd's 0, 1, and 2 are not used for other
115 for (i = 0; i < 3; i++) {
116 fd[i] = open("/dev/null", O_RDWR);
124 for (i = 0; i < 3; i++) {
131 #endif /* __linux__ */
135 int main(int argc, char *argv[])
138 struct wpa_interface *ifaces, *iface;
139 int iface_count, exitcode = -1;
140 struct wpa_params params;
141 struct wpa_global *global;
143 if (os_program_init())
146 os_memset(¶ms, 0, sizeof(params));
147 params.wpa_debug_level = MSG_INFO;
149 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
154 wpa_supplicant_fd_workaround(1);
157 c = getopt(argc, argv,
158 "b:Bc:C:D:de:f:g:hi:KLNo:O:p:P:qsTtuvW");
163 iface->bridge_ifname = optarg;
169 iface->confname = optarg;
172 iface->ctrl_interface = optarg;
175 iface->driver = optarg;
178 #ifdef CONFIG_NO_STDOUT_DEBUG
179 printf("Debugging disabled with "
180 "CONFIG_NO_STDOUT_DEBUG=y build time "
183 #else /* CONFIG_NO_STDOUT_DEBUG */
184 params.wpa_debug_level--;
186 #endif /* CONFIG_NO_STDOUT_DEBUG */
188 params.entropy_file = optarg;
190 #ifdef CONFIG_DEBUG_FILE
192 params.wpa_debug_file_path = optarg;
194 #endif /* CONFIG_DEBUG_FILE */
196 params.ctrl_interface = optarg;
203 iface->ifname = optarg;
206 params.wpa_debug_show_keys++;
213 params.override_driver = optarg;
216 params.override_ctrl_interface = optarg;
219 iface->driver_param = optarg;
222 os_free(params.pid_file);
223 params.pid_file = os_rel2abs_path(optarg);
226 params.wpa_debug_level++;
228 #ifdef CONFIG_DEBUG_SYSLOG
230 params.wpa_debug_syslog++;
232 #endif /* CONFIG_DEBUG_SYSLOG */
233 #ifdef CONFIG_DEBUG_LINUX_TRACING
235 params.wpa_debug_tracing++;
237 #endif /* CONFIG_DEBUG_LINUX_TRACING */
239 params.wpa_debug_timestamp++;
243 params.dbus_ctrl_interface = 1;
245 #endif /* CONFIG_DBUS */
247 printf("%s\n", wpa_supplicant_version);
251 params.wait_for_monitor++;
255 iface = os_realloc_array(ifaces, iface_count,
256 sizeof(struct wpa_interface));
260 iface = &ifaces[iface_count - 1];
261 os_memset(iface, 0, sizeof(*iface));
271 global = wpa_supplicant_init(¶ms);
272 if (global == NULL) {
273 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
277 wpa_printf(MSG_INFO, "Successfully initialized "
281 for (i = 0; exitcode == 0 && i < iface_count; i++) {
282 if ((ifaces[i].confname == NULL &&
283 ifaces[i].ctrl_interface == NULL) ||
284 ifaces[i].ifname == NULL) {
285 if (iface_count == 1 && (params.ctrl_interface ||
286 params.dbus_ctrl_interface))
292 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
297 exitcode = wpa_supplicant_run(global);
299 wpa_supplicant_deinit(global);
302 wpa_supplicant_fd_workaround(0);
304 os_free(params.pid_file);