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