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