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