wext.c 54 KB

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