Commit | Line | Data |
---|---|---|
4bd43f50 LR |
1 | /* |
2 | * Copyright (c) 2007-2008 Atheros Communications Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include "cprecomp.h" | |
18 | #include "ratectrl.h" | |
19 | #include "../hal/hpreg.h" | |
20 | ||
21 | /* TODO : change global variable to constant */ | |
22 | u8_t zgWpaRadiusOui[] = { 0x00, 0x50, 0xf2, 0x01 }; | |
23 | u8_t zgWpaAesOui[] = { 0x00, 0x50, 0xf2, 0x04 }; | |
24 | u8_t zgWpa2RadiusOui[] = { 0x00, 0x0f, 0xac, 0x01 }; | |
25 | u8_t zgWpa2AesOui[] = { 0x00, 0x0f, 0xac, 0x04 }; | |
26 | ||
27 | const u16_t zcCwTlb[16] = { 0, 1, 3, 7, 15, 31, 63, 127, | |
28 | 255, 511, 1023, 2047, 4095, 4095, 4095, 4095}; | |
29 | ||
30 | void zfStaStartConnectCb(zdev_t* dev); | |
31 | ||
32 | /************************************************************************/ | |
33 | /* */ | |
34 | /* FUNCTION DESCRIPTION zfStaPutApIntoBlockingList */ | |
35 | /* Put AP into blocking AP list. */ | |
36 | /* */ | |
37 | /* INPUTS */ | |
38 | /* dev : device pointer */ | |
39 | /* bssid : AP's BSSID */ | |
40 | /* weight : weight of AP */ | |
41 | /* */ | |
42 | /* OUTPUTS */ | |
43 | /* none */ | |
44 | /* */ | |
45 | /* AUTHOR */ | |
46 | /* Stephen Chen Atheros Communications, INC. 2006.12 */ | |
47 | /* */ | |
48 | /************************************************************************/ | |
49 | void zfStaPutApIntoBlockingList(zdev_t* dev, u8_t* bssid, u8_t weight) | |
50 | { | |
51 | u16_t i, j; | |
52 | zmw_get_wlan_dev(dev); | |
53 | zmw_declare_for_critical_section(); | |
54 | ||
55 | if (weight > 0) | |
56 | { | |
57 | zmw_enter_critical_section(dev); | |
58 | /*Find same bssid entry first*/ | |
59 | for (i=0; i<ZM_MAX_BLOCKING_AP_LIST_SIZE; i++) | |
60 | { | |
61 | for (j=0; j<6; j++) | |
62 | { | |
63 | if(wd->sta.blockingApList[i].addr[j]!= bssid[j]) | |
64 | { | |
65 | break; | |
66 | } | |
67 | } | |
68 | ||
69 | if(j==6) | |
70 | { | |
71 | break; | |
72 | } | |
73 | } | |
74 | /*This bssid doesn't have old record.Find an empty entry*/ | |
75 | if (i == ZM_MAX_BLOCKING_AP_LIST_SIZE) | |
76 | { | |
77 | for (i=0; i<ZM_MAX_BLOCKING_AP_LIST_SIZE; i++) | |
78 | { | |
79 | if (wd->sta.blockingApList[i].weight == 0) | |
80 | { | |
81 | break; | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | /* If the list is full, pick one entry for replacement */ | |
87 | if (i == ZM_MAX_BLOCKING_AP_LIST_SIZE) | |
88 | { | |
89 | i = bssid[5] & (ZM_MAX_BLOCKING_AP_LIST_SIZE-1); | |
90 | } | |
91 | ||
92 | /* Update AP address and weight */ | |
93 | for (j=0; j<6; j++) | |
94 | { | |
95 | wd->sta.blockingApList[i].addr[j] = bssid[j]; | |
96 | } | |
97 | ||
98 | wd->sta.blockingApList[i].weight = weight; | |
99 | zmw_leave_critical_section(dev); | |
100 | } | |
101 | ||
102 | return; | |
103 | } | |
104 | ||
105 | ||
106 | /************************************************************************/ | |
107 | /* */ | |
108 | /* FUNCTION DESCRIPTION zfStaIsApInBlockingList */ | |
109 | /* Is AP in blocking list. */ | |
110 | /* */ | |
111 | /* INPUTS */ | |
112 | /* dev : device pointer */ | |
113 | /* bssid : AP's BSSID */ | |
114 | /* */ | |
115 | /* OUTPUTS */ | |
116 | /* TRUE : AP in blocking list */ | |
117 | /* FALSE : AP not in blocking list */ | |
118 | /* */ | |
119 | /* AUTHOR */ | |
120 | /* Stephen Chen Atheros Communications, INC. 2006.12 */ | |
121 | /* */ | |
122 | /************************************************************************/ | |
123 | u16_t zfStaIsApInBlockingList(zdev_t* dev, u8_t* bssid) | |
124 | { | |
125 | u16_t i, j; | |
126 | zmw_get_wlan_dev(dev); | |
127 | //zmw_declare_for_critical_section(); | |
128 | ||
129 | //zmw_enter_critical_section(dev); | |
130 | for (i=0; i<ZM_MAX_BLOCKING_AP_LIST_SIZE; i++) | |
131 | { | |
132 | if (wd->sta.blockingApList[i].weight != 0) | |
133 | { | |
134 | for (j=0; j<6; j++) | |
135 | { | |
136 | if (wd->sta.blockingApList[i].addr[j] != bssid[j]) | |
137 | { | |
138 | break; | |
139 | } | |
140 | } | |
141 | if (j == 6) | |
142 | { | |
143 | //zmw_leave_critical_section(dev); | |
144 | return TRUE; | |
145 | } | |
146 | } | |
147 | } | |
148 | //zmw_leave_critical_section(dev); | |
149 | return FALSE; | |
150 | } | |
151 | ||
152 | ||
153 | /************************************************************************/ | |
154 | /* */ | |
155 | /* FUNCTION DESCRIPTION zfStaRefreshBlockList */ | |
156 | /* Is AP in blocking list. */ | |
157 | /* */ | |
158 | /* INPUTS */ | |
159 | /* dev : device pointer */ | |
160 | /* flushFlag : flush whole blocking list */ | |
161 | /* */ | |
162 | /* OUTPUTS */ | |
163 | /* none */ | |
164 | /* */ | |
165 | /* AUTHOR */ | |
166 | /* Stephen Chen Atheros Communications, INC. 2006.12 */ | |
167 | /* */ | |
168 | /************************************************************************/ | |
169 | void zfStaRefreshBlockList(zdev_t* dev, u16_t flushFlag) | |
170 | { | |
171 | u16_t i; | |
172 | zmw_get_wlan_dev(dev); | |
173 | zmw_declare_for_critical_section(); | |
174 | ||
175 | zmw_enter_critical_section(dev); | |
176 | for (i=0; i<ZM_MAX_BLOCKING_AP_LIST_SIZE; i++) | |
177 | { | |
178 | if (wd->sta.blockingApList[i].weight != 0) | |
179 | { | |
180 | if (flushFlag != 0) | |
181 | { | |
182 | wd->sta.blockingApList[i].weight = 0; | |
183 | } | |
184 | else | |
185 | { | |
186 | wd->sta.blockingApList[i].weight--; | |
187 | } | |
188 | } | |
189 | } | |
190 | zmw_leave_critical_section(dev); | |
191 | return; | |
192 | } | |
193 | ||
194 | ||
195 | /************************************************************************/ | |
196 | /* */ | |
197 | /* FUNCTION DESCRIPTION zfStaConnectFail */ | |
198 | /* Handle Connect failure. */ | |
199 | /* */ | |
200 | /* INPUTS */ | |
201 | /* dev : device pointer */ | |
202 | /* bssid : BSSID */ | |
203 | /* reason : reason of failure */ | |
204 | /* */ | |
205 | /* OUTPUTS */ | |
206 | /* none */ | |
207 | /* */ | |
208 | /* AUTHOR */ | |
209 | /* Stephen Chen Atheros Communications, INC. 2006.12 */ | |
210 | /* */ | |
211 | /************************************************************************/ | |
212 | void zfStaConnectFail(zdev_t* dev, u16_t reason, u16_t* bssid, u8_t weight) | |
213 | { | |
214 | zmw_get_wlan_dev(dev); | |
215 | ||
216 | /* Change internal state */ | |
217 | zfChangeAdapterState(dev, ZM_STA_STATE_DISCONNECT); | |
218 | ||
bbc9a991 | 219 | /* Improve WEP/TKIP performance with HT AP, detail information please look bug#32495 */ |
4bd43f50 LR |
220 | //zfHpSetTTSIFSTime(dev, 0x8); |
221 | ||
222 | /* Notify wrapper of connection status changes */ | |
223 | if (wd->zfcbConnectNotify != NULL) | |
224 | { | |
225 | wd->zfcbConnectNotify(dev, reason, bssid); | |
226 | } | |
227 | ||
228 | /* Put AP into internal blocking list */ | |
229 | zfStaPutApIntoBlockingList(dev, (u8_t *)bssid, weight); | |
230 | ||
231 | /* Issue another SCAN */ | |
232 | if ( wd->sta.bAutoReconnect ) | |
233 | { | |
234 | zm_debug_msg0("Start internal scan..."); | |
235 | zfScanMgrScanStop(dev, ZM_SCAN_MGR_SCAN_INTERNAL); | |
236 | zfScanMgrScanStart(dev, ZM_SCAN_MGR_SCAN_INTERNAL); | |
237 | } | |
238 | } | |
239 | ||
240 | u8_t zfiWlanIBSSGetPeerStationsCount(zdev_t* dev) | |
241 | { | |
242 | zmw_get_wlan_dev(dev); | |
243 | ||
244 | return wd->sta.oppositeCount; | |
245 | } | |
246 | ||
247 | u8_t zfiWlanIBSSIteratePeerStations(zdev_t* dev, u8_t numToIterate, zfpIBSSIteratePeerStationCb callback, void *ctx) | |
248 | { | |
249 | u8_t oppositeCount; | |
250 | u8_t i; | |
251 | u8_t index = 0; | |
252 | ||
253 | zmw_get_wlan_dev(dev); | |
254 | ||
255 | zmw_declare_for_critical_section(); | |
256 | ||
257 | zmw_enter_critical_section(dev); | |
258 | ||
259 | oppositeCount = wd->sta.oppositeCount; | |
260 | if ( oppositeCount > numToIterate ) | |
261 | { | |
262 | oppositeCount = numToIterate; | |
263 | } | |
264 | ||
265 | for(i=0; i < ZM_MAX_OPPOSITE_COUNT; i++) | |
266 | { | |
267 | if ( oppositeCount == 0 ) | |
268 | { | |
269 | break; | |
270 | } | |
271 | ||
272 | if ( wd->sta.oppositeInfo[i].valid == 0 ) | |
273 | { | |
274 | continue; | |
275 | } | |
276 | ||
277 | callback(dev, &wd->sta.oppositeInfo[i], ctx, index++); | |
278 | oppositeCount--; | |
279 | ||
280 | } | |
281 | ||
282 | zmw_leave_critical_section(dev); | |
283 | ||
284 | return index; | |
285 | } | |
286 | ||
287 | ||
288 | s8_t zfStaFindFreeOpposite(zdev_t* dev, u16_t *sa, int *pFoundIdx) | |
289 | { | |
290 | int oppositeCount; | |
291 | int i; | |
292 | ||
293 | zmw_get_wlan_dev(dev); | |
294 | ||
295 | oppositeCount = wd->sta.oppositeCount; | |
296 | ||
297 | for(i=0; i < ZM_MAX_OPPOSITE_COUNT; i++) | |
298 | { | |
299 | if ( oppositeCount == 0 ) | |
300 | { | |
301 | break; | |
302 | } | |
303 | ||
304 | if ( wd->sta.oppositeInfo[i].valid == 0 ) | |
305 | { | |
306 | continue; | |
307 | } | |
308 | ||
309 | oppositeCount--; | |
310 | if ( zfMemoryIsEqual((u8_t*) sa, wd->sta.oppositeInfo[i].macAddr, 6) ) | |
311 | { | |
312 | //wd->sta.oppositeInfo[i].aliveCounter++; | |
313 | wd->sta.oppositeInfo[i].aliveCounter = ZM_IBSS_PEER_ALIVE_COUNTER; | |
314 | ||
315 | /* it is already stored */ | |
316 | return 1; | |
317 | } | |
318 | } | |
319 | ||
320 | // Check if there's still space for new comer | |
321 | if ( wd->sta.oppositeCount == ZM_MAX_OPPOSITE_COUNT ) | |
322 | { | |
323 | return -1; | |
324 | } | |
325 | ||
326 | // Find an unused slot for new peer station | |
327 | for(i=0; i < ZM_MAX_OPPOSITE_COUNT; i++) | |
328 | { | |
329 | if ( wd->sta.oppositeInfo[i].valid == 0 ) | |
330 | { | |
331 | break; | |
332 | } | |
333 | } | |
334 | ||
335 | *pFoundIdx = i; | |
336 | return 0; | |
337 | } | |
338 | ||
339 | s8_t zfStaFindOppositeByMACAddr(zdev_t* dev, u16_t *sa, u8_t *pFoundIdx) | |
340 | { | |
341 | u32_t oppositeCount; | |
342 | u32_t i; | |
343 | ||
344 | zmw_get_wlan_dev(dev); | |
345 | ||
346 | oppositeCount = wd->sta.oppositeCount; | |
347 | ||
348 | for(i=0; i < ZM_MAX_OPPOSITE_COUNT; i++) | |
349 | { | |
350 | if ( oppositeCount == 0 ) | |
351 | { | |
352 | break; | |
353 | } | |
354 | ||
355 | if ( wd->sta.oppositeInfo[i].valid == 0 ) | |
356 | { | |
357 | continue; | |
358 | } | |
359 | ||
360 | oppositeCount--; | |
361 | if ( zfMemoryIsEqual((u8_t*) sa, wd->sta.oppositeInfo[i].macAddr, 6) ) | |
362 | { | |
363 | *pFoundIdx = (u8_t)i; | |
364 | ||
365 | return 0; | |
366 | } | |
367 | } | |
368 | ||
369 | *pFoundIdx = 0; | |
370 | return 1; | |
371 | } | |
372 | ||
373 | static void zfStaInitCommonOppositeInfo(zdev_t* dev, int i) | |
374 | { | |
375 | zmw_get_wlan_dev(dev); | |
376 | ||
377 | /* set the default rate to the highest rate */ | |
378 | wd->sta.oppositeInfo[i].valid = 1; | |
379 | wd->sta.oppositeInfo[i].aliveCounter = ZM_IBSS_PEER_ALIVE_COUNTER; | |
380 | wd->sta.oppositeCount++; | |
381 | ||
382 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
383 | /* Set parameters for new opposite peer station !!! */ | |
384 | wd->sta.oppositeInfo[i].camIdx = 0xff; // Not set key in this location | |
385 | wd->sta.oppositeInfo[i].pkInstalled = 0; | |
386 | wd->sta.oppositeInfo[i].wpaState = ZM_STA_WPA_STATE_INIT ; // No encryption | |
387 | #endif | |
388 | } | |
389 | ||
390 | int zfStaSetOppositeInfoFromBSSInfo(zdev_t* dev, struct zsBssInfo* pBssInfo) | |
391 | { | |
392 | int i; | |
393 | u8_t* dst; | |
394 | u16_t sa[3]; | |
395 | int res; | |
396 | u32_t oneTxStreamCap; | |
397 | ||
398 | zmw_get_wlan_dev(dev); | |
399 | ||
400 | zfMemoryCopy((u8_t*) sa, pBssInfo->macaddr, 6); | |
401 | ||
402 | res = zfStaFindFreeOpposite(dev, sa, &i); | |
403 | if ( res != 0 ) | |
404 | { | |
405 | goto zlReturn; | |
406 | } | |
407 | ||
408 | dst = wd->sta.oppositeInfo[i].macAddr; | |
409 | zfMemoryCopy(dst, (u8_t *)sa, 6); | |
410 | ||
411 | oneTxStreamCap = (zfHpCapability(dev) & ZM_HP_CAP_11N_ONE_TX_STREAM); | |
412 | ||
413 | if (pBssInfo->extSupportedRates[1] != 0) | |
414 | { | |
415 | /* TODO : Handle 11n */ | |
416 | if (pBssInfo->frequency < 3000) | |
417 | { | |
418 | /* 2.4GHz */ | |
419 | if (pBssInfo->EnableHT == 1) | |
420 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 1, pBssInfo->SG40); | |
421 | else | |
422 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 1, pBssInfo->SG40); | |
423 | } | |
424 | else | |
425 | { | |
426 | /* 5GHz */ | |
427 | if (pBssInfo->EnableHT == 1) | |
428 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 0, pBssInfo->SG40); | |
429 | else | |
430 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 0, pBssInfo->SG40); | |
431 | } | |
432 | } | |
433 | else | |
434 | { | |
435 | /* TODO : Handle 11n */ | |
436 | if (pBssInfo->frequency < 3000) | |
437 | { | |
438 | /* 2.4GHz */ | |
439 | if (pBssInfo->EnableHT == 1) | |
440 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 1, pBssInfo->SG40); | |
441 | else | |
442 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 0, 1, pBssInfo->SG40); | |
443 | } | |
444 | else | |
445 | { | |
446 | /* 5GHz */ | |
447 | if (pBssInfo->EnableHT == 1) | |
448 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 0, pBssInfo->SG40); | |
449 | else | |
450 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 0, pBssInfo->SG40); | |
451 | } | |
452 | } | |
453 | ||
454 | ||
455 | zfStaInitCommonOppositeInfo(dev, i); | |
456 | zlReturn: | |
457 | return 0; | |
458 | } | |
459 | ||
460 | int zfStaSetOppositeInfoFromRxBuf(zdev_t* dev, zbuf_t* buf) | |
461 | { | |
462 | int i; | |
463 | u8_t* dst; | |
464 | u16_t sa[3]; | |
465 | int res = 0; | |
466 | u16_t offset; | |
467 | u8_t bSupportExtRate; | |
468 | u32_t rtsctsRate = 0xffffffff; /* CTS:OFDM 6M, RTS:OFDM 6M */ | |
469 | u32_t oneTxStreamCap; | |
470 | ||
471 | zmw_get_wlan_dev(dev); | |
472 | zmw_declare_for_critical_section(); | |
473 | ||
474 | sa[0] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET); | |
475 | sa[1] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET+2); | |
476 | sa[2] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET+4); | |
477 | ||
478 | zmw_enter_critical_section(dev); | |
479 | ||
480 | res = zfStaFindFreeOpposite(dev, sa, &i); | |
481 | if ( res != 0 ) | |
482 | { | |
483 | goto zlReturn; | |
484 | } | |
485 | ||
486 | dst = wd->sta.oppositeInfo[i].macAddr; | |
487 | zfCopyFromRxBuffer(dev, buf, dst, ZM_WLAN_HEADER_A2_OFFSET, 6); | |
488 | ||
489 | if ( (wd->sta.currentFrequency < 3000) && !(wd->supportMode & (ZM_WIRELESS_MODE_24_54|ZM_WIRELESS_MODE_24_N)) ) | |
490 | { | |
491 | bSupportExtRate = 0; | |
492 | } else { | |
493 | bSupportExtRate = 1; | |
494 | } | |
495 | ||
496 | if ( (bSupportExtRate == 1) | |
497 | && (wd->sta.currentFrequency < 3000) | |
498 | && (wd->wlanMode == ZM_MODE_IBSS) | |
499 | && (wd->wfc.bIbssGMode == 0) ) | |
500 | { | |
501 | bSupportExtRate = 0; | |
502 | } | |
503 | ||
504 | wd->sta.connection_11b = 0; | |
505 | oneTxStreamCap = (zfHpCapability(dev) & ZM_HP_CAP_11N_ONE_TX_STREAM); | |
506 | ||
507 | if ( ((offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_RATE)) != 0xffff) | |
508 | && (bSupportExtRate == 1) ) | |
509 | { | |
510 | /* TODO : Handle 11n */ | |
511 | if (wd->sta.currentFrequency < 3000) | |
512 | { | |
513 | /* 2.4GHz */ | |
514 | if (wd->sta.EnableHT == 1) | |
515 | { | |
516 | //11ng | |
517 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 1, wd->sta.SG40); | |
518 | } | |
519 | else | |
520 | { | |
521 | //11g | |
522 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 1, wd->sta.SG40); | |
523 | } | |
524 | rtsctsRate = 0x00001bb; /* CTS:CCK 1M, RTS:OFDM 6M */ | |
525 | } | |
526 | else | |
527 | { | |
528 | /* 5GHz */ | |
529 | if (wd->sta.EnableHT == 1) | |
530 | { | |
531 | //11na | |
532 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 0, wd->sta.SG40); | |
533 | } | |
534 | else | |
535 | { | |
536 | //11a | |
537 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 0, wd->sta.SG40); | |
538 | } | |
539 | rtsctsRate = 0x10b01bb; /* CTS:OFDM 6M, RTS:OFDM 6M */ | |
540 | } | |
541 | } | |
542 | else | |
543 | { | |
544 | /* TODO : Handle 11n */ | |
545 | if (wd->sta.currentFrequency < 3000) | |
546 | { | |
547 | /* 2.4GHz */ | |
548 | if (wd->sta.EnableHT == 1) | |
549 | { | |
550 | //11ng | |
551 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 1, wd->sta.SG40); | |
552 | rtsctsRate = 0x00001bb; /* CTS:CCK 1M, RTS:OFDM 6M */ | |
553 | } | |
554 | else | |
555 | { | |
556 | //11b | |
557 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 0, 1, wd->sta.SG40); | |
558 | rtsctsRate = 0x0; /* CTS:CCK 1M, RTS:CCK 1M */ | |
559 | wd->sta.connection_11b = 1; | |
560 | } | |
561 | } | |
562 | else | |
563 | { | |
564 | /* 5GHz */ | |
565 | if (wd->sta.EnableHT == 1) | |
566 | { | |
567 | //11na | |
568 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, (oneTxStreamCap!=0)?3:2, 0, wd->sta.SG40); | |
569 | } | |
570 | else | |
571 | { | |
572 | //11a | |
573 | zfRateCtrlInitCell(dev, &wd->sta.oppositeInfo[i].rcCell, 1, 0, wd->sta.SG40); | |
574 | } | |
575 | rtsctsRate = 0x10b01bb; /* CTS:OFDM 6M, RTS:OFDM 6M */ | |
576 | } | |
577 | } | |
578 | ||
579 | zfStaInitCommonOppositeInfo(dev, i); | |
580 | ||
581 | zlReturn: | |
582 | zmw_leave_critical_section(dev); | |
583 | ||
584 | if (rtsctsRate != 0xffffffff) | |
585 | { | |
586 | zfHpSetRTSCTSRate(dev, rtsctsRate); | |
587 | } | |
588 | return res; | |
589 | } | |
590 | ||
591 | void zfStaProtErpMonitor(zdev_t* dev, zbuf_t* buf) | |
592 | { | |
593 | u16_t offset; | |
594 | u8_t erp; | |
595 | u8_t bssid[6]; | |
596 | ||
597 | zmw_get_wlan_dev(dev); | |
598 | ||
599 | if ( (wd->wlanMode == ZM_MODE_INFRASTRUCTURE)&&(zfStaIsConnected(dev)) ) | |
600 | { | |
601 | ZM_MAC_WORD_TO_BYTE(wd->sta.bssid, bssid); | |
602 | ||
603 | if (zfRxBufferEqualToStr(dev, buf, bssid, ZM_WLAN_HEADER_A2_OFFSET, 6)) | |
604 | { | |
92363b52 JP |
605 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_ERP); |
606 | if (offset != 0xffff) | |
4bd43f50 LR |
607 | { |
608 | erp = zmw_rx_buf_readb(dev, buf, offset+2); | |
609 | ||
610 | if ( erp & ZM_BIT_1 ) | |
611 | { | |
612 | //zm_debug_msg0("protection mode on"); | |
613 | if (wd->sta.bProtectionMode == FALSE) | |
614 | { | |
615 | wd->sta.bProtectionMode = TRUE; | |
616 | zfHpSetSlotTime(dev, 0); | |
617 | } | |
618 | } | |
619 | else | |
620 | { | |
621 | //zm_debug_msg0("protection mode off"); | |
622 | if (wd->sta.bProtectionMode == TRUE) | |
623 | { | |
624 | wd->sta.bProtectionMode = FALSE; | |
625 | zfHpSetSlotTime(dev, 1); | |
626 | } | |
627 | } | |
628 | } | |
629 | } | |
630 | //Check the existence of Non-N AP | |
631 | //Follow the check the "pBssInfo->EnableHT" | |
92363b52 JP |
632 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_HT_CAPABILITY); |
633 | if (offset != 0xffff) | |
4bd43f50 LR |
634 | {} |
635 | else if ((offset = zfFindElement(dev, buf, ZM_WLAN_PREN2_EID_HTCAPABILITY)) != 0xffff) | |
636 | {} | |
637 | else | |
638 | {wd->sta.NonNAPcount++;} | |
639 | } | |
640 | } | |
641 | ||
642 | void zfStaUpdateWmeParameter(zdev_t* dev, zbuf_t* buf) | |
643 | { | |
644 | u16_t tmp; | |
645 | u16_t aifs[5]; | |
646 | u16_t cwmin[5]; | |
647 | u16_t cwmax[5]; | |
648 | u16_t txop[5]; | |
649 | u8_t acm; | |
650 | u8_t ac; | |
651 | u16_t len; | |
652 | u16_t i; | |
653 | u16_t offset; | |
654 | u8_t rxWmeParameterSetCount; | |
655 | ||
656 | zmw_get_wlan_dev(dev); | |
657 | ||
658 | /* Update if WME parameter set count is changed */ | |
659 | /* If connect to WME AP */ | |
660 | if (wd->sta.wmeConnected != 0) | |
661 | { | |
662 | /* Find WME parameter element */ | |
92363b52 JP |
663 | offset = zfFindWifiElement(dev, buf, 2, 1); |
664 | if (offset != 0xffff) | |
4bd43f50 | 665 | { |
92363b52 JP |
666 | len = zmw_rx_buf_readb(dev, buf, offset+1); |
667 | if (len >= 7) | |
4bd43f50 LR |
668 | { |
669 | rxWmeParameterSetCount=zmw_rx_buf_readb(dev, buf, offset+8); | |
670 | if (rxWmeParameterSetCount != wd->sta.wmeParameterSetCount) | |
671 | { | |
672 | zm_msg0_mm(ZM_LV_0, "wmeParameterSetCount changed!"); | |
673 | wd->sta.wmeParameterSetCount = rxWmeParameterSetCount; | |
674 | /* retrieve WME parameter and update TxQ parameters */ | |
675 | acm = 0xf; | |
676 | for (i=0; i<4; i++) | |
677 | { | |
678 | if (len >= (8+(i*4)+4)) | |
679 | { | |
680 | tmp=zmw_rx_buf_readb(dev, buf, offset+10+i*4); | |
681 | ac = (tmp >> 5) & 0x3; | |
682 | if ((tmp & 0x10) == 0) | |
683 | { | |
684 | acm &= (~(1<<ac)); | |
685 | } | |
686 | aifs[ac] = ((tmp & 0xf) * 9) + 10; | |
687 | tmp=zmw_rx_buf_readb(dev, buf, offset+11+i*4); | |
688 | /* Convert to 2^n */ | |
689 | cwmin[ac] = zcCwTlb[(tmp & 0xf)]; | |
690 | cwmax[ac] = zcCwTlb[(tmp >> 4)]; | |
691 | txop[ac]=zmw_rx_buf_readh(dev, buf, | |
692 | offset+12+i*4); | |
693 | } | |
694 | } | |
695 | ||
696 | if ((acm & 0x4) != 0) | |
697 | { | |
698 | cwmin[2] = cwmin[0]; | |
699 | cwmax[2] = cwmax[0]; | |
700 | aifs[2] = aifs[0]; | |
701 | txop[2] = txop[0]; | |
702 | } | |
703 | if ((acm & 0x8) != 0) | |
704 | { | |
705 | cwmin[3] = cwmin[2]; | |
706 | cwmax[3] = cwmax[2]; | |
707 | aifs[3] = aifs[2]; | |
708 | txop[3] = txop[2]; | |
709 | } | |
710 | cwmin[4] = 3; | |
711 | cwmax[4] = 7; | |
712 | aifs[4] = 28; | |
713 | ||
714 | if ((cwmin[2]+aifs[2]) > ((cwmin[0]+aifs[0])+1)) | |
715 | { | |
716 | wd->sta.ac0PriorityHigherThanAc2 = 1; | |
717 | } | |
718 | else | |
719 | { | |
720 | wd->sta.ac0PriorityHigherThanAc2 = 0; | |
721 | } | |
722 | zfHpUpdateQosParameter(dev, cwmin, cwmax, aifs, txop); | |
723 | } | |
724 | } | |
725 | } | |
726 | } //if (wd->sta.wmeConnected != 0) | |
727 | } | |
728 | /* process 802.11h Dynamic Frequency Selection */ | |
729 | void zfStaUpdateDot11HDFS(zdev_t* dev, zbuf_t* buf) | |
730 | { | |
0009e125 RD |
731 | //u8_t length, channel, is5G; |
732 | u16_t offset; | |
733 | ||
4bd43f50 LR |
734 | zmw_get_wlan_dev(dev); |
735 | ||
736 | /* | |
737 | Channel Switch Announcement Element Format | |
738 | +------+----------+------+-------------------+------------------+--------------------+ | |
739 | |Format|Element ID|Length|Channel Switch Mode|New Channel Number|Channel Switch Count| | |
740 | +------+----------+------+-------------------+------------------+--------------------+ | |
741 | |Bytes | 1 | 1 | 1 | 1 | 1 | | |
742 | +------+----------+------+-------------------+------------------+--------------------+ | |
743 | |Value | 37 | 3 | 0 or 1 |unsigned integer |unsigned integer | | |
744 | +------+----------+------+-------------------+------------------+--------------------+ | |
745 | */ | |
4bd43f50 LR |
746 | |
747 | /* get EID(Channel Switch Announcement) */ | |
92363b52 JP |
748 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_CHANNEL_SWITCH_ANNOUNCE); |
749 | if (offset == 0xffff) | |
4bd43f50 LR |
750 | { |
751 | //zm_debug_msg0("EID(Channel Switch Announcement) not found"); | |
752 | return; | |
753 | } | |
754 | else if ( zmw_rx_buf_readb(dev, buf, offset+1) == 0x3 ) | |
755 | { | |
756 | zm_debug_msg0("EID(Channel Switch Announcement) found"); | |
757 | ||
758 | //length = zmw_rx_buf_readb(dev, buf, offset+1); | |
759 | //zfCopyFromRxBuffer(dev, buf, pBssInfo->supportedRates, offset, length+2); | |
760 | ||
761 | //Chanell Switch Mode set to 1, driver should disable transmit immediate | |
762 | //we do this by poll CCA high | |
763 | if (zmw_rx_buf_readb(dev, buf, offset+2) == 0x1 ) | |
764 | { | |
765 | //use ZM_OID_INTERNAL_WRITE,ZM_CMD_RESET to notice firmware flush quene and stop dma, | |
766 | //then restart rx dma but not tx dma | |
767 | if (wd->sta.DFSDisableTx != TRUE) | |
768 | { | |
769 | /* TODO : zfHpResetTxRx would cause Rx hang */ | |
770 | //zfHpResetTxRx(dev); | |
771 | wd->sta.DFSDisableTx = TRUE; | |
772 | /* Trgger Rx DMA */ | |
773 | zfHpStartRecv(dev); | |
774 | } | |
775 | //Adapter->ZD80211HSetting.DisableTxBy80211H=TRUE; | |
776 | //AcquireCtrOfPhyReg(Adapter); | |
777 | //ZD1205_WRITE_REGISTER(Adapter,CR24, 0x0); | |
778 | //ReleaseDoNotSleep(Adapter); | |
779 | } | |
780 | ||
781 | if (zmw_rx_buf_readb(dev, buf, offset+4) <= 0x2 ) | |
782 | { | |
783 | //Channel Switch | |
784 | //if Channel Switch Count = 0 , STA should change channel immediately. | |
785 | //if Channel Switch Count > 0 , STA should change channel after TBTT*count | |
786 | //But it won't be accurate to let driver calculate TBTT*count, and the value of | |
787 | //Channel Switch Count will decrease by one each when continue receving beacon | |
788 | //So we change channel here when we receive count <=2. | |
789 | ||
790 | zfHpDeleteAllowChannel(dev, wd->sta.currentFrequency); | |
791 | wd->frequency = zfChNumToFreq(dev, zmw_rx_buf_readb(dev, buf, offset+3), 0); | |
792 | //zfHpAddAllowChannel(dev, wd->frequency); | |
793 | zm_debug_msg1("CWY - jump to frequency = ", wd->frequency); | |
794 | zfCoreSetFrequency(dev, wd->frequency); | |
795 | wd->sta.DFSDisableTx = FALSE; | |
796 | /* Increase rxBeaconCount to prevent beacon lost */ | |
797 | if (zfStaIsConnected(dev)) | |
798 | { | |
799 | wd->sta.rxBeaconCount = 1 << 6; // 2 times of check would pass | |
800 | } | |
801 | //start tx dma to transmit packet | |
802 | ||
803 | //if (zmw_rx_buf_readb(dev, buf, offset+3) != wd->frequency) | |
804 | //{ | |
805 | // //ZDDbgPrint(("Radar Detect by AP\n")); | |
806 | // zfCoreSetFrequency(); | |
807 | // ProcessRadarDetectEvent(Adapter); | |
808 | // Set_RF_Channel(Adapter, SwRfd->Rfd->RxBuffer[index+3], (UCHAR)Adapter->RF_Mode, 1); | |
809 | // Adapter->CardSetting.Channel = SwRfd->Rfd->RxBuffer[index+3]; | |
810 | // Adapter->SaveChannel = Adapter->CardSetting.Channel; | |
811 | // Adapter->UtilityChannel = Adapter->CardSetting.Channel; | |
812 | //} | |
813 | } | |
814 | } | |
815 | ||
816 | } | |
817 | /* TODO : process 802.11h Transmission Power Control */ | |
818 | void zfStaUpdateDot11HTPC(zdev_t* dev, zbuf_t* buf) | |
819 | { | |
820 | } | |
821 | ||
822 | /* IBSS power-saving mode */ | |
823 | void zfStaIbssPSCheckState(zdev_t* dev, zbuf_t* buf) | |
824 | { | |
825 | u8_t i, frameCtrl; | |
826 | ||
827 | zmw_get_wlan_dev(dev); | |
828 | ||
829 | if ( !zfStaIsConnected(dev) ) | |
830 | { | |
831 | return; | |
832 | } | |
833 | ||
834 | if ( wd->wlanMode != ZM_MODE_IBSS ) | |
835 | { | |
836 | return ; | |
837 | } | |
838 | ||
839 | /* check BSSID */ | |
840 | if ( !zfRxBufferEqualToStr(dev, buf, (u8_t*) wd->sta.bssid, | |
841 | ZM_WLAN_HEADER_A3_OFFSET, 6) ) | |
842 | { | |
843 | return; | |
844 | } | |
845 | ||
846 | frameCtrl = zmw_rx_buf_readb(dev, buf, 1); | |
847 | ||
848 | /* check power management bit */ | |
849 | if ( frameCtrl & ZM_BIT_4 ) | |
850 | { | |
851 | for(i=1; i<ZM_MAX_PS_STA; i++) | |
852 | { | |
853 | if ( !wd->sta.staPSList.entity[i].bUsed ) | |
854 | { | |
855 | continue; | |
856 | } | |
857 | ||
858 | /* check source address */ | |
859 | if ( zfRxBufferEqualToStr(dev, buf, | |
860 | wd->sta.staPSList.entity[i].macAddr, | |
861 | ZM_WLAN_HEADER_A2_OFFSET, 6) ) | |
862 | { | |
863 | return; | |
864 | } | |
865 | } | |
866 | ||
867 | for(i=1; i<ZM_MAX_PS_STA; i++) | |
868 | { | |
869 | if ( !wd->sta.staPSList.entity[i].bUsed ) | |
870 | { | |
871 | wd->sta.staPSList.entity[i].bUsed = TRUE; | |
872 | wd->sta.staPSList.entity[i].bDataQueued = FALSE; | |
873 | break; | |
874 | } | |
875 | } | |
876 | ||
877 | if ( i == ZM_MAX_PS_STA ) | |
878 | { | |
879 | /* STA list is full */ | |
880 | return; | |
881 | } | |
882 | ||
883 | zfCopyFromRxBuffer(dev, buf, wd->sta.staPSList.entity[i].macAddr, | |
884 | ZM_WLAN_HEADER_A2_OFFSET, 6); | |
885 | ||
886 | if ( wd->sta.staPSList.count == 0 ) | |
887 | { | |
888 | // enable ATIM window | |
889 | //zfEnableAtimWindow(dev); | |
890 | } | |
891 | ||
892 | wd->sta.staPSList.count++; | |
893 | } | |
894 | else if ( wd->sta.staPSList.count ) | |
895 | { | |
896 | for(i=1; i<ZM_MAX_PS_STA; i++) | |
897 | { | |
898 | if ( wd->sta.staPSList.entity[i].bUsed ) | |
899 | { | |
900 | if ( zfRxBufferEqualToStr(dev, buf, | |
901 | wd->sta.staPSList.entity[i].macAddr, | |
902 | ZM_WLAN_HEADER_A2_OFFSET, 6) ) | |
903 | { | |
904 | wd->sta.staPSList.entity[i].bUsed = FALSE; | |
905 | wd->sta.staPSList.count--; | |
906 | ||
907 | if ( wd->sta.staPSList.entity[i].bDataQueued ) | |
908 | { | |
909 | /* send queued data */ | |
910 | } | |
911 | } | |
912 | } | |
913 | } | |
914 | ||
915 | if ( wd->sta.staPSList.count == 0 ) | |
916 | { | |
917 | /* disable ATIM window */ | |
918 | //zfDisableAtimWindow(dev); | |
919 | } | |
920 | ||
921 | } | |
922 | } | |
923 | ||
924 | /* IBSS power-saving mode */ | |
925 | u8_t zfStaIbssPSQueueData(zdev_t* dev, zbuf_t* buf) | |
926 | { | |
927 | u8_t i; | |
928 | u16_t da[3]; | |
929 | ||
930 | zmw_get_wlan_dev(dev); | |
931 | ||
932 | if ( !zfStaIsConnected(dev) ) | |
933 | { | |
934 | return 0; | |
935 | } | |
936 | ||
937 | if ( wd->wlanMode != ZM_MODE_IBSS ) | |
938 | { | |
939 | return 0; | |
940 | } | |
941 | ||
942 | if ( wd->sta.staPSList.count == 0 && wd->sta.powerSaveMode <= ZM_STA_PS_NONE ) | |
943 | { | |
944 | return 0; | |
945 | } | |
946 | ||
947 | /* DA */ | |
948 | #ifdef ZM_ENABLE_NATIVE_WIFI | |
949 | da[0] = zmw_tx_buf_readh(dev, buf, ZM_WLAN_HEADER_A1_OFFSET); | |
950 | da[1] = zmw_tx_buf_readh(dev, buf, ZM_WLAN_HEADER_A1_OFFSET + 2); | |
951 | da[2] = zmw_tx_buf_readh(dev, buf, ZM_WLAN_HEADER_A1_OFFSET + 4); | |
952 | #else | |
953 | da[0] = zmw_tx_buf_readh(dev, buf, 0); | |
954 | da[1] = zmw_tx_buf_readh(dev, buf, 2); | |
955 | da[2] = zmw_tx_buf_readh(dev, buf, 4); | |
956 | #endif | |
957 | ||
958 | if ( ZM_IS_MULTICAST_OR_BROADCAST(da) ) | |
959 | { | |
960 | wd->sta.staPSList.entity[0].bDataQueued = TRUE; | |
961 | wd->sta.ibssPSDataQueue[wd->sta.ibssPSDataCount++] = buf; | |
962 | return 1; | |
963 | } | |
964 | ||
965 | // Unicast packet... | |
966 | ||
967 | for(i=1; i<ZM_MAX_PS_STA; i++) | |
968 | { | |
969 | if ( zfMemoryIsEqual(wd->sta.staPSList.entity[i].macAddr, | |
970 | (u8_t*) da, 6) ) | |
971 | { | |
972 | wd->sta.staPSList.entity[i].bDataQueued = TRUE; | |
973 | wd->sta.ibssPSDataQueue[wd->sta.ibssPSDataCount++] = buf; | |
974 | ||
975 | return 1; | |
976 | } | |
977 | } | |
978 | ||
979 | #if 0 | |
980 | if ( wd->sta.powerSaveMode > ZM_STA_PS_NONE ) | |
981 | { | |
982 | wd->sta.staPSDataQueue[wd->sta.staPSDataCount++] = buf; | |
983 | ||
984 | return 1; | |
985 | } | |
986 | #endif | |
987 | ||
988 | return 0; | |
989 | } | |
990 | ||
991 | /* IBSS power-saving mode */ | |
992 | void zfStaIbssPSSend(zdev_t* dev) | |
993 | { | |
994 | u8_t i; | |
995 | u16_t bcastAddr[3] = {0xffff, 0xffff, 0xffff}; | |
996 | ||
997 | zmw_get_wlan_dev(dev); | |
998 | ||
999 | if ( !zfStaIsConnected(dev) ) | |
1000 | { | |
1001 | return ; | |
1002 | } | |
1003 | ||
1004 | if ( wd->wlanMode != ZM_MODE_IBSS ) | |
1005 | { | |
1006 | return ; | |
1007 | } | |
1008 | ||
1009 | for(i=0; i<ZM_MAX_PS_STA; i++) | |
1010 | { | |
1011 | if ( wd->sta.staPSList.entity[i].bDataQueued ) | |
1012 | { | |
1013 | if ( i == 0 ) | |
1014 | { | |
1015 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_ATIM, | |
1016 | bcastAddr, | |
1017 | 0, 0, 0); | |
1018 | } | |
1019 | else if ( wd->sta.staPSList.entity[i].bUsed ) | |
1020 | { | |
1021 | // Send ATIM to prevent the peer to go to sleep | |
1022 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_ATIM, | |
1023 | (u16_t*) wd->sta.staPSList.entity[i].macAddr, | |
1024 | 0, 0, 0); | |
1025 | } | |
1026 | ||
1027 | wd->sta.staPSList.entity[i].bDataQueued = FALSE; | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | for(i=0; i<wd->sta.ibssPSDataCount; i++) | |
1032 | { | |
1033 | zfTxSendEth(dev, wd->sta.ibssPSDataQueue[i], 0, | |
1034 | ZM_EXTERNAL_ALLOC_BUF, 0); | |
1035 | } | |
1036 | ||
1037 | wd->sta.ibssPrevPSDataCount = wd->sta.ibssPSDataCount; | |
1038 | wd->sta.ibssPSDataCount = 0; | |
1039 | } | |
1040 | ||
1041 | ||
1042 | void zfStaReconnect(zdev_t* dev) | |
1043 | { | |
1044 | zmw_get_wlan_dev(dev); | |
1045 | zmw_declare_for_critical_section(); | |
1046 | ||
1047 | if ( wd->wlanMode != ZM_MODE_INFRASTRUCTURE && | |
1048 | wd->wlanMode != ZM_MODE_IBSS ) | |
1049 | { | |
1050 | return; | |
1051 | } | |
1052 | ||
1053 | if ( (zfStaIsConnected(dev))||(zfStaIsConnecting(dev)) ) | |
1054 | { | |
1055 | return; | |
1056 | } | |
1057 | ||
1058 | if ( wd->sta.bChannelScan ) | |
1059 | { | |
1060 | return; | |
1061 | } | |
1062 | ||
1063 | /* Recover zero SSID length */ | |
1064 | if ( (wd->wlanMode == ZM_MODE_INFRASTRUCTURE) && (wd->ws.ssidLen == 0)) | |
1065 | { | |
1066 | zm_debug_msg0("zfStaReconnect: NOT Support!! Set SSID to any BSS"); | |
1067 | /* ANY BSS */ | |
1068 | zmw_enter_critical_section(dev); | |
1069 | wd->sta.ssid[0] = 0; | |
1070 | wd->sta.ssidLen = 0; | |
1071 | zmw_leave_critical_section(dev); | |
1072 | } | |
1073 | ||
1074 | // RAY: To ensure no TX pending before re-connecting | |
1075 | zfFlushVtxq(dev); | |
1076 | zfWlanEnable(dev); | |
1077 | zfScanMgrScanAck(dev); | |
1078 | } | |
1079 | ||
1080 | void zfStaTimer100ms(zdev_t* dev) | |
1081 | { | |
1082 | zmw_get_wlan_dev(dev); | |
1083 | ||
1084 | if ( (wd->tick % 10) == 0 ) | |
1085 | { | |
1086 | zfPushVtxq(dev); | |
1087 | // zfPowerSavingMgrMain(dev); | |
1088 | } | |
1089 | } | |
1090 | ||
1091 | ||
1092 | void zfStaCheckRxBeacon(zdev_t* dev) | |
1093 | { | |
1094 | zmw_get_wlan_dev(dev); | |
1095 | ||
1096 | if (( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) && (zfStaIsConnected(dev))) | |
1097 | { | |
1098 | if (wd->beaconInterval == 0) | |
1099 | { | |
1100 | wd->beaconInterval = 100; | |
1101 | } | |
1102 | if ( (wd->tick % ((wd->beaconInterval * 10) / ZM_MS_PER_TICK)) == 0 ) | |
1103 | { | |
1104 | /* Check rxBeaconCount */ | |
1105 | if (wd->sta.rxBeaconCount == 0) | |
1106 | { | |
1107 | if (wd->sta.beaconMissState == 1) | |
1108 | { | |
1109 | /*notify AP that we left*/ | |
1110 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_DEAUTH, wd->sta.bssid, 3, 0, 0); | |
1111 | /* Beacon Lost */ | |
1112 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_BEACON_MISS, | |
1113 | wd->sta.bssid, 0); | |
1114 | } | |
1115 | else | |
1116 | { | |
1117 | wd->sta.beaconMissState = 1; | |
1118 | /* Reset channel */ | |
1119 | zfCoreSetFrequencyExV2(dev, wd->frequency, wd->BandWidth40, | |
1120 | wd->ExtOffset, NULL, 1); | |
1121 | } | |
1122 | } | |
1123 | else | |
1124 | { | |
1125 | wd->sta.beaconMissState = 0; | |
1126 | } | |
1127 | wd->sta.rxBeaconCount = 0; | |
1128 | } | |
1129 | } | |
1130 | } | |
1131 | ||
1132 | ||
1133 | ||
1134 | void zfStaCheckConnectTimeout(zdev_t* dev) | |
1135 | { | |
1136 | zmw_get_wlan_dev(dev); | |
1137 | zmw_declare_for_critical_section(); | |
1138 | ||
1139 | if ( wd->wlanMode != ZM_MODE_INFRASTRUCTURE ) | |
1140 | { | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | if ( !zfStaIsConnecting(dev) ) | |
1145 | { | |
1146 | return; | |
1147 | } | |
1148 | ||
1149 | zmw_enter_critical_section(dev); | |
1150 | if ( (wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_OPEN)|| | |
1151 | (wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_SHARE_1)|| | |
1152 | (wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_SHARE_2)|| | |
1153 | (wd->sta.connectState == ZM_STA_CONN_STATE_ASSOCIATE) ) | |
1154 | { | |
1155 | if ( (wd->tick - wd->sta.connectTimer) > ZM_INTERVAL_CONNECT_TIMEOUT ) | |
1156 | { | |
1157 | if ( wd->sta.connectByReasso ) | |
1158 | { | |
1159 | wd->sta.failCntOfReasso++; | |
1160 | if ( wd->sta.failCntOfReasso > 2 ) | |
1161 | { | |
1162 | wd->sta.connectByReasso = FALSE; | |
1163 | } | |
1164 | } | |
1165 | ||
1166 | wd->sta.connectState = ZM_STA_CONN_STATE_NONE; | |
1167 | zm_debug_msg1("connect timeout, state = ", wd->sta.connectState); | |
1168 | //zfiWlanDisable(dev); | |
1169 | goto failed; | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | zmw_leave_critical_section(dev); | |
1174 | return; | |
1175 | ||
1176 | failed: | |
1177 | zmw_leave_critical_section(dev); | |
1178 | if(wd->sta.authMode == ZM_AUTH_MODE_AUTO) | |
1179 | { // Fix some AP not send authentication failed message to sta and lead to connect timeout ! | |
1180 | wd->sta.connectTimeoutCount++; | |
1181 | } | |
1182 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_TIMEOUT, wd->sta.bssid, 2); | |
1183 | return; | |
1184 | } | |
1185 | ||
1186 | void zfMmStaTimeTick(zdev_t* dev) | |
1187 | { | |
1188 | zmw_get_wlan_dev(dev); | |
1189 | ||
1190 | /* airopeek */ | |
1191 | if (wd->wlanMode != ZM_MODE_AP && !wd->swSniffer) | |
1192 | { | |
1193 | if ( wd->tick & 1 ) | |
1194 | { | |
1195 | zfTimerCheckAndHandle(dev); | |
1196 | } | |
1197 | ||
1198 | zfStaCheckRxBeacon(dev); | |
1199 | zfStaTimer100ms(dev); | |
1200 | zfStaCheckConnectTimeout(dev); | |
1201 | zfPowerSavingMgrMain(dev); | |
1202 | } | |
1203 | ||
1204 | #ifdef ZM_ENABLE_AGGREGATION | |
1205 | /* | |
1206 | * add by honda | |
1207 | */ | |
1208 | zfAggScanAndClear(dev, wd->tick); | |
1209 | #endif | |
1210 | } | |
1211 | ||
1212 | void zfStaSendBeacon(zdev_t* dev) | |
1213 | { | |
1214 | zbuf_t* buf; | |
1215 | u16_t offset, seq; | |
1216 | ||
1217 | zmw_get_wlan_dev(dev); | |
1218 | ||
1219 | zmw_declare_for_critical_section(); | |
1220 | ||
1221 | //zm_debug_msg0("\n"); | |
1222 | ||
1223 | /* TBD : Maximum size of beacon */ | |
92363b52 JP |
1224 | buf = zfwBufAllocate(dev, 1024); |
1225 | if (buf == NULL) | |
4bd43f50 LR |
1226 | { |
1227 | zm_debug_msg0("Allocate beacon buffer failed"); | |
1228 | return; | |
1229 | } | |
1230 | ||
1231 | offset = 0; | |
1232 | /* wlan header */ | |
1233 | /* Frame control */ | |
1234 | zmw_tx_buf_writeh(dev, buf, offset, 0x0080); | |
1235 | offset+=2; | |
1236 | /* Duration */ | |
1237 | zmw_tx_buf_writeh(dev, buf, offset, 0x0000); | |
1238 | offset+=2; | |
1239 | /* Address 1 */ | |
1240 | zmw_tx_buf_writeh(dev, buf, offset, 0xffff); | |
1241 | offset+=2; | |
1242 | zmw_tx_buf_writeh(dev, buf, offset, 0xffff); | |
1243 | offset+=2; | |
1244 | zmw_tx_buf_writeh(dev, buf, offset, 0xffff); | |
1245 | offset+=2; | |
1246 | /* Address 2 */ | |
1247 | zmw_tx_buf_writeh(dev, buf, offset, wd->macAddr[0]); | |
1248 | offset+=2; | |
1249 | zmw_tx_buf_writeh(dev, buf, offset, wd->macAddr[1]); | |
1250 | offset+=2; | |
1251 | zmw_tx_buf_writeh(dev, buf, offset, wd->macAddr[2]); | |
1252 | offset+=2; | |
1253 | /* Address 3 */ | |
1254 | zmw_tx_buf_writeh(dev, buf, offset, wd->sta.bssid[0]); | |
1255 | offset+=2; | |
1256 | zmw_tx_buf_writeh(dev, buf, offset, wd->sta.bssid[1]); | |
1257 | offset+=2; | |
1258 | zmw_tx_buf_writeh(dev, buf, offset, wd->sta.bssid[2]); | |
1259 | offset+=2; | |
1260 | ||
1261 | /* Sequence number */ | |
1262 | zmw_enter_critical_section(dev); | |
1263 | seq = ((wd->mmseq++)<<4); | |
1264 | zmw_leave_critical_section(dev); | |
1265 | zmw_tx_buf_writeh(dev, buf, offset, seq); | |
1266 | offset+=2; | |
1267 | ||
1268 | /* 24-31 Time Stamp : hardware will fill this field */ | |
1269 | offset+=8; | |
1270 | ||
1271 | /* Beacon Interval */ | |
1272 | zmw_tx_buf_writeh(dev, buf, offset, wd->beaconInterval); | |
1273 | offset+=2; | |
1274 | ||
1275 | /* Capability */ | |
1276 | zmw_tx_buf_writeb(dev, buf, offset++, wd->sta.capability[0]); | |
1277 | zmw_tx_buf_writeb(dev, buf, offset++, wd->sta.capability[1]); | |
1278 | ||
1279 | /* SSID */ | |
1280 | offset = zfStaAddIeSsid(dev, buf, offset); | |
1281 | ||
1282 | if(wd->frequency <= ZM_CH_G_14) // 2.4 GHz b+g | |
1283 | { | |
1284 | ||
1285 | /* Support Rate */ | |
1286 | offset = zfMmAddIeSupportRate(dev, buf, offset, | |
1287 | ZM_WLAN_EID_SUPPORT_RATE, ZM_RATE_SET_CCK); | |
1288 | ||
1289 | /* DS parameter set */ | |
1290 | offset = zfMmAddIeDs(dev, buf, offset); | |
1291 | ||
1292 | offset = zfStaAddIeIbss(dev, buf, offset); | |
1293 | ||
1294 | if( wd->wfc.bIbssGMode | |
1295 | && (wd->supportMode & (ZM_WIRELESS_MODE_24_54|ZM_WIRELESS_MODE_24_N)) ) // Only accompany with enabling a mode . | |
1296 | { | |
1297 | /* ERP Information */ | |
1298 | wd->erpElement = 0; | |
1299 | offset = zfMmAddIeErp(dev, buf, offset); | |
1300 | } | |
1301 | ||
1302 | /* TODO : country information */ | |
1303 | /* RSN */ | |
1304 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA2PSK ) | |
1305 | { | |
1306 | offset = zfwStaAddIeWpaRsn(dev, buf, offset, ZM_WLAN_FRAME_TYPE_AUTH); | |
1307 | } | |
1308 | ||
1309 | if( wd->wfc.bIbssGMode | |
1310 | && (wd->supportMode & (ZM_WIRELESS_MODE_24_54|ZM_WIRELESS_MODE_24_N)) ) // Only accompany with enabling a mode . | |
1311 | { | |
1312 | /* Enable G Mode */ | |
1313 | /* Extended Supported Rates */ | |
1314 | offset = zfMmAddIeSupportRate(dev, buf, offset, | |
1315 | ZM_WLAN_EID_EXTENDED_RATE, ZM_RATE_SET_OFDM); | |
1316 | } | |
1317 | } | |
1318 | else // 5GHz a | |
1319 | { | |
1320 | /* Support Rate a Mode */ | |
1321 | offset = zfMmAddIeSupportRate(dev, buf, offset, | |
1322 | ZM_WLAN_EID_SUPPORT_RATE, ZM_RATE_SET_OFDM); | |
1323 | ||
1324 | /* DS parameter set */ | |
1325 | offset = zfMmAddIeDs(dev, buf, offset); | |
1326 | ||
1327 | offset = zfStaAddIeIbss(dev, buf, offset); | |
1328 | ||
1329 | /* TODO : country information */ | |
1330 | /* RSN */ | |
1331 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA2PSK ) | |
1332 | { | |
1333 | offset = zfwStaAddIeWpaRsn(dev, buf, offset, ZM_WLAN_FRAME_TYPE_AUTH); | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | if ( wd->wlanMode != ZM_MODE_IBSS ) | |
1338 | { | |
1339 | /* TODO : Need to check if it is ok */ | |
1340 | /* HT Capabilities Info */ | |
1341 | offset = zfMmAddHTCapability(dev, buf, offset); | |
1342 | ||
1343 | /* Extended HT Capabilities Info */ | |
1344 | offset = zfMmAddExtendedHTCapability(dev, buf, offset); | |
1345 | } | |
1346 | ||
1347 | if ( wd->sta.ibssAdditionalIESize ) | |
1348 | offset = zfStaAddIbssAdditionalIE(dev, buf, offset); | |
1349 | ||
1350 | /* 1212 : write to beacon fifo */ | |
1351 | /* 1221 : write to share memory */ | |
1352 | zfHpSendBeacon(dev, buf, offset); | |
1353 | ||
1354 | /* Free beacon buffer */ | |
1355 | //zfwBufFree(dev, buf, 0); | |
1356 | } | |
1357 | ||
1358 | void zfStaSignalStatistic(zdev_t* dev, u8_t SignalStrength, u8_t SignalQuality) //CWYang(+) | |
1359 | { | |
1360 | zmw_get_wlan_dev(dev); | |
1361 | ||
1362 | /* Add Your Code to Do Works Like Moving Average Here */ | |
1363 | wd->SignalStrength = (wd->SignalStrength * 7 + SignalStrength * 3)/10; | |
1364 | wd->SignalQuality = (wd->SignalQuality * 7 + SignalQuality * 3)/10; | |
1365 | ||
1366 | } | |
1367 | ||
1368 | struct zsBssInfo* zfStaFindBssInfo(zdev_t* dev, zbuf_t* buf, struct zsWlanProbeRspFrameHeader *pProbeRspHeader) | |
1369 | { | |
1370 | u8_t i; | |
1371 | u8_t j; | |
1372 | u8_t k; | |
1373 | u8_t isMatched, length, channel; | |
1374 | u16_t offset, frequency; | |
1375 | struct zsBssInfo* pBssInfo; | |
1376 | ||
1377 | zmw_get_wlan_dev(dev); | |
1378 | ||
92363b52 JP |
1379 | pBssInfo = wd->sta.bssList.head; |
1380 | if (pBssInfo == NULL) | |
4bd43f50 LR |
1381 | { |
1382 | return NULL; | |
1383 | } | |
1384 | ||
1385 | for( i=0; i<wd->sta.bssList.bssCount; i++ ) | |
1386 | { | |
1387 | //zm_debug_msg2("check pBssInfo = ", pBssInfo); | |
1388 | ||
1389 | /* Check BSSID */ | |
1390 | for( j=0; j<6; j++ ) | |
1391 | { | |
1392 | if ( pBssInfo->bssid[j] != pProbeRspHeader->bssid[j] ) | |
1393 | { | |
1394 | break; | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | /* Check SSID */ | |
1399 | if (j == 6) | |
1400 | { | |
1401 | if (pProbeRspHeader->ssid[1] <= 32) | |
1402 | { | |
1403 | /* compare length and ssid */ | |
1404 | isMatched = 1; | |
1405 | if((pProbeRspHeader->ssid[1] != 0) && (pBssInfo->ssid[1] != 0)) | |
1406 | { | |
1407 | for( k=1; k<pProbeRspHeader->ssid[1] + 1; k++ ) | |
1408 | { | |
1409 | if ( pBssInfo->ssid[k] != pProbeRspHeader->ssid[k] ) | |
1410 | { | |
1411 | isMatched = 0; | |
1412 | break; | |
1413 | } | |
1414 | } | |
1415 | } | |
1416 | } | |
1417 | else | |
1418 | { | |
1419 | isMatched = 0; | |
1420 | } | |
1421 | } | |
1422 | else | |
1423 | { | |
1424 | isMatched = 0; | |
1425 | } | |
1426 | ||
1427 | /* Check channel */ | |
1428 | /* Add check channel to solve the bug #31222 */ | |
1429 | if (isMatched) { | |
92363b52 JP |
1430 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_DS); |
1431 | if (offset != 0xffff) { | |
1432 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1433 | if (length == 1) { | |
4bd43f50 LR |
1434 | channel = zmw_rx_buf_readb(dev, buf, offset+2); |
1435 | if (zfHpIsAllowedChannel(dev, zfChNumToFreq(dev, channel, 0)) == 0) { | |
1436 | frequency = 0; | |
1437 | } else { | |
1438 | frequency = zfChNumToFreq(dev, channel, 0);; | |
1439 | } | |
1440 | } else { | |
1441 | frequency = 0; | |
1442 | } | |
1443 | } else { | |
1444 | frequency = wd->sta.currentFrequency; | |
1445 | } | |
1446 | ||
1447 | if (frequency != 0) { | |
1448 | if ( ((frequency > 3000) && (pBssInfo->frequency > 3000)) | |
1449 | || ((frequency < 3000) && (pBssInfo->frequency < 3000)) ) { | |
1450 | /* redundant */ | |
1451 | break; | |
1452 | } | |
1453 | } | |
1454 | } | |
1455 | ||
1456 | pBssInfo = pBssInfo->next; | |
1457 | } | |
1458 | ||
1459 | if ( i == wd->sta.bssList.bssCount ) | |
1460 | { | |
1461 | pBssInfo = NULL; | |
1462 | } | |
1463 | ||
1464 | return pBssInfo; | |
1465 | } | |
1466 | ||
1467 | u8_t zfStaInitBssInfo(zdev_t* dev, zbuf_t* buf, | |
1468 | struct zsWlanProbeRspFrameHeader *pProbeRspHeader, | |
1469 | struct zsBssInfo* pBssInfo, struct zsAdditionInfo* AddInfo, u8_t type) | |
1470 | { | |
1471 | u8_t length, channel, is5G; | |
1472 | u16_t i, offset; | |
1473 | u8_t apQosInfo; | |
1474 | u16_t eachIElength = 0; | |
1475 | u16_t accumulateLen = 0; | |
1476 | ||
1477 | zmw_get_wlan_dev(dev); | |
1478 | ||
1479 | if ((type == 1) && ((pBssInfo->flag & ZM_BSS_INFO_VALID_BIT) != 0)) | |
1480 | { | |
1481 | goto zlUpdateRssi; | |
1482 | } | |
1483 | ||
1484 | /* get SSID */ | |
92363b52 JP |
1485 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_SSID); |
1486 | if (offset == 0xffff) | |
4bd43f50 LR |
1487 | { |
1488 | zm_debug_msg0("EID(SSID) not found"); | |
1489 | goto zlError; | |
1490 | } | |
1491 | ||
1492 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1493 | ||
1494 | { | |
1495 | u8_t Show_Flag = 0; | |
1496 | zfwGetShowZeroLengthSSID(dev, &Show_Flag); | |
1497 | ||
1498 | if(Show_Flag) | |
1499 | { | |
1500 | if (length > ZM_MAX_SSID_LENGTH ) | |
1501 | { | |
1502 | zm_debug_msg0("EID(SSID) is invalid"); | |
1503 | goto zlError; | |
1504 | } | |
1505 | } | |
1506 | else | |
1507 | { | |
1508 | if ( length == 0 || length > ZM_MAX_SSID_LENGTH ) | |
1509 | { | |
1510 | zm_debug_msg0("EID(SSID) is invalid"); | |
1511 | goto zlError; | |
1512 | } | |
1513 | ||
1514 | } | |
1515 | } | |
1516 | zfCopyFromRxBuffer(dev, buf, pBssInfo->ssid, offset, length+2); | |
1517 | ||
1518 | /* get DS parameter */ | |
92363b52 JP |
1519 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_DS); |
1520 | if (offset != 0xffff) | |
4bd43f50 LR |
1521 | { |
1522 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1523 | if ( length != 1 ) | |
1524 | { | |
1525 | zm_msg0_mm(ZM_LV_0, "Abnormal DS Param Set IE"); | |
1526 | goto zlError; | |
1527 | } | |
1528 | channel = zmw_rx_buf_readb(dev, buf, offset+2); | |
1529 | ||
1530 | if (zfHpIsAllowedChannel(dev, zfChNumToFreq(dev, channel, 0)) == 0) | |
1531 | { | |
1532 | goto zlError2; | |
1533 | } | |
1534 | ||
1535 | pBssInfo->frequency = zfChNumToFreq(dev, channel, 0); // auto check | |
1536 | pBssInfo->channel = channel; | |
1537 | ||
1538 | ||
1539 | } | |
1540 | else | |
1541 | { | |
1542 | /* DS parameter not found */ | |
1543 | pBssInfo->frequency = wd->sta.currentFrequency; | |
1544 | pBssInfo->channel = zfChFreqToNum(wd->sta.currentFrequency, &is5G); | |
1545 | } | |
1546 | ||
1547 | /* initialize security type */ | |
1548 | pBssInfo->securityType = ZM_SECURITY_TYPE_NONE; | |
1549 | ||
1550 | /* get macaddr */ | |
1551 | for( i=0; i<6; i++ ) | |
1552 | { | |
1553 | pBssInfo->macaddr[i] = pProbeRspHeader->sa[i]; | |
1554 | } | |
1555 | ||
1556 | /* get bssid */ | |
1557 | for( i=0; i<6; i++ ) | |
1558 | { | |
1559 | pBssInfo->bssid[i] = pProbeRspHeader->bssid[i]; | |
1560 | } | |
1561 | ||
1562 | /* get timestamp */ | |
1563 | for( i=0; i<8; i++ ) | |
1564 | { | |
1565 | pBssInfo->timeStamp[i] = pProbeRspHeader->timeStamp[i]; | |
1566 | } | |
1567 | ||
1568 | /* get beacon interval */ | |
1569 | pBssInfo->beaconInterval[0] = pProbeRspHeader->beaconInterval[0]; | |
1570 | pBssInfo->beaconInterval[1] = pProbeRspHeader->beaconInterval[1]; | |
1571 | ||
1572 | /* get capability */ | |
1573 | pBssInfo->capability[0] = pProbeRspHeader->capability[0]; | |
1574 | pBssInfo->capability[1] = pProbeRspHeader->capability[1]; | |
1575 | ||
1576 | /* Copy frame body */ | |
1577 | offset = 36; // Copy from the start of variable IE | |
1578 | pBssInfo->frameBodysize = zfwBufGetSize(dev, buf)-offset; | |
1579 | if (pBssInfo->frameBodysize > (ZM_MAX_PROBE_FRAME_BODY_SIZE-1)) | |
1580 | { | |
1581 | pBssInfo->frameBodysize = ZM_MAX_PROBE_FRAME_BODY_SIZE-1; | |
1582 | } | |
1583 | accumulateLen = 0; | |
1584 | do | |
1585 | { | |
1586 | eachIElength = zmw_rx_buf_readb(dev, buf, offset + accumulateLen+1) + 2; //Len+(EID+Data) | |
1587 | ||
1588 | if ( (eachIElength >= 2) | |
1589 | && ((accumulateLen + eachIElength) <= pBssInfo->frameBodysize) ) | |
1590 | { | |
1591 | zfCopyFromRxBuffer(dev, buf, pBssInfo->frameBody+accumulateLen, offset+accumulateLen, eachIElength); | |
1592 | accumulateLen+=(u16_t)eachIElength; | |
1593 | } | |
1594 | else | |
1595 | { | |
1596 | zm_msg0_mm(ZM_LV_1, "probersp frameBodysize abnormal"); | |
1597 | break; | |
1598 | } | |
1599 | } | |
1600 | while(accumulateLen < pBssInfo->frameBodysize); | |
1601 | pBssInfo->frameBodysize = accumulateLen; | |
1602 | ||
1603 | /* get supported rates */ | |
92363b52 JP |
1604 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_SUPPORT_RATE); |
1605 | if (offset == 0xffff) | |
4bd43f50 LR |
1606 | { |
1607 | zm_debug_msg0("EID(supported rates) not found"); | |
1608 | goto zlError; | |
1609 | } | |
1610 | ||
1611 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1612 | if ( length == 0 || length > ZM_MAX_SUPP_RATES_IE_SIZE) | |
1613 | { | |
1614 | zm_msg0_mm(ZM_LV_0, "Supported rates IE length abnormal"); | |
1615 | goto zlError; | |
1616 | } | |
1617 | zfCopyFromRxBuffer(dev, buf, pBssInfo->supportedRates, offset, length+2); | |
1618 | ||
1619 | ||
1620 | ||
1621 | /* get Country information */ | |
92363b52 JP |
1622 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_COUNTRY); |
1623 | if (offset != 0xffff) | |
4bd43f50 LR |
1624 | { |
1625 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1626 | if (length > ZM_MAX_COUNTRY_INFO_SIZE) | |
1627 | { | |
1628 | length = ZM_MAX_COUNTRY_INFO_SIZE; | |
1629 | } | |
1630 | zfCopyFromRxBuffer(dev, buf, pBssInfo->countryInfo, offset, length+2); | |
1631 | /* check 802.11d support data */ | |
1632 | if (wd->sta.b802_11D) | |
1633 | { | |
1634 | zfHpGetRegulationTablefromISO(dev, (u8_t *)&pBssInfo->countryInfo, 3); | |
1635 | /* only set regulatory one time */ | |
1636 | wd->sta.b802_11D = 0; | |
1637 | } | |
1638 | } | |
1639 | ||
1640 | /* get ERP information */ | |
92363b52 JP |
1641 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_ERP); |
1642 | if (offset != 0xffff) | |
4bd43f50 LR |
1643 | { |
1644 | pBssInfo->erp = zmw_rx_buf_readb(dev, buf, offset+2); | |
1645 | } | |
1646 | ||
1647 | /* get extended supported rates */ | |
92363b52 JP |
1648 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_RATE); |
1649 | if (offset != 0xffff) | |
4bd43f50 LR |
1650 | { |
1651 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1652 | if (length > ZM_MAX_SUPP_RATES_IE_SIZE) | |
1653 | { | |
1654 | zm_msg0_mm(ZM_LV_0, "Extended rates IE length abnormal"); | |
1655 | goto zlError; | |
1656 | } | |
1657 | zfCopyFromRxBuffer(dev, buf, pBssInfo->extSupportedRates, offset, length+2); | |
1658 | } | |
1659 | else | |
1660 | { | |
1661 | pBssInfo->extSupportedRates[0] = 0; | |
1662 | pBssInfo->extSupportedRates[1] = 0; | |
1663 | } | |
1664 | ||
1665 | /* get WPA IE */ | |
92363b52 JP |
1666 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_WPA_IE); |
1667 | if (offset != 0xffff) | |
4bd43f50 LR |
1668 | { |
1669 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1670 | if (length > ZM_MAX_IE_SIZE) | |
1671 | { | |
1672 | length = ZM_MAX_IE_SIZE; | |
1673 | } | |
1674 | zfCopyFromRxBuffer(dev, buf, pBssInfo->wpaIe, offset, length+2); | |
1675 | pBssInfo->securityType = ZM_SECURITY_TYPE_WPA; | |
1676 | } | |
1677 | else | |
1678 | { | |
1679 | pBssInfo->wpaIe[1] = 0; | |
1680 | } | |
1681 | ||
1682 | /* get WPS IE */ | |
92363b52 JP |
1683 | offset = zfFindWifiElement(dev, buf, 4, 0xff); |
1684 | if (offset != 0xffff) | |
4bd43f50 LR |
1685 | { |
1686 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1687 | if (length > ZM_MAX_WPS_IE_SIZE ) | |
1688 | { | |
1689 | length = ZM_MAX_WPS_IE_SIZE; | |
1690 | } | |
1691 | zfCopyFromRxBuffer(dev, buf, pBssInfo->wscIe, offset, length+2); | |
1692 | } | |
1693 | else | |
1694 | { | |
1695 | pBssInfo->wscIe[1] = 0; | |
1696 | } | |
1697 | ||
1698 | /* get SuperG IE */ | |
92363b52 JP |
1699 | offset = zfFindSuperGElement(dev, buf, ZM_WLAN_EID_VENDOR_PRIVATE); |
1700 | if (offset != 0xffff) | |
4bd43f50 LR |
1701 | { |
1702 | pBssInfo->apCap |= ZM_SuperG_AP; | |
1703 | } | |
1704 | ||
1705 | /* get XR IE */ | |
92363b52 JP |
1706 | offset = zfFindXRElement(dev, buf, ZM_WLAN_EID_VENDOR_PRIVATE); |
1707 | if (offset != 0xffff) | |
4bd43f50 LR |
1708 | { |
1709 | pBssInfo->apCap |= ZM_XR_AP; | |
1710 | } | |
1711 | ||
1712 | /* get RSN IE */ | |
92363b52 JP |
1713 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_RSN_IE); |
1714 | if (offset != 0xffff) | |
4bd43f50 LR |
1715 | { |
1716 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1717 | if (length > ZM_MAX_IE_SIZE) | |
1718 | { | |
1719 | length = ZM_MAX_IE_SIZE; | |
1720 | } | |
1721 | zfCopyFromRxBuffer(dev, buf, pBssInfo->rsnIe, offset, length+2); | |
1722 | pBssInfo->securityType = ZM_SECURITY_TYPE_WPA; | |
1723 | } | |
1724 | else | |
1725 | { | |
1726 | pBssInfo->rsnIe[1] = 0; | |
1727 | } | |
1728 | #ifdef ZM_ENABLE_CENC | |
1729 | /* get CENC IE */ | |
92363b52 JP |
1730 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_CENC_IE); |
1731 | if (offset != 0xffff) | |
4bd43f50 LR |
1732 | { |
1733 | length = zmw_rx_buf_readb(dev, buf, offset+1); | |
1734 | if (length > ZM_MAX_IE_SIZE ) | |
1735 | { | |
1736 | length = ZM_MAX_IE_SIZE; | |
1737 | } | |
1738 | zfCopyFromRxBuffer(dev, buf, pBssInfo->cencIe, offset, length+2); | |
1739 | pBssInfo->securityType = ZM_SECURITY_TYPE_CENC; | |
1740 | pBssInfo->capability[0] &= 0xffef; | |
1741 | } | |
1742 | else | |
1743 | { | |
1744 | pBssInfo->cencIe[1] = 0; | |
1745 | } | |
1746 | #endif //ZM_ENABLE_CENC | |
1747 | /* get WME Parameter IE, probe rsp may contain WME parameter element */ | |
1748 | //if ( wd->bQoSEnable ) | |
1749 | { | |
92363b52 JP |
1750 | offset = zfFindWifiElement(dev, buf, 2, 1); |
1751 | if (offset != 0xffff) | |
4bd43f50 LR |
1752 | { |
1753 | apQosInfo = zmw_rx_buf_readb(dev, buf, offset+8) & 0x80; | |
1754 | pBssInfo->wmeSupport = 1 | apQosInfo; | |
1755 | } | |
1756 | else if ((offset = zfFindWifiElement(dev, buf, 2, 0)) != 0xffff) | |
1757 | { | |
1758 | apQosInfo = zmw_rx_buf_readb(dev, buf, offset+8) & 0x80; | |
1759 | pBssInfo->wmeSupport = 1 | apQosInfo; | |
1760 | } | |
1761 | else | |
1762 | { | |
1763 | pBssInfo->wmeSupport = 0; | |
1764 | } | |
1765 | } | |
1766 | //CWYang(+) | |
92363b52 JP |
1767 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_HT_CAPABILITY); |
1768 | if (offset != 0xffff) | |
4bd43f50 LR |
1769 | { |
1770 | /* 11n AP */ | |
1771 | pBssInfo->EnableHT = 1; | |
1772 | if (zmw_rx_buf_readb(dev, buf, offset+1) & 0x02) | |
1773 | { | |
1774 | pBssInfo->enableHT40 = 1; | |
1775 | } | |
1776 | else | |
1777 | { | |
1778 | pBssInfo->enableHT40 = 0; | |
1779 | } | |
1780 | ||
1781 | if (zmw_rx_buf_readb(dev, buf, offset+1) & 0x40) | |
1782 | { | |
1783 | pBssInfo->SG40 = 1; | |
1784 | } | |
1785 | else | |
1786 | { | |
1787 | pBssInfo->SG40 = 0; | |
1788 | } | |
1789 | } | |
1790 | else if ((offset = zfFindElement(dev, buf, ZM_WLAN_PREN2_EID_HTCAPABILITY)) != 0xffff) | |
1791 | { | |
1792 | /* 11n AP */ | |
1793 | pBssInfo->EnableHT = 1; | |
1794 | pBssInfo->apCap |= ZM_All11N_AP; | |
1795 | if (zmw_rx_buf_readb(dev, buf, offset+2) & 0x02) | |
1796 | { | |
1797 | pBssInfo->enableHT40 = 1; | |
1798 | } | |
1799 | else | |
1800 | { | |
1801 | pBssInfo->enableHT40 = 0; | |
1802 | } | |
1803 | ||
1804 | if (zmw_rx_buf_readb(dev, buf, offset+2) & 0x40) | |
1805 | { | |
1806 | pBssInfo->SG40 = 1; | |
1807 | } | |
1808 | else | |
1809 | { | |
1810 | pBssInfo->SG40 = 0; | |
1811 | } | |
1812 | } | |
1813 | else | |
1814 | { | |
1815 | pBssInfo->EnableHT = 0; | |
1816 | } | |
1817 | /* HT information */ | |
92363b52 JP |
1818 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY); |
1819 | if (offset != 0xffff) | |
4bd43f50 LR |
1820 | { |
1821 | /* atheros pre n */ | |
1822 | pBssInfo->extChOffset = zmw_rx_buf_readb(dev, buf, offset+2) & 0x03; | |
1823 | } | |
1824 | else if ((offset = zfFindElement(dev, buf, ZM_WLAN_PREN2_EID_HTINFORMATION)) != 0xffff) | |
1825 | { | |
1826 | /* pre n 2.0 standard */ | |
1827 | pBssInfo->extChOffset = zmw_rx_buf_readb(dev, buf, offset+3) & 0x03; | |
1828 | } | |
1829 | else | |
1830 | { | |
1831 | pBssInfo->extChOffset = 0; | |
1832 | } | |
1833 | ||
1834 | if ( (pBssInfo->enableHT40 == 1) | |
1835 | && ((pBssInfo->extChOffset != 1) && (pBssInfo->extChOffset != 3)) ) | |
1836 | { | |
1837 | pBssInfo->enableHT40 = 0; | |
1838 | } | |
1839 | ||
1840 | if (pBssInfo->enableHT40 == 1) | |
1841 | { | |
1842 | if (zfHpIsAllowedChannel(dev, pBssInfo->frequency+((pBssInfo->extChOffset==1)?20:-20)) == 0) | |
1843 | { | |
1844 | /* if extension channel is not an allowed channel, treat AP as non-HT mode */ | |
1845 | pBssInfo->EnableHT = 0; | |
1846 | pBssInfo->enableHT40 = 0; | |
1847 | pBssInfo->extChOffset = 0; | |
1848 | } | |
1849 | } | |
1850 | ||
1851 | /* get ATH Extended Capability */ | |
1852 | if ( ((offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY)) != 0xffff)&& | |
1853 | ((offset = zfFindBrdcmMrvlRlnkExtCap(dev, buf)) == 0xffff)) | |
1854 | ||
1855 | { | |
1856 | pBssInfo->athOwlAp = 1; | |
1857 | } | |
1858 | else | |
1859 | { | |
1860 | pBssInfo->athOwlAp = 0; | |
1861 | } | |
1862 | ||
1863 | /* get Broadcom Extended Capability */ | |
1864 | if ( (pBssInfo->EnableHT == 1) //((offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY)) != 0xffff) | |
1865 | && ((offset = zfFindBroadcomExtCap(dev, buf)) != 0xffff) ) | |
1866 | { | |
1867 | pBssInfo->broadcomHTAp = 1; | |
1868 | } | |
1869 | else | |
1870 | { | |
1871 | pBssInfo->broadcomHTAp = 0; | |
1872 | } | |
1873 | ||
1874 | /* get Marvel Extended Capability */ | |
92363b52 JP |
1875 | offset = zfFindMarvelExtCap(dev, buf); |
1876 | if (offset != 0xffff) | |
4bd43f50 LR |
1877 | { |
1878 | pBssInfo->marvelAp = 1; | |
1879 | } | |
1880 | else | |
1881 | { | |
1882 | pBssInfo->marvelAp = 0; | |
1883 | } | |
1884 | ||
1885 | /* get ATIM window */ | |
92363b52 JP |
1886 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_IBSS); |
1887 | if (offset != 0xffff ) | |
4bd43f50 LR |
1888 | { |
1889 | pBssInfo->atimWindow = zmw_rx_buf_readh(dev, buf,offset+2); | |
1890 | } | |
1891 | ||
1892 | /* Fit for support mode */ | |
1893 | if (pBssInfo->frequency > 3000) { | |
1894 | if (wd->supportMode & ZM_WIRELESS_MODE_5_N) { | |
1895 | #if 0 | |
1896 | if (wd->supportMode & ZM_WIRELESS_MODE_5_54) { | |
1897 | /* support mode: a, n */ | |
1898 | /* do nothing */ | |
1899 | } else { | |
1900 | /* support mode: n */ | |
1901 | /* reject non-n bss info */ | |
1902 | if (!pBssInfo->EnableHT) { | |
1903 | goto zlError2; | |
1904 | } | |
1905 | } | |
1906 | #endif | |
1907 | } else { | |
1908 | if (wd->supportMode & ZM_WIRELESS_MODE_5_54) { | |
1909 | /* support mode: a */ | |
1910 | /* delete n mode information */ | |
1911 | pBssInfo->EnableHT = 0; | |
1912 | pBssInfo->enableHT40 = 0; | |
1913 | pBssInfo->apCap &= (~ZM_All11N_AP); | |
1914 | pBssInfo->extChOffset = 0; | |
1915 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1916 | pBssInfo->frameBodysize, ZM_WLAN_EID_HT_CAPABILITY); | |
1917 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1918 | pBssInfo->frameBodysize, ZM_WLAN_PREN2_EID_HTCAPABILITY); | |
1919 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1920 | pBssInfo->frameBodysize, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY); | |
1921 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1922 | pBssInfo->frameBodysize, ZM_WLAN_PREN2_EID_HTINFORMATION); | |
1923 | } else { | |
1924 | /* support mode: none */ | |
1925 | goto zlError2; | |
1926 | } | |
1927 | } | |
1928 | } else { | |
1929 | if (wd->supportMode & ZM_WIRELESS_MODE_24_N) { | |
1930 | #if 0 | |
1931 | if (wd->supportMode & ZM_WIRELESS_MODE_24_54) { | |
1932 | if (wd->supportMode & ZM_WIRELESS_MODE_24_11) { | |
1933 | /* support mode: b, g, n */ | |
1934 | /* do nothing */ | |
1935 | } else { | |
1936 | /* support mode: g, n */ | |
1937 | /* reject b-only bss info */ | |
1938 | if ( (!pBssInfo->EnableHT) | |
1939 | && (pBssInfo->extSupportedRates[1] == 0) ) { | |
1940 | goto zlError2; | |
1941 | } | |
1942 | } | |
1943 | } else { | |
1944 | if (wd->supportMode & ZM_WIRELESS_MODE_24_11) { | |
1945 | /* support mode: b, n */ | |
1946 | /* 1. reject g-only bss info | |
1947 | * 2. if non g-only, delete g mode information | |
1948 | */ | |
1949 | if ( !pBssInfo->EnableHT ) { | |
1950 | if ( zfIsGOnlyMode(dev, pBssInfo->frequency, pBssInfo->supportedRates) | |
1951 | || zfIsGOnlyMode(dev, pBssInfo->frequency, pBssInfo->extSupportedRates) ) { | |
1952 | goto zlError2; | |
1953 | } else { | |
1954 | zfGatherBMode(dev, pBssInfo->supportedRates, | |
1955 | pBssInfo->extSupportedRates); | |
1956 | pBssInfo->erp = 0; | |
1957 | ||
1958 | pBssInfo->frameBodysize = zfRemoveElement(dev, | |
1959 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
1960 | ZM_WLAN_EID_ERP); | |
1961 | pBssInfo->frameBodysize = zfRemoveElement(dev, | |
1962 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
1963 | ZM_WLAN_EID_EXTENDED_RATE); | |
1964 | ||
1965 | pBssInfo->frameBodysize = zfUpdateElement(dev, | |
1966 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
1967 | pBssInfo->supportedRates); | |
1968 | } | |
1969 | } | |
1970 | } else { | |
1971 | /* support mode: n */ | |
1972 | /* reject non-n bss info */ | |
1973 | if (!pBssInfo->EnableHT) { | |
1974 | goto zlError2; | |
1975 | } | |
1976 | } | |
1977 | } | |
1978 | #endif | |
1979 | } else { | |
1980 | /* delete n mode information */ | |
1981 | pBssInfo->EnableHT = 0; | |
1982 | pBssInfo->enableHT40 = 0; | |
1983 | pBssInfo->apCap &= (~ZM_All11N_AP); | |
1984 | pBssInfo->extChOffset = 0; | |
1985 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1986 | pBssInfo->frameBodysize, ZM_WLAN_EID_HT_CAPABILITY); | |
1987 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1988 | pBssInfo->frameBodysize, ZM_WLAN_PREN2_EID_HTCAPABILITY); | |
1989 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1990 | pBssInfo->frameBodysize, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY); | |
1991 | pBssInfo->frameBodysize = zfRemoveElement(dev, pBssInfo->frameBody, | |
1992 | pBssInfo->frameBodysize, ZM_WLAN_PREN2_EID_HTINFORMATION); | |
1993 | ||
1994 | if (wd->supportMode & ZM_WIRELESS_MODE_24_54) { | |
1995 | #if 0 | |
1996 | if (wd->supportMode & ZM_WIRELESS_MODE_24_11) { | |
1997 | /* support mode: b, g */ | |
1998 | /* delete n mode information */ | |
1999 | } else { | |
2000 | /* support mode: g */ | |
2001 | /* delete n mode information */ | |
2002 | /* reject b-only bss info */ | |
2003 | if (pBssInfo->extSupportedRates[1] == 0) { | |
2004 | goto zlError2; | |
2005 | } | |
2006 | } | |
2007 | #endif | |
2008 | } else { | |
2009 | if (wd->supportMode & ZM_WIRELESS_MODE_24_11) { | |
2010 | /* support mode: b */ | |
2011 | /* delete n mode information */ | |
2012 | if ( zfIsGOnlyMode(dev, pBssInfo->frequency, pBssInfo->supportedRates) | |
2013 | || zfIsGOnlyMode(dev, pBssInfo->frequency, pBssInfo->extSupportedRates) ) { | |
2014 | goto zlError2; | |
2015 | } else { | |
2016 | zfGatherBMode(dev, pBssInfo->supportedRates, | |
2017 | pBssInfo->extSupportedRates); | |
2018 | pBssInfo->erp = 0; | |
2019 | ||
2020 | pBssInfo->frameBodysize = zfRemoveElement(dev, | |
2021 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
2022 | ZM_WLAN_EID_ERP); | |
2023 | pBssInfo->frameBodysize = zfRemoveElement(dev, | |
2024 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
2025 | ZM_WLAN_EID_EXTENDED_RATE); | |
2026 | ||
2027 | pBssInfo->frameBodysize = zfUpdateElement(dev, | |
2028 | pBssInfo->frameBody, pBssInfo->frameBodysize, | |
2029 | pBssInfo->supportedRates); | |
2030 | } | |
2031 | } else { | |
2032 | /* support mode: none */ | |
2033 | goto zlError2; | |
2034 | } | |
2035 | } | |
2036 | } | |
2037 | } | |
2038 | ||
2039 | pBssInfo->flag |= ZM_BSS_INFO_VALID_BIT; | |
2040 | ||
2041 | zlUpdateRssi: | |
2042 | /* Update Timer information */ | |
2043 | pBssInfo->tick = wd->tick; | |
2044 | ||
2045 | /* Update ERP information */ | |
92363b52 JP |
2046 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_ERP); |
2047 | if (offset != 0xffff) | |
4bd43f50 LR |
2048 | { |
2049 | pBssInfo->erp = zmw_rx_buf_readb(dev, buf, offset+2); | |
2050 | } | |
2051 | ||
2052 | if( (s8_t)pBssInfo->signalStrength < (s8_t)AddInfo->Tail.Data.SignalStrength1 ) | |
2053 | { | |
2054 | /* Update signal strength */ | |
2055 | pBssInfo->signalStrength = (u8_t)AddInfo->Tail.Data.SignalStrength1; | |
2056 | /* Update signal quality */ | |
2057 | pBssInfo->signalQuality = (u8_t)(AddInfo->Tail.Data.SignalStrength1 * 2); | |
2058 | ||
2059 | /* Update the sorting value */ | |
2060 | pBssInfo->sortValue = zfComputeBssInfoWeightValue(dev, | |
2061 | (pBssInfo->supportedRates[6] + pBssInfo->extSupportedRates[0]), | |
2062 | pBssInfo->EnableHT, | |
2063 | pBssInfo->enableHT40, | |
2064 | pBssInfo->signalStrength); | |
2065 | } | |
2066 | ||
2067 | return 0; | |
2068 | ||
2069 | zlError: | |
2070 | ||
2071 | return 1; | |
2072 | ||
2073 | zlError2: | |
2074 | ||
2075 | return 2; | |
2076 | } | |
2077 | ||
2078 | void zfStaProcessBeacon(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* AddInfo) //CWYang(m) | |
2079 | { | |
2080 | /* Parse TIM and send PS-POLL in power saving mode */ | |
2081 | struct zsWlanBeaconFrameHeader* pBeaconHeader; | |
2082 | struct zsBssInfo* pBssInfo; | |
2083 | u8_t pBuf[sizeof(struct zsWlanBeaconFrameHeader)]; | |
2084 | u8_t bssid[6]; | |
2085 | int res; | |
2086 | ||
2087 | zmw_get_wlan_dev(dev); | |
2088 | ||
2089 | zmw_declare_for_critical_section(); | |
2090 | ||
2091 | /* sta routine jobs */ | |
2092 | zfStaProtErpMonitor(dev, buf); /* check protection mode */ | |
2093 | ||
2094 | if (zfStaIsConnected(dev)) | |
2095 | { | |
2096 | ZM_MAC_WORD_TO_BYTE(wd->sta.bssid, bssid); | |
2097 | ||
2098 | if ( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) | |
2099 | { | |
2100 | if ( zfRxBufferEqualToStr(dev, buf, bssid, ZM_WLAN_HEADER_A2_OFFSET, 6) ) | |
2101 | { | |
2102 | zfPowerSavingMgrProcessBeacon(dev, buf); | |
2103 | zfStaUpdateWmeParameter(dev, buf); | |
2104 | if (wd->sta.DFSEnable) | |
2105 | zfStaUpdateDot11HDFS(dev, buf); | |
2106 | if (wd->sta.TPCEnable) | |
2107 | zfStaUpdateDot11HTPC(dev, buf); | |
2108 | /* update signal strength and signal quality */ | |
2109 | zfStaSignalStatistic(dev, AddInfo->Tail.Data.SignalStrength1, | |
2110 | AddInfo->Tail.Data.SignalQuality); //CWYang(+) | |
2111 | wd->sta.rxBeaconCount++; | |
2112 | } | |
2113 | } | |
2114 | else if ( wd->wlanMode == ZM_MODE_IBSS ) | |
2115 | { | |
2116 | if ( zfRxBufferEqualToStr(dev, buf, bssid, ZM_WLAN_HEADER_A3_OFFSET, 6) ) | |
2117 | { | |
2118 | int res; | |
2119 | struct zsPartnerNotifyEvent event; | |
2120 | ||
2121 | zm_debug_msg0("20070916 Receive opposite Beacon!"); | |
2122 | zmw_enter_critical_section(dev); | |
2123 | wd->sta.ibssReceiveBeaconCount++; | |
2124 | zmw_leave_critical_section(dev); | |
2125 | ||
2126 | res = zfStaSetOppositeInfoFromRxBuf(dev, buf); | |
2127 | if ( res == 0 ) | |
2128 | { | |
2129 | // New peer station found. Notify the wrapper now | |
2130 | zfInitPartnerNotifyEvent(dev, buf, &event); | |
2131 | if (wd->zfcbIbssPartnerNotify != NULL) | |
2132 | { | |
2133 | wd->zfcbIbssPartnerNotify(dev, 1, &event); | |
2134 | } | |
2135 | } | |
2136 | /* update signal strength and signal quality */ | |
2137 | zfStaSignalStatistic(dev, AddInfo->Tail.Data.SignalStrength1, | |
2138 | AddInfo->Tail.Data.SignalQuality); //CWYang(+) | |
2139 | } | |
2140 | //else if ( wd->sta.ibssPartnerStatus == ZM_IBSS_PARTNER_LOST ) | |
2141 | // Why does this happen in IBSS?? The impact of Vista since | |
2142 | // we need to tell it the BSSID | |
2143 | #if 0 | |
2144 | else if ( wd->sta.oppositeCount == 0 ) | |
2145 | { /* IBSS merge if SSID matched */ | |
92363b52 JP |
2146 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_SSID); |
2147 | if (offset != 0xffff) | |
4bd43f50 LR |
2148 | { |
2149 | if ( (wd->sta.ssidLen == zmw_buf_readb(dev, buf, offset+1))&& | |
2150 | (zfRxBufferEqualToStr(dev, buf, wd->sta.ssid, | |
2151 | offset+2, wd->sta.ssidLen)) ) | |
2152 | { | |
2153 | capabilityInfo = zmw_buf_readh(dev, buf, 34); | |
2154 | ||
2155 | if ( capabilityInfo & ZM_BIT_1 ) | |
2156 | { | |
2157 | if ( (wd->sta.capability[0] & ZM_BIT_4) == | |
2158 | (capabilityInfo & ZM_BIT_4) ) | |
2159 | { | |
2160 | zm_debug_msg0("IBSS merge"); | |
2161 | zfCopyFromRxBuffer(dev, buf, bssid, | |
2162 | ZM_WLAN_HEADER_A3_OFFSET, 6); | |
2163 | zfUpdateBssid(dev, bssid); | |
2164 | } | |
2165 | } | |
2166 | } | |
2167 | } | |
2168 | } | |
2169 | #endif | |
2170 | } | |
2171 | } | |
2172 | ||
2173 | /* return if not channel scan */ | |
2174 | if ( !wd->sta.bChannelScan ) | |
2175 | { | |
2176 | goto zlReturn; | |
2177 | } | |
2178 | ||
2179 | zfCopyFromRxBuffer(dev, buf, pBuf, 0, sizeof(struct zsWlanBeaconFrameHeader)); | |
2180 | pBeaconHeader = (struct zsWlanBeaconFrameHeader*) pBuf; | |
2181 | ||
2182 | zmw_enter_critical_section(dev); | |
2183 | ||
2184 | //zm_debug_msg1("bss count = ", wd->sta.bssList.bssCount); | |
2185 | ||
2186 | pBssInfo = zfStaFindBssInfo(dev, buf, pBeaconHeader); | |
2187 | ||
2188 | if ( pBssInfo == NULL ) | |
2189 | { | |
2190 | /* Allocate a new entry if BSS not in the scan list */ | |
2191 | pBssInfo = zfBssInfoAllocate(dev); | |
2192 | if (pBssInfo != NULL) | |
2193 | { | |
2194 | res = zfStaInitBssInfo(dev, buf, pBeaconHeader, pBssInfo, AddInfo, 0); | |
2195 | //zfDumpSSID(pBssInfo->ssid[1], &(pBssInfo->ssid[2])); | |
2196 | if ( res != 0 ) | |
2197 | { | |
2198 | zfBssInfoFree(dev, pBssInfo); | |
2199 | } | |
2200 | else | |
2201 | { | |
2202 | zfBssInfoInsertToList(dev, pBssInfo); | |
2203 | } | |
2204 | } | |
2205 | } | |
2206 | else | |
2207 | { | |
2208 | res = zfStaInitBssInfo(dev, buf, pBeaconHeader, pBssInfo, AddInfo, 1); | |
2209 | if (res == 2) | |
2210 | { | |
2211 | zfBssInfoRemoveFromList(dev, pBssInfo); | |
2212 | zfBssInfoFree(dev, pBssInfo); | |
2213 | } | |
2214 | else if ( wd->wlanMode == ZM_MODE_IBSS ) | |
2215 | { | |
2216 | int idx; | |
2217 | ||
2218 | // It would reset the alive counter if the peer station is found! | |
2219 | zfStaFindFreeOpposite(dev, (u16_t *)pBssInfo->macaddr, &idx); | |
2220 | } | |
2221 | } | |
2222 | ||
2223 | zmw_leave_critical_section(dev); | |
2224 | ||
2225 | zlReturn: | |
2226 | ||
2227 | return; | |
2228 | } | |
2229 | ||
2230 | ||
2231 | void zfAuthFreqCompleteCb(zdev_t* dev) | |
2232 | { | |
2233 | zmw_get_wlan_dev(dev); | |
2234 | zmw_declare_for_critical_section(); | |
2235 | ||
2236 | zmw_enter_critical_section(dev); | |
2237 | ||
2238 | if (wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_COMPLETED) | |
2239 | { | |
2240 | zm_debug_msg0("ZM_STA_CONN_STATE_ASSOCIATE"); | |
2241 | wd->sta.connectTimer = wd->tick; | |
2242 | wd->sta.connectState = ZM_STA_CONN_STATE_ASSOCIATE; | |
2243 | } | |
2244 | ||
2245 | zmw_leave_critical_section(dev); | |
2246 | return; | |
2247 | } | |
2248 | ||
2249 | /************************************************************************/ | |
2250 | /* */ | |
2251 | /* FUNCTION DESCRIPTION zfProcessAuth */ | |
2252 | /* Process authenticate management frame. */ | |
2253 | /* */ | |
2254 | /* INPUTS */ | |
2255 | /* dev : device pointer */ | |
2256 | /* buf : auth frame buffer */ | |
2257 | /* */ | |
2258 | /* OUTPUTS */ | |
2259 | /* none */ | |
2260 | /* */ | |
2261 | /* AUTHOR */ | |
2262 | /* Stephen Chen ZyDAS Technology Corporation 2005.10 */ | |
2263 | /* */ | |
2264 | /************************************************************************/ | |
2265 | /* Note : AP allows one authenticating STA at a time, does not */ | |
2266 | /* support multiple authentication process. Make sure */ | |
2267 | /* authentication state machine will not be blocked due */ | |
2268 | /* to incompleted authentication handshake. */ | |
2269 | void zfStaProcessAuth(zdev_t* dev, zbuf_t* buf, u16_t* src, u16_t apId) | |
2270 | { | |
2271 | struct zsWlanAuthFrameHeader* pAuthFrame; | |
2272 | u8_t pBuf[sizeof(struct zsWlanAuthFrameHeader)]; | |
2273 | u32_t p1, p2; | |
2274 | ||
2275 | zmw_get_wlan_dev(dev); | |
2276 | zmw_declare_for_critical_section(); | |
2277 | ||
2278 | if ( !zfStaIsConnecting(dev) ) | |
2279 | { | |
2280 | return; | |
2281 | } | |
2282 | ||
2283 | pAuthFrame = (struct zsWlanAuthFrameHeader*) pBuf; | |
2284 | zfCopyFromRxBuffer(dev, buf, pBuf, 0, sizeof(struct zsWlanAuthFrameHeader)); | |
2285 | ||
2286 | if ( wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_OPEN ) | |
2287 | { | |
2288 | if ( (zmw_le16_to_cpu(pAuthFrame->seq) == 2)&& | |
2289 | (zmw_le16_to_cpu(pAuthFrame->algo) == 0)&& | |
2290 | (zmw_le16_to_cpu(pAuthFrame->status) == 0) ) | |
2291 | { | |
2292 | ||
2293 | zmw_enter_critical_section(dev); | |
2294 | wd->sta.connectTimer = wd->tick; | |
2295 | zm_debug_msg0("ZM_STA_CONN_STATE_AUTH_COMPLETED"); | |
2296 | wd->sta.connectState = ZM_STA_CONN_STATE_AUTH_COMPLETED; | |
2297 | zmw_leave_critical_section(dev); | |
2298 | ||
2299 | //Set channel according to AP's configuration | |
2300 | //Move to here because of Cisco 11n AP feature | |
2301 | zfCoreSetFrequencyEx(dev, wd->frequency, wd->BandWidth40, | |
2302 | wd->ExtOffset, zfAuthFreqCompleteCb); | |
2303 | ||
2304 | /* send association frame */ | |
2305 | if ( wd->sta.connectByReasso ) | |
2306 | { | |
2307 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_REASOCREQ, | |
2308 | wd->sta.bssid, 0, 0, 0); | |
2309 | } | |
2310 | else | |
2311 | { | |
2312 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_ASOCREQ, | |
2313 | wd->sta.bssid, 0, 0, 0); | |
2314 | } | |
2315 | ||
2316 | ||
2317 | } | |
2318 | else | |
2319 | { | |
2320 | zm_debug_msg1("authentication failed, status = ", | |
2321 | pAuthFrame->status); | |
2322 | ||
2323 | if (wd->sta.authMode == ZM_AUTH_MODE_AUTO) | |
2324 | { | |
2325 | wd->sta.bIsSharedKey = 1; | |
2326 | zfStaStartConnect(dev, wd->sta.bIsSharedKey); | |
2327 | } | |
2328 | else | |
2329 | { | |
2330 | zm_debug_msg0("ZM_STA_STATE_DISCONNECT"); | |
2331 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED, wd->sta.bssid, 3); | |
2332 | } | |
2333 | } | |
2334 | } | |
2335 | else if ( wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_SHARE_1 ) | |
2336 | { | |
2337 | if ( (zmw_le16_to_cpu(pAuthFrame->algo) == 1) && | |
2338 | (zmw_le16_to_cpu(pAuthFrame->seq) == 2) && | |
2339 | (zmw_le16_to_cpu(pAuthFrame->status) == 0)) | |
2340 | //&& (pAuthFrame->challengeText[1] <= 255) ) | |
2341 | { | |
2342 | zfMemoryCopy(wd->sta.challengeText, pAuthFrame->challengeText, | |
2343 | pAuthFrame->challengeText[1]+2); | |
2344 | ||
2345 | /* send the 3rd authentication frame */ | |
2346 | p1 = 0x30001; | |
2347 | p2 = 0; | |
2348 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_AUTH, | |
2349 | wd->sta.bssid, p1, p2, 0); | |
2350 | ||
2351 | zmw_enter_critical_section(dev); | |
2352 | wd->sta.connectTimer = wd->tick; | |
2353 | ||
2354 | zm_debug_msg0("ZM_STA_SUB_STATE_AUTH_SHARE_2"); | |
2355 | wd->sta.connectState = ZM_STA_CONN_STATE_AUTH_SHARE_2; | |
2356 | zmw_leave_critical_section(dev); | |
2357 | } | |
2358 | else | |
2359 | { | |
2360 | zm_debug_msg1("authentication failed, status = ", | |
2361 | pAuthFrame->status); | |
2362 | ||
2363 | zm_debug_msg0("ZM_STA_STATE_DISCONNECT"); | |
2364 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED, wd->sta.bssid, 3); | |
2365 | } | |
2366 | } | |
2367 | else if ( wd->sta.connectState == ZM_STA_CONN_STATE_AUTH_SHARE_2 ) | |
2368 | { | |
2369 | if ( (zmw_le16_to_cpu(pAuthFrame->algo) == 1)&& | |
2370 | (zmw_le16_to_cpu(pAuthFrame->seq) == 4)&& | |
2371 | (zmw_le16_to_cpu(pAuthFrame->status) == 0) ) | |
2372 | { | |
2373 | //Set channel according to AP's configuration | |
2374 | //Move to here because of Cisco 11n AP feature | |
2375 | zfCoreSetFrequencyEx(dev, wd->frequency, wd->BandWidth40, | |
2376 | wd->ExtOffset, NULL); | |
2377 | ||
2378 | /* send association frame */ | |
2379 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_ASOCREQ, | |
2380 | wd->sta.bssid, 0, 0, 0); | |
2381 | ||
2382 | zmw_enter_critical_section(dev); | |
2383 | wd->sta.connectTimer = wd->tick; | |
2384 | ||
2385 | zm_debug_msg0("ZM_STA_SUB_STATE_ASSOCIATE"); | |
2386 | wd->sta.connectState = ZM_STA_CONN_STATE_ASSOCIATE; | |
2387 | zmw_leave_critical_section(dev); | |
2388 | } | |
2389 | else | |
2390 | { | |
2391 | zm_debug_msg1("authentication failed, status = ", | |
2392 | pAuthFrame->status); | |
2393 | ||
2394 | zm_debug_msg0("ZM_STA_STATE_DISCONNECT"); | |
2395 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED, wd->sta.bssid, 3); | |
2396 | } | |
2397 | } | |
2398 | else | |
2399 | { | |
2400 | zm_debug_msg0("unknown case"); | |
2401 | } | |
2402 | } | |
2403 | ||
2404 | void zfStaProcessAsocReq(zdev_t* dev, zbuf_t* buf, u16_t* src, u16_t apId) | |
2405 | { | |
2406 | ||
2407 | return; | |
2408 | } | |
2409 | ||
2410 | void zfStaProcessAsocRsp(zdev_t* dev, zbuf_t* buf) | |
2411 | { | |
2412 | struct zsWlanAssoFrameHeader* pAssoFrame; | |
2413 | u8_t pBuf[sizeof(struct zsWlanAssoFrameHeader)]; | |
2414 | u16_t offset; | |
2415 | u32_t i; | |
2416 | u32_t oneTxStreamCap; | |
2417 | ||
2418 | zmw_get_wlan_dev(dev); | |
2419 | ||
2420 | if ( !zfStaIsConnecting(dev) ) | |
2421 | { | |
2422 | return; | |
2423 | } | |
2424 | ||
2425 | pAssoFrame = (struct zsWlanAssoFrameHeader*) pBuf; | |
2426 | zfCopyFromRxBuffer(dev, buf, pBuf, 0, sizeof(struct zsWlanAssoFrameHeader)); | |
2427 | ||
2428 | if ( wd->sta.connectState == ZM_STA_CONN_STATE_ASSOCIATE ) | |
2429 | { | |
2430 | if ( pAssoFrame->status == 0 ) | |
2431 | { | |
2432 | zm_debug_msg0("ZM_STA_STATE_CONNECTED"); | |
2433 | ||
2434 | if (wd->sta.EnableHT == 1) | |
2435 | { | |
2436 | wd->sta.wmeConnected = 1; | |
2437 | } | |
2438 | if ((wd->sta.wmeEnabled & ZM_STA_WME_ENABLE_BIT) != 0) //WME enabled | |
2439 | { | |
2440 | /* Asoc rsp may contain WME parameter element */ | |
92363b52 JP |
2441 | offset = zfFindWifiElement(dev, buf, 2, 1); |
2442 | if (offset != 0xffff) | |
4bd43f50 LR |
2443 | { |
2444 | zm_debug_msg0("WME enable"); | |
2445 | wd->sta.wmeConnected = 1; | |
2446 | if ((wd->sta.wmeEnabled & ZM_STA_UAPSD_ENABLE_BIT) != 0) | |
2447 | { | |
2448 | if ((zmw_rx_buf_readb(dev, buf, offset+8) & 0x80) != 0) | |
2449 | { | |
2450 | zm_debug_msg0("UAPSD enable"); | |
2451 | wd->sta.qosInfo = wd->sta.wmeQosInfo; | |
2452 | } | |
2453 | } | |
2454 | ||
2455 | zfStaUpdateWmeParameter(dev, buf); | |
2456 | } | |
2457 | } | |
2458 | ||
2459 | ||
2460 | //Store asoc response frame body, for VISTA only | |
2461 | wd->sta.asocRspFrameBodySize = zfwBufGetSize(dev, buf)-24; | |
2462 | if (wd->sta.asocRspFrameBodySize > ZM_CACHED_FRAMEBODY_SIZE) | |
2463 | { | |
2464 | wd->sta.asocRspFrameBodySize = ZM_CACHED_FRAMEBODY_SIZE; | |
2465 | } | |
2466 | for (i=0; i<wd->sta.asocRspFrameBodySize; i++) | |
2467 | { | |
2468 | wd->sta.asocRspFrameBody[i] = zmw_rx_buf_readb(dev, buf, i+24); | |
2469 | } | |
2470 | ||
2471 | zfStaStoreAsocRspIe(dev, buf); | |
2472 | if (wd->sta.EnableHT && | |
2473 | ((wd->sta.ie.HtCap.HtCapInfo & HTCAP_SupChannelWidthSet) != 0) && | |
2474 | (wd->ExtOffset != 0)) | |
2475 | { | |
2476 | wd->sta.htCtrlBandwidth = 1; | |
2477 | } | |
2478 | else | |
2479 | { | |
2480 | wd->sta.htCtrlBandwidth = 0; | |
2481 | } | |
2482 | ||
2483 | //Set channel according to AP's configuration | |
2484 | //zfCoreSetFrequencyEx(dev, wd->frequency, wd->BandWidth40, | |
2485 | // wd->ExtOffset, NULL); | |
2486 | ||
2487 | if (wd->sta.EnableHT == 1) | |
2488 | { | |
2489 | wd->addbaComplete = 0; | |
2490 | ||
2491 | if ((wd->sta.SWEncryptEnable & ZM_SW_TKIP_ENCRY_EN) == 0 && | |
2492 | (wd->sta.SWEncryptEnable & ZM_SW_WEP_ENCRY_EN) == 0) | |
2493 | { | |
2494 | wd->addbaCount = 1; | |
2495 | zfAggSendAddbaRequest(dev, wd->sta.bssid, 0, 0); | |
2496 | zfTimerSchedule(dev, ZM_EVENT_TIMEOUT_ADDBA, 100); | |
2497 | } | |
2498 | } | |
2499 | ||
2500 | /* set RIFS support */ | |
2501 | if(wd->sta.ie.HtInfo.ChannelInfo & ExtHtCap_RIFSMode) | |
2502 | { | |
2503 | wd->sta.HT2040 = 1; | |
2504 | // zfHpSetRifs(dev, wd->sta.EnableHT, 1, (wd->sta.currentFrequency < 3000)? 1:0); | |
2505 | } | |
2506 | ||
2507 | wd->sta.aid = pAssoFrame->aid & 0x3fff; | |
2508 | wd->sta.oppositeCount = 0; /* reset opposite count */ | |
2509 | zfStaSetOppositeInfoFromRxBuf(dev, buf); | |
2510 | ||
2511 | wd->sta.rxBeaconCount = 16; | |
2512 | ||
2513 | zfChangeAdapterState(dev, ZM_STA_STATE_CONNECTED); | |
2514 | wd->sta.connPowerInHalfDbm = zfHpGetTransmitPower(dev); | |
2515 | if (wd->zfcbConnectNotify != NULL) | |
2516 | { | |
2517 | if (wd->sta.EnableHT != 0) /* 11n */ | |
2518 | { | |
2519 | oneTxStreamCap = (zfHpCapability(dev) & ZM_HP_CAP_11N_ONE_TX_STREAM); | |
2520 | if (wd->sta.htCtrlBandwidth == 1) /* HT40*/ | |
2521 | { | |
2522 | if(oneTxStreamCap) /* one Tx stream */ | |
2523 | { | |
2524 | if (wd->sta.SG40) | |
2525 | { | |
2526 | wd->CurrentTxRateKbps = 150000; | |
2527 | wd->CurrentRxRateKbps = 300000; | |
2528 | } | |
2529 | else | |
2530 | { | |
2531 | wd->CurrentTxRateKbps = 135000; | |
2532 | wd->CurrentRxRateKbps = 270000; | |
2533 | } | |
2534 | } | |
2535 | else /* Two Tx streams */ | |
2536 | { | |
2537 | if (wd->sta.SG40) | |
2538 | { | |
2539 | wd->CurrentTxRateKbps = 300000; | |
2540 | wd->CurrentRxRateKbps = 300000; | |
2541 | } | |
2542 | else | |
2543 | { | |
2544 | wd->CurrentTxRateKbps = 270000; | |
2545 | wd->CurrentRxRateKbps = 270000; | |
2546 | } | |
2547 | } | |
2548 | } | |
2549 | else /* HT20 */ | |
2550 | { | |
2551 | if(oneTxStreamCap) /* one Tx stream */ | |
2552 | { | |
2553 | wd->CurrentTxRateKbps = 650000; | |
2554 | wd->CurrentRxRateKbps = 130000; | |
2555 | } | |
2556 | else /* Two Tx streams */ | |
2557 | { | |
2558 | wd->CurrentTxRateKbps = 130000; | |
2559 | wd->CurrentRxRateKbps = 130000; | |
2560 | } | |
2561 | } | |
2562 | } | |
2563 | else /* 11abg */ | |
2564 | { | |
2565 | if (wd->sta.connection_11b != 0) | |
2566 | { | |
2567 | wd->CurrentTxRateKbps = 11000; | |
2568 | wd->CurrentRxRateKbps = 11000; | |
2569 | } | |
2570 | else | |
2571 | { | |
2572 | wd->CurrentTxRateKbps = 54000; | |
2573 | wd->CurrentRxRateKbps = 54000; | |
2574 | } | |
2575 | } | |
2576 | ||
2577 | ||
2578 | wd->zfcbConnectNotify(dev, ZM_STATUS_MEDIA_CONNECT, wd->sta.bssid); | |
2579 | } | |
2580 | wd->sta.connectByReasso = TRUE; | |
2581 | wd->sta.failCntOfReasso = 0; | |
2582 | ||
2583 | zfPowerSavingMgrConnectNotify(dev); | |
2584 | ||
2585 | /* Disable here because fixed rate is only for test, TBD. */ | |
2586 | //if (wd->sta.EnableHT) | |
2587 | //{ | |
2588 | // wd->txMCS = 7; //Rate = 65Mbps | |
2589 | // wd->txMT = 2; // Ht rate | |
2590 | // wd->enableAggregation = 2; // Enable Aggregation | |
2591 | //} | |
2592 | } | |
2593 | else | |
2594 | { | |
2595 | zm_debug_msg1("association failed, status = ", | |
2596 | pAssoFrame->status); | |
2597 | ||
2598 | zm_debug_msg0("ZM_STA_STATE_DISCONNECT"); | |
2599 | wd->sta.connectByReasso = FALSE; | |
2600 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_ASOC_FAILED, wd->sta.bssid, 3); | |
2601 | } | |
2602 | } | |
2603 | ||
2604 | } | |
2605 | ||
2606 | void zfStaStoreAsocRspIe(zdev_t* dev, zbuf_t* buf) | |
2607 | { | |
2608 | u16_t offset; | |
2609 | u32_t i; | |
2610 | u16_t length; | |
2611 | u8_t *htcap; | |
2612 | u8_t asocBw40 = 0; | |
2613 | u8_t asocExtOffset = 0; | |
2614 | ||
2615 | zmw_get_wlan_dev(dev); | |
2616 | ||
2617 | for (i=0; i<wd->sta.asocRspFrameBodySize; i++) | |
2618 | { | |
2619 | wd->sta.asocRspFrameBody[i] = zmw_rx_buf_readb(dev, buf, i+24); | |
2620 | } | |
2621 | ||
2622 | /* HT capabilities: 28 octets */ | |
2623 | if ( ((wd->sta.currentFrequency > 3000) && !(wd->supportMode & ZM_WIRELESS_MODE_5_N)) | |
2624 | || ((wd->sta.currentFrequency < 3000) && !(wd->supportMode & ZM_WIRELESS_MODE_24_N)) ) | |
2625 | { | |
2626 | /* not 11n AP */ | |
2627 | htcap = (u8_t *)&wd->sta.ie.HtCap; | |
2628 | for (i=0; i<28; i++) | |
2629 | { | |
2630 | htcap[i] = 0; | |
2631 | } | |
2632 | wd->BandWidth40 = 0; | |
2633 | wd->ExtOffset = 0; | |
2634 | return; | |
2635 | } | |
2636 | ||
92363b52 JP |
2637 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_HT_CAPABILITY); |
2638 | if (offset != 0xffff) | |
4bd43f50 LR |
2639 | { |
2640 | /* atheros pre n */ | |
2641 | zm_debug_msg0("atheros pre n"); | |
2642 | htcap = (u8_t *)&wd->sta.ie.HtCap; | |
2643 | htcap[0] = zmw_rx_buf_readb(dev, buf, offset); | |
2644 | htcap[1] = 26; | |
2645 | for (i=1; i<=26; i++) | |
2646 | { | |
2647 | htcap[i+1] = zmw_rx_buf_readb(dev, buf, offset + i); | |
2648 | zm_msg2_mm(ZM_LV_1, "ASOC: HT Capabilities, htcap=", htcap[i+1]); | |
2649 | } | |
2650 | } | |
2651 | else if ((offset = zfFindElement(dev, buf, ZM_WLAN_PREN2_EID_HTCAPABILITY)) != 0xffff) | |
2652 | { | |
2653 | /* pre n 2.0 standard */ | |
2654 | zm_debug_msg0("pre n 2.0 standard"); | |
2655 | htcap = (u8_t *)&wd->sta.ie.HtCap; | |
2656 | for (i=0; i<28; i++) | |
2657 | { | |
2658 | htcap[i] = zmw_rx_buf_readb(dev, buf, offset + i); | |
2659 | zm_msg2_mm(ZM_LV_1, "ASOC: HT Capabilities, htcap=", htcap[i]); | |
2660 | } | |
2661 | } | |
2662 | else | |
2663 | { | |
2664 | /* not 11n AP */ | |
2665 | htcap = (u8_t *)&wd->sta.ie.HtCap; | |
2666 | for (i=0; i<28; i++) | |
2667 | { | |
2668 | htcap[i] = 0; | |
2669 | } | |
2670 | wd->BandWidth40 = 0; | |
2671 | wd->ExtOffset = 0; | |
2672 | return; | |
2673 | } | |
2674 | ||
2675 | asocBw40 = (u8_t)((wd->sta.ie.HtCap.HtCapInfo & HTCAP_SupChannelWidthSet) >> 1); | |
2676 | ||
2677 | /* HT information */ | |
92363b52 JP |
2678 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY); |
2679 | if (offset != 0xffff) | |
4bd43f50 LR |
2680 | { |
2681 | /* atheros pre n */ | |
2682 | zm_debug_msg0("atheros pre n HTINFO"); | |
2683 | length = 22; | |
2684 | htcap = (u8_t *)&wd->sta.ie.HtInfo; | |
2685 | htcap[0] = zmw_rx_buf_readb(dev, buf, offset); | |
2686 | htcap[1] = 22; | |
2687 | for (i=1; i<=22; i++) | |
2688 | { | |
2689 | htcap[i+1] = zmw_rx_buf_readb(dev, buf, offset + i); | |
2690 | zm_msg2_mm(ZM_LV_1, "ASOC: HT Info, htinfo=", htcap[i+1]); | |
2691 | } | |
2692 | } | |
2693 | else if ((offset = zfFindElement(dev, buf, ZM_WLAN_PREN2_EID_HTINFORMATION)) != 0xffff) | |
2694 | { | |
2695 | /* pre n 2.0 standard */ | |
2696 | zm_debug_msg0("pre n 2.0 standard HTINFO"); | |
2697 | length = zmw_rx_buf_readb(dev, buf, offset + 1); | |
2698 | htcap = (u8_t *)&wd->sta.ie.HtInfo; | |
2699 | for (i=0; i<24; i++) | |
2700 | { | |
2701 | htcap[i] = zmw_rx_buf_readb(dev, buf, offset + i); | |
2702 | zm_msg2_mm(ZM_LV_1, "ASOC: HT Info, htinfo=", htcap[i]); | |
2703 | } | |
2704 | } | |
2705 | else | |
2706 | { | |
2707 | zm_debug_msg0("no HTINFO"); | |
2708 | htcap = (u8_t *)&wd->sta.ie.HtInfo; | |
2709 | for (i=0; i<24; i++) | |
2710 | { | |
2711 | htcap[i] = 0; | |
2712 | } | |
2713 | } | |
2714 | asocExtOffset = wd->sta.ie.HtInfo.ChannelInfo & ExtHtCap_ExtChannelOffsetBelow; | |
2715 | ||
2716 | if ((wd->sta.EnableHT == 1) && (asocBw40 == 1) && ((asocExtOffset == 1) || (asocExtOffset == 3))) | |
2717 | { | |
2718 | wd->BandWidth40 = asocBw40; | |
2719 | wd->ExtOffset = asocExtOffset; | |
2720 | } | |
2721 | else | |
2722 | { | |
2723 | wd->BandWidth40 = 0; | |
2724 | wd->ExtOffset = 0; | |
2725 | } | |
2726 | ||
2727 | return; | |
2728 | } | |
2729 | ||
2730 | void zfStaProcessDeauth(zdev_t* dev, zbuf_t* buf) | |
2731 | { | |
2732 | u16_t apMacAddr[3]; | |
2733 | ||
2734 | zmw_get_wlan_dev(dev); | |
2735 | zmw_declare_for_critical_section(); | |
2736 | ||
2737 | /* STA : if SA=connected AP then disconnect with AP */ | |
2738 | if ( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) | |
2739 | { | |
2740 | apMacAddr[0] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET); | |
2741 | apMacAddr[1] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET+2); | |
2742 | apMacAddr[2] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET+4); | |
2743 | if ((apMacAddr[0] == wd->sta.bssid[0]) && (apMacAddr[1] == wd->sta.bssid[1]) && (apMacAddr[2] == wd->sta.bssid[2])) | |
2744 | { | |
2745 | if (zfwBufGetSize(dev, buf) >= 24+2) //not a malformed frame | |
2746 | { | |
2747 | if ( zfStaIsConnected(dev) ) | |
2748 | { | |
2749 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_DEAUTH, wd->sta.bssid, 2); | |
2750 | } | |
2751 | else if (zfStaIsConnecting(dev)) | |
2752 | { | |
2753 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED, wd->sta.bssid, 3); | |
2754 | } | |
2755 | else | |
2756 | { | |
2757 | } | |
2758 | } | |
2759 | } | |
2760 | } | |
2761 | else if ( wd->wlanMode == ZM_MODE_IBSS ) | |
2762 | { | |
2763 | u16_t peerMacAddr[3]; | |
2764 | u8_t peerIdx; | |
2765 | s8_t res; | |
2766 | ||
2767 | if ( zfStaIsConnected(dev) ) | |
2768 | { | |
2769 | peerMacAddr[0] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET); | |
2770 | peerMacAddr[1] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET+2); | |
2771 | peerMacAddr[2] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET+4); | |
2772 | ||
2773 | zmw_enter_critical_section(dev); | |
2774 | res = zfStaFindOppositeByMACAddr(dev, peerMacAddr, &peerIdx); | |
2775 | if ( res == 0 ) | |
2776 | { | |
2777 | wd->sta.oppositeInfo[peerIdx].aliveCounter = 0; | |
2778 | } | |
2779 | zmw_leave_critical_section(dev); | |
2780 | } | |
2781 | } | |
2782 | } | |
2783 | ||
2784 | void zfStaProcessDisasoc(zdev_t* dev, zbuf_t* buf) | |
2785 | { | |
2786 | u16_t apMacAddr[3]; | |
2787 | ||
2788 | zmw_get_wlan_dev(dev); | |
2789 | ||
2790 | /* STA : if SA=connected AP then disconnect with AP */ | |
2791 | if ( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) | |
2792 | { | |
2793 | apMacAddr[0] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET); | |
2794 | apMacAddr[1] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET+2); | |
2795 | apMacAddr[2] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A3_OFFSET+4); | |
2796 | ||
2797 | if ((apMacAddr[0] == wd->sta.bssid[0]) && (apMacAddr[1] == wd->sta.bssid[1]) && (apMacAddr[2] == wd->sta.bssid[2])) | |
2798 | { | |
2799 | if (zfwBufGetSize(dev, buf) >= 24+2) //not a malformed frame | |
2800 | { | |
2801 | if ( zfStaIsConnected(dev) ) | |
2802 | { | |
2803 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_DISASOC, wd->sta.bssid, 2); | |
2804 | } | |
2805 | else | |
2806 | { | |
2807 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_ASOC_FAILED, wd->sta.bssid, 3); | |
2808 | } | |
2809 | } | |
2810 | } | |
2811 | } | |
2812 | } | |
2813 | ||
2814 | ||
2815 | ||
2816 | /************************************************************************/ | |
2817 | /* */ | |
2818 | /* FUNCTION DESCRIPTION zfProcessProbeReq */ | |
2819 | /* Process probe request management frame. */ | |
2820 | /* */ | |
2821 | /* INPUTS */ | |
2822 | /* dev : device pointer */ | |
2823 | /* buf : auth frame buffer */ | |
2824 | /* */ | |
2825 | /* OUTPUTS */ | |
2826 | /* none */ | |
2827 | /* */ | |
2828 | /* AUTHOR */ | |
2829 | /* Stephen Chen ZyDAS Technology Corporation 2005.10 */ | |
2830 | /* */ | |
2831 | /************************************************************************/ | |
2832 | void zfStaProcessProbeReq(zdev_t* dev, zbuf_t* buf, u16_t* src) | |
2833 | { | |
2834 | u16_t offset; | |
2835 | u8_t len; | |
2836 | u16_t i, j; | |
2837 | u16_t sendFlag; | |
2838 | ||
2839 | zmw_get_wlan_dev(dev); | |
2840 | ||
2841 | /* check mode : AP/IBSS */ | |
274350fe | 2842 | if ((wd->wlanMode != ZM_MODE_AP) && (wd->wlanMode != ZM_MODE_IBSS)) |
4bd43f50 LR |
2843 | { |
2844 | zm_msg0_mm(ZM_LV_3, "Ignore probe req"); | |
2845 | return; | |
2846 | } | |
2847 | ||
2848 | /* check SSID */ | |
92363b52 JP |
2849 | offset = zfFindElement(dev, buf, ZM_WLAN_EID_SSID); |
2850 | if (offset == 0xffff) | |
4bd43f50 LR |
2851 | { |
2852 | zm_msg0_mm(ZM_LV_3, "probe req SSID not found"); | |
2853 | return; | |
2854 | } | |
2855 | ||
2856 | len = zmw_rx_buf_readb(dev, buf, offset+1); | |
2857 | ||
2858 | for (i=0; i<ZM_MAX_AP_SUPPORT; i++) | |
2859 | { | |
2860 | if ((wd->ap.apBitmap & (i<<i)) != 0) | |
2861 | { | |
2862 | sendFlag = 0; | |
2863 | /* boardcast SSID */ | |
2864 | if ((len == 0) && (wd->ap.hideSsid[i] == 0)) | |
2865 | { | |
2866 | sendFlag = 1; | |
2867 | } | |
2868 | /* Not broadcast SSID */ | |
2869 | else if (wd->ap.ssidLen[i] == len) | |
2870 | { | |
2871 | for (j=0; j<len; j++) | |
2872 | { | |
2873 | if (zmw_rx_buf_readb(dev, buf, offset+1+j) | |
2874 | != wd->ap.ssid[i][j]) | |
2875 | { | |
2876 | break; | |
2877 | } | |
2878 | } | |
2879 | if (j == len) | |
2880 | { | |
2881 | sendFlag = 1; | |
2882 | } | |
2883 | } | |
2884 | if (sendFlag == 1) | |
2885 | { | |
2886 | /* Send probe response */ | |
2887 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_PROBERSP, src, i, 0, 0); | |
2888 | } | |
2889 | } | |
2890 | } | |
2891 | } | |
2892 | ||
2893 | void zfStaProcessProbeRsp(zdev_t* dev, zbuf_t* buf, struct zsAdditionInfo* AddInfo) | |
2894 | { | |
2895 | /* return if not channel scan */ | |
2896 | // Probe response is sent with unicast. Is this required? | |
2897 | // IBSS would send probe request and the code below would prevent | |
2898 | // the probe response from handling. | |
2899 | #if 0 | |
2900 | zmw_get_wlan_dev(dev); | |
2901 | ||
2902 | if ( !wd->sta.bChannelScan ) | |
2903 | { | |
2904 | return; | |
2905 | } | |
2906 | #endif | |
2907 | ||
2908 | zfProcessProbeRsp(dev, buf, AddInfo); | |
2909 | } | |
2910 | ||
2911 | void zfIBSSSetupBssDesc(zdev_t *dev) | |
2912 | { | |
2913 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
2914 | u8_t i; | |
2915 | #endif | |
2916 | struct zsBssInfo *pBssInfo; | |
2917 | u16_t offset = 0; | |
2918 | ||
2919 | zmw_get_wlan_dev(dev); | |
2920 | ||
2921 | pBssInfo = &wd->sta.ibssBssDesc; | |
2922 | zfZeroMemory((u8_t *)pBssInfo, sizeof(struct zsBssInfo)); | |
2923 | ||
2924 | pBssInfo->signalStrength = 100; | |
2925 | ||
2926 | zfMemoryCopy((u8_t *)pBssInfo->macaddr, (u8_t *)wd->macAddr,6); | |
2927 | zfMemoryCopy((u8_t *)pBssInfo->bssid, (u8_t *)wd->sta.bssid, 6); | |
2928 | ||
2929 | pBssInfo->beaconInterval[0] = (u8_t)(wd->beaconInterval) ; | |
2930 | pBssInfo->beaconInterval[1] = (u8_t)((wd->beaconInterval) >> 8) ; | |
2931 | ||
2932 | pBssInfo->capability[0] = wd->sta.capability[0]; | |
2933 | pBssInfo->capability[1] = wd->sta.capability[1]; | |
2934 | ||
2935 | pBssInfo->ssid[0] = ZM_WLAN_EID_SSID; | |
2936 | pBssInfo->ssid[1] = wd->sta.ssidLen; | |
2937 | zfMemoryCopy((u8_t *)&pBssInfo->ssid[2], (u8_t *)wd->sta.ssid, wd->sta.ssidLen); | |
2938 | zfMemoryCopy((u8_t *)&pBssInfo->frameBody[offset], (u8_t *)pBssInfo->ssid, | |
2939 | wd->sta.ssidLen + 2); | |
2940 | offset += wd->sta.ssidLen + 2; | |
2941 | ||
2942 | /* support rate */ | |
2943 | ||
2944 | /* DS parameter set */ | |
2945 | pBssInfo->channel = zfChFreqToNum(wd->frequency, NULL); | |
2946 | pBssInfo->frequency = wd->frequency; | |
2947 | pBssInfo->atimWindow = wd->sta.atimWindow; | |
2948 | ||
2949 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
2950 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA2PSK ) | |
2951 | { | |
2952 | u8_t rsn[64]= | |
2953 | { | |
2954 | /* Element ID */ | |
2955 | 0x30, | |
2956 | /* Length */ | |
2957 | 0x14, | |
2958 | /* Version */ | |
2959 | 0x01, 0x00, | |
2960 | /* Group Cipher Suite, default=TKIP */ | |
2961 | 0x00, 0x0f, 0xac, 0x04, | |
2962 | /* Pairwise Cipher Suite Count */ | |
2963 | 0x01, 0x00, | |
2964 | /* Pairwise Cipher Suite, default=TKIP */ | |
2965 | 0x00, 0x0f, 0xac, 0x02, | |
2966 | /* Authentication and Key Management Suite Count */ | |
2967 | 0x01, 0x00, | |
2968 | /* Authentication type, default=PSK */ | |
2969 | 0x00, 0x0f, 0xac, 0x02, | |
2970 | /* RSN capability */ | |
2971 | 0x00, 0x00 | |
2972 | }; | |
2973 | ||
2974 | /* Overwrite Group Cipher Suite by AP's setting */ | |
2975 | zfMemoryCopy(rsn+4, zgWpa2AesOui, 4); | |
2976 | ||
2977 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
2978 | { | |
2979 | /* Overwrite Pairwise Cipher Suite by AES */ | |
2980 | zfMemoryCopy(rsn+10, zgWpa2AesOui, 4); | |
2981 | } | |
2982 | ||
2983 | // RSN element id | |
2984 | pBssInfo->frameBody[offset++] = ZM_WLAN_EID_RSN_IE ; | |
2985 | ||
2986 | // RSN length | |
2987 | pBssInfo->frameBody[offset++] = rsn[1] ; | |
2988 | ||
2989 | // RSN information | |
2990 | for(i=0; i<rsn[1]; i++) | |
2991 | { | |
2992 | pBssInfo->frameBody[offset++] = rsn[i+2] ; | |
2993 | } | |
2994 | ||
2995 | zfMemoryCopy(pBssInfo->rsnIe, rsn, rsn[1]+2); | |
2996 | } | |
2997 | #endif | |
2998 | } | |
2999 | ||
3000 | void zfIbssConnectNetwork(zdev_t* dev) | |
3001 | { | |
3002 | struct zsBssInfo* pBssInfo; | |
3003 | struct zsBssInfo tmpBssInfo; | |
3004 | u8_t macAddr[6], bssid[6], bssNotFound = TRUE; | |
3005 | u16_t i, j=100; | |
3006 | u16_t k; | |
3007 | struct zsPartnerNotifyEvent event; | |
3008 | u32_t channelFlags; | |
3009 | u16_t oppositeWepStatus; | |
3010 | ||
3011 | zmw_get_wlan_dev(dev); | |
3012 | ||
3013 | zmw_declare_for_critical_section(); | |
3014 | ||
3015 | /* change state to CONNECTING and stop the channel scanning */ | |
3016 | zfChangeAdapterState(dev, ZM_STA_STATE_CONNECTING); | |
3017 | zfPowerSavingMgrWakeup(dev); | |
3018 | ||
3019 | /* Set TxQs CWMIN, CWMAX, AIFS and TXO to WME STA default. */ | |
3020 | zfUpdateDefaultQosParameter(dev, 0); | |
3021 | ||
3022 | wd->sta.bProtectionMode = FALSE; | |
3023 | zfHpSetSlotTime(dev, 1); | |
3024 | ||
3025 | /* ESS bit off */ | |
3026 | wd->sta.capability[0] &= ~ZM_BIT_0; | |
3027 | /* IBSS bit on */ | |
3028 | wd->sta.capability[0] |= ZM_BIT_1; | |
3029 | /* not not use short slot time */ | |
3030 | wd->sta.capability[1] &= ~ZM_BIT_2; | |
3031 | ||
3032 | wd->sta.wmeConnected = 0; | |
3033 | wd->sta.psMgr.tempWakeUp = 0; | |
3034 | wd->sta.qosInfo = 0; | |
3035 | wd->sta.EnableHT = 0; | |
3036 | wd->BandWidth40 = 0; | |
3037 | wd->ExtOffset = 0; | |
3038 | ||
3039 | if ( wd->sta.bssList.bssCount ) | |
3040 | { | |
3041 | //Reorder BssList by RSSI--CWYang(+) | |
3042 | zfBssInfoReorderList(dev); | |
3043 | ||
3044 | zmw_enter_critical_section(dev); | |
3045 | ||
3046 | pBssInfo = wd->sta.bssList.head; | |
3047 | ||
3048 | for(i=0; i<wd->sta.bssList.bssCount; i++) | |
3049 | { | |
3050 | // 20070806 #1 Privacy bit | |
3051 | if ( pBssInfo->capability[0] & ZM_BIT_4 ) | |
3052 | { // Privacy Ibss network | |
3053 | // zm_debug_msg0("Privacy bit on"); | |
3054 | oppositeWepStatus = ZM_ENCRYPTION_WEP_ENABLED; | |
3055 | ||
3056 | if ( pBssInfo->rsnIe[1] != 0 ) | |
3057 | { | |
3058 | if ( (pBssInfo->rsnIe[7] == 0x01) || (pBssInfo->rsnIe[7] == 0x05) ) | |
3059 | { // WEP-40 & WEP-104 | |
3060 | // zm_debug_msg0("WEP40 or WEP104"); | |
3061 | oppositeWepStatus = ZM_ENCRYPTION_WEP_ENABLED; | |
3062 | } | |
3063 | else if ( pBssInfo->rsnIe[7] == 0x02 ) | |
3064 | { // TKIP | |
3065 | // zm_debug_msg0("TKIP"); | |
3066 | oppositeWepStatus = ZM_ENCRYPTION_TKIP; | |
3067 | } | |
3068 | else if ( pBssInfo->rsnIe[7] == 0x04 ) | |
3069 | { // AES | |
3070 | // zm_debug_msg0("CCMP-AES"); | |
3071 | oppositeWepStatus = ZM_ENCRYPTION_AES; | |
3072 | } | |
3073 | } | |
3074 | } | |
3075 | else | |
3076 | { | |
3077 | // zm_debug_msg0("Privacy bit off"); | |
3078 | oppositeWepStatus = ZM_ENCRYPTION_WEP_DISABLED; | |
3079 | } | |
3080 | ||
3081 | if ( (zfMemoryIsEqual(&(pBssInfo->ssid[2]), wd->sta.ssid, | |
3082 | wd->sta.ssidLen))&& | |
3083 | (wd->sta.ssidLen == pBssInfo->ssid[1])&& | |
3084 | (oppositeWepStatus == wd->sta.wepStatus) ) | |
3085 | { | |
3086 | /* Check support mode */ | |
3087 | if (pBssInfo->frequency > 3000) { | |
3088 | if ( (pBssInfo->EnableHT == 1) | |
3089 | || (pBssInfo->apCap & ZM_All11N_AP) ) //11n AP | |
3090 | { | |
3091 | channelFlags = CHANNEL_A_HT; | |
3092 | if (pBssInfo->enableHT40 == 1) { | |
3093 | channelFlags |= CHANNEL_HT40; | |
3094 | } | |
3095 | } else { | |
3096 | channelFlags = CHANNEL_A; | |
3097 | } | |
3098 | } else { | |
3099 | if ( (pBssInfo->EnableHT == 1) | |
3100 | || (pBssInfo->apCap & ZM_All11N_AP) ) //11n AP | |
3101 | { | |
3102 | channelFlags = CHANNEL_G_HT; | |
3103 | if(pBssInfo->enableHT40 == 1) { | |
3104 | channelFlags |= CHANNEL_HT40; | |
3105 | } | |
3106 | } else { | |
3107 | if (pBssInfo->extSupportedRates[1] == 0) { | |
3108 | channelFlags = CHANNEL_B; | |
3109 | } else { | |
3110 | channelFlags = CHANNEL_G; | |
3111 | } | |
3112 | } | |
3113 | } | |
3114 | ||
3115 | if ( ((channelFlags == CHANNEL_B) && (wd->connectMode & ZM_BIT_0)) | |
3116 | || ((channelFlags == CHANNEL_G) && (wd->connectMode & ZM_BIT_1)) | |
3117 | || ((channelFlags == CHANNEL_A) && (wd->connectMode & ZM_BIT_2)) | |
3118 | || ((channelFlags & CHANNEL_HT20) && (wd->connectMode & ZM_BIT_3)) ) | |
3119 | { | |
3120 | pBssInfo = pBssInfo->next; | |
3121 | continue; | |
3122 | } | |
3123 | ||
3124 | /* Bypass DFS channel */ | |
3125 | if (zfHpIsDfsChannelNCS(dev, pBssInfo->frequency)) | |
3126 | { | |
3127 | zm_debug_msg0("Bypass DFS channel"); | |
3128 | continue; | |
3129 | } | |
3130 | ||
3131 | /* check IBSS bit */ | |
3132 | if ( pBssInfo->capability[0] & ZM_BIT_1 ) | |
3133 | { | |
3134 | /* may check timestamp here */ | |
3135 | j = i; | |
3136 | break; | |
3137 | } | |
3138 | } | |
3139 | ||
3140 | pBssInfo = pBssInfo->next; | |
3141 | } | |
3142 | ||
3143 | if ((j < wd->sta.bssList.bssCount) && (pBssInfo != NULL)) | |
3144 | { | |
3145 | zfwMemoryCopy((u8_t*)&tmpBssInfo, (u8_t*)(pBssInfo), sizeof(struct zsBssInfo)); | |
3146 | pBssInfo = &tmpBssInfo; | |
3147 | } | |
3148 | else | |
3149 | { | |
3150 | pBssInfo = NULL; | |
3151 | } | |
3152 | ||
3153 | zmw_leave_critical_section(dev); | |
3154 | ||
3155 | //if ( j < wd->sta.bssList.bssCount ) | |
3156 | if (pBssInfo != NULL) | |
3157 | { | |
3158 | int res; | |
3159 | ||
3160 | zm_debug_msg0("IBSS found"); | |
3161 | ||
3162 | /* Found IBSS, reset bssNotFoundCount */ | |
3163 | zmw_enter_critical_section(dev); | |
3164 | wd->sta.bssNotFoundCount = 0; | |
3165 | zmw_leave_critical_section(dev); | |
3166 | ||
3167 | bssNotFound = FALSE; | |
3168 | wd->sta.atimWindow = pBssInfo->atimWindow; | |
3169 | wd->frequency = pBssInfo->frequency; | |
3170 | //wd->sta.flagFreqChanging = 1; | |
3171 | zfCoreSetFrequency(dev, wd->frequency); | |
3172 | zfUpdateBssid(dev, pBssInfo->bssid); | |
3173 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_ZERO); | |
3174 | zfUpdateSupportRate(dev, pBssInfo->supportedRates); | |
3175 | zfUpdateSupportRate(dev, pBssInfo->extSupportedRates); | |
3176 | wd->beaconInterval = pBssInfo->beaconInterval[0] + | |
3177 | (((u16_t) pBssInfo->beaconInterval[1]) << 8); | |
3178 | ||
3179 | if (wd->beaconInterval == 0) | |
3180 | { | |
3181 | wd->beaconInterval = 100; | |
3182 | } | |
3183 | ||
3184 | /* rsn information element */ | |
3185 | if ( pBssInfo->rsnIe[1] != 0 ) | |
3186 | { | |
3187 | zfMemoryCopy(wd->sta.rsnIe, pBssInfo->rsnIe, | |
3188 | pBssInfo->rsnIe[1]+2); | |
3189 | ||
3190 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
3191 | /* If not use RSNA , run traditional */ | |
3192 | zmw_enter_critical_section(dev); | |
3193 | wd->sta.ibssWpa2Psk = 1; | |
3194 | zmw_leave_critical_section(dev); | |
3195 | #endif | |
3196 | } | |
3197 | else | |
3198 | { | |
3199 | wd->sta.rsnIe[1] = 0; | |
3200 | } | |
3201 | ||
3202 | /* privacy bit */ | |
3203 | if ( pBssInfo->capability[0] & ZM_BIT_4 ) | |
3204 | { | |
3205 | wd->sta.capability[0] |= ZM_BIT_4; | |
3206 | } | |
3207 | else | |
3208 | { | |
3209 | wd->sta.capability[0] &= ~ZM_BIT_4; | |
3210 | } | |
3211 | ||
3212 | /* preamble type */ | |
3213 | wd->preambleTypeInUsed = wd->preambleType; | |
3214 | if ( wd->preambleTypeInUsed == ZM_PREAMBLE_TYPE_AUTO ) | |
3215 | { | |
3216 | if (pBssInfo->capability[0] & ZM_BIT_5) | |
3217 | { | |
3218 | wd->preambleTypeInUsed = ZM_PREAMBLE_TYPE_SHORT; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | wd->preambleTypeInUsed = ZM_PREAMBLE_TYPE_LONG; | |
3223 | } | |
3224 | } | |
3225 | ||
3226 | if (wd->preambleTypeInUsed == ZM_PREAMBLE_TYPE_LONG) | |
3227 | { | |
3228 | wd->sta.capability[0] &= ~ZM_BIT_5; | |
3229 | } | |
3230 | else | |
3231 | { | |
3232 | wd->sta.capability[0] |= ZM_BIT_5; | |
3233 | } | |
3234 | ||
3235 | wd->sta.beaconFrameBodySize = pBssInfo->frameBodysize + 12; | |
3236 | ||
3237 | if (wd->sta.beaconFrameBodySize > ZM_CACHED_FRAMEBODY_SIZE) | |
3238 | { | |
3239 | wd->sta.beaconFrameBodySize = ZM_CACHED_FRAMEBODY_SIZE; | |
3240 | } | |
3241 | ||
3242 | for (k=0; k<8; k++) | |
3243 | { | |
3244 | wd->sta.beaconFrameBody[k] = pBssInfo->timeStamp[k]; | |
3245 | } | |
3246 | wd->sta.beaconFrameBody[8] = pBssInfo->beaconInterval[0]; | |
3247 | wd->sta.beaconFrameBody[9] = pBssInfo->beaconInterval[1]; | |
3248 | wd->sta.beaconFrameBody[10] = pBssInfo->capability[0]; | |
3249 | wd->sta.beaconFrameBody[11] = pBssInfo->capability[1]; | |
3250 | //for (k=12; k<wd->sta.beaconFrameBodySize; k++) | |
3251 | for (k=0; k<pBssInfo->frameBodysize; k++) | |
3252 | { | |
3253 | wd->sta.beaconFrameBody[k+12] = pBssInfo->frameBody[k]; | |
3254 | } | |
3255 | ||
3256 | zmw_enter_critical_section(dev); | |
3257 | res = zfStaSetOppositeInfoFromBSSInfo(dev, pBssInfo); | |
3258 | if ( res == 0 ) | |
3259 | { | |
3260 | zfMemoryCopy(event.bssid, (u8_t *)(pBssInfo->bssid), 6); | |
3261 | zfMemoryCopy(event.peerMacAddr, (u8_t *)(pBssInfo->macaddr), 6); | |
3262 | } | |
3263 | zmw_leave_critical_section(dev); | |
3264 | ||
3265 | //zfwIbssPartnerNotify(dev, 1, &event); | |
3266 | goto connect_done; | |
3267 | } | |
3268 | } | |
3269 | ||
3270 | /* IBSS not found */ | |
3271 | if ( bssNotFound ) | |
3272 | { | |
3273 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
3274 | u16_t offset ; | |
3275 | #endif | |
3276 | if ( wd->sta.ibssJoinOnly ) | |
3277 | { | |
3278 | zm_debug_msg0("IBSS join only...retry..."); | |
3279 | goto retry_ibss; | |
3280 | } | |
3281 | ||
3282 | if(wd->sta.bssNotFoundCount<2) | |
3283 | { | |
3284 | zmw_enter_critical_section(dev); | |
3285 | zm_debug_msg1("IBSS not found, do sitesurvey!! bssNotFoundCount=", wd->sta.bssNotFoundCount); | |
3286 | wd->sta.bssNotFoundCount++; | |
3287 | zmw_leave_critical_section(dev); | |
3288 | goto retry_ibss; | |
3289 | } | |
3290 | else | |
3291 | { | |
3292 | zmw_enter_critical_section(dev); | |
3293 | /* Fail IBSS found, TODO create IBSS */ | |
3294 | wd->sta.bssNotFoundCount = 0; | |
3295 | zmw_leave_critical_section(dev); | |
3296 | } | |
3297 | ||
3298 | ||
3299 | if (zfHpIsDfsChannel(dev, wd->frequency)) | |
3300 | { | |
3301 | wd->frequency = zfHpFindFirstNonDfsChannel(dev, wd->frequency > 3000); | |
3302 | } | |
3303 | ||
3304 | if( wd->ws.autoSetFrequency == 0 ) | |
3305 | { /* Auto set frequency */ | |
3306 | zm_debug_msg1("Create Ad Hoc Network Band ", wd->ws.adhocMode); | |
3307 | wd->frequency = zfFindCleanFrequency(dev, wd->ws.adhocMode); | |
3308 | wd->ws.autoSetFrequency = 0xff; | |
3309 | } | |
3310 | zm_debug_msg1("IBSS not found, created one in channel ", wd->frequency); | |
3311 | ||
3312 | wd->sta.ibssBssIsCreator = 1; | |
3313 | ||
3314 | //wd->sta.flagFreqChanging = 1; | |
3315 | zfCoreSetFrequency(dev, wd->frequency); | |
3316 | if (wd->sta.bDesiredBssid == TRUE) | |
3317 | { | |
3318 | for (k=0; k<6; k++) | |
3319 | { | |
3320 | bssid[k] = wd->sta.desiredBssid[k]; | |
3321 | } | |
3322 | } | |
3323 | else | |
3324 | { | |
3325 | #if 1 | |
3326 | macAddr[0] = (wd->macAddr[0] & 0xff); | |
3327 | macAddr[1] = (wd->macAddr[0] >> 8); | |
3328 | macAddr[2] = (wd->macAddr[1] & 0xff); | |
3329 | macAddr[3] = (wd->macAddr[1] >> 8); | |
3330 | macAddr[4] = (wd->macAddr[2] & 0xff); | |
3331 | macAddr[5] = (wd->macAddr[2] >> 8); | |
3332 | zfGenerateRandomBSSID(dev, (u8_t *)wd->macAddr, (u8_t *)bssid); | |
3333 | #else | |
3334 | for (k=0; k<6; k++) | |
3335 | { | |
3336 | bssid[k] = (u8_t) zfGetRandomNumber(dev, 0); | |
3337 | } | |
3338 | bssid[0] &= ~ZM_BIT_0; | |
3339 | bssid[0] |= ZM_BIT_1; | |
3340 | #endif | |
3341 | } | |
3342 | ||
3343 | zfUpdateBssid(dev, bssid); | |
3344 | //wd->sta.atimWindow = 0x0a; | |
3345 | ||
3346 | /* rate information */ | |
3347 | if(wd->frequency <= ZM_CH_G_14) // 2.4 GHz b+g | |
3348 | { | |
3349 | if ( wd->wfc.bIbssGMode | |
3350 | && (wd->supportMode & (ZM_WIRELESS_MODE_24_54|ZM_WIRELESS_MODE_24_N)) ) | |
3351 | { | |
3352 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_IBSS_AG); | |
3353 | } | |
3354 | else | |
3355 | { | |
3356 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_IBSS_B); | |
3357 | } | |
3358 | } else { | |
3359 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_IBSS_AG); | |
3360 | } | |
3361 | ||
3362 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_WEP_DISABLED ) | |
3363 | { | |
3364 | wd->sta.capability[0] &= ~ZM_BIT_4; | |
3365 | } | |
3366 | else | |
3367 | { | |
3368 | wd->sta.capability[0] |= ZM_BIT_4; | |
3369 | } | |
3370 | ||
3371 | wd->preambleTypeInUsed = wd->preambleType; | |
3372 | if (wd->preambleTypeInUsed == ZM_PREAMBLE_TYPE_LONG) | |
3373 | { | |
3374 | wd->sta.capability[0] &= ~ZM_BIT_5; | |
3375 | } | |
3376 | else | |
3377 | { | |
3378 | wd->preambleTypeInUsed = ZM_PREAMBLE_TYPE_SHORT; | |
3379 | wd->sta.capability[0] |= ZM_BIT_5; | |
3380 | } | |
3381 | ||
3382 | zfIBSSSetupBssDesc(dev); | |
3383 | ||
3384 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
3385 | ||
3386 | // 20070411 Add WPA2PSK information to its IBSS network !!! | |
3387 | offset = 0 ; | |
3388 | ||
3389 | /* timestamp */ | |
3390 | offset += 8 ; | |
3391 | ||
3392 | /* beacon interval */ | |
3393 | wd->sta.beaconFrameBody[offset++] = (u8_t)(wd->beaconInterval) ; | |
3394 | wd->sta.beaconFrameBody[offset++] = (u8_t)((wd->beaconInterval) >> 8) ; | |
3395 | ||
3396 | /* capability information */ | |
3397 | wd->sta.beaconFrameBody[offset++] = wd->sta.capability[0] ; | |
3398 | wd->sta.beaconFrameBody[offset++] = wd->sta.capability[1] ; | |
3399 | #if 0 | |
3400 | /* ssid */ | |
3401 | // ssid element id | |
3402 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_SSID ; | |
3403 | // ssid length | |
3404 | wd->sta.beaconFrameBody[offset++] = wd->sta.ssidLen ; | |
3405 | // ssid information | |
3406 | for(i=0; i<wd->sta.ssidLen; i++) | |
3407 | { | |
3408 | wd->sta.beaconFrameBody[offset++] = wd->sta.ssid[i] ; | |
3409 | } | |
3410 | ||
3411 | /* support rate */ | |
3412 | rateSet = ZM_RATE_SET_CCK ; | |
3413 | if ( (rateSet == ZM_RATE_SET_OFDM)&&((wd->gRate & 0xff) == 0) ) | |
3414 | { | |
3415 | offset += 0 ; | |
3416 | } | |
3417 | else | |
3418 | { | |
3419 | // support rate element id | |
3420 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_SUPPORT_RATE ; | |
3421 | ||
3422 | // support rate length | |
3423 | lenOffset = offset++; | |
3424 | ||
3425 | // support rate information | |
3426 | for (i=0; i<4; i++) | |
3427 | { | |
3428 | if ((wd->bRate & (0x1<<i)) == (0x1<<i)) | |
3429 | { | |
3430 | wd->sta.beaconFrameBody[offset++] = | |
3431 | zg11bRateTbl[i]+((wd->bRateBasic & (0x1<<i))<<(7-i)) ; | |
3432 | len++; | |
3433 | } | |
3434 | } | |
3435 | ||
3436 | // support rate length | |
3437 | wd->sta.beaconFrameBody[lenOffset] = len ; | |
3438 | } | |
3439 | ||
3440 | /* DS parameter set */ | |
3441 | // DS parameter set elemet id | |
3442 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_DS ; | |
3443 | ||
3444 | // DS parameter set length | |
3445 | wd->sta.beaconFrameBody[offset++] = 1 ; | |
3446 | ||
3447 | // DS parameter set information | |
3448 | wd->sta.beaconFrameBody[offset++] = | |
3449 | zfChFreqToNum(wd->frequency, NULL) ; | |
3450 | ||
3451 | /* IBSS parameter set */ | |
3452 | // IBSS parameter set element id | |
3453 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_IBSS ; | |
3454 | ||
3455 | // IBSS parameter set length | |
3456 | wd->sta.beaconFrameBody[offset++] = 2 ; | |
3457 | ||
3458 | // IBSS parameter set information | |
3459 | wd->sta.beaconFrameBody[offset] = wd->sta.atimWindow ; | |
3460 | offset += 2 ; | |
3461 | ||
3462 | /* ERP Information and Extended Supported Rates */ | |
3463 | if ( wd->wfc.bIbssGMode | |
3464 | && (wd->supportMode & (ZM_WIRELESS_MODE_24_54|ZM_WIRELESS_MODE_24_N)) ) | |
3465 | { | |
3466 | /* ERP Information */ | |
3467 | wd->erpElement = 0; | |
3468 | // ERP element id | |
3469 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_ERP ; | |
3470 | ||
3471 | // ERP length | |
3472 | wd->sta.beaconFrameBody[offset++] = 1 ; | |
3473 | ||
3474 | // ERP information | |
3475 | wd->sta.beaconFrameBody[offset++] = wd->erpElement ; | |
3476 | ||
3477 | /* Extended Supported Rates */ | |
3478 | if ( (rateSet == ZM_RATE_SET_OFDM)&&((wd->gRate & 0xff) == 0) ) | |
3479 | { | |
3480 | offset += 0 ; | |
3481 | } | |
3482 | else | |
3483 | { | |
3484 | len = 0 ; | |
3485 | ||
3486 | // Extended Supported Rates element id | |
3487 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_EXTENDED_RATE ; | |
3488 | ||
3489 | // Extended Supported Rates length | |
3490 | lenOffset = offset++ ; | |
3491 | ||
3492 | // Extended Supported Rates information | |
3493 | for (i=0; i<8; i++) | |
3494 | { | |
3495 | if ((wd->gRate & (0x1<<i)) == (0x1<<i)) | |
3496 | { | |
3497 | wd->sta.beaconFrameBody[offset++] = | |
3498 | zg11gRateTbl[i]+((wd->gRateBasic & (0x1<<i))<<(7-i)); | |
3499 | len++; | |
3500 | } | |
3501 | } | |
3502 | ||
3503 | // extended support rate length | |
3504 | wd->sta.beaconFrameBody[lenOffset] = len ; | |
3505 | } | |
3506 | } | |
3507 | #endif | |
3508 | ||
3509 | /* RSN : important information influence the result of creating an IBSS network */ | |
3510 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA2PSK ) | |
3511 | { | |
3512 | u8_t frameType = ZM_WLAN_FRAME_TYPE_AUTH ; | |
3513 | u8_t rsn[64]= | |
3514 | { | |
3515 | /* Element ID */ | |
3516 | 0x30, | |
3517 | /* Length */ | |
3518 | 0x14, | |
3519 | /* Version */ | |
3520 | 0x01, 0x00, | |
3521 | /* Group Cipher Suite, default=TKIP */ | |
3522 | 0x00, 0x0f, 0xac, 0x04, | |
3523 | /* Pairwise Cipher Suite Count */ | |
3524 | 0x01, 0x00, | |
3525 | /* Pairwise Cipher Suite, default=TKIP */ | |
3526 | 0x00, 0x0f, 0xac, 0x02, | |
3527 | /* Authentication and Key Management Suite Count */ | |
3528 | 0x01, 0x00, | |
3529 | /* Authentication type, default=PSK */ | |
3530 | 0x00, 0x0f, 0xac, 0x02, | |
3531 | /* RSN capability */ | |
3532 | 0x00, 0x00 | |
3533 | }; | |
3534 | ||
3535 | /* Overwrite Group Cipher Suite by AP's setting */ | |
3536 | zfMemoryCopy(rsn+4, zgWpa2AesOui, 4); | |
3537 | ||
3538 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
3539 | { | |
3540 | /* Overwrite Pairwise Cipher Suite by AES */ | |
3541 | zfMemoryCopy(rsn+10, zgWpa2AesOui, 4); | |
3542 | } | |
3543 | ||
3544 | // RSN element id | |
3545 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_RSN_IE ; | |
3546 | ||
3547 | // RSN length | |
3548 | wd->sta.beaconFrameBody[offset++] = rsn[1] ; | |
3549 | ||
3550 | // RSN information | |
3551 | for(i=0; i<rsn[1]; i++) | |
3552 | wd->sta.beaconFrameBody[offset++] = rsn[i+2] ; | |
3553 | ||
3554 | zfMemoryCopy(wd->sta.rsnIe, rsn, rsn[1]+2); | |
3555 | ||
3556 | #ifdef ZM_ENABLE_IBSS_WPA2PSK | |
3557 | /* If not use RSNA , run traditional */ | |
3558 | zmw_enter_critical_section(dev); | |
3559 | wd->sta.ibssWpa2Psk = 1; | |
3560 | zmw_leave_critical_section(dev); | |
3561 | #endif | |
3562 | } | |
3563 | ||
3564 | #if 0 | |
3565 | /* HT Capabilities Info */ | |
3566 | { | |
3567 | u8_t OUI[3] = { 0x0 , 0x90 , 0x4C } ; | |
3568 | ||
3569 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_WPA_IE ; | |
3570 | ||
3571 | wd->sta.beaconFrameBody[offset++] = wd->sta.HTCap.Data.Length + 4 ; | |
3572 | ||
3573 | for (i = 0; i < 3; i++) | |
3574 | { | |
3575 | wd->sta.beaconFrameBody[offset++] = OUI[i] ; | |
3576 | } | |
3577 | ||
3578 | wd->sta.beaconFrameBody[offset++] = wd->sta.HTCap.Data.ElementID ; | |
3579 | ||
3580 | for (i = 0; i < 26; i++) | |
3581 | { | |
3582 | wd->sta.beaconFrameBody[offset++] = wd->sta.HTCap.Byte[i+2] ; | |
3583 | } | |
3584 | } | |
3585 | ||
3586 | /* Extended HT Capabilities Info */ | |
3587 | { | |
3588 | u8_t OUI[3] = { 0x0 , 0x90 , 0x4C } ; | |
3589 | ||
3590 | wd->sta.beaconFrameBody[offset++] = ZM_WLAN_EID_WPA_IE ; | |
3591 | ||
3592 | wd->sta.beaconFrameBody[offset++] = wd->sta.ExtHTCap.Data.Length + 4 ; | |
3593 | ||
3594 | for (i = 0; i < 3; i++) | |
3595 | { | |
3596 | wd->sta.beaconFrameBody[offset++] = OUI[i] ; | |
3597 | } | |
3598 | ||
3599 | wd->sta.beaconFrameBody[offset++] = wd->sta.ExtHTCap.Data.ElementID ; | |
3600 | ||
3601 | for (i = 0; i < 22; i++) | |
3602 | { | |
3603 | wd->sta.beaconFrameBody[offset++] = wd->sta.ExtHTCap.Byte[i+2] ; | |
3604 | } | |
3605 | } | |
3606 | #endif | |
3607 | ||
3608 | wd->sta.beaconFrameBodySize = offset ; | |
3609 | ||
3610 | if (wd->sta.beaconFrameBodySize > ZM_CACHED_FRAMEBODY_SIZE) | |
3611 | { | |
3612 | wd->sta.beaconFrameBodySize = ZM_CACHED_FRAMEBODY_SIZE; | |
3613 | } | |
3614 | ||
3615 | // 20070416 Let Create IBSS network could enter the zfwIbssPartnerNotify function | |
3616 | // bssNotFound = FALSE ; | |
3617 | ||
3618 | printk("The capability info 1 = %02x\n", wd->sta.capability[0]) ; | |
3619 | printk("The capability info 2 = %02x\n", wd->sta.capability[1]) ; | |
3620 | for(k=0; k<wd->sta.beaconFrameBodySize; k++) | |
3621 | { | |
3622 | printk("%02x ", wd->sta.beaconFrameBody[k]) ; | |
3623 | } | |
3624 | #if 0 | |
3625 | zmw_enter_critical_section(dev); | |
3626 | zfMemoryCopy(event.bssid, (u8_t *)bssid, 6); | |
3627 | zfMemoryCopy(event.peerMacAddr, (u8_t *)wd->macAddr, 6); | |
3628 | zmw_leave_critical_section(dev); | |
3629 | #endif | |
3630 | #endif | |
3631 | ||
3632 | //zmw_enter_critical_section(dev); | |
3633 | //wd->sta.ibssPartnerStatus = ZM_IBSS_PARTNER_LOST; | |
3634 | //zmw_leave_critical_section(dev); | |
3635 | } | |
3636 | else | |
3637 | { | |
3638 | wd->sta.ibssBssIsCreator = 0; | |
3639 | } | |
3640 | ||
3641 | connect_done: | |
3642 | zfHpEnableBeacon(dev, ZM_MODE_IBSS, wd->beaconInterval, wd->dtim, (u8_t)wd->sta.atimWindow); | |
3643 | zfStaSendBeacon(dev); // Refresh Beacon content for ZD1211B HalPlus | |
3644 | zfHpSetAtimWindow(dev, wd->sta.atimWindow); | |
3645 | ||
3646 | // Start the IBSS timer to monitor for new stations | |
3647 | zmw_enter_critical_section(dev); | |
3648 | zfTimerSchedule(dev, ZM_EVENT_IBSS_MONITOR, ZM_TICK_IBSS_MONITOR); | |
3649 | zmw_leave_critical_section(dev); | |
3650 | ||
3651 | ||
3652 | if (wd->zfcbConnectNotify != NULL) | |
3653 | { | |
3654 | wd->zfcbConnectNotify(dev, ZM_STATUS_MEDIA_CONNECT, wd->sta.bssid); | |
3655 | } | |
3656 | zfChangeAdapterState(dev, ZM_STA_STATE_CONNECTED); | |
3657 | wd->sta.connPowerInHalfDbm = zfHpGetTransmitPower(dev); | |
3658 | ||
3659 | #ifdef ZM_ENABLE_IBSS_DELAYED_JOIN_INDICATION | |
3660 | if ( !bssNotFound ) | |
3661 | { | |
3662 | wd->sta.ibssDelayedInd = 1; | |
3663 | zfMemoryCopy((u8_t *)&wd->sta.ibssDelayedIndEvent, (u8_t *)&event, sizeof(struct zsPartnerNotifyEvent)); | |
3664 | } | |
3665 | #else | |
3666 | if ( !bssNotFound ) | |
3667 | { | |
3668 | if (wd->zfcbIbssPartnerNotify != NULL) | |
3669 | { | |
3670 | wd->zfcbIbssPartnerNotify(dev, 1, &event); | |
3671 | } | |
3672 | } | |
3673 | #endif | |
3674 | ||
3675 | return; | |
3676 | ||
3677 | retry_ibss: | |
3678 | zfChangeAdapterState(dev, ZM_STA_STATE_CONNECTING); | |
3679 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_NOT_FOUND, wd->sta.bssid, 0); | |
3680 | return; | |
3681 | } | |
3682 | ||
3683 | void zfStaProcessAtim(zdev_t* dev, zbuf_t* buf) | |
3684 | { | |
3685 | zmw_get_wlan_dev(dev); | |
3686 | ||
3687 | zm_debug_msg0("Receiving Atim window notification"); | |
3688 | ||
3689 | wd->sta.recvAtim = 1; | |
3690 | } | |
3691 | ||
3692 | static struct zsBssInfo* zfInfraFindAPToConnect(zdev_t* dev, | |
3693 | struct zsBssInfo* candidateBss) | |
3694 | { | |
3695 | struct zsBssInfo* pBssInfo; | |
3696 | struct zsBssInfo* pNowBssInfo=NULL; | |
3697 | u16_t i; | |
3698 | u16_t ret, apWepStatus; | |
3699 | u32_t k; | |
3700 | u32_t channelFlags; | |
3701 | ||
3702 | zmw_get_wlan_dev(dev); | |
3703 | zmw_declare_for_critical_section(); | |
3704 | ||
3705 | zmw_enter_critical_section(dev); | |
3706 | ||
3707 | pBssInfo = wd->sta.bssList.head; | |
3708 | ||
3709 | for(i=0; i<wd->sta.bssList.bssCount; i++) | |
3710 | { | |
3711 | if ( pBssInfo->capability[0] & ZM_BIT_4 ) | |
3712 | { | |
3713 | apWepStatus = ZM_ENCRYPTION_WEP_ENABLED; | |
3714 | } | |
3715 | else | |
3716 | { | |
3717 | apWepStatus = ZM_ENCRYPTION_WEP_DISABLED; | |
3718 | } | |
3719 | ||
3720 | if ( ((zfMemoryIsEqual(&(pBssInfo->ssid[2]), wd->sta.ssid, | |
3721 | wd->sta.ssidLen))&& | |
3722 | (wd->sta.ssidLen == pBssInfo->ssid[1]))|| | |
3723 | ((wd->sta.ssidLen == 0)&& | |
3724 | /* connect to any BSS: AP's ans STA's WEP status must match */ | |
3725 | (wd->sta.wepStatus == apWepStatus )&& | |
3726 | (pBssInfo->securityType != ZM_SECURITY_TYPE_WPA) )) | |
3727 | { | |
3728 | if ( wd->sta.ssidLen == 0 ) | |
3729 | { | |
3730 | zm_debug_msg0("ANY BSS found"); | |
3731 | } | |
3732 | ||
3733 | if ( ((wd->sta.wepStatus == ZM_ENCRYPTION_WEP_DISABLED && apWepStatus == ZM_ENCRYPTION_WEP_ENABLED) || | |
3734 | (wd->sta.wepStatus == ZM_ENCRYPTION_WEP_ENABLED && | |
3735 | (apWepStatus == ZM_ENCRYPTION_WEP_DISABLED && wd->sta.dropUnencryptedPkts == 1))) && | |
3736 | (wd->sta.authMode >= ZM_AUTH_MODE_OPEN && wd->sta.authMode <= ZM_AUTH_MODE_AUTO) ) | |
3737 | { | |
3738 | zm_debug_msg0("Privacy policy is inconsistent"); | |
3739 | pBssInfo = pBssInfo->next; | |
3740 | continue; | |
3741 | } | |
3742 | ||
3743 | /* for WPA negative test */ | |
3744 | if ( !zfCheckAuthentication(dev, pBssInfo) ) | |
3745 | { | |
3746 | pBssInfo = pBssInfo->next; | |
3747 | continue; | |
3748 | } | |
3749 | ||
3750 | /* Check bssid */ | |
3751 | if (wd->sta.bDesiredBssid == TRUE) | |
3752 | { | |
3753 | for (k=0; k<6; k++) | |
3754 | { | |
3755 | if (wd->sta.desiredBssid[k] != pBssInfo->bssid[k]) | |
3756 | { | |
3757 | zm_msg0_mm(ZM_LV_1, "desired bssid not matched 1"); | |
3758 | break; | |
3759 | } | |
3760 | } | |
3761 | ||
3762 | if (k != 6) | |
3763 | { | |
3764 | zm_msg0_mm(ZM_LV_1, "desired bssid not matched 2"); | |
3765 | pBssInfo = pBssInfo->next; | |
3766 | continue; | |
3767 | } | |
3768 | } | |
3769 | ||
3770 | /* Check support mode */ | |
3771 | if (pBssInfo->frequency > 3000) { | |
3772 | if ( (pBssInfo->EnableHT == 1) | |
3773 | || (pBssInfo->apCap & ZM_All11N_AP) ) //11n AP | |
3774 | { | |
3775 | channelFlags = CHANNEL_A_HT; | |
3776 | if (pBssInfo->enableHT40 == 1) { | |
3777 | channelFlags |= CHANNEL_HT40; | |
3778 | } | |
3779 | } else { | |
3780 | channelFlags = CHANNEL_A; | |
3781 | } | |
3782 | } else { | |
3783 | if ( (pBssInfo->EnableHT == 1) | |
3784 | || (pBssInfo->apCap & ZM_All11N_AP) ) //11n AP | |
3785 | { | |
3786 | channelFlags = CHANNEL_G_HT; | |
3787 | if(pBssInfo->enableHT40 == 1) { | |
3788 | channelFlags |= CHANNEL_HT40; | |
3789 | } | |
3790 | } else { | |
3791 | if (pBssInfo->extSupportedRates[1] == 0) { | |
3792 | channelFlags = CHANNEL_B; | |
3793 | } else { | |
3794 | channelFlags = CHANNEL_G; | |
3795 | } | |
3796 | } | |
3797 | } | |
3798 | ||
3799 | if ( ((channelFlags == CHANNEL_B) && (wd->connectMode & ZM_BIT_0)) | |
3800 | || ((channelFlags == CHANNEL_G) && (wd->connectMode & ZM_BIT_1)) | |
3801 | || ((channelFlags == CHANNEL_A) && (wd->connectMode & ZM_BIT_2)) | |
3802 | || ((channelFlags & CHANNEL_HT20) && (wd->connectMode & ZM_BIT_3)) ) | |
3803 | { | |
3804 | pBssInfo = pBssInfo->next; | |
3805 | continue; | |
3806 | } | |
3807 | ||
3808 | /* Skip if AP in blocking list */ | |
92363b52 JP |
3809 | ret = zfStaIsApInBlockingList(dev, pBssInfo->bssid); |
3810 | if (ret == TRUE) | |
4bd43f50 LR |
3811 | { |
3812 | zm_msg0_mm(ZM_LV_0, "Candidate AP in blocking List, skip if there's stilla choice!"); | |
3813 | pNowBssInfo = pBssInfo; | |
3814 | pBssInfo = pBssInfo->next; | |
3815 | continue; | |
3816 | } | |
3817 | ||
3818 | if ( pBssInfo->capability[0] & ZM_BIT_0 ) // check if infra-BSS | |
3819 | { | |
3820 | pNowBssInfo = pBssInfo; | |
3821 | wd->sta.apWmeCapability = pBssInfo->wmeSupport; | |
3822 | ||
3823 | ||
3824 | goto done; | |
3825 | } | |
3826 | } | |
3827 | ||
3828 | pBssInfo = pBssInfo->next; | |
3829 | } | |
3830 | ||
3831 | done: | |
3832 | if (pNowBssInfo != NULL) | |
3833 | { | |
3834 | zfwMemoryCopy((void*)candidateBss, (void*)pNowBssInfo, sizeof(struct zsBssInfo)); | |
3835 | pNowBssInfo = candidateBss; | |
3836 | } | |
3837 | ||
3838 | zmw_leave_critical_section(dev); | |
3839 | ||
3840 | return pNowBssInfo; | |
3841 | } | |
3842 | ||
3843 | ||
3844 | void zfInfraConnectNetwork(zdev_t* dev) | |
3845 | { | |
3846 | struct zsBssInfo* pBssInfo; | |
3847 | struct zsBssInfo* pNowBssInfo=NULL; | |
3848 | struct zsBssInfo candidateBss; | |
3849 | //u16_t i, j=100, quality=10000; | |
3850 | //u8_t ret=FALSE, apWepStatus; | |
3851 | u8_t ret=FALSE; | |
3852 | u16_t k; | |
3853 | u8_t density = ZM_MPDU_DENSITY_NONE; | |
3854 | ||
3855 | zmw_get_wlan_dev(dev); | |
3856 | zmw_declare_for_critical_section(); | |
3857 | ||
3858 | /* Reset bssNotFoundCount for Ad-Hoc:IBSS */ | |
3859 | /* Need review : IbssConn -> InfraConn -> IbssConn etc, flag/counter reset? */ | |
3860 | zmw_enter_critical_section(dev); | |
3861 | wd->sta.bssNotFoundCount = 0; | |
3862 | zmw_leave_critical_section(dev); | |
3863 | ||
3864 | /* Set TxQs CWMIN, CWMAX, AIFS and TXO to WME STA default. */ | |
3865 | zfUpdateDefaultQosParameter(dev, 0); | |
3866 | ||
3867 | zfStaRefreshBlockList(dev, 0); | |
3868 | ||
3869 | /* change state to CONNECTING and stop the channel scanning */ | |
3870 | zfChangeAdapterState(dev, ZM_STA_STATE_CONNECTING); | |
3871 | zfPowerSavingMgrWakeup(dev); | |
3872 | ||
3873 | wd->sta.wmeConnected = 0; | |
3874 | wd->sta.psMgr.tempWakeUp = 0; | |
3875 | wd->sta.qosInfo = 0; | |
3876 | zfQueueFlush(dev, wd->sta.uapsdQ); | |
3877 | ||
3878 | wd->sta.connectState = ZM_STA_CONN_STATE_NONE; | |
3879 | ||
3880 | //Reorder BssList by RSSI--CWYang(+) | |
3881 | zfBssInfoReorderList(dev); | |
3882 | ||
3883 | pNowBssInfo = zfInfraFindAPToConnect(dev, &candidateBss); | |
3884 | ||
3885 | if (wd->sta.SWEncryptEnable != 0) | |
3886 | { | |
3887 | if (wd->sta.bSafeMode == 0) | |
3888 | { | |
3889 | zfStaDisableSWEncryption(dev);//Quickly reboot | |
3890 | } | |
3891 | } | |
3892 | if ( pNowBssInfo != NULL ) | |
3893 | { | |
3894 | //zm_assert(pNowBssInfo != NULL); | |
3895 | ||
3896 | pBssInfo = pNowBssInfo; | |
3897 | wd->sta.ssidLen = pBssInfo->ssid[1]; | |
3898 | zfMemoryCopy(wd->sta.ssid, &(pBssInfo->ssid[2]), pBssInfo->ssid[1]); | |
3899 | wd->frequency = pBssInfo->frequency; | |
3900 | //wd->sta.flagFreqChanging = 1; | |
3901 | ||
3902 | //zfCoreSetFrequency(dev, wd->frequency); | |
3903 | zfUpdateBssid(dev, pBssInfo->bssid); | |
3904 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_ZERO); | |
3905 | zfUpdateSupportRate(dev, pBssInfo->supportedRates); | |
3906 | zfUpdateSupportRate(dev, pBssInfo->extSupportedRates); | |
3907 | ||
3908 | wd->beaconInterval = pBssInfo->beaconInterval[0] + | |
3909 | (((u16_t) pBssInfo->beaconInterval[1]) << 8); | |
3910 | if (wd->beaconInterval == 0) | |
3911 | { | |
3912 | wd->beaconInterval = 100; | |
3913 | } | |
3914 | ||
3915 | /* ESS bit on */ | |
3916 | wd->sta.capability[0] |= ZM_BIT_0; | |
3917 | /* IBSS bit off */ | |
3918 | wd->sta.capability[0] &= ~ZM_BIT_1; | |
3919 | ||
3920 | /* 11n AP flag */ | |
3921 | wd->sta.EnableHT = pBssInfo->EnableHT; | |
3922 | wd->sta.SG40 = pBssInfo->SG40; | |
3923 | #ifdef ZM_ENABLE_CENC | |
3924 | if ( pBssInfo->securityType == ZM_SECURITY_TYPE_CENC ) | |
3925 | { | |
3926 | wd->sta.wmeEnabled = 0; //Disable WMM in CENC | |
3927 | cencInit(dev); | |
3928 | cencSetCENCMode(dev, NdisCENC_PSK); | |
3929 | wd->sta.wpaState = ZM_STA_WPA_STATE_INIT; | |
3930 | /* CENC */ | |
3931 | if ( pBssInfo->cencIe[1] != 0 ) | |
3932 | { | |
3933 | //wd->sta.wepStatus = ZM_ENCRYPTION_CENC; | |
3934 | //wd->sta.encryMode = ZM_CENC; | |
3935 | zfwCencHandleBeaconProbrespon(dev, (u8_t *)&pBssInfo->cencIe, | |
3936 | (u8_t *)&pBssInfo->ssid, (u8_t *)&pBssInfo->macaddr); | |
3937 | zfMemoryCopy(wd->sta.cencIe, pBssInfo->cencIe, | |
3938 | pBssInfo->cencIe[1]+2); | |
3939 | } | |
3940 | else | |
3941 | { | |
3942 | wd->sta.cencIe[1] = 0; | |
3943 | } | |
3944 | } | |
3945 | #endif //ZM_ENABLE_CENC | |
3946 | if ( pBssInfo->securityType == ZM_SECURITY_TYPE_WPA ) | |
3947 | { | |
3948 | wd->sta.wpaState = ZM_STA_WPA_STATE_INIT; | |
3949 | ||
3950 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_TKIP ) | |
3951 | { | |
3952 | wd->sta.encryMode = ZM_TKIP; | |
3953 | ||
3954 | /* Turn on software encryption/decryption for TKIP */ | |
3955 | if (wd->sta.EnableHT == 1) | |
3956 | { | |
3957 | zfStaEnableSWEncryption(dev, (ZM_SW_TKIP_ENCRY_EN|ZM_SW_TKIP_DECRY_EN)); | |
3958 | } | |
3959 | ||
3960 | /* Do not support TKIP in 11n mode */ | |
3961 | //wd->sta.EnableHT = 0; | |
3962 | //pBssInfo->enableHT40 = 0; | |
3963 | } | |
3964 | else if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
3965 | { | |
3966 | wd->sta.encryMode = ZM_AES; | |
3967 | ||
3968 | /* If AP supports HT mode */ | |
3969 | if (wd->sta.EnableHT) | |
3970 | { | |
3971 | /* Set MPDU density to 8 us*/ | |
3972 | density = ZM_MPDU_DENSITY_8US; | |
3973 | } | |
3974 | } | |
3975 | ||
3976 | if ( pBssInfo->wpaIe[1] != 0 ) | |
3977 | { | |
3978 | zfMemoryCopy(wd->sta.wpaIe, pBssInfo->wpaIe, | |
3979 | pBssInfo->wpaIe[1]+2); | |
3980 | } | |
3981 | else | |
3982 | { | |
3983 | wd->sta.wpaIe[1] = 0; | |
3984 | } | |
3985 | ||
3986 | if ( pBssInfo->rsnIe[1] != 0 ) | |
3987 | { | |
3988 | zfMemoryCopy(wd->sta.rsnIe, pBssInfo->rsnIe, | |
3989 | pBssInfo->rsnIe[1]+2); | |
3990 | } | |
3991 | else | |
3992 | { | |
3993 | wd->sta.rsnIe[1] = 0; | |
3994 | } | |
3995 | } | |
3996 | ||
3997 | ||
3998 | ||
3999 | /* check preamble bit */ | |
4000 | wd->preambleTypeInUsed = wd->preambleType; | |
4001 | if ( wd->preambleTypeInUsed == ZM_PREAMBLE_TYPE_AUTO ) | |
4002 | { | |
4003 | if (pBssInfo->capability[0] & ZM_BIT_5) | |
4004 | { | |
4005 | wd->preambleTypeInUsed = ZM_PREAMBLE_TYPE_SHORT; | |
4006 | } | |
4007 | else | |
4008 | { | |
4009 | wd->preambleTypeInUsed = ZM_PREAMBLE_TYPE_LONG; | |
4010 | } | |
4011 | } | |
4012 | ||
4013 | if (wd->preambleTypeInUsed == ZM_PREAMBLE_TYPE_LONG) | |
4014 | { | |
4015 | wd->sta.capability[0] &= ~ZM_BIT_5; | |
4016 | } | |
4017 | else | |
4018 | { | |
4019 | wd->sta.capability[0] |= ZM_BIT_5; | |
4020 | } | |
4021 | ||
4022 | /* check 802.11n 40MHz Setting */ | |
4023 | if ((pBssInfo->enableHT40 == 1) && | |
4024 | ((pBssInfo->extChOffset == 1) || (pBssInfo->extChOffset == 3))) | |
4025 | { | |
4026 | wd->BandWidth40 = pBssInfo->enableHT40; | |
4027 | wd->ExtOffset = pBssInfo->extChOffset; | |
4028 | } | |
4029 | else | |
4030 | { | |
4031 | wd->BandWidth40 = 0; | |
4032 | wd->ExtOffset = 0; | |
4033 | } | |
4034 | ||
4035 | /* check 802.11H support bit */ | |
4036 | ||
4037 | /* check Owl Ap */ | |
4038 | if ( pBssInfo->athOwlAp & ZM_BIT_0 ) | |
4039 | { | |
4040 | /* In this function, FW retry will be enable, ZM_MAC_REG_RETRY_MAX | |
4041 | will be set to 0. | |
4042 | */ | |
4043 | zfHpDisableHwRetry(dev); | |
4044 | wd->sta.athOwlAp = 1; | |
4045 | /* Set MPDU density to 8 us*/ | |
4046 | density = ZM_MPDU_DENSITY_8US; | |
4047 | } | |
4048 | else | |
4049 | { | |
4050 | /* In this function, FW retry will be disable, ZM_MAC_REG_RETRY_MAX | |
4051 | will be set to 3. | |
4052 | */ | |
4053 | zfHpEnableHwRetry(dev); | |
4054 | wd->sta.athOwlAp = 0; | |
4055 | } | |
4056 | wd->reorder = 1; | |
4057 | ||
4058 | /* Set MPDU density */ | |
4059 | zfHpSetMPDUDensity(dev, density); | |
4060 | ||
4061 | /* check short slot time bit */ | |
4062 | if ( pBssInfo->capability[1] & ZM_BIT_2 ) | |
4063 | { | |
4064 | wd->sta.capability[1] |= ZM_BIT_2; | |
4065 | } | |
4066 | ||
4067 | if ( pBssInfo->erp & ZM_BIT_1 ) | |
4068 | { | |
4069 | //zm_debug_msg0("protection mode on"); | |
4070 | wd->sta.bProtectionMode = TRUE; | |
4071 | zfHpSetSlotTime(dev, 0); | |
4072 | } | |
4073 | else | |
4074 | { | |
4075 | //zm_debug_msg0("protection mode off"); | |
4076 | wd->sta.bProtectionMode = FALSE; | |
4077 | zfHpSetSlotTime(dev, 1); | |
4078 | } | |
4079 | ||
4080 | if (pBssInfo->marvelAp == 1) | |
4081 | { | |
4082 | wd->sta.enableDrvBA = 0; | |
4083 | /* | |
4084 | * 8701 : NetGear 3500 (MARVELL) | |
4085 | * Downlink issue : set slottime to 20. | |
4086 | */ | |
4087 | zfHpSetSlotTimeRegister(dev, 0); | |
4088 | } | |
4089 | else | |
4090 | { | |
4091 | wd->sta.enableDrvBA = 1; | |
4092 | ||
4093 | /* | |
4094 | * This is not good for here do reset slot time. | |
4095 | * I think it should reset when leave MARVELL ap | |
4096 | * or enter disconnect state etc. | |
4097 | */ | |
4098 | zfHpSetSlotTimeRegister(dev, 1); | |
4099 | } | |
4100 | ||
4101 | //Store probe response frame body, for VISTA only | |
4102 | wd->sta.beaconFrameBodySize = pBssInfo->frameBodysize + 12; | |
4103 | if (wd->sta.beaconFrameBodySize > ZM_CACHED_FRAMEBODY_SIZE) | |
4104 | { | |
4105 | wd->sta.beaconFrameBodySize = ZM_CACHED_FRAMEBODY_SIZE; | |
4106 | } | |
4107 | for (k=0; k<8; k++) | |
4108 | { | |
4109 | wd->sta.beaconFrameBody[k] = pBssInfo->timeStamp[k]; | |
4110 | } | |
4111 | wd->sta.beaconFrameBody[8] = pBssInfo->beaconInterval[0]; | |
4112 | wd->sta.beaconFrameBody[9] = pBssInfo->beaconInterval[1]; | |
4113 | wd->sta.beaconFrameBody[10] = pBssInfo->capability[0]; | |
4114 | wd->sta.beaconFrameBody[11] = pBssInfo->capability[1]; | |
4115 | for (k=0; k<(wd->sta.beaconFrameBodySize - 12); k++) | |
4116 | { | |
4117 | wd->sta.beaconFrameBody[k+12] = pBssInfo->frameBody[k]; | |
4118 | } | |
4119 | ||
4120 | if ( ( pBssInfo->capability[0] & ZM_BIT_4 )&& | |
4121 | (( wd->sta.authMode == ZM_AUTH_MODE_OPEN )|| | |
4122 | ( wd->sta.authMode == ZM_AUTH_MODE_SHARED_KEY)|| | |
4123 | (wd->sta.authMode == ZM_AUTH_MODE_AUTO)) ) | |
4124 | { /* privacy enabled */ | |
4125 | ||
4126 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_WEP_DISABLED ) | |
4127 | { | |
4128 | zm_debug_msg0("Adapter is no WEP, try to connect to WEP AP"); | |
4129 | ret = FALSE; | |
4130 | } | |
4131 | ||
4132 | /* Do not support WEP in 11n mode */ | |
4133 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_WEP_ENABLED ) | |
4134 | { | |
4135 | /* Turn on software encryption/decryption for WEP */ | |
4136 | if (wd->sta.EnableHT == 1) | |
4137 | { | |
4138 | zfStaEnableSWEncryption(dev, (ZM_SW_WEP_ENCRY_EN|ZM_SW_WEP_DECRY_EN)); | |
4139 | } | |
4140 | ||
4141 | //wd->sta.EnableHT = 0; | |
4142 | //wd->BandWidth40 = 0; | |
4143 | //wd->ExtOffset = 0; | |
4144 | } | |
4145 | ||
4146 | wd->sta.capability[0] |= ZM_BIT_4; | |
4147 | ||
4148 | if ( wd->sta.authMode == ZM_AUTH_MODE_AUTO ) | |
4149 | { /* Try to use open and shared-key authehtication alternatively */ | |
4150 | if ( (wd->sta.connectTimeoutCount % 2) == 0 ) | |
4151 | wd->sta.bIsSharedKey = 0; | |
4152 | else | |
4153 | wd->sta.bIsSharedKey = 1; | |
4154 | } | |
4155 | else if ( wd->sta.authMode != ZM_AUTH_MODE_SHARED_KEY ) | |
4156 | { /* open or auto */ | |
4157 | //zfStaStartConnect(dev, 0); | |
4158 | wd->sta.bIsSharedKey = 0; | |
4159 | } | |
4160 | else if ( wd->sta.authMode != ZM_AUTH_MODE_OPEN ) | |
4161 | { /* shared key */ | |
4162 | //zfStaStartConnect(dev, 1) ; | |
4163 | wd->sta.bIsSharedKey = 1; | |
4164 | } | |
4165 | } | |
4166 | else | |
4167 | { | |
4168 | if ( (pBssInfo->securityType == ZM_SECURITY_TYPE_WPA)|| | |
4169 | (pBssInfo->capability[0] & ZM_BIT_4) ) | |
4170 | { | |
4171 | wd->sta.capability[0] |= ZM_BIT_4; | |
4172 | /* initialize WPA related parameters */ | |
4173 | } | |
4174 | else | |
4175 | { | |
4176 | wd->sta.capability[0] &= (~ZM_BIT_4); | |
4177 | } | |
4178 | ||
4179 | /* authentication with open system */ | |
4180 | //zfStaStartConnect(dev, 0); | |
4181 | wd->sta.bIsSharedKey = 0; | |
4182 | } | |
4183 | ||
bbc9a991 | 4184 | /* Improve WEP/TKIP performance with HT AP, detail information please look bug#32495 */ |
4bd43f50 LR |
4185 | /* |
4186 | if ( (pBssInfo->broadcomHTAp == 1) | |
4187 | && (wd->sta.SWEncryptEnable != 0) ) | |
4188 | { | |
4189 | zfHpSetTTSIFSTime(dev, 0xa); | |
4190 | } | |
4191 | else | |
4192 | { | |
4193 | zfHpSetTTSIFSTime(dev, 0x8); | |
4194 | } | |
4195 | */ | |
4196 | } | |
4197 | else | |
4198 | { | |
4199 | zm_debug_msg0("Desired SSID not found"); | |
4200 | goto zlConnectFailed; | |
4201 | } | |
4202 | ||
4203 | ||
4204 | zfCoreSetFrequencyV2(dev, wd->frequency, zfStaStartConnectCb); | |
4205 | return; | |
4206 | ||
4207 | zlConnectFailed: | |
4208 | zfStaConnectFail(dev, ZM_STATUS_MEDIA_DISCONNECT_NOT_FOUND, wd->sta.bssid, 0); | |
4209 | return; | |
4210 | } | |
4211 | ||
4212 | u8_t zfCheckWPAAuth(zdev_t* dev, struct zsBssInfo* pBssInfo) | |
4213 | { | |
4214 | u8_t ret=TRUE; | |
4215 | u8_t pmkCount; | |
4216 | u8_t i; | |
4217 | u16_t encAlgoType = 0; | |
4218 | ||
4219 | zmw_get_wlan_dev(dev); | |
4220 | ||
4221 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_TKIP ) | |
4222 | { | |
4223 | encAlgoType = ZM_TKIP; | |
4224 | } | |
4225 | else if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
4226 | { | |
4227 | encAlgoType = ZM_AES; | |
4228 | } | |
4229 | ||
4230 | switch(wd->sta.authMode) | |
4231 | { | |
4232 | case ZM_AUTH_MODE_WPA: | |
4233 | case ZM_AUTH_MODE_WPAPSK: | |
4234 | if ( pBssInfo->wpaIe[1] == 0 ) | |
4235 | { | |
4236 | ret = FALSE; | |
4237 | break; | |
4238 | } | |
4239 | ||
4240 | pmkCount = pBssInfo->wpaIe[12]; | |
4241 | for(i=0; i < pmkCount; i++) | |
4242 | { | |
4243 | if ( pBssInfo->wpaIe[17 + 4*i] == encAlgoType ) | |
4244 | { | |
4245 | ret = TRUE; | |
4246 | goto done; | |
4247 | } | |
4248 | } | |
4249 | ||
4250 | ret = FALSE; | |
4251 | break; | |
4252 | ||
4253 | case ZM_AUTH_MODE_WPA2: | |
4254 | case ZM_AUTH_MODE_WPA2PSK: | |
4255 | if ( pBssInfo->rsnIe[1] == 0 ) | |
4256 | { | |
4257 | ret = FALSE; | |
4258 | break; | |
4259 | } | |
4260 | ||
4261 | pmkCount = pBssInfo->rsnIe[8]; | |
4262 | for(i=0; i < pmkCount; i++) | |
4263 | { | |
4264 | if ( pBssInfo->rsnIe[13 + 4*i] == encAlgoType ) | |
4265 | { | |
4266 | ret = TRUE; | |
4267 | goto done; | |
4268 | } | |
4269 | } | |
4270 | ||
4271 | ret = FALSE; | |
4272 | break; | |
4273 | } | |
4274 | ||
4275 | done: | |
4276 | return ret; | |
4277 | } | |
4278 | ||
4279 | u8_t zfCheckAuthentication(zdev_t* dev, struct zsBssInfo* pBssInfo) | |
4280 | { | |
4281 | u8_t ret=TRUE; | |
4282 | u16_t encAlgoType; | |
4283 | u16_t UnicastCipherNum; | |
4284 | ||
4285 | zmw_get_wlan_dev(dev); | |
4286 | ||
4287 | /* Connecting to ANY has been checked */ | |
4288 | if ( wd->sta.ssidLen == 0 ) | |
4289 | { | |
4290 | return ret; | |
4291 | } | |
4292 | ||
4293 | ||
4294 | switch(wd->sta.authMode) | |
4295 | //switch(wd->ws.authMode)//Quickly reboot | |
4296 | { | |
4297 | case ZM_AUTH_MODE_WPA_AUTO: | |
4298 | case ZM_AUTH_MODE_WPAPSK_AUTO: | |
4299 | encAlgoType = 0; | |
4300 | if(pBssInfo->rsnIe[1] != 0) | |
4301 | { | |
4302 | UnicastCipherNum = (pBssInfo->rsnIe[8]) + | |
4303 | (pBssInfo->rsnIe[9] << 8); | |
4304 | ||
4305 | /* If there is only one unicast cipher */ | |
4306 | if (UnicastCipherNum == 1) | |
4307 | { | |
4308 | encAlgoType = pBssInfo->rsnIe[13]; | |
4309 | //encAlgoType = pBssInfo->rsnIe[7]; | |
4310 | } | |
4311 | else | |
4312 | { | |
4313 | u16_t ii; | |
4314 | u16_t desiredCipher = 0; | |
4315 | u16_t IEOffSet = 13; | |
4316 | ||
4317 | /* Enumerate all the supported unicast cipher */ | |
4318 | for (ii = 0; ii < UnicastCipherNum; ii++) | |
4319 | { | |
4320 | if (pBssInfo->rsnIe[IEOffSet+ii*4] > desiredCipher) | |
4321 | { | |
4322 | desiredCipher = pBssInfo->rsnIe[IEOffSet+ii*4]; | |
4323 | } | |
4324 | } | |
4325 | ||
4326 | encAlgoType = desiredCipher; | |
4327 | } | |
4328 | ||
4329 | if ( encAlgoType == 0x02 ) | |
4330 | { | |
4331 | wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; | |
4332 | ||
4333 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA_AUTO ) | |
4334 | { | |
4335 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA2; | |
4336 | } | |
4337 | else //ZM_AUTH_MODE_WPAPSK_AUTO | |
4338 | { | |
4339 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA2PSK; | |
4340 | } | |
4341 | } | |
4342 | else if ( encAlgoType == 0x04 ) | |
4343 | { | |
4344 | wd->sta.wepStatus = ZM_ENCRYPTION_AES; | |
4345 | ||
4346 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA_AUTO ) | |
4347 | { | |
4348 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA2; | |
4349 | } | |
4350 | else //ZM_AUTH_MODE_WPAPSK_AUTO | |
4351 | { | |
4352 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA2PSK; | |
4353 | } | |
4354 | } | |
4355 | else | |
4356 | { | |
4357 | ret = FALSE; | |
4358 | } | |
4359 | } | |
4360 | else if(pBssInfo->wpaIe[1] != 0) | |
4361 | { | |
4362 | UnicastCipherNum = (pBssInfo->wpaIe[12]) + | |
4363 | (pBssInfo->wpaIe[13] << 8); | |
4364 | ||
4365 | /* If there is only one unicast cipher */ | |
4366 | if (UnicastCipherNum == 1) | |
4367 | { | |
4368 | encAlgoType = pBssInfo->wpaIe[17]; | |
4369 | //encAlgoType = pBssInfo->wpaIe[11]; | |
4370 | } | |
4371 | else | |
4372 | { | |
4373 | u16_t ii; | |
4374 | u16_t desiredCipher = 0; | |
4375 | u16_t IEOffSet = 17; | |
4376 | ||
4377 | /* Enumerate all the supported unicast cipher */ | |
4378 | for (ii = 0; ii < UnicastCipherNum; ii++) | |
4379 | { | |
4380 | if (pBssInfo->wpaIe[IEOffSet+ii*4] > desiredCipher) | |
4381 | { | |
4382 | desiredCipher = pBssInfo->wpaIe[IEOffSet+ii*4]; | |
4383 | } | |
4384 | } | |
4385 | ||
4386 | encAlgoType = desiredCipher; | |
4387 | } | |
4388 | ||
4389 | if ( encAlgoType == 0x02 ) | |
4390 | { | |
4391 | wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; | |
4392 | ||
4393 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA_AUTO ) | |
4394 | { | |
4395 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA; | |
4396 | } | |
4397 | else //ZM_AUTH_MODE_WPAPSK_AUTO | |
4398 | { | |
4399 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPAPSK; | |
4400 | } | |
4401 | } | |
4402 | else if ( encAlgoType == 0x04 ) | |
4403 | { | |
4404 | wd->sta.wepStatus = ZM_ENCRYPTION_AES; | |
4405 | ||
4406 | if ( wd->sta.authMode == ZM_AUTH_MODE_WPA_AUTO ) | |
4407 | { | |
4408 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPA; | |
4409 | } | |
4410 | else //ZM_AUTH_MODE_WPAPSK_AUTO | |
4411 | { | |
4412 | wd->sta.currentAuthMode = ZM_AUTH_MODE_WPAPSK; | |
4413 | } | |
4414 | } | |
4415 | else | |
4416 | { | |
4417 | ret = FALSE; | |
4418 | } | |
4419 | ||
4420 | ||
4421 | } | |
4422 | else | |
4423 | { | |
4424 | ret = FALSE; | |
4425 | } | |
4426 | ||
4427 | break; | |
4428 | ||
4429 | case ZM_AUTH_MODE_WPA: | |
4430 | case ZM_AUTH_MODE_WPAPSK: | |
4431 | case ZM_AUTH_MODE_WPA_NONE: | |
4432 | case ZM_AUTH_MODE_WPA2: | |
4433 | case ZM_AUTH_MODE_WPA2PSK: | |
4434 | { | |
4435 | if ( pBssInfo->securityType != ZM_SECURITY_TYPE_WPA ) | |
4436 | { | |
4437 | ret = FALSE; | |
4438 | } | |
4439 | ||
4440 | ret = zfCheckWPAAuth(dev, pBssInfo); | |
4441 | } | |
4442 | break; | |
4443 | ||
4444 | case ZM_AUTH_MODE_OPEN: | |
4445 | case ZM_AUTH_MODE_SHARED_KEY: | |
4446 | case ZM_AUTH_MODE_AUTO: | |
4447 | { | |
4448 | if ( pBssInfo->wscIe[1] ) | |
4449 | { | |
4450 | // If the AP is a Jumpstart AP, it's ok!! Ray | |
4451 | break; | |
4452 | } | |
4453 | else if ( pBssInfo->securityType == ZM_SECURITY_TYPE_WPA ) | |
4454 | { | |
4455 | ret = FALSE; | |
4456 | } | |
4457 | } | |
4458 | break; | |
4459 | ||
4460 | default: | |
4461 | break; | |
4462 | } | |
4463 | ||
4464 | return ret; | |
4465 | } | |
4466 | ||
4467 | u8_t zfStaIsConnected(zdev_t* dev) | |
4468 | { | |
4469 | zmw_get_wlan_dev(dev); | |
4470 | ||
4471 | if ( wd->sta.adapterState == ZM_STA_STATE_CONNECTED ) | |
4472 | { | |
4473 | return TRUE; | |
4474 | } | |
4475 | ||
4476 | return FALSE; | |
4477 | } | |
4478 | ||
4479 | u8_t zfStaIsConnecting(zdev_t* dev) | |
4480 | { | |
4481 | zmw_get_wlan_dev(dev); | |
4482 | ||
4483 | if ( wd->sta.adapterState == ZM_STA_STATE_CONNECTING ) | |
4484 | { | |
4485 | return TRUE; | |
4486 | } | |
4487 | ||
4488 | return FALSE; | |
4489 | } | |
4490 | ||
4491 | u8_t zfStaIsDisconnect(zdev_t* dev) | |
4492 | { | |
4493 | zmw_get_wlan_dev(dev); | |
4494 | ||
4495 | if ( wd->sta.adapterState == ZM_STA_STATE_DISCONNECT ) | |
4496 | { | |
4497 | return TRUE; | |
4498 | } | |
4499 | ||
4500 | return FALSE; | |
4501 | } | |
4502 | ||
4503 | u8_t zfChangeAdapterState(zdev_t* dev, u8_t newState) | |
4504 | { | |
4505 | u8_t ret = TRUE; | |
4506 | ||
4507 | zmw_get_wlan_dev(dev); | |
4508 | ||
4509 | zmw_declare_for_critical_section(); | |
4510 | ||
4511 | //if ( newState == wd->sta.adapterState ) | |
4512 | //{ | |
4513 | // return FALSE; | |
4514 | //} | |
4515 | ||
4516 | switch(newState) | |
4517 | { | |
4518 | case ZM_STA_STATE_DISCONNECT: | |
4519 | zfResetSupportRate(dev, ZM_DEFAULT_SUPPORT_RATE_DISCONNECT); | |
4520 | ||
4521 | #if 1 | |
4522 | zfScanMgrScanStop(dev, ZM_SCAN_MGR_SCAN_INTERNAL); | |
4523 | #else | |
4524 | if ( wd->sta.bChannelScan ) | |
4525 | { | |
4526 | /* stop the action of channel scanning */ | |
4527 | wd->sta.bChannelScan = FALSE; | |
4528 | ret = TRUE; | |
4529 | break; | |
4530 | } | |
4531 | #endif | |
4532 | ||
4533 | break; | |
4534 | case ZM_STA_STATE_CONNECTING: | |
4535 | #if 1 | |
4536 | zfScanMgrScanStop(dev, ZM_SCAN_MGR_SCAN_INTERNAL); | |
4537 | #else | |
4538 | if ( wd->sta.bChannelScan ) | |
4539 | { | |
4540 | /* stop the action of channel scanning */ | |
4541 | wd->sta.bChannelScan = FALSE; | |
4542 | ret = TRUE; | |
4543 | break; | |
4544 | } | |
4545 | #endif | |
4546 | ||
4547 | break; | |
4548 | case ZM_STA_STATE_CONNECTED: | |
4549 | break; | |
4550 | default: | |
4551 | break; | |
4552 | } | |
4553 | ||
4554 | //if ( ret ) | |
4555 | //{ | |
4556 | zmw_enter_critical_section(dev); | |
4557 | wd->sta.adapterState = newState; | |
4558 | zmw_leave_critical_section(dev); | |
4559 | ||
4560 | zm_debug_msg1("change adapter state = ", newState); | |
4561 | //} | |
4562 | ||
4563 | return ret; | |
4564 | } | |
4565 | ||
4566 | /************************************************************************/ | |
4567 | /* */ | |
4568 | /* FUNCTION DESCRIPTION zfStaMmAddIeSsid */ | |
4569 | /* Add information element SSID to buffer. */ | |
4570 | /* */ | |
4571 | /* INPUTS */ | |
4572 | /* dev : device pointer */ | |
4573 | /* buf : buffer to add information element */ | |
4574 | /* offset : add information element from this offset */ | |
4575 | /* */ | |
4576 | /* OUTPUTS */ | |
4577 | /* buffer offset after adding information element */ | |
4578 | /* */ | |
4579 | /* AUTHOR */ | |
4580 | /* Ji-Huang Lee ZyDAS Technology Corporation 2005.11 */ | |
4581 | /* */ | |
4582 | /************************************************************************/ | |
4583 | u16_t zfStaAddIeSsid(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
4584 | { | |
4585 | u16_t i; | |
4586 | ||
4587 | zmw_get_wlan_dev(dev); | |
4588 | ||
4589 | /* Element ID */ | |
4590 | zmw_tx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_SSID); | |
4591 | ||
4592 | /* Element Length */ | |
4593 | zmw_tx_buf_writeb(dev, buf, offset++, wd->sta.ssidLen); | |
4594 | ||
4595 | /* Information : SSID */ | |
4596 | for (i=0; i<wd->sta.ssidLen; i++) | |
4597 | { | |
4598 | zmw_tx_buf_writeb(dev, buf, offset++, wd->sta.ssid[i]); | |
4599 | } | |
4600 | ||
4601 | return offset; | |
4602 | } | |
4603 | ||
4604 | /************************************************************************/ | |
4605 | /* */ | |
4606 | /* FUNCTION DESCRIPTION zfStaMmAddIeWpa */ | |
4607 | /* Add information element SSID to buffer. */ | |
4608 | /* */ | |
4609 | /* INPUTS */ | |
4610 | /* dev : device pointer */ | |
4611 | /* buf : buffer to add information element */ | |
4612 | /* offset : add information element from this offset */ | |
4613 | /* */ | |
4614 | /* OUTPUTS */ | |
4615 | /* buffer offset after adding information element */ | |
4616 | /* */ | |
4617 | /* AUTHOR */ | |
4618 | /* Ji-Huang Lee ZyDAS Technology Corporation 2006.01 */ | |
4619 | /* */ | |
4620 | /************************************************************************/ | |
4621 | u16_t zfStaAddIeWpaRsn(zdev_t* dev, zbuf_t* buf, u16_t offset, u8_t frameType) | |
4622 | { | |
4623 | u32_t i; | |
4624 | u8_t ssn[64]={ | |
4625 | /* Element ID */ | |
4626 | 0xdd, | |
4627 | /* Length */ | |
4628 | 0x18, | |
4629 | /* OUI type */ | |
4630 | 0x00, 0x50, 0xf2, 0x01, | |
4631 | /* Version */ | |
4632 | 0x01, 0x00, | |
4633 | /* Group Cipher Suite, default=TKIP */ | |
4634 | 0x00, 0x50, 0xf2, 0x02, | |
4635 | /* Pairwise Cipher Suite Count */ | |
4636 | 0x01, 0x00, | |
4637 | /* Pairwise Cipher Suite, default=TKIP */ | |
4638 | 0x00, 0x50, 0xf2, 0x02, | |
4639 | /* Authentication and Key Management Suite Count */ | |
4640 | 0x01, 0x00, | |
4641 | /* Authentication type, default=PSK */ | |
4642 | 0x00, 0x50, 0xf2, 0x02, | |
4643 | /* WPA capability */ | |
4644 | 0x00, 0x00 | |
4645 | }; | |
4646 | ||
4647 | u8_t rsn[64]={ | |
4648 | /* Element ID */ | |
4649 | 0x30, | |
4650 | /* Length */ | |
4651 | 0x14, | |
4652 | /* Version */ | |
4653 | 0x01, 0x00, | |
4654 | /* Group Cipher Suite, default=TKIP */ | |
4655 | 0x00, 0x0f, 0xac, 0x02, | |
4656 | /* Pairwise Cipher Suite Count */ | |
4657 | 0x01, 0x00, | |
4658 | /* Pairwise Cipher Suite, default=TKIP */ | |
4659 | 0x00, 0x0f, 0xac, 0x02, | |
4660 | /* Authentication and Key Management Suite Count */ | |
4661 | 0x01, 0x00, | |
4662 | /* Authentication type, default=PSK */ | |
4663 | 0x00, 0x0f, 0xac, 0x02, | |
4664 | /* RSN capability */ | |
4665 | 0x00, 0x00 | |
4666 | }; | |
4667 | ||
4668 | zmw_get_wlan_dev(dev); | |
4669 | ||
4670 | if ( wd->sta.currentAuthMode == ZM_AUTH_MODE_WPAPSK ) | |
4671 | { | |
4672 | /* Overwrite Group Cipher Suite by AP's setting */ | |
4673 | zfMemoryCopy(ssn+8, wd->sta.wpaIe+8, 4); | |
4674 | ||
4675 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
4676 | { | |
4677 | /* Overwrite Pairwise Cipher Suite by AES */ | |
4678 | zfMemoryCopy(ssn+14, zgWpaAesOui, 4); | |
4679 | } | |
4680 | ||
4681 | zfCopyToIntTxBuffer(dev, buf, ssn, offset, ssn[1]+2); | |
4682 | zfMemoryCopy(wd->sta.wpaIe, ssn, ssn[1]+2); | |
4683 | offset += (ssn[1]+2); | |
4684 | } | |
4685 | else if ( wd->sta.currentAuthMode == ZM_AUTH_MODE_WPA ) | |
4686 | { | |
4687 | /* Overwrite Group Cipher Suite by AP's setting */ | |
4688 | zfMemoryCopy(ssn+8, wd->sta.wpaIe+8, 4); | |
4689 | /* Overwrite Key Management Suite by WPA-Radius */ | |
4690 | zfMemoryCopy(ssn+20, zgWpaRadiusOui, 4); | |
4691 | ||
4692 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
4693 | { | |
4694 | /* Overwrite Pairwise Cipher Suite by AES */ | |
4695 | zfMemoryCopy(ssn+14, zgWpaAesOui, 4); | |
4696 | } | |
4697 | ||
4698 | zfCopyToIntTxBuffer(dev, buf, ssn, offset, ssn[1]+2); | |
4699 | zfMemoryCopy(wd->sta.wpaIe, ssn, ssn[1]+2); | |
4700 | offset += (ssn[1]+2); | |
4701 | } | |
4702 | else if ( wd->sta.currentAuthMode == ZM_AUTH_MODE_WPA2PSK ) | |
4703 | { | |
4704 | /* Overwrite Group Cipher Suite by AP's setting */ | |
4705 | zfMemoryCopy(rsn+4, wd->sta.rsnIe+4, 4); | |
4706 | ||
4707 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
4708 | { | |
4709 | /* Overwrite Pairwise Cipher Suite by AES */ | |
4710 | zfMemoryCopy(rsn+10, zgWpa2AesOui, 4); | |
4711 | } | |
4712 | ||
4713 | if ( frameType == ZM_WLAN_FRAME_TYPE_REASOCREQ ) | |
4714 | { | |
4715 | for(i=0; i<wd->sta.pmkidInfo.bssidCount; i++) | |
4716 | { | |
4717 | if ( zfMemoryIsEqual((u8_t*) wd->sta.pmkidInfo.bssidInfo[i].bssid, | |
4718 | (u8_t*) wd->sta.bssid, 6) ) | |
4719 | { | |
4720 | /* matched */ | |
4721 | break; | |
4722 | } | |
4723 | ||
4724 | if ( i < wd->sta.pmkidInfo.bssidCount ) | |
4725 | { | |
4726 | // Fill PMKID Count in RSN information element | |
4727 | rsn[22] = 0x01; | |
4728 | rsn[23] = 0x00; | |
4729 | ||
4730 | // Fill PMKID in RSN information element | |
4731 | zfMemoryCopy(rsn+24, | |
4732 | wd->sta.pmkidInfo.bssidInfo[i].pmkid, 16); | |
4733 | rsn[1] += 18; | |
4734 | } | |
4735 | } | |
4736 | } | |
4737 | ||
4738 | zfCopyToIntTxBuffer(dev, buf, rsn, offset, rsn[1]+2); | |
4739 | zfMemoryCopy(wd->sta.rsnIe, rsn, rsn[1]+2); | |
4740 | offset += (rsn[1]+2); | |
4741 | } | |
4742 | else if ( wd->sta.currentAuthMode == ZM_AUTH_MODE_WPA2 ) | |
4743 | { | |
4744 | /* Overwrite Group Cipher Suite by AP's setting */ | |
4745 | zfMemoryCopy(rsn+4, wd->sta.rsnIe+4, 4); | |
4746 | /* Overwrite Key Management Suite by WPA2-Radius */ | |
4747 | zfMemoryCopy(rsn+16, zgWpa2RadiusOui, 4); | |
4748 | ||
4749 | if ( wd->sta.wepStatus == ZM_ENCRYPTION_AES ) | |
4750 | { | |
4751 | /* Overwrite Pairwise Cipher Suite by AES */ | |
4752 | zfMemoryCopy(rsn+10, zgWpa2AesOui, 4); | |
4753 | } | |
4754 | ||
4755 | if (( frameType == ZM_WLAN_FRAME_TYPE_REASOCREQ || ( frameType == ZM_WLAN_FRAME_TYPE_ASOCREQ ))) | |
4756 | { | |
4757 | ||
4758 | if (wd->sta.pmkidInfo.bssidCount != 0) { | |
4759 | // Fill PMKID Count in RSN information element | |
4760 | rsn[22] = 1; | |
4761 | rsn[23] = 0; | |
4762 | /* | |
4763 | * The caller is respnsible to give us the relevant PMKID. | |
4764 | * We'll only accept 1 PMKID for now. | |
4765 | */ | |
4766 | for(i=0; i<wd->sta.pmkidInfo.bssidCount; i++) | |
4767 | { | |
4768 | if ( zfMemoryIsEqual((u8_t*) wd->sta.pmkidInfo.bssidInfo[i].bssid, (u8_t*) wd->sta.bssid, 6) ) | |
4769 | { | |
4770 | zfMemoryCopy(rsn+24, wd->sta.pmkidInfo.bssidInfo[i].pmkid, 16); | |
4771 | break; | |
4772 | } | |
4773 | } | |
4774 | rsn[1] += 18; | |
4775 | } | |
4776 | ||
4777 | } | |
4778 | ||
4779 | zfCopyToIntTxBuffer(dev, buf, rsn, offset, rsn[1]+2); | |
4780 | zfMemoryCopy(wd->sta.rsnIe, rsn, rsn[1]+2); | |
4781 | offset += (rsn[1]+2); | |
4782 | } | |
4783 | ||
4784 | return offset; | |
4785 | } | |
4786 | ||
4787 | /************************************************************************/ | |
4788 | /* */ | |
4789 | /* FUNCTION DESCRIPTION zfStaAddIeIbss */ | |
4790 | /* Add information element IBSS parameter to buffer. */ | |
4791 | /* */ | |
4792 | /* INPUTS */ | |
4793 | /* dev : device pointer */ | |
4794 | /* buf : buffer to add information element */ | |
4795 | /* offset : add information element from this offset */ | |
4796 | /* */ | |
4797 | /* OUTPUTS */ | |
4798 | /* buffer offset after adding information element */ | |
4799 | /* */ | |
4800 | /* AUTHOR */ | |
4801 | /* Ji-Huang Lee ZyDAS Technology Corporation 2005.12 */ | |
4802 | /* */ | |
4803 | /************************************************************************/ | |
4804 | u16_t zfStaAddIeIbss(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
4805 | { | |
4806 | zmw_get_wlan_dev(dev); | |
4807 | ||
4808 | /* Element ID */ | |
4809 | zmw_tx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_IBSS); | |
4810 | ||
4811 | /* Element Length */ | |
4812 | zmw_tx_buf_writeb(dev, buf, offset++, 2); | |
4813 | ||
4814 | /* ATIM window */ | |
4815 | zmw_tx_buf_writeh(dev, buf, offset, wd->sta.atimWindow); | |
4816 | offset += 2; | |
4817 | ||
4818 | return offset; | |
4819 | } | |
4820 | ||
4821 | ||
4822 | ||
4823 | /************************************************************************/ | |
4824 | /* */ | |
4825 | /* FUNCTION DESCRIPTION zfStaAddIeWmeInfo */ | |
4826 | /* Add WME Information Element to buffer. */ | |
4827 | /* */ | |
4828 | /* INPUTS */ | |
4829 | /* dev : device pointer */ | |
4830 | /* buf : buffer to add information element */ | |
4831 | /* offset : add information element from this offset */ | |
4832 | /* */ | |
4833 | /* OUTPUTS */ | |
4834 | /* buffer offset after adding information element */ | |
4835 | /* */ | |
4836 | /* AUTHOR */ | |
4837 | /* Stephen Chen ZyDAS Technology Corporation 2006.6 */ | |
4838 | /* */ | |
4839 | /************************************************************************/ | |
4840 | u16_t zfStaAddIeWmeInfo(zdev_t* dev, zbuf_t* buf, u16_t offset, u8_t qosInfo) | |
4841 | { | |
4842 | /* Element ID */ | |
4843 | zmw_tx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_WIFI_IE); | |
4844 | ||
4845 | /* Element Length */ | |
4846 | zmw_tx_buf_writeb(dev, buf, offset++, 7); | |
4847 | ||
4848 | /* OUI */ | |
4849 | zmw_tx_buf_writeb(dev, buf, offset++, 0x00); | |
4850 | zmw_tx_buf_writeb(dev, buf, offset++, 0x50); | |
4851 | zmw_tx_buf_writeb(dev, buf, offset++, 0xF2); | |
4852 | zmw_tx_buf_writeb(dev, buf, offset++, 0x02); | |
4853 | zmw_tx_buf_writeb(dev, buf, offset++, 0x00); | |
4854 | zmw_tx_buf_writeb(dev, buf, offset++, 0x01); | |
4855 | ||
4856 | /* QoS Info */ | |
4857 | zmw_tx_buf_writeb(dev, buf, offset++, qosInfo); | |
4858 | ||
4859 | return offset; | |
4860 | } | |
4861 | ||
4862 | /************************************************************************/ | |
4863 | /* */ | |
4864 | /* FUNCTION DESCRIPTION zfStaAddIePowerCap */ | |
4865 | /* Add information element Power capability to buffer. */ | |
4866 | /* */ | |
4867 | /* INPUTS */ | |
4868 | /* dev : device pointer */ | |
4869 | /* buf : buffer to add information element */ | |
4870 | /* offset : add information element from this offset */ | |
4871 | /* */ | |
4872 | /* OUTPUTS */ | |
4873 | /* buffer offset after adding information element */ | |
4874 | /* */ | |
4875 | /* AUTHOR */ | |
4876 | /* Sharon 2007.12 */ | |
4877 | /* */ | |
4878 | /************************************************************************/ | |
4879 | u16_t zfStaAddIePowerCap(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
4880 | { | |
4881 | u8_t MaxTxPower; | |
4882 | u8_t MinTxPower; | |
4883 | ||
4bd43f50 LR |
4884 | /* Element ID */ |
4885 | zmw_tx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_POWER_CAPABILITY); | |
4886 | ||
4887 | /* Element Length */ | |
4888 | zmw_tx_buf_writeb(dev, buf, offset++, 2); | |
4889 | ||
4890 | MinTxPower = (u8_t)(zfHpGetMinTxPower(dev)/2); | |
4891 | MaxTxPower = (u8_t)(zfHpGetMaxTxPower(dev)/2); | |
4892 | ||
4893 | /* Min Transmit Power Cap */ | |
4894 | zmw_tx_buf_writeh(dev, buf, offset++, MinTxPower); | |
4895 | ||
4896 | /* Max Transmit Power Cap */ | |
4897 | zmw_tx_buf_writeh(dev, buf, offset++, MaxTxPower); | |
4898 | ||
4899 | return offset; | |
4900 | } | |
4901 | /************************************************************************/ | |
4902 | /* */ | |
4903 | /* FUNCTION DESCRIPTION zfStaAddIeSupportCh */ | |
4904 | /* Add information element supported channels to buffer. */ | |
4905 | /* */ | |
4906 | /* INPUTS */ | |
4907 | /* dev : device pointer */ | |
4908 | /* buf : buffer to add information element */ | |
4909 | /* offset : add information element from this offset */ | |
4910 | /* */ | |
4911 | /* OUTPUTS */ | |
4912 | /* buffer offset after adding information element */ | |
4913 | /* */ | |
4914 | /* AUTHOR */ | |
4915 | /* Sharon 2007.12 */ | |
4916 | /* */ | |
4917 | /************************************************************************/ | |
4918 | u16_t zfStaAddIeSupportCh(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
4919 | { | |
4920 | ||
4921 | u8_t i; | |
4922 | u16_t count_24G = 0; | |
4923 | u16_t count_5G = 0; | |
4924 | u16_t channelNum; | |
4925 | u8_t length; | |
4926 | ||
4927 | zmw_get_wlan_dev(dev); | |
4928 | ||
4929 | zmw_declare_for_critical_section(); | |
4930 | zmw_enter_critical_section(dev); | |
4931 | ||
4932 | for (i = 0; i < wd->regulationTable.allowChannelCnt; i++) | |
4933 | { | |
4934 | if (wd->regulationTable.allowChannel[i].channel < 3000) | |
4935 | { // 2.4Hz | |
4936 | count_24G++; | |
4937 | } | |
4938 | else | |
4939 | { // 5GHz | |
4940 | count_5G++; | |
4941 | } | |
4942 | } | |
4943 | ||
4944 | length = (u8_t)(count_5G * 2 + 2); //5G fill by pair, 2,4G (continuous channels) fill 2 bytes | |
4945 | ||
4946 | /* Element ID */ | |
4947 | zmw_tx_buf_writeb(dev, buf, offset++, ZM_WLAN_EID_SUPPORTED_CHANNELS ); | |
4948 | ||
4949 | /* Element Length */ | |
4950 | zmw_tx_buf_writeb(dev, buf, offset++, length); | |
4951 | ||
4952 | // 2.4GHz (continuous channels) | |
4953 | /* First channel number */ | |
4954 | zmw_tx_buf_writeh(dev, buf, offset++, 1); //Start from channle 1 | |
4955 | /* Number of channels */ | |
4956 | zmw_tx_buf_writeh(dev, buf, offset++, count_24G); | |
4957 | ||
4958 | for (i = 0; i < wd->regulationTable.allowChannelCnt ; i++) | |
4959 | { | |
4960 | if (wd->regulationTable.allowChannel[i].channel > 4000 && wd->regulationTable.allowChannel[i].channel < 5000) | |
4961 | { // 5GHz 4000 -5000Mhz | |
4962 | channelNum = (wd->regulationTable.allowChannel[i].channel-4000)/5; | |
4963 | /* First channel number */ | |
4964 | zmw_tx_buf_writeh(dev, buf, offset++, channelNum); | |
4965 | /* Number of channels */ | |
4966 | zmw_tx_buf_writeh(dev, buf, offset++, 1); | |
4967 | } | |
4968 | else if (wd->regulationTable.allowChannel[i].channel >= 5000) | |
4969 | { // 5GHz >5000Mhz | |
4970 | channelNum = (wd->regulationTable.allowChannel[i].channel-5000)/5; | |
4971 | /* First channel number */ | |
4972 | zmw_tx_buf_writeh(dev, buf, offset++, channelNum); | |
4973 | /* Number of channels */ | |
4974 | zmw_tx_buf_writeh(dev, buf, offset++, 1); | |
4975 | } | |
4976 | } | |
4977 | zmw_leave_critical_section(dev); | |
4978 | ||
4979 | return offset; | |
4980 | } | |
4981 | ||
4982 | void zfStaStartConnectCb(zdev_t* dev) | |
4983 | { | |
4984 | zmw_get_wlan_dev(dev); | |
4985 | ||
4986 | zfStaStartConnect(dev, wd->sta.bIsSharedKey); | |
4987 | } | |
4988 | ||
4989 | void zfStaStartConnect(zdev_t* dev, u8_t bIsSharedKey) | |
4990 | { | |
4991 | u32_t p1, p2; | |
4992 | u8_t newConnState; | |
4993 | ||
4994 | zmw_get_wlan_dev(dev); | |
4995 | zmw_declare_for_critical_section(); | |
4996 | ||
4997 | /* p1_low = algorithm number, p1_high = transaction sequence number */ | |
4998 | if ( bIsSharedKey ) | |
4999 | { | |
5000 | //wd->sta.connectState = ZM_STA_CONN_STATE_AUTH_SHARE_1; | |
5001 | newConnState = ZM_STA_CONN_STATE_AUTH_SHARE_1; | |
5002 | zm_debug_msg0("ZM_STA_CONN_STATE_AUTH_SHARE_1"); | |
5003 | p1 = ZM_AUTH_ALGO_SHARED_KEY; | |
5004 | } | |
5005 | else | |
5006 | { | |
5007 | //wd->sta.connectState = ZM_STA_CONN_STATE_AUTH_OPEN; | |
5008 | newConnState = ZM_STA_CONN_STATE_AUTH_OPEN; | |
5009 | zm_debug_msg0("ZM_STA_CONN_STATE_AUTH_OPEN"); | |
5010 | if( wd->sta.leapEnabled ) | |
5011 | p1 = ZM_AUTH_ALGO_LEAP; | |
5012 | else | |
5013 | p1 = ZM_AUTH_ALGO_OPEN_SYSTEM; | |
5014 | } | |
5015 | ||
5016 | /* status code */ | |
5017 | p2 = 0x0; | |
5018 | ||
5019 | zmw_enter_critical_section(dev); | |
5020 | wd->sta.connectTimer = wd->tick; | |
5021 | wd->sta.connectState = newConnState; | |
5022 | zmw_leave_critical_section(dev); | |
5023 | ||
5024 | /* send the 1st authentication frame */ | |
5025 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_AUTH, wd->sta.bssid, p1, p2, 0); | |
5026 | ||
5027 | return; | |
5028 | } | |
5029 | ||
5030 | void zfSendNullData(zdev_t* dev, u8_t type) | |
5031 | { | |
5032 | zbuf_t* buf; | |
5033 | //u16_t addrTblSize; | |
5034 | //struct zsAddrTbl addrTbl; | |
5035 | u16_t err; | |
5036 | u16_t hlen; | |
5037 | u16_t header[(34+8+1)/2]; | |
5038 | u16_t bcastAddr[3] = {0xffff,0xffff,0xffff}; | |
5039 | u16_t *dstAddr; | |
5040 | ||
5041 | zmw_get_wlan_dev(dev); | |
5042 | ||
92363b52 JP |
5043 | buf = zfwBufAllocate(dev, 1024); |
5044 | if (buf == NULL) | |
4bd43f50 LR |
5045 | { |
5046 | zm_msg0_mm(ZM_LV_0, "Alloc mm buf Fail!"); | |
5047 | return; | |
5048 | } | |
5049 | ||
5050 | zfwBufSetSize(dev, buf, 0); | |
5051 | ||
5052 | //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len); | |
5053 | ||
5054 | if ( wd->wlanMode == ZM_MODE_IBSS) | |
5055 | { | |
5056 | dstAddr = bcastAddr; | |
5057 | } | |
5058 | else | |
5059 | { | |
5060 | dstAddr = wd->sta.bssid; | |
5061 | } | |
5062 | ||
5063 | if (wd->sta.wmeConnected != 0) | |
5064 | { | |
5065 | /* If connect to a WMM AP, Send QoS Null data */ | |
5066 | hlen = zfTxGenMmHeader(dev, ZM_WLAN_FRAME_TYPE_QOS_NULL, dstAddr, header, 0, buf, 0, 0); | |
5067 | } | |
5068 | else | |
5069 | { | |
5070 | hlen = zfTxGenMmHeader(dev, ZM_WLAN_FRAME_TYPE_NULL, dstAddr, header, 0, buf, 0, 0); | |
5071 | } | |
5072 | ||
5073 | if (wd->wlanMode == ZM_MODE_INFRASTRUCTURE) | |
5074 | { | |
5075 | header[4] |= 0x0100; //TODS bit | |
5076 | } | |
5077 | ||
5078 | if ( type == 1 ) | |
5079 | { | |
5080 | header[4] |= 0x1000; | |
5081 | } | |
5082 | ||
5083 | /* Get buffer DMA address */ | |
5084 | //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0) | |
5085 | //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0) | |
5086 | //{ | |
5087 | // goto zlError; | |
5088 | //} | |
5089 | ||
5090 | /*increase unicast frame counter*/ | |
5091 | wd->commTally.txUnicastFrm++; | |
5092 | ||
92363b52 JP |
5093 | err = zfHpSend(dev, header, hlen, NULL, 0, NULL, 0, buf, 0, |
5094 | ZM_INTERNAL_ALLOC_BUF, 0, 0xff); | |
5095 | if (err != ZM_SUCCESS) | |
4bd43f50 LR |
5096 | { |
5097 | goto zlError; | |
5098 | } | |
5099 | ||
5100 | ||
5101 | return; | |
5102 | ||
5103 | zlError: | |
5104 | ||
5105 | zfwBufFree(dev, buf, 0); | |
5106 | return; | |
5107 | ||
5108 | } | |
5109 | ||
5110 | void zfSendPSPoll(zdev_t* dev) | |
5111 | { | |
5112 | zbuf_t* buf; | |
5113 | //u16_t addrTblSize; | |
5114 | //struct zsAddrTbl addrTbl; | |
5115 | u16_t err; | |
5116 | u16_t hlen; | |
5117 | u16_t header[(8+24+1)/2]; | |
5118 | ||
5119 | zmw_get_wlan_dev(dev); | |
5120 | ||
92363b52 JP |
5121 | buf = zfwBufAllocate(dev, 1024); |
5122 | if (buf == NULL) | |
4bd43f50 LR |
5123 | { |
5124 | zm_msg0_mm(ZM_LV_0, "Alloc mm buf Fail!"); | |
5125 | return; | |
5126 | } | |
5127 | ||
5128 | zfwBufSetSize(dev, buf, 0); | |
5129 | ||
5130 | //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len); | |
5131 | ||
5132 | zfTxGenMmHeader(dev, ZM_WLAN_FRAME_TYPE_PSPOLL, wd->sta.bssid, header, 0, buf, 0, 0); | |
5133 | ||
5134 | header[0] = 20; | |
5135 | header[4] |= 0x1000; | |
5136 | header[5] = wd->sta.aid | 0xc000; //Both bit-14 and bit-15 are 1 | |
5137 | hlen = 16 + 8; | |
5138 | ||
5139 | /* Get buffer DMA address */ | |
5140 | //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0) | |
5141 | //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0) | |
5142 | //{ | |
5143 | // goto zlError; | |
5144 | //} | |
5145 | ||
92363b52 JP |
5146 | err = zfHpSend(dev, header, hlen, NULL, 0, NULL, 0, buf, 0, |
5147 | ZM_INTERNAL_ALLOC_BUF, 0, 0xff); | |
5148 | if (err != ZM_SUCCESS) | |
4bd43f50 LR |
5149 | { |
5150 | goto zlError; | |
5151 | } | |
5152 | ||
5153 | return; | |
5154 | ||
5155 | zlError: | |
5156 | ||
5157 | zfwBufFree(dev, buf, 0); | |
5158 | return; | |
5159 | ||
5160 | } | |
5161 | ||
5162 | void zfSendBA(zdev_t* dev, u16_t start_seq, u8_t *bitmap) | |
5163 | { | |
5164 | zbuf_t* buf; | |
5165 | //u16_t addrTblSize; | |
5166 | //struct zsAddrTbl addrTbl; | |
5167 | u16_t err; | |
5168 | u16_t hlen; | |
5169 | u16_t header[(8+24+1)/2]; | |
5170 | u16_t i, offset = 0; | |
5171 | ||
5172 | zmw_get_wlan_dev(dev); | |
5173 | ||
92363b52 JP |
5174 | buf = zfwBufAllocate(dev, 1024); |
5175 | if (buf == NULL) | |
4bd43f50 LR |
5176 | { |
5177 | zm_msg0_mm(ZM_LV_0, "Alloc mm buf Fail!"); | |
5178 | return; | |
5179 | } | |
5180 | ||
5181 | zfwBufSetSize(dev, buf, 12); // 28 = FC 2 + DU 2 + RA 6 + TA 6 + BAC 2 + SEQ 2 + BitMap 8 | |
5182 | // 12 = BAC 2 + SEQ 2 + BitMap 8 | |
5183 | ||
5184 | //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len); | |
5185 | ||
5186 | zfTxGenMmHeader(dev, ZM_WLAN_FRAME_TYPE_BA, wd->sta.bssid, header, 0, buf, 0, 0); | |
5187 | ||
5188 | header[0] = 32; /* MAC header 16 + BA control 2 + BA info 10 + FCS 4*/ | |
5189 | header[1] = 0x4; /* No ACK */ | |
5190 | ||
5191 | /* send by OFDM 6M */ | |
5192 | header[2] = (u16_t)(zcRateToPhyCtrl[4] & 0xffff); | |
5193 | header[3] = (u16_t)(zcRateToPhyCtrl[4]>>16) & 0xffff; | |
5194 | ||
5195 | hlen = 16 + 8; /* MAC header 16 + control 8*/ | |
5196 | offset = 0; | |
5197 | zmw_tx_buf_writeh(dev, buf, offset, 0x05); /*compressed bitmap on*/ | |
5198 | offset+=2; | |
5199 | zmw_tx_buf_writeh(dev, buf, offset, start_seq); | |
5200 | offset+=2; | |
5201 | ||
5202 | for (i=0; i<8; i++) { | |
5203 | zmw_tx_buf_writeb(dev, buf, offset, bitmap[i]); | |
5204 | offset++; | |
5205 | } | |
5206 | ||
92363b52 JP |
5207 | err = zfHpSend(dev, header, hlen, NULL, 0, NULL, 0, buf, 0, |
5208 | ZM_INTERNAL_ALLOC_BUF, 0, 0xff); | |
5209 | if (err != ZM_SUCCESS) | |
4bd43f50 LR |
5210 | { |
5211 | goto zlError; | |
5212 | } | |
5213 | ||
5214 | return; | |
5215 | ||
5216 | zlError: | |
5217 | ||
5218 | zfwBufFree(dev, buf, 0); | |
5219 | return; | |
5220 | ||
5221 | } | |
5222 | ||
5223 | void zfStaGetTxRate(zdev_t* dev, u16_t* macAddr, u32_t* phyCtrl, | |
5224 | u16_t* rcProbingFlag) | |
5225 | { | |
5226 | u8_t addr[6], i; | |
5227 | u8_t rate; | |
5228 | zmw_get_wlan_dev(dev); | |
5229 | zmw_declare_for_critical_section(); | |
5230 | ||
5231 | ZM_MAC_WORD_TO_BYTE(macAddr, addr); | |
5232 | *phyCtrl = 0; | |
5233 | ||
5234 | if ( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) | |
5235 | { | |
5236 | zmw_enter_critical_section(dev); | |
5237 | rate = (u8_t)zfRateCtrlGetTxRate(dev, &wd->sta.oppositeInfo[0].rcCell, rcProbingFlag); | |
5238 | //#ifdef ZM_FB50 | |
5239 | //rate = 27; | |
5240 | //#endif | |
5241 | *phyCtrl = zcRateToPhyCtrl[rate]; | |
5242 | zmw_leave_critical_section(dev); | |
5243 | } | |
5244 | else | |
5245 | { | |
5246 | zmw_enter_critical_section(dev); | |
5247 | for(i=0; i<wd->sta.oppositeCount; i++) | |
5248 | { | |
5249 | if ( addr[0] && 0x01 == 1 ) // The default beacon transmitted rate is CCK and 1 Mbps , but the a mode should use | |
5250 | // OFDM modulation and 6Mbps to transmit beacon. | |
5251 | { | |
5252 | //rate = (u8_t)zfRateCtrlGetTxRate(dev, &wd->sta.oppositeInfo[i].rcCell, rcProbingFlag); | |
5253 | rate = wd->sta.oppositeInfo[i].rcCell.operationRateSet[0]; | |
5254 | *phyCtrl = zcRateToPhyCtrl[rate]; | |
5255 | break; | |
5256 | } | |
5257 | else if ( zfMemoryIsEqual(addr, wd->sta.oppositeInfo[i].macAddr, 6) ) | |
5258 | { | |
5259 | rate = (u8_t)zfRateCtrlGetTxRate(dev, &wd->sta.oppositeInfo[i].rcCell, rcProbingFlag); | |
5260 | *phyCtrl = zcRateToPhyCtrl[rate]; | |
5261 | break; | |
5262 | } | |
5263 | } | |
5264 | zmw_leave_critical_section(dev); | |
5265 | } | |
5266 | ||
5267 | return; | |
5268 | } | |
5269 | ||
5270 | struct zsMicVar* zfStaGetRxMicKey(zdev_t* dev, zbuf_t* buf) | |
5271 | { | |
5272 | u8_t keyIndex; | |
5273 | u8_t da0; | |
5274 | ||
5275 | zmw_get_wlan_dev(dev); | |
5276 | ||
5277 | /* if need not check MIC, return NULL */ | |
5278 | if ( ((wd->sta.encryMode != ZM_TKIP)&&(wd->sta.encryMode != ZM_AES))|| | |
5279 | (wd->sta.wpaState < ZM_STA_WPA_STATE_PK_OK) ) | |
5280 | { | |
5281 | return NULL; | |
5282 | } | |
5283 | ||
5284 | da0 = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_A1_OFFSET); | |
5285 | ||
5286 | if ((zmw_rx_buf_readb(dev, buf, 0) & 0x80) == 0x80) | |
5287 | keyIndex = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_IV_OFFSET+5); /* Qos Packet*/ | |
5288 | else | |
5289 | keyIndex = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_IV_OFFSET+3); /* normal Packet*/ | |
5290 | keyIndex = (keyIndex & 0xc0) >> 6; | |
5291 | ||
5292 | return (&wd->sta.rxMicKey[keyIndex]); | |
5293 | } | |
5294 | ||
5295 | struct zsMicVar* zfStaGetTxMicKey(zdev_t* dev, zbuf_t* buf) | |
5296 | { | |
5297 | zmw_get_wlan_dev(dev); | |
5298 | ||
5299 | /* if need not check MIC, return NULL */ | |
5300 | //if ( ((wd->sta.encryMode != ZM_TKIP)&&(wd->sta.encryMode != ZM_AES))|| | |
5301 | // (wd->sta.wpaState < ZM_STA_WPA_STATE_PK_OK) ) | |
5302 | if ( (wd->sta.encryMode != ZM_TKIP) || (wd->sta.wpaState < ZM_STA_WPA_STATE_PK_OK) ) | |
5303 | { | |
5304 | return NULL; | |
5305 | } | |
5306 | ||
5307 | return (&wd->sta.txMicKey); | |
5308 | } | |
5309 | ||
5310 | u16_t zfStaRxValidateFrame(zdev_t* dev, zbuf_t* buf) | |
5311 | { | |
5312 | u8_t frameType, frameCtrl; | |
5313 | u8_t da0; | |
5314 | //u16_t sa[3]; | |
5315 | u16_t ret; | |
4bd43f50 LR |
5316 | //u8_t sa0; |
5317 | ||
5318 | zmw_get_wlan_dev(dev); | |
5319 | ||
5320 | frameType = zmw_rx_buf_readb(dev, buf, 0); | |
5321 | da0 = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_A1_OFFSET); | |
5322 | //sa0 = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_A2_OFFSET); | |
5323 | ||
5324 | if ( (!zfStaIsConnected(dev))&&((frameType & 0xf) == ZM_WLAN_DATA_FRAME) ) | |
5325 | { | |
5326 | return ZM_ERR_DATA_BEFORE_CONNECTED; | |
5327 | } | |
5328 | ||
5329 | ||
5330 | if ( (zfStaIsConnected(dev))&&((frameType & 0xf) == ZM_WLAN_DATA_FRAME) ) | |
5331 | { | |
5332 | /* check BSSID */ | |
5333 | if ( wd->wlanMode == ZM_MODE_INFRASTRUCTURE ) | |
5334 | { | |
5335 | /* Big Endian and Little Endian Compatibility */ | |
5336 | u16_t mac[3]; | |
5337 | mac[0] = zmw_cpu_to_le16(wd->sta.bssid[0]); | |
5338 | mac[1] = zmw_cpu_to_le16(wd->sta.bssid[1]); | |
5339 | mac[2] = zmw_cpu_to_le16(wd->sta.bssid[2]); | |
5340 | if ( !zfRxBufferEqualToStr(dev, buf, (u8_t *)mac, | |
5341 | ZM_WLAN_HEADER_A2_OFFSET, 6) ) | |
5342 | { | |
5343 | /*We will get lots of garbage data, especially in AES mode.*/ | |
5344 | /*To avoid sending too many deauthentication frames in STA mode, mark it.*/ | |
5345 | #if 0 | |
5346 | /* If unicast frame, send deauth to the transmitter */ | |
5347 | if (( da0 & 0x01 ) == 0) | |
5348 | { | |
5349 | for (i=0; i<3; i++) | |
5350 | { | |
5351 | sa[i] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET+(i*2)); | |
5352 | } | |
5353 | /* If mutilcast address, don't send deauthentication*/ | |
5354 | if (( sa0 & 0x01 ) == 0) | |
5355 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_DEAUTH, sa, 7, 0, 0); | |
5356 | } | |
5357 | #endif | |
5358 | return ZM_ERR_DATA_BSSID_NOT_MATCHED; | |
5359 | } | |
5360 | } | |
5361 | else if ( wd->wlanMode == ZM_MODE_IBSS ) | |
5362 | { | |
5363 | /* Big Endian and Little Endian Compatibility */ | |
5364 | u16_t mac[3]; | |
5365 | mac[0] = zmw_cpu_to_le16(wd->sta.bssid[0]); | |
5366 | mac[1] = zmw_cpu_to_le16(wd->sta.bssid[1]); | |
5367 | mac[2] = zmw_cpu_to_le16(wd->sta.bssid[2]); | |
5368 | if ( !zfRxBufferEqualToStr(dev, buf, (u8_t *)mac, | |
5369 | ZM_WLAN_HEADER_A3_OFFSET, 6) ) | |
5370 | { | |
5371 | return ZM_ERR_DATA_BSSID_NOT_MATCHED; | |
5372 | } | |
5373 | } | |
5374 | ||
5375 | frameCtrl = zmw_rx_buf_readb(dev, buf, 1); | |
5376 | ||
5377 | /* check security bit */ | |
5378 | if ( wd->sta.dropUnencryptedPkts && | |
5379 | (wd->sta.wepStatus != ZM_ENCRYPTION_WEP_DISABLED )&& | |
5380 | ( !(frameCtrl & ZM_BIT_6) ) ) | |
5381 | { /* security on, but got data without encryption */ | |
5382 | ||
5383 | #if 1 | |
5384 | ret = ZM_ERR_DATA_NOT_ENCRYPTED; | |
5385 | if ( wd->sta.pStaRxSecurityCheckCb != NULL ) | |
5386 | { | |
5387 | ret = wd->sta.pStaRxSecurityCheckCb(dev, buf); | |
5388 | } | |
5389 | else | |
5390 | { | |
5391 | ret = ZM_ERR_DATA_NOT_ENCRYPTED; | |
5392 | } | |
5393 | if (ret == ZM_ERR_DATA_NOT_ENCRYPTED) | |
5394 | { | |
5395 | wd->commTally.swRxDropUnencryptedCount++; | |
5396 | } | |
5397 | return ret; | |
5398 | #else | |
5399 | if ( (wd->sta.wepStatus != ZM_ENCRYPTION_TKIP)&& | |
5400 | (wd->sta.wepStatus != ZM_ENCRYPTION_AES) ) | |
5401 | { | |
5402 | return ZM_ERR_DATA_NOT_ENCRYPTED; | |
5403 | } | |
5404 | #endif | |
5405 | } | |
5406 | } | |
5407 | ||
5408 | return ZM_SUCCESS; | |
5409 | } | |
5410 | ||
5411 | void zfStaMicFailureHandling(zdev_t* dev, zbuf_t* buf) | |
5412 | { | |
5413 | u8_t da0; | |
5414 | u8_t micNotify = 1; | |
5415 | ||
5416 | zmw_get_wlan_dev(dev); | |
5417 | ||
5418 | zmw_declare_for_critical_section(); | |
5419 | ||
5420 | if ( wd->sta.wpaState < ZM_STA_WPA_STATE_PK_OK ) | |
5421 | { | |
5422 | return; | |
5423 | } | |
5424 | ||
5425 | zmw_enter_critical_section(dev); | |
5426 | ||
5427 | wd->sta.cmMicFailureCount++; | |
5428 | ||
5429 | if ( wd->sta.cmMicFailureCount == 1 ) | |
5430 | { | |
5431 | zm_debug_msg0("get the first MIC failure"); | |
5432 | //zfTimerSchedule(dev, ZM_EVENT_CM_TIMER, ZM_TICK_CM_TIMEOUT); | |
5433 | ||
5434 | /* Timer Resolution on WinXP is 15/16 ms */ | |
5435 | /* Decrease Time offset for <XP> Counter Measure */ | |
5436 | zfTimerSchedule(dev, ZM_EVENT_CM_TIMER, ZM_TICK_CM_TIMEOUT - ZM_TICK_CM_TIMEOUT_OFFSET); | |
5437 | } | |
5438 | else if ( wd->sta.cmMicFailureCount == 2 ) | |
5439 | { | |
5440 | zm_debug_msg0("get the second MIC failure"); | |
5441 | /* reserve 2 second for OS to send MIC failure report to AP */ | |
5442 | wd->sta.cmDisallowSsidLength = wd->sta.ssidLen; | |
5443 | zfMemoryCopy(wd->sta.cmDisallowSsid, wd->sta.ssid, wd->sta.ssidLen); | |
5444 | //wd->sta.cmMicFailureCount = 0; | |
5445 | zfTimerCancel(dev, ZM_EVENT_CM_TIMER); | |
5446 | //zfTimerSchedule(dev, ZM_EVENT_CM_DISCONNECT, ZM_TICK_CM_DISCONNECT); | |
5447 | ||
5448 | /* Timer Resolution on WinXP is 15/16 ms */ | |
5449 | /* Decrease Time offset for <XP> Counter Measure */ | |
5450 | zfTimerSchedule(dev, ZM_EVENT_CM_DISCONNECT, ZM_TICK_CM_DISCONNECT - ZM_TICK_CM_DISCONNECT_OFFSET); | |
5451 | } | |
5452 | else | |
5453 | { | |
5454 | micNotify = 0; | |
5455 | } | |
5456 | ||
5457 | zmw_leave_critical_section(dev); | |
5458 | ||
5459 | if (micNotify == 1) | |
5460 | { | |
5461 | da0 = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_A1_OFFSET); | |
5462 | if ( da0 & 0x01 ) | |
5463 | { | |
5464 | if (wd->zfcbMicFailureNotify != NULL) | |
5465 | { | |
5466 | wd->zfcbMicFailureNotify(dev, wd->sta.bssid, ZM_MIC_GROUP_ERROR); | |
5467 | } | |
5468 | } | |
5469 | else | |
5470 | { | |
5471 | if (wd->zfcbMicFailureNotify != NULL) | |
5472 | { | |
5473 | wd->zfcbMicFailureNotify(dev, wd->sta.bssid, ZM_MIC_PAIRWISE_ERROR); | |
5474 | } | |
5475 | } | |
5476 | } | |
5477 | } | |
5478 | ||
5479 | ||
5480 | u8_t zfStaBlockWlanScan(zdev_t* dev) | |
5481 | { | |
5482 | u8_t ret=FALSE; | |
5483 | ||
5484 | zmw_get_wlan_dev(dev); | |
5485 | ||
5486 | if ( wd->sta.bChannelScan ) | |
5487 | { | |
5488 | return TRUE; | |
5489 | } | |
5490 | ||
5491 | return ret; | |
5492 | } | |
5493 | ||
5494 | void zfStaResetStatus(zdev_t* dev, u8_t bInit) | |
5495 | { | |
5496 | u8_t i; | |
5497 | ||
5498 | zmw_get_wlan_dev(dev); | |
5499 | ||
5500 | zfHpDisableBeacon(dev); | |
5501 | ||
5502 | wd->dtim = 1; | |
5503 | wd->sta.capability[0] = 0x01; | |
5504 | wd->sta.capability[1] = 0x00; | |
5505 | /* 802.11h */ | |
5506 | if (wd->sta.DFSEnable || wd->sta.TPCEnable) | |
5507 | wd->sta.capability[1] |= ZM_BIT_0; | |
5508 | ||
5509 | /* release queued packets */ | |
5510 | for(i=0; i<wd->sta.ibssPSDataCount; i++) | |
5511 | { | |
5512 | zfwBufFree(dev, wd->sta.ibssPSDataQueue[i], 0); | |
5513 | } | |
5514 | ||
5515 | for(i=0; i<wd->sta.staPSDataCount; i++) | |
5516 | { | |
5517 | zfwBufFree(dev, wd->sta.staPSDataQueue[i], 0); | |
5518 | } | |
5519 | ||
5520 | wd->sta.ibssPSDataCount = 0; | |
5521 | wd->sta.staPSDataCount = 0; | |
5522 | zfZeroMemory((u8_t*) &wd->sta.staPSList, sizeof(struct zsStaPSList)); | |
5523 | ||
5524 | wd->sta.wmeConnected = 0; | |
5525 | wd->sta.psMgr.tempWakeUp = 0; | |
5526 | wd->sta.qosInfo = 0; | |
5527 | zfQueueFlush(dev, wd->sta.uapsdQ); | |
5528 | ||
5529 | return; | |
5530 | ||
5531 | } | |
5532 | ||
5533 | void zfStaIbssMonitoring(zdev_t* dev, u8_t reset) | |
5534 | { | |
5535 | u16_t i; | |
5536 | u16_t oppositeCount; | |
5537 | struct zsPartnerNotifyEvent event; | |
5538 | ||
5539 | zmw_get_wlan_dev(dev); | |
5540 | ||
5541 | zmw_declare_for_critical_section(); | |
5542 | ||
5543 | //zm_debug_msg1("zfStaIbssMonitoring %d", wd->sta.oppositeCount); | |
5544 | ||
5545 | zmw_enter_critical_section(dev); | |
5546 | ||
5547 | if ( wd->sta.oppositeCount == 0 ) | |
5548 | { | |
5549 | goto done; | |
5550 | } | |
5551 | ||
5552 | if ( wd->sta.bChannelScan ) | |
5553 | { | |
5554 | goto done; | |
5555 | } | |
5556 | ||
5557 | oppositeCount = wd->sta.oppositeCount; | |
5558 | ||
5559 | for(i=0; i < ZM_MAX_OPPOSITE_COUNT; i++) | |
5560 | { | |
5561 | if ( oppositeCount == 0 ) | |
5562 | { | |
5563 | break; | |
5564 | } | |
5565 | ||
5566 | if ( reset ) | |
5567 | { | |
5568 | wd->sta.oppositeInfo[i].valid = 0; | |
5569 | } | |
5570 | ||
5571 | if ( wd->sta.oppositeInfo[i].valid == 0 ) | |
5572 | { | |
5573 | continue; | |
5574 | } | |
5575 | ||
5576 | oppositeCount--; | |
5577 | ||
5578 | if ( wd->sta.oppositeInfo[i].aliveCounter ) | |
5579 | { | |
5580 | zm_debug_msg1("Setting alive to ", wd->sta.oppositeInfo[i].aliveCounter); | |
5581 | ||
5582 | zmw_leave_critical_section(dev); | |
5583 | ||
5584 | if ( wd->sta.oppositeInfo[i].aliveCounter != ZM_IBSS_PEER_ALIVE_COUNTER ) | |
5585 | { | |
5586 | zfSendMmFrame(dev, ZM_WLAN_FRAME_TYPE_PROBEREQ, | |
5587 | (u16_t*)wd->sta.oppositeInfo[i].macAddr, 1, 0, 0); | |
5588 | } | |
5589 | ||
5590 | zmw_enter_critical_section(dev); | |
5591 | wd->sta.oppositeInfo[i].aliveCounter--; | |
5592 | } | |
5593 | else | |
5594 | { | |
5595 | zm_debug_msg0("zfStaIbssMonitoring remove the peer station"); | |
5596 | zfMemoryCopy(event.bssid, (u8_t *)(wd->sta.bssid), 6); | |
5597 | zfMemoryCopy(event.peerMacAddr, wd->sta.oppositeInfo[i].macAddr, 6); | |
5598 | ||
5599 | wd->sta.oppositeInfo[i].valid = 0; | |
5600 | wd->sta.oppositeCount--; | |
5601 | if (wd->zfcbIbssPartnerNotify != NULL) | |
5602 | { | |
5603 | zmw_leave_critical_section(dev); | |
5604 | wd->zfcbIbssPartnerNotify(dev, 0, &event); | |
5605 | zmw_enter_critical_section(dev); | |
5606 | } | |
5607 | } | |
5608 | } | |
5609 | ||
5610 | done: | |
5611 | if ( reset == 0 ) | |
5612 | { | |
5613 | zfTimerSchedule(dev, ZM_EVENT_IBSS_MONITOR, ZM_TICK_IBSS_MONITOR); | |
5614 | } | |
5615 | ||
5616 | zmw_leave_critical_section(dev); | |
5617 | } | |
5618 | ||
5619 | void zfInitPartnerNotifyEvent(zdev_t* dev, zbuf_t* buf, struct zsPartnerNotifyEvent *event) | |
5620 | { | |
5621 | u16_t *peerMacAddr; | |
5622 | ||
5623 | zmw_get_wlan_dev(dev); | |
5624 | ||
5625 | peerMacAddr = (u16_t *)event->peerMacAddr; | |
5626 | ||
5627 | zfMemoryCopy(event->bssid, (u8_t *)(wd->sta.bssid), 6); | |
5628 | peerMacAddr[0] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET); | |
5629 | peerMacAddr[1] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET + 2); | |
5630 | peerMacAddr[2] = zmw_rx_buf_readh(dev, buf, ZM_WLAN_HEADER_A2_OFFSET + 4); | |
5631 | } | |
5632 | ||
5633 | void zfStaInitOppositeInfo(zdev_t* dev) | |
5634 | { | |
5635 | int i; | |
5636 | ||
5637 | zmw_get_wlan_dev(dev); | |
5638 | ||
5639 | for(i=0; i<ZM_MAX_OPPOSITE_COUNT; i++) | |
5640 | { | |
5641 | wd->sta.oppositeInfo[i].valid = 0; | |
5642 | wd->sta.oppositeInfo[i].aliveCounter = ZM_IBSS_PEER_ALIVE_COUNTER; | |
5643 | } | |
5644 | } | |
5645 | #ifdef ZM_ENABLE_CENC | |
5646 | u16_t zfStaAddIeCenc(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
5647 | { | |
5648 | zmw_get_wlan_dev(dev); | |
5649 | ||
5650 | if (wd->sta.cencIe[1] != 0) | |
5651 | { | |
5652 | zfCopyToIntTxBuffer(dev, buf, wd->sta.cencIe, offset, wd->sta.cencIe[1]+2); | |
5653 | offset += (wd->sta.cencIe[1]+2); | |
5654 | } | |
5655 | return offset; | |
5656 | } | |
5657 | #endif //ZM_ENABLE_CENC | |
5658 | u16_t zfStaProcessAction(zdev_t* dev, zbuf_t* buf) | |
5659 | { | |
5660 | u8_t category, actionDetails; | |
5661 | zmw_get_wlan_dev(dev); | |
5662 | ||
5663 | category = zmw_rx_buf_readb(dev, buf, 24); | |
5664 | actionDetails = zmw_rx_buf_readb(dev, buf, 25); | |
5665 | switch (category) | |
5666 | { | |
5667 | case 0: //Spectrum Management | |
5668 | switch(actionDetails) | |
5669 | { | |
5670 | case 0: //Measurement Request | |
5671 | break; | |
5672 | case 1: //Measurement Report | |
5673 | //ProcessActionSpectrumFrame_MeasurementReport(Adapter,pActionBody+3); | |
5674 | break; | |
5675 | case 2: //TPC request | |
5676 | //if (wd->sta.TPCEnable) | |
5677 | // zfStaUpdateDot11HTPC(dev, buf); | |
5678 | break; | |
5679 | case 3: //TPC report | |
5680 | //if (wd->sta.TPCEnable) | |
5681 | // zfStaUpdateDot11HTPC(dev, buf); | |
5682 | break; | |
5683 | case 4: //Channel Switch Announcement | |
5684 | if (wd->sta.DFSEnable) | |
5685 | zfStaUpdateDot11HDFS(dev, buf); | |
5686 | break; | |
5687 | default: | |
5688 | zm_debug_msg1("Action Frame contain not support action field ", actionDetails); | |
5689 | break; | |
5690 | } | |
5691 | break; | |
5692 | case ZM_WLAN_BLOCK_ACK_ACTION_FRAME: | |
5693 | zfAggBlockAckActionFrame(dev, buf); | |
5694 | break; | |
5695 | case 17: //Qos Management | |
5696 | break; | |
5697 | } | |
5698 | ||
5699 | return 0; | |
5700 | } | |
5701 | ||
5702 | /* Determine the time not send beacon , if more than some value , | |
5703 | re-write the beacon start address */ | |
5704 | void zfReWriteBeaconStartAddress(zdev_t* dev) | |
5705 | { | |
5706 | zmw_get_wlan_dev(dev); | |
5707 | ||
5708 | zmw_declare_for_critical_section(); | |
5709 | ||
5710 | zmw_enter_critical_section(dev); | |
5711 | wd->tickIbssSendBeacon++; // Increase 1 per 10ms . | |
5712 | zmw_leave_critical_section(dev); | |
5713 | ||
5714 | if ( wd->tickIbssSendBeacon == 40 ) | |
5715 | { | |
5716 | // DbgPrint("20070727"); | |
5717 | zfHpEnableBeacon(dev, ZM_MODE_IBSS, wd->beaconInterval, wd->dtim, (u8_t)wd->sta.atimWindow); | |
5718 | zmw_enter_critical_section(dev); | |
5719 | wd->tickIbssSendBeacon = 0; | |
5720 | zmw_leave_critical_section(dev); | |
5721 | } | |
5722 | } | |
5723 | ||
5724 | struct zsTkipSeed* zfStaGetRxSeed(zdev_t* dev, zbuf_t* buf) | |
5725 | { | |
5726 | u8_t keyIndex; | |
5727 | u8_t da0; | |
5728 | ||
5729 | zmw_get_wlan_dev(dev); | |
5730 | ||
5731 | /* if need not check MIC, return NULL */ | |
5732 | if ( ((wd->sta.encryMode != ZM_TKIP)&&(wd->sta.encryMode != ZM_AES))|| | |
5733 | (wd->sta.wpaState < ZM_STA_WPA_STATE_PK_OK) ) | |
5734 | { | |
5735 | return NULL; | |
5736 | } | |
5737 | ||
5738 | da0 = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_A1_OFFSET); | |
5739 | ||
5740 | if ((zmw_rx_buf_readb(dev, buf, 0) & 0x80) == 0x80) | |
5741 | keyIndex = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_IV_OFFSET+5); /* Qos Packet*/ | |
5742 | else | |
5743 | keyIndex = zmw_rx_buf_readb(dev, buf, ZM_WLAN_HEADER_IV_OFFSET+3); /* normal Packet*/ | |
5744 | keyIndex = (keyIndex & 0xc0) >> 6; | |
5745 | ||
5746 | return (&wd->sta.rxSeed[keyIndex]); | |
5747 | } | |
5748 | ||
5749 | void zfStaEnableSWEncryption(zdev_t *dev, u8_t value) | |
5750 | { | |
5751 | zmw_get_wlan_dev(dev); | |
5752 | ||
5753 | wd->sta.SWEncryptEnable = value; | |
5754 | zfHpSWDecrypt(dev, 1); | |
5755 | zfHpSWEncrypt(dev, 1); | |
5756 | } | |
5757 | ||
5758 | void zfStaDisableSWEncryption(zdev_t *dev) | |
5759 | { | |
5760 | zmw_get_wlan_dev(dev); | |
5761 | ||
5762 | wd->sta.SWEncryptEnable = 0; | |
5763 | zfHpSWDecrypt(dev, 0); | |
5764 | zfHpSWEncrypt(dev, 0); | |
5765 | } | |
5766 | ||
5767 | u16_t zfComputeBssInfoWeightValue(zdev_t *dev, u8_t isBMode, u8_t isHT, u8_t isHT40, u8_t signalStrength) | |
5768 | { | |
5769 | u8_t weightOfB = 0; | |
5770 | u8_t weightOfAGBelowThr = 0; | |
5771 | u8_t weightOfAGUpThr = 15; | |
5772 | u8_t weightOfN20BelowThr = 15; | |
5773 | u8_t weightOfN20UpThr = 30; | |
5774 | u8_t weightOfN40BelowThr = 16; | |
5775 | u8_t weightOfN40UpThr = 32; | |
5776 | ||
4bd43f50 LR |
5777 | if( isBMode == 0 ) |
5778 | return (signalStrength + weightOfB); // pure b mode , do not add the weight value for this AP ! | |
5779 | else | |
5780 | { | |
5781 | if( isHT == 0 && isHT40 == 0 ) | |
5782 | { // a , g , b/g mode ! add the weight value 15 for this AP if it's signal strength is more than some value ! | |
5783 | if( signalStrength < 18 ) // -77 dBm | |
5784 | return signalStrength + weightOfAGBelowThr; | |
5785 | else | |
5786 | return (signalStrength + weightOfAGUpThr); | |
5787 | } | |
5788 | else if( isHT == 1 && isHT40 == 0 ) | |
5789 | { // 80211n mode use 20MHz | |
5790 | if( signalStrength < 23 ) // -72 dBm | |
5791 | return (signalStrength + weightOfN20BelowThr); | |
5792 | else | |
5793 | return (signalStrength + weightOfN20UpThr); | |
5794 | } | |
5795 | else // isHT == 1 && isHT40 == 1 | |
5796 | { // 80211n mode use 40MHz | |
5797 | if( signalStrength < 16 ) // -79 dBm | |
5798 | return (signalStrength + weightOfN40BelowThr); | |
5799 | else | |
5800 | return (signalStrength + weightOfN40UpThr); | |
5801 | } | |
5802 | } | |
5803 | } | |
5804 | ||
5805 | u16_t zfStaAddIbssAdditionalIE(zdev_t* dev, zbuf_t* buf, u16_t offset) | |
5806 | { | |
5807 | u16_t i; | |
5808 | ||
5809 | zmw_get_wlan_dev(dev); | |
5810 | ||
5811 | for (i=0; i<wd->sta.ibssAdditionalIESize; i++) | |
5812 | { | |
5813 | zmw_tx_buf_writeb(dev, buf, offset++, wd->sta.ibssAdditionalIE[i]); | |
5814 | } | |
5815 | ||
5816 | return offset; | |
5817 | } |