wext.c 56 KB

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