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(void)
108 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
109 * fd 0, 1, and 2 closed. This will cause some issues because many
110 * places in wpa_supplicant are still printing out to stdout. As a
111 * workaround, make sure that fd's 0, 1, and 2 are not used for other
113 for (i = 0; i < 3; i++) {
114 s = open("/dev/null", O_RDWR);
120 #endif /* __linux__ */
124 int main(int argc, char *argv[])
127 struct wpa_interface *ifaces, *iface;
128 int iface_count, exitcode = -1;
129 struct wpa_params params;
130 struct wpa_global *global;
132 if (os_program_init())
135 os_memset(¶ms, 0, sizeof(params));
136 params.wpa_debug_level = MSG_INFO;
138 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
143 wpa_supplicant_fd_workaround();
146 c = getopt(argc, argv,
147 "b:Bc:C:D:de:f:g:hi:KLNo:O:p:P:qsTtuvW");
152 iface->bridge_ifname = optarg;
158 iface->confname = optarg;
161 iface->ctrl_interface = optarg;
164 iface->driver = optarg;
167 #ifdef CONFIG_NO_STDOUT_DEBUG
168 printf("Debugging disabled with "
169 "CONFIG_NO_STDOUT_DEBUG=y build time "
172 #else /* CONFIG_NO_STDOUT_DEBUG */
173 params.wpa_debug_level--;
175 #endif /* CONFIG_NO_STDOUT_DEBUG */
177 params.entropy_file = optarg;
179 #ifdef CONFIG_DEBUG_FILE
181 params.wpa_debug_file_path = optarg;
183 #endif /* CONFIG_DEBUG_FILE */
185 params.ctrl_interface = optarg;
192 iface->ifname = optarg;
195 params.wpa_debug_show_keys++;
202 params.override_driver = optarg;
205 params.override_ctrl_interface = optarg;
208 iface->driver_param = optarg;
211 os_free(params.pid_file);
212 params.pid_file = os_rel2abs_path(optarg);
215 params.wpa_debug_level++;
217 #ifdef CONFIG_DEBUG_SYSLOG
219 params.wpa_debug_syslog++;
221 #endif /* CONFIG_DEBUG_SYSLOG */
222 #ifdef CONFIG_DEBUG_LINUX_TRACING
224 params.wpa_debug_tracing++;
226 #endif /* CONFIG_DEBUG_LINUX_TRACING */
228 params.wpa_debug_timestamp++;
232 params.dbus_ctrl_interface = 1;
234 #endif /* CONFIG_DBUS */
236 printf("%s\n", wpa_supplicant_version);
240 params.wait_for_monitor++;
244 iface = os_realloc(ifaces, iface_count *
245 sizeof(struct wpa_interface));
249 iface = &ifaces[iface_count - 1];
250 os_memset(iface, 0, sizeof(*iface));
260 global = wpa_supplicant_init(¶ms);
261 if (global == NULL) {
262 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
266 wpa_printf(MSG_INFO, "Successfully initialized "
270 for (i = 0; exitcode == 0 && i < iface_count; i++) {
271 if ((ifaces[i].confname == NULL &&
272 ifaces[i].ctrl_interface == NULL) ||
273 ifaces[i].ifname == NULL) {
274 if (iface_count == 1 && (params.ctrl_interface ||
275 params.dbus_ctrl_interface))
281 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
286 exitcode = wpa_supplicant_run(global);
288 wpa_supplicant_deinit(global);
292 os_free(params.pid_file);