isl_ioctl.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753
  1. /*
  2. *
  3. * Copyright (C) 2002 Intersil Americas Inc.
  4. * (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
  5. * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
  6. * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <linux/version.h>
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/if_arp.h>
  26. #include <linux/pci.h>
  27. #include <asm/uaccess.h>
  28. #include "prismcompat.h"
  29. #include "isl_ioctl.h"
  30. #include "islpci_mgt.h"
  31. #include "isl_oid.h" /* additional types and defs for isl38xx fw */
  32. #include "oid_mgt.h"
  33. #include <net/iw_handler.h> /* New driver API */
  34. static void prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
  35. u8 *wpa_ie, size_t wpa_ie_len);
  36. static size_t prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);
  37. static int prism54_set_wpa(struct net_device *, struct iw_request_info *,
  38. __u32 *, char *);
  39. /**
  40. * prism54_mib_mode_helper - MIB change mode helper function
  41. * @mib: the &struct islpci_mib object to modify
  42. * @iw_mode: new mode (%IW_MODE_*)
  43. *
  44. * This is a helper function, hence it does not lock. Make sure
  45. * caller deals with locking *if* necessary. This function sets the
  46. * mode-dependent mib values and does the mapping of the Linux
  47. * Wireless API modes to Device firmware modes. It also checks for
  48. * correct valid Linux wireless modes.
  49. */
  50. static int
  51. prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
  52. {
  53. u32 config = INL_CONFIG_MANUALRUN;
  54. u32 mode, bsstype;
  55. /* For now, just catch early the Repeater and Secondary modes here */
  56. if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
  57. printk(KERN_DEBUG
  58. "%s(): Sorry, Repeater mode and Secondary mode "
  59. "are not yet supported by this driver.\n", __FUNCTION__);
  60. return -EINVAL;
  61. }
  62. priv->iw_mode = iw_mode;
  63. switch (iw_mode) {
  64. case IW_MODE_AUTO:
  65. mode = INL_MODE_CLIENT;
  66. bsstype = DOT11_BSSTYPE_ANY;
  67. break;
  68. case IW_MODE_ADHOC:
  69. mode = INL_MODE_CLIENT;
  70. bsstype = DOT11_BSSTYPE_IBSS;
  71. break;
  72. case IW_MODE_INFRA:
  73. mode = INL_MODE_CLIENT;
  74. bsstype = DOT11_BSSTYPE_INFRA;
  75. break;
  76. case IW_MODE_MASTER:
  77. mode = INL_MODE_AP;
  78. bsstype = DOT11_BSSTYPE_INFRA;
  79. break;
  80. case IW_MODE_MONITOR:
  81. mode = INL_MODE_PROMISCUOUS;
  82. bsstype = DOT11_BSSTYPE_ANY;
  83. config |= INL_CONFIG_RXANNEX;
  84. break;
  85. default:
  86. return -EINVAL;
  87. }
  88. if (init_wds)
  89. config |= INL_CONFIG_WDS;
  90. mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
  91. mgt_set(priv, OID_INL_CONFIG, &config);
  92. mgt_set(priv, OID_INL_MODE, &mode);
  93. return 0;
  94. }
  95. /**
  96. * prism54_mib_init - fill MIB cache with defaults
  97. *
  98. * this function initializes the struct given as @mib with defaults,
  99. * of which many are retrieved from the global module parameter
  100. * variables.
  101. */
  102. void
  103. prism54_mib_init(islpci_private *priv)
  104. {
  105. u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;
  106. struct obj_buffer psm_buffer = {
  107. .size = PSM_BUFFER_SIZE,
  108. .addr = priv->device_psm_buffer
  109. };
  110. channel = CARD_DEFAULT_CHANNEL;
  111. authen = CARD_DEFAULT_AUTHEN;
  112. wep = CARD_DEFAULT_WEP;
  113. filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */
  114. dot1x = CARD_DEFAULT_DOT1X;
  115. mlme = CARD_DEFAULT_MLME_MODE;
  116. conformance = CARD_DEFAULT_CONFORMANCE;
  117. power = 127;
  118. mode = CARD_DEFAULT_IW_MODE;
  119. mgt_set(priv, DOT11_OID_CHANNEL, &channel);
  120. mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);
  121. mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);
  122. mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
  123. mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);
  124. mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);
  125. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);
  126. mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);
  127. mgt_set(priv, OID_INL_OUTPUTPOWER, &power);
  128. /* This sets all of the mode-dependent values */
  129. prism54_mib_mode_helper(priv, mode);
  130. }
  131. /* this will be executed outside of atomic context thanks to
  132. * schedule_work(), thus we can as well use sleeping semaphore
  133. * locking */
  134. void
  135. prism54_update_stats(islpci_private *priv)
  136. {
  137. char *data;
  138. int j;
  139. struct obj_bss bss, *bss2;
  140. union oid_res_t r;
  141. if (down_interruptible(&priv->stats_sem))
  142. return;
  143. /* Noise floor.
  144. * I'm not sure if the unit is dBm.
  145. * Note : If we are not connected, this value seems to be irrelevant. */
  146. mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
  147. priv->local_iwstatistics.qual.noise = r.u;
  148. /* Get the rssi of the link. To do this we need to retrieve a bss. */
  149. /* First get the MAC address of the AP we are associated with. */
  150. mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
  151. data = r.ptr;
  152. /* copy this MAC to the bss */
  153. memcpy(bss.address, data, 6);
  154. kfree(data);
  155. /* now ask for the corresponding bss */
  156. j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
  157. bss2 = r.ptr;
  158. /* report the rssi and use it to calculate
  159. * link quality through a signal-noise
  160. * ratio */
  161. priv->local_iwstatistics.qual.level = bss2->rssi;
  162. priv->local_iwstatistics.qual.qual =
  163. bss2->rssi - priv->iwstatistics.qual.noise;
  164. kfree(bss2);
  165. /* report that the stats are new */
  166. priv->local_iwstatistics.qual.updated = 0x7;
  167. /* Rx : unable to decrypt the MPDU */
  168. mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
  169. priv->local_iwstatistics.discard.code = r.u;
  170. /* Tx : Max MAC retries num reached */
  171. mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
  172. priv->local_iwstatistics.discard.retries = r.u;
  173. up(&priv->stats_sem);
  174. return;
  175. }
  176. struct iw_statistics *
  177. prism54_get_wireless_stats(struct net_device *ndev)
  178. {
  179. islpci_private *priv = netdev_priv(ndev);
  180. /* If the stats are being updated return old data */
  181. if (down_trylock(&priv->stats_sem) == 0) {
  182. memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
  183. sizeof (struct iw_statistics));
  184. /* They won't be marked updated for the next time */
  185. priv->local_iwstatistics.qual.updated = 0;
  186. up(&priv->stats_sem);
  187. } else
  188. priv->iwstatistics.qual.updated = 0;
  189. /* Update our wireless stats, but do not schedule to often
  190. * (max 1 HZ) */
  191. if ((priv->stats_timestamp == 0) ||
  192. time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
  193. schedule_work(&priv->stats_work);
  194. priv->stats_timestamp = jiffies;
  195. }
  196. return &priv->iwstatistics;
  197. }
  198. static int
  199. prism54_commit(struct net_device *ndev, struct iw_request_info *info,
  200. char *cwrq, char *extra)
  201. {
  202. islpci_private *priv = netdev_priv(ndev);
  203. /* simply re-set the last set SSID, this should commit most stuff */
  204. /* Commit in Monitor mode is not necessary, also setting essid
  205. * in Monitor mode does not make sense and isn't allowed for this
  206. * device's firmware */
  207. if (priv->iw_mode != IW_MODE_MONITOR)
  208. return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
  209. return 0;
  210. }
  211. static int
  212. prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
  213. char *cwrq, char *extra)
  214. {
  215. islpci_private *priv = netdev_priv(ndev);
  216. char *capabilities;
  217. union oid_res_t r;
  218. int rvalue;
  219. if (islpci_get_state(priv) < PRV_STATE_INIT) {
  220. strncpy(cwrq, "NOT READY!", IFNAMSIZ);
  221. return 0;
  222. }
  223. rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
  224. switch (r.u) {
  225. case INL_PHYCAP_5000MHZ:
  226. capabilities = "IEEE 802.11a/b/g";
  227. break;
  228. case INL_PHYCAP_FAA:
  229. capabilities = "IEEE 802.11b/g - FAA Support";
  230. break;
  231. case INL_PHYCAP_2400MHZ:
  232. default:
  233. capabilities = "IEEE 802.11b/g"; /* Default */
  234. break;
  235. }
  236. strncpy(cwrq, capabilities, IFNAMSIZ);
  237. return rvalue;
  238. }
  239. static int
  240. prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
  241. struct iw_freq *fwrq, char *extra)
  242. {
  243. islpci_private *priv = netdev_priv(ndev);
  244. int rvalue;
  245. u32 c;
  246. if (fwrq->m < 1000)
  247. /* we have a channel number */
  248. c = fwrq->m;
  249. else
  250. c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
  251. rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
  252. /* Call commit handler */
  253. return (rvalue ? rvalue : -EINPROGRESS);
  254. }
  255. static int
  256. prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
  257. struct iw_freq *fwrq, char *extra)
  258. {
  259. islpci_private *priv = netdev_priv(ndev);
  260. union oid_res_t r;
  261. int rvalue;
  262. rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
  263. fwrq->i = r.u;
  264. rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);
  265. fwrq->m = r.u;
  266. fwrq->e = 3;
  267. return rvalue;
  268. }
  269. static int
  270. prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
  271. __u32 * uwrq, char *extra)
  272. {
  273. islpci_private *priv = netdev_priv(ndev);
  274. u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
  275. /* Let's see if the user passed a valid Linux Wireless mode */
  276. if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
  277. printk(KERN_DEBUG
  278. "%s: %s() You passed a non-valid init_mode.\n",
  279. priv->ndev->name, __FUNCTION__);
  280. return -EINVAL;
  281. }
  282. down_write(&priv->mib_sem);
  283. if (prism54_mib_mode_helper(priv, *uwrq)) {
  284. up_write(&priv->mib_sem);
  285. return -EOPNOTSUPP;
  286. }
  287. /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
  288. * extended one.
  289. */
  290. if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
  291. mlmeautolevel = DOT11_MLME_INTERMEDIATE;
  292. if (priv->wpa)
  293. mlmeautolevel = DOT11_MLME_EXTENDED;
  294. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
  295. if (mgt_commit(priv)) {
  296. up_write(&priv->mib_sem);
  297. return -EIO;
  298. }
  299. priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
  300. ? priv->monitor_type : ARPHRD_ETHER;
  301. up_write(&priv->mib_sem);
  302. return 0;
  303. }
  304. /* Use mib cache */
  305. static int
  306. prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
  307. __u32 * uwrq, char *extra)
  308. {
  309. islpci_private *priv = netdev_priv(ndev);
  310. BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
  311. IW_MODE_MONITOR));
  312. *uwrq = priv->iw_mode;
  313. return 0;
  314. }
  315. /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
  316. * emit data if (sensitivity > rssi - noise) (in dBm).
  317. * prism54_set_sens does not seem to work.
  318. */
  319. static int
  320. prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
  321. struct iw_param *vwrq, char *extra)
  322. {
  323. islpci_private *priv = netdev_priv(ndev);
  324. u32 sens;
  325. /* by default the card sets this to 20. */
  326. sens = vwrq->disabled ? 20 : vwrq->value;
  327. return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
  328. }
  329. static int
  330. prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
  331. struct iw_param *vwrq, char *extra)
  332. {
  333. islpci_private *priv = netdev_priv(ndev);
  334. union oid_res_t r;
  335. int rvalue;
  336. rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
  337. vwrq->value = r.u;
  338. vwrq->disabled = (vwrq->value == 0);
  339. vwrq->fixed = 1;
  340. return rvalue;
  341. }
  342. static int
  343. prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
  344. struct iw_point *dwrq, char *extra)
  345. {
  346. struct iw_range *range = (struct iw_range *) extra;
  347. islpci_private *priv = netdev_priv(ndev);
  348. u8 *data;
  349. int i, m, rvalue;
  350. struct obj_frequencies *freq;
  351. union oid_res_t r;
  352. memset(range, 0, sizeof (struct iw_range));
  353. dwrq->length = sizeof (struct iw_range);
  354. /* set the wireless extension version number */
  355. range->we_version_source = SUPPORTED_WIRELESS_EXT;
  356. range->we_version_compiled = WIRELESS_EXT;
  357. /* Now the encoding capabilities */
  358. range->num_encoding_sizes = 3;
  359. /* 64(40) bits WEP */
  360. range->encoding_size[0] = 5;
  361. /* 128(104) bits WEP */
  362. range->encoding_size[1] = 13;
  363. /* 256 bits for WPA-PSK */
  364. range->encoding_size[2] = 32;
  365. /* 4 keys are allowed */
  366. range->max_encoding_tokens = 4;
  367. /* we don't know the quality range... */
  368. range->max_qual.level = 0;
  369. range->max_qual.noise = 0;
  370. range->max_qual.qual = 0;
  371. /* these value describe an average quality. Needs more tweaking... */
  372. range->avg_qual.level = -80; /* -80 dBm */
  373. range->avg_qual.noise = 0; /* don't know what to put here */
  374. range->avg_qual.qual = 0;
  375. range->sensitivity = 200;
  376. /* retry limit capabilities */
  377. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  378. range->retry_flags = IW_RETRY_LIMIT;
  379. range->r_time_flags = IW_RETRY_LIFETIME;
  380. /* I don't know the range. Put stupid things here */
  381. range->min_retry = 1;
  382. range->max_retry = 65535;
  383. range->min_r_time = 1024;
  384. range->max_r_time = 65535 * 1024;
  385. /* txpower is supported in dBm's */
  386. range->txpower_capa = IW_TXPOW_DBM;
  387. #if WIRELESS_EXT > 16
  388. /* Event capability (kernel + driver) */
  389. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  390. IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
  391. IW_EVENT_CAPA_MASK(SIOCGIWAP));
  392. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  393. range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
  394. #endif /* WIRELESS_EXT > 16 */
  395. if (islpci_get_state(priv) < PRV_STATE_INIT)
  396. return 0;
  397. /* Request the device for the supported frequencies
  398. * not really relevant since some devices will report the 5 GHz band
  399. * frequencies even if they don't support them.
  400. */
  401. rvalue =
  402. mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
  403. freq = r.ptr;
  404. range->num_channels = freq->nr;
  405. range->num_frequency = freq->nr;
  406. m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
  407. for (i = 0; i < m; i++) {
  408. range->freq[i].m = freq->mhz[i];
  409. range->freq[i].e = 6;
  410. range->freq[i].i = channel_of_freq(freq->mhz[i]);
  411. }
  412. kfree(freq);
  413. rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
  414. data = r.ptr;
  415. /* We got an array of char. It is NULL terminated. */
  416. i = 0;
  417. while ((i < IW_MAX_BITRATES) && (*data != 0)) {
  418. /* the result must be in bps. The card gives us 500Kbps */
  419. range->bitrate[i] = *data * 500000;
  420. i++;
  421. data++;
  422. }
  423. range->num_bitrates = i;
  424. kfree(r.ptr);
  425. return rvalue;
  426. }
  427. /* Set AP address*/
  428. static int
  429. prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
  430. struct sockaddr *awrq, char *extra)
  431. {
  432. islpci_private *priv = netdev_priv(ndev);
  433. char bssid[6];
  434. int rvalue;
  435. if (awrq->sa_family != ARPHRD_ETHER)
  436. return -EINVAL;
  437. /* prepare the structure for the set object */
  438. memcpy(&bssid[0], awrq->sa_data, 6);
  439. /* set the bssid -- does this make sense when in AP mode? */
  440. rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
  441. return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
  442. }
  443. /* get AP address*/
  444. static int
  445. prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
  446. struct sockaddr *awrq, char *extra)
  447. {
  448. islpci_private *priv = netdev_priv(ndev);
  449. union oid_res_t r;
  450. int rvalue;
  451. rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
  452. memcpy(awrq->sa_data, r.ptr, 6);
  453. awrq->sa_family = ARPHRD_ETHER;
  454. kfree(r.ptr);
  455. return rvalue;
  456. }
  457. static int
  458. prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
  459. struct iw_param *vwrq, char *extra)
  460. {
  461. /* hehe the device does this automagicaly */
  462. return 0;
  463. }
  464. /* a little helper that will translate our data into a card independent
  465. * format that the Wireless Tools will understand. This was inspired by
  466. * the "Aironet driver for 4500 and 4800 series cards" (GPL)
  467. */
  468. static char *
  469. prism54_translate_bss(struct net_device *ndev, char *current_ev,
  470. char *end_buf, struct obj_bss *bss, char noise)
  471. {
  472. struct iw_event iwe; /* Temporary buffer */
  473. short cap;
  474. islpci_private *priv = netdev_priv(ndev);
  475. /* The first entry must be the MAC address */
  476. memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
  477. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  478. iwe.cmd = SIOCGIWAP;
  479. current_ev =
  480. iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
  481. /* The following entries will be displayed in the same order we give them */
  482. /* The ESSID. */
  483. iwe.u.data.length = bss->ssid.length;
  484. iwe.u.data.flags = 1;
  485. iwe.cmd = SIOCGIWESSID;
  486. current_ev = iwe_stream_add_point(current_ev, end_buf,
  487. &iwe, bss->ssid.octets);
  488. /* Capabilities */
  489. #define CAP_ESS 0x01
  490. #define CAP_IBSS 0x02
  491. #define CAP_CRYPT 0x10
  492. /* Mode */
  493. cap = bss->capinfo;
  494. iwe.u.mode = 0;
  495. if (cap & CAP_ESS)
  496. iwe.u.mode = IW_MODE_MASTER;
  497. else if (cap & CAP_IBSS)
  498. iwe.u.mode = IW_MODE_ADHOC;
  499. iwe.cmd = SIOCGIWMODE;
  500. if (iwe.u.mode)
  501. current_ev =
  502. iwe_stream_add_event(current_ev, end_buf, &iwe,
  503. IW_EV_UINT_LEN);
  504. /* Encryption capability */
  505. if (cap & CAP_CRYPT)
  506. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  507. else
  508. iwe.u.data.flags = IW_ENCODE_DISABLED;
  509. iwe.u.data.length = 0;
  510. iwe.cmd = SIOCGIWENCODE;
  511. current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL);
  512. /* Add frequency. (short) bss->channel is the frequency in MHz */
  513. iwe.u.freq.m = bss->channel;
  514. iwe.u.freq.e = 6;
  515. iwe.cmd = SIOCGIWFREQ;
  516. current_ev =
  517. iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
  518. /* Add quality statistics */
  519. iwe.u.qual.level = bss->rssi;
  520. iwe.u.qual.noise = noise;
  521. /* do a simple SNR for quality */
  522. iwe.u.qual.qual = bss->rssi - noise;
  523. iwe.cmd = IWEVQUAL;
  524. current_ev =
  525. iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
  526. if (priv->wpa) {
  527. u8 wpa_ie[MAX_WPA_IE_LEN];
  528. char *buf, *p;
  529. size_t wpa_ie_len;
  530. int i;
  531. wpa_ie_len = prism54_wpa_ie_get(priv, bss->address, wpa_ie);
  532. if (wpa_ie_len > 0 &&
  533. (buf = kmalloc(wpa_ie_len * 2 + 10, GFP_ATOMIC))) {
  534. p = buf;
  535. p += sprintf(p, "wpa_ie=");
  536. for (i = 0; i < wpa_ie_len; i++) {
  537. p += sprintf(p, "%02x", wpa_ie[i]);
  538. }
  539. memset(&iwe, 0, sizeof (iwe));
  540. iwe.cmd = IWEVCUSTOM;
  541. iwe.u.data.length = strlen(buf);
  542. current_ev = iwe_stream_add_point(current_ev, end_buf,
  543. &iwe, buf);
  544. kfree(buf);
  545. }
  546. }
  547. return current_ev;
  548. }
  549. static int
  550. prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
  551. struct iw_point *dwrq, char *extra)
  552. {
  553. islpci_private *priv = netdev_priv(ndev);
  554. int i, rvalue;
  555. struct obj_bsslist *bsslist;
  556. u32 noise = 0;
  557. char *current_ev = extra;
  558. union oid_res_t r;
  559. if (islpci_get_state(priv) < PRV_STATE_INIT) {
  560. /* device is not ready, fail gently */
  561. dwrq->length = 0;
  562. return 0;
  563. }
  564. /* first get the noise value. We will use it to report the link quality */
  565. rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
  566. noise = r.u;
  567. /* Ask the device for a list of known bss.
  568. * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64.
  569. * The new API, using SIOCGIWSCAN, is only limited by the buffer size.
  570. * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes.
  571. * Starting with WE-17, the buffer can be as big as needed.
  572. * But the device won't repport anything if you change the value
  573. * of IWMAX_BSS=24. */
  574. rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
  575. bsslist = r.ptr;
  576. /* ok now, scan the list and translate its info */
  577. for (i = 0; i < (int) bsslist->nr; i++) {
  578. current_ev = prism54_translate_bss(ndev, current_ev,
  579. extra + dwrq->length,
  580. &(bsslist->bsslist[i]),
  581. noise);
  582. #if WIRELESS_EXT > 16
  583. /* Check if there is space for one more entry */
  584. if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
  585. /* Ask user space to try again with a bigger buffer */
  586. rvalue = -E2BIG;
  587. break;
  588. }
  589. #endif /* WIRELESS_EXT > 16 */
  590. }
  591. kfree(bsslist);
  592. dwrq->length = (current_ev - extra);
  593. dwrq->flags = 0; /* todo */
  594. return rvalue;
  595. }
  596. static int
  597. prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
  598. struct iw_point *dwrq, char *extra)
  599. {
  600. islpci_private *priv = netdev_priv(ndev);
  601. struct obj_ssid essid;
  602. memset(essid.octets, 0, 33);
  603. /* Check if we were asked for `any' */
  604. if (dwrq->flags && dwrq->length) {
  605. if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1))
  606. return -E2BIG;
  607. essid.length = dwrq->length - 1;
  608. memcpy(essid.octets, extra, dwrq->length);
  609. } else
  610. essid.length = 0;
  611. if (priv->iw_mode != IW_MODE_MONITOR)
  612. return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
  613. /* If in monitor mode, just save to mib */
  614. mgt_set(priv, DOT11_OID_SSID, &essid);
  615. return 0;
  616. }
  617. static int
  618. prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
  619. struct iw_point *dwrq, char *extra)
  620. {
  621. islpci_private *priv = netdev_priv(ndev);
  622. struct obj_ssid *essid;
  623. union oid_res_t r;
  624. int rvalue;
  625. rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
  626. essid = r.ptr;
  627. if (essid->length) {
  628. dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */
  629. /* if it is to big, trunk it */
  630. dwrq->length = min(IW_ESSID_MAX_SIZE, essid->length + 1);
  631. } else {
  632. dwrq->flags = 0;
  633. dwrq->length = 0;
  634. }
  635. essid->octets[essid->length] = '\0';
  636. memcpy(extra, essid->octets, dwrq->length);
  637. kfree(essid);
  638. return rvalue;
  639. }
  640. /* Provides no functionality, just completes the ioctl. In essence this is a
  641. * just a cosmetic ioctl.
  642. */
  643. static int
  644. prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
  645. struct iw_point *dwrq, char *extra)
  646. {
  647. islpci_private *priv = netdev_priv(ndev);
  648. if (dwrq->length > IW_ESSID_MAX_SIZE)
  649. return -E2BIG;
  650. down_write(&priv->mib_sem);
  651. memset(priv->nickname, 0, sizeof (priv->nickname));
  652. memcpy(priv->nickname, extra, dwrq->length);
  653. up_write(&priv->mib_sem);
  654. return 0;
  655. }
  656. static int
  657. prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
  658. struct iw_point *dwrq, char *extra)
  659. {
  660. islpci_private *priv = netdev_priv(ndev);
  661. dwrq->length = 0;
  662. down_read(&priv->mib_sem);
  663. dwrq->length = strlen(priv->nickname) + 1;
  664. memcpy(extra, priv->nickname, dwrq->length);
  665. up_read(&priv->mib_sem);
  666. return 0;
  667. }
  668. /* Set the allowed Bitrates */
  669. static int
  670. prism54_set_rate(struct net_device *ndev,
  671. struct iw_request_info *info,
  672. struct iw_param *vwrq, char *extra)
  673. {
  674. islpci_private *priv = netdev_priv(ndev);
  675. u32 rate, profile;
  676. char *data;
  677. int ret, i;
  678. union oid_res_t r;
  679. if (vwrq->value == -1) {
  680. /* auto mode. No limit. */
  681. profile = 1;
  682. return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
  683. }
  684. ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
  685. if (ret) {
  686. kfree(r.ptr);
  687. return ret;
  688. }
  689. rate = (u32) (vwrq->value / 500000);
  690. data = r.ptr;
  691. i = 0;
  692. while (data[i]) {
  693. if (rate && (data[i] == rate)) {
  694. break;
  695. }
  696. if (vwrq->value == i) {
  697. break;
  698. }
  699. data[i] |= 0x80;
  700. i++;
  701. }
  702. if (!data[i]) {
  703. kfree(r.ptr);
  704. return -EINVAL;
  705. }
  706. data[i] |= 0x80;
  707. data[i + 1] = 0;
  708. /* Now, check if we want a fixed or auto value */
  709. if (vwrq->fixed) {
  710. data[0] = data[i];
  711. data[1] = 0;
  712. }
  713. /*
  714. i = 0;
  715. printk("prism54 rate: ");
  716. while(data[i]) {
  717. printk("%u ", data[i]);
  718. i++;
  719. }
  720. printk("0\n");
  721. */
  722. profile = -1;
  723. ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
  724. ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
  725. ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
  726. kfree(r.ptr);
  727. return ret;
  728. }
  729. /* Get the current bit rate */
  730. static int
  731. prism54_get_rate(struct net_device *ndev,
  732. struct iw_request_info *info,
  733. struct iw_param *vwrq, char *extra)
  734. {
  735. islpci_private *priv = netdev_priv(ndev);
  736. int rvalue;
  737. char *data;
  738. union oid_res_t r;
  739. /* Get the current bit rate */
  740. if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
  741. return rvalue;
  742. vwrq->value = r.u * 500000;
  743. /* request the device for the enabled rates */
  744. rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r);
  745. if (rvalue) {
  746. kfree(r.ptr);
  747. return rvalue;
  748. }
  749. data = r.ptr;
  750. vwrq->fixed = (data[0] != 0) && (data[1] == 0);
  751. kfree(r.ptr);
  752. return 0;
  753. }
  754. static int
  755. prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
  756. struct iw_param *vwrq, char *extra)
  757. {
  758. islpci_private *priv = netdev_priv(ndev);
  759. return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
  760. }
  761. static int
  762. prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
  763. struct iw_param *vwrq, char *extra)
  764. {
  765. islpci_private *priv = netdev_priv(ndev);
  766. union oid_res_t r;
  767. int rvalue;
  768. /* get the rts threshold */
  769. rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
  770. vwrq->value = r.u;
  771. return rvalue;
  772. }
  773. static int
  774. prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
  775. struct iw_param *vwrq, char *extra)
  776. {
  777. islpci_private *priv = netdev_priv(ndev);
  778. return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
  779. }
  780. static int
  781. prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
  782. struct iw_param *vwrq, char *extra)
  783. {
  784. islpci_private *priv = netdev_priv(ndev);
  785. union oid_res_t r;
  786. int rvalue;
  787. rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
  788. vwrq->value = r.u;
  789. return rvalue;
  790. }
  791. /* Here we have (min,max) = max retries for (small frames, big frames). Where
  792. * big frame <=> bigger than the rts threshold
  793. * small frame <=> smaller than the rts threshold
  794. * This is not really the behavior expected by the wireless tool but it seems
  795. * to be a common behavior in other drivers.
  796. */
  797. static int
  798. prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
  799. struct iw_param *vwrq, char *extra)
  800. {
  801. islpci_private *priv = netdev_priv(ndev);
  802. u32 slimit = 0, llimit = 0; /* short and long limit */
  803. u32 lifetime = 0;
  804. int rvalue = 0;
  805. if (vwrq->disabled)
  806. /* we cannot disable this feature */
  807. return -EINVAL;
  808. if (vwrq->flags & IW_RETRY_LIMIT) {
  809. if (vwrq->flags & IW_RETRY_MIN)
  810. slimit = vwrq->value;
  811. else if (vwrq->flags & IW_RETRY_MAX)
  812. llimit = vwrq->value;
  813. else {
  814. /* we are asked to set both */
  815. slimit = vwrq->value;
  816. llimit = vwrq->value;
  817. }
  818. }
  819. if (vwrq->flags & IW_RETRY_LIFETIME)
  820. /* Wireless tools use us unit while the device uses 1024 us unit */
  821. lifetime = vwrq->value / 1024;
  822. /* now set what is requested */
  823. if (slimit)
  824. rvalue =
  825. mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
  826. if (llimit)
  827. rvalue |=
  828. mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
  829. if (lifetime)
  830. rvalue |=
  831. mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
  832. &lifetime);
  833. return rvalue;
  834. }
  835. static int
  836. prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
  837. struct iw_param *vwrq, char *extra)
  838. {
  839. islpci_private *priv = netdev_priv(ndev);
  840. union oid_res_t r;
  841. int rvalue = 0;
  842. vwrq->disabled = 0; /* It cannot be disabled */
  843. if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  844. /* we are asked for the life time */
  845. rvalue =
  846. mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
  847. vwrq->value = r.u * 1024;
  848. vwrq->flags = IW_RETRY_LIFETIME;
  849. } else if ((vwrq->flags & IW_RETRY_MAX)) {
  850. /* we are asked for the long retry limit */
  851. rvalue |=
  852. mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
  853. vwrq->value = r.u;
  854. vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  855. } else {
  856. /* default. get the short retry limit */
  857. rvalue |=
  858. mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
  859. vwrq->value = r.u;
  860. vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  861. }
  862. return rvalue;
  863. }
  864. static int
  865. prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
  866. struct iw_point *dwrq, char *extra)
  867. {
  868. islpci_private *priv = netdev_priv(ndev);
  869. int rvalue = 0, force = 0;
  870. int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
  871. union oid_res_t r;
  872. /* with the new API, it's impossible to get a NULL pointer.
  873. * New version of iwconfig set the IW_ENCODE_NOKEY flag
  874. * when no key is given, but older versions don't. */
  875. if (dwrq->length > 0) {
  876. /* we have a key to set */
  877. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  878. int current_index;
  879. struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
  880. /* get the current key index */
  881. rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  882. current_index = r.u;
  883. /* Verify that the key is not marked as invalid */
  884. if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
  885. key.length = dwrq->length > sizeof (key.key) ?
  886. sizeof (key.key) : dwrq->length;
  887. memcpy(key.key, extra, key.length);
  888. if (key.length == 32)
  889. /* we want WPA-PSK */
  890. key.type = DOT11_PRIV_TKIP;
  891. if ((index < 0) || (index > 3))
  892. /* no index provided use the current one */
  893. index = current_index;
  894. /* now send the key to the card */
  895. rvalue |=
  896. mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
  897. &key);
  898. }
  899. /*
  900. * If a valid key is set, encryption should be enabled
  901. * (user may turn it off later).
  902. * This is also how "iwconfig ethX key on" works
  903. */
  904. if ((index == current_index) && (key.length > 0))
  905. force = 1;
  906. } else {
  907. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  908. if ((index >= 0) && (index <= 3)) {
  909. /* we want to set the key index */
  910. rvalue |=
  911. mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
  912. &index);
  913. } else {
  914. if (!dwrq->flags & IW_ENCODE_MODE) {
  915. /* we cannot do anything. Complain. */
  916. return -EINVAL;
  917. }
  918. }
  919. }
  920. /* now read the flags */
  921. if (dwrq->flags & IW_ENCODE_DISABLED) {
  922. /* Encoding disabled,
  923. * authen = DOT11_AUTH_OS;
  924. * invoke = 0;
  925. * exunencrypt = 0; */
  926. }
  927. if (dwrq->flags & IW_ENCODE_OPEN)
  928. /* Encode but accept non-encoded packets. No auth */
  929. invoke = 1;
  930. if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
  931. /* Refuse non-encoded packets. Auth */
  932. authen = DOT11_AUTH_BOTH;
  933. invoke = 1;
  934. exunencrypt = 1;
  935. }
  936. /* do the change if requested */
  937. if ((dwrq->flags & IW_ENCODE_MODE) || force) {
  938. rvalue |=
  939. mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
  940. rvalue |=
  941. mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
  942. rvalue |=
  943. mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
  944. &exunencrypt);
  945. }
  946. return rvalue;
  947. }
  948. static int
  949. prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
  950. struct iw_point *dwrq, char *extra)
  951. {
  952. islpci_private *priv = netdev_priv(ndev);
  953. struct obj_key *key;
  954. u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  955. u32 authen = 0, invoke = 0, exunencrypt = 0;
  956. int rvalue;
  957. union oid_res_t r;
  958. /* first get the flags */
  959. rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
  960. authen = r.u;
  961. rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
  962. invoke = r.u;
  963. rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
  964. exunencrypt = r.u;
  965. if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
  966. dwrq->flags = IW_ENCODE_RESTRICTED;
  967. else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
  968. if (invoke)
  969. dwrq->flags = IW_ENCODE_OPEN;
  970. else
  971. dwrq->flags = IW_ENCODE_DISABLED;
  972. } else
  973. /* The card should not work in this state */
  974. dwrq->flags = 0;
  975. /* get the current device key index */
  976. rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  977. devindex = r.u;
  978. /* Now get the key, return it */
  979. if ((index < 0) || (index > 3))
  980. /* no index provided, use the current one */
  981. index = devindex;
  982. rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
  983. key = r.ptr;
  984. dwrq->length = key->length;
  985. memcpy(extra, key->key, dwrq->length);
  986. kfree(key);
  987. /* return the used key index */
  988. dwrq->flags |= devindex + 1;
  989. return rvalue;
  990. }
  991. static int
  992. prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
  993. struct iw_param *vwrq, char *extra)
  994. {
  995. islpci_private *priv = netdev_priv(ndev);
  996. union oid_res_t r;
  997. int rvalue;
  998. rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
  999. /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
  1000. vwrq->value = (s32) r.u / 4;
  1001. vwrq->fixed = 1;
  1002. /* radio is not turned of
  1003. * btw: how is possible to turn off only the radio
  1004. */
  1005. vwrq->disabled = 0;
  1006. return rvalue;
  1007. }
  1008. static int
  1009. prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
  1010. struct iw_param *vwrq, char *extra)
  1011. {
  1012. islpci_private *priv = netdev_priv(ndev);
  1013. s32 u = vwrq->value;
  1014. /* intersil firmware operates in 0.25 dBm (1/4) */
  1015. u *= 4;
  1016. if (vwrq->disabled) {
  1017. /* don't know how to disable radio */
  1018. printk(KERN_DEBUG
  1019. "%s: %s() disabling radio is not yet supported.\n",
  1020. priv->ndev->name, __FUNCTION__);
  1021. return -ENOTSUPP;
  1022. } else if (vwrq->fixed)
  1023. /* currently only fixed value is supported */
  1024. return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
  1025. else {
  1026. printk(KERN_DEBUG
  1027. "%s: %s() auto power will be implemented later.\n",
  1028. priv->ndev->name, __FUNCTION__);
  1029. return -ENOTSUPP;
  1030. }
  1031. }
  1032. static int
  1033. prism54_reset(struct net_device *ndev, struct iw_request_info *info,
  1034. __u32 * uwrq, char *extra)
  1035. {
  1036. islpci_reset(netdev_priv(ndev), 0);
  1037. return 0;
  1038. }
  1039. static int
  1040. prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
  1041. struct iw_point *dwrq, char *extra)
  1042. {
  1043. union oid_res_t r;
  1044. int rvalue;
  1045. enum oid_num_t n = dwrq->flags;
  1046. rvalue = mgt_get_request((islpci_private *) ndev->priv, n, 0, NULL, &r);
  1047. dwrq->length = mgt_response_to_str(n, &r, extra);
  1048. if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
  1049. kfree(r.ptr);
  1050. return rvalue;
  1051. }
  1052. static int
  1053. prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
  1054. __u32 * uwrq, char *extra)
  1055. {
  1056. u32 oid = uwrq[0], u = uwrq[1];
  1057. return mgt_set_request((islpci_private *) ndev->priv, oid, 0, &u);
  1058. }
  1059. static int
  1060. prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
  1061. struct iw_point *dwrq, char *extra)
  1062. {
  1063. u32 oid = dwrq->flags;
  1064. return mgt_set_request((islpci_private *) ndev->priv, oid, 0, extra);
  1065. }
  1066. void
  1067. prism54_acl_init(struct islpci_acl *acl)
  1068. {
  1069. sema_init(&acl->sem, 1);
  1070. INIT_LIST_HEAD(&acl->mac_list);
  1071. acl->size = 0;
  1072. acl->policy = MAC_POLICY_OPEN;
  1073. }
  1074. static void
  1075. prism54_clear_mac(struct islpci_acl *acl)
  1076. {
  1077. struct list_head *ptr, *next;
  1078. struct mac_entry *entry;
  1079. if (down_interruptible(&acl->sem))
  1080. return;
  1081. if (acl->size == 0) {
  1082. up(&acl->sem);
  1083. return;
  1084. }
  1085. for (ptr = acl->mac_list.next, next = ptr->next;
  1086. ptr != &acl->mac_list; ptr = next, next = ptr->next) {
  1087. entry = list_entry(ptr, struct mac_entry, _list);
  1088. list_del(ptr);
  1089. kfree(entry);
  1090. }
  1091. acl->size = 0;
  1092. up(&acl->sem);
  1093. }
  1094. void
  1095. prism54_acl_clean(struct islpci_acl *acl)
  1096. {
  1097. prism54_clear_mac(acl);
  1098. }
  1099. static int
  1100. prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
  1101. struct sockaddr *awrq, char *extra)
  1102. {
  1103. islpci_private *priv = netdev_priv(ndev);
  1104. struct islpci_acl *acl = &priv->acl;
  1105. struct mac_entry *entry;
  1106. struct sockaddr *addr = (struct sockaddr *) extra;
  1107. if (addr->sa_family != ARPHRD_ETHER)
  1108. return -EOPNOTSUPP;
  1109. entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
  1110. if (entry == NULL)
  1111. return -ENOMEM;
  1112. memcpy(entry->addr, addr->sa_data, ETH_ALEN);
  1113. if (down_interruptible(&acl->sem)) {
  1114. kfree(entry);
  1115. return -ERESTARTSYS;
  1116. }
  1117. list_add_tail(&entry->_list, &acl->mac_list);
  1118. acl->size++;
  1119. up(&acl->sem);
  1120. return 0;
  1121. }
  1122. static int
  1123. prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
  1124. struct sockaddr *awrq, char *extra)
  1125. {
  1126. islpci_private *priv = netdev_priv(ndev);
  1127. struct islpci_acl *acl = &priv->acl;
  1128. struct mac_entry *entry;
  1129. struct list_head *ptr;
  1130. struct sockaddr *addr = (struct sockaddr *) extra;
  1131. if (addr->sa_family != ARPHRD_ETHER)
  1132. return -EOPNOTSUPP;
  1133. if (down_interruptible(&acl->sem))
  1134. return -ERESTARTSYS;
  1135. for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
  1136. entry = list_entry(ptr, struct mac_entry, _list);
  1137. if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
  1138. list_del(ptr);
  1139. acl->size--;
  1140. kfree(entry);
  1141. up(&acl->sem);
  1142. return 0;
  1143. }
  1144. }
  1145. up(&acl->sem);
  1146. return -EINVAL;
  1147. }
  1148. static int
  1149. prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
  1150. struct iw_point *dwrq, char *extra)
  1151. {
  1152. islpci_private *priv = netdev_priv(ndev);
  1153. struct islpci_acl *acl = &priv->acl;
  1154. struct mac_entry *entry;
  1155. struct list_head *ptr;
  1156. struct sockaddr *dst = (struct sockaddr *) extra;
  1157. dwrq->length = 0;
  1158. if (down_interruptible(&acl->sem))
  1159. return -ERESTARTSYS;
  1160. for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
  1161. entry = list_entry(ptr, struct mac_entry, _list);
  1162. memcpy(dst->sa_data, entry->addr, ETH_ALEN);
  1163. dst->sa_family = ARPHRD_ETHER;
  1164. dwrq->length++;
  1165. dst++;
  1166. }
  1167. up(&acl->sem);
  1168. return 0;
  1169. }
  1170. /* Setting policy also clears the MAC acl, even if we don't change the defaut
  1171. * policy
  1172. */
  1173. static int
  1174. prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
  1175. __u32 * uwrq, char *extra)
  1176. {
  1177. islpci_private *priv = netdev_priv(ndev);
  1178. struct islpci_acl *acl = &priv->acl;
  1179. u32 mlmeautolevel;
  1180. prism54_clear_mac(acl);
  1181. if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
  1182. return -EINVAL;
  1183. down_write(&priv->mib_sem);
  1184. acl->policy = *uwrq;
  1185. /* the ACL code needs an intermediate mlmeautolevel */
  1186. if ((priv->iw_mode == IW_MODE_MASTER) &&
  1187. (acl->policy != MAC_POLICY_OPEN))
  1188. mlmeautolevel = DOT11_MLME_INTERMEDIATE;
  1189. else
  1190. mlmeautolevel = CARD_DEFAULT_MLME_MODE;
  1191. if (priv->wpa)
  1192. mlmeautolevel = DOT11_MLME_EXTENDED;
  1193. mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
  1194. /* restart the card with our new policy */
  1195. if (mgt_commit(priv)) {
  1196. up_write(&priv->mib_sem);
  1197. return -EIO;
  1198. }
  1199. up_write(&priv->mib_sem);
  1200. return 0;
  1201. }
  1202. static int
  1203. prism54_get_policy(struct net_device *ndev, struct iw_request_info *info,
  1204. __u32 * uwrq, char *extra)
  1205. {
  1206. islpci_private *priv = netdev_priv(ndev);
  1207. struct islpci_acl *acl = &priv->acl;
  1208. *uwrq = acl->policy;
  1209. return 0;
  1210. }
  1211. /* Return 1 only if client should be accepted. */
  1212. static int
  1213. prism54_mac_accept(struct islpci_acl *acl, char *mac)
  1214. {
  1215. struct list_head *ptr;
  1216. struct mac_entry *entry;
  1217. int res = 0;
  1218. if (down_interruptible(&acl->sem))
  1219. return -ERESTARTSYS;
  1220. if (acl->policy == MAC_POLICY_OPEN) {
  1221. up(&acl->sem);
  1222. return 1;
  1223. }
  1224. for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
  1225. entry = list_entry(ptr, struct mac_entry, _list);
  1226. if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
  1227. res = 1;
  1228. break;
  1229. }
  1230. }
  1231. res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
  1232. up(&acl->sem);
  1233. return res;
  1234. }
  1235. static int
  1236. prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
  1237. struct iw_point *dwrq, char *extra)
  1238. {
  1239. struct obj_mlme *mlme;
  1240. int rvalue;
  1241. mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
  1242. if (mlme == NULL)
  1243. return -ENOMEM;
  1244. /* Tell the card to kick every client */
  1245. mlme->id = 0;
  1246. rvalue =
  1247. mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
  1248. kfree(mlme);
  1249. return rvalue;
  1250. }
  1251. static int
  1252. prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
  1253. struct sockaddr *awrq, char *extra)
  1254. {
  1255. struct obj_mlme *mlme;
  1256. struct sockaddr *addr = (struct sockaddr *) extra;
  1257. int rvalue;
  1258. if (addr->sa_family != ARPHRD_ETHER)
  1259. return -EOPNOTSUPP;
  1260. mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
  1261. if (mlme == NULL)
  1262. return -ENOMEM;
  1263. /* Tell the card to only kick the corresponding bastard */
  1264. memcpy(mlme->address, addr->sa_data, ETH_ALEN);
  1265. mlme->id = -1;
  1266. rvalue =
  1267. mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
  1268. kfree(mlme);
  1269. return rvalue;
  1270. }
  1271. /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
  1272. static void
  1273. format_event(islpci_private *priv, char *dest, const char *str,
  1274. const struct obj_mlme *mlme, u16 *length, int error)
  1275. {
  1276. const u8 *a = mlme->address;
  1277. int n = snprintf(dest, IW_CUSTOM_MAX,
  1278. "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s (%2.2X)",
  1279. str,
  1280. ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"),
  1281. a[0], a[1], a[2], a[3], a[4], a[5],
  1282. (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
  1283. : ""), mlme->code);
  1284. BUG_ON(n > IW_CUSTOM_MAX);
  1285. *length = n;
  1286. }
  1287. static void
  1288. send_formatted_event(islpci_private *priv, const char *str,
  1289. const struct obj_mlme *mlme, int error)
  1290. {
  1291. union iwreq_data wrqu;
  1292. char *memptr;
  1293. memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
  1294. if (!memptr)
  1295. return;
  1296. wrqu.data.pointer = memptr;
  1297. wrqu.data.length = 0;
  1298. format_event(priv, memptr, str, mlme, &wrqu.data.length,
  1299. error);
  1300. wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
  1301. kfree(memptr);
  1302. }
  1303. static void
  1304. send_simple_event(islpci_private *priv, const char *str)
  1305. {
  1306. union iwreq_data wrqu;
  1307. char *memptr;
  1308. int n = strlen(str);
  1309. memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
  1310. if (!memptr)
  1311. return;
  1312. BUG_ON(n > IW_CUSTOM_MAX);
  1313. wrqu.data.pointer = memptr;
  1314. wrqu.data.length = n;
  1315. strcpy(memptr, str);
  1316. wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
  1317. kfree(memptr);
  1318. }
  1319. static void
  1320. link_changed(struct net_device *ndev, u32 bitrate)
  1321. {
  1322. islpci_private *priv = netdev_priv(ndev);
  1323. if (bitrate) {
  1324. if (priv->iw_mode == IW_MODE_INFRA) {
  1325. union iwreq_data uwrq;
  1326. prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
  1327. NULL);
  1328. wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
  1329. } else
  1330. send_simple_event(netdev_priv(ndev),
  1331. "Link established");
  1332. } else
  1333. send_simple_event(netdev_priv(ndev), "Link lost");
  1334. }
  1335. /* Beacon/ProbeResp payload header */
  1336. struct ieee80211_beacon_phdr {
  1337. u8 timestamp[8];
  1338. u16 beacon_int;
  1339. u16 capab_info;
  1340. } __attribute__ ((packed));
  1341. #define WLAN_EID_GENERIC 0xdd
  1342. static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
  1343. #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
  1344. #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
  1345. static void
  1346. prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
  1347. u8 *wpa_ie, size_t wpa_ie_len)
  1348. {
  1349. struct list_head *ptr;
  1350. struct islpci_bss_wpa_ie *bss = NULL;
  1351. if (wpa_ie_len > MAX_WPA_IE_LEN)
  1352. wpa_ie_len = MAX_WPA_IE_LEN;
  1353. if (down_interruptible(&priv->wpa_sem))
  1354. return;
  1355. /* try to use existing entry */
  1356. list_for_each(ptr, &priv->bss_wpa_list) {
  1357. bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
  1358. if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
  1359. list_move(&bss->list, &priv->bss_wpa_list);
  1360. break;
  1361. }
  1362. bss = NULL;
  1363. }
  1364. if (bss == NULL) {
  1365. /* add a new BSS entry; if max number of entries is already
  1366. * reached, replace the least recently updated */
  1367. if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
  1368. bss = list_entry(priv->bss_wpa_list.prev,
  1369. struct islpci_bss_wpa_ie, list);
  1370. list_del(&bss->list);
  1371. } else {
  1372. bss = kmalloc(sizeof (*bss), GFP_ATOMIC);
  1373. if (bss != NULL) {
  1374. priv->num_bss_wpa++;
  1375. memset(bss, 0, sizeof (*bss));
  1376. }
  1377. }
  1378. if (bss != NULL) {
  1379. memcpy(bss->bssid, bssid, ETH_ALEN);
  1380. list_add(&bss->list, &priv->bss_wpa_list);
  1381. }
  1382. }
  1383. if (bss != NULL) {
  1384. memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
  1385. bss->wpa_ie_len = wpa_ie_len;
  1386. bss->last_update = jiffies;
  1387. } else {
  1388. printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR
  1389. "\n", MAC2STR(bssid));
  1390. }
  1391. /* expire old entries from WPA list */
  1392. while (priv->num_bss_wpa > 0) {
  1393. bss = list_entry(priv->bss_wpa_list.prev,
  1394. struct islpci_bss_wpa_ie, list);
  1395. if (!time_after(jiffies, bss->last_update + 60 * HZ))
  1396. break;
  1397. list_del(&bss->list);
  1398. priv->num_bss_wpa--;
  1399. kfree(bss);
  1400. }
  1401. up(&priv->wpa_sem);
  1402. }
  1403. static size_t
  1404. prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
  1405. {
  1406. struct list_head *ptr;
  1407. struct islpci_bss_wpa_ie *bss = NULL;
  1408. size_t len = 0;
  1409. if (down_interruptible(&priv->wpa_sem))
  1410. return 0;
  1411. list_for_each(ptr, &priv->bss_wpa_list) {
  1412. bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
  1413. if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
  1414. break;
  1415. bss = NULL;
  1416. }
  1417. if (bss) {
  1418. len = bss->wpa_ie_len;
  1419. memcpy(wpa_ie, bss->wpa_ie, len);
  1420. }
  1421. up(&priv->wpa_sem);
  1422. return len;
  1423. }
  1424. void
  1425. prism54_wpa_ie_init(islpci_private *priv)
  1426. {
  1427. INIT_LIST_HEAD(&priv->bss_wpa_list);
  1428. sema_init(&priv->wpa_sem, 1);
  1429. }
  1430. void
  1431. prism54_wpa_ie_clean(islpci_private *priv)
  1432. {
  1433. struct list_head *ptr, *n;
  1434. list_for_each_safe(ptr, n, &priv->bss_wpa_list) {
  1435. struct islpci_bss_wpa_ie *bss;
  1436. bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
  1437. kfree(bss);
  1438. }
  1439. }
  1440. static void
  1441. prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
  1442. u8 *payload, size_t len)
  1443. {
  1444. struct ieee80211_beacon_phdr *hdr;
  1445. u8 *pos, *end;
  1446. if (!priv->wpa)
  1447. return;
  1448. hdr = (struct ieee80211_beacon_phdr *) payload;
  1449. pos = (u8 *) (hdr + 1);
  1450. end = payload + len;
  1451. while (pos < end) {
  1452. if (pos + 2 + pos[1] > end) {
  1453. printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
  1454. "for " MACSTR "\n", MAC2STR(addr));
  1455. return;
  1456. }
  1457. if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
  1458. memcmp(pos + 2, wpa_oid, 4) == 0) {
  1459. prism54_wpa_ie_add(priv, addr, pos, pos[1] + 2);
  1460. return;
  1461. }
  1462. pos += 2 + pos[1];
  1463. }
  1464. }
  1465. static void
  1466. handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
  1467. {
  1468. if (((mlme->state == DOT11_STATE_AUTHING) ||
  1469. (mlme->state == DOT11_STATE_ASSOCING))
  1470. && mgt_mlme_answer(priv)) {
  1471. /* Someone is requesting auth and we must respond. Just send back
  1472. * the trap with error code set accordingly.
  1473. */
  1474. mlme->code = prism54_mac_accept(&priv->acl,
  1475. mlme->address) ? 0 : 1;
  1476. mgt_set_request(priv, oid, 0, mlme);
  1477. }
  1478. }
  1479. static int
  1480. prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
  1481. char *data)
  1482. {
  1483. struct obj_mlme *mlme = (struct obj_mlme *) data;
  1484. struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data;
  1485. struct obj_mlmeex *confirm;
  1486. u8 wpa_ie[MAX_WPA_IE_LEN];
  1487. int wpa_ie_len;
  1488. size_t len = 0; /* u16, better? */
  1489. u8 *payload = NULL, *pos = NULL;
  1490. int ret;
  1491. /* I think all trapable objects are listed here.
  1492. * Some oids have a EX version. The difference is that they are emitted
  1493. * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
  1494. * with more info.
  1495. * The few events already defined by the wireless tools are not really
  1496. * suited. We use the more flexible custom event facility.
  1497. */
  1498. if (oid >= DOT11_OID_BEACON) {
  1499. len = mlmeex->size;
  1500. payload = pos = mlmeex->data;
  1501. }
  1502. /* I fear prism54_process_bss_data won't work with big endian data */
  1503. if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE))
  1504. prism54_process_bss_data(priv, oid, mlmeex->address,
  1505. payload, len);
  1506. mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme);
  1507. switch (oid) {
  1508. case GEN_OID_LINKSTATE:
  1509. link_changed(priv->ndev, (u32) *data);
  1510. break;
  1511. case DOT11_OID_MICFAILURE:
  1512. send_simple_event(priv, "Mic failure");
  1513. break;
  1514. case DOT11_OID_DEAUTHENTICATE:
  1515. send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
  1516. break;
  1517. case DOT11_OID_AUTHENTICATE:
  1518. handle_request(priv, mlme, oid);
  1519. send_formatted_event(priv, "Authenticate request", mlme, 1);
  1520. break;
  1521. case DOT11_OID_DISASSOCIATE:
  1522. send_formatted_event(priv, "Disassociate request", mlme, 0);
  1523. break;
  1524. case DOT11_OID_ASSOCIATE:
  1525. handle_request(priv, mlme, oid);
  1526. send_formatted_event(priv, "Associate request", mlme, 1);
  1527. break;
  1528. case DOT11_OID_REASSOCIATE:
  1529. handle_request(priv, mlme, oid);
  1530. send_formatted_event(priv, "ReAssociate request", mlme, 1);
  1531. break;
  1532. case DOT11_OID_BEACON:
  1533. send_formatted_event(priv,
  1534. "Received a beacon from an unkown AP",
  1535. mlme, 0);
  1536. break;
  1537. case DOT11_OID_PROBE:
  1538. /* we received a probe from a client. */
  1539. send_formatted_event(priv, "Received a probe from client", mlme,
  1540. 0);
  1541. break;
  1542. /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
  1543. * is backward compatible layout-wise with "struct obj_mlme".
  1544. */
  1545. case DOT11_OID_DEAUTHENTICATEEX:
  1546. send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
  1547. break;
  1548. case DOT11_OID_AUTHENTICATEEX:
  1549. handle_request(priv, mlme, oid);
  1550. send_formatted_event(priv, "Authenticate request (ex)", mlme, 1);
  1551. if (priv->iw_mode != IW_MODE_MASTER
  1552. && mlmeex->state != DOT11_STATE_AUTHING)
  1553. break;
  1554. confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC);
  1555. if (!confirm)
  1556. break;
  1557. memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
  1558. printk(KERN_DEBUG "Authenticate from: address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
  1559. mlmeex->address[0],
  1560. mlmeex->address[1],
  1561. mlmeex->address[2],
  1562. mlmeex->address[3],
  1563. mlmeex->address[4],
  1564. mlmeex->address[5]
  1565. );
  1566. confirm->id = -1; /* or mlmeex->id ? */
  1567. confirm->state = 0; /* not used */
  1568. confirm->code = 0;
  1569. confirm->size = 6;
  1570. confirm->data[0] = 0x00;
  1571. confirm->data[1] = 0x00;
  1572. confirm->data[2] = 0x02;
  1573. confirm->data[3] = 0x00;
  1574. confirm->data[4] = 0x00;
  1575. confirm->data[5] = 0x00;
  1576. ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6);
  1577. kfree(confirm);
  1578. if (ret)
  1579. return ret;
  1580. break;
  1581. case DOT11_OID_DISASSOCIATEEX:
  1582. send_formatted_event(priv, "Disassociate request (ex)", mlme, 0);
  1583. break;
  1584. case DOT11_OID_ASSOCIATEEX:
  1585. handle_request(priv, mlme, oid);
  1586. send_formatted_event(priv, "Associate request (ex)", mlme, 1);
  1587. if (priv->iw_mode != IW_MODE_MASTER
  1588. && mlmeex->state != DOT11_STATE_AUTHING)
  1589. break;
  1590. confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
  1591. if (!confirm)
  1592. break;
  1593. memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
  1594. confirm->id = ((struct obj_mlmeex *)mlme)->id;
  1595. confirm->state = 0; /* not used */
  1596. confirm->code = 0;
  1597. wpa_ie_len = prism54_wpa_ie_get(priv, mlmeex->address, wpa_ie);
  1598. if (!wpa_ie_len) {
  1599. printk(KERN_DEBUG "No WPA IE found from "
  1600. "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
  1601. mlmeex->address[0],
  1602. mlmeex->address[1],
  1603. mlmeex->address[2],
  1604. mlmeex->address[3],
  1605. mlmeex->address[4],
  1606. mlmeex->address[5]
  1607. );
  1608. kfree(confirm);
  1609. break;
  1610. }
  1611. confirm->size = wpa_ie_len;
  1612. memcpy(&confirm->data, wpa_ie, wpa_ie_len);
  1613. mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
  1614. kfree(confirm);
  1615. break;
  1616. case DOT11_OID_REASSOCIATEEX:
  1617. handle_request(priv, mlme, oid);
  1618. send_formatted_event(priv, "Reassociate request (ex)", mlme, 1);
  1619. if (priv->iw_mode != IW_MODE_MASTER
  1620. && mlmeex->state != DOT11_STATE_ASSOCING)
  1621. break;
  1622. confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
  1623. if (!confirm)
  1624. break;
  1625. memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
  1626. confirm->id = mlmeex->id;
  1627. confirm->state = 0; /* not used */
  1628. confirm->code = 0;
  1629. wpa_ie_len = prism54_wpa_ie_get(priv, mlmeex->address, wpa_ie);
  1630. if (!wpa_ie_len) {
  1631. printk(KERN_DEBUG "No WPA IE found from "
  1632. "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
  1633. mlmeex->address[0],
  1634. mlmeex->address[1],
  1635. mlmeex->address[2],
  1636. mlmeex->address[3],
  1637. mlmeex->address[4],
  1638. mlmeex->address[5]
  1639. );
  1640. kfree(confirm);
  1641. break;
  1642. }
  1643. confirm->size = wpa_ie_len;
  1644. memcpy(&confirm->data, wpa_ie, wpa_ie_len);
  1645. mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
  1646. kfree(confirm);
  1647. break;
  1648. default:
  1649. return -EINVAL;
  1650. }
  1651. return 0;
  1652. }
  1653. /*
  1654. * Process a device trap. This is called via schedule_work(), outside of
  1655. * interrupt context, no locks held.
  1656. */
  1657. void
  1658. prism54_process_trap(void *data)
  1659. {
  1660. struct islpci_mgmtframe *frame = data;
  1661. struct net_device *ndev = frame->ndev;
  1662. enum oid_num_t n = mgt_oidtonum(frame->header->oid);
  1663. if (n != OID_NUM_LAST)
  1664. prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
  1665. islpci_mgt_release(frame);
  1666. }
  1667. int
  1668. prism54_set_mac_address(struct net_device *ndev, void *addr)
  1669. {
  1670. islpci_private *priv = netdev_priv(ndev);
  1671. int ret;
  1672. if (ndev->addr_len != 6)
  1673. return -EINVAL;
  1674. ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
  1675. &((struct sockaddr *) addr)->sa_data);
  1676. if (!ret)
  1677. memcpy(priv->ndev->dev_addr,
  1678. &((struct sockaddr *) addr)->sa_data, 6);
  1679. return ret;
  1680. }
  1681. /* Note: currently, use hostapd ioctl from the Host AP driver for WPA
  1682. * support. This is to be replaced with Linux wireless extensions once they
  1683. * get WPA support. */
  1684. /* Note II: please leave all this together as it will be easier to remove later,
  1685. * once wireless extensions add WPA support -mcgrof */
  1686. /* PRISM54_HOSTAPD ioctl() cmd: */
  1687. enum {
  1688. PRISM2_SET_ENCRYPTION = 6,
  1689. PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
  1690. PRISM2_HOSTAPD_MLME = 13,
  1691. PRISM2_HOSTAPD_SCAN_REQ = 14,
  1692. };
  1693. #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
  1694. #define PRISM54_HOSTAPD SIOCIWFIRSTPRIV+25
  1695. #define PRISM54_DROP_UNENCRYPTED SIOCIWFIRSTPRIV+26
  1696. #define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
  1697. #define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
  1698. ((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
  1699. /* Maximum length for algorithm names (-1 for nul termination)
  1700. * used in ioctl() */
  1701. #define HOSTAP_CRYPT_ALG_NAME_LEN 16
  1702. struct prism2_hostapd_param {
  1703. u32 cmd;
  1704. u8 sta_addr[ETH_ALEN];
  1705. union {
  1706. struct {
  1707. u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
  1708. u32 flags;
  1709. u32 err;
  1710. u8 idx;
  1711. u8 seq[8]; /* sequence counter (set: RX, get: TX) */
  1712. u16 key_len;
  1713. u8 key[0];
  1714. } crypt;
  1715. struct {
  1716. u8 len;
  1717. u8 data[0];
  1718. } generic_elem;
  1719. struct {
  1720. #define MLME_STA_DEAUTH 0
  1721. #define MLME_STA_DISASSOC 1
  1722. u16 cmd;
  1723. u16 reason_code;
  1724. } mlme;
  1725. struct {
  1726. u8 ssid_len;
  1727. u8 ssid[32];
  1728. } scan_req;
  1729. } u;
  1730. };
  1731. static int
  1732. prism2_ioctl_set_encryption(struct net_device *dev,
  1733. struct prism2_hostapd_param *param,
  1734. int param_len)
  1735. {
  1736. islpci_private *priv = netdev_priv(dev);
  1737. int rvalue = 0, force = 0;
  1738. int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
  1739. union oid_res_t r;
  1740. /* with the new API, it's impossible to get a NULL pointer.
  1741. * New version of iwconfig set the IW_ENCODE_NOKEY flag
  1742. * when no key is given, but older versions don't. */
  1743. if (param->u.crypt.key_len > 0) {
  1744. /* we have a key to set */
  1745. int index = param->u.crypt.idx;
  1746. int current_index;
  1747. struct obj_key key = { DOT11_PRIV_TKIP, 0, "" };
  1748. /* get the current key index */
  1749. rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
  1750. current_index = r.u;
  1751. /* Verify that the key is not marked as invalid */
  1752. if (!(param->u.crypt.flags & IW_ENCODE_NOKEY)) {
  1753. key.length = param->u.crypt.key_len > sizeof (param->u.crypt.key) ?
  1754. sizeof (param->u.crypt.key) : param->u.crypt.key_len;
  1755. memcpy(key.key, param->u.crypt.key, key.length);
  1756. if (key.length == 32)
  1757. /* we want WPA-PSK */
  1758. key.type = DOT11_PRIV_TKIP;
  1759. if ((index < 0) || (index > 3))
  1760. /* no index provided use the current one */
  1761. index = current_index;
  1762. /* now send the key to the card */
  1763. rvalue |=
  1764. mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
  1765. &key);
  1766. }
  1767. /*
  1768. * If a valid key is set, encryption should be enabled
  1769. * (user may turn it off later).
  1770. * This is also how "iwconfig ethX key on" works
  1771. */
  1772. if ((index == current_index) && (key.length > 0))
  1773. force = 1;
  1774. } else {
  1775. int index = (param->u.crypt.flags & IW_ENCODE_INDEX) - 1;
  1776. if ((index >= 0) && (index <= 3)) {
  1777. /* we want to set the key index */
  1778. rvalue |=
  1779. mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
  1780. &index);
  1781. } else {
  1782. if (!param->u.crypt.flags & IW_ENCODE_MODE) {
  1783. /* we cannot do anything. Complain. */
  1784. return -EINVAL;
  1785. }
  1786. }
  1787. }
  1788. /* now read the flags */
  1789. if (param->u.crypt.flags & IW_ENCODE_DISABLED) {
  1790. /* Encoding disabled,
  1791. * authen = DOT11_AUTH_OS;
  1792. * invoke = 0;
  1793. * exunencrypt = 0; */
  1794. }
  1795. if (param->u.crypt.flags & IW_ENCODE_OPEN)
  1796. /* Encode but accept non-encoded packets. No auth */
  1797. invoke = 1;
  1798. if ((param->u.crypt.flags & IW_ENCODE_RESTRICTED) || force) {
  1799. /* Refuse non-encoded packets. Auth */
  1800. authen = DOT11_AUTH_BOTH;
  1801. invoke = 1;
  1802. exunencrypt = 1;
  1803. }
  1804. /* do the change if requested */
  1805. if ((param->u.crypt.flags & IW_ENCODE_MODE) || force) {
  1806. rvalue |=
  1807. mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
  1808. rvalue |=
  1809. mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
  1810. rvalue |=
  1811. mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
  1812. &exunencrypt);
  1813. }
  1814. return rvalue;
  1815. }
  1816. static int
  1817. prism2_ioctl_set_generic_element(struct net_device *ndev,
  1818. struct prism2_hostapd_param *param,
  1819. int param_len)
  1820. {
  1821. islpci_private *priv = netdev_priv(ndev);
  1822. int max_len, len, alen, ret=0;
  1823. struct obj_attachment *attach;
  1824. len = param->u.generic_elem.len;
  1825. max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
  1826. if (max_len < 0 || max_len < len)
  1827. return -EINVAL;
  1828. alen = sizeof(*attach) + len;
  1829. attach = kmalloc(alen, GFP_KERNEL);
  1830. if (attach == NULL)
  1831. return -ENOMEM;
  1832. memset(attach, 0, alen);
  1833. #define WLAN_FC_TYPE_MGMT 0
  1834. #define WLAN_FC_STYPE_ASSOC_REQ 0
  1835. #define WLAN_FC_STYPE_REASSOC_REQ 2
  1836. /* Note: endianness is covered by mgt_set_varlen */
  1837. attach->type = (WLAN_FC_TYPE_MGMT << 2) |
  1838. (WLAN_FC_STYPE_ASSOC_REQ << 4);
  1839. attach->id = -1;
  1840. attach->size = len;
  1841. memcpy(attach->data, param->u.generic_elem.data, len);
  1842. ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
  1843. if (ret == 0) {
  1844. attach->type = (WLAN_FC_TYPE_MGMT << 2) |
  1845. (WLAN_FC_STYPE_REASSOC_REQ << 4);
  1846. ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
  1847. if (ret == 0)
  1848. printk(KERN_DEBUG "%s: WPA IE Attachment was set\n",
  1849. ndev->name);
  1850. }
  1851. kfree(attach);
  1852. return ret;
  1853. }
  1854. static int
  1855. prism2_ioctl_mlme(struct net_device *dev, struct prism2_hostapd_param *param)
  1856. {
  1857. return -EOPNOTSUPP;
  1858. }
  1859. static int
  1860. prism2_ioctl_scan_req(struct net_device *ndev,
  1861. struct prism2_hostapd_param *param)
  1862. {
  1863. islpci_private *priv = netdev_priv(ndev);
  1864. int i, rvalue;
  1865. struct obj_bsslist *bsslist;
  1866. u32 noise = 0;
  1867. char *extra = "";
  1868. char *current_ev = "foo";
  1869. union oid_res_t r;
  1870. if (islpci_get_state(priv) < PRV_STATE_INIT) {
  1871. /* device is not ready, fail gently */
  1872. return 0;
  1873. }
  1874. /* first get the noise value. We will use it to report the link quality */
  1875. rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
  1876. noise = r.u;
  1877. /* Ask the device for a list of known bss. We can report at most
  1878. * IW_MAX_AP=64 to the range struct. But the device won't repport anything
  1879. * if you change the value of IWMAX_BSS=24.
  1880. */
  1881. rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
  1882. bsslist = r.ptr;
  1883. /* ok now, scan the list and translate its info */
  1884. for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++)
  1885. current_ev = prism54_translate_bss(ndev, current_ev,
  1886. extra + IW_SCAN_MAX_DATA,
  1887. &(bsslist->bsslist[i]),
  1888. noise);
  1889. kfree(bsslist);
  1890. return rvalue;
  1891. }
  1892. static int
  1893. prism54_hostapd(struct net_device *ndev, struct iw_point *p)
  1894. {
  1895. struct prism2_hostapd_param *param;
  1896. int ret = 0;
  1897. u32 uwrq;
  1898. printk(KERN_DEBUG "prism54_hostapd - len=%d\n", p->length);
  1899. if (p->length < sizeof(struct prism2_hostapd_param) ||
  1900. p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
  1901. return -EINVAL;
  1902. param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
  1903. if (param == NULL)
  1904. return -ENOMEM;
  1905. if (copy_from_user(param, p->pointer, p->length)) {
  1906. kfree(param);
  1907. return -EFAULT;
  1908. }
  1909. switch (param->cmd) {
  1910. case PRISM2_SET_ENCRYPTION:
  1911. printk(KERN_DEBUG "%s: Caught WPA supplicant set encryption request\n",
  1912. ndev->name);
  1913. ret = prism2_ioctl_set_encryption(ndev, param, p->length);
  1914. break;
  1915. case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
  1916. printk(KERN_DEBUG "%s: Caught WPA supplicant set WPA IE request\n",
  1917. ndev->name);
  1918. ret = prism2_ioctl_set_generic_element(ndev, param,
  1919. p->length);
  1920. break;
  1921. case PRISM2_HOSTAPD_MLME:
  1922. printk(KERN_DEBUG "%s: Caught WPA supplicant MLME request\n",
  1923. ndev->name);
  1924. ret = prism2_ioctl_mlme(ndev, param);
  1925. break;
  1926. case PRISM2_HOSTAPD_SCAN_REQ:
  1927. printk(KERN_DEBUG "%s: Caught WPA supplicant scan request\n",
  1928. ndev->name);
  1929. ret = prism2_ioctl_scan_req(ndev, param);
  1930. break;
  1931. case PRISM54_SET_WPA:
  1932. printk(KERN_DEBUG "%s: Caught WPA supplicant wpa init request\n",
  1933. ndev->name);
  1934. uwrq = 1;
  1935. ret = prism54_set_wpa(ndev, NULL, &uwrq, NULL);
  1936. break;
  1937. case PRISM54_DROP_UNENCRYPTED:
  1938. printk(KERN_DEBUG "%s: Caught WPA drop unencrypted request\n",
  1939. ndev->name);
  1940. #if 0
  1941. uwrq = 0x01;
  1942. mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &uwrq);
  1943. down_write(&priv->mib_sem);
  1944. mgt_commit(priv);
  1945. up_write(&priv->mib_sem);
  1946. #endif
  1947. /* Not necessary, as set_wpa does it, should we just do it here though? */
  1948. ret = 0;
  1949. break;
  1950. default:
  1951. printk(KERN_DEBUG "%s: Caught a WPA supplicant request that is not supported\n",
  1952. ndev->name);
  1953. ret = -EOPNOTSUPP;
  1954. break;
  1955. }
  1956. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  1957. ret = -EFAULT;
  1958. kfree(param);
  1959. return ret;
  1960. }
  1961. static int
  1962. prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
  1963. __u32 * uwrq, char *extra)
  1964. {
  1965. islpci_private *priv = netdev_priv(ndev);
  1966. u32 mlme, authen, dot1x, filter, wep;
  1967. if (islpci_get_state(priv) < PRV_STATE_INIT)
  1968. return 0;
  1969. wep = 1; /* For privacy invoked */
  1970. filter = 1; /* Filter out all unencrypted frames */
  1971. dot1x = 0x01; /* To enable eap filter */
  1972. mlme = DOT11_MLME_EXTENDED;
  1973. authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
  1974. down_write(&priv->mib_sem);
  1975. priv->wpa = *uwrq;
  1976. switch (priv->wpa) {
  1977. default:
  1978. case 0: /* Clears/disables WPA and friends */
  1979. wep = 0;
  1980. filter = 0; /* Do not filter un-encrypted data */
  1981. dot1x = 0;
  1982. mlme = DOT11_MLME_AUTO;
  1983. printk("%s: Disabling WPA\n", ndev->name);
  1984. break;
  1985. case 2:
  1986. case 1: /* WPA */
  1987. printk("%s: Enabling WPA\n", ndev->name);
  1988. break;
  1989. }
  1990. up_write(&priv->mib_sem);
  1991. mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
  1992. mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep);
  1993. mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter);
  1994. mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
  1995. mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme);
  1996. return 0;
  1997. }
  1998. static int
  1999. prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
  2000. __u32 * uwrq, char *extra)
  2001. {
  2002. islpci_private *priv = netdev_priv(ndev);
  2003. *uwrq = priv->wpa;
  2004. return 0;
  2005. }
  2006. static int
  2007. prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info,
  2008. __u32 * uwrq, char *extra)
  2009. {
  2010. islpci_private *priv = netdev_priv(ndev);
  2011. priv->monitor_type =
  2012. (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211);
  2013. if (priv->iw_mode == IW_MODE_MONITOR)
  2014. priv->ndev->type = priv->monitor_type;
  2015. return 0;
  2016. }
  2017. static int
  2018. prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info,
  2019. __u32 * uwrq, char *extra)
  2020. {
  2021. islpci_private *priv = netdev_priv(ndev);
  2022. *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM);
  2023. return 0;
  2024. }
  2025. static int
  2026. prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info,
  2027. __u32 * uwrq, char *extra)
  2028. {
  2029. islpci_private *priv = netdev_priv(ndev);
  2030. priv->priv_oid = *uwrq;
  2031. printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
  2032. return 0;
  2033. }
  2034. static int
  2035. prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info,
  2036. struct iw_point *data, char *extra)
  2037. {
  2038. islpci_private *priv = netdev_priv(ndev);
  2039. struct islpci_mgmtframe *response;
  2040. int ret = -EIO;
  2041. printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
  2042. data->length = 0;
  2043. if (islpci_get_state(priv) >= PRV_STATE_INIT) {
  2044. ret =
  2045. islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
  2046. priv->priv_oid, extra, 256,
  2047. &response);
  2048. printk("%s: ret: %i\n", ndev->name, ret);
  2049. if (ret || !response
  2050. || response->header->operation == PIMFOR_OP_ERROR) {
  2051. if (response) {
  2052. islpci_mgt_release(response);
  2053. }
  2054. printk("%s: EIO\n", ndev->name);
  2055. ret = -EIO;
  2056. }
  2057. if (!ret) {
  2058. data->length = response->header->length;
  2059. memcpy(extra, response->data, data->length);
  2060. islpci_mgt_release(response);
  2061. printk("%s: len: %i\n", ndev->name, data->length);
  2062. }
  2063. }
  2064. return ret;
  2065. }
  2066. static int
  2067. prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info,
  2068. struct iw_point *data, char *extra)
  2069. {
  2070. islpci_private *priv = netdev_priv(ndev);
  2071. struct islpci_mgmtframe *response;
  2072. int ret = 0, response_op = PIMFOR_OP_ERROR;
  2073. printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid,
  2074. data->length);
  2075. if (islpci_get_state(priv) >= PRV_STATE_INIT) {
  2076. ret =
  2077. islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
  2078. priv->priv_oid, extra, data->length,
  2079. &response);
  2080. printk("%s: ret: %i\n", ndev->name, ret);
  2081. if (ret || !response
  2082. || response->header->operation == PIMFOR_OP_ERROR) {
  2083. if (response) {
  2084. islpci_mgt_release(response);
  2085. }
  2086. printk("%s: EIO\n", ndev->name);
  2087. ret = -EIO;
  2088. }
  2089. if (!ret) {
  2090. response_op = response->header->operation;
  2091. printk("%s: response_op: %i\n", ndev->name,
  2092. response_op);
  2093. islpci_mgt_release(response);
  2094. }
  2095. }
  2096. return (ret ? ret : -EINPROGRESS);
  2097. }
  2098. static int
  2099. prism54_set_spy(struct net_device *ndev,
  2100. struct iw_request_info *info,
  2101. union iwreq_data *uwrq, char *extra)
  2102. {
  2103. islpci_private *priv = netdev_priv(ndev);
  2104. u32 u, oid = OID_INL_CONFIG;
  2105. down_write(&priv->mib_sem);
  2106. mgt_get(priv, OID_INL_CONFIG, &u);
  2107. if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0))
  2108. /* disable spy */
  2109. u &= ~INL_CONFIG_RXANNEX;
  2110. else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0))
  2111. /* enable spy */
  2112. u |= INL_CONFIG_RXANNEX;
  2113. mgt_set(priv, OID_INL_CONFIG, &u);
  2114. mgt_commit_list(priv, &oid, 1);
  2115. up_write(&priv->mib_sem);
  2116. return iw_handler_set_spy(ndev, info, uwrq, extra);
  2117. }
  2118. static const iw_handler prism54_handler[] = {
  2119. (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */
  2120. (iw_handler) prism54_get_name, /* SIOCGIWNAME */
  2121. (iw_handler) NULL, /* SIOCSIWNWID */
  2122. (iw_handler) NULL, /* SIOCGIWNWID */
  2123. (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */
  2124. (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */
  2125. (iw_handler) prism54_set_mode, /* SIOCSIWMODE */
  2126. (iw_handler) prism54_get_mode, /* SIOCGIWMODE */
  2127. (iw_handler) prism54_set_sens, /* SIOCSIWSENS */
  2128. (iw_handler) prism54_get_sens, /* SIOCGIWSENS */
  2129. (iw_handler) NULL, /* SIOCSIWRANGE */
  2130. (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
  2131. (iw_handler) NULL, /* SIOCSIWPRIV */
  2132. (iw_handler) NULL, /* SIOCGIWPRIV */
  2133. (iw_handler) NULL, /* SIOCSIWSTATS */
  2134. (iw_handler) NULL, /* SIOCGIWSTATS */
  2135. prism54_set_spy, /* SIOCSIWSPY */
  2136. iw_handler_get_spy, /* SIOCGIWSPY */
  2137. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2138. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2139. (iw_handler) prism54_set_wap, /* SIOCSIWAP */
  2140. (iw_handler) prism54_get_wap, /* SIOCGIWAP */
  2141. (iw_handler) NULL, /* -- hole -- */
  2142. (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */
  2143. (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
  2144. (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
  2145. (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
  2146. (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
  2147. (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */
  2148. (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */
  2149. (iw_handler) NULL, /* -- hole -- */
  2150. (iw_handler) NULL, /* -- hole -- */
  2151. (iw_handler) prism54_set_rate, /* SIOCSIWRATE */
  2152. (iw_handler) prism54_get_rate, /* SIOCGIWRATE */
  2153. (iw_handler) prism54_set_rts, /* SIOCSIWRTS */
  2154. (iw_handler) prism54_get_rts, /* SIOCGIWRTS */
  2155. (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */
  2156. (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */
  2157. (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */
  2158. (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */
  2159. (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
  2160. (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
  2161. (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */
  2162. (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */
  2163. (iw_handler) NULL, /* SIOCSIWPOWER */
  2164. (iw_handler) NULL, /* SIOCGIWPOWER */
  2165. };
  2166. /* The low order bit identify a SET (0) or a GET (1) ioctl. */
  2167. #define PRISM54_RESET SIOCIWFIRSTPRIV
  2168. #define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1
  2169. #define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2
  2170. #define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3
  2171. #define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4
  2172. #define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6
  2173. #define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8
  2174. #define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10
  2175. #define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11
  2176. #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
  2177. #define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14
  2178. #define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15
  2179. #define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16
  2180. #define PRISM54_GET_OID SIOCIWFIRSTPRIV+17
  2181. #define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18
  2182. #define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20
  2183. #define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22
  2184. #define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23
  2185. #define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24
  2186. #define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
  2187. #define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
  2188. #define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
  2189. #define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x }
  2190. #define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x)
  2191. #define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x)
  2192. #define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x)
  2193. /* Note : limited to 128 private ioctls (wireless tools 26) */
  2194. static const struct iw_priv_args prism54_private_args[] = {
  2195. /*{ cmd, set_args, get_args, name } */
  2196. {PRISM54_RESET, 0, 0, "reset"},
  2197. {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  2198. "get_prismhdr"},
  2199. {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
  2200. "set_prismhdr"},
  2201. {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  2202. "getPolicy"},
  2203. {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
  2204. "setPolicy"},
  2205. {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
  2206. {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
  2207. "addMac"},
  2208. {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
  2209. "delMac"},
  2210. {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
  2211. "kickMac"},
  2212. {PRISM54_KICK_ALL, 0, 0, "kickAll"},
  2213. {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  2214. "get_wpa"},
  2215. {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
  2216. "set_wpa"},
  2217. {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
  2218. "dbg_oid"},
  2219. {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"},
  2220. {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"},
  2221. /* --- sub-ioctls handlers --- */
  2222. {PRISM54_GET_OID,
  2223. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""},
  2224. {PRISM54_SET_OID_U32,
  2225. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
  2226. {PRISM54_SET_OID_STR,
  2227. IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
  2228. {PRISM54_SET_OID_ADDR,
  2229. IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
  2230. /* --- sub-ioctls definitions --- */
  2231. IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"),
  2232. IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"),
  2233. IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"),
  2234. IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"),
  2235. IWPRIV_U32(DOT11_OID_STATE, "state"),
  2236. IWPRIV_U32(DOT11_OID_AID, "aid"),
  2237. IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"),
  2238. IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"),
  2239. IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"),
  2240. IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"),
  2241. IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"),
  2242. IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"),
  2243. IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"),
  2244. IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"),
  2245. IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"),
  2246. IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"),
  2247. IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"),
  2248. IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"),
  2249. IWPRIV_U32(DOT11_OID_PSM, "psm"),
  2250. IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"),
  2251. IWPRIV_U32(DOT11_OID_CLIENTS, "clients"),
  2252. IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"),
  2253. IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"),
  2254. IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"),
  2255. IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"),
  2256. IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"),
  2257. IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"),
  2258. IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"),
  2259. IWPRIV_GET(DOT11_OID_RATES, "rates"),
  2260. IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"),
  2261. IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"),
  2262. IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"),
  2263. IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"),
  2264. IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"),
  2265. IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"),
  2266. IWPRIV_U32(DOT11_OID_PROFILES, "profile"),
  2267. IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"),
  2268. IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"),
  2269. IWPRIV_GET(DOT11_OID_BSSS, "bsss"),
  2270. IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"),
  2271. IWPRIV_U32(OID_INL_MODE, "mode"),
  2272. IWPRIV_U32(OID_INL_CONFIG, "config"),
  2273. IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"),
  2274. IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"),
  2275. IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"),
  2276. };
  2277. static const iw_handler prism54_private_handler[] = {
  2278. (iw_handler) prism54_reset,
  2279. (iw_handler) prism54_get_policy,
  2280. (iw_handler) prism54_set_policy,
  2281. (iw_handler) prism54_get_mac,
  2282. (iw_handler) prism54_add_mac,
  2283. (iw_handler) NULL,
  2284. (iw_handler) prism54_del_mac,
  2285. (iw_handler) NULL,
  2286. (iw_handler) prism54_kick_mac,
  2287. (iw_handler) NULL,
  2288. (iw_handler) prism54_kick_all,
  2289. (iw_handler) prism54_get_wpa,
  2290. (iw_handler) prism54_set_wpa,
  2291. (iw_handler) NULL,
  2292. (iw_handler) prism54_debug_oid,
  2293. (iw_handler) prism54_debug_get_oid,
  2294. (iw_handler) prism54_debug_set_oid,
  2295. (iw_handler) prism54_get_oid,
  2296. (iw_handler) prism54_set_u32,
  2297. (iw_handler) NULL,
  2298. (iw_handler) prism54_set_raw,
  2299. (iw_handler) NULL,
  2300. (iw_handler) prism54_set_raw,
  2301. (iw_handler) prism54_get_prismhdr,
  2302. (iw_handler) prism54_set_prismhdr,
  2303. };
  2304. const struct iw_handler_def prism54_handler_def = {
  2305. .num_standard = sizeof (prism54_handler) / sizeof (iw_handler),
  2306. .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler),
  2307. .num_private_args =
  2308. sizeof (prism54_private_args) / sizeof (struct iw_priv_args),
  2309. .standard = (iw_handler *) prism54_handler,
  2310. .private = (iw_handler *) prism54_private_handler,
  2311. .private_args = (struct iw_priv_args *) prism54_private_args,
  2312. #if WIRELESS_EXT > 16
  2313. .get_wireless_stats = prism54_get_wireless_stats,
  2314. #endif /* WIRELESS_EXT > 16 */
  2315. #if WIRELESS_EXT == 16
  2316. .spy_offset = offsetof(islpci_private, spy_data),
  2317. #endif /* WIRELESS_EXT == 16 */
  2318. };
  2319. /* For wpa_supplicant */
  2320. int
  2321. prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
  2322. {
  2323. struct iwreq *wrq = (struct iwreq *) rq;
  2324. int ret = -1;
  2325. switch (cmd) {
  2326. case PRISM54_HOSTAPD:
  2327. if (!capable(CAP_NET_ADMIN))
  2328. return -EPERM;
  2329. ret = prism54_hostapd(ndev, &wrq->u.data);
  2330. return ret;
  2331. }
  2332. return -EOPNOTSUPP;
  2333. }