isl_ioctl.c 73 KB

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