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 static void usage(void)
29 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
30 "[-g<global ctrl>] \\\n"
31 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
32 "[-p<driver_param>] \\\n"
33 " [-b<br_ifname>] [-f<debug file>] \\\n"
34 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
36 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
39 wpa_supplicant_version, wpa_supplicant_license);
41 for (i = 0; wpa_supplicant_drivers[i]; i++) {
43 wpa_supplicant_drivers[i]->name,
44 wpa_supplicant_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 " -d = increase debugging verbosity (-dd even more)\n"
55 " -D = driver name (can be multiple drivers: nl80211,wext)\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 printf(" -t = include timestamp in debug messages\n"
65 " -h = show this help text\n"
66 " -L = show license (GPL and BSD)\n"
67 " -p = driver parameters\n"
69 " -q = decrease debugging verbosity (-qq even less)\n");
70 #ifdef CONFIG_CTRL_IFACE_DBUS
71 printf(" -u = enable DBus control interface\n");
72 #endif /* CONFIG_CTRL_IFACE_DBUS */
73 printf(" -v = show version\n"
74 " -W = wait for a control interface monitor before starting\n"
75 " -N = start describing new interface\n");
78 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
79 wpa_supplicant_drivers[i] ?
80 wpa_supplicant_drivers[i]->name : "wext");
81 #endif /* CONFIG_NO_STDOUT_DEBUG */
85 static void license(void)
87 #ifndef CONFIG_NO_STDOUT_DEBUG
88 printf("%s\n\n%s%s%s%s%s\n",
89 wpa_supplicant_version,
90 wpa_supplicant_full_license1,
91 wpa_supplicant_full_license2,
92 wpa_supplicant_full_license3,
93 wpa_supplicant_full_license4,
94 wpa_supplicant_full_license5);
95 #endif /* CONFIG_NO_STDOUT_DEBUG */
99 static void wpa_supplicant_fd_workaround(void)
103 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
104 * fd 0, 1, and 2 closed. This will cause some issues because many
105 * places in wpa_supplicant are still printing out to stdout. As a
106 * workaround, make sure that fd's 0, 1, and 2 are not used for other
108 for (i = 0; i < 3; i++) {
109 s = open("/dev/null", O_RDWR);
115 #endif /* __linux__ */
119 int main(int argc, char *argv[])
122 struct wpa_interface *ifaces, *iface;
123 int iface_count, exitcode = -1;
124 struct wpa_params params;
125 struct wpa_global *global;
127 if (os_program_init())
130 os_memset(¶ms, 0, sizeof(params));
131 params.wpa_debug_level = MSG_INFO;
133 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
138 wpa_supplicant_fd_workaround();
141 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qstuvW");
146 iface->bridge_ifname = optarg;
152 iface->confname = optarg;
155 iface->ctrl_interface = optarg;
158 iface->driver = optarg;
161 #ifdef CONFIG_NO_STDOUT_DEBUG
162 printf("Debugging disabled with "
163 "CONFIG_NO_STDOUT_DEBUG=y build time "
166 #else /* CONFIG_NO_STDOUT_DEBUG */
167 params.wpa_debug_level--;
169 #endif /* CONFIG_NO_STDOUT_DEBUG */
170 #ifdef CONFIG_DEBUG_FILE
172 params.wpa_debug_file_path = optarg;
174 #endif /* CONFIG_DEBUG_FILE */
176 params.ctrl_interface = optarg;
183 iface->ifname = optarg;
186 params.wpa_debug_show_keys++;
193 iface->driver_param = optarg;
196 os_free(params.pid_file);
197 params.pid_file = os_rel2abs_path(optarg);
200 params.wpa_debug_level++;
202 #ifdef CONFIG_DEBUG_SYSLOG
204 params.wpa_debug_syslog++;
206 #endif /* CONFIG_DEBUG_SYSLOG */
208 params.wpa_debug_timestamp++;
210 #ifdef CONFIG_CTRL_IFACE_DBUS
212 params.dbus_ctrl_interface = 1;
214 #endif /* CONFIG_CTRL_IFACE_DBUS */
216 printf("%s\n", wpa_supplicant_version);
220 params.wait_for_monitor++;
224 iface = os_realloc(ifaces, iface_count *
225 sizeof(struct wpa_interface));
229 iface = &ifaces[iface_count - 1];
230 os_memset(iface, 0, sizeof(*iface));
240 global = wpa_supplicant_init(¶ms);
241 if (global == NULL) {
242 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
247 for (i = 0; exitcode == 0 && i < iface_count; i++) {
248 if ((ifaces[i].confname == NULL &&
249 ifaces[i].ctrl_interface == NULL) ||
250 ifaces[i].ifname == NULL) {
251 if (iface_count == 1 && (params.ctrl_interface ||
252 params.dbus_ctrl_interface))
258 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
263 exitcode = wpa_supplicant_run(global);
265 wpa_supplicant_deinit(global);
269 os_free(params.pid_file);