Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * WPA Supplicant / main() function for UNIX like OSes and MinGW
  3. * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
  4. *
  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.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #ifdef __linux__
  16. #include <fcntl.h>
  17. #endif /* __linux__ */
  18. #include "common.h"
  19. #include "wpa_supplicant_i.h"
  20. #include "driver_i.h"
  21. extern struct wpa_driver_ops *wpa_drivers[];
  22. static void usage(void)
  23. {
  24. int i;
  25. printf("%s\n\n%s\n"
  26. "usage:\n"
  27. " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
  28. "[-g<global ctrl>] \\\n"
  29. " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
  30. "[-p<driver_param>] \\\n"
  31. " [-b<br_ifname>] [-f<debug file>] \\\n"
  32. " [-o<override driver>] [-O<override ctrl>] \\\n"
  33. " [-N -i<ifname> -c<conf> [-C<ctrl>] "
  34. "[-D<driver>] \\\n"
  35. " [-p<driver_param>] [-b<br_ifname>] ...]\n"
  36. "\n"
  37. "drivers:\n",
  38. wpa_supplicant_version, wpa_supplicant_license);
  39. for (i = 0; wpa_drivers[i]; i++) {
  40. printf(" %s = %s\n",
  41. wpa_drivers[i]->name,
  42. wpa_drivers[i]->desc);
  43. }
  44. #ifndef CONFIG_NO_STDOUT_DEBUG
  45. printf("options:\n"
  46. " -b = optional bridge interface name\n"
  47. " -B = run daemon in the background\n"
  48. " -c = Configuration file\n"
  49. " -C = ctrl_interface parameter (only used if -c is not)\n"
  50. " -i = interface name\n"
  51. " -d = increase debugging verbosity (-dd even more)\n"
  52. " -D = driver name (can be multiple drivers: nl80211,wext)\n");
  53. #ifdef CONFIG_DEBUG_FILE
  54. printf(" -f = log output to debug file instead of stdout\n");
  55. #endif /* CONFIG_DEBUG_FILE */
  56. printf(" -g = global ctrl_interface\n"
  57. " -K = include keys (passwords, etc.) in debug output\n");
  58. #ifdef CONFIG_DEBUG_SYSLOG
  59. printf(" -s = log output to syslog instead of stdout\n");
  60. #endif /* CONFIG_DEBUG_SYSLOG */
  61. printf(" -t = include timestamp in debug messages\n"
  62. " -h = show this help text\n"
  63. " -L = show license (GPL and BSD)\n"
  64. " -o = override driver parameter for new interfaces\n"
  65. " -O = override ctrl_interface parameter for new interfaces\n"
  66. " -p = driver parameters\n"
  67. " -P = PID file\n"
  68. " -q = decrease debugging verbosity (-qq even less)\n");
  69. #ifdef CONFIG_DBUS
  70. printf(" -u = enable DBus control interface\n");
  71. #endif /* CONFIG_DBUS */
  72. printf(" -v = show version\n"
  73. " -W = wait for a control interface monitor before starting\n"
  74. " -N = start describing new interface\n");
  75. printf("example:\n"
  76. " wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
  77. wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
  78. #endif /* CONFIG_NO_STDOUT_DEBUG */
  79. }
  80. static void license(void)
  81. {
  82. #ifndef CONFIG_NO_STDOUT_DEBUG
  83. printf("%s\n\n%s%s%s%s%s\n",
  84. wpa_supplicant_version,
  85. wpa_supplicant_full_license1,
  86. wpa_supplicant_full_license2,
  87. wpa_supplicant_full_license3,
  88. wpa_supplicant_full_license4,
  89. wpa_supplicant_full_license5);
  90. #endif /* CONFIG_NO_STDOUT_DEBUG */
  91. }
  92. static void wpa_supplicant_fd_workaround(void)
  93. {
  94. #ifdef __linux__
  95. int s, i;
  96. /* When started from pcmcia-cs scripts, wpa_supplicant might start with
  97. * fd 0, 1, and 2 closed. This will cause some issues because many
  98. * places in wpa_supplicant are still printing out to stdout. As a
  99. * workaround, make sure that fd's 0, 1, and 2 are not used for other
  100. * sockets. */
  101. for (i = 0; i < 3; i++) {
  102. s = open("/dev/null", O_RDWR);
  103. if (s > 2) {
  104. close(s);
  105. break;
  106. }
  107. }
  108. #endif /* __linux__ */
  109. }
  110. int main(int argc, char *argv[])
  111. {
  112. int c, i;
  113. struct wpa_interface *ifaces, *iface;
  114. int iface_count, exitcode = -1;
  115. struct wpa_params params;
  116. struct wpa_global *global;
  117. if (os_program_init())
  118. return -1;
  119. os_memset(&params, 0, sizeof(params));
  120. params.wpa_debug_level = MSG_INFO;
  121. iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
  122. if (ifaces == NULL)
  123. return -1;
  124. iface_count = 1;
  125. wpa_supplicant_fd_workaround();
  126. for (;;) {
  127. c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW");
  128. if (c < 0)
  129. break;
  130. switch (c) {
  131. case 'b':
  132. iface->bridge_ifname = optarg;
  133. break;
  134. case 'B':
  135. params.daemonize++;
  136. break;
  137. case 'c':
  138. iface->confname = optarg;
  139. break;
  140. case 'C':
  141. iface->ctrl_interface = optarg;
  142. break;
  143. case 'D':
  144. iface->driver = optarg;
  145. break;
  146. case 'd':
  147. #ifdef CONFIG_NO_STDOUT_DEBUG
  148. printf("Debugging disabled with "
  149. "CONFIG_NO_STDOUT_DEBUG=y build time "
  150. "option.\n");
  151. goto out;
  152. #else /* CONFIG_NO_STDOUT_DEBUG */
  153. params.wpa_debug_level--;
  154. break;
  155. #endif /* CONFIG_NO_STDOUT_DEBUG */
  156. #ifdef CONFIG_DEBUG_FILE
  157. case 'f':
  158. params.wpa_debug_file_path = optarg;
  159. break;
  160. #endif /* CONFIG_DEBUG_FILE */
  161. case 'g':
  162. params.ctrl_interface = optarg;
  163. break;
  164. case 'h':
  165. usage();
  166. exitcode = 0;
  167. goto out;
  168. case 'i':
  169. iface->ifname = optarg;
  170. break;
  171. case 'K':
  172. params.wpa_debug_show_keys++;
  173. break;
  174. case 'L':
  175. license();
  176. exitcode = 0;
  177. goto out;
  178. case 'o':
  179. params.override_driver = optarg;
  180. break;
  181. case 'O':
  182. params.override_ctrl_interface = optarg;
  183. break;
  184. case 'p':
  185. iface->driver_param = optarg;
  186. break;
  187. case 'P':
  188. os_free(params.pid_file);
  189. params.pid_file = os_rel2abs_path(optarg);
  190. break;
  191. case 'q':
  192. params.wpa_debug_level++;
  193. break;
  194. #ifdef CONFIG_DEBUG_SYSLOG
  195. case 's':
  196. params.wpa_debug_syslog++;
  197. break;
  198. #endif /* CONFIG_DEBUG_SYSLOG */
  199. case 't':
  200. params.wpa_debug_timestamp++;
  201. break;
  202. #ifdef CONFIG_DBUS
  203. case 'u':
  204. params.dbus_ctrl_interface = 1;
  205. break;
  206. #endif /* CONFIG_DBUS */
  207. case 'v':
  208. printf("%s\n", wpa_supplicant_version);
  209. exitcode = 0;
  210. goto out;
  211. case 'W':
  212. params.wait_for_monitor++;
  213. break;
  214. case 'N':
  215. iface_count++;
  216. iface = os_realloc(ifaces, iface_count *
  217. sizeof(struct wpa_interface));
  218. if (iface == NULL)
  219. goto out;
  220. ifaces = iface;
  221. iface = &ifaces[iface_count - 1];
  222. os_memset(iface, 0, sizeof(*iface));
  223. break;
  224. default:
  225. usage();
  226. exitcode = 0;
  227. goto out;
  228. }
  229. }
  230. exitcode = 0;
  231. global = wpa_supplicant_init(&params);
  232. if (global == NULL) {
  233. wpa_printf(MSG_ERROR, "Failed to initialize wpa_supplicant");
  234. exitcode = -1;
  235. goto out;
  236. }
  237. for (i = 0; exitcode == 0 && i < iface_count; i++) {
  238. if ((ifaces[i].confname == NULL &&
  239. ifaces[i].ctrl_interface == NULL) ||
  240. ifaces[i].ifname == NULL) {
  241. if (iface_count == 1 && (params.ctrl_interface ||
  242. params.dbus_ctrl_interface))
  243. break;
  244. usage();
  245. exitcode = -1;
  246. break;
  247. }
  248. if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
  249. exitcode = -1;
  250. }
  251. if (exitcode == 0)
  252. exitcode = wpa_supplicant_run(global);
  253. wpa_supplicant_deinit(global);
  254. out:
  255. os_free(ifaces);
  256. os_free(params.pid_file);
  257. os_program_deinit();
  258. return exitcode;
  259. }