iwinfo: reorganize iwinfo header to enum and defines
[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 enum iwinfo_80211 {
27 IWINFO_80211_A = 0,
28 IWINFO_80211_B,
29 IWINFO_80211_G,
30 IWINFO_80211_N,
31 IWINFO_80211_AC,
32 IWINFO_80211_AD,
33 IWINFO_80211_AX,
34
35 /* keep last */
36 IWINFO_80211_COUNT
37 };
38
39 #define IWINFO_80211_A (1 << IWINFO_80211_A)
40 #define IWINFO_80211_B (1 << IWINFO_80211_B)
41 #define IWINFO_80211_G (1 << IWINFO_80211_G)
42 #define IWINFO_80211_N (1 << IWINFO_80211_N)
43 #define IWINFO_80211_AC (1 << IWINFO_80211_AC)
44 #define IWINFO_80211_AD (1 << IWINFO_80211_AD)
45 #define IWINFO_80211_AX (1 << IWINFO_80211_AX)
46
47 extern const char * const IWINFO_80211_NAMES[IWINFO_80211_COUNT];
48
49
50 enum iwinfo_band {
51 IWINFO_BAND_24 = 0,
52 IWINFO_BAND_5,
53 IWINFO_BAND_6,
54 IWINFO_BAND_60,
55
56 /* keep last */
57 IWINFO_BAND_COUNT
58 };
59
60 #define IWINFO_BAND_24 (1 << IWINFO_BAND_24)
61 #define IWINFO_BAND_5 (1 << IWINFO_BAND_5)
62 #define IWINFO_BAND_6 (1 << IWINFO_BAND_6)
63 #define IWINFO_BAND_60 (1 << IWINFO_BAND_60)
64
65 extern const char * const IWINFO_BAND_NAMES[IWINFO_BAND_COUNT];
66
67
68 enum iwinfo_cipher {
69 IWINFO_CIPHER_NONE = 0,
70 IWINFO_CIPHER_WEP40,
71 IWINFO_CIPHER_TKIP,
72 IWINFO_CIPHER_WRAP,
73 IWINFO_CIPHER_CCMP,
74 IWINFO_CIPHER_WEP104,
75 IWINFO_CIPHER_AESOCB,
76 IWINFO_CIPHER_CKIP,
77 IWINFO_CIPHER_GCMP,
78 IWINFO_CIPHER_CCMP256,
79 IWINFO_CIPHER_GCMP256,
80
81 /* keep last */
82 IWINFO_CIPHER_COUNT
83 };
84
85 #define IWINFO_CIPHER_NONE (1 << IWINFO_CIPHER_NONE)
86 #define IWINFO_CIPHER_WEP40 (1 << IWINFO_CIPHER_WEP40)
87 #define IWINFO_CIPHER_TKIP (1 << IWINFO_CIPHER_TKIP)
88 #define IWINFO_CIPHER_WRAP (1 << IWINFO_CIPHER_WRAP)
89 #define IWINFO_CIPHER_CCMP (1 << IWINFO_CIPHER_CCMP)
90 #define IWINFO_CIPHER_WEP104 (1 << IWINFO_CIPHER_WEP104)
91 #define IWINFO_CIPHER_AESOCB (1 << IWINFO_CIPHER_AESOCB)
92 #define IWINFO_CIPHER_CKIP (1 << IWINFO_CIPHER_CKIP)
93 #define IWINFO_CIPHER_GCMP (1 << IWINFO_CIPHER_GCMP)
94 #define IWINFO_CIPHER_CCMP256 (1 << IWINFO_CIPHER_CCMP256)
95 #define IWINFO_CIPHER_GCMP256 (1 << IWINFO_CIPHER_GCMP256)
96
97 extern const char * const IWINFO_CIPHER_NAMES[IWINFO_CIPHER_COUNT];
98
99
100 enum iwinfo_kmgmt {
101 IWINFO_KMGMT_NONE = 0,
102 IWINFO_KMGMT_8021x,
103 IWINFO_KMGMT_PSK,
104 IWINFO_KMGMT_SAE,
105 IWINFO_KMGMT_OWE,
106
107 /* keep last */
108 IWINFO_KMGMT_COUNT
109 };
110
111 #define IWINFO_KMGMT_NONE (1 << IWINFO_KMGMT_NONE)
112 #define IWINFO_KMGMT_8021x (1 << IWINFO_KMGMT_8021x)
113 #define IWINFO_KMGMT_PSK (1 << IWINFO_KMGMT_PSK)
114 #define IWINFO_KMGMT_SAE (1 << IWINFO_KMGMT_SAE)
115 #define IWINFO_KMGMT_OWE (1 << IWINFO_KMGMT_OWE)
116
117 extern const char * const IWINFO_KMGMT_NAMES[IWINFO_KMGMT_COUNT];
118
119
120 enum iwinfo_auth {
121 IWINFO_AUTH_OPEN = 0,
122 IWINFO_AUTH_SHARED,
123
124 /* keep last */
125 IWINFO_AUTH_COUNT
126 };
127
128 extern const char * const IWINFO_AUTH_NAMES[IWINFO_AUTH_COUNT];
129
130
131 enum iwinfo_freq_flag {
132 IWINFO_FREQ_NO_10MHZ = 0,
133 IWINFO_FREQ_NO_20MHZ,
134 IWINFO_FREQ_NO_HT40PLUS,
135 IWINFO_FREQ_NO_HT40MINUS,
136 IWINFO_FREQ_NO_80MHZ,
137 IWINFO_FREQ_NO_160MHZ,
138 IWINFO_FREQ_NO_HE,
139
140 /* keep last */
141 IWINFO_FREQ_FLAG_COUNT,
142 };
143
144 #define IWINFO_FREQ_NO_10MHZ (1 << IWINFO_FREQ_NO_10MHZ)
145 #define IWINFO_FREQ_NO_20MHZ (1 << IWINFO_FREQ_NO_20MHZ)
146 #define IWINFO_FREQ_NO_HT40PLUS (1 << IWINFO_FREQ_NO_HT40PLUS)
147 #define IWINFO_FREQ_NO_HT40MINUS (1 << IWINFO_FREQ_NO_HT40MINUS)
148 #define IWINFO_FREQ_NO_80MHZ (1 << IWINFO_FREQ_NO_80MHZ)
149 #define IWINFO_FREQ_NO_160MHZ (1 << IWINFO_FREQ_NO_160MHZ)
150 #define IWINFO_FREQ_NO_HE (1 << IWINFO_FREQ_NO_HE)
151
152
153 enum iwinfo_opmode {
154 IWINFO_OPMODE_UNKNOWN = 0,
155 IWINFO_OPMODE_MASTER,
156 IWINFO_OPMODE_ADHOC,
157 IWINFO_OPMODE_CLIENT,
158 IWINFO_OPMODE_MONITOR,
159 IWINFO_OPMODE_AP_VLAN,
160 IWINFO_OPMODE_WDS,
161 IWINFO_OPMODE_MESHPOINT,
162 IWINFO_OPMODE_P2P_CLIENT,
163 IWINFO_OPMODE_P2P_GO,
164
165 /* keep last */
166 IWINFO_OPMODE_COUNT
167 };
168
169 extern const char * const IWINFO_OPMODE_NAMES[IWINFO_OPMODE_COUNT];
170
171
172 enum iwinfo_htmode {
173 IWINFO_HTMODE_HT20 = 0,
174 IWINFO_HTMODE_HT40,
175 IWINFO_HTMODE_VHT20,
176 IWINFO_HTMODE_VHT40,
177 IWINFO_HTMODE_VHT80,
178 IWINFO_HTMODE_VHT80_80,
179 IWINFO_HTMODE_VHT160,
180 IWINFO_HTMODE_NOHT,
181 IWINFO_HTMODE_HE20,
182 IWINFO_HTMODE_HE40,
183 IWINFO_HTMODE_HE80,
184 IWINFO_HTMODE_HE80_80,
185 IWINFO_HTMODE_HE160,
186
187 /* keep last */
188 IWINFO_HTMODE_COUNT
189 };
190
191 #define IWINFO_HTMODE_HT20 (1 << IWINFO_HTMODE_HT20)
192 #define IWINFO_HTMODE_HT40 (1 << IWINFO_HTMODE_HT40)
193 #define IWINFO_HTMODE_VHT20 (1 << IWINFO_HTMODE_VHT20)
194 #define IWINFO_HTMODE_VHT40 (1 << IWINFO_HTMODE_VHT40)
195 #define IWINFO_HTMODE_VHT80 (1 << IWINFO_HTMODE_VHT80)
196 #define IWINFO_HTMODE_VHT80_80 (1 << IWINFO_HTMODE_VHT80_80)
197 #define IWINFO_HTMODE_VHT160 (1 << IWINFO_HTMODE_VHT160)
198 #define IWINFO_HTMODE_NOHT (1 << IWINFO_HTMODE_NOHT)
199 #define IWINFO_HTMODE_HE20 (1 << IWINFO_HTMODE_HE20)
200 #define IWINFO_HTMODE_HE40 (1 << IWINFO_HTMODE_HE40)
201 #define IWINFO_HTMODE_HE80 (1 << IWINFO_HTMODE_HE80)
202 #define IWINFO_HTMODE_HE80_80 (1 << IWINFO_HTMODE_HE80_80)
203 #define IWINFO_HTMODE_HE160 (1 << IWINFO_HTMODE_HE160)
204
205 extern const char * const IWINFO_HTMODE_NAMES[IWINFO_HTMODE_COUNT];
206
207
208 struct iwinfo_rate_entry {
209 uint32_t rate;
210 int8_t mcs;
211 uint8_t is_40mhz:1;
212 uint8_t is_short_gi:1;
213 uint8_t is_ht:1;
214 uint8_t is_vht:1;
215 uint8_t is_he:1;
216 uint8_t he_gi;
217 uint8_t he_dcm;
218 uint8_t mhz;
219 uint8_t nss;
220 };
221
222 struct iwinfo_assoclist_entry {
223 uint8_t mac[6];
224 int8_t signal;
225 int8_t signal_avg;
226 int8_t noise;
227 uint32_t inactive;
228 uint32_t connected_time;
229 uint32_t rx_packets;
230 uint32_t tx_packets;
231 uint64_t rx_drop_misc;
232 struct iwinfo_rate_entry rx_rate;
233 struct iwinfo_rate_entry tx_rate;
234 uint32_t rx_bytes;
235 uint32_t tx_bytes;
236 uint32_t tx_retries;
237 uint32_t tx_failed;
238 uint64_t t_offset;
239 uint8_t is_authorized:1;
240 uint8_t is_authenticated:1;
241 uint8_t is_preamble_short:1;
242 uint8_t is_wme:1;
243 uint8_t is_mfp:1;
244 uint8_t is_tdls:1;
245 uint32_t thr;
246 uint16_t llid;
247 uint16_t plid;
248 char plink_state[16];
249 char local_ps[16];
250 char peer_ps[16];
251 char nonpeer_ps[16];
252 };
253
254 struct iwinfo_survey_entry {
255 uint64_t active_time;
256 uint64_t busy_time;
257 uint64_t busy_time_ext;
258 uint64_t rxtime;
259 uint64_t txtime;
260 uint32_t mhz;
261 uint8_t noise;
262 };
263
264 struct iwinfo_txpwrlist_entry {
265 uint8_t dbm;
266 uint16_t mw;
267 };
268
269 struct iwinfo_freqlist_entry {
270 uint8_t channel;
271 uint32_t mhz;
272 uint8_t restricted;
273 uint32_t flags;
274 };
275
276 struct iwinfo_crypto_entry {
277 uint8_t enabled;
278 uint8_t wpa_version;
279 uint16_t group_ciphers;
280 uint16_t pair_ciphers;
281 uint8_t auth_suites;
282 uint8_t auth_algs;
283 };
284
285 struct iwinfo_scanlist_ht_chan_entry {
286 uint8_t primary_chan;
287 uint8_t secondary_chan_off;
288 uint8_t chan_width;
289 };
290
291 struct iwinfo_scanlist_vht_chan_entry {
292 uint8_t chan_width;
293 uint8_t center_chan_1;
294 uint8_t center_chan_2;
295 };
296
297 extern const char * const ht_secondary_offset[4];
298 /* 0 = 20 MHz
299 1 = 40 MHz or higher (refer to vht if supported) */
300 extern const uint16_t ht_chan_width[2];
301 /* 0 = 40 MHz or lower (refer to ht to a more precise width)
302 1 = 80 MHz
303 2 = 160 MHz
304 3 = 80+80 MHz */
305 extern const uint16_t vht_chan_width[4];
306
307 struct iwinfo_scanlist_entry {
308 uint8_t mac[6];
309 char ssid[IWINFO_ESSID_MAX_SIZE+1];
310 enum iwinfo_opmode mode;
311 uint8_t channel;
312 uint8_t signal;
313 uint8_t quality;
314 uint8_t quality_max;
315 struct iwinfo_crypto_entry crypto;
316 struct iwinfo_scanlist_ht_chan_entry ht_chan_info;
317 struct iwinfo_scanlist_vht_chan_entry vht_chan_info;
318 };
319
320 struct iwinfo_country_entry {
321 uint16_t iso3166;
322 char ccode[4];
323 };
324
325 struct iwinfo_iso3166_label {
326 uint16_t iso3166;
327 const char name[28];
328 };
329
330 struct iwinfo_hardware_id {
331 uint16_t vendor_id;
332 uint16_t device_id;
333 uint16_t subsystem_vendor_id;
334 uint16_t subsystem_device_id;
335 char compatible[128];
336 };
337
338 struct iwinfo_hardware_entry {
339 char vendor_name[64];
340 char device_name[64];
341 uint16_t vendor_id;
342 uint16_t device_id;
343 uint16_t subsystem_vendor_id;
344 uint16_t subsystem_device_id;
345 int16_t txpower_offset;
346 int16_t frequency_offset;
347 char compatible[128];
348 };
349
350 extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[];
351
352 #define IWINFO_HARDWARE_FILE "/usr/share/libiwinfo/devices.txt"
353
354
355 struct iwinfo_ops {
356 const char *name;
357
358 int (*probe)(const char *ifname);
359 int (*mode)(const char *, int *);
360 int (*channel)(const char *, int *);
361 int (*center_chan1)(const char *, int *);
362 int (*center_chan2)(const char *, int *);
363 int (*frequency)(const char *, int *);
364 int (*frequency_offset)(const char *, int *);
365 int (*txpower)(const char *, int *);
366 int (*txpower_offset)(const char *, int *);
367 int (*bitrate)(const char *, int *);
368 int (*signal)(const char *, int *);
369 int (*noise)(const char *, int *);
370 int (*quality)(const char *, int *);
371 int (*quality_max)(const char *, int *);
372 int (*mbssid_support)(const char *, int *);
373 int (*hwmodelist)(const char *, int *);
374 int (*htmodelist)(const char *, int *);
375 int (*htmode)(const char *, int *);
376 int (*ssid)(const char *, char *);
377 int (*bssid)(const char *, char *);
378 int (*country)(const char *, char *);
379 int (*hardware_id)(const char *, char *);
380 int (*hardware_name)(const char *, char *);
381 int (*encryption)(const char *, char *);
382 int (*phyname)(const char *, char *);
383 int (*assoclist)(const char *, char *, int *);
384 int (*txpwrlist)(const char *, char *, int *);
385 int (*scanlist)(const char *, char *, int *);
386 int (*freqlist)(const char *, char *, int *);
387 int (*countrylist)(const char *, char *, int *);
388 int (*survey)(const char *, char *, int *);
389 int (*lookup_phy)(const char *, char *);
390 int (*phy_path)(const char *phyname, const char **path);
391 void (*close)(void);
392 };
393
394 const char * iwinfo_type(const char *ifname);
395 const struct iwinfo_ops * iwinfo_backend(const char *ifname);
396 const struct iwinfo_ops * iwinfo_backend_by_name(const char *name);
397 void iwinfo_finish(void);
398
399 extern const struct iwinfo_ops wext_ops;
400 extern const struct iwinfo_ops madwifi_ops;
401 extern const struct iwinfo_ops nl80211_ops;
402 extern const struct iwinfo_ops wl_ops;
403
404 #include "iwinfo/utils.h"
405
406 #endif