MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink.org / rtmp_info.c
blob3394f31688351aef46fa539c3b06cce06716e71c
1 /*
2 ***************************************************************************
3 * Ralink Tech Inc.
4 * 4F, No. 2 Technology 5th Rd.
5 * Science-based Industrial Park
6 * Hsin-chu, Taiwan, R.O.C.
8 * (c) Copyright 2002, Ralink Technology, Inc.
10 * All rights reserved. Ralink's source code is an unpublished work and the
11 * use of a copyright notice does not imply otherwise. This source code
12 * contains confidential trade secret material of Ralink Tech. Any attemp
13 * or participation in deciphering, decoding, reverse engineering or in any
14 * way altering the source code is stricitly prohibited, unless the prior
15 * written consent of Ralink Technology, Inc. is obtained.
16 ***************************************************************************
18 Module Name:
19 rtmp_info.c
21 Abstract:
22 IOCTL related subroutines
24 Revision History:
25 Who When What
26 -------- ---------- ----------------------------------------------
27 Rory Chen 01-03-2003 created
31 #include "rt_config.h"
32 #include <net/iw_handler.h>
34 #ifndef IW_ESSID_MAX_SIZE
35 /* Maximum size of the ESSID and NICKN strings */
36 #define IW_ESSID_MAX_SIZE 32
37 #endif
39 #define NR_WEP_KEYS 4
40 #define WEP_SMALL_KEY_LEN (40/8)
41 #define WEP_LARGE_KEY_LEN (104/8)
43 #define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \
44 switch (ch) \
45 { \
46 case 1: khz = 2412000; break; \
47 case 2: khz = 2417000; break; \
48 case 3: khz = 2422000; break; \
49 case 4: khz = 2427000; break; \
50 case 5: khz = 2432000; break; \
51 case 6: khz = 2437000; break; \
52 case 7: khz = 2442000; break; \
53 case 8: khz = 2447000; break; \
54 case 9: khz = 2452000; break; \
55 case 10: khz = 2457000; break; \
56 case 11: khz = 2462000; break; \
57 case 12: khz = 2467000; break; \
58 case 13: khz = 2472000; break; \
59 case 14: khz = 2484000; break; \
60 case 36: /* UNII */ khz = 5180000; break; \
61 case 40: /* UNII */ khz = 5200000; break; \
62 case 44: /* UNII */ khz = 5220000; break; \
63 case 48: /* UNII */ khz = 5240000; break; \
64 case 52: /* UNII */ khz = 5260000; break; \
65 case 56: /* UNII */ khz = 5280000; break; \
66 case 60: /* UNII */ khz = 5300000; break; \
67 case 64: /* UNII */ khz = 5320000; break; \
68 case 149: /* UNII */ khz = 5745000; break; \
69 case 153: /* UNII */ khz = 5765000; break; \
70 case 157: /* UNII */ khz = 5785000; break; \
71 case 161: /* UNII */ khz = 5805000; break; \
72 case 100: /* HiperLAN2 */ khz = 5500000; break; \
73 case 104: /* HiperLAN2 */ khz = 5520000; break; \
74 case 108: /* HiperLAN2 */ khz = 5540000; break; \
75 case 112: /* HiperLAN2 */ khz = 5560000; break; \
76 case 116: /* HiperLAN2 */ khz = 5580000; break; \
77 case 120: /* HiperLAN2 */ khz = 5600000; break; \
78 case 124: /* HiperLAN2 */ khz = 5620000; break; \
79 case 128: /* HiperLAN2 */ khz = 5640000; break; \
80 case 132: /* HiperLAN2 */ khz = 5660000; break; \
81 case 136: /* HiperLAN2 */ khz = 5680000; break; \
82 case 140: /* HiperLAN2 */ khz = 5700000; break; \
83 case 34: /* Japan MMAC */ khz = 5170000; break; \
84 case 38: /* Japan MMAC */ khz = 5190000; break; \
85 case 42: /* Japan MMAC */ khz = 5210000; break; \
86 case 46: /* Japan MMAC */ khz = 5230000; break; \
87 default: khz = 2412000; break; \
88 } \
91 #define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \
92 switch (khz) \
93 { \
94 case 2412000: ch = 1; break; \
95 case 2417000: ch = 2; break; \
96 case 2422000: ch = 3; break; \
97 case 2427000: ch = 4; break; \
98 case 2432000: ch = 5; break; \
99 case 2437000: ch = 6; break; \
100 case 2442000: ch = 7; break; \
101 case 2447000: ch = 8; break; \
102 case 2452000: ch = 9; break; \
103 case 2457000: ch = 10; break; \
104 case 2462000: ch = 11; break; \
105 case 2467000: ch = 12; break; \
106 case 2472000: ch = 13; break; \
107 case 2484000: ch = 14; break; \
108 case 5180000: ch = 36; /* UNII */ break; \
109 case 5200000: ch = 40; /* UNII */ break; \
110 case 5220000: ch = 44; /* UNII */ break; \
111 case 5240000: ch = 48; /* UNII */ break; \
112 case 5260000: ch = 52; /* UNII */ break; \
113 case 5280000: ch = 56; /* UNII */ break; \
114 case 5300000: ch = 60; /* UNII */ break; \
115 case 5320000: ch = 64; /* UNII */ break; \
116 case 5745000: ch = 149; /* UNII */ break; \
117 case 5765000: ch = 153; /* UNII */ break; \
118 case 5785000: ch = 157; /* UNII */ break; \
119 case 5805000: ch = 161; /* UNII */ break; \
120 case 5500000: ch = 100; /* HiperLAN2 */ break; \
121 case 5520000: ch = 104; /* HiperLAN2 */ break; \
122 case 5540000: ch = 108; /* HiperLAN2 */ break; \
123 case 5560000: ch = 112; /* HiperLAN2 */ break; \
124 case 5580000: ch = 116; /* HiperLAN2 */ break; \
125 case 5600000: ch = 120; /* HiperLAN2 */ break; \
126 case 5620000: ch = 124; /* HiperLAN2 */ break; \
127 case 5640000: ch = 128; /* HiperLAN2 */ break; \
128 case 5660000: ch = 132; /* HiperLAN2 */ break; \
129 case 5680000: ch = 136; /* HiperLAN2 */ break; \
130 case 5700000: ch = 140; /* HiperLAN2 */ break; \
131 case 5170000: ch = 34; /* Japan MMAC */ break; \
132 case 5190000: ch = 38; /* Japan MMAC */ break; \
133 case 5210000: ch = 42; /* Japan MMAC */ break; \
134 case 5230000: ch = 46; /* Japan MMAC */ break; \
135 default: ch = 1; break; \
139 struct iw_priv_args privtab[] = {
140 { RTPRIV_IOCTL_SET,
141 IW_PRIV_TYPE_CHAR | 1024, 0,
142 "set"},
143 { RTPRIV_IOCTL_BBP,
144 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
145 "bbp"},
146 { RTPRIV_IOCTL_MAC,
147 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
148 "mac"},
149 { RTPRIV_IOCTL_E2P,
150 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
151 "e2p"}
154 static struct {
155 char *name;
156 int (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
157 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
158 {"CountryRegion", Set_CountryRegion_Proc },
159 {"SSID", Set_SSID_Proc},
160 {"WirelessMode", Set_WirelessMode_Proc},
161 {"TxRate", Set_TxRate_Proc},
162 {"AdhocModeRate", Set_AdhocModeRate_Proc},
163 {"Channel", Set_Channel_Proc},
164 {"BGProtection", Set_BGProtection_Proc},
165 {"TxPreamble", Set_TxPreamble_Proc},
166 {"RTSThreshold", Set_RTSThreshold_Proc},
167 {"FragThreshold", Set_FragThreshold_Proc},
168 {"TxBurst", Set_TxBurst_Proc},
169 {"TurboRate", Set_TurboRate_Proc},
170 {"NetworkType", Set_NetworkType_Proc},
171 {"AuthMode", Set_AuthMode_Proc},
172 {"EncrypType", Set_EncrypType_Proc},
173 {"DefaultKeyID", Set_DefaultKeyID_Proc},
174 {"Key1", Set_Key1_Proc},
175 {"Key2", Set_Key2_Proc},
176 {"Key3", Set_Key3_Proc},
177 {"Key4", Set_Key4_Proc},
178 {"WPAPSK", Set_WPAPSK_Proc},
179 #ifdef RT2500_DBG
180 {"Debug", Set_Debug_Proc},
181 #endif
183 #ifdef RALINK_ATE
184 {"ATE", Set_ATE_Proc }, // set ATE Mode to: STOP, TXCONT, TXCARR, TXFRAME, RXFRAME
185 {"ATEDA", Set_ATE_DA_Proc }, // set ATE TxFrames ADDR1, DA
186 {"ATESA", Set_ATE_SA_Proc }, // set ATE TxFrames ADDR2, SA
187 {"ATEBSSID", Set_ATE_BSSID_Proc }, // set ATE TxFrames ADDR3, BSSID
188 {"ATECHANNEL", Set_ATE_CHANNEL_Proc }, // set ATE Channel
189 {"ATETXPOW", Set_ATE_TX_POWER_Proc }, // set ATE TxPower
190 {"ATETXLEN", Set_ATE_TX_LENGTH_Proc}, // set ATE TxLength
191 {"ATETXCNT", Set_ATE_TX_COUNT_Proc }, // set ATE TxCount
192 {"ATETXRATE", Set_ATE_TX_RATE_Proc }, // set ATE TxRate
193 #endif //#ifdef RALINK_ATE
195 {NULL,}
198 char * rtstrchr(const char * s, int c)
200 for(; *s != (char) c; ++s)
201 if (*s == '\0')
202 return NULL;
203 return (char *) s;
206 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
208 int rt_ioctl_giwrange(struct net_device *dev,
209 struct iw_request_info *info,
210 struct iw_point *data, char *extra)
212 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
213 struct iw_range *range = (struct iw_range *) extra;
214 u16 val;
215 int i;
217 DBGPRINT(RT_DEBUG_TRACE,"0. rtusb_ioctl_giwrange\n");
218 data->length = sizeof(struct iw_range);
219 memset(range, 0, sizeof(struct iw_range));
221 range->txpower_capa = IW_TXPOW_DBM;
223 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
225 range->min_pmp = 1 * 1024;
226 range->max_pmp = 65535 * 1024;
227 range->min_pmt = 1 * 1024;
228 range->max_pmt = 1000 * 1024;
229 range->pmp_flags = IW_POWER_PERIOD;
230 range->pmt_flags = IW_POWER_TIMEOUT;
231 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
232 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
235 range->we_version_compiled = WIRELESS_EXT;
236 range->we_version_source = 14;
238 range->retry_capa = IW_RETRY_LIMIT;
239 range->retry_flags = IW_RETRY_LIMIT;
240 range->min_retry = 0;
241 range->max_retry = 255;
243 range->num_channels = pAdapter->PortCfg.SupportedRatesLen;
245 val = 0;
246 for (i = 0; i < pAdapter->PortCfg.SupportedRatesLen; i++) {
247 range->freq[val].i =(pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2;
248 range->freq[val].m = (pAdapter->PortCfg.SupportedRates[i] & 0x7f)/2 * 100000;
249 range->freq[val].e = 1;
250 val++;
251 if (val == IW_MAX_FREQUENCIES)
252 break;
254 range->num_frequency = val;
256 range->max_qual.qual = 70; /* what is correct max? This was not
257 * documented exactly. At least
258 * 69 has been observed. */
259 range->max_qual.level = 0; /* dB */
260 range->max_qual.noise = 0; /* dB */
262 /* What would be suitable values for "average/typical" qual? */
263 range->avg_qual.qual = 20;
264 range->avg_qual.level = -60;
265 range->avg_qual.noise = -95;
266 range->sensitivity = 3;
268 range->max_encoding_tokens = NR_WEP_KEYS;
269 range->num_encoding_sizes = 2;
270 range->encoding_size[0] = 5;
271 range->encoding_size[1] = 13;
273 #if 0
274 over2 = 0;
275 len = prism2_get_datarates(dev, rates);
276 range->num_bitrates = 0;
277 for (i = 0; i < len; i++) {
278 if (range->num_bitrates < IW_MAX_BITRATES) {
279 range->bitrate[range->num_bitrates] =
280 rates[i] * 500000;
281 range->num_bitrates++;
283 if (rates[i] == 0x0b || rates[i] == 0x16)
284 over2 = 1;
286 /* estimated maximum TCP throughput values (bps) */
287 range->throughput = over2 ? 5500000 : 1500000;
288 #endif
289 range->min_rts = 0;
290 range->max_rts = 2347;
291 range->min_frag = 256;
292 range->max_frag = 2346;
294 return 0;
297 static int
298 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
299 void *w, char *extra)
301 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
302 char *this_char;
303 char *value;
304 int Status;
306 while ((this_char = strsep(&extra, ",")) != NULL)
308 if (!*this_char)
309 continue;
311 if ((value = rtstrchr(this_char, '=')) != NULL)
312 *value++ = 0;
314 if (!value || !*value)
315 continue;
317 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
319 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
321 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
322 { //FALSE:Set private failed then return Invalid argument
323 Status = -EINVAL;
325 break; //Exit for loop.
329 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
330 { //Not found argument
331 Status = -EINVAL;
332 DBGPRINT(RT_DEBUG_TRACE, "ioctl::(iwpriv) Not Support Set Command [%s=%s]\n", this_char, value);
333 break;
336 return 0;
339 static const iw_handler rt_priv_handlers[] = {
340 (iw_handler) rt_ioctl_setparam, /* SIOCWFIRSTPRIV+0 */
343 #ifdef SIOCGIWSCAN
344 int rt_ioctl_siwscan(struct net_device *dev,
345 struct iw_request_info *info,
346 struct iw_point *data, char *extra)
348 ULONG Now;
349 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
350 int Status = NDIS_STATUS_SUCCESS;
351 BOOLEAN StateMachineTouched = FALSE;
352 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
353 return 0;
355 Now = jiffies;
357 if ((pAdapter->MediaState == NdisMediaStateConnected) &&
358 ((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ||
359 (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
360 (pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
363 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
364 Status = NDIS_STATUS_SUCCESS;
365 break;
368 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
370 MlmeRestartStateMachine(pAdapter);
371 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
374 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
375 // this request, because this request is initiated by NDIS.
376 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
377 // Reset Missed scan number
378 pAdapter->PortCfg.IgnoredScanNumber = 0;
379 pAdapter->PortCfg.LastScanTime = Now;
381 MlmeEnqueue(&pAdapter->Mlme.Queue,
382 MLME_CNTL_STATE_MACHINE,
383 OID_802_11_BSSID_LIST_SCAN,
385 NULL);
387 Status = NDIS_STATUS_SUCCESS;
388 StateMachineTouched = TRUE;
389 }while(0);
390 return 0;
393 rt_ioctl_giwscan(struct net_device *dev,
394 struct iw_request_info *info,
395 struct iw_point *data, char *extra)
398 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
399 int i=2, j;
400 char *current_ev = extra;
401 char *end_buf = extra + IW_SCAN_MAX_DATA;
402 char *current_val;
403 struct iw_event iwe;
404 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)){
406 * Still scanning, indicate the caller should try again.
408 return -EAGAIN;
410 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
412 if (current_ev >= end_buf)
413 break;
415 //================================
416 memset(&iwe, 0, sizeof(iwe));
417 iwe.cmd = SIOCGIWAP;
418 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
419 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, ETH_ALEN);
420 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
421 //================================
422 memset(&iwe, 0, sizeof(iwe));
423 iwe.cmd = SIOCGIWMODE;
424 if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11IBSS)
426 iwe.u.mode = IW_MODE_ADHOC;
428 else if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
430 iwe.u.mode = IW_MODE_INFRA;
432 else
434 iwe.u.mode = IW_MODE_AUTO;
437 iwe.len = IW_EV_UINT_LEN;
438 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
439 //================================
440 memset(&iwe, 0, sizeof(iwe));
441 iwe.cmd = SIOCGIWESSID;
442 iwe.u.data.length = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
443 iwe.u.data.flags = 1;
444 current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
445 //================================
446 memset(&iwe, 0, sizeof(iwe));
447 iwe.cmd = SIOCGIWENCODE;
448 if (CAP_IS_PRIVACY_ON (pAdapter->PortCfg.BssTab.BssEntry[i].CapabilityInfo ))
449 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
450 else
451 iwe.u.data.flags = IW_ENCODE_DISABLED;
452 current_ev = iwe_stream_add_point(current_ev, end_buf,&iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
454 //================================
455 memset(&iwe, 0, sizeof(iwe));
456 iwe.cmd = SIOCGIWRATE;
457 current_val = current_ev + IW_EV_LCP_LEN;
458 //for (j = 0; j < pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen;j++)
459 for (j = 0; j < 1;j++)
461 iwe.u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.BssTab.BssEntry[i].Rates[i]/2] * 1000000;
462 iwe.u.bitrate.disabled = 0;
463 current_val = iwe_stream_add_value(current_ev,
464 current_val, end_buf, &iwe,
465 IW_EV_PARAM_LEN);
467 //================================
468 memset(&iwe, 0, sizeof(iwe));
469 iwe.cmd = SIOCGIWFREQ;
470 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
471 iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
472 else
473 iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
474 iwe.u.freq.e = 0;
475 iwe.u.freq.i = 0;
476 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
477 //================================
478 memset(&iwe, 0, sizeof(iwe));
481 data->length = current_ev - extra;
482 DBGPRINT(RT_DEBUG_TRACE,"rtusb_ioctl_giwscan. %d BSS returned\n",pAdapter->PortCfg.BssTab.BssNr);
483 return 0;
485 #endif
486 static const iw_handler rt_handler[] =
488 (iw_handler) NULL, /* SIOCSIWCOMMIT */
489 (iw_handler) NULL, /* SIOCGIWNAME 1 */
490 (iw_handler) NULL, /* SIOCSIWNWID */
491 (iw_handler) NULL, /* SIOCGIWNWID */
492 (iw_handler) NULL, /* SIOCSIWFREQ */
493 (iw_handler) NULL, /* SIOCGIWFREQ 5*/
494 (iw_handler) NULL, /* SIOCSIWMODE */
495 (iw_handler) NULL, /* SIOCGIWMODE */
496 (iw_handler) NULL, /* SIOCSIWSENS */
497 (iw_handler) NULL, /* SIOCGIWSENS */
498 (iw_handler) NULL /* not used */,/* SIOCSIWRANGE */
499 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE 11 */
500 (iw_handler) NULL /* not used */,/* SIOCSIWPRIV */
501 (iw_handler) NULL /* kernel code */,/* SIOCGIWPRIV */
502 (iw_handler) NULL /* not used */,/* SIOCSIWSTATS */
503 (iw_handler) NULL /* kernel code */,/* SIOCGIWSTATS f*/
504 (iw_handler) NULL, /* SIOCSIWSPY */
505 (iw_handler) NULL, /* SIOCGIWSPY */
506 (iw_handler) NULL, /* -- hole -- */
507 (iw_handler) NULL, /* -- hole -- */
508 (iw_handler) NULL, /* SIOCSIWAP */
509 (iw_handler) NULL, /* SIOCGIWAP 0x15*/
510 (iw_handler) NULL, /* -- hole -- 0x16 */
511 (iw_handler) NULL, /* SIOCGIWAPLIST */
512 #ifdef SIOCGIWSCAN
513 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN 0x18*/
514 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
515 #else
516 (iw_handler) NULL, /* SIOCSIWSCAN */
517 (iw_handler) NULL, /* SIOCGIWSCAN */
518 #endif /* SIOCGIWSCAN */
519 (iw_handler) NULL, /* SIOCSIWESSID */
520 (iw_handler) NULL, /* SIOCGIWESSID */
521 (iw_handler) NULL, /* SIOCSIWNICKN */
522 (iw_handler) NULL, /* SIOCGIWNICKN 1d*/
523 (iw_handler) NULL, /* -- hole -- */
524 (iw_handler) NULL, /* -- hole -- */
525 (iw_handler) NULL, /* SIOCSIWRATE 20*/
526 (iw_handler) NULL, /* SIOCGIWRATE */
527 (iw_handler) NULL, /* SIOCSIWRTS */
528 (iw_handler) NULL, /* SIOCGIWRTS */
529 (iw_handler) NULL, /* SIOCSIWFRAG */
530 (iw_handler) NULL, /* SIOCGIWFRAG 25*/
531 (iw_handler) NULL, /* SIOCSIWTXPOW */
532 (iw_handler) NULL, /* SIOCGIWTXPOW */
533 (iw_handler) NULL, /* SIOCSIWRETRY */
534 (iw_handler) NULL, /* SIOCGIWRETRY 29*/
535 (iw_handler) NULL, /* SIOCSIWENCODE 2a*/
536 (iw_handler) NULL, /* SIOCGIWENCODE 2b*/
537 (iw_handler) NULL, /* SIOCSIWPOWER 2c*/
538 (iw_handler) NULL, /* SIOCGIWPOWER 2d*/
541 const struct iw_handler_def rt2500_iw_handler_def =
543 #define N(a) (sizeof (a) / sizeof (a[0]))
544 .standard = (iw_handler *) rt_handler,
545 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
546 .private = (iw_handler *) rt_priv_handlers,
547 .num_private = N(rt_priv_handlers),
548 .private_args = (struct iw_priv_args *) privtab,
549 .num_private_args = N(privtab),
550 #if WIRELESS_EXT > 15
551 // .spy_offset = offsetof(struct hostap_interface, spy_data),
552 #endif /* WIRELESS_EXT > 15 */
554 INT RTMPSetInformation(
555 IN PRTMP_ADAPTER pAdapter,
556 IN OUT struct ifreq *rq,
557 IN INT cmd)
559 struct iwreq *wrq = (struct iwreq *) rq;
560 NDIS_802_11_SSID Ssid, *pSsid=NULL;
561 NDIS_802_11_MAC_ADDRESS Bssid;
562 RT_802_11_PHY_MODE PhyMode;
563 RT_802_11_STA_CONFIG StaConfig;
564 NDIS_802_11_RATES aryRates;
565 RT_802_11_PREAMBLE Preamble;
566 NDIS_802_11_WEP_STATUS WepStatus;
567 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
568 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
569 NDIS_802_11_RTS_THRESHOLD RtsThresh;
570 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
571 NDIS_802_11_POWER_MODE PowerMode;
572 NDIS_802_11_TX_POWER_LEVEL TxPowerLevel;
573 PNDIS_802_11_KEY pKey = NULL;
574 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
575 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
576 ULONG Now;
577 ULONG KeyIdx;
578 INT Status = NDIS_STATUS_SUCCESS;
579 UCHAR CountryRegion;
580 BOOLEAN RadioState;
581 BOOLEAN StateMachineTouched = FALSE;
582 USHORT TxTotalCnt;
584 switch(cmd & 0x7FFF) {
585 case RT_OID_802_11_COUNTRY_REGION:
586 if (wrq->u.data.length != sizeof(CountryRegion))
587 Status = -EINVAL;
588 else
590 copy_from_user(&CountryRegion, wrq->u.data.pointer, wrq->u.data.length);
591 pAdapter->PortCfg.CountryRegion = CountryRegion;
592 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_COUNTRY_REGION (=%d) \n", pAdapter->PortCfg.CountryRegion);
594 break;
595 case OID_802_11_BSSID_LIST_SCAN:
596 Now = jiffies;
597 TxTotalCnt = pAdapter->DrsCounters.OneSecTxOkCount +
598 pAdapter->DrsCounters.OneSecTxRetryOkCount +
599 pAdapter->DrsCounters.OneSecTxFailCount;
600 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", TxTotalCnt);
601 // For XP WZC, we will allow scan every 10 times, roughly 10 minutes.
602 // if ((Oid == OID_802_11_BSSID_LIST_SCAN) &&
603 // (pAdapter->MediaState == NdisMediaStateConnected) &&
604 // (pAdapter->PortCfg.IgnoredScanNumber < 10))
605 if (TxTotalCnt > 100)
607 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
608 Status = NDIS_STATUS_SUCCESS;
609 pAdapter->PortCfg.IgnoredScanNumber++;
610 break;
613 if ((pAdapter->MediaState == NdisMediaStateConnected) &&
614 ((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ||
615 (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
616 (pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
619 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
620 Status = NDIS_STATUS_SUCCESS;
621 break;
624 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
626 MlmeRestartStateMachine(pAdapter);
627 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
630 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
631 // this request, because this request is initiated by NDIS.
632 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
633 // Reset Missed scan number
634 pAdapter->PortCfg.IgnoredScanNumber = 0;
635 pAdapter->PortCfg.LastScanTime = Now;
637 MlmeEnqueue(&pAdapter->Mlme.Queue,
638 MLME_CNTL_STATE_MACHINE,
639 OID_802_11_BSSID_LIST_SCAN,
641 NULL);
643 Status = NDIS_STATUS_SUCCESS;
644 StateMachineTouched = TRUE;
645 break;
646 case OID_802_11_SSID:
647 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
648 Status = -EINVAL;
649 else
651 copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
652 pSsid = &Ssid;
654 if (pSsid->SsidLength > MAX_LEN_OF_SSID)
655 Status = -EINVAL;
656 else
658 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
660 MlmeRestartStateMachine(pAdapter);
661 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
663 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
664 // this request, because this request is initiated by NDIS.
665 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
667 MlmeEnqueue(&pAdapter->Mlme.Queue,
668 MLME_CNTL_STATE_MACHINE,
669 OID_802_11_SSID,
670 sizeof(NDIS_802_11_SSID),
671 (VOID *)pSsid
673 Status = NDIS_STATUS_SUCCESS;
674 StateMachineTouched = TRUE;
676 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", pSsid->SsidLength, pSsid->Ssid);
679 break;
680 case OID_802_11_BSSID:
681 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
682 Status = -EINVAL;
683 else
685 copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
687 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
689 MlmeRestartStateMachine(pAdapter);
690 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
693 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
694 // this request, because this request is initiated by NDIS.
695 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
697 MlmeEnqueue(&pAdapter->Mlme.Queue,
698 MLME_CNTL_STATE_MACHINE,
699 OID_802_11_BSSID,
700 sizeof(NDIS_802_11_MAC_ADDRESS),
701 (VOID *)&Bssid);
702 Status = NDIS_STATUS_SUCCESS;
703 StateMachineTouched = TRUE;
704 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
705 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]);
707 break;
708 case RT_OID_802_11_RADIO:
709 if (wrq->u.data.length != sizeof(BOOLEAN))
710 Status = -EINVAL;
711 else
713 copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
714 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_RADIO (=%d)\n", RadioState);
715 if (pAdapter->PortCfg.bSwRadio != RadioState)
717 pAdapter->PortCfg.bSwRadio = RadioState;
718 if (pAdapter->PortCfg.bRadio != (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio))
720 pAdapter->PortCfg.bRadio = (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio);
721 if (pAdapter->PortCfg.bRadio == TRUE)
722 MlmeRadioOn(pAdapter);
723 else
724 MlmeRadioOff(pAdapter);
728 break;
729 case RT_OID_802_11_PHY_MODE:
730 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
731 Status = -EINVAL;
732 else
734 copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
735 RTMPSetPhyMode(pAdapter, PhyMode);
736 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode);
738 break;
739 case RT_OID_802_11_STA_CONFIG:
740 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
741 Status = -EINVAL;
742 else
744 copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
745 pAdapter->PortCfg.EnableTxBurst = StaConfig.EnableTxBurst;
746 pAdapter->PortCfg.EnableTurboRate = StaConfig.EnableTurboRate;
747 pAdapter->PortCfg.UseBGProtection = StaConfig.UseBGProtection;
748 // pAdapter->PortCfg.UseShortSlotTime = StaConfig.UseShortSlotTime;
749 pAdapter->PortCfg.UseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
750 if (pAdapter->PortCfg.AdhocMode != StaConfig.AdhocMode)
752 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
753 // if setting changed, need to reset current TX rate as well as BEACON frame format
754 pAdapter->PortCfg.AdhocMode = StaConfig.AdhocMode;
755 if (pAdapter->PortCfg.BssType == BSS_INDEP)
757 MlmeUpdateTxRates(pAdapter, FALSE);
758 MakeIbssBeacon(pAdapter);
761 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d,72/100=%d,Protection=%d,ShortSlot=%d,OFDM in 11g Adhoc=%d\n",
762 pAdapter->PortCfg.EnableTxBurst,
763 pAdapter->PortCfg.EnableTurboRate,
764 pAdapter->PortCfg.UseBGProtection,
765 pAdapter->PortCfg.UseShortSlotTime,
766 pAdapter->PortCfg.AdhocMode);
768 break;
769 case OID_802_11_DESIRED_RATES:
770 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
771 Status = -EINVAL;
772 else
774 copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
775 NdisZeroMemory(pAdapter->PortCfg.DesiredRates, MAX_LEN_OF_SUPPORTED_RATES);
776 NdisMoveMemory(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
777 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
778 pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
779 pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
780 pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
781 pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
782 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
783 MlmeUpdateTxRates(pAdapter, FALSE);
785 break;
786 case RT_OID_802_11_PREAMBLE:
787 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
788 Status = -EINVAL;
789 else
791 copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
792 if (Preamble == Rt802_11PreambleShort)
794 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
795 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
797 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
799 // if user wants AUTO, initialize to LONG here, then change according to AP's
800 // capability upon association.
801 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
802 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
804 else
806 Status = EINVAL;
807 break;
809 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_SET_PREAMBLE (=%d)\n", Preamble);
811 break;
812 case OID_802_11_WEP_STATUS:
813 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
814 Status = -EINVAL;
815 else
817 copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
818 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
819 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
821 if (pAdapter->PortCfg.WepStatus != WepStatus)
823 // Config has changed
824 pAdapter->bConfigChanged = TRUE;
826 pAdapter->PortCfg.WepStatus = WepStatus;
828 else
830 Status = -EINVAL;
831 break;
833 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus);
835 break;
836 case OID_802_11_AUTHENTICATION_MODE:
837 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
838 Status = -EINVAL;
839 else
841 copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
842 if (AuthMode > Ndis802_11AuthModeMax)
844 Status = -EINVAL;
845 break;
847 else
849 if (pAdapter->PortCfg.AuthMode != AuthMode)
851 // Config has changed
852 pAdapter->bConfigChanged = TRUE;
854 pAdapter->PortCfg.AuthMode = AuthMode;
856 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
857 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->PortCfg.AuthMode);
859 break;
860 case OID_802_11_INFRASTRUCTURE_MODE:
861 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
862 Status = -EINVAL;
863 else
865 copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
866 if (BssType == Ndis802_11IBSS)
868 if (pAdapter->PortCfg.BssType != BSS_INDEP)
870 // Config has changed
871 pAdapter->bConfigChanged = TRUE;
873 pAdapter->PortCfg.BssType = BSS_INDEP;
874 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (AD-HOC)\n");
876 else if (BssType == Ndis802_11Infrastructure)
878 if (pAdapter->PortCfg.BssType != BSS_INFRA)
880 // Config has changed
881 pAdapter->bConfigChanged = TRUE;
883 pAdapter->PortCfg.BssType = BSS_INFRA;
884 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (INFRA)\n");
886 else
888 Status = -EINVAL;
889 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n");
892 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
893 pAdapter->PortCfg.WpaState = SS_NOTUSE;
894 break;
895 case RT_OID_802_11_RESET_COUNTERS:
896 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
897 NdisZeroMemory(&pAdapter->Counters, sizeof(COUNTER_802_3));
898 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
899 NdisZeroMemory(&pAdapter->Mlme.PrevWlanCounters, sizeof(COUNTER_802_11));
900 DBGPRINT(RT_DEBUG_INFO, "Set::RT_OID_802_11_RESET_COUNTERS \n");
901 break;
902 case OID_802_11_RTS_THRESHOLD:
903 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
904 Status = -EINVAL;
905 else
907 copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
908 if (RtsThresh > MAX_RTS_THRESHOLD)
909 Status = -EINVAL;
910 else
911 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
913 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RTS_THRESHOLD (=%d)\n",RtsThresh);
914 break;
915 case OID_802_11_FRAGMENTATION_THRESHOLD:
916 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
917 Status = -EINVAL;
918 else
920 copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
921 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
922 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
924 if (FragThresh == 0)
926 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
927 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
929 else
930 Status = -EINVAL;
932 else
933 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
935 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%d) \n",FragThresh);
936 break;
937 case OID_802_11_POWER_MODE:
938 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
939 Status = -EINVAL;
940 else
942 copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
943 // save user's policy here, but not change PortCfg.Psm immediately
944 if (PowerMode == Ndis802_11PowerModeCAM)
946 // clear PSM bit immediately
947 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
948 pAdapter->PortCfg.RecvDtim = TRUE;
949 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
950 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
951 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
953 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
955 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
956 // to exclude certain situations.
957 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
958 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
959 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
960 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
961 pAdapter->PortCfg.RecvDtim = TRUE; // FALSE;
962 pAdapter->PortCfg.DefaultListenCount = 5;
964 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
966 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
967 // to exclude certain situations.
968 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
969 pAdapter->PortCfg.RecvDtim = TRUE;
970 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
971 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
972 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
973 pAdapter->PortCfg.DefaultListenCount = 3;
975 else
976 Status = -EINVAL;
978 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode);
979 break;
980 case OID_802_11_TX_POWER_LEVEL:
981 if (wrq->u.data.length != sizeof(NDIS_802_11_TX_POWER_LEVEL))
982 Status = -EINVAL;
983 else
985 copy_from_user(&TxPowerLevel, wrq->u.data.pointer, wrq->u.data.length);
986 if (TxPowerLevel > MAX_TX_POWER_LEVEL)
987 Status = -EINVAL;
988 else
989 pAdapter->PortCfg.TxPower = (UCHAR)TxPowerLevel;
991 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_TX_POWER_LEVEL (=%d) \n",TxPowerLevel);
992 break;
993 // For WPA PSK PMK key
994 case RT_OID_802_11_ADD_WPA:
995 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
996 copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
997 if (pKey->Length != wrq->u.data.length)
999 Status = -EINVAL;
1000 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!!\n");
1002 else
1004 if (pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPAPSK)
1006 Status = -EOPNOTSUPP;
1007 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK]\n");
1009 else // Only for WPA PSK mode
1011 pAdapter->PortCfg.PskKey.KeyLen = (UCHAR) pKey->KeyLength;
1012 NdisMoveMemory(pAdapter->PortCfg.PskKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
1013 // Use RaConfig as PSK agent.
1014 // Start STA supplicant state machine
1015 pAdapter->PortCfg.WpaState = SS_START;
1017 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength);
1020 kfree(pKey);
1021 break;
1022 case OID_802_11_REMOVE_KEY:
1023 pRemoveKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1024 copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
1025 if (pRemoveKey->Length != wrq->u.data.length)
1027 Status = -EINVAL;
1028 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!\n");
1030 else
1032 if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1034 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
1035 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n");
1037 else
1039 KeyIdx = pRemoveKey->KeyIndex;
1041 if (KeyIdx & 0x80000000)
1043 // Should never set default bit when remove key
1044 Status = -EINVAL;
1045 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n");
1047 else
1049 KeyIdx = KeyIdx & 0x0fffffff;
1050 if (KeyIdx > 3)
1052 Status = -EINVAL;
1053 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx);
1055 else
1057 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
1058 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length);
1063 kfree(pRemoveKey);
1064 break;
1065 case OID_802_11_ADD_KEY:
1066 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1067 copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
1068 if (pKey->Length != wrq->u.data.length)
1070 Status = -EINVAL;
1071 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY, Failed!!\n");
1073 else
1075 if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1077 RTMPWPAAddKeyProc(pAdapter, pKey);
1079 else // Old WEP stuff
1081 KeyIdx = pKey->KeyIndex & 0x0fffffff;
1083 // it is a shared key
1084 if (KeyIdx > 4)
1085 Status = -EINVAL;
1086 else
1088 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
1089 NdisMoveMemory(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
1090 if (pKey->KeyIndex & 0x80000000)
1092 // Default key for tx (shared key)
1093 pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
1097 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength);
1099 kfree(pKey);
1100 break;
1101 case OID_802_11_CONFIGURATION:
1102 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
1103 Status = -EINVAL;
1104 else
1106 copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
1107 pConfig = &Config;
1108 pAdapter->PortCfg.IbssConfig.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
1109 pAdapter->PortCfg.IbssConfig.AtimWin = (USHORT) pConfig->ATIMWindow;
1110 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->PortCfg.IbssConfig.Channel);
1111 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_CONFIGURATION (BeacnPeriod=%d,AtimW=%d,Ch=%d)\n",
1112 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->PortCfg.IbssConfig.Channel);
1113 // Config has changed
1114 pAdapter->bConfigChanged = TRUE;
1116 break;
1117 default:
1118 DBGPRINT(RT_DEBUG_TRACE, "Set::unknown IOCTL's subcmd = 0x%08x\n", cmd);
1119 Status = -EOPNOTSUPP;
1120 break;
1123 return Status;
1126 INT RTMPQueryInformation(
1127 IN PRTMP_ADAPTER pAdapter,
1128 IN OUT struct ifreq *rq,
1129 IN INT cmd)
1131 struct iwreq *wrq = (struct iwreq *) rq;
1132 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
1133 PNDIS_WLAN_BSSID_EX pBss;
1134 NDIS_802_11_SSID Ssid;
1135 NDIS_802_11_CONFIGURATION Configuration;
1136 RT_802_11_LINK_STATUS LinkStatus;
1137 RT_802_11_STA_CONFIG StaConfig;
1138 NDIS_802_11_STATISTICS Statistics;
1139 NDIS_802_11_RTS_THRESHOLD RtsThresh;
1140 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1141 NDIS_802_11_POWER_MODE PowerMode;
1142 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
1143 RT_802_11_PREAMBLE PreamType;
1144 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
1145 NDIS_802_11_WEP_STATUS WepStatus;
1146 RT_VERSION_INFO DriverVersionInfo;
1147 ULONG BssBufSize;
1148 ULONG BssLen;
1149 ULONG ulInfo = 0;
1150 ULONG FcsValue;
1151 PUCHAR pBuf = NULL;
1152 PUCHAR pPtr;
1153 INT Status = NDIS_STATUS_SUCCESS;
1154 UCHAR Padding;
1155 UINT i;
1156 BOOLEAN RadioState;
1158 switch(cmd) {
1159 case RT_OID_DEVICE_NAME:
1160 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_DEVICE_NAME\n");
1161 wrq->u.data.length = sizeof(NIC_DEVICE_NAME);
1162 copy_to_user(wrq->u.data.pointer, NIC_DEVICE_NAME, wrq->u.data.length);
1163 break;
1164 case RT_OID_VERSION_INFO:
1165 DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_VERSION_INFO \n");
1166 DriverVersionInfo.DriverVersionW = 1;
1167 DriverVersionInfo.DriverVersionX = 4;
1168 DriverVersionInfo.DriverVersionY = 3;
1169 DriverVersionInfo.DriverVersionZ = 0;
1170 DriverVersionInfo.DriverBuildYear = 2004;
1171 DriverVersionInfo.DriverBuildMonth = 9;
1172 DriverVersionInfo.DriverBuildDay = 8;
1173 wrq->u.data.length = sizeof(RT_VERSION_INFO);
1174 copy_to_user(wrq->u.data.pointer, &DriverVersionInfo, wrq->u.data.length);
1175 break;
1176 case OID_802_11_BSSID_LIST:
1177 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->PortCfg.BssTab.BssNr);
1178 // Claculate total buffer size required
1179 BssBufSize = sizeof(ULONG);
1181 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1183 // Align pointer to 4 bytes boundary.
1184 Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1185 if (Padding == 4)
1186 Padding = 0;
1187 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding);
1190 // For safety issue, we add 256 bytes just in case
1191 BssBufSize += 256;
1192 // Allocate the same size as passed from higher layer
1193 pBuf = kmalloc(BssBufSize, GFP_KERNEL);
1194 if(pBuf == NULL)
1196 Status = -ENOMEM;
1197 break;
1199 // Init 802_11_BSSID_LIST_EX structure
1200 NdisZeroMemory(pBuf, BssBufSize);
1201 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
1202 pBssidList->NumberOfItems = pAdapter->PortCfg.BssTab.BssNr;
1204 // Calculate total buffer length
1205 BssLen = 4; // Consist of NumberOfItems
1206 // Point to start of NDIS_WLAN_BSSID_EX
1207 // pPtr = pBuf + sizeof(ULONG);
1208 pPtr = (PUCHAR) &pBssidList->Bssid[0];
1209 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1211 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
1212 NdisMoveMemory(&pBss->MacAddress, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
1213 if ((pAdapter->PortCfg.BssTab.BssEntry[i].Hidden == 1) && (pAdapter->PortCfg.bShowHiddenSSID == FALSE))
1215 pBss->Ssid.SsidLength = 0;
1217 else
1219 pBss->Ssid.SsidLength = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
1220 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen);
1222 pBss->Privacy = pAdapter->PortCfg.BssTab.BssEntry[i].Privacy;
1223 pBss->Rssi = pAdapter->PortCfg.BssTab.BssEntry[i].Rssi - RSSI_TO_DBM_OFFSET;
1224 pBss->NetworkTypeInUse = Ndis802_11DS;
1225 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1226 pBss->Configuration.BeaconPeriod = pAdapter->PortCfg.BssTab.BssEntry[i].BeaconPeriod;
1227 pBss->Configuration.ATIMWindow = pAdapter->PortCfg.BssTab.BssEntry[i].AtimWin;
1229 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.BssTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
1231 if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == BSS_INFRA)
1232 pBss->InfrastructureMode = Ndis802_11Infrastructure;
1233 else
1234 pBss->InfrastructureMode = Ndis802_11IBSS;
1236 NdisMoveMemory(pBss->SupportedRates, pAdapter->PortCfg.BssTab.BssEntry[i].Rates, pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen);
1238 DBGPRINT(RT_DEBUG_TRACE, "BSS#%d - %s, Ch %d = %d Khz\n",
1239 i,pBss->Ssid.Ssid,pAdapter->PortCfg.BssTab.BssEntry[i].Channel,pBss->Configuration.DSConfig);
1241 if (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen == 0)
1243 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
1244 NdisMoveMemory(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1245 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs);
1247 else
1249 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1250 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs);
1251 NdisMoveMemory(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1252 NdisMoveMemory(pPtr, pAdapter->PortCfg.BssTab.BssEntry[i].VarIEs, pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen);
1253 pPtr += pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1255 // Align pointer to 4 bytes boundary.
1256 Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1257 if (Padding == 4)
1258 Padding = 0;
1259 pPtr += Padding;
1260 pBss->Length = sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding;
1261 BssLen += pBss->Length;
1263 wrq->u.data.length = BssLen;
1264 copy_to_user(wrq->u.data.pointer, pBssidList, wrq->u.data.length);
1265 kfree(pBssidList);
1266 break;
1267 case OID_802_3_CURRENT_ADDRESS:
1268 wrq->u.data.length = ETH_LENGTH_OF_ADDRESS;
1269 copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
1270 DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_3_CURRENT_ADDRESS \n");
1271 break;
1272 case OID_GEN_MEDIA_CONNECT_STATUS:
1273 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_MEDIA_CONNECT_STATUS \n");
1274 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
1275 copy_to_user(wrq->u.data.pointer, &pAdapter->MediaState, wrq->u.data.length);
1276 break;
1277 case OID_802_11_BSSID:
1278 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1280 copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.Bssid, sizeof(MACADDR));
1282 DBGPRINT(RT_DEBUG_INFO, "IOCTL::SIOCGIWAP(=%02x:%02x:%02x:%02x:%02x:%02x)\n",
1283 pAdapter->PortCfg.Bssid.Octet[0],pAdapter->PortCfg.Bssid.Octet[1],pAdapter->PortCfg.Bssid.Octet[2],
1284 pAdapter->PortCfg.Bssid.Octet[3],pAdapter->PortCfg.Bssid.Octet[4],pAdapter->PortCfg.Bssid.Octet[5]);
1287 else
1289 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_BSSID(=EMPTY)\n");
1290 Status = -ENOTCONN;
1292 break;
1293 case OID_802_11_SSID:
1294 Ssid.SsidLength = pAdapter->PortCfg.SsidLen;
1295 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
1296 NdisMoveMemory(Ssid.Ssid, pAdapter->PortCfg.Ssid, Ssid.SsidLength);
1297 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
1298 copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
1299 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid);
1300 break;
1301 case RT_OID_802_11_LINK_STATUS:
1302 LinkStatus.CurrTxRate = RateIdTo500Kbps[pAdapter->PortCfg.TxRate]; // unit : 500 kbps
1303 LinkStatus.ChannelQuality = pAdapter->Mlme.ChannelQuality;
1304 LinkStatus.RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
1305 LinkStatus.TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
1306 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
1307 copy_to_user(wrq->u.data.pointer, &LinkStatus, wrq->u.data.length);
1308 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_LINK_STATUS\n");
1309 break;
1310 case OID_802_11_CONFIGURATION:
1311 Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1312 Configuration.BeaconPeriod = pAdapter->PortCfg.BeaconPeriod;
1313 Configuration.ATIMWindow = pAdapter->PortCfg.AtimWin;
1314 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, Configuration.DSConfig);
1315 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
1316 copy_to_user(wrq->u.data.pointer, &Configuration, wrq->u.data.length);
1317 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_CONFIGURATION(BeaconPeriod=%d,AtimW=%d,Channel=%d) \n",
1318 Configuration.BeaconPeriod, Configuration.ATIMWindow, pAdapter->PortCfg.Channel);
1319 break;
1320 case OID_802_11_RSSI:
1321 ulInfo = pAdapter->PortCfg.LastRssi - RSSI_TO_DBM_OFFSET;
1322 wrq->u.data.length = sizeof(ulInfo);
1323 copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1324 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_RSSI(=%d)\n", ulInfo);
1325 break;
1326 case OID_802_11_STATISTICS:
1327 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_STATISTICS \n");
1328 // Update FCS counters
1329 RTMP_IO_READ32(pAdapter, CNT0, &FcsValue);
1330 pAdapter->WlanCounters.FCSErrorCount.QuadPart += ((FcsValue & 0x0000ffff) >> 7);
1331 // Add FCS error count to private counters
1332 pAdapter->RalinkCounters.RealFcsErrCount.QuadPart += FcsValue;
1334 // Sanity check for calculation of sucessful count
1335 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
1336 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1338 Statistics.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
1339 Statistics.MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
1340 Statistics.FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
1341 Statistics.RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1342 Statistics.MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
1343 Statistics.RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
1344 Statistics.RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
1345 Statistics.ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
1346 Statistics.FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
1347 Statistics.ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
1348 Statistics.MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
1349 #ifdef RT2500_DBG
1350 Statistics.FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
1351 #else
1352 Statistics.FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
1353 Statistics.FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
1354 #endif
1355 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
1356 copy_to_user(wrq->u.data.pointer, &Statistics, wrq->u.data.length);
1357 break;
1358 case OID_GEN_RCV_OK:
1359 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_OK \n");
1360 ulInfo = pAdapter->Counters.GoodReceives;
1361 wrq->u.data.length = sizeof(ulInfo);
1362 copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1363 break;
1364 case OID_GEN_RCV_NO_BUFFER:
1365 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_NO_BUFFER \n");
1366 ulInfo = pAdapter->Counters.RxNoBuffer;
1367 wrq->u.data.length = sizeof(ulInfo);
1368 copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1369 break;
1370 case RT_OID_802_11_PHY_MODE:
1371 ulInfo = (ULONG)pAdapter->PortCfg.PhyMode;
1372 wrq->u.data.length = sizeof(ulInfo);
1373 copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1374 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_PHY_MODE (=%d)\n", ulInfo);
1375 break;
1376 case RT_OID_802_11_STA_CONFIG:
1377 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_STA_CONFIG\n");
1378 StaConfig.EnableTxBurst = pAdapter->PortCfg.EnableTxBurst;
1379 StaConfig.EnableTurboRate = pAdapter->PortCfg.EnableTurboRate;
1380 StaConfig.UseBGProtection = pAdapter->PortCfg.UseBGProtection;
1381 StaConfig.UseShortSlotTime = pAdapter->PortCfg.UseShortSlotTime;
1382 StaConfig.AdhocMode = pAdapter->PortCfg.AdhocMode;
1383 StaConfig.HwRadioStatus = (pAdapter->PortCfg.bHwRadio == TRUE) ? 1 : 0;
1384 StaConfig.Rsv1 = 0;
1385 StaConfig.SystemErrorBitmap = pAdapter->PortCfg.SystemErrorBitmap;
1386 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
1387 copy_to_user(wrq->u.data.pointer, &StaConfig, wrq->u.data.length);
1388 break;
1389 case OID_802_11_RTS_THRESHOLD:
1390 RtsThresh = pAdapter->PortCfg.RtsThreshold;
1391 wrq->u.data.length = sizeof(RtsThresh);
1392 copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
1393 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_RTS_THRESHOLD(=%d)\n", RtsThresh);
1394 break;
1395 case OID_802_11_FRAGMENTATION_THRESHOLD:
1396 FragThresh = pAdapter->PortCfg.FragmentThreshold;
1397 if (pAdapter->PortCfg.bFragmentZeroDisable == TRUE)
1398 FragThresh = 0;
1399 wrq->u.data.length = sizeof(FragThresh);
1400 copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
1401 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%d)\n", FragThresh);
1402 break;
1403 case OID_802_11_POWER_MODE:
1404 PowerMode = pAdapter->PortCfg.WindowsPowerMode;
1405 wrq->u.data.length = sizeof(PowerMode);
1406 copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
1407 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode);
1408 break;
1409 case RT_OID_802_11_RADIO:
1410 RadioState = (BOOLEAN) pAdapter->PortCfg.bSwRadio;
1411 wrq->u.data.length = sizeof(RadioState);
1412 copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
1413 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState);
1414 break;
1415 case OID_802_11_INFRASTRUCTURE_MODE:
1416 if (ADHOC_ON(pAdapter))
1417 BssType = Ndis802_11IBSS;
1418 else if (INFRA_ON(pAdapter))
1419 BssType = Ndis802_11Infrastructure;
1420 else
1421 BssType = Ndis802_11AutoUnknown;
1423 wrq->u.data.length = sizeof(BssType);
1424 copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
1425 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType);
1426 break;
1427 case RT_OID_802_11_PREAMBLE:
1428 PreamType = pAdapter->PortCfg.WindowsTxPreamble;
1429 wrq->u.data.length = sizeof(PreamType);
1430 copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
1431 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_PREAMBLE(=%d)\n", PreamType);
1432 break;
1433 case OID_802_11_AUTHENTICATION_MODE:
1434 AuthMode = pAdapter->PortCfg.AuthMode;
1435 wrq->u.data.length = sizeof(AuthMode);
1436 copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
1437 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode);
1438 break;
1439 case OID_802_11_WEP_STATUS:
1440 WepStatus = pAdapter->PortCfg.WepStatus;
1441 wrq->u.data.length = sizeof(WepStatus);
1442 copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
1443 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus);
1444 break;
1446 case RT_OID_802_11_QUERY_EEPROM_VERSION:
1447 wrq->u.data.length = sizeof(ULONG);
1448 copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.EepromVersion, wrq->u.data.length);
1449 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_EEPROM_VERSION (=%d)\n", pAdapter->PortCfg.EepromVersion);
1450 break;
1452 default:
1453 DBGPRINT(RT_DEBUG_TRACE, "Query::unknown IOCTL's subcmd = 0x%08x\n", cmd);
1454 Status = -EOPNOTSUPP;
1455 break;
1458 return Status;
1461 INT RT2500_ioctl(
1462 IN struct net_device *net_dev,
1463 IN OUT struct ifreq *rq,
1464 IN INT cmd)
1466 PRTMP_ADAPTER pAdapter= net_dev->priv;
1467 struct iwreq *wrq = (struct iwreq *) rq;
1468 struct iw_point *erq = NULL;
1469 struct iw_freq *frq = NULL;
1470 NDIS_802_11_SSID Ssid, *pSsid=NULL;
1471 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType = Ndis802_11Infrastructure;
1472 NDIS_802_11_RTS_THRESHOLD RtsThresh;
1473 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1474 NDIS_802_11_MAC_ADDRESS Bssid;
1475 INT Status = NDIS_STATUS_SUCCESS;
1476 USHORT subcmd;
1477 BOOLEAN StateMachineTouched = FALSE;
1478 int i, chan = -1, index = 0, len = 0;
1480 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1482 DBGPRINT(RT_DEBUG_TRACE, "INFO::Network is down!\n");
1483 return -ENETDOWN;
1486 switch(cmd) {
1487 case SIOCGIWNAME:
1488 DBGPRINT(RT_DEBUG_TRACE, "IOCTL::SIOCGIWNAME\n");
1489 strcpy(wrq->u.name, "RT2500 Wireless"); //Less then 16 bytes.
1490 break;
1491 case SIOCSIWESSID: //Set ESSID
1492 erq = &wrq->u.essid;
1493 memset(&Ssid, 0x00, sizeof(NDIS_802_11_SSID));
1494 if (erq->flags)
1496 if (erq->length > IW_ESSID_MAX_SIZE)
1498 DBGPRINT(RT_DEBUG_ERROR, "--> SIOCSIWESSID (%s) =====> error (len=%d)\n", pSsid->Ssid, erq->length);
1499 Status = -E2BIG;
1500 break;
1503 copy_from_user(Ssid.Ssid, erq->pointer, (erq->length - 1));
1504 Ssid.SsidLength = erq->length - 1; //minus null character.
1506 else
1507 Ssid.SsidLength = 0; // ANY ssid
1509 pSsid = &Ssid;
1510 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1512 MlmeRestartStateMachine(pAdapter);
1513 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
1516 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1517 // this request, because this request is initiated by NDIS.
1518 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
1519 MlmeEnqueue(&pAdapter->Mlme.Queue,
1520 MLME_CNTL_STATE_MACHINE,
1521 OID_802_11_SSID,
1522 sizeof(NDIS_802_11_SSID),
1523 (VOID *)pSsid
1525 Status = NDIS_STATUS_SUCCESS;
1526 StateMachineTouched = TRUE;
1528 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWESSID[cmd=0x%x] (Len=%d,Ssid=%s)\n", SIOCSIWESSID, pSsid->SsidLength, pSsid->Ssid);
1529 break;
1530 case SIOCGIWESSID: //Get ESSID
1531 erq = &wrq->u.essid;
1533 if(pAdapter->MediaState == NdisMediaStateConnected)
1535 erq->flags=1;
1536 erq->length = pAdapter->PortCfg.SsidLen;
1537 copy_to_user(erq->pointer, pAdapter->PortCfg.Ssid, erq->length);
1539 else
1540 {//the ANY ssid was specified
1541 erq->flags=0;
1542 erq->length=0;
1544 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWESSID (Len=%d, ssid=%s...)\n", erq->length, erq->pointer);
1545 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWESSID, AutoReconnect=%d, CurrState=%d, MediaState=%d, RfType=%d\n", pAdapter->PortCfg.AutoReconnect, pAdapter->Mlme.CntlMachine.CurrState, pAdapter->MediaState, pAdapter->PortCfg.RfType);
1546 break;
1547 case SIOCGIWNWID: // get network id
1548 Status = -EOPNOTSUPP;
1549 break;
1550 case SIOCSIWNWID: // set network id (the cell)
1551 Status = -EOPNOTSUPP;
1552 break;
1553 case SIOCSIWFREQ: // set channel/frequency (Hz)
1554 frq = &wrq->u.freq;
1555 if((frq->e == 0) && (frq->m <= 1000))
1556 chan = frq->m; // Setting by channel number
1557 else
1558 MAP_KHZ_TO_CHANNEL_ID( (frq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
1559 pAdapter->PortCfg.IbssConfig.Channel = chan;
1560 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->PortCfg.IbssConfig.Channel);
1561 break;
1562 case SIOCGIWFREQ: // get channel/frequency (Hz)
1563 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1564 wrq->u.freq.m = pAdapter->PortCfg.Channel;
1565 else
1566 wrq->u.freq.m = pAdapter->PortCfg.IbssConfig.Channel;
1567 wrq->u.freq.e = 0;
1568 wrq->u.freq.i = 0;
1569 break;
1570 case SIOCGIWNICKN: //get node name/nickname
1571 erq = &wrq->u.data;
1572 erq->length = strlen(pAdapter->nickn);
1573 copy_to_user(erq->pointer, pAdapter->nickn, erq->length);
1574 break;
1575 case SIOCSIWNICKN: //set node name/nickname
1576 erq = &wrq->u.data;
1577 if (erq->flags)
1579 if (erq->length <= IW_ESSID_MAX_SIZE)
1580 copy_from_user(pAdapter->nickn, erq->pointer, erq->length);
1581 else
1582 Status = -E2BIG;
1584 break;
1585 case SIOCGIWRATE: //get default bit rate (bps)
1586 wrq->u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.TxRate] * 1000000;
1587 wrq->u.bitrate.disabled = 0;
1588 break;
1589 case SIOCSIWRATE: //set default bit rate (bps)
1590 RTMPSetDesiredRates(pAdapter, wrq->u.bitrate.value);
1591 break;
1592 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
1593 wrq->u.rts.value = (INT) pAdapter->PortCfg.RtsThreshold;
1594 wrq->u.rts.disabled = (wrq->u.rts.value == MAX_RTS_THRESHOLD);
1595 wrq->u.rts.fixed = 1;
1596 break;
1597 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
1598 RtsThresh = wrq->u.rts.value;
1599 if (wrq->u.rts.disabled)
1600 RtsThresh = MAX_RTS_THRESHOLD;
1602 if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
1603 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
1604 else if (RtsThresh == 0)
1605 pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1607 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWRTS (=%d)\n", pAdapter->PortCfg.RtsThreshold);
1608 break;
1609 case SIOCGIWFRAG: //get fragmentation thr (bytes)
1610 wrq->u.frag.value = (INT) pAdapter->PortCfg.FragmentThreshold;
1611 wrq->u.frag.disabled = (wrq->u.frag.value >= MAX_FRAG_THRESHOLD);
1612 wrq->u.frag.fixed = 1;
1613 break;
1614 case SIOCSIWFRAG: //set fragmentation thr (bytes)
1615 FragThresh = wrq->u.frag.value;
1616 if (wrq->u.rts.disabled)
1617 FragThresh = MAX_FRAG_THRESHOLD;
1619 if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
1620 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
1621 else if (FragThresh == 0)
1622 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1624 if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
1625 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
1626 else
1627 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
1629 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWFRAG (=%d)\n", pAdapter->PortCfg.FragmentThreshold);
1630 break;
1631 case SIOCGIWENCODE: //get encoding token & mode
1632 index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
1633 if ((index < 0) || (index >= NR_WEP_KEYS))
1634 index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
1636 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeOpen)
1637 wrq->u.encoding.flags = IW_ENCODE_OPEN;
1638 else if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeShared)
1639 wrq->u.encoding.flags = IW_ENCODE_RESTRICTED;
1641 if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
1642 wrq->u.encoding.flags |= IW_ENCODE_DISABLED;
1643 else
1645 if(wrq->u.encoding.pointer)
1647 wrq->u.encoding.length = pAdapter->PortCfg.SharedKey[index].KeyLen;
1648 copy_to_user(wrq->u.encoding.pointer,
1649 pAdapter->PortCfg.SharedKey[index].Key,
1650 pAdapter->PortCfg.SharedKey[index].KeyLen);
1651 wrq->u.encoding.flags |= (index + 1);
1654 break;
1655 case SIOCSIWENCODE: //set encoding token & mode
1656 index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
1657 /* take the old default key if index is invalid */
1658 if((index < 0) || (index >= NR_WEP_KEYS))
1659 index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
1661 if(wrq->u.encoding.pointer)
1663 len = wrq->u.encoding.length;
1664 if(len > WEP_LARGE_KEY_LEN)
1665 len = WEP_LARGE_KEY_LEN;
1667 memset(pAdapter->PortCfg.SharedKey[index].Key, 0x00, MAX_LEN_OF_KEY);
1668 copy_from_user(pAdapter->PortCfg.SharedKey[index].Key,
1669 wrq->u.encoding.pointer, len);
1670 pAdapter->PortCfg.SharedKey[index].KeyLen = len <= WEP_SMALL_KEY_LEN ? WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
1672 pAdapter->PortCfg.DefaultKeyId = (UCHAR) index;
1673 if (wrq->u.encoding.flags & IW_ENCODE_DISABLED)
1674 pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
1675 else
1676 pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
1678 if (wrq->u.encoding.flags & IW_ENCODE_RESTRICTED)
1679 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
1680 else
1681 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
1683 if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
1684 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
1686 //#ifdef RT2500_DBG
1687 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWENCODE Key[%x] => \n", index);
1688 for (i = 0; i < len; i++)
1690 DBGPRINT(RT_DEBUG_TRACE, "%02x:", pAdapter->PortCfg.SharedKey[index].Key[i]);
1691 if (i%16 == 15)
1692 DBGPRINT(RT_DEBUG_TRACE, "\n");
1694 DBGPRINT(RT_DEBUG_TRACE, "\n");
1695 //#endif
1696 break;
1697 case SIOCGIWAP: //get access point MAC addresses
1698 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1700 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
1701 memcpy(wrq->u.ap_addr.sa_data, &pAdapter->PortCfg.Bssid, ETH_ALEN);
1703 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=%02x:%02x:%02x:%02x:%02x:%02x)\n",
1704 pAdapter->PortCfg.Bssid.Octet[0], pAdapter->PortCfg.Bssid.Octet[1], pAdapter->PortCfg.Bssid.Octet[2],
1705 pAdapter->PortCfg.Bssid.Octet[3], pAdapter->PortCfg.Bssid.Octet[4], pAdapter->PortCfg.Bssid.Octet[5]);
1707 else
1709 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=EMPTY)\n");
1710 Status = -ENOTCONN;
1712 break;
1713 case SIOCSIWAP: //set access point MAC addresses
1714 memcpy(&Bssid, &wrq->u.ap_addr.sa_data, sizeof(NDIS_802_11_MAC_ADDRESS));
1715 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1717 MlmeRestartStateMachine(pAdapter);
1718 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
1721 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1722 // this request, because this request is initiated by NDIS.
1723 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
1725 MlmeEnqueue(&pAdapter->Mlme.Queue,
1726 MLME_CNTL_STATE_MACHINE,
1727 OID_802_11_BSSID,
1728 sizeof(NDIS_802_11_MAC_ADDRESS),
1729 (VOID *)&Bssid);
1730 Status = NDIS_STATUS_SUCCESS;
1731 StateMachineTouched = TRUE;
1732 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
1733 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]);
1734 break;
1735 case SIOCGIWMODE: //get operation mode
1736 if (ADHOC_ON(pAdapter))
1738 BssType = Ndis802_11IBSS;
1739 wrq->u.mode = IW_MODE_ADHOC;
1741 else if (INFRA_ON(pAdapter))
1743 BssType = Ndis802_11Infrastructure;
1744 wrq->u.mode = IW_MODE_INFRA;
1746 else
1748 BssType = Ndis802_11AutoUnknown;
1749 wrq->u.mode = IW_MODE_AUTO;
1751 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWMODE(=%d)\n", BssType);
1752 break;
1753 case SIOCSIWMODE: //set operation mode
1754 if(wrq->u.mode == IW_MODE_ADHOC)
1756 if (pAdapter->PortCfg.BssType != BSS_INDEP)
1758 // Config has changed
1759 pAdapter->bConfigChanged = TRUE;
1761 pAdapter->PortCfg.BssType = BSS_INDEP;
1762 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (AD-HOC)\n");
1764 else if (wrq->u.mode == IW_MODE_INFRA)
1766 if (pAdapter->PortCfg.BssType != BSS_INFRA)
1768 // Config has changed
1769 pAdapter->bConfigChanged = TRUE;
1771 pAdapter->PortCfg.BssType = BSS_INFRA;
1772 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (INFRA)\n");
1774 else
1776 Status = -EINVAL;
1777 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (unknown)\n");
1779 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1780 pAdapter->PortCfg.WpaState = SS_NOTUSE;
1781 break;
1782 case SIOCGIWSENS: //get sensitivity (dBm)
1783 case SIOCSIWSENS: //set sensitivity (dBm)
1784 case SIOCGIWPOWER: //get Power Management settings
1785 case SIOCSIWPOWER: //set Power Management settings
1786 case SIOCGIWTXPOW: //get transmit power (dBm)
1787 case SIOCSIWTXPOW: //set transmit power (dBm)
1788 Status = -EOPNOTSUPP;
1789 break;
1790 case RT_PRIV_IOCTL:
1791 subcmd = wrq->u.data.flags;
1792 if( subcmd & OID_GET_SET_TOGGLE)
1793 Status = RTMPSetInformation(pAdapter, rq, subcmd);
1794 else
1795 Status = RTMPQueryInformation(pAdapter, rq, subcmd);
1796 break;
1797 case SIOCGIWPRIV:
1798 if (wrq->u.data.pointer) {
1799 if ( verify_area(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) )
1800 break;
1801 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
1802 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
1803 Status = -EFAULT;
1805 break;
1806 case RTPRIV_IOCTL_SET:
1808 char *this_char;
1809 char *value;
1811 if( verify_area(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) )
1812 break;
1814 while ((this_char = strsep((char**)&wrq->u.data.pointer, ",")) != NULL)
1816 if (!*this_char)
1817 continue;
1819 if ((value = rtstrchr(this_char, '=')) != NULL)
1820 *value++ = 0;
1822 if (!value || !*value)
1823 continue;
1825 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1827 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1829 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1830 { //FALSE:Set private failed then return Invalid argument
1831 Status = -EINVAL;
1833 break; //Exit for loop.
1837 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1838 { //Not found argument
1839 Status = -EINVAL;
1840 DBGPRINT(RT_DEBUG_TRACE, "ioctl::(iwpriv) Not Support Set Command [%s=%s]\n", this_char, value);
1841 break;
1845 break;
1847 case RTPRIV_IOCTL_BBP:
1848 RTMPIoctlBBP(pAdapter, wrq);
1849 break;
1851 case RTPRIV_IOCTL_MAC:
1852 RTMPIoctlMAC(pAdapter, wrq);
1853 break;
1855 case RTPRIV_IOCTL_E2P:
1856 RTMPIoctlE2PROM(pAdapter, wrq);
1857 break;
1859 default:
1860 DBGPRINT(RT_DEBUG_TRACE, "IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd);
1861 Status = -EOPNOTSUPP;
1862 break;
1865 if(StateMachineTouched) // Upper layer sent a MLME-related operations
1866 MlmeHandler(pAdapter);
1868 return Status;
1872 UCHAR BCAST[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1874 ========================================================================
1876 Routine Description:
1877 Add WPA key process
1879 Arguments:
1880 pAdapter Pointer to our adapter
1881 pBuf Pointer to the where the key stored
1883 Return Value:
1884 NDIS_SUCCESS Add key successfully
1886 Note:
1888 ========================================================================
1890 NDIS_STATUS RTMPWPAAddKeyProc(
1891 IN PRTMP_ADAPTER pAdapter,
1892 IN PVOID pBuf)
1894 PNDIS_802_11_KEY pKey;
1895 ULONG KeyIdx;
1896 NDIS_STATUS Status;
1897 PUCHAR pTxMic, pRxMic;
1898 BOOLEAN bTxKey; // Set the key as transmit key
1899 BOOLEAN bPairwise; // Indicate the key is pairwise key
1900 BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
1901 // Otherwise, it will set by the NIC.
1902 BOOLEAN bAuthenticator; // indicate key is set by authenticator.
1903 INT i, PairwiseIdx;
1905 pKey = (PNDIS_802_11_KEY) pBuf;
1906 KeyIdx = pKey->KeyIndex & 0xff;
1907 // Bit 31 of Add-key, Tx Key
1908 bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
1909 // Bit 30 of Add-key PairwiseKey
1910 bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
1911 // Bit 29 of Add-key KeyRSC
1912 bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
1913 // Bit 28 of Add-key Authenticator
1914 bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
1916 // 1. Check Group / Pairwise Key
1917 if (bPairwise) // Pairwise Key
1919 // 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
1920 if (KeyIdx != 0)
1921 return(NDIS_STATUS_FAILURE);
1923 // 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
1924 if (bTxKey == FALSE)
1925 return(NDIS_STATUS_FAILURE);
1927 // 3. If BSSID is not all 0xff, return NDIS_STATUS_INVALID_DATA
1928 if (NdisEqualMemory(pKey->BSSID, BCAST, 6))
1929 return(NDIS_STATUS_FAILURE);
1931 // 4. Selct RxMic / TxMic based on Supp / Authenticator
1932 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
1934 // for WPA-None Tx, Rx MIC is the same
1935 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
1936 pRxMic = pTxMic;
1938 else if (bAuthenticator == TRUE)
1940 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
1941 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
1943 else
1945 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
1946 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
1949 // 5. Find the old entry to overwrite or find an empty entry.
1950 PairwiseIdx = 0;
1951 for (i = 0; i < PAIRWISE_KEY_NO; i++)
1953 if (pAdapter->PortCfg.PairwiseKey[i].KeyLen == 0)
1955 PairwiseIdx = i;
1956 break;
1958 else if (RTMPEqualMemory(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6))
1960 // Found the old entry
1961 PairwiseIdx = i;
1962 break;
1965 // If there is no match and no empty pairwise key, we have to replace an old one
1966 // which will be index 0 in our case.
1968 // 6. Check RxTsc
1969 if (bKeyRSC == TRUE)
1971 NdisMoveMemory(&pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, &pKey->KeyRSC, 6);
1973 else
1975 NdisZeroMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, 6);
1978 // 7. Copy information into Pairwise Key structure.
1979 // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
1980 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].KeyLen = 16;
1981 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key, &pKey->KeyMaterial, 16);
1982 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic, pRxMic, 8);
1983 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic, pTxMic, 8);
1984 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].BssId, pKey->BSSID, 6);
1985 // Init TxTsc to one based on WiFi WPA specs
1986 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[0] = 1;
1987 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[1] = 0;
1988 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[2] = 0;
1989 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[3] = 0;
1990 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[4] = 0;
1991 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[5] = 0;
1992 Status = NDIS_STATUS_SUCCESS;
1994 DBGPRINT(RT_DEBUG_INFO, "TKIP Key = ");
1995 for (i = 0; i < 16; i++)
1997 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key[i]);
1999 DBGPRINT(RT_DEBUG_INFO, "\n");
2000 DBGPRINT(RT_DEBUG_INFO, "TKIP Rx MIC Key = ");
2001 for (i = 0; i < 8; i++)
2003 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic[i]);
2005 DBGPRINT(RT_DEBUG_INFO, "\n");
2006 DBGPRINT(RT_DEBUG_INFO, "TKIP Tx MIC Key = ");
2007 for (i = 0; i < 8; i++)
2009 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic[i]);
2011 DBGPRINT(RT_DEBUG_INFO, "\n");
2012 DBGPRINT(RT_DEBUG_INFO, "TKIP RxTSC = ");
2013 for (i = 0; i < 6; i++)
2015 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc[i]);
2017 DBGPRINT(RT_DEBUG_INFO, "\n");
2018 DBGPRINT(RT_DEBUG_INFO, "BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2019 pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2022 else // Group Key
2024 // 1. Check BSSID, if not current BSSID or Bcast, return NDIS_STATUS_INVALID_DATA
2025 if ((!NdisEqualMemory(&pKey->BSSID, &BCAST, 6)) &&
2026 (!NdisEqualMemory(&pKey->BSSID, &pAdapter->PortCfg.Bssid, 6)))
2027 return(NDIS_STATUS_FAILURE);
2030 // 2. Check Key index for supported Group Key
2031 if (KeyIdx >= GROUP_KEY_NO)
2032 return(NDIS_STATUS_FAILURE);
2034 // 3. Set as default Tx Key if bTxKey is TRUE
2035 if (bTxKey == TRUE)
2036 pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
2038 // 4. Selct RxMic / TxMic based on Supp / Authenticator
2039 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2041 // for WPA-None Tx, Rx MIC is the same
2042 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2043 pRxMic = pTxMic;
2045 else if (bAuthenticator == TRUE)
2047 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2048 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2050 else
2052 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2053 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2056 // 5. Check RxTsc
2057 if (bKeyRSC == TRUE)
2059 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, &pKey->KeyRSC, 6);
2061 else
2063 NdisZeroMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, 6);
2066 // 6. Copy information into Group Key structure.
2067 // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
2068 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 16;
2069 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].Key, &pKey->KeyMaterial, 16);
2070 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxMic, pRxMic, 8);
2071 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].TxMic, pTxMic, 8);
2072 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6);
2073 // Init TxTsc to one based on WiFi WPA specs
2074 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[0] = 1;
2075 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[1] = 0;
2076 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[2] = 0;
2077 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[3] = 0;
2078 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[4] = 0;
2079 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[5] = 0;
2080 // 802.1x port control
2081 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2082 Status = NDIS_STATUS_SUCCESS;
2084 // For WEP compatibility, in case it use OID_ADD_KEY, not OID_ADD_WEP
2085 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2087 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
2088 NdisMoveMemory(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
2091 DBGPRINT(RT_DEBUG_INFO, "TKIP Key = ");
2092 for (i = 0; i < 16; i++)
2094 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].Key[i]);
2096 DBGPRINT(RT_DEBUG_INFO, "\n");
2097 DBGPRINT(RT_DEBUG_INFO, "TKIP Rx MIC Key = ");
2098 for (i = 0; i < 8; i++)
2100 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxMic[i]);
2102 DBGPRINT(RT_DEBUG_INFO, "\n");
2103 DBGPRINT(RT_DEBUG_INFO, "TKIP Tx MIC Key = ");
2104 for (i = 0; i < 8; i++)
2106 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].TxMic[i]);
2108 DBGPRINT(RT_DEBUG_INFO, "\n");
2109 DBGPRINT(RT_DEBUG_INFO, "TKIP RxTSC = ");
2110 for (i = 0; i < 6; i++)
2112 DBGPRINT(RT_DEBUG_INFO, "%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc[i]);
2114 DBGPRINT(RT_DEBUG_INFO, "\n");
2115 DBGPRINT(RT_DEBUG_INFO, "BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2116 pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2119 return (Status);
2123 ========================================================================
2125 Routine Description:
2126 Remove WPA Key process
2128 Arguments:
2129 pAdapter Pointer to our adapter
2130 pBuf Pointer to the where the key stored
2132 Return Value:
2133 NDIS_SUCCESS Add key successfully
2135 Note:
2137 ========================================================================
2139 NDIS_STATUS RTMPWPARemoveKeyProc(
2140 IN PRTMP_ADAPTER pAdapter,
2141 IN PVOID pBuf)
2143 PNDIS_802_11_REMOVE_KEY pKey;
2144 ULONG KeyIdx;
2145 NDIS_STATUS Status = NDIS_STATUS_FAILURE;
2146 BOOLEAN bTxKey; // Set the key as transmit key
2147 BOOLEAN bPairwise; // Indicate the key is pairwise key
2148 BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
2149 // Otherwise, it will set by the NIC.
2150 BOOLEAN bAuthenticator; // indicate key is set by authenticator.
2151 INT i;
2153 pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
2154 KeyIdx = pKey->KeyIndex & 0xff;
2155 // Bit 31 of Add-key, Tx Key
2156 bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
2157 // Bit 30 of Add-key PairwiseKey
2158 bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
2159 // Bit 29 of Add-key KeyRSC
2160 bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
2161 // Bit 28 of Add-key Authenticator
2162 bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
2164 // 1. If bTx is TRUE, return failure information
2165 if (bTxKey == TRUE)
2166 return(NDIS_STATUS_FAILURE);
2168 // 2. Check Pairwise Key
2169 if (bPairwise)
2171 // a. If BSSID is broadcast, remove all pairwise keys.
2172 if (NdisEqualMemory(&pKey->BSSID, &BCAST, 6))
2174 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2176 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2178 Status = NDIS_STATUS_SUCCESS;
2181 // b. If not broadcast, remove the pairwise specified by BSSID
2182 else
2184 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2186 if (NdisEqualMemory(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6))
2188 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2189 Status = NDIS_STATUS_SUCCESS;
2190 break;
2195 // c. If no pairwise supported, delete Group Key 0.
2196 // The will be false since we do support pairwise keys.
2198 // 3. Group Key
2199 else
2201 // a. If BSSID is broadcast, remove all group keys indexed
2202 if (NdisEqualMemory(&pKey->BSSID, &BCAST, 6))
2204 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2205 Status = NDIS_STATUS_SUCCESS;
2208 // b. If BSSID matched, delte the group key indexed.
2209 else if (NdisEqualMemory(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6))
2211 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2212 Status = NDIS_STATUS_SUCCESS;
2215 // c. For WEP compatibility
2216 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2218 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
2222 return (Status);
2227 ========================================================================
2229 Routine Description:
2230 Remove All WPA Keys
2232 Arguments:
2233 pAdapter Pointer to our adapter
2235 Return Value:
2236 None
2238 Note:
2240 ========================================================================
2242 VOID RTMPWPARemoveAllKeys(
2243 IN PRTMP_ADAPTER pAdapter)
2245 INT i;
2247 // For WPA-None, there is no need to remove it, since WinXP won't set it again after
2248 // Link up. And it will be replaced if user changed it.
2249 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2250 return;
2252 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2254 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2257 for (i = 0; i < GROUP_KEY_NO; i++)
2259 pAdapter->PortCfg.GroupKey[i].KeyLen = 0;
2264 ========================================================================
2266 Routine Description:
2267 Change NIC PHY mode. Re-association may be necessary.
2269 Arguments:
2270 pAdapter Pointer to our adapter
2271 phmode
2273 ========================================================================
2275 VOID RTMPSetPhyMode(
2276 IN PRTMP_ADAPTER pAdapter,
2277 IN ULONG phymode)
2279 INT i;
2281 DBGPRINT(RT_DEBUG_TRACE,"RTMPSetPhyMode(=%d)\n", phymode);
2283 // the selected phymode must be supported by the RF IC encoded in E2PROM
2284 if (pAdapter->PortCfg.RfType < RFIC_5222)
2286 if (phymode == PHY_11A)
2287 phymode = PHY_11BG_MIXED;
2290 // if no change, do nothing
2291 if (pAdapter->PortCfg.PhyMode == phymode)
2292 return;
2294 pAdapter->PortCfg.PhyMode = (UCHAR)phymode;
2295 BuildChannelList(pAdapter);
2297 for (i = 0; i < pAdapter->PortCfg.ChannelListNum; i++)
2299 if (pAdapter->PortCfg.IbssConfig.Channel == pAdapter->PortCfg.ChannelList[i])
2300 break;
2302 if (i == pAdapter->PortCfg.ChannelListNum)
2303 pAdapter->PortCfg.IbssConfig.Channel = FirstChannel(pAdapter);
2304 pAdapter->PortCfg.Channel = pAdapter->PortCfg.IbssConfig.Channel;
2306 AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
2307 AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
2309 switch (phymode) {
2310 case PHY_11B:
2311 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2312 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2313 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2314 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2315 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 4;
2316 pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2317 pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2318 pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps
2319 pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2320 pAdapter->PortCfg.SupportedRatesLen = 4;
2321 pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2322 pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2323 pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2324 pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2325 pAdapter->PortCfg.DesiredRates[4] = 0;
2326 pAdapter->PortCfg.DesiredRates[5] = 0;
2327 pAdapter->PortCfg.DesiredRates[6] = 0;
2328 pAdapter->PortCfg.DesiredRates[7] = 0;
2329 pAdapter->PortCfg.DesiredRates[8] = 0;
2330 pAdapter->PortCfg.DesiredRates[9] = 0;
2331 pAdapter->PortCfg.DesiredRates[10] = 0;
2332 pAdapter->PortCfg.DesiredRates[11] = 0;
2333 break;
2335 case PHY_11BG_MIXED:
2336 case PHY_11ABG_MIXED:
2337 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2338 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2339 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2340 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2341 pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0x12; // 9 mbps, in units of 0.5 Mbps
2342 pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x24; // 18 mbps, in units of 0.5 Mbps
2343 pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x48; // 36 mbps, in units of 0.5 Mbps
2344 pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2345 pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2346 pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2347 pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2348 pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0x60; // 48 mbps, in units of 0.5 Mbps
2349 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 12;
2350 pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2351 pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2352 pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2353 pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2354 pAdapter->PortCfg.SupportedRates[4] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2355 pAdapter->PortCfg.SupportedRates[5] = 0x12; // 9 mbps, in units of 0.5 Mbps
2356 pAdapter->PortCfg.SupportedRates[6] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2357 pAdapter->PortCfg.SupportedRates[7] = 0x24; // 18 mbps, in units of 0.5 Mbps
2358 pAdapter->PortCfg.SupportedRates[8] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2359 pAdapter->PortCfg.SupportedRates[9] = 0x48; // 36 mbps, in units of 0.5 Mbps
2360 pAdapter->PortCfg.SupportedRates[10] = 0x60; // 48 mbps, in units of 0.5 Mbps
2361 pAdapter->PortCfg.SupportedRates[11] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2362 pAdapter->PortCfg.SupportedRatesLen = 12;
2363 pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2364 pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2365 pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2366 pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2367 pAdapter->PortCfg.DesiredRates[4] = 12; // 6 mbps, in units of 0.5 Mbps
2368 pAdapter->PortCfg.DesiredRates[5] = 18; // 9 mbps, in units of 0.5 Mbps
2369 pAdapter->PortCfg.DesiredRates[6] = 24; // 12 mbps, in units of 0.5 Mbps
2370 pAdapter->PortCfg.DesiredRates[7] = 36; // 18 mbps, in units of 0.5 Mbps
2371 pAdapter->PortCfg.DesiredRates[8] = 48; // 24 mbps, in units of 0.5 Mbps
2372 pAdapter->PortCfg.DesiredRates[9] = 72; // 36 mbps, in units of 0.5 Mbps
2373 pAdapter->PortCfg.DesiredRates[10] = 96; // 48 mbps, in units of 0.5 Mbps
2374 pAdapter->PortCfg.DesiredRates[11] = 108; // 54 mbps, in units of 0.5 Mbps
2375 break;
2377 case PHY_11A:
2378 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2379 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2380 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2381 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2382 pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2383 pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2384 pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2385 pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2386 pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0;
2387 pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0;
2388 pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0;
2389 pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0;
2390 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 8;
2391 pAdapter->PortCfg.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2392 pAdapter->PortCfg.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2393 pAdapter->PortCfg.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2394 pAdapter->PortCfg.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2395 pAdapter->PortCfg.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2396 pAdapter->PortCfg.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2397 pAdapter->PortCfg.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2398 pAdapter->PortCfg.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2399 pAdapter->PortCfg.SupportedRates[8] = 0;
2400 pAdapter->PortCfg.SupportedRates[9] = 0;
2401 pAdapter->PortCfg.SupportedRates[10] = 0;
2402 pAdapter->PortCfg.SupportedRates[11] = 0;
2403 pAdapter->PortCfg.SupportedRatesLen = 8;
2404 pAdapter->PortCfg.DesiredRates[0] = 12; // 6 mbps, in units of 0.5 Mbps
2405 pAdapter->PortCfg.DesiredRates[1] = 18; // 9 mbps, in units of 0.5 Mbps
2406 pAdapter->PortCfg.DesiredRates[2] = 24; // 12 mbps, in units of 0.5 Mbps
2407 pAdapter->PortCfg.DesiredRates[3] = 36; // 18 mbps, in units of 0.5 Mbps
2408 pAdapter->PortCfg.DesiredRates[4] = 48; // 24 mbps, in units of 0.5 Mbps
2409 pAdapter->PortCfg.DesiredRates[5] = 72; // 36 mbps, in units of 0.5 Mbps
2410 pAdapter->PortCfg.DesiredRates[6] = 96; // 48 mbps, in units of 0.5 Mbps
2411 pAdapter->PortCfg.DesiredRates[7] = 108; // 54 mbps, in units of 0.5 Mbps
2412 pAdapter->PortCfg.DesiredRates[8] = 0;
2413 pAdapter->PortCfg.DesiredRates[9] = 0;
2414 pAdapter->PortCfg.DesiredRates[10] = 0;
2415 pAdapter->PortCfg.DesiredRates[11] = 0;
2416 break;
2418 default:
2419 break;
2422 MlmeUpdateTxRates(pAdapter, FALSE);
2423 AsicSetSlotTime(pAdapter, FALSE);
2424 MakeIbssBeacon(pAdapter); // supported rates may change
2427 VOID RTMPSetDesiredRates(
2428 IN PRTMP_ADAPTER pAdapter,
2429 IN LONG Rates)
2431 NDIS_802_11_RATES aryRates;
2433 memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
2434 switch (pAdapter->PortCfg.PhyMode)
2436 case PHY_11A: // A only
2437 switch (Rates)
2439 case 6000000: //6M
2440 aryRates[0] = 0x0c; // 6M
2441 break;
2442 case 9000000: //9M
2443 aryRates[0] = 0x12; // 9M
2444 break;
2445 case 12000000: //12M
2446 aryRates[0] = 0x18; // 12M
2447 break;
2448 case 18000000: //18M
2449 aryRates[0] = 0x24; // 18M
2450 break;
2451 case 24000000: //24M
2452 aryRates[0] = 0x30; // 24M
2453 break;
2454 case 36000000: //36M
2455 aryRates[0] = 0x48; // 36M
2456 break;
2457 case 48000000: //48M
2458 aryRates[0] = 0x60; // 48M
2459 break;
2460 case 54000000: //54M
2461 aryRates[0] = 0x6c; // 54M
2462 break;
2463 case -1: //Auto
2464 default:
2465 aryRates[0] = 0x6c; // 54Mbps
2466 aryRates[1] = 0x60; // 48Mbps
2467 aryRates[2] = 0x48; // 36Mbps
2468 aryRates[3] = 0x30; // 24Mbps
2469 aryRates[4] = 0x24; // 18M
2470 aryRates[5] = 0x18; // 12M
2471 aryRates[6] = 0x12; // 9M
2472 aryRates[7] = 0x0c; // 6M
2473 break;
2475 break;
2476 case PHY_11BG_MIXED: // B/G Mixed
2477 case PHY_11B: // B only
2478 case PHY_11ABG_MIXED: // A/B/G Mixed
2479 default:
2480 switch (Rates)
2482 case 1000000: //1M
2483 aryRates[0] = 0x02;
2484 break;
2485 case 2000000: //2M
2486 aryRates[0] = 0x04;
2487 break;
2488 case 5000000: //5.5M
2489 aryRates[0] = 0x0b; // 5.5M
2490 break;
2491 case 11000000: //11M
2492 aryRates[0] = 0x16; // 11M
2493 break;
2494 case 6000000: //6M
2495 aryRates[0] = 0x0c; // 6M
2496 break;
2497 case 9000000: //9M
2498 aryRates[0] = 0x12; // 9M
2499 break;
2500 case 12000000: //12M
2501 aryRates[0] = 0x18; // 12M
2502 break;
2503 case 18000000: //18M
2504 aryRates[0] = 0x24; // 18M
2505 break;
2506 case 24000000: //24M
2507 aryRates[0] = 0x30; // 24M
2508 break;
2509 case 36000000: //36M
2510 aryRates[0] = 0x48; // 36M
2511 break;
2512 case 48000000: //48M
2513 aryRates[0] = 0x60; // 48M
2514 break;
2515 case 54000000: //54M
2516 aryRates[0] = 0x6c; // 54M
2517 break;
2518 case -1: //Auto
2519 default:
2520 if (pAdapter->PortCfg.PhyMode == PHY_11B)
2521 { //B Only
2522 aryRates[0] = 0x16; // 11Mbps
2523 aryRates[1] = 0x0b; // 5.5Mbps
2524 aryRates[2] = 0x04; // 2Mbps
2525 aryRates[3] = 0x02; // 1Mbps
2527 else
2528 { //(B/G) Mixed or (A/B/G) Mixed
2529 aryRates[0] = 0x6c; // 54Mbps
2530 aryRates[1] = 0x60; // 48Mbps
2531 aryRates[2] = 0x48; // 36Mbps
2532 aryRates[3] = 0x30; // 24Mbps
2533 aryRates[4] = 0x16; // 11Mbps
2534 aryRates[5] = 0x0b; // 5.5Mbps
2535 aryRates[6] = 0x04; // 2Mbps
2536 aryRates[7] = 0x02; // 1Mbps
2538 break;
2540 break;
2543 NdisZeroMemory(pAdapter->PortCfg.DesiredRates, MAX_LEN_OF_SUPPORTED_RATES);
2544 NdisMoveMemory(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
2545 DBGPRINT(RT_DEBUG_TRACE, " RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
2546 pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
2547 pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
2548 pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
2549 pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
2550 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
2551 MlmeUpdateTxRates(pAdapter, FALSE);
2554 ==========================================================================
2555 Description:
2556 Set Country Region
2557 Return:
2558 TRUE if all parameters are OK, FALSE otherwise
2559 ==========================================================================
2561 INT Set_CountryRegion_Proc(
2562 IN PRTMP_ADAPTER pAdapter,
2563 IN PUCHAR arg)
2565 ULONG region;
2566 int success = TRUE;
2568 region = simple_strtol(arg, 0, 10);
2569 if( (region >= REGION_MIN) && (region <= REGION_MAX) )
2571 pAdapter->PortCfg.CountryRegion = (UCHAR) region;
2572 DBGPRINT(RT_DEBUG_TRACE, "Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
2573 DBGPRINT(RT_DEBUG_TRACE, "Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
2575 else
2576 success = FALSE;
2578 return success;
2581 ==========================================================================
2582 Description:
2583 Set SSID
2584 Return:
2585 TRUE if all parameters are OK, FALSE otherwise
2586 ==========================================================================
2588 INT Set_SSID_Proc(
2589 IN PRTMP_ADAPTER pAdapter,
2590 IN PUCHAR arg)
2592 NDIS_802_11_SSID Ssid, *pSsid=NULL;
2593 BOOLEAN StateMachineTouched = FALSE;
2594 int success = TRUE;
2596 if( strlen(arg) <= MAX_LEN_OF_SSID)
2598 NdisZeroMemory(&Ssid, MAX_LEN_OF_SSID);
2599 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
2600 Ssid.SsidLength = strlen(arg);
2601 pSsid = &Ssid;
2603 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
2605 MlmeRestartStateMachine(pAdapter);
2606 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
2608 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
2609 // this request, because this request is initiated by NDIS.
2610 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
2612 MlmeEnqueue(&pAdapter->Mlme.Queue,
2613 MLME_CNTL_STATE_MACHINE,
2614 OID_802_11_SSID,
2615 sizeof(NDIS_802_11_SSID),
2616 (VOID *)pSsid);
2618 StateMachineTouched = TRUE;
2619 DBGPRINT(RT_DEBUG_TRACE, "Set_SSID_Proc::(Len=%d,Ssid=%s)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
2621 else
2623 success = FALSE;
2624 DBGPRINT(RT_DEBUG_ERROR, "--> Set_SSID_Proc (%s) ===> error\n", pSsid->Ssid);
2626 if (StateMachineTouched) // Upper layer sent a MLME-related operations
2627 MlmeHandler(pAdapter);
2629 return success;
2632 ==========================================================================
2633 Description:
2634 Set Wireless Mode
2635 Return:
2636 TRUE if all parameters are OK, FALSE otherwise
2637 ==========================================================================
2639 INT Set_WirelessMode_Proc(
2640 IN PRTMP_ADAPTER pAdapter,
2641 IN PUCHAR arg)
2643 ULONG WirelessMode;
2644 int success = TRUE;
2646 WirelessMode = simple_strtol(arg, 0, 10);
2648 if ((WirelessMode == PHY_11BG_MIXED) || (WirelessMode == PHY_11B) ||
2649 (WirelessMode == PHY_11A) || (WirelessMode == PHY_11ABG_MIXED))
2651 RTMPSetPhyMode(pAdapter, WirelessMode);
2652 DBGPRINT(RT_DEBUG_TRACE, "Set_WirelessMode_Proc::(=%d)\n", WirelessMode);
2654 else
2655 success = FALSE;
2657 return success;
2660 ==========================================================================
2661 Description:
2662 Set TxRate
2663 Return:
2664 TRUE if all parameters are OK, FALSE otherwise
2665 ==========================================================================
2667 INT Set_TxRate_Proc(
2668 IN PRTMP_ADAPTER pAdapter,
2669 IN PUCHAR arg)
2671 ULONG TxRate;
2672 int success = TRUE;
2673 ULONG rate_mapping[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
2675 TxRate = simple_strtol(arg, 0, 10);
2677 if (TxRate == 0)
2678 RTMPSetDesiredRates(pAdapter, -1);
2679 else
2680 RTMPSetDesiredRates(pAdapter, (LONG) (rate_mapping[TxRate-1] * 1000000));
2681 return success;
2684 ==========================================================================
2685 Description:
2686 Set AdhocMode support Rate can or can not exceed 11Mbps against WiFi spec.
2687 Return:
2688 TRUE if all parameters are OK, FALSE otherwise
2689 ==========================================================================
2691 INT Set_AdhocModeRate_Proc(
2692 IN PRTMP_ADAPTER pAdapter,
2693 IN PUCHAR arg)
2695 ULONG AdhocMode;
2697 AdhocMode = simple_strtol(arg, 0, 10);
2699 if (AdhocMode == 1)
2700 pAdapter->PortCfg.AdhocMode = 1;
2701 else if (AdhocMode == 0)
2702 pAdapter->PortCfg.AdhocMode = 0;
2703 else
2704 return FALSE; //Invalid argument
2706 DBGPRINT(RT_DEBUG_TRACE, "Set_AdhocModeRate_Proc::(AdhocMode=%d)\n", pAdapter->PortCfg.AdhocMode);
2708 return TRUE;
2711 ==========================================================================
2712 Description:
2713 Set Channel
2714 Return:
2715 TRUE if all parameters are OK, FALSE otherwise
2716 ==========================================================================
2718 INT Set_Channel_Proc(
2719 IN PRTMP_ADAPTER pAdapter,
2720 IN PUCHAR arg)
2722 int success = TRUE;
2723 UCHAR Channel;
2725 Channel = (UCHAR) simple_strtol(arg, 0, 10);
2727 if (ChannelSanity(pAdapter, Channel) == TRUE)
2729 pAdapter->PortCfg.Channel = Channel;
2731 // Scott: 2005-04-26
2732 // Fix adhoc mode channel setting bug.
2733 pAdapter->PortCfg.IbssConfig.Channel = Channel;
2734 DBGPRINT(RT_DEBUG_TRACE, "Set_Channel_Proc::(Channel=%d)\n", Channel);
2736 else
2737 success = FALSE;
2739 return success;
2742 ==========================================================================
2743 Description:
2744 For Debug information
2745 Return:
2746 TRUE if all parameters are OK, FALSE otherwise
2747 ==========================================================================
2749 #ifdef RT2500_DBG
2750 INT Set_Debug_Proc(
2751 IN PRTMP_ADAPTER pAdapter,
2752 IN PUCHAR arg)
2755 DBGPRINT(RT_DEBUG_TRACE, "**************************************************************\n");
2756 DBGPRINT(RT_DEBUG_TRACE, "==> Set_Debug_Proc\n");
2757 //To do here.
2759 if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
2760 RTDebugLevel = simple_strtol(arg, 0, 10);
2762 DBGPRINT(RT_DEBUG_TRACE, "<== Set_Debug_Proc\n");
2763 DBGPRINT(RT_DEBUG_TRACE, "**************************************************************\n");
2764 return TRUE;
2766 #endif
2768 ==========================================================================
2769 Description:
2770 Set 11B/11G Protection
2771 Return:
2772 TRUE if all parameters are OK, FALSE otherwise
2773 ==========================================================================
2775 INT Set_BGProtection_Proc(
2776 IN PRTMP_ADAPTER pAdapter,
2777 IN PUCHAR arg)
2780 switch (simple_strtol(arg, 0, 10))
2782 case 0: //AUTO
2783 pAdapter->PortCfg.UseBGProtection = 0;
2784 break;
2785 case 1: //Always On
2786 pAdapter->PortCfg.UseBGProtection = 1;
2787 break;
2788 case 2: //Always OFF
2789 pAdapter->PortCfg.UseBGProtection = 2;
2790 break;
2791 default: //Invalid argument
2792 return FALSE;
2794 DBGPRINT(RT_DEBUG_TRACE, "Set_BGProtection_Proc::(BGProtection=%d)\n", pAdapter->PortCfg.UseBGProtection);
2796 return TRUE;
2799 ==========================================================================
2800 Description:
2801 Set TxPreamble
2802 Return:
2803 TRUE if all parameters are OK, FALSE otherwise
2804 ==========================================================================
2806 INT Set_TxPreamble_Proc(
2807 IN PRTMP_ADAPTER pAdapter,
2808 IN PUCHAR arg)
2810 RT_802_11_PREAMBLE Preamble;
2812 Preamble = simple_strtol(arg, 0, 10);
2813 switch (Preamble)
2815 case Rt802_11PreambleShort:
2816 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
2817 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
2818 break;
2819 case Rt802_11PreambleLong:
2820 case Rt802_11PreambleAuto:
2821 // if user wants AUTO, initialize to LONG here, then change according to AP's
2822 // capability upon association.
2823 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
2824 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
2825 break;
2826 default: //Invalid argument
2827 return FALSE;
2830 DBGPRINT(RT_DEBUG_TRACE, "Set_TxPreamble_Proc::(TxPreamble=%d)\n", Preamble);
2832 return TRUE;
2835 ==========================================================================
2836 Description:
2837 Set RTS Threshold
2838 Return:
2839 TRUE if all parameters are OK, FALSE otherwise
2840 ==========================================================================
2842 INT Set_RTSThreshold_Proc(
2843 IN PRTMP_ADAPTER pAdapter,
2844 IN PUCHAR arg)
2846 NDIS_802_11_RTS_THRESHOLD RtsThresh;
2848 RtsThresh = simple_strtol(arg, 0, 10);
2850 if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
2851 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
2852 else if (RtsThresh == 0)
2853 pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
2854 else
2855 return FALSE;
2857 DBGPRINT(RT_DEBUG_TRACE, "Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAdapter->PortCfg.RtsThreshold);
2858 return TRUE;
2861 ==========================================================================
2862 Description:
2863 Set Fragment Threshold
2864 Return:
2865 TRUE if all parameters are OK, FALSE otherwise
2866 ==========================================================================
2868 INT Set_FragThreshold_Proc(
2869 IN PRTMP_ADAPTER pAdapter,
2870 IN PUCHAR arg)
2872 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
2874 FragThresh = simple_strtol(arg, 0, 10);
2876 if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
2877 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
2878 else if (FragThresh == 0)
2879 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
2880 else
2881 return FALSE; //Invalid argument
2883 if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
2884 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
2885 else
2886 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
2888 DBGPRINT(RT_DEBUG_TRACE, "Set_FragThreshold_Proc::(FragThreshold=%d)\n", FragThresh);
2890 return TRUE;
2893 ==========================================================================
2894 Description:
2895 Set TxBurst
2896 Return:
2897 TRUE if all parameters are OK, FALSE otherwise
2898 ==========================================================================
2900 INT Set_TxBurst_Proc(
2901 IN PRTMP_ADAPTER pAdapter,
2902 IN PUCHAR arg)
2904 ULONG TxBurst;
2906 TxBurst = simple_strtol(arg, 0, 10);
2908 if (TxBurst == 1)
2909 pAdapter->PortCfg.EnableTxBurst = TRUE;
2910 else if (TxBurst == 0)
2911 pAdapter->PortCfg.EnableTxBurst = FALSE;
2912 else
2913 return FALSE; //Invalid argument
2915 DBGPRINT(RT_DEBUG_TRACE, "Set_TxBurst_Proc::(TxBurst=%d)\n", pAdapter->PortCfg.EnableTxBurst);
2917 return TRUE;
2920 ==========================================================================
2921 Description:
2922 Set TurboRate Enable or Disable
2923 Return:
2924 TRUE if all parameters are OK, FALSE otherwise
2925 ==========================================================================
2927 INT Set_TurboRate_Proc(
2928 IN PRTMP_ADAPTER pAdapter,
2929 IN PUCHAR arg)
2931 ULONG TurboRate;
2933 TurboRate = simple_strtol(arg, 0, 10);
2935 if (TurboRate == 1)
2936 pAdapter->PortCfg.EnableTurboRate = TRUE;
2937 else if (TurboRate == 0)
2938 pAdapter->PortCfg.EnableTurboRate = FALSE;
2939 else
2940 return FALSE; //Invalid argument
2942 DBGPRINT(RT_DEBUG_TRACE, "Set_TurboRate_Proc::(TurboRate=%d)\n", pAdapter->PortCfg.EnableTurboRate);
2944 return TRUE;
2947 ==========================================================================
2948 Description:
2949 Set Short Slot Time Enable or Disable
2950 Return:
2951 TRUE if all parameters are OK, FALSE otherwise
2952 ==========================================================================
2954 INT Set_ShortSlot_Proc(
2955 IN PRTMP_ADAPTER pAdapter,
2956 IN PUCHAR arg)
2958 ULONG ShortSlot;
2960 ShortSlot = simple_strtol(arg, 0, 10);
2962 if (ShortSlot == 1)
2963 pAdapter->PortCfg.UseShortSlotTime = TRUE;
2964 else if (ShortSlot == 0)
2965 pAdapter->PortCfg.UseShortSlotTime = FALSE;
2966 else
2967 return FALSE; //Invalid argument
2969 DBGPRINT(RT_DEBUG_TRACE, "Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAdapter->PortCfg.UseShortSlotTime);
2971 return TRUE;
2975 ==========================================================================
2976 Description:
2977 Set Network Type(Infrastructure/Adhoc mode)
2978 Return:
2979 TRUE if all parameters are OK, FALSE otherwise
2980 ==========================================================================
2982 INT Set_NetworkType_Proc(
2983 IN PRTMP_ADAPTER pAdapter,
2984 IN PUCHAR arg)
2986 if (strcmp(arg, "Adhoc") == 0)
2987 pAdapter->PortCfg.BssType = BSS_INDEP;
2988 else //Default Infrastructure mode
2989 pAdapter->PortCfg.BssType = BSS_INFRA;
2991 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
2992 pAdapter->PortCfg.WpaState = SS_NOTUSE;
2994 DBGPRINT(RT_DEBUG_TRACE, "Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->PortCfg.BssType);
2996 return TRUE;
3000 ==========================================================================
3001 Description:
3002 Set Authentication mode
3003 Return:
3004 TRUE if all parameters are OK, FALSE otherwise
3005 ==========================================================================
3007 INT Set_AuthMode_Proc(
3008 IN PRTMP_ADAPTER pAdapter,
3009 IN PUCHAR arg)
3011 if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
3012 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
3013 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
3014 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
3015 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
3016 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
3017 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
3018 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
3019 else
3020 return FALSE;
3022 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3024 DBGPRINT(RT_DEBUG_TRACE, "Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->PortCfg.AuthMode);
3026 return TRUE;
3030 ==========================================================================
3031 Description:
3032 Set Encryption Type
3033 Return:
3034 TRUE if all parameters are OK, FALSE otherwise
3035 ==========================================================================
3037 INT Set_EncrypType_Proc(
3038 IN PRTMP_ADAPTER pAdapter,
3039 IN PUCHAR arg)
3041 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
3042 pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
3043 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
3044 pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
3045 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
3046 pAdapter->PortCfg.WepStatus = Ndis802_11Encryption2Enabled;
3047 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
3048 pAdapter->PortCfg.WepStatus = Ndis802_11Encryption3Enabled;
3049 else
3050 return FALSE;
3052 DBGPRINT(RT_DEBUG_TRACE, "Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->PortCfg.WepStatus);
3054 return TRUE;
3057 ==========================================================================
3058 Description:
3059 Set Default Key ID
3060 Return:
3061 TRUE if all parameters are OK, FALSE otherwise
3062 ==========================================================================
3064 INT Set_DefaultKeyID_Proc(
3065 IN PRTMP_ADAPTER pAdapter,
3066 IN PUCHAR arg)
3068 ULONG KeyIdx;
3070 KeyIdx = simple_strtol(arg, 0, 10);
3071 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
3072 pAdapter->PortCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
3073 else
3074 return FALSE; //Invalid argument
3076 DBGPRINT(RT_DEBUG_TRACE, "Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->PortCfg.DefaultKeyId);
3078 return TRUE;
3081 ==========================================================================
3082 Description:
3083 Set WEP KEY1
3084 Return:
3085 TRUE if all parameters are OK, FALSE otherwise
3086 ==========================================================================
3088 INT Set_Key1_Proc(
3089 IN PRTMP_ADAPTER pAdapter,
3090 IN PUCHAR arg)
3092 int KeyLen;
3093 int i;
3095 KeyLen = strlen(arg);
3097 switch (KeyLen)
3099 case 5: //wep 40 Ascii type
3100 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3101 memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3102 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3103 break;
3104 case 10: //wep 40 Hex type
3105 for(i=0; i < KeyLen; i++)
3107 if( !isxdigit(*(arg+i)) )
3108 return FALSE; //Not Hex value;
3110 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3111 AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3112 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3113 break;
3114 case 13: //wep 104 Ascii type
3115 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3116 memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3117 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3118 break;
3119 case 26: //wep 104 Hex type
3120 for(i=0; i < KeyLen; i++)
3122 if( !isxdigit(*(arg+i)) )
3123 return FALSE; //Not Hex value;
3125 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3126 AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3127 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3128 break;
3129 default: //Invalid argument
3130 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::Invalid argument (=%s)\n", arg);
3131 return FALSE;
3134 return TRUE;
3137 ==========================================================================
3138 Description:
3139 Set WEP KEY2
3140 Return:
3141 TRUE if all parameters are OK, FALSE otherwise
3142 ==========================================================================
3144 INT Set_Key2_Proc(
3145 IN PRTMP_ADAPTER pAdapter,
3146 IN PUCHAR arg)
3148 int KeyLen;
3149 int i;
3151 KeyLen = strlen(arg);
3153 switch (KeyLen)
3155 case 5: //wep 40 Ascii type
3156 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3157 memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3158 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3159 break;
3160 case 10: //wep 40 Hex type
3161 for(i=0; i < KeyLen; i++)
3163 if( !isxdigit(*(arg+i)) )
3164 return FALSE; //Not Hex value;
3166 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3167 AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3168 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3169 break;
3170 case 13: //wep 104 Ascii type
3171 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3172 memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3173 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3174 break;
3175 case 26: //wep 104 Hex type
3176 for(i=0; i < KeyLen; i++)
3178 if( !isxdigit(*(arg+i)) )
3179 return FALSE; //Not Hex value;
3181 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3182 AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3183 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3184 break;
3185 default: //Invalid argument
3186 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::Invalid argument (=%s)\n", arg);
3187 return FALSE;
3190 return TRUE;
3193 ==========================================================================
3194 Description:
3195 Set WEP KEY3
3196 Return:
3197 TRUE if all parameters are OK, FALSE otherwise
3198 ==========================================================================
3200 INT Set_Key3_Proc(
3201 IN PRTMP_ADAPTER pAdapter,
3202 IN PUCHAR arg)
3204 int KeyLen;
3205 int i;
3207 KeyLen = strlen(arg);
3209 switch (KeyLen)
3211 case 5: //wep 40 Ascii type
3212 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3213 memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3214 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3215 break;
3216 case 10: //wep 40 Hex type
3217 for(i=0; i < KeyLen; i++)
3219 if( !isxdigit(*(arg+i)) )
3220 return FALSE; //Not Hex value;
3222 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3223 AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3224 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3225 break;
3226 case 13: //wep 104 Ascii type
3227 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3228 memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3229 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3230 break;
3231 case 26: //wep 104 Hex type
3232 for(i=0; i < KeyLen; i++)
3234 if( !isxdigit(*(arg+i)) )
3235 return FALSE; //Not Hex value;
3237 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3238 AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3239 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3240 break;
3241 default: //Invalid argument
3242 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::Invalid argument (=%s)\n", arg);
3243 return FALSE;
3246 return TRUE;
3249 ==========================================================================
3250 Description:
3251 Set WEP KEY4
3252 Return:
3253 TRUE if all parameters are OK, FALSE otherwise
3254 ==========================================================================
3256 INT Set_Key4_Proc(
3257 IN PRTMP_ADAPTER pAdapter,
3258 IN PUCHAR arg)
3260 int KeyLen;
3261 int i;
3263 KeyLen = strlen(arg);
3265 switch (KeyLen)
3267 case 5: //wep 40 Ascii type
3268 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3269 memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3270 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3271 break;
3272 case 10: //wep 40 Hex type
3273 for(i=0; i < KeyLen; i++)
3275 if( !isxdigit(*(arg+i)) )
3276 return FALSE; //Not Hex value;
3278 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3279 AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3280 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3281 break;
3282 case 13: //wep 104 Ascii type
3283 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3284 memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3285 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3286 break;
3287 case 26: //wep 104 Hex type
3288 for(i=0; i < KeyLen; i++)
3290 if( !isxdigit(*(arg+i)) )
3291 return FALSE; //Not Hex value;
3293 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3294 AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3295 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3296 break;
3297 default: //Invalid argument
3298 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::Invalid argument (=%s)\n", arg);
3299 return FALSE;
3302 return TRUE;
3305 ==========================================================================
3306 Description:
3307 Set WPA PSK key
3308 Return:
3309 TRUE if all parameters are OK, FALSE otherwise
3310 ==========================================================================
3312 INT Set_WPAPSK_Proc(
3313 IN PRTMP_ADAPTER pAdapter,
3314 IN PUCHAR arg)
3316 UCHAR keyMaterial[40];
3318 DBGPRINT(RT_DEBUG_TRACE, "Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg);
3319 if ((strlen(arg) < 8) || (strlen(arg) > 64))
3321 DBGPRINT(RT_DEBUG_TRACE, "Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg);
3322 return FALSE;
3325 PasswordHash((char *)arg, pAdapter->Mlme.CntlAux.Ssid, pAdapter->Mlme.CntlAux.SsidLen, keyMaterial);
3327 NdisMoveMemory(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
3329 // Use RaConfig as PSK agent.
3330 // Start STA supplicant state machine
3331 pAdapter->PortCfg.WpaState = SS_START;
3333 return TRUE;
3337 ==========================================================================
3338 Description:
3339 Read / Write BBP
3340 Arguments:
3341 pAdapter Pointer to our adapter
3342 wrq Pointer to the ioctl argument
3344 Return Value:
3345 None
3347 Note:
3348 Usage:
3349 1.) iwpriv ra0 bbp ==> read all BBP
3350 2.) iwpriv ra0 bbp 1,2,10,32 ==> raed BBP where ID=1,2,10,32
3351 3.) iwpriv ra0 bbp 1=10,17=3E ==> write BBP R1=0x10, R17=0x3E
3352 ==========================================================================
3354 VOID RTMPIoctlBBP(
3355 IN PRTMP_ADAPTER pAdapter,
3356 IN struct iwreq *wrq)
3358 char *this_char;
3359 char *value;
3360 int i=0;
3361 int count = 0;
3362 UCHAR regBBP;
3363 char msg[1024];
3364 char arg[255];
3365 char *ptr;
3366 ULONG bbpId;
3367 ULONG bbpValue;
3368 BOOLEAN bIsPrintAllBBP = FALSE;
3370 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlBBP\n");
3371 memset(msg, 0x00, 1024);
3372 if (wrq->u.data.length > 1) //No parameters.
3374 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3375 ptr = arg;
3376 sprintf(msg, "\n");
3377 //Parsing Read or Write
3378 while ((this_char = strsep(&ptr, ",")) != NULL)
3380 i++;
3381 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3382 if (!*this_char)
3383 continue;
3385 if ((value = rtstrchr(this_char, '=')) != NULL)
3386 *value++ = 0;
3388 if (!value || !*value)
3389 { //Read
3390 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s, value=%s\n", this_char, value);
3391 bbpId = simple_strtol(this_char, 0, 10);
3392 // Scott 2004-12-03 if ((bbpId >=0) && (bbpId <= 63))
3393 if ((bbpId >=0) && (bbpId <= 100))
3395 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, bbpId, &regBBP);
3396 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3397 count++;
3398 if (count%5 == 4)
3399 sprintf(msg+strlen(msg), "\n");
3400 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3402 else
3403 {//Invalid parametes, so default print all bbp
3404 bIsPrintAllBBP = TRUE;
3405 break;
3408 else
3409 { //Write
3410 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s, value=%s\n", this_char, value);
3411 bbpId = simple_strtol(this_char, 0, 10);
3412 bbpValue = simple_strtol(value, 0, 10);
3413 DBGPRINT(RT_DEBUG_TRACE, "bbpID=%02d, value=0x%x\n", bbpId, bbpValue);
3414 if ((bbpId >=0) && (bbpId <= 63))
3416 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, (UCHAR) bbpId, (UCHAR) bbpValue);
3417 //Read it back for showing
3418 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, bbpId, &regBBP);
3419 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3420 count++;
3421 if (count%5 == 4)
3422 sprintf(msg+strlen(msg), "\n");
3423 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3425 else
3426 {//Invalid parametes, so default print all bbp
3427 bIsPrintAllBBP = TRUE;
3428 break;
3433 else
3434 bIsPrintAllBBP = TRUE;
3436 if (bIsPrintAllBBP)
3438 memset(msg, 0x00, 1024);
3439 sprintf(msg, "\n");
3440 for (i = 0; i <= 63; i++)
3442 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, i, &regBBP);
3443 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", i, i*2, regBBP);
3444 if (i%5 == 4)
3445 sprintf(msg+strlen(msg), "\n");
3447 // Copy the information into the user buffer
3448 DBGPRINT(RT_DEBUG_TRACE, "strlen(msg) =%d\n", strlen(msg));
3449 wrq->u.data.length = strlen(msg);
3450 copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3452 else
3454 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3455 // Copy the information into the user buffer
3456 DBGPRINT(RT_DEBUG_TRACE, "strlen(msg) =%d\n", strlen(msg));
3457 wrq->u.data.length = strlen(msg);
3458 copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3460 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlBBP\n");
3464 ==========================================================================
3465 Description:
3466 Read / Write MAC
3467 Arguments:
3468 pAdapter Pointer to our adapter
3469 wrq Pointer to the ioctl argument
3471 Return Value:
3472 None
3474 Note:
3475 Usage:
3476 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
3477 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
3478 ==========================================================================
3480 VOID RTMPIoctlMAC(
3481 IN PRTMP_ADAPTER pAdapter,
3482 IN struct iwreq *wrq)
3484 char *this_char;
3485 char *value;
3486 int j=0, k=0;
3487 int count = 0;
3488 char msg[1024];
3489 char arg[255];
3490 char *ptr;
3491 ULONG macAddr = 0;
3492 UCHAR temp[16], temp2[16];
3493 ULONG macValue;
3495 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlMAC\n");
3496 memset(msg, 0x00, 1024);
3497 if (wrq->u.data.length > 1) //No parameters.
3499 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3500 ptr = arg;
3501 sprintf(msg, "\n");
3502 //Parsing Read or Write
3503 while ((this_char = strsep(&ptr, ",")) != NULL)
3505 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3506 if (!*this_char)
3507 continue;
3509 if ((value = rtstrchr(this_char, '=')) != NULL)
3510 *value++ = 0;
3512 if (!value || !*value)
3513 { //Read
3514 DBGPRINT(RT_DEBUG_TRACE, "Read: this_char=%s, strlen=%d\n", this_char, strlen(this_char));
3516 // Sanity check
3517 if(strlen(this_char) > 4)
3518 break;
3520 j = strlen(this_char);
3521 while(j-- > 0)
3523 if(this_char[j] > 'f' || this_char[j] < '0')
3524 return;
3527 // Mac Addr
3528 k = j = strlen(this_char);
3529 while(j-- > 0)
3531 this_char[4-k+j] = this_char[j];
3534 while(k < 4)
3535 this_char[3-k++]='0';
3536 this_char[4]='\0';
3538 if(strlen(this_char) == 4)
3540 AtoH(this_char, temp, 4);
3541 macAddr = *temp*256 + temp[1];
3542 if (macAddr < 0xFFFF)
3544 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
3545 DBGPRINT(RT_DEBUG_TRACE, "macAddr=%x, regMAC=%x\n", macAddr, macValue);
3546 sprintf(msg+strlen(msg), "[0x%08X]:%08X ", macAddr , macValue);
3547 count++;
3548 if (count%5 == 4)
3549 sprintf(msg+strlen(msg), "\n");
3550 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3552 else
3553 {//Invalid parametes, so default print all bbp
3554 break;
3558 else
3559 { //Write
3560 DBGPRINT(RT_DEBUG_TRACE, "Write: this_char=%s, strlen(value)=%d, value=%s\n", this_char, strlen(value), value);
3561 memcpy(&temp2, value, strlen(value));
3562 temp2[strlen(value)] = '\0';
3564 // Sanity check
3565 if((strlen(this_char) > 4) || strlen(temp2) > 8)
3566 break;
3568 j = strlen(this_char);
3569 while(j-- > 0)
3571 if(this_char[j] > 'f' || this_char[j] < '0')
3572 return;
3575 j = strlen(temp2);
3576 while(j-- > 0)
3578 if(temp2[j] > 'f' || temp2[j] < '0')
3579 return;
3582 //MAC Addr
3583 k = j = strlen(this_char);
3584 while(j-- > 0)
3586 this_char[4-k+j] = this_char[j];
3589 while(k < 4)
3590 this_char[3-k++]='0';
3591 this_char[4]='\0';
3593 //MAC value
3594 k = j = strlen(temp2);
3595 while(j-- > 0)
3597 temp2[8-k+j] = temp2[j];
3600 while(k < 8)
3601 temp2[7-k++]='0';
3602 temp2[8]='\0';
3605 AtoH(this_char, temp, 4);
3606 macAddr = *temp*256 + temp[1];
3608 AtoH(temp2, temp, 8);
3609 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
3611 DBGPRINT(RT_DEBUG_TRACE, "macAddr=%02x, macValue=0x%x\n", macAddr, macValue);
3613 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
3614 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", macAddr, macValue);
3615 count++;
3616 if (count%5 == 4)
3617 sprintf(msg+strlen(msg), "\n");
3618 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3624 if(strlen(msg) == 1)
3625 sprintf(msg+strlen(msg), "===>Error command format!");
3626 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3627 // Copy the information into the user buffer
3628 DBGPRINT(RT_DEBUG_TRACE, "strlen(msg) =%d\n", strlen(msg));
3629 wrq->u.data.length = strlen(msg);
3630 copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3632 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlMAC\n");
3636 ==========================================================================
3637 Description:
3638 Read / Write E2PROM
3639 Arguments:
3640 pAdapter Pointer to our adapter
3641 wrq Pointer to the ioctl argument
3643 Return Value:
3644 None
3646 Note:
3647 Usage:
3648 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
3649 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
3650 ==========================================================================
3652 VOID RTMPIoctlE2PROM(
3653 IN PRTMP_ADAPTER pAdapter,
3654 IN struct iwreq *wrq)
3656 char *this_char;
3657 char *value;
3658 int j=0, k=0;
3659 int count = 0;
3660 char msg[1024];
3661 char arg[255];
3662 char *ptr;
3663 USHORT eepAddr = 0;
3664 UCHAR temp[16], temp2[16];
3665 USHORT eepValue;
3667 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlE2PROM\n");
3668 memset(msg, 0x00, 1024);
3669 if (wrq->u.data.length > 1) //No parameters.
3671 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3672 ptr = arg;
3673 sprintf(msg, "\n");
3674 //Parsing Read or Write
3675 while ((this_char = strsep(&ptr, ",")) != NULL)
3677 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3678 if (!*this_char)
3679 continue;
3681 if ((value = strchr(this_char, '=')) != NULL)
3682 *value++ = 0;
3684 if (!value || !*value)
3685 { //Read
3686 DBGPRINT(RT_DEBUG_TRACE, "Read: this_char=%s, strlen=%d\n", this_char, strlen(this_char));
3688 // Sanity check
3689 if(strlen(this_char) > 4)
3690 break;
3692 j = strlen(this_char);
3693 while(j-- > 0)
3695 if(this_char[j] > 'f' || this_char[j] < '0')
3696 return;
3699 // E2PROM addr
3700 k = j = strlen(this_char);
3701 while(j-- > 0)
3703 this_char[4-k+j] = this_char[j];
3706 while(k < 4)
3707 this_char[3-k++]='0';
3708 this_char[4]='\0';
3710 if(strlen(this_char) == 4)
3712 AtoH(this_char, temp, 4);
3713 eepAddr = *temp*256 + temp[1];
3714 if (eepAddr < 0xFFFF)
3716 eepValue = RTMP_EEPROM_READ16(pAdapter, eepAddr);
3717 DBGPRINT(RT_DEBUG_TRACE, "eepAddr=%x, eepValue=%x\n", eepAddr, eepValue);
3718 sprintf(msg+strlen(msg), "[0x%04X]:%04X ", eepAddr , eepValue);
3719 count++;
3720 if (count%5 == 4)
3721 sprintf(msg+strlen(msg), "\n");
3722 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3724 else
3725 {//Invalid parametes, so default printk all bbp
3726 break;
3730 else
3731 { //Write
3732 DBGPRINT(RT_DEBUG_TRACE, "Write: this_char=%s, strlen(value)=%d, value=%s\n", this_char, strlen(value), value);
3733 memcpy(&temp2, value, strlen(value));
3734 temp2[strlen(value)] = '\0';
3736 // Sanity check
3737 if((strlen(this_char) > 4) || strlen(temp2) > 8)
3738 break;
3740 j = strlen(this_char);
3741 while(j-- > 0)
3743 if(this_char[j] > 'f' || this_char[j] < '0')
3744 return;
3746 j = strlen(temp2);
3747 while(j-- > 0)
3749 if(temp2[j] > 'f' || temp2[j] < '0')
3750 return;
3753 //MAC Addr
3754 k = j = strlen(this_char);
3755 while(j-- > 0)
3757 this_char[4-k+j] = this_char[j];
3760 while(k < 4)
3761 this_char[3-k++]='0';
3762 this_char[4]='\0';
3764 //MAC value
3765 k = j = strlen(temp2);
3766 while(j-- > 0)
3768 temp2[4-k+j] = temp2[j];
3771 while(k < 4)
3772 temp2[3-k++]='0';
3773 temp2[4]='\0';
3775 AtoH(this_char, temp, 4);
3776 eepAddr = *temp*256 + temp[1];
3778 AtoH(temp2, temp, 4);
3779 eepValue = *temp*256 + temp[1];
3781 DBGPRINT(RT_DEBUG_TRACE, "eepAddr=%02x, eepValue=0x%x\n", eepAddr, eepValue);
3783 RTMP_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
3784 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
3785 count++;
3786 if (count%5 == 4)
3787 sprintf(msg+strlen(msg), "\n");
3788 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3793 if(strlen(msg) == 1)
3794 sprintf(msg+strlen(msg), "===>Error command format!");
3796 // Copy the information into the user buffer
3797 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3798 wrq->u.data.length = strlen(msg);
3799 copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3801 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlE2PROM\n");
3805 #ifdef RALINK_ATE
3806 UCHAR TempletFrame[24] = {0x08,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xAA,0xBB,0x12,0x34,0x56,0x00,0x11,0x22,0xAA,0xBB,0xCC,0x00,0x00}; // 802.11 MAC Header, Type:Data, Length:24bytes
3809 ==========================================================================
3810 Description:
3811 Set ATE operation mode to
3812 0. APSTOP = Stop AP Mode
3813 1. APSTART = Start AP Mode
3814 2. TXCONT = Continuous Transmit
3815 3. TXCARR = Transmit Carrier
3816 4. TXFRAME = Transmit Frames
3817 5. RXFRAME = Receive Frames
3818 Return:
3819 TRUE if all parameters are OK, FALSE otherwise
3820 ==========================================================================
3822 INT Set_ATE_Proc(
3823 IN PRTMP_ADAPTER pAdapter,
3824 IN PUCHAR arg)
3826 USHORT BbpData;
3827 ULONG MacData;
3828 PTXD_STRUC pTxD;
3829 PUCHAR pDest;
3830 UINT i, j;
3832 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_Proc\n");
3833 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
3835 // Scott AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
3836 // Scott AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
3838 AsicSwitchChannel(pAdapter, pAdapter->ate.Channel);
3839 AsicLockChannel(pAdapter, pAdapter->ate.Channel);
3841 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, 63, &BbpData);
3842 RTMP_IO_READ32(pAdapter, MACCSR1, &MacData);
3844 BbpData = 0;
3845 MacData &= 0xFBFFFFFF;
3847 if (!strcmp(arg, "STASTOP"))
3849 DBGPRINT(RT_DEBUG_TRACE, "ATE: STASTOP\n");
3851 pAdapter->ate.Mode = ATE_STASTOP;
3853 LinkDown(pAdapter);
3854 AsicEnableBssSync(pAdapter);
3855 netif_stop_queue(pAdapter->net_dev);
3856 RTMPStationStop(pAdapter);
3857 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff); // Stop Rx
3859 else if (!strcmp(arg, "STASTART"))
3861 DBGPRINT(RT_DEBUG_TRACE, "ATE: STASTART\n");
3863 pAdapter->ate.Mode = ATE_STASTART;
3865 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0x56); // Start Rx
3866 netif_start_queue(pAdapter->net_dev);
3867 RTMPStationStart(pAdapter);
3869 else if (!strcmp(arg, "TXCONT")) // Continuous Tx
3871 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXCONT\n");
3873 pAdapter->ate.Mode = ATE_TXCONT;
3875 BbpData |= 0x80;
3876 MacData |= 0x04000000;
3878 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
3880 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
3881 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
3883 // Prepare frame payload
3884 memcpy(pDest, &TempletFrame, LENGTH_802_11);
3885 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
3886 pDest[j] = 0xAA;
3887 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
3888 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
3889 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
3891 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
3892 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
3893 pAdapter->ate.TxLength, pAdapter->PortCfg.TxPreambleInUsed, 0);
3895 pAdapter->CurEncryptIndex++;
3896 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
3898 pAdapter->CurEncryptIndex = 0;
3902 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
3903 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
3905 else if (!strcmp(arg, "TXCARR")) // Tx Carrier -------------------------------------
3907 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXCARR\n");
3908 pAdapter->ate.Mode = ATE_TXCARR;
3910 BbpData |= 0x40;
3911 MacData |= 0x04000000;
3913 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
3915 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
3916 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
3918 // Prepare frame payload
3919 memcpy(pDest, &TempletFrame, LENGTH_802_11);
3920 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
3921 pDest[j] = 0xAA;
3922 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
3923 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
3924 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
3926 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
3927 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
3928 pAdapter->ate.TxLength, pAdapter->PortCfg.TxPreambleInUsed, 0);
3930 pAdapter->CurEncryptIndex++;
3931 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
3933 pAdapter->CurEncryptIndex = 0;
3937 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
3938 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
3940 else if (!strcmp(arg, "TXFRAME")) // Tx Frames --------------------------------------
3942 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXFRAME(Count=%d)\n", pAdapter->ate.TxCount);
3943 pAdapter->ate.Mode = ATE_TXFRAME;
3945 pAdapter->ate.TxDoneCount = 0;
3947 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
3949 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
3950 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
3952 // Prepare frame payload
3953 memcpy(pDest, &TempletFrame, LENGTH_802_11);
3954 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
3955 pDest[j] = 0xAA;
3956 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
3957 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
3958 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
3960 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
3961 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
3962 pAdapter->ate.TxLength, Rt802_11PreambleLong, 0);
3964 pAdapter->CurEncryptIndex++;
3965 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
3967 pAdapter->CurEncryptIndex = 0;
3970 pAdapter->ate.TxDoneCount += i;
3971 //printk("TXFRAME txcount=%d\n", pAdapter->ate.TxCount);
3972 //printk("pAdapter->ate.TxDoneCount = %d\n", pAdapter->ate.TxDoneCount);
3974 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
3975 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
3977 else if (!strcmp(arg, "RXFRAME")) // Rx Frames --------------------------------------
3979 DBGPRINT(RT_DEBUG_TRACE, "ATE: RXFRAME\n");
3980 pAdapter->ate.Mode = ATE_RXFRAME;
3981 pAdapter->ate.TxDoneCount = pAdapter->ate.TxCount;
3983 RTMP_IO_WRITE32(pAdapter, TXCSR0, 0x08); // Abort Tx
3984 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0x56); // Start Rx
3986 else
3988 DBGPRINT(RT_DEBUG_TRACE, "ATE: Invalid arg!\n");
3989 return FALSE;
3992 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
3993 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
3995 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_Proc\n");
3996 return TRUE;
4000 ==========================================================================
4001 Description:
4002 Set ATE ADDR1=DA for TxFrames Return:
4003 TRUE if all parameters are OK, FALSE otherwise
4004 ==========================================================================
4006 INT Set_ATE_DA_Proc(
4007 IN PRTMP_ADAPTER pAdapter,
4008 IN PUCHAR arg)
4010 char *value;
4011 int i;
4013 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_DA_Proc\n");
4014 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4016 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4017 return FALSE;
4019 #if 0 // The Linux 2.6.x removed strtok. To use strsep. Victor Yu. 01-11-2006
4020 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4021 #else
4022 for (i=0, value = strsep(&arg,":"); value; value = strsep(NULL,":"))
4023 #endif
4025 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4026 return FALSE; //Invalid
4028 AtoH(value, &pAdapter->ate.Addr1[i++], 2);
4031 if(i != 6)
4032 return FALSE; //Invalid
4034 DBGPRINT(RT_DEBUG_TRACE, "DA=%2X:%2X:%2X:%2X:%2X:%2X\n", pAdapter->ate.Addr1[0], pAdapter->ate.Addr1[1], pAdapter->ate.Addr1[2], pAdapter->ate.Addr1[3], pAdapter->ate.Addr1[4], pAdapter->ate.Addr1[5]);
4035 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_DA_Proc\n");
4037 return TRUE;
4041 ==========================================================================
4042 Description:
4043 Set ATE ADDR2=SA for TxFrames Return:
4044 TRUE if all parameters are OK, FALSE otherwise
4045 ==========================================================================
4047 INT Set_ATE_SA_Proc(
4048 IN PRTMP_ADAPTER pAdapter,
4049 IN PUCHAR arg)
4051 char *value;
4052 int i;
4054 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_SA_Proc\n");
4055 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4057 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4058 return FALSE;
4060 #if 0 // The Linux 2.6.x removed strtok. To use strsep. Victor Yu. 01-11-2006
4061 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4062 #else
4063 for (i=0, value = strsep(&arg,":"); value; value = strsep(NULL,":"))
4064 #endif
4066 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4067 return FALSE; //Invalid
4069 AtoH(value, &pAdapter->ate.Addr2[i++], 2);
4072 if(i != 6)
4073 return FALSE; //Invalid
4075 DBGPRINT(RT_DEBUG_TRACE, "DA=%2X:%2X:%2X:%2X:%2X:%2X\n", pAdapter->ate.Addr2[0], pAdapter->ate.Addr2[1], pAdapter->ate.Addr2[2], pAdapter->ate.Addr2[3], pAdapter->ate.Addr2[4], pAdapter->ate.Addr2[5]);
4076 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_SA_Proc\n");
4078 return TRUE;
4082 ==========================================================================
4083 Description:
4084 Set ATE ADDR3=BSSID for TxFrames Return:
4085 TRUE if all parameters are OK, FALSE otherwise
4086 ==========================================================================
4088 INT Set_ATE_BSSID_Proc(
4089 IN PRTMP_ADAPTER pAdapter,
4090 IN PUCHAR arg)
4092 char *value;
4093 int i;
4095 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_BSSID_Proc\n");
4096 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4098 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4099 return FALSE;
4101 #if 0 // The Linux 2.6.x removed strtok. To use strsep. Victor Yu. 01-11-2006
4102 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4103 #else
4104 for (i=0, value = strsep(&arg,":"); value; value = strsep(NULL,":"))
4105 #endif
4107 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4108 return FALSE; //Invalid
4110 AtoH(value, &pAdapter->ate.Addr3[i++], 2);
4113 if(i != 6)
4114 return FALSE; //Invalid
4116 DBGPRINT(RT_DEBUG_TRACE, "DA=%2X:%2X:%2X:%2X:%2X:%2X\n", pAdapter->ate.Addr3[0], pAdapter->ate.Addr3[1], pAdapter->ate.Addr3[2], pAdapter->ate.Addr3[3], pAdapter->ate.Addr3[4], pAdapter->ate.Addr3[5]);
4117 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_BSSID_Proc\n");
4119 return TRUE;
4123 ==========================================================================
4124 Description:
4125 Set ATE Channel Return:
4126 TRUE if all parameters are OK, FALSE otherwise
4127 ==========================================================================
4129 INT Set_ATE_CHANNEL_Proc(
4130 IN PRTMP_ADAPTER pAdapter,
4131 IN PUCHAR arg)
4133 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_CHANNEL_Proc (arg = %s)\n", arg);
4135 pAdapter->ate.Channel = simple_strtol(arg, 0, 10);
4137 if((pAdapter->ate.Channel < 1) || (pAdapter->ate.Channel > 14))
4139 pAdapter->ate.Channel = 1;
4140 return FALSE;
4143 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAdapter->ate.Channel);
4144 //printk("channel changed to %d\n", pAdapter->ate.Channel);
4145 return TRUE;
4149 ==========================================================================
4150 Description:
4151 Set ATE Tx Power Return:
4152 TRUE if all parameters are OK, FALSE otherwise
4153 ==========================================================================
4155 INT Set_ATE_TX_POWER_Proc(
4156 IN PRTMP_ADAPTER pAdapter,
4157 IN PUCHAR arg)
4159 ULONG R3;
4161 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_POWER_Proc\n");
4162 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4164 pAdapter->ate.TxPower = simple_strtol(arg, 0, 10);
4166 if(pAdapter->ate.TxPower >= 32)
4168 // Scott pAdapter->ate.TxPower = pAdapter->PortCfg.ChannelTxPower[pAdapter->PortCfg.Channel - 1];;
4169 pAdapter->ate.TxPower = pAdapter->PortCfg.ChannelTxPower[pAdapter->ate.Channel - 1];;
4170 return FALSE;
4173 R3 = pAdapter->ate.TxPower;
4174 R3 = R3 << 9; // shift TX power control to correct RF register bit position
4176 R3 |= (pAdapter->PortCfg.LatchRfRegs.R3 & 0xffffc1ff);
4177 RTMP_RF_IO_WRITE32(pAdapter, R3);
4179 // Scott
4180 pAdapter->PortCfg.LatchRfRegs.R3 = R3;
4182 DBGPRINT(RT_DEBUG_TRACE, "TxPower = %d\n", pAdapter->ate.TxPower);
4183 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_POWER_Proc\n");
4185 return TRUE;
4189 ==========================================================================
4190 Description:
4191 Set ATE Tx Length Return:
4192 TRUE if all parameters are OK, FALSE otherwise
4193 ==========================================================================
4195 INT Set_ATE_TX_LENGTH_Proc(
4196 IN PRTMP_ADAPTER pAdapter,
4197 IN PUCHAR arg)
4199 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_LENGTH_Proc\n");
4200 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4202 pAdapter->ate.TxLength = simple_strtol(arg, 0, 10);
4204 if((pAdapter->ate.TxLength < 24) || (pAdapter->ate.TxLength > 1500))
4206 pAdapter->ate.TxLength = 1500;
4207 return FALSE;
4210 DBGPRINT(RT_DEBUG_TRACE, "TxLength = %d\n", pAdapter->ate.TxLength);
4211 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_LENGTH_Proc\n");
4213 return TRUE;
4217 ==========================================================================
4218 Description:
4219 Set ATE Tx Count Return:
4220 TRUE if all parameters are OK, FALSE otherwise
4221 ==========================================================================
4223 INT Set_ATE_TX_COUNT_Proc(
4224 IN PRTMP_ADAPTER pAdapter,
4225 IN PUCHAR arg)
4227 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_COUNT_Proc\n");
4228 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4230 pAdapter->ate.TxCount = simple_strtol(arg, 0, 10);
4232 DBGPRINT(RT_DEBUG_TRACE, "TxCount = %d\n", pAdapter->ate.TxCount);
4233 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_COUNT_Proc\n");
4235 return TRUE;
4239 ==========================================================================
4240 Description:
4241 Set ATE Tx Rate
4242 Return:
4243 TRUE if all parameters are OK, FALSE otherwise
4244 ==========================================================================
4246 INT Set_ATE_TX_RATE_Proc(
4247 IN PRTMP_ADAPTER pAdapter,
4248 IN PUCHAR arg)
4250 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_RATE_Proc\n");
4251 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4253 pAdapter->ate.TxRate = simple_strtol(arg, 0, 10);
4255 if(pAdapter->ate.TxRate > RATE_54)
4257 pAdapter->ate.TxRate = RATE_11;
4258 return FALSE;
4261 DBGPRINT(RT_DEBUG_TRACE, "TxRate = %d\n", pAdapter->ate.TxRate);
4262 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_RATE_Proc\n");
4264 return TRUE;
4267 VOID RTMPStationStop(
4268 IN PRTMP_ADAPTER pAd)
4270 DBGPRINT(RT_DEBUG_TRACE, "==> RTMPStationStop\n");
4271 #if 0 // mask by Victor Yu. 01-11-2006
4272 RTMPCancelTimer(&pAd->timer);
4273 #endif
4274 RTMPCancelTimer(&pAd->Mlme.AssocAux.AssocTimer);
4275 RTMPCancelTimer(&pAd->Mlme.AssocAux.ReassocTimer);
4276 RTMPCancelTimer(&pAd->Mlme.AssocAux.DisassocTimer);
4277 RTMPCancelTimer(&pAd->Mlme.AuthAux.AuthTimer);
4278 RTMPCancelTimer(&pAd->Mlme.AuthRspAux.AuthRspTimer);
4279 RTMPCancelTimer(&pAd->Mlme.SyncAux.BeaconTimer);
4280 RTMPCancelTimer(&pAd->Mlme.SyncAux.ScanTimer);
4281 RTMPCancelTimer(&pAd->Mlme.PeriodicTimer);
4282 RTMPCancelTimer(&pAd->PortCfg.RfTuningTimer);
4283 if (pAd->PortCfg.LedMode == LED_MODE_TXRX_ACTIVITY)
4284 RTMPCancelTimer(&pAd->PortCfg.LedCntl.BlinkTimer);
4285 RTMPCancelTimer(&pAd->PortCfg.RxAnt.RxAntDiversityTimer);
4286 DBGPRINT(RT_DEBUG_TRACE, "<== RTMPStationStop\n");
4289 VOID RTMPStationStart(
4290 IN PRTMP_ADAPTER pAd)
4292 DBGPRINT(RT_DEBUG_TRACE, "==> RTMPStationStart\n");
4293 RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
4294 // Scott RTMPSetTimer(pAd, &pAd->timer, DEBUG_TASK_DELAY);
4295 DBGPRINT(RT_DEBUG_TRACE, "<== RTMPStationStart\n");
4298 #endif //#ifdef RALINK_ATE