1 /** \file measurementSrv.c 2 * \brief This file include the measurement SRV interface functions implementation. 3 * \author Ronen Kalish 4 * \date 09-November-2005 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 #include "measurementTypes.h" 42 #include "MeasurementSrv.h" 43 #include "MeasurementSrvSM.h" 44 #include "report.h" 45 #include "whalCtrl_api.h" 46 #include "osApi.h" 47 #include "MacServices.h" 48 #include "paramIn.h" 49 #include "public_event_mbox.h" 50 #include "measurementSrvDbgPrint.h" 51 52 /** 53 * \author Ronen Kalish\n 54 * \date 08-November-2005\n 55 * \brief Creates the measurement SRV object 56 * 57 * Function Scope \e Public.\n 58 * \param hOS - handle to the OS object.\n 59 * \return a handle to the measurement SRV object, NULL if an error occurred.\n 60 */ 61 TI_HANDLE MacServices_measurementSRV_create( TI_HANDLE hOS ) 62 { 63 measurementSRV_t* pMeasurementSRV; 64 int i; 65 66 /* allocate the measurement SRV object */ 67 pMeasurementSRV = os_memoryAlloc( hOS, sizeof(measurementSRV_t) ); 68 if ( NULL == pMeasurementSRV ) 69 { 70 WLAN_OS_REPORT( ("ERROR: Failed to create measurement SRV object.") ); 71 return NULL; 72 } 73 74 /* nullify the object */ 75 os_memoryZero( hOS, pMeasurementSRV, sizeof(measurementSRV_t) ); 76 77 /* store OS handle */ 78 pMeasurementSRV->hOS = hOS; 79 80 /* allocate the SM */ 81 if ( OK != fsm_Create( hOS, &(pMeasurementSRV->SM), MSR_SRV_NUM_OF_STATES, MSR_SRV_NUM_OF_EVENTS ) ) 82 { 83 pMeasurementSRV->SM = NULL; 84 WLAN_OS_REPORT(("Failed to create measurement SRV state machine.\n")); 85 MacServices_measurementSRV_destroy( pMeasurementSRV ); 86 return NULL; 87 } 88 89 /* allocate the timers */ 90 pMeasurementSRV->hStartStopTimer = 91 os_timerCreate( hOS, MacServices_measurementSRV_startStopTimerExpired, (TI_HANDLE)pMeasurementSRV ); 92 if ( NULL == pMeasurementSRV->hStartStopTimer ) 93 { 94 WLAN_OS_REPORT(("Failed to create measurement SRV FW guard timer.\n")); 95 MacServices_measurementSRV_destroy( pMeasurementSRV ); 96 return NULL; 97 } 98 99 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 100 { 101 pMeasurementSRV->hRequestTimer[ i ] 102 = os_timerCreate( hOS, MacServices_measurementSRV_requestTimerExpired, (TI_HANDLE)pMeasurementSRV ); 103 if ( NULL == pMeasurementSRV->hRequestTimer[ i ] ) 104 { 105 WLAN_OS_REPORT(("Failed to create measurement SRV request timers.\n")); 106 MacServices_measurementSRV_destroy( pMeasurementSRV ); 107 return NULL; 108 } 109 } 110 111 return (TI_HANDLE)pMeasurementSRV; 112 } 113 114 /** 115 * \author Ronen Kalish\n 116 * \date 08-November-2005\n 117 * \brief Initializes the measurement SRV object 118 * 119 * Function Scope \e Public.\n 120 * \param hMeasurementSRV - handle to the measurement SRV object.\n 121 * \param hReport - handle to the report object.\n 122 * \param hHALCtrl - handle to the HAL CTRL object.\n 123 * \param hPowerSaveSRV - handle to the power save SRV object.\n 124 */ 125 void MacServices_measurementSRV_init( TI_HANDLE hMeasurementSRV, TI_HANDLE hReport, TI_HANDLE hHALCtrl, 126 TI_HANDLE hPowerSaveSRV ) 127 { 128 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 129 int i; 130 131 /* store handles */ 132 pMeasurementSRV->hReport = hReport; 133 pMeasurementSRV->hHalCtrl = hHALCtrl; 134 pMeasurementSRV->hPowerSaveSRV = hPowerSaveSRV; 135 136 /* Initialize the state machine */ 137 measurementSRVSM_init( hMeasurementSRV ); 138 139 /* mark that all timers are not running */ 140 pMeasurementSRV->bStartStopTimerRunning = FALSE; 141 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 142 { 143 pMeasurementSRV->bRequestTimerRunning[ i ] = FALSE; 144 } 145 146 /* register HAL callbacks */ 147 /* Register and Enable the Measure Start event in HAL */ 148 whalCtrl_EventMbox_RegisterForEvent( pMeasurementSRV->hHalCtrl, 149 HAL_EVENT_MEASUREMENT_START, 150 (void *)MacServices_measurementSRV_measureStartCB, 151 hMeasurementSRV ); 152 whalCtrl_EventMbox_Enable( pMeasurementSRV->hHalCtrl, HAL_EVENT_MEASUREMENT_START ); 153 154 /* Register and Enable the Measurement Complete event in HAL. 155 This event will be received when the Measurement duration expired, 156 or after Stop Measure command. */ 157 whalCtrl_EventMbox_RegisterForEvent( pMeasurementSRV->hHalCtrl, 158 HAL_EVENT_MEASUREMENT_COMPLETE, 159 (void *)MacServices_measurementSRV_measureCompleteCB, 160 hMeasurementSRV ); 161 whalCtrl_EventMbox_Enable( pMeasurementSRV->hHalCtrl, HAL_EVENT_MEASUREMENT_COMPLETE ); 162 163 /* Register and Enable the AP Discovery Complete event in HAL */ 164 whalCtrl_EventMbox_RegisterForEvent( pMeasurementSRV->hHalCtrl, 165 HAL_EVENT_AP_DISCOVERY_COMPLETE, 166 (void *)MacServices_measurementSRV_apDiscoveryCompleteCB, 167 hMeasurementSRV ); 168 whalCtrl_EventMbox_Enable( pMeasurementSRV->hHalCtrl, HAL_EVENT_AP_DISCOVERY_COMPLETE); 169 170 171 WLAN_REPORT_INIT( hReport, MEASUREMENT_SRV_MODULE_LOG, (".....Measurement SRV configured successfully.\n") ); 172 } 173 174 /** 175 * \brief Restart the measurement SRV object upon recovery. 176 * 177 * Function Scope \e Public.\n 178 * \param hMeasurementSRV - handle to the measurement SRV object.\n 179 */ 180 void measurementSRV_restart( TI_HANDLE hMeasurementSRV) 181 { 182 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 183 int i; 184 185 /* if a timer is running, stop it */ 186 if ( TRUE == pMeasurementSRV->bStartStopTimerRunning ) 187 { 188 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 189 pMeasurementSRV->bStartStopTimerRunning = FALSE; 190 } 191 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 192 { 193 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 194 { 195 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hRequestTimer[ i ] ); 196 pMeasurementSRV->bRequestTimerRunning[ i ] = FALSE; 197 } 198 } 199 200 201 /* Initialize the state machine */ 202 /* initialize current state */ 203 pMeasurementSRV->SMState = MSR_SRV_STATE_IDLE; 204 205 /* mark that all timers are not running */ 206 pMeasurementSRV->bStartStopTimerRunning = FALSE; 207 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 208 { 209 pMeasurementSRV->bRequestTimerRunning[ i ] = FALSE; 210 } 211 212 } 213 214 /** 215 * \author Ronen Kalish\n 216 * \date 08-November-2005\n 217 * \brief Destroys the measurement SRV object 218 * 219 * Function Scope \e Public.\n 220 * \param hMeasurementSRV - handle to the measurement SRV object.\n 221 */ 222 void MacServices_measurementSRV_destroy( TI_HANDLE hMeasurementSRV ) 223 { 224 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 225 int i; 226 227 /* sanity cehcking */ 228 if ( NULL == hMeasurementSRV ) 229 { 230 return; 231 } 232 233 /* release state machine */ 234 if ( NULL != pMeasurementSRV->SM ) 235 { 236 fsm_Unload( pMeasurementSRV->hOS, pMeasurementSRV->SM ); 237 } 238 239 /* release timers */ 240 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 241 { 242 if ( NULL != pMeasurementSRV->hRequestTimer[ i ] ) 243 { 244 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 245 { 246 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hRequestTimer[ i ] ); 247 } 248 os_timerDestroy( pMeasurementSRV->hOS, pMeasurementSRV->hRequestTimer[ i ] ); 249 } 250 } 251 if ( NULL != pMeasurementSRV->hStartStopTimer ) 252 { 253 if ( TRUE == pMeasurementSRV->bStartStopTimerRunning ) 254 { 255 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 256 } 257 os_timerDestroy( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 258 } 259 260 /* release object space */ 261 os_memoryFree( pMeasurementSRV->hOS, (TI_HANDLE)pMeasurementSRV, sizeof(measurementSRV_t) ); 262 } 263 264 /** 265 * \author Ronen Kalish\n 266 * \date 09-November-2005\n 267 * \brief Starts a measurement operation.\n 268 * 269 * Function Scope \e Public.\n 270 * \param hMacServices - handle to the MacServices object.\n 271 * \param pMsrRequest - a structure containing measurement parameters.\n 272 * \param timeToRequestexpiryMs - the time (in milliseconds) the measurement SRV has to start the request.\n 273 * \param cmdResponseCBFunc - callback function to used for command response.\n 274 * \param cmdResponseCBObj - handle to pass to command response CB.\n 275 * \param cmdCompleteCBFunc - callback function to be used for command complete.\n 276 * \param cmdCompleteCBObj - handle to pass to command complete CB.\n 277 * \return OK if successful (various, TBD codes if not).\n 278 */ 279 TI_STATUS MacServices_measurementSRV_startMeasurement( TI_HANDLE hMacServices, 280 measurement_request_t* pMsrRequest, 281 UINT32 timeToRequestExpiryMs, 282 CmdResponseCB_t cmdResponseCBFunc, 283 TI_HANDLE cmdResponseCBObj, 284 measurement_srvCompleteCB_t cmdCompleteCBFunc, 285 TI_HANDLE cmdCompleteCBObj ) 286 { 287 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV; 288 int i; 289 290 #ifdef TI_DBG 291 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 292 ("%s: Received measurement request.\n", __FUNCTION__) ); 293 measurementSRVPrintRequest( (TI_HANDLE)pMeasurementSRV, pMsrRequest ); 294 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 295 ("time to expiry: %d ms, cmd response CB: 0x%x, cmd response handle: 0x%x\n", 296 timeToRequestExpiryMs, 297 cmdResponseCBFunc, 298 cmdResponseCBObj) ); 299 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 300 ("cmd complete CB: 0x%x, cmd complete handle: 0x%x\n", 301 cmdCompleteCBFunc, 302 cmdCompleteCBObj) ); 303 #endif 304 305 /* mark that request is in progress */ 306 pMeasurementSRV->bInRequest = TRUE; 307 308 /* mark to send NULL data when exiting driver mode (can be changed to FALSE 309 only when explictly stopping the measurement */ 310 pMeasurementSRV->bSendNullDataWhenExitPs = TRUE; 311 312 /* Nullify return status */ 313 pMeasurementSRV->returnStatus = OK; 314 315 /* copy request parameters */ 316 os_memoryCopy( pMeasurementSRV->hOS, (void *)&(pMeasurementSRV->msrRequest), (void *)pMsrRequest, 317 sizeof(measurement_request_t) ); 318 319 /* Mark the current time stamp and the duration to start to cehck expiry later */ 320 pMeasurementSRV->requestRecptionTimeStampMs = os_timeStampMs( pMeasurementSRV->hOS ); 321 pMeasurementSRV->timeToRequestExpiryMs = timeToRequestExpiryMs; 322 323 /* copy callbacks */ 324 pMeasurementSRV->commandResponseCBFunc = cmdResponseCBFunc; 325 pMeasurementSRV->commandResponseCBObj = cmdResponseCBObj; 326 pMeasurementSRV->measurmentCompleteCBFunc = cmdCompleteCBFunc; 327 pMeasurementSRV->measurementCompleteCBObj = cmdCompleteCBObj; 328 329 /* initialize reply */ 330 pMeasurementSRV->msrReply.numberOfTypes = pMsrRequest->numberOfTypes; 331 for ( i = 0; i < pMsrRequest->numberOfTypes; i++ ) 332 { 333 pMeasurementSRV->msrReply.msrTypes[ i ].msrType = pMeasurementSRV->msrRequest.msrTypes[ i ].msrType; 334 pMeasurementSRV->msrReply.msrTypes[ i ].status = OK; 335 } 336 337 /* nullify the pending CBs bitmap */ 338 pMeasurementSRV->pendingParamCBs = 0; 339 340 /* send a start measurement event to the SM */ 341 measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 342 MSR_SRV_EVENT_MEASURE_START_REQUEST ); 343 344 /* mark that request has been sent */ 345 pMeasurementSRV->bInRequest = FALSE; 346 347 return pMeasurementSRV->returnStatus; 348 } 349 350 /** 351 * \author Ronen Kalish\n 352 * \date 09-November-2005\n 353 * \brief Stops a measurement operation in progress.\n 354 * 355 * Function Scope \e Public.\n 356 * \param hMacServices - handle to the MacServices object.\n 357 * \param bSendNullData - whether to send NULL data when exiting driver mode.\n 358 * \param cmdResponseCBFunc - callback function to used for command response.\n 359 * \param cmdResponseCBObj - handle to pass to command response CB.\n 360 * \return OK if successful (various, TBD codes if not).\n 361 */ 362 TI_STATUS MacServices_measurementSRV_stopMeasurement( TI_HANDLE hMacServices, 363 BOOLEAN bSendNullData, 364 CmdResponseCB_t cmdResponseCBFunc, 365 TI_HANDLE cmdResponseCBObj ) 366 { 367 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV; 368 369 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 370 ("%s: Received measurement stop request.\n", __FUNCTION__) ); 371 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 372 ("Send null data:%s, cmd response CB: 0x%x, cmd response handle: 0x%x\n", 373 (TRUE == bSendNullData ? "Yes" : "No"), 374 cmdResponseCBFunc, 375 cmdResponseCBObj) ); 376 377 /* store callbacks */ 378 pMeasurementSRV->commandResponseCBFunc = cmdResponseCBFunc; 379 pMeasurementSRV->commandResponseCBObj = cmdResponseCBObj; 380 381 /* store NULL data indication */ 382 pMeasurementSRV->bSendNullDataWhenExitPs = bSendNullData; 383 384 /* mark that current return status is OK */ 385 pMeasurementSRV->returnStatus = OK; 386 387 /* mark that a stop request is in progress */ 388 pMeasurementSRV->bInRequest = TRUE; 389 390 /* send a stop event to the SM */ 391 measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 392 MSR_SRV_EVENT_MEASURE_STOP_REQUEST ); 393 394 /*mark that stop request has completed */ 395 pMeasurementSRV->bInRequest = FALSE; 396 397 return pMeasurementSRV->returnStatus; 398 } 399 400 /** 401 * \author Ronen Kalish\n 402 * \date 09-November-2005\n 403 * \brief Notifies the measurement SRV of a FW reset (recovery).\n 404 * 405 * Function Scope \e Public.\n 406 * \param hMacServices - handle to the MacServices object.\n 407 */ 408 void MacServices_measurementSRV_FWReset( TI_HANDLE hMacServices ) 409 { 410 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV; 411 int i; 412 413 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 414 ("%s: Received FW reset indication.\n", __FUNCTION__) ); 415 416 /* if a timer is running, stop it */ 417 if ( TRUE == pMeasurementSRV->bStartStopTimerRunning ) 418 { 419 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 420 pMeasurementSRV->bStartStopTimerRunning = FALSE; 421 } 422 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 423 { 424 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 425 { 426 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hRequestTimer[ i ] ); 427 pMeasurementSRV->bRequestTimerRunning[ i ] = FALSE; 428 } 429 } 430 431 /* change SM state to idle */ 432 pMeasurementSRV->SMState = MSR_SRV_STATE_IDLE; 433 } 434 435 /** 436 * \author Ronen Kalish\n 437 * \date 09-November-2005\n 438 * \brief callback function used by the power manager to notify driver mode result 439 * 440 * Function Scope \e Public.\n 441 * \param hMeasurementSRV - handle to the measurement SRV object.\n 442 * \param PSMode - the power save mode the STA is currently in.\n 443 * \param psStatus - the power save request status.\n 444 */ 445 void MacServices_measurementSRV_powerSaveCB( TI_HANDLE hMeasurementSRV, UINT8 PSMode, UINT8 psStatus ) 446 { 447 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 448 449 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 450 ("%s: Power save SRV CB called. PS mode:%d status: %d\n", 451 __FUNCTION__, PSMode, psStatus) ); 452 453 /* if driver mode entry succeedded */ 454 if ( ENTER_POWER_SAVE_SUCCESS == psStatus ) 455 { 456 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 457 ("%s: PS successful.\n", __FUNCTION__) ); 458 459 /* send a RIVER_MODE_SUCCESS event */ 460 measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 461 MSR_SRV_EVENT_DRIVER_MODE_SUCCESS ); 462 } 463 /* driver mode entry failed */ 464 else 465 { 466 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 467 ("%s: PS failed, status %d.\n", __FUNCTION__, psStatus) ); 468 469 /* Set the return status to NOK */ 470 pMeasurementSRV->returnStatus = (TI_STATUS)psStatus; 471 472 /* send a DRIVER_MODE_FAILURE event */ 473 measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 474 MSR_SRV_EVENT_DRIVER_MODE_FAILURE ); 475 } 476 } 477 478 /** 479 * \author Ronen Kalish\n 480 * \date 14-November-2005\n 481 * \brief callback function used by the HAL for measure start event (sent when the FW 482 * has started measurement operation, i.e. switched channel and changed RX filters).\n 483 * 484 * Function Scope \e Public.\n 485 * \param hMeasurementSRV - handle to the measurement SRV object.\n 486 */ 487 void MacServices_measurementSRV_measureStartCB( TI_HANDLE hMeasurementSRV ) 488 { 489 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 490 491 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 492 ("%s: measure start CB called.\n", __FUNCTION__) ); 493 494 /* stop the FW guard timer */ 495 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 496 pMeasurementSRV->bStartStopTimerRunning = FALSE; 497 498 /* clear the CB function, so that it won't be called on stop as well! */ 499 pMeasurementSRV->commandResponseCBFunc = NULL; 500 pMeasurementSRV->commandResponseCBObj = NULL; 501 502 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 503 MSR_SRV_EVENT_START_SUCCESS ); 504 } 505 506 /** 507 * \author Ronen Kalish\n 508 * \date 14-November-2005\n 509 * \brief callback function used by the HAL for measure stop event (sent when the FW 510 * has finished measurement operation, i.e. switched channel to serving channel and changed back RX filters).\n 511 * 512 * Function Scope \e Public.\n 513 * \param hMeasurementSRV - handle to the measurement SRV object.\n 514 */ 515 void MacServices_measurementSRV_measureCompleteCB( TI_HANDLE hMeasurementSRV ) 516 { 517 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 518 519 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 520 ("%s: measure complete CB called.\n", __FUNCTION__)); 521 522 /* stop the FW guard timer */ 523 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hStartStopTimer ); 524 pMeasurementSRV->bStartStopTimerRunning = FALSE; 525 526 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 527 MSR_SRV_EVENT_STOP_COMPLETE ); 528 } 529 530 /** 531 * \author Ronen Kalish\n 532 * \date 14-November-2005\n 533 * \brief callback function used by the HAL for AP discovery stop event (sent when the FW 534 * has finished AP discovery operation).\n 535 * 536 * Function Scope \e Public.\n 537 * \param hMeasurementSRV - handle to the measurement SRV object.\n 538 */ 539 void MacServices_measurementSRV_apDiscoveryCompleteCB( TI_HANDLE hMeasurementSRV ) 540 { 541 #ifdef TI_DBG 542 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 543 544 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 545 ("%s: AP Discovery complete CB called.\n", __FUNCTION__) ); 546 #endif /* TI_DBG */ 547 } 548 549 /** 550 * \author Ronen Kalish\n 551 * \date 14-November-2005\n 552 * \brief called when a measurement FW guard timer expires. 553 * 554 * Function Scope \e Public.\n 555 * \param hMeasuremntSRV - handle to the measurement SRV object.\n 556 */ 557 void MacServices_measurementSRV_startStopTimerExpired( TI_HANDLE hMeasurementSRV ) 558 { 559 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 560 int i; 561 562 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 563 ("%s: FW guard timer expired.\n", __FUNCTION__) ); 564 565 /* mark that the FW guard timer is not running */ 566 pMeasurementSRV->bStartStopTimerRunning = FALSE; 567 568 /* if any other timer is running - stop it */ 569 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 570 { 571 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 572 { 573 os_timerStop( pMeasurementSRV->hOS, pMeasurementSRV->hRequestTimer[ i ] ); 574 pMeasurementSRV->bRequestTimerRunning[ i ] = FALSE; 575 } 576 } 577 578 /* change SM state to idle */ 579 pMeasurementSRV->SMState = MSR_SRV_STATE_IDLE; 580 581 /*Error Reporting - call the centeral error function in the health monitor if a request for measurement was faield*/ 582 pMeasurementSRV->failureEventFunc(pMeasurementSRV->failureEventObj ,MEASUREMENT_FAILURE); 583 } 584 585 /** 586 * \author Ronen Kalish\n 587 * \date 15-November-2005\n 588 * \brief called when a measurement type timer expires.\n 589 * 590 * Function Scope \e Public.\n 591 * \param hMeasuremntSRV - handle to the measurement SRV object.\n 592 */ 593 void MacServices_measurementSRV_requestTimerExpired( TI_HANDLE hMeasurementSRV ) 594 { 595 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 596 int requestIndex; 597 598 /* find the expired measurement type */ 599 requestIndex = measurementSRVFindMinDuration( hMeasurementSRV ); 600 if ( -1 == requestIndex ) 601 { 602 /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */ 603 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 604 ("%s: Request timer expired and request index from findMinDuration is -1?!?", __FUNCTION__) ); 605 return; 606 } 607 608 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 609 ("%s: request timer expired, request index: %d.\n", __FUNCTION__, requestIndex) ); 610 611 /* mark that the timer is not running and that this request has completed */ 612 pMeasurementSRV->bRequestTimerRunning[ requestIndex ] = FALSE; 613 614 /* collect results and send stop command if necessary */ 615 switch (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType) 616 { 617 case MSR_TYPE_BEACON_MEASUREMENT: 618 measurementSRVHandleBeaconMsrComplete( hMeasurementSRV, requestIndex ); 619 break; 620 621 case MSR_TYPE_CCA_LOAD_MEASUREMENT: 622 measurementSRVHandleChannelLoadComplete( hMeasurementSRV, requestIndex ); 623 break; 624 625 case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT: 626 measurementSRVHandleNoiseHistogramComplete( hMeasurementSRV, requestIndex ); 627 break; 628 629 /* used here to avoid compilation warning only, does nothing */ 630 case MSR_TYPE_BASIC_MEASUREMENT: 631 case MSR_TYPE_FRAME_MEASUREMENT: 632 case MSR_TYPE_MAX_NUM_OF_MEASURE_TYPES: 633 default: 634 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 635 ("%s: measure type %d not supported for request %d\n", 636 __FUNCTION__, 637 pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType, 638 requestIndex) ); 639 break; 640 } 641 642 /* if no measurement are running and no CBs are pending, send ALL TYPES COMPLETE event */ 643 if ( TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ) ) 644 { 645 /* send the event */ 646 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 647 MSR_SRV_EVENT_ALL_TYPES_COMPLETE ); 648 } 649 } 650 651 /** 652 * \author Ronen Kalish\n 653 * \date 13-November-2005\n 654 * \brief Checks whether a beacon measurement is part of current measurement request 655 * 656 * Function Scope \e Private.\n 657 * \param hMeasurementSRV - handle to the measurement SRV object.\n 658 * \return TRUE if a beacon measurement is part of current request, FALSE otherwise.\n 659 */ 660 BOOLEAN measurementSRVIsBeaconMeasureIncluded( TI_HANDLE hMeasurementSRV ) 661 { 662 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 663 int i; 664 665 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 666 { 667 if ( MSR_TYPE_BEACON_MEASUREMENT == pMeasurementSRV->msrRequest.msrTypes[ i ].msrType ) 668 { 669 return TRUE; 670 } 671 } 672 return FALSE; 673 } 674 675 /** 676 * \author Ronen Kalish\n 677 * \date 15-November-2005\n 678 * \brief Finds the index for the measurement request with the shortest period 679 * (the one that has now completed).\n 680 * 681 * Function Scope \e Private.\n 682 * \param hMeasurementSRV - handle to the measurement SRV object.\n 683 * \return index of the measurement request with the shortest duration.\n 684 */ 685 int measurementSRVFindMinDuration( TI_HANDLE hMeasurementSRV ) 686 { 687 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 688 int i, minIndex; 689 UINT32 minValue; 690 691 692 minIndex = minValue = 0; /* minIndex is initialized only to avoid compilation warning! */ 693 694 /* find the index with the minimum duration */ 695 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 696 { 697 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 698 { 699 if ( (0 == minValue) || 700 (pMeasurementSRV->msrRequest.msrTypes[ i ].duration < minValue) ) 701 { 702 minValue = pMeasurementSRV->msrRequest.msrTypes[ i ].duration; 703 minIndex = i; 704 } 705 } 706 } 707 708 /* if no entry with positive duration exists, return -1 */ 709 if ( 0 == minValue ) 710 { 711 return -1; 712 } 713 else 714 { /* otherwise, return the index of the type with the shortest duration */ 715 return minIndex; 716 } 717 } 718 719 /** 720 * \author Ronen Kalish\n 721 * \date 15-November-2005\n 722 * \brief Handles an AP discovery timer expiry, by setting necessary values in the 723 * reply struct.\n 724 * 725 * Function Scope \e Private.\n 726 * \param hMeasurementSRV - handle to the measurement SRV object.\n 727 * \param requestIndex - index of the beacon request in the request structure.\n 728 */ 729 void measurementSRVHandleBeaconMsrComplete( TI_HANDLE hMeasurementSRV, int requestIndex ) 730 { 731 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 732 int status; 733 734 735 WLAN_REPORT_INFORMATION(pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 736 ("%s: Sending AP Discovery Stop to the HAL...", __FUNCTION__) ); 737 738 /* send stop AP discovery command */ 739 status = whalCtrl_ApDiscoveryStop( pMeasurementSRV->hHalCtrl ); 740 if ( OK != status ) 741 { 742 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 743 ("%s: status %d received from whalCtrl_ApDiscoveryStop\n", __FUNCTION__, status) ); 744 } 745 } 746 747 /** 748 * \author Ronen Kalish\n 749 * \date 15-November-2005\n 750 * \brief Handles a channel load timer expiry, by requesting channel load 751 * results from the FW.\n 752 * 753 * Function Scope \e Private.\n 754 * \param hMeasurementSRV - handle to the measurement SRV object.\n 755 * \param requestIndex - index of the channel load request in the request structure.\n 756 */ 757 void measurementSRVHandleChannelLoadComplete( TI_HANDLE hMeasurementSRV, int requestIndex ) 758 { 759 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 760 whalParamInfo_t whalParam; 761 TI_STATUS status; 762 763 /* Getting the Medium Occupancy Register */ 764 whalParam.paramType = HAL_CTRL_MEDIUM_OCCUPANCY_PARAM; 765 whalParam.content.interogateCmdCBParams.CB_Func = (void *)MacServices_measurementSRV_channelLoadParamCB; 766 whalParam.content.interogateCmdCBParams.CB_handle = hMeasurementSRV; 767 whalParam.content.interogateCmdCBParams.CB_buf = (UINT8*)(&(pMeasurementSRV->mediumOccupancyResults)); 768 status = whalCtrl_GetParam( pMeasurementSRV->hHalCtrl, &whalParam ); 769 770 if ( status != OK ) 771 { 772 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 773 ("%s: whalCtrl_GetParam returned status %d\n", __FUNCTION__, status) ); 774 775 /* mark that the specific measurment type has failed */ 776 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 777 778 /* if all measurement types has finished, an event will be send by request timer expired */ 779 } 780 else 781 { 782 /* mark that channel load param CB is pending */ 783 pMeasurementSRV->pendingParamCBs |= MSR_SRV_WAITING_CHANNEL_LOAD_RESULTS; 784 } 785 } 786 787 /** 788 * \author Ronen Kalish\n 789 * \date 15-November-2005\n 790 * \brief Handles a noise histogram timer expiry, by requesting noise histogram 791 * reaults from the FW.\n 792 * 793 * Function Scope \e Private.\n 794 * \param hMeasurementSRV - handle to the measurement SRV object.\n 795 * \param requestIndex - index of the beacon request in the request structure.\n 796 */ 797 void measurementSRVHandleNoiseHistogramComplete( TI_HANDLE hMeasurementSRV, int requestIndex ) 798 { 799 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 800 whalParamInfo_t whalParam; 801 whalCtrl_noiseHistogram_t pNoiseHistParams; 802 TI_STATUS status; 803 804 /* Set Noise Histogram Cmd Params */ 805 pNoiseHistParams.cmd = STOP_NOISE_HIST; 806 pNoiseHistParams.sampleInterval = 0; 807 os_memoryZero( pMeasurementSRV->hOS, &(pNoiseHistParams.ranges[0]), MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES ); 808 809 /* Send a Stop command to the FW */ 810 status = (TI_STATUS)whalCtrl_NoiseHistogramCmd( pMeasurementSRV->hHalCtrl, &pNoiseHistParams ); 811 812 if ( OK != status ) 813 { 814 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 815 ("%s: whalCtrl_NoiseHistogramCmd returned status %d\n", __FUNCTION__, status) ); 816 817 /* mark that the specific measurment type has failed */ 818 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 819 820 /* if all measurement types has finished, an event will be send by request timer expired */ 821 } 822 823 /* Get measurement results */ 824 whalParam.paramType = HAL_CTRL_NOISE_HISTOGRAM_PARAM; 825 whalParam.content.interogateCmdCBParams.CB_Func = (void *)MacServices_measurementSRV_noiseHistCallBack; 826 whalParam.content.interogateCmdCBParams.CB_handle = hMeasurementSRV; 827 whalParam.content.interogateCmdCBParams.CB_buf = (UINT8*)(&(pMeasurementSRV->noiseHistogramResults)); 828 status = whalCtrl_GetParam( pMeasurementSRV->hHalCtrl, &whalParam ); 829 830 if ( OK == status ) 831 { 832 /* setting On the Waitng for Noise Histogram Results Bit */ 833 pMeasurementSRV->pendingParamCBs |= MSR_SRV_WAITING_NOISE_HIST_RESULTS; 834 835 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 836 ("%s: sent noise histogram stop command.\n", 837 __FUNCTION__) ); 838 } 839 else 840 { 841 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 842 ("%s: whalCtrl_GetParam returned status %d\n", __FUNCTION__, status) ); 843 844 /* mark that the specific measurment type has failed */ 845 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 846 847 /* if all measurement types has finished, an event will be send by request timer expired */ 848 } 849 } 850 851 /** 852 * \author Ronen Kalish\n 853 * \date 16-November-2005\n 854 * \brief Callback for channel load get param call.\n 855 * 856 * Function Scope \e Public.\n 857 * \param hMeasurementSRV - handle to the measurement SRV object.\n 858 * \param status - the get_param call status.\n 859 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object) 860 */ 861 void MacServices_measurementSRV_channelLoadParamCB( TI_HANDLE hMeasurementSRV, TI_STATUS status, 862 UINT8* CB_buf ) 863 { 864 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 865 UINT32 mediumUsageInMs, periodInMs; 866 int requestIndex; 867 868 /* when this CB is called as a result of the nulify call at the measurement beginning, 869 the handle will be NULL. In this case, nothing needs to be done. */ 870 if ( NULL == hMeasurementSRV ) 871 { 872 return; 873 } 874 875 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 876 ("%s: Channel load CB called, status:%d\n", __FUNCTION__, status) ); 877 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 878 ("result address (reported): 0x%x, result address (assumed): 0x%x, results (reported):\n", 879 CB_buf, &(pMeasurementSRV->mediumOccupancyResults)) ); 880 WLAN_REPORT_HEX_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, CB_buf, sizeof(mediumOccupancy_t) ); 881 882 /* setting Off the Waitng for Channel Load Results Bit */ 883 pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_CHANNEL_LOAD_RESULTS; 884 885 /* find the request index */ 886 requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_CCA_LOAD_MEASUREMENT ); 887 if ( -1 == requestIndex ) 888 { 889 /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */ 890 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 891 ("%s: request index from measurementSRVFindIndexByType is -1?!?", __FUNCTION__) ); 892 return; 893 } 894 895 if ( (OK == status) && (0 != pMeasurementSRV->mediumOccupancyResults.Period) ) 896 { 897 /* calculate results */ 898 mediumUsageInMs = pMeasurementSRV->mediumOccupancyResults.MediumUsage / 1000; 899 periodInMs = pMeasurementSRV->mediumOccupancyResults.Period / 1000; 900 901 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 902 ("%s: MediumUsage = %d Period = %d\n", 903 __FUNCTION__,mediumUsageInMs, periodInMs) ); 904 905 if ( periodInMs <= pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration ) 906 { 907 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction = 908 ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) / 909 pMeasurementSRV->mediumOccupancyResults.Period; 910 } 911 else 912 { 913 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction = 914 ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) / 915 (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration * 1000); 916 } 917 } 918 else 919 { 920 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 921 ("%s: channel load failed. Status=%d, period=%d\n", 922 __FUNCTION__, 923 status, 924 pMeasurementSRV->mediumOccupancyResults.Period) ); 925 926 /* mark result status */ 927 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 928 } 929 930 /* if no measurement are running and no CBs are pending, 931 send ALL TYPES COMPLETE event */ 932 if ( TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ) ) 933 { 934 /* send the event */ 935 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 936 MSR_SRV_EVENT_ALL_TYPES_COMPLETE ); 937 } 938 } 939 940 /** 941 * \date 03-January-2005\n 942 * \brief Dummy callback for channel load get param call. Used to clear the channel load tracker.\n 943 * 944 * Function Scope \e Public.\n 945 * \param hMeasurementSRV - handle to the measurement SRV object.\n 946 * \param status - the get_param call status.\n 947 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object) 948 */ 949 void MacServices_measurementSRV_dummyChannelLoadParamCB( TI_HANDLE hMeasurementSRV, TI_STATUS status, 950 UINT8* CB_buf ) 951 { 952 #ifdef TI_DBG 953 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*) hMeasurementSRV; 954 955 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 956 ("%s: Dummy Channel Load callback called (status = %d)\n", __FUNCTION__, status)); 957 #endif /* TI_DBG */ 958 } 959 960 /** 961 * \author Ronen Kalish\n 962 * \date 16-November-2005\n 963 * \brief Callback for noise histogram get param call.\n 964 * 965 * Function Scope \e Public.\n 966 * \param hMeasurementSRV - handle to the measurement SRV object.\n 967 * \param status - the get_param call status.\n 968 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object) 969 */ 970 void MacServices_measurementSRV_noiseHistCallBack( TI_HANDLE hMeasurementSRV, TI_STATUS status, 971 UINT8* CB_buf ) 972 { 973 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 974 UINT8 index; 975 UINT32 sumOfSamples; 976 int requestIndex; 977 978 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 979 ("%s: noise histogram CB called, status: %d\n", __FUNCTION__, status) ); 980 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 981 ("result address (reported): 0x%x, result address (assumed): 0x%x, results (reported):\n", 982 CB_buf, &(pMeasurementSRV->noiseHistogramResults)) ); 983 WLAN_REPORT_HEX_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, CB_buf, sizeof(noiseHistogramResults_t) ); 984 985 /* setting Off the Waitng for noise histogram Results Bit */ 986 pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_NOISE_HIST_RESULTS; 987 988 /* find the request index */ 989 requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT ); 990 if ( -1 == requestIndex ) 991 { 992 /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */ 993 WLAN_REPORT_ERROR( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 994 ("%s: request index from measurementSRVFindIndexByType is -1?!?", __FUNCTION__) ); 995 return; 996 } 997 998 if ( OK == status ) 999 { 1000 sumOfSamples = pMeasurementSRV->noiseHistogramResults.numOfLostCycles; 1001 1002 /* Print For Debug */ 1003 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 1004 ("%s: numOfLostCycles = %d " 1005 "numOfTxHwGenLostCycles = %d numOfRxLostCycles = %d numOfExceedLastThresholdLostCycles = %d\n", 1006 __FUNCTION__, 1007 pMeasurementSRV->noiseHistogramResults.numOfLostCycles, 1008 pMeasurementSRV->noiseHistogramResults.numOfTxHwGenLostCycles, 1009 pMeasurementSRV->noiseHistogramResults.numOfRxLostCycles, 1010 pMeasurementSRV->noiseHistogramResults.numOfLostCycles - 1011 (pMeasurementSRV->noiseHistogramResults.numOfTxHwGenLostCycles + 1012 pMeasurementSRV->noiseHistogramResults.numOfRxLostCycles)) ); 1013 1014 for ( index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++ ) 1015 { 1016 sumOfSamples += pMeasurementSRV->noiseHistogramResults.counters[ index ]; 1017 1018 /* Print For Debug */ 1019 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 1020 ("%s: Counter #%d = %x\n", 1021 __FUNCTION__, index, pMeasurementSRV->noiseHistogramResults.counters[index])); 1022 } 1023 1024 /* If there weren't enough samples --> Reject the Request */ 1025 if ( (sumOfSamples - pMeasurementSRV->noiseHistogramResults.numOfLostCycles) < 1026 NOISE_HISTOGRAM_THRESHOLD ) 1027 { 1028 WLAN_REPORT_WARNING( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 1029 ("%s: noise histogram CB, rejecting request because %d samples received.\n", 1030 __FUNCTION__, 1031 sumOfSamples - pMeasurementSRV->noiseHistogramResults.numOfLostCycles) ); 1032 1033 /* set negative result status */ 1034 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 1035 } 1036 else 1037 { 1038 for (index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++) 1039 { 1040 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ index ] = 1041 ( 255 * pMeasurementSRV->noiseHistogramResults.counters[ index ]) / sumOfSamples; 1042 } 1043 1044 WLAN_REPORT_INFORMATION( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 1045 ("%s: Valid noise histogram reply. RPIDensity: %d %d %d %d %d %d %d %d\n", 1046 __FUNCTION__, 1047 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 0 ], 1048 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 1 ], 1049 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 2 ], 1050 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 3 ], 1051 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 4 ], 1052 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 5 ], 1053 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 6 ], 1054 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ 7 ]) ); 1055 } 1056 } 1057 else 1058 { 1059 WLAN_REPORT_WARNING( pMeasurementSRV->hReport, MEASUREMENT_SRV_MODULE_LOG, 1060 ("%s: noise histogram CB with status: %d, rejecting request.\n", 1061 __FUNCTION__, status) ); 1062 /* set negative result status */ 1063 pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = NOK; 1064 } 1065 1066 /* if no measurement are running and no CBs are pending, 1067 send ALL TYPES COMPLETE event */ 1068 if ( TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ) ) 1069 { 1070 /* send the event */ 1071 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 1072 MSR_SRV_EVENT_ALL_TYPES_COMPLETE ); 1073 } 1074 } 1075 1076 /** 1077 * \author Ronen Kalish\n 1078 * \date 16-November-2005\n 1079 * \brief Checks whether all measuremtn types had completed and all param CBs had been called.\n 1080 * 1081 * Function Scope \e Public.\n 1082 * \param hMeasurementSRV - handle to the measurement SRV object.\n 1083 * \param status - the get_param call status.\n 1084 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object) 1085 */ 1086 BOOLEAN measurementSRVIsMeasurementComplete( TI_HANDLE hMeasurementSRV ) 1087 { 1088 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 1089 int i; 1090 1091 /* verify that no request is currently running */ 1092 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 1093 { 1094 if ( TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 1095 { 1096 return FALSE; 1097 } 1098 } 1099 1100 /* verify that no CBs are pending */ 1101 if ( 0 != (pMeasurementSRV->pendingParamCBs & 1102 (MSR_SRV_WAITING_CHANNEL_LOAD_RESULTS | MSR_SRV_WAITING_NOISE_HIST_RESULTS)) ) 1103 { 1104 return FALSE; 1105 } 1106 1107 return TRUE; 1108 } 1109 1110 /** 1111 * \author Ronen Kalish\n 1112 * \date 17-November-2005\n 1113 * \brief Finds a measure type index in the measure request array.\n 1114 * 1115 * Function Scope \e Public.\n 1116 * \param hMeasurementSRV - handle to the measurement SRV object.\n 1117 * \param type - the measure type to look for.\n 1118 * \return the type index, -1 if not found.\n 1119 */ 1120 int measurementSRVFindIndexByType( TI_HANDLE hMeasurementSRV, measurement_type_e type ) 1121 { 1122 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 1123 int i; 1124 1125 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 1126 { 1127 if ( type == pMeasurementSRV->msrRequest.msrTypes[ i ].msrType ) 1128 { 1129 return i; 1130 } 1131 } 1132 return -1; 1133 } 1134 1135 1136 1137 /**************************************************************************************** 1138 * measurementSRVRegisterFailureEventCB * 1139 **************************************************************************************** 1140 DESCRIPTION: Registers a failure event callback for scan error notifications. 1141 1142 1143 INPUT: - hMeasurementSRV - handle to the Measurement SRV object. 1144 - failureEventCB - the failure event callback function.\n 1145 - hFailureEventObj - handle to the object passed to the failure event callback function. 1146 1147 OUTPUT: 1148 RETURN: void. 1149 ****************************************************************************************/ 1150 1151 void measurementSRVRegisterFailureEventCB( TI_HANDLE hMeasurementSRV, 1152 void * failureEventCB, TI_HANDLE hFailureEventObj ) 1153 { 1154 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 1155 1156 pMeasurementSRV->failureEventFunc = (failureEventCB_t)failureEventCB; 1157 pMeasurementSRV->failureEventObj = hFailureEventObj; 1158 } 1159 1160 1161