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


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:20