1/*
2 * systemConfig.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 reportReplvl.c
35 *  \brief Report level implementation
36 *
37 *  \see reportReplvl.h
38 */
39
40/***************************************************************************/
41/*																			*/
42/*		MODULE:	reportReplvl.c												*/
43/*    PURPOSE:	Report level implementation	 								*/
44/*																			*/
45/***************************************************************************/
46#define __FILE_ID__  FILE_ID_87
47#include "tidef.h"
48#include "osApi.h"
49#include "siteHash.h"
50#include "sme.h"
51#include "rate.h"
52#include "smeApi.h"
53#include "rsnApi.h"
54#include "report.h"
55#include "TWDriver.h"
56#include "connApi.h"
57#include "DataCtrl_Api.h"
58#include "siteMgrApi.h"
59#include "EvHandler.h"
60#include "TI_IPC_Api.h"
61#include "regulatoryDomainApi.h"
62#include "measurementMgrApi.h"
63#ifdef XCC_MODULE_INCLUDED
64#include "XCCMngr.h"
65#include "TransmitPowerXCC.h"
66#include "XCCRMMngr.h"
67#endif
68
69#include "qosMngr_API.h"
70#include "StaCap.h"
71
72
73/****************************************************************************
74								MATRIC ISSUE
75	Each function in the select process returns a MATCH, NO_MATCH value in order to
76	skip non relevant sites. In addition, some of the functions also measures a matching level of a site.
77	The matching level is returned as a bit map. The select function 'OR's those bit maps in order to
78	select the site that has the biggest matching level. If a function returns a NO_MATCH value, the matching level of the
79	site is reset.
80	Following is the site matching level bit map structure.
81	Please notice, that if all the match functions returned MATCH for a site, its matric must be different than 0,
82	because of the rates bits.
83
84
85	    31 - 24           23 - 20           20 - 16             15 - 10       9 - 8         7         6           5         4 - 0
86	+---------------+---------------+-----------------------+-------------+------------+----------+---------+-----------+-----------+
87	| Rx Level      | Privacy       | Attempts              |Rates        | Modulation |Preamble  | Channel | Spectrum  | Reserved  |
88	|		        |	    		|		                | 		      |			   |		  |		    | management|		    |
89	+---------------+---------------+-----------------------+-------------+------------+----------+---------+-----------+-----------+
90****************************************************************************/
91
92/* Matric bit map definition */
93typedef enum
94{
95	/* Rx level */
96	METRIC_RX_LEVEL_MASK			= 0xFF,
97	METRIC_RX_LEVEL_SHIFT			= 24,
98
99	/* Privacy */
100	METRIC_PRIVACY_MASK				= 0x0F,
101	METRIC_PRIVACY_SHIFT			= 20,
102
103	/* Number of attempts */
104	METRIC_ATTEMPTS_NUMBER_MASK		= 0x0F,
105	METRIC_ATTEMPTS_NUMBER_SHIFT	= 16,
106
107
108	/* Rates */
109	METRIC_RATES_MASK				= 0x3F,
110	METRIC_RATES_SHIFT				= 10,
111
112	/* PBCC */
113	METRIC_MODULATION_MASK			= 0x03,
114	METRIC_MODULATION_SHIFT			= 8,
115
116	/* Preamble*/
117	METRIC_PREAMBLE_MASK			= 0x01,
118	METRIC_PREAMBLE_SHIFT			= 7,
119
120	/* Channel */
121	METRIC_CHANNEL_MASK				= 0x01,
122	METRIC_CHANNEL_SHIFT			= 6,
123
124	/* Spectrum management Capability */
125	METRIC_SPECTRUM_MANAGEMENT_MASK	= 0x01,
126	METRIC_SPECTRUM_MANAGEMENT_SHIFT= 5,
127
128	/* Priority Site */
129	METRIC_PRIORITY_SITE_MASK		= 0x01,
130	METRIC_PRIORITY_SITE_SHIFT		= 4
131
132} matric_e;
133
134#define MAX_GB_MODE_CHANEL      14
135
136#define MAX_RSN_DATA_SIZE       256
137
138/* RSSI values boundaries and metric values for best, good, etc  signals */
139#define SELECT_RSSI_BEST_LEVEL      (-22)
140#define SELECT_RSSI_GOOD_LEVEL      (-38)
141#define SELECT_RSSI_NORMAL_LEVEL    (-56)
142#define SELECT_RSSI_POOR_LEVEL      (-72)
143#define SELECT_RSSI_BAD_LEVEL       (-82)
144
145
146#define  RSSI_METRIC_BEST      6
147#define  RSSI_METRIC_GOOD      5
148#define  RSSI_METRIC_NORMAL    4
149#define  RSSI_METRIC_POOR      3
150#define  RSSI_METRIC_BAD       2
151#define  RSSI_METRIC_NOSIGNAL  1
152
153/* Local functions prototypes */
154
155static TI_STATUS sendProbeResponse(siteMgr_t *pSiteMgr, TMacAddr *pBssid);
156
157/* Interface functions Implementation */
158
159/***********************************************************************
160 *                        addSelfSite
161 ***********************************************************************
162DESCRIPTION: This function is called if the selection fails and desired BSS type is IBSS
163			That means we creating our own network and wait for other stations to join us.
164			the best site for teh station.
165			Performs the following:
166				-	If the desired BSSID is broadcast, we generate a random BSSId, otherwise we use the desired one.
167				-	If the site table is full we remove the most old site
168				-	We send a probe response with our oiwn desired attributes in order to add the site to the site table
169
170INPUT:      pSiteMgr	-	site mgr handle.
171
172OUTPUT:
173
174RETURN:     Pointer to rthe self site entry in the site table
175
176************************************************************************/
177siteEntry_t *addSelfSite(TI_HANDLE hSiteMgr)
178{
179	siteMgr_t       *pSiteMgr = (siteMgr_t *)hSiteMgr;
180    siteEntry_t		*pSite;
181	TMacAddr		bssid;
182    TSsid           *pSsid    = &pSiteMgr->pDesiredParams->siteMgrDesiredSSID;
183
184	if (OS_802_11_SSID_JUNK (pSsid->str, pSsid->len))
185		return NULL;
186
187	if (MAC_BROADCAST (pSiteMgr->pDesiredParams->siteMgrDesiredBSSID))
188	{
189		MAC_COPY (bssid, pSiteMgr->ibssBssid);
190	}
191	else
192	{
193		MAC_COPY (bssid, pSiteMgr->pDesiredParams->siteMgrDesiredBSSID);
194	}
195
196	if(pSiteMgr->pDesiredParams->siteMgrDesiredChannel <= 14)
197	{
198		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
199        pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
200	}
201	else
202	{
203		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
204		pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
205	}
206
207    siteMgr_ConfigRate(pSiteMgr);
208
209	/* First make sure that there is a place in the site table, if not, reomve the eldest site. */
210	if (pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->numOfSites == pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->maxNumOfSites)
211		removeEldestSite(pSiteMgr);
212
213	sendProbeResponse(pSiteMgr, &bssid);
214
215	/* Now find the site in the site table. */
216	pSite = findSiteEntry(pSiteMgr, &bssid);
217	if (pSite == NULL)
218	{
219		return NULL;
220	}
221	pSite->beaconModulation = pSite->probeModulation;
222	pSite->barkerPreambleType = PREAMBLE_UNSPECIFIED;
223
224   	pSiteMgr->pSitesMgmtParams->pPrimarySite = pSite;
225	pSite->siteType = SITE_SELF;
226
227	return pSite;
228}
229
230/***********************************************************************
231 *                        sendProbeResponse
232 ***********************************************************************
233DESCRIPTION: This function is called by the function 'addSelfSite()' in order to send a probe response
234			to the site mgr. This will cause the site manager to add a new entry to the site table, the self site entry.
235
236INPUT:      pSiteMgr	-	site mgr handle.
237			pBssid		-	Received BSSID
238
239OUTPUT:
240
241RETURN:     TI_OK
242
243************************************************************************/
244static TI_STATUS sendProbeResponse(siteMgr_t *pSiteMgr, TMacAddr *pBssid)
245{
246	mlmeFrameInfo_t		frame;
247    ECipherSuite        rsnStatus;
248	dot11_SSID_t 		ssid;
249	dot11_RATES_t 		rates;
250	dot11_FH_PARAMS_t 	FHParamsSet;
251	dot11_DS_PARAMS_t 	DSParamsSet;
252	dot11_CF_PARAMS_t 	CFParamsSet;
253	dot11_IBSS_PARAMS_t IBSSParamsSet;
254	TI_UINT32			len = 0, ofdmIndex = 0;
255    ERadioBand          band;
256	dot11_RATES_t 		extRates;
257	TI_UINT8			ratesBuf[DOT11_MAX_SUPPORTED_RATES];
258	TI_BOOL				extRatesInd = TI_FALSE;
259
260	/* The easiest way to add a site to the site table is to simulate a probe frame. */
261	frame.subType = PROBE_RESPONSE;
262	os_memoryZero(pSiteMgr->hOs, &frame, sizeof(mlmeFrameInfo_t));
263		/* Initialize the frame fields */
264	frame.subType = PROBE_RESPONSE;
265	os_memoryZero(pSiteMgr->hOs, (void *)frame.content.iePacket.timestamp, TIME_STAMP_LEN);
266
267	/* Build  Beacon interval  */
268	frame.content.iePacket.beaconInerval = pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval;
269
270	/* Build  capability field */
271	frame.content.iePacket.capabilities = 0;
272	frame.content.iePacket.capabilities |= (TI_TRUE << CAP_IBSS_SHIFT); /* Bss type must be independent */
273
274	if ((pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType == PREAMBLE_SHORT))
275		frame.content.iePacket.capabilities |= (TI_TRUE << CAP_PREAMBLE_SHIFT);
276
277	/* call RSN to get the privacy desired */
278    rsn_getParamEncryptionStatus(pSiteMgr->hRsn, &rsnStatus); /* RSN_ENCRYPTION_STATUS_PARAM */
279	if (rsnStatus == TWD_CIPHER_NONE)
280	{
281		frame.content.iePacket.capabilities |= (TI_FALSE << CAP_PRIVACY_SHIFT);
282	} else {
283		frame.content.iePacket.capabilities |= (TI_TRUE << CAP_PRIVACY_SHIFT);
284	}
285
286	if (pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_PBCC)
287		frame.content.iePacket.capabilities |= (TI_TRUE << CAP_PBCC_SHIFT);
288
289    if (pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
290    {
291        if(pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime == PHY_SLOT_TIME_SHORT)
292            frame.content.iePacket.capabilities |= (TI_TRUE << CAP_SLOT_TIME_SHIFT);
293    }
294
295	/* Build ssid */
296	os_memoryZero(pSiteMgr->hOs, (void *)ssid.serviceSetId, MAX_SSID_LEN);
297
298	if (pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len == 0)
299		ssid.hdr[1] = 0;
300	else
301	{
302		os_memoryCopy(pSiteMgr->hOs, (void *)ssid.serviceSetId, (void *)pSiteMgr->pDesiredParams->siteMgrDesiredSSID.str, pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len);
303		ssid.hdr[1] = pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len;
304	}
305
306	if(pSiteMgr->pDesiredParams->siteMgrDesiredChannel <= MAX_GB_MODE_CHANEL)
307		siteMgr_updateRates(pSiteMgr, TI_FALSE, TI_TRUE);
308	else
309		siteMgr_updateRates(pSiteMgr, TI_TRUE, TI_TRUE);
310
311	/* Build Rates */
312	rate_DrvBitmapToNetStr (pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask,
313						    pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask,
314                            ratesBuf,
315                            &len,
316                            &ofdmIndex);
317
318	if(pSiteMgr->siteMgrOperationalMode != DOT11_G_MODE ||
319       pSiteMgr->pDesiredParams->siteMgrUseDraftNum == DRAFT_5_AND_EARLIER ||
320	   ofdmIndex == len)
321	{
322		rates.hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
323		rates.hdr[1] = len;
324		os_memoryCopy(pSiteMgr->hOs, (void *)rates.rates, ratesBuf, rates.hdr[1]);
325	}
326	else
327	{
328		rates.hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
329		rates.hdr[1] = ofdmIndex;
330		os_memoryCopy(pSiteMgr->hOs, (void *)rates.rates, ratesBuf, rates.hdr[1]);
331
332		extRates.hdr[0] = DOT11_EXT_SUPPORTED_RATES_ELE_ID;
333		extRates.hdr[1] = len - ofdmIndex;
334		os_memoryCopy(pSiteMgr->hOs, (void *)extRates.rates, &ratesBuf[ofdmIndex], extRates.hdr[1]);
335		extRatesInd = TI_TRUE;
336	}
337
338    if((pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE) || (pSiteMgr->siteMgrOperationalMode == DOT11_DUAL_MODE))
339    {
340        erpProtectionType_e protType;
341        ctrlData_getParamProtType(pSiteMgr->hCtrlData, &protType); /* CTRL_DATA_CURRENT_IBSS_PROTECTION_PARAM */
342        frame.content.iePacket.useProtection = protType;
343    }
344    else
345    {
346        frame.content.iePacket.useProtection = ERP_PROTECTION_NONE;
347    }
348
349	/* Build FH */
350	os_memoryZero(pSiteMgr->hOs, &FHParamsSet, sizeof(dot11_FH_PARAMS_t));
351
352	/* Build DS */
353	DSParamsSet.hdr[1] = 1;
354	DSParamsSet.currChannel = pSiteMgr->pDesiredParams->siteMgrDesiredChannel;
355
356	/* Build CF */
357	os_memoryZero(pSiteMgr->hOs, &CFParamsSet, sizeof(dot11_CF_PARAMS_t));
358
359	/* Build IBSS */
360	os_memoryZero(pSiteMgr->hOs, &IBSSParamsSet, sizeof(dot11_IBSS_PARAMS_t));
361	IBSSParamsSet.hdr[1] = 2;
362	IBSSParamsSet.atimWindow = pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow;
363
364	frame.content.iePacket.pSsid = &ssid;
365	frame.content.iePacket.pRates = &rates;
366
367	if(extRatesInd)
368		frame.content.iePacket.pExtRates = &extRates;
369	else
370		frame.content.iePacket.pExtRates = NULL;
371
372	frame.content.iePacket.pFHParamsSet = &FHParamsSet;
373	frame.content.iePacket.pDSParamsSet = &DSParamsSet;
374	frame.content.iePacket.pCFParamsSet = &CFParamsSet;
375	frame.content.iePacket.pIBSSParamsSet = &IBSSParamsSet;
376
377    band = ( MAX_GB_MODE_CHANEL >= pSiteMgr->pDesiredParams->siteMgrDesiredChannel ? RADIO_BAND_2_4_GHZ : RADIO_BAND_5_0_GHZ );
378	/* Update site */
379	siteMgr_updateSite(pSiteMgr, pBssid, &frame ,pSiteMgr->pDesiredParams->siteMgrDesiredChannel, band, TI_FALSE);
380
381	return TI_OK;
382}
383
384/***********************************************************************
385 *                        systemConfig
386 ***********************************************************************
387DESCRIPTION: This function is called by the function 'siteMgr_selectSite()' in order to configure
388			the system with the chosen site attribute.
389
390INPUT:      pSiteMgr	-	site mgr handle.
391
392OUTPUT:
393
394RETURN:     TI_OK
395
396************************************************************************/
397TI_STATUS systemConfig(siteMgr_t *pSiteMgr)
398{
399	paramInfo_t *pParam;
400	siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
401	TRsnData	rsnData;
402	TI_UINT8	rsnAssocIeLen;
403    dot11_RSN_t *pRsnIe;
404    TI_UINT8    rsnIECount=0;
405    TI_UINT8    *curRsnData;
406    TI_UINT16   length;
407    TI_UINT16   capabilities;
408    TI_UINT16   PktLength=0;
409    TI_UINT8	*pIeBuffer=NULL;
410    TI_BOOL     b11nEnable;
411    TI_BOOL     bWmeEnable;
412
413#ifdef XCC_MODULE_INCLUDED
414    TI_UINT8     ExternTxPower;
415#endif
416	TI_STATUS	status;
417	ESlotTime	slotTime;
418	TI_UINT32	StaTotalRates;
419	dot11_ACParameters_t *p_ACParametersDummy = NULL;
420    TtxCtrlHtControl tHtControl;
421
422    curRsnData = os_memoryAlloc(pSiteMgr->hOs, MAX_RSN_DATA_SIZE);
423    if (!curRsnData)
424        return TI_NOK;
425    pParam = (paramInfo_t *)os_memoryAlloc(pSiteMgr->hOs, sizeof(paramInfo_t));
426    if (!pParam) {
427        os_memoryFree(pSiteMgr->hOs, curRsnData, MAX_RSN_DATA_SIZE);
428        return TI_NOK;
429    }
430
431	if (pPrimarySite->probeRecv)
432	{
433		pIeBuffer = pPrimarySite->probeRespBuffer;
434		PktLength = pPrimarySite->probeRespLength;
435	}
436    else if (pPrimarySite->beaconRecv)
437	{
438		pIeBuffer = pPrimarySite->beaconBuffer;
439		PktLength = pPrimarySite->beaconLength;
440	}
441
442	pSiteMgr->prevRadioBand = pSiteMgr->radioBand;
443
444    TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": Capabilities, Slot Time Bit = %d (capabilities = %d)\n", (pPrimarySite->capabilities >> CAP_SLOT_TIME_SHIFT) & 1, pPrimarySite->capabilities);
445
446	if(pPrimarySite->channel <= MAX_GB_MODE_CHANEL)
447	{
448		if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_B_MODE)
449		{
450			pSiteMgr->siteMgrOperationalMode = DOT11_B_MODE;
451			slotTime = PHY_SLOT_TIME_LONG;
452
453            TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": 11b Mode, Slot Time = %d\n", (TI_UINT8)slotTime);
454		}
455		else
456		{
457			pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
458
459			if (((pPrimarySite->capabilities >> CAP_SLOT_TIME_SHIFT) & CAP_SLOT_TIME_MASK) == PHY_SLOT_TIME_SHORT)
460			{
461			slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
462
463            TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": 11g Mode, Slot Time = %d (desired)\n", (TI_UINT8)slotTime);
464			}
465			else
466			{
467				slotTime = PHY_SLOT_TIME_LONG;
468
469                TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": 11g Mode, Slot Time = %d\n", (TI_UINT8) slotTime);
470			}
471		}
472
473		pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
474		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
475	}
476	else
477	{
478		pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
479		pSiteMgr->radioBand = RADIO_BAND_5_0_GHZ;
480		slotTime = PHY_SLOT_TIME_SHORT;
481
482        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, ": 11a Mode, Slot Time = %d\n", (TI_UINT8)slotTime);
483
484		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
485	}
486
487	/* since we are moving to the different band, the siteMgr should be reconfigured */
488	if(pSiteMgr->prevRadioBand != pSiteMgr->radioBand)
489		siteMgr_bandParamsConfig(pSiteMgr, TI_TRUE);
490
491	if(pPrimarySite->channel <= MAX_GB_MODE_CHANEL)
492		siteMgr_updateRates(pSiteMgr, TI_FALSE, TI_TRUE);
493	else
494		siteMgr_updateRates(pSiteMgr, TI_TRUE, TI_TRUE);
495
496	/* configure hal with common core-hal parameters */
497	TWD_SetRadioBand (pSiteMgr->hTWD, pSiteMgr->radioBand);
498
499	pPrimarySite->currentSlotTime = slotTime;
500	TWD_CfgSlotTime (pSiteMgr->hTWD, slotTime);
501
502	/***************** Config Site Manager *************************/
503	/* L.M. Should be fixed, should take into account the AP's rates */
504	if(pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_CCK)
505		pSiteMgr->chosenModulation = DRV_MODULATION_CCK;
506	else if(pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_PBCC)
507	{
508		if(pPrimarySite->probeModulation != DRV_MODULATION_NONE)
509			pSiteMgr->chosenModulation = pPrimarySite->probeModulation;
510		else
511			pSiteMgr->chosenModulation = pPrimarySite->beaconModulation;
512	}
513	else
514		pSiteMgr->chosenModulation = DRV_MODULATION_OFDM;
515
516	/* We use this variable in order tp perform the PBCC algorithm. */
517	pSiteMgr->currentDataModulation = pSiteMgr->chosenModulation;
518	/***************** Config Data CTRL *************************/
519
520	pParam->paramType = CTRL_DATA_CURRENT_BSSID_PARAM;							/* Current BSSID */
521	MAC_COPY (pParam->content.ctrlDataCurrentBSSID, pPrimarySite->bssid);
522	ctrlData_setParam(pSiteMgr->hCtrlData, pParam);
523
524	pParam->paramType = CTRL_DATA_CURRENT_BSS_TYPE_PARAM;							/* Current BSS Type */
525	pParam->content.ctrlDataCurrentBssType = pPrimarySite->bssType;
526	ctrlData_setParam(pSiteMgr->hCtrlData, pParam);
527
528	pParam->paramType = CTRL_DATA_CURRENT_PREAMBLE_TYPE_PARAM;					/* Current Preamble Type */
529	if ((pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType == PREAMBLE_SHORT) &&
530		(pPrimarySite->currentPreambleType == PREAMBLE_SHORT))
531		pParam->content.ctrlDataCurrentPreambleType = PREAMBLE_SHORT;
532	else
533		pParam->content.ctrlDataCurrentPreambleType = PREAMBLE_LONG;
534	ctrlData_setParam(pSiteMgr->hCtrlData, pParam);
535
536    /* Mutual Rates Matching */
537	StaTotalRates = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask |
538					pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
539
540
541    pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask = StaTotalRates &
542														   pPrimarySite->rateMask.supportedRateMask;
543
544	pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask = StaTotalRates &
545															pPrimarySite->rateMask.basicRateMask;
546	if (pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask == 0)
547	{
548		pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask =
549			pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
550	}
551
552    /* set protection */
553    if(BSS_INDEPENDENT == pPrimarySite->bssType)
554    {
555        pParam->paramType = CTRL_DATA_CURRENT_IBSS_PROTECTION_PARAM;
556    }
557    else
558    {
559        pParam->paramType = CTRL_DATA_CURRENT_PROTECTION_STATUS_PARAM;
560    }
561    pParam->content.ctrlDataProtectionEnabled = pPrimarySite->useProtection;
562    ctrlData_setParam(pSiteMgr->hCtrlData, pParam);
563
564	pbccAlgorithm(pSiteMgr);
565
566	/********** Set Site QOS protocol support *************/
567
568	/* Set WME Params */
569	 status = siteMgr_getWMEParamsSite(pSiteMgr,&p_ACParametersDummy);
570	 if(status == TI_OK)
571	 {
572		 pParam->content.qosSiteProtocol = QOS_WME;
573	 }
574	 else
575	 {
576		 pParam->content.qosSiteProtocol = QOS_NONE;
577	 }
578
579     TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, " systemConfigt() : pParam->content.qosSiteProtoco %d\n", pParam->content.qosSiteProtocol);
580
581	 pParam->paramType = QOS_MNGR_SET_SITE_PROTOCOL;
582	 qosMngr_setParams(pSiteMgr->hQosMngr, pParam);
583
584     /* Set active protocol in qosMngr according to station desired mode and site capabilities
585	    Must be called BEFORE setting the "CURRENT_PS_MODE" into the QosMngr */
586     qosMngr_selectActiveProtocol(pSiteMgr->hQosMngr);
587
588	 /* set PS capability parameter */
589	 pParam->paramType = QOS_MNGR_CURRENT_PS_MODE;
590	 if(pPrimarySite->APSDSupport == TI_TRUE)
591		 pParam->content.currentPsMode = PS_SCHEME_UPSD_TRIGGER;
592	 else
593		 pParam->content.currentPsMode = PS_SCHEME_LEGACY;
594      qosMngr_setParams(pSiteMgr->hQosMngr, pParam);
595
596     /* Set upsd/ps_poll configuration */
597     /* Must be done AFTER setting the active Protocol */
598     qosMngr_setAcPsDeliveryMode (pSiteMgr->hQosMngr);
599
600
601     /********** Set Site HT setting support *************/
602     /* set HT setting to the FW */
603     /* verify 11n_Enable and Chip type */
604     StaCap_IsHtEnable (pSiteMgr->hStaCap, &b11nEnable);
605
606     /* verify that WME flag enable */
607     qosMngr_GetWmeEnableFlag (pSiteMgr->hQosMngr, &bWmeEnable);
608
609     if ((b11nEnable != TI_FALSE) &&
610         (bWmeEnable != TI_FALSE) &&
611         (pPrimarySite->tHtCapabilities.tHdr[0] != TI_FALSE) &&
612         (pPrimarySite->tHtInformation.tHdr[0] != TI_FALSE))
613     {
614         TWD_CfgSetFwHtCapabilities (pSiteMgr->hTWD, &pPrimarySite->tHtCapabilities, TI_TRUE);
615         TWD_CfgSetFwHtInformation (pSiteMgr->hTWD, &pPrimarySite->tHtInformation);
616
617         /* the FW not supported in HT control field in TX */
618
619        tHtControl.bHtEnable = TI_FALSE;
620         txCtrlParams_SetHtControl (pSiteMgr->hTxCtrl, &tHtControl);
621     }
622     else
623     {
624         TWD_CfgSetFwHtCapabilities (pSiteMgr->hTWD, &pPrimarySite->tHtCapabilities, TI_FALSE);
625
626         tHtControl.bHtEnable = TI_FALSE;
627         txCtrlParams_SetHtControl (pSiteMgr->hTxCtrl, &tHtControl);
628     }
629
630	/***************** Config RSN *************************/
631    /* Get the RSN IE data */
632    pRsnIe = pPrimarySite->pRsnIe;
633	length = 0;
634    rsnIECount = 0;
635    while ((length < pPrimarySite->rsnIeLen) && (pPrimarySite->rsnIeLen < 255)
636           && (rsnIECount < MAX_RSN_IE))
637    {
638        curRsnData[0+length] = pRsnIe->hdr[0];
639        curRsnData[1+length] = pRsnIe->hdr[1];
640        os_memoryCopy(pSiteMgr->hOs, &curRsnData[2+length], (void *)pRsnIe->rsnIeData, pRsnIe->hdr[1]);
641        length += pRsnIe->hdr[1]+2;
642        pRsnIe += 1;
643        rsnIECount++;
644    }
645    if (length<pPrimarySite->rsnIeLen)
646    {
647        TRACE2(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "siteMgr_selectSiteFromTable, RSN IE is too long: rsnIeLen=%d, MAX_RSN_IE=%d\n", pPrimarySite->rsnIeLen, MAX_RSN_IE);
648    }
649
650	rsnData.pIe = (pPrimarySite->rsnIeLen==0) ? NULL : curRsnData;
651	rsnData.ieLen = pPrimarySite->rsnIeLen;
652    rsnData.privacy = pPrimarySite->privacy;
653
654    rsn_setSite(pSiteMgr->hRsn, &rsnData, NULL, &rsnAssocIeLen);
655
656	/***************** Config RegulatoryDomain **************************/
657
658#ifdef XCC_MODULE_INCLUDED
659	/* set XCC TPC if present */
660	if(XCC_ParseClientTP(pSiteMgr->hOs,pPrimarySite,&ExternTxPower,pIeBuffer,PktLength) == TI_OK)
661    {
662        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Select XCC_ParseClientTP == OK: Dbm = %d\n",ExternTxPower);
663        pParam->paramType = REGULATORY_DOMAIN_EXTERN_TX_POWER_PREFERRED;
664        pParam->content.ExternTxPowerPreferred = ExternTxPower;
665        regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain, pParam);
666    }
667	/* Parse and save the XCC Version Number if exists */
668	XCCMngr_parseXCCVer(pSiteMgr->hXCCMngr, pIeBuffer, PktLength);
669
670#endif
671
672	/* Note: TX Power Control adjustment is now done through siteMgr_assocReport() */
673	if (pPrimarySite->powerConstraint>0)
674	{	/* setting power constraint */
675		pParam->paramType = REGULATORY_DOMAIN_SET_POWER_CONSTRAINT_PARAM;
676		pParam->content.powerConstraint = pPrimarySite->powerConstraint;
677		regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain, pParam);
678	}
679
680
681	/***************** Config MeasurementMgr object **************************/
682    capabilities = pPrimarySite->capabilities;
683
684    /* Updating the Measurement Module Mode */
685    measurementMgr_setMeasurementMode(pSiteMgr->hMeasurementMgr, capabilities,
686									pIeBuffer, PktLength);
687    os_memoryFree(pSiteMgr->hOs, curRsnData, MAX_RSN_DATA_SIZE);
688    os_memoryFree(pSiteMgr->hOs, pParam, sizeof(paramInfo_t));
689	return TI_OK;
690}
691
692