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.
18 #endif /* __linux__ */
21 #include "wpa_supplicant_i.h"
24 static void usage(void)
29 " wpa_supplicant [-BddhKLqqtuvW] [-P<pid file>] "
30 "[-g<global ctrl>] \\\n"
31 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
32 "[-p<driver_param>] \\\n"
33 " [-b<br_ifname>] [-f<debug file>] \\\n"
34 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
36 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
39 wpa_supplicant_version
, wpa_supplicant_license
);
41 for (i
= 0; wpa_supplicant_drivers
[i
]; i
++) {
43 wpa_supplicant_drivers
[i
]->name
,
44 wpa_supplicant_drivers
[i
]->desc
);
47 #ifndef CONFIG_NO_STDOUT_DEBUG
49 " -b = optional bridge interface name\n"
50 " -B = run daemon in the background\n"
51 " -c = Configuration file\n"
52 " -C = ctrl_interface parameter (only used if -c is not)\n"
53 " -i = interface name\n"
54 " -d = increase debugging verbosity (-dd even more)\n"
56 #ifdef CONFIG_DEBUG_FILE
57 " -f = log output to debug file instead of stdout\n"
58 #endif /* CONFIG_DEBUG_FILE */
59 " -g = global ctrl_interface\n"
60 " -K = include keys (passwords, etc.) in debug output\n"
61 " -t = include timestamp in debug messages\n"
62 " -h = show this help text\n"
63 " -L = show license (GPL and BSD)\n");
64 printf(" -p = driver parameters\n"
66 " -q = decrease debugging verbosity (-qq even less)\n"
67 #ifdef CONFIG_CTRL_IFACE_DBUS
68 " -u = enable DBus control interface\n"
69 #endif /* CONFIG_CTRL_IFACE_DBUS */
70 " -v = show version\n"
71 " -W = wait for a control interface monitor before starting\n"
72 " -N = start describing new interface\n");
75 " wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf\n");
76 #endif /* CONFIG_NO_STDOUT_DEBUG */
80 static void license(void)
82 #ifndef CONFIG_NO_STDOUT_DEBUG
83 printf("%s\n\n%s%s%s%s%s\n",
84 wpa_supplicant_version
,
85 wpa_supplicant_full_license1
,
86 wpa_supplicant_full_license2
,
87 wpa_supplicant_full_license3
,
88 wpa_supplicant_full_license4
,
89 wpa_supplicant_full_license5
);
90 #endif /* CONFIG_NO_STDOUT_DEBUG */
94 static void wpa_supplicant_fd_workaround(void)
98 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
99 * fd 0, 1, and 2 closed. This will cause some issues because many
100 * places in wpa_supplicant are still printing out to stdout. As a
101 * workaround, make sure that fd's 0, 1, and 2 are not used for other
103 for (i
= 0; i
< 3; i
++) {
104 s
= open("/dev/null", O_RDWR
);
110 #endif /* __linux__ */
114 int main(int argc
, char *argv
[])
117 struct wpa_interface
*ifaces
, *iface
;
118 int iface_count
, exitcode
= -1;
119 struct wpa_params params
;
120 struct wpa_global
*global
;
122 if (os_program_init())
125 os_memset(¶ms
, 0, sizeof(params
));
126 params
.wpa_debug_level
= MSG_INFO
;
128 iface
= ifaces
= os_zalloc(sizeof(struct wpa_interface
));
133 wpa_supplicant_fd_workaround();
136 c
= getopt(argc
, argv
, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvW");
141 iface
->bridge_ifname
= optarg
;
147 iface
->confname
= optarg
;
150 iface
->ctrl_interface
= optarg
;
153 iface
->driver
= optarg
;
156 #ifdef CONFIG_NO_STDOUT_DEBUG
157 printf("Debugging disabled with "
158 "CONFIG_NO_STDOUT_DEBUG=y build time "
161 #else /* CONFIG_NO_STDOUT_DEBUG */
162 params
.wpa_debug_level
--;
164 #endif /* CONFIG_NO_STDOUT_DEBUG */
165 #ifdef CONFIG_DEBUG_FILE
167 params
.wpa_debug_file_path
= optarg
;
169 #endif /* CONFIG_DEBUG_FILE */
171 params
.ctrl_interface
= optarg
;
178 iface
->ifname
= optarg
;
181 params
.wpa_debug_show_keys
++;
188 iface
->driver_param
= optarg
;
191 os_free(params
.pid_file
);
192 params
.pid_file
= os_rel2abs_path(optarg
);
195 params
.wpa_debug_level
++;
198 params
.wpa_debug_timestamp
++;
200 #ifdef CONFIG_CTRL_IFACE_DBUS
202 params
.dbus_ctrl_interface
= 1;
204 #endif /* CONFIG_CTRL_IFACE_DBUS */
206 printf("%s\n", wpa_supplicant_version
);
210 params
.wait_for_monitor
++;
214 iface
= os_realloc(ifaces
, iface_count
*
215 sizeof(struct wpa_interface
));
219 iface
= &ifaces
[iface_count
- 1];
220 os_memset(iface
, 0, sizeof(*iface
));
230 global
= wpa_supplicant_init(¶ms
);
231 if (global
== NULL
) {
232 wpa_printf(MSG_ERROR
, "Failed to initialize wpa_supplicant");
237 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
238 if ((ifaces
[i
].confname
== NULL
&&
239 ifaces
[i
].ctrl_interface
== NULL
) ||
240 ifaces
[i
].ifname
== NULL
) {
241 if (iface_count
== 1 && (params
.ctrl_interface
||
242 params
.dbus_ctrl_interface
))
248 if (wpa_supplicant_add_iface(global
, &ifaces
[i
]) == NULL
)
253 exitcode
= wpa_supplicant_run(global
);
255 wpa_supplicant_deinit(global
);
259 os_free(params
.pid_file
);