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