wext.c 56 KB

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