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 printf(" -t = include timestamp in debug messages\n"
65 " -h = show this help text\n"
66 " -L = show license (BSD)\n"
67 " -o = override driver parameter for new interfaces\n"
68 " -O = override ctrl_interface parameter for new interfaces\n"
69 " -p = driver parameters\n"
71 " -q = decrease debugging verbosity (-qq even less)\n");
73 printf(" -u = enable DBus control interface\n");
74 #endif /* CONFIG_DBUS */
75 printf(" -v = show version\n"
76 " -W = wait for a control interface monitor before starting\n"
77 " -N = start describing new interface\n");
80 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
81 wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
82 #endif /* CONFIG_NO_STDOUT_DEBUG */
86 static void license(void)
88 #ifndef CONFIG_NO_STDOUT_DEBUG
89 printf("%s\n\n%s%s%s%s%s\n",
90 wpa_supplicant_version,
91 wpa_supplicant_full_license1,
92 wpa_supplicant_full_license2,
93 wpa_supplicant_full_license3,
94 wpa_supplicant_full_license4,
95 wpa_supplicant_full_license5);
96 #endif /* CONFIG_NO_STDOUT_DEBUG */
100 static void wpa_supplicant_fd_workaround(void)
104 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
105 * fd 0, 1, and 2 closed. This will cause some issues because many
106 * places in wpa_supplicant are still printing out to stdout. As a
107 * workaround, make sure that fd's 0, 1, and 2 are not used for other
109 for (i = 0; i < 3; i++) {
110 s = open("/dev/null", O_RDWR);
116 #endif /* __linux__ */
120 int main(int argc, char *argv[])
123 struct wpa_interface *ifaces, *iface;
124 int iface_count, exitcode = -1;
125 struct wpa_params params;
126 struct wpa_global *global;
128 if (os_program_init())
131 os_memset(¶ms, 0, sizeof(params));
132 params.wpa_debug_level = MSG_INFO;
134 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
139 wpa_supplicant_fd_workaround();
142 c = getopt(argc, argv, "b:Bc:C:D:de:f:g:hi:KLNo:O:p:P:qstuvW");
147 iface->bridge_ifname = optarg;
153 iface->confname = optarg;
156 iface->ctrl_interface = optarg;
159 iface->driver = optarg;
162 #ifdef CONFIG_NO_STDOUT_DEBUG
163 printf("Debugging disabled with "
164 "CONFIG_NO_STDOUT_DEBUG=y build time "
167 #else /* CONFIG_NO_STDOUT_DEBUG */
168 params.wpa_debug_level--;
170 #endif /* CONFIG_NO_STDOUT_DEBUG */
172 params.entropy_file = optarg;
174 #ifdef CONFIG_DEBUG_FILE
176 params.wpa_debug_file_path = optarg;
178 #endif /* CONFIG_DEBUG_FILE */
180 params.ctrl_interface = optarg;
187 iface->ifname = optarg;
190 params.wpa_debug_show_keys++;
197 params.override_driver = optarg;
200 params.override_ctrl_interface = optarg;
203 iface->driver_param = optarg;
206 os_free(params.pid_file);
207 params.pid_file = os_rel2abs_path(optarg);
210 params.wpa_debug_level++;
212 #ifdef CONFIG_DEBUG_SYSLOG
214 params.wpa_debug_syslog++;
216 #endif /* CONFIG_DEBUG_SYSLOG */
218 params.wpa_debug_timestamp++;
222 params.dbus_ctrl_interface = 1;
224 #endif /* CONFIG_DBUS */
226 printf("%s\n", wpa_supplicant_version);
230 params.wait_for_monitor++;
234 iface = os_realloc(ifaces, iface_count *
235 sizeof(struct wpa_interface));
239 iface = &ifaces[iface_count - 1];
240 os_memset(iface, 0, sizeof(*iface));
250 global = wpa_supplicant_init(¶ms);
251 if (global == NULL) {
252 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
257 for (i = 0; exitcode == 0 && i < iface_count; i++) {
258 if ((ifaces[i].confname == NULL &&
259 ifaces[i].ctrl_interface == NULL) ||
260 ifaces[i].ifname == NULL) {
261 if (iface_count == 1 && (params.ctrl_interface ||
262 params.dbus_ctrl_interface))
268 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
273 exitcode = wpa_supplicant_run(global);
275 wpa_supplicant_deinit(global);
279 os_free(params.pid_file);