MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink / Module / rtmp_info.c
blob084006dc357cb84267b7eca6930b450fd97f26fc
1 /*************************************************************************
2 * Ralink Tech Inc. *
3 * 4F, No. 2 Technology 5th Rd. *
4 * Science-based Industrial Park *
5 * Hsin-chu, Taiwan, R.O.C. *
6 * *
7 * (c) Copyright 2002, Ralink Technology, Inc. *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the *
21 * Free Software Foundation, Inc., *
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23 * *
24 *************************************************************************
26 Module Name:
27 rtmp_info.c
29 Abstract:
30 IOCTL related subroutines
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Rory Chen 01-03-2003 created
39 #include "rt_config.h"
40 #include <net/iw_handler.h>
42 #ifndef IW_ESSID_MAX_SIZE
43 /* Maximum size of the ESSID and NICKN strings */
44 #define IW_ESSID_MAX_SIZE 32
45 #endif
47 #define NR_WEP_KEYS 4
48 #define WEP_SMALL_KEY_LEN (40/8)
49 #define WEP_LARGE_KEY_LEN (104/8)
51 #define MAP_CHANNEL_ID_TO_KHZ(ch, khz) { \
52 switch (ch) \
53 { \
54 case 1: khz = 2412000; break; \
55 case 2: khz = 2417000; break; \
56 case 3: khz = 2422000; break; \
57 case 4: khz = 2427000; break; \
58 case 5: khz = 2432000; break; \
59 case 6: khz = 2437000; break; \
60 case 7: khz = 2442000; break; \
61 case 8: khz = 2447000; break; \
62 case 9: khz = 2452000; break; \
63 case 10: khz = 2457000; break; \
64 case 11: khz = 2462000; break; \
65 case 12: khz = 2467000; break; \
66 case 13: khz = 2472000; break; \
67 case 14: khz = 2484000; break; \
68 case 36: /* UNII */ khz = 5180000; break; \
69 case 40: /* UNII */ khz = 5200000; break; \
70 case 44: /* UNII */ khz = 5220000; break; \
71 case 48: /* UNII */ khz = 5240000; break; \
72 case 52: /* UNII */ khz = 5260000; break; \
73 case 56: /* UNII */ khz = 5280000; break; \
74 case 60: /* UNII */ khz = 5300000; break; \
75 case 64: /* UNII */ khz = 5320000; break; \
76 case 149: /* UNII */ khz = 5745000; break; \
77 case 153: /* UNII */ khz = 5765000; break; \
78 case 157: /* UNII */ khz = 5785000; break; \
79 case 161: /* UNII */ khz = 5805000; break; \
80 case 100: /* HiperLAN2 */ khz = 5500000; break; \
81 case 104: /* HiperLAN2 */ khz = 5520000; break; \
82 case 108: /* HiperLAN2 */ khz = 5540000; break; \
83 case 112: /* HiperLAN2 */ khz = 5560000; break; \
84 case 116: /* HiperLAN2 */ khz = 5580000; break; \
85 case 120: /* HiperLAN2 */ khz = 5600000; break; \
86 case 124: /* HiperLAN2 */ khz = 5620000; break; \
87 case 128: /* HiperLAN2 */ khz = 5640000; break; \
88 case 132: /* HiperLAN2 */ khz = 5660000; break; \
89 case 136: /* HiperLAN2 */ khz = 5680000; break; \
90 case 140: /* HiperLAN2 */ khz = 5700000; break; \
91 case 34: /* Japan MMAC */ khz = 5170000; break; \
92 case 38: /* Japan MMAC */ khz = 5190000; break; \
93 case 42: /* Japan MMAC */ khz = 5210000; break; \
94 case 46: /* Japan MMAC */ khz = 5230000; break; \
95 default: khz = 2412000; break; \
96 } \
99 #define MAP_KHZ_TO_CHANNEL_ID(khz, ch) { \
100 switch (khz) \
102 case 2412000: ch = 1; break; \
103 case 2417000: ch = 2; break; \
104 case 2422000: ch = 3; break; \
105 case 2427000: ch = 4; break; \
106 case 2432000: ch = 5; break; \
107 case 2437000: ch = 6; break; \
108 case 2442000: ch = 7; break; \
109 case 2447000: ch = 8; break; \
110 case 2452000: ch = 9; break; \
111 case 2457000: ch = 10; break; \
112 case 2462000: ch = 11; break; \
113 case 2467000: ch = 12; break; \
114 case 2472000: ch = 13; break; \
115 case 2484000: ch = 14; break; \
116 case 5180000: ch = 36; /* UNII */ break; \
117 case 5200000: ch = 40; /* UNII */ break; \
118 case 5220000: ch = 44; /* UNII */ break; \
119 case 5240000: ch = 48; /* UNII */ break; \
120 case 5260000: ch = 52; /* UNII */ break; \
121 case 5280000: ch = 56; /* UNII */ break; \
122 case 5300000: ch = 60; /* UNII */ break; \
123 case 5320000: ch = 64; /* UNII */ break; \
124 case 5745000: ch = 149; /* UNII */ break; \
125 case 5765000: ch = 153; /* UNII */ break; \
126 case 5785000: ch = 157; /* UNII */ break; \
127 case 5805000: ch = 161; /* UNII */ break; \
128 case 5500000: ch = 100; /* HiperLAN2 */ break; \
129 case 5520000: ch = 104; /* HiperLAN2 */ break; \
130 case 5540000: ch = 108; /* HiperLAN2 */ break; \
131 case 5560000: ch = 112; /* HiperLAN2 */ break; \
132 case 5580000: ch = 116; /* HiperLAN2 */ break; \
133 case 5600000: ch = 120; /* HiperLAN2 */ break; \
134 case 5620000: ch = 124; /* HiperLAN2 */ break; \
135 case 5640000: ch = 128; /* HiperLAN2 */ break; \
136 case 5660000: ch = 132; /* HiperLAN2 */ break; \
137 case 5680000: ch = 136; /* HiperLAN2 */ break; \
138 case 5700000: ch = 140; /* HiperLAN2 */ break; \
139 case 5170000: ch = 34; /* Japan MMAC */ break; \
140 case 5190000: ch = 38; /* Japan MMAC */ break; \
141 case 5210000: ch = 42; /* Japan MMAC */ break; \
142 case 5230000: ch = 46; /* Japan MMAC */ break; \
143 default: ch = 1; break; \
147 struct iw_priv_args privtab[] = {
148 { RTPRIV_IOCTL_SET,
149 IW_PRIV_TYPE_CHAR | 1024, 0,
150 "set"},
151 { RTPRIV_IOCTL_BBP,
152 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
153 "bbp"},
154 { RTPRIV_IOCTL_MAC,
155 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
156 "mac"},
157 { RTPRIV_IOCTL_E2P,
158 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
159 "e2p"}
162 static struct {
163 char *name;
164 int (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
165 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
166 {"CountryRegion", Set_CountryRegion_Proc },
167 {"SSID", Set_SSID_Proc},
168 {"WirelessMode", Set_WirelessMode_Proc},
169 {"TxRate", Set_TxRate_Proc},
170 {"AdhocOfdm", Set_AdhocModeRate_Proc},
171 {"Channel", Set_Channel_Proc},
172 {"BGProtection", Set_BGProtection_Proc},
173 {"StaWithEtherBridge", Set_StaWithEtherBridge_Proc},
174 {"TxPreamble", Set_TxPreamble_Proc},
175 {"RTSThreshold", Set_RTSThreshold_Proc},
176 {"FragThreshold", Set_FragThreshold_Proc},
177 {"TxBurst", Set_TxBurst_Proc},
178 {"TurboRate", Set_TurboRate_Proc},
179 {"NetworkType", Set_NetworkType_Proc},
180 {"AuthMode", Set_AuthMode_Proc},
181 {"EncrypType", Set_EncrypType_Proc},
182 {"DefaultKeyID", Set_DefaultKeyID_Proc},
183 {"Key1", Set_Key1_Proc},
184 {"Key2", Set_Key2_Proc},
185 {"Key3", Set_Key3_Proc},
186 {"Key4", Set_Key4_Proc},
187 {"WPAPSK", Set_WPAPSK_Proc},
188 {"WPANONE", Set_WPANONE_Proc},
189 #ifdef RT2500_DBG
190 {"Debug", Set_Debug_Proc},
191 #endif
193 #ifdef RALINK_ATE
194 {"ATE", Set_ATE_Proc }, // set ATE Mode to: STOP, TXCONT, TXCARR, TXFRAME, RXFRAME
195 {"ATEDA", Set_ATE_DA_Proc }, // set ATE TxFrames ADDR1, DA
196 {"ATESA", Set_ATE_SA_Proc }, // set ATE TxFrames ADDR2, SA
197 {"ATEBSSID", Set_ATE_BSSID_Proc }, // set ATE TxFrames ADDR3, BSSID
198 {"ATECHANNEL",Set_ATE_CHANNEL_Proc }, // set ATE Channel
199 {"ATETXPOW", Set_ATE_TX_POWER_Proc }, // set ATE TxPower
200 {"ATETXLEN", Set_ATE_TX_LENGTH_Proc}, // set ATE TxLength
201 {"ATETXCNT", Set_ATE_TX_COUNT_Proc }, // set ATE TxCount
202 {"ATETXRATE", Set_ATE_TX_RATE_Proc }, // set ATE TxRate
203 #endif //#ifdef RALINK_ATE
205 {NULL,}
208 char * rtstrchr(const char * s, int c)
210 for(; *s != (char) c; ++s)
211 if (*s == '\0')
212 return NULL;
213 return (char *) s;
216 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
218 int rt_ioctl_giwrange(struct net_device *dev,
219 struct iw_request_info *info,
220 struct iw_point *data, char *extra)
222 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
223 struct iw_range *range = (struct iw_range *) extra;
224 u16 val;
225 int i;
227 //check if the interface is down
228 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
230 DBGPRINT(RT_DEBUG_TRACE, "INFO::Network is down!\n");
231 return -ENETDOWN;
234 DBGPRINT(RT_DEBUG_TRACE,"0. rtusb_ioctl_giwrange\n");
235 data->length = sizeof(struct iw_range);
236 memset(range, 0, sizeof(struct iw_range));
238 range->txpower_capa = IW_TXPOW_DBM;
240 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
242 range->min_pmp = 1 * 1024;
243 range->max_pmp = 65535 * 1024;
244 range->min_pmt = 1 * 1024;
245 range->max_pmt = 1000 * 1024;
246 range->pmp_flags = IW_POWER_PERIOD;
247 range->pmt_flags = IW_POWER_TIMEOUT;
248 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
249 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
252 range->we_version_compiled = WIRELESS_EXT;
253 range->we_version_source = 14;
255 range->retry_capa = IW_RETRY_LIMIT;
256 range->retry_flags = IW_RETRY_LIMIT;
257 range->min_retry = 0;
258 range->max_retry = 255;
260 range->num_channels = pAdapter->PortCfg.ChannelListNum;
262 val = 0;
263 for (i = 0; i < pAdapter->PortCfg.ChannelListNum; i++) {
264 range->freq[val].i =pAdapter->PortCfg.ChannelList[i];
265 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.ChannelList[i],range->freq[val].m );
266 range->freq[val].e = 1;
267 val++;
268 if (val == IW_MAX_FREQUENCIES)
269 break;
271 range->num_frequency = val;
273 range->max_qual.qual = 100; /* what is correct max? This was not
274 * documented exactly. At least
275 * 69 has been observed. */
276 range->max_qual.level = 1; /* dB */
277 range->max_qual.noise = 152; /* dB */
278 range->max_qual.updated = 172; /* Updated all three */
280 /* What would be suitable values for "average/typical" qual? */
281 range->avg_qual.qual = pAdapter->Mlme.ChannelQuality;
282 range->avg_qual.level = pAdapter->PortCfg.LastRssi;
283 range->avg_qual.noise = 0;
284 range->avg_qual.updated = 7; /* Updated all three */
286 range->sensitivity = -30;
288 range->max_encoding_tokens = NR_WEP_KEYS;
289 range->num_encoding_sizes = 2;
290 range->encoding_size[0] = 5;
291 range->encoding_size[1] = 13;
293 for (i = 0; i < pAdapter->PortCfg.SupportedRatesLen; i++) {
294 range->bitrate[range->num_bitrates] =(pAdapter->PortCfg.SupportedRates[i] & 0x7f)*5000;
295 range->num_bitrates++;
297 range->throughput = 22000000;
298 #if 0
299 over2 = 0;
300 len = prism2_get_datarates(dev, rates);
301 range->num_bitrates = 0;
302 for (i = 0; i < len; i++) {
303 if (range->num_bitrates < IW_MAX_BITRATES) {
304 range->bitrate[range->num_bitrates] =
305 rates[i] * 500000;
306 range->num_bitrates++;
308 if (rates[i] == 0x0b || rates[i] == 0x16)
309 over2 = 1;
311 /* estimated maximum TCP throughput values (bps) */
312 range->throughput = over2 ? 5500000 : 1500000;
313 #endif
314 range->min_rts = 0;
315 range->max_rts = 2347;
316 range->min_frag = 256;
317 range->max_frag = 2346;
319 return 0;
322 static int
323 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
324 void *w, char *extra)
326 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
327 char *this_char;
328 char *value;
329 int Status;
331 while ((this_char = strsep(&extra, ",")) != NULL)
333 if (!*this_char)
334 continue;
336 if ((value = rtstrchr(this_char, '=')) != NULL)
337 *value++ = 0;
339 if (!value || !*value)
340 continue;
342 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
344 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
346 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
347 { //FALSE:Set private failed then return Invalid argument
348 Status = -EINVAL;
350 break; //Exit for loop.
354 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
355 { //Not found argument
356 Status = -EINVAL;
357 DBGPRINT(RT_DEBUG_TRACE, "ioctl::(iwpriv) Not Support Set Command [%s=%s]\n", this_char, value);
358 break;
361 return 0;
364 static const iw_handler rt_priv_handlers[] = {
365 (iw_handler) rt_ioctl_setparam, /* SIOCWFIRSTPRIV+0 */
368 #ifdef SIOCGIWSCAN
369 int rt_ioctl_siwscan(struct net_device *dev,
370 struct iw_request_info *info,
371 struct iw_point *data, char *extra)
373 ULONG Now;
374 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
375 int Status = NDIS_STATUS_SUCCESS;
376 BOOLEAN StateMachineTouched = FALSE;
379 //check if the interface is down
380 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
382 DBGPRINT(RT_DEBUG_TRACE, "INFO::Network is down!\n");
383 return -ENETDOWN;
386 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
387 return 0;
389 Now = jiffies;
391 if ((pAdapter->MediaState == NdisMediaStateConnected) &&
392 ((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ||
393 (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
394 (pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
397 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
398 Status = NDIS_STATUS_SUCCESS;
399 break;
402 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
404 MlmeRestartStateMachine(pAdapter);
405 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
408 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
409 // this request, because this request is initiated by NDIS.
410 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
411 // Reset Missed scan number
412 pAdapter->PortCfg.IgnoredScanNumber = 0;
413 pAdapter->PortCfg.LastScanTime = Now;
415 MlmeEnqueue(&pAdapter->Mlme.Queue,
416 MLME_CNTL_STATE_MACHINE,
417 OID_802_11_BSSID_LIST_SCAN,
419 NULL);
421 Status = NDIS_STATUS_SUCCESS;
422 StateMachineTouched = TRUE;
423 }while(0);
424 return 0;
427 rt_ioctl_giwscan(struct net_device *dev,
428 struct iw_request_info *info,
429 struct iw_point *data, char *extra)
432 PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;
433 int i=2, j;
434 char *current_ev = extra;
435 char *end_buf = extra + IW_SCAN_MAX_DATA;
436 char *current_val;
437 struct iw_event iwe;
439 //check if the interface is down
440 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
442 DBGPRINT(RT_DEBUG_TRACE, "INFO::Network is down!\n");
443 return -ENETDOWN;
446 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)){
448 * Still scanning, indicate the caller should try again.
450 return -EAGAIN;
452 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
454 if (current_ev >= end_buf)
455 break;
457 //================================
458 memset(&iwe, 0, sizeof(iwe));
459 iwe.cmd = SIOCGIWAP;
460 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
461 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, ETH_ALEN);
462 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
463 //================================
464 memset(&iwe, 0, sizeof(iwe));
465 iwe.cmd = SIOCGIWMODE;
466 if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11IBSS)
468 iwe.u.mode = IW_MODE_ADHOC;
470 else if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
472 iwe.u.mode = IW_MODE_INFRA;
474 else
476 iwe.u.mode = IW_MODE_AUTO;
479 iwe.len = IW_EV_UINT_LEN;
480 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
481 //================================
482 memset(&iwe, 0, sizeof(iwe));
483 iwe.cmd = SIOCGIWESSID;
484 iwe.u.data.length = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
485 iwe.u.data.flags = 1;
486 current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
487 //================================
488 memset(&iwe, 0, sizeof(iwe));
489 iwe.cmd = SIOCGIWENCODE;
490 if (CAP_IS_PRIVACY_ON (pAdapter->PortCfg.BssTab.BssEntry[i].CapabilityInfo ))
491 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
492 else
493 iwe.u.data.flags = IW_ENCODE_DISABLED;
494 current_ev = iwe_stream_add_point(current_ev, end_buf,&iwe, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid);
496 //================================
497 memset(&iwe, 0, sizeof(iwe));
498 iwe.cmd = SIOCGIWRATE;
499 current_val = current_ev + IW_EV_LCP_LEN;
500 //for (j = 0; j < pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen;j++)
501 for (j = 0; j < 1;j++)
503 iwe.u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.BssTab.BssEntry[i].Rates[i]/2] * 1000000;
504 iwe.u.bitrate.disabled = 0;
505 current_val = iwe_stream_add_value(current_ev,
506 current_val, end_buf, &iwe,
507 IW_EV_PARAM_LEN);
509 //================================
510 memset(&iwe, 0, sizeof(iwe));
511 iwe.cmd = SIOCGIWFREQ;
512 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
513 iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
514 else
515 iwe.u.freq.m = pAdapter->PortCfg.BssTab.BssEntry[i].Channel;
516 iwe.u.freq.e = 0;
517 iwe.u.freq.i = 0;
518 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
519 //================================
520 memset(&iwe, 0, sizeof(iwe));
523 data->length = current_ev - extra;
524 DBGPRINT(RT_DEBUG_TRACE,"rtusb_ioctl_giwscan. %d BSS returned\n",pAdapter->PortCfg.BssTab.BssNr);
525 return 0;
527 #endif
528 static const iw_handler rt_handler[] =
530 (iw_handler) NULL, /* SIOCSIWCOMMIT */
531 (iw_handler) NULL, /* SIOCGIWNAME 1 */
532 (iw_handler) NULL, /* SIOCSIWNWID */
533 (iw_handler) NULL, /* SIOCGIWNWID */
534 (iw_handler) NULL, /* SIOCSIWFREQ */
535 (iw_handler) NULL, /* SIOCGIWFREQ 5*/
536 (iw_handler) NULL, /* SIOCSIWMODE */
537 (iw_handler) NULL, /* SIOCGIWMODE */
538 (iw_handler) NULL, /* SIOCSIWSENS */
539 (iw_handler) NULL, /* SIOCGIWSENS */
540 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
541 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE 11 */
542 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
543 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
544 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
545 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS f*/
546 (iw_handler) NULL, /* SIOCSIWSPY */
547 (iw_handler) NULL, /* SIOCGIWSPY */
548 (iw_handler) NULL, /* -- hole -- */
549 (iw_handler) NULL, /* -- hole -- */
550 (iw_handler) NULL, /* SIOCSIWAP */
551 (iw_handler) NULL, /* SIOCGIWAP 0x15*/
552 (iw_handler) NULL, /* -- hole -- 0x16 */
553 (iw_handler) NULL, /* SIOCGIWAPLIST */
554 #ifdef SIOCGIWSCAN
555 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN 0x18*/
556 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
557 #else
558 (iw_handler) NULL, /* SIOCSIWSCAN */
559 (iw_handler) NULL, /* SIOCGIWSCAN */
560 #endif /* SIOCGIWSCAN */
561 (iw_handler) NULL, /* SIOCSIWESSID */
562 (iw_handler) NULL, /* SIOCGIWESSID */
563 (iw_handler) NULL, /* SIOCSIWNICKN */
564 (iw_handler) NULL, /* SIOCGIWNICKN 1d*/
565 (iw_handler) NULL, /* -- hole -- */
566 (iw_handler) NULL, /* -- hole -- */
567 (iw_handler) NULL, /* SIOCSIWRATE 20*/
568 (iw_handler) NULL, /* SIOCGIWRATE */
569 (iw_handler) NULL, /* SIOCSIWRTS */
570 (iw_handler) NULL, /* SIOCGIWRTS */
571 (iw_handler) NULL, /* SIOCSIWFRAG */
572 (iw_handler) NULL, /* SIOCGIWFRAG 25*/
573 (iw_handler) NULL, /* SIOCSIWTXPOW */
574 (iw_handler) NULL, /* SIOCGIWTXPOW */
575 (iw_handler) NULL, /* SIOCSIWRETRY */
576 (iw_handler) NULL, /* SIOCGIWRETRY 29*/
577 (iw_handler) NULL, /* SIOCSIWENCODE 2a*/
578 (iw_handler) NULL, /* SIOCGIWENCODE 2b*/
579 (iw_handler) NULL, /* SIOCSIWPOWER 2c*/
580 (iw_handler) NULL, /* SIOCGIWPOWER 2d*/
583 const struct iw_handler_def rt2500_iw_handler_def =
585 #define N(a) (sizeof (a) / sizeof (a[0]))
586 .standard = (iw_handler *) rt_handler,
587 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
588 .private = (iw_handler *) rt_priv_handlers,
589 .num_private = N(rt_priv_handlers),
590 .private_args = (struct iw_priv_args *) privtab,
591 .num_private_args = N(privtab),
592 #if WIRELESS_EXT > 15
593 // .spy_offset = offsetof(struct hostap_interface, spy_data),
594 #endif /* WIRELESS_EXT > 15 */
596 INT RTMPSetInformation(
597 IN PRTMP_ADAPTER pAdapter,
598 IN OUT struct ifreq *rq,
599 IN INT cmd)
601 struct iwreq *wrq = (struct iwreq *) rq;
602 NDIS_802_11_SSID Ssid, *pSsid=NULL;
603 NDIS_802_11_MAC_ADDRESS Bssid;
604 RT_802_11_PHY_MODE PhyMode;
605 RT_802_11_STA_CONFIG StaConfig;
606 NDIS_802_11_RATES aryRates;
607 RT_802_11_PREAMBLE Preamble;
608 NDIS_802_11_WEP_STATUS WepStatus;
609 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
610 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
611 NDIS_802_11_RTS_THRESHOLD RtsThresh;
612 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
613 NDIS_802_11_POWER_MODE PowerMode;
614 NDIS_802_11_TX_POWER_LEVEL TxPowerLevel;
615 PNDIS_802_11_KEY pKey = NULL;
616 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
617 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
618 ULONG Now;
619 ULONG KeyIdx;
620 INT Status = NDIS_STATUS_SUCCESS;
621 UCHAR CountryRegion;
622 BOOLEAN RadioState;
623 BOOLEAN StateMachineTouched = FALSE;
624 USHORT TxTotalCnt;
626 switch(cmd & 0x7FFF) {
627 case RT_OID_802_11_COUNTRY_REGION:
628 if (wrq->u.data.length != sizeof(CountryRegion))
629 Status = -EINVAL;
630 else
632 Status = copy_from_user(&CountryRegion, wrq->u.data.pointer, wrq->u.data.length);
633 pAdapter->PortCfg.CountryRegion = CountryRegion;
634 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_COUNTRY_REGION (=%d) \n", pAdapter->PortCfg.CountryRegion);
636 break;
637 case OID_802_11_BSSID_LIST_SCAN:
638 Now = jiffies;
639 TxTotalCnt = pAdapter->DrsCounters.OneSecTxOkCount +
640 pAdapter->DrsCounters.OneSecTxRetryOkCount +
641 pAdapter->DrsCounters.OneSecTxFailCount;
642 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", TxTotalCnt);
643 // For XP WZC, we will allow scan every 10 times, roughly 10 minutes.
644 // if ((Oid == OID_802_11_BSSID_LIST_SCAN) &&
645 // (pAdapter->MediaState == NdisMediaStateConnected) &&
646 // (pAdapter->PortCfg.IgnoredScanNumber < 10))
647 if (TxTotalCnt > 100)
649 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
650 Status = NDIS_STATUS_SUCCESS;
651 pAdapter->PortCfg.IgnoredScanNumber++;
652 break;
655 if ((pAdapter->MediaState == NdisMediaStateConnected) &&
656 ((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ||
657 (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
658 (pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)
661 DBGPRINT(RT_DEBUG_TRACE, "!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n");
662 Status = NDIS_STATUS_SUCCESS;
663 break;
666 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
668 MlmeRestartStateMachine(pAdapter);
669 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
672 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
673 // this request, because this request is initiated by NDIS.
674 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
675 // Reset Missed scan number
676 pAdapter->PortCfg.IgnoredScanNumber = 0;
677 pAdapter->PortCfg.LastScanTime = Now;
679 MlmeEnqueue(&pAdapter->Mlme.Queue,
680 MLME_CNTL_STATE_MACHINE,
681 OID_802_11_BSSID_LIST_SCAN,
683 NULL);
685 Status = NDIS_STATUS_SUCCESS;
686 StateMachineTouched = TRUE;
687 break;
688 case OID_802_11_SSID:
689 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
690 Status = -EINVAL;
691 else
693 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
694 pSsid = &Ssid;
696 if (pSsid->SsidLength > MAX_LEN_OF_SSID)
697 Status = -EINVAL;
698 else
700 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
702 MlmeRestartStateMachine(pAdapter);
703 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
705 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
706 // this request, because this request is initiated by NDIS.
707 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
709 MlmeEnqueue(&pAdapter->Mlme.Queue,
710 MLME_CNTL_STATE_MACHINE,
711 OID_802_11_SSID,
712 sizeof(NDIS_802_11_SSID),
713 (VOID *)pSsid
715 Status = NDIS_STATUS_SUCCESS;
716 StateMachineTouched = TRUE;
718 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", pSsid->SsidLength, pSsid->Ssid);
721 break;
722 case OID_802_11_BSSID:
723 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
724 Status = -EINVAL;
725 else
727 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
729 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
731 MlmeRestartStateMachine(pAdapter);
732 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
735 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
736 // this request, because this request is initiated by NDIS.
737 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
739 MlmeEnqueue(&pAdapter->Mlme.Queue,
740 MLME_CNTL_STATE_MACHINE,
741 OID_802_11_BSSID,
742 sizeof(NDIS_802_11_MAC_ADDRESS),
743 (VOID *)&Bssid);
744 Status = NDIS_STATUS_SUCCESS;
745 StateMachineTouched = TRUE;
746 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
747 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]);
749 break;
750 case RT_OID_802_11_RADIO:
751 if (wrq->u.data.length != sizeof(BOOLEAN))
752 Status = -EINVAL;
753 else
755 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
756 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_RADIO (=%d)\n", RadioState);
757 if (pAdapter->PortCfg.bSwRadio != RadioState)
759 pAdapter->PortCfg.bSwRadio = RadioState;
760 if (pAdapter->PortCfg.bRadio != (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio))
762 pAdapter->PortCfg.bRadio = (pAdapter->PortCfg.bHwRadio && pAdapter->PortCfg.bSwRadio);
763 if (pAdapter->PortCfg.bRadio == TRUE)
764 MlmeRadioOn(pAdapter);
765 else
766 MlmeRadioOff(pAdapter);
770 break;
771 case RT_OID_802_11_PHY_MODE:
772 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
773 Status = -EINVAL;
774 else
776 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
777 RTMPSetPhyMode(pAdapter, PhyMode);
778 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode);
780 break;
781 case RT_OID_802_11_STA_CONFIG:
782 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
783 Status = -EINVAL;
784 else
786 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
787 pAdapter->PortCfg.EnableTxBurst = StaConfig.EnableTxBurst;
788 pAdapter->PortCfg.EnableTurboRate = StaConfig.EnableTurboRate;
789 pAdapter->PortCfg.UseBGProtection = StaConfig.UseBGProtection;
790 // pAdapter->PortCfg.UseShortSlotTime = StaConfig.UseShortSlotTime;
791 pAdapter->PortCfg.UseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
792 if (pAdapter->PortCfg.AdhocMode != StaConfig.AdhocMode)
794 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
795 // if setting changed, need to reset current TX rate as well as BEACON frame format
796 pAdapter->PortCfg.AdhocMode = StaConfig.AdhocMode;
797 if (pAdapter->PortCfg.BssType == BSS_INDEP)
799 MlmeUpdateTxRates(pAdapter, FALSE);
800 MakeIbssBeacon(pAdapter);
803 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",
804 pAdapter->PortCfg.EnableTxBurst,
805 pAdapter->PortCfg.EnableTurboRate,
806 pAdapter->PortCfg.UseBGProtection,
807 pAdapter->PortCfg.UseShortSlotTime,
808 pAdapter->PortCfg.AdhocMode);
810 break;
811 case OID_802_11_DESIRED_RATES:
812 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
813 Status = -EINVAL;
814 else
816 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
817 NdisZeroMemory(pAdapter->PortCfg.DesiredRates, MAX_LEN_OF_SUPPORTED_RATES);
818 NdisMoveMemory(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
819 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
820 pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
821 pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
822 pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
823 pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
824 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
825 MlmeUpdateTxRates(pAdapter, FALSE);
827 break;
828 case RT_OID_802_11_PREAMBLE:
829 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
830 Status = -EINVAL;
831 else
833 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
834 if (Preamble == Rt802_11PreambleShort)
836 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
837 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
839 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
841 // if user wants AUTO, initialize to LONG here, then change according to AP's
842 // capability upon association.
843 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
844 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
846 else
848 Status = EINVAL;
849 break;
851 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_SET_PREAMBLE (=%d)\n", Preamble);
853 break;
854 case OID_802_11_WEP_STATUS:
855 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
856 Status = -EINVAL;
857 else
859 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
860 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
861 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
863 if (pAdapter->PortCfg.WepStatus != WepStatus)
865 // Config has changed
866 pAdapter->bConfigChanged = TRUE;
868 pAdapter->PortCfg.WepStatus = WepStatus;
870 else
872 Status = -EINVAL;
873 break;
875 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus);
877 break;
878 case OID_802_11_AUTHENTICATION_MODE:
879 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
880 Status = -EINVAL;
881 else
883 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
884 if (AuthMode > Ndis802_11AuthModeMax)
886 Status = -EINVAL;
887 break;
889 else
891 if (pAdapter->PortCfg.AuthMode != AuthMode)
893 // Config has changed
894 pAdapter->bConfigChanged = TRUE;
896 pAdapter->PortCfg.AuthMode = AuthMode;
898 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
899 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->PortCfg.AuthMode);
901 break;
902 case OID_802_11_INFRASTRUCTURE_MODE:
903 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
904 Status = -EINVAL;
905 else
907 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
908 if (BssType == Ndis802_11IBSS)
910 if (pAdapter->PortCfg.BssType != BSS_INDEP)
912 // Config has changed
913 pAdapter->bConfigChanged = TRUE;
915 pAdapter->PortCfg.BssType = BSS_INDEP;
916 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (AD-HOC)\n");
918 else if (BssType == Ndis802_11Infrastructure)
920 if (pAdapter->PortCfg.BssType != BSS_INFRA)
922 // Config has changed
923 pAdapter->bConfigChanged = TRUE;
925 pAdapter->PortCfg.BssType = BSS_INFRA;
926 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (INFRA)\n");
928 else
930 Status = -EINVAL;
931 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n");
934 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
935 pAdapter->PortCfg.WpaState = SS_NOTUSE;
936 break;
937 case RT_OID_802_11_RESET_COUNTERS:
938 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
939 NdisZeroMemory(&pAdapter->Counters, sizeof(COUNTER_802_3));
940 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
941 NdisZeroMemory(&pAdapter->Mlme.PrevWlanCounters, sizeof(COUNTER_802_11));
942 DBGPRINT(RT_DEBUG_INFO, "Set::RT_OID_802_11_RESET_COUNTERS \n");
943 break;
944 case OID_802_11_RTS_THRESHOLD:
945 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
946 Status = -EINVAL;
947 else
949 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
950 if (RtsThresh > MAX_RTS_THRESHOLD)
951 Status = -EINVAL;
952 else
953 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
955 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_RTS_THRESHOLD (=%d)\n",RtsThresh);
956 break;
957 case OID_802_11_FRAGMENTATION_THRESHOLD:
958 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
959 Status = -EINVAL;
960 else
962 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
963 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
964 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
966 if (FragThresh == 0)
968 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
969 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
971 else
972 Status = -EINVAL;
974 else
975 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
977 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%d) \n",FragThresh);
978 break;
979 case OID_802_11_POWER_MODE:
980 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
981 Status = -EINVAL;
982 else
984 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
985 // save user's policy here, but not change PortCfg.Psm immediately
986 if (PowerMode == Ndis802_11PowerModeCAM)
988 // clear PSM bit immediately
989 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
990 pAdapter->PortCfg.RecvDtim = TRUE;
991 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
992 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
993 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
995 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
997 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
998 // to exclude certain situations.
999 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
1000 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
1001 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
1002 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
1003 pAdapter->PortCfg.RecvDtim = TRUE; // FALSE;
1004 pAdapter->PortCfg.DefaultListenCount = 5;
1006 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
1008 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1009 // to exclude certain situations.
1010 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
1011 pAdapter->PortCfg.RecvDtim = TRUE;
1012 if (pAdapter->PortCfg.WindowsACCAMEnable == FALSE)
1013 pAdapter->PortCfg.WindowsPowerMode = PowerMode;
1014 pAdapter->PortCfg.WindowsBatteryPowerMode = PowerMode;
1015 pAdapter->PortCfg.DefaultListenCount = 3;
1017 else
1018 Status = -EINVAL;
1020 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode);
1021 break;
1022 case OID_802_11_TX_POWER_LEVEL:
1023 if (wrq->u.data.length != sizeof(NDIS_802_11_TX_POWER_LEVEL))
1024 Status = -EINVAL;
1025 else
1027 Status = copy_from_user(&TxPowerLevel, wrq->u.data.pointer, wrq->u.data.length);
1028 if (TxPowerLevel > MAX_TX_POWER_LEVEL)
1029 Status = -EINVAL;
1030 else
1031 pAdapter->PortCfg.TxPower = (UCHAR)TxPowerLevel;
1033 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_TX_POWER_LEVEL (=%d) \n",TxPowerLevel);
1034 break;
1035 // For WPA PSK PMK key
1036 case RT_OID_802_11_ADD_WPA:
1037 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1038 if(pKey == NULL)
1040 Status = -ENOMEM;
1041 break;
1044 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
1045 if (pKey->Length != wrq->u.data.length)
1047 Status = -EINVAL;
1048 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!!\n");
1050 else
1052 if (pAdapter->PortCfg.AuthMode != Ndis802_11AuthModeWPAPSK)
1054 Status = -EOPNOTSUPP;
1055 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK]\n");
1057 else // Only for WPA PSK mode
1059 pAdapter->PortCfg.PskKey.KeyLen = (UCHAR) pKey->KeyLength;
1060 NdisMoveMemory(pAdapter->PortCfg.PskKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
1061 // Use RaConfig as PSK agent.
1062 // Start STA supplicant state machine
1063 pAdapter->PortCfg.WpaState = SS_START;
1065 DBGPRINT(RT_DEBUG_TRACE, "Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength);
1068 kfree(pKey);
1069 break;
1070 case OID_802_11_REMOVE_KEY:
1071 pRemoveKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1072 if(pRemoveKey == NULL)
1074 Status = -ENOMEM;
1075 break;
1078 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
1079 if (pRemoveKey->Length != wrq->u.data.length)
1081 Status = -EINVAL;
1082 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!\n");
1084 else
1086 if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1088 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
1089 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n");
1091 else
1093 KeyIdx = pRemoveKey->KeyIndex;
1095 if (KeyIdx & 0x80000000)
1097 // Should never set default bit when remove key
1098 Status = -EINVAL;
1099 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n");
1101 else
1103 KeyIdx = KeyIdx & 0x0fffffff;
1104 if (KeyIdx > 3)
1106 Status = -EINVAL;
1107 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx);
1109 else
1111 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
1112 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length);
1117 kfree(pRemoveKey);
1118 break;
1119 case OID_802_11_ADD_KEY:
1120 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
1121 if(pKey == NULL)
1123 Status = -ENOMEM;
1124 break;
1127 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
1128 if (pKey->Length != wrq->u.data.length)
1130 Status = -EINVAL;
1131 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY, Failed!!\n");
1133 else
1135 if (pAdapter->PortCfg.AuthMode >= Ndis802_11AuthModeWPA)
1137 RTMPWPAAddKeyProc(pAdapter, pKey);
1139 else // Old WEP stuff
1141 KeyIdx = pKey->KeyIndex & 0x0fffffff;
1143 // it is a shared key
1144 if (KeyIdx > 4)
1145 Status = -EINVAL;
1146 else
1148 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
1149 NdisMoveMemory(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
1150 if (pKey->KeyIndex & 0x80000000)
1152 // Default key for tx (shared key)
1153 pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
1157 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength);
1159 kfree(pKey);
1160 break;
1161 case OID_802_11_CONFIGURATION:
1162 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
1163 Status = -EINVAL;
1164 else
1166 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
1167 pConfig = &Config;
1168 pAdapter->PortCfg.IbssConfig.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
1169 pAdapter->PortCfg.IbssConfig.AtimWin = (USHORT) pConfig->ATIMWindow;
1170 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->PortCfg.IbssConfig.Channel);
1171 DBGPRINT(RT_DEBUG_TRACE, "Set::OID_802_11_CONFIGURATION (BeacnPeriod=%d,AtimW=%d,Ch=%d)\n",
1172 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->PortCfg.IbssConfig.Channel);
1173 // Config has changed
1174 pAdapter->bConfigChanged = TRUE;
1176 break;
1177 default:
1178 DBGPRINT(RT_DEBUG_TRACE, "Set::unknown IOCTL's subcmd = 0x%08x\n", cmd);
1179 Status = -EOPNOTSUPP;
1180 break;
1183 return Status;
1186 INT RTMPQueryInformation(
1187 IN PRTMP_ADAPTER pAdapter,
1188 IN OUT struct ifreq *rq,
1189 IN INT cmd)
1191 struct iwreq *wrq = (struct iwreq *) rq;
1192 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
1193 PNDIS_WLAN_BSSID_EX pBss;
1194 NDIS_802_11_SSID Ssid;
1195 NDIS_802_11_CONFIGURATION Configuration;
1196 RT_802_11_LINK_STATUS LinkStatus;
1197 RT_802_11_STA_CONFIG StaConfig;
1198 NDIS_802_11_STATISTICS Statistics;
1199 NDIS_802_11_RTS_THRESHOLD RtsThresh;
1200 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1201 NDIS_802_11_POWER_MODE PowerMode;
1202 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
1203 RT_802_11_PREAMBLE PreamType;
1204 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
1205 NDIS_802_11_WEP_STATUS WepStatus;
1206 RT_VERSION_INFO DriverVersionInfo;
1207 ULONG BssBufSize;
1208 ULONG BssLen;
1209 ULONG ulInfo = 0;
1210 ULONG FcsValue;
1211 PUCHAR pBuf = NULL;
1212 PUCHAR pPtr;
1213 INT Status = NDIS_STATUS_SUCCESS;
1214 UCHAR Padding;
1215 UINT i;
1216 BOOLEAN RadioState;
1218 switch(cmd) {
1219 case RT_OID_DEVICE_NAME:
1220 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_DEVICE_NAME\n");
1221 wrq->u.data.length = sizeof(NIC_DEVICE_NAME);
1222 Status = copy_to_user(wrq->u.data.pointer, NIC_DEVICE_NAME, wrq->u.data.length);
1223 break;
1224 case RT_OID_VERSION_INFO:
1225 DBGPRINT(RT_DEBUG_INFO, "Query::RT_OID_VERSION_INFO \n");
1226 DriverVersionInfo.DriverVersionW = DRV_MAJORVERSION;
1227 DriverVersionInfo.DriverVersionX = DRV_MINORVERSION;
1228 DriverVersionInfo.DriverVersionY = DRV_SUBVERSION;
1229 DriverVersionInfo.DriverVersionZ = DRV_TESTVERSION;
1230 DriverVersionInfo.DriverBuildYear = DRV_YEAR;
1231 DriverVersionInfo.DriverBuildMonth = DRV_MONTH;
1232 DriverVersionInfo.DriverBuildDay = DRV_DAY;
1233 wrq->u.data.length = sizeof(RT_VERSION_INFO);
1234 Status = copy_to_user(wrq->u.data.pointer, &DriverVersionInfo, wrq->u.data.length);
1235 break;
1236 case OID_802_11_BSSID_LIST:
1237 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->PortCfg.BssTab.BssNr);
1238 // Claculate total buffer size required
1239 BssBufSize = sizeof(ULONG);
1241 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1243 // Align pointer to 4 bytes boundary.
1244 Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1245 if (Padding == 4)
1246 Padding = 0;
1247 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 4 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding);
1250 // For safety issue, we add 256 bytes just in case
1251 BssBufSize += 256;
1252 // Allocate the same size as passed from higher layer
1253 pBuf = kmalloc(BssBufSize, GFP_KERNEL);
1254 if(pBuf == NULL)
1256 Status = -ENOMEM;
1257 break;
1259 // Init 802_11_BSSID_LIST_EX structure
1260 NdisZeroMemory(pBuf, BssBufSize);
1261 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
1262 pBssidList->NumberOfItems = pAdapter->PortCfg.BssTab.BssNr;
1264 // Calculate total buffer length
1265 BssLen = 4; // Consist of NumberOfItems
1266 // Point to start of NDIS_WLAN_BSSID_EX
1267 // pPtr = pBuf + sizeof(ULONG);
1268 pPtr = (PUCHAR) &pBssidList->Bssid[0];
1269 for (i = 0; i < pAdapter->PortCfg.BssTab.BssNr; i++)
1271 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
1272 NdisMoveMemory(&pBss->MacAddress, &pAdapter->PortCfg.BssTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
1273 if ((pAdapter->PortCfg.BssTab.BssEntry[i].Hidden == 1) && (pAdapter->PortCfg.bShowHiddenSSID == FALSE))
1275 pBss->Ssid.SsidLength = 0;
1277 else
1279 pBss->Ssid.SsidLength = pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen;
1280 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].Ssid, pAdapter->PortCfg.BssTab.BssEntry[i].SsidLen);
1282 pBss->Privacy = pAdapter->PortCfg.BssTab.BssEntry[i].Privacy;
1283 pBss->Rssi = pAdapter->PortCfg.BssTab.BssEntry[i].Rssi - pAdapter->PortCfg.RssiToDbm;
1284 pBss->NetworkTypeInUse = Ndis802_11DS;
1285 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1286 pBss->Configuration.BeaconPeriod = pAdapter->PortCfg.BssTab.BssEntry[i].BeaconPeriod;
1287 pBss->Configuration.ATIMWindow = pAdapter->PortCfg.BssTab.BssEntry[i].AtimWin;
1289 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.BssTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
1291 if (pAdapter->PortCfg.BssTab.BssEntry[i].BssType == BSS_INFRA)
1292 pBss->InfrastructureMode = Ndis802_11Infrastructure;
1293 else
1294 pBss->InfrastructureMode = Ndis802_11IBSS;
1296 NdisMoveMemory(pBss->SupportedRates, pAdapter->PortCfg.BssTab.BssEntry[i].Rates, pAdapter->PortCfg.BssTab.BssEntry[i].RatesLen);
1298 DBGPRINT(RT_DEBUG_TRACE, "BSS#%d - %s, Ch %d = %d Khz\n",
1299 i,pBss->Ssid.Ssid,pAdapter->PortCfg.BssTab.BssEntry[i].Channel,pBss->Configuration.DSConfig);
1301 if (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen == 0)
1303 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
1304 NdisMoveMemory(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1305 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
1307 else
1309 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1310 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
1311 NdisMoveMemory(pBss->IEs, &pAdapter->PortCfg.BssTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
1312 NdisMoveMemory(pPtr, pAdapter->PortCfg.BssTab.BssEntry[i].VarIEs, pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen);
1313 pPtr += pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen;
1315 // Align pointer to 4 bytes boundary.
1316 Padding = 4 - (pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen & 0x0003);
1317 if (Padding == 4)
1318 Padding = 0;
1319 pPtr += Padding;
1320 pBss->Length = sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->PortCfg.BssTab.BssEntry[i].VarIELen + Padding;
1321 BssLen += pBss->Length;
1323 wrq->u.data.length = BssLen;
1324 Status = copy_to_user(wrq->u.data.pointer, pBssidList, wrq->u.data.length);
1325 kfree(pBssidList);
1326 break;
1327 case OID_802_3_CURRENT_ADDRESS:
1328 wrq->u.data.length = ETH_LENGTH_OF_ADDRESS;
1329 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
1330 DBGPRINT(RT_DEBUG_INFO, "Query::OID_802_3_CURRENT_ADDRESS \n");
1331 break;
1332 case OID_GEN_MEDIA_CONNECT_STATUS:
1333 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_MEDIA_CONNECT_STATUS \n");
1334 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
1335 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->MediaState, wrq->u.data.length);
1336 break;
1337 case OID_802_11_BSSID:
1338 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1340 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.Bssid, sizeof(MACADDR));
1342 DBGPRINT(RT_DEBUG_INFO, "IOCTL::SIOCGIWAP(=%02x:%02x:%02x:%02x:%02x:%02x)\n",
1343 pAdapter->PortCfg.Bssid.Octet[0],pAdapter->PortCfg.Bssid.Octet[1],pAdapter->PortCfg.Bssid.Octet[2],
1344 pAdapter->PortCfg.Bssid.Octet[3],pAdapter->PortCfg.Bssid.Octet[4],pAdapter->PortCfg.Bssid.Octet[5]);
1347 else
1349 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_BSSID(=EMPTY)\n");
1350 Status = -ENOTCONN;
1352 break;
1353 case OID_802_11_SSID:
1354 Ssid.SsidLength = pAdapter->PortCfg.SsidLen;
1355 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
1356 NdisMoveMemory(Ssid.Ssid, pAdapter->PortCfg.Ssid, Ssid.SsidLength);
1357 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
1358 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
1359 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid);
1360 break;
1361 case RT_OID_802_11_LINK_STATUS:
1362 LinkStatus.CurrTxRate = RateIdTo500Kbps[pAdapter->PortCfg.TxRate]; // unit : 500 kbps
1363 LinkStatus.ChannelQuality = pAdapter->Mlme.ChannelQuality;
1364 LinkStatus.RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
1365 LinkStatus.TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
1366 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
1367 Status = copy_to_user(wrq->u.data.pointer, &LinkStatus, wrq->u.data.length);
1368 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_LINK_STATUS\n");
1369 break;
1370 case OID_802_11_CONFIGURATION:
1371 Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
1372 Configuration.BeaconPeriod = pAdapter->PortCfg.BeaconPeriod;
1373 Configuration.ATIMWindow = pAdapter->PortCfg.AtimWin;
1374 MAP_CHANNEL_ID_TO_KHZ(pAdapter->PortCfg.Channel, Configuration.DSConfig);
1375 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
1376 Status = copy_to_user(wrq->u.data.pointer, &Configuration, wrq->u.data.length);
1377 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_CONFIGURATION(BeaconPeriod=%d,AtimW=%d,Channel=%d) \n",
1378 Configuration.BeaconPeriod, Configuration.ATIMWindow, pAdapter->PortCfg.Channel);
1379 break;
1380 case OID_802_11_RSSI:
1381 ulInfo = pAdapter->PortCfg.LastRssi - pAdapter->PortCfg.RssiToDbm;
1382 wrq->u.data.length = sizeof(ulInfo);
1383 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1384 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_RSSI(=%d)\n", ulInfo);
1385 break;
1386 case OID_802_11_STATISTICS:
1387 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_STATISTICS \n");
1388 // Update FCS counters
1389 RTMP_IO_READ32(pAdapter, CNT0, &FcsValue);
1390 pAdapter->WlanCounters.FCSErrorCount.QuadPart += ((FcsValue & 0x0000ffff) >> 7);
1391 // Add FCS error count to private counters
1392 pAdapter->RalinkCounters.RealFcsErrCount.QuadPart += FcsValue;
1394 // Sanity check for calculation of sucessful count
1395 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
1396 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1398 Statistics.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
1399 Statistics.MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
1400 Statistics.FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
1401 Statistics.RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
1402 Statistics.MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
1403 Statistics.RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
1404 Statistics.RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
1405 Statistics.ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
1406 Statistics.FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
1407 Statistics.ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
1408 Statistics.MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
1409 #ifdef RT2500_DBG
1410 Statistics.FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
1411 #else
1412 Statistics.FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
1413 Statistics.FrameDuplicateCount.vv.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.vv.LowPart / 100;
1414 #endif
1415 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
1416 Status = copy_to_user(wrq->u.data.pointer, &Statistics, wrq->u.data.length);
1417 break;
1418 case OID_GEN_RCV_OK:
1419 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_OK \n");
1420 ulInfo = pAdapter->Counters.GoodReceives;
1421 wrq->u.data.length = sizeof(ulInfo);
1422 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1423 break;
1424 case OID_GEN_RCV_NO_BUFFER:
1425 DBGPRINT(RT_DEBUG_INFO, "Query::OID_GEN_RCV_NO_BUFFER \n");
1426 ulInfo = pAdapter->Counters.RxNoBuffer;
1427 wrq->u.data.length = sizeof(ulInfo);
1428 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1429 break;
1430 case RT_OID_802_11_PHY_MODE:
1431 ulInfo = (ULONG)pAdapter->PortCfg.PhyMode;
1432 wrq->u.data.length = sizeof(ulInfo);
1433 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
1434 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_PHY_MODE (=%d)\n", ulInfo);
1435 break;
1436 case RT_OID_802_11_STA_CONFIG:
1437 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_STA_CONFIG\n");
1438 StaConfig.EnableTxBurst = pAdapter->PortCfg.EnableTxBurst;
1439 StaConfig.EnableTurboRate = pAdapter->PortCfg.EnableTurboRate;
1440 StaConfig.UseBGProtection = pAdapter->PortCfg.UseBGProtection;
1441 StaConfig.UseShortSlotTime = pAdapter->PortCfg.UseShortSlotTime;
1442 StaConfig.AdhocMode = pAdapter->PortCfg.AdhocMode;
1443 StaConfig.HwRadioStatus = (pAdapter->PortCfg.bHwRadio == TRUE) ? 1 : 0;
1444 StaConfig.Rsv1 = 0;
1445 StaConfig.SystemErrorBitmap = pAdapter->PortCfg.SystemErrorBitmap;
1446 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
1447 Status = copy_to_user(wrq->u.data.pointer, &StaConfig, wrq->u.data.length);
1448 break;
1449 case OID_802_11_RTS_THRESHOLD:
1450 RtsThresh = pAdapter->PortCfg.RtsThreshold;
1451 wrq->u.data.length = sizeof(RtsThresh);
1452 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
1453 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_RTS_THRESHOLD(=%d)\n", RtsThresh);
1454 break;
1455 case OID_802_11_FRAGMENTATION_THRESHOLD:
1456 FragThresh = pAdapter->PortCfg.FragmentThreshold;
1457 if (pAdapter->PortCfg.bFragmentZeroDisable == TRUE)
1458 FragThresh = 0;
1459 wrq->u.data.length = sizeof(FragThresh);
1460 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
1461 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%d)\n", FragThresh);
1462 break;
1463 case OID_802_11_POWER_MODE:
1464 PowerMode = pAdapter->PortCfg.WindowsPowerMode;
1465 wrq->u.data.length = sizeof(PowerMode);
1466 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
1467 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode);
1468 break;
1469 case RT_OID_802_11_RADIO:
1470 RadioState = (BOOLEAN) pAdapter->PortCfg.bSwRadio;
1471 wrq->u.data.length = sizeof(RadioState);
1472 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
1473 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState);
1474 break;
1475 case OID_802_11_INFRASTRUCTURE_MODE:
1476 if (ADHOC_ON(pAdapter))
1477 BssType = Ndis802_11IBSS;
1478 else if (INFRA_ON(pAdapter))
1479 BssType = Ndis802_11Infrastructure;
1480 else
1481 BssType = Ndis802_11AutoUnknown;
1483 wrq->u.data.length = sizeof(BssType);
1484 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
1485 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType);
1486 break;
1487 case RT_OID_802_11_PREAMBLE:
1488 PreamType = pAdapter->PortCfg.WindowsTxPreamble;
1489 wrq->u.data.length = sizeof(PreamType);
1490 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
1491 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_PREAMBLE(=%d)\n", PreamType);
1492 break;
1493 case OID_802_11_AUTHENTICATION_MODE:
1494 AuthMode = pAdapter->PortCfg.AuthMode;
1495 wrq->u.data.length = sizeof(AuthMode);
1496 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
1497 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode);
1498 break;
1499 case OID_802_11_WEP_STATUS:
1500 WepStatus = pAdapter->PortCfg.WepStatus;
1501 wrq->u.data.length = sizeof(WepStatus);
1502 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
1503 DBGPRINT(RT_DEBUG_TRACE, "Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus);
1504 break;
1506 case RT_OID_802_11_QUERY_EEPROM_VERSION:
1507 wrq->u.data.length = sizeof(ULONG);
1508 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->PortCfg.EepromVersion, wrq->u.data.length);
1509 DBGPRINT(RT_DEBUG_TRACE, "Query::RT_OID_802_11_QUERY_EEPROM_VERSION (=%d)\n", pAdapter->PortCfg.EepromVersion);
1510 break;
1512 default:
1513 DBGPRINT(RT_DEBUG_TRACE, "Query::unknown IOCTL's subcmd = 0x%08x\n", cmd);
1514 Status = -EOPNOTSUPP;
1515 break;
1518 return Status;
1521 INT RT2500_ioctl(
1522 IN struct net_device *net_dev,
1523 IN OUT struct ifreq *rq,
1524 IN INT cmd)
1526 PRTMP_ADAPTER pAdapter= net_dev->priv;
1527 struct iwreq *wrq = (struct iwreq *) rq;
1528 struct iw_point *erq = NULL;
1529 struct iw_freq *frq = NULL;
1530 NDIS_802_11_SSID Ssid, *pSsid=NULL;
1531 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType = Ndis802_11Infrastructure;
1532 NDIS_802_11_RTS_THRESHOLD RtsThresh;
1533 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
1534 NDIS_802_11_MAC_ADDRESS Bssid;
1535 INT Status = NDIS_STATUS_SUCCESS;
1536 USHORT subcmd;
1537 BOOLEAN StateMachineTouched = FALSE;
1538 int i, chan = -1, index = 0, len = 0;
1540 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1542 DBGPRINT(RT_DEBUG_TRACE, "INFO::Network is down!\n");
1543 return -ENETDOWN;
1546 switch(cmd) {
1547 case SIOCGIWNAME:
1548 DBGPRINT(RT_DEBUG_TRACE, "IOCTL::SIOCGIWNAME\n");
1549 strcpy(wrq->u.name, "RT2500 Wireless"); //Less then 16 bytes.
1550 break;
1551 case SIOCSIWESSID: //Set ESSID
1552 erq = &wrq->u.essid;
1553 memset(&Ssid, 0x00, sizeof(NDIS_802_11_SSID));
1554 if (erq->flags)
1556 if (erq->length > IW_ESSID_MAX_SIZE)
1558 Status = -E2BIG;
1559 break;
1562 Status = copy_from_user(Ssid.Ssid, erq->pointer, (erq->length - 1));
1563 Ssid.SsidLength = erq->length - 1; //minus null character.
1565 else
1566 Ssid.SsidLength = 0; // ANY ssid
1568 pSsid = &Ssid;
1569 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1571 MlmeRestartStateMachine(pAdapter);
1572 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
1575 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1576 // this request, because this request is initiated by NDIS.
1577 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
1579 MlmeEnqueue(&pAdapter->Mlme.Queue,
1580 MLME_CNTL_STATE_MACHINE,
1581 OID_802_11_SSID,
1582 sizeof(NDIS_802_11_SSID),
1583 (VOID *)pSsid
1585 Status = NDIS_STATUS_SUCCESS;
1586 StateMachineTouched = TRUE;
1588 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWESSID[cmd=0x%x] (Len=%d,Ssid=%s)\n", SIOCSIWESSID, pSsid->SsidLength, pSsid->Ssid);
1589 break;
1590 case SIOCGIWESSID: //Get ESSID
1591 erq = &wrq->u.essid;
1593 if(pAdapter->MediaState == NdisMediaStateConnected)
1595 erq->flags=1;
1596 erq->length = pAdapter->PortCfg.SsidLen;
1597 Status = copy_to_user(erq->pointer, pAdapter->PortCfg.Ssid, erq->length);
1599 else
1600 {//the ANY ssid was specified
1601 erq->flags=0;
1602 erq->length=0;
1604 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWESSID (Len=%d, ssid=%lu...)\n", erq->length, (unsigned long)erq->pointer);
1605 break;
1606 case SIOCGIWNWID: // get network id
1607 Status = -EOPNOTSUPP;
1608 break;
1609 case SIOCSIWNWID: // set network id (the cell)
1610 Status = -EOPNOTSUPP;
1611 break;
1612 case SIOCSIWFREQ: // set channel/frequency (Hz)
1613 frq = &wrq->u.freq;
1614 if((frq->e == 0) && (frq->m <= 1000))
1615 chan = frq->m; // Setting by channel number
1616 else
1617 MAP_KHZ_TO_CHANNEL_ID( (frq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
1618 pAdapter->PortCfg.IbssConfig.Channel = chan;
1619 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->PortCfg.IbssConfig.Channel);
1620 break;
1621 case SIOCGIWFREQ: // get channel/frequency (Hz)
1622 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1623 wrq->u.freq.m = pAdapter->PortCfg.Channel;
1624 else
1625 wrq->u.freq.m = pAdapter->PortCfg.IbssConfig.Channel;
1626 wrq->u.freq.e = 0;
1627 wrq->u.freq.i = 0;
1628 break;
1629 case SIOCGIWNICKN: //get node name/nickname
1630 erq = &wrq->u.data;
1631 erq->length = strlen(pAdapter->nickn);
1632 Status = copy_to_user(erq->pointer, pAdapter->nickn, erq->length);
1633 break;
1634 case SIOCSIWNICKN: //set node name/nickname
1635 erq = &wrq->u.data;
1636 if (erq->flags)
1638 if (erq->length <= IW_ESSID_MAX_SIZE)
1639 Status = copy_from_user(pAdapter->nickn, erq->pointer, erq->length);
1640 else
1641 Status = -E2BIG;
1643 break;
1644 case SIOCGIWRATE: //get default bit rate (bps)
1645 wrq->u.bitrate.value = RateIdToMbps[pAdapter->PortCfg.TxRate] * 1000000;
1646 wrq->u.bitrate.disabled = 0;
1647 break;
1648 case SIOCSIWRATE: //set default bit rate (bps)
1649 RTMPSetDesiredRates(pAdapter, wrq->u.bitrate.value);
1650 break;
1651 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
1652 wrq->u.rts.value = (INT) pAdapter->PortCfg.RtsThreshold;
1653 wrq->u.rts.disabled = (wrq->u.rts.value == MAX_RTS_THRESHOLD);
1654 wrq->u.rts.fixed = 1;
1655 break;
1656 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
1657 RtsThresh = wrq->u.rts.value;
1658 if (wrq->u.rts.disabled)
1659 RtsThresh = MAX_RTS_THRESHOLD;
1661 if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
1662 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
1663 else if (RtsThresh == 0)
1664 pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1666 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWRTS (=%d)\n", pAdapter->PortCfg.RtsThreshold);
1667 break;
1668 case SIOCGIWFRAG: //get fragmentation thr (bytes)
1669 wrq->u.frag.value = (INT) pAdapter->PortCfg.FragmentThreshold;
1670 wrq->u.frag.disabled = (wrq->u.frag.value >= MAX_FRAG_THRESHOLD);
1671 wrq->u.frag.fixed = 1;
1672 break;
1673 case SIOCSIWFRAG: //set fragmentation thr (bytes)
1674 FragThresh = wrq->u.frag.value;
1675 if (wrq->u.rts.disabled)
1676 FragThresh = MAX_FRAG_THRESHOLD;
1678 if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
1679 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
1680 else if (FragThresh == 0)
1681 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1683 if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
1684 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
1685 else
1686 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
1688 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWFRAG (=%d)\n", pAdapter->PortCfg.FragmentThreshold);
1689 break;
1690 case SIOCGIWENCODE: //get encoding token & mode
1691 index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
1692 if ((index < 0) || (index >= NR_WEP_KEYS))
1693 index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
1695 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeOpen)
1696 wrq->u.encoding.flags = IW_ENCODE_OPEN;
1697 else if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeShared)
1698 wrq->u.encoding.flags = IW_ENCODE_RESTRICTED;
1700 if (pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
1701 wrq->u.encoding.flags |= IW_ENCODE_DISABLED;
1702 else
1704 if(wrq->u.encoding.pointer)
1706 wrq->u.encoding.length = pAdapter->PortCfg.SharedKey[index].KeyLen;
1707 Status = copy_to_user(wrq->u.encoding.pointer,
1708 pAdapter->PortCfg.SharedKey[index].Key,
1709 pAdapter->PortCfg.SharedKey[index].KeyLen);
1710 wrq->u.encoding.flags |= (index + 1);
1713 break;
1714 case SIOCSIWENCODE: //set encoding token & mode
1715 index = (wrq->u.encoding.flags & IW_ENCODE_INDEX) - 1;
1716 /* take the old default key if index is invalid */
1717 if((index < 0) || (index >= NR_WEP_KEYS))
1718 index = pAdapter->PortCfg.DefaultKeyId; // Default key for tx (shared key)
1720 if(wrq->u.encoding.pointer)
1722 len = wrq->u.encoding.length;
1723 if(len > WEP_LARGE_KEY_LEN)
1724 len = WEP_LARGE_KEY_LEN;
1726 memset(pAdapter->PortCfg.SharedKey[index].Key, 0x00, MAX_LEN_OF_KEY);
1727 Status = copy_from_user(pAdapter->PortCfg.SharedKey[index].Key,
1728 wrq->u.encoding.pointer, len);
1729 pAdapter->PortCfg.SharedKey[index].KeyLen = len <= WEP_SMALL_KEY_LEN ? WEP_SMALL_KEY_LEN : WEP_LARGE_KEY_LEN;
1731 pAdapter->PortCfg.DefaultKeyId = (UCHAR) index;
1732 if (wrq->u.encoding.flags & IW_ENCODE_DISABLED)
1733 pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
1734 else
1735 pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
1737 if (wrq->u.encoding.flags & IW_ENCODE_RESTRICTED)
1738 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
1739 else
1740 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
1742 if(pAdapter->PortCfg.WepStatus == Ndis802_11WEPDisabled)
1743 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
1745 //#ifdef RT2500_DBG
1746 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWENCODE Key[%x] => \n", index);
1747 for (i = 0; i < len; i++)
1749 DBGPRINT(RT_DEBUG_TRACE, "%02x:", pAdapter->PortCfg.SharedKey[index].Key[i]);
1750 if (i%16 == 15)
1751 DBGPRINT(RT_DEBUG_TRACE, "\n");
1753 DBGPRINT(RT_DEBUG_TRACE, "\n");
1754 //#endif
1755 break;
1756 case SIOCGIWAP: //get access point MAC addresses
1757 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1759 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
1760 memcpy(wrq->u.ap_addr.sa_data, &pAdapter->PortCfg.Bssid, ETH_ALEN);
1762 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=%02x:%02x:%02x:%02x:%02x:%02x)\n",
1763 pAdapter->PortCfg.Bssid.Octet[0], pAdapter->PortCfg.Bssid.Octet[1], pAdapter->PortCfg.Bssid.Octet[2],
1764 pAdapter->PortCfg.Bssid.Octet[3], pAdapter->PortCfg.Bssid.Octet[4], pAdapter->PortCfg.Bssid.Octet[5]);
1766 else
1768 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWAP(=EMPTY)\n");
1769 Status = -ENOTCONN;
1771 break;
1772 case SIOCSIWAP: //set access point MAC addresses
1773 memcpy(&Bssid, &wrq->u.ap_addr.sa_data, sizeof(NDIS_802_11_MAC_ADDRESS));
1774 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1776 MlmeRestartStateMachine(pAdapter);
1777 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
1780 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1781 // this request, because this request is initiated by NDIS.
1782 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
1784 MlmeEnqueue(&pAdapter->Mlme.Queue,
1785 MLME_CNTL_STATE_MACHINE,
1786 OID_802_11_BSSID,
1787 sizeof(NDIS_802_11_MAC_ADDRESS),
1788 (VOID *)&Bssid);
1789 Status = NDIS_STATUS_SUCCESS;
1790 StateMachineTouched = TRUE;
1791 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
1792 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]);
1793 break;
1794 case SIOCGIWMODE: //get operation mode
1795 if (ADHOC_ON(pAdapter))
1797 BssType = Ndis802_11IBSS;
1798 wrq->u.mode = IW_MODE_ADHOC;
1800 else if (INFRA_ON(pAdapter))
1802 BssType = Ndis802_11Infrastructure;
1803 wrq->u.mode = IW_MODE_INFRA;
1805 else
1807 BssType = Ndis802_11AutoUnknown;
1808 wrq->u.mode = IW_MODE_AUTO;
1810 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCGIWMODE(=%d)\n", BssType);
1811 break;
1812 case SIOCSIWMODE: //set operation mode
1813 if(wrq->u.mode == IW_MODE_ADHOC)
1815 if (pAdapter->PortCfg.BssType != BSS_INDEP)
1817 // Config has changed
1818 pAdapter->bConfigChanged = TRUE;
1820 pAdapter->PortCfg.BssType = BSS_INDEP;
1821 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (AD-HOC)\n");
1823 else if (wrq->u.mode == IW_MODE_INFRA)
1825 if (pAdapter->PortCfg.BssType != BSS_INFRA)
1827 // Config has changed
1828 pAdapter->bConfigChanged = TRUE;
1830 pAdapter->PortCfg.BssType = BSS_INFRA;
1831 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (INFRA)\n");
1833 else
1835 Status = -EINVAL;
1836 DBGPRINT(RT_DEBUG_TRACE, "ioctl::SIOCSIWMODE (unknown)\n");
1838 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1839 pAdapter->PortCfg.WpaState = SS_NOTUSE;
1840 break;
1841 case SIOCGIWSENS: //get sensitivity (dBm)
1842 case SIOCSIWSENS: //set sensitivity (dBm)
1843 case SIOCGIWPOWER: //get Power Management settings
1844 case SIOCSIWPOWER: //set Power Management settings
1845 case SIOCGIWTXPOW: //get transmit power (dBm)
1846 case SIOCSIWTXPOW: //set transmit power (dBm)
1847 Status = -EOPNOTSUPP;
1848 break;
1849 case RT_PRIV_IOCTL:
1850 subcmd = wrq->u.data.flags;
1851 if( subcmd & OID_GET_SET_TOGGLE)
1852 Status = RTMPSetInformation(pAdapter, rq, subcmd);
1853 else
1854 Status = RTMPQueryInformation(pAdapter, rq, subcmd);
1855 break;
1856 case SIOCGIWPRIV:
1857 if (wrq->u.data.pointer) {
1858 if (
1859 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1860 access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab))
1861 #else
1862 verify_area(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab))
1863 #endif
1865 break;
1867 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
1868 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
1869 Status = -EFAULT;
1871 break;
1872 case RTPRIV_IOCTL_SET:
1874 char *this_char;
1875 char *value;
1877 if (
1878 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1879 access_ok(VERIFY_WRITE, wrq->u.data.pointer, wrq->u.data.length)
1880 #else
1881 verify_area(VERIFY_WRITE, wrq->u.data.pointer, wrq->u.data.length)
1882 #endif
1884 break;
1886 while ((this_char = strsep((char**)&wrq->u.data.pointer, ",")) != NULL)
1888 if (!*this_char)
1889 continue;
1891 if ((value = rtstrchr(this_char, '=')) != NULL)
1892 *value++ = 0;
1894 if (!value || !*value)
1895 continue;
1897 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1899 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1901 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1902 { //FALSE:Set private failed then return Invalid argument
1903 Status = -EINVAL;
1905 break; //Exit for loop.
1909 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1910 { //Not found argument
1911 Status = -EINVAL;
1912 DBGPRINT(RT_DEBUG_TRACE, "ioctl::(iwpriv) Not Support Set Command [%s=%s]\n", this_char, value);
1913 break;
1917 break;
1919 case RTPRIV_IOCTL_BBP:
1920 RTMPIoctlBBP(pAdapter, wrq);
1921 break;
1923 case RTPRIV_IOCTL_MAC:
1924 RTMPIoctlMAC(pAdapter, wrq);
1925 break;
1927 #ifdef RALINK_ATE
1928 case RTPRIV_IOCTL_E2P:
1929 RTMPIoctlE2PROM(pAdapter, wrq);
1930 break;
1931 #endif
1932 default:
1933 DBGPRINT(RT_DEBUG_TRACE, "IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd);
1934 Status = -EOPNOTSUPP;
1935 break;
1938 if(StateMachineTouched) // Upper layer sent a MLME-related operations
1939 MlmeHandler(pAdapter);
1941 return Status;
1945 UCHAR BCAST[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1947 ========================================================================
1949 Routine Description:
1950 Add WPA key process
1952 Arguments:
1953 pAdapter Pointer to our adapter
1954 pBuf Pointer to the where the key stored
1956 Return Value:
1957 NDIS_SUCCESS Add key successfully
1959 Note:
1961 ========================================================================
1963 NDIS_STATUS RTMPWPAAddKeyProc(
1964 IN PRTMP_ADAPTER pAdapter,
1965 IN PVOID pBuf)
1967 PNDIS_802_11_KEY pKey;
1968 ULONG KeyIdx;
1969 NDIS_STATUS Status;
1970 PUCHAR pTxMic, pRxMic;
1971 BOOLEAN bTxKey; // Set the key as transmit key
1972 BOOLEAN bPairwise; // Indicate the key is pairwise key
1973 BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
1974 // Otherwise, it will set by the NIC.
1975 BOOLEAN bAuthenticator; // indicate key is set by authenticator.
1976 INT i, PairwiseIdx;
1978 pKey = (PNDIS_802_11_KEY) pBuf;
1979 KeyIdx = pKey->KeyIndex & 0xff;
1980 // Bit 31 of Add-key, Tx Key
1981 bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
1982 // Bit 30 of Add-key PairwiseKey
1983 bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
1984 // Bit 29 of Add-key KeyRSC
1985 bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
1986 // Bit 28 of Add-key Authenticator
1987 bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
1989 // 1. Check Group / Pairwise Key
1990 if (bPairwise) // Pairwise Key
1992 // 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
1993 if (KeyIdx != 0)
1994 return(NDIS_STATUS_FAILURE);
1996 // 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
1997 if (bTxKey == FALSE)
1998 return(NDIS_STATUS_FAILURE);
2000 // 3. If BSSID is not all 0xff, return NDIS_STATUS_INVALID_DATA
2001 if (NdisEqualMemory(pKey->BSSID, BCAST, 6))
2002 return(NDIS_STATUS_FAILURE);
2004 // 4. Selct RxMic / TxMic based on Supp / Authenticator
2005 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2007 // for WPA-None Tx, Rx MIC is the same
2008 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2009 pRxMic = pTxMic;
2011 else if (bAuthenticator == TRUE)
2013 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2014 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2016 else
2018 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2019 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2022 // 5. Find the old entry to overwrite or find an empty entry.
2023 PairwiseIdx = 0;
2024 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2026 if (pAdapter->PortCfg.PairwiseKey[i].KeyLen == 0)
2028 PairwiseIdx = i;
2029 break;
2031 else if (RTMPEqualMemory(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6))
2033 // Found the old entry
2034 PairwiseIdx = i;
2035 break;
2038 // If there is no match and no empty pairwise key, we have to replace an old one
2039 // which will be index 0 in our case.
2041 // 6. Check RxTsc
2042 if (bKeyRSC == TRUE)
2044 NdisMoveMemory(&pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, &pKey->KeyRSC, 6);
2046 else
2048 NdisZeroMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc, 6);
2051 // 7. Copy information into Pairwise Key structure.
2052 // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
2053 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].KeyLen = 16;
2054 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key, &pKey->KeyMaterial, 16);
2055 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic, pRxMic, 8);
2056 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic, pTxMic, 8);
2057 NdisMoveMemory(pAdapter->PortCfg.PairwiseKey[PairwiseIdx].BssId, pKey->BSSID, 6);
2058 // Init TxTsc to one based on WiFi WPA specs
2059 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[0] = 1;
2060 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[1] = 0;
2061 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[2] = 0;
2062 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[3] = 0;
2063 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[4] = 0;
2064 pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxTsc[5] = 0;
2065 Status = NDIS_STATUS_SUCCESS;
2067 #ifdef RT2500_DBG
2068 printk("PairwiseKey Key (Index-%d) = ", PairwiseIdx);
2069 for (i = 0; i < 16; i++)
2071 printk("%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].Key[i]);
2073 printk("\n");
2074 printk("PairwiseKey Rx MIC Key = ");
2075 for (i = 0; i < 8; i++)
2077 printk("%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxMic[i]);
2079 printk("\n");
2080 printk("PairwiseKey Tx MIC Key = ");
2081 for (i = 0; i < 8; i++)
2083 printk("%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].TxMic[i]);
2085 printk("\n");
2086 printk("RxTSC = ");
2087 for (i = 0; i < 6; i++)
2089 printk("%02x:", pAdapter->PortCfg.PairwiseKey[PairwiseIdx].RxTsc[i]);
2091 printk("\n");
2092 printk("BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2093 pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2094 #endif
2096 else // Group Key
2098 DBGPRINT(RT_DEBUG_TRACE, "Ready to set Group key\n");
2099 // 1. Check BSSID, if not current BSSID or Bcast, return NDIS_STATUS_INVALID_DATA
2100 if ((!NdisEqualMemory(&pKey->BSSID, &BCAST, 6)) &&
2101 (!NdisEqualMemory(&pKey->BSSID, &pAdapter->PortCfg.Bssid, 6)))
2102 return(NDIS_STATUS_FAILURE);
2105 // 2. Check Key index for supported Group Key
2106 if (KeyIdx >= GROUP_KEY_NO)
2107 return(NDIS_STATUS_FAILURE);
2109 // 3. Set as default Tx Key if bTxKey is TRUE
2110 if (bTxKey == TRUE)
2111 pAdapter->PortCfg.DefaultKeyId = (UCHAR) KeyIdx;
2113 // 4. Selct RxMic / TxMic based on Supp / Authenticator
2114 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2116 // for WPA-None Tx, Rx MIC is the same
2117 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2118 pRxMic = pTxMic;
2120 else if (bAuthenticator == TRUE)
2122 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2123 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2125 else
2127 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
2128 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
2131 // 5. Check RxTsc
2132 if (bKeyRSC == TRUE)
2134 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, &pKey->KeyRSC, 6);
2136 else
2138 NdisZeroMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc, 6);
2141 // 6. Copy information into Group Key structure.
2142 // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
2143 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 16;
2144 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].Key, &pKey->KeyMaterial, 16);
2145 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].RxMic, pRxMic, 8);
2146 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].TxMic, pTxMic, 8);
2147 NdisMoveMemory(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6);
2148 // Init TxTsc to one based on WiFi WPA specs
2149 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[0] = 1;
2150 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[1] = 0;
2151 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[2] = 0;
2152 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[3] = 0;
2153 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[4] = 0;
2154 pAdapter->PortCfg.GroupKey[KeyIdx].TxTsc[5] = 0;
2155 // 802.1x port control
2156 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2157 Status = NDIS_STATUS_SUCCESS;
2159 // For WEP compatibility, in case it use OID_ADD_KEY, not OID_ADD_WEP
2160 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2162 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
2163 NdisMoveMemory(pAdapter->PortCfg.SharedKey[KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
2166 #ifdef RT2500_DBG
2167 printk("GroupKey Key (Index-%d) = ",KeyIdx);
2168 for (i = 0; i < 16; i++)
2170 printk("%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].Key[i]);
2172 printk("\n");
2173 printk("GroupKey Rx MIC Key = ");
2174 for (i = 0; i < 8; i++)
2176 printk("%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxMic[i]);
2178 printk("\n");
2179 printk("GroupKey Tx MIC Key = ");
2180 for (i = 0; i < 8; i++)
2182 printk("%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].TxMic[i]);
2184 printk("\n");
2186 printk("RxTSC = ");
2187 for (i = 0; i < 6; i++)
2189 printk("%02x:", pAdapter->PortCfg.GroupKey[KeyIdx].RxTsc[i]);
2191 printk("\n");
2192 printk("BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
2193 pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]);
2194 #endif
2196 return (Status);
2200 ========================================================================
2202 Routine Description:
2203 Remove WPA Key process
2205 Arguments:
2206 pAdapter Pointer to our adapter
2207 pBuf Pointer to the where the key stored
2209 Return Value:
2210 NDIS_SUCCESS Add key successfully
2212 Note:
2214 ========================================================================
2216 NDIS_STATUS RTMPWPARemoveKeyProc(
2217 IN PRTMP_ADAPTER pAdapter,
2218 IN PVOID pBuf)
2220 PNDIS_802_11_REMOVE_KEY pKey;
2221 ULONG KeyIdx;
2222 NDIS_STATUS Status = NDIS_STATUS_FAILURE;
2223 BOOLEAN bTxKey; // Set the key as transmit key
2224 BOOLEAN bPairwise; // Indicate the key is pairwise key
2225 BOOLEAN bKeyRSC; // indicate the receive SC set by KeyRSC value.
2226 // Otherwise, it will set by the NIC.
2227 BOOLEAN bAuthenticator; // indicate key is set by authenticator.
2228 INT i;
2230 pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
2231 KeyIdx = pKey->KeyIndex & 0xff;
2232 // Bit 31 of Add-key, Tx Key
2233 bTxKey = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
2234 // Bit 30 of Add-key PairwiseKey
2235 bPairwise = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
2236 // Bit 29 of Add-key KeyRSC
2237 bKeyRSC = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
2238 // Bit 28 of Add-key Authenticator
2239 bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
2241 // 1. If bTx is TRUE, return failure information
2242 if (bTxKey == TRUE)
2243 return(NDIS_STATUS_FAILURE);
2245 // 2. Check Pairwise Key
2246 if (bPairwise)
2248 // a. If BSSID is broadcast, remove all pairwise keys.
2249 if (NdisEqualMemory(&pKey->BSSID, &BCAST, 6))
2251 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2253 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2255 Status = NDIS_STATUS_SUCCESS;
2258 // b. If not broadcast, remove the pairwise specified by BSSID
2259 else
2261 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2263 if (NdisEqualMemory(pAdapter->PortCfg.PairwiseKey[i].BssId, pKey->BSSID, 6))
2265 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2266 Status = NDIS_STATUS_SUCCESS;
2267 break;
2272 // c. If no pairwise supported, delete Group Key 0.
2273 // The will be false since we do support pairwise keys.
2275 // 3. Group Key
2276 else
2278 // a. If BSSID is broadcast, remove all group keys indexed
2279 if (NdisEqualMemory(&pKey->BSSID, &BCAST, 6))
2281 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2282 Status = NDIS_STATUS_SUCCESS;
2285 // b. If BSSID matched, delte the group key indexed.
2286 else if (NdisEqualMemory(pAdapter->PortCfg.GroupKey[KeyIdx].BssId, pKey->BSSID, 6))
2288 pAdapter->PortCfg.GroupKey[KeyIdx].KeyLen = 0;
2289 Status = NDIS_STATUS_SUCCESS;
2292 // c. For WEP compatibility
2293 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2295 pAdapter->PortCfg.SharedKey[KeyIdx].KeyLen = 0;
2299 return (Status);
2304 ========================================================================
2306 Routine Description:
2307 Remove All WPA Keys
2309 Arguments:
2310 pAdapter Pointer to our adapter
2312 Return Value:
2313 None
2315 Note:
2317 ========================================================================
2319 VOID RTMPWPARemoveAllKeys(
2320 IN PRTMP_ADAPTER pAdapter)
2322 INT i;
2324 // For WPA-None, there is no need to remove it, since WinXP won't set it again after
2325 // Link up. And it will be replaced if user changed it.
2326 if (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
2327 return;
2329 for (i = 0; i < PAIRWISE_KEY_NO; i++)
2331 pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
2334 for (i = 0; i < GROUP_KEY_NO; i++)
2336 pAdapter->PortCfg.GroupKey[i].KeyLen = 0;
2341 ========================================================================
2343 Routine Description:
2344 Change NIC PHY mode. Re-association may be necessary.
2346 Arguments:
2347 pAdapter Pointer to our adapter
2348 phmode
2350 ========================================================================
2352 VOID RTMPSetPhyMode(
2353 IN PRTMP_ADAPTER pAdapter,
2354 IN ULONG phymode)
2356 INT i;
2358 DBGPRINT(RT_DEBUG_TRACE,"RTMPSetPhyMode(=%d)\n", phymode);
2360 // the selected phymode must be supported by the RF IC encoded in E2PROM
2361 if (pAdapter->PortCfg.RfType < RFIC_5222)
2363 if (phymode == PHY_11A)
2364 phymode = PHY_11BG_MIXED;
2367 // if no change, do nothing
2368 if (pAdapter->PortCfg.PhyMode == phymode)
2369 return;
2371 pAdapter->PortCfg.PhyMode = (UCHAR)phymode;
2372 BuildChannelList(pAdapter);
2374 for (i = 0; i < pAdapter->PortCfg.ChannelListNum; i++)
2376 if (pAdapter->PortCfg.IbssConfig.Channel == pAdapter->PortCfg.ChannelList[i])
2377 break;
2379 if (i == pAdapter->PortCfg.ChannelListNum)
2380 pAdapter->PortCfg.IbssConfig.Channel = FirstChannel(pAdapter);
2381 pAdapter->PortCfg.Channel = pAdapter->PortCfg.IbssConfig.Channel;
2383 AsicSwitchChannel(pAdapter, pAdapter->PortCfg.Channel);
2384 AsicLockChannel(pAdapter, pAdapter->PortCfg.Channel);
2386 switch (phymode) {
2387 case PHY_11B:
2388 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2389 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2390 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2391 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2392 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 4;
2393 pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2394 pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2395 pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps
2396 pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2397 pAdapter->PortCfg.SupportedRatesLen = 4;
2398 pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2399 pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2400 pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2401 pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2402 pAdapter->PortCfg.DesiredRates[4] = 0;
2403 pAdapter->PortCfg.DesiredRates[5] = 0;
2404 pAdapter->PortCfg.DesiredRates[6] = 0;
2405 pAdapter->PortCfg.DesiredRates[7] = 0;
2406 pAdapter->PortCfg.DesiredRates[8] = 0;
2407 pAdapter->PortCfg.DesiredRates[9] = 0;
2408 pAdapter->PortCfg.DesiredRates[10] = 0;
2409 pAdapter->PortCfg.DesiredRates[11] = 0;
2410 break;
2412 case PHY_11BG_MIXED:
2413 case PHY_11ABG_MIXED:
2414 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2415 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2416 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2417 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2418 pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0x12; // 9 mbps, in units of 0.5 Mbps
2419 pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x24; // 18 mbps, in units of 0.5 Mbps
2420 pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x48; // 36 mbps, in units of 0.5 Mbps
2421 pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2422 pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2423 pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2424 pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2425 pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0x60; // 48 mbps, in units of 0.5 Mbps
2426 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 12;
2427 pAdapter->PortCfg.SupportedRates[0] = 0x82; // 1 mbps, in units of 0.5 Mbps, basic rate
2428 pAdapter->PortCfg.SupportedRates[1] = 0x84; // 2 mbps, in units of 0.5 Mbps, basic rate
2429 pAdapter->PortCfg.SupportedRates[2] = 0x8B; // 5.5 mbps, in units of 0.5 Mbps, basic rate
2430 pAdapter->PortCfg.SupportedRates[3] = 0x96; // 11 mbps, in units of 0.5 Mbps, basic rate
2431 pAdapter->PortCfg.SupportedRates[4] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2432 pAdapter->PortCfg.SupportedRates[5] = 0x12; // 9 mbps, in units of 0.5 Mbps
2433 pAdapter->PortCfg.SupportedRates[6] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2434 pAdapter->PortCfg.SupportedRates[7] = 0x24; // 18 mbps, in units of 0.5 Mbps
2435 pAdapter->PortCfg.SupportedRates[8] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2436 pAdapter->PortCfg.SupportedRates[9] = 0x48; // 36 mbps, in units of 0.5 Mbps
2437 pAdapter->PortCfg.SupportedRates[10] = 0x60; // 48 mbps, in units of 0.5 Mbps
2438 pAdapter->PortCfg.SupportedRates[11] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2439 pAdapter->PortCfg.SupportedRatesLen = 12;
2440 pAdapter->PortCfg.DesiredRates[0] = 2; // 1 mbps, in units of 0.5 Mbps
2441 pAdapter->PortCfg.DesiredRates[1] = 4; // 2 mbps, in units of 0.5 Mbps
2442 pAdapter->PortCfg.DesiredRates[2] = 11; // 5.5 mbps, in units of 0.5 Mbps
2443 pAdapter->PortCfg.DesiredRates[3] = 22; // 11 mbps, in units of 0.5 Mbps
2444 pAdapter->PortCfg.DesiredRates[4] = 12; // 6 mbps, in units of 0.5 Mbps
2445 pAdapter->PortCfg.DesiredRates[5] = 18; // 9 mbps, in units of 0.5 Mbps
2446 pAdapter->PortCfg.DesiredRates[6] = 24; // 12 mbps, in units of 0.5 Mbps
2447 pAdapter->PortCfg.DesiredRates[7] = 36; // 18 mbps, in units of 0.5 Mbps
2448 pAdapter->PortCfg.DesiredRates[8] = 48; // 24 mbps, in units of 0.5 Mbps
2449 pAdapter->PortCfg.DesiredRates[9] = 72; // 36 mbps, in units of 0.5 Mbps
2450 pAdapter->PortCfg.DesiredRates[10] = 96; // 48 mbps, in units of 0.5 Mbps
2451 pAdapter->PortCfg.DesiredRates[11] = 108; // 54 mbps, in units of 0.5 Mbps
2452 break;
2454 case PHY_11A:
2455 pAdapter->PortCfg.IbssConfig.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2456 pAdapter->PortCfg.IbssConfig.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2457 pAdapter->PortCfg.IbssConfig.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2458 pAdapter->PortCfg.IbssConfig.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2459 pAdapter->PortCfg.IbssConfig.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2460 pAdapter->PortCfg.IbssConfig.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2461 pAdapter->PortCfg.IbssConfig.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2462 pAdapter->PortCfg.IbssConfig.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2463 pAdapter->PortCfg.IbssConfig.SupportedRates[8] = 0;
2464 pAdapter->PortCfg.IbssConfig.SupportedRates[9] = 0;
2465 pAdapter->PortCfg.IbssConfig.SupportedRates[10] = 0;
2466 pAdapter->PortCfg.IbssConfig.SupportedRates[11] = 0;
2467 pAdapter->PortCfg.IbssConfig.SupportedRatesLen = 8;
2468 pAdapter->PortCfg.SupportedRates[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2469 pAdapter->PortCfg.SupportedRates[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2470 pAdapter->PortCfg.SupportedRates[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2471 pAdapter->PortCfg.SupportedRates[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2472 pAdapter->PortCfg.SupportedRates[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2473 pAdapter->PortCfg.SupportedRates[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2474 pAdapter->PortCfg.SupportedRates[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2475 pAdapter->PortCfg.SupportedRates[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2476 pAdapter->PortCfg.SupportedRates[8] = 0;
2477 pAdapter->PortCfg.SupportedRates[9] = 0;
2478 pAdapter->PortCfg.SupportedRates[10] = 0;
2479 pAdapter->PortCfg.SupportedRates[11] = 0;
2480 pAdapter->PortCfg.SupportedRatesLen = 8;
2481 pAdapter->PortCfg.DesiredRates[0] = 12; // 6 mbps, in units of 0.5 Mbps
2482 pAdapter->PortCfg.DesiredRates[1] = 18; // 9 mbps, in units of 0.5 Mbps
2483 pAdapter->PortCfg.DesiredRates[2] = 24; // 12 mbps, in units of 0.5 Mbps
2484 pAdapter->PortCfg.DesiredRates[3] = 36; // 18 mbps, in units of 0.5 Mbps
2485 pAdapter->PortCfg.DesiredRates[4] = 48; // 24 mbps, in units of 0.5 Mbps
2486 pAdapter->PortCfg.DesiredRates[5] = 72; // 36 mbps, in units of 0.5 Mbps
2487 pAdapter->PortCfg.DesiredRates[6] = 96; // 48 mbps, in units of 0.5 Mbps
2488 pAdapter->PortCfg.DesiredRates[7] = 108; // 54 mbps, in units of 0.5 Mbps
2489 pAdapter->PortCfg.DesiredRates[8] = 0;
2490 pAdapter->PortCfg.DesiredRates[9] = 0;
2491 pAdapter->PortCfg.DesiredRates[10] = 0;
2492 pAdapter->PortCfg.DesiredRates[11] = 0;
2493 break;
2495 default:
2496 break;
2499 MlmeUpdateTxRates(pAdapter, FALSE);
2500 AsicSetSlotTime(pAdapter, FALSE);
2501 MakeIbssBeacon(pAdapter); // supported rates may change
2504 VOID RTMPSetDesiredRates(
2505 IN PRTMP_ADAPTER pAdapter,
2506 IN LONG Rates)
2508 NDIS_802_11_RATES aryRates;
2510 memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
2511 switch (pAdapter->PortCfg.PhyMode)
2513 case PHY_11A: // A only
2514 switch (Rates)
2516 case 6000000: //6M
2517 aryRates[0] = 0x0c; // 6M
2518 break;
2519 case 9000000: //9M
2520 aryRates[0] = 0x12; // 9M
2521 break;
2522 case 12000000: //12M
2523 aryRates[0] = 0x18; // 12M
2524 break;
2525 case 18000000: //18M
2526 aryRates[0] = 0x24; // 18M
2527 break;
2528 case 24000000: //24M
2529 aryRates[0] = 0x30; // 24M
2530 break;
2531 case 36000000: //36M
2532 aryRates[0] = 0x48; // 36M
2533 break;
2534 case 48000000: //48M
2535 aryRates[0] = 0x60; // 48M
2536 break;
2537 case 54000000: //54M
2538 aryRates[0] = 0x6c; // 54M
2539 break;
2540 case -1: //Auto
2541 default:
2542 aryRates[0] = 0x6c; // 54Mbps
2543 aryRates[1] = 0x60; // 48Mbps
2544 aryRates[2] = 0x48; // 36Mbps
2545 aryRates[3] = 0x30; // 24Mbps
2546 aryRates[4] = 0x24; // 18M
2547 aryRates[5] = 0x18; // 12M
2548 aryRates[6] = 0x12; // 9M
2549 aryRates[7] = 0x0c; // 6M
2550 break;
2552 break;
2553 case PHY_11BG_MIXED: // B/G Mixed
2554 case PHY_11B: // B only
2555 case PHY_11ABG_MIXED: // A/B/G Mixed
2556 default:
2557 switch (Rates)
2559 case 1000000: //1M
2560 aryRates[0] = 0x02;
2561 break;
2562 case 2000000: //2M
2563 aryRates[0] = 0x04;
2564 break;
2565 case 5000000: //5.5M
2566 aryRates[0] = 0x0b; // 5.5M
2567 break;
2568 case 11000000: //11M
2569 aryRates[0] = 0x16; // 11M
2570 break;
2571 case 6000000: //6M
2572 aryRates[0] = 0x0c; // 6M
2573 break;
2574 case 9000000: //9M
2575 aryRates[0] = 0x12; // 9M
2576 break;
2577 case 12000000: //12M
2578 aryRates[0] = 0x18; // 12M
2579 break;
2580 case 18000000: //18M
2581 aryRates[0] = 0x24; // 18M
2582 break;
2583 case 24000000: //24M
2584 aryRates[0] = 0x30; // 24M
2585 break;
2586 case 36000000: //36M
2587 aryRates[0] = 0x48; // 36M
2588 break;
2589 case 48000000: //48M
2590 aryRates[0] = 0x60; // 48M
2591 break;
2592 case 54000000: //54M
2593 aryRates[0] = 0x6c; // 54M
2594 break;
2595 case -1: //Auto
2596 default:
2597 if (pAdapter->PortCfg.PhyMode == PHY_11B)
2598 { //B Only
2599 aryRates[0] = 0x16; // 11Mbps
2600 aryRates[1] = 0x0b; // 5.5Mbps
2601 aryRates[2] = 0x04; // 2Mbps
2602 aryRates[3] = 0x02; // 1Mbps
2604 else
2605 { //(B/G) Mixed or (A/B/G) Mixed
2606 aryRates[0] = 0x6c; // 54Mbps
2607 aryRates[1] = 0x60; // 48Mbps
2608 aryRates[2] = 0x48; // 36Mbps
2609 aryRates[3] = 0x30; // 24Mbps
2610 aryRates[4] = 0x16; // 11Mbps
2611 aryRates[5] = 0x0b; // 5.5Mbps
2612 aryRates[6] = 0x04; // 2Mbps
2613 aryRates[7] = 0x02; // 1Mbps
2615 break;
2617 break;
2620 NdisZeroMemory(pAdapter->PortCfg.DesiredRates, MAX_LEN_OF_SUPPORTED_RATES);
2621 NdisMoveMemory(pAdapter->PortCfg.DesiredRates, &aryRates, sizeof(NDIS_802_11_RATES));
2622 DBGPRINT(RT_DEBUG_TRACE, " RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
2623 pAdapter->PortCfg.DesiredRates[0],pAdapter->PortCfg.DesiredRates[1],
2624 pAdapter->PortCfg.DesiredRates[2],pAdapter->PortCfg.DesiredRates[3],
2625 pAdapter->PortCfg.DesiredRates[4],pAdapter->PortCfg.DesiredRates[5],
2626 pAdapter->PortCfg.DesiredRates[6],pAdapter->PortCfg.DesiredRates[7] );
2627 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
2628 MlmeUpdateTxRates(pAdapter, FALSE);
2631 ==========================================================================
2632 Description:
2633 Set Country Region
2634 Return:
2635 TRUE if all parameters are OK, FALSE otherwise
2636 ==========================================================================
2638 INT Set_CountryRegion_Proc(
2639 IN PRTMP_ADAPTER pAdapter,
2640 IN PUCHAR arg)
2642 ULONG region;
2643 int success = TRUE;
2645 region = simple_strtol(arg, 0, 10);
2646 if( (region >= REGION_MIN) && (region <= REGION_MAX) )
2648 pAdapter->PortCfg.CountryRegion = (UCHAR) region;
2649 DBGPRINT(RT_DEBUG_TRACE, "Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
2650 DBGPRINT(RT_DEBUG_TRACE, "Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAdapter->PortCfg.CountryRegion);
2652 else
2653 success = FALSE;
2655 return success;
2658 ==========================================================================
2659 Description:
2660 Set SSID
2661 Return:
2662 TRUE if all parameters are OK, FALSE otherwise
2663 ==========================================================================
2665 INT Set_SSID_Proc(
2666 IN PRTMP_ADAPTER pAdapter,
2667 IN PUCHAR arg)
2669 NDIS_802_11_SSID Ssid, *pSsid=NULL;
2670 BOOLEAN StateMachineTouched = FALSE;
2671 int success = TRUE;
2673 if( strlen(arg) <= MAX_LEN_OF_SSID)
2675 NdisZeroMemory(&Ssid, MAX_LEN_OF_SSID);
2676 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
2677 Ssid.SsidLength = strlen(arg);
2678 pSsid = &Ssid;
2680 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
2682 MlmeRestartStateMachine(pAdapter);
2683 DBGPRINT(RT_DEBUG_TRACE, "!!! MLME busy, reset MLME state machine !!!\n");
2685 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
2686 // this request, because this request is initiated by NDIS.
2687 pAdapter->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
2689 MlmeEnqueue(&pAdapter->Mlme.Queue,
2690 MLME_CNTL_STATE_MACHINE,
2691 OID_802_11_SSID,
2692 sizeof(NDIS_802_11_SSID),
2693 (VOID *)pSsid);
2695 StateMachineTouched = TRUE;
2696 DBGPRINT(RT_DEBUG_TRACE, "Set_SSID_Proc::(Len=%d,Ssid=%s)\n", pAdapter->PortCfg.SsidLen, pAdapter->PortCfg.Ssid);
2698 else
2699 success = FALSE;
2701 if (StateMachineTouched) // Upper layer sent a MLME-related operations
2702 MlmeHandler(pAdapter);
2704 return success;
2707 ==========================================================================
2708 Description:
2709 Set Wireless Mode
2710 Return:
2711 TRUE if all parameters are OK, FALSE otherwise
2712 ==========================================================================
2714 INT Set_WirelessMode_Proc(
2715 IN PRTMP_ADAPTER pAdapter,
2716 IN PUCHAR arg)
2718 ULONG WirelessMode;
2719 int success = TRUE;
2721 WirelessMode = simple_strtol(arg, 0, 10);
2723 if ((WirelessMode == PHY_11BG_MIXED) || (WirelessMode == PHY_11B) ||
2724 (WirelessMode == PHY_11A) || (WirelessMode == PHY_11ABG_MIXED))
2726 RTMPSetPhyMode(pAdapter, WirelessMode);
2727 DBGPRINT(RT_DEBUG_TRACE, "Set_WirelessMode_Proc::(=%d)\n", WirelessMode);
2729 else
2730 success = FALSE;
2732 return success;
2735 ==========================================================================
2736 Description:
2737 Set TxRate
2738 Return:
2739 TRUE if all parameters are OK, FALSE otherwise
2740 ==========================================================================
2742 INT Set_TxRate_Proc(
2743 IN PRTMP_ADAPTER pAdapter,
2744 IN PUCHAR arg)
2746 ULONG TxRate;
2747 int success = TRUE;
2748 ULONG rate_mapping[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
2750 TxRate = simple_strtol(arg, 0, 10);
2752 if (TxRate == 0)
2753 RTMPSetDesiredRates(pAdapter, -1);
2754 else
2755 RTMPSetDesiredRates(pAdapter, (LONG) (rate_mapping[TxRate-1] * 1000000));
2756 return success;
2759 ==========================================================================
2760 Description:
2761 Set AdhocMode support Rate can or can not exceed 11Mbps against WiFi spec.
2762 Return:
2763 TRUE if all parameters are OK, FALSE otherwise
2764 ==========================================================================
2766 INT Set_AdhocModeRate_Proc(
2767 IN PRTMP_ADAPTER pAdapter,
2768 IN PUCHAR arg)
2770 ULONG AdhocMode;
2772 AdhocMode = simple_strtol(arg, 0, 10);
2774 if (AdhocMode == 1)
2775 pAdapter->PortCfg.AdhocMode = 1;
2776 else if (AdhocMode == 0)
2777 pAdapter->PortCfg.AdhocMode = 0;
2778 else
2779 return FALSE; //Invalid argument
2781 DBGPRINT(RT_DEBUG_TRACE, "Set_AdhocModeRate_Proc::(AdhocMode=%d)\n", pAdapter->PortCfg.AdhocMode);
2783 return TRUE;
2786 ==========================================================================
2787 Description:
2788 Set Channel
2789 Return:
2790 TRUE if all parameters are OK, FALSE otherwise
2791 ==========================================================================
2793 INT Set_Channel_Proc(
2794 IN PRTMP_ADAPTER pAdapter,
2795 IN PUCHAR arg)
2797 int success = TRUE;
2798 UCHAR Channel;
2800 Channel = (UCHAR) simple_strtol(arg, 0, 10);
2802 if (ChannelSanity(pAdapter, Channel) == TRUE)
2804 pAdapter->PortCfg.Channel = Channel;
2805 pAdapter->PortCfg.IbssConfig.Channel = Channel;
2806 DBGPRINT(RT_DEBUG_TRACE, "Set_Channel_Proc::(Channel=%d)\n", Channel);
2808 else
2809 success = FALSE;
2811 return success;
2814 ==========================================================================
2815 Description:
2816 For Debug information
2817 Return:
2818 TRUE if all parameters are OK, FALSE otherwise
2819 ==========================================================================
2821 #ifdef RT2500_DBG
2822 INT Set_Debug_Proc(
2823 IN PRTMP_ADAPTER pAdapter,
2824 IN PUCHAR arg)
2827 DBGPRINT(RT_DEBUG_TRACE, "**************************************************************\n");
2828 DBGPRINT(RT_DEBUG_TRACE, "==> Set_Debug_Proc\n");
2829 //To do here.
2831 if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
2832 RTDebugLevel = simple_strtol(arg, 0, 10);
2834 DBGPRINT(RT_DEBUG_TRACE, "<== Set_Debug_Proc\n");
2835 DBGPRINT(RT_DEBUG_TRACE, "**************************************************************\n");
2836 return TRUE;
2838 #endif
2840 ==========================================================================
2841 Description:
2842 Set 11B/11G Protection
2843 Return:
2844 TRUE if all parameters are OK, FALSE otherwise
2845 ==========================================================================
2847 INT Set_BGProtection_Proc(
2848 IN PRTMP_ADAPTER pAdapter,
2849 IN PUCHAR arg)
2852 switch (simple_strtol(arg, 0, 10))
2854 case 0: //AUTO
2855 pAdapter->PortCfg.UseBGProtection = 0;
2856 break;
2857 case 1: //Always On
2858 pAdapter->PortCfg.UseBGProtection = 1;
2859 break;
2860 case 2: //Always OFF
2861 pAdapter->PortCfg.UseBGProtection = 2;
2862 break;
2863 default: //Invalid argument
2864 return FALSE;
2866 DBGPRINT(RT_DEBUG_TRACE, "Set_BGProtection_Proc::(BGProtection=%d)\n", pAdapter->PortCfg.UseBGProtection);
2868 return TRUE;
2871 ==========================================================================
2872 Description:
2873 Set StaWithEtherBridge function on/off
2874 Return:
2875 TRUE if all parameters are OK, FALSE otherwise
2876 ==========================================================================
2878 INT Set_StaWithEtherBridge_Proc(
2879 IN PRTMP_ADAPTER pAdapter,
2880 IN PUCHAR arg)
2883 switch (simple_strtol(arg, 0, 10))
2885 case 0: //Off
2886 pAdapter->PortCfg.StaWithEtherBridge.Enable = FALSE;
2887 break;
2888 case 1: //On
2889 pAdapter->PortCfg.StaWithEtherBridge.Enable = TRUE;
2890 break;
2891 default: //Invalid argument
2892 return FALSE;
2894 DBGPRINT(RT_DEBUG_TRACE, "Set_StaWithEtherBridge_Proc::(StaWithEtherBridge=%d)\n", pAdapter->PortCfg.StaWithEtherBridge.Enable);
2896 return TRUE;
2899 ==========================================================================
2900 Description:
2901 Set TxPreamble
2902 Return:
2903 TRUE if all parameters are OK, FALSE otherwise
2904 ==========================================================================
2906 INT Set_TxPreamble_Proc(
2907 IN PRTMP_ADAPTER pAdapter,
2908 IN PUCHAR arg)
2910 RT_802_11_PREAMBLE Preamble;
2912 Preamble = simple_strtol(arg, 0, 10);
2913 switch (Preamble)
2915 case Rt802_11PreambleShort:
2916 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
2917 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
2918 break;
2919 case Rt802_11PreambleLong:
2920 case Rt802_11PreambleAuto:
2921 // if user wants AUTO, initialize to LONG here, then change according to AP's
2922 // capability upon association.
2923 pAdapter->PortCfg.WindowsTxPreamble = Preamble;
2924 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
2925 break;
2926 default: //Invalid argument
2927 return FALSE;
2930 DBGPRINT(RT_DEBUG_TRACE, "Set_TxPreamble_Proc::(TxPreamble=%d)\n", Preamble);
2932 return TRUE;
2935 ==========================================================================
2936 Description:
2937 Set RTS Threshold
2938 Return:
2939 TRUE if all parameters are OK, FALSE otherwise
2940 ==========================================================================
2942 INT Set_RTSThreshold_Proc(
2943 IN PRTMP_ADAPTER pAdapter,
2944 IN PUCHAR arg)
2946 NDIS_802_11_RTS_THRESHOLD RtsThresh;
2948 RtsThresh = simple_strtol(arg, 0, 10);
2950 if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
2951 pAdapter->PortCfg.RtsThreshold = (USHORT)RtsThresh;
2952 else if (RtsThresh == 0)
2953 pAdapter->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;
2954 else
2955 return FALSE;
2957 DBGPRINT(RT_DEBUG_TRACE, "Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAdapter->PortCfg.RtsThreshold);
2958 return TRUE;
2961 ==========================================================================
2962 Description:
2963 Set Fragment Threshold
2964 Return:
2965 TRUE if all parameters are OK, FALSE otherwise
2966 ==========================================================================
2968 INT Set_FragThreshold_Proc(
2969 IN PRTMP_ADAPTER pAdapter,
2970 IN PUCHAR arg)
2972 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
2974 FragThresh = simple_strtol(arg, 0, 10);
2976 if ( (FragThresh >= MIN_FRAG_THRESHOLD) && (FragThresh <= MAX_FRAG_THRESHOLD))
2977 pAdapter->PortCfg.FragmentThreshold = (USHORT)FragThresh;
2978 else if (FragThresh == 0)
2979 pAdapter->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
2980 else
2981 return FALSE; //Invalid argument
2983 if (pAdapter->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
2984 pAdapter->PortCfg.bFragmentZeroDisable = TRUE;
2985 else
2986 pAdapter->PortCfg.bFragmentZeroDisable = FALSE;
2988 DBGPRINT(RT_DEBUG_TRACE, "Set_FragThreshold_Proc::(FragThreshold=%d)\n", FragThresh);
2990 return TRUE;
2993 ==========================================================================
2994 Description:
2995 Set TxBurst
2996 Return:
2997 TRUE if all parameters are OK, FALSE otherwise
2998 ==========================================================================
3000 INT Set_TxBurst_Proc(
3001 IN PRTMP_ADAPTER pAdapter,
3002 IN PUCHAR arg)
3004 ULONG TxBurst;
3006 TxBurst = simple_strtol(arg, 0, 10);
3008 if (TxBurst == 1)
3009 pAdapter->PortCfg.EnableTxBurst = TRUE;
3010 else if (TxBurst == 0)
3011 pAdapter->PortCfg.EnableTxBurst = FALSE;
3012 else
3013 return FALSE; //Invalid argument
3015 DBGPRINT(RT_DEBUG_TRACE, "Set_TxBurst_Proc::(TxBurst=%d)\n", pAdapter->PortCfg.EnableTxBurst);
3017 return TRUE;
3020 ==========================================================================
3021 Description:
3022 Set TurboRate Enable or Disable
3023 Return:
3024 TRUE if all parameters are OK, FALSE otherwise
3025 ==========================================================================
3027 INT Set_TurboRate_Proc(
3028 IN PRTMP_ADAPTER pAdapter,
3029 IN PUCHAR arg)
3031 ULONG TurboRate;
3033 TurboRate = simple_strtol(arg, 0, 10);
3035 if (TurboRate == 1)
3036 pAdapter->PortCfg.EnableTurboRate = TRUE;
3037 else if (TurboRate == 0)
3038 pAdapter->PortCfg.EnableTurboRate = FALSE;
3039 else
3040 return FALSE; //Invalid argument
3042 DBGPRINT(RT_DEBUG_TRACE, "Set_TurboRate_Proc::(TurboRate=%d)\n", pAdapter->PortCfg.EnableTurboRate);
3044 return TRUE;
3047 ==========================================================================
3048 Description:
3049 Set Short Slot Time Enable or Disable
3050 Return:
3051 TRUE if all parameters are OK, FALSE otherwise
3052 ==========================================================================
3054 INT Set_ShortSlot_Proc(
3055 IN PRTMP_ADAPTER pAdapter,
3056 IN PUCHAR arg)
3058 ULONG ShortSlot;
3060 ShortSlot = simple_strtol(arg, 0, 10);
3062 if (ShortSlot == 1)
3063 pAdapter->PortCfg.UseShortSlotTime = TRUE;
3064 else if (ShortSlot == 0)
3065 pAdapter->PortCfg.UseShortSlotTime = FALSE;
3066 else
3067 return FALSE; //Invalid argument
3069 DBGPRINT(RT_DEBUG_TRACE, "Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAdapter->PortCfg.UseShortSlotTime);
3071 return TRUE;
3075 ==========================================================================
3076 Description:
3077 Set Network Type(Infrastructure/Adhoc mode)
3078 Return:
3079 TRUE if all parameters are OK, FALSE otherwise
3080 ==========================================================================
3082 INT Set_NetworkType_Proc(
3083 IN PRTMP_ADAPTER pAdapter,
3084 IN PUCHAR arg)
3086 if (strcmp(arg, "Adhoc") == 0)
3087 pAdapter->PortCfg.BssType = BSS_INDEP;
3088 else //Default Infrastructure mode
3089 pAdapter->PortCfg.BssType = BSS_INFRA;
3091 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
3092 pAdapter->PortCfg.WpaState = SS_NOTUSE;
3094 DBGPRINT(RT_DEBUG_TRACE, "Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->PortCfg.BssType);
3096 return TRUE;
3100 ==========================================================================
3101 Description:
3102 Set Authentication mode
3103 Return:
3104 TRUE if all parameters are OK, FALSE otherwise
3105 ==========================================================================
3107 INT Set_AuthMode_Proc(
3108 IN PRTMP_ADAPTER pAdapter,
3109 IN PUCHAR arg)
3111 if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
3112 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
3113 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
3114 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeShared;
3115 else if ((strcmp(arg, "AUTO") == 0) || (strcmp(arg, "auto") == 0))
3116 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
3117 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
3118 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
3119 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
3120 pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
3121 else
3122 return FALSE;
3124 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3126 DBGPRINT(RT_DEBUG_TRACE, "Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->PortCfg.AuthMode);
3128 return TRUE;
3132 ==========================================================================
3133 Description:
3134 Set Encryption Type
3135 Return:
3136 TRUE if all parameters are OK, FALSE otherwise
3137 ==========================================================================
3139 INT Set_EncrypType_Proc(
3140 IN PRTMP_ADAPTER pAdapter,
3141 IN PUCHAR arg)
3143 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
3144 pAdapter->PortCfg.WepStatus = Ndis802_11WEPDisabled;
3145 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
3146 pAdapter->PortCfg.WepStatus = Ndis802_11WEPEnabled;
3147 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
3148 pAdapter->PortCfg.WepStatus = Ndis802_11Encryption2Enabled;
3149 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
3150 pAdapter->PortCfg.WepStatus = Ndis802_11Encryption3Enabled;
3151 else
3152 return FALSE;
3154 DBGPRINT(RT_DEBUG_TRACE, "Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->PortCfg.WepStatus);
3156 return TRUE;
3159 ==========================================================================
3160 Description:
3161 Set Default Key ID
3162 Return:
3163 TRUE if all parameters are OK, FALSE otherwise
3164 ==========================================================================
3166 INT Set_DefaultKeyID_Proc(
3167 IN PRTMP_ADAPTER pAdapter,
3168 IN PUCHAR arg)
3170 ULONG KeyIdx;
3172 KeyIdx = simple_strtol(arg, 0, 10);
3173 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
3174 pAdapter->PortCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
3175 else
3176 return FALSE; //Invalid argument
3178 DBGPRINT(RT_DEBUG_TRACE, "Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->PortCfg.DefaultKeyId);
3180 return TRUE;
3183 ==========================================================================
3184 Description:
3185 Set WEP KEY1
3186 Return:
3187 TRUE if all parameters are OK, FALSE otherwise
3188 ==========================================================================
3190 INT Set_Key1_Proc(
3191 IN PRTMP_ADAPTER pAdapter,
3192 IN PUCHAR arg)
3194 int KeyLen;
3195 int i;
3197 KeyLen = strlen(arg);
3199 switch (KeyLen)
3201 case 5: //wep 40 Ascii type
3202 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3203 memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3204 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3205 break;
3206 case 10: //wep 40 Hex type
3207 for(i=0; i < KeyLen; i++)
3209 if( !isxdigit(*(arg+i)) )
3210 return FALSE; //Not Hex value;
3212 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3213 AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3214 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3215 break;
3216 case 13: //wep 104 Ascii type
3217 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen;
3218 memcpy(pAdapter->PortCfg.SharedKey[0].Key, arg, KeyLen);
3219 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii");
3220 break;
3221 case 26: //wep 104 Hex type
3222 for(i=0; i < KeyLen; i++)
3224 if( !isxdigit(*(arg+i)) )
3225 return FALSE; //Not Hex value;
3227 pAdapter->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
3228 AtoH(arg, pAdapter->PortCfg.SharedKey[0].Key, KeyLen / 2);
3229 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex");
3230 break;
3231 default: //Invalid argument
3232 DBGPRINT(RT_DEBUG_TRACE, "Set_Key1_Proc::Invalid argument (=%s)\n", arg);
3233 return FALSE;
3236 return TRUE;
3239 ==========================================================================
3240 Description:
3241 Set WEP KEY2
3242 Return:
3243 TRUE if all parameters are OK, FALSE otherwise
3244 ==========================================================================
3246 INT Set_Key2_Proc(
3247 IN PRTMP_ADAPTER pAdapter,
3248 IN PUCHAR arg)
3250 int KeyLen;
3251 int i;
3253 KeyLen = strlen(arg);
3255 switch (KeyLen)
3257 case 5: //wep 40 Ascii type
3258 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3259 memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3260 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3261 break;
3262 case 10: //wep 40 Hex type
3263 for(i=0; i < KeyLen; i++)
3265 if( !isxdigit(*(arg+i)) )
3266 return FALSE; //Not Hex value;
3268 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3269 AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3270 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3271 break;
3272 case 13: //wep 104 Ascii type
3273 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen;
3274 memcpy(pAdapter->PortCfg.SharedKey[1].Key, arg, KeyLen);
3275 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii");
3276 break;
3277 case 26: //wep 104 Hex type
3278 for(i=0; i < KeyLen; i++)
3280 if( !isxdigit(*(arg+i)) )
3281 return FALSE; //Not Hex value;
3283 pAdapter->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
3284 AtoH(arg, pAdapter->PortCfg.SharedKey[1].Key, KeyLen / 2);
3285 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex");
3286 break;
3287 default: //Invalid argument
3288 DBGPRINT(RT_DEBUG_TRACE, "Set_Key2_Proc::Invalid argument (=%s)\n", arg);
3289 return FALSE;
3292 return TRUE;
3295 ==========================================================================
3296 Description:
3297 Set WEP KEY3
3298 Return:
3299 TRUE if all parameters are OK, FALSE otherwise
3300 ==========================================================================
3302 INT Set_Key3_Proc(
3303 IN PRTMP_ADAPTER pAdapter,
3304 IN PUCHAR arg)
3306 int KeyLen;
3307 int i;
3309 KeyLen = strlen(arg);
3311 switch (KeyLen)
3313 case 5: //wep 40 Ascii type
3314 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3315 memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3316 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3317 break;
3318 case 10: //wep 40 Hex type
3319 for(i=0; i < KeyLen; i++)
3321 if( !isxdigit(*(arg+i)) )
3322 return FALSE; //Not Hex value;
3324 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3325 AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3326 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3327 break;
3328 case 13: //wep 104 Ascii type
3329 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen;
3330 memcpy(pAdapter->PortCfg.SharedKey[2].Key, arg, KeyLen);
3331 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Ascii");
3332 break;
3333 case 26: //wep 104 Hex type
3334 for(i=0; i < KeyLen; i++)
3336 if( !isxdigit(*(arg+i)) )
3337 return FALSE; //Not Hex value;
3339 pAdapter->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
3340 AtoH(arg, pAdapter->PortCfg.SharedKey[2].Key, KeyLen / 2);
3341 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::(Key3=%s and type=%s)\n", arg, "Hex");
3342 break;
3343 default: //Invalid argument
3344 DBGPRINT(RT_DEBUG_TRACE, "Set_Key3_Proc::Invalid argument (=%s)\n", arg);
3345 return FALSE;
3348 return TRUE;
3351 ==========================================================================
3352 Description:
3353 Set WEP KEY4
3354 Return:
3355 TRUE if all parameters are OK, FALSE otherwise
3356 ==========================================================================
3358 INT Set_Key4_Proc(
3359 IN PRTMP_ADAPTER pAdapter,
3360 IN PUCHAR arg)
3362 int KeyLen;
3363 int i;
3365 KeyLen = strlen(arg);
3367 switch (KeyLen)
3369 case 5: //wep 40 Ascii type
3370 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3371 memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3372 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3373 break;
3374 case 10: //wep 40 Hex type
3375 for(i=0; i < KeyLen; i++)
3377 if( !isxdigit(*(arg+i)) )
3378 return FALSE; //Not Hex value;
3380 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3381 AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3382 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3383 break;
3384 case 13: //wep 104 Ascii type
3385 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen;
3386 memcpy(pAdapter->PortCfg.SharedKey[3].Key, arg, KeyLen);
3387 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii");
3388 break;
3389 case 26: //wep 104 Hex type
3390 for(i=0; i < KeyLen; i++)
3392 if( !isxdigit(*(arg+i)) )
3393 return FALSE; //Not Hex value;
3395 pAdapter->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
3396 AtoH(arg, pAdapter->PortCfg.SharedKey[3].Key, KeyLen / 2);
3397 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex");
3398 break;
3399 default: //Invalid argument
3400 DBGPRINT(RT_DEBUG_TRACE, "Set_Key4_Proc::Invalid argument (=%s)\n", arg);
3401 return FALSE;
3404 return TRUE;
3407 ==========================================================================
3408 Description:
3409 Set WPA PSK key
3410 Return:
3411 TRUE if all parameters are OK, FALSE otherwise
3412 ==========================================================================
3414 INT Set_WPAPSK_Proc(
3415 IN PRTMP_ADAPTER pAdapter,
3416 IN PUCHAR arg)
3418 UCHAR keyMaterial[40];
3420 DBGPRINT(RT_DEBUG_TRACE, "Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg);
3421 if ((strlen(arg) < 8) || (strlen(arg) > 64))
3423 DBGPRINT(RT_DEBUG_TRACE, "Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg);
3424 return FALSE;
3427 if (strlen(arg) == 64)
3429 AtoH(arg, pAdapter->PortCfg.PskKey.Key, 32);
3431 else
3433 PasswordHash((char *)arg, pAdapter->Mlme.CntlAux.Ssid, pAdapter->Mlme.CntlAux.SsidLen, keyMaterial);
3435 NdisMoveMemory(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
3438 // Use RaConfig as PSK agent.
3439 // Start STA supplicant state machine
3440 pAdapter->PortCfg.WpaState = SS_START;
3442 return TRUE;
3447 ==========================================================================
3448 Description:
3449 Set WPA NONE key
3450 Return:
3451 TRUE if all parameters are OK, FALSE otherwise
3452 ==========================================================================
3455 INT Set_WPANONE_Proc(
3456 IN PRTMP_ADAPTER pAdapter,
3457 IN PUCHAR arg)
3459 UCHAR keyMaterial[40];
3461 DBGPRINT(RT_DEBUG_TRACE, "Set_WPANONE_Proc::(WPANONE=%s)\n", arg);
3462 if ((strlen(arg) < 8) || (strlen(arg) > 64))
3464 DBGPRINT(RT_DEBUG_TRACE, "Set failed!!(WPANONE=%s), WPANONE key-string required 8 ~ 64 characters \n", arg);
3465 return FALSE;
3468 if (strlen(arg) == 64)
3470 AtoH(arg, pAdapter->PortCfg.PskKey.Key, 32);
3472 else
3474 PasswordHash((char *)arg, pAdapter->Mlme.CntlAux.Ssid, pAdapter->Mlme.CntlAux.SsidLen, keyMaterial);
3476 NdisMoveMemory(pAdapter->PortCfg.PskKey.Key, keyMaterial, 32);
3479 // Use RaConfig as PSK agent.
3480 // Start STA supplicant state machine
3481 pAdapter->PortCfg.WpaState = SS_START;
3483 //-----------------------------------------------------------------------------
3484 // pasted from "RTMPWPAAddKeyProc(...)"
3485 // major on Group Key only.
3487 // Group Key
3489 // 3. Set as default Tx Key if bTxKey is TRUE
3490 pAdapter->PortCfg.DefaultKeyId = 0;
3492 // 4. Selct RxMic / TxMic based on Supp / Authenticator
3493 // for WPA-None Tx, Rx MIC is the same
3494 //pTxMic = (PUCHAR) (keyMaterial) + 16;
3495 //pRxMic = pTxMic;
3497 NdisZeroMemory(pAdapter->PortCfg.GroupKey[0].RxTsc, 6);
3499 // 6. Copy information into Group Key structure.
3500 // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
3501 pAdapter->PortCfg.GroupKey[0].KeyLen = 16;
3502 NdisMoveMemory(pAdapter->PortCfg.GroupKey[0].Key, (PUCHAR)(keyMaterial) + 0,16);
3503 NdisMoveMemory(pAdapter->PortCfg.GroupKey[0].RxMic, (PUCHAR)(keyMaterial) + 16, 8);
3504 NdisMoveMemory(pAdapter->PortCfg.GroupKey[0].TxMic, (PUCHAR)(keyMaterial) + 16, 8);
3505 NdisMoveMemory(pAdapter->PortCfg.GroupKey[0].BssId, &pAdapter->PortCfg.Bssid, 6);
3507 // Init TxTsc to one based on WiFi WPA specs
3508 pAdapter->PortCfg.GroupKey[0].TxTsc[0] = 1;
3509 pAdapter->PortCfg.GroupKey[0].TxTsc[1] = 0;
3510 pAdapter->PortCfg.GroupKey[0].TxTsc[2] = 0;
3511 pAdapter->PortCfg.GroupKey[0].TxTsc[3] = 0;
3512 pAdapter->PortCfg.GroupKey[0].TxTsc[4] = 0;
3513 pAdapter->PortCfg.GroupKey[0].TxTsc[5] = 0;
3515 // 802.1x port control
3516 pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_SECURED;
3518 return TRUE;
3522 ==========================================================================
3523 Description:
3524 Read / Write BBP
3525 Arguments:
3526 pAdapter Pointer to our adapter
3527 wrq Pointer to the ioctl argument
3529 Return Value:
3530 None
3532 Note:
3533 Usage:
3534 1.) iwpriv ra0 bbp ==> read all BBP
3535 2.) iwpriv ra0 bbp 1,2,10,32 ==> raed BBP where ID=1,2,10,32
3536 3.) iwpriv ra0 bbp 1=10,17=3E ==> write BBP R1=0x10, R17=0x3E
3537 ==========================================================================
3539 VOID RTMPIoctlBBP(
3540 IN PRTMP_ADAPTER pAdapter,
3541 IN struct iwreq *wrq)
3543 char *this_char;
3544 char *value;
3545 int i=0;
3546 int count = 0;
3547 UCHAR regBBP;
3548 char msg[1024];
3549 char arg[255];
3550 char *ptr;
3551 ULONG bbpId;
3552 ULONG bbpValue;
3553 BOOLEAN bIsPrintAllBBP = FALSE;
3554 INT Status = 0;
3556 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlBBP\n");
3557 memset(msg, 0x00, 1024);
3558 if (wrq->u.data.length > 1) //No parameters.
3560 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3561 ptr = arg;
3562 sprintf(msg, "\n");
3563 //Parsing Read or Write
3564 while ((this_char = strsep(&ptr, ",")) != NULL)
3566 i++;
3567 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3568 if (!*this_char)
3569 continue;
3571 if ((value = rtstrchr(this_char, '=')) != NULL)
3572 *value++ = 0;
3574 if (!value || !*value)
3575 { //Read
3576 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s, value=%s\n", this_char, value);
3577 bbpId = simple_strtol(this_char, 0, 10);
3578 if ((bbpId >=0) && (bbpId <= 63))
3580 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, bbpId, &regBBP);
3581 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3582 count++;
3583 if (count%5 == 4)
3584 sprintf(msg+strlen(msg), "\n");
3585 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3587 else
3588 {//Invalid parametes, so default print all bbp
3589 bIsPrintAllBBP = TRUE;
3590 break;
3593 else
3594 { //Write
3595 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s, value=%s\n", this_char, value);
3596 bbpId = simple_strtol(this_char, 0, 10);
3597 bbpValue = simple_strtol(value, 0, 10);
3598 DBGPRINT(RT_DEBUG_TRACE, "bbpID=%02d, value=0x%x\n", bbpId, bbpValue);
3599 if ((bbpId >=0) && (bbpId <= 63))
3601 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, (UCHAR) bbpId, (UCHAR) bbpValue);
3602 //Read it back for showing
3603 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, bbpId, &regBBP);
3604 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3605 count++;
3606 if (count%5 == 4)
3607 sprintf(msg+strlen(msg), "\n");
3608 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3610 else
3611 {//Invalid parametes, so default print all bbp
3612 bIsPrintAllBBP = TRUE;
3613 break;
3618 else
3619 bIsPrintAllBBP = TRUE;
3621 if (bIsPrintAllBBP)
3623 memset(msg, 0x00, 1024);
3624 sprintf(msg, "\n");
3625 for (i = 0; i <= 63; i++)
3627 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, i, &regBBP);
3628 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X ", i, i*2, regBBP);
3629 if (i%5 == 4)
3630 sprintf(msg+strlen(msg), "\n");
3632 // Copy the information into the user buffer
3633 wrq->u.data.length = strlen(msg);
3634 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3636 else
3638 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3639 // Copy the information into the user buffer
3640 wrq->u.data.length = strlen(msg);
3641 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3643 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlBBP\n");
3647 ==========================================================================
3648 Description:
3649 Read / Write MAC
3650 Arguments:
3651 pAdapter Pointer to our adapter
3652 wrq Pointer to the ioctl argument
3654 Return Value:
3655 None
3657 Note:
3658 Usage:
3659 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
3660 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
3661 ==========================================================================
3663 VOID RTMPIoctlMAC(
3664 IN PRTMP_ADAPTER pAdapter,
3665 IN struct iwreq *wrq)
3667 char *this_char;
3668 char *value;
3669 int j=0, k=0;
3670 int count = 0;
3671 char msg[1024];
3672 char arg[255];
3673 char *ptr;
3674 ULONG macAddr = 0;
3675 UCHAR temp[16], temp2[16];
3676 ULONG macValue;
3677 INT Status = 0;
3679 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlMAC\n");
3680 memset(msg, 0x00, 1024);
3681 if (wrq->u.data.length > 1) //No parameters.
3683 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3684 ptr = arg;
3685 sprintf(msg, "\n");
3686 //Parsing Read or Write
3687 while ((this_char = strsep(&ptr, ",")) != NULL)
3689 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3690 if (!*this_char)
3691 continue;
3693 if ((value = rtstrchr(this_char, '=')) != NULL)
3694 *value++ = 0;
3696 if (!value || !*value)
3697 { //Read
3698 // Sanity check
3699 if(strlen(this_char) > 4)
3700 break;
3702 j = strlen(this_char);
3703 while(j-- > 0)
3705 if(this_char[j] > 'f' || this_char[j] < '0')
3706 return;
3709 // Mac Addr
3710 k = j = strlen(this_char);
3711 while(j-- > 0)
3713 this_char[4-k+j] = this_char[j];
3716 while(k < 4)
3717 this_char[3-k++]='0';
3718 this_char[4]='\0';
3720 if(strlen(this_char) == 4)
3722 AtoH(this_char, temp, 4);
3723 macAddr = *temp*256 + temp[1];
3724 if (macAddr < 0xFFFF)
3726 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
3727 DBGPRINT(RT_DEBUG_TRACE, "macAddr=%x, regMAC=%x\n", macAddr, macValue);
3728 sprintf(msg+strlen(msg), "[0x%08X]:%08X ", macAddr , macValue);
3729 count++;
3730 if (count%5 == 4)
3731 sprintf(msg+strlen(msg), "\n");
3732 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3734 else
3735 {//Invalid parametes, so default print all bbp
3736 break;
3740 else
3741 { //Write
3742 memcpy(&temp2, value, strlen(value));
3743 temp2[strlen(value)] = '\0';
3745 // Sanity check
3746 if((strlen(this_char) > 4) || strlen(temp2) > 8)
3747 break;
3749 j = strlen(this_char);
3750 while(j-- > 0)
3752 if(this_char[j] > 'f' || this_char[j] < '0')
3753 return;
3756 j = strlen(temp2);
3757 while(j-- > 0)
3759 if(temp2[j] > 'f' || temp2[j] < '0')
3760 return;
3763 //MAC Addr
3764 k = j = strlen(this_char);
3765 while(j-- > 0)
3767 this_char[4-k+j] = this_char[j];
3770 while(k < 4)
3771 this_char[3-k++]='0';
3772 this_char[4]='\0';
3774 //MAC value
3775 k = j = strlen(temp2);
3776 while(j-- > 0)
3778 temp2[8-k+j] = temp2[j];
3781 while(k < 8)
3782 temp2[7-k++]='0';
3783 temp2[8]='\0';
3786 AtoH(this_char, temp, 4);
3787 macAddr = *temp*256 + temp[1];
3789 AtoH(temp2, temp, 8);
3790 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
3792 DBGPRINT(RT_DEBUG_TRACE, "macAddr=%02x, macValue=0x%x\n", macAddr, macValue);
3794 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
3795 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", macAddr, macValue);
3796 count++;
3797 if (count%5 == 4)
3798 sprintf(msg+strlen(msg), "\n");
3799 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3805 if(strlen(msg) == 1)
3806 sprintf(msg+strlen(msg), "===>Error command format!");
3807 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3808 // Copy the information into the user buffer
3809 wrq->u.data.length = strlen(msg);
3810 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3812 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlMAC\n");
3815 #ifdef RALINK_ATE
3817 ==========================================================================
3818 Description:
3819 Read / Write E2PROM
3820 Arguments:
3821 pAdapter Pointer to our adapter
3822 wrq Pointer to the ioctl argument
3824 Return Value:
3825 None
3827 Note:
3828 Usage:
3829 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
3830 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
3831 ==========================================================================
3833 VOID RTMPIoctlE2PROM(
3834 IN PRTMP_ADAPTER pAdapter,
3835 IN struct iwreq *wrq)
3837 char *this_char;
3838 char *value;
3839 int j=0, k=0;
3840 int count = 0;
3841 char msg[1024];
3842 char arg[255];
3843 char *ptr;
3844 USHORT eepAddr = 0;
3845 UCHAR temp[16], temp2[16];
3846 USHORT eepValue;
3847 INT Status = 0;
3849 DBGPRINT(RT_DEBUG_TRACE, "==>RTMPIoctlE2PROM\n");
3850 memset(msg, 0x00, 1024);
3851 if (wrq->u.data.length > 1) //No parameters.
3853 memcpy(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
3854 ptr = arg;
3855 sprintf(msg, "\n");
3856 //Parsing Read or Write
3857 while ((this_char = strsep(&ptr, ",")) != NULL)
3859 DBGPRINT(RT_DEBUG_TRACE, "this_char=%s\n", this_char);
3860 if (!*this_char)
3861 continue;
3863 if ((value = strchr(this_char, '=')) != NULL)
3864 *value++ = 0;
3866 if (!value || !*value)
3867 { //Read
3868 DBGPRINT(RT_DEBUG_TRACE, "Read: this_char=%s, strlen=%d\n", this_char, strlen(this_char));
3870 // Sanity check
3871 if(strlen(this_char) > 4)
3872 break;
3874 j = strlen(this_char);
3875 while(j-- > 0)
3877 if(this_char[j] > 'f' || this_char[j] < '0')
3878 return;
3881 // E2PROM addr
3882 k = j = strlen(this_char);
3883 while(j-- > 0)
3885 this_char[4-k+j] = this_char[j];
3888 while(k < 4)
3889 this_char[3-k++]='0';
3890 this_char[4]='\0';
3892 if(strlen(this_char) == 4)
3894 AtoH(this_char, temp, 4);
3895 eepAddr = *temp*256 + temp[1];
3896 if (eepAddr < 0xFFFF)
3898 eepValue = RTMP_EEPROM_READ16(pAdapter, eepAddr);
3899 DBGPRINT(RT_DEBUG_TRACE, "eepAddr=%x, eepValue=%x\n", eepAddr, eepValue);
3900 sprintf(msg+strlen(msg), "[0x%04X]:%04X ", eepAddr , eepValue);
3901 count++;
3902 if (count%5 == 4)
3903 sprintf(msg+strlen(msg), "\n");
3904 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3906 else
3907 {//Invalid parametes, so default printk all bbp
3908 break;
3912 else
3913 { //Write
3914 DBGPRINT(RT_DEBUG_TRACE, "Write: this_char=%s, strlen(value)=%d, value=%s\n", this_char, strlen(value), value);
3915 memcpy(&temp2, value, strlen(value));
3916 temp2[strlen(value)] = '\0';
3918 // Sanity check
3919 if((strlen(this_char) > 4) || strlen(temp2) > 8)
3920 break;
3922 j = strlen(this_char);
3923 while(j-- > 0)
3925 if(this_char[j] > 'f' || this_char[j] < '0')
3926 return;
3928 j = strlen(temp2);
3929 while(j-- > 0)
3931 if(temp2[j] > 'f' || temp2[j] < '0')
3932 return;
3935 //MAC Addr
3936 k = j = strlen(this_char);
3937 while(j-- > 0)
3939 this_char[4-k+j] = this_char[j];
3942 while(k < 4)
3943 this_char[3-k++]='0';
3944 this_char[4]='\0';
3946 //MAC value
3947 k = j = strlen(temp2);
3948 while(j-- > 0)
3950 temp2[4-k+j] = temp2[j];
3953 while(k < 4)
3954 temp2[3-k++]='0';
3955 temp2[4]='\0';
3957 AtoH(this_char, temp, 4);
3958 eepAddr = *temp*256 + temp[1];
3960 AtoH(temp2, temp, 4);
3961 eepValue = *temp*256 + temp[1];
3963 DBGPRINT(RT_DEBUG_TRACE, "eepAddr=%02x, eepValue=0x%x\n", eepAddr, eepValue);
3965 RTMP_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
3966 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
3967 count++;
3968 if (count%5 == 4)
3969 sprintf(msg+strlen(msg), "\n");
3970 DBGPRINT(RT_DEBUG_TRACE, "msg=%s\n", msg);
3975 if(strlen(msg) == 1)
3976 sprintf(msg+strlen(msg), "===>Error command format!");
3978 // Copy the information into the user buffer
3979 DBGPRINT(RT_DEBUG_TRACE, "copy to user [msg=%s]\n", msg);
3980 wrq->u.data.length = strlen(msg);
3981 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
3983 DBGPRINT(RT_DEBUG_TRACE, "<==RTMPIoctlE2PROM\n");
3986 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
3989 ==========================================================================
3990 Description:
3991 Set ATE operation mode to
3992 0. STASTOP = Stop STA Mode
3993 1. STASTART = Start STA Mode
3994 2. TXCONT = Continuous Transmit
3995 3. TXCARR = Transmit Carrier
3996 4. TXFRAME = Transmit Frames
3997 5. RXFRAME = Receive Frames
3998 Return:
3999 TRUE if all parameters are OK, FALSE otherwise
4000 ==========================================================================
4002 INT Set_ATE_Proc(
4003 IN PRTMP_ADAPTER pAdapter,
4004 IN PUCHAR arg)
4006 USHORT BbpData;
4007 ULONG MacData;
4008 PTXD_STRUC pTxD;
4009 PUCHAR pDest;
4010 UINT i, j;
4012 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_Proc (arg = %s)\n", arg);
4014 mdelay(5);
4016 AsicSwitchChannel(pAdapter, pAdapter->ate.Channel);
4017 AsicLockChannel(pAdapter, pAdapter->ate.Channel);
4019 mdelay(5);
4021 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter, 63, &BbpData);
4022 RTMP_IO_READ32(pAdapter, MACCSR1, &MacData);
4024 BbpData = 0;
4025 MacData &= 0xFBFFFFFF;
4027 if (!strcmp(arg, "STASTOP"))
4029 DBGPRINT(RT_DEBUG_TRACE, "ATE: STASTOP\n");
4031 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4032 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4034 pAdapter->ate.Mode = ATE_STASTOP;
4036 LinkDown(pAdapter);
4037 AsicEnableBssSync(pAdapter);
4038 netif_stop_queue(pAdapter->net_dev);
4039 RTMPStationStop(pAdapter);
4040 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff); // Stop Rx
4042 else if (!strcmp(arg, "STASTART"))
4044 DBGPRINT(RT_DEBUG_TRACE, "ATE: STASTART\n");
4046 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4047 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4049 pAdapter->ate.Mode = ATE_STASTART;
4051 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0x56); // Start Rx
4052 netif_start_queue(pAdapter->net_dev);
4053 RTMPStationStart(pAdapter);
4055 else if (!strcmp(arg, "TXCONT")) // Continuous Tx
4057 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXCONT\n");
4059 pAdapter->ate.Mode = ATE_TXCONT;
4061 BbpData |= 0x80;
4062 MacData |= 0x04000000;
4064 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4065 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4067 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
4069 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
4070 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
4072 // Prepare frame payload
4073 memcpy(pDest, &TempletFrame, LENGTH_802_11);
4074 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
4075 pDest[j] = 0xAA;
4076 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
4077 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
4078 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
4080 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
4081 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
4082 pAdapter->ate.TxLength, pAdapter->PortCfg.TxPreambleInUsed, 0);
4084 pAdapter->CurEncryptIndex++;
4085 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
4087 pAdapter->CurEncryptIndex = 0;
4091 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
4092 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
4094 else if (!strcmp(arg, "TXCARR")) // Tx Carrier -------------------------------------
4096 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXCARR\n");
4097 pAdapter->ate.Mode = ATE_TXCARR;
4099 BbpData |= 0x40;
4100 MacData |= 0x04000000;
4102 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4103 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4105 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
4107 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
4108 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
4110 // Prepare frame payload
4111 memcpy(pDest, &TempletFrame, LENGTH_802_11);
4112 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
4113 pDest[j] = 0xAA;
4114 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
4115 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
4116 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
4118 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
4119 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
4120 pAdapter->ate.TxLength, pAdapter->PortCfg.TxPreambleInUsed, 0);
4122 pAdapter->CurEncryptIndex++;
4123 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
4125 pAdapter->CurEncryptIndex = 0;
4129 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
4130 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
4132 else if (!strcmp(arg, "TXFRAME")) // Tx Frames --------------------------------------
4134 DBGPRINT(RT_DEBUG_TRACE, "ATE: TXFRAME(Count=%d)\n", pAdapter->ate.TxCount);
4135 pAdapter->ate.Mode = ATE_TXFRAME;
4137 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4138 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4140 pAdapter->ate.TxDoneCount = 0;
4142 for (i = 0; (i < TX_RING_SIZE) && (i < pAdapter->ate.TxCount); i++)
4144 pTxD = (PTXD_STRUC)pAdapter->TxRing[pAdapter->CurEncryptIndex].va_addr;
4145 pDest = (PUCHAR) pAdapter->TxRing[pAdapter->CurEncryptIndex].va_data_addr;
4147 // Prepare frame payload
4148 memcpy(pDest, &TempletFrame, LENGTH_802_11);
4149 for(j = LENGTH_802_11; j < pAdapter->ate.TxLength; j++)
4150 pDest[j] = 0xAA;
4151 memcpy(&pDest[4], &pAdapter->ate.Addr1, ETH_LENGTH_OF_ADDRESS);
4152 memcpy(&pDest[10], &pAdapter->ate.Addr2, ETH_LENGTH_OF_ADDRESS);
4153 memcpy(&pDest[16], &pAdapter->ate.Addr3, ETH_LENGTH_OF_ADDRESS);
4155 RTMPWriteTxDescriptor(pTxD, TRUE, CIPHER_NONE, FALSE, FALSE, FALSE,
4156 SHORT_RETRY, IFS_BACKOFF, pAdapter->ate.TxRate, 4,
4157 pAdapter->ate.TxLength, Rt802_11PreambleLong, 0);
4159 pAdapter->CurEncryptIndex++;
4160 if (pAdapter->CurEncryptIndex >= TX_RING_SIZE)
4162 pAdapter->CurEncryptIndex = 0;
4165 pAdapter->ate.TxDoneCount += i;
4166 DBGPRINT(RT_DEBUG_TRACE, "TXFRAME txcount=%d\n", pAdapter->ate.TxCount);
4167 DBGPRINT(RT_DEBUG_TRACE, "pAdapter->ate.TxDoneCount = %d\n", pAdapter->ate.TxDoneCount);
4169 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0xffffffff);
4170 RTMP_IO_WRITE32(pAdapter, SECCSR1, 0x1);
4172 else if (!strcmp(arg, "RXFRAME")) // Rx Frames --------------------------------------
4174 DBGPRINT(RT_DEBUG_TRACE, "ATE: RXFRAME\n");
4176 RTMP_IO_WRITE32(pAdapter, MACCSR1, MacData);
4177 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter, 63, BbpData);
4179 pAdapter->ate.Mode = ATE_RXFRAME;
4180 pAdapter->ate.TxDoneCount = pAdapter->ate.TxCount;
4182 RTMP_IO_WRITE32(pAdapter, TXCSR0, 0x08); // Abort Tx
4183 RTMP_IO_WRITE32(pAdapter, RXCSR0, 0x56); // Start Rx
4185 else
4187 DBGPRINT(RT_DEBUG_TRACE, "ATE: Invalid arg!\n");
4188 return FALSE;
4190 mdelay(5);
4192 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_Proc\n");
4193 return TRUE;
4197 ==========================================================================
4198 Description:
4199 Set ATE ADDR1=DA for TxFrames Return:
4200 TRUE if all parameters are OK, FALSE otherwise
4201 ==========================================================================
4203 INT Set_ATE_DA_Proc(
4204 IN PRTMP_ADAPTER pAdapter,
4205 IN PUCHAR arg)
4207 char *value;
4208 int i;
4210 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_DA_Proc\n");
4211 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4213 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4214 return FALSE;
4216 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4218 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4219 return FALSE; //Invalid
4221 AtoH(value, &pAdapter->ate.Addr1[i++], 2);
4224 if(i != 6)
4225 return FALSE; //Invalid
4227 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]);
4228 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_DA_Proc\n");
4230 return TRUE;
4234 ==========================================================================
4235 Description:
4236 Set ATE ADDR2=SA for TxFrames Return:
4237 TRUE if all parameters are OK, FALSE otherwise
4238 ==========================================================================
4240 INT Set_ATE_SA_Proc(
4241 IN PRTMP_ADAPTER pAdapter,
4242 IN PUCHAR arg)
4244 char *value;
4245 int i;
4247 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_SA_Proc\n");
4248 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4250 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4251 return FALSE;
4253 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4255 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4256 return FALSE; //Invalid
4258 AtoH(value, &pAdapter->ate.Addr2[i++], 2);
4261 if(i != 6)
4262 return FALSE; //Invalid
4264 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]);
4265 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_SA_Proc\n");
4267 return TRUE;
4271 ==========================================================================
4272 Description:
4273 Set ATE ADDR3=BSSID for TxFrames Return:
4274 TRUE if all parameters are OK, FALSE otherwise
4275 ==========================================================================
4277 INT Set_ATE_BSSID_Proc(
4278 IN PRTMP_ADAPTER pAdapter,
4279 IN PUCHAR arg)
4281 char *value;
4282 int i;
4284 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_BSSID_Proc\n");
4285 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4287 if(strlen(arg) != 17) //Mac address acceptable format 01:02:03:04:05:06 length 17
4288 return FALSE;
4290 for (i=0, value = strtok(arg,":"); value; value = strtok(NULL,":"))
4292 if((strlen(value) != 2) || (!isxdigit(*value)) || (!isxdigit(*(value+1))) )
4293 return FALSE; //Invalid
4295 AtoH(value, &pAdapter->ate.Addr3[i++], 2);
4298 if(i != 6)
4299 return FALSE; //Invalid
4301 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]);
4302 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_BSSID_Proc\n");
4304 return TRUE;
4308 ==========================================================================
4309 Description:
4310 Set ATE Channel Return:
4311 TRUE if all parameters are OK, FALSE otherwise
4312 ==========================================================================
4314 INT Set_ATE_CHANNEL_Proc(
4315 IN PRTMP_ADAPTER pAdapter,
4316 IN PUCHAR arg)
4318 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_CHANNEL_Proc (arg = %s)\n", arg);
4320 pAdapter->ate.Channel = simple_strtol(arg, 0, 10);
4322 if((pAdapter->ate.Channel < 1) || (pAdapter->ate.Channel > 14))
4324 pAdapter->ate.Channel = 1;
4325 return FALSE;
4328 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_CHANNEL_Proc (ATE Channel = %d)\n", pAdapter->ate.Channel);
4330 return TRUE;
4334 ==========================================================================
4335 Description:
4336 Set ATE Tx Power Return:
4337 TRUE if all parameters are OK, FALSE otherwise
4338 ==========================================================================
4340 INT Set_ATE_TX_POWER_Proc(
4341 IN PRTMP_ADAPTER pAdapter,
4342 IN PUCHAR arg)
4344 ULONG R3;
4346 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_POWER_Proc\n");
4347 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4349 pAdapter->ate.TxPower = simple_strtol(arg, 0, 10);
4351 if(pAdapter->ate.TxPower >= 32)
4353 pAdapter->ate.TxPower = pAdapter->PortCfg.ChannelTxPower[pAdapter->PortCfg.Channel - 1];;
4354 return FALSE;
4357 R3 = pAdapter->ate.TxPower;
4358 R3 = R3 << 9; // shift TX power control to correct RF register bit position
4360 R3 |= (pAdapter->PortCfg.LatchRfRegs.R3 & 0xffffc1ff);
4361 RTMP_RF_IO_WRITE32(pAdapter, R3);
4363 DBGPRINT(RT_DEBUG_TRACE, "TxPower = %d\n", pAdapter->ate.TxPower);
4364 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_POWER_Proc\n");
4366 return TRUE;
4370 ==========================================================================
4371 Description:
4372 Set ATE Tx Length Return:
4373 TRUE if all parameters are OK, FALSE otherwise
4374 ==========================================================================
4376 INT Set_ATE_TX_LENGTH_Proc(
4377 IN PRTMP_ADAPTER pAdapter,
4378 IN PUCHAR arg)
4380 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_LENGTH_Proc\n");
4381 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4383 pAdapter->ate.TxLength = simple_strtol(arg, 0, 10);
4385 if((pAdapter->ate.TxLength < 24) || (pAdapter->ate.TxLength > 1500))
4387 pAdapter->ate.TxLength = 1500;
4388 return FALSE;
4391 DBGPRINT(RT_DEBUG_TRACE, "TxLength = %d\n", pAdapter->ate.TxLength);
4392 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_LENGTH_Proc\n");
4394 return TRUE;
4398 ==========================================================================
4399 Description:
4400 Set ATE Tx Count Return:
4401 TRUE if all parameters are OK, FALSE otherwise
4402 ==========================================================================
4404 INT Set_ATE_TX_COUNT_Proc(
4405 IN PRTMP_ADAPTER pAdapter,
4406 IN PUCHAR arg)
4408 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_COUNT_Proc\n");
4409 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4411 pAdapter->ate.TxCount = simple_strtol(arg, 0, 10);
4413 DBGPRINT(RT_DEBUG_TRACE, "TxCount = %d\n", pAdapter->ate.TxCount);
4414 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_COUNT_Proc\n");
4416 return TRUE;
4420 ==========================================================================
4421 Description:
4422 Set ATE Tx Rate
4423 Return:
4424 TRUE if all parameters are OK, FALSE otherwise
4425 ==========================================================================
4427 INT Set_ATE_TX_RATE_Proc(
4428 IN PRTMP_ADAPTER pAdapter,
4429 IN PUCHAR arg)
4431 DBGPRINT(RT_DEBUG_TRACE, "==> Set_ATE_TX_RATE_Proc\n");
4432 DBGPRINT(RT_DEBUG_TRACE, "arg=%s\n", arg);
4434 pAdapter->ate.TxRate = simple_strtol(arg, 0, 10);
4436 if(pAdapter->ate.TxRate > RATE_54)
4438 pAdapter->ate.TxRate = RATE_11;
4439 return FALSE;
4442 DBGPRINT(RT_DEBUG_TRACE, "TxRate = %d\n", pAdapter->ate.TxRate);
4443 DBGPRINT(RT_DEBUG_TRACE, "<== Set_ATE_TX_RATE_Proc\n");
4445 return TRUE;
4448 VOID RTMPStationStop(
4449 IN PRTMP_ADAPTER pAd)
4451 DBGPRINT(RT_DEBUG_TRACE, "==> RTMPStationStop\n");
4452 RTMPCancelTimer(&pAd->timer);
4453 RTMPCancelTimer(&pAd->Mlme.AssocAux.AssocTimer);
4454 RTMPCancelTimer(&pAd->Mlme.AssocAux.ReassocTimer);
4455 RTMPCancelTimer(&pAd->Mlme.AssocAux.DisassocTimer);
4456 RTMPCancelTimer(&pAd->Mlme.AuthAux.AuthTimer);
4457 RTMPCancelTimer(&pAd->Mlme.AuthRspAux.AuthRspTimer);
4458 RTMPCancelTimer(&pAd->Mlme.SyncAux.BeaconTimer);
4459 RTMPCancelTimer(&pAd->Mlme.SyncAux.ScanTimer);
4460 RTMPCancelTimer(&pAd->Mlme.PeriodicTimer);
4461 RTMPCancelTimer(&pAd->PortCfg.RfTuningTimer);
4462 if (pAd->PortCfg.LedMode == LED_MODE_TXRX_ACTIVITY)
4463 RTMPCancelTimer(&pAd->PortCfg.LedCntl.BlinkTimer);
4464 RTMPCancelTimer(&pAd->PortCfg.RxAnt.RxAntDiversityTimer);
4465 DBGPRINT(RT_DEBUG_TRACE, "<== RTMPStationStop\n");
4468 VOID RTMPStationStart(
4469 IN PRTMP_ADAPTER pAd)
4471 DBGPRINT(RT_DEBUG_TRACE, "==> RTMPStationStart\n");
4472 RTMPSetTimer(pAd, &pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV);
4473 //RTMPSetTimer(pAd, &pAd->timer, DEBUG_TASK_DELAY); //not used.
4474 DBGPRINT(RT_DEBUG_TRACE, "<== RTMPStationStart\n");
4477 #endif //#ifdef RALINK_ATE