wext.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213
  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 "join.h"
  18. #include "wext.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. 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, band) * 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. range->min_pmp = 1000000;
  534. range->max_pmp = 120000000;
  535. range->min_pmt = 1000;
  536. range->max_pmt = 1000000;
  537. range->pmp_flags = IW_POWER_PERIOD;
  538. range->pmt_flags = IW_POWER_TIMEOUT;
  539. range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
  540. /*
  541. * Minimum version we recommend
  542. */
  543. range->we_version_source = 15;
  544. /*
  545. * Version we are compiled with
  546. */
  547. range->we_version_compiled = WIRELESS_EXT;
  548. range->retry_capa = IW_RETRY_LIMIT;
  549. range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  550. range->min_retry = TX_RETRY_MIN;
  551. range->max_retry = TX_RETRY_MAX;
  552. /*
  553. * Set the qual, level and noise range values
  554. */
  555. range->max_qual.qual = 100;
  556. range->max_qual.level = 0;
  557. range->max_qual.noise = 0;
  558. range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  559. range->avg_qual.qual = 70;
  560. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  561. range->avg_qual.level = 0;
  562. range->avg_qual.noise = 0;
  563. range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  564. range->sensitivity = 0;
  565. /*
  566. * Setup the supported power level ranges
  567. */
  568. memset(range->txpower, 0, sizeof(range->txpower));
  569. range->txpower[0] = 5;
  570. range->txpower[1] = 7;
  571. range->txpower[2] = 9;
  572. range->txpower[3] = 11;
  573. range->txpower[4] = 13;
  574. range->txpower[5] = 15;
  575. range->txpower[6] = 17;
  576. range->txpower[7] = 19;
  577. range->num_txpower = 8;
  578. range->txpower_capa = IW_TXPOW_DBM;
  579. range->txpower_capa |= IW_TXPOW_RANGE;
  580. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  581. IW_EVENT_CAPA_MASK(SIOCGIWAP) |
  582. IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
  583. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  584. if (priv->fwcapinfo & FW_CAPINFO_WPA) {
  585. range->enc_capa = IW_ENC_CAPA_WPA
  586. | IW_ENC_CAPA_WPA2
  587. | IW_ENC_CAPA_CIPHER_TKIP
  588. | IW_ENC_CAPA_CIPHER_CCMP;
  589. }
  590. out:
  591. lbs_deb_leave(LBS_DEB_WEXT);
  592. return 0;
  593. }
  594. static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
  595. struct iw_param *vwrq, char *extra)
  596. {
  597. struct lbs_private *priv = dev->priv;
  598. lbs_deb_enter(LBS_DEB_WEXT);
  599. if (!priv->ps_supported) {
  600. if (vwrq->disabled)
  601. return 0;
  602. else
  603. return -EINVAL;
  604. }
  605. /* PS is currently supported only in Infrastructure mode
  606. * Remove this check if it is to be supported in IBSS mode also
  607. */
  608. if (vwrq->disabled) {
  609. priv->psmode = LBS802_11POWERMODECAM;
  610. if (priv->psstate != PS_STATE_FULL_POWER) {
  611. lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
  612. }
  613. return 0;
  614. }
  615. if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  616. lbs_deb_wext(
  617. "setting power timeout is not supported\n");
  618. return -EINVAL;
  619. } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
  620. lbs_deb_wext("setting power period not supported\n");
  621. return -EINVAL;
  622. }
  623. if (priv->psmode != LBS802_11POWERMODECAM) {
  624. return 0;
  625. }
  626. priv->psmode = LBS802_11POWERMODEMAX_PSP;
  627. if (priv->connect_status == LBS_CONNECTED) {
  628. lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
  629. }
  630. lbs_deb_leave(LBS_DEB_WEXT);
  631. return 0;
  632. }
  633. static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
  634. struct iw_param *vwrq, char *extra)
  635. {
  636. struct lbs_private *priv = dev->priv;
  637. int mode;
  638. lbs_deb_enter(LBS_DEB_WEXT);
  639. mode = priv->psmode;
  640. if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
  641. || priv->connect_status == LBS_DISCONNECTED)
  642. {
  643. goto out;
  644. }
  645. vwrq->value = 0;
  646. out:
  647. lbs_deb_leave(LBS_DEB_WEXT);
  648. return 0;
  649. }
  650. static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
  651. {
  652. enum {
  653. POOR = 30,
  654. FAIR = 60,
  655. GOOD = 80,
  656. VERY_GOOD = 90,
  657. EXCELLENT = 95,
  658. PERFECT = 100
  659. };
  660. struct lbs_private *priv = dev->priv;
  661. u32 rssi_qual;
  662. u32 tx_qual;
  663. u32 quality = 0;
  664. int stats_valid = 0;
  665. u8 rssi;
  666. u32 tx_retries;
  667. lbs_deb_enter(LBS_DEB_WEXT);
  668. priv->wstats.status = priv->mode;
  669. /* If we're not associated, all quality values are meaningless */
  670. if ((priv->connect_status != LBS_CONNECTED) &&
  671. (priv->mesh_connect_status != LBS_CONNECTED))
  672. goto out;
  673. /* Quality by RSSI */
  674. priv->wstats.qual.level =
  675. CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
  676. priv->NF[TYPE_BEACON][TYPE_NOAVG]);
  677. if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
  678. priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
  679. } else {
  680. priv->wstats.qual.noise =
  681. CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
  682. }
  683. lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
  684. lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
  685. rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
  686. if (rssi < 15)
  687. rssi_qual = rssi * POOR / 10;
  688. else if (rssi < 20)
  689. rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
  690. else if (rssi < 30)
  691. rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
  692. else if (rssi < 40)
  693. rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
  694. 10 + GOOD;
  695. else
  696. rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
  697. 10 + VERY_GOOD;
  698. quality = rssi_qual;
  699. /* Quality by TX errors */
  700. priv->wstats.discard.retries = priv->stats.tx_errors;
  701. tx_retries = le32_to_cpu(priv->logmsg.retry);
  702. if (tx_retries > 75)
  703. tx_qual = (90 - tx_retries) * POOR / 15;
  704. else if (tx_retries > 70)
  705. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  706. else if (tx_retries > 65)
  707. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  708. else if (tx_retries > 50)
  709. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  710. 15 + GOOD;
  711. else
  712. tx_qual = (50 - tx_retries) *
  713. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  714. quality = min(quality, tx_qual);
  715. priv->wstats.discard.code = le32_to_cpu(priv->logmsg.wepundecryptable);
  716. priv->wstats.discard.fragment = le32_to_cpu(priv->logmsg.rxfrag);
  717. priv->wstats.discard.retries = tx_retries;
  718. priv->wstats.discard.misc = le32_to_cpu(priv->logmsg.ackfailure);
  719. /* Calculate quality */
  720. priv->wstats.qual.qual = min_t(u8, quality, 100);
  721. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  722. stats_valid = 1;
  723. /* update stats asynchronously for future calls */
  724. lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
  725. 0, 0, NULL);
  726. lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
  727. 0, 0, NULL);
  728. out:
  729. if (!stats_valid) {
  730. priv->wstats.miss.beacon = 0;
  731. priv->wstats.discard.retries = 0;
  732. priv->wstats.qual.qual = 0;
  733. priv->wstats.qual.level = 0;
  734. priv->wstats.qual.noise = 0;
  735. priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
  736. priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
  737. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  738. }
  739. lbs_deb_leave(LBS_DEB_WEXT);
  740. return &priv->wstats;
  741. }
  742. static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
  743. struct iw_freq *fwrq, char *extra)
  744. {
  745. int ret = -EINVAL;
  746. struct lbs_private *priv = dev->priv;
  747. struct chan_freq_power *cfp;
  748. struct assoc_request * assoc_req;
  749. lbs_deb_enter(LBS_DEB_WEXT);
  750. mutex_lock(&priv->lock);
  751. assoc_req = lbs_get_association_request(priv);
  752. if (!assoc_req) {
  753. ret = -ENOMEM;
  754. goto out;
  755. }
  756. /* If setting by frequency, convert to a channel */
  757. if (fwrq->e == 1) {
  758. long f = fwrq->m / 100000;
  759. cfp = find_cfp_by_band_and_freq(priv, 0, f);
  760. if (!cfp) {
  761. lbs_deb_wext("invalid freq %ld\n", f);
  762. goto out;
  763. }
  764. fwrq->e = 0;
  765. fwrq->m = (int) cfp->channel;
  766. }
  767. /* Setting by channel number */
  768. if (fwrq->m > 1000 || fwrq->e > 0) {
  769. goto out;
  770. }
  771. cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
  772. if (!cfp) {
  773. goto out;
  774. }
  775. assoc_req->channel = fwrq->m;
  776. ret = 0;
  777. out:
  778. if (ret == 0) {
  779. set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
  780. lbs_postpone_association_work(priv);
  781. } else {
  782. lbs_cancel_association_work(priv);
  783. }
  784. mutex_unlock(&priv->lock);
  785. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  786. return ret;
  787. }
  788. static int lbs_mesh_set_freq(struct net_device *dev,
  789. struct iw_request_info *info,
  790. struct iw_freq *fwrq, char *extra)
  791. {
  792. struct lbs_private *priv = dev->priv;
  793. struct chan_freq_power *cfp;
  794. int ret = -EINVAL;
  795. lbs_deb_enter(LBS_DEB_WEXT);
  796. /* If setting by frequency, convert to a channel */
  797. if (fwrq->e == 1) {
  798. long f = fwrq->m / 100000;
  799. cfp = find_cfp_by_band_and_freq(priv, 0, f);
  800. if (!cfp) {
  801. lbs_deb_wext("invalid freq %ld\n", f);
  802. goto out;
  803. }
  804. fwrq->e = 0;
  805. fwrq->m = (int) cfp->channel;
  806. }
  807. /* Setting by channel number */
  808. if (fwrq->m > 1000 || fwrq->e > 0) {
  809. goto out;
  810. }
  811. cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
  812. if (!cfp) {
  813. goto out;
  814. }
  815. if (fwrq->m != priv->curbssparams.channel) {
  816. lbs_deb_wext("mesh channel change forces eth disconnect\n");
  817. if (priv->mode == IW_MODE_INFRA)
  818. lbs_send_deauthentication(priv);
  819. else if (priv->mode == IW_MODE_ADHOC)
  820. lbs_stop_adhoc_network(priv);
  821. }
  822. lbs_mesh_config(priv, 1, fwrq->m);
  823. lbs_update_channel(priv);
  824. ret = 0;
  825. out:
  826. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  827. return ret;
  828. }
  829. static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
  830. struct iw_param *vwrq, char *extra)
  831. {
  832. struct lbs_private *priv = dev->priv;
  833. u8 new_rate = 0;
  834. int ret = -EINVAL;
  835. u8 rates[MAX_RATES + 1];
  836. lbs_deb_enter(LBS_DEB_WEXT);
  837. lbs_deb_wext("vwrq->value %d\n", vwrq->value);
  838. /* Auto rate? */
  839. if (vwrq->value == -1) {
  840. priv->auto_rate = 1;
  841. priv->cur_rate = 0;
  842. } else {
  843. if (vwrq->value % 100000)
  844. goto out;
  845. memset(rates, 0, sizeof(rates));
  846. copy_active_data_rates(priv, rates);
  847. new_rate = vwrq->value / 500000;
  848. if (!memchr(rates, new_rate, sizeof(rates))) {
  849. lbs_pr_alert("fixed data rate 0x%X out of range\n",
  850. new_rate);
  851. goto out;
  852. }
  853. priv->cur_rate = new_rate;
  854. priv->auto_rate = 0;
  855. }
  856. ret = lbs_set_data_rate(priv, new_rate);
  857. out:
  858. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  859. return ret;
  860. }
  861. static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
  862. struct iw_param *vwrq, char *extra)
  863. {
  864. struct lbs_private *priv = dev->priv;
  865. lbs_deb_enter(LBS_DEB_WEXT);
  866. if (priv->connect_status == LBS_CONNECTED) {
  867. vwrq->value = priv->cur_rate * 500000;
  868. if (priv->auto_rate)
  869. vwrq->fixed = 0;
  870. else
  871. vwrq->fixed = 1;
  872. } else {
  873. vwrq->fixed = 0;
  874. vwrq->value = 0;
  875. }
  876. lbs_deb_leave(LBS_DEB_WEXT);
  877. return 0;
  878. }
  879. static int lbs_set_mode(struct net_device *dev,
  880. struct iw_request_info *info, u32 * uwrq, char *extra)
  881. {
  882. int ret = 0;
  883. struct lbs_private *priv = dev->priv;
  884. struct assoc_request * assoc_req;
  885. lbs_deb_enter(LBS_DEB_WEXT);
  886. if ( (*uwrq != IW_MODE_ADHOC)
  887. && (*uwrq != IW_MODE_INFRA)
  888. && (*uwrq != IW_MODE_AUTO)) {
  889. lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
  890. ret = -EINVAL;
  891. goto out;
  892. }
  893. mutex_lock(&priv->lock);
  894. assoc_req = lbs_get_association_request(priv);
  895. if (!assoc_req) {
  896. ret = -ENOMEM;
  897. lbs_cancel_association_work(priv);
  898. } else {
  899. assoc_req->mode = *uwrq;
  900. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  901. lbs_postpone_association_work(priv);
  902. lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
  903. }
  904. mutex_unlock(&priv->lock);
  905. out:
  906. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  907. return ret;
  908. }
  909. /**
  910. * @brief Get Encryption key
  911. *
  912. * @param dev A pointer to net_device structure
  913. * @param info A pointer to iw_request_info structure
  914. * @param vwrq A pointer to iw_param structure
  915. * @param extra A pointer to extra data buf
  916. * @return 0 --success, otherwise fail
  917. */
  918. static int lbs_get_encode(struct net_device *dev,
  919. struct iw_request_info *info,
  920. struct iw_point *dwrq, u8 * extra)
  921. {
  922. struct lbs_private *priv = dev->priv;
  923. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  924. lbs_deb_enter(LBS_DEB_WEXT);
  925. lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
  926. dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
  927. dwrq->flags = 0;
  928. /* Authentication method */
  929. switch (priv->secinfo.auth_mode) {
  930. case IW_AUTH_ALG_OPEN_SYSTEM:
  931. dwrq->flags = IW_ENCODE_OPEN;
  932. break;
  933. case IW_AUTH_ALG_SHARED_KEY:
  934. case IW_AUTH_ALG_LEAP:
  935. dwrq->flags = IW_ENCODE_RESTRICTED;
  936. break;
  937. default:
  938. dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
  939. break;
  940. }
  941. memset(extra, 0, 16);
  942. mutex_lock(&priv->lock);
  943. /* Default to returning current transmit key */
  944. if (index < 0)
  945. index = priv->wep_tx_keyidx;
  946. if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
  947. memcpy(extra, priv->wep_keys[index].key,
  948. priv->wep_keys[index].len);
  949. dwrq->length = priv->wep_keys[index].len;
  950. dwrq->flags |= (index + 1);
  951. /* Return WEP enabled */
  952. dwrq->flags &= ~IW_ENCODE_DISABLED;
  953. } else if ((priv->secinfo.WPAenabled)
  954. || (priv->secinfo.WPA2enabled)) {
  955. /* return WPA enabled */
  956. dwrq->flags &= ~IW_ENCODE_DISABLED;
  957. dwrq->flags |= IW_ENCODE_NOKEY;
  958. } else {
  959. dwrq->flags |= IW_ENCODE_DISABLED;
  960. }
  961. mutex_unlock(&priv->lock);
  962. lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
  963. extra[0], extra[1], extra[2],
  964. extra[3], extra[4], extra[5], dwrq->length);
  965. lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
  966. lbs_deb_leave(LBS_DEB_WEXT);
  967. return 0;
  968. }
  969. /**
  970. * @brief Set Encryption key (internal)
  971. *
  972. * @param priv A pointer to private card structure
  973. * @param key_material A pointer to key material
  974. * @param key_length length of key material
  975. * @param index key index to set
  976. * @param set_tx_key Force set TX key (1 = yes, 0 = no)
  977. * @return 0 --success, otherwise fail
  978. */
  979. static int lbs_set_wep_key(struct assoc_request *assoc_req,
  980. const char *key_material,
  981. u16 key_length,
  982. u16 index,
  983. int set_tx_key)
  984. {
  985. int ret = 0;
  986. struct enc_key *pkey;
  987. lbs_deb_enter(LBS_DEB_WEXT);
  988. /* Paranoid validation of key index */
  989. if (index > 3) {
  990. ret = -EINVAL;
  991. goto out;
  992. }
  993. /* validate max key length */
  994. if (key_length > KEY_LEN_WEP_104) {
  995. ret = -EINVAL;
  996. goto out;
  997. }
  998. pkey = &assoc_req->wep_keys[index];
  999. if (key_length > 0) {
  1000. memset(pkey, 0, sizeof(struct enc_key));
  1001. pkey->type = KEY_TYPE_ID_WEP;
  1002. /* Standardize the key length */
  1003. pkey->len = (key_length > KEY_LEN_WEP_40) ?
  1004. KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
  1005. memcpy(pkey->key, key_material, key_length);
  1006. }
  1007. if (set_tx_key) {
  1008. /* Ensure the chosen key is valid */
  1009. if (!pkey->len) {
  1010. lbs_deb_wext("key not set, so cannot enable it\n");
  1011. ret = -EINVAL;
  1012. goto out;
  1013. }
  1014. assoc_req->wep_tx_keyidx = index;
  1015. }
  1016. assoc_req->secinfo.wep_enabled = 1;
  1017. out:
  1018. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1019. return ret;
  1020. }
  1021. static int validate_key_index(u16 def_index, u16 raw_index,
  1022. u16 *out_index, u16 *is_default)
  1023. {
  1024. if (!out_index || !is_default)
  1025. return -EINVAL;
  1026. /* Verify index if present, otherwise use default TX key index */
  1027. if (raw_index > 0) {
  1028. if (raw_index > 4)
  1029. return -EINVAL;
  1030. *out_index = raw_index - 1;
  1031. } else {
  1032. *out_index = def_index;
  1033. *is_default = 1;
  1034. }
  1035. return 0;
  1036. }
  1037. static void disable_wep(struct assoc_request *assoc_req)
  1038. {
  1039. int i;
  1040. lbs_deb_enter(LBS_DEB_WEXT);
  1041. /* Set Open System auth mode */
  1042. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1043. /* Clear WEP keys and mark WEP as disabled */
  1044. assoc_req->secinfo.wep_enabled = 0;
  1045. for (i = 0; i < 4; i++)
  1046. assoc_req->wep_keys[i].len = 0;
  1047. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1048. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1049. lbs_deb_leave(LBS_DEB_WEXT);
  1050. }
  1051. static void disable_wpa(struct assoc_request *assoc_req)
  1052. {
  1053. lbs_deb_enter(LBS_DEB_WEXT);
  1054. memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
  1055. assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
  1056. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1057. memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
  1058. assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
  1059. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1060. assoc_req->secinfo.WPAenabled = 0;
  1061. assoc_req->secinfo.WPA2enabled = 0;
  1062. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1063. lbs_deb_leave(LBS_DEB_WEXT);
  1064. }
  1065. /**
  1066. * @brief Set Encryption key
  1067. *
  1068. * @param dev A pointer to net_device structure
  1069. * @param info A pointer to iw_request_info structure
  1070. * @param vwrq A pointer to iw_param structure
  1071. * @param extra A pointer to extra data buf
  1072. * @return 0 --success, otherwise fail
  1073. */
  1074. static int lbs_set_encode(struct net_device *dev,
  1075. struct iw_request_info *info,
  1076. struct iw_point *dwrq, char *extra)
  1077. {
  1078. int ret = 0;
  1079. struct lbs_private *priv = dev->priv;
  1080. struct assoc_request * assoc_req;
  1081. u16 is_default = 0, index = 0, set_tx_key = 0;
  1082. lbs_deb_enter(LBS_DEB_WEXT);
  1083. mutex_lock(&priv->lock);
  1084. assoc_req = lbs_get_association_request(priv);
  1085. if (!assoc_req) {
  1086. ret = -ENOMEM;
  1087. goto out;
  1088. }
  1089. if (dwrq->flags & IW_ENCODE_DISABLED) {
  1090. disable_wep (assoc_req);
  1091. disable_wpa (assoc_req);
  1092. goto out;
  1093. }
  1094. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1095. (dwrq->flags & IW_ENCODE_INDEX),
  1096. &index, &is_default);
  1097. if (ret) {
  1098. ret = -EINVAL;
  1099. goto out;
  1100. }
  1101. /* If WEP isn't enabled, or if there is no key data but a valid
  1102. * index, set the TX key.
  1103. */
  1104. if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
  1105. set_tx_key = 1;
  1106. ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
  1107. if (ret)
  1108. goto out;
  1109. if (dwrq->length)
  1110. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1111. if (set_tx_key)
  1112. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1113. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1114. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1115. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1116. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1117. }
  1118. out:
  1119. if (ret == 0) {
  1120. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1121. lbs_postpone_association_work(priv);
  1122. } else {
  1123. lbs_cancel_association_work(priv);
  1124. }
  1125. mutex_unlock(&priv->lock);
  1126. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1127. return ret;
  1128. }
  1129. /**
  1130. * @brief Get Extended Encryption key (WPA/802.1x and WEP)
  1131. *
  1132. * @param dev A pointer to net_device structure
  1133. * @param info A pointer to iw_request_info structure
  1134. * @param vwrq A pointer to iw_param structure
  1135. * @param extra A pointer to extra data buf
  1136. * @return 0 on success, otherwise failure
  1137. */
  1138. static int lbs_get_encodeext(struct net_device *dev,
  1139. struct iw_request_info *info,
  1140. struct iw_point *dwrq,
  1141. char *extra)
  1142. {
  1143. int ret = -EINVAL;
  1144. struct lbs_private *priv = dev->priv;
  1145. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1146. int index, max_key_len;
  1147. lbs_deb_enter(LBS_DEB_WEXT);
  1148. max_key_len = dwrq->length - sizeof(*ext);
  1149. if (max_key_len < 0)
  1150. goto out;
  1151. index = dwrq->flags & IW_ENCODE_INDEX;
  1152. if (index) {
  1153. if (index < 1 || index > 4)
  1154. goto out;
  1155. index--;
  1156. } else {
  1157. index = priv->wep_tx_keyidx;
  1158. }
  1159. if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
  1160. ext->alg != IW_ENCODE_ALG_WEP) {
  1161. if (index != 0 || priv->mode != IW_MODE_INFRA)
  1162. goto out;
  1163. }
  1164. dwrq->flags = index + 1;
  1165. memset(ext, 0, sizeof(*ext));
  1166. if ( !priv->secinfo.wep_enabled
  1167. && !priv->secinfo.WPAenabled
  1168. && !priv->secinfo.WPA2enabled) {
  1169. ext->alg = IW_ENCODE_ALG_NONE;
  1170. ext->key_len = 0;
  1171. dwrq->flags |= IW_ENCODE_DISABLED;
  1172. } else {
  1173. u8 *key = NULL;
  1174. if ( priv->secinfo.wep_enabled
  1175. && !priv->secinfo.WPAenabled
  1176. && !priv->secinfo.WPA2enabled) {
  1177. /* WEP */
  1178. ext->alg = IW_ENCODE_ALG_WEP;
  1179. ext->key_len = priv->wep_keys[index].len;
  1180. key = &priv->wep_keys[index].key[0];
  1181. } else if ( !priv->secinfo.wep_enabled
  1182. && (priv->secinfo.WPAenabled ||
  1183. priv->secinfo.WPA2enabled)) {
  1184. /* WPA */
  1185. struct enc_key * pkey = NULL;
  1186. if ( priv->wpa_mcast_key.len
  1187. && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
  1188. pkey = &priv->wpa_mcast_key;
  1189. else if ( priv->wpa_unicast_key.len
  1190. && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
  1191. pkey = &priv->wpa_unicast_key;
  1192. if (pkey) {
  1193. if (pkey->type == KEY_TYPE_ID_AES) {
  1194. ext->alg = IW_ENCODE_ALG_CCMP;
  1195. } else {
  1196. ext->alg = IW_ENCODE_ALG_TKIP;
  1197. }
  1198. ext->key_len = pkey->len;
  1199. key = &pkey->key[0];
  1200. } else {
  1201. ext->alg = IW_ENCODE_ALG_TKIP;
  1202. ext->key_len = 0;
  1203. }
  1204. } else {
  1205. goto out;
  1206. }
  1207. if (ext->key_len > max_key_len) {
  1208. ret = -E2BIG;
  1209. goto out;
  1210. }
  1211. if (ext->key_len)
  1212. memcpy(ext->key, key, ext->key_len);
  1213. else
  1214. dwrq->flags |= IW_ENCODE_NOKEY;
  1215. dwrq->flags |= IW_ENCODE_ENABLED;
  1216. }
  1217. ret = 0;
  1218. out:
  1219. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1220. return ret;
  1221. }
  1222. /**
  1223. * @brief Set Encryption key Extended (WPA/802.1x and WEP)
  1224. *
  1225. * @param dev A pointer to net_device structure
  1226. * @param info A pointer to iw_request_info structure
  1227. * @param vwrq A pointer to iw_param structure
  1228. * @param extra A pointer to extra data buf
  1229. * @return 0 --success, otherwise fail
  1230. */
  1231. static int lbs_set_encodeext(struct net_device *dev,
  1232. struct iw_request_info *info,
  1233. struct iw_point *dwrq,
  1234. char *extra)
  1235. {
  1236. int ret = 0;
  1237. struct lbs_private *priv = dev->priv;
  1238. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1239. int alg = ext->alg;
  1240. struct assoc_request * assoc_req;
  1241. lbs_deb_enter(LBS_DEB_WEXT);
  1242. mutex_lock(&priv->lock);
  1243. assoc_req = lbs_get_association_request(priv);
  1244. if (!assoc_req) {
  1245. ret = -ENOMEM;
  1246. goto out;
  1247. }
  1248. if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
  1249. disable_wep (assoc_req);
  1250. disable_wpa (assoc_req);
  1251. } else if (alg == IW_ENCODE_ALG_WEP) {
  1252. u16 is_default = 0, index, set_tx_key = 0;
  1253. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1254. (dwrq->flags & IW_ENCODE_INDEX),
  1255. &index, &is_default);
  1256. if (ret)
  1257. goto out;
  1258. /* If WEP isn't enabled, or if there is no key data but a valid
  1259. * index, or if the set-TX-key flag was passed, set the TX key.
  1260. */
  1261. if ( !assoc_req->secinfo.wep_enabled
  1262. || (dwrq->length == 0 && !is_default)
  1263. || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
  1264. set_tx_key = 1;
  1265. /* Copy key to driver */
  1266. ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
  1267. set_tx_key);
  1268. if (ret)
  1269. goto out;
  1270. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1271. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1272. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1273. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1274. }
  1275. /* Mark the various WEP bits as modified */
  1276. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1277. if (dwrq->length)
  1278. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1279. if (set_tx_key)
  1280. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1281. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1282. struct enc_key * pkey;
  1283. /* validate key length */
  1284. if (((alg == IW_ENCODE_ALG_TKIP)
  1285. && (ext->key_len != KEY_LEN_WPA_TKIP))
  1286. || ((alg == IW_ENCODE_ALG_CCMP)
  1287. && (ext->key_len != KEY_LEN_WPA_AES))) {
  1288. lbs_deb_wext("invalid size %d for key of alg "
  1289. "type %d\n",
  1290. ext->key_len,
  1291. alg);
  1292. ret = -EINVAL;
  1293. goto out;
  1294. }
  1295. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1296. pkey = &assoc_req->wpa_mcast_key;
  1297. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1298. } else {
  1299. pkey = &assoc_req->wpa_unicast_key;
  1300. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1301. }
  1302. memset(pkey, 0, sizeof (struct enc_key));
  1303. memcpy(pkey->key, ext->key, ext->key_len);
  1304. pkey->len = ext->key_len;
  1305. if (pkey->len)
  1306. pkey->flags |= KEY_INFO_WPA_ENABLED;
  1307. /* Do this after zeroing key structure */
  1308. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1309. pkey->flags |= KEY_INFO_WPA_MCAST;
  1310. } else {
  1311. pkey->flags |= KEY_INFO_WPA_UNICAST;
  1312. }
  1313. if (alg == IW_ENCODE_ALG_TKIP) {
  1314. pkey->type = KEY_TYPE_ID_TKIP;
  1315. } else if (alg == IW_ENCODE_ALG_CCMP) {
  1316. pkey->type = KEY_TYPE_ID_AES;
  1317. }
  1318. /* If WPA isn't enabled yet, do that now */
  1319. if ( assoc_req->secinfo.WPAenabled == 0
  1320. && assoc_req->secinfo.WPA2enabled == 0) {
  1321. assoc_req->secinfo.WPAenabled = 1;
  1322. assoc_req->secinfo.WPA2enabled = 1;
  1323. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1324. }
  1325. disable_wep (assoc_req);
  1326. }
  1327. out:
  1328. if (ret == 0) {
  1329. lbs_postpone_association_work(priv);
  1330. } else {
  1331. lbs_cancel_association_work(priv);
  1332. }
  1333. mutex_unlock(&priv->lock);
  1334. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1335. return ret;
  1336. }
  1337. static int lbs_set_genie(struct net_device *dev,
  1338. struct iw_request_info *info,
  1339. struct iw_point *dwrq,
  1340. char *extra)
  1341. {
  1342. struct lbs_private *priv = dev->priv;
  1343. int ret = 0;
  1344. struct assoc_request * assoc_req;
  1345. lbs_deb_enter(LBS_DEB_WEXT);
  1346. mutex_lock(&priv->lock);
  1347. assoc_req = lbs_get_association_request(priv);
  1348. if (!assoc_req) {
  1349. ret = -ENOMEM;
  1350. goto out;
  1351. }
  1352. if (dwrq->length > MAX_WPA_IE_LEN ||
  1353. (dwrq->length && extra == NULL)) {
  1354. ret = -EINVAL;
  1355. goto out;
  1356. }
  1357. if (dwrq->length) {
  1358. memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
  1359. assoc_req->wpa_ie_len = dwrq->length;
  1360. } else {
  1361. memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
  1362. assoc_req->wpa_ie_len = 0;
  1363. }
  1364. out:
  1365. if (ret == 0) {
  1366. set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
  1367. lbs_postpone_association_work(priv);
  1368. } else {
  1369. lbs_cancel_association_work(priv);
  1370. }
  1371. mutex_unlock(&priv->lock);
  1372. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1373. return ret;
  1374. }
  1375. static int lbs_get_genie(struct net_device *dev,
  1376. struct iw_request_info *info,
  1377. struct iw_point *dwrq,
  1378. char *extra)
  1379. {
  1380. int ret = 0;
  1381. struct lbs_private *priv = dev->priv;
  1382. lbs_deb_enter(LBS_DEB_WEXT);
  1383. if (priv->wpa_ie_len == 0) {
  1384. dwrq->length = 0;
  1385. goto out;
  1386. }
  1387. if (dwrq->length < priv->wpa_ie_len) {
  1388. ret = -E2BIG;
  1389. goto out;
  1390. }
  1391. dwrq->length = priv->wpa_ie_len;
  1392. memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
  1393. out:
  1394. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1395. return ret;
  1396. }
  1397. static int lbs_set_auth(struct net_device *dev,
  1398. struct iw_request_info *info,
  1399. struct iw_param *dwrq,
  1400. char *extra)
  1401. {
  1402. struct lbs_private *priv = dev->priv;
  1403. struct assoc_request * assoc_req;
  1404. int ret = 0;
  1405. int updated = 0;
  1406. lbs_deb_enter(LBS_DEB_WEXT);
  1407. mutex_lock(&priv->lock);
  1408. assoc_req = lbs_get_association_request(priv);
  1409. if (!assoc_req) {
  1410. ret = -ENOMEM;
  1411. goto out;
  1412. }
  1413. switch (dwrq->flags & IW_AUTH_INDEX) {
  1414. case IW_AUTH_TKIP_COUNTERMEASURES:
  1415. case IW_AUTH_CIPHER_PAIRWISE:
  1416. case IW_AUTH_CIPHER_GROUP:
  1417. case IW_AUTH_KEY_MGMT:
  1418. case IW_AUTH_DROP_UNENCRYPTED:
  1419. /*
  1420. * libertas does not use these parameters
  1421. */
  1422. break;
  1423. case IW_AUTH_WPA_VERSION:
  1424. if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
  1425. assoc_req->secinfo.WPAenabled = 0;
  1426. assoc_req->secinfo.WPA2enabled = 0;
  1427. disable_wpa (assoc_req);
  1428. }
  1429. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
  1430. assoc_req->secinfo.WPAenabled = 1;
  1431. assoc_req->secinfo.wep_enabled = 0;
  1432. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1433. }
  1434. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
  1435. assoc_req->secinfo.WPA2enabled = 1;
  1436. assoc_req->secinfo.wep_enabled = 0;
  1437. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1438. }
  1439. updated = 1;
  1440. break;
  1441. case IW_AUTH_80211_AUTH_ALG:
  1442. if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
  1443. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1444. } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  1445. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1446. } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
  1447. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
  1448. } else {
  1449. ret = -EINVAL;
  1450. }
  1451. updated = 1;
  1452. break;
  1453. case IW_AUTH_WPA_ENABLED:
  1454. if (dwrq->value) {
  1455. if (!assoc_req->secinfo.WPAenabled &&
  1456. !assoc_req->secinfo.WPA2enabled) {
  1457. assoc_req->secinfo.WPAenabled = 1;
  1458. assoc_req->secinfo.WPA2enabled = 1;
  1459. assoc_req->secinfo.wep_enabled = 0;
  1460. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1461. }
  1462. } else {
  1463. assoc_req->secinfo.WPAenabled = 0;
  1464. assoc_req->secinfo.WPA2enabled = 0;
  1465. disable_wpa (assoc_req);
  1466. }
  1467. updated = 1;
  1468. break;
  1469. default:
  1470. ret = -EOPNOTSUPP;
  1471. break;
  1472. }
  1473. out:
  1474. if (ret == 0) {
  1475. if (updated)
  1476. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1477. lbs_postpone_association_work(priv);
  1478. } else if (ret != -EOPNOTSUPP) {
  1479. lbs_cancel_association_work(priv);
  1480. }
  1481. mutex_unlock(&priv->lock);
  1482. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1483. return ret;
  1484. }
  1485. static int lbs_get_auth(struct net_device *dev,
  1486. struct iw_request_info *info,
  1487. struct iw_param *dwrq,
  1488. char *extra)
  1489. {
  1490. int ret = 0;
  1491. struct lbs_private *priv = dev->priv;
  1492. lbs_deb_enter(LBS_DEB_WEXT);
  1493. switch (dwrq->flags & IW_AUTH_INDEX) {
  1494. case IW_AUTH_WPA_VERSION:
  1495. dwrq->value = 0;
  1496. if (priv->secinfo.WPAenabled)
  1497. dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
  1498. if (priv->secinfo.WPA2enabled)
  1499. dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
  1500. if (!dwrq->value)
  1501. dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
  1502. break;
  1503. case IW_AUTH_80211_AUTH_ALG:
  1504. dwrq->value = priv->secinfo.auth_mode;
  1505. break;
  1506. case IW_AUTH_WPA_ENABLED:
  1507. if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
  1508. dwrq->value = 1;
  1509. break;
  1510. default:
  1511. ret = -EOPNOTSUPP;
  1512. }
  1513. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1514. return ret;
  1515. }
  1516. static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
  1517. struct iw_param *vwrq, char *extra)
  1518. {
  1519. int ret = 0;
  1520. struct lbs_private *priv = dev->priv;
  1521. u16 dbm;
  1522. lbs_deb_enter(LBS_DEB_WEXT);
  1523. if (vwrq->disabled) {
  1524. lbs_radio_ioctl(priv, RADIO_OFF);
  1525. return 0;
  1526. }
  1527. priv->preamble = CMD_TYPE_AUTO_PREAMBLE;
  1528. lbs_radio_ioctl(priv, RADIO_ON);
  1529. /* Userspace check in iwrange if it should use dBm or mW,
  1530. * therefore this should never happen... Jean II */
  1531. if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
  1532. return -EOPNOTSUPP;
  1533. } else
  1534. dbm = (u16) vwrq->value;
  1535. /* auto tx power control */
  1536. if (vwrq->fixed == 0)
  1537. dbm = 0xffff;
  1538. lbs_deb_wext("txpower set %d dbm\n", dbm);
  1539. ret = lbs_prepare_and_send_command(priv,
  1540. CMD_802_11_RF_TX_POWER,
  1541. CMD_ACT_TX_POWER_OPT_SET_LOW,
  1542. CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
  1543. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1544. return ret;
  1545. }
  1546. static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
  1547. struct iw_point *dwrq, char *extra)
  1548. {
  1549. struct lbs_private *priv = dev->priv;
  1550. lbs_deb_enter(LBS_DEB_WEXT);
  1551. /*
  1552. * Note : if dwrq->flags != 0, we should get the relevant SSID from
  1553. * the SSID list...
  1554. */
  1555. /*
  1556. * Get the current SSID
  1557. */
  1558. if (priv->connect_status == LBS_CONNECTED) {
  1559. memcpy(extra, priv->curbssparams.ssid,
  1560. priv->curbssparams.ssid_len);
  1561. extra[priv->curbssparams.ssid_len] = '\0';
  1562. } else {
  1563. memset(extra, 0, 32);
  1564. extra[priv->curbssparams.ssid_len] = '\0';
  1565. }
  1566. /*
  1567. * If none, we may want to get the one that was set
  1568. */
  1569. dwrq->length = priv->curbssparams.ssid_len;
  1570. dwrq->flags = 1; /* active */
  1571. lbs_deb_leave(LBS_DEB_WEXT);
  1572. return 0;
  1573. }
  1574. static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
  1575. struct iw_point *dwrq, char *extra)
  1576. {
  1577. struct lbs_private *priv = dev->priv;
  1578. int ret = 0;
  1579. u8 ssid[IW_ESSID_MAX_SIZE];
  1580. u8 ssid_len = 0;
  1581. struct assoc_request * assoc_req;
  1582. int in_ssid_len = dwrq->length;
  1583. lbs_deb_enter(LBS_DEB_WEXT);
  1584. /* Check the size of the string */
  1585. if (in_ssid_len > IW_ESSID_MAX_SIZE) {
  1586. ret = -E2BIG;
  1587. goto out;
  1588. }
  1589. memset(&ssid, 0, sizeof(ssid));
  1590. if (!dwrq->flags || !in_ssid_len) {
  1591. /* "any" SSID requested; leave SSID blank */
  1592. } else {
  1593. /* Specific SSID requested */
  1594. memcpy(&ssid, extra, in_ssid_len);
  1595. ssid_len = in_ssid_len;
  1596. }
  1597. if (!ssid_len) {
  1598. lbs_deb_wext("requested any SSID\n");
  1599. } else {
  1600. lbs_deb_wext("requested SSID '%s'\n",
  1601. escape_essid(ssid, ssid_len));
  1602. }
  1603. out:
  1604. mutex_lock(&priv->lock);
  1605. if (ret == 0) {
  1606. /* Get or create the current association request */
  1607. assoc_req = lbs_get_association_request(priv);
  1608. if (!assoc_req) {
  1609. ret = -ENOMEM;
  1610. } else {
  1611. /* Copy the SSID to the association request */
  1612. memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
  1613. assoc_req->ssid_len = ssid_len;
  1614. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  1615. lbs_postpone_association_work(priv);
  1616. }
  1617. }
  1618. /* Cancel the association request if there was an error */
  1619. if (ret != 0) {
  1620. lbs_cancel_association_work(priv);
  1621. }
  1622. mutex_unlock(&priv->lock);
  1623. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1624. return ret;
  1625. }
  1626. static int lbs_mesh_get_essid(struct net_device *dev,
  1627. struct iw_request_info *info,
  1628. struct iw_point *dwrq, char *extra)
  1629. {
  1630. struct lbs_private *priv = dev->priv;
  1631. lbs_deb_enter(LBS_DEB_WEXT);
  1632. memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
  1633. dwrq->length = priv->mesh_ssid_len;
  1634. dwrq->flags = 1; /* active */
  1635. lbs_deb_leave(LBS_DEB_WEXT);
  1636. return 0;
  1637. }
  1638. static int lbs_mesh_set_essid(struct net_device *dev,
  1639. struct iw_request_info *info,
  1640. struct iw_point *dwrq, char *extra)
  1641. {
  1642. struct lbs_private *priv = dev->priv;
  1643. int ret = 0;
  1644. lbs_deb_enter(LBS_DEB_WEXT);
  1645. /* Check the size of the string */
  1646. if (dwrq->length > IW_ESSID_MAX_SIZE) {
  1647. ret = -E2BIG;
  1648. goto out;
  1649. }
  1650. if (!dwrq->flags || !dwrq->length) {
  1651. ret = -EINVAL;
  1652. goto out;
  1653. } else {
  1654. /* Specific SSID requested */
  1655. memcpy(priv->mesh_ssid, extra, dwrq->length);
  1656. priv->mesh_ssid_len = dwrq->length;
  1657. }
  1658. lbs_mesh_config(priv, 1, priv->curbssparams.channel);
  1659. out:
  1660. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1661. return ret;
  1662. }
  1663. /**
  1664. * @brief Connect to the AP or Ad-hoc Network with specific bssid
  1665. *
  1666. * @param dev A pointer to net_device structure
  1667. * @param info A pointer to iw_request_info structure
  1668. * @param awrq A pointer to iw_param structure
  1669. * @param extra A pointer to extra data buf
  1670. * @return 0 --success, otherwise fail
  1671. */
  1672. static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
  1673. struct sockaddr *awrq, char *extra)
  1674. {
  1675. struct lbs_private *priv = dev->priv;
  1676. struct assoc_request * assoc_req;
  1677. int ret = 0;
  1678. DECLARE_MAC_BUF(mac);
  1679. lbs_deb_enter(LBS_DEB_WEXT);
  1680. if (awrq->sa_family != ARPHRD_ETHER)
  1681. return -EINVAL;
  1682. lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
  1683. mutex_lock(&priv->lock);
  1684. /* Get or create the current association request */
  1685. assoc_req = lbs_get_association_request(priv);
  1686. if (!assoc_req) {
  1687. lbs_cancel_association_work(priv);
  1688. ret = -ENOMEM;
  1689. } else {
  1690. /* Copy the BSSID to the association request */
  1691. memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
  1692. set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
  1693. lbs_postpone_association_work(priv);
  1694. }
  1695. mutex_unlock(&priv->lock);
  1696. return ret;
  1697. }
  1698. void lbs_get_fwversion(struct lbs_private *priv, char *fwversion, int maxlen)
  1699. {
  1700. char fwver[32];
  1701. mutex_lock(&priv->lock);
  1702. sprintf(fwver, "%u.%u.%u.p%u",
  1703. priv->fwrelease >> 24 & 0xff,
  1704. priv->fwrelease >> 16 & 0xff,
  1705. priv->fwrelease >> 8 & 0xff,
  1706. priv->fwrelease & 0xff);
  1707. mutex_unlock(&priv->lock);
  1708. snprintf(fwversion, maxlen, fwver);
  1709. }
  1710. /*
  1711. * iwconfig settable callbacks
  1712. */
  1713. static const iw_handler lbs_handler[] = {
  1714. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1715. (iw_handler) lbs_get_name, /* SIOCGIWNAME */
  1716. (iw_handler) NULL, /* SIOCSIWNWID */
  1717. (iw_handler) NULL, /* SIOCGIWNWID */
  1718. (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
  1719. (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
  1720. (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
  1721. (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
  1722. (iw_handler) NULL, /* SIOCSIWSENS */
  1723. (iw_handler) NULL, /* SIOCGIWSENS */
  1724. (iw_handler) NULL, /* SIOCSIWRANGE */
  1725. (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
  1726. (iw_handler) NULL, /* SIOCSIWPRIV */
  1727. (iw_handler) NULL, /* SIOCGIWPRIV */
  1728. (iw_handler) NULL, /* SIOCSIWSTATS */
  1729. (iw_handler) NULL, /* SIOCGIWSTATS */
  1730. iw_handler_set_spy, /* SIOCSIWSPY */
  1731. iw_handler_get_spy, /* SIOCGIWSPY */
  1732. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1733. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1734. (iw_handler) lbs_set_wap, /* SIOCSIWAP */
  1735. (iw_handler) lbs_get_wap, /* SIOCGIWAP */
  1736. (iw_handler) NULL, /* SIOCSIWMLME */
  1737. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1738. (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
  1739. (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
  1740. (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
  1741. (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
  1742. (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
  1743. (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
  1744. (iw_handler) NULL, /* -- hole -- */
  1745. (iw_handler) NULL, /* -- hole -- */
  1746. (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
  1747. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1748. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1749. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1750. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1751. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1752. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1753. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1754. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1755. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1756. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1757. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1758. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1759. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1760. (iw_handler) NULL, /* -- hole -- */
  1761. (iw_handler) NULL, /* -- hole -- */
  1762. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1763. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1764. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1765. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1766. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1767. (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
  1768. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1769. };
  1770. static const iw_handler mesh_wlan_handler[] = {
  1771. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1772. (iw_handler) lbs_get_name, /* SIOCGIWNAME */
  1773. (iw_handler) NULL, /* SIOCSIWNWID */
  1774. (iw_handler) NULL, /* SIOCGIWNWID */
  1775. (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
  1776. (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
  1777. (iw_handler) NULL, /* SIOCSIWMODE */
  1778. (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
  1779. (iw_handler) NULL, /* SIOCSIWSENS */
  1780. (iw_handler) NULL, /* SIOCGIWSENS */
  1781. (iw_handler) NULL, /* SIOCSIWRANGE */
  1782. (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
  1783. (iw_handler) NULL, /* SIOCSIWPRIV */
  1784. (iw_handler) NULL, /* SIOCGIWPRIV */
  1785. (iw_handler) NULL, /* SIOCSIWSTATS */
  1786. (iw_handler) NULL, /* SIOCGIWSTATS */
  1787. iw_handler_set_spy, /* SIOCSIWSPY */
  1788. iw_handler_get_spy, /* SIOCGIWSPY */
  1789. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1790. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1791. (iw_handler) NULL, /* SIOCSIWAP */
  1792. (iw_handler) NULL, /* SIOCGIWAP */
  1793. (iw_handler) NULL, /* SIOCSIWMLME */
  1794. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1795. (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
  1796. (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
  1797. (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
  1798. (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
  1799. (iw_handler) NULL, /* SIOCSIWNICKN */
  1800. (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
  1801. (iw_handler) NULL, /* -- hole -- */
  1802. (iw_handler) NULL, /* -- hole -- */
  1803. (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
  1804. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1805. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1806. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1807. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1808. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1809. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1810. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1811. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1812. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1813. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1814. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1815. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1816. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1817. (iw_handler) NULL, /* -- hole -- */
  1818. (iw_handler) NULL, /* -- hole -- */
  1819. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1820. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1821. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1822. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1823. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1824. (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
  1825. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1826. };
  1827. struct iw_handler_def lbs_handler_def = {
  1828. .num_standard = ARRAY_SIZE(lbs_handler),
  1829. .standard = (iw_handler *) lbs_handler,
  1830. .get_wireless_stats = lbs_get_wireless_stats,
  1831. };
  1832. struct iw_handler_def mesh_handler_def = {
  1833. .num_standard = ARRAY_SIZE(mesh_wlan_handler),
  1834. .standard = (iw_handler *) mesh_wlan_handler,
  1835. .get_wireless_stats = lbs_get_wireless_stats,
  1836. };