Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "includes.h"
00016 #ifdef __linux__
00017 #include <fcntl.h>
00018 #endif
00019
00020 #include "common.h"
00021 #include "wpa_supplicant_i.h"
00022 #include "driver_i.h"
00023
00024 extern struct wpa_driver_ops *wpa_drivers[];
00025
00026
00027 static void usage(void)
00028 {
00029 int i;
00030 printf("%s\n\n%s\n"
00031 "usage:\n"
00032 " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
00033 "[-g<global ctrl>] \\\n"
00034 " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
00035 "[-p<driver_param>] \\\n"
00036 " [-b<br_ifname>] [-f<debug file>] \\\n"
00037 " [-o<override driver>] [-O<override ctrl>] \\\n"
00038 " [-N -i<ifname> -c<conf> [-C<ctrl>] "
00039 "[-D<driver>] \\\n"
00040 " [-p<driver_param>] [-b<br_ifname>] ...]\n"
00041 "\n"
00042 "drivers:\n",
00043 wpa_supplicant_version, wpa_supplicant_license);
00044
00045 for (i = 0; wpa_drivers[i]; i++) {
00046 printf(" %s = %s\n",
00047 wpa_drivers[i]->name,
00048 wpa_drivers[i]->desc);
00049 }
00050
00051 #ifndef CONFIG_NO_STDOUT_DEBUG
00052 printf("options:\n"
00053 " -b = optional bridge interface name\n"
00054 " -B = run daemon in the background\n"
00055 " -c = Configuration file\n"
00056 " -C = ctrl_interface parameter (only used if -c is not)\n"
00057 " -i = interface name\n"
00058 " -d = increase debugging verbosity (-dd even more)\n"
00059 " -D = driver name (can be multiple drivers: nl80211,wext)\n");
00060 #ifdef CONFIG_DEBUG_FILE
00061 printf(" -f = log output to debug file instead of stdout\n");
00062 #endif
00063 printf(" -g = global ctrl_interface\n"
00064 " -K = include keys (passwords, etc.) in debug output\n");
00065 #ifdef CONFIG_DEBUG_SYSLOG
00066 printf(" -s = log output to syslog instead of stdout\n");
00067 #endif
00068 printf(" -t = include timestamp in debug messages\n"
00069 " -h = show this help text\n"
00070 " -L = show license (GPL and BSD)\n"
00071 " -o = override driver parameter for new interfaces\n"
00072 " -O = override ctrl_interface parameter for new interfaces\n"
00073 " -p = driver parameters\n"
00074 " -P = PID file\n"
00075 " -q = decrease debugging verbosity (-qq even less)\n");
00076 #ifdef CONFIG_DBUS
00077 printf(" -u = enable DBus control interface\n");
00078 #endif
00079 printf(" -v = show version\n"
00080 " -W = wait for a control interface monitor before starting\n"
00081 " -N = start describing new interface\n");
00082
00083 printf("example:\n"
00084 " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
00085 wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
00086 #endif
00087 }
00088
00089
00090 static void license(void)
00091 {
00092 #ifndef CONFIG_NO_STDOUT_DEBUG
00093 printf("%s\n\n%s%s%s%s%s\n",
00094 wpa_supplicant_version,
00095 wpa_supplicant_full_license1,
00096 wpa_supplicant_full_license2,
00097 wpa_supplicant_full_license3,
00098 wpa_supplicant_full_license4,
00099 wpa_supplicant_full_license5);
00100 #endif
00101 }
00102
00103
00104 static void wpa_supplicant_fd_workaround(void)
00105 {
00106 #ifdef __linux__
00107 int s, i;
00108
00109
00110
00111
00112
00113 for (i = 0; i < 3; i++) {
00114 s = open("/dev/null", O_RDWR);
00115 if (s > 2) {
00116 close(s);
00117 break;
00118 }
00119 }
00120 #endif
00121 }
00122
00123
00124 int main(int argc, char *argv[])
00125 {
00126 int c, i;
00127 struct wpa_interface *ifaces, *iface;
00128 int iface_count, exitcode = -1;
00129 struct wpa_params params;
00130 struct wpa_global *global;
00131
00132 setlinebuf(stdout);
00133
00134 if (os_program_init())
00135 return -1;
00136
00137 os_memset(¶ms, 0, sizeof(params));
00138 params.wpa_debug_level = MSG_INFO;
00139
00140 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
00141 if (ifaces == NULL)
00142 return -1;
00143 iface_count = 1;
00144
00145 wpa_supplicant_fd_workaround();
00146
00147 for (;;) {
00148 c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW");
00149 if (c < 0)
00150 break;
00151 switch (c) {
00152 case 'b':
00153 iface->bridge_ifname = optarg;
00154 break;
00155 case 'B':
00156 params.daemonize++;
00157 break;
00158 case 'c':
00159 iface->confname = optarg;
00160 break;
00161 case 'C':
00162 iface->ctrl_interface = optarg;
00163 break;
00164 case 'D':
00165 iface->driver = optarg;
00166 break;
00167 case 'd':
00168 #ifdef CONFIG_NO_STDOUT_DEBUG
00169 printf("Debugging disabled with "
00170 "CONFIG_NO_STDOUT_DEBUG=y build time "
00171 "option.\n");
00172 goto out;
00173 #else
00174 params.wpa_debug_level--;
00175 break;
00176 #endif
00177 #ifdef CONFIG_DEBUG_FILE
00178 case 'f':
00179 params.wpa_debug_file_path = optarg;
00180 break;
00181 #endif
00182 case 'g':
00183 params.ctrl_interface = optarg;
00184 break;
00185 case 'h':
00186 usage();
00187 exitcode = 0;
00188 goto out;
00189 case 'i':
00190 iface->ifname = optarg;
00191 break;
00192 case 'K':
00193 params.wpa_debug_show_keys++;
00194 break;
00195 case 'L':
00196 license();
00197 exitcode = 0;
00198 goto out;
00199 case 'o':
00200 params.override_driver = optarg;
00201 break;
00202 case 'O':
00203 params.override_ctrl_interface = optarg;
00204 break;
00205 case 'p':
00206 iface->driver_param = optarg;
00207 break;
00208 case 'P':
00209 os_free(params.pid_file);
00210 params.pid_file = os_rel2abs_path(optarg);
00211 break;
00212 case 'q':
00213 params.wpa_debug_level++;
00214 break;
00215 #ifdef CONFIG_DEBUG_SYSLOG
00216 case 's':
00217 params.wpa_debug_syslog++;
00218 break;
00219 #endif
00220 case 't':
00221 params.wpa_debug_timestamp++;
00222 break;
00223 #ifdef CONFIG_DBUS
00224 case 'u':
00225 params.dbus_ctrl_interface = 1;
00226 break;
00227 #endif
00228 case 'v':
00229 printf("%s\n", wpa_supplicant_version);
00230 exitcode = 0;
00231 goto out;
00232 case 'W':
00233 params.wait_for_monitor++;
00234 break;
00235 case 'N':
00236 iface_count++;
00237 iface = os_realloc(ifaces, iface_count *
00238 sizeof(struct wpa_interface));
00239 if (iface == NULL)
00240 goto out;
00241 ifaces = iface;
00242 iface = &ifaces[iface_count - 1];
00243 os_memset(iface, 0, sizeof(*iface));
00244 break;
00245 default:
00246 usage();
00247 exitcode = 0;
00248 goto out;
00249 }
00250 }
00251
00252 exitcode = 0;
00253 global = wpa_supplicant_init(¶ms);
00254 if (global == NULL) {
00255 wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
00256 exitcode = -1;
00257 goto out;
00258 }
00259
00260 for (i = 0; exitcode == 0 && i < iface_count; i++) {
00261 if ((ifaces[i].confname == NULL &&
00262 ifaces[i].ctrl_interface == NULL) ||
00263 ifaces[i].ifname == NULL) {
00264 if (iface_count == 1 && (params.ctrl_interface ||
00265 params.dbus_ctrl_interface))
00266 break;
00267 usage();
00268 exitcode = -1;
00269 break;
00270 }
00271 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
00272 exitcode = -1;
00273 }
00274
00275 if (exitcode == 0)
00276 exitcode = wpa_supplicant_run(global);
00277
00278 wpa_supplicant_deinit(global);
00279
00280 out:
00281 os_free(ifaces);
00282 os_free(params.pid_file);
00283
00284 os_program_deinit();
00285
00286 return exitcode;
00287 }