2 * WPA Supplicant / main() function for UNIX like OSes and MinGW
3 * Copyright (c) 2003-2013, 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"
17 #include "p2p_supplicant.h"
20 static void usage(void)
25 " wpa_supplicant [-BddhKLqq"
26 #ifdef CONFIG_DEBUG_SYSLOG
28 #endif /* CONFIG_DEBUG_SYSLOG */
32 #endif /* CONFIG_DBUS */
34 "[-g<global ctrl>] \\\n"
36 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
37 "[-p<driver_param>] \\\n"
38 " [-b<br_ifname>] [-e<entropy file>]"
39 #ifdef CONFIG_DEBUG_FILE
41 #endif /* CONFIG_DEBUG_FILE */
43 " [-o<override driver>] [-O<override ctrl>] \\\n"
44 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
46 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
50 wpa_supplicant_version, wpa_supplicant_license);
52 for (i = 0; wpa_drivers[i]; i++) {
55 wpa_drivers[i]->desc);
58 #ifndef CONFIG_NO_STDOUT_DEBUG
60 " -b = optional bridge interface name\n"
61 " -B = run daemon in the background\n"
62 " -c = Configuration file\n"
63 " -C = ctrl_interface parameter (only used if -c is not)\n"
64 " -i = interface name\n"
65 " -I = additional configuration file\n"
66 " -d = increase debugging verbosity (-dd even more)\n"
67 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
68 " -e = entropy file\n");
69 #ifdef CONFIG_DEBUG_FILE
70 printf(" -f = log output to debug file instead of stdout\n");
71 #endif /* CONFIG_DEBUG_FILE */
72 printf(" -g = global ctrl_interface\n"
73 " -G = global ctrl_interface group\n"
74 " -K = include keys (passwords, etc.) in debug output\n");
75 #ifdef CONFIG_DEBUG_SYSLOG
76 printf(" -s = log output to syslog instead of stdout\n");
77 #endif /* CONFIG_DEBUG_SYSLOG */
78 #ifdef CONFIG_DEBUG_LINUX_TRACING
79 printf(" -T = record to Linux tracing in addition to logging\n");
80 printf(" (records all messages regardless of debug verbosity)\n");
81 #endif /* CONFIG_DEBUG_LINUX_TRACING */
82 printf(" -t = include timestamp in debug messages\n"
83 " -h = show this help text\n"
84 " -L = show license (BSD)\n"
85 " -o = override driver parameter for new interfaces\n"
86 " -O = override ctrl_interface parameter for new interfaces\n"
87 " -p = driver parameters\n"
89 " -q = decrease debugging verbosity (-qq even less)\n");
91 printf(" -u = enable DBus control interface\n");
92 #endif /* CONFIG_DBUS */
93 printf(" -v = show version\n"
94 " -W = wait for a control interface monitor before starting\n"
95 " -N = start describing new interface\n");
98 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
99 wpa_drivers[0] ? wpa_drivers[0]->name : "nl80211");
100 #endif /* CONFIG_NO_STDOUT_DEBUG */
104 static void license(void)
106 #ifndef CONFIG_NO_STDOUT_DEBUG
107 printf("%s\n\n%s%s%s%s%s\n",
108 wpa_supplicant_version,
109 wpa_supplicant_full_license1,
110 wpa_supplicant_full_license2,
111 wpa_supplicant_full_license3,
112 wpa_supplicant_full_license4,
113 wpa_supplicant_full_license5);
114 #endif /* CONFIG_NO_STDOUT_DEBUG */
118 static void wpa_supplicant_fd_workaround(int start)
121 static int fd[3] = { -1, -1, -1 };
123 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
124 * fd 0, 1, and 2 closed. This will cause some issues because many
125 * places in wpa_supplicant are still printing out to stdout. As a
126 * workaround, make sure that fd's 0, 1, and 2 are not used for other
129 for (i = 0; i < 3; i++) {
130 fd[i] = open("/dev/null", O_RDWR);
138 for (i = 0; i < 3; i++) {
145 #endif /* __linux__ */
149 int main(int argc, char *argv[])
152 struct wpa_interface *ifaces, *iface;
153 int iface_count, exitcode = -1;
154 struct wpa_params params;
155 struct wpa_global *global;
157 if (os_program_init())
160 os_memset(¶ms, 0, sizeof(params));
161 params.wpa_debug_level = MSG_INFO;
163 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
168 wpa_supplicant_fd_workaround(1);
170 #ifdef CONFIG_DRIVER_NDIS
171 void driver_ndis_init_ops(void);
172 driver_ndis_init_ops();
173 #endif /* CONFIG_DRIVER_NDIS */
176 c = getopt(argc, argv,
177 "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
182 iface->bridge_ifname = optarg;
188 iface->confname = optarg;
191 iface->ctrl_interface = optarg;
194 iface->driver = optarg;
197 #ifdef CONFIG_NO_STDOUT_DEBUG
198 printf("Debugging disabled with "
199 "CONFIG_NO_STDOUT_DEBUG=y build time "
202 #else /* CONFIG_NO_STDOUT_DEBUG */
203 params.wpa_debug_level--;
205 #endif /* CONFIG_NO_STDOUT_DEBUG */
207 params.entropy_file = optarg;
209 #ifdef CONFIG_DEBUG_FILE
211 params.wpa_debug_file_path = optarg;
213 #endif /* CONFIG_DEBUG_FILE */
215 params.ctrl_interface = optarg;
218 params.ctrl_interface_group = optarg;
225 iface->ifname = optarg;
228 iface->confanother = optarg;
231 params.wpa_debug_show_keys++;
238 params.override_driver = optarg;
241 params.override_ctrl_interface = optarg;
244 iface->driver_param = optarg;
247 os_free(params.pid_file);
248 params.pid_file = os_rel2abs_path(optarg);
251 params.wpa_debug_level++;
253 #ifdef CONFIG_DEBUG_SYSLOG
255 params.wpa_debug_syslog++;
257 #endif /* CONFIG_DEBUG_SYSLOG */
258 #ifdef CONFIG_DEBUG_LINUX_TRACING
260 params.wpa_debug_tracing++;
262 #endif /* CONFIG_DEBUG_LINUX_TRACING */
264 params.wpa_debug_timestamp++;
268 params.dbus_ctrl_interface = 1;
270 #endif /* CONFIG_DBUS */
272 printf("%s\n", wpa_supplicant_version);
276 params.wait_for_monitor++;
280 iface = os_realloc_array(ifaces, iface_count,
281 sizeof(struct wpa_interface));
285 iface = &ifaces[iface_count - 1];
286 os_memset(iface, 0, sizeof(*iface));
296 global = wpa_supplicant_init(¶ms);
297 if (global == NULL) {
298 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
302 wpa_printf(MSG_INFO, "Successfully initialized "
306 for (i = 0; exitcode == 0 && i < iface_count; i++) {
307 struct wpa_supplicant *wpa_s;
309 if ((ifaces[i].confname == NULL &&
310 ifaces[i].ctrl_interface == NULL) ||
311 ifaces[i].ifname == NULL) {
312 if (iface_count == 1 && (params.ctrl_interface ||
313 params.dbus_ctrl_interface))
319 wpa_s = wpa_supplicant_add_iface(global, &ifaces[i]);
325 if (wpa_s->global->p2p == NULL &&
327 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
328 wpas_p2p_add_p2pdev_interface(wpa_s) < 0)
330 #endif /* CONFIG_P2P */
334 exitcode = wpa_supplicant_run(global);
336 wpa_supplicant_deinit(global);
339 wpa_supplicant_fd_workaround(0);
341 os_free(params.pid_file);