1 /* 2 * ScanSrvSM.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 ScanSrvSM.c 35 * \brief This file include the scan SRV Sm implementation 36 * \author Ronen Kalish 37 * \date 10-Jan-2005 38 */ 39 40 #define __FILE_ID__ FILE_ID_116 41 #include "ScanSrvSM.h" 42 #include "ScanSrv.h" 43 #include "report.h" 44 #include "timer.h" 45 #include "MacServices_api.h" 46 #include "PowerSrv_API.h" 47 #include "CmdBld.h" 48 49 50 /********************************************************************************/ 51 /* Internal functions prototypes. */ 52 /********************************************************************************/ 53 54 static TI_STATUS scanSRVSM_PsFailWhileScanning( TI_HANDLE hScanSrv ); 55 static TI_STATUS actionNop( TI_HANDLE hScanSrv ); 56 static TI_STATUS actionUnexpected( TI_HANDLE hScanSrv ); 57 58 59 /********************************************************************************/ 60 /* Interface functions Implementation. */ 61 /********************************************************************************/ 62 63 64 /** 65 * \author Ronen Kalish\n 66 * \date 10-Jan-2005\n 67 * \brief Initialize the scan SRV SM. 68 * 69 * Function Scope \e Public.\n 70 * \param hScanSrv - handle to the scan SRV object.\n 71 * \return TI_OK if successful, TI_NOK otherwise.\n 72 */ 73 TI_STATUS scanSRVSM_init( TI_HANDLE hScanSrv ) 74 { 75 scanSRV_t* pScanSRV = (scanSRV_t*)hScanSrv; 76 77 fsm_actionCell_t smMatrix[ SCAN_SRV_NUM_OF_STATES ][ SCAN_SRV_NUM_OF_EVENTS ] = 78 { 79 /* next state and actions for IDLE state */ 80 { 81 {SCAN_SRV_STATE_PS_WAIT, scanSRVSM_requestPS}, /*"REQUEST_PS",*/ 82 {SCAN_SRV_STATE_IDLE, actionUnexpected}, /*"PS_FAIL",*/ 83 {SCAN_SRV_STATE_SCANNING, scanSRVSM_startActualScan}, /*"PS_SUCCESS", */ 84 {SCAN_SRV_STATE_IDLE, actionUnexpected}, /*"PS_PEND",*/ 85 {SCAN_SRV_STATE_IDLE, actionUnexpected}, /*"STOP_SCAN"*/ 86 {SCAN_SRV_STATE_IDLE, actionNop}, /*"FW_RESET"*/ 87 {SCAN_SRV_STATE_IDLE, actionUnexpected}, /*"TIMER_EXPIRED"*/ 88 {SCAN_SRV_STATE_IDLE, actionUnexpected}, /*"SCAN_COMPLETE"*/ 89 }, 90 91 92 /* next state and actions for PS_WAIT state */ 93 { 94 {SCAN_SRV_STATE_PS_WAIT, actionUnexpected}, /*"REQUEST_PS",*/ 95 {SCAN_SRV_STATE_PS_EXIT, scanSRVSM_releasePS}, /*"PS_FAIL",*/ 96 {SCAN_SRV_STATE_SCANNING, scanSRVSM_startActualScan}, /*"PS_SUCCESS", */ 97 {SCAN_SRV_STATE_PS_WAIT, actionNop}, /*"PS_PEND",*/ 98 {SCAN_SRV_STATE_STOPPING, actionNop}, /*"STOP_SCAN"*/ 99 {SCAN_SRV_STATE_IDLE, scanSRVSM_handleRecovery}, /*"FW_RESET"*/ 100 {SCAN_SRV_STATE_PS_WAIT, actionUnexpected}, /*"TIMER_EXPIRED"*/ 101 {SCAN_SRV_STATE_PS_WAIT, actionUnexpected}, /*"SCAN_COMPLETE"*/ 102 }, 103 104 /* next state and actions for SCANNING state */ 105 { 106 {SCAN_SRV_STATE_SCANNING, actionUnexpected}, /*"REQUEST_PS",*/ 107 {SCAN_SRV_STATE_SCANNING, scanSRVSM_PsFailWhileScanning}, /*"PS_FAIL",*/ 108 {SCAN_SRV_STATE_SCANNING, actionUnexpected}, /*"PS_SUCCESS", */ 109 {SCAN_SRV_STATE_SCANNING, actionUnexpected}, /*"PS_PEND",*/ 110 {SCAN_SRV_STATE_STOPPING, actionNop }, /*"STOP_SCAN"*/ 111 {SCAN_SRV_STATE_IDLE, scanSRVSM_handleRecovery}, /*"FW_RESET"*/ 112 {SCAN_SRV_STATE_SCANNING, scanSRVSM_handleTimerExpiry}, /*"TIMER_EXPIRED"*/ 113 {SCAN_SRV_STATE_PS_EXIT, scanSRVSM_releasePS}, /*"SCAN_COMPLETE"*/ 114 115 }, 116 117 /* next state and actions for STOPPING state */ 118 { 119 {SCAN_SRV_STATE_STOPPING, actionUnexpected}, /*"REQUEST_PS",*/ 120 {SCAN_SRV_STATE_PS_EXIT, scanSRVSM_releasePS}, /*"PS_FAIL",*/ 121 {SCAN_SRV_STATE_PS_EXIT, scanSRVSM_releasePS}, /*"PS_SUCCESS", */ 122 {SCAN_SRV_STATE_STOPPING, actionUnexpected}, /*"PS_PEND",*/ 123 {SCAN_SRV_STATE_STOPPING, actionNop }, /*"STOP_SCAN"*/ 124 {SCAN_SRV_STATE_IDLE, scanSRVSM_handleRecovery}, /*"FW_RESET"*/ 125 {SCAN_SRV_STATE_STOPPING, scanSRVSM_handleTimerExpiry}, /*"TIMER_EXPIRED"*/ 126 {SCAN_SRV_STATE_PS_EXIT, scanSRVSM_releasePS} /*"SCAN_COMPLETE"*/ 127 128 } , 129 130 /* next state and actions for PS_EXIT state */ 131 { 132 {SCAN_SRV_STATE_PS_EXIT, actionUnexpected}, /*"REQUEST_PS",*/ 133 {SCAN_SRV_STATE_IDLE, scanSRVSM_notifyScanComplete}, /*"PS_FAIL",*/ 134 {SCAN_SRV_STATE_IDLE, scanSRVSM_notifyScanComplete}, /*"PS_SUCCESS", */ 135 {SCAN_SRV_STATE_PS_EXIT, actionNop}, /*"PS_PEND",*/ 136 {SCAN_SRV_STATE_PS_EXIT, actionNop}, /*"STOP_SCAN"*/ 137 {SCAN_SRV_STATE_IDLE, scanSRVSM_handleRecovery}, /*"FW_RESET"*/ 138 {SCAN_SRV_STATE_PS_EXIT, actionUnexpected}, /*"TIMER_EXPIRED"*/ 139 {SCAN_SRV_STATE_PS_EXIT, actionUnexpected}, /*"SCAN_COMPLETE"*/ 140 } 141 }; 142 143 /* initialize current state */ 144 pScanSRV->SMState = SCAN_SRV_STATE_IDLE; 145 146 /* configure the state machine */ 147 return fsm_Config( pScanSRV->SM, (fsm_Matrix_t)smMatrix, 148 (TI_UINT8)SCAN_SRV_NUM_OF_STATES, (TI_UINT8)SCAN_SRV_NUM_OF_EVENTS, 149 (fsm_eventActivation_t)scanSRVSM_SMEvent, pScanSRV->hOS ); 150 } 151 152 /** 153 * \author Ronen Kalish\n 154 * \date 10-Jan-2005\n 155 * \brief Processes an event. 156 * 157 * Function Scope \e Public.\n 158 * \param hScanSrv - handle to the scan SRV object.\n 159 * \param currentState - the current scan SRV SM state.\n 160 * \param event - the event to handle.\n 161 * \return TI_OK if successful, TI_NOK otherwise.\n 162 */ 163 TI_STATUS scanSRVSM_SMEvent( TI_HANDLE hScanSrv, scan_SRVSMStates_e* currentState, 164 scan_SRVSMEvents_e event ) 165 { 166 scanSRV_t *pScanSRV = (scanSRV_t *)hScanSrv; 167 TI_STATUS status = TI_OK; 168 TI_UINT8 nextState; 169 170 /* obtain the next state */ 171 status = fsm_GetNextState( pScanSRV->SM, *(TI_UINT8*)currentState, (TI_UINT8)event, &nextState ); 172 if ( status != TI_OK ) 173 { 174 TRACE2(pScanSRV->hReport, REPORT_SEVERITY_ERROR, "Failed getting scan SRV next state. state = %d event = %d\n", (TI_UINT8)*currentState,(TI_UINT8)event); 175 return TI_NOK; 176 } 177 178 TRACE3(pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "scanSRVSM_SMEvent: <currentState = %d, event = %d> --> nextState = %d\n", *currentState, event, nextState); 179 180 /* move */ 181 return fsm_Event( pScanSRV->SM, (TI_UINT8*)currentState, (TI_UINT8)event, hScanSrv ); 182 } 183 184 /** 185 * \author Ronen Kalish\n 186 * \date 10-Jan-2005\n 187 * \brief Request to enter driver mode from the power manager module.\n 188 * 189 * Function Scope \e Private.\n 190 * \param hScanSrv - handle to the scan SRV object.\n 191 * \return TI_OK if successful, TI_NOK otherwise.\n 192 */ 193 TI_STATUS scanSRVSM_requestPS( TI_HANDLE hScanSrv ) 194 { 195 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 196 TI_STATUS psStatus; 197 198 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Requesting Driver mode from PowerSave Srv.\n"); 199 200 psStatus = powerSrv_ReservePS( pScanSRV->hPowerSrv, 201 pScanSRV->psRequest, 202 pScanSRV->bSendNullData, 203 hScanSrv, 204 MacServices_scanSRV_powerSaveCB); 205 206 switch (psStatus) 207 { 208 /* if successful */ 209 case POWER_SAVE_802_11_IS_CURRENT: 210 /* send a PS_SUCCESS event */ 211 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Driver mode successful, continuing to scan.\n"); 212 return scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_SUCCESS ); 213 214 /* if pending */ 215 case POWER_SAVE_802_11_PENDING: 216 case TI_OK: 217 /* send a PS_PEND event */ 218 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Driver mode pending, Waiting.\n"); 219 return scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_PEND ); 220 221 /* if not successful */ 222 default: 223 224 /* mark not to exit from driver mode (no entry was performed) */ 225 pScanSRV->bExitFromDriverMode = TI_FALSE; 226 227 /* if still wishing to scan */ 228 if ( pScanSRV->bScanOnDriverModeFailure ) 229 { 230 /* send a PS_SUCCESS event - scan will proceed regardless of the error */ 231 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Driver mode failed, continuing to scan.\n"); 232 scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_SUCCESS ); 233 } 234 /* otherwise, return */ 235 else 236 { 237 /* mark the return code */ 238 pScanSRV->returnStatus = TI_NOK; 239 /* send a PS_FAIL event */ 240 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Driver mode failed, aborting scan.\n"); 241 scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_FAIL ); 242 } 243 break; 244 } 245 246 return TI_OK; 247 } 248 249 /** 250 * \author Yuval Adler\n 251 * \date 6-Oct-2005\n 252 * \brief Request to release PS mode from the PowerSRV , and wait for answer.\n\n 253 * 254 * Function Scope \e Private.\n 255 * \param hScanSrv - handle to the scan SRV object.\n 256 * \return TI_OK if successful, TI_NOK otherwise.\n 257 */ 258 259 TI_STATUS scanSRVSM_releasePS( TI_HANDLE hScanSrv ) 260 { 261 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 262 TI_STATUS psStatus; 263 264 /* stop timer */ 265 if ( TI_TRUE == pScanSRV->bTimerRunning ) 266 { 267 tmr_StopTimer (pScanSRV->hScanSrvTimer); 268 pScanSRV->bTimerRunning = TI_FALSE; 269 } 270 271 /* if exit from driver mode requested, do so */ 272 if ( TI_TRUE == pScanSRV->bExitFromDriverMode ) 273 { 274 /* here we need to get an answer if we succeeded to exit driver mode */ 275 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Releasing Driver mode from Power Srv.\n"); 276 277 psStatus = powerSrv_ReleasePS( pScanSRV->hPowerSrv, 278 pScanSRV->bSendNullData, 279 hScanSrv, 280 MacServices_scanSRV_powerSaveCB); 281 282 283 } 284 else /* no need to exit PS - send PS_SUCCESS */ 285 { 286 return scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_SUCCESS ); 287 } 288 289 290 switch (psStatus) 291 { 292 /* if successful */ 293 case POWER_SAVE_802_11_IS_CURRENT: 294 /* send a PS_SUCCESS event */ 295 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode exit successful, scan done.\n"); 296 return scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_SUCCESS ); 297 298 /* if pending */ 299 case POWER_SAVE_802_11_PENDING: 300 case TI_OK: 301 /* stay in the PS_EXIT state */ 302 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode exit pending, Waiting.\n"); 303 break; 304 305 /* if not successful */ 306 default: 307 308 /* send a PS_FAIL event */ 309 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode exit failed, scan done."); 310 return scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_PS_FAIL ); 311 312 } 313 314 return TI_OK; 315 } 316 317 /** 318 * \author Ronen Kalish\n 319 * \date 10-Jan-2005\n 320 * \brief Send the scan command to the firmware.\n 321 * 322 * Function Scope \e Private.\n 323 * \param hScanSrv - handle to the scan SRV object.\n 324 * \return TI_OK if successful, TI_NOK otherwise.\n 325 */ 326 TI_STATUS scanSRVSM_startActualScan( TI_HANDLE hScanSrv ) 327 { 328 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 329 330 331 /* start the timer */ 332 pScanSRV->bTimerRunning = TI_TRUE; 333 tmr_StartTimer (pScanSRV->hScanSrvTimer, 334 MacServices_scanSRV_scanTimerExpired, 335 (TI_HANDLE)pScanSRV, 336 MacServices_scanSRVcalculateScanTimeout (hScanSrv, pScanSRV->scanParams, !pScanSRV->bDtimOverlapping), 337 TI_FALSE); 338 339 TRACE1( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "Sending scan , type: %x to HAL.\n",pScanSRV->scanParams->scanType); 340 341 /* start the scan */ 342 /* we send the MacServices_scanSRVCommandMailBoxCB to be called when this command is recieved */ 343 if ( SCAN_TYPE_SPS == pScanSRV->scanParams->scanType ) 344 { 345 pScanSRV->returnStatus = cmdBld_CmdStartSPSScan (pScanSRV->hCmdBld, pScanSRV->scanParams, pScanSRV->eScanTag, 346 (void *)MacServices_scanSRVCommandMailBoxCB, hScanSrv); 347 } 348 else 349 { 350 pScanSRV->returnStatus = cmdBld_CmdStartScan (pScanSRV->hCmdBld, pScanSRV->scanParams, pScanSRV->eScanTag, 351 pScanSRV->bHighPriority , (void *)MacServices_scanSRVCommandMailBoxCB, 352 hScanSrv); 353 } 354 /* if scan request failed */ 355 if ( TI_OK != pScanSRV->returnStatus ) 356 { 357 TRACE1( pScanSRV->hReport, REPORT_SEVERITY_ERROR, "HAL returned code %d for scan request, quitting scan.\n", pScanSRV->returnStatus); 358 359 /* send a scan complete event. This will do all necessary clean-up (timer, power manager, notifying scan complete) */ 360 scanSRVSM_SMEvent( hScanSrv, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_SCAN_COMPLETE ); 361 } 362 363 return TI_OK; 364 } 365 366 367 /** 368 * \author Ronen Kalish\n 369 * \date 10-Jan-2005\n 370 * \brief Notifies scan complete to upper layer.\n 371 * 372 * Function Scope \e Private.\n 373 * \param hScanSrv - handle to the scan SRV object.\n 374 * \return TI_OK if successful, TI_NOK otherwise.\n 375 */ 376 TI_STATUS scanSRVSM_notifyScanComplete( TI_HANDLE hScanSrv ) 377 { 378 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 379 TCmdResponseCb CB_Func; 380 TI_HANDLE CB_Handle; 381 TI_STATUS PSMode; 382 383 /* call the scan complete CB - only if not currently running from within a request context! */ 384 if ( TI_FALSE == pScanSRV->bInRequest ) 385 { 386 /* this means that ResponseFunc was not called yet , so we call it before ScanComplete */ 387 if (pScanSRV->commandResponseFunc) 388 { 389 /* must erase CB function before calling it to enable nested scans */ 390 CB_Func = pScanSRV->commandResponseFunc; 391 CB_Handle = pScanSRV->commandResponseObj; 392 393 pScanSRV->commandResponseFunc = NULL; 394 pScanSRV->commandResponseObj = NULL; 395 396 /* if we reached here than response status was TI_OK */ 397 CB_Func(CB_Handle, TI_OK); 398 399 } 400 /* if function returns TI_TRUE than we are in PS mode , else - not */ 401 PSMode = powerSrv_getPsStatus(pScanSRV->hPowerSrv) ? POWER_SAVE_802_11_SUCCESS : POWER_SAVE_802_11_FAIL; 402 403 TRACE2( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "scanSRVSM_notifyScanComplete status = 0x%x PSMode = 0x%x\n",pScanSRV->returnStatus,PSMode); 404 405 406 TRACE0(pScanSRV->hReport, REPORT_SEVERITY_INFORMATION , "scanSRVSM_notifyScanComplete: call TWD_OWN_EVENT_SCAN_CMPLT CB. In std MacServices_scanSRV_scanCompleteCB()\n"); 407 408 pScanSRV->scanCompleteNotificationFunc( pScanSRV->scanCompleteNotificationObj, 409 pScanSRV->eScanTag, 410 pScanSRV->uResultCount, 411 pScanSRV->SPSScanResult, 412 pScanSRV->bTSFError, 413 pScanSRV->returnStatus, 414 PSMode ); 415 } 416 417 return TI_OK; 418 } 419 420 421 /** 422 * \author Ronen Kalish\n 423 * \date 10-Jan-2005\n 424 * \brief Handles a timer expiry event - starts a recovery process. 425 * 426 * Function Scope \e Private.\n 427 * \param hScanSrv - handle to the scan SRV object.\n 428 * \return TI_OK if successful, TI_NOK otherwise.\n 429 */ 430 TI_STATUS scanSRVSM_handleTimerExpiry( TI_HANDLE hScanSrv ) 431 { 432 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 433 434 /* 435 * No scan complete bug workaround: 436 * Only after a consecutive configurable number of no scan complete events the recovery trigger 437 * will be issued. This is done as a workaround for a bug in the FW where if a channel is too 438 * loaded it wouldn't be able to send a probe request and will get stuck waiting for this channel 439 */ 440 441 pScanSRV->currentNumberOfConsecutiveNoScanCompleteEvents++; 442 443 if ( pScanSRV->currentNumberOfConsecutiveNoScanCompleteEvents >= 444 pScanSRV->numberOfNoScanCompleteToRecovery ) 445 { 446 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_ERROR, ": Timer expired. Starting recovery process.\n"); 447 448 pScanSRV->currentNumberOfConsecutiveNoScanCompleteEvents = 0; 449 450 /* mark the return status */ 451 pScanSRV->returnStatus = TI_NOK; 452 453 /* mark that the timer is no longer running */ 454 pScanSRV->bTimerRunning = TI_FALSE; 455 456 /* call the recovery module */ 457 pScanSRV->failureEventFunc(pScanSRV->failureEventObj ,NO_SCAN_COMPLETE_FAILURE); 458 } 459 else 460 { 461 TRACE2( pScanSRV->hReport, REPORT_SEVERITY_ERROR, ": Timer expired. consecutive failures:%d, threshold:%d, still not calling recovery.\n", pScanSRV->currentNumberOfConsecutiveNoScanCompleteEvents, pScanSRV->numberOfNoScanCompleteToRecovery); 462 463 /* send a top scan command, which can help solving the FW bug described above */ 464 if ( TI_FALSE == pScanSRV->bSPSScan ) 465 { 466 cmdBld_CmdStopScan (pScanSRV->hCmdBld, pScanSRV->eScanTag, NULL, NULL); 467 } 468 else 469 { 470 cmdBld_CmdStopSPSScan (pScanSRV->hCmdBld, pScanSRV->eScanTag, NULL, NULL); 471 } 472 473 /* imitate a scan complete event to the SM */ 474 pScanSRV->bTSFError = TI_FALSE; 475 pScanSRV->SPSScanResult = 0xffff; 476 scanSRVSM_SMEvent( (TI_HANDLE)pScanSRV, (scan_SRVSMStates_e*)&pScanSRV->SMState, SCAN_SRV_EVENT_SCAN_COMPLETE ); 477 } 478 479 return TI_OK; 480 } 481 482 /** 483 * \author Shirit Brook\n 484 * \date 10-Jan-2005\n 485 * \brief Handles PS Fail event while in Scanning - Indicate not to Exit PS. 486 * This event can be reached when Roaming is invoked while in Scanning state. 487 * The PM Module is stopped and generates PS Fail to all its clients. 488 * 489 * Function Scope \e Private.\n 490 * \param hScanSrv - handle to the scan SRV object.\n 491 * \return TI_OK if successful, TI_NOK otherwise.\n 492 */ 493 static TI_STATUS scanSRVSM_PsFailWhileScanning( TI_HANDLE hScanSrv ) 494 { 495 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 496 497 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "scanSRVSM_PsFailWhileScanning. Indicate not to Enter PS.\n"); 498 499 pScanSRV->bExitFromDriverMode = TI_FALSE; 500 501 return TI_OK; 502 } 503 504 505 /** 506 * \author Ronen Kalish\n 507 * \date 17-Jan-2005\n 508 * \brief Handles a FW reset event (one that was detected outside the scan SRV) by stopping the timer. 509 * 510 * Function Scope \e Private.\n 511 * \param hScanSrv - handle to the scan SRV object.\n 512 * \return TI_OK if successful, TI_NOK otherwise.\n 513 */ 514 TI_STATUS scanSRVSM_handleRecovery( TI_HANDLE hScanSrv ) 515 { 516 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 517 518 TRACE0( pScanSRV->hReport, REPORT_SEVERITY_INFORMATION, "FW reset event from outside.\n"); 519 520 /* The Power Manager is responsible to exit PS mode in recovery. Also, the scan CB is not called - 521 The SCR is responsible to notify scan concentrator of the event (which actually notifies scan SRV */ 522 523 /* if timer is running - stop it */ 524 if ( TI_TRUE == pScanSRV->bTimerRunning ) 525 { 526 tmr_StopTimer (pScanSRV->hScanSrvTimer); 527 pScanSRV->bTimerRunning = TI_FALSE; 528 } 529 else 530 { 531 /* shouldn't happen - only called if timer is supposedly running */ 532 TRACE1( pScanSRV->hReport, REPORT_SEVERITY_WARNING, "SM: External FW reset in state %d and timer is not running?", pScanSRV->SMState); 533 } 534 535 return TI_OK; 536 } 537 538 /** 539 * \author Ronen Kalish\n 540 * \date 11-Jan-2005\n 541 * \brief Handles an unexpected event.\n 542 * 543 * Function Scope \e Private.\n 544 * \param hScanSrv - handle to the scan SRV object.\n 545 * \return always TI_OK.\n 546 */ 547 static TI_STATUS actionUnexpected( TI_HANDLE hScanSrv ) 548 { 549 scanSRV_t *pScanSRV = (scanSRV_t*)hScanSrv; 550 551 TRACE1( pScanSRV->hReport, REPORT_SEVERITY_ERROR, "Scan SRV state machine error, unexpected Event, state=%d\n\n", pScanSRV->SMState); 552 553 if ( pScanSRV->bTimerRunning ) 554 { 555 tmr_StopTimer (pScanSRV->hScanSrvTimer); 556 pScanSRV->bTimerRunning = TI_FALSE; 557 } 558 559 /* we must clean the old command response CB since they are no longer relevant 560 since the state machine may be corrupted */ 561 pScanSRV->commandResponseFunc = NULL; 562 pScanSRV->commandResponseObj = NULL; 563 564 /* indicate the unexpected event in the return status */ 565 pScanSRV->returnStatus = TI_NOK; 566 567 return TI_OK; 568 } 569 570 /** 571 * \author Ronen Kalish\n 572 * \date 10-Jan-2005\n 573 * \brief Handles an event that doesn't require any action.\n 574 * 575 * Function Scope \e Private.\n 576 * \param hScanSrv - handle to the scan SRV object.\n 577 * \return always TI_OK.\n 578 */ 579 static TI_STATUS actionNop( TI_HANDLE hScanSrv ) 580 { 581 return TI_OK; 582 } 583 584 585