wireless.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277
  1. /*
  2. * This file implement the Wireless Extensions APIs.
  3. *
  4. * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
  5. * Copyright (c) 1997-2006 Jean Tourrilhes, All Rights Reserved.
  6. *
  7. * (As all part of the Linux kernel, this file is GPL)
  8. */
  9. /************************** DOCUMENTATION **************************/
  10. /*
  11. * API definition :
  12. * --------------
  13. * See <linux/wireless.h> for details of the APIs and the rest.
  14. *
  15. * History :
  16. * -------
  17. *
  18. * v1 - 5.12.01 - Jean II
  19. * o Created this file.
  20. *
  21. * v2 - 13.12.01 - Jean II
  22. * o Move /proc/net/wireless stuff from net/core/dev.c to here
  23. * o Make Wireless Extension IOCTLs go through here
  24. * o Added iw_handler handling ;-)
  25. * o Added standard ioctl description
  26. * o Initial dumb commit strategy based on orinoco.c
  27. *
  28. * v3 - 19.12.01 - Jean II
  29. * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call
  30. * o Add event dispatcher function
  31. * o Add event description
  32. * o Propagate events as rtnetlink IFLA_WIRELESS option
  33. * o Generate event on selected SET requests
  34. *
  35. * v4 - 18.04.02 - Jean II
  36. * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
  37. *
  38. * v5 - 21.06.02 - Jean II
  39. * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup)
  40. * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
  41. * o Add IWEVCUSTOM for driver specific event/scanning token
  42. * o Turn on WE_STRICT_WRITE by default + kernel warning
  43. * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num)
  44. * o Fix off-by-one in test (extra_size <= IFNAMSIZ)
  45. *
  46. * v6 - 9.01.03 - Jean II
  47. * o Add common spy support : iw_handler_set_spy(), wireless_spy_update()
  48. * o Add enhanced spy support : iw_handler_set_thrspy() and event.
  49. * o Add WIRELESS_EXT version display in /proc/net/wireless
  50. *
  51. * v6 - 18.06.04 - Jean II
  52. * o Change get_spydata() method for added safety
  53. * o Remove spy #ifdef, they are always on -> cleaner code
  54. * o Allow any size GET request if user specifies length > max
  55. * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV
  56. * o Start migrating get_wireless_stats to struct iw_handler_def
  57. * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
  58. * Based on patch from Pavel Roskin <proski@gnu.org> :
  59. * o Fix kernel data leak to user space in private handler handling
  60. *
  61. * v7 - 18.3.05 - Jean II
  62. * o Remove (struct iw_point *)->pointer from events and streams
  63. * o Remove spy_offset from struct iw_handler_def
  64. * o Start deprecating dev->get_wireless_stats, output a warning
  65. * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
  66. * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats)
  67. *
  68. * v8 - 17.02.06 - Jean II
  69. * o RtNetlink requests support (SET/GET)
  70. */
  71. /***************************** INCLUDES *****************************/
  72. #include <linux/config.h> /* Not needed ??? */
  73. #include <linux/module.h>
  74. #include <linux/types.h> /* off_t */
  75. #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
  76. #include <linux/proc_fs.h>
  77. #include <linux/rtnetlink.h> /* rtnetlink stuff */
  78. #include <linux/seq_file.h>
  79. #include <linux/init.h> /* for __init */
  80. #include <linux/if_arp.h> /* ARPHRD_ETHER */
  81. #include <linux/etherdevice.h> /* compare_ether_addr */
  82. #include <linux/wireless.h> /* Pretty obvious */
  83. #include <net/iw_handler.h> /* New driver API */
  84. #include <asm/uaccess.h> /* copy_to_user() */
  85. /**************************** CONSTANTS ****************************/
  86. /* Debugging stuff */
  87. #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
  88. #undef WE_RTNETLINK_DEBUG /* Debug RtNetlink API */
  89. #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
  90. #undef WE_SPY_DEBUG /* Debug enhanced spy support */
  91. /* Options */
  92. //CONFIG_NET_WIRELESS_RTNETLINK /* Wireless requests over RtNetlink */
  93. #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
  94. #define WE_SET_EVENT /* Generate an event on some set commands */
  95. /************************* GLOBAL VARIABLES *************************/
  96. /*
  97. * You should not use global variables, because of re-entrancy.
  98. * On our case, it's only const, so it's OK...
  99. */
  100. /*
  101. * Meta-data about all the standard Wireless Extension request we
  102. * know about.
  103. */
  104. static const struct iw_ioctl_description standard_ioctl[] = {
  105. [SIOCSIWCOMMIT - SIOCIWFIRST] = {
  106. .header_type = IW_HEADER_TYPE_NULL,
  107. },
  108. [SIOCGIWNAME - SIOCIWFIRST] = {
  109. .header_type = IW_HEADER_TYPE_CHAR,
  110. .flags = IW_DESCR_FLAG_DUMP,
  111. },
  112. [SIOCSIWNWID - SIOCIWFIRST] = {
  113. .header_type = IW_HEADER_TYPE_PARAM,
  114. .flags = IW_DESCR_FLAG_EVENT,
  115. },
  116. [SIOCGIWNWID - SIOCIWFIRST] = {
  117. .header_type = IW_HEADER_TYPE_PARAM,
  118. .flags = IW_DESCR_FLAG_DUMP,
  119. },
  120. [SIOCSIWFREQ - SIOCIWFIRST] = {
  121. .header_type = IW_HEADER_TYPE_FREQ,
  122. .flags = IW_DESCR_FLAG_EVENT,
  123. },
  124. [SIOCGIWFREQ - SIOCIWFIRST] = {
  125. .header_type = IW_HEADER_TYPE_FREQ,
  126. .flags = IW_DESCR_FLAG_DUMP,
  127. },
  128. [SIOCSIWMODE - SIOCIWFIRST] = {
  129. .header_type = IW_HEADER_TYPE_UINT,
  130. .flags = IW_DESCR_FLAG_EVENT,
  131. },
  132. [SIOCGIWMODE - SIOCIWFIRST] = {
  133. .header_type = IW_HEADER_TYPE_UINT,
  134. .flags = IW_DESCR_FLAG_DUMP,
  135. },
  136. [SIOCSIWSENS - SIOCIWFIRST] = {
  137. .header_type = IW_HEADER_TYPE_PARAM,
  138. },
  139. [SIOCGIWSENS - SIOCIWFIRST] = {
  140. .header_type = IW_HEADER_TYPE_PARAM,
  141. },
  142. [SIOCSIWRANGE - SIOCIWFIRST] = {
  143. .header_type = IW_HEADER_TYPE_NULL,
  144. },
  145. [SIOCGIWRANGE - SIOCIWFIRST] = {
  146. .header_type = IW_HEADER_TYPE_POINT,
  147. .token_size = 1,
  148. .max_tokens = sizeof(struct iw_range),
  149. .flags = IW_DESCR_FLAG_DUMP,
  150. },
  151. [SIOCSIWPRIV - SIOCIWFIRST] = {
  152. .header_type = IW_HEADER_TYPE_NULL,
  153. },
  154. [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
  155. .header_type = IW_HEADER_TYPE_POINT,
  156. .token_size = sizeof(struct iw_priv_args),
  157. .max_tokens = 16,
  158. .flags = IW_DESCR_FLAG_NOMAX,
  159. },
  160. [SIOCSIWSTATS - SIOCIWFIRST] = {
  161. .header_type = IW_HEADER_TYPE_NULL,
  162. },
  163. [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
  164. .header_type = IW_HEADER_TYPE_POINT,
  165. .token_size = 1,
  166. .max_tokens = sizeof(struct iw_statistics),
  167. .flags = IW_DESCR_FLAG_DUMP,
  168. },
  169. [SIOCSIWSPY - SIOCIWFIRST] = {
  170. .header_type = IW_HEADER_TYPE_POINT,
  171. .token_size = sizeof(struct sockaddr),
  172. .max_tokens = IW_MAX_SPY,
  173. },
  174. [SIOCGIWSPY - SIOCIWFIRST] = {
  175. .header_type = IW_HEADER_TYPE_POINT,
  176. .token_size = sizeof(struct sockaddr) +
  177. sizeof(struct iw_quality),
  178. .max_tokens = IW_MAX_SPY,
  179. },
  180. [SIOCSIWTHRSPY - SIOCIWFIRST] = {
  181. .header_type = IW_HEADER_TYPE_POINT,
  182. .token_size = sizeof(struct iw_thrspy),
  183. .min_tokens = 1,
  184. .max_tokens = 1,
  185. },
  186. [SIOCGIWTHRSPY - SIOCIWFIRST] = {
  187. .header_type = IW_HEADER_TYPE_POINT,
  188. .token_size = sizeof(struct iw_thrspy),
  189. .min_tokens = 1,
  190. .max_tokens = 1,
  191. },
  192. [SIOCSIWAP - SIOCIWFIRST] = {
  193. .header_type = IW_HEADER_TYPE_ADDR,
  194. },
  195. [SIOCGIWAP - SIOCIWFIRST] = {
  196. .header_type = IW_HEADER_TYPE_ADDR,
  197. .flags = IW_DESCR_FLAG_DUMP,
  198. },
  199. [SIOCSIWMLME - SIOCIWFIRST] = {
  200. .header_type = IW_HEADER_TYPE_POINT,
  201. .token_size = 1,
  202. .min_tokens = sizeof(struct iw_mlme),
  203. .max_tokens = sizeof(struct iw_mlme),
  204. },
  205. [SIOCGIWAPLIST - SIOCIWFIRST] = {
  206. .header_type = IW_HEADER_TYPE_POINT,
  207. .token_size = sizeof(struct sockaddr) +
  208. sizeof(struct iw_quality),
  209. .max_tokens = IW_MAX_AP,
  210. .flags = IW_DESCR_FLAG_NOMAX,
  211. },
  212. [SIOCSIWSCAN - SIOCIWFIRST] = {
  213. .header_type = IW_HEADER_TYPE_POINT,
  214. .token_size = 1,
  215. .min_tokens = 0,
  216. .max_tokens = sizeof(struct iw_scan_req),
  217. },
  218. [SIOCGIWSCAN - SIOCIWFIRST] = {
  219. .header_type = IW_HEADER_TYPE_POINT,
  220. .token_size = 1,
  221. .max_tokens = IW_SCAN_MAX_DATA,
  222. .flags = IW_DESCR_FLAG_NOMAX,
  223. },
  224. [SIOCSIWESSID - SIOCIWFIRST] = {
  225. .header_type = IW_HEADER_TYPE_POINT,
  226. .token_size = 1,
  227. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  228. .flags = IW_DESCR_FLAG_EVENT,
  229. },
  230. [SIOCGIWESSID - SIOCIWFIRST] = {
  231. .header_type = IW_HEADER_TYPE_POINT,
  232. .token_size = 1,
  233. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  234. .flags = IW_DESCR_FLAG_DUMP,
  235. },
  236. [SIOCSIWNICKN - SIOCIWFIRST] = {
  237. .header_type = IW_HEADER_TYPE_POINT,
  238. .token_size = 1,
  239. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  240. },
  241. [SIOCGIWNICKN - SIOCIWFIRST] = {
  242. .header_type = IW_HEADER_TYPE_POINT,
  243. .token_size = 1,
  244. .max_tokens = IW_ESSID_MAX_SIZE + 1,
  245. },
  246. [SIOCSIWRATE - SIOCIWFIRST] = {
  247. .header_type = IW_HEADER_TYPE_PARAM,
  248. },
  249. [SIOCGIWRATE - SIOCIWFIRST] = {
  250. .header_type = IW_HEADER_TYPE_PARAM,
  251. },
  252. [SIOCSIWRTS - SIOCIWFIRST] = {
  253. .header_type = IW_HEADER_TYPE_PARAM,
  254. },
  255. [SIOCGIWRTS - SIOCIWFIRST] = {
  256. .header_type = IW_HEADER_TYPE_PARAM,
  257. },
  258. [SIOCSIWFRAG - SIOCIWFIRST] = {
  259. .header_type = IW_HEADER_TYPE_PARAM,
  260. },
  261. [SIOCGIWFRAG - SIOCIWFIRST] = {
  262. .header_type = IW_HEADER_TYPE_PARAM,
  263. },
  264. [SIOCSIWTXPOW - SIOCIWFIRST] = {
  265. .header_type = IW_HEADER_TYPE_PARAM,
  266. },
  267. [SIOCGIWTXPOW - SIOCIWFIRST] = {
  268. .header_type = IW_HEADER_TYPE_PARAM,
  269. },
  270. [SIOCSIWRETRY - SIOCIWFIRST] = {
  271. .header_type = IW_HEADER_TYPE_PARAM,
  272. },
  273. [SIOCGIWRETRY - SIOCIWFIRST] = {
  274. .header_type = IW_HEADER_TYPE_PARAM,
  275. },
  276. [SIOCSIWENCODE - SIOCIWFIRST] = {
  277. .header_type = IW_HEADER_TYPE_POINT,
  278. .token_size = 1,
  279. .max_tokens = IW_ENCODING_TOKEN_MAX,
  280. .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
  281. },
  282. [SIOCGIWENCODE - SIOCIWFIRST] = {
  283. .header_type = IW_HEADER_TYPE_POINT,
  284. .token_size = 1,
  285. .max_tokens = IW_ENCODING_TOKEN_MAX,
  286. .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
  287. },
  288. [SIOCSIWPOWER - SIOCIWFIRST] = {
  289. .header_type = IW_HEADER_TYPE_PARAM,
  290. },
  291. [SIOCGIWPOWER - SIOCIWFIRST] = {
  292. .header_type = IW_HEADER_TYPE_PARAM,
  293. },
  294. [SIOCSIWGENIE - SIOCIWFIRST] = {
  295. .header_type = IW_HEADER_TYPE_POINT,
  296. .token_size = 1,
  297. .max_tokens = IW_GENERIC_IE_MAX,
  298. },
  299. [SIOCGIWGENIE - SIOCIWFIRST] = {
  300. .header_type = IW_HEADER_TYPE_POINT,
  301. .token_size = 1,
  302. .max_tokens = IW_GENERIC_IE_MAX,
  303. },
  304. [SIOCSIWAUTH - SIOCIWFIRST] = {
  305. .header_type = IW_HEADER_TYPE_PARAM,
  306. },
  307. [SIOCGIWAUTH - SIOCIWFIRST] = {
  308. .header_type = IW_HEADER_TYPE_PARAM,
  309. },
  310. [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
  311. .header_type = IW_HEADER_TYPE_POINT,
  312. .token_size = 1,
  313. .min_tokens = sizeof(struct iw_encode_ext),
  314. .max_tokens = sizeof(struct iw_encode_ext) +
  315. IW_ENCODING_TOKEN_MAX,
  316. },
  317. [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
  318. .header_type = IW_HEADER_TYPE_POINT,
  319. .token_size = 1,
  320. .min_tokens = sizeof(struct iw_encode_ext),
  321. .max_tokens = sizeof(struct iw_encode_ext) +
  322. IW_ENCODING_TOKEN_MAX,
  323. },
  324. [SIOCSIWPMKSA - SIOCIWFIRST] = {
  325. .header_type = IW_HEADER_TYPE_POINT,
  326. .token_size = 1,
  327. .min_tokens = sizeof(struct iw_pmksa),
  328. .max_tokens = sizeof(struct iw_pmksa),
  329. },
  330. };
  331. static const int standard_ioctl_num = (sizeof(standard_ioctl) /
  332. sizeof(struct iw_ioctl_description));
  333. /*
  334. * Meta-data about all the additional standard Wireless Extension events
  335. * we know about.
  336. */
  337. static const struct iw_ioctl_description standard_event[] = {
  338. [IWEVTXDROP - IWEVFIRST] = {
  339. .header_type = IW_HEADER_TYPE_ADDR,
  340. },
  341. [IWEVQUAL - IWEVFIRST] = {
  342. .header_type = IW_HEADER_TYPE_QUAL,
  343. },
  344. [IWEVCUSTOM - IWEVFIRST] = {
  345. .header_type = IW_HEADER_TYPE_POINT,
  346. .token_size = 1,
  347. .max_tokens = IW_CUSTOM_MAX,
  348. },
  349. [IWEVREGISTERED - IWEVFIRST] = {
  350. .header_type = IW_HEADER_TYPE_ADDR,
  351. },
  352. [IWEVEXPIRED - IWEVFIRST] = {
  353. .header_type = IW_HEADER_TYPE_ADDR,
  354. },
  355. [IWEVGENIE - IWEVFIRST] = {
  356. .header_type = IW_HEADER_TYPE_POINT,
  357. .token_size = 1,
  358. .max_tokens = IW_GENERIC_IE_MAX,
  359. },
  360. [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
  361. .header_type = IW_HEADER_TYPE_POINT,
  362. .token_size = 1,
  363. .max_tokens = sizeof(struct iw_michaelmicfailure),
  364. },
  365. [IWEVASSOCREQIE - IWEVFIRST] = {
  366. .header_type = IW_HEADER_TYPE_POINT,
  367. .token_size = 1,
  368. .max_tokens = IW_GENERIC_IE_MAX,
  369. },
  370. [IWEVASSOCRESPIE - IWEVFIRST] = {
  371. .header_type = IW_HEADER_TYPE_POINT,
  372. .token_size = 1,
  373. .max_tokens = IW_GENERIC_IE_MAX,
  374. },
  375. [IWEVPMKIDCAND - IWEVFIRST] = {
  376. .header_type = IW_HEADER_TYPE_POINT,
  377. .token_size = 1,
  378. .max_tokens = sizeof(struct iw_pmkid_cand),
  379. },
  380. };
  381. static const int standard_event_num = (sizeof(standard_event) /
  382. sizeof(struct iw_ioctl_description));
  383. /* Size (in bytes) of the various private data types */
  384. static const char iw_priv_type_size[] = {
  385. 0, /* IW_PRIV_TYPE_NONE */
  386. 1, /* IW_PRIV_TYPE_BYTE */
  387. 1, /* IW_PRIV_TYPE_CHAR */
  388. 0, /* Not defined */
  389. sizeof(__u32), /* IW_PRIV_TYPE_INT */
  390. sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
  391. sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
  392. 0, /* Not defined */
  393. };
  394. /* Size (in bytes) of various events */
  395. static const int event_type_size[] = {
  396. IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
  397. 0,
  398. IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
  399. 0,
  400. IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
  401. IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
  402. IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
  403. 0,
  404. IW_EV_POINT_LEN, /* Without variable payload */
  405. IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
  406. IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
  407. };
  408. /************************ COMMON SUBROUTINES ************************/
  409. /*
  410. * Stuff that may be used in various place or doesn't fit in one
  411. * of the section below.
  412. */
  413. /* ---------------------------------------------------------------- */
  414. /*
  415. * Return the driver handler associated with a specific Wireless Extension.
  416. * Called from various place, so make sure it remains efficient.
  417. */
  418. static inline iw_handler get_handler(struct net_device *dev,
  419. unsigned int cmd)
  420. {
  421. /* Don't "optimise" the following variable, it will crash */
  422. unsigned int index; /* *MUST* be unsigned */
  423. /* Check if we have some wireless handlers defined */
  424. if(dev->wireless_handlers == NULL)
  425. return NULL;
  426. /* Try as a standard command */
  427. index = cmd - SIOCIWFIRST;
  428. if(index < dev->wireless_handlers->num_standard)
  429. return dev->wireless_handlers->standard[index];
  430. /* Try as a private command */
  431. index = cmd - SIOCIWFIRSTPRIV;
  432. if(index < dev->wireless_handlers->num_private)
  433. return dev->wireless_handlers->private[index];
  434. /* Not found */
  435. return NULL;
  436. }
  437. /* ---------------------------------------------------------------- */
  438. /*
  439. * Get statistics out of the driver
  440. */
  441. static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
  442. {
  443. /* New location */
  444. if((dev->wireless_handlers != NULL) &&
  445. (dev->wireless_handlers->get_wireless_stats != NULL))
  446. return dev->wireless_handlers->get_wireless_stats(dev);
  447. /* Old location, field to be removed in next WE */
  448. if(dev->get_wireless_stats) {
  449. static int printed_message;
  450. if (!printed_message++)
  451. printk(KERN_DEBUG "%s (WE) : Driver using old /proc/net/wireless support, please fix driver !\n",
  452. dev->name);
  453. return dev->get_wireless_stats(dev);
  454. }
  455. /* Not found */
  456. return (struct iw_statistics *) NULL;
  457. }
  458. /* ---------------------------------------------------------------- */
  459. /*
  460. * Call the commit handler in the driver
  461. * (if exist and if conditions are right)
  462. *
  463. * Note : our current commit strategy is currently pretty dumb,
  464. * but we will be able to improve on that...
  465. * The goal is to try to agreagate as many changes as possible
  466. * before doing the commit. Drivers that will define a commit handler
  467. * are usually those that need a reset after changing parameters, so
  468. * we want to minimise the number of reset.
  469. * A cool idea is to use a timer : at each "set" command, we re-set the
  470. * timer, when the timer eventually fires, we call the driver.
  471. * Hopefully, more on that later.
  472. *
  473. * Also, I'm waiting to see how many people will complain about the
  474. * netif_running(dev) test. I'm open on that one...
  475. * Hopefully, the driver will remember to do a commit in "open()" ;-)
  476. */
  477. static inline int call_commit_handler(struct net_device * dev)
  478. {
  479. if((netif_running(dev)) &&
  480. (dev->wireless_handlers->standard[0] != NULL)) {
  481. /* Call the commit handler on the driver */
  482. return dev->wireless_handlers->standard[0](dev, NULL,
  483. NULL, NULL);
  484. } else
  485. return 0; /* Command completed successfully */
  486. }
  487. /* ---------------------------------------------------------------- */
  488. /*
  489. * Calculate size of private arguments
  490. */
  491. static inline int get_priv_size(__u16 args)
  492. {
  493. int num = args & IW_PRIV_SIZE_MASK;
  494. int type = (args & IW_PRIV_TYPE_MASK) >> 12;
  495. return num * iw_priv_type_size[type];
  496. }
  497. /* ---------------------------------------------------------------- */
  498. /*
  499. * Re-calculate the size of private arguments
  500. */
  501. static inline int adjust_priv_size(__u16 args,
  502. union iwreq_data * wrqu)
  503. {
  504. int num = wrqu->data.length;
  505. int max = args & IW_PRIV_SIZE_MASK;
  506. int type = (args & IW_PRIV_TYPE_MASK) >> 12;
  507. /* Make sure the driver doesn't goof up */
  508. if (max < num)
  509. num = max;
  510. return num * iw_priv_type_size[type];
  511. }
  512. /* ---------------------------------------------------------------- */
  513. /*
  514. * Standard Wireless Handler : get wireless stats
  515. * Allow programatic access to /proc/net/wireless even if /proc
  516. * doesn't exist... Also more efficient...
  517. */
  518. static int iw_handler_get_iwstats(struct net_device * dev,
  519. struct iw_request_info * info,
  520. union iwreq_data * wrqu,
  521. char * extra)
  522. {
  523. /* Get stats from the driver */
  524. struct iw_statistics *stats;
  525. stats = get_wireless_stats(dev);
  526. if (stats != (struct iw_statistics *) NULL) {
  527. /* Copy statistics to extra */
  528. memcpy(extra, stats, sizeof(struct iw_statistics));
  529. wrqu->data.length = sizeof(struct iw_statistics);
  530. /* Check if we need to clear the updated flag */
  531. if(wrqu->data.flags != 0)
  532. stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
  533. return 0;
  534. } else
  535. return -EOPNOTSUPP;
  536. }
  537. /* ---------------------------------------------------------------- */
  538. /*
  539. * Standard Wireless Handler : get iwpriv definitions
  540. * Export the driver private handler definition
  541. * They will be picked up by tools like iwpriv...
  542. */
  543. static int iw_handler_get_private(struct net_device * dev,
  544. struct iw_request_info * info,
  545. union iwreq_data * wrqu,
  546. char * extra)
  547. {
  548. /* Check if the driver has something to export */
  549. if((dev->wireless_handlers->num_private_args == 0) ||
  550. (dev->wireless_handlers->private_args == NULL))
  551. return -EOPNOTSUPP;
  552. /* Check if there is enough buffer up there */
  553. if(wrqu->data.length < dev->wireless_handlers->num_private_args) {
  554. /* User space can't know in advance how large the buffer
  555. * needs to be. Give it a hint, so that we can support
  556. * any size buffer we want somewhat efficiently... */
  557. wrqu->data.length = dev->wireless_handlers->num_private_args;
  558. return -E2BIG;
  559. }
  560. /* Set the number of available ioctls. */
  561. wrqu->data.length = dev->wireless_handlers->num_private_args;
  562. /* Copy structure to the user buffer. */
  563. memcpy(extra, dev->wireless_handlers->private_args,
  564. sizeof(struct iw_priv_args) * wrqu->data.length);
  565. return 0;
  566. }
  567. /******************** /proc/net/wireless SUPPORT ********************/
  568. /*
  569. * The /proc/net/wireless file is a human readable user-space interface
  570. * exporting various wireless specific statistics from the wireless devices.
  571. * This is the most popular part of the Wireless Extensions ;-)
  572. *
  573. * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
  574. * The content of the file is basically the content of "struct iw_statistics".
  575. */
  576. #ifdef CONFIG_PROC_FS
  577. /* ---------------------------------------------------------------- */
  578. /*
  579. * Print one entry (line) of /proc/net/wireless
  580. */
  581. static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
  582. struct net_device *dev)
  583. {
  584. /* Get stats from the driver */
  585. struct iw_statistics *stats = get_wireless_stats(dev);
  586. if (stats) {
  587. seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
  588. "%6d %6d %6d\n",
  589. dev->name, stats->status, stats->qual.qual,
  590. stats->qual.updated & IW_QUAL_QUAL_UPDATED
  591. ? '.' : ' ',
  592. ((__s32) stats->qual.level) -
  593. ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
  594. stats->qual.updated & IW_QUAL_LEVEL_UPDATED
  595. ? '.' : ' ',
  596. ((__s32) stats->qual.noise) -
  597. ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
  598. stats->qual.updated & IW_QUAL_NOISE_UPDATED
  599. ? '.' : ' ',
  600. stats->discard.nwid, stats->discard.code,
  601. stats->discard.fragment, stats->discard.retries,
  602. stats->discard.misc, stats->miss.beacon);
  603. stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
  604. }
  605. }
  606. /* ---------------------------------------------------------------- */
  607. /*
  608. * Print info for /proc/net/wireless (print all entries)
  609. */
  610. static int wireless_seq_show(struct seq_file *seq, void *v)
  611. {
  612. if (v == SEQ_START_TOKEN)
  613. seq_printf(seq, "Inter-| sta-| Quality | Discarded "
  614. "packets | Missed | WE\n"
  615. " face | tus | link level noise | nwid "
  616. "crypt frag retry misc | beacon | %d\n",
  617. WIRELESS_EXT);
  618. else
  619. wireless_seq_printf_stats(seq, v);
  620. return 0;
  621. }
  622. static struct seq_operations wireless_seq_ops = {
  623. .start = dev_seq_start,
  624. .next = dev_seq_next,
  625. .stop = dev_seq_stop,
  626. .show = wireless_seq_show,
  627. };
  628. static int wireless_seq_open(struct inode *inode, struct file *file)
  629. {
  630. return seq_open(file, &wireless_seq_ops);
  631. }
  632. static struct file_operations wireless_seq_fops = {
  633. .owner = THIS_MODULE,
  634. .open = wireless_seq_open,
  635. .read = seq_read,
  636. .llseek = seq_lseek,
  637. .release = seq_release,
  638. };
  639. int __init wireless_proc_init(void)
  640. {
  641. /* Create /proc/net/wireless entry */
  642. if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
  643. return -ENOMEM;
  644. return 0;
  645. }
  646. #endif /* CONFIG_PROC_FS */
  647. /************************** IOCTL SUPPORT **************************/
  648. /*
  649. * The original user space API to configure all those Wireless Extensions
  650. * is through IOCTLs.
  651. * In there, we check if we need to call the new driver API (iw_handler)
  652. * or just call the driver ioctl handler.
  653. */
  654. /* ---------------------------------------------------------------- */
  655. /*
  656. * Wrapper to call a standard Wireless Extension handler.
  657. * We do various checks and also take care of moving data between
  658. * user space and kernel space.
  659. */
  660. static int ioctl_standard_call(struct net_device * dev,
  661. struct ifreq * ifr,
  662. unsigned int cmd,
  663. iw_handler handler)
  664. {
  665. struct iwreq * iwr = (struct iwreq *) ifr;
  666. const struct iw_ioctl_description * descr;
  667. struct iw_request_info info;
  668. int ret = -EINVAL;
  669. /* Get the description of the IOCTL */
  670. if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
  671. return -EOPNOTSUPP;
  672. descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
  673. #ifdef WE_IOCTL_DEBUG
  674. printk(KERN_DEBUG "%s (WE) : Found standard handler for 0x%04X\n",
  675. ifr->ifr_name, cmd);
  676. printk(KERN_DEBUG "%s (WE) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
  677. #endif /* WE_IOCTL_DEBUG */
  678. /* Prepare the call */
  679. info.cmd = cmd;
  680. info.flags = 0;
  681. /* Check if we have a pointer to user space data or not */
  682. if(descr->header_type != IW_HEADER_TYPE_POINT) {
  683. /* No extra arguments. Trivial to handle */
  684. ret = handler(dev, &info, &(iwr->u), NULL);
  685. #ifdef WE_SET_EVENT
  686. /* Generate an event to notify listeners of the change */
  687. if((descr->flags & IW_DESCR_FLAG_EVENT) &&
  688. ((ret == 0) || (ret == -EIWCOMMIT)))
  689. wireless_send_event(dev, cmd, &(iwr->u), NULL);
  690. #endif /* WE_SET_EVENT */
  691. } else {
  692. char * extra;
  693. int extra_size;
  694. int user_length = 0;
  695. int err;
  696. /* Calculate space needed by arguments. Always allocate
  697. * for max space. Easier, and won't last long... */
  698. extra_size = descr->max_tokens * descr->token_size;
  699. /* Check what user space is giving us */
  700. if(IW_IS_SET(cmd)) {
  701. /* Check NULL pointer */
  702. if((iwr->u.data.pointer == NULL) &&
  703. (iwr->u.data.length != 0))
  704. return -EFAULT;
  705. /* Check if number of token fits within bounds */
  706. if(iwr->u.data.length > descr->max_tokens)
  707. return -E2BIG;
  708. if(iwr->u.data.length < descr->min_tokens)
  709. return -EINVAL;
  710. } else {
  711. /* Check NULL pointer */
  712. if(iwr->u.data.pointer == NULL)
  713. return -EFAULT;
  714. /* Save user space buffer size for checking */
  715. user_length = iwr->u.data.length;
  716. /* Don't check if user_length > max to allow forward
  717. * compatibility. The test user_length < min is
  718. * implied by the test at the end. */
  719. /* Support for very large requests */
  720. if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
  721. (user_length > descr->max_tokens)) {
  722. /* Allow userspace to GET more than max so
  723. * we can support any size GET requests.
  724. * There is still a limit : -ENOMEM. */
  725. extra_size = user_length * descr->token_size;
  726. /* Note : user_length is originally a __u16,
  727. * and token_size is controlled by us,
  728. * so extra_size won't get negative and
  729. * won't overflow... */
  730. }
  731. }
  732. #ifdef WE_IOCTL_DEBUG
  733. printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
  734. dev->name, extra_size);
  735. #endif /* WE_IOCTL_DEBUG */
  736. /* Create the kernel buffer */
  737. extra = kmalloc(extra_size, GFP_KERNEL);
  738. if (extra == NULL) {
  739. return -ENOMEM;
  740. }
  741. /* If it is a SET, get all the extra data in here */
  742. if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
  743. err = copy_from_user(extra, iwr->u.data.pointer,
  744. iwr->u.data.length *
  745. descr->token_size);
  746. if (err) {
  747. kfree(extra);
  748. return -EFAULT;
  749. }
  750. #ifdef WE_IOCTL_DEBUG
  751. printk(KERN_DEBUG "%s (WE) : Got %d bytes\n",
  752. dev->name,
  753. iwr->u.data.length * descr->token_size);
  754. #endif /* WE_IOCTL_DEBUG */
  755. }
  756. /* Call the handler */
  757. ret = handler(dev, &info, &(iwr->u), extra);
  758. /* If we have something to return to the user */
  759. if (!ret && IW_IS_GET(cmd)) {
  760. /* Check if there is enough buffer up there */
  761. if(user_length < iwr->u.data.length) {
  762. kfree(extra);
  763. return -E2BIG;
  764. }
  765. err = copy_to_user(iwr->u.data.pointer, extra,
  766. iwr->u.data.length *
  767. descr->token_size);
  768. if (err)
  769. ret = -EFAULT;
  770. #ifdef WE_IOCTL_DEBUG
  771. printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
  772. dev->name,
  773. iwr->u.data.length * descr->token_size);
  774. #endif /* WE_IOCTL_DEBUG */
  775. }
  776. #ifdef WE_SET_EVENT
  777. /* Generate an event to notify listeners of the change */
  778. if((descr->flags & IW_DESCR_FLAG_EVENT) &&
  779. ((ret == 0) || (ret == -EIWCOMMIT))) {
  780. if(descr->flags & IW_DESCR_FLAG_RESTRICT)
  781. /* If the event is restricted, don't
  782. * export the payload */
  783. wireless_send_event(dev, cmd, &(iwr->u), NULL);
  784. else
  785. wireless_send_event(dev, cmd, &(iwr->u),
  786. extra);
  787. }
  788. #endif /* WE_SET_EVENT */
  789. /* Cleanup - I told you it wasn't that long ;-) */
  790. kfree(extra);
  791. }
  792. /* Call commit handler if needed and defined */
  793. if(ret == -EIWCOMMIT)
  794. ret = call_commit_handler(dev);
  795. /* Here, we will generate the appropriate event if needed */
  796. return ret;
  797. }
  798. /* ---------------------------------------------------------------- */
  799. /*
  800. * Wrapper to call a private Wireless Extension handler.
  801. * We do various checks and also take care of moving data between
  802. * user space and kernel space.
  803. * It's not as nice and slimline as the standard wrapper. The cause
  804. * is struct iw_priv_args, which was not really designed for the
  805. * job we are going here.
  806. *
  807. * IMPORTANT : This function prevent to set and get data on the same
  808. * IOCTL and enforce the SET/GET convention. Not doing it would be
  809. * far too hairy...
  810. * If you need to set and get data at the same time, please don't use
  811. * a iw_handler but process it in your ioctl handler (i.e. use the
  812. * old driver API).
  813. */
  814. static inline int ioctl_private_call(struct net_device * dev,
  815. struct ifreq * ifr,
  816. unsigned int cmd,
  817. iw_handler handler)
  818. {
  819. struct iwreq * iwr = (struct iwreq *) ifr;
  820. const struct iw_priv_args * descr = NULL;
  821. struct iw_request_info info;
  822. int extra_size = 0;
  823. int i;
  824. int ret = -EINVAL;
  825. /* Get the description of the IOCTL */
  826. for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
  827. if(cmd == dev->wireless_handlers->private_args[i].cmd) {
  828. descr = &(dev->wireless_handlers->private_args[i]);
  829. break;
  830. }
  831. #ifdef WE_IOCTL_DEBUG
  832. printk(KERN_DEBUG "%s (WE) : Found private handler for 0x%04X\n",
  833. ifr->ifr_name, cmd);
  834. if(descr) {
  835. printk(KERN_DEBUG "%s (WE) : Name %s, set %X, get %X\n",
  836. dev->name, descr->name,
  837. descr->set_args, descr->get_args);
  838. }
  839. #endif /* WE_IOCTL_DEBUG */
  840. /* Compute the size of the set/get arguments */
  841. if(descr != NULL) {
  842. if(IW_IS_SET(cmd)) {
  843. int offset = 0; /* For sub-ioctls */
  844. /* Check for sub-ioctl handler */
  845. if(descr->name[0] == '\0')
  846. /* Reserve one int for sub-ioctl index */
  847. offset = sizeof(__u32);
  848. /* Size of set arguments */
  849. extra_size = get_priv_size(descr->set_args);
  850. /* Does it fits in iwr ? */
  851. if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
  852. ((extra_size + offset) <= IFNAMSIZ))
  853. extra_size = 0;
  854. } else {
  855. /* Size of get arguments */
  856. extra_size = get_priv_size(descr->get_args);
  857. /* Does it fits in iwr ? */
  858. if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
  859. (extra_size <= IFNAMSIZ))
  860. extra_size = 0;
  861. }
  862. }
  863. /* Prepare the call */
  864. info.cmd = cmd;
  865. info.flags = 0;
  866. /* Check if we have a pointer to user space data or not. */
  867. if(extra_size == 0) {
  868. /* No extra arguments. Trivial to handle */
  869. ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
  870. } else {
  871. char * extra;
  872. int err;
  873. /* Check what user space is giving us */
  874. if(IW_IS_SET(cmd)) {
  875. /* Check NULL pointer */
  876. if((iwr->u.data.pointer == NULL) &&
  877. (iwr->u.data.length != 0))
  878. return -EFAULT;
  879. /* Does it fits within bounds ? */
  880. if(iwr->u.data.length > (descr->set_args &
  881. IW_PRIV_SIZE_MASK))
  882. return -E2BIG;
  883. } else {
  884. /* Check NULL pointer */
  885. if(iwr->u.data.pointer == NULL)
  886. return -EFAULT;
  887. }
  888. #ifdef WE_IOCTL_DEBUG
  889. printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
  890. dev->name, extra_size);
  891. #endif /* WE_IOCTL_DEBUG */
  892. /* Always allocate for max space. Easier, and won't last
  893. * long... */
  894. extra = kmalloc(extra_size, GFP_KERNEL);
  895. if (extra == NULL) {
  896. return -ENOMEM;
  897. }
  898. /* If it is a SET, get all the extra data in here */
  899. if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
  900. err = copy_from_user(extra, iwr->u.data.pointer,
  901. extra_size);
  902. if (err) {
  903. kfree(extra);
  904. return -EFAULT;
  905. }
  906. #ifdef WE_IOCTL_DEBUG
  907. printk(KERN_DEBUG "%s (WE) : Got %d elem\n",
  908. dev->name, iwr->u.data.length);
  909. #endif /* WE_IOCTL_DEBUG */
  910. }
  911. /* Call the handler */
  912. ret = handler(dev, &info, &(iwr->u), extra);
  913. /* If we have something to return to the user */
  914. if (!ret && IW_IS_GET(cmd)) {
  915. /* Adjust for the actual length if it's variable,
  916. * avoid leaking kernel bits outside. */
  917. if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
  918. extra_size = adjust_priv_size(descr->get_args,
  919. &(iwr->u));
  920. }
  921. err = copy_to_user(iwr->u.data.pointer, extra,
  922. extra_size);
  923. if (err)
  924. ret = -EFAULT;
  925. #ifdef WE_IOCTL_DEBUG
  926. printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
  927. dev->name, iwr->u.data.length);
  928. #endif /* WE_IOCTL_DEBUG */
  929. }
  930. /* Cleanup - I told you it wasn't that long ;-) */
  931. kfree(extra);
  932. }
  933. /* Call commit handler if needed and defined */
  934. if(ret == -EIWCOMMIT)
  935. ret = call_commit_handler(dev);
  936. return ret;
  937. }
  938. /* ---------------------------------------------------------------- */
  939. /*
  940. * Main IOCTl dispatcher. Called from the main networking code
  941. * (dev_ioctl() in net/core/dev.c).
  942. * Check the type of IOCTL and call the appropriate wrapper...
  943. */
  944. int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
  945. {
  946. struct net_device *dev;
  947. iw_handler handler;
  948. /* Permissions are already checked in dev_ioctl() before calling us.
  949. * The copy_to/from_user() of ifr is also dealt with in there */
  950. /* Make sure the device exist */
  951. if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
  952. return -ENODEV;
  953. /* A bunch of special cases, then the generic case...
  954. * Note that 'cmd' is already filtered in dev_ioctl() with
  955. * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
  956. switch(cmd)
  957. {
  958. case SIOCGIWSTATS:
  959. /* Get Wireless Stats */
  960. return ioctl_standard_call(dev,
  961. ifr,
  962. cmd,
  963. &iw_handler_get_iwstats);
  964. case SIOCGIWPRIV:
  965. /* Check if we have some wireless handlers defined */
  966. if(dev->wireless_handlers != NULL) {
  967. /* We export to user space the definition of
  968. * the private handler ourselves */
  969. return ioctl_standard_call(dev,
  970. ifr,
  971. cmd,
  972. &iw_handler_get_private);
  973. }
  974. // ## Fall-through for old API ##
  975. default:
  976. /* Generic IOCTL */
  977. /* Basic check */
  978. if (!netif_device_present(dev))
  979. return -ENODEV;
  980. /* New driver API : try to find the handler */
  981. handler = get_handler(dev, cmd);
  982. if(handler != NULL) {
  983. /* Standard and private are not the same */
  984. if(cmd < SIOCIWFIRSTPRIV)
  985. return ioctl_standard_call(dev,
  986. ifr,
  987. cmd,
  988. handler);
  989. else
  990. return ioctl_private_call(dev,
  991. ifr,
  992. cmd,
  993. handler);
  994. }
  995. /* Old driver API : call driver ioctl handler */
  996. if (dev->do_ioctl) {
  997. return dev->do_ioctl(dev, ifr, cmd);
  998. }
  999. return -EOPNOTSUPP;
  1000. }
  1001. /* Not reached */
  1002. return -EINVAL;
  1003. }
  1004. /********************** RTNETLINK REQUEST API **********************/
  1005. /*
  1006. * The alternate user space API to configure all those Wireless Extensions
  1007. * is through RtNetlink.
  1008. * This API support only the new driver API (iw_handler).
  1009. *
  1010. * This RtNetlink API use the same query/reply model as the ioctl API.
  1011. * Maximum effort has been done to fit in the RtNetlink model, and
  1012. * we support both RtNetlink Set and RtNelink Get operations.
  1013. * On the other hand, we don't offer Dump operations because of the
  1014. * following reasons :
  1015. * o Large number of parameters, most optional
  1016. * o Large size of some parameters (> 100 bytes)
  1017. * o Each parameters need to be extracted from hardware
  1018. * o Scan requests can take seconds and disable network activity.
  1019. * Because of this high cost/overhead, we want to return only the
  1020. * parameters the user application is really interested in.
  1021. * We could offer partial Dump using the IW_DESCR_FLAG_DUMP flag.
  1022. *
  1023. * The API uses the standard RtNetlink socket. When the RtNetlink code
  1024. * find a IFLA_WIRELESS field in a RtNetlink SET_LINK request,
  1025. * it calls here.
  1026. */
  1027. #ifdef CONFIG_NET_WIRELESS_RTNETLINK
  1028. /* ---------------------------------------------------------------- */
  1029. /*
  1030. * Wrapper to call a standard Wireless Extension GET handler.
  1031. * We do various checks and call the handler with the proper args.
  1032. */
  1033. static int rtnetlink_standard_get(struct net_device * dev,
  1034. struct iw_event * request,
  1035. int request_len,
  1036. iw_handler handler,
  1037. char ** p_buf,
  1038. int * p_len)
  1039. {
  1040. const struct iw_ioctl_description * descr = NULL;
  1041. unsigned int cmd;
  1042. union iwreq_data * wrqu;
  1043. int hdr_len;
  1044. struct iw_request_info info;
  1045. char * buffer = NULL;
  1046. int buffer_size = 0;
  1047. int ret = -EINVAL;
  1048. /* Get the description of the Request */
  1049. cmd = request->cmd;
  1050. if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
  1051. return -EOPNOTSUPP;
  1052. descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
  1053. #ifdef WE_RTNETLINK_DEBUG
  1054. printk(KERN_DEBUG "%s (WE.r) : Found standard handler for 0x%04X\n",
  1055. dev->name, cmd);
  1056. printk(KERN_DEBUG "%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
  1057. #endif /* WE_RTNETLINK_DEBUG */
  1058. /* Check if wrqu is complete */
  1059. hdr_len = event_type_size[descr->header_type];
  1060. if(request_len < hdr_len) {
  1061. #ifdef WE_RTNETLINK_DEBUG
  1062. printk(KERN_DEBUG
  1063. "%s (WE.r) : Wireless request too short (%d)\n",
  1064. dev->name, request_len);
  1065. #endif /* WE_RTNETLINK_DEBUG */
  1066. return -EINVAL;
  1067. }
  1068. /* Prepare the call */
  1069. info.cmd = cmd;
  1070. info.flags = 0;
  1071. /* Check if we have extra data in the reply or not */
  1072. if(descr->header_type != IW_HEADER_TYPE_POINT) {
  1073. /* Create the kernel buffer that we will return.
  1074. * It's at an offset to match the TYPE_POINT case... */
  1075. buffer_size = request_len + IW_EV_POINT_OFF;
  1076. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1077. if (buffer == NULL) {
  1078. return -ENOMEM;
  1079. }
  1080. /* Copy event data */
  1081. memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
  1082. /* Use our own copy of wrqu */
  1083. wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
  1084. + IW_EV_LCP_LEN);
  1085. /* No extra arguments. Trivial to handle */
  1086. ret = handler(dev, &info, wrqu, NULL);
  1087. } else {
  1088. union iwreq_data wrqu_point;
  1089. char * extra = NULL;
  1090. int extra_size = 0;
  1091. /* Get a temp copy of wrqu (skip pointer) */
  1092. memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
  1093. ((char *) request) + IW_EV_LCP_LEN,
  1094. IW_EV_POINT_LEN - IW_EV_LCP_LEN);
  1095. /* Calculate space needed by arguments. Always allocate
  1096. * for max space. Easier, and won't last long... */
  1097. extra_size = descr->max_tokens * descr->token_size;
  1098. /* Support for very large requests */
  1099. if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
  1100. (wrqu_point.data.length > descr->max_tokens))
  1101. extra_size = (wrqu_point.data.length
  1102. * descr->token_size);
  1103. buffer_size = extra_size + IW_EV_POINT_LEN + IW_EV_POINT_OFF;
  1104. #ifdef WE_RTNETLINK_DEBUG
  1105. printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
  1106. dev->name, extra_size, buffer_size);
  1107. #endif /* WE_RTNETLINK_DEBUG */
  1108. /* Create the kernel buffer that we will return */
  1109. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1110. if (buffer == NULL) {
  1111. return -ENOMEM;
  1112. }
  1113. /* Put wrqu in the right place (just before extra).
  1114. * Leave space for IWE header and dummy pointer...
  1115. * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
  1116. */
  1117. memcpy(buffer + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
  1118. ((char *) &wrqu_point) + IW_EV_POINT_OFF,
  1119. IW_EV_POINT_LEN - IW_EV_LCP_LEN);
  1120. wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_LEN);
  1121. /* Extra comes logically after that. Offset +12 bytes. */
  1122. extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_LEN;
  1123. /* Call the handler */
  1124. ret = handler(dev, &info, wrqu, extra);
  1125. /* Calculate real returned length */
  1126. extra_size = (wrqu->data.length * descr->token_size);
  1127. /* Re-adjust reply size */
  1128. request->len = extra_size + IW_EV_POINT_LEN;
  1129. /* Put the iwe header where it should, i.e. scrap the
  1130. * dummy pointer. */
  1131. memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_LEN);
  1132. #ifdef WE_RTNETLINK_DEBUG
  1133. printk(KERN_DEBUG "%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev->name, cmd, hdr_len, wrqu->data.length, extra_size, buffer_size);
  1134. #endif /* WE_RTNETLINK_DEBUG */
  1135. /* Check if there is enough buffer up there */
  1136. if(wrqu_point.data.length < wrqu->data.length)
  1137. ret = -E2BIG;
  1138. }
  1139. /* Return the buffer to the caller */
  1140. if (!ret) {
  1141. *p_buf = buffer;
  1142. *p_len = request->len;
  1143. } else {
  1144. /* Cleanup */
  1145. if(buffer)
  1146. kfree(buffer);
  1147. }
  1148. return ret;
  1149. }
  1150. /* ---------------------------------------------------------------- */
  1151. /*
  1152. * Wrapper to call a standard Wireless Extension SET handler.
  1153. * We do various checks and call the handler with the proper args.
  1154. */
  1155. static inline int rtnetlink_standard_set(struct net_device * dev,
  1156. struct iw_event * request,
  1157. int request_len,
  1158. iw_handler handler)
  1159. {
  1160. const struct iw_ioctl_description * descr = NULL;
  1161. unsigned int cmd;
  1162. union iwreq_data * wrqu;
  1163. union iwreq_data wrqu_point;
  1164. int hdr_len;
  1165. char * extra = NULL;
  1166. int extra_size = 0;
  1167. struct iw_request_info info;
  1168. int ret = -EINVAL;
  1169. /* Get the description of the Request */
  1170. cmd = request->cmd;
  1171. if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
  1172. return -EOPNOTSUPP;
  1173. descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
  1174. #ifdef WE_RTNETLINK_DEBUG
  1175. printk(KERN_DEBUG "%s (WE.r) : Found standard SET handler for 0x%04X\n",
  1176. dev->name, cmd);
  1177. printk(KERN_DEBUG "%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
  1178. #endif /* WE_RTNETLINK_DEBUG */
  1179. /* Extract fixed header from request. This is properly aligned. */
  1180. wrqu = &request->u;
  1181. /* Check if wrqu is complete */
  1182. hdr_len = event_type_size[descr->header_type];
  1183. if(request_len < hdr_len) {
  1184. #ifdef WE_RTNETLINK_DEBUG
  1185. printk(KERN_DEBUG
  1186. "%s (WE.r) : Wireless request too short (%d)\n",
  1187. dev->name, request_len);
  1188. #endif /* WE_RTNETLINK_DEBUG */
  1189. return -EINVAL;
  1190. }
  1191. /* Prepare the call */
  1192. info.cmd = cmd;
  1193. info.flags = 0;
  1194. /* Check if we have extra data in the request or not */
  1195. if(descr->header_type != IW_HEADER_TYPE_POINT) {
  1196. /* No extra arguments. Trivial to handle */
  1197. ret = handler(dev, &info, wrqu, NULL);
  1198. } else {
  1199. int extra_len;
  1200. /* Put wrqu in the right place (skip pointer) */
  1201. memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
  1202. wrqu, IW_EV_POINT_LEN - IW_EV_LCP_LEN);
  1203. /* Don't forget about the event code... */
  1204. wrqu = &wrqu_point;
  1205. /* Check if number of token fits within bounds */
  1206. if(wrqu_point.data.length > descr->max_tokens)
  1207. return -E2BIG;
  1208. if(wrqu_point.data.length < descr->min_tokens)
  1209. return -EINVAL;
  1210. /* Real length of payload */
  1211. extra_len = wrqu_point.data.length * descr->token_size;
  1212. /* Check if request is self consistent */
  1213. if((request_len - hdr_len) < extra_len) {
  1214. #ifdef WE_RTNETLINK_DEBUG
  1215. printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
  1216. dev->name, extra_size);
  1217. #endif /* WE_RTNETLINK_DEBUG */
  1218. return -EINVAL;
  1219. }
  1220. #ifdef WE_RTNETLINK_DEBUG
  1221. printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
  1222. dev->name, extra_size);
  1223. #endif /* WE_RTNETLINK_DEBUG */
  1224. /* Always allocate for max space. Easier, and won't last
  1225. * long... */
  1226. extra_size = descr->max_tokens * descr->token_size;
  1227. extra = kmalloc(extra_size, GFP_KERNEL);
  1228. if (extra == NULL)
  1229. return -ENOMEM;
  1230. /* Copy extra in aligned buffer */
  1231. memcpy(extra, ((char *) request) + hdr_len, extra_len);
  1232. /* Call the handler */
  1233. ret = handler(dev, &info, &wrqu_point, extra);
  1234. }
  1235. #ifdef WE_SET_EVENT
  1236. /* Generate an event to notify listeners of the change */
  1237. if((descr->flags & IW_DESCR_FLAG_EVENT) &&
  1238. ((ret == 0) || (ret == -EIWCOMMIT))) {
  1239. if(descr->flags & IW_DESCR_FLAG_RESTRICT)
  1240. /* If the event is restricted, don't
  1241. * export the payload */
  1242. wireless_send_event(dev, cmd, wrqu, NULL);
  1243. else
  1244. wireless_send_event(dev, cmd, wrqu, extra);
  1245. }
  1246. #endif /* WE_SET_EVENT */
  1247. /* Cleanup - I told you it wasn't that long ;-) */
  1248. if(extra)
  1249. kfree(extra);
  1250. /* Call commit handler if needed and defined */
  1251. if(ret == -EIWCOMMIT)
  1252. ret = call_commit_handler(dev);
  1253. return ret;
  1254. }
  1255. /* ---------------------------------------------------------------- */
  1256. /*
  1257. * Wrapper to call a private Wireless Extension GET handler.
  1258. * Same as above...
  1259. * It's not as nice and slimline as the standard wrapper. The cause
  1260. * is struct iw_priv_args, which was not really designed for the
  1261. * job we are going here.
  1262. *
  1263. * IMPORTANT : This function prevent to set and get data on the same
  1264. * IOCTL and enforce the SET/GET convention. Not doing it would be
  1265. * far too hairy...
  1266. * If you need to set and get data at the same time, please don't use
  1267. * a iw_handler but process it in your ioctl handler (i.e. use the
  1268. * old driver API).
  1269. */
  1270. static inline int rtnetlink_private_get(struct net_device * dev,
  1271. struct iw_event * request,
  1272. int request_len,
  1273. iw_handler handler,
  1274. char ** p_buf,
  1275. int * p_len)
  1276. {
  1277. const struct iw_priv_args * descr = NULL;
  1278. unsigned int cmd;
  1279. union iwreq_data * wrqu;
  1280. int hdr_len;
  1281. struct iw_request_info info;
  1282. int extra_size = 0;
  1283. int i;
  1284. char * buffer = NULL;
  1285. int buffer_size = 0;
  1286. int ret = -EINVAL;
  1287. /* Get the description of the Request */
  1288. cmd = request->cmd;
  1289. for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
  1290. if(cmd == dev->wireless_handlers->private_args[i].cmd) {
  1291. descr = &(dev->wireless_handlers->private_args[i]);
  1292. break;
  1293. }
  1294. if(descr == NULL)
  1295. return -EOPNOTSUPP;
  1296. #ifdef WE_RTNETLINK_DEBUG
  1297. printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
  1298. dev->name, cmd);
  1299. printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
  1300. dev->name, descr->name, descr->set_args, descr->get_args);
  1301. #endif /* WE_RTNETLINK_DEBUG */
  1302. /* Compute the max size of the get arguments */
  1303. extra_size = get_priv_size(descr->get_args);
  1304. /* Does it fits in wrqu ? */
  1305. if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
  1306. (extra_size <= IFNAMSIZ)) {
  1307. hdr_len = extra_size;
  1308. extra_size = 0;
  1309. } else {
  1310. hdr_len = IW_EV_POINT_LEN;
  1311. }
  1312. /* Check if wrqu is complete */
  1313. if(request_len < hdr_len) {
  1314. #ifdef WE_RTNETLINK_DEBUG
  1315. printk(KERN_DEBUG
  1316. "%s (WE.r) : Wireless request too short (%d)\n",
  1317. dev->name, request_len);
  1318. #endif /* WE_RTNETLINK_DEBUG */
  1319. return -EINVAL;
  1320. }
  1321. /* Prepare the call */
  1322. info.cmd = cmd;
  1323. info.flags = 0;
  1324. /* Check if we have a pointer to user space data or not. */
  1325. if(extra_size == 0) {
  1326. /* Create the kernel buffer that we will return.
  1327. * It's at an offset to match the TYPE_POINT case... */
  1328. buffer_size = request_len + IW_EV_POINT_OFF;
  1329. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1330. if (buffer == NULL) {
  1331. return -ENOMEM;
  1332. }
  1333. /* Copy event data */
  1334. memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
  1335. /* Use our own copy of wrqu */
  1336. wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
  1337. + IW_EV_LCP_LEN);
  1338. /* No extra arguments. Trivial to handle */
  1339. ret = handler(dev, &info, wrqu, (char *) wrqu);
  1340. } else {
  1341. char * extra;
  1342. /* Buffer for full reply */
  1343. buffer_size = extra_size + IW_EV_POINT_LEN + IW_EV_POINT_OFF;
  1344. #ifdef WE_RTNETLINK_DEBUG
  1345. printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
  1346. dev->name, extra_size, buffer_size);
  1347. #endif /* WE_RTNETLINK_DEBUG */
  1348. /* Create the kernel buffer that we will return */
  1349. buffer = kmalloc(buffer_size, GFP_KERNEL);
  1350. if (buffer == NULL) {
  1351. return -ENOMEM;
  1352. }
  1353. /* Put wrqu in the right place (just before extra).
  1354. * Leave space for IWE header and dummy pointer...
  1355. * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
  1356. */
  1357. memcpy(buffer + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
  1358. ((char *) request) + IW_EV_LCP_LEN,
  1359. IW_EV_POINT_LEN - IW_EV_LCP_LEN);
  1360. wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_LEN);
  1361. /* Extra comes logically after that. Offset +12 bytes. */
  1362. extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_LEN;
  1363. /* Call the handler */
  1364. ret = handler(dev, &info, wrqu, extra);
  1365. /* Adjust for the actual length if it's variable,
  1366. * avoid leaking kernel bits outside. */
  1367. if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
  1368. extra_size = adjust_priv_size(descr->get_args, wrqu);
  1369. /* Re-adjust reply size */
  1370. request->len = extra_size + IW_EV_POINT_LEN;
  1371. /* Put the iwe header where it should, i.e. scrap the
  1372. * dummy pointer. */
  1373. memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_LEN);
  1374. #ifdef WE_RTNETLINK_DEBUG
  1375. printk(KERN_DEBUG "%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev->name, cmd, hdr_len, wrqu->data.length, extra_size, buffer_size);
  1376. #endif /* WE_RTNETLINK_DEBUG */
  1377. }
  1378. /* Return the buffer to the caller */
  1379. if (!ret) {
  1380. *p_buf = buffer;
  1381. *p_len = request->len;
  1382. } else {
  1383. /* Cleanup */
  1384. if(buffer)
  1385. kfree(buffer);
  1386. }
  1387. return ret;
  1388. }
  1389. /* ---------------------------------------------------------------- */
  1390. /*
  1391. * Wrapper to call a private Wireless Extension SET handler.
  1392. * Same as above...
  1393. * It's not as nice and slimline as the standard wrapper. The cause
  1394. * is struct iw_priv_args, which was not really designed for the
  1395. * job we are going here.
  1396. *
  1397. * IMPORTANT : This function prevent to set and get data on the same
  1398. * IOCTL and enforce the SET/GET convention. Not doing it would be
  1399. * far too hairy...
  1400. * If you need to set and get data at the same time, please don't use
  1401. * a iw_handler but process it in your ioctl handler (i.e. use the
  1402. * old driver API).
  1403. */
  1404. static inline int rtnetlink_private_set(struct net_device * dev,
  1405. struct iw_event * request,
  1406. int request_len,
  1407. iw_handler handler)
  1408. {
  1409. const struct iw_priv_args * descr = NULL;
  1410. unsigned int cmd;
  1411. union iwreq_data * wrqu;
  1412. union iwreq_data wrqu_point;
  1413. int hdr_len;
  1414. char * extra = NULL;
  1415. int extra_size = 0;
  1416. int offset = 0; /* For sub-ioctls */
  1417. struct iw_request_info info;
  1418. int i;
  1419. int ret = -EINVAL;
  1420. /* Get the description of the Request */
  1421. cmd = request->cmd;
  1422. for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
  1423. if(cmd == dev->wireless_handlers->private_args[i].cmd) {
  1424. descr = &(dev->wireless_handlers->private_args[i]);
  1425. break;
  1426. }
  1427. if(descr == NULL)
  1428. return -EOPNOTSUPP;
  1429. #ifdef WE_RTNETLINK_DEBUG
  1430. printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
  1431. ifr->ifr_name, cmd);
  1432. printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
  1433. dev->name, descr->name, descr->set_args, descr->get_args);
  1434. #endif /* WE_RTNETLINK_DEBUG */
  1435. /* Compute the size of the set arguments */
  1436. /* Check for sub-ioctl handler */
  1437. if(descr->name[0] == '\0')
  1438. /* Reserve one int for sub-ioctl index */
  1439. offset = sizeof(__u32);
  1440. /* Size of set arguments */
  1441. extra_size = get_priv_size(descr->set_args);
  1442. /* Does it fits in wrqu ? */
  1443. if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
  1444. (extra_size <= IFNAMSIZ)) {
  1445. hdr_len = IW_EV_LCP_LEN + extra_size;
  1446. extra_size = 0;
  1447. } else {
  1448. hdr_len = IW_EV_POINT_LEN;
  1449. }
  1450. /* Extract fixed header from request. This is properly aligned. */
  1451. wrqu = &request->u;
  1452. /* Check if wrqu is complete */
  1453. if(request_len < hdr_len) {
  1454. #ifdef WE_RTNETLINK_DEBUG
  1455. printk(KERN_DEBUG
  1456. "%s (WE.r) : Wireless request too short (%d)\n",
  1457. dev->name, request_len);
  1458. #endif /* WE_RTNETLINK_DEBUG */
  1459. return -EINVAL;
  1460. }
  1461. /* Prepare the call */
  1462. info.cmd = cmd;
  1463. info.flags = 0;
  1464. /* Check if we have a pointer to user space data or not. */
  1465. if(extra_size == 0) {
  1466. /* No extra arguments. Trivial to handle */
  1467. ret = handler(dev, &info, wrqu, (char *) wrqu);
  1468. } else {
  1469. int extra_len;
  1470. /* Put wrqu in the right place (skip pointer) */
  1471. memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
  1472. wrqu, IW_EV_POINT_LEN - IW_EV_LCP_LEN);
  1473. /* Does it fits within bounds ? */
  1474. if(wrqu_point.data.length > (descr->set_args &
  1475. IW_PRIV_SIZE_MASK))
  1476. return -E2BIG;
  1477. /* Real length of payload */
  1478. extra_len = adjust_priv_size(descr->set_args, &wrqu_point);
  1479. /* Check if request is self consistent */
  1480. if((request_len - hdr_len) < extra_len) {
  1481. #ifdef WE_RTNETLINK_DEBUG
  1482. printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
  1483. dev->name, extra_size);
  1484. #endif /* WE_RTNETLINK_DEBUG */
  1485. return -EINVAL;
  1486. }
  1487. #ifdef WE_RTNETLINK_DEBUG
  1488. printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
  1489. dev->name, extra_size);
  1490. #endif /* WE_RTNETLINK_DEBUG */
  1491. /* Always allocate for max space. Easier, and won't last
  1492. * long... */
  1493. extra = kmalloc(extra_size, GFP_KERNEL);
  1494. if (extra == NULL)
  1495. return -ENOMEM;
  1496. /* Copy extra in aligned buffer */
  1497. memcpy(extra, ((char *) request) + hdr_len, extra_len);
  1498. /* Call the handler */
  1499. ret = handler(dev, &info, &wrqu_point, extra);
  1500. /* Cleanup - I told you it wasn't that long ;-) */
  1501. kfree(extra);
  1502. }
  1503. /* Call commit handler if needed and defined */
  1504. if(ret == -EIWCOMMIT)
  1505. ret = call_commit_handler(dev);
  1506. return ret;
  1507. }
  1508. /* ---------------------------------------------------------------- */
  1509. /*
  1510. * Main RtNetlink dispatcher. Called from the main networking code
  1511. * (do_getlink() in net/core/rtnetlink.c).
  1512. * Check the type of Request and call the appropriate wrapper...
  1513. */
  1514. int wireless_rtnetlink_get(struct net_device * dev,
  1515. char * data,
  1516. int len,
  1517. char ** p_buf,
  1518. int * p_len)
  1519. {
  1520. struct iw_event * request = (struct iw_event *) data;
  1521. iw_handler handler;
  1522. /* Check length */
  1523. if(len < IW_EV_LCP_LEN) {
  1524. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
  1525. dev->name, len);
  1526. return -EINVAL;
  1527. }
  1528. /* ReCheck length (len may have padding) */
  1529. if(request->len > len) {
  1530. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
  1531. dev->name, request->len, len);
  1532. return -EINVAL;
  1533. }
  1534. /* Only accept GET requests in here */
  1535. if(!IW_IS_GET(request->cmd))
  1536. return -EOPNOTSUPP;
  1537. /* Special cases */
  1538. if(request->cmd == SIOCGIWSTATS)
  1539. /* Get Wireless Stats */
  1540. return rtnetlink_standard_get(dev,
  1541. request,
  1542. request->len,
  1543. &iw_handler_get_iwstats,
  1544. p_buf, p_len);
  1545. if(request->cmd == SIOCGIWPRIV) {
  1546. /* Check if we have some wireless handlers defined */
  1547. if(dev->wireless_handlers == NULL)
  1548. return -EOPNOTSUPP;
  1549. /* Get Wireless Stats */
  1550. return rtnetlink_standard_get(dev,
  1551. request,
  1552. request->len,
  1553. &iw_handler_get_private,
  1554. p_buf, p_len);
  1555. }
  1556. /* Basic check */
  1557. if (!netif_device_present(dev))
  1558. return -ENODEV;
  1559. /* Try to find the handler */
  1560. handler = get_handler(dev, request->cmd);
  1561. if(handler != NULL) {
  1562. /* Standard and private are not the same */
  1563. if(request->cmd < SIOCIWFIRSTPRIV)
  1564. return rtnetlink_standard_get(dev,
  1565. request,
  1566. request->len,
  1567. handler,
  1568. p_buf, p_len);
  1569. else
  1570. return rtnetlink_private_get(dev,
  1571. request,
  1572. request->len,
  1573. handler,
  1574. p_buf, p_len);
  1575. }
  1576. return -EOPNOTSUPP;
  1577. }
  1578. /* ---------------------------------------------------------------- */
  1579. /*
  1580. * Main RtNetlink dispatcher. Called from the main networking code
  1581. * (do_setlink() in net/core/rtnetlink.c).
  1582. * Check the type of Request and call the appropriate wrapper...
  1583. */
  1584. int wireless_rtnetlink_set(struct net_device * dev,
  1585. char * data,
  1586. int len)
  1587. {
  1588. struct iw_event * request = (struct iw_event *) data;
  1589. iw_handler handler;
  1590. /* Check length */
  1591. if(len < IW_EV_LCP_LEN) {
  1592. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
  1593. dev->name, len);
  1594. return -EINVAL;
  1595. }
  1596. /* ReCheck length (len may have padding) */
  1597. if(request->len > len) {
  1598. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
  1599. dev->name, request->len, len);
  1600. return -EINVAL;
  1601. }
  1602. /* Only accept SET requests in here */
  1603. if(!IW_IS_SET(request->cmd))
  1604. return -EOPNOTSUPP;
  1605. /* Basic check */
  1606. if (!netif_device_present(dev))
  1607. return -ENODEV;
  1608. /* New driver API : try to find the handler */
  1609. handler = get_handler(dev, request->cmd);
  1610. if(handler != NULL) {
  1611. /* Standard and private are not the same */
  1612. if(request->cmd < SIOCIWFIRSTPRIV)
  1613. return rtnetlink_standard_set(dev,
  1614. request,
  1615. request->len,
  1616. handler);
  1617. else
  1618. return rtnetlink_private_set(dev,
  1619. request,
  1620. request->len,
  1621. handler);
  1622. }
  1623. return -EOPNOTSUPP;
  1624. }
  1625. #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
  1626. /************************* EVENT PROCESSING *************************/
  1627. /*
  1628. * Process events generated by the wireless layer or the driver.
  1629. * Most often, the event will be propagated through rtnetlink
  1630. */
  1631. #ifdef WE_EVENT_RTNETLINK
  1632. /* ---------------------------------------------------------------- */
  1633. /*
  1634. * Fill a rtnetlink message with our event data.
  1635. * Note that we propage only the specified event and don't dump the
  1636. * current wireless config. Dumping the wireless config is far too
  1637. * expensive (for each parameter, the driver need to query the hardware).
  1638. */
  1639. static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
  1640. struct net_device * dev,
  1641. int type,
  1642. char * event,
  1643. int event_len)
  1644. {
  1645. struct ifinfomsg *r;
  1646. struct nlmsghdr *nlh;
  1647. unsigned char *b = skb->tail;
  1648. nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
  1649. r = NLMSG_DATA(nlh);
  1650. r->ifi_family = AF_UNSPEC;
  1651. r->__ifi_pad = 0;
  1652. r->ifi_type = dev->type;
  1653. r->ifi_index = dev->ifindex;
  1654. r->ifi_flags = dev_get_flags(dev);
  1655. r->ifi_change = 0; /* Wireless changes don't affect those flags */
  1656. /* Add the wireless events in the netlink packet */
  1657. RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
  1658. nlh->nlmsg_len = skb->tail - b;
  1659. return skb->len;
  1660. nlmsg_failure:
  1661. rtattr_failure:
  1662. skb_trim(skb, b - skb->data);
  1663. return -1;
  1664. }
  1665. /* ---------------------------------------------------------------- */
  1666. /*
  1667. * Create and broadcast and send it on the standard rtnetlink socket
  1668. * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
  1669. * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
  1670. * within a RTM_NEWLINK event.
  1671. */
  1672. static inline void rtmsg_iwinfo(struct net_device * dev,
  1673. char * event,
  1674. int event_len)
  1675. {
  1676. struct sk_buff *skb;
  1677. int size = NLMSG_GOODSIZE;
  1678. skb = alloc_skb(size, GFP_ATOMIC);
  1679. if (!skb)
  1680. return;
  1681. if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
  1682. event, event_len) < 0) {
  1683. kfree_skb(skb);
  1684. return;
  1685. }
  1686. NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
  1687. netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
  1688. }
  1689. #endif /* WE_EVENT_RTNETLINK */
  1690. /* ---------------------------------------------------------------- */
  1691. /*
  1692. * Main event dispatcher. Called from other parts and drivers.
  1693. * Send the event on the appropriate channels.
  1694. * May be called from interrupt context.
  1695. */
  1696. void wireless_send_event(struct net_device * dev,
  1697. unsigned int cmd,
  1698. union iwreq_data * wrqu,
  1699. char * extra)
  1700. {
  1701. const struct iw_ioctl_description * descr = NULL;
  1702. int extra_len = 0;
  1703. struct iw_event *event; /* Mallocated whole event */
  1704. int event_len; /* Its size */
  1705. int hdr_len; /* Size of the event header */
  1706. int wrqu_off = 0; /* Offset in wrqu */
  1707. /* Don't "optimise" the following variable, it will crash */
  1708. unsigned cmd_index; /* *MUST* be unsigned */
  1709. /* Get the description of the Event */
  1710. if(cmd <= SIOCIWLAST) {
  1711. cmd_index = cmd - SIOCIWFIRST;
  1712. if(cmd_index < standard_ioctl_num)
  1713. descr = &(standard_ioctl[cmd_index]);
  1714. } else {
  1715. cmd_index = cmd - IWEVFIRST;
  1716. if(cmd_index < standard_event_num)
  1717. descr = &(standard_event[cmd_index]);
  1718. }
  1719. /* Don't accept unknown events */
  1720. if(descr == NULL) {
  1721. /* Note : we don't return an error to the driver, because
  1722. * the driver would not know what to do about it. It can't
  1723. * return an error to the user, because the event is not
  1724. * initiated by a user request.
  1725. * The best the driver could do is to log an error message.
  1726. * We will do it ourselves instead...
  1727. */
  1728. printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
  1729. dev->name, cmd);
  1730. return;
  1731. }
  1732. #ifdef WE_EVENT_DEBUG
  1733. printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
  1734. dev->name, cmd);
  1735. printk(KERN_DEBUG "%s (WE) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
  1736. #endif /* WE_EVENT_DEBUG */
  1737. /* Check extra parameters and set extra_len */
  1738. if(descr->header_type == IW_HEADER_TYPE_POINT) {
  1739. /* Check if number of token fits within bounds */
  1740. if(wrqu->data.length > descr->max_tokens) {
  1741. printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
  1742. return;
  1743. }
  1744. if(wrqu->data.length < descr->min_tokens) {
  1745. printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
  1746. return;
  1747. }
  1748. /* Calculate extra_len - extra is NULL for restricted events */
  1749. if(extra != NULL)
  1750. extra_len = wrqu->data.length * descr->token_size;
  1751. /* Always at an offset in wrqu */
  1752. wrqu_off = IW_EV_POINT_OFF;
  1753. #ifdef WE_EVENT_DEBUG
  1754. printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
  1755. #endif /* WE_EVENT_DEBUG */
  1756. }
  1757. /* Total length of the event */
  1758. hdr_len = event_type_size[descr->header_type];
  1759. event_len = hdr_len + extra_len;
  1760. #ifdef WE_EVENT_DEBUG
  1761. printk(KERN_DEBUG "%s (WE) : Event 0x%04X, hdr_len %d, wrqu_off %d, event_len %d\n", dev->name, cmd, hdr_len, wrqu_off, event_len);
  1762. #endif /* WE_EVENT_DEBUG */
  1763. /* Create temporary buffer to hold the event */
  1764. event = kmalloc(event_len, GFP_ATOMIC);
  1765. if(event == NULL)
  1766. return;
  1767. /* Fill event */
  1768. event->len = event_len;
  1769. event->cmd = cmd;
  1770. memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
  1771. if(extra != NULL)
  1772. memcpy(((char *) event) + hdr_len, extra, extra_len);
  1773. #ifdef WE_EVENT_RTNETLINK
  1774. /* Send via the RtNetlink event channel */
  1775. rtmsg_iwinfo(dev, (char *) event, event_len);
  1776. #endif /* WE_EVENT_RTNETLINK */
  1777. /* Cleanup */
  1778. kfree(event);
  1779. return; /* Always success, I guess ;-) */
  1780. }
  1781. /********************** ENHANCED IWSPY SUPPORT **********************/
  1782. /*
  1783. * In the old days, the driver was handling spy support all by itself.
  1784. * Now, the driver can delegate this task to Wireless Extensions.
  1785. * It needs to use those standard spy iw_handler in struct iw_handler_def,
  1786. * push data to us via wireless_spy_update() and include struct iw_spy_data
  1787. * in its private part (and export it in net_device->wireless_data->spy_data).
  1788. * One of the main advantage of centralising spy support here is that
  1789. * it becomes much easier to improve and extend it without having to touch
  1790. * the drivers. One example is the addition of the Spy-Threshold events.
  1791. */
  1792. /* ---------------------------------------------------------------- */
  1793. /*
  1794. * Return the pointer to the spy data in the driver.
  1795. * Because this is called on the Rx path via wireless_spy_update(),
  1796. * we want it to be efficient...
  1797. */
  1798. static inline struct iw_spy_data * get_spydata(struct net_device *dev)
  1799. {
  1800. /* This is the new way */
  1801. if(dev->wireless_data)
  1802. return(dev->wireless_data->spy_data);
  1803. return NULL;
  1804. }
  1805. /*------------------------------------------------------------------*/
  1806. /*
  1807. * Standard Wireless Handler : set Spy List
  1808. */
  1809. int iw_handler_set_spy(struct net_device * dev,
  1810. struct iw_request_info * info,
  1811. union iwreq_data * wrqu,
  1812. char * extra)
  1813. {
  1814. struct iw_spy_data * spydata = get_spydata(dev);
  1815. struct sockaddr * address = (struct sockaddr *) extra;
  1816. /* Make sure driver is not buggy or using the old API */
  1817. if(!spydata)
  1818. return -EOPNOTSUPP;
  1819. /* Disable spy collection while we copy the addresses.
  1820. * While we copy addresses, any call to wireless_spy_update()
  1821. * will NOP. This is OK, as anyway the addresses are changing. */
  1822. spydata->spy_number = 0;
  1823. /* We want to operate without locking, because wireless_spy_update()
  1824. * most likely will happen in the interrupt handler, and therefore
  1825. * have its own locking constraints and needs performance.
  1826. * The rtnl_lock() make sure we don't race with the other iw_handlers.
  1827. * This make sure wireless_spy_update() "see" that the spy list
  1828. * is temporarily disabled. */
  1829. wmb();
  1830. /* Are there are addresses to copy? */
  1831. if(wrqu->data.length > 0) {
  1832. int i;
  1833. /* Copy addresses */
  1834. for(i = 0; i < wrqu->data.length; i++)
  1835. memcpy(spydata->spy_address[i], address[i].sa_data,
  1836. ETH_ALEN);
  1837. /* Reset stats */
  1838. memset(spydata->spy_stat, 0,
  1839. sizeof(struct iw_quality) * IW_MAX_SPY);
  1840. #ifdef WE_SPY_DEBUG
  1841. printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
  1842. for (i = 0; i < wrqu->data.length; i++)
  1843. printk(KERN_DEBUG
  1844. "%02X:%02X:%02X:%02X:%02X:%02X \n",
  1845. spydata->spy_address[i][0],
  1846. spydata->spy_address[i][1],
  1847. spydata->spy_address[i][2],
  1848. spydata->spy_address[i][3],
  1849. spydata->spy_address[i][4],
  1850. spydata->spy_address[i][5]);
  1851. #endif /* WE_SPY_DEBUG */
  1852. }
  1853. /* Make sure above is updated before re-enabling */
  1854. wmb();
  1855. /* Enable addresses */
  1856. spydata->spy_number = wrqu->data.length;
  1857. return 0;
  1858. }
  1859. /*------------------------------------------------------------------*/
  1860. /*
  1861. * Standard Wireless Handler : get Spy List
  1862. */
  1863. int iw_handler_get_spy(struct net_device * dev,
  1864. struct iw_request_info * info,
  1865. union iwreq_data * wrqu,
  1866. char * extra)
  1867. {
  1868. struct iw_spy_data * spydata = get_spydata(dev);
  1869. struct sockaddr * address = (struct sockaddr *) extra;
  1870. int i;
  1871. /* Make sure driver is not buggy or using the old API */
  1872. if(!spydata)
  1873. return -EOPNOTSUPP;
  1874. wrqu->data.length = spydata->spy_number;
  1875. /* Copy addresses. */
  1876. for(i = 0; i < spydata->spy_number; i++) {
  1877. memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
  1878. address[i].sa_family = AF_UNIX;
  1879. }
  1880. /* Copy stats to the user buffer (just after). */
  1881. if(spydata->spy_number > 0)
  1882. memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
  1883. spydata->spy_stat,
  1884. sizeof(struct iw_quality) * spydata->spy_number);
  1885. /* Reset updated flags. */
  1886. for(i = 0; i < spydata->spy_number; i++)
  1887. spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
  1888. return 0;
  1889. }
  1890. /*------------------------------------------------------------------*/
  1891. /*
  1892. * Standard Wireless Handler : set spy threshold
  1893. */
  1894. int iw_handler_set_thrspy(struct net_device * dev,
  1895. struct iw_request_info *info,
  1896. union iwreq_data * wrqu,
  1897. char * extra)
  1898. {
  1899. struct iw_spy_data * spydata = get_spydata(dev);
  1900. struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
  1901. /* Make sure driver is not buggy or using the old API */
  1902. if(!spydata)
  1903. return -EOPNOTSUPP;
  1904. /* Just do it */
  1905. memcpy(&(spydata->spy_thr_low), &(threshold->low),
  1906. 2 * sizeof(struct iw_quality));
  1907. /* Clear flag */
  1908. memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
  1909. #ifdef WE_SPY_DEBUG
  1910. printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
  1911. #endif /* WE_SPY_DEBUG */
  1912. return 0;
  1913. }
  1914. /*------------------------------------------------------------------*/
  1915. /*
  1916. * Standard Wireless Handler : get spy threshold
  1917. */
  1918. int iw_handler_get_thrspy(struct net_device * dev,
  1919. struct iw_request_info *info,
  1920. union iwreq_data * wrqu,
  1921. char * extra)
  1922. {
  1923. struct iw_spy_data * spydata = get_spydata(dev);
  1924. struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
  1925. /* Make sure driver is not buggy or using the old API */
  1926. if(!spydata)
  1927. return -EOPNOTSUPP;
  1928. /* Just do it */
  1929. memcpy(&(threshold->low), &(spydata->spy_thr_low),
  1930. 2 * sizeof(struct iw_quality));
  1931. return 0;
  1932. }
  1933. /*------------------------------------------------------------------*/
  1934. /*
  1935. * Prepare and send a Spy Threshold event
  1936. */
  1937. static void iw_send_thrspy_event(struct net_device * dev,
  1938. struct iw_spy_data * spydata,
  1939. unsigned char * address,
  1940. struct iw_quality * wstats)
  1941. {
  1942. union iwreq_data wrqu;
  1943. struct iw_thrspy threshold;
  1944. /* Init */
  1945. wrqu.data.length = 1;
  1946. wrqu.data.flags = 0;
  1947. /* Copy address */
  1948. memcpy(threshold.addr.sa_data, address, ETH_ALEN);
  1949. threshold.addr.sa_family = ARPHRD_ETHER;
  1950. /* Copy stats */
  1951. memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
  1952. /* Copy also thresholds */
  1953. memcpy(&(threshold.low), &(spydata->spy_thr_low),
  1954. 2 * sizeof(struct iw_quality));
  1955. #ifdef WE_SPY_DEBUG
  1956. printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
  1957. threshold.addr.sa_data[0],
  1958. threshold.addr.sa_data[1],
  1959. threshold.addr.sa_data[2],
  1960. threshold.addr.sa_data[3],
  1961. threshold.addr.sa_data[4],
  1962. threshold.addr.sa_data[5], threshold.qual.level);
  1963. #endif /* WE_SPY_DEBUG */
  1964. /* Send event to user space */
  1965. wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
  1966. }
  1967. /* ---------------------------------------------------------------- */
  1968. /*
  1969. * Call for the driver to update the spy data.
  1970. * For now, the spy data is a simple array. As the size of the array is
  1971. * small, this is good enough. If we wanted to support larger number of
  1972. * spy addresses, we should use something more efficient...
  1973. */
  1974. void wireless_spy_update(struct net_device * dev,
  1975. unsigned char * address,
  1976. struct iw_quality * wstats)
  1977. {
  1978. struct iw_spy_data * spydata = get_spydata(dev);
  1979. int i;
  1980. int match = -1;
  1981. /* Make sure driver is not buggy or using the old API */
  1982. if(!spydata)
  1983. return;
  1984. #ifdef WE_SPY_DEBUG
  1985. printk(KERN_DEBUG "wireless_spy_update() : wireless_data %p, spydata %p, address %02X:%02X:%02X:%02X:%02X:%02X\n", dev->wireless_data, spydata, address[0], address[1], address[2], address[3], address[4], address[5]);
  1986. #endif /* WE_SPY_DEBUG */
  1987. /* Update all records that match */
  1988. for(i = 0; i < spydata->spy_number; i++)
  1989. if(!compare_ether_addr(address, spydata->spy_address[i])) {
  1990. memcpy(&(spydata->spy_stat[i]), wstats,
  1991. sizeof(struct iw_quality));
  1992. match = i;
  1993. }
  1994. /* Generate an event if we cross the spy threshold.
  1995. * To avoid event storms, we have a simple hysteresis : we generate
  1996. * event only when we go under the low threshold or above the
  1997. * high threshold. */
  1998. if(match >= 0) {
  1999. if(spydata->spy_thr_under[match]) {
  2000. if(wstats->level > spydata->spy_thr_high.level) {
  2001. spydata->spy_thr_under[match] = 0;
  2002. iw_send_thrspy_event(dev, spydata,
  2003. address, wstats);
  2004. }
  2005. } else {
  2006. if(wstats->level < spydata->spy_thr_low.level) {
  2007. spydata->spy_thr_under[match] = 1;
  2008. iw_send_thrspy_event(dev, spydata,
  2009. address, wstats);
  2010. }
  2011. }
  2012. }
  2013. }
  2014. EXPORT_SYMBOL(iw_handler_get_spy);
  2015. EXPORT_SYMBOL(iw_handler_get_thrspy);
  2016. EXPORT_SYMBOL(iw_handler_set_spy);
  2017. EXPORT_SYMBOL(iw_handler_set_thrspy);
  2018. EXPORT_SYMBOL(wireless_send_event);
  2019. EXPORT_SYMBOL(wireless_spy_update);