wext.c 64 KB

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