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