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>] "
47 " [-m<P2P Device config file>] \\\n"
48 #endif /* CONFIG_P2P */
49 " [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
53 wpa_supplicant_version
, wpa_supplicant_license
);
55 for (i
= 0; wpa_drivers
[i
]; i
++) {
58 wpa_drivers
[i
]->desc
);
61 #ifndef CONFIG_NO_STDOUT_DEBUG
63 " -b = optional bridge interface name\n"
64 " -B = run daemon in the background\n"
65 " -c = Configuration file\n"
66 " -C = ctrl_interface parameter (only used if -c is not)\n"
67 " -i = interface name\n"
68 " -I = additional configuration file\n"
69 " -d = increase debugging verbosity (-dd even more)\n"
70 " -D = driver name (can be multiple drivers: nl80211,wext)\n"
71 " -e = entropy file\n");
72 #ifdef CONFIG_DEBUG_FILE
73 printf(" -f = log output to debug file instead of stdout\n");
74 #endif /* CONFIG_DEBUG_FILE */
75 printf(" -g = global ctrl_interface\n"
76 " -G = global ctrl_interface group\n"
77 " -K = include keys (passwords, etc.) in debug output\n");
78 #ifdef CONFIG_DEBUG_SYSLOG
79 printf(" -s = log output to syslog instead of stdout\n");
80 #endif /* CONFIG_DEBUG_SYSLOG */
81 #ifdef CONFIG_DEBUG_LINUX_TRACING
82 printf(" -T = record to Linux tracing in addition to logging\n");
83 printf(" (records all messages regardless of debug verbosity)\n");
84 #endif /* CONFIG_DEBUG_LINUX_TRACING */
85 printf(" -t = include timestamp in debug messages\n"
86 " -h = show this help text\n"
87 " -L = show license (BSD)\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");
94 printf(" -u = enable DBus control interface\n");
95 #endif /* CONFIG_DBUS */
96 printf(" -v = show version\n"
97 " -W = wait for a control interface monitor before starting\n"
99 " -m = Configuration file for the P2P Device interface\n"
100 #endif /* CONFIG_P2P */
101 " -N = start describing new interface\n");
104 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
105 wpa_drivers
[0] ? wpa_drivers
[0]->name
: "nl80211");
106 #endif /* CONFIG_NO_STDOUT_DEBUG */
110 static void license(void)
112 #ifndef CONFIG_NO_STDOUT_DEBUG
113 printf("%s\n\n%s%s%s%s%s\n",
114 wpa_supplicant_version
,
115 wpa_supplicant_full_license1
,
116 wpa_supplicant_full_license2
,
117 wpa_supplicant_full_license3
,
118 wpa_supplicant_full_license4
,
119 wpa_supplicant_full_license5
);
120 #endif /* CONFIG_NO_STDOUT_DEBUG */
124 static void wpa_supplicant_fd_workaround(int start
)
127 static int fd
[3] = { -1, -1, -1 };
129 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
130 * fd 0, 1, and 2 closed. This will cause some issues because many
131 * places in wpa_supplicant are still printing out to stdout. As a
132 * workaround, make sure that fd's 0, 1, and 2 are not used for other
135 for (i
= 0; i
< 3; i
++) {
136 fd
[i
] = open("/dev/null", O_RDWR
);
144 for (i
= 0; i
< 3; i
++) {
151 #endif /* __linux__ */
155 int main(int argc
, char *argv
[])
158 struct wpa_interface
*ifaces
, *iface
;
159 int iface_count
, exitcode
= -1;
160 struct wpa_params params
;
161 struct wpa_global
*global
;
163 if (os_program_init())
166 os_memset(¶ms
, 0, sizeof(params
));
167 params
.wpa_debug_level
= MSG_INFO
;
169 iface
= ifaces
= os_zalloc(sizeof(struct wpa_interface
));
174 wpa_supplicant_fd_workaround(1);
177 c
= getopt(argc
, argv
,
178 "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsTtuvW");
183 iface
->bridge_ifname
= optarg
;
189 iface
->confname
= optarg
;
192 iface
->ctrl_interface
= optarg
;
195 iface
->driver
= optarg
;
198 #ifdef CONFIG_NO_STDOUT_DEBUG
199 printf("Debugging disabled with "
200 "CONFIG_NO_STDOUT_DEBUG=y build time "
203 #else /* CONFIG_NO_STDOUT_DEBUG */
204 params
.wpa_debug_level
--;
206 #endif /* CONFIG_NO_STDOUT_DEBUG */
208 params
.entropy_file
= optarg
;
210 #ifdef CONFIG_DEBUG_FILE
212 params
.wpa_debug_file_path
= optarg
;
214 #endif /* CONFIG_DEBUG_FILE */
216 params
.ctrl_interface
= optarg
;
219 params
.ctrl_interface_group
= optarg
;
226 iface
->ifname
= optarg
;
229 iface
->confanother
= optarg
;
232 params
.wpa_debug_show_keys
++;
240 iface
->conf_p2p_dev
= optarg
;
242 #endif /* CONFIG_P2P */
244 params
.override_driver
= optarg
;
247 params
.override_ctrl_interface
= optarg
;
250 iface
->driver_param
= optarg
;
253 os_free(params
.pid_file
);
254 params
.pid_file
= os_rel2abs_path(optarg
);
257 params
.wpa_debug_level
++;
259 #ifdef CONFIG_DEBUG_SYSLOG
261 params
.wpa_debug_syslog
++;
263 #endif /* CONFIG_DEBUG_SYSLOG */
264 #ifdef CONFIG_DEBUG_LINUX_TRACING
266 params
.wpa_debug_tracing
++;
268 #endif /* CONFIG_DEBUG_LINUX_TRACING */
270 params
.wpa_debug_timestamp
++;
274 params
.dbus_ctrl_interface
= 1;
276 #endif /* CONFIG_DBUS */
278 printf("%s\n", wpa_supplicant_version
);
282 params
.wait_for_monitor
++;
286 iface
= os_realloc_array(ifaces
, iface_count
,
287 sizeof(struct wpa_interface
));
291 iface
= &ifaces
[iface_count
- 1];
292 os_memset(iface
, 0, sizeof(*iface
));
302 global
= wpa_supplicant_init(¶ms
);
303 if (global
== NULL
) {
304 wpa_printf(MSG_ERROR
, "Failed to initialize wpa_supplicant");
308 wpa_printf(MSG_INFO
, "Successfully initialized "
312 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
313 struct wpa_supplicant
*wpa_s
;
315 if ((ifaces
[i
].confname
== NULL
&&
316 ifaces
[i
].ctrl_interface
== NULL
) ||
317 ifaces
[i
].ifname
== NULL
) {
318 if (iface_count
== 1 && (params
.ctrl_interface
||
319 params
.dbus_ctrl_interface
))
325 wpa_s
= wpa_supplicant_add_iface(global
, &ifaces
[i
]);
333 exitcode
= wpa_supplicant_run(global
);
335 wpa_supplicant_deinit(global
);
338 wpa_supplicant_fd_workaround(0);
340 os_free(params
.pid_file
);