wext.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757
  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. WLANSETENCRYPTIONMODE,
  907. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  908. IW_PRIV_TYPE_NONE,
  909. "encryptionmode",
  910. },
  911. {
  912. WLANSETREGION,
  913. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  914. IW_PRIV_TYPE_NONE,
  915. "setregioncode"},
  916. {
  917. WLAN_SET_LISTEN_INTERVAL,
  918. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  919. IW_PRIV_TYPE_NONE,
  920. "setlisteninter"},
  921. {
  922. WLAN_SET_MULTIPLE_DTIM,
  923. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  924. IW_PRIV_TYPE_NONE,
  925. "setmultipledtim"},
  926. {
  927. WLAN_SET_ATIM_WINDOW,
  928. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  929. IW_PRIV_TYPE_NONE,
  930. "atimwindow"},
  931. {
  932. WLANSETBCNAVG,
  933. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  934. IW_PRIV_TYPE_NONE,
  935. "setbcnavg"},
  936. {
  937. WLANSETDATAAVG,
  938. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  939. IW_PRIV_TYPE_NONE,
  940. "setdataavg"},
  941. {
  942. WLAN_SET_LINKMODE,
  943. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  944. IW_PRIV_TYPE_NONE,
  945. "linkmode"},
  946. {
  947. WLAN_SET_RADIOMODE,
  948. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  949. IW_PRIV_TYPE_NONE,
  950. "radiomode"},
  951. {
  952. WLAN_SET_DEBUGMODE,
  953. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  954. IW_PRIV_TYPE_NONE,
  955. "debugmode"},
  956. {
  957. WLAN_SUBCMD_MESH_SET_TTL,
  958. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  959. IW_PRIV_TYPE_NONE,
  960. "mesh_set_ttl"},
  961. {
  962. WLAN_SETNONE_GETONEINT,
  963. IW_PRIV_TYPE_NONE,
  964. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  965. ""},
  966. {
  967. WLANGETREGION,
  968. IW_PRIV_TYPE_NONE,
  969. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  970. "getregioncode"},
  971. {
  972. WLAN_GET_LISTEN_INTERVAL,
  973. IW_PRIV_TYPE_NONE,
  974. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  975. "getlisteninter"},
  976. {
  977. WLAN_GET_MULTIPLE_DTIM,
  978. IW_PRIV_TYPE_NONE,
  979. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  980. "getmultipledtim"},
  981. {
  982. WLAN_GET_TX_RATE,
  983. IW_PRIV_TYPE_NONE,
  984. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  985. "gettxrate"},
  986. {
  987. WLANGETBCNAVG,
  988. IW_PRIV_TYPE_NONE,
  989. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  990. "getbcnavg"},
  991. {
  992. WLAN_GET_LINKMODE,
  993. IW_PRIV_TYPE_NONE,
  994. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  995. "get_linkmode"},
  996. {
  997. WLAN_GET_RADIOMODE,
  998. IW_PRIV_TYPE_NONE,
  999. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1000. "get_radiomode"},
  1001. {
  1002. WLAN_GET_DEBUGMODE,
  1003. IW_PRIV_TYPE_NONE,
  1004. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1005. "get_debugmode"},
  1006. {
  1007. WLAN_SUBCMD_FWT_CLEANUP,
  1008. IW_PRIV_TYPE_NONE,
  1009. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1010. "fwt_cleanup"},
  1011. {
  1012. WLAN_SUBCMD_FWT_TIME,
  1013. IW_PRIV_TYPE_NONE,
  1014. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1015. "fwt_time"},
  1016. {
  1017. WLAN_SUBCMD_MESH_GET_TTL,
  1018. IW_PRIV_TYPE_NONE,
  1019. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1020. "mesh_get_ttl"},
  1021. {
  1022. WLAN_SETNONE_GETTWELVE_CHAR,
  1023. IW_PRIV_TYPE_NONE,
  1024. IW_PRIV_TYPE_CHAR | 12,
  1025. ""},
  1026. {
  1027. WLAN_SUBCMD_GETRXANTENNA,
  1028. IW_PRIV_TYPE_NONE,
  1029. IW_PRIV_TYPE_CHAR | 12,
  1030. "getrxant"},
  1031. {
  1032. WLAN_SUBCMD_GETTXANTENNA,
  1033. IW_PRIV_TYPE_NONE,
  1034. IW_PRIV_TYPE_CHAR | 12,
  1035. "gettxant"},
  1036. {
  1037. WLAN_GET_TSF,
  1038. IW_PRIV_TYPE_NONE,
  1039. IW_PRIV_TYPE_CHAR | 12,
  1040. "gettsf"},
  1041. {
  1042. WLAN_SETNONE_GETNONE,
  1043. IW_PRIV_TYPE_NONE,
  1044. IW_PRIV_TYPE_NONE,
  1045. ""},
  1046. {
  1047. WLANDEAUTH,
  1048. IW_PRIV_TYPE_NONE,
  1049. IW_PRIV_TYPE_NONE,
  1050. "deauth"},
  1051. {
  1052. WLANADHOCSTOP,
  1053. IW_PRIV_TYPE_NONE,
  1054. IW_PRIV_TYPE_NONE,
  1055. "adhocstop"},
  1056. {
  1057. WLANRADIOON,
  1058. IW_PRIV_TYPE_NONE,
  1059. IW_PRIV_TYPE_NONE,
  1060. "radioon"},
  1061. {
  1062. WLANRADIOOFF,
  1063. IW_PRIV_TYPE_NONE,
  1064. IW_PRIV_TYPE_NONE,
  1065. "radiooff"},
  1066. {
  1067. WLANWLANIDLEON,
  1068. IW_PRIV_TYPE_NONE,
  1069. IW_PRIV_TYPE_NONE,
  1070. "wlanidle-on"},
  1071. {
  1072. WLANWLANIDLEOFF,
  1073. IW_PRIV_TYPE_NONE,
  1074. IW_PRIV_TYPE_NONE,
  1075. "wlanidle-off"},
  1076. {
  1077. WLAN_SUBCMD_FWT_RESET,
  1078. IW_PRIV_TYPE_NONE,
  1079. IW_PRIV_TYPE_NONE,
  1080. "fwt_reset"},
  1081. {
  1082. WLAN_SUBCMD_BT_RESET,
  1083. IW_PRIV_TYPE_NONE,
  1084. IW_PRIV_TYPE_NONE,
  1085. "bt_reset"},
  1086. {
  1087. WLAN_SET128CHAR_GET128CHAR,
  1088. IW_PRIV_TYPE_CHAR | 128,
  1089. IW_PRIV_TYPE_CHAR | 128,
  1090. ""},
  1091. /* BT Management */
  1092. {
  1093. WLAN_SUBCMD_BT_ADD,
  1094. IW_PRIV_TYPE_CHAR | 128,
  1095. IW_PRIV_TYPE_CHAR | 128,
  1096. "bt_add"},
  1097. {
  1098. WLAN_SUBCMD_BT_DEL,
  1099. IW_PRIV_TYPE_CHAR | 128,
  1100. IW_PRIV_TYPE_CHAR | 128,
  1101. "bt_del"},
  1102. {
  1103. WLAN_SUBCMD_BT_LIST,
  1104. IW_PRIV_TYPE_CHAR | 128,
  1105. IW_PRIV_TYPE_CHAR | 128,
  1106. "bt_list"},
  1107. /* FWT Management */
  1108. {
  1109. WLAN_SUBCMD_FWT_ADD,
  1110. IW_PRIV_TYPE_CHAR | 128,
  1111. IW_PRIV_TYPE_CHAR | 128,
  1112. "fwt_add"},
  1113. {
  1114. WLAN_SUBCMD_FWT_DEL,
  1115. IW_PRIV_TYPE_CHAR | 128,
  1116. IW_PRIV_TYPE_CHAR | 128,
  1117. "fwt_del"},
  1118. {
  1119. WLAN_SUBCMD_FWT_LOOKUP,
  1120. IW_PRIV_TYPE_CHAR | 128,
  1121. IW_PRIV_TYPE_CHAR | 128,
  1122. "fwt_lookup"},
  1123. {
  1124. WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
  1125. IW_PRIV_TYPE_CHAR | 128,
  1126. IW_PRIV_TYPE_CHAR | 128,
  1127. "fwt_list_neigh"},
  1128. {
  1129. WLAN_SUBCMD_FWT_LIST,
  1130. IW_PRIV_TYPE_CHAR | 128,
  1131. IW_PRIV_TYPE_CHAR | 128,
  1132. "fwt_list"},
  1133. {
  1134. WLAN_SUBCMD_FWT_LIST_ROUTE,
  1135. IW_PRIV_TYPE_CHAR | 128,
  1136. IW_PRIV_TYPE_CHAR | 128,
  1137. "fwt_list_route"},
  1138. {
  1139. WLANSCAN_MODE,
  1140. IW_PRIV_TYPE_CHAR | 128,
  1141. IW_PRIV_TYPE_CHAR | 128,
  1142. "scanmode"},
  1143. {
  1144. WLAN_GET_ADHOC_STATUS,
  1145. IW_PRIV_TYPE_CHAR | 128,
  1146. IW_PRIV_TYPE_CHAR | 128,
  1147. "getadhocstatus"},
  1148. {
  1149. WLAN_SETNONE_GETWORDCHAR,
  1150. IW_PRIV_TYPE_NONE,
  1151. IW_PRIV_TYPE_CHAR | 128,
  1152. ""},
  1153. {
  1154. WLANSETWPAIE,
  1155. IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 24,
  1156. IW_PRIV_TYPE_NONE,
  1157. "setwpaie"},
  1158. {
  1159. WLANGETLOG,
  1160. IW_PRIV_TYPE_NONE,
  1161. IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE,
  1162. "getlog"},
  1163. {
  1164. WLAN_SET_GET_SIXTEEN_INT,
  1165. IW_PRIV_TYPE_INT | 16,
  1166. IW_PRIV_TYPE_INT | 16,
  1167. ""},
  1168. {
  1169. WLAN_TPCCFG,
  1170. IW_PRIV_TYPE_INT | 16,
  1171. IW_PRIV_TYPE_INT | 16,
  1172. "tpccfg"},
  1173. {
  1174. WLAN_POWERCFG,
  1175. IW_PRIV_TYPE_INT | 16,
  1176. IW_PRIV_TYPE_INT | 16,
  1177. "powercfg"},
  1178. {
  1179. WLAN_AUTO_FREQ_SET,
  1180. IW_PRIV_TYPE_INT | 16,
  1181. IW_PRIV_TYPE_INT | 16,
  1182. "setafc"},
  1183. {
  1184. WLAN_AUTO_FREQ_GET,
  1185. IW_PRIV_TYPE_INT | 16,
  1186. IW_PRIV_TYPE_INT | 16,
  1187. "getafc"},
  1188. {
  1189. WLAN_SCANPROBES,
  1190. IW_PRIV_TYPE_INT | 16,
  1191. IW_PRIV_TYPE_INT | 16,
  1192. "scanprobes"},
  1193. {
  1194. WLAN_LED_GPIO_CTRL,
  1195. IW_PRIV_TYPE_INT | 16,
  1196. IW_PRIV_TYPE_INT | 16,
  1197. "ledgpio"},
  1198. {
  1199. WLAN_ADAPT_RATESET,
  1200. IW_PRIV_TYPE_INT | 16,
  1201. IW_PRIV_TYPE_INT | 16,
  1202. "rateadapt"},
  1203. {
  1204. WLAN_INACTIVITY_TIMEOUT,
  1205. IW_PRIV_TYPE_INT | 16,
  1206. IW_PRIV_TYPE_INT | 16,
  1207. "inactivityto"},
  1208. {
  1209. WLANSNR,
  1210. IW_PRIV_TYPE_INT | 16,
  1211. IW_PRIV_TYPE_INT | 16,
  1212. "getSNR"},
  1213. {
  1214. WLAN_GET_RATE,
  1215. IW_PRIV_TYPE_INT | 16,
  1216. IW_PRIV_TYPE_INT | 16,
  1217. "getrate"},
  1218. {
  1219. WLAN_GET_RXINFO,
  1220. IW_PRIV_TYPE_INT | 16,
  1221. IW_PRIV_TYPE_INT | 16,
  1222. "getrxinfo"},
  1223. };
  1224. static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
  1225. {
  1226. enum {
  1227. POOR = 30,
  1228. FAIR = 60,
  1229. GOOD = 80,
  1230. VERY_GOOD = 90,
  1231. EXCELLENT = 95,
  1232. PERFECT = 100
  1233. };
  1234. wlan_private *priv = dev->priv;
  1235. wlan_adapter *adapter = priv->adapter;
  1236. u32 rssi_qual;
  1237. u32 tx_qual;
  1238. u32 quality = 0;
  1239. int stats_valid = 0;
  1240. u8 rssi;
  1241. u32 tx_retries;
  1242. ENTER();
  1243. priv->wstats.status = adapter->inframode;
  1244. /* If we're not associated, all quality values are meaningless */
  1245. if (adapter->connect_status != libertas_connected)
  1246. goto out;
  1247. /* Quality by RSSI */
  1248. priv->wstats.qual.level =
  1249. CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
  1250. adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  1251. if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  1252. priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  1253. } else {
  1254. priv->wstats.qual.noise =
  1255. CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  1256. }
  1257. lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
  1258. lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
  1259. rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
  1260. if (rssi < 15)
  1261. rssi_qual = rssi * POOR / 10;
  1262. else if (rssi < 20)
  1263. rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
  1264. else if (rssi < 30)
  1265. rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
  1266. else if (rssi < 40)
  1267. rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
  1268. 10 + GOOD;
  1269. else
  1270. rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
  1271. 10 + VERY_GOOD;
  1272. quality = rssi_qual;
  1273. /* Quality by TX errors */
  1274. priv->wstats.discard.retries = priv->stats.tx_errors;
  1275. tx_retries = adapter->logmsg.retry;
  1276. if (tx_retries > 75)
  1277. tx_qual = (90 - tx_retries) * POOR / 15;
  1278. else if (tx_retries > 70)
  1279. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  1280. else if (tx_retries > 65)
  1281. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  1282. else if (tx_retries > 50)
  1283. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  1284. 15 + GOOD;
  1285. else
  1286. tx_qual = (50 - tx_retries) *
  1287. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  1288. quality = min(quality, tx_qual);
  1289. priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
  1290. priv->wstats.discard.fragment = adapter->logmsg.fcserror;
  1291. priv->wstats.discard.retries = tx_retries;
  1292. priv->wstats.discard.misc = adapter->logmsg.ackfailure;
  1293. /* Calculate quality */
  1294. priv->wstats.qual.qual = max(quality, (u32)100);
  1295. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  1296. stats_valid = 1;
  1297. /* update stats asynchronously for future calls */
  1298. libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
  1299. 0, 0, NULL);
  1300. libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
  1301. 0, 0, NULL);
  1302. out:
  1303. if (!stats_valid) {
  1304. priv->wstats.miss.beacon = 0;
  1305. priv->wstats.discard.retries = 0;
  1306. priv->wstats.qual.qual = 0;
  1307. priv->wstats.qual.level = 0;
  1308. priv->wstats.qual.noise = 0;
  1309. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
  1310. priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
  1311. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  1312. }
  1313. LEAVE ();
  1314. return &priv->wstats;
  1315. }
  1316. static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
  1317. struct iw_freq *fwrq, char *extra)
  1318. {
  1319. int ret = 0;
  1320. wlan_private *priv = dev->priv;
  1321. wlan_adapter *adapter = priv->adapter;
  1322. int rc = -EINPROGRESS; /* Call commit handler */
  1323. struct chan_freq_power *cfp;
  1324. ENTER();
  1325. /*
  1326. * If setting by frequency, convert to a channel
  1327. */
  1328. if (fwrq->e == 1) {
  1329. long f = fwrq->m / 100000;
  1330. int c = 0;
  1331. cfp = find_cfp_by_band_and_freq(adapter, 0, f);
  1332. if (!cfp) {
  1333. lbs_pr_debug(1, "Invalid freq=%ld\n", f);
  1334. return -EINVAL;
  1335. }
  1336. c = (int)cfp->channel;
  1337. if (c < 0)
  1338. return -EINVAL;
  1339. fwrq->e = 0;
  1340. fwrq->m = c;
  1341. }
  1342. /*
  1343. * Setting by channel number
  1344. */
  1345. if (fwrq->m > 1000 || fwrq->e > 0) {
  1346. rc = -EOPNOTSUPP;
  1347. } else {
  1348. int channel = fwrq->m;
  1349. cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
  1350. if (!cfp) {
  1351. rc = -EINVAL;
  1352. } else {
  1353. if (adapter->inframode == wlan802_11ibss) {
  1354. rc = changeadhocchannel(priv, channel);
  1355. /* If station is WEP enabled, send the
  1356. * command to set WEP in firmware
  1357. */
  1358. if (adapter->secinfo.WEPstatus ==
  1359. wlan802_11WEPenabled) {
  1360. lbs_pr_debug(1, "set_freq: WEP enabled\n");
  1361. ret = libertas_prepare_and_send_command(priv,
  1362. cmd_802_11_set_wep,
  1363. cmd_act_add,
  1364. cmd_option_waitforrsp,
  1365. 0,
  1366. NULL);
  1367. if (ret) {
  1368. LEAVE();
  1369. return ret;
  1370. }
  1371. adapter->currentpacketfilter |=
  1372. cmd_act_mac_wep_enable;
  1373. libertas_set_mac_packet_filter(priv);
  1374. }
  1375. } else {
  1376. rc = -EOPNOTSUPP;
  1377. }
  1378. }
  1379. }
  1380. LEAVE();
  1381. return rc;
  1382. }
  1383. /**
  1384. * @brief use index to get the data rate
  1385. *
  1386. * @param index The index of data rate
  1387. * @return data rate or 0
  1388. */
  1389. u32 libertas_index_to_data_rate(u8 index)
  1390. {
  1391. if (index >= sizeof(libertas_wlan_data_rates))
  1392. index = 0;
  1393. return libertas_wlan_data_rates[index];
  1394. }
  1395. /**
  1396. * @brief use rate to get the index
  1397. *
  1398. * @param rate data rate
  1399. * @return index or 0
  1400. */
  1401. u8 libertas_data_rate_to_index(u32 rate)
  1402. {
  1403. u8 *ptr;
  1404. if (rate)
  1405. if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
  1406. sizeof(libertas_wlan_data_rates))))
  1407. return (ptr - libertas_wlan_data_rates);
  1408. return 0;
  1409. }
  1410. static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
  1411. struct iw_param *vwrq, char *extra)
  1412. {
  1413. wlan_private *priv = dev->priv;
  1414. wlan_adapter *adapter = priv->adapter;
  1415. u32 data_rate;
  1416. u16 action;
  1417. int ret = 0;
  1418. u8 rates[WLAN_SUPPORTED_RATES];
  1419. u8 *rate;
  1420. ENTER();
  1421. lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
  1422. if (vwrq->value == -1) {
  1423. action = cmd_act_set_tx_auto; // Auto
  1424. adapter->is_datarate_auto = 1;
  1425. adapter->datarate = 0;
  1426. } else {
  1427. if (vwrq->value % 100000) {
  1428. return -EINVAL;
  1429. }
  1430. data_rate = vwrq->value / 500000;
  1431. memset(rates, 0, sizeof(rates));
  1432. get_active_data_rates(adapter, rates);
  1433. rate = rates;
  1434. while (*rate) {
  1435. lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate,
  1436. data_rate);
  1437. if ((*rate & 0x7f) == (data_rate & 0x7f))
  1438. break;
  1439. rate++;
  1440. }
  1441. if (!*rate) {
  1442. lbs_pr_alert( "The fixed data rate 0x%X is out "
  1443. "of range.\n", data_rate);
  1444. return -EINVAL;
  1445. }
  1446. adapter->datarate = data_rate;
  1447. action = cmd_act_set_tx_fix_rate;
  1448. adapter->is_datarate_auto = 0;
  1449. }
  1450. ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
  1451. action, cmd_option_waitforrsp, 0, NULL);
  1452. LEAVE();
  1453. return ret;
  1454. }
  1455. static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
  1456. struct iw_param *vwrq, char *extra)
  1457. {
  1458. wlan_private *priv = dev->priv;
  1459. wlan_adapter *adapter = priv->adapter;
  1460. ENTER();
  1461. if (adapter->is_datarate_auto) {
  1462. vwrq->fixed = 0;
  1463. } else {
  1464. vwrq->fixed = 1;
  1465. }
  1466. vwrq->value = adapter->datarate * 500000;
  1467. LEAVE();
  1468. return 0;
  1469. }
  1470. static int wlan_set_mode(struct net_device *dev,
  1471. struct iw_request_info *info, u32 * uwrq, char *extra)
  1472. {
  1473. int ret = 0;
  1474. wlan_private *priv = dev->priv;
  1475. wlan_adapter *adapter = priv->adapter;
  1476. struct assoc_request * assoc_req;
  1477. enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode;
  1478. ENTER();
  1479. switch (*uwrq) {
  1480. case IW_MODE_ADHOC:
  1481. lbs_pr_debug(1, "Wanted mode is ad-hoc: current datarate=%#x\n",
  1482. adapter->datarate);
  1483. new_mode = wlan802_11ibss;
  1484. adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
  1485. break;
  1486. case IW_MODE_INFRA:
  1487. lbs_pr_debug(1, "Wanted mode is Infrastructure\n");
  1488. new_mode = wlan802_11infrastructure;
  1489. break;
  1490. case IW_MODE_AUTO:
  1491. lbs_pr_debug(1, "Wanted mode is Auto\n");
  1492. new_mode = wlan802_11autounknown;
  1493. break;
  1494. default:
  1495. lbs_pr_debug(1, "Wanted mode is Unknown: 0x%x\n", *uwrq);
  1496. return -EINVAL;
  1497. }
  1498. mutex_lock(&adapter->lock);
  1499. assoc_req = wlan_get_association_request(adapter);
  1500. if (!assoc_req) {
  1501. ret = -ENOMEM;
  1502. } else {
  1503. assoc_req->mode = new_mode;
  1504. }
  1505. if (ret == 0) {
  1506. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  1507. wlan_postpone_association_work(priv);
  1508. } else {
  1509. wlan_cancel_association_work(priv);
  1510. }
  1511. mutex_unlock(&adapter->lock);
  1512. LEAVE();
  1513. return ret;
  1514. }
  1515. /**
  1516. * @brief Get Encryption key
  1517. *
  1518. * @param dev A pointer to net_device structure
  1519. * @param info A pointer to iw_request_info structure
  1520. * @param vwrq A pointer to iw_param structure
  1521. * @param extra A pointer to extra data buf
  1522. * @return 0 --success, otherwise fail
  1523. */
  1524. static int wlan_get_encode(struct net_device *dev,
  1525. struct iw_request_info *info,
  1526. struct iw_point *dwrq, u8 * extra)
  1527. {
  1528. wlan_private *priv = dev->priv;
  1529. wlan_adapter *adapter = priv->adapter;
  1530. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  1531. ENTER();
  1532. lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
  1533. dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
  1534. dwrq->flags = 0;
  1535. /* Authentication method */
  1536. switch (adapter->secinfo.authmode) {
  1537. case wlan802_11authmodeopen:
  1538. dwrq->flags = IW_ENCODE_OPEN;
  1539. break;
  1540. case wlan802_11authmodeshared:
  1541. case wlan802_11authmodenetworkEAP:
  1542. dwrq->flags = IW_ENCODE_RESTRICTED;
  1543. break;
  1544. default:
  1545. dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
  1546. break;
  1547. }
  1548. if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled)
  1549. || adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
  1550. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1551. } else {
  1552. dwrq->flags |= IW_ENCODE_DISABLED;
  1553. }
  1554. memset(extra, 0, 16);
  1555. mutex_lock(&adapter->lock);
  1556. /* Default to returning current transmit key */
  1557. if (index < 0)
  1558. index = adapter->wep_tx_keyidx;
  1559. if ((adapter->wep_keys[index].len) &&
  1560. (adapter->secinfo.WEPstatus == wlan802_11WEPenabled)) {
  1561. memcpy(extra, adapter->wep_keys[index].key,
  1562. adapter->wep_keys[index].len);
  1563. dwrq->length = adapter->wep_keys[index].len;
  1564. dwrq->flags |= (index + 1);
  1565. /* Return WEP enabled */
  1566. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1567. } else if ((adapter->secinfo.WPAenabled)
  1568. || (adapter->secinfo.WPA2enabled)) {
  1569. /* return WPA enabled */
  1570. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1571. } else {
  1572. dwrq->flags |= IW_ENCODE_DISABLED;
  1573. }
  1574. mutex_unlock(&adapter->lock);
  1575. dwrq->flags |= IW_ENCODE_NOKEY;
  1576. lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
  1577. extra[0], extra[1], extra[2],
  1578. extra[3], extra[4], extra[5], dwrq->length);
  1579. lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
  1580. LEAVE();
  1581. return 0;
  1582. }
  1583. /**
  1584. * @brief Set Encryption key (internal)
  1585. *
  1586. * @param priv A pointer to private card structure
  1587. * @param key_material A pointer to key material
  1588. * @param key_length length of key material
  1589. * @param index key index to set
  1590. * @param set_tx_key Force set TX key (1 = yes, 0 = no)
  1591. * @return 0 --success, otherwise fail
  1592. */
  1593. static int wlan_set_wep_key(struct assoc_request *assoc_req,
  1594. const char *key_material,
  1595. u16 key_length,
  1596. u16 index,
  1597. int set_tx_key)
  1598. {
  1599. struct WLAN_802_11_KEY *pkey;
  1600. ENTER();
  1601. /* Paranoid validation of key index */
  1602. if (index > 3) {
  1603. LEAVE();
  1604. return -EINVAL;
  1605. }
  1606. /* validate max key length */
  1607. if (key_length > KEY_LEN_WEP_104) {
  1608. LEAVE();
  1609. return -EINVAL;
  1610. }
  1611. pkey = &assoc_req->wep_keys[index];
  1612. if (key_length > 0) {
  1613. memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
  1614. pkey->type = KEY_TYPE_ID_WEP;
  1615. /* Standardize the key length */
  1616. pkey->len = (key_length > KEY_LEN_WEP_40) ?
  1617. KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
  1618. memcpy(pkey->key, key_material, key_length);
  1619. }
  1620. if (set_tx_key) {
  1621. /* Ensure the chosen key is valid */
  1622. if (!pkey->len) {
  1623. lbs_pr_debug(1, "key not set, so cannot enable it\n");
  1624. LEAVE();
  1625. return -EINVAL;
  1626. }
  1627. assoc_req->wep_tx_keyidx = index;
  1628. }
  1629. assoc_req->secinfo.WEPstatus = wlan802_11WEPenabled;
  1630. LEAVE();
  1631. return 0;
  1632. }
  1633. static int validate_key_index(u16 def_index, u16 raw_index,
  1634. u16 *out_index, u16 *is_default)
  1635. {
  1636. if (!out_index || !is_default)
  1637. return -EINVAL;
  1638. /* Verify index if present, otherwise use default TX key index */
  1639. if (raw_index > 0) {
  1640. if (raw_index > 4)
  1641. return -EINVAL;
  1642. *out_index = raw_index - 1;
  1643. } else {
  1644. *out_index = def_index;
  1645. *is_default = 1;
  1646. }
  1647. return 0;
  1648. }
  1649. static void disable_wep(struct assoc_request *assoc_req)
  1650. {
  1651. int i;
  1652. /* Set Open System auth mode */
  1653. assoc_req->secinfo.authmode = wlan802_11authmodeopen;
  1654. /* Clear WEP keys and mark WEP as disabled */
  1655. assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
  1656. for (i = 0; i < 4; i++)
  1657. assoc_req->wep_keys[i].len = 0;
  1658. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1659. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1660. }
  1661. /**
  1662. * @brief Set Encryption key
  1663. *
  1664. * @param dev A pointer to net_device structure
  1665. * @param info A pointer to iw_request_info structure
  1666. * @param vwrq A pointer to iw_param structure
  1667. * @param extra A pointer to extra data buf
  1668. * @return 0 --success, otherwise fail
  1669. */
  1670. static int wlan_set_encode(struct net_device *dev,
  1671. struct iw_request_info *info,
  1672. struct iw_point *dwrq, char *extra)
  1673. {
  1674. int ret = 0;
  1675. wlan_private *priv = dev->priv;
  1676. wlan_adapter *adapter = priv->adapter;
  1677. struct assoc_request * assoc_req;
  1678. u16 is_default = 0, index = 0, set_tx_key = 0;
  1679. ENTER();
  1680. mutex_lock(&adapter->lock);
  1681. assoc_req = wlan_get_association_request(adapter);
  1682. if (!assoc_req) {
  1683. ret = -ENOMEM;
  1684. goto out;
  1685. }
  1686. if (dwrq->flags & IW_ENCODE_DISABLED) {
  1687. disable_wep (assoc_req);
  1688. goto out;
  1689. }
  1690. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1691. (dwrq->flags & IW_ENCODE_INDEX),
  1692. &index, &is_default);
  1693. if (ret) {
  1694. ret = -EINVAL;
  1695. goto out;
  1696. }
  1697. /* If WEP isn't enabled, or if there is no key data but a valid
  1698. * index, set the TX key.
  1699. */
  1700. if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled)
  1701. || (dwrq->length == 0 && !is_default))
  1702. set_tx_key = 1;
  1703. ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
  1704. if (ret)
  1705. goto out;
  1706. if (dwrq->length)
  1707. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1708. if (set_tx_key)
  1709. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1710. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1711. assoc_req->secinfo.authmode = wlan802_11authmodeshared;
  1712. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1713. assoc_req->secinfo.authmode = wlan802_11authmodeopen;
  1714. }
  1715. out:
  1716. if (ret == 0) {
  1717. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1718. wlan_postpone_association_work(priv);
  1719. } else {
  1720. wlan_cancel_association_work(priv);
  1721. }
  1722. mutex_unlock(&adapter->lock);
  1723. LEAVE();
  1724. return ret;
  1725. }
  1726. /**
  1727. * @brief Get Extended Encryption key (WPA/802.1x and WEP)
  1728. *
  1729. * @param dev A pointer to net_device structure
  1730. * @param info A pointer to iw_request_info structure
  1731. * @param vwrq A pointer to iw_param structure
  1732. * @param extra A pointer to extra data buf
  1733. * @return 0 on success, otherwise failure
  1734. */
  1735. static int wlan_get_encodeext(struct net_device *dev,
  1736. struct iw_request_info *info,
  1737. struct iw_point *dwrq,
  1738. char *extra)
  1739. {
  1740. int ret = -EINVAL;
  1741. wlan_private *priv = dev->priv;
  1742. wlan_adapter *adapter = priv->adapter;
  1743. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1744. int index, max_key_len;
  1745. ENTER();
  1746. max_key_len = dwrq->length - sizeof(*ext);
  1747. if (max_key_len < 0)
  1748. goto out;
  1749. index = dwrq->flags & IW_ENCODE_INDEX;
  1750. if (index) {
  1751. if (index < 1 || index > 4)
  1752. goto out;
  1753. index--;
  1754. } else {
  1755. index = adapter->wep_tx_keyidx;
  1756. }
  1757. if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
  1758. ext->alg != IW_ENCODE_ALG_WEP) {
  1759. if (index != 0 || adapter->inframode != wlan802_11infrastructure)
  1760. goto out;
  1761. }
  1762. dwrq->flags = index + 1;
  1763. memset(ext, 0, sizeof(*ext));
  1764. if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled)
  1765. && !adapter->secinfo.WPAenabled && !adapter->secinfo.WPA2enabled) {
  1766. ext->alg = IW_ENCODE_ALG_NONE;
  1767. ext->key_len = 0;
  1768. dwrq->flags |= IW_ENCODE_DISABLED;
  1769. } else {
  1770. u8 *key = NULL;
  1771. if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled)
  1772. && !adapter->secinfo.WPAenabled
  1773. && !adapter->secinfo.WPA2enabled) {
  1774. ext->alg = IW_ENCODE_ALG_WEP;
  1775. ext->key_len = adapter->wep_keys[index].len;
  1776. key = &adapter->wep_keys[index].key[0];
  1777. } else if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled) &&
  1778. (adapter->secinfo.WPAenabled ||
  1779. adapter->secinfo.WPA2enabled)) {
  1780. /* WPA */
  1781. ext->alg = IW_ENCODE_ALG_TKIP;
  1782. ext->key_len = 0;
  1783. } else {
  1784. goto out;
  1785. }
  1786. if (ext->key_len > max_key_len) {
  1787. ret = -E2BIG;
  1788. goto out;
  1789. }
  1790. if (ext->key_len)
  1791. memcpy(ext->key, key, ext->key_len);
  1792. else
  1793. dwrq->flags |= IW_ENCODE_NOKEY;
  1794. dwrq->flags |= IW_ENCODE_ENABLED;
  1795. }
  1796. ret = 0;
  1797. out:
  1798. LEAVE();
  1799. return ret;
  1800. }
  1801. /**
  1802. * @brief Set Encryption key Extended (WPA/802.1x and WEP)
  1803. *
  1804. * @param dev A pointer to net_device structure
  1805. * @param info A pointer to iw_request_info structure
  1806. * @param vwrq A pointer to iw_param structure
  1807. * @param extra A pointer to extra data buf
  1808. * @return 0 --success, otherwise fail
  1809. */
  1810. static int wlan_set_encodeext(struct net_device *dev,
  1811. struct iw_request_info *info,
  1812. struct iw_point *dwrq,
  1813. char *extra)
  1814. {
  1815. int ret = 0;
  1816. wlan_private *priv = dev->priv;
  1817. wlan_adapter *adapter = priv->adapter;
  1818. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1819. int alg = ext->alg;
  1820. struct assoc_request * assoc_req;
  1821. ENTER();
  1822. mutex_lock(&adapter->lock);
  1823. assoc_req = wlan_get_association_request(adapter);
  1824. if (!assoc_req) {
  1825. ret = -ENOMEM;
  1826. goto out;
  1827. }
  1828. if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
  1829. disable_wep (assoc_req);
  1830. } else if (alg == IW_ENCODE_ALG_WEP) {
  1831. u16 is_default = 0, index, set_tx_key = 0;
  1832. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1833. (dwrq->flags & IW_ENCODE_INDEX),
  1834. &index, &is_default);
  1835. if (ret)
  1836. goto out;
  1837. /* If WEP isn't enabled, or if there is no key data but a valid
  1838. * index, or if the set-TX-key flag was passed, set the TX key.
  1839. */
  1840. if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled)
  1841. || (dwrq->length == 0 && !is_default)
  1842. || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
  1843. set_tx_key = 1;
  1844. /* Copy key to driver */
  1845. ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
  1846. set_tx_key);
  1847. if (ret)
  1848. goto out;
  1849. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1850. assoc_req->secinfo.authmode =
  1851. wlan802_11authmodeshared;
  1852. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1853. assoc_req->secinfo.authmode =
  1854. wlan802_11authmodeopen;
  1855. }
  1856. /* Mark the various WEP bits as modified */
  1857. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1858. if (dwrq->length)
  1859. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1860. if (set_tx_key)
  1861. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1862. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1863. struct WLAN_802_11_KEY * pkey;
  1864. /* validate key length */
  1865. if (((alg == IW_ENCODE_ALG_TKIP)
  1866. && (ext->key_len != KEY_LEN_WPA_TKIP))
  1867. || ((alg == IW_ENCODE_ALG_CCMP)
  1868. && (ext->key_len != KEY_LEN_WPA_AES))) {
  1869. lbs_pr_debug(1, "Invalid size %d for key of alg"
  1870. "type %d.\n",
  1871. ext->key_len,
  1872. alg);
  1873. ret = -EINVAL;
  1874. goto out;
  1875. }
  1876. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
  1877. pkey = &assoc_req->wpa_mcast_key;
  1878. else
  1879. pkey = &assoc_req->wpa_unicast_key;
  1880. memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
  1881. memcpy(pkey->key, ext->key, ext->key_len);
  1882. pkey->len = ext->key_len;
  1883. pkey->flags = KEY_INFO_WPA_ENABLED;
  1884. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1885. pkey->flags |= KEY_INFO_WPA_MCAST;
  1886. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1887. } else {
  1888. pkey->flags |= KEY_INFO_WPA_UNICAST;
  1889. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1890. }
  1891. if (alg == IW_ENCODE_ALG_TKIP)
  1892. pkey->type = KEY_TYPE_ID_TKIP;
  1893. else if (alg == IW_ENCODE_ALG_CCMP)
  1894. pkey->type = KEY_TYPE_ID_AES;
  1895. /* If WPA isn't enabled yet, do that now */
  1896. if ( assoc_req->secinfo.WPAenabled == 0
  1897. && assoc_req->secinfo.WPA2enabled == 0) {
  1898. assoc_req->secinfo.WPAenabled = 1;
  1899. assoc_req->secinfo.WPA2enabled = 1;
  1900. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1901. }
  1902. disable_wep (assoc_req);
  1903. }
  1904. out:
  1905. if (ret == 0) {
  1906. wlan_postpone_association_work(priv);
  1907. } else {
  1908. wlan_cancel_association_work(priv);
  1909. }
  1910. mutex_unlock(&adapter->lock);
  1911. LEAVE();
  1912. return ret;
  1913. }
  1914. static int wlan_set_genie(struct net_device *dev,
  1915. struct iw_request_info *info,
  1916. struct iw_point *dwrq,
  1917. char *extra)
  1918. {
  1919. wlan_private *priv = dev->priv;
  1920. wlan_adapter *adapter = priv->adapter;
  1921. int ret = 0;
  1922. struct assoc_request * assoc_req;
  1923. ENTER();
  1924. mutex_lock(&adapter->lock);
  1925. assoc_req = wlan_get_association_request(adapter);
  1926. if (!assoc_req) {
  1927. ret = -ENOMEM;
  1928. goto out;
  1929. }
  1930. if (dwrq->length > MAX_WPA_IE_LEN ||
  1931. (dwrq->length && extra == NULL)) {
  1932. ret = -EINVAL;
  1933. goto out;
  1934. }
  1935. if (dwrq->length) {
  1936. memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
  1937. assoc_req->wpa_ie_len = dwrq->length;
  1938. } else {
  1939. memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
  1940. assoc_req->wpa_ie_len = 0;
  1941. }
  1942. out:
  1943. if (ret == 0) {
  1944. set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
  1945. wlan_postpone_association_work(priv);
  1946. } else {
  1947. wlan_cancel_association_work(priv);
  1948. }
  1949. mutex_unlock(&adapter->lock);
  1950. LEAVE();
  1951. return ret;
  1952. }
  1953. static int wlan_get_genie(struct net_device *dev,
  1954. struct iw_request_info *info,
  1955. struct iw_point *dwrq,
  1956. char *extra)
  1957. {
  1958. wlan_private *priv = dev->priv;
  1959. wlan_adapter *adapter = priv->adapter;
  1960. ENTER();
  1961. if (adapter->wpa_ie_len == 0) {
  1962. dwrq->length = 0;
  1963. LEAVE();
  1964. return 0;
  1965. }
  1966. if (dwrq->length < adapter->wpa_ie_len) {
  1967. LEAVE();
  1968. return -E2BIG;
  1969. }
  1970. dwrq->length = adapter->wpa_ie_len;
  1971. memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
  1972. LEAVE();
  1973. return 0;
  1974. }
  1975. static int wlan_set_auth(struct net_device *dev,
  1976. struct iw_request_info *info,
  1977. struct iw_param *dwrq,
  1978. char *extra)
  1979. {
  1980. wlan_private *priv = dev->priv;
  1981. wlan_adapter *adapter = priv->adapter;
  1982. struct assoc_request * assoc_req;
  1983. int ret = 0;
  1984. int updated = 0;
  1985. ENTER();
  1986. mutex_lock(&adapter->lock);
  1987. assoc_req = wlan_get_association_request(adapter);
  1988. if (!assoc_req) {
  1989. ret = -ENOMEM;
  1990. goto out;
  1991. }
  1992. switch (dwrq->flags & IW_AUTH_INDEX) {
  1993. case IW_AUTH_TKIP_COUNTERMEASURES:
  1994. case IW_AUTH_CIPHER_PAIRWISE:
  1995. case IW_AUTH_CIPHER_GROUP:
  1996. case IW_AUTH_KEY_MGMT:
  1997. /*
  1998. * libertas does not use these parameters
  1999. */
  2000. break;
  2001. case IW_AUTH_WPA_VERSION:
  2002. if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
  2003. assoc_req->secinfo.WPAenabled = 0;
  2004. assoc_req->secinfo.WPA2enabled = 0;
  2005. }
  2006. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
  2007. assoc_req->secinfo.WPAenabled = 1;
  2008. assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
  2009. assoc_req->secinfo.authmode =
  2010. wlan802_11authmodeopen;
  2011. }
  2012. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
  2013. assoc_req->secinfo.WPA2enabled = 1;
  2014. assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
  2015. assoc_req->secinfo.authmode =
  2016. wlan802_11authmodeopen;
  2017. }
  2018. updated = 1;
  2019. break;
  2020. case IW_AUTH_DROP_UNENCRYPTED:
  2021. if (dwrq->value) {
  2022. adapter->currentpacketfilter |=
  2023. cmd_act_mac_strict_protection_enable;
  2024. } else {
  2025. adapter->currentpacketfilter &=
  2026. ~cmd_act_mac_strict_protection_enable;
  2027. }
  2028. updated = 1;
  2029. break;
  2030. case IW_AUTH_80211_AUTH_ALG:
  2031. if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
  2032. assoc_req->secinfo.authmode =
  2033. wlan802_11authmodeshared;
  2034. } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  2035. assoc_req->secinfo.authmode =
  2036. wlan802_11authmodeopen;
  2037. } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
  2038. assoc_req->secinfo.authmode =
  2039. wlan802_11authmodenetworkEAP;
  2040. } else {
  2041. ret = -EINVAL;
  2042. }
  2043. updated = 1;
  2044. break;
  2045. case IW_AUTH_WPA_ENABLED:
  2046. if (dwrq->value) {
  2047. if (!assoc_req->secinfo.WPAenabled &&
  2048. !assoc_req->secinfo.WPA2enabled) {
  2049. assoc_req->secinfo.WPAenabled = 1;
  2050. assoc_req->secinfo.WPA2enabled = 1;
  2051. assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
  2052. assoc_req->secinfo.authmode =
  2053. wlan802_11authmodeopen;
  2054. }
  2055. } else {
  2056. assoc_req->secinfo.WPAenabled = 0;
  2057. assoc_req->secinfo.WPA2enabled = 0;
  2058. }
  2059. updated = 1;
  2060. break;
  2061. default:
  2062. ret = -EOPNOTSUPP;
  2063. break;
  2064. }
  2065. out:
  2066. if (ret == 0) {
  2067. if (updated)
  2068. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  2069. wlan_postpone_association_work(priv);
  2070. } else if (ret != -EOPNOTSUPP) {
  2071. wlan_cancel_association_work(priv);
  2072. }
  2073. mutex_unlock(&adapter->lock);
  2074. LEAVE();
  2075. return ret;
  2076. }
  2077. static int wlan_get_auth(struct net_device *dev,
  2078. struct iw_request_info *info,
  2079. struct iw_param *dwrq,
  2080. char *extra)
  2081. {
  2082. wlan_private *priv = dev->priv;
  2083. wlan_adapter *adapter = priv->adapter;
  2084. ENTER();
  2085. switch (dwrq->flags & IW_AUTH_INDEX) {
  2086. case IW_AUTH_WPA_VERSION:
  2087. dwrq->value = 0;
  2088. if (adapter->secinfo.WPAenabled)
  2089. dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
  2090. if (adapter->secinfo.WPA2enabled)
  2091. dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
  2092. if (!dwrq->value)
  2093. dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
  2094. break;
  2095. case IW_AUTH_DROP_UNENCRYPTED:
  2096. dwrq->value = 0;
  2097. if (adapter->currentpacketfilter &
  2098. cmd_act_mac_strict_protection_enable)
  2099. dwrq->value = 1;
  2100. break;
  2101. case IW_AUTH_80211_AUTH_ALG:
  2102. switch (adapter->secinfo.authmode) {
  2103. case wlan802_11authmodeshared:
  2104. dwrq->value = IW_AUTH_ALG_SHARED_KEY;
  2105. break;
  2106. case wlan802_11authmodeopen:
  2107. dwrq->value = IW_AUTH_ALG_OPEN_SYSTEM;
  2108. break;
  2109. case wlan802_11authmodenetworkEAP:
  2110. dwrq->value = IW_AUTH_ALG_LEAP;
  2111. break;
  2112. default:
  2113. break;
  2114. }
  2115. break;
  2116. case IW_AUTH_WPA_ENABLED:
  2117. if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
  2118. dwrq->value = 1;
  2119. break;
  2120. default:
  2121. LEAVE();
  2122. return -EOPNOTSUPP;
  2123. }
  2124. LEAVE();
  2125. return 0;
  2126. }
  2127. static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
  2128. struct iw_param *vwrq, char *extra)
  2129. {
  2130. int ret = 0;
  2131. wlan_private *priv = dev->priv;
  2132. wlan_adapter *adapter = priv->adapter;
  2133. u16 dbm;
  2134. ENTER();
  2135. if (vwrq->disabled) {
  2136. wlan_radio_ioctl(priv, RADIO_OFF);
  2137. return 0;
  2138. }
  2139. adapter->preamble = cmd_type_auto_preamble;
  2140. wlan_radio_ioctl(priv, RADIO_ON);
  2141. if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
  2142. dbm = (u16) mw_to_dbm(vwrq->value);
  2143. } else
  2144. dbm = (u16) vwrq->value;
  2145. /* auto tx power control */
  2146. if (vwrq->fixed == 0)
  2147. dbm = 0xffff;
  2148. lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
  2149. ret = libertas_prepare_and_send_command(priv,
  2150. cmd_802_11_rf_tx_power,
  2151. cmd_act_tx_power_opt_set_low,
  2152. cmd_option_waitforrsp, 0, (void *)&dbm);
  2153. LEAVE();
  2154. return ret;
  2155. }
  2156. static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
  2157. struct iw_point *dwrq, char *extra)
  2158. {
  2159. wlan_private *priv = dev->priv;
  2160. wlan_adapter *adapter = priv->adapter;
  2161. ENTER();
  2162. /*
  2163. * Note : if dwrq->flags != 0, we should get the relevant SSID from
  2164. * the SSID list...
  2165. */
  2166. /*
  2167. * Get the current SSID
  2168. */
  2169. if (adapter->connect_status == libertas_connected) {
  2170. memcpy(extra, adapter->curbssparams.ssid.ssid,
  2171. adapter->curbssparams.ssid.ssidlength);
  2172. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  2173. } else {
  2174. memset(extra, 0, 32);
  2175. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  2176. }
  2177. /*
  2178. * If none, we may want to get the one that was set
  2179. */
  2180. /* To make the driver backward compatible with WPA supplicant v0.2.4 */
  2181. if (dwrq->length == 32) /* check with WPA supplicant buffer size */
  2182. dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
  2183. IW_ESSID_MAX_SIZE);
  2184. else
  2185. dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
  2186. dwrq->flags = 1; /* active */
  2187. LEAVE();
  2188. return 0;
  2189. }
  2190. static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
  2191. struct iw_point *dwrq, char *extra)
  2192. {
  2193. wlan_private *priv = dev->priv;
  2194. wlan_adapter *adapter = priv->adapter;
  2195. int ret = 0;
  2196. struct WLAN_802_11_SSID ssid;
  2197. struct assoc_request * assoc_req;
  2198. int ssid_len = dwrq->length;
  2199. ENTER();
  2200. /*
  2201. * WE-20 and earlier NULL pad the end of the SSID and increment
  2202. * SSID length so it can be used like a string. WE-21 and later don't,
  2203. * but some userspace tools aren't able to cope with the change.
  2204. */
  2205. if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
  2206. ssid_len--;
  2207. /* Check the size of the string */
  2208. if (ssid_len > IW_ESSID_MAX_SIZE) {
  2209. ret = -E2BIG;
  2210. goto out;
  2211. }
  2212. memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
  2213. if (!dwrq->flags || !ssid_len) {
  2214. /* "any" SSID requested; leave SSID blank */
  2215. } else {
  2216. /* Specific SSID requested */
  2217. memcpy(&ssid.ssid, extra, ssid_len);
  2218. ssid.ssidlength = ssid_len;
  2219. }
  2220. lbs_pr_debug(1, "Requested new SSID = %s\n",
  2221. (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
  2222. out:
  2223. mutex_lock(&adapter->lock);
  2224. if (ret == 0) {
  2225. /* Get or create the current association request */
  2226. assoc_req = wlan_get_association_request(adapter);
  2227. if (!assoc_req) {
  2228. ret = -ENOMEM;
  2229. } else {
  2230. /* Copy the SSID to the association request */
  2231. memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
  2232. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  2233. wlan_postpone_association_work(priv);
  2234. }
  2235. }
  2236. /* Cancel the association request if there was an error */
  2237. if (ret != 0) {
  2238. wlan_cancel_association_work(priv);
  2239. }
  2240. mutex_unlock(&adapter->lock);
  2241. LEAVE();
  2242. return ret;
  2243. }
  2244. /**
  2245. * @brief Connect to the AP or Ad-hoc Network with specific bssid
  2246. *
  2247. * @param dev A pointer to net_device structure
  2248. * @param info A pointer to iw_request_info structure
  2249. * @param awrq A pointer to iw_param structure
  2250. * @param extra A pointer to extra data buf
  2251. * @return 0 --success, otherwise fail
  2252. */
  2253. static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
  2254. struct sockaddr *awrq, char *extra)
  2255. {
  2256. wlan_private *priv = dev->priv;
  2257. wlan_adapter *adapter = priv->adapter;
  2258. struct assoc_request * assoc_req;
  2259. int ret = 0;
  2260. ENTER();
  2261. if (awrq->sa_family != ARPHRD_ETHER)
  2262. return -EINVAL;
  2263. lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
  2264. mutex_lock(&adapter->lock);
  2265. /* Get or create the current association request */
  2266. assoc_req = wlan_get_association_request(adapter);
  2267. if (!assoc_req) {
  2268. wlan_cancel_association_work(priv);
  2269. ret = -ENOMEM;
  2270. } else {
  2271. /* Copy the BSSID to the association request */
  2272. memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
  2273. set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
  2274. wlan_postpone_association_work(priv);
  2275. }
  2276. mutex_unlock(&adapter->lock);
  2277. return ret;
  2278. }
  2279. void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
  2280. {
  2281. union {
  2282. u32 l;
  2283. u8 c[4];
  2284. } ver;
  2285. char fwver[32];
  2286. mutex_lock(&adapter->lock);
  2287. ver.l = adapter->fwreleasenumber;
  2288. mutex_unlock(&adapter->lock);
  2289. if (ver.c[3] == 0)
  2290. sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
  2291. else
  2292. sprintf(fwver, "%u.%u.%u.p%u",
  2293. ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  2294. snprintf(fwversion, maxlen, fwver);
  2295. }
  2296. /*
  2297. * iwconfig settable callbacks
  2298. */
  2299. static const iw_handler wlan_handler[] = {
  2300. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  2301. (iw_handler) wlan_get_name, /* SIOCGIWNAME */
  2302. (iw_handler) NULL, /* SIOCSIWNWID */
  2303. (iw_handler) NULL, /* SIOCGIWNWID */
  2304. (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
  2305. (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
  2306. (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
  2307. (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
  2308. (iw_handler) NULL, /* SIOCSIWSENS */
  2309. (iw_handler) NULL, /* SIOCGIWSENS */
  2310. (iw_handler) NULL, /* SIOCSIWRANGE */
  2311. (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
  2312. (iw_handler) NULL, /* SIOCSIWPRIV */
  2313. (iw_handler) NULL, /* SIOCGIWPRIV */
  2314. (iw_handler) NULL, /* SIOCSIWSTATS */
  2315. (iw_handler) NULL, /* SIOCGIWSTATS */
  2316. iw_handler_set_spy, /* SIOCSIWSPY */
  2317. iw_handler_get_spy, /* SIOCGIWSPY */
  2318. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2319. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2320. (iw_handler) wlan_set_wap, /* SIOCSIWAP */
  2321. (iw_handler) wlan_get_wap, /* SIOCGIWAP */
  2322. (iw_handler) NULL, /* SIOCSIWMLME */
  2323. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  2324. (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
  2325. (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
  2326. (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
  2327. (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
  2328. (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
  2329. (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
  2330. (iw_handler) NULL, /* -- hole -- */
  2331. (iw_handler) NULL, /* -- hole -- */
  2332. (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
  2333. (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
  2334. (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
  2335. (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
  2336. (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
  2337. (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
  2338. (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
  2339. (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
  2340. (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
  2341. (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
  2342. (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
  2343. (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
  2344. (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
  2345. (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
  2346. (iw_handler) NULL, /* -- hole -- */
  2347. (iw_handler) NULL, /* -- hole -- */
  2348. (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
  2349. (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
  2350. (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
  2351. (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
  2352. (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
  2353. (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
  2354. (iw_handler) NULL, /* SIOCSIWPMKSA */
  2355. };
  2356. struct iw_handler_def libertas_handler_def = {
  2357. .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
  2358. .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
  2359. .num_private_args = sizeof(wlan_private_args) /
  2360. sizeof(struct iw_priv_args),
  2361. .standard = (iw_handler *) wlan_handler,
  2362. .private = (iw_handler *) wlan_private_handler,
  2363. .private_args = (struct iw_priv_args *)wlan_private_args,
  2364. .get_wireless_stats = wlan_get_wireless_stats,
  2365. };