wlantest.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * wlantest - IEEE 802.11 protocol monitoring and testing tool
  3. * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef WLANTEST_H
  9. #define WLANTEST_H
  10. #include "utils/list.h"
  11. #include "common/wpa_common.h"
  12. #include "wlantest_ctrl.h"
  13. struct ieee802_11_elems;
  14. struct radius_msg;
  15. struct ieee80211_hdr;
  16. struct wlantest_bss;
  17. #define MAX_RADIUS_SECRET_LEN 128
  18. struct wlantest_radius_secret {
  19. struct dl_list list;
  20. char secret[MAX_RADIUS_SECRET_LEN];
  21. };
  22. struct wlantest_passphrase {
  23. struct dl_list list;
  24. char passphrase[64];
  25. u8 ssid[32];
  26. size_t ssid_len;
  27. u8 bssid[ETH_ALEN];
  28. };
  29. struct wlantest_pmk {
  30. struct dl_list list;
  31. u8 pmk[PMK_LEN_MAX];
  32. size_t pmk_len;
  33. };
  34. struct wlantest_ptk {
  35. struct dl_list list;
  36. struct wpa_ptk ptk;
  37. size_t ptk_len;
  38. };
  39. struct wlantest_wep {
  40. struct dl_list list;
  41. size_t key_len;
  42. u8 key[13];
  43. };
  44. struct wlantest_sta {
  45. struct dl_list list;
  46. struct wlantest_bss *bss;
  47. u8 addr[ETH_ALEN];
  48. enum {
  49. STATE1 /* not authenticated */,
  50. STATE2 /* authenticated */,
  51. STATE3 /* associated */
  52. } state;
  53. u16 auth_alg;
  54. u16 aid;
  55. u8 rsnie[257]; /* WPA/RSN IE */
  56. u8 osenie[257]; /* OSEN IE */
  57. int proto;
  58. int pairwise_cipher;
  59. int group_cipher;
  60. int key_mgmt;
  61. int rsn_capab;
  62. u8 anonce[32]; /* ANonce from the previous EAPOL-Key msg 1/4 or 3/4 */
  63. u8 snonce[32]; /* SNonce from the previous EAPOL-Key msg 2/4 */
  64. struct wpa_ptk ptk; /* Derived PTK */
  65. int ptk_set;
  66. struct wpa_ptk tptk; /* Derived PTK during rekeying */
  67. int tptk_set;
  68. u8 rsc_tods[16 + 1][6];
  69. u8 rsc_fromds[16 + 1][6];
  70. u8 ap_sa_query_tr[2];
  71. u8 sta_sa_query_tr[2];
  72. u32 counters[NUM_WLANTEST_STA_COUNTER];
  73. u16 assocreq_capab_info;
  74. u16 assocreq_listen_int;
  75. u8 *assocreq_ies;
  76. size_t assocreq_ies_len;
  77. /* Last ICMP Echo request information */
  78. u32 icmp_echo_req_src;
  79. u32 icmp_echo_req_dst;
  80. u16 icmp_echo_req_id;
  81. u16 icmp_echo_req_seq;
  82. le16 seq_ctrl_to_sta[17];
  83. le16 seq_ctrl_to_ap[17];
  84. int pwrmgt;
  85. int pspoll;
  86. u8 gtk[32];
  87. size_t gtk_len;
  88. int gtk_idx;
  89. u32 tx_tid[16 + 1];
  90. u32 rx_tid[16 + 1];
  91. };
  92. struct wlantest_tdls {
  93. struct dl_list list;
  94. struct wlantest_sta *init;
  95. struct wlantest_sta *resp;
  96. struct tpk {
  97. u8 kck[16];
  98. u8 tk[16];
  99. } tpk;
  100. int link_up;
  101. u8 dialog_token;
  102. u8 rsc_init[16 + 1][6];
  103. u8 rsc_resp[16 + 1][6];
  104. u32 counters[NUM_WLANTEST_TDLS_COUNTER];
  105. u8 inonce[32];
  106. u8 rnonce[32];
  107. };
  108. struct wlantest_bss {
  109. struct dl_list list;
  110. u8 bssid[ETH_ALEN];
  111. u16 capab_info;
  112. u16 prev_capab_info;
  113. u8 ssid[32];
  114. size_t ssid_len;
  115. int beacon_seen;
  116. int proberesp_seen;
  117. int parse_error_reported;
  118. u8 wpaie[257];
  119. u8 rsnie[257];
  120. u8 osenie[257];
  121. int proto;
  122. int pairwise_cipher;
  123. int group_cipher;
  124. int mgmt_group_cipher;
  125. int key_mgmt;
  126. int rsn_capab;
  127. struct dl_list sta; /* struct wlantest_sta */
  128. struct dl_list pmk; /* struct wlantest_pmk */
  129. u8 gtk[4][32];
  130. size_t gtk_len[4];
  131. int gtk_idx;
  132. u8 rsc[4][6];
  133. u8 igtk[6][32];
  134. size_t igtk_len[6];
  135. int igtk_idx;
  136. u8 ipn[6][6];
  137. u32 counters[NUM_WLANTEST_BSS_COUNTER];
  138. struct dl_list tdls; /* struct wlantest_tdls */
  139. u8 mdid[2];
  140. u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
  141. size_t r0kh_id_len;
  142. u8 r1kh_id[FT_R1KH_ID_LEN];
  143. };
  144. struct wlantest_radius {
  145. struct dl_list list;
  146. u32 srv;
  147. u32 cli;
  148. struct radius_msg *last_req;
  149. };
  150. #define MAX_CTRL_CONNECTIONS 10
  151. #define MAX_NOTES 10
  152. struct wlantest {
  153. int monitor_sock;
  154. int monitor_wired;
  155. int ctrl_sock;
  156. int ctrl_socks[MAX_CTRL_CONNECTIONS];
  157. struct dl_list passphrase; /* struct wlantest_passphrase */
  158. struct dl_list bss; /* struct wlantest_bss */
  159. struct dl_list secret; /* struct wlantest_radius_secret */
  160. struct dl_list radius; /* struct wlantest_radius */
  161. struct dl_list pmk; /* struct wlantest_pmk */
  162. struct dl_list ptk; /* struct wlantest_ptk */
  163. struct dl_list wep; /* struct wlantest_wep */
  164. unsigned int rx_mgmt;
  165. unsigned int rx_ctrl;
  166. unsigned int rx_data;
  167. unsigned int fcs_error;
  168. void *write_pcap; /* pcap_t* */
  169. void *write_pcap_dumper; /* pcpa_dumper_t */
  170. struct timeval write_pcap_time;
  171. u8 *decrypted;
  172. size_t decrypted_len;
  173. FILE *pcapng;
  174. u32 write_pcapng_time_high;
  175. u32 write_pcapng_time_low;
  176. u8 last_hdr[30];
  177. size_t last_len;
  178. int last_mgmt_valid;
  179. unsigned int assume_fcs:1;
  180. unsigned int pcap_no_buffer:1;
  181. char *notes[MAX_NOTES];
  182. size_t num_notes;
  183. const char *write_file;
  184. const char *pcapng_file;
  185. };
  186. void add_note(struct wlantest *wt, int level, const char *fmt, ...)
  187. PRINTF_FORMAT(3, 4);
  188. void clear_notes(struct wlantest *wt);
  189. size_t notes_len(struct wlantest *wt, size_t hdrlen);
  190. int add_wep(struct wlantest *wt, const char *key);
  191. int read_cap_file(struct wlantest *wt, const char *fname);
  192. int read_wired_cap_file(struct wlantest *wt, const char *fname);
  193. int write_pcap_init(struct wlantest *wt, const char *fname);
  194. void write_pcap_deinit(struct wlantest *wt);
  195. void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len);
  196. void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
  197. const u8 *buf2, size_t len2);
  198. int write_pcapng_init(struct wlantest *wt, const char *fname);
  199. void write_pcapng_deinit(struct wlantest *wt);
  200. struct pcap_pkthdr;
  201. void write_pcapng_write_read(struct wlantest *wt, int dlt,
  202. struct pcap_pkthdr *hdr, const u8 *data);
  203. void write_pcapng_captured(struct wlantest *wt, const u8 *buf, size_t len);
  204. void wlantest_process(struct wlantest *wt, const u8 *data, size_t len);
  205. void wlantest_process_prism(struct wlantest *wt, const u8 *data, size_t len);
  206. void wlantest_process_80211(struct wlantest *wt, const u8 *data, size_t len);
  207. void wlantest_process_wired(struct wlantest *wt, const u8 *data, size_t len);
  208. int monitor_init(struct wlantest *wt, const char *ifname);
  209. int monitor_init_wired(struct wlantest *wt, const char *ifname);
  210. void monitor_deinit(struct wlantest *wt);
  211. void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len);
  212. void rx_mgmt_ack(struct wlantest *wt, const struct ieee80211_hdr *hdr);
  213. void rx_data(struct wlantest *wt, const u8 *data, size_t len);
  214. void rx_data_eapol(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
  215. const u8 *dst, const u8 *src,
  216. const u8 *data, size_t len, int prot);
  217. void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
  218. const u8 *dst, const u8 *src, const u8 *data, size_t len,
  219. const u8 *peer_addr);
  220. void rx_data_80211_encap(struct wlantest *wt, const u8 *bssid,
  221. const u8 *sta_addr, const u8 *dst, const u8 *src,
  222. const u8 *data, size_t len);
  223. struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid);
  224. struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid);
  225. void bss_deinit(struct wlantest_bss *bss);
  226. void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
  227. struct ieee802_11_elems *elems);
  228. void bss_flush(struct wlantest *wt);
  229. int bss_add_pmk_from_passphrase(struct wlantest_bss *bss,
  230. const char *passphrase);
  231. void pmk_deinit(struct wlantest_pmk *pmk);
  232. void tdls_deinit(struct wlantest_tdls *tdls);
  233. struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr);
  234. struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
  235. void sta_deinit(struct wlantest_sta *sta);
  236. void sta_update_assoc(struct wlantest_sta *sta,
  237. struct ieee802_11_elems *elems);
  238. u8 * ccmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  239. const u8 *data, size_t data_len, size_t *decrypted_len);
  240. u8 * ccmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
  241. u8 *pn, int keyid, size_t *encrypted_len);
  242. u8 * ccmp_encrypt_pv1(const u8 *tk, const u8 *a1, const u8 *a2, const u8 *a3,
  243. const u8 *frame, size_t len,
  244. size_t hdrlen, const u8 *pn, int keyid,
  245. size_t *encrypted_len);
  246. void ccmp_get_pn(u8 *pn, const u8 *data);
  247. u8 * ccmp_256_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  248. const u8 *data, size_t data_len, size_t *decrypted_len);
  249. u8 * ccmp_256_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen,
  250. u8 *qos, u8 *pn, int keyid, size_t *encrypted_len);
  251. u8 * tkip_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
  252. const u8 *data, size_t data_len, size_t *decrypted_len);
  253. u8 * tkip_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
  254. u8 *pn, int keyid, size_t *encrypted_len);
  255. void tkip_get_pn(u8 *pn, const u8 *data);
  256. u8 * wep_decrypt(struct wlantest *wt, const struct ieee80211_hdr *hdr,
  257. const u8 *data, size_t data_len, size_t *decrypted_len);
  258. u8 * bip_protect(const u8 *igtk, size_t igtk_len, u8 *frame, size_t len,
  259. u8 *ipn, int keyid, size_t *prot_len);
  260. u8 * bip_gmac_protect(const u8 *igtk, size_t igtk_len, u8 *frame, size_t len,
  261. u8 *ipn, int keyid, size_t *prot_len);
  262. u8 * gcmp_decrypt(const u8 *tk, size_t tk_len, const struct ieee80211_hdr *hdr,
  263. const u8 *data, size_t data_len, size_t *decrypted_len);
  264. u8 * gcmp_encrypt(const u8 *tk, size_t tk_len, const u8 *frame, size_t len,
  265. size_t hdrlen, const u8 *qos,
  266. const u8 *pn, int keyid, size_t *encrypted_len);
  267. int ctrl_init(struct wlantest *wt);
  268. void ctrl_deinit(struct wlantest *wt);
  269. int wlantest_inject(struct wlantest *wt, struct wlantest_bss *bss,
  270. struct wlantest_sta *sta, u8 *frame, size_t len,
  271. enum wlantest_inject_protection prot);
  272. int wlantest_relog(struct wlantest *wt);
  273. #endif /* WLANTEST_H */