wext.c 54 KB

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