summaryrefslogtreecommitdiff
path: root/wilink_6_1/stad/src/AirLink_Managment/requestHandler.c
blob: 7d652f98391e40ad4bb20f06745bb959ad48c80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/*
 * requestHandler.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file RequestHandler.c
 *  \brief RequestHandler module interface
 *
 *  \see RequestHandler.h
 */

/****************************************************************************************************/
/*																									*/
/*		MODULE:		RequestHandler.c																*/
/*		PURPOSE:	RequestHandler module interface.												*/
/*                  This module handle the incoming measurement requests. The object handle			*/
/*					data base that stores all measurement requests from the last incoming.			*/
/*					This module export interface function for sceduling the next requests to be		*/
/*					executed and stores all relevent fields for constructing a measurement report.	*/
/*																									*/
/****************************************************************************************************/
#define __FILE_ID__  FILE_ID_4
#include "report.h"
#include "osApi.h"
#include "paramOut.h"
#include "requestHandler.h"

#ifdef XCC_MODULE_INCLUDED
#include "XCCRMMngrParam.h"
#endif

/* allocation vector */
#define REQUEST_HANDLER_INIT_BIT		(1)

#define DOT11_MEASUREMENT_REQUEST_ELE_ID (38)

/********************************************************************************/
/*						Internal functions prototypes.							*/
/********************************************************************************/
static void release_module(requestHandler_t *pRequestHandler, TI_UINT32 initVec);

static TI_STATUS insertMeasurementIEToQueue(TI_HANDLE           hRequestHandler,
											TI_UINT16			frameToken,
											EMeasurementMode	measurementMode,
											TI_UINT8			*pData,
                                            TI_UINT8            *singelRequestLen);

/********************************************************************************/
/*						Interface functions Implementation.						*/
/********************************************************************************/


/********************************************************************************
 *                        requestHandler_create									*
 ********************************************************************************
DESCRIPTION: RequestHandler module creation function, called by the measurement in 
				creation phase. performs the following:

				-	Allocate the RequestHandler handle
				                                                                                                   
INPUT:      hOs -	Handle to OS		

OUTPUT:		

RETURN:     Handle to the RequestHandler module on success, NULL otherwise
************************************************************************/
TI_HANDLE requestHandler_create(TI_HANDLE hOs)
{
	requestHandler_t			*pRequestHandler = NULL;
	TI_UINT32			initVec = 0;
	
	
	/* allocating the RequestHandler object */
	pRequestHandler = os_memoryAlloc(hOs,sizeof(requestHandler_t));

	if (pRequestHandler == NULL)
		return NULL;

	initVec |= (1 << REQUEST_HANDLER_INIT_BIT);

	return(pRequestHandler);
}

/************************************************************************
 *                        requestHandler_config		    				*
 ************************************************************************
DESCRIPTION: RequestHandler module configuration function, called by the measurement
			  in configuration phase. performs the following:
				-	Reset & initiailzes local variables
				-	Init the handles to be used by the module
                                                                                                   
INPUT:      hRequestHandler	-	RequestHandler handle.
			List of handles to be used by the module
			
OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS RequestHandler_config(TI_HANDLE 	hRequestHandler,
						TI_HANDLE		hReport,
						TI_HANDLE		hOs)
{
	requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler;
	

	/* init variables */
    pRequestHandler->parserRequestIEHdr = NULL;
	pRequestHandler->numOfWaitingRequests = 0;	/*	indicating empty data base	*/
	pRequestHandler->activeRequestID = -1;		/*			   					*/
	pRequestHandler->hReport	= hReport;
	pRequestHandler->hOs		= hOs;

	/* Clearing the Request Array , mostly due to parallel bit */
	os_memoryZero(pRequestHandler->hOs, pRequestHandler->reqArr, MAX_NUM_REQ * sizeof(MeasurementRequest_t));

TRACE0(pRequestHandler->hReport, REPORT_SEVERITY_INIT, ": RequestHandler configured successfully\n");

	return TI_OK;
}

/***********************************************************************
 *                        requestHandler_setParam									
 ***********************************************************************
DESCRIPTION: RequestHandler set param function, called by the following:
			-	config mgr in order to set a parameter receiving from 
				the OS abstraction layer.
			-	From inside the dirver	
                                                                                                   
INPUT:      hRequestHandler	-	RequestHandler handle.
			pParam			-	Pointer to the parameter		

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS requestHandler_setParam(TI_HANDLE	hRequestHandler,
								  paramInfo_t	*pParam)
{
	requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler;
	
	switch(pParam->paramType)
	{
/*	case RequestHandler_PARAM_TYPE:*/
		
	/*	break;*/
		
	default:
TRACE1(pRequestHandler->hReport, REPORT_SEVERITY_ERROR, ": Set param, Params is not supported, %d\n\n", pParam->paramType);
		return PARAM_NOT_SUPPORTED;
	}

/*	return TI_OK; - unreachable */
}

/***********************************************************************
 *                        requestHandler_getParam									
 ***********************************************************************
DESCRIPTION: RequestHandler get param function, called by the following:
			-	config mgr in order to get a parameter from the OS a
				bstraction layer.
			-	From inside the dirver	
                                                                                                   
INPUT:      hRequestHandler	-	RequestHandler handle.
			pParam			-	Pointer to the parameter		

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS requestHandler_getParam(TI_HANDLE		hRequestHandler,
								  paramInfo_t	*pParam)
{
	requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler;
/*	TI_STATUS			status;*/
	
	switch(pParam->paramType)
	{
	/*case RequestHandler_PARAM:*/
		
		
		/*return status;*/
	
	default:
TRACE1(pRequestHandler->hReport, REPORT_SEVERITY_ERROR, ": Get param, Params is not supported, %d\n\n", pParam->paramType);
		return PARAM_NOT_SUPPORTED;
	}

/*	return TI_OK; - unreachable */
}

/************************************************************************
 *                        RequestHandler_destroy						*
 ************************************************************************
DESCRIPTION: RequestHandler module destroy function, called by the config 
			 mgr in the destroy phase 
			 performs the following:
			 -	Free all memory aloocated by the module
                                                                                                   
INPUT:      hRequestHandler	-	RequestHandler handle.		

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
TI_STATUS requestHandler_destroy(TI_HANDLE hRequestHandler)
{
	requestHandler_t * pRequestHandler = (requestHandler_t *)hRequestHandler;
	TI_UINT32 initVec;

	if (pRequestHandler == NULL)
		return TI_OK;

	initVec = 0xFFFF;
	release_module(pRequestHandler, initVec);

	return TI_OK;
}

/************************************************************************
 *                  requestHandler_insertRequests						*
 ************************************************************************
DESCRIPTION: RequestHandler module parsing function, called by the 
			  measurement object when measuremnt request frame is received.
				performs the following:
				-	Parsers the measurement request frame.
				-	Inserts all requests into the queue.
				-	Initializes each request according to the its frame 
					token, measurement token, measurement type, parallel,
					channel number, duration time and scan mode.
				-	The function updates the numOfWaitingRequests variable
					and set to zero the activeReqId.

			 Note:  The activeReqId contains the index for the first request
					that should be executed or to the current active request.

INPUT:      hRequestHandler	    -	RequestHandler handle.
			measurementMode     -	The MEasurement Object Mode.
			measurementFrameReq -   The New Frame request that was received.

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
TI_STATUS requestHandler_insertRequests(TI_HANDLE hRequestHandler,
										EMeasurementMode measurementMode,
										TMeasurementFrameRequest measurementFrameReq)
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;
    TI_INT32               requestsLen = measurementFrameReq.requestsLen;
    TI_UINT8               singelRequestLen = 0;
    TI_UINT8               *requests = measurementFrameReq.requests;
		    
	if (requestsLen < 2)
    {
        TRACE0(pRequestHandler->hReport, REPORT_SEVERITY_ERROR, ": Invalid length of the data.\n");

        return TI_NOK;
    }

	/* Inserting all measurement request into the queues */
	while (requestsLen > 0)
	{
		if(insertMeasurementIEToQueue(hRequestHandler, 
                                       measurementFrameReq.hdr->dialogToken, 
                                       measurementMode, 
                                       requests,
                                       &singelRequestLen) != TI_OK )
        {
            requestHandler_clearRequests(hRequestHandler);
			return TI_NOK;
        }
  
		requestsLen -= singelRequestLen;
		requests += singelRequestLen;
      
	}

	pRequestHandler->activeRequestID = 0;
	
TRACE2(pRequestHandler->hReport, REPORT_SEVERITY_INFORMATION, ": Inserted into queue: activeRequestID = %d, numOfWaitingRequests = %d\n",					pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests);

	return TI_OK;
}

/************************************************************************
 *                  requestHandler_getNextReq							*
 ************************************************************************
DESCRIPTION: RequestHandler module function for retrieving the requests that
				should be executed.
				performs the following:
				-	returns pointers to one request/several requests that
					should be performed in parallel.
				Note: The function updates the numOfWaitingRequests internal
				varaible ONLY IF the returned request/s are going to be 
				executed immediatly (isForActivation = TI_TRUE).

INPUT:      hRequestHandler	-	RequestHandler handle.
			
  			isForActivation -	A flag that indicates if the returned 
								request/s are going to be executed immediatly

OUTPUT:		pRequest		-	pointer contains the address in which the 
								next requests for activation should be inserted.
		
			numOfRequests	-	indicates how many requests should be activated
								in parallel.
			
RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
TI_STATUS requestHandler_getNextReq(TI_HANDLE hRequestHandler,
									TI_BOOL	  isForActivation,
									MeasurementRequest_t *pRequest[],
									TI_UINT8*	  numOfRequests)
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;
	TI_UINT8				requestIndex = pRequestHandler->activeRequestID;
	TI_UINT8				loopIndex = 0;
	
TRACE2(pRequestHandler->hReport, REPORT_SEVERITY_INFORMATION, ": Looking for requests. activeRequestID = %d, numOfWaitingRequests = %d\n",					pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests);

	if(pRequestHandler->numOfWaitingRequests <= 0)
		return TI_NOK;

	do{
		pRequest[loopIndex] = &(pRequestHandler->reqArr[requestIndex]);
		requestIndex++;
		loopIndex++;
	}
	while ( (loopIndex < pRequestHandler->numOfWaitingRequests) && 
            (pRequestHandler->reqArr[requestIndex].isParallel) );

	*numOfRequests = loopIndex;

TRACE1(pRequestHandler->hReport, REPORT_SEVERITY_INFORMATION, ": Found %d requests to execute in parallel.\n", loopIndex);

	if(isForActivation == TI_TRUE)
	{
		pRequestHandler->numOfWaitingRequests -= loopIndex;

TRACE1(pRequestHandler->hReport, REPORT_SEVERITY_INFORMATION, ": Requests were queried for activation so decreasing numOfWaitingRequests to %d\n", pRequestHandler->numOfWaitingRequests);
	}

	return TI_OK;
}

/************************************************************************
 *                  requestHandler_getCurrentExpiredReq					*
 ************************************************************************
DESCRIPTION: RequestHandler module function for retrieving the request that
				finished its execution.
				performs the following:
				-	returns pointers to the request that
					finished its execution in.

INPUT:      hRequestHandler	-	RequestHandler handle.
			requestIndex	-	Index of request in the queue
			
OUTPUT:		pRequest		-	pointer contains the addresse of the 
								request that finished its execution.

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
TI_STATUS requestHandler_getCurrentExpiredReq(TI_HANDLE hRequestHandler,
											  TI_UINT8 requestIndex,
											  MeasurementRequest_t **pRequest)
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;
	
	requestIndex += pRequestHandler->activeRequestID;

	*pRequest = &(pRequestHandler->reqArr[requestIndex]);

	return TI_OK;
}


/************************************************************************
 *                  requestHandler_clearRequests						*
 ************************************************************************
DESCRIPTION: RequestHandler module function for cleaning the data base.
				performs the following:
				-	Clears all requests from the queue by setting
					the activeReqId and numOfWaitingRequests variables.
			Note:	The function does not actually zero all queue 
					variables or destroy the object.

INPUT:      hRequestHandler	-	RequestHandler handle.
			
OUTPUT:		None

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
TI_STATUS requestHandler_clearRequests(TI_HANDLE hRequestHandler)
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;

	pRequestHandler->numOfWaitingRequests = 0;
	pRequestHandler->activeRequestID = -1;
	
	/* Clearing the Request Array , mostly due to parallel bit */
	os_memoryZero(pRequestHandler->hOs,pRequestHandler->reqArr,
				  MAX_NUM_REQ * sizeof(MeasurementRequest_t));	
	
TRACE2(pRequestHandler->hReport, REPORT_SEVERITY_INFORMATION, ": Request queue has been cleared. activeRequestID = %d, numOfWaitingRequests = %d\n",					pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests);

	return TI_OK;
}


	
/************************************************************************
 *                  requestHandler_getFrameToken						*
 ************************************************************************
DESCRIPTION: RequestHandler module function for getting the token of the 
				frame that is now being processed.

INPUT:      hRequestHandler	-	RequestHandler handle.
			
			
OUTPUT:		frameToken

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
TI_STATUS requestHandler_getFrameToken(TI_HANDLE hRequestHandler,TI_UINT16 *frameToken )
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;

	if(pRequestHandler->activeRequestID == -1)
		return TI_NOK;

	*frameToken = pRequestHandler->reqArr[0].frameToken;
	
	return TI_OK;
}

/************************************************************************
 *              requestHandler_setRequestParserFunction					*
 ************************************************************************
DESCRIPTION: RequestHandler module function for setting the function that
             parasers a request IE.

INPUT:      hRequestHandler	-	RequestHandler handle.
            parserRequestIE -   A pointer to the function.
			
			
OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/	
TI_STATUS requestHandler_setRequestParserFunction(TI_HANDLE hRequestHandler, 
                                                  parserRequestIEHdr_t parserRequestIEHdr)
{
	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;

    pRequestHandler->parserRequestIEHdr = parserRequestIEHdr;

    return TI_OK;
}

/********************************************************************************/
/*						Internal functions Implementation.						*/
/********************************************************************************/

/************************************************************************
 *                  insertMeasurementIEToQueue							*
 ************************************************************************
DESCRIPTION: The function inserts measurement request of one received 
				measurement request information element.

INPUT:      hRequestHandler	-	A Handler to the Request Handler Object.
			frameToken		-	Frame token of the received frame in which
								This current measurement request IE is included.
            measurementObjMode - XCC or SPECTRUM_MNGMNT
			dataLen			-	pointer to the data length that is left.
			pData			-	pointer to the data.
			
OUTPUT:		singelRequestLen - The Length of the request that was inserted 
                               to the queue.

RETURN:     TI_OK on success, TI_NOK otherwise
************************************************************************/
static TI_STATUS insertMeasurementIEToQueue(TI_HANDLE           hRequestHandler,
											TI_UINT16				frameToken,
											EMeasurementMode	measurementObjMode,
											TI_UINT8				*pData,
                                            TI_UINT8               *singelRequestLen)
{
   	requestHandler_t	*pRequestHandler = (requestHandler_t *)hRequestHandler;

	TI_UINT16		HeaderLen;
	TI_UINT8		measurementMode;
	TI_UINT8		parallelBit;
	TI_UINT8		enableBit;
	TI_UINT16		durationTime;
    TI_UINT16      measurementToken;
	
	MeasurementRequest_t	*pCurrRequest = &(pRequestHandler->reqArr[pRequestHandler->numOfWaitingRequests]);

    if (pRequestHandler->parserRequestIEHdr(pData, &HeaderLen, &measurementToken) != TI_OK)
    {
        return TI_NOK;
    }

	pCurrRequest->frameToken = frameToken;	
	pCurrRequest->measurementToken = measurementToken;

    pData += HeaderLen;

    /*** Getting the Measurement Mode ***/
	measurementMode		= *pData++;

	/* getting parallel bit */
	parallelBit = measurementMode & 0x1;
	
    /* getting Enable bit */
	enableBit = (measurementMode & 0x2)>>1;
	
    /* checking enable bit, the current implementation does not support 
		enable bit which set to one, so there is no need to check request/report bits	*/
	if(enableBit == 1)
		return TI_OK;
    
    pCurrRequest->isParallel = parallelBit;


    /* Getting the Measurement Mode */
   	pCurrRequest->Type = (EMeasurementType)(*pData++);

	/* Inserting the request that is included in the current measurement request IE. */
	pCurrRequest->channelNumber = *pData++;
    
	pCurrRequest->ScanMode = (EMeasurementScanMode)(*pData++); /* IN dot11h - Spare = 0 */

    os_memoryCopy(pRequestHandler->hOs, &durationTime, pData, 2);
    durationTime = ENDIAN_HANDLE_WORD(durationTime);
	pCurrRequest->DurationTime = durationTime;
	
	*singelRequestLen = HeaderLen + 6;

	pRequestHandler->numOfWaitingRequests ++;
	
	return TI_OK;
}


/***********************************************************************
 *                        release_module									
 ***********************************************************************
DESCRIPTION:	Called by the destroy function or by the create function 
				(on failure). Go over the vector, for each bit that is 
				set, release the corresponding module.
                                                                                                   
INPUT:      pRequestHandler	-	RequestHandler pointer.
			initVec			-	Vector that contains a bit set for each 
								module thah had been initiualized

OUTPUT:		

RETURN:     TI_OK on success, TI_NOK otherwise

************************************************************************/
static void release_module(requestHandler_t *pRequestHandler, TI_UINT32 initVec)
{
	
	if ( initVec & (1 << REQUEST_HANDLER_INIT_BIT) )
		os_memoryFree(pRequestHandler->hOs, pRequestHandler, sizeof(requestHandler_t));
		
	initVec = 0;
}