wext.c 55 KB

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