1/* 2 * MeasurementSrvSM.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34/** \file measurementSrv.c 35 * \brief This file include the measurement SRV state machine implementation. 36 * \author Ronen Kalish 37 * \date 13-November-2005 38 */ 39 40#define __FILE_ID__ FILE_ID_112 41#include "osApi.h" 42#include "report.h" 43#include "MeasurementSrvSM.h" 44#include "MeasurementSrv.h" 45#include "PowerSrv_API.h" 46#include "timer.h" 47#include "fsm.h" 48#include "TWDriverInternal.h" 49#include "CmdBld.h" 50 51 52TI_STATUS actionUnexpected( TI_HANDLE hMeasurementSrv ); 53TI_STATUS actionNop( TI_HANDLE hMeasurementSrv ); 54static void measurementSRVSM_requestMeasureStartResponseCB(TI_HANDLE hMeasurementSRV, TI_UINT32 uMboxStatus); 55 56 57/** 58 * \author Ronen Kalish\n 59 * \date 08-November-2005\n 60 * \brief Initialize the measurement SRV SM.\n 61 * 62 * Function Scope \e Public.\n 63 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 64 * \return TI_OK if successful, TI_NOK otherwise.\n 65 */ 66TI_STATUS measurementSRVSM_init( TI_HANDLE hMeasurementSRV ) 67{ 68 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 69 70 fsm_actionCell_t smMatrix[ MSR_SRV_NUM_OF_STATES ][ MSR_SRV_NUM_OF_EVENTS ] = 71 { 72 /* next state and actions for IDLE state */ 73 { 74 {MSR_SRV_STATE_WAIT_FOR_DRIVER_MODE, measurementSRVSM_requestDriverMode}, /*"MESSURE_START_REQUEST"*/ 75 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_SUCCESS"*/ 76 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_FAILURE"*/ 77 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_SUCCESS"*/ 78 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_FAILURE"*/ 79 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"ALL_TYPES_COMPLETE"*/ 80 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"STOP_COMPLETE"*/ 81 {MSR_SRV_STATE_IDLE, measurementSRVSRVSM_dummyStop} /*"MEASURE_STOP_REQUEST"*/ 82 }, 83 84 85 /* next state and actions for WAIT_FOR_DRIVER_MODE state */ 86 { 87 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"MESSURE_START_REQUEST"*/ 88 {MSR_SRV_STATE_WAIT_FOR_MEASURE_START, measurementSRVSM_requestMeasureStart}, /*"DRIVER_MODE_SUCCESS"*/ 89 {MSR_SRV_STATE_IDLE, measurementSRVSM_DriverModeFailure}, /*"DRIVER_MODE_FAILURE"*/ 90 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_SUCCESS"*/ 91 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_FAILURE"*/ 92 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"ALL_TYPES_COMPLETE"*/ 93 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"STOP_COMPLETE"*/ 94 {MSR_SRV_STATE_IDLE, measurementSRVSM_stopFromWaitForDriverMode} /*"MEASURE_STOP_REQUEST"*/ 95 }, 96 97 /* next state and actions for WAIT_FOR_MEASURE_START state */ 98 { 99 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"MESSURE_START_REQUEST"*/ 100 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_SUCCESS"*/ 101 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_FAILURE"*/ 102 {MSR_SRV_STATE_MEASURE_IN_PROGRESS, measurementSRVSM_startMeasureTypes}, /*"START_SUCCESS"*/ 103 {MSR_SRV_STATE_IDLE, measurementSRVSM_measureStartFailure}, /*"START_FAILURE"*/ 104 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"ALL_TYPES_COMPLETE"*/ 105 {MSR_SRV_STATE_IDLE, measurementSRVSM_completeMeasure}, /*"STOP_COMPLETE"*/ 106 {MSR_SRV_STATE_WAIT_FOR_MEASURE_STOP, measurementSRVSM_stopFromWaitForMeasureStart} 107 /*"MEASURE_STOP_REQUEST"*/ 108 }, 109 110 /* next state and actions for MEASURE_IN_PROGRESS state */ 111 { 112 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"MESSURE_START_REQUEST"*/ 113 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_SUCCESS"*/ 114 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_FAILURE"*/ 115 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_SUCCESS"*/ 116 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_FAILURE"*/ 117 {MSR_SRV_STATE_WAIT_FOR_MEASURE_STOP, measurementSRVSM_requestMeasureStop}, /*"ALL_TYPES_COMPLETE"*/ 118 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"STOP_COMPLETE"*/ 119 {MSR_SRV_STATE_WAIT_FOR_MEASURE_STOP, measurementSRVSM_stopFromMeasureInProgress} 120 /*"MEASURE_STOP_REQUEST"*/ 121 }, 122 123 /* next state and actions for WAIT_FOR_MEASURE_STOP state */ 124 { 125 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"MESSURE_START_REQUEST"*/ 126 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_SUCCESS"*/ 127 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"DRIVER_MODE_FAILURE"*/ 128 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_SUCCESS"*/ 129 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"START_FAILURE"*/ 130 {MSR_SRV_STATE_IDLE, actionUnexpected}, /*"ALL_TYPES_COMPLETE"*/ 131 {MSR_SRV_STATE_IDLE, measurementSRVSM_completeMeasure}, /*"STOP_COMPLETE"*/ 132 {MSR_SRV_STATE_WAIT_FOR_MEASURE_STOP, measurementSRVSRVSM_dummyStop} /*"MEASURE_STOP_REQUEST"*/ 133 } 134 }; 135 136 /* initialize current state */ 137 pMeasurementSRV->SMState = MSR_SRV_STATE_IDLE; 138 139 /* configure the state machine */ 140 return fsm_Config( pMeasurementSRV->SM, (fsm_Matrix_t)smMatrix, 141 (TI_UINT8)MSR_SRV_NUM_OF_STATES, (TI_UINT8)MSR_SRV_NUM_OF_EVENTS, 142 (fsm_eventActivation_t)measurementSRVSM_SMEvent, pMeasurementSRV->hOS ); 143} 144 145/** 146 * \author Ronen Kalish\n 147 * \date 08-November-2005\n 148 * \brief Processes an event.\n 149 * 150 * Function Scope \e Public.\n 151 * \param hMeasurementSrv - handle to the measurement SRV object.\n 152 * \param currentState - the current scan SRV SM state.\n 153 * \param event - the event to handle.\n 154 * \return TI_OK if successful, TI_NOK otherwise.\n 155 */ 156TI_STATUS measurementSRVSM_SMEvent( TI_HANDLE hMeasurementSrv, measurements_SRVSMStates_e* currentState, 157 measurement_SRVSMEvents_e event ) 158{ 159 measurementSRV_t *pMeasurementSRV = (measurementSRV_t *)hMeasurementSrv; 160 TI_STATUS status = TI_OK; 161 TI_UINT8 nextState; 162 163 /* obtain the next state */ 164 status = fsm_GetNextState( pMeasurementSRV->SM, (TI_UINT8)*currentState, (TI_UINT8)event, &nextState ); 165 if ( status != TI_OK ) 166 { 167 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "measurementSRVSM_SMEvent: State machine error, failed getting next state\n"); 168 return TI_NOK; 169 } 170 171 /* report the move */ 172 TRACE3( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "measurementSRVSM_SMEvent: <currentState = %d, event = %d> --> nextState = %d\n", currentState, event, nextState); 173 174 /* move */ 175 return fsm_Event( pMeasurementSRV->SM, (TI_UINT8*)currentState, (TI_UINT8)event, hMeasurementSrv ); 176} 177 178/** 179 * \author Ronen Kalish\n 180 * \date 08-November-2005\n 181 * \brief Handle a MEASURE_START_REQUEST event by requesting driver mode.\n 182 * 183 * Function Scope \e Public.\n 184 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 185 * \return always TI_OK.\n 186 */ 187TI_STATUS measurementSRVSM_requestDriverMode( TI_HANDLE hMeasurementSRV ) 188{ 189 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 190 TI_STATUS PSStatus; 191 TTwdParamInfo paramInfo; 192 193 /* get the current channel */ 194 paramInfo.paramType = TWD_CURRENT_CHANNEL_PARAM_ID; 195 cmdBld_GetParam (pMeasurementSRV->hCmdBld, ¶mInfo); 196 197 /* check if the request is on the serving channel */ 198 if ( paramInfo.content.halCtrlCurrentChannel == pMeasurementSRV->msrRequest.channel ) 199 { 200 /* Switch Power Save SRV to driver mode w/o changing power save mode*/ 201 PSStatus = powerSrv_ReservePS( pMeasurementSRV->hPowerSaveSRV, POWER_SAVE_KEEP_CURRENT, 202 TI_TRUE, hMeasurementSRV, MacServices_measurementSRV_powerSaveCB ); 203 } 204 else 205 { 206 /* Switch Power Save SRV to driver mode with PS mode */ 207 PSStatus = powerSrv_ReservePS( pMeasurementSRV->hPowerSaveSRV, POWER_SAVE_ON, 208 TI_TRUE, hMeasurementSRV, MacServices_measurementSRV_powerSaveCB ); 209 } 210 211 switch (PSStatus) 212 { 213 case POWER_SAVE_802_11_IS_CURRENT: 214 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode entered successfully\n"); 215 /* send a power save success event */ 216 return measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 217 MSR_SRV_EVENT_DRIVER_MODE_SUCCESS ); 218 219 case POWER_SAVE_802_11_PENDING: 220 case TI_OK: 221 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode pending\n"); 222 break; 223 224 default: /* Error */ 225 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Error %d when requesting driver mode\n",PSStatus); 226 227 /* Set the return status to TI_NOK */ 228 pMeasurementSRV->returnStatus = PSStatus; 229 230 /* send a power save failure event */ 231 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 232 MSR_SRV_EVENT_DRIVER_MODE_FAILURE ); 233 break; 234 } 235 236 return TI_OK; 237} 238 239/** 240 * \author Ronen Kalish\n 241 * \date 08-November-2005\n 242 * \brief Handle a DRIVER_MODE_SUCCESS event by sending start measure command to the FW.\n 243 * 244 * Function Scope \e Public.\n 245 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 246 * \return always TI_OK.\n 247 */ 248TI_STATUS measurementSRVSM_requestMeasureStart( TI_HANDLE hMeasurementSRV ) 249{ 250 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 251 TMeasurementParams pMeasurementCmd; 252 TI_STATUS status; 253 TI_UINT32 currentTime = os_timeStampMs( pMeasurementSRV->hOS ); 254 255 /* check if request time has expired (note: timer wrap-around is also handled)*/ 256 if ( (pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs) 257 < currentTime ) 258 { 259 TI_INT32 i; 260 261 TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request time has expired, request expiry time:%d, current time:%d\n", pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs, currentTime); 262 263 /* mark that all measurement types has failed */ 264 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 265 { 266 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 267 } 268 269 /* send a measurement complete event */ 270 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 271 MSR_SRV_EVENT_STOP_COMPLETE ); 272 273 return TI_OK; 274 } 275 276 pMeasurementCmd.channel = pMeasurementSRV->msrRequest.channel; 277 pMeasurementCmd.band = pMeasurementSRV->msrRequest.band; 278 pMeasurementCmd.duration = 0; /* Infinite */ 279 pMeasurementCmd.eTag = pMeasurementSRV->msrRequest.eTag; 280 281 if ( measurementSRVIsBeaconMeasureIncluded( hMeasurementSRV )) 282 { /* Beacon Measurement is one of the types */ 283 284 /* get the current channel */ 285 TTwdParamInfo paramInfo; 286 287 paramInfo.paramType = TWD_CURRENT_CHANNEL_PARAM_ID; 288 cmdBld_GetParam (pMeasurementSRV->hCmdBld, ¶mInfo); 289 290 pMeasurementCmd.ConfigOptions = RX_CONFIG_OPTION_FOR_MEASUREMENT; 291 292 /* check if the request is on the serving channel */ 293 if ( paramInfo.content.halCtrlCurrentChannel == pMeasurementSRV->msrRequest.channel ) 294 { 295 /* Set the RX Filter to the join one, so that any packets will 296 be received on the serving channel - beacons and probe requests for 297 the measurmenet, and also data (for normal operation) */ 298 pMeasurementCmd.FilterOptions = RX_FILTER_OPTION_JOIN; 299 } 300 else 301 { 302 /* not on the serving channle - only beacons and rpobe responses are required */ 303 pMeasurementCmd.FilterOptions = RX_FILTER_OPTION_DEF_PRSP_BCN; 304 } 305 } 306 else 307 { /* No beacon measurement - use the current RX Filter */ 308 pMeasurementCmd.ConfigOptions = 0xffffffff; 309 pMeasurementCmd.FilterOptions = 0xffffffff; 310 } 311 312 /* Send start measurement command */ 313 status = cmdBld_CmdMeasurement (pMeasurementSRV->hCmdBld, 314 &pMeasurementCmd, 315 (void *)measurementSRVSM_requestMeasureStartResponseCB, 316 pMeasurementSRV); 317 318 if ( TI_OK != status ) 319 { 320 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement start command, statud=%d,\n", status); 321 322 /* keep the faulty return status */ 323 pMeasurementSRV->returnStatus = status; 324 325 /* send a measurement start fail event */ 326 return measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 327 MSR_SRV_EVENT_START_FAILURE ); 328 } 329 330 TRACE6( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure start command sent. Params:\n channel=%d, band=%d, duration=%d, \n configOptions=0x%x, filterOptions=0x%x, status=%d, \n", pMeasurementCmd.channel, pMeasurementCmd.band, pMeasurementCmd.duration, pMeasurementCmd.ConfigOptions, pMeasurementCmd.FilterOptions, status); 331 332 /* start the FW guard timer */ 333 pMeasurementSRV->bStartStopTimerRunning = TI_TRUE; 334 tmr_StartTimer (pMeasurementSRV->hStartStopTimer, 335 MacServices_measurementSRV_startStopTimerExpired, 336 (TI_HANDLE)pMeasurementSRV, 337 MSR_FW_GUARD_TIME, 338 TI_FALSE); 339 340 return TI_OK; 341} 342 343/** 344 * \author Ronen Kalish\n 345 * \date 08-November-2005\n 346 * \brief Handle a START_SUCCESS event by starting different measure types and setting timers.\n 347 * 348 * Function Scope \e Public.\n 349 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 350 * \return always TI_OK.\n 351 */ 352TI_STATUS measurementSRVSM_startMeasureTypes( TI_HANDLE hMeasurementSRV ) 353{ 354 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 355 TI_UINT8 requestIndex, rangeIndex; 356 TI_INT8 rangeUpperBound; 357 TTwdParamInfo tTwdParam; 358 TI_STATUS status; 359 TNoiseHistogram pNoiseHistParams; 360 TApDiscoveryParams pApDiscoveryParams; 361 TI_UINT32 currentTime = os_timeStampMs( pMeasurementSRV->hOS ); 362 363 /* check if request time has expired (note: timer wrap-around is also handled)*/ 364 if ( (pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs) 365 < currentTime ) 366 { 367 TI_INT32 i; 368 369 TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request time has expired, request expiry time:%d, current time:%d\n", pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs, currentTime); 370 371 /* mark that all measurement types has failed */ 372 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 373 { 374 pMeasurementSRV->msrReply.msrTypes[ i ].status = MSR_REJECT_MAX_DELAY_PASSED; 375 } 376 377 /* send a measurement complete event */ 378 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 379 MSR_SRV_EVENT_ALL_TYPES_COMPLETE ); 380 381 return TI_OK; 382 } 383 384 /* Going over all request types that should be executed in parallel 385 to start their timers and execute the measurement */ 386 for ( requestIndex = 0; requestIndex < pMeasurementSRV->msrRequest.numberOfTypes ; requestIndex++ ) 387 { 388 switch (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType) 389 { 390 case MSR_TYPE_CCA_LOAD_MEASUREMENT: 391 /* Clearing the Medium Occupancy Register */ 392 tTwdParam.paramType = TWD_MEDIUM_OCCUPANCY_PARAM_ID; 393 tTwdParam.content.interogateCmdCBParams.fCb = (void *)MacServices_measurementSRV_dummyChannelLoadParamCB; 394 tTwdParam.content.interogateCmdCBParams.hCb = hMeasurementSRV; 395 tTwdParam.content.interogateCmdCBParams.pCb = 396 (TI_UINT8*)&pMeasurementSRV->mediumOccupancyResults; 397 status = cmdBld_GetParam (pMeasurementSRV->hCmdBld, &tTwdParam); 398 if( TI_OK == status ) 399 { 400 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Medium Usage has been nullified, starting timer.\n"); 401 402 /* Start Timer */ 403 tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex], 404 MacServices_measurementSRV_requestTimerExpired, 405 (TI_HANDLE)pMeasurementSRV, 406 pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration, 407 TI_FALSE); 408 pMeasurementSRV->bRequestTimerRunning[requestIndex] = TI_TRUE; 409 } 410 else 411 { 412 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_GetParam (for channel load) returned status %d\n", status); 413 } 414 415 break; 416 417 case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT: 418 /* Set Noise Histogram Cmd Params */ 419 pNoiseHistParams.cmd = START_NOISE_HIST; 420 pNoiseHistParams.sampleInterval = DEF_SAMPLE_INTERVAL; 421 os_memoryZero( pMeasurementSRV->hOS, &(pNoiseHistParams.ranges[0]), MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES ); 422 423 /* Set Ranges */ 424 /* (-87) - First Range's Upper Bound */ 425 rangeUpperBound = -87; 426 427 /* Previously we converted from RxLevel to dBm - now this isn't necessary */ 428 /* rangeUpperBound = TWD_convertRSSIToRxLevel( pMeasurementSRV->hTWD, -87); */ 429 430 for(rangeIndex = 0; rangeIndex < MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES -1; rangeIndex++) 431 { 432 if(rangeUpperBound > 0) 433 { 434 pNoiseHistParams.ranges[rangeIndex] = 0; 435 } 436 else 437 { 438 pNoiseHistParams.ranges[rangeIndex] = rangeUpperBound; 439 } 440 rangeUpperBound += 5; 441 } 442 pNoiseHistParams.ranges[rangeIndex] = 0xFE; 443 444 /* Print for Debug */ 445 TRACE8(pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ":Noise histogram Measurement Ranges:\n%d %d %d %d %d %d %d %d\n", (TI_INT8) pNoiseHistParams.ranges[0], (TI_INT8) pNoiseHistParams.ranges[1], (TI_INT8) pNoiseHistParams.ranges[2], (TI_INT8) pNoiseHistParams.ranges[3], (TI_INT8) pNoiseHistParams.ranges[4], (TI_INT8) pNoiseHistParams.ranges[5], (TI_INT8) pNoiseHistParams.ranges[6], (TI_INT8) pNoiseHistParams.ranges[7]); 446 447 /* Send a Start command to the FW */ 448 status = cmdBld_CmdNoiseHistogram (pMeasurementSRV->hCmdBld, &pNoiseHistParams, NULL, NULL); 449 450 if ( TI_OK == status ) 451 { 452 /* Print for Debug */ 453 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Sent noise histogram command. Starting timer\n"); 454 455 /* Start Timer */ 456 tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex], 457 MacServices_measurementSRV_requestTimerExpired, 458 (TI_HANDLE)pMeasurementSRV, 459 pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration, 460 TI_FALSE); 461 pMeasurementSRV->bRequestTimerRunning[requestIndex] = TI_TRUE; 462 } 463 else 464 { 465 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_NoiseHistogramCmd returned status %d\n", status); 466 } 467 break; 468 469 case MSR_TYPE_BEACON_MEASUREMENT: 470 /* set all parameters in the AP discovery command */ 471 pApDiscoveryParams.scanDuration = pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration * 1000; /* TODO change this to an infinite value (was 0) */ 472 pApDiscoveryParams.numOfProbRqst = 1; 473 pApDiscoveryParams.txdRateSet = HW_BIT_RATE_1MBPS; 474 pApDiscoveryParams.ConfigOptions = RX_CONFIG_OPTION_FOR_MEASUREMENT; 475 pApDiscoveryParams.FilterOptions = RX_FILTER_OPTION_DEF_PRSP_BCN; 476 pApDiscoveryParams.txPowerDbm = pMeasurementSRV->msrRequest.txPowerDbm; 477 pApDiscoveryParams.scanOptions = SCAN_ACTIVE; /* both scan type and band are 0 for active and */ 478 /* 2.4 GHz, respectively, but 2.4 is not defined */ 479 480 /* band determined at the initiate measurement command not at that structure */ 481 482 /* scan mode go into the scan option field */ 483 if ( MSR_SCAN_MODE_PASSIVE == pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].scanMode ) 484 { 485 pApDiscoveryParams.scanOptions |= SCAN_PASSIVE; 486 } 487 488 /* Send AP Discovery command */ 489 status = cmdBld_CmdApDiscovery (pMeasurementSRV->hCmdBld, &pApDiscoveryParams, NULL, NULL); 490 491 if ( TI_OK == status ) 492 { 493 TRACE7( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": AP discovery command sent. Params:\n scanDuration=%d, scanOptions=%d, numOfProbRqst=%d, txdRateSet=%d, txPowerDbm=%d, configOptions=%d, filterOptions=%d\n Starting timer...\n", pApDiscoveryParams.scanDuration, pApDiscoveryParams.scanOptions, pApDiscoveryParams.numOfProbRqst, pApDiscoveryParams.txdRateSet, pApDiscoveryParams.txPowerDbm, pApDiscoveryParams.ConfigOptions, pApDiscoveryParams.FilterOptions); 494 495 /* Start Timer */ 496 tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex], 497 MacServices_measurementSRV_requestTimerExpired, 498 (TI_HANDLE)pMeasurementSRV, 499 pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration, 500 TI_FALSE); 501 pMeasurementSRV->bRequestTimerRunning[ requestIndex ] = TI_TRUE; 502 } 503 else 504 { 505 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_ApDiscoveryCmd returned status %d\n", status); 506 } 507 break; 508 509 case MSR_TYPE_BASIC_MEASUREMENT: /* not supported in current implemntation */ 510 case MSR_TYPE_FRAME_MEASUREMENT: /* not supported in current implemntation */ 511 default: 512 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Measurement type %d is not supported\n", pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType); 513 break; 514 } 515 } 516 517 /* if no measurement types are running, sen al types complete event. 518 This can happen if all types failed to start */ 519 if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV )) 520 { 521 /* send the event */ 522 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 523 MSR_SRV_EVENT_ALL_TYPES_COMPLETE ); 524 } 525 526 return TI_OK; 527} 528 529/** 530 * \author Ronen Kalish\n 531 * \date 08-November-2005\n 532 * \brief Handle an ALL_TYPE_COMPLETE event by sending a stop measure command to the FW.\n 533 * 534 * Function Scope \e Public.\n 535 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 536 * \return always TI_OK.\n 537 */ 538TI_STATUS measurementSRVSM_requestMeasureStop( TI_HANDLE hMeasurementSRV ) 539{ 540 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 541 TI_STATUS status; 542 543 /* since this function may also be called when stop is requested and start complete event 544 has not yet been received from the FW, we may need to stop the FW guard timer */ 545 if (pMeasurementSRV->bStartStopTimerRunning) 546 { 547 tmr_StopTimer (pMeasurementSRV->hStartStopTimer); 548 pMeasurementSRV->bStartStopTimerRunning = TI_FALSE; 549 } 550 551 /* Send Measurement Stop command to the FW */ 552 status = cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld, 553 (void *)pMeasurementSRV->commandResponseCBFunc, 554 pMeasurementSRV->commandResponseCBObj); 555 556 pMeasurementSRV->commandResponseCBFunc = NULL; 557 pMeasurementSRV->commandResponseCBObj = NULL; 558 559 if ( TI_OK != status ) 560 { 561 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement stop command, statud=%d,\n", status); 562 563 /* send a measurement complete event - since it can't be stopped */ 564 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), MSR_SRV_EVENT_STOP_COMPLETE ); 565 return TI_OK; 566 } 567 568 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure stop command sent.\n"); 569 570 /* start the FW guard timer */ 571 pMeasurementSRV->bStartStopTimerRunning = TI_TRUE; 572 tmr_StartTimer (pMeasurementSRV->hStartStopTimer, 573 MacServices_measurementSRV_startStopTimerExpired, 574 (TI_HANDLE)pMeasurementSRV, 575 MSR_FW_GUARD_TIME, 576 TI_FALSE); 577 578 return TI_OK; 579} 580 581/** 582 * \author Ronen Kalish\n 583 * \date 08-November-2005\n 584 * \brief Handle a STOP_COMPLETE event by exiting driver mode and calling the complete CB.\n 585 * 586 * Function Scope \e Public.\n 587 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 588 * \return always TI_OK.\n 589 */ 590TI_STATUS measurementSRVSM_completeMeasure( TI_HANDLE hMeasurementSRV ) 591{ 592 measurementSRV_t *pMeasurementSRV = (measurementSRV_t *)hMeasurementSRV; 593 594 /* Switch Power Save SRV back to user mode */ 595 powerSrv_ReleasePS( pMeasurementSRV->hPowerSaveSRV, pMeasurementSRV->bSendNullDataWhenExitPs, NULL, NULL ); 596 597 /* if the response CB is still pending, call it (when requestExpiryTimeStamp was reached) */ 598 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 599 { 600 pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_OK ); 601 } 602 603 /* call the complete CB */ 604 if ( NULL != pMeasurementSRV->measurmentCompleteCBFunc ) 605 { 606 pMeasurementSRV->measurmentCompleteCBFunc( pMeasurementSRV->measurementCompleteCBObj, 607 &(pMeasurementSRV->msrReply)); 608 } 609 610 return TI_OK; 611} 612 613/** 614 * \author Ronen Kalish\n 615 * \date 08-November-2005\n 616 * \brief Handle a STOP_REQUEST event when in WAIT_FOR_DRIVER_MODE state by exiting driver mode. 617 * 618 * Function Scope \e Public.\n 619 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 620 * \return always TI_OK.\n 621 */ 622TI_STATUS measurementSRVSM_stopFromWaitForDriverMode( TI_HANDLE hMeasurementSRV ) 623{ 624 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 625 626 /* Switch Power Save SRV back to user mode */ 627 powerSrv_ReleasePS( pMeasurementSRV->hPowerSaveSRV, pMeasurementSRV->bSendNullDataWhenExitPs, NULL, NULL ); 628 629 /* if we are not running within a stop request context (shouldn't happen), call the CBs */ 630 if ( TI_FALSE == pMeasurementSRV->bInRequest ) 631 { 632 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": stop from wait for driver mode: not within a request context?!? \n"); 633 634 /* call the response CB - this shouldn't happen, as only GWSI has response CB, and it shouldn't call 635 stop before driver */ 636 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 637 { 638 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": stop from wait for driver mode: command response CB is not NULL?!? \n"); 639 pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_OK ); 640 641 pMeasurementSRV->commandResponseCBFunc = NULL; 642 pMeasurementSRV->commandResponseCBObj = NULL; 643 } 644 /* call the complete CB */ 645 if ( NULL != pMeasurementSRV->measurmentCompleteCBFunc ) 646 { 647 /* mark that all types has failed */ 648 TI_INT32 i; 649 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 650 { 651 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 652 } 653 /* call the complete CB */ 654 pMeasurementSRV->measurmentCompleteCBFunc( pMeasurementSRV->measurementCompleteCBObj, 655 &(pMeasurementSRV->msrReply)); 656 } 657 else 658 { 659 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": stop from wait for driver mode and response CB is NULL!!!\n"); 660 } 661 } 662 /* we are within a stop request context */ 663 else 664 { 665 /* if the command response Cb is valid, send a measure stop command to the FW - 666 although it is not necessary, we need it to get a different context for the command response. 667 This shouldn't happen, as only GWSI has command response, and it shouldn't call stop measure 668 before it got the commadn response for start measure */ 669 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 670 { 671 /* shouldn't happen - a command response is valid (GWSI) and stop measure called 672 before measure start response was received (driver) */ 673 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": stop from wait for driver mode - within request context and command response is not NULL?!?\n"); 674 675 cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld, 676 (void *)pMeasurementSRV->commandResponseCBFunc, 677 pMeasurementSRV->commandResponseCBObj); 678 679 pMeasurementSRV->commandResponseCBFunc = NULL; 680 pMeasurementSRV->commandResponseCBObj = NULL; 681 } 682 if ( NULL != pMeasurementSRV->measurmentCompleteCBFunc ) 683 { 684 /* Note: this is being called from request context, but there's npthing else that can be done */ 685 /* mark that all types has failed */ 686 TI_INT32 i; 687 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 688 { 689 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 690 } 691 /* call the complete CB */ 692 pMeasurementSRV->measurmentCompleteCBFunc( pMeasurementSRV->measurementCompleteCBObj, 693 &(pMeasurementSRV->msrReply)); 694 } 695 } 696 697 return TI_OK; 698} 699 700/** 701 * \author Ronen Kalish\n 702 * \date 27-November-2005\n 703 * \brief handle a STOP_REQUEST event when in WAIT_FOR_DRIVER_MODE by marking negative result status 704 * \brief and calling the ordinary stop function 705 * 706 * Function Scope \e Public.\n 707 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 708 * \return always TI_OK.\n 709 */ 710TI_STATUS measurementSRVSM_stopFromWaitForMeasureStart( TI_HANDLE hMeasurementSRV ) 711{ 712 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 713 TI_INT32 i; 714 715 /* mark that all types has failed */ 716 for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ ) 717 { 718 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 719 } 720 721 /* call the ordinary stop function (will send a measure stop command to FW) */ 722 measurementSRVSM_requestMeasureStop( hMeasurementSRV ); 723 724 return TI_OK; 725} 726 727/** 728 * \author Ronen Kalish\n 729 * \date 08-November-2005\n 730 * \brief handle a STOP_REQUEST event when in MEASURE_IN_PROGRESS by stopping all measure types and 731 * \brief requesting measure stop from the FW.\n 732 * 733 * Function Scope \e Public.\n 734 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 735 * \return always TI_OK.\n 736 */ 737TI_STATUS measurementSRVSM_stopFromMeasureInProgress( TI_HANDLE hMeasurementSRV ) 738{ 739 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 740 TNoiseHistogram pNoiseHistParams; 741 TI_STATUS status; 742 TI_INT32 i; 743 744 /* stop all running measure types */ 745 for (i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++) 746 { 747 if (pMeasurementSRV->bRequestTimerRunning[i]) 748 { 749 /* stop timer */ 750 tmr_StopTimer (pMeasurementSRV->hRequestTimer[i]); 751 pMeasurementSRV->bRequestTimerRunning[i] = TI_FALSE; 752 753 /* if necessary, stop measurement type */ 754 switch ( pMeasurementSRV->msrRequest.msrTypes[ i ].msrType ) 755 { 756 case MSR_TYPE_BEACON_MEASUREMENT: 757 /* send stop AP discovery command */ 758 status = cmdBld_CmdApDiscoveryStop (pMeasurementSRV->hCmdBld, NULL, NULL); 759 if ( TI_OK != status ) 760 { 761 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_ApDiscoveryStop returned status %d\n", status); 762 } 763 break; 764 765 case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT: 766 /* Set Noise Histogram Cmd Params */ 767 pNoiseHistParams.cmd = STOP_NOISE_HIST; 768 pNoiseHistParams.sampleInterval = 0; 769 os_memoryZero( pMeasurementSRV->hOS, &(pNoiseHistParams.ranges[ 0 ]), MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES ); 770 771 /* Send a Stop command to the FW */ 772 status = cmdBld_CmdNoiseHistogram (pMeasurementSRV->hCmdBld, &pNoiseHistParams, NULL, NULL); 773 774 if ( TI_OK != status ) 775 { 776 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_NoiseHistogramCmd returned status %d\n", status); 777 } 778 break; 779 780 /* These are just to avoid compilation warnings, nothing is actualy done here! */ 781 case MSR_TYPE_BASIC_MEASUREMENT: 782 case MSR_TYPE_CCA_LOAD_MEASUREMENT: 783 case MSR_TYPE_FRAME_MEASUREMENT: 784 case MSR_TYPE_MAX_NUM_OF_MEASURE_TYPES: 785 default: 786 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": unsupported measurement type: %d\n", pMeasurementSRV->msrRequest.msrTypes[ i ].msrType); 787 break; 788 } 789 790 /* mark that measurement has failed */ 791 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 792 } 793 } 794 795 /* Send Measurement Stop command to the FW */ 796 status = cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld, 797 (void *)pMeasurementSRV->commandResponseCBFunc, 798 pMeasurementSRV->commandResponseCBObj); 799 800 pMeasurementSRV->commandResponseCBFunc = NULL; 801 pMeasurementSRV->commandResponseCBObj = NULL; 802 803 if ( TI_OK != status ) 804 { 805 TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement stop command, statud=%d,\n", status); 806 807 /* send a measurement complete event - since it can't be stopped */ 808 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 809 MSR_SRV_EVENT_STOP_COMPLETE ); 810 return TI_OK; 811 } 812 813 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure stop command sent.\n"); 814 815 /* start the FW guard timer */ 816 pMeasurementSRV->bStartStopTimerRunning = TI_TRUE; 817 tmr_StartTimer (pMeasurementSRV->hStartStopTimer, 818 MacServices_measurementSRV_startStopTimerExpired, 819 (TI_HANDLE)pMeasurementSRV, 820 MSR_FW_GUARD_TIME, 821 TI_FALSE); 822 823 return TI_OK; 824} 825 826/** 827 * \author Ronen Kalish\n 828 * \date 08-November-2005\n 829 * \brief handle a DRIVER_MODE_FAILURE event by calling the response and complete CBs.\n 830 * 831 * Function Scope \e Public.\n 832 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 833 * \return always TI_OK.\n 834 */ 835TI_STATUS measurementSRVSM_DriverModeFailure( TI_HANDLE hMeasurementSRV ) 836{ 837 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 838 839 /* this function can be called from within a request (when the power save SRV returned an immediate error), 840 or in a different context, when power save entry failed. The latter is a valid status, whereas the former 841 indicates a severe error. However, as there is nothing to do with the former (other than debug it), the same 842 failure indication is used for both of them, which will make the upper layer (Palau driver or TI measurement 843 manager) to return to idle state. Still, for the former the error is returned as the return status from the 844 measurement start API call whereas for the latter the error is indicated both by the command response and 845 measurement complete CBs status */ 846 847 /* if we are running within a request context, don't call the CBs! The startMeasurement function 848 will return an invalid status instead */ 849 if ( TI_FALSE == pMeasurementSRV->bInRequest ) 850 { 851 /* if a response CB is available (GWSI) call it */ 852 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 853 { 854 pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_NOK ); 855 } 856 857 /* if a complete CB is available (both GWSI and TI driver), call it */ 858 if ( NULL != pMeasurementSRV->measurmentCompleteCBFunc ) 859 { 860 /* mark that all types has failed */ 861 TI_INT32 i; 862 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 863 { 864 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 865 } 866 /* call the complete CB */ 867 pMeasurementSRV->measurmentCompleteCBFunc( pMeasurementSRV->measurementCompleteCBObj, 868 &(pMeasurementSRV->msrReply)); 869 } 870 else 871 { 872 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": driver mode failure and complete CB is NULL!!!\n"); 873 } 874 } 875 876 return TI_OK; 877} 878 879/** 880 * \author Ronen Kalish\n 881 * \date 08-November-2005\n 882 * \brief handle a START_FAILURE event by exiting driver mode and calling the complete CB.\n 883 * 884 * Function Scope \e Public.\n 885 * \param hMeasurementSrv - handle to the Measurement SRV object.\n 886 * \return always TI_OK.\n 887 */ 888TI_STATUS measurementSRVSM_measureStartFailure( TI_HANDLE hMeasurementSRV ) 889{ 890 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 891 892 /* This function can be called from within a request context (if the driver mode entry process 893 was immediate), or from the driver mode CB context. Regardless of teh context in which it runs, 894 The error indicates that something is wrong in the HAL. There is no way to solve this (other than debug it). 895 The error is either indicating by the measurement start API return status (if still in the request context), 896 or by calling the response (if available, only in GWSI) and complete CBs with invalid status */ 897 898 /* Switch Power save SRV back to user mode */ 899 powerSrv_ReleasePS( pMeasurementSRV->hPowerSaveSRV, pMeasurementSRV->bSendNullDataWhenExitPs, NULL, NULL ); 900 901 /* if we are running within a request context, don't call the CB! The startMeasurement function 902 will return an invalid status instead */ 903 if ( TI_FALSE == pMeasurementSRV->bInRequest ) 904 { 905 /* if a response CB is available (GWSI) call it */ 906 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 907 { 908 pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_NOK ); 909 } 910 911 /* if a complete CB is available (both GWSI and TI driver), call it */ 912 if ( NULL != pMeasurementSRV->measurmentCompleteCBFunc ) 913 { 914 /* mark that all types has failed */ 915 TI_INT32 i; 916 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 917 { 918 pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK; 919 } 920 /* call the complete CB */ 921 pMeasurementSRV->measurmentCompleteCBFunc( pMeasurementSRV->measurementCompleteCBObj, 922 &(pMeasurementSRV->msrReply)); 923 } 924 else 925 { 926 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Start measurement failure and response and complete CBs are NULL!!!\n"); 927 } 928 } 929 930 return TI_OK; 931} 932 933 934static void measurementSRVSM_requestMeasureStartResponseCB(TI_HANDLE hMeasurementSRV, TI_UINT32 uMboxStatus) 935{ 936 measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV; 937 TI_INT32 i; 938 939TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS = %d\n", uMboxStatus); 940 941 if (uMboxStatus == TI_OK) 942 { 943TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS_SUCCESS!\n"); 944 945 if ( NULL != pMeasurementSRV->commandResponseCBFunc ) 946 { 947 pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_OK ); 948 } 949 } 950 else 951 { 952 if (uMboxStatus == SG_REJECT_MEAS_SG_ACTIVE) 953 { 954TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS_REJECT_MEAS_SG_ACTIVE!\n"); 955 } 956 957TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS NOK!!!\n"); 958 959 960 /* if a timer is running, stop it */ 961 if ( TI_TRUE == pMeasurementSRV->bStartStopTimerRunning ) 962 { 963TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "***** STOP TIMER 8 *****\n"); 964 tmr_StopTimer( pMeasurementSRV->hStartStopTimer ); 965 pMeasurementSRV->bStartStopTimerRunning = TI_FALSE; 966 } 967 for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ ) 968 { 969 if ( TI_TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] ) 970 { 971 tmr_StopTimer( pMeasurementSRV->hRequestTimer[ i ] ); 972 pMeasurementSRV->bRequestTimerRunning[ i ] = TI_FALSE; 973 } 974 } 975 976 measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), 977 MSR_SRV_EVENT_START_FAILURE ); 978 } 979} 980 981 982/** 983 * \author Ronen Kalish\n 984 * \date 23-December-2005\n 985 * \brief Handles a stop request when no stop is needed (SM is either idle or already send stop command to FW.\n 986 * 987 * Function Scope \e Private.\n 988 * \param hMeasurementSrv - handle to the measurement SRV object.\n 989 * \return always TI_OK.\n 990 */ 991TI_STATUS measurementSRVSRVSM_dummyStop( TI_HANDLE hMeasurementSrv ) 992{ 993 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSrv; 994 995 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_WARNING, ": sending unnecessary stop measurement command to FW...\n"); 996 997 /* send a stop command to FW, to obtain a different context in ehich to cal the command response CB */ 998 cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld, 999 (void *)pMeasurementSRV->commandResponseCBFunc, 1000 pMeasurementSRV->commandResponseCBObj); 1001 1002 pMeasurementSRV->commandResponseCBFunc = NULL; 1003 pMeasurementSRV->commandResponseCBObj = NULL; 1004 1005 return TI_OK; 1006} 1007 1008/** 1009 * \author Ronen Kalish\n 1010 * \date 17-November-2005\n 1011 * \brief Handles an unexpected event.\n 1012 * 1013 * Function Scope \e Private.\n 1014 * \param hMeasurementSrv - handle to the measurement SRV object.\n 1015 * \return always TI_OK.\n 1016 */ 1017TI_STATUS actionUnexpected( TI_HANDLE hMeasurementSrv ) 1018{ 1019 measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSrv; 1020 TI_INT32 i; 1021 1022 TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_SM, ": measurement SRV state machine error, unexpected Event\n"); 1023 1024 if (pMeasurementSRV->bStartStopTimerRunning) 1025 { 1026 tmr_StopTimer (pMeasurementSRV->hStartStopTimer); 1027 pMeasurementSRV->bStartStopTimerRunning = TI_FALSE; 1028 } 1029 1030 for (i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++) 1031 { 1032 if (pMeasurementSRV->bRequestTimerRunning[i]) 1033 { 1034 tmr_StopTimer (pMeasurementSRV->hRequestTimer[i]); 1035 pMeasurementSRV->bRequestTimerRunning[i] = TI_FALSE; 1036 } 1037 } 1038 1039 /* we must clean the old command response CB since they are no longer relevant 1040 since the state machine may be corrupted */ 1041 pMeasurementSRV->commandResponseCBFunc = NULL; 1042 pMeasurementSRV->commandResponseCBObj = NULL; 1043 1044 /* indicate the unexpected event in the return status */ 1045 pMeasurementSRV->returnStatus = TI_NOK; 1046 1047 return TI_OK; 1048} 1049 1050/** 1051 * \author Ronen Kalish\n 1052 * \date 10-Jan-2005\n 1053 * \brief Handles an event that doesn't require any action.\n 1054 * 1055 * Function Scope \e Private.\n 1056 * \param hMeasurementSrv - handle to the measurement SRV object.\n 1057 * \return always TI_OK.\n 1058 */ 1059TI_STATUS actionNop( TI_HANDLE hMeasurementSrv ) 1060{ 1061 return TI_OK; 1062} 1063 1064