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.
20 #endif /* __linux__ */
23 #include "wpa_supplicant_i.h"
26 extern const char *wpa_supplicant_version;
27 extern const char *wpa_supplicant_license;
28 #ifndef CONFIG_NO_STDOUT_DEBUG
29 extern const char *wpa_supplicant_full_license1;
30 extern const char *wpa_supplicant_full_license2;
31 extern const char *wpa_supplicant_full_license3;
32 extern const char *wpa_supplicant_full_license4;
33 extern const char *wpa_supplicant_full_license5;
34 #endif /* CONFIG_NO_STDOUT_DEBUG */
36 extern struct wpa_driver_ops *wpa_supplicant_drivers[];
39 static void usage(void)
44 " wpa_supplicant [-BddhKLqqtuvwW] [-P<pid file>] "
45 "[-g<global ctrl>] \\\n"
46 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
47 "[-p<driver_param>] \\\n"
48 " [-b<br_ifname>] [-f<debug file>] \\\n"
49 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
51 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
54 wpa_supplicant_version, wpa_supplicant_license);
56 for (i = 0; wpa_supplicant_drivers[i]; i++) {
58 wpa_supplicant_drivers[i]->name,
59 wpa_supplicant_drivers[i]->desc);
62 #ifndef CONFIG_NO_STDOUT_DEBUG
64 " -b = optional bridge interface name\n"
65 " -B = run daemon in the background\n"
66 " -c = Configuration file\n"
67 " -C = ctrl_interface parameter (only used if -c is not)\n"
68 " -i = interface name\n"
69 " -d = increase debugging verbosity (-dd even more)\n"
71 #ifdef CONFIG_DEBUG_FILE
72 " -f = log output to debug file instead of stdout\n"
73 #endif /* CONFIG_DEBUG_FILE */
74 " -g = global ctrl_interface\n"
75 " -K = include keys (passwords, etc.) in debug output\n"
76 " -t = include timestamp in debug messages\n"
77 " -h = show this help text\n"
78 " -L = show license (GPL and BSD)\n");
79 printf(" -p = driver parameters\n"
81 " -q = decrease debugging verbosity (-qq even less)\n"
82 #ifdef CONFIG_CTRL_IFACE_DBUS
83 " -u = enable DBus control interface\n"
84 #endif /* CONFIG_CTRL_IFACE_DBUS */
85 " -v = show version\n"
86 " -w = wait for interface to be added, if needed\n"
87 " -W = wait for a control interface monitor before starting\n"
88 " -N = start describing new interface\n");
91 " wpa_supplicant -Dbsd -iwlan0 -c/etc/wpa_supplicant.conf\n");
92 #endif /* CONFIG_NO_STDOUT_DEBUG */
96 static void license(void)
98 #ifndef CONFIG_NO_STDOUT_DEBUG
99 printf("%s\n\n%s%s%s%s%s\n",
100 wpa_supplicant_version,
101 wpa_supplicant_full_license1,
102 wpa_supplicant_full_license2,
103 wpa_supplicant_full_license3,
104 wpa_supplicant_full_license4,
105 wpa_supplicant_full_license5);
106 #endif /* CONFIG_NO_STDOUT_DEBUG */
110 static void wpa_supplicant_fd_workaround(void)
114 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
115 * fd 0, 1, and 2 closed. This will cause some issues because many
116 * places in wpa_supplicant are still printing out to stdout. As a
117 * workaround, make sure that fd's 0, 1, and 2 are not used for other
119 for (i = 0; i < 3; i++) {
120 s = open("/dev/null", O_RDWR);
126 #endif /* __linux__ */
130 int main(int argc, char *argv[])
133 struct wpa_interface *ifaces, *iface;
134 int iface_count, exitcode = -1;
135 struct wpa_params params;
136 struct wpa_global *global;
138 if (os_program_init())
141 os_memset(¶ms, 0, sizeof(params));
142 params.wpa_debug_level = MSG_INFO;
144 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
149 wpa_supplicant_fd_workaround();
152 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvwW");
157 iface->bridge_ifname = optarg;
163 iface->confname = optarg;
166 iface->ctrl_interface = optarg;
169 iface->driver = optarg;
172 #ifdef CONFIG_NO_STDOUT_DEBUG
173 printf("Debugging disabled with "
174 "CONFIG_NO_STDOUT_DEBUG=y build time "
177 #else /* CONFIG_NO_STDOUT_DEBUG */
178 params.wpa_debug_level--;
180 #endif /* CONFIG_NO_STDOUT_DEBUG */
181 #ifdef CONFIG_DEBUG_FILE
183 params.wpa_debug_file_path = optarg;
185 #endif /* CONFIG_DEBUG_FILE */
187 params.ctrl_interface = optarg;
194 iface->ifname = optarg;
197 params.wpa_debug_show_keys++;
204 iface->driver_param = optarg;
207 os_free(params.pid_file);
208 params.pid_file = os_rel2abs_path(optarg);
211 params.wpa_debug_level++;
214 params.wpa_debug_timestamp++;
216 #ifdef CONFIG_CTRL_IFACE_DBUS
218 params.dbus_ctrl_interface = 1;
220 #endif /* CONFIG_CTRL_IFACE_DBUS */
222 printf("%s\n", wpa_supplicant_version);
226 params.wait_for_interface++;
229 params.wait_for_monitor++;
233 iface = os_realloc(ifaces, iface_count *
234 sizeof(struct wpa_interface));
238 iface = &ifaces[iface_count - 1];
239 os_memset(iface, 0, sizeof(*iface));
249 global = wpa_supplicant_init(¶ms);
250 if (global == NULL) {
251 printf("Failed to initialize wpa_supplicant\n");
256 for (i = 0; exitcode == 0 && i < iface_count; i++) {
257 if ((ifaces[i].confname == NULL &&
258 ifaces[i].ctrl_interface == NULL) ||
259 ifaces[i].ifname == NULL) {
260 if (iface_count == 1 && (params.ctrl_interface ||
261 params.dbus_ctrl_interface))
267 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
272 exitcode = wpa_supplicant_run(global);
274 wpa_supplicant_deinit(global);
278 os_free(params.pid_file);