wext.c 55 KB

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