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