wireless.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  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. /* If command is `get the encoding parameters', check if
  1538. * the user has the right to do it */
  1539. if (request->cmd == SIOCGIWENCODE ||
  1540. request->cmd == SIOCGIWENCODEEXT) {
  1541. if (!capable(CAP_NET_ADMIN))
  1542. return -EPERM;
  1543. }
  1544. /* Special cases */
  1545. if(request->cmd == SIOCGIWSTATS)
  1546. /* Get Wireless Stats */
  1547. return rtnetlink_standard_get(dev,
  1548. request,
  1549. request->len,
  1550. &iw_handler_get_iwstats,
  1551. p_buf, p_len);
  1552. if(request->cmd == SIOCGIWPRIV) {
  1553. /* Check if we have some wireless handlers defined */
  1554. if(dev->wireless_handlers == NULL)
  1555. return -EOPNOTSUPP;
  1556. /* Get Wireless Stats */
  1557. return rtnetlink_standard_get(dev,
  1558. request,
  1559. request->len,
  1560. &iw_handler_get_private,
  1561. p_buf, p_len);
  1562. }
  1563. /* Basic check */
  1564. if (!netif_device_present(dev))
  1565. return -ENODEV;
  1566. /* Try to find the handler */
  1567. handler = get_handler(dev, request->cmd);
  1568. if(handler != NULL) {
  1569. /* Standard and private are not the same */
  1570. if(request->cmd < SIOCIWFIRSTPRIV)
  1571. return rtnetlink_standard_get(dev,
  1572. request,
  1573. request->len,
  1574. handler,
  1575. p_buf, p_len);
  1576. else
  1577. return rtnetlink_private_get(dev,
  1578. request,
  1579. request->len,
  1580. handler,
  1581. p_buf, p_len);
  1582. }
  1583. return -EOPNOTSUPP;
  1584. }
  1585. /* ---------------------------------------------------------------- */
  1586. /*
  1587. * Main RtNetlink dispatcher. Called from the main networking code
  1588. * (do_setlink() in net/core/rtnetlink.c).
  1589. * Check the type of Request and call the appropriate wrapper...
  1590. */
  1591. int wireless_rtnetlink_set(struct net_device * dev,
  1592. char * data,
  1593. int len)
  1594. {
  1595. struct iw_event * request = (struct iw_event *) data;
  1596. iw_handler handler;
  1597. /* Check length */
  1598. if(len < IW_EV_LCP_LEN) {
  1599. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
  1600. dev->name, len);
  1601. return -EINVAL;
  1602. }
  1603. /* ReCheck length (len may have padding) */
  1604. if(request->len > len) {
  1605. printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
  1606. dev->name, request->len, len);
  1607. return -EINVAL;
  1608. }
  1609. /* Only accept SET requests in here */
  1610. if(!IW_IS_SET(request->cmd))
  1611. return -EOPNOTSUPP;
  1612. /* Basic check */
  1613. if (!netif_device_present(dev))
  1614. return -ENODEV;
  1615. /* New driver API : try to find the handler */
  1616. handler = get_handler(dev, request->cmd);
  1617. if(handler != NULL) {
  1618. /* Standard and private are not the same */
  1619. if(request->cmd < SIOCIWFIRSTPRIV)
  1620. return rtnetlink_standard_set(dev,
  1621. request,
  1622. request->len,
  1623. handler);
  1624. else
  1625. return rtnetlink_private_set(dev,
  1626. request,
  1627. request->len,
  1628. handler);
  1629. }
  1630. return -EOPNOTSUPP;
  1631. }
  1632. #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
  1633. /************************* EVENT PROCESSING *************************/
  1634. /*
  1635. * Process events generated by the wireless layer or the driver.
  1636. * Most often, the event will be propagated through rtnetlink
  1637. */
  1638. #ifdef WE_EVENT_RTNETLINK
  1639. /* ---------------------------------------------------------------- */
  1640. /*
  1641. * Fill a rtnetlink message with our event data.
  1642. * Note that we propage only the specified event and don't dump the
  1643. * current wireless config. Dumping the wireless config is far too
  1644. * expensive (for each parameter, the driver need to query the hardware).
  1645. */
  1646. static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
  1647. struct net_device * dev,
  1648. int type,
  1649. char * event,
  1650. int event_len)
  1651. {
  1652. struct ifinfomsg *r;
  1653. struct nlmsghdr *nlh;
  1654. unsigned char *b = skb->tail;
  1655. nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
  1656. r = NLMSG_DATA(nlh);
  1657. r->ifi_family = AF_UNSPEC;
  1658. r->__ifi_pad = 0;
  1659. r->ifi_type = dev->type;
  1660. r->ifi_index = dev->ifindex;
  1661. r->ifi_flags = dev_get_flags(dev);
  1662. r->ifi_change = 0; /* Wireless changes don't affect those flags */
  1663. /* Add the wireless events in the netlink packet */
  1664. RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
  1665. nlh->nlmsg_len = skb->tail - b;
  1666. return skb->len;
  1667. nlmsg_failure:
  1668. rtattr_failure:
  1669. skb_trim(skb, b - skb->data);
  1670. return -1;
  1671. }
  1672. /* ---------------------------------------------------------------- */
  1673. /*
  1674. * Create and broadcast and send it on the standard rtnetlink socket
  1675. * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
  1676. * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
  1677. * within a RTM_NEWLINK event.
  1678. */
  1679. static inline void rtmsg_iwinfo(struct net_device * dev,
  1680. char * event,
  1681. int event_len)
  1682. {
  1683. struct sk_buff *skb;
  1684. int size = NLMSG_GOODSIZE;
  1685. skb = alloc_skb(size, GFP_ATOMIC);
  1686. if (!skb)
  1687. return;
  1688. if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
  1689. event, event_len) < 0) {
  1690. kfree_skb(skb);
  1691. return;
  1692. }
  1693. NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
  1694. netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
  1695. }
  1696. #endif /* WE_EVENT_RTNETLINK */
  1697. /* ---------------------------------------------------------------- */
  1698. /*
  1699. * Main event dispatcher. Called from other parts and drivers.
  1700. * Send the event on the appropriate channels.
  1701. * May be called from interrupt context.
  1702. */
  1703. void wireless_send_event(struct net_device * dev,
  1704. unsigned int cmd,
  1705. union iwreq_data * wrqu,
  1706. char * extra)
  1707. {
  1708. const struct iw_ioctl_description * descr = NULL;
  1709. int extra_len = 0;
  1710. struct iw_event *event; /* Mallocated whole event */
  1711. int event_len; /* Its size */
  1712. int hdr_len; /* Size of the event header */
  1713. int wrqu_off = 0; /* Offset in wrqu */
  1714. /* Don't "optimise" the following variable, it will crash */
  1715. unsigned cmd_index; /* *MUST* be unsigned */
  1716. /* Get the description of the Event */
  1717. if(cmd <= SIOCIWLAST) {
  1718. cmd_index = cmd - SIOCIWFIRST;
  1719. if(cmd_index < standard_ioctl_num)
  1720. descr = &(standard_ioctl[cmd_index]);
  1721. } else {
  1722. cmd_index = cmd - IWEVFIRST;
  1723. if(cmd_index < standard_event_num)
  1724. descr = &(standard_event[cmd_index]);
  1725. }
  1726. /* Don't accept unknown events */
  1727. if(descr == NULL) {
  1728. /* Note : we don't return an error to the driver, because
  1729. * the driver would not know what to do about it. It can't
  1730. * return an error to the user, because the event is not
  1731. * initiated by a user request.
  1732. * The best the driver could do is to log an error message.
  1733. * We will do it ourselves instead...
  1734. */
  1735. printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
  1736. dev->name, cmd);
  1737. return;
  1738. }
  1739. #ifdef WE_EVENT_DEBUG
  1740. printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
  1741. dev->name, cmd);
  1742. 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);
  1743. #endif /* WE_EVENT_DEBUG */
  1744. /* Check extra parameters and set extra_len */
  1745. if(descr->header_type == IW_HEADER_TYPE_POINT) {
  1746. /* Check if number of token fits within bounds */
  1747. if(wrqu->data.length > descr->max_tokens) {
  1748. printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
  1749. return;
  1750. }
  1751. if(wrqu->data.length < descr->min_tokens) {
  1752. printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
  1753. return;
  1754. }
  1755. /* Calculate extra_len - extra is NULL for restricted events */
  1756. if(extra != NULL)
  1757. extra_len = wrqu->data.length * descr->token_size;
  1758. /* Always at an offset in wrqu */
  1759. wrqu_off = IW_EV_POINT_OFF;
  1760. #ifdef WE_EVENT_DEBUG
  1761. printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
  1762. #endif /* WE_EVENT_DEBUG */
  1763. }
  1764. /* Total length of the event */
  1765. hdr_len = event_type_size[descr->header_type];
  1766. event_len = hdr_len + extra_len;
  1767. #ifdef WE_EVENT_DEBUG
  1768. 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);
  1769. #endif /* WE_EVENT_DEBUG */
  1770. /* Create temporary buffer to hold the event */
  1771. event = kmalloc(event_len, GFP_ATOMIC);
  1772. if(event == NULL)
  1773. return;
  1774. /* Fill event */
  1775. event->len = event_len;
  1776. event->cmd = cmd;
  1777. memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
  1778. if(extra != NULL)
  1779. memcpy(((char *) event) + hdr_len, extra, extra_len);
  1780. #ifdef WE_EVENT_RTNETLINK
  1781. /* Send via the RtNetlink event channel */
  1782. rtmsg_iwinfo(dev, (char *) event, event_len);
  1783. #endif /* WE_EVENT_RTNETLINK */
  1784. /* Cleanup */
  1785. kfree(event);
  1786. return; /* Always success, I guess ;-) */
  1787. }
  1788. /********************** ENHANCED IWSPY SUPPORT **********************/
  1789. /*
  1790. * In the old days, the driver was handling spy support all by itself.
  1791. * Now, the driver can delegate this task to Wireless Extensions.
  1792. * It needs to use those standard spy iw_handler in struct iw_handler_def,
  1793. * push data to us via wireless_spy_update() and include struct iw_spy_data
  1794. * in its private part (and export it in net_device->wireless_data->spy_data).
  1795. * One of the main advantage of centralising spy support here is that
  1796. * it becomes much easier to improve and extend it without having to touch
  1797. * the drivers. One example is the addition of the Spy-Threshold events.
  1798. */
  1799. /* ---------------------------------------------------------------- */
  1800. /*
  1801. * Return the pointer to the spy data in the driver.
  1802. * Because this is called on the Rx path via wireless_spy_update(),
  1803. * we want it to be efficient...
  1804. */
  1805. static inline struct iw_spy_data * get_spydata(struct net_device *dev)
  1806. {
  1807. /* This is the new way */
  1808. if(dev->wireless_data)
  1809. return(dev->wireless_data->spy_data);
  1810. return NULL;
  1811. }
  1812. /*------------------------------------------------------------------*/
  1813. /*
  1814. * Standard Wireless Handler : set Spy List
  1815. */
  1816. int iw_handler_set_spy(struct net_device * dev,
  1817. struct iw_request_info * info,
  1818. union iwreq_data * wrqu,
  1819. char * extra)
  1820. {
  1821. struct iw_spy_data * spydata = get_spydata(dev);
  1822. struct sockaddr * address = (struct sockaddr *) extra;
  1823. /* Make sure driver is not buggy or using the old API */
  1824. if(!spydata)
  1825. return -EOPNOTSUPP;
  1826. /* Disable spy collection while we copy the addresses.
  1827. * While we copy addresses, any call to wireless_spy_update()
  1828. * will NOP. This is OK, as anyway the addresses are changing. */
  1829. spydata->spy_number = 0;
  1830. /* We want to operate without locking, because wireless_spy_update()
  1831. * most likely will happen in the interrupt handler, and therefore
  1832. * have its own locking constraints and needs performance.
  1833. * The rtnl_lock() make sure we don't race with the other iw_handlers.
  1834. * This make sure wireless_spy_update() "see" that the spy list
  1835. * is temporarily disabled. */
  1836. wmb();
  1837. /* Are there are addresses to copy? */
  1838. if(wrqu->data.length > 0) {
  1839. int i;
  1840. /* Copy addresses */
  1841. for(i = 0; i < wrqu->data.length; i++)
  1842. memcpy(spydata->spy_address[i], address[i].sa_data,
  1843. ETH_ALEN);
  1844. /* Reset stats */
  1845. memset(spydata->spy_stat, 0,
  1846. sizeof(struct iw_quality) * IW_MAX_SPY);
  1847. #ifdef WE_SPY_DEBUG
  1848. printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
  1849. for (i = 0; i < wrqu->data.length; i++)
  1850. printk(KERN_DEBUG
  1851. "%02X:%02X:%02X:%02X:%02X:%02X \n",
  1852. spydata->spy_address[i][0],
  1853. spydata->spy_address[i][1],
  1854. spydata->spy_address[i][2],
  1855. spydata->spy_address[i][3],
  1856. spydata->spy_address[i][4],
  1857. spydata->spy_address[i][5]);
  1858. #endif /* WE_SPY_DEBUG */
  1859. }
  1860. /* Make sure above is updated before re-enabling */
  1861. wmb();
  1862. /* Enable addresses */
  1863. spydata->spy_number = wrqu->data.length;
  1864. return 0;
  1865. }
  1866. /*------------------------------------------------------------------*/
  1867. /*
  1868. * Standard Wireless Handler : get Spy List
  1869. */
  1870. int iw_handler_get_spy(struct net_device * dev,
  1871. struct iw_request_info * info,
  1872. union iwreq_data * wrqu,
  1873. char * extra)
  1874. {
  1875. struct iw_spy_data * spydata = get_spydata(dev);
  1876. struct sockaddr * address = (struct sockaddr *) extra;
  1877. int i;
  1878. /* Make sure driver is not buggy or using the old API */
  1879. if(!spydata)
  1880. return -EOPNOTSUPP;
  1881. wrqu->data.length = spydata->spy_number;
  1882. /* Copy addresses. */
  1883. for(i = 0; i < spydata->spy_number; i++) {
  1884. memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
  1885. address[i].sa_family = AF_UNIX;
  1886. }
  1887. /* Copy stats to the user buffer (just after). */
  1888. if(spydata->spy_number > 0)
  1889. memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
  1890. spydata->spy_stat,
  1891. sizeof(struct iw_quality) * spydata->spy_number);
  1892. /* Reset updated flags. */
  1893. for(i = 0; i < spydata->spy_number; i++)
  1894. spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
  1895. return 0;
  1896. }
  1897. /*------------------------------------------------------------------*/
  1898. /*
  1899. * Standard Wireless Handler : set spy threshold
  1900. */
  1901. int iw_handler_set_thrspy(struct net_device * dev,
  1902. struct iw_request_info *info,
  1903. union iwreq_data * wrqu,
  1904. char * extra)
  1905. {
  1906. struct iw_spy_data * spydata = get_spydata(dev);
  1907. struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
  1908. /* Make sure driver is not buggy or using the old API */
  1909. if(!spydata)
  1910. return -EOPNOTSUPP;
  1911. /* Just do it */
  1912. memcpy(&(spydata->spy_thr_low), &(threshold->low),
  1913. 2 * sizeof(struct iw_quality));
  1914. /* Clear flag */
  1915. memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
  1916. #ifdef WE_SPY_DEBUG
  1917. printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
  1918. #endif /* WE_SPY_DEBUG */
  1919. return 0;
  1920. }
  1921. /*------------------------------------------------------------------*/
  1922. /*
  1923. * Standard Wireless Handler : get spy threshold
  1924. */
  1925. int iw_handler_get_thrspy(struct net_device * dev,
  1926. struct iw_request_info *info,
  1927. union iwreq_data * wrqu,
  1928. char * extra)
  1929. {
  1930. struct iw_spy_data * spydata = get_spydata(dev);
  1931. struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
  1932. /* Make sure driver is not buggy or using the old API */
  1933. if(!spydata)
  1934. return -EOPNOTSUPP;
  1935. /* Just do it */
  1936. memcpy(&(threshold->low), &(spydata->spy_thr_low),
  1937. 2 * sizeof(struct iw_quality));
  1938. return 0;
  1939. }
  1940. /*------------------------------------------------------------------*/
  1941. /*
  1942. * Prepare and send a Spy Threshold event
  1943. */
  1944. static void iw_send_thrspy_event(struct net_device * dev,
  1945. struct iw_spy_data * spydata,
  1946. unsigned char * address,
  1947. struct iw_quality * wstats)
  1948. {
  1949. union iwreq_data wrqu;
  1950. struct iw_thrspy threshold;
  1951. /* Init */
  1952. wrqu.data.length = 1;
  1953. wrqu.data.flags = 0;
  1954. /* Copy address */
  1955. memcpy(threshold.addr.sa_data, address, ETH_ALEN);
  1956. threshold.addr.sa_family = ARPHRD_ETHER;
  1957. /* Copy stats */
  1958. memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
  1959. /* Copy also thresholds */
  1960. memcpy(&(threshold.low), &(spydata->spy_thr_low),
  1961. 2 * sizeof(struct iw_quality));
  1962. #ifdef WE_SPY_DEBUG
  1963. printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
  1964. threshold.addr.sa_data[0],
  1965. threshold.addr.sa_data[1],
  1966. threshold.addr.sa_data[2],
  1967. threshold.addr.sa_data[3],
  1968. threshold.addr.sa_data[4],
  1969. threshold.addr.sa_data[5], threshold.qual.level);
  1970. #endif /* WE_SPY_DEBUG */
  1971. /* Send event to user space */
  1972. wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
  1973. }
  1974. /* ---------------------------------------------------------------- */
  1975. /*
  1976. * Call for the driver to update the spy data.
  1977. * For now, the spy data is a simple array. As the size of the array is
  1978. * small, this is good enough. If we wanted to support larger number of
  1979. * spy addresses, we should use something more efficient...
  1980. */
  1981. void wireless_spy_update(struct net_device * dev,
  1982. unsigned char * address,
  1983. struct iw_quality * wstats)
  1984. {
  1985. struct iw_spy_data * spydata = get_spydata(dev);
  1986. int i;
  1987. int match = -1;
  1988. /* Make sure driver is not buggy or using the old API */
  1989. if(!spydata)
  1990. return;
  1991. #ifdef WE_SPY_DEBUG
  1992. 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]);
  1993. #endif /* WE_SPY_DEBUG */
  1994. /* Update all records that match */
  1995. for(i = 0; i < spydata->spy_number; i++)
  1996. if(!compare_ether_addr(address, spydata->spy_address[i])) {
  1997. memcpy(&(spydata->spy_stat[i]), wstats,
  1998. sizeof(struct iw_quality));
  1999. match = i;
  2000. }
  2001. /* Generate an event if we cross the spy threshold.
  2002. * To avoid event storms, we have a simple hysteresis : we generate
  2003. * event only when we go under the low threshold or above the
  2004. * high threshold. */
  2005. if(match >= 0) {
  2006. if(spydata->spy_thr_under[match]) {
  2007. if(wstats->level > spydata->spy_thr_high.level) {
  2008. spydata->spy_thr_under[match] = 0;
  2009. iw_send_thrspy_event(dev, spydata,
  2010. address, wstats);
  2011. }
  2012. } else {
  2013. if(wstats->level < spydata->spy_thr_low.level) {
  2014. spydata->spy_thr_under[match] = 1;
  2015. iw_send_thrspy_event(dev, spydata,
  2016. address, wstats);
  2017. }
  2018. }
  2019. }
  2020. }
  2021. EXPORT_SYMBOL(iw_handler_get_spy);
  2022. EXPORT_SYMBOL(iw_handler_get_thrspy);
  2023. EXPORT_SYMBOL(iw_handler_set_spy);
  2024. EXPORT_SYMBOL(iw_handler_set_thrspy);
  2025. EXPORT_SYMBOL(wireless_send_event);
  2026. EXPORT_SYMBOL(wireless_spy_update);