iwinfo.h 10 KB

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