wext.c 55 KB

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