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