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>] [-I<config file>] "
39 wpa_supplicant_version, wpa_supplicant_license);
41 for (i = 0; wpa_drivers[i]; i++) {
44 wpa_drivers[i]->desc);
47 #ifndef CONFIG_NO_STDOUT_DEBUG
49 " -b = optional bridge interface name\n"
50 " -B = run daemon in the background\n"
51 " -c = Configuration file\n"
52 " -C = ctrl_interface parameter (only used if -c is not)\n"
53 " -i = interface name\n"
54 " -I = additional configuration file\n"
55 " -d = increase debugging verbosity (-dd even more)\n"
56 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
57 " -e = entropy file\n");
58 #ifdef CONFIG_DEBUG_FILE
59 printf(" -f = log output to debug file instead of stdout\n");
60 #endif /* CONFIG_DEBUG_FILE */
61 printf(" -g = global ctrl_interface\n"
62 " -K = include keys (passwords, etc.) in debug output\n");
63 #ifdef CONFIG_DEBUG_SYSLOG
64 printf(" -s = log output to syslog instead of stdout\n");
65 #endif /* CONFIG_DEBUG_SYSLOG */
66 #ifdef CONFIG_DEBUG_LINUX_TRACING
67 printf(" -T = record to Linux tracing in addition to logging\n");
68 printf(" (records all messages regardless of debug verbosity)\n");
69 #endif /* CONFIG_DEBUG_LINUX_TRACING */
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[0] ? wpa_drivers[0]->name : "nl80211");
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(int start)
109 static int fd[3] = { -1, -1, -1 };
111 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
112 * fd 0, 1, and 2 closed. This will cause some issues because many
113 * places in wpa_supplicant are still printing out to stdout. As a
114 * workaround, make sure that fd's 0, 1, and 2 are not used for other
117 for (i = 0; i < 3; i++) {
118 fd[i] = open("/dev/null", O_RDWR);
126 for (i = 0; i < 3; i++) {
133 #endif /* __linux__ */
137 int main(int argc, char *argv[])
140 struct wpa_interface *ifaces, *iface;
141 int iface_count, exitcode = -1;
142 struct wpa_params params;
143 struct wpa_global *global;
145 if (os_program_init())
148 os_memset(¶ms, 0, sizeof(params));
149 params.wpa_debug_level = MSG_INFO;
151 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
156 wpa_supplicant_fd_workaround(1);
159 c = getopt(argc, argv,
160 "b:Bc:C:D:de:f:g:hi:I:KLNo:O:p:P:qsTtuvW");
165 iface->bridge_ifname = optarg;
171 iface->confname = optarg;
174 iface->ctrl_interface = optarg;
177 iface->driver = optarg;
180 #ifdef CONFIG_NO_STDOUT_DEBUG
181 printf("Debugging disabled with "
182 "CONFIG_NO_STDOUT_DEBUG=y build time "
185 #else /* CONFIG_NO_STDOUT_DEBUG */
186 params.wpa_debug_level--;
188 #endif /* CONFIG_NO_STDOUT_DEBUG */
190 params.entropy_file = optarg;
192 #ifdef CONFIG_DEBUG_FILE
194 params.wpa_debug_file_path = optarg;
196 #endif /* CONFIG_DEBUG_FILE */
198 params.ctrl_interface = optarg;
205 iface->ifname = optarg;
208 iface->confanother = optarg;
211 params.wpa_debug_show_keys++;
218 params.override_driver = optarg;
221 params.override_ctrl_interface = optarg;
224 iface->driver_param = optarg;
227 os_free(params.pid_file);
228 params.pid_file = os_rel2abs_path(optarg);
231 params.wpa_debug_level++;
233 #ifdef CONFIG_DEBUG_SYSLOG
235 params.wpa_debug_syslog++;
237 #endif /* CONFIG_DEBUG_SYSLOG */
238 #ifdef CONFIG_DEBUG_LINUX_TRACING
240 params.wpa_debug_tracing++;
242 #endif /* CONFIG_DEBUG_LINUX_TRACING */
244 params.wpa_debug_timestamp++;
248 params.dbus_ctrl_interface = 1;
250 #endif /* CONFIG_DBUS */
252 printf("%s\n", wpa_supplicant_version);
256 params.wait_for_monitor++;
260 iface = os_realloc_array(ifaces, iface_count,
261 sizeof(struct wpa_interface));
265 iface = &ifaces[iface_count - 1];
266 os_memset(iface, 0, sizeof(*iface));
276 global = wpa_supplicant_init(¶ms);
277 if (global == NULL) {
278 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
282 wpa_printf(MSG_INFO, "Successfully initialized "
286 for (i = 0; exitcode == 0 && i < iface_count; i++) {
287 if ((ifaces[i].confname == NULL &&
288 ifaces[i].ctrl_interface == NULL) ||
289 ifaces[i].ifname == NULL) {
290 if (iface_count == 1 && (params.ctrl_interface ||
291 params.dbus_ctrl_interface))
297 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
302 exitcode = wpa_supplicant_run(global);
304 wpa_supplicant_deinit(global);
307 wpa_supplicant_fd_workaround(0);
309 os_free(params.pid_file);