1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * This program is distributed in the hope that it will be useful, but WITHOUT
5 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9 * You should have received a copy of the GNU General Public License along with
10 * this program; if not, write to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
13 * The full GNU General Public License is included in this distribution in the
14 * file called LICENSE.
16 * Contact Information:
17 * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
20 #include <linux/string.h>
25 static u32 rtl8192_rates[] = {
26 1000000, 2000000, 5500000, 11000000, 6000000, 9000000, 12000000,
27 18000000, 24000000, 36000000, 48000000, 54000000
34 static int r8192_wx_get_freq(struct net_device *dev,
35 struct iw_request_info *a,
36 union iwreq_data *wrqu, char *b)
38 struct r8192_priv *priv = rtllib_priv(dev);
40 return rtllib_wx_get_freq(priv->rtllib, a, wrqu, b);
44 static int r8192_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
45 union iwreq_data *wrqu, char *b)
47 struct r8192_priv *priv = rtllib_priv(dev);
49 return rtllib_wx_get_mode(priv->rtllib, a, wrqu, b);
52 static int r8192_wx_get_rate(struct net_device *dev,
53 struct iw_request_info *info,
54 union iwreq_data *wrqu, char *extra)
56 struct r8192_priv *priv = rtllib_priv(dev);
58 return rtllib_wx_get_rate(priv->rtllib, info, wrqu, extra);
63 static int r8192_wx_set_rate(struct net_device *dev,
64 struct iw_request_info *info,
65 union iwreq_data *wrqu, char *extra)
68 struct r8192_priv *priv = rtllib_priv(dev);
70 if (priv->bHwRadioOff)
75 ret = rtllib_wx_set_rate(priv->rtllib, info, wrqu, extra);
83 static int r8192_wx_set_rts(struct net_device *dev,
84 struct iw_request_info *info,
85 union iwreq_data *wrqu, char *extra)
88 struct r8192_priv *priv = rtllib_priv(dev);
90 if (priv->bHwRadioOff)
95 ret = rtllib_wx_set_rts(priv->rtllib, info, wrqu, extra);
102 static int r8192_wx_get_rts(struct net_device *dev,
103 struct iw_request_info *info,
104 union iwreq_data *wrqu, char *extra)
106 struct r8192_priv *priv = rtllib_priv(dev);
108 return rtllib_wx_get_rts(priv->rtllib, info, wrqu, extra);
111 static int r8192_wx_set_power(struct net_device *dev,
112 struct iw_request_info *info,
113 union iwreq_data *wrqu, char *extra)
116 struct r8192_priv *priv = rtllib_priv(dev);
118 if (priv->bHwRadioOff) {
120 "%s():Hw is Radio Off, we can't set Power,return\n",
126 ret = rtllib_wx_set_power(priv->rtllib, info, wrqu, extra);
133 static int r8192_wx_get_power(struct net_device *dev,
134 struct iw_request_info *info,
135 union iwreq_data *wrqu, char *extra)
137 struct r8192_priv *priv = rtllib_priv(dev);
139 return rtllib_wx_get_power(priv->rtllib, info, wrqu, extra);
142 static int r8192_wx_set_rawtx(struct net_device *dev,
143 struct iw_request_info *info,
144 union iwreq_data *wrqu, char *extra)
146 struct r8192_priv *priv = rtllib_priv(dev);
149 if (priv->bHwRadioOff)
154 ret = rtllib_wx_set_rawtx(priv->rtllib, info, wrqu, extra);
162 static int r8192_wx_force_reset(struct net_device *dev,
163 struct iw_request_info *info,
164 union iwreq_data *wrqu, char *extra)
166 struct r8192_priv *priv = rtllib_priv(dev);
170 RT_TRACE(COMP_DBG, "%s(): force reset ! extra is %d\n",
172 priv->force_reset = *extra;
178 static int r8192_wx_force_mic_error(struct net_device *dev,
179 struct iw_request_info *info,
180 union iwreq_data *wrqu, char *extra)
182 struct r8192_priv *priv = rtllib_priv(dev);
183 struct rtllib_device *ieee = priv->rtllib;
187 RT_TRACE(COMP_DBG, "%s(): force mic error !\n", __func__);
188 ieee->force_mic_error = true;
194 #define MAX_ADHOC_PEER_NUM 64
195 struct adhoc_peer_entry {
196 unsigned char MacAddr[ETH_ALEN];
197 unsigned char WirelessMode;
198 unsigned char bCurTxBW40MHz;
200 struct adhoc_peers_info {
201 struct adhoc_peer_entry Entry[MAX_ADHOC_PEER_NUM];
205 static int r8192_wx_get_adhoc_peers(struct net_device *dev,
206 struct iw_request_info *info,
207 union iwreq_data *wrqu, char *extra)
213 static int r8191se_wx_get_firm_version(struct net_device *dev,
214 struct iw_request_info *info,
215 struct iw_param *wrqu, char *extra)
220 static int r8192_wx_adapter_power_status(struct net_device *dev,
221 struct iw_request_info *info,
222 union iwreq_data *wrqu, char *extra)
224 struct r8192_priv *priv = rtllib_priv(dev);
225 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
226 (&(priv->rtllib->PowerSaveControl));
227 struct rtllib_device *ieee = priv->rtllib;
231 RT_TRACE(COMP_POWER, "%s(): %s\n", __func__, (*extra == 6) ?
232 "DC power" : "AC power");
233 if (*extra || priv->force_lps) {
234 priv->ps_force = false;
235 pPSC->bLeisurePs = true;
237 if (priv->rtllib->state == RTLLIB_LINKED)
240 priv->ps_force = true;
241 pPSC->bLeisurePs = false;
250 static int r8192se_wx_set_radio(struct net_device *dev,
251 struct iw_request_info *info,
252 union iwreq_data *wrqu, char *extra)
254 struct r8192_priv *priv = rtllib_priv(dev);
258 netdev_info(dev, "%s(): set radio ! extra is %d\n", __func__, *extra);
259 if ((*extra != 0) && (*extra != 1)) {
261 "%s(): set radio an err value,must 0(radio off) or 1(radio on)\n",
266 priv->sw_radio_on = *extra;
272 static int r8192se_wx_set_lps_awake_interval(struct net_device *dev,
273 struct iw_request_info *info,
274 union iwreq_data *wrqu, char *extra)
276 struct r8192_priv *priv = rtllib_priv(dev);
277 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
278 (&(priv->rtllib->PowerSaveControl));
282 netdev_info(dev, "%s(): set lps awake interval ! extra is %d\n",
285 pPSC->RegMaxLPSAwakeIntvl = *extra;
290 static int r8192se_wx_set_force_lps(struct net_device *dev,
291 struct iw_request_info *info,
292 union iwreq_data *wrqu, char *extra)
294 struct r8192_priv *priv = rtllib_priv(dev);
299 "%s(): force LPS ! extra is %d (1 is open 0 is close)\n",
301 priv->force_lps = *extra;
307 static int r8192_wx_set_debugflag(struct net_device *dev,
308 struct iw_request_info *info,
309 union iwreq_data *wrqu, char *extra)
311 struct r8192_priv *priv = rtllib_priv(dev);
314 if (priv->bHwRadioOff)
317 netdev_info(dev, "=====>%s(), *extra:%x, debugflag:%x\n", __func__,
318 *extra, rt_global_debug_component);
320 rt_global_debug_component |= (1<<c);
322 rt_global_debug_component &= BIT31;
326 static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
327 union iwreq_data *wrqu, char *b)
329 struct r8192_priv *priv = rtllib_priv(dev);
330 struct rtllib_device *ieee = netdev_priv_rsl(dev);
332 enum rt_rf_power_state rtState;
335 if (priv->bHwRadioOff)
337 rtState = priv->rtllib->eRFPowerState;
339 if (wrqu->mode == IW_MODE_ADHOC || wrqu->mode == IW_MODE_MONITOR ||
340 ieee->bNetPromiscuousMode) {
341 if (priv->rtllib->PowerSaveControl.bInactivePs) {
342 if (rtState == eRfOff) {
343 if (priv->rtllib->RfOffReason >
345 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",
350 netdev_info(dev, "=========>%s(): IPSLeave\n",
352 down(&priv->rtllib->ips_sem);
354 up(&priv->rtllib->ips_sem);
358 ret = rtllib_wx_set_mode(priv->rtllib, a, wrqu, b);
364 struct iw_range_with_scan_capa {
365 /* Informative stuff (to choose between different interface) */
366 __u32 throughput; /* To give an idea... */
367 /* In theory this value should be the maximum benchmarked
368 * TCP/IP throughput, because with most of these devices the
369 * bit rate is meaningless (overhead an co) to estimate how
370 * fast the connection will go and pick the fastest one.
371 * I suggest people to play with Netperf or any benchmark...
374 /* NWID (or domain id) */
375 __u32 min_nwid; /* Minimal NWID we are able to set */
376 __u32 max_nwid; /* Maximal NWID we are able to set */
378 /* Old Frequency (backward compat - moved lower ) */
379 __u16 old_num_channels;
380 __u8 old_num_frequency;
382 /* Scan capabilities */
386 static int rtl8192_wx_get_range(struct net_device *dev,
387 struct iw_request_info *info,
388 union iwreq_data *wrqu, char *extra)
390 struct iw_range *range = (struct iw_range *)extra;
391 struct r8192_priv *priv = rtllib_priv(dev);
395 wrqu->data.length = sizeof(*range);
396 memset(range, 0, sizeof(*range));
398 /* ~130 Mb/s real (802.11n) */
399 range->throughput = 130 * 1000 * 1000;
401 if (priv->rf_set_sens != NULL) {
402 /* signal level threshold range */
403 range->sensitivity = priv->max_sens;
406 range->max_qual.qual = 100;
407 range->max_qual.level = 0;
408 range->max_qual.noise = 0;
409 range->max_qual.updated = 7; /* Updated all three */
411 range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
412 range->avg_qual.level = 0;
413 range->avg_qual.noise = 0;
414 range->avg_qual.updated = 7; /* Updated all three */
416 range->num_bitrates = min(RATE_COUNT, IW_MAX_BITRATES);
418 for (i = 0; i < range->num_bitrates; i++)
419 range->bitrate[i] = rtl8192_rates[i];
421 range->max_rts = DEFAULT_RTS_THRESHOLD;
422 range->min_frag = MIN_FRAG_THRESHOLD;
423 range->max_frag = MAX_FRAG_THRESHOLD;
426 range->max_pmp = 5000000;
428 range->max_pmt = 65535*1000;
429 range->pmp_flags = IW_POWER_PERIOD;
430 range->pmt_flags = IW_POWER_TIMEOUT;
431 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
432 range->we_version_compiled = WIRELESS_EXT;
433 range->we_version_source = 18;
435 for (i = 0, val = 0; i < 14; i++) {
436 if ((priv->rtllib->active_channel_map)[i+1]) {
437 range->freq[val].i = i + 1;
438 range->freq[val].m = rtllib_wlan_frequencies[i] *
440 range->freq[val].e = 1;
444 if (val == IW_MAX_FREQUENCIES)
447 range->num_frequency = val;
448 range->num_channels = val;
449 range->enc_capa = IW_ENC_CAPA_WPA|IW_ENC_CAPA_WPA2|
450 IW_ENC_CAPA_CIPHER_TKIP|IW_ENC_CAPA_CIPHER_CCMP;
451 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
453 /* Event capability (kernel + driver) */
458 static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
459 union iwreq_data *wrqu, char *b)
461 struct r8192_priv *priv = rtllib_priv(dev);
462 struct rtllib_device *ieee = priv->rtllib;
463 enum rt_rf_power_state rtState;
466 if (!(ieee->softmac_features & IEEE_SOFTMAC_SCAN)) {
467 if ((ieee->state >= RTLLIB_ASSOCIATING) &&
468 (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED))
470 if ((priv->rtllib->state == RTLLIB_LINKED) &&
471 (priv->rtllib->CntAfterLink < 2))
475 if (priv->bHwRadioOff) {
476 netdev_info(dev, "================>%s(): hwradio off\n",
480 rtState = priv->rtllib->eRFPowerState;
483 if (priv->rtllib->LinkDetectInfo.bBusyTraffic == true)
486 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
487 struct iw_scan_req *req = (struct iw_scan_req *)b;
489 if (req->essid_len) {
490 ieee->current_network.ssid_len = req->essid_len;
491 memcpy(ieee->current_network.ssid, req->essid,
498 priv->rtllib->FirstIe_InScan = true;
500 if (priv->rtllib->state != RTLLIB_LINKED) {
501 if (priv->rtllib->PowerSaveControl.bInactivePs) {
502 if (rtState == eRfOff) {
503 if (priv->rtllib->RfOffReason >
506 "%s(): RF is OFF.\n",
511 RT_TRACE(COMP_PS, "=========>%s(): IPSLeave\n",
513 down(&priv->rtllib->ips_sem);
515 up(&priv->rtllib->ips_sem);
518 rtllib_stop_scan(priv->rtllib);
519 if (priv->rtllib->LedControlHandler)
520 priv->rtllib->LedControlHandler(dev,
521 LED_CTL_SITE_SURVEY);
523 if (priv->rtllib->eRFPowerState != eRfOff) {
524 priv->rtllib->actscanning = true;
526 if (ieee->ScanOperationBackupHandler)
527 ieee->ScanOperationBackupHandler(ieee->dev,
530 rtllib_start_scan_syncro(priv->rtllib, 0);
532 if (ieee->ScanOperationBackupHandler)
533 ieee->ScanOperationBackupHandler(ieee->dev,
538 priv->rtllib->actscanning = true;
539 ret = rtllib_wx_set_scan(priv->rtllib, a, wrqu, b);
547 static int r8192_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
548 union iwreq_data *wrqu, char *b)
552 struct r8192_priv *priv = rtllib_priv(dev);
557 if (priv->bHwRadioOff)
563 ret = rtllib_wx_get_scan(priv->rtllib, a, wrqu, b);
570 static int r8192_wx_set_essid(struct net_device *dev,
571 struct iw_request_info *a,
572 union iwreq_data *wrqu, char *b)
574 struct r8192_priv *priv = rtllib_priv(dev);
577 if (priv->bHwRadioOff) {
579 "=========>%s():hw radio off,or Rf state is eRfOff, return\n",
584 ret = rtllib_wx_set_essid(priv->rtllib, a, wrqu, b);
591 static int r8192_wx_get_essid(struct net_device *dev,
592 struct iw_request_info *a,
593 union iwreq_data *wrqu, char *b)
596 struct r8192_priv *priv = rtllib_priv(dev);
600 ret = rtllib_wx_get_essid(priv->rtllib, a, wrqu, b);
607 static int r8192_wx_set_nick(struct net_device *dev,
608 struct iw_request_info *info,
609 union iwreq_data *wrqu, char *extra)
611 struct r8192_priv *priv = rtllib_priv(dev);
613 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
616 wrqu->data.length = min_t(size_t, wrqu->data.length, sizeof(priv->nick));
617 memset(priv->nick, 0, sizeof(priv->nick));
618 memcpy(priv->nick, extra, wrqu->data.length);
624 static int r8192_wx_get_nick(struct net_device *dev,
625 struct iw_request_info *info,
626 union iwreq_data *wrqu, char *extra)
628 struct r8192_priv *priv = rtllib_priv(dev);
631 wrqu->data.length = strlen(priv->nick);
632 memcpy(extra, priv->nick, wrqu->data.length);
633 wrqu->data.flags = 1; /* active */
638 static int r8192_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
639 union iwreq_data *wrqu, char *b)
642 struct r8192_priv *priv = rtllib_priv(dev);
644 if (priv->bHwRadioOff)
649 ret = rtllib_wx_set_freq(priv->rtllib, a, wrqu, b);
655 static int r8192_wx_get_name(struct net_device *dev,
656 struct iw_request_info *info,
657 union iwreq_data *wrqu, char *extra)
659 struct r8192_priv *priv = rtllib_priv(dev);
661 return rtllib_wx_get_name(priv->rtllib, info, wrqu, extra);
665 static int r8192_wx_set_frag(struct net_device *dev,
666 struct iw_request_info *info,
667 union iwreq_data *wrqu, char *extra)
669 struct r8192_priv *priv = rtllib_priv(dev);
671 if (priv->bHwRadioOff)
674 if (wrqu->frag.disabled)
675 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
677 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
678 wrqu->frag.value > MAX_FRAG_THRESHOLD)
681 priv->rtllib->fts = wrqu->frag.value & ~0x1;
688 static int r8192_wx_get_frag(struct net_device *dev,
689 struct iw_request_info *info,
690 union iwreq_data *wrqu, char *extra)
692 struct r8192_priv *priv = rtllib_priv(dev);
694 wrqu->frag.value = priv->rtllib->fts;
695 wrqu->frag.fixed = 0; /* no auto select */
696 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD);
702 static int r8192_wx_set_wap(struct net_device *dev,
703 struct iw_request_info *info,
704 union iwreq_data *awrq,
708 struct r8192_priv *priv = rtllib_priv(dev);
710 if (priv->bHwRadioOff)
715 ret = rtllib_wx_set_wap(priv->rtllib, info, awrq, extra);
724 static int r8192_wx_get_wap(struct net_device *dev,
725 struct iw_request_info *info,
726 union iwreq_data *wrqu, char *extra)
728 struct r8192_priv *priv = rtllib_priv(dev);
730 return rtllib_wx_get_wap(priv->rtllib, info, wrqu, extra);
734 static int r8192_wx_get_enc(struct net_device *dev,
735 struct iw_request_info *info,
736 union iwreq_data *wrqu, char *key)
738 struct r8192_priv *priv = rtllib_priv(dev);
740 return rtllib_wx_get_encode(priv->rtllib, info, wrqu, key);
743 static int r8192_wx_set_enc(struct net_device *dev,
744 struct iw_request_info *info,
745 union iwreq_data *wrqu, char *key)
747 struct r8192_priv *priv = rtllib_priv(dev);
750 struct rtllib_device *ieee = priv->rtllib;
751 u32 hwkey[4] = {0, 0, 0, 0};
754 u8 zero_addr[4][6] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
755 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
756 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
757 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
760 if (priv->bHwRadioOff)
766 priv->rtllib->wx_set_enc = 1;
767 down(&priv->rtllib->ips_sem);
769 up(&priv->rtllib->ips_sem);
772 RT_TRACE(COMP_SEC, "Setting SW wep key");
773 ret = rtllib_wx_set_encode(priv->rtllib, info, wrqu, key);
777 if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
778 ieee->pairwise_key_type = ieee->group_key_type = KEY_TYPE_NA;
779 CamResetAllEntry(dev);
780 memset(priv->rtllib->swcamtable, 0,
781 sizeof(struct sw_cam_table) * 32);
784 if (wrqu->encoding.length != 0) {
786 for (i = 0; i < 4; i++) {
787 hwkey[i] |= key[4*i+0]&mask;
788 if (i == 1 && (4 * i + 1) == wrqu->encoding.length)
790 if (i == 3 && (4 * i + 1) == wrqu->encoding.length)
792 hwkey[i] |= (key[4 * i + 1] & mask) << 8;
793 hwkey[i] |= (key[4 * i + 2] & mask) << 16;
794 hwkey[i] |= (key[4 * i + 3] & mask) << 24;
797 #define CONF_WEP40 0x4
798 #define CONF_WEP104 0x14
800 switch (wrqu->encoding.flags & IW_ENCODE_INDEX) {
802 key_idx = ieee->crypt_info.tx_keyidx;
819 if (wrqu->encoding.length == 0x5) {
820 ieee->pairwise_key_type = KEY_TYPE_WEP40;
821 EnableHWSecurityConfig8192(dev);
824 else if (wrqu->encoding.length == 0xd) {
825 ieee->pairwise_key_type = KEY_TYPE_WEP104;
826 EnableHWSecurityConfig8192(dev);
827 setKey(dev, key_idx, key_idx, KEY_TYPE_WEP104,
828 zero_addr[key_idx], 0, hwkey);
829 set_swcam(dev, key_idx, key_idx, KEY_TYPE_WEP104,
830 zero_addr[key_idx], 0, hwkey, 0);
833 "wrong type in WEP, not WEP40 and WEP104\n");
838 priv->rtllib->wx_set_enc = 0;
842 static int r8192_wx_set_scan_type(struct net_device *dev,
843 struct iw_request_info *aa,
844 union iwreq_data *wrqu, char *p)
846 struct r8192_priv *priv = rtllib_priv(dev);
847 int *parms = (int *)p;
850 if (priv->bHwRadioOff)
853 priv->rtllib->active_scan = mode;
860 #define R8192_MAX_RETRY 255
861 static int r8192_wx_set_retry(struct net_device *dev,
862 struct iw_request_info *info,
863 union iwreq_data *wrqu, char *extra)
865 struct r8192_priv *priv = rtllib_priv(dev);
868 if (priv->bHwRadioOff)
873 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
874 wrqu->retry.disabled) {
878 if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) {
883 if (wrqu->retry.value > R8192_MAX_RETRY) {
887 if (wrqu->retry.flags & IW_RETRY_MAX) {
888 priv->retry_rts = wrqu->retry.value;
889 DMESG("Setting retry for RTS/CTS data to %d",
893 priv->retry_data = wrqu->retry.value;
894 DMESG("Setting retry for non RTS/CTS data to %d",
906 static int r8192_wx_get_retry(struct net_device *dev,
907 struct iw_request_info *info,
908 union iwreq_data *wrqu, char *extra)
910 struct r8192_priv *priv = rtllib_priv(dev);
913 wrqu->retry.disabled = 0; /* can't be disabled */
915 if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
919 if (wrqu->retry.flags & IW_RETRY_MAX) {
920 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
921 wrqu->retry.value = priv->retry_rts;
923 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
924 wrqu->retry.value = priv->retry_data;
929 static int r8192_wx_get_sens(struct net_device *dev,
930 struct iw_request_info *info,
931 union iwreq_data *wrqu, char *extra)
933 struct r8192_priv *priv = rtllib_priv(dev);
935 if (priv->rf_set_sens == NULL)
936 return -1; /* we have not this support for this radio */
937 wrqu->sens.value = priv->sens;
942 static int r8192_wx_set_sens(struct net_device *dev,
943 struct iw_request_info *info,
944 union iwreq_data *wrqu, char *extra)
947 struct r8192_priv *priv = rtllib_priv(dev);
951 if (priv->bHwRadioOff)
955 if (priv->rf_set_sens == NULL) {
956 err = -1; /* we have not this support for this radio */
959 if (priv->rf_set_sens(dev, wrqu->sens.value) == 0)
960 priv->sens = wrqu->sens.value;
970 static int r8192_wx_set_enc_ext(struct net_device *dev,
971 struct iw_request_info *info,
972 union iwreq_data *wrqu, char *extra)
975 struct r8192_priv *priv = rtllib_priv(dev);
976 struct rtllib_device *ieee = priv->rtllib;
978 if (priv->bHwRadioOff)
983 priv->rtllib->wx_set_enc = 1;
984 down(&priv->rtllib->ips_sem);
986 up(&priv->rtllib->ips_sem);
988 ret = rtllib_wx_set_encode_ext(ieee, info, wrqu, extra);
990 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
993 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
994 struct iw_point *encoding = &wrqu->encoding;
995 u8 idx = 0, alg = 0, group = 0;
997 if ((encoding->flags & IW_ENCODE_DISABLED) ||
998 ext->alg == IW_ENCODE_ALG_NONE) {
999 ieee->pairwise_key_type = ieee->group_key_type
1001 CamResetAllEntry(dev);
1002 memset(priv->rtllib->swcamtable, 0,
1003 sizeof(struct sw_cam_table) * 32);
1006 alg = (ext->alg == IW_ENCODE_ALG_CCMP) ? KEY_TYPE_CCMP :
1008 idx = encoding->flags & IW_ENCODE_INDEX;
1011 group = ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY;
1013 if ((!group) || (IW_MODE_ADHOC == ieee->iw_mode) ||
1014 (alg == KEY_TYPE_WEP40)) {
1015 if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40))
1016 alg = KEY_TYPE_WEP104;
1017 ieee->pairwise_key_type = alg;
1018 EnableHWSecurityConfig8192(dev);
1020 memcpy((u8 *)key, ext->key, 16);
1022 if ((alg & KEY_TYPE_WEP40) && (ieee->auth_mode != 2)) {
1023 if (ext->key_len == 13)
1024 ieee->pairwise_key_type = alg = KEY_TYPE_WEP104;
1025 setKey(dev, idx, idx, alg, zero, 0, key);
1026 set_swcam(dev, idx, idx, alg, zero, 0, key, 0);
1028 ieee->group_key_type = alg;
1029 setKey(dev, idx, idx, alg, broadcast_addr, 0, key);
1030 set_swcam(dev, idx, idx, alg, broadcast_addr, 0,
1033 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) &&
1034 ieee->pHTInfo->bCurrentHTSupport)
1035 write_nic_byte(dev, 0x173, 1);
1036 setKey(dev, 4, idx, alg, (u8 *)ieee->ap_mac_addr,
1038 set_swcam(dev, 4, idx, alg, (u8 *)ieee->ap_mac_addr,
1046 priv->rtllib->wx_set_enc = 0;
1051 static int r8192_wx_set_auth(struct net_device *dev,
1052 struct iw_request_info *info,
1053 union iwreq_data *data, char *extra)
1057 struct r8192_priv *priv = rtllib_priv(dev);
1059 if (priv->bHwRadioOff)
1062 down(&priv->wx_sem);
1063 ret = rtllib_wx_set_auth(priv->rtllib, info, &(data->param), extra);
1068 static int r8192_wx_set_mlme(struct net_device *dev,
1069 struct iw_request_info *info,
1070 union iwreq_data *wrqu, char *extra)
1075 struct r8192_priv *priv = rtllib_priv(dev);
1077 if (priv->bHwRadioOff)
1080 down(&priv->wx_sem);
1081 ret = rtllib_wx_set_mlme(priv->rtllib, info, wrqu, extra);
1086 static int r8192_wx_set_gen_ie(struct net_device *dev,
1087 struct iw_request_info *info,
1088 union iwreq_data *data, char *extra)
1092 struct r8192_priv *priv = rtllib_priv(dev);
1094 if (priv->bHwRadioOff)
1097 down(&priv->wx_sem);
1098 ret = rtllib_wx_set_gen_ie(priv->rtllib, extra, data->data.length);
1103 static int r8192_wx_get_gen_ie(struct net_device *dev,
1104 struct iw_request_info *info,
1105 union iwreq_data *data, char *extra)
1108 struct r8192_priv *priv = rtllib_priv(dev);
1109 struct rtllib_device *ieee = priv->rtllib;
1111 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
1112 data->data.length = 0;
1116 if (data->data.length < ieee->wpa_ie_len)
1119 data->data.length = ieee->wpa_ie_len;
1120 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
1124 #define OID_RT_INTEL_PROMISCUOUS_MODE 0xFF0101F6
1126 static int r8192_wx_set_PromiscuousMode(struct net_device *dev,
1127 struct iw_request_info *info,
1128 union iwreq_data *wrqu, char *extra)
1130 struct r8192_priv *priv = rtllib_priv(dev);
1131 struct rtllib_device *ieee = priv->rtllib;
1137 u32 bFilterSourceStationFrame;
1139 if (copy_from_user(info_buf, wrqu->data.pointer, sizeof(info_buf)))
1143 bPromiscuousOn = info_buf[1];
1144 bFilterSourceStationFrame = info_buf[2];
1146 if (OID_RT_INTEL_PROMISCUOUS_MODE == oid) {
1147 ieee->IntelPromiscuousModeInfo.bPromiscuousOn =
1148 (bPromiscuousOn) ? (true) : (false);
1149 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1150 (bFilterSourceStationFrame) ? (true) : (false);
1152 (rtllib_EnableIntelPromiscuousMode(dev, false)) :
1153 (rtllib_DisableIntelPromiscuousMode(dev, false));
1156 "=======>%s(), on = %d, filter src sta = %d\n",
1157 __func__, bPromiscuousOn,
1158 bFilterSourceStationFrame);
1167 static int r8192_wx_get_PromiscuousMode(struct net_device *dev,
1168 struct iw_request_info *info,
1169 union iwreq_data *wrqu, char *extra)
1171 struct r8192_priv *priv = rtllib_priv(dev);
1172 struct rtllib_device *ieee = priv->rtllib;
1174 down(&priv->wx_sem);
1176 snprintf(extra, 45, "PromiscuousMode:%d, FilterSrcSTAFrame:%d",
1177 ieee->IntelPromiscuousModeInfo.bPromiscuousOn,
1178 ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame);
1179 wrqu->data.length = strlen(extra) + 1;
1187 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
1188 static iw_handler r8192_wx_handlers[] = {
1189 IW_IOCTL(SIOCGIWNAME) = r8192_wx_get_name,
1190 IW_IOCTL(SIOCSIWFREQ) = r8192_wx_set_freq,
1191 IW_IOCTL(SIOCGIWFREQ) = r8192_wx_get_freq,
1192 IW_IOCTL(SIOCSIWMODE) = r8192_wx_set_mode,
1193 IW_IOCTL(SIOCGIWMODE) = r8192_wx_get_mode,
1194 IW_IOCTL(SIOCSIWSENS) = r8192_wx_set_sens,
1195 IW_IOCTL(SIOCGIWSENS) = r8192_wx_get_sens,
1196 IW_IOCTL(SIOCGIWRANGE) = rtl8192_wx_get_range,
1197 IW_IOCTL(SIOCSIWAP) = r8192_wx_set_wap,
1198 IW_IOCTL(SIOCGIWAP) = r8192_wx_get_wap,
1199 IW_IOCTL(SIOCSIWSCAN) = r8192_wx_set_scan,
1200 IW_IOCTL(SIOCGIWSCAN) = r8192_wx_get_scan,
1201 IW_IOCTL(SIOCSIWESSID) = r8192_wx_set_essid,
1202 IW_IOCTL(SIOCGIWESSID) = r8192_wx_get_essid,
1203 IW_IOCTL(SIOCSIWNICKN) = r8192_wx_set_nick,
1204 IW_IOCTL(SIOCGIWNICKN) = r8192_wx_get_nick,
1205 IW_IOCTL(SIOCSIWRATE) = r8192_wx_set_rate,
1206 IW_IOCTL(SIOCGIWRATE) = r8192_wx_get_rate,
1207 IW_IOCTL(SIOCSIWRTS) = r8192_wx_set_rts,
1208 IW_IOCTL(SIOCGIWRTS) = r8192_wx_get_rts,
1209 IW_IOCTL(SIOCSIWFRAG) = r8192_wx_set_frag,
1210 IW_IOCTL(SIOCGIWFRAG) = r8192_wx_get_frag,
1211 IW_IOCTL(SIOCSIWRETRY) = r8192_wx_set_retry,
1212 IW_IOCTL(SIOCGIWRETRY) = r8192_wx_get_retry,
1213 IW_IOCTL(SIOCSIWENCODE) = r8192_wx_set_enc,
1214 IW_IOCTL(SIOCGIWENCODE) = r8192_wx_get_enc,
1215 IW_IOCTL(SIOCSIWPOWER) = r8192_wx_set_power,
1216 IW_IOCTL(SIOCGIWPOWER) = r8192_wx_get_power,
1217 IW_IOCTL(SIOCSIWGENIE) = r8192_wx_set_gen_ie,
1218 IW_IOCTL(SIOCGIWGENIE) = r8192_wx_get_gen_ie,
1219 IW_IOCTL(SIOCSIWMLME) = r8192_wx_set_mlme,
1220 IW_IOCTL(SIOCSIWAUTH) = r8192_wx_set_auth,
1221 IW_IOCTL(SIOCSIWENCODEEXT) = r8192_wx_set_enc_ext,
1224 /* the following rule need to be following,
1225 * Odd : get (world access),
1226 * even : set (root access)
1228 static const struct iw_priv_args r8192_private_args[] = {
1230 SIOCIWFIRSTPRIV + 0x0,
1231 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_debugflag"
1233 SIOCIWFIRSTPRIV + 0x1,
1234 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "activescan"
1236 SIOCIWFIRSTPRIV + 0x2,
1237 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx"
1239 SIOCIWFIRSTPRIV + 0x3,
1240 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "forcereset"
1242 SIOCIWFIRSTPRIV + 0x4,
1243 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "force_mic_error"
1245 SIOCIWFIRSTPRIV + 0x5,
1246 IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT|IW_PRIV_SIZE_FIXED|1,
1249 SIOCIWFIRSTPRIV + 0x6,
1250 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED|1, IW_PRIV_TYPE_NONE,
1253 SIOCIWFIRSTPRIV + 0x9,
1254 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED|1, IW_PRIV_TYPE_NONE,
1257 SIOCIWFIRSTPRIV + 0xa,
1258 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED|1, IW_PRIV_TYPE_NONE,
1261 SIOCIWFIRSTPRIV + 0xb,
1262 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED|1, IW_PRIV_TYPE_NONE,
1265 SIOCIWFIRSTPRIV + 0xc,
1266 0, IW_PRIV_TYPE_CHAR|2047, "adhoc_peer_list"
1268 SIOCIWFIRSTPRIV + 0x16,
1269 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "setpromisc"
1271 SIOCIWFIRSTPRIV + 0x17,
1272 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 45, "getpromisc"
1277 static iw_handler r8192_private_handler[] = {
1278 (iw_handler)r8192_wx_set_debugflag, /*SIOCIWSECONDPRIV*/
1279 (iw_handler)r8192_wx_set_scan_type,
1280 (iw_handler)r8192_wx_set_rawtx,
1281 (iw_handler)r8192_wx_force_reset,
1282 (iw_handler)r8192_wx_force_mic_error,
1283 (iw_handler)r8191se_wx_get_firm_version,
1284 (iw_handler)r8192_wx_adapter_power_status,
1287 (iw_handler)r8192se_wx_set_radio,
1288 (iw_handler)r8192se_wx_set_lps_awake_interval,
1289 (iw_handler)r8192se_wx_set_force_lps,
1290 (iw_handler)r8192_wx_get_adhoc_peers,
1300 (iw_handler)r8192_wx_set_PromiscuousMode,
1301 (iw_handler)r8192_wx_get_PromiscuousMode,
1304 static struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
1306 struct r8192_priv *priv = rtllib_priv(dev);
1307 struct rtllib_device *ieee = priv->rtllib;
1308 struct iw_statistics *wstats = &priv->wstats;
1313 if (ieee->state < RTLLIB_LINKED) {
1314 wstats->qual.qual = 10;
1315 wstats->qual.level = 0;
1316 wstats->qual.noise = -100;
1317 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1321 tmp_level = (&ieee->current_network)->stats.rssi;
1322 tmp_qual = (&ieee->current_network)->stats.signal;
1323 tmp_noise = (&ieee->current_network)->stats.noise;
1325 wstats->qual.level = tmp_level;
1326 wstats->qual.qual = tmp_qual;
1327 wstats->qual.noise = tmp_noise;
1328 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1332 const struct iw_handler_def r8192_wx_handlers_def = {
1333 .standard = r8192_wx_handlers,
1334 .num_standard = ARRAY_SIZE(r8192_wx_handlers),
1335 .private = r8192_private_handler,
1336 .num_private = ARRAY_SIZE(r8192_private_handler),
1337 .num_private_args = sizeof(r8192_private_args) /
1338 sizeof(struct iw_priv_args),
1339 .get_wireless_stats = r8192_get_wireless_stats,
1340 .private_args = (struct iw_priv_args *)r8192_private_args,