wlantest.h 5.7 KB

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