wlantest.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #ifndef WLANTEST_H
  15. #define WLANTEST_H
  16. #include "utils/list.h"
  17. #include "common/wpa_common.h"
  18. struct ieee802_11_elems;
  19. struct radius_msg;
  20. struct ieee80211_hdr;
  21. struct wlantest_bss;
  22. #define MAX_RADIUS_SECRET_LEN 128
  23. struct wlantest_radius_secret {
  24. struct dl_list list;
  25. char secret[MAX_RADIUS_SECRET_LEN];
  26. };
  27. struct wlantest_passphrase {
  28. struct dl_list list;
  29. char passphrase[64];
  30. u8 ssid[32];
  31. size_t ssid_len;
  32. u8 bssid[ETH_ALEN];
  33. };
  34. struct wlantest_pmk {
  35. struct dl_list list;
  36. u8 pmk[32];
  37. };
  38. struct wlantest_sta {
  39. struct dl_list list;
  40. struct wlantest_bss *bss;
  41. u8 addr[ETH_ALEN];
  42. enum {
  43. STATE1 /* not authenticated */,
  44. STATE2 /* authenticated */,
  45. STATE3 /* associated */
  46. } state;
  47. u16 aid;
  48. u8 rsnie[257]; /* WPA/RSN IE */
  49. int proto;
  50. int pairwise_cipher;
  51. int group_cipher;
  52. int key_mgmt;
  53. int rsn_capab;
  54. u8 anonce[32]; /* ANonce from the previous EAPOL-Key msg 1/4 or 3/4 */
  55. u8 snonce[32]; /* SNonce from the previous EAPOL-Key msg 2/4 */
  56. struct wpa_ptk ptk; /* Derived PTK */
  57. int ptk_set;
  58. u8 rsc_tods[16 + 1][6];
  59. u8 rsc_fromds[16 + 1][6];
  60. u8 ap_sa_query_tr[2];
  61. u8 sta_sa_query_tr[2];
  62. };
  63. struct wlantest_bss {
  64. struct dl_list list;
  65. u8 bssid[ETH_ALEN];
  66. u16 capab_info;
  67. u8 ssid[32];
  68. size_t ssid_len;
  69. int proberesp_seen;
  70. int parse_error_reported;
  71. u8 wpaie[257];
  72. u8 rsnie[257];
  73. int proto;
  74. int pairwise_cipher;
  75. int group_cipher;
  76. int mgmt_group_cipher;
  77. int key_mgmt;
  78. int rsn_capab;
  79. struct dl_list sta; /* struct wlantest_sta */
  80. struct dl_list pmk; /* struct wlantest_pmk */
  81. u8 gtk[4][32];
  82. size_t gtk_len[4];
  83. u8 rsc[4][6];
  84. u8 igtk[6][16];
  85. int igtk_set[6];
  86. u8 ipn[6][6];
  87. };
  88. struct wlantest_radius {
  89. struct dl_list list;
  90. u32 srv;
  91. u32 cli;
  92. struct radius_msg *last_req;
  93. };
  94. #define MAX_CTRL_CONNECTIONS 10
  95. struct wlantest {
  96. int monitor_sock;
  97. int monitor_wired;
  98. int ctrl_sock;
  99. int ctrl_socks[MAX_CTRL_CONNECTIONS];
  100. struct dl_list passphrase; /* struct wlantest_passphrase */
  101. struct dl_list bss; /* struct wlantest_bss */
  102. struct dl_list secret; /* struct wlantest_radius_secret */
  103. struct dl_list radius; /* struct wlantest_radius */
  104. struct dl_list pmk; /* struct wlantest_pmk */
  105. unsigned int rx_mgmt;
  106. unsigned int rx_ctrl;
  107. unsigned int rx_data;
  108. unsigned int fcs_error;
  109. void *write_pcap; /* pcap_t* */
  110. void *write_pcap_dumper; /* pcpa_dumper_t */
  111. struct timeval write_pcap_time;
  112. };
  113. int read_cap_file(struct wlantest *wt, const char *fname);
  114. int read_wired_cap_file(struct wlantest *wt, const char *fname);
  115. int write_pcap_init(struct wlantest *wt, const char *fname);
  116. void write_pcap_deinit(struct wlantest *wt);
  117. void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len);
  118. void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
  119. const u8 *buf2, size_t len2);
  120. void wlantest_process(struct wlantest *wt, const u8 *data, size_t len);
  121. void wlantest_process_wired(struct wlantest *wt, const u8 *data, size_t len);
  122. u32 crc32(const u8 *frame, size_t frame_len);
  123. int monitor_init(struct wlantest *wt, const char *ifname);
  124. int monitor_init_wired(struct wlantest *wt, const char *ifname);
  125. void monitor_deinit(struct wlantest *wt);
  126. void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len);
  127. void rx_data(struct wlantest *wt, const u8 *data, size_t len);
  128. struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid);
  129. void bss_deinit(struct wlantest_bss *bss);
  130. void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
  131. struct ieee802_11_elems *elems);
  132. void pmk_deinit(struct wlantest_pmk *pmk);
  133. struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
  134. void sta_deinit(struct wlantest_sta *sta);
  135. void sta_update_assoc(struct wlantest_sta *sta,
  136. struct ieee802_11_elems *elems);
  137. u8 * ccmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  138. const u8 *data, size_t data_len, size_t *decrypted_len);
  139. void ccmp_get_pn(u8 *pn, const u8 *data);
  140. u8 * tkip_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  141. const u8 *data, size_t data_len, size_t *decrypted_len);
  142. void tkip_get_pn(u8 *pn, const u8 *data);
  143. int ctrl_init(struct wlantest *wt);
  144. void ctrl_deinit(struct wlantest *wt);
  145. #endif /* WLANTEST_H */