blob: 8cfddfa9fd01e6c84bfcc6620ae72e50d4e3cf1f [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam842dad02014-02-18 18:44:02 -08002 * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam842dad02014-02-18 18:44:02 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080028/*
Jeff Johnson295189b2012-06-20 16:38:30 -070029 *
Jeff Johnson295189b2012-06-20 16:38:30 -070030 * This file dphHashTable.cc implements the member functions of
31 * DPH hash table class.
32 *
33 * Author: Sandesh Goel
34 * Date: 02/25/02
35 * History:-
36 * Date Modified by Modification Information
37 * --------------------------------------------------------------------
38 *
39 */
40#include "palTypes.h"
41#include "cfgApi.h"
42#include "schApi.h"
43#include "dphGlobal.h"
44#include "limDebug.h"
45
Jeff Johnson295189b2012-06-20 16:38:30 -070046
Jeff Johnson295189b2012-06-20 16:38:30 -070047#include "halMsgApi.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070048
49// ---------------------------------------------------------------------
50/**
51 * dphHashTableClass()
52 *
53 * FUNCTION:
54 * Constructor function
55 *
56 * LOGIC:
57 *
58 * ASSUMPTIONS:
59 *
60 * NOTE:
61 *
62 * @param None
63 * @return None
64 */
65
66void dphHashTableClassInit(tpAniSirGlobal pMac, dphHashTableClass* pDphHashTable)
67{
68 tANI_U16 i;
69
70 for (i=0; i<pDphHashTable->size; i++)
71 {
72 pDphHashTable->pHashTable[i] = 0;
73 }
74
75 for (i=0; i<pDphHashTable->size; i++)
76 {
77 pDphHashTable->pDphNodeArray[i].valid = 0;
78 pDphHashTable->pDphNodeArray[i].added = 0;
79 pDphHashTable->pDphNodeArray[i].assocId = i;
80 }
81
82}
83
84// ---------------------------------------------------------------------
85/**
86 * hashFunction
87 *
88 * FUNCTION:
89 * Hashing function
90 *
91 * LOGIC:
92 *
93 * ASSUMPTIONS:
94 *
95 * NOTE:
96 *
97 * @param staAddr MAC address of the station
98 * @return None
99 */
100
101tANI_U16 hashFunction(tpAniSirGlobal pMac, tANI_U8 staAddr[], tANI_U16 numSta)
102{
103 int i;
104 tANI_U16 sum = 0;
105
106 for (i=0; i<6; i++)
107 sum += staAddr[i];
108
109 return (sum % numSta);
110}
111
112// ---------------------------------------------------------------------
113/**
114 * dphLookupHashEntry
115 *
116 * FUNCTION:
117 * Look up an entry in hash table
118 *
119 * LOGIC:
120 *
121 * ASSUMPTIONS:
122 *
123 * NOTE:
124 *
125 * @param staAddr MAC address of the station
126 * @param pStaId pointer to the Station ID assigned to the station
127 * @return pointer to STA hash entry if lookup was a success \n
128 * NULL if lookup was a failure
129 */
130
131tpDphHashNode dphLookupHashEntry(tpAniSirGlobal pMac, tANI_U8 staAddr[], tANI_U16 *pAssocId,
132 dphHashTableClass* pDphHashTable)
133{
134 tpDphHashNode ptr = NULL;
135 tANI_U16 index = hashFunction(pMac, staAddr, pDphHashTable->size);
136
137 for (ptr = pDphHashTable->pHashTable[index]; ptr; ptr = ptr->next)
138 {
139 if (dphCompareMacAddr(staAddr, ptr->staAddr))
140 {
141 *pAssocId = ptr->assocId;
142 break;
143 }
144 }
145 return ptr;
146}
147
148// ---------------------------------------------------------------------
149/**
150 * dphGetHashEntry
151 *
152 * FUNCTION:
153 * Get a pointer to the hash node
154 *
155 * LOGIC:
156 *
157 * ASSUMPTIONS:
158 *
159 * NOTE:
160 *
161 * @param staId Station ID
162 * @return pointer to STA hash entry if lookup was a success \n
163 * NULL if lookup was a failure
164 */
165
Gopichand Nakkala777e6032012-12-31 16:39:21 -0800166tpDphHashNode dphGetHashEntry(tpAniSirGlobal pMac, tANI_U16 peerIdx, dphHashTableClass* pDphHashTable)
Jeff Johnson295189b2012-06-20 16:38:30 -0700167{
Gopichand Nakkala777e6032012-12-31 16:39:21 -0800168 if (peerIdx < pDphHashTable->size)
Jeff Johnson295189b2012-06-20 16:38:30 -0700169 {
Gopichand Nakkala777e6032012-12-31 16:39:21 -0800170 if (pDphHashTable->pDphNodeArray[peerIdx].added)
171 return &pDphHashTable->pDphNodeArray[peerIdx];
Jeff Johnson295189b2012-06-20 16:38:30 -0700172 else
173 return NULL;
174 }
175 else
176 return NULL;
177
178}
179
180static inline tpDphHashNode getNode(tpAniSirGlobal pMac, tANI_U8 assocId, dphHashTableClass* pDphHashTable)
181{
182 return &pDphHashTable->pDphNodeArray[assocId];
183}
184
185
186
187
188// ---------------------------------------------------------------------
189/**
190 * dphLookupAssocId
191 *
192 * FUNCTION:
193 * This function looks up assocID given the station Id. It traverses the complete table to do this.
194 * Need to find an efficient way to do this.
195 * LOGIC:
196 *
197 * ASSUMPTIONS:
198 *
199 * NOTE:
200 *
201 * @param pMac pointer to global Mac structure.
202 * @param staIdx station ID
203 * @param *assocId pointer to associd to be returned by this function.
204 * @return pointer to the dph node.
205 */
206tpDphHashNode dphLookupAssocId(tpAniSirGlobal pMac, tANI_U16 staIdx, tANI_U16* assocId, dphHashTableClass* pDphHashTable)
207{
208 tANI_U8 i;
209
210 for(i=0; i<pDphHashTable->size; i++)
211 {
212 if( (pDphHashTable->pDphNodeArray[i].added) &&
213 (pDphHashTable->pDphNodeArray[i].staIndex == staIdx))
214 {
215 *assocId = i;
216 break;
217 }
218
219 }
220 if(i==pDphHashTable->size)
221 return NULL;
222 return &pDphHashTable->pDphNodeArray[i];
223
224}
225
226
227
228
229/** -------------------------------------------------------------
230\fn dphInitStaState
231\brief Initialize STA state. this function saves the staId from the current entry in the DPH table with given assocId
232\ if validStaIdx flag is set. Otherwise it sets the staId to invalid.
233\param tpAniSirGlobal pMac
234\param tSirMacAddr staAddr
235\param tANI_U16 assocId
236\param tANI_U8 validStaIdx - true ==> the staId in the DPH entry with given assocId is valid and restore it back.
237\ false ==> set the staId to invalid.
238\return tpDphHashNode - DPH hash node if found.
239 -------------------------------------------------------------*/
240
241tpDphHashNode dphInitStaState(tpAniSirGlobal pMac, tSirMacAddr staAddr,
242 tANI_U16 assocId, tANI_U8 validStaIdx, dphHashTableClass* pDphHashTable)
243{
244 tANI_U32 val;
245
246 tpDphHashNode pStaDs;
247 tANI_U16 staIdx = HAL_STA_INVALID_IDX;
248
249 if (assocId >= pDphHashTable->size)
250 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700251 PELOGE(limLog(pMac, LOGE, FL("Invalid Assoc Id %d"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700252 return NULL;
253 }
254
255 pStaDs = getNode(pMac, (tANI_U8) assocId, pDphHashTable);
256 staIdx = pStaDs->staIndex;
257
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700258 PELOG1(limLog(pMac, LOG1, FL("Assoc Id %d, Addr %08X"), assocId, pStaDs);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700259
260 // Clear the STA node except for the next pointer (last 4 bytes)
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +0530261 vos_mem_set( (tANI_U8 *) pStaDs, sizeof(tDphHashNode) - sizeof(tpDphHashNode), 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700262
263 // Initialize the assocId
264 pStaDs->assocId = assocId;
265 if(true == validStaIdx)
266 pStaDs->staIndex = staIdx;
267 else
268 pStaDs->staIndex = HAL_STA_INVALID_IDX;
269
270 // Initialize STA mac address
Bansidhar Gopalachari0a96a382013-07-24 16:55:34 +0530271 vos_mem_copy( pStaDs->staAddr, staAddr, sizeof(tSirMacAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -0700272
273 // Initialize fragmentation threshold
274 if (wlan_cfgGetInt(pMac, WNI_CFG_FRAGMENTATION_THRESHOLD, &val) != eSIR_SUCCESS)
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700275 limLog(pMac, LOGP, FL("could not retrieve fragmentation threshold"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700276 else
277 pStaDs->fragSize = (tANI_U16) val;
278
279 pStaDs->added = 1;
280 pStaDs->encPolicy = HAL_ENC_POLICY_NULL;
281
Jeff Johnson295189b2012-06-20 16:38:30 -0700282#ifdef WMM_APSD
283 pStaDs->stopQueue = 0;
284 pStaDs->spStatus = 0;
285 pStaDs->apsdMaxSpLen = 0;
286 pStaDs->acMode[0] = pStaDs->acMode[1] = pStaDs->acMode[2] = pStaDs->acMode[3] = 0;
287#endif /* WMM_APSD */
288 pStaDs->valid = 1;
289 return pStaDs;
290}
291
292// ---------------------------------------------------------------------
293/**
294 * dphAddHashEntry
295 *
296 * FUNCTION:
297 * Add entry to hash table
298 *
299 * LOGIC:
300 *
301 * ASSUMPTIONS:
302 *
303 * NOTE:
304 *
305 * @param staAddr MAC address of the station
306 * @param staId Station ID assigned to the station
307 * @return Pointer to STA hash entry
308 */
309
310tpDphHashNode dphAddHashEntry(tpAniSirGlobal pMac, tSirMacAddr staAddr, tANI_U16 assocId, dphHashTableClass* pDphHashTable)
311{
312 tpDphHashNode ptr, node;
313 tANI_U16 index = hashFunction(pMac, staAddr, pDphHashTable->size);
314
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700315 PELOG1(limLog(pMac, LOG1, FL("assocId %d index %d STA addr"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700316 assocId, index);
317 dphPrintMacAddr(pMac, staAddr, LOG1);)
318
319 if (assocId >= pDphHashTable->size)
320 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700321 PELOGE(limLog(pMac, LOGE, FL("invalid STA id %d"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700322 return NULL;
323 }
324
325 if (pDphHashTable->pDphNodeArray[assocId].added)
326 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700327 PELOGE(limLog(pMac, LOGE, FL("already added STA %d"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 return NULL;
329 }
330
331 for (ptr = pDphHashTable->pHashTable[index]; ptr; ptr = ptr->next)
332 {
333 if (ptr == ptr->next)
334 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700335 PELOGE(limLog(pMac, LOGE, FL("Infinite Loop"));)
Jeff Johnson295189b2012-06-20 16:38:30 -0700336 return NULL;
337 }
338
339 if (dphCompareMacAddr(staAddr, ptr->staAddr) || ptr->assocId== assocId)
340 break;
341 }
342
343 if (ptr)
344 {
345 // Duplicate entry
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700346 limLog(pMac, LOGE, FL("assocId %d hashIndex %d entry exists"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700347 assocId, index);
348 return NULL;
349 }
350 else
351 {
352 if (dphInitStaState(pMac, staAddr, assocId, false, pDphHashTable) == NULL)
353 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700354 PELOGE(limLog(pMac, LOGE, FL("could not Init STAid=%d"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700355 return NULL;
356 }
357
358 // Add the node to the link list
359 pDphHashTable->pDphNodeArray[assocId].next = pDphHashTable->pHashTable[index];
360 pDphHashTable->pHashTable[index] = &pDphHashTable->pDphNodeArray[assocId];
361
362 node = pDphHashTable->pHashTable[index];
363 return node;
364 }
365}
366
367// ---------------------------------------------------------------------
368/**
369 * dphDeleteHashEntry
370 *
371 * FUNCTION:
372 * Delete entry from hash table
373 *
374 * LOGIC:
375 *
376 * ASSUMPTIONS:
377 *
378 * NOTE:
379 *
380 * @param staAddr MAC address of the station
381 * @param staId Station ID assigned to the station
382 * @return eSIR_SUCCESS if successful,\n
383 * eSIR_FAILURE otherwise
384 */
385
386tSirRetStatus dphDeleteHashEntry(tpAniSirGlobal pMac, tSirMacAddr staAddr, tANI_U16 assocId, dphHashTableClass* pDphHashTable)
387{
388 tpDphHashNode ptr, prev;
389 tANI_U16 index = hashFunction(pMac, staAddr, pDphHashTable->size);
390
391
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700392 PELOG1(limLog(pMac, LOG1, FL("assocId %d index %d STA addr"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700393 assocId, index);
394 dphPrintMacAddr(pMac, staAddr, LOG1);)
395
396 if (assocId >= pDphHashTable->size)
397 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700398 PELOGE(limLog(pMac, LOGE, FL("invalid STA id %d"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700399 return eSIR_FAILURE;
400 }
401
402 if (pDphHashTable->pDphNodeArray[assocId].added == 0)
403 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700404 PELOGE(limLog(pMac, LOGE, FL("STA %d never added"), assocId);)
Jeff Johnson295189b2012-06-20 16:38:30 -0700405 return eSIR_FAILURE;
406 }
407
408
409 for (prev = 0, ptr = pDphHashTable->pHashTable[index];
410 ptr;
411 prev = ptr, ptr = ptr->next)
412 {
413 if (dphCompareMacAddr(staAddr, ptr->staAddr))
414 break;
415 if (prev == ptr)
416 {
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700417 PELOGE(limLog(pMac, LOGE, FL("Infinite Loop"));)
Jeff Johnson295189b2012-06-20 16:38:30 -0700418 return eSIR_FAILURE;
419 }
420 }
421
422 if (ptr)
423 {
424 /// Delete the entry after invalidating it
425 ptr->valid = 0;
Lee Hoonkif987a0b2013-01-29 02:07:07 -0800426 memset(ptr->staAddr, 0, sizeof(ptr->staAddr));
Jeff Johnson295189b2012-06-20 16:38:30 -0700427 if (prev == 0)
428 pDphHashTable->pHashTable[index] = ptr->next;
429 else
430 prev->next = ptr->next;
431 ptr->added = 0;
432 ptr->next = 0;
433 }
434 else
435 {
436 /// Entry not present
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700437 PELOGE(limLog(pMac, LOGE, FL("Entry not present STA addr"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700438 dphPrintMacAddr(pMac, staAddr, LOGE);)
439 return eSIR_FAILURE;
440 }
441
442 return eSIR_SUCCESS;
443}
444
445// ---------------------------------------------------------------------
446/**
447 * dphPrintMacAddr
448 *
449 * FUNCTION:
450 * Print a MAC address
451 *
452 * LOGIC:
453 *
454 * ASSUMPTIONS:
455 *
456 * NOTE:
457 *
458 * @param addr MAC address
459 * @return None
460 */
461
462void
463dphPrintMacAddr(tpAniSirGlobal pMac, tANI_U8 addr[], tANI_U32 level)
464{
Kiran Kumar Lokereaf882c82013-03-18 16:07:05 -0700465 limLog(pMac, (tANI_U16) level, FL("MAC ADDR = %d:%d:%d:%d:%d:%d"),
Jeff Johnson295189b2012-06-20 16:38:30 -0700466 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
467}
468
469// ---------------------------------------------------------------------