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 const char *wpa_supplicant_version;
25 extern const char *wpa_supplicant_license;
26 #ifndef CONFIG_NO_STDOUT_DEBUG
27 extern const char *wpa_supplicant_full_license1;
28 extern const char *wpa_supplicant_full_license2;
29 extern const char *wpa_supplicant_full_license3;
30 extern const char *wpa_supplicant_full_license4;
31 extern const char *wpa_supplicant_full_license5;
32 #endif /* CONFIG_NO_STDOUT_DEBUG */
34 extern struct wpa_driver_ops *wpa_supplicant_drivers[];
37 static void usage(void)
42 " wpa_supplicant [-BddhKLqqtuvW] [-P<pid file>] "
43 "[-g<global ctrl>] \\\n"
44 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
45 "[-p<driver_param>] \\\n"
46 " [-b<br_ifname>] [-f<debug file>] \\\n"
47 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
49 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
52 wpa_supplicant_version, wpa_supplicant_license);
54 for (i = 0; wpa_supplicant_drivers[i]; i++) {
56 wpa_supplicant_drivers[i]->name,
57 wpa_supplicant_drivers[i]->desc);
60 #ifndef CONFIG_NO_STDOUT_DEBUG
62 " -b = optional bridge interface name\n"
63 " -B = run daemon in the background\n"
64 " -c = Configuration file\n"
65 " -C = ctrl_interface parameter (only used if -c is not)\n"
66 " -i = interface name\n"
67 " -d = increase debugging verbosity (-dd even more)\n"
69 #ifdef CONFIG_DEBUG_FILE
70 " -f = log output to debug file instead of stdout\n"
71 #endif /* CONFIG_DEBUG_FILE */
72 " -g = global ctrl_interface\n"
73 " -K = include keys (passwords, etc.) in debug output\n"
74 " -t = include timestamp in debug messages\n"
75 " -h = show this help text\n"
76 " -L = show license (GPL and BSD)\n");
77 printf(" -p = driver parameters\n"
79 " -q = decrease debugging verbosity (-qq even less)\n"
80 #ifdef CONFIG_CTRL_IFACE_DBUS
81 " -u = enable DBus control interface\n"
82 #endif /* CONFIG_CTRL_IFACE_DBUS */
83 " -v = show version\n"
84 " -W = wait for a control interface monitor before starting\n"
85 " -N = start describing new interface\n");
88 " wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf\n");
89 #endif /* CONFIG_NO_STDOUT_DEBUG */
93 static void license(void)
95 #ifndef CONFIG_NO_STDOUT_DEBUG
96 printf("%s\n\n%s%s%s%s%s\n",
97 wpa_supplicant_version,
98 wpa_supplicant_full_license1,
99 wpa_supplicant_full_license2,
100 wpa_supplicant_full_license3,
101 wpa_supplicant_full_license4,
102 wpa_supplicant_full_license5);
103 #endif /* CONFIG_NO_STDOUT_DEBUG */
107 static void wpa_supplicant_fd_workaround(void)
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
116 for (i = 0; i < 3; i++) {
117 s = open("/dev/null", O_RDWR);
123 #endif /* __linux__ */
127 int main(int argc, char *argv[])
130 struct wpa_interface *ifaces, *iface;
131 int iface_count, exitcode = -1;
132 struct wpa_params params;
133 struct wpa_global *global;
135 if (os_program_init())
138 os_memset(¶ms, 0, sizeof(params));
139 params.wpa_debug_level = MSG_INFO;
141 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
146 wpa_supplicant_fd_workaround();
149 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvW");
154 iface->bridge_ifname = optarg;
160 iface->confname = optarg;
163 iface->ctrl_interface = optarg;
166 iface->driver = optarg;
169 #ifdef CONFIG_NO_STDOUT_DEBUG
170 printf("Debugging disabled with "
171 "CONFIG_NO_STDOUT_DEBUG=y build time "
174 #else /* CONFIG_NO_STDOUT_DEBUG */
175 params.wpa_debug_level--;
177 #endif /* CONFIG_NO_STDOUT_DEBUG */
178 #ifdef CONFIG_DEBUG_FILE
180 params.wpa_debug_file_path = optarg;
182 #endif /* CONFIG_DEBUG_FILE */
184 params.ctrl_interface = optarg;
191 iface->ifname = optarg;
194 params.wpa_debug_show_keys++;
201 iface->driver_param = optarg;
204 os_free(params.pid_file);
205 params.pid_file = os_rel2abs_path(optarg);
208 params.wpa_debug_level++;
211 params.wpa_debug_timestamp++;
213 #ifdef CONFIG_CTRL_IFACE_DBUS
215 params.dbus_ctrl_interface = 1;
217 #endif /* CONFIG_CTRL_IFACE_DBUS */
219 printf("%s\n", wpa_supplicant_version);
223 params.wait_for_monitor++;
227 iface = os_realloc(ifaces, iface_count *
228 sizeof(struct wpa_interface));
232 iface = &ifaces[iface_count - 1];
233 os_memset(iface, 0, sizeof(*iface));
243 global = wpa_supplicant_init(¶ms);
244 if (global == NULL) {
245 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
250 for (i = 0; exitcode == 0 && i < iface_count; i++) {
251 if ((ifaces[i].confname == NULL &&
252 ifaces[i].ctrl_interface == NULL) ||
253 ifaces[i].ifname == NULL) {
254 if (iface_count == 1 && (params.ctrl_interface ||
255 params.dbus_ctrl_interface))
261 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
266 exitcode = wpa_supplicant_run(global);
268 wpa_supplicant_deinit(global);
272 os_free(params.pid_file);