1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * siteHash.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file siteHash.c
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \brief Site Hash implementation
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \see siteHash.h
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************/
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*																			*/
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*		MODULE:	siteHash.c													*/
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*    PURPOSE:	Site Hash implementation 									*/
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*																			*/
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/***************************************************************************/
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__  FILE_ID_84
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "report.h"
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h"
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "siteMgrApi.h"
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "siteHash.h"
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "smeApi.h"
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************************************************
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	This file implements the site hash mechanism. This mechanism is used for faster access to the sites information.
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	It is compound of the following:
60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		1.	hash function	-	which maps the 4 last bits of the BSSID to an entry in the hash table.
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		2.	hash table		-	each entry in the table points to a linked list of site entries
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		3.	site table		-	each entry holds a site information
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	In order to find a site in the site table, we operate the hash function on the site's BSSID.
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	We receive a hash entry. We go over the linked list pointed by this hash entry until we find the site entry.
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*****************************************************************************************************************/
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define WLAN_NUM_OF_MISSED_SACNS_BEFORE_AGING 2
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/********************************************/
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*		Functions Implementations			*/
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/********************************************/
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                        siteMgr_resetSiteTable						*
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtDESCRIPTION: reset the following things:
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Mgmt parameters structure
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Site table
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Hash table
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Primary site pointer
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Number of sites
83981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
84981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtINPUT:      hSiteMgr				-	Handle to site mgr
85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtOUTPUT:
88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtRETURN:     TI_OK
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt************************************************************************/
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS siteMgr_resetSiteTable(TI_HANDLE	hSiteMgr, siteTablesParams_t	*pSiteTableParams)
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	int i;
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	siteMgr_t		*pSiteMgr = (siteMgr_t *)hSiteMgr;
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	os_memoryZero(pSiteMgr->hOs, &pSiteTableParams->siteTable[0], sizeof(siteEntry_t)*pSiteTableParams->maxNumOfSites);
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	for (i = 0; i < pSiteTableParams->maxNumOfSites; i++)
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		pSiteTableParams->siteTable[i].index = i;
102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		pSiteTableParams->siteTable[i].siteType = SITE_NULL;
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSiteTableParams->siteTable[i].beaconRecv = TI_FALSE;
104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSiteTableParams->siteTable[i].dtimPeriod = 1;
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteTableParams->numOfSites = 0;
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteMgr->pSitesMgmtParams->pPrimarySite = NULL;
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return TI_OK;
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                        findSiteEntry									*
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtDESCRIPTION: Perform the following things:
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	Compute the site's hash entry based on the site BSSID and hash function
119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	Look fotr the site entry in the linked list pointed by the hash entry
120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	If the site is found in the site table, returns a pointer to the site entry
121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	If the site is not found, return NULL.
122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtINPUT:      pSiteMgr	-	Handle to site mgr
124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			mac			-	The site BSSID
125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtOUTPUT:
128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtRETURN:     Pointer to the site entry if site found, NULL otherwise
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt************************************************************************/
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtsiteEntry_t	*findSiteEntry(siteMgr_t		*pSiteMgr,
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				           TMacAddr 		*mac)
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    siteTablesParams_t      *pCurrentSiteTable = pSiteMgr->pSitesMgmtParams->pCurrentSiteTable;
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	siteEntry_t             *pSiteEntry;
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8                 tableIndex=2, i;
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    do
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tableIndex--;
143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		for (i = 0; i < pCurrentSiteTable->maxNumOfSites; i++)
144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    {
145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			pSiteEntry = &(pCurrentSiteTable->siteTable[i]);
146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    	if (MAC_EQUAL (pSiteEntry->bssid, *mac))
148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    	{
149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "FIND success, bssid: %X-%X-%X-%X-%X-%X\n\n", (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]);
150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    		return pSiteEntry;
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    	}
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    }
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	   if ((pSiteMgr->pDesiredParams->siteMgrDesiredDot11Mode == DOT11_DUAL_MODE) && (tableIndex==1))
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	   {   /* change site table */
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	       if (pCurrentSiteTable == &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables)
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pCurrentSiteTable = (siteTablesParams_t *)&pSiteMgr->pSitesMgmtParams->dot11A_sitesTables;
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	       else
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              {
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                  pCurrentSiteTable = &pSiteMgr->pSitesMgmtParams->dot11BG_sitesTables;
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt              }
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	   }
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    } while (tableIndex>0);
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "FIND failure, bssid: %X-%X-%X-%X-%X-%X\n\n", (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]);
171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return NULL;
174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                        findAndInsertSiteEntry									*
178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************
179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtDESCRIPTION: Perform the following things:
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	Compute the site's hash entry based on the site BSSID and hash function
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	Look for the site entry in the linked list pointed by the hash entry
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	If the site is found in the site table, returns a pointer to the site entry
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			-	If the site is not found in the site table, tries to add the site
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	If succeeds, returns a pointer to the site entry
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt				-	Otherwise, returns NULL
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtINPUT:      pSiteMgr	-	Handle to site mgr
188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			mac			-	The site BSSID
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            band        -   The site band
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtOUTPUT:
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtRETURN:     Pointer to the site entry if site found/inserted, NULL otherwise
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt************************************************************************/
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtsiteEntry_t	*findAndInsertSiteEntry(siteMgr_t		*pSiteMgr,
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt									TMacAddr    	*mac,
199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                    ERadioBand      band)
200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_UINT8             i, emptySiteIndex=0, nextSite2Remove=0;
202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	siteEntry_t         *pSiteEntry, *pPrimarySite=pSiteMgr->pSitesMgmtParams->pPrimarySite;
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	sitesMgmtParams_t   *pSitesMgmtParams  = pSiteMgr->pSitesMgmtParams;
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	siteTablesParams_t  *pCurrentSiteTable;
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL              firstEmptySiteFound = TI_FALSE;
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32            oldestTS;
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* choose site table according to AP's band */
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ( RADIO_BAND_2_4_GHZ == band )
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pCurrentSiteTable = &(pSitesMgmtParams->dot11BG_sitesTables);
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else if (RADIO_BAND_5_0_GHZ == band)
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pCurrentSiteTable = (siteTablesParams_t*) &(pSitesMgmtParams->dot11A_sitesTables);
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "Bad band: %d\n\n", band);
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pCurrentSiteTable = &(pSitesMgmtParams->dot11BG_sitesTables);
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Set the first TS to a site which is not the Primary site */
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pPrimarySite != &(pCurrentSiteTable->siteTable[0]))
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        oldestTS = pCurrentSiteTable->siteTable[0].localTimeStamp;
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		{
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        oldestTS = pCurrentSiteTable->siteTable[1].localTimeStamp;
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		}
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Loop all the sites till the desired MAC is found */
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for (i = 0; i < pCurrentSiteTable->maxNumOfSites; i++)
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSiteEntry = &(pCurrentSiteTable->siteTable[i]);
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (MAC_EQUAL (pSiteEntry->bssid, *mac))
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		{
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            TRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "FIND success, bssid: %X-%X-%X-%X-%X-%X\n\n", (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5]);
243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            return pSiteEntry;
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else if (pSiteEntry->siteType == SITE_NULL)
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {   /* Save the first empty site, in case the
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            desired MAC is not found */
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (!firstEmptySiteFound)
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                emptySiteIndex = i;
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                firstEmptySiteFound=TI_TRUE;
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if ((oldestTS > pSiteEntry->localTimeStamp) &&
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (pSiteEntry != pPrimarySite))
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {   /* Save the oldest site's index, according to TS */
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            oldestTS = pSiteEntry->localTimeStamp;
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            nextSite2Remove = i;
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((!firstEmptySiteFound) || (pCurrentSiteTable->numOfSites>=pCurrentSiteTable->maxNumOfSites))
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		/* No NULL entry has been found. Remove the oldest site */
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSiteEntry =  &(pCurrentSiteTable->siteTable[nextSite2Remove]);
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE9(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "INSERT failure, no free entry!, numOfSites=%d, removing site index=%d,\n                                bssid: %X-%X-%X-%X-%X-%X, ts=%d \n", pCurrentSiteTable->numOfSites, nextSite2Remove, pSiteEntry->bssid[0], pSiteEntry->bssid[1], pSiteEntry->bssid[2], pSiteEntry->bssid[3], pSiteEntry->bssid[4], pSiteEntry->bssid[5], pSiteEntry->localTimeStamp);
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        removeSiteEntry(pSiteMgr, pCurrentSiteTable, pSiteEntry);
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        emptySiteIndex = nextSite2Remove;
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pCurrentSiteTable->numOfSites++;
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteEntry = &(pCurrentSiteTable->siteTable[emptySiteIndex]);
279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	/* fill the entry with the station mac */
281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	MAC_COPY (pSiteEntry->bssid, *mac);
282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Some parameters have to be initialized immediately after entry allocation */
284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if(pSiteMgr->siteMgrOperationalMode == DOT11_G_MODE)
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSiteEntry->currentSlotTime = pSiteMgr->pDesiredParams->siteMgrDesiredSlotTime;
287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE8(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "INSERT success, bssid: %X-%X-%X-%X-%X-%X, band=%d, index=%d\n\n", (*mac)[0], (*mac)[1], (*mac)[2], (*mac)[3], (*mac)[4], (*mac)[5], band, emptySiteIndex);
289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return pSiteEntry;
292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                        removeSiteEntry								*
296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************
297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtDESCRIPTION: Removes the site entry from the site table
298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtINPUT:      pSiteMgr		   - Handle to site mgr
300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pCurrSiteTblParams - Pointer to current site table parameters
301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            hashPtr			   - Pointer to the site entry
302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtOUTPUT:
305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtRETURN:
307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt************************************************************************/
309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid removeSiteEntry(siteMgr_t  *pSiteMgr,
310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                     siteTablesParams_t  *pCurrSiteTblParams,
311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                     siteEntry_t         *pSiteEntry)
312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_UINT8			index;
314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	if (pSiteEntry == NULL)
316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "REMOVAL failure, site is NULL\n\n");
318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		return;
319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	if (pCurrSiteTblParams->numOfSites == 0)
322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE0(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "REMOVAL failure, site table is empty\n\n");
324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		return;
325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "removeSiteEntry REMOVE ssid=, bssid= 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\n\n",			   pSiteEntry->bssid[0], pSiteEntry->bssid[1], pSiteEntry->bssid[2],			   pSiteEntry->bssid[3], pSiteEntry->bssid[4], pSiteEntry->bssid[5] );
328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pCurrSiteTblParams->numOfSites--;
330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	/* Now remove (exclude) hashPtr entry from the linked list */
332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE6(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "REMOVAL success, bssid: %X-%X-%X-%X-%X-%X\n\n", pSiteEntry->bssid[0], pSiteEntry->bssid[1], pSiteEntry->bssid[2], pSiteEntry->bssid[3], pSiteEntry->bssid[4], pSiteEntry->bssid[5]);
334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, " SITE TABLE remaining entries number  %d \n", pCurrSiteTblParams->numOfSites);
335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	/* Clean the rest of the entry structure */
337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	index = pSiteEntry->index;     /* keep the index of the siteTable entry */
338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	os_memoryZero(pSiteMgr->hOs, pSiteEntry, sizeof(siteEntry_t));
339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* This is not required!!!! - Remove!!*/
341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteEntry->dtimPeriod = 1;
342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteEntry->siteType = SITE_NULL;
343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	pSiteEntry->index = index;   /* restore the index of the siteTable */
344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	/* if removing previous primary site - update the link */
346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	if (pSiteEntry == pSiteMgr->pSitesMgmtParams->pPrevPrimarySite)
347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		pSiteMgr->pSitesMgmtParams->pPrevPrimarySite = NULL;
349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return;
352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
354