rtl871x_ioctl_linux.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348
  1. /******************************************************************************
  2. * rtl871x_ioctl_linux.c
  3. *
  4. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  5. * Linux device driver for RTL8192SU
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * Modifications for inclusion into the Linux staging tree are
  21. * Copyright(c) 2010 Larry Finger. All rights reserved.
  22. *
  23. * Contact information:
  24. * WLAN FAE <wlanfae@realtek.com>
  25. * Larry Finger <Larry.Finger@lwfinger.net>
  26. *
  27. ******************************************************************************/
  28. #define _RTL871X_IOCTL_LINUX_C_
  29. #define _RTL871X_MP_IOCTL_C_
  30. #include "osdep_service.h"
  31. #include "drv_types.h"
  32. #include "wlan_bssdef.h"
  33. #include "rtl871x_debug.h"
  34. #include "wifi.h"
  35. #include "rtl871x_mlme.h"
  36. #include "rtl871x_ioctl.h"
  37. #include "rtl871x_ioctl_set.h"
  38. #include "rtl871x_mp_ioctl.h"
  39. #include "mlme_osdep.h"
  40. #include <linux/wireless.h>
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/io.h>
  44. #include <linux/semaphore.h>
  45. #include <net/iw_handler.h>
  46. #include <linux/if_arp.h>
  47. #include <linux/etherdevice.h>
  48. #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 0x1E)
  49. #define SCAN_ITEM_SIZE 768
  50. #define MAX_CUSTOM_LEN 64
  51. #define RATE_COUNT 4
  52. static const u32 rtl8180_rates[] = {1000000, 2000000, 5500000, 11000000,
  53. 6000000, 9000000, 12000000, 18000000,
  54. 24000000, 36000000, 48000000, 54000000};
  55. static const long ieee80211_wlan_frequencies[] = {
  56. 2412, 2417, 2422, 2427,
  57. 2432, 2437, 2442, 2447,
  58. 2452, 2457, 2462, 2467,
  59. 2472, 2484
  60. };
  61. static const char * const iw_operation_mode[] = {
  62. "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary",
  63. "Monitor"
  64. };
  65. void r8712_indicate_wx_assoc_event(struct _adapter *padapter)
  66. {
  67. union iwreq_data wrqu;
  68. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  69. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  70. memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress,
  71. ETH_ALEN);
  72. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  73. }
  74. void r8712_indicate_wx_disassoc_event(struct _adapter *padapter)
  75. {
  76. union iwreq_data wrqu;
  77. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  78. eth_zero_addr(wrqu.ap_addr.sa_data);
  79. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  80. }
  81. static inline void handle_pairwise_key(struct sta_info *psta,
  82. struct ieee_param *param,
  83. struct _adapter *padapter)
  84. {
  85. /* pairwise key */
  86. memcpy(psta->x_UncstKey.skey, param->u.crypt.key,
  87. (param->u.crypt. key_len > 16 ? 16 : param->u.crypt.key_len));
  88. if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
  89. memcpy(psta->tkiptxmickey. skey, &(param->u.crypt.
  90. key[16]), 8);
  91. memcpy(psta->tkiprxmickey. skey, &(param->u.crypt.
  92. key[24]), 8);
  93. padapter->securitypriv. busetkipkey = false;
  94. mod_timer(&padapter->securitypriv.tkip_timer,
  95. jiffies + msecs_to_jiffies(50));
  96. }
  97. r8712_setstakey_cmd(padapter, (unsigned char *)psta, true);
  98. }
  99. static inline void handle_group_key(struct ieee_param *param,
  100. struct _adapter *padapter)
  101. {
  102. if (param->u.crypt.idx > 0 &&
  103. param->u.crypt.idx < 3) {
  104. /* group key idx is 1 or 2 */
  105. memcpy(padapter->securitypriv.XGrpKey[param->u.crypt.
  106. idx - 1].skey, param->u.crypt.key,
  107. (param->u.crypt.key_len > 16 ? 16 :
  108. param->u.crypt.key_len));
  109. memcpy(padapter->securitypriv.XGrptxmickey[param->
  110. u.crypt.idx - 1].skey, &(param->u.crypt.key[16]), 8);
  111. memcpy(padapter->securitypriv. XGrprxmickey[param->
  112. u.crypt.idx - 1].skey, &(param->u.crypt.key[24]), 8);
  113. padapter->securitypriv.binstallGrpkey = true;
  114. r8712_set_key(padapter, &padapter->securitypriv,
  115. param->u.crypt.idx);
  116. if (padapter->registrypriv.power_mgnt > PS_MODE_ACTIVE) {
  117. if (padapter->registrypriv.power_mgnt != padapter->
  118. pwrctrlpriv.pwr_mode)
  119. mod_timer(&padapter->mlmepriv.dhcp_timer,
  120. jiffies + msecs_to_jiffies(60000));
  121. }
  122. }
  123. }
  124. static inline char *translate_scan(struct _adapter *padapter,
  125. struct iw_request_info *info,
  126. struct wlan_network *pnetwork,
  127. char *start, char *stop)
  128. {
  129. struct iw_event iwe;
  130. struct ieee80211_ht_cap *pht_capie;
  131. char *current_val;
  132. s8 *p;
  133. u32 i = 0, ht_ielen = 0;
  134. u16 cap, ht_cap = false, mcs_rate;
  135. u8 rssi;
  136. if ((pnetwork->network.Configuration.DSConfig < 1) ||
  137. (pnetwork->network.Configuration.DSConfig > 14)) {
  138. if (pnetwork->network.Configuration.DSConfig < 1)
  139. pnetwork->network.Configuration.DSConfig = 1;
  140. else
  141. pnetwork->network.Configuration.DSConfig = 14;
  142. }
  143. /* AP MAC address */
  144. iwe.cmd = SIOCGIWAP;
  145. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  146. ether_addr_copy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress);
  147. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
  148. /* Add the ESSID */
  149. iwe.cmd = SIOCGIWESSID;
  150. iwe.u.data.flags = 1;
  151. iwe.u.data.length = min_t(u32, pnetwork->network.Ssid.SsidLength, 32);
  152. start = iwe_stream_add_point(info, start, stop, &iwe,
  153. pnetwork->network.Ssid.Ssid);
  154. /* parsing HT_CAP_IE */
  155. p = r8712_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_,
  156. &ht_ielen, pnetwork->network.IELength - 12);
  157. if (p && ht_ielen > 0) {
  158. ht_cap = true;
  159. pht_capie = (struct ieee80211_ht_cap *)(p + 2);
  160. memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
  161. }
  162. /* Add the protocol name */
  163. iwe.cmd = SIOCGIWNAME;
  164. if (r8712_is_cckratesonly_included(pnetwork->network.rates)) {
  165. if (ht_cap)
  166. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
  167. else
  168. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
  169. } else if (r8712_is_cckrates_included(pnetwork->network.rates)) {
  170. if (ht_cap)
  171. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
  172. else
  173. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
  174. } else {
  175. if (ht_cap)
  176. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
  177. else
  178. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
  179. }
  180. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
  181. /* Add mode */
  182. iwe.cmd = SIOCGIWMODE;
  183. memcpy((u8 *)&cap, r8712_get_capability_from_ie(pnetwork->network.IEs),
  184. 2);
  185. le16_to_cpus(&cap);
  186. if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
  187. if (cap & WLAN_CAPABILITY_BSS)
  188. iwe.u.mode = (u32)IW_MODE_MASTER;
  189. else
  190. iwe.u.mode = (u32)IW_MODE_ADHOC;
  191. start = iwe_stream_add_event(info, start, stop, &iwe,
  192. IW_EV_UINT_LEN);
  193. }
  194. /* Add frequency/channel */
  195. iwe.cmd = SIOCGIWFREQ;
  196. {
  197. /* check legal index */
  198. u8 dsconfig = pnetwork->network.Configuration.DSConfig;
  199. if (dsconfig >= 1 && dsconfig <= sizeof(
  200. ieee80211_wlan_frequencies) / sizeof(long))
  201. iwe.u.freq.m = (s32)(ieee80211_wlan_frequencies[
  202. pnetwork->network.Configuration.
  203. DSConfig - 1] * 100000);
  204. else
  205. iwe.u.freq.m = 0;
  206. }
  207. iwe.u.freq.e = (s16)1;
  208. iwe.u.freq.i = (u8)pnetwork->network.Configuration.DSConfig;
  209. start = iwe_stream_add_event(info, start, stop, &iwe,
  210. IW_EV_FREQ_LEN);
  211. /* Add encryption capability */
  212. iwe.cmd = SIOCGIWENCODE;
  213. if (cap & WLAN_CAPABILITY_PRIVACY)
  214. iwe.u.data.flags = (u16)(IW_ENCODE_ENABLED |
  215. IW_ENCODE_NOKEY);
  216. else
  217. iwe.u.data.flags = (u16)(IW_ENCODE_DISABLED);
  218. iwe.u.data.length = (u16)0;
  219. start = iwe_stream_add_point(info, start, stop, &iwe,
  220. pnetwork->network.Ssid.Ssid);
  221. /*Add basic and extended rates */
  222. current_val = start + iwe_stream_lcp_len(info);
  223. iwe.cmd = SIOCGIWRATE;
  224. iwe.u.bitrate.fixed = 0;
  225. iwe.u.bitrate.disabled = 0;
  226. iwe.u.bitrate.value = 0;
  227. i = 0;
  228. while (pnetwork->network.rates[i] != 0) {
  229. /* Bit rate given in 500 kb/s units */
  230. iwe.u.bitrate.value = (pnetwork->network.rates[i++] &
  231. 0x7F) * 500000;
  232. current_val = iwe_stream_add_value(info, start, current_val,
  233. stop, &iwe, IW_EV_PARAM_LEN);
  234. }
  235. /* Check if we added any event */
  236. if ((current_val - start) > iwe_stream_lcp_len(info))
  237. start = current_val;
  238. /* parsing WPA/WPA2 IE */
  239. {
  240. u8 buf[MAX_WPA_IE_LEN];
  241. u8 wpa_ie[255], rsn_ie[255];
  242. u16 wpa_len = 0, rsn_len = 0;
  243. int n;
  244. r8712_get_sec_ie(pnetwork->network.IEs,
  245. pnetwork->network.IELength, rsn_ie, &rsn_len,
  246. wpa_ie, &wpa_len);
  247. if (wpa_len > 0) {
  248. memset(buf, 0, MAX_WPA_IE_LEN);
  249. n = sprintf(buf, "wpa_ie=");
  250. for (i = 0; i < wpa_len; i++) {
  251. n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
  252. "%02x", wpa_ie[i]);
  253. if (n >= MAX_WPA_IE_LEN)
  254. break;
  255. }
  256. memset(&iwe, 0, sizeof(iwe));
  257. iwe.cmd = IWEVCUSTOM;
  258. iwe.u.data.length = (u16)strlen(buf);
  259. start = iwe_stream_add_point(info, start, stop,
  260. &iwe, buf);
  261. memset(&iwe, 0, sizeof(iwe));
  262. iwe.cmd = IWEVGENIE;
  263. iwe.u.data.length = (u16)wpa_len;
  264. start = iwe_stream_add_point(info, start, stop,
  265. &iwe, wpa_ie);
  266. }
  267. if (rsn_len > 0) {
  268. memset(buf, 0, MAX_WPA_IE_LEN);
  269. n = sprintf(buf, "rsn_ie=");
  270. for (i = 0; i < rsn_len; i++) {
  271. n += snprintf(buf + n, MAX_WPA_IE_LEN - n,
  272. "%02x", rsn_ie[i]);
  273. if (n >= MAX_WPA_IE_LEN)
  274. break;
  275. }
  276. memset(&iwe, 0, sizeof(iwe));
  277. iwe.cmd = IWEVCUSTOM;
  278. iwe.u.data.length = strlen(buf);
  279. start = iwe_stream_add_point(info, start, stop,
  280. &iwe, buf);
  281. memset(&iwe, 0, sizeof(iwe));
  282. iwe.cmd = IWEVGENIE;
  283. iwe.u.data.length = rsn_len;
  284. start = iwe_stream_add_point(info, start, stop, &iwe,
  285. rsn_ie);
  286. }
  287. }
  288. { /* parsing WPS IE */
  289. u8 wps_ie[512];
  290. uint wps_ielen;
  291. if (r8712_get_wps_ie(pnetwork->network.IEs,
  292. pnetwork->network.IELength,
  293. wps_ie, &wps_ielen)) {
  294. if (wps_ielen > 2) {
  295. iwe.cmd = IWEVGENIE;
  296. iwe.u.data.length = (u16)wps_ielen;
  297. start = iwe_stream_add_point(info, start, stop,
  298. &iwe, wps_ie);
  299. }
  300. }
  301. }
  302. /* Add quality statistics */
  303. iwe.cmd = IWEVQUAL;
  304. rssi = r8712_signal_scale_mapping(pnetwork->network.Rssi);
  305. /* we only update signal_level (signal strength) that is rssi. */
  306. iwe.u.qual.updated = (u8)(IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_UPDATED |
  307. IW_QUAL_NOISE_INVALID);
  308. iwe.u.qual.level = rssi; /* signal strength */
  309. iwe.u.qual.qual = 0; /* signal quality */
  310. iwe.u.qual.noise = 0; /* noise level */
  311. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
  312. /* how to translate rssi to ?% */
  313. return start;
  314. }
  315. static int wpa_set_auth_algs(struct net_device *dev, u32 value)
  316. {
  317. struct _adapter *padapter = netdev_priv(dev);
  318. int ret = 0;
  319. if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
  320. padapter->securitypriv.ndisencryptstatus =
  321. Ndis802_11Encryption1Enabled;
  322. padapter->securitypriv.ndisauthtype =
  323. Ndis802_11AuthModeAutoSwitch;
  324. padapter->securitypriv.AuthAlgrthm = 3;
  325. } else if (value & AUTH_ALG_SHARED_KEY) {
  326. padapter->securitypriv.ndisencryptstatus =
  327. Ndis802_11Encryption1Enabled;
  328. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
  329. padapter->securitypriv.AuthAlgrthm = 1;
  330. } else if (value & AUTH_ALG_OPEN_SYSTEM) {
  331. if (padapter->securitypriv.ndisauthtype <
  332. Ndis802_11AuthModeWPAPSK) {
  333. padapter->securitypriv.ndisauthtype =
  334. Ndis802_11AuthModeOpen;
  335. padapter->securitypriv.AuthAlgrthm = 0;
  336. }
  337. } else {
  338. ret = -EINVAL;
  339. }
  340. return ret;
  341. }
  342. static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
  343. u32 param_len)
  344. {
  345. int ret = 0;
  346. u32 wep_key_idx, wep_key_len = 0;
  347. struct NDIS_802_11_WEP *pwep = NULL;
  348. struct _adapter *padapter = netdev_priv(dev);
  349. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  350. struct security_priv *psecuritypriv = &padapter->securitypriv;
  351. param->u.crypt.err = 0;
  352. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  353. if (param_len != (u32)((u8 *) param->u.crypt.key - (u8 *)param) +
  354. param->u.crypt.key_len)
  355. return -EINVAL;
  356. if (is_broadcast_ether_addr(param->sta_addr)) {
  357. if (param->u.crypt.idx >= WEP_KEYS) {
  358. /* for large key indices, set the default (0) */
  359. param->u.crypt.idx = 0;
  360. }
  361. } else {
  362. return -EINVAL;
  363. }
  364. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  365. netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__);
  366. padapter->securitypriv.ndisencryptstatus =
  367. Ndis802_11Encryption1Enabled;
  368. padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
  369. padapter->securitypriv.XGrpPrivacy = _WEP40_;
  370. wep_key_idx = param->u.crypt.idx;
  371. wep_key_len = param->u.crypt.key_len;
  372. if (wep_key_idx >= WEP_KEYS)
  373. wep_key_idx = 0;
  374. if (wep_key_len > 0) {
  375. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  376. pwep = kmalloc((u32)(wep_key_len +
  377. FIELD_OFFSET(struct NDIS_802_11_WEP,
  378. KeyMaterial)), GFP_ATOMIC);
  379. if (pwep == NULL)
  380. return -ENOMEM;
  381. memset(pwep, 0, sizeof(struct NDIS_802_11_WEP));
  382. pwep->KeyLength = wep_key_len;
  383. pwep->Length = wep_key_len +
  384. FIELD_OFFSET(struct NDIS_802_11_WEP,
  385. KeyMaterial);
  386. if (wep_key_len == 13) {
  387. padapter->securitypriv.PrivacyAlgrthm =
  388. _WEP104_;
  389. padapter->securitypriv.XGrpPrivacy =
  390. _WEP104_;
  391. }
  392. } else {
  393. return -EINVAL;
  394. }
  395. pwep->KeyIndex = wep_key_idx;
  396. pwep->KeyIndex |= 0x80000000;
  397. memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
  398. if (param->u.crypt.set_tx) {
  399. if (r8712_set_802_11_add_wep(padapter, pwep) ==
  400. (u8)_FAIL)
  401. ret = -EOPNOTSUPP;
  402. } else {
  403. /* don't update "psecuritypriv->PrivacyAlgrthm" and
  404. * "psecuritypriv->PrivacyKeyIndex=keyid", but can
  405. * r8712_set_key to fw/cam
  406. */
  407. if (wep_key_idx >= WEP_KEYS) {
  408. ret = -EOPNOTSUPP;
  409. goto exit;
  410. }
  411. memcpy(&(psecuritypriv->DefKey[wep_key_idx].
  412. skey[0]), pwep->KeyMaterial,
  413. pwep->KeyLength);
  414. psecuritypriv->DefKeylen[wep_key_idx] =
  415. pwep->KeyLength;
  416. r8712_set_key(padapter, psecuritypriv, wep_key_idx);
  417. }
  418. goto exit;
  419. }
  420. if (padapter->securitypriv.AuthAlgrthm == 2) { /* 802_1x */
  421. struct sta_info *psta, *pbcmc_sta;
  422. struct sta_priv *pstapriv = &padapter->stapriv;
  423. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE |
  424. WIFI_MP_STATE)) { /* sta mode */
  425. psta = r8712_get_stainfo(pstapriv,
  426. get_bssid(pmlmepriv));
  427. if (psta) {
  428. psta->ieee8021x_blocked = false;
  429. if ((padapter->securitypriv.ndisencryptstatus ==
  430. Ndis802_11Encryption2Enabled) ||
  431. (padapter->securitypriv.ndisencryptstatus ==
  432. Ndis802_11Encryption3Enabled))
  433. psta->XPrivacy = padapter->
  434. securitypriv.PrivacyAlgrthm;
  435. if (param->u.crypt.set_tx == 1)
  436. handle_pairwise_key(psta, param,
  437. padapter);
  438. else /* group key */
  439. handle_group_key(param, padapter);
  440. }
  441. pbcmc_sta = r8712_get_bcmc_stainfo(padapter);
  442. if (pbcmc_sta) {
  443. pbcmc_sta->ieee8021x_blocked = false;
  444. if ((padapter->securitypriv.ndisencryptstatus ==
  445. Ndis802_11Encryption2Enabled) ||
  446. (padapter->securitypriv.ndisencryptstatus ==
  447. Ndis802_11Encryption3Enabled))
  448. pbcmc_sta->XPrivacy =
  449. padapter->securitypriv.
  450. PrivacyAlgrthm;
  451. }
  452. }
  453. }
  454. exit:
  455. kfree(pwep);
  456. return ret;
  457. }
  458. static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
  459. unsigned short ielen)
  460. {
  461. u8 *buf = NULL;
  462. int group_cipher = 0, pairwise_cipher = 0;
  463. int ret = 0;
  464. if ((ielen > MAX_WPA_IE_LEN) || (pie == NULL))
  465. return -EINVAL;
  466. if (ielen) {
  467. buf = kmemdup(pie, ielen, GFP_ATOMIC);
  468. if (buf == NULL)
  469. return -ENOMEM;
  470. if (ielen < RSN_HEADER_LEN) {
  471. ret = -EINVAL;
  472. goto exit;
  473. }
  474. if (r8712_parse_wpa_ie(buf, ielen, &group_cipher,
  475. &pairwise_cipher) == _SUCCESS) {
  476. padapter->securitypriv.AuthAlgrthm = 2;
  477. padapter->securitypriv.ndisauthtype =
  478. Ndis802_11AuthModeWPAPSK;
  479. }
  480. if (r8712_parse_wpa2_ie(buf, ielen, &group_cipher,
  481. &pairwise_cipher) == _SUCCESS) {
  482. padapter->securitypriv.AuthAlgrthm = 2;
  483. padapter->securitypriv.ndisauthtype =
  484. Ndis802_11AuthModeWPA2PSK;
  485. }
  486. switch (group_cipher) {
  487. case WPA_CIPHER_NONE:
  488. padapter->securitypriv.XGrpPrivacy =
  489. _NO_PRIVACY_;
  490. padapter->securitypriv.ndisencryptstatus =
  491. Ndis802_11EncryptionDisabled;
  492. break;
  493. case WPA_CIPHER_WEP40:
  494. padapter->securitypriv.XGrpPrivacy = _WEP40_;
  495. padapter->securitypriv.ndisencryptstatus =
  496. Ndis802_11Encryption1Enabled;
  497. break;
  498. case WPA_CIPHER_TKIP:
  499. padapter->securitypriv.XGrpPrivacy = _TKIP_;
  500. padapter->securitypriv.ndisencryptstatus =
  501. Ndis802_11Encryption2Enabled;
  502. break;
  503. case WPA_CIPHER_CCMP:
  504. padapter->securitypriv.XGrpPrivacy = _AES_;
  505. padapter->securitypriv.ndisencryptstatus =
  506. Ndis802_11Encryption3Enabled;
  507. break;
  508. case WPA_CIPHER_WEP104:
  509. padapter->securitypriv.XGrpPrivacy = _WEP104_;
  510. padapter->securitypriv.ndisencryptstatus =
  511. Ndis802_11Encryption1Enabled;
  512. break;
  513. }
  514. switch (pairwise_cipher) {
  515. case WPA_CIPHER_NONE:
  516. padapter->securitypriv.PrivacyAlgrthm =
  517. _NO_PRIVACY_;
  518. padapter->securitypriv.ndisencryptstatus =
  519. Ndis802_11EncryptionDisabled;
  520. break;
  521. case WPA_CIPHER_WEP40:
  522. padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
  523. padapter->securitypriv.ndisencryptstatus =
  524. Ndis802_11Encryption1Enabled;
  525. break;
  526. case WPA_CIPHER_TKIP:
  527. padapter->securitypriv.PrivacyAlgrthm = _TKIP_;
  528. padapter->securitypriv.ndisencryptstatus =
  529. Ndis802_11Encryption2Enabled;
  530. break;
  531. case WPA_CIPHER_CCMP:
  532. padapter->securitypriv.PrivacyAlgrthm = _AES_;
  533. padapter->securitypriv.ndisencryptstatus =
  534. Ndis802_11Encryption3Enabled;
  535. break;
  536. case WPA_CIPHER_WEP104:
  537. padapter->securitypriv.PrivacyAlgrthm = _WEP104_;
  538. padapter->securitypriv.ndisencryptstatus =
  539. Ndis802_11Encryption1Enabled;
  540. break;
  541. }
  542. padapter->securitypriv.wps_phase = false;
  543. {/* set wps_ie */
  544. u16 cnt = 0;
  545. u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  546. while (cnt < ielen) {
  547. eid = buf[cnt];
  548. if ((eid == _VENDOR_SPECIFIC_IE_) &&
  549. (!memcmp(&buf[cnt + 2], wps_oui, 4))) {
  550. netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE\n");
  551. padapter->securitypriv.wps_ie_len =
  552. ((buf[cnt + 1] + 2) <
  553. (MAX_WPA_IE_LEN << 2)) ?
  554. (buf[cnt + 1] + 2) :
  555. (MAX_WPA_IE_LEN << 2);
  556. memcpy(padapter->securitypriv.wps_ie,
  557. &buf[cnt],
  558. padapter->securitypriv.wps_ie_len);
  559. padapter->securitypriv.wps_phase =
  560. true;
  561. netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE, wps_phase==true\n");
  562. cnt += buf[cnt + 1] + 2;
  563. break;
  564. } else {
  565. cnt += buf[cnt + 1] + 2;
  566. }
  567. }
  568. }
  569. }
  570. exit:
  571. kfree(buf);
  572. return ret;
  573. }
  574. static int r8711_wx_get_name(struct net_device *dev,
  575. struct iw_request_info *info,
  576. union iwreq_data *wrqu, char *extra)
  577. {
  578. struct _adapter *padapter = netdev_priv(dev);
  579. u32 ht_ielen = 0;
  580. char *p;
  581. u8 ht_cap = false;
  582. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  583. struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
  584. u8 *prates;
  585. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ==
  586. true) {
  587. /* parsing HT_CAP_IE */
  588. p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_,
  589. &ht_ielen, pcur_bss->IELength - 12);
  590. if (p && ht_ielen > 0)
  591. ht_cap = true;
  592. prates = pcur_bss->rates;
  593. if (r8712_is_cckratesonly_included(prates)) {
  594. if (ht_cap)
  595. snprintf(wrqu->name, IFNAMSIZ,
  596. "IEEE 802.11bn");
  597. else
  598. snprintf(wrqu->name, IFNAMSIZ,
  599. "IEEE 802.11b");
  600. } else if (r8712_is_cckrates_included(prates)) {
  601. if (ht_cap)
  602. snprintf(wrqu->name, IFNAMSIZ,
  603. "IEEE 802.11bgn");
  604. else
  605. snprintf(wrqu->name, IFNAMSIZ,
  606. "IEEE 802.11bg");
  607. } else {
  608. if (ht_cap)
  609. snprintf(wrqu->name, IFNAMSIZ,
  610. "IEEE 802.11gn");
  611. else
  612. snprintf(wrqu->name, IFNAMSIZ,
  613. "IEEE 802.11g");
  614. }
  615. } else {
  616. snprintf(wrqu->name, IFNAMSIZ, "unassociated");
  617. }
  618. return 0;
  619. }
  620. static const long frequency_list[] = {
  621. 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462,
  622. 2467, 2472, 2484, 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
  623. 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210,
  624. 5220, 5230, 5240, 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560,
  625. 5580, 5600, 5620, 5640, 5660, 5680, 5700, 5745, 5765, 5785, 5805,
  626. 5825
  627. };
  628. static int r8711_wx_set_freq(struct net_device *dev,
  629. struct iw_request_info *info,
  630. union iwreq_data *wrqu, char *extra)
  631. {
  632. struct _adapter *padapter = netdev_priv(dev);
  633. struct iw_freq *fwrq = &wrqu->freq;
  634. int rc = 0;
  635. /* If setting by frequency, convert to a channel */
  636. if ((fwrq->e == 1) &&
  637. (fwrq->m >= (int) 2.412e8) &&
  638. (fwrq->m <= (int) 2.487e8)) {
  639. int f = fwrq->m / 100000;
  640. int c = 0;
  641. while ((c < 14) && (f != frequency_list[c]))
  642. c++;
  643. fwrq->e = 0;
  644. fwrq->m = c + 1;
  645. }
  646. /* Setting by channel number */
  647. if ((fwrq->m > 14) || (fwrq->e > 0)) {
  648. rc = -EOPNOTSUPP;
  649. } else {
  650. int channel = fwrq->m;
  651. if ((channel < 1) || (channel > 14)) {
  652. rc = -EINVAL;
  653. } else {
  654. /* Yes ! We can set it !!! */
  655. padapter->registrypriv.channel = channel;
  656. }
  657. }
  658. return rc;
  659. }
  660. static int r8711_wx_get_freq(struct net_device *dev,
  661. struct iw_request_info *info,
  662. union iwreq_data *wrqu, char *extra)
  663. {
  664. struct _adapter *padapter = netdev_priv(dev);
  665. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  666. struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
  667. if (check_fwstate(pmlmepriv, _FW_LINKED)) {
  668. wrqu->freq.m = ieee80211_wlan_frequencies[
  669. pcur_bss->Configuration.DSConfig - 1] * 100000;
  670. wrqu->freq.e = 1;
  671. wrqu->freq.i = pcur_bss->Configuration.DSConfig;
  672. } else {
  673. return -ENOLINK;
  674. }
  675. return 0;
  676. }
  677. static int r8711_wx_set_mode(struct net_device *dev,
  678. struct iw_request_info *a,
  679. union iwreq_data *wrqu, char *b)
  680. {
  681. struct _adapter *padapter = netdev_priv(dev);
  682. enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  683. switch (wrqu->mode) {
  684. case IW_MODE_AUTO:
  685. networkType = Ndis802_11AutoUnknown;
  686. break;
  687. case IW_MODE_ADHOC:
  688. networkType = Ndis802_11IBSS;
  689. break;
  690. case IW_MODE_MASTER:
  691. networkType = Ndis802_11APMode;
  692. break;
  693. case IW_MODE_INFRA:
  694. networkType = Ndis802_11Infrastructure;
  695. break;
  696. default:
  697. return -EINVAL;
  698. }
  699. if (Ndis802_11APMode == networkType)
  700. r8712_setopmode_cmd(padapter, networkType);
  701. else
  702. r8712_setopmode_cmd(padapter, Ndis802_11AutoUnknown);
  703. r8712_set_802_11_infrastructure_mode(padapter, networkType);
  704. return 0;
  705. }
  706. static int r8711_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
  707. union iwreq_data *wrqu, char *b)
  708. {
  709. struct _adapter *padapter = netdev_priv(dev);
  710. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  711. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
  712. wrqu->mode = IW_MODE_INFRA;
  713. else if (check_fwstate(pmlmepriv,
  714. WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE))
  715. wrqu->mode = IW_MODE_ADHOC;
  716. else if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
  717. wrqu->mode = IW_MODE_MASTER;
  718. else
  719. wrqu->mode = IW_MODE_AUTO;
  720. return 0;
  721. }
  722. static int r871x_wx_set_pmkid(struct net_device *dev,
  723. struct iw_request_info *a,
  724. union iwreq_data *wrqu, char *extra)
  725. {
  726. struct _adapter *padapter = netdev_priv(dev);
  727. struct security_priv *psecuritypriv = &padapter->securitypriv;
  728. struct iw_pmksa *pPMK = (struct iw_pmksa *) extra;
  729. u8 strZeroMacAddress[ETH_ALEN] = {0x00};
  730. u8 strIssueBssid[ETH_ALEN] = {0x00};
  731. u8 j, blInserted = false;
  732. int intReturn = false;
  733. /*
  734. * There are the BSSID information in the bssid.sa_data array.
  735. * If cmd is IW_PMKSA_FLUSH, it means the wpa_supplicant wants to clear
  736. * all the PMKID information. If cmd is IW_PMKSA_ADD, it means the
  737. * wpa_supplicant wants to add a PMKID/BSSID to driver.
  738. * If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to
  739. * remove a PMKID/BSSID from driver.
  740. */
  741. if (pPMK == NULL)
  742. return -EINVAL;
  743. memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
  744. switch (pPMK->cmd) {
  745. case IW_PMKSA_ADD:
  746. if (!memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN))
  747. return intReturn;
  748. intReturn = true;
  749. blInserted = false;
  750. /* overwrite PMKID */
  751. for (j = 0; j < NUM_PMKID_CACHE; j++) {
  752. if (!memcmp(psecuritypriv->PMKIDList[j].Bssid,
  753. strIssueBssid, ETH_ALEN)) {
  754. /* BSSID is matched, the same AP => rewrite
  755. * with new PMKID.
  756. */
  757. netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n",
  758. __func__);
  759. memcpy(psecuritypriv->PMKIDList[j].PMKID,
  760. pPMK->pmkid, IW_PMKID_LEN);
  761. psecuritypriv->PMKIDList[j].bUsed = true;
  762. psecuritypriv->PMKIDIndex = j + 1;
  763. blInserted = true;
  764. break;
  765. }
  766. }
  767. if (!blInserted) {
  768. /* Find a new entry */
  769. netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n",
  770. __func__, psecuritypriv->PMKIDIndex);
  771. memcpy(psecuritypriv->PMKIDList[psecuritypriv->
  772. PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
  773. memcpy(psecuritypriv->PMKIDList[psecuritypriv->
  774. PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
  775. psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].
  776. bUsed = true;
  777. psecuritypriv->PMKIDIndex++;
  778. if (psecuritypriv->PMKIDIndex == NUM_PMKID_CACHE)
  779. psecuritypriv->PMKIDIndex = 0;
  780. }
  781. break;
  782. case IW_PMKSA_REMOVE:
  783. intReturn = true;
  784. for (j = 0; j < NUM_PMKID_CACHE; j++) {
  785. if (!memcmp(psecuritypriv->PMKIDList[j].Bssid,
  786. strIssueBssid, ETH_ALEN)) {
  787. /* BSSID is matched, the same AP => Remove
  788. * this PMKID information and reset it.
  789. */
  790. eth_zero_addr(psecuritypriv->PMKIDList[j].Bssid);
  791. psecuritypriv->PMKIDList[j].bUsed = false;
  792. break;
  793. }
  794. }
  795. break;
  796. case IW_PMKSA_FLUSH:
  797. memset(psecuritypriv->PMKIDList, 0,
  798. sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
  799. psecuritypriv->PMKIDIndex = 0;
  800. intReturn = true;
  801. break;
  802. default:
  803. netdev_info(dev, "r8712u: %s: unknown Command\n", __func__);
  804. intReturn = false;
  805. break;
  806. }
  807. return intReturn;
  808. }
  809. static int r8711_wx_get_sens(struct net_device *dev,
  810. struct iw_request_info *info,
  811. union iwreq_data *wrqu, char *extra)
  812. {
  813. wrqu->sens.value = 0;
  814. wrqu->sens.fixed = 0; /* no auto select */
  815. wrqu->sens.disabled = 1;
  816. return 0;
  817. }
  818. static int r8711_wx_get_range(struct net_device *dev,
  819. struct iw_request_info *info,
  820. union iwreq_data *wrqu, char *extra)
  821. {
  822. struct iw_range *range = (struct iw_range *)extra;
  823. u16 val;
  824. int i;
  825. wrqu->data.length = sizeof(*range);
  826. memset(range, 0, sizeof(*range));
  827. /* Let's try to keep this struct in the same order as in
  828. * linux/include/wireless.h
  829. */
  830. /* TODO: See what values we can set, and remove the ones we can't
  831. * set, or fill them with some default data.
  832. */
  833. /* ~5 Mb/s real (802.11b) */
  834. range->throughput = 5 * 1000 * 1000;
  835. /* TODO: 8711 sensitivity ? */
  836. /* signal level threshold range */
  837. /* percent values between 0 and 100. */
  838. range->max_qual.qual = 100;
  839. range->max_qual.level = 100;
  840. range->max_qual.noise = 100;
  841. range->max_qual.updated = 7; /* Updated all three */
  842. range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
  843. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  844. range->avg_qual.level = 0x100 - 78;
  845. range->avg_qual.noise = 0;
  846. range->avg_qual.updated = 7; /* Updated all three */
  847. range->num_bitrates = RATE_COUNT;
  848. for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
  849. range->bitrate[i] = rtl8180_rates[i];
  850. range->min_frag = MIN_FRAG_THRESHOLD;
  851. range->max_frag = MAX_FRAG_THRESHOLD;
  852. range->pm_capa = 0;
  853. range->we_version_compiled = WIRELESS_EXT;
  854. range->we_version_source = 16;
  855. range->num_channels = 14;
  856. for (i = 0, val = 0; i < 14; i++) {
  857. /* Include only legal frequencies for some countries */
  858. range->freq[val].i = i + 1;
  859. range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000;
  860. range->freq[val].e = 1;
  861. val++;
  862. if (val == IW_MAX_FREQUENCIES)
  863. break;
  864. }
  865. range->num_frequency = val;
  866. range->enc_capa = IW_ENC_CAPA_WPA |
  867. IW_ENC_CAPA_WPA2 |
  868. IW_ENC_CAPA_CIPHER_TKIP |
  869. IW_ENC_CAPA_CIPHER_CCMP;
  870. return 0;
  871. }
  872. static int r8711_wx_get_rate(struct net_device *dev,
  873. struct iw_request_info *info,
  874. union iwreq_data *wrqu, char *extra);
  875. static int r871x_wx_set_priv(struct net_device *dev,
  876. struct iw_request_info *info,
  877. union iwreq_data *awrq,
  878. char *extra)
  879. {
  880. int ret = 0, len = 0;
  881. char *ext;
  882. struct _adapter *padapter = netdev_priv(dev);
  883. struct iw_point *dwrq = (struct iw_point *)awrq;
  884. len = dwrq->length;
  885. ext = memdup_user(dwrq->pointer, len);
  886. if (IS_ERR(ext))
  887. return PTR_ERR(ext);
  888. if (!strcasecmp(ext, "RSSI")) {
  889. /*Return received signal strength indicator in -db for */
  890. /* current AP */
  891. /*<ssid> Rssi xx */
  892. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  893. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  894. /*static u8 xxxx; */
  895. if (check_fwstate(pmlmepriv, _FW_LINKED)) {
  896. sprintf(ext, "%s rssi %d",
  897. pcur_network->network.Ssid.Ssid,
  898. /*(xxxx=xxxx+10) */
  899. ((padapter->recvpriv.fw_rssi) >> 1) - 95
  900. /*pcur_network->network.Rssi */
  901. );
  902. } else {
  903. sprintf(ext, "OK");
  904. }
  905. } else if (!strcasecmp(ext, "LINKSPEED")) {
  906. /*Return link speed in MBPS */
  907. /*LinkSpeed xx */
  908. union iwreq_data wrqd;
  909. int ret_inner;
  910. int mbps;
  911. ret_inner = r8711_wx_get_rate(dev, info, &wrqd, extra);
  912. if (ret_inner != 0)
  913. mbps = 0;
  914. else
  915. mbps = wrqd.bitrate.value / 1000000;
  916. sprintf(ext, "LINKSPEED %d", mbps);
  917. } else if (!strcasecmp(ext, "MACADDR")) {
  918. /*Return mac address of the station */
  919. /* Macaddr = xx:xx:xx:xx:xx:xx */
  920. sprintf(ext, "MACADDR = %pM", dev->dev_addr);
  921. } else if (!strcasecmp(ext, "SCAN-ACTIVE")) {
  922. /*Set scan type to active */
  923. /*OK if successful */
  924. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  925. pmlmepriv->passive_mode = 1;
  926. sprintf(ext, "OK");
  927. } else if (!strcasecmp(ext, "SCAN-PASSIVE")) {
  928. /*Set scan type to passive */
  929. /*OK if successful */
  930. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  931. pmlmepriv->passive_mode = 0;
  932. sprintf(ext, "OK");
  933. } else if (!strncmp(ext, "DCE-E", 5)) {
  934. /*Set scan type to passive */
  935. /*OK if successful */
  936. r8712_disconnectCtrlEx_cmd(padapter
  937. , 1 /*u32 enableDrvCtrl */
  938. , 5 /*u32 tryPktCnt */
  939. , 100 /*u32 tryPktInterval */
  940. , 5000 /*u32 firstStageTO */
  941. );
  942. sprintf(ext, "OK");
  943. } else if (!strncmp(ext, "DCE-D", 5)) {
  944. /*Set scan type to passive */
  945. /*OK if successfu */
  946. r8712_disconnectCtrlEx_cmd(padapter
  947. , 0 /*u32 enableDrvCtrl */
  948. , 5 /*u32 tryPktCnt */
  949. , 100 /*u32 tryPktInterval */
  950. , 5000 /*u32 firstStageTO */
  951. );
  952. sprintf(ext, "OK");
  953. } else {
  954. netdev_info(dev, "r8712u: %s: unknown Command %s.\n",
  955. __func__, ext);
  956. goto FREE_EXT;
  957. }
  958. if (copy_to_user(dwrq->pointer, ext,
  959. min(dwrq->length, (__u16)(strlen(ext) + 1))))
  960. ret = -EFAULT;
  961. FREE_EXT:
  962. kfree(ext);
  963. return ret;
  964. }
  965. /* set bssid flow
  966. * s1. set_802_11_infrastructure_mode()
  967. * s2. set_802_11_authentication_mode()
  968. * s3. set_802_11_encryption_mode()
  969. * s4. set_802_11_bssid()
  970. *
  971. * This function intends to handle the Set AP command, which specifies the
  972. * MAC# of a preferred Access Point.
  973. * Currently, the request comes via Wireless Extensions' SIOCSIWAP ioctl.
  974. *
  975. * For this operation to succeed, there is no need for the interface to be up.
  976. *
  977. */
  978. static int r8711_wx_set_wap(struct net_device *dev,
  979. struct iw_request_info *info,
  980. union iwreq_data *awrq,
  981. char *extra)
  982. {
  983. int ret = -EINPROGRESS;
  984. struct _adapter *padapter = netdev_priv(dev);
  985. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  986. struct __queue *queue = &pmlmepriv->scanned_queue;
  987. struct sockaddr *temp = (struct sockaddr *)awrq;
  988. unsigned long irqL;
  989. struct list_head *phead;
  990. u8 *dst_bssid;
  991. struct wlan_network *pnetwork = NULL;
  992. enum NDIS_802_11_AUTHENTICATION_MODE authmode;
  993. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
  994. return -EBUSY;
  995. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
  996. return ret;
  997. if (temp->sa_family != ARPHRD_ETHER)
  998. return -EINVAL;
  999. authmode = padapter->securitypriv.ndisauthtype;
  1000. spin_lock_irqsave(&queue->lock, irqL);
  1001. phead = &queue->queue;
  1002. pmlmepriv->pscanned = phead->next;
  1003. while (1) {
  1004. if (end_of_queue_search(phead, pmlmepriv->pscanned))
  1005. break;
  1006. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned,
  1007. struct wlan_network, list);
  1008. pmlmepriv->pscanned = pmlmepriv->pscanned->next;
  1009. dst_bssid = pnetwork->network.MacAddress;
  1010. if (!memcmp(dst_bssid, temp->sa_data, ETH_ALEN)) {
  1011. r8712_set_802_11_infrastructure_mode(padapter,
  1012. pnetwork->network.InfrastructureMode);
  1013. break;
  1014. }
  1015. }
  1016. spin_unlock_irqrestore(&queue->lock, irqL);
  1017. if (!ret) {
  1018. if (!r8712_set_802_11_authentication_mode(padapter, authmode)) {
  1019. ret = -ENOMEM;
  1020. } else {
  1021. if (!r8712_set_802_11_bssid(padapter, temp->sa_data))
  1022. ret = -1;
  1023. }
  1024. }
  1025. return ret;
  1026. }
  1027. static int r8711_wx_get_wap(struct net_device *dev,
  1028. struct iw_request_info *info,
  1029. union iwreq_data *wrqu, char *extra)
  1030. {
  1031. struct _adapter *padapter = netdev_priv(dev);
  1032. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1033. struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
  1034. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1035. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE |
  1036. WIFI_AP_STATE))
  1037. ether_addr_copy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress);
  1038. else
  1039. eth_zero_addr(wrqu->ap_addr.sa_data);
  1040. return 0;
  1041. }
  1042. static int r871x_wx_set_mlme(struct net_device *dev,
  1043. struct iw_request_info *info,
  1044. union iwreq_data *wrqu, char *extra)
  1045. {
  1046. int ret = 0;
  1047. struct _adapter *padapter = netdev_priv(dev);
  1048. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  1049. if (mlme == NULL)
  1050. return -1;
  1051. switch (mlme->cmd) {
  1052. case IW_MLME_DEAUTH:
  1053. if (!r8712_set_802_11_disassociate(padapter))
  1054. ret = -1;
  1055. break;
  1056. case IW_MLME_DISASSOC:
  1057. if (!r8712_set_802_11_disassociate(padapter))
  1058. ret = -1;
  1059. break;
  1060. default:
  1061. return -EOPNOTSUPP;
  1062. }
  1063. return ret;
  1064. }
  1065. /**
  1066. *
  1067. * This function intends to handle the Set Scan command.
  1068. * Currently, the request comes via Wireless Extensions' SIOCSIWSCAN ioctl.
  1069. *
  1070. * For this operation to succeed, the interface is brought Up beforehand.
  1071. *
  1072. */
  1073. static int r8711_wx_set_scan(struct net_device *dev,
  1074. struct iw_request_info *a,
  1075. union iwreq_data *wrqu, char *extra)
  1076. {
  1077. struct _adapter *padapter = netdev_priv(dev);
  1078. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1079. u8 status = true;
  1080. if (padapter->bDriverStopped) {
  1081. netdev_info(dev, "In %s: bDriverStopped=%d\n",
  1082. __func__, padapter->bDriverStopped);
  1083. return -1;
  1084. }
  1085. if (!padapter->bup)
  1086. return -ENETDOWN;
  1087. if (!padapter->hw_init_completed)
  1088. return -1;
  1089. if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) ||
  1090. (pmlmepriv->sitesurveyctrl.traffic_busy))
  1091. return 0;
  1092. if (wrqu->data.length == sizeof(struct iw_scan_req)) {
  1093. struct iw_scan_req *req = (struct iw_scan_req *)extra;
  1094. if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  1095. struct ndis_802_11_ssid ssid;
  1096. unsigned long irqL;
  1097. u32 len = min_t(u8, req->essid_len, IW_ESSID_MAX_SIZE);
  1098. memset((unsigned char *)&ssid, 0,
  1099. sizeof(struct ndis_802_11_ssid));
  1100. memcpy(ssid.Ssid, req->essid, len);
  1101. ssid.SsidLength = len;
  1102. spin_lock_irqsave(&pmlmepriv->lock, irqL);
  1103. if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
  1104. _FW_UNDER_LINKING)) ||
  1105. (pmlmepriv->sitesurveyctrl.traffic_busy)) {
  1106. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
  1107. status = false;
  1108. } else {
  1109. status = r8712_sitesurvey_cmd(padapter, &ssid);
  1110. }
  1111. spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
  1112. }
  1113. } else {
  1114. status = r8712_set_802_11_bssid_list_scan(padapter);
  1115. }
  1116. if (!status)
  1117. return -1;
  1118. return 0;
  1119. }
  1120. static int r8711_wx_get_scan(struct net_device *dev,
  1121. struct iw_request_info *a,
  1122. union iwreq_data *wrqu, char *extra)
  1123. {
  1124. struct _adapter *padapter = netdev_priv(dev);
  1125. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1126. struct __queue *queue = &pmlmepriv->scanned_queue;
  1127. struct wlan_network *pnetwork = NULL;
  1128. unsigned long irqL;
  1129. struct list_head *plist, *phead;
  1130. char *ev = extra;
  1131. char *stop = ev + wrqu->data.length;
  1132. u32 ret = 0, cnt = 0;
  1133. if (padapter->bDriverStopped)
  1134. return -EINVAL;
  1135. while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
  1136. _FW_UNDER_LINKING)) {
  1137. msleep(30);
  1138. cnt++;
  1139. if (cnt > 100)
  1140. break;
  1141. }
  1142. spin_lock_irqsave(&queue->lock, irqL);
  1143. phead = &queue->queue;
  1144. plist = phead->next;
  1145. while (1) {
  1146. if (end_of_queue_search(phead, plist))
  1147. break;
  1148. if ((stop - ev) < SCAN_ITEM_SIZE) {
  1149. ret = -E2BIG;
  1150. break;
  1151. }
  1152. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1153. ev = translate_scan(padapter, a, pnetwork, ev, stop);
  1154. plist = plist->next;
  1155. }
  1156. spin_unlock_irqrestore(&queue->lock, irqL);
  1157. wrqu->data.length = ev - extra;
  1158. wrqu->data.flags = 0;
  1159. return ret;
  1160. }
  1161. /* set ssid flow
  1162. * s1. set_802_11_infrastructure_mode()
  1163. * s2. set_802_11_authenticaion_mode()
  1164. * s3. set_802_11_encryption_mode()
  1165. * s4. set_802_11_ssid()
  1166. *
  1167. * This function intends to handle the Set ESSID command.
  1168. * Currently, the request comes via the Wireless Extensions' SIOCSIWESSID ioctl.
  1169. *
  1170. * For this operation to succeed, there is no need for the interface to be Up.
  1171. *
  1172. */
  1173. static int r8711_wx_set_essid(struct net_device *dev,
  1174. struct iw_request_info *a,
  1175. union iwreq_data *wrqu, char *extra)
  1176. {
  1177. struct _adapter *padapter = netdev_priv(dev);
  1178. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1179. struct __queue *queue = &pmlmepriv->scanned_queue;
  1180. struct wlan_network *pnetwork = NULL;
  1181. enum NDIS_802_11_AUTHENTICATION_MODE authmode;
  1182. struct ndis_802_11_ssid ndis_ssid;
  1183. u8 *dst_ssid, *src_ssid;
  1184. struct list_head *phead;
  1185. u32 len;
  1186. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
  1187. return -EBUSY;
  1188. if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
  1189. return 0;
  1190. if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
  1191. return -E2BIG;
  1192. authmode = padapter->securitypriv.ndisauthtype;
  1193. if (wrqu->essid.flags && wrqu->essid.length) {
  1194. len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ?
  1195. wrqu->essid.length : IW_ESSID_MAX_SIZE;
  1196. memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
  1197. ndis_ssid.SsidLength = len;
  1198. memcpy(ndis_ssid.Ssid, extra, len);
  1199. src_ssid = ndis_ssid.Ssid;
  1200. phead = &queue->queue;
  1201. pmlmepriv->pscanned = phead->next;
  1202. while (1) {
  1203. if (end_of_queue_search(phead, pmlmepriv->pscanned))
  1204. break;
  1205. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned,
  1206. struct wlan_network, list);
  1207. pmlmepriv->pscanned = pmlmepriv->pscanned->next;
  1208. dst_ssid = pnetwork->network.Ssid.Ssid;
  1209. if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength))
  1210. && (pnetwork->network.Ssid.SsidLength ==
  1211. ndis_ssid.SsidLength)) {
  1212. if (check_fwstate(pmlmepriv,
  1213. WIFI_ADHOC_STATE)) {
  1214. if (pnetwork->network.
  1215. InfrastructureMode
  1216. !=
  1217. padapter->mlmepriv.
  1218. cur_network.network.
  1219. InfrastructureMode)
  1220. continue;
  1221. }
  1222. r8712_set_802_11_infrastructure_mode(
  1223. padapter,
  1224. pnetwork->network.InfrastructureMode);
  1225. break;
  1226. }
  1227. }
  1228. r8712_set_802_11_authentication_mode(padapter, authmode);
  1229. r8712_set_802_11_ssid(padapter, &ndis_ssid);
  1230. }
  1231. return -EINPROGRESS;
  1232. }
  1233. static int r8711_wx_get_essid(struct net_device *dev,
  1234. struct iw_request_info *a,
  1235. union iwreq_data *wrqu, char *extra)
  1236. {
  1237. struct _adapter *padapter = netdev_priv(dev);
  1238. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1239. struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
  1240. u32 len, ret = 0;
  1241. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
  1242. len = pcur_bss->Ssid.SsidLength;
  1243. wrqu->essid.length = len;
  1244. memcpy(extra, pcur_bss->Ssid.Ssid, len);
  1245. wrqu->essid.flags = 1;
  1246. } else {
  1247. ret = -ENOLINK;
  1248. }
  1249. return ret;
  1250. }
  1251. static int r8711_wx_set_rate(struct net_device *dev,
  1252. struct iw_request_info *a,
  1253. union iwreq_data *wrqu, char *extra)
  1254. {
  1255. struct _adapter *padapter = netdev_priv(dev);
  1256. u32 target_rate = wrqu->bitrate.value;
  1257. u32 fixed = wrqu->bitrate.fixed;
  1258. u32 ratevalue = 0;
  1259. u8 datarates[NumRates];
  1260. u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
  1261. int i, ret = 0;
  1262. if (target_rate == -1) {
  1263. ratevalue = 11;
  1264. goto set_rate;
  1265. }
  1266. target_rate = target_rate / 100000;
  1267. switch (target_rate) {
  1268. case 10:
  1269. ratevalue = 0;
  1270. break;
  1271. case 20:
  1272. ratevalue = 1;
  1273. break;
  1274. case 55:
  1275. ratevalue = 2;
  1276. break;
  1277. case 60:
  1278. ratevalue = 3;
  1279. break;
  1280. case 90:
  1281. ratevalue = 4;
  1282. break;
  1283. case 110:
  1284. ratevalue = 5;
  1285. break;
  1286. case 120:
  1287. ratevalue = 6;
  1288. break;
  1289. case 180:
  1290. ratevalue = 7;
  1291. break;
  1292. case 240:
  1293. ratevalue = 8;
  1294. break;
  1295. case 360:
  1296. ratevalue = 9;
  1297. break;
  1298. case 480:
  1299. ratevalue = 10;
  1300. break;
  1301. case 540:
  1302. ratevalue = 11;
  1303. break;
  1304. default:
  1305. ratevalue = 11;
  1306. break;
  1307. }
  1308. set_rate:
  1309. for (i = 0; i < NumRates; i++) {
  1310. if (ratevalue == mpdatarate[i]) {
  1311. datarates[i] = mpdatarate[i];
  1312. if (fixed == 0)
  1313. break;
  1314. } else {
  1315. datarates[i] = 0xff;
  1316. }
  1317. }
  1318. if (r8712_setdatarate_cmd(padapter, datarates) != _SUCCESS)
  1319. ret = -ENOMEM;
  1320. return ret;
  1321. }
  1322. static int r8711_wx_get_rate(struct net_device *dev,
  1323. struct iw_request_info *info,
  1324. union iwreq_data *wrqu, char *extra)
  1325. {
  1326. struct _adapter *padapter = netdev_priv(dev);
  1327. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1328. struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
  1329. struct ieee80211_ht_cap *pht_capie;
  1330. unsigned char rf_type = padapter->registrypriv.rf_config;
  1331. int i;
  1332. u8 *p;
  1333. u16 rate, max_rate = 0, ht_cap = false;
  1334. u32 ht_ielen = 0;
  1335. u8 bw_40MHz = 0, short_GI = 0;
  1336. u16 mcs_rate = 0;
  1337. i = 0;
  1338. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
  1339. p = r8712_get_ie(&pcur_bss->IEs[12],
  1340. _HT_CAPABILITY_IE_, &ht_ielen,
  1341. pcur_bss->IELength - 12);
  1342. if (p && ht_ielen > 0) {
  1343. ht_cap = true;
  1344. pht_capie = (struct ieee80211_ht_cap *)(p + 2);
  1345. memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
  1346. bw_40MHz = (pht_capie->cap_info &
  1347. IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
  1348. short_GI = (pht_capie->cap_info &
  1349. (IEEE80211_HT_CAP_SGI_20 |
  1350. IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
  1351. }
  1352. while ((pcur_bss->rates[i] != 0) &&
  1353. (pcur_bss->rates[i] != 0xFF)) {
  1354. rate = pcur_bss->rates[i] & 0x7F;
  1355. if (rate > max_rate)
  1356. max_rate = rate;
  1357. wrqu->bitrate.fixed = 0; /* no auto select */
  1358. wrqu->bitrate.value = rate * 500000;
  1359. i++;
  1360. }
  1361. if (ht_cap) {
  1362. if (mcs_rate & 0x8000 /* MCS15 */
  1363. &&
  1364. rf_type == RTL8712_RF_2T2R)
  1365. max_rate = (bw_40MHz) ? ((short_GI) ? 300 :
  1366. 270) : ((short_GI) ? 144 : 130);
  1367. else /* default MCS7 */
  1368. max_rate = (bw_40MHz) ? ((short_GI) ? 150 :
  1369. 135) : ((short_GI) ? 72 : 65);
  1370. max_rate *= 2; /* Mbps/2 */
  1371. }
  1372. wrqu->bitrate.value = max_rate * 500000;
  1373. } else {
  1374. return -ENOLINK;
  1375. }
  1376. return 0;
  1377. }
  1378. static int r8711_wx_get_rts(struct net_device *dev,
  1379. struct iw_request_info *info,
  1380. union iwreq_data *wrqu, char *extra)
  1381. {
  1382. struct _adapter *padapter = netdev_priv(dev);
  1383. wrqu->rts.value = padapter->registrypriv.rts_thresh;
  1384. wrqu->rts.fixed = 0; /* no auto select */
  1385. return 0;
  1386. }
  1387. static int r8711_wx_set_frag(struct net_device *dev,
  1388. struct iw_request_info *info,
  1389. union iwreq_data *wrqu, char *extra)
  1390. {
  1391. struct _adapter *padapter = netdev_priv(dev);
  1392. if (wrqu->frag.disabled) {
  1393. padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
  1394. } else {
  1395. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  1396. wrqu->frag.value > MAX_FRAG_THRESHOLD)
  1397. return -EINVAL;
  1398. padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
  1399. }
  1400. return 0;
  1401. }
  1402. static int r8711_wx_get_frag(struct net_device *dev,
  1403. struct iw_request_info *info,
  1404. union iwreq_data *wrqu, char *extra)
  1405. {
  1406. struct _adapter *padapter = netdev_priv(dev);
  1407. wrqu->frag.value = padapter->xmitpriv.frag_len;
  1408. wrqu->frag.fixed = 0; /* no auto select */
  1409. return 0;
  1410. }
  1411. static int r8711_wx_get_retry(struct net_device *dev,
  1412. struct iw_request_info *info,
  1413. union iwreq_data *wrqu, char *extra)
  1414. {
  1415. wrqu->retry.value = 7;
  1416. wrqu->retry.fixed = 0; /* no auto select */
  1417. wrqu->retry.disabled = 1;
  1418. return 0;
  1419. }
  1420. static int r8711_wx_set_enc(struct net_device *dev,
  1421. struct iw_request_info *info,
  1422. union iwreq_data *wrqu, char *keybuf)
  1423. {
  1424. u32 key;
  1425. u32 keyindex_provided;
  1426. struct NDIS_802_11_WEP wep;
  1427. enum NDIS_802_11_AUTHENTICATION_MODE authmode;
  1428. struct iw_point *erq = &(wrqu->encoding);
  1429. struct _adapter *padapter = netdev_priv(dev);
  1430. key = erq->flags & IW_ENCODE_INDEX;
  1431. memset(&wep, 0, sizeof(struct NDIS_802_11_WEP));
  1432. if (erq->flags & IW_ENCODE_DISABLED) {
  1433. netdev_info(dev, "r8712u: %s: EncryptionDisabled\n", __func__);
  1434. padapter->securitypriv.ndisencryptstatus =
  1435. Ndis802_11EncryptionDisabled;
  1436. padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
  1437. padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
  1438. padapter->securitypriv.AuthAlgrthm = 0; /* open system */
  1439. authmode = Ndis802_11AuthModeOpen;
  1440. padapter->securitypriv.ndisauthtype = authmode;
  1441. return 0;
  1442. }
  1443. if (key) {
  1444. if (key > WEP_KEYS)
  1445. return -EINVAL;
  1446. key--;
  1447. keyindex_provided = 1;
  1448. } else {
  1449. keyindex_provided = 0;
  1450. key = padapter->securitypriv.PrivacyKeyIndex;
  1451. }
  1452. /* set authentication mode */
  1453. if (erq->flags & IW_ENCODE_OPEN) {
  1454. netdev_info(dev, "r8712u: %s: IW_ENCODE_OPEN\n", __func__);
  1455. padapter->securitypriv.ndisencryptstatus =
  1456. Ndis802_11Encryption1Enabled;
  1457. padapter->securitypriv.AuthAlgrthm = 0; /* open system */
  1458. padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
  1459. padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
  1460. authmode = Ndis802_11AuthModeOpen;
  1461. padapter->securitypriv.ndisauthtype = authmode;
  1462. } else if (erq->flags & IW_ENCODE_RESTRICTED) {
  1463. netdev_info(dev,
  1464. "r8712u: %s: IW_ENCODE_RESTRICTED\n", __func__);
  1465. padapter->securitypriv.ndisencryptstatus =
  1466. Ndis802_11Encryption1Enabled;
  1467. padapter->securitypriv.AuthAlgrthm = 1; /* shared system */
  1468. padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
  1469. padapter->securitypriv.XGrpPrivacy = _WEP40_;
  1470. authmode = Ndis802_11AuthModeShared;
  1471. padapter->securitypriv.ndisauthtype = authmode;
  1472. } else {
  1473. padapter->securitypriv.ndisencryptstatus =
  1474. Ndis802_11Encryption1Enabled;
  1475. padapter->securitypriv.AuthAlgrthm = 0; /* open system */
  1476. padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
  1477. padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
  1478. authmode = Ndis802_11AuthModeOpen;
  1479. padapter->securitypriv.ndisauthtype = authmode;
  1480. }
  1481. wep.KeyIndex = key;
  1482. if (erq->length > 0) {
  1483. wep.KeyLength = erq->length <= 5 ? 5 : 13;
  1484. wep.Length = wep.KeyLength +
  1485. FIELD_OFFSET(struct NDIS_802_11_WEP, KeyMaterial);
  1486. } else {
  1487. wep.KeyLength = 0;
  1488. if (keyindex_provided == 1) { /* set key_id only, no given
  1489. * KeyMaterial(erq->length==0).
  1490. */
  1491. padapter->securitypriv.PrivacyKeyIndex = key;
  1492. switch (padapter->securitypriv.DefKeylen[key]) {
  1493. case 5:
  1494. padapter->securitypriv.PrivacyAlgrthm =
  1495. _WEP40_;
  1496. break;
  1497. case 13:
  1498. padapter->securitypriv.PrivacyAlgrthm =
  1499. _WEP104_;
  1500. break;
  1501. default:
  1502. padapter->securitypriv.PrivacyAlgrthm =
  1503. _NO_PRIVACY_;
  1504. break;
  1505. }
  1506. return 0;
  1507. }
  1508. }
  1509. wep.KeyIndex |= 0x80000000; /* transmit key */
  1510. memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
  1511. if (r8712_set_802_11_add_wep(padapter, &wep) == _FAIL)
  1512. return -EOPNOTSUPP;
  1513. return 0;
  1514. }
  1515. static int r8711_wx_get_enc(struct net_device *dev,
  1516. struct iw_request_info *info,
  1517. union iwreq_data *wrqu, char *keybuf)
  1518. {
  1519. uint key, ret = 0;
  1520. struct _adapter *padapter = netdev_priv(dev);
  1521. struct iw_point *erq = &(wrqu->encoding);
  1522. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1523. if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
  1524. if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
  1525. erq->length = 0;
  1526. erq->flags |= IW_ENCODE_DISABLED;
  1527. return 0;
  1528. }
  1529. }
  1530. key = erq->flags & IW_ENCODE_INDEX;
  1531. if (key) {
  1532. if (key > WEP_KEYS)
  1533. return -EINVAL;
  1534. key--;
  1535. } else {
  1536. key = padapter->securitypriv.PrivacyKeyIndex;
  1537. }
  1538. erq->flags = key + 1;
  1539. switch (padapter->securitypriv.ndisencryptstatus) {
  1540. case Ndis802_11EncryptionNotSupported:
  1541. case Ndis802_11EncryptionDisabled:
  1542. erq->length = 0;
  1543. erq->flags |= IW_ENCODE_DISABLED;
  1544. break;
  1545. case Ndis802_11Encryption1Enabled:
  1546. erq->length = padapter->securitypriv.DefKeylen[key];
  1547. if (erq->length) {
  1548. memcpy(keybuf, padapter->securitypriv.DefKey[
  1549. key].skey, padapter->securitypriv.
  1550. DefKeylen[key]);
  1551. erq->flags |= IW_ENCODE_ENABLED;
  1552. if (padapter->securitypriv.ndisauthtype ==
  1553. Ndis802_11AuthModeOpen)
  1554. erq->flags |= IW_ENCODE_OPEN;
  1555. else if (padapter->securitypriv.ndisauthtype ==
  1556. Ndis802_11AuthModeShared)
  1557. erq->flags |= IW_ENCODE_RESTRICTED;
  1558. } else {
  1559. erq->length = 0;
  1560. erq->flags |= IW_ENCODE_DISABLED;
  1561. }
  1562. break;
  1563. case Ndis802_11Encryption2Enabled:
  1564. case Ndis802_11Encryption3Enabled:
  1565. erq->length = 16;
  1566. erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN |
  1567. IW_ENCODE_NOKEY);
  1568. break;
  1569. default:
  1570. erq->length = 0;
  1571. erq->flags |= IW_ENCODE_DISABLED;
  1572. break;
  1573. }
  1574. return ret;
  1575. }
  1576. static int r8711_wx_get_power(struct net_device *dev,
  1577. struct iw_request_info *info,
  1578. union iwreq_data *wrqu, char *extra)
  1579. {
  1580. wrqu->power.value = 0;
  1581. wrqu->power.fixed = 0; /* no auto select */
  1582. wrqu->power.disabled = 1;
  1583. return 0;
  1584. }
  1585. static int r871x_wx_set_gen_ie(struct net_device *dev,
  1586. struct iw_request_info *info,
  1587. union iwreq_data *wrqu, char *extra)
  1588. {
  1589. struct _adapter *padapter = netdev_priv(dev);
  1590. return r871x_set_wpa_ie(padapter, extra, wrqu->data.length);
  1591. }
  1592. static int r871x_wx_set_auth(struct net_device *dev,
  1593. struct iw_request_info *info,
  1594. union iwreq_data *wrqu, char *extra)
  1595. {
  1596. struct _adapter *padapter = netdev_priv(dev);
  1597. struct iw_param *param = (struct iw_param *)&(wrqu->param);
  1598. int paramid;
  1599. int paramval;
  1600. int ret = 0;
  1601. paramid = param->flags & IW_AUTH_INDEX;
  1602. paramval = param->value;
  1603. switch (paramid) {
  1604. case IW_AUTH_WPA_VERSION:
  1605. break;
  1606. case IW_AUTH_CIPHER_PAIRWISE:
  1607. break;
  1608. case IW_AUTH_CIPHER_GROUP:
  1609. break;
  1610. case IW_AUTH_KEY_MGMT:
  1611. /*
  1612. * ??? does not use these parameters
  1613. */
  1614. break;
  1615. case IW_AUTH_TKIP_COUNTERMEASURES:
  1616. if (paramval) {
  1617. /* wpa_supplicant is enabling tkip countermeasure. */
  1618. padapter->securitypriv.btkip_countermeasure = true;
  1619. } else {
  1620. /* wpa_supplicant is disabling tkip countermeasure. */
  1621. padapter->securitypriv.btkip_countermeasure = false;
  1622. }
  1623. break;
  1624. case IW_AUTH_DROP_UNENCRYPTED:
  1625. /* HACK:
  1626. *
  1627. * wpa_supplicant calls set_wpa_enabled when the driver
  1628. * is loaded and unloaded, regardless of if WPA is being
  1629. * used. No other calls are made which can be used to
  1630. * determine if encryption will be used or not prior to
  1631. * association being expected. If encryption is not being
  1632. * used, drop_unencrypted is set to false, else true -- we
  1633. * can use this to determine if the CAP_PRIVACY_ON bit should
  1634. * be set.
  1635. */
  1636. if (padapter->securitypriv.ndisencryptstatus ==
  1637. Ndis802_11Encryption1Enabled) {
  1638. /* it means init value, or using wep,
  1639. * ndisencryptstatus =
  1640. * Ndis802_11Encryption1Enabled,
  1641. * then it needn't reset it;
  1642. */
  1643. break;
  1644. }
  1645. if (paramval) {
  1646. padapter->securitypriv.ndisencryptstatus =
  1647. Ndis802_11EncryptionDisabled;
  1648. padapter->securitypriv.PrivacyAlgrthm =
  1649. _NO_PRIVACY_;
  1650. padapter->securitypriv.XGrpPrivacy =
  1651. _NO_PRIVACY_;
  1652. padapter->securitypriv.AuthAlgrthm = 0;
  1653. padapter->securitypriv.ndisauthtype =
  1654. Ndis802_11AuthModeOpen;
  1655. }
  1656. break;
  1657. case IW_AUTH_80211_AUTH_ALG:
  1658. ret = wpa_set_auth_algs(dev, (u32)paramval);
  1659. break;
  1660. case IW_AUTH_WPA_ENABLED:
  1661. break;
  1662. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1663. break;
  1664. case IW_AUTH_PRIVACY_INVOKED:
  1665. break;
  1666. default:
  1667. return -EOPNOTSUPP;
  1668. }
  1669. return ret;
  1670. }
  1671. static int r871x_wx_set_enc_ext(struct net_device *dev,
  1672. struct iw_request_info *info,
  1673. union iwreq_data *wrqu, char *extra)
  1674. {
  1675. struct iw_point *pencoding = &wrqu->encoding;
  1676. struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
  1677. struct ieee_param *param = NULL;
  1678. char *alg_name;
  1679. u32 param_len;
  1680. int ret = 0;
  1681. switch (pext->alg) {
  1682. case IW_ENCODE_ALG_NONE:
  1683. alg_name = "none";
  1684. break;
  1685. case IW_ENCODE_ALG_WEP:
  1686. alg_name = "WEP";
  1687. break;
  1688. case IW_ENCODE_ALG_TKIP:
  1689. alg_name = "TKIP";
  1690. break;
  1691. case IW_ENCODE_ALG_CCMP:
  1692. alg_name = "CCMP";
  1693. break;
  1694. default:
  1695. return -EINVAL;
  1696. }
  1697. param_len = sizeof(struct ieee_param) + pext->key_len;
  1698. param = kzalloc(param_len, GFP_ATOMIC);
  1699. if (param == NULL)
  1700. return -ENOMEM;
  1701. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  1702. eth_broadcast_addr(param->sta_addr);
  1703. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  1704. if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
  1705. param->u.crypt.set_tx = 0;
  1706. if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  1707. param->u.crypt.set_tx = 1;
  1708. param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1;
  1709. if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  1710. memcpy(param->u.crypt.seq, pext->rx_seq, 8);
  1711. if (pext->key_len) {
  1712. param->u.crypt.key_len = pext->key_len;
  1713. memcpy(param + 1, pext + 1, pext->key_len);
  1714. }
  1715. ret = wpa_set_encryption(dev, param, param_len);
  1716. kfree(param);
  1717. return ret;
  1718. }
  1719. static int r871x_wx_get_nick(struct net_device *dev,
  1720. struct iw_request_info *info,
  1721. union iwreq_data *wrqu, char *extra)
  1722. {
  1723. if (extra) {
  1724. wrqu->data.length = 8;
  1725. wrqu->data.flags = 1;
  1726. memcpy(extra, "rtl_wifi", 8);
  1727. }
  1728. return 0;
  1729. }
  1730. static int r8711_wx_read32(struct net_device *dev,
  1731. struct iw_request_info *info,
  1732. union iwreq_data *wrqu, char *keybuf)
  1733. {
  1734. struct _adapter *padapter = netdev_priv(dev);
  1735. u32 addr;
  1736. u32 data32;
  1737. get_user(addr, (u32 __user *)wrqu->data.pointer);
  1738. data32 = r8712_read32(padapter, addr);
  1739. put_user(data32, (u32 __user *)wrqu->data.pointer);
  1740. wrqu->data.length = (data32 & 0xffff0000) >> 16;
  1741. wrqu->data.flags = data32 & 0xffff;
  1742. get_user(addr, (u32 __user *)wrqu->data.pointer);
  1743. return 0;
  1744. }
  1745. static int r8711_wx_write32(struct net_device *dev,
  1746. struct iw_request_info *info,
  1747. union iwreq_data *wrqu, char *keybuf)
  1748. {
  1749. struct _adapter *padapter = netdev_priv(dev);
  1750. u32 addr;
  1751. u32 data32;
  1752. get_user(addr, (u32 __user *)wrqu->data.pointer);
  1753. data32 = ((u32)wrqu->data.length << 16) | (u32)wrqu->data.flags;
  1754. r8712_write32(padapter, addr, data32);
  1755. return 0;
  1756. }
  1757. static int dummy(struct net_device *dev,
  1758. struct iw_request_info *a,
  1759. union iwreq_data *wrqu, char *b)
  1760. {
  1761. return -ENOSYS;
  1762. }
  1763. static int r8711_drvext_hdl(struct net_device *dev,
  1764. struct iw_request_info *info,
  1765. union iwreq_data *wrqu, char *extra)
  1766. {
  1767. return 0;
  1768. }
  1769. static int r871x_mp_ioctl_hdl(struct net_device *dev,
  1770. struct iw_request_info *info,
  1771. union iwreq_data *wrqu, char *extra)
  1772. {
  1773. struct _adapter *padapter = netdev_priv(dev);
  1774. struct iw_point *p = &wrqu->data;
  1775. struct oid_par_priv oid_par;
  1776. struct mp_ioctl_handler *phandler;
  1777. struct mp_ioctl_param *poidparam;
  1778. unsigned long BytesRead, BytesWritten, BytesNeeded;
  1779. u8 *pparmbuf, bset;
  1780. u16 len;
  1781. uint status;
  1782. int ret = 0;
  1783. if ((!p->length) || (!p->pointer))
  1784. return -EINVAL;
  1785. bset = (u8)(p->flags & 0xFFFF);
  1786. len = p->length;
  1787. pparmbuf = memdup_user(p->pointer, len);
  1788. if (IS_ERR(pparmbuf))
  1789. return PTR_ERR(pparmbuf);
  1790. poidparam = (struct mp_ioctl_param *)pparmbuf;
  1791. if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
  1792. ret = -EINVAL;
  1793. goto _r871x_mp_ioctl_hdl_exit;
  1794. }
  1795. phandler = mp_ioctl_hdl + poidparam->subcode;
  1796. if ((phandler->paramsize != 0) &&
  1797. (poidparam->len < phandler->paramsize)) {
  1798. ret = -EINVAL;
  1799. goto _r871x_mp_ioctl_hdl_exit;
  1800. }
  1801. if (phandler->oid == 0 && phandler->handler) {
  1802. status = phandler->handler(&oid_par);
  1803. } else if (phandler->handler) {
  1804. oid_par.adapter_context = padapter;
  1805. oid_par.oid = phandler->oid;
  1806. oid_par.information_buf = poidparam->data;
  1807. oid_par.information_buf_len = poidparam->len;
  1808. oid_par.dbg = 0;
  1809. BytesWritten = 0;
  1810. BytesNeeded = 0;
  1811. if (bset) {
  1812. oid_par.bytes_rw = &BytesRead;
  1813. oid_par.bytes_needed = &BytesNeeded;
  1814. oid_par.type_of_oid = SET_OID;
  1815. } else {
  1816. oid_par.bytes_rw = &BytesWritten;
  1817. oid_par.bytes_needed = &BytesNeeded;
  1818. oid_par.type_of_oid = QUERY_OID;
  1819. }
  1820. status = phandler->handler(&oid_par);
  1821. /* todo:check status, BytesNeeded, etc. */
  1822. } else {
  1823. netdev_info(dev, "r8712u: %s: err!, subcode=%d, oid=%d, handler=%p\n",
  1824. __func__, poidparam->subcode, phandler->oid,
  1825. phandler->handler);
  1826. ret = -EFAULT;
  1827. goto _r871x_mp_ioctl_hdl_exit;
  1828. }
  1829. if (bset == 0x00) { /* query info */
  1830. if (copy_to_user(p->pointer, pparmbuf, len))
  1831. ret = -EFAULT;
  1832. }
  1833. if (status) {
  1834. ret = -EFAULT;
  1835. goto _r871x_mp_ioctl_hdl_exit;
  1836. }
  1837. _r871x_mp_ioctl_hdl_exit:
  1838. kfree(pparmbuf);
  1839. return ret;
  1840. }
  1841. static int r871x_get_ap_info(struct net_device *dev,
  1842. struct iw_request_info *info,
  1843. union iwreq_data *wrqu, char *extra)
  1844. {
  1845. struct _adapter *padapter = netdev_priv(dev);
  1846. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1847. struct __queue *queue = &pmlmepriv->scanned_queue;
  1848. struct iw_point *pdata = &wrqu->data;
  1849. struct wlan_network *pnetwork = NULL;
  1850. u32 cnt = 0, wpa_ielen;
  1851. unsigned long irqL;
  1852. struct list_head *plist, *phead;
  1853. unsigned char *pbuf;
  1854. u8 bssid[ETH_ALEN];
  1855. char data[32];
  1856. if (padapter->bDriverStopped || (pdata == NULL))
  1857. return -EINVAL;
  1858. while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
  1859. _FW_UNDER_LINKING)) {
  1860. msleep(30);
  1861. cnt++;
  1862. if (cnt > 100)
  1863. break;
  1864. }
  1865. pdata->flags = 0;
  1866. if (pdata->length >= 32) {
  1867. if (copy_from_user(data, pdata->pointer, 32))
  1868. return -EINVAL;
  1869. } else {
  1870. return -EINVAL;
  1871. }
  1872. spin_lock_irqsave(&(pmlmepriv->scanned_queue.lock), irqL);
  1873. phead = &queue->queue;
  1874. plist = phead->next;
  1875. while (1) {
  1876. if (end_of_queue_search(phead, plist))
  1877. break;
  1878. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1879. if (!mac_pton(data, bssid)) {
  1880. netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n",
  1881. (u8 *)data);
  1882. spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock),
  1883. irqL);
  1884. return -EINVAL;
  1885. }
  1886. netdev_info(dev, "r8712u: BSSID:%pM\n", bssid);
  1887. if (ether_addr_equal(bssid, pnetwork->network.MacAddress)) {
  1888. /* BSSID match, then check if supporting wpa/wpa2 */
  1889. pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12],
  1890. &wpa_ielen, pnetwork->network.IELength - 12);
  1891. if (pbuf && (wpa_ielen > 0)) {
  1892. pdata->flags = 1;
  1893. break;
  1894. }
  1895. pbuf = r8712_get_wpa2_ie(&pnetwork->network.IEs[12],
  1896. &wpa_ielen, pnetwork->network.IELength - 12);
  1897. if (pbuf && (wpa_ielen > 0)) {
  1898. pdata->flags = 2;
  1899. break;
  1900. }
  1901. }
  1902. plist = plist->next;
  1903. }
  1904. spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock), irqL);
  1905. if (pdata->length >= 34) {
  1906. if (copy_to_user((u8 __user *)pdata->pointer + 32,
  1907. (u8 *)&pdata->flags, 1))
  1908. return -EINVAL;
  1909. }
  1910. return 0;
  1911. }
  1912. static int r871x_set_pid(struct net_device *dev,
  1913. struct iw_request_info *info,
  1914. union iwreq_data *wrqu, char *extra)
  1915. {
  1916. struct _adapter *padapter = netdev_priv(dev);
  1917. struct iw_point *pdata = &wrqu->data;
  1918. if ((padapter->bDriverStopped) || (pdata == NULL))
  1919. return -EINVAL;
  1920. if (copy_from_user(&padapter->pid, pdata->pointer, sizeof(int)))
  1921. return -EINVAL;
  1922. return 0;
  1923. }
  1924. static int r871x_set_chplan(struct net_device *dev,
  1925. struct iw_request_info *info,
  1926. union iwreq_data *wrqu, char *extra)
  1927. {
  1928. int ret = 0;
  1929. struct _adapter *padapter = netdev_priv(dev);
  1930. struct iw_point *pdata = &wrqu->data;
  1931. int ch_plan = -1;
  1932. if ((padapter->bDriverStopped) || (pdata == NULL)) {
  1933. ret = -EINVAL;
  1934. goto exit;
  1935. }
  1936. ch_plan = (int)*extra;
  1937. r8712_set_chplan_cmd(padapter, ch_plan);
  1938. exit:
  1939. return ret;
  1940. }
  1941. static int r871x_wps_start(struct net_device *dev,
  1942. struct iw_request_info *info,
  1943. union iwreq_data *wrqu, char *extra)
  1944. {
  1945. struct _adapter *padapter = netdev_priv(dev);
  1946. struct iw_point *pdata = &wrqu->data;
  1947. u32 u32wps_start = 0;
  1948. if ((padapter->bDriverStopped) || (pdata == NULL))
  1949. return -EINVAL;
  1950. if (copy_from_user((void *)&u32wps_start, pdata->pointer, 4))
  1951. return -EFAULT;
  1952. if (u32wps_start == 0)
  1953. u32wps_start = *extra;
  1954. if (u32wps_start == 1) /* WPS Start */
  1955. padapter->ledpriv.LedControlHandler(padapter,
  1956. LED_CTL_START_WPS);
  1957. else if (u32wps_start == 2) /* WPS Stop because of wps success */
  1958. padapter->ledpriv.LedControlHandler(padapter,
  1959. LED_CTL_STOP_WPS);
  1960. else if (u32wps_start == 3) /* WPS Stop because of wps fail */
  1961. padapter->ledpriv.LedControlHandler(padapter,
  1962. LED_CTL_STOP_WPS_FAIL);
  1963. return 0;
  1964. }
  1965. static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
  1966. {
  1967. struct _adapter *padapter = netdev_priv(dev);
  1968. switch (name) {
  1969. case IEEE_PARAM_WPA_ENABLED:
  1970. padapter->securitypriv.AuthAlgrthm = 2; /* 802.1x */
  1971. switch ((value) & 0xff) {
  1972. case 1: /* WPA */
  1973. padapter->securitypriv.ndisauthtype =
  1974. Ndis802_11AuthModeWPAPSK; /* WPA_PSK */
  1975. padapter->securitypriv.ndisencryptstatus =
  1976. Ndis802_11Encryption2Enabled;
  1977. break;
  1978. case 2: /* WPA2 */
  1979. padapter->securitypriv.ndisauthtype =
  1980. Ndis802_11AuthModeWPA2PSK; /* WPA2_PSK */
  1981. padapter->securitypriv.ndisencryptstatus =
  1982. Ndis802_11Encryption3Enabled;
  1983. break;
  1984. }
  1985. break;
  1986. case IEEE_PARAM_TKIP_COUNTERMEASURES:
  1987. break;
  1988. case IEEE_PARAM_DROP_UNENCRYPTED:
  1989. /* HACK:
  1990. *
  1991. * wpa_supplicant calls set_wpa_enabled when the driver
  1992. * is loaded and unloaded, regardless of if WPA is being
  1993. * used. No other calls are made which can be used to
  1994. * determine if encryption will be used or not prior to
  1995. * association being expected. If encryption is not being
  1996. * used, drop_unencrypted is set to false, else true -- we
  1997. * can use this to determine if the CAP_PRIVACY_ON bit should
  1998. * be set.
  1999. */
  2000. break;
  2001. case IEEE_PARAM_PRIVACY_INVOKED:
  2002. break;
  2003. case IEEE_PARAM_AUTH_ALGS:
  2004. return wpa_set_auth_algs(dev, value);
  2005. case IEEE_PARAM_IEEE_802_1X:
  2006. break;
  2007. case IEEE_PARAM_WPAX_SELECT:
  2008. /* added for WPA2 mixed mode */
  2009. break;
  2010. default:
  2011. return -EOPNOTSUPP;
  2012. }
  2013. return 0;
  2014. }
  2015. static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
  2016. {
  2017. struct _adapter *padapter = netdev_priv(dev);
  2018. switch (command) {
  2019. case IEEE_MLME_STA_DEAUTH:
  2020. if (!r8712_set_802_11_disassociate(padapter))
  2021. return -1;
  2022. break;
  2023. case IEEE_MLME_STA_DISASSOC:
  2024. if (!r8712_set_802_11_disassociate(padapter))
  2025. return -1;
  2026. break;
  2027. default:
  2028. return -EOPNOTSUPP;
  2029. }
  2030. return 0;
  2031. }
  2032. static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
  2033. {
  2034. struct ieee_param *param;
  2035. int ret = 0;
  2036. struct _adapter *padapter = netdev_priv(dev);
  2037. if (p->length < sizeof(struct ieee_param) || !p->pointer)
  2038. return -EINVAL;
  2039. param = memdup_user(p->pointer, p->length);
  2040. if (IS_ERR(param))
  2041. return PTR_ERR(param);
  2042. switch (param->cmd) {
  2043. case IEEE_CMD_SET_WPA_PARAM:
  2044. ret = wpa_set_param(dev, param->u.wpa_param.name,
  2045. param->u.wpa_param.value);
  2046. break;
  2047. case IEEE_CMD_SET_WPA_IE:
  2048. ret = r871x_set_wpa_ie(padapter, (char *)param->u.wpa_ie.data,
  2049. (u16)param->u.wpa_ie.len);
  2050. break;
  2051. case IEEE_CMD_SET_ENCRYPTION:
  2052. ret = wpa_set_encryption(dev, param, p->length);
  2053. break;
  2054. case IEEE_CMD_MLME:
  2055. ret = wpa_mlme(dev, param->u.mlme.command,
  2056. param->u.mlme.reason_code);
  2057. break;
  2058. default:
  2059. ret = -EOPNOTSUPP;
  2060. break;
  2061. }
  2062. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  2063. ret = -EFAULT;
  2064. kfree(param);
  2065. return ret;
  2066. }
  2067. /* based on "driver_ipw" and for hostapd */
  2068. int r871x_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2069. {
  2070. struct iwreq *wrq = (struct iwreq *)rq;
  2071. switch (cmd) {
  2072. case RTL_IOCTL_WPA_SUPPLICANT:
  2073. return wpa_supplicant_ioctl(dev, &wrq->u.data);
  2074. default:
  2075. return -EOPNOTSUPP;
  2076. }
  2077. return 0;
  2078. }
  2079. static iw_handler r8711_handlers[] = {
  2080. NULL, /* SIOCSIWCOMMIT */
  2081. r8711_wx_get_name, /* SIOCGIWNAME */
  2082. dummy, /* SIOCSIWNWID */
  2083. dummy, /* SIOCGIWNWID */
  2084. r8711_wx_set_freq, /* SIOCSIWFREQ */
  2085. r8711_wx_get_freq, /* SIOCGIWFREQ */
  2086. r8711_wx_set_mode, /* SIOCSIWMODE */
  2087. r8711_wx_get_mode, /* SIOCGIWMODE */
  2088. dummy, /* SIOCSIWSENS */
  2089. r8711_wx_get_sens, /* SIOCGIWSENS */
  2090. NULL, /* SIOCSIWRANGE */
  2091. r8711_wx_get_range, /* SIOCGIWRANGE */
  2092. r871x_wx_set_priv, /* SIOCSIWPRIV */
  2093. NULL, /* SIOCGIWPRIV */
  2094. NULL, /* SIOCSIWSTATS */
  2095. NULL, /* SIOCGIWSTATS */
  2096. dummy, /* SIOCSIWSPY */
  2097. dummy, /* SIOCGIWSPY */
  2098. NULL, /* SIOCGIWTHRSPY */
  2099. NULL, /* SIOCWIWTHRSPY */
  2100. r8711_wx_set_wap, /* SIOCSIWAP */
  2101. r8711_wx_get_wap, /* SIOCGIWAP */
  2102. r871x_wx_set_mlme, /* request MLME operation;
  2103. * uses struct iw_mlme
  2104. */
  2105. dummy, /* SIOCGIWAPLIST -- deprecated */
  2106. r8711_wx_set_scan, /* SIOCSIWSCAN */
  2107. r8711_wx_get_scan, /* SIOCGIWSCAN */
  2108. r8711_wx_set_essid, /* SIOCSIWESSID */
  2109. r8711_wx_get_essid, /* SIOCGIWESSID */
  2110. dummy, /* SIOCSIWNICKN */
  2111. r871x_wx_get_nick, /* SIOCGIWNICKN */
  2112. NULL, /* -- hole -- */
  2113. NULL, /* -- hole -- */
  2114. r8711_wx_set_rate, /* SIOCSIWRATE */
  2115. r8711_wx_get_rate, /* SIOCGIWRATE */
  2116. dummy, /* SIOCSIWRTS */
  2117. r8711_wx_get_rts, /* SIOCGIWRTS */
  2118. r8711_wx_set_frag, /* SIOCSIWFRAG */
  2119. r8711_wx_get_frag, /* SIOCGIWFRAG */
  2120. dummy, /* SIOCSIWTXPOW */
  2121. dummy, /* SIOCGIWTXPOW */
  2122. dummy, /* SIOCSIWRETRY */
  2123. r8711_wx_get_retry, /* SIOCGIWRETRY */
  2124. r8711_wx_set_enc, /* SIOCSIWENCODE */
  2125. r8711_wx_get_enc, /* SIOCGIWENCODE */
  2126. dummy, /* SIOCSIWPOWER */
  2127. r8711_wx_get_power, /* SIOCGIWPOWER */
  2128. NULL, /*---hole---*/
  2129. NULL, /*---hole---*/
  2130. r871x_wx_set_gen_ie, /* SIOCSIWGENIE */
  2131. NULL, /* SIOCGIWGENIE */
  2132. r871x_wx_set_auth, /* SIOCSIWAUTH */
  2133. NULL, /* SIOCGIWAUTH */
  2134. r871x_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
  2135. NULL, /* SIOCGIWENCODEEXT */
  2136. r871x_wx_set_pmkid, /* SIOCSIWPMKSA */
  2137. NULL, /*---hole---*/
  2138. };
  2139. static const struct iw_priv_args r8711_private_args[] = {
  2140. {
  2141. SIOCIWFIRSTPRIV + 0x0,
  2142. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "read32"
  2143. },
  2144. {
  2145. SIOCIWFIRSTPRIV + 0x1,
  2146. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "write32"
  2147. },
  2148. {
  2149. SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
  2150. },
  2151. {
  2152. SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
  2153. },
  2154. {
  2155. SIOCIWFIRSTPRIV + 0x4,
  2156. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
  2157. },
  2158. {
  2159. SIOCIWFIRSTPRIV + 0x5,
  2160. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setpid"
  2161. },
  2162. {
  2163. SIOCIWFIRSTPRIV + 0x6,
  2164. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
  2165. },
  2166. {
  2167. SIOCIWFIRSTPRIV + 0x7,
  2168. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "chplan"
  2169. }
  2170. };
  2171. static iw_handler r8711_private_handler[] = {
  2172. r8711_wx_read32,
  2173. r8711_wx_write32,
  2174. r8711_drvext_hdl,
  2175. r871x_mp_ioctl_hdl,
  2176. r871x_get_ap_info, /*for MM DTV platform*/
  2177. r871x_set_pid,
  2178. r871x_wps_start,
  2179. r871x_set_chplan
  2180. };
  2181. static struct iw_statistics *r871x_get_wireless_stats(struct net_device *dev)
  2182. {
  2183. struct _adapter *padapter = netdev_priv(dev);
  2184. struct iw_statistics *piwstats = &padapter->iwstats;
  2185. int tmp_level = 0;
  2186. int tmp_qual = 0;
  2187. int tmp_noise = 0;
  2188. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) != true) {
  2189. piwstats->qual.qual = 0;
  2190. piwstats->qual.level = 0;
  2191. piwstats->qual.noise = 0;
  2192. } else {
  2193. /* show percentage, we need transfer dbm to orignal value. */
  2194. tmp_level = padapter->recvpriv.fw_rssi;
  2195. tmp_qual = padapter->recvpriv.signal;
  2196. tmp_noise = padapter->recvpriv.noise;
  2197. piwstats->qual.level = tmp_level;
  2198. piwstats->qual.qual = tmp_qual;
  2199. piwstats->qual.noise = tmp_noise;
  2200. }
  2201. piwstats->qual.updated = IW_QUAL_ALL_UPDATED;
  2202. return &padapter->iwstats;
  2203. }
  2204. struct iw_handler_def r871x_handlers_def = {
  2205. .standard = r8711_handlers,
  2206. .num_standard = ARRAY_SIZE(r8711_handlers),
  2207. .private = r8711_private_handler,
  2208. .private_args = (struct iw_priv_args *)r8711_private_args,
  2209. .num_private = ARRAY_SIZE(r8711_private_handler),
  2210. .num_private_args = sizeof(r8711_private_args) /
  2211. sizeof(struct iw_priv_args),
  2212. .get_wireless_stats = r871x_get_wireless_stats
  2213. };