wext.c 56 KB

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