예제 #1
0
DataVaultPtr DataBank_OpenNameSpace (
	DataBankPtr self,
	esif_string nameSpace
	)
{
	DataVaultPtr DB = NULL;
	UInt32 ns;

	// Exit if NameSpace already exists
	// TODO: Change this to a linked list or array of pointers so each DataVaultPtr is static
	esif_ccb_read_lock(&self->lock);
	for (ns = 0; ns < self->size; ns++) {
		if (esif_ccb_stricmp(nameSpace, self->elements[ns].name) == 0) {
			DB = &self->elements[ns];
			break;
		}
	}
	esif_ccb_read_unlock(&self->lock);
	if (DB != NULL || ns >= ESIF_MAX_NAME_SPACES) {
		return DB;
	}

	// Not Found. Create NameSpace
	esif_ccb_write_lock(&self->lock);
	DB = &self->elements[self->size++];
	DataVault_ctor(DB);
	esif_ccb_strcpy(DB->name, nameSpace, ESIF_NAME_LEN);
	esif_ccb_strlwr(DB->name, sizeof(DB->name));
	esif_ccb_write_unlock(&self->lock);
	return DB;
}
예제 #2
0
// Recursively create a path if it does not already exist
static int esif_ccb_makepath (char *path)
{
	int rc = -1;
	struct stat st = {0};

	// create path only if it does not already exist
	if ((rc = esif_ccb_stat(path, &st)) != 0) {
		size_t len = esif_ccb_strlen(path, MAX_PATH);
		char dir[MAX_PATH];
		char *slash;

		// trim any trailing slash
		esif_ccb_strcpy(dir, path, MAX_PATH);
		if (len > 0 && dir[len - 1] == *ESIF_PATH_SEP) {
			dir[len - 1] = 0;
		}

		// if path doesn't exist and can't be created, recursively create parent folder(s)
		if ((rc = esif_ccb_stat(dir, &st)) != 0 && (rc = esif_ccb_mkdir(dir)) != 0) {
			if ((slash = esif_ccb_strrchr(dir, *ESIF_PATH_SEP)) != 0) {
				*slash = 0;
				if ((rc = esif_ccb_makepath(dir)) == 0) {
					*slash = *ESIF_PATH_SEP;
					rc     = esif_ccb_mkdir(dir);
				}
			}
		}
	}
	return rc;
}
예제 #3
0
DataVaultPtr DataBank_OpenNameSpace (
	DataBankPtr self,
	esif_string nameSpace
	)
{
	DataVaultPtr DB = NULL;
	UInt32 ns;

	// TODO: Locking

	// Exit if NameSpace already exists
	// TODO: Change this to a linked list or array of pointers so each DataVaultPtr is static
	for (ns = 0; ns < self->size; ns++)
		if (strcmp(nameSpace, self->elements[ns].name) == 0) {
			return &self->elements[ns];
		}
	if (ns >= ESIF_MAX_NAME_SPACES) {
		return NULL;
	}

	// Not Found. Create NameSpace
	DB = &self->elements[self->size++];
	DataVault_ctor(DB);
	esif_ccb_strcpy(DB->name, nameSpace, ESIF_NAME_LEN);
	return DB;
}
예제 #4
0
파일: esif_ws_cgi.c 프로젝트: qbbian/dptf
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);
}
예제 #5
0
// new operator
DataVaultPtr DataVault_Create(char* name)
{
	DataVaultPtr self = (DataVaultPtr)esif_ccb_malloc(sizeof(*self));
	DataVault_ctor(self);

	esif_ccb_strcpy(self->name, name, sizeof(self->name));
	esif_ccb_strlwr(self->name, sizeof(self->name));

	return self;
}
예제 #6
0
IStringPtr IString_CreateFrom (IStringPtr src)
{
	IStringPtr self = IString_Create();
	if (self && src) {
		IString_SetInstance(self, esif_ccb_malloc(src->buf_len), src->buf_len, src->data_len);
		if (self->buf_ptr) {
			esif_ccb_strcpy((ZString)self->buf_ptr, (ZString)src->buf_ptr, src->data_len);
		}
	}
	return self;
}
예제 #7
0
// Duplicate a ZString substring into a new Dynamically-Allocated IString
IStringPtr IString_StrdupSubstr (
	ZString src,
	u32 chars
	)
{
	IStringPtr self = IString_CreateAs(chars + 1);
	if (self && self->buf_ptr) {
		esif_ccb_strcpy((ZString)self->buf_ptr, src, self->buf_len);
		self->data_len = self->buf_len;
	}
	return self;
}
예제 #8
0
파일: esif_ws_server.c 프로젝트: LjdCN/dptf
void esif_ws_server_set_ipaddr_port(const char *ipaddr, u32 portPtr, Bool restricted)
{
	if (ipaddr == NULL) {
		ipaddr = (restricted ? WEBSOCKET_RESTRICTED_IPADDR : WEBSOCKET_DEFAULT_IPADDR);
	}
	if (portPtr == 0) {
		portPtr = atoi(restricted ? WEBSOCKET_RESTRICTED_PORT : WEBSOCKET_DEFAULT_PORT);
	}
	esif_ccb_strcpy(g_ws_ipaddr, ipaddr, sizeof(g_ws_ipaddr));
	esif_ccb_sprintf(sizeof(g_ws_port), g_ws_port, "%d", portPtr);
	g_ws_restricted = restricted;
}
예제 #9
0
파일: esif_uf_pm.c 프로젝트: naitaku/dptf
/*
   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);
}
예제 #10
0
// This extracts the Kernel version from the string returned by esif_cmd_info()
static void extract_kernel_version(char *str, size_t buf_len)
{
	char *prefix = "Kernel Version = ";
	size_t len = esif_ccb_strlen(prefix, buf_len);

	if (str != NULL && esif_ccb_strnicmp(str, "Kernel Version = ", len) == 0) {
		esif_ccb_strcpy(str, str+len, buf_len);
		len = esif_ccb_strlen(str, buf_len);
		if (len > 1 && str[len-1] == '\n') {
			str[len-1] = 0;
		}
	}
}
예제 #11
0
eEsifError EsifCfgMgrInit ()
{
#ifdef ESIF_ATTR_OS_WINDOWS
		if (GetWindowsDirectoryA(g_DataVaultDir, sizeof(g_DataVaultDir)) == 0)
			esif_ccb_strcpy(g_DataVaultDir, "C:\\Windows", sizeof(g_DataVaultDir));
		esif_ccb_strcat(g_DataVaultDir, "\\ServiceProfiles\\LocalService\\AppData\\Local\\Intel\\DPTF\\", sizeof(g_DataVaultDir));
#else
		esif_ccb_strcpy(g_DataVaultDir, "/etc/dptf/", sizeof(g_DataVaultDir));
#endif

#ifdef BIG_LOCK
	esif_ccb_mutex_init(&g_shellLock);
#endif

	if (!g_DataBankMgr) {
		g_DataBankMgr = DataBank_Create();
		if (g_DataBankMgr) {
			return DataBank_LoadDataVaults(g_DataBankMgr);
		}
	}
	return ESIF_E_NO_MEMORY;
}
예제 #12
0
파일: esif_uf.c 프로젝트: hoangt/dptf
char *esif_memtrace_strdup(
	const char *str,
	const char *func,
	const char *file,
	int line
	)
{
	size_t len    = esif_ccb_strlen(str, 0x7fffffff) + 1;
	char *mem_ptr = (char *)esif_memtrace_alloc(0, len, func, file, line);
	if (NULL != mem_ptr) {
		esif_ccb_strcpy(mem_ptr, str, len);
	}
	return mem_ptr;
}
예제 #13
0
파일: esif_uf_pm.c 프로젝트: naitaku/dptf
/*
**  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;
}
예제 #14
0
// Copy an IString, overwriting the existing IString
ZString IString_Copy (
	IStringPtr self,
	IStringPtr src
	)
{
	ESIF_ASSERT(self && src);
	if (src->data_len > self->buf_len) {
#ifdef ISTRING_AUTOGROW
		if (IString_Resize(self, src->data_len + ISTRING_AUTOGROW) == NULL)
#endif
		return 0;
	}
	esif_ccb_strcpy((ZString)self->buf_ptr, (ZString)src->buf_ptr, self->buf_len);
	self->data_len = src->data_len;
	return (ZString)self->buf_ptr;
}
예제 #15
0
// Concatenate (Append) an IString to the current IString
ZString IString_Concat (
	IStringPtr self,
	IStringPtr src
	)
{
	u32 self_len;
	ESIF_ASSERT(self && src);
	self_len = (self->data_len ? self->data_len - 1 : 0);
	if (self_len + src->data_len > self->buf_len) {
#ifdef ISTRING_AUTOGROW
		if (IString_Resize(self, self_len + src->data_len + ISTRING_AUTOGROW) == NULL)
#endif
		return 0;
	}
	esif_ccb_strcpy((ZString)self->buf_ptr + self_len, (ZString)src->buf_ptr, self->buf_len - self_len);
	self->data_len += src->data_len - 1;
	return (ZString)self->buf_ptr;
}
예제 #16
0
파일: esif_uf.c 프로젝트: hoangt/dptf
// Build Full Pathname for a given path type including an optional filename and extention. 
esif_string esif_build_path(
	esif_string buffer, 
	size_t buf_len,
	esif_pathtype type,
	esif_string filename,
	esif_string ext)
{
	char *pathname = NULL;

	if (NULL == buffer) {
		return NULL;
	}

	// Get Pathname. Do not return full path in result string if it starts with a "#" unless no filename specified
	if ((pathname = esif_pathlist_get(type)) != NULL) {
		if (*pathname == '#') {
			if (filename == NULL && ext == NULL)
				pathname++;
			else
				pathname = "";
		}
		esif_ccb_strcpy(buffer, pathname, buf_len);
	}

	// Create folder if necessary
	if (buffer[0] != '\0') {
		esif_ccb_makepath(buffer);
	}

	// Append Optional filename.ext
	if (filename != NULL || ext != NULL) {
		if (buffer[0] != '\0')
			esif_ccb_strcat(buffer, ESIF_PATH_SEP, buf_len);
		if (filename != NULL)
			esif_ccb_strcat(buffer, filename, buf_len);
		if (ext != NULL)
			esif_ccb_strcat(buffer, ext, buf_len);
	}
	if (buffer[0] == '\0') {
		buffer = NULL;
	}
	return buffer;
}
예제 #17
0
/* Get Kernel Information */
static void esif_execute_ipc_command_get_kernel_info(
	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_kernel_info) ==
	    command_ptr->rsp_data_len) {
		struct esif_command_get_kernel_info *data_ptr =
			(struct esif_command_get_kernel_info *)
			(command_ptr + 1);

		esif_ccb_strcpy(data_ptr->ver_str, ESIF_VERSION, ESIF_NAME_LEN);

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

		command_ptr->return_code = ESIF_OK;
	}
}
예제 #18
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 */
}
예제 #19
0
// Retrieve a single value from a DataVault
eEsifError DataVault_GetValue(
	DataVaultPtr self,
	EsifDataPtr path,
	EsifDataPtr value,
	esif_flags_t *flagsPtr
	)
{
	eEsifError rc = ESIF_E_NOT_FOUND;
	DataCacheEntryPtr keypair = NULL;

	if (!self)
		return ESIF_E_PARAMETER_IS_NULL;

	if (flagsPtr)
		*flagsPtr = 0;

	// Return "keyname1|keyname2|..." if path contains "*" or "?"
	if (esif_ccb_strpbrk((esif_string)path->buf_ptr, "*?") != NULL) {
		EsifDataPtr nameSpace = EsifData_CreateAs(ESIF_DATA_STRING, esif_ccb_strdup(self->name), ESIFAUTOLEN, ESIFAUTOLEN);
		EsifDataPtr key		  = EsifData_CreateAs(ESIF_DATA_STRING, path->buf_ptr, 0, ESIFAUTOLEN);
		EsifConfigFindContext context = NULL;
		esif_string keylist = NULL;
		u32 data_len = 0;
		
		// Verify valid Data Type and Data Buffer size
		if (value->type != ESIF_DATA_STRING && value->type != ESIF_DATA_AUTO) {
			rc = ESIF_E_UNSUPPORTED_RESULT_DATA_TYPE;
		}
		
		if (rc == ESIF_E_NOT_FOUND && nameSpace != NULL && key != NULL && (rc = EsifConfigFindFirst(nameSpace, key, NULL, &context)) == ESIF_OK) {
			do {
				data_len += (u32)key->data_len;
				esif_string newlist = esif_ccb_realloc(keylist, data_len);
				if (newlist == NULL) {
					EsifData_Set(key, ESIF_DATA_STRING, "", 0, ESIFAUTOLEN);
					rc = ESIF_E_NO_MEMORY;
					break;
				}
				keylist = newlist;
				esif_ccb_sprintf_concat(data_len, keylist, "%s%s", (*keylist ? "|" : ""), (char *)key->buf_ptr);
				EsifData_Set(key, ESIF_DATA_STRING, path->buf_ptr, 0, ESIFAUTOLEN);
			} while ((rc = EsifConfigFindNext(nameSpace, key, NULL, &context)) == ESIF_OK);
		
			EsifConfigFindClose(&context);
			if (rc == ESIF_E_ITERATION_DONE) {
				rc = ESIF_OK;
			}
		}
		EsifData_Destroy(nameSpace);
		EsifData_Destroy(key);
		if (!keylist || rc != ESIF_OK) {
			esif_ccb_free(keylist);
			return rc;
		}

		// Return keylist value and data type
		if (value->type == ESIF_DATA_AUTO) {
			value->type = ESIF_DATA_STRING;
		}
		if (value->buf_len == ESIF_DATA_ALLOCATE) {
			esif_ccb_free(value->buf_ptr);
			value->buf_ptr = esif_ccb_strdup(keylist);
			value->buf_len = data_len;
			value->data_len = data_len;
		}
		else if (value->buf_len < data_len) {
			rc = ESIF_E_NEED_LARGER_BUFFER;
			value->data_len = data_len;
		}
		else if (value->buf_ptr) {
			esif_ccb_strcpy(value->buf_ptr, keylist, value->buf_len);
			value->data_len = data_len;
		}
		esif_ccb_free(keylist);
		return rc;
	}

	// Write to Log before retrieval if AUTO
	if (value->type == ESIF_DATA_AUTO || value->buf_len == ESIF_DATA_ALLOCATE) {
		DataVault_WriteLog(self, "AUTO", (esif_string)(self->name), path, 0, value);
	}

	keypair = DataCache_GetValue(self->cache, (esif_string)path->buf_ptr);
	
	if (NULL != keypair) {
		UInt32 data_len = keypair->value.data_len;
		void *buf_ptr   = keypair->value.buf_ptr;
		UInt32 buf_len  = 0;
		Bool buf_alloc = ESIF_FALSE;

		// File Redirect?
		if (keypair->flags & ESIF_SERVICE_CONFIG_FILELINK) {
			if (ReadFileIntoBuffer((esif_string)buf_ptr, &buf_ptr, &data_len) != ESIF_OK) {
				value->data_len = 0;
				if (value->type == ESIF_DATA_AUTO) {
					value->type = keypair->value.type;
				}
				if (value->buf_len == ESIF_DATA_ALLOCATE) {
					value->buf_len = 0;
					value->buf_ptr = 0;
				}
				return ESIF_OK;	// return OK and a blank buffer if file not found/error
			}
			// Include Null Terminator if result is STRING
			if (value->buf_len == ESIF_DATA_ALLOCATE && (value->type == ESIF_DATA_STRING || (value->type == ESIF_DATA_AUTO && keypair->value.type == ESIF_DATA_STRING))) {
				data_len++;
			}
			buf_len = data_len;
			buf_alloc = ESIF_TRUE;
		}

		// Match Found. Verify Data Type matches unless AUTO
		if (value->type != keypair->value.type && value->type != ESIF_DATA_AUTO) {
			rc = ESIF_E_UNSUPPORTED_RESULT_DATA_TYPE;	// TODO: ESIF_E_INVALID_DATA_TYPE
		}
		// Verify Data Buffer is large enough unless Auto-Allocate
		else if (value->buf_len < data_len && value->buf_len != ESIF_DATA_ALLOCATE) {
			value->data_len = data_len;
			rc = ESIF_E_NEED_LARGER_BUFFER;
		}
		// Return pointer to static contents if this is a static vault
		else if ((self->flags & ESIF_SERVICE_CONFIG_STATIC) &&
				 (value->type == ESIF_DATA_AUTO) &&
				 (value->buf_len == ESIF_DATA_ALLOCATE)) {
			value->type     = keypair->value.type;
			value->data_len = data_len;
			value->buf_len  = 0;	// Caller MUST NOT Free!
			value->buf_ptr  = buf_ptr;
			rc = ESIF_OK;
		} 
		else {
			// Set Data Type and Auto-Allocate Buffer?
			if (value->type == ESIF_DATA_AUTO) {
				value->type = keypair->value.type;
			}
			if (ESIF_DATA_ALLOCATE == value->buf_len) {
				value->buf_len = esif_ccb_max(1, data_len);
				value->buf_ptr = esif_ccb_malloc(value->buf_len);
				if (!value->buf_ptr) {
					if (buf_alloc) {
						esif_ccb_free(buf_ptr);
					}
					return ESIF_E_NO_MEMORY;
				}
			}

			// Read from file if NOCACHE option
			if ((keypair->flags & ESIF_SERVICE_CONFIG_NOCACHE) && keypair->value.buf_len == 0) {
				size_t offset = (size_t)keypair->value.buf_ptr;
				if (DataVault_GetFromSource(self, (esif_string)value->buf_ptr, data_len, offset) != ESIF_OK) {
					if (buf_alloc) {
						esif_ccb_free(buf_ptr);
					}
					return ESIF_E_NOT_FOUND;
				}
				// Unscramble Data?
				if (keypair->flags & ESIF_SERVICE_CONFIG_SCRAMBLE) {
					UInt32 byte;
					for (byte = 0; byte < data_len; byte++)
						((UInt8*)(value->buf_ptr))[byte] = ~((UInt8*)(value->buf_ptr))[byte];
				}
			} else {
				esif_ccb_memcpy(value->buf_ptr, buf_ptr, data_len);
			}
			value->data_len = data_len;
			rc = ESIF_OK;
		}

		// Return flags
		if (rc == ESIF_OK) {
			if (flagsPtr != NULL)
				*flagsPtr = keypair->flags;
		}

		// Destroy Dynamically copied data, such as FILELINK contents
		if (buf_alloc) {
			esif_ccb_free(buf_ptr);
		}
	}
	// Write to Log
	DataVault_WriteLog(self, "GET", (esif_string)self->name, path, 0, value);
	return rc;
}
예제 #20
0
파일: esif_ws_http.c 프로젝트: hoangt/dptf
static int esif_ws_http_process_static_pages (
	ClientRecordPtr connection,
	char *buffer,
	char *resource,
	ssize_t ret,
	char *fileType
	)
{
	struct stat st={0};
	char tmpbuffer[128]={0};
	char file_to_open[MAX_PATH]={0};
	char content_disposition[MAX_PATH]={0};
	FILE *file_fp = NULL;

	esif_build_path(file_to_open, sizeof(file_to_open), ESIF_PATHTYPE_UI, resource, NULL);
	esif_ccb_fopen(&file_fp, (esif_string)file_to_open, (esif_string)"rb");
	
	// Log file workaround: If not found in HTML folder, look in LOG folder
	if (NULL == file_fp) {
		char logpath[MAX_PATH]={0};
		esif_build_path(logpath, sizeof(logpath), ESIF_PATHTYPE_LOG, resource, NULL);
		esif_ccb_fopen(&file_fp, (esif_string)logpath, (esif_string)"rb");
		if (NULL != file_fp) 
			esif_ccb_strcpy(file_to_open, logpath, sizeof(file_to_open));
	}
	
	ESIF_TRACE_DEBUG("HTTP: file=%s, type=%s\n", file_to_open, fileType);
	if (NULL == file_fp) {
		ESIF_TRACE_DEBUG("failed to open file: %s\n", file_to_open);
		return 404;
	}

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

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

	// Add Content-Disposition header to prompt user with Save-As Dialog if unknown file type
	if (esif_ccb_strcmp(fileType, UNKNOWN_MIME_TYPE) == 0) {
		esif_ccb_sprintf(sizeof(content_disposition), content_disposition,  "Content-Disposition: attachment; filename=\"%s\";\n", resource);
	}

	esif_ccb_sprintf(WS_BUFFER_LENGTH, buffer,	
					"HTTP/1.1 200 OK\n"
					"Server: ESIF_UF/%s\n"
					"Last-Modified: %s\n"
					"Date: %s\n"
					"Content-Type: %s\n"
					"Content-Length: %ld\n"
					"%s"
					"Connection: close\n"
					"\n",
				ESIF_UF_VERSION,
				esif_ws_http_time_stamp(st.st_mtime, tmpbuffer),
				esif_ws_http_time_stamp(time(0), tmpbuffer), 
				fileType, 
				(long)st.st_size, 
				content_disposition);

	send(connection->socket, buffer, (int)esif_ccb_strlen(buffer, WS_BUFFER_LENGTH), ESIF_WS_SEND_FLAGS);
	while ((ret = (int)fread(buffer, 1, WS_BUFFER_LENGTH, file_fp)) > 0) {
		send(connection->socket, buffer, (int)ret, ESIF_WS_SEND_FLAGS);
	}
	fclose(file_fp);

	return 0;
}
예제 #21
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;
}
예제 #22
0
/* Get Kernel Information */
static void esif_execute_ipc_command_get_memory_stats(
	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_memory_stats) ==
	    command_ptr->rsp_data_len) {

		struct esif_command_get_memory_stats *data_ptr =
			(struct esif_command_get_memory_stats *)
			(command_ptr + 1);
		u32 reset = *(u32 *)data_ptr;

		if (reset) {
			esif_ccb_memset(&data_ptr->stats, 0,
					sizeof(struct esif_memory_stats));

			esif_ccb_write_lock(&g_memstat_lock);
			esif_ccb_memset(&g_memstat, 0,
					sizeof(struct esif_memory_stats));
			esif_ccb_write_unlock(&g_memstat_lock);
		} else {
			int i = 0;

			esif_ccb_read_lock(&g_memstat_lock);
			esif_ccb_memcpy(&data_ptr->stats, &g_memstat,
					sizeof(struct esif_memory_stats));
			esif_ccb_read_unlock(&g_memstat_lock);

			esif_ccb_read_lock(&g_mempool_lock);
			for (i = 0; i < ESIF_MEMPOOL_TYPE_MAX; i++) {
				if (NULL == g_mempool[i])
					continue;	/* Skip Unused */

				esif_ccb_strcpy(data_ptr->mempool_stat[i].name,
						g_mempool[i]->name_ptr,
						ESIF_NAME_LEN);
				data_ptr->mempool_stat[i].pool_tag    =
					g_mempool[i]->pool_tag;
				data_ptr->mempool_stat[i].object_size =
					g_mempool[i]->object_size;
				data_ptr->mempool_stat[i].alloc_count =
					g_mempool[i]->alloc_count;
				data_ptr->mempool_stat[i].free_count  =
					g_mempool[i]->free_count;
			}
			esif_ccb_read_unlock(&g_mempool_lock);

			esif_ccb_read_lock(&g_memtype_lock);
			for (i = 0; i < ESIF_MEMTYPE_TYPE_MAX; i++) {
				if (NULL == g_memtype[i])
					continue;	/* Skip Unused */

				esif_ccb_strcpy(data_ptr->memtype_stat[i].name,
						g_memtype[i]->name_ptr,
						ESIF_NAME_LEN);
				data_ptr->memtype_stat[i].pool_tag    =
					g_memtype[i]->type_tag;
				data_ptr->memtype_stat[i].alloc_count =
					g_memtype[i]->alloc_count;
				data_ptr->memtype_stat[i].free_count  =
					g_memtype[i]->free_count;
			}
			esif_ccb_read_unlock(&g_memtype_lock);
		}

		ESIF_TRACE_DYN_COMMAND(
			"%s: ESIF_COMMAND_TYPE_GET_MEMORY_STATS reset %d\n",
			ESIF_FUNC,
			reset);

		command_ptr->return_code = ESIF_OK;
	}
}
예제 #23
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;
	}
}
예제 #24
0
파일: esif_uf.c 프로젝트: hoangt/dptf
/* 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;
}
예제 #25
0
파일: esif_uf_dspmgr.c 프로젝트: 01org/dptf
static eEsifError esif_dsp_file_scan()
{
	eEsifError rc = ESIF_OK;
	struct esif_ccb_file *ffdPtr = NULL;
	esif_ccb_file_enum_t findHandle = ESIF_INVALID_FILE_ENUM_HANDLE;
	char path[MAX_PATH]    = {0};
	char pattern[MAX_PATH] = {0};
	StringPtr namesp = ESIF_DSP_NAMESPACE;
	DataVaultPtr DB = DataBank_GetDataVault(namesp);

	// 1. Load all EDP's in the DSP Configuration Namespace, if any exist
	if (DB) {
		EsifDataPtr nameSpace = EsifData_CreateAs(ESIF_DATA_AUTO, namesp, 0, ESIFAUTOLEN);
		EsifDataPtr key       = EsifData_CreateAs(ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);
		EsifDataPtr value     = EsifData_CreateAs(ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);
		EsifConfigFindContext context = NULL;

		ESIF_TRACE_DEBUG("SCAN CONFIG For DSP Files NameSpace = %s, Pattern %s", namesp, pattern);
		if (nameSpace != NULL && key != NULL && value != NULL &&
			(rc = EsifConfigFindFirst(nameSpace, key, value, &context)) == ESIF_OK) {
			do {
				// Load all keys from the DataVault with an ".edp" extension
				if (key->data_len >= 5 && esif_ccb_stricmp(((StringPtr)(key->buf_ptr)) + key->data_len - 5, ".edp") == 0) {
					ffdPtr = (struct esif_ccb_file *)esif_ccb_malloc(sizeof(*ffdPtr));
					esif_ccb_strcpy(ffdPtr->filename, (StringPtr)key->buf_ptr, sizeof(ffdPtr->filename));
					if (esif_dsp_entry_create(ffdPtr) != ESIF_OK) {
						esif_ccb_free(ffdPtr);
					}
				}
				EsifData_Set(key, ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);
				EsifData_Set(value, ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);
			} while ((rc = EsifConfigFindNext(nameSpace, key, value, &context)) == ESIF_OK);

			EsifConfigFindClose(&context);
			if (rc == ESIF_E_ITERATION_DONE) {
				rc = ESIF_OK;
			}
		}
		EsifData_Destroy(nameSpace);
		EsifData_Destroy(key);
		EsifData_Destroy(value);
	}

	// 2. Load all EDP's from the DSP folder, if any exist, except ones already loaded from DataBank
	esif_build_path(path, MAX_PATH, ESIF_PATHTYPE_DSP, NULL, NULL);
	esif_ccb_strcpy(pattern, "*.edp", MAX_PATH);

	ESIF_TRACE_DEBUG("SCAN File System For DSP Files Path = %s, Pattern %s", path, pattern);
	/* Find the first file in the directory that matches are search */
	ffdPtr = (struct esif_ccb_file *)esif_ccb_malloc(sizeof(*ffdPtr));
	if (ffdPtr == NULL) {
		ESIF_TRACE_ERROR("Fail to allocate esif_ccb file\n");
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	findHandle = esif_ccb_file_enum_first(path, pattern, ffdPtr);
	if (ESIF_INVALID_FILE_ENUM_HANDLE == findHandle) {
		rc = ESIF_E_UNSPECIFIED;
		goto exit;
	}

	/* Process Each File */
	do {
		// Don't process the file if it the same name was already loaded from a DataVault
		if (DB == NULL || DataCache_GetValue(DB->cache, ffdPtr->filename) == NULL) {
			if (esif_dsp_entry_create(ffdPtr) != ESIF_OK) {
				esif_ccb_free(ffdPtr);
			}
			ffdPtr = (struct esif_ccb_file *)esif_ccb_malloc(sizeof(*ffdPtr));
		}
	} while (esif_ccb_file_enum_next(findHandle, pattern, ffdPtr));
	esif_ccb_file_enum_close(findHandle);

exit:
	if (ffdPtr != NULL) {
		esif_ccb_free(ffdPtr);
	}
	return rc;
}
예제 #26
0
파일: esif_uf_dspmgr.c 프로젝트: 01org/dptf
/* Add DSP Entry */
static eEsifError esif_dsp_entry_create(struct esif_ccb_file *file_ptr)
{
	eEsifError rc  = ESIF_E_UNSPECIFIED;
	EsifDspPtr dspPtr = NULL;
	EsifFpcPtr fpcPtr    = NULL;
	UInt32 fpcIsStatic = ESIF_FALSE;
	UInt8 i = 0;
	char path[MAX_PATH]={0};
	UInt32 fpcSize = 0;
	UInt32 edpSize = 0;
	size_t numFpcBytesRead = 0;
	struct edp_dir edp_dir;
	EsifDataPtr nameSpace = 0;
	EsifDataPtr key = 0;
	EsifDataPtr value = 0;
	IOStreamPtr ioPtr = IOStream_Create();

	if ((NULL == file_ptr) || (NULL == ioPtr)) {
		ESIF_TRACE_ERROR("The file pointer or IO stream is NULL\n");
		goto exit;
	}
	nameSpace = EsifData_CreateAs(ESIF_DATA_STRING, ESIF_DSP_NAMESPACE, 0, ESIFAUTOLEN);
	key       = EsifData_CreateAs(ESIF_DATA_STRING, file_ptr->filename, 0, ESIFAUTOLEN);
	value     = EsifData_CreateAs(ESIF_DATA_AUTO, NULL, ESIF_DATA_ALLOCATE, 0);

	if (nameSpace == NULL || key == NULL || value == NULL) {
		rc = ESIF_E_NO_MEMORY;
		goto exit;
	}

	ESIF_TRACE_DEBUG("Filename: %s", file_ptr->filename);

	dspPtr = esif_dsp_create();
	if (NULL == dspPtr) {
		ESIF_TRACE_ERROR("Fail to allocate dsp entry\n");
		goto exit;
	}

	// Look for EDP file on disk first then in DataVault (static or file)
	esif_build_path(path, sizeof(path), ESIF_PATHTYPE_DSP, file_ptr->filename, NULL);
	if (!esif_ccb_file_exists(path) && EsifConfigGet(nameSpace, key, value) == ESIF_OK) {
		esif_ccb_strcpy(path, file_ptr->filename, MAX_PATH);
		IOStream_SetMemory(ioPtr, StoreReadOnly, (BytePtr)value->buf_ptr, value->data_len);
	} else {
		IOStream_SetFile(ioPtr, StoreReadOnly, path, "rb");
	}
	ESIF_TRACE_DEBUG("Fullpath: %s", path);

	if (IOStream_Open(ioPtr) != 0) {
		ESIF_TRACE_ERROR("File not found (%s)", path);
		goto exit;
	}

	/* Read FPC From EDP File */
	if (esif_ccb_strstr(&path[0], ".edp")) {
		/* EDP - Only Read The FPC Part */
		edpSize = (UInt32)IOStream_GetSize(ioPtr);
		if (!edpSize) {
			goto exit;
		}
		numFpcBytesRead = IOStream_Read(ioPtr, &edp_dir, sizeof(edp_dir));
		if (!esif_verify_edp(&edp_dir, numFpcBytesRead)) {
			ESIF_TRACE_ERROR("Invalid EDP Header: Signature=%4.4s Version=%d\n", (char *)&edp_dir.signature, edp_dir.version);
			goto exit;
		}
		if (edpSize > MAX_EDP_SIZE || edp_dir.fpc_offset > MAX_FPC_SIZE || edp_dir.fpc_offset > edpSize) {
			ESIF_TRACE_ERROR("The edp or fpc file size is larger than maximum\n");
			goto exit;
		}
		fpcSize = edpSize - edp_dir.fpc_offset;
		IOStream_Seek(ioPtr, edp_dir.fpc_offset, SEEK_SET);
		ESIF_TRACE_DEBUG("File found (%s) size %u, FPC size %u from offset %u", path, edpSize, fpcSize, edp_dir.fpc_offset);
	} else {
		ESIF_TRACE_DEBUG("File %s does not have .fpc and .edp format!", path);
	}

	// use static DataVault buffer (if available), otherwise allocate space for our FPC file contents (which will not be freed)
	if (IOStream_GetType(ioPtr) == StreamMemory && value->buf_len == 0) {
		fpcPtr = (EsifFpcPtr)IOStream_GetMemoryBuffer(ioPtr); 
		if (NULL == fpcPtr) {
			ESIF_TRACE_ERROR("NULL buffer");
			goto exit;
		}
		fpcPtr  = (EsifFpcPtr) (((BytePtr) fpcPtr) + IOStream_GetOffset(ioPtr));
		numFpcBytesRead = fpcSize;
		ESIF_TRACE_DEBUG("Static vault size %u buf_ptr=0x%p\n", (int)numFpcBytesRead, fpcPtr);
		fpcIsStatic = ESIF_TRUE;
	} else {
		fpcPtr = (EsifFpcPtr)esif_ccb_malloc(fpcSize);
		if (NULL == fpcPtr) {
			ESIF_TRACE_ERROR("malloc failed to allocate %u bytes\n", fpcSize);
			goto exit;
		}
		ESIF_TRACE_DEBUG("File malloc size %u", fpcSize);

		// read file contents
		numFpcBytesRead = IOStream_Read(ioPtr, fpcPtr, fpcSize);
		if (numFpcBytesRead < fpcSize) {
			ESIF_TRACE_ERROR("Read short received %u of %u bytes\n", (int)numFpcBytesRead, fpcSize);
			goto exit;
		}

		ESIF_TRACE_DEBUG("File read size %u", (int)numFpcBytesRead);
	}
	ESIF_TRACE_DEBUG("\nDecode Length:  %u", fpcPtr->size);
	ESIF_TRACE_DEBUG("Code:           %s", fpcPtr->header.code);
	ESIF_TRACE_DEBUG("Ver Major:      %u", fpcPtr->header.ver_major);
	ESIF_TRACE_DEBUG("Ver Minor:      %u", fpcPtr->header.ver_minor);
	ESIF_TRACE_DEBUG("Name:           %s", fpcPtr->header.name);
	ESIF_TRACE_DEBUG("Description:    %s", fpcPtr->header.description);
	ESIF_TRACE_DEBUG("Type:           %s", fpcPtr->header.type);
	ESIF_TRACE_DEBUG("Bus Enumerator: %u", fpcPtr->header.bus_enum);
	ESIF_TRACE_DEBUG("ACPI Device:    %s", fpcPtr->header.acpi_device);
	ESIF_TRACE_DEBUG("ACPI Scope:     %s", fpcPtr->header.acpi_scope);
	ESIF_TRACE_DEBUG("ACPI Type:      %s", fpcPtr->header.acpi_type);
	ESIF_TRACE_DEBUG("ACPI UID:       %s", fpcPtr->header.acpi_UID);
	ESIF_TRACE_DEBUG("PCI Vendor ID:  %s", fpcPtr->header.pci_vendor_id);
	ESIF_TRACE_DEBUG("PCI Device ID:  %s", fpcPtr->header.pci_device_id);
	ESIF_TRACE_DEBUG("PCI Bus:        %s", fpcPtr->header.pci_bus);
	ESIF_TRACE_DEBUG("PCI Device:     %s", fpcPtr->header.pci_device);
	ESIF_TRACE_DEBUG("PCI Function:   %s", fpcPtr->header.pci_function);

	dspPtr->code_ptr = (EsifString)fpcPtr->header.name;
	dspPtr->bus_enum = (UInt8 *)&fpcPtr->header.bus_enum;
	dspPtr->type     = (EsifString)fpcPtr->header.type;
	dspPtr->ver_major_ptr  = (UInt8 *)&fpcPtr->header.ver_major;
	dspPtr->ver_minor_ptr  = (UInt8 *)&fpcPtr->header.ver_minor;
	dspPtr->acpi_device    = (EsifString)fpcPtr->header.acpi_device;
	dspPtr->acpi_scope     = (EsifString)fpcPtr->header.acpi_scope;
	dspPtr->acpi_type      = (EsifString)fpcPtr->header.acpi_type;
	dspPtr->acpi_uid       = (EsifString)fpcPtr->header.acpi_UID;
	dspPtr->vendor_id      = (EsifString)fpcPtr->header.pci_vendor_id;
	dspPtr->device_id      = (EsifString)fpcPtr->header.pci_device_id;
	dspPtr->pci_bus		= (EsifString)&fpcPtr->header.pci_bus;
	dspPtr->pci_bus_device = (EsifString)&fpcPtr->header.pci_device;
	dspPtr->pci_function   = (EsifString)&fpcPtr->header.pci_function;

	/* Assign Function Pointers */
	dspPtr->get_code = get_code;
	dspPtr->get_ver_minor     = get_ver_minor;
	dspPtr->get_ver_major     = get_ver_major;
	dspPtr->get_temp_tc1      = get_temp_c1;
	dspPtr->get_percent_xform      = get_percent_xform;

	dspPtr->insert_primitive  = insert_primitive;
	dspPtr->insert_algorithm  = insert_algorithm;
	dspPtr->insert_domain     = insert_domain;
	dspPtr->insert_event      = insert_event;
	dspPtr->get_primitive     = get_primitive;
	dspPtr->get_action = get_action;
	dspPtr->get_algorithm     = get_algorithm;
	dspPtr->get_domain = get_domain;
	dspPtr->get_event_by_type = get_event_by_type;
	dspPtr->get_event_by_guid = get_event_by_guid;
	dspPtr->init_fpc_iterator = init_fpc_iterator;
	dspPtr->get_next_fpc_domain = get_next_fpc_domain;


	dspPtr->get_domain_count = get_domain_count;

	rc = esif_fpc_load(fpcPtr, dspPtr);
	if (ESIF_OK == rc) {
		ESIF_TRACE_DEBUG("FPC %s load successfully", path);
	} else {
		ESIF_TRACE_DEBUG("Unable to load FPC %s, rc %s", path, esif_rc_str(rc));
		goto exit;
	}

	/* Lock DSP Manager */
	esif_ccb_write_lock(&g_dm.lock);

	/* Simple Table Lookup For Now. Scan Table And Find First Empty Slot */
	/* Empty slot indicated by AVAILABLE state                           */
	for (i = 0; i < MAX_DSP_MANAGER_ENTRY; i++) {
		if (NULL == g_dm.dme[i].dsp_ptr) {
			break;
		}
	}

	/* If No Available Slots Return */
	if (i >= MAX_DSP_MANAGER_ENTRY) {
		esif_ccb_write_unlock(&g_dm.lock);
		ESIF_TRACE_ERROR("No free dsp manager entry is available for %s\n", file_ptr->filename);
		goto exit;
	}

	/*
	** Take Slot
	*/
	g_dm.dme[i].dsp_ptr  = dspPtr;
	g_dm.dme[i].file_ptr = file_ptr;
	g_dm.dme[i].fpc_ptr  = (fpcIsStatic ? 0 : fpcPtr);
	g_dm.dme_count++;
	dspPtr = NULL;	// Prevent deallocate on exit
	fpcPtr = NULL;	// Prevent deallocate on exit

	esif_ccb_write_unlock(&g_dm.lock);
	rc = ESIF_OK;
	ESIF_TRACE_INFO("Create entry in dsp manager successfully for %s\n", file_ptr->filename);

exit:
	IOStream_Destroy(ioPtr);
	EsifData_Destroy(nameSpace);
	EsifData_Destroy(key);
	EsifData_Destroy(value);
	esif_dsp_destroy(dspPtr);
	if (!fpcIsStatic) {
		esif_ccb_free(fpcPtr);
	}
	return rc;
}
예제 #27
0
// Automatically Load all Static DataVaults and *.dv files in the current folder into the DataBank
eEsifError DataBank_LoadDataVaults (DataBankPtr self)
{
	eEsifError rc = ESIF_OK;
	esif_ccb_file_find_handle find_handle;
	esif_string file_path = 0;
	char file_pattern[MAX_PATH];
	char file_path_buf[MAX_PATH] = {0};
	struct esif_ccb_file *ffd_ptr;
	UInt32 idx;

	ASSERT(self);
	esif_ccb_lock_init(&self->lock);

	// TODO: Locking

	// Import all Static DataVaults into ReadOnly DataVaults
	for (idx = 0; g_StaticDataVaults[idx].name; idx++) {
		DataVaultPtr DB = DataBank_OpenNameSpace(self, g_StaticDataVaults[idx].name);
		if (DB) {
			IOStream_SetMemory(DB->stream, g_StaticDataVaults[idx].buffer, g_StaticDataVaults[idx].buf_len);
			DB->flags |= (ESIF_SERVICE_CONFIG_READONLY | ESIF_SERVICE_CONFIG_NOCACHE);
			DataVault_ReadVault(DB);
		}
	}

	// Create ESIFDV_DIR if it doesn't exit (only 1 level deep for now)
	esif_ccb_makepath(ESIFDV_DIR);

	// Import all matching *.dv files into ReadWrite DataVaults
	esif_ccb_strcpy(file_path_buf, ESIFDV_DIR, sizeof(file_path_buf));
	file_path = file_path_buf;
	esif_ccb_sprintf(MAX_PATH, file_pattern, "*%s", ESIFDV_FILEEXT);
	ffd_ptr   = (struct esif_ccb_file*)esif_ccb_malloc(sizeof(*ffd_ptr));
	if (NULL == ffd_ptr) {
		return ESIF_E_NO_MEMORY;
	}

	find_handle = esif_ccb_file_enum_first(file_path, file_pattern, ffd_ptr);
	if (INVALID_HANDLE_VALUE == find_handle) {
		rc = ESIF_OK;	// No Persisted DataVaults found
	} else {
		do {
			struct esif_ccb_file dv_file = {0};
			DataVaultPtr DB = 0;

			// Read DataVault File, unless it's already been loaded as a Static DataVault
			if (esif_ccb_strlen(ffd_ptr->filename, MAX_PATH) > sizeof(ESIFDV_FILEEXT)) {
				ffd_ptr->filename[esif_ccb_strlen(ffd_ptr->filename, MAX_PATH) - (sizeof(ESIFDV_FILEEXT) - 1)] = 0;	// Truncate ".dv" extension
				if (DataBank_GetNameSpace(self, ffd_ptr->filename) == NULL) {
					DB = DataBank_OpenNameSpace(self, ffd_ptr->filename);
					if (DB) {
						esif_ccb_sprintf(MAX_PATH, dv_file.filename, "%s%s%s", file_path, DB->name, ESIFDV_FILEEXT);
						IOStream_SetFile(DB->stream, dv_file.filename, "rb");
						DataVault_ReadVault(DB);
					}
				}
			}
		} while (esif_ccb_file_enum_next(find_handle, file_pattern, ffd_ptr));
		esif_ccb_file_enum_close(find_handle);
	}
	esif_ccb_free(ffd_ptr);
	return rc;
}