iwinfo: add support for GCMP cipher
[project/iwinfo.git] / include / iwinfo.h
1 #ifndef __IWINFO_H_
2 #define __IWINFO_H_
3
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <sys/wait.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <fcntl.h>
12 #include <glob.h>
13 #include <ctype.h>
14 #include <dirent.h>
15 #include <stdint.h>
16
17 #include <sys/ioctl.h>
18 #include <sys/mman.h>
19 #include <net/if.h>
20 #include <errno.h>
21
22
23 #define IWINFO_BUFSIZE 24 * 1024
24 #define IWINFO_ESSID_MAX_SIZE 32
25
26 #define IWINFO_80211_A (1 << 0)
27 #define IWINFO_80211_B (1 << 1)
28 #define IWINFO_80211_G (1 << 2)
29 #define IWINFO_80211_N (1 << 3)
30 #define IWINFO_80211_AC (1 << 4)
31 #define IWINFO_80211_AD (1 << 5)
32
33 #define IWINFO_CIPHER_NONE (1 << 0)
34 #define IWINFO_CIPHER_WEP40 (1 << 1)
35 #define IWINFO_CIPHER_TKIP (1 << 2)
36 #define IWINFO_CIPHER_WRAP (1 << 3)
37 #define IWINFO_CIPHER_CCMP (1 << 4)
38 #define IWINFO_CIPHER_WEP104 (1 << 5)
39 #define IWINFO_CIPHER_AESOCB (1 << 6)
40 #define IWINFO_CIPHER_CKIP (1 << 7)
41 #define IWINFO_CIPHER_GCMP (1 << 8)
42 #define IWINFO_CIPHER_COUNT 9
43
44 #define IWINFO_KMGMT_NONE (1 << 0)
45 #define IWINFO_KMGMT_8021x (1 << 1)
46 #define IWINFO_KMGMT_PSK (1 << 2)
47 #define IWINFO_KMGMT_SAE (1 << 3)
48 #define IWINFO_KMGMT_OWE (1 << 4)
49 #define IWINFO_KMGMT_COUNT 5
50
51 #define IWINFO_AUTH_OPEN (1 << 0)
52 #define IWINFO_AUTH_SHARED (1 << 1)
53 #define IWINFO_AUTH_COUNT 2
54
55 #define IWINFO_FREQ_NO_10MHZ (1 << 0)
56 #define IWINFO_FREQ_NO_20MHZ (1 << 1)
57 #define IWINFO_FREQ_NO_HT40PLUS (1 << 2)
58 #define IWINFO_FREQ_NO_HT40MINUS (1 << 3)
59 #define IWINFO_FREQ_NO_80MHZ (1 << 4)
60 #define IWINFO_FREQ_NO_160MHZ (1 << 5)
61 #define IWINFO_FREQ_NO_2160MHZ (1 << 6)
62
63 extern const char *IWINFO_CIPHER_NAMES[IWINFO_CIPHER_COUNT];
64 extern const char *IWINFO_KMGMT_NAMES[IWINFO_KMGMT_COUNT];
65 extern const char *IWINFO_AUTH_NAMES[IWINFO_AUTH_COUNT];
66
67
68 enum iwinfo_opmode {
69 IWINFO_OPMODE_UNKNOWN = 0,
70 IWINFO_OPMODE_MASTER = 1,
71 IWINFO_OPMODE_ADHOC = 2,
72 IWINFO_OPMODE_CLIENT = 3,
73 IWINFO_OPMODE_MONITOR = 4,
74 IWINFO_OPMODE_AP_VLAN = 5,
75 IWINFO_OPMODE_WDS = 6,
76 IWINFO_OPMODE_MESHPOINT = 7,
77 IWINFO_OPMODE_P2P_CLIENT = 8,
78 IWINFO_OPMODE_P2P_GO = 9,
79 };
80
81 extern const char *IWINFO_OPMODE_NAMES[];
82
83
84 enum iwinfo_htmode {
85 IWINFO_HTMODE_HT20 = (1 << 0),
86 IWINFO_HTMODE_HT40 = (1 << 1),
87 IWINFO_HTMODE_VHT20 = (1 << 2),
88 IWINFO_HTMODE_VHT40 = (1 << 3),
89 IWINFO_HTMODE_VHT80 = (1 << 4),
90 IWINFO_HTMODE_VHT80_80 = (1 << 5),
91 IWINFO_HTMODE_VHT160 = (1 << 6),
92 IWINFO_HTMODE_NOHT = (1 << 7),
93
94 IWINFO_HTMODE_COUNT = 8
95 };
96
97 extern const char *IWINFO_HTMODE_NAMES[IWINFO_HTMODE_COUNT];
98
99
100 struct iwinfo_rate_entry {
101 uint32_t rate;
102 int8_t mcs;
103 uint8_t is_40mhz:1;
104 uint8_t is_short_gi:1;
105 uint8_t is_ht:1;
106 uint8_t is_vht:1;
107 uint8_t mhz;
108 uint8_t nss;
109 };
110
111 struct iwinfo_assoclist_entry {
112 uint8_t mac[6];
113 int8_t signal;
114 int8_t signal_avg;
115 int8_t noise;
116 uint32_t inactive;
117 uint32_t connected_time;
118 uint32_t rx_packets;
119 uint32_t tx_packets;
120 uint64_t rx_drop_misc;
121 struct iwinfo_rate_entry rx_rate;
122 struct iwinfo_rate_entry tx_rate;
123 uint32_t rx_bytes;
124 uint32_t tx_bytes;
125 uint32_t tx_retries;
126 uint32_t tx_failed;
127 uint64_t t_offset;
128 uint8_t is_authorized:1;
129 uint8_t is_authenticated:1;
130 uint8_t is_preamble_short:1;
131 uint8_t is_wme:1;
132 uint8_t is_mfp:1;
133 uint8_t is_tdls:1;
134 uint32_t thr;
135 uint16_t llid;
136 uint16_t plid;
137 char plink_state[16];
138 char local_ps[16];
139 char peer_ps[16];
140 char nonpeer_ps[16];
141 };
142
143 struct iwinfo_survey_entry {
144 uint64_t active_time;
145 uint64_t busy_time;
146 uint64_t busy_time_ext;
147 uint64_t rxtime;
148 uint64_t txtime;
149 uint32_t mhz;
150 uint8_t noise;
151 };
152
153 struct iwinfo_txpwrlist_entry {
154 uint8_t dbm;
155 uint16_t mw;
156 };
157
158 struct iwinfo_freqlist_entry {
159 uint8_t channel;
160 uint32_t mhz;
161 uint8_t restricted;
162 uint32_t flags;
163 };
164
165 struct iwinfo_crypto_entry {
166 uint8_t enabled;
167 uint8_t wpa_version;
168 uint16_t group_ciphers;
169 uint16_t pair_ciphers;
170 uint8_t auth_suites;
171 uint8_t auth_algs;
172 };
173
174 struct iwinfo_scanlist_ht_chan_entry {
175 uint8_t primary_chan;
176 uint8_t secondary_chan_off;
177 uint8_t chan_width;
178 };
179
180 struct iwinfo_scanlist_vht_chan_entry {
181 uint8_t chan_width;
182 uint8_t center_chan_1;
183 uint8_t center_chan_2;
184 };
185
186 static const char *ht_secondary_offset[4] = {
187 "no secondary",
188 "above",
189 "[reserved!]",
190 "below",
191 };
192
193
194 static uint16_t ht_chan_width[2] = {
195 20, /* 20 MHz */
196 2040, /* 40 MHz or higher (refer to vht if supported) */
197 };
198
199 static uint16_t vht_chan_width[] = {
200 [0] = 40, /* 40 MHz or lower (refer to ht to a more precise width) */
201 [1] = 80, /* 80 MHz */
202 [3] = 8080, /* 80+80 MHz */
203 [2] = 160, /* 160 MHz */
204 };
205
206 struct iwinfo_scanlist_entry {
207 uint8_t mac[6];
208 char ssid[IWINFO_ESSID_MAX_SIZE+1];
209 enum iwinfo_opmode mode;
210 uint8_t channel;
211 uint8_t signal;
212 uint8_t quality;
213 uint8_t quality_max;
214 struct iwinfo_crypto_entry crypto;
215 struct iwinfo_scanlist_ht_chan_entry ht_chan_info;
216 struct iwinfo_scanlist_vht_chan_entry vht_chan_info;
217 };
218
219 struct iwinfo_country_entry {
220 uint16_t iso3166;
221 char ccode[4];
222 };
223
224 struct iwinfo_iso3166_label {
225 uint16_t iso3166;
226 char name[28];
227 };
228
229 struct iwinfo_hardware_id {
230 uint16_t vendor_id;
231 uint16_t device_id;
232 uint16_t subsystem_vendor_id;
233 uint16_t subsystem_device_id;
234 };
235
236 struct iwinfo_hardware_entry {
237 char vendor_name[64];
238 char device_name[64];
239 uint16_t vendor_id;
240 uint16_t device_id;
241 uint16_t subsystem_vendor_id;
242 uint16_t subsystem_device_id;
243 int16_t txpower_offset;
244 int16_t frequency_offset;
245 };
246
247 extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[];
248
249 #define IWINFO_HARDWARE_FILE "/usr/share/libiwinfo/hardware.txt"
250
251
252 struct iwinfo_ops {
253 const char *name;
254
255 int (*probe)(const char *ifname);
256 int (*mode)(const char *, int *);
257 int (*channel)(const char *, int *);
258 int (*frequency)(const char *, int *);
259 int (*frequency_offset)(const char *, int *);
260 int (*txpower)(const char *, int *);
261 int (*txpower_offset)(const char *, int *);
262 int (*bitrate)(const char *, int *);
263 int (*signal)(const char *, int *);
264 int (*noise)(const char *, int *);
265 int (*quality)(const char *, int *);
266 int (*quality_max)(const char *, int *);
267 int (*mbssid_support)(const char *, int *);
268 int (*hwmodelist)(const char *, int *);
269 int (*htmodelist)(const char *, int *);
270 int (*htmode)(const char *, int *);
271 int (*ssid)(const char *, char *);
272 int (*bssid)(const char *, char *);
273 int (*country)(const char *, char *);
274 int (*hardware_id)(const char *, char *);
275 int (*hardware_name)(const char *, char *);
276 int (*encryption)(const char *, char *);
277 int (*phyname)(const char *, char *);
278 int (*assoclist)(const char *, char *, int *);
279 int (*txpwrlist)(const char *, char *, int *);
280 int (*scanlist)(const char *, char *, int *);
281 int (*freqlist)(const char *, char *, int *);
282 int (*countrylist)(const char *, char *, int *);
283 int (*survey)(const char *, char *, int *);
284 int (*lookup_phy)(const char *, char *);
285 void (*close)(void);
286 int (*center_chan1)(const char *, int *);
287 int (*center_chan2)(const char *, int *);
288 };
289
290 const char * iwinfo_type(const char *ifname);
291 const struct iwinfo_ops * iwinfo_backend(const char *ifname);
292 const struct iwinfo_ops * iwinfo_backend_by_name(const char *name);
293 void iwinfo_finish(void);
294
295 extern const struct iwinfo_ops wext_ops;
296 extern const struct iwinfo_ops madwifi_ops;
297 extern const struct iwinfo_ops nl80211_ops;
298 extern const struct iwinfo_ops wl_ops;
299
300 #include "iwinfo/utils.h"
301
302 #endif