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__ */
16 #include "wpa_supplicant_i.h"
18 #include "p2p_supplicant.h"
21 static void usage(void)
26 " wpa_supplicant [-BddhKLqq"
27 #ifdef CONFIG_DEBUG_SYSLOG
29 #endif /* CONFIG_DEBUG_SYSLOG */
31 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
33 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
35 "[-g<global ctrl>] \\\n"
37 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
38 "[-p<driver_param>] \\\n"
39 " [-b<br_ifname>] [-e<entropy file>]"
40 #ifdef CONFIG_DEBUG_FILE
42 #endif /* CONFIG_DEBUG_FILE */
44 " [-o<override driver>] [-O<override ctrl>] \\\n"
45 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
48 " [-m<P2P Device config file>] \\\n"
49 #endif /* CONFIG_P2P */
50 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
54 wpa_supplicant_version
, wpa_supplicant_license
);
56 for (i
= 0; wpa_drivers
[i
]; i
++) {
59 wpa_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 " -d = increase debugging verbosity (-dd even more)\n"
69 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
70 " -e = entropy file\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 " -G = global ctrl_interface group\n"
76 " -h = show this help text\n"
77 " -i = interface name\n"
78 " -I = additional configuration file\n"
79 " -K = include keys (passwords, etc.) in debug output\n"
80 " -L = show license (BSD)\n"
82 " -m = Configuration file for the P2P Device interface\n"
83 #endif /* CONFIG_P2P */
84 #ifdef CONFIG_MATCH_IFACE
85 " -M = start describing new matching interface\n"
86 #endif /* CONFIG_MATCH_IFACE */
87 " -N = start describing new interface\n"
88 " -o = override driver parameter for new interfaces\n"
89 " -O = override ctrl_interface parameter for new interfaces\n"
90 " -p = driver parameters\n"
92 " -q = decrease debugging verbosity (-qq even less)\n"
93 #ifdef CONFIG_DEBUG_SYSLOG
94 " -s = log output to syslog instead of stdout\n"
95 #endif /* CONFIG_DEBUG_SYSLOG */
96 " -t = include timestamp in debug messages\n"
97 #ifdef CONFIG_DEBUG_LINUX_TRACING
98 " -T = record to Linux tracing in addition to logging\n"
99 " (records all messages regardless of debug verbosity)\n"
100 #endif /* CONFIG_DEBUG_LINUX_TRACING */
101 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
102 " -u = enable DBus control interface\n"
103 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
104 " -v = show version\n"
105 " -W = wait for a control interface monitor before starting\n");
108 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
109 wpa_drivers
[0] ? wpa_drivers
[0]->name
: "nl80211");
110 #endif /* CONFIG_NO_STDOUT_DEBUG */
114 static void license(void)
116 #ifndef CONFIG_NO_STDOUT_DEBUG
117 printf("%s\n\n%s%s%s%s%s\n",
118 wpa_supplicant_version
,
119 wpa_supplicant_full_license1
,
120 wpa_supplicant_full_license2
,
121 wpa_supplicant_full_license3
,
122 wpa_supplicant_full_license4
,
123 wpa_supplicant_full_license5
);
124 #endif /* CONFIG_NO_STDOUT_DEBUG */
128 static void wpa_supplicant_fd_workaround(int start
)
131 static int fd
[3] = { -1, -1, -1 };
133 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
134 * fd 0, 1, and 2 closed. This will cause some issues because many
135 * places in wpa_supplicant are still printing out to stdout. As a
136 * workaround, make sure that fd's 0, 1, and 2 are not used for other
139 for (i
= 0; i
< 3; i
++) {
140 fd
[i
] = open("/dev/null", O_RDWR
);
148 for (i
= 0; i
< 3; i
++) {
155 #endif /* __linux__ */
159 #ifdef CONFIG_MATCH_IFACE
160 static int wpa_supplicant_init_match(struct wpa_global
*global
)
163 * The assumption is that the first driver is the primary driver and
164 * will handle the arrival / departure of interfaces.
166 if (wpa_drivers
[0]->global_init
&& !global
->drv_priv
[0]) {
167 global
->drv_priv
[0] = wpa_drivers
[0]->global_init(global
);
168 if (!global
->drv_priv
[0]) {
169 wpa_printf(MSG_ERROR
,
170 "Failed to initialize driver '%s'",
171 wpa_drivers
[0]->name
);
178 #endif /* CONFIG_MATCH_IFACE */
181 int main(int argc
, char *argv
[])
184 struct wpa_interface
*ifaces
, *iface
;
185 int iface_count
, exitcode
= -1;
186 struct wpa_params params
;
187 struct wpa_global
*global
;
189 if (os_program_init())
192 os_memset(¶ms
, 0, sizeof(params
));
193 params
.wpa_debug_level
= MSG_INFO
;
195 iface
= ifaces
= os_zalloc(sizeof(struct wpa_interface
));
200 wpa_supplicant_fd_workaround(1);
203 c
= getopt(argc
, argv
,
204 "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW");
209 iface
->bridge_ifname
= optarg
;
215 iface
->confname
= optarg
;
218 iface
->ctrl_interface
= optarg
;
221 iface
->driver
= optarg
;
224 #ifdef CONFIG_NO_STDOUT_DEBUG
225 printf("Debugging disabled with "
226 "CONFIG_NO_STDOUT_DEBUG=y build time "
229 #else /* CONFIG_NO_STDOUT_DEBUG */
230 params
.wpa_debug_level
--;
232 #endif /* CONFIG_NO_STDOUT_DEBUG */
234 params
.entropy_file
= optarg
;
236 #ifdef CONFIG_DEBUG_FILE
238 params
.wpa_debug_file_path
= optarg
;
240 #endif /* CONFIG_DEBUG_FILE */
242 params
.ctrl_interface
= optarg
;
245 params
.ctrl_interface_group
= optarg
;
252 iface
->ifname
= optarg
;
255 iface
->confanother
= optarg
;
258 params
.wpa_debug_show_keys
++;
266 params
.conf_p2p_dev
= optarg
;
268 #endif /* CONFIG_P2P */
270 params
.override_driver
= optarg
;
273 params
.override_ctrl_interface
= optarg
;
276 iface
->driver_param
= optarg
;
279 os_free(params
.pid_file
);
280 params
.pid_file
= os_rel2abs_path(optarg
);
283 params
.wpa_debug_level
++;
285 #ifdef CONFIG_DEBUG_SYSLOG
287 params
.wpa_debug_syslog
++;
289 #endif /* CONFIG_DEBUG_SYSLOG */
290 #ifdef CONFIG_DEBUG_LINUX_TRACING
292 params
.wpa_debug_tracing
++;
294 #endif /* CONFIG_DEBUG_LINUX_TRACING */
296 params
.wpa_debug_timestamp
++;
298 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
300 params
.dbus_ctrl_interface
= 1;
302 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
304 printf("%s\n", wpa_supplicant_version
);
308 params
.wait_for_monitor
++;
310 #ifdef CONFIG_MATCH_IFACE
312 params
.match_iface_count
++;
313 iface
= os_realloc_array(params
.match_ifaces
,
314 params
.match_iface_count
,
315 sizeof(struct wpa_interface
));
318 params
.match_ifaces
= iface
;
319 iface
= ¶ms
.match_ifaces
[params
.match_iface_count
-
321 os_memset(iface
, 0, sizeof(*iface
));
323 #endif /* CONFIG_MATCH_IFACE */
326 iface
= os_realloc_array(ifaces
, iface_count
,
327 sizeof(struct wpa_interface
));
331 iface
= &ifaces
[iface_count
- 1];
332 os_memset(iface
, 0, sizeof(*iface
));
342 global
= wpa_supplicant_init(¶ms
);
343 if (global
== NULL
) {
344 wpa_printf(MSG_ERROR
, "Failed to initialize wpa_supplicant");
348 wpa_printf(MSG_INFO
, "Successfully initialized "
352 if (fst_global_init()) {
353 wpa_printf(MSG_ERROR
, "Failed to initialize FST");
358 #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
359 if (!fst_global_add_ctrl(fst_ctrl_cli
))
360 wpa_printf(MSG_WARNING
, "Failed to add CLI FST ctrl");
363 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
364 struct wpa_supplicant
*wpa_s
;
366 if ((ifaces
[i
].confname
== NULL
&&
367 ifaces
[i
].ctrl_interface
== NULL
) ||
368 ifaces
[i
].ifname
== NULL
) {
369 if (iface_count
== 1 && (params
.ctrl_interface
||
370 #ifdef CONFIG_MATCH_IFACE
371 params
.match_iface_count
||
372 #endif /* CONFIG_MATCH_IFACE */
373 params
.dbus_ctrl_interface
))
379 wpa_s
= wpa_supplicant_add_iface(global
, &ifaces
[i
], NULL
);
386 #ifdef CONFIG_MATCH_IFACE
388 exitcode
= wpa_supplicant_init_match(global
);
389 #endif /* CONFIG_MATCH_IFACE */
392 exitcode
= wpa_supplicant_run(global
);
394 wpa_supplicant_deinit(global
);
399 wpa_supplicant_fd_workaround(0);
401 #ifdef CONFIG_MATCH_IFACE
402 os_free(params
.match_ifaces
);
403 #endif /* CONFIG_MATCH_IFACE */
404 os_free(params
.pid_file
);