1/*
2 * siteMgr.c
3 *
4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in
15 *    the documentation and/or other materials provided with the
16 *    distribution.
17 *  * Neither the name Texas Instruments nor the names of its
18 *    contributors may be used to endorse or promote products derived
19 *    from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file siteMgr.c
35 *  \brief Site Manager implementation
36 *
37 *  \see siteMgr.h
38 */
39
40/****************************************************************************/
41/*                                                                          */
42/*      MODULE: siteMgr.c                                                   */
43/*    PURPOSE:  Site Manager implementation                                 */
44/*                                                                          */
45/***************************************************************************/
46
47#define __FILE_ID__  FILE_ID_85
48#include "tidef.h"
49#include "report.h"
50#include "osApi.h"
51#include "siteMgrApi.h"
52#include "siteHash.h"
53#include "smeApi.h"
54#include "rate.h"
55#include "connApi.h"
56#include "mlmeSm.h"
57#include "sme.h"
58#include "DataCtrl_Api.h"
59#include "regulatoryDomainApi.h"
60#include "rsnApi.h"
61#include "measurementMgrApi.h"
62#include "qosMngr_API.h"
63#include "PowerMgr_API.h"
64#include "EvHandler.h"
65#include "TI_IPC_Api.h"
66#include "MacServices_api.h"
67#include "apConn.h"
68#include "currBss.h"
69#include "PowerMgr.h"
70#include "TWDriver.h"
71#include "admCtrl.h"
72#include "DrvMainModules.h"
73#include "StaCap.h"
74#include "freq.h"
75#include "currBssApi.h"
76#include "CmdBld.h"
77#ifdef XCC_MODULE_INCLUDED
78#include "XCCMngr.h"
79#endif
80
81/* definitions */
82
83#define JOIN_RATE_MASK_1M   0x01
84#define JOIN_RATE_MASK_2M   0x02
85#define JOIN_RATE_MASK_5_5M 0x04
86#define JOIN_RATE_MASK_11M  0x08
87#define JOIN_RATE_MASK_22M  0x10
88
89
90#define SITE_MGR_INIT_BIT           1
91#define TIMER_INIT_BIT              2
92#define DESIRED_PARAMS_INIT_BIT     3
93#define MGMT_PARAMS_INIT_BIT        4
94
95#define BUILT_IN_TEST_PERIOD 500
96
97#define KEEP_ALIVE_SEND_NULL_DATA_PERIOD  10000
98
99/* Reconfig constants */
100#define SCAN_FAIL_THRESHOLD_FOR_RECONFIG        4  /* After 4 times we reset the 580 register and still no AP found - make recovery */
101#define SCAN_FAIL_THRESHOLD_FOR_RESET_REG_580   90  /* After 90 times (45 seconds) and  no AP found - reset the 580 register */
102#define SCAN_FAIL_RECONFIG_ENABLED              TI_TRUE
103#define SCAN_FAIL_RECONFIG_DISABLED             TI_FALSE
104
105#define TRIGGER_HIGH_TX_PW_PACING 10
106#define TRIGGER_LOW_TX_PW_PACING 10
107#define TRIGGER_HIGH_TX_PW_HYSTERESIS 3
108#define TRIGGER_LOW_TX_PW_HYSTERESIS 3
109
110/* Local Macros */
111
112#define UPDATE_BEACON_INTERVAL(pSite, pFrameInfo)       pSite->beaconInterval = pFrameInfo->content.iePacket.beaconInerval
113
114#define UPDATE_CAPABILITIES(pSite, pFrameInfo)          pSite->capabilities = pFrameInfo->content.iePacket.capabilities
115
116#define UPDATE_PRIVACY(pSite, pFrameInfo)               pSite->privacy = ((pFrameInfo->content.iePacket.capabilities >> CAP_PRIVACY_SHIFT) & CAP_PRIVACY_MASK) ? TI_TRUE : TI_FALSE
117
118#define UPDATE_AGILITY(pSite, pFrameInfo)               pSite->agility = ((pFrameInfo->content.iePacket.capabilities >> CAP_AGILE_SHIFT) & CAP_AGILE_MASK) ? TI_TRUE : TI_FALSE
119
120#define UPDATE_SLOT_TIME(pSite, pFrameInfo)             pSite->newSlotTime = ((pFrameInfo->content.iePacket.capabilities >> CAP_SLOT_TIME_SHIFT) & CAP_SLOT_TIME_MASK) ? PHY_SLOT_TIME_SHORT : PHY_SLOT_TIME_LONG
121#define UPDATE_PROTECTION(pSite, pFrameInfo)            pSite->useProtection = (pFrameInfo->content.iePacket.useProtection)
122
123#define UPDATE_SSID(pSite, pFrameInfo)                  if (pFrameInfo->content.iePacket.pSsid != NULL) { \
124                                                        pSite->ssid.len = pFrameInfo->content.iePacket.pSsid->hdr[1]; \
125                                                        os_memoryCopy(pSiteMgr->hOs, \
126                                                        (void *)pSite->ssid.str, \
127                                                        (void *)pFrameInfo->content.iePacket.pSsid->serviceSetId, \
128                                                        pFrameInfo->content.iePacket.pSsid->hdr[1]) ;}
129
130#define UPDATE_CHANNEL(pSite, pFrameInfo, rxChannel)    if (pFrameInfo->content.iePacket.pDSParamsSet == NULL) \
131                                                            pSite->channel = rxChannel; \
132                                                        else \
133                                                            pSite->channel = pFrameInfo->content.iePacket.pDSParamsSet->currChannel;
134
135
136
137#define UPDATE_DTIM_PERIOD(pSite, pFrameInfo)           if (pFrameInfo->content.iePacket.pTIM != NULL) \
138                                                        pSite->dtimPeriod = pFrameInfo->content.iePacket.pTIM->dtimPeriod
139
140#define UPDATE_ATIM_WINDOW(pSite, pFrameInfo)           if (pFrameInfo->content.iePacket.pIBSSParamsSet != NULL) \
141                                                        pSite->atimWindow = pFrameInfo->content.iePacket.pIBSSParamsSet->atimWindow
142
143#define UPDATE_BEACON_AP_TX_POWER(pSite, pFrameInfo)    if (pFrameInfo->content.iePacket.TPCReport != NULL) \
144                                                        pSite->APTxPower = pFrameInfo->content.iePacket.TPCReport->transmitPower
145
146#define UPDATE_PROBE_AP_TX_POWER(pSite, pFrameInfo)     if (pFrameInfo->content.iePacket.TPCReport != NULL) \
147                                                        pSite->APTxPower = pFrameInfo->content.iePacket.TPCReport->transmitPower
148
149#define UPDATE_BSS_TYPE(pSite, pFrameInfo)              pSite->bssType = ((pFrameInfo->content.iePacket.capabilities >> CAP_ESS_SHIFT) & CAP_ESS_MASK) ? BSS_INFRASTRUCTURE : BSS_INDEPENDENT
150
151#define UPDATE_LOCAL_TIME_STAMP(pSiteMgr, pSite, pFrameInfo)        pSite->localTimeStamp = os_timeStampMs(pSiteMgr->hOs)
152
153/* Updated from beacons */
154#define UPDATE_BEACON_MODULATION(pSite, pFrameInfo)     pSite->beaconModulation = ((pFrameInfo->content.iePacket.capabilities >> CAP_PBCC_SHIFT) & CAP_PBCC_MASK) ? DRV_MODULATION_PBCC : DRV_MODULATION_CCK
155
156/* Updated from probes */
157#define UPDATE_PROBE_MODULATION(pSite, pFrameInfo)          pSite->probeModulation = ((pFrameInfo->content.iePacket.capabilities >> CAP_PBCC_SHIFT) & CAP_PBCC_MASK) ? DRV_MODULATION_PBCC : DRV_MODULATION_CCK
158
159#define UPDATE_BEACON_RECV(pSite)                       pSite->beaconRecv = TI_TRUE
160
161#define UPDATE_PROBE_RECV(pSite)                        pSite->probeRecv = TI_TRUE
162
163
164#define UPDATE_RSN_IE(pSite, pRsnIe, rsnIeLen)              if (pRsnIe != NULL) { \
165                                                            TI_UINT8 length=0, index=0;\
166                                                            pSite->rsnIeLen = rsnIeLen;\
167                                                            while ((length < pSite->rsnIeLen) && (index<MAX_RSN_IE)){\
168                                                                pSite->pRsnIe[index].hdr[0] = pRsnIe->hdr[0];\
169                                                                pSite->pRsnIe[index].hdr[1] = pRsnIe->hdr[1];\
170                                                                os_memoryCopy(pSiteMgr->hOs, (void *)pSite->pRsnIe[index].rsnIeData, (void *)pRsnIe->rsnIeData, pRsnIe->hdr[1]);\
171                                                                length += (pRsnIe->hdr[1]+2); \
172                                                                pRsnIe += 1; \
173                                                                index++;}\
174                                                        } \
175                                                        else {pSite->rsnIeLen = 0;}
176
177#define UPDATE_BEACON_TIMESTAMP(pSiteMgr, pSite, pFrameInfo)    os_memoryCopy(pSiteMgr->hOs, pSite->tsfTimeStamp, (void *)pFrameInfo->content.iePacket.timestamp, TIME_STAMP_LEN)
178
179
180
181
182/* Local  functions definitions*/
183
184static void update_apsd(siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
185
186static void release_module(siteMgr_t *pSiteMgr, TI_UINT32 initVec);
187
188static void updateSiteInfo(siteMgr_t *pSiteMgr, mlmeFrameInfo_t *pFrameInfo, siteEntry_t    *pSite, TI_UINT8 rxChannel);
189
190static void updateRates(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
191
192static void updateBeaconQosParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
193
194static void updateProbeQosParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
195
196static void siteMgr_UpdatHtParams (siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
197
198static void updateWSCParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
199
200static void updatePreamble(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo);
201
202static void getPrimarySiteDesc(siteMgr_t *pSiteMgr, OS_802_11_BSSID *pPrimarySiteDesc, TI_BOOL supplyExtendedInfo);
203
204static TI_STATUS getPrimaryBssid(siteMgr_t *pSiteMgr, OS_802_11_BSSID_EX *primaryBssid, TI_UINT32 *pLength);
205
206static ERate translateRateMaskToValue(siteMgr_t *pSiteMgr, TI_UINT32 rateMask);
207
208static void getSupportedRateSet(siteMgr_t *pSiteMgr, TRates *pRatesSet);
209
210static TI_STATUS setSupportedRateSet(siteMgr_t *pSiteMgr, TRates *pRatesSet);
211
212static void siteMgr_externalConfigurationParametersSet(TI_HANDLE hSiteMgr);
213
214static int parseWscMethodFromIE (siteMgr_t *pSiteMgr, dot11_WSC_t *WSCParams, TIWLN_SIMPLE_CONFIG_MODE *pSelectedMethod);
215
216static TI_UINT16 incrementTxSessionCount(siteMgr_t *pSiteMgr);
217static void siteMgr_TxPowerAdaptation(TI_HANDLE hSiteMgr, RssiEventDir_e highLowEdge);
218static void siteMgr_TxPowerLowThreshold(TI_HANDLE hSiteMgr, TI_UINT8 *data, TI_UINT8 dataLength);
219static void siteMgr_TxPowerHighThreshold(TI_HANDLE hSiteMgr, TI_UINT8 *data, TI_UINT8 dataLength);
220
221
222/************************************************************************
223*                        siteMgr_setTemporaryTxPower                    *
224*************************************************************************
225DESCRIPTION:	This function is used to start the Tx Power Control adjust mechanism
226				in regulatoryDomain.
227
228INPUT:      bActivateTempFix             -   Whether the power should be adjusted
229************************************************************************/
230void siteMgr_setTemporaryTxPower(siteMgr_t* pSiteMgr, TI_BOOL bActivateTempFix)
231{
232	paramInfo_t         param;
233
234TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_setTemporaryTxPower is =  \n");
235
236	/* Set the temporary Power Level via the Regulatory Domain*/
237	param.paramType = REGULATORY_DOMAIN_TEMPORARY_TX_ATTENUATION_PARAM;
238	param.content.bActivateTempPowerFix = bActivateTempFix;
239	regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&param);
240}
241
242/* Interface functions Implementation */
243
244
245/*static void UPDATE_RSN_IE (siteMgr_t* pSiteMgr, siteEntry_t   *pSite, dot11_RSN_t *pRsnIe, TI_UINT8 rsnIeLen)
246{
247
248    if (pRsnIe != NULL) {
249            TI_UINT8 length=0, index=0;
250            pSite->rsnIeLen = rsnIeLen;
251            while ((length < pSite->rsnIeLen) && (index<MAX_RSN_IE)){
252                pSite->pRsnIe[index].hdr = pRsnIe->hdr;
253                os_memoryCopy(pSiteMgr->hOs, pSite->pRsnIe[index].rsnIeData, pRsnIe->rsnIeData, pRsnIe->hdr[1]);
254                length += (pRsnIe->hdr[1] + 2);
255                pRsnIe += 1;
256                index++;}
257        }
258        else {pSite->rsnIeLen = 0;}
259}*/
260/************************************************************************
261 *                        siteMgr_create                                *
262 ************************************************************************
263DESCRIPTION: Site manager module creation function, called by the config mgr in creation phase
264                performs the following:
265                -   Allocate the site manager handle
266                -   Allocate the desired & mgmt params structure
267
268INPUT:      hOs             -   Handle to OS
269
270
271OUTPUT:
272
273
274RETURN:     Handle to the site manager module on success, NULL otherwise
275************************************************************************/
276TI_HANDLE siteMgr_create(TI_HANDLE hOs)
277{
278    siteMgr_t       *pSiteMgr;
279    TI_UINT32          initVec;
280
281    initVec = 0;
282
283    pSiteMgr = os_memoryAlloc(hOs, sizeof(siteMgr_t));
284    if (pSiteMgr == NULL)
285        return NULL;
286
287    os_memoryZero(hOs, pSiteMgr, sizeof(siteMgr_t));
288
289    initVec |= (1 << SITE_MGR_INIT_BIT);
290
291    pSiteMgr->pDesiredParams = os_memoryAlloc(hOs, sizeof(siteMgrInitParams_t));
292    if (pSiteMgr->pDesiredParams == NULL)
293    {
294        release_module(pSiteMgr, initVec);
295        return NULL;
296    }
297
298    initVec |= (1 << DESIRED_PARAMS_INIT_BIT);
299
300    pSiteMgr->pSitesMgmtParams = os_memoryAlloc(hOs, sizeof(sitesMgmtParams_t));
301    if (pSiteMgr->pSitesMgmtParams == NULL)
302    {
303        release_module(pSiteMgr, initVec);
304        return NULL;
305    }
306
307    initVec |= (1 << MGMT_PARAMS_INIT_BIT);
308
309    pSiteMgr->hOs = hOs;
310
311    return(pSiteMgr);
312}
313
314
315
316/************************************************************************
317 *                        siteMgr_init                                  *
318 ************************************************************************
319DESCRIPTION: Module init function, called by the DrvMain in init phase
320                performs the following:
321                -   Reset & initiailzes local variables
322                -   Init the handles to be used by the module
323
324INPUT:      pStadHandles -  List of handles to be used by the module
325
326OUTPUT:
327
328RETURN:     void
329************************************************************************/
330void siteMgr_init (TStadHandlesList *pStadHandles)
331{
332    siteMgr_t *pSiteMgr = (siteMgr_t *)(pStadHandles->hSiteMgr);
333
334    /* Init handles */
335    pSiteMgr->hConn                 = pStadHandles->hConn;
336    pSiteMgr->hSmeSm                = pStadHandles->hSme;
337    pSiteMgr->hTWD                  = pStadHandles->hTWD;
338    pSiteMgr->hCtrlData             = pStadHandles->hCtrlData;
339    pSiteMgr->hRxData               = pStadHandles->hRxData;
340    pSiteMgr->hTxCtrl               = pStadHandles->hTxCtrl;
341    pSiteMgr->hRsn                  = pStadHandles->hRsn;
342    pSiteMgr->hAuth                 = pStadHandles->hAuth;
343    pSiteMgr->hAssoc                = pStadHandles->hAssoc;
344    pSiteMgr->hRegulatoryDomain     = pStadHandles->hRegulatoryDomain;
345    pSiteMgr->hMeasurementMgr       = pStadHandles->hMeasurementMgr;
346    pSiteMgr->hReport               = pStadHandles->hReport;
347    pSiteMgr->hOs                   = pStadHandles->hOs;
348    pSiteMgr->hMlmeSm               = pStadHandles->hMlmeSm;
349    pSiteMgr->hAssoc                = pStadHandles->hAssoc;
350    pSiteMgr->hReport               = pStadHandles->hReport;
351    pSiteMgr->hXCCMngr              = pStadHandles->hXCCMngr;
352    pSiteMgr->hApConn               = pStadHandles->hAPConnection;
353    pSiteMgr->hCurrBss              = pStadHandles->hCurrBss;
354    pSiteMgr->hQosMngr              = pStadHandles->hQosMngr;
355    pSiteMgr->hPowerMgr             = pStadHandles->hPowerMgr;
356    pSiteMgr->hScr                  = pStadHandles->hSCR;
357    pSiteMgr->hEvHandler            = pStadHandles->hEvHandler;
358    pSiteMgr->hStaCap               = pStadHandles->hStaCap;
359}
360
361
362TI_STATUS siteMgr_SetDefaults (TI_HANDLE                hSiteMgr,
363                               siteMgrInitParams_t     *pSiteMgrInitParams)
364{
365    siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
366    TI_UINT32       timestamp;
367    ESlotTime       slotTime;
368    TMacAddr        saBssid;
369    TI_STATUS       status;
370    RssiSnrTriggerCfg_t tTriggerCfg;
371
372    pSiteMgr->siteMgrTxPowerCheckTime   = 0;
373    pSiteMgr->siteMgrWSCCurrMode        = TIWLN_SIMPLE_CONFIG_OFF;
374    pSiteMgr->includeWSCinProbeReq      = pSiteMgrInitParams->includeWSCinProbeReq;
375
376    /* Init desired parameters */
377    os_memoryCopy(pSiteMgr->hOs, pSiteMgr->pDesiredParams, pSiteMgrInitParams, sizeof(siteMgrInitParams_t));
378
379    /* Init Beacon Filter Desired State */
380    pSiteMgr->beaconFilterParams.desiredState = pSiteMgrInitParams->beaconFilterParams.desiredState;
381    /* Init Beacon Filter numOfStored parameter */
382    pSiteMgr->beaconFilterParams.numOfStored = pSiteMgrInitParams->beaconFilterParams.numOfStored;
383
384    /* Init management params */
385    pSiteMgr->pSitesMgmtParams->dot11A_sitesTables.maxNumOfSites = MAX_SITES_A_BAND;
386    siteMgr_resetSiteTable(pSiteMgr,(siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables);
387    pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables.maxNumOfSites = MAX_SITES_BG_BAND;
388    siteMgr_resetSiteTable(pSiteMgr,&pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables);
389
390    /* calculate random BSSID for usage in IBSS */
391    timestamp = os_timeStampMs(pSiteMgr->hOs);
392    os_memoryCopy(pSiteMgr->hOs, (void *)&(pSiteMgr->ibssBssid[0]), &timestamp, sizeof(TI_UINT32));
393
394    timestamp = os_timeStampMs(pSiteMgr->hOs);
395    os_memoryCopy(pSiteMgr->hOs, (void *)&(pSiteMgr->ibssBssid[2]), &timestamp, sizeof(TI_UINT32));
396
397    /* Get the Source MAC address in order to use it for AD-Hoc BSSID, solving Conexant ST issue for WiFi test */
398    status = ctrlData_getParamBssid(pSiteMgr->hCtrlData, CTRL_DATA_MAC_ADDRESS, saBssid);
399    if (status != TI_OK)
400    {
401        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE ,"\n ERROR !!! : siteMgr_config - Error in getting MAC address\n" );
402        WLAN_OS_REPORT(("\n ERROR !!! : siteMgr_config - Error in getting MAC address\n" ));
403        return TI_NOK;
404    }
405    pSiteMgr->ibssBssid[0] = 0x02;
406    pSiteMgr->ibssBssid[1] = saBssid[1];
407    pSiteMgr->ibssBssid[2] = saBssid[2];
408
409    pSiteMgr->pDesiredParams->siteMgrSupportedBand = RADIO_BAND_DUAL;
410
411    pSiteMgr->beaconSentCount = 0;
412    pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow = 0;
413	pSiteMgr->txSessionCount = MIN_TX_SESSION_COUNT;
414
415    if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)
416    {
417       if(pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_DUAL)
418       {
419           pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
420           pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
421           slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
422           pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
423       }
424       else if(pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_2_4_GHZ)
425       {
426           pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode = DOT11_G_MODE;
427           pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
428           pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
429           slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
430           pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
431       }
432       else
433       {
434           pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode = DOT11_A_MODE;
435           pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
436           pSiteMgr->radioBand = RADIO_BAND_5_0_GHZ;
437           slotTime = PHY_SLOT_TIME_SHORT;
438           pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
439       }
440    }
441    else if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_G_MODE)
442    {
443        slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
444        pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
445        if((pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_DUAL) ||
446           (pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_2_4_GHZ))
447        {
448            pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
449            pSiteMgr->siteMgrOperationalMode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
450
451        }
452        else
453        {   TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE ,"\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n");
454            WLAN_OS_REPORT(("\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n"));
455            return TI_NOK;
456        }
457    }
458    else if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_B_MODE)
459    {
460        slotTime = PHY_SLOT_TIME_LONG;
461        pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
462        if((pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_DUAL) ||
463           (pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_2_4_GHZ))
464        {
465            pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
466            pSiteMgr->siteMgrOperationalMode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
467        }
468        else
469        {
470            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE ,"\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n");
471            WLAN_OS_REPORT(("\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n"));
472            return TI_NOK;
473        }
474    }
475    else
476    {
477        slotTime = PHY_SLOT_TIME_SHORT;
478        pSiteMgr->radioBand = RADIO_BAND_5_0_GHZ;
479        if((pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_DUAL) ||
480           (pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_5_0_GHZ))
481        {
482            pSiteMgr->siteMgrOperationalMode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
483            pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
484        }
485        else
486        {
487            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE ,"\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n");
488            WLAN_OS_REPORT(("\nERROR !!!.....The radio doesn't support the desired dot11 mode !!! \n"));
489            return TI_NOK;
490        }
491    }
492
493    /* Configure hal with common core-hal parameters */
494    TWD_SetRadioBand(pSiteMgr->hTWD, pSiteMgr->radioBand);
495    TWD_CfgSlotTime (pSiteMgr->hTWD, slotTime);
496    siteMgr_ConfigRate(hSiteMgr);
497
498    TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INIT, " SiteMgr - numOfElements = %d IETableSize = %d\n" , pSiteMgrInitParams->beaconFilterParams.numOfElements, pSiteMgrInitParams->beaconFilterParams.IETableSize);
499    /* Send the table regardless to the state */
500    TWD_CfgBeaconFilterTable (pSiteMgr->hTWD,
501                              pSiteMgrInitParams->beaconFilterParams.numOfElements,
502                              pSiteMgrInitParams->beaconFilterParams.IETable,
503                              pSiteMgrInitParams->beaconFilterParams.IETableSize);
504
505    /*  At start-up Set the Beacon Filter state as the User required */
506    TWD_CfgBeaconFilterOpt (pSiteMgr->hTWD, pSiteMgrInitParams->beaconFilterParams.desiredState, pSiteMgr->beaconFilterParams.numOfStored);
507
508    pSiteMgr->pSitesMgmtParams->pPrevPrimarySite = NULL;
509
510    /* Clears the ProbeReqWSC IE */
511    os_memoryZero(pSiteMgr->hOs,&pSiteMgr->siteMgrWSCProbeReqParams,sizeof(DOT11_WSC_PROBE_REQ_MAX_LENGTH));
512
513    /* Register the RSSI Trigger events at the currBss RSSI/SNR static table*/
514    currBSS_RegisterTriggerEvent(pSiteMgr->hCurrBss, TWD_OWN_EVENT_RSSI_SNR_TRIGGER_2, (TI_UINT8)0,(void*)siteMgr_TxPowerHighThreshold,hSiteMgr);
515    currBSS_RegisterTriggerEvent(pSiteMgr->hCurrBss, TWD_OWN_EVENT_RSSI_SNR_TRIGGER_3, (TI_UINT8)0,(void*)siteMgr_TxPowerLowThreshold, hSiteMgr);
516
517    tTriggerCfg.index     = TRIGGER_EVENT_HIGH_TX_PW;
518    tTriggerCfg.threshold = (0 - pSiteMgr->pDesiredParams->TxPowerRssiThresh);
519    tTriggerCfg.pacing    = TRIGGER_HIGH_TX_PW_PACING;
520    tTriggerCfg.metric    = METRIC_EVENT_RSSI_DATA;
521    tTriggerCfg.type      = RX_QUALITY_EVENT_EDGE;
522    tTriggerCfg.direction = RSSI_EVENT_DIR_HIGH;
523    tTriggerCfg.hystersis = TRIGGER_HIGH_TX_PW_HYSTERESIS;
524    tTriggerCfg.enable     = TI_TRUE;
525    TWD_CfgRssiSnrTrigger (pSiteMgr->hTWD, &tTriggerCfg);
526
527    tTriggerCfg.index     = TRIGGER_EVENT_LOW_TX_PW;
528    tTriggerCfg.threshold = (0 - pSiteMgr->pDesiredParams->TxPowerRssiRestoreThresh);
529    tTriggerCfg.pacing    = TRIGGER_LOW_TX_PW_PACING;
530    tTriggerCfg.metric    = METRIC_EVENT_RSSI_DATA;
531    tTriggerCfg.type      = RX_QUALITY_EVENT_EDGE;
532    tTriggerCfg.direction = RSSI_EVENT_DIR_LOW;
533    tTriggerCfg.hystersis = TRIGGER_LOW_TX_PW_HYSTERESIS;
534    tTriggerCfg.enable    = TI_TRUE;
535    TWD_CfgRssiSnrTrigger (pSiteMgr->hTWD, &tTriggerCfg);
536
537    TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INIT, ".....Site manager configured successfully\n");
538
539    return TI_OK;
540}
541
542
543/************************************************************************
544 *                        siteMgr_unLoad                                    *
545 ************************************************************************
546DESCRIPTION: site manager module unload function, called by the config mgr in the unlod phase
547                performs the following:
548                -   Free all memory aloocated by the module
549
550INPUT:      hSiteMgr    -   site mgr handle.
551
552
553OUTPUT:
554
555RETURN:     TI_OK on success, TI_NOK otherwise
556
557************************************************************************/
558TI_STATUS siteMgr_unLoad(TI_HANDLE hSiteMgr)
559{
560    TI_UINT32          initVec;
561    siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
562
563    if (!pSiteMgr)
564        return TI_OK;
565
566    initVec = 0xFFFF;
567    release_module(pSiteMgr, initVec);
568
569    return TI_OK;
570}
571
572/***********************************************************************
573 *                        siteMgr_setParam
574 ***********************************************************************
575DESCRIPTION: site mgr set param function, called by the following:
576                -   config mgr in order to set a parameter from the OS abstraction layer.
577                In this fuction, the site manager OS abstraction layer configures the site manager to the desired params.
578                Sometimes it requires a re scan, depending in the parameter type
579
580INPUT:      hSiteMgr    -   Connection handle.
581            pParam  -   Pointer to the parameter
582
583OUTPUT:
584
585RETURN:     TI_OK on success, TI_NOK on failure
586
587************************************************************************/
588
589TI_STATUS siteMgr_setParam(TI_HANDLE        hSiteMgr,
590                        paramInfo_t     *pParam)
591{
592    siteMgr_t *pSiteMgr = (siteMgr_t *)hSiteMgr;
593    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
594    OS_802_11_CONFIGURATION *pConfig;
595    TI_UINT32      channel;
596    ESlotTime  slotTime;
597    paramInfo_t	param;
598
599    switch(pParam->paramType)
600    {
601    case SITE_MGR_CONFIGURATION_PARAM:
602        pConfig = pParam->content.pSiteMgrConfiguration;
603
604/*      for(channel = 0; channel < SITE_MGR_CHANNEL_MAX+1; channel++)
605        {
606            if(pConfig->channel == pSiteMgr->pDesiredParams->siteMgrFreq2ChannelTable[channel])
607                break;
608        }*/
609
610        channel = Freq2Chan(pConfig->Union.channel);
611
612        if(channel == 0 || channel > SITE_MGR_CHANNEL_MAX)
613            return PARAM_VALUE_NOT_VALID;
614        else
615            pConfig->Union.channel = channel;
616
617        if((pSiteMgr->pDesiredParams->siteMgrDesiredChannel != pConfig->Union.channel) ||
618           (pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow != pConfig->ATIMWindow))
619        {
620            pSiteMgr->pDesiredParams->siteMgrDesiredChannel = (TI_UINT8)pConfig->Union.channel;
621            pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval = (TI_UINT16)pConfig->BeaconPeriod;
622            pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow = pConfig->ATIMWindow;
623        }
624
625        return TI_OK;
626
627    case SITE_MGR_DESIRED_CHANNEL_PARAM:
628        if (pParam->content.siteMgrDesiredChannel > SITE_MGR_CHANNEL_MAX)
629            return PARAM_VALUE_NOT_VALID;
630
631        if (pSiteMgr->pDesiredParams->siteMgrDesiredChannel != pParam->content.siteMgrDesiredChannel)
632            pSiteMgr->pDesiredParams->siteMgrDesiredChannel = (TI_UINT8)pParam->content.siteMgrDesiredChannel;
633        return TI_OK;
634
635    case SITE_MGR_DESIRED_BSSID_PARAM:
636            MAC_COPY (pSiteMgr->pDesiredParams->siteMgrDesiredBSSID, pParam->content.siteMgrDesiredBSSID);
637           return TI_OK;
638
639    case SITE_MGR_DESIRED_SSID_PARAM:
640
641        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "\nSet new SSID= (len=%d)  \n", pParam->content.siteMgrDesiredSSID.len);
642
643        if (pParam->content.siteMgrDesiredSSID.len > MAX_SSID_LEN)
644            return PARAM_VALUE_NOT_VALID;
645
646        os_memoryCopy(pSiteMgr->hOs, &pSiteMgr->pDesiredParams->siteMgrDesiredSSID, &pParam->content.siteMgrDesiredSSID, sizeof(TSsid));
647        /* only add null at the end of the string if the string length is less than 32 bytes and so we have one char left
648        */
649        if ( MAX_SSID_LEN > pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len )
650        {
651            pSiteMgr->pDesiredParams->siteMgrDesiredSSID.str[pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len] = '\0';
652        }
653
654        /* increase the random IBSS BSSID calculated during init */
655		pSiteMgr->ibssBssid[MAC_ADDR_LEN - 1] ++;
656
657        if (OS_802_11_SSID_JUNK (pSiteMgr->pDesiredParams->siteMgrDesiredSSID.str, pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len))
658        {
659            rsn_removedDefKeys(pSiteMgr->hRsn);
660        }
661
662        /* due to the fact we call to SME_DESIRED_SSID_ACT_PARAM also we not need to call sme_Restart */
663        return TI_OK;
664
665    case SITE_MGR_DESIRED_BSS_TYPE_PARAM:
666
667         TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "\nSet BssType = %d\n", pParam->content.siteMgrDesiredBSSType);
668        if (pParam->content.siteMgrDesiredBSSType > BSS_ANY)
669            return PARAM_VALUE_NOT_VALID;
670
671        if (pSiteMgr->pDesiredParams->siteMgrDesiredBSSType != pParam->content.siteMgrDesiredBSSType)
672        {
673            pSiteMgr->pDesiredParams->siteMgrDesiredBSSType = pParam->content.siteMgrDesiredBSSType;
674
675			/* If the new BSS type is NOT Ad_Hoc, We make sure that the rate masks are set to G */
676			 if(pSiteMgr->pDesiredParams->siteMgrDesiredBSSType != BSS_INDEPENDENT)
677
678            {
679				 pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
680                 siteMgr_ConfigRate(pSiteMgr);
681            }
682
683            /* If the new BSS type is Ad_Hoc, increase the random BSSID calculated during init */
684            if(pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_INDEPENDENT)
685            {
686                pSiteMgr->ibssBssid[MAC_ADDR_LEN - 1] ++;
687            }
688
689            /* go to B_ONLY Mode only if WiFI bit is Set*/
690            if (pSiteMgr->pDesiredParams->siteMgrWiFiAdhoc == TI_TRUE)
691            {   /* Configuration For AdHoc when using external configuration */
692                if(pSiteMgr->pDesiredParams->siteMgrExternalConfiguration == TI_FALSE)
693                {
694                    siteMgr_externalConfigurationParametersSet(hSiteMgr);
695                }
696            }
697        }
698
699        return TI_OK;
700
701    case SITE_MGR_SIMPLE_CONFIG_MODE: /* Setting the WiFiSimpleConfig mode */
702
703		/* Modify the current mode */
704		pSiteMgr->siteMgrWSCCurrMode = pParam->content.siteMgrWSCMode.WSCMode;
705
706TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Setting SimpleConfig Mode to %d\n", pSiteMgr->siteMgrWSCCurrMode);
707
708		/* In case the WSC is on ,the ProbeReq WSC IE need to be updated */
709
710		if(pSiteMgr->siteMgrWSCCurrMode != TIWLN_SIMPLE_CONFIG_OFF)
711		{
712			os_memoryCopy(pSiteMgr->hOs, &pSiteMgr->siteMgrWSCProbeReqParams, &pParam->content.siteMgrWSCMode.probeReqWSCIE, DOT11_WSC_PROBE_REQ_MAX_LENGTH);
713
714			param.paramType = RSN_WPA_PROMOTE_OPTIONS;
715           	param.content.rsnWPAPromoteFlags = ADMCTRL_WPA_OPTION_ENABLE_PROMOTE_AUTH_MODE;
716           	rsn_setParam(pSiteMgr->hRsn, &param);
717
718            /* update the SME on the WPS mode */
719            param.paramType = SME_WSC_PB_MODE_PARAM;
720            sme_SetParam (pSiteMgr->hSmeSm, &param);
721		}
722		else
723		{
724			param.paramType = RSN_WPA_PROMOTE_OPTIONS;
725           	param.content.rsnWPAPromoteFlags = ADMCTRL_WPA_OPTION_NONE;
726           	rsn_setParam(pSiteMgr->hRsn, &param);
727		}
728
729        return TI_OK;
730
731    case SITE_MGR_DESIRED_MODULATION_TYPE_PARAM:
732        if ((pParam->content.siteMgrDesiredModulationType < DRV_MODULATION_CCK) ||
733            (pParam->content.siteMgrDesiredModulationType > DRV_MODULATION_OFDM))
734            return PARAM_VALUE_NOT_VALID;
735
736        if (pSiteMgr->pDesiredParams->siteMgrDesiredModulationType != pParam->content.siteMgrDesiredModulationType)
737        {
738            pSiteMgr->pDesiredParams->siteMgrDesiredModulationType = pParam->content.siteMgrDesiredModulationType;
739            /* means that we are moving from non-pbcc network to pbcc */
740            if (pParam->content.siteMgrDesiredModulationType == DRV_MODULATION_PBCC)
741                sme_Restart (pSiteMgr->hSmeSm);
742            return TI_OK;
743        }
744        return TI_OK;
745
746    case SITE_MGR_BEACON_RECV:
747        if (!pPrimarySite)
748        {
749            return NO_SITE_SELECTED_YET;
750        }
751        pPrimarySite->beaconRecv = pParam->content.siteMgrBeaconRecv;
752        return TI_OK;
753
754
755    case SITE_MGR_DESIRED_BEACON_INTERVAL_PARAM:
756        if (pParam->content.siteMgrDesiredBeaconInterval < SITE_MGR_BEACON_INTERVAL_MIN)
757            return PARAM_VALUE_NOT_VALID;
758
759        if (pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval != pParam->content.siteMgrDesiredBeaconInterval)
760            pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval = pParam->content.siteMgrDesiredBeaconInterval;
761        return TI_OK;
762
763    case SITE_MGR_DESIRED_PREAMBLE_TYPE_PARAM:
764        if ((pParam->content.siteMgrDesiredPreambleType != PREAMBLE_LONG) &&
765            (pParam->content.siteMgrDesiredPreambleType != PREAMBLE_SHORT))
766            return PARAM_VALUE_NOT_VALID;
767
768        if (pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType != pParam->content.siteMgrDesiredPreambleType)
769        {
770            pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType = pParam->content.siteMgrDesiredPreambleType;
771        }
772        return TI_OK;
773
774    case SITE_MGR_DESIRED_SUPPORTED_RATE_SET_PARAM:
775        return setSupportedRateSet(pSiteMgr, &(pParam->content.siteMgrDesiredSupportedRateSet));
776
777    case SITE_MGR_DESIRED_DOT11_MODE_PARAM:
778        if(pParam->content.siteMgrDot11Mode > DOT11_MAX_MODE)
779            return PARAM_VALUE_NOT_VALID;
780
781        if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode != pParam->content.siteMgrDot11Mode)
782        {
783            pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode = pParam->content.siteMgrDot11Mode;
784
785            /* since the dot11ABAmode changed, the STA operational mode should be changed */
786            if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)
787            {
788                if(pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_DUAL)
789                {
790                    pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
791                }
792                else if(pSiteMgr->pDesiredParams->siteMgrSupportedBand == RADIO_BAND_2_4_GHZ)
793                {
794                    pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode = DOT11_G_MODE;
795                    pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
796                }
797                else
798                {
799                    pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode = DOT11_G_MODE;
800                    pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
801                }
802
803            }
804            else
805                pSiteMgr->siteMgrOperationalMode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
806
807            /* configure HAL with new parameters update rates and select site table */
808            pSiteMgr->prevRadioBand = pSiteMgr->radioBand;
809            if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
810            {
811                pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
812                pSiteMgr->radioBand = RADIO_BAND_5_0_GHZ;
813                slotTime = PHY_SLOT_TIME_SHORT;
814            }
815            else if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
816            {
817                pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
818                pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
819                slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
820            }
821            else
822            {
823                pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
824                pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
825                slotTime = PHY_SLOT_TIME_LONG;
826            }
827
828            if(pSiteMgr->prevRadioBand != pSiteMgr->radioBand)
829                siteMgr_bandParamsConfig(pSiteMgr, TI_TRUE);
830
831            /* Configure TWD */
832            TWD_SetRadioBand(pSiteMgr->hTWD, pSiteMgr->radioBand);
833            TWD_CfgSlotTime (pSiteMgr->hTWD, slotTime);
834
835            /* If the BSS type is Ad_Hoc, increase the random BSSID calculated during init */
836            if(pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_INDEPENDENT)
837            {
838                pSiteMgr->ibssBssid[MAC_ADDR_LEN - 1] ++;
839            }
840
841            /*siteMgr_resetAllSiteTables(pSiteMgr); */
842            sme_Restart (pSiteMgr->hSmeSm);
843        }
844        return TI_OK;
845
846    case SITE_MGR_OPERATIONAL_MODE_PARAM:
847
848        if(pParam->content.siteMgrDot11OperationalMode < DOT11_B_MODE ||
849            pParam->content.siteMgrDot11OperationalMode > DOT11_G_MODE )
850            return PARAM_VALUE_NOT_VALID;
851
852        pSiteMgr->siteMgrOperationalMode = pParam->content.siteMgrDot11OperationalMode;
853        break;
854
855
856    case SITE_MGR_RADIO_BAND_PARAM:
857        if((TI_INT8)pParam->content.siteMgrRadioBand < RADIO_BAND_2_4_GHZ ||
858           (TI_INT8)pParam->content.siteMgrRadioBand > RADIO_BAND_DUAL )
859            return PARAM_VALUE_NOT_VALID;
860
861        pSiteMgr->prevRadioBand = pSiteMgr->radioBand;
862        pSiteMgr->radioBand = pParam->content.siteMgrRadioBand;
863        if(pSiteMgr->prevRadioBand != pSiteMgr->radioBand)
864            siteMgr_bandParamsConfig(pSiteMgr, TI_FALSE);
865
866        break;
867
868    case SITE_MGR_DESIRED_SLOT_TIME_PARAM:
869        if(pParam->content.siteMgrSlotTime != PHY_SLOT_TIME_LONG &&
870           pParam->content.siteMgrSlotTime != PHY_SLOT_TIME_SHORT)
871            return PARAM_VALUE_NOT_VALID;
872
873        if (pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime != pParam->content.siteMgrSlotTime)
874        {
875            if (pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
876            {
877                pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime = pParam->content.siteMgrSlotTime;
878                if (!pPrimarySite)
879                    TWD_CfgSlotTime (pSiteMgr->hTWD, pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime);
880                else if (pPrimarySite->bssType != BSS_INFRASTRUCTURE)
881                    TWD_CfgSlotTime (pSiteMgr->hTWD, pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime);
882            }
883
884        }
885        return TI_OK;
886
887    case SITE_MGR_BEACON_FILTER_DESIRED_STATE_PARAM:
888        {
889            /* Check if the Desired  mode has changed - If not no need to send the MIB to the FW */
890            if (pSiteMgr->beaconFilterParams.desiredState == pParam->content.siteMgrDesiredBeaconFilterState)
891            {
892                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Beacon Filter already \n");
893                break;
894            }
895
896            /* Set the New Desired User request of Beacon Filter */
897            pSiteMgr->beaconFilterParams.desiredState = pParam->content.siteMgrDesiredBeaconFilterState;
898
899            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "New Beacon Filter State is: \n");
900
901            /* Send the User required Beacon Filter Configuration to the FW */
902            TWD_CfgBeaconFilterOpt (pSiteMgr->hTWD, pSiteMgr->beaconFilterParams.desiredState, pSiteMgr->beaconFilterParams.numOfStored);
903        }
904
905        break;
906
907    case SITE_MGR_LAST_RX_RATE_PARAM:
908        if (pPrimarySite != NULL)
909        {
910            pPrimarySite->rxRate = pParam->content.ctrlDataCurrentBasicRate;
911        }
912        break;
913
914    case SITE_MGR_CURRENT_CHANNEL_PARAM:
915        if (!pPrimarySite)
916        {
917            return NO_SITE_SELECTED_YET;
918        }
919        pPrimarySite->channel = pParam->content.siteMgrCurrentChannel;
920        break;
921
922    case SITE_MGR_CURRENT_SIGNAL_PARAM:
923        if (!pPrimarySite)
924        {
925            return NO_SITE_SELECTED_YET;
926        }
927
928        pPrimarySite->rssi = pParam->content.siteMgrCurrentSignal.rssi;
929        break;
930
931    case SITE_MGRT_SET_RATE_MANAGMENT:
932        TWD_SetRateMngDebug(pSiteMgr->hTWD,&pParam ->content.RateMng);
933        break;
934
935    default:
936        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Set param, Params is not supported, %d\n", pParam->paramType);
937        return PARAM_NOT_SUPPORTED;
938    }
939
940    return TI_OK;
941}
942
943TI_STATUS siteMgr_getParamWSC(TI_HANDLE hSiteMgr, TIWLN_SIMPLE_CONFIG_MODE *wscParam)
944{ /* SITE_MGR_SIMPLE_CONFIG_MODE: - Retrieving the WiFiSimpleConfig mode */
945    siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
946
947	if (pSiteMgr == NULL)
948	{
949		return TI_NOK;
950	}
951
952    *wscParam = pSiteMgr->siteMgrWSCCurrMode;
953    return TI_OK;
954}
955
956/***********************************************************************
957 *                        siteMgr_getParam
958 ***********************************************************************
959DESCRIPTION: Site mgr get param function, called by the following:
960            -   config mgr in order to get a parameter from the OS abstraction layer.
961            -   From inside the dirver
962
963INPUT:      hSiteMgr    -   site mgr handle.
964            pParam  -   Pointer to the parameter
965
966OUTPUT:
967
968RETURN:     TI_OK on success, TI_NOK otherwise
969
970************************************************************************/
971TI_STATUS siteMgr_getParam(TI_HANDLE        hSiteMgr,
972                            paramInfo_t     *pParam)
973{
974    siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
975    siteEntry_t     *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
976    TI_STATUS       status = TI_OK;
977    TI_UINT8           siteEntryIndex;
978    TTwdParamInfo   tTwdParam;
979
980	if(pSiteMgr == NULL)
981	{
982		return TI_NOK;
983	}
984
985    switch(pParam->paramType)
986    {
987
988    case SITE_MGR_CONFIGURATION_PARAM:
989        pParam->content.pSiteMgrConfiguration->Length = sizeof(OS_802_11_CONFIGURATION);
990        pParam->content.pSiteMgrConfiguration->ATIMWindow = pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow;
991        pParam->content.pSiteMgrConfiguration->BeaconPeriod = pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval;
992        pParam->content.pSiteMgrConfiguration->Union.channel =
993            Chan2Freq(pSiteMgr->pDesiredParams->siteMgrDesiredChannel);
994            /*pSiteMgr->pDesiredParams->siteMgrFreq2ChannelTable[pSiteMgr->pDesiredParams->siteMgrDesiredChannel];*/
995        break;
996
997    case SITE_MGR_DESIRED_CHANNEL_PARAM:
998        pParam->content.siteMgrDesiredChannel = pSiteMgr->pDesiredParams->siteMgrDesiredChannel;
999        break;
1000
1001	case SITE_MGR_SIMPLE_CONFIG_MODE: /* Retrieving the WiFiSimpleConfig mode */
1002		pParam->content.siteMgrWSCMode.WSCMode = pSiteMgr->siteMgrWSCCurrMode;
1003
1004        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Retrieving the SimpleConfig Mode (%d) \n", pSiteMgr->siteMgrWSCCurrMode);
1005		break;
1006
1007    case SITE_MGR_DESIRED_SUPPORTED_RATE_SET_PARAM:
1008        getSupportedRateSet(pSiteMgr, &(pParam->content.siteMgrDesiredSupportedRateSet));
1009        break;
1010
1011    case SITE_MGR_DESIRED_MODULATION_TYPE_PARAM:
1012        pParam->content.siteMgrDesiredModulationType = pSiteMgr->pDesiredParams->siteMgrDesiredModulationType;
1013        break;
1014
1015    case SITE_MGR_DESIRED_BEACON_INTERVAL_PARAM:
1016        pParam->content.siteMgrDesiredBeaconInterval = pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval;
1017        break;
1018
1019    case SITE_MGR_DESIRED_PREAMBLE_TYPE_PARAM:
1020        pParam->content.siteMgrDesiredPreambleType = pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType;
1021        break;
1022
1023    case SITE_MGR_CURRENT_SIGNAL_PARAM:
1024        if (!pPrimarySite)
1025        {
1026            pParam->content.siteMgrCurrentSignal.rssi = 0;
1027            pParam->content.siteMgrCurrentSignal.snr = 0;
1028            return NO_SITE_SELECTED_YET;
1029        }
1030
1031        pParam->content.siteMgrCurrentSignal.rssi = pPrimarySite->rssi;
1032        pParam->content.siteMgrCurrentSignal.snr = pPrimarySite->snr;
1033        break;
1034
1035    case SITE_MGR_POWER_CONSTRAINT_PARAM:
1036        if (!pPrimarySite)
1037        {
1038            pParam->content.powerConstraint = 0;
1039            return NO_SITE_SELECTED_YET;
1040        }
1041        pParam->content.powerConstraint = pPrimarySite->powerConstraint;
1042        break;
1043
1044
1045    case SITE_MGR_DTIM_PERIOD_PARAM:
1046        if (!pPrimarySite)
1047        {
1048            pParam->content.siteMgrDtimPeriod = 0;
1049            return NO_SITE_SELECTED_YET;
1050        }
1051        pParam->content.siteMgrDtimPeriod = pPrimarySite->dtimPeriod;
1052        break;
1053
1054    case SITE_MGR_BEACON_RECV:
1055        if (!pPrimarySite)
1056        {
1057            pParam->content.siteMgrBeaconRecv = TI_FALSE;
1058            return NO_SITE_SELECTED_YET;
1059        }
1060        pParam->content.siteMgrBeaconRecv = pPrimarySite->beaconRecv;
1061        break;
1062
1063
1064    case SITE_MGR_BEACON_INTERVAL_PARAM:
1065        if (!pPrimarySite)
1066        {
1067            pParam->content.beaconInterval = 0;
1068            return NO_SITE_SELECTED_YET;
1069        }
1070        pParam->content.beaconInterval = pPrimarySite->beaconInterval;
1071        break;
1072
1073    case SITE_MGR_AP_TX_POWER_PARAM:
1074        if (!pPrimarySite)
1075        {
1076            pParam->content.APTxPower = 0;
1077            return NO_SITE_SELECTED_YET;
1078        }
1079        pParam->content.APTxPower = pPrimarySite->APTxPower;
1080        break;
1081
1082    case SITE_MGR_SITE_CAPABILITY_PARAM:
1083        if (!pPrimarySite)
1084        {
1085            pParam->content.siteMgrSiteCapability = 0;
1086            return NO_SITE_SELECTED_YET;
1087        }
1088        pParam->content.siteMgrSiteCapability = pPrimarySite->capabilities;
1089        break;
1090
1091    case SITE_MGR_CURRENT_CHANNEL_PARAM:
1092        if (!pPrimarySite)
1093        {
1094            pParam->content.siteMgrCurrentChannel = 0;
1095            return NO_SITE_SELECTED_YET;
1096        }
1097        pParam->content.siteMgrCurrentChannel = pPrimarySite->channel;
1098        break;
1099
1100    case SITE_MGR_CURRENT_SSID_PARAM:
1101        if (!pPrimarySite)
1102        {
1103            os_memoryZero(pSiteMgr->hOs, (void *)pParam->content.siteMgrCurrentSSID.str, MAX_SSID_LEN);
1104            pParam->content.siteMgrCurrentSSID.len = 0;
1105            return NO_SITE_SELECTED_YET;
1106        }
1107        if(pPrimarySite->ssid.len == 0)
1108            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_getParam: ssid length is zero, while primarySite is selected \n");
1109        os_memoryCopy(pSiteMgr->hOs, &pParam->content.siteMgrCurrentSSID, &pPrimarySite->ssid, sizeof(TSsid));
1110        break;
1111
1112
1113    case SITE_MGR_CURRENT_BSS_TYPE_PARAM:
1114        if (!pPrimarySite)
1115        {
1116            pParam->content.siteMgrCurrentBSSType = pSiteMgr->pDesiredParams->siteMgrDesiredBSSType;
1117            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Trying to get current BSS Type while no site is selected\n");
1118
1119        }
1120        else{
1121            pParam->content.siteMgrCurrentBSSType = pPrimarySite->bssType;
1122        }
1123
1124        break;
1125
1126
1127    case SITE_MGR_CURRENT_RATE_PAIR_PARAM:
1128        if (!pPrimarySite)
1129        {
1130            pParam->content.siteMgrCurrentRateMask.basicRateMask = 0;
1131            pParam->content.siteMgrCurrentRateMask.supportedRateMask = 0;
1132            return NO_SITE_SELECTED_YET;
1133        }
1134        pParam->content.siteMgrCurrentRateMask.basicRateMask = pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask;
1135        pParam->content.siteMgrCurrentRateMask.supportedRateMask = pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask;
1136        TRACE4(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "SITE_MGR: bitmapBasicPrimary= 0x%X,bitMapBasicDesired = 0x%X,bitMapSuppPrimary = 0x%X, bitMapSuppDesired = 0x%X\n", pPrimarySite->rateMask.basicRateMask,pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask, pPrimarySite->rateMask.supportedRateMask,pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask);
1137        break;
1138
1139    case SITE_MGR_CURRENT_MODULATION_TYPE_PARAM:
1140        if (!pPrimarySite)
1141        {
1142            pParam->content.siteMgrCurrentModulationType = DRV_MODULATION_NONE;
1143            return NO_SITE_SELECTED_YET;
1144        }
1145        pParam->content.siteMgrCurrentModulationType = pSiteMgr->chosenModulation;
1146        break;
1147
1148    case SITE_MGR_DESIRED_SLOT_TIME_PARAM:
1149        pParam->content.siteMgrSlotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
1150        break;
1151
1152    case SITE_MGR_CURRENT_SLOT_TIME_PARAM:
1153
1154        if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
1155        {
1156            if(!pPrimarySite)
1157                pParam->content.siteMgrSlotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
1158            else
1159                pParam->content.siteMgrSlotTime = pPrimarySite->currentSlotTime;
1160        }
1161        else if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
1162            pParam->content.siteMgrSlotTime = PHY_SLOT_TIME_SHORT;
1163        else
1164            pParam->content.siteMgrSlotTime = PHY_SLOT_TIME_LONG;
1165
1166        break;
1167
1168    case SITE_MGR_LAST_BEACON_BUF_PARAM:
1169        if (pPrimarySite != NULL)
1170        {
1171            if (pPrimarySite->probeRecv)
1172            {
1173                pParam->content.siteMgrLastBeacon.isBeacon = TI_FALSE;
1174                pParam->content.siteMgrLastBeacon.bufLength = pPrimarySite->probeRespLength;
1175                pParam->content.siteMgrLastBeacon.buffer = pPrimarySite->probeRespBuffer;
1176            }
1177            else
1178            {
1179                pParam->content.siteMgrLastBeacon.isBeacon = TI_TRUE;
1180                pParam->content.siteMgrLastBeacon.bufLength = pPrimarySite->beaconLength;
1181                pParam->content.siteMgrLastBeacon.buffer = pPrimarySite->beaconBuffer;
1182            }
1183        }
1184        break;
1185
1186    case SITE_MGR_BEACON_FILTER_DESIRED_STATE_PARAM:
1187        {
1188            if ( NULL != pSiteMgr )
1189            {
1190                pParam->content.siteMgrDesiredBeaconFilterState = pSiteMgr->beaconFilterParams.desiredState;
1191            }
1192            else
1193            {
1194                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "pSite = NULL ! No info available");
1195            }
1196        }
1197        break;
1198
1199    case SITE_MGR_GET_SELECTED_BSSID_INFO:
1200        getPrimarySiteDesc(pSiteMgr, pParam->content.pSiteMgrPrimarySiteDesc, TI_FALSE);
1201        break;
1202
1203	case SITE_MGR_GET_SELECTED_BSSID_INFO_EX:
1204       getPrimarySiteDesc(pSiteMgr, (OS_802_11_BSSID *)pParam->content.pSiteMgrSelectedSiteInfo,TI_TRUE);
1205       break;
1206
1207    case SITE_MGR_PRIMARY_SITE_PARAM:
1208       status = getPrimaryBssid(pSiteMgr, (OS_802_11_BSSID_EX *)pParam->content.pSiteMgrSelectedSiteInfo, &pParam->paramLength);
1209       break;
1210
1211
1212    case SITE_MGR_TI_WLAN_COUNTERS_PARAM:
1213        pParam->paramType = RX_DATA_COUNTERS_PARAM;
1214        rxData_getParam(pSiteMgr->hRxData, pParam);
1215
1216        tTwdParam.paramType = TWD_COUNTERS_PARAM_ID;
1217        TWD_GetParam (pSiteMgr->hTWD, &tTwdParam);
1218        pParam->content.siteMgrTiWlanCounters.RecvNoBuffer = tTwdParam.content.halCtrlCounters.RecvNoBuffer;
1219        pParam->content.siteMgrTiWlanCounters.FragmentsRecv = tTwdParam.content.halCtrlCounters.FragmentsRecv;
1220        pParam->content.siteMgrTiWlanCounters.FrameDuplicates = tTwdParam.content.halCtrlCounters.FrameDuplicates;
1221        pParam->content.siteMgrTiWlanCounters.FcsErrors = tTwdParam.content.halCtrlCounters.FcsErrors;
1222        pParam->content.siteMgrTiWlanCounters.RecvError = tTwdParam.content.halCtrlCounters.RecvError;
1223
1224        pParam->paramType = AUTH_COUNTERS_PARAM;
1225        auth_getParam(pSiteMgr->hAuth, pParam);
1226
1227		pParam->paramType = MLME_BEACON_RECV;
1228        mlme_getParam(pSiteMgr->hMlmeSm, pParam);
1229
1230        pParam->paramType = ASSOC_COUNTERS_PARAM;
1231        assoc_getParam(pSiteMgr->hAssoc, pParam);
1232        pParam->content.siteMgrTiWlanCounters.BeaconsXmit = pSiteMgr->beaconSentCount;
1233        break;
1234
1235    case SITE_MGR_FIRMWARE_VERSION_PARAM:
1236        {
1237            TFwInfo *pFwInfo = TWD_GetFWInfo (pSiteMgr->hTWD);
1238            os_memoryCopy(pSiteMgr->hOs,
1239                          pParam->content.siteMgrFwVersion,
1240                          pFwInfo->fwVer,
1241                          sizeof(pFwInfo->fwVer));
1242        }
1243        break;
1244
1245    case SITE_MGR_CURRENT_TX_RATE_PARAM:
1246        {
1247            ERate rate = txCtrlParams_GetTxRate (pSiteMgr->hTxCtrl);
1248            pParam->content.siteMgrCurrentTxRate = rate_DrvToNet (rate);
1249        }
1250        break;
1251
1252    case SITE_MGR_CURRENT_RX_RATE_PARAM:
1253        {
1254            pParam->paramType = RX_DATA_RATE_PARAM;
1255            rxData_getParam (pSiteMgr->hRxData, pParam);
1256            pParam->content.siteMgrCurrentRxRate =
1257                (TI_UINT8)rate_DrvToNet ((ERate)pParam->content.siteMgrCurrentRxRate);
1258        }
1259        break;
1260
1261    case SITE_MGR_DESIRED_DOT11_MODE_PARAM:
1262        pParam->content.siteMgrDot11Mode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
1263        break;
1264
1265	case SITE_MGR_NETWORK_TYPE_IN_USE:
1266		if (pPrimarySite)
1267		{ /* Connected - return the current mode */
1268			pParam->content.siteMgrDot11Mode = pSiteMgr->siteMgrOperationalMode;
1269		}
1270		else
1271		{ /* Disconnected - return the desired mode */
1272			pParam->content.siteMgrDot11Mode = pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode;
1273		}
1274        break;
1275
1276
1277    case SITE_MGR_OPERATIONAL_MODE_PARAM:
1278        pParam->content.siteMgrDot11OperationalMode = pSiteMgr->siteMgrOperationalMode;
1279        break;
1280
1281    case SITE_MGR_RADIO_BAND_PARAM:
1282        pParam->content.siteMgrRadioBand = pSiteMgr->radioBand;
1283        break;
1284
1285    case SITE_MGR_CURRENT_PREAMBLE_TYPE_PARAM:
1286        if (!pPrimarySite)
1287            return NO_SITE_SELECTED_YET;
1288
1289        pParam->content.siteMgrCurrentPreambleType = pPrimarySite->currentPreambleType;
1290        break;
1291
1292    case SITE_MGR_CURRENT_BSSID_PARAM:
1293        if (pPrimarySite != NULL)
1294        {
1295            MAC_COPY (pParam->content.siteMgrDesiredBSSID, pPrimarySite->bssid);
1296        }
1297		else
1298			return NO_SITE_SELECTED_YET;
1299        break;
1300
1301    case SITE_MGR_LAST_RX_RATE_PARAM:
1302        if (pPrimarySite != NULL)
1303        {
1304            pParam->content.ctrlDataCurrentBasicRate = pPrimarySite->rxRate;
1305        }
1306        break;
1307
1308    case SITE_MGR_PREV_SITE_BSSID_PARAM:
1309        if (pSiteMgr->pSitesMgmtParams->pPrevPrimarySite==NULL)
1310        {
1311            return TI_NOK;
1312        }
1313        MAC_COPY (pParam->content.siteMgrDesiredBSSID, pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->bssid);
1314        break;
1315
1316    case SITE_MGR_PREV_SITE_SSID_PARAM:
1317        if (pSiteMgr->pSitesMgmtParams->pPrevPrimarySite==NULL)
1318        {
1319            return TI_NOK;
1320        }
1321        pParam->content.siteMgrDesiredSSID.len = pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->ssid.len;
1322        os_memoryCopy(pSiteMgr->hOs,
1323                      (void *)pParam->content.siteMgrDesiredSSID.str,
1324                      (void *)pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->ssid.str,
1325                      pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->ssid.len);
1326        break;
1327
1328    case SITE_MGR_PREV_SITE_CHANNEL_PARAM:
1329        if (pSiteMgr->pSitesMgmtParams->pPrevPrimarySite==NULL)
1330        {
1331            return TI_NOK;
1332        }
1333        pParam->content.siteMgrDesiredChannel = pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->channel;
1334        break;
1335
1336    case SITE_MGR_SITE_ENTRY_BY_INDEX:
1337        siteEntryIndex = pParam->content.siteMgrIndexOfDesiredSiteEntry;
1338        if(siteEntryIndex >= MAX_SITES_BG_BAND)
1339        {
1340            return TI_NOK;
1341        }
1342        pParam->content.pSiteMgrDesiredSiteEntry =
1343            (TI_UINT8*)(&(pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->siteTable[siteEntryIndex]));
1344        break;
1345
1346    case SITE_MGR_CUR_NUM_OF_SITES:
1347        pParam->content.siteMgrNumberOfSites = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->numOfSites;
1348        break;
1349
1350    case SITE_MGR_CURRENT_TSF_TIME_STAMP:
1351        os_memoryCopy(pSiteMgr->hOs, pParam->content.siteMgrCurrentTsfTimeStamp,
1352                      pSiteMgr->pSitesMgmtParams->pPrimarySite->tsfTimeStamp,
1353                      TIME_STAMP_LEN);
1354        break;
1355
1356    case SITE_MGR_GET_AP_QOS_CAPABILITIES:
1357       if (!pPrimarySite)
1358       {
1359           pParam->content.qosApCapabilities.uQOSFlag = 0;
1360           pParam->content.qosApCapabilities.uAPSDFlag = 0;
1361           TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Not connected to an AP...\n");
1362           return NOT_CONNECTED;
1363       }
1364       pParam->content.qosApCapabilities.uQOSFlag = pPrimarySite->WMESupported;
1365       pParam->content.qosApCapabilities.uAPSDFlag = pPrimarySite->APSDSupport;
1366       break;
1367
1368    case SITE_MGR_GET_PRIMARY_SITE:
1369       if (!pPrimarySite)
1370       {
1371           pParam->content.pPrimarySite = (void *)NULL;
1372           return NOT_CONNECTED;
1373       }
1374       else
1375       {
1376           pParam->content.pPrimarySite = (void *)pPrimarySite;
1377       }
1378       break;
1379
1380    case SITE_MGR_PRIMARY_SITE_HT_SUPPORT:
1381       if (!pPrimarySite)
1382       {
1383           pParam->content.bPrimarySiteHtSupport = TI_FALSE;
1384           return NOT_CONNECTED;
1385       }
1386       else
1387       {
1388           if((pPrimarySite->tHtCapabilities.tHdr[0] != TI_FALSE) && (pPrimarySite->tHtInformation.tHdr[0] != TI_FALSE))
1389           {
1390               pParam->content.bPrimarySiteHtSupport = TI_TRUE;
1391           }
1392           else
1393           {
1394               pParam->content.bPrimarySiteHtSupport = TI_FALSE;
1395           }
1396       }
1397       break;
1398    case SITE_MGRT_GET_RATE_MANAGMENT:
1399         return cmdBld_ItrRateParams (pSiteMgr->hTWD,
1400                                      pParam->content.interogateCmdCBParams.fCb,
1401                                      pParam->content.interogateCmdCBParams.hCb,
1402                                      (void*)pParam->content.interogateCmdCBParams.pCb);
1403
1404    default:
1405        {
1406            TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Get param, Params is not supported, 0x%x\n", pParam->paramType);
1407        }
1408
1409        return PARAM_NOT_SUPPORTED;
1410    }
1411
1412    return status;
1413}
1414
1415
1416/***********************************************************************
1417 *                        siteMgr_join
1418 ***********************************************************************
1419DESCRIPTION: Called by the connection state machine in order to join a BSS.
1420                -   If the BSS is infrastructure, sets a NULL data template to the HAL
1421                -   If the BSS is IBSS, sets a probe response & beacon template to the HAL
1422            Call the HAL with the join parameters
1423
1424
1425INPUT:      hSiteMgr    -   site mgr handle.
1426            JoinCompleteCB - join command complete callback function ptr
1427            CB_handle - handle to pass to callback function
1428
1429OUTPUT:
1430
1431RETURN:     TI_OK on success, TI_NOK otherwise
1432
1433************************************************************************/
1434TI_STATUS siteMgr_join(TI_HANDLE    hSiteMgr)
1435{
1436    siteMgr_t               *pSiteMgr = (siteMgr_t *)hSiteMgr;
1437    TJoinBss                joinParams;
1438    TSetTemplate            templateStruct;
1439    probeRspTemplate_t      probeRspTemplate;
1440    nullDataTemplate_t      nullDataTemplate;
1441    disconnTemplate_t       disconnTemplate;
1442    psPollTemplate_t        psPollTemplate;
1443    QosNullDataTemplate_t   QosNullDataTemplate;
1444    siteEntry_t             *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
1445    EPreamble               curPreamble;
1446
1447    if (pPrimarySite == NULL)
1448    {
1449        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Join BSS, Primary Site is NULL\n");
1450        return TI_OK;
1451    }
1452
1453    /* Configure the system according to parameters of Primary Site */
1454    systemConfig(pSiteMgr);
1455
1456    joinParams.bssType = pPrimarySite->bssType;
1457    joinParams.beaconInterval = pPrimarySite->beaconInterval;
1458    joinParams.dtimInterval = pPrimarySite->dtimPeriod;
1459    joinParams.pBSSID = (TI_UINT8 *)&pPrimarySite->bssid;
1460    joinParams.pSSID = (TI_UINT8 *)&pPrimarySite->ssid.str;
1461    joinParams.ssidLength = pPrimarySite->ssid.len;
1462
1463    /*
1464     * Set the radio band and the HW management Tx rate according to operational mode.
1465     * The HW management frames includes Beacon and Probe-Response (in IBSS).
1466     */
1467    if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
1468    {
1469        joinParams.radioBand = RADIO_BAND_5_0_GHZ;
1470    }
1471    else
1472    {
1473        joinParams.radioBand = RADIO_BAND_2_4_GHZ;
1474    }
1475
1476    joinParams.channel = pPrimarySite->channel;
1477    if (joinParams.channel == SPECIAL_BG_CHANNEL)
1478    {
1479         joinParams.basicRateSet     = (TI_UINT16)rate_GetDrvBitmapForDefaultBasicSet ();
1480    }
1481    else /* != SPECIAL_BG_CHANNEL */
1482    {
1483        joinParams.basicRateSet = (TI_UINT16)pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask;
1484    }
1485
1486    ctrlData_getParamPreamble(pSiteMgr->hCtrlData, &curPreamble); /* CTRL_DATA_CURRENT_PREAMBLE_TYPE_PARAM */
1487    /* Set the preamble before the join */
1488    TWD_CfgPreamble (pSiteMgr->hTWD, curPreamble);
1489
1490    /* Now, Set templates to the HAL */
1491    templateStruct.uRateMask = RATE_MASK_UNSPECIFIED;
1492    if (pPrimarySite->bssType == BSS_INDEPENDENT)
1493    {
1494        templateStruct.ptr = (TI_UINT8 *)&probeRspTemplate;
1495        templateStruct.type = PROBE_RESPONSE_TEMPLATE;
1496        buildProbeRspTemplate(pSiteMgr, &templateStruct);
1497        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1498
1499        /* We don't have to build a beacon template, because it is equal to probe response,
1500        we only have to change the frame sup type */
1501        probeRspTemplate.hdr.fc = ENDIAN_HANDLE_WORD(DOT11_FC_BEACON);
1502        templateStruct.type = BEACON_TEMPLATE;
1503        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1504    }
1505    else
1506    {
1507        templateStruct.ptr = (TI_UINT8 *)&nullDataTemplate;
1508        templateStruct.type = NULL_DATA_TEMPLATE;
1509        buildNullTemplate(pSiteMgr, &templateStruct);
1510        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1511
1512        /* Send PsPoll template to HAL */
1513        templateStruct.ptr = (TI_UINT8 *)&psPollTemplate;
1514        templateStruct.type = PS_POLL_TEMPLATE;
1515        buildPsPollTemplate(pSiteMgr, &templateStruct);
1516        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1517
1518        /* Set QOS Null data template to the firmware.
1519            Note:  the AC to use with this template may change in QoS-manager. */
1520        templateStruct.ptr = (TI_UINT8 *)&QosNullDataTemplate;
1521        templateStruct.type = QOS_NULL_DATA_TEMPLATE;
1522        buildQosNullDataTemplate(pSiteMgr, &templateStruct, 0);
1523        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1524
1525        /* Send disconnect (Deauth/Disassoc) template to HAL */
1526        templateStruct.ptr = (TI_UINT8 *)&disconnTemplate;
1527        templateStruct.type = DISCONN_TEMPLATE;
1528        buildDisconnTemplate(pSiteMgr, &templateStruct);
1529        TWD_CmdTemplate (pSiteMgr->hTWD, &templateStruct, NULL, NULL);
1530
1531    }
1532
1533    /* Reset the Tx Power Control adjustment in RegulatoryDomain */
1534    siteMgr_setTemporaryTxPower(pSiteMgr, TI_FALSE);
1535
1536	/* Get a new Tx-Session-Count (also updates the TxCtrl module). */
1537	joinParams.txSessionCount = incrementTxSessionCount(pSiteMgr);
1538
1539    return TWD_CmdJoinBss (((siteMgr_t *)hSiteMgr)->hTWD, &joinParams);
1540}
1541
1542
1543/***********************************************************************
1544 *                        siteMgr_removeSelfSite
1545 ***********************************************************************
1546DESCRIPTION: Called by the Self connection state machine in order to remove the self site from the site table.
1547                Remove the site entry form the table and reset the primary site pointer
1548
1549
1550INPUT:      hSiteMgr    -   site mgr handle.
1551
1552OUTPUT:
1553
1554RETURN:     TI_OK on success, TI_NOK otherwise
1555
1556************************************************************************/
1557TI_STATUS siteMgr_removeSelfSite(TI_HANDLE  hSiteMgr)
1558{
1559    siteMgr_t           *pSiteMgr  = (siteMgr_t *)hSiteMgr;
1560    siteTablesParams_t  *currTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
1561
1562    if(pSiteMgr->pSitesMgmtParams->pPrimarySite == NULL)
1563    {
1564        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_WARNING, "Remove self site Failure, pointer is NULL\n\n");
1565        return TI_OK;
1566    }
1567
1568    if(pSiteMgr->pSitesMgmtParams->pPrimarySite->siteType != SITE_SELF)
1569    {
1570        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Remove self site Failure, site is not self\n\n");
1571        return TI_OK;
1572    }
1573
1574    removeSiteEntry(pSiteMgr, currTable, pSiteMgr->pSitesMgmtParams->pPrimarySite);
1575    pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
1576
1577    return TI_OK;
1578}
1579
1580/***********************************************************************
1581 *                        siteMgr_IbssMerge
1582 ***********************************************************************/
1583TI_STATUS siteMgr_IbssMerge(TI_HANDLE       hSiteMgr,
1584                          TMacAddr      	our_bssid,
1585						  TMacAddr      	new_bssid,
1586                          mlmeFrameInfo_t   *pFrameInfo,
1587                          TI_UINT8          rxChannel,
1588                          ERadioBand        band)
1589{
1590	siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
1591    siteEntry_t *pSite;
1592	paramInfo_t Param;
1593
1594	pSite = findAndInsertSiteEntry(pSiteMgr, (TMacAddr*)&our_bssid, band);
1595
1596	if(!pSite) {
1597TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_IbssMerge, cannot find our site table entry, our_bssid: %X-%X-%X-%X-%X-%X\n", 						   (our_bssid)[0], (our_bssid)[1], (our_bssid)[2], (our_bssid)[3], 						   (our_bssid)[4], (our_bssid)[5]);
1598		return TI_NOK;
1599	}
1600
1601	updateSiteInfo(pSiteMgr, pFrameInfo, pSite, rxChannel);
1602
1603	pSite->siteType = SITE_PRIMARY;
1604	pSiteMgr->pSitesMgmtParams->pPrimarySite = pSite;
1605
1606	MAC_COPY(pSite->bssid, new_bssid);
1607
1608	Param.paramType   = SITE_MGR_DESIRED_BSSID_PARAM;
1609    Param.paramLength = sizeof(TMacAddr);
1610	MAC_COPY(Param.content.siteMgrDesiredBSSID, new_bssid);
1611
1612	siteMgr_setParam ( hSiteMgr, &Param );
1613
1614	conn_ibssMerge(pSiteMgr->hConn);
1615
1616	return TI_OK;
1617}
1618
1619
1620
1621/***********************************************************************
1622 *                        siteMgr_updateSite
1623 ***********************************************************************
1624DESCRIPTION: Called by the MLME parser upon receiving a beacon or probe response.
1625            Performs the following:
1626                -   Insert the site entry into the site hash table
1627                -   Update the site information in the site table
1628                -   If the site is the primary site, it handles the PBCC algorithm if needed
1629                -   If the site is NULL (means it is the first frame received from this site)
1630                    we update the site type to be regular
1631                -   If the site type is self, we inform the self connection SM
1632                    that another station joined the network we created
1633
1634
1635INPUT:      hSiteMgr    -   site mgr handle.
1636            bssid       -   BSSID received
1637            pFrameInfo  -   Frame content after the parsing
1638            rxChannel   -   The channel on which frame was received
1639            band        -   Band on which frame was received
1640            measuring   -   Determines whether the beacon or probe response
1641                            has been received while a beacon measurement
1642                            took place
1643
1644OUTPUT:
1645
1646RETURN:     TI_OK on success, TI_NOK otherwise
1647
1648************************************************************************/
1649TI_STATUS siteMgr_updateSite(TI_HANDLE          hSiteMgr,
1650                          TMacAddr      *bssid,
1651                          mlmeFrameInfo_t   *pFrameInfo,
1652                          TI_UINT8             rxChannel,
1653                          ERadioBand       band,
1654                          TI_BOOL              measuring)
1655{
1656    siteEntry_t *pSite;
1657    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
1658    paramInfo_t param;
1659
1660
1661    /* The following is not required, since the scanCncn is responsible to check
1662        the channels validity before scanning.
1663        The problem it caused was that when 802.11d is enabled,
1664        channels that are valid for Passive only, will not be updated.*/
1665    /*if (isChannelSupprted(pSiteMgr->hRegulatoryDomain , rxChannel) == TI_FALSE)
1666    {
1667        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_WARNING, "Channel ERROR - try to register a site that its channel (=%d) isn't in the regulatory domain.\n\            registration ABORTED!!!", rxChannel);
1668        return TI_NOK;
1669    }*/
1670
1671
1672    pSite = findAndInsertSiteEntry(pSiteMgr, bssid, band);
1673
1674
1675
1676    if (pSite == NULL)
1677    {
1678        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Site Update failure, table is full, bssid: %X-%X-%X-%X-%X-%X\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1679        return TI_OK;
1680    }
1681
1682    updateSiteInfo(pSiteMgr, pFrameInfo, pSite, rxChannel);
1683
1684    switch(pSite->siteType)
1685    {
1686    case SITE_PRIMARY:
1687        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "PRIMARY site updated, bssid: %X-%X-%X-%X-%X-%X\n\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1688        if (pSiteMgr->pSitesMgmtParams->pPrimarySite == NULL)
1689        {
1690            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_updateSite: Primary Site Is NULL\n");
1691            pSite->siteType = SITE_REGULAR;
1692            break;
1693        }
1694        /* Now, if the following is TI_TRUE we perform the PBCC algorithm: */
1695        /* If the BSS type is infrastructure, &&
1696            The chosen modulation is PBCC &&
1697            The beacon modulation is not NONE &&
1698            The current data modulation is different than the beacon modulation. */
1699        if ((pSite->bssType == BSS_INFRASTRUCTURE) &&
1700            (pSiteMgr->chosenModulation == DRV_MODULATION_PBCC) &&
1701            (pSite->beaconModulation != DRV_MODULATION_NONE) &&
1702            (pSiteMgr->currentDataModulation != pSite->beaconModulation))
1703        {
1704            pSiteMgr->currentDataModulation = pSite->beaconModulation;
1705            pbccAlgorithm(pSiteMgr);
1706        }
1707
1708        /* Now handle the slot time, first check if the slot time changed since the last
1709           setting to the HAL ,and if yes set the new value */
1710        if((pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE) &&
1711           (pSite->bssType == BSS_INFRASTRUCTURE))
1712        {
1713            if (pSite->currentSlotTime != pSite->newSlotTime)
1714            {
1715                pSite->currentSlotTime = pSite->newSlotTime;
1716                TWD_CfgSlotTime (pSiteMgr->hTWD, pSite->currentSlotTime);
1717            }
1718        }
1719
1720        /* Now handle the current protection status */
1721        if((pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE) && (pSite->bssType == BSS_INFRASTRUCTURE))
1722        {
1723            param.paramType = CTRL_DATA_CURRENT_PROTECTION_STATUS_PARAM;
1724            param.content.ctrlDataProtectionEnabled = pSite->useProtection;
1725            ctrlData_setParam(pSiteMgr->hCtrlData, &param);
1726        }
1727
1728        /* Now handle the current preamble type,
1729           if desired preamble type is long, the ctrl data param should not be changed */
1730        if((pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE) &&
1731           (pSite->bssType == BSS_INFRASTRUCTURE) &&
1732           (pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType != PREAMBLE_LONG))
1733        {
1734            param.paramType = CTRL_DATA_CURRENT_PREAMBLE_TYPE_PARAM;
1735            if((pSite->preambleAssRspCap == PREAMBLE_LONG) ||
1736               (pSite->barkerPreambleType == PREAMBLE_LONG))
1737                  {
1738                param.content.ctrlDataCurrentPreambleType = PREAMBLE_LONG;
1739            }
1740            else
1741                param.content.ctrlDataCurrentPreambleType = PREAMBLE_SHORT;
1742
1743            ctrlData_setParam(pSiteMgr->hCtrlData, &param);
1744        }
1745
1746        param.paramType = CTRL_DATA_RATE_CONTROL_ENABLE_PARAM;
1747        ctrlData_setParam(pSiteMgr->hCtrlData, &param);
1748        break;
1749
1750    case SITE_NULL:
1751        pSite->siteType = SITE_REGULAR;
1752        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "REGULAR site added, bssid: %X-%X-%X-%X-%X-%X\n\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1753        break;
1754
1755    case SITE_SELF:
1756        pSite->siteType = SITE_PRIMARY;
1757        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "SELF ----> PRIMARY site , bssid: %X-%X-%X-%X-%X-%X\n\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1758        conn_ibssStaJoined(pSiteMgr->hConn);
1759        break;
1760
1761    case SITE_REGULAR:
1762        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "REGULAR site updated, bssid: %X-%X-%X-%X-%X-%X\n\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1763        break;
1764
1765    default:
1766        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Setting site type failure, bssid: %X-%X-%X-%X-%X-%X\n\n", (*bssid)[0], (*bssid)[1], (*bssid)[2], (*bssid)[3], (*bssid)[4], (*bssid)[5]);
1767        break;
1768    }
1769
1770    return TI_OK;
1771}
1772
1773/***********************************************************************
1774 *                        siteMgr_start
1775 ***********************************************************************
1776DESCRIPTION: Called by the SME SM in order to start the aging timer
1777
1778
1779INPUT:      hSiteMgr    -   site mgr handle.
1780
1781OUTPUT:
1782
1783RETURN:     TI_OK on success, TI_NOK otherwise
1784
1785************************************************************************/
1786TI_STATUS siteMgr_start(TI_HANDLE   hSiteMgr)
1787{
1788    siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
1789
1790    /* update timestamp each time aging started (needed for quiet scan) */
1791    if(pSiteMgr->pSitesMgmtParams->pPrimarySite)
1792        pSiteMgr->pSitesMgmtParams->pPrimarySite->localTimeStamp = os_timeStampMs(pSiteMgr->hOs);
1793
1794    return TI_OK;
1795}
1796
1797
1798/***********************************************************************
1799 *                        siteMgr_stop
1800 ***********************************************************************
1801DESCRIPTION: Called by the SME SM in order to stop site mgr timers
1802
1803
1804INPUT:      hSiteMgr    -   site mgr handle.
1805
1806OUTPUT:
1807
1808RETURN:     TI_OK on success, TI_NOK otherwise
1809
1810************************************************************************/
1811TI_STATUS siteMgr_stop(TI_HANDLE    hSiteMgr)
1812{
1813
1814    return TI_OK;
1815}
1816
1817
1818/***********************************************************************
1819 *                        siteMgr_updatePrimarySiteFailStatus
1820 ***********************************************************************
1821DESCRIPTION: Called by the SME SM when the connection with the primary site fails
1822                If the primary site is NULL, return.
1823
1824
1825INPUT:      hSiteMgr    -   site mgr handle.
1826            bRemoveSite -   Whether to remove the site
1827
1828OUTPUT:
1829
1830RETURN:     TI_OK on success, TI_NOK otherwise
1831
1832************************************************************************/
1833
1834TI_STATUS siteMgr_updatePrimarySiteFailStatus(TI_HANDLE hSiteMgr,
1835                                           TI_BOOL bRemoveSite)
1836{
1837    siteMgr_t           *pSiteMgr = (siteMgr_t *)hSiteMgr;
1838    siteTablesParams_t  *currTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
1839
1840    if (pSiteMgr->pSitesMgmtParams->pPrimarySite == NULL)
1841        return TI_OK;
1842
1843    TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, " SITE MGR: bRemoveSite = %d \n", bRemoveSite);
1844
1845    if (bRemoveSite)
1846    {
1847        removeSiteEntry(pSiteMgr, currTable, pSiteMgr->pSitesMgmtParams->pPrimarySite);
1848        pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
1849    }
1850    else	/* Currently never used */
1851    {
1852        pSiteMgr->pSitesMgmtParams->pPrimarySite->failStatus = STATUS_UNSPECIFIED;
1853    }
1854
1855    return TI_OK;
1856}
1857
1858
1859/***********************************************************************
1860 *                        siteMgr_isCurrentBand24
1861 ***********************************************************************
1862DESCRIPTION: The function checks the current operational mode and
1863                returns if the current band is 2.4Ghz or 5Ghz.
1864
1865INPUT:      hSiteMgr    -   site mgr handle.
1866
1867OUTPUT:
1868
1869RETURN:     TI_TRUE if current band is 2.4Ghz, TI_FALSE otherwise.
1870
1871************************************************************************/
1872TI_BOOL siteMgr_isCurrentBand24(TI_HANDLE  hSiteMgr)
1873{
1874    siteMgr_t   *pSiteMgr =     (siteMgr_t *)hSiteMgr;
1875
1876    if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
1877        return TI_FALSE;
1878
1879    return TI_TRUE; /* 802.11b supports onlty 2.4G band */
1880
1881}
1882
1883/***********************************************************************
1884 *                        removeEldestSite
1885 ***********************************************************************
1886DESCRIPTION: Called by the select when trying to create an IBSS and site table is full
1887                Remove the eldest site from the table
1888
1889INPUT:      hSiteMgr    -   site mgr handle.
1890
1891OUTPUT:
1892
1893RETURN:     TI_OK on success, TI_NOK otherwise
1894
1895************************************************************************/
1896TI_STATUS removeEldestSite(siteMgr_t *pSiteMgr)
1897{
1898    int             i;
1899    siteEntry_t     *pEldestSite = NULL, *pSiteTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->siteTable;
1900    siteTablesParams_t  *currTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
1901    TI_UINT32          currentTimsStamp = os_timeStampMs(pSiteMgr->hOs);
1902    TI_UINT32          biggestGap = 0;
1903
1904    for (i = 0; i < currTable->maxNumOfSites; i++)
1905    {
1906        if (biggestGap < ((TI_UINT32)(currentTimsStamp - pSiteTable[i].localTimeStamp)))
1907        {
1908            biggestGap = ((TI_UINT32)(currentTimsStamp - pSiteTable[i].localTimeStamp));
1909            pEldestSite = &(pSiteTable[i]);
1910        }
1911    }
1912
1913    removeSiteEntry(pSiteMgr, currTable, pEldestSite);
1914
1915    return TI_OK;
1916}
1917
1918
1919/***********************************************************************
1920 *                        update_apsd
1921 ***********************************************************************
1922DESCRIPTION:    Sets the site APSD support flag according to the
1923                beacon's capabilities vector and the WME-params IE if exists.
1924
1925INPUT:      pSite       -   Pointer to the site entry in the site table
1926            pFrameInfo  -   Frame information after the parsing
1927
1928OUTPUT:     pSite->APSDSupport flag
1929
1930RETURN:
1931
1932************************************************************************/
1933static void update_apsd(siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
1934{
1935    /* If WME-Params IE is not included in the beacon, set the APSD-Support flag
1936         only by the beacons capabilities bit map. */
1937    if (pFrameInfo->content.iePacket.WMEParams == NULL)
1938        pSite->APSDSupport = (((pFrameInfo->content.iePacket.capabilities >> CAP_APSD_SHIFT) & CAP_APSD_MASK) ? TI_TRUE : TI_FALSE);
1939
1940    /* Else, set the APSD-Support flag if either the capabilities APSD bit or the
1941         WME-Params APSD bit indicate so. */
1942    else
1943        pSite->APSDSupport = ((((pFrameInfo->content.iePacket.capabilities >> CAP_APSD_SHIFT) & CAP_APSD_MASK) ? TI_TRUE : TI_FALSE) ||
1944        (((pFrameInfo->content.iePacket.WMEParams->ACInfoField >> AP_QOS_INFO_UAPSD_SHIFT) & AP_QOS_INFO_UAPSD_MASK) ? TI_TRUE : TI_FALSE));
1945}
1946
1947
1948/***********************************************************************
1949 *                        release_module
1950 ***********************************************************************
1951DESCRIPTION:    Called by the un load function
1952                Go over the vector, for each bit that is set, release the corresponding module.
1953
1954INPUT:      pSiteMgr    -   site mgr handle.
1955            initVec -   Vector that contains a bit set for each module thah had been initiualized
1956
1957OUTPUT:
1958
1959RETURN:     TI_OK on success, TI_NOK otherwise
1960
1961************************************************************************/
1962static void release_module(siteMgr_t *pSiteMgr, TI_UINT32 initVec)
1963{
1964    if ( (initVec & (1 << MGMT_PARAMS_INIT_BIT)) && pSiteMgr->pSitesMgmtParams)
1965        os_memoryFree(pSiteMgr->hOs, pSiteMgr->pSitesMgmtParams, sizeof(sitesMgmtParams_t));
1966
1967    if ( (initVec & (1 << DESIRED_PARAMS_INIT_BIT)) && pSiteMgr->pDesiredParams)
1968        os_memoryFree(pSiteMgr->hOs, pSiteMgr->pDesiredParams, sizeof(siteMgrInitParams_t));
1969
1970    if (initVec & (1 << SITE_MGR_INIT_BIT))
1971        os_memoryFree(pSiteMgr->hOs, pSiteMgr, sizeof(siteMgr_t));
1972
1973    initVec = 0;
1974}
1975
1976
1977static TI_BOOL isIeSsidBroadcast (dot11_SSID_t *pIESsid)
1978{
1979    if ((pIESsid == NULL) || (pIESsid->hdr[1] == 0))
1980    {
1981        return TI_TRUE;
1982    }
1983
1984    /* According to 802.11, Broadcast SSID should be with length 0,
1985        however, different vendors use invalid chanrs for Broadcast SSID. */
1986    if (pIESsid->serviceSetId[0] < OS_802_11_SSID_FIRST_VALID_CHAR)
1987    {
1988        return TI_TRUE;
1989    }
1990
1991    return TI_FALSE;
1992}
1993
1994
1995/***********************************************************************
1996 *                        updateSiteInfo
1997 ***********************************************************************
1998DESCRIPTION:    Called upon receiving a beacon or probe response
1999                Go over the vector, for each bit that is set, release the corresponding module.
2000                Update theaite entry in the site table with the information received in the frame
2001
2002INPUT:      pSiteMgr    -   site mgr handle.
2003            pFrameInfo  -   Frame information after the parsing
2004            pSite       -   Pointer to the site entry in the site table
2005
2006OUTPUT:
2007
2008RETURN:     TI_OK on success, TI_NOK otherwise
2009
2010************************************************************************/
2011static void updateSiteInfo(siteMgr_t *pSiteMgr, mlmeFrameInfo_t *pFrameInfo, siteEntry_t    *pSite, TI_UINT8 rxChannel)
2012{
2013    paramInfo_t param;
2014    TI_BOOL        ssidUpdated = TI_FALSE;
2015
2016    switch (pFrameInfo->subType)
2017    {
2018    case BEACON:
2019
2020        UPDATE_BEACON_INTERVAL(pSite, pFrameInfo);
2021
2022        UPDATE_CAPABILITIES(pSite, pFrameInfo);
2023
2024
2025        /***********************************/
2026        /* Must be before UPDATE_PRIVACY and UPDATE_RSN_IE */
2027        if (pSite->ssid.len==0)
2028        {   /* Update the SSID only if the site's SSID is NULL */
2029            if (isIeSsidBroadcast(pFrameInfo->content.iePacket.pSsid) == TI_FALSE)
2030            {   /* And the SSID is not Broadcast */
2031                ssidUpdated = TI_TRUE;
2032                UPDATE_SSID(pSite, pFrameInfo);
2033            }
2034        }
2035        else if (pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len > 0)
2036        {   /* There is a desired SSID */
2037            if (pFrameInfo->content.iePacket.pSsid != NULL)
2038            {
2039                if (os_memoryCompare (pSiteMgr->hOs,
2040                                      (TI_UINT8 *)pSiteMgr->pDesiredParams->siteMgrDesiredSSID.str,
2041                                      (TI_UINT8 *)pFrameInfo->content.iePacket.pSsid->serviceSetId,
2042                                      pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len)==0)
2043                {   /* update only SSID that equals the desired SSID */
2044                    ssidUpdated = TI_TRUE;
2045                    UPDATE_SSID(pSite, pFrameInfo);
2046                }
2047            }
2048            else
2049            {
2050                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateSiteInfo BEACON, pSsid=NULL\n");
2051            }
2052        }
2053        /***********************************/
2054
2055        if (ssidUpdated)
2056        {
2057
2058            UPDATE_PRIVACY(pSite, pFrameInfo);
2059        }
2060
2061        update_apsd(pSite, pFrameInfo);
2062
2063        updatePreamble(pSiteMgr, pSite, pFrameInfo);
2064
2065        UPDATE_AGILITY(pSite, pFrameInfo);
2066
2067
2068        if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
2069        {
2070            UPDATE_SLOT_TIME(pSite, pFrameInfo);
2071            UPDATE_PROTECTION(pSite, pFrameInfo);
2072        }
2073
2074        /* Updating HT params */
2075        siteMgr_UpdatHtParams (pSiteMgr, pSite, pFrameInfo);
2076
2077        updateRates(pSiteMgr, pSite, pFrameInfo);
2078
2079        if ((pFrameInfo->content.iePacket.pDSParamsSet != NULL)  &&
2080            (pFrameInfo->content.iePacket.pDSParamsSet->currChannel!=rxChannel))
2081        {
2082            TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateSiteInfo, wrong CHANNELS:rxChannel=%d,currChannel=%d\n", rxChannel, pFrameInfo->content.iePacket.pDSParamsSet->currChannel);
2083        }
2084        else
2085            UPDATE_CHANNEL(pSite, pFrameInfo , rxChannel);
2086
2087
2088        UPDATE_BSS_TYPE(pSite, pFrameInfo);
2089
2090        if (pSite->bssType == BSS_INFRASTRUCTURE)
2091            UPDATE_DTIM_PERIOD(pSite, pFrameInfo);
2092
2093        UPDATE_ATIM_WINDOW(pSite, pFrameInfo);
2094
2095        UPDATE_BEACON_AP_TX_POWER(pSite, pFrameInfo);
2096
2097        /* Updating QoS params */
2098        updateBeaconQosParams(pSiteMgr, pSite, pFrameInfo);
2099
2100
2101        /* updating CountryIE  */
2102        if ((pFrameInfo->content.iePacket.country  != NULL) &&
2103			(pFrameInfo->content.iePacket.country->hdr[1] != 0))
2104        {
2105            /* set the country info in the regulatory domain - If a different code was detected earlier
2106               the regDomain will ignore it */
2107            param.paramType = REGULATORY_DOMAIN_COUNTRY_PARAM;
2108            param.content.pCountry = (TCountry *)pFrameInfo->content.iePacket.country;
2109            regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&param);
2110        }
2111
2112        /* Updating WSC params */
2113        updateWSCParams(pSiteMgr, pSite, pFrameInfo);
2114
2115        UPDATE_LOCAL_TIME_STAMP(pSiteMgr, pSite, pFrameInfo);
2116
2117        UPDATE_BEACON_MODULATION(pSite, pFrameInfo);
2118
2119        /* If the BSS type is independent, the beacon & probe modulation are equal,
2120            It is important to update this field here for dynamic PBCC algorithm compatibility */
2121        if (pSite->bssType == BSS_INDEPENDENT)
2122            UPDATE_PROBE_MODULATION(pSite, pFrameInfo);
2123
2124
2125        if (pSite->siteType == SITE_PRIMARY)
2126        {
2127
2128            if (pSiteMgr->pSitesMgmtParams->pPrimarySite == NULL)
2129            {
2130                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateSiteInfo: Primary Site Is NULL\n");
2131                pSite->siteType = SITE_REGULAR;
2132            }
2133            else
2134            {
2135                /*  If the site that we got the beacon on is the primary site - which means we are either trying */
2136                /*  to connect to it or we are already connected - send the EVENT_GOT_BEACON to the conn module (through the SME module) */
2137                /*  so the conn module will be aware of the beacon status of the site it's trying to connect to */
2138
2139#ifdef XCC_MODULE_INCLUDED
2140                TI_INT8 ExternTxPower;
2141
2142                if (pFrameInfo->content.iePacket.cellTP != NULL)
2143                {
2144                    ExternTxPower = pFrameInfo->content.iePacket.cellTP->power;
2145                }
2146                else	/* Set to maximum possible. Note that we add +1 so that Dbm = 26 and not 25 */
2147                {
2148                    ExternTxPower = MAX_TX_POWER / DBM_TO_TX_POWER_FACTOR + 1;
2149                }
2150
2151                param.paramType = REGULATORY_DOMAIN_EXTERN_TX_POWER_PREFERRED;
2152                param.content.ExternTxPowerPreferred = ExternTxPower;
2153                regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain, &param);
2154#endif
2155
2156                /* Updating the Tx Power according to the received Power Constraint  */
2157                if(pFrameInfo->content.iePacket.powerConstraint  != NULL)
2158                {   /* Checking if the recieved constraint is different from the one that is already known  */
2159                    if( pFrameInfo->content.iePacket.powerConstraint->powerConstraint != pSite->powerConstraint)
2160                    {   /* check if Spectrum Management is enabled */
2161                        param.paramType = REGULATORY_DOMAIN_MANAGEMENT_CAPABILITY_ENABLED_PARAM;
2162                        regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
2163                        if(param.content.spectrumManagementEnabled)
2164                        {   /* setting power constraint */
2165                            pSite->powerConstraint = pFrameInfo->content.iePacket.powerConstraint->powerConstraint;
2166                            param.paramType = REGULATORY_DOMAIN_SET_POWER_CONSTRAINT_PARAM;
2167                            param.content.powerConstraint = pSite->powerConstraint;
2168                            regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&param);
2169
2170                        }
2171                    }
2172                }
2173                /* update HT Information IE at the FW whenever any of its relevant fields is changed. */
2174                if (pSite->bHtInfoUpdate == TI_TRUE)
2175                {
2176                    TI_BOOL b11nEnable, bWmeEnable;
2177
2178                    /* verify 11n_Enable and Chip type */
2179                    StaCap_IsHtEnable (pSiteMgr->hStaCap, &b11nEnable);
2180
2181                    /* verify that WME flag enable */
2182                    qosMngr_GetWmeEnableFlag (pSiteMgr->hQosMngr, &bWmeEnable);
2183
2184                    if ((b11nEnable != TI_FALSE) && (bWmeEnable != TI_FALSE))
2185                    {
2186                        TWD_CfgSetFwHtInformation (pSiteMgr->hTWD, &pSite->tHtInformation);
2187                    }
2188                }
2189            }
2190        }
2191
2192        UPDATE_BEACON_RECV(pSite);
2193
2194        if (ssidUpdated)
2195        {
2196            dot11_RSN_t *pRsnIe = pFrameInfo->content.iePacket.pRsnIe;
2197            TI_UINT8       rsnIeLen = pFrameInfo->content.iePacket.rsnIeLen;
2198            UPDATE_RSN_IE(pSite, pRsnIe, rsnIeLen);
2199        }
2200
2201        UPDATE_BEACON_TIMESTAMP(pSiteMgr, pSite, pFrameInfo);
2202
2203
2204
2205        TWD_UpdateDtimTbtt (pSiteMgr->hTWD, pSite->dtimPeriod, pSite->beaconInterval);
2206
2207        break;
2208
2209
2210    case PROBE_RESPONSE:
2211
2212        UPDATE_BEACON_INTERVAL(pSite, pFrameInfo);
2213
2214        UPDATE_CAPABILITIES(pSite, pFrameInfo);
2215
2216                ssidUpdated = TI_TRUE;
2217        if (pSite->siteType == SITE_PRIMARY)
2218        {   /* Primary SITE */
2219            if (pFrameInfo->content.iePacket.pSsid != NULL &&
2220                pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len > 0)
2221            {   /* There's a desired SSID*/
2222                if (os_memoryCompare (pSiteMgr->hOs,
2223                                      (TI_UINT8*)pSiteMgr->pDesiredParams->siteMgrDesiredSSID.str,
2224                                      (TI_UINT8*)pFrameInfo->content.iePacket.pSsid->serviceSetId,
2225                                      pFrameInfo->content.iePacket.pSsid->hdr[1])!=0)
2226                {   /* Do not overwrite the primary site's SSID with a different than the desired SSID*/
2227                    ssidUpdated = TI_FALSE;
2228                }
2229
2230            }
2231            else if (pFrameInfo->content.iePacket.pSsid == NULL)
2232            {
2233                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateSiteInfo PROBE_RESP, pSsid=NULL\n");
2234            }
2235        }
2236
2237        if (ssidUpdated)
2238        {
2239            UPDATE_SSID(pSite, pFrameInfo);
2240            UPDATE_PRIVACY(pSite, pFrameInfo);
2241        }
2242
2243        update_apsd(pSite, pFrameInfo);
2244
2245
2246        if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
2247        {
2248            UPDATE_PROTECTION(pSite, pFrameInfo);
2249        }
2250
2251        updatePreamble(pSiteMgr, pSite, pFrameInfo);
2252
2253        UPDATE_AGILITY(pSite, pFrameInfo);
2254
2255        /* Updating HT params */
2256        siteMgr_UpdatHtParams (pSiteMgr, pSite, pFrameInfo);
2257
2258        updateRates(pSiteMgr, pSite, pFrameInfo);
2259
2260        if ((pFrameInfo->content.iePacket.pDSParamsSet != NULL)  &&
2261            (pFrameInfo->content.iePacket.pDSParamsSet->currChannel!=rxChannel))
2262        {
2263            TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateSiteInfo, wrong CHANNELS:rxChannel=%d,currChannel=%d\n", rxChannel, pFrameInfo->content.iePacket.pDSParamsSet->currChannel);
2264        }
2265        else
2266            UPDATE_CHANNEL(pSite, pFrameInfo, rxChannel);
2267
2268
2269        UPDATE_BSS_TYPE(pSite, pFrameInfo);
2270
2271        UPDATE_ATIM_WINDOW(pSite, pFrameInfo);
2272
2273        UPDATE_PROBE_AP_TX_POWER(pSite, pFrameInfo);
2274
2275        /* Updating WME params */
2276        updateProbeQosParams(pSiteMgr, pSite, pFrameInfo);
2277
2278
2279        /* updating CountryIE  */
2280        if ((pFrameInfo->content.iePacket.country  != NULL) &&
2281			(pFrameInfo->content.iePacket.country->hdr[1] != 0))
2282        {
2283            /* set the country info in the regulatory domain - If a different code was detected earlier
2284               the regDomain will ignore it */
2285            param.paramType = REGULATORY_DOMAIN_COUNTRY_PARAM;
2286            param.content.pCountry = (TCountry *)pFrameInfo->content.iePacket.country;
2287            regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&param);
2288        }
2289
2290        /* Updating WSC params */
2291        updateWSCParams(pSiteMgr, pSite, pFrameInfo);
2292
2293        UPDATE_LOCAL_TIME_STAMP(pSiteMgr, pSite, pFrameInfo);
2294
2295        UPDATE_PROBE_MODULATION(pSite, pFrameInfo);
2296
2297        /* If the BSS type is independent, the beacon & probe modulation are equal,
2298            It is important to update this field here for dynamic PBCC algorithm compatibility */
2299        if (pSite->bssType == BSS_INDEPENDENT)
2300            UPDATE_BEACON_MODULATION(pSite, pFrameInfo);
2301
2302        UPDATE_PROBE_RECV(pSite);
2303
2304        if (ssidUpdated)
2305        {
2306            dot11_RSN_t *pRsnIe = pFrameInfo->content.iePacket.pRsnIe;
2307            TI_UINT8       rsnIeLen = pFrameInfo->content.iePacket.rsnIeLen;
2308            UPDATE_RSN_IE(pSite, pRsnIe, rsnIeLen);
2309
2310        }
2311
2312        UPDATE_BEACON_TIMESTAMP(pSiteMgr, pSite, pFrameInfo);
2313
2314        break;
2315
2316    default:
2317        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Site Update failure, un known frame sub type %d\n\n", pFrameInfo->subType);
2318        break;
2319    }
2320}
2321
2322/***********************************************************************
2323 *                        updatePreamble
2324 ***********************************************************************
2325DESCRIPTION:    Called by the function 'updateSiteInfo()'
2326
2327INPUT:      pSiteMgr    -   site mgr handle.
2328            pFrameInfo  -   Frame information after the parsing
2329            pSite       -   Pointer to the site entry in the site table
2330
2331OUTPUT:
2332
2333RETURN:
2334
2335************************************************************************/
2336static void updatePreamble(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2337{
2338    pSite->currentPreambleType = ((pFrameInfo->content.iePacket.capabilities >> CAP_PREAMBLE_SHIFT) & CAP_PREAMBLE_MASK) ? PREAMBLE_SHORT : PREAMBLE_LONG;
2339
2340    pSite->barkerPreambleType = pFrameInfo->content.iePacket.barkerPreambleMode;
2341}
2342
2343/***********************************************************************
2344 *                        updateBeaconQosParams
2345 ***********************************************************************
2346DESCRIPTION:    Called by the function 'updateSiteInfo()'
2347
2348INPUT:      pSiteMgr    -   site mgr handle.
2349            pFrameInfo  -   Frame information after the parsing
2350            pSite       -   Pointer to the site entry in the site table
2351
2352OUTPUT:
2353
2354RETURN:
2355
2356************************************************************************/
2357
2358static void updateBeaconQosParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2359{
2360    /* Updating WME params */
2361    if (pFrameInfo->content.iePacket.WMEParams  != NULL)
2362    {
2363        /* Checking if this is IE includes new WME Parameters */
2364        if(( ((pFrameInfo->content.iePacket.WMEParams->ACInfoField) & dot11_WME_ACINFO_MASK ) != pSite->lastWMEParameterCnt) ||
2365            (!pSite->WMESupported) )
2366        {
2367            pSite->WMESupported = TI_TRUE;
2368
2369            /* Checking if this IE is information only or is a paremeters IE */
2370            if(pFrameInfo->content.iePacket.WMEParams->OUISubType == dot11_WME_OUI_SUB_TYPE_PARAMS_IE)
2371            {
2372                if(pSite->siteType == SITE_PRIMARY)
2373                {
2374                    qosMngr_updateIEinfo(pSiteMgr->hQosMngr,(TI_UINT8 *)(pFrameInfo->content.iePacket.WMEParams), QOS_WME);
2375                }
2376                /* updating the QOS_WME paraeters into the site table. */
2377                os_memoryCopy(pSiteMgr->hOs, &pSite->WMEParameters, &(pFrameInfo->content.iePacket.WMEParams->WME_ACParameteres), sizeof( dot11_ACParameters_t));
2378                pSite->lastWMEParameterCnt = (pFrameInfo->content.iePacket.WMEParams->ACInfoField) & dot11_WME_ACINFO_MASK;
2379                TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "$$$$$$ QOS_WME parameters were updates according to beacon, cntSeq = %d\n",pSite->lastWMEParameterCnt);
2380            }
2381        }
2382    }else
2383    {
2384        pSite->WMESupported = TI_FALSE;
2385        }
2386
2387}
2388
2389/***********************************************************************
2390 *                        updateProbeQosParams
2391 ***********************************************************************
2392DESCRIPTION:    Called by the function 'updateSiteInfo()'
2393
2394INPUT:      pSiteMgr    -   site mgr handle.
2395            pFrameInfo  -   Frame information after the parsing
2396            pSite       -   Pointer to the site entry in the site table
2397
2398OUTPUT:
2399
2400RETURN:
2401
2402************************************************************************/
2403static void updateProbeQosParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2404{
2405    /* Updating QOS_WME params */
2406    if (pFrameInfo->content.iePacket.WMEParams  != NULL)
2407    {
2408        /* Checking if this is IE includes new QOS_WME Parameters */
2409        if(( ((pFrameInfo->content.iePacket.WMEParams->ACInfoField) & dot11_WME_ACINFO_MASK ) != pSite->lastWMEParameterCnt) ||
2410            (!pSite->WMESupported) )
2411        {
2412            pSite->WMESupported = TI_TRUE;
2413
2414            /* Checking if this IE is information only or is a paremeters IE */
2415            if(pFrameInfo->content.iePacket.WMEParams->OUISubType == dot11_WME_OUI_SUB_TYPE_PARAMS_IE)
2416            {
2417                if(pSite->siteType == SITE_PRIMARY)
2418                {
2419                    qosMngr_updateIEinfo(pSiteMgr->hQosMngr,(TI_UINT8 *)(pFrameInfo->content.iePacket.WMEParams),QOS_WME);
2420                }
2421                /* updating the QOS_WME paraeters into the site table. */
2422                os_memoryCopy(pSiteMgr->hOs, &pSite->WMEParameters, &(pFrameInfo->content.iePacket.WMEParams->WME_ACParameteres), sizeof( dot11_ACParameters_t));
2423                pSite->lastWMEParameterCnt = (pFrameInfo->content.iePacket.WMEParams->ACInfoField) & dot11_WME_ACINFO_MASK;
2424                TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "$$$$$$ QOS_WME parameters were updates according to  probe response, cntSeq = %d\n",pSite->lastWMEParameterCnt);
2425            }
2426        }
2427    }else
2428    {
2429        pSite->WMESupported = TI_FALSE;
2430        }
2431
2432}
2433
2434/***********************************************************************
2435 *                        siteMgr_UpdatHtParams
2436 ***********************************************************************
2437DESCRIPTION:    Called by the function 'updateSiteInfo()'
2438
2439INPUT:      pSiteMgr    -   site mgr handle.
2440            pSite       -   Pointer to the site entry in the site table
2441            pFrameInfo  -   Frame information after the parsing
2442
2443OUTPUT:
2444
2445RETURN:
2446
2447************************************************************************/
2448static void siteMgr_UpdatHtParams (siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2449{
2450    /* Updating HT capabilites IE params */
2451    if (pFrameInfo->content.iePacket.pHtCapabilities != NULL)
2452    {
2453	   /* updating the HT capabilities unparse format into the site table. */
2454       os_memoryCopy (pSiteMgr->hOs, &pSite->tHtCapabilities,
2455                      (TI_UINT8 *)(pFrameInfo->content.iePacket.pHtCapabilities),
2456                      sizeof(Tdot11HtCapabilitiesUnparse));
2457
2458       TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION , "$$$$$$ HT capabilites parameters were updates.\n");
2459    }
2460    else
2461    {
2462        pSite->tHtCapabilities.tHdr[0] = TI_FALSE;
2463    }
2464
2465    /* Updating HT Information IE params */
2466	if (pFrameInfo->content.iePacket.pHtInformation != NULL)
2467	{
2468	   /* update in case different setting vlaue from the last one */
2469       if (os_memoryCompare (pSiteMgr->hOs,
2470                             (TI_UINT8 *)&pSite->tHtInformation,
2471                             (TI_UINT8 *)pFrameInfo->content.iePacket.pHtInformation,
2472                             sizeof(Tdot11HtInformationUnparse)) != 0)
2473       {
2474           pSite->bHtInfoUpdate = TI_TRUE;
2475           /* updating the HT Information unparse pormat into the site table. */
2476           os_memoryCopy (pSiteMgr->hOs, &pSite->tHtInformation, pFrameInfo->content.iePacket.pHtInformation, sizeof(Tdot11HtInformationUnparse));
2477           TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION , "$$$$$$ HT Information parameters were updates.\n");
2478       }
2479       else
2480       {
2481           pSite->bHtInfoUpdate = TI_FALSE;
2482       }
2483    }
2484	else
2485    {
2486		pSite->tHtInformation.tHdr[0] = TI_FALSE;
2487    }
2488}
2489
2490
2491/***********************************************************************
2492 *                        updateWSCParams
2493 ***********************************************************************
2494DESCRIPTION:    Called by the function 'updateSiteInfo()'
2495
2496INPUT:      pSiteMgr    -   site mgr handle.
2497            pFrameInfo  -   Frame information after the parsing
2498            pSite       -   Pointer to the site entry in the site table
2499
2500OUTPUT:
2501
2502RETURN:
2503
2504************************************************************************/
2505static void updateWSCParams(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2506{
2507   int res;
2508
2509   TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "updateWSCParams called (BSSID: %X-%X-%X-%X-%X-%X)\n",pSite->bssid[0], pSite->bssid[1], pSite->bssid[2], pSite->bssid[3], pSite->bssid[4], pSite->bssid[5]);
2510
2511	/* if the IE is not null => the WSC is on - check which method is supported */
2512	if (pFrameInfo->content.iePacket.WSCParams  != NULL)
2513	{
2514         res = parseWscMethodFromIE (pSiteMgr, pFrameInfo->content.iePacket.WSCParams, &pSite->WSCSiteMode);
2515
2516         TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "pSite->WSCSiteMode = %d\n",pSite->WSCSiteMode);
2517	}
2518	else
2519	{
2520			pSite->WSCSiteMode = TIWLN_SIMPLE_CONFIG_OFF;
2521	}
2522
2523}
2524
2525static int parseWscMethodFromIE (siteMgr_t *pSiteMgr, dot11_WSC_t *WSCParams, TIWLN_SIMPLE_CONFIG_MODE *pSelectedMethod)
2526{
2527   TI_UINT8 *tlvPtr,*endPtr;
2528   TI_UINT16   tlvPtrType,tlvPtrLen,selectedMethod=0;
2529
2530   tlvPtr = (TI_UINT8*)WSCParams->WSCBeaconOrProbIE;
2531   endPtr = tlvPtr + WSCParams->hdr[1] - (DOT11_OUI_LEN + 1);
2532
2533   do
2534   {
2535      os_memoryCopy (pSiteMgr->hOs, (void *)&tlvPtrType, (void *)tlvPtr, 2);
2536      tlvPtrType = WLANTOHS(tlvPtrType);
2537
2538      /*if (tlvPtrType == DOT11_WSC_SELECTED_REGISTRAR_CONFIG_METHODS)*/
2539      if (tlvPtrType == DOT11_WSC_DEVICE_PASSWORD_ID)
2540      {
2541         tlvPtr+=2;
2542         tlvPtr+=2;
2543         os_memoryCopy (pSiteMgr->hOs, (void *)&selectedMethod, (void *)tlvPtr, 2);
2544         selectedMethod = WLANTOHS (selectedMethod);
2545         break;
2546      }
2547      else
2548      {
2549         tlvPtr+=2;
2550         os_memoryCopy (pSiteMgr->hOs, (void *)&tlvPtrLen, (void *)tlvPtr, 2);
2551         tlvPtrLen = WLANTOHS (tlvPtrLen);
2552         tlvPtr+=tlvPtrLen+2;
2553      }
2554   } while ((tlvPtr < endPtr) && (selectedMethod == 0));
2555
2556   if (tlvPtr >= endPtr)
2557   {
2558      return TI_NOK;
2559   }
2560
2561   if (selectedMethod == DOT11_WSC_DEVICE_PASSWORD_ID_PIN)
2562      *pSelectedMethod = TIWLN_SIMPLE_CONFIG_PIN_METHOD;
2563   else if (selectedMethod == DOT11_WSC_DEVICE_PASSWORD_ID_PBC)
2564      *pSelectedMethod = TIWLN_SIMPLE_CONFIG_PBC_METHOD;
2565   else return TI_NOK;
2566
2567   return TI_OK;
2568}
2569
2570
2571/***********************************************************************
2572 *                        updateRates
2573 ***********************************************************************
2574DESCRIPTION:    Called by the function 'updateSiteInfo()' in order to translate the rates received
2575                in the beacon or probe response to rate used by the driver. Perfoms the following:
2576                    -   Check the rates validity. If rates are invalid, return
2577                    -   Get the max active rate & max basic rate, if invalid, return
2578                    -   Translate the max active rate and max basic rate from network rates to host rates.
2579                        The max active & max basic rate are used by the driver from now on in all the processes:
2580                        (selection, join, transmission, etc....)
2581
2582INPUT:      pSiteMgr    -   site mgr handle.
2583            pFrameInfo  -   Frame information after the parsing
2584            pSite       -   Pointer to the site entry in the site table
2585
2586OUTPUT:
2587
2588RETURN:     TI_OK on success, TI_NOK otherwise
2589
2590************************************************************************/
2591static void updateRates(siteMgr_t *pSiteMgr, siteEntry_t *pSite, mlmeFrameInfo_t *pFrameInfo)
2592{
2593    TI_UINT8   maxBasicRate = 0, maxActiveRate = 0;
2594    TI_UINT32  bitMapExtSupp = 0;
2595    paramInfo_t param;
2596    TI_UINT32   uMcsbasicRateMask, uMcsSupportedRateMask;
2597
2598    if (pFrameInfo->content.iePacket.pRates == NULL)
2599    {
2600        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "updateRates, pRates=NULL, beacon & probeResp are: \n");
2601        return;
2602    }
2603
2604    /* Update the rate elements */
2605    maxBasicRate = rate_GetMaxBasicFromStr ((TI_UINT8 *)pFrameInfo->content.iePacket.pRates->rates,pFrameInfo->content.iePacket.pRates->hdr[1], maxBasicRate);
2606    maxActiveRate = rate_GetMaxActiveFromStr ((TI_UINT8 *)pFrameInfo->content.iePacket.pRates->rates,pFrameInfo->content.iePacket.pRates->hdr[1], maxActiveRate);
2607
2608    if(pFrameInfo->content.iePacket.pExtRates)
2609    {
2610        maxBasicRate = rate_GetMaxBasicFromStr ((TI_UINT8 *)pFrameInfo->content.iePacket.pExtRates->rates,pFrameInfo->content.iePacket.pExtRates->hdr[1], maxBasicRate);
2611        maxActiveRate = rate_GetMaxActiveFromStr ((TI_UINT8 *)pFrameInfo->content.iePacket.pExtRates->rates,pFrameInfo->content.iePacket.pExtRates->hdr[1], maxActiveRate);
2612    }
2613
2614
2615    /*
2616TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "1- maxBasicRate = 0x%X, maxActiveRate = 0x%X \n", maxBasicRate,maxActiveRate);
2617	*/
2618
2619    if (maxActiveRate == 0)
2620        maxActiveRate = maxBasicRate;
2621
2622    /* Now update it from network to host rates */
2623    pSite->maxBasicRate = rate_NetToDrv (maxBasicRate);
2624    pSite->maxActiveRate = rate_NetToDrv (maxActiveRate);
2625
2626    /* for now we use constat MCS rate */
2627    if (pFrameInfo->content.iePacket.pHtInformation != NULL)
2628    {
2629        pSite->maxBasicRate = DRV_RATE_MCS_7;
2630        pSite->maxActiveRate = DRV_RATE_MCS_7;
2631    }
2632
2633    if (pSite->maxActiveRate == DRV_RATE_INVALID)
2634            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Network To Host Rate failure, no active network rate\n");
2635
2636    if (pSite->maxBasicRate != DRV_RATE_INVALID)
2637    {
2638        if (pSite->maxActiveRate != DRV_RATE_INVALID)
2639        {
2640            pSite->maxActiveRate = TI_MAX (pSite->maxActiveRate, pSite->maxBasicRate);
2641        }
2642    } else { /* in case some vendors don't specify basic rates */
2643        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_WARNING, "Network To Host Rate failure, no basic network rate");
2644        pSite->maxBasicRate = pSite->maxActiveRate;
2645    }
2646
2647    /* build rates bit map */
2648    rate_NetStrToDrvBitmap (&pSite->rateMask.supportedRateMask,
2649                            pFrameInfo->content.iePacket.pRates->rates,
2650                            pFrameInfo->content.iePacket.pRates->hdr[1]);
2651    rate_NetBasicStrToDrvBitmap (&pSite->rateMask.basicRateMask,
2652                                 pFrameInfo->content.iePacket.pRates->rates,
2653                                 pFrameInfo->content.iePacket.pRates->hdr[1]);
2654
2655    if(pFrameInfo->content.iePacket.pExtRates)
2656    {
2657        rate_NetStrToDrvBitmap (&bitMapExtSupp,
2658                                pFrameInfo->content.iePacket.pExtRates->rates,
2659                                       pFrameInfo->content.iePacket.pExtRates->hdr[1]);
2660
2661        pSite->rateMask.supportedRateMask |= bitMapExtSupp;
2662
2663        rate_NetBasicStrToDrvBitmap (&bitMapExtSupp,
2664                                     pFrameInfo->content.iePacket.pExtRates->rates,
2665                                        pFrameInfo->content.iePacket.pExtRates->hdr[1]);
2666
2667        pSite->rateMask.basicRateMask |= bitMapExtSupp;
2668    }
2669
2670
2671    if (pFrameInfo->content.iePacket.pHtCapabilities != NULL)
2672    {
2673        /* MCS build rates bit map */
2674        rate_McsNetStrToDrvBitmap (&uMcsSupportedRateMask,
2675                                   (pFrameInfo->content.iePacket.pHtCapabilities->aHtCapabilitiesIe + DOT11_HT_CAPABILITIES_MCS_RATE_OFFSET));
2676
2677        pSite->rateMask.supportedRateMask |= uMcsSupportedRateMask;
2678    }
2679
2680    if (pFrameInfo->content.iePacket.pHtInformation != NULL)
2681    {
2682        /* MCS build rates bit map */
2683        rate_McsNetStrToDrvBitmap (&uMcsbasicRateMask,
2684                                   (pFrameInfo->content.iePacket.pHtInformation->aHtInformationIe + DOT11_HT_INFORMATION_MCS_RATE_OFFSET));
2685
2686        pSite->rateMask.basicRateMask |= uMcsbasicRateMask;
2687    }
2688
2689
2690    param.paramType = CTRL_DATA_CURRENT_SUPPORTED_RATE_MASK_PARAM;
2691    param.content.ctrlDataCurrentRateMask = pSite->rateMask.supportedRateMask;
2692    /* clear the 22Mbps bit in case the PBCC is not allowed */
2693    if(pSiteMgr->currentDataModulation != DRV_MODULATION_PBCC && pSiteMgr->currentDataModulation != DRV_MODULATION_OFDM)
2694    {
2695      param.content.ctrlDataCurrentRateMask &= ~DRV_RATE_MASK_22_PBCC;
2696    }
2697    ctrlData_setParam(pSiteMgr->hCtrlData, &param);
2698}
2699
2700/***********************************************************************
2701 *                        getPrimaryBssid
2702 ***********************************************************************
2703DESCRIPTION:    Called by the OS abstraction layer in order to get the BSSID list from the site table
2704
2705INPUT:      pSiteMgr    -   site mgr handle.
2706
2707OUTPUT:     bssidList   -   BSSID list pointer
2708
2709RETURN:
2710
2711************************************************************************/
2712static TI_STATUS getPrimaryBssid(siteMgr_t *pSiteMgr, OS_802_11_BSSID_EX *primaryBssid, TI_UINT32 *pLength)
2713{
2714    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
2715    TI_UINT32                  len, firstOFDMloc = 0;
2716    OS_802_11_FIXED_IEs     *pFixedIes;
2717    OS_802_11_VARIABLE_IEs  *pVarIes;
2718    TI_UINT32                  length;
2719
2720
2721    if ((primaryBssid==NULL) || (pLength==NULL))
2722    {
2723        *pLength = 0;
2724        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "getPrimaryBssid, one of the ptr is NULL, primaryBssid=%p, pLength is NULL\n", primaryBssid);
2725        return TI_NOK;
2726
2727    }
2728
2729    if (pPrimarySite==NULL)
2730    {
2731        *pLength = 0;
2732        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "getPrimaryBssid, pPrimarySite is NULL \n");
2733        return TI_NOK;
2734
2735    }
2736    length = pPrimarySite->beaconLength + sizeof(OS_802_11_BSSID_EX) + sizeof(OS_802_11_FIXED_IEs);
2737    if (length > *pLength)
2738    {
2739        TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "getPrimaryBssid, insufficient length,  required length=%d, pLength=%d \n", length, *pLength);
2740        *pLength = length;
2741
2742        return TI_NOK;
2743    }
2744
2745    TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Entering getPrimaryBssid, length = %d\n", *pLength);
2746
2747    primaryBssid->Length = length;
2748    /* MacAddress */
2749    MAC_COPY (primaryBssid->MacAddress, pPrimarySite->bssid);
2750
2751    /* Capabilities */
2752    primaryBssid->Capabilities = pPrimarySite->capabilities;
2753
2754    /* SSID */
2755    os_memoryZero(pSiteMgr->hOs, primaryBssid->Ssid.Ssid, MAX_SSID_LEN);
2756    if (pPrimarySite->ssid.len > MAX_SSID_LEN)
2757    {
2758        pPrimarySite->ssid.len = MAX_SSID_LEN;
2759    }
2760    os_memoryCopy (pSiteMgr->hOs,
2761                   (void *)primaryBssid->Ssid.Ssid,
2762                   (void *)pPrimarySite->ssid.str,
2763                   pPrimarySite->ssid.len);
2764    primaryBssid->Ssid.SsidLength = pPrimarySite->ssid.len;
2765
2766    /* privacy */
2767    primaryBssid->Privacy = pPrimarySite->privacy;
2768
2769    /* RSSI */
2770    primaryBssid->Rssi = pPrimarySite->rssi;
2771
2772    /* NetworkTypeInUse & SupportedRates */
2773    /* SupportedRates */
2774    os_memoryZero(pSiteMgr->hOs, (void *)primaryBssid->SupportedRates, sizeof(OS_802_11_RATES_EX));
2775
2776    rate_DrvBitmapToNetStr (pPrimarySite->rateMask.supportedRateMask,
2777                            pPrimarySite->rateMask.basicRateMask,
2778                            (TI_UINT8 *)primaryBssid->SupportedRates,
2779                            &len,
2780                            &firstOFDMloc);
2781
2782    /* set network type acording to band and rates */
2783    if (pPrimarySite->channel <= SITE_MGR_CHANNEL_B_G_MAX)
2784    {
2785        if (firstOFDMloc == len)
2786        {
2787            primaryBssid->NetworkTypeInUse = os802_11DS;
2788        } else {
2789            primaryBssid->NetworkTypeInUse = os802_11OFDM24;
2790        }
2791    } else {
2792        primaryBssid->NetworkTypeInUse = os802_11OFDM5;
2793    }
2794
2795    /* Configuration */
2796    primaryBssid->Configuration.Length = sizeof(OS_802_11_CONFIGURATION);
2797    primaryBssid->Configuration.BeaconPeriod = pPrimarySite->beaconInterval;
2798    primaryBssid->Configuration.ATIMWindow = pPrimarySite->atimWindow;
2799    primaryBssid->Configuration.Union.channel = Chan2Freq(pPrimarySite->channel);
2800
2801    /* InfrastructureMode */
2802    if  (pPrimarySite->bssType == BSS_INDEPENDENT)
2803        primaryBssid->InfrastructureMode = os802_11IBSS;
2804    else
2805        primaryBssid->InfrastructureMode = os802_11Infrastructure;
2806    primaryBssid->IELength = 0;
2807
2808    /* copy fixed IEs from site entry */
2809    pFixedIes = (OS_802_11_FIXED_IEs*)&primaryBssid->IEs[primaryBssid->IELength];
2810    os_memoryCopy(pSiteMgr->hOs, (void *)pFixedIes->TimeStamp, (void *)&pPrimarySite->tsfTimeStamp, TIME_STAMP_LEN);
2811    pFixedIes->BeaconInterval = pPrimarySite->beaconInterval;
2812    pFixedIes->Capabilities = pPrimarySite->capabilities;
2813    primaryBssid->IELength += sizeof(OS_802_11_FIXED_IEs);
2814    pVarIes = (OS_802_11_VARIABLE_IEs*)&primaryBssid->IEs[primaryBssid->IELength];
2815
2816    /* Copy all variable IEs */
2817    TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Copy all variable beaconLength=%d, IELength=%d\n", pPrimarySite->beaconLength, primaryBssid->IELength);
2818    TRACE_INFO_HEX(pSiteMgr->hReport, pPrimarySite->beaconBuffer, pPrimarySite->beaconLength);
2819
2820    os_memoryCopy(pSiteMgr->hOs, pVarIes, pPrimarySite->beaconBuffer, pPrimarySite->beaconLength);
2821
2822    primaryBssid->IELength += pPrimarySite->beaconLength;
2823
2824
2825    primaryBssid->Length = sizeof(OS_802_11_BSSID_EX) + primaryBssid->IELength - 1;
2826
2827    TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "BSSID MAC = %x-%x-%x-%x-%x-%x\n", primaryBssid->MacAddress[0], primaryBssid->MacAddress[1], primaryBssid->MacAddress[2], primaryBssid->MacAddress[3], primaryBssid->MacAddress[4], primaryBssid->MacAddress[5]);
2828
2829
2830    TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "primaryBssid is\n");
2831    TRACE_INFO_HEX(pSiteMgr->hReport, (TI_UINT8*)primaryBssid, primaryBssid->Length);
2832
2833
2834    TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Exiting getBssidList, length =%d, IELength=%d \n", primaryBssid->Length, primaryBssid->IELength);
2835
2836    *pLength = primaryBssid->Length;
2837
2838    return TI_OK;
2839}
2840
2841#ifdef REPORT_LOG
2842/***********************************************************************
2843 *                        siteMgr_printPrimarySiteDesc
2844 ***********************************************************************
2845DESCRIPTION:    Called by the OS abstraction layer in order to get the primary site description
2846
2847INPUT:      pSiteMgr            -   site mgr handle.
2848            supplyExtendedInfo  - If OS_802_11_BSSID_EX structure should be used (extended info)
2849                                  (Assuming that if this function is called with TI_TRUE, enough memory was allocated to hold the extended info)
2850
2851OUTPUT:     pPrimarySiteDesc    -   Primary site description pointer
2852
2853RETURN:
2854
2855************************************************************************/
2856void siteMgr_printPrimarySiteDesc(TI_HANDLE hSiteMgr )
2857{
2858    siteMgr_t *pSiteMgr = (siteMgr_t*) hSiteMgr;
2859
2860    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
2861
2862    /* the driver logger can't print %s
2863     * TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE, "-- SSID  = %s \n",pPrimarySite->ssid.str);
2864     */
2865    TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_CONSOLE,"-- BSSID = %x-%x-%x-%x-%x-%x\n",
2866                    pPrimarySite->bssid[0], pPrimarySite->bssid[1], pPrimarySite->bssid[2], pPrimarySite->bssid[3],
2867                    pPrimarySite->bssid[4], pPrimarySite->bssid[5]);
2868
2869
2870	WLAN_OS_REPORT(("-- SSID  = %s \n",pPrimarySite->ssid.str));
2871	WLAN_OS_REPORT(("-- BSSID = %x-%x-%x-%x-%x-%x\n",
2872					pPrimarySite->bssid[0], pPrimarySite->bssid[1], pPrimarySite->bssid[2], pPrimarySite->bssid[3],
2873					pPrimarySite->bssid[4], pPrimarySite->bssid[5]));
2874}
2875#endif
2876
2877/***********************************************************************
2878 *                        getPrimarySiteDesc
2879 ***********************************************************************
2880DESCRIPTION:    Called by the OS abstraction layer in order to get the primary site description
2881
2882INPUT:      pSiteMgr            - site mgr handle.
2883            supplyExtendedInfo  - If OS_802_11_BSSID_EX structure should be used (extended info)
2884                                  (Assuming that if this function is called with TI_TRUE, enough memory was allocated to hold the extended info)
2885
2886OUTPUT:     pPrimarySiteDesc    - Primary site description pointer
2887
2888RETURN:
2889
2890************************************************************************/
2891static void getPrimarySiteDesc(siteMgr_t *pSiteMgr, OS_802_11_BSSID *pPrimarySiteDesc, TI_BOOL supplyExtendedInfo)
2892{
2893    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
2894    OS_802_11_BSSID_EX *pExPrimarySiteDesc = (OS_802_11_BSSID_EX *) pPrimarySiteDesc;
2895    TI_UINT32  len, firstOFDMloc = 0;
2896    OS_802_11_FIXED_IEs     *pFixedIes;
2897    OS_802_11_VARIABLE_IEs  *pVarIes;
2898    TI_UINT8 rsnIeLength,index;
2899    OS_802_11_RATES_EX  SupportedRates;
2900
2901
2902    if (pPrimarySiteDesc == NULL)
2903    {
2904        return;
2905    }
2906    if (pPrimarySite == NULL)
2907    {
2908        os_memoryZero(pSiteMgr->hOs, pPrimarySiteDesc, sizeof(OS_802_11_BSSID));
2909        return;
2910    }
2911
2912    TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "getPrimarySiteDesc - enter\n");
2913
2914
2915    /* If an "extended" request has been made - update the length accordingly */
2916   if (supplyExtendedInfo == TI_FALSE)
2917    pPrimarySiteDesc->Length = sizeof(OS_802_11_BSSID);
2918   else
2919    pPrimarySiteDesc->Length = sizeof(OS_802_11_BSSID_EX);
2920
2921    /* MacAddress */
2922    MAC_COPY (pPrimarySiteDesc->MacAddress, pPrimarySite->bssid);
2923
2924    /* Capabilities */
2925    pPrimarySiteDesc->Capabilities = pPrimarySite->capabilities;
2926
2927    /* SSID */
2928    os_memoryCopy (pSiteMgr->hOs,
2929                   (void *)pPrimarySiteDesc->Ssid.Ssid,
2930                   (void *)pPrimarySite->ssid.str,
2931                   pPrimarySite->ssid.len);
2932    pPrimarySiteDesc->Ssid.SsidLength = pPrimarySite->ssid.len;
2933
2934    /* privacy */
2935    pPrimarySiteDesc->Privacy = pPrimarySite->privacy;
2936
2937    /* RSSI */
2938
2939    pPrimarySiteDesc->Rssi = pPrimarySite->rssi;
2940
2941    pPrimarySiteDesc->NetworkTypeInUse = os802_11DS;
2942
2943    pPrimarySiteDesc->Configuration.Length = sizeof(OS_802_11_CONFIGURATION);
2944    pPrimarySiteDesc->Configuration.BeaconPeriod = pPrimarySite->beaconInterval;
2945    pPrimarySiteDesc->Configuration.ATIMWindow = pPrimarySite->atimWindow;
2946    pPrimarySiteDesc->Configuration.Union.channel = pPrimarySite->channel;
2947
2948    if  (pPrimarySite->bssType == BSS_INDEPENDENT)
2949        pPrimarySiteDesc->InfrastructureMode = os802_11IBSS;
2950    else
2951        pPrimarySiteDesc->InfrastructureMode = os802_11Infrastructure;
2952
2953   /* SupportedRates */
2954   if (supplyExtendedInfo == TI_FALSE)
2955      os_memoryZero(pSiteMgr->hOs, (void *)pPrimarySiteDesc->SupportedRates, sizeof(OS_802_11_RATES));
2956   else
2957      os_memoryZero(pSiteMgr->hOs, (void *)pPrimarySiteDesc->SupportedRates, sizeof(OS_802_11_RATES_EX));
2958
2959   rate_DrvBitmapToNetStr (pPrimarySite->rateMask.supportedRateMask,
2960                           pPrimarySite->rateMask.basicRateMask,
2961                           &SupportedRates[0],
2962                           &len,
2963                           &firstOFDMloc);
2964
2965   if (supplyExtendedInfo == TI_FALSE)
2966       os_memoryCopy(pSiteMgr->hOs, (void *)pPrimarySiteDesc->SupportedRates, (void *)SupportedRates, sizeof(OS_802_11_RATES));
2967   else
2968       os_memoryCopy(pSiteMgr->hOs, (void *)pPrimarySiteDesc->SupportedRates, (void *)SupportedRates, sizeof(OS_802_11_RATES_EX));
2969
2970
2971   if (supplyExtendedInfo == TI_TRUE)
2972   {
2973      pExPrimarySiteDesc->IELength = 0;
2974
2975     /* copy fixed IEs from site entry */
2976     pFixedIes = (OS_802_11_FIXED_IEs*)&pExPrimarySiteDesc->IEs[pExPrimarySiteDesc->IELength];
2977     os_memoryCopy(pSiteMgr->hOs, (void *)pFixedIes->TimeStamp, (void *)&pPrimarySite->tsfTimeStamp, TIME_STAMP_LEN);
2978     pFixedIes->BeaconInterval = pPrimarySite->beaconInterval;
2979     pFixedIes->Capabilities = pPrimarySite->capabilities;
2980     pExPrimarySiteDesc->IELength += sizeof(OS_802_11_FIXED_IEs);
2981
2982     /* copy variable IEs */
2983     /* copy SSID */
2984     pVarIes = (OS_802_11_VARIABLE_IEs*)&pExPrimarySiteDesc->IEs[pExPrimarySiteDesc->IELength];
2985     pVarIes->ElementID = SSID_IE_ID;
2986     pVarIes->Length = pPrimarySite->ssid.len;
2987     os_memoryCopy (pSiteMgr->hOs,
2988                    (void *)pVarIes->data,
2989                    (void *)pPrimarySite->ssid.str,
2990                    pPrimarySite->ssid.len);
2991     pExPrimarySiteDesc->IELength += (pVarIes->Length + 2);
2992
2993
2994     /* copy RSN information elements */
2995     rsnIeLength = 0;
2996     for (index=0; index<MAX_RSN_IE && pPrimarySite->pRsnIe[index].hdr[1] > 0; index++)
2997       {
2998            pVarIes =  (OS_802_11_VARIABLE_IEs*)&pExPrimarySiteDesc->IEs[pExPrimarySiteDesc->IELength+rsnIeLength];
2999         pVarIes->ElementID = pPrimarySite->pRsnIe[index].hdr[0];
3000             pVarIes->Length = pPrimarySite->pRsnIe[index].hdr[1];
3001             os_memoryCopy(pSiteMgr->hOs, (void *)pVarIes->data, (void *)pPrimarySite->pRsnIe[index].rsnIeData, pPrimarySite->pRsnIe[index].hdr[1]);
3002             rsnIeLength += pPrimarySite->pRsnIe[index].hdr[1] + 2;
3003            TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "RSN IE ID=%d, Length=%x\n", pVarIes->ElementID, pVarIes->Length);
3004
3005            TRACE_INFO_HEX(pSiteMgr->hReport, (TI_UINT8 *)pVarIes->data,pVarIes->Length);
3006         }
3007
3008         pExPrimarySiteDesc->IELength += pPrimarySite->rsnIeLen;
3009
3010         pExPrimarySiteDesc->Length = sizeof(OS_802_11_BSSID_EX) + pExPrimarySiteDesc->IELength - 1;
3011
3012         TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "BSSID MAC = %x-%x-%x-%x-%x-%x\n", pExPrimarySiteDesc->MacAddress[0], pExPrimarySiteDesc->MacAddress[1], pExPrimarySiteDesc->MacAddress[2], pExPrimarySiteDesc->MacAddress[3], pExPrimarySiteDesc->MacAddress[4], pExPrimarySiteDesc->MacAddress[5]);
3013
3014         TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "pExPrimarySiteDesc length before alignment = %d\n", pExPrimarySiteDesc->Length);
3015
3016         /* make sure length is 4 bytes aligned */
3017         if (pExPrimarySiteDesc->Length % 4)
3018         {
3019            pExPrimarySiteDesc->Length += (4 - (pExPrimarySiteDesc->Length % 4));
3020         }
3021
3022         TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "pExPrimarySiteDesc length after alignment = %d\n", pExPrimarySiteDesc->Length);
3023
3024        }
3025
3026}
3027
3028
3029/***********************************************************************
3030 *                        translateRateMaskToValue
3031 ***********************************************************************
3032DESCRIPTION:    Called by the function 'siteMgr_config()' in order to translate the rate mask read
3033                from registry to rate value
3034
3035INPUT:      pSiteMgr            -   site mgr handle.
3036            rateMask            -   Rate mask
3037
3038OUTPUT:     The rate after the translation
3039
3040RETURN:
3041
3042************************************************************************/
3043static ERate translateRateMaskToValue(siteMgr_t *pSiteMgr, TI_UINT32 rateMask)
3044{
3045    if (rateMask & DRV_RATE_MASK_54_OFDM)
3046        return DRV_RATE_54M;
3047    if (rateMask & DRV_RATE_MASK_48_OFDM)
3048        return DRV_RATE_48M;
3049    if (rateMask & DRV_RATE_MASK_36_OFDM)
3050        return DRV_RATE_36M;
3051    if (rateMask & DRV_RATE_MASK_24_OFDM)
3052        return DRV_RATE_24M;
3053    if (rateMask & DRV_RATE_MASK_22_PBCC)
3054        return DRV_RATE_22M;
3055    if (rateMask & DRV_RATE_MASK_18_OFDM)
3056        return DRV_RATE_18M;
3057    if (rateMask & DRV_RATE_MASK_12_OFDM)
3058        return DRV_RATE_12M;
3059    if (rateMask & DRV_RATE_MASK_11_CCK)
3060        return DRV_RATE_11M;
3061    if (rateMask & DRV_RATE_MASK_9_OFDM)
3062        return DRV_RATE_9M;
3063    if (rateMask & DRV_RATE_MASK_6_OFDM)
3064        return DRV_RATE_6M;
3065    if (rateMask & DRV_RATE_MASK_5_5_CCK)
3066        return DRV_RATE_5_5M;
3067    if (rateMask & DRV_RATE_MASK_2_BARKER)
3068        return DRV_RATE_2M;
3069    if (rateMask & DRV_RATE_MASK_1_BARKER)
3070        return DRV_RATE_1M;
3071
3072    TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_WARNING, "Translate rate mask to value, mask is 0x%X\n", rateMask);
3073    if(pSiteMgr->siteMgrOperationalMode != DOT11_A_MODE)
3074        return DRV_RATE_1M;
3075    else
3076        return DRV_RATE_6M;
3077}
3078
3079
3080/***********************************************************************
3081 *                        getSupportedRateSet
3082 ***********************************************************************
3083DESCRIPTION:    Called by the function 'siteMgr_getParam()' in order to get the supported rate set
3084                Build an array of network rates based on the max active & max basic rates
3085
3086INPUT:      pSiteMgr            -   site mgr handle.
3087
3088OUTPUT:     pRatesSet           -   The array built
3089
3090RETURN:
3091
3092************************************************************************/
3093static void getSupportedRateSet(siteMgr_t *pSiteMgr, TRates *pRatesSet)
3094{
3095    TI_UINT32 dontCareParam;
3096    TI_UINT32 len = 0;
3097
3098    rate_DrvBitmapToNetStr (pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask,
3099                               pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask,
3100                            (TI_UINT8 *)pRatesSet->ratesString,
3101                            &len,
3102                            &dontCareParam);
3103
3104    pRatesSet->len = (TI_UINT8) len;
3105}
3106
3107/***********************************************************************
3108 *                        setSupportedRateSet
3109 ***********************************************************************
3110DESCRIPTION:    Called by the function 'siteMgr_setParam()' in order to set the supported rate set
3111                Go over the input array and set the max active & max basic rates. (after translation from network
3112                rates to host rates ofcourse)
3113                If max basic rate is bigger than the mac active one, print an error.
3114                If the basic or active rate are different than the ones already stored by the site manager,
3115                it initiates a reconnection by calling sme_Restart
3116
3117INPUT:      pSiteMgr            -   site mgr handle.
3118            pRatesSet           -   The rates array received
3119
3120OUTPUT:
3121
3122RETURN:     TI_OK on success
3123
3124************************************************************************/
3125static TI_STATUS setSupportedRateSet(siteMgr_t *pSiteMgr, TRates *pRatesSet)
3126{
3127    TI_UINT8  i,j, drvRate;
3128    ERate maxActiveRate = (ERate)0, maxBasicRate = (ERate)0;
3129    TI_UINT32 suppBitMap, basicBitMap;
3130    static  ERate basicRates_G[]  = {DRV_RATE_1M,DRV_RATE_2M,DRV_RATE_5_5M,DRV_RATE_11M};
3131    static ERate basicRates_A[]  = {DRV_RATE_6M,DRV_RATE_12M,DRV_RATE_24M};
3132    ERate* currentBasicRates;
3133    TI_UINT32 currentBasicRatesLength;
3134
3135#ifndef NET_BASIC_MASK
3136#define NET_BASIC_MASK      0x80    /* defined in common/src/utils/utils.c */
3137#endif
3138
3139    if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
3140    {
3141        currentBasicRates = &basicRates_A[0];
3142        currentBasicRatesLength = sizeof(basicRates_A) / sizeof(basicRates_A[0]);
3143    }
3144    else
3145    {
3146        currentBasicRates = &basicRates_G[0];
3147        currentBasicRatesLength = sizeof(basicRates_G) / sizeof(basicRates_G[0]);
3148    }
3149
3150        /* Basic rates must be supported. If one of 1M,2M,5.5M,11M is not supported fail.*/
3151
3152    for (j=0;j < currentBasicRatesLength;j++)
3153    {
3154        for (i = 0; i < pRatesSet->len; i++)
3155        {
3156            drvRate = rate_NetToDrv (pRatesSet->ratesString[i]);
3157            if ((drvRate & ( NET_BASIC_MASK-1)) == currentBasicRates[j])
3158                break;
3159        }
3160        /* not all the basic rates are supported! Failure*/
3161        if (i == pRatesSet->len)
3162        {
3163            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Rates set must contain the basic set! Failing\n");
3164            return PARAM_VALUE_NOT_VALID;
3165        }
3166    }
3167
3168    for (i = 0; i < pRatesSet->len; i++)
3169    {
3170        drvRate = rate_NetToDrv (pRatesSet->ratesString[i]);
3171        if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
3172        {
3173            if(drvRate < DRV_RATE_6M)
3174            {
3175                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Notice, the driver configured in 11a mode, but CCK rate appears\n");
3176                return PARAM_VALUE_NOT_VALID;
3177            }
3178        }
3179        else if(pSiteMgr->siteMgrOperationalMode == DOT11_B_MODE)
3180        {
3181            if(drvRate >= DRV_RATE_6M)
3182            {
3183                TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Notice, the driver configured in 11b mode, but OFDM rate appears\n");
3184                return PARAM_VALUE_NOT_VALID;
3185            }
3186        }
3187        maxActiveRate = TI_MAX ((ERate)drvRate, maxActiveRate);
3188    }
3189
3190    for (i = 0; i < pRatesSet->len; i++)
3191    {
3192        if (NET_BASIC_RATE(pRatesSet->ratesString[i]))
3193            maxBasicRate = TI_MAX (rate_NetToDrv (pRatesSet->ratesString[i]), maxBasicRate);
3194    }
3195
3196    /* If the basic rate is bigger than the supported one, we print an error */
3197    if (pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxBasic > pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxActive)
3198    {
3199        TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Notice, the rates configuration is invalid, basic rate is bigger than supported, Max Basic: %d Max Supported: %d\n", pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxBasic, pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxActive);
3200        return PARAM_VALUE_NOT_VALID;
3201    }
3202
3203    pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxActive = maxActiveRate;
3204    pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxBasic = maxBasicRate;
3205
3206    /* configure desired modulation */
3207    if(maxActiveRate == DRV_RATE_22M)
3208        pSiteMgr->pDesiredParams->siteMgrDesiredModulationType = DRV_MODULATION_PBCC;
3209    else if(maxActiveRate < DRV_RATE_22M)
3210        pSiteMgr->pDesiredParams->siteMgrDesiredModulationType = DRV_MODULATION_CCK;
3211    else
3212        pSiteMgr->pDesiredParams->siteMgrDesiredModulationType = DRV_MODULATION_OFDM;
3213
3214
3215    rate_NetStrToDrvBitmap (&suppBitMap, pRatesSet->ratesString, pRatesSet->len);
3216    rate_NetBasicStrToDrvBitmap (&basicBitMap, pRatesSet->ratesString, pRatesSet->len);
3217
3218    if((pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask != basicBitMap) ||
3219       (pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask != suppBitMap))
3220    {
3221        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask = suppBitMap;
3222        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask = basicBitMap;
3223        pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask = basicBitMap;
3224        pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask = suppBitMap;
3225        /* Initialize Mutual Rates Matching */
3226        pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
3227        pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3228
3229        sme_Restart (pSiteMgr->hSmeSm);
3230    }
3231
3232    return TI_OK;
3233}
3234
3235/***********************************************************************
3236 *                        pbccAlgorithm
3237 ***********************************************************************
3238DESCRIPTION:    Called by the following functions:
3239                -   systemConfig(), in the system configuration phase after the selection
3240                -   siteMgr_updateSite(), in a case of a primary site update & if a PBCC algorithm
3241                    is needed to be performed
3242                Performs the PBCC algorithm
3243
3244
3245INPUT:      hSiteMgr            -   site mgr handle.
3246
3247OUTPUT:
3248
3249RETURN:     TI_OK on always
3250
3251************************************************************************/
3252TI_STATUS pbccAlgorithm(TI_HANDLE hSiteMgr)
3253{
3254    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3255    paramInfo_t param;
3256    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3257    TI_UINT32   supportedRateMask ;
3258
3259
3260    if (pPrimarySite->channel == SPECIAL_BG_CHANNEL)
3261        supportedRateMask = (rate_GetDrvBitmapForDefaultSupporteSet() & pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask) ;
3262    else
3263        supportedRateMask = pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask ;
3264
3265    param.paramType = CTRL_DATA_CURRENT_SUPPORTED_RATE_MASK_PARAM;
3266    param.content.ctrlDataCurrentRateMask = supportedRateMask;
3267    /* clear the 22Mbps bit in case the PBCC is not allowed */
3268    if(pSiteMgr->currentDataModulation != DRV_MODULATION_PBCC &&
3269       pSiteMgr->currentDataModulation != DRV_MODULATION_OFDM)
3270            param.content.ctrlDataCurrentRateMask &= ~DRV_RATE_MASK_22_PBCC;
3271    ctrlData_setParam(pSiteMgr->hCtrlData, &param);
3272
3273    param.paramType = CTRL_DATA_RATE_CONTROL_ENABLE_PARAM;
3274    ctrlData_setParam(pSiteMgr->hCtrlData, &param);
3275
3276    return TI_OK;
3277}
3278
3279
3280/***********************************************************************
3281 *                        siteMgr_assocReport
3282 ***********************************************************************
3283DESCRIPTION:    Called by the following functions:
3284                -   assoc_recv()
3285
3286
3287INPUT:      hSiteMgr            -   siteMgr handle.
3288            capabilities        -   assoc rsp capabilities field.
3289			bCiscoAP			-   whether we are connected to a Cisco AP. Used for Tx Power Control adjustment
3290OUTPUT:
3291
3292RETURN:     TI_OK on always
3293
3294************************************************************************/
3295TI_STATUS siteMgr_assocReport(TI_HANDLE hSiteMgr, TI_UINT16 capabilities, TI_BOOL bCiscoAP)
3296{
3297    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3298    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3299
3300    /* handle AP's preamble capability */
3301    pPrimarySite->preambleAssRspCap = ((capabilities >> CAP_PREAMBLE_SHIFT) & CAP_PREAMBLE_MASK)  ? PREAMBLE_SHORT : PREAMBLE_LONG;
3302
3303	/*
3304	 * Enable/Disable the Tx Power Control adjustment.
3305	 * When we are connected to Cisco AP - TX Power Control adjustment is disabled.
3306	 */
3307	pSiteMgr->siteMgrTxPowerEnabled = ( !bCiscoAP ) && ( pSiteMgr->pDesiredParams->TxPowerControlOn );
3308
3309TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": Tx Power Control adjustment is %d\n", pSiteMgr->siteMgrTxPowerEnabled);
3310
3311    return TI_OK;
3312}
3313
3314/***********************************************************************
3315 *                        siteMgr_setWMEParamsSite
3316 ***********************************************************************
3317DESCRIPTION:    Set the QOS_WME params as received from the associated
3318                AP. The function is called by the QoS Mgr
3319                after receving association response succefully.
3320
3321INPUT:      hSiteMgr    -   SiteMgr handle.
3322
3323OUTPUT:     pDot11_WME_PARAM_t - pointer to the QOS_WME Param IE.
3324
3325RETURN:     TI_OK on always
3326
3327************************************************************************/
3328TI_STATUS siteMgr_setWMEParamsSite(TI_HANDLE hSiteMgr,dot11_WME_PARAM_t *pDot11_WME_PARAM)
3329{
3330    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3331    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3332
3333    if( pPrimarySite == NULL )
3334    {
3335        return TI_OK;
3336    }
3337
3338    if( pDot11_WME_PARAM == NULL )
3339    {
3340        pPrimarySite->WMESupported = TI_FALSE;
3341        return TI_OK;
3342    }
3343
3344    /* Update the QOS_WME params */
3345    os_memoryCopy(pSiteMgr->hOs,&pPrimarySite->WMEParameters,&pDot11_WME_PARAM->WME_ACParameteres,sizeof(dot11_ACParameters_t));
3346    pPrimarySite->lastWMEParameterCnt = (pDot11_WME_PARAM->ACInfoField & dot11_WME_ACINFO_MASK);
3347    TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "$$$$$$ QOS_WME parameters were updates according to association response, cntSeq = %d\n",pPrimarySite->lastWMEParameterCnt);
3348
3349    return TI_OK;
3350}
3351
3352
3353/***********************************************************************
3354 *                        siteMgr_getWMEParamsSite
3355 ***********************************************************************
3356DESCRIPTION:    Get the QOS_WME params as recieved from the associated
3357                AP. The function is called by the Qos Mgr in order
3358                to set all QOS_WME parameters to the core and Hal
3359
3360INPUT:      hSiteMgr    -   SiteMgr handle.
3361
3362OUTPUT:     pWME_ACParameters_t - pointer to the QOS_WME Param.
3363
3364RETURN:     TI_OK if there are valid QOS_WME parameters , TI_NOK otherwise.
3365
3366************************************************************************/
3367TI_STATUS siteMgr_getWMEParamsSite(TI_HANDLE hSiteMgr,dot11_ACParameters_t **pWME_ACParameters_t)
3368{
3369    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3370    siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3371
3372    if(pPrimarySite->WMESupported == TI_TRUE)
3373    {
3374        *pWME_ACParameters_t = &pPrimarySite->WMEParameters;
3375        return TI_OK;
3376    }
3377    else
3378    {
3379        *pWME_ACParameters_t = NULL;
3380        return TI_NOK;
3381    }
3382
3383}
3384
3385/***********************************************************************
3386 *                        siteMgr_setCurrentTable
3387 ***********************************************************************
3388DESCRIPTION:
3389
3390INPUT:      hSiteMgr    -   SiteMgr handle.
3391
3392OUTPUT:
3393
3394RETURN:
3395
3396************************************************************************/
3397void siteMgr_setCurrentTable(TI_HANDLE hSiteMgr, ERadioBand radioBand)
3398{
3399    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3400
3401    if(radioBand == RADIO_BAND_2_4_GHZ)
3402        pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
3403    else
3404        pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
3405}
3406
3407/***********************************************************************
3408 *                        siteMgr_updateRates
3409 ***********************************************************************
3410DESCRIPTION:
3411
3412INPUT:      hSiteMgr    -   SiteMgr handle.
3413
3414OUTPUT:
3415
3416RETURN:
3417
3418************************************************************************/
3419
3420void siteMgr_updateRates(TI_HANDLE hSiteMgr, TI_BOOL dot11a, TI_BOOL updateToOS)
3421{
3422    TI_UINT32  statusData;
3423    TI_UINT32  localSuppRateMask, localBasicRateMask;
3424
3425    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3426
3427    localSuppRateMask = pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask;
3428    localBasicRateMask = pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask;
3429
3430
3431    rate_ValidateVsBand (&localSuppRateMask, &localBasicRateMask, dot11a);
3432
3433    pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask = localBasicRateMask;
3434    pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask = localSuppRateMask;
3435
3436     /* Initialize Mutual Rates Matching */
3437    pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
3438    pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3439
3440    /*If we are in dual mode and we are only scanning A band we don't have to set the siteMgrCurrentDesiredTxRate.*/
3441    if (updateToOS == TI_TRUE)
3442    {
3443        TI_UINT32 uSupportedRates = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3444        ERate eMaxRate = rate_GetMaxFromDrvBitmap (uSupportedRates);
3445
3446        /* Make sure that the basic rate set is included in the supported rate set */
3447        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask &= uSupportedRates;
3448
3449        /* Set desired modulation */
3450        pSiteMgr->pDesiredParams->siteMgrDesiredModulationType =
3451            (eMaxRate < DRV_RATE_22M) ? DRV_MODULATION_CCK : DRV_MODULATION_OFDM;
3452    }
3453    pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxBasic = translateRateMaskToValue(pSiteMgr, pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask);
3454    pSiteMgr->pDesiredParams->siteMgrDesiredRatePair.maxActive = translateRateMaskToValue(pSiteMgr, pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask);
3455
3456    if (updateToOS == TI_TRUE)
3457	{
3458        siteEntry_t  *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3459        TI_UINT32 commonSupportedRateMask;
3460        ERate maxRate;
3461
3462        commonSupportedRateMask = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3463        if (pPrimarySite)
3464        {
3465            commonSupportedRateMask &= pPrimarySite->rateMask.supportedRateMask;
3466        }
3467
3468        maxRate = translateRateMaskToValue(pSiteMgr, commonSupportedRateMask);
3469
3470        /* report the desired rate to OS */
3471        statusData = rate_DrvToNet(maxRate);
3472        EvHandlerSendEvent(pSiteMgr->hEvHandler, IPC_EVENT_LINK_SPEED, (TI_UINT8 *)&statusData,sizeof(TI_UINT32));
3473    }
3474}
3475
3476
3477/**
3478 * \fn     siteMgr_SelectRateMatch
3479 * \brief  Checks if the rates settings match those of a site
3480 *
3481 * Checks if the rates settings match those of a site
3482 *
3483 * \param  hSiteMgr - handle to the siteMgr object
3484 * \param  pCurrentSite - the site to check
3485 * \return TI_TRUE if site matches rates settings, TI FALSE if it doesn't
3486 * \sa     sme_Select
3487 */
3488TI_BOOL siteMgr_SelectRateMatch (TI_HANDLE hSiteMgr, TSiteEntry *pCurrentSite)
3489{
3490    siteMgr_t *pSiteMgr = (siteMgr_t *)hSiteMgr;
3491    TI_UINT32 MatchedBasicRateMask;
3492    TI_UINT32 MatchedSupportedRateMask;
3493	TI_UINT32 StaTotalRates;
3494	TI_UINT32 SiteTotalRates;
3495
3496	/* If the basic or active rate are invalid (0), return NO_MATCH. */
3497	if ((pCurrentSite->maxBasicRate == DRV_RATE_INVALID) || (pCurrentSite->maxActiveRate == DRV_RATE_INVALID))
3498	{
3499        TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_SelectRateMatch: basic or active rate are invalid. maxBasic=%d,maxActive=%d \n", pCurrentSite->maxBasicRate ,pCurrentSite->maxActiveRate);
3500		return TI_FALSE;
3501	}
3502
3503	if (DRV_RATE_MAX < pCurrentSite->maxBasicRate)
3504	{
3505        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_SelectRateMatch: basic rate is too high. maxBasic=%d\n", pCurrentSite->maxBasicRate);
3506		return TI_FALSE;
3507	}
3508
3509	if(pCurrentSite->channel <= SITE_MGR_CHANNEL_B_G_MAX)
3510		siteMgr_updateRates(pSiteMgr, TI_FALSE, TI_TRUE);
3511	else
3512		siteMgr_updateRates(pSiteMgr, TI_TRUE, TI_TRUE);
3513
3514	StaTotalRates = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask |
3515				    pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3516
3517	SiteTotalRates = pCurrentSite->rateMask.basicRateMask | pCurrentSite->rateMask.supportedRateMask;
3518
3519	MatchedBasicRateMask = SiteTotalRates
3520				& pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
3521
3522    MatchedSupportedRateMask = SiteTotalRates &
3523				pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
3524
3525    if ((StaTotalRates & pCurrentSite->rateMask.basicRateMask) != pCurrentSite->rateMask.basicRateMask)
3526    {
3527        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_SelectRateMatch: Basic or Supported Rates Doesn't Match \n");
3528        return TI_FALSE;
3529
3530    }
3531
3532    return TI_TRUE;
3533}
3534
3535/***********************************************************************
3536 *                        siteMgr_bandParamsConfig
3537 ***********************************************************************
3538DESCRIPTION:
3539
3540INPUT:      hSiteMgr    -   SiteMgr handle.
3541
3542OUTPUT:
3543
3544RETURN:
3545
3546************************************************************************/
3547void siteMgr_bandParamsConfig(TI_HANDLE hSiteMgr,  TI_BOOL updateToOS)
3548{
3549    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3550
3551    /* reconfig rates */
3552    if(pSiteMgr->siteMgrOperationalMode == DOT11_A_MODE)
3553        siteMgr_updateRates(hSiteMgr, TI_TRUE, updateToOS);
3554    else
3555        siteMgr_updateRates(hSiteMgr, TI_FALSE, updateToOS);
3556
3557    /* go to B_ONLY Mode only if WiFI bit is Set*/
3558    if (pSiteMgr->pDesiredParams->siteMgrWiFiAdhoc == TI_TRUE)
3559    {   /* Configuration For AdHoc when using external configuration */
3560        if (pSiteMgr->pDesiredParams->siteMgrExternalConfiguration == TI_FALSE)
3561        {
3562            siteMgr_externalConfigurationParametersSet(hSiteMgr);
3563        }
3564    }
3565
3566}
3567
3568void siteMgr_ConfigRate(TI_HANDLE hSiteMgr)
3569{
3570    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3571    TI_BOOL      dot11a, b11nEnable;
3572    EDot11Mode   OperationMode;
3573
3574    OperationMode = pSiteMgr->siteMgrOperationalMode;
3575
3576    /* reconfig rates */
3577    if (OperationMode == DOT11_A_MODE)
3578        dot11a = TI_TRUE;
3579    else
3580        dot11a = TI_FALSE;
3581
3582    /*
3583    ** Specific change to ch 14, that channel is only used in Japan, and is limited
3584    ** to rates 1,2,5.5,11
3585    */
3586    if(pSiteMgr->pDesiredParams->siteMgrDesiredChannel == SPECIAL_BG_CHANNEL)
3587    {
3588        if(pSiteMgr->pDesiredParams->siteMgrRegstryBasicRate[OperationMode] > BASIC_RATE_SET_1_2_5_5_11)
3589            pSiteMgr->pDesiredParams->siteMgrRegstryBasicRate[OperationMode] = BASIC_RATE_SET_1_2_5_5_11;
3590
3591
3592        if(pSiteMgr->pDesiredParams->siteMgrRegstrySuppRate[OperationMode] > SUPPORTED_RATE_SET_1_2_5_5_11)
3593            pSiteMgr->pDesiredParams->siteMgrRegstrySuppRate[OperationMode] = SUPPORTED_RATE_SET_1_2_5_5_11;
3594    }
3595
3596    /* use HT MCS rates */
3597    StaCap_IsHtEnable (pSiteMgr->hStaCap, &b11nEnable);
3598    if (TI_TRUE == b11nEnable)
3599    {
3600        OperationMode = DOT11_N_MODE;
3601    }
3602
3603    pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask =
3604        rate_BasicToDrvBitmap (pSiteMgr->pDesiredParams->siteMgrRegstryBasicRate[OperationMode], dot11a);
3605
3606    pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask =
3607        rate_SupportedToDrvBitmap (pSiteMgr->pDesiredParams->siteMgrRegstrySuppRate[OperationMode], dot11a);
3608
3609    siteMgr_updateRates(pSiteMgr, dot11a, TI_TRUE);
3610
3611        /* go to B_ONLY Mode only if WiFI bit is Set*/
3612    if (pSiteMgr->pDesiredParams->siteMgrWiFiAdhoc == TI_TRUE)
3613    {   /* Configuration For AdHoc when using external configuration */
3614        if (pSiteMgr->pDesiredParams->siteMgrExternalConfiguration == TI_FALSE)
3615        {
3616            siteMgr_externalConfigurationParametersSet(hSiteMgr);
3617        }
3618    }
3619}
3620
3621static void siteMgr_externalConfigurationParametersSet(TI_HANDLE hSiteMgr)
3622{
3623    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3624
3625    /* Overwrite the parameters for AdHoc with External Configuration */
3626
3627    if( ((pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_A_MODE) ||
3628        (pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)) &&
3629        !pSiteMgr->pDesiredParams->siteMgrWiFiAdhoc && pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_INDEPENDENT)
3630        return;
3631
3632
3633    if(pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_INDEPENDENT)
3634    {
3635        pSiteMgr->siteMgrOperationalMode = DOT11_B_MODE;
3636        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask = rate_BasicToDrvBitmap (BASIC_RATE_SET_1_2_5_5_11, TI_FALSE);
3637        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask = rate_SupportedToDrvBitmap (SUPPORTED_RATE_SET_1_2_5_5_11, TI_FALSE);
3638        pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask = rate_BasicToDrvBitmap (BASIC_RATE_SET_1_2_5_5_11, TI_FALSE);
3639        pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask = rate_SupportedToDrvBitmap (SUPPORTED_RATE_SET_1_2_5_5_11, TI_FALSE);
3640        pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime = PHY_SLOT_TIME_LONG;
3641
3642        TWD_SetRadioBand(pSiteMgr->hTWD, RADIO_BAND_2_4_GHZ);
3643        TWD_CfgSlotTime (pSiteMgr->hTWD, PHY_SLOT_TIME_LONG);
3644
3645    }
3646    else
3647    {
3648        if(pSiteMgr->radioBand == RADIO_BAND_2_4_GHZ)
3649            pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
3650        else
3651            pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
3652        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask = rate_BasicToDrvBitmap (BASIC_RATE_SET_1_2_5_5_11, TI_FALSE);
3653        pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask = rate_SupportedToDrvBitmap (SUPPORTED_RATE_SET_ALL, TI_FALSE);
3654        pSiteMgr->pDesiredParams->siteMgrRegstryBasicRateMask = rate_BasicToDrvBitmap (BASIC_RATE_SET_1_2_5_5_11, TI_FALSE);
3655        pSiteMgr->pDesiredParams->siteMgrRegstrySuppRateMask = rate_SupportedToDrvBitmap (SUPPORTED_RATE_SET_ALL, TI_FALSE);
3656
3657        pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime = PHY_SLOT_TIME_LONG;
3658
3659        TWD_CfgSlotTime (pSiteMgr->hTWD, PHY_SLOT_TIME_LONG);
3660    }
3661}
3662
3663
3664TI_STATUS siteMgr_saveProbeRespBuffer(TI_HANDLE hSiteMgr, TMacAddr  *bssid, TI_UINT8 *pProbeRespBuffer, TI_UINT32 length)
3665{
3666    siteEntry_t *pSite;
3667    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3668
3669    if (pSiteMgr == NULL)
3670    {
3671        return TI_NOK;
3672    }
3673
3674    TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION , "siteMgr_saveProbeRespBuffer called\n");
3675
3676    if (pProbeRespBuffer==NULL || length>=MAX_BEACON_BODY_LENGTH)
3677    {
3678        return TI_NOK;
3679    }
3680
3681    pSite = findSiteEntry(pSiteMgr, bssid);
3682    if (pSite==NULL)
3683    {
3684        return TI_NOK;
3685    }
3686
3687    os_memoryCopy(pSiteMgr->hOs, pSite->probeRespBuffer, pProbeRespBuffer, length);
3688    pSite->probeRespLength = length;
3689
3690    TRACE17(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_saveProbeRespBuffer: BSSID=%x-%x-%x-%x-%x-%x, TSF=%x-%x-%x-%x-%x-%x-%x-%x, \n ts=%d, rssi=%d\n channel = %d \n", pSite->bssid[0], pSite->bssid[1], pSite->bssid[2], pSite->bssid[3], pSite->bssid[4], pSite->bssid[5], pSite->tsfTimeStamp[0], pSite->tsfTimeStamp[1], pSite->tsfTimeStamp[2], pSite->tsfTimeStamp[3], pSite->tsfTimeStamp[4], pSite->tsfTimeStamp[5], pSite->tsfTimeStamp[6], pSite->tsfTimeStamp[7], os_timeStampMs(pSiteMgr->hOs), pSite->rssi, pSite->channel);
3691
3692    return TI_OK;
3693}
3694
3695TI_STATUS siteMgr_saveBeaconBuffer(TI_HANDLE hSiteMgr, TMacAddr *bssid, TI_UINT8 *pBeaconBuffer, TI_UINT32 length)
3696{
3697    siteEntry_t *pSite;
3698    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3699
3700    if (pSiteMgr==NULL)
3701    {
3702        return TI_NOK;
3703    }
3704
3705	TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION , "siteMgr_saveBeaconBuffer called\n");
3706
3707    if (pBeaconBuffer==NULL || length>=MAX_BEACON_BODY_LENGTH)
3708    {
3709        return TI_NOK;
3710    }
3711
3712    pSite = findSiteEntry(pSiteMgr, bssid);
3713    if (pSite==NULL)
3714    {
3715        return TI_NOK;
3716    }
3717
3718    os_memoryCopy(pSiteMgr->hOs, pSite->beaconBuffer, pBeaconBuffer, length);
3719    pSite->beaconLength = length;
3720
3721    /*if (pSiteMgr->pSitesMgmtParams->pPrimarySite!=NULL)
3722    {
3723        if (!os_memoryCompare(pSiteMgr->hOs, pSiteMgr->pSitesMgmtParams->pPrimarySite->ssid.ssidString, pSite->ssid.ssidString, pSiteMgr->pSitesMgmtParams->pPrimarySite->ssid.len))
3724        {
3725            TRACE16(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_saveBeaconBuffer: BSSID=%x-%x-%x-%x-%x-%x, TSF=%x-%x-%x-%x-%x-%x-%x-%x, \n ts=%d, rssi=%d \n", pSite->bssid[0], pSite->bssid[1], pSite->bssid[2], pSite->bssid[3], pSite->bssid[4], pSite->bssid[5], pSite->tsfTimeStamp[0], pSite->tsfTimeStamp[1], pSite->tsfTimeStamp[2], pSite->tsfTimeStamp[3], pSite->tsfTimeStamp[4], pSite->tsfTimeStamp[5], pSite->tsfTimeStamp[6], pSite->tsfTimeStamp[7], pSite->osTimeStamp, pSite->rssi);
3726        }
3727    }*/
3728    if ( MAX_SSID_LEN > pSite->ssid.len )
3729    {
3730        pSite->ssid.str[pSite->ssid.len] = '\0';
3731    }
3732
3733    /*
3734TRACE9(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_saveBeaconBuffer: BSSID=%x-%x-%x-%x-%x-%x, SSID=, \n ts=%d, rssi=%d\n channel = %d \n", pSite->bssid[0], pSite->bssid[1], pSite->bssid[2], pSite->bssid[3], pSite->bssid[4], pSite->bssid[5], pSite->osTimeStamp, pSite->rssi, pSite->channel);
3735
3736    */
3737    return TI_OK;
3738}
3739
3740
3741void siteMgr_resetChannelList(TI_HANDLE hSiteMgr)
3742{
3743    TI_UINT8       index;
3744    siteMgr_t   *pSiteMgr = (siteMgr_t*)hSiteMgr;
3745
3746    if (hSiteMgr==NULL)
3747    {
3748        return;
3749    }
3750
3751    for (index=0; index < pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->maxNumOfSites; index++)
3752    {
3753        if (pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->siteTable[index].siteType != SITE_NULL)
3754        {
3755            pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->siteTable[index].prioritySite = TI_FALSE;
3756        }
3757    }
3758
3759}
3760
3761
3762void siteMgr_IsERP_Needed(TI_HANDLE hSiteMgr,TI_BOOL *useProtection,TI_BOOL *NonErpPresent,TI_BOOL *barkerPreambleType)
3763{
3764    siteMgr_t       *pSiteMgr = (siteMgr_t*)hSiteMgr;
3765    paramInfo_t     param;
3766    siteEntry_t     *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3767
3768    *useProtection = TI_FALSE;
3769    *NonErpPresent = TI_FALSE;
3770    *barkerPreambleType = TI_FALSE;
3771
3772    param.paramType = CTRL_DATA_CURRENT_IBSS_PROTECTION_PARAM;
3773    ctrlData_getParam(pSiteMgr->hCtrlData, &param);
3774
3775    /* On WifiAdhoc (for band B) The STa should not include in the beacon an ERP IE (see WiFi B  clause 2.2, 5.8.2) */
3776    if (pSiteMgr->pDesiredParams->siteMgrWiFiAdhoc == TI_TRUE)
3777    {
3778        /* Return the default => ERP is not needed */
3779        return;
3780    }
3781
3782    /* check if STA is connected */
3783    if (pPrimarySite)
3784    {
3785        if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE || pSiteMgr->siteMgrOperationalMode == DOT11_DUAL_MODE)
3786        {
3787            if(param.content.ctrlDataIbssProtecionType == ERP_PROTECTION_STANDARD)
3788            {
3789                if(pPrimarySite->siteType == SITE_SELF)
3790                {
3791                    if(pPrimarySite->channel <= SITE_MGR_CHANNEL_B_G_MAX) /* if channel B&G*/
3792                    {
3793                            *useProtection = TI_TRUE;
3794                            *NonErpPresent = TI_TRUE;
3795                            *barkerPreambleType = TI_TRUE;
3796                    }
3797                }
3798                else if(pPrimarySite->bssType == BSS_INDEPENDENT)
3799                {
3800                    if(pPrimarySite->useProtection == TI_TRUE)
3801                        *useProtection = TI_TRUE;
3802                    if(pPrimarySite->NonErpPresent == TI_TRUE)
3803                        *NonErpPresent = TI_TRUE;
3804                    if(pPrimarySite->barkerPreambleType == PREAMBLE_SHORT)
3805                        *barkerPreambleType = TI_TRUE;
3806                }
3807            }
3808        }
3809    }
3810}
3811
3812/**
3813 * \fn     siteMgr_CopyToPrimarySite()
3814 * \brief  Responsible to copy candidate AP from SME table to site Mgr table
3815 *
3816 * \note
3817 * \param  hSiteMgr - SiteMgr handle.
3818 * \param  pCandidate - candidate AP from SME table.
3819 * \return TI_OK on success or TI_NOK on failure
3820 * \sa
3821 */
3822TI_STATUS siteMgr_CopyToPrimarySite (TI_HANDLE hSiteMgr, TSiteEntry *pCandidate)
3823{
3824    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3825    bssEntry_t  newAP;
3826
3827    MAC_COPY (newAP.BSSID, pCandidate->bssid);
3828    newAP.band = pCandidate->eBand;
3829    newAP.RSSI = pCandidate->rssi;
3830    newAP.rxRate = pCandidate->rxRate;
3831    newAP.channel = pCandidate->channel;
3832    os_memoryCopy(pSiteMgr->hOs, (void *)&newAP.lastRxTSF, (void *)pCandidate->tsfTimeStamp , TIME_STAMP_LEN);
3833    newAP.beaconInterval = pCandidate->beaconInterval;
3834    newAP.capabilities = pCandidate->capabilities;
3835
3836    /* get frame type */
3837    if (TI_TRUE == pCandidate->probeRecv)
3838    {
3839        newAP.resultType = SCAN_RFT_PROBE_RESPONSE;
3840        newAP.pBuffer = (TI_UINT8 *)(pCandidate->probeRespBuffer);
3841        /* length of all IEs of beacon (or probe response) buffer */
3842        newAP.bufferLength = pCandidate->probeRespLength;
3843    }
3844    else
3845    {
3846        if (TI_TRUE == pCandidate->beaconRecv)
3847        {
3848            newAP.resultType = SCAN_RFT_BEACON;
3849            newAP.pBuffer = (TI_UINT8 *)(pCandidate->beaconBuffer);
3850            /* length of all IEs of beacon (or probe response) buffer */
3851            newAP.bufferLength = pCandidate->beaconLength;
3852
3853        }
3854        else
3855        {
3856            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_CopyToPrimarySite: try to update primary site without updated prob_res\beacon\n\n");
3857            return TI_NOK;
3858        }
3859    }
3860
3861    if (newAP.pBuffer == NULL)
3862    {
3863        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_CopyToPrimarySite: pBufferBody is NULL !\n");
3864        return TI_NOK;
3865    }
3866
3867    return siteMgr_overwritePrimarySite (hSiteMgr, &newAP, TI_FALSE);
3868}
3869
3870
3871/***********************************************************************
3872 *                        siteMgr_disSelectSite
3873 ***********************************************************************
3874DESCRIPTION: Called by the SME SM in order to dis select the primary site.
3875			The function set the primary site pointer to NULL and set its type to type regular
3876
3877INPUT:      hSiteMgr	-	site mgr handle.
3878
3879OUTPUT:
3880
3881RETURN:     TI_OK
3882
3883************************************************************************/
3884TI_STATUS siteMgr_disSelectSite(TI_HANDLE	hSiteMgr)
3885{
3886	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
3887
3888	/* This protection is because in the case that the BSS was LOST the primary site was removed already. */
3889	if (pSiteMgr->pSitesMgmtParams->pPrimarySite != NULL)
3890	{
3891        TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_disSelectSite REMOVE Primary ssid=, bssid= 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\n\n", pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[0], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[1], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[2], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[3], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[4], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[5] );
3892
3893        pSiteMgr->pSitesMgmtParams->pPrimarySite->siteType = SITE_REGULAR;
3894		pSiteMgr->pSitesMgmtParams->pPrevPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3895		pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
3896	}
3897
3898	return TI_OK;
3899}
3900
3901
3902/**
3903*
3904* siteMgr_overwritePrimarySite
3905*
3906* \b Description:
3907*
3908* This function sets new AP as a primary site and, if requested, stores previous
3909* AP's info; called during roaming
3910*
3911* \b ARGS:
3912*
3913*  I   - pCurrBSS - Current BSS handle \n
3914*
3915* \b RETURNS:
3916*
3917*  TI_OK on success, TI_NOK on failure.
3918*
3919* \sa
3920*/
3921TI_STATUS siteMgr_overwritePrimarySite(TI_HANDLE hSiteMgr, bssEntry_t *newAP, TI_BOOL requiredToStorePrevSite)
3922{
3923    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
3924    siteEntry_t *newApEntry;
3925    mlmeIEParsingParams_t *ieListParseParams = mlmeParser_getParseIEsBuffer(pSiteMgr->hMlmeSm);
3926
3927    TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_overwritePrimarySite: new site bssid= 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\n\n", newAP->BSSID[0], newAP->BSSID[1], newAP->BSSID[2], newAP->BSSID[3], newAP->BSSID[4], newAP->BSSID[5]);
3928
3929    /* If previous primary site present, and requested to save it - store it */
3930    if (requiredToStorePrevSite)
3931    {
3932        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_overwritePrimarySite: required to store prev prim site \n");
3933        /* Store latest primary site, make ite a regular site */
3934        pSiteMgr->pSitesMgmtParams->pPrevPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
3935        pSiteMgr->pSitesMgmtParams->pPrevPrimarySite->siteType = SITE_REGULAR;
3936    }
3937    else
3938    {
3939        TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_overwritePrimarySite: not required to store prev prim site \n");
3940        if (pSiteMgr->pSitesMgmtParams->pPrimarySite != NULL)
3941        {
3942            TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Removing Primary ssid=, bssid= 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\n\n", pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[0], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[1], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[2], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[3], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[4], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid[5] );
3943
3944            pSiteMgr->pSitesMgmtParams->pPrimarySite->siteType  = SITE_REGULAR;
3945            pSiteMgr->pSitesMgmtParams->pPrimarySite->beaconRecv = TI_FALSE;
3946
3947            pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
3948        }
3949        else
3950        {
3951            TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "siteMgr_overwritePrimarySite: primary site is NULL \n");
3952        }
3953
3954    }
3955
3956    /* Find not occupied entry in site table, and store new AP BSSID in */
3957    /* If pPrimarySite is not set to NULL, store it in pPrevSite before updating */
3958    newApEntry = findAndInsertSiteEntry(pSiteMgr, &(newAP->BSSID), newAP->band);
3959
3960    if (newApEntry != NULL)
3961    {
3962        /* Zero frame content */
3963        os_memoryZero(pSiteMgr->hOs, ieListParseParams, sizeof(mlmeIEParsingParams_t));
3964
3965        /* Update parameters of new AP */
3966        newApEntry->rssi            = newAP->RSSI;
3967        newApEntry->bssType         = BSS_INFRASTRUCTURE;
3968        newApEntry->dtimPeriod      = 1;
3969        newApEntry->rxRate          = (ERate)newAP->rxRate;
3970        /* Mark the site as regular in order to prevent from calling Power manager during beacon parsing */
3971        newApEntry->siteType        = SITE_REGULAR;
3972
3973        os_memoryCopy(pSiteMgr->hOs, &newApEntry->ssid, &pSiteMgr->pDesiredParams->siteMgrDesiredSSID, sizeof(TSsid));
3974
3975        if (newAP->resultType == SCAN_RFT_PROBE_RESPONSE)
3976        {
3977            ieListParseParams->frame.subType = PROBE_RESPONSE;
3978            siteMgr_saveProbeRespBuffer(hSiteMgr, &(newAP->BSSID), newAP->pBuffer, newAP->bufferLength);
3979        }
3980        else
3981        {
3982            ieListParseParams->frame.subType = BEACON;
3983            siteMgr_saveBeaconBuffer(hSiteMgr, &(newAP->BSSID), newAP->pBuffer, newAP->bufferLength);
3984        }
3985        ieListParseParams->band = newAP->band;
3986        ieListParseParams->rxChannel = newAP->channel;
3987        ieListParseParams->myBssid = TI_FALSE;
3988
3989        ieListParseParams->frame.content.iePacket.pRsnIe = NULL;
3990        ieListParseParams->frame.content.iePacket.rsnIeLen = 0;
3991        ieListParseParams->frame.content.iePacket.barkerPreambleMode = PREAMBLE_UNSPECIFIED;
3992        os_memoryCopy(pSiteMgr->hOs, (void *)ieListParseParams->frame.content.iePacket.timestamp, (void *)&newAP->lastRxTSF, TIME_STAMP_LEN);
3993        ieListParseParams->frame.content.iePacket.beaconInerval     = newAP->beaconInterval;
3994        ieListParseParams->frame.content.iePacket.capabilities  = newAP->capabilities;
3995
3996        if (mlmeParser_parseIEs(pSiteMgr->hMlmeSm, newAP->pBuffer, newAP->bufferLength, ieListParseParams) != TI_OK)
3997        {
3998            /* Error in parsing Probe response packet - exit */
3999            return TI_NOK;
4000        }
4001
4002        siteMgr_updateSite(hSiteMgr, &(newAP->BSSID), &ieListParseParams->frame, newAP->channel, newAP->band, TI_FALSE);
4003
4004        /* Select the entry as primary site */
4005        newApEntry->siteType = SITE_PRIMARY;
4006        pSiteMgr->pSitesMgmtParams->pPrimarySite = newApEntry;
4007        return TI_OK;
4008    }
4009    else
4010    {
4011        return TI_NOK;
4012    }
4013}
4014
4015
4016/**
4017 * \fn     siteMgr_changeBandParams
4018 * \brief  change band params at the SithMgr and the TWD
4019
4020 * \param  hSiteMgr - handle to the siteMgr object.
4021 * \param  radioBand - the set radio band.
4022 * \return TI_TRUE if site matches RSN settings, TI FALSE if it doesn't
4023 * \sa     sme_Select
4024 */
4025void siteMgr_changeBandParams (TI_HANDLE hSiteMgr, ERadioBand radioBand)
4026{
4027	paramInfo_t	param;
4028    siteMgr_t   *pSiteMgr = (siteMgr_t *)hSiteMgr;
4029
4030	/* change dot11 mode */
4031	param.paramType = SITE_MGR_OPERATIONAL_MODE_PARAM;
4032	if(radioBand == RADIO_BAND_2_4_GHZ)
4033		param.content.siteMgrDot11OperationalMode = DOT11_G_MODE;
4034	else
4035		param.content.siteMgrDot11OperationalMode = DOT11_A_MODE;
4036
4037	siteMgr_setParam(hSiteMgr, &param);
4038
4039	param.paramType = SITE_MGR_RADIO_BAND_PARAM;
4040	param.content.siteMgrRadioBand = radioBand;
4041	siteMgr_setParam(hSiteMgr, &param);
4042
4043	siteMgr_setCurrentTable(hSiteMgr, radioBand);
4044
4045	/* configure hal with common core-hal parameters */
4046	TWD_SetRadioBand (pSiteMgr->hTWD, radioBand);
4047}
4048
4049
4050/***********************************************************************
4051                incrementTxSessionCount
4052 ***********************************************************************
4053DESCRIPTION: Increment the Tx-Session-Counter (cyclic in range 1-7), which
4054               is configured to the FW in the Join command to distinguish
4055			   between Tx packets of different AP-connections.
4056			 Update also the TxCtrl module.
4057
4058INPUT:      pSiteMgr    -   site mgr handle.
4059
4060OUTPUT:
4061
4062RETURN:     TI_UINT16 - the new Tx-Session-Count (range is 1-7).
4063
4064************************************************************************/
4065static TI_UINT16 incrementTxSessionCount(siteMgr_t *pSiteMgr)
4066{
4067	pSiteMgr->txSessionCount++;
4068	if(pSiteMgr->txSessionCount > MAX_TX_SESSION_COUNT)
4069		pSiteMgr->txSessionCount = MIN_TX_SESSION_COUNT;
4070
4071	txCtrlParams_updateTxSessionCount(pSiteMgr->hTxCtrl, pSiteMgr->txSessionCount);
4072
4073	return pSiteMgr->txSessionCount;
4074}
4075
4076
4077/**
4078*
4079* siteMgr_TxPowerHighThreshold
4080*
4081* \b Description:
4082*
4083* Called by EventMBox upon TX Power Adaptation High Threshold Trigger.
4084*
4085* \b ARGS:
4086*
4087*  I   - hSiteMgr - Site Mgr handle \n
4088*
4089* \b RETURNS:
4090*
4091*  None
4092*
4093* \sa
4094*/
4095void siteMgr_TxPowerHighThreshold(TI_HANDLE hSiteMgr,
4096                                      TI_UINT8     *data,
4097                                      TI_UINT8     dataLength)
4098{
4099    siteMgr_TxPowerAdaptation(hSiteMgr, RSSI_EVENT_DIR_HIGH);
4100}
4101
4102/**
4103*
4104* siteMgr_TxPowerLowThreshold
4105*
4106* \b Description:
4107*
4108* Called by EventMBox upon TX Power Adaptation Low Threshold Trigger.
4109*
4110* \b ARGS:
4111*
4112*  I   - hSiteMgr - Site Mgr handle \n
4113*
4114* \b RETURNS:
4115*
4116*  None
4117*
4118* \sa
4119*/
4120void siteMgr_TxPowerLowThreshold(TI_HANDLE hSiteMgr,
4121                                      TI_UINT8     *data,
4122                                      TI_UINT8     dataLength)
4123{
4124    siteMgr_TxPowerAdaptation(hSiteMgr, RSSI_EVENT_DIR_LOW);
4125}
4126
4127/**
4128*
4129* siteMgr_TxPowerAdaptation
4130*
4131* \b Description:
4132*
4133* TX Power Adaptation - Used for TX power adjust .
4134*
4135* \b ARGS:
4136*
4137*  I   - hSiteMgr - Site Mgr handle \n
4138*      - highLowEdge - Direction of Edge event
4139*
4140* \b RETURNS:
4141*
4142*  None
4143*
4144* \sa
4145*/
4146static void siteMgr_TxPowerAdaptation(TI_HANDLE hSiteMgr, RssiEventDir_e highLowEdge)
4147{
4148    siteMgr_t    *pSiteMgr = (siteMgr_t *)hSiteMgr;
4149    paramInfo_t   param;
4150    TI_UINT8      txPowerLevel;
4151    TI_STATUS     status;
4152
4153    if ((pSiteMgr->pSitesMgmtParams->pPrimarySite) && (pSiteMgr->siteMgrTxPowerEnabled))
4154    {
4155        /* getting the current Tx power  */
4156        param.paramType = REGULATORY_DOMAIN_CURRENT_TX_ATTENUATION_PARAM;
4157        status = regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
4158        txPowerLevel = param.content.desiredTxPower;
4159
4160        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": Current Tx PowerLevel = %d\n", txPowerLevel);
4161        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": TxPowerRecoverLevel = %d\n", pSiteMgr->pDesiredParams->TxPowerRecoverLevel);
4162
4163        if ((status != TI_OK) || ((highLowEdge == RSSI_EVENT_DIR_HIGH) && (pSiteMgr->pDesiredParams->TxPowerRecoverLevel > txPowerLevel)))
4164        {
4165            /* Setting the power in the FW , only if the translation succeeded */
4166
4167            siteMgr_setTemporaryTxPower (pSiteMgr, pSiteMgr->pDesiredParams->TxPowerRecoverLevel) ;  /* set lowest power lvel */;
4168        }
4169        else
4170        {
4171             if ( highLowEdge == RSSI_EVENT_DIR_LOW )
4172             {
4173                siteMgr_setTemporaryTxPower (pSiteMgr, txPowerLevel);  /* set highest power level */;
4174
4175             }
4176        }
4177    }
4178}
4179
4180