• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * trafficAdmControl.c
3  *
4  * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *  * Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *  * Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *  * Neither the name Texas Instruments nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 /***************************************************************************/
36 /*																		   */
37 /*	  MODULE:	admCtrlQos.c											   */
38 /*    PURPOSE:	WSM/WME admission Control							       */
39 /*																	 	   */
40 /***************************************************************************/
41 
42 #define __FILE_ID__  FILE_ID_89
43 #include "osApi.h"
44 
45 #include "paramOut.h"
46 
47 #include "timer.h"
48 #include "fsm.h"
49 #include "report.h"
50 
51 #include "DataCtrl_Api.h"
52 
53 #include "trafficAdmControl.h"
54 #include "qosMngr_API.h"
55 #include "TWDriver.h"
56 #ifdef XCC_MODULE_INCLUDED
57 #include "XCCMngr.h"
58 #endif
59 /* Constants */
60 
61 /** number of states in the state machine */
62 #define	TRAFFIC_ADM_CTRL_SM_NUM_STATES		2
63 
64 /** number of events in the state machine */
65 #define	TRAFFIC_ADM_CTRL_SM_NUM_EVENTS			5
66 
67 extern int WMEQosTagToACTable[MAX_NUM_OF_802_1d_TAGS];
68 
69 typedef struct
70 {
71 	TI_HANDLE hTrafficAdmCtrl;
72 	tspecInfo_t *pTSpecInfo;
73 	TI_UINT8		acID;
74 
75 }fsmTSpecInfo_t;
76 
77 
78 /* Timer functions */
79 void trafficAdmCtrl_timeoutAcBE(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured);
80 void trafficAdmCtrl_timeoutAcBK(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured);
81 void trafficAdmCtrl_timeoutAcVI(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured);
82 void trafficAdmCtrl_timeoutAcVO(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured);
83 
84 
85 /* SM Functions */
86 TI_STATUS trafficAdmCtrl_smEvent(trafficAdmCtrl_t *pAdmCtrlQos, TI_UINT8 event, void *pData);
87 
88 TI_STATUS trafficAdmCtrl_smActionUnexpectedTspecResponse(fsmTSpecInfo_t *fsmTSpecInfo);	/*unxcepted*/
89 TI_STATUS trafficAdmCtrl_smActionUnexpected(fsmTSpecInfo_t *fsmTSpecInfo);	/*unxcepted*/
90 TI_STATUS trafficAdmCtrl_smActionNop(fsmTSpecInfo_t *fsmTSpecInfo);			/*NOP*/
91 TI_STATUS trafficAdmCtrl_smStart(fsmTSpecInfo_t *fsmTSpecInfo);				/*EVENT_START*/
92 TI_STATUS trafficAdmCtrl_smWaitStop(fsmTSpecInfo_t *fsmTSpecInfo);			/*EVENT_STOP*/
93 TI_STATUS trafficAdmCtrl_smWaitAccept(fsmTSpecInfo_t *fsmTSpecInfo);		/*EVENT_ACCEPT*/
94 TI_STATUS trafficAdmCtrl_smWaitReject(fsmTSpecInfo_t *fsmTSpecInfo);		/*EVENT_REJECT*/
95 TI_STATUS trafficAdmCtrl_smWaitTimeout(fsmTSpecInfo_t *fsmTSpecInfo);		/*EVENT_TIMEOUT*/
96 
97 
98 
99 TI_STATUS trafficAdmCtrl_sendAdmissionReq(TI_HANDLE hTrafficAdmCtrl, tspecInfo_t *pTSpecInfo);
100 TI_STATUS trafficAdmCtrl_startTimer(trafficAdmCtrl_t* pTrafficAdmCtrl, TI_UINT8 acID);
101 TI_STATUS trafficAdmCtrl_stopTimer(trafficAdmCtrl_t* pTrafficAdmCtrl, TI_UINT8 acID);
102 
103 
104 TI_STATUS trafficAdmCtrl_buildFrameHeader(trafficAdmCtrl_t *pTrafficAdmCtrl, TTxCtrlBlk *pPktCtrlBlk);
105 
106 static TI_STATUS trafficAdmCtrl_tokenToAc (TI_HANDLE hTrafficAdmCtrl, TI_UINT8 token, TI_UINT8 *acID);
107 
108 /********************************************************************************
109  *							trafficAdmCtrl_create								*
110  ********************************************************************************
111 DESCRIPTION: trafficAdmCtrl module creation function
112 
113   INPUT:      hOs -			Handle to OS
114 
115 
116 OUTPUT:
117 
118 RETURN:     Handle to the trafficAdmCtrl module on success, NULL otherwise
119 
120 ************************************************************************/
121 
trafficAdmCtrl_create(TI_HANDLE hOs)122 TI_HANDLE trafficAdmCtrl_create(TI_HANDLE hOs)
123 {
124 	trafficAdmCtrl_t 		*pTrafficAdmCtrl;
125 	TI_STATUS			status;
126 
127 	/* allocate admission control context memory */
128 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)os_memoryAlloc(hOs, sizeof(trafficAdmCtrl_t));
129 	if (pTrafficAdmCtrl == NULL)
130 	{
131 		return NULL;
132 	}
133 
134 	os_memoryZero(hOs, pTrafficAdmCtrl, sizeof(trafficAdmCtrl_t));
135 
136 	pTrafficAdmCtrl->hOs = hOs;
137 
138 	/* allocate memory for admCtrlQos state machine */
139 	status = fsm_Create(hOs, &pTrafficAdmCtrl->pTrafficAdmCtrlSm, TRAFFIC_ADM_CTRL_SM_NUM_STATES, TRAFFIC_ADM_CTRL_SM_NUM_EVENTS);
140 	if (status != TI_OK)
141 	{
142 		os_memoryFree(hOs, pTrafficAdmCtrl, sizeof(trafficAdmCtrl_t));
143 		return NULL;
144 	}
145 
146 	return pTrafficAdmCtrl;
147 }
148 /************************************************************************
149  *                        trafficAdmCtrl_unload						    *
150  ************************************************************************
151 DESCRIPTION: trafficAdmCtrl module destroy function,
152 				-	Free all memory alocated by the module
153 
154 INPUT:      hTrafficAdmCtrl	-	trafficAdmCtrl handle.
155 
156 OUTPUT:
157 
158 RETURN:     TI_OK on success, TI_NOK otherwise
159 
160 ************************************************************************/
trafficAdmCtrl_unload(TI_HANDLE hTrafficAdmCtrl)161 TI_STATUS trafficAdmCtrl_unload(TI_HANDLE hTrafficAdmCtrl)
162 {
163 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
164 	TI_UINT32         uAcId;
165 
166     if (pTrafficAdmCtrl->pTrafficAdmCtrlSm)
167 	{
168         fsm_Unload (pTrafficAdmCtrl->hOs, pTrafficAdmCtrl->pTrafficAdmCtrlSm);
169 	}
170 
171 	/* free timers */
172 	for (uAcId = 0; uAcId < MAX_NUM_OF_AC; uAcId++)
173     {
174         if (pTrafficAdmCtrl->hAdmCtrlTimer[uAcId])
175         {
176             tmr_DestroyTimer (pTrafficAdmCtrl->hAdmCtrlTimer[uAcId]);
177         }
178     }
179 
180 	os_memoryFree(pTrafficAdmCtrl->hOs, pTrafficAdmCtrl, sizeof(trafficAdmCtrl_t));
181 
182 	return TI_OK;
183 }
184 
185 /************************************************************************
186  *                        trafficAdmCtrl_config							*
187  ************************************************************************
188 DESCRIPTION: trafficAdmCtrl module configuration function,
189 				performs the following:
190 				-	Reset & initiailzes local variables
191 				-	Init the handles to be used by the module
192 
193 INPUT:      hTrafficAdmCtrl	         -	trafficAdmCtrl handle.
194 		    List of handles to be used by the module
195 			pTrafficAdmCtrlInitParams	-	init parameters.
196 
197 OUTPUT:
198 
199 RETURN:     TI_OK on success, TI_NOK otherwise
200 ************************************************************************/
trafficAdmCtrl_config(TI_HANDLE hTrafficAdmCtrl,TI_HANDLE hTxMgmtQ,TI_HANDLE hReport,TI_HANDLE hOs,TI_HANDLE hQosMngr,TI_HANDLE hCtrlData,TI_HANDLE hXCCMgr,TI_HANDLE hTimer,TI_HANDLE hTWD,TI_HANDLE hTxCtrl,trafficAdmCtrlInitParams_t * pTrafficAdmCtrlInitParams)201 TI_STATUS trafficAdmCtrl_config (TI_HANDLE hTrafficAdmCtrl,
202     						     TI_HANDLE hTxMgmtQ,
203     						     TI_HANDLE hReport,
204     						     TI_HANDLE hOs,
205     						     TI_HANDLE hQosMngr,
206     						     TI_HANDLE hCtrlData,
207     						     TI_HANDLE hXCCMgr,
208     						     TI_HANDLE hTimer,
209     						     TI_HANDLE hTWD,
210                                  TI_HANDLE hTxCtrl,
211     						     trafficAdmCtrlInitParams_t *pTrafficAdmCtrlInitParams)
212 {
213 	trafficAdmCtrl_t	*pTrafficAdmCtrl;
214 	TI_STATUS			status;
215 	TI_UINT32      		uAcId;
216 
217 	fsm_actionCell_t	trafficAdmCtrl_smMatrix[TRAFFIC_ADM_CTRL_SM_NUM_STATES][TRAFFIC_ADM_CTRL_SM_NUM_EVENTS] =
218 	{
219 		/* next state and actions for IDLE state */
220 		{{TRAFFIC_ADM_CTRL_SM_STATE_WAIT, (fsm_Action_t)trafficAdmCtrl_smStart},			/*EVENT_START*/
221 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smActionNop},		/*EVENT_STOP*/
222 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smActionUnexpectedTspecResponse}, /*EVENT_ACCEPT*/
223 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smActionUnexpectedTspecResponse}, /*EVENT_REJECT*/
224 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smActionUnexpected}, /*EVENT_TIMEOUT*/
225 		},
226 		/* next state and actions for WAIT state */
227 		{{TRAFFIC_ADM_CTRL_SM_STATE_WAIT, (fsm_Action_t)trafficAdmCtrl_smActionUnexpected},	/*EVENT_START*/
228 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smWaitStop},			/*EVENT_STOP*/
229 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smWaitAccept},		/*EVENT_ACCEPT*/
230 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smWaitReject},		/*EVENT_REJECT*/
231 		 {TRAFFIC_ADM_CTRL_SM_STATE_IDLE, (fsm_Action_t)trafficAdmCtrl_smWaitTimeout},		/*EVENT_TIMEOUT*/
232 		},
233 	};
234 
235 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
236 
237 	pTrafficAdmCtrl->hTxMgmtQ = hTxMgmtQ;
238 	pTrafficAdmCtrl->hReport	= hReport;
239 	pTrafficAdmCtrl->hOs		= hOs;
240 	pTrafficAdmCtrl->hQosMngr	= hQosMngr;
241 	pTrafficAdmCtrl->hCtrlData	= hCtrlData;
242 	pTrafficAdmCtrl->hXCCMgr	= hXCCMgr;
243 	pTrafficAdmCtrl->hTimer	    = hTimer;
244 	pTrafficAdmCtrl->hTWD	    = hTWD;
245 	pTrafficAdmCtrl->hTxCtrl	= hTxCtrl;
246 
247 	for (uAcId = 0; uAcId < MAX_NUM_OF_AC; uAcId++)
248     {
249 		pTrafficAdmCtrl->dialogToken[uAcId] = 0;
250 
251         /* Create per AC timers */
252         pTrafficAdmCtrl->hAdmCtrlTimer[uAcId] = tmr_CreateTimer (pTrafficAdmCtrl->hTimer);
253         if (pTrafficAdmCtrl->hAdmCtrlTimer[uAcId] == NULL)
254         {
255             TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR, "trafficAdmCtrl_config(): Failed to create hAssocSmTimer!\n");
256             return TI_NOK;
257         }
258     }
259 
260     /* configure state machine */
261 	status = fsm_Config(pTrafficAdmCtrl->pTrafficAdmCtrlSm, &trafficAdmCtrl_smMatrix[0][0],
262 						TRAFFIC_ADM_CTRL_SM_NUM_STATES, TRAFFIC_ADM_CTRL_SM_NUM_EVENTS, NULL, hOs);
263 	if (status != TI_OK)
264 	{
265 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR, "TRAFFIC_ADM_CTRL_SM: fsm_Config - Error  \n");
266 
267 		return TI_NOK;
268 	}
269 
270 	pTrafficAdmCtrl->timeout =  pTrafficAdmCtrlInitParams->trafficAdmCtrlResponseTimeout;
271     pTrafficAdmCtrl->useFixedMsduSize = pTrafficAdmCtrlInitParams->trafficAdmCtrlUseFixedMsduSize;
272 
273 	pTrafficAdmCtrl->dialogTokenCounter = INITIAL_DIALOG_TOKEN;
274 
275 
276 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "TRAFFIC ADM CTRL -  configuration completed ..... \n");
277 
278 	return TI_OK;
279 }
280 
281 
282 /************************************************************************
283  *                        trafficAdmCtrl_smEvent						*
284  ************************************************************************
285 DESCRIPTION: trafficAdmCtrl SM general function
286 
287 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
288 			event				-	the event to the SM.
289 			pData				-	handle to passing parameter
290 OUTPUT:
291 
292 RETURN:     TI_OK on success, TI_NOK otherwise
293 ************************************************************************/
294 
trafficAdmCtrl_smEvent(trafficAdmCtrl_t * pTrafficAdmCtrl,TI_UINT8 event,void * pData)295 TI_STATUS trafficAdmCtrl_smEvent(trafficAdmCtrl_t *pTrafficAdmCtrl, TI_UINT8 event, void *pData)
296 {
297 	TI_STATUS 		status;
298 	TI_UINT8			nextState;
299 	fsmTSpecInfo_t	*fsmTSpecInfo = (fsmTSpecInfo_t*)pData;
300 	TI_UINT8			acID = fsmTSpecInfo->acID;
301 
302 	status = fsm_GetNextState(pTrafficAdmCtrl->pTrafficAdmCtrlSm, pTrafficAdmCtrl->currentState[acID], event, &nextState);
303 	if (status != TI_OK)
304 	{
305 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR, "ADM_CTRL: ERROR - failed getting next state \n");
306 
307 		return(TI_NOK);
308 	}
309 
310 	TRACE3(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "trafficAdmCtrl_smEvent: <currentState = %d, event = %d> --> nextState = %d\n", pTrafficAdmCtrl->currentState[acID], event, nextState);
311 
312 	status = fsm_Event(pTrafficAdmCtrl->pTrafficAdmCtrlSm, &pTrafficAdmCtrl->currentState[acID], event, pData);
313 
314 	return(status);
315 }
316 
317 
318 /************************************************************************
319 *							state machine functions						*
320 ************************************************************************/
321 /************************************************************************
322  *                        trafficAdmCtrl_smStart						*
323  ************************************************************************
324 DESCRIPTION: the action function when event start ocuured on idle state
325 				performs the following:
326 				-	send admision requestReset
327 				-	start timer for the response.
328 
329 INPUT:      fsmTSpecInfo - parameters for the request
330 
331 OUTPUT:
332 
333 RETURN:     TI_OK on success, TI_NOK otherwise
334 ************************************************************************/
335 
trafficAdmCtrl_smStart(fsmTSpecInfo_t * fsmTSpecInfo)336 TI_STATUS trafficAdmCtrl_smStart(fsmTSpecInfo_t *fsmTSpecInfo)
337 {
338 	TI_STATUS				status;
339 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
340 	tspecInfo_t				*pTSpecInfo;
341 
342 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
343 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
344 
345 	/* send adm request frame */
346 	status = trafficAdmCtrl_sendAdmissionReq(pTrafficAdmCtrl, pTSpecInfo);
347 	if(status != TI_OK)
348 		return status;
349 
350 	/* init timer */
351 	trafficAdmCtrl_startTimer(pTrafficAdmCtrl, pTSpecInfo->AC);
352 
353 	return TI_OK;
354 }
355 /************************************************************************
356  *                        trafficAdmCtrl_smWaitStop						*
357  ************************************************************************
358 DESCRIPTION: the action function when event stop ocuured on wait state
359 				performs the following:
360 				-	stop timer.
361 
362 INPUT:      fsmTSpecInfo - parameters of the request
363 
364 OUTPUT:
365 
366 RETURN:     TI_OK on success, TI_NOK otherwise
367 ************************************************************************/
368 
trafficAdmCtrl_smWaitStop(fsmTSpecInfo_t * fsmTSpecInfo)369 TI_STATUS trafficAdmCtrl_smWaitStop(fsmTSpecInfo_t *fsmTSpecInfo)
370 {
371 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
372 	tspecInfo_t				*pTSpecInfo;
373 
374 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
375 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
376 
377 	/* stop timer */
378 	trafficAdmCtrl_stopTimer(pTrafficAdmCtrl,fsmTSpecInfo->pTSpecInfo->AC);
379 
380 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "TRAFFIC ADM CTRL -  AC = %d,    Stoped ..... \n", pTSpecInfo->AC);
381 
382 
383 	return TI_OK;
384 }
385 /************************************************************************
386  *                        trafficAdmCtrl_smWaitAccept					*
387  ************************************************************************
388 DESCRIPTION: the action function when event accept ocuured on wait state
389 				performs the following:
390 				-	update the Qos Mngr of the status and the parameters
391 
392 INPUT:      fsmTSpecInfo - parameters of the response
393 
394 OUTPUT:
395 
396 RETURN:     TI_OK on success, TI_NOK otherwise
397 ************************************************************************/
398 
trafficAdmCtrl_smWaitAccept(fsmTSpecInfo_t * fsmTSpecInfo)399 TI_STATUS trafficAdmCtrl_smWaitAccept(fsmTSpecInfo_t *fsmTSpecInfo)
400 {
401 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
402 	tspecInfo_t				*pTSpecInfo;
403 
404 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
405 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
406 
407 	/* update the QosMngr */
408 	qosMngr_setAdmissionInfo(pTrafficAdmCtrl->hQosMngr, pTSpecInfo->AC, pTSpecInfo, STATUS_TRAFFIC_ADM_REQUEST_ACCEPT);
409 
410 	return TI_OK;
411 }
412 /************************************************************************
413  *                        trafficAdmCtrl_smWaitReject					*
414  ************************************************************************
415 DESCRIPTION: the action function when event reject ocuured on wait state
416 				performs the following:
417 				-	update the Qos Mngr of the status and the parameters
418 
419 INPUT:      fsmTSpecInfo - parameters of the response
420 
421 OUTPUT:
422 
423 RETURN:     TI_OK on success, TI_NOK otherwise
424 ************************************************************************/
trafficAdmCtrl_smWaitReject(fsmTSpecInfo_t * fsmTSpecInfo)425 TI_STATUS trafficAdmCtrl_smWaitReject(fsmTSpecInfo_t *fsmTSpecInfo)
426 {
427 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
428 	tspecInfo_t				*pTSpecInfo;
429 
430 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
431 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
432 
433 	/* update the QosMngr */
434 	qosMngr_setAdmissionInfo(pTrafficAdmCtrl->hQosMngr, pTSpecInfo->AC, pTSpecInfo,	STATUS_TRAFFIC_ADM_REQUEST_REJECT);
435 
436 	return TI_OK;
437 }
438 /************************************************************************
439  *                        trafficAdmCtrl_smWaitTimeout					*
440  ************************************************************************
441 DESCRIPTION: the action function when event timeout ocuured on wait state
442 				performs the following:
443 				-	update the Qos Mngr of the status and the parameters
444 
445 INPUT:      fsmTSpecInfo - parameters of the request
446 
447 OUTPUT:
448 
449 RETURN:     TI_OK on success, TI_NOK otherwise
450 ************************************************************************/
451 
trafficAdmCtrl_smWaitTimeout(fsmTSpecInfo_t * fsmTSpecInfo)452 TI_STATUS trafficAdmCtrl_smWaitTimeout(fsmTSpecInfo_t *fsmTSpecInfo)
453 {
454 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
455 
456 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
457 
458 	/* update the QosMngr */
459 	qosMngr_setAdmissionInfo(pTrafficAdmCtrl->hQosMngr, fsmTSpecInfo->acID, NULL, STATUS_TRAFFIC_ADM_REQUEST_TIMEOUT);
460 
461 	return TI_OK;
462 }
463 /************************************************************************
464  *               trafficAdmCtrl_smActionUnexpected						*
465  ************************************************************************
466 DESCRIPTION:
467 INPUT:      fsmTSpecInfo - tspec parameters
468 
469 OUTPUT:
470 
471 RETURN:     TI_OK on success, TI_NOK otherwise
472 ************************************************************************/
473 
trafficAdmCtrl_smActionUnexpected(fsmTSpecInfo_t * fsmTSpecInfo)474 TI_STATUS trafficAdmCtrl_smActionUnexpected(fsmTSpecInfo_t *fsmTSpecInfo)
475 {
476 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
477 
478 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
479 
480 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR, "TRAFFIC ADM CTRL -  AC = %d,    ActionUnexpected ..... \n", fsmTSpecInfo->acID);
481 
482 	return TI_OK;
483 }
484 
485 /************************************************************************
486  *               trafficAdmCtrl_smActionUnexpectedTspecResponse			*
487  ************************************************************************
488 DESCRIPTION:
489 INPUT:      fsmTSpecInfo - tspec parameters
490 OUTPUT:
491 RETURN:     TI_OK on success, TI_NOK otherwise
492 ************************************************************************/
493 
trafficAdmCtrl_smActionUnexpectedTspecResponse(fsmTSpecInfo_t * fsmTSpecInfo)494 TI_STATUS trafficAdmCtrl_smActionUnexpectedTspecResponse(fsmTSpecInfo_t *fsmTSpecInfo)
495 {
496 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
497 	tspecInfo_t				*pTSpecInfo;
498 
499 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
500 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
501 
502 	/* Send event to user application - how come TSPEC response arrives without request ? */
503 	qosMngr_sendUnexpectedTSPECResponseEvent (pTrafficAdmCtrl->hQosMngr,pTSpecInfo);
504 
505 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_WARNING, "TRAFFIC ADM CTRL -  AC = %d,    ActionUnexpected ..... \n", fsmTSpecInfo->acID);
506 
507 	return TI_OK;
508 }
509 
510 
511 /************************************************************************
512  *                        trafficAdmCtrl_smActionNop					*
513  ************************************************************************
514 DESCRIPTION:
515 INPUT:      fsmTSpecInfo - tspec parameters
516 
517 OUTPUT:
518 
519 RETURN:     TI_OK on success, TI_NOK otherwise
520 ************************************************************************/
521 
trafficAdmCtrl_smActionNop(fsmTSpecInfo_t * fsmTSpecInfo)522 TI_STATUS trafficAdmCtrl_smActionNop(fsmTSpecInfo_t *fsmTSpecInfo)
523 {
524 	trafficAdmCtrl_t		*pTrafficAdmCtrl;
525 	tspecInfo_t				*pTSpecInfo;
526 
527 	pTrafficAdmCtrl = (trafficAdmCtrl_t*)(fsmTSpecInfo->hTrafficAdmCtrl);
528 	pTSpecInfo = fsmTSpecInfo->pTSpecInfo;
529 
530 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "TRAFFIC ADM CTRL -  AC = %d,    Action NOP..... \n", pTSpecInfo->AC);
531 
532 	return TI_OK;
533 }
534 /************************************************************************
535  *							API FUNCTIONS						        *
536  ************************************************************************
537  ************************************************************************/
538 
539 /************************************************************************
540  *                    trafficAdmCtrl_startAdmRequest                    *
541  ************************************************************************
542 DESCRIPTION: start TSPEC signaling
543 
544 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
545 			pTSpecInfo			-	the TSPEC parameters
546 
547 OUTPUT:
548 
549 RETURN:     TI_OK on success, TI_NOK otherwise
550 
551 ************************************************************************/
552 
trafficAdmCtrl_startAdmRequest(TI_HANDLE hTrafficAdmCtrl,tspecInfo_t * pTSpecInfo)553 TI_STATUS trafficAdmCtrl_startAdmRequest(TI_HANDLE	hTrafficAdmCtrl, tspecInfo_t *pTSpecInfo)
554 {
555 	TI_STATUS			status;
556 	fsmTSpecInfo_t		fsmTSpecInfo;
557 
558 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
559 
560 	if (pTrafficAdmCtrl == NULL)
561 		return TI_NOK;
562 
563 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
564 	fsmTSpecInfo.pTSpecInfo = pTSpecInfo;
565 	fsmTSpecInfo.acID = pTSpecInfo->AC;
566 
567 	/* send event START to SM */
568 	status = trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_START, &fsmTSpecInfo);
569 
570 	return status;
571 
572 }
573 /************************************************************************
574  *                    trafficAdmCtrl_stopAdmRequest                     *
575  ************************************************************************
576 DESCRIPTION: stop specific tspec signaling
577 
578 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
579 			acID				-	the AC of the tspec to stop
580 
581 OUTPUT:
582 
583 RETURN:     TI_OK on success, TI_NOK otherwise
584 
585 ************************************************************************/
586 
trafficAdmCtrl_stopAdmRequest(TI_HANDLE hTrafficAdmCtrl,TI_UINT8 acID)587 TI_STATUS trafficAdmCtrl_stopAdmRequest(TI_HANDLE hTrafficAdmCtrl, TI_UINT8 acID)
588 {
589 	TI_STATUS			status;
590 	trafficAdmCtrl_t	*pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
591 
592 	tspecInfo_t			pTSpecInfo;
593 	fsmTSpecInfo_t		fsmTSpecInfo;
594 
595 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
596 	fsmTSpecInfo.pTSpecInfo = &pTSpecInfo;
597 
598 	fsmTSpecInfo.pTSpecInfo->AC = (EAcTrfcType)acID;
599 	fsmTSpecInfo.acID = acID;
600 
601 	/* send event STOP to SM */
602 	status = trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_STOP, &fsmTSpecInfo);
603 
604 	return status;
605 
606 }
607 /************************************************************************
608  *                    trafficAdmCtrl_stop			                     *
609  ************************************************************************
610 DESCRIPTION: stop all tspecs and reset SM
611 			called on disconnect
612 
613 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
614 
615 OUTPUT:
616 
617 RETURN:     TI_OK on success, TI_NOK otherwise
618 
619 ************************************************************************/
trafficAdmCtrl_stop(TI_HANDLE hTrafficAdmCtrl)620 TI_STATUS trafficAdmCtrl_stop(TI_HANDLE	hTrafficAdmCtrl)
621 {
622 	TI_UINT32  uAcId;
623 
624 	trafficAdmCtrl_t	*pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
625 
626 	tspecInfo_t			pTSpecInfo;
627 	fsmTSpecInfo_t		fsmTSpecInfo;
628 
629 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
630 	fsmTSpecInfo.pTSpecInfo = &pTSpecInfo;
631 
632 	/* clean all AC SM  */
633 	for (uAcId = 0; uAcId < MAX_NUM_OF_AC; uAcId++)
634 	{
635 		fsmTSpecInfo.pTSpecInfo->AC = (EAcTrfcType)uAcId;
636 		fsmTSpecInfo.acID = uAcId;
637 		trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_STOP, &fsmTSpecInfo);
638 
639         pTrafficAdmCtrl->dialogToken[uAcId] = 0;
640 	}
641 
642 	pTrafficAdmCtrl->dialogTokenCounter = INITIAL_DIALOG_TOKEN;
643 
644 	return TI_OK;
645 }
646 
647 /************************************************************************
648  *                    trafficAdmCtrl_recv			                     *
649  ************************************************************************
650 DESCRIPTION:
651 
652 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
653 
654 OUTPUT:
655 
656 RETURN:     TI_OK on success, TI_NOK otherwise
657 
658 ************************************************************************/
659 
trafficAdmCtrl_recv(TI_HANDLE hTrafficAdmCtrl,TI_UINT8 * pData,TI_UINT8 action)660 TI_STATUS trafficAdmCtrl_recv(TI_HANDLE hTrafficAdmCtrl, TI_UINT8* pData, TI_UINT8 action)
661 {
662 	TI_STATUS 			status = TI_OK;
663 	TI_UINT8				statusCode;
664 	TI_UINT8				dialogToken;
665 	TI_UINT8				tacID;
666 	tspecInfo_t			tspecInfo;
667 	fsmTSpecInfo_t		fsmTSpecInfo;
668 
669 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
670 
671 	if (action == ADDTS_RESPONSE_ACTION)
672 	{
673 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "action = 1 - ADDTS RESPONSE ACTION........!! \n");
674 
675 		/* parsing the dialog token */
676 		dialogToken = *pData;
677 		pData++;
678 
679 		/* in WME status code is 1 byte, in WSM is 2 bytes */
680 		statusCode = *pData;
681 		pData++;
682 
683 		tspecInfo.statusCode = statusCode;
684 
685 TRACE2(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "dialogToken = %d ,  statusCode = %d \n",dialogToken, statusCode);
686 
687 		trafficAdmCtrl_parseTspecIE(&tspecInfo, pData);
688 
689 		if (trafficAdmCtrl_tokenToAc (pTrafficAdmCtrl, dialogToken, &tacID) == TI_NOK)
690 		{
691 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_WARNING, "dialog token Not found,  dialogToken = %d , \n",dialogToken);
692 
693 			qosMngr_sendUnexpectedTSPECResponseEvent(pTrafficAdmCtrl->hQosMngr, &tspecInfo);
694 
695 			return TI_NOK;
696 		}
697 
698 		/* validate dialog token matching */
699 		if(pTrafficAdmCtrl->dialogToken[tspecInfo.AC] != dialogToken)
700 		{
701 TRACE2(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_WARNING, "dialog token mismatch,  dialogToken = %d ,  acID = %d \n",dialogToken, tspecInfo.AC);
702 
703 			qosMngr_sendUnexpectedTSPECResponseEvent(pTrafficAdmCtrl->hQosMngr, &tspecInfo);
704 
705 			return TI_NOK;
706 		}
707 
708 		/* Stop the relevant Timer */
709 		trafficAdmCtrl_stopTimer(pTrafficAdmCtrl, tspecInfo.AC);
710 
711 		fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
712 		fsmTSpecInfo.pTSpecInfo = &tspecInfo;
713 
714 		fsmTSpecInfo.acID = tspecInfo.AC;
715 
716 		if(statusCode != ADDTS_STATUS_CODE_SUCCESS)
717 		{
718 			/* admission reject */
719 			/********************/
720 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "***** admCtrlQos_recv: admission reject [ statusCode = %d ]\n",statusCode);
721 
722 
723 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "ADDTS Response (reject) userPriority = %d , \n", tspecInfo.userPriority);
724 
725 			trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_REJECT, &fsmTSpecInfo);
726 
727 		}
728 		else
729 		{
730 			/* admission accept */
731 			/********************/
732 
733 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "***** admCtrlQos_recv: admission accept [ statusCode = %d ]\n",statusCode);
734 
735 
736 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "ADDTS Response (accepted) userPriority = %d ,  \n", tspecInfo.userPriority);
737 
738 TRACE2(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "mediumTime = %d ,  surplusBandwidthAllowance = %d \n", tspecInfo.mediumTime, tspecInfo.surplausBwAllowance);
739 
740 			trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_ACCEPT, &fsmTSpecInfo);
741 		}
742 	}
743 	else
744 	{
745 		status = TI_NOK;
746 TRACE1(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "trafficAdmCtrl_recv: unknown action code = %d ,  \n",action);
747 
748 	}
749 	return status;
750 }
751 
752 
753 /************************************************************************
754  *                    trafficAdmCtrl_sendDeltsFrame                     *
755  ************************************************************************
756 DESCRIPTION:
757 
758 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
759 
760 OUTPUT:
761 
762 RETURN:     TI_OK on success, TI_NOK otherwise
763 
764 ************************************************************************/
trafficAdmCtrl_sendDeltsFrame(TI_HANDLE hTrafficAdmCtrl,tspecInfo_t * pTSpecInfo,TI_UINT8 reasonCode)765 TI_STATUS trafficAdmCtrl_sendDeltsFrame(TI_HANDLE hTrafficAdmCtrl, tspecInfo_t *pTSpecInfo, TI_UINT8 reasonCode)
766 {
767 	TI_STATUS           status = TI_OK;
768     TTxCtrlBlk          *pPktCtrlBlk;
769     TI_UINT8            *pPktBuffer;
770 	TI_UINT32           totalLen = 0;
771 	tsInfo_t            tsInfo;
772 	trafficAdmCtrl_t    *pTrafficAdmCtrl = (trafficAdmCtrl_t *)hTrafficAdmCtrl;
773 
774 
775     TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "admCtrlQos_sendDeltsFrame: Enter....!! \n");
776 
777 	/* Allocate a TxCtrlBlk and data buffer (large enough for the max packet) */
778     pPktCtrlBlk = TWD_txCtrlBlk_Alloc (pTrafficAdmCtrl->hTWD);
779     pPktBuffer  = txCtrl_AllocPacketBuffer (pTrafficAdmCtrl->hTxCtrl, pPktCtrlBlk, 2000);
780     if (pPktBuffer == NULL)
781     {
782         TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR , ": No memory\n");
783         TWD_txCtrlBlk_Free (pTrafficAdmCtrl->hTWD, pPktCtrlBlk);
784         return TI_NOK;
785     }
786 
787 	status = trafficAdmCtrl_buildFrameHeader (pTrafficAdmCtrl, pPktCtrlBlk);
788 	if (status != TI_OK)
789 	{
790         TWD_txCtrlBlk_Free (pTrafficAdmCtrl->hTWD, pPktCtrlBlk);
791 		return TI_NOK;
792 	}
793 
794 	*(pPktBuffer + totalLen) = WME_CATAGORY_QOS;    /* CATEGORY_QOS in WME = 17*/
795 	totalLen++;
796 	*(pPktBuffer + totalLen) = DELTS_ACTION;        /* DELTS ACTION */
797 	totalLen++;
798 	*(pPktBuffer + totalLen) = 0;		/* DIALOG_TOKEN is 0 in DELTS */
799 	totalLen++;
800 	*(pPktBuffer + totalLen) = 0;		/* STATUS CODE is 0 in DELTS */
801 	totalLen++;
802 
803 	/*
804 	 * Build tsInfo fields
805 	 */
806 
807 	tsInfo.tsInfoArr[0] = 0;
808 	tsInfo.tsInfoArr[1] = 0;
809 	tsInfo.tsInfoArr[2] = 0;
810 
811     tsInfo.tsInfoArr[0] |= ( (pTSpecInfo->userPriority) << TSID_SHIFT);
812 
813 	tsInfo.tsInfoArr[0] |= (BI_DIRECTIONAL << DIRECTION_SHIFT);		/* bidirectional */
814 	tsInfo.tsInfoArr[0] |= (TS_INFO_0_ACCESS_POLICY_EDCA << ACCESS_POLICY_SHIFT);	/* EDCA */
815 
816 	tsInfo.tsInfoArr[1] |= (0 << AGGREGATION_SHIFT);
817 
818 	tsInfo.tsInfoArr[1] |= (pTSpecInfo->UPSDFlag << APSD_SHIFT);
819 
820 	tsInfo.tsInfoArr[1] |= (pTSpecInfo->userPriority << USER_PRIORITY_SHIFT);
821 	tsInfo.tsInfoArr[1] |= (NORMAL_ACKNOWLEDGEMENT << TSINFO_ACK_POLICY_SHIFT);
822 
823 	tsInfo.tsInfoArr[2] |= (NO_SCHEDULE << SCHEDULE_SHIFT);
824 
825 	/*
826 	 * Build TSpec IE for DELTS
827 	 */
828 
829     *(pPktBuffer + totalLen    ) = WME_TSPEC_IE_ID;
830 	*(pPktBuffer + totalLen + 1) = WME_TSPEC_IE_TSINFO_LEN;
831 
832 	*(pPktBuffer + totalLen + 2) = 0x00;
833 	*(pPktBuffer + totalLen + 3) = 0x50;
834 	*(pPktBuffer + totalLen + 4) = 0xf2;
835 	*(pPktBuffer + totalLen + 5) = WME_TSPEC_IE_OUI_TYPE;
836 	*(pPktBuffer + totalLen + 6) = WME_TSPEC_IE_OUI_SUB_TYPE;
837 	*(pPktBuffer + totalLen + 7) = WME_TSPEC_IE_VERSION;
838 
839 	*(pPktBuffer + totalLen + 8) = tsInfo.tsInfoArr[0];
840 	*(pPktBuffer + totalLen + 9) = tsInfo.tsInfoArr[1];
841 	*(pPktBuffer + totalLen +10) = tsInfo.tsInfoArr[2];
842 
843 	totalLen += WME_TSPEC_IE_TSINFO_LEN + 2;
844 
845     /* Update packet parameters (start-time, pkt-type and BDL) */
846     pPktCtrlBlk->tTxDescriptor.startTime = os_timeStampMs (pTrafficAdmCtrl->hOs);
847     pPktCtrlBlk->tTxPktParams.uPktType   = TX_PKT_TYPE_MGMT;
848     BUILD_TX_TWO_BUF_PKT_BDL (pPktCtrlBlk, pPktCtrlBlk->aPktHdr, WLAN_HDR_LEN, pPktBuffer, totalLen)
849 
850 	/* Enqueue packet in the mgmt-queues and run the scheduler. */
851 	status = txMgmtQ_Xmit (pTrafficAdmCtrl->hTxMgmtQ, pPktCtrlBlk, TI_FALSE);
852 
853 	return TI_OK;
854 }
855 
856 
857 /************************************************************************
858  *							INTERNAL FUNCTIONS					        *
859  ************************************************************************/
860 /************************************************************************
861  *                    trafficAdmCtrl_startTimer		                    *
862  ************************************************************************
863 DESCRIPTION: start a specific ac timer
864 
865 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
866 			acID				-	the AC of the timer
867 
868 OUTPUT:
869 
870 RETURN:     TI_OK on success, TI_NOK otherwise
871 
872 ************************************************************************/
873 
trafficAdmCtrl_startTimer(trafficAdmCtrl_t * pTrafficAdmCtrl,TI_UINT8 acID)874 TI_STATUS trafficAdmCtrl_startTimer(trafficAdmCtrl_t* pTrafficAdmCtrl, TI_UINT8 acID)
875 {
876     TTimerCbFunc fTimerExpiryFunc = NULL;
877 
878     if (pTrafficAdmCtrl == NULL)
879     {
880 		return TI_NOK;
881     }
882 
883     switch (acID)
884     {
885         case QOS_AC_BE:  fTimerExpiryFunc = trafficAdmCtrl_timeoutAcBE;   break;
886         case QOS_AC_BK:  fTimerExpiryFunc = trafficAdmCtrl_timeoutAcBK;   break;
887         case QOS_AC_VI:  fTimerExpiryFunc = trafficAdmCtrl_timeoutAcVI;   break;
888         case QOS_AC_VO:  fTimerExpiryFunc = trafficAdmCtrl_timeoutAcVO;   break;
889     }
890 
891     tmr_StartTimer (pTrafficAdmCtrl->hAdmCtrlTimer[acID],
892                     fTimerExpiryFunc,
893                     (TI_HANDLE)pTrafficAdmCtrl,
894                     pTrafficAdmCtrl->timeout,
895                     TI_FALSE);
896 
897 	return TI_OK;
898 }
899 /************************************************************************
900  *                    trafficAdmCtrl_stopTimer		                    *
901  ************************************************************************
902 DESCRIPTION: stop a specific ac timer
903 
904 INPUT:      pTrafficAdmCtrl	    -	trafficAdmCtr handle.
905 			acID				-	the AC of the timer
906 
907 OUTPUT:
908 
909 RETURN:     TI_OK on success, TI_NOK otherwise
910 
911 ************************************************************************/
912 
trafficAdmCtrl_stopTimer(trafficAdmCtrl_t * pTrafficAdmCtrl,TI_UINT8 acID)913 TI_STATUS trafficAdmCtrl_stopTimer(trafficAdmCtrl_t* pTrafficAdmCtrl, TI_UINT8 acID)
914 {
915 	if (pTrafficAdmCtrl == NULL)
916 		return TI_NOK;
917 
918 	tmr_StopTimer (pTrafficAdmCtrl->hAdmCtrlTimer[acID]);
919 
920 	return TI_OK;
921 }
922 
923 /************************************************************************
924  *						  AC timers functionc		                    *
925  ************************************************************************/
926 
927 /* QOS_AC_BE */
928 /*********/
trafficAdmCtrl_timeoutAcBE(TI_HANDLE hTrafficAdmCtrl,TI_BOOL bTwdInitOccured)929 void trafficAdmCtrl_timeoutAcBE (TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured)
930 {
931 	fsmTSpecInfo_t	fsmTSpecInfo;
932 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
933 
934 
935 	/* FSM Tspec Info Structure */
936 	fsmTSpecInfo.acID = QOS_AC_BE;
937 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
938 	fsmTSpecInfo.pTSpecInfo = NULL;
939 
940 	trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_TIMEOUT, &fsmTSpecInfo);
941 }
942 
943 /* QOS_AC_BK */
944 /*********/
trafficAdmCtrl_timeoutAcBK(TI_HANDLE hTrafficAdmCtrl,TI_BOOL bTwdInitOccured)945 void trafficAdmCtrl_timeoutAcBK(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured)
946 {
947 	fsmTSpecInfo_t	fsmTSpecInfo;
948 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
949 
950 
951 	/* FSM Tspec Info Structure */
952 	fsmTSpecInfo.acID = QOS_AC_BK;
953 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
954 	fsmTSpecInfo.pTSpecInfo = NULL;
955 
956 	trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_TIMEOUT, &fsmTSpecInfo);
957 
958 }
959 /* QOS_AC_VI */
960 /*********/
trafficAdmCtrl_timeoutAcVI(TI_HANDLE hTrafficAdmCtrl,TI_BOOL bTwdInitOccured)961 void trafficAdmCtrl_timeoutAcVI(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured)
962 {
963 	fsmTSpecInfo_t	fsmTSpecInfo;
964 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
965 
966 
967 	/* FSM Tspec Info Structure */
968 	fsmTSpecInfo.acID = QOS_AC_VI;
969 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
970 	fsmTSpecInfo.pTSpecInfo = NULL;
971 
972 	trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_TIMEOUT, &fsmTSpecInfo);
973 
974 }
975 /* QOS_AC_VO */
976 /*********/
trafficAdmCtrl_timeoutAcVO(TI_HANDLE hTrafficAdmCtrl,TI_BOOL bTwdInitOccured)977 void trafficAdmCtrl_timeoutAcVO(TI_HANDLE hTrafficAdmCtrl, TI_BOOL bTwdInitOccured)
978 {
979 	fsmTSpecInfo_t	fsmTSpecInfo;
980 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
981 
982 
983 	/* FSM Tspec Info Structure */
984 	fsmTSpecInfo.acID = QOS_AC_VO;
985 	fsmTSpecInfo.hTrafficAdmCtrl = hTrafficAdmCtrl;
986 	fsmTSpecInfo.pTSpecInfo = NULL;
987 
988 	trafficAdmCtrl_smEvent(pTrafficAdmCtrl, TRAFFIC_ADM_CTRL_SM_EVENT_TIMEOUT, &fsmTSpecInfo);
989 
990 }
991 
992 
trafficAdmCtrl_tokenToAc(TI_HANDLE hTrafficAdmCtrl,TI_UINT8 token,TI_UINT8 * acID)993 static TI_STATUS trafficAdmCtrl_tokenToAc (TI_HANDLE hTrafficAdmCtrl, TI_UINT8 token, TI_UINT8 *acID)
994 {
995 	TI_UINT8 idx;
996 	trafficAdmCtrl_t *pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
997 
998 	for (idx=0; idx<MAX_NUM_OF_AC; idx++)
999 	{
1000 		if (pTrafficAdmCtrl->dialogToken[idx] == token)
1001 		{
1002 			*acID = idx;
1003 			return (TI_OK);
1004 		}
1005 	}
1006 
1007 	return (TI_NOK);
1008 
1009 }
1010 
1011 
1012 
1013 /************************************************************************
1014  *              trafficAdmCtrl_buildFrameHeader							*
1015  ************************************************************************
1016 DESCRIPTION: build frame header
1017 
1018 INPUT:
1019 
1020 OUTPUT:
1021 
1022 RETURN:     TI_OK on success, TI_NOK otherwise
1023 ************************************************************************/
trafficAdmCtrl_buildFrameHeader(trafficAdmCtrl_t * pTrafficAdmCtrl,TTxCtrlBlk * pPktCtrlBlk)1024 TI_STATUS trafficAdmCtrl_buildFrameHeader(trafficAdmCtrl_t *pTrafficAdmCtrl, TTxCtrlBlk *pPktCtrlBlk)
1025 {
1026    	TI_STATUS			status;
1027 	TMacAddr		    daBssid, saBssid;
1028 	dot11_mgmtHeader_t *pdot11Header;
1029 	ScanBssType_e		currBssType;
1030 	TMacAddr    		currBssId;
1031 
1032 	pdot11Header = (dot11_mgmtHeader_t *)(pPktCtrlBlk->aPktHdr);
1033 
1034     /* Get the Destination MAC address */
1035 	status = ctrlData_getParamBssid(pTrafficAdmCtrl->hCtrlData, CTRL_DATA_CURRENT_BSSID_PARAM, daBssid);
1036 	if (status != TI_OK)
1037 	{
1038 		return TI_NOK;
1039 	}
1040 
1041     /* Get the Source MAC address */
1042 	status = ctrlData_getParamBssid(pTrafficAdmCtrl->hCtrlData, CTRL_DATA_MAC_ADDRESS, saBssid);
1043 	if (status != TI_OK)
1044 	{
1045 		return TI_NOK;
1046 	}
1047 
1048 	/* receive BssId and Bss Type from control module */
1049 	ctrlData_getCurrBssTypeAndCurrBssId(pTrafficAdmCtrl->hCtrlData, &currBssId, &currBssType);
1050 	if (currBssType != BSS_INFRASTRUCTURE)
1051     {
1052  		/* report failure but don't stop... */
1053 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR, "trafficAdmCtrl_buildFrameHeader: Error !! currBssType = BSS_INFRASTRUCTURE \n");
1054 
1055 		return TI_NOK;
1056     }
1057 	/* infrastructure BSS */
1058 
1059 	/* copy BSSID */
1060 	MAC_COPY (pdot11Header->BSSID, currBssId);
1061 	/* copy source mac address */
1062 	MAC_COPY (pdot11Header->SA, saBssid);
1063 	/* copy destination mac address */
1064 	MAC_COPY (pdot11Header->DA, daBssid);
1065 
1066 	/* set frame ctrl to mgmt action frame an to DS */
1067 	pdot11Header->fc = ENDIAN_HANDLE_WORD(DOT11_FC_ACTION | DOT11_FC_TO_DS);
1068 
1069 	return TI_OK;
1070 }
1071 
1072 /************************************************************************
1073  *                  trafficAdmCtrl_sendAdmissionReq						*
1074  ************************************************************************
1075 DESCRIPTION: send admision request frame
1076 
1077 INPUT:      hTrafficAdmCtrl	         -	Qos Manager handle.
1078 		    pTSpecInfo				 -  tspec parameters
1079 
1080 OUTPUT:
1081 
1082 RETURN:     TI_OK on success, TI_NOK otherwise
1083 ************************************************************************/
1084 
trafficAdmCtrl_sendAdmissionReq(TI_HANDLE hTrafficAdmCtrl,tspecInfo_t * pTSpecInfo)1085 TI_STATUS trafficAdmCtrl_sendAdmissionReq(TI_HANDLE hTrafficAdmCtrl, tspecInfo_t *pTSpecInfo)
1086 {
1087 	TI_STATUS			status = TI_OK;
1088     TTxCtrlBlk          *pPktCtrlBlk;
1089     TI_UINT8            *pPktBuffer;
1090 	TI_UINT32			len;
1091 	TI_UINT32			totalLen = 0;
1092 	trafficAdmCtrl_t	*pTrafficAdmCtrl = (trafficAdmCtrl_t*)hTrafficAdmCtrl;
1093 
1094 
1095 TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_INFORMATION, "admCtrlQos_smAdmissionReq: Enter....!! \n");
1096 
1097 	/* Allocate a TxCtrlBlk and data buffer (large enough for the max packet) */
1098     pPktCtrlBlk = TWD_txCtrlBlk_Alloc (pTrafficAdmCtrl->hTWD);
1099     pPktBuffer  = txCtrl_AllocPacketBuffer (pTrafficAdmCtrl->hTxCtrl, pPktCtrlBlk, 2000);
1100     if (pPktBuffer == NULL)
1101     {
1102         TRACE0(pTrafficAdmCtrl->hReport, REPORT_SEVERITY_ERROR , ": No memory\n");
1103         TWD_txCtrlBlk_Free (pTrafficAdmCtrl->hTWD, pPktCtrlBlk);
1104         return TI_NOK;
1105     }
1106 
1107 	status = trafficAdmCtrl_buildFrameHeader (pTrafficAdmCtrl, pPktCtrlBlk);
1108 	if (status != TI_OK)
1109 	{
1110         TWD_txCtrlBlk_Free (pTrafficAdmCtrl->hTWD, pPktCtrlBlk);
1111 		return TI_NOK;
1112 	}
1113 
1114 	*(pPktBuffer + totalLen) = WME_CATAGORY_QOS;			/* CATEGORY_QOS WME = 17*/
1115 	totalLen++;
1116 	*(pPktBuffer + totalLen) = ADDTS_REQUEST_ACTION;		/* ADDTS request ACTION */
1117 	totalLen++;
1118 
1119 	/* storing the dialog token for response validation */
1120 	pTrafficAdmCtrl->dialogToken[pTSpecInfo->AC] = pTrafficAdmCtrl->dialogTokenCounter++;	/* DIALOG_TOKEN */
1121 	*(pPktBuffer + totalLen) = pTrafficAdmCtrl->dialogToken[pTSpecInfo->AC];
1122 	totalLen++;
1123 
1124 	*(pPktBuffer + totalLen) = 0;	 /* STATUS CODE is 0 for ADDTS */
1125 	totalLen++;
1126 
1127 	trafficAdmCtrl_buildTSPec (pTrafficAdmCtrl, pTSpecInfo, pPktBuffer + totalLen, (TI_UINT32*)&len);
1128 	totalLen += len;
1129 
1130     /* Update packet parameters (start-time, length, pkt-type) */
1131     pPktCtrlBlk->tTxDescriptor.startTime = os_timeStampMs (pTrafficAdmCtrl->hOs);
1132     pPktCtrlBlk->tTxPktParams.uPktType   = TX_PKT_TYPE_MGMT;
1133     BUILD_TX_TWO_BUF_PKT_BDL (pPktCtrlBlk, pPktCtrlBlk->aPktHdr, WLAN_HDR_LEN, pPktBuffer, totalLen)
1134 
1135 	/* Enqueue packet in the mgmt-queues and run the scheduler. */
1136 	status = txMgmtQ_Xmit (pTrafficAdmCtrl->hTxMgmtQ, pPktCtrlBlk, TI_FALSE);
1137 
1138 	return TI_OK;
1139 }
1140 /************************************************************************
1141  *                        trafficAdmCtrl_buildTSPec							*
1142  ************************************************************************
1143 DESCRIPTION: build a tspec according to the tspec parameters
1144 
1145 INPUT:      hTrafficAdmCtrl	     -	Qos Manager handle.
1146 		    pTSpecInfo			 -  tspec parameters
1147 
1148 OUTPUT:		pPktBuffer             - the Tspec IE to send
1149 			len					 - the tspec frame len
1150 
1151 RETURN:     TI_OK on success, TI_NOK otherwise
1152 ************************************************************************/
1153 
trafficAdmCtrl_buildTSPec(trafficAdmCtrl_t * pTrafficAdmCtrl,tspecInfo_t * pTSpecInfo,TI_UINT8 * pDataBuf,TI_UINT32 * len)1154 void trafficAdmCtrl_buildTSPec(trafficAdmCtrl_t	*pTrafficAdmCtrl,
1155 							   tspecInfo_t		*pTSpecInfo,
1156 							   TI_UINT8			*pDataBuf,
1157 							   TI_UINT32		*len)
1158 {
1159 	tsInfo_t			tsInfo;
1160 	TI_UINT16		nominalMSDUSize;
1161 	TI_UINT32		suspensionInterval = 0;   /* disable */
1162 
1163 
1164 	os_memoryZero(pTrafficAdmCtrl->hOs, (void *)pDataBuf, WME_TSPEC_IE_LEN + 2);
1165 
1166 	*pDataBuf =			WME_TSPEC_IE_ID;
1167 	*(pDataBuf + 1) =	WME_TSPEC_IE_LEN;
1168 
1169 	*(pDataBuf + 2) =	0x00;
1170 	*(pDataBuf + 3) =	0x50;
1171 	*(pDataBuf + 4) =	0xf2;
1172 	*(pDataBuf + 5) =	WME_TSPEC_IE_OUI_TYPE;
1173 	*(pDataBuf + 6) =	WME_TSPEC_IE_OUI_SUB_TYPE;
1174 	*(pDataBuf + 7) =	WME_TSPEC_IE_VERSION;
1175 
1176 	/*
1177 	 * Build tsInfo fields
1178 	 */
1179 
1180 	tsInfo.tsInfoArr[0] = 0;
1181 	tsInfo.tsInfoArr[1] = 0;
1182 	tsInfo.tsInfoArr[2] = 0;
1183 
1184 	tsInfo.tsInfoArr[0] |=		( (pTSpecInfo->userPriority) << TSID_SHIFT);
1185 	tsInfo.tsInfoArr[0] |=		(pTSpecInfo->streamDirection << DIRECTION_SHIFT);		/* bidirectional */
1186 
1187 	tsInfo.tsInfoArr[0] |=		(TS_INFO_0_ACCESS_POLICY_EDCA << ACCESS_POLICY_SHIFT);	/* EDCA */
1188 
1189 	tsInfo.tsInfoArr[1] |=		(0 << AGGREGATION_SHIFT);
1190 
1191 	tsInfo.tsInfoArr[1] |=		(pTSpecInfo->UPSDFlag << APSD_SHIFT);
1192 
1193 	tsInfo.tsInfoArr[1] |=		(pTSpecInfo->userPriority << USER_PRIORITY_SHIFT);
1194 	tsInfo.tsInfoArr[1] |=		(NORMAL_ACKNOWLEDGEMENT << TSINFO_ACK_POLICY_SHIFT);
1195 
1196 	tsInfo.tsInfoArr[2] |=		(NO_SCHEDULE << SCHEDULE_SHIFT);
1197 
1198 	*(pDataBuf + 8) =	tsInfo.tsInfoArr[0];
1199 	*(pDataBuf + 9) =	tsInfo.tsInfoArr[1];
1200 	*(pDataBuf +10) =	tsInfo.tsInfoArr[2];
1201 
1202 	pDataBuf += 11;  /* Progress the data pointer to the next IE parameters. */
1203 
1204 	/*
1205 	 * Set all remained parameters
1206 	 */
1207 
1208     nominalMSDUSize = pTSpecInfo->nominalMsduSize;
1209     if (pTrafficAdmCtrl->useFixedMsduSize)
1210 		nominalMSDUSize |= FIX_MSDU_SIZE;
1211 
1212 	COPY_WLAN_WORD(pDataBuf,      &nominalMSDUSize);			/* Nominal-MSDU-size. */
1213 	COPY_WLAN_WORD(pDataBuf +  2, &nominalMSDUSize);			/* Maximum-MSDU-size. */
1214 	COPY_WLAN_LONG(pDataBuf +  4, &pTSpecInfo->uMinimumServiceInterval); /* Minimum service interval */
1215 	COPY_WLAN_LONG(pDataBuf +  8, &pTSpecInfo->uMaximumServiceInterval); /* Maximum service interval */
1216 	COPY_WLAN_LONG(pDataBuf + 16, &suspensionInterval);
1217 	COPY_WLAN_LONG(pDataBuf + 24, &pTSpecInfo->meanDataRate);	/* Minimum-data-rate. */
1218 	COPY_WLAN_LONG(pDataBuf + 28, &pTSpecInfo->meanDataRate);	/* Mean-data-rate. */
1219 	COPY_WLAN_LONG(pDataBuf + 32, &pTSpecInfo->meanDataRate);	/* Peak-data-rate. */
1220 	COPY_WLAN_LONG(pDataBuf + 44, &pTSpecInfo->minimumPHYRate);
1221 	COPY_WLAN_WORD(pDataBuf + 48, &pTSpecInfo->surplausBwAllowance);
1222 
1223 	*len = WME_TSPEC_IE_LEN + 2;
1224 }
1225 
1226 
1227 
1228 /************************************************************************
1229  *                        trafficAdmCtrl_parseTspecIE					*
1230  ************************************************************************
1231 DESCRIPTION: parses a tspec IE according to the tspec parameters
1232 
1233 INPUT:      pData			-  tspec IE from received frame
1234 
1235 OUTPUT:		pTSpecInfo		-  parsed tspec parameters
1236 
1237 RETURN:     None
1238 ************************************************************************/
trafficAdmCtrl_parseTspecIE(tspecInfo_t * pTSpecInfo,TI_UINT8 * pData)1239 void trafficAdmCtrl_parseTspecIE(tspecInfo_t *pTSpecInfo, TI_UINT8 *pData)
1240 {
1241 	tsInfo_t			tsInfo;
1242 	TI_UINT8				userPriority;
1243 	TI_UINT8				acID;
1244 	TI_UINT8				tid;
1245 	TI_UINT8				direction;
1246 	TI_UINT8				APSDbit;
1247 
1248 	pData += 8;  /* Skip the WME_TSPEC_IE header */
1249 
1250 	/* Get the TS-Info (3 bytes) and parse its fields */
1251 	tsInfo.tsInfoArr[0] = *pData;
1252 	tsInfo.tsInfoArr[1] = *(pData + 1);
1253 	tsInfo.tsInfoArr[2] = *(pData + 2);
1254 	pData += 3;
1255 
1256 	userPriority = (((tsInfo.tsInfoArr[1]) & TS_INFO_1_USER_PRIORITY_MASK) >> USER_PRIORITY_SHIFT);
1257 
1258 	acID = WMEQosTagToACTable[userPriority];
1259 
1260 	tid = 	(((tsInfo.tsInfoArr[0]) & TS_INFO_0_TSID_MASK) >> TSID_SHIFT);
1261 	APSDbit = (((tsInfo.tsInfoArr[1]) & TS_INFO_1_APSD_MASK) >> APSD_SHIFT);
1262 	direction = (((tsInfo.tsInfoArr[0]) & TS_INFO_0_DIRECTION_MASK) >> DIRECTION_SHIFT);
1263 
1264 
1265 	pTSpecInfo->AC = (EAcTrfcType)acID;
1266 	pTSpecInfo->userPriority = userPriority;
1267 	pTSpecInfo->UPSDFlag = APSDbit;
1268 	pTSpecInfo->streamDirection = (EStreamDirection)direction;
1269 	pTSpecInfo->tid = tid;
1270 
1271 	/* Get the other Tspec IE parameters (handle WLAN fram endianess if required) */
1272 	COPY_WLAN_WORD(&pTSpecInfo->nominalMsduSize, pData);
1273 	COPY_WLAN_LONG(&pTSpecInfo->uMinimumServiceInterval, pData + 4);
1274 	COPY_WLAN_LONG(&pTSpecInfo->uMaximumServiceInterval, pData + 8);
1275 	COPY_WLAN_LONG(&pTSpecInfo->meanDataRate, pData + 28);
1276 	COPY_WLAN_LONG(&pTSpecInfo->minimumPHYRate, pData + 44);
1277 	COPY_WLAN_WORD(&pTSpecInfo->surplausBwAllowance, pData + 48);
1278 	pTSpecInfo->surplausBwAllowance >>= SURPLUS_BANDWIDTH_ALLOW;  /* Surplus is in 3 MSBits of TI_UINT16 */
1279 	COPY_WLAN_WORD(&pTSpecInfo->mediumTime, pData + 50);
1280 }
1281 
1282 
1283 
1284 /*************************************************************************
1285  *																		 *
1286  *							DEBUG FUNCTIONS								 *
1287  *																		 *
1288  *************************************************************************/
trafficAdmCtrl_print(trafficAdmCtrl_t * pTrafficAdmCtr)1289 void trafficAdmCtrl_print(trafficAdmCtrl_t *pTrafficAdmCtr)
1290 {
1291 	TI_UINT32 acID;
1292 
1293 	WLAN_OS_REPORT(("     traffic Adm Ctrl  \n"));
1294 	WLAN_OS_REPORT(("-----------------------------------\n\n"));
1295 	WLAN_OS_REPORT(("timeout                   = %d\n",pTrafficAdmCtr->timeout));
1296 	WLAN_OS_REPORT(("dialogTokenCounter        = %d\n",pTrafficAdmCtr->dialogTokenCounter));
1297 
1298 	for (acID = 0 ; acID < MAX_NUM_OF_AC ; acID++)
1299 	{
1300 			WLAN_OS_REPORT(("     AC = %d  \n",acID));
1301 			WLAN_OS_REPORT(("----------------------\n"));
1302 			WLAN_OS_REPORT(("currentState   = %d \n",pTrafficAdmCtr->currentState[acID]));
1303 			WLAN_OS_REPORT(("dialogToken    = %d \n",pTrafficAdmCtr->dialogToken[acID]));
1304 	}
1305 }
1306 
1307