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