]>
Commit | Line | Data |
---|---|---|
91980990 GKH |
1 | /* |
2 | ************************************************************************* | |
3 | * Ralink Tech Inc. | |
4 | * 5F., No.36, Taiyuan St., Jhubei City, | |
5 | * Hsinchu County 302, | |
6 | * Taiwan, R.O.C. | |
7 | * | |
8 | * (c) Copyright 2002-2007, Ralink Technology, Inc. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify * | |
11 | * it under the terms of the GNU General Public License as published by * | |
12 | * the Free Software Foundation; either version 2 of the License, or * | |
13 | * (at your option) any later version. * | |
14 | * * | |
15 | * This program is distributed in the hope that it will be useful, * | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
18 | * GNU General Public License for more details. * | |
19 | * * | |
20 | * You should have received a copy of the GNU General Public License * | |
21 | * along with this program; if not, write to the * | |
22 | * Free Software Foundation, Inc., * | |
23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
24 | * * | |
25 | ************************************************************************* | |
26 | ||
27 | Module Name: | |
28 | sta_ioctl.c | |
29 | ||
30 | Abstract: | |
31 | IOCTL related subroutines | |
32 | ||
33 | Revision History: | |
34 | Who When What | |
35 | -------- ---------- ---------------------------------------------- | |
36 | Rory Chen 01-03-2003 created | |
37 | Rory Chen 02-14-2005 modify to support RT61 | |
38 | */ | |
39 | ||
40 | #include "rt_config.h" | |
41 | ||
42 | #ifdef DBG | |
51126deb | 43 | extern unsigned long RTDebugLevel; |
91980990 GKH |
44 | #endif |
45 | ||
46 | #define NR_WEP_KEYS 4 | |
47 | #define WEP_SMALL_KEY_LEN (40/8) | |
48 | #define WEP_LARGE_KEY_LEN (104/8) | |
49 | ||
50 | #define GROUP_KEY_NO 4 | |
51 | ||
51126deb | 52 | extern u8 CipherWpa2Template[]; |
91980990 | 53 | |
62eb734b | 54 | struct PACKED rt_version_info { |
51126deb BZ |
55 | u8 DriverVersionW; |
56 | u8 DriverVersionX; | |
57 | u8 DriverVersionY; | |
58 | u8 DriverVersionZ; | |
59 | u32 DriverBuildYear; | |
60 | u32 DriverBuildMonth; | |
61 | u32 DriverBuildDay; | |
62eb734b | 62 | }; |
91980990 | 63 | |
9f548a2a BZ |
64 | static __s32 ralinkrate[] = { 2, 4, 11, 22, /* CCK */ |
65 | 12, 18, 24, 36, 48, 72, 96, 108, /* OFDM */ | |
66 | 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, /* 20MHz, 800ns GI, MCS: 0 ~ 15 */ | |
67 | 39, 78, 117, 156, 234, 312, 351, 390, /* 20MHz, 800ns GI, MCS: 16 ~ 23 */ | |
68 | 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, /* 40MHz, 800ns GI, MCS: 0 ~ 15 */ | |
69 | 81, 162, 243, 324, 486, 648, 729, 810, /* 40MHz, 800ns GI, MCS: 16 ~ 23 */ | |
70 | 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, /* 20MHz, 400ns GI, MCS: 0 ~ 15 */ | |
71 | 43, 87, 130, 173, 260, 317, 390, 433, /* 20MHz, 400ns GI, MCS: 16 ~ 23 */ | |
72 | 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, /* 40MHz, 400ns GI, MCS: 0 ~ 15 */ | |
66cd8d6e BZ |
73 | 90, 180, 270, 360, 540, 720, 810, 900 |
74 | }; | |
ca97b838 | 75 | |
62eb734b | 76 | int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg); |
91980990 | 77 | |
62eb734b | 78 | int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg); |
91980990 | 79 | |
62eb734b | 80 | void RTMPAddKey(struct rt_rtmp_adapter *pAd, struct rt_ndis_802_11_key *pKey) |
91980990 | 81 | { |
51126deb | 82 | unsigned long KeyIdx; |
62eb734b | 83 | struct rt_mac_table_entry *pEntry; |
66cd8d6e BZ |
84 | |
85 | DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n")); | |
86 | ||
87 | if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) { | |
88 | if (pKey->KeyIndex & 0x80000000) { | |
89 | if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) { | |
90 | NdisZeroMemory(pAd->StaCfg.PMK, 32); | |
91 | NdisMoveMemory(pAd->StaCfg.PMK, | |
92 | pKey->KeyMaterial, | |
93 | pKey->KeyLength); | |
94 | goto end; | |
95 | } | |
9f548a2a | 96 | /* Update PTK */ |
66cd8d6e | 97 | NdisZeroMemory(&pAd->SharedKey[BSS0][0], |
62eb734b | 98 | sizeof(struct rt_cipher_key)); |
66cd8d6e BZ |
99 | pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK; |
100 | NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, | |
101 | pKey->KeyMaterial, LEN_TKIP_EK); | |
102 | ||
103 | if (pAd->StaCfg.PairCipher == | |
104 | Ndis802_11Encryption2Enabled) { | |
105 | NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, | |
106 | pKey->KeyMaterial + LEN_TKIP_EK, | |
107 | LEN_TKIP_TXMICK); | |
108 | NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, | |
109 | pKey->KeyMaterial + LEN_TKIP_EK + | |
110 | LEN_TKIP_TXMICK, | |
111 | LEN_TKIP_RXMICK); | |
112 | } else { | |
113 | NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, | |
114 | pKey->KeyMaterial + LEN_TKIP_EK, | |
115 | LEN_TKIP_TXMICK); | |
116 | NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, | |
117 | pKey->KeyMaterial + LEN_TKIP_EK + | |
118 | LEN_TKIP_TXMICK, | |
119 | LEN_TKIP_RXMICK); | |
120 | } | |
91980990 | 121 | |
9f548a2a | 122 | /* Decide its ChiperAlg */ |
66cd8d6e BZ |
123 | if (pAd->StaCfg.PairCipher == |
124 | Ndis802_11Encryption2Enabled) | |
125 | pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP; | |
126 | else if (pAd->StaCfg.PairCipher == | |
127 | Ndis802_11Encryption3Enabled) | |
128 | pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES; | |
129 | else | |
130 | pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE; | |
131 | ||
62eb734b | 132 | /* Update these related information to struct rt_mac_table_entry */ |
66cd8d6e BZ |
133 | pEntry = &pAd->MacTab.Content[BSSID_WCID]; |
134 | NdisMoveMemory(pEntry->PairwiseKey.Key, | |
135 | pAd->SharedKey[BSS0][0].Key, | |
136 | LEN_TKIP_EK); | |
137 | NdisMoveMemory(pEntry->PairwiseKey.RxMic, | |
138 | pAd->SharedKey[BSS0][0].RxMic, | |
139 | LEN_TKIP_RXMICK); | |
140 | NdisMoveMemory(pEntry->PairwiseKey.TxMic, | |
141 | pAd->SharedKey[BSS0][0].TxMic, | |
142 | LEN_TKIP_TXMICK); | |
143 | pEntry->PairwiseKey.CipherAlg = | |
144 | pAd->SharedKey[BSS0][0].CipherAlg; | |
145 | ||
9f548a2a | 146 | /* Update pairwise key information to ASIC Shared Key Table */ |
66cd8d6e BZ |
147 | AsicAddSharedKeyEntry(pAd, |
148 | BSS0, | |
149 | 0, | |
150 | pAd->SharedKey[BSS0][0].CipherAlg, | |
151 | pAd->SharedKey[BSS0][0].Key, | |
152 | pAd->SharedKey[BSS0][0].TxMic, | |
153 | pAd->SharedKey[BSS0][0].RxMic); | |
154 | ||
9f548a2a | 155 | /* Update ASIC WCID attribute table and IVEIV table */ |
66cd8d6e BZ |
156 | RTMPAddWcidAttributeEntry(pAd, |
157 | BSS0, | |
158 | 0, | |
159 | pAd->SharedKey[BSS0][0]. | |
160 | CipherAlg, pEntry); | |
91980990 | 161 | |
66cd8d6e | 162 | if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2) { |
9f548a2a BZ |
163 | /* set 802.1x port control */ |
164 | /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ | |
91980990 GKH |
165 | STA_PORT_SECURED(pAd); |
166 | ||
9f548a2a | 167 | /* Indicate Connected for GUI */ |
66cd8d6e BZ |
168 | pAd->IndicateMediaState = |
169 | NdisMediaStateConnected; | |
170 | } | |
171 | } else { | |
9f548a2a | 172 | /* Update GTK */ |
66cd8d6e BZ |
173 | pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF); |
174 | NdisZeroMemory(&pAd-> | |
175 | SharedKey[BSS0][pAd->StaCfg. | |
176 | DefaultKeyId], | |
62eb734b | 177 | sizeof(struct rt_cipher_key)); |
66cd8d6e BZ |
178 | pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = |
179 | LEN_TKIP_EK; | |
180 | NdisMoveMemory(pAd-> | |
181 | SharedKey[BSS0][pAd->StaCfg. | |
182 | DefaultKeyId].Key, | |
183 | pKey->KeyMaterial, LEN_TKIP_EK); | |
184 | ||
185 | if (pAd->StaCfg.GroupCipher == | |
186 | Ndis802_11Encryption2Enabled) { | |
187 | NdisMoveMemory(pAd-> | |
188 | SharedKey[BSS0][pAd->StaCfg. | |
189 | DefaultKeyId]. | |
190 | RxMic, | |
191 | pKey->KeyMaterial + LEN_TKIP_EK, | |
192 | LEN_TKIP_TXMICK); | |
193 | NdisMoveMemory(pAd-> | |
194 | SharedKey[BSS0][pAd->StaCfg. | |
195 | DefaultKeyId]. | |
196 | TxMic, | |
197 | pKey->KeyMaterial + LEN_TKIP_EK + | |
198 | LEN_TKIP_TXMICK, | |
199 | LEN_TKIP_RXMICK); | |
200 | } else { | |
201 | NdisMoveMemory(pAd-> | |
202 | SharedKey[BSS0][pAd->StaCfg. | |
203 | DefaultKeyId]. | |
204 | TxMic, | |
205 | pKey->KeyMaterial + LEN_TKIP_EK, | |
206 | LEN_TKIP_TXMICK); | |
207 | NdisMoveMemory(pAd-> | |
208 | SharedKey[BSS0][pAd->StaCfg. | |
209 | DefaultKeyId]. | |
210 | RxMic, | |
211 | pKey->KeyMaterial + LEN_TKIP_EK + | |
212 | LEN_TKIP_TXMICK, | |
213 | LEN_TKIP_RXMICK); | |
214 | } | |
215 | ||
9f548a2a | 216 | /* Update Shared Key CipherAlg */ |
66cd8d6e BZ |
217 | pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. |
218 | CipherAlg = CIPHER_NONE; | |
219 | if (pAd->StaCfg.GroupCipher == | |
220 | Ndis802_11Encryption2Enabled) | |
221 | pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. | |
222 | CipherAlg = CIPHER_TKIP; | |
223 | else if (pAd->StaCfg.GroupCipher == | |
224 | Ndis802_11Encryption3Enabled) | |
225 | pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. | |
226 | CipherAlg = CIPHER_AES; | |
227 | ||
9f548a2a | 228 | /* Update group key information to ASIC Shared Key Table */ |
66cd8d6e BZ |
229 | AsicAddSharedKeyEntry(pAd, |
230 | BSS0, | |
231 | pAd->StaCfg.DefaultKeyId, | |
232 | pAd->SharedKey[BSS0][pAd->StaCfg. | |
233 | DefaultKeyId]. | |
234 | CipherAlg, | |
235 | pAd->SharedKey[BSS0][pAd->StaCfg. | |
236 | DefaultKeyId]. | |
237 | Key, | |
238 | pAd->SharedKey[BSS0][pAd->StaCfg. | |
239 | DefaultKeyId]. | |
240 | TxMic, | |
241 | pAd->SharedKey[BSS0][pAd->StaCfg. | |
242 | DefaultKeyId]. | |
243 | RxMic); | |
244 | ||
9f548a2a | 245 | /* Update ASIC WCID attribute table and IVEIV table */ |
66cd8d6e BZ |
246 | RTMPAddWcidAttributeEntry(pAd, |
247 | BSS0, | |
248 | pAd->StaCfg.DefaultKeyId, | |
249 | pAd->SharedKey[BSS0][pAd-> | |
250 | StaCfg. | |
251 | DefaultKeyId]. | |
252 | CipherAlg, NULL); | |
253 | ||
9f548a2a BZ |
254 | /* set 802.1x port control */ |
255 | /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ | |
91980990 GKH |
256 | STA_PORT_SECURED(pAd); |
257 | ||
9f548a2a | 258 | /* Indicate Connected for GUI */ |
66cd8d6e BZ |
259 | pAd->IndicateMediaState = NdisMediaStateConnected; |
260 | } | |
9f548a2a | 261 | } else /* dynamic WEP from wpa_supplicant */ |
91980990 | 262 | { |
51126deb BZ |
263 | u8 CipherAlg; |
264 | u8 *Key; | |
91980990 | 265 | |
66cd8d6e | 266 | if (pKey->KeyLength == 32) |
91980990 GKH |
267 | goto end; |
268 | ||
269 | KeyIdx = pKey->KeyIndex & 0x0fffffff; | |
270 | ||
66cd8d6e | 271 | if (KeyIdx < 4) { |
9f548a2a | 272 | /* it is a default shared key, for Pairwise key setting */ |
66cd8d6e | 273 | if (pKey->KeyIndex & 0x80000000) { |
91980990 GKH |
274 | pEntry = MacTableLookup(pAd, pKey->BSSID); |
275 | ||
66cd8d6e BZ |
276 | if (pEntry) { |
277 | DBGPRINT(RT_DEBUG_TRACE, | |
278 | ("RTMPAddKey: Set Pair-wise Key\n")); | |
91980990 | 279 | |
9f548a2a | 280 | /* set key material and key length */ |
66cd8d6e | 281 | pEntry->PairwiseKey.KeyLen = |
51126deb | 282 | (u8)pKey->KeyLength; |
66cd8d6e BZ |
283 | NdisMoveMemory(pEntry->PairwiseKey.Key, |
284 | &pKey->KeyMaterial, | |
285 | pKey->KeyLength); | |
91980990 | 286 | |
9f548a2a | 287 | /* set Cipher type */ |
91980990 | 288 | if (pKey->KeyLength == 5) |
66cd8d6e BZ |
289 | pEntry->PairwiseKey.CipherAlg = |
290 | CIPHER_WEP64; | |
91980990 | 291 | else |
66cd8d6e BZ |
292 | pEntry->PairwiseKey.CipherAlg = |
293 | CIPHER_WEP128; | |
91980990 | 294 | |
9f548a2a | 295 | /* Add Pair-wise key to Asic */ |
66cd8d6e BZ |
296 | AsicAddPairwiseKeyEntry(pAd, |
297 | pEntry->Addr, | |
51126deb | 298 | (u8)pEntry-> |
66cd8d6e BZ |
299 | Aid, |
300 | &pEntry-> | |
301 | PairwiseKey); | |
91980990 | 302 | |
9f548a2a BZ |
303 | /* update WCID attribute table and IVEIV table for this entry */ |
304 | RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, /* The value may be not zero */ | |
66cd8d6e BZ |
305 | pEntry-> |
306 | PairwiseKey. | |
307 | CipherAlg, | |
308 | pEntry); | |
91980990 GKH |
309 | |
310 | } | |
66cd8d6e | 311 | } else { |
9f548a2a | 312 | /* Default key for tx (shared key) */ |
51126deb | 313 | pAd->StaCfg.DefaultKeyId = (u8)KeyIdx; |
91980990 | 314 | |
9f548a2a | 315 | /* set key material and key length */ |
66cd8d6e | 316 | pAd->SharedKey[BSS0][KeyIdx].KeyLen = |
51126deb | 317 | (u8)pKey->KeyLength; |
66cd8d6e BZ |
318 | NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, |
319 | &pKey->KeyMaterial, | |
320 | pKey->KeyLength); | |
91980990 | 321 | |
9f548a2a | 322 | /* Set Ciper type */ |
91980990 | 323 | if (pKey->KeyLength == 5) |
66cd8d6e BZ |
324 | pAd->SharedKey[BSS0][KeyIdx].CipherAlg = |
325 | CIPHER_WEP64; | |
91980990 | 326 | else |
66cd8d6e BZ |
327 | pAd->SharedKey[BSS0][KeyIdx].CipherAlg = |
328 | CIPHER_WEP128; | |
91980990 | 329 | |
66cd8d6e BZ |
330 | CipherAlg = |
331 | pAd->SharedKey[BSS0][KeyIdx].CipherAlg; | |
332 | Key = pAd->SharedKey[BSS0][KeyIdx].Key; | |
91980990 | 333 | |
9f548a2a | 334 | /* Set Group key material to Asic */ |
66cd8d6e BZ |
335 | AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, |
336 | CipherAlg, Key, NULL, | |
337 | NULL); | |
91980990 | 338 | |
9f548a2a | 339 | /* Update WCID attribute table and IVEIV table for this group key table */ |
66cd8d6e BZ |
340 | RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, |
341 | CipherAlg, NULL); | |
91980990 GKH |
342 | |
343 | } | |
344 | } | |
345 | } | |
346 | end: | |
347 | return; | |
348 | } | |
349 | ||
66cd8d6e | 350 | char *rtstrchr(const char *s, int c) |
91980990 | 351 | { |
66cd8d6e BZ |
352 | for (; *s != (char)c; ++s) |
353 | if (*s == '\0') | |
354 | return NULL; | |
355 | return (char *)s; | |
91980990 GKH |
356 | } |
357 | ||
358 | /* | |
359 | This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function | |
360 | */ | |
361 | ||
362 | int | |
363 | rt_ioctl_giwname(struct net_device *dev, | |
66cd8d6e | 364 | struct iw_request_info *info, char *name, char *extra) |
91980990 | 365 | { |
ca97b838 | 366 | strncpy(name, "Ralink STA", IFNAMSIZ); |
9f548a2a BZ |
367 | /* RT2870 2.1.0.0 uses "RT2870 Wireless" */ |
368 | /* RT3090 2.1.0.0 uses "RT2860 Wireless" */ | |
91980990 GKH |
369 | return 0; |
370 | } | |
371 | ||
372 | int rt_ioctl_siwfreq(struct net_device *dev, | |
66cd8d6e BZ |
373 | struct iw_request_info *info, |
374 | struct iw_freq *freq, char *extra) | |
91980990 | 375 | { |
62eb734b | 376 | struct rt_rtmp_adapter *pAdapter = NULL; |
66cd8d6e | 377 | int chan = -1; |
91980990 | 378 | |
ca97b838 BZ |
379 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
380 | ||
9f548a2a | 381 | /*check if the interface is down */ |
66cd8d6e BZ |
382 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
383 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
384 | return -ENETDOWN; | |
385 | } | |
91980990 GKH |
386 | |
387 | if (freq->e > 1) | |
388 | return -EINVAL; | |
389 | ||
66cd8d6e | 390 | if ((freq->e == 0) && (freq->m <= 1000)) |
9f548a2a | 391 | chan = freq->m; /* Setting by channel number */ |
91980990 | 392 | else |
9f548a2a | 393 | MAP_KHZ_TO_CHANNEL_ID((freq->m / 100), chan); /* Setting by frequency - search the table , like 2.412G, 2.422G, */ |
66cd8d6e BZ |
394 | |
395 | if (ChannelSanity(pAdapter, chan) == TRUE) { | |
396 | pAdapter->CommonCfg.Channel = chan; | |
397 | DBGPRINT(RT_DEBUG_ERROR, | |
398 | ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", | |
399 | SIOCSIWFREQ, pAdapter->CommonCfg.Channel)); | |
400 | } else | |
401 | return -EINVAL; | |
91980990 GKH |
402 | |
403 | return 0; | |
404 | } | |
66cd8d6e | 405 | |
91980990 | 406 | int rt_ioctl_giwfreq(struct net_device *dev, |
66cd8d6e BZ |
407 | struct iw_request_info *info, |
408 | struct iw_freq *freq, char *extra) | |
91980990 | 409 | { |
62eb734b | 410 | struct rt_rtmp_adapter *pAdapter = NULL; |
51126deb BZ |
411 | u8 ch; |
412 | unsigned long m = 2412000; | |
ca97b838 BZ |
413 | |
414 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
415 | ||
66cd8d6e | 416 | ch = pAdapter->CommonCfg.Channel; |
91980990 | 417 | |
66cd8d6e | 418 | DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwfreq %d\n", ch)); |
91980990 | 419 | |
66cd8d6e | 420 | MAP_CHANNEL_ID_TO_KHZ(ch, m); |
91980990 GKH |
421 | freq->m = m * 100; |
422 | freq->e = 1; | |
423 | return 0; | |
424 | } | |
425 | ||
426 | int rt_ioctl_siwmode(struct net_device *dev, | |
66cd8d6e | 427 | struct iw_request_info *info, __u32 * mode, char *extra) |
91980990 | 428 | { |
62eb734b | 429 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
430 | |
431 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 432 | |
9f548a2a | 433 | /*check if the interface is down */ |
66cd8d6e BZ |
434 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
435 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
436 | return -ENETDOWN; | |
437 | } | |
91980990 | 438 | |
66cd8d6e BZ |
439 | switch (*mode) { |
440 | case IW_MODE_ADHOC: | |
441 | Set_NetworkType_Proc(pAdapter, "Adhoc"); | |
442 | break; | |
443 | case IW_MODE_INFRA: | |
444 | Set_NetworkType_Proc(pAdapter, "Infra"); | |
445 | break; | |
446 | case IW_MODE_MONITOR: | |
447 | Set_NetworkType_Proc(pAdapter, "Monitor"); | |
448 | break; | |
449 | default: | |
450 | DBGPRINT(RT_DEBUG_TRACE, | |
451 | ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", | |
452 | *mode)); | |
453 | return -EINVAL; | |
91980990 GKH |
454 | } |
455 | ||
9f548a2a | 456 | /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */ |
91980990 GKH |
457 | pAdapter->StaCfg.WpaState = SS_NOTUSE; |
458 | ||
459 | return 0; | |
460 | } | |
461 | ||
462 | int rt_ioctl_giwmode(struct net_device *dev, | |
66cd8d6e | 463 | struct iw_request_info *info, __u32 * mode, char *extra) |
91980990 | 464 | { |
62eb734b | 465 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
466 | |
467 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 GKH |
468 | |
469 | if (ADHOC_ON(pAdapter)) | |
470 | *mode = IW_MODE_ADHOC; | |
66cd8d6e | 471 | else if (INFRA_ON(pAdapter)) |
91980990 | 472 | *mode = IW_MODE_INFRA; |
66cd8d6e BZ |
473 | else if (MONITOR_ON(pAdapter)) { |
474 | *mode = IW_MODE_MONITOR; | |
475 | } else | |
476 | *mode = IW_MODE_AUTO; | |
91980990 GKH |
477 | |
478 | DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode)); | |
479 | return 0; | |
480 | } | |
481 | ||
482 | int rt_ioctl_siwsens(struct net_device *dev, | |
66cd8d6e | 483 | struct iw_request_info *info, char *name, char *extra) |
91980990 | 484 | { |
62eb734b | 485 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
486 | |
487 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 488 | |
9f548a2a | 489 | /*check if the interface is down */ |
66cd8d6e BZ |
490 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
491 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
492 | return -ENETDOWN; | |
493 | } | |
91980990 GKH |
494 | |
495 | return 0; | |
496 | } | |
497 | ||
498 | int rt_ioctl_giwsens(struct net_device *dev, | |
66cd8d6e | 499 | struct iw_request_info *info, char *name, char *extra) |
91980990 GKH |
500 | { |
501 | return 0; | |
502 | } | |
503 | ||
504 | int rt_ioctl_giwrange(struct net_device *dev, | |
66cd8d6e BZ |
505 | struct iw_request_info *info, |
506 | struct iw_point *data, char *extra) | |
91980990 | 507 | { |
62eb734b | 508 | struct rt_rtmp_adapter *pAdapter = NULL; |
66cd8d6e | 509 | struct iw_range *range = (struct iw_range *)extra; |
91980990 GKH |
510 | u16 val; |
511 | int i; | |
512 | ||
ca97b838 BZ |
513 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
514 | ||
66cd8d6e | 515 | DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwrange\n")); |
91980990 GKH |
516 | data->length = sizeof(struct iw_range); |
517 | memset(range, 0, sizeof(struct iw_range)); | |
518 | ||
519 | range->txpower_capa = IW_TXPOW_DBM; | |
520 | ||
66cd8d6e | 521 | if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) { |
91980990 GKH |
522 | range->min_pmp = 1 * 1024; |
523 | range->max_pmp = 65535 * 1024; | |
524 | range->min_pmt = 1 * 1024; | |
525 | range->max_pmt = 1000 * 1024; | |
526 | range->pmp_flags = IW_POWER_PERIOD; | |
527 | range->pmt_flags = IW_POWER_TIMEOUT; | |
528 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | | |
66cd8d6e | 529 | IW_POWER_UNICAST_R | IW_POWER_ALL_R; |
91980990 GKH |
530 | } |
531 | ||
532 | range->we_version_compiled = WIRELESS_EXT; | |
533 | range->we_version_source = 14; | |
534 | ||
535 | range->retry_capa = IW_RETRY_LIMIT; | |
536 | range->retry_flags = IW_RETRY_LIMIT; | |
537 | range->min_retry = 0; | |
538 | range->max_retry = 255; | |
539 | ||
66cd8d6e | 540 | range->num_channels = pAdapter->ChannelListNum; |
91980990 GKH |
541 | |
542 | val = 0; | |
66cd8d6e | 543 | for (i = 1; i <= range->num_channels; i++) { |
ca97b838 | 544 | u32 m = 2412000; |
66cd8d6e BZ |
545 | range->freq[val].i = pAdapter->ChannelList[i - 1].Channel; |
546 | MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i - 1].Channel, m); | |
547 | range->freq[val].m = m * 100; /* OS_HZ */ | |
91980990 GKH |
548 | |
549 | range->freq[val].e = 1; | |
550 | val++; | |
551 | if (val == IW_MAX_FREQUENCIES) | |
552 | break; | |
553 | } | |
554 | range->num_frequency = val; | |
555 | ||
66cd8d6e BZ |
556 | range->max_qual.qual = 100; /* what is correct max? This was not |
557 | * documented exactly. At least | |
558 | * 69 has been observed. */ | |
559 | range->max_qual.level = 0; /* dB */ | |
560 | range->max_qual.noise = 0; /* dB */ | |
91980990 GKH |
561 | |
562 | /* What would be suitable values for "average/typical" qual? */ | |
563 | range->avg_qual.qual = 20; | |
564 | range->avg_qual.level = -60; | |
565 | range->avg_qual.noise = -95; | |
566 | range->sensitivity = 3; | |
567 | ||
568 | range->max_encoding_tokens = NR_WEP_KEYS; | |
569 | range->num_encoding_sizes = 2; | |
570 | range->encoding_size[0] = 5; | |
571 | range->encoding_size[1] = 13; | |
572 | ||
573 | range->min_rts = 0; | |
574 | range->max_rts = 2347; | |
575 | range->min_frag = 256; | |
576 | range->max_frag = 2346; | |
577 | ||
91980990 GKH |
578 | /* IW_ENC_CAPA_* bit field */ |
579 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | |
66cd8d6e | 580 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
91980990 GKH |
581 | |
582 | return 0; | |
583 | } | |
584 | ||
585 | int rt_ioctl_siwap(struct net_device *dev, | |
66cd8d6e BZ |
586 | struct iw_request_info *info, |
587 | struct sockaddr *ap_addr, char *extra) | |
91980990 | 588 | { |
62eb734b | 589 | struct rt_rtmp_adapter *pAdapter = NULL; |
66cd8d6e | 590 | NDIS_802_11_MAC_ADDRESS Bssid; |
91980990 | 591 | |
ca97b838 BZ |
592 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
593 | ||
9f548a2a | 594 | /*check if the interface is down */ |
66cd8d6e BZ |
595 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
596 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
597 | return -ENETDOWN; | |
598 | } | |
599 | ||
600 | if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { | |
601 | RTMP_MLME_RESET_STATE_MACHINE(pAdapter); | |
602 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 603 | ("MLME busy, reset MLME state machine!\n")); |
66cd8d6e | 604 | } |
9f548a2a BZ |
605 | /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */ |
606 | /* this request, because this request is initiated by NDIS. */ | |
66cd8d6e | 607 | pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE; |
9f548a2a | 608 | /* Prevent to connect AP again in STAMlmePeriodicExec */ |
66cd8d6e | 609 | pAdapter->MlmeAux.AutoReconnectSsidLen = 32; |
91980990 | 610 | |
66cd8d6e BZ |
611 | memset(Bssid, 0, MAC_ADDR_LEN); |
612 | memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN); | |
613 | MlmeEnqueue(pAdapter, | |
614 | MLME_CNTL_STATE_MACHINE, | |
615 | OID_802_11_BSSID, | |
51126deb | 616 | sizeof(NDIS_802_11_MAC_ADDRESS), (void *) & Bssid); |
91980990 | 617 | |
66cd8d6e BZ |
618 | DBGPRINT(RT_DEBUG_TRACE, |
619 | ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n", Bssid[0], | |
620 | Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5])); | |
91980990 GKH |
621 | |
622 | return 0; | |
623 | } | |
624 | ||
625 | int rt_ioctl_giwap(struct net_device *dev, | |
66cd8d6e BZ |
626 | struct iw_request_info *info, |
627 | struct sockaddr *ap_addr, char *extra) | |
91980990 | 628 | { |
62eb734b | 629 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
630 | |
631 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 632 | |
66cd8d6e | 633 | if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) { |
91980990 GKH |
634 | ap_addr->sa_family = ARPHRD_ETHER; |
635 | memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN); | |
636 | } | |
9f548a2a | 637 | /* Add for RT2870 */ |
66cd8d6e BZ |
638 | else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) { |
639 | ap_addr->sa_family = ARPHRD_ETHER; | |
640 | memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN); | |
641 | } else { | |
91980990 GKH |
642 | DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n")); |
643 | return -ENOTCONN; | |
644 | } | |
645 | ||
646 | return 0; | |
647 | } | |
648 | ||
649 | /* | |
650 | * Units are in db above the noise floor. That means the | |
651 | * rssi values reported in the tx/rx descriptors in the | |
652 | * driver are the SNR expressed in db. | |
653 | * | |
654 | * If you assume that the noise floor is -95, which is an | |
655 | * excellent assumption 99.5 % of the time, then you can | |
656 | * derive the absolute signal level (i.e. -95 + rssi). | |
657 | * There are some other slight factors to take into account | |
658 | * depending on whether the rssi measurement is from 11b, | |
659 | * 11g, or 11a. These differences are at most 2db and | |
660 | * can be documented. | |
661 | * | |
662 | * NB: various calculations are based on the orinoco/wavelan | |
663 | * drivers for compatibility | |
664 | */ | |
62eb734b | 665 | static void set_quality(struct rt_rtmp_adapter *pAdapter, |
66cd8d6e | 666 | struct iw_quality *iq, signed char rssi) |
91980990 GKH |
667 | { |
668 | __u8 ChannelQuality; | |
669 | ||
9f548a2a | 670 | /* Normalize Rssi */ |
91980990 GKH |
671 | if (rssi >= -50) |
672 | ChannelQuality = 100; | |
9f548a2a | 673 | else if (rssi >= -80) /* between -50 ~ -80dbm */ |
66cd8d6e | 674 | ChannelQuality = (__u8) (24 + ((rssi + 80) * 26) / 10); |
9f548a2a | 675 | else if (rssi >= -90) /* between -80 ~ -90dbm */ |
66cd8d6e | 676 | ChannelQuality = (__u8) ((rssi + 90) * 26) / 10; |
91980990 GKH |
677 | else |
678 | ChannelQuality = 0; | |
679 | ||
66cd8d6e | 680 | iq->qual = (__u8) ChannelQuality; |
91980990 | 681 | |
66cd8d6e | 682 | iq->level = (__u8) (rssi); |
9f548a2a | 683 | iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8) pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); /* noise level (dBm) */ |
66cd8d6e BZ |
684 | iq->noise += 256 - 143; |
685 | iq->updated = pAdapter->iw_stats.qual.updated; | |
91980990 GKH |
686 | } |
687 | ||
688 | int rt_ioctl_iwaplist(struct net_device *dev, | |
66cd8d6e BZ |
689 | struct iw_request_info *info, |
690 | struct iw_point *data, char *extra) | |
91980990 | 691 | { |
62eb734b | 692 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
693 | |
694 | struct sockaddr addr[IW_MAX_AP]; | |
695 | struct iw_quality qual[IW_MAX_AP]; | |
696 | int i; | |
697 | ||
ca97b838 BZ |
698 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
699 | ||
9f548a2a | 700 | /*check if the interface is down */ |
66cd8d6e BZ |
701 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
702 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
91980990 GKH |
703 | data->length = 0; |
704 | return 0; | |
9f548a2a | 705 | /*return -ENETDOWN; */ |
91980990 GKH |
706 | } |
707 | ||
66cd8d6e BZ |
708 | for (i = 0; i < IW_MAX_AP; i++) { |
709 | if (i >= pAdapter->ScanTab.BssNr) | |
91980990 GKH |
710 | break; |
711 | addr[i].sa_family = ARPHRD_ETHER; | |
66cd8d6e BZ |
712 | memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, |
713 | MAC_ADDR_LEN); | |
714 | set_quality(pAdapter, &qual[i], | |
715 | pAdapter->ScanTab.BssEntry[i].Rssi); | |
91980990 GKH |
716 | } |
717 | data->length = i; | |
66cd8d6e BZ |
718 | memcpy(extra, &addr, i * sizeof(addr[0])); |
719 | data->flags = 1; /* signal quality present (sort of) */ | |
720 | memcpy(extra + i * sizeof(addr[0]), &qual, i * sizeof(qual[i])); | |
91980990 GKH |
721 | |
722 | return 0; | |
723 | } | |
724 | ||
91980990 | 725 | int rt_ioctl_siwscan(struct net_device *dev, |
66cd8d6e BZ |
726 | struct iw_request_info *info, |
727 | struct iw_point *data, char *extra) | |
91980990 | 728 | { |
62eb734b | 729 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 | 730 | |
51126deb | 731 | unsigned long Now; |
91980990 GKH |
732 | int Status = NDIS_STATUS_SUCCESS; |
733 | ||
ca97b838 BZ |
734 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
735 | ||
9f548a2a | 736 | /*check if the interface is down */ |
66cd8d6e | 737 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
91980990 GKH |
738 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); |
739 | return -ENETDOWN; | |
740 | } | |
741 | ||
66cd8d6e BZ |
742 | if (MONITOR_ON(pAdapter)) { |
743 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 744 | ("Driver is in Monitor Mode now!\n")); |
66cd8d6e BZ |
745 | return -EINVAL; |
746 | } | |
ca97b838 | 747 | |
66cd8d6e | 748 | if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { |
91980990 GKH |
749 | pAdapter->StaCfg.WpaSupplicantScanCount++; |
750 | } | |
91980990 | 751 | |
66cd8d6e | 752 | pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE; |
91980990 | 753 | if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) |
ca97b838 | 754 | return NDIS_STATUS_SUCCESS; |
66cd8d6e | 755 | do { |
91980990 GKH |
756 | Now = jiffies; |
757 | ||
66cd8d6e BZ |
758 | if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) |
759 | && (pAdapter->StaCfg.WpaSupplicantScanCount > 3)) { | |
760 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 761 | ("WpaSupplicantScanCount > 3\n")); |
91980990 GKH |
762 | Status = NDIS_STATUS_SUCCESS; |
763 | break; | |
764 | } | |
91980990 | 765 | |
66cd8d6e BZ |
766 | if ((OPSTATUS_TEST_FLAG |
767 | (pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) | |
768 | && ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) | |
769 | || (pAdapter->StaCfg.AuthMode == | |
770 | Ndis802_11AuthModeWPAPSK)) | |
771 | && (pAdapter->StaCfg.PortSecured == | |
772 | WPA_802_1X_PORT_NOT_SECURED)) { | |
773 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 774 | ("Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n")); |
91980990 GKH |
775 | Status = NDIS_STATUS_SUCCESS; |
776 | break; | |
777 | } | |
778 | ||
66cd8d6e | 779 | if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { |
ca97b838 | 780 | RTMP_MLME_RESET_STATE_MACHINE(pAdapter); |
66cd8d6e | 781 | DBGPRINT(RT_DEBUG_TRACE, |
06aea994 | 782 | ("MLME busy, reset MLME state machine!\n")); |
91980990 | 783 | } |
9f548a2a BZ |
784 | /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */ |
785 | /* this request, because this request is initiated by NDIS. */ | |
91980990 | 786 | pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE; |
9f548a2a | 787 | /* Reset allowed scan retries */ |
91980990 GKH |
788 | pAdapter->StaCfg.ScanCnt = 0; |
789 | pAdapter->StaCfg.LastScanTime = Now; | |
790 | ||
791 | MlmeEnqueue(pAdapter, | |
66cd8d6e BZ |
792 | MLME_CNTL_STATE_MACHINE, |
793 | OID_802_11_BSSID_LIST_SCAN, 0, NULL); | |
91980990 GKH |
794 | |
795 | Status = NDIS_STATUS_SUCCESS; | |
ca97b838 | 796 | RTMP_MLME_HANDLER(pAdapter); |
66cd8d6e | 797 | } while (0); |
ca97b838 | 798 | return NDIS_STATUS_SUCCESS; |
91980990 GKH |
799 | } |
800 | ||
801 | int rt_ioctl_giwscan(struct net_device *dev, | |
66cd8d6e BZ |
802 | struct iw_request_info *info, |
803 | struct iw_point *data, char *extra) | |
91980990 | 804 | { |
62eb734b | 805 | struct rt_rtmp_adapter *pAdapter = NULL; |
66cd8d6e | 806 | int i = 0; |
51126deb BZ |
807 | char *current_ev = extra, *previous_ev = extra; |
808 | char *end_buf; | |
809 | char *current_val; | |
810 | char custom[MAX_CUSTOM_LEN] = { 0 }; | |
91980990 GKH |
811 | struct iw_event iwe; |
812 | ||
ca97b838 BZ |
813 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
814 | ||
66cd8d6e | 815 | if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) { |
91980990 GKH |
816 | /* |
817 | * Still scanning, indicate the caller should try again. | |
818 | */ | |
819 | return -EAGAIN; | |
820 | } | |
821 | ||
66cd8d6e | 822 | if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { |
91980990 GKH |
823 | pAdapter->StaCfg.WpaSupplicantScanCount = 0; |
824 | } | |
91980990 | 825 | |
66cd8d6e | 826 | if (pAdapter->ScanTab.BssNr == 0) { |
91980990 GKH |
827 | data->length = 0; |
828 | return 0; | |
829 | } | |
830 | ||
66cd8d6e BZ |
831 | if (data->length > 0) |
832 | end_buf = extra + data->length; | |
833 | else | |
834 | end_buf = extra + IW_SCAN_MAX_DATA; | |
91980990 | 835 | |
66cd8d6e BZ |
836 | for (i = 0; i < pAdapter->ScanTab.BssNr; i++) { |
837 | if (current_ev >= end_buf) { | |
e82bf85e | 838 | return -E2BIG; |
66cd8d6e | 839 | } |
9f548a2a BZ |
840 | /*MAC address */ |
841 | /*================================ */ | |
91980990 GKH |
842 | memset(&iwe, 0, sizeof(iwe)); |
843 | iwe.cmd = SIOCGIWAP; | |
844 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
66cd8d6e BZ |
845 | memcpy(iwe.u.ap_addr.sa_data, |
846 | &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN); | |
91980990 | 847 | |
66cd8d6e BZ |
848 | previous_ev = current_ev; |
849 | current_ev = | |
850 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
851 | IW_EV_ADDR_LEN); | |
852 | if (current_ev == previous_ev) | |
853 | return -E2BIG; | |
3a32ed12 BZ |
854 | |
855 | /* | |
66cd8d6e BZ |
856 | Protocol: |
857 | it will show scanned AP's WirelessMode . | |
858 | it might be | |
859 | 802.11a | |
860 | 802.11a/n | |
861 | 802.11g/n | |
862 | 802.11b/g/n | |
863 | 802.11g | |
864 | 802.11b/g | |
865 | */ | |
3a32ed12 BZ |
866 | memset(&iwe, 0, sizeof(iwe)); |
867 | iwe.cmd = SIOCGIWNAME; | |
868 | ||
3a32ed12 | 869 | { |
62eb734b | 870 | struct rt_bss_entry *pBssEntry = &pAdapter->ScanTab.BssEntry[i]; |
66cd8d6e BZ |
871 | BOOLEAN isGonly = FALSE; |
872 | int rateCnt = 0; | |
3a32ed12 | 873 | |
66cd8d6e BZ |
874 | if (pBssEntry->Channel > 14) { |
875 | if (pBssEntry->HtCapabilityLen != 0) | |
876 | strcpy(iwe.u.name, "802.11a/n"); | |
877 | else | |
878 | strcpy(iwe.u.name, "802.11a"); | |
879 | } else { | |
880 | /* | |
881 | if one of non B mode rate is set supported rate . it mean G only. | |
882 | */ | |
883 | for (rateCnt = 0; | |
884 | rateCnt < pBssEntry->SupRateLen; | |
885 | rateCnt++) { | |
886 | /* | |
887 | 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only. | |
888 | */ | |
889 | if (pBssEntry->SupRate[rateCnt] == 140 | |
890 | || pBssEntry->SupRate[rateCnt] == | |
891 | 146 | |
892 | || pBssEntry->SupRate[rateCnt] >= | |
893 | 152) | |
894 | isGonly = TRUE; | |
895 | } | |
3a32ed12 | 896 | |
66cd8d6e BZ |
897 | for (rateCnt = 0; |
898 | rateCnt < pBssEntry->ExtRateLen; | |
899 | rateCnt++) { | |
900 | if (pBssEntry->ExtRate[rateCnt] == 140 | |
901 | || pBssEntry->ExtRate[rateCnt] == | |
902 | 146 | |
903 | || pBssEntry->ExtRate[rateCnt] >= | |
904 | 152) | |
905 | isGonly = TRUE; | |
906 | } | |
3a32ed12 | 907 | |
66cd8d6e BZ |
908 | if (pBssEntry->HtCapabilityLen != 0) { |
909 | if (isGonly == TRUE) | |
910 | strcpy(iwe.u.name, "802.11g/n"); | |
3a32ed12 | 911 | else |
66cd8d6e BZ |
912 | strcpy(iwe.u.name, |
913 | "802.11b/g/n"); | |
914 | } else { | |
915 | if (isGonly == TRUE) | |
916 | strcpy(iwe.u.name, "802.11g"); | |
917 | else { | |
918 | if (pBssEntry->SupRateLen == 4 | |
919 | && pBssEntry->ExtRateLen == | |
920 | 0) | |
921 | strcpy(iwe.u.name, | |
922 | "802.11b"); | |
923 | else | |
924 | strcpy(iwe.u.name, | |
925 | "802.11b/g"); | |
926 | } | |
3a32ed12 BZ |
927 | } |
928 | } | |
929 | } | |
3a32ed12 BZ |
930 | |
931 | previous_ev = current_ev; | |
66cd8d6e BZ |
932 | current_ev = |
933 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
934 | IW_EV_ADDR_LEN); | |
935 | if (current_ev == previous_ev) | |
936 | return -E2BIG; | |
91980990 | 937 | |
9f548a2a BZ |
938 | /*ESSID */ |
939 | /*================================ */ | |
91980990 GKH |
940 | memset(&iwe, 0, sizeof(iwe)); |
941 | iwe.cmd = SIOCGIWESSID; | |
942 | iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen; | |
943 | iwe.u.data.flags = 1; | |
944 | ||
66cd8d6e BZ |
945 | previous_ev = current_ev; |
946 | current_ev = | |
947 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
51126deb | 948 | (char *)pAdapter->ScanTab. |
66cd8d6e BZ |
949 | BssEntry[i].Ssid); |
950 | if (current_ev == previous_ev) | |
951 | return -E2BIG; | |
91980990 | 952 | |
9f548a2a BZ |
953 | /*Network Type */ |
954 | /*================================ */ | |
91980990 GKH |
955 | memset(&iwe, 0, sizeof(iwe)); |
956 | iwe.cmd = SIOCGIWMODE; | |
66cd8d6e | 957 | if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS) { |
91980990 | 958 | iwe.u.mode = IW_MODE_ADHOC; |
66cd8d6e BZ |
959 | } else if (pAdapter->ScanTab.BssEntry[i].BssType == |
960 | Ndis802_11Infrastructure) { | |
91980990 | 961 | iwe.u.mode = IW_MODE_INFRA; |
66cd8d6e | 962 | } else { |
91980990 GKH |
963 | iwe.u.mode = IW_MODE_AUTO; |
964 | } | |
965 | iwe.len = IW_EV_UINT_LEN; | |
966 | ||
66cd8d6e BZ |
967 | previous_ev = current_ev; |
968 | current_ev = | |
969 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
970 | IW_EV_UINT_LEN); | |
971 | if (current_ev == previous_ev) | |
972 | return -E2BIG; | |
91980990 | 973 | |
9f548a2a BZ |
974 | /*Channel and Frequency */ |
975 | /*================================ */ | |
91980990 GKH |
976 | memset(&iwe, 0, sizeof(iwe)); |
977 | iwe.cmd = SIOCGIWFREQ; | |
a2c3fdb9 | 978 | iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel; |
91980990 GKH |
979 | iwe.u.freq.e = 0; |
980 | iwe.u.freq.i = 0; | |
981 | ||
982 | previous_ev = current_ev; | |
66cd8d6e BZ |
983 | current_ev = |
984 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
985 | IW_EV_FREQ_LEN); | |
986 | if (current_ev == previous_ev) | |
987 | return -E2BIG; | |
988 | ||
9f548a2a BZ |
989 | /*Add quality statistics */ |
990 | /*================================ */ | |
66cd8d6e BZ |
991 | memset(&iwe, 0, sizeof(iwe)); |
992 | iwe.cmd = IWEVQUAL; | |
993 | iwe.u.qual.level = 0; | |
994 | iwe.u.qual.noise = 0; | |
995 | set_quality(pAdapter, &iwe.u.qual, | |
996 | pAdapter->ScanTab.BssEntry[i].Rssi); | |
997 | current_ev = | |
998 | iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
999 | IW_EV_QUAL_LEN); | |
1000 | if (current_ev == previous_ev) | |
1001 | return -E2BIG; | |
91980990 | 1002 | |
9f548a2a BZ |
1003 | /*Encyption key */ |
1004 | /*================================ */ | |
91980990 GKH |
1005 | memset(&iwe, 0, sizeof(iwe)); |
1006 | iwe.cmd = SIOCGIWENCODE; | |
66cd8d6e BZ |
1007 | if (CAP_IS_PRIVACY_ON |
1008 | (pAdapter->ScanTab.BssEntry[i].CapabilityInfo)) | |
1009 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
91980990 GKH |
1010 | else |
1011 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
1012 | ||
66cd8d6e BZ |
1013 | previous_ev = current_ev; |
1014 | current_ev = | |
1015 | iwe_stream_add_point(info, current_ev, end_buf, &iwe, | |
1016 | (char *)pAdapter-> | |
1017 | SharedKey[BSS0][(iwe.u.data. | |
1018 | flags & | |
1019 | IW_ENCODE_INDEX) - | |
1020 | 1].Key); | |
1021 | if (current_ev == previous_ev) | |
1022 | return -E2BIG; | |
91980990 | 1023 | |
9f548a2a BZ |
1024 | /*Bit Rate */ |
1025 | /*================================ */ | |
66cd8d6e | 1026 | if (pAdapter->ScanTab.BssEntry[i].SupRateLen) { |
51126deb | 1027 | u8 tmpRate = |
66cd8d6e BZ |
1028 | pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter-> |
1029 | ScanTab. | |
1030 | BssEntry[i]. | |
1031 | SupRateLen - | |
1032 | 1]; | |
91980990 GKH |
1033 | memset(&iwe, 0, sizeof(iwe)); |
1034 | iwe.cmd = SIOCGIWRATE; | |
66cd8d6e BZ |
1035 | current_val = current_ev + IW_EV_LCP_LEN; |
1036 | if (tmpRate == 0x82) | |
1037 | iwe.u.bitrate.value = 1 * 1000000; | |
1038 | else if (tmpRate == 0x84) | |
1039 | iwe.u.bitrate.value = 2 * 1000000; | |
1040 | else if (tmpRate == 0x8B) | |
1041 | iwe.u.bitrate.value = 5.5 * 1000000; | |
1042 | else if (tmpRate == 0x96) | |
1043 | iwe.u.bitrate.value = 11 * 1000000; | |
1044 | else | |
1045 | iwe.u.bitrate.value = (tmpRate / 2) * 1000000; | |
1046 | ||
1047 | if (tmpRate == 0x6c | |
1048 | && pAdapter->ScanTab.BssEntry[i].HtCapabilityLen > | |
1049 | 0) { | |
4dbb8e57 | 1050 | int rate_count = ARRAY_SIZE(ralinkrate); |
62eb734b | 1051 | struct rt_ht_cap_info capInfo = |
66cd8d6e BZ |
1052 | pAdapter->ScanTab.BssEntry[i].HtCapability. |
1053 | HtCapInfo; | |
1054 | int shortGI = | |
1055 | capInfo.ChannelWidth ? capInfo. | |
1056 | ShortGIfor40 : capInfo.ShortGIfor20; | |
1057 | int maxMCS = | |
1058 | pAdapter->ScanTab.BssEntry[i].HtCapability. | |
1059 | MCSSet[1] ? 15 : 7; | |
1060 | int rate_index = | |
51126deb BZ |
1061 | 12 + ((u8)capInfo.ChannelWidth * 24) + |
1062 | ((u8)shortGI * 48) + ((u8)maxMCS); | |
4dbb8e57 | 1063 | |
ca97b838 BZ |
1064 | if (rate_index < 0) |
1065 | rate_index = 0; | |
4dbb8e57 DC |
1066 | if (rate_index >= rate_count) |
1067 | rate_index = rate_count - 1; | |
66cd8d6e BZ |
1068 | iwe.u.bitrate.value = |
1069 | ralinkrate[rate_index] * 500000; | |
ca97b838 BZ |
1070 | } |
1071 | ||
91980990 | 1072 | iwe.u.bitrate.disabled = 0; |
27eff3bf | 1073 | current_val = iwe_stream_add_value(info, current_ev, |
66cd8d6e BZ |
1074 | current_val, end_buf, |
1075 | &iwe, | |
1076 | IW_EV_PARAM_LEN); | |
91980990 | 1077 | |
66cd8d6e BZ |
1078 | if ((current_val - current_ev) > IW_EV_LCP_LEN) |
1079 | current_ev = current_val; | |
1080 | else | |
1081 | return -E2BIG; | |
1082 | } | |
9f548a2a | 1083 | /*WPA IE */ |
66cd8d6e | 1084 | if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0) { |
91980990 GKH |
1085 | memset(&iwe, 0, sizeof(iwe)); |
1086 | memset(&custom[0], 0, MAX_CUSTOM_LEN); | |
66cd8d6e BZ |
1087 | memcpy(custom, |
1088 | &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]), | |
1089 | pAdapter->ScanTab.BssEntry[i].WpaIE.IELen); | |
91980990 | 1090 | iwe.cmd = IWEVGENIE; |
66cd8d6e BZ |
1091 | iwe.u.data.length = |
1092 | pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; | |
1093 | current_ev = | |
1094 | iwe_stream_add_point(info, current_ev, end_buf, | |
1095 | &iwe, custom); | |
91980990 | 1096 | if (current_ev == previous_ev) |
e82bf85e | 1097 | return -E2BIG; |
91980990 | 1098 | } |
9f548a2a | 1099 | /*WPA2 IE */ |
66cd8d6e BZ |
1100 | if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0) { |
1101 | memset(&iwe, 0, sizeof(iwe)); | |
91980990 | 1102 | memset(&custom[0], 0, MAX_CUSTOM_LEN); |
66cd8d6e BZ |
1103 | memcpy(custom, |
1104 | &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]), | |
1105 | pAdapter->ScanTab.BssEntry[i].RsnIE.IELen); | |
91980990 | 1106 | iwe.cmd = IWEVGENIE; |
66cd8d6e BZ |
1107 | iwe.u.data.length = |
1108 | pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; | |
1109 | current_ev = | |
1110 | iwe_stream_add_point(info, current_ev, end_buf, | |
1111 | &iwe, custom); | |
91980990 | 1112 | if (current_ev == previous_ev) |
e82bf85e | 1113 | return -E2BIG; |
66cd8d6e | 1114 | } |
91980990 GKH |
1115 | } |
1116 | ||
1117 | data->length = current_ev - extra; | |
66cd8d6e BZ |
1118 | pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE; |
1119 | DBGPRINT(RT_DEBUG_ERROR, | |
1120 | ("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n", | |
1121 | i, pAdapter->ScanTab.BssNr, data->length)); | |
91980990 GKH |
1122 | return 0; |
1123 | } | |
91980990 GKH |
1124 | |
1125 | int rt_ioctl_siwessid(struct net_device *dev, | |
66cd8d6e BZ |
1126 | struct iw_request_info *info, |
1127 | struct iw_point *data, char *essid) | |
91980990 | 1128 | { |
62eb734b | 1129 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1130 | |
1131 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1132 | |
9f548a2a | 1133 | /*check if the interface is down */ |
66cd8d6e BZ |
1134 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1135 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1136 | return -ENETDOWN; | |
1137 | } | |
91980990 | 1138 | |
66cd8d6e | 1139 | if (data->flags) { |
51126deb | 1140 | char *pSsidString = NULL; |
91980990 | 1141 | |
9f548a2a | 1142 | /* Includes null character. */ |
91980990 GKH |
1143 | if (data->length > (IW_ESSID_MAX_SIZE + 1)) |
1144 | return -E2BIG; | |
1145 | ||
66cd8d6e BZ |
1146 | pSsidString = kmalloc(MAX_LEN_OF_SSID + 1, MEM_ALLOC_FLAG); |
1147 | if (pSsidString) { | |
1148 | NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID + 1); | |
91980990 GKH |
1149 | NdisMoveMemory(pSsidString, essid, data->length); |
1150 | if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE) | |
1151 | return -EINVAL; | |
66cd8d6e | 1152 | } else |
91980990 | 1153 | return -ENOMEM; |
66cd8d6e | 1154 | } else { |
9f548a2a | 1155 | /* ANY ssid */ |
91980990 GKH |
1156 | if (Set_SSID_Proc(pAdapter, "") == FALSE) |
1157 | return -EINVAL; | |
66cd8d6e | 1158 | } |
91980990 GKH |
1159 | return 0; |
1160 | } | |
1161 | ||
1162 | int rt_ioctl_giwessid(struct net_device *dev, | |
66cd8d6e BZ |
1163 | struct iw_request_info *info, |
1164 | struct iw_point *data, char *essid) | |
91980990 | 1165 | { |
62eb734b | 1166 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1167 | |
1168 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 GKH |
1169 | |
1170 | data->flags = 1; | |
66cd8d6e BZ |
1171 | if (MONITOR_ON(pAdapter)) { |
1172 | data->length = 0; | |
1173 | return 0; | |
1174 | } | |
91980990 | 1175 | |
66cd8d6e BZ |
1176 | if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) { |
1177 | DBGPRINT(RT_DEBUG_TRACE, ("MediaState is connected\n")); | |
91980990 | 1178 | data->length = pAdapter->CommonCfg.SsidLen; |
66cd8d6e BZ |
1179 | memcpy(essid, pAdapter->CommonCfg.Ssid, |
1180 | pAdapter->CommonCfg.SsidLen); | |
91980990 | 1181 | } |
ca97b838 | 1182 | #ifdef RTMP_MAC_USB |
9f548a2a | 1183 | /* Add for RT2870 */ |
66cd8d6e BZ |
1184 | else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) { |
1185 | data->length = pAdapter->CommonCfg.SsidLen; | |
1186 | memcpy(essid, pAdapter->CommonCfg.Ssid, | |
1187 | pAdapter->CommonCfg.SsidLen); | |
3a32ed12 | 1188 | } |
9f548a2a BZ |
1189 | #endif /* RTMP_MAC_USB // */ |
1190 | else { /*the ANY ssid was specified */ | |
66cd8d6e BZ |
1191 | data->length = 0; |
1192 | DBGPRINT(RT_DEBUG_TRACE, | |
1193 | ("MediaState is not connected, ess\n")); | |
91980990 GKH |
1194 | } |
1195 | ||
1196 | return 0; | |
1197 | ||
1198 | } | |
1199 | ||
1200 | int rt_ioctl_siwnickn(struct net_device *dev, | |
66cd8d6e BZ |
1201 | struct iw_request_info *info, |
1202 | struct iw_point *data, char *nickname) | |
91980990 | 1203 | { |
62eb734b | 1204 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1205 | |
1206 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1207 | |
9f548a2a | 1208 | /*check if the interface is down */ |
66cd8d6e BZ |
1209 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1210 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1211 | return -ENETDOWN; | |
1212 | } | |
91980990 GKH |
1213 | |
1214 | if (data->length > IW_ESSID_MAX_SIZE) | |
1215 | return -EINVAL; | |
1216 | ||
1217 | memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1); | |
1218 | memcpy(pAdapter->nickname, nickname, data->length); | |
1219 | ||
91980990 GKH |
1220 | return 0; |
1221 | } | |
1222 | ||
1223 | int rt_ioctl_giwnickn(struct net_device *dev, | |
66cd8d6e BZ |
1224 | struct iw_request_info *info, |
1225 | struct iw_point *data, char *nickname) | |
91980990 | 1226 | { |
62eb734b | 1227 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 | 1228 | |
ca97b838 BZ |
1229 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1230 | ||
51126deb BZ |
1231 | if (data->length > strlen((char *)pAdapter->nickname) + 1) |
1232 | data->length = strlen((char *)pAdapter->nickname) + 1; | |
91980990 | 1233 | if (data->length > 0) { |
66cd8d6e BZ |
1234 | memcpy(nickname, pAdapter->nickname, data->length - 1); |
1235 | nickname[data->length - 1] = '\0'; | |
91980990 GKH |
1236 | } |
1237 | return 0; | |
1238 | } | |
1239 | ||
1240 | int rt_ioctl_siwrts(struct net_device *dev, | |
66cd8d6e BZ |
1241 | struct iw_request_info *info, |
1242 | struct iw_param *rts, char *extra) | |
91980990 | 1243 | { |
62eb734b | 1244 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
1245 | u16 val; |
1246 | ||
ca97b838 BZ |
1247 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1248 | ||
9f548a2a | 1249 | /*check if the interface is down */ |
66cd8d6e BZ |
1250 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1251 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1252 | return -ENETDOWN; | |
1253 | } | |
91980990 GKH |
1254 | |
1255 | if (rts->disabled) | |
1256 | val = MAX_RTS_THRESHOLD; | |
1257 | else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD) | |
1258 | return -EINVAL; | |
1259 | else if (rts->value == 0) | |
66cd8d6e | 1260 | val = MAX_RTS_THRESHOLD; |
91980990 GKH |
1261 | else |
1262 | val = rts->value; | |
1263 | ||
1264 | if (val != pAdapter->CommonCfg.RtsThreshold) | |
1265 | pAdapter->CommonCfg.RtsThreshold = val; | |
1266 | ||
1267 | return 0; | |
1268 | } | |
1269 | ||
1270 | int rt_ioctl_giwrts(struct net_device *dev, | |
66cd8d6e BZ |
1271 | struct iw_request_info *info, |
1272 | struct iw_param *rts, char *extra) | |
91980990 | 1273 | { |
62eb734b | 1274 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1275 | |
1276 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1277 | |
9f548a2a | 1278 | /*check if the interface is down */ |
66cd8d6e BZ |
1279 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1280 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1281 | return -ENETDOWN; | |
1282 | } | |
91980990 GKH |
1283 | |
1284 | rts->value = pAdapter->CommonCfg.RtsThreshold; | |
1285 | rts->disabled = (rts->value == MAX_RTS_THRESHOLD); | |
1286 | rts->fixed = 1; | |
1287 | ||
1288 | return 0; | |
1289 | } | |
1290 | ||
1291 | int rt_ioctl_siwfrag(struct net_device *dev, | |
66cd8d6e BZ |
1292 | struct iw_request_info *info, |
1293 | struct iw_param *frag, char *extra) | |
91980990 | 1294 | { |
62eb734b | 1295 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
1296 | u16 val; |
1297 | ||
ca97b838 BZ |
1298 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1299 | ||
9f548a2a | 1300 | /*check if the interface is down */ |
66cd8d6e BZ |
1301 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1302 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1303 | return -ENETDOWN; | |
1304 | } | |
91980990 GKH |
1305 | |
1306 | if (frag->disabled) | |
1307 | val = MAX_FRAG_THRESHOLD; | |
66cd8d6e BZ |
1308 | else if (frag->value >= MIN_FRAG_THRESHOLD |
1309 | && frag->value <= MAX_FRAG_THRESHOLD) | |
1310 | val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */ | |
91980990 | 1311 | else if (frag->value == 0) |
66cd8d6e | 1312 | val = MAX_FRAG_THRESHOLD; |
91980990 GKH |
1313 | else |
1314 | return -EINVAL; | |
1315 | ||
1316 | pAdapter->CommonCfg.FragmentThreshold = val; | |
1317 | return 0; | |
1318 | } | |
1319 | ||
1320 | int rt_ioctl_giwfrag(struct net_device *dev, | |
66cd8d6e BZ |
1321 | struct iw_request_info *info, |
1322 | struct iw_param *frag, char *extra) | |
91980990 | 1323 | { |
62eb734b | 1324 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1325 | |
1326 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1327 | |
9f548a2a | 1328 | /*check if the interface is down */ |
66cd8d6e BZ |
1329 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1330 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1331 | return -ENETDOWN; | |
1332 | } | |
91980990 GKH |
1333 | |
1334 | frag->value = pAdapter->CommonCfg.FragmentThreshold; | |
1335 | frag->disabled = (frag->value == MAX_FRAG_THRESHOLD); | |
1336 | frag->fixed = 1; | |
1337 | ||
1338 | return 0; | |
1339 | } | |
1340 | ||
1341 | #define MAX_WEP_KEY_SIZE 13 | |
1342 | #define MIN_WEP_KEY_SIZE 5 | |
1343 | int rt_ioctl_siwencode(struct net_device *dev, | |
66cd8d6e BZ |
1344 | struct iw_request_info *info, |
1345 | struct iw_point *erq, char *extra) | |
91980990 | 1346 | { |
62eb734b | 1347 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1348 | |
1349 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1350 | |
9f548a2a | 1351 | /*check if the interface is down */ |
66cd8d6e BZ |
1352 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1353 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1354 | return -ENETDOWN; | |
1355 | } | |
1356 | ||
1357 | if ((erq->length == 0) && (erq->flags & IW_ENCODE_DISABLED)) { | |
91980990 GKH |
1358 | pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; |
1359 | pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; | |
1360 | pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; | |
66cd8d6e BZ |
1361 | pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; |
1362 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; | |
1363 | goto done; | |
1364 | } else if (erq->flags & IW_ENCODE_RESTRICTED | |
1365 | || erq->flags & IW_ENCODE_OPEN) { | |
9f548a2a | 1366 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ |
91980990 GKH |
1367 | STA_PORT_SECURED(pAdapter); |
1368 | pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled; | |
1369 | pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled; | |
1370 | pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled; | |
66cd8d6e | 1371 | pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; |
91980990 GKH |
1372 | if (erq->flags & IW_ENCODE_RESTRICTED) |
1373 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared; | |
66cd8d6e | 1374 | else |
91980990 | 1375 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; |
91980990 GKH |
1376 | } |
1377 | ||
66cd8d6e | 1378 | if (erq->length > 0) { |
91980990 GKH |
1379 | int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1; |
1380 | /* Check the size of the key */ | |
66cd8d6e | 1381 | if (erq->length > MAX_WEP_KEY_SIZE) { |
91980990 GKH |
1382 | return -EINVAL; |
1383 | } | |
1384 | /* Check key index */ | |
66cd8d6e BZ |
1385 | if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS)) { |
1386 | DBGPRINT(RT_DEBUG_TRACE, | |
1387 | ("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n", | |
1388 | keyIdx, pAdapter->StaCfg.DefaultKeyId)); | |
91980990 | 1389 | |
9f548a2a | 1390 | /*Using default key */ |
91980990 | 1391 | keyIdx = pAdapter->StaCfg.DefaultKeyId; |
66cd8d6e | 1392 | } else |
ca97b838 | 1393 | pAdapter->StaCfg.DefaultKeyId = keyIdx; |
91980990 | 1394 | |
66cd8d6e BZ |
1395 | NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16); |
1396 | ||
1397 | if (erq->length == MAX_WEP_KEY_SIZE) { | |
1398 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = | |
1399 | MAX_WEP_KEY_SIZE; | |
1400 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = | |
1401 | CIPHER_WEP128; | |
1402 | } else if (erq->length == MIN_WEP_KEY_SIZE) { | |
1403 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = | |
1404 | MIN_WEP_KEY_SIZE; | |
1405 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = | |
1406 | CIPHER_WEP64; | |
1407 | } else | |
91980990 GKH |
1408 | /* Disable the key */ |
1409 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0; | |
1410 | ||
1411 | /* Check if the key is not marked as invalid */ | |
66cd8d6e | 1412 | if (!(erq->flags & IW_ENCODE_NOKEY)) { |
91980990 | 1413 | /* Copy the key in the driver */ |
66cd8d6e BZ |
1414 | NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, |
1415 | extra, erq->length); | |
1416 | } | |
1417 | } else { | |
91980990 GKH |
1418 | /* Do we want to just set the transmit key index ? */ |
1419 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; | |
66cd8d6e | 1420 | if ((index >= 0) && (index < 4)) { |
91980990 | 1421 | pAdapter->StaCfg.DefaultKeyId = index; |
66cd8d6e | 1422 | } else |
91980990 | 1423 | /* Don't complain if only change the mode */ |
66cd8d6e BZ |
1424 | if (!(erq->flags & IW_ENCODE_MODE)) |
1425 | return -EINVAL; | |
1426 | } | |
91980990 GKH |
1427 | |
1428 | done: | |
66cd8d6e BZ |
1429 | DBGPRINT(RT_DEBUG_TRACE, |
1430 | ("==>rt_ioctl_siwencode::erq->flags=%x\n", erq->flags)); | |
1431 | DBGPRINT(RT_DEBUG_TRACE, | |
1432 | ("==>rt_ioctl_siwencode::AuthMode=%x\n", | |
1433 | pAdapter->StaCfg.AuthMode)); | |
1434 | DBGPRINT(RT_DEBUG_TRACE, | |
1435 | ("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n", | |
1436 | pAdapter->StaCfg.DefaultKeyId, | |
1437 | pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. | |
1438 | KeyLen)); | |
1439 | DBGPRINT(RT_DEBUG_TRACE, | |
1440 | ("==>rt_ioctl_siwencode::WepStatus=%x\n", | |
1441 | pAdapter->StaCfg.WepStatus)); | |
91980990 GKH |
1442 | return 0; |
1443 | } | |
1444 | ||
1445 | int | |
1446 | rt_ioctl_giwencode(struct net_device *dev, | |
66cd8d6e BZ |
1447 | struct iw_request_info *info, |
1448 | struct iw_point *erq, char *key) | |
91980990 GKH |
1449 | { |
1450 | int kid; | |
62eb734b | 1451 | struct rt_rtmp_adapter *pAdapter = NULL; |
ca97b838 BZ |
1452 | |
1453 | GET_PAD_FROM_NET_DEV(pAdapter, dev); | |
91980990 | 1454 | |
9f548a2a | 1455 | /*check if the interface is down */ |
66cd8d6e BZ |
1456 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1457 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1458 | return -ENETDOWN; | |
91980990 GKH |
1459 | } |
1460 | ||
1461 | kid = erq->flags & IW_ENCODE_INDEX; | |
66cd8d6e BZ |
1462 | DBGPRINT(RT_DEBUG_TRACE, |
1463 | ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX)); | |
91980990 | 1464 | |
66cd8d6e | 1465 | if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) { |
91980990 GKH |
1466 | erq->length = 0; |
1467 | erq->flags = IW_ENCODE_DISABLED; | |
66cd8d6e | 1468 | } else if ((kid > 0) && (kid <= 4)) { |
9f548a2a | 1469 | /* copy wep key */ |
66cd8d6e BZ |
1470 | erq->flags = kid; /* NB: base 1 */ |
1471 | if (erq->length > pAdapter->SharedKey[BSS0][kid - 1].KeyLen) | |
1472 | erq->length = pAdapter->SharedKey[BSS0][kid - 1].KeyLen; | |
1473 | memcpy(key, pAdapter->SharedKey[BSS0][kid - 1].Key, | |
1474 | erq->length); | |
9f548a2a BZ |
1475 | /*if ((kid == pAdapter->PortCfg.DefaultKeyId)) */ |
1476 | /*erq->flags |= IW_ENCODE_ENABLED; */ /* XXX */ | |
91980990 | 1477 | if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) |
66cd8d6e | 1478 | erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ |
91980990 | 1479 | else |
66cd8d6e | 1480 | erq->flags |= IW_ENCODE_OPEN; /* XXX */ |
91980990 | 1481 | |
66cd8d6e | 1482 | } else if (kid == 0) { |
91980990 | 1483 | if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) |
66cd8d6e | 1484 | erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ |
91980990 | 1485 | else |
66cd8d6e BZ |
1486 | erq->flags |= IW_ENCODE_OPEN; /* XXX */ |
1487 | erq->length = | |
1488 | pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. | |
1489 | KeyLen; | |
1490 | memcpy(key, | |
1491 | pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. | |
1492 | Key, erq->length); | |
9f548a2a | 1493 | /* copy default key ID */ |
91980990 | 1494 | if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) |
66cd8d6e | 1495 | erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ |
91980990 | 1496 | else |
66cd8d6e BZ |
1497 | erq->flags |= IW_ENCODE_OPEN; /* XXX */ |
1498 | erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */ | |
91980990 GKH |
1499 | erq->flags |= IW_ENCODE_ENABLED; /* XXX */ |
1500 | } | |
1501 | ||
1502 | return 0; | |
1503 | ||
1504 | } | |
1505 | ||
62eb734b | 1506 | void getBaInfo(struct rt_rtmp_adapter *pAd, char *pOutBuf) |
91980990 | 1507 | { |
51126deb | 1508 | int i, j; |
62eb734b BZ |
1509 | struct rt_ba_ori_entry *pOriBAEntry; |
1510 | struct rt_ba_rec_entry *pRecBAEntry; | |
91980990 | 1511 | |
66cd8d6e | 1512 | for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) { |
62eb734b | 1513 | struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[i]; |
66cd8d6e BZ |
1514 | if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) |
1515 | && (pEntry->Sst == SST_ASSOC)) | |
1516 | || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh)) { | |
1517 | sprintf(pOutBuf + strlen(pOutBuf), | |
1518 | "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n", | |
1519 | pEntry->Addr[0], pEntry->Addr[1], | |
1520 | pEntry->Addr[2], pEntry->Addr[3], | |
1521 | pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid); | |
91980990 GKH |
1522 | |
1523 | sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf); | |
66cd8d6e BZ |
1524 | for (j = 0; j < NUM_OF_TID; j++) { |
1525 | if (pEntry->BARecWcidArray[j] != 0) { | |
1526 | pRecBAEntry = | |
1527 | &pAd->BATable.BARecEntry[pEntry-> | |
1528 | BARecWcidArray | |
1529 | [j]]; | |
1530 | sprintf(pOutBuf + strlen(pOutBuf), | |
1531 | "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", | |
1532 | j, pRecBAEntry->BAWinSize, | |
1533 | pRecBAEntry->LastIndSeq, | |
1534 | pRecBAEntry->list.qlen); | |
91980990 GKH |
1535 | } |
1536 | } | |
1537 | sprintf(pOutBuf, "%s\n", pOutBuf); | |
1538 | ||
1539 | sprintf(pOutBuf, "%s[Originator]\n", pOutBuf); | |
66cd8d6e BZ |
1540 | for (j = 0; j < NUM_OF_TID; j++) { |
1541 | if (pEntry->BAOriWcidArray[j] != 0) { | |
1542 | pOriBAEntry = | |
1543 | &pAd->BATable.BAOriEntry[pEntry-> | |
1544 | BAOriWcidArray | |
1545 | [j]]; | |
1546 | sprintf(pOutBuf + strlen(pOutBuf), | |
1547 | "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", | |
1548 | j, pOriBAEntry->BAWinSize, | |
1549 | pOriBAEntry->Sequence, | |
1550 | pEntry->TxSeq[j]); | |
91980990 GKH |
1551 | } |
1552 | } | |
1553 | sprintf(pOutBuf, "%s\n\n", pOutBuf); | |
1554 | } | |
66cd8d6e BZ |
1555 | if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30)) |
1556 | break; | |
91980990 GKH |
1557 | } |
1558 | ||
1559 | return; | |
1560 | } | |
91980990 | 1561 | |
91980990 | 1562 | int rt_ioctl_siwmlme(struct net_device *dev, |
66cd8d6e BZ |
1563 | struct iw_request_info *info, |
1564 | union iwreq_data *wrqu, char *extra) | |
91980990 | 1565 | { |
62eb734b | 1566 | struct rt_rtmp_adapter *pAd = NULL; |
91980990 | 1567 | struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer; |
62eb734b BZ |
1568 | struct rt_mlme_queue_elem MsgElem; |
1569 | struct rt_mlme_disassoc_req DisAssocReq; | |
1570 | struct rt_mlme_deauth_req DeAuthReq; | |
91980990 | 1571 | |
ca97b838 BZ |
1572 | GET_PAD_FROM_NET_DEV(pAd, dev); |
1573 | ||
d599edca | 1574 | DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__)); |
91980990 GKH |
1575 | |
1576 | if (pMlme == NULL) | |
1577 | return -EINVAL; | |
1578 | ||
66cd8d6e | 1579 | switch (pMlme->cmd) { |
91980990 | 1580 | #ifdef IW_MLME_DEAUTH |
66cd8d6e BZ |
1581 | case IW_MLME_DEAUTH: |
1582 | DBGPRINT(RT_DEBUG_TRACE, | |
1583 | ("====> %s - IW_MLME_DEAUTH\n", __func__)); | |
1584 | COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid); | |
1585 | DeAuthReq.Reason = pMlme->reason_code; | |
62eb734b | 1586 | MsgElem.MsgLen = sizeof(struct rt_mlme_deauth_req); |
66cd8d6e | 1587 | NdisMoveMemory(MsgElem.Msg, &DeAuthReq, |
62eb734b | 1588 | sizeof(struct rt_mlme_deauth_req)); |
66cd8d6e BZ |
1589 | MlmeDeauthReqAction(pAd, &MsgElem); |
1590 | if (INFRA_ON(pAd)) { | |
1591 | LinkDown(pAd, FALSE); | |
1592 | pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; | |
1593 | } | |
1594 | break; | |
9f548a2a | 1595 | #endif /* IW_MLME_DEAUTH // */ |
91980990 | 1596 | #ifdef IW_MLME_DISASSOC |
66cd8d6e BZ |
1597 | case IW_MLME_DISASSOC: |
1598 | DBGPRINT(RT_DEBUG_TRACE, | |
1599 | ("====> %s - IW_MLME_DISASSOC\n", __func__)); | |
1600 | COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid); | |
1601 | DisAssocReq.Reason = pMlme->reason_code; | |
1602 | ||
1603 | MsgElem.Machine = ASSOC_STATE_MACHINE; | |
1604 | MsgElem.MsgType = MT2_MLME_DISASSOC_REQ; | |
62eb734b | 1605 | MsgElem.MsgLen = sizeof(struct rt_mlme_disassoc_req); |
66cd8d6e | 1606 | NdisMoveMemory(MsgElem.Msg, &DisAssocReq, |
62eb734b | 1607 | sizeof(struct rt_mlme_disassoc_req)); |
66cd8d6e BZ |
1608 | |
1609 | pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC; | |
1610 | MlmeDisassocReqAction(pAd, &MsgElem); | |
1611 | break; | |
9f548a2a | 1612 | #endif /* IW_MLME_DISASSOC // */ |
66cd8d6e BZ |
1613 | default: |
1614 | DBGPRINT(RT_DEBUG_TRACE, | |
1615 | ("====> %s - Unknow Command\n", __func__)); | |
1616 | break; | |
91980990 GKH |
1617 | } |
1618 | ||
1619 | return 0; | |
1620 | } | |
91980990 | 1621 | |
91980990 | 1622 | int rt_ioctl_siwauth(struct net_device *dev, |
66cd8d6e BZ |
1623 | struct iw_request_info *info, |
1624 | union iwreq_data *wrqu, char *extra) | |
91980990 | 1625 | { |
62eb734b | 1626 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
1627 | struct iw_param *param = &wrqu->param; |
1628 | ||
ca97b838 BZ |
1629 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1630 | ||
9f548a2a | 1631 | /*check if the interface is down */ |
66cd8d6e BZ |
1632 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1633 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1634 | return -ENETDOWN; | |
91980990 GKH |
1635 | } |
1636 | switch (param->flags & IW_AUTH_INDEX) { | |
66cd8d6e BZ |
1637 | case IW_AUTH_WPA_VERSION: |
1638 | if (param->value == IW_AUTH_WPA_VERSION_WPA) { | |
1639 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK; | |
1640 | if (pAdapter->StaCfg.BssType == BSS_ADHOC) | |
1641 | pAdapter->StaCfg.AuthMode = | |
1642 | Ndis802_11AuthModeWPANone; | |
1643 | } else if (param->value == IW_AUTH_WPA_VERSION_WPA2) | |
1644 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK; | |
1645 | ||
1646 | DBGPRINT(RT_DEBUG_TRACE, | |
1647 | ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", | |
1648 | __func__, param->value)); | |
1649 | break; | |
1650 | case IW_AUTH_CIPHER_PAIRWISE: | |
1651 | if (param->value == IW_AUTH_CIPHER_NONE) { | |
1652 | pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; | |
1653 | pAdapter->StaCfg.OrigWepStatus = | |
1654 | pAdapter->StaCfg.WepStatus; | |
1655 | pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; | |
1656 | } else if (param->value == IW_AUTH_CIPHER_WEP40 || | |
1657 | param->value == IW_AUTH_CIPHER_WEP104) { | |
1658 | pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled; | |
1659 | pAdapter->StaCfg.OrigWepStatus = | |
1660 | pAdapter->StaCfg.WepStatus; | |
1661 | pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled; | |
1662 | pAdapter->StaCfg.IEEE8021X = FALSE; | |
1663 | } else if (param->value == IW_AUTH_CIPHER_TKIP) { | |
1664 | pAdapter->StaCfg.WepStatus = | |
1665 | Ndis802_11Encryption2Enabled; | |
1666 | pAdapter->StaCfg.OrigWepStatus = | |
1667 | pAdapter->StaCfg.WepStatus; | |
1668 | pAdapter->StaCfg.PairCipher = | |
1669 | Ndis802_11Encryption2Enabled; | |
1670 | } else if (param->value == IW_AUTH_CIPHER_CCMP) { | |
1671 | pAdapter->StaCfg.WepStatus = | |
1672 | Ndis802_11Encryption3Enabled; | |
1673 | pAdapter->StaCfg.OrigWepStatus = | |
1674 | pAdapter->StaCfg.WepStatus; | |
1675 | pAdapter->StaCfg.PairCipher = | |
1676 | Ndis802_11Encryption3Enabled; | |
1677 | } | |
1678 | DBGPRINT(RT_DEBUG_TRACE, | |
1679 | ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", | |
1680 | __func__, param->value)); | |
1681 | break; | |
1682 | case IW_AUTH_CIPHER_GROUP: | |
1683 | if (param->value == IW_AUTH_CIPHER_NONE) { | |
1684 | pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; | |
1685 | } else if (param->value == IW_AUTH_CIPHER_WEP40 || | |
1686 | param->value == IW_AUTH_CIPHER_WEP104) { | |
1687 | pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled; | |
1688 | } else if (param->value == IW_AUTH_CIPHER_TKIP) { | |
1689 | pAdapter->StaCfg.GroupCipher = | |
1690 | Ndis802_11Encryption2Enabled; | |
1691 | } else if (param->value == IW_AUTH_CIPHER_CCMP) { | |
1692 | pAdapter->StaCfg.GroupCipher = | |
1693 | Ndis802_11Encryption3Enabled; | |
1694 | } | |
1695 | DBGPRINT(RT_DEBUG_TRACE, | |
1696 | ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", | |
1697 | __func__, param->value)); | |
1698 | break; | |
1699 | case IW_AUTH_KEY_MGMT: | |
1700 | if (param->value == IW_AUTH_KEY_MGMT_802_1X) { | |
1701 | if (pAdapter->StaCfg.AuthMode == | |
1702 | Ndis802_11AuthModeWPAPSK) { | |
1703 | pAdapter->StaCfg.AuthMode = | |
1704 | Ndis802_11AuthModeWPA; | |
1705 | pAdapter->StaCfg.IEEE8021X = FALSE; | |
1706 | } else if (pAdapter->StaCfg.AuthMode == | |
1707 | Ndis802_11AuthModeWPA2PSK) { | |
1708 | pAdapter->StaCfg.AuthMode = | |
1709 | Ndis802_11AuthModeWPA2; | |
1710 | pAdapter->StaCfg.IEEE8021X = FALSE; | |
1711 | } else | |
9f548a2a | 1712 | /* WEP 1x */ |
66cd8d6e BZ |
1713 | pAdapter->StaCfg.IEEE8021X = TRUE; |
1714 | } else if (param->value == 0) { | |
9f548a2a | 1715 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ |
66cd8d6e BZ |
1716 | STA_PORT_SECURED(pAdapter); |
1717 | } | |
1718 | DBGPRINT(RT_DEBUG_TRACE, | |
1719 | ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", | |
1720 | __func__, param->value)); | |
1721 | break; | |
1722 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
1723 | break; | |
1724 | case IW_AUTH_PRIVACY_INVOKED: | |
1725 | /*if (param->value == 0) | |
1726 | { | |
1727 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; | |
1728 | pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; | |
1729 | pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; | |
1730 | pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; | |
1731 | pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; | |
1732 | } */ | |
1733 | DBGPRINT(RT_DEBUG_TRACE, | |
1734 | ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", | |
1735 | __func__, param->value)); | |
1736 | break; | |
1737 | case IW_AUTH_DROP_UNENCRYPTED: | |
1738 | if (param->value != 0) | |
1739 | pAdapter->StaCfg.PortSecured = | |
1740 | WPA_802_1X_PORT_NOT_SECURED; | |
1741 | else { | |
9f548a2a | 1742 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ |
66cd8d6e BZ |
1743 | STA_PORT_SECURED(pAdapter); |
1744 | } | |
1745 | DBGPRINT(RT_DEBUG_TRACE, | |
1746 | ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", | |
1747 | __func__, param->value)); | |
1748 | break; | |
1749 | case IW_AUTH_80211_AUTH_ALG: | |
1750 | if (param->value & IW_AUTH_ALG_SHARED_KEY) { | |
1751 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared; | |
1752 | } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) { | |
1753 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; | |
1754 | } else | |
1755 | return -EINVAL; | |
1756 | DBGPRINT(RT_DEBUG_TRACE, | |
1757 | ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", | |
1758 | __func__, param->value)); | |
1759 | break; | |
1760 | case IW_AUTH_WPA_ENABLED: | |
1761 | DBGPRINT(RT_DEBUG_TRACE, | |
1762 | ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", | |
1763 | __func__, param->value)); | |
1764 | break; | |
1765 | default: | |
1766 | return -EOPNOTSUPP; | |
1767 | } | |
91980990 GKH |
1768 | |
1769 | return 0; | |
1770 | } | |
1771 | ||
1772 | int rt_ioctl_giwauth(struct net_device *dev, | |
66cd8d6e BZ |
1773 | struct iw_request_info *info, |
1774 | union iwreq_data *wrqu, char *extra) | |
91980990 | 1775 | { |
62eb734b | 1776 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
1777 | struct iw_param *param = &wrqu->param; |
1778 | ||
ca97b838 BZ |
1779 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1780 | ||
9f548a2a | 1781 | /*check if the interface is down */ |
66cd8d6e BZ |
1782 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1783 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1784 | return -ENETDOWN; | |
1785 | } | |
91980990 GKH |
1786 | |
1787 | switch (param->flags & IW_AUTH_INDEX) { | |
1788 | case IW_AUTH_DROP_UNENCRYPTED: | |
66cd8d6e BZ |
1789 | param->value = |
1790 | (pAdapter->StaCfg.WepStatus == | |
1791 | Ndis802_11WEPDisabled) ? 0 : 1; | |
91980990 GKH |
1792 | break; |
1793 | ||
1794 | case IW_AUTH_80211_AUTH_ALG: | |
66cd8d6e BZ |
1795 | param->value = |
1796 | (pAdapter->StaCfg.AuthMode == | |
1797 | Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : | |
1798 | IW_AUTH_ALG_OPEN_SYSTEM; | |
91980990 GKH |
1799 | break; |
1800 | ||
1801 | case IW_AUTH_WPA_ENABLED: | |
66cd8d6e BZ |
1802 | param->value = |
1803 | (pAdapter->StaCfg.AuthMode >= | |
1804 | Ndis802_11AuthModeWPA) ? 1 : 0; | |
91980990 GKH |
1805 | break; |
1806 | ||
1807 | default: | |
1808 | return -EOPNOTSUPP; | |
1809 | } | |
66cd8d6e BZ |
1810 | DBGPRINT(RT_DEBUG_TRACE, |
1811 | ("rt_ioctl_giwauth::param->value = %d!\n", param->value)); | |
91980990 GKH |
1812 | return 0; |
1813 | } | |
1814 | ||
62eb734b | 1815 | void fnSetCipherKey(struct rt_rtmp_adapter *pAdapter, |
51126deb BZ |
1816 | int keyIdx, |
1817 | u8 CipherAlg, | |
66cd8d6e | 1818 | IN BOOLEAN bGTK, IN struct iw_encode_ext *ext) |
91980990 | 1819 | { |
62eb734b | 1820 | NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(struct rt_cipher_key)); |
66cd8d6e BZ |
1821 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK; |
1822 | NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, | |
1823 | LEN_TKIP_EK); | |
1824 | NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, | |
1825 | ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK); | |
1826 | NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, | |
1827 | ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, | |
1828 | LEN_TKIP_RXMICK); | |
1829 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg; | |
1830 | ||
9f548a2a | 1831 | /* Update group key information to ASIC Shared Key Table */ |
91980990 | 1832 | AsicAddSharedKeyEntry(pAdapter, |
66cd8d6e BZ |
1833 | BSS0, |
1834 | keyIdx, | |
1835 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, | |
1836 | pAdapter->SharedKey[BSS0][keyIdx].Key, | |
1837 | pAdapter->SharedKey[BSS0][keyIdx].TxMic, | |
1838 | pAdapter->SharedKey[BSS0][keyIdx].RxMic); | |
1839 | ||
1840 | if (bGTK) | |
9f548a2a | 1841 | /* Update ASIC WCID attribute table and IVEIV table */ |
66cd8d6e BZ |
1842 | RTMPAddWcidAttributeEntry(pAdapter, |
1843 | BSS0, | |
1844 | keyIdx, | |
1845 | pAdapter->SharedKey[BSS0][keyIdx]. | |
1846 | CipherAlg, NULL); | |
1847 | else | |
9f548a2a | 1848 | /* Update ASIC WCID attribute table and IVEIV table */ |
66cd8d6e BZ |
1849 | RTMPAddWcidAttributeEntry(pAdapter, |
1850 | BSS0, | |
1851 | keyIdx, | |
1852 | pAdapter->SharedKey[BSS0][keyIdx]. | |
1853 | CipherAlg, | |
1854 | &pAdapter->MacTab. | |
1855 | Content[BSSID_WCID]); | |
91980990 GKH |
1856 | } |
1857 | ||
1858 | int rt_ioctl_siwencodeext(struct net_device *dev, | |
66cd8d6e BZ |
1859 | struct iw_request_info *info, |
1860 | union iwreq_data *wrqu, char *extra) | |
1861 | { | |
62eb734b | 1862 | struct rt_rtmp_adapter *pAdapter = NULL; |
91980990 GKH |
1863 | struct iw_point *encoding = &wrqu->encoding; |
1864 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
66cd8d6e | 1865 | int keyIdx, alg = ext->alg; |
91980990 | 1866 | |
ca97b838 BZ |
1867 | GET_PAD_FROM_NET_DEV(pAdapter, dev); |
1868 | ||
9f548a2a | 1869 | /*check if the interface is down */ |
66cd8d6e BZ |
1870 | if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
1871 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
1872 | return -ENETDOWN; | |
91980990 GKH |
1873 | } |
1874 | ||
66cd8d6e BZ |
1875 | if (encoding->flags & IW_ENCODE_DISABLED) { |
1876 | keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1; | |
9f548a2a | 1877 | /* set BSSID wcid entry of the Pair-wise Key table as no-security mode */ |
66cd8d6e BZ |
1878 | AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID); |
1879 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0; | |
91980990 | 1880 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE; |
51126deb | 1881 | AsicRemoveSharedKeyEntry(pAdapter, 0, (u8)keyIdx); |
66cd8d6e | 1882 | NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], |
62eb734b | 1883 | sizeof(struct rt_cipher_key)); |
66cd8d6e BZ |
1884 | DBGPRINT(RT_DEBUG_TRACE, |
1885 | ("%s::Remove all keys!(encoding->flags = %x)\n", | |
1886 | __func__, encoding->flags)); | |
1887 | } else { | |
9f548a2a | 1888 | /* Get Key Index and convet to our own defined key index */ |
66cd8d6e BZ |
1889 | keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1; |
1890 | if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS)) | |
1891 | return -EINVAL; | |
91980990 | 1892 | |
66cd8d6e BZ |
1893 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { |
1894 | pAdapter->StaCfg.DefaultKeyId = keyIdx; | |
1895 | DBGPRINT(RT_DEBUG_TRACE, | |
1896 | ("%s::DefaultKeyId = %d\n", __func__, | |
1897 | pAdapter->StaCfg.DefaultKeyId)); | |
1898 | } | |
ed291e80 | 1899 | |
66cd8d6e BZ |
1900 | switch (alg) { |
1901 | case IW_ENCODE_ALG_NONE: | |
1902 | DBGPRINT(RT_DEBUG_TRACE, | |
1903 | ("%s::IW_ENCODE_ALG_NONE\n", __func__)); | |
1904 | break; | |
1905 | case IW_ENCODE_ALG_WEP: | |
1906 | DBGPRINT(RT_DEBUG_TRACE, | |
1907 | ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", | |
1908 | __func__, ext->key_len, keyIdx)); | |
1909 | if (ext->key_len == MAX_WEP_KEY_SIZE) { | |
1910 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = | |
1911 | MAX_WEP_KEY_SIZE; | |
1912 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = | |
1913 | CIPHER_WEP128; | |
1914 | } else if (ext->key_len == MIN_WEP_KEY_SIZE) { | |
1915 | pAdapter->SharedKey[BSS0][keyIdx].KeyLen = | |
1916 | MIN_WEP_KEY_SIZE; | |
1917 | pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = | |
1918 | CIPHER_WEP64; | |
1919 | } else | |
1920 | return -EINVAL; | |
ed291e80 | 1921 | |
66cd8d6e BZ |
1922 | NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, |
1923 | 16); | |
1924 | NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, | |
1925 | ext->key, ext->key_len); | |
1926 | if (pAdapter->StaCfg.GroupCipher == | |
1927 | Ndis802_11GroupWEP40Enabled | |
1928 | || pAdapter->StaCfg.GroupCipher == | |
1929 | Ndis802_11GroupWEP104Enabled) { | |
9f548a2a | 1930 | /* Set Group key material to Asic */ |
66cd8d6e BZ |
1931 | AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, |
1932 | pAdapter-> | |
1933 | SharedKey[BSS0][keyIdx]. | |
1934 | CipherAlg, | |
1935 | pAdapter-> | |
1936 | SharedKey[BSS0][keyIdx]. | |
1937 | Key, NULL, NULL); | |
1938 | ||
9f548a2a | 1939 | /* Update WCID attribute table and IVEIV table for this group key table */ |
66cd8d6e BZ |
1940 | RTMPAddWcidAttributeEntry(pAdapter, BSS0, |
1941 | keyIdx, | |
1942 | pAdapter-> | |
1943 | SharedKey[BSS0] | |
1944 | [keyIdx].CipherAlg, | |
1945 | NULL); | |
1946 | ||
1947 | STA_PORT_SECURED(pAdapter); | |
1948 | ||
9f548a2a | 1949 | /* Indicate Connected for GUI */ |
66cd8d6e BZ |
1950 | pAdapter->IndicateMediaState = |
1951 | NdisMediaStateConnected; | |
1952 | } | |
1953 | break; | |
1954 | case IW_ENCODE_ALG_TKIP: | |
1955 | DBGPRINT(RT_DEBUG_TRACE, | |
1956 | ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", | |
1957 | __func__, keyIdx, ext->key_len)); | |
1958 | if (ext->key_len == 32) { | |
1959 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
1960 | fnSetCipherKey(pAdapter, keyIdx, | |
1961 | CIPHER_TKIP, FALSE, ext); | |
1962 | if (pAdapter->StaCfg.AuthMode >= | |
1963 | Ndis802_11AuthModeWPA2) { | |
9f548a2a | 1964 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ |
66cd8d6e BZ |
1965 | STA_PORT_SECURED(pAdapter); |
1966 | pAdapter->IndicateMediaState = | |
1967 | NdisMediaStateConnected; | |
1968 | } | |
1969 | } else if (ext-> | |
1970 | ext_flags & IW_ENCODE_EXT_GROUP_KEY) | |
1971 | { | |
1972 | fnSetCipherKey(pAdapter, keyIdx, | |
1973 | CIPHER_TKIP, TRUE, ext); | |
ed291e80 | 1974 | |
9f548a2a BZ |
1975 | /* set 802.1x port control */ |
1976 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ | |
66cd8d6e BZ |
1977 | STA_PORT_SECURED(pAdapter); |
1978 | pAdapter->IndicateMediaState = | |
1979 | NdisMediaStateConnected; | |
ed291e80 | 1980 | } |
66cd8d6e BZ |
1981 | } else |
1982 | return -EINVAL; | |
1983 | break; | |
1984 | case IW_ENCODE_ALG_CCMP: | |
1985 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
1986 | fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, | |
1987 | FALSE, ext); | |
1988 | if (pAdapter->StaCfg.AuthMode >= | |
1989 | Ndis802_11AuthModeWPA2) | |
9f548a2a | 1990 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ |
66cd8d6e BZ |
1991 | STA_PORT_SECURED(pAdapter); |
1992 | pAdapter->IndicateMediaState = | |
1993 | NdisMediaStateConnected; | |
1994 | } else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { | |
1995 | fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, | |
1996 | TRUE, ext); | |
1997 | ||
9f548a2a BZ |
1998 | /* set 802.1x port control */ |
1999 | /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ | |
66cd8d6e BZ |
2000 | STA_PORT_SECURED(pAdapter); |
2001 | pAdapter->IndicateMediaState = | |
2002 | NdisMediaStateConnected; | |
2003 | } | |
2004 | break; | |
2005 | default: | |
2006 | return -EINVAL; | |
91980990 | 2007 | } |
66cd8d6e | 2008 | } |
91980990 | 2009 | |
66cd8d6e | 2010 | return 0; |
91980990 GKH |
2011 | } |
2012 | ||
2013 | int | |
2014 | rt_ioctl_giwencodeext(struct net_device *dev, | |
66cd8d6e BZ |
2015 | struct iw_request_info *info, |
2016 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2017 | { |
62eb734b | 2018 | struct rt_rtmp_adapter *pAd = NULL; |
51126deb | 2019 | char *pKey = NULL; |
91980990 GKH |
2020 | struct iw_point *encoding = &wrqu->encoding; |
2021 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
2022 | int idx, max_key_len; | |
2023 | ||
ca97b838 BZ |
2024 | GET_PAD_FROM_NET_DEV(pAd, dev); |
2025 | ||
66cd8d6e | 2026 | DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_giwencodeext\n")); |
91980990 GKH |
2027 | |
2028 | max_key_len = encoding->length - sizeof(*ext); | |
2029 | if (max_key_len < 0) | |
2030 | return -EINVAL; | |
2031 | ||
2032 | idx = encoding->flags & IW_ENCODE_INDEX; | |
66cd8d6e | 2033 | if (idx) { |
91980990 GKH |
2034 | if (idx < 1 || idx > 4) |
2035 | return -EINVAL; | |
2036 | idx--; | |
2037 | ||
2038 | if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) || | |
66cd8d6e BZ |
2039 | (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)) { |
2040 | if (idx != pAd->StaCfg.DefaultKeyId) { | |
91980990 GKH |
2041 | ext->key_len = 0; |
2042 | return 0; | |
2043 | } | |
2044 | } | |
66cd8d6e | 2045 | } else |
91980990 GKH |
2046 | idx = pAd->StaCfg.DefaultKeyId; |
2047 | ||
2048 | encoding->flags = idx + 1; | |
2049 | memset(ext, 0, sizeof(*ext)); | |
2050 | ||
2051 | ext->key_len = 0; | |
66cd8d6e BZ |
2052 | switch (pAd->StaCfg.WepStatus) { |
2053 | case Ndis802_11WEPDisabled: | |
2054 | ext->alg = IW_ENCODE_ALG_NONE; | |
2055 | encoding->flags |= IW_ENCODE_DISABLED; | |
2056 | break; | |
2057 | case Ndis802_11WEPEnabled: | |
2058 | ext->alg = IW_ENCODE_ALG_WEP; | |
2059 | if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len) | |
2060 | return -E2BIG; | |
2061 | else { | |
2062 | ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen; | |
51126deb | 2063 | pKey = (char *)& (pAd->SharedKey[BSS0][idx].Key[0]); |
66cd8d6e BZ |
2064 | } |
2065 | break; | |
2066 | case Ndis802_11Encryption2Enabled: | |
2067 | case Ndis802_11Encryption3Enabled: | |
2068 | if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) | |
2069 | ext->alg = IW_ENCODE_ALG_TKIP; | |
2070 | else | |
2071 | ext->alg = IW_ENCODE_ALG_CCMP; | |
91980990 | 2072 | |
66cd8d6e BZ |
2073 | if (max_key_len < 32) |
2074 | return -E2BIG; | |
2075 | else { | |
2076 | ext->key_len = 32; | |
51126deb | 2077 | pKey = (char *)& pAd->StaCfg.PMK[0]; |
66cd8d6e BZ |
2078 | } |
2079 | break; | |
2080 | default: | |
2081 | return -EINVAL; | |
91980990 GKH |
2082 | } |
2083 | ||
66cd8d6e | 2084 | if (ext->key_len && pKey) { |
91980990 GKH |
2085 | encoding->flags |= IW_ENCODE_ENABLED; |
2086 | memcpy(ext->key, pKey, ext->key_len); | |
2087 | } | |
2088 | ||
2089 | return 0; | |
2090 | } | |
2091 | ||
91980990 | 2092 | int rt_ioctl_siwgenie(struct net_device *dev, |
66cd8d6e BZ |
2093 | struct iw_request_info *info, |
2094 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2095 | { |
62eb734b | 2096 | struct rt_rtmp_adapter *pAd = NULL; |
ca97b838 BZ |
2097 | |
2098 | GET_PAD_FROM_NET_DEV(pAd, dev); | |
91980990 | 2099 | |
66cd8d6e | 2100 | DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwgenie\n")); |
ca97b838 | 2101 | pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE; |
91980990 GKH |
2102 | if (wrqu->data.length > MAX_LEN_OF_RSNIE || |
2103 | (wrqu->data.length && extra == NULL)) | |
2104 | return -EINVAL; | |
2105 | ||
66cd8d6e | 2106 | if (wrqu->data.length) { |
91980990 | 2107 | pAd->StaCfg.RSNIE_Len = wrqu->data.length; |
66cd8d6e BZ |
2108 | NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, |
2109 | pAd->StaCfg.RSNIE_Len); | |
ca97b838 | 2110 | pAd->StaCfg.bRSN_IE_FromWpaSupplicant = TRUE; |
66cd8d6e | 2111 | } else { |
91980990 GKH |
2112 | pAd->StaCfg.RSNIE_Len = 0; |
2113 | NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE); | |
2114 | } | |
2115 | ||
2116 | return 0; | |
2117 | } | |
91980990 GKH |
2118 | |
2119 | int rt_ioctl_giwgenie(struct net_device *dev, | |
66cd8d6e BZ |
2120 | struct iw_request_info *info, |
2121 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2122 | { |
62eb734b | 2123 | struct rt_rtmp_adapter *pAd = NULL; |
ca97b838 BZ |
2124 | |
2125 | GET_PAD_FROM_NET_DEV(pAd, dev); | |
91980990 GKH |
2126 | |
2127 | if ((pAd->StaCfg.RSNIE_Len == 0) || | |
66cd8d6e | 2128 | (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)) { |
91980990 GKH |
2129 | wrqu->data.length = 0; |
2130 | return 0; | |
2131 | } | |
2132 | ||
66cd8d6e BZ |
2133 | if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { |
2134 | if (wrqu->data.length < pAd->StaCfg.RSNIE_Len) | |
2135 | return -E2BIG; | |
91980990 | 2136 | |
66cd8d6e BZ |
2137 | wrqu->data.length = pAd->StaCfg.RSNIE_Len; |
2138 | memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len); | |
2139 | } else { | |
51126deb | 2140 | u8 RSNIe = IE_WPA; |
91980990 | 2141 | |
9f548a2a | 2142 | if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) /* ID, Len */ |
91980990 GKH |
2143 | return -E2BIG; |
2144 | wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2; | |
2145 | ||
2146 | if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) || | |
66cd8d6e | 2147 | (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)) |
91980990 GKH |
2148 | RSNIe = IE_RSN; |
2149 | ||
2150 | extra[0] = (char)RSNIe; | |
2151 | extra[1] = pAd->StaCfg.RSNIE_Len; | |
66cd8d6e BZ |
2152 | memcpy(extra + 2, &pAd->StaCfg.RSN_IE[0], |
2153 | pAd->StaCfg.RSNIE_Len); | |
91980990 GKH |
2154 | } |
2155 | ||
2156 | return 0; | |
2157 | } | |
2158 | ||
2159 | int rt_ioctl_siwpmksa(struct net_device *dev, | |
66cd8d6e BZ |
2160 | struct iw_request_info *info, |
2161 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2162 | { |
62eb734b | 2163 | struct rt_rtmp_adapter *pAd = NULL; |
91980990 | 2164 | struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer; |
51126deb | 2165 | int CachedIdx = 0, idx = 0; |
91980990 | 2166 | |
ca97b838 BZ |
2167 | GET_PAD_FROM_NET_DEV(pAd, dev); |
2168 | ||
91980990 GKH |
2169 | if (pPmksa == NULL) |
2170 | return -EINVAL; | |
2171 | ||
66cd8d6e BZ |
2172 | DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwpmksa\n")); |
2173 | switch (pPmksa->cmd) { | |
2174 | case IW_PMKSA_FLUSH: | |
2175 | NdisZeroMemory(pAd->StaCfg.SavedPMK, | |
62eb734b | 2176 | sizeof(struct rt_bssid_info) * PMKID_NO); |
66cd8d6e BZ |
2177 | DBGPRINT(RT_DEBUG_TRACE, |
2178 | ("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n")); | |
2179 | break; | |
2180 | case IW_PMKSA_REMOVE: | |
2181 | for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; | |
2182 | CachedIdx++) { | |
9f548a2a | 2183 | /* compare the BSSID */ |
66cd8d6e BZ |
2184 | if (NdisEqualMemory |
2185 | (pPmksa->bssid.sa_data, | |
2186 | pAd->StaCfg.SavedPMK[CachedIdx].BSSID, | |
2187 | MAC_ADDR_LEN)) { | |
2188 | NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx]. | |
2189 | BSSID, MAC_ADDR_LEN); | |
2190 | NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx]. | |
2191 | PMKID, 16); | |
2192 | for (idx = CachedIdx; | |
2193 | idx < (pAd->StaCfg.SavedPMKNum - 1); | |
2194 | idx++) { | |
2195 | NdisMoveMemory(&pAd->StaCfg. | |
2196 | SavedPMK[idx].BSSID[0], | |
2197 | &pAd->StaCfg. | |
2198 | SavedPMK[idx + | |
2199 | 1].BSSID[0], | |
2200 | MAC_ADDR_LEN); | |
2201 | NdisMoveMemory(&pAd->StaCfg. | |
2202 | SavedPMK[idx].PMKID[0], | |
2203 | &pAd->StaCfg. | |
2204 | SavedPMK[idx + | |
2205 | 1].PMKID[0], | |
2206 | 16); | |
2207 | } | |
2208 | pAd->StaCfg.SavedPMKNum--; | |
2209 | break; | |
2210 | } | |
2211 | } | |
91980990 | 2212 | |
66cd8d6e BZ |
2213 | DBGPRINT(RT_DEBUG_TRACE, |
2214 | ("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n")); | |
2215 | break; | |
2216 | case IW_PMKSA_ADD: | |
2217 | for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; | |
2218 | CachedIdx++) { | |
9f548a2a | 2219 | /* compare the BSSID */ |
66cd8d6e BZ |
2220 | if (NdisEqualMemory |
2221 | (pPmksa->bssid.sa_data, | |
2222 | pAd->StaCfg.SavedPMK[CachedIdx].BSSID, | |
2223 | MAC_ADDR_LEN)) | |
2224 | break; | |
2225 | } | |
2226 | ||
9f548a2a | 2227 | /* Found, replace it */ |
66cd8d6e BZ |
2228 | if (CachedIdx < PMKID_NO) { |
2229 | DBGPRINT(RT_DEBUG_OFF, | |
2230 | ("Update PMKID, idx = %d\n", CachedIdx)); | |
2231 | NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. | |
2232 | BSSID[0], pPmksa->bssid.sa_data, | |
2233 | MAC_ADDR_LEN); | |
2234 | NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. | |
2235 | PMKID[0], pPmksa->pmkid, 16); | |
2236 | pAd->StaCfg.SavedPMKNum++; | |
2237 | } | |
9f548a2a | 2238 | /* Not found, replace the last one */ |
66cd8d6e | 2239 | else { |
9f548a2a | 2240 | /* Randomly replace one */ |
66cd8d6e BZ |
2241 | CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO); |
2242 | DBGPRINT(RT_DEBUG_OFF, | |
2243 | ("Update PMKID, idx = %d\n", CachedIdx)); | |
2244 | NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. | |
2245 | BSSID[0], pPmksa->bssid.sa_data, | |
2246 | MAC_ADDR_LEN); | |
2247 | NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. | |
2248 | PMKID[0], pPmksa->pmkid, 16); | |
2249 | } | |
2250 | ||
2251 | DBGPRINT(RT_DEBUG_TRACE, | |
2252 | ("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n")); | |
2253 | break; | |
2254 | default: | |
2255 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 2256 | ("rt_ioctl_siwpmksa - Unknown Command!\n")); |
66cd8d6e | 2257 | break; |
91980990 GKH |
2258 | } |
2259 | ||
2260 | return 0; | |
2261 | } | |
91980990 | 2262 | |
91980990 | 2263 | int rt_ioctl_siwrate(struct net_device *dev, |
66cd8d6e BZ |
2264 | struct iw_request_info *info, |
2265 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2266 | { |
62eb734b | 2267 | struct rt_rtmp_adapter *pAd = NULL; |
51126deb | 2268 | u32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed; |
91980990 | 2269 | |
ca97b838 BZ |
2270 | GET_PAD_FROM_NET_DEV(pAd, dev); |
2271 | ||
9f548a2a | 2272 | /*check if the interface is down */ |
66cd8d6e BZ |
2273 | if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
2274 | DBGPRINT(RT_DEBUG_TRACE, | |
2275 | ("rt_ioctl_siwrate::Network is down!\n")); | |
2276 | return -ENETDOWN; | |
91980990 GKH |
2277 | } |
2278 | ||
66cd8d6e BZ |
2279 | DBGPRINT(RT_DEBUG_TRACE, |
2280 | ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed)); | |
2281 | /* rate = -1 => auto rate | |
2282 | rate = X, fixed = 1 => (fixed rate X) | |
2283 | */ | |
2284 | if (rate == -1) { | |
9f548a2a | 2285 | /*Auto Rate */ |
91980990 GKH |
2286 | pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; |
2287 | pAd->StaCfg.bAutoTxRateSwitch = TRUE; | |
2288 | if ((pAd->CommonCfg.PhyMode <= PHY_11G) || | |
66cd8d6e BZ |
2289 | (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= |
2290 | MODE_OFDM)) | |
91980990 GKH |
2291 | RTMPSetDesiredRates(pAd, -1); |
2292 | ||
91980990 | 2293 | SetCommonHT(pAd); |
66cd8d6e BZ |
2294 | } else { |
2295 | if (fixed) { | |
2296 | pAd->StaCfg.bAutoTxRateSwitch = FALSE; | |
2297 | if ((pAd->CommonCfg.PhyMode <= PHY_11G) || | |
2298 | (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field. | |
2299 | MODE <= MODE_OFDM)) | |
2300 | RTMPSetDesiredRates(pAd, rate); | |
2301 | else { | |
2302 | pAd->StaCfg.DesiredTransmitSetting.field.MCS = | |
2303 | MCS_AUTO; | |
2304 | SetCommonHT(pAd); | |
2305 | } | |
2306 | DBGPRINT(RT_DEBUG_TRACE, | |
2307 | ("rt_ioctl_siwrate::(HtMcs=%d)\n", | |
2308 | pAd->StaCfg.DesiredTransmitSetting.field. | |
2309 | MCS)); | |
2310 | } else { | |
9f548a2a | 2311 | /* TODO: rate = X, fixed = 0 => (rates <= X) */ |
66cd8d6e BZ |
2312 | return -EOPNOTSUPP; |
2313 | } | |
2314 | } | |
2315 | ||
2316 | return 0; | |
91980990 GKH |
2317 | } |
2318 | ||
2319 | int rt_ioctl_giwrate(struct net_device *dev, | |
66cd8d6e BZ |
2320 | struct iw_request_info *info, |
2321 | union iwreq_data *wrqu, char *extra) | |
91980990 | 2322 | { |
62eb734b | 2323 | struct rt_rtmp_adapter *pAd = NULL; |
66cd8d6e BZ |
2324 | int rate_index = 0, rate_count = 0; |
2325 | HTTRANSMIT_SETTING ht_setting; | |
ca97b838 | 2326 | /* Remove to global variable |
91980990 GKH |
2327 | __s32 ralinkrate[] = |
2328 | {2, 4, 11, 22, // CCK | |
2329 | 12, 18, 24, 36, 48, 72, 96, 108, // OFDM | |
2330 | 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15 | |
2331 | 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23 | |
2332 | 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15 | |
2333 | 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23 | |
2334 | 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15 | |
2335 | 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23 | |
2336 | 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15 | |
2337 | 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23 | |
ca97b838 BZ |
2338 | */ |
2339 | GET_PAD_FROM_NET_DEV(pAd, dev); | |
91980990 | 2340 | |
4dbb8e57 | 2341 | rate_count = ARRAY_SIZE(ralinkrate); |
9f548a2a | 2342 | /*check if the interface is down */ |
66cd8d6e BZ |
2343 | if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
2344 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
2345 | return -ENETDOWN; | |
91980990 GKH |
2346 | } |
2347 | ||
66cd8d6e BZ |
2348 | if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) && |
2349 | (INFRA_ON(pAd)) && | |
2350 | ((pAd->CommonCfg.PhyMode <= PHY_11G) | |
2351 | || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= | |
2352 | MODE_OFDM))) | |
2353 | ht_setting.word = pAd->StaCfg.HTPhyMode.word; | |
2354 | else | |
2355 | ht_setting.word = | |
2356 | pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word; | |
2357 | ||
2358 | if (ht_setting.field.MODE >= MODE_HTMIX) { | |
51126deb | 2359 | /* rate_index = 12 + ((u8)ht_setting.field.BW *16) + ((u8)ht_setting.field.ShortGI *32) + ((u8)ht_setting.field.MCS); */ |
66cd8d6e | 2360 | rate_index = |
51126deb BZ |
2361 | 12 + ((u8)ht_setting.field.BW * 24) + |
2362 | ((u8)ht_setting.field.ShortGI * 48) + | |
2363 | ((u8)ht_setting.field.MCS); | |
66cd8d6e | 2364 | } else if (ht_setting.field.MODE == MODE_OFDM) |
51126deb | 2365 | rate_index = (u8)(ht_setting.field.MCS) + 4; |
66cd8d6e | 2366 | else if (ht_setting.field.MODE == MODE_CCK) |
51126deb | 2367 | rate_index = (u8)(ht_setting.field.MCS); |
66cd8d6e BZ |
2368 | |
2369 | if (rate_index < 0) | |
2370 | rate_index = 0; | |
2371 | ||
4dbb8e57 DC |
2372 | if (rate_index >= rate_count) |
2373 | rate_index = rate_count - 1; | |
66cd8d6e BZ |
2374 | |
2375 | wrqu->bitrate.value = ralinkrate[rate_index] * 500000; | |
2376 | wrqu->bitrate.disabled = 0; | |
2377 | ||
2378 | return 0; | |
91980990 GKH |
2379 | } |
2380 | ||
66cd8d6e BZ |
2381 | static const iw_handler rt_handler[] = { |
2382 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ | |
2383 | (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */ | |
2384 | (iw_handler) NULL, /* SIOCSIWNWID */ | |
2385 | (iw_handler) NULL, /* SIOCGIWNWID */ | |
2386 | (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */ | |
2387 | (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */ | |
2388 | (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */ | |
2389 | (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */ | |
2390 | (iw_handler) NULL, /* SIOCSIWSENS */ | |
2391 | (iw_handler) NULL, /* SIOCGIWSENS */ | |
2392 | (iw_handler) NULL /* not used */ , /* SIOCSIWRANGE */ | |
2393 | (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */ | |
2394 | (iw_handler) NULL /* not used */ , /* SIOCSIWPRIV */ | |
2395 | (iw_handler) NULL /* kernel code */ , /* SIOCGIWPRIV */ | |
2396 | (iw_handler) NULL /* not used */ , /* SIOCSIWSTATS */ | |
2397 | (iw_handler) rt28xx_get_wireless_stats /* kernel code */ , /* SIOCGIWSTATS */ | |
2398 | (iw_handler) NULL, /* SIOCSIWSPY */ | |
2399 | (iw_handler) NULL, /* SIOCGIWSPY */ | |
2400 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ | |
2401 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ | |
2402 | (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */ | |
2403 | (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */ | |
2404 | (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */ | |
2405 | (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */ | |
2406 | (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */ | |
2407 | (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */ | |
2408 | (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */ | |
2409 | (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */ | |
2410 | (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */ | |
2411 | (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */ | |
2412 | (iw_handler) NULL, /* -- hole -- */ | |
2413 | (iw_handler) NULL, /* -- hole -- */ | |
2414 | (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */ | |
2415 | (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */ | |
2416 | (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */ | |
2417 | (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */ | |
2418 | (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */ | |
2419 | (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */ | |
2420 | (iw_handler) NULL, /* SIOCSIWTXPOW */ | |
2421 | (iw_handler) NULL, /* SIOCGIWTXPOW */ | |
2422 | (iw_handler) NULL, /* SIOCSIWRETRY */ | |
2423 | (iw_handler) NULL, /* SIOCGIWRETRY */ | |
2424 | (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */ | |
2425 | (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */ | |
2426 | (iw_handler) NULL, /* SIOCSIWPOWER */ | |
2427 | (iw_handler) NULL, /* SIOCGIWPOWER */ | |
2428 | (iw_handler) NULL, /* -- hole -- */ | |
2429 | (iw_handler) NULL, /* -- hole -- */ | |
2430 | (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */ | |
2431 | (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */ | |
2432 | (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */ | |
2433 | (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */ | |
2434 | (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ | |
2435 | (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */ | |
2436 | (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */ | |
91980990 GKH |
2437 | }; |
2438 | ||
66cd8d6e BZ |
2439 | const struct iw_handler_def rt28xx_iw_handler_def = { |
2440 | .standard = (iw_handler *) rt_handler, | |
2441 | .num_standard = sizeof(rt_handler) / sizeof(iw_handler), | |
91980990 | 2442 | #if IW_HANDLER_VERSION >= 7 |
66cd8d6e | 2443 | .get_wireless_stats = rt28xx_get_wireless_stats, |
91980990 GKH |
2444 | #endif |
2445 | }; | |
2446 | ||
51126deb BZ |
2447 | int rt28xx_sta_ioctl(IN struct net_device *net_dev, |
2448 | IN OUT struct ifreq *rq, int cmd) | |
91980990 | 2449 | { |
8a10a546 | 2450 | struct os_cookie *pObj; |
62eb734b | 2451 | struct rt_rtmp_adapter *pAd = NULL; |
66cd8d6e BZ |
2452 | struct iwreq *wrq = (struct iwreq *)rq; |
2453 | BOOLEAN StateMachineTouched = FALSE; | |
51126deb | 2454 | int Status = NDIS_STATUS_SUCCESS; |
91980990 | 2455 | |
ca97b838 BZ |
2456 | GET_PAD_FROM_NET_DEV(pAd, net_dev); |
2457 | ||
8a10a546 | 2458 | pObj = (struct os_cookie *)pAd->OS_Cookie; |
ca97b838 | 2459 | |
9f548a2a | 2460 | /*check if the interface is down */ |
66cd8d6e BZ |
2461 | if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { |
2462 | { | |
2463 | DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); | |
2464 | return -ENETDOWN; | |
2465 | } | |
2466 | } | |
91980990 | 2467 | |
9f548a2a | 2468 | { /* determine this ioctl command is comming from which interface. */ |
91980990 GKH |
2469 | pObj->ioctl_if_type = INT_MAIN; |
2470 | pObj->ioctl_if = MAIN_MBSSID; | |
2471 | } | |
2472 | ||
66cd8d6e BZ |
2473 | switch (cmd) { |
2474 | case SIOCGIFHWADDR: | |
2475 | DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n")); | |
2476 | memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN); | |
2477 | break; | |
2478 | case SIOCGIWNAME: | |
2479 | { | |
2480 | char *name = &wrq->u.name[0]; | |
2481 | rt_ioctl_giwname(net_dev, NULL, name, NULL); | |
91980990 GKH |
2482 | break; |
2483 | } | |
9f548a2a | 2484 | case SIOCGIWESSID: /*Get ESSID */ |
66cd8d6e BZ |
2485 | { |
2486 | struct iw_point *essid = &wrq->u.essid; | |
2487 | rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer); | |
91980990 GKH |
2488 | break; |
2489 | } | |
9f548a2a | 2490 | case SIOCSIWESSID: /*Set ESSID */ |
66cd8d6e BZ |
2491 | { |
2492 | struct iw_point *essid = &wrq->u.essid; | |
2493 | rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer); | |
91980990 GKH |
2494 | break; |
2495 | } | |
9f548a2a BZ |
2496 | case SIOCSIWNWID: /* set network id (the cell) */ |
2497 | case SIOCGIWNWID: /* get network id */ | |
66cd8d6e BZ |
2498 | Status = -EOPNOTSUPP; |
2499 | break; | |
9f548a2a | 2500 | case SIOCSIWFREQ: /*set channel/frequency (Hz) */ |
66cd8d6e BZ |
2501 | { |
2502 | struct iw_freq *freq = &wrq->u.freq; | |
2503 | rt_ioctl_siwfreq(net_dev, NULL, freq, NULL); | |
91980990 GKH |
2504 | break; |
2505 | } | |
9f548a2a | 2506 | case SIOCGIWFREQ: /* get channel/frequency (Hz) */ |
66cd8d6e BZ |
2507 | { |
2508 | struct iw_freq *freq = &wrq->u.freq; | |
2509 | rt_ioctl_giwfreq(net_dev, NULL, freq, NULL); | |
91980990 GKH |
2510 | break; |
2511 | } | |
9f548a2a | 2512 | case SIOCSIWNICKN: /*set node name/nickname */ |
66cd8d6e | 2513 | { |
9f548a2a BZ |
2514 | /*struct iw_point *data=&wrq->u.data; */ |
2515 | /*rt_ioctl_siwnickn(net_dev, NULL, data, NULL); */ | |
91980990 GKH |
2516 | break; |
2517 | } | |
9f548a2a | 2518 | case SIOCGIWNICKN: /*get node name/nickname */ |
66cd8d6e BZ |
2519 | { |
2520 | struct iw_point *erq = NULL; | |
2521 | erq = &wrq->u.data; | |
51126deb | 2522 | erq->length = strlen((char *)pAd->nickname); |
66cd8d6e BZ |
2523 | Status = |
2524 | copy_to_user(erq->pointer, pAd->nickname, | |
2525 | erq->length); | |
91980990 GKH |
2526 | break; |
2527 | } | |
9f548a2a | 2528 | case SIOCGIWRATE: /*get default bit rate (bps) */ |
66cd8d6e BZ |
2529 | rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL); |
2530 | break; | |
9f548a2a | 2531 | case SIOCSIWRATE: /*set default bit rate (bps) */ |
66cd8d6e BZ |
2532 | rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL); |
2533 | break; | |
9f548a2a | 2534 | case SIOCGIWRTS: /* get RTS/CTS threshold (bytes) */ |
66cd8d6e BZ |
2535 | { |
2536 | struct iw_param *rts = &wrq->u.rts; | |
2537 | rt_ioctl_giwrts(net_dev, NULL, rts, NULL); | |
91980990 GKH |
2538 | break; |
2539 | } | |
9f548a2a | 2540 | case SIOCSIWRTS: /*set RTS/CTS threshold (bytes) */ |
66cd8d6e BZ |
2541 | { |
2542 | struct iw_param *rts = &wrq->u.rts; | |
2543 | rt_ioctl_siwrts(net_dev, NULL, rts, NULL); | |
91980990 GKH |
2544 | break; |
2545 | } | |
9f548a2a | 2546 | case SIOCGIWFRAG: /*get fragmentation thr (bytes) */ |
66cd8d6e BZ |
2547 | { |
2548 | struct iw_param *frag = &wrq->u.frag; | |
2549 | rt_ioctl_giwfrag(net_dev, NULL, frag, NULL); | |
91980990 GKH |
2550 | break; |
2551 | } | |
9f548a2a | 2552 | case SIOCSIWFRAG: /*set fragmentation thr (bytes) */ |
66cd8d6e BZ |
2553 | { |
2554 | struct iw_param *frag = &wrq->u.frag; | |
2555 | rt_ioctl_siwfrag(net_dev, NULL, frag, NULL); | |
91980990 GKH |
2556 | break; |
2557 | } | |
9f548a2a | 2558 | case SIOCGIWENCODE: /*get encoding token & mode */ |
66cd8d6e BZ |
2559 | { |
2560 | struct iw_point *erq = &wrq->u.encoding; | |
2561 | if (erq) | |
2562 | rt_ioctl_giwencode(net_dev, NULL, erq, | |
2563 | erq->pointer); | |
91980990 GKH |
2564 | break; |
2565 | } | |
9f548a2a | 2566 | case SIOCSIWENCODE: /*set encoding token & mode */ |
66cd8d6e BZ |
2567 | { |
2568 | struct iw_point *erq = &wrq->u.encoding; | |
2569 | if (erq) | |
2570 | rt_ioctl_siwencode(net_dev, NULL, erq, | |
2571 | erq->pointer); | |
91980990 GKH |
2572 | break; |
2573 | } | |
9f548a2a | 2574 | case SIOCGIWAP: /*get access point MAC addresses */ |
66cd8d6e BZ |
2575 | { |
2576 | struct sockaddr *ap_addr = &wrq->u.ap_addr; | |
2577 | rt_ioctl_giwap(net_dev, NULL, ap_addr, | |
2578 | ap_addr->sa_data); | |
91980990 GKH |
2579 | break; |
2580 | } | |
9f548a2a | 2581 | case SIOCSIWAP: /*set access point MAC addresses */ |
66cd8d6e BZ |
2582 | { |
2583 | struct sockaddr *ap_addr = &wrq->u.ap_addr; | |
2584 | rt_ioctl_siwap(net_dev, NULL, ap_addr, | |
2585 | ap_addr->sa_data); | |
91980990 GKH |
2586 | break; |
2587 | } | |
9f548a2a | 2588 | case SIOCGIWMODE: /*get operation mode */ |
66cd8d6e BZ |
2589 | { |
2590 | __u32 *mode = &wrq->u.mode; | |
2591 | rt_ioctl_giwmode(net_dev, NULL, mode, NULL); | |
91980990 GKH |
2592 | break; |
2593 | } | |
9f548a2a | 2594 | case SIOCSIWMODE: /*set operation mode */ |
66cd8d6e BZ |
2595 | { |
2596 | __u32 *mode = &wrq->u.mode; | |
2597 | rt_ioctl_siwmode(net_dev, NULL, mode, NULL); | |
91980990 GKH |
2598 | break; |
2599 | } | |
9f548a2a BZ |
2600 | case SIOCGIWSENS: /*get sensitivity (dBm) */ |
2601 | case SIOCSIWSENS: /*set sensitivity (dBm) */ | |
2602 | case SIOCGIWPOWER: /*get Power Management settings */ | |
2603 | case SIOCSIWPOWER: /*set Power Management settings */ | |
2604 | case SIOCGIWTXPOW: /*get transmit power (dBm) */ | |
2605 | case SIOCSIWTXPOW: /*set transmit power (dBm) */ | |
2606 | case SIOCGIWRANGE: /*Get range of parameters */ | |
2607 | case SIOCGIWRETRY: /*get retry limits and lifetime */ | |
2608 | case SIOCSIWRETRY: /*set retry limits and lifetime */ | |
66cd8d6e BZ |
2609 | case RT_PRIV_IOCTL: |
2610 | case RT_PRIV_IOCTL_EXT: | |
2611 | case RTPRIV_IOCTL_SET: | |
2612 | case RTPRIV_IOCTL_GSITESURVEY: | |
2613 | case SIOCGIWPRIV: | |
2614 | Status = -EOPNOTSUPP; | |
2615 | break; | |
2616 | case SIOCETHTOOL: | |
2617 | break; | |
2618 | default: | |
2619 | DBGPRINT(RT_DEBUG_ERROR, | |
2620 | ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd)); | |
2621 | Status = -EOPNOTSUPP; | |
2622 | break; | |
91980990 GKH |
2623 | } |
2624 | ||
9f548a2a | 2625 | if (StateMachineTouched) /* Upper layer sent a MLME-related operations */ |
66cd8d6e | 2626 | RTMP_MLME_HANDLER(pAd); |
91980990 GKH |
2627 | |
2628 | return Status; | |
2629 | } | |
2630 | ||
2631 | /* | |
2632 | ========================================================================== | |
2633 | Description: | |
2634 | Set SSID | |
2635 | Return: | |
2636 | TRUE if all parameters are OK, FALSE otherwise | |
2637 | ========================================================================== | |
2638 | */ | |
62eb734b | 2639 | int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg) |
91980990 | 2640 | { |
62eb734b | 2641 | struct rt_ndis_802_11_ssid Ssid, *pSsid = NULL; |
66cd8d6e BZ |
2642 | BOOLEAN StateMachineTouched = FALSE; |
2643 | int success = TRUE; | |
2644 | ||
2645 | if (strlen(arg) <= MAX_LEN_OF_SSID) { | |
62eb734b | 2646 | NdisZeroMemory(&Ssid, sizeof(struct rt_ndis_802_11_ssid)); |
66cd8d6e BZ |
2647 | if (strlen(arg) != 0) { |
2648 | NdisMoveMemory(Ssid.Ssid, arg, strlen(arg)); | |
2649 | Ssid.SsidLength = strlen(arg); | |
9f548a2a | 2650 | } else /*ANY ssid */ |
66cd8d6e BZ |
2651 | { |
2652 | Ssid.SsidLength = 0; | |
2653 | memcpy(Ssid.Ssid, "", 0); | |
91980990 GKH |
2654 | pAdapter->StaCfg.BssType = BSS_INFRA; |
2655 | pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; | |
66cd8d6e BZ |
2656 | pAdapter->StaCfg.WepStatus = |
2657 | Ndis802_11EncryptionDisabled; | |
91980990 | 2658 | } |
66cd8d6e | 2659 | pSsid = &Ssid; |
91980990 | 2660 | |
66cd8d6e BZ |
2661 | if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { |
2662 | RTMP_MLME_RESET_STATE_MACHINE(pAdapter); | |
2663 | DBGPRINT(RT_DEBUG_TRACE, | |
06aea994 | 2664 | ("MLME busy, reset MLME state machine!\n")); |
66cd8d6e | 2665 | } |
91980990 | 2666 | |
ca97b838 | 2667 | if ((pAdapter->StaCfg.WpaPassPhraseLen >= 8) && |
66cd8d6e | 2668 | (pAdapter->StaCfg.WpaPassPhraseLen <= 64)) { |
51126deb BZ |
2669 | char passphrase_str[65] = { 0 }; |
2670 | u8 keyMaterial[40]; | |
ca97b838 | 2671 | |
66cd8d6e BZ |
2672 | RTMPMoveMemory(passphrase_str, |
2673 | pAdapter->StaCfg.WpaPassPhrase, | |
2674 | pAdapter->StaCfg.WpaPassPhraseLen); | |
ca97b838 | 2675 | RTMPZeroMemory(pAdapter->StaCfg.PMK, 32); |
66cd8d6e | 2676 | if (pAdapter->StaCfg.WpaPassPhraseLen == 64) { |
51126deb | 2677 | AtoH((char *)pAdapter->StaCfg.WpaPassPhrase, |
66cd8d6e BZ |
2678 | pAdapter->StaCfg.PMK, 32); |
2679 | } else { | |
51126deb | 2680 | PasswordHash((char *)pAdapter->StaCfg. |
66cd8d6e BZ |
2681 | WpaPassPhrase, Ssid.Ssid, |
2682 | Ssid.SsidLength, keyMaterial); | |
2683 | NdisMoveMemory(pAdapter->StaCfg.PMK, | |
2684 | keyMaterial, 32); | |
ca97b838 BZ |
2685 | } |
2686 | } | |
2687 | ||
66cd8d6e BZ |
2688 | pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE; |
2689 | pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE; | |
91980990 GKH |
2690 | pAdapter->bConfigChanged = TRUE; |
2691 | ||
66cd8d6e BZ |
2692 | MlmeEnqueue(pAdapter, |
2693 | MLME_CNTL_STATE_MACHINE, | |
2694 | OID_802_11_SSID, | |
62eb734b | 2695 | sizeof(struct rt_ndis_802_11_ssid), (void *) pSsid); |
66cd8d6e BZ |
2696 | |
2697 | StateMachineTouched = TRUE; | |
2698 | DBGPRINT(RT_DEBUG_TRACE, | |
2699 | ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, | |
2700 | Ssid.Ssid)); | |
2701 | } else | |
2702 | success = FALSE; | |
2703 | ||
9f548a2a | 2704 | if (StateMachineTouched) /* Upper layer sent a MLME-related operations */ |
66cd8d6e | 2705 | RTMP_MLME_HANDLER(pAdapter); |
91980990 | 2706 | |
66cd8d6e | 2707 | return success; |
91980990 GKH |
2708 | } |
2709 | ||
91980990 GKH |
2710 | /* |
2711 | ========================================================================== | |
2712 | Description: | |
2713 | Set Network Type(Infrastructure/Adhoc mode) | |
2714 | Return: | |
2715 | TRUE if all parameters are OK, FALSE otherwise | |
2716 | ========================================================================== | |
2717 | */ | |
62eb734b | 2718 | int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg) |
91980990 | 2719 | { |
51126deb | 2720 | u32 Value = 0; |
91980990 | 2721 | |
66cd8d6e BZ |
2722 | if (strcmp(arg, "Adhoc") == 0) { |
2723 | if (pAdapter->StaCfg.BssType != BSS_ADHOC) { | |
9f548a2a | 2724 | /* Config has changed */ |
91980990 | 2725 | pAdapter->bConfigChanged = TRUE; |
66cd8d6e BZ |
2726 | if (MONITOR_ON(pAdapter)) { |
2727 | RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, | |
2728 | STANORMAL); | |
2729 | RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); | |
91980990 GKH |
2730 | Value &= (~0x80); |
2731 | RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); | |
66cd8d6e BZ |
2732 | OPSTATUS_CLEAR_FLAG(pAdapter, |
2733 | fOP_STATUS_MEDIA_STATE_CONNECTED); | |
2734 | pAdapter->StaCfg.bAutoReconnect = TRUE; | |
2735 | LinkDown(pAdapter, FALSE); | |
2736 | } | |
2737 | if (INFRA_ON(pAdapter)) { | |
9f548a2a BZ |
2738 | /*BOOLEAN Cancelled; */ |
2739 | /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */ | |
2740 | /* Since calling this indicate user don't want to connect to that SSID anymore. */ | |
66cd8d6e BZ |
2741 | pAdapter->MlmeAux.AutoReconnectSsidLen = 32; |
2742 | NdisZeroMemory(pAdapter->MlmeAux. | |
2743 | AutoReconnectSsid, | |
2744 | pAdapter->MlmeAux. | |
2745 | AutoReconnectSsidLen); | |
91980990 GKH |
2746 | |
2747 | LinkDown(pAdapter, FALSE); | |
2748 | ||
66cd8d6e BZ |
2749 | DBGPRINT(RT_DEBUG_TRACE, |
2750 | ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n")); | |
91980990 GKH |
2751 | } |
2752 | } | |
2753 | pAdapter->StaCfg.BssType = BSS_ADHOC; | |
66cd8d6e BZ |
2754 | pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType; |
2755 | DBGPRINT(RT_DEBUG_TRACE, | |
2756 | ("===>Set_NetworkType_Proc::(AD-HOC)\n")); | |
2757 | } else if (strcmp(arg, "Infra") == 0) { | |
2758 | if (pAdapter->StaCfg.BssType != BSS_INFRA) { | |
9f548a2a | 2759 | /* Config has changed */ |
91980990 | 2760 | pAdapter->bConfigChanged = TRUE; |
66cd8d6e BZ |
2761 | if (MONITOR_ON(pAdapter)) { |
2762 | RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, | |
2763 | STANORMAL); | |
2764 | RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); | |
91980990 GKH |
2765 | Value &= (~0x80); |
2766 | RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); | |
66cd8d6e BZ |
2767 | OPSTATUS_CLEAR_FLAG(pAdapter, |
2768 | fOP_STATUS_MEDIA_STATE_CONNECTED); | |
2769 | pAdapter->StaCfg.bAutoReconnect = TRUE; | |
2770 | LinkDown(pAdapter, FALSE); | |
2771 | } | |
2772 | if (ADHOC_ON(pAdapter)) { | |
9f548a2a BZ |
2773 | /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */ |
2774 | /* Since calling this indicate user don't want to connect to that SSID anymore. */ | |
66cd8d6e BZ |
2775 | pAdapter->MlmeAux.AutoReconnectSsidLen = 32; |
2776 | NdisZeroMemory(pAdapter->MlmeAux. | |
2777 | AutoReconnectSsid, | |
2778 | pAdapter->MlmeAux. | |
2779 | AutoReconnectSsidLen); | |
91980990 GKH |
2780 | |
2781 | LinkDown(pAdapter, FALSE); | |
2782 | } | |
2783 | } | |
2784 | pAdapter->StaCfg.BssType = BSS_INFRA; | |
66cd8d6e BZ |
2785 | pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType; |
2786 | DBGPRINT(RT_DEBUG_TRACE, | |
2787 | ("===>Set_NetworkType_Proc::(INFRA)\n")); | |
2788 | } else if (strcmp(arg, "Monitor") == 0) { | |
51126deb | 2789 | u8 bbpValue = 0; |
91980990 GKH |
2790 | BCN_TIME_CFG_STRUC csr; |
2791 | OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON); | |
66cd8d6e | 2792 | OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON); |
91980990 | 2793 | OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED); |
9f548a2a | 2794 | /* disable all periodic state machine */ |
91980990 | 2795 | pAdapter->StaCfg.bAutoReconnect = FALSE; |
9f548a2a | 2796 | /* reset all mlme state machine */ |
66cd8d6e BZ |
2797 | RTMP_MLME_RESET_STATE_MACHINE(pAdapter); |
2798 | DBGPRINT(RT_DEBUG_TRACE, | |
2799 | ("fOP_STATUS_MEDIA_STATE_CONNECTED \n")); | |
2800 | if (pAdapter->CommonCfg.CentralChannel == 0) { | |
2801 | if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED) | |
2802 | pAdapter->CommonCfg.CentralChannel = 36; | |
2803 | else | |
2804 | pAdapter->CommonCfg.CentralChannel = 6; | |
2805 | } else | |
2806 | N_ChannelCheck(pAdapter); | |
2807 | ||
2808 | if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED && | |
2809 | pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 && | |
2810 | pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == | |
2811 | EXTCHA_ABOVE) { | |
9f548a2a | 2812 | /* 40MHz ,control channel at lower */ |
66cd8d6e BZ |
2813 | RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, |
2814 | &bbpValue); | |
91980990 GKH |
2815 | bbpValue &= (~0x18); |
2816 | bbpValue |= 0x10; | |
66cd8d6e BZ |
2817 | RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, |
2818 | bbpValue); | |
91980990 | 2819 | pAdapter->CommonCfg.BBPCurrentBW = BW_40; |
9f548a2a | 2820 | /* RX : control channel at lower */ |
66cd8d6e BZ |
2821 | RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, |
2822 | &bbpValue); | |
91980990 | 2823 | bbpValue &= (~0x20); |
66cd8d6e BZ |
2824 | RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, |
2825 | bbpValue); | |
91980990 GKH |
2826 | |
2827 | RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value); | |
2828 | Value &= 0xfffffffe; | |
2829 | RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value); | |
66cd8d6e BZ |
2830 | pAdapter->CommonCfg.CentralChannel = |
2831 | pAdapter->CommonCfg.Channel + 2; | |
2832 | AsicSwitchChannel(pAdapter, | |
2833 | pAdapter->CommonCfg.CentralChannel, | |
2834 | FALSE); | |
2835 | AsicLockChannel(pAdapter, | |
2836 | pAdapter->CommonCfg.CentralChannel); | |
2837 | DBGPRINT(RT_DEBUG_TRACE, | |
2838 | ("BW_40 ,control_channel(%d), CentralChannel(%d) \n", | |
2839 | pAdapter->CommonCfg.Channel, | |
2840 | pAdapter->CommonCfg.CentralChannel)); | |
2841 | } else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED | |
2842 | && pAdapter->CommonCfg.RegTransmitSetting.field.BW == | |
2843 | BW_40 | |
2844 | && pAdapter->CommonCfg.RegTransmitSetting.field. | |
2845 | EXTCHA == EXTCHA_BELOW) { | |
9f548a2a | 2846 | /* 40MHz ,control channel at upper */ |
66cd8d6e BZ |
2847 | RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, |
2848 | &bbpValue); | |
91980990 GKH |
2849 | bbpValue &= (~0x18); |
2850 | bbpValue |= 0x10; | |
66cd8d6e BZ |
2851 | RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, |
2852 | bbpValue); | |
91980990 GKH |
2853 | pAdapter->CommonCfg.BBPCurrentBW = BW_40; |
2854 | RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value); | |
2855 | Value |= 0x1; | |
2856 | RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value); | |
2857 | ||
66cd8d6e BZ |
2858 | RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, |
2859 | &bbpValue); | |
91980990 | 2860 | bbpValue |= (0x20); |
66cd8d6e BZ |
2861 | RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, |
2862 | bbpValue); | |
2863 | pAdapter->CommonCfg.CentralChannel = | |
2864 | pAdapter->CommonCfg.Channel - 2; | |
2865 | AsicSwitchChannel(pAdapter, | |
2866 | pAdapter->CommonCfg.CentralChannel, | |
2867 | FALSE); | |
2868 | AsicLockChannel(pAdapter, | |
2869 | pAdapter->CommonCfg.CentralChannel); | |
2870 | DBGPRINT(RT_DEBUG_TRACE, | |
2871 | ("BW_40 ,control_channel(%d), CentralChannel(%d) \n", | |
2872 | pAdapter->CommonCfg.Channel, | |
2873 | pAdapter->CommonCfg.CentralChannel)); | |
2874 | } else { | |
9f548a2a | 2875 | /* 20MHz */ |
66cd8d6e BZ |
2876 | RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, |
2877 | &bbpValue); | |
91980990 | 2878 | bbpValue &= (~0x18); |
66cd8d6e BZ |
2879 | RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, |
2880 | bbpValue); | |
91980990 | 2881 | pAdapter->CommonCfg.BBPCurrentBW = BW_20; |
66cd8d6e BZ |
2882 | AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, |
2883 | FALSE); | |
91980990 | 2884 | AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel); |
66cd8d6e BZ |
2885 | DBGPRINT(RT_DEBUG_TRACE, |
2886 | ("BW_20, Channel(%d)\n", | |
2887 | pAdapter->CommonCfg.Channel)); | |
91980990 | 2888 | } |
9f548a2a | 2889 | /* Enable Rx with promiscuous reception */ |
91980990 | 2890 | RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3); |
9f548a2a BZ |
2891 | /* ASIC supporsts sniffer function with replacing RSSI with timestamp. */ |
2892 | /*RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); */ | |
2893 | /*Value |= (0x80); */ | |
2894 | /*RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); */ | |
2895 | /* disable sync */ | |
91980990 GKH |
2896 | RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word); |
2897 | csr.field.bBeaconGen = 0; | |
2898 | csr.field.bTBTTEnable = 0; | |
2899 | csr.field.TsfSyncMode = 0; | |
2900 | RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word); | |
2901 | ||
2902 | pAdapter->StaCfg.BssType = BSS_MONITOR; | |
9f548a2a | 2903 | pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; /*ARPHRD_IEEE80211; // IEEE80211 */ |
66cd8d6e BZ |
2904 | DBGPRINT(RT_DEBUG_TRACE, |
2905 | ("===>Set_NetworkType_Proc::(MONITOR)\n")); | |
2906 | } | |
9f548a2a | 2907 | /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */ |
66cd8d6e | 2908 | pAdapter->StaCfg.WpaState = SS_NOTUSE; |
91980990 | 2909 | |
66cd8d6e BZ |
2910 | DBGPRINT(RT_DEBUG_TRACE, |
2911 | ("Set_NetworkType_Proc::(NetworkType=%d)\n", | |
2912 | pAdapter->StaCfg.BssType)); | |
91980990 | 2913 | |
66cd8d6e | 2914 | return TRUE; |
91980990 | 2915 | } |