/*
    This function is called to complete script execution from all possible execution paths.
*/
void _MCP_BTS_SP_CompleteExecution(McpBtsSpContext *context, McpBtsSpStatus executionStatus)
{
    if (executionStatus == MCP_BTS_SP_STATUS_SUCCESS)
    {
        MCP_LOG_INFO(("_MCP_BTS_SP_CompleteExecution: SCRIPT EXECUTION SUCCESSFULLY COMPLETED"));
    }
    else if (executionStatus == MCP_BTS_SP_STATUS_EXECUTION_ABORTED)
    {
        MCP_LOG_INFO(("_MCP_BTS_SP_CompleteExecution: SCRIPT EXECUTION ABORTED"));
    }
    else
    {
        MCP_LOG_FATAL(("_MCP_BTS_SP_CompleteExecution: SCRIPT EXECUTION FAILED (%s)", 
                            _MCP_BTS_SP_DebugStatusStr(executionStatus)));
    }

    /* Close script file ([ToDo] - Memory scripts ) */
    _MCP_BTS_SP_CloseScript(context);

    /* If execution completed asynchronously, notify the callback on execution completion status */
    if (context->asyncExecution == MCP_TRUE)
    {
        (context->cbData.execCompleteCb)(context, executionStatus);
    }
}
示例#2
0
void MCP_GenSM_Event (MCP_TGenSM *pGenSM, McpU32 uEvent, void *pData)
{

    McpU32           uCurrentState;
    MCP_TGenSM_actionCell   *pCell;

    /* mark that an event is pending */
    pGenSM->bEventPending = MCP_TRUE;

    /* save event and data */
    pGenSM->uEvent = uEvent;
    pGenSM->pData = pData;

    /* if an event is currently executing, return (new event will be handled when current event is done)*/
    if (MCP_TRUE == pGenSM->bInAction)
    {		       
				MCP_LOG_INFO(("Event is already in process ! delaying execution of event: %s \n",
								pGenSM->pEventTString(pGenSM->uEvent)));
        return;
    }

    /* execute events, until none is pending */
    while (MCP_TRUE == pGenSM->bEventPending)
    {
        /* get the cell pointer for the current state and event */
        pCell = &(pGenSM->tMatrix[ (pGenSM->uCurrentState * pGenSM->uEventNum) + pGenSM->uEvent ]);

	/* print state transition information */
	MCP_LOG_INFO(("Transition from State:%s, Event:%s -->  State : %s\n",
 					pGenSM->pStateTString(pGenSM->uCurrentState),
					pGenSM->pEventTString(pGenSM->uEvent),
					pGenSM->pStateTString(pCell->uNextState)));
        
        /* mark that event execution is in place */
        pGenSM->bInAction = MCP_TRUE;

        /* mark that pending event is being handled */
        pGenSM->bEventPending = MCP_FALSE;
        
        /* keep current state */
        uCurrentState = pGenSM->uCurrentState;
	/*Save previous State - For debug info */
	 pGenSM->uPreviousState= pGenSM->uCurrentState;
        /* update current state */
        pGenSM->uCurrentState = pCell->uNextState;

        /* run transition function */
        (*(pCell->fAction)) (pGenSM->pData);

        /* mark that event execution is complete */
        pGenSM->bInAction = MCP_FALSE;
    }
}
void _CCM_VAC_MappingEngine_SetOptionalResourcesList (TCCM_VAC_MappingEngine *ptMappEngine,
                                                      ECAL_Operation eOperation,
                                                      TCAL_ResourceList *ptResourceList)
{
    McpU32                      uIndex;

    MCP_FUNC_START ("_CCM_VAC_MappingEngine_SetOptionalResourcesList");

    MCP_LOG_INFO (("_CCM_VAC_MappingEngine_SetOptionalResourcesList: requesting to change optional resources list for "
                   "operation %s", _CCM_VAC_DebugOperationStr(eOperation)));

    /* verify object pointer and list pointer */
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptMappEngine), 
                                ("_CCM_VAC_MappingEngine_SetOptionalResourcesList: NULL object!"));
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptResourceList), 
                                ("_CCM_VAC_MappingEngine_SetOptionalResourcesList: NULL resource list!"));

    /* loop over all optional resources */
    for (uIndex = 0;
         uIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists;
         uIndex++)
    {
        /* if this optional resource is include in the new list */
        if (MCP_TRUE ==
            _CCM_VAC_MEIsResourceOnList (ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource,
            ptResourceList))
        {
            /* mark the optional resource as used */
            ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].bIsUsed =
                MCP_TRUE;
            MCP_LOG_INFO (("_CCM_VAC_MappingEngine_SetOptionalResourcesList: optional resource %s is "
                           "set to used for operation %s",
                           _CCM_VAC_DebugResourceStr(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource),
                           _CCM_VAC_DebugOperationStr(eOperation)));
        }
        else
        {
            /* mark the optional resource as unused */
            ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].bIsUsed = 
                MCP_FALSE;
            MCP_LOG_INFO (("_CCM_VAC_MappingEngine_SetOptionalResourcesList: optional resource %s is "
                           "set to unused for operation %s",
                           _CCM_VAC_DebugResourceStr(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource),
                           _CCM_VAC_DebugOperationStr(eOperation)));
        }
    }

    MCP_FUNC_END ();
}
McpConfigParserStatus MCP_CONFIG_PARSER_GetIntegerKey (McpConfigParser *pConfigParser,
                                                       McpU8 *pSectionName,
                                                       McpU8 *pKeyName,
                                                       McpS32 *pKeyIntValue)
{
    McpU8       *pKeyAsciiValue;

    MCP_FUNC_START ("MCP_CONFIG_PARSER_GetIntegerKey");

    MCP_LOG_INFO (("MCP_CONFIG_PARSER_GetIntegerKey: looking for key %s in section %s",
                   pKeyName, pSectionName));

    /* search for the ASCII value of this key */
    if (MCP_CONFIG_PARSER_STATUS_SUCCESS == 
        MCP_CONFIG_PARSER_GetAsciiKey (pConfigParser, pSectionName, pKeyName, &pKeyAsciiValue))
    {
        /* key was found */
        *pKeyIntValue = MCP_UTILS_AtoU32((const char *)pKeyAsciiValue);
        return MCP_CONFIG_PARSER_STATUS_SUCCESS;
    }

    /* key or section were not found */
    *pKeyIntValue = 0;
    return MCP_CONFIG_PARSER_STATUS_FAILURE_KEY_DOESNT_EXIST;
}
_CcmImStatus _CCM_IM_BtTranSm_PerformCompletion(    
                                _CcmIm_BtTranSm_Obj                     *thisObj,
                                _CcmIm_BtTranSm_CompletionEventType eventType,
                                _CcmImStatus                        completionStatus)
{
    _CcmImStatus                        status;
    _CcmIm_BtTranSm_CompletionEvent completionEvent;
        
    MCP_FUNC_START("_CCM_IM_BtTranSm_PerformCompletion");

    MCP_LOG_INFO(("_CCM_IM_BtTranSm_PerformCompletion: BT Tran Off Completed (status: %d), Calling Parent", completionStatus));

    if (thisObj->asyncCompletion == MCP_TRUE)
    {
        /* 
            Notify parent SM (BtTranSm) of completion and its status. BtTranSm is not aware
            of the id of the stack that initiated Bt Tran Off. It is up to the parent SM to record
            this information.
        */
        completionEvent.chipId = thisObj->chipId;
        completionEvent.completionStatus = completionStatus;
        completionEvent.eventType = eventType;
        
        (thisObj->parentCb)(&completionEvent);
    }
        
    status =    _CCM_IM_STATUS_SUCCESS;
    
    MCP_FUNC_END();

    return status;
}
示例#6
0
McpPoolStatus MCP_POOL_Destroy(McpPool	 *pool)
{
	McpPoolStatus	status = MCP_POOL_STATUS_SUCCESS;
	McpU32		numOfAllocatedElements;
	
	MCP_FUNC_START("MCP_POOL_Destroy");

	MCP_LOG_INFO(("Destroying Pool %s", pool->name));
		
	MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument"));

	/* It is illegal to destroy a pool while there are allocated elements in the pool */
	status = MCP_POOL_GetNumOfAllocatedElements(pool, &numOfAllocatedElements);
	MCP_VERIFY_ERR_NORET(	(0 == numOfAllocatedElements), 
							("Pool %s still has %d allocated elements", pool->name, numOfAllocatedElements));

	pool->elementsMemory = 0;
	pool->numOfElements = 0;
	pool->elementAllocatedSize = 0;
	pool->numOfAllocatedElements = 0;
	MCP_HAL_STRING_StrCpy(pool->name, "");
	
	MCP_FUNC_END();
	
	return status;
}
void _CCM_VAC_MappingEngine_OperationToResourceList (TCCM_VAC_MappingEngine *ptMappEngine, 
                                                     ECAL_Operation eOperation,
                                                     TCAL_ResourceList *ptResourceList)
{
    McpU32                      uIndex, uOptListsIndex;
    TCAL_ResourceList           *ptTempList;

    MCP_FUNC_START ("_CCM_VAC_MappingEngine_OperationToResourceList");

    MCP_LOG_INFO (("_CCM_VAC_MappingEngine_OperationToResourceList: requesting resource list for operation %s",
                   _CCM_VAC_DebugOperationStr(eOperation)));

    /* verify object pointer and list pointer */
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptMappEngine), 
                                ("_CCM_VAC_MappingEngine_OperationToResourceList: NULL object!"));
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptResourceList), 
                                ("_CCM_VAC_MappingEngine_OperationToResourceList: NULL resource list!"));

    /* nullify the output resource list */
    ptResourceList->uNumOfResources = 0;

    /* First copy all mandatory resources */
    ptTempList = &(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tMandatoryResources);
    for (uIndex = 0; uIndex < ptTempList->uNumOfResources; uIndex++)
    {
        ptResourceList->eResources[ ptResourceList->uNumOfResources ] = ptTempList->eResources[ uIndex ];
        ptResourceList->uNumOfResources++;
    }

    /* than copy all optional resources lists currently in use */
    for (uOptListsIndex = 0; 
         uOptListsIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists;
         uOptListsIndex++)
    {
        /* if this optional resource is in use at the moment */
        if (MCP_TRUE == 
            ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptListsIndex ].bIsUsed)
        {
            /* copy the optional resource */
            ptResourceList->eResources[ ptResourceList->uNumOfResources ] =
                ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptListsIndex ].eOptionalResource;
            ptResourceList->uNumOfResources++;

            /* set the pointer to the derived resources list */
            ptTempList = 
                &(ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uOptListsIndex ].tDerivedResourcesList);

            /* now copy all derived resources in the list */
            for (uIndex = 0; uIndex < ptTempList->uNumOfResources; uIndex++)
            {
                ptResourceList->eResources[ ptResourceList->uNumOfResources ] = ptTempList->eResources[ uIndex ];
                ptResourceList->uNumOfResources++;
            }
        }
    }

    MCP_FUNC_END ();
}
/*
    Opens the script file and obtains its size
*/
McpBtsSpStatus _MCP_BTS_SP_FsOpenScript(McpBtsSpContext *context,
                                        const McpUtf8 *fullFileName)
{
    McpHalFsStatus fsStatus;
    McpHalFsStat fsStat;

    /* Get file information */
    fsStatus = MCP_HAL_FS_Stat(fullFileName, &fsStat);

    if (fsStatus != MCP_HAL_FS_STATUS_SUCCESS)
    {

        /* Failed to get file information - report and return proper error code */
        MCP_LOG_ERROR(("_MCP_BTS_SP_FsOpenScript: MCP_HAL_FS_Stat Failed (%d)",
                       fsStatus));

        if (fsStatus == MCP_HAL_FS_STATUS_ERROR_NOTFOUND)
        {
            return MCP_BTS_SP_STATUS_FILE_NOT_FOUND;
        }
        else
        {
            return MCP_BTS_SP_STATUS_FFS_ERROR;
        }
    }

    /* Record the file size*/
    context->scriptSize = fsStat.size;
    
    /* Open the script file for reading as a binary file */
    fsStatus = MCP_HAL_FS_Open(fullFileName,  
                               (MCP_HAL_FS_O_RDONLY | MCP_HAL_FS_O_BINARY), 
                               &context->locationData.fileDesc);

    if (fsStatus != MCP_HAL_FS_STATUS_SUCCESS)
    {
        MCP_LOG_ERROR(("_MCP_BTS_SP_FsOpenScript: MCP_HAL_FS_Open Failed (%d)",
                       fsStatus));
        return MCP_BTS_SP_STATUS_FFS_ERROR;
    }

    MCP_LOG_INFO(("_MCP_BTS_SP_FsOpenScript: Successfully opened %s",
                  (char *)fullFileName));       

    return MCP_BTS_SP_STATUS_SUCCESS;
}
/** 
 * \fn     CCMA_SetTranParms 
 * \brief  Configure transport layer
 * 
 */ 
EMcpfRes CCMA_SetTranParms (handle_t hCcma, CcmaTranParms *pTranParms)
{
	TCcmaObj *pCcma = (TCcmaObj *)hCcma;
    EMcpfRes eRes;
    McpU16 uSpeedInKbps;
    
    MCP_FUNC_START("CCMA_SetTranParms");

    uSpeedInKbps = (McpU16)(pTranParms->parms.uartParms.speed / 1000);

    MCP_LOG_INFO(("Setting UART Speed to %d Kbps", uSpeedInKbps));

    eRes = mcpf_trans_SetSpeed(pCcma->hMcpf, uSpeedInKbps);
        
    MCP_FUNC_END();

    return eRes;
}
示例#10
0
文件: ccm.c 项目: anupam19/XperiaL_FM
CcmStatus CCM_StaticInit(void)
{
    CcmStatus       status;
    CcmImStatus     imStatus;
    ECCM_VAC_Status vacStatus;
    
    /* Used to init once only */
    static McpBool firstInit = MCP_TRUE;

    MCP_FUNC_START("CCM_StaticInit");

    if (firstInit == MCP_FALSE)
    {
        MCP_LOG_INFO(("_CCM_StaticInit Already Initialized, Exiting Successfully"));
        MCP_RET(CCM_STATUS_SUCCESS);
    }

    firstInit = MCP_FALSE;

    status = _CCM_StaticInit();
    MCP_VERIFY_FATAL((status == CCM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("_CCM_StaticInit"));

    /* Initialize contained entities (IM, PM, VAC) */
    
    imStatus = CCM_IM_StaticInit();
    MCP_VERIFY_FATAL((imStatus == CCM_IM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_StaticInit"));

    vacStatus = CCM_VAC_StaticInit();
    MCP_VERIFY_FATAL ((CCM_VAC_STATUS_SUCCESS == vacStatus), CCM_STATUS_INTERNAL_ERROR,
                      ("CCM_StaticInit: VAC initialization failed with status %d", vacStatus));

    CCM_CAL_StaticInit();

    status = CCM_STATUS_SUCCESS;
    
    MCP_FUNC_END();
    
    return status;
}
void _CCM_VAC_MappingEngine_GetOptionalResourcesList (TCCM_VAC_MappingEngine *ptMappEngine,
                                                      ECAL_Operation eOperation,
                                                      TCAL_ResourceList *ptResourceList)
{
    McpU32                      uIndex;

    MCP_FUNC_START ("_CCM_VAC_MappingEngine_GetOptionalResourcesList");

    MCP_LOG_INFO (("_CCM_VAC_MappingEngine_GetOptionalResourcesList: requesting optional resources list for "
                   "operation %s", _CCM_VAC_DebugOperationStr(eOperation)));

    /* verify object pointer and list pointer */
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptMappEngine), 
                                ("_CCM_VAC_MappingEngine_GetOptionalResourcesList: NULL object!"));
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptResourceList), 
                                ("_CCM_VAC_MappingEngine_GetOptionalResourcesList: NULL resource list!"));

    /* nullify the output resource list */
    ptResourceList->uNumOfResources = 0;

    /* loop over all optional resources */
    for (uIndex = 0;
         uIndex < ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.uNumOfResourceLists;
         uIndex++)
    {
        /* if the optional resource is currently in use */
        if (MCP_TRUE == ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].bIsUsed)
        {
            /* add it to the list */
            ptResourceList->eResources[ ptResourceList->uNumOfResources ] = 
                ptMappEngine->tConfig.tOpToResMap[ eOperation ].tOptionalResources.tOptionalResourceLists[ uIndex ].eOptionalResource;
            ptResourceList->uNumOfResources++;
        }
    }

    MCP_FUNC_END ();
}
/** 
 * \fn     CCMA_TransportOn 
 * \brief  Start transport layer initialization 
 * 
 */ 
EMcpfRes CCMA_TransportOn(handle_t hCcma)
{
    TCcmaObj *pCcma = (TCcmaObj *)hCcma;
    EMcpfRes eRes;

    MCP_FUNC_START("CCMA_TransportOn");


#ifdef MCP_STK_ENABLE

    pCcma->hHalHci = hal_hci_OpenSocket(pCcma->hMcpf, 0, CCMA_HCI_PKT_TYPE_EVT, NULL, ccmaReceiveCb, hCcma);


    /* Chip is now on and STK wrote its version into the file, get it */
    eRes = hal_hci_GetChipVersion(pCcma->hHalHci, &pCcma->chipVersion);
    MCPF_Assert(RES_OK == eRes);
    
    MCP_LOG_INFO(("CCMA_GetChipVersion: %d.%d.%d, full - 0x%04x",
                  pCcma->chipVersion.projectType,
                  pCcma->chipVersion.major,
                  pCcma->chipVersion.minor,
                  pCcma->chipVersion.full));
    
#else

    eRes = HCIA_SendCommand (((Tmcpf *)pCcma->hMcpf)->hHcia,
							 CCMA_HCI_CMD_HCC_RESET, 
							 NULL, 0,
							 transportOnComplete, 
							 hCcma);
#endif


    MCP_FUNC_END();

    return eRes;
}
/*
    The main state machine of the script processor
*/
McpBtsSpStatus _MCP_BTS_SP_ProcessScriptCommands(McpBtsSpContext *context,
                                                 McpBtsSpProcessingEvent processingEvent,
                                                 void *eventData)
{
    McpBtsSpStatus spStatus = MCP_BTS_SP_STATUS_SUCCESS;
    McpBool keepProcessing;

    MCP_UNUSED_PARAMETER(eventData);
    
    MCP_LOG_INFO(("_MCP_BTS_SP_ProcessScriptCommands: Processing Event: %d", processingEvent));

    keepProcessing = MCP_TRUE;
    
    while ((keepProcessing == MCP_TRUE) && (context->abortRequested == MCP_FALSE))
    {
        keepProcessing = MCP_FALSE;

        MCP_LOG_INFO(("_MCP_BTS_SP_ProcessScriptCommands: State = %d", context->processingState));
        
        switch (context->processingState)
        {
            case MCP_BTS_SP_PROCESSING_STATE_NONE:

                if (processingEvent == MCP_BTS_SP_PROCESSING_EVENT_START)
                {
                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_PROCESS_NEXT_ACTION;             
                }
                else
                {
                    MCP_LOG_FATAL(("_MCP_BTS_SP_ProcessScriptCommands: Unexpected Processing Event (%d)",
                                   processingEvent));

                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                    spStatus = MCP_BTS_SP_STATUS_INTERNAL_ERROR;
                }

                keepProcessing = MCP_TRUE;
                
            break;

            case MCP_BTS_SP_PROCESSING_STATE_PROCESS_NEXT_ACTION:
            {
                McpBool moreActions;
                
                /* Process next script action as long as we do not have to wait for a command complete event */
                do {
                    spStatus = _MCP_BTS_SP_ProcessNextScriptAction(context, &moreActions);
                } while ((spStatus == MCP_BTS_SP_STATUS_SUCCESS) && (moreActions == MCP_TRUE));

                /* [ToDo] - Handle the case of the last actio in the script being a "Send Command" (illegal) */
                if (spStatus == MCP_BTS_SP_STATUS_PENDING)
                {
                    /* The first time we wait for a command complete event we will record that fact */
                    context->asyncExecution = MCP_TRUE;

                    /* */
                    if (moreActions == MCP_TRUE)
                    {
                        context->processingState = MCP_BTS_SP_PROCESSING_STATE_WAIT_FOR_COMMAND_COMPLETE;
                    }
                    else
                    {
                        context->processingState = MCP_BTS_SP_PROCESSING_STATE_WAIT_FOR_LAST_COMMAND_COMPLETE;
                    }
                }
                else
                {
                    /* 
                        We get here in 2 cases:
                        1. script processing error
                        2. Last script action was not a "Send Command" action

                        In that case we terminate. spStatus stores the completion status
                    */
                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                    keepProcessing = MCP_TRUE;
                }
            }
            break;
            
            case MCP_BTS_SP_PROCESSING_STATE_WAIT_FOR_COMMAND_COMPLETE:

                if (processingEvent == MCP_BTS_SP_PROCESSING_EVENT_COMMAND_COMPLETE)
                {
                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_PROCESS_NEXT_ACTION; 
                }
                else
                {
                    MCP_LOG_FATAL(("_MCP_BTS_SP_ProcessScriptCommands: Unexpected Processing Event (%d)",
                                   processingEvent));

                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                    spStatus = MCP_BTS_SP_STATUS_INTERNAL_ERROR;
                }
                
                keepProcessing = MCP_TRUE;
                
            break;

            case MCP_BTS_SP_PROCESSING_STATE_WAIT_FOR_LAST_COMMAND_COMPLETE:
                
                if (processingEvent == MCP_BTS_SP_PROCESSING_EVENT_COMMAND_COMPLETE)
                {
                    spStatus = MCP_BTS_SP_STATUS_SUCCESS;
                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                }
                else
                {
                    MCP_LOG_FATAL(("_MCP_BTS_SP_ProcessScriptCommands: Unexpected Processing Event (%d)",
                                   processingEvent));

                    context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                    spStatus = MCP_BTS_SP_STATUS_INTERNAL_ERROR;
                }

                keepProcessing = MCP_TRUE;
                
            break;
            
            case MCP_BTS_SP_PROCESSING_STATE_DONE:

                MCP_LOG_INFO(("_MCP_BTS_SP_ProcessScriptCommands: Completed (%s)",
                              _MCP_BTS_SP_DebugStatusStr(spStatus)));
                
                _MCP_BTS_SP_CompleteExecution(context, spStatus);

            break;
            
            default:
                MCP_LOG_FATAL(("_MCP_BTS_SP_ProcessScriptCommands: Invalid Processing State (%s)",
                               context->processingState));

                context->processingState = MCP_BTS_SP_PROCESSING_STATE_DONE;
                spStatus = MCP_BTS_SP_STATUS_INTERNAL_ERROR;
                keepProcessing = MCP_TRUE;
        }
    }

    if (context->abortRequested == MCP_TRUE)
    {
        _MCP_BTS_SP_CompleteExecution(context, MCP_BTS_SP_STATUS_EXECUTION_ABORTED);
    }
    
    return spStatus;
}
McpConfigParserStatus MCP_CONFIG_PARSER_Open (McpUtf8 *pFileName, 
                                              McpU8 *pMemConfig, 
                                              McpConfigParser *pConfigParser)
{
    McpU8                   pLine[ MCP_CONFIG_PARSE_LINE_LENGTH ];
    McpConfigParserStatus   status = MCP_CONFIG_PARSER_STATUS_SUCCESS;
    McpBool                 opStatus = MCP_TRUE;
    McpConfigReader         tConfigReader;


    MCP_FUNC_START ("MCP_CONFIG_PARSER_Open");

    MCP_LOG_INFO (("MCP_CONFIG_PARSER_Open: Attempting to open file %s",
        (NULL == pFileName ? (McpU8 *)"NULL": pFileName)));

    /* open the file or memory location */
    opStatus = MCP_CONFIG_READER_Open (&tConfigReader, pFileName, pMemConfig);
    MCP_VERIFY_ERR ((MCP_TRUE == opStatus),
                    MCP_CONFIG_PARSER_STATUS_FAILURE_FILE_ERROR,
                    ("MCP_CONFIG_PARSER_Open: unable to open configuration storage"));

    /* initialize config parser object data */
    pConfigParser->uKeysNum = 0;
    pConfigParser->uSectionNum = 0;

    do
    {
        /* read next line */
        opStatus = MCP_CONFIG_READER_getNextLine (&tConfigReader, pLine);

        /* if reading succeeded */
        if (MCP_TRUE == opStatus)
        {
            /* if this is an empty line */
            if (MCP_TRUE == _MCP_CONFIG_PARSER_IsEmptyLine (pLine))
            {
                continue;
            }
            /* if this is a new section */
            else if (MCP_TRUE == _MCP_CONFIG_PARSER_IsSection (pLine))
            {
                /* Verify we do not overflow the sections buffer */
                MCP_VERIFY_ERR ((MCP_CONFIG_PARSER_SECTION_NUMBER > pConfigParser->uSectionNum),
                                MCP_CONFIG_PARSER_STATUS_FAILURE_FILE_ERROR,
                                ("MCP_CONFIG_PARSER_Open config file contains too many sections"));
            
                /* start a new section */
                pConfigParser->tSections[ pConfigParser->uSectionNum ].uStartingKeyIndex = 
                    pConfigParser->uKeysNum;
                pConfigParser->tSections[ pConfigParser->uSectionNum ].uLastFoundKeyIndex = 
                    pConfigParser->uKeysNum;
                pConfigParser->tSections[ pConfigParser->uSectionNum ].uNumberOfKeys = 0;
                /* store new section name */
                _MCP_CONFIG_PARSER_GetSectionName (pLine, pConfigParser->tSections[ pConfigParser->uSectionNum ].pSectionName);
                /* increase number of sections */
                pConfigParser->uSectionNum++;


            }
            /* it is a key */
            else
            {
                /* verify a section exists */
                MCP_VERIFY_ERR ((0 < pConfigParser->uSectionNum),
                                MCP_CONFIG_PARSER_STATUS_FAILURE_FILE_ERROR,
                                ("MCP_CONFIG_PARSER_Open: Key not within section boundry"));


                /* Verify we do not overflow the keys buffer */
                MCP_VERIFY_ERR ((MCP_CONFIG_PARSER_KEY_NUMBER > pConfigParser->uKeysNum),
                                MCP_CONFIG_PARSER_STATUS_FAILURE_FILE_ERROR,
                                ("MCP_CONFIG_PARSER_Open config file contains too many keys"));
                                
                /* parse key */
                _MCP_CONFIG_PARSER_GetKeyName (pLine, pConfigParser->pKeyNames[ pConfigParser->uKeysNum ]);
                _MCP_CONFIG_PARSER_GetKeyValue (pLine, pConfigParser->pKeyValues[ pConfigParser->uKeysNum ]);
                /* add key to current section */
                pConfigParser->tSections[ pConfigParser->uSectionNum - 1 ].uNumberOfKeys++;
                /* increase number of keys */
                pConfigParser->uKeysNum++;

                
            }
        } 
    } while (MCP_TRUE == opStatus); /* continue to the next line while reading succeeds */

  	opStatus = MCP_CONFIG_READER_Close(&tConfigReader);
	MCP_VERIFY_ERR ((MCP_TRUE == opStatus),
					MCP_CONFIG_PARSER_STATUS_FAILURE_FILE_ERROR,
					("MCP_CONFIG_PARSER_Open: unable to close configuration storage"));
    MCP_FUNC_END ();

    return status;
}
McpConfigParserStatus MCP_CONFIG_PARSER_GetAsciiKey (McpConfigParser *pConfigParser,
                                                     McpU8 *pSectionName,
                                                     McpU8 *pKeyName,
                                                     McpU8 **pKeyAsciiValue)
{
    McpU32      uSectionIndex, uKeyIndex;

    MCP_FUNC_START ("MCP_CONFIG_PARSER_GetAsciiKey");

    MCP_LOG_INFO (("MCP_CONFIG_PARSER_GetAsciiKey: looking for key %s in section %s",
                   pKeyName, pSectionName));

    /* first find the section */
    uSectionIndex = 0;
    while ((uSectionIndex < pConfigParser->uSectionNum) && 
           (0 != MCP_HAL_STRING_StriCmp ((const char *)pSectionName, 
                                         (const char *)pConfigParser->tSections[ uSectionIndex ].pSectionName)))
    {
        uSectionIndex++;
    }

    /* if section was found */
    if (uSectionIndex < pConfigParser->uSectionNum)
    {
        /* find the key */
        /* start from the last found key, to allow reading more than one key with the same name */
        uKeyIndex = pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex;
        while ((uKeyIndex < (pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex + 
                             pConfigParser->tSections[ uSectionIndex ].uNumberOfKeys)) &&
               (0 != MCP_HAL_STRING_StriCmp ((const char *)pKeyName, 
                                             (const char *)pConfigParser->pKeyNames[ uKeyIndex ])))
        {
            uKeyIndex++;
        }

        /* if key was found */
        if (uKeyIndex < (pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex + 
                         pConfigParser->tSections[ uSectionIndex ].uNumberOfKeys))
        {
            /* keep last key found */
            if ((uKeyIndex + 1) >= (pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex + 
                                    pConfigParser->tSections[ uSectionIndex ].uNumberOfKeys))
            {
                /* last found key was the last key in the section - update to the first key */
                pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex = 
                    pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex;
            }
            else
            {
                /* update to the next key */
                pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex = uKeyIndex + 1;
            }

            /* set key value */
            *pKeyAsciiValue = pConfigParser->pKeyValues[ uKeyIndex ];
            return MCP_CONFIG_PARSER_STATUS_SUCCESS;
        }

        /* now continue from the first key */
        uKeyIndex = pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex;
        while ((uKeyIndex < pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex) &&
               (0 == MCP_HAL_STRING_StriCmp ((const char *)pKeyName, 
                                             (const char *)pConfigParser->pKeyNames[ uKeyIndex ])))
        {
            uKeyIndex++;
        }

        /* if key was found */
        if (uKeyIndex < pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex)
        {
            /* keep last key found */
            if ((uKeyIndex + 1) >= (pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex + 
                                    pConfigParser->tSections[ uSectionIndex ].uNumberOfKeys))
            {
                /* last found key was the last key in the section - update to the first key */
                pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex = 
                    pConfigParser->tSections[ uSectionIndex ].uStartingKeyIndex;
            }
            else
            {
                /* update to the next key */
                pConfigParser->tSections[ uSectionIndex ].uLastFoundKeyIndex = uKeyIndex + 1;
            }

            /* set key value */
            *pKeyAsciiValue = pConfigParser->pKeyValues[ uKeyIndex ];
            return MCP_CONFIG_PARSER_STATUS_SUCCESS;
        }
    }

    MCP_FUNC_END ();

    /* key or section were not found */
    *pKeyAsciiValue = NULL;
    return MCP_CONFIG_PARSER_STATUS_FAILURE_KEY_DOESNT_EXIST;
}
McpBool _CCM_VAC_AllocationEngine_TryAllocate (TCCM_VAC_AllocationEngine *ptAllocEngine,
                                               ECAL_Resource eResource, 
                                               ECAL_Operation *peOperation)
{
    McpBool     status = MCP_FALSE;

    MCP_FUNC_START ("_CCM_VAC_AllocationEngine_TryAllocate");

    MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s requesting resource %s",
                   _CCM_VAC_DebugOperationStr(*peOperation),
                   _CCM_VAC_DebugResourceStr (eResource)));

    /* verify object pointer and resource availability */
    MCP_VERIFY_FATAL ((NULL != ptAllocEngine), MCP_FALSE, 
                      ("_CCM_VAC_AllocationEngine_TryAllocate: NULL object!"));
    MCP_VERIFY_ERR ((MCP_TRUE == ptAllocEngine->tResources[ eResource ].bAvailable),
                    MCP_FALSE,
                    ("_CCM_VAC_AllocationEngine_TryAllocate: attempting to allocate resource %s "
                     "which is unavailable, for operation %s", _CCM_VAC_DebugResourceStr (eResource),
                     _CCM_VAC_DebugOperationStr (*peOperation)));

    /* if the resource is currently not allocated at all */
    if (0 == ptAllocEngine->tResources[ eResource ].uNumberOfOwners)
    {
        MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: no current owner, resource is allocated"));

        /* allocate the resource to the requesting operation */
        ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ] = *peOperation;
        ptAllocEngine->tResources[ eResource ].uNumberOfOwners++;
        status = MCP_TRUE;
    }
    /* one operation is already holding the resource */
    else if (1 == ptAllocEngine->tResources[ eResource ].uNumberOfOwners)
    {
        TCAL_OperationPair      tNewPair;

        /* first check if this is a re-allocation (e.g. for resource change) */
        if (*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ])
        {
            MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owning the "
                           "resource, allocation succeeds", 
                           _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ])));
            status = MCP_TRUE;
        }
        /* now check if both operations may share the resource */
        else
        {
            /* fill in the new operation pair */
            tNewPair.eOperations[ 0 ] = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ];
            tNewPair.eOperations[ 1 ] = *peOperation;
    
            /* if the new pair is allowed */
            if (MCP_TRUE == _CCM_VAC_AEIsPairAllowed (ptAllocEngine, eResource, &tNewPair))
            {
                MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owning the "
                                   "resource, operation pair is allowed, allocation succeeded", 
                                   _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ])));
    
                /* fill in the new operation mutually owning the resource */
                ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ] = *peOperation;
                ptAllocEngine->tResources[ eResource ].uNumberOfOwners++;
                status = MCP_TRUE;
            }
            else
            {
                MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operation %s already owns the "
                               "resource, allocation failed", 
                               _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ])));

                /* indicate current owner */
                *peOperation = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ];
                status = MCP_FALSE;
            }
        }
    }
    /* two operations are currently mutually owning the resource */
    else
    {
        /* first check if this is a re-allocation */
        if ((*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]) || 
            (*peOperation == ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ]))
        {
            MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operations %s and %s already owning the "
                           "resource, allocation succeeded", 
                           _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]),
                           _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ])));
            status = MCP_TRUE;
        }
        else
        {
            MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_TryAllocate: operations %s and %s already owning the "
                           "resource, allocation failed", 
                           _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]),
                           _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ])));
    
            /* the current owner is indicated as the first operation */
            *peOperation = ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ];
            status = MCP_FALSE;
        }
    }

    MCP_FUNC_END ();

    return status;
}
_CcmImStatus _CCM_IM_BtTranSm_InternalHandleEvent(  _CcmIm_BtTranSm_Obj         *thisObj, 
                                                                _CcmIm_BtTranSm_Event   event,
                                                                void                        *eventData)
{
    _CcmImStatus                status;
    _CcmIm_BtTranSm_Entry       *smEntry;
    
    MCP_FUNC_START("_CCM_IM_BtTranSm_InternalHandleEvent");
    
    MCP_VERIFY_FATAL((thisObj != NULL), _CCM_IM_STATUS_INVALID_PARM, ("_CCM_IM_BtTranSm_InternalHandleEvent: Null this"));
    MCP_VERIFY_FATAL((event < _CCM_IM_NUM_OF_BT_TRAN_SM_EVENTS), _CCM_IM_STATUS_INVALID_PARM,
                        ("_CCM_IM_BtTranSm_InternalHandleEvent: Invalid event (%d)", event));

    MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: Handling SM{%s, %s}", 
                    _CCM_IM_BtTranSm_DebugStatetStr(thisObj->state),
                    _CCM_IM_BtTranSm_DebugEventStr(event)));
    
    /* Extract the SM entry matching the current {state, event} */
    smEntry = &_ccmIm_BtTranSm_Data.sm[thisObj->state][event];
    
    MCP_VERIFY_FATAL((smEntry->action != NULL), _CCM_IM_STATUS_NULL_SM_ENTRY, 
                        ("_CCM_IM_BtTranSm_InternalHandleEvent: No matching SM Entry"));
    
    /* Transit to the next SM state */
    thisObj->state = smEntry->nextState;

    /* The entry is valid, invoke the action */
    status = (smEntry->action)(thisObj, eventData);

    if (status == _CCM_IM_STATUS_SUCCESS)
    {
        MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: Action Completed Synchronously"));
    }
    else if (status == _CCM_IM_STATUS_PENDING)
    {
        thisObj->asyncCompletion = MCP_TRUE;   
    }
    else
    {
        /* Action failed */
        MCP_FATAL(status, ("_CCM_IM_BtTranSm_InternalHandleEvent"));
    }
    
    if (status == _CCM_IM_STATUS_SUCCESS)
    {   
        MCP_VERIFY_FATAL((smEntry->syncNextEvent != _CCM_IM_INVALID_BT_TRAN_SM_EVENT), 
                            _CCM_IM_STATUS_INTERNAL_ERROR, 
                            ("_CCM_IM_BtTranSm_InternalHandleEvent: Missing syncNextEvent"));

        if (smEntry->syncNextEvent != _CCM_IM_BT_TRAN_SM_EVENT_NULL_EVENT)
        {
            status = _CCM_IM_BtTranSm_InternalHandleEvent(thisObj, smEntry->syncNextEvent, NULL);
        }
    }

    MCP_LOG_INFO(("_CCM_IM_BtTranSm_InternalHandleEvent: On Exit, State: %s", _CCM_IM_BtTranSm_DebugStatetStr(thisObj->state)));
    
    MCP_FUNC_END();
    
    return status;
}
void _CCM_VAC_AllocationEngine_Release (TCCM_VAC_AllocationEngine *ptAllocEngine,
                                        ECAL_Resource eResource,
                                        ECAL_Operation eOperation)
{
    MCP_FUNC_START ("_CCM_VAC_AllocationEngine_Release");

    MCP_LOG_INFO (("_CCM_VAC_AllocationEngine_Release: operation %s releasing resource %s",
                   _CCM_VAC_DebugOperationStr(eOperation),
                   _CCM_VAC_DebugResourceStr (eResource)));

    /* verify object pointer, resource availability, and resource allocation */
    MCP_VERIFY_FATAL_NO_RETVAR ((NULL != ptAllocEngine),
                                ("_CCM_VAC_AllocationEngine_Release: NULL object!"));
    MCP_VERIFY_ERR_NO_RETVAR ((MCP_TRUE == ptAllocEngine->tResources[ eResource ].bAvailable),
                              ("_CCM_VAC_AllocationEngine_Release: attempting to release resource %s "
                               "which is unavailable, by operation %s",
                               _CCM_VAC_DebugResourceStr (eResource),
                               _CCM_VAC_DebugOperationStr (eOperation)));
    MCP_VERIFY_ERR_NO_RETVAR ((0 < ptAllocEngine->tResources[ eResource ].uNumberOfOwners),
                              ("_CCM_VAC_AllocationEngine_Release: resource %s is not allocated!",
                               _CCM_VAC_DebugResourceStr (eResource)));
    
    /* if the resource is allocated by only one operation */
    if (1 == ptAllocEngine->tResources[ eResource ].uNumberOfOwners)
    {
        /* verify resource owner is the requesting operation */
        MCP_VERIFY_ERR_NO_RETVAR ((ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ] == eOperation),
                                  ("_CCM_VAC_AllocationEngine_Release: operation %s requesting to release "
                                   "resource %s, which is allocated to operation %s!",
                                   _CCM_VAC_DebugOperationStr(eOperation),
                                   _CCM_VAC_DebugResourceStr (eResource),
                                   _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ])));

        /* release the resource */
        ptAllocEngine->tResources[ eResource ].uNumberOfOwners--;
    }
    /* the resource is mutually allocated by two operations */
    else
    {
        /* the requesting operation is in first place */
        if (ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ] == eOperation)
        {
            /* move the operation in second place to first place */
            ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ] = 
                ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ];
            /* reduce number of owners */
            ptAllocEngine->tResources[ eResource ].uNumberOfOwners--;
        }
        /* the requesting operation is in second place */
        else if (ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ] == eOperation)
        {
            /* simply reduce number of owners */
            ptAllocEngine->tResources[ eResource ].uNumberOfOwners--;
        }
        else
        {
            MCP_ERR_NO_RETVAR (("_CCM_VAC_AllocationEngine_Release: resource %s ia allocated to "
                                "operations %s and %s!",
                                _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 0 ]),
                                _CCM_VAC_DebugOperationStr(ptAllocEngine->tResources[ eResource ].eCurrentOwners[ 1 ])));
        }
    }

    MCP_FUNC_END ();
}