1
/***************************************************************************
2
* RT2x00 SourceForge Project - http://rt2x00.sourceforge.net *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
* Licensed under the GNU GPL *
20
* Original code supplied under license from RaLink Inc, 2004. *
21
***************************************************************************/
23
/*************************************************************************
25
* Module Name: rtusb_info.c
31
* -------- ---------- -------------------------
32
* Name Date Modification logs
33
* Jan Lee 2005-06-01 Release
34
* RobinC 02-06-2005 RFMON Mode added
35
* RobinC 02-06-2005 Fix frequency reporting
36
* MarkW 13-07-2005 Fix ESSID reporting
37
*************************************************************************/
39
#include "rt_config.h"
40
#include <net/iw_handler.h>
44
#define WEP_SMALL_KEY_LEN (40/8)
45
#define WEP_LARGE_KEY_LEN (104/8)
48
#define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \
51
case 1: khz = 2412000; break; \
52
case 2: khz = 2417000; break; \
53
case 3: khz = 2422000; break; \
54
case 4: khz = 2427000; break; \
55
case 5: khz = 2432000; break; \
56
case 6: khz = 2437000; break; \
57
case 7: khz = 2442000; break; \
58
case 8: khz = 2447000; break; \
59
case 9: khz = 2452000; break; \
60
case 10: khz = 2457000; break; \
61
case 11: khz = 2462000; break; \
62
case 12: khz = 2467000; break; \
63
case 13: khz = 2472000; break; \
64
case 14: khz = 2484000; break; \
65
case 36: /* UNII */ khz = 5180000; break; \
66
case 40: /* UNII */ khz = 5200000; break; \
67
case 44: /* UNII */ khz = 5220000; break; \
68
case 48: /* UNII */ khz = 5240000; break; \
69
case 52: /* UNII */ khz = 5260000; break; \
70
case 56: /* UNII */ khz = 5280000; break; \
71
case 60: /* UNII */ khz = 5300000; break; \
72
case 64: /* UNII */ khz = 5320000; break; \
73
case 149: /* UNII */ khz = 5745000; break; \
74
case 153: /* UNII */ khz = 5765000; break; \
75
case 157: /* UNII */ khz = 5785000; break; \
76
case 161: /* UNII */ khz = 5805000; break; \
77
case 100: /* HiperLAN2 */ khz = 5500000; break; \
78
case 104: /* HiperLAN2 */ khz = 5520000; break; \
79
case 108: /* HiperLAN2 */ khz = 5540000; break; \
80
case 112: /* HiperLAN2 */ khz = 5560000; break; \
81
case 116: /* HiperLAN2 */ khz = 5580000; break; \
82
case 120: /* HiperLAN2 */ khz = 5600000; break; \
83
case 124: /* HiperLAN2 */ khz = 5620000; break; \
84
case 128: /* HiperLAN2 */ khz = 5640000; break; \
85
case 132: /* HiperLAN2 */ khz = 5660000; break; \
86
case 136: /* HiperLAN2 */ khz = 5680000; break; \
87
case 140: /* HiperLAN2 */ khz = 5700000; break; \
88
case 34: /* Japan MMAC */ khz = 5170000; break; \
89
case 38: /* Japan MMAC */ khz = 5190000; break; \
90
case 42: /* Japan MMAC */ khz = 5210000; break; \
91
case 46: /* Japan MMAC */ khz = 5230000; break; \
92
default: khz = 2412000; break; \
96
#define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \
99
case 2412000: ch = 1; break; \
100
case 2417000: ch = 2; break; \
101
case 2422000: ch = 3; break; \
102
case 2427000: ch = 4; break; \
103
case 2432000: ch = 5; break; \
104
case 2437000: ch = 6; break; \
105
case 2442000: ch = 7; break; \
106
case 2447000: ch = 8; break; \
107
case 2452000: ch = 9; break; \
108
case 2457000: ch = 10; break; \
109
case 2462000: ch = 11; break; \
110
case 2467000: ch = 12; break; \
111
case 2472000: ch = 13; break; \
112
case 2484000: ch = 14; break; \
113
case 5180000: ch = 36; /* UNII */ break; \
114
case 5200000: ch = 40; /* UNII */ break; \
115
case 5220000: ch = 44; /* UNII */ break; \
116
case 5240000: ch = 48; /* UNII */ break; \
117
case 5260000: ch = 52; /* UNII */ break; \
118
case 5280000: ch = 56; /* UNII */ break; \
119
case 5300000: ch = 60; /* UNII */ break; \
120
case 5320000: ch = 64; /* UNII */ break; \
121
case 5745000: ch = 149; /* UNII */ break; \
122
case 5765000: ch = 153; /* UNII */ break; \
123
case 5785000: ch = 157; /* UNII */ break; \
124
case 5805000: ch = 161; /* UNII */ break; \
125
case 5500000: ch = 100; /* HiperLAN2 */ break; \
126
case 5520000: ch = 104; /* HiperLAN2 */ break; \
127
case 5540000: ch = 108; /* HiperLAN2 */ break; \
128
case 5560000: ch = 112; /* HiperLAN2 */ break; \
129
case 5580000: ch = 116; /* HiperLAN2 */ break; \
130
case 5600000: ch = 120; /* HiperLAN2 */ break; \
131
case 5620000: ch = 124; /* HiperLAN2 */ break; \
132
case 5640000: ch = 128; /* HiperLAN2 */ break; \
133
case 5660000: ch = 132; /* HiperLAN2 */ break; \
134
case 5680000: ch = 136; /* HiperLAN2 */ break; \
135
case 5700000: ch = 140; /* HiperLAN2 */ break; \
136
case 5170000: ch = 34; /* Japan MMAC */ break; \
137
case 5190000: ch = 38; /* Japan MMAC */ break; \
138
case 5210000: ch = 42; /* Japan MMAC */ break; \
139
case 5230000: ch = 46; /* Japan MMAC */ break; \
140
default: ch = 1; break; \
149
int (*set_proc)(PRT2570ADAPTER pAdapter, PUCHAR arg);
150
} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
151
{"CountryRegion", Set_CountryRegion_Proc },
152
{"SSID", Set_SSID_Proc},
153
{"WirelessMode", Set_WirelessMode_Proc},
154
{"TxRate", Set_TxRate_Proc},
155
{"Channel", Set_Channel_Proc},
156
{"BGProtection", Set_BGProtection_Proc},
157
{"TxPreamble", Set_TxPreamble_Proc},
158
{"RTSThreshold", Set_RTSThreshold_Proc},
159
{"FragThreshold", Set_FragThreshold_Proc},
160
{"TxBurst", Set_TxBurst_Proc},
161
{"TurboRate", Set_TurboRate_Proc},
162
{"AuthMode", Set_AuthMode_Proc},
163
{"EncrypType", Set_EncrypType_Proc},
164
{"DefaultKeyID", Set_DefaultKeyID_Proc},
165
{"Key1", Set_Key1_Proc},
166
{"Key2", Set_Key2_Proc},
167
{"Key3", Set_Key3_Proc},
168
{"Key4", Set_Key4_Proc},
169
{"WPAPSK", Set_WPAPSK_Proc},
170
{"bb", Set_R17_Proc},
171
{"rr", Read_R17_Proc},
178
rtusb_ioctl_giwname(struct net_device *dev,
179
struct iw_request_info *info,
180
char *name, char *extra)
182
strncpy(name, "RT2500USB WLAN", IFNAMSIZ);
186
int rtusb_ioctl_siwfreq(struct net_device *dev,
187
struct iw_request_info *info,
188
struct iw_freq *freq, char *extra)
190
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
196
if((freq->e == 0) && (freq->m <= 1000))
197
chan = freq->m; // Setting by channel number
199
MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
200
pAdapter->PortCfg.IbssConfig.Channel = chan;
201
DBGPRINT(RT_DEBUG_ERROR, "<==SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->PortCfg.IbssConfig.Channel);
203
// CD: setting the channel in Monitor mode is unrelated to RFMONTx
205
if (pAdapter->PortCfg.BssType == BSS_MONITOR)
207
pAdapter->PortCfg.Channel = pAdapter->PortCfg.IbssConfig.Channel;
208
AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
209
AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
214
int rtusb_ioctl_giwfreq(struct net_device *dev,
215
struct iw_request_info *info,
216
struct iw_freq *freq, char *extra)
218
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
219
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::rtusb_ioctl_giwfreq %d\n",pAdapter->PortCfg.Channel);
221
if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
223
MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, freq->m);
227
MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.IbssConfig.Channel, freq->m );
235
int rtusb_ioctl_siwmode(struct net_device *dev,
236
struct iw_request_info *info,
237
__u32 *mode, char *extra)
239
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
244
if (pAdapter->PortCfg.BssType != BSS_INDEP)
246
// Config has changed
247
if INFRA_ON(pAdapter)
249
RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
250
// First cancel linkdown timer
251
DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n");
253
pAdapter->bConfigChanged = TRUE;
255
pAdapter->net->type = 1;
256
pAdapter->PortCfg.BssType = BSS_INDEP;
257
DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (AD-HOC)\n");
260
if (pAdapter->PortCfg.BssType != BSS_INFRA)
262
// Config has changed
263
if (pAdapter->PortCfg.BssType != BSS_INFRA)
265
// Config has changed
266
// pAdapter->bConfigChanged = TRUE;
267
if ADHOC_ON(pAdapter)
268
RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
270
pAdapter->bConfigChanged = TRUE;
272
pAdapter->net->type = 1;
273
pAdapter->PortCfg.BssType = BSS_INFRA;
274
DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (INFRA)\n");
276
case IW_MODE_MONITOR:
277
pAdapter->PortCfg.BssType=BSS_MONITOR;
278
RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
279
pAdapter->bConfigChanged = TRUE;
280
if (pAdapter->PortCfg.MallowRFMONTx == TRUE) {
281
if (pAdapter->PortCfg.ForcePrismHeader == 1)
282
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
284
pAdapter->net->type = 801; // ARPHRD_IEEE80211
286
if (pAdapter->PortCfg.ForcePrismHeader == 2)
287
pAdapter->net->type = 801; // ARPHRD_IEEE80211
289
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
291
RTUSBWriteMACRegister(pAdapter, TXRX_CSR2, 0x4e);
294
DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (unknown)\n");
298
// Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
299
pAdapter->PortCfg.WpaState = SS_NOTUSE;
304
int rtusb_ioctl_giwmode(struct net_device *dev,
305
struct iw_request_info *info,
306
__u32 *mode, char *extra)
308
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
309
if (pAdapter->PortCfg.BssType == BSS_MONITOR)
310
*mode = IW_MODE_MONITOR;
313
if (ADHOC_ON(pAdapter))
314
*mode = IW_MODE_ADHOC;
316
*mode = IW_MODE_INFRA;
318
DBGPRINT(RT_DEBUG_TEMP,"--->rtusb_ioctl_giwmode\n");
322
int rtusb_ioctl_siwsens(struct net_device *dev,
323
struct iw_request_info *info,
324
char *name, char *extra)
329
int rtusb_ioctl_giwsens(struct net_device *dev,
330
struct iw_request_info *info,
331
char *name, char *extra)
336
This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
338
int rtusb_ioctl_giwrange(struct net_device *dev,
339
struct iw_request_info *info,
340
struct iw_point *data, char *extra)
342
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
343
struct iw_range *range = (struct iw_range *) extra;
348
data->length = sizeof(struct iw_range);
349
memset(range, 0, sizeof(struct iw_range));
351
range->txpower_capa = IW_TXPOW_DBM;
353
if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
355
range->min_pmp = 1 * 1024;
356
range->max_pmp = 65535 * 1024;
357
range->min_pmt = 1 * 1024;
358
range->max_pmt = 1000 * 1024;
359
range->pmp_flags = IW_POWER_PERIOD;
360
range->pmt_flags = IW_POWER_TIMEOUT;
361
range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
362
IW_POWER_UNICAST_R | IW_POWER_ALL_R;
366
range->we_version_compiled = WIRELESS_EXT;
367
range->we_version_source = 16;
369
range->retry_capa = IW_RETRY_LIMIT;
370
range->retry_flags = IW_RETRY_LIMIT;
371
range->min_retry = 0;
372
range->max_retry = 255;
374
range->num_channels = pAdapter->PortCfg.ChannelListNum;
377
for (i = 0; i < pAdapter->PortCfg.SupportedRatesLen; i++) {
378
range->freq[val].i =(pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2;
379
range->freq[val].m = (pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2 * 100000;
380
range->freq[val].e = 1;
382
if (val == IW_MAX_FREQUENCIES)
386
range->num_frequency = 0;
387
for (i = 1; i <= range->num_channels; i++)
389
range->freq[range->num_frequency].i = i;
390
MAP_CHANNEL_ID_TO_KHZ(i, m);
392
range->freq[range->num_frequency].m = m;
393
range->freq[range->num_frequency].e = 3;
394
if (++range->num_frequency == IW_MAX_FREQUENCIES)
398
range->max_qual.qual = 100; /* percentage */
399
range->max_qual.level = 0; /* dB */
400
range->max_qual.noise = 0; /* dB */
402
/* What would be suitable values for "average/typical" qual? */
403
range->avg_qual.qual = 20;
404
range->avg_qual.level = -60;
405
range->avg_qual.noise = -95;
406
range->sensitivity = 3;
408
range->max_encoding_tokens = NR_WEP_KEYS;
409
range->num_encoding_sizes = 2;
410
range->encoding_size[0] = 5;
411
range->encoding_size[1] = 13;
415
len = prism2_get_datarates(dev, rates);
416
range->num_bitrates = 0;
417
for (i = 0; i < len; i++) {
418
if (range->num_bitrates < IW_MAX_BITRATES) {
419
range->bitrate[range->num_bitrates] =
421
range->num_bitrates++;
423
if (rates[i] == 0x0b || rates[i] == 0x16)
426
/* estimated maximum TCP throughput values (bps) */
427
range->throughput = over2 ? 5500000 : 1500000;
430
range->max_rts = 2347;
431
range->min_frag = 256;
432
range->max_frag = 2346;
437
int rtusb_ioctl_giwap(struct net_device *dev,
438
struct iw_request_info *info,
439
struct sockaddr *ap_addr, char *extra)
442
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
444
if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
446
ap_addr->sa_family = ARPHRD_ETHER;
447
memcpy(ap_addr->sa_data, &pAdapter->PortCfg.Bssid, ETH_ALEN);
451
DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=EMPTY)\n");
459
* Units are in db above the noise floor. That means the
460
* rssi values reported in the tx/rx descriptors in the
461
* driver are the SNR expressed in db.
463
* If you assume that the noise floor is -95, which is an
464
* excellent assumption 99.5 % of the time, then you can
465
* derive the absolute signal level (i.e. -95 + rssi).
466
* There are some other slight factors to take into account
467
* depending on whether the rssi measurement is from 11b,
468
* 11g, or 11a. These differences are at most 2db and
471
* NB: various calculations are based on the orinoco/wavelan
472
* drivers for compatibility
475
set_quality(struct iw_quality *iq, u_int rssi)
478
/* NB: max is 94 because noise is hardcoded to 161 */
482
iq->noise = RSSI_TO_DBM_OFFSET; /* -95dBm */
483
iq->level = iq->noise + iq->qual;
486
int rtusb_ioctl_iwaplist(struct net_device *dev,
487
struct iw_request_info *info,
488
struct iw_point *data, char *extra)
491
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
492
struct sockaddr addr[IW_MAX_AP];
493
struct iw_quality qual[IW_MAX_AP];
496
for (i = 0; i <IW_MAX_AP ; i++)
498
if (i >= pAdapter->PortCfg.BssTab.BssNr)
500
addr[i].sa_family = ARPHRD_ETHER;
501
memcpy(addr[i].sa_data, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
502
set_quality(&qual[i], pAdapter->PortCfg.BssTab.BssEntry[i].Rssi);
505
memcpy(extra, &addr, i*sizeof(addr[0]));
506
data->flags = 1; /* signal quality present (sort of) */
507
memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
513
int rtusb_ioctl_siwscan(struct net_device *dev,
514
struct iw_request_info *info,
515
struct iw_point *data, char *extra)
517
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
518
int Status = STATUS_SUCCESS;
521
if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
523
if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
526
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
527
if ((pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (pAdapter->MLMEThr_pid > 0))
529
if ((pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (pAdapter->MLMEThr_active))
532
DBGPRINT(RT_DEBUG_ERROR, "!!! MLME busy, reset MLME state machine !!!\n");
533
MlmeRestartStateMachine(pAdapter);
534
MlmePostRestartStateMachine(pAdapter);
535
return (RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_BSSID_LIST_SCAN, TRUE, NULL, 0));
539
pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
540
// Reset Missed scan number
541
pAdapter->PortCfg.IgnoredScanNumber = 0;
543
MlmeEnqueue(pAdapter,
544
MLME_CNTL_STATE_MACHINE,
545
OID_802_11_BSSID_LIST_SCAN,
548
RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
550
Status = NDIS_STATUS_SUCCESS;
555
rtusb_ioctl_giwscan(struct net_device *dev,
556
struct iw_request_info *info,
557
struct iw_point *data, char *extra)
560
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
562
char *current_ev = extra;
563
char *end_buf = extra + IW_SCAN_MAX_DATA;
567
if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)){
569
* Still scanning, indicate the caller should try again.
574
for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
576
if (current_ev >= end_buf)
579
//================================
580
memset(&iwe, 0, sizeof(iwe));
582
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
583
memcpy(iwe.u.ap_addr.sa_data, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, ETH_ALEN);
584
current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
585
//================================
586
memset(&iwe, 0, sizeof(iwe));
587
iwe.cmd = SIOCGIWMODE;
588
if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11IBSS)
590
iwe.u.mode = IW_MODE_ADHOC;
592
else if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
594
iwe.u.mode = IW_MODE_INFRA;
598
iwe.u.mode = IW_MODE_AUTO;
601
iwe.len = IW_EV_UINT_LEN;
602
current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
603
//================================
604
memset(&iwe, 0, sizeof(iwe));
605
iwe.cmd = SIOCGIWESSID;
606
iwe.u.data.length = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
607
iwe.u.data.flags = 1;
608
current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
609
//================================
610
memset(&iwe, 0, sizeof(iwe));
611
iwe.cmd = SIOCGIWENCODE;
612
if (CAP_IS_PRIVACY_ON (pAdapter->PortCfg.BssTab.BssEntry[i].CapabilityInfo ))
613
iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
615
iwe.u.data.flags = IW_ENCODE_DISABLED;
616
current_ev = iwe_stream_add_point(current_ev, end_buf,&iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
618
//================================
619
memset(&iwe, 0, sizeof(iwe));
620
iwe.cmd = SIOCGIWRATE;
621
current_val = current_ev + IW_EV_LCP_LEN;
622
//for (j = 0; j < pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen;j++)
623
for (j = 0; j < 1;j++)
625
iwe.u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.BssTab.BssEntry[i].Rates[i]/2] * 1000000;
626
iwe.u.bitrate.disabled = 0;
627
current_val = iwe_stream_add_value(current_ev,
628
current_val, end_buf, &iwe,
631
//================================
632
memset(&iwe, 0, sizeof(iwe));
633
iwe.cmd = SIOCGIWFREQ;
634
if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
635
iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
637
iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
640
current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
641
//================================
642
memset(&iwe, 0, sizeof(iwe));
645
data->length = current_ev - extra;
646
DBGPRINT(RT_DEBUG_TRACE,"rtusb_ioctl_giwscan. %d BSS returned\n",pAdapter->PortCfg.BssTab.BssNr);
650
int rtusb_ioctl_siwessid(struct net_device *dev,
651
struct iw_request_info *info,
652
struct iw_point *data, char *essid)
654
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
655
NDIS_802_11_SSID Ssid, *pSsid=NULL;
657
memset(&Ssid, 0x00, sizeof(NDIS_802_11_SSID));
660
if (data->length > IW_ESSID_MAX_SIZE)
665
memcpy(Ssid.Ssid, essid, (data->length - 1));
666
Ssid.SsidLength = data->length - 1; //minus null character.
667
memcpy(pAdapter->PortCfg.Ssid, essid, (data->length - 1));
668
pAdapter->PortCfg.SsidLen = data->length - 1;
671
Ssid.SsidLength = 0; // ANY ssid
675
// tell CNTL state machine to call NdisMSetInformationComplete() after completing
676
// this request, because this request is initiated by NDIS.
677
pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
678
DBGPRINT(RT_DEBUG_TRACE,"--->Ssid.SsidLength = %d, %s\n",Ssid.SsidLength, Ssid.Ssid);
679
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
680
if (pAdapter->MLMEThr_pid > 0)
682
if (!IS_ERR(pAdapter->MLMEThr))
684
MlmeEnqueue(pAdapter,
685
MLME_CNTL_STATE_MACHINE,
687
sizeof(NDIS_802_11_SSID),
691
RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
695
int rtusb_ioctl_giwessid(struct net_device *dev,
696
struct iw_request_info *info,
697
struct iw_point *data, char *essid)
699
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
701
data->flags = 1; /* active */
702
DBGPRINT(RT_DEBUG_TRACE,"MediaState is connected\n");
703
data->length = pAdapter->PortCfg.SsidLen;
704
memcpy(essid, pAdapter->PortCfg.Ssid, pAdapter->PortCfg.SsidLen);
705
pAdapter->PortCfg.Ssid[pAdapter->PortCfg.SsidLen] = '\0';
706
DBGPRINT(RT_DEBUG_TRACE,"pAdapter->PortCfg.Ssid=%s , Ssidlen = %d\n",pAdapter->PortCfg.Ssid, pAdapter->PortCfg.SsidLen);
708
DBGPRINT(RT_DEBUG_TRACE, "<==rtusb_ioctl_giwessid:: (Len=%d, ssid=%s...)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
714
int rtusb_ioctl_siwnickn(struct net_device *dev,
715
struct iw_request_info *info,
716
struct iw_point *data, char *nickname)
718
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
720
if (data->length > IEEE80211_NWID_LEN)
723
memset(pAdapter->nickn, 0, IEEE80211_NWID_LEN);
724
memcpy(pAdapter->nickn, nickname, data->length);
725
pAdapter->nicknamelen = data->length;
731
int rtusb_ioctl_giwnickn(struct net_device *dev,
732
struct iw_request_info *info,
733
struct iw_point *data, char *nickname)
735
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
737
if (data->length > pAdapter->nicknamelen + 1)
738
data->length = pAdapter->nicknamelen + 1;
739
if (data->length > 0) {
740
memcpy(nickname, pAdapter->nickn, data->length-1);
741
nickname[data->length-1] = '\0';
747
int rtusb_ioctl_siwrts(struct net_device *dev,
748
struct iw_request_info *info,
749
struct iw_param *rts, char *extra)
751
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
755
val = MAX_RTS_THRESHOLD;
756
else if (1 > rts->value || rts->value > MAX_RTS_THRESHOLD)
761
if (val != pAdapter->PortCfg.RtsThreshold)
762
pAdapter->PortCfg.RtsThreshold = val;
767
int rtusb_ioctl_giwrts(struct net_device *dev,
768
struct iw_request_info *info,
769
struct iw_param *rts, char *extra)
771
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
773
rts->value = pAdapter->PortCfg.RtsThreshold;
774
rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
781
int rtusb_ioctl_siwfrag(struct net_device *dev,
782
struct iw_request_info *info,
783
struct iw_param *rts, char *extra)
785
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
789
val = MAX_FRAG_THRESHOLD;
790
else if (rts->value < 256 || rts->value > MAX_FRAG_THRESHOLD)
793
val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
795
pAdapter->PortCfg.FragmentThreshold = val;
799
int rtusb_ioctl_giwfrag(struct net_device *dev,
800
struct iw_request_info *info,
801
struct iw_param *rts, char *extra)
803
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
805
rts->value = pAdapter->PortCfg.FragmentThreshold;
806
rts->disabled = (rts->value == 2346);
812
int rtusb_ioctl_siwencode(struct net_device *dev,
813
struct iw_request_info *info,
814
struct iw_point *erq, char *extra)
816
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
817
NDIS_802_11_WEP WepKey;
820
memset(&WepKey, 0, sizeof(NDIS_802_11_WEP));
822
if (erq->flags & IW_ENCODE_DISABLED)
824
pAdapter->PortCfg.PairCipher = Ndis802_11WEPDisabled;
825
pAdapter->PortCfg.GroupCipher = Ndis802_11WEPDisabled;
826
pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
830
pAdapter->PortCfg.PairCipher = Ndis802_11WEPEnabled;
831
pAdapter->PortCfg.GroupCipher = Ndis802_11WEPEnabled;
832
pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
835
if (erq->flags & IW_ENCODE_RESTRICTED)
836
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
837
else if(erq->flags & IW_ENCODE_OPEN)
838
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
840
if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
841
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
843
if ((erq->flags & IW_ENCODE_DISABLED) == 0 && erq->pointer)
846
if (erq->length > IFNAMSIZ)
849
/* Old solution to take default key */
850
index = (erq->flags & IW_ENCODE_INDEX) ;
851
if((index < 0) || (index > NR_WEP_KEYS))
853
DBGPRINT(RT_DEBUG_TRACE," erq->flags = %x\n",erq->flags);
857
pAdapter->PortCfg.DefaultKeyId = index -1;
860
if ((erq->length == 1) && (index == 0))
862
/* New solution to take default key when old way not work, not change KeyMaterial*/
863
memcpy(&kid, erq->pointer, 1 );
864
if((index < 0) || (index >= NR_WEP_KEYS))
866
//WepKey.KeyIndex = 0x80000000 + index;
867
DBGPRINT(RT_DEBUG_TRACE,"kid = %d , erq->length = %d\n",kid, erq->length);
869
pAdapter->PortCfg.DefaultKeyId = kid-1;
871
pAdapter->PortCfg.DefaultKeyId = 0;
875
DBGPRINT(RT_DEBUG_TRACE,"DefaultKeyId = %d , erq->length = %d, flags 0x%x\n",pAdapter->PortCfg.DefaultKeyId, erq->length,erq->flags);
877
if(len > WEP_LARGE_KEY_LEN)
878
len = WEP_LARGE_KEY_LEN;
879
// If this instruction default key
880
memset(pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].Key, 0, MAX_LEN_OF_KEY);
881
memcpy(pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].Key, erq->pointer, len);
882
memcpy(WepKey.KeyMaterial, erq->pointer, len);
883
WepKey.KeyIndex = 0x80000000 + pAdapter->PortCfg.DefaultKeyId;
884
WepKey.KeyLength = len;
885
pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen =(UCHAR) (len <= WEP_SMALL_KEY_LEN ? WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN);
886
// need to enqueue cmd to thread
887
RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_WEP, TRUE, &WepKey, sizeof(WepKey));
891
DBGPRINT(RT_DEBUG_TRACE, "==>AuthMode=%x\n",pAdapter->PortCfg.AuthMode);
892
DBGPRINT(RT_DEBUG_TRACE, "==>DefaultKeyId=%x, KeyLen = %d\n",pAdapter->PortCfg.DefaultKeyId , pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen);
893
DBGPRINT(RT_DEBUG_TRACE, "==>WepStatus=%x\n",pAdapter->PortCfg.WepStatus);
898
rtusb_ioctl_giwencode(struct net_device *dev,
899
struct iw_request_info *info,
900
struct iw_point *erq, char *key)
902
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
905
kid = erq->flags & IW_ENCODE_INDEX;
906
DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX);
908
if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
911
erq->flags = IW_ENCODE_DISABLED;
915
erq->flags = IW_ENCODE_ENABLED;
917
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeShared)
918
erq->flags |= IW_ENCODE_RESTRICTED;
920
erq->flags |= IW_ENCODE_OPEN;
922
if ((kid > 0) && (kid <=4))
925
erq->flags |= kid & IW_ENCODE_INDEX; /* NB: base 1 */
926
if (erq->length > pAdapter->PortCfg.SharedKey[kid-1].KeyLen)
927
erq->length = pAdapter->PortCfg.SharedKey[kid-1].KeyLen;
928
memcpy(key, pAdapter->PortCfg.SharedKey[kid-1].Key, erq->length);
932
// copy default key ID
933
erq->flags |= (pAdapter->PortCfg.DefaultKeyId + 1) & IW_ENCODE_INDEX; /* NB: base 1 */
934
erq->length = pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen;
935
memcpy(key, pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].Key, erq->length);
943
rtusb_ioctl_setauth(struct net_device *dev, struct iw_request_info *info,
944
void *w, char *extra)
946
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
947
int param = *(int *) extra;
952
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
953
DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeOpen\n");
956
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
957
DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeShared\n");
960
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
961
pAdapter->PortCfg.WpaState = SS_START;
962
DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeWPAPSK\n");
965
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
966
DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth Ndis802_11AuthModeWPANone\n");
974
pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
979
static int rtusb_ioctl_setkeyid(struct net_device *dev, struct iw_request_info *info,
980
void *w, char *extra)
983
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
984
int param = *(int *)extra;
990
pAdapter->PortCfg.DefaultKeyId = 0;
993
pAdapter->PortCfg.DefaultKeyId = 1;
996
pAdapter->PortCfg.DefaultKeyId = 2;
999
pAdapter->PortCfg.DefaultKeyId = 3;
1007
if (pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen == 5)
1008
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
1010
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
1012
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
1014
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
1015
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
1017
DBGPRINT(RT_DEBUG_TRACE, "===>DefaultKeyId = [%d]\n",pAdapter->PortCfg.DefaultKeyId);
1023
rtusb_ioctl_setencryp(struct net_device *dev, struct iw_request_info *info,
1024
void *w, char *extra)
1027
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1028
int param = *(int *)extra;
1029
NDIS_802_11_WEP_STATUS WepStatus;//set by OID_802_11_WEP_STATUS
1030
DBGPRINT(RT_DEBUG_TRACE, "===>setencryp\n");
1031
DBGPRINT(RT_DEBUG_TRACE, "===>info->cmd 0x%x \n",(info->cmd));
1032
DBGPRINT(RT_DEBUG_TRACE, "===>info->flags 0x%x , param %x , extra %x\n",(info->flags), param,*extra);
1036
pAdapter->PortCfg.WepStatus= Ndis802_11WEPDisabled;
1037
pAdapter->PortCfg.PairCipher= Ndis802_11WEPDisabled;
1038
pAdapter->PortCfg.GroupCipher= Ndis802_11WEPDisabled;
1039
pAdapter->PortCfg.CipherAlg = CIPHER_NONE;
1040
WepStatus = Ndis802_11WEPDisabled;
1043
pAdapter->PortCfg.WepStatus= Ndis802_11Encryption1Enabled;
1044
pAdapter->PortCfg.PairCipher= Ndis802_11Encryption1Enabled;
1045
pAdapter->PortCfg.GroupCipher= Ndis802_11Encryption1Enabled;
1046
WepStatus = Ndis802_11Encryption1Enabled;
1049
pAdapter->PortCfg.WepStatus= Ndis802_11Encryption2Enabled;
1050
pAdapter->PortCfg.PairCipher= Ndis802_11Encryption2Enabled;
1051
pAdapter->PortCfg.GroupCipher= Ndis802_11Encryption2Enabled;
1052
pAdapter->PortCfg.CipherAlg = CIPHER_TKIP;
1053
WepStatus = Ndis802_11Encryption2Enabled;
1059
RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_WEP_STATUS, TRUE, &WepStatus, sizeof(WepStatus));
1064
rtusb_ioctl_setwpapsk(struct net_device *dev, struct iw_request_info *info,
1065
void *w, char *extra)
1067
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1068
NDIS_802_11_KEY Key;
1069
// rtusb_ioctl_setwpapsk accept > 16 chars, so data is passed through w instead of extra.
1070
struct iw_point *iwp = (struct iw_point *)w;
1071
UCHAR keyMaterial[80];
1072
UCHAR keyMaterial2[80];
1073
INT Status = NDIS_STATUS_SUCCESS;
1076
DBGPRINT(RT_DEBUG_TRACE, "===>\n");
1077
DBGPRINT(RT_DEBUG_TRACE, "===>info->cmd 0x%x \n",(info->cmd));
1078
DBGPRINT(RT_DEBUG_TRACE, "===>info->flags 0x%x \n",(info->flags));
1079
memset(Key.KeyMaterial, 0, 64);
1080
memset(keyMaterial2, 0, 80);
1081
memcpy(Key.BSSID, pAdapter->PortCfg.Bssid.Octet, 6);
1082
//memcpy(&Key.KeyRSC, pMsg3->KeyDesc.KeyRsc, LEN_KEY_DESC_RSC);
1083
if (iwp->length < 64)
1085
if(copy_from_user(&keyMaterial2, iwp->pointer, iwp->length))
1088
PasswordHash(keyMaterial2, pAdapter->Mlme.CntlAux.Ssid, pAdapter->Mlme.CntlAux.SsidLen, keyMaterial);
1090
Key.Length = sizeof(Key);
1091
Key.KeyIndex = 0x80000000;
1093
DBGPRINT_RAW(RT_DEBUG_TEMP,"pAdapter->Mlme.CntlAux.Ssid: ");
1094
for(i = 0; i < pAdapter->Mlme.CntlAux.SsidLen; i++)
1095
DBGPRINT_RAW(RT_DEBUG_TEMP,"%c ", pAdapter->Mlme.CntlAux.Ssid[i]);
1096
DBGPRINT_RAW(RT_DEBUG_TEMP,"\n");
1098
memcpy(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
1099
memcpy(Key.KeyMaterial, keyMaterial, 32);
1100
DBGPRINT_RAW(RT_DEBUG_TEMP,"WPAPSK Key : ");
1101
for(i = 0; i < 32; i++)
1102
DBGPRINT_RAW(RT_DEBUG_TEMP,"%x ", Key.KeyMaterial[i]);
1103
DBGPRINT_RAW(RT_DEBUG_TEMP,"\n");
1106
else if (iwp->length == 64)
1108
if(copy_from_user(&keyMaterial2, iwp->pointer, iwp->length))
1111
AtoH(Key.KeyMaterial, keyMaterial, 32);
1113
DBGPRINT_RAW(RT_DEBUG_TEMP,"WPAPSK Key : ");
1114
for(i = 0; i < 32; i++)
1115
DBGPRINT_RAW(RT_DEBUG_TEMP,"%x ", keyMaterial[i]);
1116
DBGPRINT_RAW(RT_DEBUG_TEMP,"\n");
1118
memcpy(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
1119
memcpy(Key.KeyMaterial, keyMaterial, 32);
1127
RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_KEY, TRUE, &Key, sizeof(Key));
1129
pAdapter->PortCfg.WepStatus= Ndis802_11Encryption2Enabled;
1130
pAdapter->PortCfg.PairCipher= Ndis802_11Encryption2Enabled;
1131
pAdapter->PortCfg.GroupCipher= Ndis802_11Encryption2Enabled;
1132
pAdapter->PortCfg.CipherAlg= CIPHER_TKIP;
1133
// Start STA supplicant state machine
1139
static int rtusb_ioctl_setrfmontx(struct net_device *dev,
1140
struct iw_request_info *info,
1141
struct iw_point *data, char *extra)
1143
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1147
if (extra) { /* Change the state if there's param. */
1148
param = *(int *)extra;
1152
pAdapter->PortCfg.MallowRFMONTx = TRUE;
1153
if (pAdapter->PortCfg.ForcePrismHeader == 1)
1154
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
1156
pAdapter->net->type = 801; // ARPHRD_IEEE80211
1159
pAdapter->PortCfg.MallowRFMONTx = FALSE;
1160
if (pAdapter->PortCfg.ForcePrismHeader == 2)
1161
pAdapter->net->type = 801; // ARPHRD_IEEE80211
1163
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
1170
value = pAdapter->PortCfg.MallowRFMONTx == TRUE ? '1' : '0';
1172
data->length = sizeof (char);
1173
if (data->pointer != NULL && copy_to_user (data->pointer, &value, data->length))
1174
DBGPRINT (RT_DEBUG_ERROR, "rtusb_ioctl_setrfmontx - copy to user failure.\n");
1179
static int rtusb_ioctl_setforceprismheader(struct net_device *dev,
1180
struct iw_request_info *info,
1181
struct iw_point *data, char *extra)
1183
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1184
int param = *(int *)extra;
1189
pAdapter->PortCfg.ForcePrismHeader = 0;
1190
if (pAdapter->PortCfg.MallowRFMONTx == TRUE)
1191
pAdapter->net->type = 801; // ARPHRD_IEEE80211
1193
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
1196
pAdapter->PortCfg.ForcePrismHeader = 1;
1197
pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
1200
pAdapter->PortCfg.ForcePrismHeader = 2;
1201
pAdapter->net->type = 801; // ARPHRD_IEEE80211
1210
static int rtusb_ioctl_setadhocmode(struct net_device *dev,
1211
struct iw_request_info *info,
1212
struct iw_point *data, char *extra)
1214
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1215
int param = *(int *)extra;
1220
pAdapter->PortCfg.AdhocMode = 0;
1223
pAdapter->PortCfg.AdhocMode = 1;
1226
pAdapter->PortCfg.AdhocMode = 2;
1235
static int rtusb_ioctl_setpsm(struct net_device *dev, struct iw_request_info *info,
1236
void *w, char *extra)
1239
PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
1240
int param = *(int *)extra;
1245
// clear PSM bit immediately
1246
MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
1247
pAdapter->PortCfg.RecvDtim = TRUE;
1248
pAdapter->PortCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
1252
// do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1253
// to exclude certain situations.
1254
pAdapter->PortCfg.RecvDtim = TRUE;
1255
pAdapter->PortCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
1256
pAdapter->PortCfg.DefaultListenCount = 3;
1267
static const iw_handler rtusb_handler[] =
1269
(iw_handler) NULL, /* SIOCSIWCOMMIT */
1270
(iw_handler) rtusb_ioctl_giwname, /* SIOCGIWNAME 1 */
1271
(iw_handler) NULL, /* SIOCSIWNWID */
1272
(iw_handler) NULL, /* SIOCGIWNWID */
1273
(iw_handler) rtusb_ioctl_siwfreq, /* SIOCSIWFREQ */
1274
(iw_handler) rtusb_ioctl_giwfreq, /* SIOCGIWFREQ 5*/
1275
(iw_handler) rtusb_ioctl_siwmode, /* SIOCSIWMODE */
1276
(iw_handler) rtusb_ioctl_giwmode, /* SIOCGIWMODE */
1277
(iw_handler) NULL, /* SIOCSIWSENS */
1278
(iw_handler) NULL, /* SIOCGIWSENS */
1279
(iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1280
(iw_handler) rtusb_ioctl_giwrange, /* SIOCGIWRANGE 11 */
1281
(iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1282
(iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1283
(iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1284
(iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS f*/
1285
(iw_handler) NULL, /* SIOCSIWSPY */
1286
(iw_handler) NULL, /* SIOCGIWSPY */
1287
(iw_handler) NULL, /* -- hole -- */
1288
(iw_handler) NULL, /* -- hole -- */
1289
(iw_handler) NULL, /* SIOCSIWAP */
1290
(iw_handler) rtusb_ioctl_giwap, /* SIOCGIWAP 0x15*/
1291
(iw_handler) NULL, /* -- hole -- 0x16 */
1292
(iw_handler) rtusb_ioctl_iwaplist, /* SIOCGIWAPLIST */
1294
(iw_handler) rtusb_ioctl_siwscan, /* SIOCSIWSCAN 0x18*/
1295
(iw_handler) rtusb_ioctl_giwscan, /* SIOCGIWSCAN */
1297
(iw_handler) NULL, /* SIOCSIWSCAN */
1298
(iw_handler) NULL, /* SIOCGIWSCAN */
1299
#endif /* SIOCGIWSCAN */
1300
(iw_handler) rtusb_ioctl_siwessid, /* SIOCSIWESSID */
1301
(iw_handler) rtusb_ioctl_giwessid, /* SIOCGIWESSID */
1302
(iw_handler) rtusb_ioctl_siwnickn, /* SIOCSIWNICKN */
1303
(iw_handler) rtusb_ioctl_giwnickn, /* SIOCGIWNICKN 1d*/
1304
(iw_handler) NULL, /* -- hole -- */
1305
(iw_handler) NULL, /* -- hole -- */
1306
(iw_handler) NULL, /* SIOCSIWRATE 20*/
1307
(iw_handler) NULL, /* SIOCGIWRATE */
1308
(iw_handler) rtusb_ioctl_siwrts, /* SIOCSIWRTS */
1309
(iw_handler) rtusb_ioctl_giwrts, /* SIOCGIWRTS */
1310
(iw_handler) rtusb_ioctl_siwfrag, /* SIOCSIWFRAG */
1311
(iw_handler) rtusb_ioctl_giwfrag, /* SIOCGIWFRAG 25*/
1312
(iw_handler) NULL, /* SIOCSIWTXPOW */
1313
(iw_handler) NULL, /* SIOCGIWTXPOW */
1314
(iw_handler) NULL, /* SIOCSIWRETRY */
1315
(iw_handler) NULL, /* SIOCGIWRETRY 29*/
1316
(iw_handler) rtusb_ioctl_siwencode, /* SIOCSIWENCODE 2a*/
1317
(iw_handler) rtusb_ioctl_giwencode, /* SIOCGIWENCODE 2b*/
1318
(iw_handler) NULL, /* SIOCSIWPOWER 2c*/
1319
(iw_handler) NULL, /* SIOCGIWPOWER 2d*/
1321
static const iw_handler rtusb_priv_handlers[] = {
1322
(iw_handler) rtusb_ioctl_setauth, /* SIOCWFIRSTPRIV+0 */
1323
(iw_handler) rtusb_ioctl_setencryp, /* SIOCWFIRSTPRIV+1 */
1324
(iw_handler) rtusb_ioctl_setwpapsk, /* SIOCWFIRSTPRIV+2 */
1325
(iw_handler) rtusb_ioctl_setpsm, /* SIOCWFIRSTPRIV+3 */
1326
(iw_handler) rtusb_ioctl_setadhocmode, /* SIOCWFIRSTPRIV+4 */
1327
(iw_handler) rtusb_ioctl_setrfmontx, /* SIOCWFIRSTPRIV+5 */
1328
(iw_handler) rtusb_ioctl_setforceprismheader, /* SIOCWFIRSTPRIV+6 */
1331
#define MAX_WPAPSK_STRING 64
1332
static const struct iw_priv_args privtab[] = {
1333
{ RTPRIV_IOCTL_AUTH,
1334
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "auth"},
1335
{ RTPRIV_IOCTL_WEPSTATUS,
1336
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enc"},
1337
{ RTPRIV_IOCTL_WPAPSK,
1338
IW_PRIV_TYPE_CHAR | MAX_WPAPSK_STRING,
1339
0, "wpapsk"}, // Variable arg count
1341
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "psm"}, // Variable arg count
1342
{ RTPRIV_IOCTL_ADHOCMODE,
1343
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "adhocmode"},
1344
{ RTPRIV_IOCTL_RFMONTX,
1345
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1346
IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | sizeof(char), "rfmontx"},
1347
{ RTPRIV_IOCTL_FORCEPRISMHEADER,
1348
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "forceprismheader"},
1351
IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
1354
IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
1359
const struct iw_handler_def rt2500usb_iw_handler_def =
1361
.standard = (iw_handler *) rtusb_handler,
1362
.num_standard = sizeof(rtusb_handler) / sizeof(iw_handler),
1363
.private = (iw_handler *) rtusb_priv_handlers,
1364
.num_private = ARRAY_SIZE(rtusb_handler),
1365
.private_args = (struct iw_priv_args *) privtab,
1366
.num_private_args = ARRAY_SIZE(privtab),
1367
.get_wireless_stats = RTUSB_get_wireless_stats,
1370
INT RTMPQueryInformation(
1371
IN PRT2570ADAPTER pAdapter,
1372
IN OUT struct ifreq *rq,
1375
struct iwreq *wrq = (struct iwreq *) rq;
1376
NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
1377
PNDIS_WLAN_BSSID_EX pBss;
1378
NDIS_802_11_SSID Ssid;
1379
NDIS_802_11_CONFIGURATION Configuration;
1380
RT_802_11_LINK_STATUS LinkStatus;
1381
NDIS_802_11_STATISTICS Statistics;
1382
NDIS_802_11_RTS_THRESHOLD RtsThresh;
1383
NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1384
NDIS_802_11_POWER_MODE PowerMode;
1385
NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
1386
RT_802_11_PREAMBLE PreamType;
1387
NDIS_802_11_AUTHENTICATION_MODE AuthMode;
1388
NDIS_802_11_WEP_STATUS WepStatus;
1389
RT_VERSION_INFO DriverVersionInfo;
1395
INT Status = NDIS_STATUS_SUCCESS;
1403
case RT_OID_DEVICE_NAME:
1404
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_DEVICE_NAME\n");
1405
wrq->u.data.length = sizeof(NIC_DEVICE_NAME);
1406
if(copy_to_user(wrq->u.data.pointer, NIC_DEVICE_NAME, wrq->u.data.length))
1410
case RT_OID_VERSION_INFO:
1411
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_VERSION_INFO \n");
1412
DriverVersionInfo.DriverMajorVersion = DRV_MAJORVERSION;
1413
DriverVersionInfo.DriverMinorVersion = DRV_MINORVERSION;
1414
DriverVersionInfo.DriverSubVersion = DRV_SUBVERSION;
1415
DriverVersionInfo.DriverTestVersion = DRV_TESTVERSION;
1416
DriverVersionInfo.DriverBuildYear = DRV_YEAR;
1417
DriverVersionInfo.DriverBuildMonth = DRV_MONTH;
1418
DriverVersionInfo.DriverBuildDay = DRV_DAY;
1419
wrq->u.data.length = sizeof(RT_VERSION_INFO);
1420
if(copy_to_user(wrq->u.data.pointer, &DriverVersionInfo, wrq->u.data.length))
1424
case OID_802_11_BSSID_LIST:
1426
DBGPRINT(RT_DEBUG_ERROR, "Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->PortCfg.BssTab.BssNr);
1427
// Claculate total buffer size required
1428
BssBufSize = sizeof(ULONG);
1430
for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1432
// Align pointer to 4 bytes boundary.
1433
Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1436
BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding);
1439
// For safety issue, we add 256 bytes just in case
1441
// Allocate the same size as passed from higher layer
1442
pBuf = kmalloc(BssBufSize, GFP_KERNEL);
1448
// Init 802_11_BSSID_LIST_EX structure
1449
memset(pBuf, 0, BssBufSize);
1452
pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
1453
pBssidList->NumberOfItems = pAdapter->PortCfg.BssTab.BssNr;
1455
// Calculate total buffer length
1456
BssLen = 4; // Consist of NumberOfItems
1457
// Point to start of NDIS_WLAN_BSSID_EX
1458
// pPtr = pBuf + sizeof(ULONG);
1459
pPtr = (PUCHAR) &pBssidList->Bssid[0];
1460
for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1462
pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
1463
memcpy(&pBss->MacAddress, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
1464
if (pAdapter->PortCfg.BssTab.BssEntry[i].Hidden == 1)
1466
pBss->Ssid.SsidLength = 0;
1470
pBss->Ssid.SsidLength = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
1471
memcpy(pBss->Ssid.Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen);
1473
pBss->Privacy = pAdapter->PortCfg.BssTab.BssEntry[i].Privacy;
1474
//DBGPRINT(RT_DEBUG_ERROR,"pBss->Privacy=%x\n",(pBss->Privacy));
1475
pBss->Rssi = pAdapter->PortCfg.BssTab.BssEntry[i].Rssi - RSSI_TO_DBM_OFFSET;
1476
//DBGPRINT(RT_DEBUG_ERROR,"pBss->Rssi=%x\n",pBss->Rssi);
1477
pBss->NetworkTypeInUse = Ndis802_11DS;
1478
//DBGPRINT(RT_DEBUG_ERROR,"pBss->NetworkTypeInUse=%x\n",(pBss->NetworkTypeInUse));
1479
pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1480
//DBGPRINT(RT_DEBUG_ERROR,"pBss->pBss->Configuration.Length=%d\n",pBss->Configuration.Length);
1481
pBss->Configuration.BeaconPeriod = pAdapter->PortCfg.BssTab.BssEntry[i].BeaconPeriod;
1482
//DBGPRINT(RT_DEBUG_ERROR,"pBss->pBss->Configuration.BeaconPeriod=%d\n",pBss->Configuration.BeaconPeriod);
1483
pBss->Configuration.ATIMWindow = pAdapter->PortCfg.BssTab.BssEntry[i].AtimWin;
1485
MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.BssTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
1487
if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == BSS_INFRA)
1488
pBss->InfrastructureMode = Ndis802_11Infrastructure;
1490
pBss->InfrastructureMode = Ndis802_11IBSS;
1492
memcpy(pBss->SupportedRates, pAdapter->PortCfg.BssTab.BssEntry[i].Rates, pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen);
1494
//DBGPRINT(RT_DEBUG_ERROR, "BSS#%d - %s, length of ssid=%d,Ch %d = %d Khz\n",
1495
// i,pBss->Ssid.Ssid,pBss->Ssid.SsidLength,pAdapter->PortCfg.BssTab.BssEntry[i].Channel,pBss->Configuration.DSConfig);
1497
if (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen == 0)
1499
pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
1500
memcpy(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1501
pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs);
1505
pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1506
pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs);
1507
memcpy(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1508
memcpy(pPtr, pAdapter->PortCfg.BssTab.BssEntry[i].VarIEs, pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen);
1509
pPtr += pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1511
// Align pointer to 4 bytes boundary.
1512
Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1516
pBss->Length = sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding;
1517
BssLen += pBss->Length;
1519
wrq->u.data.length = BssLen;
1520
DBGPRINT(RT_DEBUG_INFO,"copy to user in OID_802_11_BSSID_LIST = %d\n",wrq->u.data.length);
1522
if(copy_to_user(wrq->u.data.pointer, pBssidList, wrq->u.data.length))
1527
case OID_802_11_TX_POWER_LEVEL:
1528
wrq->u.data.length = sizeof(ULONG);
1529
if(copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.TxPower, wrq->u.data.length))
1532
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->PortCfg.TxPower);
1534
case OID_802_3_CURRENT_ADDRESS:
1535
wrq->u.data.length = ETH_LENGTH_OF_ADDRESS;
1536
if(copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length))
1539
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_3_CURRENT_ADDRESS \n");
1541
case OID_GEN_MEDIA_CONNECT_STATUS:
1542
DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_MEDIA_CONNECT_STATUS \n");
1543
wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
1544
if(copy_to_user(wrq->u.data.pointer, &pAdapter->MediaState, wrq->u.data.length))
1548
case OID_802_11_BSSID:
1549
if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1551
if(copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.Bssid, sizeof(MACADDR)))
1554
DBGPRINT(RT_DEBUG_INFO, "IOCTL::SIOCGIWAP(=%02x:%02x:%02x:%02x:%02x:%02x)\n",
1555
pAdapter->PortCfg.Bssid.Octet[0],pAdapter->PortCfg.Bssid.Octet[1],pAdapter->PortCfg.Bssid.Octet[2],
1556
pAdapter->PortCfg.Bssid.Octet[3],pAdapter->PortCfg.Bssid.Octet[4],pAdapter->PortCfg.Bssid.Octet[5]);
1561
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_BSSID(=EMPTY)\n");
1565
case OID_802_11_SSID:
1566
Ssid.SsidLength = pAdapter->PortCfg.SsidLen;
1567
memset(Ssid.Ssid, 0, MAX_LEN_OF_SSID);
1568
memcpy(Ssid.Ssid, pAdapter->PortCfg.Ssid, Ssid.SsidLength);
1569
wrq->u.data.length = sizeof(NDIS_802_11_SSID);
1570
if(copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length))
1573
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid);
1575
case RT_OID_802_11_QUERY_LINK_STATUS:
1576
LinkStatus.CurrTxRate = RateIdTo500Kbps[pAdapter->PortCfg.TxRate]; // unit : 500 kbps
1577
LinkStatus.ChannelQuality = pAdapter->Mlme.ChannelQuality;
1578
LinkStatus.RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
1579
LinkStatus.TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
1580
wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
1581
if(copy_to_user(wrq->u.data.pointer, &LinkStatus, wrq->u.data.length))
1584
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_LINK_STATUS\n");
1586
case OID_802_11_CONFIGURATION:
1587
Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1588
Configuration.BeaconPeriod = pAdapter->PortCfg.BeaconPeriod;
1589
Configuration.ATIMWindow = pAdapter->PortCfg.AtimWin;
1590
if (ADHOC_ON(pAdapter))
1591
{MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.IbssConfig.Channel, Configuration.DSConfig);}
1593
{MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, Configuration.DSConfig);}
1594
wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
1595
if(copy_to_user(wrq->u.data.pointer, &Configuration, wrq->u.data.length))
1598
DBGPRINT(RT_DEBUG_ERROR, "Query::OID_802_11_CONFIGURATION(BeaconPeriod=%d,AtimW=%d,bssidChannel=%d) \n",
1599
Configuration.BeaconPeriod, Configuration.ATIMWindow, pAdapter->PortCfg.IbssConfig.Channel);
1601
case OID_802_11_RSSI:
1602
ulInfo = pAdapter->PortCfg.LastRssi;
1603
wrq->u.data.length = sizeof(UCHAR);
1604
if(copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
1607
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RSSI(=%d)\n", ulInfo);
1609
case OID_802_11_RSSI_TRIGGER:
1610
ulInfo = pAdapter->PortCfg.LastRssi - RSSI_TO_DBM_OFFSET;
1611
wrq->u.data.length = sizeof(ulInfo);
1612
if(copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
1615
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RSSI_TRIGGER(=%d)\n", ulInfo);
1617
case OID_802_11_STATISTICS:
1618
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_STATISTICS \n");
1619
// Update FCS counters
1621
// Sanity check for calculation of sucessful count
1622
if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
1623
pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1625
Statistics.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
1626
Statistics.MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
1627
Statistics.FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
1628
Statistics.RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1629
Statistics.MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
1630
Statistics.RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
1631
Statistics.RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
1632
Statistics.ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
1633
Statistics.FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
1634
Statistics.ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
1635
Statistics.MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
1636
Statistics.FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
1637
wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
1638
if(copy_to_user(wrq->u.data.pointer, &Statistics, wrq->u.data.length))
1642
case OID_GEN_RCV_OK:
1643
DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_OK \n");
1644
ulInfo = pAdapter->Counters.GoodReceives;
1645
wrq->u.data.length = sizeof(ulInfo);
1646
if(copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
1650
case OID_GEN_RCV_NO_BUFFER:
1651
DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_NO_BUFFER \n");
1652
ulInfo = pAdapter->Counters.RxNoBuffer;
1653
wrq->u.data.length = sizeof(ulInfo);
1654
if(copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
1658
case RT_OID_802_11_PHY_MODE:
1659
ulInfo = (ULONG)pAdapter->PortCfg.PhyMode;
1660
wrq->u.data.length = sizeof(ulInfo);
1661
if(copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
1664
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_PHY_MODE (=%d)\n", ulInfo);
1666
case OID_802_11_RTS_THRESHOLD:
1667
RtsThresh = pAdapter->PortCfg.RtsThreshold;
1668
wrq->u.data.length = sizeof(RtsThresh);
1669
if(copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length))
1672
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RTS_THRESHOLD(=%d)\n", RtsThresh);
1674
case OID_802_11_FRAGMENTATION_THRESHOLD:
1675
FragThresh = pAdapter->PortCfg.FragmentThreshold;
1676
if (pAdapter->PortCfg.bFragmentZeroDisable == TRUE)
1678
wrq->u.data.length = sizeof(FragThresh);
1679
if(copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length))
1682
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%d)\n", FragThresh);
1684
case OID_802_11_POWER_MODE:
1685
PowerMode = pAdapter->PortCfg.WindowsPowerMode;
1686
wrq->u.data.length = sizeof(PowerMode);
1687
if(copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length))
1690
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode);
1692
case RT_OID_802_11_RADIO:
1693
RadioState = (BOOLEAN) pAdapter->PortCfg.bSwRadio;
1694
wrq->u.data.length = sizeof(RadioState);
1695
if(copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length))
1698
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState);
1700
case OID_802_11_INFRASTRUCTURE_MODE:
1701
if (ADHOC_ON(pAdapter))
1702
BssType = Ndis802_11IBSS;
1703
else if (INFRA_ON(pAdapter))
1704
BssType = Ndis802_11Infrastructure;
1706
BssType = Ndis802_11AutoUnknown;
1708
wrq->u.data.length = sizeof(BssType);
1709
if(copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length))
1712
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType);
1714
case RT_OID_802_11_PREAMBLE:
1715
PreamType = pAdapter->PortCfg.WindowsTxPreamble;
1716
wrq->u.data.length = sizeof(PreamType);
1717
if(copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length))
1720
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType);
1722
case OID_802_11_AUTHENTICATION_MODE:
1723
AuthMode = pAdapter->PortCfg.AuthMode;
1724
wrq->u.data.length = sizeof(AuthMode);
1725
if(copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length))
1728
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode);
1730
case OID_802_11_WEP_STATUS:
1731
WepStatus = pAdapter->PortCfg.WepStatus;
1732
wrq->u.data.length = sizeof(WepStatus);
1733
if(copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length))
1736
DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus);
1738
case RT_OID_802_11_QUERY_NOISE_LEVEL:
1739
LastR17Value = (pAdapter->PortCfg.LastR17Value > BBP_R17_DYNAMIC_UP_BOUND) ? BBP_R17_DYNAMIC_UP_BOUND : ((ULONG) pAdapter->PortCfg.LastR17Value);
1740
wrq->u.data.length = sizeof(UCHAR);
1741
if(copy_to_user(wrq->u.data.pointer, &LastR17Value, wrq->u.data.length))
1744
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", LastR17Value);
1746
case RT_OID_802_11_EXTRA_INFO:
1747
wrq->u.data.length = sizeof(ULONG);
1748
if(copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length))
1751
DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_EXTRA_INFO (=%d)\n", pAdapter->ExtraInfo);
1754
DBGPRINT(RT_DEBUG_TRACE, "Query::unknown IOCTL's subcmd = 0x%08x\n", cmd);
1755
Status = -EOPNOTSUPP;
1764
INT RTMPSetInformation(
1765
IN PRT2570ADAPTER pAdapter,
1766
IN OUT struct ifreq *rq,
1769
struct iwreq *wrq = (struct iwreq *) rq;
1770
NDIS_802_11_SSID Ssid, *pSsid=NULL;
1771
NDIS_802_11_MAC_ADDRESS Bssid;
1772
RT_802_11_PHY_MODE PhyMode;
1773
NDIS_802_11_RATES aryRates;
1774
RT_802_11_PREAMBLE Preamble;
1775
NDIS_802_11_WEP_STATUS WepStatus;
1776
NDIS_802_11_AUTHENTICATION_MODE AuthMode;
1777
NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
1778
NDIS_802_11_RTS_THRESHOLD RtsThresh;
1779
NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1780
NDIS_802_11_POWER_MODE PowerMode;
1781
NDIS_802_11_TX_POWER_LEVEL TxPowerLevel;
1782
NDIS_802_11_KEY Key;
1783
PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
1784
NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
1787
INT Status = NDIS_STATUS_SUCCESS;
1788
UCHAR CountryRegion;
1790
NDIS_802_11_PRIVACY_FILTER Filter;
1791
NDIS_802_11_RSSI RssiTrigger;
1793
DBGPRINT(RT_DEBUG_INFO, "Set::RTMPSetInformation \n");
1795
switch(cmd & 0x7FFF) {
1796
case OID_802_11_BSSID:
1797
DBGPRINT(RT_DEBUG_ERROR,"enter OID_802_11_BSSID in RTMPSetInformation\n");
1798
if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
1802
if(copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length))
1805
pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
1806
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_BSSID, TRUE, &Bssid, wrq->u.data.length);
1810
case OID_802_11_SSID:
1811
DBGPRINT(RT_DEBUG_ERROR,"enter OID_802_11_SSID in RTMPSetInformation\n");
1812
if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
1816
if(copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length))
1821
if (pSsid->SsidLength > MAX_LEN_OF_SSID)
1825
Status =RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_SSID, TRUE, pSsid, sizeof(NDIS_802_11_SSID));
1826
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", pSsid->SsidLength, pSsid->Ssid);
1830
case OID_802_11_INFRASTRUCTURE_MODE:
1831
if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
1835
if(copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length))
1838
if (BssType == Ndis802_11IBSS)
1840
if (pAdapter->PortCfg.BssType != BSS_INDEP)
1842
// Config has changed
1843
if INFRA_ON(pAdapter)
1845
RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
1846
// First cancel linkdown timer
1847
DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n");
1850
pAdapter->PortCfg.BssType = BSS_INDEP;
1851
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (AD-HOC)\n");
1853
else if (BssType == Ndis802_11Infrastructure)
1855
if (pAdapter->PortCfg.BssType != BSS_INFRA)
1857
// Config has changed
1858
// pAdapter->bConfigChanged = TRUE;
1859
if ADHOC_ON(pAdapter)
1860
RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
1862
pAdapter->PortCfg.BssType = BSS_INFRA;
1863
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (INFRA)\n");
1868
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n");
1871
// Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1872
pAdapter->PortCfg.WpaState = SS_NOTUSE;
1874
case OID_802_11_ADD_KEY:
1875
DBGPRINT(RT_DEBUG_ERROR, "!!!!!!!!!!!!!!!!!!!!!Set::OID_802_11_ADD_KEY !!\n");
1876
if(copy_from_user(&Key, wrq->u.data.pointer, wrq->u.data.length))
1879
if (Key.Length != wrq->u.data.length)
1882
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY, Failed!!\n");
1886
if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1888
Status = RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_KEY, TRUE, &Key, wrq->u.data.length);
1890
else // Old WEP stuff
1892
KeyIdx = Key.KeyIndex & 0x0fffffff;
1893
Status = RTMPWPAWepKeySanity(pAdapter, &Key);
1894
if (Status == NDIS_STATUS_SUCCESS)
1895
Status = RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_KEY_WEP, TRUE, &Key, wrq->u.data.length);
1898
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", Key.KeyIndex, Key.KeyLength);
1901
case OID_802_11_REMOVE_KEY:
1902
DBGPRINT(RT_DEBUG_ERROR, "Set::OID_802_11_REMOVE_KEY!!\n");
1903
pRemoveKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1904
if(copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length))
1907
if (pRemoveKey->Length != wrq->u.data.length)
1910
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!\n");
1914
if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1916
Status = RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_REMOVE_KEY, TRUE, pRemoveKey, wrq->u.data.length);
1917
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n");
1921
KeyIdx = pRemoveKey->KeyIndex;
1923
if (KeyIdx & 0x80000000)
1925
// Should never set default bit when remove key
1927
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n");
1931
KeyIdx = KeyIdx & 0x0fffffff;
1935
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx);
1939
pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
1940
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length);
1947
case OID_802_11_AUTHENTICATION_MODE:
1948
if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
1952
if(copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length))
1955
if (AuthMode > Ndis802_11AuthModeMax)
1962
if (pAdapter->PortCfg.AuthMode != AuthMode)
1964
// Config has changed
1965
pAdapter->bConfigChanged = TRUE;
1967
pAdapter->PortCfg.AuthMode = AuthMode;
1969
pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1970
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->PortCfg.AuthMode);
1973
case OID_802_11_PRIVACY_FILTER:
1974
if (wrq->u.data.length != sizeof(NDIS_802_11_PRIVACY_FILTER))
1978
if(copy_from_user(&Filter, wrq->u.data.pointer, wrq->u.data.length))
1981
if ((Filter == Ndis802_11PrivFilterAcceptAll) || (Filter == Ndis802_11PrivFilter8021xWEP))
1982
pAdapter->PortCfg.PrivacyFilter = Filter;
1986
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_PRIVACY_FILTER (=%d) \n",pAdapter->PortCfg.PrivacyFilter);
1988
case OID_802_11_BSSID_LIST_SCAN:
1990
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID_LIST_SCAN \n");
1993
if (pAdapter->ScanAllowed == FALSE)
1995
DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
1996
pAdapter->PortCfg.IgnoredScanNumber = 99;
1997
return NDIS_STATUS_SUCCESS;
2000
if ((pAdapter->MediaState == NdisMediaStateConnected) &&
2001
((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ||
2002
(pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
2003
(pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
2005
DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
2006
Status = NDIS_STATUS_SUCCESS;
2010
Status =RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_BSSID_LIST_SCAN, TRUE, NULL, 0);
2012
case OID_802_11_WEP_STATUS:
2013
if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
2017
if(copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length))
2020
// Since TKIP, AES, WEP are all supported. It should not have any invalid setting
2021
if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
2023
Status = RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_WEP_STATUS, TRUE, &WepStatus, sizeof(NDIS_802_11_WEP_STATUS));
2024
pAdapter->PortCfg.WepStatus = WepStatus;
2025
pAdapter->PortCfg.OrigWepStatus = WepStatus;
2026
pAdapter->PortCfg.PairCipher = WepStatus;
2027
pAdapter->PortCfg.GroupCipher = WepStatus;
2030
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus);
2033
case OID_802_11_TX_POWER_LEVEL:
2034
if (wrq->u.data.length != sizeof(NDIS_802_11_TX_POWER_LEVEL))
2038
if(copy_from_user(&TxPowerLevel, wrq->u.data.pointer, wrq->u.data.length))
2041
if (TxPowerLevel > MAX_TX_POWER_LEVEL)
2044
pAdapter->PortCfg.TxPower = (UCHAR)TxPowerLevel;
2046
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_TX_POWER_LEVEL (=%d) \n",TxPowerLevel);
2048
case OID_802_11_RSSI_TRIGGER:
2049
if (wrq->u.data.length != sizeof(NDIS_802_11_RSSI))
2053
if(copy_from_user(&RssiTrigger, wrq->u.data.pointer, wrq->u.data.length))
2056
if (RssiTrigger > MAX_RSSI_TRIGGER || RssiTrigger < MIN_RSSI_TRIGGER)
2060
pAdapter->PortCfg.RssiTrigger = (UCHAR)RssiTrigger + pAdapter->BBPTuningParameters.RSSIToDbmOffset;
2061
if (pAdapter->PortCfg.RssiTrigger > pAdapter->PortCfg.LastRssi)
2062
pAdapter->PortCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
2064
pAdapter->PortCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD;
2067
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RSSI_TRIGGER (=%d)\n",RssiTrigger);
2069
case OID_802_11_FRAGMENTATION_THRESHOLD:
2070
if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
2074
if(copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length))
2077
pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
2078
if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
2080
if (FragThresh == 0)
2082
pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
2083
pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
2089
pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
2091
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%d) \n",FragThresh);
2093
case OID_802_11_RTS_THRESHOLD:
2094
if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
2098
if(copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length))
2101
if (RtsThresh > MAX_RTS_THRESHOLD)
2104
pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
2106
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RTS_THRESHOLD (=%d)\n",RtsThresh);
2108
case OID_802_11_DESIRED_RATES:
2109
if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
2113
if(copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length))
2116
memset(pAdapter->PortCfg.DesiredRates, 0, MAX_LEN_OF_SUPPORTED_RATES);
2117
memcpy(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
2118
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
2119
pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
2120
pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
2121
pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
2122
pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
2123
// Changing DesiredRate may affect the MAX TX rate we used to TX frames out
2124
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_UPDATE_TX_RATE, TRUE, NULL, 0);
2127
case OID_802_11_CONFIGURATION:
2128
if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
2132
if(copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length))
2136
pAdapter->PortCfg.IbssConfig.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
2137
pAdapter->PortCfg.IbssConfig.AtimWin = (USHORT) pConfig->ATIMWindow;
2138
MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->PortCfg.IbssConfig.Channel);
2139
DBGPRINT(RT_DEBUG_ERROR, "Set::OID_802_11_CONFIGURATION (BeacnPeriod=%d,AtimW=%d,Ch=%d)\n",
2140
pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->PortCfg.IbssConfig.Channel);
2141
// Config has changed
2142
pAdapter->bConfigChanged = TRUE;
2145
case OID_802_11_POWER_MODE:
2146
if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
2150
if(copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length))
2153
// save user's policy here, but not change PortCfg.Psm immediately
2154
if (PowerMode == Ndis802_11PowerModeCAM)
2156
// clear PSM bit immediately
2157
MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
2158
pAdapter->PortCfg.RecvDtim = TRUE;
2159
pAdapter->PortCfg.WindowsPowerMode = PowerMode;
2161
else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
2163
// do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
2164
// to exclude certain situations.
2165
// MlmeSetPsmBit(pAdapter, PWR_SAVE);
2166
pAdapter->PortCfg.WindowsPowerMode = PowerMode;
2167
pAdapter->PortCfg.RecvDtim = TRUE; // FALSE;
2168
pAdapter->PortCfg.DefaultListenCount = 5;
2170
else if (PowerMode == Ndis802_11PowerModeFast_PSP)
2172
// do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
2173
// to exclude certain situations.
2174
// MlmeSetPsmBit(pAdapter, PWR_SAVE);
2175
pAdapter->PortCfg.RecvDtim = TRUE;
2176
pAdapter->PortCfg.WindowsPowerMode = PowerMode;
2177
pAdapter->PortCfg.DefaultListenCount = 3;
2182
DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode);
2184
case RT_OID_802_11_PREAMBLE:
2185
if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
2189
if(copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length))
2192
if ((Preamble == Rt802_11PreambleShort) || (Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
2194
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_PREAMBLE, TRUE, &Preamble, sizeof(RT_802_11_PREAMBLE));
2201
DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_SET_PREAMBLE (=%d)\n", Preamble);
2204
case RT_OID_802_11_RADIO:
2205
if (wrq->u.data.length != sizeof(BOOLEAN))
2210
if(copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length))
2213
DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_RADIO (=%d)\n", RadioState);
2214
if (pAdapter->PortCfg.bSwRadio != RadioState)
2216
pAdapter->PortCfg.bSwRadio = RadioState;
2217
if (pAdapter->PortCfg.bRadio != (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio))
2219
pAdapter->PortCfg.bRadio = (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio);
2220
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_SET_RADIO, TRUE, NULL, 0);
2225
case RT_OID_802_11_COUNTRY_REGION:
2226
if (wrq->u.data.length != sizeof(CountryRegion))
2228
else if (!(pAdapter->PortCfg.CountryRegion & 0x80)) // Only avaliable when EEPROM not programming
2232
if(copy_from_user(&pAdapter->PortCfg.CountryRegion, wrq->u.data.pointer, wrq->u.data.length))
2235
TmpPhy = pAdapter->PortCfg.PhyMode;
2236
pAdapter->PortCfg.PhyMode = 0xff;
2237
// Build all corresponding channel information
2238
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_PHY_MODE, TRUE, &TmpPhy, sizeof(TmpPhy));
2239
DBGPRINT(RT_DEBUG_ERROR, "Set::RT_OID_802_11_COUNTRY_REGION (=%d) \n", pAdapter->PortCfg.CountryRegion);
2242
case RT_OID_802_11_PHY_MODE:
2243
if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
2247
if(copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length))
2250
Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_PHY_MODE, TRUE, &PhyMode, sizeof(RT_802_11_PHY_MODE));
2251
DBGPRINT(RT_DEBUG_ERROR, "Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode);
2254
case RT_OID_802_11_STA_CONFIG:
2255
if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
2261
Status = (RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_STA_CONFIG, TRUE, wrq->u.data.pointer, sizeof(RT_802_11_STA_CONFIG)));
2264
case RT_OID_802_11_RESET_COUNTERS:
2265
memset(&pAdapter->WlanCounters, 0, sizeof(COUNTER_802_11));
2266
memset(&pAdapter->Counters, 0, sizeof(COUNTER_802_3));
2267
memset(&pAdapter->RalinkCounters, 0, sizeof(COUNTER_RALINK));
2268
memset(&pAdapter->Mlme.PrevWlanCounters, 0, sizeof(COUNTER_802_11));
2270
return(RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_RESET_COUNTERS, TRUE, NULL, 0));
2272
DBGPRINT(RT_DEBUG_INFO, "Set::RT_OID_802_11_RESET_COUNTERS \n");
2275
// For WPA PSK PMK key
2276
case RT_OID_802_11_ADD_WPA:
2277
DBGPRINT(RT_DEBUG_ERROR, "!!!!!!!!!!!!!!!!!!!!!Set::RT_OID_802_11_ADD_WPA \n");
2278
if (wrq->u.data.length > sizeof(Key))
2282
if(copy_from_user(&Key, wrq->u.data.pointer, wrq->u.data.length))
2285
if (Key.Length != wrq->u.data.length)
2288
DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!!\n");
2292
if ((pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPAPSK) && (pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPANone))
2294
Status = -EOPNOTSUPP;
2295
DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK]\n");
2297
else // Only for WPA PSK mode
2299
pAdapter->PortCfg.PskKey.KeyLen = (UCHAR) Key.KeyLength;
2300
memcpy(pAdapter->PortCfg.PskKey.Key, Key.KeyMaterial, Key.KeyLength);
2302
if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
2304
RTMPWPAAddKeyProc(pAdapter, &Key);
2307
// Use RaConfig as PSK agent.
2308
// Start STA supplicant state machine
2309
pAdapter->PortCfg.WpaState = SS_START;
2313
DBGPRINT(RT_DEBUG_LOUD, "RT_OID_802_11_ADD_WPA Key => \n");
2314
DBGPRINT(RT_DEBUG_LOUD, " ");
2315
for (i = 0; i < Key.KeyLength; i++)
2317
DBGPRINT_RAW(RT_DEBUG_LOUD, "%02x:", pAdapter->PortCfg.PskKey.Key[i]);
2319
DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
2320
DBGPRINT(RT_DEBUG_LOUD, " ");
2323
DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
2326
DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", Key.KeyIndex, Key.KeyLength);
2334
DBGPRINT(RT_DEBUG_TRACE, "Set::unknown IOCTL's subcmd = 0x%08x\n", cmd);
2335
Status = -EOPNOTSUPP;
2344
UCHAR BCAST[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2346
========================================================================
2348
Routine Description:
2352
pAdapter Pointer to our adapter
2353
pBuf Pointer to the where the key stored
2356
NDIS_SUCCESS Add key successfully
2360
========================================================================
2362
NDIS_STATUS RTMPWPAAddKeyProc(
2363
IN PRT2570ADAPTER pAdapter,
2366
PNDIS_802_11_KEY pKey;
2370
PUCHAR pTxMic, pRxMic;
2371
BOOLEAN bTxKey; // Set the key as transmit key
2372
BOOLEAN bPairwise; // Indicate the key is pairwise key
2373
BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
2374
// Otherwise, it will set by the NIC.
2375
BOOLEAN bAuthenticator; // indicate key is set by authenticator.
2377
TXRX_CSR0_STRUC TxRxCsr0;
2378
UCHAR ZeroKey[4 * 16];
2380
DBGPRINT(RT_DEBUG_TEMP,"===>RTMPWPAAddKeyProc\n" );
2381
pKey = (PNDIS_802_11_KEY) pBuf;
2382
KeyIdx = pKey->KeyIndex & 0xff;
2383
DBGPRINT(RT_DEBUG_TEMP,"RTMPWPAAddKeyProc KeyIdx = %x\n", pKey->KeyIndex );
2384
// Bit 31 of Add-key, Tx Key
2385
bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
2386
// Bit 30 of Add-key PairwiseKey
2387
bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
2388
// Bit 29 of Add-key KeyRSC
2389
bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
2390
// Bit 28 of Add-key Authenticator
2391
bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
2393
memset(ZeroKey, 0, 4 * 16);
2394
// 1. Check Group / Pairwise Key
2395
if (bPairwise) // Pairwise Key
2397
// 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
2399
return(NDIS_STATUS_FAILURE);
2401
// 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
2402
if (bTxKey == FALSE)
2403
return(NDIS_STATUS_FAILURE);
2405
// 3. If BSSID is not all 0xff, return NDIS_STATUS_INVALID_DATA
2406
if ((memcmp(pKey->BSSID, BCAST, 6) == 0))
2407
return(NDIS_STATUS_FAILURE);
2409
// 4. Selct RxMic / TxMic based on Supp / Authenticator
2410
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2412
// for WPA-None Tx, Rx MIC is the same
2413
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2416
else if (bAuthenticator == TRUE)
2418
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2419
pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2423
pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2424
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2427
// 5. Find the old entry to overwrite or find an empty entry.
2429
for (i = 0; i < PAIRWISE_KEY_NO; i++)
2431
if (pAdapter->PortCfg.PairwiseKey[i].KeyLen == 0)
2436
else if ((memcmp(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6) == 0))
2438
// Found the old entry
2443
// If there is no match and no empty pairwise key, we have to replace an old one
2444
// which will be index 0 in our case.
2447
if (bKeyRSC == TRUE)
2449
memcpy(&pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, &pKey->KeyRSC, 6);
2453
memset(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, 0, 6);
2456
// 7. Copy information into Pairwise Key structure.
2457
// pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
2458
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].KeyLen = 16;
2459
memset(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key, 0, 16);
2460
memcpy(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key, &pKey->KeyMaterial, 16);
2461
memcpy(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic, pRxMic, 8);
2462
memcpy(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic, pTxMic, 8);
2463
memcpy(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].BssId, pKey->BSSID, 6);
2464
// Init TxTsc to one based on WiFi WPA specs
2465
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[0] = 1;
2466
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[1] = 0;
2467
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[2] = 0;
2468
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[3] = 0;
2469
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[4] = 0;
2470
pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[5] = 0;
2472
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &TxRxCsr0.value);
2473
TxRxCsr0.field.KeyID |= (0x01 << KeyIdx);
2474
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, TxRxCsr0.value);
2475
RTUSBMultiWriteMAC(pAdapter, (USHORT)(SEC_CSR0 + KeyIdx * 0x10), pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key, pAdapter->PortCfg.PairwiseKey[PairwiseIdx].KeyLen);
2477
Status = NDIS_STATUS_SUCCESS;
2479
DBGPRINT(RT_DEBUG_TEMP,"Add Pairwise TKIP Key %d= ",PairwiseIdx);
2480
DBGPRINT(RT_DEBUG_TEMP,"Pairwise TKIP Key = ");
2481
for (i = 0; i < 16; i++)
2483
DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key[i]);
2485
DBGPRINT_RAW(RT_DEBUG_INFO,"\n");
2486
DBGPRINT(RT_DEBUG_INFO,"TKIP Rx MIC Key = ");
2487
for (i = 0; i < 8; i++)
2489
DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic[i]);
2491
DBGPRINT_RAW(RT_DEBUG_INFO,"\n");
2492
DBGPRINT(RT_DEBUG_INFO,"TKIP Tx MIC Key = ");
2493
for (i = 0; i < 8; i++)
2495
DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic[i]);
2497
DBGPRINT_RAW(RT_DEBUG_INFO,"\n");
2498
DBGPRINT(RT_DEBUG_INFO,"TKIP RxTSC = ");
2499
for (i = 0; i < 6; i++)
2501
DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc[i]);
2503
DBGPRINT_RAW(RT_DEBUG_INFO,"\n");
2504
DBGPRINT(RT_DEBUG_INFO,"BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2505
pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2510
// 1. Check BSSID, if not current BSSID or Bcast, return NDIS_STATUS_INVALID_DATA
2511
//if ((memcmp(&pKey->BSSID, &BCAST, 6) != 0) &&
2512
// (memcmp(&pKey->BSSID, &pAdapter->PortCfg.Bssid, 6) != 0))
2513
// return(NDIS_STATUS_FAILURE);
2515
// 2. Check Key index for supported Group Key
2516
if (KeyIdx >= GROUP_KEY_NO)
2517
return(NDIS_STATUS_FAILURE);
2519
// 3. Set as default Tx Key if bTxKey is TRUE
2521
pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
2523
// 4. Selct RxMic / TxMic based on Supp / Authenticator
2524
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2526
// for WPA-None Tx, Rx MIC is the same
2527
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2530
else if (bAuthenticator == TRUE)
2532
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2533
pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2537
pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2538
pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2542
if (bKeyRSC == TRUE)
2544
memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, &pKey->KeyRSC, 6);
2548
memset(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, 0, 6);
2551
// 6. Copy information into Group Key structure.
2552
// pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
2553
pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 16;
2554
memset(pAdapter->PortCfg.GroupKey[KeyIdx].Key, 0, 16);
2555
memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].Key, &pKey->KeyMaterial, 16);
2556
memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].RxMic, pRxMic, 8);
2557
memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].TxMic, pTxMic, 8);
2558
memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6);
2559
// Init TxTsc to one based on WiFi WPA specs
2560
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[0] = 1;
2561
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[1] = 0;
2562
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[2] = 0;
2563
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[3] = 0;
2564
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[4] = 0;
2565
pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[5] = 0;
2566
// 802.1x port control
2567
pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2569
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &TxRxCsr0.value);
2570
// a. If BSSID is broadcast, remove all group keys indexed
2571
TxRxCsr0.field.KeyID |= (0x01 << KeyIdx);
2572
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, TxRxCsr0.value);
2573
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2575
RTUSBMultiWriteMAC(pAdapter, (USHORT)(SEC_CSR0 + KeyIdx * 0x10), pAdapter->PortCfg.GroupKey[KeyIdx].Key, 16);
2579
RTUSBMultiWriteMAC(pAdapter, (USHORT)(SEC_CSR0 + KeyIdx * 0x10), pAdapter->PortCfg.GroupKey[KeyIdx].Key, 16);
2581
DBGPRINT(RT_DEBUG_TRACE, "AddGroupKey::Use Hardware to decript broadcast/Mulitcast packet.\n");
2583
Status = NDIS_STATUS_SUCCESS;
2584
// c. For WEP compatibility
2585
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2587
pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
2590
DBGPRINT(RT_DEBUG_ERROR,"Group TKIP Key =\n ");
2591
for (i = 0; i < 16; i++)
2593
DBGPRINT_RAW(RT_DEBUG_ERROR,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].Key[i]);
2595
DBGPRINT_RAW(RT_DEBUG_ERROR,"\n");
2596
DBGPRINT(RT_DEBUG_TRACE,"TKIP Rx MIC Key = \n");
2597
for (i = 0; i < 8; i++)
2599
DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxMic[i]);
2601
DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");
2602
DBGPRINT(RT_DEBUG_TRACE,"TKIP Tx MIC Key = \n");
2603
for (i = 0; i < 8; i++)
2605
DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].TxMic[i]);
2607
DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");
2608
DBGPRINT(RT_DEBUG_TRACE,"TKIP RxTSC =\n ");
2609
for (i = 0; i < 6; i++)
2611
DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc[i]);
2613
DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");
2614
DBGPRINT(RT_DEBUG_INFO,"BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2615
pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2617
// For WEP compatibility, in case it use OID_ADD_KEY, not OID_ADD_WEP
2618
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2620
pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
2621
memcpy(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
2628
========================================================================
2630
Routine Description:
2631
Remove WPA Key process
2634
pAdapter Pointer to our adapter
2635
pBuf Pointer to the where the key stored
2638
NDIS_SUCCESS Add key successfully
2642
========================================================================
2644
NDIS_STATUS RTMPWPARemoveKeyProc(
2645
IN PRT2570ADAPTER pAdapter,
2648
PNDIS_802_11_REMOVE_KEY pKey;
2650
NDIS_STATUS Status = NDIS_STATUS_FAILURE;
2652
BOOLEAN bTxKey; // Set the key as transmit key
2653
BOOLEAN bPairwise; // Indicate the key is pairwise key
2654
BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
2655
// Otherwise, it will set by the NIC.
2656
BOOLEAN bAuthenticator; // indicate key is set by authenticator.
2660
pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
2661
KeyIdx = pKey->KeyIndex & 0xff;
2662
// Bit 31 of Add-key, Tx Key
2663
bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
2664
// Bit 30 of Add-key PairwiseKey
2665
bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
2666
// Bit 29 of Add-key KeyRSC
2667
bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
2668
// Bit 28 of Add-key Authenticator
2669
bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
2671
// 1. If bTx is TRUE, return failure information
2673
return(NDIS_STATUS_FAILURE);
2675
// 2. Check Pairwise Key
2678
// a. If BSSID is broadcast, remove all pairwise keys.
2679
if ((memcmp(&pKey->BSSID, &BCAST, 6) == 0))
2681
for (i = 0; i < PAIRWISE_KEY_NO; i++)
2683
pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2685
Status = NDIS_STATUS_SUCCESS;
2686
// RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
2687
// RTUSBReadMACRegister(pAdapter, TXRX_CSR0, temp & 0xfdff);
2690
// b. If not broadcast, remove the pairwise specified by BSSID
2693
for (i = 0; i < PAIRWISE_KEY_NO; i++)
2695
if ((memcmp(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6) == 0))
2697
pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2698
// RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
2699
// RTUSBReadMACRegister(pAdapter, TXRX_CSR0, temp & 0xfdff);
2700
Status = NDIS_STATUS_SUCCESS;
2706
// c. If no pairwise supported, delete Group Key 0.
2707
// The will be false since we do support pairwise keys.
2712
// a. If BSSID is broadcast, remove all group keys indexed
2713
if ((memcmp(&pKey->BSSID, &BCAST, 6) == 0))
2715
pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2716
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
2717
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, temp & (~(0x200 << KeyIdx)));
2718
Status = NDIS_STATUS_SUCCESS;
2721
// b. If BSSID matched, delte the group key indexed.
2722
else if ((memcmp(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6) == 0))
2724
pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2725
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
2726
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, temp & (~(0x200 << KeyIdx)));
2727
Status = NDIS_STATUS_SUCCESS;
2736
========================================================================
2738
Routine Description:
2742
pAdapter Pointer to our adapter
2749
========================================================================
2751
VOID RTMPWPARemoveAllKeys(
2752
IN PRT2570ADAPTER pAdapter)
2757
// For WPA-None, there is no need to remove it, since WinXP won't set it again after
2758
// Link up. And it will be replaced if user changed it.
2759
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2762
for (i = 0; i < PAIRWISE_KEY_NO; i++)
2764
pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2767
for (i = 0; i < GROUP_KEY_NO; i++)
2769
pAdapter->PortCfg.GroupKey[i].KeyLen = 0;
2772
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
2773
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, temp & 0xe1ff);
2777
========================================================================
2778
Routine Description:
2779
Change NIC PHY mode. Re-association may be necessary. possible settings
2780
include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
2783
pAdapter - Pointer to our adapter
2785
========================================================================
2787
VOID RTMPSetPhyMode(
2788
IN PRT2570ADAPTER pAdapter,
2791
DBGPRINT(RT_DEBUG_ERROR,"RTMPSetPhyMode(=%d)\n", phymode);
2793
// the selected phymode must be supported by the RF IC encoded in E2PROM
2794
if (pAdapter->PortCfg.RfType == RFIC_2426)
2798
else if (pAdapter->PortCfg.RfType < RFIC_5222)
2800
if (phymode == PHY_11A)
2801
phymode = PHY_11BG_MIXED;
2804
// if no change, do nothing
2805
if (pAdapter->PortCfg.PhyMode == phymode)
2808
pAdapter->PortCfg.PhyMode = (UCHAR)phymode;
2809
BuildChannelList(pAdapter);
2810
pAdapter->PortCfg.IbssConfig.Channel = FirstChannel(pAdapter);
2811
pAdapter->PortCfg.Channel = FirstChannel(pAdapter);
2812
AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
2813
AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
2817
DBGPRINT(RT_DEBUG_TEMP,"PHY_11B\n");
2818
pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2819
pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2820
pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2821
pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2822
pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 4;
2823
pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2824
pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2825
pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps
2826
pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2827
pAdapter->PortCfg.SupportedRatesLen = 4;
2828
pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2829
pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2830
pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2831
pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2832
pAdapter->PortCfg.DesiredRates[4] = 0;
2833
pAdapter->PortCfg.DesiredRates[5] = 0;
2834
pAdapter->PortCfg.DesiredRates[6] = 0;
2835
pAdapter->PortCfg.DesiredRates[7] = 0;
2836
pAdapter->PortCfg.DesiredRates[8] = 0;
2837
pAdapter->PortCfg.DesiredRates[9] = 0;
2838
pAdapter->PortCfg.DesiredRates[10] = 0;
2839
pAdapter->PortCfg.DesiredRates[11] = 0;
2842
case PHY_11BG_MIXED:
2843
case PHY_11ABG_MIXED:
2844
DBGPRINT(RT_DEBUG_TEMP,"PHY_11BG_MIXED\n");
2845
pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2846
pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2847
pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2848
pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2849
pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2850
pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x12; // 9 mbps, in units of 0.5 Mbps
2851
pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2852
pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x24; // 18 mbps, in units of 0.5 Mbps
2853
pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2854
pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0x48; // 36 mbps, in units of 0.5 Mbps
2855
pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0x60; // 48 mbps, in units of 0.5 Mbps
2856
pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2857
pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 12;
2858
pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2859
pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2860
pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2861
pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2862
pAdapter->PortCfg.SupportedRates[4] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2863
pAdapter->PortCfg.SupportedRates[5] = 0x12; // 9 mbps, in units of 0.5 Mbps
2864
pAdapter->PortCfg.SupportedRates[6] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2865
pAdapter->PortCfg.SupportedRates[7] = 0x24; // 18 mbps, in units of 0.5 Mbps
2866
pAdapter->PortCfg.SupportedRates[8] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2867
pAdapter->PortCfg.SupportedRates[9] = 0x48; // 36 mbps, in units of 0.5 Mbps
2868
pAdapter->PortCfg.SupportedRates[10] = 0x60; // 48 mbps, in units of 0.5 Mbps
2869
pAdapter->PortCfg.SupportedRates[11] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2870
pAdapter->PortCfg.SupportedRatesLen = 12;
2871
pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2872
pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2873
pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2874
pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2875
pAdapter->PortCfg.DesiredRates[4] = 12; // 6 mbps, in units of 0.5 Mbps
2876
pAdapter->PortCfg.DesiredRates[5] = 18; // 9 mbps, in units of 0.5 Mbps
2877
pAdapter->PortCfg.DesiredRates[6] = 24; // 12 mbps, in units of 0.5 Mbps
2878
pAdapter->PortCfg.DesiredRates[7] = 36; // 18 mbps, in units of 0.5 Mbps
2879
pAdapter->PortCfg.DesiredRates[8] = 48; // 24 mbps, in units of 0.5 Mbps
2880
pAdapter->PortCfg.DesiredRates[9] = 72; // 36 mbps, in units of 0.5 Mbps
2881
pAdapter->PortCfg.DesiredRates[10] = 96; // 48 mbps, in units of 0.5 Mbps
2882
pAdapter->PortCfg.DesiredRates[11] = 108; // 54 mbps, in units of 0.5 Mbps
2886
DBGPRINT(RT_DEBUG_TEMP,"PHY_11A\n");
2887
pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2888
pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2889
pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2890
pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2891
pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2892
pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2893
pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2894
pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2895
pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0;
2896
pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0;
2897
pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0;
2898
pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0;
2899
pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 8;
2900
pAdapter->PortCfg.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2901
pAdapter->PortCfg.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2902
pAdapter->PortCfg.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2903
pAdapter->PortCfg.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2904
pAdapter->PortCfg.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2905
pAdapter->PortCfg.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2906
pAdapter->PortCfg.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2907
pAdapter->PortCfg.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2908
pAdapter->PortCfg.SupportedRates[8] = 0;
2909
pAdapter->PortCfg.SupportedRates[9] = 0;
2910
pAdapter->PortCfg.SupportedRates[10] = 0;
2911
pAdapter->PortCfg.SupportedRates[11] = 0;
2912
pAdapter->PortCfg.SupportedRatesLen = 8;
2913
pAdapter->PortCfg.DesiredRates[0] = 12; // 6 mbps, in units of 0.5 Mbps
2914
pAdapter->PortCfg.DesiredRates[1] = 18; // 9 mbps, in units of 0.5 Mbps
2915
pAdapter->PortCfg.DesiredRates[2] = 24; // 12 mbps, in units of 0.5 Mbps
2916
pAdapter->PortCfg.DesiredRates[3] = 36; // 18 mbps, in units of 0.5 Mbps
2917
pAdapter->PortCfg.DesiredRates[4] = 48; // 24 mbps, in units of 0.5 Mbps
2918
pAdapter->PortCfg.DesiredRates[5] = 72; // 36 mbps, in units of 0.5 Mbps
2919
pAdapter->PortCfg.DesiredRates[6] = 96; // 48 mbps, in units of 0.5 Mbps
2920
pAdapter->PortCfg.DesiredRates[7] = 108; // 54 mbps, in units of 0.5 Mbps
2921
pAdapter->PortCfg.DesiredRates[8] = 0;
2922
pAdapter->PortCfg.DesiredRates[9] = 0;
2923
pAdapter->PortCfg.DesiredRates[10] = 0;
2924
pAdapter->PortCfg.DesiredRates[11] = 0;
2928
DBGPRINT(RT_DEBUG_TEMP,"default\n");
2932
MlmeUpdateTxRates(pAdapter, FALSE);
2933
AsicSetSlotTime(pAdapter, FALSE);
2934
MakeIbssBeacon(pAdapter); // supported rates may change
2938
VOID RT2570SetDesiredRates(
2939
IN PRT2570ADAPTER pAdapter,
2943
NDIS_802_11_RATES aryRates;
2944
ULONG rate_mapping[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
2945
DBGPRINT(RT_DEBUG_TEMP, "1.RT2570SetDesiredRates::(Rates=%d)\n", Rates );
2947
DBGPRINT(RT_DEBUG_ERROR, "2.RT2570SetDesiredRates::(Rates=%d)\n", Rates );
2948
if (Rates < 13 && (Rates > 0))
2949
Rates = rate_mapping[Rates-1] * 1000000;
2951
memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
2952
switch (pAdapter->PortCfg.PhyMode)
2954
case PHY_11A: // A only
2958
aryRates[0] = 0x0c; // 6M
2961
aryRates[0] = 0x12; // 9M
2963
case 12000000: //12M
2964
aryRates[0] = 0x18; // 12M
2966
case 18000000: //18M
2967
aryRates[0] = 0x24; // 18M
2969
case 24000000: //24M
2970
aryRates[0] = 0x30; // 24M
2972
case 36000000: //36M
2973
aryRates[0] = 0x48; // 36M
2975
case 48000000: //48M
2976
aryRates[0] = 0x60; // 48M
2978
case 54000000: //54M
2979
aryRates[0] = 0x6c; // 54M
2983
aryRates[0] = 0x6c; // 54Mbps
2984
aryRates[1] = 0x60; // 48Mbps
2985
aryRates[2] = 0x48; // 36Mbps
2986
aryRates[3] = 0x30; // 24Mbps
2987
aryRates[4] = 0x24; // 18M
2988
aryRates[5] = 0x18; // 12M
2989
aryRates[6] = 0x12; // 9M
2990
aryRates[7] = 0x0c; // 6M
2994
case PHY_11B: // B only
3003
case 5000000: //5.5M
3004
aryRates[0] = 0x0b; // 5.5M
3006
case 11000000: //11M
3007
aryRates[0] = 0x16; // 11M
3011
aryRates[0] = 0x16; // 11Mbps
3012
aryRates[1] = 0x0b; // 5.5Mbps
3013
aryRates[2] = 0x04; // 2Mbps
3014
aryRates[3] = 0x02; // 1Mbps
3018
case PHY_11BG_MIXED: // B/G Mixed
3019
case PHY_11ABG_MIXED: // A/B/G Mixed
3029
case 5000000: //5.5M
3030
aryRates[0] = 0x0b; // 5.5M
3032
case 11000000: //11M
3033
aryRates[0] = 0x16; // 11M
3036
aryRates[0] = 0x0c; // 6M
3039
aryRates[0] = 0x12; // 9M
3041
case 12000000: //12M
3042
aryRates[0] = 0x18; // 12M
3044
case 18000000: //18M
3045
aryRates[0] = 0x24; // 18M
3047
case 24000000: //24M
3048
aryRates[0] = 0x30; // 24M
3050
case 36000000: //36M
3051
aryRates[0] = 0x48; // 36M
3053
case 48000000: //48M
3054
aryRates[0] = 0x60; // 48M
3056
case 54000000: //54M
3057
aryRates[0] = 0x6c; // 54M
3061
if (pAdapter->PortCfg.PhyMode == PHY_11B)
3063
aryRates[0] = 0x16; // 11Mbps
3064
aryRates[1] = 0x0b; // 5.5Mbps
3065
aryRates[2] = 0x04; // 2Mbps
3066
aryRates[3] = 0x02; // 1Mbps
3069
{ //(B/G) Mixed or (A/B/G) Mixed
3070
aryRates[0] = 0x6c; // 54Mbps
3071
aryRates[1] = 0x60; // 48Mbps
3072
aryRates[2] = 0x48; // 36Mbps
3073
aryRates[3] = 0x30; // 24Mbps
3074
aryRates[4] = 0x16; // 11Mbps
3075
aryRates[5] = 0x0b; // 5.5Mbps
3076
aryRates[6] = 0x04; // 2Mbps
3077
aryRates[7] = 0x02; // 1Mbps
3084
memset(pAdapter->PortCfg.DesiredRates, 0, MAX_LEN_OF_SUPPORTED_RATES);
3085
memcpy(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
3086
DBGPRINT(RT_DEBUG_TEMP, " RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3087
pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
3088
pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
3089
pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
3090
pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
3091
// Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3092
MlmeUpdateTxRates(pAdapter, FALSE);
3097
IN PRT2570ADAPTER pAdapter,
3106
TUNN = simple_strtol(arg, 0, 10);
3109
DBGPRINT(RT_DEBUG_TEMP, "Set_R17_Proc -->TUNN = 0x%x id = %d, Value=ox%x!!!\n",TUNN,i,Value);
3110
RTUSBWriteBBPRegister(pAdapter, i, Value);
3115
IN PRT2570ADAPTER pAdapter,
3123
for ( i = 0 ; i<70; i++)
3126
RTUSBReadBBPRegister(pAdapter, i, &Value);
3127
DBGPRINT(RT_DEBUG_TEMP,"Read_BBP_Proc R%d = 0x%x\n",i,Value);
3133
==========================================================================
3137
TRUE if all parameters are OK, FALSE otherwise
3138
==========================================================================
3140
INT Set_CountryRegion_Proc(
3141
IN PRT2570ADAPTER pAdapter,
3147
region = simple_strtol(arg, 0, 10);
3148
if( (region >= REGION_MIN) && (region <= REGION_MAX) )
3150
pAdapter->PortCfg.CountryRegion = (UCHAR) region;
3151
DBGPRINT(RT_DEBUG_TRACE, "Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
3152
printk("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
3160
==========================================================================
3164
TRUE if all parameters are OK, FALSE otherwise
3165
==========================================================================
3168
IN PRT2570ADAPTER pAdapter,
3172
NDIS_802_11_SSID Ssid, *pSsid=NULL;
3173
BOOLEAN StateMachineTouched = FALSE;
3174
if( strlen(arg) <= MAX_LEN_OF_SSID)
3176
memset(&Ssid, 0, sizeof(NDIS_802_11_SSID));
3177
memcpy(Ssid.Ssid, arg, strlen(arg));
3178
Ssid.SsidLength = strlen(arg);
3181
if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3183
MlmeRestartStateMachine(pAdapter);
3184
MlmePostRestartStateMachine(pAdapter);
3185
DBGPRINT(RT_DEBUG_TEMP, "!!! MLME busy, reset MLME state machine !!!\n");
3187
// tell CNTL state machine to call NdisMSetInformationComplete() after completing
3188
// this request, because this request is initiated by NDIS.
3189
pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
3191
MlmeEnqueue(pAdapter,
3192
MLME_CNTL_STATE_MACHINE,
3194
sizeof(NDIS_802_11_SSID),
3197
StateMachineTouched = TRUE;
3198
DBGPRINT(RT_DEBUG_TEMP, "Set_SSID_Proc::(Len=%d,Ssid=%s)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
3203
RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
3208
==========================================================================
3212
TRUE if all parameters are OK, FALSE otherwise
3213
==========================================================================
3215
INT Set_WirelessMode_Proc(
3216
IN PRT2570ADAPTER pAdapter,
3222
WirelessMode = simple_strtol(arg, 0, 10);
3224
if ((WirelessMode == PHY_11BG_MIXED) || (WirelessMode == PHY_11B) ||
3225
(WirelessMode == PHY_11A) || (WirelessMode == PHY_11ABG_MIXED))
3227
RTMPSetPhyMode(pAdapter, WirelessMode);
3228
DBGPRINT(RT_DEBUG_TEMP, "Set_WirelessMode_Proc::(=%d)\n", WirelessMode);
3236
==========================================================================
3240
TRUE if all parameters are OK, FALSE otherwise
3241
==========================================================================
3243
INT Set_TxRate_Proc(
3244
IN PRT2570ADAPTER pAdapter,
3250
ULONG rate_mapping[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
3251
TxRate = simple_strtol(arg, 0, 10);
3252
DBGPRINT(RT_DEBUG_TEMP, "Set_TxRate_Proc::(TxRate=%d)\n", TxRate);
3257
RT2570SetDesiredRates(pAdapter, -1);
3259
RT2570SetDesiredRates(pAdapter, (LONG) (rate_mapping[TxRate-1] * 1000000));
3265
==========================================================================
3269
TRUE if all parameters are OK, FALSE otherwise
3270
==========================================================================
3272
INT Set_Channel_Proc(
3273
IN PRT2570ADAPTER pAdapter,
3279
Channel = (UCHAR) simple_strtol(arg, 0, 10);
3281
if (ChannelSanity(pAdapter, Channel) == TRUE)
3283
pAdapter->PortCfg.Channel = Channel;
3284
DBGPRINT(RT_DEBUG_TRACE, "Set_Channel_Proc::(Channel=%d)\n", Channel);
3293
==========================================================================
3295
Set 11B/11G Protection
3297
TRUE if all parameters are OK, FALSE otherwise
3298
==========================================================================
3300
INT Set_BGProtection_Proc(
3301
IN PRT2570ADAPTER pAdapter,
3305
switch (simple_strtol(arg, 0, 10))
3308
pAdapter->PortCfg.UseBGProtection = 0;
3311
pAdapter->PortCfg.UseBGProtection = 1;
3313
case 2: //Always OFF
3314
pAdapter->PortCfg.UseBGProtection = 2;
3316
default: //Invalid argument
3319
DBGPRINT(RT_DEBUG_TEMP, "Set_BGProtection_Proc::(BGProtection=%d)\n", pAdapter->PortCfg.UseBGProtection);
3324
==========================================================================
3328
TRUE if all parameters are OK, FALSE otherwise
3329
==========================================================================
3331
INT Set_TxPreamble_Proc(
3332
IN PRT2570ADAPTER pAdapter,
3336
RT_802_11_PREAMBLE Preamble;
3337
Preamble = simple_strtol(arg, 0, 10);
3340
case Rt802_11PreambleShort:
3341
pAdapter->PortCfg.WindowsTxPreamble = Preamble;
3342
MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3344
case Rt802_11PreambleLong:
3345
case Rt802_11PreambleAuto:
3346
// if user wants AUTO, initialize to LONG here, then change according to AP's
3347
// capability upon association.
3348
pAdapter->PortCfg.WindowsTxPreamble = Preamble;
3349
MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3351
default: //Invalid argument
3355
DBGPRINT(RT_DEBUG_TEMP, "Set_TxPreamble_Proc::(TxPreamble=%d)\n", Preamble);
3361
==========================================================================
3365
TRUE if all parameters are OK, FALSE otherwise
3366
==========================================================================
3368
INT Set_RTSThreshold_Proc(
3369
IN PRT2570ADAPTER pAdapter,
3372
NDIS_802_11_RTS_THRESHOLD RtsThresh;
3374
RtsThresh = simple_strtol(arg, 0, 10);
3376
if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
3377
pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
3378
else if (RtsThresh == 0)
3379
pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
3383
DBGPRINT(RT_DEBUG_TEMP, "Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAdapter->PortCfg.RtsThreshold);
3387
==========================================================================
3389
Set Fragment Threshold
3391
TRUE if all parameters are OK, FALSE otherwise
3392
==========================================================================
3394
INT Set_FragThreshold_Proc(
3395
IN PRT2570ADAPTER pAdapter,
3398
NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3400
FragThresh = simple_strtol(arg, 0, 10);
3402
if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
3403
pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
3404
else if (FragThresh == 0)
3405
pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3407
return FALSE; //Invalid argument
3409
if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
3410
pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
3412
pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
3414
DBGPRINT(RT_DEBUG_TEMP, "Set_FragThreshold_Proc::(FragThreshold=%d)\n", FragThresh);
3419
==========================================================================
3423
TRUE if all parameters are OK, FALSE otherwise
3424
==========================================================================
3426
INT Set_TxBurst_Proc(
3427
IN PRT2570ADAPTER pAdapter,
3432
TxBurst = simple_strtol(arg, 0, 10);
3435
pAdapter->PortCfg.EnableTxBurst = TRUE;
3436
else if (TxBurst == 0)
3437
pAdapter->PortCfg.EnableTxBurst = FALSE;
3439
return FALSE; //Invalid argument
3441
DBGPRINT(RT_DEBUG_TEMP, "Set_TxBurst_Proc::(TxBurst=%d)\n", pAdapter->PortCfg.EnableTxBurst);
3446
==========================================================================
3448
Set TurboRate Enable or Disable
3450
TRUE if all parameters are OK, FALSE otherwise
3451
==========================================================================
3453
INT Set_TurboRate_Proc(
3454
IN PRT2570ADAPTER pAdapter,
3459
TurboRate = simple_strtol(arg, 0, 10);
3462
pAdapter->PortCfg.EnableTurboRate = TRUE;
3463
else if (TurboRate == 0)
3464
pAdapter->PortCfg.EnableTurboRate = FALSE;
3466
return FALSE; //Invalid argument
3468
DBGPRINT(RT_DEBUG_TEMP, "Set_TurboRate_Proc::(TurboRate=%d)\n", pAdapter->PortCfg.EnableTurboRate);
3473
==========================================================================
3475
Set Short Slot Time Enable or Disable
3477
TRUE if all parameters are OK, FALSE otherwise
3478
==========================================================================
3480
INT Set_ShortSlot_Proc(
3481
IN PRT2570ADAPTER pAdapter,
3486
ShortSlot = simple_strtol(arg, 0, 10);
3489
pAdapter->PortCfg.UseShortSlotTime = TRUE;
3490
else if (ShortSlot == 0)
3491
pAdapter->PortCfg.UseShortSlotTime = FALSE;
3493
return FALSE; //Invalid argument
3495
DBGPRINT(RT_DEBUG_TEMP, "Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAdapter->PortCfg.UseShortSlotTime);
3500
==========================================================================
3502
Set Authentication mode
3504
TRUE if all parameters are OK, FALSE otherwise
3505
==========================================================================
3507
INT Set_AuthMode_Proc(
3508
IN PRT2570ADAPTER pAdapter,
3511
if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
3512
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
3513
else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
3514
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
3515
else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
3516
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
3517
else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
3518
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
3522
pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3524
DBGPRINT(RT_DEBUG_TEMP, "Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->PortCfg.AuthMode);
3529
==========================================================================
3533
TRUE if all parameters are OK, FALSE otherwise
3534
==========================================================================
3536
INT Set_EncrypType_Proc(
3537
IN PRT2570ADAPTER pAdapter,
3541
if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
3543
pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
3544
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3546
DBGPRINT(RT_DEBUG_INFO,"Set::NONERead TXRX_CSR0 %x !!!!!!!!!!!!!!!!!\n",Value);
3547
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3549
else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
3551
pAdapter->PortCfg.WepStatus = Ndis802_11Encryption1Enabled;
3552
if ((pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen == 5) || (pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen == 10))
3553
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
3555
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
3557
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3558
DBGPRINT(RT_DEBUG_TEMP,"Set::WEPRead TXRX_CSR0 %x !!!!!!!!!!!!!!!!!\n",Value);
3560
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3561
DBGPRINT(RT_DEBUG_TEMP,"Set::WEPRead TXRX_CSR0 %x !!!!!!!!!!!!!!!!!\n",Value);
3562
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3564
else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
3566
pAdapter->PortCfg.WepStatus = Ndis802_11Encryption2Enabled;
3567
pAdapter->PortCfg.CipherAlg = CIPHER_TKIP;
3568
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3569
DBGPRINT(RT_DEBUG_INFO,"Set::Read TXRX_CSR0 %x !!!!!!!!!!!!!!!!!\n",Value);
3571
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3572
DBGPRINT(RT_DEBUG_INFO,"Set::Read TXRX_CSR0 %x !!!!!!!!!!!!!!!!!\n",Value);
3573
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3575
else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
3577
pAdapter->PortCfg.WepStatus = Ndis802_11Encryption3Enabled;
3578
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3580
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3581
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3585
DBGPRINT(RT_DEBUG_INFO,"Set::EncrypType ERROR !!!!!!!!!!!!!!!!!\n");
3590
DBGPRINT(RT_DEBUG_TEMP, "Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->PortCfg.WepStatus);
3596
==========================================================================
3600
TRUE if all parameters are OK, FALSE otherwise
3601
==========================================================================
3603
INT Set_DefaultKeyID_Proc(
3604
IN PRT2570ADAPTER pAdapter,
3609
KeyIdx = simple_strtol(arg, 0, 10);
3610
if((KeyIdx >= 1 ) && (KeyIdx <= 4))
3611
pAdapter->PortCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
3613
return FALSE; //Invalid argument
3615
DBGPRINT(RT_DEBUG_TEMP, "Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->PortCfg.DefaultKeyId);
3620
==========================================================================
3624
TRUE if all parameters are OK, FALSE otherwise
3625
==========================================================================
3628
IN PRT2570ADAPTER pAdapter,
3635
KeyLen = strlen(arg);
3639
case 5: //wep 40 Ascii type
3640
pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3641
memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3642
DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3645
case 10: //wep 40 Hex type
3646
for(i=0; i < KeyLen; i++)
3648
if( !isxdigit(*(arg+i)) )
3649
return FALSE; //Not Hex value;
3651
pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3652
AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3653
DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3656
case 13: //wep 104 Ascii type
3657
pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3658
memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3659
DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3661
case 26: //wep 104 Hex type
3662
for(i=0; i < KeyLen; i++)
3664
if( !isxdigit(*(arg+i)) )
3665
return FALSE; //Not Hex value;
3667
pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3668
AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3669
DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3671
default: //Invalid argument
3672
DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::Invalid argument (=%s)\n", arg);
3677
RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 0 * 0x10), pAdapter->PortCfg.SharedKey[0].Key, 16);
3681
// Default key for tx (shared key)
3682
pAdapter->PortCfg.DefaultKeyId = (UCHAR)0;
3686
if ( (KeyLen == 5) ||( KeyLen == 10) )
3687
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
3689
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
3691
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3693
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3694
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3699
==========================================================================
3703
TRUE if all parameters are OK, FALSE otherwise
3704
==========================================================================
3707
IN PRT2570ADAPTER pAdapter,
3714
KeyLen = strlen(arg);
3718
case 5: //wep 40 Ascii type
3719
pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3720
memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3721
DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3723
case 10: //wep 40 Hex type
3724
for(i=0; i < KeyLen; i++)
3726
if( !isxdigit(*(arg+i)) )
3727
return FALSE; //Not Hex value;
3729
pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3730
AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3731
DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3733
case 13: //wep 104 Ascii type
3734
pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3735
memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3736
DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3738
case 26: //wep 104 Hex type
3739
for(i=0; i < KeyLen; i++)
3741
if( !isxdigit(*(arg+i)) )
3742
return FALSE; //Not Hex value;
3744
pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3745
AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3746
DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3748
default: //Invalid argument
3749
DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::Invalid argument (=%s)\n", arg);
3753
RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 1 * 0x10), pAdapter->PortCfg.SharedKey[1].Key, 16);
3759
// Default key for tx (shared key)
3760
pAdapter->PortCfg.DefaultKeyId = (UCHAR)1;
3764
if ( (KeyLen == 5) ||( KeyLen == 10) )
3765
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
3767
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
3769
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3771
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3772
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3777
==========================================================================
3781
TRUE if all parameters are OK, FALSE otherwise
3782
==========================================================================
3785
IN PRT2570ADAPTER pAdapter,
3792
KeyLen = strlen(arg);
3796
case 5: //wep 40 Ascii type
3797
pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3798
memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3799
DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3801
case 10: //wep 40 Hex type
3802
for(i=0; i < KeyLen; i++)
3804
if( !isxdigit(*(arg+i)) )
3805
return FALSE; //Not Hex value;
3807
pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3808
AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3809
DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3811
case 13: //wep 104 Ascii type
3812
pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3813
memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3814
DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3816
case 26: //wep 104 Hex type
3817
for(i=0; i < KeyLen; i++)
3819
if( !isxdigit(*(arg+i)) )
3820
return FALSE; //Not Hex value;
3822
pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3823
AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3824
DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3826
default: //Invalid argument
3827
DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::Invalid argument (=%s)\n", arg);
3831
RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 2 * 0x10), pAdapter->PortCfg.SharedKey[2].Key, 16);
3834
// Default key for tx (shared key)
3835
pAdapter->PortCfg.DefaultKeyId = (UCHAR)2;
3839
if ( (KeyLen == 5) ||( KeyLen == 10) )
3840
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
3842
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
3844
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3846
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3847
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3852
==========================================================================
3856
TRUE if all parameters are OK, FALSE otherwise
3857
==========================================================================
3860
IN PRT2570ADAPTER pAdapter,
3867
KeyLen = strlen(arg);
3871
case 5: //wep 40 Ascii type
3872
pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3873
memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3874
DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3876
case 10: //wep 40 Hex type
3877
for(i=0; i < KeyLen; i++)
3879
if( !isxdigit(*(arg+i)) )
3880
return FALSE; //Not Hex value;
3882
pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3883
AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3884
DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3886
case 13: //wep 104 Ascii type
3887
pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3888
memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3889
DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3891
case 26: //wep 104 Hex type
3892
for(i=0; i < KeyLen; i++)
3894
if( !isxdigit(*(arg+i)) )
3895
return FALSE; //Not Hex value;
3897
pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3898
AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3899
DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3901
default: //Invalid argument
3902
DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::Invalid argument (=%s)\n", arg);
3906
RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 3 * 0x10), pAdapter->PortCfg.SharedKey[3].Key, 16);
3909
// Default key for tx (shared key)
3910
pAdapter->PortCfg.DefaultKeyId = (UCHAR)3;
3914
if ( (KeyLen == 5) ||( KeyLen == 10) )
3915
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
3917
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
3919
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
3921
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
3922
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
3927
==========================================================================
3931
TRUE if all parameters are OK, FALSE otherwise
3932
==========================================================================
3934
INT Set_WPAPSK_Proc(
3935
IN PRT2570ADAPTER pAdapter,
3939
UCHAR keyMaterial[40];
3941
DBGPRINT(RT_DEBUG_TRACE, "Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg);
3942
if ((strlen(arg) < 8) || (strlen(arg) > 64))
3944
DBGPRINT(RT_DEBUG_TRACE, "Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg);
3948
PasswordHash((char *)arg, pAdapter->PortCfg.Ssid, pAdapter->PortCfg.SsidLen, keyMaterial);
3950
memcpy(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
3952
// Use RaConfig as PSK agent.
3953
// Start STA supplicant state machine
3954
pAdapter->PortCfg.WpaState = SS_START;
3956
DBGPRINT(RT_DEBUG_LOUD, "Set_WPAPSK_Proc WPAPSK Key => \n");
3957
DBGPRINT(RT_DEBUG_LOUD, " ");
3958
for (i = 0; i < 32; i++)
3960
DBGPRINT_RAW(RT_DEBUG_LOUD, "%02x:", pAdapter->PortCfg.PskKey.Key[i]);
3962
DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
3963
DBGPRINT(RT_DEBUG_LOUD, " ");
3966
DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
3974
int usb_rt2570_ioctl(struct net_device *net_dev, struct ifreq *rq,
3977
PRT2570ADAPTER pAdapter= net_dev->priv;
3978
struct iwreq *wrq = (struct iwreq *) rq;
3979
struct iw_point *erq = NULL;
3980
struct iw_freq *frq = NULL;
3981
NDIS_802_11_NETWORK_INFRASTRUCTURE BssType = Ndis802_11Infrastructure;
3982
NDIS_802_11_RTS_THRESHOLD RtsThresh;
3983
NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3984
NDIS_802_11_MAC_ADDRESS Bssid;
3985
INT Status = NDIS_STATUS_SUCCESS;
3986
BOOLEAN StateMachineTouched = FALSE;
3987
int chan = -1, index = 0, len = 0;
3990
if ( (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_REMOVE_IN_PROGRESS)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)))
3992
DBGPRINT(RT_DEBUG_TRACE,"INFO::remove in progress!\n");
3995
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
3996
if (pAdapter->RTUSBCmdThr_pid < 0)
3999
if (!pAdapter->RTUSBCmdThr_active)
4006
DBGPRINT(RT_DEBUG_INFO,"IOCTL::SIOCGIWNAME\n");
4007
strcpy(wrq->u.name,"RT2570 Wireless"); //Less then 16 bytes.
4009
case SIOCSIWESSID: //Set ESSID
4010
DBGPRINT(RT_DEBUG_INFO, "==>ioctl::SIOCSIWESSID\n");
4013
case SIOCGIWESSID: //Get ESSID
4014
DBGPRINT(RT_DEBUG_INFO, "==>ioctl::SIOCGIWESSID\n");
4016
case SIOCSIWFREQ: // set channel/frequency (Hz)
4017
frq = &(wrq->u.freq);
4018
if((frq->e == 0) && (frq->m <= 1000))
4019
chan = frq->m; // Setting by channel number
4021
MAP_KHZ_TO_CHANNEL_ID( (frq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
4022
pAdapter->PortCfg.IbssConfig.Channel = chan;
4023
DBGPRINT(RT_DEBUG_ERROR, "<==ioctl::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->PortCfg.IbssConfig.Channel);
4025
case SIOCGIWFREQ: // get channel/frequency (Hz)
4026
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWFREQ\n");
4028
case SIOCGIWNICKN: //get node name/nickname
4029
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWNICKN\n");
4031
erq->length = strlen(pAdapter->nickn);
4032
if(copy_to_user(erq->pointer, pAdapter->nickn, erq->length))
4035
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCGIWNICKN\n");
4037
case SIOCSIWNICKN: //set node name/nickname
4038
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWNICKN\n");
4039
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCSIWNICKN\n");
4041
case SIOCGIWRATE: //get default bit rate (bps)
4042
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWRATE\n");
4043
wrq->u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.TxRate] * 1000000;
4044
wrq->u.bitrate.disabled = 0;
4045
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCGIWRATE\n");
4047
case SIOCSIWRATE: //set default bit rate (bps)
4048
DBGPRINT(RT_DEBUG_TEMP,"==>IOCTL::SIOCSIWRATE %d\n",wrq->u.bitrate.value);
4049
RT2570SetDesiredRates(pAdapter, wrq->u.bitrate.value);
4050
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCSIWRATE\n");
4052
case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
4053
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWRTS\n");
4054
wrq->u.rts.value = (INT) pAdapter->PortCfg.RtsThreshold;
4055
wrq->u.rts.disabled = (wrq->u.rts.value == MAX_RTS_THRESHOLD);
4056
wrq->u.rts.fixed = 1;
4057
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCGIWRTS\n");
4059
case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
4060
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWRTS\n");
4061
RtsThresh = wrq->u.rts.value;
4062
if (wrq->u.rts.disabled)
4063
RtsThresh = MAX_RTS_THRESHOLD;
4065
if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
4066
pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
4067
else if (RtsThresh == 0)
4068
pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
4070
DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCSIWRTS (=%d)\n", pAdapter->PortCfg.RtsThreshold);
4072
case SIOCGIWFRAG: //get fragmentation thr (bytes)
4073
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWFRAG\n");
4074
wrq->u.frag.value = (INT) pAdapter->PortCfg.FragmentThreshold;
4075
wrq->u.frag.disabled = (wrq->u.frag.value >= MAX_FRAG_THRESHOLD);
4076
wrq->u.frag.fixed = 1;
4077
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCGIWFRAG\n");
4079
case SIOCSIWFRAG: //set fragmentation thr (bytes)
4080
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWFRAG\n");
4081
FragThresh = wrq->u.frag.value;
4082
if (wrq->u.rts.disabled)
4083
FragThresh = MAX_FRAG_THRESHOLD;
4085
if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
4086
pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
4087
else if (FragThresh == 0)
4088
pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
4090
if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
4091
pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
4093
pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
4095
DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCSIWFRAG (=%d)\n", pAdapter->PortCfg.FragmentThreshold);
4097
case SIOCGIWENCODE: //get encoding token & mode
4098
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWENCODE\n");
4099
index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
4100
if ((index < 0) || (index >= NR_WEP_KEYS))
4101
index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
4103
if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeOpen)
4104
wrq->u.encoding.flags = IW_ENCODE_OPEN;
4105
else if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeShared)
4106
wrq->u.encoding.flags = IW_ENCODE_RESTRICTED;
4108
if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
4109
wrq->u.encoding.flags |= IW_ENCODE_DISABLED;
4112
if(wrq->u.encoding.pointer)
4114
wrq->u.encoding.length = pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen;
4115
if(copy_to_user(wrq->u.encoding.pointer,
4116
pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].Key,
4117
pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen))
4120
wrq->u.encoding.flags |= (pAdapter->PortCfg.DefaultKeyId + 1);
4123
DBGPRINT(RT_DEBUG_TEMP,"<==IOCTL::SIOCGIWENCODE , DefaultKeyId=%d\n", pAdapter->PortCfg.DefaultKeyId);
4125
case SIOCSIWENCODE: //set encoding token & mode
4126
index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
4127
DBGPRINT(RT_DEBUG_TEMP,"==>IOCTL::SIOCSIWENCODE index= %d\n",index);
4128
/* take the old default key if index is invalid */
4129
if((index < 0) || (index >= NR_WEP_KEYS))
4130
index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
4132
if((wrq->u.encoding.pointer) && ((wrq->u.encoding.flags & IW_ENCODE_NOKEY) == 0))
4134
printk(" !IW_ENCODE_NOKEY \n" );
4135
len = wrq->u.encoding.length;
4136
if(len > WEP_LARGE_KEY_LEN)
4137
len = WEP_LARGE_KEY_LEN;
4139
memset(pAdapter->PortCfg.SharedKey[index].Key, 0x00, MAX_LEN_OF_KEY);
4140
if(copy_from_user(pAdapter->PortCfg.SharedKey[index].Key, wrq->u.encoding.pointer, len))
4143
pAdapter->PortCfg.SharedKey[index].KeyLen = len <= WEP_SMALL_KEY_LEN ? WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
4145
if (wrq->u.encoding.flags & IW_ENCODE_DISABLED)
4146
pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
4148
pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
4150
if (wrq->u.encoding.flags & IW_ENCODE_RESTRICTED)
4151
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
4153
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
4155
if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
4156
pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
4158
if ((wrq->u.encoding.flags & IW_ENCODE_NOKEY) == 0)
4160
RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + index * 0x10), pAdapter->PortCfg.SharedKey[index].Key, 16);
4162
pAdapter->PortCfg.DefaultKeyId = (UCHAR) index;
4163
if ( (len == 5) ||( len == 10) )
4164
pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
4166
pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
4168
RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
4170
Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
4171
RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
4175
DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCSIWENCODE\n");
4177
case SIOCGIWAP: //get access point MAC addresses
4178
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWAP\n");
4179
DBGPRINT(RT_DEBUG_TEMP,"<==>IOCTL::SIOCGIWAP\n");
4181
case SIOCSIWAP: //set access point MAC addresses
4182
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWAP\n");
4183
memcpy(&Bssid, &wrq->u.ap_addr.sa_data, sizeof(NDIS_802_11_MAC_ADDRESS));
4184
if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4186
DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
4189
// tell CNTL state machine to call NdisMSetInformationComplete() after completing
4190
// this request, because this request is initiated by NDIS.
4191
pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
4193
MlmeEnqueue(pAdapter,
4194
MLME_CNTL_STATE_MACHINE,
4196
sizeof(NDIS_802_11_MAC_ADDRESS),
4198
Status = NDIS_STATUS_SUCCESS;
4199
StateMachineTouched = TRUE;
4200
DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
4201
Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]);
4202
DBGPRINT(RT_DEBUG_TEMP,"<==IOCTL::SIOCSIWAP\n");
4204
case SIOCGIWMODE: //get operation mode
4205
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWMODE\n");
4206
if (ADHOC_ON(pAdapter))
4208
BssType = Ndis802_11IBSS;
4209
wrq->u.mode = IW_MODE_ADHOC;
4211
else if (INFRA_ON(pAdapter))
4213
BssType = Ndis802_11Infrastructure;
4214
wrq->u.mode = IW_MODE_INFRA;
4218
BssType = Ndis802_11AutoUnknown;
4219
wrq->u.mode = IW_MODE_AUTO;
4221
DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCGIWMODE(=%d)\n", BssType);
4223
case SIOCSIWMODE: //set operation mode
4224
DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWMODE\n");
4225
DBGPRINT(RT_DEBUG_TEMP,"<==IOCTL::SIOCSIWMODE\n");
4227
case SIOCGIWSENS: //get sensitivity (dBm)
4228
case SIOCSIWSENS: //set sensitivity (dBm)
4229
case SIOCGIWPOWER: //get Power Management settings
4230
case SIOCSIWPOWER: //set Power Management settings
4231
case SIOCGIWTXPOW: //get transmit power (dBm)
4232
case SIOCSIWTXPOW: //set transmit power (dBm)
4233
DBGPRINT(RT_DEBUG_TRACE,"<==>IOCTL::multi not support\n");
4234
Status = -EOPNOTSUPP;
4237
DBGPRINT(RT_DEBUG_TEMP, "Query::SIOCGIWAPLIST (%d BSS returned)\n",pAdapter->PortCfg.BssTab.BssNr);
4238
DBGPRINT(RT_DEBUG_TEMP,"<==>WIRELESS_EXT=%d IOCTL::SIOCGIWAPLIST \n",WIRELESS_EXT);
4242
if (wrq->u.data.pointer) {
4243
if ( !access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) )
4245
wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
4246
if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
4251
DBGPRINT(RT_DEBUG_INFO, "IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd);
4252
Status = -EOPNOTSUPP;
4256
if(StateMachineTouched) // Upper layer sent a MLME-related operations
4257
RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));