wext.c 57 KB

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