iwinfo.h 7.5 KB

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