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