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 const char *wpa_supplicant_version
;
25 extern const char *wpa_supplicant_license
;
26 #ifndef CONFIG_NO_STDOUT_DEBUG
27 extern const char *wpa_supplicant_full_license1
;
28 extern const char *wpa_supplicant_full_license2
;
29 extern const char *wpa_supplicant_full_license3
;
30 extern const char *wpa_supplicant_full_license4
;
31 extern const char *wpa_supplicant_full_license5
;
32 #endif /* CONFIG_NO_STDOUT_DEBUG */
34 extern struct wpa_driver_ops
*wpa_supplicant_drivers
[];
37 static void usage(void)
42 " wpa_supplicant [-BddehLqquvwW] [-P<pid file>] "
43 "[-g<global ctrl>] \\\n"
44 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
45 "[-p<driver_param>] \\\n"
46 " [-b<br_ifname> [-N -i<ifname> -c<conf> [-C<ctrl>] "
48 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
51 wpa_supplicant_version
, wpa_supplicant_license
);
53 for (i
= 0; wpa_supplicant_drivers
[i
]; i
++) {
55 wpa_supplicant_drivers
[i
]->name
,
56 wpa_supplicant_drivers
[i
]->desc
);
59 #ifndef CONFIG_NO_STDOUT_DEBUG
61 " -b = optional bridge interface name\n"
62 " -B = run daemon in the background\n"
63 " -c = Configuration file\n"
64 " -C = ctrl_interface parameter (only used if -c is not)\n"
65 " -i = interface name\n"
66 " -d = increase debugging verbosity (-dd even more)\n"
68 " -g = global ctrl_interface\n"
69 " -K = include keys (passwords, etc.) in debug output\n"
70 " -t = include timestamp in debug messages\n"
71 " -h = show this help text\n"
72 " -L = show license (GPL and BSD)\n");
73 printf(" -p = driver parameters\n"
75 " -q = decrease debugging verbosity (-qq even less)\n"
76 #ifdef CONFIG_CTRL_IFACE_DBUS
77 " -u = enable DBus control interface\n"
78 #endif /* CONFIG_CTRL_IFACE_DBUS */
79 " -v = show version\n"
80 " -w = wait for interface to be added, if needed\n"
81 " -W = wait for a control interface monitor before starting\n"
82 " -N = start describing new interface\n");
85 " wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf\n");
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:dg:hi:KLNp:P:qtuvwW");
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 */
176 params
.ctrl_interface
= optarg
;
183 iface
->ifname
= optarg
;
186 params
.wpa_debug_show_keys
++;
193 iface
->driver_param
= optarg
;
196 os_free(params
.pid_file
);
197 params
.pid_file
= os_rel2abs_path(optarg
);
200 params
.wpa_debug_level
++;
203 params
.wpa_debug_timestamp
++;
205 #ifdef CONFIG_CTRL_IFACE_DBUS
207 params
.dbus_ctrl_interface
= 1;
209 #endif /* CONFIG_CTRL_IFACE_DBUS */
211 printf("%s\n", wpa_supplicant_version
);
215 params
.wait_for_interface
++;
218 params
.wait_for_monitor
++;
222 iface
= os_realloc(ifaces
, iface_count
*
223 sizeof(struct wpa_interface
));
227 iface
= &ifaces
[iface_count
- 1];
228 os_memset(iface
, 0, sizeof(*iface
));
238 global
= wpa_supplicant_init(¶ms
);
239 if (global
== NULL
) {
240 printf("Failed to initialize wpa_supplicant\n");
245 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
246 if ((ifaces
[i
].confname
== NULL
&&
247 ifaces
[i
].ctrl_interface
== NULL
) ||
248 ifaces
[i
].ifname
== NULL
) {
249 if (iface_count
== 1 && (params
.ctrl_interface
||
250 params
.dbus_ctrl_interface
))
256 if (wpa_supplicant_add_iface(global
, &ifaces
[i
]) == NULL
)
261 exitcode
= wpa_supplicant_run(global
);
263 wpa_supplicant_deinit(global
);
267 os_free(params
.pid_file
);