wext-core.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. static int iw_handler_get_iwstats(struct net_device * dev,
  609. struct iw_request_info * info,
  610. union iwreq_data * wrqu,
  611. char * extra)
  612. {
  613. /* Get stats from the driver */
  614. struct iw_statistics *stats;
  615. stats = get_wireless_stats(dev);
  616. if (stats) {
  617. /* Copy statistics to extra */
  618. memcpy(extra, stats, sizeof(struct iw_statistics));
  619. wrqu->data.length = sizeof(struct iw_statistics);
  620. /* Check if we need to clear the updated flag */
  621. if (wrqu->data.flags != 0)
  622. stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
  623. return 0;
  624. } else
  625. return -EOPNOTSUPP;
  626. }
  627. static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
  628. {
  629. /* Don't "optimise" the following variable, it will crash */
  630. unsigned int index; /* *MUST* be unsigned */
  631. const struct iw_handler_def *handlers = NULL;
  632. #ifdef CONFIG_CFG80211_WEXT
  633. if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy)
  634. handlers = dev->ieee80211_ptr->wiphy->wext;
  635. #endif
  636. #ifdef CONFIG_WIRELESS_EXT
  637. if (dev->wireless_handlers)
  638. handlers = dev->wireless_handlers;
  639. #endif
  640. if (!handlers)
  641. return NULL;
  642. /* Try as a standard command */
  643. index = IW_IOCTL_IDX(cmd);
  644. if (index < handlers->num_standard)
  645. return handlers->standard[index];
  646. #ifdef CONFIG_WEXT_PRIV
  647. /* Try as a private command */
  648. index = cmd - SIOCIWFIRSTPRIV;
  649. if (index < handlers->num_private)
  650. return handlers->private[index];
  651. #endif
  652. /* Not found */
  653. return NULL;
  654. }
  655. static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
  656. const struct iw_ioctl_description *descr,
  657. iw_handler handler, struct net_device *dev,
  658. struct iw_request_info *info)
  659. {
  660. int err, extra_size, user_length = 0, essid_compat = 0;
  661. char *extra;
  662. /* Calculate space needed by arguments. Always allocate
  663. * for max space.
  664. */
  665. extra_size = descr->max_tokens * descr->token_size;
  666. /* Check need for ESSID compatibility for WE < 21 */
  667. switch (cmd) {
  668. case SIOCSIWESSID:
  669. case SIOCGIWESSID:
  670. case SIOCSIWNICKN:
  671. case SIOCGIWNICKN:
  672. if (iwp->length == descr->max_tokens + 1)
  673. essid_compat = 1;
  674. else if (IW_IS_SET(cmd) && (iwp->length != 0)) {
  675. char essid[IW_ESSID_MAX_SIZE + 1];
  676. unsigned int len;
  677. len = iwp->length * descr->token_size;
  678. if (len > IW_ESSID_MAX_SIZE)
  679. return -EFAULT;
  680. err = copy_from_user(essid, iwp->pointer, len);
  681. if (err)
  682. return -EFAULT;
  683. if (essid[iwp->length - 1] == '\0')
  684. essid_compat = 1;
  685. }
  686. break;
  687. default:
  688. break;
  689. }
  690. iwp->length -= essid_compat;
  691. /* Check what user space is giving us */
  692. if (IW_IS_SET(cmd)) {
  693. /* Check NULL pointer */
  694. if (!iwp->pointer && iwp->length != 0)
  695. return -EFAULT;
  696. /* Check if number of token fits within bounds */
  697. if (iwp->length > descr->max_tokens)
  698. return -E2BIG;
  699. if (iwp->length < descr->min_tokens)
  700. return -EINVAL;
  701. } else {
  702. /* Check NULL pointer */
  703. if (!iwp->pointer)
  704. return -EFAULT;
  705. /* Save user space buffer size for checking */
  706. user_length = iwp->length;
  707. /* Don't check if user_length > max to allow forward
  708. * compatibility. The test user_length < min is
  709. * implied by the test at the end.
  710. */
  711. /* Support for very large requests */
  712. if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
  713. (user_length > descr->max_tokens)) {
  714. /* Allow userspace to GET more than max so
  715. * we can support any size GET requests.
  716. * There is still a limit : -ENOMEM.
  717. */
  718. extra_size = user_length * descr->token_size;
  719. /* Note : user_length is originally a __u16,
  720. * and token_size is controlled by us,
  721. * so extra_size won't get negative and
  722. * won't overflow...
  723. */
  724. }
  725. }
  726. /* kzalloc() ensures NULL-termination for essid_compat. */
  727. extra = kzalloc(extra_size, GFP_KERNEL);
  728. if (!extra)
  729. return -ENOMEM;
  730. /* If it is a SET, get all the extra data in here */
  731. if (IW_IS_SET(cmd) && (iwp->length != 0)) {
  732. if (copy_from_user(extra, iwp->pointer,
  733. iwp->length *
  734. descr->token_size)) {
  735. err = -EFAULT;
  736. goto out;
  737. }
  738. if (cmd == SIOCSIWENCODEEXT) {
  739. struct iw_encode_ext *ee = (void *) extra;
  740. if (iwp->length < sizeof(*ee) + ee->key_len) {
  741. err = -EFAULT;
  742. goto out;
  743. }
  744. }
  745. }
  746. if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
  747. /*
  748. * If this is a GET, but not NOMAX, it means that the extra
  749. * data is not bounded by userspace, but by max_tokens. Thus
  750. * set the length to max_tokens. This matches the extra data
  751. * allocation.
  752. * The driver should fill it with the number of tokens it
  753. * provided, and it may check iwp->length rather than having
  754. * knowledge of max_tokens. If the driver doesn't change the
  755. * iwp->length, this ioctl just copies back max_token tokens
  756. * filled with zeroes. Hopefully the driver isn't claiming
  757. * them to be valid data.
  758. */
  759. iwp->length = descr->max_tokens;
  760. }
  761. err = handler(dev, info, (union iwreq_data *) iwp, extra);
  762. iwp->length += essid_compat;
  763. /* If we have something to return to the user */
  764. if (!err && IW_IS_GET(cmd)) {
  765. /* Check if there is enough buffer up there */
  766. if (user_length < iwp->length) {
  767. err = -E2BIG;
  768. goto out;
  769. }
  770. if (copy_to_user(iwp->pointer, extra,
  771. iwp->length *
  772. descr->token_size)) {
  773. err = -EFAULT;
  774. goto out;
  775. }
  776. }
  777. /* Generate an event to notify listeners of the change */
  778. if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
  779. ((err == 0) || (err == -EIWCOMMIT))) {
  780. union iwreq_data *data = (union iwreq_data *) iwp;
  781. if (descr->flags & IW_DESCR_FLAG_RESTRICT)
  782. /* If the event is restricted, don't
  783. * export the payload.
  784. */
  785. wireless_send_event(dev, cmd, data, NULL);
  786. else
  787. wireless_send_event(dev, cmd, data, extra);
  788. }
  789. out:
  790. kfree(extra);
  791. return err;
  792. }
  793. /*
  794. * Call the commit handler in the driver
  795. * (if exist and if conditions are right)
  796. *
  797. * Note : our current commit strategy is currently pretty dumb,
  798. * but we will be able to improve on that...
  799. * The goal is to try to agreagate as many changes as possible
  800. * before doing the commit. Drivers that will define a commit handler
  801. * are usually those that need a reset after changing parameters, so
  802. * we want to minimise the number of reset.
  803. * A cool idea is to use a timer : at each "set" command, we re-set the
  804. * timer, when the timer eventually fires, we call the driver.
  805. * Hopefully, more on that later.
  806. *
  807. * Also, I'm waiting to see how many people will complain about the
  808. * netif_running(dev) test. I'm open on that one...
  809. * Hopefully, the driver will remember to do a commit in "open()" ;-)
  810. */
  811. int call_commit_handler(struct net_device *dev)
  812. {
  813. #ifdef CONFIG_WIRELESS_EXT
  814. if ((netif_running(dev)) &&
  815. (dev->wireless_handlers->standard[0] != NULL))
  816. /* Call the commit handler on the driver */
  817. return dev->wireless_handlers->standard[0](dev, NULL,
  818. NULL, NULL);
  819. else
  820. return 0; /* Command completed successfully */
  821. #else
  822. /* cfg80211 has no commit */
  823. return 0;
  824. #endif
  825. }
  826. /*
  827. * Main IOCTl dispatcher.
  828. * Check the type of IOCTL and call the appropriate wrapper...
  829. */
  830. static int wireless_process_ioctl(struct net *net, struct iwreq *iwr,
  831. unsigned int cmd,
  832. struct iw_request_info *info,
  833. wext_ioctl_func standard,
  834. wext_ioctl_func private)
  835. {
  836. struct net_device *dev;
  837. iw_handler handler;
  838. /* Permissions are already checked in dev_ioctl() before calling us.
  839. * The copy_to/from_user() of ifr is also dealt with in there */
  840. /* Make sure the device exist */
  841. if ((dev = __dev_get_by_name(net, iwr->ifr_name)) == NULL)
  842. return -ENODEV;
  843. /* A bunch of special cases, then the generic case...
  844. * Note that 'cmd' is already filtered in dev_ioctl() with
  845. * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
  846. if (cmd == SIOCGIWSTATS)
  847. return standard(dev, iwr, cmd, info,
  848. &iw_handler_get_iwstats);
  849. #ifdef CONFIG_WEXT_PRIV
  850. if (cmd == SIOCGIWPRIV && dev->wireless_handlers)
  851. return standard(dev, iwr, cmd, info,
  852. iw_handler_get_private);
  853. #endif
  854. /* Basic check */
  855. if (!netif_device_present(dev))
  856. return -ENODEV;
  857. /* New driver API : try to find the handler */
  858. handler = get_handler(dev, cmd);
  859. if (handler) {
  860. /* Standard and private are not the same */
  861. if (cmd < SIOCIWFIRSTPRIV)
  862. return standard(dev, iwr, cmd, info, handler);
  863. else if (private)
  864. return private(dev, iwr, cmd, info, handler);
  865. }
  866. return -EOPNOTSUPP;
  867. }
  868. /* If command is `set a parameter', or `get the encoding parameters',
  869. * check if the user has the right to do it.
  870. */
  871. static int wext_permission_check(unsigned int cmd)
  872. {
  873. if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE ||
  874. cmd == SIOCGIWENCODEEXT) &&
  875. !capable(CAP_NET_ADMIN))
  876. return -EPERM;
  877. return 0;
  878. }
  879. /* entry point from dev ioctl */
  880. static int wext_ioctl_dispatch(struct net *net, struct iwreq *iwr,
  881. unsigned int cmd, struct iw_request_info *info,
  882. wext_ioctl_func standard,
  883. wext_ioctl_func private)
  884. {
  885. int ret = wext_permission_check(cmd);
  886. if (ret)
  887. return ret;
  888. dev_load(net, iwr->ifr_name);
  889. rtnl_lock();
  890. ret = wireless_process_ioctl(net, iwr, cmd, info, standard, private);
  891. rtnl_unlock();
  892. return ret;
  893. }
  894. /*
  895. * Wrapper to call a standard Wireless Extension handler.
  896. * We do various checks and also take care of moving data between
  897. * user space and kernel space.
  898. */
  899. static int ioctl_standard_call(struct net_device * dev,
  900. struct iwreq *iwr,
  901. unsigned int cmd,
  902. struct iw_request_info *info,
  903. iw_handler handler)
  904. {
  905. const struct iw_ioctl_description * descr;
  906. int ret = -EINVAL;
  907. /* Get the description of the IOCTL */
  908. if (IW_IOCTL_IDX(cmd) >= standard_ioctl_num)
  909. return -EOPNOTSUPP;
  910. descr = &(standard_ioctl[IW_IOCTL_IDX(cmd)]);
  911. /* Check if we have a pointer to user space data or not */
  912. if (descr->header_type != IW_HEADER_TYPE_POINT) {
  913. /* No extra arguments. Trivial to handle */
  914. ret = handler(dev, info, &(iwr->u), NULL);
  915. /* Generate an event to notify listeners of the change */
  916. if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
  917. ((ret == 0) || (ret == -EIWCOMMIT)))
  918. wireless_send_event(dev, cmd, &(iwr->u), NULL);
  919. } else {
  920. ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr,
  921. handler, dev, info);
  922. }
  923. /* Call commit handler if needed and defined */
  924. if (ret == -EIWCOMMIT)
  925. ret = call_commit_handler(dev);
  926. /* Here, we will generate the appropriate event if needed */
  927. return ret;
  928. }
  929. int wext_handle_ioctl(struct net *net, unsigned int cmd, void __user *arg)
  930. {
  931. struct iw_request_info info = { .cmd = cmd, .flags = 0 };
  932. struct iwreq iwr;
  933. int ret;
  934. if (copy_from_user(&iwr, arg, sizeof(iwr)))
  935. return -EFAULT;
  936. iwr.ifr_name[sizeof(iwr.ifr_name) - 1] = 0;
  937. ret = wext_ioctl_dispatch(net, &iwr, cmd, &info,
  938. ioctl_standard_call,
  939. ioctl_private_call);
  940. if (ret >= 0 &&
  941. IW_IS_GET(cmd) &&
  942. copy_to_user(arg, &iwr, sizeof(struct iwreq)))
  943. return -EFAULT;
  944. return ret;
  945. }
  946. #ifdef CONFIG_COMPAT
  947. static int compat_standard_call(struct net_device *dev,
  948. struct iwreq *iwr,
  949. unsigned int cmd,
  950. struct iw_request_info *info,
  951. iw_handler handler)
  952. {
  953. const struct iw_ioctl_description *descr;
  954. struct compat_iw_point *iwp_compat;
  955. struct iw_point iwp;
  956. int err;
  957. descr = standard_ioctl + IW_IOCTL_IDX(cmd);
  958. if (descr->header_type != IW_HEADER_TYPE_POINT)
  959. return ioctl_standard_call(dev, iwr, cmd, info, handler);
  960. iwp_compat = (struct compat_iw_point *) &iwr->u.data;
  961. iwp.pointer = compat_ptr(iwp_compat->pointer);
  962. iwp.length = iwp_compat->length;
  963. iwp.flags = iwp_compat->flags;
  964. err = ioctl_standard_iw_point(&iwp, cmd, descr, handler, dev, info);
  965. iwp_compat->pointer = ptr_to_compat(iwp.pointer);
  966. iwp_compat->length = iwp.length;
  967. iwp_compat->flags = iwp.flags;
  968. return err;
  969. }
  970. int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
  971. unsigned long arg)
  972. {
  973. void __user *argp = (void __user *)arg;
  974. struct iw_request_info info;
  975. struct iwreq iwr;
  976. char *colon;
  977. int ret;
  978. if (copy_from_user(&iwr, argp, sizeof(struct iwreq)))
  979. return -EFAULT;
  980. iwr.ifr_name[IFNAMSIZ-1] = 0;
  981. colon = strchr(iwr.ifr_name, ':');
  982. if (colon)
  983. *colon = 0;
  984. info.cmd = cmd;
  985. info.flags = IW_REQUEST_FLAG_COMPAT;
  986. ret = wext_ioctl_dispatch(net, &iwr, cmd, &info,
  987. compat_standard_call,
  988. compat_private_call);
  989. if (ret >= 0 &&
  990. IW_IS_GET(cmd) &&
  991. copy_to_user(argp, &iwr, sizeof(struct iwreq)))
  992. return -EFAULT;
  993. return ret;
  994. }
  995. #endif
  996. char *iwe_stream_add_event(struct iw_request_info *info, char *stream,
  997. char *ends, struct iw_event *iwe, int event_len)
  998. {
  999. int lcp_len = iwe_stream_lcp_len(info);
  1000. event_len = iwe_stream_event_len_adjust(info, event_len);
  1001. /* Check if it's possible */
  1002. if (likely((stream + event_len) < ends)) {
  1003. iwe->len = event_len;
  1004. /* Beware of alignement issues on 64 bits */
  1005. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  1006. memcpy(stream + lcp_len, &iwe->u,
  1007. event_len - lcp_len);
  1008. stream += event_len;
  1009. }
  1010. return stream;
  1011. }
  1012. EXPORT_SYMBOL(iwe_stream_add_event);
  1013. char *iwe_stream_add_point(struct iw_request_info *info, char *stream,
  1014. char *ends, struct iw_event *iwe, char *extra)
  1015. {
  1016. int event_len = iwe_stream_point_len(info) + iwe->u.data.length;
  1017. int point_len = iwe_stream_point_len(info);
  1018. int lcp_len = iwe_stream_lcp_len(info);
  1019. /* Check if it's possible */
  1020. if (likely((stream + event_len) < ends)) {
  1021. iwe->len = event_len;
  1022. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  1023. memcpy(stream + lcp_len,
  1024. ((char *) &iwe->u) + IW_EV_POINT_OFF,
  1025. IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
  1026. if (iwe->u.data.length && extra)
  1027. memcpy(stream + point_len, extra, iwe->u.data.length);
  1028. stream += event_len;
  1029. }
  1030. return stream;
  1031. }
  1032. EXPORT_SYMBOL(iwe_stream_add_point);
  1033. char *iwe_stream_add_value(struct iw_request_info *info, char *event,
  1034. char *value, char *ends, struct iw_event *iwe,
  1035. int event_len)
  1036. {
  1037. int lcp_len = iwe_stream_lcp_len(info);
  1038. /* Don't duplicate LCP */
  1039. event_len -= IW_EV_LCP_LEN;
  1040. /* Check if it's possible */
  1041. if (likely((value + event_len) < ends)) {
  1042. /* Add new value */
  1043. memcpy(value, &iwe->u, event_len);
  1044. value += event_len;
  1045. /* Patch LCP */
  1046. iwe->len = value - event;
  1047. memcpy(event, (char *) iwe, lcp_len);
  1048. }
  1049. return value;
  1050. }
  1051. EXPORT_SYMBOL(iwe_stream_add_value);