Beispiel #1
0
static void esif_ws_http_process_post (const char *buffer)
{
	char *begPtr;
	char *endPtr;
	char *namebox;
	char *nameboxVal     = NULL;
	char *passwordbox;
	char *passwordboxVal = NULL;
	size_t namebox_size;
	size_t passwordbox_size;

	printf("buffer from POST: %s\n", buffer);

	namebox = strstr(buffer, "namebox");
	if (namebox) {
		begPtr = strchr((const char*)namebox, '=');
		begPtr++;
		endPtr = strchr(begPtr, '&');
		namebox_size = endPtr - begPtr;
		nameboxVal   = (char*)esif_ccb_malloc(namebox_size + 1);
		if (NULL == nameboxVal) {
			exit(1);
		}
		esif_ccb_memcpy(nameboxVal, namebox + 8, namebox_size + 1);
		nameboxVal[namebox_size] = 0;
		printf("name: %s ", nameboxVal);
	}

	passwordbox = strstr(buffer, "passwordbox");

	if (passwordbox) {
		begPtr = strchr((const char*)passwordbox, '=');
		begPtr++;
		endPtr = strchr(begPtr, '&');
		passwordbox_size = endPtr - begPtr;
		passwordboxVal   = (char*)esif_ccb_malloc(passwordbox_size + 1);
		if (NULL == passwordboxVal) {
			exit(1);
		}
		esif_ccb_memcpy(passwordboxVal, passwordbox + 12, passwordbox_size + 1);
		passwordboxVal[passwordbox_size] = 0;
		printf("password: %s\n", passwordboxVal);
	}

	if (nameboxVal) {
		esif_ccb_free(nameboxVal);
	}

	if (passwordboxVal) {
		esif_ccb_free(passwordboxVal);
	}
}
Beispiel #2
0
void DataBank_CloseNameSpace (
	DataBankPtr self,
	esif_string nameSpace
	)
{
	UInt32 ns;

	esif_ccb_write_lock(&self->lock);

	// Find Existing NameSpace
	for (ns = 0; ns < self->size; ns++) {
		if (esif_ccb_stricmp(nameSpace, self->elements[ns].name) == 0) {
			DataVault_dtor(&self->elements[ns]);

			// Move Array Items down one and wipe the final item
			for ( ; ns + 1 < self->size; ns++)
				esif_ccb_memcpy(&self->elements[ns], &self->elements[ns + 1], sizeof(self->elements[ns]));
			if (ns < ESIF_MAX_NAME_SPACES) {
				WIPEPTR(&self->elements[ns]);
			}
			self->size--;
		}
	}
	esif_ccb_write_unlock(&self->lock);
}
Beispiel #3
0
void SupportedPolicyList::update(void)
{
    m_guid.clear();

    // TODO: This should be moved to a DPTF Initialization class. For now, ignore empty result buffer
    DptfBuffer ignore = m_dptfManager->getEsifServices()->primitiveExecuteGet(
        esif_primitive_type::GET_DPTF_CONFIGURATION, ESIF_DATA_BINARY);
    
    DptfBuffer buffer = m_dptfManager->getEsifServices()->primitiveExecuteGet(
        esif_primitive_type::GET_SUPPORTED_POLICIES, ESIF_DATA_BINARY);

    if ((buffer.size() % sizeof(AcpiEsifGuid)) != 0)
    {
        std::stringstream message;
        message << "Received invalid data length [" << buffer.size() << "] from primitive call: GET_SUPPORTED_POLICIES";
        throw dptf_exception(message.str());
    }

    UInt32 guidCount = buffer.size() / sizeof(AcpiEsifGuid);
    AcpiEsifGuid* acpiEsifGuid = reinterpret_cast<AcpiEsifGuid*>(buffer.get());

    for (UInt32 i = 0; i < guidCount; i++)
    {
        UInt8 guidByteArray[GuidSize] = {0};
        esif_ccb_memcpy(guidByteArray, &acpiEsifGuid[i].uuid, GuidSize);
        Guid guid(guidByteArray);
        m_dptfManager->getEsifServices()->writeMessageInfo("Supported GUID: " + guid.toString());
        m_guid.push_back(guid);
    }
}
Beispiel #4
0
/* Data For Interface Marshaling */
static AppDomainDataPtr CreateDomainData(const struct esif_fpc_domain *domainPtr)
{
	AppDomainDataPtr dom_data_ptr = (AppDomainDataPtr)esif_ccb_malloc(sizeof(AppDomainData));

	ESIF_TRACE_DEBUG("%s\n", domainPtr->descriptor.name);

	if (NULL == dom_data_ptr) {
		goto exit;
	}

	dom_data_ptr->fName.buf_ptr  = (void *)domainPtr->descriptor.name;
	dom_data_ptr->fName.buf_len  = ESIF_NAME_LEN;
	dom_data_ptr->fName.data_len = (UInt32)esif_ccb_strlen(domainPtr->descriptor.name, ESIF_NAME_LEN);
	dom_data_ptr->fName.type     = ESIF_DATA_STRING;

	dom_data_ptr->fDescription.buf_ptr  = (void *)domainPtr->descriptor.description;
	dom_data_ptr->fDescription.buf_len  = ESIF_DESC_LEN;
	dom_data_ptr->fDescription.data_len = (UInt32)esif_ccb_strlen(domainPtr->descriptor.description, ESIF_DESC_LEN);
	dom_data_ptr->fDescription.type     = ESIF_DATA_STRING;

	dom_data_ptr->fGuid.buf_ptr  = (void *)domainPtr->descriptor.guid;
	dom_data_ptr->fGuid.buf_len  = ESIF_GUID_LEN;
	dom_data_ptr->fGuid.data_len = ESIF_GUID_LEN;
	dom_data_ptr->fGuid.type     = ESIF_DATA_GUID;

	dom_data_ptr->fVersion    = APP_DOMAIN_VERSION;
	dom_data_ptr->fType       = (enum esif_domain_type)domainPtr->descriptor.domainType;
	dom_data_ptr->fCapability = domainPtr->capability_for_domain.capability_flags;
	esif_ccb_memcpy(dom_data_ptr->fCapabilityBytes, domainPtr->capability_for_domain.capability_mask, 32);

exit:

	return dom_data_ptr;
}
Beispiel #5
0
static void esif_ws_cgi_parse_script (
    const char *resourceLoc,
    int fd,
    char *full_script_name
)
{
    char abbr_script_name[100];
    u32 i = 0;


    esif_ccb_memcpy(abbr_script_name, resourceLoc, esif_ccb_strlen(resourceLoc, MAX_SIZE));
    abbr_script_name[esif_ccb_strlen(resourceLoc, MAX_SIZE)] = 0;
    printf("cgi script name: %s\n", abbr_script_name);
    i = i;	// to satisfy compiler
#ifdef ESIF_ATTR_OS_WINDOWS
    for (i = 0; i < esif_ccb_strlen(abbr_script_name, MAX_SIZE); i++)
        if (abbr_script_name[i] == '/') {
            abbr_script_name[i] = '\\';
        }

#endif


    esif_ccb_strcat(full_script_name, abbr_script_name, sizeof(full_script_name));

    printf("full_cgi_script_name: %s\n", full_script_name);

    esif_ws_cgi_redirect_output(full_script_name, fd);
}
Beispiel #6
0
/* Get Debug Module Level */
static void esif_execute_ipc_command_get_debug_module_level(
	struct esif_ipc_command *command_ptr
	)
{
	/* Sanity Check */
	if (ESIF_DATA_STRUCTURE == command_ptr->rsp_data_type &&
	    0 == command_ptr->rsp_data_offset &&
	    sizeof(struct esif_command_get_debug_module_level) ==
	    command_ptr->rsp_data_len) {
		struct esif_command_get_debug_module_level *data_ptr =
			(struct esif_command_get_debug_module_level *)
			(command_ptr + 1);

		data_ptr->modules = g_esif_module_mask;
		esif_ccb_memcpy(&data_ptr->levels,
				&g_esif_module_category_mask,
				sizeof(g_esif_module_category_mask));
		data_ptr->tracelevel = g_esif_trace_level;

		ESIF_TRACE_DYN_COMMAND(
			"%s: ESIF_COMMAND_TYPE_GET_DEBUG_MODULE_LEVEL "
			"modules 0x%08X\n",
			ESIF_FUNC,
			data_ptr->modules);

		command_ptr->return_code = ESIF_OK;
	}
}
Beispiel #7
0
/*
   Map upper participant metadata to upper particpant instance.  A participant
   that is created from the upperframework will never have a lower framework
   component.  These participants are to cover the case were we either have no
   Kernel corresponding participant or in some cases we may not even have a
   lower frame work present.
 */
static void UpInitializeOriginUF(
	const EsifUpPtr upPtr,
	const void *upMetadataPtr
	)
{
	/* Upper Participant Metadata Format */
	EsifParticipantIfacePtr metadata_ptr =
		(EsifParticipantIfacePtr)upMetadataPtr;

	ESIF_ASSERT(upPtr != NULL);
	ESIF_ASSERT(metadata_ptr != NULL);

	/* Store Lower Framework Instance */
	upPtr->fLpInstance = 255;	/* Not Used */

	/* Common */
	upPtr->fMetadata.fVersion    = metadata_ptr->version;
	upPtr->fMetadata.fEnumerator = (enum esif_participant_enum)metadata_ptr->enumerator;
	upPtr->fMetadata.fFlags = metadata_ptr->flags;

	esif_ccb_memcpy(&upPtr->fMetadata.fDriverType, &metadata_ptr->class_guid, ESIF_GUID_LEN);

	esif_ccb_strcpy(upPtr->fMetadata.fName, metadata_ptr->name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDesc, metadata_ptr->desc, ESIF_DESC_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDriverName, metadata_ptr->driver_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDeviceName, metadata_ptr->device_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDevicePath, metadata_ptr->device_path, ESIF_PATH_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fAcpiScope, metadata_ptr->object_id, ESIF_SCOPE_LEN);
}
Beispiel #8
0
void EsifDataGuid::initialize(const UInt8 guid[GuidSize])
{
	esif_ccb_memcpy(m_guid, guid, GuidSize);

	m_esifData.type = esif_data_type::ESIF_DATA_GUID;
	m_esifData.buf_ptr = m_guid;
	m_esifData.buf_len = GuidSize;
	m_esifData.data_len = GuidSize;
}
Beispiel #9
0
static void esif_ws_cgi_parse_query (
    char *query,
    const char *beg_parms_loc_in_query,
    int fd,
    char *cgi_dir
)
{
    char *cgi_script;
    char *cgi_script_buf;
    // char *cgi_dir;
    char cgiParms[100];
    size_t cgi_script_size;
#define MAX_SIZE 100

    cgi_script_size = query - beg_parms_loc_in_query;
    cgi_script = (char*)esif_ccb_malloc(cgi_script_size + 1);
    if (cgi_script == NULL) {
        exit(1);
    }
    // cgi_dir = (char*)esif_ccb_malloc(esif_ccb_strlen(cgi_dir, MAX_SIZE) + cgi_script_size);
    // if (cgi_dir == NULL)
    // exit(1);

    esif_ccb_memcpy(cgi_script, beg_parms_loc_in_query, cgi_script_size);
    // esif_ccb_memcpy(cgi_dir, DIRECTORY, esif_ccb_strlen(DIRECTORY, MAX_SIZE));

    cgi_script[cgi_script_size] = '\0';
    // cgi_dir[esif_ccb_strlen(DIRECTORY, MAX_SIZE)]='\0';
    printf("cgi_script 1: %s\n", cgi_script);
    query++;

    cgi_script_buf = cgi_script;

#ifdef ESIF_ATTR_OS_WINDOWS

    cgi_script_buf = (char*)strrchr(cgi_script_buf, '/');
    cgi_script_buf++;
    cgi_script_buf[esif_ccb_strlen(cgi_script_buf, MAX_SIZE)] = '\0';
#endif


    esif_ccb_strcpy(cgiParms, query, esif_ccb_strlen(query, MAX_SIZE));

    printf("cgi_dir: %s\n", cgi_dir);

    printf("cgiParms 1: %s\n", cgiParms);

    esif_ccb_strcat(cgi_dir, cgi_script_buf, sizeof(cgi_dir));


    esif_ws_cgi_redirect_output(cgi_dir, fd);
    if (cgi_script) {
        esif_ccb_free(cgi_script);
    }
    // if (cgi_dir)
    // esif_ccb_free(cgi_dir);
}
Beispiel #10
0
static int esif_ws_http_is_authorized (const char *buffer)
{
	char *begPtr;
	char *endPtr;
	char *namebox;
	char *nameboxVal;
	char *passwordbox;
	char *passwordboxVal = NULL;
	int result;

	printf("esif_ws_http_is_authorized : Buffer received: %s\n", buffer);

	namebox = strstr(buffer, "namebox");
	if (namebox) {
		begPtr     = strchr((const char*)namebox, '=');
		begPtr++;
		endPtr     = strchr(begPtr, '&');
		nameboxVal = (char*)esif_ccb_malloc(endPtr - begPtr + 1);
		esif_ccb_memcpy(nameboxVal, namebox + 8, endPtr - begPtr + 1);
		nameboxVal[endPtr - begPtr] = 0;
		printf("name: %s ", nameboxVal);
	}

	passwordbox = strstr(buffer, "passwordbox");

	if (passwordbox) {
		begPtr = strchr((const char*)passwordbox, '=');
		begPtr++;
		endPtr = strchr(begPtr, '&');
		passwordboxVal = (char*)esif_ccb_malloc(endPtr - begPtr + 1);
		esif_ccb_memcpy(passwordboxVal, passwordbox + 12, endPtr - begPtr + 1);
		passwordboxVal[endPtr - begPtr] = 0;
		printf("esif_ws_http_password: %s\n", passwordboxVal);
	}

	if (passwordboxVal && !strcmp(passwordboxVal, esif_ws_http_password)) {
		result = 1;
	} else {
		result = 0;
	}

	return result;
}
void PolicyServicesPlatformNotification::executeOsc(const Guid& guid, UInt32 oscCapabilities)
{
	Bool successful = false;

	struct esif_data_complex_osc osc;
	esif_ccb_memcpy(osc.guid, guid, Guid::GuidSize);
	osc.revision = 1;
	osc.count = 2;
	osc.status = 0;
	osc.capabilities = oscCapabilities;
	std::string failureMessage;

	try
	{
		getEsifServices()->primitiveExecuteSet(
			SET_OPERATING_SYSTEM_CAPABILITIES,
			ESIF_DATA_STRUCTURE,
			&osc,
			sizeof(esif_data_complex_osc),
			sizeof(esif_data_complex_osc));
		successful = true;
	}
	catch (std::exception& ex)
	{
		failureMessage = ex.what();
	}
	catch (...)
	{
		failureMessage = "Unknown error.";
	}

	if (osc.status & 0xE)
	{
		if (osc.status & 0x2)
		{
			throw dptf_exception("Platform supports _OSC but unable to process _OSC request.");
		}

		if (osc.status & 0x4)
		{
			throw dptf_exception("Platform failed _OSC Reason: Unrecognized UUID.");
		}

		if (osc.status & 0x8)
		{
			throw dptf_exception("Platform failed _OSC Reason: Unrecognized revision.");
		}
	}

	if (successful == false)
	{
		throw dptf_exception("Failure during execution of _OSC: " + failureMessage);
	}
}
Beispiel #12
0
/* CPC Unpack */
enum esif_rc esif_cpc_unpack(
	struct esif_lp_dsp *dsp_ptr,
	const struct esif_data *req_data_ptr
	)
{
	struct esif_lp_cpc *cpc_ptr = NULL;
	struct esif_cpc_header *cpc_header_ptr = NULL;

	ESIF_TRACE_DYN_CPC("%s: START\n", ESIF_FUNC);
	ESIF_TRACE_DYN_CPC("%s: dsp %p req_data %p cpc %p size %d\n",
			   ESIF_FUNC,
			   dsp_ptr,
			   req_data_ptr,
			   req_data_ptr->buf_ptr,
			   req_data_ptr->buf_len);

	/* Validate Thourougly Here */
	if (req_data_ptr->type != ESIF_DATA_DSP)
		return ESIF_E_INVALID_REQUEST_TYPE;

	if (req_data_ptr->buf_len < sizeof(struct esif_cpc_header))
		return ESIF_E_CPC_SHORT;

	cpc_ptr        = (struct esif_lp_cpc *)req_data_ptr->buf_ptr;
	cpc_header_ptr = (struct esif_cpc_header *)&cpc_ptr->header;

	ESIF_TRACE_DYN_CPC(
		"%s: code %s ver %x (%x,%x), signature %08x, version %x\n",
		ESIF_FUNC,
		cpc_header_ptr->code,
		cpc_header_ptr->version,
		cpc_header_ptr->ver_major,
		cpc_header_ptr->ver_minor,
		cpc_header_ptr->cpc.signature,
		cpc_header_ptr->cpc.version);

	if (cpc_header_ptr->cpc.signature != *(unsigned int *)"@CPC")
		return ESIF_E_CPC_SIGNATURE;

	/* Make a copy for now */
	cpc_ptr = (struct esif_lp_cpc *)esif_ccb_malloc(req_data_ptr->buf_len);
	if (NULL != cpc_ptr) {
		esif_ccb_memcpy(cpc_ptr,
				req_data_ptr->buf_ptr,
				req_data_ptr->buf_len);

		dsp_ptr->cpc_ptr = cpc_ptr;
		esif_cpc_to_dsp(dsp_ptr);
	}
	ESIF_TRACE_DYN_CPC(" %s: STOP\n", ESIF_FUNC);
	return ESIF_OK;
}
Beispiel #13
0
std::vector<Guid> SupportedPolicyList::parseBufferForPolicyGuids(const DptfBuffer& buffer)
{
	UInt32 guidCount = buffer.size() / sizeof(AcpiEsifGuid);
	AcpiEsifGuid* acpiEsifGuid = reinterpret_cast<AcpiEsifGuid*>(buffer.get());

	std::vector<Guid> guids;
	for (UInt32 i = 0; i < guidCount; i++)
	{
		UInt8 guidByteArray[GuidSize] = { 0 };
		esif_ccb_memcpy(guidByteArray, &acpiEsifGuid[i].uuid, GuidSize);
		guids.push_back(Guid(guidByteArray));
	}
	return guids;
}
Beispiel #14
0
/*
**  Map lower participant metadata to upper participant instance.  Every
**  lower participant must have a corresponding upper particpant.  Here we
**  intialize the data from the upper participant from the lower participant
**  registration data.
*/
static void UpInitializeOriginLF(
	const EsifUpPtr upPtr,
	const UInt8 lpInstance,
	const void *lpMetadataPtr
	)
{
	/* Lower Framework Participant Metadata Format */
	struct esif_ipc_event_data_create_participant *metadata_ptr =
		(struct esif_ipc_event_data_create_participant *)lpMetadataPtr;

	ESIF_ASSERT(upPtr != NULL);
	ESIF_ASSERT(metadata_ptr != NULL);

	/* Store Lower Framework Instance. */
	upPtr->fLpInstance = lpInstance;

	/* Common */
	upPtr->fMetadata.fVersion    = metadata_ptr->version;
	upPtr->fMetadata.fEnumerator = (enum esif_participant_enum)metadata_ptr->enumerator;
	upPtr->fMetadata.fFlags = metadata_ptr->flags;

	esif_ccb_memcpy(&upPtr->fMetadata.fDriverType, &metadata_ptr->class_guid, ESIF_GUID_LEN);

	esif_ccb_strcpy(upPtr->fMetadata.fName, metadata_ptr->name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDesc, metadata_ptr->desc, ESIF_DESC_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDriverName, metadata_ptr->driver_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDeviceName, metadata_ptr->device_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fDevicePath, metadata_ptr->device_path, ESIF_PATH_LEN);

	/* ACPI */
	esif_ccb_strcpy(upPtr->fMetadata.fAcpiUID, metadata_ptr->acpi_uid, sizeof(upPtr->fMetadata.fAcpiUID));
	upPtr->fMetadata.fAcpiType = metadata_ptr->acpi_type;
	esif_ccb_strcpy(upPtr->fMetadata.fAcpiDevice, metadata_ptr->acpi_device, ESIF_NAME_LEN);
	esif_ccb_strcpy(upPtr->fMetadata.fAcpiScope, metadata_ptr->acpi_scope, ESIF_SCOPE_LEN);

	/* PCI */
	upPtr->fMetadata.fPciVendor    = (u16)metadata_ptr->pci_vendor;
	upPtr->fMetadata.fPciDevice    = (u16)metadata_ptr->pci_device;
	upPtr->fMetadata.fPciBus       = metadata_ptr->pci_bus;
	upPtr->fMetadata.fPciBusDevice = metadata_ptr->pci_bus_device;
	upPtr->fMetadata.fPciFunction  = metadata_ptr->pci_function;
	upPtr->fMetadata.fPciRevision  = metadata_ptr->pci_revision;
	upPtr->fMetadata.fPciClass     = metadata_ptr->pci_class;
	upPtr->fMetadata.fPciSubClass  = metadata_ptr->pci_sub_class;
	upPtr->fMetadata.fPciProgIf    = metadata_ptr->pci_prog_if;
}
Beispiel #15
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;
}
Beispiel #16
0
static void esif_ws_http_serve_cgi_scripts (
	const char *buffer,
	int fd
	)
{
	char *blankCharPtr;
	char *endPtr;
	char *uri;
	size_t uri_size;
	printf("CGI script\n");

	blankCharPtr = strchr((const char*)buffer, ' ');
	blankCharPtr++;
	endPtr = strchr(blankCharPtr, ' ');


	uri_size = endPtr - blankCharPtr;

	uri = (char*)esif_ccb_malloc(uri_size + 1);
	if (uri == NULL) {
		exit(1);
	}


	esif_ccb_memcpy(uri, buffer + 4, uri_size + 1);
	uri[uri_size] = 0;

	printf("uri: %s\n", uri);

	if (!strncmp(buffer, "POST ", 5)) {
		esif_ws_http_process_post((const char*)buffer);
	}

	esif_ws_cgi_execute_cgi_script(uri, fd, g_server_root);

	if (uri) {
		esif_ccb_free(uri);
	}
}
Beispiel #17
0
/* Allocate IPC */
struct esif_ipc *esif_ipc_alloc(
	enum esif_ipc_type type,
	u32 data_len
	)
{
	u32 ipc_size = data_len + sizeof(struct esif_ipc);
	struct esif_ipc *ipc_ptr = (struct esif_ipc *)esif_ccb_malloc(ipc_size);
	if (NULL == ipc_ptr)
		return NULL;

	ipc_ptr->version     = ESIF_IPC_VERSION;
	ipc_ptr->type        = type;
	ipc_ptr->data_len    = data_len;
	ipc_ptr->return_code = ESIF_OK;

#ifdef ESIF_ATTR_HMAC
	esif_ccb_memcpy(ipc->hmac, x, ESIF_HMAC_LEN);
#endif
	ESIF_TRACE_DEBUG("%s: ipc = %p, type = %d, size = %d data_len = %d\n",
			 ESIF_FUNC, ipc_ptr, type, (int)ipc_size,
			 (int)data_len);
	return ipc_ptr;
}
Beispiel #18
0
/*
 *******************************************************************************
 ** PUBLIC
 *******************************************************************************
 */
void esif_ws_http_copy_server_root (char *dir)
{
	#define MAX_LENGTH 200
	esif_ccb_memcpy(g_server_root, dir, esif_ccb_strlen(dir, MAX_LENGTH));
}
Beispiel #19
0
/* Get Participants */
static void esif_execute_ipc_command_get_participants(
	struct esif_ipc_command *command_ptr
	)
{
	/* Sanity Check */
	if (ESIF_DATA_STRUCTURE == command_ptr->rsp_data_type &&
	    0 == command_ptr->rsp_data_offset &&
	    sizeof(struct esif_command_get_participants) ==
	    command_ptr->rsp_data_len) {
		u8 i = 0;
		struct esif_command_get_participants *data_ptr =
			(struct esif_command_get_participants *)
			(command_ptr + 1);

		ESIF_TRACE_DYN_COMMAND(
			"%s: ESIF_COMMAND_TYPE_GET_PARTICIPANTS\n",
			ESIF_FUNC);

		for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
			struct esif_lp *lp_ptr =
				esif_lf_pm_lp_get_by_instance_id(i);
			if (NULL != lp_ptr) {
				data_ptr->participant_info[i].id = i;
				esif_ccb_strcpy(
					data_ptr->participant_info[i].name,
					lp_ptr->pi_ptr->name,
					ESIF_NAME_LEN);
				esif_ccb_strcpy(
					data_ptr->participant_info[i].desc,
					lp_ptr->pi_ptr->desc,
					ESIF_DESC_LEN);
				esif_ccb_memcpy(
					data_ptr->participant_info[i].class_guid,
					lp_ptr->pi_ptr->class_guid,
					ESIF_GUID_LEN);
				data_ptr->participant_info[i].version  =
					lp_ptr->pi_ptr->version;
				data_ptr->participant_info[i].bus_enum =
					lp_ptr->pi_ptr->enumerator;
				data_ptr->participant_info[i].state    =
					esif_lf_pm_lp_get_state(lp_ptr);
				if (NULL != lp_ptr->dsp_ptr) {
					esif_ccb_strcpy(
					    data_ptr->participant_info[i].dsp_code,
					    lp_ptr->dsp_ptr->get_code(
					    lp_ptr->dsp_ptr),
					    ESIF_DSP_NAME_LEN);
					data_ptr->participant_info[i].dsp_ver_major =
						lp_ptr->dsp_ptr->get_ver_major(
							lp_ptr->dsp_ptr);
					data_ptr->participant_info[i].
					dsp_ver_minor =
						lp_ptr->dsp_ptr->get_ver_minor(
							lp_ptr->dsp_ptr);
				}
			} else {
				data_ptr->participant_info[i].id = i;
				if (1 == i) {
					esif_ccb_strcpy(
						data_ptr->participant_info[i].desc,
						"RESERVED",
						ESIF_DESC_LEN);
				} else {
				}
			}
		}
		data_ptr->count = i;
		command_ptr->return_code = ESIF_OK;
	}
}
Beispiel #20
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;
}
Beispiel #21
0
/* Get Participant */
static void esif_execute_ipc_command_get_participant_detail(
	struct esif_ipc_command *command_ptr
	)
{
	/* Sanity Check */
	if (ESIF_DATA_STRUCTURE == command_ptr->rsp_data_type &&
	    0 == command_ptr->rsp_data_offset &&
	    sizeof(struct esif_command_get_participant_detail) ==
	    command_ptr->rsp_data_len) {
		struct esif_command_get_participant_detail *data_ptr =
			(struct esif_command_get_participant_detail *)(
				command_ptr + 1);

		/* ID Will Be In Buffer ON Arrival */
		u32 participant_id = *(u32 *) data_ptr;

		ESIF_TRACE_DYN_COMMAND(
			"%s: ESIF_COMMAND_TYPE_PARTICIPANT_DETAIL id %d\n",
			ESIF_FUNC,
			participant_id);
		{
			struct esif_lp *lp_ptr =
			   esif_lf_pm_lp_get_by_instance_id((u8)participant_id);

			if (NULL != lp_ptr) {
				/* Participant Info */
				data_ptr->id         = participant_id;
				data_ptr->version    = lp_ptr->pi_ptr->version;
				data_ptr->enumerator =
					lp_ptr->pi_ptr->enumerator;
				esif_ccb_strcpy(data_ptr->name,
						lp_ptr->pi_ptr->name,
						ESIF_NAME_LEN);
				esif_ccb_strcpy(data_ptr->desc,
						lp_ptr->pi_ptr->desc,
						ESIF_DESC_LEN);
				esif_ccb_strcpy(data_ptr->driver_name,
						lp_ptr->pi_ptr->driver_name,
						ESIF_NAME_LEN);
				esif_ccb_strcpy(data_ptr->device_name,
						lp_ptr->pi_ptr->device_name,
						ESIF_NAME_LEN);
				esif_ccb_strcpy(data_ptr->device_path,
						lp_ptr->pi_ptr->device_path,
						ESIF_PATH_LEN);
				esif_ccb_memcpy(data_ptr->class_guid,
						lp_ptr->pi_ptr->class_guid,
						ESIF_GUID_LEN);
				data_ptr->flags = lp_ptr->pi_ptr->flags;

				/* ACPI */
				esif_ccb_strcpy(data_ptr->acpi_device,
						lp_ptr->pi_ptr->acpi_device,
						ESIF_NAME_LEN);
				esif_ccb_strcpy(data_ptr->acpi_scope,
						lp_ptr->pi_ptr->acpi_scope,
						ESIF_SCOPE_LEN);
				esif_ccb_strcpy(data_ptr->acpi_uid,
						lp_ptr->pi_ptr->acpi_uid,
						sizeof(data_ptr->acpi_uid));
				data_ptr->acpi_type = lp_ptr->pi_ptr->acpi_type;

				/* PCI */
				data_ptr->pci_vendor     =
					(u16)lp_ptr->pi_ptr->pci_vendor;
				data_ptr->pci_device     =
					(u16)lp_ptr->pi_ptr->pci_device;
				data_ptr->pci_bus        =
					lp_ptr->pi_ptr->pci_bus;
				data_ptr->pci_bus_device =
					lp_ptr->pi_ptr->pci_bus_device;
				data_ptr->pci_function   =
					lp_ptr->pi_ptr->pci_function;
				data_ptr->pci_revision   =
					lp_ptr->pi_ptr->pci_revision;
				data_ptr->pci_class      =
					lp_ptr->pi_ptr->pci_class;
				data_ptr->pci_sub_class  =
					lp_ptr->pi_ptr->pci_sub_class;
				data_ptr->pci_prog_if    =
					lp_ptr->pi_ptr->pci_prog_if;

				/* LP */
				data_ptr->state        =
					esif_lf_pm_lp_get_state(lp_ptr);
				data_ptr->timer_period =
					lp_ptr->domains[0].timer_period_msec;

				if (NULL != lp_ptr->dsp_ptr) {
					/* Have DSP */
					data_ptr->have_dsp = 1;
					esif_ccb_strcpy(data_ptr->dsp_code,
							lp_ptr->dsp_ptr->get_code(
							lp_ptr->dsp_ptr),
							ESIF_DSP_NAME_LEN);
					data_ptr->dsp_ver_major =
						lp_ptr->dsp_ptr->get_ver_major(
							lp_ptr->dsp_ptr);
					data_ptr->dsp_ver_minor =
						lp_ptr->dsp_ptr->get_ver_minor(
							lp_ptr->dsp_ptr);

					if (NULL != lp_ptr->dsp_ptr->cpc_ptr) {
						/* Have CPC */
						data_ptr->have_cpc    = 1;
						data_ptr->cpc_version =
							lp_ptr->dsp_ptr->cpc_ptr->header.version;
						data_ptr->cpc_signature =
							lp_ptr->dsp_ptr->cpc_ptr->header.cpc.signature;
						data_ptr->cpc_size =
							lp_ptr->dsp_ptr->cpc_ptr->size;
						data_ptr->cpc_primitive_count =
							lp_ptr->dsp_ptr->cpc_ptr->number_of_basic_primitives;
					}	/* cpc */
				}	/* dsp */
			}	/* lp */
		}	/* block */
		command_ptr->return_code = ESIF_OK;
	}	/* if */
}
Beispiel #22
0
static eEsifError EsifSetActionDelegateRset(
	const EsifUpDomainPtr domainPtr,
	const EsifDataPtr requestPtr)
{
	eEsifError rc = ESIF_E_PRIMITIVE_ACTION_FAILURE;
	EsifPrimitiveTupleParameter parameters = { 0 };
	EsifPrimitiveTuple tuple = { 0 };
	Bool signal_event = ESIF_FALSE;
	char domain_str[8] = { 0 };
	int j = 0;

	ESIF_ASSERT(domainPtr != NULL);
	ESIF_ASSERT(requestPtr != NULL);
	
	if (requestPtr->buf_ptr == NULL) {
		rc = ESIF_E_PARAMETER_IS_NULL;
		goto exit;
	}
	if (requestPtr->data_len != sizeof(parameters)) {
		rc = ESIF_E_REQUEST_DATA_OUT_OF_BOUNDS;
		goto exit;
	}
	
	// Convert BINARY Parameters to Primitive Tuple
	esif_ccb_memcpy(&parameters, requestPtr->buf_ptr, sizeof(parameters));
	
	ESIF_TRACE_DEBUG("CONFIG RESET: { %s (%hd), %s, %hd }\n",
		esif_primitive_str(parameters.id.integer.value),
		(u16)parameters.id.integer.value,
		esif_primitive_domain_str((u16)parameters.domain.integer.value, domain_str, sizeof(domain_str)),
		(u16)parameters.instance.integer.value
		);

	// Look up Primitive Tuple in the DSP and verify it is a valid SET primtive
	EsifDspPtr dspPtr = EsifUp_GetDsp(domainPtr->upPtr);
	if (dspPtr == NULL) {
		rc = ESIF_E_NEED_DSP;
		goto exit;
	}
	tuple.id = (u16) parameters.id.integer.value;
	tuple.domain = (u16) parameters.domain.integer.value;
	tuple.instance = (u16) parameters.instance.integer.value;
	EsifFpcPrimitivePtr primitivePtr = dspPtr->get_primitive(dspPtr, &tuple);
	if (primitivePtr == NULL) {
		rc = ESIF_E_PRIMITIVE_NOT_FOUND_IN_DSP;
		goto exit;
	}
	if (primitivePtr->operation != ESIF_PRIMITIVE_OP_SET) {
		rc = ESIF_E_INVALID_REQUEST_TYPE;
		goto exit;
	}

	// Find first CONFIG Action and Delete its Key from its DataVault
	for (j = 0; j < (int)primitivePtr->num_actions; j++) {
		EsifFpcActionPtr fpcActionPtr = dspPtr->get_action(dspPtr, primitivePtr, (u8)j);
		DataItemPtr paramDataVault = EsifFpcAction_GetParam(fpcActionPtr, (const UInt8)0);
		DataItemPtr paramKeyName = EsifFpcAction_GetParam(fpcActionPtr, (const UInt8)1);
		EsifString expandedKeyName = NULL;
		if (fpcActionPtr->type != ESIF_ACTION_CONFIG) {
			continue;
		}
		if (paramDataVault == NULL || paramKeyName == NULL || paramDataVault->data_type != ESIF_DSP_PARAMETER_TYPE_STRING || paramKeyName->data_type != ESIF_DSP_PARAMETER_TYPE_STRING) {
			rc = ESIF_E_PARAMETER_IS_OUT_OF_BOUNDS;
			goto exit;
		}
		
		// Replace "%nm%" tokens in the key name or make a copy of the key name for static keys
		expandedKeyName = EsifUp_CreateTokenReplacedParamString(domainPtr->upPtr, primitivePtr, (StringPtr)paramKeyName->data);
		if (expandedKeyName == NULL) {
			expandedKeyName = esif_ccb_strdup((StringPtr)paramKeyName->data);
			if (expandedKeyName == NULL) {
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}
		}

		// Valid SET CONFIG Primitive found with valid DV/Key Name; Delete the associated Key from the DataVault
		EsifDataPtr data_nspace = EsifData_CreateAs(ESIF_DATA_STRING, (StringPtr)paramDataVault->data, 0, ESIFAUTOLEN);
		EsifDataPtr data_key    = EsifData_CreateAs(ESIF_DATA_STRING, expandedKeyName, 0, ESIFAUTOLEN);

		// Do not signal an Event if Key does not exist in DataVault
		if (DataBank_KeyExists(g_DataBankMgr, (StringPtr)paramDataVault->data, expandedKeyName) == ESIF_FALSE) {
			rc = ESIF_OK;
		}
		else if (data_nspace == NULL || data_key == NULL) {
			rc = ESIF_E_NO_MEMORY;
		}
		else {
			// Delete Existing Key from DataVault
			rc = EsifConfigDelete(data_nspace, data_key);
			if (rc == ESIF_OK) {
				signal_event = ESIF_TRUE;
			}

			ESIF_TRACE_DEBUG("CONFIG RESET: config delete @%s %s [rc=%s (%d)]\n",
				(StringPtr)data_nspace->buf_ptr,
				(StringPtr)data_key->buf_ptr,
				esif_rc_str(rc),
				rc
				);
		}

		// Signal any Event(s) associated with this SET Primitive
		if (signal_event) {
			EsifActConfigSignalChangeEvents(domainPtr->upPtr, tuple, NULL);
		}

		EsifData_Destroy(data_nspace);
		EsifData_Destroy(data_key);
		esif_ccb_free(expandedKeyName);
		break;
	}
	if (j >= (int)primitivePtr->num_actions) {
		rc = ESIF_E_UNSUPPORTED_ACTION_TYPE;
	}

exit:
	return rc;
}
Beispiel #23
0
static eEsifError EsifGetActionDelegateCnfg(
	const EsifUpDomainPtr domainPtr,
	const EsifDataPtr requestPtr,
	EsifDataPtr responsePtr
	)
{
	extern int g_shell_enabled; // ESIF Shell Enabled Flag
	extern Bool g_ws_restricted;// Web Server Restricted Mode Flag
	eEsifError rc = ESIF_OK;
	EsifPrimitiveTuple dcfgTuple = { GET_CONFIG_ACCESS_CONTROL_SUR, 0, 255 };
	EsifPrimitiveTuple gddvTuple = { GET_CONFIG_DATAVAULT_SUR, 0, 255 };
	EsifData dcfgData = { ESIF_DATA_UINT32, NULL, ESIF_DATA_ALLOCATE, 0 };
	EsifData gddvData = { ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0 };

	ESIF_ASSERT(NULL != domainPtr);
	ESIF_ASSERT(NULL != requestPtr);

	UNREFERENCED_PARAMETER(responsePtr); // Not currently used by DPTF

	dcfgTuple.domain = domainPtr->domain;
	gddvTuple.domain = domainPtr->domain;

	// Execute DCFG to read Access Control List Bitmask from BIOS, if it exists
	rc = EsifUp_ExecutePrimitive(domainPtr->upPtr, &dcfgTuple, requestPtr, &dcfgData);
	if (rc == ESIF_OK && dcfgData.buf_ptr != NULL && dcfgData.buf_len >= sizeof(UInt32)) {
		DCfgOptions newmask = { .asU32 = *(UInt32 *)dcfgData.buf_ptr };
		DCfg_Set(newmask);

		ESIF_TRACE_INFO("DCFG Loaded: 0x%08X\n", newmask.asU32);

		// Disable ESIF Shell if Access Control forbids it
		if (DCfg_Get().opt.ShellAccessControl) {
			g_shell_enabled = 0;
		}

		// Stop Web Server (if Started) if Restricted or Generic Access Control forbids it
		if (EsifWebIsStarted() && 
			((!g_ws_restricted && DCfg_Get().opt.GenericUIAccessControl)|| 
			 (g_ws_restricted && DCfg_Get().opt.RestrictedUIAccessControl)) ) {
			EsifWebStop();
		}
	}

	// Execute GDDV to read DataVault from BIOS, if it exists
	rc = EsifUp_ExecutePrimitive(domainPtr->upPtr, &gddvTuple, requestPtr, &gddvData);
	if (rc != ESIF_OK) {
		// Always Return OK if no ESIF_LF or GDDV object in BIOS
		if (rc == ESIF_E_NO_LOWER_FRAMEWORK || rc == ESIF_E_ACPI_OBJECT_NOT_FOUND) {
			rc = ESIF_OK;
		}
	}
	else {
		char *dv_name = "__merge"; // Temporary DV Name
		DataVaultPtr DB = DataBank_GetNameSpace(g_DataBankMgr, dv_name);
		if (DB != NULL) {
			DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
		}
		DB = DataBank_OpenNameSpace(g_DataBankMgr, dv_name);

		// Load Datavault into temporary namespace. DV may or may not be preceded by a variant
		if (DB) {
			u32 skipbytes = 0;
			void *buffer = NULL;

			//
			// This is in place to resolve a static code analysis issue.
			// This should never happen if EsifUp_ExecutePrimitive is successful above.
			//
			if (NULL == gddvData.buf_ptr) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("No data returned for BIOS datavault.\n");
				goto exit;
			}

			skipbytes = (memcmp(gddvData.buf_ptr, "\xE5\x1F", 2) == 0 ? 0 : sizeof(union esif_data_variant));
			buffer = esif_ccb_malloc(gddvData.data_len);
			if (NULL == buffer) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("Unable to allocate memory\n");
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}

			esif_ccb_memcpy(buffer, (u8*)gddvData.buf_ptr + skipbytes, gddvData.data_len - skipbytes);
			IOStream_SetMemory(DB->stream, buffer, gddvData.data_len - skipbytes);

			if ((rc = DataVault_ReadVault(DB)) != ESIF_OK) {
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
				ESIF_TRACE_DEBUG("Unable to Open DataVault: %s\n", esif_rc_str(rc));
				rc = ESIF_OK;
			}
			else {
				EsifDataPtr data_nspace = NULL;
				EsifDataPtr data_key = NULL;
				EsifDataPtr data_targetdv = NULL;
				esif_flags_t options = 0; // NOPERSIST
				esif_string keyspec = "*"; // Merge All Keys
				esif_string targetdv = g_DataVaultDefault;

				DB->flags |= (ESIF_SERVICE_CONFIG_READONLY);

				// Merge Contents into Default DataVault
				data_nspace = EsifData_CreateAs(ESIF_DATA_STRING, dv_name, 0, ESIFAUTOLEN);
				data_targetdv = EsifData_CreateAs(ESIF_DATA_STRING, targetdv, 0, ESIFAUTOLEN);
				data_key = EsifData_CreateAs(ESIF_DATA_STRING, keyspec, 0, ESIFAUTOLEN);
				if (data_nspace == NULL || data_key == NULL || data_targetdv == NULL) {
					rc = ESIF_E_NO_MEMORY;
				}
				else {
					rc = EsifConfigCopy(data_nspace, data_targetdv, data_key, options, ESIF_FALSE, NULL);
				}

				ESIF_TRACE_INFO("GDDV Loaded: %d bytes, %d keys => %s.dv [%s]\n",
					(int)IOStream_GetSize(DB->stream),
					DataCache_GetCount(DB->cache),
					targetdv,
					esif_rc_str(rc));

				EsifData_Destroy(data_nspace);
				EsifData_Destroy(data_key);
				EsifData_Destroy(data_targetdv);
				DataBank_CloseNameSpace(g_DataBankMgr, dv_name);
			}
			esif_ccb_free(buffer);
		}
	}
exit:
	esif_ccb_free(dcfgData.buf_ptr);
	esif_ccb_free(gddvData.buf_ptr);
	return rc;
}
Beispiel #24
0
Guid::Guid(const UInt8 guid[GuidSize])
    : m_valid(true)
{
    esif_ccb_memcpy(m_guid, guid, GuidSize);
}
Beispiel #25
0
/* Work Around */
static enum esif_rc get_participant_data(
	struct esif_ipc_event_data_create_participant *pi_ptr,
	UInt8 participantId
	)
{
	eEsifError rc = ESIF_OK;

	struct esif_command_get_part_detail *data_ptr = NULL;
	struct esif_ipc_command *command_ptr = NULL;
	struct esif_ipc *ipc_ptr = NULL;
	const u32 data_len = sizeof(struct esif_command_get_part_detail);

	ipc_ptr = esif_ipc_alloc_command(&command_ptr, data_len);
	if (NULL == ipc_ptr || NULL == command_ptr) {
		ESIF_TRACE_ERROR("Fail to allocate esif_ipc/esif_ipc_command\n");
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	command_ptr->type = ESIF_COMMAND_TYPE_GET_PARTICIPANT_DETAIL;
	command_ptr->req_data_type   = ESIF_DATA_UINT32;
	command_ptr->req_data_offset = 0;
	command_ptr->req_data_len    = 4;
	command_ptr->rsp_data_type   = ESIF_DATA_STRUCTURE;
	command_ptr->rsp_data_offset = 0;
	command_ptr->rsp_data_len    = data_len;

	// ID For Command
	*(u32 *)(command_ptr + 1) = participantId;
	rc = ipc_execute(ipc_ptr);

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

	if (ESIF_OK != ipc_ptr->return_code) {
		rc = ipc_ptr->return_code;
		ESIF_TRACE_WARN("ipc_ptr return_code failure - %s\n", esif_rc_str(rc));
		goto exit;
	}

	if (ESIF_OK != command_ptr->return_code) {
		rc = command_ptr->return_code;
		ESIF_TRACE_WARN("command_ptr return_code failure - %s\n", esif_rc_str(rc));
		goto exit;
	}

	// our data
	data_ptr = (struct esif_command_get_part_detail *)(command_ptr + 1);
	if (0 == data_ptr->version) {
		ESIF_TRACE_ERROR("Participant version is 0\n");
		goto exit;
	}

	pi_ptr->id = (u8)data_ptr->id;
	pi_ptr->version = data_ptr->version;
	esif_ccb_memcpy(pi_ptr->class_guid, data_ptr->class_guid, ESIF_GUID_LEN);

	pi_ptr->enumerator = data_ptr->enumerator;
	pi_ptr->flags = data_ptr->flags;

	esif_ccb_strcpy(pi_ptr->name, data_ptr->name, ESIF_NAME_LEN);
	esif_ccb_strcpy(pi_ptr->desc, data_ptr->desc, ESIF_DESC_LEN);
	esif_ccb_strcpy(pi_ptr->driver_name, data_ptr->driver_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(pi_ptr->device_name, data_ptr->device_name, ESIF_NAME_LEN);
	esif_ccb_strcpy(pi_ptr->device_path, data_ptr->device_path, ESIF_NAME_LEN);

	/* ACPI */
	esif_ccb_strcpy(pi_ptr->acpi_device, data_ptr->acpi_device, ESIF_NAME_LEN);
	esif_ccb_strcpy(pi_ptr->acpi_scope, data_ptr->acpi_scope, ESIF_SCOPE_LEN);
	esif_ccb_strcpy(pi_ptr->acpi_uid, data_ptr->acpi_uid, sizeof(pi_ptr->acpi_uid));
	pi_ptr->acpi_type = data_ptr->acpi_type;

	/* PCI */
	pi_ptr->pci_vendor     = data_ptr->pci_vendor;
	pi_ptr->pci_device     = data_ptr->pci_device;
	pi_ptr->pci_bus        = data_ptr->pci_bus;
	pi_ptr->pci_bus_device = data_ptr->pci_bus_device;
	pi_ptr->pci_function   = data_ptr->pci_function;
	pi_ptr->pci_revision   = data_ptr->pci_revision;
	pi_ptr->pci_class      = data_ptr->pci_class;
	pi_ptr->pci_sub_class  = data_ptr->pci_sub_class;
	pi_ptr->pci_prog_if    = data_ptr->pci_prog_if;

exit:

	if (NULL != ipc_ptr) {
		esif_ipc_free(ipc_ptr);
	}
	return rc;
}
Beispiel #26
0
// Search and Replace
ZString IString_ReplaceIString (
	IStringPtr self,
	IStringPtr what,
	IStringPtr with,
	int IgnoreCase
	)
{
	ZString from, to, find;
	u32 count, oldsize, newsize;

	// Sanity checks. Cannot replace an empty string
	ESIF_ASSERT(self && what && with);
	if (self->data_len <= 1 || what->data_len <= 1) {
		return 0;
	}

	// Count occurances of replacment string in original string
	for (count = 0, find = (ZString)self->buf_ptr; (find = (ZString)strfind(find, (ZString)what->buf_ptr, IgnoreCase)) != NULL; count++)
		find += what->data_len - 1;

	// Compute new string size and Resize if necessary
	oldsize = self->data_len;
	newsize = self->data_len + (count * (int)(esif_ccb_max(with->data_len, 1) - what->data_len));
	if (newsize > self->buf_len) {
#ifdef ISTRING_AUTOGROW
		if (IString_Resize(self, newsize + ISTRING_AUTOGROW) == NULL)
#endif
		return 0;
	}

	// Do an in-string replacement so that another copy of the string does not need to be allocated
	// a) newsize <= oldsize: Do a left-to-right copy replacment
	// b) newsize >  oldsize: Move string to end of newsize buffer, then do a left-to-right copy replacement
	from = to = (ZString)self->buf_ptr;
	self->data_len = newsize;
	if (newsize > oldsize) {
		// Move string to end of reallocated (data_len) buffer
		esif_ccb_memmove(((ZString)self->buf_ptr) + (newsize - oldsize), (ZString)self->buf_ptr, oldsize);
		from += newsize - oldsize;
	}
	// Do a left-to-right copy (from -> to), replacing each occurance of old string (what) with new string (with)
	while ((find = (ZString)strfind(from, (ZString)what->buf_ptr, IgnoreCase)) != NULL) {
		if (from > to) {
			esif_ccb_memcpy(to, from, (size_t)(find - from));
		}
		to += (size_t)(find - from);
		if (with->data_len > 0) {
			esif_ccb_memcpy(to, (ZString)with->buf_ptr, with->data_len - 1);
			to += with->data_len - 1;
		}
		from = find + (what->data_len > 0 ? what->data_len - 1 : 0);
	}
	// Copy remainder of string, if any
	if (to < from) {
		esif_ccb_memcpy(to, from, newsize - (size_t)(to - (ZString)self->buf_ptr));
	}
	to += newsize - (size_t)(to - (ZString)self->buf_ptr);
	// zero out remainder of old string, if any
	if (oldsize > newsize) {
		esif_ccb_memset(to, 0, oldsize - newsize);
	}
	return (ZString)self->buf_ptr;
}
Beispiel #27
0
static int esif_ws_http_server_static_pages (
	char *buffer,
	char *resource,
	int fd,
	ssize_t ret,
	char *fileType
	)
{
	struct stat st;
	char tmpbuffer[128];
	char file_to_open[1000];
	FILE *file_fp = NULL;
	#define MAX_SIZE 200


	esif_ccb_memcpy(file_to_open, g_server_root, esif_ccb_strlen(g_server_root, MAX_SIZE));
	file_to_open[esif_ccb_strlen(g_server_root, MAX_SIZE)] = '\0';
	// printf("file to open after esif_ccb_memcpy: %s\n", file_to_open);
	// printf("resource : %s\n", resource);

#ifdef ESIF_ATTR_OS_WINDOWS

	strcat_s((esif_string)file_to_open, 1000, resource);
	esif_ccb_fopen(&file_fp, (esif_string)file_to_open, (esif_string)"rb");
#else
	strcat((esif_string)file_to_open, resource);
	esif_ccb_fopen(&file_fp, (esif_string)file_to_open, (esif_string)"r");
#endif
	printf("file to open: %s\n", file_to_open);
	printf("file type: %s\n", fileType);


	if (NULL == file_fp) {
		printf("failed to open file: %s\n", file_to_open);
		return 404;
	}

	if (esif_ccb_stat(file_to_open, &st) != 0) {
		printf("Could not stat file descriptor \n");
		fclose(file_fp);
		return 404;
	}


	(long)fseek(file_fp, (off_t)0, SEEK_END);
	(void)fseek(file_fp, (off_t)0, SEEK_SET);

	if (!strcmp(fileType, "text/xml")) {
		(void)esif_ccb_sprintf(BUFFER_LENGTH, buffer, (char*)"HTTP/1.1 200 OK\n<?xml version==\"1.0\" encoding=\"utf-8\"?>\n"
															 "Server: server/%d.0\n"
															 "Content-Type: %s\nContent-Length: %ld\nConnection: close\n\n",
							   VERSION, fileType, (long)st.st_size);
	} else {
		(void)esif_ccb_sprintf(BUFFER_LENGTH, buffer, (char*)"HTTP/1.1 200 OK\n"
															 "Server: server/%d.0\nLast-Modified: %s\nDate: %s\n"
															 "Content-Type: %s\nContent-Length: %ld\nConnection: close\n\n",
							   VERSION,
							   esif_ws_http_time_stamp(st.st_mtime, tmpbuffer), esif_ws_http_time_stamp(time(0), tmpbuffer), fileType, (long)st.st_size);
	}

	(void)send(fd, buffer, (int)esif_ccb_strlen(buffer, MAX_SIZE), 0);
	while ((ret = (int)fread(buffer, 1, BUFFER_LENGTH, file_fp)) > 0)

		(void)send(fd, buffer, ret, 0);
	fclose(file_fp);

	return 0;
}
Beispiel #28
0
static eEsifError EsifEventMgr_AddEntry(
	EsifFpcEventPtr fpcEventPtr,
	UInt8 participantId,
	UInt16 domainId,
	EVENT_OBSERVER_CALLBACK eventCallback,
	void *contextPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifLinkListPtr listPtr = NULL;
	EsifLinkListNodePtr nodePtr = NULL;
	EventMgrEntryPtr curEntryPtr = NULL;
	EventMgrEntryPtr newEntryPtr = NULL;
	atomic_t refCount = 1;

	ESIF_ASSERT(eventCallback != NULL);

	esif_ccb_write_lock(&g_EsifEventMgr.listLock);

	listPtr = g_EsifEventMgr.observerLists[fpcEventPtr->esif_event % NUM_EVENT_LISTS];
	if(NULL == listPtr) {
		rc = ESIF_E_UNSPECIFIED;
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}

	/* 
	 * First verify we don't already have the same entry.
	 * If we do, just increment the reference count.
	 */
	nodePtr = listPtr->head_ptr;
	while (nodePtr != NULL) {
		curEntryPtr = (EventMgrEntryPtr) nodePtr->data_ptr;
		if ((curEntryPtr->fpcEvent.esif_event == fpcEventPtr->esif_event) &&
			(curEntryPtr->participantId == participantId) &&
			(curEntryPtr->domainId == domainId) &&
			(curEntryPtr->contextPtr == contextPtr) &&
			(curEntryPtr->callback == eventCallback)){
			break;
		}
		nodePtr = nodePtr->next_ptr;
	}
	/* If we found an existing entry, update the reference count */
	if (nodePtr != NULL) {
		atomic_inc(&curEntryPtr->refCount);
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}
	esif_ccb_write_unlock(&g_EsifEventMgr.listLock);

	/*
	 * If an matching observer entry was not present; create a new observer entry,
	 * enable the events, and then place it into the list
	 */
	newEntryPtr = esif_ccb_malloc(sizeof(*newEntryPtr));
	if (NULL == newEntryPtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	newEntryPtr->callback = eventCallback;
	newEntryPtr->contextPtr = contextPtr;
	newEntryPtr->domainId = domainId;
	newEntryPtr->participantId = participantId;
	newEntryPtr->refCount = refCount;
	esif_ccb_memcpy(&newEntryPtr->fpcEvent, fpcEventPtr, sizeof(newEntryPtr->fpcEvent));

	nodePtr = esif_link_list_create_node(newEntryPtr);
	if (NULL == nodePtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}
	
	esif_ccb_write_lock(&g_EsifEventMgr.listLock);
	esif_link_list_add_node_at_back(listPtr, nodePtr);
	esif_ccb_write_unlock(&g_EsifEventMgr.listLock);

	rc = EsifEventMgr_EnableEvent(newEntryPtr);
	if (ESIF_OK != rc)
	{
		esif_ccb_write_lock(&g_EsifEventMgr.listLock);
		esif_link_list_node_remove(listPtr, nodePtr);
		esif_ccb_write_unlock(&g_EsifEventMgr.listLock);
		goto exit;
	}

exit:
	ESIF_TRACE_DEBUG("  RefCount: " ATOMIC_FMT "\n", refCount);

	if (ESIF_OK != rc) {
		esif_ccb_free(newEntryPtr);
	}

	return rc;
}
Beispiel #29
0
static void esif_ws_http_process_get_or_post (
	char *buffer,
	int fd,
	ssize_t ret
	)
{
	char *blankCharPtr0    = NULL;
	char *blankCharPtr1    = NULL;
	char *questMarkCharPtr = NULL;
	char resource[100];
	char *fileName;
	char *method;
	char *fileType = NULL;
	int result     = 0;

#ifdef ESIF_ATTR_OS_WINDOWS
	char *str;
#endif


	if (!strncmp(buffer, "GET ", 4)) {
		method = "GET";
	} else {
		method = "POST";
	}

	blankCharPtr0    = strchr(buffer, ' ');
	blankCharPtr0++;
	blankCharPtr1    = strchr(blankCharPtr0, ' ');
	questMarkCharPtr = strchr(blankCharPtr0, '?');


	/* special case */
	if (questMarkCharPtr && questMarkCharPtr < blankCharPtr1) {
		// resource =  (char *)esif_ccb_malloc(questMarkCharPtr - blankCharPtr0 );
		if (!strcmp(method, "GET")) {
			esif_ccb_memcpy(resource, buffer + 4, questMarkCharPtr - blankCharPtr0);
		} else {
			esif_ccb_memcpy(resource, buffer + 5, questMarkCharPtr - blankCharPtr0);
		}
		resource[questMarkCharPtr - blankCharPtr0] = 0;
	} else {
		// resource =  (char *)esif_ccb_malloc(blankCharPtr1 - blankCharPtr0);
		if (!strcmp(method, "GET")) {
			esif_ccb_memcpy(resource, buffer + 4, blankCharPtr1 - blankCharPtr0);
		} else {
			esif_ccb_memcpy(resource, buffer + 5, blankCharPtr1 - blankCharPtr0);
		}
		resource[blankCharPtr1 - blankCharPtr0] = 0;
	}

	printf("resource b4: %s\n", resource);
	if (resource[1] == '\0') {
		printf("empty resource: %s\n", resource);
		result = esif_ws_http_server_static_pages(buffer, "index.html", fd, ret, "text/html");
		if (result > 0)
		{
			esif_ws_http_send_error_code(fd, result);
			
		}
		
		return;
	}

	fileName = &resource[1];

	// resource++;
#ifdef ESIF_ATTR_OS_WINDOWS
	do {
		str = strchr(resource, '/');
		if (str) {
			str[0] = '\\';
		}
	} while (str != NULL);
	// printf("str: %s\n", str);
#endif
	fileType = esif_ws_http_get_file_type(fileName);
	if (NULL != fileType) {
		result = esif_ws_http_server_static_pages(buffer, fileName, fd, ret, fileType);
		
		if (result > 0)
		{
			esif_ws_http_send_error_code(fd, result);
			
		}
	
	} else {
		printf("File type is not valid\n");
	}
	
	esif_ws_http_send_error_code(fd, result);
	result = result;
}
Beispiel #30
0
eEsifError ESIF_CALLCONV EsifEventMgr_SignalEvent(
	UInt8 participantId,
	UInt16 domainId,
	eEsifEventType eventType,
	const EsifDataPtr eventDataPtr
	)
{
	eEsifError rc = ESIF_OK;
	EsifEventQueueItemPtr queueEventPtr = NULL;
	EsifDataPtr queueDataPtr = NULL;

	if (NULL == g_EsifEventMgr.eventQueuePtr) { /* Should never happen */
		rc = ESIF_E_UNSPECIFIED;
		goto exit;
	}

	queueEventPtr = esif_ccb_malloc(sizeof(*queueEventPtr));
	if (NULL == queueEventPtr) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	if ((eventDataPtr != NULL) &&
	    (eventDataPtr->buf_ptr != NULL) && 
	    (eventDataPtr->buf_len > 0) &&
	    (eventDataPtr->data_len > 0) &&
	    (eventDataPtr->buf_len >= eventDataPtr->data_len)) {

		queueDataPtr = esif_ccb_malloc(eventDataPtr->data_len);
		if (NULL == queueDataPtr) {
			rc = ESIF_E_NO_MEMORY;
			goto exit;
		}

		esif_ccb_memcpy(queueDataPtr, eventDataPtr->buf_ptr, eventDataPtr->data_len);

		queueEventPtr->eventData.type = eventDataPtr->type;
		queueEventPtr->eventData.buf_ptr = queueDataPtr;
		queueEventPtr->eventData.buf_len = eventDataPtr->data_len;
		queueEventPtr->eventData.data_len = eventDataPtr->data_len;
	}

	queueEventPtr->participantId = participantId;
	queueEventPtr->domainId = domainId;
	queueEventPtr->eventType = eventType;

	ESIF_TRACE_INFO("Queuing %s event for Part. %u Dom. 0x%04X\n",
		esif_event_type_str(eventType),
		participantId,
		domainId);

	rc = esif_queue_enqueue(g_EsifEventMgr.eventQueuePtr, queueEventPtr);
	if (rc != ESIF_OK) {
		goto exit;
	}

exit:
	if (rc != ESIF_OK) {
		esif_ccb_free(queueEventPtr);
		esif_ccb_free(queueDataPtr);

	}
	return rc;
}