wext.c 54 KB

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