~ubuntu-branches/ubuntu/precise/rt2570/precise

« back to all changes in this revision

Viewing changes to Module/rtusb_info.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno
  • Date: 2005-05-29 19:03:04 UTC
  • Revision ID: james.westby@ubuntu.com-20050529190304-2brtsi5bwy4wp3bo
Tags: upstream-1.1.0+cvs20060421
ImportĀ upstreamĀ versionĀ 1.1.0+cvs20060421

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************** 
 
2
 * RT2x00 SourceForge Project - http://rt2x00.sourceforge.net              * 
 
3
 *                                                                         * 
 
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.                                   * 
 
8
 *                                                                         * 
 
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.                          * 
 
13
 *                                                                         * 
 
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.             * 
 
18
 *                                                                         * 
 
19
 *   Licensed under the GNU GPL                                            * 
 
20
 *   Original code supplied under license from RaLink Inc, 2004.           * 
 
21
 ***************************************************************************/
 
22
 
 
23
/*************************************************************************
 
24
 *
 
25
 *      Module Name:    rtusb_info.c
 
26
 *
 
27
 *      Abstract:       
 
28
 *
 
29
 *      Revision History:
 
30
 *      Who             When            What
 
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
 *************************************************************************/
 
38
 
 
39
#include "rt_config.h"
 
40
#include <net/iw_handler.h>
 
41
 
 
42
 
 
43
#define NR_WEP_KEYS 4
 
44
#define WEP_SMALL_KEY_LEN (40/8)
 
45
#define WEP_LARGE_KEY_LEN (104/8)
 
46
 
 
47
 
 
48
#define     MAP_CHANNEL_ID_TO_KHZ(ch, khz)  {               \
 
49
                switch (ch)                                 \
 
50
                {                                           \
 
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;     \
 
93
                }                                           \
 
94
            }
 
95
 
 
96
#define         MAP_KHZ_TO_CHANNEL_ID(khz, ch)  {                               \
 
97
                                switch (khz)                                                            \
 
98
                                {                                                                                       \
 
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;         \
 
141
                                }                                                                                       \
 
142
                        }
 
143
 
 
144
 
 
145
#if 0
 
146
 
 
147
static struct {
 
148
        char *name;
 
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},
 
172
        {NULL,}
 
173
};
 
174
 
 
175
#endif
 
176
 
 
177
int
 
178
rtusb_ioctl_giwname(struct net_device *dev,
 
179
                   struct iw_request_info *info,
 
180
                   char *name, char *extra)
 
181
{
 
182
        strncpy(name, "RT2500USB WLAN", IFNAMSIZ);
 
183
        return 0;
 
184
}
 
185
 
 
186
int rtusb_ioctl_siwfreq(struct net_device *dev,
 
187
                        struct iw_request_info *info,
 
188
                        struct iw_freq *freq, char *extra)
 
189
{
 
190
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
191
        int     chan = -1;
 
192
 
 
193
        if (freq->e > 1)
 
194
                return -EINVAL;
 
195
 
 
196
        if((freq->e == 0) && (freq->m <= 1000))
 
197
                chan = freq->m; // Setting by channel number 
 
198
        else
 
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);
 
202
 
 
203
        // CD: setting the channel in Monitor mode is unrelated to RFMONTx
 
204
 
 
205
        if (pAdapter->PortCfg.BssType == BSS_MONITOR)
 
206
        {
 
207
                pAdapter->PortCfg.Channel = pAdapter->PortCfg.IbssConfig.Channel;
 
208
                AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
 
209
                AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
 
210
        }
 
211
 
 
212
        return 0;
 
213
}
 
214
int rtusb_ioctl_giwfreq(struct net_device *dev,
 
215
                   struct iw_request_info *info,
 
216
                   struct iw_freq *freq, char *extra)
 
217
{
 
218
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
219
        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::rtusb_ioctl_giwfreq  %d\n",pAdapter->PortCfg.Channel);
 
220
        
 
221
        if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
 
222
        {        
 
223
            MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, freq->m);
 
224
        }
 
225
        else
 
226
        {
 
227
                 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.IbssConfig.Channel, freq->m );
 
228
        }
 
229
        
 
230
        freq->e = 3;
 
231
        freq->i = 0;
 
232
        return 0;
 
233
}
 
234
 
 
235
int rtusb_ioctl_siwmode(struct net_device *dev,
 
236
                   struct iw_request_info *info,
 
237
                   __u32 *mode, char *extra)
 
238
{
 
239
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
240
 
 
241
        switch (*mode)
 
242
        {
 
243
                case IW_MODE_ADHOC:
 
244
                        if (pAdapter->PortCfg.BssType != BSS_INDEP)
 
245
                        {
 
246
                                // Config has changed
 
247
                                if INFRA_ON(pAdapter)
 
248
                                {
 
249
                                        RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
 
250
                                        // First cancel linkdown timer
 
251
                                        DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n");                                                   
 
252
                                }
 
253
                                pAdapter->bConfigChanged = TRUE;
 
254
                        }
 
255
                        pAdapter->net->type = 1;
 
256
                        pAdapter->PortCfg.BssType = BSS_INDEP;
 
257
                        DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (AD-HOC)\n");
 
258
                        break;
 
259
                case IW_MODE_INFRA:
 
260
                        if (pAdapter->PortCfg.BssType != BSS_INFRA)
 
261
                        {
 
262
                                // Config has changed
 
263
                                if (pAdapter->PortCfg.BssType != BSS_INFRA)
 
264
                                {
 
265
                                        // Config has changed
 
266
                                        // pAdapter->bConfigChanged = TRUE;
 
267
                                        if ADHOC_ON(pAdapter)
 
268
                                                RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
 
269
                                }
 
270
                                pAdapter->bConfigChanged = TRUE;
 
271
                        }
 
272
                        pAdapter->net->type = 1;
 
273
                        pAdapter->PortCfg.BssType = BSS_INFRA;
 
274
                        DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (INFRA)\n");
 
275
                        break;
 
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
 
283
                                else
 
284
                                        pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
285
                        } else {
 
286
                                if (pAdapter->PortCfg.ForcePrismHeader == 2)
 
287
                                        pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
288
                                else
 
289
                                        pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
 
290
                        }
 
291
                        RTUSBWriteMACRegister(pAdapter, TXRX_CSR2, 0x4e);
 
292
                        break;  
 
293
                default:
 
294
                        DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (unknown)\n");
 
295
                        return -EINVAL;
 
296
        }
 
297
        
 
298
        // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
 
299
        pAdapter->PortCfg.WpaState = SS_NOTUSE;
 
300
 
 
301
        return 0;
 
302
}
 
303
 
 
304
int rtusb_ioctl_giwmode(struct net_device *dev,
 
305
                   struct iw_request_info *info,
 
306
                   __u32 *mode, char *extra)
 
307
{
 
308
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
309
        if (pAdapter->PortCfg.BssType == BSS_MONITOR)
 
310
                *mode = IW_MODE_MONITOR;
 
311
        else
 
312
        {
 
313
                if (ADHOC_ON(pAdapter))
 
314
                        *mode = IW_MODE_ADHOC;
 
315
                else
 
316
                        *mode = IW_MODE_INFRA;
 
317
        }
 
318
        DBGPRINT(RT_DEBUG_TEMP,"--->rtusb_ioctl_giwmode\n");            
 
319
        return 0;
 
320
}
 
321
 
 
322
int rtusb_ioctl_siwsens(struct net_device *dev,
 
323
                   struct iw_request_info *info,
 
324
                   char *name, char *extra)
 
325
{
 
326
        return 0;
 
327
}
 
328
 
 
329
int rtusb_ioctl_giwsens(struct net_device *dev,
 
330
                   struct iw_request_info *info,
 
331
                   char *name, char *extra)
 
332
{
 
333
        return 0;
 
334
}
 
335
/*
 
336
This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
 
337
*/
 
338
int rtusb_ioctl_giwrange(struct net_device *dev,
 
339
                   struct iw_request_info *info,
 
340
                   struct iw_point *data, char *extra)
 
341
{
 
342
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
343
        struct iw_range *range = (struct iw_range *) extra;
 
344
        u16 val;
 
345
        int i;
 
346
        ULONG   m;
 
347
        
 
348
        data->length = sizeof(struct iw_range);
 
349
        memset(range, 0, sizeof(struct iw_range));
 
350
 
 
351
        range->txpower_capa = IW_TXPOW_DBM;
 
352
 
 
353
        if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
 
354
        {
 
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;
 
363
        }
 
364
        
 
365
 
 
366
        range->we_version_compiled = WIRELESS_EXT;
 
367
        range->we_version_source = 16;
 
368
 
 
369
        range->retry_capa = IW_RETRY_LIMIT;
 
370
        range->retry_flags = IW_RETRY_LIMIT;
 
371
        range->min_retry = 0;
 
372
        range->max_retry = 255;
 
373
 
 
374
        range->num_channels =  pAdapter->PortCfg.ChannelListNum;
 
375
 
 
376
        val = 0;
 
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;
 
381
                        val++;
 
382
                if (val == IW_MAX_FREQUENCIES)
 
383
                        break;
 
384
        }
 
385
        
 
386
        range->num_frequency = 0;
 
387
        for (i = 1; i <= range->num_channels; i++)
 
388
        {
 
389
                range->freq[range->num_frequency].i = i;
 
390
                MAP_CHANNEL_ID_TO_KHZ(i, m);
 
391
 
 
392
                range->freq[range->num_frequency].m = m;
 
393
                range->freq[range->num_frequency].e = 3;
 
394
                if (++range->num_frequency == IW_MAX_FREQUENCIES)
 
395
                break;
 
396
        }
 
397
 
 
398
        range->max_qual.qual = 100; /* percentage */ 
 
399
        range->max_qual.level = 0; /* dB */
 
400
        range->max_qual.noise = 0; /* dB */
 
401
 
 
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;
 
407
 
 
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;
 
412
 
 
413
#if 0
 
414
        over2 = 0;
 
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] =
 
420
                                rates[i] * 500000;
 
421
                        range->num_bitrates++;
 
422
                }
 
423
                if (rates[i] == 0x0b || rates[i] == 0x16)
 
424
                        over2 = 1;
 
425
        }
 
426
        /* estimated maximum TCP throughput values (bps) */
 
427
        range->throughput = over2 ? 5500000 : 1500000;
 
428
    #endif
 
429
        range->min_rts = 0;
 
430
        range->max_rts = 2347;
 
431
        range->min_frag = 256;
 
432
        range->max_frag = 2346;
 
433
 
 
434
        return 0;
 
435
}
 
436
 
 
437
int rtusb_ioctl_giwap(struct net_device *dev,
 
438
                      struct iw_request_info *info,
 
439
                      struct sockaddr *ap_addr, char *extra)
 
440
{
 
441
 
 
442
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
443
 
 
444
        if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
 
445
        {
 
446
                ap_addr->sa_family = ARPHRD_ETHER;
 
447
                memcpy(ap_addr->sa_data, &pAdapter->PortCfg.Bssid, ETH_ALEN);
 
448
        }
 
449
        else
 
450
        {
 
451
                DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=EMPTY)\n");
 
452
                return -ENOTCONN;
 
453
        }
 
454
 
 
455
        return 0;
 
456
}
 
457
 
 
458
/*
 
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.
 
462
 *
 
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
 
469
 * can be documented.
 
470
 *
 
471
 * NB: various calculations are based on the orinoco/wavelan
 
472
 *     drivers for compatibility
 
473
 */
 
474
static void
 
475
set_quality(struct iw_quality *iq, u_int rssi)
 
476
{
 
477
        iq->qual = rssi;
 
478
        /* NB: max is 94 because noise is hardcoded to 161 */
 
479
        if (iq->qual > 94)
 
480
                iq->qual = 94;
 
481
 
 
482
        iq->noise = RSSI_TO_DBM_OFFSET;         /* -95dBm */
 
483
        iq->level = iq->noise + iq->qual;
 
484
        iq->updated = 7;
 
485
}
 
486
int rtusb_ioctl_iwaplist(struct net_device *dev,
 
487
                        struct iw_request_info *info,
 
488
                        struct iw_point *data, char *extra)
 
489
{
 
490
 
 
491
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
492
        struct sockaddr addr[IW_MAX_AP];
 
493
        struct iw_quality qual[IW_MAX_AP];
 
494
        int i;
 
495
        
 
496
        for (i = 0; i <IW_MAX_AP ; i++)
 
497
        {
 
498
                if (i >=  pAdapter->PortCfg.BssTab.BssNr)
 
499
                        break;
 
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);
 
503
        }
 
504
        data->length = i;
 
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]));
 
508
 
 
509
        return 0;
 
510
}
 
511
#ifdef SIOCGIWSCAN
 
512
 
 
513
int rtusb_ioctl_siwscan(struct net_device *dev,
 
514
                        struct iw_request_info *info,
 
515
                        struct iw_point *data, char *extra)
 
516
{
 
517
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
518
        int Status = STATUS_SUCCESS;
 
519
 
 
520
        do{
 
521
                if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
 
522
                        return 0;
 
523
                if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
 
524
                        return 0;
 
525
 
 
526
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
 
527
                if ((pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (pAdapter->MLMEThr_pid > 0))
 
528
#else
 
529
                if ((pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) && (pAdapter->MLMEThr_active))
 
530
#endif
 
531
                {
 
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));
 
536
                        
 
537
                }
 
538
                 
 
539
                pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
 
540
                // Reset Missed scan number
 
541
                pAdapter->PortCfg.IgnoredScanNumber = 0;
 
542
 
 
543
                MlmeEnqueue(pAdapter, 
 
544
                                MLME_CNTL_STATE_MACHINE, 
 
545
                                OID_802_11_BSSID_LIST_SCAN, 
 
546
                                0, 
 
547
                                NULL);
 
548
                RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
 
549
 
 
550
                Status = NDIS_STATUS_SUCCESS;
 
551
        }while(0);
 
552
        return 0;
 
553
}
 
554
int
 
555
rtusb_ioctl_giwscan(struct net_device *dev,
 
556
                        struct iw_request_info *info,
 
557
                        struct iw_point *data, char *extra)
 
558
{
 
559
 
 
560
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
561
        int i=2, j;
 
562
        char *current_ev = extra;
 
563
        char *end_buf = extra + IW_SCAN_MAX_DATA;
 
564
        char *current_val;
 
565
        struct iw_event iwe;
 
566
 
 
567
        if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)){
 
568
                /*
 
569
                 * Still scanning, indicate the caller should try again.
 
570
                 */
 
571
                return -EAGAIN;
 
572
        }
 
573
 
 
574
        for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++) 
 
575
        {
 
576
                if (current_ev >= end_buf)
 
577
                        break;
 
578
 
 
579
                //================================
 
580
                memset(&iwe, 0, sizeof(iwe));
 
581
                iwe.cmd = SIOCGIWAP;
 
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)
 
589
                {
 
590
                        iwe.u.mode = IW_MODE_ADHOC;
 
591
                }
 
592
                else if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
 
593
                {
 
594
                        iwe.u.mode = IW_MODE_INFRA;
 
595
                }
 
596
                else
 
597
                {
 
598
                        iwe.u.mode = IW_MODE_AUTO;
 
599
                }
 
600
 
 
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;
 
614
                else
 
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);
 
617
 
 
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++)
 
624
                {
 
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,
 
629
                                IW_EV_PARAM_LEN);
 
630
                }
 
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;
 
636
                else
 
637
                        iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
 
638
                iwe.u.freq.e = 0;
 
639
                iwe.u.freq.i = 0;
 
640
                current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
 
641
                //================================
 
642
                memset(&iwe, 0, sizeof(iwe));
 
643
 
 
644
        }
 
645
        data->length = current_ev - extra;
 
646
        DBGPRINT(RT_DEBUG_TRACE,"rtusb_ioctl_giwscan. %d BSS returned\n",pAdapter->PortCfg.BssTab.BssNr);                                               
 
647
        return 0;
 
648
}
 
649
#endif
 
650
int rtusb_ioctl_siwessid(struct net_device *dev,
 
651
                         struct iw_request_info *info,
 
652
                         struct iw_point *data, char *essid)
 
653
{
 
654
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
655
        NDIS_802_11_SSID                                        Ssid, *pSsid=NULL;
 
656
 
 
657
        memset(&Ssid, 0x00, sizeof(NDIS_802_11_SSID));
 
658
        if (data->flags)
 
659
        {
 
660
                if (data->length > IW_ESSID_MAX_SIZE)
 
661
                {
 
662
                        return -E2BIG;
 
663
                }
 
664
 
 
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;
 
669
        }
 
670
        else
 
671
                Ssid.SsidLength = 0;  // ANY ssid 
 
672
 
 
673
        pSsid = &Ssid;
 
674
 
 
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)
 
681
#else
 
682
        if (!IS_ERR(pAdapter->MLMEThr))
 
683
#endif
 
684
                MlmeEnqueue(pAdapter, 
 
685
                                MLME_CNTL_STATE_MACHINE, 
 
686
                                OID_802_11_SSID,
 
687
                                sizeof(NDIS_802_11_SSID),
 
688
                                (VOID *)pSsid
 
689
                                );
 
690
 
 
691
        RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
 
692
        return 0;
 
693
}
 
694
 
 
695
int rtusb_ioctl_giwessid(struct net_device *dev,
 
696
                         struct iw_request_info *info,
 
697
                         struct iw_point *data, char *essid)
 
698
{
 
699
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
700
 
 
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);
 
707
 
 
708
        DBGPRINT(RT_DEBUG_TRACE, "<==rtusb_ioctl_giwessid:: (Len=%d, ssid=%s...)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
 
709
 
 
710
        return 0;
 
711
 
 
712
}
 
713
 
 
714
int rtusb_ioctl_siwnickn(struct net_device *dev,
 
715
                         struct iw_request_info *info,
 
716
                         struct iw_point *data, char *nickname)
 
717
{
 
718
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
719
 
 
720
        if (data->length > IEEE80211_NWID_LEN)
 
721
                return -EINVAL;
 
722
 
 
723
        memset(pAdapter->nickn, 0, IEEE80211_NWID_LEN);
 
724
        memcpy(pAdapter->nickn, nickname, data->length);
 
725
        pAdapter->nicknamelen = data->length;
 
726
 
 
727
 
 
728
        return 0;
 
729
}
 
730
 
 
731
int rtusb_ioctl_giwnickn(struct net_device *dev,
 
732
                         struct iw_request_info *info,
 
733
                         struct iw_point *data, char *nickname)
 
734
{
 
735
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
736
 
 
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';
 
742
        }
 
743
        return 0;
 
744
}
 
745
 
 
746
 
 
747
int rtusb_ioctl_siwrts(struct net_device *dev,
 
748
                       struct iw_request_info *info,
 
749
                       struct iw_param *rts, char *extra)
 
750
{
 
751
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
752
        u16 val;
 
753
 
 
754
        if (rts->disabled)
 
755
                val = MAX_RTS_THRESHOLD;
 
756
        else if (1 > rts->value || rts->value > MAX_RTS_THRESHOLD)
 
757
                return -EINVAL;
 
758
        else
 
759
                val = rts->value;
 
760
        
 
761
        if (val != pAdapter->PortCfg.RtsThreshold)
 
762
                pAdapter->PortCfg.RtsThreshold = val;
 
763
 
 
764
        return 0;
 
765
}
 
766
 
 
767
int rtusb_ioctl_giwrts(struct net_device *dev,
 
768
                       struct iw_request_info *info,
 
769
                       struct iw_param *rts, char *extra)
 
770
{
 
771
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
772
 
 
773
        rts->value = pAdapter->PortCfg.RtsThreshold;
 
774
        rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
 
775
        rts->fixed = 1;
 
776
 
 
777
        return 0;
 
778
}
 
779
 
 
780
 
 
781
int rtusb_ioctl_siwfrag(struct net_device *dev,
 
782
                        struct iw_request_info *info,
 
783
                        struct iw_param *rts, char *extra)
 
784
{
 
785
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
786
        u16 val;
 
787
 
 
788
        if (rts->disabled)
 
789
                val = MAX_FRAG_THRESHOLD;
 
790
        else if (rts->value < 256 || rts->value > MAX_FRAG_THRESHOLD)
 
791
                return -EINVAL;
 
792
        else
 
793
                val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
 
794
 
 
795
        pAdapter->PortCfg.FragmentThreshold = val;
 
796
        return 0;
 
797
}
 
798
 
 
799
int rtusb_ioctl_giwfrag(struct net_device *dev,
 
800
                        struct iw_request_info *info,
 
801
                        struct iw_param *rts, char *extra)
 
802
{
 
803
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
804
 
 
805
        rts->value = pAdapter->PortCfg.FragmentThreshold;
 
806
        rts->disabled = (rts->value == 2346);
 
807
        rts->fixed = 1;
 
808
 
 
809
        return 0;
 
810
}
 
811
 
 
812
int rtusb_ioctl_siwencode(struct net_device *dev,
 
813
                          struct iw_request_info *info,
 
814
                          struct iw_point *erq, char *extra)
 
815
{
 
816
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
817
        NDIS_802_11_WEP WepKey;
 
818
        int     index, len;
 
819
        CHAR    kid = 0;
 
820
        memset(&WepKey, 0, sizeof(NDIS_802_11_WEP));
 
821
 
 
822
        if (erq->flags & IW_ENCODE_DISABLED)
 
823
        {
 
824
                pAdapter->PortCfg.PairCipher = Ndis802_11WEPDisabled;
 
825
                pAdapter->PortCfg.GroupCipher = Ndis802_11WEPDisabled;
 
826
                pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
 
827
        }
 
828
        else
 
829
        {
 
830
                pAdapter->PortCfg.PairCipher = Ndis802_11WEPEnabled;
 
831
                pAdapter->PortCfg.GroupCipher = Ndis802_11WEPEnabled;
 
832
                pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
 
833
        }
 
834
 
 
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;
 
839
 
 
840
        if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
 
841
                pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
 
842
    
 
843
        if ((erq->flags & IW_ENCODE_DISABLED) == 0 && erq->pointer) 
 
844
        {
 
845
                /* Enable crypto. */
 
846
                if (erq->length > IFNAMSIZ)
 
847
                        return -EINVAL;
 
848
 
 
849
                /* Old solution to take  default key  */
 
850
                index = (erq->flags & IW_ENCODE_INDEX) ;
 
851
                if((index < 0) || (index > NR_WEP_KEYS))
 
852
                        return -EINVAL;     
 
853
                        DBGPRINT(RT_DEBUG_TRACE," erq->flags = %x\n",erq->flags);
 
854
                
 
855
                if (index != 0)
 
856
                {
 
857
                        pAdapter->PortCfg.DefaultKeyId = index -1;
 
858
                }
 
859
                
 
860
                if ((erq->length == 1) && (index == 0))
 
861
                {
 
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))
 
865
                                return -EINVAL;     
 
866
                        //WepKey.KeyIndex = 0x80000000 + index;
 
867
                        DBGPRINT(RT_DEBUG_TRACE,"kid = %d , erq->length = %d\n",kid, erq->length);
 
868
                        if (kid > 0)
 
869
                                pAdapter->PortCfg.DefaultKeyId = kid-1;
 
870
                        else 
 
871
                                pAdapter->PortCfg.DefaultKeyId = 0;
 
872
                }
 
873
                else
 
874
                {
 
875
                        DBGPRINT(RT_DEBUG_TRACE,"DefaultKeyId = %d , erq->length = %d, flags 0x%x\n",pAdapter->PortCfg.DefaultKeyId, erq->length,erq->flags);
 
876
                        len = erq->length;
 
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));
 
888
                }
 
889
                
 
890
        }
 
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);
 
894
        return 0;
 
895
}
 
896
 
 
897
int
 
898
rtusb_ioctl_giwencode(struct net_device *dev,
 
899
                          struct iw_request_info *info,
 
900
                          struct iw_point *erq, char *key)
 
901
{
 
902
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
903
        int kid;
 
904
        
 
905
        kid = erq->flags & IW_ENCODE_INDEX;
 
906
        DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX);
 
907
 
 
908
        if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
 
909
        {
 
910
                erq->length = 0;
 
911
                erq->flags = IW_ENCODE_DISABLED;
 
912
                return 0;
 
913
        }
 
914
 
 
915
        erq->flags = IW_ENCODE_ENABLED;
 
916
 
 
917
        if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeShared)
 
918
                erq->flags |= IW_ENCODE_RESTRICTED;
 
919
        else
 
920
                erq->flags |= IW_ENCODE_OPEN;
 
921
 
 
922
        if ((kid > 0) && (kid <=4))
 
923
        {
 
924
                // copy wep key
 
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);
 
929
        }
 
930
        else if (kid == 0)
 
931
        {
 
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);
 
936
        }
 
937
                
 
938
        return 0;
 
939
 
 
940
}
 
941
 
 
942
static int
 
943
rtusb_ioctl_setauth(struct net_device *dev, struct iw_request_info *info,
 
944
                         void *w, char *extra)
 
945
{
 
946
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
947
        int param = *(int *) extra;
 
948
  
 
949
        switch(param)
 
950
        {
 
951
                case 1:
 
952
                        pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
 
953
                        DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeOpen\n");
 
954
                        break;
 
955
                case 2:
 
956
                        pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
 
957
                        DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeShared\n");
 
958
                        break;
 
959
                case 3:
 
960
                        pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
 
961
                        pAdapter->PortCfg.WpaState = SS_START;
 
962
                        DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth RTPRIV802_11AuthModeWPAPSK\n");
 
963
                        break;
 
964
                case 4:
 
965
                        pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
 
966
                        DBGPRINT(RT_DEBUG_TRACE, "===>rtusb_ioctl_setauth Ndis802_11AuthModeWPANone\n");
 
967
                        break;
 
968
                default:
 
969
                        return -EOPNOTSUPP;
 
970
 
 
971
        }
 
972
 
 
973
 
 
974
        pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
 
975
 
 
976
        return 0;
 
977
}
 
978
#if 0
 
979
static int rtusb_ioctl_setkeyid(struct net_device *dev, struct iw_request_info *info,
 
980
                         void *w, char *extra)
 
981
{
 
982
 
 
983
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
984
        int param = *(int *)extra;
 
985
        USHORT  Value;
 
986
 
 
987
        switch(param)
 
988
        {
 
989
                case 1:
 
990
                        pAdapter->PortCfg.DefaultKeyId = 0;
 
991
                        break;
 
992
                case 2:
 
993
                        pAdapter->PortCfg.DefaultKeyId = 1;
 
994
                        break;
 
995
                case 3:
 
996
                        pAdapter->PortCfg.DefaultKeyId = 2;
 
997
                        break;
 
998
                case 4:
 
999
                        pAdapter->PortCfg.DefaultKeyId = 3;
 
1000
                        break;
 
1001
                default:
 
1002
                        return -EOPNOTSUPP;
 
1003
 
 
1004
        }
 
1005
 
 
1006
 
 
1007
        if (pAdapter->PortCfg.SharedKey[pAdapter->PortCfg.DefaultKeyId].KeyLen == 5)
 
1008
                pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
1009
        else
 
1010
                pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
1011
                                        
 
1012
        RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
1013
        Value &= 0xfe00;
 
1014
        Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
1015
        RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
1016
        
 
1017
        DBGPRINT(RT_DEBUG_TRACE, "===>DefaultKeyId = [%d]\n",pAdapter->PortCfg.DefaultKeyId);
 
1018
 
 
1019
        return 0;
 
1020
}
 
1021
#endif
 
1022
static int
 
1023
rtusb_ioctl_setencryp(struct net_device *dev, struct iw_request_info *info,
 
1024
                         void *w, char *extra)
 
1025
{
 
1026
 
 
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);
 
1033
        switch(param)
 
1034
        {
 
1035
                case 1:
 
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;
 
1041
                        break;
 
1042
                case 2:
 
1043
                        pAdapter->PortCfg.WepStatus= Ndis802_11Encryption1Enabled;
 
1044
                        pAdapter->PortCfg.PairCipher= Ndis802_11Encryption1Enabled;
 
1045
                        pAdapter->PortCfg.GroupCipher= Ndis802_11Encryption1Enabled;
 
1046
                        WepStatus = Ndis802_11Encryption1Enabled;
 
1047
                        break;
 
1048
                case 3:
 
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;
 
1054
                        break;
 
1055
                default:
 
1056
                        return -EOPNOTSUPP;
 
1057
 
 
1058
        }
 
1059
        RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_WEP_STATUS, TRUE, &WepStatus, sizeof(WepStatus));
 
1060
 
 
1061
        return 0;
 
1062
}
 
1063
static int
 
1064
rtusb_ioctl_setwpapsk(struct net_device *dev, struct iw_request_info *info,
 
1065
                         void *w, char *extra)
 
1066
{
 
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;
 
1074
        int     i;
 
1075
 
 
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)
 
1084
        {
 
1085
                if(copy_from_user(&keyMaterial2, iwp->pointer, iwp->length))
 
1086
                        Status = -EINVAL;
 
1087
 
 
1088
                PasswordHash(keyMaterial2, pAdapter->Mlme.CntlAux.Ssid, pAdapter->Mlme.CntlAux.SsidLen, keyMaterial);
 
1089
 
 
1090
                Key.Length    = sizeof(Key);
 
1091
                Key.KeyIndex  = 0x80000000;           
 
1092
                Key.KeyLength = 32;
 
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");
 
1097
 
 
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");
 
1104
 
 
1105
        }
 
1106
        else if (iwp->length == 64)
 
1107
        {
 
1108
                if(copy_from_user(&keyMaterial2, iwp->pointer, iwp->length))
 
1109
                        Status = -EINVAL;
 
1110
 
 
1111
                AtoH(Key.KeyMaterial, keyMaterial, 32);
 
1112
 
 
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");
 
1117
 
 
1118
                memcpy(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
 
1119
                memcpy(Key.KeyMaterial, keyMaterial, 32);
 
1120
 
 
1121
        }
 
1122
        
 
1123
        else
 
1124
                return -EOPNOTSUPP;
 
1125
 
 
1126
 
 
1127
        RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_KEY, TRUE, &Key, sizeof(Key));
 
1128
 
 
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
 
1134
        
 
1135
        return 0;
 
1136
 
 
1137
}
 
1138
 
 
1139
static int rtusb_ioctl_setrfmontx(struct net_device *dev,
 
1140
                                  struct iw_request_info *info,
 
1141
                                  struct iw_point *data, char *extra)
 
1142
{
 
1143
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
1144
        int param;
 
1145
        char value;     
 
1146
 
 
1147
        if (extra) { /* Change the state if there's param. */
 
1148
           param = *(int *)extra;
 
1149
           switch(param)
 
1150
           {
 
1151
             case 1:
 
1152
                pAdapter->PortCfg.MallowRFMONTx = TRUE;
 
1153
                if (pAdapter->PortCfg.ForcePrismHeader == 1)
 
1154
                        pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
 
1155
                else
 
1156
                        pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
1157
                break;
 
1158
             case 0:
 
1159
                pAdapter->PortCfg.MallowRFMONTx = FALSE;
 
1160
                if (pAdapter->PortCfg.ForcePrismHeader == 2)
 
1161
                        pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
1162
                else
 
1163
                        pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
 
1164
                break;
 
1165
             default:
 
1166
                return -EOPNOTSUPP;
 
1167
           }
 
1168
        }
 
1169
 
 
1170
        value = pAdapter->PortCfg.MallowRFMONTx == TRUE ? '1' : '0';
 
1171
 
 
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");
 
1175
 
 
1176
        return 0;
 
1177
}
 
1178
 
 
1179
static int rtusb_ioctl_setforceprismheader(struct net_device *dev,
 
1180
                                  struct iw_request_info *info,
 
1181
                                  struct iw_point *data, char *extra)
 
1182
{
 
1183
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
1184
        int param = *(int *)extra;
 
1185
 
 
1186
        switch(param)
 
1187
        {
 
1188
        case 0:
 
1189
                pAdapter->PortCfg.ForcePrismHeader = 0;
 
1190
                if (pAdapter->PortCfg.MallowRFMONTx == TRUE)
 
1191
                        pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
1192
                else
 
1193
                        pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
 
1194
                break;
 
1195
        case 1:
 
1196
                pAdapter->PortCfg.ForcePrismHeader = 1;
 
1197
                pAdapter->net->type = 802; // ARPHRD_IEEE80211_PRISM
 
1198
                break;
 
1199
        case 2:
 
1200
                pAdapter->PortCfg.ForcePrismHeader = 2;
 
1201
                pAdapter->net->type = 801; // ARPHRD_IEEE80211
 
1202
                break;
 
1203
        default:
 
1204
                return -EOPNOTSUPP;
 
1205
        }
 
1206
 
 
1207
        return 0;
 
1208
}
 
1209
 
 
1210
static int rtusb_ioctl_setadhocmode(struct net_device *dev,
 
1211
                                  struct iw_request_info *info,
 
1212
                                  struct iw_point *data, char *extra)
 
1213
{
 
1214
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
1215
        int param = *(int *)extra;
 
1216
 
 
1217
        switch(param)
 
1218
        {
 
1219
        case 0:
 
1220
                        pAdapter->PortCfg.AdhocMode = 0;
 
1221
                        break;
 
1222
                case 1:
 
1223
                        pAdapter->PortCfg.AdhocMode = 1;
 
1224
                        break;
 
1225
                case 2:
 
1226
                        pAdapter->PortCfg.AdhocMode = 2;
 
1227
                break;
 
1228
                default:
 
1229
                        return -EOPNOTSUPP;
 
1230
        }
 
1231
 
 
1232
        return 0;
 
1233
}
 
1234
 
 
1235
static int rtusb_ioctl_setpsm(struct net_device *dev, struct iw_request_info *info,
 
1236
                         void *w, char *extra)
 
1237
{
 
1238
 
 
1239
        PRT2570ADAPTER pAdapter = (PRT2570ADAPTER) dev->priv;
 
1240
        int param = *(int *)extra;
 
1241
 
 
1242
        switch(param)
 
1243
        {
 
1244
                case 0:
 
1245
                        // clear PSM bit immediately
 
1246
                        MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
 
1247
                        pAdapter->PortCfg.RecvDtim = TRUE;
 
1248
                        pAdapter->PortCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
 
1249
                        break;
 
1250
        
 
1251
                case 1:
 
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;
 
1257
                        break;
 
1258
                        
 
1259
                default:
 
1260
                        return -EOPNOTSUPP;
 
1261
 
 
1262
        }
 
1263
    
 
1264
        return 0;
 
1265
 
 
1266
}
 
1267
static const iw_handler rtusb_handler[] =
 
1268
{
 
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 */
 
1293
#ifdef SIOCGIWSCAN
 
1294
        (iw_handler) rtusb_ioctl_siwscan,               /* SIOCSIWSCAN          0x18*/
 
1295
        (iw_handler) rtusb_ioctl_giwscan,               /* SIOCGIWSCAN */
 
1296
#else
 
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*/
 
1320
};
 
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 */
 
1329
};
 
1330
 
 
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  
 
1340
        { RTPRIV_IOCTL_PSM, 
 
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"},
 
1349
#if 0
 
1350
        { RTPRIV_IOCTL_BBP,
 
1351
          IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
 
1352
          "bbp"},
 
1353
        { RTPRIV_IOCTL_MAC,
 
1354
          IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
 
1355
          "mac"}
 
1356
#endif
 
1357
};
 
1358
 
 
1359
const struct iw_handler_def rt2500usb_iw_handler_def =
 
1360
{
 
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,
 
1368
};
 
1369
 
 
1370
INT RTMPQueryInformation(
 
1371
        IN      PRT2570ADAPTER pAdapter,
 
1372
        IN      OUT struct ifreq        *rq,
 
1373
        IN      INT                             cmd)
 
1374
{
 
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;
 
1390
        ULONG                                                           BssBufSize;
 
1391
        ULONG                                                           BssLen;
 
1392
        ULONG                                                           ulInfo = 0;
 
1393
        PUCHAR                                                          pBuf = NULL;
 
1394
        PUCHAR                                                          pPtr;
 
1395
        INT                                                             Status = NDIS_STATUS_SUCCESS;
 
1396
        UCHAR                                                           Padding;
 
1397
        UINT                                                            i;
 
1398
        BOOLEAN                                                         RadioState;
 
1399
        UCHAR                         LastR17Value;
 
1400
 
 
1401
        
 
1402
        switch(cmd) {
 
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))
 
1407
                                Status = -EFAULT;
 
1408
 
 
1409
                        break;
 
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))
 
1421
                                Status = -EFAULT;
 
1422
 
 
1423
                        break;
 
1424
                case OID_802_11_BSSID_LIST:
 
1425
                
 
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);
 
1429
                        
 
1430
                        for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++) 
 
1431
                        {
 
1432
                                // Align pointer to 4 bytes boundary.
 
1433
                                Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
 
1434
                                if (Padding == 4)
 
1435
                                        Padding = 0;
 
1436
                                BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding);
 
1437
                        }
 
1438
 
 
1439
                        // For safety issue, we add 256 bytes just in case
 
1440
                        BssBufSize += 256;
 
1441
                        // Allocate the same size as passed from higher layer
 
1442
                        pBuf = kmalloc(BssBufSize, GFP_KERNEL);
 
1443
                        if(pBuf == NULL)
 
1444
                        {
 
1445
                                Status = -ENOMEM;
 
1446
                                break;
 
1447
                        }
 
1448
                        // Init 802_11_BSSID_LIST_EX structure
 
1449
                        memset(pBuf, 0, BssBufSize);
 
1450
 
 
1451
                        
 
1452
                        pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
 
1453
                        pBssidList->NumberOfItems = pAdapter->PortCfg.BssTab.BssNr;
 
1454
                        
 
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++) 
 
1461
                        {
 
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)
 
1465
                                {
 
1466
                                        pBss->Ssid.SsidLength = 0;
 
1467
                                }
 
1468
                                else
 
1469
                                {
 
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);
 
1472
                                }
 
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;
 
1484
 
 
1485
                                MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.BssTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
 
1486
 
 
1487
                                if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == BSS_INFRA) 
 
1488
                                        pBss->InfrastructureMode = Ndis802_11Infrastructure;
 
1489
                                else
 
1490
                                        pBss->InfrastructureMode = Ndis802_11IBSS;
 
1491
 
 
1492
                                memcpy(pBss->SupportedRates, pAdapter->PortCfg.BssTab.BssEntry[i].Rates, pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen);
 
1493
 
 
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);
 
1496
 
 
1497
                                if (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen == 0)
 
1498
                                {
 
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);
 
1502
                                }
 
1503
                                else
 
1504
                                {
 
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;
 
1510
                                }
 
1511
                                // Align pointer to 4 bytes boundary.
 
1512
                                Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
 
1513
                                if (Padding == 4)
 
1514
                                        Padding = 0;
 
1515
                                pPtr += Padding;
 
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;
 
1518
                        }
 
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);
 
1521
 
 
1522
                        if(copy_to_user(wrq->u.data.pointer, pBssidList, wrq->u.data.length))
 
1523
                                Status = -EFAULT;
 
1524
 
 
1525
                        kfree(pBssidList);
 
1526
                        break;
 
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))
 
1530
                                Status = -EFAULT;
 
1531
 
 
1532
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->PortCfg.TxPower);
 
1533
                        break;
 
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))
 
1537
                                Status = -EFAULT;
 
1538
 
 
1539
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_3_CURRENT_ADDRESS \n");
 
1540
                        break;
 
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))
 
1545
                                Status = -EFAULT;
 
1546
 
 
1547
                        break;
 
1548
                case OID_802_11_BSSID:
 
1549
                        if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
 
1550
                        {
 
1551
                                if(copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.Bssid, sizeof(MACADDR)))
 
1552
                                        Status = -EFAULT;
 
1553
 
 
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]);
 
1557
 
 
1558
                        }
 
1559
                        else
 
1560
                        {
 
1561
                                DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_BSSID(=EMPTY)\n");
 
1562
                                Status = -ENOTCONN;
 
1563
                        }
 
1564
                        break;
 
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))
 
1571
                                Status = -EFAULT;
 
1572
 
 
1573
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid);
 
1574
                        break;
 
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))
 
1582
                                Status = -EFAULT;
 
1583
 
 
1584
                        DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_LINK_STATUS\n");
 
1585
                        break;
 
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);}
 
1592
                        else
 
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))
 
1596
                                Status = -EFAULT;
 
1597
 
 
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);
 
1600
                        break;
 
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))
 
1605
                                Status = -EFAULT;
 
1606
 
 
1607
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RSSI(=%d)\n", ulInfo);
 
1608
                        break;
 
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))
 
1613
                                Status = -EFAULT;
 
1614
 
 
1615
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RSSI_TRIGGER(=%d)\n", ulInfo);
 
1616
                        break;
 
1617
                case OID_802_11_STATISTICS:
 
1618
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_STATISTICS \n");
 
1619
                        // Update FCS counters
 
1620
 
 
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;
 
1624
 
 
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))
 
1639
                                Status = -EFAULT;
 
1640
 
 
1641
                        break;
 
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))
 
1647
                                Status = -EFAULT;
 
1648
 
 
1649
                        break;
 
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))
 
1655
                                Status = -EFAULT;
 
1656
 
 
1657
                        break;
 
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))
 
1662
                                Status = -EFAULT;
 
1663
 
 
1664
                        DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_PHY_MODE (=%d)\n", ulInfo);
 
1665
                        break;
 
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))
 
1670
                                Status = -EFAULT;
 
1671
 
 
1672
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_RTS_THRESHOLD(=%d)\n", RtsThresh);
 
1673
                        break;
 
1674
                case OID_802_11_FRAGMENTATION_THRESHOLD:
 
1675
                        FragThresh = pAdapter->PortCfg.FragmentThreshold;
 
1676
                        if (pAdapter->PortCfg.bFragmentZeroDisable == TRUE)
 
1677
                                FragThresh = 0;
 
1678
                        wrq->u.data.length = sizeof(FragThresh);
 
1679
                        if(copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length))
 
1680
                                Status = -EFAULT;
 
1681
 
 
1682
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%d)\n", FragThresh);
 
1683
                        break;
 
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))
 
1688
                                Status = -EFAULT;
 
1689
 
 
1690
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode);
 
1691
                        break;
 
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))
 
1696
                                Status = -EFAULT;
 
1697
 
 
1698
                        DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState);
 
1699
                        break;
 
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;
 
1705
                        else
 
1706
                                BssType = Ndis802_11AutoUnknown;
 
1707
 
 
1708
                        wrq->u.data.length = sizeof(BssType);
 
1709
                        if(copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length))
 
1710
                                Status = -EFAULT;
 
1711
 
 
1712
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType);
 
1713
                        break;
 
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))
 
1718
                                Status = -EFAULT;
 
1719
 
 
1720
                        DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType);
 
1721
                        break;
 
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))
 
1726
                                Status = -EFAULT;
 
1727
 
 
1728
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode);
 
1729
                        break;
 
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))
 
1734
                                Status = -EFAULT;
 
1735
 
 
1736
                        DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus);
 
1737
                        break;
 
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))
 
1742
                                Status = -EFAULT;
 
1743
 
 
1744
                        DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", LastR17Value);
 
1745
                        break;
 
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))
 
1749
                                Status = -EFAULT;
 
1750
 
 
1751
                    DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_802_11_EXTRA_INFO (=%d)\n", pAdapter->ExtraInfo);
 
1752
                    break;
 
1753
                default:
 
1754
                        DBGPRINT(RT_DEBUG_TRACE, "Query::unknown IOCTL's subcmd = 0x%08x\n", cmd);
 
1755
                        Status = -EOPNOTSUPP;
 
1756
                        break;
 
1757
        }
 
1758
 
 
1759
        return Status;
 
1760
}
 
1761
 
 
1762
 
 
1763
 
 
1764
INT RTMPSetInformation(
 
1765
        IN      PRT2570ADAPTER pAdapter,
 
1766
        IN      OUT struct ifreq        *rq,
 
1767
        IN      INT                             cmd)
 
1768
{
 
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;
 
1785
        ULONG                                                           Now;
 
1786
        ULONG                                                           KeyIdx;
 
1787
        INT                                                             Status = NDIS_STATUS_SUCCESS;
 
1788
        UCHAR                                                           CountryRegion;
 
1789
        BOOLEAN                                                         RadioState;
 
1790
        NDIS_802_11_PRIVACY_FILTER           Filter;
 
1791
        NDIS_802_11_RSSI                     RssiTrigger;
 
1792
        
 
1793
        DBGPRINT(RT_DEBUG_INFO, "Set::RTMPSetInformation \n");
 
1794
        
 
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))
 
1799
                                Status  = -EINVAL;
 
1800
                        else
 
1801
                        {
 
1802
                                if(copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length))
 
1803
                                        Status = -EINVAL;
 
1804
 
 
1805
                                pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
 
1806
                                Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_BSSID, TRUE, &Bssid, wrq->u.data.length);
 
1807
                                                                        
 
1808
                        }
 
1809
                        break;
 
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))
 
1813
                                Status = -EINVAL;
 
1814
                        else
 
1815
                        {
 
1816
                                if(copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length))
 
1817
                                        Status = -EINVAL;
 
1818
                                        
 
1819
                                pSsid = &Ssid;
 
1820
 
 
1821
                                if (pSsid->SsidLength > MAX_LEN_OF_SSID)
 
1822
                                        Status = -EINVAL;
 
1823
                                else
 
1824
                                {
 
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);
 
1827
                                }
 
1828
                        }
 
1829
                        break;
 
1830
                case OID_802_11_INFRASTRUCTURE_MODE:
 
1831
                        if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
 
1832
                                Status  = -EINVAL;
 
1833
                        else
 
1834
                        {
 
1835
                                if(copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length))
 
1836
                                        Status = -EINVAL;
 
1837
 
 
1838
                                if (BssType == Ndis802_11IBSS) 
 
1839
                                {
 
1840
                                        if (pAdapter->PortCfg.BssType != BSS_INDEP)
 
1841
                                        {
 
1842
                                                // Config has changed
 
1843
                                                if INFRA_ON(pAdapter)
 
1844
                                                {
 
1845
                                                        RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
 
1846
                                                        // First cancel linkdown timer
 
1847
                                                        DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n");                                                   
 
1848
                                                }
 
1849
                                        }
 
1850
                                        pAdapter->PortCfg.BssType = BSS_INDEP;
 
1851
                                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (AD-HOC)\n");
 
1852
                                }
 
1853
                                else if (BssType == Ndis802_11Infrastructure) 
 
1854
                                {
 
1855
                                        if (pAdapter->PortCfg.BssType != BSS_INFRA)
 
1856
                                        {
 
1857
                                                // Config has changed
 
1858
                                                // pAdapter->bConfigChanged = TRUE;
 
1859
                                                if ADHOC_ON(pAdapter)
 
1860
                                                        RTUSBEnqueueInternalCmd(pAdapter, RT_OID_LINK_DOWN);
 
1861
                                        }
 
1862
                                        pAdapter->PortCfg.BssType = BSS_INFRA;
 
1863
                                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (INFRA)\n");
 
1864
                                }
 
1865
                                else
 
1866
                                {
 
1867
                                        Status  = -EINVAL;
 
1868
                                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n");
 
1869
                                }
 
1870
                        }
 
1871
                        // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
 
1872
                        pAdapter->PortCfg.WpaState = SS_NOTUSE;
 
1873
                        break;
 
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))
 
1877
                                Status = -EINVAL;
 
1878
                                        
 
1879
                        if (Key.Length != wrq->u.data.length)
 
1880
                        {
 
1881
                                Status  = -EINVAL;
 
1882
                                DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY, Failed!!\n");
 
1883
                        }
 
1884
                        else
 
1885
                        {
 
1886
                                if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
 
1887
                                {
 
1888
                                        Status = RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_ADD_KEY, TRUE, &Key, wrq->u.data.length);
 
1889
                                }
 
1890
                                else    // Old WEP stuff
 
1891
                                {
 
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);
 
1896
 
 
1897
                                }
 
1898
                                DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", Key.KeyIndex, Key.KeyLength);
 
1899
                        }
 
1900
                        break;
 
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))
 
1905
                                Status = -EINVAL;
 
1906
                                        
 
1907
                        if (pRemoveKey->Length != wrq->u.data.length)
 
1908
                        {
 
1909
                                Status  = -EINVAL;
 
1910
                                DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!\n");
 
1911
                        }
 
1912
                        else
 
1913
                        {
 
1914
                                if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
 
1915
                                {
 
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");
 
1918
                                }
 
1919
                                else
 
1920
                                {
 
1921
                                        KeyIdx = pRemoveKey->KeyIndex;
 
1922
 
 
1923
                                        if (KeyIdx & 0x80000000)
 
1924
                                        {
 
1925
                                                // Should never set default bit when remove key
 
1926
                                                Status  = -EINVAL;
 
1927
                                                DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n");
 
1928
                                        }
 
1929
                                        else
 
1930
                                        {
 
1931
                                                KeyIdx = KeyIdx & 0x0fffffff;
 
1932
                                                if (KeyIdx > 3)
 
1933
                                                {
 
1934
                                                        Status  = -EINVAL;
 
1935
                                                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx);
 
1936
                                                }
 
1937
                                                else
 
1938
                                                {
 
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);
 
1941
                                                }
 
1942
                                        }
 
1943
                                }
 
1944
                        }
 
1945
                        kfree(pRemoveKey);
 
1946
                        break;
 
1947
                case OID_802_11_AUTHENTICATION_MODE:
 
1948
                        if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE)) 
 
1949
                                Status  = -EINVAL;
 
1950
                        else
 
1951
                        {
 
1952
                                if(copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length))
 
1953
                                        Status = -EINVAL;
 
1954
                                        
 
1955
                                if (AuthMode > Ndis802_11AuthModeMax)
 
1956
                                {
 
1957
                                        Status  = -EINVAL;
 
1958
                                        break;
 
1959
                                }
 
1960
                                else
 
1961
                                {
 
1962
                                        if (pAdapter->PortCfg.AuthMode != AuthMode)
 
1963
                                        {
 
1964
                                                // Config has changed
 
1965
                                                pAdapter->bConfigChanged = TRUE;
 
1966
                                        }
 
1967
                                        pAdapter->PortCfg.AuthMode = AuthMode;
 
1968
                                }
 
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);
 
1971
                        }
 
1972
                        break;
 
1973
                case OID_802_11_PRIVACY_FILTER:
 
1974
                        if (wrq->u.data.length != sizeof(NDIS_802_11_PRIVACY_FILTER))
 
1975
                                Status = -EINVAL;
 
1976
                        else 
 
1977
                        {
 
1978
                                if(copy_from_user(&Filter, wrq->u.data.pointer, wrq->u.data.length))
 
1979
                                        Status = -EINVAL;
 
1980
                                        
 
1981
                                if ((Filter == Ndis802_11PrivFilterAcceptAll) || (Filter == Ndis802_11PrivFilter8021xWEP))
 
1982
                                        pAdapter->PortCfg.PrivacyFilter = Filter;
 
1983
                                else
 
1984
                                        Status = -EINVAL;
 
1985
                        }
 
1986
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_PRIVACY_FILTER (=%d) \n",pAdapter->PortCfg.PrivacyFilter);
 
1987
                        break;
 
1988
                case OID_802_11_BSSID_LIST_SCAN:
 
1989
                        Now = jiffies;
 
1990
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID_LIST_SCAN \n");
 
1991
 
 
1992
 
 
1993
                        if (pAdapter->ScanAllowed == FALSE)
 
1994
                        {
 
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;
 
1998
                        }
 
1999
 
 
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))
 
2004
                        {
 
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;
 
2007
                                break;
 
2008
                        }
 
2009
 
 
2010
                        Status =RTUSBEnqueueCmdFromNdis(pAdapter, OID_802_11_BSSID_LIST_SCAN, TRUE, NULL, 0);
 
2011
                                        break;
 
2012
                case OID_802_11_WEP_STATUS:
 
2013
                        if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
 
2014
                                Status  = -EINVAL;
 
2015
                        else
 
2016
                        {
 
2017
                                if(copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length))
 
2018
                                        Status = -EINVAL;
 
2019
 
 
2020
                                // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
 
2021
                                if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
 
2022
                                {
 
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;
 
2028
                                }
 
2029
 
 
2030
                                DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus);
 
2031
                        }
 
2032
                        break;
 
2033
                case OID_802_11_TX_POWER_LEVEL:
 
2034
                        if (wrq->u.data.length != sizeof(NDIS_802_11_TX_POWER_LEVEL))
 
2035
                                Status  = -EINVAL;
 
2036
                        else
 
2037
                        {
 
2038
                                if(copy_from_user(&TxPowerLevel, wrq->u.data.pointer, wrq->u.data.length))
 
2039
                                        Status = -EINVAL;
 
2040
 
 
2041
                                if (TxPowerLevel > MAX_TX_POWER_LEVEL)
 
2042
                                        Status  = -EINVAL;
 
2043
                                else
 
2044
                                        pAdapter->PortCfg.TxPower = (UCHAR)TxPowerLevel;
 
2045
                        }
 
2046
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_TX_POWER_LEVEL (=%d) \n",TxPowerLevel);
 
2047
                        break;
 
2048
                case OID_802_11_RSSI_TRIGGER:
 
2049
                        if (wrq->u.data.length != sizeof(NDIS_802_11_RSSI))
 
2050
                                Status = -EINVAL;
 
2051
                        else 
 
2052
                        {
 
2053
                                if(copy_from_user(&RssiTrigger, wrq->u.data.pointer, wrq->u.data.length))
 
2054
                                        Status = -EINVAL;
 
2055
 
 
2056
                                if (RssiTrigger > MAX_RSSI_TRIGGER || RssiTrigger < MIN_RSSI_TRIGGER) 
 
2057
                                        Status = -EINVAL;
 
2058
                                else
 
2059
                                {
 
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;
 
2063
                                        else
 
2064
                                                pAdapter->PortCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD;
 
2065
                                }
 
2066
                        }
 
2067
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RSSI_TRIGGER (=%d)\n",RssiTrigger);
 
2068
                        break;
 
2069
                case OID_802_11_FRAGMENTATION_THRESHOLD:
 
2070
                        if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
 
2071
                                Status  = -EINVAL;
 
2072
                        else
 
2073
                        {
 
2074
                                if(copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length))
 
2075
                                        Status = -EINVAL;
 
2076
 
 
2077
                                pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
 
2078
                                if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
 
2079
                                {
 
2080
                                        if (FragThresh == 0)
 
2081
                                        {
 
2082
                                                pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
 
2083
                                                pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
 
2084
                                        }
 
2085
                                        else
 
2086
                                                Status  = -EINVAL;
 
2087
                                }
 
2088
                                else
 
2089
                                        pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
 
2090
                        }
 
2091
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%d) \n",FragThresh);
 
2092
                        break;
 
2093
                case OID_802_11_RTS_THRESHOLD:
 
2094
                        if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
 
2095
                                Status  = -EINVAL;
 
2096
                        else
 
2097
                        {
 
2098
                                if(copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length))
 
2099
                                        Status = -EINVAL;
 
2100
 
 
2101
                                if (RtsThresh > MAX_RTS_THRESHOLD)
 
2102
                                        Status  = -EINVAL;
 
2103
                                else
 
2104
                                        pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
 
2105
                        }
 
2106
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RTS_THRESHOLD (=%d)\n",RtsThresh);
 
2107
                        break;
 
2108
                case OID_802_11_DESIRED_RATES:
 
2109
                        if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
 
2110
                                Status  = -EINVAL;
 
2111
                        else
 
2112
                        {
 
2113
                                if(copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length))
 
2114
                                        Status = -EINVAL;
 
2115
 
 
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);
 
2125
                        }
 
2126
                        break;
 
2127
                case OID_802_11_CONFIGURATION:
 
2128
                        if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
 
2129
                                Status  = -EINVAL;
 
2130
                        else
 
2131
                        {
 
2132
                                if(copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length))
 
2133
                                        Status = -EINVAL;
 
2134
 
 
2135
                                pConfig = &Config;
 
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;
 
2143
                        }
 
2144
                        break;
 
2145
                case OID_802_11_POWER_MODE:
 
2146
                        if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
 
2147
                                Status = -EINVAL;
 
2148
                        else
 
2149
                        {
 
2150
                                if(copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length))
 
2151
                                        Status = -EINVAL;
 
2152
 
 
2153
                                // save user's policy here, but not change PortCfg.Psm immediately
 
2154
                                if (PowerMode == Ndis802_11PowerModeCAM) 
 
2155
                                {
 
2156
                                        // clear PSM bit immediately
 
2157
                                        MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
 
2158
                                        pAdapter->PortCfg.RecvDtim = TRUE;
 
2159
                                        pAdapter->PortCfg.WindowsPowerMode = PowerMode;
 
2160
                                }
 
2161
                                else if (PowerMode == Ndis802_11PowerModeMAX_PSP) 
 
2162
                                {
 
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;
 
2169
                                }
 
2170
                                else if (PowerMode == Ndis802_11PowerModeFast_PSP) 
 
2171
                                {
 
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;
 
2178
                                }
 
2179
                                else
 
2180
                                        Status = -EINVAL;
 
2181
                        }
 
2182
                        DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode);
 
2183
                        break;
 
2184
                case RT_OID_802_11_PREAMBLE:
 
2185
                        if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
 
2186
                                Status  = -EINVAL;
 
2187
                        else
 
2188
                        {
 
2189
                                if(copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length))
 
2190
                                        Status = -EINVAL;
 
2191
 
 
2192
                                if ((Preamble == Rt802_11PreambleShort) || (Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
 
2193
                                {
 
2194
                                        Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_PREAMBLE, TRUE, &Preamble, sizeof(RT_802_11_PREAMBLE));
 
2195
                                }
 
2196
                                else
 
2197
                                {
 
2198
                                        Status = EINVAL;
 
2199
                                        break;
 
2200
                                }
 
2201
                                DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_SET_PREAMBLE (=%d)\n", Preamble);
 
2202
                        }
 
2203
                        break;
 
2204
                case RT_OID_802_11_RADIO:
 
2205
                        if (wrq->u.data.length != sizeof(BOOLEAN))
 
2206
                                Status  = -EINVAL;
 
2207
                        else
 
2208
                        {
 
2209
                                Status  = -EINVAL;
 
2210
                                if(copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length))
 
2211
                                        Status = -EINVAL;
 
2212
 
 
2213
                                DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_RADIO (=%d)\n", RadioState);
 
2214
                                if (pAdapter->PortCfg.bSwRadio != RadioState)
 
2215
                                {
 
2216
                                        pAdapter->PortCfg.bSwRadio = RadioState;
 
2217
                                        if (pAdapter->PortCfg.bRadio != (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio))
 
2218
                                        {
 
2219
                                                pAdapter->PortCfg.bRadio = (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio);
 
2220
                                                Status = RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_SET_RADIO, TRUE, NULL, 0);
 
2221
                                        }
 
2222
                                }
 
2223
                        }
 
2224
                        break;
 
2225
                case RT_OID_802_11_COUNTRY_REGION:
 
2226
                        if (wrq->u.data.length != sizeof(CountryRegion))
 
2227
                                Status = -EINVAL;
 
2228
                        else if (!(pAdapter->PortCfg.CountryRegion & 0x80))     // Only avaliable when EEPROM not programming
 
2229
                        {
 
2230
                                ULONG   TmpPhy;
 
2231
                                
 
2232
                                if(copy_from_user(&pAdapter->PortCfg.CountryRegion, wrq->u.data.pointer, wrq->u.data.length))
 
2233
                                        Status = -EINVAL;
 
2234
 
 
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);
 
2240
                        }
 
2241
                        break;
 
2242
                case RT_OID_802_11_PHY_MODE:
 
2243
                        if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
 
2244
                                Status  = -EINVAL;
 
2245
                        else
 
2246
                        {
 
2247
                                if(copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length))
 
2248
                                        Status = -EINVAL;
 
2249
 
 
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);
 
2252
                        }
 
2253
                        break;
 
2254
                case RT_OID_802_11_STA_CONFIG:
 
2255
                        if (wrq->u.data.length  != sizeof(RT_802_11_STA_CONFIG))
 
2256
                        {
 
2257
                                Status  = -EINVAL;
 
2258
                        }
 
2259
                        else 
 
2260
                        {
 
2261
                                Status =  (RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_STA_CONFIG, TRUE, wrq->u.data.pointer, sizeof(RT_802_11_STA_CONFIG)));
 
2262
                        }
 
2263
                        break;
 
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));
 
2269
                         {
 
2270
                                return(RTUSBEnqueueCmdFromNdis(pAdapter, RT_OID_802_11_RESET_COUNTERS, TRUE, NULL, 0));
 
2271
                         }
 
2272
                        DBGPRINT(RT_DEBUG_INFO, "Set::RT_OID_802_11_RESET_COUNTERS \n");
 
2273
                        break;
 
2274
#if 1
 
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))  
 
2279
                                Status = -EINVAL;
 
2280
                        else
 
2281
                       {
 
2282
                                if(copy_from_user(&Key, wrq->u.data.pointer, wrq->u.data.length))
 
2283
                                        Status = -EINVAL;
 
2284
 
 
2285
                                if (Key.Length != wrq->u.data.length)
 
2286
                                {
 
2287
                                        Status  = -EINVAL;
 
2288
                                        DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!!\n");
 
2289
                                }
 
2290
                                else
 
2291
                                {
 
2292
                                        if ((pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPAPSK) && (pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPANone))
 
2293
                                        {
 
2294
                                                Status = -EOPNOTSUPP;
 
2295
                                                DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK]\n");
 
2296
                                        }
 
2297
                                        else // Only for WPA PSK mode
 
2298
                                        {
 
2299
                                                pAdapter->PortCfg.PskKey.KeyLen = (UCHAR) Key.KeyLength;
 
2300
                                                memcpy(pAdapter->PortCfg.PskKey.Key, Key.KeyMaterial, Key.KeyLength);
 
2301
 
 
2302
                                                if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
 
2303
                                                {
 
2304
                                                        RTMPWPAAddKeyProc(pAdapter, &Key);
 
2305
                                                }
 
2306
                                                
 
2307
                                                // Use RaConfig as PSK agent.
 
2308
                                                // Start STA supplicant state machine
 
2309
                                                pAdapter->PortCfg.WpaState = SS_START;
 
2310
#ifdef RT2500_DBG
 
2311
        {
 
2312
                                                int     i;
 
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++)
 
2316
                                                {
 
2317
                                                        DBGPRINT_RAW(RT_DEBUG_LOUD, "%02x:", pAdapter->PortCfg.PskKey.Key[i]);
 
2318
                                                        if (i%16 == 15) {
 
2319
                                                                DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
 
2320
                                                                DBGPRINT(RT_DEBUG_LOUD, "    ");
 
2321
                                                        }
 
2322
                                                }
 
2323
                                                DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
 
2324
        }
 
2325
#endif
 
2326
                                                DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", Key.KeyIndex, Key.KeyLength);
 
2327
                                        }
 
2328
                                }
 
2329
 
 
2330
                        }
 
2331
                break;
 
2332
#endif            
 
2333
                default:
 
2334
                        DBGPRINT(RT_DEBUG_TRACE, "Set::unknown IOCTL's subcmd = 0x%08x\n", cmd);
 
2335
                        Status = -EOPNOTSUPP;
 
2336
                        break;
 
2337
        }
 
2338
 
 
2339
        return Status;
 
2340
}
 
2341
 
 
2342
 
 
2343
 
 
2344
UCHAR   BCAST[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
2345
/*
 
2346
        ========================================================================
 
2347
        
 
2348
        Routine Description:
 
2349
                Add WPA key process
 
2350
 
 
2351
        Arguments:
 
2352
                pAdapter                                                Pointer to our adapter
 
2353
                pBuf                                                    Pointer to the where the key stored
 
2354
 
 
2355
        Return Value:
 
2356
                NDIS_SUCCESS                                    Add key successfully
 
2357
 
 
2358
        Note:
 
2359
                
 
2360
        ========================================================================
 
2361
*/
 
2362
NDIS_STATUS     RTMPWPAAddKeyProc(
 
2363
        IN      PRT2570ADAPTER  pAdapter,
 
2364
        IN      PVOID                   pBuf)
 
2365
{
 
2366
        PNDIS_802_11_KEY        pKey;
 
2367
        ULONG                           KeyIdx;
 
2368
        NDIS_STATUS                     Status;
 
2369
        
 
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.
 
2376
        INT             i, PairwiseIdx;
 
2377
        TXRX_CSR0_STRUC  TxRxCsr0;
 
2378
        UCHAR           ZeroKey[4 * 16];
 
2379
        
 
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;
 
2392
 
 
2393
        memset(ZeroKey, 0, 4 * 16);
 
2394
        // 1. Check Group / Pairwise Key
 
2395
        if (bPairwise)  // Pairwise Key
 
2396
        {
 
2397
                // 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
 
2398
                if (KeyIdx != 0)
 
2399
                        return(NDIS_STATUS_FAILURE);
 
2400
                
 
2401
                // 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
 
2402
                if (bTxKey == FALSE)
 
2403
                        return(NDIS_STATUS_FAILURE);
 
2404
 
 
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);
 
2408
                        
 
2409
                // 4. Selct RxMic / TxMic based on Supp / Authenticator
 
2410
                if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
 
2411
                {
 
2412
                        // for WPA-None Tx, Rx MIC is the same
 
2413
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2414
                        pRxMic = pTxMic;
 
2415
                }
 
2416
                else if (bAuthenticator == TRUE)
 
2417
                {
 
2418
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2419
                        pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
 
2420
                }
 
2421
                else
 
2422
                {
 
2423
                        pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2424
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
 
2425
                }
 
2426
                
 
2427
                // 5. Find the old entry to overwrite or find an empty entry.
 
2428
                PairwiseIdx = 0;
 
2429
                for (i = 0; i < PAIRWISE_KEY_NO; i++)
 
2430
                {
 
2431
                        if (pAdapter->PortCfg.PairwiseKey[i].KeyLen == 0)
 
2432
                        {
 
2433
                                PairwiseIdx = i;
 
2434
                                break;
 
2435
                        }
 
2436
                        else if ((memcmp(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6) == 0))
 
2437
                        {
 
2438
                                // Found the old entry
 
2439
                                PairwiseIdx = i;
 
2440
                                break;
 
2441
                        }
 
2442
                }
 
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.
 
2445
 
 
2446
                // 6. Check RxTsc
 
2447
                if (bKeyRSC == TRUE)
 
2448
                {
 
2449
                        memcpy(&pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, &pKey->KeyRSC, 6);
 
2450
                }
 
2451
                else
 
2452
                {
 
2453
                        memset(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, 0, 6);
 
2454
                }
 
2455
                
 
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;
 
2471
 
 
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);
 
2476
 
 
2477
                Status = NDIS_STATUS_SUCCESS;
 
2478
                
 
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++)
 
2482
                {
 
2483
                        DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key[i]);
 
2484
                }
 
2485
                DBGPRINT_RAW(RT_DEBUG_INFO,"\n");                                               
 
2486
                DBGPRINT(RT_DEBUG_INFO,"TKIP Rx MIC Key = ");
 
2487
                for (i = 0; i < 8; i++)
 
2488
                {
 
2489
                        DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic[i]);
 
2490
                }
 
2491
                DBGPRINT_RAW(RT_DEBUG_INFO,"\n");                                               
 
2492
                DBGPRINT(RT_DEBUG_INFO,"TKIP Tx MIC Key = ");
 
2493
                for (i = 0; i < 8; i++)
 
2494
                {
 
2495
                        DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic[i]);
 
2496
                }
 
2497
                DBGPRINT_RAW(RT_DEBUG_INFO,"\n");                                               
 
2498
                DBGPRINT(RT_DEBUG_INFO,"TKIP RxTSC = ");
 
2499
                for (i = 0; i < 6; i++)
 
2500
                {
 
2501
                        DBGPRINT_RAW(RT_DEBUG_INFO,"%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc[i]);
 
2502
                }
 
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]);
 
2506
                
 
2507
        }
 
2508
        else    // Group Key
 
2509
        {
 
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);
 
2514
 
 
2515
                // 2. Check Key index for supported Group Key
 
2516
                if (KeyIdx >= GROUP_KEY_NO)
 
2517
                        return(NDIS_STATUS_FAILURE);
 
2518
                
 
2519
                // 3. Set as default Tx Key if bTxKey is TRUE
 
2520
                if (bTxKey == TRUE)
 
2521
                        pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
 
2522
                
 
2523
                // 4. Selct RxMic / TxMic based on Supp / Authenticator
 
2524
                if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
 
2525
                {
 
2526
                        // for WPA-None Tx, Rx MIC is the same
 
2527
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2528
                        pRxMic = pTxMic;
 
2529
                }
 
2530
                else if (bAuthenticator == TRUE)
 
2531
                {
 
2532
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2533
                        pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
 
2534
                }
 
2535
                else
 
2536
                {
 
2537
                        pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
 
2538
                        pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
 
2539
                }
 
2540
                
 
2541
                // 5. Check RxTsc
 
2542
                if (bKeyRSC == TRUE)
 
2543
                {
 
2544
                        memcpy(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, &pKey->KeyRSC, 6);
 
2545
                }
 
2546
                else
 
2547
                {
 
2548
                        memset(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, 0, 6);
 
2549
                }
 
2550
 
 
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;
 
2568
 
 
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)
 
2574
                {
 
2575
                        RTUSBMultiWriteMAC(pAdapter, (USHORT)(SEC_CSR0 + KeyIdx * 0x10), pAdapter->PortCfg.GroupKey[KeyIdx].Key, 16);
 
2576
                }
 
2577
                else
 
2578
                {
 
2579
                        RTUSBMultiWriteMAC(pAdapter, (USHORT)(SEC_CSR0 + KeyIdx * 0x10), pAdapter->PortCfg.GroupKey[KeyIdx].Key, 16);
 
2580
                }
 
2581
                DBGPRINT(RT_DEBUG_TRACE, "AddGroupKey::Use Hardware to decript broadcast/Mulitcast packet.\n");
 
2582
 
 
2583
                Status = NDIS_STATUS_SUCCESS;
 
2584
                // c. For WEP compatibility
 
2585
                if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
 
2586
                {
 
2587
                        pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
 
2588
                }
 
2589
 
 
2590
                DBGPRINT(RT_DEBUG_ERROR,"Group TKIP Key =\n ");
 
2591
                for (i = 0; i < 16; i++)
 
2592
                {
 
2593
                        DBGPRINT_RAW(RT_DEBUG_ERROR,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].Key[i]);
 
2594
                }
 
2595
                DBGPRINT_RAW(RT_DEBUG_ERROR,"\n");                                              
 
2596
                DBGPRINT(RT_DEBUG_TRACE,"TKIP Rx MIC Key = \n");
 
2597
                for (i = 0; i < 8; i++)
 
2598
                {
 
2599
                        DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxMic[i]);
 
2600
                }
 
2601
                DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");                                              
 
2602
                DBGPRINT(RT_DEBUG_TRACE,"TKIP Tx MIC Key = \n");
 
2603
                for (i = 0; i < 8; i++)
 
2604
                {
 
2605
                        DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].TxMic[i]);
 
2606
                }
 
2607
                DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");                                              
 
2608
                DBGPRINT(RT_DEBUG_TRACE,"TKIP RxTSC =\n ");
 
2609
                for (i = 0; i < 6; i++)
 
2610
                {
 
2611
                        DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc[i]);
 
2612
                }
 
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]);
 
2616
        
 
2617
                // For WEP compatibility, in case it use OID_ADD_KEY, not OID_ADD_WEP
 
2618
                if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
 
2619
                {
 
2620
                        pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
 
2621
                        memcpy(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
 
2622
                }
 
2623
        }
 
2624
        return (Status);
 
2625
}
 
2626
 
 
2627
/*
 
2628
        ========================================================================
 
2629
        
 
2630
        Routine Description:
 
2631
                Remove WPA Key process
 
2632
 
 
2633
        Arguments:
 
2634
                pAdapter                                                Pointer to our adapter
 
2635
                pBuf                                                    Pointer to the where the key stored
 
2636
 
 
2637
        Return Value:
 
2638
                NDIS_SUCCESS                                    Add key successfully
 
2639
 
 
2640
        Note:
 
2641
                
 
2642
        ========================================================================
 
2643
*/
 
2644
NDIS_STATUS     RTMPWPARemoveKeyProc(
 
2645
        IN      PRT2570ADAPTER  pAdapter,
 
2646
        IN      PVOID                   pBuf)
 
2647
{
 
2648
        PNDIS_802_11_REMOVE_KEY pKey;
 
2649
        ULONG                                   KeyIdx;
 
2650
        NDIS_STATUS                             Status = NDIS_STATUS_FAILURE;
 
2651
        
 
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.
 
2657
        INT             i;
 
2658
        USHORT          temp;
 
2659
        
 
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;
 
2670
 
 
2671
        // 1. If bTx is TRUE, return failure information
 
2672
        if (bTxKey == TRUE)
 
2673
                return(NDIS_STATUS_FAILURE);
 
2674
 
 
2675
        // 2. Check Pairwise Key
 
2676
        if (bPairwise)
 
2677
        {
 
2678
                // a. If BSSID is broadcast, remove all pairwise keys.
 
2679
                if ((memcmp(&pKey->BSSID, &BCAST, 6) == 0))
 
2680
                {
 
2681
                        for (i = 0; i < PAIRWISE_KEY_NO; i++)
 
2682
                        {
 
2683
                                pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
 
2684
                        }
 
2685
                        Status = NDIS_STATUS_SUCCESS;
 
2686
//                      RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
 
2687
//                      RTUSBReadMACRegister(pAdapter, TXRX_CSR0, temp & 0xfdff);
 
2688
                }
 
2689
 
 
2690
                // b. If not broadcast, remove the pairwise specified by BSSID
 
2691
                else
 
2692
                {
 
2693
                        for (i = 0; i < PAIRWISE_KEY_NO; i++)
 
2694
                        {
 
2695
                                if ((memcmp(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6) == 0))
 
2696
                                {
 
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;
 
2701
                                        break;
 
2702
                                }
 
2703
                        }
 
2704
                        
 
2705
                }
 
2706
                // c. If no pairwise supported, delete Group Key 0.
 
2707
                //        The will be false since we do support pairwise keys.
 
2708
        }
 
2709
        // 3. Group Key
 
2710
        else
 
2711
        {
 
2712
                // a. If BSSID is broadcast, remove all group keys indexed
 
2713
                if ((memcmp(&pKey->BSSID, &BCAST, 6) == 0))
 
2714
                {
 
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;
 
2719
                }
 
2720
 
 
2721
                // b. If BSSID matched, delte the group key indexed.
 
2722
                else if ((memcmp(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6) == 0))
 
2723
                {
 
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;
 
2728
                }
 
2729
        }
 
2730
        
 
2731
        return (Status);
 
2732
}
 
2733
 
 
2734
 
 
2735
/*
 
2736
        ========================================================================
 
2737
        
 
2738
        Routine Description:
 
2739
                Remove All WPA Keys
 
2740
 
 
2741
        Arguments:
 
2742
                pAdapter                                                Pointer to our adapter
 
2743
 
 
2744
        Return Value:
 
2745
                None
 
2746
 
 
2747
        Note:
 
2748
                
 
2749
        ========================================================================
 
2750
*/
 
2751
VOID    RTMPWPARemoveAllKeys(
 
2752
        IN      PRT2570ADAPTER  pAdapter)
 
2753
{
 
2754
        INT i;
 
2755
        USHORT  temp;
 
2756
 
 
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)
 
2760
                return;
 
2761
        
 
2762
        for (i = 0; i < PAIRWISE_KEY_NO; i++)
 
2763
        {
 
2764
                pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
 
2765
        }
 
2766
        
 
2767
        for (i = 0; i < GROUP_KEY_NO; i++)
 
2768
        {
 
2769
                pAdapter->PortCfg.GroupKey[i].KeyLen = 0;
 
2770
        }
 
2771
 
 
2772
        RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &temp);
 
2773
        RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, temp & 0xe1ff);
 
2774
}
 
2775
 
 
2776
/*
 
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 
 
2781
 
 
2782
        Arguments:
 
2783
                pAdapter - Pointer to our adapter
 
2784
                phymode  - 
 
2785
        ========================================================================
 
2786
*/
 
2787
VOID    RTMPSetPhyMode(
 
2788
        IN      PRT2570ADAPTER  pAdapter,
 
2789
        IN      ULONG phymode)
 
2790
{
 
2791
        DBGPRINT(RT_DEBUG_ERROR,"RTMPSetPhyMode(=%d)\n", phymode);
 
2792
        
 
2793
        // the selected phymode must be supported by the RF IC encoded in E2PROM
 
2794
        if (pAdapter->PortCfg.RfType == RFIC_2426)
 
2795
        {
 
2796
                phymode = PHY_11B;
 
2797
        }
 
2798
        else if (pAdapter->PortCfg.RfType < RFIC_5222)
 
2799
        {
 
2800
                if (phymode == PHY_11A)
 
2801
                        phymode = PHY_11BG_MIXED;
 
2802
        }
 
2803
                
 
2804
        // if no change, do nothing
 
2805
        if (pAdapter->PortCfg.PhyMode == phymode)
 
2806
                return;
 
2807
 
 
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);
 
2814
        
 
2815
        switch (phymode) {
 
2816
                case PHY_11B:
 
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;
 
2840
                        break;
 
2841
                        
 
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
 
2883
                        break;
 
2884
                        
 
2885
                case PHY_11A:
 
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;
 
2925
                        break;
 
2926
                        
 
2927
                default:
 
2928
        DBGPRINT(RT_DEBUG_TEMP,"default\n");
 
2929
                        break;
 
2930
        }
 
2931
        
 
2932
        MlmeUpdateTxRates(pAdapter, FALSE);
 
2933
        AsicSetSlotTime(pAdapter, FALSE);
 
2934
        MakeIbssBeacon(pAdapter);        // supported rates may change
 
2935
}
 
2936
 
 
2937
 
 
2938
VOID    RT2570SetDesiredRates(
 
2939
        IN      PRT2570ADAPTER  pAdapter,
 
2940
        IN      LONG                    Rates)
 
2941
{
 
2942
#if 1
 
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 );
 
2946
        
 
2947
        DBGPRINT(RT_DEBUG_ERROR, "2.RT2570SetDesiredRates::(Rates=%d)\n",       Rates );
 
2948
        if (Rates < 13 && (Rates > 0))
 
2949
                Rates = rate_mapping[Rates-1] * 1000000;
 
2950
        
 
2951
        memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
 
2952
        switch (pAdapter->PortCfg.PhyMode)
 
2953
        {
 
2954
                case PHY_11A: // A only
 
2955
                        switch (Rates)
 
2956
                        {
 
2957
                                case 6000000: //6M
 
2958
                                        aryRates[0] = 0x0c; // 6M
 
2959
                                        break;
 
2960
                                case 9000000: //9M
 
2961
                                        aryRates[0] = 0x12; // 9M
 
2962
                                        break;
 
2963
                                case 12000000: //12M
 
2964
                                        aryRates[0] = 0x18; // 12M
 
2965
                                        break;
 
2966
                                case 18000000: //18M
 
2967
                                        aryRates[0] = 0x24; // 18M
 
2968
                                        break;
 
2969
                                case 24000000: //24M
 
2970
                                        aryRates[0] = 0x30; // 24M
 
2971
                                        break;
 
2972
                                case 36000000: //36M
 
2973
                                        aryRates[0] = 0x48; // 36M
 
2974
                                        break;
 
2975
                                case 48000000: //48M
 
2976
                                        aryRates[0] = 0x60; // 48M
 
2977
                                        break;
 
2978
                                case 54000000: //54M
 
2979
                                        aryRates[0] = 0x6c; // 54M
 
2980
                                        break;
 
2981
                                case -1: //Auto
 
2982
                                default:
 
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
 
2991
                                        break;
 
2992
                        }
 
2993
                        break;
 
2994
                case PHY_11B: // B only
 
2995
                        switch (Rates)
 
2996
                        {
 
2997
                                case 1000000: //6M
 
2998
                                aryRates[0] = 0x02;
 
2999
                                        break;
 
3000
                                case 2000000: //6M
 
3001
                                        aryRates[0] = 0x04;
 
3002
                                        break;
 
3003
                                case 5000000: //5.5M
 
3004
                                        aryRates[0] = 0x0b; // 5.5M
 
3005
                                        break;
 
3006
                                case 11000000: //11M
 
3007
                                        aryRates[0] = 0x16; // 11M
 
3008
                                        break;
 
3009
                                case -1: //Auto
 
3010
                                default:
 
3011
                                                aryRates[0] = 0x16; // 11Mbps
 
3012
                                                aryRates[1] = 0x0b; // 5.5Mbps
 
3013
                                                aryRates[2] = 0x04; // 2Mbps
 
3014
                                                aryRates[3] = 0x02; // 1Mbps
 
3015
                                        break;
 
3016
                        }
 
3017
                        break;
 
3018
                case PHY_11BG_MIXED: // B/G Mixed
 
3019
                case PHY_11ABG_MIXED: // A/B/G Mixed
 
3020
                default:
 
3021
                        switch (Rates)
 
3022
                        {
 
3023
                                case 1000000: //6M
 
3024
                                        aryRates[0] = 0x02;
 
3025
                                        break;
 
3026
                                case 2000000: //6M
 
3027
                                        aryRates[0] = 0x04;
 
3028
                                        break;
 
3029
                                case 5000000: //5.5M
 
3030
                                        aryRates[0] = 0x0b; // 5.5M
 
3031
                                        break;
 
3032
                                case 11000000: //11M
 
3033
                                        aryRates[0] = 0x16; // 11M
 
3034
                                        break;
 
3035
                                case 6000000: //6M
 
3036
                                        aryRates[0] = 0x0c; // 6M
 
3037
                                        break;
 
3038
                                case 9000000: //9M
 
3039
                                        aryRates[0] = 0x12; // 9M
 
3040
                                        break;
 
3041
                                case 12000000: //12M
 
3042
                                        aryRates[0] = 0x18; // 12M
 
3043
                                        break;
 
3044
                                case 18000000: //18M
 
3045
                                        aryRates[0] = 0x24; // 18M
 
3046
                                        break;
 
3047
                                case 24000000: //24M
 
3048
                                        aryRates[0] = 0x30; // 24M
 
3049
                                        break;
 
3050
                                case 36000000: //36M
 
3051
                                        aryRates[0] = 0x48; // 36M
 
3052
                                        break;
 
3053
                                case 48000000: //48M
 
3054
                                        aryRates[0] = 0x60; // 48M
 
3055
                                        break;
 
3056
                                case 54000000: //54M
 
3057
                                        aryRates[0] = 0x6c; // 54M
 
3058
                                        break;
 
3059
                                case -1: //Auto
 
3060
                                default:
 
3061
                                        if (pAdapter->PortCfg.PhyMode == PHY_11B)
 
3062
                                        { //B Only
 
3063
                                                aryRates[0] = 0x16; // 11Mbps
 
3064
                                                aryRates[1] = 0x0b; // 5.5Mbps
 
3065
                                                aryRates[2] = 0x04; // 2Mbps
 
3066
                                                aryRates[3] = 0x02; // 1Mbps
 
3067
                                        }
 
3068
                                        else
 
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
 
3078
                                        }
 
3079
                                        break;
 
3080
                        }
 
3081
                        break;
 
3082
        }
 
3083
 
 
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);
 
3093
#endif
 
3094
}
 
3095
 
 
3096
INT Set_R17_Proc(
 
3097
        IN      PRT2570ADAPTER   pAdapter, 
 
3098
        IN      PUCHAR                  arg)
 
3099
{
 
3100
 
 
3101
        ULONG                                                           TUNN;
 
3102
        UINT    i = 0;
 
3103
        UCHAR   Value = 0x0;
 
3104
        int                                                             success = TRUE;
 
3105
        
 
3106
        TUNN = simple_strtol(arg, 0, 10);
 
3107
        i = (TUNN/100);
 
3108
        Value = TUNN%100;
 
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);
 
3111
 
 
3112
        return success;
 
3113
}
 
3114
INT Read_R17_Proc(
 
3115
        IN      PRT2570ADAPTER   pAdapter, 
 
3116
        IN      PUCHAR                  arg)
 
3117
 
 
3118
{
 
3119
 
 
3120
        UINT    i = 0;
 
3121
        UCHAR   Value = 0x0;
 
3122
        int                                                             success = TRUE;
 
3123
        for ( i = 0 ; i<70; i++)
 
3124
        {
 
3125
                
 
3126
                 RTUSBReadBBPRegister(pAdapter, i, &Value);
 
3127
                DBGPRINT(RT_DEBUG_TEMP,"Read_BBP_Proc R%d = 0x%x\n",i,Value);
 
3128
        }
 
3129
        return success;
 
3130
 
 
3131
}
 
3132
/* 
 
3133
        ==========================================================================
 
3134
        Description:
 
3135
                Set Country Region
 
3136
        Return:
 
3137
                TRUE if all parameters are OK, FALSE otherwise
 
3138
        ==========================================================================
 
3139
*/
 
3140
INT Set_CountryRegion_Proc(
 
3141
        IN      PRT2570ADAPTER   pAdapter, 
 
3142
        IN      PUCHAR                  arg)
 
3143
{
 
3144
        ULONG                                                           region;
 
3145
        int                                                             success = TRUE;
 
3146
 
 
3147
        region = simple_strtol(arg, 0, 10);
 
3148
        if( (region >= REGION_MIN) && (region <= REGION_MAX) )
 
3149
        {
 
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);
 
3153
        }
 
3154
        else
 
3155
                success = FALSE;
 
3156
 
 
3157
        return success;
 
3158
}
 
3159
/* 
 
3160
        ==========================================================================
 
3161
        Description:
 
3162
                Set SSID
 
3163
        Return:
 
3164
                TRUE if all parameters are OK, FALSE otherwise
 
3165
        ==========================================================================
 
3166
*/
 
3167
INT Set_SSID_Proc(
 
3168
        IN      PRT2570ADAPTER   pAdapter, 
 
3169
        IN      PUCHAR                  arg)
 
3170
{
 
3171
        int                                                             success = TRUE;
 
3172
        NDIS_802_11_SSID                                        Ssid, *pSsid=NULL;
 
3173
        BOOLEAN                                                         StateMachineTouched = FALSE;
 
3174
        if( strlen(arg) <= MAX_LEN_OF_SSID)
 
3175
        {
 
3176
                memset(&Ssid, 0, sizeof(NDIS_802_11_SSID));
 
3177
                memcpy(Ssid.Ssid, arg, strlen(arg));
 
3178
                Ssid.SsidLength = strlen(arg);
 
3179
                pSsid = &Ssid;
 
3180
 
 
3181
                if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
 
3182
                {
 
3183
                        MlmeRestartStateMachine(pAdapter);
 
3184
                        MlmePostRestartStateMachine(pAdapter);
 
3185
                        DBGPRINT(RT_DEBUG_TEMP, "!!! MLME busy, reset MLME state machine !!!\n");
 
3186
                }
 
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; 
 
3190
 
 
3191
                MlmeEnqueue(pAdapter, 
 
3192
                                        MLME_CNTL_STATE_MACHINE, 
 
3193
                                        OID_802_11_SSID,
 
3194
                                        sizeof(NDIS_802_11_SSID),
 
3195
                                        (VOID *)pSsid);
 
3196
 
 
3197
                StateMachineTouched = TRUE;
 
3198
                DBGPRINT(RT_DEBUG_TEMP, "Set_SSID_Proc::(Len=%d,Ssid=%s)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
 
3199
        }
 
3200
        else
 
3201
                success = FALSE;
 
3202
 
 
3203
        RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
 
3204
        return success;
 
3205
 
 
3206
}
 
3207
/* 
 
3208
        ==========================================================================
 
3209
        Description:
 
3210
                Set Wireless Mode
 
3211
        Return:
 
3212
                TRUE if all parameters are OK, FALSE otherwise
 
3213
        ==========================================================================
 
3214
*/
 
3215
INT Set_WirelessMode_Proc(
 
3216
        IN      PRT2570ADAPTER   pAdapter, 
 
3217
        IN      PUCHAR                  arg)
 
3218
{
 
3219
        int                                                             success = TRUE;
 
3220
#if 0
 
3221
        ULONG                                                           WirelessMode;
 
3222
        WirelessMode = simple_strtol(arg, 0, 10);
 
3223
 
 
3224
        if ((WirelessMode == PHY_11BG_MIXED) || (WirelessMode == PHY_11B) ||
 
3225
                (WirelessMode == PHY_11A) || (WirelessMode == PHY_11ABG_MIXED))
 
3226
        {
 
3227
                RTMPSetPhyMode(pAdapter, WirelessMode);
 
3228
                DBGPRINT(RT_DEBUG_TEMP, "Set_WirelessMode_Proc::(=%d)\n", WirelessMode);
 
3229
        }
 
3230
        else
 
3231
                success = FALSE;
 
3232
#endif
 
3233
        return success;
 
3234
}
 
3235
/* 
 
3236
        ==========================================================================
 
3237
        Description:
 
3238
                Set TxRate
 
3239
        Return:
 
3240
                TRUE if all parameters are OK, FALSE otherwise
 
3241
        ==========================================================================
 
3242
*/
 
3243
INT Set_TxRate_Proc(
 
3244
        IN      PRT2570ADAPTER   pAdapter, 
 
3245
        IN      PUCHAR                  arg)
 
3246
{
 
3247
        int                                                             success = TRUE;
 
3248
#if 0           
 
3249
        ULONG                                                           TxRate;
 
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);
 
3253
        if (TxRate > 12)
 
3254
                return FALSE;
 
3255
        
 
3256
        if (TxRate == 0)
 
3257
                RT2570SetDesiredRates(pAdapter, -1);
 
3258
        else
 
3259
                RT2570SetDesiredRates(pAdapter, (LONG) (rate_mapping[TxRate-1] * 1000000));
 
3260
#endif
 
3261
 
 
3262
        return success;
 
3263
}
 
3264
/* 
 
3265
        ==========================================================================
 
3266
        Description:
 
3267
                Set Channel
 
3268
        Return:
 
3269
                TRUE if all parameters are OK, FALSE otherwise
 
3270
        ==========================================================================
 
3271
*/
 
3272
INT Set_Channel_Proc(
 
3273
        IN      PRT2570ADAPTER   pAdapter, 
 
3274
        IN      PUCHAR                  arg)
 
3275
{
 
3276
        int                                                             success = TRUE;
 
3277
        UCHAR                                                           Channel;
 
3278
 
 
3279
        Channel = (UCHAR) simple_strtol(arg, 0, 10);
 
3280
 
 
3281
        if (ChannelSanity(pAdapter, Channel) == TRUE)
 
3282
        {
 
3283
                pAdapter->PortCfg.Channel = Channel;
 
3284
                DBGPRINT(RT_DEBUG_TRACE, "Set_Channel_Proc::(Channel=%d)\n", Channel);
 
3285
        }
 
3286
        else
 
3287
                success = FALSE;
 
3288
 
 
3289
        return success;
 
3290
}
 
3291
 
 
3292
/* 
 
3293
        ==========================================================================
 
3294
        Description:
 
3295
                Set 11B/11G Protection
 
3296
        Return:
 
3297
                TRUE if all parameters are OK, FALSE otherwise
 
3298
        ==========================================================================
 
3299
*/
 
3300
INT Set_BGProtection_Proc(
 
3301
        IN      PRT2570ADAPTER   pAdapter, 
 
3302
        IN      PUCHAR                  arg)
 
3303
 
 
3304
{
 
3305
        switch (simple_strtol(arg, 0, 10))
 
3306
        {
 
3307
                case 0: //AUTO
 
3308
                        pAdapter->PortCfg.UseBGProtection = 0;
 
3309
                        break;
 
3310
                case 1: //Always On
 
3311
                        pAdapter->PortCfg.UseBGProtection = 1;
 
3312
                        break;
 
3313
                case 2: //Always OFF
 
3314
                        pAdapter->PortCfg.UseBGProtection = 2;
 
3315
                        break;          
 
3316
                default:  //Invalid argument 
 
3317
                        return FALSE;
 
3318
        }
 
3319
        DBGPRINT(RT_DEBUG_TEMP, "Set_BGProtection_Proc::(BGProtection=%d)\n", pAdapter->PortCfg.UseBGProtection);
 
3320
 
 
3321
        return TRUE;
 
3322
}
 
3323
/* 
 
3324
        ==========================================================================
 
3325
        Description:
 
3326
                Set TxPreamble
 
3327
        Return:
 
3328
                TRUE if all parameters are OK, FALSE otherwise
 
3329
        ==========================================================================
 
3330
*/
 
3331
INT Set_TxPreamble_Proc(
 
3332
        IN      PRT2570ADAPTER   pAdapter, 
 
3333
        IN      PUCHAR                  arg)
 
3334
{
 
3335
#if 0
 
3336
        RT_802_11_PREAMBLE                                      Preamble;
 
3337
        Preamble = simple_strtol(arg, 0, 10);
 
3338
        switch (Preamble)
 
3339
        {
 
3340
                case Rt802_11PreambleShort:
 
3341
                        pAdapter->PortCfg.WindowsTxPreamble = Preamble;
 
3342
                        MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
 
3343
                        break;
 
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);
 
3350
                        break;
 
3351
                default: //Invalid argument 
 
3352
                        return FALSE;
 
3353
        }
 
3354
 
 
3355
        DBGPRINT(RT_DEBUG_TEMP, "Set_TxPreamble_Proc::(TxPreamble=%d)\n", Preamble);
 
3356
#endif
 
3357
 
 
3358
        return TRUE;
 
3359
}
 
3360
/* 
 
3361
        ==========================================================================
 
3362
        Description:
 
3363
                Set RTS Threshold
 
3364
        Return:
 
3365
                TRUE if all parameters are OK, FALSE otherwise
 
3366
        ==========================================================================
 
3367
*/
 
3368
INT Set_RTSThreshold_Proc(
 
3369
        IN      PRT2570ADAPTER   pAdapter, 
 
3370
        IN      PUCHAR                  arg)
 
3371
{
 
3372
        NDIS_802_11_RTS_THRESHOLD                       RtsThresh;
 
3373
 
 
3374
        RtsThresh = simple_strtol(arg, 0, 10);
 
3375
 
 
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;
 
3380
        else
 
3381
                return FALSE;
 
3382
 
 
3383
        DBGPRINT(RT_DEBUG_TEMP, "Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAdapter->PortCfg.RtsThreshold);
 
3384
        return TRUE;
 
3385
}
 
3386
/* 
 
3387
        ==========================================================================
 
3388
        Description:
 
3389
                Set Fragment Threshold
 
3390
        Return:
 
3391
                TRUE if all parameters are OK, FALSE otherwise
 
3392
        ==========================================================================
 
3393
*/
 
3394
INT Set_FragThreshold_Proc(
 
3395
        IN      PRT2570ADAPTER   pAdapter, 
 
3396
        IN      PUCHAR                  arg)
 
3397
{
 
3398
        NDIS_802_11_FRAGMENTATION_THRESHOLD     FragThresh;
 
3399
 
 
3400
        FragThresh = simple_strtol(arg, 0, 10);
 
3401
 
 
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;
 
3406
        else
 
3407
                return FALSE; //Invalid argument 
 
3408
 
 
3409
        if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
 
3410
                pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
 
3411
        else
 
3412
                pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
 
3413
 
 
3414
        DBGPRINT(RT_DEBUG_TEMP, "Set_FragThreshold_Proc::(FragThreshold=%d)\n", FragThresh);
 
3415
 
 
3416
        return TRUE;
 
3417
}
 
3418
/* 
 
3419
        ==========================================================================
 
3420
        Description:
 
3421
                Set TxBurst
 
3422
        Return:
 
3423
                TRUE if all parameters are OK, FALSE otherwise
 
3424
        ==========================================================================
 
3425
*/
 
3426
INT Set_TxBurst_Proc(
 
3427
        IN      PRT2570ADAPTER   pAdapter, 
 
3428
        IN      PUCHAR                  arg)
 
3429
{
 
3430
        ULONG                                                           TxBurst;
 
3431
 
 
3432
        TxBurst = simple_strtol(arg, 0, 10);
 
3433
 
 
3434
        if (TxBurst == 1)
 
3435
                pAdapter->PortCfg.EnableTxBurst = TRUE;
 
3436
        else if (TxBurst == 0)
 
3437
                pAdapter->PortCfg.EnableTxBurst = FALSE;
 
3438
        else
 
3439
                return FALSE;  //Invalid argument 
 
3440
        
 
3441
        DBGPRINT(RT_DEBUG_TEMP, "Set_TxBurst_Proc::(TxBurst=%d)\n", pAdapter->PortCfg.EnableTxBurst);
 
3442
 
 
3443
        return TRUE;
 
3444
}
 
3445
/* 
 
3446
        ==========================================================================
 
3447
        Description:
 
3448
                Set TurboRate Enable or Disable
 
3449
        Return:
 
3450
                TRUE if all parameters are OK, FALSE otherwise
 
3451
        ==========================================================================
 
3452
*/
 
3453
INT Set_TurboRate_Proc(
 
3454
        IN      PRT2570ADAPTER   pAdapter, 
 
3455
        IN      PUCHAR                  arg)
 
3456
{
 
3457
        ULONG                                                           TurboRate;
 
3458
 
 
3459
        TurboRate = simple_strtol(arg, 0, 10);
 
3460
 
 
3461
        if (TurboRate == 1)
 
3462
                pAdapter->PortCfg.EnableTurboRate = TRUE;
 
3463
        else if (TurboRate == 0)
 
3464
                pAdapter->PortCfg.EnableTurboRate = FALSE;
 
3465
        else
 
3466
                return FALSE;  //Invalid argument 
 
3467
        
 
3468
        DBGPRINT(RT_DEBUG_TEMP, "Set_TurboRate_Proc::(TurboRate=%d)\n", pAdapter->PortCfg.EnableTurboRate);
 
3469
 
 
3470
        return TRUE;
 
3471
}
 
3472
/* 
 
3473
        ==========================================================================
 
3474
        Description:
 
3475
                Set Short Slot Time Enable or Disable
 
3476
        Return:
 
3477
                TRUE if all parameters are OK, FALSE otherwise
 
3478
        ==========================================================================
 
3479
*/
 
3480
INT Set_ShortSlot_Proc(
 
3481
        IN      PRT2570ADAPTER   pAdapter, 
 
3482
        IN      PUCHAR                  arg)
 
3483
{
 
3484
        ULONG                                                           ShortSlot;
 
3485
 
 
3486
        ShortSlot = simple_strtol(arg, 0, 10);
 
3487
 
 
3488
        if (ShortSlot == 1)
 
3489
                pAdapter->PortCfg.UseShortSlotTime = TRUE;
 
3490
        else if (ShortSlot == 0)
 
3491
                pAdapter->PortCfg.UseShortSlotTime = FALSE;
 
3492
        else
 
3493
                return FALSE;  //Invalid argument 
 
3494
 
 
3495
        DBGPRINT(RT_DEBUG_TEMP, "Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAdapter->PortCfg.UseShortSlotTime);
 
3496
 
 
3497
        return TRUE;
 
3498
}
 
3499
/* 
 
3500
        ==========================================================================
 
3501
        Description:
 
3502
                Set Authentication mode
 
3503
        Return:
 
3504
                TRUE if all parameters are OK, FALSE otherwise
 
3505
        ==========================================================================
 
3506
*/
 
3507
INT Set_AuthMode_Proc(
 
3508
        IN      PRT2570ADAPTER   pAdapter, 
 
3509
        IN      PUCHAR                  arg)
 
3510
{
 
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;
 
3519
        else
 
3520
                return FALSE;  
 
3521
 
 
3522
        pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
 
3523
 
 
3524
        DBGPRINT(RT_DEBUG_TEMP, "Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->PortCfg.AuthMode);
 
3525
 
 
3526
        return TRUE;
 
3527
}
 
3528
/* 
 
3529
        ==========================================================================
 
3530
        Description:
 
3531
                Set Encryption Type
 
3532
        Return:
 
3533
                TRUE if all parameters are OK, FALSE otherwise
 
3534
        ==========================================================================
 
3535
*/
 
3536
INT Set_EncrypType_Proc(
 
3537
        IN      PRT2570ADAPTER   pAdapter, 
 
3538
        IN      PUCHAR                  arg)
 
3539
{
 
3540
        USHORT  Value;
 
3541
        if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
 
3542
        {
 
3543
                pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
 
3544
                RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3545
                Value &= 0xfe00;
 
3546
                DBGPRINT(RT_DEBUG_INFO,"Set::NONERead  TXRX_CSR0  %x !!!!!!!!!!!!!!!!!\n",Value);
 
3547
                RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3548
        }
 
3549
        else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
 
3550
        {
 
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;
 
3554
                else
 
3555
                        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
3556
                        
 
3557
                RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3558
                DBGPRINT(RT_DEBUG_TEMP,"Set::WEPRead  TXRX_CSR0  %x !!!!!!!!!!!!!!!!!\n",Value);
 
3559
                Value &= 0xfe00;
 
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);
 
3563
        }
 
3564
        else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
 
3565
        {
 
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);
 
3570
                Value &= 0xfe00;
 
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);
 
3574
        }
 
3575
        else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
 
3576
        {
 
3577
                pAdapter->PortCfg.WepStatus = Ndis802_11Encryption3Enabled;
 
3578
                RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3579
                Value &= 0xfe00;
 
3580
                Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
3581
                RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3582
        }
 
3583
        else
 
3584
        {
 
3585
                DBGPRINT(RT_DEBUG_INFO,"Set::EncrypType ERROR !!!!!!!!!!!!!!!!!\n");
 
3586
                
 
3587
                return FALSE;
 
3588
        }
 
3589
 
 
3590
        DBGPRINT(RT_DEBUG_TEMP, "Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->PortCfg.WepStatus);
 
3591
 
 
3592
 
 
3593
        return TRUE;
 
3594
}
 
3595
/* 
 
3596
        ==========================================================================
 
3597
        Description:
 
3598
                Set Default Key ID
 
3599
        Return:
 
3600
                TRUE if all parameters are OK, FALSE otherwise
 
3601
        ==========================================================================
 
3602
*/
 
3603
INT Set_DefaultKeyID_Proc(
 
3604
        IN      PRT2570ADAPTER   pAdapter, 
 
3605
        IN      PUCHAR                  arg)
 
3606
{
 
3607
        ULONG                                                           KeyIdx;
 
3608
 
 
3609
        KeyIdx = simple_strtol(arg, 0, 10);
 
3610
        if((KeyIdx >= 1 ) && (KeyIdx <= 4))
 
3611
                pAdapter->PortCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
 
3612
        else
 
3613
                return FALSE;  //Invalid argument 
 
3614
 
 
3615
        DBGPRINT(RT_DEBUG_TEMP, "Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->PortCfg.DefaultKeyId);
 
3616
 
 
3617
        return TRUE;
 
3618
}
 
3619
/* 
 
3620
        ==========================================================================
 
3621
        Description:
 
3622
                Set WEP KEY1
 
3623
        Return:
 
3624
                TRUE if all parameters are OK, FALSE otherwise
 
3625
        ==========================================================================
 
3626
*/
 
3627
INT Set_Key1_Proc(
 
3628
        IN      PRT2570ADAPTER   pAdapter, 
 
3629
        IN      PUCHAR                  arg)
 
3630
{
 
3631
        int                                                             KeyLen;
 
3632
        int                                                             i;
 
3633
        USHORT  Value;
 
3634
 
 
3635
        KeyLen = strlen(arg);
 
3636
 
 
3637
        switch (KeyLen)
 
3638
        {
 
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");           
 
3643
                
 
3644
                        break;
 
3645
                case 10: //wep 40 Hex type
 
3646
                        for(i=0; i < KeyLen; i++)
 
3647
                        {
 
3648
                                if( !isxdigit(*(arg+i)) )
 
3649
                                        return FALSE;  //Not Hex value;
 
3650
                        }
 
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");     
 
3654
                 
 
3655
                        break;
 
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");           
 
3660
                        break;
 
3661
                case 26: //wep 104 Hex type
 
3662
                        for(i=0; i < KeyLen; i++)
 
3663
                        {
 
3664
                                if( !isxdigit(*(arg+i)) )
 
3665
                                        return FALSE;  //Not Hex value;
 
3666
                        }
 
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");     
 
3670
                        break;
 
3671
                default: //Invalid argument 
 
3672
                        DBGPRINT(RT_DEBUG_TEMP, "Set_Key1_Proc::Invalid argument (=%s)\n", arg);           
 
3673
                        return FALSE;
 
3674
        }
 
3675
 
 
3676
 
 
3677
        RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 0 * 0x10), pAdapter->PortCfg.SharedKey[0].Key, 16);       
 
3678
 
 
3679
                                                                
 
3680
                                                                
 
3681
        // Default key for tx (shared key)
 
3682
        pAdapter->PortCfg.DefaultKeyId = (UCHAR)0;
 
3683
                                                                
 
3684
                                                                
 
3685
                                                                
 
3686
        if ( (KeyLen == 5) ||( KeyLen == 10) )
 
3687
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
3688
        else
 
3689
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
3690
                                                                
 
3691
         RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3692
         Value &= 0xfe00;
 
3693
         Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
3694
         RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3695
        
 
3696
        return TRUE;
 
3697
}
 
3698
/* 
 
3699
        ==========================================================================
 
3700
        Description:
 
3701
                Set WEP KEY2
 
3702
        Return:
 
3703
                TRUE if all parameters are OK, FALSE otherwise
 
3704
        ==========================================================================
 
3705
*/
 
3706
INT Set_Key2_Proc(
 
3707
        IN      PRT2570ADAPTER   pAdapter, 
 
3708
        IN      PUCHAR                  arg)
 
3709
{
 
3710
        int                                                             KeyLen;
 
3711
        int                                                             i;
 
3712
        USHORT  Value;
 
3713
 
 
3714
        KeyLen = strlen(arg);
 
3715
 
 
3716
        switch (KeyLen)
 
3717
        {
 
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");
 
3722
                        break;
 
3723
                case 10: //wep 40 Hex type
 
3724
                        for(i=0; i < KeyLen; i++)
 
3725
                        {
 
3726
                                if( !isxdigit(*(arg+i)) )
 
3727
                                        return FALSE;  //Not Hex value;
 
3728
                        }
 
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");
 
3732
                        break;
 
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");
 
3737
                        break;
 
3738
                case 26: //wep 104 Hex type
 
3739
                        for(i=0; i < KeyLen; i++)
 
3740
                        {
 
3741
                                if( !isxdigit(*(arg+i)) )
 
3742
                                        return FALSE;  //Not Hex value;
 
3743
                        }
 
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");
 
3747
                        break;
 
3748
                default: //Invalid argument 
 
3749
                        DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::Invalid argument (=%s)\n", arg);
 
3750
                        return FALSE;
 
3751
        }
 
3752
 
 
3753
        RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 1 * 0x10), pAdapter->PortCfg.SharedKey[1].Key, 16);       
 
3754
 
 
3755
        
 
3756
                                                                
 
3757
                                                                
 
3758
                                                                
 
3759
        // Default key for tx (shared key)
 
3760
        pAdapter->PortCfg.DefaultKeyId = (UCHAR)1;
 
3761
                                                                
 
3762
                                                                
 
3763
                                                                
 
3764
        if ( (KeyLen == 5) ||( KeyLen == 10) )
 
3765
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
3766
        else
 
3767
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
3768
                                                                
 
3769
         RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3770
         Value &= 0xfe00;
 
3771
         Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
3772
         RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3773
 
 
3774
        return TRUE;
 
3775
}
 
3776
/* 
 
3777
        ==========================================================================
 
3778
        Description:
 
3779
                Set WEP KEY3
 
3780
        Return:
 
3781
                TRUE if all parameters are OK, FALSE otherwise
 
3782
        ==========================================================================
 
3783
*/
 
3784
INT Set_Key3_Proc(
 
3785
        IN      PRT2570ADAPTER   pAdapter, 
 
3786
        IN      PUCHAR                  arg)
 
3787
{
 
3788
        int                                                             KeyLen;
 
3789
        int                                                             i;
 
3790
        USHORT  Value;  
 
3791
 
 
3792
        KeyLen = strlen(arg);
 
3793
 
 
3794
        switch (KeyLen)
 
3795
        {
 
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");
 
3800
                        break;
 
3801
                case 10: //wep 40 Hex type
 
3802
                        for(i=0; i < KeyLen; i++)
 
3803
                        {
 
3804
                                if( !isxdigit(*(arg+i)) )
 
3805
                                        return FALSE;  //Not Hex value;
 
3806
                        }
 
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");
 
3810
                        break;
 
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");
 
3815
                        break;
 
3816
                case 26: //wep 104 Hex type
 
3817
                        for(i=0; i < KeyLen; i++)
 
3818
                        {
 
3819
                                if( !isxdigit(*(arg+i)) )
 
3820
                                        return FALSE;  //Not Hex value;
 
3821
                        }
 
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");
 
3825
                        break;
 
3826
                default: //Invalid argument 
 
3827
                        DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::Invalid argument (=%s)\n", arg);
 
3828
                        return FALSE;
 
3829
        }
 
3830
 
 
3831
        RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 2 * 0x10), pAdapter->PortCfg.SharedKey[2].Key, 16);       
 
3832
 
 
3833
                                                                
 
3834
        // Default key for tx (shared key)
 
3835
        pAdapter->PortCfg.DefaultKeyId = (UCHAR)2;
 
3836
                                                                
 
3837
                                                                
 
3838
                                                                
 
3839
        if ( (KeyLen == 5) ||( KeyLen == 10) )
 
3840
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
3841
        else
 
3842
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
3843
                                                                
 
3844
         RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3845
         Value &= 0xfe00;
 
3846
         Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
3847
         RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3848
 
 
3849
        return TRUE;
 
3850
}
 
3851
/* 
 
3852
        ==========================================================================
 
3853
        Description:
 
3854
                Set WEP KEY4
 
3855
        Return:
 
3856
                TRUE if all parameters are OK, FALSE otherwise
 
3857
        ==========================================================================
 
3858
*/
 
3859
INT Set_Key4_Proc(
 
3860
        IN      PRT2570ADAPTER   pAdapter, 
 
3861
        IN      PUCHAR                  arg)
 
3862
{
 
3863
        int                                                             KeyLen;
 
3864
        int                                                             i;
 
3865
        USHORT  Value;
 
3866
 
 
3867
        KeyLen = strlen(arg);
 
3868
 
 
3869
        switch (KeyLen)
 
3870
        {
 
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");
 
3875
                        break;
 
3876
                case 10: //wep 40 Hex type
 
3877
                        for(i=0; i < KeyLen; i++)
 
3878
                        {
 
3879
                                if( !isxdigit(*(arg+i)) )
 
3880
                                        return FALSE;  //Not Hex value;
 
3881
                        }
 
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");
 
3885
                        break;
 
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");
 
3890
                        break;
 
3891
                case 26: //wep 104 Hex type
 
3892
                        for(i=0; i < KeyLen; i++)
 
3893
                        {
 
3894
                                if( !isxdigit(*(arg+i)) )
 
3895
                                        return FALSE;  //Not Hex value;
 
3896
                        }
 
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");
 
3900
                        break;
 
3901
                default: //Invalid argument 
 
3902
                        DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::Invalid argument (=%s)\n", arg);
 
3903
                        return FALSE;
 
3904
        }
 
3905
 
 
3906
        RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + 3 * 0x10), pAdapter->PortCfg.SharedKey[3].Key, 16);       
 
3907
 
 
3908
                                                                
 
3909
        // Default key for tx (shared key)
 
3910
        pAdapter->PortCfg.DefaultKeyId = (UCHAR)3;
 
3911
                                                                
 
3912
                                                                
 
3913
                                                                
 
3914
        if ( (KeyLen == 5) ||( KeyLen == 10) )
 
3915
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
3916
        else
 
3917
        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
3918
                                                                
 
3919
         RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
3920
         Value &= 0xfe00;
 
3921
         Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
3922
         RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
3923
 
 
3924
        return TRUE;
 
3925
}
 
3926
/* 
 
3927
        ==========================================================================
 
3928
        Description:
 
3929
                Set WPA PSK key
 
3930
        Return:
 
3931
                TRUE if all parameters are OK, FALSE otherwise
 
3932
        ==========================================================================
 
3933
*/
 
3934
INT Set_WPAPSK_Proc(
 
3935
        IN      PRT2570ADAPTER   pAdapter, 
 
3936
        IN      PUCHAR                  arg)
 
3937
{
 
3938
#if 0
 
3939
        UCHAR                                                           keyMaterial[40];
 
3940
 
 
3941
        DBGPRINT(RT_DEBUG_TRACE, "Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg);
 
3942
        if ((strlen(arg) < 8) || (strlen(arg) > 64))
 
3943
        {
 
3944
                DBGPRINT(RT_DEBUG_TRACE, "Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg);
 
3945
                return FALSE;
 
3946
        }
 
3947
 
 
3948
        PasswordHash((char *)arg, pAdapter->PortCfg.Ssid, pAdapter->PortCfg.SsidLen, keyMaterial);
 
3949
 
 
3950
        memcpy(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
 
3951
 
 
3952
        // Use RaConfig as PSK agent.
 
3953
        // Start STA supplicant state machine
 
3954
        pAdapter->PortCfg.WpaState = SS_START;
 
3955
#ifdef RT2500_DBG
 
3956
        DBGPRINT(RT_DEBUG_LOUD, "Set_WPAPSK_Proc WPAPSK Key => \n");
 
3957
        DBGPRINT(RT_DEBUG_LOUD, "    ");
 
3958
        for (i = 0; i < 32; i++)
 
3959
        {
 
3960
                DBGPRINT_RAW(RT_DEBUG_LOUD, "%02x:", pAdapter->PortCfg.PskKey.Key[i]);
 
3961
                if (i%16 == 15) {
 
3962
                  DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
 
3963
                  DBGPRINT(RT_DEBUG_LOUD, "    ");
 
3964
                }
 
3965
        }
 
3966
        DBGPRINT_RAW(RT_DEBUG_LOUD, "\n");
 
3967
#endif
 
3968
#endif
 
3969
return TRUE;
 
3970
 
 
3971
}
 
3972
 
 
3973
 
 
3974
int usb_rt2570_ioctl(struct net_device *net_dev, struct ifreq *rq,
 
3975
                          int cmd)
 
3976
{
 
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;
 
3988
        USHORT  Value;
 
3989
        
 
3990
        if ( (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_REMOVE_IN_PROGRESS)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)))
 
3991
        {
 
3992
                DBGPRINT(RT_DEBUG_TRACE,"INFO::remove in progress!\n");
 
3993
                return -ENETDOWN;
 
3994
        }
 
3995
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
 
3996
        if (pAdapter->RTUSBCmdThr_pid < 0)
 
3997
                return -ENETDOWN;
 
3998
#else
 
3999
        if (!pAdapter->RTUSBCmdThr_active)
 
4000
                return -ENETDOWN;
 
4001
#endif
 
4002
        
 
4003
        switch(cmd) {
 
4004
 
 
4005
                case SIOCGIWNAME:
 
4006
                        DBGPRINT(RT_DEBUG_INFO,"IOCTL::SIOCGIWNAME\n");
 
4007
                        strcpy(wrq->u.name,"RT2570 Wireless");   //Less then 16 bytes. 
 
4008
                        break;
 
4009
                case SIOCSIWESSID:      //Set ESSID
 
4010
                        DBGPRINT(RT_DEBUG_INFO, "==>ioctl::SIOCSIWESSID\n");
 
4011
 
 
4012
                        break;
 
4013
                case SIOCGIWESSID:      //Get ESSID
 
4014
                        DBGPRINT(RT_DEBUG_INFO, "==>ioctl::SIOCGIWESSID\n");
 
4015
                        break;
 
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 
 
4020
                        else
 
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);
 
4024
                break;
 
4025
                case SIOCGIWFREQ: // get channel/frequency (Hz)
 
4026
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWFREQ\n");
 
4027
                        break;
 
4028
                case SIOCGIWNICKN: //get node name/nickname
 
4029
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWNICKN\n");
 
4030
                        erq = &wrq->u.data;
 
4031
                        erq->length = strlen(pAdapter->nickn);
 
4032
                        if(copy_to_user(erq->pointer, pAdapter->nickn, erq->length))
 
4033
                                Status = -EFAULT;
 
4034
 
 
4035
                         DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCGIWNICKN\n");
 
4036
                        break;
 
4037
                case SIOCSIWNICKN: //set node name/nickname
 
4038
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWNICKN\n");
 
4039
                         DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCSIWNICKN\n");
 
4040
                        break;
 
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");
 
4046
                        break;
 
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");
 
4051
                        break;
 
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");
 
4058
                        break;
 
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;
 
4064
 
 
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;
 
4069
 
 
4070
                        DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCSIWRTS (=%d)\n", pAdapter->PortCfg.RtsThreshold);
 
4071
                        break;
 
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");
 
4078
                        break;
 
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;
 
4084
 
 
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;
 
4089
 
 
4090
                        if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
 
4091
                                pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
 
4092
                        else
 
4093
                                pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
 
4094
 
 
4095
                        DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCSIWFRAG (=%d)\n", pAdapter->PortCfg.FragmentThreshold);
 
4096
                        break;
 
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)
 
4102
 
 
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;
 
4107
 
 
4108
                        if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
 
4109
                                wrq->u.encoding.flags |= IW_ENCODE_DISABLED;
 
4110
                        else
 
4111
                        {
 
4112
                                if(wrq->u.encoding.pointer)
 
4113
                                {
 
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))
 
4118
                                                Status = -EFAULT;
 
4119
 
 
4120
                                        wrq->u.encoding.flags |= (pAdapter->PortCfg.DefaultKeyId + 1);
 
4121
                                }
 
4122
                        }
 
4123
                         DBGPRINT(RT_DEBUG_TEMP,"<==IOCTL::SIOCGIWENCODE , DefaultKeyId=%d\n", pAdapter->PortCfg.DefaultKeyId);
 
4124
                        break;
 
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)
 
4131
 
 
4132
                        if((wrq->u.encoding.pointer) && ((wrq->u.encoding.flags & IW_ENCODE_NOKEY) == 0))
 
4133
                        {
 
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;
 
4138
 
 
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))
 
4141
                                        Status = -EINVAL;
 
4142
 
 
4143
                                pAdapter->PortCfg.SharedKey[index].KeyLen = len <= WEP_SMALL_KEY_LEN ? WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
 
4144
                        }
 
4145
                        if (wrq->u.encoding.flags & IW_ENCODE_DISABLED)
 
4146
                                pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
 
4147
                        else
 
4148
                                pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
 
4149
 
 
4150
                        if (wrq->u.encoding.flags & IW_ENCODE_RESTRICTED)
 
4151
                                pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
 
4152
                        else 
 
4153
                                pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
 
4154
 
 
4155
                        if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
 
4156
                                pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
 
4157
 
 
4158
                        if ((wrq->u.encoding.flags & IW_ENCODE_NOKEY) == 0)
 
4159
                        {
 
4160
                                RTUSBMultiWrite(pAdapter, (USHORT)(SEC_CSR0 + index * 0x10), pAdapter->PortCfg.SharedKey[index].Key, 16);       
 
4161
 
 
4162
                                pAdapter->PortCfg.DefaultKeyId = (UCHAR) index;
 
4163
                                if ( (len == 5) ||( len == 10) )
 
4164
                                        pAdapter->PortCfg.CipherAlg = CIPHER_WEP64;
 
4165
                                else
 
4166
                                        pAdapter->PortCfg.CipherAlg = CIPHER_WEP128;
 
4167
                                                                                        
 
4168
                                 RTUSBReadMACRegister(pAdapter, TXRX_CSR0, &Value);
 
4169
                                 Value &= 0xfe00;
 
4170
                                 Value |= ((LENGTH_802_11 << 3) | (pAdapter->PortCfg.CipherAlg));
 
4171
                                 RTUSBWriteMACRegister(pAdapter, TXRX_CSR0, Value);
 
4172
 
 
4173
                        }
 
4174
 
 
4175
                        DBGPRINT(RT_DEBUG_TRACE,"<==IOCTL::SIOCSIWENCODE\n");
 
4176
                        break;
 
4177
                case SIOCGIWAP:  //get access point MAC addresses
 
4178
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWAP\n");
 
4179
                         DBGPRINT(RT_DEBUG_TEMP,"<==>IOCTL::SIOCGIWAP\n");
 
4180
                        break;
 
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)
 
4185
                        {
 
4186
                                DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
 
4187
                        }
 
4188
 
 
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; 
 
4192
 
 
4193
                        MlmeEnqueue(pAdapter, 
 
4194
                                                MLME_CNTL_STATE_MACHINE, 
 
4195
                                                OID_802_11_BSSID, 
 
4196
                                                sizeof(NDIS_802_11_MAC_ADDRESS),
 
4197
                                                (VOID *)&Bssid);
 
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");
 
4203
                        break;
 
4204
                case SIOCGIWMODE:  //get operation mode
 
4205
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCGIWMODE\n");
 
4206
                        if (ADHOC_ON(pAdapter))
 
4207
                        {
 
4208
                                BssType = Ndis802_11IBSS;
 
4209
                                wrq->u.mode = IW_MODE_ADHOC;
 
4210
                        }
 
4211
                        else if (INFRA_ON(pAdapter))
 
4212
                        {
 
4213
                                BssType = Ndis802_11Infrastructure;
 
4214
                                wrq->u.mode = IW_MODE_INFRA;
 
4215
                        }
 
4216
                        else
 
4217
                        {
 
4218
                                BssType = Ndis802_11AutoUnknown;
 
4219
                                wrq->u.mode = IW_MODE_AUTO;
 
4220
                        }
 
4221
                        DBGPRINT(RT_DEBUG_TRACE, "<==ioctl::SIOCGIWMODE(=%d)\n", BssType);
 
4222
                        break;
 
4223
                case SIOCSIWMODE:  //set operation mode
 
4224
                        DBGPRINT(RT_DEBUG_TRACE,"==>IOCTL::SIOCSIWMODE\n");
 
4225
                        DBGPRINT(RT_DEBUG_TEMP,"<==IOCTL::SIOCSIWMODE\n");
 
4226
                        break;
 
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;
 
4235
                        break;
 
4236
                case SIOCGIWAPLIST:
 
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);
 
4239
                        break;
 
4240
 
 
4241
                case SIOCGIWPRIV:
 
4242
                        if (wrq->u.data.pointer) {
 
4243
                                if ( !access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) )
 
4244
                                        break;
 
4245
                                wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
 
4246
                                if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
 
4247
                                        Status = -EFAULT;
 
4248
                        }
 
4249
                        break;
 
4250
                default:
 
4251
                        DBGPRINT(RT_DEBUG_INFO, "IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd);
 
4252
                        Status = -EOPNOTSUPP;
 
4253
                        break;
 
4254
        }
 
4255
 
 
4256
        if(StateMachineTouched) // Upper layer sent a MLME-related operations
 
4257
                RTUSBUp(pAdapter, (&(pAdapter->mlme_semaphore)));
 
4258
        
 
4259
        return Status;
 
4260
}
 
4261