wext.c 56 KB

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