wext.c 55 KB

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