1 /** \file RequestHandler.c 2 * \brief RequestHandler module interface 3 * 4 * \see RequestHandler.h 5 */ 6 /**************************************************************************** 7 **+-----------------------------------------------------------------------+** 8 **| |** 9 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |** 10 **| All rights reserved. |** 11 **| |** 12 **| Redistribution and use in source and binary forms, with or without |** 13 **| modification, are permitted provided that the following conditions |** 14 **| are met: |** 15 **| |** 16 **| * Redistributions of source code must retain the above copyright |** 17 **| notice, this list of conditions and the following disclaimer. |** 18 **| * Redistributions in binary form must reproduce the above copyright |** 19 **| notice, this list of conditions and the following disclaimer in |** 20 **| the documentation and/or other materials provided with the |** 21 **| distribution. |** 22 **| * Neither the name Texas Instruments nor the names of its |** 23 **| contributors may be used to endorse or promote products derived |** 24 **| from this software without specific prior written permission. |** 25 **| |** 26 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |** 27 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |** 28 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |** 29 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |** 30 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |** 31 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |** 32 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |** 33 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |** 34 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |** 35 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |** 36 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |** 37 **| |** 38 **+-----------------------------------------------------------------------+** 39 ****************************************************************************/ 40 41 /****************************************************************************************************/ 42 /* */ 43 /* MODULE: RequestHandler.c */ 44 /* PURPOSE: RequestHandler module interface. */ 45 /* This module handle the incoming measurement requests. The object handle */ 46 /* data base that stores all measurement requests from the last incoming. */ 47 /* This module export interface function for sceduling the next requests to be */ 48 /* executed and stores all relevent fields for constructing a measurement report. */ 49 /* */ 50 /****************************************************************************************************/ 51 #include "report.h" 52 #include "osApi.h" 53 #include "paramOut.h" 54 #include "paramIn.h" 55 #include "utils.h" 56 #include "requestHandler.h" 57 58 #ifdef EXC_MODULE_INCLUDED 59 #include "excRMMngrParam.h" 60 #endif 61 62 /* allocation vector */ 63 #define REQUEST_HANDLER_INIT_BIT (1) 64 65 #define DOT11_MEASUREMENT_REQUEST_ELE_ID (38) 66 67 /********************************************************************************/ 68 /* Internal functions prototypes. */ 69 /********************************************************************************/ 70 static void release_module(requestHandler_t *pRequestHandler, UINT32 initVec); 71 72 static TI_STATUS insertMeasurementIEToQueue(TI_HANDLE hRequestHandler, 73 UINT16 frameToken, 74 measurement_mode_e measurementMode, 75 UINT8 *pData, 76 UINT8 *singelRequestLen); 77 78 /********************************************************************************/ 79 /* Interface functions Implementation. */ 80 /********************************************************************************/ 81 82 83 /******************************************************************************** 84 * requestHandler_create * 85 ******************************************************************************** 86 DESCRIPTION: RequestHandler module creation function, called by the measurement in 87 creation phase. performs the following: 88 89 - Allocate the RequestHandler handle 90 91 INPUT: hOs - Handle to OS 92 93 OUTPUT: 94 95 RETURN: Handle to the RequestHandler module on success, NULL otherwise 96 ************************************************************************/ 97 TI_HANDLE requestHandler_create(TI_HANDLE hOs) 98 { 99 requestHandler_t *pRequestHandler = NULL; 100 UINT32 initVec = 0; 101 102 103 /* allocating the RequestHandler object */ 104 pRequestHandler = os_memoryAlloc(hOs,sizeof(requestHandler_t)); 105 106 if (pRequestHandler == NULL) 107 return NULL; 108 109 initVec |= (1 << REQUEST_HANDLER_INIT_BIT); 110 111 return(pRequestHandler); 112 } 113 114 /************************************************************************ 115 * requestHandler_config * 116 ************************************************************************ 117 DESCRIPTION: RequestHandler module configuration function, called by the measurement 118 in configuration phase. performs the following: 119 - Reset & initiailzes local variables 120 - Init the handles to be used by the module 121 122 INPUT: hRequestHandler - RequestHandler handle. 123 List of handles to be used by the module 124 125 OUTPUT: 126 127 RETURN: OK on success, NOK otherwise 128 129 ************************************************************************/ 130 TI_STATUS RequestHandler_config(TI_HANDLE hRequestHandler, 131 TI_HANDLE hReport, 132 TI_HANDLE hOs) 133 { 134 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 135 136 137 /* init variables */ 138 pRequestHandler->parserRequestIEHdr = NULL; 139 pRequestHandler->numOfWaitingRequests = 0; /* indicating empty data base */ 140 pRequestHandler->activeRequestID = -1; /* */ 141 pRequestHandler->hReport = hReport; 142 pRequestHandler->hOs = hOs; 143 144 /* Clearing the Request Array , mostly due to parallel bit */ 145 os_memoryZero(pRequestHandler->hOs, pRequestHandler->reqArr, MAX_NUM_REQ * sizeof(MeasurementRequest_t)); 146 147 WLAN_REPORT_INIT(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, ("%s: RequestHandler configured successfully\n", __FUNCTION__)); 148 149 return OK; 150 } 151 152 /*********************************************************************** 153 * requestHandler_setParam 154 *********************************************************************** 155 DESCRIPTION: RequestHandler set param function, called by the following: 156 - config mgr in order to set a parameter receiving from 157 the OS abstraction layer. 158 - From inside the dirver 159 160 INPUT: hRequestHandler - RequestHandler handle. 161 pParam - Pointer to the parameter 162 163 OUTPUT: 164 165 RETURN: OK on success, NOK otherwise 166 167 ************************************************************************/ 168 TI_STATUS requestHandler_setParam(TI_HANDLE hRequestHandler, 169 paramInfo_t *pParam) 170 { 171 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 172 173 switch(pParam->paramType) 174 { 175 /* case RequestHandler_PARAM_TYPE:*/ 176 177 /* break;*/ 178 179 default: 180 WLAN_REPORT_ERROR(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 181 ("%s: Set param, Params is not supported, %d\n\n", __FUNCTION__, pParam->paramType)); 182 return PARAM_NOT_SUPPORTED; 183 } 184 185 /* return OK; - unreachable */ 186 } 187 188 /*********************************************************************** 189 * requestHandler_getParam 190 *********************************************************************** 191 DESCRIPTION: RequestHandler get param function, called by the following: 192 - config mgr in order to get a parameter from the OS a 193 bstraction layer. 194 - From inside the dirver 195 196 INPUT: hRequestHandler - RequestHandler handle. 197 pParam - Pointer to the parameter 198 199 OUTPUT: 200 201 RETURN: OK on success, NOK otherwise 202 203 ************************************************************************/ 204 TI_STATUS requestHandler_getParam(TI_HANDLE hRequestHandler, 205 paramInfo_t *pParam) 206 { 207 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 208 /* TI_STATUS status;*/ 209 210 switch(pParam->paramType) 211 { 212 /*case RequestHandler_PARAM:*/ 213 214 215 /*return status;*/ 216 217 default: 218 WLAN_REPORT_ERROR(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 219 ("%s: Get param, Params is not supported, %d\n\n", __FUNCTION__, pParam->paramType)); 220 return PARAM_NOT_SUPPORTED; 221 } 222 223 /* return OK; - unreachable */ 224 } 225 226 /************************************************************************ 227 * RequestHandler_destroy * 228 ************************************************************************ 229 DESCRIPTION: RequestHandler module destroy function, called by the config 230 mgr in the destroy phase 231 performs the following: 232 - Free all memory aloocated by the module 233 234 INPUT: hRequestHandler - RequestHandler handle. 235 236 OUTPUT: 237 238 RETURN: OK on success, NOK otherwise 239 240 ************************************************************************/ 241 TI_STATUS requestHandler_destroy(TI_HANDLE hRequestHandler) 242 { 243 requestHandler_t * pRequestHandler = (requestHandler_t *)hRequestHandler; 244 UINT32 initVec; 245 246 if (pRequestHandler == NULL) 247 return OK; 248 249 initVec = 0xFFFF; 250 release_module(pRequestHandler, initVec); 251 252 return OK; 253 } 254 255 /************************************************************************ 256 * requestHandler_insertRequests * 257 ************************************************************************ 258 DESCRIPTION: RequestHandler module parsing function, called by the 259 measurement object when measuremnt request frame is received. 260 performs the following: 261 - Parsers the measurement request frame. 262 - Inserts all requests into the queue. 263 - Initializes each request according to the its frame 264 token, measurement token, measurement type, parallel, 265 channel number, duration time and scan mode. 266 - The function updates the numOfWaitingRequests variable 267 and set to zero the activeReqId. 268 269 Note: The activeReqId contains the index for the first request 270 that should be executed or to the current active request. 271 272 INPUT: hRequestHandler - RequestHandler handle. 273 measurementMode - The MEasurement Object Mode. 274 measurementFrameReq - The New Frame request that was received. 275 276 OUTPUT: 277 278 RETURN: OK on success, NOK otherwise 279 ************************************************************************/ 280 TI_STATUS requestHandler_insertRequests(TI_HANDLE hRequestHandler, 281 measurement_mode_e measurementMode, 282 measurement_frameRequest_t measurementFrameReq) 283 { 284 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 285 INT32 requestsLen = measurementFrameReq.requestsLen; 286 UINT8 singelRequestLen = 0; 287 UINT8 *requests = measurementFrameReq.requests; 288 289 if (requestsLen < 2) 290 { 291 WLAN_REPORT_ERROR(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 292 ("%s: Invalid length of the data.\n", __FUNCTION__)); 293 294 return NOK; 295 } 296 297 /* Inserting all measurement request into the queues */ 298 while (requestsLen > 0) 299 { 300 if(insertMeasurementIEToQueue(hRequestHandler, 301 measurementFrameReq.hdr->dialogToken, 302 measurementMode, 303 requests, 304 &singelRequestLen) != OK ) 305 { 306 requestHandler_clearRequests(hRequestHandler); 307 return NOK; 308 } 309 310 requestsLen -= singelRequestLen; 311 requests += singelRequestLen; 312 313 } 314 315 pRequestHandler->activeRequestID = 0; 316 317 WLAN_REPORT_INFORMATION(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 318 ("%s: Inserted into queue: activeRequestID = %d, numOfWaitingRequests = %d\n", __FUNCTION__, 319 pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests)); 320 321 return OK; 322 } 323 324 /************************************************************************ 325 * requestHandler_getNextReq * 326 ************************************************************************ 327 DESCRIPTION: RequestHandler module function for retrieving the requests that 328 should be executed. 329 performs the following: 330 - returns pointers to one request/several requests that 331 should be performed in parallel. 332 Note: The function updates the numOfWaitingRequests internal 333 varaible ONLY IF the returned request/s are going to be 334 executed immediatly (isForActivation = TRUE). 335 336 INPUT: hRequestHandler - RequestHandler handle. 337 338 isForActivation - A flag that indicates if the returned 339 request/s are going to be executed immediatly 340 341 OUTPUT: pRequest - pointer contains the address in which the 342 next requests for activation should be inserted. 343 344 numOfRequests - indicates how many requests should be activated 345 in parallel. 346 347 RETURN: OK on success, NOK otherwise 348 ************************************************************************/ 349 TI_STATUS requestHandler_getNextReq(TI_HANDLE hRequestHandler, 350 BOOL isForActivation, 351 MeasurementRequest_t *pRequest[], 352 UINT8* numOfRequests) 353 { 354 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 355 UINT8 requestIndex = pRequestHandler->activeRequestID; 356 UINT8 loopIndex = 0; 357 358 WLAN_REPORT_INFORMATION(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 359 ("%s: Looking for requests. activeRequestID = %d, numOfWaitingRequests = %d\n", __FUNCTION__, 360 pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests)); 361 362 if(pRequestHandler->numOfWaitingRequests <= 0) 363 return NOK; 364 365 do{ 366 pRequest[loopIndex] = &(pRequestHandler->reqArr[requestIndex]); 367 requestIndex++; 368 loopIndex++; 369 } 370 while ( (loopIndex < pRequestHandler->numOfWaitingRequests) && 371 (pRequestHandler->reqArr[requestIndex].isParallel) ); 372 373 *numOfRequests = loopIndex; 374 375 WLAN_REPORT_INFORMATION(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 376 ("%s: Found %d requests to execute in parallel.\n", __FUNCTION__, loopIndex)); 377 378 if(isForActivation == TRUE) 379 { 380 pRequestHandler->numOfWaitingRequests -= loopIndex; 381 382 WLAN_REPORT_INFORMATION(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 383 ("%s: Requests were queried for activation so decreasing numOfWaitingRequests to %d\n", __FUNCTION__, pRequestHandler->numOfWaitingRequests)); 384 } 385 386 return OK; 387 } 388 389 /************************************************************************ 390 * requestHandler_getCurrentExpiredReq * 391 ************************************************************************ 392 DESCRIPTION: RequestHandler module function for retrieving the request that 393 finished its execution. 394 performs the following: 395 - returns pointers to the request that 396 finished its execution in. 397 398 INPUT: hRequestHandler - RequestHandler handle. 399 requestIndex - Index of request in the queue 400 401 OUTPUT: pRequest - pointer contains the addresse of the 402 request that finished its execution. 403 404 RETURN: OK on success, NOK otherwise 405 ************************************************************************/ 406 TI_STATUS requestHandler_getCurrentExpiredReq(TI_HANDLE hRequestHandler, 407 UINT8 requestIndex, 408 MeasurementRequest_t **pRequest) 409 { 410 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 411 412 requestIndex += pRequestHandler->activeRequestID; 413 414 *pRequest = &(pRequestHandler->reqArr[requestIndex]); 415 416 return OK; 417 } 418 419 420 /************************************************************************ 421 * requestHandler_clearRequests * 422 ************************************************************************ 423 DESCRIPTION: RequestHandler module function for cleaning the data base. 424 performs the following: 425 - Clears all requests from the queue by setting 426 the activeReqId and numOfWaitingRequests variables. 427 Note: The function does not actually zero all queue 428 variables or destroy the object. 429 430 INPUT: hRequestHandler - RequestHandler handle. 431 432 OUTPUT: None 433 434 RETURN: OK on success, NOK otherwise 435 ************************************************************************/ 436 TI_STATUS requestHandler_clearRequests(TI_HANDLE hRequestHandler) 437 { 438 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 439 440 pRequestHandler->numOfWaitingRequests = 0; 441 pRequestHandler->activeRequestID = -1; 442 443 /* Clearing the Request Array , mostly due to parallel bit */ 444 os_memoryZero(pRequestHandler->hOs,pRequestHandler->reqArr, 445 MAX_NUM_REQ * sizeof(MeasurementRequest_t)); 446 447 WLAN_REPORT_INFORMATION(pRequestHandler->hReport, MEASUREMENT_MNGR_MODULE_LOG, 448 ("%s: Request queue has been cleared. activeRequestID = %d, numOfWaitingRequests = %d\n", __FUNCTION__, 449 pRequestHandler->activeRequestID, pRequestHandler->numOfWaitingRequests)); 450 451 return OK; 452 } 453 454 455 456 /************************************************************************ 457 * requestHandler_getFrameToken * 458 ************************************************************************ 459 DESCRIPTION: RequestHandler module function for getting the token of the 460 frame that is now being processed. 461 462 INPUT: hRequestHandler - RequestHandler handle. 463 464 465 OUTPUT: frameToken 466 467 RETURN: OK on success, NOK otherwise 468 ************************************************************************/ 469 TI_STATUS requestHandler_getFrameToken(TI_HANDLE hRequestHandler,UINT16 *frameToken ) 470 { 471 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 472 473 if(pRequestHandler->activeRequestID == -1) 474 return NOK; 475 476 *frameToken = pRequestHandler->reqArr[0].frameToken; 477 478 return OK; 479 } 480 481 /************************************************************************ 482 * requestHandler_setRequestParserFunction * 483 ************************************************************************ 484 DESCRIPTION: RequestHandler module function for setting the function that 485 parasers a request IE. 486 487 INPUT: hRequestHandler - RequestHandler handle. 488 parserRequestIE - A pointer to the function. 489 490 491 OUTPUT: 492 493 RETURN: OK on success, NOK otherwise 494 ************************************************************************/ 495 TI_STATUS requestHandler_setRequestParserFunction(TI_HANDLE hRequestHandler, 496 parserRequestIEHdr_t parserRequestIEHdr) 497 { 498 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 499 500 pRequestHandler->parserRequestIEHdr = parserRequestIEHdr; 501 502 return OK; 503 } 504 505 /********************************************************************************/ 506 /* Internal functions Implementation. */ 507 /********************************************************************************/ 508 509 /************************************************************************ 510 * insertMeasurementIEToQueue * 511 ************************************************************************ 512 DESCRIPTION: The function inserts measurement request of one received 513 measurement request information element. 514 515 INPUT: hRequestHandler - A Handler to the Request Handler Object. 516 frameToken - Frame token of the received frame in which 517 This current measurement request IE is included. 518 measurementObjMode - EXC or SPECTRUM_MNGMNT 519 dataLen - pointer to the data length that is left. 520 pData - pointer to the data. 521 522 OUTPUT: singelRequestLen - The Length of the request that was inserted 523 to the queue. 524 525 RETURN: OK on success, NOK otherwise 526 ************************************************************************/ 527 static TI_STATUS insertMeasurementIEToQueue(TI_HANDLE hRequestHandler, 528 UINT16 frameToken, 529 measurement_mode_e measurementObjMode, 530 UINT8 *pData, 531 UINT8 *singelRequestLen) 532 { 533 requestHandler_t *pRequestHandler = (requestHandler_t *)hRequestHandler; 534 535 UINT16 HeaderLen; 536 UINT8 measurementMode; 537 UINT8 parallelBit; 538 UINT8 enableBit; 539 UINT16 durationTime; 540 UINT16 measurementToken; 541 542 MeasurementRequest_t *pCurrRequest = &(pRequestHandler->reqArr[pRequestHandler->numOfWaitingRequests]); 543 544 if (pRequestHandler->parserRequestIEHdr(pData, &HeaderLen, &measurementToken) != OK) 545 { 546 return NOK; 547 } 548 549 pCurrRequest->frameToken = frameToken; 550 pCurrRequest->measurementToken = measurementToken; 551 552 pData += HeaderLen; 553 554 /*** Getting the Measurement Mode ***/ 555 measurementMode = *pData++; 556 557 /* getting parallel bit */ 558 parallelBit = measurementMode & 0x1; 559 560 /* getting Enable bit */ 561 enableBit = (measurementMode & 0x2)>>1; 562 563 /* checking enable bit, the current implementation does not support 564 enable bit which set to one, so there is no need to check request/report bits */ 565 if(enableBit == 1) 566 return OK; 567 568 pCurrRequest->isParallel = parallelBit; 569 570 571 /* Getting the Measurement Mode */ 572 pCurrRequest->Type = (measurement_type_e)(*pData++); 573 574 /* Inserting the request that is included in the current measurement request IE. */ 575 pCurrRequest->channelNumber = *pData++; 576 577 pCurrRequest->ScanMode = (measurement_scanMode_e)(*pData++); /* IN dot11h - Spare = 0 */ 578 579 os_memoryCopy(pRequestHandler->hOs, &durationTime, pData, 2); 580 durationTime = ENDIAN_HANDLE_WORD(durationTime); 581 pCurrRequest->DurationTime = durationTime; 582 583 *singelRequestLen = HeaderLen + 6; 584 585 pRequestHandler->numOfWaitingRequests ++; 586 587 return OK; 588 } 589 590 591 /*********************************************************************** 592 * release_module 593 *********************************************************************** 594 DESCRIPTION: Called by the destroy function or by the create function 595 (on failure). Go over the vector, for each bit that is 596 set, release the corresponding module. 597 598 INPUT: pRequestHandler - RequestHandler pointer. 599 initVec - Vector that contains a bit set for each 600 module thah had been initiualized 601 602 OUTPUT: 603 604 RETURN: OK on success, NOK otherwise 605 606 ************************************************************************/ 607 static void release_module(requestHandler_t *pRequestHandler, UINT32 initVec) 608 { 609 610 if ( initVec & (1 << REQUEST_HANDLER_INIT_BIT) ) 611 utils_nullMemoryFree(pRequestHandler->hOs, pRequestHandler, 612 sizeof(requestHandler_t)); 613 614 initVec = 0; 615 } 616 617 618 619 620 621 622