02ad623ac1d86b5c4eccff63b74b6a97ea667d3e
[oweals/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
32 #define IWINFO_CIPHER_NONE   (1 << 0)
33 #define IWINFO_CIPHER_WEP40  (1 << 1)
34 #define IWINFO_CIPHER_TKIP   (1 << 2)
35 #define IWINFO_CIPHER_WRAP   (1 << 3)
36 #define IWINFO_CIPHER_CCMP   (1 << 4)
37 #define IWINFO_CIPHER_WEP104 (1 << 5)
38 #define IWINFO_CIPHER_AESOCB (1 << 6)
39 #define IWINFO_CIPHER_CKIP   (1 << 7)
40 #define IWINFO_CIPHER_COUNT  8
41
42 #define IWINFO_KMGMT_NONE    (1 << 0)
43 #define IWINFO_KMGMT_8021x   (1 << 1)
44 #define IWINFO_KMGMT_PSK     (1 << 2)
45 #define IWINFO_KMGMT_COUNT   3
46
47 #define IWINFO_AUTH_OPEN     (1 << 0)
48 #define IWINFO_AUTH_SHARED   (1 << 1)
49 #define IWINFO_AUTH_COUNT    2
50
51 #define IWINFO_FREQ_NO_10MHZ            (1 << 0)
52 #define IWINFO_FREQ_NO_20MHZ            (1 << 1)
53 #define IWINFO_FREQ_NO_HT40PLUS         (1 << 2)
54 #define IWINFO_FREQ_NO_HT40MINUS        (1 << 3)
55 #define IWINFO_FREQ_NO_80MHZ            (1 << 4)
56 #define IWINFO_FREQ_NO_160MHZ           (1 << 5)
57
58 extern const char *IWINFO_CIPHER_NAMES[IWINFO_CIPHER_COUNT];
59 extern const char *IWINFO_KMGMT_NAMES[IWINFO_KMGMT_COUNT];
60 extern const char *IWINFO_AUTH_NAMES[IWINFO_AUTH_COUNT];
61
62
63 enum iwinfo_opmode {
64         IWINFO_OPMODE_UNKNOWN    = 0,
65         IWINFO_OPMODE_MASTER     = 1,
66         IWINFO_OPMODE_ADHOC      = 2,
67         IWINFO_OPMODE_CLIENT     = 3,
68         IWINFO_OPMODE_MONITOR    = 4,
69         IWINFO_OPMODE_AP_VLAN    = 5,
70         IWINFO_OPMODE_WDS        = 6,
71         IWINFO_OPMODE_MESHPOINT  = 7,
72         IWINFO_OPMODE_P2P_CLIENT = 8,
73         IWINFO_OPMODE_P2P_GO     = 9,
74 };
75
76 extern const char *IWINFO_OPMODE_NAMES[];
77
78
79 enum iwinfo_htmode {
80         IWINFO_HTMODE_HT20       = (1 << 0),
81         IWINFO_HTMODE_HT40       = (1 << 1),
82         IWINFO_HTMODE_VHT20      = (1 << 2),
83         IWINFO_HTMODE_VHT40      = (1 << 3),
84         IWINFO_HTMODE_VHT80      = (1 << 4),
85         IWINFO_HTMODE_VHT80_80   = (1 << 5),
86         IWINFO_HTMODE_VHT160     = (1 << 6),
87
88         IWINFO_HTMODE_COUNT      = 7
89 };
90
91 extern const char *IWINFO_HTMODE_NAMES[IWINFO_HTMODE_COUNT];
92
93
94 struct iwinfo_rate_entry {
95         uint32_t rate;
96         int8_t mcs;
97         uint8_t is_40mhz:1;
98         uint8_t is_short_gi:1;
99         uint8_t is_ht:1;
100         uint8_t is_vht:1;
101         uint8_t mhz;
102         uint8_t nss;
103 };
104
105 struct iwinfo_assoclist_entry {
106         uint8_t mac[6];
107         int8_t signal;
108         int8_t signal_avg;
109         int8_t noise;
110         uint32_t inactive;
111         uint32_t connected_time;
112         uint32_t rx_packets;
113         uint32_t tx_packets;
114         uint64_t rx_drop_misc;
115         struct iwinfo_rate_entry rx_rate;
116         struct iwinfo_rate_entry tx_rate;
117         uint32_t rx_bytes;
118         uint32_t tx_bytes;
119         uint32_t tx_retries;
120         uint32_t tx_failed;
121         uint64_t t_offset;
122         uint8_t is_authorized:1;
123         uint8_t is_authenticated:1;
124         uint8_t is_preamble_short:1;
125         uint8_t is_wme:1;
126         uint8_t is_mfp:1;
127         uint8_t is_tdls:1;
128         uint32_t thr;
129         uint16_t llid;
130         uint16_t plid;
131         char plink_state[16];
132         char local_ps[16];
133         char peer_ps[16];
134         char nonpeer_ps[16];
135 };
136
137 struct iwinfo_survey_entry {
138         uint64_t active_time;
139         uint64_t busy_time;
140         uint64_t busy_time_ext;
141         uint64_t rxtime;
142         uint64_t txtime;
143         uint32_t mhz;
144         uint8_t noise;
145 };
146
147 struct iwinfo_txpwrlist_entry {
148         uint8_t  dbm;
149         uint16_t mw;
150 };
151
152 struct iwinfo_freqlist_entry {
153         uint8_t channel;
154         uint32_t mhz;
155         uint8_t restricted;
156         uint32_t flags;
157 };
158
159 struct iwinfo_crypto_entry {
160         uint8_t enabled;
161         uint8_t wpa_version;
162         uint8_t group_ciphers;
163         uint8_t pair_ciphers;
164         uint8_t auth_suites;
165         uint8_t auth_algs;
166 };
167
168 struct iwinfo_scanlist_entry {
169         uint8_t mac[6];
170         char ssid[IWINFO_ESSID_MAX_SIZE+1];
171         enum iwinfo_opmode mode;
172         uint8_t channel;
173         uint8_t signal;
174         uint8_t quality;
175         uint8_t quality_max;
176         struct iwinfo_crypto_entry crypto;
177 };
178
179 struct iwinfo_country_entry {
180         uint16_t iso3166;
181         char ccode[4];
182 };
183
184 struct iwinfo_iso3166_label {
185         uint16_t iso3166;
186         char name[28];
187 };
188
189 struct iwinfo_hardware_id {
190         uint16_t vendor_id;
191         uint16_t device_id;
192         uint16_t subsystem_vendor_id;
193         uint16_t subsystem_device_id;
194 };
195
196 struct iwinfo_hardware_entry {
197         char vendor_name[64];
198         char device_name[64];
199         uint16_t vendor_id;
200         uint16_t device_id;
201         uint16_t subsystem_vendor_id;
202         uint16_t subsystem_device_id;
203         int16_t txpower_offset;
204         int16_t frequency_offset;
205 };
206
207 extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[];
208
209 #define IWINFO_HARDWARE_FILE    "/usr/share/libiwinfo/hardware.txt"
210
211
212 struct iwinfo_ops {
213         const char *name;
214
215         int (*probe)(const char *ifname);
216         int (*mode)(const char *, int *);
217         int (*channel)(const char *, int *);
218         int (*frequency)(const char *, int *);
219         int (*frequency_offset)(const char *, int *);
220         int (*txpower)(const char *, int *);
221         int (*txpower_offset)(const char *, int *);
222         int (*bitrate)(const char *, int *);
223         int (*signal)(const char *, int *);
224         int (*noise)(const char *, int *);
225         int (*quality)(const char *, int *);
226         int (*quality_max)(const char *, int *);
227         int (*mbssid_support)(const char *, int *);
228         int (*hwmodelist)(const char *, int *);
229         int (*htmodelist)(const char *, int *);
230         int (*ssid)(const char *, char *);
231         int (*bssid)(const char *, char *);
232         int (*country)(const char *, char *);
233         int (*hardware_id)(const char *, char *);
234         int (*hardware_name)(const char *, char *);
235         int (*encryption)(const char *, char *);
236         int (*phyname)(const char *, char *);
237         int (*assoclist)(const char *, char *, int *);
238         int (*txpwrlist)(const char *, char *, int *);
239         int (*scanlist)(const char *, char *, int *);
240         int (*freqlist)(const char *, char *, int *);
241         int (*countrylist)(const char *, char *, int *);
242         int (*survey)(const char *, char *, int *);
243         int (*lookup_phy)(const char *, char *);
244         void (*close)(void);
245 };
246
247 const char * iwinfo_type(const char *ifname);
248 const struct iwinfo_ops * iwinfo_backend(const char *ifname);
249 const struct iwinfo_ops * iwinfo_backend_by_name(const char *name);
250 void iwinfo_finish(void);
251
252 extern const struct iwinfo_ops wext_ops;
253 extern const struct iwinfo_ops madwifi_ops;
254 extern const struct iwinfo_ops nl80211_ops;
255 extern const struct iwinfo_ops wl_ops;
256
257 #include "iwinfo/utils.h"
258
259 #endif