wext.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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_set_rate(struct net_device *dev, struct iw_request_info *info,
  783. struct iw_param *vwrq, char *extra)
  784. {
  785. struct lbs_private *priv = dev->priv;
  786. u8 new_rate = 0;
  787. int ret = -EINVAL;
  788. u8 rates[MAX_RATES + 1];
  789. lbs_deb_enter(LBS_DEB_WEXT);
  790. lbs_deb_wext("vwrq->value %d\n", vwrq->value);
  791. /* Auto rate? */
  792. if (vwrq->value == -1) {
  793. priv->auto_rate = 1;
  794. priv->cur_rate = 0;
  795. } else {
  796. if (vwrq->value % 100000)
  797. goto out;
  798. memset(rates, 0, sizeof(rates));
  799. copy_active_data_rates(priv, rates);
  800. new_rate = vwrq->value / 500000;
  801. if (!memchr(rates, new_rate, sizeof(rates))) {
  802. lbs_pr_alert("fixed data rate 0x%X out of range\n",
  803. new_rate);
  804. goto out;
  805. }
  806. priv->cur_rate = new_rate;
  807. priv->auto_rate = 0;
  808. }
  809. ret = lbs_set_data_rate(priv, new_rate);
  810. out:
  811. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  812. return ret;
  813. }
  814. static int lbs_get_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. lbs_deb_enter(LBS_DEB_WEXT);
  819. if (priv->connect_status == LBS_CONNECTED) {
  820. vwrq->value = priv->cur_rate * 500000;
  821. if (priv->auto_rate)
  822. vwrq->fixed = 0;
  823. else
  824. vwrq->fixed = 1;
  825. } else {
  826. vwrq->fixed = 0;
  827. vwrq->value = 0;
  828. }
  829. lbs_deb_leave(LBS_DEB_WEXT);
  830. return 0;
  831. }
  832. static int lbs_set_mode(struct net_device *dev,
  833. struct iw_request_info *info, u32 * uwrq, char *extra)
  834. {
  835. int ret = 0;
  836. struct lbs_private *priv = dev->priv;
  837. struct assoc_request * assoc_req;
  838. lbs_deb_enter(LBS_DEB_WEXT);
  839. if ( (*uwrq != IW_MODE_ADHOC)
  840. && (*uwrq != IW_MODE_INFRA)
  841. && (*uwrq != IW_MODE_AUTO)) {
  842. lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
  843. ret = -EINVAL;
  844. goto out;
  845. }
  846. mutex_lock(&priv->lock);
  847. assoc_req = lbs_get_association_request(priv);
  848. if (!assoc_req) {
  849. ret = -ENOMEM;
  850. lbs_cancel_association_work(priv);
  851. } else {
  852. assoc_req->mode = *uwrq;
  853. set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
  854. lbs_postpone_association_work(priv);
  855. lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
  856. }
  857. mutex_unlock(&priv->lock);
  858. out:
  859. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  860. return ret;
  861. }
  862. /**
  863. * @brief Get Encryption key
  864. *
  865. * @param dev A pointer to net_device structure
  866. * @param info A pointer to iw_request_info structure
  867. * @param vwrq A pointer to iw_param structure
  868. * @param extra A pointer to extra data buf
  869. * @return 0 --success, otherwise fail
  870. */
  871. static int lbs_get_encode(struct net_device *dev,
  872. struct iw_request_info *info,
  873. struct iw_point *dwrq, u8 * extra)
  874. {
  875. struct lbs_private *priv = dev->priv;
  876. int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
  877. lbs_deb_enter(LBS_DEB_WEXT);
  878. lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
  879. dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
  880. dwrq->flags = 0;
  881. /* Authentication method */
  882. switch (priv->secinfo.auth_mode) {
  883. case IW_AUTH_ALG_OPEN_SYSTEM:
  884. dwrq->flags = IW_ENCODE_OPEN;
  885. break;
  886. case IW_AUTH_ALG_SHARED_KEY:
  887. case IW_AUTH_ALG_LEAP:
  888. dwrq->flags = IW_ENCODE_RESTRICTED;
  889. break;
  890. default:
  891. dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
  892. break;
  893. }
  894. memset(extra, 0, 16);
  895. mutex_lock(&priv->lock);
  896. /* Default to returning current transmit key */
  897. if (index < 0)
  898. index = priv->wep_tx_keyidx;
  899. if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
  900. memcpy(extra, priv->wep_keys[index].key,
  901. priv->wep_keys[index].len);
  902. dwrq->length = priv->wep_keys[index].len;
  903. dwrq->flags |= (index + 1);
  904. /* Return WEP enabled */
  905. dwrq->flags &= ~IW_ENCODE_DISABLED;
  906. } else if ((priv->secinfo.WPAenabled)
  907. || (priv->secinfo.WPA2enabled)) {
  908. /* return WPA enabled */
  909. dwrq->flags &= ~IW_ENCODE_DISABLED;
  910. dwrq->flags |= IW_ENCODE_NOKEY;
  911. } else {
  912. dwrq->flags |= IW_ENCODE_DISABLED;
  913. }
  914. mutex_unlock(&priv->lock);
  915. lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
  916. extra[0], extra[1], extra[2],
  917. extra[3], extra[4], extra[5], dwrq->length);
  918. lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
  919. lbs_deb_leave(LBS_DEB_WEXT);
  920. return 0;
  921. }
  922. /**
  923. * @brief Set Encryption key (internal)
  924. *
  925. * @param priv A pointer to private card structure
  926. * @param key_material A pointer to key material
  927. * @param key_length length of key material
  928. * @param index key index to set
  929. * @param set_tx_key Force set TX key (1 = yes, 0 = no)
  930. * @return 0 --success, otherwise fail
  931. */
  932. static int lbs_set_wep_key(struct assoc_request *assoc_req,
  933. const char *key_material,
  934. u16 key_length,
  935. u16 index,
  936. int set_tx_key)
  937. {
  938. int ret = 0;
  939. struct enc_key *pkey;
  940. lbs_deb_enter(LBS_DEB_WEXT);
  941. /* Paranoid validation of key index */
  942. if (index > 3) {
  943. ret = -EINVAL;
  944. goto out;
  945. }
  946. /* validate max key length */
  947. if (key_length > KEY_LEN_WEP_104) {
  948. ret = -EINVAL;
  949. goto out;
  950. }
  951. pkey = &assoc_req->wep_keys[index];
  952. if (key_length > 0) {
  953. memset(pkey, 0, sizeof(struct enc_key));
  954. pkey->type = KEY_TYPE_ID_WEP;
  955. /* Standardize the key length */
  956. pkey->len = (key_length > KEY_LEN_WEP_40) ?
  957. KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
  958. memcpy(pkey->key, key_material, key_length);
  959. }
  960. if (set_tx_key) {
  961. /* Ensure the chosen key is valid */
  962. if (!pkey->len) {
  963. lbs_deb_wext("key not set, so cannot enable it\n");
  964. ret = -EINVAL;
  965. goto out;
  966. }
  967. assoc_req->wep_tx_keyidx = index;
  968. }
  969. assoc_req->secinfo.wep_enabled = 1;
  970. out:
  971. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  972. return ret;
  973. }
  974. static int validate_key_index(u16 def_index, u16 raw_index,
  975. u16 *out_index, u16 *is_default)
  976. {
  977. if (!out_index || !is_default)
  978. return -EINVAL;
  979. /* Verify index if present, otherwise use default TX key index */
  980. if (raw_index > 0) {
  981. if (raw_index > 4)
  982. return -EINVAL;
  983. *out_index = raw_index - 1;
  984. } else {
  985. *out_index = def_index;
  986. *is_default = 1;
  987. }
  988. return 0;
  989. }
  990. static void disable_wep(struct assoc_request *assoc_req)
  991. {
  992. int i;
  993. lbs_deb_enter(LBS_DEB_WEXT);
  994. /* Set Open System auth mode */
  995. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  996. /* Clear WEP keys and mark WEP as disabled */
  997. assoc_req->secinfo.wep_enabled = 0;
  998. for (i = 0; i < 4; i++)
  999. assoc_req->wep_keys[i].len = 0;
  1000. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1001. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1002. lbs_deb_leave(LBS_DEB_WEXT);
  1003. }
  1004. static void disable_wpa(struct assoc_request *assoc_req)
  1005. {
  1006. lbs_deb_enter(LBS_DEB_WEXT);
  1007. memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
  1008. assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
  1009. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1010. memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
  1011. assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
  1012. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1013. assoc_req->secinfo.WPAenabled = 0;
  1014. assoc_req->secinfo.WPA2enabled = 0;
  1015. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1016. lbs_deb_leave(LBS_DEB_WEXT);
  1017. }
  1018. /**
  1019. * @brief Set Encryption key
  1020. *
  1021. * @param dev A pointer to net_device structure
  1022. * @param info A pointer to iw_request_info structure
  1023. * @param vwrq A pointer to iw_param structure
  1024. * @param extra A pointer to extra data buf
  1025. * @return 0 --success, otherwise fail
  1026. */
  1027. static int lbs_set_encode(struct net_device *dev,
  1028. struct iw_request_info *info,
  1029. struct iw_point *dwrq, char *extra)
  1030. {
  1031. int ret = 0;
  1032. struct lbs_private *priv = dev->priv;
  1033. struct assoc_request * assoc_req;
  1034. u16 is_default = 0, index = 0, set_tx_key = 0;
  1035. lbs_deb_enter(LBS_DEB_WEXT);
  1036. mutex_lock(&priv->lock);
  1037. assoc_req = lbs_get_association_request(priv);
  1038. if (!assoc_req) {
  1039. ret = -ENOMEM;
  1040. goto out;
  1041. }
  1042. if (dwrq->flags & IW_ENCODE_DISABLED) {
  1043. disable_wep (assoc_req);
  1044. disable_wpa (assoc_req);
  1045. goto out;
  1046. }
  1047. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1048. (dwrq->flags & IW_ENCODE_INDEX),
  1049. &index, &is_default);
  1050. if (ret) {
  1051. ret = -EINVAL;
  1052. goto out;
  1053. }
  1054. /* If WEP isn't enabled, or if there is no key data but a valid
  1055. * index, set the TX key.
  1056. */
  1057. if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
  1058. set_tx_key = 1;
  1059. ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
  1060. if (ret)
  1061. goto out;
  1062. if (dwrq->length)
  1063. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1064. if (set_tx_key)
  1065. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1066. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1067. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1068. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1069. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1070. }
  1071. out:
  1072. if (ret == 0) {
  1073. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1074. lbs_postpone_association_work(priv);
  1075. } else {
  1076. lbs_cancel_association_work(priv);
  1077. }
  1078. mutex_unlock(&priv->lock);
  1079. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1080. return ret;
  1081. }
  1082. /**
  1083. * @brief Get Extended Encryption key (WPA/802.1x and WEP)
  1084. *
  1085. * @param dev A pointer to net_device structure
  1086. * @param info A pointer to iw_request_info structure
  1087. * @param vwrq A pointer to iw_param structure
  1088. * @param extra A pointer to extra data buf
  1089. * @return 0 on success, otherwise failure
  1090. */
  1091. static int lbs_get_encodeext(struct net_device *dev,
  1092. struct iw_request_info *info,
  1093. struct iw_point *dwrq,
  1094. char *extra)
  1095. {
  1096. int ret = -EINVAL;
  1097. struct lbs_private *priv = dev->priv;
  1098. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1099. int index, max_key_len;
  1100. lbs_deb_enter(LBS_DEB_WEXT);
  1101. max_key_len = dwrq->length - sizeof(*ext);
  1102. if (max_key_len < 0)
  1103. goto out;
  1104. index = dwrq->flags & IW_ENCODE_INDEX;
  1105. if (index) {
  1106. if (index < 1 || index > 4)
  1107. goto out;
  1108. index--;
  1109. } else {
  1110. index = priv->wep_tx_keyidx;
  1111. }
  1112. if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
  1113. ext->alg != IW_ENCODE_ALG_WEP) {
  1114. if (index != 0 || priv->mode != IW_MODE_INFRA)
  1115. goto out;
  1116. }
  1117. dwrq->flags = index + 1;
  1118. memset(ext, 0, sizeof(*ext));
  1119. if ( !priv->secinfo.wep_enabled
  1120. && !priv->secinfo.WPAenabled
  1121. && !priv->secinfo.WPA2enabled) {
  1122. ext->alg = IW_ENCODE_ALG_NONE;
  1123. ext->key_len = 0;
  1124. dwrq->flags |= IW_ENCODE_DISABLED;
  1125. } else {
  1126. u8 *key = NULL;
  1127. if ( priv->secinfo.wep_enabled
  1128. && !priv->secinfo.WPAenabled
  1129. && !priv->secinfo.WPA2enabled) {
  1130. /* WEP */
  1131. ext->alg = IW_ENCODE_ALG_WEP;
  1132. ext->key_len = priv->wep_keys[index].len;
  1133. key = &priv->wep_keys[index].key[0];
  1134. } else if ( !priv->secinfo.wep_enabled
  1135. && (priv->secinfo.WPAenabled ||
  1136. priv->secinfo.WPA2enabled)) {
  1137. /* WPA */
  1138. struct enc_key * pkey = NULL;
  1139. if ( priv->wpa_mcast_key.len
  1140. && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
  1141. pkey = &priv->wpa_mcast_key;
  1142. else if ( priv->wpa_unicast_key.len
  1143. && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
  1144. pkey = &priv->wpa_unicast_key;
  1145. if (pkey) {
  1146. if (pkey->type == KEY_TYPE_ID_AES) {
  1147. ext->alg = IW_ENCODE_ALG_CCMP;
  1148. } else {
  1149. ext->alg = IW_ENCODE_ALG_TKIP;
  1150. }
  1151. ext->key_len = pkey->len;
  1152. key = &pkey->key[0];
  1153. } else {
  1154. ext->alg = IW_ENCODE_ALG_TKIP;
  1155. ext->key_len = 0;
  1156. }
  1157. } else {
  1158. goto out;
  1159. }
  1160. if (ext->key_len > max_key_len) {
  1161. ret = -E2BIG;
  1162. goto out;
  1163. }
  1164. if (ext->key_len)
  1165. memcpy(ext->key, key, ext->key_len);
  1166. else
  1167. dwrq->flags |= IW_ENCODE_NOKEY;
  1168. dwrq->flags |= IW_ENCODE_ENABLED;
  1169. }
  1170. ret = 0;
  1171. out:
  1172. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1173. return ret;
  1174. }
  1175. /**
  1176. * @brief Set Encryption key Extended (WPA/802.1x and WEP)
  1177. *
  1178. * @param dev A pointer to net_device structure
  1179. * @param info A pointer to iw_request_info structure
  1180. * @param vwrq A pointer to iw_param structure
  1181. * @param extra A pointer to extra data buf
  1182. * @return 0 --success, otherwise fail
  1183. */
  1184. static int lbs_set_encodeext(struct net_device *dev,
  1185. struct iw_request_info *info,
  1186. struct iw_point *dwrq,
  1187. char *extra)
  1188. {
  1189. int ret = 0;
  1190. struct lbs_private *priv = dev->priv;
  1191. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  1192. int alg = ext->alg;
  1193. struct assoc_request * assoc_req;
  1194. lbs_deb_enter(LBS_DEB_WEXT);
  1195. mutex_lock(&priv->lock);
  1196. assoc_req = lbs_get_association_request(priv);
  1197. if (!assoc_req) {
  1198. ret = -ENOMEM;
  1199. goto out;
  1200. }
  1201. if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
  1202. disable_wep (assoc_req);
  1203. disable_wpa (assoc_req);
  1204. } else if (alg == IW_ENCODE_ALG_WEP) {
  1205. u16 is_default = 0, index, set_tx_key = 0;
  1206. ret = validate_key_index(assoc_req->wep_tx_keyidx,
  1207. (dwrq->flags & IW_ENCODE_INDEX),
  1208. &index, &is_default);
  1209. if (ret)
  1210. goto out;
  1211. /* If WEP isn't enabled, or if there is no key data but a valid
  1212. * index, or if the set-TX-key flag was passed, set the TX key.
  1213. */
  1214. if ( !assoc_req->secinfo.wep_enabled
  1215. || (dwrq->length == 0 && !is_default)
  1216. || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
  1217. set_tx_key = 1;
  1218. /* Copy key to driver */
  1219. ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
  1220. set_tx_key);
  1221. if (ret)
  1222. goto out;
  1223. if (dwrq->flags & IW_ENCODE_RESTRICTED) {
  1224. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1225. } else if (dwrq->flags & IW_ENCODE_OPEN) {
  1226. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1227. }
  1228. /* Mark the various WEP bits as modified */
  1229. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1230. if (dwrq->length)
  1231. set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
  1232. if (set_tx_key)
  1233. set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
  1234. } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
  1235. struct enc_key * pkey;
  1236. /* validate key length */
  1237. if (((alg == IW_ENCODE_ALG_TKIP)
  1238. && (ext->key_len != KEY_LEN_WPA_TKIP))
  1239. || ((alg == IW_ENCODE_ALG_CCMP)
  1240. && (ext->key_len != KEY_LEN_WPA_AES))) {
  1241. lbs_deb_wext("invalid size %d for key of alg "
  1242. "type %d\n",
  1243. ext->key_len,
  1244. alg);
  1245. ret = -EINVAL;
  1246. goto out;
  1247. }
  1248. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1249. pkey = &assoc_req->wpa_mcast_key;
  1250. set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
  1251. } else {
  1252. pkey = &assoc_req->wpa_unicast_key;
  1253. set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
  1254. }
  1255. memset(pkey, 0, sizeof (struct enc_key));
  1256. memcpy(pkey->key, ext->key, ext->key_len);
  1257. pkey->len = ext->key_len;
  1258. if (pkey->len)
  1259. pkey->flags |= KEY_INFO_WPA_ENABLED;
  1260. /* Do this after zeroing key structure */
  1261. if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
  1262. pkey->flags |= KEY_INFO_WPA_MCAST;
  1263. } else {
  1264. pkey->flags |= KEY_INFO_WPA_UNICAST;
  1265. }
  1266. if (alg == IW_ENCODE_ALG_TKIP) {
  1267. pkey->type = KEY_TYPE_ID_TKIP;
  1268. } else if (alg == IW_ENCODE_ALG_CCMP) {
  1269. pkey->type = KEY_TYPE_ID_AES;
  1270. }
  1271. /* If WPA isn't enabled yet, do that now */
  1272. if ( assoc_req->secinfo.WPAenabled == 0
  1273. && assoc_req->secinfo.WPA2enabled == 0) {
  1274. assoc_req->secinfo.WPAenabled = 1;
  1275. assoc_req->secinfo.WPA2enabled = 1;
  1276. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1277. }
  1278. disable_wep (assoc_req);
  1279. }
  1280. out:
  1281. if (ret == 0) {
  1282. lbs_postpone_association_work(priv);
  1283. } else {
  1284. lbs_cancel_association_work(priv);
  1285. }
  1286. mutex_unlock(&priv->lock);
  1287. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1288. return ret;
  1289. }
  1290. static int lbs_set_genie(struct net_device *dev,
  1291. struct iw_request_info *info,
  1292. struct iw_point *dwrq,
  1293. char *extra)
  1294. {
  1295. struct lbs_private *priv = dev->priv;
  1296. int ret = 0;
  1297. struct assoc_request * assoc_req;
  1298. lbs_deb_enter(LBS_DEB_WEXT);
  1299. mutex_lock(&priv->lock);
  1300. assoc_req = lbs_get_association_request(priv);
  1301. if (!assoc_req) {
  1302. ret = -ENOMEM;
  1303. goto out;
  1304. }
  1305. if (dwrq->length > MAX_WPA_IE_LEN ||
  1306. (dwrq->length && extra == NULL)) {
  1307. ret = -EINVAL;
  1308. goto out;
  1309. }
  1310. if (dwrq->length) {
  1311. memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
  1312. assoc_req->wpa_ie_len = dwrq->length;
  1313. } else {
  1314. memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
  1315. assoc_req->wpa_ie_len = 0;
  1316. }
  1317. out:
  1318. if (ret == 0) {
  1319. set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
  1320. lbs_postpone_association_work(priv);
  1321. } else {
  1322. lbs_cancel_association_work(priv);
  1323. }
  1324. mutex_unlock(&priv->lock);
  1325. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1326. return ret;
  1327. }
  1328. static int lbs_get_genie(struct net_device *dev,
  1329. struct iw_request_info *info,
  1330. struct iw_point *dwrq,
  1331. char *extra)
  1332. {
  1333. int ret = 0;
  1334. struct lbs_private *priv = dev->priv;
  1335. lbs_deb_enter(LBS_DEB_WEXT);
  1336. if (priv->wpa_ie_len == 0) {
  1337. dwrq->length = 0;
  1338. goto out;
  1339. }
  1340. if (dwrq->length < priv->wpa_ie_len) {
  1341. ret = -E2BIG;
  1342. goto out;
  1343. }
  1344. dwrq->length = priv->wpa_ie_len;
  1345. memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
  1346. out:
  1347. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1348. return ret;
  1349. }
  1350. static int lbs_set_auth(struct net_device *dev,
  1351. struct iw_request_info *info,
  1352. struct iw_param *dwrq,
  1353. char *extra)
  1354. {
  1355. struct lbs_private *priv = dev->priv;
  1356. struct assoc_request * assoc_req;
  1357. int ret = 0;
  1358. int updated = 0;
  1359. lbs_deb_enter(LBS_DEB_WEXT);
  1360. mutex_lock(&priv->lock);
  1361. assoc_req = lbs_get_association_request(priv);
  1362. if (!assoc_req) {
  1363. ret = -ENOMEM;
  1364. goto out;
  1365. }
  1366. switch (dwrq->flags & IW_AUTH_INDEX) {
  1367. case IW_AUTH_TKIP_COUNTERMEASURES:
  1368. case IW_AUTH_CIPHER_PAIRWISE:
  1369. case IW_AUTH_CIPHER_GROUP:
  1370. case IW_AUTH_KEY_MGMT:
  1371. case IW_AUTH_DROP_UNENCRYPTED:
  1372. /*
  1373. * libertas does not use these parameters
  1374. */
  1375. break;
  1376. case IW_AUTH_WPA_VERSION:
  1377. if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
  1378. assoc_req->secinfo.WPAenabled = 0;
  1379. assoc_req->secinfo.WPA2enabled = 0;
  1380. disable_wpa (assoc_req);
  1381. }
  1382. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
  1383. assoc_req->secinfo.WPAenabled = 1;
  1384. assoc_req->secinfo.wep_enabled = 0;
  1385. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1386. }
  1387. if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
  1388. assoc_req->secinfo.WPA2enabled = 1;
  1389. assoc_req->secinfo.wep_enabled = 0;
  1390. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1391. }
  1392. updated = 1;
  1393. break;
  1394. case IW_AUTH_80211_AUTH_ALG:
  1395. if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
  1396. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
  1397. } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
  1398. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1399. } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
  1400. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
  1401. } else {
  1402. ret = -EINVAL;
  1403. }
  1404. updated = 1;
  1405. break;
  1406. case IW_AUTH_WPA_ENABLED:
  1407. if (dwrq->value) {
  1408. if (!assoc_req->secinfo.WPAenabled &&
  1409. !assoc_req->secinfo.WPA2enabled) {
  1410. assoc_req->secinfo.WPAenabled = 1;
  1411. assoc_req->secinfo.WPA2enabled = 1;
  1412. assoc_req->secinfo.wep_enabled = 0;
  1413. assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
  1414. }
  1415. } else {
  1416. assoc_req->secinfo.WPAenabled = 0;
  1417. assoc_req->secinfo.WPA2enabled = 0;
  1418. disable_wpa (assoc_req);
  1419. }
  1420. updated = 1;
  1421. break;
  1422. default:
  1423. ret = -EOPNOTSUPP;
  1424. break;
  1425. }
  1426. out:
  1427. if (ret == 0) {
  1428. if (updated)
  1429. set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
  1430. lbs_postpone_association_work(priv);
  1431. } else if (ret != -EOPNOTSUPP) {
  1432. lbs_cancel_association_work(priv);
  1433. }
  1434. mutex_unlock(&priv->lock);
  1435. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1436. return ret;
  1437. }
  1438. static int lbs_get_auth(struct net_device *dev,
  1439. struct iw_request_info *info,
  1440. struct iw_param *dwrq,
  1441. char *extra)
  1442. {
  1443. int ret = 0;
  1444. struct lbs_private *priv = dev->priv;
  1445. lbs_deb_enter(LBS_DEB_WEXT);
  1446. switch (dwrq->flags & IW_AUTH_INDEX) {
  1447. case IW_AUTH_WPA_VERSION:
  1448. dwrq->value = 0;
  1449. if (priv->secinfo.WPAenabled)
  1450. dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
  1451. if (priv->secinfo.WPA2enabled)
  1452. dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
  1453. if (!dwrq->value)
  1454. dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
  1455. break;
  1456. case IW_AUTH_80211_AUTH_ALG:
  1457. dwrq->value = priv->secinfo.auth_mode;
  1458. break;
  1459. case IW_AUTH_WPA_ENABLED:
  1460. if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
  1461. dwrq->value = 1;
  1462. break;
  1463. default:
  1464. ret = -EOPNOTSUPP;
  1465. }
  1466. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1467. return ret;
  1468. }
  1469. static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
  1470. struct iw_param *vwrq, char *extra)
  1471. {
  1472. int ret = 0;
  1473. struct lbs_private *priv = dev->priv;
  1474. u16 dbm;
  1475. lbs_deb_enter(LBS_DEB_WEXT);
  1476. if (vwrq->disabled) {
  1477. lbs_radio_ioctl(priv, RADIO_OFF);
  1478. return 0;
  1479. }
  1480. priv->preamble = CMD_TYPE_AUTO_PREAMBLE;
  1481. lbs_radio_ioctl(priv, RADIO_ON);
  1482. /* Userspace check in iwrange if it should use dBm or mW,
  1483. * therefore this should never happen... Jean II */
  1484. if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
  1485. return -EOPNOTSUPP;
  1486. } else
  1487. dbm = (u16) vwrq->value;
  1488. /* auto tx power control */
  1489. if (vwrq->fixed == 0)
  1490. dbm = 0xffff;
  1491. lbs_deb_wext("txpower set %d dbm\n", dbm);
  1492. ret = lbs_prepare_and_send_command(priv,
  1493. CMD_802_11_RF_TX_POWER,
  1494. CMD_ACT_TX_POWER_OPT_SET_LOW,
  1495. CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
  1496. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1497. return ret;
  1498. }
  1499. static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
  1500. struct iw_point *dwrq, char *extra)
  1501. {
  1502. struct lbs_private *priv = dev->priv;
  1503. lbs_deb_enter(LBS_DEB_WEXT);
  1504. /*
  1505. * Note : if dwrq->flags != 0, we should get the relevant SSID from
  1506. * the SSID list...
  1507. */
  1508. /*
  1509. * Get the current SSID
  1510. */
  1511. if (priv->connect_status == LBS_CONNECTED) {
  1512. memcpy(extra, priv->curbssparams.ssid,
  1513. priv->curbssparams.ssid_len);
  1514. extra[priv->curbssparams.ssid_len] = '\0';
  1515. } else {
  1516. memset(extra, 0, 32);
  1517. extra[priv->curbssparams.ssid_len] = '\0';
  1518. }
  1519. /*
  1520. * If none, we may want to get the one that was set
  1521. */
  1522. dwrq->length = priv->curbssparams.ssid_len;
  1523. dwrq->flags = 1; /* active */
  1524. lbs_deb_leave(LBS_DEB_WEXT);
  1525. return 0;
  1526. }
  1527. static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
  1528. struct iw_point *dwrq, char *extra)
  1529. {
  1530. struct lbs_private *priv = dev->priv;
  1531. int ret = 0;
  1532. u8 ssid[IW_ESSID_MAX_SIZE];
  1533. u8 ssid_len = 0;
  1534. struct assoc_request * assoc_req;
  1535. int in_ssid_len = dwrq->length;
  1536. lbs_deb_enter(LBS_DEB_WEXT);
  1537. /* Check the size of the string */
  1538. if (in_ssid_len > IW_ESSID_MAX_SIZE) {
  1539. ret = -E2BIG;
  1540. goto out;
  1541. }
  1542. memset(&ssid, 0, sizeof(ssid));
  1543. if (!dwrq->flags || !in_ssid_len) {
  1544. /* "any" SSID requested; leave SSID blank */
  1545. } else {
  1546. /* Specific SSID requested */
  1547. memcpy(&ssid, extra, in_ssid_len);
  1548. ssid_len = in_ssid_len;
  1549. }
  1550. if (!ssid_len) {
  1551. lbs_deb_wext("requested any SSID\n");
  1552. } else {
  1553. lbs_deb_wext("requested SSID '%s'\n",
  1554. escape_essid(ssid, ssid_len));
  1555. }
  1556. out:
  1557. mutex_lock(&priv->lock);
  1558. if (ret == 0) {
  1559. /* Get or create the current association request */
  1560. assoc_req = lbs_get_association_request(priv);
  1561. if (!assoc_req) {
  1562. ret = -ENOMEM;
  1563. } else {
  1564. /* Copy the SSID to the association request */
  1565. memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
  1566. assoc_req->ssid_len = ssid_len;
  1567. set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
  1568. lbs_postpone_association_work(priv);
  1569. }
  1570. }
  1571. /* Cancel the association request if there was an error */
  1572. if (ret != 0) {
  1573. lbs_cancel_association_work(priv);
  1574. }
  1575. mutex_unlock(&priv->lock);
  1576. lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
  1577. return ret;
  1578. }
  1579. /**
  1580. * @brief Connect to the AP or Ad-hoc Network with specific bssid
  1581. *
  1582. * @param dev A pointer to net_device structure
  1583. * @param info A pointer to iw_request_info structure
  1584. * @param awrq A pointer to iw_param structure
  1585. * @param extra A pointer to extra data buf
  1586. * @return 0 --success, otherwise fail
  1587. */
  1588. static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
  1589. struct sockaddr *awrq, char *extra)
  1590. {
  1591. struct lbs_private *priv = dev->priv;
  1592. struct assoc_request * assoc_req;
  1593. int ret = 0;
  1594. DECLARE_MAC_BUF(mac);
  1595. lbs_deb_enter(LBS_DEB_WEXT);
  1596. if (awrq->sa_family != ARPHRD_ETHER)
  1597. return -EINVAL;
  1598. lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
  1599. mutex_lock(&priv->lock);
  1600. /* Get or create the current association request */
  1601. assoc_req = lbs_get_association_request(priv);
  1602. if (!assoc_req) {
  1603. lbs_cancel_association_work(priv);
  1604. ret = -ENOMEM;
  1605. } else {
  1606. /* Copy the BSSID to the association request */
  1607. memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
  1608. set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
  1609. lbs_postpone_association_work(priv);
  1610. }
  1611. mutex_unlock(&priv->lock);
  1612. return ret;
  1613. }
  1614. void lbs_get_fwversion(struct lbs_private *priv, char *fwversion, int maxlen)
  1615. {
  1616. char fwver[32];
  1617. mutex_lock(&priv->lock);
  1618. if (priv->fwreleasenumber[3] == 0)
  1619. sprintf(fwver, "%u.%u.%u",
  1620. priv->fwreleasenumber[2],
  1621. priv->fwreleasenumber[1],
  1622. priv->fwreleasenumber[0]);
  1623. else
  1624. sprintf(fwver, "%u.%u.%u.p%u",
  1625. priv->fwreleasenumber[2],
  1626. priv->fwreleasenumber[1],
  1627. priv->fwreleasenumber[0],
  1628. priv->fwreleasenumber[3]);
  1629. mutex_unlock(&priv->lock);
  1630. snprintf(fwversion, maxlen, fwver);
  1631. }
  1632. /*
  1633. * iwconfig settable callbacks
  1634. */
  1635. static const iw_handler lbs_handler[] = {
  1636. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1637. (iw_handler) lbs_get_name, /* SIOCGIWNAME */
  1638. (iw_handler) NULL, /* SIOCSIWNWID */
  1639. (iw_handler) NULL, /* SIOCGIWNWID */
  1640. (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
  1641. (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
  1642. (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
  1643. (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
  1644. (iw_handler) NULL, /* SIOCSIWSENS */
  1645. (iw_handler) NULL, /* SIOCGIWSENS */
  1646. (iw_handler) NULL, /* SIOCSIWRANGE */
  1647. (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
  1648. (iw_handler) NULL, /* SIOCSIWPRIV */
  1649. (iw_handler) NULL, /* SIOCGIWPRIV */
  1650. (iw_handler) NULL, /* SIOCSIWSTATS */
  1651. (iw_handler) NULL, /* SIOCGIWSTATS */
  1652. iw_handler_set_spy, /* SIOCSIWSPY */
  1653. iw_handler_get_spy, /* SIOCGIWSPY */
  1654. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1655. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1656. (iw_handler) lbs_set_wap, /* SIOCSIWAP */
  1657. (iw_handler) lbs_get_wap, /* SIOCGIWAP */
  1658. (iw_handler) NULL, /* SIOCSIWMLME */
  1659. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1660. (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
  1661. (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
  1662. (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
  1663. (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
  1664. (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
  1665. (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
  1666. (iw_handler) NULL, /* -- hole -- */
  1667. (iw_handler) NULL, /* -- hole -- */
  1668. (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
  1669. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1670. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1671. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1672. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1673. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1674. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1675. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1676. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1677. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1678. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1679. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1680. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1681. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1682. (iw_handler) NULL, /* -- hole -- */
  1683. (iw_handler) NULL, /* -- hole -- */
  1684. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1685. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1686. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1687. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1688. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1689. (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
  1690. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1691. };
  1692. static const iw_handler mesh_wlan_handler[] = {
  1693. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1694. (iw_handler) lbs_get_name, /* SIOCGIWNAME */
  1695. (iw_handler) NULL, /* SIOCSIWNWID */
  1696. (iw_handler) NULL, /* SIOCGIWNWID */
  1697. (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
  1698. (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
  1699. (iw_handler) NULL, /* SIOCSIWMODE */
  1700. (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
  1701. (iw_handler) NULL, /* SIOCSIWSENS */
  1702. (iw_handler) NULL, /* SIOCGIWSENS */
  1703. (iw_handler) NULL, /* SIOCSIWRANGE */
  1704. (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
  1705. (iw_handler) NULL, /* SIOCSIWPRIV */
  1706. (iw_handler) NULL, /* SIOCGIWPRIV */
  1707. (iw_handler) NULL, /* SIOCSIWSTATS */
  1708. (iw_handler) NULL, /* SIOCGIWSTATS */
  1709. iw_handler_set_spy, /* SIOCSIWSPY */
  1710. iw_handler_get_spy, /* SIOCGIWSPY */
  1711. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1712. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1713. (iw_handler) NULL, /* SIOCSIWAP */
  1714. (iw_handler) NULL, /* SIOCGIWAP */
  1715. (iw_handler) NULL, /* SIOCSIWMLME */
  1716. (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
  1717. (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
  1718. (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
  1719. (iw_handler) NULL, /* SIOCSIWESSID */
  1720. (iw_handler) NULL, /* SIOCGIWESSID */
  1721. (iw_handler) NULL, /* SIOCSIWNICKN */
  1722. (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
  1723. (iw_handler) NULL, /* -- hole -- */
  1724. (iw_handler) NULL, /* -- hole -- */
  1725. (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
  1726. (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
  1727. (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
  1728. (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
  1729. (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
  1730. (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
  1731. (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
  1732. (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
  1733. (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
  1734. (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
  1735. (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
  1736. (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
  1737. (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
  1738. (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
  1739. (iw_handler) NULL, /* -- hole -- */
  1740. (iw_handler) NULL, /* -- hole -- */
  1741. (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
  1742. (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
  1743. (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
  1744. (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
  1745. (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
  1746. (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
  1747. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1748. };
  1749. struct iw_handler_def lbs_handler_def = {
  1750. .num_standard = ARRAY_SIZE(lbs_handler),
  1751. .standard = (iw_handler *) lbs_handler,
  1752. .get_wireless_stats = lbs_get_wireless_stats,
  1753. };
  1754. struct iw_handler_def mesh_handler_def = {
  1755. .num_standard = ARRAY_SIZE(mesh_wlan_handler),
  1756. .standard = (iw_handler *) mesh_wlan_handler,
  1757. .get_wireless_stats = lbs_get_wireless_stats,
  1758. };