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 extern struct wpa_driver_ops
*wpa_drivers
[];
27 static void usage(void)
32 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
33 "[-g<global ctrl>] \\\n"
34 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
35 "[-p<driver_param>] \\\n"
36 " [-b<br_ifname>] [-f<debug file>] \\\n"
37 " [-o<override driver>] [-O<override ctrl>] \\\n"
38 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
40 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
43 wpa_supplicant_version
, wpa_supplicant_license
);
45 for (i
= 0; wpa_drivers
[i
]; i
++) {
48 wpa_drivers
[i
]->desc
);
51 #ifndef CONFIG_NO_STDOUT_DEBUG
53 " -b = optional bridge interface name\n"
54 " -B = run daemon in the background\n"
55 " -c = Configuration file\n"
56 " -C = ctrl_interface parameter (only used if -c is not)\n"
57 " -i = interface name\n"
58 " -d = increase debugging verbosity (-dd even more)\n"
59 " -D = driver name (can be multiple drivers: nl80211,wext)\n");
60 #ifdef CONFIG_DEBUG_FILE
61 printf(" -f = log output to debug file instead of stdout\n");
62 #endif /* CONFIG_DEBUG_FILE */
63 printf(" -g = global ctrl_interface\n"
64 " -K = include keys (passwords, etc.) in debug output\n");
65 #ifdef CONFIG_DEBUG_SYSLOG
66 printf(" -s = log output to syslog instead of stdout\n");
67 #endif /* CONFIG_DEBUG_SYSLOG */
68 printf(" -t = include timestamp in debug messages\n"
69 " -h = show this help text\n"
70 " -L = show license (GPL and BSD)\n"
71 " -o = override driver parameter for new interfaces\n"
72 " -O = override ctrl_interface parameter for new interfaces\n"
73 " -p = driver parameters\n"
75 " -q = decrease debugging verbosity (-qq even less)\n");
76 #if defined(CONFIG_CTRL_IFACE_DBUS) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
77 printf(" -u = enable DBus control interface\n");
78 #endif /* CONFIG_CTRL_IFACE_DBUS || CONFIG_CTRL_IFACE_DBUS_NEW */
79 printf(" -v = show version\n"
80 " -W = wait for a control interface monitor before starting\n"
81 " -N = start describing new interface\n");
84 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
85 wpa_drivers
[i
] ? wpa_drivers
[i
]->name
: "wext");
86 #endif /* CONFIG_NO_STDOUT_DEBUG */
90 static void license(void)
92 #ifndef CONFIG_NO_STDOUT_DEBUG
93 printf("%s\n\n%s%s%s%s%s\n",
94 wpa_supplicant_version
,
95 wpa_supplicant_full_license1
,
96 wpa_supplicant_full_license2
,
97 wpa_supplicant_full_license3
,
98 wpa_supplicant_full_license4
,
99 wpa_supplicant_full_license5
);
100 #endif /* CONFIG_NO_STDOUT_DEBUG */
104 static void wpa_supplicant_fd_workaround(void)
108 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
109 * fd 0, 1, and 2 closed. This will cause some issues because many
110 * places in wpa_supplicant are still printing out to stdout. As a
111 * workaround, make sure that fd's 0, 1, and 2 are not used for other
113 for (i
= 0; i
< 3; i
++) {
114 s
= open("/dev/null", O_RDWR
);
120 #endif /* __linux__ */
124 int main(int argc
, char *argv
[])
127 struct wpa_interface
*ifaces
, *iface
;
128 int iface_count
, exitcode
= -1;
129 struct wpa_params params
;
130 struct wpa_global
*global
;
132 if (os_program_init())
135 os_memset(¶ms
, 0, sizeof(params
));
136 params
.wpa_debug_level
= MSG_INFO
;
138 iface
= ifaces
= os_zalloc(sizeof(struct wpa_interface
));
143 wpa_supplicant_fd_workaround();
146 c
= getopt(argc
, argv
, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW");
151 iface
->bridge_ifname
= optarg
;
157 iface
->confname
= optarg
;
160 iface
->ctrl_interface
= optarg
;
163 iface
->driver
= optarg
;
166 #ifdef CONFIG_NO_STDOUT_DEBUG
167 printf("Debugging disabled with "
168 "CONFIG_NO_STDOUT_DEBUG=y build time "
171 #else /* CONFIG_NO_STDOUT_DEBUG */
172 params
.wpa_debug_level
--;
174 #endif /* CONFIG_NO_STDOUT_DEBUG */
175 #ifdef CONFIG_DEBUG_FILE
177 params
.wpa_debug_file_path
= optarg
;
179 #endif /* CONFIG_DEBUG_FILE */
181 params
.ctrl_interface
= optarg
;
188 iface
->ifname
= optarg
;
191 params
.wpa_debug_show_keys
++;
198 params
.override_driver
= optarg
;
201 params
.override_ctrl_interface
= optarg
;
204 iface
->driver_param
= optarg
;
207 os_free(params
.pid_file
);
208 params
.pid_file
= os_rel2abs_path(optarg
);
211 params
.wpa_debug_level
++;
213 #ifdef CONFIG_DEBUG_SYSLOG
215 params
.wpa_debug_syslog
++;
217 #endif /* CONFIG_DEBUG_SYSLOG */
219 params
.wpa_debug_timestamp
++;
221 #if defined(CONFIG_CTRL_IFACE_DBUS) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
223 params
.dbus_ctrl_interface
= 1;
225 #endif /* CONFIG_CTRL_IFACE_DBUS || CONFIG_CTRL_IFACE_DBUS_NEW */
227 printf("%s\n", wpa_supplicant_version
);
231 params
.wait_for_monitor
++;
235 iface
= os_realloc(ifaces
, iface_count
*
236 sizeof(struct wpa_interface
));
240 iface
= &ifaces
[iface_count
- 1];
241 os_memset(iface
, 0, sizeof(*iface
));
251 global
= wpa_supplicant_init(¶ms
);
252 if (global
== NULL
) {
253 wpa_printf(MSG_ERROR
, "Failed to initialize wpa_supplicant");
258 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
259 if ((ifaces
[i
].confname
== NULL
&&
260 ifaces
[i
].ctrl_interface
== NULL
) ||
261 ifaces
[i
].ifname
== NULL
) {
262 if (iface_count
== 1 && (params
.ctrl_interface
||
263 params
.dbus_ctrl_interface
))
269 if (wpa_supplicant_add_iface(global
, &ifaces
[i
]) == NULL
)
274 exitcode
= wpa_supplicant_run(global
);
276 wpa_supplicant_deinit(global
);
280 os_free(params
.pid_file
);