2010-11-06 15:20:45 +01:00
|
|
|
/*
|
|
|
|
* wlantest - IEEE 802.11 protocol monitoring and testing tool
|
2013-11-17 20:11:35 +01:00
|
|
|
* Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
|
2010-11-06 15:20:45 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2010-11-06 15:20:45 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WLANTEST_H
|
|
|
|
#define WLANTEST_H
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
#include "utils/list.h"
|
2010-11-06 21:57:49 +01:00
|
|
|
#include "common/wpa_common.h"
|
2010-11-18 18:05:29 +01:00
|
|
|
#include "wlantest_ctrl.h"
|
2010-11-06 16:11:12 +01:00
|
|
|
|
2010-11-06 16:57:21 +01:00
|
|
|
struct ieee802_11_elems;
|
2010-11-07 18:43:10 +01:00
|
|
|
struct radius_msg;
|
2010-11-11 00:29:30 +01:00
|
|
|
struct ieee80211_hdr;
|
2010-11-12 21:40:59 +01:00
|
|
|
struct wlantest_bss;
|
2010-11-06 16:57:21 +01:00
|
|
|
|
2010-11-07 18:43:10 +01:00
|
|
|
#define MAX_RADIUS_SECRET_LEN 128
|
|
|
|
|
|
|
|
struct wlantest_radius_secret {
|
|
|
|
struct dl_list list;
|
|
|
|
char secret[MAX_RADIUS_SECRET_LEN];
|
|
|
|
};
|
2010-11-06 16:11:12 +01:00
|
|
|
|
2010-11-06 21:57:49 +01:00
|
|
|
struct wlantest_passphrase {
|
|
|
|
struct dl_list list;
|
|
|
|
char passphrase[64];
|
|
|
|
u8 ssid[32];
|
|
|
|
size_t ssid_len;
|
|
|
|
u8 bssid[ETH_ALEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wlantest_pmk {
|
|
|
|
struct dl_list list;
|
|
|
|
u8 pmk[32];
|
|
|
|
};
|
|
|
|
|
2013-11-17 21:52:15 +01:00
|
|
|
struct wlantest_ptk {
|
|
|
|
struct dl_list list;
|
|
|
|
struct wpa_ptk ptk;
|
|
|
|
size_t ptk_len;
|
|
|
|
};
|
|
|
|
|
2011-01-14 16:43:17 +01:00
|
|
|
struct wlantest_wep {
|
|
|
|
struct dl_list list;
|
|
|
|
size_t key_len;
|
|
|
|
u8 key[13];
|
|
|
|
};
|
|
|
|
|
2010-11-06 16:31:02 +01:00
|
|
|
struct wlantest_sta {
|
|
|
|
struct dl_list list;
|
2010-11-12 21:40:59 +01:00
|
|
|
struct wlantest_bss *bss;
|
2010-11-06 16:31:02 +01:00
|
|
|
u8 addr[ETH_ALEN];
|
2010-11-06 16:55:27 +01:00
|
|
|
enum {
|
|
|
|
STATE1 /* not authenticated */,
|
|
|
|
STATE2 /* authenticated */,
|
|
|
|
STATE3 /* associated */
|
|
|
|
} state;
|
|
|
|
u16 aid;
|
2010-11-06 17:10:34 +01:00
|
|
|
u8 rsnie[257]; /* WPA/RSN IE */
|
2014-05-15 11:40:02 +02:00
|
|
|
u8 osenie[257]; /* OSEN IE */
|
2010-11-12 21:40:59 +01:00
|
|
|
int proto;
|
|
|
|
int pairwise_cipher;
|
|
|
|
int group_cipher;
|
|
|
|
int key_mgmt;
|
|
|
|
int rsn_capab;
|
2010-11-06 21:57:49 +01:00
|
|
|
u8 anonce[32]; /* ANonce from the previous EAPOL-Key msg 1/4 or 3/4 */
|
|
|
|
u8 snonce[32]; /* SNonce from the previous EAPOL-Key msg 2/4 */
|
|
|
|
struct wpa_ptk ptk; /* Derived PTK */
|
2014-08-29 15:05:05 +02:00
|
|
|
size_t tk_len;
|
2010-11-06 21:57:49 +01:00
|
|
|
int ptk_set;
|
2011-11-14 21:33:26 +01:00
|
|
|
struct wpa_ptk tptk; /* Derived PTK during rekeying */
|
|
|
|
int tptk_set;
|
2010-11-11 19:46:15 +01:00
|
|
|
u8 rsc_tods[16 + 1][6];
|
|
|
|
u8 rsc_fromds[16 + 1][6];
|
2010-11-11 20:34:06 +01:00
|
|
|
u8 ap_sa_query_tr[2];
|
|
|
|
u8 sta_sa_query_tr[2];
|
2010-11-18 18:05:29 +01:00
|
|
|
u32 counters[NUM_WLANTEST_STA_COUNTER];
|
2010-11-19 16:09:02 +01:00
|
|
|
u16 assocreq_capab_info;
|
|
|
|
u16 assocreq_listen_int;
|
|
|
|
u8 *assocreq_ies;
|
|
|
|
size_t assocreq_ies_len;
|
2010-11-20 21:34:42 +01:00
|
|
|
|
|
|
|
/* Last ICMP Echo request information */
|
|
|
|
u32 icmp_echo_req_src;
|
|
|
|
u32 icmp_echo_req_dst;
|
|
|
|
u16 icmp_echo_req_id;
|
|
|
|
u16 icmp_echo_req_seq;
|
2010-11-23 13:27:28 +01:00
|
|
|
|
|
|
|
le16 seq_ctrl_to_sta[17];
|
|
|
|
le16 seq_ctrl_to_ap[17];
|
2011-01-07 14:54:58 +01:00
|
|
|
|
|
|
|
int pwrmgt;
|
|
|
|
int pspoll;
|
2011-12-22 15:59:25 +01:00
|
|
|
|
|
|
|
u8 gtk[32];
|
|
|
|
size_t gtk_len;
|
|
|
|
int gtk_idx;
|
2013-12-24 19:21:27 +01:00
|
|
|
|
|
|
|
u32 tx_tid[16 + 1];
|
|
|
|
u32 rx_tid[16 + 1];
|
2010-11-06 16:31:02 +01:00
|
|
|
};
|
|
|
|
|
2010-12-13 10:20:55 +01:00
|
|
|
struct wlantest_tdls {
|
|
|
|
struct dl_list list;
|
|
|
|
struct wlantest_sta *init;
|
|
|
|
struct wlantest_sta *resp;
|
|
|
|
struct tpk {
|
|
|
|
u8 kck[16];
|
|
|
|
u8 tk[16];
|
|
|
|
} tpk;
|
|
|
|
int link_up;
|
2010-12-16 16:08:00 +01:00
|
|
|
u8 dialog_token;
|
2010-12-13 10:20:55 +01:00
|
|
|
u8 rsc_init[16 + 1][6];
|
|
|
|
u8 rsc_resp[16 + 1][6];
|
2010-12-16 18:08:49 +01:00
|
|
|
u32 counters[NUM_WLANTEST_TDLS_COUNTER];
|
2013-05-26 20:35:00 +02:00
|
|
|
u8 inonce[32];
|
|
|
|
u8 rnonce[32];
|
2010-12-13 10:20:55 +01:00
|
|
|
};
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
struct wlantest_bss {
|
|
|
|
struct dl_list list;
|
|
|
|
u8 bssid[ETH_ALEN];
|
|
|
|
u16 capab_info;
|
2011-01-14 16:43:17 +01:00
|
|
|
u16 prev_capab_info;
|
2010-11-06 16:11:12 +01:00
|
|
|
u8 ssid[32];
|
|
|
|
size_t ssid_len;
|
|
|
|
int proberesp_seen;
|
|
|
|
int parse_error_reported;
|
|
|
|
u8 wpaie[257];
|
|
|
|
u8 rsnie[257];
|
2014-05-15 11:40:02 +02:00
|
|
|
u8 osenie[257];
|
2010-11-12 21:40:59 +01:00
|
|
|
int proto;
|
|
|
|
int pairwise_cipher;
|
|
|
|
int group_cipher;
|
|
|
|
int mgmt_group_cipher;
|
|
|
|
int key_mgmt;
|
|
|
|
int rsn_capab;
|
2010-11-06 16:31:02 +01:00
|
|
|
struct dl_list sta; /* struct wlantest_sta */
|
2010-11-06 21:57:49 +01:00
|
|
|
struct dl_list pmk; /* struct wlantest_pmk */
|
2010-11-09 19:29:12 +01:00
|
|
|
u8 gtk[4][32];
|
|
|
|
size_t gtk_len[4];
|
2010-11-19 15:48:33 +01:00
|
|
|
int gtk_idx;
|
2010-11-11 19:21:11 +01:00
|
|
|
u8 rsc[4][6];
|
2015-01-23 16:24:24 +01:00
|
|
|
u8 igtk[6][32];
|
|
|
|
size_t igtk_len[6];
|
2010-11-19 15:48:33 +01:00
|
|
|
int igtk_idx;
|
2010-11-10 01:06:59 +01:00
|
|
|
u8 ipn[6][6];
|
2010-11-18 18:05:29 +01:00
|
|
|
u32 counters[NUM_WLANTEST_BSS_COUNTER];
|
2010-12-13 10:20:55 +01:00
|
|
|
struct dl_list tdls; /* struct wlantest_tdls */
|
2015-08-06 14:51:36 +02:00
|
|
|
u8 mdid[2];
|
|
|
|
u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
|
|
|
|
size_t r0kh_id_len;
|
|
|
|
u8 r1kh_id[FT_R1KH_ID_LEN];
|
2010-11-06 16:11:12 +01:00
|
|
|
};
|
|
|
|
|
2010-11-07 18:43:10 +01:00
|
|
|
struct wlantest_radius {
|
|
|
|
struct dl_list list;
|
|
|
|
u32 srv;
|
|
|
|
u32 cli;
|
|
|
|
struct radius_msg *last_req;
|
|
|
|
};
|
|
|
|
|
2010-11-13 17:38:19 +01:00
|
|
|
|
|
|
|
#define MAX_CTRL_CONNECTIONS 10
|
2013-05-26 18:39:48 +02:00
|
|
|
#define MAX_NOTES 10
|
2010-11-13 17:38:19 +01:00
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
struct wlantest {
|
|
|
|
int monitor_sock;
|
2010-11-07 16:59:50 +01:00
|
|
|
int monitor_wired;
|
2010-11-06 15:20:45 +01:00
|
|
|
|
2010-11-13 17:38:19 +01:00
|
|
|
int ctrl_sock;
|
|
|
|
int ctrl_socks[MAX_CTRL_CONNECTIONS];
|
|
|
|
|
2010-11-06 21:57:49 +01:00
|
|
|
struct dl_list passphrase; /* struct wlantest_passphrase */
|
2010-11-06 16:11:12 +01:00
|
|
|
struct dl_list bss; /* struct wlantest_bss */
|
2010-11-07 18:43:10 +01:00
|
|
|
struct dl_list secret; /* struct wlantest_radius_secret */
|
|
|
|
struct dl_list radius; /* struct wlantest_radius */
|
|
|
|
struct dl_list pmk; /* struct wlantest_pmk */
|
2013-11-17 21:52:15 +01:00
|
|
|
struct dl_list ptk; /* struct wlantest_ptk */
|
2011-01-14 16:43:17 +01:00
|
|
|
struct dl_list wep; /* struct wlantest_wep */
|
2010-11-06 16:11:12 +01:00
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
unsigned int rx_mgmt;
|
|
|
|
unsigned int rx_ctrl;
|
|
|
|
unsigned int rx_data;
|
|
|
|
unsigned int fcs_error;
|
2010-11-12 00:00:31 +01:00
|
|
|
|
|
|
|
void *write_pcap; /* pcap_t* */
|
|
|
|
void *write_pcap_dumper; /* pcpa_dumper_t */
|
|
|
|
struct timeval write_pcap_time;
|
2013-05-26 18:39:48 +02:00
|
|
|
u8 *decrypted;
|
|
|
|
size_t decrypted_len;
|
|
|
|
FILE *pcapng;
|
|
|
|
u32 write_pcapng_time_high;
|
|
|
|
u32 write_pcapng_time_low;
|
2011-01-03 18:28:40 +01:00
|
|
|
|
|
|
|
u8 last_hdr[30];
|
|
|
|
size_t last_len;
|
|
|
|
int last_mgmt_valid;
|
2013-01-17 11:55:30 +01:00
|
|
|
|
|
|
|
unsigned int assume_fcs:1;
|
2013-05-26 18:39:48 +02:00
|
|
|
|
|
|
|
char *notes[MAX_NOTES];
|
|
|
|
size_t num_notes;
|
2013-11-17 20:11:35 +01:00
|
|
|
|
|
|
|
const char *write_file;
|
|
|
|
const char *pcapng_file;
|
2010-11-06 15:20:45 +01:00
|
|
|
};
|
|
|
|
|
2013-05-26 18:39:48 +02:00
|
|
|
void add_note(struct wlantest *wt, int level, const char *fmt, ...)
|
|
|
|
PRINTF_FORMAT(3, 4);
|
|
|
|
void clear_notes(struct wlantest *wt);
|
|
|
|
size_t notes_len(struct wlantest *wt, size_t hdrlen);
|
|
|
|
|
2011-01-28 12:33:21 +01:00
|
|
|
int add_wep(struct wlantest *wt, const char *key);
|
2010-11-06 15:20:45 +01:00
|
|
|
int read_cap_file(struct wlantest *wt, const char *fname);
|
2010-11-07 16:59:50 +01:00
|
|
|
int read_wired_cap_file(struct wlantest *wt, const char *fname);
|
2013-05-26 18:39:48 +02:00
|
|
|
|
2010-11-12 00:00:31 +01:00
|
|
|
int write_pcap_init(struct wlantest *wt, const char *fname);
|
|
|
|
void write_pcap_deinit(struct wlantest *wt);
|
|
|
|
void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len);
|
|
|
|
void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
|
|
|
|
const u8 *buf2, size_t len2);
|
2013-05-26 18:39:48 +02:00
|
|
|
|
|
|
|
int write_pcapng_init(struct wlantest *wt, const char *fname);
|
|
|
|
void write_pcapng_deinit(struct wlantest *wt);
|
|
|
|
struct pcap_pkthdr;
|
|
|
|
void write_pcapng_write_read(struct wlantest *wt, int dlt,
|
|
|
|
struct pcap_pkthdr *hdr, const u8 *data);
|
|
|
|
void write_pcapng_captured(struct wlantest *wt, const u8 *buf, size_t len);
|
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
void wlantest_process(struct wlantest *wt, const u8 *data, size_t len);
|
2010-12-02 21:56:37 +01:00
|
|
|
void wlantest_process_prism(struct wlantest *wt, const u8 *data, size_t len);
|
2010-12-04 20:18:21 +01:00
|
|
|
void wlantest_process_80211(struct wlantest *wt, const u8 *data, size_t len);
|
2010-11-07 16:59:50 +01:00
|
|
|
void wlantest_process_wired(struct wlantest *wt, const u8 *data, size_t len);
|
2010-11-06 15:20:45 +01:00
|
|
|
u32 crc32(const u8 *frame, size_t frame_len);
|
|
|
|
int monitor_init(struct wlantest *wt, const char *ifname);
|
2010-11-07 16:59:50 +01:00
|
|
|
int monitor_init_wired(struct wlantest *wt, const char *ifname);
|
2010-11-06 15:20:45 +01:00
|
|
|
void monitor_deinit(struct wlantest *wt);
|
2010-11-06 17:01:24 +01:00
|
|
|
void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len);
|
2011-01-03 18:28:40 +01:00
|
|
|
void rx_mgmt_ack(struct wlantest *wt, const struct ieee80211_hdr *hdr);
|
2010-11-06 17:01:24 +01:00
|
|
|
void rx_data(struct wlantest *wt, const u8 *data, size_t len);
|
2010-11-20 20:40:04 +01:00
|
|
|
void rx_data_eapol(struct wlantest *wt, const u8 *dst, const u8 *src,
|
|
|
|
const u8 *data, size_t len, int prot);
|
2010-11-20 21:34:42 +01:00
|
|
|
void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
|
2011-01-24 13:50:51 +01:00
|
|
|
const u8 *dst, const u8 *src, const u8 *data, size_t len,
|
|
|
|
const u8 *peer_addr);
|
2010-12-13 10:20:55 +01:00
|
|
|
void rx_data_80211_encap(struct wlantest *wt, const u8 *bssid,
|
|
|
|
const u8 *sta_addr, const u8 *dst, const u8 *src,
|
|
|
|
const u8 *data, size_t len);
|
2010-11-06 15:20:45 +01:00
|
|
|
|
2010-11-19 21:00:10 +01:00
|
|
|
struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid);
|
2010-11-06 16:11:12 +01:00
|
|
|
struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid);
|
|
|
|
void bss_deinit(struct wlantest_bss *bss);
|
2010-11-06 21:57:49 +01:00
|
|
|
void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
|
|
|
|
struct ieee802_11_elems *elems);
|
2010-11-18 16:36:08 +01:00
|
|
|
void bss_flush(struct wlantest *wt);
|
2010-11-21 12:19:43 +01:00
|
|
|
int bss_add_pmk_from_passphrase(struct wlantest_bss *bss,
|
|
|
|
const char *passphrase);
|
2010-11-07 18:43:10 +01:00
|
|
|
void pmk_deinit(struct wlantest_pmk *pmk);
|
2011-01-24 13:26:35 +01:00
|
|
|
void tdls_deinit(struct wlantest_tdls *tdls);
|
2010-11-06 16:11:12 +01:00
|
|
|
|
2010-11-19 21:00:10 +01:00
|
|
|
struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr);
|
2010-11-06 16:31:02 +01:00
|
|
|
struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
|
|
|
|
void sta_deinit(struct wlantest_sta *sta);
|
2010-11-06 17:10:34 +01:00
|
|
|
void sta_update_assoc(struct wlantest_sta *sta,
|
|
|
|
struct ieee802_11_elems *elems);
|
2010-11-06 16:31:02 +01:00
|
|
|
|
2010-11-11 00:29:30 +01:00
|
|
|
u8 * ccmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
|
|
|
|
const u8 *data, size_t data_len, size_t *decrypted_len);
|
2010-11-19 15:09:19 +01:00
|
|
|
u8 * ccmp_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
|
|
|
|
u8 *pn, int keyid, size_t *encrypted_len);
|
2010-11-11 19:21:11 +01:00
|
|
|
void ccmp_get_pn(u8 *pn, const u8 *data);
|
2012-09-09 17:38:18 +02:00
|
|
|
u8 * ccmp_256_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
|
|
|
|
const u8 *data, size_t data_len, size_t *decrypted_len);
|
|
|
|
u8 * ccmp_256_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen,
|
|
|
|
u8 *qos, u8 *pn, int keyid, size_t *encrypted_len);
|
2010-11-11 00:29:30 +01:00
|
|
|
|
2010-11-13 10:36:37 +01:00
|
|
|
u8 * tkip_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
|
|
|
|
const u8 *data, size_t data_len, size_t *decrypted_len);
|
2010-11-19 15:09:19 +01:00
|
|
|
u8 * tkip_encrypt(const u8 *tk, u8 *frame, size_t len, size_t hdrlen, u8 *qos,
|
|
|
|
u8 *pn, int keyid, size_t *encrypted_len);
|
2010-11-13 11:40:36 +01:00
|
|
|
void tkip_get_pn(u8 *pn, const u8 *data);
|
2010-11-13 10:36:37 +01:00
|
|
|
|
2011-01-14 16:43:17 +01:00
|
|
|
u8 * wep_decrypt(struct wlantest *wt, const struct ieee80211_hdr *hdr,
|
|
|
|
const u8 *data, size_t data_len, size_t *decrypted_len);
|
|
|
|
|
2015-01-23 16:24:24 +01:00
|
|
|
u8 * bip_protect(const u8 *igtk, size_t igtk_len, u8 *frame, size_t len,
|
|
|
|
u8 *ipn, int keyid, size_t *prot_len);
|
2012-09-09 18:04:53 +02:00
|
|
|
u8 * bip_gmac_protect(const u8 *igtk, size_t igtk_len, u8 *frame, size_t len,
|
|
|
|
u8 *ipn, int keyid, size_t *prot_len);
|
2012-09-08 15:32:35 +02:00
|
|
|
|
2012-09-09 13:01:03 +02:00
|
|
|
u8 * gcmp_decrypt(const u8 *tk, size_t tk_len, const struct ieee80211_hdr *hdr,
|
2012-09-08 19:00:54 +02:00
|
|
|
const u8 *data, size_t data_len, size_t *decrypted_len);
|
2015-04-24 09:19:53 +02:00
|
|
|
u8 * gcmp_encrypt(const u8 *tk, size_t tk_len, const u8 *frame, size_t len,
|
|
|
|
size_t hdrlen, const u8 *qos,
|
|
|
|
const u8 *pn, int keyid, size_t *encrypted_len);
|
2012-09-08 19:00:54 +02:00
|
|
|
|
2010-11-13 17:38:19 +01:00
|
|
|
int ctrl_init(struct wlantest *wt);
|
|
|
|
void ctrl_deinit(struct wlantest *wt);
|
|
|
|
|
2010-11-18 23:35:13 +01:00
|
|
|
int wlantest_inject(struct wlantest *wt, struct wlantest_bss *bss,
|
|
|
|
struct wlantest_sta *sta, u8 *frame, size_t len,
|
|
|
|
enum wlantest_inject_protection prot);
|
|
|
|
|
2013-11-17 20:11:35 +01:00
|
|
|
int wlantest_relog(struct wlantest *wt);
|
|
|
|
|
2010-11-06 15:20:45 +01:00
|
|
|
#endif /* WLANTEST_H */
|