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 lbs_postpone_association_work(struct lbs_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 lbs_cancel_association_work(struct lbs_private *priv)
  28. {
  29. cancel_delayed_work(&priv->assoc_work);
  30. kfree(priv->adapter->pending_assoc_req);
  31. priv->adapter->pending_assoc_req = NULL;
  32. }
  33. /**
  34. * @brief Find the channel frequency power info with specific channel
  35. *
  36. * @param adapter A pointer to struct lbs_adapter structure
  37. * @param band it can be BAND_A, BAND_G or BAND_B
  38. * @param channel the channel for looking
  39. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  40. */
  41. struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
  42. struct lbs_adapter *adapter,
  43. u8 band,
  44. u16 channel)
  45. {
  46. struct chan_freq_power *cfp = NULL;
  47. struct region_channel *rc;
  48. int i, j;
  49. for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
  50. rc = &adapter->region_channel[j];
  51. if (adapter->enable11d)
  52. rc = &adapter->universal_channel[j];
  53. if (!rc->valid || !rc->CFP)
  54. continue;
  55. if (rc->band != band)
  56. continue;
  57. for (i = 0; i < rc->nrcfp; i++) {
  58. if (rc->CFP[i].channel == channel) {
  59. cfp = &rc->CFP[i];
  60. break;
  61. }
  62. }
  63. }
  64. if (!cfp && channel)
  65. lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
  66. "cfp by band %d / channel %d\n", band, channel);
  67. return cfp;
  68. }
  69. /**
  70. * @brief Find the channel frequency power info with specific frequency
  71. *
  72. * @param adapter A pointer to struct lbs_adapter structure
  73. * @param band it can be BAND_A, BAND_G or BAND_B
  74. * @param freq the frequency for looking
  75. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  76. */
  77. static struct chan_freq_power *find_cfp_by_band_and_freq(
  78. struct lbs_adapter *adapter,
  79. u8 band,
  80. u32 freq)
  81. {
  82. struct chan_freq_power *cfp = NULL;
  83. struct region_channel *rc;
  84. int i, j;
  85. for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
  86. rc = &adapter->region_channel[j];
  87. if (adapter->enable11d)
  88. rc = &adapter->universal_channel[j];
  89. if (!rc->valid || !rc->CFP)
  90. continue;
  91. if (rc->band != band)
  92. continue;
  93. for (i = 0; i < rc->nrcfp; i++) {
  94. if (rc->CFP[i].freq == freq) {
  95. cfp = &rc->CFP[i];
  96. break;
  97. }
  98. }
  99. }
  100. if (!cfp && freq)
  101. lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
  102. "band %d / freq %d\n", band, freq);
  103. return cfp;
  104. }
  105. /**
  106. * @brief Set Radio On/OFF
  107. *
  108. * @param priv A pointer to struct lbs_private structure
  109. * @option Radio Option
  110. * @return 0 --success, otherwise fail
  111. */
  112. static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
  113. {
  114. int ret = 0;
  115. struct lbs_adapter *adapter = priv->adapter;
  116. lbs_deb_enter(LBS_DEB_WEXT);
  117. if (adapter->radioon != option) {
  118. lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
  119. adapter->radioon = option;
  120. ret = lbs_prepare_and_send_command(priv,
  121. CMD_802_11_RADIO_CONTROL,
  122. CMD_ACT_SET,
  123. CMD_OPTION_WAITFORRSP, 0, NULL);
  124. }
  125. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  126. return ret;
  127. }
  128. /**
  129. * @brief Copy active data rates based on adapter mode and status
  130. *
  131. * @param adapter A pointer to struct lbs_adapter structure
  132. * @param rate The buf to return the active rates
  133. */
  134. static void copy_active_data_rates(struct lbs_adapter *adapter, u8 *rates)
  135. {
  136. lbs_deb_enter(LBS_DEB_WEXT);
  137. if ((adapter->connect_status != LBS_CONNECTED) &&
  138. (adapter->mesh_connect_status != LBS_CONNECTED))
  139. memcpy(rates, lbs_bg_rates, MAX_RATES);
  140. else
  141. memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
  142. lbs_deb_leave(LBS_DEB_WEXT);
  143. }
  144. static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
  145. char *cwrq, char *extra)
  146. {
  147. lbs_deb_enter(LBS_DEB_WEXT);
  148. /* We could add support for 802.11n here as needed. Jean II */
  149. snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
  150. lbs_deb_leave(LBS_DEB_WEXT);
  151. return 0;
  152. }
  153. static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
  154. struct iw_freq *fwrq, char *extra)
  155. {
  156. struct lbs_private *priv = dev->priv;
  157. struct lbs_adapter *adapter = priv->adapter;
  158. struct chan_freq_power *cfp;
  159. lbs_deb_enter(LBS_DEB_WEXT);
  160. cfp = lbs_find_cfp_by_band_and_channel(adapter, 0,
  161. adapter->curbssparams.channel);
  162. if (!cfp) {
  163. if (adapter->curbssparams.channel)
  164. lbs_deb_wext("invalid channel %d\n",
  165. adapter->curbssparams.channel);
  166. return -EINVAL;
  167. }
  168. fwrq->m = (long)cfp->freq * 100000;
  169. fwrq->e = 1;
  170. lbs_deb_wext("freq %u\n", fwrq->m);
  171. lbs_deb_leave(LBS_DEB_WEXT);
  172. return 0;
  173. }
  174. static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
  175. struct sockaddr *awrq, char *extra)
  176. {
  177. struct lbs_private *priv = dev->priv;
  178. struct lbs_adapter *adapter = priv->adapter;
  179. lbs_deb_enter(LBS_DEB_WEXT);
  180. if (adapter->connect_status == LBS_CONNECTED) {
  181. memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  182. } else {
  183. memset(awrq->sa_data, 0, ETH_ALEN);
  184. }
  185. awrq->sa_family = ARPHRD_ETHER;
  186. lbs_deb_leave(LBS_DEB_WEXT);
  187. return 0;
  188. }
  189. static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
  190. struct iw_point *dwrq, char *extra)
  191. {
  192. struct lbs_private *priv = dev->priv;
  193. struct lbs_adapter *adapter = priv->adapter;
  194. lbs_deb_enter(LBS_DEB_WEXT);
  195. /*
  196. * Check the size of the string
  197. */
  198. if (dwrq->length > 16) {
  199. return -E2BIG;
  200. }
  201. mutex_lock(&adapter->lock);
  202. memset(adapter->nodename, 0, sizeof(adapter->nodename));
  203. memcpy(adapter->nodename, extra, dwrq->length);
  204. mutex_unlock(&adapter->lock);
  205. lbs_deb_leave(LBS_DEB_WEXT);
  206. return 0;
  207. }
  208. static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
  209. struct iw_point *dwrq, char *extra)
  210. {
  211. struct lbs_private *priv = dev->priv;
  212. struct lbs_adapter *adapter = priv->adapter;
  213. lbs_deb_enter(LBS_DEB_WEXT);
  214. dwrq->length = strlen(adapter->nodename);
  215. memcpy(extra, adapter->nodename, dwrq->length);
  216. extra[dwrq->length] = '\0';
  217. dwrq->flags = 1; /* active */
  218. lbs_deb_leave(LBS_DEB_WEXT);
  219. return 0;
  220. }
  221. static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
  222. struct iw_point *dwrq, char *extra)
  223. {
  224. struct lbs_private *priv = dev->priv;
  225. struct lbs_adapter *adapter = priv->adapter;
  226. lbs_deb_enter(LBS_DEB_WEXT);
  227. /* Use nickname to indicate that mesh is on */
  228. if (adapter->mesh_connect_status == LBS_CONNECTED) {
  229. strncpy(extra, "Mesh", 12);
  230. extra[12] = '\0';
  231. dwrq->length = strlen(extra);
  232. }
  233. else {
  234. extra[0] = '\0';
  235. dwrq->length = 0;
  236. }
  237. lbs_deb_leave(LBS_DEB_WEXT);
  238. return 0;
  239. }
  240. static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
  241. struct iw_param *vwrq, char *extra)
  242. {
  243. int ret = 0;
  244. struct lbs_private *priv = dev->priv;
  245. struct lbs_adapter *adapter = priv->adapter;
  246. u32 rthr = vwrq->value;
  247. lbs_deb_enter(LBS_DEB_WEXT);
  248. if (vwrq->disabled) {
  249. adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
  250. } else {
  251. if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
  252. return -EINVAL;
  253. adapter->rtsthsd = rthr;
  254. }
  255. ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
  256. CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
  257. OID_802_11_RTS_THRESHOLD, &rthr);
  258. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  259. return ret;
  260. }
  261. static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
  262. struct iw_param *vwrq, char *extra)
  263. {
  264. int ret = 0;
  265. struct lbs_private *priv = dev->priv;
  266. struct lbs_adapter *adapter = priv->adapter;
  267. lbs_deb_enter(LBS_DEB_WEXT);
  268. adapter->rtsthsd = 0;
  269. ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
  270. CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
  271. OID_802_11_RTS_THRESHOLD, NULL);
  272. if (ret)
  273. goto out;
  274. vwrq->value = adapter->rtsthsd;
  275. vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
  276. || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
  277. vwrq->fixed = 1;
  278. out:
  279. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  280. return ret;
  281. }
  282. static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
  283. struct iw_param *vwrq, char *extra)
  284. {
  285. int ret = 0;
  286. u32 fthr = vwrq->value;
  287. struct lbs_private *priv = dev->priv;
  288. struct lbs_adapter *adapter = priv->adapter;
  289. lbs_deb_enter(LBS_DEB_WEXT);
  290. if (vwrq->disabled) {
  291. adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
  292. } else {
  293. if (fthr < MRVDRV_FRAG_MIN_VALUE
  294. || fthr > MRVDRV_FRAG_MAX_VALUE)
  295. return -EINVAL;
  296. adapter->fragthsd = fthr;
  297. }
  298. ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
  299. CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
  300. OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
  301. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  302. return ret;
  303. }
  304. static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
  305. struct iw_param *vwrq, char *extra)
  306. {
  307. int ret = 0;
  308. struct lbs_private *priv = dev->priv;
  309. struct lbs_adapter *adapter = priv->adapter;
  310. lbs_deb_enter(LBS_DEB_WEXT);
  311. adapter->fragthsd = 0;
  312. ret = lbs_prepare_and_send_command(priv,
  313. CMD_802_11_SNMP_MIB,
  314. CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
  315. OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
  316. if (ret)
  317. goto out;
  318. vwrq->value = adapter->fragthsd;
  319. vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
  320. || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
  321. vwrq->fixed = 1;
  322. out:
  323. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  324. return ret;
  325. }
  326. static int lbs_get_mode(struct net_device *dev,
  327. struct iw_request_info *info, u32 * uwrq, char *extra)
  328. {
  329. struct lbs_private *priv = dev->priv;
  330. struct lbs_adapter *adapter = priv->adapter;
  331. lbs_deb_enter(LBS_DEB_WEXT);
  332. *uwrq = adapter->mode;
  333. lbs_deb_leave(LBS_DEB_WEXT);
  334. return 0;
  335. }
  336. static int mesh_wlan_get_mode(struct net_device *dev,
  337. struct iw_request_info *info, u32 * uwrq,
  338. char *extra)
  339. {
  340. lbs_deb_enter(LBS_DEB_WEXT);
  341. *uwrq = IW_MODE_REPEAT ;
  342. lbs_deb_leave(LBS_DEB_WEXT);
  343. return 0;
  344. }
  345. static int lbs_get_txpow(struct net_device *dev,
  346. struct iw_request_info *info,
  347. struct iw_param *vwrq, char *extra)
  348. {
  349. int ret = 0;
  350. struct lbs_private *priv = dev->priv;
  351. struct lbs_adapter *adapter = priv->adapter;
  352. lbs_deb_enter(LBS_DEB_WEXT);
  353. ret = lbs_prepare_and_send_command(priv,
  354. CMD_802_11_RF_TX_POWER,
  355. CMD_ACT_TX_POWER_OPT_GET,
  356. CMD_OPTION_WAITFORRSP, 0, NULL);
  357. if (ret)
  358. goto out;
  359. lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
  360. vwrq->value = adapter->txpowerlevel;
  361. vwrq->fixed = 1;
  362. if (adapter->radioon) {
  363. vwrq->disabled = 0;
  364. vwrq->flags = IW_TXPOW_DBM;
  365. } else {
  366. vwrq->disabled = 1;
  367. }
  368. out:
  369. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  370. return ret;
  371. }
  372. static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
  373. struct iw_param *vwrq, char *extra)
  374. {
  375. int ret = 0;
  376. struct lbs_private *priv = dev->priv;
  377. struct lbs_adapter *adapter = priv->adapter;
  378. lbs_deb_enter(LBS_DEB_WEXT);
  379. if (vwrq->flags == IW_RETRY_LIMIT) {
  380. /* The MAC has a 4-bit Total_Tx_Count register
  381. Total_Tx_Count = 1 + Tx_Retry_Count */
  382. #define TX_RETRY_MIN 0
  383. #define TX_RETRY_MAX 14
  384. if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
  385. return -EINVAL;
  386. /* Adding 1 to convert retry count to try count */
  387. adapter->txretrycount = vwrq->value + 1;
  388. ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
  389. CMD_ACT_SET,
  390. CMD_OPTION_WAITFORRSP,
  391. OID_802_11_TX_RETRYCOUNT, NULL);
  392. if (ret)
  393. goto out;
  394. } else {
  395. return -EOPNOTSUPP;
  396. }
  397. out:
  398. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  399. return ret;
  400. }
  401. static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
  402. struct iw_param *vwrq, char *extra)
  403. {
  404. struct lbs_private *priv = dev->priv;
  405. struct lbs_adapter *adapter = priv->adapter;
  406. int ret = 0;
  407. lbs_deb_enter(LBS_DEB_WEXT);
  408. adapter->txretrycount = 0;
  409. ret = lbs_prepare_and_send_command(priv,
  410. CMD_802_11_SNMP_MIB,
  411. CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
  412. OID_802_11_TX_RETRYCOUNT, NULL);
  413. if (ret)
  414. goto out;
  415. vwrq->disabled = 0;
  416. if (!vwrq->flags) {
  417. vwrq->flags = IW_RETRY_LIMIT;
  418. /* Subtract 1 to convert try count to retry count */
  419. vwrq->value = adapter->txretrycount - 1;
  420. }
  421. out:
  422. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  423. return ret;
  424. }
  425. static inline void sort_channels(struct iw_freq *freq, int num)
  426. {
  427. int i, j;
  428. struct iw_freq temp;
  429. for (i = 0; i < num; i++)
  430. for (j = i + 1; j < num; j++)
  431. if (freq[i].i > freq[j].i) {
  432. temp.i = freq[i].i;
  433. temp.m = freq[i].m;
  434. freq[i].i = freq[j].i;
  435. freq[i].m = freq[j].m;
  436. freq[j].i = temp.i;
  437. freq[j].m = temp.m;
  438. }
  439. }
  440. /* data rate listing
  441. MULTI_BANDS:
  442. abg a b b/g
  443. Infra G(12) A(8) B(4) G(12)
  444. Adhoc A+B(12) A(8) B(4) B(4)
  445. non-MULTI_BANDS:
  446. b b/g
  447. Infra B(4) G(12)
  448. Adhoc B(4) B(4)
  449. */
  450. /**
  451. * @brief Get Range Info
  452. *
  453. * @param dev A pointer to net_device structure
  454. * @param info A pointer to iw_request_info structure
  455. * @param vwrq A pointer to iw_param structure
  456. * @param extra A pointer to extra data buf
  457. * @return 0 --success, otherwise fail
  458. */
  459. static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
  460. struct iw_point *dwrq, char *extra)
  461. {
  462. int i, j;
  463. struct lbs_private *priv = dev->priv;
  464. struct lbs_adapter *adapter = priv->adapter;
  465. struct iw_range *range = (struct iw_range *)extra;
  466. struct chan_freq_power *cfp;
  467. u8 rates[MAX_RATES + 1];
  468. u8 flag = 0;
  469. lbs_deb_enter(LBS_DEB_WEXT);
  470. dwrq->length = sizeof(struct iw_range);
  471. memset(range, 0, sizeof(struct iw_range));
  472. range->min_nwid = 0;
  473. range->max_nwid = 0;
  474. memset(rates, 0, sizeof(rates));
  475. copy_active_data_rates(adapter, rates);
  476. range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
  477. for (i = 0; i < range->num_bitrates; i++)
  478. range->bitrate[i] = rates[i] * 500000;
  479. range->num_bitrates = i;
  480. lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
  481. range->num_bitrates);
  482. range->num_frequency = 0;
  483. if (priv->adapter->enable11d &&
  484. (adapter->connect_status == LBS_CONNECTED ||
  485. adapter->mesh_connect_status == LBS_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)lbs_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 < ARRAY_SIZE(adapter->region_channel)); j++) {
  512. cfp = adapter->region_channel[j].CFP;
  513. for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  514. && adapter->region_channel[j].valid
  515. && cfp
  516. && (i < adapter->region_channel[j].nrcfp); i++) {
  517. range->freq[range->num_frequency].i =
  518. (long)cfp->channel;
  519. range->freq[range->num_frequency].m =
  520. (long)cfp->freq * 100000;
  521. range->freq[range->num_frequency].e = 1;
  522. cfp++;
  523. range->num_frequency++;
  524. }
  525. }
  526. }
  527. lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
  528. IW_MAX_FREQUENCIES, range->num_frequency);
  529. range->num_channels = range->num_frequency;
  530. sort_channels(&range->freq[0], range->num_frequency);
  531. /*
  532. * Set an indication of the max TCP throughput in bit/s that we can
  533. * expect using this interface
  534. */
  535. if (i > 2)
  536. range->throughput = 5000 * 1000;
  537. else
  538. range->throughput = 1500 * 1000;
  539. range->min_rts = MRVDRV_RTS_MIN_VALUE;
  540. range->max_rts = MRVDRV_RTS_MAX_VALUE;
  541. range->min_frag = MRVDRV_FRAG_MIN_VALUE;
  542. range->max_frag = MRVDRV_FRAG_MAX_VALUE;
  543. range->encoding_size[0] = 5;
  544. range->encoding_size[1] = 13;
  545. range->num_encoding_sizes = 2;
  546. range->max_encoding_tokens = 4;
  547. range->min_pmp = 1000000;
  548. range->max_pmp = 120000000;
  549. range->min_pmt = 1000;
  550. range->max_pmt = 1000000;
  551. range->pmp_flags = IW_POWER_PERIOD;
  552. range->pmt_flags = IW_POWER_TIMEOUT;
  553. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
  554. /*
  555. * Minimum version we recommend
  556. */
  557. range->we_version_source = 15;
  558. /*
  559. * Version we are compiled with
  560. */
  561. range->we_version_compiled = WIRELESS_EXT;
  562. range->retry_capa = IW_RETRY_LIMIT;
  563. range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  564. range->min_retry = TX_RETRY_MIN;
  565. range->max_retry = TX_RETRY_MAX;
  566. /*
  567. * Set the qual, level and noise range values
  568. */
  569. range->max_qual.qual = 100;
  570. range->max_qual.level = 0;
  571. range->max_qual.noise = 0;
  572. range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  573. range->avg_qual.qual = 70;
  574. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  575. range->avg_qual.level = 0;
  576. range->avg_qual.noise = 0;
  577. range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  578. range->sensitivity = 0;
  579. /*
  580. * Setup the supported power level ranges
  581. */
  582. memset(range->txpower, 0, sizeof(range->txpower));
  583. range->txpower[0] = 5;
  584. range->txpower[1] = 7;
  585. range->txpower[2] = 9;
  586. range->txpower[3] = 11;
  587. range->txpower[4] = 13;
  588. range->txpower[5] = 15;
  589. range->txpower[6] = 17;
  590. range->txpower[7] = 19;
  591. range->num_txpower = 8;
  592. range->txpower_capa = IW_TXPOW_DBM;
  593. range->txpower_capa |= IW_TXPOW_RANGE;
  594. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  595. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  596. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  597. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  598. if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
  599. range->enc_capa = IW_ENC_CAPA_WPA
  600. | IW_ENC_CAPA_WPA2
  601. | IW_ENC_CAPA_CIPHER_TKIP
  602. | IW_ENC_CAPA_CIPHER_CCMP;
  603. }
  604. out:
  605. lbs_deb_leave(LBS_DEB_WEXT);
  606. return 0;
  607. }
  608. static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
  609. struct iw_param *vwrq, char *extra)
  610. {
  611. struct lbs_private *priv = dev->priv;
  612. struct lbs_adapter *adapter = priv->adapter;
  613. lbs_deb_enter(LBS_DEB_WEXT);
  614. /* PS is currently supported only in Infrastructure mode
  615. * Remove this check if it is to be supported in IBSS mode also
  616. */
  617. if (vwrq->disabled) {
  618. adapter->psmode = LBS802_11POWERMODECAM;
  619. if (adapter->psstate != PS_STATE_FULL_POWER) {
  620. lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
  621. }
  622. return 0;
  623. }
  624. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  625. lbs_deb_wext(
  626. "setting power timeout is not supported\n");
  627. return -EINVAL;
  628. } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
  629. lbs_deb_wext("setting power period not supported\n");
  630. return -EINVAL;
  631. }
  632. if (adapter->psmode != LBS802_11POWERMODECAM) {
  633. return 0;
  634. }
  635. adapter->psmode = LBS802_11POWERMODEMAX_PSP;
  636. if (adapter->connect_status == LBS_CONNECTED) {
  637. lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
  638. }
  639. lbs_deb_leave(LBS_DEB_WEXT);
  640. return 0;
  641. }
  642. static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
  643. struct iw_param *vwrq, char *extra)
  644. {
  645. struct lbs_private *priv = dev->priv;
  646. struct lbs_adapter *adapter = priv->adapter;
  647. int mode;
  648. lbs_deb_enter(LBS_DEB_WEXT);
  649. mode = adapter->psmode;
  650. if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
  651. || adapter->connect_status == LBS_DISCONNECTED)
  652. {
  653. goto out;
  654. }
  655. vwrq->value = 0;
  656. out:
  657. lbs_deb_leave(LBS_DEB_WEXT);
  658. return 0;
  659. }
  660. static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
  661. {
  662. enum {
  663. POOR = 30,
  664. FAIR = 60,
  665. GOOD = 80,
  666. VERY_GOOD = 90,
  667. EXCELLENT = 95,
  668. PERFECT = 100
  669. };
  670. struct lbs_private *priv = dev->priv;
  671. struct lbs_adapter *adapter = priv->adapter;
  672. u32 rssi_qual;
  673. u32 tx_qual;
  674. u32 quality = 0;
  675. int stats_valid = 0;
  676. u8 rssi;
  677. u32 tx_retries;
  678. lbs_deb_enter(LBS_DEB_WEXT);
  679. priv->wstats.status = adapter->mode;
  680. /* If we're not associated, all quality values are meaningless */
  681. if ((adapter->connect_status != LBS_CONNECTED) &&
  682. (adapter->mesh_connect_status != LBS_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. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  736. 0, 0, NULL);
  737. lbs_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 lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
  754. struct iw_freq *fwrq, char *extra)
  755. {
  756. int ret = -EINVAL;
  757. struct lbs_private *priv = dev->priv;
  758. struct lbs_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 = lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  793. } else {
  794. lbs_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 lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
  801. struct iw_param *vwrq, char *extra)
  802. {
  803. struct lbs_private *priv = dev->priv;
  804. struct lbs_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 = lbs_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 lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
  838. struct iw_param *vwrq, char *extra)
  839. {
  840. struct lbs_private *priv = dev->priv;
  841. struct lbs_adapter *adapter = priv->adapter;
  842. lbs_deb_enter(LBS_DEB_WEXT);
  843. if (adapter->connect_status == LBS_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 lbs_set_mode(struct net_device *dev,
  857. struct iw_request_info *info, u32 * uwrq, char *extra)
  858. {
  859. int ret = 0;
  860. struct lbs_private *priv = dev->priv;
  861. struct lbs_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 = lbs_get_association_request(adapter);
  873. if (!assoc_req) {
  874. ret = -ENOMEM;
  875. lbs_cancel_association_work(priv);
  876. } else {
  877. assoc_req->mode = *uwrq;
  878. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  879. lbs_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 lbs_get_encode(struct net_device *dev,
  897. struct iw_request_info *info,
  898. struct iw_point *dwrq, u8 * extra)
  899. {
  900. struct lbs_private *priv = dev->priv;
  901. struct lbs_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 lbs_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 lbs_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. struct lbs_private *priv = dev->priv;
  1066. struct lbs_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 = lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  1109. } else {
  1110. lbs_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 lbs_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. struct lbs_private *priv = dev->priv;
  1132. struct lbs_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 lbs_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. struct lbs_private *priv = dev->priv;
  1226. struct lbs_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 = lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  1319. } else {
  1320. lbs_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 lbs_set_genie(struct net_device *dev,
  1327. struct iw_request_info *info,
  1328. struct iw_point *dwrq,
  1329. char *extra)
  1330. {
  1331. struct lbs_private *priv = dev->priv;
  1332. struct lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  1358. } else {
  1359. lbs_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 lbs_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. struct lbs_private *priv = dev->priv;
  1372. struct lbs_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 lbs_set_auth(struct net_device *dev,
  1389. struct iw_request_info *info,
  1390. struct iw_param *dwrq,
  1391. char *extra)
  1392. {
  1393. struct lbs_private *priv = dev->priv;
  1394. struct lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  1470. } else if (ret != -EOPNOTSUPP) {
  1471. lbs_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 lbs_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. struct lbs_private *priv = dev->priv;
  1484. struct lbs_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 lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
  1510. struct iw_param *vwrq, char *extra)
  1511. {
  1512. int ret = 0;
  1513. struct lbs_private *priv = dev->priv;
  1514. struct lbs_adapter *adapter = priv->adapter;
  1515. u16 dbm;
  1516. lbs_deb_enter(LBS_DEB_WEXT);
  1517. if (vwrq->disabled) {
  1518. lbs_radio_ioctl(priv, RADIO_OFF);
  1519. return 0;
  1520. }
  1521. adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
  1522. lbs_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 = lbs_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 lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
  1541. struct iw_point *dwrq, char *extra)
  1542. {
  1543. struct lbs_private *priv = dev->priv;
  1544. struct lbs_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 == LBS_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 lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
  1570. struct iw_point *dwrq, char *extra)
  1571. {
  1572. struct lbs_private *priv = dev->priv;
  1573. struct lbs_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 = lbs_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. lbs_postpone_association_work(priv);
  1612. }
  1613. }
  1614. /* Cancel the association request if there was an error */
  1615. if (ret != 0) {
  1616. lbs_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 lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
  1632. struct sockaddr *awrq, char *extra)
  1633. {
  1634. struct lbs_private *priv = dev->priv;
  1635. struct lbs_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 = lbs_get_association_request(adapter);
  1646. if (!assoc_req) {
  1647. lbs_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. lbs_postpone_association_work(priv);
  1654. }
  1655. mutex_unlock(&adapter->lock);
  1656. return ret;
  1657. }
  1658. void lbs_get_fwversion(struct lbs_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 lbs_handler[] = {
  1680. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1681. (iw_handler) lbs_get_name, /* SIOCGIWNAME */
  1682. (iw_handler) NULL, /* SIOCSIWNWID */
  1683. (iw_handler) NULL, /* SIOCGIWNWID */
  1684. (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
  1685. (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
  1686. (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
  1687. (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
  1688. (iw_handler) NULL, /* SIOCSIWSENS */
  1689. (iw_handler) NULL, /* SIOCGIWSENS */
  1690. (iw_handler) NULL, /* SIOCSIWRANGE */
  1691. (iw_handler) lbs_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) lbs_set_wap, /* SIOCSIWAP */
  1701. (iw_handler) lbs_get_wap, /* SIOCGIWAP */
  1702. (iw_handler) NULL, /* SIOCSIWMLME */
  1703. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1704. (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
  1705. (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
  1706. (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
  1707. (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
  1708. (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
  1709. (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
  1710. (iw_handler) NULL, /* -- hole -- */
  1711. (iw_handler) NULL, /* -- hole -- */
  1712. (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
  1713. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1714. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1715. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1716. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1717. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1718. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1719. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1720. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1721. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1722. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1723. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1724. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1725. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1726. (iw_handler) NULL, /* -- hole -- */
  1727. (iw_handler) NULL, /* -- hole -- */
  1728. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1729. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1730. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1731. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1732. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1733. (iw_handler) lbs_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) lbs_get_name, /* SIOCGIWNAME */
  1739. (iw_handler) NULL, /* SIOCSIWNWID */
  1740. (iw_handler) NULL, /* SIOCGIWNWID */
  1741. (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
  1742. (iw_handler) lbs_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) lbs_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) lbs_set_scan, /* SIOCSIWSCAN */
  1762. (iw_handler) lbs_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) lbs_set_rate, /* SIOCSIWRATE */
  1770. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1771. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1772. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1773. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1774. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1775. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1776. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1777. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1778. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1779. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1780. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1781. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1782. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1783. (iw_handler) NULL, /* -- hole -- */
  1784. (iw_handler) NULL, /* -- hole -- */
  1785. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1786. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1787. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1788. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1789. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1790. (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
  1791. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1792. };
  1793. struct iw_handler_def lbs_handler_def = {
  1794. .num_standard = ARRAY_SIZE(lbs_handler),
  1795. .standard = (iw_handler *) lbs_handler,
  1796. .get_wireless_stats = lbs_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 = lbs_get_wireless_stats,
  1802. };