wext.c 55 KB

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