diff options
Diffstat (limited to 'contrib/wpa_supplicant/main.c')
-rw-r--r-- | contrib/wpa_supplicant/main.c | 110 |
1 files changed, 66 insertions, 44 deletions
diff --git a/contrib/wpa_supplicant/main.c b/contrib/wpa_supplicant/main.c index 8d82666..fdce7c5 100644 --- a/contrib/wpa_supplicant/main.c +++ b/contrib/wpa_supplicant/main.c @@ -1,6 +1,6 @@ /* * WPA Supplicant / main() function for UNIX like OSes and MinGW - * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi> + * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -12,11 +12,10 @@ * See README and COPYING for more details. */ -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> +#include "includes.h" +#ifdef __linux__ #include <fcntl.h> +#endif /* __linux__ */ #include "common.h" #include "wpa_supplicant_i.h" @@ -25,7 +24,11 @@ extern const char *wpa_supplicant_version; extern const char *wpa_supplicant_license; #ifndef CONFIG_NO_STDOUT_DEBUG -extern const char *wpa_supplicant_full_license; +extern const char *wpa_supplicant_full_license1; +extern const char *wpa_supplicant_full_license2; +extern const char *wpa_supplicant_full_license3; +extern const char *wpa_supplicant_full_license4; +extern const char *wpa_supplicant_full_license5; #endif /* CONFIG_NO_STDOUT_DEBUG */ extern struct wpa_driver_ops *wpa_supplicant_drivers[]; @@ -36,12 +39,13 @@ static void usage(void) int i; printf("%s\n\n%s\n" "usage:\n" - " wpa_supplicant [-BddehLqqvwW] [-P<pid file>] " + " wpa_supplicant [-BddehLqquvwW] [-P<pid file>] " "[-g<global ctrl>] \\\n" " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] " "[-p<driver_param>] \\\n" - " [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] " - "[-p<driver_param>] ...]\n" + " [-b<br_ifname> [-N -i<ifname> -c<conf> [-C<ctrl>] " + "[-D<driver>] \\\n" + " [-p<driver_param>] [-b<br_ifname>] ...]\n" "\n" "drivers:\n", wpa_supplicant_version, wpa_supplicant_license); @@ -54,6 +58,7 @@ static void usage(void) #ifndef CONFIG_NO_STDOUT_DEBUG printf("options:\n" + " -b = optional bridge interface name\n" " -B = run daemon in the background\n" " -c = Configuration file\n" " -C = ctrl_interface parameter (only used if -c is not)\n" @@ -64,10 +69,13 @@ static void usage(void) " -K = include keys (passwords, etc.) in debug output\n" " -t = include timestamp in debug messages\n" " -h = show this help text\n" - " -L = show license (GPL and BSD)\n" - " -p = driver parameters\n" + " -L = show license (GPL and BSD)\n"); + printf(" -p = driver parameters\n" " -P = PID file\n" " -q = decrease debugging verbosity (-qq even less)\n" +#ifdef CONFIG_CTRL_IFACE_DBUS + " -u = enable DBus control interface\n" +#endif /* CONFIG_CTRL_IFACE_DBUS */ " -v = show version\n" " -w = wait for interface to be added, if needed\n" " -W = wait for a control interface monitor before starting\n" @@ -82,14 +90,20 @@ static void usage(void) static void license(void) { #ifndef CONFIG_NO_STDOUT_DEBUG - printf("%s\n\n%s\n", - wpa_supplicant_version, wpa_supplicant_full_license); + printf("%s\n\n%s%s%s%s%s\n", + wpa_supplicant_version, + wpa_supplicant_full_license1, + wpa_supplicant_full_license2, + wpa_supplicant_full_license3, + wpa_supplicant_full_license4, + wpa_supplicant_full_license5); #endif /* CONFIG_NO_STDOUT_DEBUG */ } static void wpa_supplicant_fd_workaround(void) { +#ifdef __linux__ int s, i; /* When started from pcmcia-cs scripts, wpa_supplicant might start with * fd 0, 1, and 2 closed. This will cause some issues because many @@ -103,6 +117,7 @@ static void wpa_supplicant_fd_workaround(void) break; } } +#endif /* __linux__ */ } @@ -110,34 +125,31 @@ int main(int argc, char *argv[]) { int c, i; struct wpa_interface *ifaces, *iface; - int iface_count, exitcode; + int iface_count, exitcode = -1; struct wpa_params params; struct wpa_global *global; -#ifdef CONFIG_NATIVE_WINDOWS - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 0), &wsaData)) { - printf("Could not find a usable WinSock.dll\n"); + if (os_program_init()) return -1; - } -#endif /* CONFIG_NATIVE_WINDOWS */ - memset(¶ms, 0, sizeof(params)); + os_memset(¶ms, 0, sizeof(params)); params.wpa_debug_level = MSG_INFO; - iface = ifaces = malloc(sizeof(struct wpa_interface)); + iface = ifaces = os_zalloc(sizeof(struct wpa_interface)); if (ifaces == NULL) return -1; - memset(iface, 0, sizeof(*iface)); iface_count = 1; wpa_supplicant_fd_workaround(); for (;;) { - c = getopt(argc, argv, "Bc:C:D:dg:hi:KLNp:P:qtvwW"); + c = getopt(argc, argv, "b:Bc:C:D:dg:hi:KLNp:P:qtuvwW"); if (c < 0) break; switch (c) { + case 'b': + iface->bridge_ifname = optarg; + break; case 'B': params.daemonize++; break; @@ -155,7 +167,7 @@ int main(int argc, char *argv[]) printf("Debugging disabled with " "CONFIG_NO_STDOUT_DEBUG=y build time " "option.\n"); - return -1; + goto out; #else /* CONFIG_NO_STDOUT_DEBUG */ params.wpa_debug_level--; break; @@ -165,7 +177,8 @@ int main(int argc, char *argv[]) break; case 'h': usage(); - return -1; + exitcode = 0; + goto out; case 'i': iface->ifname = optarg; break; @@ -174,12 +187,14 @@ int main(int argc, char *argv[]) break; case 'L': license(); - return -1; + exitcode = 0; + goto out; case 'p': iface->driver_param = optarg; break; case 'P': - params.pid_file = rel2abs_path(optarg); + os_free(params.pid_file); + params.pid_file = os_rel2abs_path(optarg); break; case 'q': params.wpa_debug_level++; @@ -187,9 +202,15 @@ int main(int argc, char *argv[]) case 't': params.wpa_debug_timestamp++; break; +#ifdef CONFIG_CTRL_IFACE_DBUS + case 'u': + params.dbus_ctrl_interface = 1; + break; +#endif /* CONFIG_CTRL_IFACE_DBUS */ case 'v': printf("%s\n", wpa_supplicant_version); - return -1; + exitcode = 0; + goto out; case 'w': params.wait_for_interface++; break; @@ -198,19 +219,18 @@ int main(int argc, char *argv[]) break; case 'N': iface_count++; - iface = realloc(ifaces, iface_count * - sizeof(struct wpa_interface)); - if (iface == NULL) { - free(ifaces); - return -1; - } + iface = os_realloc(ifaces, iface_count * + sizeof(struct wpa_interface)); + if (iface == NULL) + goto out; ifaces = iface; iface = &ifaces[iface_count - 1]; - memset(iface, 0, sizeof(*iface)); + os_memset(iface, 0, sizeof(*iface)); break; default: usage(); - return -1; + exitcode = 0; + goto out; } } @@ -219,16 +239,19 @@ int main(int argc, char *argv[]) if (global == NULL) { printf("Failed to initialize wpa_supplicant\n"); exitcode = -1; + goto out; } for (i = 0; exitcode == 0 && i < iface_count; i++) { if ((ifaces[i].confname == NULL && ifaces[i].ctrl_interface == NULL) || ifaces[i].ifname == NULL) { - if (iface_count == 1 && params.ctrl_interface) + if (iface_count == 1 && (params.ctrl_interface || + params.dbus_ctrl_interface)) break; usage(); - return -1; + exitcode = -1; + break; } if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL) exitcode = -1; @@ -239,12 +262,11 @@ int main(int argc, char *argv[]) wpa_supplicant_deinit(global); - free(ifaces); - free(params.pid_file); +out: + os_free(ifaces); + os_free(params.pid_file); -#ifdef CONFIG_NATIVE_WINDOWS - WSACleanup(); -#endif /* CONFIG_NATIVE_WINDOWS */ + os_program_deinit(); return exitcode; } |