wext.c 57 KB

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