wlantest.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * wlantest - IEEE 802.11 protocol monitoring and testing tool
  3. * Copyright (c) 2010, 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 "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "utils/eloop.h"
  17. #include "wlantest.h"
  18. extern int wpa_debug_level;
  19. static void wlantest_terminate(int sig, void *signal_ctx)
  20. {
  21. eloop_terminate();
  22. }
  23. static void usage(void)
  24. {
  25. printf("wlantest [-ddhqq] [-i<ifname>] [-r<pcap file>]\n");
  26. }
  27. static void wlantest_init(struct wlantest *wt)
  28. {
  29. os_memset(wt, 0, sizeof(*wt));
  30. wt->monitor_sock = -1;
  31. dl_list_init(&wt->bss);
  32. }
  33. static void wlantest_deinit(struct wlantest *wt)
  34. {
  35. struct wlantest_bss *bss, *n;
  36. if (wt->monitor_sock >= 0)
  37. monitor_deinit(wt);
  38. dl_list_for_each_safe(bss, n, &wt->bss, struct wlantest_bss, list)
  39. bss_deinit(bss);
  40. }
  41. int main(int argc, char *argv[])
  42. {
  43. int c;
  44. const char *read_file = NULL;
  45. const char *ifname = NULL;
  46. struct wlantest wt;
  47. wpa_debug_level = MSG_INFO;
  48. if (os_program_init())
  49. return -1;
  50. wlantest_init(&wt);
  51. for (;;) {
  52. c = getopt(argc, argv, "dhi:r:q");
  53. if (c < 0)
  54. break;
  55. switch (c) {
  56. case 'd':
  57. if (wpa_debug_level > 0)
  58. wpa_debug_level--;
  59. break;
  60. case 'h':
  61. usage();
  62. return 0;
  63. case 'i':
  64. ifname = optarg;
  65. break;
  66. case 'q':
  67. wpa_debug_level++;
  68. break;
  69. case 'r':
  70. read_file = optarg;
  71. break;
  72. default:
  73. usage();
  74. return -1;
  75. }
  76. }
  77. if (ifname == NULL && read_file == NULL) {
  78. usage();
  79. return 0;
  80. }
  81. if (eloop_init())
  82. return -1;
  83. if (read_file && read_cap_file(&wt, read_file) < 0)
  84. return -1;
  85. if (ifname && monitor_init(&wt, ifname) < 0)
  86. return -1;
  87. eloop_register_signal_terminate(wlantest_terminate, &wt);
  88. eloop_run();
  89. wpa_printf(MSG_INFO, "Processed: rx_mgmt=%u rx_ctrl=%u rx_data=%u "
  90. "fcs_error=%u",
  91. wt.rx_mgmt, wt.rx_ctrl, wt.rx_data, wt.fcs_error);
  92. wlantest_deinit(&wt);
  93. eloop_destroy();
  94. os_program_deinit();
  95. return 0;
  96. }