/**
 * \\n
 * \date 09-November-2005\n
 * \brief callback function used by the power manager to notify driver mode result
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param PSMode - the power save mode the STA is currently in.\n
 * \param psStatus - the power save request status.\n
 */
void MacServices_measurementSRV_powerSaveCB( TI_HANDLE hMeasurementSRV, TI_UINT8 PSMode, TI_UINT8 psStatus )
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;

    TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Power save SRV CB called. PS mode:%d status: %d\n", PSMode, psStatus);

    /* if driver mode entry succeedded */
    if ( ENTER_POWER_SAVE_SUCCESS == psStatus )
    {
        TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": PS successful.\n");

        /* send a RIVER_MODE_SUCCESS event */
        measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_DRIVER_MODE_SUCCESS );
    }
    /* driver mode entry failed */
    else
    {
        TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": PS failed, status %d.\n", psStatus);

        /* Set the return status to TI_NOK */
        pMeasurementSRV->returnStatus = (TI_STATUS)psStatus;

        /* send a DRIVER_MODE_FAILURE event */
        measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_DRIVER_MODE_FAILURE );
    }
}
/** 
 * \\n
 * \date 09-November-2005\n
 * \brief callback function used by the power manager to notify driver mode result
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param PSMode - the power save mode the STA is currently in.\n
 * \param psStatus - the power save request status.\n
 */
void MacServices_measurementSRV_powerSaveCB( TI_HANDLE hMeasurementSRV, TI_UINT8 PSMode, TI_UINT8 psStatus )
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;


	/* if driver mode entry succeedded */
    if ( ENTER_POWER_SAVE_SUCCESS == psStatus )
    {

        /* send a RIVER_MODE_SUCCESS event */
        measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 
                                  MSR_SRV_EVENT_DRIVER_MODE_SUCCESS );
    }
    /* driver mode entry failed */
    else
    {

        /* Set the return status to TI_NOK */
        pMeasurementSRV->returnStatus = (TI_STATUS)psStatus;

        /* send a DRIVER_MODE_FAILURE event */
        measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState), 
								  MSR_SRV_EVENT_DRIVER_MODE_FAILURE );
    }
}
/**
 * \\n
 * \date 08-November-2005\n
 * \brief Handle a MEASURE_START_REQUEST event by requesting driver mode.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_requestDriverMode( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t    *pMeasurementSRV  = (measurementSRV_t*)hMeasurementSRV;
	TI_STATUS           PSStatus;
	TTwdParamInfo       paramInfo;

	/* get the current channel */
	paramInfo.paramType = TWD_CURRENT_CHANNEL_PARAM_ID;
	cmdBld_GetParam (pMeasurementSRV->hCmdBld, &paramInfo);

	/* check if the request is on the serving channel */
	if ( paramInfo.content.halCtrlCurrentChannel == pMeasurementSRV->msrRequest.channel )
	{
		/* Switch Power Save SRV to driver mode w/o changing power save mode*/
		PSStatus = powerSrv_ReservePS( pMeasurementSRV->hPowerSaveSRV, POWER_SAVE_KEEP_CURRENT,
		                               TI_TRUE, hMeasurementSRV, MacServices_measurementSRV_powerSaveCB );
	}
	else
	{
		/* Switch Power Save SRV to driver mode with PS mode */
		PSStatus = powerSrv_ReservePS( pMeasurementSRV->hPowerSaveSRV, POWER_SAVE_ON,
		                               TI_TRUE, hMeasurementSRV, MacServices_measurementSRV_powerSaveCB );
	}

	switch (PSStatus)
	{
	case POWER_SAVE_802_11_IS_CURRENT:
		TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode entered successfully\n");
		/* send a power save success event */
		return measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                                 MSR_SRV_EVENT_DRIVER_MODE_SUCCESS );

	case POWER_SAVE_802_11_PENDING:
	case TI_OK:
		TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Driver mode pending\n");
		break;

	default: /* Error */
		TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Error %d when requesting driver mode\n",PSStatus);

		/* Set the return status to TI_NOK */
		pMeasurementSRV->returnStatus = PSStatus;

		/* send a power save failure event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_DRIVER_MODE_FAILURE );
		break;
	}

	return TI_OK;
}
/**
 * \\n
 * \date 09-November-2005\n
 * \brief Stops a measurement operation in progress.\n
 *
 * Function Scope \e Public.\n
 * \param hMacServices - handle to the MacServices object.\n
 * \param bSendNullData - whether to send NULL data when exiting driver mode.\n
 * \param cmdResponseCBFunc - callback function to used for command response.\n
 * \param cmdResponseCBObj - handle to pass to command response CB.\n
 * \return TI_OK if successful (various, TBD codes if not).\n
 */
TI_STATUS MacServices_measurementSRV_stopMeasurement( TI_HANDLE hMacServices,
        TI_BOOL bSendNullData,
        TCmdResponseCb cmdResponseCBFunc,
        TI_HANDLE cmdResponseCBObj )
{
	measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV;


	/* store callbacks */
	pMeasurementSRV->commandResponseCBFunc = cmdResponseCBFunc;
	pMeasurementSRV->commandResponseCBObj = cmdResponseCBObj;

	/* store NULL data indication */
	pMeasurementSRV->bSendNullDataWhenExitPs = bSendNullData;

	/* mark that current return status is TI_OK */
	pMeasurementSRV->returnStatus = TI_OK;

	/* mark that a stop request is in progress */
	pMeasurementSRV->bInRequest = TI_TRUE;

	/* send a stop event to the SM */
	measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState),
	                          MSR_SRV_EVENT_MEASURE_STOP_REQUEST );

	/*mark that stop request has completed */
	pMeasurementSRV->bInRequest = TI_FALSE;

	return pMeasurementSRV->returnStatus;
}
/**
 * \\n
 * \date 09-November-2005\n
 * \brief Stops a measurement operation in progress.\n
 *
 * Function Scope \e Public.\n
 * \param hMacServices - handle to the MacServices object.\n
 * \param bSendNullData - whether to send NULL data when exiting driver mode.\n
 * \param cmdResponseCBFunc - callback function to used for command response.\n
 * \param cmdResponseCBObj - handle to pass to command response CB.\n
 * \return TI_OK if successful (various, TBD codes if not).\n
 */
TI_STATUS MacServices_measurementSRV_stopMeasurement( TI_HANDLE hMacServices,
        TI_BOOL bSendNullData,
        TCmdResponseCb cmdResponseCBFunc,
        TI_HANDLE cmdResponseCBObj )
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV;

    TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Received measurement stop request.\n");
    TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "Send null data:, cmd response CB: 0x%x, cmd response handle: 0x%x\n",							  cmdResponseCBFunc,							  cmdResponseCBObj);

    /* store callbacks */
    pMeasurementSRV->commandResponseCBFunc = cmdResponseCBFunc;
    pMeasurementSRV->commandResponseCBObj = cmdResponseCBObj;

    /* store NULL data indication */
    pMeasurementSRV->bSendNullDataWhenExitPs = bSendNullData;

    /* mark that current return status is TI_OK */
    pMeasurementSRV->returnStatus = TI_OK;

    /* mark that a stop request is in progress */
    pMeasurementSRV->bInRequest = TI_TRUE;

    /* send a stop event to the SM */
    measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState),
                              MSR_SRV_EVENT_MEASURE_STOP_REQUEST );

    /*mark that stop request has completed */
    pMeasurementSRV->bInRequest = TI_FALSE;

    return pMeasurementSRV->returnStatus;
}
/**
 * \\n
 * \date 09-November-2005\n
 * \brief Starts a measurement operation.\n
 *
 * Function Scope \e Public.\n
 * \param hMacServices - handle to the MacServices object.\n
 * \param pMsrRequest - a structure containing measurement parameters.\n
 * \param timeToRequestexpiryMs - the time (in milliseconds) the measurement SRV has to start the request.\n
 * \param cmdResponseCBFunc - callback function to used for command response.\n
 * \param cmdResponseCBObj - handle to pass to command response CB.\n
 * \param cmdCompleteCBFunc - callback function to be used for command complete.\n
 * \param cmdCompleteCBObj - handle to pass to command complete CB.\n
 * \return TI_OK if successful (various, TBD codes if not).\n
 */
TI_STATUS MacServices_measurementSRV_startMeasurement( TI_HANDLE hMacServices,
        TMeasurementRequest* pMsrRequest,
        TI_UINT32 timeToRequestExpiryMs,
        TCmdResponseCb cmdResponseCBFunc,
        TI_HANDLE cmdResponseCBObj,
        TMeasurementSrvCompleteCb cmdCompleteCBFunc,
        TI_HANDLE cmdCompleteCBObj )
{
	measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)((MacServices_t*)hMacServices)->hMeasurementSRV;
	TI_INT32 i;

#ifdef TI_DBG
	measurementSRVPrintRequest( (TI_HANDLE)pMeasurementSRV, pMsrRequest );
#endif

	/* mark that request is in progress */
	pMeasurementSRV->bInRequest = TI_TRUE;

	/* mark to send NULL data when exiting driver mode (can be changed to TI_FALSE
	   only when explictly stopping the measurement */
	pMeasurementSRV->bSendNullDataWhenExitPs = TI_TRUE;

	/* Nullify return status */
	pMeasurementSRV->returnStatus = TI_OK;

	/* copy request parameters */
	os_memoryCopy (pMeasurementSRV->hOS,
	               (void *)&pMeasurementSRV->msrRequest,
	               (void *)pMsrRequest,
	               sizeof(TMeasurementRequest));

	/* Mark the current time stamp and the duration to start to cehck expiry later */
	pMeasurementSRV->requestRecptionTimeStampMs = os_timeStampMs( pMeasurementSRV->hOS );
	pMeasurementSRV->timeToRequestExpiryMs = timeToRequestExpiryMs;

	/* copy callbacks */
	pMeasurementSRV->commandResponseCBFunc = cmdResponseCBFunc;
	pMeasurementSRV->commandResponseCBObj = cmdResponseCBObj;
	pMeasurementSRV->measurmentCompleteCBFunc = cmdCompleteCBFunc;
	pMeasurementSRV->measurementCompleteCBObj = cmdCompleteCBObj;

	/* initialize reply */
	pMeasurementSRV->msrReply.numberOfTypes = pMsrRequest->numberOfTypes;
	for ( i = 0; i < pMsrRequest->numberOfTypes; i++ ) {
		pMeasurementSRV->msrReply.msrTypes[ i ].msrType = pMeasurementSRV->msrRequest.msrTypes[ i ].msrType;
		pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_OK;
	}

	/* nullify the pending CBs bitmap */
	pMeasurementSRV->pendingParamCBs = 0;

	/* send a start measurement event to the SM */
	measurementSRVSM_SMEvent( (TI_HANDLE)pMeasurementSRV, &(pMeasurementSRV->SMState),
	                          MSR_SRV_EVENT_MEASURE_START_REQUEST );

	/* mark that request has been sent */
	pMeasurementSRV->bInRequest = TI_FALSE;

	return pMeasurementSRV->returnStatus;
}
/**
 * \\n
 * \date 16-November-2005\n
 * \brief Callback for noise histogram get param call.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param status - the get_param call status.\n
 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object)
 */
void MacServices_measurementSRV_noiseHistCallBack( TI_HANDLE hMeasurementSRV, TI_STATUS status,
        TI_UINT8* CB_buf )
{
	measurementSRV_t		    *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TI_UINT8		                index;
	TI_UINT32                      sumOfSamples;
	TI_INT32							requestIndex;


	/* setting Off the Waitng for noise histogram Results Bit */
	pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_NOISE_HIST_RESULTS;

	/* find the request index */
	requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT );
	if ( -1 == requestIndex ) {
		/* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */
		return;
	}

	if ( TI_OK == status ) {
		sumOfSamples = pMeasurementSRV->noiseHistogramResults.numOfLostCycles;

		/* Print For Debug */

		for ( index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++ ) {
			sumOfSamples += pMeasurementSRV->noiseHistogramResults.counters[ index ];

			/* Print For Debug */
		}

		/* If there weren't enough samples --> Reject the Request */
		if ( (sumOfSamples - pMeasurementSRV->noiseHistogramResults.numOfLostCycles) <
		        NOISE_HISTOGRAM_THRESHOLD ) {

			/* set negative result status */
			pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
		} else {
			for (index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++) {
				pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ index ] =
				    ( 255 * pMeasurementSRV->noiseHistogramResults.counters[ index ]) / sumOfSamples;
			}

		}
	} else {
		/* set negative result status */
		pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
	}

	/* if no measurement are running and no CBs are pending,
	   send ALL TYPES COMPLETE event */
	if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV )) {
		/* send the event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
	}
}
/**
 * \\n
 * \date 14-November-2005\n
 * \brief callback function used by the HAL for measure stop event (sent when the FW
 * has finished measurement operation, i.e. switched channel to serving channel and changed back RX filters).\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 */
void MacServices_measurementSRV_measureCompleteCB( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;


	/* stop the FW guard timer */
	tmr_StopTimer (pMeasurementSRV->hStartStopTimer);
	pMeasurementSRV->bStartStopTimerRunning = TI_FALSE;

	measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
	                          MSR_SRV_EVENT_STOP_COMPLETE );
}
/**
 * \\n
 * \date 16-November-2005\n
 * \brief Callback for channel load get param call.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param status - the get_param call status.\n
 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object)
 */
void MacServices_measurementSRV_channelLoadParamCB( TI_HANDLE hMeasurementSRV, TI_STATUS status,
        TI_UINT8* CB_buf )
{
	measurementSRV_t	    *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TI_UINT32                  mediumUsageInMs, periodInMs;
	TI_INT32 					requestIndex;

	/* when this CB is called as a result of the nulify call at the measurement beginning,
	   the handle will be NULL. In this case, nothing needs to be done. */
	if ( NULL == hMeasurementSRV ) {
		return;
	}

	/* setting Off the Waitng for Channel Load Results Bit */
	pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_CHANNEL_LOAD_RESULTS;

	/* find the request index */
	requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_CCA_LOAD_MEASUREMENT );
	if ( -1 == requestIndex ) {
		/* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */
		return;
	}

	if ( (TI_OK == status) && (0 != pMeasurementSRV->mediumOccupancyResults.Period)) {
		/* calculate results */
		mediumUsageInMs = pMeasurementSRV->mediumOccupancyResults.MediumUsage / 1000;
		periodInMs      = pMeasurementSRV->mediumOccupancyResults.Period / 1000;


		if ( periodInMs <= pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration ) {
			pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction =
			    ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) /
			    pMeasurementSRV->mediumOccupancyResults.Period;
		} else {
			pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction =
			    ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) /
			    (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration * 1000);
		}
	} else {

		/* mark result status */
		pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
	}

	/* if no measurement are running and no CBs are pending,
	   send ALL TYPES COMPLETE event */
	if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV )) {
		/* send the event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
	}
}
/**
 * \\n
 * \date 14-November-2005\n
 * \brief callback function used by the HAL for measure stop event (sent when the FW
 * has finished measurement operation, i.e. switched channel to serving channel and changed back RX filters).\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 */
void MacServices_measurementSRV_measureCompleteCB( TI_HANDLE hMeasurementSRV )
{
    measurementSRV_t *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;

    TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure complete CB called.\n");

    /* stop the FW guard timer */
    tmr_StopTimer (pMeasurementSRV->hStartStopTimer);
    pMeasurementSRV->bStartStopTimerRunning = TI_FALSE;

    measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                              MSR_SRV_EVENT_STOP_COMPLETE );
}
/**
 * \\n
 * \date 15-November-2005\n
 * \brief called when a measurement type timer expires.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasuremntSRV - handle to the measurement SRV object.\n
 * \param bTwdInitOccured -   Indicates if TWDriver recovery occured since timer started.\n
 */
void MacServices_measurementSRV_requestTimerExpired (TI_HANDLE hMeasurementSRV, TI_BOOL bTwdInitOccured)
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
    TI_INT32 requestIndex;

    /* find the expired measurement type */
    requestIndex = measurementSRVFindMinDuration( hMeasurementSRV );
    if ( -1 == requestIndex )
    {
        /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */
        TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Request timer expired and request index from findMinDuration is -1?!?");
        return;
    }

    TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": request timer expired, request index: %d.\n", requestIndex);

    /* mark that the timer is not running and that this request has completed */
    pMeasurementSRV->bRequestTimerRunning[ requestIndex ] = TI_FALSE;

    /* collect results and send stop command if necessary */
    switch (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType)
    {
    case MSR_TYPE_BEACON_MEASUREMENT:
        measurementSRVHandleBeaconMsrComplete( hMeasurementSRV, requestIndex );
        break;

    case MSR_TYPE_CCA_LOAD_MEASUREMENT:
        measurementSRVHandleChannelLoadComplete( hMeasurementSRV, requestIndex );
        break;

    case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT:
        measurementSRVHandleNoiseHistogramComplete( hMeasurementSRV, requestIndex );
        break;

    /* used here to avoid compilation warning only, does nothing */
    case MSR_TYPE_BASIC_MEASUREMENT:
    case MSR_TYPE_FRAME_MEASUREMENT:
    case MSR_TYPE_MAX_NUM_OF_MEASURE_TYPES:
    default:
        TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": measure type %d not supported for request %d\n", 							pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType,							requestIndex);
        break;
    }

    /* if no measurement are running and no CBs are pending, send ALL TYPES COMPLETE event */
    if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
    {
        /* send the event */
        measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
    }
}
Exemple #12
0
/**
 * \\n
 * \brief Handle measurement start success if all measurements
 *        failed send ALL_TYPE_COMPLETE event to stop measure command to the FW.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_startMeasureTypesSuccess( TI_HANDLE hMeasurementSRV )
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
    /* if no measurement types are running, send al types complete event.
       This can happen if all types failed to start */
    if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
    {
        /* send the event */
        measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
    }

    return TI_OK;
}
/**
 * \\n
 * \date 14-November-2005\n
 * \brief callback function used by the HAL for measure start event (sent when the FW
 * has started measurement operation, i.e. switched channel and changed RX filters).\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 */
void MacServices_measurementSRV_measureStartCB( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t *pMeasurementSRV  = (measurementSRV_t*)hMeasurementSRV;


	/* stop the FW guard timer */
	tmr_StopTimer (pMeasurementSRV->hStartStopTimer);
	pMeasurementSRV->bStartStopTimerRunning = TI_FALSE;

	/* clear the CB function, so that it won't be called on stop as well! */
	pMeasurementSRV->commandResponseCBFunc = NULL;
	pMeasurementSRV->commandResponseCBObj = NULL;

	measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
	                          MSR_SRV_EVENT_START_SUCCESS );
}
static void measurementSRVSM_requestMeasureStartResponseCB(TI_HANDLE hMeasurementSRV, TI_UINT32 uMboxStatus)
{
	measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TI_INT32 i;

	TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS = %d\n", uMboxStatus);

	if (uMboxStatus == TI_OK)
	{
		TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS_SUCCESS!\n");

		if ( NULL != pMeasurementSRV->commandResponseCBFunc )
		{
			pMeasurementSRV->commandResponseCBFunc( pMeasurementSRV->commandResponseCBObj, TI_OK );
		}
	}
	else
	{
		if (uMboxStatus == SG_REJECT_MEAS_SG_ACTIVE)
		{
			TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS_REJECT_MEAS_SG_ACTIVE!\n");
		}

		TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": FW has responded with CMD_STATUS NOK!!!\n");


		/* if a timer is running, stop it */
		if ( TI_TRUE == pMeasurementSRV->bStartStopTimerRunning )
		{
			TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "***** STOP TIMER 8 *****\n");
			tmr_StopTimer( pMeasurementSRV->hStartStopTimer );
			pMeasurementSRV->bStartStopTimerRunning = TI_FALSE;
		}
		for ( i = 0; i < MAX_NUM_OF_MSR_TYPES_IN_PARALLEL; i++ )
		{
			if ( TI_TRUE == pMeasurementSRV->bRequestTimerRunning[ i ] )
			{
				tmr_StopTimer( pMeasurementSRV->hRequestTimer[ i ] );
				pMeasurementSRV->bRequestTimerRunning[ i ] = TI_FALSE;
			}
		}

		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_START_FAILURE );
	}
}
/**
 * \\n
 * \date 08-November-2005\n
 * \brief Handle an ALL_TYPE_COMPLETE event by sending a stop measure command to the FW.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_requestMeasureStop( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TI_STATUS status;

	/* since this function may also be called when stop is requested and start complete event
	   has not yet been received from the FW, we may need to stop the FW guard timer */
	if (pMeasurementSRV->bStartStopTimerRunning)
	{
		tmr_StopTimer (pMeasurementSRV->hStartStopTimer);
		pMeasurementSRV->bStartStopTimerRunning = TI_FALSE;
	}

	/* Send Measurement Stop command to the FW */
	status = cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld,
	                                    (void *)pMeasurementSRV->commandResponseCBFunc,
	                                    pMeasurementSRV->commandResponseCBObj);

	pMeasurementSRV->commandResponseCBFunc = NULL;
	pMeasurementSRV->commandResponseCBObj = NULL;

	if ( TI_OK != status )
	{
		TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement stop command, statud=%d,\n", status);

		/* send a measurement complete event - since it can't be stopped */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState), MSR_SRV_EVENT_STOP_COMPLETE );
		return TI_OK;
	}

	TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure stop command sent.\n");

	/* start the FW guard timer */
	pMeasurementSRV->bStartStopTimerRunning = TI_TRUE;
	tmr_StartTimer (pMeasurementSRV->hStartStopTimer,
	                MacServices_measurementSRV_startStopTimerExpired,
	                (TI_HANDLE)pMeasurementSRV,
	                MSR_FW_GUARD_TIME,
	                TI_FALSE);

	return TI_OK;
}
Exemple #16
0
/**
 * \\n
 * \date 08-November-2005\n
 * \brief handle AP_DISCOVERY event received from firmware after AP_DISCOVERY_STOP command\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_apDiscoveryStopComplete(TI_HANDLE hMeasurementSRV)
{
    measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
    TI_UINT32 requestIndex = pMeasurementSRV->uApDiscoveryRequestIndex;

    /* stop Ap Discovery event timer */
    tmr_StopTimer(pMeasurementSRV->hApDiscoveryTimer);

    pMeasurementSRV->bRequestTimerRunning[ requestIndex ] = TI_FALSE;
    pMeasurementSRV->uApDiscoveryRequestIndex = INVALID_MSR_INDEX;

    /* if no measurement are running and no CBs are pending, send ALL TYPES COMPLETE event */
    if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
    {
        /* send the event */
        return measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
    }

    return TI_OK;
}
/**
 * \\n
 * \date 08-November-2005\n
 * \brief Handle a DRIVER_MODE_SUCCESS event by sending start measure command to the FW.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_requestMeasureStart( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t     *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TMeasurementParams    pMeasurementCmd;
	TI_STATUS             status;
	TI_UINT32                currentTime = os_timeStampMs( pMeasurementSRV->hOS );

	/* check if request time has expired (note: timer wrap-around is also handled)*/
	if ( (pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs)
	        < currentTime )
	{
		TI_INT32 i;

		TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request time has expired, request expiry time:%d, current time:%d\n", pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs, currentTime);

		/* mark that all measurement types has failed */
		for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ )
		{
			pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK;
		}

		/* send a measurement complete event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_STOP_COMPLETE );

		return TI_OK;
	}

	pMeasurementCmd.channel = pMeasurementSRV->msrRequest.channel;
	pMeasurementCmd.band = pMeasurementSRV->msrRequest.band;
	pMeasurementCmd.duration = 0; /* Infinite */
	pMeasurementCmd.eTag = pMeasurementSRV->msrRequest.eTag;

	if ( measurementSRVIsBeaconMeasureIncluded( hMeasurementSRV ))
	{  /* Beacon Measurement is one of the types */

		/* get the current channel */
		TTwdParamInfo	paramInfo;

		paramInfo.paramType = TWD_CURRENT_CHANNEL_PARAM_ID;
		cmdBld_GetParam (pMeasurementSRV->hCmdBld, &paramInfo);

		pMeasurementCmd.ConfigOptions = RX_CONFIG_OPTION_FOR_MEASUREMENT;

		/* check if the request is on the serving channel */
		if ( paramInfo.content.halCtrlCurrentChannel == pMeasurementSRV->msrRequest.channel )
		{
			/* Set the RX Filter to the join one, so that any packets will
			be received on the serving channel - beacons and probe requests for
			the measurmenet, and also data (for normal operation) */
			pMeasurementCmd.FilterOptions = RX_FILTER_OPTION_JOIN;
		}
		else
		{
			/* not on the serving channle - only beacons and rpobe responses are required */
			pMeasurementCmd.FilterOptions = RX_FILTER_OPTION_DEF_PRSP_BCN;
		}
	}
	else
	{  /* No beacon measurement - use the current RX Filter */
		pMeasurementCmd.ConfigOptions = 0xffffffff;
		pMeasurementCmd.FilterOptions = 0xffffffff;
	}

	/* Send start measurement command */
	status = cmdBld_CmdMeasurement (pMeasurementSRV->hCmdBld,
	                                &pMeasurementCmd,
	                                (void *)measurementSRVSM_requestMeasureStartResponseCB,
	                                pMeasurementSRV);

	if ( TI_OK != status )
	{
		TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement start command, statud=%d,\n", status);

		/* keep the faulty return status */
		pMeasurementSRV->returnStatus = status;

		/* send a measurement start fail event */
		return measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                                 MSR_SRV_EVENT_START_FAILURE );
	}

	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);

	/* start the FW guard timer */
	pMeasurementSRV->bStartStopTimerRunning = TI_TRUE;
	tmr_StartTimer (pMeasurementSRV->hStartStopTimer,
	                MacServices_measurementSRV_startStopTimerExpired,
	                (TI_HANDLE)pMeasurementSRV,
	                MSR_FW_GUARD_TIME,
	                TI_FALSE);

	return TI_OK;
}
/**
 * \\n
 * \date 16-November-2005\n
 * \brief Callback for channel load get param call.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param status - the get_param call status.\n
 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object)
 */
void MacServices_measurementSRV_channelLoadParamCB( TI_HANDLE hMeasurementSRV, TI_STATUS status,
        TI_UINT8* CB_buf )
{
    measurementSRV_t	    *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
    TI_UINT32                  mediumUsageInMs, periodInMs;
    TI_INT32 					requestIndex;

    /* when this CB is called as a result of the nulify call at the measurement beginning,
       the handle will be NULL. In this case, nothing needs to be done. */
    if ( NULL == hMeasurementSRV )
    {
        return;
    }

    TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Channel load CB called, status:%d\n", status);
    TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "result address (reported): 0x%x, result address (assumed): 0x%x, results (reported):\n",							  CB_buf, &(pMeasurementSRV->mediumOccupancyResults));
    TRACE_INFO_HEX( pMeasurementSRV->hReport, CB_buf, sizeof(TMediumOccupancy));

    /* setting Off the Waitng for Channel Load Results Bit */
    pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_CHANNEL_LOAD_RESULTS;

    /* find the request index */
    requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_CCA_LOAD_MEASUREMENT );
    if ( -1 == requestIndex )
    {
        /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */
        TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request index from measurementSRVFindIndexByType is -1?!?");
        return;
    }

    if ( (TI_OK == status) && (0 != pMeasurementSRV->mediumOccupancyResults.Period))
    {
        /* calculate results */
        mediumUsageInMs = pMeasurementSRV->mediumOccupancyResults.MediumUsage / 1000;
        periodInMs      = pMeasurementSRV->mediumOccupancyResults.Period / 1000;

        TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": MediumUsage = %d Period = %d\n",mediumUsageInMs, periodInMs);

        if ( periodInMs <= pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration )
        {
            pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction =
                ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) /
                pMeasurementSRV->mediumOccupancyResults.Period;
        }
        else
        {
            pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.CCABusyFraction =
                ( 255 * pMeasurementSRV->mediumOccupancyResults.MediumUsage ) /
                (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration * 1000);
        }
    }
    else
    {
        TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": channel load failed. Status=%d, period=%d\n",							status,							pMeasurementSRV->mediumOccupancyResults.Period);

        /* mark result status */
        pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
    }

    /* if no measurement are running and no CBs are pending,
       send ALL TYPES COMPLETE event */
    if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
    {
        /* send the event */
        measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
    }
}
/**
 * \\n
 * \date 16-November-2005\n
 * \brief Callback for noise histogram get param call.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSRV - handle to the measurement SRV object.\n
 * \param status - the get_param call status.\n
 * \param CB_buf - pointer to the results buffer (already on the measurement SRV object)
 */
void MacServices_measurementSRV_noiseHistCallBack( TI_HANDLE hMeasurementSRV, TI_STATUS status,
        TI_UINT8* CB_buf )
{
    measurementSRV_t		    *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
    TI_UINT8		                index;
    TI_UINT32                      sumOfSamples;
    TI_INT32							requestIndex;

    TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": noise histogram CB called, status: %d\n", status);
    TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, "result address (reported): 0x%x, result address (assumed): 0x%x, results (reported):\n",							  CB_buf, &(pMeasurementSRV->noiseHistogramResults));
    TRACE_INFO_HEX( pMeasurementSRV->hReport, CB_buf, sizeof(TNoiseHistogramResults));

    /* setting Off the Waitng for noise histogram Results Bit */
    pMeasurementSRV->pendingParamCBs &= ~MSR_SRV_WAITING_NOISE_HIST_RESULTS;

    /* find the request index */
    requestIndex = measurementSRVFindIndexByType( hMeasurementSRV, MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT );
    if ( -1 == requestIndex )
    {
        /* indicates we can't find the request in the requets array. Shouldn't happen, but nothing to do */
        TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request index from measurementSRVFindIndexByType is -1?!?");
        return;
    }

    if ( TI_OK == status )
    {
        sumOfSamples = pMeasurementSRV->noiseHistogramResults.numOfLostCycles;

        /* Print For Debug */
        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));

        for ( index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++ )
        {
            sumOfSamples += pMeasurementSRV->noiseHistogramResults.counters[ index ];

            /* Print For Debug */
            TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Counter #%d = %x\n", index, pMeasurementSRV->noiseHistogramResults.counters[index]);
        }

        /* If there weren't enough samples --> Reject the Request */
        if ( (sumOfSamples - pMeasurementSRV->noiseHistogramResults.numOfLostCycles) <
                NOISE_HISTOGRAM_THRESHOLD )
        {
            TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_WARNING, ": noise histogram CB, rejecting request because %d samples received.\n",								  sumOfSamples - pMeasurementSRV->noiseHistogramResults.numOfLostCycles);

            /* set negative result status */
            pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
        }
        else
        {
            for (index = 0; index < NUM_OF_NOISE_HISTOGRAM_COUNTERS; index++)
            {
                pMeasurementSRV->msrReply.msrTypes[ requestIndex ].replyValue.RPIDensity[ index ] =
                    ( 255 * pMeasurementSRV->noiseHistogramResults.counters[ index ]) / sumOfSamples;
            }

            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 ]);
        }
    }
    else
    {
        TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_WARNING, ": noise histogram CB with status: %d, rejecting request.\n", status);
        /* set negative result status */
        pMeasurementSRV->msrReply.msrTypes[ requestIndex ].status = TI_NOK;
    }

    /* if no measurement are running and no CBs are pending,
       send ALL TYPES COMPLETE event */
    if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
    {
        /* send the event */
        measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
                                  MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
    }
}
/**
 * \\n
 * \date 08-November-2005\n
 * \brief Handle a START_SUCCESS event by starting different measure types and setting timers.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_startMeasureTypes( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t      *pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TI_UINT8                 requestIndex, rangeIndex;
	TI_INT8                  rangeUpperBound;
	TTwdParamInfo         tTwdParam;
	TI_STATUS             status;
	TNoiseHistogram       pNoiseHistParams;
	TApDiscoveryParams    pApDiscoveryParams;
	TI_UINT32                currentTime = os_timeStampMs( pMeasurementSRV->hOS );

	/* check if request time has expired (note: timer wrap-around is also handled)*/
	if ( (pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs)
	        < currentTime )
	{
		TI_INT32 i;

		TRACE2( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": request time has expired, request expiry time:%d, current time:%d\n", pMeasurementSRV->requestRecptionTimeStampMs + pMeasurementSRV->timeToRequestExpiryMs, currentTime);

		/* mark that all measurement types has failed */
		for ( i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++ )
		{
			pMeasurementSRV->msrReply.msrTypes[ i ].status = MSR_REJECT_MAX_DELAY_PASSED;
		}

		/* send a measurement complete event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_ALL_TYPES_COMPLETE );

		return TI_OK;
	}

	/* Going over all request types that should be executed in parallel
	to start their timers and execute the measurement */
	for ( requestIndex = 0; requestIndex < pMeasurementSRV->msrRequest.numberOfTypes ; requestIndex++ )
	{
		switch (pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType)
		{
		case MSR_TYPE_CCA_LOAD_MEASUREMENT:
			/* Clearing the Medium Occupancy Register */
			tTwdParam.paramType = TWD_MEDIUM_OCCUPANCY_PARAM_ID;
			tTwdParam.content.interogateCmdCBParams.fCb = (void *)MacServices_measurementSRV_dummyChannelLoadParamCB;
			tTwdParam.content.interogateCmdCBParams.hCb = hMeasurementSRV;
			tTwdParam.content.interogateCmdCBParams.pCb =
			    (TI_UINT8*)&pMeasurementSRV->mediumOccupancyResults;
			status = cmdBld_GetParam (pMeasurementSRV->hCmdBld, &tTwdParam);
			if ( TI_OK == status  )
			{
				TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Medium Usage has been nullified, starting timer.\n");

				/* Start Timer */
				tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex],
				                MacServices_measurementSRV_requestTimerExpired,
				                (TI_HANDLE)pMeasurementSRV,
				                pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration,
				                TI_FALSE);
				pMeasurementSRV->bRequestTimerRunning[requestIndex] = TI_TRUE;
			}
			else
			{
				TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_GetParam (for channel load) returned status %d\n", status);
			}

			break;

		case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT:
			/* Set Noise Histogram Cmd Params */
			pNoiseHistParams.cmd = START_NOISE_HIST;
			pNoiseHistParams.sampleInterval = DEF_SAMPLE_INTERVAL;
			os_memoryZero( pMeasurementSRV->hOS, &(pNoiseHistParams.ranges[0]), MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES );

			/* Set Ranges */
			/* (-87) - First Range's Upper Bound */
			rangeUpperBound = -87;

			/* Previously we converted from RxLevel to dBm - now this isn't necessary */
			/* rangeUpperBound = TWD_convertRSSIToRxLevel( pMeasurementSRV->hTWD, -87); */

			for (rangeIndex = 0; rangeIndex < MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES -1; rangeIndex++)
			{
				if (rangeUpperBound > 0)
				{
					pNoiseHistParams.ranges[rangeIndex] = 0;
				}
				else
				{
					pNoiseHistParams.ranges[rangeIndex] = rangeUpperBound;
				}
				rangeUpperBound += 5;
			}
			pNoiseHistParams.ranges[rangeIndex] = 0xFE;

			/* Print for Debug */
			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]);

			/* Send a Start command to the FW */
			status = cmdBld_CmdNoiseHistogram (pMeasurementSRV->hCmdBld, &pNoiseHistParams, NULL, NULL);

			if ( TI_OK == status )
			{
				/* Print for Debug */
				TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": Sent noise histogram command. Starting timer\n");

				/* Start Timer */
				tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex],
				                MacServices_measurementSRV_requestTimerExpired,
				                (TI_HANDLE)pMeasurementSRV,
				                pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration,
				                TI_FALSE);
				pMeasurementSRV->bRequestTimerRunning[requestIndex] = TI_TRUE;
			}
			else
			{
				TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_NoiseHistogramCmd returned status %d\n", status);
			}
			break;

		case MSR_TYPE_BEACON_MEASUREMENT:
			/* set all parameters in the AP discovery command */
			pApDiscoveryParams.scanDuration = pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].duration * 1000;
			pApDiscoveryParams.numOfProbRqst = 1;
			pApDiscoveryParams.txdRateSet = HW_BIT_RATE_1MBPS;
			pApDiscoveryParams.ConfigOptions = RX_CONFIG_OPTION_FOR_MEASUREMENT;
			pApDiscoveryParams.FilterOptions = RX_FILTER_OPTION_DEF_PRSP_BCN;
			pApDiscoveryParams.txPowerDbm = pMeasurementSRV->msrRequest.txPowerDbm;
			pApDiscoveryParams.scanOptions = SCAN_ACTIVE; /* both scan type and band are 0 for active and */
			/* 2.4 GHz, respectively, but 2.4 is not defined */

			/* band determined at the initiate measurement command not at that structure */

			/* scan mode go into the scan option field */
			if ( MSR_SCAN_MODE_PASSIVE == pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].scanMode )
			{
				pApDiscoveryParams.scanOptions |= SCAN_PASSIVE;
			}

			/* Send AP Discovery command */
			status = cmdBld_CmdApDiscovery (pMeasurementSRV->hCmdBld, &pApDiscoveryParams, NULL, NULL);

			if ( TI_OK == status )
			{
				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);

				/* Start Timer */
				tmr_StartTimer (pMeasurementSRV->hRequestTimer[requestIndex],
				                MacServices_measurementSRV_requestTimerExpired,
				                (TI_HANDLE)pMeasurementSRV,
				                pMeasurementSRV->msrRequest.msrTypes[requestIndex].duration,
				                TI_FALSE);
				pMeasurementSRV->bRequestTimerRunning[ requestIndex ] = TI_TRUE;
			}
			else
			{
				TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_ApDiscoveryCmd returned status %d\n", status);
			}
			break;

		case MSR_TYPE_BASIC_MEASUREMENT: /* not supported in current implemntation */
		case MSR_TYPE_FRAME_MEASUREMENT: /* not supported in current implemntation */
		default:
			TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Measurement type %d is not supported\n", pMeasurementSRV->msrRequest.msrTypes[ requestIndex ].msrType);
			break;
		}
	}

	/* if no measurement types are running, sen al types complete event.
	   This can happen if all types failed to start */
	if ( TI_TRUE == measurementSRVIsMeasurementComplete( hMeasurementSRV ))
	{
		/* send the event */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_ALL_TYPES_COMPLETE );
	}

	return TI_OK;
}
/**
 * \\n
 * \date 08-November-2005\n
 * \brief handle a STOP_REQUEST event when in MEASURE_IN_PROGRESS by stopping all measure types and
 * \brief requesting measure stop from the FW.\n
 *
 * Function Scope \e Public.\n
 * \param hMeasurementSrv - handle to the Measurement SRV object.\n
 * \return always TI_OK.\n
 */
TI_STATUS measurementSRVSM_stopFromMeasureInProgress( TI_HANDLE hMeasurementSRV )
{
	measurementSRV_t* pMeasurementSRV = (measurementSRV_t*)hMeasurementSRV;
	TNoiseHistogram   pNoiseHistParams;
	TI_STATUS         status;
	TI_INT32          i;

	/* stop all running measure types */
	for (i = 0; i < pMeasurementSRV->msrRequest.numberOfTypes; i++)
	{
		if (pMeasurementSRV->bRequestTimerRunning[i])
		{
			/* stop timer */
			tmr_StopTimer (pMeasurementSRV->hRequestTimer[i]);
			pMeasurementSRV->bRequestTimerRunning[i] = TI_FALSE;

			/* if necessary, stop measurement type */
			switch ( pMeasurementSRV->msrRequest.msrTypes[ i ].msrType )
			{
			case MSR_TYPE_BEACON_MEASUREMENT:
				/* send stop AP discovery command */
				status = cmdBld_CmdApDiscoveryStop (pMeasurementSRV->hCmdBld, NULL, NULL);
				if ( TI_OK != status )
				{
					TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_ApDiscoveryStop returned status %d\n", status);
				}
				break;

			case MSR_TYPE_NOISE_HISTOGRAM_MEASUREMENT:
				/* Set Noise Histogram Cmd Params */
				pNoiseHistParams.cmd = STOP_NOISE_HIST;
				pNoiseHistParams.sampleInterval = 0;
				os_memoryZero( pMeasurementSRV->hOS, &(pNoiseHistParams.ranges[ 0 ]), MEASUREMENT_NOISE_HISTOGRAM_NUM_OF_RANGES );

				/* Send a Stop command to the FW */
				status = cmdBld_CmdNoiseHistogram (pMeasurementSRV->hCmdBld, &pNoiseHistParams, NULL, NULL);

				if ( TI_OK != status )
				{
					TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": TWD_NoiseHistogramCmd returned status %d\n", status);
				}
				break;

				/* These are just to avoid compilation warnings, nothing is actualy done here! */
			case MSR_TYPE_BASIC_MEASUREMENT:
			case MSR_TYPE_CCA_LOAD_MEASUREMENT:
			case MSR_TYPE_FRAME_MEASUREMENT:
			case MSR_TYPE_MAX_NUM_OF_MEASURE_TYPES:
			default:
				TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": unsupported measurement type: %d\n", pMeasurementSRV->msrRequest.msrTypes[ i ].msrType);
				break;
			}

			/* mark that measurement has failed */
			pMeasurementSRV->msrReply.msrTypes[ i ].status = TI_NOK;
		}
	}

	/* Send Measurement Stop command to the FW */
	status = cmdBld_CmdMeasurementStop (pMeasurementSRV->hCmdBld,
	                                    (void *)pMeasurementSRV->commandResponseCBFunc,
	                                    pMeasurementSRV->commandResponseCBObj);

	pMeasurementSRV->commandResponseCBFunc = NULL;
	pMeasurementSRV->commandResponseCBObj = NULL;

	if ( TI_OK != status )
	{
		TRACE1( pMeasurementSRV->hReport, REPORT_SEVERITY_ERROR, ": Failed to send measurement stop command, statud=%d,\n", status);

		/* send a measurement complete event - since it can't be stopped */
		measurementSRVSM_SMEvent( hMeasurementSRV, &(pMeasurementSRV->SMState),
		                          MSR_SRV_EVENT_STOP_COMPLETE );
		return TI_OK;
	}

	TRACE0( pMeasurementSRV->hReport, REPORT_SEVERITY_INFORMATION, ": measure stop command sent.\n");

	/* start the FW guard timer */
	pMeasurementSRV->bStartStopTimerRunning = TI_TRUE;
	tmr_StartTimer (pMeasurementSRV->hStartStopTimer,
	                MacServices_measurementSRV_startStopTimerExpired,
	                (TI_HANDLE)pMeasurementSRV,
	                MSR_FW_GUARD_TIME,
	                TI_FALSE);

	return TI_OK;
}