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>] \\\n"
37 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
39 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
42 wpa_supplicant_version, wpa_supplicant_license);
44 for (i = 0; wpa_drivers[i]; i++) {
47 wpa_drivers[i]->desc);
50 #ifndef CONFIG_NO_STDOUT_DEBUG
52 " -b = optional bridge interface name\n"
53 " -B = run daemon in the background\n"
54 " -c = Configuration file\n"
55 " -C = ctrl_interface parameter (only used if -c is not)\n"
56 " -i = interface name\n"
57 " -d = increase debugging verbosity (-dd even more)\n"
58 " -D = driver name (can be multiple drivers: nl80211,wext)\n");
59 #ifdef CONFIG_DEBUG_FILE
60 printf(" -f = log output to debug file instead of stdout\n");
61 #endif /* CONFIG_DEBUG_FILE */
62 printf(" -g = global ctrl_interface\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 printf(" -t = include timestamp in debug messages\n"
68 " -h = show this help text\n"
69 " -L = show license (GPL and BSD)\n"
70 " -p = driver parameters\n"
72 " -q = decrease debugging verbosity (-qq even less)\n");
73 #ifdef CONFIG_CTRL_IFACE_DBUS
74 printf(" -u = enable DBus control interface\n");
75 #endif /* CONFIG_CTRL_IFACE_DBUS */
76 printf(" -v = show version\n"
77 " -W = wait for a control interface monitor before starting\n"
78 " -N = start describing new interface\n");
81 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
82 wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
83 #endif /* CONFIG_NO_STDOUT_DEBUG */
87 static void license(void)
89 #ifndef CONFIG_NO_STDOUT_DEBUG
90 printf("%s\n\n%s%s%s%s%s\n",
91 wpa_supplicant_version,
92 wpa_supplicant_full_license1,
93 wpa_supplicant_full_license2,
94 wpa_supplicant_full_license3,
95 wpa_supplicant_full_license4,
96 wpa_supplicant_full_license5);
97 #endif /* CONFIG_NO_STDOUT_DEBUG */
101 static void wpa_supplicant_fd_workaround(void)
105 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
106 * fd 0, 1, and 2 closed. This will cause some issues because many
107 * places in wpa_supplicant are still printing out to stdout. As a
108 * workaround, make sure that fd's 0, 1, and 2 are not used for other
110 for (i = 0; i < 3; i++) {
111 s = open("/dev/null", O_RDWR);
117 #endif /* __linux__ */
121 int main(int argc, char *argv[])
124 struct wpa_interface *ifaces, *iface;
125 int iface_count, exitcode = -1;
126 struct wpa_params params;
127 struct wpa_global *global;
129 if (os_program_init())
132 os_memset(¶ms, 0, sizeof(params));
133 params.wpa_debug_level = MSG_INFO;
135 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
140 wpa_supplicant_fd_workaround();
143 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qstuvW");
148 iface->bridge_ifname = optarg;
154 iface->confname = optarg;
157 iface->ctrl_interface = optarg;
160 iface->driver = optarg;
163 #ifdef CONFIG_NO_STDOUT_DEBUG
164 printf("Debugging disabled with "
165 "CONFIG_NO_STDOUT_DEBUG=y build time "
168 #else /* CONFIG_NO_STDOUT_DEBUG */
169 params.wpa_debug_level--;
171 #endif /* CONFIG_NO_STDOUT_DEBUG */
172 #ifdef CONFIG_DEBUG_FILE
174 params.wpa_debug_file_path = optarg;
176 #endif /* CONFIG_DEBUG_FILE */
178 params.ctrl_interface = optarg;
185 iface->ifname = optarg;
188 params.wpa_debug_show_keys++;
195 iface->driver_param = optarg;
198 os_free(params.pid_file);
199 params.pid_file = os_rel2abs_path(optarg);
202 params.wpa_debug_level++;
204 #ifdef CONFIG_DEBUG_SYSLOG
206 params.wpa_debug_syslog++;
208 #endif /* CONFIG_DEBUG_SYSLOG */
210 params.wpa_debug_timestamp++;
212 #ifdef CONFIG_CTRL_IFACE_DBUS
214 params.dbus_ctrl_interface = 1;
216 #endif /* CONFIG_CTRL_IFACE_DBUS */
218 printf("%s\n", wpa_supplicant_version);
222 params.wait_for_monitor++;
226 iface = os_realloc(ifaces, iface_count *
227 sizeof(struct wpa_interface));
231 iface = &ifaces[iface_count - 1];
232 os_memset(iface, 0, sizeof(*iface));
242 global = wpa_supplicant_init(¶ms);
243 if (global == NULL) {
244 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
249 for (i = 0; exitcode == 0 && i < iface_count; i++) {
250 if ((ifaces[i].confname == NULL &&
251 ifaces[i].ctrl_interface == NULL) ||
252 ifaces[i].ifname == NULL) {
253 if (iface_count == 1 && (params.ctrl_interface ||
254 params.dbus_ctrl_interface))
260 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
265 exitcode = wpa_supplicant_run(global);
267 wpa_supplicant_deinit(global);
271 os_free(params.pid_file);