2 * Copyright (c) 2007-2008 Atheros Communications Inc.
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.
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.
19 #include "../hal/hpreg.h"
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 };
27 const u16_t zcCwTlb
[16] = { 0, 1, 3, 7, 15, 31, 63, 127,
28 255, 511, 1023, 2047, 4095, 4095, 4095, 4095};
30 void zfStaStartConnectCb(zdev_t
* dev
);
32 /************************************************************************/
34 /* FUNCTION DESCRIPTION zfStaPutApIntoBlockingList */
35 /* Put AP into blocking AP list. */
38 /* dev : device pointer */
39 /* bssid : AP's BSSID */
40 /* weight : weight of AP */
46 /* Stephen Chen Atheros Communications, INC. 2006.12 */
48 /************************************************************************/
49 void zfStaPutApIntoBlockingList(zdev_t
* dev
, u8_t
* bssid
, u8_t weight
)
52 zmw_get_wlan_dev(dev
);
53 zmw_declare_for_critical_section();
57 zmw_enter_critical_section(dev
);
58 /*Find same bssid entry first*/
59 for (i
=0; i
<ZM_MAX_BLOCKING_AP_LIST_SIZE
; i
++)
63 if(wd
->sta
.blockingApList
[i
].addr
[j
]!= bssid
[j
])
74 /*This bssid doesn't have old record.Find an empty entry*/
75 if (i
== ZM_MAX_BLOCKING_AP_LIST_SIZE
)
77 for (i
=0; i
<ZM_MAX_BLOCKING_AP_LIST_SIZE
; i
++)
79 if (wd
->sta
.blockingApList
[i
].weight
== 0)
86 /* If the list is full, pick one entry for replacement */
87 if (i
== ZM_MAX_BLOCKING_AP_LIST_SIZE
)
89 i
= bssid
[5] & (ZM_MAX_BLOCKING_AP_LIST_SIZE
-1);
92 /* Update AP address and weight */
95 wd
->sta
.blockingApList
[i
].addr
[j
] = bssid
[j
];
98 wd
->sta
.blockingApList
[i
].weight
= weight
;
99 zmw_leave_critical_section(dev
);
106 /************************************************************************/
108 /* FUNCTION DESCRIPTION zfStaIsApInBlockingList */
109 /* Is AP in blocking list. */
112 /* dev : device pointer */
113 /* bssid : AP's BSSID */
116 /* TRUE : AP in blocking list */
117 /* FALSE : AP not in blocking list */
120 /* Stephen Chen Atheros Communications, INC. 2006.12 */
122 /************************************************************************/
123 u16_t
zfStaIsApInBlockingList(zdev_t
* dev
, u8_t
* bssid
)
126 zmw_get_wlan_dev(dev
);
127 //zmw_declare_for_critical_section();
129 //zmw_enter_critical_section(dev);
130 for (i
=0; i
<ZM_MAX_BLOCKING_AP_LIST_SIZE
; i
++)
132 if (wd
->sta
.blockingApList
[i
].weight
!= 0)
136 if (wd
->sta
.blockingApList
[i
].addr
[j
] != bssid
[j
])
143 //zmw_leave_critical_section(dev);
148 //zmw_leave_critical_section(dev);
153 /************************************************************************/
155 /* FUNCTION DESCRIPTION zfStaRefreshBlockList */
156 /* Is AP in blocking list. */
159 /* dev : device pointer */
160 /* flushFlag : flush whole blocking list */
166 /* Stephen Chen Atheros Communications, INC. 2006.12 */
168 /************************************************************************/
169 void zfStaRefreshBlockList(zdev_t
* dev
, u16_t flushFlag
)
172 zmw_get_wlan_dev(dev
);
173 zmw_declare_for_critical_section();
175 zmw_enter_critical_section(dev
);
176 for (i
=0; i
<ZM_MAX_BLOCKING_AP_LIST_SIZE
; i
++)
178 if (wd
->sta
.blockingApList
[i
].weight
!= 0)
182 wd
->sta
.blockingApList
[i
].weight
= 0;
186 wd
->sta
.blockingApList
[i
].weight
--;
190 zmw_leave_critical_section(dev
);
195 /************************************************************************/
197 /* FUNCTION DESCRIPTION zfStaConnectFail */
198 /* Handle Connect failure. */
201 /* dev : device pointer */
203 /* reason : reason of failure */
209 /* Stephen Chen Atheros Communications, INC. 2006.12 */
211 /************************************************************************/
212 void zfStaConnectFail(zdev_t
* dev
, u16_t reason
, u16_t
* bssid
, u8_t weight
)
214 zmw_get_wlan_dev(dev
);
216 /* Change internal state */
217 zfChangeAdapterState(dev
, ZM_STA_STATE_DISCONNECT
);
219 /* Improve WEP/TKIP performance with HT AP, detail information please look bug#32495 */
220 //zfHpSetTTSIFSTime(dev, 0x8);
222 /* Notify wrapper of connection status changes */
223 if (wd
->zfcbConnectNotify
!= NULL
)
225 wd
->zfcbConnectNotify(dev
, reason
, bssid
);
228 /* Put AP into internal blocking list */
229 zfStaPutApIntoBlockingList(dev
, (u8_t
*)bssid
, weight
);
231 /* Issue another SCAN */
232 if ( wd
->sta
.bAutoReconnect
)
234 zm_debug_msg0("Start internal scan...");
235 zfScanMgrScanStop(dev
, ZM_SCAN_MGR_SCAN_INTERNAL
);
236 zfScanMgrScanStart(dev
, ZM_SCAN_MGR_SCAN_INTERNAL
);
240 u8_t
zfiWlanIBSSGetPeerStationsCount(zdev_t
* dev
)
242 zmw_get_wlan_dev(dev
);
244 return wd
->sta
.oppositeCount
;
247 u8_t
zfiWlanIBSSIteratePeerStations(zdev_t
* dev
, u8_t numToIterate
, zfpIBSSIteratePeerStationCb callback
, void *ctx
)
253 zmw_get_wlan_dev(dev
);
255 zmw_declare_for_critical_section();
257 zmw_enter_critical_section(dev
);
259 oppositeCount
= wd
->sta
.oppositeCount
;
260 if ( oppositeCount
> numToIterate
)
262 oppositeCount
= numToIterate
;
265 for(i
=0; i
< ZM_MAX_OPPOSITE_COUNT
; i
++)
267 if ( oppositeCount
== 0 )
272 if ( wd
->sta
.oppositeInfo
[i
].valid
== 0 )
277 callback(dev
, &wd
->sta
.oppositeInfo
[i
], ctx
, index
++);
282 zmw_leave_critical_section(dev
);
288 s8_t
zfStaFindFreeOpposite(zdev_t
* dev
, u16_t
*sa
, int *pFoundIdx
)
293 zmw_get_wlan_dev(dev
);
295 oppositeCount
= wd
->sta
.oppositeCount
;
297 for(i
=0; i
< ZM_MAX_OPPOSITE_COUNT
; i
++)
299 if ( oppositeCount
== 0 )
304 if ( wd
->sta
.oppositeInfo
[i
].valid
== 0 )
310 if ( zfMemoryIsEqual((u8_t
*) sa
, wd
->sta
.oppositeInfo
[i
].macAddr
, 6) )
312 //wd->sta.oppositeInfo[i].aliveCounter++;
313 wd
->sta
.oppositeInfo
[i
].aliveCounter
= ZM_IBSS_PEER_ALIVE_COUNTER
;
315 /* it is already stored */
320 // Check if there's still space for new comer
321 if ( wd
->sta
.oppositeCount
== ZM_MAX_OPPOSITE_COUNT
)
326 // Find an unused slot for new peer station
327 for(i
=0; i
< ZM_MAX_OPPOSITE_COUNT
; i
++)
329 if ( wd
->sta
.oppositeInfo
[i
].valid
== 0 )
339 s8_t
zfStaFindOppositeByMACAddr(zdev_t
* dev
, u16_t
*sa
, u8_t
*pFoundIdx
)
344 zmw_get_wlan_dev(dev
);
346 oppositeCount
= wd
->sta
.oppositeCount
;
348 for(i
=0; i
< ZM_MAX_OPPOSITE_COUNT
; i
++)
350 if ( oppositeCount
== 0 )
355 if ( wd
->sta
.oppositeInfo
[i
].valid
== 0 )
361 if ( zfMemoryIsEqual((u8_t
*) sa
, wd
->sta
.oppositeInfo
[i
].macAddr
, 6) )
363 *pFoundIdx
= (u8_t
)i
;
373 static void zfStaInitCommonOppositeInfo(zdev_t
* dev
, int i
)
375 zmw_get_wlan_dev(dev
);
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
++;
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
390 int zfStaSetOppositeInfoFromBSSInfo(zdev_t
* dev
, struct zsBssInfo
* pBssInfo
)
396 u32_t oneTxStreamCap
;
398 zmw_get_wlan_dev(dev
);
400 zfMemoryCopy((u8_t
*) sa
, pBssInfo
->macaddr
, 6);
402 res
= zfStaFindFreeOpposite(dev
, sa
, &i
);
408 dst
= wd
->sta
.oppositeInfo
[i
].macAddr
;
409 zfMemoryCopy(dst
, (u8_t
*)sa
, 6);
411 oneTxStreamCap
= (zfHpCapability(dev
) & ZM_HP_CAP_11N_ONE_TX_STREAM
);
413 if (pBssInfo
->extSupportedRates
[1] != 0)
415 /* TODO : Handle 11n */
416 if (pBssInfo
->frequency
< 3000)
419 if (pBssInfo
->EnableHT
== 1)
420 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 1, pBssInfo
->SG40
);
422 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 1, pBssInfo
->SG40
);
427 if (pBssInfo
->EnableHT
== 1)
428 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 0, pBssInfo
->SG40
);
430 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 0, pBssInfo
->SG40
);
435 /* TODO : Handle 11n */
436 if (pBssInfo
->frequency
< 3000)
439 if (pBssInfo
->EnableHT
== 1)
440 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 1, pBssInfo
->SG40
);
442 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 0, 1, pBssInfo
->SG40
);
447 if (pBssInfo
->EnableHT
== 1)
448 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 0, pBssInfo
->SG40
);
450 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 0, pBssInfo
->SG40
);
455 zfStaInitCommonOppositeInfo(dev
, i
);
460 int zfStaSetOppositeInfoFromRxBuf(zdev_t
* dev
, zbuf_t
* buf
)
467 u8_t bSupportExtRate
;
468 u32_t rtsctsRate
= 0xffffffff; /* CTS:OFDM 6M, RTS:OFDM 6M */
469 u32_t oneTxStreamCap
;
471 zmw_get_wlan_dev(dev
);
472 zmw_declare_for_critical_section();
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);
478 zmw_enter_critical_section(dev
);
480 res
= zfStaFindFreeOpposite(dev
, sa
, &i
);
486 dst
= wd
->sta
.oppositeInfo
[i
].macAddr
;
487 zfCopyFromRxBuffer(dev
, buf
, dst
, ZM_WLAN_HEADER_A2_OFFSET
, 6);
489 if ( (wd
->sta
.currentFrequency
< 3000) && !(wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) )
496 if ( (bSupportExtRate
== 1)
497 && (wd
->sta
.currentFrequency
< 3000)
498 && (wd
->wlanMode
== ZM_MODE_IBSS
)
499 && (wd
->wfc
.bIbssGMode
== 0) )
504 wd
->sta
.connection_11b
= 0;
505 oneTxStreamCap
= (zfHpCapability(dev
) & ZM_HP_CAP_11N_ONE_TX_STREAM
);
507 if ( ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_EXTENDED_RATE
)) != 0xffff)
508 && (bSupportExtRate
== 1) )
510 /* TODO : Handle 11n */
511 if (wd
->sta
.currentFrequency
< 3000)
514 if (wd
->sta
.EnableHT
== 1)
517 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 1, wd
->sta
.SG40
);
522 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 1, wd
->sta
.SG40
);
524 rtsctsRate
= 0x00001bb; /* CTS:CCK 1M, RTS:OFDM 6M */
529 if (wd
->sta
.EnableHT
== 1)
532 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 0, wd
->sta
.SG40
);
537 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 0, wd
->sta
.SG40
);
539 rtsctsRate
= 0x10b01bb; /* CTS:OFDM 6M, RTS:OFDM 6M */
544 /* TODO : Handle 11n */
545 if (wd
->sta
.currentFrequency
< 3000)
548 if (wd
->sta
.EnableHT
== 1)
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 */
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;
565 if (wd
->sta
.EnableHT
== 1)
568 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, (oneTxStreamCap
!=0)?3:2, 0, wd
->sta
.SG40
);
573 zfRateCtrlInitCell(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, 1, 0, wd
->sta
.SG40
);
575 rtsctsRate
= 0x10b01bb; /* CTS:OFDM 6M, RTS:OFDM 6M */
579 zfStaInitCommonOppositeInfo(dev
, i
);
582 zmw_leave_critical_section(dev
);
584 if (rtsctsRate
!= 0xffffffff)
586 zfHpSetRTSCTSRate(dev
, rtsctsRate
);
591 void zfStaProtErpMonitor(zdev_t
* dev
, zbuf_t
* buf
)
597 zmw_get_wlan_dev(dev
);
599 if ( (wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)&&(zfStaIsConnected(dev
)) )
601 ZM_MAC_WORD_TO_BYTE(wd
->sta
.bssid
, bssid
);
603 if (zfRxBufferEqualToStr(dev
, buf
, bssid
, ZM_WLAN_HEADER_A2_OFFSET
, 6))
605 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_ERP
);
606 if (offset
!= 0xffff)
608 erp
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
610 if ( erp
& ZM_BIT_1
)
612 //zm_debug_msg0("protection mode on");
613 if (wd
->sta
.bProtectionMode
== FALSE
)
615 wd
->sta
.bProtectionMode
= TRUE
;
616 zfHpSetSlotTime(dev
, 0);
621 //zm_debug_msg0("protection mode off");
622 if (wd
->sta
.bProtectionMode
== TRUE
)
624 wd
->sta
.bProtectionMode
= FALSE
;
625 zfHpSetSlotTime(dev
, 1);
630 //Check the existence of Non-N AP
631 //Follow the check the "pBssInfo->EnableHT"
632 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_HT_CAPABILITY
);
633 if (offset
!= 0xffff)
635 else if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_PREN2_EID_HTCAPABILITY
)) != 0xffff)
638 {wd
->sta
.NonNAPcount
++;}
642 void zfStaUpdateWmeParameter(zdev_t
* dev
, zbuf_t
* buf
)
654 u8_t rxWmeParameterSetCount
;
656 zmw_get_wlan_dev(dev
);
658 /* Update if WME parameter set count is changed */
659 /* If connect to WME AP */
660 if (wd
->sta
.wmeConnected
!= 0)
662 /* Find WME parameter element */
663 offset
= zfFindWifiElement(dev
, buf
, 2, 1);
664 if (offset
!= 0xffff)
666 len
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
669 rxWmeParameterSetCount
=zmw_rx_buf_readb(dev
, buf
, offset
+8);
670 if (rxWmeParameterSetCount
!= wd
->sta
.wmeParameterSetCount
)
672 zm_msg0_mm(ZM_LV_0
, "wmeParameterSetCount changed!");
673 wd
->sta
.wmeParameterSetCount
= rxWmeParameterSetCount
;
674 /* retrieve WME parameter and update TxQ parameters */
678 if (len
>= (8+(i
*4)+4))
680 tmp
=zmw_rx_buf_readb(dev
, buf
, offset
+10+i
*4);
681 ac
= (tmp
>> 5) & 0x3;
682 if ((tmp
& 0x10) == 0)
686 aifs
[ac
] = ((tmp
& 0xf) * 9) + 10;
687 tmp
=zmw_rx_buf_readb(dev
, buf
, offset
+11+i
*4);
689 cwmin
[ac
] = zcCwTlb
[(tmp
& 0xf)];
690 cwmax
[ac
] = zcCwTlb
[(tmp
>> 4)];
691 txop
[ac
]=zmw_rx_buf_readh(dev
, buf
,
696 if ((acm
& 0x4) != 0)
703 if ((acm
& 0x8) != 0)
714 if ((cwmin
[2]+aifs
[2]) > ((cwmin
[0]+aifs
[0])+1))
716 wd
->sta
.ac0PriorityHigherThanAc2
= 1;
720 wd
->sta
.ac0PriorityHigherThanAc2
= 0;
722 zfHpUpdateQosParameter(dev
, cwmin
, cwmax
, aifs
, txop
);
726 } //if (wd->sta.wmeConnected != 0)
728 /* process 802.11h Dynamic Frequency Selection */
729 void zfStaUpdateDot11HDFS(zdev_t
* dev
, zbuf_t
* buf
)
731 //u8_t length, channel, is5G;
734 zmw_get_wlan_dev(dev
);
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 +------+----------+------+-------------------+------------------+--------------------+
747 /* get EID(Channel Switch Announcement) */
748 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_CHANNEL_SWITCH_ANNOUNCE
);
749 if (offset
== 0xffff)
751 //zm_debug_msg0("EID(Channel Switch Announcement) not found");
754 else if ( zmw_rx_buf_readb(dev
, buf
, offset
+1) == 0x3 )
756 zm_debug_msg0("EID(Channel Switch Announcement) found");
758 //length = zmw_rx_buf_readb(dev, buf, offset+1);
759 //zfCopyFromRxBuffer(dev, buf, pBssInfo->supportedRates, offset, length+2);
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 )
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
)
769 /* TODO : zfHpResetTxRx would cause Rx hang */
770 //zfHpResetTxRx(dev);
771 wd
->sta
.DFSDisableTx
= TRUE
;
775 //Adapter->ZD80211HSetting.DisableTxBy80211H=TRUE;
776 //AcquireCtrOfPhyReg(Adapter);
777 //ZD1205_WRITE_REGISTER(Adapter,CR24, 0x0);
778 //ReleaseDoNotSleep(Adapter);
781 if (zmw_rx_buf_readb(dev
, buf
, offset
+4) <= 0x2 )
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.
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
))
799 wd
->sta
.rxBeaconCount
= 1 << 6; // 2 times of check would pass
801 //start tx dma to transmit packet
803 //if (zmw_rx_buf_readb(dev, buf, offset+3) != wd->frequency)
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;
817 /* TODO : process 802.11h Transmission Power Control */
818 void zfStaUpdateDot11HTPC(zdev_t
* dev
, zbuf_t
* buf
)
822 /* IBSS power-saving mode */
823 void zfStaIbssPSCheckState(zdev_t
* dev
, zbuf_t
* buf
)
827 zmw_get_wlan_dev(dev
);
829 if ( !zfStaIsConnected(dev
) )
834 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
840 if ( !zfRxBufferEqualToStr(dev
, buf
, (u8_t
*) wd
->sta
.bssid
,
841 ZM_WLAN_HEADER_A3_OFFSET
, 6) )
846 frameCtrl
= zmw_rx_buf_readb(dev
, buf
, 1);
848 /* check power management bit */
849 if ( frameCtrl
& ZM_BIT_4
)
851 for(i
=1; i
<ZM_MAX_PS_STA
; i
++)
853 if ( !wd
->sta
.staPSList
.entity
[i
].bUsed
)
858 /* check source address */
859 if ( zfRxBufferEqualToStr(dev
, buf
,
860 wd
->sta
.staPSList
.entity
[i
].macAddr
,
861 ZM_WLAN_HEADER_A2_OFFSET
, 6) )
867 for(i
=1; i
<ZM_MAX_PS_STA
; i
++)
869 if ( !wd
->sta
.staPSList
.entity
[i
].bUsed
)
871 wd
->sta
.staPSList
.entity
[i
].bUsed
= TRUE
;
872 wd
->sta
.staPSList
.entity
[i
].bDataQueued
= FALSE
;
877 if ( i
== ZM_MAX_PS_STA
)
879 /* STA list is full */
883 zfCopyFromRxBuffer(dev
, buf
, wd
->sta
.staPSList
.entity
[i
].macAddr
,
884 ZM_WLAN_HEADER_A2_OFFSET
, 6);
886 if ( wd
->sta
.staPSList
.count
== 0 )
888 // enable ATIM window
889 //zfEnableAtimWindow(dev);
892 wd
->sta
.staPSList
.count
++;
894 else if ( wd
->sta
.staPSList
.count
)
896 for(i
=1; i
<ZM_MAX_PS_STA
; i
++)
898 if ( wd
->sta
.staPSList
.entity
[i
].bUsed
)
900 if ( zfRxBufferEqualToStr(dev
, buf
,
901 wd
->sta
.staPSList
.entity
[i
].macAddr
,
902 ZM_WLAN_HEADER_A2_OFFSET
, 6) )
904 wd
->sta
.staPSList
.entity
[i
].bUsed
= FALSE
;
905 wd
->sta
.staPSList
.count
--;
907 if ( wd
->sta
.staPSList
.entity
[i
].bDataQueued
)
909 /* send queued data */
915 if ( wd
->sta
.staPSList
.count
== 0 )
917 /* disable ATIM window */
918 //zfDisableAtimWindow(dev);
924 /* IBSS power-saving mode */
925 u8_t
zfStaIbssPSQueueData(zdev_t
* dev
, zbuf_t
* buf
)
930 zmw_get_wlan_dev(dev
);
932 if ( !zfStaIsConnected(dev
) )
937 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
942 if ( wd
->sta
.staPSList
.count
== 0 && wd
->sta
.powerSaveMode
<= ZM_STA_PS_NONE
)
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);
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);
958 if ( ZM_IS_MULTICAST_OR_BROADCAST(da
) )
960 wd
->sta
.staPSList
.entity
[0].bDataQueued
= TRUE
;
961 wd
->sta
.ibssPSDataQueue
[wd
->sta
.ibssPSDataCount
++] = buf
;
967 for(i
=1; i
<ZM_MAX_PS_STA
; i
++)
969 if ( zfMemoryIsEqual(wd
->sta
.staPSList
.entity
[i
].macAddr
,
972 wd
->sta
.staPSList
.entity
[i
].bDataQueued
= TRUE
;
973 wd
->sta
.ibssPSDataQueue
[wd
->sta
.ibssPSDataCount
++] = buf
;
980 if ( wd
->sta
.powerSaveMode
> ZM_STA_PS_NONE
)
982 wd
->sta
.staPSDataQueue
[wd
->sta
.staPSDataCount
++] = buf
;
991 /* IBSS power-saving mode */
992 void zfStaIbssPSSend(zdev_t
* dev
)
995 u16_t bcastAddr
[3] = {0xffff, 0xffff, 0xffff};
997 zmw_get_wlan_dev(dev
);
999 if ( !zfStaIsConnected(dev
) )
1004 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
1009 for(i
=0; i
<ZM_MAX_PS_STA
; i
++)
1011 if ( wd
->sta
.staPSList
.entity
[i
].bDataQueued
)
1015 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_ATIM
,
1019 else if ( wd
->sta
.staPSList
.entity
[i
].bUsed
)
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
,
1027 wd
->sta
.staPSList
.entity
[i
].bDataQueued
= FALSE
;
1031 for(i
=0; i
<wd
->sta
.ibssPSDataCount
; i
++)
1033 zfTxSendEth(dev
, wd
->sta
.ibssPSDataQueue
[i
], 0,
1034 ZM_EXTERNAL_ALLOC_BUF
, 0);
1037 wd
->sta
.ibssPrevPSDataCount
= wd
->sta
.ibssPSDataCount
;
1038 wd
->sta
.ibssPSDataCount
= 0;
1042 void zfStaReconnect(zdev_t
* dev
)
1044 zmw_get_wlan_dev(dev
);
1045 zmw_declare_for_critical_section();
1047 if ( wd
->wlanMode
!= ZM_MODE_INFRASTRUCTURE
&&
1048 wd
->wlanMode
!= ZM_MODE_IBSS
)
1053 if ( (zfStaIsConnected(dev
))||(zfStaIsConnecting(dev
)) )
1058 if ( wd
->sta
.bChannelScan
)
1063 /* Recover zero SSID length */
1064 if ( (wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
) && (wd
->ws
.ssidLen
== 0))
1066 zm_debug_msg0("zfStaReconnect: NOT Support!! Set SSID to 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
);
1074 // RAY: To ensure no TX pending before re-connecting
1077 zfScanMgrScanAck(dev
);
1080 void zfStaTimer100ms(zdev_t
* dev
)
1082 zmw_get_wlan_dev(dev
);
1084 if ( (wd
->tick
% 10) == 0 )
1087 // zfPowerSavingMgrMain(dev);
1092 void zfStaCheckRxBeacon(zdev_t
* dev
)
1094 zmw_get_wlan_dev(dev
);
1096 if (( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
) && (zfStaIsConnected(dev
)))
1098 if (wd
->beaconInterval
== 0)
1100 wd
->beaconInterval
= 100;
1102 if ( (wd
->tick
% ((wd
->beaconInterval
* 10) / ZM_MS_PER_TICK
)) == 0 )
1104 /* Check rxBeaconCount */
1105 if (wd
->sta
.rxBeaconCount
== 0)
1107 if (wd
->sta
.beaconMissState
== 1)
1109 /*notify AP that we left*/
1110 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_DEAUTH
, wd
->sta
.bssid
, 3, 0, 0);
1112 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_BEACON_MISS
,
1117 wd
->sta
.beaconMissState
= 1;
1119 zfCoreSetFrequencyExV2(dev
, wd
->frequency
, wd
->BandWidth40
,
1120 wd
->ExtOffset
, NULL
, 1);
1125 wd
->sta
.beaconMissState
= 0;
1127 wd
->sta
.rxBeaconCount
= 0;
1134 void zfStaCheckConnectTimeout(zdev_t
* dev
)
1136 zmw_get_wlan_dev(dev
);
1137 zmw_declare_for_critical_section();
1139 if ( wd
->wlanMode
!= ZM_MODE_INFRASTRUCTURE
)
1144 if ( !zfStaIsConnecting(dev
) )
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
) )
1155 if ( (wd
->tick
- wd
->sta
.connectTimer
) > ZM_INTERVAL_CONNECT_TIMEOUT
)
1157 if ( wd
->sta
.connectByReasso
)
1159 wd
->sta
.failCntOfReasso
++;
1160 if ( wd
->sta
.failCntOfReasso
> 2 )
1162 wd
->sta
.connectByReasso
= FALSE
;
1166 wd
->sta
.connectState
= ZM_STA_CONN_STATE_NONE
;
1167 zm_debug_msg1("connect timeout, state = ", wd
->sta
.connectState
);
1168 //zfiWlanDisable(dev);
1173 zmw_leave_critical_section(dev
);
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
++;
1182 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_TIMEOUT
, wd
->sta
.bssid
, 2);
1186 void zfMmStaTimeTick(zdev_t
* dev
)
1188 zmw_get_wlan_dev(dev
);
1191 if (wd
->wlanMode
!= ZM_MODE_AP
&& !wd
->swSniffer
)
1195 zfTimerCheckAndHandle(dev
);
1198 zfStaCheckRxBeacon(dev
);
1199 zfStaTimer100ms(dev
);
1200 zfStaCheckConnectTimeout(dev
);
1201 zfPowerSavingMgrMain(dev
);
1204 #ifdef ZM_ENABLE_AGGREGATION
1208 zfAggScanAndClear(dev
, wd
->tick
);
1212 void zfStaSendBeacon(zdev_t
* dev
)
1217 zmw_get_wlan_dev(dev
);
1219 zmw_declare_for_critical_section();
1221 //zm_debug_msg0("\n");
1223 /* TBD : Maximum size of beacon */
1224 buf
= zfwBufAllocate(dev
, 1024);
1227 zm_debug_msg0("Allocate beacon buffer failed");
1234 zmw_tx_buf_writeh(dev
, buf
, offset
, 0x0080);
1237 zmw_tx_buf_writeh(dev
, buf
, offset
, 0x0000);
1240 zmw_tx_buf_writeh(dev
, buf
, offset
, 0xffff);
1242 zmw_tx_buf_writeh(dev
, buf
, offset
, 0xffff);
1244 zmw_tx_buf_writeh(dev
, buf
, offset
, 0xffff);
1247 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->macAddr
[0]);
1249 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->macAddr
[1]);
1251 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->macAddr
[2]);
1254 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[0]);
1256 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[1]);
1258 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.bssid
[2]);
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
);
1268 /* 24-31 Time Stamp : hardware will fill this field */
1271 /* Beacon Interval */
1272 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->beaconInterval
);
1276 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[0]);
1277 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.capability
[1]);
1280 offset
= zfStaAddIeSsid(dev
, buf
, offset
);
1282 if(wd
->frequency
<= ZM_CH_G_14
) // 2.4 GHz b+g
1286 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1287 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_CCK
);
1289 /* DS parameter set */
1290 offset
= zfMmAddIeDs(dev
, buf
, offset
);
1292 offset
= zfStaAddIeIbss(dev
, buf
, offset
);
1294 if( wd
->wfc
.bIbssGMode
1295 && (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) ) // Only accompany with enabling a mode .
1297 /* ERP Information */
1299 offset
= zfMmAddIeErp(dev
, buf
, offset
);
1302 /* TODO : country information */
1304 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
1306 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, ZM_WLAN_FRAME_TYPE_AUTH
);
1309 if( wd
->wfc
.bIbssGMode
1310 && (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) ) // Only accompany with enabling a mode .
1313 /* Extended Supported Rates */
1314 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1315 ZM_WLAN_EID_EXTENDED_RATE
, ZM_RATE_SET_OFDM
);
1320 /* Support Rate a Mode */
1321 offset
= zfMmAddIeSupportRate(dev
, buf
, offset
,
1322 ZM_WLAN_EID_SUPPORT_RATE
, ZM_RATE_SET_OFDM
);
1324 /* DS parameter set */
1325 offset
= zfMmAddIeDs(dev
, buf
, offset
);
1327 offset
= zfStaAddIeIbss(dev
, buf
, offset
);
1329 /* TODO : country information */
1331 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
1333 offset
= zfwStaAddIeWpaRsn(dev
, buf
, offset
, ZM_WLAN_FRAME_TYPE_AUTH
);
1337 if ( wd
->wlanMode
!= ZM_MODE_IBSS
)
1339 /* TODO : Need to check if it is ok */
1340 /* HT Capabilities Info */
1341 offset
= zfMmAddHTCapability(dev
, buf
, offset
);
1343 /* Extended HT Capabilities Info */
1344 offset
= zfMmAddExtendedHTCapability(dev
, buf
, offset
);
1347 if ( wd
->sta
.ibssAdditionalIESize
)
1348 offset
= zfStaAddIbssAdditionalIE(dev
, buf
, offset
);
1350 /* 1212 : write to beacon fifo */
1351 /* 1221 : write to share memory */
1352 zfHpSendBeacon(dev
, buf
, offset
);
1354 /* Free beacon buffer */
1355 //zfwBufFree(dev, buf, 0);
1358 void zfStaSignalStatistic(zdev_t
* dev
, u8_t SignalStrength
, u8_t SignalQuality
) //CWYang(+)
1360 zmw_get_wlan_dev(dev
);
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;
1368 struct zsBssInfo
* zfStaFindBssInfo(zdev_t
* dev
, zbuf_t
* buf
, struct zsWlanProbeRspFrameHeader
*pProbeRspHeader
)
1373 u8_t isMatched
, length
, channel
;
1374 u16_t offset
, frequency
;
1375 struct zsBssInfo
* pBssInfo
;
1377 zmw_get_wlan_dev(dev
);
1379 pBssInfo
= wd
->sta
.bssList
.head
;
1380 if (pBssInfo
== NULL
)
1385 for( i
=0; i
<wd
->sta
.bssList
.bssCount
; i
++ )
1387 //zm_debug_msg2("check pBssInfo = ", pBssInfo);
1390 for( j
=0; j
<6; j
++ )
1392 if ( pBssInfo
->bssid
[j
] != pProbeRspHeader
->bssid
[j
] )
1401 if (pProbeRspHeader
->ssid
[1] <= 32)
1403 /* compare length and ssid */
1405 if((pProbeRspHeader
->ssid
[1] != 0) && (pBssInfo
->ssid
[1] != 0))
1407 for( k
=1; k
<pProbeRspHeader
->ssid
[1] + 1; k
++ )
1409 if ( pBssInfo
->ssid
[k
] != pProbeRspHeader
->ssid
[k
] )
1428 /* Add check channel to solve the bug #31222 */
1430 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_DS
);
1431 if (offset
!= 0xffff) {
1432 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1434 channel
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
1435 if (zfHpIsAllowedChannel(dev
, zfChNumToFreq(dev
, channel
, 0)) == 0) {
1438 frequency
= zfChNumToFreq(dev
, channel
, 0);;
1444 frequency
= wd
->sta
.currentFrequency
;
1447 if (frequency
!= 0) {
1448 if ( ((frequency
> 3000) && (pBssInfo
->frequency
> 3000))
1449 || ((frequency
< 3000) && (pBssInfo
->frequency
< 3000)) ) {
1456 pBssInfo
= pBssInfo
->next
;
1459 if ( i
== wd
->sta
.bssList
.bssCount
)
1467 u8_t
zfStaInitBssInfo(zdev_t
* dev
, zbuf_t
* buf
,
1468 struct zsWlanProbeRspFrameHeader
*pProbeRspHeader
,
1469 struct zsBssInfo
* pBssInfo
, struct zsAdditionInfo
* AddInfo
, u8_t type
)
1471 u8_t length
, channel
, is5G
;
1474 u16_t eachIElength
= 0;
1475 u16_t accumulateLen
= 0;
1477 zmw_get_wlan_dev(dev
);
1479 if ((type
== 1) && ((pBssInfo
->flag
& ZM_BSS_INFO_VALID_BIT
) != 0))
1485 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SSID
);
1486 if (offset
== 0xffff)
1488 zm_debug_msg0("EID(SSID) not found");
1492 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1496 zfwGetShowZeroLengthSSID(dev
, &Show_Flag
);
1500 if (length
> ZM_MAX_SSID_LENGTH
)
1502 zm_debug_msg0("EID(SSID) is invalid");
1508 if ( length
== 0 || length
> ZM_MAX_SSID_LENGTH
)
1510 zm_debug_msg0("EID(SSID) is invalid");
1516 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->ssid
, offset
, length
+2);
1518 /* get DS parameter */
1519 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_DS
);
1520 if (offset
!= 0xffff)
1522 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1525 zm_msg0_mm(ZM_LV_0
, "Abnormal DS Param Set IE");
1528 channel
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
1530 if (zfHpIsAllowedChannel(dev
, zfChNumToFreq(dev
, channel
, 0)) == 0)
1535 pBssInfo
->frequency
= zfChNumToFreq(dev
, channel
, 0); // auto check
1536 pBssInfo
->channel
= channel
;
1542 /* DS parameter not found */
1543 pBssInfo
->frequency
= wd
->sta
.currentFrequency
;
1544 pBssInfo
->channel
= zfChFreqToNum(wd
->sta
.currentFrequency
, &is5G
);
1547 /* initialize security type */
1548 pBssInfo
->securityType
= ZM_SECURITY_TYPE_NONE
;
1551 for( i
=0; i
<6; i
++ )
1553 pBssInfo
->macaddr
[i
] = pProbeRspHeader
->sa
[i
];
1557 for( i
=0; i
<6; i
++ )
1559 pBssInfo
->bssid
[i
] = pProbeRspHeader
->bssid
[i
];
1563 for( i
=0; i
<8; i
++ )
1565 pBssInfo
->timeStamp
[i
] = pProbeRspHeader
->timeStamp
[i
];
1568 /* get beacon interval */
1569 pBssInfo
->beaconInterval
[0] = pProbeRspHeader
->beaconInterval
[0];
1570 pBssInfo
->beaconInterval
[1] = pProbeRspHeader
->beaconInterval
[1];
1572 /* get capability */
1573 pBssInfo
->capability
[0] = pProbeRspHeader
->capability
[0];
1574 pBssInfo
->capability
[1] = pProbeRspHeader
->capability
[1];
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))
1581 pBssInfo
->frameBodysize
= ZM_MAX_PROBE_FRAME_BODY_SIZE
-1;
1586 eachIElength
= zmw_rx_buf_readb(dev
, buf
, offset
+ accumulateLen
+1) + 2; //Len+(EID+Data)
1588 if ( (eachIElength
>= 2)
1589 && ((accumulateLen
+ eachIElength
) <= pBssInfo
->frameBodysize
) )
1591 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->frameBody
+accumulateLen
, offset
+accumulateLen
, eachIElength
);
1592 accumulateLen
+=(u16_t
)eachIElength
;
1596 zm_msg0_mm(ZM_LV_1
, "probersp frameBodysize abnormal");
1600 while(accumulateLen
< pBssInfo
->frameBodysize
);
1601 pBssInfo
->frameBodysize
= accumulateLen
;
1603 /* get supported rates */
1604 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SUPPORT_RATE
);
1605 if (offset
== 0xffff)
1607 zm_debug_msg0("EID(supported rates) not found");
1611 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1612 if ( length
== 0 || length
> ZM_MAX_SUPP_RATES_IE_SIZE
)
1614 zm_msg0_mm(ZM_LV_0
, "Supported rates IE length abnormal");
1617 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->supportedRates
, offset
, length
+2);
1621 /* get Country information */
1622 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_COUNTRY
);
1623 if (offset
!= 0xffff)
1625 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1626 if (length
> ZM_MAX_COUNTRY_INFO_SIZE
)
1628 length
= ZM_MAX_COUNTRY_INFO_SIZE
;
1630 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->countryInfo
, offset
, length
+2);
1631 /* check 802.11d support data */
1632 if (wd
->sta
.b802_11D
)
1634 zfHpGetRegulationTablefromISO(dev
, (u8_t
*)&pBssInfo
->countryInfo
, 3);
1635 /* only set regulatory one time */
1636 wd
->sta
.b802_11D
= 0;
1640 /* get ERP information */
1641 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_ERP
);
1642 if (offset
!= 0xffff)
1644 pBssInfo
->erp
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
1647 /* get extended supported rates */
1648 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_EXTENDED_RATE
);
1649 if (offset
!= 0xffff)
1651 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1652 if (length
> ZM_MAX_SUPP_RATES_IE_SIZE
)
1654 zm_msg0_mm(ZM_LV_0
, "Extended rates IE length abnormal");
1657 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->extSupportedRates
, offset
, length
+2);
1661 pBssInfo
->extSupportedRates
[0] = 0;
1662 pBssInfo
->extSupportedRates
[1] = 0;
1666 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_WPA_IE
);
1667 if (offset
!= 0xffff)
1669 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1670 if (length
> ZM_MAX_IE_SIZE
)
1672 length
= ZM_MAX_IE_SIZE
;
1674 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->wpaIe
, offset
, length
+2);
1675 pBssInfo
->securityType
= ZM_SECURITY_TYPE_WPA
;
1679 pBssInfo
->wpaIe
[1] = 0;
1683 offset
= zfFindWifiElement(dev
, buf
, 4, 0xff);
1684 if (offset
!= 0xffff)
1686 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1687 if (length
> ZM_MAX_WPS_IE_SIZE
)
1689 length
= ZM_MAX_WPS_IE_SIZE
;
1691 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->wscIe
, offset
, length
+2);
1695 pBssInfo
->wscIe
[1] = 0;
1699 offset
= zfFindSuperGElement(dev
, buf
, ZM_WLAN_EID_VENDOR_PRIVATE
);
1700 if (offset
!= 0xffff)
1702 pBssInfo
->apCap
|= ZM_SuperG_AP
;
1706 offset
= zfFindXRElement(dev
, buf
, ZM_WLAN_EID_VENDOR_PRIVATE
);
1707 if (offset
!= 0xffff)
1709 pBssInfo
->apCap
|= ZM_XR_AP
;
1713 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_RSN_IE
);
1714 if (offset
!= 0xffff)
1716 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1717 if (length
> ZM_MAX_IE_SIZE
)
1719 length
= ZM_MAX_IE_SIZE
;
1721 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->rsnIe
, offset
, length
+2);
1722 pBssInfo
->securityType
= ZM_SECURITY_TYPE_WPA
;
1726 pBssInfo
->rsnIe
[1] = 0;
1728 #ifdef ZM_ENABLE_CENC
1730 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_CENC_IE
);
1731 if (offset
!= 0xffff)
1733 length
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
1734 if (length
> ZM_MAX_IE_SIZE
)
1736 length
= ZM_MAX_IE_SIZE
;
1738 zfCopyFromRxBuffer(dev
, buf
, pBssInfo
->cencIe
, offset
, length
+2);
1739 pBssInfo
->securityType
= ZM_SECURITY_TYPE_CENC
;
1740 pBssInfo
->capability
[0] &= 0xffef;
1744 pBssInfo
->cencIe
[1] = 0;
1746 #endif //ZM_ENABLE_CENC
1747 /* get WME Parameter IE, probe rsp may contain WME parameter element */
1748 //if ( wd->bQoSEnable )
1750 offset
= zfFindWifiElement(dev
, buf
, 2, 1);
1751 if (offset
!= 0xffff)
1753 apQosInfo
= zmw_rx_buf_readb(dev
, buf
, offset
+8) & 0x80;
1754 pBssInfo
->wmeSupport
= 1 | apQosInfo
;
1756 else if ((offset
= zfFindWifiElement(dev
, buf
, 2, 0)) != 0xffff)
1758 apQosInfo
= zmw_rx_buf_readb(dev
, buf
, offset
+8) & 0x80;
1759 pBssInfo
->wmeSupport
= 1 | apQosInfo
;
1763 pBssInfo
->wmeSupport
= 0;
1767 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_HT_CAPABILITY
);
1768 if (offset
!= 0xffff)
1771 pBssInfo
->EnableHT
= 1;
1772 if (zmw_rx_buf_readb(dev
, buf
, offset
+1) & 0x02)
1774 pBssInfo
->enableHT40
= 1;
1778 pBssInfo
->enableHT40
= 0;
1781 if (zmw_rx_buf_readb(dev
, buf
, offset
+1) & 0x40)
1790 else if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_PREN2_EID_HTCAPABILITY
)) != 0xffff)
1793 pBssInfo
->EnableHT
= 1;
1794 pBssInfo
->apCap
|= ZM_All11N_AP
;
1795 if (zmw_rx_buf_readb(dev
, buf
, offset
+2) & 0x02)
1797 pBssInfo
->enableHT40
= 1;
1801 pBssInfo
->enableHT40
= 0;
1804 if (zmw_rx_buf_readb(dev
, buf
, offset
+2) & 0x40)
1815 pBssInfo
->EnableHT
= 0;
1817 /* HT information */
1818 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
);
1819 if (offset
!= 0xffff)
1822 pBssInfo
->extChOffset
= zmw_rx_buf_readb(dev
, buf
, offset
+2) & 0x03;
1824 else if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_PREN2_EID_HTINFORMATION
)) != 0xffff)
1826 /* pre n 2.0 standard */
1827 pBssInfo
->extChOffset
= zmw_rx_buf_readb(dev
, buf
, offset
+3) & 0x03;
1831 pBssInfo
->extChOffset
= 0;
1834 if ( (pBssInfo
->enableHT40
== 1)
1835 && ((pBssInfo
->extChOffset
!= 1) && (pBssInfo
->extChOffset
!= 3)) )
1837 pBssInfo
->enableHT40
= 0;
1840 if (pBssInfo
->enableHT40
== 1)
1842 if (zfHpIsAllowedChannel(dev
, pBssInfo
->frequency
+((pBssInfo
->extChOffset
==1)?20:-20)) == 0)
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;
1851 /* get ATH Extended Capability */
1852 if ( ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
)) != 0xffff)&&
1853 ((offset
= zfFindBrdcmMrvlRlnkExtCap(dev
, buf
)) == 0xffff))
1856 pBssInfo
->athOwlAp
= 1;
1860 pBssInfo
->athOwlAp
= 0;
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) )
1867 pBssInfo
->broadcomHTAp
= 1;
1871 pBssInfo
->broadcomHTAp
= 0;
1874 /* get Marvel Extended Capability */
1875 offset
= zfFindMarvelExtCap(dev
, buf
);
1876 if (offset
!= 0xffff)
1878 pBssInfo
->marvelAp
= 1;
1882 pBssInfo
->marvelAp
= 0;
1885 /* get ATIM window */
1886 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_IBSS
);
1887 if (offset
!= 0xffff )
1889 pBssInfo
->atimWindow
= zmw_rx_buf_readh(dev
, buf
,offset
+2);
1892 /* Fit for support mode */
1893 if (pBssInfo
->frequency
> 3000) {
1894 if (wd
->supportMode
& ZM_WIRELESS_MODE_5_N
) {
1896 if (wd
->supportMode
& ZM_WIRELESS_MODE_5_54
) {
1897 /* support mode: a, n */
1900 /* support mode: n */
1901 /* reject non-n bss info */
1902 if (!pBssInfo
->EnableHT
) {
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
);
1924 /* support mode: none */
1929 if (wd
->supportMode
& ZM_WIRELESS_MODE_24_N
) {
1931 if (wd
->supportMode
& ZM_WIRELESS_MODE_24_54
) {
1932 if (wd
->supportMode
& ZM_WIRELESS_MODE_24_11
) {
1933 /* support mode: b, g, n */
1936 /* support mode: g, n */
1937 /* reject b-only bss info */
1938 if ( (!pBssInfo
->EnableHT
)
1939 && (pBssInfo
->extSupportedRates
[1] == 0) ) {
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
1949 if ( !pBssInfo
->EnableHT
) {
1950 if ( zfIsGOnlyMode(dev
, pBssInfo
->frequency
, pBssInfo
->supportedRates
)
1951 || zfIsGOnlyMode(dev
, pBssInfo
->frequency
, pBssInfo
->extSupportedRates
) ) {
1954 zfGatherBMode(dev
, pBssInfo
->supportedRates
,
1955 pBssInfo
->extSupportedRates
);
1958 pBssInfo
->frameBodysize
= zfRemoveElement(dev
,
1959 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
1961 pBssInfo
->frameBodysize
= zfRemoveElement(dev
,
1962 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
1963 ZM_WLAN_EID_EXTENDED_RATE
);
1965 pBssInfo
->frameBodysize
= zfUpdateElement(dev
,
1966 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
1967 pBssInfo
->supportedRates
);
1971 /* support mode: n */
1972 /* reject non-n bss info */
1973 if (!pBssInfo
->EnableHT
) {
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
);
1994 if (wd
->supportMode
& ZM_WIRELESS_MODE_24_54
) {
1996 if (wd
->supportMode
& ZM_WIRELESS_MODE_24_11
) {
1997 /* support mode: b, g */
1998 /* delete n mode information */
2000 /* support mode: g */
2001 /* delete n mode information */
2002 /* reject b-only bss info */
2003 if (pBssInfo
->extSupportedRates
[1] == 0) {
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
) ) {
2016 zfGatherBMode(dev
, pBssInfo
->supportedRates
,
2017 pBssInfo
->extSupportedRates
);
2020 pBssInfo
->frameBodysize
= zfRemoveElement(dev
,
2021 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
2023 pBssInfo
->frameBodysize
= zfRemoveElement(dev
,
2024 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
2025 ZM_WLAN_EID_EXTENDED_RATE
);
2027 pBssInfo
->frameBodysize
= zfUpdateElement(dev
,
2028 pBssInfo
->frameBody
, pBssInfo
->frameBodysize
,
2029 pBssInfo
->supportedRates
);
2032 /* support mode: none */
2039 pBssInfo
->flag
|= ZM_BSS_INFO_VALID_BIT
;
2042 /* Update Timer information */
2043 pBssInfo
->tick
= wd
->tick
;
2045 /* Update ERP information */
2046 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_ERP
);
2047 if (offset
!= 0xffff)
2049 pBssInfo
->erp
= zmw_rx_buf_readb(dev
, buf
, offset
+2);
2052 if( (s8_t
)pBssInfo
->signalStrength
< (s8_t
)AddInfo
->Tail
.Data
.SignalStrength1
)
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);
2059 /* Update the sorting value */
2060 pBssInfo
->sortValue
= zfComputeBssInfoWeightValue(dev
,
2061 (pBssInfo
->supportedRates
[6] + pBssInfo
->extSupportedRates
[0]),
2063 pBssInfo
->enableHT40
,
2064 pBssInfo
->signalStrength
);
2078 void zfStaProcessBeacon(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
) //CWYang(m)
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
)];
2087 zmw_get_wlan_dev(dev
);
2089 zmw_declare_for_critical_section();
2091 /* sta routine jobs */
2092 zfStaProtErpMonitor(dev
, buf
); /* check protection mode */
2094 if (zfStaIsConnected(dev
))
2096 ZM_MAC_WORD_TO_BYTE(wd
->sta
.bssid
, bssid
);
2098 if ( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
2100 if ( zfRxBufferEqualToStr(dev
, buf
, bssid
, ZM_WLAN_HEADER_A2_OFFSET
, 6) )
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
++;
2114 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
2116 if ( zfRxBufferEqualToStr(dev
, buf
, bssid
, ZM_WLAN_HEADER_A3_OFFSET
, 6) )
2119 struct zsPartnerNotifyEvent event
;
2121 zm_debug_msg0("20070916 Receive opposite Beacon!");
2122 zmw_enter_critical_section(dev
);
2123 wd
->sta
.ibssReceiveBeaconCount
++;
2124 zmw_leave_critical_section(dev
);
2126 res
= zfStaSetOppositeInfoFromRxBuf(dev
, buf
);
2129 // New peer station found. Notify the wrapper now
2130 zfInitPartnerNotifyEvent(dev
, buf
, &event
);
2131 if (wd
->zfcbIbssPartnerNotify
!= NULL
)
2133 wd
->zfcbIbssPartnerNotify(dev
, 1, &event
);
2136 /* update signal strength and signal quality */
2137 zfStaSignalStatistic(dev
, AddInfo
->Tail
.Data
.SignalStrength1
,
2138 AddInfo
->Tail
.Data
.SignalQuality
); //CWYang(+)
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
2144 else if ( wd
->sta
.oppositeCount
== 0 )
2145 { /* IBSS merge if SSID matched */
2146 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SSID
);
2147 if (offset
!= 0xffff)
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
)) )
2153 capabilityInfo
= zmw_buf_readh(dev
, buf
, 34);
2155 if ( capabilityInfo
& ZM_BIT_1
)
2157 if ( (wd
->sta
.capability
[0] & ZM_BIT_4
) ==
2158 (capabilityInfo
& ZM_BIT_4
) )
2160 zm_debug_msg0("IBSS merge");
2161 zfCopyFromRxBuffer(dev
, buf
, bssid
,
2162 ZM_WLAN_HEADER_A3_OFFSET
, 6);
2163 zfUpdateBssid(dev
, bssid
);
2173 /* return if not channel scan */
2174 if ( !wd
->sta
.bChannelScan
)
2179 zfCopyFromRxBuffer(dev
, buf
, pBuf
, 0, sizeof(struct zsWlanBeaconFrameHeader
));
2180 pBeaconHeader
= (struct zsWlanBeaconFrameHeader
*) pBuf
;
2182 zmw_enter_critical_section(dev
);
2184 //zm_debug_msg1("bss count = ", wd->sta.bssList.bssCount);
2186 pBssInfo
= zfStaFindBssInfo(dev
, buf
, pBeaconHeader
);
2188 if ( pBssInfo
== NULL
)
2190 /* Allocate a new entry if BSS not in the scan list */
2191 pBssInfo
= zfBssInfoAllocate(dev
);
2192 if (pBssInfo
!= NULL
)
2194 res
= zfStaInitBssInfo(dev
, buf
, pBeaconHeader
, pBssInfo
, AddInfo
, 0);
2195 //zfDumpSSID(pBssInfo->ssid[1], &(pBssInfo->ssid[2]));
2198 zfBssInfoFree(dev
, pBssInfo
);
2202 zfBssInfoInsertToList(dev
, pBssInfo
);
2208 res
= zfStaInitBssInfo(dev
, buf
, pBeaconHeader
, pBssInfo
, AddInfo
, 1);
2211 zfBssInfoRemoveFromList(dev
, pBssInfo
);
2212 zfBssInfoFree(dev
, pBssInfo
);
2214 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
2218 // It would reset the alive counter if the peer station is found!
2219 zfStaFindFreeOpposite(dev
, (u16_t
*)pBssInfo
->macaddr
, &idx
);
2223 zmw_leave_critical_section(dev
);
2231 void zfAuthFreqCompleteCb(zdev_t
* dev
)
2233 zmw_get_wlan_dev(dev
);
2234 zmw_declare_for_critical_section();
2236 zmw_enter_critical_section(dev
);
2238 if (wd
->sta
.connectState
== ZM_STA_CONN_STATE_AUTH_COMPLETED
)
2240 zm_debug_msg0("ZM_STA_CONN_STATE_ASSOCIATE");
2241 wd
->sta
.connectTimer
= wd
->tick
;
2242 wd
->sta
.connectState
= ZM_STA_CONN_STATE_ASSOCIATE
;
2245 zmw_leave_critical_section(dev
);
2249 /************************************************************************/
2251 /* FUNCTION DESCRIPTION zfProcessAuth */
2252 /* Process authenticate management frame. */
2255 /* dev : device pointer */
2256 /* buf : auth frame buffer */
2262 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
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
)
2271 struct zsWlanAuthFrameHeader
* pAuthFrame
;
2272 u8_t pBuf
[sizeof(struct zsWlanAuthFrameHeader
)];
2275 zmw_get_wlan_dev(dev
);
2276 zmw_declare_for_critical_section();
2278 if ( !zfStaIsConnecting(dev
) )
2283 pAuthFrame
= (struct zsWlanAuthFrameHeader
*) pBuf
;
2284 zfCopyFromRxBuffer(dev
, buf
, pBuf
, 0, sizeof(struct zsWlanAuthFrameHeader
));
2286 if ( wd
->sta
.connectState
== ZM_STA_CONN_STATE_AUTH_OPEN
)
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) )
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
);
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
);
2304 /* send association frame */
2305 if ( wd
->sta
.connectByReasso
)
2307 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_REASOCREQ
,
2308 wd
->sta
.bssid
, 0, 0, 0);
2312 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_ASOCREQ
,
2313 wd
->sta
.bssid
, 0, 0, 0);
2320 zm_debug_msg1("authentication failed, status = ",
2321 pAuthFrame
->status
);
2323 if (wd
->sta
.authMode
== ZM_AUTH_MODE_AUTO
)
2325 wd
->sta
.bIsSharedKey
= 1;
2326 zfStaStartConnect(dev
, wd
->sta
.bIsSharedKey
);
2330 zm_debug_msg0("ZM_STA_STATE_DISCONNECT");
2331 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED
, wd
->sta
.bssid
, 3);
2335 else if ( wd
->sta
.connectState
== ZM_STA_CONN_STATE_AUTH_SHARE_1
)
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) )
2342 zfMemoryCopy(wd
->sta
.challengeText
, pAuthFrame
->challengeText
,
2343 pAuthFrame
->challengeText
[1]+2);
2345 /* send the 3rd authentication frame */
2348 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_AUTH
,
2349 wd
->sta
.bssid
, p1
, p2
, 0);
2351 zmw_enter_critical_section(dev
);
2352 wd
->sta
.connectTimer
= wd
->tick
;
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
);
2360 zm_debug_msg1("authentication failed, status = ",
2361 pAuthFrame
->status
);
2363 zm_debug_msg0("ZM_STA_STATE_DISCONNECT");
2364 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED
, wd
->sta
.bssid
, 3);
2367 else if ( wd
->sta
.connectState
== ZM_STA_CONN_STATE_AUTH_SHARE_2
)
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) )
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
);
2378 /* send association frame */
2379 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_ASOCREQ
,
2380 wd
->sta
.bssid
, 0, 0, 0);
2382 zmw_enter_critical_section(dev
);
2383 wd
->sta
.connectTimer
= wd
->tick
;
2385 zm_debug_msg0("ZM_STA_SUB_STATE_ASSOCIATE");
2386 wd
->sta
.connectState
= ZM_STA_CONN_STATE_ASSOCIATE
;
2387 zmw_leave_critical_section(dev
);
2391 zm_debug_msg1("authentication failed, status = ",
2392 pAuthFrame
->status
);
2394 zm_debug_msg0("ZM_STA_STATE_DISCONNECT");
2395 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED
, wd
->sta
.bssid
, 3);
2400 zm_debug_msg0("unknown case");
2404 void zfStaProcessAsocReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t
* src
, u16_t apId
)
2410 void zfStaProcessAsocRsp(zdev_t
* dev
, zbuf_t
* buf
)
2412 struct zsWlanAssoFrameHeader
* pAssoFrame
;
2413 u8_t pBuf
[sizeof(struct zsWlanAssoFrameHeader
)];
2416 u32_t oneTxStreamCap
;
2418 zmw_get_wlan_dev(dev
);
2420 if ( !zfStaIsConnecting(dev
) )
2425 pAssoFrame
= (struct zsWlanAssoFrameHeader
*) pBuf
;
2426 zfCopyFromRxBuffer(dev
, buf
, pBuf
, 0, sizeof(struct zsWlanAssoFrameHeader
));
2428 if ( wd
->sta
.connectState
== ZM_STA_CONN_STATE_ASSOCIATE
)
2430 if ( pAssoFrame
->status
== 0 )
2432 zm_debug_msg0("ZM_STA_STATE_CONNECTED");
2434 if (wd
->sta
.EnableHT
== 1)
2436 wd
->sta
.wmeConnected
= 1;
2438 if ((wd
->sta
.wmeEnabled
& ZM_STA_WME_ENABLE_BIT
) != 0) //WME enabled
2440 /* Asoc rsp may contain WME parameter element */
2441 offset
= zfFindWifiElement(dev
, buf
, 2, 1);
2442 if (offset
!= 0xffff)
2444 zm_debug_msg0("WME enable");
2445 wd
->sta
.wmeConnected
= 1;
2446 if ((wd
->sta
.wmeEnabled
& ZM_STA_UAPSD_ENABLE_BIT
) != 0)
2448 if ((zmw_rx_buf_readb(dev
, buf
, offset
+8) & 0x80) != 0)
2450 zm_debug_msg0("UAPSD enable");
2451 wd
->sta
.qosInfo
= wd
->sta
.wmeQosInfo
;
2455 zfStaUpdateWmeParameter(dev
, buf
);
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
)
2464 wd
->sta
.asocRspFrameBodySize
= ZM_CACHED_FRAMEBODY_SIZE
;
2466 for (i
=0; i
<wd
->sta
.asocRspFrameBodySize
; i
++)
2468 wd
->sta
.asocRspFrameBody
[i
] = zmw_rx_buf_readb(dev
, buf
, i
+24);
2471 zfStaStoreAsocRspIe(dev
, buf
);
2472 if (wd
->sta
.EnableHT
&&
2473 ((wd
->sta
.ie
.HtCap
.HtCapInfo
& HTCAP_SupChannelWidthSet
) != 0) &&
2474 (wd
->ExtOffset
!= 0))
2476 wd
->sta
.htCtrlBandwidth
= 1;
2480 wd
->sta
.htCtrlBandwidth
= 0;
2483 //Set channel according to AP's configuration
2484 //zfCoreSetFrequencyEx(dev, wd->frequency, wd->BandWidth40,
2485 // wd->ExtOffset, NULL);
2487 if (wd
->sta
.EnableHT
== 1)
2489 wd
->addbaComplete
= 0;
2491 if ((wd
->sta
.SWEncryptEnable
& ZM_SW_TKIP_ENCRY_EN
) == 0 &&
2492 (wd
->sta
.SWEncryptEnable
& ZM_SW_WEP_ENCRY_EN
) == 0)
2495 zfAggSendAddbaRequest(dev
, wd
->sta
.bssid
, 0, 0);
2496 zfTimerSchedule(dev
, ZM_EVENT_TIMEOUT_ADDBA
, 100);
2500 /* set RIFS support */
2501 if(wd
->sta
.ie
.HtInfo
.ChannelInfo
& ExtHtCap_RIFSMode
)
2504 // zfHpSetRifs(dev, wd->sta.EnableHT, 1, (wd->sta.currentFrequency < 3000)? 1:0);
2507 wd
->sta
.aid
= pAssoFrame
->aid
& 0x3fff;
2508 wd
->sta
.oppositeCount
= 0; /* reset opposite count */
2509 zfStaSetOppositeInfoFromRxBuf(dev
, buf
);
2511 wd
->sta
.rxBeaconCount
= 16;
2513 zfChangeAdapterState(dev
, ZM_STA_STATE_CONNECTED
);
2514 wd
->sta
.connPowerInHalfDbm
= zfHpGetTransmitPower(dev
);
2515 if (wd
->zfcbConnectNotify
!= NULL
)
2517 if (wd
->sta
.EnableHT
!= 0) /* 11n */
2519 oneTxStreamCap
= (zfHpCapability(dev
) & ZM_HP_CAP_11N_ONE_TX_STREAM
);
2520 if (wd
->sta
.htCtrlBandwidth
== 1) /* HT40*/
2522 if(oneTxStreamCap
) /* one Tx stream */
2526 wd
->CurrentTxRateKbps
= 150000;
2527 wd
->CurrentRxRateKbps
= 300000;
2531 wd
->CurrentTxRateKbps
= 135000;
2532 wd
->CurrentRxRateKbps
= 270000;
2535 else /* Two Tx streams */
2539 wd
->CurrentTxRateKbps
= 300000;
2540 wd
->CurrentRxRateKbps
= 300000;
2544 wd
->CurrentTxRateKbps
= 270000;
2545 wd
->CurrentRxRateKbps
= 270000;
2551 if(oneTxStreamCap
) /* one Tx stream */
2553 wd
->CurrentTxRateKbps
= 650000;
2554 wd
->CurrentRxRateKbps
= 130000;
2556 else /* Two Tx streams */
2558 wd
->CurrentTxRateKbps
= 130000;
2559 wd
->CurrentRxRateKbps
= 130000;
2565 if (wd
->sta
.connection_11b
!= 0)
2567 wd
->CurrentTxRateKbps
= 11000;
2568 wd
->CurrentRxRateKbps
= 11000;
2572 wd
->CurrentTxRateKbps
= 54000;
2573 wd
->CurrentRxRateKbps
= 54000;
2578 wd
->zfcbConnectNotify(dev
, ZM_STATUS_MEDIA_CONNECT
, wd
->sta
.bssid
);
2580 wd
->sta
.connectByReasso
= TRUE
;
2581 wd
->sta
.failCntOfReasso
= 0;
2583 zfPowerSavingMgrConnectNotify(dev
);
2585 /* Disable here because fixed rate is only for test, TBD. */
2586 //if (wd->sta.EnableHT)
2588 // wd->txMCS = 7; //Rate = 65Mbps
2589 // wd->txMT = 2; // Ht rate
2590 // wd->enableAggregation = 2; // Enable Aggregation
2595 zm_debug_msg1("association failed, status = ",
2596 pAssoFrame
->status
);
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);
2606 void zfStaStoreAsocRspIe(zdev_t
* dev
, zbuf_t
* buf
)
2613 u8_t asocExtOffset
= 0;
2615 zmw_get_wlan_dev(dev
);
2617 for (i
=0; i
<wd
->sta
.asocRspFrameBodySize
; i
++)
2619 wd
->sta
.asocRspFrameBody
[i
] = zmw_rx_buf_readb(dev
, buf
, i
+24);
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
)) )
2627 htcap
= (u8_t
*)&wd
->sta
.ie
.HtCap
;
2628 for (i
=0; i
<28; i
++)
2632 wd
->BandWidth40
= 0;
2637 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_HT_CAPABILITY
);
2638 if (offset
!= 0xffff)
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
);
2645 for (i
=1; i
<=26; i
++)
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]);
2651 else if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_PREN2_EID_HTCAPABILITY
)) != 0xffff)
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
++)
2658 htcap
[i
] = zmw_rx_buf_readb(dev
, buf
, offset
+ i
);
2659 zm_msg2_mm(ZM_LV_1
, "ASOC: HT Capabilities, htcap=", htcap
[i
]);
2665 htcap
= (u8_t
*)&wd
->sta
.ie
.HtCap
;
2666 for (i
=0; i
<28; i
++)
2670 wd
->BandWidth40
= 0;
2675 asocBw40
= (u8_t
)((wd
->sta
.ie
.HtCap
.HtCapInfo
& HTCAP_SupChannelWidthSet
) >> 1);
2677 /* HT information */
2678 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_EXTENDED_HT_CAPABILITY
);
2679 if (offset
!= 0xffff)
2682 zm_debug_msg0("atheros pre n HTINFO");
2684 htcap
= (u8_t
*)&wd
->sta
.ie
.HtInfo
;
2685 htcap
[0] = zmw_rx_buf_readb(dev
, buf
, offset
);
2687 for (i
=1; i
<=22; i
++)
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]);
2693 else if ((offset
= zfFindElement(dev
, buf
, ZM_WLAN_PREN2_EID_HTINFORMATION
)) != 0xffff)
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
++)
2701 htcap
[i
] = zmw_rx_buf_readb(dev
, buf
, offset
+ i
);
2702 zm_msg2_mm(ZM_LV_1
, "ASOC: HT Info, htinfo=", htcap
[i
]);
2707 zm_debug_msg0("no HTINFO");
2708 htcap
= (u8_t
*)&wd
->sta
.ie
.HtInfo
;
2709 for (i
=0; i
<24; i
++)
2714 asocExtOffset
= wd
->sta
.ie
.HtInfo
.ChannelInfo
& ExtHtCap_ExtChannelOffsetBelow
;
2716 if ((wd
->sta
.EnableHT
== 1) && (asocBw40
== 1) && ((asocExtOffset
== 1) || (asocExtOffset
== 3)))
2718 wd
->BandWidth40
= asocBw40
;
2719 wd
->ExtOffset
= asocExtOffset
;
2723 wd
->BandWidth40
= 0;
2730 void zfStaProcessDeauth(zdev_t
* dev
, zbuf_t
* buf
)
2734 zmw_get_wlan_dev(dev
);
2735 zmw_declare_for_critical_section();
2737 /* STA : if SA=connected AP then disconnect with AP */
2738 if ( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
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]))
2745 if (zfwBufGetSize(dev
, buf
) >= 24+2) //not a malformed frame
2747 if ( zfStaIsConnected(dev
) )
2749 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_DEAUTH
, wd
->sta
.bssid
, 2);
2751 else if (zfStaIsConnecting(dev
))
2753 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_AUTH_FAILED
, wd
->sta
.bssid
, 3);
2761 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
2763 u16_t peerMacAddr
[3];
2767 if ( zfStaIsConnected(dev
) )
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);
2773 zmw_enter_critical_section(dev
);
2774 res
= zfStaFindOppositeByMACAddr(dev
, peerMacAddr
, &peerIdx
);
2777 wd
->sta
.oppositeInfo
[peerIdx
].aliveCounter
= 0;
2779 zmw_leave_critical_section(dev
);
2784 void zfStaProcessDisasoc(zdev_t
* dev
, zbuf_t
* buf
)
2788 zmw_get_wlan_dev(dev
);
2790 /* STA : if SA=connected AP then disconnect with AP */
2791 if ( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
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);
2797 if ((apMacAddr
[0] == wd
->sta
.bssid
[0]) && (apMacAddr
[1] == wd
->sta
.bssid
[1]) && (apMacAddr
[2] == wd
->sta
.bssid
[2]))
2799 if (zfwBufGetSize(dev
, buf
) >= 24+2) //not a malformed frame
2801 if ( zfStaIsConnected(dev
) )
2803 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_DISASOC
, wd
->sta
.bssid
, 2);
2807 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_ASOC_FAILED
, wd
->sta
.bssid
, 3);
2816 /************************************************************************/
2818 /* FUNCTION DESCRIPTION zfProcessProbeReq */
2819 /* Process probe request management frame. */
2822 /* dev : device pointer */
2823 /* buf : auth frame buffer */
2829 /* Stephen Chen ZyDAS Technology Corporation 2005.10 */
2831 /************************************************************************/
2832 void zfStaProcessProbeReq(zdev_t
* dev
, zbuf_t
* buf
, u16_t
* src
)
2839 zmw_get_wlan_dev(dev
);
2841 /* check mode : AP/IBSS */
2842 if ((wd
->wlanMode
!= ZM_MODE_AP
) && (wd
->wlanMode
!= ZM_MODE_IBSS
))
2844 zm_msg0_mm(ZM_LV_3
, "Ignore probe req");
2849 offset
= zfFindElement(dev
, buf
, ZM_WLAN_EID_SSID
);
2850 if (offset
== 0xffff)
2852 zm_msg0_mm(ZM_LV_3
, "probe req SSID not found");
2856 len
= zmw_rx_buf_readb(dev
, buf
, offset
+1);
2858 for (i
=0; i
<ZM_MAX_AP_SUPPORT
; i
++)
2860 if ((wd
->ap
.apBitmap
& (i
<<i
)) != 0)
2863 /* boardcast SSID */
2864 if ((len
== 0) && (wd
->ap
.hideSsid
[i
] == 0))
2868 /* Not broadcast SSID */
2869 else if (wd
->ap
.ssidLen
[i
] == len
)
2871 for (j
=0; j
<len
; j
++)
2873 if (zmw_rx_buf_readb(dev
, buf
, offset
+1+j
)
2874 != wd
->ap
.ssid
[i
][j
])
2886 /* Send probe response */
2887 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBERSP
, src
, i
, 0, 0);
2893 void zfStaProcessProbeRsp(zdev_t
* dev
, zbuf_t
* buf
, struct zsAdditionInfo
* AddInfo
)
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.
2900 zmw_get_wlan_dev(dev
);
2902 if ( !wd
->sta
.bChannelScan
)
2908 zfProcessProbeRsp(dev
, buf
, AddInfo
);
2911 void zfIBSSSetupBssDesc(zdev_t
*dev
)
2913 #ifdef ZM_ENABLE_IBSS_WPA2PSK
2916 struct zsBssInfo
*pBssInfo
;
2919 zmw_get_wlan_dev(dev
);
2921 pBssInfo
= &wd
->sta
.ibssBssDesc
;
2922 zfZeroMemory((u8_t
*)pBssInfo
, sizeof(struct zsBssInfo
));
2924 pBssInfo
->signalStrength
= 100;
2926 zfMemoryCopy((u8_t
*)pBssInfo
->macaddr
, (u8_t
*)wd
->macAddr
,6);
2927 zfMemoryCopy((u8_t
*)pBssInfo
->bssid
, (u8_t
*)wd
->sta
.bssid
, 6);
2929 pBssInfo
->beaconInterval
[0] = (u8_t
)(wd
->beaconInterval
) ;
2930 pBssInfo
->beaconInterval
[1] = (u8_t
)((wd
->beaconInterval
) >> 8) ;
2932 pBssInfo
->capability
[0] = wd
->sta
.capability
[0];
2933 pBssInfo
->capability
[1] = wd
->sta
.capability
[1];
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;
2944 /* DS parameter set */
2945 pBssInfo
->channel
= zfChFreqToNum(wd
->frequency
, NULL
);
2946 pBssInfo
->frequency
= wd
->frequency
;
2947 pBssInfo
->atimWindow
= wd
->sta
.atimWindow
;
2949 #ifdef ZM_ENABLE_IBSS_WPA2PSK
2950 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
2960 /* Group Cipher Suite, default=TKIP */
2961 0x00, 0x0f, 0xac, 0x04,
2962 /* Pairwise Cipher Suite Count */
2964 /* Pairwise Cipher Suite, default=TKIP */
2965 0x00, 0x0f, 0xac, 0x02,
2966 /* Authentication and Key Management Suite Count */
2968 /* Authentication type, default=PSK */
2969 0x00, 0x0f, 0xac, 0x02,
2970 /* RSN capability */
2974 /* Overwrite Group Cipher Suite by AP's setting */
2975 zfMemoryCopy(rsn
+4, zgWpa2AesOui
, 4);
2977 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
2979 /* Overwrite Pairwise Cipher Suite by AES */
2980 zfMemoryCopy(rsn
+10, zgWpa2AesOui
, 4);
2984 pBssInfo
->frameBody
[offset
++] = ZM_WLAN_EID_RSN_IE
;
2987 pBssInfo
->frameBody
[offset
++] = rsn
[1] ;
2990 for(i
=0; i
<rsn
[1]; i
++)
2992 pBssInfo
->frameBody
[offset
++] = rsn
[i
+2] ;
2995 zfMemoryCopy(pBssInfo
->rsnIe
, rsn
, rsn
[1]+2);
3000 void zfIbssConnectNetwork(zdev_t
* dev
)
3002 struct zsBssInfo
* pBssInfo
;
3003 struct zsBssInfo tmpBssInfo
;
3004 u8_t macAddr
[6], bssid
[6], bssNotFound
= TRUE
;
3007 struct zsPartnerNotifyEvent event
;
3009 u16_t oppositeWepStatus
;
3011 zmw_get_wlan_dev(dev
);
3013 zmw_declare_for_critical_section();
3015 /* change state to CONNECTING and stop the channel scanning */
3016 zfChangeAdapterState(dev
, ZM_STA_STATE_CONNECTING
);
3017 zfPowerSavingMgrWakeup(dev
);
3019 /* Set TxQs CWMIN, CWMAX, AIFS and TXO to WME STA default. */
3020 zfUpdateDefaultQosParameter(dev
, 0);
3022 wd
->sta
.bProtectionMode
= FALSE
;
3023 zfHpSetSlotTime(dev
, 1);
3026 wd
->sta
.capability
[0] &= ~ZM_BIT_0
;
3028 wd
->sta
.capability
[0] |= ZM_BIT_1
;
3029 /* not not use short slot time */
3030 wd
->sta
.capability
[1] &= ~ZM_BIT_2
;
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;
3039 if ( wd
->sta
.bssList
.bssCount
)
3041 //Reorder BssList by RSSI--CWYang(+)
3042 zfBssInfoReorderList(dev
);
3044 zmw_enter_critical_section(dev
);
3046 pBssInfo
= wd
->sta
.bssList
.head
;
3048 for(i
=0; i
<wd
->sta
.bssList
.bssCount
; i
++)
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
;
3056 if ( pBssInfo
->rsnIe
[1] != 0 )
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
;
3063 else if ( pBssInfo
->rsnIe
[7] == 0x02 )
3065 // zm_debug_msg0("TKIP");
3066 oppositeWepStatus
= ZM_ENCRYPTION_TKIP
;
3068 else if ( pBssInfo
->rsnIe
[7] == 0x04 )
3070 // zm_debug_msg0("CCMP-AES");
3071 oppositeWepStatus
= ZM_ENCRYPTION_AES
;
3077 // zm_debug_msg0("Privacy bit off");
3078 oppositeWepStatus
= ZM_ENCRYPTION_WEP_DISABLED
;
3081 if ( (zfMemoryIsEqual(&(pBssInfo
->ssid
[2]), wd
->sta
.ssid
,
3083 (wd
->sta
.ssidLen
== pBssInfo
->ssid
[1])&&
3084 (oppositeWepStatus
== wd
->sta
.wepStatus
) )
3086 /* Check support mode */
3087 if (pBssInfo
->frequency
> 3000) {
3088 if ( (pBssInfo
->EnableHT
== 1)
3089 || (pBssInfo
->apCap
& ZM_All11N_AP
) ) //11n AP
3091 channelFlags
= CHANNEL_A_HT
;
3092 if (pBssInfo
->enableHT40
== 1) {
3093 channelFlags
|= CHANNEL_HT40
;
3096 channelFlags
= CHANNEL_A
;
3099 if ( (pBssInfo
->EnableHT
== 1)
3100 || (pBssInfo
->apCap
& ZM_All11N_AP
) ) //11n AP
3102 channelFlags
= CHANNEL_G_HT
;
3103 if(pBssInfo
->enableHT40
== 1) {
3104 channelFlags
|= CHANNEL_HT40
;
3107 if (pBssInfo
->extSupportedRates
[1] == 0) {
3108 channelFlags
= CHANNEL_B
;
3110 channelFlags
= CHANNEL_G
;
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
)) )
3120 pBssInfo
= pBssInfo
->next
;
3124 /* Bypass DFS channel */
3125 if (zfHpIsDfsChannelNCS(dev
, pBssInfo
->frequency
))
3127 zm_debug_msg0("Bypass DFS channel");
3131 /* check IBSS bit */
3132 if ( pBssInfo
->capability
[0] & ZM_BIT_1
)
3134 /* may check timestamp here */
3140 pBssInfo
= pBssInfo
->next
;
3143 if ((j
< wd
->sta
.bssList
.bssCount
) && (pBssInfo
!= NULL
))
3145 zfwMemoryCopy((u8_t
*)&tmpBssInfo
, (u8_t
*)(pBssInfo
), sizeof(struct zsBssInfo
));
3146 pBssInfo
= &tmpBssInfo
;
3153 zmw_leave_critical_section(dev
);
3155 //if ( j < wd->sta.bssList.bssCount )
3156 if (pBssInfo
!= NULL
)
3160 zm_debug_msg0("IBSS found");
3162 /* Found IBSS, reset bssNotFoundCount */
3163 zmw_enter_critical_section(dev
);
3164 wd
->sta
.bssNotFoundCount
= 0;
3165 zmw_leave_critical_section(dev
);
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);
3179 if (wd
->beaconInterval
== 0)
3181 wd
->beaconInterval
= 100;
3184 /* rsn information element */
3185 if ( pBssInfo
->rsnIe
[1] != 0 )
3187 zfMemoryCopy(wd
->sta
.rsnIe
, pBssInfo
->rsnIe
,
3188 pBssInfo
->rsnIe
[1]+2);
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
);
3199 wd
->sta
.rsnIe
[1] = 0;
3203 if ( pBssInfo
->capability
[0] & ZM_BIT_4
)
3205 wd
->sta
.capability
[0] |= ZM_BIT_4
;
3209 wd
->sta
.capability
[0] &= ~ZM_BIT_4
;
3213 wd
->preambleTypeInUsed
= wd
->preambleType
;
3214 if ( wd
->preambleTypeInUsed
== ZM_PREAMBLE_TYPE_AUTO
)
3216 if (pBssInfo
->capability
[0] & ZM_BIT_5
)
3218 wd
->preambleTypeInUsed
= ZM_PREAMBLE_TYPE_SHORT
;
3222 wd
->preambleTypeInUsed
= ZM_PREAMBLE_TYPE_LONG
;
3226 if (wd
->preambleTypeInUsed
== ZM_PREAMBLE_TYPE_LONG
)
3228 wd
->sta
.capability
[0] &= ~ZM_BIT_5
;
3232 wd
->sta
.capability
[0] |= ZM_BIT_5
;
3235 wd
->sta
.beaconFrameBodySize
= pBssInfo
->frameBodysize
+ 12;
3237 if (wd
->sta
.beaconFrameBodySize
> ZM_CACHED_FRAMEBODY_SIZE
)
3239 wd
->sta
.beaconFrameBodySize
= ZM_CACHED_FRAMEBODY_SIZE
;
3244 wd
->sta
.beaconFrameBody
[k
] = pBssInfo
->timeStamp
[k
];
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
++)
3253 wd
->sta
.beaconFrameBody
[k
+12] = pBssInfo
->frameBody
[k
];
3256 zmw_enter_critical_section(dev
);
3257 res
= zfStaSetOppositeInfoFromBSSInfo(dev
, pBssInfo
);
3260 zfMemoryCopy(event
.bssid
, (u8_t
*)(pBssInfo
->bssid
), 6);
3261 zfMemoryCopy(event
.peerMacAddr
, (u8_t
*)(pBssInfo
->macaddr
), 6);
3263 zmw_leave_critical_section(dev
);
3265 //zfwIbssPartnerNotify(dev, 1, &event);
3270 /* IBSS not found */
3273 #ifdef ZM_ENABLE_IBSS_WPA2PSK
3276 if ( wd
->sta
.ibssJoinOnly
)
3278 zm_debug_msg0("IBSS join only...retry...");
3282 if(wd
->sta
.bssNotFoundCount
<2)
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
);
3292 zmw_enter_critical_section(dev
);
3293 /* Fail IBSS found, TODO create IBSS */
3294 wd
->sta
.bssNotFoundCount
= 0;
3295 zmw_leave_critical_section(dev
);
3299 if (zfHpIsDfsChannel(dev
, wd
->frequency
))
3301 wd
->frequency
= zfHpFindFirstNonDfsChannel(dev
, wd
->frequency
> 3000);
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;
3310 zm_debug_msg1("IBSS not found, created one in channel ", wd
->frequency
);
3312 wd
->sta
.ibssBssIsCreator
= 1;
3314 //wd->sta.flagFreqChanging = 1;
3315 zfCoreSetFrequency(dev
, wd
->frequency
);
3316 if (wd
->sta
.bDesiredBssid
== TRUE
)
3320 bssid
[k
] = wd
->sta
.desiredBssid
[k
];
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
);
3336 bssid
[k
] = (u8_t
) zfGetRandomNumber(dev
, 0);
3338 bssid
[0] &= ~ZM_BIT_0
;
3339 bssid
[0] |= ZM_BIT_1
;
3343 zfUpdateBssid(dev
, bssid
);
3344 //wd->sta.atimWindow = 0x0a;
3346 /* rate information */
3347 if(wd
->frequency
<= ZM_CH_G_14
) // 2.4 GHz b+g
3349 if ( wd
->wfc
.bIbssGMode
3350 && (wd
->supportMode
& (ZM_WIRELESS_MODE_24_54
|ZM_WIRELESS_MODE_24_N
)) )
3352 zfResetSupportRate(dev
, ZM_DEFAULT_SUPPORT_RATE_IBSS_AG
);
3356 zfResetSupportRate(dev
, ZM_DEFAULT_SUPPORT_RATE_IBSS_B
);
3359 zfResetSupportRate(dev
, ZM_DEFAULT_SUPPORT_RATE_IBSS_AG
);
3362 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_WEP_DISABLED
)
3364 wd
->sta
.capability
[0] &= ~ZM_BIT_4
;
3368 wd
->sta
.capability
[0] |= ZM_BIT_4
;
3371 wd
->preambleTypeInUsed
= wd
->preambleType
;
3372 if (wd
->preambleTypeInUsed
== ZM_PREAMBLE_TYPE_LONG
)
3374 wd
->sta
.capability
[0] &= ~ZM_BIT_5
;
3378 wd
->preambleTypeInUsed
= ZM_PREAMBLE_TYPE_SHORT
;
3379 wd
->sta
.capability
[0] |= ZM_BIT_5
;
3382 zfIBSSSetupBssDesc(dev
);
3384 #ifdef ZM_ENABLE_IBSS_WPA2PSK
3386 // 20070411 Add WPA2PSK information to its IBSS network !!!
3392 /* beacon interval */
3393 wd
->sta
.beaconFrameBody
[offset
++] = (u8_t
)(wd
->beaconInterval
) ;
3394 wd
->sta
.beaconFrameBody
[offset
++] = (u8_t
)((wd
->beaconInterval
) >> 8) ;
3396 /* capability information */
3397 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.capability
[0] ;
3398 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.capability
[1] ;
3402 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_SSID
;
3404 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.ssidLen
;
3406 for(i
=0; i
<wd
->sta
.ssidLen
; i
++)
3408 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.ssid
[i
] ;
3412 rateSet
= ZM_RATE_SET_CCK
;
3413 if ( (rateSet
== ZM_RATE_SET_OFDM
)&&((wd
->gRate
& 0xff) == 0) )
3419 // support rate element id
3420 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_SUPPORT_RATE
;
3422 // support rate length
3423 lenOffset
= offset
++;
3425 // support rate information
3428 if ((wd
->bRate
& (0x1<<i
)) == (0x1<<i
))
3430 wd
->sta
.beaconFrameBody
[offset
++] =
3431 zg11bRateTbl
[i
]+((wd
->bRateBasic
& (0x1<<i
))<<(7-i
)) ;
3436 // support rate length
3437 wd
->sta
.beaconFrameBody
[lenOffset
] = len
;
3440 /* DS parameter set */
3441 // DS parameter set elemet id
3442 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_DS
;
3444 // DS parameter set length
3445 wd
->sta
.beaconFrameBody
[offset
++] = 1 ;
3447 // DS parameter set information
3448 wd
->sta
.beaconFrameBody
[offset
++] =
3449 zfChFreqToNum(wd
->frequency
, NULL
) ;
3451 /* IBSS parameter set */
3452 // IBSS parameter set element id
3453 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_IBSS
;
3455 // IBSS parameter set length
3456 wd
->sta
.beaconFrameBody
[offset
++] = 2 ;
3458 // IBSS parameter set information
3459 wd
->sta
.beaconFrameBody
[offset
] = wd
->sta
.atimWindow
;
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
)) )
3466 /* ERP Information */
3469 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_ERP
;
3472 wd
->sta
.beaconFrameBody
[offset
++] = 1 ;
3475 wd
->sta
.beaconFrameBody
[offset
++] = wd
->erpElement
;
3477 /* Extended Supported Rates */
3478 if ( (rateSet
== ZM_RATE_SET_OFDM
)&&((wd
->gRate
& 0xff) == 0) )
3486 // Extended Supported Rates element id
3487 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_EXTENDED_RATE
;
3489 // Extended Supported Rates length
3490 lenOffset
= offset
++ ;
3492 // Extended Supported Rates information
3495 if ((wd
->gRate
& (0x1<<i
)) == (0x1<<i
))
3497 wd
->sta
.beaconFrameBody
[offset
++] =
3498 zg11gRateTbl
[i
]+((wd
->gRateBasic
& (0x1<<i
))<<(7-i
));
3503 // extended support rate length
3504 wd
->sta
.beaconFrameBody
[lenOffset
] = len
;
3509 /* RSN : important information influence the result of creating an IBSS network */
3510 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA2PSK
)
3512 u8_t frameType
= ZM_WLAN_FRAME_TYPE_AUTH
;
3521 /* Group Cipher Suite, default=TKIP */
3522 0x00, 0x0f, 0xac, 0x04,
3523 /* Pairwise Cipher Suite Count */
3525 /* Pairwise Cipher Suite, default=TKIP */
3526 0x00, 0x0f, 0xac, 0x02,
3527 /* Authentication and Key Management Suite Count */
3529 /* Authentication type, default=PSK */
3530 0x00, 0x0f, 0xac, 0x02,
3531 /* RSN capability */
3535 /* Overwrite Group Cipher Suite by AP's setting */
3536 zfMemoryCopy(rsn
+4, zgWpa2AesOui
, 4);
3538 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
3540 /* Overwrite Pairwise Cipher Suite by AES */
3541 zfMemoryCopy(rsn
+10, zgWpa2AesOui
, 4);
3545 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_RSN_IE
;
3548 wd
->sta
.beaconFrameBody
[offset
++] = rsn
[1] ;
3551 for(i
=0; i
<rsn
[1]; i
++)
3552 wd
->sta
.beaconFrameBody
[offset
++] = rsn
[i
+2] ;
3554 zfMemoryCopy(wd
->sta
.rsnIe
, rsn
, rsn
[1]+2);
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
);
3565 /* HT Capabilities Info */
3567 u8_t OUI
[3] = { 0x0 , 0x90 , 0x4C } ;
3569 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_WPA_IE
;
3571 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.HTCap
.Data
.Length
+ 4 ;
3573 for (i
= 0; i
< 3; i
++)
3575 wd
->sta
.beaconFrameBody
[offset
++] = OUI
[i
] ;
3578 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.HTCap
.Data
.ElementID
;
3580 for (i
= 0; i
< 26; i
++)
3582 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.HTCap
.Byte
[i
+2] ;
3586 /* Extended HT Capabilities Info */
3588 u8_t OUI
[3] = { 0x0 , 0x90 , 0x4C } ;
3590 wd
->sta
.beaconFrameBody
[offset
++] = ZM_WLAN_EID_WPA_IE
;
3592 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.ExtHTCap
.Data
.Length
+ 4 ;
3594 for (i
= 0; i
< 3; i
++)
3596 wd
->sta
.beaconFrameBody
[offset
++] = OUI
[i
] ;
3599 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.ExtHTCap
.Data
.ElementID
;
3601 for (i
= 0; i
< 22; i
++)
3603 wd
->sta
.beaconFrameBody
[offset
++] = wd
->sta
.ExtHTCap
.Byte
[i
+2] ;
3608 wd
->sta
.beaconFrameBodySize
= offset
;
3610 if (wd
->sta
.beaconFrameBodySize
> ZM_CACHED_FRAMEBODY_SIZE
)
3612 wd
->sta
.beaconFrameBodySize
= ZM_CACHED_FRAMEBODY_SIZE
;
3615 // 20070416 Let Create IBSS network could enter the zfwIbssPartnerNotify function
3616 // bssNotFound = FALSE ;
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
++)
3622 printk("%02x ", wd
->sta
.beaconFrameBody
[k
]) ;
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
);
3632 //zmw_enter_critical_section(dev);
3633 //wd->sta.ibssPartnerStatus = ZM_IBSS_PARTNER_LOST;
3634 //zmw_leave_critical_section(dev);
3638 wd
->sta
.ibssBssIsCreator
= 0;
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
);
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
);
3652 if (wd
->zfcbConnectNotify
!= NULL
)
3654 wd
->zfcbConnectNotify(dev
, ZM_STATUS_MEDIA_CONNECT
, wd
->sta
.bssid
);
3656 zfChangeAdapterState(dev
, ZM_STA_STATE_CONNECTED
);
3657 wd
->sta
.connPowerInHalfDbm
= zfHpGetTransmitPower(dev
);
3659 #ifdef ZM_ENABLE_IBSS_DELAYED_JOIN_INDICATION
3662 wd
->sta
.ibssDelayedInd
= 1;
3663 zfMemoryCopy((u8_t
*)&wd
->sta
.ibssDelayedIndEvent
, (u8_t
*)&event
, sizeof(struct zsPartnerNotifyEvent
));
3668 if (wd
->zfcbIbssPartnerNotify
!= NULL
)
3670 wd
->zfcbIbssPartnerNotify(dev
, 1, &event
);
3678 zfChangeAdapterState(dev
, ZM_STA_STATE_CONNECTING
);
3679 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_NOT_FOUND
, wd
->sta
.bssid
, 0);
3683 void zfStaProcessAtim(zdev_t
* dev
, zbuf_t
* buf
)
3685 zmw_get_wlan_dev(dev
);
3687 zm_debug_msg0("Receiving Atim window notification");
3689 wd
->sta
.recvAtim
= 1;
3692 static struct zsBssInfo
* zfInfraFindAPToConnect(zdev_t
* dev
,
3693 struct zsBssInfo
* candidateBss
)
3695 struct zsBssInfo
* pBssInfo
;
3696 struct zsBssInfo
* pNowBssInfo
=NULL
;
3698 u16_t ret
, apWepStatus
;
3702 zmw_get_wlan_dev(dev
);
3703 zmw_declare_for_critical_section();
3705 zmw_enter_critical_section(dev
);
3707 pBssInfo
= wd
->sta
.bssList
.head
;
3709 for(i
=0; i
<wd
->sta
.bssList
.bssCount
; i
++)
3711 if ( pBssInfo
->capability
[0] & ZM_BIT_4
)
3713 apWepStatus
= ZM_ENCRYPTION_WEP_ENABLED
;
3717 apWepStatus
= ZM_ENCRYPTION_WEP_DISABLED
;
3720 if ( ((zfMemoryIsEqual(&(pBssInfo
->ssid
[2]), wd
->sta
.ssid
,
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
) ))
3728 if ( wd
->sta
.ssidLen
== 0 )
3730 zm_debug_msg0("ANY BSS found");
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
) )
3738 zm_debug_msg0("Privacy policy is inconsistent");
3739 pBssInfo
= pBssInfo
->next
;
3743 /* for WPA negative test */
3744 if ( !zfCheckAuthentication(dev
, pBssInfo
) )
3746 pBssInfo
= pBssInfo
->next
;
3751 if (wd
->sta
.bDesiredBssid
== TRUE
)
3755 if (wd
->sta
.desiredBssid
[k
] != pBssInfo
->bssid
[k
])
3757 zm_msg0_mm(ZM_LV_1
, "desired bssid not matched 1");
3764 zm_msg0_mm(ZM_LV_1
, "desired bssid not matched 2");
3765 pBssInfo
= pBssInfo
->next
;
3770 /* Check support mode */
3771 if (pBssInfo
->frequency
> 3000) {
3772 if ( (pBssInfo
->EnableHT
== 1)
3773 || (pBssInfo
->apCap
& ZM_All11N_AP
) ) //11n AP
3775 channelFlags
= CHANNEL_A_HT
;
3776 if (pBssInfo
->enableHT40
== 1) {
3777 channelFlags
|= CHANNEL_HT40
;
3780 channelFlags
= CHANNEL_A
;
3783 if ( (pBssInfo
->EnableHT
== 1)
3784 || (pBssInfo
->apCap
& ZM_All11N_AP
) ) //11n AP
3786 channelFlags
= CHANNEL_G_HT
;
3787 if(pBssInfo
->enableHT40
== 1) {
3788 channelFlags
|= CHANNEL_HT40
;
3791 if (pBssInfo
->extSupportedRates
[1] == 0) {
3792 channelFlags
= CHANNEL_B
;
3794 channelFlags
= CHANNEL_G
;
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
)) )
3804 pBssInfo
= pBssInfo
->next
;
3808 /* Skip if AP in blocking list */
3809 ret
= zfStaIsApInBlockingList(dev
, pBssInfo
->bssid
);
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
;
3818 if ( pBssInfo
->capability
[0] & ZM_BIT_0
) // check if infra-BSS
3820 pNowBssInfo
= pBssInfo
;
3821 wd
->sta
.apWmeCapability
= pBssInfo
->wmeSupport
;
3828 pBssInfo
= pBssInfo
->next
;
3832 if (pNowBssInfo
!= NULL
)
3834 zfwMemoryCopy((void*)candidateBss
, (void*)pNowBssInfo
, sizeof(struct zsBssInfo
));
3835 pNowBssInfo
= candidateBss
;
3838 zmw_leave_critical_section(dev
);
3844 void zfInfraConnectNetwork(zdev_t
* dev
)
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;
3853 u8_t density
= ZM_MPDU_DENSITY_NONE
;
3855 zmw_get_wlan_dev(dev
);
3856 zmw_declare_for_critical_section();
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
);
3864 /* Set TxQs CWMIN, CWMAX, AIFS and TXO to WME STA default. */
3865 zfUpdateDefaultQosParameter(dev
, 0);
3867 zfStaRefreshBlockList(dev
, 0);
3869 /* change state to CONNECTING and stop the channel scanning */
3870 zfChangeAdapterState(dev
, ZM_STA_STATE_CONNECTING
);
3871 zfPowerSavingMgrWakeup(dev
);
3873 wd
->sta
.wmeConnected
= 0;
3874 wd
->sta
.psMgr
.tempWakeUp
= 0;
3875 wd
->sta
.qosInfo
= 0;
3876 zfQueueFlush(dev
, wd
->sta
.uapsdQ
);
3878 wd
->sta
.connectState
= ZM_STA_CONN_STATE_NONE
;
3880 //Reorder BssList by RSSI--CWYang(+)
3881 zfBssInfoReorderList(dev
);
3883 pNowBssInfo
= zfInfraFindAPToConnect(dev
, &candidateBss
);
3885 if (wd
->sta
.SWEncryptEnable
!= 0)
3887 if (wd
->sta
.bSafeMode
== 0)
3889 zfStaDisableSWEncryption(dev
);//Quickly reboot
3892 if ( pNowBssInfo
!= NULL
)
3894 //zm_assert(pNowBssInfo != NULL);
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;
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
);
3908 wd
->beaconInterval
= pBssInfo
->beaconInterval
[0] +
3909 (((u16_t
) pBssInfo
->beaconInterval
[1]) << 8);
3910 if (wd
->beaconInterval
== 0)
3912 wd
->beaconInterval
= 100;
3916 wd
->sta
.capability
[0] |= ZM_BIT_0
;
3918 wd
->sta
.capability
[0] &= ~ZM_BIT_1
;
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
)
3926 wd
->sta
.wmeEnabled
= 0; //Disable WMM in CENC
3928 cencSetCENCMode(dev
, NdisCENC_PSK
);
3929 wd
->sta
.wpaState
= ZM_STA_WPA_STATE_INIT
;
3931 if ( pBssInfo
->cencIe
[1] != 0 )
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);
3942 wd
->sta
.cencIe
[1] = 0;
3945 #endif //ZM_ENABLE_CENC
3946 if ( pBssInfo
->securityType
== ZM_SECURITY_TYPE_WPA
)
3948 wd
->sta
.wpaState
= ZM_STA_WPA_STATE_INIT
;
3950 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_TKIP
)
3952 wd
->sta
.encryMode
= ZM_TKIP
;
3954 /* Turn on software encryption/decryption for TKIP */
3955 if (wd
->sta
.EnableHT
== 1)
3957 zfStaEnableSWEncryption(dev
, (ZM_SW_TKIP_ENCRY_EN
|ZM_SW_TKIP_DECRY_EN
));
3960 /* Do not support TKIP in 11n mode */
3961 //wd->sta.EnableHT = 0;
3962 //pBssInfo->enableHT40 = 0;
3964 else if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
3966 wd
->sta
.encryMode
= ZM_AES
;
3968 /* If AP supports HT mode */
3969 if (wd
->sta
.EnableHT
)
3971 /* Set MPDU density to 8 us*/
3972 density
= ZM_MPDU_DENSITY_8US
;
3976 if ( pBssInfo
->wpaIe
[1] != 0 )
3978 zfMemoryCopy(wd
->sta
.wpaIe
, pBssInfo
->wpaIe
,
3979 pBssInfo
->wpaIe
[1]+2);
3983 wd
->sta
.wpaIe
[1] = 0;
3986 if ( pBssInfo
->rsnIe
[1] != 0 )
3988 zfMemoryCopy(wd
->sta
.rsnIe
, pBssInfo
->rsnIe
,
3989 pBssInfo
->rsnIe
[1]+2);
3993 wd
->sta
.rsnIe
[1] = 0;
3999 /* check preamble bit */
4000 wd
->preambleTypeInUsed
= wd
->preambleType
;
4001 if ( wd
->preambleTypeInUsed
== ZM_PREAMBLE_TYPE_AUTO
)
4003 if (pBssInfo
->capability
[0] & ZM_BIT_5
)
4005 wd
->preambleTypeInUsed
= ZM_PREAMBLE_TYPE_SHORT
;
4009 wd
->preambleTypeInUsed
= ZM_PREAMBLE_TYPE_LONG
;
4013 if (wd
->preambleTypeInUsed
== ZM_PREAMBLE_TYPE_LONG
)
4015 wd
->sta
.capability
[0] &= ~ZM_BIT_5
;
4019 wd
->sta
.capability
[0] |= ZM_BIT_5
;
4022 /* check 802.11n 40MHz Setting */
4023 if ((pBssInfo
->enableHT40
== 1) &&
4024 ((pBssInfo
->extChOffset
== 1) || (pBssInfo
->extChOffset
== 3)))
4026 wd
->BandWidth40
= pBssInfo
->enableHT40
;
4027 wd
->ExtOffset
= pBssInfo
->extChOffset
;
4031 wd
->BandWidth40
= 0;
4035 /* check 802.11H support bit */
4038 if ( pBssInfo
->athOwlAp
& ZM_BIT_0
)
4040 /* In this function, FW retry will be enable, ZM_MAC_REG_RETRY_MAX
4043 zfHpDisableHwRetry(dev
);
4044 wd
->sta
.athOwlAp
= 1;
4045 /* Set MPDU density to 8 us*/
4046 density
= ZM_MPDU_DENSITY_8US
;
4050 /* In this function, FW retry will be disable, ZM_MAC_REG_RETRY_MAX
4053 zfHpEnableHwRetry(dev
);
4054 wd
->sta
.athOwlAp
= 0;
4058 /* Set MPDU density */
4059 zfHpSetMPDUDensity(dev
, density
);
4061 /* check short slot time bit */
4062 if ( pBssInfo
->capability
[1] & ZM_BIT_2
)
4064 wd
->sta
.capability
[1] |= ZM_BIT_2
;
4067 if ( pBssInfo
->erp
& ZM_BIT_1
)
4069 //zm_debug_msg0("protection mode on");
4070 wd
->sta
.bProtectionMode
= TRUE
;
4071 zfHpSetSlotTime(dev
, 0);
4075 //zm_debug_msg0("protection mode off");
4076 wd
->sta
.bProtectionMode
= FALSE
;
4077 zfHpSetSlotTime(dev
, 1);
4080 if (pBssInfo
->marvelAp
== 1)
4082 wd
->sta
.enableDrvBA
= 0;
4084 * 8701 : NetGear 3500 (MARVELL)
4085 * Downlink issue : set slottime to 20.
4087 zfHpSetSlotTimeRegister(dev
, 0);
4091 wd
->sta
.enableDrvBA
= 1;
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.
4098 zfHpSetSlotTimeRegister(dev
, 1);
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
)
4105 wd
->sta
.beaconFrameBodySize
= ZM_CACHED_FRAMEBODY_SIZE
;
4109 wd
->sta
.beaconFrameBody
[k
] = pBssInfo
->timeStamp
[k
];
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
++)
4117 wd
->sta
.beaconFrameBody
[k
+12] = pBssInfo
->frameBody
[k
];
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 */
4126 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_WEP_DISABLED
)
4128 zm_debug_msg0("Adapter is no WEP, try to connect to WEP AP");
4132 /* Do not support WEP in 11n mode */
4133 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_WEP_ENABLED
)
4135 /* Turn on software encryption/decryption for WEP */
4136 if (wd
->sta
.EnableHT
== 1)
4138 zfStaEnableSWEncryption(dev
, (ZM_SW_WEP_ENCRY_EN
|ZM_SW_WEP_DECRY_EN
));
4141 //wd->sta.EnableHT = 0;
4142 //wd->BandWidth40 = 0;
4143 //wd->ExtOffset = 0;
4146 wd
->sta
.capability
[0] |= ZM_BIT_4
;
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;
4153 wd
->sta
.bIsSharedKey
= 1;
4155 else if ( wd
->sta
.authMode
!= ZM_AUTH_MODE_SHARED_KEY
)
4156 { /* open or auto */
4157 //zfStaStartConnect(dev, 0);
4158 wd
->sta
.bIsSharedKey
= 0;
4160 else if ( wd
->sta
.authMode
!= ZM_AUTH_MODE_OPEN
)
4162 //zfStaStartConnect(dev, 1) ;
4163 wd
->sta
.bIsSharedKey
= 1;
4168 if ( (pBssInfo
->securityType
== ZM_SECURITY_TYPE_WPA
)||
4169 (pBssInfo
->capability
[0] & ZM_BIT_4
) )
4171 wd
->sta
.capability
[0] |= ZM_BIT_4
;
4172 /* initialize WPA related parameters */
4176 wd
->sta
.capability
[0] &= (~ZM_BIT_4
);
4179 /* authentication with open system */
4180 //zfStaStartConnect(dev, 0);
4181 wd
->sta
.bIsSharedKey
= 0;
4184 /* Improve WEP/TKIP performance with HT AP, detail information please look bug#32495 */
4186 if ( (pBssInfo->broadcomHTAp == 1)
4187 && (wd->sta.SWEncryptEnable != 0) )
4189 zfHpSetTTSIFSTime(dev, 0xa);
4193 zfHpSetTTSIFSTime(dev, 0x8);
4199 zm_debug_msg0("Desired SSID not found");
4200 goto zlConnectFailed
;
4204 zfCoreSetFrequencyV2(dev
, wd
->frequency
, zfStaStartConnectCb
);
4208 zfStaConnectFail(dev
, ZM_STATUS_MEDIA_DISCONNECT_NOT_FOUND
, wd
->sta
.bssid
, 0);
4212 u8_t
zfCheckWPAAuth(zdev_t
* dev
, struct zsBssInfo
* pBssInfo
)
4217 u16_t encAlgoType
= 0;
4219 zmw_get_wlan_dev(dev
);
4221 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_TKIP
)
4223 encAlgoType
= ZM_TKIP
;
4225 else if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
4227 encAlgoType
= ZM_AES
;
4230 switch(wd
->sta
.authMode
)
4232 case ZM_AUTH_MODE_WPA
:
4233 case ZM_AUTH_MODE_WPAPSK
:
4234 if ( pBssInfo
->wpaIe
[1] == 0 )
4240 pmkCount
= pBssInfo
->wpaIe
[12];
4241 for(i
=0; i
< pmkCount
; i
++)
4243 if ( pBssInfo
->wpaIe
[17 + 4*i
] == encAlgoType
)
4253 case ZM_AUTH_MODE_WPA2
:
4254 case ZM_AUTH_MODE_WPA2PSK
:
4255 if ( pBssInfo
->rsnIe
[1] == 0 )
4261 pmkCount
= pBssInfo
->rsnIe
[8];
4262 for(i
=0; i
< pmkCount
; i
++)
4264 if ( pBssInfo
->rsnIe
[13 + 4*i
] == encAlgoType
)
4279 u8_t
zfCheckAuthentication(zdev_t
* dev
, struct zsBssInfo
* pBssInfo
)
4283 u16_t UnicastCipherNum
;
4285 zmw_get_wlan_dev(dev
);
4287 /* Connecting to ANY has been checked */
4288 if ( wd
->sta
.ssidLen
== 0 )
4294 switch(wd
->sta
.authMode
)
4295 //switch(wd->ws.authMode)//Quickly reboot
4297 case ZM_AUTH_MODE_WPA_AUTO
:
4298 case ZM_AUTH_MODE_WPAPSK_AUTO
:
4300 if(pBssInfo
->rsnIe
[1] != 0)
4302 UnicastCipherNum
= (pBssInfo
->rsnIe
[8]) +
4303 (pBssInfo
->rsnIe
[9] << 8);
4305 /* If there is only one unicast cipher */
4306 if (UnicastCipherNum
== 1)
4308 encAlgoType
= pBssInfo
->rsnIe
[13];
4309 //encAlgoType = pBssInfo->rsnIe[7];
4314 u16_t desiredCipher
= 0;
4315 u16_t IEOffSet
= 13;
4317 /* Enumerate all the supported unicast cipher */
4318 for (ii
= 0; ii
< UnicastCipherNum
; ii
++)
4320 if (pBssInfo
->rsnIe
[IEOffSet
+ii
*4] > desiredCipher
)
4322 desiredCipher
= pBssInfo
->rsnIe
[IEOffSet
+ii
*4];
4326 encAlgoType
= desiredCipher
;
4329 if ( encAlgoType
== 0x02 )
4331 wd
->sta
.wepStatus
= ZM_ENCRYPTION_TKIP
;
4333 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA_AUTO
)
4335 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA2
;
4337 else //ZM_AUTH_MODE_WPAPSK_AUTO
4339 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA2PSK
;
4342 else if ( encAlgoType
== 0x04 )
4344 wd
->sta
.wepStatus
= ZM_ENCRYPTION_AES
;
4346 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA_AUTO
)
4348 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA2
;
4350 else //ZM_AUTH_MODE_WPAPSK_AUTO
4352 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA2PSK
;
4360 else if(pBssInfo
->wpaIe
[1] != 0)
4362 UnicastCipherNum
= (pBssInfo
->wpaIe
[12]) +
4363 (pBssInfo
->wpaIe
[13] << 8);
4365 /* If there is only one unicast cipher */
4366 if (UnicastCipherNum
== 1)
4368 encAlgoType
= pBssInfo
->wpaIe
[17];
4369 //encAlgoType = pBssInfo->wpaIe[11];
4374 u16_t desiredCipher
= 0;
4375 u16_t IEOffSet
= 17;
4377 /* Enumerate all the supported unicast cipher */
4378 for (ii
= 0; ii
< UnicastCipherNum
; ii
++)
4380 if (pBssInfo
->wpaIe
[IEOffSet
+ii
*4] > desiredCipher
)
4382 desiredCipher
= pBssInfo
->wpaIe
[IEOffSet
+ii
*4];
4386 encAlgoType
= desiredCipher
;
4389 if ( encAlgoType
== 0x02 )
4391 wd
->sta
.wepStatus
= ZM_ENCRYPTION_TKIP
;
4393 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA_AUTO
)
4395 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA
;
4397 else //ZM_AUTH_MODE_WPAPSK_AUTO
4399 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPAPSK
;
4402 else if ( encAlgoType
== 0x04 )
4404 wd
->sta
.wepStatus
= ZM_ENCRYPTION_AES
;
4406 if ( wd
->sta
.authMode
== ZM_AUTH_MODE_WPA_AUTO
)
4408 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPA
;
4410 else //ZM_AUTH_MODE_WPAPSK_AUTO
4412 wd
->sta
.currentAuthMode
= ZM_AUTH_MODE_WPAPSK
;
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
:
4435 if ( pBssInfo
->securityType
!= ZM_SECURITY_TYPE_WPA
)
4440 ret
= zfCheckWPAAuth(dev
, pBssInfo
);
4444 case ZM_AUTH_MODE_OPEN
:
4445 case ZM_AUTH_MODE_SHARED_KEY
:
4446 case ZM_AUTH_MODE_AUTO
:
4448 if ( pBssInfo
->wscIe
[1] )
4450 // If the AP is a Jumpstart AP, it's ok!! Ray
4453 else if ( pBssInfo
->securityType
== ZM_SECURITY_TYPE_WPA
)
4467 u8_t
zfStaIsConnected(zdev_t
* dev
)
4469 zmw_get_wlan_dev(dev
);
4471 if ( wd
->sta
.adapterState
== ZM_STA_STATE_CONNECTED
)
4479 u8_t
zfStaIsConnecting(zdev_t
* dev
)
4481 zmw_get_wlan_dev(dev
);
4483 if ( wd
->sta
.adapterState
== ZM_STA_STATE_CONNECTING
)
4491 u8_t
zfStaIsDisconnect(zdev_t
* dev
)
4493 zmw_get_wlan_dev(dev
);
4495 if ( wd
->sta
.adapterState
== ZM_STA_STATE_DISCONNECT
)
4503 u8_t
zfChangeAdapterState(zdev_t
* dev
, u8_t newState
)
4507 zmw_get_wlan_dev(dev
);
4509 zmw_declare_for_critical_section();
4511 //if ( newState == wd->sta.adapterState )
4518 case ZM_STA_STATE_DISCONNECT
:
4519 zfResetSupportRate(dev
, ZM_DEFAULT_SUPPORT_RATE_DISCONNECT
);
4522 zfScanMgrScanStop(dev
, ZM_SCAN_MGR_SCAN_INTERNAL
);
4524 if ( wd
->sta
.bChannelScan
)
4526 /* stop the action of channel scanning */
4527 wd
->sta
.bChannelScan
= FALSE
;
4534 case ZM_STA_STATE_CONNECTING
:
4536 zfScanMgrScanStop(dev
, ZM_SCAN_MGR_SCAN_INTERNAL
);
4538 if ( wd
->sta
.bChannelScan
)
4540 /* stop the action of channel scanning */
4541 wd
->sta
.bChannelScan
= FALSE
;
4548 case ZM_STA_STATE_CONNECTED
:
4556 zmw_enter_critical_section(dev
);
4557 wd
->sta
.adapterState
= newState
;
4558 zmw_leave_critical_section(dev
);
4560 zm_debug_msg1("change adapter state = ", newState
);
4566 /************************************************************************/
4568 /* FUNCTION DESCRIPTION zfStaMmAddIeSsid */
4569 /* Add information element SSID to buffer. */
4572 /* dev : device pointer */
4573 /* buf : buffer to add information element */
4574 /* offset : add information element from this offset */
4577 /* buffer offset after adding information element */
4580 /* Ji-Huang Lee ZyDAS Technology Corporation 2005.11 */
4582 /************************************************************************/
4583 u16_t
zfStaAddIeSsid(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
4587 zmw_get_wlan_dev(dev
);
4590 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SSID
);
4592 /* Element Length */
4593 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ssidLen
);
4595 /* Information : SSID */
4596 for (i
=0; i
<wd
->sta
.ssidLen
; i
++)
4598 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ssid
[i
]);
4604 /************************************************************************/
4606 /* FUNCTION DESCRIPTION zfStaMmAddIeWpa */
4607 /* Add information element SSID to buffer. */
4610 /* dev : device pointer */
4611 /* buf : buffer to add information element */
4612 /* offset : add information element from this offset */
4615 /* buffer offset after adding information element */
4618 /* Ji-Huang Lee ZyDAS Technology Corporation 2006.01 */
4620 /************************************************************************/
4621 u16_t
zfStaAddIeWpaRsn(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t frameType
)
4630 0x00, 0x50, 0xf2, 0x01,
4633 /* Group Cipher Suite, default=TKIP */
4634 0x00, 0x50, 0xf2, 0x02,
4635 /* Pairwise Cipher Suite Count */
4637 /* Pairwise Cipher Suite, default=TKIP */
4638 0x00, 0x50, 0xf2, 0x02,
4639 /* Authentication and Key Management Suite Count */
4641 /* Authentication type, default=PSK */
4642 0x00, 0x50, 0xf2, 0x02,
4643 /* WPA capability */
4654 /* Group Cipher Suite, default=TKIP */
4655 0x00, 0x0f, 0xac, 0x02,
4656 /* Pairwise Cipher Suite Count */
4658 /* Pairwise Cipher Suite, default=TKIP */
4659 0x00, 0x0f, 0xac, 0x02,
4660 /* Authentication and Key Management Suite Count */
4662 /* Authentication type, default=PSK */
4663 0x00, 0x0f, 0xac, 0x02,
4664 /* RSN capability */
4668 zmw_get_wlan_dev(dev
);
4670 if ( wd
->sta
.currentAuthMode
== ZM_AUTH_MODE_WPAPSK
)
4672 /* Overwrite Group Cipher Suite by AP's setting */
4673 zfMemoryCopy(ssn
+8, wd
->sta
.wpaIe
+8, 4);
4675 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
4677 /* Overwrite Pairwise Cipher Suite by AES */
4678 zfMemoryCopy(ssn
+14, zgWpaAesOui
, 4);
4681 zfCopyToIntTxBuffer(dev
, buf
, ssn
, offset
, ssn
[1]+2);
4682 zfMemoryCopy(wd
->sta
.wpaIe
, ssn
, ssn
[1]+2);
4683 offset
+= (ssn
[1]+2);
4685 else if ( wd
->sta
.currentAuthMode
== ZM_AUTH_MODE_WPA
)
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);
4692 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
4694 /* Overwrite Pairwise Cipher Suite by AES */
4695 zfMemoryCopy(ssn
+14, zgWpaAesOui
, 4);
4698 zfCopyToIntTxBuffer(dev
, buf
, ssn
, offset
, ssn
[1]+2);
4699 zfMemoryCopy(wd
->sta
.wpaIe
, ssn
, ssn
[1]+2);
4700 offset
+= (ssn
[1]+2);
4702 else if ( wd
->sta
.currentAuthMode
== ZM_AUTH_MODE_WPA2PSK
)
4704 /* Overwrite Group Cipher Suite by AP's setting */
4705 zfMemoryCopy(rsn
+4, wd
->sta
.rsnIe
+4, 4);
4707 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
4709 /* Overwrite Pairwise Cipher Suite by AES */
4710 zfMemoryCopy(rsn
+10, zgWpa2AesOui
, 4);
4713 if ( frameType
== ZM_WLAN_FRAME_TYPE_REASOCREQ
)
4715 for(i
=0; i
<wd
->sta
.pmkidInfo
.bssidCount
; i
++)
4717 if ( zfMemoryIsEqual((u8_t
*) wd
->sta
.pmkidInfo
.bssidInfo
[i
].bssid
,
4718 (u8_t
*) wd
->sta
.bssid
, 6) )
4724 if ( i
< wd
->sta
.pmkidInfo
.bssidCount
)
4726 // Fill PMKID Count in RSN information element
4730 // Fill PMKID in RSN information element
4731 zfMemoryCopy(rsn
+24,
4732 wd
->sta
.pmkidInfo
.bssidInfo
[i
].pmkid
, 16);
4738 zfCopyToIntTxBuffer(dev
, buf
, rsn
, offset
, rsn
[1]+2);
4739 zfMemoryCopy(wd
->sta
.rsnIe
, rsn
, rsn
[1]+2);
4740 offset
+= (rsn
[1]+2);
4742 else if ( wd
->sta
.currentAuthMode
== ZM_AUTH_MODE_WPA2
)
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);
4749 if ( wd
->sta
.wepStatus
== ZM_ENCRYPTION_AES
)
4751 /* Overwrite Pairwise Cipher Suite by AES */
4752 zfMemoryCopy(rsn
+10, zgWpa2AesOui
, 4);
4755 if (( frameType
== ZM_WLAN_FRAME_TYPE_REASOCREQ
|| ( frameType
== ZM_WLAN_FRAME_TYPE_ASOCREQ
)))
4758 if (wd
->sta
.pmkidInfo
.bssidCount
!= 0) {
4759 // Fill PMKID Count in RSN information element
4763 * The caller is respnsible to give us the relevant PMKID.
4764 * We'll only accept 1 PMKID for now.
4766 for(i
=0; i
<wd
->sta
.pmkidInfo
.bssidCount
; i
++)
4768 if ( zfMemoryIsEqual((u8_t
*) wd
->sta
.pmkidInfo
.bssidInfo
[i
].bssid
, (u8_t
*) wd
->sta
.bssid
, 6) )
4770 zfMemoryCopy(rsn
+24, wd
->sta
.pmkidInfo
.bssidInfo
[i
].pmkid
, 16);
4779 zfCopyToIntTxBuffer(dev
, buf
, rsn
, offset
, rsn
[1]+2);
4780 zfMemoryCopy(wd
->sta
.rsnIe
, rsn
, rsn
[1]+2);
4781 offset
+= (rsn
[1]+2);
4787 /************************************************************************/
4789 /* FUNCTION DESCRIPTION zfStaAddIeIbss */
4790 /* Add information element IBSS parameter to buffer. */
4793 /* dev : device pointer */
4794 /* buf : buffer to add information element */
4795 /* offset : add information element from this offset */
4798 /* buffer offset after adding information element */
4801 /* Ji-Huang Lee ZyDAS Technology Corporation 2005.12 */
4803 /************************************************************************/
4804 u16_t
zfStaAddIeIbss(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
4806 zmw_get_wlan_dev(dev
);
4809 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_IBSS
);
4811 /* Element Length */
4812 zmw_tx_buf_writeb(dev
, buf
, offset
++, 2);
4815 zmw_tx_buf_writeh(dev
, buf
, offset
, wd
->sta
.atimWindow
);
4823 /************************************************************************/
4825 /* FUNCTION DESCRIPTION zfStaAddIeWmeInfo */
4826 /* Add WME Information Element to buffer. */
4829 /* dev : device pointer */
4830 /* buf : buffer to add information element */
4831 /* offset : add information element from this offset */
4834 /* buffer offset after adding information element */
4837 /* Stephen Chen ZyDAS Technology Corporation 2006.6 */
4839 /************************************************************************/
4840 u16_t
zfStaAddIeWmeInfo(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
, u8_t qosInfo
)
4843 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_WIFI_IE
);
4845 /* Element Length */
4846 zmw_tx_buf_writeb(dev
, buf
, offset
++, 7);
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);
4857 zmw_tx_buf_writeb(dev
, buf
, offset
++, qosInfo
);
4862 /************************************************************************/
4864 /* FUNCTION DESCRIPTION zfStaAddIePowerCap */
4865 /* Add information element Power capability to buffer. */
4868 /* dev : device pointer */
4869 /* buf : buffer to add information element */
4870 /* offset : add information element from this offset */
4873 /* buffer offset after adding information element */
4876 /* Sharon 2007.12 */
4878 /************************************************************************/
4879 u16_t
zfStaAddIePowerCap(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
4885 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_POWER_CAPABILITY
);
4887 /* Element Length */
4888 zmw_tx_buf_writeb(dev
, buf
, offset
++, 2);
4890 MinTxPower
= (u8_t
)(zfHpGetMinTxPower(dev
)/2);
4891 MaxTxPower
= (u8_t
)(zfHpGetMaxTxPower(dev
)/2);
4893 /* Min Transmit Power Cap */
4894 zmw_tx_buf_writeh(dev
, buf
, offset
++, MinTxPower
);
4896 /* Max Transmit Power Cap */
4897 zmw_tx_buf_writeh(dev
, buf
, offset
++, MaxTxPower
);
4901 /************************************************************************/
4903 /* FUNCTION DESCRIPTION zfStaAddIeSupportCh */
4904 /* Add information element supported channels to buffer. */
4907 /* dev : device pointer */
4908 /* buf : buffer to add information element */
4909 /* offset : add information element from this offset */
4912 /* buffer offset after adding information element */
4915 /* Sharon 2007.12 */
4917 /************************************************************************/
4918 u16_t
zfStaAddIeSupportCh(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
4922 u16_t count_24G
= 0;
4927 zmw_get_wlan_dev(dev
);
4929 zmw_declare_for_critical_section();
4930 zmw_enter_critical_section(dev
);
4932 for (i
= 0; i
< wd
->regulationTable
.allowChannelCnt
; i
++)
4934 if (wd
->regulationTable
.allowChannel
[i
].channel
< 3000)
4944 length
= (u8_t
)(count_5G
* 2 + 2); //5G fill by pair, 2,4G (continuous channels) fill 2 bytes
4947 zmw_tx_buf_writeb(dev
, buf
, offset
++, ZM_WLAN_EID_SUPPORTED_CHANNELS
);
4949 /* Element Length */
4950 zmw_tx_buf_writeb(dev
, buf
, offset
++, length
);
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
);
4958 for (i
= 0; i
< wd
->regulationTable
.allowChannelCnt
; i
++)
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);
4968 else if (wd
->regulationTable
.allowChannel
[i
].channel
>= 5000)
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);
4977 zmw_leave_critical_section(dev
);
4982 void zfStaStartConnectCb(zdev_t
* dev
)
4984 zmw_get_wlan_dev(dev
);
4986 zfStaStartConnect(dev
, wd
->sta
.bIsSharedKey
);
4989 void zfStaStartConnect(zdev_t
* dev
, u8_t bIsSharedKey
)
4994 zmw_get_wlan_dev(dev
);
4995 zmw_declare_for_critical_section();
4997 /* p1_low = algorithm number, p1_high = transaction sequence number */
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
;
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
;
5013 p1
= ZM_AUTH_ALGO_OPEN_SYSTEM
;
5019 zmw_enter_critical_section(dev
);
5020 wd
->sta
.connectTimer
= wd
->tick
;
5021 wd
->sta
.connectState
= newConnState
;
5022 zmw_leave_critical_section(dev
);
5024 /* send the 1st authentication frame */
5025 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_AUTH
, wd
->sta
.bssid
, p1
, p2
, 0);
5030 void zfSendNullData(zdev_t
* dev
, u8_t type
)
5033 //u16_t addrTblSize;
5034 //struct zsAddrTbl addrTbl;
5037 u16_t header
[(34+8+1)/2];
5038 u16_t bcastAddr
[3] = {0xffff,0xffff,0xffff};
5041 zmw_get_wlan_dev(dev
);
5043 buf
= zfwBufAllocate(dev
, 1024);
5046 zm_msg0_mm(ZM_LV_0
, "Alloc mm buf Fail!");
5050 zfwBufSetSize(dev
, buf
, 0);
5052 //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len);
5054 if ( wd
->wlanMode
== ZM_MODE_IBSS
)
5056 dstAddr
= bcastAddr
;
5060 dstAddr
= wd
->sta
.bssid
;
5063 if (wd
->sta
.wmeConnected
!= 0)
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);
5070 hlen
= zfTxGenMmHeader(dev
, ZM_WLAN_FRAME_TYPE_NULL
, dstAddr
, header
, 0, buf
, 0, 0);
5073 if (wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
5075 header
[4] |= 0x0100; //TODS bit
5080 header
[4] |= 0x1000;
5083 /* Get buffer DMA address */
5084 //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0)
5085 //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0)
5090 /*increase unicast frame counter*/
5091 wd
->commTally
.txUnicastFrm
++;
5093 err
= zfHpSend(dev
, header
, hlen
, NULL
, 0, NULL
, 0, buf
, 0,
5094 ZM_INTERNAL_ALLOC_BUF
, 0, 0xff);
5095 if (err
!= ZM_SUCCESS
)
5105 zfwBufFree(dev
, buf
, 0);
5110 void zfSendPSPoll(zdev_t
* dev
)
5113 //u16_t addrTblSize;
5114 //struct zsAddrTbl addrTbl;
5117 u16_t header
[(8+24+1)/2];
5119 zmw_get_wlan_dev(dev
);
5121 buf
= zfwBufAllocate(dev
, 1024);
5124 zm_msg0_mm(ZM_LV_0
, "Alloc mm buf Fail!");
5128 zfwBufSetSize(dev
, buf
, 0);
5130 //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len);
5132 zfTxGenMmHeader(dev
, ZM_WLAN_FRAME_TYPE_PSPOLL
, wd
->sta
.bssid
, header
, 0, buf
, 0, 0);
5135 header
[4] |= 0x1000;
5136 header
[5] = wd
->sta
.aid
| 0xc000; //Both bit-14 and bit-15 are 1
5139 /* Get buffer DMA address */
5140 //if ((addrTblSize = zfwBufMapDma(dev, buf, &addrTbl)) == 0)
5141 //if ((addrTblSize = zfwMapTxDma(dev, buf, &addrTbl)) == 0)
5146 err
= zfHpSend(dev
, header
, hlen
, NULL
, 0, NULL
, 0, buf
, 0,
5147 ZM_INTERNAL_ALLOC_BUF
, 0, 0xff);
5148 if (err
!= ZM_SUCCESS
)
5157 zfwBufFree(dev
, buf
, 0);
5162 void zfSendBA(zdev_t
* dev
, u16_t start_seq
, u8_t
*bitmap
)
5165 //u16_t addrTblSize;
5166 //struct zsAddrTbl addrTbl;
5169 u16_t header
[(8+24+1)/2];
5170 u16_t i
, offset
= 0;
5172 zmw_get_wlan_dev(dev
);
5174 buf
= zfwBufAllocate(dev
, 1024);
5177 zm_msg0_mm(ZM_LV_0
, "Alloc mm buf Fail!");
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
5184 //zm_msg2_mm(ZM_LV_2, "buf->len=", buf->len);
5186 zfTxGenMmHeader(dev
, ZM_WLAN_FRAME_TYPE_BA
, wd
->sta
.bssid
, header
, 0, buf
, 0, 0);
5188 header
[0] = 32; /* MAC header 16 + BA control 2 + BA info 10 + FCS 4*/
5189 header
[1] = 0x4; /* No ACK */
5191 /* send by OFDM 6M */
5192 header
[2] = (u16_t
)(zcRateToPhyCtrl
[4] & 0xffff);
5193 header
[3] = (u16_t
)(zcRateToPhyCtrl
[4]>>16) & 0xffff;
5195 hlen
= 16 + 8; /* MAC header 16 + control 8*/
5197 zmw_tx_buf_writeh(dev
, buf
, offset
, 0x05); /*compressed bitmap on*/
5199 zmw_tx_buf_writeh(dev
, buf
, offset
, start_seq
);
5202 for (i
=0; i
<8; i
++) {
5203 zmw_tx_buf_writeb(dev
, buf
, offset
, bitmap
[i
]);
5207 err
= zfHpSend(dev
, header
, hlen
, NULL
, 0, NULL
, 0, buf
, 0,
5208 ZM_INTERNAL_ALLOC_BUF
, 0, 0xff);
5209 if (err
!= ZM_SUCCESS
)
5218 zfwBufFree(dev
, buf
, 0);
5223 void zfStaGetTxRate(zdev_t
* dev
, u16_t
* macAddr
, u32_t
* phyCtrl
,
5224 u16_t
* rcProbingFlag
)
5228 zmw_get_wlan_dev(dev
);
5229 zmw_declare_for_critical_section();
5231 ZM_MAC_WORD_TO_BYTE(macAddr
, addr
);
5234 if ( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
5236 zmw_enter_critical_section(dev
);
5237 rate
= (u8_t
)zfRateCtrlGetTxRate(dev
, &wd
->sta
.oppositeInfo
[0].rcCell
, rcProbingFlag
);
5241 *phyCtrl
= zcRateToPhyCtrl
[rate
];
5242 zmw_leave_critical_section(dev
);
5246 zmw_enter_critical_section(dev
);
5247 for(i
=0; i
<wd
->sta
.oppositeCount
; i
++)
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.
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
];
5257 else if ( zfMemoryIsEqual(addr
, wd
->sta
.oppositeInfo
[i
].macAddr
, 6) )
5259 rate
= (u8_t
)zfRateCtrlGetTxRate(dev
, &wd
->sta
.oppositeInfo
[i
].rcCell
, rcProbingFlag
);
5260 *phyCtrl
= zcRateToPhyCtrl
[rate
];
5264 zmw_leave_critical_section(dev
);
5270 struct zsMicVar
* zfStaGetRxMicKey(zdev_t
* dev
, zbuf_t
* buf
)
5275 zmw_get_wlan_dev(dev
);
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
) )
5284 da0
= zmw_rx_buf_readb(dev
, buf
, ZM_WLAN_HEADER_A1_OFFSET
);
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*/
5289 keyIndex
= zmw_rx_buf_readb(dev
, buf
, ZM_WLAN_HEADER_IV_OFFSET
+3); /* normal Packet*/
5290 keyIndex
= (keyIndex
& 0xc0) >> 6;
5292 return (&wd
->sta
.rxMicKey
[keyIndex
]);
5295 struct zsMicVar
* zfStaGetTxMicKey(zdev_t
* dev
, zbuf_t
* buf
)
5297 zmw_get_wlan_dev(dev
);
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
) )
5307 return (&wd
->sta
.txMicKey
);
5310 u16_t
zfStaRxValidateFrame(zdev_t
* dev
, zbuf_t
* buf
)
5312 u8_t frameType
, frameCtrl
;
5318 zmw_get_wlan_dev(dev
);
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);
5324 if ( (!zfStaIsConnected(dev
))&&((frameType
& 0xf) == ZM_WLAN_DATA_FRAME
) )
5326 return ZM_ERR_DATA_BEFORE_CONNECTED
;
5330 if ( (zfStaIsConnected(dev
))&&((frameType
& 0xf) == ZM_WLAN_DATA_FRAME
) )
5333 if ( wd
->wlanMode
== ZM_MODE_INFRASTRUCTURE
)
5335 /* Big Endian and Little Endian Compatibility */
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) )
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.*/
5346 /* If unicast frame, send deauth to the transmitter */
5347 if (( da0
& 0x01 ) == 0)
5351 sa
[i
] = zmw_rx_buf_readh(dev
, buf
, ZM_WLAN_HEADER_A2_OFFSET
+(i
*2));
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);
5358 return ZM_ERR_DATA_BSSID_NOT_MATCHED
;
5361 else if ( wd
->wlanMode
== ZM_MODE_IBSS
)
5363 /* Big Endian and Little Endian Compatibility */
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) )
5371 return ZM_ERR_DATA_BSSID_NOT_MATCHED
;
5375 frameCtrl
= zmw_rx_buf_readb(dev
, buf
, 1);
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 */
5384 ret
= ZM_ERR_DATA_NOT_ENCRYPTED
;
5385 if ( wd
->sta
.pStaRxSecurityCheckCb
!= NULL
)
5387 ret
= wd
->sta
.pStaRxSecurityCheckCb(dev
, buf
);
5391 ret
= ZM_ERR_DATA_NOT_ENCRYPTED
;
5393 if (ret
== ZM_ERR_DATA_NOT_ENCRYPTED
)
5395 wd
->commTally
.swRxDropUnencryptedCount
++;
5399 if ( (wd
->sta
.wepStatus
!= ZM_ENCRYPTION_TKIP
)&&
5400 (wd
->sta
.wepStatus
!= ZM_ENCRYPTION_AES
) )
5402 return ZM_ERR_DATA_NOT_ENCRYPTED
;
5411 void zfStaMicFailureHandling(zdev_t
* dev
, zbuf_t
* buf
)
5416 zmw_get_wlan_dev(dev
);
5418 zmw_declare_for_critical_section();
5420 if ( wd
->sta
.wpaState
< ZM_STA_WPA_STATE_PK_OK
)
5425 zmw_enter_critical_section(dev
);
5427 wd
->sta
.cmMicFailureCount
++;
5429 if ( wd
->sta
.cmMicFailureCount
== 1 )
5431 zm_debug_msg0("get the first MIC failure");
5432 //zfTimerSchedule(dev, ZM_EVENT_CM_TIMER, ZM_TICK_CM_TIMEOUT);
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
);
5438 else if ( wd
->sta
.cmMicFailureCount
== 2 )
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);
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
);
5457 zmw_leave_critical_section(dev
);
5461 da0
= zmw_rx_buf_readb(dev
, buf
, ZM_WLAN_HEADER_A1_OFFSET
);
5464 if (wd
->zfcbMicFailureNotify
!= NULL
)
5466 wd
->zfcbMicFailureNotify(dev
, wd
->sta
.bssid
, ZM_MIC_GROUP_ERROR
);
5471 if (wd
->zfcbMicFailureNotify
!= NULL
)
5473 wd
->zfcbMicFailureNotify(dev
, wd
->sta
.bssid
, ZM_MIC_PAIRWISE_ERROR
);
5480 u8_t
zfStaBlockWlanScan(zdev_t
* dev
)
5484 zmw_get_wlan_dev(dev
);
5486 if ( wd
->sta
.bChannelScan
)
5494 void zfStaResetStatus(zdev_t
* dev
, u8_t bInit
)
5498 zmw_get_wlan_dev(dev
);
5500 zfHpDisableBeacon(dev
);
5503 wd
->sta
.capability
[0] = 0x01;
5504 wd
->sta
.capability
[1] = 0x00;
5506 if (wd
->sta
.DFSEnable
|| wd
->sta
.TPCEnable
)
5507 wd
->sta
.capability
[1] |= ZM_BIT_0
;
5509 /* release queued packets */
5510 for(i
=0; i
<wd
->sta
.ibssPSDataCount
; i
++)
5512 zfwBufFree(dev
, wd
->sta
.ibssPSDataQueue
[i
], 0);
5515 for(i
=0; i
<wd
->sta
.staPSDataCount
; i
++)
5517 zfwBufFree(dev
, wd
->sta
.staPSDataQueue
[i
], 0);
5520 wd
->sta
.ibssPSDataCount
= 0;
5521 wd
->sta
.staPSDataCount
= 0;
5522 zfZeroMemory((u8_t
*) &wd
->sta
.staPSList
, sizeof(struct zsStaPSList
));
5524 wd
->sta
.wmeConnected
= 0;
5525 wd
->sta
.psMgr
.tempWakeUp
= 0;
5526 wd
->sta
.qosInfo
= 0;
5527 zfQueueFlush(dev
, wd
->sta
.uapsdQ
);
5533 void zfStaIbssMonitoring(zdev_t
* dev
, u8_t reset
)
5536 u16_t oppositeCount
;
5537 struct zsPartnerNotifyEvent event
;
5539 zmw_get_wlan_dev(dev
);
5541 zmw_declare_for_critical_section();
5543 //zm_debug_msg1("zfStaIbssMonitoring %d", wd->sta.oppositeCount);
5545 zmw_enter_critical_section(dev
);
5547 if ( wd
->sta
.oppositeCount
== 0 )
5552 if ( wd
->sta
.bChannelScan
)
5557 oppositeCount
= wd
->sta
.oppositeCount
;
5559 for(i
=0; i
< ZM_MAX_OPPOSITE_COUNT
; i
++)
5561 if ( oppositeCount
== 0 )
5568 wd
->sta
.oppositeInfo
[i
].valid
= 0;
5571 if ( wd
->sta
.oppositeInfo
[i
].valid
== 0 )
5578 if ( wd
->sta
.oppositeInfo
[i
].aliveCounter
)
5580 zm_debug_msg1("Setting alive to ", wd
->sta
.oppositeInfo
[i
].aliveCounter
);
5582 zmw_leave_critical_section(dev
);
5584 if ( wd
->sta
.oppositeInfo
[i
].aliveCounter
!= ZM_IBSS_PEER_ALIVE_COUNTER
)
5586 zfSendMmFrame(dev
, ZM_WLAN_FRAME_TYPE_PROBEREQ
,
5587 (u16_t
*)wd
->sta
.oppositeInfo
[i
].macAddr
, 1, 0, 0);
5590 zmw_enter_critical_section(dev
);
5591 wd
->sta
.oppositeInfo
[i
].aliveCounter
--;
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);
5599 wd
->sta
.oppositeInfo
[i
].valid
= 0;
5600 wd
->sta
.oppositeCount
--;
5601 if (wd
->zfcbIbssPartnerNotify
!= NULL
)
5603 zmw_leave_critical_section(dev
);
5604 wd
->zfcbIbssPartnerNotify(dev
, 0, &event
);
5605 zmw_enter_critical_section(dev
);
5613 zfTimerSchedule(dev
, ZM_EVENT_IBSS_MONITOR
, ZM_TICK_IBSS_MONITOR
);
5616 zmw_leave_critical_section(dev
);
5619 void zfInitPartnerNotifyEvent(zdev_t
* dev
, zbuf_t
* buf
, struct zsPartnerNotifyEvent
*event
)
5623 zmw_get_wlan_dev(dev
);
5625 peerMacAddr
= (u16_t
*)event
->peerMacAddr
;
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);
5633 void zfStaInitOppositeInfo(zdev_t
* dev
)
5637 zmw_get_wlan_dev(dev
);
5639 for(i
=0; i
<ZM_MAX_OPPOSITE_COUNT
; i
++)
5641 wd
->sta
.oppositeInfo
[i
].valid
= 0;
5642 wd
->sta
.oppositeInfo
[i
].aliveCounter
= ZM_IBSS_PEER_ALIVE_COUNTER
;
5645 #ifdef ZM_ENABLE_CENC
5646 u16_t
zfStaAddIeCenc(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
5648 zmw_get_wlan_dev(dev
);
5650 if (wd
->sta
.cencIe
[1] != 0)
5652 zfCopyToIntTxBuffer(dev
, buf
, wd
->sta
.cencIe
, offset
, wd
->sta
.cencIe
[1]+2);
5653 offset
+= (wd
->sta
.cencIe
[1]+2);
5657 #endif //ZM_ENABLE_CENC
5658 u16_t
zfStaProcessAction(zdev_t
* dev
, zbuf_t
* buf
)
5660 u8_t category
, actionDetails
;
5661 zmw_get_wlan_dev(dev
);
5663 category
= zmw_rx_buf_readb(dev
, buf
, 24);
5664 actionDetails
= zmw_rx_buf_readb(dev
, buf
, 25);
5667 case 0: //Spectrum Management
5668 switch(actionDetails
)
5670 case 0: //Measurement Request
5672 case 1: //Measurement Report
5673 //ProcessActionSpectrumFrame_MeasurementReport(Adapter,pActionBody+3);
5675 case 2: //TPC request
5676 //if (wd->sta.TPCEnable)
5677 // zfStaUpdateDot11HTPC(dev, buf);
5679 case 3: //TPC report
5680 //if (wd->sta.TPCEnable)
5681 // zfStaUpdateDot11HTPC(dev, buf);
5683 case 4: //Channel Switch Announcement
5684 if (wd
->sta
.DFSEnable
)
5685 zfStaUpdateDot11HDFS(dev
, buf
);
5688 zm_debug_msg1("Action Frame contain not support action field ", actionDetails
);
5692 case ZM_WLAN_BLOCK_ACK_ACTION_FRAME
:
5693 zfAggBlockAckActionFrame(dev
, buf
);
5695 case 17: //Qos Management
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
)
5706 zmw_get_wlan_dev(dev
);
5708 zmw_declare_for_critical_section();
5710 zmw_enter_critical_section(dev
);
5711 wd
->tickIbssSendBeacon
++; // Increase 1 per 10ms .
5712 zmw_leave_critical_section(dev
);
5714 if ( wd
->tickIbssSendBeacon
== 40 )
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
);
5724 struct zsTkipSeed
* zfStaGetRxSeed(zdev_t
* dev
, zbuf_t
* buf
)
5729 zmw_get_wlan_dev(dev
);
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
) )
5738 da0
= zmw_rx_buf_readb(dev
, buf
, ZM_WLAN_HEADER_A1_OFFSET
);
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*/
5743 keyIndex
= zmw_rx_buf_readb(dev
, buf
, ZM_WLAN_HEADER_IV_OFFSET
+3); /* normal Packet*/
5744 keyIndex
= (keyIndex
& 0xc0) >> 6;
5746 return (&wd
->sta
.rxSeed
[keyIndex
]);
5749 void zfStaEnableSWEncryption(zdev_t
*dev
, u8_t value
)
5751 zmw_get_wlan_dev(dev
);
5753 wd
->sta
.SWEncryptEnable
= value
;
5754 zfHpSWDecrypt(dev
, 1);
5755 zfHpSWEncrypt(dev
, 1);
5758 void zfStaDisableSWEncryption(zdev_t
*dev
)
5760 zmw_get_wlan_dev(dev
);
5762 wd
->sta
.SWEncryptEnable
= 0;
5763 zfHpSWDecrypt(dev
, 0);
5764 zfHpSWEncrypt(dev
, 0);
5767 u16_t
zfComputeBssInfoWeightValue(zdev_t
*dev
, u8_t isBMode
, u8_t isHT
, u8_t isHT40
, u8_t signalStrength
)
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;
5778 return (signalStrength
+ weightOfB
); // pure b mode , do not add the weight value for this AP !
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
;
5786 return (signalStrength
+ weightOfAGUpThr
);
5788 else if( isHT
== 1 && isHT40
== 0 )
5789 { // 80211n mode use 20MHz
5790 if( signalStrength
< 23 ) // -72 dBm
5791 return (signalStrength
+ weightOfN20BelowThr
);
5793 return (signalStrength
+ weightOfN20UpThr
);
5795 else // isHT == 1 && isHT40 == 1
5796 { // 80211n mode use 40MHz
5797 if( signalStrength
< 16 ) // -79 dBm
5798 return (signalStrength
+ weightOfN40BelowThr
);
5800 return (signalStrength
+ weightOfN40UpThr
);
5805 u16_t
zfStaAddIbssAdditionalIE(zdev_t
* dev
, zbuf_t
* buf
, u16_t offset
)
5809 zmw_get_wlan_dev(dev
);
5811 for (i
=0; i
<wd
->sta
.ibssAdditionalIESize
; i
++)
5813 zmw_tx_buf_writeb(dev
, buf
, offset
++, wd
->sta
.ibssAdditionalIE
[i
]);