wext.c 54 KB

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