iw_handler.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. * This file define the new driver API for Wireless Extensions
  3. *
  4. * Version : 8 16.3.07
  5. *
  6. * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
  7. * Copyright (c) 2001-2007 Jean Tourrilhes, All Rights Reserved.
  8. */
  9. #ifndef _IW_HANDLER_H
  10. #define _IW_HANDLER_H
  11. /************************** DOCUMENTATION **************************/
  12. /*
  13. * Initial driver API (1996 -> onward) :
  14. * -----------------------------------
  15. * The initial API just sends the IOCTL request received from user space
  16. * to the driver (via the driver ioctl handler). The driver has to
  17. * handle all the rest...
  18. *
  19. * The initial API also defines a specific handler in struct net_device
  20. * to handle wireless statistics.
  21. *
  22. * The initial APIs served us well and has proven a reasonably good design.
  23. * However, there is a few shortcommings :
  24. * o No events, everything is a request to the driver.
  25. * o Large ioctl function in driver with gigantic switch statement
  26. * (i.e. spaghetti code).
  27. * o Driver has to mess up with copy_to/from_user, and in many cases
  28. * does it unproperly. Common mistakes are :
  29. * * buffer overflows (no checks or off by one checks)
  30. * * call copy_to/from_user with irq disabled
  31. * o The user space interface is tied to ioctl because of the use
  32. * copy_to/from_user.
  33. *
  34. * New driver API (2002 -> onward) :
  35. * -------------------------------
  36. * The new driver API is just a bunch of standard functions (handlers),
  37. * each handling a specific Wireless Extension. The driver just export
  38. * the list of handler it supports, and those will be called apropriately.
  39. *
  40. * I tried to keep the main advantage of the previous API (simplicity,
  41. * efficiency and light weight), and also I provide a good dose of backward
  42. * compatibility (most structures are the same, driver can use both API
  43. * simultaneously, ...).
  44. * Hopefully, I've also addressed the shortcomming of the initial API.
  45. *
  46. * The advantage of the new API are :
  47. * o Handling of Extensions in driver broken in small contained functions
  48. * o Tighter checks of ioctl before calling the driver
  49. * o Flexible commit strategy (at least, the start of it)
  50. * o Backward compatibility (can be mixed with old API)
  51. * o Driver doesn't have to worry about memory and user-space issues
  52. * The last point is important for the following reasons :
  53. * o You are now able to call the new driver API from any API you
  54. * want (including from within other parts of the kernel).
  55. * o Common mistakes are avoided (buffer overflow, user space copy
  56. * with irq disabled and so on).
  57. *
  58. * The Drawback of the new API are :
  59. * o bloat (especially kernel)
  60. * o need to migrate existing drivers to new API
  61. * My initial testing shows that the new API adds around 3kB to the kernel
  62. * and save between 0 and 5kB from a typical driver.
  63. * Also, as all structures and data types are unchanged, the migration is
  64. * quite straightforward (but tedious).
  65. *
  66. * ---
  67. *
  68. * The new driver API is defined below in this file. User space should
  69. * not be aware of what's happening down there...
  70. *
  71. * A new kernel wrapper is in charge of validating the IOCTLs and calling
  72. * the appropriate driver handler. This is implemented in :
  73. * # net/core/wireless.c
  74. *
  75. * The driver export the list of handlers in :
  76. * # include/linux/netdevice.h (one place)
  77. *
  78. * The new driver API is available for WIRELESS_EXT >= 13.
  79. * Good luck with migration to the new API ;-)
  80. */
  81. /* ---------------------- THE IMPLEMENTATION ---------------------- */
  82. /*
  83. * Some of the choice I've made are pretty controversials. Defining an
  84. * API is very much weighting compromises. This goes into some of the
  85. * details and the thinking behind the implementation.
  86. *
  87. * Implementation goals :
  88. * --------------------
  89. * The implementation goals were as follow :
  90. * o Obvious : you should not need a PhD to understand what's happening,
  91. * the benefit is easier maintenance.
  92. * o Flexible : it should accommodate a wide variety of driver
  93. * implementations and be as flexible as the old API.
  94. * o Lean : it should be efficient memory wise to minimise the impact
  95. * on kernel footprint.
  96. * o Transparent to user space : the large number of user space
  97. * applications that use Wireless Extensions should not need
  98. * any modifications.
  99. *
  100. * Array of functions versus Struct of functions
  101. * ---------------------------------------------
  102. * 1) Having an array of functions allow the kernel code to access the
  103. * handler in a single lookup, which is much more efficient (think hash
  104. * table here).
  105. * 2) The only drawback is that driver writer may put their handler in
  106. * the wrong slot. This is trivial to test (I set the frequency, the
  107. * bitrate changes). Once the handler is in the proper slot, it will be
  108. * there forever, because the array is only extended at the end.
  109. * 3) Backward/forward compatibility : adding new handler just require
  110. * extending the array, so you can put newer driver in older kernel
  111. * without having to patch the kernel code (and vice versa).
  112. *
  113. * All handler are of the same generic type
  114. * ----------------------------------------
  115. * That's a feature !!!
  116. * 1) Having a generic handler allow to have generic code, which is more
  117. * efficient. If each of the handler was individually typed I would need
  118. * to add a big switch in the kernel (== more bloat). This solution is
  119. * more scalable, adding new Wireless Extensions doesn't add new code.
  120. * 2) You can use the same handler in different slots of the array. For
  121. * hardware, it may be more efficient or logical to handle multiple
  122. * Wireless Extensions with a single function, and the API allow you to
  123. * do that. (An example would be a single record on the card to control
  124. * both bitrate and frequency, the handler would read the old record,
  125. * modify it according to info->cmd and rewrite it).
  126. *
  127. * Functions prototype uses union iwreq_data
  128. * -----------------------------------------
  129. * Some would have preferred functions defined this way :
  130. * static int mydriver_ioctl_setrate(struct net_device *dev,
  131. * long rate, int auto)
  132. * 1) The kernel code doesn't "validate" the content of iwreq_data, and
  133. * can't do it (different hardware may have different notion of what a
  134. * valid frequency is), so we don't pretend that we do it.
  135. * 2) The above form is not extendable. If I want to add a flag (for
  136. * example to distinguish setting max rate and basic rate), I would
  137. * break the prototype. Using iwreq_data is more flexible.
  138. * 3) Also, the above form is not generic (see above).
  139. * 4) I don't expect driver developper using the wrong field of the
  140. * union (Doh !), so static typechecking doesn't add much value.
  141. * 5) Lastly, you can skip the union by doing :
  142. * static int mydriver_ioctl_setrate(struct net_device *dev,
  143. * struct iw_request_info *info,
  144. * struct iw_param *rrq,
  145. * char *extra)
  146. * And then adding the handler in the array like this :
  147. * (iw_handler) mydriver_ioctl_setrate, // SIOCSIWRATE
  148. *
  149. * Using functions and not a registry
  150. * ----------------------------------
  151. * Another implementation option would have been for every instance to
  152. * define a registry (a struct containing all the Wireless Extensions)
  153. * and only have a function to commit the registry to the hardware.
  154. * 1) This approach can be emulated by the current code, but not
  155. * vice versa.
  156. * 2) Some drivers don't keep any configuration in the driver, for them
  157. * adding such a registry would be a significant bloat.
  158. * 3) The code to translate from Wireless Extension to native format is
  159. * needed anyway, so it would not reduce significantely the amount of code.
  160. * 4) The current approach only selectively translate Wireless Extensions
  161. * to native format and only selectively set, whereas the registry approach
  162. * would require to translate all WE and set all parameters for any single
  163. * change.
  164. * 5) For many Wireless Extensions, the GET operation return the current
  165. * dynamic value, not the value that was set.
  166. *
  167. * This header is <net/iw_handler.h>
  168. * ---------------------------------
  169. * 1) This header is kernel space only and should not be exported to
  170. * user space. Headers in "include/linux/" are exported, headers in
  171. * "include/net/" are not.
  172. *
  173. * Mixed 32/64 bit issues
  174. * ----------------------
  175. * The Wireless Extensions are designed to be 64 bit clean, by using only
  176. * datatypes with explicit storage size.
  177. * There are some issues related to kernel and user space using different
  178. * memory model, and in particular 64bit kernel with 32bit user space.
  179. * The problem is related to struct iw_point, that contains a pointer
  180. * that *may* need to be translated.
  181. * This is quite messy. The new API doesn't solve this problem (it can't),
  182. * but is a step in the right direction :
  183. * 1) Meta data about each ioctl is easily available, so we know what type
  184. * of translation is needed.
  185. * 2) The move of data between kernel and user space is only done in a single
  186. * place in the kernel, so adding specific hooks in there is possible.
  187. * 3) In the long term, it allows to move away from using ioctl as the
  188. * user space API.
  189. *
  190. * So many comments and so few code
  191. * --------------------------------
  192. * That's a feature. Comments won't bloat the resulting kernel binary.
  193. */
  194. /***************************** INCLUDES *****************************/
  195. #include <linux/wireless.h> /* IOCTL user space API */
  196. #include <linux/if_ether.h>
  197. /***************************** VERSION *****************************/
  198. /*
  199. * This constant is used to know which version of the driver API is
  200. * available. Hopefully, this will be pretty stable and no changes
  201. * will be needed...
  202. * I just plan to increment with each new version.
  203. */
  204. #define IW_HANDLER_VERSION 8
  205. /*
  206. * Changes :
  207. *
  208. * V2 to V3
  209. * --------
  210. * - Move event definition in <linux/wireless.h>
  211. * - Add Wireless Event support :
  212. * o wireless_send_event() prototype
  213. * o iwe_stream_add_event/point() inline functions
  214. * V3 to V4
  215. * --------
  216. * - Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
  217. *
  218. * V4 to V5
  219. * --------
  220. * - Add new spy support : struct iw_spy_data & prototypes
  221. *
  222. * V5 to V6
  223. * --------
  224. * - Change the way we get to spy_data method for added safety
  225. * - Remove spy #ifdef, they are always on -> cleaner code
  226. * - Add IW_DESCR_FLAG_NOMAX flag for very large requests
  227. * - Start migrating get_wireless_stats to struct iw_handler_def
  228. *
  229. * V6 to V7
  230. * --------
  231. * - Add struct ieee80211_device pointer in struct iw_public_data
  232. * - Remove (struct iw_point *)->pointer from events and streams
  233. * - Remove spy_offset from struct iw_handler_def
  234. * - Add "check" version of event macros for ieee802.11 stack
  235. *
  236. * V7 to V8
  237. * ----------
  238. * - Prevent leaking of kernel space in stream on 64 bits.
  239. */
  240. /**************************** CONSTANTS ****************************/
  241. /* Enhanced spy support available */
  242. #define IW_WIRELESS_SPY
  243. #define IW_WIRELESS_THRSPY
  244. /* Special error message for the driver to indicate that we
  245. * should do a commit after return from the iw_handler */
  246. #define EIWCOMMIT EINPROGRESS
  247. /* Flags available in struct iw_request_info */
  248. #define IW_REQUEST_FLAG_COMPAT 0x0001 /* Compat ioctl call */
  249. /* Type of headers we know about (basically union iwreq_data) */
  250. #define IW_HEADER_TYPE_NULL 0 /* Not available */
  251. #define IW_HEADER_TYPE_CHAR 2 /* char [IFNAMSIZ] */
  252. #define IW_HEADER_TYPE_UINT 4 /* __u32 */
  253. #define IW_HEADER_TYPE_FREQ 5 /* struct iw_freq */
  254. #define IW_HEADER_TYPE_ADDR 6 /* struct sockaddr */
  255. #define IW_HEADER_TYPE_POINT 8 /* struct iw_point */
  256. #define IW_HEADER_TYPE_PARAM 9 /* struct iw_param */
  257. #define IW_HEADER_TYPE_QUAL 10 /* struct iw_quality */
  258. /* Handling flags */
  259. /* Most are not implemented. I just use them as a reminder of some
  260. * cool features we might need one day ;-) */
  261. #define IW_DESCR_FLAG_NONE 0x0000 /* Obvious */
  262. /* Wrapper level flags */
  263. #define IW_DESCR_FLAG_DUMP 0x0001 /* Not part of the dump command */
  264. #define IW_DESCR_FLAG_EVENT 0x0002 /* Generate an event on SET */
  265. #define IW_DESCR_FLAG_RESTRICT 0x0004 /* GET : request is ROOT only */
  266. /* SET : Omit payload from generated iwevent */
  267. #define IW_DESCR_FLAG_NOMAX 0x0008 /* GET : no limit on request size */
  268. /* Driver level flags */
  269. #define IW_DESCR_FLAG_WAIT 0x0100 /* Wait for driver event */
  270. /****************************** TYPES ******************************/
  271. /* ----------------------- WIRELESS HANDLER ----------------------- */
  272. /*
  273. * A wireless handler is just a standard function, that looks like the
  274. * ioctl handler.
  275. * We also define there how a handler list look like... As the Wireless
  276. * Extension space is quite dense, we use a simple array, which is faster
  277. * (that's the perfect hash table ;-).
  278. */
  279. /*
  280. * Meta data about the request passed to the iw_handler.
  281. * Most handlers can safely ignore what's in there.
  282. * The 'cmd' field might come handy if you want to use the same handler
  283. * for multiple command...
  284. * This struct is also my long term insurance. I can add new fields here
  285. * without breaking the prototype of iw_handler...
  286. */
  287. struct iw_request_info {
  288. __u16 cmd; /* Wireless Extension command */
  289. __u16 flags; /* More to come ;-) */
  290. };
  291. struct net_device;
  292. /*
  293. * This is how a function handling a Wireless Extension should look
  294. * like (both get and set, standard and private).
  295. */
  296. typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
  297. union iwreq_data *wrqu, char *extra);
  298. /*
  299. * This define all the handler that the driver export.
  300. * As you need only one per driver type, please use a static const
  301. * shared by all driver instances... Same for the members...
  302. * This will be linked from net_device in <linux/netdevice.h>
  303. */
  304. struct iw_handler_def {
  305. /* Array of handlers for standard ioctls
  306. * We will call dev->wireless_handlers->standard[ioctl - SIOCIWFIRST]
  307. */
  308. const iw_handler * standard;
  309. /* Number of handlers defined (more precisely, index of the
  310. * last defined handler + 1) */
  311. __u16 num_standard;
  312. #ifdef CONFIG_WEXT_PRIV
  313. __u16 num_private;
  314. /* Number of private arg description */
  315. __u16 num_private_args;
  316. /* Array of handlers for private ioctls
  317. * Will call dev->wireless_handlers->private[ioctl - SIOCIWFIRSTPRIV]
  318. */
  319. const iw_handler * private;
  320. /* Arguments of private handler. This one is just a list, so you
  321. * can put it in any order you want and should not leave holes...
  322. * We will automatically export that to user space... */
  323. const struct iw_priv_args * private_args;
  324. #endif
  325. /* New location of get_wireless_stats, to de-bloat struct net_device.
  326. * The old pointer in struct net_device will be gradually phased
  327. * out, and drivers are encouraged to use this one... */
  328. struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
  329. };
  330. /* ---------------------- IOCTL DESCRIPTION ---------------------- */
  331. /*
  332. * One of the main goal of the new interface is to deal entirely with
  333. * user space/kernel space memory move.
  334. * For that, we need to know :
  335. * o if iwreq is a pointer or contain the full data
  336. * o what is the size of the data to copy
  337. *
  338. * For private IOCTLs, we use the same rules as used by iwpriv and
  339. * defined in struct iw_priv_args.
  340. *
  341. * For standard IOCTLs, things are quite different and we need to
  342. * use the stuctures below. Actually, this struct is also more
  343. * efficient, but that's another story...
  344. */
  345. /*
  346. * Describe how a standard IOCTL looks like.
  347. */
  348. struct iw_ioctl_description {
  349. __u8 header_type; /* NULL, iw_point or other */
  350. __u8 token_type; /* Future */
  351. __u16 token_size; /* Granularity of payload */
  352. __u16 min_tokens; /* Min acceptable token number */
  353. __u16 max_tokens; /* Max acceptable token number */
  354. __u32 flags; /* Special handling of the request */
  355. };
  356. /* Need to think of short header translation table. Later. */
  357. /* --------------------- ENHANCED SPY SUPPORT --------------------- */
  358. /*
  359. * In the old days, the driver was handling spy support all by itself.
  360. * Now, the driver can delegate this task to Wireless Extensions.
  361. * It needs to include this struct in its private part and use the
  362. * standard spy iw_handler.
  363. */
  364. /*
  365. * Instance specific spy data, i.e. addresses spied and quality for them.
  366. */
  367. struct iw_spy_data {
  368. /* --- Standard spy support --- */
  369. int spy_number;
  370. u_char spy_address[IW_MAX_SPY][ETH_ALEN];
  371. struct iw_quality spy_stat[IW_MAX_SPY];
  372. /* --- Enhanced spy support (event) */
  373. struct iw_quality spy_thr_low; /* Low threshold */
  374. struct iw_quality spy_thr_high; /* High threshold */
  375. u_char spy_thr_under[IW_MAX_SPY];
  376. };
  377. /* --------------------- DEVICE WIRELESS DATA --------------------- */
  378. /*
  379. * This is all the wireless data specific to a device instance that
  380. * is managed by the core of Wireless Extensions or the 802.11 layer.
  381. * We only keep pointer to those structures, so that a driver is free
  382. * to share them between instances.
  383. * This structure should be initialised before registering the device.
  384. * Access to this data follow the same rules as any other struct net_device
  385. * data (i.e. valid as long as struct net_device exist, same locking rules).
  386. */
  387. /* Forward declaration */
  388. struct libipw_device;
  389. /* The struct */
  390. struct iw_public_data {
  391. /* Driver enhanced spy support */
  392. struct iw_spy_data * spy_data;
  393. /* Legacy structure managed by the ipw2x00-specific IEEE 802.11 layer */
  394. struct libipw_device * libipw;
  395. };
  396. /**************************** PROTOTYPES ****************************/
  397. /*
  398. * Functions part of the Wireless Extensions (defined in net/core/wireless.c).
  399. * Those may be called only within the kernel.
  400. */
  401. /* First : function strictly used inside the kernel */
  402. /* Handle /proc/net/wireless, called in net/code/dev.c */
  403. int dev_get_wireless_info(char *buffer, char **start, off_t offset, int length);
  404. /* Second : functions that may be called by driver modules */
  405. /* Send a single event to user space */
  406. void wireless_send_event(struct net_device *dev, unsigned int cmd,
  407. union iwreq_data *wrqu, const char *extra);
  408. #ifdef CONFIG_WEXT_CORE
  409. /* flush all previous wext events - if work is done from netdev notifiers */
  410. void wireless_nlevent_flush(void);
  411. #else
  412. static inline void wireless_nlevent_flush(void) {}
  413. #endif
  414. /* We may need a function to send a stream of events to user space.
  415. * More on that later... */
  416. /* Standard handler for SIOCSIWSPY */
  417. int iw_handler_set_spy(struct net_device *dev, struct iw_request_info *info,
  418. union iwreq_data *wrqu, char *extra);
  419. /* Standard handler for SIOCGIWSPY */
  420. int iw_handler_get_spy(struct net_device *dev, struct iw_request_info *info,
  421. union iwreq_data *wrqu, char *extra);
  422. /* Standard handler for SIOCSIWTHRSPY */
  423. int iw_handler_set_thrspy(struct net_device *dev, struct iw_request_info *info,
  424. union iwreq_data *wrqu, char *extra);
  425. /* Standard handler for SIOCGIWTHRSPY */
  426. int iw_handler_get_thrspy(struct net_device *dev, struct iw_request_info *info,
  427. union iwreq_data *wrqu, char *extra);
  428. /* Driver call to update spy records */
  429. void wireless_spy_update(struct net_device *dev, unsigned char *address,
  430. struct iw_quality *wstats);
  431. /************************* INLINE FUNTIONS *************************/
  432. /*
  433. * Function that are so simple that it's more efficient inlining them
  434. */
  435. static inline int iwe_stream_lcp_len(struct iw_request_info *info)
  436. {
  437. #ifdef CONFIG_COMPAT
  438. if (info->flags & IW_REQUEST_FLAG_COMPAT)
  439. return IW_EV_COMPAT_LCP_LEN;
  440. #endif
  441. return IW_EV_LCP_LEN;
  442. }
  443. static inline int iwe_stream_point_len(struct iw_request_info *info)
  444. {
  445. #ifdef CONFIG_COMPAT
  446. if (info->flags & IW_REQUEST_FLAG_COMPAT)
  447. return IW_EV_COMPAT_POINT_LEN;
  448. #endif
  449. return IW_EV_POINT_LEN;
  450. }
  451. static inline int iwe_stream_event_len_adjust(struct iw_request_info *info,
  452. int event_len)
  453. {
  454. #ifdef CONFIG_COMPAT
  455. if (info->flags & IW_REQUEST_FLAG_COMPAT) {
  456. event_len -= IW_EV_LCP_LEN;
  457. event_len += IW_EV_COMPAT_LCP_LEN;
  458. }
  459. #endif
  460. return event_len;
  461. }
  462. /*------------------------------------------------------------------*/
  463. /*
  464. * Wrapper to add an Wireless Event to a stream of events.
  465. */
  466. static inline char *
  467. iwe_stream_add_event(struct iw_request_info *info, char *stream, char *ends,
  468. struct iw_event *iwe, int event_len)
  469. {
  470. int lcp_len = iwe_stream_lcp_len(info);
  471. event_len = iwe_stream_event_len_adjust(info, event_len);
  472. /* Check if it's possible */
  473. if(likely((stream + event_len) < ends)) {
  474. iwe->len = event_len;
  475. /* Beware of alignement issues on 64 bits */
  476. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  477. memcpy(stream + lcp_len, &iwe->u,
  478. event_len - lcp_len);
  479. stream += event_len;
  480. }
  481. return stream;
  482. }
  483. static inline char *
  484. iwe_stream_add_event_check(struct iw_request_info *info, char *stream,
  485. char *ends, struct iw_event *iwe, int event_len)
  486. {
  487. char *res = iwe_stream_add_event(info, stream, ends, iwe, event_len);
  488. if (res == stream)
  489. return ERR_PTR(-E2BIG);
  490. return res;
  491. }
  492. /*------------------------------------------------------------------*/
  493. /*
  494. * Wrapper to add an short Wireless Event containing a pointer to a
  495. * stream of events.
  496. */
  497. static inline char *
  498. iwe_stream_add_point(struct iw_request_info *info, char *stream, char *ends,
  499. struct iw_event *iwe, char *extra)
  500. {
  501. int event_len = iwe_stream_point_len(info) + iwe->u.data.length;
  502. int point_len = iwe_stream_point_len(info);
  503. int lcp_len = iwe_stream_lcp_len(info);
  504. /* Check if it's possible */
  505. if(likely((stream + event_len) < ends)) {
  506. iwe->len = event_len;
  507. memcpy(stream, (char *) iwe, IW_EV_LCP_PK_LEN);
  508. memcpy(stream + lcp_len,
  509. ((char *) &iwe->u) + IW_EV_POINT_OFF,
  510. IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
  511. if (iwe->u.data.length && extra)
  512. memcpy(stream + point_len, extra, iwe->u.data.length);
  513. stream += event_len;
  514. }
  515. return stream;
  516. }
  517. static inline char *
  518. iwe_stream_add_point_check(struct iw_request_info *info, char *stream,
  519. char *ends, struct iw_event *iwe, char *extra)
  520. {
  521. char *res = iwe_stream_add_point(info, stream, ends, iwe, extra);
  522. if (res == stream)
  523. return ERR_PTR(-E2BIG);
  524. return res;
  525. }
  526. /*------------------------------------------------------------------*/
  527. /*
  528. * Wrapper to add a value to a Wireless Event in a stream of events.
  529. * Be careful, this one is tricky to use properly :
  530. * At the first run, you need to have (value = event + IW_EV_LCP_LEN).
  531. */
  532. static inline char *
  533. iwe_stream_add_value(struct iw_request_info *info, char *event, char *value,
  534. char *ends, struct iw_event *iwe, int event_len)
  535. {
  536. int lcp_len = iwe_stream_lcp_len(info);
  537. /* Don't duplicate LCP */
  538. event_len -= IW_EV_LCP_LEN;
  539. /* Check if it's possible */
  540. if(likely((value + event_len) < ends)) {
  541. /* Add new value */
  542. memcpy(value, &iwe->u, event_len);
  543. value += event_len;
  544. /* Patch LCP */
  545. iwe->len = value - event;
  546. memcpy(event, (char *) iwe, lcp_len);
  547. }
  548. return value;
  549. }
  550. #endif /* _IW_HANDLER_H */