wext-core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. * This file implement the Wireless Extensions core API.
  3. *
  4. * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
  5. * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
  6. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * (As all part of the Linux kernel, this file is GPL)
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/rtnetlink.h>
  13. #include <linux/slab.h>
  14. #include <linux/wireless.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/export.h>
  17. #include <net/cfg80211.h>
  18. #include <net/iw_handler.h>
  19. #include <net/netlink.h>
  20. #include <net/wext.h>
  21. #include <net/net_namespace.h>
  22. typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *,
  23. unsigned int, struct iw_request_info *,
  24. iw_handler);
  25. /*
  26. * Meta-data about all the standard Wireless Extension request we
  27. * know about.
  28. */
  29. static const struct iw_ioctl_description standard_ioctl[] = {
  30. [IW_IOCTL_IDX(SIOCSIWCOMMIT)] = {
  31. .header_type = IW_HEADER_TYPE_NULL,
  32. },
  33. [IW_IOCTL_IDX(SIOCGIWNAME)] = {
  34. .header_type = IW_HEADER_TYPE_CHAR,
  35. .flags = IW_DESCR_FLAG_DUMP,
  36. },
  37. [IW_IOCTL_IDX(SIOCSIWNWID)] = {
  38. .header_type = IW_HEADER_TYPE_PARAM,
  39. .flags = IW_DESCR_FLAG_EVENT,
  40. },
  41. [IW_IOCTL_IDX(SIOCGIWNWID)] = {
  42. .header_type = IW_HEADER_TYPE_PARAM,
  43. .flags = IW_DESCR_FLAG_DUMP,
  44. },
  45. [IW_IOCTL_IDX(SIOCSIWFREQ)] = {
  46. .header_type = IW_HEADER_TYPE_FREQ,
  47. .flags = IW_DESCR_FLAG_EVENT,
  48. },
  49. [IW_IOCTL_IDX(SIOCGIWFREQ)] = {
  50. .header_type = IW_HEADER_TYPE_FREQ,
  51. .flags = IW_DESCR_FLAG_DUMP,
  52. },
  53. [IW_IOCTL_IDX(SIOCSIWMODE)] = {
  54. .header_type = IW_HEADER_TYPE_UINT,
  55. .flags = IW_DESCR_FLAG_EVENT,
  56. },
  57. [IW_IOCTL_IDX(SIOCGIWMODE)] = {
  58. .header_type = IW_HEADER_TYPE_UINT,
  59. .flags = IW_DESCR_FLAG_DUMP,
  60. },
  61. [IW_IOCTL_IDX(SIOCSIWSENS)] = {
  62. .header_type = IW_HEADER_TYPE_PARAM,
  63. },
  64. [IW_IOCTL_IDX(SIOCGIWSENS)] = {
  65. .header_type = IW_HEADER_TYPE_PARAM,
  66. },
  67. [IW_IOCTL_IDX(SIOCSIWRANGE)] = {
  68. .header_type = IW_HEADER_TYPE_NULL,
  69. },
  70. [IW_IOCTL_IDX(SIOCGIWRANGE)] = {
  71. .header_type = IW_HEADER_TYPE_POINT,
  72. .token_size = 1,
  73. .max_tokens = sizeof(struct iw_range),
  74. .flags = IW_DESCR_FLAG_DUMP,
  75. },
  76. [IW_IOCTL_IDX(SIOCSIWPRIV)] = {
  77. .header_type = IW_HEADER_TYPE_NULL,
  78. },
  79. [IW_IOCTL_IDX(SIOCGIWPRIV)] = { /* (handled directly by us) */
  80. .header_type = IW_HEADER_TYPE_POINT,
  81. .token_size = sizeof(struct iw_priv_args),
  82. .max_tokens = 16,
  83. .flags = IW_DESCR_FLAG_NOMAX,
  84. },
  85. [IW_IOCTL_IDX(SIOCSIWSTATS)] = {
  86. .header_type = IW_HEADER_TYPE_NULL,
  87. },
  88. [IW_IOCTL_IDX(SIOCGIWSTATS)] = { /* (handled directly by us) */
  89. .header_type = IW_HEADER_TYPE_POINT,
  90. .token_size = 1,
  91. .max_tokens = sizeof(struct iw_statistics),
  92. .flags = IW_DESCR_FLAG_DUMP,
  93. },
  94. [IW_IOCTL_IDX(SIOCSIWSPY)] = {
  95. .header_type = IW_HEADER_TYPE_POINT,
  96. .token_size = sizeof(struct sockaddr),
  97. .max_tokens = IW_MAX_SPY,
  98. },
  99. [IW_IOCTL_IDX(SIOCGIWSPY)] = {
  100. .header_type = IW_HEADER_TYPE_POINT,
  101. .token_size = sizeof(struct sockaddr) +
  102. sizeof(struct iw_quality),
  103. .max_tokens = IW_MAX_SPY,
  104. },
  105. [IW_IOCTL_IDX(SIOCSIWTHRSPY)] = {
  106. .header_type = IW_HEADER_TYPE_POINT,
  107. .token_size = sizeof(struct iw_thrspy),
  108. .min_tokens = 1,
  109. .max_tokens = 1,
  110. },
  111. [IW_IOCTL_IDX(SIOCGIWTHRSPY)] = {
  112. .header_type = IW_HEADER_TYPE_POINT,
  113. .token_size = sizeof(struct iw_thrspy),
  114. .min_tokens = 1,
  115. .max_tokens = 1,
  116. },
  117. [IW_IOCTL_IDX(SIOCSIWAP)] = {
  118. .header_type = IW_HEADER_TYPE_ADDR,
  119. },
  120. [IW_IOCTL_IDX(SIOCGIWAP)] = {
  121. .header_type = IW_HEADER_TYPE_ADDR,
  122. .flags = IW_DESCR_FLAG_DUMP,
  123. },
  124. [IW_IOCTL_IDX(SIOCSIWMLME)] = {
  125. .header_type = IW_HEADER_TYPE_POINT,
  126. .token_size = 1,
  127. .min_tokens = sizeof(struct iw_mlme),
  128. .max_tokens = sizeof(struct iw_mlme),
  129. },
  130. [IW_IOCTL_IDX(SIOCGIWAPLIST)] = {
  131. .header_type = IW_HEADER_TYPE_POINT,
  132. .token_size = sizeof(struct sockaddr) +
  133. sizeof(struct iw_quality),
  134. .max_tokens = IW_MAX_AP,
  135. .flags = IW_DESCR_FLAG_NOMAX,
  136. },
  137. [IW_IOCTL_IDX(SIOCSIWSCAN)] = {
  138. .header_type = IW_HEADER_TYPE_POINT,
  139. .token_size = 1,
  140. .min_tokens = 0,
  141. .max_tokens = sizeof(struct iw_scan_req),
  142. },
  143. [IW_IOCTL_IDX(SIOCGIWSCAN)] = {
  144. .header_type = IW_HEADER_TYPE_POINT,
  145. .token_size = 1,
  146. .max_tokens = IW_SCAN_MAX_DATA,
  147. .flags = IW_DESCR_FLAG_NOMAX,
  148. },
  149. [IW_IOCTL_IDX(SIOCSIWESSID)] = {
  150. .header_type = IW_HEADER_TYPE_POINT,
  151. .token_size = 1,
  152. .max_tokens = IW_ESSID_MAX_SIZE,
  153. .flags = IW_DESCR_FLAG_EVENT,
  154. },
  155. [IW_IOCTL_IDX(SIOCGIWESSID)] = {
  156. .header_type = IW_HEADER_TYPE_POINT,
  157. .token_size = 1,
  158. .max_tokens = IW_ESSID_MAX_SIZE,
  159. .flags = IW_DESCR_FLAG_DUMP,
  160. },
  161. [IW_IOCTL_IDX(SIOCSIWNICKN)] = {
  162. .header_type = IW_HEADER_TYPE_POINT,
  163. .token_size = 1,
  164. .max_tokens = IW_ESSID_MAX_SIZE,
  165. },
  166. [IW_IOCTL_IDX(SIOCGIWNICKN)] = {
  167. .header_type = IW_HEADER_TYPE_POINT,
  168. .token_size = 1,
  169. .max_tokens = IW_ESSID_MAX_SIZE,
  170. },
  171. [IW_IOCTL_IDX(SIOCSIWRATE)] = {
  172. .header_type = IW_HEADER_TYPE_PARAM,
  173. },
  174. [IW_IOCTL_IDX(SIOCGIWRATE)] = {
  175. .header_type = IW_HEADER_TYPE_PARAM,
  176. },
  177. [IW_IOCTL_IDX(SIOCSIWRTS)] = {
  178. .header_type = IW_HEADER_TYPE_PARAM,
  179. },
  180. [IW_IOCTL_IDX(SIOCGIWRTS)] = {
  181. .header_type = IW_HEADER_TYPE_PARAM,
  182. },
  183. [IW_IOCTL_IDX(SIOCSIWFRAG)] = {
  184. .header_type = IW_HEADER_TYPE_PARAM,
  185. },
  186. [IW_IOCTL_IDX(SIOCGIWFRAG)] = {
  187. .header_type = IW_HEADER_TYPE_PARAM,
  188. },
  189. [IW_IOCTL_IDX(SIOCSIWTXPOW)] = {
  190. .header_type = IW_HEADER_TYPE_PARAM,
  191. },
  192. [IW_IOCTL_IDX(SIOCGIWTXPOW)] = {
  193. .header_type = IW_HEADER_TYPE_PARAM,
  194. },
  195. [IW_IOCTL_IDX(SIOCSIWRETRY)] = {
  196. .header_type = IW_HEADER_TYPE_PARAM,
  197. },
  198. [IW_IOCTL_IDX(SIOCGIWRETRY)] = {
  199. .header_type = IW_HEADER_TYPE_PARAM,
  200. },
  201. [IW_IOCTL_IDX(SIOCSIWENCODE)] = {
  202. .header_type = IW_HEADER_TYPE_POINT,
  203. .token_size = 1,
  204. .max_tokens = IW_ENCODING_TOKEN_MAX,
  205. .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
  206. },
  207. [IW_IOCTL_IDX(SIOCGIWENCODE)] = {
  208. .header_type = IW_HEADER_TYPE_POINT,
  209. .token_size = 1,
  210. .max_tokens = IW_ENCODING_TOKEN_MAX,
  211. .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
  212. },
  213. [IW_IOCTL_IDX(SIOCSIWPOWER)] = {
  214. .header_type = IW_HEADER_TYPE_PARAM,
  215. },
  216. [IW_IOCTL_IDX(SIOCGIWPOWER)] = {
  217. .header_type = IW_HEADER_TYPE_PARAM,
  218. },
  219. [IW_IOCTL_IDX(SIOCSIWGENIE)] = {
  220. .header_type = IW_HEADER_TYPE_POINT,
  221. .token_size = 1,
  222. .max_tokens = IW_GENERIC_IE_MAX,
  223. },
  224. [IW_IOCTL_IDX(SIOCGIWGENIE)] = {
  225. .header_type = IW_HEADER_TYPE_POINT,
  226. .token_size = 1,
  227. .max_tokens = IW_GENERIC_IE_MAX,
  228. },
  229. [IW_IOCTL_IDX(SIOCSIWAUTH)] = {
  230. .header_type = IW_HEADER_TYPE_PARAM,
  231. },
  232. [IW_IOCTL_IDX(SIOCGIWAUTH)] = {
  233. .header_type = IW_HEADER_TYPE_PARAM,
  234. },
  235. [IW_IOCTL_IDX(SIOCSIWENCODEEXT)] = {
  236. .header_type = IW_HEADER_TYPE_POINT,
  237. .token_size = 1,
  238. .min_tokens = sizeof(struct iw_encode_ext),
  239. .max_tokens = sizeof(struct iw_encode_ext) +
  240. IW_ENCODING_TOKEN_MAX,
  241. },
  242. [IW_IOCTL_IDX(SIOCGIWENCODEEXT)] = {
  243. .header_type = IW_HEADER_TYPE_POINT,
  244. .token_size = 1,
  245. .min_tokens = sizeof(struct iw_encode_ext),
  246. .max_tokens = sizeof(struct iw_encode_ext) +
  247. IW_ENCODING_TOKEN_MAX,
  248. },
  249. [IW_IOCTL_IDX(SIOCSIWPMKSA)] = {
  250. .header_type = IW_HEADER_TYPE_POINT,
  251. .token_size = 1,
  252. .min_tokens = sizeof(struct iw_pmksa),
  253. .max_tokens = sizeof(struct iw_pmksa),
  254. },
  255. };
  256. static const unsigned int standard_ioctl_num = ARRAY_SIZE(standard_ioctl);
  257. /*
  258. * Meta-data about all the additional standard Wireless Extension events
  259. * we know about.
  260. */
  261. static const struct iw_ioctl_description standard_event[] = {
  262. [IW_EVENT_IDX(IWEVTXDROP)] = {
  263. .header_type = IW_HEADER_TYPE_ADDR,
  264. },
  265. [IW_EVENT_IDX(IWEVQUAL)] = {
  266. .header_type = IW_HEADER_TYPE_QUAL,
  267. },
  268. [IW_EVENT_IDX(IWEVCUSTOM)] = {
  269. .header_type = IW_HEADER_TYPE_POINT,
  270. .token_size = 1,
  271. .max_tokens = IW_CUSTOM_MAX,
  272. },
  273. [IW_EVENT_IDX(IWEVREGISTERED)] = {
  274. .header_type = IW_HEADER_TYPE_ADDR,
  275. },
  276. [IW_EVENT_IDX(IWEVEXPIRED)] = {
  277. .header_type = IW_HEADER_TYPE_ADDR,
  278. },
  279. [IW_EVENT_IDX(IWEVGENIE)] = {
  280. .header_type = IW_HEADER_TYPE_POINT,
  281. .token_size = 1,
  282. .max_tokens = IW_GENERIC_IE_MAX,
  283. },
  284. [IW_EVENT_IDX(IWEVMICHAELMICFAILURE)] = {
  285. .header_type = IW_HEADER_TYPE_POINT,
  286. .token_size = 1,
  287. .max_tokens = sizeof(struct iw_michaelmicfailure),
  288. },
  289. [IW_EVENT_IDX(IWEVASSOCREQIE)] = {
  290. .header_type = IW_HEADER_TYPE_POINT,
  291. .token_size = 1,
  292. .max_tokens = IW_GENERIC_IE_MAX,
  293. },
  294. [IW_EVENT_IDX(IWEVASSOCRESPIE)] = {
  295. .header_type = IW_HEADER_TYPE_POINT,
  296. .token_size = 1,
  297. .max_tokens = IW_GENERIC_IE_MAX,
  298. },
  299. [IW_EVENT_IDX(IWEVPMKIDCAND)] = {
  300. .header_type = IW_HEADER_TYPE_POINT,
  301. .token_size = 1,
  302. .max_tokens = sizeof(struct iw_pmkid_cand),
  303. },
  304. };
  305. static const unsigned int standard_event_num = ARRAY_SIZE(standard_event);
  306. /* Size (in bytes) of various events */
  307. static const int event_type_size[] = {
  308. IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
  309. 0,
  310. IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
  311. 0,
  312. IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
  313. IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
  314. IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
  315. 0,
  316. IW_EV_POINT_LEN, /* Without variable payload */
  317. IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
  318. IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
  319. };
  320. #ifdef CONFIG_COMPAT
  321. static const int compat_event_type_size[] = {
  322. IW_EV_COMPAT_LCP_LEN, /* IW_HEADER_TYPE_NULL */
  323. 0,
  324. IW_EV_COMPAT_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
  325. 0,
  326. IW_EV_COMPAT_UINT_LEN, /* IW_HEADER_TYPE_UINT */
  327. IW_EV_COMPAT_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
  328. IW_EV_COMPAT_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
  329. 0,
  330. IW_EV_COMPAT_POINT_LEN, /* Without variable payload */
  331. IW_EV_COMPAT_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
  332. IW_EV_COMPAT_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
  333. };
  334. #endif
  335. /* IW event code */
  336. void wireless_nlevent_flush(void)
  337. {
  338. struct sk_buff *skb;
  339. struct net *net;
  340. down_read(&net_rwsem);
  341. for_each_net(net) {
  342. while ((skb = skb_dequeue(&net->wext_nlevents)))
  343. rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
  344. GFP_KERNEL);
  345. }
  346. up_read(&net_rwsem);
  347. }
  348. EXPORT_SYMBOL_GPL(wireless_nlevent_flush);
  349. static int wext_netdev_notifier_call(struct notifier_block *nb,
  350. unsigned long state, void *ptr)
  351. {
  352. /*
  353. * When a netdev changes state in any way, flush all pending messages
  354. * to avoid them going out in a strange order, e.g. RTM_NEWLINK after
  355. * RTM_DELLINK, or with IFF_UP after without IFF_UP during dev_close()
  356. * or similar - all of which could otherwise happen due to delays from
  357. * schedule_work().
  358. */
  359. wireless_nlevent_flush();
  360. return NOTIFY_OK;
  361. }
  362. static struct notifier_block wext_netdev_notifier = {
  363. .notifier_call = wext_netdev_notifier_call,
  364. };
  365. static int __net_init wext_pernet_init(struct net *net)
  366. {
  367. skb_queue_head_init(&net->wext_nlevents);
  368. return 0;
  369. }
  370. static void __net_exit wext_pernet_exit(struct net *net)
  371. {
  372. skb_queue_purge(&net->wext_nlevents);
  373. }
  374. static struct pernet_operations wext_pernet_ops = {
  375. .init = wext_pernet_init,
  376. .exit = wext_pernet_exit,
  377. };
  378. static int __init wireless_nlevent_init(void)
  379. {
  380. int err = register_pernet_subsys(&wext_pernet_ops);
  381. if (err)
  382. return err;
  383. err = register_netdevice_notifier(&wext_netdev_notifier);
  384. if (err)
  385. unregister_pernet_subsys(&wext_pernet_ops);
  386. return err;
  387. }
  388. subsys_initcall(wireless_nlevent_init);
  389. /* Process events generated by the wireless layer or the driver. */
  390. static void wireless_nlevent_process(struct work_struct *work)
  391. {
  392. wireless_nlevent_flush();
  393. }
  394. static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process);
  395. static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev,
  396. struct sk_buff *skb)
  397. {
  398. struct ifinfomsg *r;
  399. struct nlmsghdr *nlh;
  400. nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0);
  401. if (!nlh)
  402. return NULL;
  403. r = nlmsg_data(nlh);
  404. r->ifi_family = AF_UNSPEC;
  405. r->__ifi_pad = 0;
  406. r->ifi_type = dev->type;
  407. r->ifi_index = dev->ifindex;
  408. r->ifi_flags = dev_get_flags(dev);
  409. r->ifi_change = 0; /* Wireless changes don't affect those flags */
  410. if (nla_put_string(skb, IFLA_IFNAME, dev->name))
  411. goto nla_put_failure;
  412. return nlh;
  413. nla_put_failure:
  414. nlmsg_cancel(skb, nlh);
  415. return NULL;
  416. }
  417. /*
  418. * Main event dispatcher. Called from other parts and drivers.
  419. * Send the event on the appropriate channels.
  420. * May be called from interrupt context.
  421. */
  422. void wireless_send_event(struct net_device * dev,
  423. unsigned int cmd,
  424. union iwreq_data * wrqu,
  425. const char * extra)
  426. {
  427. const struct iw_ioctl_description * descr = NULL;
  428. int extra_len = 0;
  429. struct iw_event *event; /* Mallocated whole event */
  430. int event_len; /* Its size */
  431. int hdr_len; /* Size of the event header */
  432. int wrqu_off = 0; /* Offset in wrqu */
  433. /* Don't "optimise" the following variable, it will crash */
  434. unsigned int cmd_index; /* *MUST* be unsigned */
  435. struct sk_buff *skb;
  436. struct nlmsghdr *nlh;
  437. struct nlattr *nla;
  438. #ifdef CONFIG_COMPAT
  439. struct __compat_iw_event *compat_event;
  440. struct compat_iw_point compat_wrqu;
  441. struct sk_buff *compskb;
  442. #endif
  443. /*
  444. * Nothing in the kernel sends scan events with data, be safe.
  445. * This is necessary because we cannot fix up scan event data
  446. * for compat, due to being contained in 'extra', but normally
  447. * applications are required to retrieve the scan data anyway
  448. * and no data is included in the event, this codifies that
  449. * practice.
  450. */
  451. if (WARN_ON(cmd == SIOCGIWSCAN && extra))
  452. extra = NULL;
  453. /* Get the description of the Event */
  454. if (cmd <= SIOCIWLAST) {
  455. cmd_index = IW_IOCTL_IDX(cmd);
  456. if (cmd_index < standard_ioctl_num)
  457. descr = &(standard_ioctl[cmd_index]);
  458. } else {
  459. cmd_index = IW_EVENT_IDX(cmd);
  460. if (cmd_index < standard_event_num)
  461. descr = &(standard_event[cmd_index]);
  462. }
  463. /* Don't accept unknown events */
  464. if (descr == NULL) {
  465. /* Note : we don't return an error to the driver, because
  466. * the driver would not know what to do about it. It can't
  467. * return an error to the user, because the event is not
  468. * initiated by a user request.
  469. * The best the driver could do is to log an error message.
  470. * We will do it ourselves instead...
  471. */
  472. netdev_err(dev, "(WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
  473. cmd);
  474. return;
  475. }
  476. /* Check extra parameters and set extra_len */
  477. if (descr->header_type == IW_HEADER_TYPE_POINT) {
  478. /* Check if number of token fits within bounds */
  479. if (wrqu->data.length > descr->max_tokens) {
  480. netdev_err(dev, "(WE) : Wireless Event (cmd=0x%04X) too big (%d)\n",
  481. cmd, wrqu->data.length);
  482. return;
  483. }
  484. if (wrqu->data.length < descr->min_tokens) {
  485. netdev_err(dev, "(WE) : Wireless Event (cmd=0x%04X) too small (%d)\n",
  486. cmd, wrqu->data.length);
  487. return;
  488. }
  489. /* Calculate extra_len - extra is NULL for restricted events */
  490. if (extra != NULL)
  491. extra_len = wrqu->data.length * descr->token_size;
  492. /* Always at an offset in wrqu */
  493. wrqu_off = IW_EV_POINT_OFF;
  494. }
  495. /* Total length of the event */
  496. hdr_len = event_type_size[descr->header_type];
  497. event_len = hdr_len + extra_len;
  498. /*
  499. * The problem for 64/32 bit.
  500. *
  501. * On 64-bit, a regular event is laid out as follows:
  502. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  503. * | event.len | event.cmd | p a d d i n g |
  504. * | wrqu data ... (with the correct size) |
  505. *
  506. * This padding exists because we manipulate event->u,
  507. * and 'event' is not packed.
  508. *
  509. * An iw_point event is laid out like this instead:
  510. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
  511. * | event.len | event.cmd | p a d d i n g |
  512. * | iwpnt.len | iwpnt.flg | p a d d i n g |
  513. * | extra data ...
  514. *
  515. * The second padding exists because struct iw_point is extended,
  516. * but this depends on the platform...
  517. *
  518. * On 32-bit, all the padding shouldn't be there.
  519. */
  520. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  521. if (!skb)
  522. return;
  523. /* Send via the RtNetlink event channel */
  524. nlh = rtnetlink_ifinfo_prep(dev, skb);
  525. if (WARN_ON(!nlh)) {
  526. kfree_skb(skb);
  527. return;
  528. }
  529. /* Add the wireless events in the netlink packet */
  530. nla = nla_reserve(skb, IFLA_WIRELESS, event_len);
  531. if (!nla) {
  532. kfree_skb(skb);
  533. return;
  534. }
  535. event = nla_data(nla);
  536. /* Fill event - first clear to avoid data leaking */
  537. memset(event, 0, hdr_len);
  538. event->len = event_len;
  539. event->cmd = cmd;
  540. memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
  541. if (extra_len)
  542. memcpy(((char *) event) + hdr_len, extra, extra_len);
  543. nlmsg_end(skb, nlh);
  544. #ifdef CONFIG_COMPAT
  545. hdr_len = compat_event_type_size[descr->header_type];
  546. event_len = hdr_len + extra_len;
  547. compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  548. if (!compskb) {
  549. kfree_skb(skb);
  550. return;
  551. }
  552. /* Send via the RtNetlink event channel */
  553. nlh = rtnetlink_ifinfo_prep(dev, compskb);
  554. if (WARN_ON(!nlh)) {
  555. kfree_skb(skb);
  556. kfree_skb(compskb);
  557. return;
  558. }
  559. /* Add the wireless events in the netlink packet */
  560. nla = nla_reserve(compskb, IFLA_WIRELESS, event_len);
  561. if (!nla) {
  562. kfree_skb(skb);
  563. kfree_skb(compskb);
  564. return;
  565. }
  566. compat_event = nla_data(nla);
  567. compat_event->len = event_len;
  568. compat_event->cmd = cmd;
  569. if (descr->header_type == IW_HEADER_TYPE_POINT) {
  570. compat_wrqu.length = wrqu->data.length;
  571. compat_wrqu.flags = wrqu->data.flags;
  572. memcpy(&compat_event->pointer,
  573. ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF,
  574. hdr_len - IW_EV_COMPAT_LCP_LEN);
  575. if (extra_len)
  576. memcpy(((char *) compat_event) + hdr_len,
  577. extra, extra_len);
  578. } else {
  579. /* extra_len must be zero, so no if (extra) needed */
  580. memcpy(&compat_event->pointer, wrqu,
  581. hdr_len - IW_EV_COMPAT_LCP_LEN);
  582. }
  583. nlmsg_end(compskb, nlh);
  584. skb_shinfo(skb)->frag_list = compskb;
  585. #endif
  586. skb_queue_tail(&dev_net(dev)->wext_nlevents, skb);
  587. schedule_work(&wireless_nlevent_work);
  588. }
  589. EXPORT_SYMBOL(wireless_send_event);
  590. /* IW handlers */
  591. struct iw_statistics *get_wireless_stats(struct net_device *dev)
  592. {
  593. #ifdef CONFIG_WIRELESS_EXT
  594. if ((dev->wireless_handlers != NULL) &&
  595. (dev->wireless_handlers->get_wireless_stats != NULL))
  596. return dev->wireless_handlers->get_wireless_stats(dev);
  597. #endif
  598. #ifdef CONFIG_CFG80211_WEXT
  599. if (dev->ieee80211_ptr &&
  600. dev->ieee80211_ptr->wiphy &&
  601. dev->ieee80211_ptr->wiphy->wext &&
  602. dev->ieee80211_ptr->wiphy->wext->get_wireless_stats)
  603. return dev->ieee80211_ptr->wiphy->wext->get_wireless_stats(dev);
  604. #endif
  605. /* not found */
  606. return NULL;
  607. }
  608. /* noinline to avoid a bogus warning with -O3 */
  609. static noinline int iw_handler_get_iwstats(struct net_device * dev,
  610. struct iw_request_info * info,
  611. union iwreq_data * wrqu,
  612. char * extra)
  613. {
  614. /* Get stats from the driver */
  615. struct iw_statistics *stats;
  616. stats = get_wireless_stats(dev);
  617. if (stats) {
  618. /* Copy statistics to extra */
  619. memcpy(extra, stats, sizeof(struct iw_statistics));
  620. wrqu->data.length = sizeof(struct iw_statistics);
  621. /* Check if we need to clear the updated flag */
  622. if (wrqu->data.flags != 0)
  623. stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
  624. return 0;
  625. } else
  626. return -EOPNOTSUPP;
  627. }
  628. static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
  629. {
  630. /* Don't "optimise" the following variable, it will crash */
  631. unsigned int index; /* *MUST* be unsigned */
  632. const struct iw_handler_def *handlers = NULL;
  633. #ifdef CONFIG_CFG80211_WEXT
  634. if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy)
  635. handlers = dev->ieee80211_ptr->wiphy->wext;
  636. #endif
  637. #ifdef CONFIG_WIRELESS_EXT
  638. if (dev->wireless_handlers)
  639. handlers = dev->wireless_handlers;
  640. #endif
  641. if (!handlers)
  642. return NULL;
  643. /* Try as a standard command */
  644. index = IW_IOCTL_IDX(cmd);
  645. if (index < handlers->num_standard)
  646. return handlers->standard[index];
  647. #ifdef CONFIG_WEXT_PRIV
  648. /* Try as a private command */
  649. index = cmd - SIOCIWFIRSTPRIV;
  650. if (index < handlers->num_private)
  651. return handlers->private[index];
  652. #endif
  653. /* Not found */
  654. return NULL;
  655. }
  656. static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
  657. const struct iw_ioctl_description *descr,
  658. iw_handler handler, struct net_device *dev,
  659. struct iw_request_info *info)
  660. {
  661. int err, extra_size, user_length = 0, essid_compat = 0;
  662. char *extra;
  663. /* Calculate space needed by arguments. Always allocate
  664. * for max space.
  665. */
  666. extra_size = descr->max_tokens * descr->token_size;
  667. /* Check need for ESSID compatibility for WE < 21 */
  668. switch (cmd) {
  669. case SIOCSIWESSID:
  670. case SIOCGIWESSID:
  671. case SIOCSIWNICKN:
  672. case SIOCGIWNICKN:
  673. if (iwp->length == descr->max_tokens + 1)
  674. essid_compat = 1;
  675. else if (IW_IS_SET(cmd) && (iwp->length != 0)) {
  676. char essid[IW_ESSID_MAX_SIZE + 1];
  677. unsigned int len;
  678. len = iwp->length * descr->token_size;
  679. if (len > IW_ESSID_MAX_SIZE)
  680. return -EFAULT;
  681. err = copy_from_user(essid, iwp->pointer, len);
  682. if (err)
  683. return -EFAULT;
  684. if (essid[iwp->length - 1] == '\0')
  685. essid_compat = 1;
  686. }
  687. break;
  688. default:
  689. break;
  690. }
  691. iwp->length -= essid_compat;
  692. /* Check what user space is giving us */
  693. if (IW_IS_SET(cmd)) {
  694. /* Check NULL pointer */
  695. if (!iwp->pointer && iwp->length != 0)
  696. return -EFAULT;
  697. /* Check if number of token fits within bounds */
  698. if (iwp->length > descr->max_tokens)
  699. return -E2BIG;
  700. if (iwp->length < descr->min_tokens)
  701. return -EINVAL;
  702. } else {
  703. /* Check NULL pointer */
  704. if (!iwp->pointer)
  705. return -EFAULT;
  706. /* Save user space buffer size for checking */
  707. user_length = iwp->length;
  708. /* Don't check if user_length > max to allow forward
  709. * compatibility. The test user_length < min is
  710. * implied by the test at the end.
  711. */
  712. /* Support for very large requests */
  713. if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
  714. (user_length > descr->max_tokens)) {
  715. /* Allow userspace to GET more than max so
  716. * we can support any size GET requests.
  717. * There is still a limit : -ENOMEM.
  718. */
  719. extra_size = user_length * descr->token_size;
  720. /* Note : user_length is originally a __u16,
  721. * and token_size is controlled by us,
  722. * so extra_size won't get negative and
  723. * won't overflow...
  724. */
  725. }
  726. }
  727. /* kzalloc() ensures NULL-termination for essid_compat. */
  728. extra = kzalloc(extra_size, GFP_KERNEL);
  729. if (!extra)
  730. return -ENOMEM;
  731. /* If it is a SET, get all the extra data in here */
  732. if (IW_IS_SET(cmd) && (iwp->length != 0)) {
  733. if (copy_from_user(extra, iwp->pointer,
  734. iwp->length *
  735. descr->token_size)) {
  736. err = -EFAULT;
  737. goto out;
  738. }
  739. if (cmd == SIOCSIWENCODEEXT) {
  740. struct iw_encode_ext *ee = (void *) extra;
  741. if (iwp->length < sizeof(*ee) + ee->key_len) {
  742. err = -EFAULT;
  743. goto out;
  744. }
  745. }
  746. }
  747. if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
  748. /*
  749. * If this is a GET, but not NOMAX, it means that the extra
  750. * data is not bounded by userspace, but by max_tokens. Thus
  751. * set the length to max_tokens. This matches the extra data
  752. * allocation.
  753. * The driver should fill it with the number of tokens it
  754. * provided, and it may check iwp->length rather than having
  755. * knowledge of max_tokens. If the driver doesn't change the
  756. * iwp->length, this ioctl just copies back max_token tokens
  757. * filled with zeroes. Hopefully the driver isn't claiming
  758. * them to be valid data.
  759. */
  760. iwp->length = descr->max_tokens;
  761. }
  762. err = handler(dev, info, (union iwreq_data *) iwp, extra);
  763. iwp->length += essid_compat;
  764. /* If we have something to return to the user */
  765. if (!err && IW_IS_GET(cmd)) {
  766. /* Check if there is enough buffer up there */
  767. if (user_length < iwp->length) {
  768. err = -E2BIG;
  769. goto out;
  770. }
  771. if (copy_to_user(iwp->pointer, extra,
  772. iwp->length *
  773. descr->token_size)) {
  774. err = -EFAULT;
  775. goto out;
  776. }
  777. }
  778. /* Generate an event to notify listeners of the change */
  779. if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
  780. ((err == 0) || (err == -EIWCOMMIT))) {
  781. union iwreq_data *data = (union iwreq_data *) iwp;
  782. if (descr->flags & IW_DESCR_FLAG_RESTRICT)
  783. /* If the event is restricted, don't
  784. * export the payload.
  785. */
  786. wireless_send_event(dev, cmd, data, NULL);
  787. else
  788. wireless_send_event(dev, cmd, data, extra);
  789. }
  790. out:
  791. kfree(extra);
  792. return err;
  793. }
  794. /*
  795. * Call the commit handler in the driver
  796. * (if exist and if conditions are right)
  797. *
  798. * Note : our current commit strategy is currently pretty dumb,
  799. * but we will be able to improve on that...
  800. * The goal is to try to agreagate as many changes as possible
  801. * before doing the commit. Drivers that will define a commit handler
  802. * are usually those that need a reset after changing parameters, so
  803. * we want to minimise the number of reset.
  804. * A cool idea is to use a timer : at each "set" command, we re-set the
  805. * timer, when the timer eventually fires, we call the driver.
  806. * Hopefully, more on that later.
  807. *
  808. * Also, I'm waiting to see how many people will complain about the
  809. * netif_running(dev) test. I'm open on that one...
  810. * Hopefully, the driver will remember to do a commit in "open()" ;-)
  811. */
  812. int call_commit_handler(struct net_device *dev)
  813. {
  814. #ifdef CONFIG_WIRELESS_EXT
  815. if (netif_running(dev) &&
  816. dev->wireless_handlers &&
  817. dev->wireless_handlers->standard[0])
  818. /* Call the commit handler on the driver */
  819. return dev->wireless_handlers->standard[0](dev, NULL,
  820. NULL, NULL);
  821. else
  822. return 0; /* Command completed successfully */
  823. #else
  824. /* cfg80211 has no commit */
  825. return 0;
  826. #endif
  827. }
  828. /*
  829. * Main IOCTl dispatcher.
  830. * Check the type of IOCTL and call the appropriate wrapper...
  831. */
  832. static int wireless_process_ioctl(struct net *net, struct iwreq *iwr,
  833. unsigned int cmd,
  834. struct iw_request_info *info,
  835. wext_ioctl_func standard,
  836. wext_ioctl_func private)
  837. {
  838. struct net_device *dev;
  839. iw_handler handler;
  840. /* Permissions are already checked in dev_ioctl() before calling us.
  841. * The copy_to/from_user() of ifr is also dealt with in there */
  842. /* Make sure the device exist */
  843. if ((dev = __dev_get_by_name(net, iwr->ifr_name)) == NULL)
  844. return -ENODEV;
  845. /* A bunch of special cases, then the generic case...
  846. * Note that 'cmd' is already filtered in dev_ioctl() with
  847. * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
  848. if (cmd == SIOCGIWSTATS)
  849. return standard(dev, iwr, cmd, info,
  850. &iw_handler_get_iwstats);
  851. #ifdef CONFIG_WEXT_PRIV
  852. if (cmd == SIOCGIWPRIV && dev->wireless_handlers)
  853. return standard(dev, iwr, cmd, info,
  854. iw_handler_get_private);
  855. #endif
  856. /* Basic check */
  857. if (!netif_device_present(dev))
  858. return -ENODEV;
  859. /* New driver API : try to find the handler */
  860. handler = get_handler(dev, cmd);
  861. if (handler) {
  862. /* Standard and private are not the same */
  863. if (cmd < SIOCIWFIRSTPRIV)
  864. return standard(dev, iwr, cmd, info, handler);
  865. else if (private)
  866. return private(dev, iwr, cmd, info, handler);
  867. }
  868. return -EOPNOTSUPP;
  869. }
  870. /* If command is `set a parameter', or `get the encoding parameters',
  871. * check if the user has the right to do it.
  872. */
  873. static int wext_permission_check(unsigned int cmd)
  874. {
  875. if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE ||
  876. cmd == SIOCGIWENCODEEXT) &&
  877. !capable(CAP_NET_ADMIN))
  878. return -EPERM;
  879. return 0;
  880. }
  881. /* entry point from dev ioctl */
  882. static int wext_ioctl_dispatch(struct net *net, struct iwreq *iwr,
  883. unsigned int cmd, struct iw_request_info *info,
  884. wext_ioctl_func standard,
  885. wext_ioctl_func private)
  886. {
  887. int ret = wext_permission_check(cmd);
  888. if (ret)
  889. return ret;
  890. dev_load(net, iwr->ifr_name);
  891. rtnl_lock();
  892. ret = wireless_process_ioctl(net, iwr, cmd, info, standard, private);
  893. rtnl_unlock();
  894. return ret;
  895. }
  896. /*
  897. * Wrapper to call a standard Wireless Extension handler.
  898. * We do various checks and also take care of moving data between
  899. * user space and kernel space.
  900. */
  901. static int ioctl_standard_call(struct net_device * dev,
  902. struct iwreq *iwr,
  903. unsigned int cmd,
  904. struct iw_request_info *info,
  905. iw_handler handler)
  906. {
  907. const struct iw_ioctl_description * descr;
  908. int ret = -EINVAL;
  909. /* Get the description of the IOCTL */
  910. if (IW_IOCTL_IDX(cmd) >= standard_ioctl_num)
  911. return -EOPNOTSUPP;
  912. descr = &(standard_ioctl[IW_IOCTL_IDX(cmd)]);
  913. /* Check if we have a pointer to user space data or not */
  914. if (descr->header_type != IW_HEADER_TYPE_POINT) {
  915. /* No extra arguments. Trivial to handle */
  916. ret = handler(dev, info, &(iwr->u), NULL);
  917. /* Generate an event to notify listeners of the change */
  918. if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
  919. ((ret == 0) || (ret == -EIWCOMMIT)))
  920. wireless_send_event(dev, cmd, &(iwr->u), NULL);
  921. } else {
  922. ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr,
  923. handler, dev, info);
  924. }
  925. /* Call commit handler if needed and defined */
  926. if (ret == -EIWCOMMIT)
  927. ret = call_commit_handler(dev);
  928. /* Here, we will generate the appropriate event if needed */
  929. return ret;
  930. }
  931. int wext_handle_ioctl(struct net *net, unsigned int cmd, void __user *arg)
  932. {
  933. struct iw_request_info info = { .cmd = cmd, .flags = 0 };
  934. struct iwreq iwr;
  935. int ret;
  936. if (copy_from_user(&iwr, arg, sizeof(iwr)))
  937. return -EFAULT;
  938. iwr.ifr_name[sizeof(iwr.ifr_name) - 1] = 0;
  939. ret = wext_ioctl_dispatch(net, &iwr, cmd, &info,
  940. ioctl_standard_call,
  941. ioctl_private_call);
  942. if (ret >= 0 &&
  943. IW_IS_GET(cmd) &&
  944. copy_to_user(arg, &iwr, sizeof(struct iwreq)))
  945. return -EFAULT;
  946. return ret;
  947. }
  948. #ifdef CONFIG_COMPAT
  949. static int compat_standard_call(struct net_device *dev,
  950. struct iwreq *iwr,
  951. unsigned int cmd,
  952. struct iw_request_info *info,
  953. iw_handler handler)
  954. {
  955. const struct iw_ioctl_description *descr;
  956. struct compat_iw_point *iwp_compat;
  957. struct iw_point iwp;
  958. int err;
  959. descr = standard_ioctl + IW_IOCTL_IDX(cmd);
  960. if (descr->header_type != IW_HEADER_TYPE_POINT)
  961. return ioctl_standard_call(dev, iwr, cmd, info, handler);
  962. iwp_compat = (struct compat_iw_point *) &iwr->u.data;
  963. iwp.pointer = compat_ptr(iwp_compat->pointer);
  964. iwp.length = iwp_compat->length;
  965. iwp.flags = iwp_compat->flags;
  966. err = ioctl_standard_iw_point(&iwp, cmd, descr, handler, dev, info);
  967. iwp_compat->pointer = ptr_to_compat(iwp.pointer);
  968. iwp_compat->length = iwp.length;
  969. iwp_compat->flags = iwp.flags;
  970. return err;
  971. }
  972. int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
  973. unsigned long arg)
  974. {
  975. void __user *argp = (void __user *)arg;
  976. struct iw_request_info info;
  977. struct iwreq iwr;
  978. char *colon;
  979. int ret;
  980. if (copy_from_user(&iwr, argp, sizeof(struct iwreq)))
  981. return -EFAULT;
  982. iwr.ifr_name[IFNAMSIZ-1] = 0;
  983. colon = strchr(iwr.ifr_name, ':');
  984. if (colon)
  985. *colon = 0;
  986. info.cmd = cmd;
  987. info.flags = IW_REQUEST_FLAG_COMPAT;
  988. ret = wext_ioctl_dispatch(net, &iwr, cmd, &info,
  989. compat_standard_call,
  990. compat_private_call);
  991. if (ret >= 0 &&
  992. IW_IS_GET(cmd) &&
  993. copy_to_user(argp, &iwr, sizeof(struct iwreq)))
  994. return -EFAULT;
  995. return ret;
  996. }
  997. #endif
  998. char *iwe_stream_add_event(struct iw_request_info *info, char *stream,
  999. char *ends, struct iw_event *iwe, int event_len)
  1000. {
  1001. int lcp_len = iwe_stream_lcp_len(info);
  1002. event_len = iwe_stream_event_len_adjust(info, event_len);
  1003. /* Check if it's possible */
  1004. if (likely((stream + event_len) < ends)) {
  1005. iwe->len = event_len;
  1006. /* Beware of alignement issues on 64 bits */
  1007. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  1008. memcpy(stream + lcp_len, &iwe->u,
  1009. event_len - lcp_len);
  1010. stream += event_len;
  1011. }
  1012. return stream;
  1013. }
  1014. EXPORT_SYMBOL(iwe_stream_add_event);
  1015. char *iwe_stream_add_point(struct iw_request_info *info, char *stream,
  1016. char *ends, struct iw_event *iwe, char *extra)
  1017. {
  1018. int event_len = iwe_stream_point_len(info) + iwe->u.data.length;
  1019. int point_len = iwe_stream_point_len(info);
  1020. int lcp_len = iwe_stream_lcp_len(info);
  1021. /* Check if it's possible */
  1022. if (likely((stream + event_len) < ends)) {
  1023. iwe->len = event_len;
  1024. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  1025. memcpy(stream + lcp_len,
  1026. ((char *) &iwe->u) + IW_EV_POINT_OFF,
  1027. IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
  1028. if (iwe->u.data.length && extra)
  1029. memcpy(stream + point_len, extra, iwe->u.data.length);
  1030. stream += event_len;
  1031. }
  1032. return stream;
  1033. }
  1034. EXPORT_SYMBOL(iwe_stream_add_point);
  1035. char *iwe_stream_add_value(struct iw_request_info *info, char *event,
  1036. char *value, char *ends, struct iw_event *iwe,
  1037. int event_len)
  1038. {
  1039. int lcp_len = iwe_stream_lcp_len(info);
  1040. /* Don't duplicate LCP */
  1041. event_len -= IW_EV_LCP_LEN;
  1042. /* Check if it's possible */
  1043. if (likely((value + event_len) < ends)) {
  1044. /* Add new value */
  1045. memcpy(value, &iwe->u, event_len);
  1046. value += event_len;
  1047. /* Patch LCP */
  1048. iwe->len = value - event;
  1049. memcpy(event, (char *) iwe, lcp_len);
  1050. }
  1051. return value;
  1052. }
  1053. EXPORT_SYMBOL(iwe_stream_add_value);