Ejemplo n.º 1
0
/* Start Conjure Library */
eEsifError EsifConjureStart(EsifCnjPtr conjurePtr)
{
	eEsifError rc = ESIF_OK;
	GetIfaceFuncPtr iface_func_ptr = NULL;
	EsifString iface_func_name     = "GetConjureInterface";

	char libPath[ESIF_LIBPATH_LEN];

	ESIF_TRACE_DEBUG("%s name=%s\n", ESIF_FUNC, conjurePtr->fLibNamePtr);
	esif_build_path(libPath, ESIF_LIBPATH_LEN, ESIF_PATHTYPE_DLL, conjurePtr->fLibNamePtr, ESIF_LIB_EXT);
	conjurePtr->fLibHandle = esif_ccb_library_load(libPath);

	if (NULL == conjurePtr->fLibHandle) {
		rc = ESIF_E_UNSPECIFIED;
		ESIF_TRACE_ERROR("%s esif_ccb_library_load() %s failed.\n", ESIF_FUNC, libPath);
		goto exit;
	}
	ESIF_TRACE_DEBUG("%s esif_ccb_library_load() %s completed.\n", ESIF_FUNC, libPath);

	iface_func_ptr = (GetIfaceFuncPtr)esif_ccb_library_get_func(conjurePtr->fLibHandle, (EsifString)iface_func_name);
	if (NULL == iface_func_ptr) {
		rc = ESIF_E_UNSPECIFIED;
		ESIF_TRACE_ERROR("%s esif_ccb_library_get_func() %s failed.\n", ESIF_FUNC, iface_func_name);
		goto exit;
	}

	ESIF_TRACE_DEBUG("%s esif_ccb_library_get_func() %s completed.\n", ESIF_FUNC, iface_func_name);
	rc = ConjureCreate(conjurePtr, iface_func_ptr);
	ESIF_TRACE_DEBUG("%s ConjureCreate completed.\n", ESIF_FUNC);
exit:
	return rc;
}
Ejemplo n.º 2
0
/* Unregister Upper Participant Instance */
eEsifError EsifUpManagerUnregisterParticipant(
	const eEsifParticipantOrigin origin,
	const void *participantHandle
	)
{
	eEsifError rc    = ESIF_OK;
	EsifUpManagerEntryPtr entry_ptr = NULL;
	EsifUpPtr up_ptr = NULL;
	UInt8 instance;

	UNREFERENCED_PARAMETER(origin);

	/* Validate parameters */
	if (NULL == participantHandle) {
		ESIF_TRACE_ERROR("The participant handle pointer is NULL\n");
		ESIF_ASSERT(participantHandle != NULL);
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	instance = *(UInt8 *)participantHandle;

	if (instance >= MAX_PARTICIPANT_ENTRY) {
		ESIF_TRACE_ERROR("Instance id %d is out of range\n", instance);
		rc = ESIF_E_PARAMETER_IS_OUT_OF_BOUNDS;
		goto exit;
	}

	esif_ccb_write_lock(&g_uppMgr.fLock);

	entry_ptr = &g_uppMgr.fEntries[instance];
	if (NULL != entry_ptr) {
		up_ptr = entry_ptr->fUpPtr;
		if (NULL != up_ptr) {
			entry_ptr->fState = ESIF_PM_PARTICIPANT_REMOVED;
			g_uppMgr.fEntryCount--;
		}
	}
	esif_ccb_write_unlock(&g_uppMgr.fLock);

	if (NULL != up_ptr) {
		rc = EsifAppMgrDestroyParticipantInAllApps(up_ptr);
	}

	ESIF_TRACE_INFO("Unregister participant, instant id = %d\n", instance);
exit:
	return rc;
}
Ejemplo n.º 3
0
/* Map a participant handle to  */
eEsifError EsifUpManagerMapLpidToPartHandle(
	const UInt8 lpInstance,
	void *participantHandle
	)
{
	eEsifError rc    = ESIF_E_INVALID_HANDLE;
	UInt8 i = 0;

	/* Validate parameters */
	if (NULL == participantHandle) {
		ESIF_TRACE_ERROR("The participant handle pointer is NULL\n");
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	esif_ccb_read_lock(&g_uppMgr.fLock);

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		if (g_uppMgr.fEntries[i].fUpPtr && (g_uppMgr.fEntries[i].fUpPtr->fLpInstance == lpInstance)) {
			break;
		}
	}

	esif_ccb_read_unlock(&g_uppMgr.fLock);

	if (i >= MAX_PARTICIPANT_ENTRY) {
		goto exit;
	}

	*(UInt8 *)participantHandle = i;
	rc = ESIF_OK;

exit:
	return rc;
}
Ejemplo n.º 4
0
/* Check if a participant already exists by the name */
Bool EsifUpManagerDoesAvailableParticipantExistByName (
	char *participantName
	)
{
	Bool bRet = ESIF_FALSE;
	EsifUpPtr up_ptr = NULL;
	UInt8 i;

	if (NULL == participantName) {
		ESIF_TRACE_ERROR("The participant name pointer is NULL\n");
		goto exit;
	}

	esif_ccb_read_lock(&g_uppMgr.fLock);

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		up_ptr = EsifUpManagerGetAvailableParticipantByInstance(i);

		if (NULL == up_ptr) {
			continue;
		}

		if ((g_uppMgr.fEntries[i].fState > ESIF_PM_PARTICIPANT_REMOVED) && !strcmp(up_ptr->fMetadata.fName, participantName)) {
			bRet = ESIF_TRUE;
			break;
		}
	}
	esif_ccb_read_unlock(&g_uppMgr.fLock);
exit:
	return bRet;
}
Ejemplo n.º 5
0
static eEsifError EsifAct_CallIfaceDestroy(EsifActPtr self)
{
	eEsifError rc = ESIF_OK;

	if (self == NULL) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	if (self->createCalled) {
		switch (self->iface.hdr.fIfaceVersion) {
		case ESIF_ACT_IFACE_VER_STATIC:
			if (self->iface.ifaceStatic.destroyFuncPtr != NULL) {
				rc = self->iface.ifaceStatic.destroyFuncPtr(self->actCtx);
			}
			break;
		case ESIF_ACT_IFACE_VER_V1:
			if (self->iface.actIfaceV1.destroyFuncPtr != NULL) {
				rc = self->iface.actIfaceV1.destroyFuncPtr(self->actCtx);		
			}
			break;
		default:
			break;
		}
		if (ESIF_OK != rc) {
			ESIF_TRACE_ERROR("Error destroying action. Error Code : %x", rc);
		}	
	}
exit:
	return rc;
}
Ejemplo n.º 6
0
/* Removes a participant from each running application */
eEsifError EsifAppMgrDestroyParticipantInAllApps(const EsifUpPtr upPtr)
{
	eEsifError rc = ESIF_OK;
	EsifAppPtr app_ptr = NULL;
	UInt8 i;

	if (NULL == upPtr) {
		ESIF_TRACE_ERROR("The participant data pointer is NULL\n");
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	esif_ccb_read_lock(&g_appMgr.fLock);

	for (i = 0; i < ESIF_MAX_APPS; i++) {
		app_ptr = &g_appMgr.fEntries[i];

		if (NULL != app_ptr->fHandle) {
			EsifAppDestroyParticipant(app_ptr, upPtr);
		}
	}

	esif_ccb_read_unlock(&g_appMgr.fLock);
exit:
	return rc;
}
Ejemplo n.º 7
0
// IPC Auto Connect
eEsifError ipc_autoconnect(UInt32 max_retries)
{
	eEsifError rc = ESIF_OK;
	UInt32 connect_retries = 0;

	ESIF_TRACE_ENTRY_INFO();

	if (g_ipc_handle != ESIF_INVALID_HANDLE) {
		return rc;
	}

	// Attempt to connect to LF indefinitely until ESIF exits (unless the LF version is unsupported)
	while (!g_quit) {
		rc = ipc_connect();
		if (rc == ESIF_OK || rc == ESIF_E_NOT_SUPPORTED) {
			break;
		}

		if (max_retries > 0 && ++connect_retries >= max_retries) {
			ESIF_TRACE_ERROR("Unable to do an IPC connect\n");
			break;
		}

		esif_ccb_sleep(1);
	}
	ESIF_TRACE_EXIT_INFO_W_STATUS(rc);
	return rc;
}
Ejemplo n.º 8
0
eEsifError EsifUpManagerRegisterParticipantsWithApp(EsifAppPtr aAppPtr)
{
	eEsifError rc = ESIF_OK;
	UInt8 i = 0;

	if (NULL == aAppPtr) {
		ESIF_TRACE_ERROR("Esif app pointer is NULL\n");
		return ESIF_E_PARAMETER_IS_NULL;
	}

	esif_ccb_read_lock(&g_uppMgr.fLock);

	/* Skip 0 ESIF treats this as a participant no one else does :) */
	for (i = 1; i < MAX_PARTICIPANT_ENTRY; i++) {
		EsifUpPtr up_ptr = g_uppMgr.fEntries[i].fUpPtr;
		if ((NULL != up_ptr) && (g_uppMgr.fEntries[i].fState > ESIF_PM_PARTICIPANT_REMOVED)) {
			rc = EsifAppCreateParticipant(aAppPtr, up_ptr);
			if (ESIF_OK != rc) {
				break;
			}
		}
	}

	esif_ccb_read_unlock(&g_uppMgr.fLock);

	ESIF_TRACE_INFO("Register participants with App, status = %s\n", esif_rc_str(rc));
	return rc;
}
Ejemplo n.º 9
0
/* Destroy Hash Table */
void esif_ht_destroy(
    struct esif_ht *self,
    item_destroy_func item_destroy_fptr
)
{
    u32 index = 0;

    if ((self == NULL) || (self->table == NULL)) {
        ESIF_TRACE_ERROR("Hash table ptr NULL\n");
        goto exit;
    }

    ESIF_TRACE_DYN_VERB("Destroying hash table %p\n", self);

    for (index = 0; index < self->size; ++index) {
        if (self->table[index] == NULL)
            continue;

        ESIF_TRACE_DYN_VERB("Destroy linked list %d\n", index);

        esif_destroy_ht_nodes(self->table[index], item_destroy_fptr);
        esif_link_list_destroy(self->table[index]);
        self->table[index] = NULL;
    }

    esif_ccb_free(self->table);
    esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_HASH2, self);
exit:
    return;
}
Ejemplo n.º 10
0
void * esif_ht_get_item(
    struct esif_ht *self,
    u8 *key_ptr,
    u32 key_length
)
{
    struct esif_ht_node *ht_node = NULL;
    void *item_ptr = NULL;

    if ((key_ptr == NULL) || (self == NULL)) {
        ESIF_TRACE_ERROR("NULL ptr passed in\n");
        goto exit;
    }

    ht_node = esif_ht_get_ht_node(self,
                                  key_ptr,
                                  key_length);
    if (ht_node == NULL) {
        ESIF_TRACE_DYN_VERB("HT node data not found for passed in key\n");
        goto exit;
    }

    item_ptr = ht_node->item_ptr;
exit:
    return item_ptr;
}
Ejemplo n.º 11
0
/* Get By Instance From ID */
EsifUpPtr EsifUpManagerGetAvailableParticipantByInstance (
	const UInt8 id
	)
{
	EsifUpPtr up_ptr = NULL;
	ESIF_TRACE_DEBUG("%s: instance %d\n", ESIF_FUNC, id);

	if (id >= MAX_PARTICIPANT_ENTRY) {
		ESIF_TRACE_ERROR("Instance id %d is out of range\n", id);
		ESIF_ASSERT(0);
		goto exit;
	}

	/* Lock manager */
	esif_ccb_read_lock(&g_uppMgr.fLock);

	if (g_uppMgr.fEntries[id].fState > ESIF_PM_PARTICIPANT_REMOVED) {
		up_ptr = g_uppMgr.fEntries[id].fUpPtr;
	}

	/* Unlock Manager */
	esif_ccb_read_unlock(&g_uppMgr.fLock);

exit:

	if (NULL == up_ptr) {
		ESIF_TRACE_DEBUG("%s: instance %d NOT found or OUT OF BOUNDS\n",
						 ESIF_FUNC, id);
	}
	return up_ptr;
}
Ejemplo n.º 12
0
EsifUpPtr EsifUpManagerGetAvailableParticipantByName (
	char *participantName
	)
{
	EsifUpPtr up_ptr = NULL;
	UInt8 i;

	if (NULL == participantName) {
		ESIF_TRACE_ERROR("The participant name pointer is NULL\n");
		goto exit;
	}

	esif_ccb_read_lock(&g_uppMgr.fLock);

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		up_ptr = EsifUpManagerGetAvailableParticipantByInstance(i);

		if (NULL == up_ptr) {
			continue;
		}
		if (!strcmp(participantName, up_ptr->fMetadata.fName)) {
			break;
		}
		up_ptr = NULL;
	}

	esif_ccb_read_unlock(&g_uppMgr.fLock);
exit:
	return up_ptr;
}
Ejemplo n.º 13
0
static void EsifDataLogSchedule(const void *ctx)
{
	eEsifError rc = ESIF_OK;

	UNREFERENCED_PARAMETER(ctx);

	if (dataLogContextPtr == NULL) {
		ESIF_TRACE_DEBUG("Data logging schedule fired had no context.\n");
		goto exit;
	}

	if (dataLogContextPtr->dataLogScheduleTimer == NULL) {
		ESIF_TRACE_DEBUG("Data logging schedule fired but had no reference to the members.\n");
		goto exit;
	}

	/*
	* Serialize access to the datalog state.
	*/
	while (atomic_set(&g_dataLogLock, ESIF_TRUE)) {
		esif_ccb_sleep_msec(ESIF_DATALOG_LOCK_SLEEP_MS);
	}

	if (EsifDataIsLogStarted()){
		ESIF_TRACE_DEBUG("Data logging schedule fired but was already started.\n");
		goto exit;
	}

	rc = EsifDataLogValidateParticipantList(dataLogContextPtr->dataLogParticipantList);
	if (rc != ESIF_OK) {
		ESIF_TRACE_ERROR("There was a problem with your participant list. You may have selected invalid participants, or too many participants. \n");
		goto exit;
	}
	rc = EsifDataLogOpenLogFile();
	if (rc != ESIF_OK) {
		ESIF_TRACE_ERROR("Error opening scheduled log file... \n");
		goto exit;
	}
	ESIF_TRACE_DEBUG("Data logging starting... \n");
	g_dataLogInterval = dataLogContextPtr->dataLogInterval;
	EsifDataLogStart();

exit:
	EsifDataLogCleanup();
	atomic_set(&g_dataLogLock, ESIF_FALSE);
}
Ejemplo n.º 14
0
static struct esif_ht_node *esif_alloc_ht_node(
    u8 *key_ptr,
    u32 key_length,
    void *item_ptr
)
{
    enum esif_rc rc = ESIF_OK;
    struct esif_ht_node *ht_node_ptr = NULL;

    ESIF_ASSERT(key_ptr != NULL);

    ht_node_ptr =
        (struct esif_ht_node *)esif_ccb_malloc(sizeof(*ht_node_ptr));
    if (ht_node_ptr == NULL) {
        ESIF_TRACE_ERROR("Unable to allocate HT node\n");
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    ht_node_ptr->key_ptr = esif_ccb_malloc(key_length);
    if (ht_node_ptr->key_ptr == NULL) {
        ESIF_TRACE_ERROR("Unable to allocate HT node key ptr\n");
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    esif_ccb_memcpy(ht_node_ptr->key_ptr, key_ptr, key_length);
    ht_node_ptr->key_length = key_length;
    ht_node_ptr->item_ptr = item_ptr;
exit:
    if (rc != ESIF_OK) {
        if (ht_node_ptr) {
            if (ht_node_ptr->key_ptr)
                esif_ccb_free(ht_node_ptr->key_ptr);

            esif_ccb_free(ht_node_ptr);
            ht_node_ptr = NULL;
        }
    }

    return ht_node_ptr;
}
Ejemplo n.º 15
0
static eEsifError EsifActMgr_GetTypeFromPossAct_Locked(
	EsifActMgrEntryPtr entryPtr,
	enum esif_action_type *typePtr
	)
{
	eEsifError rc = ESIF_OK;
	GetIfaceFuncPtr getIfacePtr = NULL;
	EsifActIface iface = {0};

	ESIF_ASSERT(entryPtr != NULL);
	ESIF_ASSERT(typePtr != NULL);

	/* If we already have the type from a previous search, return it */
	if (entryPtr->type != 0) {
		*typePtr = entryPtr->type;
	}

	/* If we don't already have the type; load the library and get the type */
	rc = EsifActMgr_LoadAction(entryPtr, &getIfacePtr);
	if (rc != ESIF_OK) {
		goto exit;
	}

	iface.hdr.fIfaceType = eIfaceTypeAction;
	iface.hdr.fIfaceVersion = ESIF_INTERFACE_VERSION;
	iface.hdr.fIfaceSize = sizeof(iface);

	rc = getIfacePtr(&iface);
	if (ESIF_OK != rc) {
		goto exit;
	}

	/* Check EsifActIface */
	if (iface.hdr.fIfaceType != eIfaceTypeAction ||
		iface.hdr.fIfaceVersion > ESIF_ACT_FACE_VER_MAX ||
		iface.hdr.fIfaceSize != EsifActIface_Sizeof(iface.hdr.fIfaceVersion)) {
		ESIF_TRACE_ERROR("The action interface does not meet requirements\n");
		goto exit;
	}

	/* Check if this type is already available; we only allow one instance */
	rc = EsifActIface_GetType(&iface, &entryPtr->type);
	if (rc != ESIF_OK) {
		goto exit;
	}

	*typePtr = entryPtr->type;
exit:
	if (rc != ESIF_OK) {
		EsifActMgr_UnloadAction(entryPtr);
	}
	return rc;
}
Ejemplo n.º 16
0
enum esif_rc esif_ht_add_item(
    struct esif_ht *self,
    u8 *key_ptr,
    u32 key_length,
    void *item_ptr
)
{
    enum esif_rc rc = ESIF_OK;
    struct esif_link_list *ll_ptr = NULL;
    struct esif_ht_node *ht_node = NULL;

    if ((key_ptr == NULL) || (self == NULL)) {
        ESIF_TRACE_DYN_VERB("NULL ptr passed in \n");
        rc = ESIF_E_PARAMETER_IS_NULL;
        goto exit;
    }

    ll_ptr = esif_ht_get_ll(self, key_ptr, key_length);
    if (ll_ptr == NULL) {
        ESIF_ASSERT(ESIF_FALSE); /* Should never happen */
        ESIF_TRACE_DYN_VERB("LL NULL for passed in key\n");
        rc = ESIF_E_NOT_FOUND;
        goto exit;
    }

    ht_node = esif_alloc_ht_node(key_ptr, key_length, item_ptr);
    if (ht_node == NULL) {
        rc = ESIF_E_NO_MEMORY;
        goto exit;
    }

    rc = esif_link_list_add_at_back(ll_ptr, (void *)ht_node);
    if (rc != ESIF_OK) {
        ESIF_TRACE_ERROR("Unable to add new HT link list node\n");
        goto exit;
    }

    ESIF_TRACE_DYN_VERB(
        "Key %p, key size %d, item %p, table %p ll %p\n",
        key_ptr,
        key_length,
        item_ptr,
        self,
        ll_ptr);
exit:
    if (rc != ESIF_OK) {
        if (ht_node != NULL)
            esif_destroy_ht_node(ht_node);
    }

    return rc;
}
Ejemplo n.º 17
0
// Dispatch An Event
void EsifEvent_GetAndSignalIpcEvent()
{
#ifdef ESIF_FEAT_OPT_ACTION_SYSFS
	// NOOP
#else
	int r_bytes     = 0;
	int data_len    = 1024;	/* TODO: Change from "magic number" */
	enum esif_rc rc = ESIF_OK;
	struct esif_ipc *ipc_ptr = NULL;
	struct esif_ipc_event *event_ptr = NULL;

	ipc_ptr = esif_ipc_alloc_event(&event_ptr, data_len);
	if (NULL == ipc_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate esif_ipc\n");
		return;
	}

//
// TODO:  This needs to be in an OS abstraction layer
//
#ifdef ESIF_ATTR_OS_LINUX
	r_bytes = read(g_ipc_handle, ipc_ptr, data_len);
#endif
#ifdef ESIF_ATTR_OS_WINDOWS

	rc = ipc_execute(ipc_ptr);
	//
	// TODO:  The return size check is a W/A until a better solution is developed to determine if an event was returned.
	// (The current LF code does not change the original data_len or fail the request if there are not events.)
	//
	r_bytes = 0;
	if ((ESIF_OK == rc) && (ipc_ptr->data_len != (u32)data_len)) {
		r_bytes = ipc_ptr->data_len;
	}
#endif

	// Have Event?
	if (r_bytes > 0) {
		ESIF_TRACE_DEBUG("IPC version=%d, type=%d, len = %d, data_len=%d\n",
			ipc_ptr->version,
			ipc_ptr->type,
			r_bytes,
			ipc_ptr->data_len);

		EsifEvent_SignalIpcEvent(event_ptr);
	}
	esif_ipc_free(ipc_ptr);
#endif
}
Ejemplo n.º 18
0
/* Data For Interface Marshaling */
static AppDataPtr CreateAppData(esif_string pathBuf)
{
	AppDataPtr app_data_ptr = NULL;
	char policyPath[ESIF_PATH_LEN] = { 0 };

	if (NULL == pathBuf) {
		ESIF_TRACE_ERROR("Path buffer is NULL\n");
		goto exit;
	}

	/* Build path(s) for DPTF: "HomeDir" or "HomeDir|[#]PolicyDir" */
	esif_build_path(pathBuf, ESIF_PATH_LEN, ESIF_PATHTYPE_DPTF, NULL, NULL);
	esif_build_path(policyPath, sizeof(policyPath), ESIF_PATHTYPE_DLL, NULL, NULL);
	if (esif_ccb_strcmp(pathBuf, policyPath) != 0) {
		char policyDummyPath[ESIF_PATH_LEN] = { 0 }; /* empty if path starts with "#" */
		esif_build_path(policyDummyPath, sizeof(policyDummyPath), ESIF_PATHTYPE_DLL, "", NULL);
		esif_ccb_sprintf_concat(ESIF_PATH_LEN, pathBuf, "|%s%s", (policyDummyPath[0] ? "" : "#"), policyPath);
	}
	ESIF_TRACE_DEBUG("pathBuf=%s\n\n", (esif_string)pathBuf);

	app_data_ptr = (AppDataPtr)esif_ccb_malloc(sizeof(AppData));
	if (NULL == app_data_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate AppData\n");
		goto exit;
	}

	app_data_ptr->fPathHome.buf_ptr  = (void *)pathBuf;
	app_data_ptr->fPathHome.buf_len  = ESIF_PATH_LEN;
	app_data_ptr->fPathHome.data_len = (UInt32)esif_ccb_strlen(pathBuf, ESIF_PATH_LEN);
	app_data_ptr->fPathHome.type     = ESIF_DATA_STRING;
	app_data_ptr->fLogLevel          = (eLogType) g_traceLevel;

exit:

	return app_data_ptr;
}
Ejemplo n.º 19
0
static eEsifError EsifActMgr_UnloadAction(EsifActMgrEntryPtr entryPtr)
{
	eEsifError rc = ESIF_OK;

	if (entryPtr == NULL) {
		ESIF_TRACE_ERROR("\tactPtr is NULL");
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}

	esif_ccb_library_unload(entryPtr->lib);
	entryPtr->lib = NULL;
exit:
	return rc;
}
Ejemplo n.º 20
0
static eEsifError EsifActMgr_LoadAction(
	EsifActMgrEntryPtr entryPtr,
	GetIfaceFuncPtr *getIfacePtr
	)
{
	eEsifError rc = ESIF_OK;
	GetIfaceFuncPtr ifaceFuncPtr = NULL;
	EsifString ifaceFuncName     = "GetActionInterface";
	char libPath[ESIF_LIBPATH_LEN];

	ESIF_ASSERT(entryPtr != NULL);
	ESIF_ASSERT(getIfacePtr != NULL);

	ESIF_TRACE_DEBUG("Name=%s\n", entryPtr->libName);
	esif_build_path(libPath, sizeof(libPath), ESIF_PATHTYPE_DLL, entryPtr->libName, ESIF_LIB_EXT);
	entryPtr->lib = esif_ccb_library_load(libPath);

	if (NULL == entryPtr->lib || NULL == entryPtr->lib->handle) {
		rc = esif_ccb_library_error(entryPtr->lib);
		ESIF_TRACE_ERROR("esif_ccb_library_load() %s failed [%s (%d)]: %s\n", libPath, esif_rc_str(rc), rc, esif_ccb_library_errormsg(entryPtr->lib));
		goto exit;
	}
	ESIF_TRACE_DEBUG("esif_ccb_library_load() %s completed.\n", libPath);

	ifaceFuncPtr = (GetIfaceFuncPtr)esif_ccb_library_get_func(entryPtr->lib, (EsifString)ifaceFuncName);
	if (NULL == ifaceFuncPtr) {
		rc = esif_ccb_library_error(entryPtr->lib);
		ESIF_TRACE_ERROR("esif_ccb_library_get_func() %s failed [%s (%d)]: %s\n", libPath, esif_rc_str(rc), rc, esif_ccb_library_errormsg(entryPtr->lib));
		goto exit;
	}
	ESIF_TRACE_DEBUG("esif_ccb_library_get_func() %s completed.\n", ifaceFuncName);

	*getIfacePtr = ifaceFuncPtr;
exit:
	return rc;
}
Ejemplo n.º 21
0
// IPC Connect
eEsifError ipc_connect()
{
	eEsifError rc = ESIF_OK;
	int check_kernel_version = ESIF_TRUE;

	ESIF_TRACE_ENTRY_INFO();

	// Exit if IPC already connected
	if (g_ipc_handle != ESIF_INVALID_HANDLE) {
		return ESIF_OK;
	}

	// Connect to LF
	g_ipc_handle = esif_ipc_connect((char *)SESSION_ID);
	if (g_ipc_handle == ESIF_INVALID_HANDLE) {
		ESIF_TRACE_WARN("ESIF LF is not available\n");
		rc = ESIF_E_NO_LOWER_FRAMEWORK;
	}
	else {
		char *outbuf = esif_ccb_malloc(OUT_BUF_LEN);
		char *kern_str = (outbuf != NULL ? esif_cmd_info(outbuf) : NULL);
		ESIF_TRACE_DEBUG("ESIF IPC Kernel Device Opened\n");
		if (NULL != kern_str) {
			// Extract just the Kernel LF Version from the result string
			extract_kernel_version(kern_str, OUT_BUF_LEN);

			// Bypass Kernel Version check for DEBUG builds
			#if defined(ESIF_ATTR_DEBUG)
			check_kernel_version = ESIF_FALSE;
			#endif

			// Validate Kernel LF version is compatible with UF version
			if (check_kernel_version == ESIF_FALSE || esif_ccb_strcmp(kern_str, ESIF_VERSION) == 0) {
				ESIF_TRACE_INFO("Kernel Version: %s\n", kern_str);
				esif_ccb_sprintf(sizeof(g_esif_kernel_version), g_esif_kernel_version, "%s", kern_str);
			}
			else {
				ESIF_TRACE_ERROR("ESIF_LF Version (%s) Incompatible with ESIF_UF Version (%s)\n", kern_str, ESIF_VERSION);
				ipc_disconnect();
				rc = ESIF_E_NOT_SUPPORTED;
			}
		}
		esif_ccb_free(outbuf);
	}
	ESIF_TRACE_EXIT_INFO_W_STATUS(rc);
	return rc;
}
Ejemplo n.º 22
0
enum esif_rc esif_ht_remove_item(
    struct esif_ht *self,
    u8 *key_ptr,
    u32 key_length
)
{
    enum esif_rc rc = ESIF_OK;
    struct esif_link_list *ll_ptr = NULL;
    struct esif_link_list_node *ll_node = NULL;
    struct esif_ht_node *ht_node = NULL;

    if ((key_ptr == NULL) || (self == NULL)) {
        ESIF_TRACE_ERROR("NULL ptr passed in\n");
        rc = ESIF_E_PARAMETER_IS_NULL;
        goto exit;
    }

    ll_ptr = esif_ht_get_ll(self, key_ptr, key_length);
    if (ll_ptr == NULL) {
        ESIF_ASSERT(ESIF_FALSE); /* Should never happen */
        ESIF_TRACE_DYN_VERB("LL NULL for passed in key\n");
        rc = ESIF_E_NOT_FOUND;
        goto exit;
    }

    ll_node = esif_find_node_in_ht_ll(ll_ptr, key_ptr, key_length);
    if (ll_node == NULL) {
        ESIF_TRACE_DYN_VERB("LL node not found for passed in key\n");
        rc = ESIF_E_NOT_FOUND;
        goto exit;
    }

    ht_node = (struct esif_ht_node *)ll_node->data_ptr;
    if (ht_node == NULL) {
        ESIF_ASSERT(ESIF_FALSE);
        ESIF_TRACE_DYN_VERB("ht_node NULL\n");
        rc = ESIF_E_PARAMETER_IS_NULL;
        goto exit;
    }

    esif_destroy_ht_node(ht_node);
    esif_link_list_node_remove(ll_ptr, ll_node);
exit:
    return rc;
}
Ejemplo n.º 23
0
static EsifUpManagerEntryPtr EsifUpManagerGetParticipantEntryFromMetadata(
	const eEsifParticipantOrigin origin,
	const void *metadataPtr
	)
{
	EsifUpManagerEntryPtr entry_ptr = NULL;
	char *participantName = "";
	UInt8 i;

	/* Validate parameters */
	if (NULL == metadataPtr) {
		ESIF_TRACE_ERROR("The meta data pointer is NULL\n");
		goto exit;
	}

	switch (origin) {
	case eParticipantOriginLF:
		participantName = ((struct esif_ipc_event_data_create_participant *)metadataPtr)->name;
		break;

	case eParticipantOriginUF:
		participantName = ((EsifParticipantIfacePtr)metadataPtr)->name;
		break;

	default:
		goto exit;
		break;
	}


	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		entry_ptr = &g_uppMgr.fEntries[i];

		if (NULL != entry_ptr->fUpPtr) {
			if (!strcmp(entry_ptr->fUpPtr->fMetadata.fName, participantName)) {
				break;
			}
		}
		entry_ptr = NULL;
	}

exit:
	return entry_ptr;
}
Ejemplo n.º 24
0
static eEsifError EsifActMgr_CreateAction(
	EsifActMgrEntryPtr entryPtr,
	EsifActIfacePtr actIfacePtr
	)
{
	eEsifError rc = ESIF_OK;
	enum esif_action_type actType = 0;
	EsifActPtr actPtr = NULL;

	ESIF_ASSERT(entryPtr != NULL);
	ESIF_ASSERT(actIfacePtr != NULL);

	/* Check EsifActIface */
	if (actIfacePtr->hdr.fIfaceType != eIfaceTypeAction ||
		actIfacePtr->hdr.fIfaceVersion > ESIF_ACT_FACE_VER_MAX ||
		actIfacePtr->hdr.fIfaceSize != EsifActIface_Sizeof(actIfacePtr->hdr.fIfaceVersion)) {
		ESIF_TRACE_ERROR("The action interface does not meet requirements\n");
		goto exit;
	}

	/* Check if this type is already available; we only allow one instance */
	rc = EsifActIface_GetType(actIfacePtr, &actType);
	if (rc != ESIF_OK) {
		goto exit;
	}

	actPtr = EsifActMgr_GetAction(actType, ACT_MGR_NO_UPINSTANCE);
	if (actPtr != NULL) {
		EsifAct_PutRef(actPtr);
		rc = ESIF_E_ACTION_ALREADY_STARTED;
		goto exit;
	}

	rc = EsifAct_CreateAction(actIfacePtr, entryPtr->upInstance, &actPtr);
	if (rc != ESIF_OK) {
		goto exit;
	}

	entryPtr->type = actPtr->type;
	entryPtr->actCtx = actPtr->actCtx;
	entryPtr->actPtr = actPtr;
exit:
	return rc;
}
Ejemplo n.º 25
0
/* Create Hash Table */
struct esif_ht * esif_ht_create(
    u32 size
)
{
    u32 index = 0;
    struct esif_ht *new_ht_ptr = NULL;

    new_ht_ptr = (struct esif_ht *)
                 esif_ccb_mempool_zalloc(ESIF_MEMPOOL_TYPE_HASH2);

    if (NULL == new_ht_ptr) {
        ESIF_TRACE_ERROR("Cannot allocate mem for hash table\n");
        ESIF_ASSERT(ESIF_FALSE);
        goto exit;
    }

    new_ht_ptr->size = size;
    new_ht_ptr->table = (struct esif_link_list **)
                        esif_ccb_malloc(sizeof(*new_ht_ptr->table) * size);

    if (new_ht_ptr->table == NULL) {
        esif_ccb_mempool_free(ESIF_MEMPOOL_TYPE_HASH2, new_ht_ptr);
        new_ht_ptr = NULL;
        goto exit;
    }

    for (index = 0; index < size; ++index) {
        ESIF_TRACE_DYN_VERB("Create linked list %d\n", index);
        new_ht_ptr->table[index] = esif_link_list_create();

        if (new_ht_ptr->table[index] == NULL) {
            ESIF_TRACE_DYN_VERB("Creation failed\n");
            esif_ht_destroy(new_ht_ptr, NULL);
            new_ht_ptr = NULL;
            goto exit;
        }
    }

    ESIF_TRACE_DYN_VERB("Have hash table %p\n", new_ht_ptr);
exit:
    return new_ht_ptr;
}
Ejemplo n.º 26
0
Bool EsifActIface_IsSupported(
		EsifActIfacePtr self
	)
{
	Bool isSupported = ESIF_TRUE;

	if (NULL == self) {
		isSupported = ESIF_FALSE;
		ESIF_TRACE_ERROR("Interface ptr is NULL\n");
		goto exit;
	}

	if (self->hdr.fIfaceType != eIfaceTypeAction ||
		self->hdr.fIfaceVersion > ESIF_ACT_FACE_VER_MAX ||
		self->hdr.fIfaceSize != EsifActIface_Sizeof(self->hdr.fIfaceVersion)) {
		isSupported = ESIF_FALSE;
		ESIF_TRACE_INFO("The action interface does not meet requirements\n");
	}
exit:
	return isSupported;
}
Ejemplo n.º 27
0
static eEsifError EsifAct_CallIfaceCreate(
	EsifActPtr self
	)
{
	eEsifError rc = ESIF_OK;

	if (self == NULL) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}
		
	switch (self->iface.hdr.fIfaceVersion) {
	case ESIF_ACT_IFACE_VER_STATIC:
		if (self->iface.ifaceStatic.createFuncPtr != NULL) {
			rc = self->iface.ifaceStatic.createFuncPtr(&self->iface, &self->actCtx);
			self->createCalled = ESIF_TRUE;
		}
		break;
	case ESIF_ACT_IFACE_VER_V1:
		if (self->iface.actIfaceV1.createFuncPtr != NULL) {

			self->iface.actIfaceV1.traceLevel = g_traceLevel;
			self->iface.actIfaceV1.writeLogFuncPtr = EsifActWriteLogHandler;
			self->iface.actIfaceV1.sendEventFuncPtr = EsifActIface_ReceiveEventV1;
			self->iface.actIfaceV1.execPrimitiveFuncPtr = EsifActIface_ExecutePrimitiveV1;

			rc = self->iface.actIfaceV1.createFuncPtr(&self->iface, &self->actCtx);		
			self->createCalled = ESIF_TRUE;
		}
		break;
	default:
		break;
	}
exit:
	if (ESIF_OK != rc) {
		ESIF_TRACE_ERROR("Error creating action. Error Code : %x", rc);
	}	
	return rc;
}
Ejemplo n.º 28
0
static void *ESIF_CALLCONV EsifDataLogWorkerThread(void *ptr)
{
	eEsifError rc = ESIF_OK;

	UNREFERENCED_PARAMETER(ptr);

	ESIF_TRACE_ENTRY_INFO();

	while (!g_dataLogQuit) {
		esif_ccb_time_t msecStart = 0;
		esif_ccb_time_t msecStop = 0;
		esif_ccb_time_t msecDif = 0;
		UInt32 sleepMs = 0;

		esif_ccb_system_time(&msecStart);
		EsifDataLogFire(0);
		esif_ccb_system_time(&msecStop);

		/* Determine how long processing actually took */
		msecDif = msecStop - msecStart;

		/* Determine next sleep time based on previous processing time*/
		sleepMs = g_dataLogInterval - ((int) msecDif);
		if ((sleepMs < MIN_STATUS_LOG_INTERVAL_ADJUSTED) || (msecDif > g_dataLogInterval)){
			sleepMs = MIN_STATUS_LOG_INTERVAL_ADJUSTED;
		}

		rc = EsifTimedEventWait(&g_dataLogQuitEvent, sleepMs);
		if (rc != ESIF_OK) {
			ESIF_TRACE_ERROR("Error waiting on data log event\n");
			goto exit;
		}
	}
exit:
	ESIF_TRACE_EXIT_INFO();
	return 0;
}
Ejemplo n.º 29
0
/* Create participant */
EsifUpPtr EsifUpManagerCreateParticipant(
	const eEsifParticipantOrigin origin,
	const void *handle,
	const void *metadataPtr
	)
{
	EsifUpPtr up_ptr = NULL;
	EsifUpManagerEntryPtr entry_ptr = NULL;
	UInt8 i = 0;
	UInt8 lpInstance;

	/* Lock manager */
	esif_ccb_write_lock(&g_uppMgr.fLock);

	/* Validate parameters */
	if (NULL == handle || NULL == metadataPtr) {
		ESIF_TRACE_ERROR("Invalid handle or meta data pointer\n");
		goto exit;
	}

	lpInstance = *(UInt8 *)handle;

	/*
	 * Check if a participant has already been created, but was then removed.
	 * In that case, just re-enable the participant.
	 */
	entry_ptr = EsifUpManagerGetParticipantEntryFromMetadata(origin, metadataPtr);
	if (NULL != entry_ptr) {
		up_ptr = entry_ptr->fUpPtr;
		entry_ptr->fState = ESIF_PM_PARTICIPANT_STATE_CREATED;
		g_uppMgr.fEntryCount++;
		goto exit;
	}

	/* Allocate a particpant */
	up_ptr = (EsifUpPtr)esif_ccb_malloc(sizeof(EsifUp));
	if (NULL == up_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate EsifUp\n");
		ESIF_ASSERT(up_ptr != NULL);
		goto exit;
	}

	/*
	**  Find available slot in participant manager table.  Simple Table Lookup For Now.
	**  Scan table and find first empty slot.  Empty slot indicated by AVAILABLE state.
	*/
	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		if (ESIF_PM_PARTICIPANT_STATE_AVAILABLE == g_uppMgr.fEntries[i].fState) {
			break;
		}
	}

	/* If no available slots return */
	if (i >= MAX_PARTICIPANT_ENTRY) {
		ESIF_TRACE_ERROR("No available slot in participant manager\n");
		esif_ccb_free(up_ptr);
		up_ptr = NULL;
		goto exit;
	}

	/* Take slot */
	g_uppMgr.fEntries[i].fState = ESIF_PM_PARTICIPANT_STATE_CREATED;
	g_uppMgr.fEntryCount++;

	/* Initialize participant */
	up_ptr->fInstance = i;
	up_ptr->fEnabled  = ESIF_TRUE;

	/* Initialize based on origin */
	switch (origin) {
	case eParticipantOriginLF:
		UpInitializeOriginLF(up_ptr, lpInstance, metadataPtr);
		break;

	case eParticipantOriginUF:
		UpInitializeOriginUF(up_ptr, metadataPtr);
		break;

	default:
		break;
	}

	/* Unlock manager */
	g_uppMgr.fEntries[i].fUpPtr = up_ptr;
	ESIF_TRACE_INFO("The participant data of %s is created in ESIF UF, instance = %d\n", up_ptr->fMetadata.fName, i);

exit:
	esif_ccb_write_unlock(&g_uppMgr.fLock);
	return up_ptr;
}
Ejemplo n.º 30
0
static eEsifError ActionCreate(
	EsifActPtr actionPtr,
	GetIfaceFuncPtr ifaceFuncPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifActTypePtr action_type_ptr = NULL;
	EsifData p1   = {ESIF_DATA_STRING, "action_iD", sizeof("action_id")};
	EsifData p2   = {ESIF_DATA_STRING, "domain_qualifier", sizeof("domain_qaulifier")};
	EsifData p3   = {ESIF_DATA_UINT32, "kernel_abi_type", sizeof("Kernel_abi_type")};
	EsifData p4   = {ESIF_DATA_UINT8, "mode", sizeof("mode")};

	char name[ESIF_NAME_LEN] = {0};
	ESIF_DATA(data_name, ESIF_DATA_STRING, name, ESIF_NAME_LEN);

	char desc[ESIF_DESC_LEN] = {0};
	ESIF_DATA(data_desc, ESIF_DATA_STRING, desc, ESIF_DESC_LEN);

	char version[ESIF_DESC_LEN] = {0};
	ESIF_DATA(data_version, ESIF_DATA_STRING, version, ESIF_DESC_LEN);

	UInt32 action_type_id = 0;
	EsifData action_type  = {ESIF_DATA_UINT32, &action_type_id, sizeof(action_type_id), 0};

	esif_guid_t guid   = {0};
	EsifData data_guid = {ESIF_DATA_GUID, &guid, sizeof(guid), 0};

	EsifString act_type_ptr = NULL;
	EsifInterface act_service_iface;

	ESIF_ASSERT(actionPtr != NULL);
	ESIF_ASSERT(ifaceFuncPtr != NULL);

	/* Assign the EsifInterface Functions */
	act_service_iface.fIfaceType              = eIfaceTypeEsifService;
	act_service_iface.fIfaceVersion           = 1;
	act_service_iface.fIfaceSize              = (UInt16)sizeof(EsifInterface);

	act_service_iface.fGetConfigFuncPtr       = EsifSvcConfigGet;
	act_service_iface.fSetConfigFuncPtr       = EsifSvcConfigSet;
	act_service_iface.fPrimitiveFuncPtr       = EsifSvcPrimitiveExec;
	act_service_iface.fWriteLogFuncPtr        = EsifSvcWriteLog;
	act_service_iface.fRegisterEventFuncPtr   = EsifSvcEventRegister;
	act_service_iface.fUnregisterEventFuncPtr = EsifSvcEventUnregister;

	/* GetApplicationInterface Handleshake send ESIF receive APP Interface */
	rc = ifaceFuncPtr(&actionPtr->fInterface);
	if (ESIF_OK != rc) {
		goto exit;
	}

	/* Check EsifAppInterface */
	if (actionPtr->fInterface.fIfaceType != eIfaceTypeAction ||
		actionPtr->fInterface.fIfaceSize != (UInt16)sizeof(EsifActInterface) ||
		actionPtr->fInterface.fIfaceVersion != 1 ||

		/* Functions Pointers */
		actionPtr->fInterface.fActCreateFuncPtr == NULL ||
		actionPtr->fInterface.fActDestroyFuncPtr == NULL ||
		actionPtr->fInterface.fActGetAboutFuncPtr == NULL ||
		actionPtr->fInterface.fActGetDescriptionFuncPtr == NULL ||
		actionPtr->fInterface.fActGetFuncPtr == NULL ||
		actionPtr->fInterface.fActGetIDFuncPtr == NULL ||
		actionPtr->fInterface.fActGetGuidFuncPtr == NULL ||
		actionPtr->fInterface.fActGetNameFuncPtr == NULL ||
		actionPtr->fInterface.fActGetStateFuncPtr == NULL ||
		actionPtr->fInterface.fActGetStatusFuncPtr == NULL ||
		actionPtr->fInterface.fActGetVersionFuncPtr == NULL ||
		actionPtr->fInterface.fActSetFuncPtr == NULL ||
		actionPtr->fInterface.fActSetStateFuncPtr == NULL) {
		ESIF_TRACE_ERROR("The required function pointer in EsifActInterface is NULL\n");
		goto exit;
	}

	/* Callback for application information */
	rc = actionPtr->fInterface.fActGetNameFuncPtr(&data_name);
	if (ESIF_OK != rc) {
		goto exit;
	}

	rc = actionPtr->fInterface.fActGetDescriptionFuncPtr(&data_desc);
	if (ESIF_OK != rc) {
		goto exit;
	}

	rc = actionPtr->fInterface.fActGetVersionFuncPtr(&data_version);
	if (ESIF_OK != rc) {
		goto exit;
	}

	rc = actionPtr->fInterface.fActGetIDFuncPtr(&action_type);
	if (ESIF_OK != rc) {
		goto exit;
	}

	rc = actionPtr->fInterface.fActGetGuidFuncPtr(&data_guid);
	if (ESIF_OK != rc) {
		goto exit;
	}

	act_type_ptr = "plugin";

	ESIF_TRACE_DEBUG("%s\n\n"
					 "Action Name   : %s\n"
					 "Action Desc   : %s\n"
					 "Action Type   : %s\n"
					 "Action Version: %s\n\n",
					 ESIF_FUNC,
					 (EsifString)data_name.buf_ptr,
					 (EsifString)data_desc.buf_ptr,
					 (EsifString)act_type_ptr,
					 (EsifString)data_version.buf_ptr);

	/* Create The Application */
	CMD_OUT("create action\n");
	rc = actionPtr->fInterface.fActCreateFuncPtr(
			&act_service_iface,
			NULL,
			&actionPtr->fHandle,
			eEsifActStateEnabled,
			&p1,
			&p2,
			&p3,
			&p4,
			NULL);

	if (ESIF_OK != rc) {
		goto exit;
	}

	/* Append New Action To Linked List */
	action_type_ptr = (EsifActTypePtr)esif_ccb_malloc(sizeof(EsifActType));

	if (NULL == action_type_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate EsifActType\n");
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}
	action_type_ptr->fHandle = actionPtr->fHandle;
	action_type_ptr->fType   = *(UInt8 *)action_type.buf_ptr;

	esif_ccb_strcpy(action_type_ptr->fName,
					(EsifString)data_name.buf_ptr, ESIF_NAME_LEN);
	esif_ccb_strcpy(action_type_ptr->fDesc,
					(EsifString)data_desc.buf_ptr, ESIF_DESC_LEN);
	esif_ccb_strcpy(action_type_ptr->fOsType, ESIF_ATTR_OS, ESIF_NAME_LEN);

	action_type_ptr->fGetFuncPtr = actionPtr->fInterface.fActGetFuncPtr;
	action_type_ptr->fSetFuncPtr = actionPtr->fInterface.fActSetFuncPtr;
	esif_ccb_memcpy(action_type_ptr->fGuid, data_guid.buf_ptr, ESIF_GUID_LEN);
	action_type_ptr->fIsKernel   = ESIF_FALSE;
	action_type_ptr->fIsPlugin   = ESIF_TRUE;

	/* Register Action */
	if (NULL != g_actMgr.AddActType) {
		rc = g_actMgr.AddActType(&g_actMgr, action_type_ptr);
	} else {
		ESIF_TRACE_ERROR("Fail to add action type since g_actMrg.AddActType is NULL\n");
		esif_ccb_free(action_type_ptr);
		rc = ESIF_E_NO_CREATE;
	}
exit:
	return rc;
}