wlantest: Add option for writing a PCAP dump file
[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
21 struct ieee802_11_elems;
22 struct radius_msg;
23 struct ieee80211_hdr;
24
25 #define MAX_RADIUS_SECRET_LEN 128
26
27 struct wlantest_radius_secret {
28         struct dl_list list;
29         char secret[MAX_RADIUS_SECRET_LEN];
30 };
31
32 struct wlantest_passphrase {
33         struct dl_list list;
34         char passphrase[64];
35         u8 ssid[32];
36         size_t ssid_len;
37         u8 bssid[ETH_ALEN];
38 };
39
40 struct wlantest_pmk {
41         struct dl_list list;
42         u8 pmk[32];
43 };
44
45 struct wlantest_sta {
46         struct dl_list list;
47         u8 addr[ETH_ALEN];
48         enum {
49                 STATE1 /* not authenticated */,
50                 STATE2 /* authenticated */,
51                 STATE3 /* associated */
52         } state;
53         u16 aid;
54         u8 rsnie[257]; /* WPA/RSN IE */
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 };
64
65 struct wlantest_bss {
66         struct dl_list list;
67         u8 bssid[ETH_ALEN];
68         u16 capab_info;
69         u8 ssid[32];
70         size_t ssid_len;
71         int proberesp_seen;
72         int parse_error_reported;
73         u8 wpaie[257];
74         u8 rsnie[257];
75         struct dl_list sta; /* struct wlantest_sta */
76         struct dl_list pmk; /* struct wlantest_pmk */
77         u8 gtk[4][32];
78         size_t gtk_len[4];
79         u8 rsc[4][6];
80         u8 igtk[6][16];
81         int igtk_set[6];
82         u8 ipn[6][6];
83 };
84
85 struct wlantest_radius {
86         struct dl_list list;
87         u32 srv;
88         u32 cli;
89         struct radius_msg *last_req;
90 };
91
92 struct wlantest {
93         int monitor_sock;
94         int monitor_wired;
95
96         struct dl_list passphrase; /* struct wlantest_passphrase */
97         struct dl_list bss; /* struct wlantest_bss */
98         struct dl_list secret; /* struct wlantest_radius_secret */
99         struct dl_list radius; /* struct wlantest_radius */
100         struct dl_list pmk; /* struct wlantest_pmk */
101
102         unsigned int rx_mgmt;
103         unsigned int rx_ctrl;
104         unsigned int rx_data;
105         unsigned int fcs_error;
106
107         void *write_pcap; /* pcap_t* */
108         void *write_pcap_dumper; /* pcpa_dumper_t */
109         struct timeval write_pcap_time;
110 };
111
112 int read_cap_file(struct wlantest *wt, const char *fname);
113 int read_wired_cap_file(struct wlantest *wt, const char *fname);
114 int write_pcap_init(struct wlantest *wt, const char *fname);
115 void write_pcap_deinit(struct wlantest *wt);
116 void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len);
117 void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
118                           const u8 *buf2, size_t len2);
119 void wlantest_process(struct wlantest *wt, const u8 *data, size_t len);
120 void wlantest_process_wired(struct wlantest *wt, const u8 *data, size_t len);
121 u32 crc32(const u8 *frame, size_t frame_len);
122 int monitor_init(struct wlantest *wt, const char *ifname);
123 int monitor_init_wired(struct wlantest *wt, const char *ifname);
124 void monitor_deinit(struct wlantest *wt);
125 void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len);
126 void rx_data(struct wlantest *wt, const u8 *data, size_t len);
127
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
134 struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
135 void sta_deinit(struct wlantest_sta *sta);
136 void sta_update_assoc(struct wlantest_sta *sta,
137                       struct ieee802_11_elems *elems);
138
139 u8 * ccmp_decrypt(const u8 *tk, const struct ieee80211_hdr *hdr,
140                   const u8 *data, size_t data_len, size_t *decrypted_len);
141 void ccmp_get_pn(u8 *pn, const u8 *data);
142
143 #endif /* WLANTEST_H */