wext.c 54 KB

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