wext.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423
  1. /**
  2. * This file contains ioctl functions
  3. */
  4. #include <linux/ctype.h>
  5. #include <linux/delay.h>
  6. #include <linux/if.h>
  7. #include <linux/if_arp.h>
  8. #include <linux/wireless.h>
  9. #include <linux/bitops.h>
  10. #include <net/ieee80211.h>
  11. #include <net/iw_handler.h>
  12. #include "host.h"
  13. #include "radiotap.h"
  14. #include "decl.h"
  15. #include "defs.h"
  16. #include "dev.h"
  17. #include "join.h"
  18. #include "wext.h"
  19. #include "assoc.h"
  20. /**
  21. * @brief Convert mw value to dbm value
  22. *
  23. * @param mw the value of mw
  24. * @return the value of dbm
  25. */
  26. static int mw_to_dbm(int mw)
  27. {
  28. if (mw < 2)
  29. return 0;
  30. else if (mw < 3)
  31. return 3;
  32. else if (mw < 4)
  33. return 5;
  34. else if (mw < 6)
  35. return 7;
  36. else if (mw < 7)
  37. return 8;
  38. else if (mw < 8)
  39. return 9;
  40. else if (mw < 10)
  41. return 10;
  42. else if (mw < 13)
  43. return 11;
  44. else if (mw < 16)
  45. return 12;
  46. else if (mw < 20)
  47. return 13;
  48. else if (mw < 25)
  49. return 14;
  50. else if (mw < 32)
  51. return 15;
  52. else if (mw < 40)
  53. return 16;
  54. else if (mw < 50)
  55. return 17;
  56. else if (mw < 63)
  57. return 18;
  58. else if (mw < 79)
  59. return 19;
  60. else if (mw < 100)
  61. return 20;
  62. else
  63. return 21;
  64. }
  65. /**
  66. * @brief Find the channel frequency power info with specific channel
  67. *
  68. * @param adapter A pointer to wlan_adapter structure
  69. * @param band it can be BAND_A, BAND_G or BAND_B
  70. * @param channel the channel for looking
  71. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  72. */
  73. struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
  74. u8 band, u16 channel)
  75. {
  76. struct chan_freq_power *cfp = NULL;
  77. struct region_channel *rc;
  78. int count = sizeof(adapter->region_channel) /
  79. sizeof(adapter->region_channel[0]);
  80. int i, j;
  81. for (j = 0; !cfp && (j < count); j++) {
  82. rc = &adapter->region_channel[j];
  83. if (adapter->enable11d)
  84. rc = &adapter->universal_channel[j];
  85. if (!rc->valid || !rc->CFP)
  86. continue;
  87. if (rc->band != band)
  88. continue;
  89. for (i = 0; i < rc->nrcfp; i++) {
  90. if (rc->CFP[i].channel == channel) {
  91. cfp = &rc->CFP[i];
  92. break;
  93. }
  94. }
  95. }
  96. if (!cfp && channel)
  97. lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find "
  98. "cfp by band %d & channel %d\n", band, channel);
  99. return cfp;
  100. }
  101. /**
  102. * @brief Find the channel frequency power info with specific frequency
  103. *
  104. * @param adapter A pointer to wlan_adapter structure
  105. * @param band it can be BAND_A, BAND_G or BAND_B
  106. * @param freq the frequency for looking
  107. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  108. */
  109. static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
  110. u8 band, u32 freq)
  111. {
  112. struct chan_freq_power *cfp = NULL;
  113. struct region_channel *rc;
  114. int count = sizeof(adapter->region_channel) /
  115. sizeof(adapter->region_channel[0]);
  116. int i, j;
  117. for (j = 0; !cfp && (j < count); j++) {
  118. rc = &adapter->region_channel[j];
  119. if (adapter->enable11d)
  120. rc = &adapter->universal_channel[j];
  121. if (!rc->valid || !rc->CFP)
  122. continue;
  123. if (rc->band != band)
  124. continue;
  125. for (i = 0; i < rc->nrcfp; i++) {
  126. if (rc->CFP[i].freq == freq) {
  127. cfp = &rc->CFP[i];
  128. break;
  129. }
  130. }
  131. }
  132. if (!cfp && freq)
  133. lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
  134. "band %d & freq %d\n", band, freq);
  135. return cfp;
  136. }
  137. static int updatecurrentchannel(wlan_private * priv)
  138. {
  139. int ret;
  140. /*
  141. ** the channel in f/w could be out of sync, get the current channel
  142. */
  143. ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
  144. cmd_opt_802_11_rf_channel_get,
  145. cmd_option_waitforrsp, 0, NULL);
  146. lbs_pr_debug(1, "Current channel = %d\n",
  147. priv->adapter->curbssparams.channel);
  148. return ret;
  149. }
  150. static int setcurrentchannel(wlan_private * priv, int channel)
  151. {
  152. lbs_pr_debug(1, "Set channel = %d\n", channel);
  153. /*
  154. ** Current channel is not set to adhocchannel requested, set channel
  155. */
  156. return (libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
  157. cmd_opt_802_11_rf_channel_set,
  158. cmd_option_waitforrsp, 0, &channel));
  159. }
  160. static int changeadhocchannel(wlan_private * priv, int channel)
  161. {
  162. int ret = 0;
  163. wlan_adapter *adapter = priv->adapter;
  164. adapter->adhocchannel = channel;
  165. updatecurrentchannel(priv);
  166. if (adapter->curbssparams.channel == adapter->adhocchannel) {
  167. /* adhocchannel is set to the current channel already */
  168. LEAVE();
  169. return 0;
  170. }
  171. lbs_pr_debug(1, "Updating channel from %d to %d\n",
  172. adapter->curbssparams.channel, adapter->adhocchannel);
  173. setcurrentchannel(priv, adapter->adhocchannel);
  174. updatecurrentchannel(priv);
  175. if (adapter->curbssparams.channel != adapter->adhocchannel) {
  176. lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n",
  177. adapter->adhocchannel, adapter->curbssparams.channel);
  178. LEAVE();
  179. return -1;
  180. }
  181. if (adapter->connect_status == libertas_connected) {
  182. int i;
  183. struct WLAN_802_11_SSID curadhocssid;
  184. lbs_pr_debug(1, "channel Changed while in an IBSS\n");
  185. /* Copy the current ssid */
  186. memcpy(&curadhocssid, &adapter->curbssparams.ssid,
  187. sizeof(struct WLAN_802_11_SSID));
  188. /* Exit Adhoc mode */
  189. lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
  190. ret = libertas_stop_adhoc_network(priv);
  191. if (ret) {
  192. LEAVE();
  193. return ret;
  194. }
  195. /* Scan for the network, do not save previous results. Stale
  196. * scan data will cause us to join a non-existant adhoc network
  197. */
  198. libertas_send_specific_SSID_scan(priv, &curadhocssid, 0);
  199. // find out the BSSID that matches the current SSID
  200. i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
  201. IW_MODE_ADHOC);
  202. if (i >= 0) {
  203. lbs_pr_debug(1, "SSID found at %d in List,"
  204. "so join\n", i);
  205. libertas_join_adhoc_network(priv, &adapter->scantable[i]);
  206. } else {
  207. // else send START command
  208. lbs_pr_debug(1, "SSID not found in list, "
  209. "so creating adhoc with ssid = %s\n",
  210. curadhocssid.ssid);
  211. libertas_start_adhoc_network(priv, &curadhocssid);
  212. } // end of else (START command)
  213. }
  214. LEAVE();
  215. return 0;
  216. }
  217. /**
  218. * @brief Set Radio On/OFF
  219. *
  220. * @param priv A pointer to wlan_private structure
  221. * @option Radio Option
  222. * @return 0 --success, otherwise fail
  223. */
  224. int wlan_radio_ioctl(wlan_private * priv, u8 option)
  225. {
  226. int ret = 0;
  227. wlan_adapter *adapter = priv->adapter;
  228. ENTER();
  229. if (adapter->radioon != option) {
  230. lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
  231. adapter->radioon = option;
  232. ret = libertas_prepare_and_send_command(priv,
  233. cmd_802_11_radio_control,
  234. cmd_act_set,
  235. cmd_option_waitforrsp, 0, NULL);
  236. }
  237. LEAVE();
  238. return ret;
  239. }
  240. /**
  241. * @brief Copy rates
  242. *
  243. * @param dest A pointer to Dest Buf
  244. * @param src A pointer to Src Buf
  245. * @param len The len of Src Buf
  246. * @return Number of rates copyed
  247. */
  248. static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
  249. {
  250. int i;
  251. for (i = 0; i < len && src[i]; i++, pos++) {
  252. if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
  253. break;
  254. dest[pos] = src[i];
  255. }
  256. return pos;
  257. }
  258. /**
  259. * @brief Get active data rates
  260. *
  261. * @param adapter A pointer to wlan_adapter structure
  262. * @param rate The buf to return the active rates
  263. * @return The number of rates
  264. */
  265. static int get_active_data_rates(wlan_adapter * adapter,
  266. u8* rates)
  267. {
  268. int k = 0;
  269. ENTER();
  270. if (adapter->connect_status != libertas_connected) {
  271. if (adapter->mode == IW_MODE_INFRA) {
  272. lbs_pr_debug(1, "Infra\n");
  273. k = copyrates(rates, k, libertas_supported_rates,
  274. sizeof(libertas_supported_rates));
  275. } else {
  276. lbs_pr_debug(1, "Adhoc G\n");
  277. k = copyrates(rates, k, libertas_adhoc_rates_g,
  278. sizeof(libertas_adhoc_rates_g));
  279. }
  280. } else {
  281. k = copyrates(rates, 0, adapter->curbssparams.datarates,
  282. adapter->curbssparams.numofrates);
  283. }
  284. LEAVE();
  285. return k;
  286. }
  287. static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
  288. char *cwrq, char *extra)
  289. {
  290. const char *cp;
  291. char comm[6] = { "COMM-" };
  292. char mrvl[6] = { "MRVL-" };
  293. int cnt;
  294. ENTER();
  295. strcpy(cwrq, mrvl);
  296. cp = strstr(libertas_driver_version, comm);
  297. if (cp == libertas_driver_version) //skip leading "COMM-"
  298. cp = libertas_driver_version + strlen(comm);
  299. else
  300. cp = libertas_driver_version;
  301. cnt = strlen(mrvl);
  302. cwrq += cnt;
  303. while (cnt < 16 && (*cp != '-')) {
  304. *cwrq++ = toupper(*cp++);
  305. cnt++;
  306. }
  307. *cwrq = '\0';
  308. LEAVE();
  309. return 0;
  310. }
  311. static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
  312. struct iw_freq *fwrq, char *extra)
  313. {
  314. wlan_private *priv = dev->priv;
  315. wlan_adapter *adapter = priv->adapter;
  316. struct chan_freq_power *cfp;
  317. ENTER();
  318. cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
  319. adapter->curbssparams.channel);
  320. if (!cfp) {
  321. if (adapter->curbssparams.channel)
  322. lbs_pr_debug(1, "Invalid channel=%d\n",
  323. adapter->curbssparams.channel);
  324. return -EINVAL;
  325. }
  326. fwrq->m = (long)cfp->freq * 100000;
  327. fwrq->e = 1;
  328. lbs_pr_debug(1, "freq=%u\n", fwrq->m);
  329. LEAVE();
  330. return 0;
  331. }
  332. static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
  333. struct sockaddr *awrq, char *extra)
  334. {
  335. wlan_private *priv = dev->priv;
  336. wlan_adapter *adapter = priv->adapter;
  337. ENTER();
  338. if (adapter->connect_status == libertas_connected) {
  339. memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  340. } else {
  341. memset(awrq->sa_data, 0, ETH_ALEN);
  342. }
  343. awrq->sa_family = ARPHRD_ETHER;
  344. LEAVE();
  345. return 0;
  346. }
  347. static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
  348. struct iw_point *dwrq, char *extra)
  349. {
  350. wlan_private *priv = dev->priv;
  351. wlan_adapter *adapter = priv->adapter;
  352. ENTER();
  353. /*
  354. * Check the size of the string
  355. */
  356. if (dwrq->length > 16) {
  357. return -E2BIG;
  358. }
  359. mutex_lock(&adapter->lock);
  360. memset(adapter->nodename, 0, sizeof(adapter->nodename));
  361. memcpy(adapter->nodename, extra, dwrq->length);
  362. mutex_unlock(&adapter->lock);
  363. LEAVE();
  364. return 0;
  365. }
  366. static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
  367. struct iw_point *dwrq, char *extra)
  368. {
  369. wlan_private *priv = dev->priv;
  370. wlan_adapter *adapter = priv->adapter;
  371. ENTER();
  372. /*
  373. * Get the Nick Name saved
  374. */
  375. mutex_lock(&adapter->lock);
  376. strncpy(extra, adapter->nodename, 16);
  377. mutex_unlock(&adapter->lock);
  378. extra[16] = '\0';
  379. /*
  380. * If none, we may want to get the one that was set
  381. */
  382. /*
  383. * Push it out !
  384. */
  385. dwrq->length = strlen(extra) + 1;
  386. LEAVE();
  387. return 0;
  388. }
  389. static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
  390. struct iw_param *vwrq, char *extra)
  391. {
  392. int ret = 0;
  393. wlan_private *priv = dev->priv;
  394. wlan_adapter *adapter = priv->adapter;
  395. int rthr = vwrq->value;
  396. ENTER();
  397. if (vwrq->disabled) {
  398. adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
  399. } else {
  400. if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
  401. return -EINVAL;
  402. adapter->rtsthsd = rthr;
  403. }
  404. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  405. cmd_act_set, cmd_option_waitforrsp,
  406. OID_802_11_RTS_THRESHOLD, &rthr);
  407. LEAVE();
  408. return ret;
  409. }
  410. static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
  411. struct iw_param *vwrq, char *extra)
  412. {
  413. int ret = 0;
  414. wlan_private *priv = dev->priv;
  415. wlan_adapter *adapter = priv->adapter;
  416. ENTER();
  417. adapter->rtsthsd = 0;
  418. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  419. cmd_act_get, cmd_option_waitforrsp,
  420. OID_802_11_RTS_THRESHOLD, NULL);
  421. if (ret) {
  422. LEAVE();
  423. return ret;
  424. }
  425. vwrq->value = adapter->rtsthsd;
  426. vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
  427. || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
  428. vwrq->fixed = 1;
  429. LEAVE();
  430. return 0;
  431. }
  432. static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
  433. struct iw_param *vwrq, char *extra)
  434. {
  435. int ret = 0;
  436. int fthr = vwrq->value;
  437. wlan_private *priv = dev->priv;
  438. wlan_adapter *adapter = priv->adapter;
  439. ENTER();
  440. if (vwrq->disabled) {
  441. adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
  442. } else {
  443. if (fthr < MRVDRV_FRAG_MIN_VALUE
  444. || fthr > MRVDRV_FRAG_MAX_VALUE)
  445. return -EINVAL;
  446. adapter->fragthsd = fthr;
  447. }
  448. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  449. cmd_act_set, cmd_option_waitforrsp,
  450. OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
  451. LEAVE();
  452. return ret;
  453. }
  454. static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
  455. struct iw_param *vwrq, char *extra)
  456. {
  457. int ret = 0;
  458. wlan_private *priv = dev->priv;
  459. wlan_adapter *adapter = priv->adapter;
  460. ENTER();
  461. adapter->fragthsd = 0;
  462. ret = libertas_prepare_and_send_command(priv,
  463. cmd_802_11_snmp_mib,
  464. cmd_act_get, cmd_option_waitforrsp,
  465. OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
  466. if (ret) {
  467. LEAVE();
  468. return ret;
  469. }
  470. vwrq->value = adapter->fragthsd;
  471. vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
  472. || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
  473. vwrq->fixed = 1;
  474. LEAVE();
  475. return ret;
  476. }
  477. static int wlan_get_mode(struct net_device *dev,
  478. struct iw_request_info *info, u32 * uwrq, char *extra)
  479. {
  480. wlan_private *priv = dev->priv;
  481. wlan_adapter *adapter = priv->adapter;
  482. ENTER();
  483. *uwrq = adapter->mode;
  484. LEAVE();
  485. return 0;
  486. }
  487. static int wlan_get_txpow(struct net_device *dev,
  488. struct iw_request_info *info,
  489. struct iw_param *vwrq, char *extra)
  490. {
  491. int ret = 0;
  492. wlan_private *priv = dev->priv;
  493. wlan_adapter *adapter = priv->adapter;
  494. ENTER();
  495. ret = libertas_prepare_and_send_command(priv,
  496. cmd_802_11_rf_tx_power,
  497. cmd_act_tx_power_opt_get,
  498. cmd_option_waitforrsp, 0, NULL);
  499. if (ret) {
  500. LEAVE();
  501. return ret;
  502. }
  503. lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
  504. vwrq->value = adapter->txpowerlevel;
  505. vwrq->fixed = 1;
  506. if (adapter->radioon) {
  507. vwrq->disabled = 0;
  508. vwrq->flags = IW_TXPOW_DBM;
  509. } else {
  510. vwrq->disabled = 1;
  511. }
  512. LEAVE();
  513. return 0;
  514. }
  515. static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
  516. struct iw_param *vwrq, char *extra)
  517. {
  518. int ret = 0;
  519. wlan_private *priv = dev->priv;
  520. wlan_adapter *adapter = priv->adapter;
  521. ENTER();
  522. if (vwrq->flags == IW_RETRY_LIMIT) {
  523. /* The MAC has a 4-bit Total_Tx_Count register
  524. Total_Tx_Count = 1 + Tx_Retry_Count */
  525. #define TX_RETRY_MIN 0
  526. #define TX_RETRY_MAX 14
  527. if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
  528. return -EINVAL;
  529. /* Adding 1 to convert retry count to try count */
  530. adapter->txretrycount = vwrq->value + 1;
  531. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  532. cmd_act_set,
  533. cmd_option_waitforrsp,
  534. OID_802_11_TX_RETRYCOUNT, NULL);
  535. if (ret) {
  536. LEAVE();
  537. return ret;
  538. }
  539. } else {
  540. return -EOPNOTSUPP;
  541. }
  542. LEAVE();
  543. return 0;
  544. }
  545. static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
  546. struct iw_param *vwrq, char *extra)
  547. {
  548. wlan_private *priv = dev->priv;
  549. wlan_adapter *adapter = priv->adapter;
  550. int ret = 0;
  551. ENTER();
  552. adapter->txretrycount = 0;
  553. ret = libertas_prepare_and_send_command(priv,
  554. cmd_802_11_snmp_mib,
  555. cmd_act_get, cmd_option_waitforrsp,
  556. OID_802_11_TX_RETRYCOUNT, NULL);
  557. if (ret) {
  558. LEAVE();
  559. return ret;
  560. }
  561. vwrq->disabled = 0;
  562. if (!vwrq->flags) {
  563. vwrq->flags = IW_RETRY_LIMIT;
  564. /* Subtract 1 to convert try count to retry count */
  565. vwrq->value = adapter->txretrycount - 1;
  566. }
  567. LEAVE();
  568. return 0;
  569. }
  570. static inline void sort_channels(struct iw_freq *freq, int num)
  571. {
  572. int i, j;
  573. struct iw_freq temp;
  574. for (i = 0; i < num; i++)
  575. for (j = i + 1; j < num; j++)
  576. if (freq[i].i > freq[j].i) {
  577. temp.i = freq[i].i;
  578. temp.m = freq[i].m;
  579. freq[i].i = freq[j].i;
  580. freq[i].m = freq[j].m;
  581. freq[j].i = temp.i;
  582. freq[j].m = temp.m;
  583. }
  584. }
  585. /* data rate listing
  586. MULTI_BANDS:
  587. abg a b b/g
  588. Infra G(12) A(8) B(4) G(12)
  589. Adhoc A+B(12) A(8) B(4) B(4)
  590. non-MULTI_BANDS:
  591. b b/g
  592. Infra B(4) G(12)
  593. Adhoc B(4) B(4)
  594. */
  595. /**
  596. * @brief Get Range Info
  597. *
  598. * @param dev A pointer to net_device structure
  599. * @param info A pointer to iw_request_info structure
  600. * @param vwrq A pointer to iw_param structure
  601. * @param extra A pointer to extra data buf
  602. * @return 0 --success, otherwise fail
  603. */
  604. static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
  605. struct iw_point *dwrq, char *extra)
  606. {
  607. int i, j;
  608. wlan_private *priv = dev->priv;
  609. wlan_adapter *adapter = priv->adapter;
  610. struct iw_range *range = (struct iw_range *)extra;
  611. struct chan_freq_power *cfp;
  612. u8 rates[WLAN_SUPPORTED_RATES];
  613. u8 flag = 0;
  614. ENTER();
  615. dwrq->length = sizeof(struct iw_range);
  616. memset(range, 0, sizeof(struct iw_range));
  617. range->min_nwid = 0;
  618. range->max_nwid = 0;
  619. memset(rates, 0, sizeof(rates));
  620. range->num_bitrates = get_active_data_rates(adapter, rates);
  621. for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
  622. i++) {
  623. range->bitrate[i] = (rates[i] & 0x7f) * 500000;
  624. }
  625. range->num_bitrates = i;
  626. lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
  627. range->num_bitrates);
  628. range->num_frequency = 0;
  629. if (priv->adapter->enable11d &&
  630. adapter->connect_status == libertas_connected) {
  631. u8 chan_no;
  632. u8 band;
  633. struct parsed_region_chan_11d *parsed_region_chan =
  634. &adapter->parsed_region_chan;
  635. if (parsed_region_chan == NULL) {
  636. lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
  637. LEAVE();
  638. return 0;
  639. }
  640. band = parsed_region_chan->band;
  641. lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
  642. parsed_region_chan->nr_chan);
  643. for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  644. && (i < parsed_region_chan->nr_chan); i++) {
  645. chan_no = parsed_region_chan->chanpwr[i].chan;
  646. lbs_pr_debug(1, "chan_no=%d\n", chan_no);
  647. range->freq[range->num_frequency].i = (long)chan_no;
  648. range->freq[range->num_frequency].m =
  649. (long)libertas_chan_2_freq(chan_no, band) * 100000;
  650. range->freq[range->num_frequency].e = 1;
  651. range->num_frequency++;
  652. }
  653. flag = 1;
  654. }
  655. if (!flag) {
  656. for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  657. && (j < sizeof(adapter->region_channel)
  658. / sizeof(adapter->region_channel[0])); j++) {
  659. cfp = adapter->region_channel[j].CFP;
  660. for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  661. && adapter->region_channel[j].valid
  662. && cfp
  663. && (i < adapter->region_channel[j].nrcfp); i++) {
  664. range->freq[range->num_frequency].i =
  665. (long)cfp->channel;
  666. range->freq[range->num_frequency].m =
  667. (long)cfp->freq * 100000;
  668. range->freq[range->num_frequency].e = 1;
  669. cfp++;
  670. range->num_frequency++;
  671. }
  672. }
  673. }
  674. lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
  675. IW_MAX_FREQUENCIES, range->num_frequency);
  676. range->num_channels = range->num_frequency;
  677. sort_channels(&range->freq[0], range->num_frequency);
  678. /*
  679. * Set an indication of the max TCP throughput in bit/s that we can
  680. * expect using this interface
  681. */
  682. if (i > 2)
  683. range->throughput = 5000 * 1000;
  684. else
  685. range->throughput = 1500 * 1000;
  686. range->min_rts = MRVDRV_RTS_MIN_VALUE;
  687. range->max_rts = MRVDRV_RTS_MAX_VALUE;
  688. range->min_frag = MRVDRV_FRAG_MIN_VALUE;
  689. range->max_frag = MRVDRV_FRAG_MAX_VALUE;
  690. range->encoding_size[0] = 5;
  691. range->encoding_size[1] = 13;
  692. range->num_encoding_sizes = 2;
  693. range->max_encoding_tokens = 4;
  694. range->min_pmp = 1000000;
  695. range->max_pmp = 120000000;
  696. range->min_pmt = 1000;
  697. range->max_pmt = 1000000;
  698. range->pmp_flags = IW_POWER_PERIOD;
  699. range->pmt_flags = IW_POWER_TIMEOUT;
  700. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
  701. /*
  702. * Minimum version we recommend
  703. */
  704. range->we_version_source = 15;
  705. /*
  706. * Version we are compiled with
  707. */
  708. range->we_version_compiled = WIRELESS_EXT;
  709. range->retry_capa = IW_RETRY_LIMIT;
  710. range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  711. range->min_retry = TX_RETRY_MIN;
  712. range->max_retry = TX_RETRY_MAX;
  713. /*
  714. * Set the qual, level and noise range values
  715. */
  716. range->max_qual.qual = 100;
  717. range->max_qual.level = 0;
  718. range->max_qual.noise = 0;
  719. range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  720. range->avg_qual.qual = 70;
  721. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  722. range->avg_qual.level = 0;
  723. range->avg_qual.noise = 0;
  724. range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  725. range->sensitivity = 0;
  726. /*
  727. * Setup the supported power level ranges
  728. */
  729. memset(range->txpower, 0, sizeof(range->txpower));
  730. range->txpower[0] = 5;
  731. range->txpower[1] = 7;
  732. range->txpower[2] = 9;
  733. range->txpower[3] = 11;
  734. range->txpower[4] = 13;
  735. range->txpower[5] = 15;
  736. range->txpower[6] = 17;
  737. range->txpower[7] = 19;
  738. range->num_txpower = 8;
  739. range->txpower_capa = IW_TXPOW_DBM;
  740. range->txpower_capa |= IW_TXPOW_RANGE;
  741. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  742. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  743. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  744. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  745. if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
  746. range->enc_capa = IW_ENC_CAPA_WPA
  747. | IW_ENC_CAPA_WPA2
  748. | IW_ENC_CAPA_CIPHER_TKIP
  749. | IW_ENC_CAPA_CIPHER_CCMP;
  750. }
  751. LEAVE();
  752. return 0;
  753. }
  754. static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
  755. struct iw_param *vwrq, char *extra)
  756. {
  757. wlan_private *priv = dev->priv;
  758. wlan_adapter *adapter = priv->adapter;
  759. ENTER();
  760. /* PS is currently supported only in Infrastructure mode
  761. * Remove this check if it is to be supported in IBSS mode also
  762. */
  763. if (vwrq->disabled) {
  764. adapter->psmode = wlan802_11powermodecam;
  765. if (adapter->psstate != PS_STATE_FULL_POWER) {
  766. libertas_ps_wakeup(priv, cmd_option_waitforrsp);
  767. }
  768. return 0;
  769. }
  770. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  771. lbs_pr_debug(1,
  772. "Setting power timeout command is not supported\n");
  773. return -EINVAL;
  774. } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
  775. lbs_pr_debug(1, "Setting power period command is not supported\n");
  776. return -EINVAL;
  777. }
  778. if (adapter->psmode != wlan802_11powermodecam) {
  779. return 0;
  780. }
  781. adapter->psmode = wlan802_11powermodemax_psp;
  782. if (adapter->connect_status == libertas_connected) {
  783. libertas_ps_sleep(priv, cmd_option_waitforrsp);
  784. }
  785. LEAVE();
  786. return 0;
  787. }
  788. static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
  789. struct iw_param *vwrq, char *extra)
  790. {
  791. wlan_private *priv = dev->priv;
  792. wlan_adapter *adapter = priv->adapter;
  793. int mode;
  794. ENTER();
  795. mode = adapter->psmode;
  796. if ((vwrq->disabled = (mode == wlan802_11powermodecam))
  797. || adapter->connect_status == libertas_disconnected) {
  798. LEAVE();
  799. return 0;
  800. }
  801. vwrq->value = 0;
  802. LEAVE();
  803. return 0;
  804. }
  805. /*
  806. * iwpriv settable callbacks
  807. */
  808. static const iw_handler wlan_private_handler[] = {
  809. NULL, /* SIOCIWFIRSTPRIV */
  810. };
  811. static const struct iw_priv_args wlan_private_args[] = {
  812. /*
  813. * { cmd, set_args, get_args, name }
  814. */
  815. /* Using iwpriv sub-command feature */
  816. {
  817. WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
  818. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  819. IW_PRIV_TYPE_NONE,
  820. ""},
  821. {
  822. WLANSETREGION,
  823. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  824. IW_PRIV_TYPE_NONE,
  825. "setregioncode"},
  826. {
  827. WLAN_SUBCMD_MESH_SET_TTL,
  828. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  829. IW_PRIV_TYPE_NONE,
  830. "mesh_set_ttl"},
  831. {
  832. WLAN_SETNONE_GETONEINT,
  833. IW_PRIV_TYPE_NONE,
  834. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  835. ""},
  836. {
  837. WLANGETREGION,
  838. IW_PRIV_TYPE_NONE,
  839. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  840. "getregioncode"},
  841. {
  842. WLAN_SUBCMD_FWT_CLEANUP,
  843. IW_PRIV_TYPE_NONE,
  844. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  845. "fwt_cleanup"},
  846. {
  847. WLAN_SUBCMD_FWT_TIME,
  848. IW_PRIV_TYPE_NONE,
  849. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  850. "fwt_time"},
  851. {
  852. WLAN_SUBCMD_MESH_GET_TTL,
  853. IW_PRIV_TYPE_NONE,
  854. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  855. "mesh_get_ttl"},
  856. {
  857. WLAN_SETNONE_GETNONE,
  858. IW_PRIV_TYPE_NONE,
  859. IW_PRIV_TYPE_NONE,
  860. ""},
  861. {
  862. WLAN_SUBCMD_FWT_RESET,
  863. IW_PRIV_TYPE_NONE,
  864. IW_PRIV_TYPE_NONE,
  865. "fwt_reset"},
  866. {
  867. WLAN_SUBCMD_BT_RESET,
  868. IW_PRIV_TYPE_NONE,
  869. IW_PRIV_TYPE_NONE,
  870. "bt_reset"},
  871. {
  872. WLAN_SET128CHAR_GET128CHAR,
  873. IW_PRIV_TYPE_CHAR | 128,
  874. IW_PRIV_TYPE_CHAR | 128,
  875. ""},
  876. /* BT Management */
  877. {
  878. WLAN_SUBCMD_BT_ADD,
  879. IW_PRIV_TYPE_CHAR | 128,
  880. IW_PRIV_TYPE_CHAR | 128,
  881. "bt_add"},
  882. {
  883. WLAN_SUBCMD_BT_DEL,
  884. IW_PRIV_TYPE_CHAR | 128,
  885. IW_PRIV_TYPE_CHAR | 128,
  886. "bt_del"},
  887. {
  888. WLAN_SUBCMD_BT_LIST,
  889. IW_PRIV_TYPE_CHAR | 128,
  890. IW_PRIV_TYPE_CHAR | 128,
  891. "bt_list"},
  892. /* FWT Management */
  893. {
  894. WLAN_SUBCMD_FWT_ADD,
  895. IW_PRIV_TYPE_CHAR | 128,
  896. IW_PRIV_TYPE_CHAR | 128,
  897. "fwt_add"},
  898. {
  899. WLAN_SUBCMD_FWT_DEL,
  900. IW_PRIV_TYPE_CHAR | 128,
  901. IW_PRIV_TYPE_CHAR | 128,
  902. "fwt_del"},
  903. {
  904. WLAN_SUBCMD_FWT_LOOKUP,
  905. IW_PRIV_TYPE_CHAR | 128,
  906. IW_PRIV_TYPE_CHAR | 128,
  907. "fwt_lookup"},
  908. {
  909. WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
  910. IW_PRIV_TYPE_CHAR | 128,
  911. IW_PRIV_TYPE_CHAR | 128,
  912. "fwt_list_neigh"},
  913. {
  914. WLAN_SUBCMD_FWT_LIST,
  915. IW_PRIV_TYPE_CHAR | 128,
  916. IW_PRIV_TYPE_CHAR | 128,
  917. "fwt_list"},
  918. {
  919. WLAN_SUBCMD_FWT_LIST_ROUTE,
  920. IW_PRIV_TYPE_CHAR | 128,
  921. IW_PRIV_TYPE_CHAR | 128,
  922. "fwt_list_route"},
  923. {
  924. WLAN_SET_GET_SIXTEEN_INT,
  925. IW_PRIV_TYPE_INT | 16,
  926. IW_PRIV_TYPE_INT | 16,
  927. ""},
  928. {
  929. WLAN_LED_GPIO_CTRL,
  930. IW_PRIV_TYPE_INT | 16,
  931. IW_PRIV_TYPE_INT | 16,
  932. "ledgpio"},
  933. };
  934. static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
  935. {
  936. enum {
  937. POOR = 30,
  938. FAIR = 60,
  939. GOOD = 80,
  940. VERY_GOOD = 90,
  941. EXCELLENT = 95,
  942. PERFECT = 100
  943. };
  944. wlan_private *priv = dev->priv;
  945. wlan_adapter *adapter = priv->adapter;
  946. u32 rssi_qual;
  947. u32 tx_qual;
  948. u32 quality = 0;
  949. int stats_valid = 0;
  950. u8 rssi;
  951. u32 tx_retries;
  952. ENTER();
  953. priv->wstats.status = adapter->mode;
  954. /* If we're not associated, all quality values are meaningless */
  955. if (adapter->connect_status != libertas_connected)
  956. goto out;
  957. /* Quality by RSSI */
  958. priv->wstats.qual.level =
  959. CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
  960. adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  961. if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  962. priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  963. } else {
  964. priv->wstats.qual.noise =
  965. CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  966. }
  967. lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
  968. lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
  969. rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
  970. if (rssi < 15)
  971. rssi_qual = rssi * POOR / 10;
  972. else if (rssi < 20)
  973. rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
  974. else if (rssi < 30)
  975. rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
  976. else if (rssi < 40)
  977. rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
  978. 10 + GOOD;
  979. else
  980. rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
  981. 10 + VERY_GOOD;
  982. quality = rssi_qual;
  983. /* Quality by TX errors */
  984. priv->wstats.discard.retries = priv->stats.tx_errors;
  985. tx_retries = adapter->logmsg.retry;
  986. if (tx_retries > 75)
  987. tx_qual = (90 - tx_retries) * POOR / 15;
  988. else if (tx_retries > 70)
  989. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  990. else if (tx_retries > 65)
  991. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  992. else if (tx_retries > 50)
  993. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  994. 15 + GOOD;
  995. else
  996. tx_qual = (50 - tx_retries) *
  997. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  998. quality = min(quality, tx_qual);
  999. priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
  1000. priv->wstats.discard.fragment = adapter->logmsg.fcserror;
  1001. priv->wstats.discard.retries = tx_retries;
  1002. priv->wstats.discard.misc = adapter->logmsg.ackfailure;
  1003. /* Calculate quality */
  1004. priv->wstats.qual.qual = max(quality, (u32)100);
  1005. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  1006. stats_valid = 1;
  1007. /* update stats asynchronously for future calls */
  1008. libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
  1009. 0, 0, NULL);
  1010. libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
  1011. 0, 0, NULL);
  1012. out:
  1013. if (!stats_valid) {
  1014. priv->wstats.miss.beacon = 0;
  1015. priv->wstats.discard.retries = 0;
  1016. priv->wstats.qual.qual = 0;
  1017. priv->wstats.qual.level = 0;
  1018. priv->wstats.qual.noise = 0;
  1019. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
  1020. priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
  1021. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  1022. }
  1023. LEAVE ();
  1024. return &priv->wstats;
  1025. }
  1026. static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
  1027. struct iw_freq *fwrq, char *extra)
  1028. {
  1029. int ret = 0;
  1030. wlan_private *priv = dev->priv;
  1031. wlan_adapter *adapter = priv->adapter;
  1032. int rc = -EINPROGRESS; /* Call commit handler */
  1033. struct chan_freq_power *cfp;
  1034. ENTER();
  1035. /*
  1036. * If setting by frequency, convert to a channel
  1037. */
  1038. if (fwrq->e == 1) {
  1039. long f = fwrq->m / 100000;
  1040. int c = 0;
  1041. cfp = find_cfp_by_band_and_freq(adapter, 0, f);
  1042. if (!cfp) {
  1043. lbs_pr_debug(1, "Invalid freq=%ld\n", f);
  1044. return -EINVAL;
  1045. }
  1046. c = (int)cfp->channel;
  1047. if (c < 0)
  1048. return -EINVAL;
  1049. fwrq->e = 0;
  1050. fwrq->m = c;
  1051. }
  1052. /*
  1053. * Setting by channel number
  1054. */
  1055. if (fwrq->m > 1000 || fwrq->e > 0) {
  1056. rc = -EOPNOTSUPP;
  1057. } else {
  1058. int channel = fwrq->m;
  1059. cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
  1060. if (!cfp) {
  1061. rc = -EINVAL;
  1062. } else {
  1063. if (adapter->mode == IW_MODE_ADHOC) {
  1064. rc = changeadhocchannel(priv, channel);
  1065. /* If station is WEP enabled, send the
  1066. * command to set WEP in firmware
  1067. */
  1068. if (adapter->secinfo.wep_enabled) {
  1069. lbs_pr_debug(1, "set_freq: WEP enabled\n");
  1070. ret = libertas_prepare_and_send_command(priv,
  1071. cmd_802_11_set_wep,
  1072. cmd_act_add,
  1073. cmd_option_waitforrsp,
  1074. 0,
  1075. NULL);
  1076. if (ret) {
  1077. LEAVE();
  1078. return ret;
  1079. }
  1080. adapter->currentpacketfilter |=
  1081. cmd_act_mac_wep_enable;
  1082. libertas_set_mac_packet_filter(priv);
  1083. }
  1084. } else {
  1085. rc = -EOPNOTSUPP;
  1086. }
  1087. }
  1088. }
  1089. LEAVE();
  1090. return rc;
  1091. }
  1092. /**
  1093. * @brief use index to get the data rate
  1094. *
  1095. * @param index The index of data rate
  1096. * @return data rate or 0
  1097. */
  1098. u32 libertas_index_to_data_rate(u8 index)
  1099. {
  1100. if (index >= sizeof(libertas_wlan_data_rates))
  1101. index = 0;
  1102. return libertas_wlan_data_rates[index];
  1103. }
  1104. /**
  1105. * @brief use rate to get the index
  1106. *
  1107. * @param rate data rate
  1108. * @return index or 0
  1109. */
  1110. u8 libertas_data_rate_to_index(u32 rate)
  1111. {
  1112. u8 *ptr;
  1113. if (rate)
  1114. if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
  1115. sizeof(libertas_wlan_data_rates))))
  1116. return (ptr - libertas_wlan_data_rates);
  1117. return 0;
  1118. }
  1119. static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
  1120. struct iw_param *vwrq, char *extra)
  1121. {
  1122. wlan_private *priv = dev->priv;
  1123. wlan_adapter *adapter = priv->adapter;
  1124. u32 data_rate;
  1125. u16 action;
  1126. int ret = 0;
  1127. u8 rates[WLAN_SUPPORTED_RATES];
  1128. u8 *rate;
  1129. ENTER();
  1130. lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
  1131. if (vwrq->value == -1) {
  1132. action = cmd_act_set_tx_auto; // Auto
  1133. adapter->is_datarate_auto = 1;
  1134. adapter->datarate = 0;
  1135. } else {
  1136. if (vwrq->value % 100000) {
  1137. return -EINVAL;
  1138. }
  1139. data_rate = vwrq->value / 500000;
  1140. memset(rates, 0, sizeof(rates));
  1141. get_active_data_rates(adapter, rates);
  1142. rate = rates;
  1143. while (*rate) {
  1144. lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate,
  1145. data_rate);
  1146. if ((*rate & 0x7f) == (data_rate & 0x7f))
  1147. break;
  1148. rate++;
  1149. }
  1150. if (!*rate) {
  1151. lbs_pr_alert( "The fixed data rate 0x%X is out "
  1152. "of range.\n", data_rate);
  1153. return -EINVAL;
  1154. }
  1155. adapter->datarate = data_rate;
  1156. action = cmd_act_set_tx_fix_rate;
  1157. adapter->is_datarate_auto = 0;
  1158. }
  1159. ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
  1160. action, cmd_option_waitforrsp, 0, NULL);
  1161. LEAVE();
  1162. return ret;
  1163. }
  1164. static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
  1165. struct iw_param *vwrq, char *extra)
  1166. {
  1167. wlan_private *priv = dev->priv;
  1168. wlan_adapter *adapter = priv->adapter;
  1169. ENTER();
  1170. if (adapter->is_datarate_auto) {
  1171. vwrq->fixed = 0;
  1172. } else {
  1173. vwrq->fixed = 1;
  1174. }
  1175. vwrq->value = adapter->datarate * 500000;
  1176. LEAVE();
  1177. return 0;
  1178. }
  1179. static int wlan_set_mode(struct net_device *dev,
  1180. struct iw_request_info *info, u32 * uwrq, char *extra)
  1181. {
  1182. int ret = 0;
  1183. wlan_private *priv = dev->priv;
  1184. wlan_adapter *adapter = priv->adapter;
  1185. struct assoc_request * assoc_req;
  1186. ENTER();
  1187. if ( (*uwrq != IW_MODE_ADHOC)
  1188. && (*uwrq != IW_MODE_INFRA)
  1189. && (*uwrq != IW_MODE_AUTO)) {
  1190. lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
  1191. ret = -EINVAL;
  1192. goto out;
  1193. }
  1194. mutex_lock(&adapter->lock);
  1195. assoc_req = wlan_get_association_request(adapter);
  1196. if (!assoc_req) {
  1197. ret = -ENOMEM;
  1198. wlan_cancel_association_work(priv);
  1199. } else {
  1200. assoc_req->mode = *uwrq;
  1201. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  1202. wlan_postpone_association_work(priv);
  1203. lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
  1204. }
  1205. mutex_unlock(&adapter->lock);
  1206. out:
  1207. LEAVE();
  1208. return ret;
  1209. }
  1210. /**
  1211. * @brief Get Encryption key
  1212. *
  1213. * @param dev A pointer to net_device structure
  1214. * @param info A pointer to iw_request_info structure
  1215. * @param vwrq A pointer to iw_param structure
  1216. * @param extra A pointer to extra data buf
  1217. * @return 0 --success, otherwise fail
  1218. */
  1219. static int wlan_get_encode(struct net_device *dev,
  1220. struct iw_request_info *info,
  1221. struct iw_point *dwrq, u8 * extra)
  1222. {
  1223. wlan_private *priv = dev->priv;
  1224. wlan_adapter *adapter = priv->adapter;
  1225. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  1226. ENTER();
  1227. lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
  1228. dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
  1229. dwrq->flags = 0;
  1230. /* Authentication method */
  1231. switch (adapter->secinfo.auth_mode) {
  1232. case IW_AUTH_ALG_OPEN_SYSTEM:
  1233. dwrq->flags = IW_ENCODE_OPEN;
  1234. break;
  1235. case IW_AUTH_ALG_SHARED_KEY:
  1236. case IW_AUTH_ALG_LEAP:
  1237. dwrq->flags = IW_ENCODE_RESTRICTED;
  1238. break;
  1239. default:
  1240. dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
  1241. break;
  1242. }
  1243. if ( adapter->secinfo.wep_enabled
  1244. || adapter->secinfo.WPAenabled
  1245. || adapter->secinfo.WPA2enabled) {
  1246. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1247. } else {
  1248. dwrq->flags |= IW_ENCODE_DISABLED;
  1249. }
  1250. memset(extra, 0, 16);
  1251. mutex_lock(&adapter->lock);
  1252. /* Default to returning current transmit key */
  1253. if (index < 0)
  1254. index = adapter->wep_tx_keyidx;
  1255. if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
  1256. memcpy(extra, adapter->wep_keys[index].key,
  1257. adapter->wep_keys[index].len);
  1258. dwrq->length = adapter->wep_keys[index].len;
  1259. dwrq->flags |= (index + 1);
  1260. /* Return WEP enabled */
  1261. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1262. } else if ((adapter->secinfo.WPAenabled)
  1263. || (adapter->secinfo.WPA2enabled)) {
  1264. /* return WPA enabled */
  1265. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1266. } else {
  1267. dwrq->flags |= IW_ENCODE_DISABLED;
  1268. }
  1269. mutex_unlock(&adapter->lock);
  1270. dwrq->flags |= IW_ENCODE_NOKEY;
  1271. lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
  1272. extra[0], extra[1], extra[2],
  1273. extra[3], extra[4], extra[5], dwrq->length);
  1274. lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
  1275. LEAVE();
  1276. return 0;
  1277. }
  1278. /**
  1279. * @brief Set Encryption key (internal)
  1280. *
  1281. * @param priv A pointer to private card structure
  1282. * @param key_material A pointer to key material
  1283. * @param key_length length of key material
  1284. * @param index key index to set
  1285. * @param set_tx_key Force set TX key (1 = yes, 0 = no)
  1286. * @return 0 --success, otherwise fail
  1287. */
  1288. static int wlan_set_wep_key(struct assoc_request *assoc_req,
  1289. const char *key_material,
  1290. u16 key_length,
  1291. u16 index,
  1292. int set_tx_key)
  1293. {
  1294. struct WLAN_802_11_KEY *pkey;
  1295. ENTER();
  1296. /* Paranoid validation of key index */
  1297. if (index > 3) {
  1298. LEAVE();
  1299. return -EINVAL;
  1300. }
  1301. /* validate max key length */
  1302. if (key_length > KEY_LEN_WEP_104) {
  1303. LEAVE();
  1304. return -EINVAL;
  1305. }
  1306. pkey = &assoc_req->wep_keys[index];
  1307. if (key_length > 0) {
  1308. memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
  1309. pkey->type = KEY_TYPE_ID_WEP;
  1310. /* Standardize the key length */
  1311. pkey->len = (key_length > KEY_LEN_WEP_40) ?
  1312. KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
  1313. memcpy(pkey->key, key_material, key_length);
  1314. }
  1315. if (set_tx_key) {
  1316. /* Ensure the chosen key is valid */
  1317. if (!pkey->len) {
  1318. lbs_pr_debug(1, "key not set, so cannot enable it\n");
  1319. LEAVE();
  1320. return -EINVAL;
  1321. }
  1322. assoc_req->wep_tx_keyidx = index;
  1323. }
  1324. assoc_req->secinfo.wep_enabled = 1;
  1325. LEAVE();
  1326. return 0;
  1327. }
  1328. static int validate_key_index(u16 def_index, u16 raw_index,
  1329. u16 *out_index, u16 *is_default)
  1330. {
  1331. if (!out_index || !is_default)
  1332. return -EINVAL;
  1333. /* Verify index if present, otherwise use default TX key index */
  1334. if (raw_index > 0) {
  1335. if (raw_index > 4)
  1336. return -EINVAL;
  1337. *out_index = raw_index - 1;
  1338. } else {
  1339. *out_index = def_index;
  1340. *is_default = 1;
  1341. }
  1342. return 0;
  1343. }
  1344. static void disable_wep(struct assoc_request *assoc_req)
  1345. {
  1346. int i;
  1347. /* Set Open System auth mode */
  1348. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1349. /* Clear WEP keys and mark WEP as disabled */
  1350. assoc_req->secinfo.wep_enabled = 0;
  1351. for (i = 0; i < 4; i++)
  1352. assoc_req->wep_keys[i].len = 0;
  1353. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1354. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1355. }
  1356. /**
  1357. * @brief Set Encryption key
  1358. *
  1359. * @param dev A pointer to net_device structure
  1360. * @param info A pointer to iw_request_info structure
  1361. * @param vwrq A pointer to iw_param structure
  1362. * @param extra A pointer to extra data buf
  1363. * @return 0 --success, otherwise fail
  1364. */
  1365. static int wlan_set_encode(struct net_device *dev,
  1366. struct iw_request_info *info,
  1367. struct iw_point *dwrq, char *extra)
  1368. {
  1369. int ret = 0;
  1370. wlan_private *priv = dev->priv;
  1371. wlan_adapter *adapter = priv->adapter;
  1372. struct assoc_request * assoc_req;
  1373. u16 is_default = 0, index = 0, set_tx_key = 0;
  1374. ENTER();
  1375. mutex_lock(&adapter->lock);
  1376. assoc_req = wlan_get_association_request(adapter);
  1377. if (!assoc_req) {
  1378. ret = -ENOMEM;
  1379. goto out;
  1380. }
  1381. if (dwrq->flags & IW_ENCODE_DISABLED) {
  1382. disable_wep (assoc_req);
  1383. goto out;
  1384. }
  1385. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1386. (dwrq->flags & IW_ENCODE_INDEX),
  1387. &index, &is_default);
  1388. if (ret) {
  1389. ret = -EINVAL;
  1390. goto out;
  1391. }
  1392. /* If WEP isn't enabled, or if there is no key data but a valid
  1393. * index, set the TX key.
  1394. */
  1395. if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
  1396. set_tx_key = 1;
  1397. ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
  1398. if (ret)
  1399. goto out;
  1400. if (dwrq->length)
  1401. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1402. if (set_tx_key)
  1403. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1404. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1405. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1406. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1407. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1408. }
  1409. out:
  1410. if (ret == 0) {
  1411. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1412. wlan_postpone_association_work(priv);
  1413. } else {
  1414. wlan_cancel_association_work(priv);
  1415. }
  1416. mutex_unlock(&adapter->lock);
  1417. LEAVE();
  1418. return ret;
  1419. }
  1420. /**
  1421. * @brief Get Extended Encryption key (WPA/802.1x and WEP)
  1422. *
  1423. * @param dev A pointer to net_device structure
  1424. * @param info A pointer to iw_request_info structure
  1425. * @param vwrq A pointer to iw_param structure
  1426. * @param extra A pointer to extra data buf
  1427. * @return 0 on success, otherwise failure
  1428. */
  1429. static int wlan_get_encodeext(struct net_device *dev,
  1430. struct iw_request_info *info,
  1431. struct iw_point *dwrq,
  1432. char *extra)
  1433. {
  1434. int ret = -EINVAL;
  1435. wlan_private *priv = dev->priv;
  1436. wlan_adapter *adapter = priv->adapter;
  1437. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1438. int index, max_key_len;
  1439. ENTER();
  1440. max_key_len = dwrq->length - sizeof(*ext);
  1441. if (max_key_len < 0)
  1442. goto out;
  1443. index = dwrq->flags & IW_ENCODE_INDEX;
  1444. if (index) {
  1445. if (index < 1 || index > 4)
  1446. goto out;
  1447. index--;
  1448. } else {
  1449. index = adapter->wep_tx_keyidx;
  1450. }
  1451. if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
  1452. ext->alg != IW_ENCODE_ALG_WEP) {
  1453. if (index != 0 || adapter->mode != IW_MODE_INFRA)
  1454. goto out;
  1455. }
  1456. dwrq->flags = index + 1;
  1457. memset(ext, 0, sizeof(*ext));
  1458. if ( !adapter->secinfo.wep_enabled
  1459. && !adapter->secinfo.WPAenabled
  1460. && !adapter->secinfo.WPA2enabled) {
  1461. ext->alg = IW_ENCODE_ALG_NONE;
  1462. ext->key_len = 0;
  1463. dwrq->flags |= IW_ENCODE_DISABLED;
  1464. } else {
  1465. u8 *key = NULL;
  1466. if ( adapter->secinfo.wep_enabled
  1467. && !adapter->secinfo.WPAenabled
  1468. && !adapter->secinfo.WPA2enabled) {
  1469. ext->alg = IW_ENCODE_ALG_WEP;
  1470. ext->key_len = adapter->wep_keys[index].len;
  1471. key = &adapter->wep_keys[index].key[0];
  1472. } else if ( !adapter->secinfo.wep_enabled
  1473. && (adapter->secinfo.WPAenabled ||
  1474. adapter->secinfo.WPA2enabled)) {
  1475. /* WPA */
  1476. ext->alg = IW_ENCODE_ALG_TKIP;
  1477. ext->key_len = 0;
  1478. } else {
  1479. goto out;
  1480. }
  1481. if (ext->key_len > max_key_len) {
  1482. ret = -E2BIG;
  1483. goto out;
  1484. }
  1485. if (ext->key_len)
  1486. memcpy(ext->key, key, ext->key_len);
  1487. else
  1488. dwrq->flags |= IW_ENCODE_NOKEY;
  1489. dwrq->flags |= IW_ENCODE_ENABLED;
  1490. }
  1491. ret = 0;
  1492. out:
  1493. LEAVE();
  1494. return ret;
  1495. }
  1496. /**
  1497. * @brief Set Encryption key Extended (WPA/802.1x and WEP)
  1498. *
  1499. * @param dev A pointer to net_device structure
  1500. * @param info A pointer to iw_request_info structure
  1501. * @param vwrq A pointer to iw_param structure
  1502. * @param extra A pointer to extra data buf
  1503. * @return 0 --success, otherwise fail
  1504. */
  1505. static int wlan_set_encodeext(struct net_device *dev,
  1506. struct iw_request_info *info,
  1507. struct iw_point *dwrq,
  1508. char *extra)
  1509. {
  1510. int ret = 0;
  1511. wlan_private *priv = dev->priv;
  1512. wlan_adapter *adapter = priv->adapter;
  1513. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1514. int alg = ext->alg;
  1515. struct assoc_request * assoc_req;
  1516. ENTER();
  1517. mutex_lock(&adapter->lock);
  1518. assoc_req = wlan_get_association_request(adapter);
  1519. if (!assoc_req) {
  1520. ret = -ENOMEM;
  1521. goto out;
  1522. }
  1523. if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
  1524. disable_wep (assoc_req);
  1525. } else if (alg == IW_ENCODE_ALG_WEP) {
  1526. u16 is_default = 0, index, set_tx_key = 0;
  1527. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1528. (dwrq->flags & IW_ENCODE_INDEX),
  1529. &index, &is_default);
  1530. if (ret)
  1531. goto out;
  1532. /* If WEP isn't enabled, or if there is no key data but a valid
  1533. * index, or if the set-TX-key flag was passed, set the TX key.
  1534. */
  1535. if ( !assoc_req->secinfo.wep_enabled
  1536. || (dwrq->length == 0 && !is_default)
  1537. || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
  1538. set_tx_key = 1;
  1539. /* Copy key to driver */
  1540. ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
  1541. set_tx_key);
  1542. if (ret)
  1543. goto out;
  1544. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1545. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1546. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1547. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1548. }
  1549. /* Mark the various WEP bits as modified */
  1550. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1551. if (dwrq->length)
  1552. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1553. if (set_tx_key)
  1554. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1555. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1556. struct WLAN_802_11_KEY * pkey;
  1557. /* validate key length */
  1558. if (((alg == IW_ENCODE_ALG_TKIP)
  1559. && (ext->key_len != KEY_LEN_WPA_TKIP))
  1560. || ((alg == IW_ENCODE_ALG_CCMP)
  1561. && (ext->key_len != KEY_LEN_WPA_AES))) {
  1562. lbs_pr_debug(1, "Invalid size %d for key of alg"
  1563. "type %d.\n",
  1564. ext->key_len,
  1565. alg);
  1566. ret = -EINVAL;
  1567. goto out;
  1568. }
  1569. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
  1570. pkey = &assoc_req->wpa_mcast_key;
  1571. else
  1572. pkey = &assoc_req->wpa_unicast_key;
  1573. memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
  1574. memcpy(pkey->key, ext->key, ext->key_len);
  1575. pkey->len = ext->key_len;
  1576. pkey->flags = KEY_INFO_WPA_ENABLED;
  1577. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1578. pkey->flags |= KEY_INFO_WPA_MCAST;
  1579. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1580. } else {
  1581. pkey->flags |= KEY_INFO_WPA_UNICAST;
  1582. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1583. }
  1584. if (alg == IW_ENCODE_ALG_TKIP)
  1585. pkey->type = KEY_TYPE_ID_TKIP;
  1586. else if (alg == IW_ENCODE_ALG_CCMP)
  1587. pkey->type = KEY_TYPE_ID_AES;
  1588. /* If WPA isn't enabled yet, do that now */
  1589. if ( assoc_req->secinfo.WPAenabled == 0
  1590. && assoc_req->secinfo.WPA2enabled == 0) {
  1591. assoc_req->secinfo.WPAenabled = 1;
  1592. assoc_req->secinfo.WPA2enabled = 1;
  1593. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1594. }
  1595. disable_wep (assoc_req);
  1596. }
  1597. out:
  1598. if (ret == 0) {
  1599. wlan_postpone_association_work(priv);
  1600. } else {
  1601. wlan_cancel_association_work(priv);
  1602. }
  1603. mutex_unlock(&adapter->lock);
  1604. LEAVE();
  1605. return ret;
  1606. }
  1607. static int wlan_set_genie(struct net_device *dev,
  1608. struct iw_request_info *info,
  1609. struct iw_point *dwrq,
  1610. char *extra)
  1611. {
  1612. wlan_private *priv = dev->priv;
  1613. wlan_adapter *adapter = priv->adapter;
  1614. int ret = 0;
  1615. struct assoc_request * assoc_req;
  1616. ENTER();
  1617. mutex_lock(&adapter->lock);
  1618. assoc_req = wlan_get_association_request(adapter);
  1619. if (!assoc_req) {
  1620. ret = -ENOMEM;
  1621. goto out;
  1622. }
  1623. if (dwrq->length > MAX_WPA_IE_LEN ||
  1624. (dwrq->length && extra == NULL)) {
  1625. ret = -EINVAL;
  1626. goto out;
  1627. }
  1628. if (dwrq->length) {
  1629. memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
  1630. assoc_req->wpa_ie_len = dwrq->length;
  1631. } else {
  1632. memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
  1633. assoc_req->wpa_ie_len = 0;
  1634. }
  1635. out:
  1636. if (ret == 0) {
  1637. set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
  1638. wlan_postpone_association_work(priv);
  1639. } else {
  1640. wlan_cancel_association_work(priv);
  1641. }
  1642. mutex_unlock(&adapter->lock);
  1643. LEAVE();
  1644. return ret;
  1645. }
  1646. static int wlan_get_genie(struct net_device *dev,
  1647. struct iw_request_info *info,
  1648. struct iw_point *dwrq,
  1649. char *extra)
  1650. {
  1651. wlan_private *priv = dev->priv;
  1652. wlan_adapter *adapter = priv->adapter;
  1653. ENTER();
  1654. if (adapter->wpa_ie_len == 0) {
  1655. dwrq->length = 0;
  1656. LEAVE();
  1657. return 0;
  1658. }
  1659. if (dwrq->length < adapter->wpa_ie_len) {
  1660. LEAVE();
  1661. return -E2BIG;
  1662. }
  1663. dwrq->length = adapter->wpa_ie_len;
  1664. memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
  1665. LEAVE();
  1666. return 0;
  1667. }
  1668. static int wlan_set_auth(struct net_device *dev,
  1669. struct iw_request_info *info,
  1670. struct iw_param *dwrq,
  1671. char *extra)
  1672. {
  1673. wlan_private *priv = dev->priv;
  1674. wlan_adapter *adapter = priv->adapter;
  1675. struct assoc_request * assoc_req;
  1676. int ret = 0;
  1677. int updated = 0;
  1678. ENTER();
  1679. mutex_lock(&adapter->lock);
  1680. assoc_req = wlan_get_association_request(adapter);
  1681. if (!assoc_req) {
  1682. ret = -ENOMEM;
  1683. goto out;
  1684. }
  1685. switch (dwrq->flags & IW_AUTH_INDEX) {
  1686. case IW_AUTH_TKIP_COUNTERMEASURES:
  1687. case IW_AUTH_CIPHER_PAIRWISE:
  1688. case IW_AUTH_CIPHER_GROUP:
  1689. case IW_AUTH_KEY_MGMT:
  1690. /*
  1691. * libertas does not use these parameters
  1692. */
  1693. break;
  1694. case IW_AUTH_WPA_VERSION:
  1695. if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
  1696. assoc_req->secinfo.WPAenabled = 0;
  1697. assoc_req->secinfo.WPA2enabled = 0;
  1698. }
  1699. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
  1700. assoc_req->secinfo.WPAenabled = 1;
  1701. assoc_req->secinfo.wep_enabled = 0;
  1702. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1703. }
  1704. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
  1705. assoc_req->secinfo.WPA2enabled = 1;
  1706. assoc_req->secinfo.wep_enabled = 0;
  1707. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1708. }
  1709. updated = 1;
  1710. break;
  1711. case IW_AUTH_DROP_UNENCRYPTED:
  1712. if (dwrq->value) {
  1713. adapter->currentpacketfilter |=
  1714. cmd_act_mac_strict_protection_enable;
  1715. } else {
  1716. adapter->currentpacketfilter &=
  1717. ~cmd_act_mac_strict_protection_enable;
  1718. }
  1719. updated = 1;
  1720. break;
  1721. case IW_AUTH_80211_AUTH_ALG:
  1722. if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
  1723. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1724. } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  1725. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1726. } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
  1727. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
  1728. } else {
  1729. ret = -EINVAL;
  1730. }
  1731. updated = 1;
  1732. break;
  1733. case IW_AUTH_WPA_ENABLED:
  1734. if (dwrq->value) {
  1735. if (!assoc_req->secinfo.WPAenabled &&
  1736. !assoc_req->secinfo.WPA2enabled) {
  1737. assoc_req->secinfo.WPAenabled = 1;
  1738. assoc_req->secinfo.WPA2enabled = 1;
  1739. assoc_req->secinfo.wep_enabled = 0;
  1740. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1741. }
  1742. } else {
  1743. assoc_req->secinfo.WPAenabled = 0;
  1744. assoc_req->secinfo.WPA2enabled = 0;
  1745. }
  1746. updated = 1;
  1747. break;
  1748. default:
  1749. ret = -EOPNOTSUPP;
  1750. break;
  1751. }
  1752. out:
  1753. if (ret == 0) {
  1754. if (updated)
  1755. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1756. wlan_postpone_association_work(priv);
  1757. } else if (ret != -EOPNOTSUPP) {
  1758. wlan_cancel_association_work(priv);
  1759. }
  1760. mutex_unlock(&adapter->lock);
  1761. LEAVE();
  1762. return ret;
  1763. }
  1764. static int wlan_get_auth(struct net_device *dev,
  1765. struct iw_request_info *info,
  1766. struct iw_param *dwrq,
  1767. char *extra)
  1768. {
  1769. wlan_private *priv = dev->priv;
  1770. wlan_adapter *adapter = priv->adapter;
  1771. ENTER();
  1772. switch (dwrq->flags & IW_AUTH_INDEX) {
  1773. case IW_AUTH_WPA_VERSION:
  1774. dwrq->value = 0;
  1775. if (adapter->secinfo.WPAenabled)
  1776. dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
  1777. if (adapter->secinfo.WPA2enabled)
  1778. dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
  1779. if (!dwrq->value)
  1780. dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
  1781. break;
  1782. case IW_AUTH_DROP_UNENCRYPTED:
  1783. dwrq->value = 0;
  1784. if (adapter->currentpacketfilter &
  1785. cmd_act_mac_strict_protection_enable)
  1786. dwrq->value = 1;
  1787. break;
  1788. case IW_AUTH_80211_AUTH_ALG:
  1789. dwrq->value = adapter->secinfo.auth_mode;
  1790. break;
  1791. case IW_AUTH_WPA_ENABLED:
  1792. if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
  1793. dwrq->value = 1;
  1794. break;
  1795. default:
  1796. LEAVE();
  1797. return -EOPNOTSUPP;
  1798. }
  1799. LEAVE();
  1800. return 0;
  1801. }
  1802. static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
  1803. struct iw_param *vwrq, char *extra)
  1804. {
  1805. int ret = 0;
  1806. wlan_private *priv = dev->priv;
  1807. wlan_adapter *adapter = priv->adapter;
  1808. u16 dbm;
  1809. ENTER();
  1810. if (vwrq->disabled) {
  1811. wlan_radio_ioctl(priv, RADIO_OFF);
  1812. return 0;
  1813. }
  1814. adapter->preamble = cmd_type_auto_preamble;
  1815. wlan_radio_ioctl(priv, RADIO_ON);
  1816. if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
  1817. dbm = (u16) mw_to_dbm(vwrq->value);
  1818. } else
  1819. dbm = (u16) vwrq->value;
  1820. /* auto tx power control */
  1821. if (vwrq->fixed == 0)
  1822. dbm = 0xffff;
  1823. lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
  1824. ret = libertas_prepare_and_send_command(priv,
  1825. cmd_802_11_rf_tx_power,
  1826. cmd_act_tx_power_opt_set_low,
  1827. cmd_option_waitforrsp, 0, (void *)&dbm);
  1828. LEAVE();
  1829. return ret;
  1830. }
  1831. static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
  1832. struct iw_point *dwrq, char *extra)
  1833. {
  1834. wlan_private *priv = dev->priv;
  1835. wlan_adapter *adapter = priv->adapter;
  1836. ENTER();
  1837. /*
  1838. * Note : if dwrq->flags != 0, we should get the relevant SSID from
  1839. * the SSID list...
  1840. */
  1841. /*
  1842. * Get the current SSID
  1843. */
  1844. if (adapter->connect_status == libertas_connected) {
  1845. memcpy(extra, adapter->curbssparams.ssid.ssid,
  1846. adapter->curbssparams.ssid.ssidlength);
  1847. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  1848. } else {
  1849. memset(extra, 0, 32);
  1850. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  1851. }
  1852. /*
  1853. * If none, we may want to get the one that was set
  1854. */
  1855. /* To make the driver backward compatible with WPA supplicant v0.2.4 */
  1856. if (dwrq->length == 32) /* check with WPA supplicant buffer size */
  1857. dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
  1858. IW_ESSID_MAX_SIZE);
  1859. else
  1860. dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
  1861. dwrq->flags = 1; /* active */
  1862. LEAVE();
  1863. return 0;
  1864. }
  1865. static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
  1866. struct iw_point *dwrq, char *extra)
  1867. {
  1868. wlan_private *priv = dev->priv;
  1869. wlan_adapter *adapter = priv->adapter;
  1870. int ret = 0;
  1871. struct WLAN_802_11_SSID ssid;
  1872. struct assoc_request * assoc_req;
  1873. int ssid_len = dwrq->length;
  1874. ENTER();
  1875. /*
  1876. * WE-20 and earlier NULL pad the end of the SSID and increment
  1877. * SSID length so it can be used like a string. WE-21 and later don't,
  1878. * but some userspace tools aren't able to cope with the change.
  1879. */
  1880. if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
  1881. ssid_len--;
  1882. /* Check the size of the string */
  1883. if (ssid_len > IW_ESSID_MAX_SIZE) {
  1884. ret = -E2BIG;
  1885. goto out;
  1886. }
  1887. memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
  1888. if (!dwrq->flags || !ssid_len) {
  1889. /* "any" SSID requested; leave SSID blank */
  1890. } else {
  1891. /* Specific SSID requested */
  1892. memcpy(&ssid.ssid, extra, ssid_len);
  1893. ssid.ssidlength = ssid_len;
  1894. }
  1895. lbs_pr_debug(1, "Requested new SSID = %s\n",
  1896. (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
  1897. out:
  1898. mutex_lock(&adapter->lock);
  1899. if (ret == 0) {
  1900. /* Get or create the current association request */
  1901. assoc_req = wlan_get_association_request(adapter);
  1902. if (!assoc_req) {
  1903. ret = -ENOMEM;
  1904. } else {
  1905. /* Copy the SSID to the association request */
  1906. memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
  1907. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  1908. wlan_postpone_association_work(priv);
  1909. }
  1910. }
  1911. /* Cancel the association request if there was an error */
  1912. if (ret != 0) {
  1913. wlan_cancel_association_work(priv);
  1914. }
  1915. mutex_unlock(&adapter->lock);
  1916. LEAVE();
  1917. return ret;
  1918. }
  1919. /**
  1920. * @brief Connect to the AP or Ad-hoc Network with specific bssid
  1921. *
  1922. * @param dev A pointer to net_device structure
  1923. * @param info A pointer to iw_request_info structure
  1924. * @param awrq A pointer to iw_param structure
  1925. * @param extra A pointer to extra data buf
  1926. * @return 0 --success, otherwise fail
  1927. */
  1928. static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
  1929. struct sockaddr *awrq, char *extra)
  1930. {
  1931. wlan_private *priv = dev->priv;
  1932. wlan_adapter *adapter = priv->adapter;
  1933. struct assoc_request * assoc_req;
  1934. int ret = 0;
  1935. ENTER();
  1936. if (awrq->sa_family != ARPHRD_ETHER)
  1937. return -EINVAL;
  1938. lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
  1939. mutex_lock(&adapter->lock);
  1940. /* Get or create the current association request */
  1941. assoc_req = wlan_get_association_request(adapter);
  1942. if (!assoc_req) {
  1943. wlan_cancel_association_work(priv);
  1944. ret = -ENOMEM;
  1945. } else {
  1946. /* Copy the BSSID to the association request */
  1947. memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
  1948. set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
  1949. wlan_postpone_association_work(priv);
  1950. }
  1951. mutex_unlock(&adapter->lock);
  1952. return ret;
  1953. }
  1954. void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
  1955. {
  1956. union {
  1957. u32 l;
  1958. u8 c[4];
  1959. } ver;
  1960. char fwver[32];
  1961. mutex_lock(&adapter->lock);
  1962. ver.l = adapter->fwreleasenumber;
  1963. mutex_unlock(&adapter->lock);
  1964. if (ver.c[3] == 0)
  1965. sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
  1966. else
  1967. sprintf(fwver, "%u.%u.%u.p%u",
  1968. ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1969. snprintf(fwversion, maxlen, fwver);
  1970. }
  1971. /*
  1972. * iwconfig settable callbacks
  1973. */
  1974. static const iw_handler wlan_handler[] = {
  1975. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1976. (iw_handler) wlan_get_name, /* SIOCGIWNAME */
  1977. (iw_handler) NULL, /* SIOCSIWNWID */
  1978. (iw_handler) NULL, /* SIOCGIWNWID */
  1979. (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
  1980. (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
  1981. (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
  1982. (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
  1983. (iw_handler) NULL, /* SIOCSIWSENS */
  1984. (iw_handler) NULL, /* SIOCGIWSENS */
  1985. (iw_handler) NULL, /* SIOCSIWRANGE */
  1986. (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
  1987. (iw_handler) NULL, /* SIOCSIWPRIV */
  1988. (iw_handler) NULL, /* SIOCGIWPRIV */
  1989. (iw_handler) NULL, /* SIOCSIWSTATS */
  1990. (iw_handler) NULL, /* SIOCGIWSTATS */
  1991. iw_handler_set_spy, /* SIOCSIWSPY */
  1992. iw_handler_get_spy, /* SIOCGIWSPY */
  1993. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1994. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1995. (iw_handler) wlan_set_wap, /* SIOCSIWAP */
  1996. (iw_handler) wlan_get_wap, /* SIOCGIWAP */
  1997. (iw_handler) NULL, /* SIOCSIWMLME */
  1998. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1999. (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
  2000. (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
  2001. (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
  2002. (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
  2003. (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
  2004. (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
  2005. (iw_handler) NULL, /* -- hole -- */
  2006. (iw_handler) NULL, /* -- hole -- */
  2007. (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
  2008. (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
  2009. (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
  2010. (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
  2011. (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
  2012. (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
  2013. (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
  2014. (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
  2015. (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
  2016. (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
  2017. (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
  2018. (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
  2019. (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
  2020. (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
  2021. (iw_handler) NULL, /* -- hole -- */
  2022. (iw_handler) NULL, /* -- hole -- */
  2023. (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
  2024. (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
  2025. (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
  2026. (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
  2027. (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
  2028. (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
  2029. (iw_handler) NULL, /* SIOCSIWPMKSA */
  2030. };
  2031. struct iw_handler_def libertas_handler_def = {
  2032. .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
  2033. .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
  2034. .num_private_args = sizeof(wlan_private_args) /
  2035. sizeof(struct iw_priv_args),
  2036. .standard = (iw_handler *) wlan_handler,
  2037. .private = (iw_handler *) wlan_private_handler,
  2038. .private_args = (struct iw_priv_args *)wlan_private_args,
  2039. .get_wireless_stats = wlan_get_wireless_stats,
  2040. };