wext.c 55 KB

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