2 * WPA Supplicant / main() function for UNIX like OSes and MinGW
3 * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.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.
22 #include "wpa_supplicant_i.h"
25 extern const char *wpa_supplicant_version
;
26 extern const char *wpa_supplicant_license
;
27 #ifndef CONFIG_NO_STDOUT_DEBUG
28 extern const char *wpa_supplicant_full_license
;
29 #endif /* CONFIG_NO_STDOUT_DEBUG */
31 extern struct wpa_driver_ops
*wpa_supplicant_drivers
[];
34 static void usage(void)
39 " wpa_supplicant [-BddehLqqvwW] [-P<pid file>] "
40 "[-g<global ctrl>] \\\n"
41 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
42 "[-p<driver_param>] \\\n"
43 " [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] "
44 "[-p<driver_param>] ...]\n"
47 wpa_supplicant_version
, wpa_supplicant_license
);
49 for (i
= 0; wpa_supplicant_drivers
[i
]; i
++) {
51 wpa_supplicant_drivers
[i
]->name
,
52 wpa_supplicant_drivers
[i
]->desc
);
55 #ifndef CONFIG_NO_STDOUT_DEBUG
57 " -B = run daemon in the background\n"
58 " -c = Configuration file\n"
59 " -C = ctrl_interface parameter (only used if -c is not)\n"
60 " -i = interface name\n"
61 " -d = increase debugging verbosity (-dd even more)\n"
63 " -g = global ctrl_interface\n"
64 " -K = include keys (passwords, etc.) in debug output\n"
65 " -t = include timestamp in debug messages\n"
66 " -h = show this help text\n"
67 " -L = show license (GPL and BSD)\n"
68 " -p = driver parameters\n"
70 " -q = decrease debugging verbosity (-qq even less)\n"
71 " -v = show version\n"
72 " -w = wait for interface to be added, if needed\n"
73 " -W = wait for a control interface monitor before starting\n"
74 " -N = start describing new interface\n");
77 " wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf\n");
78 #endif /* CONFIG_NO_STDOUT_DEBUG */
82 static void license(void)
84 #ifndef CONFIG_NO_STDOUT_DEBUG
86 wpa_supplicant_version
, wpa_supplicant_full_license
);
87 #endif /* CONFIG_NO_STDOUT_DEBUG */
91 static void wpa_supplicant_fd_workaround(void)
94 /* When started from pcmcia-cs scripts, wpa_supplicant might start with
95 * fd 0, 1, and 2 closed. This will cause some issues because many
96 * places in wpa_supplicant are still printing out to stdout. As a
97 * workaround, make sure that fd's 0, 1, and 2 are not used for other
99 for (i
= 0; i
< 3; i
++) {
100 s
= open("/dev/null", O_RDWR
);
109 int main(int argc
, char *argv
[])
112 struct wpa_interface
*ifaces
, *iface
;
113 int iface_count
, exitcode
= -1;
114 struct wpa_params params
;
115 struct wpa_global
*global
;
117 #ifdef CONFIG_NATIVE_WINDOWS
119 if (WSAStartup(MAKEWORD(2, 0), &wsaData
)) {
120 printf("Could not find a usable WinSock.dll\n");
123 #endif /* CONFIG_NATIVE_WINDOWS */
125 memset(¶ms
, 0, sizeof(params
));
126 params
.wpa_debug_level
= MSG_INFO
;
128 iface
= ifaces
= malloc(sizeof(struct wpa_interface
));
131 memset(iface
, 0, sizeof(*iface
));
134 wpa_supplicant_fd_workaround();
137 c
= getopt(argc
, argv
, "Bc:C:D:dg:hi:KLNp:P:qtvwW");
145 iface
->confname
= optarg
;
148 iface
->ctrl_interface
= optarg
;
151 iface
->driver
= optarg
;
154 #ifdef CONFIG_NO_STDOUT_DEBUG
155 printf("Debugging disabled with "
156 "CONFIG_NO_STDOUT_DEBUG=y build time "
159 #else /* CONFIG_NO_STDOUT_DEBUG */
160 params
.wpa_debug_level
--;
162 #endif /* CONFIG_NO_STDOUT_DEBUG */
164 params
.ctrl_interface
= optarg
;
170 iface
->ifname
= optarg
;
173 params
.wpa_debug_show_keys
++;
179 iface
->driver_param
= optarg
;
182 params
.pid_file
= rel2abs_path(optarg
);
185 params
.wpa_debug_level
++;
188 params
.wpa_debug_timestamp
++;
191 printf("%s\n", wpa_supplicant_version
);
194 params
.wait_for_interface
++;
197 params
.wait_for_monitor
++;
201 iface
= realloc(ifaces
, iface_count
*
202 sizeof(struct wpa_interface
));
206 iface
= &ifaces
[iface_count
- 1];
207 memset(iface
, 0, sizeof(*iface
));
216 global
= wpa_supplicant_init(¶ms
);
217 if (global
== NULL
) {
218 printf("Failed to initialize wpa_supplicant\n");
222 for (i
= 0; exitcode
== 0 && i
< iface_count
; i
++) {
223 if ((ifaces
[i
].confname
== NULL
&&
224 ifaces
[i
].ctrl_interface
== NULL
) ||
225 ifaces
[i
].ifname
== NULL
) {
226 if (iface_count
== 1 && params
.ctrl_interface
)
232 if (wpa_supplicant_add_iface(global
, &ifaces
[i
]) == NULL
)
237 exitcode
= wpa_supplicant_run(global
);
239 wpa_supplicant_deinit(global
);
243 free(params
.pid_file
);
245 #ifdef CONFIG_NATIVE_WINDOWS
247 #endif /* CONFIG_NATIVE_WINDOWS */