Mirror of the official iwinfo project repository by OpenWrt https://git.openwrt.org/project/iwinfo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

383 lines
11 KiB

  1. /*
  2. * iwinfo - Wireless Information Library - Linux Wireless Extension Headers
  3. *
  4. * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
  5. *
  6. * The iwinfo library is free software: you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version 2
  8. * as published by the Free Software Foundation.
  9. *
  10. * The iwinfo library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
  17. */
  18. #ifndef __IWINFO_WEXT_SCAN_H_
  19. #define __IWINFO_WEXT_SCAN_H_
  20. #include <fcntl.h>
  21. #include "iwinfo.h"
  22. #include "iwinfo/utils.h"
  23. #include "api/wext.h"
  24. typedef struct stream_descr
  25. {
  26. char * end; /* End of the stream */
  27. char * current; /* Current event in stream of events */
  28. char * value; /* Current value in event */
  29. } stream_descr;
  30. /*
  31. * Describe how a standard IOCTL looks like.
  32. */
  33. struct iw_ioctl_description
  34. {
  35. uint8_t header_type; /* NULL, iw_point or other */
  36. uint8_t token_type; /* Future */
  37. uint16_t token_size; /* Granularity of payload */
  38. uint16_t min_tokens; /* Min acceptable token number */
  39. uint16_t max_tokens; /* Max acceptable token number */
  40. uint32_t flags; /* Special handling of the request */
  41. };
  42. /* Type of headers we know about (basically union iwreq_data) */
  43. #define IW_HEADER_TYPE_NULL 0 /* Not available */
  44. #define IW_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */
  45. #define IW_HEADER_TYPE_UINT 4 /* __u32 */
  46. #define IW_HEADER_TYPE_FREQ 5 /* struct iw_freq */
  47. #define IW_HEADER_TYPE_ADDR 6 /* struct sockaddr */
  48. #define IW_HEADER_TYPE_POINT 8 /* struct iw_point */
  49. #define IW_HEADER_TYPE_PARAM 9 /* struct iw_param */
  50. #define IW_HEADER_TYPE_QUAL 10 /* struct iw_quality */
  51. /* Handling flags */
  52. /* Most are not implemented. I just use them as a reminder of some
  53. * cool features we might need one day ;-) */
  54. #define IW_DESCR_FLAG_NONE 0x0000 /* Obvious */
  55. /* Wrapper level flags */
  56. #define IW_DESCR_FLAG_DUMP 0x0001 /* Not part of the dump command */
  57. #define IW_DESCR_FLAG_EVENT 0x0002 /* Generate an event on SET */
  58. #define IW_DESCR_FLAG_RESTRICT 0x0004 /* GET : request is ROOT only */
  59. /* SET : Omit payload from generated iwevent */
  60. #define IW_DESCR_FLAG_NOMAX 0x0008 /* GET : no limit on request size */
  61. /* Driver level flags */
  62. #define IW_DESCR_FLAG_WAIT 0x0100 /* Wait for driver event */
  63. /*
  64. * Meta-data about all the standard Wireless Extension request we
  65. * know about.
  66. */
  67. static const struct iw_ioctl_description standard_ioctl_descr[] = {
  68. [SIOCSIWCOMMIT - SIOCIWFIRST] = {
  69. .header_type = IW_HEADER_TYPE_NULL,
  70. },
  71. [SIOCGIWNAME - SIOCIWFIRST] = {
  72. .header_type = IW_HEADER_TYPE_CHAR,
  73. .flags = IW_DESCR_FLAG_DUMP,
  74. },
  75. [SIOCSIWNWID - SIOCIWFIRST] = {
  76. .header_type = IW_HEADER_TYPE_PARAM,
  77. .flags = IW_DESCR_FLAG_EVENT,
  78. },
  79. [SIOCGIWNWID - SIOCIWFIRST] = {
  80. .header_type = IW_HEADER_TYPE_PARAM,
  81. .flags = IW_DESCR_FLAG_DUMP,
  82. },
  83. [SIOCSIWFREQ - SIOCIWFIRST] = {
  84. .header_type = IW_HEADER_TYPE_FREQ,
  85. .flags = IW_DESCR_FLAG_EVENT,
  86. },
  87. [SIOCGIWFREQ - SIOCIWFIRST] = {
  88. .header_type = IW_HEADER_TYPE_FREQ,
  89. .flags = IW_DESCR_FLAG_DUMP,
  90. },
  91. [SIOCSIWMODE - SIOCIWFIRST] = {
  92. .header_type = IW_HEADER_TYPE_UINT,
  93. .flags = IW_DESCR_FLAG_EVENT,
  94. },
  95. [SIOCGIWMODE - SIOCIWFIRST] = {
  96. .header_type = IW_HEADER_TYPE_UINT,
  97. .flags = IW_DESCR_FLAG_DUMP,
  98. },
  99. [SIOCSIWSENS - SIOCIWFIRST] = {
  100. .header_type = IW_HEADER_TYPE_PARAM,
  101. },
  102. [SIOCGIWSENS - SIOCIWFIRST] = {
  103. .header_type = IW_HEADER_TYPE_PARAM,
  104. },
  105. [SIOCSIWRANGE - SIOCIWFIRST] = {
  106. .header_type = IW_HEADER_TYPE_NULL,
  107. },
  108. [SIOCGIWRANGE - SIOCIWFIRST] = {
  109. .header_type = IW_HEADER_TYPE_POINT,
  110. .token_size = 1,
  111. .max_tokens = sizeof(struct iw_range),
  112. .flags = IW_DESCR_FLAG_DUMP,
  113. },
  114. [SIOCSIWPRIV - SIOCIWFIRST] = {
  115. .header_type = IW_HEADER_TYPE_NULL,
  116. },
  117. [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
  118. .header_type = IW_HEADER_TYPE_NULL,
  119. },
  120. [SIOCSIWSTATS - SIOCIWFIRST] = {
  121. .header_type = IW_HEADER_TYPE_NULL,
  122. },
  123. [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
  124. .header_type = IW_HEADER_TYPE_NULL,
  125. .flags = IW_DESCR_FLAG_DUMP,
  126. },
  127. [SIOCSIWSPY - SIOCIWFIRST] = {
  128. .header_type = IW_HEADER_TYPE_POINT,
  129. .token_size = sizeof(struct sockaddr),
  130. .max_tokens = IW_MAX_SPY,
  131. },
  132. [SIOCGIWSPY - SIOCIWFIRST] = {
  133. .header_type = IW_HEADER_TYPE_POINT,
  134. .token_size = sizeof(struct sockaddr) +
  135. sizeof(struct iw_quality),
  136. .max_tokens = IW_MAX_SPY,
  137. },
  138. [SIOCSIWTHRSPY - SIOCIWFIRST] = {
  139. .header_type = IW_HEADER_TYPE_POINT,
  140. .token_size = sizeof(struct iw_thrspy),
  141. .min_tokens = 1,
  142. .max_tokens = 1,
  143. },
  144. [SIOCGIWTHRSPY - SIOCIWFIRST] = {
  145. .header_type = IW_HEADER_TYPE_POINT,
  146. .token_size = sizeof(struct iw_thrspy),
  147. .min_tokens = 1,
  148. .max_tokens = 1,
  149. },
  150. [SIOCSIWAP - SIOCIWFIRST] = {
  151. .header_type = IW_HEADER_TYPE_ADDR,
  152. },
  153. [SIOCGIWAP - SIOCIWFIRST] = {
  154. .header_type = IW_HEADER_TYPE_ADDR,
  155. .flags = IW_DESCR_FLAG_DUMP,
  156. },
  157. [SIOCSIWMLME - SIOCIWFIRST] = {
  158. .header_type = IW_HEADER_TYPE_POINT,
  159. .token_size = 1,
  160. .min_tokens = sizeof(struct iw_mlme),
  161. .max_tokens = sizeof(struct iw_mlme),
  162. },
  163. [SIOCGIWAPLIST - SIOCIWFIRST] = {
  164. .header_type = IW_HEADER_TYPE_POINT,
  165. .token_size = sizeof(struct sockaddr) +
  166. sizeof(struct iw_quality),
  167. .max_tokens = IW_MAX_AP,
  168. .flags = IW_DESCR_FLAG_NOMAX,
  169. },
  170. [SIOCSIWSCAN - SIOCIWFIRST] = {
  171. .header_type = IW_HEADER_TYPE_POINT,
  172. .token_size = 1,
  173. .min_tokens = 0,
  174. .max_tokens = sizeof(struct iw_scan_req),
  175. },
  176. [SIOCGIWSCAN - SIOCIWFIRST] = {
  177. .header_type = IW_HEADER_TYPE_POINT,
  178. .token_size = 1,
  179. .max_tokens = IW_SCAN_MAX_DATA,
  180. .flags = IW_DESCR_FLAG_NOMAX,
  181. },
  182. [SIOCSIWESSID - SIOCIWFIRST] = {
  183. .header_type = IW_HEADER_TYPE_POINT,
  184. .token_size = 1,
  185. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  186. .flags = IW_DESCR_FLAG_EVENT,
  187. },
  188. [SIOCGIWESSID - SIOCIWFIRST] = {
  189. .header_type = IW_HEADER_TYPE_POINT,
  190. .token_size = 1,
  191. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  192. .flags = IW_DESCR_FLAG_DUMP,
  193. },
  194. [SIOCSIWNICKN - SIOCIWFIRST] = {
  195. .header_type = IW_HEADER_TYPE_POINT,
  196. .token_size = 1,
  197. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  198. },
  199. [SIOCGIWNICKN - SIOCIWFIRST] = {
  200. .header_type = IW_HEADER_TYPE_POINT,
  201. .token_size = 1,
  202. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  203. },
  204. [SIOCSIWRATE - SIOCIWFIRST] = {
  205. .header_type = IW_HEADER_TYPE_PARAM,
  206. },
  207. [SIOCGIWRATE - SIOCIWFIRST] = {
  208. .header_type = IW_HEADER_TYPE_PARAM,
  209. },
  210. [SIOCSIWRTS - SIOCIWFIRST] = {
  211. .header_type = IW_HEADER_TYPE_PARAM,
  212. },
  213. [SIOCGIWRTS - SIOCIWFIRST] = {
  214. .header_type = IW_HEADER_TYPE_PARAM,
  215. },
  216. [SIOCSIWFRAG - SIOCIWFIRST] = {
  217. .header_type = IW_HEADER_TYPE_PARAM,
  218. },
  219. [SIOCGIWFRAG - SIOCIWFIRST] = {
  220. .header_type = IW_HEADER_TYPE_PARAM,
  221. },
  222. [SIOCSIWTXPOW - SIOCIWFIRST] = {
  223. .header_type = IW_HEADER_TYPE_PARAM,
  224. },
  225. [SIOCGIWTXPOW - SIOCIWFIRST] = {
  226. .header_type = IW_HEADER_TYPE_PARAM,
  227. },
  228. [SIOCSIWRETRY - SIOCIWFIRST] = {
  229. .header_type = IW_HEADER_TYPE_PARAM,
  230. },
  231. [SIOCGIWRETRY - SIOCIWFIRST] = {
  232. .header_type = IW_HEADER_TYPE_PARAM,
  233. },
  234. [SIOCSIWENCODE - SIOCIWFIRST] = {
  235. .header_type = IW_HEADER_TYPE_POINT,
  236. .token_size = 1,
  237. .max_tokens = IW_ENCODING_TOKEN_MAX,
  238. .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
  239. },
  240. [SIOCGIWENCODE - SIOCIWFIRST] = {
  241. .header_type = IW_HEADER_TYPE_POINT,
  242. .token_size = 1,
  243. .max_tokens = IW_ENCODING_TOKEN_MAX,
  244. .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
  245. },
  246. [SIOCSIWPOWER - SIOCIWFIRST] = {
  247. .header_type = IW_HEADER_TYPE_PARAM,
  248. },
  249. [SIOCGIWPOWER - SIOCIWFIRST] = {
  250. .header_type = IW_HEADER_TYPE_PARAM,
  251. },
  252. [SIOCSIWMODUL - SIOCIWFIRST] = {
  253. .header_type = IW_HEADER_TYPE_PARAM,
  254. },
  255. [SIOCGIWMODUL - SIOCIWFIRST] = {
  256. .header_type = IW_HEADER_TYPE_PARAM,
  257. },
  258. [SIOCSIWGENIE - SIOCIWFIRST] = {
  259. .header_type = IW_HEADER_TYPE_POINT,
  260. .token_size = 1,
  261. .max_tokens = IW_GENERIC_IE_MAX,
  262. },
  263. [SIOCGIWGENIE - SIOCIWFIRST] = {
  264. .header_type = IW_HEADER_TYPE_POINT,
  265. .token_size = 1,
  266. .max_tokens = IW_GENERIC_IE_MAX,
  267. },
  268. [SIOCSIWAUTH - SIOCIWFIRST] = {
  269. .header_type = IW_HEADER_TYPE_PARAM,
  270. },
  271. [SIOCGIWAUTH - SIOCIWFIRST] = {
  272. .header_type = IW_HEADER_TYPE_PARAM,
  273. },
  274. [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
  275. .header_type = IW_HEADER_TYPE_POINT,
  276. .token_size = 1,
  277. .min_tokens = sizeof(struct iw_encode_ext),
  278. .max_tokens = sizeof(struct iw_encode_ext) +
  279. IW_ENCODING_TOKEN_MAX,
  280. },
  281. [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
  282. .header_type = IW_HEADER_TYPE_POINT,
  283. .token_size = 1,
  284. .min_tokens = sizeof(struct iw_encode_ext),
  285. .max_tokens = sizeof(struct iw_encode_ext) +
  286. IW_ENCODING_TOKEN_MAX,
  287. },
  288. [SIOCSIWPMKSA - SIOCIWFIRST] = {
  289. .header_type = IW_HEADER_TYPE_POINT,
  290. .token_size = 1,
  291. .min_tokens = sizeof(struct iw_pmksa),
  292. .max_tokens = sizeof(struct iw_pmksa),
  293. },
  294. };
  295. /*
  296. * Meta-data about all the additional standard Wireless Extension events
  297. * we know about.
  298. */
  299. static const struct iw_ioctl_description standard_event_descr[] = {
  300. [IWEVTXDROP - IWEVFIRST] = {
  301. .header_type = IW_HEADER_TYPE_ADDR,
  302. },
  303. [IWEVQUAL - IWEVFIRST] = {
  304. .header_type = IW_HEADER_TYPE_QUAL,
  305. },
  306. [IWEVCUSTOM - IWEVFIRST] = {
  307. .header_type = IW_HEADER_TYPE_POINT,
  308. .token_size = 1,
  309. .max_tokens = IW_CUSTOM_MAX,
  310. },
  311. [IWEVREGISTERED - IWEVFIRST] = {
  312. .header_type = IW_HEADER_TYPE_ADDR,
  313. },
  314. [IWEVEXPIRED - IWEVFIRST] = {
  315. .header_type = IW_HEADER_TYPE_ADDR,
  316. },
  317. [IWEVGENIE - IWEVFIRST] = {
  318. .header_type = IW_HEADER_TYPE_POINT,
  319. .token_size = 1,
  320. .max_tokens = IW_GENERIC_IE_MAX,
  321. },
  322. [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
  323. .header_type = IW_HEADER_TYPE_POINT,
  324. .token_size = 1,
  325. .max_tokens = sizeof(struct iw_michaelmicfailure),
  326. },
  327. [IWEVASSOCREQIE - IWEVFIRST] = {
  328. .header_type = IW_HEADER_TYPE_POINT,
  329. .token_size = 1,
  330. .max_tokens = IW_GENERIC_IE_MAX,
  331. },
  332. [IWEVASSOCRESPIE - IWEVFIRST] = {
  333. .header_type = IW_HEADER_TYPE_POINT,
  334. .token_size = 1,
  335. .max_tokens = IW_GENERIC_IE_MAX,
  336. },
  337. [IWEVPMKIDCAND - IWEVFIRST] = {
  338. .header_type = IW_HEADER_TYPE_POINT,
  339. .token_size = 1,
  340. .max_tokens = sizeof(struct iw_pmkid_cand),
  341. },
  342. };
  343. /* Size (in bytes) of various events */
  344. static const int event_type_size[] = {
  345. IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */
  346. 0,
  347. IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */
  348. 0,
  349. IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */
  350. IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */
  351. IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */
  352. 0,
  353. IW_EV_POINT_PK_LEN, /* Without variable payload */
  354. IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */
  355. IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */
  356. };
  357. static const unsigned int standard_ioctl_num =
  358. (sizeof(standard_ioctl_descr) / sizeof(struct iw_ioctl_description));
  359. static const unsigned int standard_event_num =
  360. (sizeof(standard_event_descr) / sizeof(struct iw_ioctl_description));
  361. #define IW_IE_CYPHER_NUM 8
  362. #define IW_IE_KEY_MGMT_NUM 3
  363. int wext_get_scanlist(const char *ifname, char *buf, int *len);
  364. #endif