wlantest.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. int main(int argc, char *argv[])
  28. {
  29. int c;
  30. const char *read_file = NULL;
  31. const char *ifname = NULL;
  32. struct wlantest wt;
  33. wpa_debug_level = MSG_INFO;
  34. if (os_program_init())
  35. return -1;
  36. os_memset(&wt, 0, sizeof(wt));
  37. wt.monitor_sock = -1;
  38. for (;;) {
  39. c = getopt(argc, argv, "dhi:r:q");
  40. if (c < 0)
  41. break;
  42. switch (c) {
  43. case 'd':
  44. if (wpa_debug_level > 0)
  45. wpa_debug_level--;
  46. break;
  47. case 'h':
  48. usage();
  49. return 0;
  50. case 'i':
  51. ifname = optarg;
  52. break;
  53. case 'q':
  54. wpa_debug_level++;
  55. break;
  56. case 'r':
  57. read_file = optarg;
  58. break;
  59. default:
  60. usage();
  61. return -1;
  62. }
  63. }
  64. if (ifname == NULL && read_file == NULL) {
  65. usage();
  66. return 0;
  67. }
  68. if (eloop_init())
  69. return -1;
  70. if (read_file && read_cap_file(&wt, read_file) < 0)
  71. return -1;
  72. if (ifname && monitor_init(&wt, ifname) < 0)
  73. return -1;
  74. eloop_register_signal_terminate(wlantest_terminate, &wt);
  75. eloop_run();
  76. wpa_printf(MSG_INFO, "Processed: rx_mgmt=%u rx_ctrl=%u rx_data=%u "
  77. "fcs_error=%u",
  78. wt.rx_mgmt, wt.rx_ctrl, wt.rx_data, wt.fcs_error);
  79. if (ifname)
  80. monitor_deinit(&wt);
  81. eloop_destroy();
  82. os_program_deinit();
  83. return 0;
  84. }