wext.c 56 KB

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