wext.c 54 KB

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