wext.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  1. /**
  2. * This file contains ioctl functions
  3. */
  4. #include <linux/ctype.h>
  5. #include <linux/delay.h>
  6. #include <linux/if.h>
  7. #include <linux/if_arp.h>
  8. #include <linux/wireless.h>
  9. #include <linux/bitops.h>
  10. #include <net/ieee80211.h>
  11. #include <net/iw_handler.h>
  12. #include "host.h"
  13. #include "radiotap.h"
  14. #include "decl.h"
  15. #include "defs.h"
  16. #include "dev.h"
  17. #include "join.h"
  18. #include "wext.h"
  19. #include "assoc.h"
  20. /**
  21. * the rates supported by the card
  22. */
  23. static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
  24. { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
  25. 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
  26. };
  27. /**
  28. * @brief Convert mw value to dbm value
  29. *
  30. * @param mw the value of mw
  31. * @return the value of dbm
  32. */
  33. static int mw_to_dbm(int mw)
  34. {
  35. if (mw < 2)
  36. return 0;
  37. else if (mw < 3)
  38. return 3;
  39. else if (mw < 4)
  40. return 5;
  41. else if (mw < 6)
  42. return 7;
  43. else if (mw < 7)
  44. return 8;
  45. else if (mw < 8)
  46. return 9;
  47. else if (mw < 10)
  48. return 10;
  49. else if (mw < 13)
  50. return 11;
  51. else if (mw < 16)
  52. return 12;
  53. else if (mw < 20)
  54. return 13;
  55. else if (mw < 25)
  56. return 14;
  57. else if (mw < 32)
  58. return 15;
  59. else if (mw < 40)
  60. return 16;
  61. else if (mw < 50)
  62. return 17;
  63. else if (mw < 63)
  64. return 18;
  65. else if (mw < 79)
  66. return 19;
  67. else if (mw < 100)
  68. return 20;
  69. else
  70. return 21;
  71. }
  72. /**
  73. * @brief Find the channel frequency power info with specific channel
  74. *
  75. * @param adapter A pointer to wlan_adapter structure
  76. * @param band it can be BAND_A, BAND_G or BAND_B
  77. * @param channel the channel for looking
  78. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  79. */
  80. struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
  81. u8 band, u16 channel)
  82. {
  83. struct chan_freq_power *cfp = NULL;
  84. struct region_channel *rc;
  85. int count = sizeof(adapter->region_channel) /
  86. sizeof(adapter->region_channel[0]);
  87. int i, j;
  88. for (j = 0; !cfp && (j < count); j++) {
  89. rc = &adapter->region_channel[j];
  90. if (adapter->enable11d)
  91. rc = &adapter->universal_channel[j];
  92. if (!rc->valid || !rc->CFP)
  93. continue;
  94. if (rc->band != band)
  95. continue;
  96. for (i = 0; i < rc->nrcfp; i++) {
  97. if (rc->CFP[i].channel == channel) {
  98. cfp = &rc->CFP[i];
  99. break;
  100. }
  101. }
  102. }
  103. if (!cfp && channel)
  104. lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
  105. "cfp by band %d / channel %d\n", band, channel);
  106. return cfp;
  107. }
  108. /**
  109. * @brief Find the channel frequency power info with specific frequency
  110. *
  111. * @param adapter A pointer to wlan_adapter structure
  112. * @param band it can be BAND_A, BAND_G or BAND_B
  113. * @param freq the frequency for looking
  114. * @return A pointer to struct chan_freq_power structure or NULL if not find.
  115. */
  116. static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
  117. u8 band, u32 freq)
  118. {
  119. struct chan_freq_power *cfp = NULL;
  120. struct region_channel *rc;
  121. int count = sizeof(adapter->region_channel) /
  122. sizeof(adapter->region_channel[0]);
  123. int i, j;
  124. for (j = 0; !cfp && (j < count); j++) {
  125. rc = &adapter->region_channel[j];
  126. if (adapter->enable11d)
  127. rc = &adapter->universal_channel[j];
  128. if (!rc->valid || !rc->CFP)
  129. continue;
  130. if (rc->band != band)
  131. continue;
  132. for (i = 0; i < rc->nrcfp; i++) {
  133. if (rc->CFP[i].freq == freq) {
  134. cfp = &rc->CFP[i];
  135. break;
  136. }
  137. }
  138. }
  139. if (!cfp && freq)
  140. lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
  141. "band %d / freq %d\n", band, freq);
  142. return cfp;
  143. }
  144. /**
  145. * @brief Set Radio On/OFF
  146. *
  147. * @param priv A pointer to wlan_private structure
  148. * @option Radio Option
  149. * @return 0 --success, otherwise fail
  150. */
  151. int wlan_radio_ioctl(wlan_private * priv, u8 option)
  152. {
  153. int ret = 0;
  154. wlan_adapter *adapter = priv->adapter;
  155. lbs_deb_enter(LBS_DEB_WEXT);
  156. if (adapter->radioon != option) {
  157. lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
  158. adapter->radioon = option;
  159. ret = libertas_prepare_and_send_command(priv,
  160. cmd_802_11_radio_control,
  161. cmd_act_set,
  162. cmd_option_waitforrsp, 0, NULL);
  163. }
  164. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  165. return ret;
  166. }
  167. /**
  168. * @brief Copy rates
  169. *
  170. * @param dest A pointer to Dest Buf
  171. * @param src A pointer to Src Buf
  172. * @param len The len of Src Buf
  173. * @return Number of rates copyed
  174. */
  175. static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
  176. {
  177. int i;
  178. for (i = 0; i < len && src[i]; i++, pos++) {
  179. if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
  180. break;
  181. dest[pos] = src[i];
  182. }
  183. return pos;
  184. }
  185. /**
  186. * @brief Get active data rates
  187. *
  188. * @param adapter A pointer to wlan_adapter structure
  189. * @param rate The buf to return the active rates
  190. * @return The number of rates
  191. */
  192. static int get_active_data_rates(wlan_adapter * adapter,
  193. u8* rates)
  194. {
  195. int k = 0;
  196. lbs_deb_enter(LBS_DEB_WEXT);
  197. if (adapter->connect_status != libertas_connected) {
  198. if (adapter->mode == IW_MODE_INFRA) {
  199. lbs_deb_wext("infra\n");
  200. k = copyrates(rates, k, libertas_supported_rates,
  201. sizeof(libertas_supported_rates));
  202. } else {
  203. lbs_deb_wext("Adhoc G\n");
  204. k = copyrates(rates, k, libertas_adhoc_rates_g,
  205. sizeof(libertas_adhoc_rates_g));
  206. }
  207. } else {
  208. k = copyrates(rates, 0, adapter->curbssparams.datarates,
  209. adapter->curbssparams.numofrates);
  210. }
  211. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
  212. return k;
  213. }
  214. static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
  215. char *cwrq, char *extra)
  216. {
  217. const char *cp;
  218. char comm[6] = { "COMM-" };
  219. char mrvl[6] = { "MRVL-" };
  220. int cnt;
  221. lbs_deb_enter(LBS_DEB_WEXT);
  222. strcpy(cwrq, mrvl);
  223. cp = strstr(libertas_driver_version, comm);
  224. if (cp == libertas_driver_version) //skip leading "COMM-"
  225. cp = libertas_driver_version + strlen(comm);
  226. else
  227. cp = libertas_driver_version;
  228. cnt = strlen(mrvl);
  229. cwrq += cnt;
  230. while (cnt < 16 && (*cp != '-')) {
  231. *cwrq++ = toupper(*cp++);
  232. cnt++;
  233. }
  234. *cwrq = '\0';
  235. lbs_deb_leave(LBS_DEB_WEXT);
  236. return 0;
  237. }
  238. static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
  239. struct iw_freq *fwrq, char *extra)
  240. {
  241. wlan_private *priv = dev->priv;
  242. wlan_adapter *adapter = priv->adapter;
  243. struct chan_freq_power *cfp;
  244. lbs_deb_enter(LBS_DEB_WEXT);
  245. cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
  246. adapter->curbssparams.channel);
  247. if (!cfp) {
  248. if (adapter->curbssparams.channel)
  249. lbs_deb_wext("invalid channel %d\n",
  250. adapter->curbssparams.channel);
  251. return -EINVAL;
  252. }
  253. fwrq->m = (long)cfp->freq * 100000;
  254. fwrq->e = 1;
  255. lbs_deb_wext("freq %u\n", fwrq->m);
  256. lbs_deb_leave(LBS_DEB_WEXT);
  257. return 0;
  258. }
  259. static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
  260. struct sockaddr *awrq, char *extra)
  261. {
  262. wlan_private *priv = dev->priv;
  263. wlan_adapter *adapter = priv->adapter;
  264. lbs_deb_enter(LBS_DEB_WEXT);
  265. if (adapter->connect_status == libertas_connected) {
  266. memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
  267. } else {
  268. memset(awrq->sa_data, 0, ETH_ALEN);
  269. }
  270. awrq->sa_family = ARPHRD_ETHER;
  271. lbs_deb_leave(LBS_DEB_WEXT);
  272. return 0;
  273. }
  274. static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
  275. struct iw_point *dwrq, char *extra)
  276. {
  277. wlan_private *priv = dev->priv;
  278. wlan_adapter *adapter = priv->adapter;
  279. lbs_deb_enter(LBS_DEB_WEXT);
  280. /*
  281. * Check the size of the string
  282. */
  283. if (dwrq->length > 16) {
  284. return -E2BIG;
  285. }
  286. mutex_lock(&adapter->lock);
  287. memset(adapter->nodename, 0, sizeof(adapter->nodename));
  288. memcpy(adapter->nodename, extra, dwrq->length);
  289. mutex_unlock(&adapter->lock);
  290. lbs_deb_leave(LBS_DEB_WEXT);
  291. return 0;
  292. }
  293. static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
  294. struct iw_point *dwrq, char *extra)
  295. {
  296. wlan_private *priv = dev->priv;
  297. wlan_adapter *adapter = priv->adapter;
  298. lbs_deb_enter(LBS_DEB_WEXT);
  299. /*
  300. * Get the Nick Name saved
  301. */
  302. mutex_lock(&adapter->lock);
  303. strncpy(extra, adapter->nodename, 16);
  304. mutex_unlock(&adapter->lock);
  305. extra[16] = '\0';
  306. /*
  307. * If none, we may want to get the one that was set
  308. */
  309. /*
  310. * Push it out !
  311. */
  312. dwrq->length = strlen(extra) + 1;
  313. lbs_deb_leave(LBS_DEB_WEXT);
  314. return 0;
  315. }
  316. static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
  317. struct iw_point *dwrq, char *extra)
  318. {
  319. wlan_private *priv = dev->priv;
  320. wlan_adapter *adapter = priv->adapter;
  321. lbs_deb_enter(LBS_DEB_WEXT);
  322. /* Use nickname to indicate that mesh is on */
  323. if (adapter->connect_status == libertas_connected) {
  324. strncpy(extra, "Mesh", 12);
  325. extra[12] = '\0';
  326. dwrq->length = strlen(extra) + 1;
  327. }
  328. else {
  329. extra[0] = '\0';
  330. dwrq->length = 1 ;
  331. }
  332. lbs_deb_leave(LBS_DEB_WEXT);
  333. return 0;
  334. }
  335. static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
  336. struct iw_param *vwrq, char *extra)
  337. {
  338. int ret = 0;
  339. wlan_private *priv = dev->priv;
  340. wlan_adapter *adapter = priv->adapter;
  341. int rthr = vwrq->value;
  342. lbs_deb_enter(LBS_DEB_WEXT);
  343. if (vwrq->disabled) {
  344. adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
  345. } else {
  346. if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
  347. return -EINVAL;
  348. adapter->rtsthsd = rthr;
  349. }
  350. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  351. cmd_act_set, cmd_option_waitforrsp,
  352. OID_802_11_RTS_THRESHOLD, &rthr);
  353. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  354. return ret;
  355. }
  356. static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
  357. struct iw_param *vwrq, char *extra)
  358. {
  359. int ret = 0;
  360. wlan_private *priv = dev->priv;
  361. wlan_adapter *adapter = priv->adapter;
  362. lbs_deb_enter(LBS_DEB_WEXT);
  363. adapter->rtsthsd = 0;
  364. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  365. cmd_act_get, cmd_option_waitforrsp,
  366. OID_802_11_RTS_THRESHOLD, NULL);
  367. if (ret)
  368. goto out;
  369. vwrq->value = adapter->rtsthsd;
  370. vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
  371. || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
  372. vwrq->fixed = 1;
  373. out:
  374. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  375. return ret;
  376. }
  377. static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
  378. struct iw_param *vwrq, char *extra)
  379. {
  380. int ret = 0;
  381. int fthr = vwrq->value;
  382. wlan_private *priv = dev->priv;
  383. wlan_adapter *adapter = priv->adapter;
  384. lbs_deb_enter(LBS_DEB_WEXT);
  385. if (vwrq->disabled) {
  386. adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
  387. } else {
  388. if (fthr < MRVDRV_FRAG_MIN_VALUE
  389. || fthr > MRVDRV_FRAG_MAX_VALUE)
  390. return -EINVAL;
  391. adapter->fragthsd = fthr;
  392. }
  393. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  394. cmd_act_set, cmd_option_waitforrsp,
  395. OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
  396. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  397. return ret;
  398. }
  399. static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
  400. struct iw_param *vwrq, char *extra)
  401. {
  402. int ret = 0;
  403. wlan_private *priv = dev->priv;
  404. wlan_adapter *adapter = priv->adapter;
  405. lbs_deb_enter(LBS_DEB_WEXT);
  406. adapter->fragthsd = 0;
  407. ret = libertas_prepare_and_send_command(priv,
  408. cmd_802_11_snmp_mib,
  409. cmd_act_get, cmd_option_waitforrsp,
  410. OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
  411. if (ret)
  412. goto out;
  413. vwrq->value = adapter->fragthsd;
  414. vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
  415. || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
  416. vwrq->fixed = 1;
  417. out:
  418. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  419. return ret;
  420. }
  421. static int wlan_get_mode(struct net_device *dev,
  422. struct iw_request_info *info, u32 * uwrq, char *extra)
  423. {
  424. wlan_private *priv = dev->priv;
  425. wlan_adapter *adapter = priv->adapter;
  426. lbs_deb_enter(LBS_DEB_WEXT);
  427. *uwrq = adapter->mode;
  428. lbs_deb_leave(LBS_DEB_WEXT);
  429. return 0;
  430. }
  431. static int mesh_wlan_get_mode(struct net_device *dev,
  432. struct iw_request_info *info, u32 * uwrq,
  433. char *extra)
  434. {
  435. lbs_deb_enter(LBS_DEB_WEXT);
  436. *uwrq = IW_MODE_REPEAT ;
  437. lbs_deb_leave(LBS_DEB_WEXT);
  438. return 0;
  439. }
  440. static int wlan_get_txpow(struct net_device *dev,
  441. struct iw_request_info *info,
  442. struct iw_param *vwrq, char *extra)
  443. {
  444. int ret = 0;
  445. wlan_private *priv = dev->priv;
  446. wlan_adapter *adapter = priv->adapter;
  447. lbs_deb_enter(LBS_DEB_WEXT);
  448. ret = libertas_prepare_and_send_command(priv,
  449. cmd_802_11_rf_tx_power,
  450. cmd_act_tx_power_opt_get,
  451. cmd_option_waitforrsp, 0, NULL);
  452. if (ret)
  453. goto out;
  454. lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
  455. vwrq->value = adapter->txpowerlevel;
  456. vwrq->fixed = 1;
  457. if (adapter->radioon) {
  458. vwrq->disabled = 0;
  459. vwrq->flags = IW_TXPOW_DBM;
  460. } else {
  461. vwrq->disabled = 1;
  462. }
  463. out:
  464. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  465. return ret;
  466. }
  467. static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
  468. struct iw_param *vwrq, char *extra)
  469. {
  470. int ret = 0;
  471. wlan_private *priv = dev->priv;
  472. wlan_adapter *adapter = priv->adapter;
  473. lbs_deb_enter(LBS_DEB_WEXT);
  474. if (vwrq->flags == IW_RETRY_LIMIT) {
  475. /* The MAC has a 4-bit Total_Tx_Count register
  476. Total_Tx_Count = 1 + Tx_Retry_Count */
  477. #define TX_RETRY_MIN 0
  478. #define TX_RETRY_MAX 14
  479. if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
  480. return -EINVAL;
  481. /* Adding 1 to convert retry count to try count */
  482. adapter->txretrycount = vwrq->value + 1;
  483. ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
  484. cmd_act_set,
  485. cmd_option_waitforrsp,
  486. OID_802_11_TX_RETRYCOUNT, NULL);
  487. if (ret)
  488. goto out;
  489. } else {
  490. return -EOPNOTSUPP;
  491. }
  492. out:
  493. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  494. return ret;
  495. }
  496. static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
  497. struct iw_param *vwrq, char *extra)
  498. {
  499. wlan_private *priv = dev->priv;
  500. wlan_adapter *adapter = priv->adapter;
  501. int ret = 0;
  502. lbs_deb_enter(LBS_DEB_WEXT);
  503. adapter->txretrycount = 0;
  504. ret = libertas_prepare_and_send_command(priv,
  505. cmd_802_11_snmp_mib,
  506. cmd_act_get, cmd_option_waitforrsp,
  507. OID_802_11_TX_RETRYCOUNT, NULL);
  508. if (ret)
  509. goto out;
  510. vwrq->disabled = 0;
  511. if (!vwrq->flags) {
  512. vwrq->flags = IW_RETRY_LIMIT;
  513. /* Subtract 1 to convert try count to retry count */
  514. vwrq->value = adapter->txretrycount - 1;
  515. }
  516. out:
  517. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  518. return ret;
  519. }
  520. static inline void sort_channels(struct iw_freq *freq, int num)
  521. {
  522. int i, j;
  523. struct iw_freq temp;
  524. for (i = 0; i < num; i++)
  525. for (j = i + 1; j < num; j++)
  526. if (freq[i].i > freq[j].i) {
  527. temp.i = freq[i].i;
  528. temp.m = freq[i].m;
  529. freq[i].i = freq[j].i;
  530. freq[i].m = freq[j].m;
  531. freq[j].i = temp.i;
  532. freq[j].m = temp.m;
  533. }
  534. }
  535. /* data rate listing
  536. MULTI_BANDS:
  537. abg a b b/g
  538. Infra G(12) A(8) B(4) G(12)
  539. Adhoc A+B(12) A(8) B(4) B(4)
  540. non-MULTI_BANDS:
  541. b b/g
  542. Infra B(4) G(12)
  543. Adhoc B(4) B(4)
  544. */
  545. /**
  546. * @brief Get Range Info
  547. *
  548. * @param dev A pointer to net_device structure
  549. * @param info A pointer to iw_request_info structure
  550. * @param vwrq A pointer to iw_param structure
  551. * @param extra A pointer to extra data buf
  552. * @return 0 --success, otherwise fail
  553. */
  554. static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
  555. struct iw_point *dwrq, char *extra)
  556. {
  557. int i, j;
  558. wlan_private *priv = dev->priv;
  559. wlan_adapter *adapter = priv->adapter;
  560. struct iw_range *range = (struct iw_range *)extra;
  561. struct chan_freq_power *cfp;
  562. u8 rates[WLAN_SUPPORTED_RATES];
  563. u8 flag = 0;
  564. lbs_deb_enter(LBS_DEB_WEXT);
  565. dwrq->length = sizeof(struct iw_range);
  566. memset(range, 0, sizeof(struct iw_range));
  567. range->min_nwid = 0;
  568. range->max_nwid = 0;
  569. memset(rates, 0, sizeof(rates));
  570. range->num_bitrates = get_active_data_rates(adapter, rates);
  571. for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
  572. i++) {
  573. range->bitrate[i] = (rates[i] & 0x7f) * 500000;
  574. }
  575. range->num_bitrates = i;
  576. lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
  577. range->num_bitrates);
  578. range->num_frequency = 0;
  579. if (priv->adapter->enable11d &&
  580. adapter->connect_status == libertas_connected) {
  581. u8 chan_no;
  582. u8 band;
  583. struct parsed_region_chan_11d *parsed_region_chan =
  584. &adapter->parsed_region_chan;
  585. if (parsed_region_chan == NULL) {
  586. lbs_deb_wext("11d: parsed_region_chan is NULL\n");
  587. goto out;
  588. }
  589. band = parsed_region_chan->band;
  590. lbs_deb_wext("band %d, nr_char %d\n", band,
  591. parsed_region_chan->nr_chan);
  592. for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  593. && (i < parsed_region_chan->nr_chan); i++) {
  594. chan_no = parsed_region_chan->chanpwr[i].chan;
  595. lbs_deb_wext("chan_no %d\n", chan_no);
  596. range->freq[range->num_frequency].i = (long)chan_no;
  597. range->freq[range->num_frequency].m =
  598. (long)libertas_chan_2_freq(chan_no, band) * 100000;
  599. range->freq[range->num_frequency].e = 1;
  600. range->num_frequency++;
  601. }
  602. flag = 1;
  603. }
  604. if (!flag) {
  605. for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  606. && (j < sizeof(adapter->region_channel)
  607. / sizeof(adapter->region_channel[0])); j++) {
  608. cfp = adapter->region_channel[j].CFP;
  609. for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
  610. && adapter->region_channel[j].valid
  611. && cfp
  612. && (i < adapter->region_channel[j].nrcfp); i++) {
  613. range->freq[range->num_frequency].i =
  614. (long)cfp->channel;
  615. range->freq[range->num_frequency].m =
  616. (long)cfp->freq * 100000;
  617. range->freq[range->num_frequency].e = 1;
  618. cfp++;
  619. range->num_frequency++;
  620. }
  621. }
  622. }
  623. lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
  624. IW_MAX_FREQUENCIES, range->num_frequency);
  625. range->num_channels = range->num_frequency;
  626. sort_channels(&range->freq[0], range->num_frequency);
  627. /*
  628. * Set an indication of the max TCP throughput in bit/s that we can
  629. * expect using this interface
  630. */
  631. if (i > 2)
  632. range->throughput = 5000 * 1000;
  633. else
  634. range->throughput = 1500 * 1000;
  635. range->min_rts = MRVDRV_RTS_MIN_VALUE;
  636. range->max_rts = MRVDRV_RTS_MAX_VALUE;
  637. range->min_frag = MRVDRV_FRAG_MIN_VALUE;
  638. range->max_frag = MRVDRV_FRAG_MAX_VALUE;
  639. range->encoding_size[0] = 5;
  640. range->encoding_size[1] = 13;
  641. range->num_encoding_sizes = 2;
  642. range->max_encoding_tokens = 4;
  643. range->min_pmp = 1000000;
  644. range->max_pmp = 120000000;
  645. range->min_pmt = 1000;
  646. range->max_pmt = 1000000;
  647. range->pmp_flags = IW_POWER_PERIOD;
  648. range->pmt_flags = IW_POWER_TIMEOUT;
  649. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
  650. /*
  651. * Minimum version we recommend
  652. */
  653. range->we_version_source = 15;
  654. /*
  655. * Version we are compiled with
  656. */
  657. range->we_version_compiled = WIRELESS_EXT;
  658. range->retry_capa = IW_RETRY_LIMIT;
  659. range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  660. range->min_retry = TX_RETRY_MIN;
  661. range->max_retry = TX_RETRY_MAX;
  662. /*
  663. * Set the qual, level and noise range values
  664. */
  665. range->max_qual.qual = 100;
  666. range->max_qual.level = 0;
  667. range->max_qual.noise = 0;
  668. range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  669. range->avg_qual.qual = 70;
  670. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  671. range->avg_qual.level = 0;
  672. range->avg_qual.noise = 0;
  673. range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  674. range->sensitivity = 0;
  675. /*
  676. * Setup the supported power level ranges
  677. */
  678. memset(range->txpower, 0, sizeof(range->txpower));
  679. range->txpower[0] = 5;
  680. range->txpower[1] = 7;
  681. range->txpower[2] = 9;
  682. range->txpower[3] = 11;
  683. range->txpower[4] = 13;
  684. range->txpower[5] = 15;
  685. range->txpower[6] = 17;
  686. range->txpower[7] = 19;
  687. range->num_txpower = 8;
  688. range->txpower_capa = IW_TXPOW_DBM;
  689. range->txpower_capa |= IW_TXPOW_RANGE;
  690. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  691. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  692. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  693. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  694. if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
  695. range->enc_capa = IW_ENC_CAPA_WPA
  696. | IW_ENC_CAPA_WPA2
  697. | IW_ENC_CAPA_CIPHER_TKIP
  698. | IW_ENC_CAPA_CIPHER_CCMP;
  699. }
  700. out:
  701. lbs_deb_leave(LBS_DEB_WEXT);
  702. return 0;
  703. }
  704. static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
  705. struct iw_param *vwrq, char *extra)
  706. {
  707. wlan_private *priv = dev->priv;
  708. wlan_adapter *adapter = priv->adapter;
  709. lbs_deb_enter(LBS_DEB_WEXT);
  710. /* PS is currently supported only in Infrastructure mode
  711. * Remove this check if it is to be supported in IBSS mode also
  712. */
  713. if (vwrq->disabled) {
  714. adapter->psmode = wlan802_11powermodecam;
  715. if (adapter->psstate != PS_STATE_FULL_POWER) {
  716. libertas_ps_wakeup(priv, cmd_option_waitforrsp);
  717. }
  718. return 0;
  719. }
  720. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  721. lbs_deb_wext(
  722. "setting power timeout is not supported\n");
  723. return -EINVAL;
  724. } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
  725. lbs_deb_wext("setting power period not supported\n");
  726. return -EINVAL;
  727. }
  728. if (adapter->psmode != wlan802_11powermodecam) {
  729. return 0;
  730. }
  731. adapter->psmode = wlan802_11powermodemax_psp;
  732. if (adapter->connect_status == libertas_connected) {
  733. libertas_ps_sleep(priv, cmd_option_waitforrsp);
  734. }
  735. lbs_deb_leave(LBS_DEB_WEXT);
  736. return 0;
  737. }
  738. static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
  739. struct iw_param *vwrq, char *extra)
  740. {
  741. wlan_private *priv = dev->priv;
  742. wlan_adapter *adapter = priv->adapter;
  743. int mode;
  744. lbs_deb_enter(LBS_DEB_WEXT);
  745. mode = adapter->psmode;
  746. if ((vwrq->disabled = (mode == wlan802_11powermodecam))
  747. || adapter->connect_status == libertas_disconnected)
  748. {
  749. goto out;
  750. }
  751. vwrq->value = 0;
  752. out:
  753. lbs_deb_leave(LBS_DEB_WEXT);
  754. return 0;
  755. }
  756. /*
  757. * iwpriv settable callbacks
  758. */
  759. static const iw_handler wlan_private_handler[] = {
  760. NULL, /* SIOCIWFIRSTPRIV */
  761. };
  762. static const struct iw_priv_args wlan_private_args[] = {
  763. /*
  764. * { cmd, set_args, get_args, name }
  765. */
  766. /* Using iwpriv sub-command feature */
  767. {
  768. WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
  769. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  770. IW_PRIV_TYPE_NONE,
  771. ""},
  772. {
  773. WLANSETREGION,
  774. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  775. IW_PRIV_TYPE_NONE,
  776. "setregioncode"},
  777. {
  778. WLAN_SUBCMD_MESH_SET_TTL,
  779. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  780. IW_PRIV_TYPE_NONE,
  781. "mesh_set_ttl"},
  782. {
  783. WLAN_SETNONE_GETONEINT,
  784. IW_PRIV_TYPE_NONE,
  785. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  786. ""},
  787. {
  788. WLANGETREGION,
  789. IW_PRIV_TYPE_NONE,
  790. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  791. "getregioncode"},
  792. {
  793. WLAN_SUBCMD_FWT_CLEANUP,
  794. IW_PRIV_TYPE_NONE,
  795. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  796. "fwt_cleanup"},
  797. {
  798. WLAN_SUBCMD_FWT_TIME,
  799. IW_PRIV_TYPE_NONE,
  800. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  801. "fwt_time"},
  802. {
  803. WLAN_SUBCMD_MESH_GET_TTL,
  804. IW_PRIV_TYPE_NONE,
  805. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  806. "mesh_get_ttl"},
  807. {
  808. WLAN_SETNONE_GETNONE,
  809. IW_PRIV_TYPE_NONE,
  810. IW_PRIV_TYPE_NONE,
  811. ""},
  812. {
  813. WLAN_SUBCMD_FWT_RESET,
  814. IW_PRIV_TYPE_NONE,
  815. IW_PRIV_TYPE_NONE,
  816. "fwt_reset"},
  817. {
  818. WLAN_SUBCMD_BT_RESET,
  819. IW_PRIV_TYPE_NONE,
  820. IW_PRIV_TYPE_NONE,
  821. "bt_reset"},
  822. {
  823. WLAN_SET128CHAR_GET128CHAR,
  824. IW_PRIV_TYPE_CHAR | 128,
  825. IW_PRIV_TYPE_CHAR | 128,
  826. ""},
  827. /* BT Management */
  828. {
  829. WLAN_SUBCMD_BT_ADD,
  830. IW_PRIV_TYPE_CHAR | 128,
  831. IW_PRIV_TYPE_CHAR | 128,
  832. "bt_add"},
  833. {
  834. WLAN_SUBCMD_BT_DEL,
  835. IW_PRIV_TYPE_CHAR | 128,
  836. IW_PRIV_TYPE_CHAR | 128,
  837. "bt_del"},
  838. {
  839. WLAN_SUBCMD_BT_LIST,
  840. IW_PRIV_TYPE_CHAR | 128,
  841. IW_PRIV_TYPE_CHAR | 128,
  842. "bt_list"},
  843. {
  844. WLAN_SUBCMD_BT_SET_INVERT,
  845. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  846. IW_PRIV_TYPE_NONE,
  847. "bt_set_invert"},
  848. {
  849. WLAN_SUBCMD_BT_GET_INVERT,
  850. IW_PRIV_TYPE_NONE,
  851. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  852. "bt_get_invert"},
  853. /* FWT Management */
  854. {
  855. WLAN_SUBCMD_FWT_ADD,
  856. IW_PRIV_TYPE_CHAR | 128,
  857. IW_PRIV_TYPE_CHAR | 128,
  858. "fwt_add"},
  859. {
  860. WLAN_SUBCMD_FWT_DEL,
  861. IW_PRIV_TYPE_CHAR | 128,
  862. IW_PRIV_TYPE_CHAR | 128,
  863. "fwt_del"},
  864. {
  865. WLAN_SUBCMD_FWT_LOOKUP,
  866. IW_PRIV_TYPE_CHAR | 128,
  867. IW_PRIV_TYPE_CHAR | 128,
  868. "fwt_lookup"},
  869. {
  870. WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
  871. IW_PRIV_TYPE_CHAR | 128,
  872. IW_PRIV_TYPE_CHAR | 128,
  873. "fwt_list_neigh"},
  874. {
  875. WLAN_SUBCMD_FWT_LIST,
  876. IW_PRIV_TYPE_CHAR | 128,
  877. IW_PRIV_TYPE_CHAR | 128,
  878. "fwt_list"},
  879. {
  880. WLAN_SUBCMD_FWT_LIST_ROUTE,
  881. IW_PRIV_TYPE_CHAR | 128,
  882. IW_PRIV_TYPE_CHAR | 128,
  883. "fwt_list_route"},
  884. {
  885. WLAN_SET_GET_SIXTEEN_INT,
  886. IW_PRIV_TYPE_INT | 16,
  887. IW_PRIV_TYPE_INT | 16,
  888. ""},
  889. {
  890. WLAN_LED_GPIO_CTRL,
  891. IW_PRIV_TYPE_INT | 16,
  892. IW_PRIV_TYPE_INT | 16,
  893. "ledgpio"},
  894. };
  895. static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
  896. {
  897. enum {
  898. POOR = 30,
  899. FAIR = 60,
  900. GOOD = 80,
  901. VERY_GOOD = 90,
  902. EXCELLENT = 95,
  903. PERFECT = 100
  904. };
  905. wlan_private *priv = dev->priv;
  906. wlan_adapter *adapter = priv->adapter;
  907. u32 rssi_qual;
  908. u32 tx_qual;
  909. u32 quality = 0;
  910. int stats_valid = 0;
  911. u8 rssi;
  912. u32 tx_retries;
  913. lbs_deb_enter(LBS_DEB_WEXT);
  914. priv->wstats.status = adapter->mode;
  915. /* If we're not associated, all quality values are meaningless */
  916. if (adapter->connect_status != libertas_connected)
  917. goto out;
  918. /* Quality by RSSI */
  919. priv->wstats.qual.level =
  920. CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
  921. adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  922. if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  923. priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  924. } else {
  925. priv->wstats.qual.noise =
  926. CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
  927. }
  928. lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
  929. lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
  930. rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
  931. if (rssi < 15)
  932. rssi_qual = rssi * POOR / 10;
  933. else if (rssi < 20)
  934. rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
  935. else if (rssi < 30)
  936. rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
  937. else if (rssi < 40)
  938. rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
  939. 10 + GOOD;
  940. else
  941. rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
  942. 10 + VERY_GOOD;
  943. quality = rssi_qual;
  944. /* Quality by TX errors */
  945. priv->wstats.discard.retries = priv->stats.tx_errors;
  946. tx_retries = adapter->logmsg.retry;
  947. if (tx_retries > 75)
  948. tx_qual = (90 - tx_retries) * POOR / 15;
  949. else if (tx_retries > 70)
  950. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  951. else if (tx_retries > 65)
  952. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  953. else if (tx_retries > 50)
  954. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  955. 15 + GOOD;
  956. else
  957. tx_qual = (50 - tx_retries) *
  958. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  959. quality = min(quality, tx_qual);
  960. priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
  961. priv->wstats.discard.fragment = adapter->logmsg.rxfrag;
  962. priv->wstats.discard.retries = tx_retries;
  963. priv->wstats.discard.misc = adapter->logmsg.ackfailure;
  964. /* Calculate quality */
  965. priv->wstats.qual.qual = max(quality, (u32)100);
  966. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  967. stats_valid = 1;
  968. /* update stats asynchronously for future calls */
  969. libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
  970. 0, 0, NULL);
  971. libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
  972. 0, 0, NULL);
  973. out:
  974. if (!stats_valid) {
  975. priv->wstats.miss.beacon = 0;
  976. priv->wstats.discard.retries = 0;
  977. priv->wstats.qual.qual = 0;
  978. priv->wstats.qual.level = 0;
  979. priv->wstats.qual.noise = 0;
  980. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
  981. priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
  982. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  983. }
  984. lbs_deb_leave(LBS_DEB_WEXT);
  985. return &priv->wstats;
  986. }
  987. static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
  988. struct iw_freq *fwrq, char *extra)
  989. {
  990. int ret = -EINVAL;
  991. wlan_private *priv = dev->priv;
  992. wlan_adapter *adapter = priv->adapter;
  993. struct chan_freq_power *cfp;
  994. struct assoc_request * assoc_req;
  995. lbs_deb_enter(LBS_DEB_WEXT);
  996. mutex_lock(&adapter->lock);
  997. assoc_req = wlan_get_association_request(adapter);
  998. if (!assoc_req) {
  999. ret = -ENOMEM;
  1000. goto out;
  1001. }
  1002. /* If setting by frequency, convert to a channel */
  1003. if (fwrq->e == 1) {
  1004. long f = fwrq->m / 100000;
  1005. cfp = find_cfp_by_band_and_freq(adapter, 0, f);
  1006. if (!cfp) {
  1007. lbs_deb_wext("invalid freq %ld\n", f);
  1008. goto out;
  1009. }
  1010. fwrq->e = 0;
  1011. fwrq->m = (int) cfp->channel;
  1012. }
  1013. /* Setting by channel number */
  1014. if (fwrq->m > 1000 || fwrq->e > 0) {
  1015. goto out;
  1016. }
  1017. cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
  1018. if (!cfp) {
  1019. goto out;
  1020. }
  1021. assoc_req->channel = fwrq->m;
  1022. ret = 0;
  1023. out:
  1024. if (ret == 0) {
  1025. set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
  1026. wlan_postpone_association_work(priv);
  1027. } else {
  1028. wlan_cancel_association_work(priv);
  1029. }
  1030. mutex_unlock(&adapter->lock);
  1031. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1032. return ret;
  1033. }
  1034. /**
  1035. * @brief use index to get the data rate
  1036. *
  1037. * @param index The index of data rate
  1038. * @return data rate or 0
  1039. */
  1040. u32 libertas_index_to_data_rate(u8 index)
  1041. {
  1042. if (index >= sizeof(libertas_wlan_data_rates))
  1043. index = 0;
  1044. return libertas_wlan_data_rates[index];
  1045. }
  1046. /**
  1047. * @brief use rate to get the index
  1048. *
  1049. * @param rate data rate
  1050. * @return index or 0
  1051. */
  1052. u8 libertas_data_rate_to_index(u32 rate)
  1053. {
  1054. u8 *ptr;
  1055. if (rate)
  1056. if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
  1057. sizeof(libertas_wlan_data_rates))))
  1058. return (ptr - libertas_wlan_data_rates);
  1059. return 0;
  1060. }
  1061. static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
  1062. struct iw_param *vwrq, char *extra)
  1063. {
  1064. wlan_private *priv = dev->priv;
  1065. wlan_adapter *adapter = priv->adapter;
  1066. u32 data_rate;
  1067. u16 action;
  1068. int ret = 0;
  1069. u8 rates[WLAN_SUPPORTED_RATES];
  1070. u8 *rate;
  1071. lbs_deb_enter(LBS_DEB_WEXT);
  1072. lbs_deb_wext("vwrq->value %d\n", vwrq->value);
  1073. if (vwrq->value == -1) {
  1074. action = cmd_act_set_tx_auto; // Auto
  1075. adapter->is_datarate_auto = 1;
  1076. adapter->datarate = 0;
  1077. } else {
  1078. if (vwrq->value % 100000) {
  1079. return -EINVAL;
  1080. }
  1081. data_rate = vwrq->value / 500000;
  1082. memset(rates, 0, sizeof(rates));
  1083. get_active_data_rates(adapter, rates);
  1084. rate = rates;
  1085. while (*rate) {
  1086. lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
  1087. data_rate);
  1088. if ((*rate & 0x7f) == (data_rate & 0x7f))
  1089. break;
  1090. rate++;
  1091. }
  1092. if (!*rate) {
  1093. lbs_pr_alert("fixed data rate 0x%X out "
  1094. "of range\n", data_rate);
  1095. return -EINVAL;
  1096. }
  1097. adapter->datarate = data_rate;
  1098. action = cmd_act_set_tx_fix_rate;
  1099. adapter->is_datarate_auto = 0;
  1100. }
  1101. ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
  1102. action, cmd_option_waitforrsp, 0, NULL);
  1103. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1104. return ret;
  1105. }
  1106. static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
  1107. struct iw_param *vwrq, char *extra)
  1108. {
  1109. wlan_private *priv = dev->priv;
  1110. wlan_adapter *adapter = priv->adapter;
  1111. lbs_deb_enter(LBS_DEB_WEXT);
  1112. if (adapter->is_datarate_auto) {
  1113. vwrq->fixed = 0;
  1114. } else {
  1115. vwrq->fixed = 1;
  1116. }
  1117. vwrq->value = adapter->datarate * 500000;
  1118. lbs_deb_leave(LBS_DEB_WEXT);
  1119. return 0;
  1120. }
  1121. static int wlan_set_mode(struct net_device *dev,
  1122. struct iw_request_info *info, u32 * uwrq, char *extra)
  1123. {
  1124. int ret = 0;
  1125. wlan_private *priv = dev->priv;
  1126. wlan_adapter *adapter = priv->adapter;
  1127. struct assoc_request * assoc_req;
  1128. lbs_deb_enter(LBS_DEB_WEXT);
  1129. if ( (*uwrq != IW_MODE_ADHOC)
  1130. && (*uwrq != IW_MODE_INFRA)
  1131. && (*uwrq != IW_MODE_AUTO)) {
  1132. lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
  1133. ret = -EINVAL;
  1134. goto out;
  1135. }
  1136. mutex_lock(&adapter->lock);
  1137. assoc_req = wlan_get_association_request(adapter);
  1138. if (!assoc_req) {
  1139. ret = -ENOMEM;
  1140. wlan_cancel_association_work(priv);
  1141. } else {
  1142. assoc_req->mode = *uwrq;
  1143. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  1144. wlan_postpone_association_work(priv);
  1145. lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
  1146. }
  1147. mutex_unlock(&adapter->lock);
  1148. out:
  1149. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1150. return ret;
  1151. }
  1152. /**
  1153. * @brief Get Encryption key
  1154. *
  1155. * @param dev A pointer to net_device structure
  1156. * @param info A pointer to iw_request_info structure
  1157. * @param vwrq A pointer to iw_param structure
  1158. * @param extra A pointer to extra data buf
  1159. * @return 0 --success, otherwise fail
  1160. */
  1161. static int wlan_get_encode(struct net_device *dev,
  1162. struct iw_request_info *info,
  1163. struct iw_point *dwrq, u8 * extra)
  1164. {
  1165. wlan_private *priv = dev->priv;
  1166. wlan_adapter *adapter = priv->adapter;
  1167. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  1168. lbs_deb_enter(LBS_DEB_WEXT);
  1169. lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
  1170. dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
  1171. dwrq->flags = 0;
  1172. /* Authentication method */
  1173. switch (adapter->secinfo.auth_mode) {
  1174. case IW_AUTH_ALG_OPEN_SYSTEM:
  1175. dwrq->flags = IW_ENCODE_OPEN;
  1176. break;
  1177. case IW_AUTH_ALG_SHARED_KEY:
  1178. case IW_AUTH_ALG_LEAP:
  1179. dwrq->flags = IW_ENCODE_RESTRICTED;
  1180. break;
  1181. default:
  1182. dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
  1183. break;
  1184. }
  1185. if ( adapter->secinfo.wep_enabled
  1186. || adapter->secinfo.WPAenabled
  1187. || adapter->secinfo.WPA2enabled) {
  1188. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1189. } else {
  1190. dwrq->flags |= IW_ENCODE_DISABLED;
  1191. }
  1192. memset(extra, 0, 16);
  1193. mutex_lock(&adapter->lock);
  1194. /* Default to returning current transmit key */
  1195. if (index < 0)
  1196. index = adapter->wep_tx_keyidx;
  1197. if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
  1198. memcpy(extra, adapter->wep_keys[index].key,
  1199. adapter->wep_keys[index].len);
  1200. dwrq->length = adapter->wep_keys[index].len;
  1201. dwrq->flags |= (index + 1);
  1202. /* Return WEP enabled */
  1203. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1204. } else if ((adapter->secinfo.WPAenabled)
  1205. || (adapter->secinfo.WPA2enabled)) {
  1206. /* return WPA enabled */
  1207. dwrq->flags &= ~IW_ENCODE_DISABLED;
  1208. } else {
  1209. dwrq->flags |= IW_ENCODE_DISABLED;
  1210. }
  1211. mutex_unlock(&adapter->lock);
  1212. dwrq->flags |= IW_ENCODE_NOKEY;
  1213. lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
  1214. extra[0], extra[1], extra[2],
  1215. extra[3], extra[4], extra[5], dwrq->length);
  1216. lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
  1217. lbs_deb_leave(LBS_DEB_WEXT);
  1218. return 0;
  1219. }
  1220. /**
  1221. * @brief Set Encryption key (internal)
  1222. *
  1223. * @param priv A pointer to private card structure
  1224. * @param key_material A pointer to key material
  1225. * @param key_length length of key material
  1226. * @param index key index to set
  1227. * @param set_tx_key Force set TX key (1 = yes, 0 = no)
  1228. * @return 0 --success, otherwise fail
  1229. */
  1230. static int wlan_set_wep_key(struct assoc_request *assoc_req,
  1231. const char *key_material,
  1232. u16 key_length,
  1233. u16 index,
  1234. int set_tx_key)
  1235. {
  1236. int ret = 0;
  1237. struct WLAN_802_11_KEY *pkey;
  1238. lbs_deb_enter(LBS_DEB_WEXT);
  1239. /* Paranoid validation of key index */
  1240. if (index > 3) {
  1241. ret = -EINVAL;
  1242. goto out;
  1243. }
  1244. /* validate max key length */
  1245. if (key_length > KEY_LEN_WEP_104) {
  1246. ret = -EINVAL;
  1247. goto out;
  1248. }
  1249. pkey = &assoc_req->wep_keys[index];
  1250. if (key_length > 0) {
  1251. memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
  1252. pkey->type = KEY_TYPE_ID_WEP;
  1253. /* Standardize the key length */
  1254. pkey->len = (key_length > KEY_LEN_WEP_40) ?
  1255. KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
  1256. memcpy(pkey->key, key_material, key_length);
  1257. }
  1258. if (set_tx_key) {
  1259. /* Ensure the chosen key is valid */
  1260. if (!pkey->len) {
  1261. lbs_deb_wext("key not set, so cannot enable it\n");
  1262. ret = -EINVAL;
  1263. goto out;
  1264. }
  1265. assoc_req->wep_tx_keyidx = index;
  1266. }
  1267. assoc_req->secinfo.wep_enabled = 1;
  1268. out:
  1269. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1270. return ret;
  1271. }
  1272. static int validate_key_index(u16 def_index, u16 raw_index,
  1273. u16 *out_index, u16 *is_default)
  1274. {
  1275. if (!out_index || !is_default)
  1276. return -EINVAL;
  1277. /* Verify index if present, otherwise use default TX key index */
  1278. if (raw_index > 0) {
  1279. if (raw_index > 4)
  1280. return -EINVAL;
  1281. *out_index = raw_index - 1;
  1282. } else {
  1283. *out_index = def_index;
  1284. *is_default = 1;
  1285. }
  1286. return 0;
  1287. }
  1288. static void disable_wep(struct assoc_request *assoc_req)
  1289. {
  1290. int i;
  1291. lbs_deb_enter(LBS_DEB_WEXT);
  1292. /* Set Open System auth mode */
  1293. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1294. /* Clear WEP keys and mark WEP as disabled */
  1295. assoc_req->secinfo.wep_enabled = 0;
  1296. for (i = 0; i < 4; i++)
  1297. assoc_req->wep_keys[i].len = 0;
  1298. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1299. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1300. lbs_deb_leave(LBS_DEB_WEXT);
  1301. }
  1302. static void disable_wpa(struct assoc_request *assoc_req)
  1303. {
  1304. lbs_deb_enter(LBS_DEB_WEXT);
  1305. memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct WLAN_802_11_KEY));
  1306. assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
  1307. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1308. memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct WLAN_802_11_KEY));
  1309. assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
  1310. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1311. assoc_req->secinfo.WPAenabled = 0;
  1312. assoc_req->secinfo.WPA2enabled = 0;
  1313. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1314. lbs_deb_leave(LBS_DEB_WEXT);
  1315. }
  1316. /**
  1317. * @brief Set Encryption key
  1318. *
  1319. * @param dev A pointer to net_device structure
  1320. * @param info A pointer to iw_request_info structure
  1321. * @param vwrq A pointer to iw_param structure
  1322. * @param extra A pointer to extra data buf
  1323. * @return 0 --success, otherwise fail
  1324. */
  1325. static int wlan_set_encode(struct net_device *dev,
  1326. struct iw_request_info *info,
  1327. struct iw_point *dwrq, char *extra)
  1328. {
  1329. int ret = 0;
  1330. wlan_private *priv = dev->priv;
  1331. wlan_adapter *adapter = priv->adapter;
  1332. struct assoc_request * assoc_req;
  1333. u16 is_default = 0, index = 0, set_tx_key = 0;
  1334. lbs_deb_enter(LBS_DEB_WEXT);
  1335. mutex_lock(&adapter->lock);
  1336. assoc_req = wlan_get_association_request(adapter);
  1337. if (!assoc_req) {
  1338. ret = -ENOMEM;
  1339. goto out;
  1340. }
  1341. if (dwrq->flags & IW_ENCODE_DISABLED) {
  1342. disable_wep (assoc_req);
  1343. disable_wpa (assoc_req);
  1344. goto out;
  1345. }
  1346. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1347. (dwrq->flags & IW_ENCODE_INDEX),
  1348. &index, &is_default);
  1349. if (ret) {
  1350. ret = -EINVAL;
  1351. goto out;
  1352. }
  1353. /* If WEP isn't enabled, or if there is no key data but a valid
  1354. * index, set the TX key.
  1355. */
  1356. if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
  1357. set_tx_key = 1;
  1358. ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
  1359. if (ret)
  1360. goto out;
  1361. if (dwrq->length)
  1362. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1363. if (set_tx_key)
  1364. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1365. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1366. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1367. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1368. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1369. }
  1370. out:
  1371. if (ret == 0) {
  1372. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1373. wlan_postpone_association_work(priv);
  1374. } else {
  1375. wlan_cancel_association_work(priv);
  1376. }
  1377. mutex_unlock(&adapter->lock);
  1378. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1379. return ret;
  1380. }
  1381. /**
  1382. * @brief Get Extended Encryption key (WPA/802.1x and WEP)
  1383. *
  1384. * @param dev A pointer to net_device structure
  1385. * @param info A pointer to iw_request_info structure
  1386. * @param vwrq A pointer to iw_param structure
  1387. * @param extra A pointer to extra data buf
  1388. * @return 0 on success, otherwise failure
  1389. */
  1390. static int wlan_get_encodeext(struct net_device *dev,
  1391. struct iw_request_info *info,
  1392. struct iw_point *dwrq,
  1393. char *extra)
  1394. {
  1395. int ret = -EINVAL;
  1396. wlan_private *priv = dev->priv;
  1397. wlan_adapter *adapter = priv->adapter;
  1398. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1399. int index, max_key_len;
  1400. lbs_deb_enter(LBS_DEB_WEXT);
  1401. max_key_len = dwrq->length - sizeof(*ext);
  1402. if (max_key_len < 0)
  1403. goto out;
  1404. index = dwrq->flags & IW_ENCODE_INDEX;
  1405. if (index) {
  1406. if (index < 1 || index > 4)
  1407. goto out;
  1408. index--;
  1409. } else {
  1410. index = adapter->wep_tx_keyidx;
  1411. }
  1412. if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
  1413. ext->alg != IW_ENCODE_ALG_WEP) {
  1414. if (index != 0 || adapter->mode != IW_MODE_INFRA)
  1415. goto out;
  1416. }
  1417. dwrq->flags = index + 1;
  1418. memset(ext, 0, sizeof(*ext));
  1419. if ( !adapter->secinfo.wep_enabled
  1420. && !adapter->secinfo.WPAenabled
  1421. && !adapter->secinfo.WPA2enabled) {
  1422. ext->alg = IW_ENCODE_ALG_NONE;
  1423. ext->key_len = 0;
  1424. dwrq->flags |= IW_ENCODE_DISABLED;
  1425. } else {
  1426. u8 *key = NULL;
  1427. if ( adapter->secinfo.wep_enabled
  1428. && !adapter->secinfo.WPAenabled
  1429. && !adapter->secinfo.WPA2enabled) {
  1430. /* WEP */
  1431. ext->alg = IW_ENCODE_ALG_WEP;
  1432. ext->key_len = adapter->wep_keys[index].len;
  1433. key = &adapter->wep_keys[index].key[0];
  1434. } else if ( !adapter->secinfo.wep_enabled
  1435. && (adapter->secinfo.WPAenabled ||
  1436. adapter->secinfo.WPA2enabled)) {
  1437. /* WPA */
  1438. struct WLAN_802_11_KEY * pkey = NULL;
  1439. if ( adapter->wpa_mcast_key.len
  1440. && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
  1441. pkey = &adapter->wpa_mcast_key;
  1442. else if ( adapter->wpa_unicast_key.len
  1443. && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
  1444. pkey = &adapter->wpa_unicast_key;
  1445. if (pkey) {
  1446. if (pkey->type == KEY_TYPE_ID_AES) {
  1447. ext->alg = IW_ENCODE_ALG_CCMP;
  1448. } else {
  1449. ext->alg = IW_ENCODE_ALG_TKIP;
  1450. }
  1451. ext->key_len = pkey->len;
  1452. key = &pkey->key[0];
  1453. } else {
  1454. ext->alg = IW_ENCODE_ALG_TKIP;
  1455. ext->key_len = 0;
  1456. }
  1457. } else {
  1458. goto out;
  1459. }
  1460. if (ext->key_len > max_key_len) {
  1461. ret = -E2BIG;
  1462. goto out;
  1463. }
  1464. if (ext->key_len)
  1465. memcpy(ext->key, key, ext->key_len);
  1466. else
  1467. dwrq->flags |= IW_ENCODE_NOKEY;
  1468. dwrq->flags |= IW_ENCODE_ENABLED;
  1469. }
  1470. ret = 0;
  1471. out:
  1472. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1473. return ret;
  1474. }
  1475. /**
  1476. * @brief Set Encryption key Extended (WPA/802.1x and WEP)
  1477. *
  1478. * @param dev A pointer to net_device structure
  1479. * @param info A pointer to iw_request_info structure
  1480. * @param vwrq A pointer to iw_param structure
  1481. * @param extra A pointer to extra data buf
  1482. * @return 0 --success, otherwise fail
  1483. */
  1484. static int wlan_set_encodeext(struct net_device *dev,
  1485. struct iw_request_info *info,
  1486. struct iw_point *dwrq,
  1487. char *extra)
  1488. {
  1489. int ret = 0;
  1490. wlan_private *priv = dev->priv;
  1491. wlan_adapter *adapter = priv->adapter;
  1492. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1493. int alg = ext->alg;
  1494. struct assoc_request * assoc_req;
  1495. lbs_deb_enter(LBS_DEB_WEXT);
  1496. mutex_lock(&adapter->lock);
  1497. assoc_req = wlan_get_association_request(adapter);
  1498. if (!assoc_req) {
  1499. ret = -ENOMEM;
  1500. goto out;
  1501. }
  1502. if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
  1503. disable_wep (assoc_req);
  1504. disable_wpa (assoc_req);
  1505. } else if (alg == IW_ENCODE_ALG_WEP) {
  1506. u16 is_default = 0, index, set_tx_key = 0;
  1507. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1508. (dwrq->flags & IW_ENCODE_INDEX),
  1509. &index, &is_default);
  1510. if (ret)
  1511. goto out;
  1512. /* If WEP isn't enabled, or if there is no key data but a valid
  1513. * index, or if the set-TX-key flag was passed, set the TX key.
  1514. */
  1515. if ( !assoc_req->secinfo.wep_enabled
  1516. || (dwrq->length == 0 && !is_default)
  1517. || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
  1518. set_tx_key = 1;
  1519. /* Copy key to driver */
  1520. ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
  1521. set_tx_key);
  1522. if (ret)
  1523. goto out;
  1524. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1525. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1526. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1527. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1528. }
  1529. /* Mark the various WEP bits as modified */
  1530. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1531. if (dwrq->length)
  1532. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1533. if (set_tx_key)
  1534. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1535. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1536. struct WLAN_802_11_KEY * pkey;
  1537. /* validate key length */
  1538. if (((alg == IW_ENCODE_ALG_TKIP)
  1539. && (ext->key_len != KEY_LEN_WPA_TKIP))
  1540. || ((alg == IW_ENCODE_ALG_CCMP)
  1541. && (ext->key_len != KEY_LEN_WPA_AES))) {
  1542. lbs_deb_wext("invalid size %d for key of alg"
  1543. "type %d\n",
  1544. ext->key_len,
  1545. alg);
  1546. ret = -EINVAL;
  1547. goto out;
  1548. }
  1549. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1550. pkey = &assoc_req->wpa_mcast_key;
  1551. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1552. } else {
  1553. pkey = &assoc_req->wpa_unicast_key;
  1554. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1555. }
  1556. memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
  1557. memcpy(pkey->key, ext->key, ext->key_len);
  1558. pkey->len = ext->key_len;
  1559. if (pkey->len)
  1560. pkey->flags |= KEY_INFO_WPA_ENABLED;
  1561. /* Do this after zeroing key structure */
  1562. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1563. pkey->flags |= KEY_INFO_WPA_MCAST;
  1564. } else {
  1565. pkey->flags |= KEY_INFO_WPA_UNICAST;
  1566. }
  1567. if (alg == IW_ENCODE_ALG_TKIP) {
  1568. pkey->type = KEY_TYPE_ID_TKIP;
  1569. } else if (alg == IW_ENCODE_ALG_CCMP) {
  1570. pkey->type = KEY_TYPE_ID_AES;
  1571. } else {
  1572. ret = -EINVAL;
  1573. goto out;
  1574. }
  1575. /* If WPA isn't enabled yet, do that now */
  1576. if ( assoc_req->secinfo.WPAenabled == 0
  1577. && assoc_req->secinfo.WPA2enabled == 0) {
  1578. assoc_req->secinfo.WPAenabled = 1;
  1579. assoc_req->secinfo.WPA2enabled = 1;
  1580. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1581. }
  1582. disable_wep (assoc_req);
  1583. }
  1584. out:
  1585. if (ret == 0) {
  1586. wlan_postpone_association_work(priv);
  1587. } else {
  1588. wlan_cancel_association_work(priv);
  1589. }
  1590. mutex_unlock(&adapter->lock);
  1591. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1592. return ret;
  1593. }
  1594. static int wlan_set_genie(struct net_device *dev,
  1595. struct iw_request_info *info,
  1596. struct iw_point *dwrq,
  1597. char *extra)
  1598. {
  1599. wlan_private *priv = dev->priv;
  1600. wlan_adapter *adapter = priv->adapter;
  1601. int ret = 0;
  1602. struct assoc_request * assoc_req;
  1603. lbs_deb_enter(LBS_DEB_WEXT);
  1604. mutex_lock(&adapter->lock);
  1605. assoc_req = wlan_get_association_request(adapter);
  1606. if (!assoc_req) {
  1607. ret = -ENOMEM;
  1608. goto out;
  1609. }
  1610. if (dwrq->length > MAX_WPA_IE_LEN ||
  1611. (dwrq->length && extra == NULL)) {
  1612. ret = -EINVAL;
  1613. goto out;
  1614. }
  1615. if (dwrq->length) {
  1616. memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
  1617. assoc_req->wpa_ie_len = dwrq->length;
  1618. } else {
  1619. memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
  1620. assoc_req->wpa_ie_len = 0;
  1621. }
  1622. out:
  1623. if (ret == 0) {
  1624. set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
  1625. wlan_postpone_association_work(priv);
  1626. } else {
  1627. wlan_cancel_association_work(priv);
  1628. }
  1629. mutex_unlock(&adapter->lock);
  1630. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1631. return ret;
  1632. }
  1633. static int wlan_get_genie(struct net_device *dev,
  1634. struct iw_request_info *info,
  1635. struct iw_point *dwrq,
  1636. char *extra)
  1637. {
  1638. int ret = 0;
  1639. wlan_private *priv = dev->priv;
  1640. wlan_adapter *adapter = priv->adapter;
  1641. lbs_deb_enter(LBS_DEB_WEXT);
  1642. if (adapter->wpa_ie_len == 0) {
  1643. dwrq->length = 0;
  1644. goto out;
  1645. }
  1646. if (dwrq->length < adapter->wpa_ie_len) {
  1647. ret = -E2BIG;
  1648. goto out;
  1649. }
  1650. dwrq->length = adapter->wpa_ie_len;
  1651. memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
  1652. out:
  1653. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1654. return ret;
  1655. }
  1656. static int wlan_set_auth(struct net_device *dev,
  1657. struct iw_request_info *info,
  1658. struct iw_param *dwrq,
  1659. char *extra)
  1660. {
  1661. wlan_private *priv = dev->priv;
  1662. wlan_adapter *adapter = priv->adapter;
  1663. struct assoc_request * assoc_req;
  1664. int ret = 0;
  1665. int updated = 0;
  1666. lbs_deb_enter(LBS_DEB_WEXT);
  1667. mutex_lock(&adapter->lock);
  1668. assoc_req = wlan_get_association_request(adapter);
  1669. if (!assoc_req) {
  1670. ret = -ENOMEM;
  1671. goto out;
  1672. }
  1673. switch (dwrq->flags & IW_AUTH_INDEX) {
  1674. case IW_AUTH_TKIP_COUNTERMEASURES:
  1675. case IW_AUTH_CIPHER_PAIRWISE:
  1676. case IW_AUTH_CIPHER_GROUP:
  1677. case IW_AUTH_KEY_MGMT:
  1678. case IW_AUTH_DROP_UNENCRYPTED:
  1679. /*
  1680. * libertas does not use these parameters
  1681. */
  1682. break;
  1683. case IW_AUTH_WPA_VERSION:
  1684. if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
  1685. assoc_req->secinfo.WPAenabled = 0;
  1686. assoc_req->secinfo.WPA2enabled = 0;
  1687. disable_wpa (assoc_req);
  1688. }
  1689. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
  1690. assoc_req->secinfo.WPAenabled = 1;
  1691. assoc_req->secinfo.wep_enabled = 0;
  1692. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1693. }
  1694. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
  1695. assoc_req->secinfo.WPA2enabled = 1;
  1696. assoc_req->secinfo.wep_enabled = 0;
  1697. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1698. }
  1699. updated = 1;
  1700. break;
  1701. case IW_AUTH_80211_AUTH_ALG:
  1702. if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
  1703. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1704. } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  1705. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1706. } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
  1707. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
  1708. } else {
  1709. ret = -EINVAL;
  1710. }
  1711. updated = 1;
  1712. break;
  1713. case IW_AUTH_WPA_ENABLED:
  1714. if (dwrq->value) {
  1715. if (!assoc_req->secinfo.WPAenabled &&
  1716. !assoc_req->secinfo.WPA2enabled) {
  1717. assoc_req->secinfo.WPAenabled = 1;
  1718. assoc_req->secinfo.WPA2enabled = 1;
  1719. assoc_req->secinfo.wep_enabled = 0;
  1720. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1721. }
  1722. } else {
  1723. assoc_req->secinfo.WPAenabled = 0;
  1724. assoc_req->secinfo.WPA2enabled = 0;
  1725. disable_wpa (assoc_req);
  1726. }
  1727. updated = 1;
  1728. break;
  1729. default:
  1730. ret = -EOPNOTSUPP;
  1731. break;
  1732. }
  1733. out:
  1734. if (ret == 0) {
  1735. if (updated)
  1736. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1737. wlan_postpone_association_work(priv);
  1738. } else if (ret != -EOPNOTSUPP) {
  1739. wlan_cancel_association_work(priv);
  1740. }
  1741. mutex_unlock(&adapter->lock);
  1742. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1743. return ret;
  1744. }
  1745. static int wlan_get_auth(struct net_device *dev,
  1746. struct iw_request_info *info,
  1747. struct iw_param *dwrq,
  1748. char *extra)
  1749. {
  1750. int ret = 0;
  1751. wlan_private *priv = dev->priv;
  1752. wlan_adapter *adapter = priv->adapter;
  1753. lbs_deb_enter(LBS_DEB_WEXT);
  1754. switch (dwrq->flags & IW_AUTH_INDEX) {
  1755. case IW_AUTH_WPA_VERSION:
  1756. dwrq->value = 0;
  1757. if (adapter->secinfo.WPAenabled)
  1758. dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
  1759. if (adapter->secinfo.WPA2enabled)
  1760. dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
  1761. if (!dwrq->value)
  1762. dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
  1763. break;
  1764. case IW_AUTH_80211_AUTH_ALG:
  1765. dwrq->value = adapter->secinfo.auth_mode;
  1766. break;
  1767. case IW_AUTH_WPA_ENABLED:
  1768. if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
  1769. dwrq->value = 1;
  1770. break;
  1771. default:
  1772. ret = -EOPNOTSUPP;
  1773. }
  1774. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1775. return ret;
  1776. }
  1777. static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
  1778. struct iw_param *vwrq, char *extra)
  1779. {
  1780. int ret = 0;
  1781. wlan_private *priv = dev->priv;
  1782. wlan_adapter *adapter = priv->adapter;
  1783. u16 dbm;
  1784. lbs_deb_enter(LBS_DEB_WEXT);
  1785. if (vwrq->disabled) {
  1786. wlan_radio_ioctl(priv, RADIO_OFF);
  1787. return 0;
  1788. }
  1789. adapter->preamble = cmd_type_auto_preamble;
  1790. wlan_radio_ioctl(priv, RADIO_ON);
  1791. if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
  1792. dbm = (u16) mw_to_dbm(vwrq->value);
  1793. } else
  1794. dbm = (u16) vwrq->value;
  1795. /* auto tx power control */
  1796. if (vwrq->fixed == 0)
  1797. dbm = 0xffff;
  1798. lbs_deb_wext("txpower set %d dbm\n", dbm);
  1799. ret = libertas_prepare_and_send_command(priv,
  1800. cmd_802_11_rf_tx_power,
  1801. cmd_act_tx_power_opt_set_low,
  1802. cmd_option_waitforrsp, 0, (void *)&dbm);
  1803. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1804. return ret;
  1805. }
  1806. static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
  1807. struct iw_point *dwrq, char *extra)
  1808. {
  1809. wlan_private *priv = dev->priv;
  1810. wlan_adapter *adapter = priv->adapter;
  1811. lbs_deb_enter(LBS_DEB_WEXT);
  1812. /*
  1813. * Note : if dwrq->flags != 0, we should get the relevant SSID from
  1814. * the SSID list...
  1815. */
  1816. /*
  1817. * Get the current SSID
  1818. */
  1819. if (adapter->connect_status == libertas_connected) {
  1820. memcpy(extra, adapter->curbssparams.ssid.ssid,
  1821. adapter->curbssparams.ssid.ssidlength);
  1822. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  1823. } else {
  1824. memset(extra, 0, 32);
  1825. extra[adapter->curbssparams.ssid.ssidlength] = '\0';
  1826. }
  1827. /*
  1828. * If none, we may want to get the one that was set
  1829. */
  1830. /* To make the driver backward compatible with WPA supplicant v0.2.4 */
  1831. if (dwrq->length == 32) /* check with WPA supplicant buffer size */
  1832. dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
  1833. IW_ESSID_MAX_SIZE);
  1834. else
  1835. dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
  1836. dwrq->flags = 1; /* active */
  1837. lbs_deb_leave(LBS_DEB_WEXT);
  1838. return 0;
  1839. }
  1840. static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
  1841. struct iw_point *dwrq, char *extra)
  1842. {
  1843. wlan_private *priv = dev->priv;
  1844. wlan_adapter *adapter = priv->adapter;
  1845. int ret = 0;
  1846. struct WLAN_802_11_SSID ssid;
  1847. struct assoc_request * assoc_req;
  1848. int ssid_len = dwrq->length;
  1849. lbs_deb_enter(LBS_DEB_WEXT);
  1850. /*
  1851. * WE-20 and earlier NULL pad the end of the SSID and increment
  1852. * SSID length so it can be used like a string. WE-21 and later don't,
  1853. * but some userspace tools aren't able to cope with the change.
  1854. */
  1855. if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
  1856. ssid_len--;
  1857. /* Check the size of the string */
  1858. if (ssid_len > IW_ESSID_MAX_SIZE) {
  1859. ret = -E2BIG;
  1860. goto out;
  1861. }
  1862. memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
  1863. if (!dwrq->flags || !ssid_len) {
  1864. /* "any" SSID requested; leave SSID blank */
  1865. } else {
  1866. /* Specific SSID requested */
  1867. memcpy(&ssid.ssid, extra, ssid_len);
  1868. ssid.ssidlength = ssid_len;
  1869. }
  1870. lbs_deb_wext("requested new SSID '%s'\n",
  1871. (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
  1872. out:
  1873. mutex_lock(&adapter->lock);
  1874. if (ret == 0) {
  1875. /* Get or create the current association request */
  1876. assoc_req = wlan_get_association_request(adapter);
  1877. if (!assoc_req) {
  1878. ret = -ENOMEM;
  1879. } else {
  1880. /* Copy the SSID to the association request */
  1881. memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
  1882. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  1883. wlan_postpone_association_work(priv);
  1884. }
  1885. }
  1886. /* Cancel the association request if there was an error */
  1887. if (ret != 0) {
  1888. wlan_cancel_association_work(priv);
  1889. }
  1890. mutex_unlock(&adapter->lock);
  1891. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1892. return ret;
  1893. }
  1894. /**
  1895. * @brief Connect to the AP or Ad-hoc Network with specific bssid
  1896. *
  1897. * @param dev A pointer to net_device structure
  1898. * @param info A pointer to iw_request_info structure
  1899. * @param awrq A pointer to iw_param structure
  1900. * @param extra A pointer to extra data buf
  1901. * @return 0 --success, otherwise fail
  1902. */
  1903. static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
  1904. struct sockaddr *awrq, char *extra)
  1905. {
  1906. wlan_private *priv = dev->priv;
  1907. wlan_adapter *adapter = priv->adapter;
  1908. struct assoc_request * assoc_req;
  1909. int ret = 0;
  1910. lbs_deb_enter(LBS_DEB_WEXT);
  1911. if (awrq->sa_family != ARPHRD_ETHER)
  1912. return -EINVAL;
  1913. lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
  1914. mutex_lock(&adapter->lock);
  1915. /* Get or create the current association request */
  1916. assoc_req = wlan_get_association_request(adapter);
  1917. if (!assoc_req) {
  1918. wlan_cancel_association_work(priv);
  1919. ret = -ENOMEM;
  1920. } else {
  1921. /* Copy the BSSID to the association request */
  1922. memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
  1923. set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
  1924. wlan_postpone_association_work(priv);
  1925. }
  1926. mutex_unlock(&adapter->lock);
  1927. return ret;
  1928. }
  1929. void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
  1930. {
  1931. union {
  1932. u32 l;
  1933. u8 c[4];
  1934. } ver;
  1935. char fwver[32];
  1936. mutex_lock(&adapter->lock);
  1937. ver.l = adapter->fwreleasenumber;
  1938. mutex_unlock(&adapter->lock);
  1939. if (ver.c[3] == 0)
  1940. sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
  1941. else
  1942. sprintf(fwver, "%u.%u.%u.p%u",
  1943. ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
  1944. snprintf(fwversion, maxlen, fwver);
  1945. }
  1946. /*
  1947. * iwconfig settable callbacks
  1948. */
  1949. static const iw_handler wlan_handler[] = {
  1950. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1951. (iw_handler) wlan_get_name, /* SIOCGIWNAME */
  1952. (iw_handler) NULL, /* SIOCSIWNWID */
  1953. (iw_handler) NULL, /* SIOCGIWNWID */
  1954. (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
  1955. (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
  1956. (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
  1957. (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
  1958. (iw_handler) NULL, /* SIOCSIWSENS */
  1959. (iw_handler) NULL, /* SIOCGIWSENS */
  1960. (iw_handler) NULL, /* SIOCSIWRANGE */
  1961. (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
  1962. (iw_handler) NULL, /* SIOCSIWPRIV */
  1963. (iw_handler) NULL, /* SIOCGIWPRIV */
  1964. (iw_handler) NULL, /* SIOCSIWSTATS */
  1965. (iw_handler) NULL, /* SIOCGIWSTATS */
  1966. iw_handler_set_spy, /* SIOCSIWSPY */
  1967. iw_handler_get_spy, /* SIOCGIWSPY */
  1968. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1969. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1970. (iw_handler) wlan_set_wap, /* SIOCSIWAP */
  1971. (iw_handler) wlan_get_wap, /* SIOCGIWAP */
  1972. (iw_handler) NULL, /* SIOCSIWMLME */
  1973. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1974. (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
  1975. (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
  1976. (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
  1977. (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
  1978. (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
  1979. (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
  1980. (iw_handler) NULL, /* -- hole -- */
  1981. (iw_handler) NULL, /* -- hole -- */
  1982. (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
  1983. (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
  1984. (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
  1985. (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
  1986. (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
  1987. (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
  1988. (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
  1989. (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
  1990. (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
  1991. (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
  1992. (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
  1993. (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
  1994. (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
  1995. (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
  1996. (iw_handler) NULL, /* -- hole -- */
  1997. (iw_handler) NULL, /* -- hole -- */
  1998. (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
  1999. (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
  2000. (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
  2001. (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
  2002. (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
  2003. (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
  2004. (iw_handler) NULL, /* SIOCSIWPMKSA */
  2005. };
  2006. static const iw_handler mesh_wlan_handler[] = {
  2007. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  2008. (iw_handler) wlan_get_name, /* SIOCGIWNAME */
  2009. (iw_handler) NULL, /* SIOCSIWNWID */
  2010. (iw_handler) NULL, /* SIOCGIWNWID */
  2011. (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
  2012. (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
  2013. (iw_handler) NULL, /* SIOCSIWMODE */
  2014. (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
  2015. (iw_handler) NULL, /* SIOCSIWSENS */
  2016. (iw_handler) NULL, /* SIOCGIWSENS */
  2017. (iw_handler) NULL, /* SIOCSIWRANGE */
  2018. (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
  2019. (iw_handler) NULL, /* SIOCSIWPRIV */
  2020. (iw_handler) NULL, /* SIOCGIWPRIV */
  2021. (iw_handler) NULL, /* SIOCSIWSTATS */
  2022. (iw_handler) NULL, /* SIOCGIWSTATS */
  2023. iw_handler_set_spy, /* SIOCSIWSPY */
  2024. iw_handler_get_spy, /* SIOCGIWSPY */
  2025. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2026. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2027. (iw_handler) NULL, /* SIOCSIWAP */
  2028. (iw_handler) NULL, /* SIOCGIWAP */
  2029. (iw_handler) NULL, /* SIOCSIWMLME */
  2030. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  2031. (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
  2032. (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
  2033. (iw_handler) NULL, /* SIOCSIWESSID */
  2034. (iw_handler) NULL, /* SIOCGIWESSID */
  2035. (iw_handler) NULL, /* SIOCSIWNICKN */
  2036. (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
  2037. (iw_handler) NULL, /* -- hole -- */
  2038. (iw_handler) NULL, /* -- hole -- */
  2039. (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
  2040. (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
  2041. (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
  2042. (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
  2043. (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
  2044. (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
  2045. (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
  2046. (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
  2047. (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
  2048. (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
  2049. (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
  2050. (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
  2051. (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
  2052. (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
  2053. (iw_handler) NULL, /* -- hole -- */
  2054. (iw_handler) NULL, /* -- hole -- */
  2055. (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
  2056. (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
  2057. (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
  2058. (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
  2059. (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
  2060. (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
  2061. (iw_handler) NULL, /* SIOCSIWPMKSA */
  2062. };
  2063. struct iw_handler_def libertas_handler_def = {
  2064. .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
  2065. .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
  2066. .num_private_args = sizeof(wlan_private_args) /
  2067. sizeof(struct iw_priv_args),
  2068. .standard = (iw_handler *) wlan_handler,
  2069. .private = (iw_handler *) wlan_private_handler,
  2070. .private_args = (struct iw_priv_args *)wlan_private_args,
  2071. .get_wireless_stats = wlan_get_wireless_stats,
  2072. };
  2073. struct iw_handler_def mesh_handler_def = {
  2074. .num_standard = sizeof(mesh_wlan_handler) / sizeof(iw_handler),
  2075. .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
  2076. .num_private_args = sizeof(wlan_private_args) /
  2077. sizeof(struct iw_priv_args),
  2078. .standard = (iw_handler *) mesh_wlan_handler,
  2079. .private = (iw_handler *) wlan_private_handler,
  2080. .private_args = (struct iw_priv_args *)wlan_private_args,
  2081. .get_wireless_stats = wlan_get_wireless_stats,
  2082. };