1/** \file reportReplvl.c
2 *  \brief Report level implementation
3 *
4 *  \see reportReplvl.h
5 */
6/****************************************************************************
7**+-----------------------------------------------------------------------+**
8**|                                                                       |**
9**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
10**| All rights reserved.                                                  |**
11**|                                                                       |**
12**| Redistribution and use in source and binary forms, with or without    |**
13**| modification, are permitted provided that the following conditions    |**
14**| are met:                                                              |**
15**|                                                                       |**
16**|  * Redistributions of source code must retain the above copyright     |**
17**|    notice, this list of conditions and the following disclaimer.      |**
18**|  * Redistributions in binary form must reproduce the above copyright  |**
19**|    notice, this list of conditions and the following disclaimer in    |**
20**|    the documentation and/or other materials provided with the         |**
21**|    distribution.                                                      |**
22**|  * Neither the name Texas Instruments nor the names of its            |**
23**|    contributors may be used to endorse or promote products derived    |**
24**|    from this software without specific prior written permission.      |**
25**|                                                                       |**
26**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
27**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
28**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
29**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
30**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
31**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
32**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
33**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
34**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
35**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
36**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
37**|                                                                       |**
38**+-----------------------------------------------------------------------+**
39****************************************************************************/
40
41/***************************************************************************/
42/*																									*/
43/*		MODULE:	reportReplvl.c																*/
44/*    PURPOSE:	Report level implementation	 										*/
45/*																									*/
46/***************************************************************************/
47#include "osTIType.h"
48#include "osApi.h"
49#include "siteHash.h"
50#include "smeSmApi.h"
51#include "utils.h"
52#include "smeApi.h"
53#include "rsnApi.h"
54#include "report.h"
55#include "whalCtrl_api.h"
56#include "connApi.h"
57#include "DataCtrl_Api.h"
58#include "siteMgrApi.h"
59#include "regulatoryDomainApi.h"
60#include "measurementMgrApi.h"
61#ifdef EXC_MODULE_INCLUDED
62#include "excMngr.h"
63#include "TransmitPowerExc.h"
64#include "excRMMngr.h"
65#endif
66
67#include "qosMngr_API.h"
68
69
70/****************************************************************************
71								MATRIC ISSUE
72	Each function in the select process returns a MATCH, NO_MATCH value in order to
73	skip non relevant sites. In addition, some of the functions also measures a matching level of a site.
74	The matching level is returned as a bit map. The select function 'OR's those bit maps in order to
75	select the site that has the biggest matching level. If a function returns a NO_MATCH value, the matching level of the
76	site is reset.
77	Following is the site matching level bit map structure.
78	Please notice, that if all the match functions returned MATCH for a site, its matric must be different than 0,
79	because of the rates bits.
80
81
82	    31 - 24           23 - 20           20 - 16             15 - 10       9 - 8         7         6           5         4 - 0
83	+---------------+---------------+-----------------------+-------------+------------+----------+---------+-----------+-----------+
84	| Rx Level      | Privacy       | Attempts              |Rates        | Modulation |Preamble  | Channel | Spectrum  | Reserved  |
85	|		        |	    		|		                | 		      |			   |		  |		    | management|		    |
86	+---------------+---------------+-----------------------+-------------+------------+----------+---------+-----------+-----------+
87****************************************************************************/
88
89/* Matric bit map definition */
90typedef enum
91{
92	/* Rx level */
93	METRIC_RX_LEVEL_MASK			= 0xFF,
94	METRIC_RX_LEVEL_SHIFT			= 24,
95
96	/* Privacy */
97	METRIC_PRIVACY_MASK				= 0x0F,
98	METRIC_PRIVACY_SHIFT			= 20,
99
100	/* Number of attempts */
101	METRIC_ATTEMPTS_NUMBER_MASK		= 0x0F,
102	METRIC_ATTEMPTS_NUMBER_SHIFT	= 16,
103
104
105	/* Rates */
106	METRIC_RATES_MASK				= 0x3F,
107	METRIC_RATES_SHIFT				= 10,
108
109	/* PBCC */
110	METRIC_MODULATION_MASK			= 0x03,
111	METRIC_MODULATION_SHIFT			= 8,
112
113	/* Preamble*/
114	METRIC_PREAMBLE_MASK			= 0x01,
115	METRIC_PREAMBLE_SHIFT			= 7,
116
117	/* Channel */
118	METRIC_CHANNEL_MASK				= 0x01,
119	METRIC_CHANNEL_SHIFT			= 6,
120
121	/* Spectrum management Capability */
122	METRIC_SPECTRUM_MANAGEMENT_MASK	= 0x01,
123	METRIC_SPECTRUM_MANAGEMENT_SHIFT= 5,
124
125	/* Priority Site */
126	METRIC_PRIORITY_SITE_MASK		= 0x01,
127	METRIC_PRIORITY_SITE_SHIFT		= 4,
128
129} matric_e;
130
131#define MAX_GB_MODE_CHANEL		14
132
133/* RSSI values boundaries and metric values for best, good, etc  signals */
134#define SELECT_RSSI_BEST_LEVEL      (-22)
135#define SELECT_RSSI_GOOD_LEVEL      (-38)
136#define SELECT_RSSI_NORMAL_LEVEL    (-56)
137#define SELECT_RSSI_POOR_LEVEL      (-72)
138#define SELECT_RSSI_BAD_LEVEL       (-82)
139
140
141#define  RSSI_METRIC_BEST      6
142#define  RSSI_METRIC_GOOD      5
143#define  RSSI_METRIC_NORMAL    4
144#define  RSSI_METRIC_POOR      3
145#define  RSSI_METRIC_BAD       2
146#define  RSSI_METRIC_NOSIGNAL  1
147
148/* Local functions prototypes */
149
150static match_e ssidMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite);
151
152
153static match_e bssidMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite);
154
155static match_e bssTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite);
156
157static match_e ratesMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
158
159static match_e modulationTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
160
161static match_e preambleTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
162
163static match_e channelMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
164
165static match_e spectrumManagementMatchingLevel(siteMgr_t *pSiteMgr, UINT16 siteCapability, UINT32 *matchingLevel);
166
167static match_e rxLevelMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
168
169static match_e attemptsNumberMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
170
171static match_e prioritySiteMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel);
172
173static siteEntry_t *addSelfSite(siteMgr_t *pSiteMgr);
174
175static TI_STATUS sendProbeResponse(siteMgr_t *pSiteMgr, macAddress_t *pBssid);
176
177/* Interface functions Implementation */
178
179
180/**************************************************************/
181/* DEBUG CLI CRASH (systemConfig stack usage reduction)       */
182/**************************************************************/
183
184static paramInfo_t gSystemCfgParam;
185static UINT8       curRsnData[255];
186/**************************************************************/
187
188/***********************************************************************
189 *                        siteMgr_disSelectSite
190 ***********************************************************************
191DESCRIPTION: Called by the SME SM in order to dis select the primary site.
192			The function set the primary site pointer to NULL and set its type to type regular
193
194INPUT:      hSiteMgr	-	site mgr handle.
195
196OUTPUT:
197
198RETURN:     OK
199
200************************************************************************/
201TI_STATUS siteMgr_disSelectSite(TI_HANDLE	hSiteMgr)
202{
203	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
204
205	/* This protection is because in the case that the BSS was LOST the primary site was removed already. */
206	if (pSiteMgr->pSitesMgmtParams->pPrimarySite != NULL)
207	{
208        WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("siteMgr_disSelectSite REMOVE Primary ssid=%s, bssid= 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\n\n",
209                   pSiteMgr->pSitesMgmtParams->pPrimarySite->ssid.ssidString,
210                   pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[0], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[1], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[2],
211                   pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[3], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[4], pSiteMgr->pSitesMgmtParams->pPrimarySite->bssid.addr[5] ));
212
213        pSiteMgr->pSitesMgmtParams->pPrimarySite->siteType = SITE_REGULAR;
214		pSiteMgr->pSitesMgmtParams->pPrevPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
215		pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
216	}
217
218	return OK;
219}
220
221/***********************************************************************
222 *                        siteMgr_selectSite
223 ***********************************************************************
224DESCRIPTION: Site selection function. Called by the SME SM in order to select
225			the best site for teh station.
226			The function go over the site table, and for each site it calls the match functions
227			If one fo the functions returns NO_MATCH from some reason, it skips the current site
228			and move to the next one.
229			The site that has the biggest bit map is chosen.
230				-	If a site is chosen, the function calls the 'systemConfig()' function in order
231					to configure the station with the chosen site attribute. Than it reports
232					a select status success to the SME SM.
233				-	If no site is chosen & the desired BSS type is infrastructure, it reports
234					a select status failure to the SME SM.
235				-	If no site is chosen but the desired BSS type is IBSS, we create a self site by adding an entry
236					to the site table, than we configure the system and reports a select status success to the SME SM.
237
238			NOTE: if the reScanFlag is set, means we received a scan command from the utility while in the
239					previous scanning, we report a select status failure to the SME SM because a re scan is needed
240					and we don't perform a selection.
241
242
243INPUT:      hSiteMgr	-	site mgr handle.
244
245OUTPUT:
246
247RETURN:     OK
248
249************************************************************************/
250siteEntry_t* siteMgr_selectSiteFromTable(TI_HANDLE	hSiteMgr)
251{
252	UINT32		metric;
253	UINT32		prevMatchingLevel = 0;
254	UINT8		siteIndex, tableIndex, numberOfSites = 0;
255	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
256	siteEntry_t	*pSiteEntry, *pLastMatchSite = NULL;
257	rsnData_t	rsnData;
258	dot11_RSN_t	*pRsnIe;
259	UINT8		rsnIECount=0;
260	UINT8       	length=0;
261	paramInfo_t	param;
262	radioBand_e	radioBand;
263	BOOL		bRegulatoryDomainEnabled;
264
265	siteTablesParams_t* currTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
266
267	WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
268							("SITE MATCH , Desired ssid (%s) len= (%d)\n\n",
269							 pSiteMgr->pDesiredParams->siteMgrDesiredSSID.ssidString,
270							 pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len));
271
272
273    for (tableIndex = 0; tableIndex < NUM_OF_SITE_TABLE ; tableIndex++)
274	{
275		/* If regulatoryDomains is enable, it should be checked if Country IE was detected */
276		param.paramType = REGULATORY_DOMAIN_ENABLED_PARAM;
277		regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
278		bRegulatoryDomainEnabled = param.content.regulatoryDomainEnabled;
279
280		if(currTable == &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables)
281			radioBand = RADIO_BAND_2_4_GHZ;
282		else
283			radioBand = RADIO_BAND_5_0_GHZ;
284
285		/* Check if country code was received */
286		param.paramType			 = REGULATORY_DOMAIN_IS_COUNTRY_FOUND;
287		param.content.eRadioBand = radioBand;
288		regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
289
290		if( ( bRegulatoryDomainEnabled == TRUE) && ( !param.content.bIsCountryFound ) )
291		{
292			if( radioBand == RADIO_BAND_2_4_GHZ)
293				WLAN_REPORT_WARNING(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("There is no valid Country IE for 2.4G band\n"));
294			else
295				WLAN_REPORT_WARNING(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("There is no valid Country IE for 5G band\n"));
296
297			if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)
298			{
299				/* change site table */
300				if(currTable == &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables)
301                {
302                    currTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
303/*                    siteMgr_updateRates(pSiteMgr, TRUE, TRUE);*/
304                }
305				else
306                {
307                    currTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
308/*                    siteMgr_updateRates(pSiteMgr, FALSE, TRUE);*/
309                }
310			}
311			continue;
312		}
313
314		for (siteIndex = 0; siteIndex < currTable->maxNumOfSites; siteIndex++)
315		{
316			pSiteEntry = &(currTable->siteTable[siteIndex]);
317
318			length = 0;
319			metric = 0;
320			pSiteEntry->matchingLevel = 0;
321
322
323			if(pSiteEntry->siteType == SITE_PRIMARY)
324			{
325				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE PRIMARY, ssid (%s len= %d ),  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->ssid.ssidString, pSiteEntry->ssid.len, pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
326			}
327
328
329			if (pSiteEntry->siteType != SITE_REGULAR)
330				continue;
331
332			numberOfSites++;
333
334			pSiteEntry->ssid.ssidString[pSiteEntry->ssid.len] = 0;
335			if (ssidMatchingLevel(pSiteMgr, pSiteEntry) != MATCH)
336			{
337				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, ssid (%s len= %d ),  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->ssid.ssidString, pSiteEntry->ssid.len, pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
338				continue;
339			}
340
341			if (bssidMatchingLevel(pSiteMgr, pSiteEntry) != MATCH)
342			{
343				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, bssid,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
344				continue;
345			}
346
347			if (bssTypeMatchingLevel(pSiteMgr, pSiteEntry) != MATCH)
348			{
349				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, bss Type,  %X-%X-%X-%X-%X-%X\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
350				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, bss Type,  siteMgrDesiredBSSType=%d, bssType=%d\n",pSiteMgr->pDesiredParams->siteMgrDesiredBSSType, pSiteEntry->bssType));
351				continue;
352			}
353
354			if (ratesMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
355			{
356				pSiteEntry->matchingLevel = 0;
357				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, rates,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
358				continue;
359			}
360			pSiteEntry->matchingLevel |= metric << METRIC_RATES_SHIFT;
361
362
363			/* Get the RSN IE data */
364			pRsnIe = pSiteEntry->pRsnIe;
365            rsnIECount = 0;
366			while ((length < pSiteEntry->rsnIeLen) && (rsnIECount < MAX_RSN_IE))
367			{
368				curRsnData[0+length] = pRsnIe->hdr.eleId;
369				curRsnData[1+length] = pRsnIe->hdr.eleLen;
370				os_memoryCopy(pSiteMgr->hOs, &curRsnData[2+length], (void *)pRsnIe->rsnIeData, pRsnIe->hdr.eleLen);
371				length += pRsnIe->hdr.eleLen+2;
372				pRsnIe += 1;
373                rsnIECount++;
374			}
375            if (length<pSiteEntry->rsnIeLen)
376            {
377                WLAN_REPORT_ERROR(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
378                                  ("siteMgr_selectSiteFromTable, RSN IE is too long: rsnIeLen=%d, MAX_RSN_IE=%d\n",
379                                    pSiteEntry->rsnIeLen, MAX_RSN_IE));
380			}
381
382			rsnData.pIe = (pSiteEntry->rsnIeLen==0) ? NULL :curRsnData;
383			rsnData.ieLen = pSiteEntry->rsnIeLen;
384			rsnData.privacy = pSiteEntry->privacy;
385
386			if (rsn_evalSite(pSiteMgr->hRsn, &rsnData, pSiteEntry->bssType, pSiteEntry->bssid, &metric) != OK)
387			{
388				pSiteEntry->matchingLevel = 0;
389				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, RSN,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
390				continue;
391			}
392
393			pSiteEntry->matchingLevel |= metric << METRIC_PRIVACY_SHIFT;
394
395
396
397
398#if 0 /* TODO - Define 4x evaluation */
399			if (ctrlData_evalSite(pSiteMgr->hCtrlData, &pSiteEntry->fourXParams, &metric) != OK)
400			{
401				pSiteEntry->matchingLevel = 0;
402				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, RSN,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
403				continue;
404			}
405			pSiteEntry->matchingLevel |= metric << METRIC_4X_SHIFT;
406#endif
407
408			if (modulationTypeMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
409			{
410				pSiteEntry->matchingLevel = 0;
411				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, modulation Type,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
412				continue;
413			}
414			pSiteEntry->matchingLevel |= metric << METRIC_MODULATION_SHIFT;
415
416			if (preambleTypeMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
417			{
418				pSiteEntry->matchingLevel = 0;
419				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, preamble,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
420				continue;
421			}
422			pSiteEntry->matchingLevel |= metric << METRIC_PREAMBLE_SHIFT;
423
424			if (channelMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
425			{
426				pSiteEntry->matchingLevel = 0;
427				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, channel,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
428				continue;
429			}
430			pSiteEntry->matchingLevel |= metric << METRIC_CHANNEL_SHIFT;
431
432			if (spectrumManagementMatchingLevel(pSiteMgr,pSiteEntry->capabilities,&metric) != MATCH)
433			{
434				pSiteEntry->matchingLevel = 0;
435				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, spectrum management.\n\n"));
436				continue;
437			}
438			pSiteEntry->matchingLevel |= metric << METRIC_SPECTRUM_MANAGEMENT_SHIFT;
439
440			if (rxLevelMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
441			{
442				pSiteEntry->matchingLevel = 0;
443				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, Rx level,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
444				continue;
445			}
446			pSiteEntry->matchingLevel |= metric << METRIC_RX_LEVEL_SHIFT;
447
448			if (attemptsNumberMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
449			{
450				pSiteEntry->matchingLevel = 0;
451				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, Number of attempts,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
452				continue;
453			}
454			pSiteEntry->matchingLevel |= metric << METRIC_ATTEMPTS_NUMBER_SHIFT;
455
456			if (prioritySiteMatchingLevel(pSiteMgr, pSiteEntry, &metric) != MATCH)
457			{
458				pSiteEntry->matchingLevel = 0;
459				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, priority Site,  %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid.addr[0], pSiteEntry->bssid.addr[1], pSiteEntry->bssid.addr[2], pSiteEntry->bssid.addr[3], pSiteEntry->bssid.addr[4], pSiteEntry->bssid.addr[5]));
460				continue;
461			}
462			pSiteEntry->matchingLevel |= metric << METRIC_PRIORITY_SITE_SHIFT;
463
464			if(pSiteEntry->matchingLevel > prevMatchingLevel)
465			{
466				prevMatchingLevel = pSiteEntry->matchingLevel;
467				pLastMatchSite = pSiteEntry;
468			}
469		}
470		if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)
471		{
472            /* change site table */
473            if(currTable == &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables)
474            {
475                currTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
476/*                siteMgr_updateRates(pSiteMgr, TRUE, TRUE);*/
477            }
478            else
479            {
480                currTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
481 /*               siteMgr_updateRates(pSiteMgr, FALSE, TRUE);*/
482            }
483		}
484		else
485			break;
486
487	}
488	WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("				NUMBER OF SITES:	%d\n\n", numberOfSites));
489
490	return pLastMatchSite;
491}
492
493TI_STATUS siteMgr_selectSite(TI_HANDLE	hSiteMgr)
494{
495	radioBand_e radioBand;
496	paramInfo_t	param;
497	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
498
499	siteEntry_t* pLastMatchSite = siteMgr_selectSiteFromTable(hSiteMgr);
500
501	if (pLastMatchSite != NULL)
502	{
503		pSiteMgr->pSitesMgmtParams->pPrimarySite = pLastMatchSite;
504		pLastMatchSite->siteType = SITE_PRIMARY;
505
506		WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SELECT SUCCESS FROM TABLE, bssid: %X-%X-%X-%X-%X-%X\n\n", pLastMatchSite->bssid.addr[0], pLastMatchSite->bssid.addr[1], pLastMatchSite->bssid.addr[2], pLastMatchSite->bssid.addr[3], pLastMatchSite->bssid.addr[4], pLastMatchSite->bssid.addr[5]));
507
508
509		/***************** Config Connection *************************/
510		param.paramType = CONN_TYPE_PARAM;
511		if (pLastMatchSite->bssType == BSS_INDEPENDENT)
512			param.content.connType = CONNECTION_IBSS;
513		else
514			param.content.connType = CONNECTION_INFRA;
515		conn_setParam(pSiteMgr->hConn, &param);
516
517		return smeSm_reportSelectStatus(pSiteMgr->hSmeSm, (mgmtStatus_e)SELECT_STATUS_SUCCESS);
518	}
519
520	if ((pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_ANY) ||
521		(pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_INDEPENDENT))	/* Means we can start our own BSS */
522	{
523
524		if (pSiteMgr->pDesiredParams->siteMgrDesiredChannel >= SITE_MGR_CHANNEL_A_MIN)
525		{
526			radioBand = RADIO_BAND_5_0_GHZ;
527		}
528		else {
529			radioBand = RADIO_BAND_2_4_GHZ;
530		}
531
532        /*
533        update the regulatory domain with the selected band
534        */
535		/* Check if the selected channel is valid according to regDomain */
536		param.paramType = REGULATORY_DOMAIN_GET_SCAN_CAPABILITIES;
537		param.content.channelCapabilityReq.band = radioBand;
538		param.content.channelCapabilityReq.scanOption = ACTIVE_SCANNING;
539		param.content.channelCapabilityReq.channelNum = pSiteMgr->pDesiredParams->siteMgrDesiredChannel;
540		regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
541		if (!param.content.channelCapabilityRet.channelValidity)
542		{
543			WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("IBSS SELECT FAILURE  - No channel !!!\n\n"));
544			return smeSm_reportSelectStatus(pSiteMgr->hSmeSm, (mgmtStatus_e)SELECT_STATUS_FAILURE);
545		}
546
547		pLastMatchSite = addSelfSite(pSiteMgr);
548		if (pLastMatchSite == NULL)
549		{
550			WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("IBSS SELECT FAILURE  - could not open self site !!!\n\n"));
551			return smeSm_reportSelectStatus(pSiteMgr->hSmeSm, (mgmtStatus_e)SELECT_STATUS_FAILURE);
552		}
553
554		pSiteMgr->pSitesMgmtParams->pPrimarySite = pLastMatchSite;
555		pLastMatchSite->siteType = SITE_SELF;
556
557		WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("%%%%%%%%%%%%%%	SELF SELECT SUCCESS, bssid: %X-%X-%X-%X-%X-%X	%%%%%%%%%%%%%%\n\n", pLastMatchSite->bssid.addr[0], pLastMatchSite->bssid.addr[1], pLastMatchSite->bssid.addr[2], pLastMatchSite->bssid.addr[3], pLastMatchSite->bssid.addr[4], pLastMatchSite->bssid.addr[5]));
558
559		/***************** Config Connection *************************/
560
561		param.paramType = CONN_TYPE_PARAM;											/* Connection Type*/
562		param.content.connType = CONNECTION_SELF;
563		conn_setParam(pSiteMgr->hConn, &param);
564
565		return smeSm_reportSelectStatus(pSiteMgr->hSmeSm, (mgmtStatus_e)SELECT_STATUS_SUCCESS);
566	}
567
568	WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SELECT FAILURE \n\n"));
569
570	return smeSm_reportSelectStatus(pSiteMgr->hSmeSm, (mgmtStatus_e)SELECT_STATUS_FAILURE);
571}
572
573
574void siteMgr_setNotReceivedParameter(TI_HANDLE	hSiteMgr, ssid_t* ssid , radioBand_e band)
575{
576	UINT8		siteIndex;
577	siteEntry_t *pSiteEntry;
578	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
579	siteTablesParams_t* currTable=NULL;
580
581
582	/*
583	 * Set the propiate site table.
584	 */
585	switch (band) {
586	case  RADIO_BAND_2_4_GHZ  :
587		currTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
588		break;
589
590	case RADIO_BAND_5_0_GHZ :
591		currTable = (siteTablesParams_t*)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
592		break;
593
594	case RADIO_BAND_DUAL:
595	default:
596		WLAN_REPORT_ERROR(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("siteMgr_setNotReceivedParameter() invalid band.\n"));
597
598	}
599
600
601	/*
602	 *  Increase the scanned sites "Not_Received" counter, this counter is used by the
603	 *  aging logic to clean old sites.
604	 */
605	for (siteIndex = 0; siteIndex < currTable->maxNumOfSites; siteIndex++)
606	{
607		pSiteEntry = &(currTable->siteTable[siteIndex]);
608
609		/* Self site & null site are never aged out. */
610		if ((pSiteEntry->siteType == SITE_SELF) || (pSiteEntry->siteType == SITE_NULL) || (pSiteEntry->siteType == SITE_PRIMARY))
611			continue;
612
613		/* If scan for any ssid all sites are expected to be found, and all should be marked. */
614		if( utils_isAnySSID(ssid) )
615		{
616			pSiteEntry->Not_Received++;
617		}
618		/* otherwise, the scan was a unicast scan, and thus only sites that match the desired SSID are marked*/
619		else
620		{
621            if(os_memoryCompare(pSiteMgr->hOs, (UINT8 *)ssid->ssidString, (UINT8 *)pSiteEntry->ssid.ssidString, pSiteEntry->ssid.len) == 0)
622			{
623				pSiteEntry->Not_Received++;
624			}
625		}
626	} /* for (... all sites in table ) */
627}
628
629
630
631void siteMgr_resetAttemptsNumberParameter(TI_HANDLE	hSiteMgr)
632{
633	UINT8		siteIndex, tableIndex;
634	siteEntry_t *pSiteEntry;
635	siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
636
637	siteTablesParams_t* currTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
638
639	for (tableIndex = 0; tableIndex < NUM_OF_SITE_TABLE ; tableIndex++)
640	{
641		for (siteIndex = 0; siteIndex < currTable->maxNumOfSites; siteIndex++)
642		{
643			pSiteEntry = &(currTable->siteTable[siteIndex]);
644
645			/* Self site & null site are never aged out. */
646			if ((pSiteEntry->siteType == SITE_SELF) || (pSiteEntry->siteType == SITE_NULL))
647				continue;
648
649			pSiteEntry->attemptsNumber = 0;
650		}
651		if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE)
652		{
653			/* change site table */
654			if(currTable == &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables)
655				currTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
656			else
657				currTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
658		}
659		else
660			break;
661
662	}
663}
664
665/* Local functions Implementation */
666
667/************************************************************************************************************/
668/*		Each functions of the following measures the matching level of a site for the specific attribute,
669		for example: BSSId, SSID, etc...
670		The input is the site manager handle which contains the desired attributes, and a pointer
671		to the site in the site table.
672		The function returns NO_MATCH if it is not possible to work with this site and MATCH otherwise.
673		Some of the functions, in a case of a MATCH, compute also the site matching level and returns it too.
674		This used later in the function 'siteMgr_selectSite()'.
675	*/
676/************************************************************************************************************/
677
678static match_e ssidMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite)
679{
680	if (pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len == 0)
681	{	/* match any site that is not hidden */
682        if (pSite->ssid.ssidString[0]=='\0') /* hidden ssid */
683        {
684            WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("Null SSID and hidden ssid \n\n"));
685            return NO_MATCH;
686        }
687        else
688        {
689            WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("Null SSID and not hidden ssid \n\n"));
690            return MATCH;
691        }
692    }
693	if ((pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len == pSite->ssid.len) &&
694            (os_memoryCompare(pSiteMgr->hOs, (UINT8 *)pSiteMgr->pDesiredParams->siteMgrDesiredSSID.ssidString, (UINT8 *)pSite->ssid.ssidString, pSite->ssid.len) == 0))
695		return MATCH;
696
697	else
698		return NO_MATCH;
699}
700
701
702static match_e bssidMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite)
703{
704	/* If BSSID is NULL, return NO_MATCH */
705	if MAC_NULL((&(pSite->bssid)))
706		return NO_MATCH;
707
708	if MAC_BROADCAST((&(pSiteMgr->pDesiredParams->siteMgrDesiredBSSID)))
709		return MATCH;
710
711	if MAC_EQUAL((&(pSite->bssid)), (&(pSiteMgr->pDesiredParams->siteMgrDesiredBSSID)))
712		return MATCH;
713
714	return NO_MATCH;
715}
716
717static match_e bssTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite)
718{
719	if (pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == BSS_ANY)
720		return MATCH;
721
722	if (pSiteMgr->pDesiredParams->siteMgrDesiredBSSType == pSite->bssType)
723		return MATCH;
724
725	return NO_MATCH;
726}
727
728static match_e ratesMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
729{
730    UINT32 MatchedBasicRateMask;
731    UINT32 MatchedSupportedRateMask;
732    UINT32 MatchedMaxBasicRate;
733    UINT32 MatchedMaxActiveRate;
734	UINT32 StaTotalRates;
735	UINT32 SiteTotalRates;
736
737	/* If the basic or active rate are invalid (0), return NO_MATCH. */
738	if ((pSite->maxBasicRate == DRV_RATE_INVALID) || (pSite->maxActiveRate == DRV_RATE_INVALID))
739	{
740		WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, 1.maxBasic=%d,maxActive=%d \n", pSite->maxBasicRate,pSite->maxActiveRate));
741		return NO_MATCH;
742	}
743
744	if (DRV_RATE_MAX < pSite->maxBasicRate)
745	{
746		WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, 1.maxBasic=%d,maxActive=%d \n", pSite->maxBasicRate,pSite->maxActiveRate));
747		return NO_MATCH;
748	}
749
750	if(pSite->channel <= 14)
751		siteMgr_updateRates(pSiteMgr, FALSE, TRUE);
752	else
753		siteMgr_updateRates(pSiteMgr, TRUE, TRUE);
754
755	StaTotalRates = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask
756				| pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
757
758	SiteTotalRates = pSite->rateMask.basicRateMask | pSite->rateMask.supportedRateMask;
759
760	MatchedBasicRateMask = SiteTotalRates
761				& pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
762
763
764    MatchedSupportedRateMask = SiteTotalRates &
765				pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
766
767    if ((StaTotalRates & pSite->rateMask.basicRateMask) != pSite->rateMask.basicRateMask)
768    {
769        WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,  ("SITE MATCH FAILURE, Basic or Supported Rates Doesn't Match \n"));
770        return NO_MATCH;
771
772    }
773
774
775    MatchedMaxBasicRate = getMaxRatefromBitmap(MatchedBasicRateMask);
776    MatchedMaxActiveRate = getMaxRatefromBitmap(MatchedSupportedRateMask);
777
778    MatchedMaxActiveRate = MAX(MatchedMaxBasicRate,MatchedMaxActiveRate);
779
780	*matchingLevel = MatchedMaxActiveRate;
781	return MATCH;
782}
783
784static match_e modulationTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
785{
786	/* If the desired modulation is CCK, we set the modulation bits off. */
787	if (pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_CCK)
788	{
789		*matchingLevel = 0;
790		return MATCH;
791	}
792
793	/* Now, the desired modulation is PBCC */
794	if (pSite->beaconModulation == DRV_MODULATION_PBCC)		/* if the site current modulation is PBCC */
795	{
796		*matchingLevel = 2;
797		return MATCH;
798	}
799
800	if (pSite->probeModulation == DRV_MODULATION_PBCC)		/* if the site potential modulation is PBCC */
801	{
802		*matchingLevel = 1;
803		return MATCH;
804	}
805	else												/* the current modulation is CCK */
806	{
807		*matchingLevel = 0;
808		return MATCH;
809	}
810}
811
812static match_e preambleTypeMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
813{
814	/* NOw, the chip preamble is SHORT */
815	/* If the desired preamble is LONG, we set the preamble bits off. */
816	if (pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType == PREAMBLE_LONG)
817	{
818		*matchingLevel = 0;
819		return MATCH;
820	}
821
822	/* Now, the desired preamble is SHORT */
823	if (pSite->currentPreambleType == PREAMBLE_SHORT)	/* site preamble is SHORT */
824	{
825		*matchingLevel = 1;
826		return MATCH;
827	}
828	else										/* site preamble is LONG */
829	{
830		*matchingLevel = 0;
831		return MATCH;
832	}
833}
834
835static match_e channelMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
836{
837	paramInfo_t     tParam;
838	/*	when 802.11d is enabled,
839	channels that are not valid for Active, will not be mach.*/
840	tParam.content.channel = pSite->channel;
841	tParam.paramType = REGULATORY_DOMAIN_IS_CHANNEL_SUPPORTED;
842	regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain, &tParam);
843	if ( !tParam.content.bIsChannelSupprted )
844	{
845        WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
846			("channelMatchingLevel: channel =%d isn't valid for Active and will not be matched.\n",
847			pSite->channel));
848		return NO_MATCH;
849	}
850
851	/* If the site channel is equal to the desired channel, we set the channel bit on. */
852	if (pSite->channel == pSiteMgr->pDesiredParams->siteMgrDesiredChannel)
853	{
854		*matchingLevel = 1;
855		return MATCH;
856	}
857	else
858	{
859		*matchingLevel = 0;
860		return MATCH;
861	}
862/*	return NO_MATCH; - unreachable*/
863
864}
865
866static match_e rxLevelMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
867{
868
869	if(pSite->rssi > SELECT_RSSI_BEST_LEVEL)
870		*matchingLevel = (UINT8)RSSI_METRIC_BEST;
871	else if (pSite->rssi > SELECT_RSSI_GOOD_LEVEL)
872		*matchingLevel = (UINT8)RSSI_METRIC_GOOD;
873	else if(pSite->rssi > SELECT_RSSI_NORMAL_LEVEL)
874		*matchingLevel = (UINT8)RSSI_METRIC_NORMAL;
875	else if (pSite->rssi > SELECT_RSSI_POOR_LEVEL)
876		*matchingLevel = (UINT8)RSSI_METRIC_POOR;
877	else if(pSite->rssi > SELECT_RSSI_BAD_LEVEL)
878		*matchingLevel = (UINT8)RSSI_METRIC_BAD;
879	else
880		*matchingLevel = (UINT8)RSSI_METRIC_NOSIGNAL;
881
882	return MATCH;
883
884}
885
886static match_e attemptsNumberMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
887{
888	if(pSite->attemptsNumber > 0)
889	{
890		return NO_MATCH;
891	}
892	else
893	{
894		*matchingLevel = 0x0F - pSite->attemptsNumber;
895		return MATCH;
896	}
897}
898
899static match_e spectrumManagementMatchingLevel(siteMgr_t *pSiteMgr, UINT16 siteCapability, UINT32 *matchingLevel)
900{
901	paramInfo_t		param;
902	TI_STATUS		status;
903	/* If the site has spectrum management capabilty and the station
904	   spectrumManagementCapabilty is enabled, we set the spectrum management bit on. */
905	param.paramType = REGULATORY_DOMAIN_MANAGEMENT_CAPABILITY_ENABLED_PARAM;
906	status = regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
907	if(status == OK && param.content.spectrumManagementEnabled)
908	{
909		if (siteCapability & DOT11_SPECTRUM_MANAGEMENT)
910			*matchingLevel = 1;
911		else
912			*matchingLevel = 0;
913	}
914
915	return MATCH;
916}
917
918static match_e prioritySiteMatchingLevel(siteMgr_t *pSiteMgr, siteEntry_t *pSite, UINT32 *matchingLevel)
919{
920	/* If the site channel is equal to the desired channel, we set the channel bit on. */
921	if (pSite->prioritySite)
922	{
923		*matchingLevel = 1;
924		return MATCH;
925	}
926	else
927	{
928		*matchingLevel = 0;
929		return MATCH;
930	}
931/*	return NO_MATCH; - unreachable */
932}
933
934/***********************************************************************
935 *                        addSelfSite
936 ***********************************************************************
937DESCRIPTION: This function is called if the selection fails and desired BSS type is IBSS
938			That means we creating our own network and wait for other stations to join us.
939			the best site for teh station.
940			Performs the following:
941				-	If the desired BSSID is broadcast, we generate a random BSSId, otherwise we use the desired one.
942				-	If the site table is full we remove the most old site
943				-	We send a probe response with our oiwn desired attributes in order to add the site to the site table
944
945INPUT:      pSiteMgr	-	site mgr handle.
946
947OUTPUT:
948
949RETURN:     Pointer to rthe self site entry in the site table
950
951************************************************************************/
952siteEntry_t *addSelfSite(siteMgr_t *pSiteMgr)
953{
954	siteEntry_t			*pSite;
955	macAddress_t		bssid;
956
957
958	if (utils_isJunkSSID(&(pSiteMgr->pDesiredParams->siteMgrDesiredSSID)) == TRUE)
959		return NULL ;
960
961	if MAC_BROADCAST((&(pSiteMgr->pDesiredParams->siteMgrDesiredBSSID)))
962	{
963		os_memoryCopy(pSiteMgr->hOs, (void *)bssid.addr, (void *)pSiteMgr->ibssBssid.addr, sizeof(macAddress_t));
964	}
965	else
966	{
967		os_memoryCopy(pSiteMgr->hOs, (void *)bssid.addr, (void *)pSiteMgr->pDesiredParams->siteMgrDesiredBSSID.addr, sizeof(macAddress_t));
968	}
969
970	if(pSiteMgr->pDesiredParams->siteMgrDesiredChannel <= 14)
971	{
972		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
973        pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
974	}
975	else
976	{
977		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
978		pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
979	}
980
981    siteMgr_ConfigRate(pSiteMgr);
982
983	/* First make sure that there is a place in the site table, if not, reomve the eldest site. */
984	if (pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->numOfSites == pSiteMgr->pSitesMgmtParams->pCurrentSiteTable->maxNumOfSites)
985		removeEldestSite(pSiteMgr);
986
987	sendProbeResponse(pSiteMgr, &bssid);
988
989	/* Now find the site in the site table. */
990	pSite = findSiteEntry(pSiteMgr, &bssid);
991	if (pSite == NULL)
992	{
993		return NULL;
994	}
995	pSite->beaconModulation = pSite->probeModulation;
996	pSite->barkerPreambleType = PREAMBLE_UNSPECIFIED;
997
998	return pSite;
999
1000}
1001
1002/***********************************************************************
1003 *                        sendProbeResponse
1004 ***********************************************************************
1005DESCRIPTION: This function is called by the function 'addSelfSite()' in order to send a probe response
1006			to the site mgr. This will cause the site manager to add a new entry to the site table, the self site entry.
1007
1008INPUT:      pSiteMgr	-	site mgr handle.
1009			pBssid		-	Received BSSID
1010
1011OUTPUT:
1012
1013RETURN:     OK
1014
1015************************************************************************/
1016static TI_STATUS sendProbeResponse(siteMgr_t *pSiteMgr, macAddress_t *pBssid)
1017{
1018	mlmeFrameInfo_t		frame;
1019	paramInfo_t			param;
1020	dot11_SSID_t 		ssid;
1021	dot11_RATES_t 		rates;
1022	dot11_FH_PARAMS_t 	FHParamsSet;
1023	dot11_DS_PARAMS_t 	DSParamsSet;
1024	dot11_CF_PARAMS_t 	CFParamsSet;
1025	dot11_IBSS_PARAMS_t IBSSParamsSet;
1026	UINT32				len = 0, ofdmIndex = 0;
1027    radioBand_e         band;
1028	dot11_RATES_t 		extRates;
1029	UINT8				ratesBuf[MAX_SUPPORTED_RATES];
1030	BOOL				extRatesInd = FALSE;
1031
1032	/* The easiest way to add a site to the site table is to simulate a probe frame. */
1033	frame.subType = PROBE_RESPONSE;
1034	os_memoryZero(pSiteMgr->hOs, &frame, sizeof(mlmeFrameInfo_t));
1035		/* Initialize the frame fields */
1036	frame.subType = PROBE_RESPONSE;
1037	os_memoryZero(pSiteMgr->hOs, (void *)frame.content.iePacket.timestamp, TIME_STAMP_LEN);
1038
1039	/* Build  Beacon interval  */
1040	frame.content.iePacket.beaconInerval = pSiteMgr->pDesiredParams->siteMgrDesiredBeaconInterval;
1041
1042	/* Build  capability field */
1043	frame.content.iePacket.capabilities = 0;
1044	frame.content.iePacket.capabilities |= (TRUE << CAP_IBSS_SHIFT); /* Bss type must be independent */
1045
1046	if ((pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType == PREAMBLE_SHORT))
1047		frame.content.iePacket.capabilities |= (TRUE << CAP_PREAMBLE_SHIFT);
1048
1049	/* call RSN to get the privacy desired */
1050	param.paramType = RSN_ENCRYPTION_STATUS_PARAM;
1051	rsn_getParam(pSiteMgr->hRsn, &param);
1052	if (param.content.rsnEncryptionStatus == RSN_CIPHER_NONE)
1053	{
1054		frame.content.iePacket.capabilities |= (FALSE << CAP_PRIVACY_SHIFT);
1055	} else {
1056		frame.content.iePacket.capabilities |= (TRUE << CAP_PRIVACY_SHIFT);
1057	}
1058
1059	if (pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_PBCC)
1060		frame.content.iePacket.capabilities |= (TRUE << CAP_PBCC_SHIFT);
1061
1062    if (pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
1063    {
1064        if(pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime == PHY_SLOT_TIME_SHORT)
1065            frame.content.iePacket.capabilities |= (TRUE << CAP_SLOT_TIME_SHIFT);
1066    }
1067
1068	/* Build ssid */
1069	os_memoryZero(pSiteMgr->hOs, (void *)ssid.serviceSetId, MAX_SSID_LEN);
1070
1071	if (pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len == 0)
1072		ssid.hdr.eleLen = 0;
1073	else
1074	{
1075		os_memoryCopy(pSiteMgr->hOs, (void *)ssid.serviceSetId, (void *)pSiteMgr->pDesiredParams->siteMgrDesiredSSID.ssidString, pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len);
1076		ssid.hdr.eleLen = pSiteMgr->pDesiredParams->siteMgrDesiredSSID.len;
1077	}
1078
1079	if(pSiteMgr->pDesiredParams->siteMgrDesiredChannel <= MAX_GB_MODE_CHANEL)
1080		siteMgr_updateRates(pSiteMgr, FALSE, TRUE);
1081	else
1082		siteMgr_updateRates(pSiteMgr, TRUE, TRUE);
1083
1084	/* Build Rates */
1085	bitMapToNetworkStringRates(pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask,
1086							   pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask,
1087							   ratesBuf, &len, &ofdmIndex);
1088
1089	if(pSiteMgr->siteMgrOperationalMode != DOT11_G_MODE ||
1090       pSiteMgr->pDesiredParams->siteMgrUseDraftNum == DRAFT_5_AND_EARLIER ||
1091	   ofdmIndex == len)
1092	{
1093		rates.hdr.eleId = DOT11_SUPPORTED_RATES_ELE_ID;
1094		rates.hdr.eleLen = len;
1095		os_memoryCopy(pSiteMgr->hOs, (void *)rates.rates, ratesBuf, rates.hdr.eleLen);
1096	}
1097	else
1098	{
1099		rates.hdr.eleId = DOT11_SUPPORTED_RATES_ELE_ID;
1100		rates.hdr.eleLen = ofdmIndex;
1101		os_memoryCopy(pSiteMgr->hOs, (void *)rates.rates, ratesBuf, rates.hdr.eleLen);
1102
1103		extRates.hdr.eleId = DOT11_EXT_SUPPORTED_RATES_ELE_ID;
1104		extRates.hdr.eleLen = len - ofdmIndex;
1105		os_memoryCopy(pSiteMgr->hOs, (void *)extRates.rates, &ratesBuf[ofdmIndex], extRates.hdr.eleLen);
1106		extRatesInd = TRUE;
1107	}
1108
1109
1110	/* Build FH */
1111	os_memoryZero(pSiteMgr->hOs, &FHParamsSet, sizeof(dot11_FH_PARAMS_t));
1112
1113	/* Build DS */
1114	DSParamsSet.hdr.eleLen = 1;
1115	DSParamsSet.currChannel = pSiteMgr->pDesiredParams->siteMgrDesiredChannel;
1116
1117	/* Build CF */
1118	os_memoryZero(pSiteMgr->hOs, &CFParamsSet, sizeof(dot11_CF_PARAMS_t));
1119
1120	/* Build IBSS */
1121	os_memoryZero(pSiteMgr->hOs, &IBSSParamsSet, sizeof(dot11_IBSS_PARAMS_t));
1122	IBSSParamsSet.hdr.eleLen = 2;
1123	IBSSParamsSet.atimWindow = pSiteMgr->pDesiredParams->siteMgrDesiredAtimWindow;
1124
1125	frame.content.iePacket.pSsid = &ssid;
1126	frame.content.iePacket.pRates = &rates;
1127
1128	if(extRatesInd)
1129		frame.content.iePacket.pExtRates = &extRates;
1130	else
1131		frame.content.iePacket.pExtRates = NULL;
1132
1133	frame.content.iePacket.pFHParamsSet = &FHParamsSet;
1134	frame.content.iePacket.pDSParamsSet = &DSParamsSet;
1135	frame.content.iePacket.pCFParamsSet = &CFParamsSet;
1136	frame.content.iePacket.pIBSSParamsSet = &IBSSParamsSet;
1137
1138    band = ( MAX_GB_MODE_CHANEL >= pSiteMgr->pDesiredParams->siteMgrDesiredChannel ? RADIO_BAND_2_4_GHZ : RADIO_BAND_5_0_GHZ );
1139	/* Update site */
1140	siteMgr_updateSite(pSiteMgr, pBssid, &frame ,pSiteMgr->pDesiredParams->siteMgrDesiredChannel, band, FALSE);
1141
1142	return OK;
1143}
1144
1145/***********************************************************************
1146 *                        systemConfig
1147 ***********************************************************************
1148DESCRIPTION: This function is called by the function 'siteMgr_selectSite()' in order to configure
1149			the system with the chosen site attribute.
1150
1151INPUT:      pSiteMgr	-	site mgr handle.
1152
1153OUTPUT:
1154
1155RETURN:     OK
1156
1157************************************************************************/
1158TI_STATUS systemConfig(siteMgr_t *pSiteMgr)
1159{
1160	siteEntry_t *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
1161	rsnData_t	rsnData;
1162	UINT8		rsnAssocIeLen;
1163    dot11_RSN_t *pRsnIe;
1164    UINT8       rsnIECount=0;
1165    UINT16      length;
1166    UINT16      capabilities;
1167    UINT16      PktLength=0;
1168    UINT8		*pIeBuffer=NULL;
1169
1170#ifdef EXC_MODULE_INCLUDED
1171    UINT8        ExternTxPower;
1172#endif
1173	TI_STATUS	status;
1174	slotTime_e	slotTime;
1175	UINT32		StaTotalRates;
1176	ACParameters_t *p_ACParametersDummy = NULL;
1177
1178
1179	if (pPrimarySite->probeRecv)
1180	{
1181		pIeBuffer = pPrimarySite->probeRespBuffer;
1182		PktLength = pPrimarySite->probeRespLength;
1183	}
1184    else if (pPrimarySite->beaconRecv)
1185	{
1186		pIeBuffer = pPrimarySite->beaconBuffer;
1187		PktLength = pPrimarySite->beaconLength;
1188	}
1189
1190	pSiteMgr->prevRadioBand = pSiteMgr->radioBand;
1191
1192	WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1193		("%s: Capabilities, Slot Time Bit = %d (capabilities = %d)\n", __FUNCTION__, (pPrimarySite->capabilities >> CAP_SLOT_TIME_SHIFT) & 1, pPrimarySite->capabilities));
1194
1195	if(pPrimarySite->channel <= MAX_GB_MODE_CHANEL)
1196	{
1197		if(pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_B_MODE)
1198		{
1199			pSiteMgr->siteMgrOperationalMode = DOT11_B_MODE;
1200			slotTime = PHY_SLOT_TIME_LONG;
1201
1202			WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1203				("%s: 11b Mode, Slot Time = %d\n", __FUNCTION__, (UINT8)slotTime));
1204		}
1205		else
1206		{
1207			pSiteMgr->siteMgrOperationalMode = DOT11_G_MODE;
1208
1209			if (((pPrimarySite->capabilities >> CAP_SLOT_TIME_SHIFT) & CAP_SLOT_TIME_MASK) == PHY_SLOT_TIME_SHORT)
1210			{
1211			slotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
1212
1213				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1214					("%s: 11g Mode, Slot Time = %d (desired)\n", __FUNCTION__, (UINT8)slotTime));
1215			}
1216			else
1217			{
1218				slotTime = PHY_SLOT_TIME_LONG;
1219
1220				WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1221					("%s: 11g Mode, Slot Time = %d\n", __FUNCTION__, (UINT8) slotTime));
1222			}
1223		}
1224
1225		pSiteMgr->radioBand = RADIO_BAND_2_4_GHZ;
1226		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
1227	}
1228	else
1229	{
1230		pSiteMgr->siteMgrOperationalMode = DOT11_A_MODE;
1231		pSiteMgr->radioBand = RADIO_BAND_5_0_GHZ;
1232		slotTime = PHY_SLOT_TIME_SHORT;
1233
1234		WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1235			("%s: 11a Mode, Slot Time = %d\n", __FUNCTION__, (UINT8)slotTime));
1236
1237		pSiteMgr->pSitesMgmtParams->pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
1238	}
1239
1240	/* since we are moving to the different band, the siteMgr should be reconfigured */
1241	if(pSiteMgr->prevRadioBand != pSiteMgr->radioBand)
1242		siteMgr_bandParamsConfig(pSiteMgr, TRUE);
1243
1244	if(pPrimarySite->channel <= MAX_GB_MODE_CHANEL)
1245		siteMgr_updateRates(pSiteMgr, FALSE, TRUE);
1246	else
1247		siteMgr_updateRates(pSiteMgr, TRUE, TRUE);
1248
1249	/* configure hal with common core-hal parameters */
1250	whalCtrl_SetRadioBand(pSiteMgr->hHalCtrl, pSiteMgr->radioBand);
1251
1252	pPrimarySite->currentSlotTime = slotTime;
1253	whalCtrl_SetSlotTime(pSiteMgr->hHalCtrl, slotTime);
1254
1255	/***************** Config HAL *************************/
1256	/* Current Beacon Interval */
1257	whalCtrl_SetBeaconInterval( pSiteMgr->hHalCtrl , pPrimarySite->beaconInterval);
1258
1259	/***************** Config Site Manager *************************/
1260	/* L.M. Should be fixed, should take into account the AP's rates */
1261	if(pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_CCK)
1262		pSiteMgr->chosenModulation = DRV_MODULATION_CCK;
1263	else if(pSiteMgr->pDesiredParams->siteMgrDesiredModulationType == DRV_MODULATION_PBCC)
1264	{
1265		if(pPrimarySite->probeModulation != DRV_MODULATION_NONE)
1266			pSiteMgr->chosenModulation = pPrimarySite->probeModulation;
1267		else
1268			pSiteMgr->chosenModulation = pPrimarySite->beaconModulation;
1269	}
1270	else
1271		pSiteMgr->chosenModulation = DRV_MODULATION_OFDM;
1272
1273	/* We use this variable in order tp perform the PBCC algorithm. */
1274	pSiteMgr->currentDataModulation = pSiteMgr->chosenModulation;
1275	/***************** Config Data CTRL *************************/
1276
1277	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_BSSID_PARAM;							/* Current BSSID */
1278	os_memoryCopy(pSiteMgr->hOs, &(gSystemCfgParam.content.ctrlDataCurrentBSSID), &(pPrimarySite->bssid), sizeof(macAddress_t));
1279	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1280
1281	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_BSS_TYPE_PARAM;							/* Current BSS Type */
1282	gSystemCfgParam.content.ctrlDataCurrentBssType = pPrimarySite->bssType;
1283	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1284
1285	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_PREAMBLE_TYPE_PARAM;					/* Current Preamble Type */
1286	if ((pSiteMgr->pDesiredParams->siteMgrDesiredPreambleType == PREAMBLE_SHORT) &&
1287		(pPrimarySite->currentPreambleType == PREAMBLE_SHORT))
1288		gSystemCfgParam.content.ctrlDataCurrentPreambleType = PREAMBLE_SHORT;
1289	else
1290		gSystemCfgParam.content.ctrlDataCurrentPreambleType = PREAMBLE_LONG;
1291	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1292
1293    /* Mutual Rates Matching */
1294	StaTotalRates = pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask |
1295					pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.supportedRateMask;
1296
1297
1298    pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask = StaTotalRates &
1299														   pPrimarySite->rateMask.supportedRateMask;
1300
1301	pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask = StaTotalRates &
1302															pPrimarySite->rateMask.basicRateMask;
1303	if (pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask == 0)
1304	{
1305		pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask =
1306			pSiteMgr->pDesiredParams->siteMgrCurrentDesiredRateMask.basicRateMask;
1307	}
1308
1309    pSiteMgr->pDesiredParams->siteMgrMatchedMaxBasicRate = getMaxRatefromBitmap(pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask);
1310
1311    pSiteMgr->pDesiredParams->siteMgrMatchedMaxActiveRate = getMaxRatefromBitmap(pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask);
1312
1313    pSiteMgr->pDesiredParams->siteMgrMatchedMaxActiveRate = MAX(pSiteMgr->pDesiredParams->siteMgrMatchedMaxBasicRate,pSiteMgr->pDesiredParams->siteMgrMatchedMaxActiveRate);
1314
1315	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_BASIC_RATE_PARAM;						/* Current Basic Rate */
1316	gSystemCfgParam.content.ctrlDataCurrentBasicRate = (rate_e)pSiteMgr->pDesiredParams->siteMgrMatchedMaxBasicRate;
1317	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1318
1319	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_BASIC_RATE_MASK_PARAM;
1320	gSystemCfgParam.content.ctrlDataBasicRateBitMask = pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask;
1321	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1322	gSystemCfgParam.paramType = CTRL_DATA_CURRENT_BASIC_MODULATION_PARAM;						/* Current Mgmt Rate */
1323	if ((pPrimarySite->maxBasicRate == DRV_RATE_1M) || (pPrimarySite->maxBasicRate == DRV_RATE_2M))
1324		gSystemCfgParam.content.ctrlDataCurrentBasicModulationType = DRV_MODULATION_QPSK;
1325	else if (pPrimarySite->maxBasicRate == DRV_RATE_22M)
1326		gSystemCfgParam.content.ctrlDataCurrentBasicModulationType = DRV_MODULATION_PBCC;
1327	else if (pPrimarySite->maxBasicRate < DRV_RATE_22M)
1328		gSystemCfgParam.content.ctrlDataCurrentBasicModulationType = DRV_MODULATION_CCK;
1329	else
1330		gSystemCfgParam.content.ctrlDataCurrentBasicModulationType = DRV_MODULATION_OFDM;
1331
1332	ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1333    gSystemCfgParam.paramType = CTRL_DATA_CURRENT_PROTECTION_STATUS_PARAM;
1334    gSystemCfgParam.content.ctrlDataProtectionEnabled = pPrimarySite->useProtection;
1335    ctrlData_setParam(pSiteMgr->hCtrlData, &gSystemCfgParam);
1336
1337	ctrlData_setSite(pSiteMgr->hCtrlData, &pPrimarySite->fourXParams);
1338
1339	pbccAlgorithm(pSiteMgr);
1340
1341	/********** Set Site QOS protocol support *************/
1342
1343	/* Set WME Params */
1344	 status = siteMgr_getWMEParamsSite(pSiteMgr,&p_ACParametersDummy);
1345	 if(status == OK)
1346	 {
1347		 gSystemCfgParam.content.qosSiteProtocol = WME;
1348	 }
1349	 else
1350	 {
1351			 gSystemCfgParam.content.qosSiteProtocol = NONE_QOS;
1352	 }
1353
1354	WLAN_REPORT_DEBUG_TX(pSiteMgr->hReport,
1355	 (" systemConfigt() : param.content.qosSiteProtoco %d\n", gSystemCfgParam.content.qosSiteProtocol));
1356
1357	 gSystemCfgParam.paramType = QOS_MNGR_SET_SITE_PROTOCOL;
1358	 qosMngr_setParams(pSiteMgr->hQosMngr,&gSystemCfgParam);
1359
1360     /* Set active protocol in qosMngr according to station desired mode and site capabilities
1361	Must be called BEFORE setting the "CURRENT_PS_MODE" into the QosMngr */
1362     qosMngr_selectActiveProtocol(pSiteMgr->hQosMngr);
1363
1364	 /* set PS capability parameter */
1365	 gSystemCfgParam.paramType = QOS_MNGR_CURRENT_PS_MODE;
1366	 if(pPrimarySite->APSDSupport == TRUE)
1367		 gSystemCfgParam.content.currentPsMode = PS_SCHEME_UPSD_TRIGGER;
1368	 else
1369		 gSystemCfgParam.content.currentPsMode = PS_SCHEME_LEGACY_PSPOLL;
1370      qosMngr_setParams(pSiteMgr->hQosMngr,&gSystemCfgParam);
1371
1372     /* Set upsd/ps_poll configuration */
1373     /* Must be done AFTER setting the active Protocol */
1374     qosMngr_setAcPsDeliveryMode (pSiteMgr->hQosMngr);
1375
1376	/***************** Config RSN *************************/
1377    /* Get the RSN IE data */
1378    pRsnIe = pPrimarySite->pRsnIe;
1379	length=0;
1380    rsnIECount = 0;
1381    while ((length < pPrimarySite->rsnIeLen) && (pPrimarySite->rsnIeLen < 255)
1382           && (rsnIECount < MAX_RSN_IE))
1383    {
1384        curRsnData[0+length] = pRsnIe->hdr.eleId;
1385        curRsnData[1+length] = pRsnIe->hdr.eleLen;
1386        os_memoryCopy(pSiteMgr->hOs, &curRsnData[2+length], (void *)pRsnIe->rsnIeData, pRsnIe->hdr.eleLen);
1387        length += pRsnIe->hdr.eleLen+2;
1388        pRsnIe += 1;
1389        rsnIECount++;
1390    }
1391    if (length<pPrimarySite->rsnIeLen)
1392    {
1393        WLAN_REPORT_ERROR(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1394                          ("siteMgr_selectSiteFromTable, RSN IE is too long: rsnIeLen=%d, MAX_RSN_IE=%d\n",
1395                            pPrimarySite->rsnIeLen, MAX_RSN_IE));
1396    }
1397
1398	rsnData.pIe = (pPrimarySite->rsnIeLen==0) ? NULL :curRsnData;
1399	rsnData.ieLen = pPrimarySite->rsnIeLen;
1400    rsnData.privacy = pPrimarySite->privacy;
1401
1402    rsn_setSite(pSiteMgr->hRsn, &rsnData, NULL, &rsnAssocIeLen);
1403
1404	/***************** Config RegulatoryDomain **************************/
1405
1406#ifdef EXC_MODULE_INCLUDED
1407	/* set EXC TPC if present */
1408	if(Exc_ParseClientTP(pSiteMgr->hOs,pPrimarySite,&ExternTxPower,pIeBuffer,PktLength) == OK)
1409    {
1410        WLAN_REPORT_INFORMATION(pSiteMgr->hReport, SITE_MGR_MODULE_LOG,
1411			("Select Exc_ParseClientTP == OK: Dbm = %d\n",ExternTxPower));
1412		gSystemCfgParam.paramType = REGULATORY_DOMAIN_EXTERN_TX_POWER_PREFERRED;
1413		gSystemCfgParam.content.ExternTxPowerPreferred = ExternTxPower;
1414		regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&gSystemCfgParam);
1415    }
1416	/* Parse and save the EXC Version Number if exists */
1417	excMngr_parseExcVer(pSiteMgr->hExcMngr, pIeBuffer, PktLength);
1418
1419#endif
1420
1421	/* Note: TX Power Control adjustment is now done through siteMgr_assocReport() */
1422	if (pPrimarySite->powerConstraint>0)
1423	{	/* setting power constraint */
1424		gSystemCfgParam.paramType = REGULATORY_DOMAIN_SET_POWER_CONSTRAINT_PARAM;
1425		gSystemCfgParam.content.powerConstraint = pPrimarySite->powerConstraint;
1426		regulatoryDomain_setParam(pSiteMgr->hRegulatoryDomain,&gSystemCfgParam);
1427	}
1428
1429
1430	/***************** Config MeasurementMgr object **************************/
1431    capabilities = pPrimarySite->capabilities;
1432
1433    /* Updating the Measurement Module Mode */
1434    measurementMgr_setMeasurementMode(pSiteMgr->hMeasurementMgr, capabilities,
1435									pIeBuffer, PktLength);
1436
1437
1438	return OK;
1439}
1440