McpPoolStatus MCP_POOL_IsElelementAllocated(McpPool *pool, const void* element, McpBool *answer) { McpPoolStatus status = MCP_POOL_STATUS_SUCCESS; /* Map the element's address to a map index */ McpU32 freedIndex = MCP_POOL_INVALID_ELEMENT_INDEX; MCP_FUNC_START("MCP_POOL_IsElelementAllocated"); MCP_VERIFY_FATAL((0 != pool), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null pool argument")); MCP_VERIFY_FATAL((0 != element), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null element argument")); MCP_VERIFY_FATAL((0 != answer), MCP_POOL_STATUS_INTERNAL_ERROR, ("Null answer argument")); MCP_VERIFY_FATAL((MCP_FALSE == MCP_POOL_IsDestroyed(pool)), MCP_POOL_STATUS_INTERNAL_ERROR, ("Pool Already Destroyed")); freedIndex = MCP_POOL_GetElementIndexFromAddress(pool, (void*)element); MCP_VERIFY_ERR((MCP_POOL_INVALID_ELEMENT_INDEX != freedIndex), MCP_POOL_STATUS_INVALID_PARM, ("Invalid element address")); if (MCP_POOL_ALLOCATED_ELEMENT_MAP_INDICATION == pool->allocationMap[freedIndex]) { *answer = MCP_TRUE; } else { *answer = MCP_FALSE; } MCP_FUNC_END(); return status; }
/*------------------------------------------------------------------------------ * Call back function for the script processor to send an HCI command *------------------------------------------------------------------------------ */ McpBtsSpStatus MCP_LM_SendHciCmdCB (McpBtsSpContext *context, McpU16 hciOpcode, McpU8 *hciCmdParms, McpUint hciCmdParmsLen) { McpBtsSpStatus status = MCP_BTS_SP_STATUS_PENDING; BtHciIfStatus btHciIfStatus; MCP_FUNC_START("MCP_LM_SendHciCmdCB"); MCP_UNUSED_PARAMETER(context); btHciIfStatus = BT_HCI_IF_SendHciCommand(handle, (BtHciIfHciOpcode)hciOpcode, hciCmdParms, (McpU8)hciCmdParmsLen, BT_HCI_IF_HCI_EVENT_COMMAND_COMPLETE, NULL); MCP_VERIFY_ERR((btHciIfStatus == BT_HCI_IF_STATUS_PENDING), MCP_BTS_SP_STATUS_FAILED, ("MCP_LM_SendHciCmdCB: BT_HCI_IF_SendHciCommand Failed")); MCP_FUNC_END(); return status; }
McpHalStatus MCP_LoadMngr_StopLoadScript(TLoadMngrCB fCB, void *pUserData) { McpHalStatus status; MCP_FUNC_START("MCP_LoadMngr_StopLoadScript"); /* check for preliminary conditions that there is a CB */ MCP_VERIFY_ERR ((NULL != fCB), MCP_HAL_STATUS_FAILED, ("MCP_LoadMngr_LoadScript: NULL CB!")); /* Update CB and user data */ fCb = fCB; pUserData = (void*)pUserData; /*Send an MCP_LM_EVENT_ABORT event to the SM*/ MCP_GenSM_Event (&tDataGenSm, MCP_LM_EVENT_ABORT, NULL); /* * copy the SM status to 'status', to avoid compilation warning and * allow VERIFY_ERR above to return correct status */ status = iLoadSmstatus; MCP_FUNC_END(); return status; }
/* The function needs to do the following: - Perform CCM "class" static initialization (if necessary - first time) - "Create" the instance (again, if it's the first creation of this instance) */ CcmStatus CCM_Create(McpHalChipId chipId, CcmObj **thisObj) { CcmStatus status; CcmImStatus imStatus; ECCM_VAC_Status vacStatus; McpConfigParserStatus eConfigParserStatus; McpUtf8 scriptPath[MCP_HAL_CONFIG_FS_MAX_PATH_LEN_CHARS * MCP_HAL_CONFIG_MAX_BYTES_IN_UTF8_CHAR] = ""; MCP_FUNC_START("CCM_Create"); MCP_VERIFY_FATAL((chipId < MCP_HAL_MAX_NUM_OF_CHIPS), CCM_STATUS_INTERNAL_ERROR, (("Invalid Chip Id"), chipId)); if (_CCM_StaticData._ccm_Objs[chipId].refCount == 0) { _CCM_StaticData._ccm_Objs[chipId].chipId = chipId; /* read ini file */ MCP_StrCpyUtf8(scriptPath, (const McpUtf8 *)CCM_VAC_CONFIG_PATH_NAME); MCP_StrCatUtf8(scriptPath, (const McpUtf8 *)CCM_VAC_CONFIG_FILE_NAME); eConfigParserStatus = MCP_CONFIG_PARSER_Open(scriptPath, (McpU8*)CCM_VAC_MEM_CONFIG, &(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); MCP_VERIFY_ERR ((MCP_CONFIG_PARSER_STATUS_SUCCESS == eConfigParserStatus), CCM_VAC_STATUS_FAILURE_UNSPECIFIED, ("_CCM_VAC_ConfigurationEngine_Create: reading config file failed with status %d", eConfigParserStatus)); imStatus = CCM_IM_Create(chipId, &_CCM_StaticData._ccm_Objs[chipId].imObj, _CCM_NotifyChipOn, &_CCM_StaticData._ccm_Objs[chipId]); MCP_VERIFY_FATAL((imStatus == CCM_IM_STATUS_SUCCESS), CCM_STATUS_INTERNAL_ERROR, ("CCM_IM_Create Failed")); CAL_Create (chipId, CCM_IMI_GetBtHciIfObj (_CCM_StaticData._ccm_Objs[chipId].imObj), &(_CCM_StaticData._ccm_Objs[chipId].calObj),&(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); /* CAL creation cannot fail */ vacStatus = CCM_VAC_Create (chipId, _CCM_StaticData._ccm_Objs[chipId].calObj, &(_CCM_StaticData._ccm_Objs[chipId].vacObj), &(_CCM_StaticData._ccm_Objs[chipId].tConfigParser)); MCP_VERIFY_FATAL ((CCM_VAC_STATUS_SUCCESS == vacStatus), CCM_STATUS_INTERNAL_ERROR, ("CCM_Create: VAC creation failed with status %d", vacStatus)); } ++_CCM_StaticData._ccm_Objs[chipId].refCount; /* Set the instance pointer (out parameter) to be used in external references to this instance */ *thisObj = &_CCM_StaticData._ccm_Objs[chipId]; status = CCM_STATUS_SUCCESS; MCP_FUNC_END(); return status; }
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; }
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; }