wext.c 59 KB

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