blob: e3d665f548d0d1c578e7ca5df5130373c0c49560 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. 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.
20 */
21
22/*
23 * */
24/**=========================================================================
25
26 \file limSession.c
27
28 \brief implementation for lim Session related APIs
29
30 \author Sunit Bhatia
31
32 Copyright 2008 (c) Qualcomm, Incorporated. All Rights Reserved.
33
34 Qualcomm Confidential and Proprietary.
35
36 ========================================================================*/
37
38
39/*--------------------------------------------------------------------------
40 Include Files
41 ------------------------------------------------------------------------*/
42#include "aniGlobal.h"
43#include "limDebug.h"
44#include "limSession.h"
45#include "limUtils.h"
46#ifdef FEATURE_WLAN_CCX
47#include "ccxApi.h"
48#endif
49
50/*--------------------------------------------------------------------------
51
52 \brief peInitBeaconParams() - Initialize the beaconParams structure
53
54
55 \param tpPESession - pointer to the session context or NULL if session can not be created.
56 \return void
57 \sa
58
59 --------------------------------------------------------------------------*/
60
61void peInitBeaconParams(tpAniSirGlobal pMac, tpPESession psessionEntry)
62{
63 psessionEntry->beaconParams.beaconInterval = 0;
64 psessionEntry->beaconParams.fShortPreamble = 0;
65 psessionEntry->beaconParams.llaCoexist = 0;
66 psessionEntry->beaconParams.llbCoexist = 0;
67 psessionEntry->beaconParams.llgCoexist = 0;
68 psessionEntry->beaconParams.ht20Coexist = 0;
69 psessionEntry->beaconParams.llnNonGFCoexist = 0;
70 psessionEntry->beaconParams.fRIFSMode = 0;
71 psessionEntry->beaconParams.fLsigTXOPProtectionFullSupport = 0;
72 psessionEntry->beaconParams.gHTObssMode = 0;
73
74 // Number of legacy STAs associated
75 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLim11bParams, sizeof(tLimProtStaParams));
76 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLim11aParams, sizeof(tLimProtStaParams));
77 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLim11gParams, sizeof(tLimProtStaParams));
78 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLimNonGfParams, sizeof(tLimProtStaParams));
79 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLimHt20Params, sizeof(tLimProtStaParams));
80 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLimLsigTxopParams, sizeof(tLimProtStaParams));
81 palZeroMemory(pMac->hHdd, (void*)&psessionEntry->gLimOlbcParams, sizeof(tLimProtStaParams));
82}
83
84/*--------------------------------------------------------------------------
85
86 \brief peCreateSession() - creates a new PE session given the BSSID
87
88 This function returns the session context and the session ID if the session
89 corresponding to the passed BSSID is found in the PE session table.
90
91 \param pMac - pointer to global adapter context
92 \param bssid - BSSID of the new session
93 \param sessionId -session ID is returned here, if session is created.
94
95 \return tpPESession - pointer to the session context or NULL if session can not be created.
96
97 \sa
98
99 --------------------------------------------------------------------------*/
100tpPESession peCreateSession(tpAniSirGlobal pMac, tANI_U8 *bssid , tANI_U8* sessionId, tANI_U16 numSta)
101{
102 tANI_U8 i;
103 for(i =0; i < pMac->lim.maxBssId; i++)
104 {
105 /* Find first free room in session table */
106 if(pMac->lim.gpSession[i].valid == FALSE)
107 {
108 palZeroMemory(pMac, (void*)&pMac->lim.gpSession[i], sizeof(tPESession));
109
110 //Allocate space for Station Table for this session.
111 if (eHAL_STATUS_SUCCESS != palAllocateMemory(pMac->hHdd,
112 (void **) &pMac->lim.gpSession[i].dph.dphHashTable.pHashTable, sizeof(tpDphHashNode)*numSta))
113 {
114 limLog(pMac, LOGE, FL("memory allocate failed!\n"));
115 return NULL;
116 }
117
118 if (eHAL_STATUS_SUCCESS != palAllocateMemory(pMac->hHdd,
119 (void **) &pMac->lim.gpSession[i].dph.dphHashTable.pDphNodeArray, sizeof(tDphHashNode)*numSta))
120 {
121 limLog(pMac, LOGE, FL("memory allocate failed!\n"));
122 palFreeMemory(pMac->hHdd,pMac->lim.gpSession[i].dph.dphHashTable.pHashTable);
123 return NULL;
124 }
125 pMac->lim.gpSession[i].dph.dphHashTable.size = numSta;
126
127 dphHashTableClassInit(pMac,
128 &pMac->lim.gpSession[i].dph.dphHashTable);
129
130 /* Copy the BSSID to the session table */
131 sirCopyMacAddr(pMac->lim.gpSession[i].bssId, bssid);
132 pMac->lim.gpSession[i].valid = TRUE;
133
134 /* Intialize the SME and MLM states to IDLE */
135 pMac->lim.gpSession[i].limMlmState = eLIM_MLM_IDLE_STATE;
136 pMac->lim.gpSession[i].limSmeState = eLIM_SME_IDLE_STATE;
137 pMac->lim.gpSession[i].limCurrentAuthType = eSIR_OPEN_SYSTEM;
138 peInitBeaconParams(pMac, &pMac->lim.gpSession[i]);
139#ifdef WLAN_FEATURE_VOWIFI_11R
140 pMac->lim.gpSession[i].is11Rconnection = FALSE;
141#endif
142
143#ifdef FEATURE_WLAN_CCX
144 pMac->lim.gpSession[i].isCCXconnection = FALSE;
145#endif
146
147#if defined WLAN_FEATURE_VOWIFI_11R || defined FEATURE_WLAN_CCX
148 pMac->lim.gpSession[i].isFastTransitionEnabled = FALSE;
149#endif
150 *sessionId = i;
151
152 pMac->lim.gpSession[i].gLimPhyMode = WNI_CFG_PHY_MODE_11G; //TODO :Check with the team what should be default mode
153 return(&pMac->lim.gpSession[i]);
154 }
155 }
156 limLog(pMac, LOGE, FL("Session can not be created.. Reached Max permitted sessions \n "));
157 return NULL;
158}
159
160
161/*--------------------------------------------------------------------------
162 \brief peFindSessionByBssid() - looks up the PE session given the BSSID.
163
164 This function returns the session context and the session ID if the session
165 corresponding to the given BSSID is found in the PE session table.
166
167 \param pMac - pointer to global adapter context
168 \param bssid - BSSID of the session
169 \param sessionId -session ID is returned here, if session is found.
170
171 \return tpPESession - pointer to the session context or NULL if session is not found.
172
173 \sa
174 --------------------------------------------------------------------------*/
175tpPESession peFindSessionByBssid(tpAniSirGlobal pMac, tANI_U8* bssid, tANI_U8* sessionId)
176{
177 tANI_U8 i;
178
179 for(i =0; i < pMac->lim.maxBssId; i++)
180 {
181 /* If BSSID matches return corresponding tables address*/
182 if( (pMac->lim.gpSession[i].valid) && (sirCompareMacAddr(pMac->lim.gpSession[i].bssId, bssid)))
183 {
184 *sessionId = i;
185 return(&pMac->lim.gpSession[i]);
186 }
187 }
188
189 limLog(pMac, LOG4, FL("Session lookup fails for BSSID: \n "));
190 limPrintMacAddr(pMac, bssid, LOG4);
191 return(NULL);
192
193}
194
195
196
197/*--------------------------------------------------------------------------
198 \brief peFindSessionBySessionId() - looks up the PE session given the session ID.
199
200 This function returns the session context if the session
201 corresponding to the given session ID is found in the PE session table.
202
203 \param pMac - pointer to global adapter context
204 \param sessionId -session ID for which session context needs to be looked up.
205
206 \return tpPESession - pointer to the session context or NULL if session is not found.
207
208 \sa
209 --------------------------------------------------------------------------*/
210 tpPESession peFindSessionBySessionId(tpAniSirGlobal pMac , tANI_U8 sessionId)
211{
212 if(sessionId >= pMac->lim.maxBssId)
213 {
214 limLog(pMac, LOGE, FL("Invalid sessionId: %d \n "), sessionId);
215 return(NULL);
216 }
217 if((pMac->lim.gpSession[sessionId].valid == TRUE))
218 {
219 return(&pMac->lim.gpSession[sessionId]);
220 }
221 limLog(pMac, LOG1, FL("Session %d not active\n "), sessionId);
222 return(NULL);
223
224}
225
226
227/*--------------------------------------------------------------------------
228 \brief peFindSessionByStaId() - looks up the PE session given staid.
229
230 This function returns the session context and the session ID if the session
231 corresponding to the given StaId is found in the PE session table.
232
233 \param pMac - pointer to global adapter context
234 \param staid - StaId of the session
235 \param sessionId -session ID is returned here, if session is found.
236
237 \return tpPESession - pointer to the session context or NULL if session is not found.
238
239 \sa
240 --------------------------------------------------------------------------*/
241tpPESession peFindSessionByStaId(tpAniSirGlobal pMac, tANI_U8 staid, tANI_U8* sessionId)
242{
243 tANI_U8 i, j;
244
245 for(i =0; i < pMac->lim.maxBssId; i++)
246 {
247 if(pMac->lim.gpSession[i].valid)
248 {
249 for(j = 0; j < pMac->lim.gpSession[i].dph.dphHashTable.size; j++)
250 {
251 if((pMac->lim.gpSession[i].dph.dphHashTable.pDphNodeArray[j].valid) &&
252 (pMac->lim.gpSession[i].dph.dphHashTable.pDphNodeArray[j].added) &&
253 (staid == pMac->lim.gpSession[i].dph.dphHashTable.pDphNodeArray[j].staIndex))
254 {
255 *sessionId = i;
256 return(&pMac->lim.gpSession[i]);
257 }
258 }
259 }
260 }
261
262 limLog(pMac, LOG4, FL("Session lookup fails for StaId: \n "));
263 return(NULL);
264}
265
266
267
268/*--------------------------------------------------------------------------
269 \brief peDeleteSession() - deletes the PE session given the session ID.
270
271
272 \param pMac - pointer to global adapter context
273 \param sessionId -session ID of the session which needs to be deleted.
274
275 \sa
276 --------------------------------------------------------------------------*/
277void peDeleteSession(tpAniSirGlobal pMac, tpPESession psessionEntry)
278{
279 tANI_U16 i = 0;
280
281 limLog(pMac, LOGW, FL("Trying to delete a session %d.\n "), psessionEntry->peSessionId);
282
283 if(psessionEntry->pLimStartBssReq != NULL)
284 {
285 palFreeMemory( pMac->hHdd, psessionEntry->pLimStartBssReq );
286 psessionEntry->pLimStartBssReq = NULL;
287 }
288
289 if(psessionEntry->pLimJoinReq != NULL)
290 {
291 palFreeMemory( pMac->hHdd, psessionEntry->pLimJoinReq );
292 psessionEntry->pLimJoinReq = NULL;
293 }
294
295 if(psessionEntry->pLimReAssocReq != NULL)
296 {
297 palFreeMemory( pMac->hHdd, psessionEntry->pLimReAssocReq );
298 psessionEntry->pLimReAssocReq = NULL;
299 }
300
301 if(psessionEntry->pLimMlmJoinReq != NULL)
302 {
303 palFreeMemory( pMac->hHdd, psessionEntry->pLimMlmJoinReq );
304 psessionEntry->pLimMlmJoinReq = NULL;
305 }
306
307 if(psessionEntry->dph.dphHashTable.pHashTable != NULL)
308 {
309 palFreeMemory(pMac->hHdd, psessionEntry->dph.dphHashTable.pHashTable);
310 psessionEntry->dph.dphHashTable.pHashTable = NULL;
311 }
312
313 if(psessionEntry->dph.dphHashTable.pDphNodeArray != NULL)
314 {
315 palFreeMemory(pMac->hHdd, psessionEntry->dph.dphHashTable.pDphNodeArray);
316 psessionEntry->dph.dphHashTable.pDphNodeArray = NULL;
317 }
318
319 if(psessionEntry->beacon != NULL)
320 {
321 palFreeMemory( pMac->hHdd, psessionEntry->beacon);
322 psessionEntry->beacon = NULL;
323 }
324
325 if(psessionEntry->assocReq != NULL)
326 {
327 palFreeMemory( pMac->hHdd, psessionEntry->assocReq);
328 psessionEntry->assocReq = NULL;
329 }
330
331 if(psessionEntry->assocRsp != NULL)
332 {
333 palFreeMemory( pMac->hHdd, psessionEntry->assocRsp);
334 psessionEntry->assocRsp = NULL;
335 }
336
337
338 if(psessionEntry->parsedAssocReq != NULL)
339 {
340 // Cleanup the individual allocation first
341 for (i=0; i < psessionEntry->dph.dphHashTable.size; i++)
342 {
343 if ( psessionEntry->parsedAssocReq[i] != NULL )
344 {
345 if( ((tpSirAssocReq)(psessionEntry->parsedAssocReq[i]))->assocReqFrame )
346 {
347 palFreeMemory(pMac->hHdd,
348 ((tpSirAssocReq)(psessionEntry->parsedAssocReq[i]))->assocReqFrame);
349 ((tpSirAssocReq)(psessionEntry->parsedAssocReq[i]))->assocReqFrame = NULL;
350 ((tpSirAssocReq)(psessionEntry->parsedAssocReq[i]))->assocReqFrameLength = 0;
351 }
352 palFreeMemory(pMac->hHdd, (void *)psessionEntry->parsedAssocReq[i]);
353 psessionEntry->parsedAssocReq[i] = NULL;
354 }
355 }
356 // Cleanup the whole block
357 palFreeMemory(pMac->hHdd, (void *)psessionEntry->parsedAssocReq);
358 psessionEntry->parsedAssocReq = NULL;
359 }
360
361#ifdef FEATURE_WLAN_CCX
362 limCleanupCcxCtxt(pMac, psessionEntry);
363#endif
364
365 psessionEntry->valid = FALSE;
366 return;
367}
368
369
370/*--------------------------------------------------------------------------
371 \brief peFindSessionByPeerSta() - looks up the PE session given the Station Address.
372
373 This function returns the session context and the session ID if the session
374 corresponding to the given station address is found in the PE session table.
375
376 \param pMac - pointer to global adapter context
377 \param sa - Peer STA Address of the session
378 \param sessionId -session ID is returned here, if session is found.
379
380 \return tpPESession - pointer to the session context or NULL if session is not found.
381
382 \sa
383 --------------------------------------------------------------------------*/
384
385
386tpPESession peFindSessionByPeerSta(tpAniSirGlobal pMac, tANI_U8* sa, tANI_U8* sessionId)
387{
388 tANI_U8 i;
389 tpDphHashNode pSta;
390 tANI_U16 aid;
391
392 for(i =0; i < pMac->lim.maxBssId; i++)
393 {
394 if( (pMac->lim.gpSession[i].valid))
395 {
396 pSta = dphLookupHashEntry(pMac, sa, &aid, &pMac->lim.gpSession[i].dph.dphHashTable);
397 if (pSta != NULL)
398 {
399 *sessionId = i;
400 return &pMac->lim.gpSession[i];
401 }
402 }
403 }
404
405 return NULL;
406}
407
408
409
410
411
412
413
414
415