wext.c 59 KB

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