if ((ret * sizeof(u16)) > U16_MAX) {
dev_err(wmi_priv.class_dev, "Error string too long\n"); return -ERANGE;
}
*length = ret * sizeof(u16); returnsizeof(u16) + *length;
}
/** * calculate_string_buffer() - determines size of string buffer for use with BIOS communication * @str: the string to calculate based upon *
*/
size_t calculate_string_buffer(constchar *str)
{ /* u16 length field + one UTF16 char for each input char */ returnsizeof(u16) + strlen(str) * sizeof(u16);
}
/** * calculate_security_buffer() - determines size of security buffer for authentication scheme * @authentication: the authentication content * * Currently only supported type is Admin password
*/
size_t calculate_security_buffer(char *authentication)
{ if (strlen(authentication) > 0) { return (sizeof(u32) * 2) + strlen(authentication) +
strlen(authentication) % 2;
} returnsizeof(u32) * 2;
}
/** * populate_security_buffer() - builds a security buffer for authentication scheme * @buffer: the buffer to populate * @authentication: the authentication content * * Currently only supported type is PLAIN TEXT
*/ void populate_security_buffer(char *buffer, char *authentication)
{ char *auth = buffer + sizeof(u32) * 2;
u32 *sectype = (u32 *) buffer;
u32 *seclen = sectype + 1;
/* plain text */ if (strlen(authentication) > 0)
memcpy(auth, authentication, *seclen);
}
/** * map_wmi_error() - map errors from WMI methods to kernel error codes * @error_code: integer error code returned from Dell's firmware
*/ int map_wmi_error(int error_code)
{ switch (error_code) { case 0: /* success */ return 0; case 1: /* failed */ return -EIO; case 2: /* invalid parameter */ return -EINVAL; case 3: /* access denied */ return -EACCES; case 4: /* not supported */ return -EOPNOTSUPP; case 5: /* memory error */ return -ENOMEM; case 6: /* protocol error */ return -EPROTO;
} /* unspecified error */ return -EIO;
}
/** * reset_bios_show() - sysfs implementaton for read reset_bios * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer to display to userspace
*/ static ssize_t reset_bios_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{ char *start = buf; int i;
for (i = 0; i < MAX_TYPES; i++) { if (i == reset_option)
buf += sprintf(buf, "[%s] ", reset_types[i]); else
buf += sprintf(buf, "%s ", reset_types[i]);
}
buf += sprintf(buf, "\n"); return buf-start;
}
/** * reset_bios_store() - sysfs implementaton for write reset_bios * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer from userspace * @count: the size of the buffer from userspace
*/ static ssize_t reset_bios_store(struct kobject *kobj, struct kobj_attribute *attr, constchar *buf, size_t count)
{ int type = sysfs_match_string(reset_types, buf); int ret;
if (type < 0) return type;
ret = set_bios_defaults(type);
pr_debug("reset all attributes request type %d: %d\n", type, ret); if (!ret) {
reset_option = type;
ret = count;
}
return ret;
}
/** * pending_reboot_show() - sysfs implementaton for read pending_reboot * @kobj: Kernel object for this attribute * @attr: Kernel object attribute * @buf: The buffer to display to userspace * * Stores default value as 0 * When current_value is changed this attribute is set to 1 to notify reboot may be required
*/ static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
{ return sprintf(buf, "%d\n", wmi_priv.pending_changes);
}
/** * strlcpy_attr - Copy a length-limited, NULL-terminated string with bound checks * @dest: Where to copy the string to * @src: Where to copy the string from
*/ void strlcpy_attr(char *dest, char *src)
{
size_t len = strlen(src) + 1;
if (len > 1 && len <= MAX_BUFF)
strscpy(dest, src, len);
/*len can be zero because any property not-applicable to attribute can * be empty so check only for too long buffers and log error
*/ if (len > MAX_BUFF)
pr_err("Source string returned from BIOS is out of bound!\n");
}
/** * get_wmiobj_pointer() - Get Content of WMI block for particular instance * @instance_id: WMI instance ID * @guid_string: WMI GUID (in str form) * * Fetches the content for WMI block (instance_id) under GUID (guid_string) * Caller must kfree the return
*/ union acpi_object *get_wmiobj_pointer(int instance_id, constchar *guid_string)
{ struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_status status;
status = wmi_query_block(guid_string, instance_id, &out);
/** * get_instance_count() - Compute total number of instances under guid_string * @guid_string: WMI GUID (in string form)
*/ int get_instance_count(constchar *guid_string)
{ int ret;
ret = wmi_instance_count(guid_string); if (ret < 0) return 0;
return ret;
}
/** * alloc_attributes_data() - Allocate attributes data for a particular type * @attr_type: Attribute type to allocate
*/ staticint alloc_attributes_data(int attr_type)
{ int retval = 0;
/** * destroy_attribute_objs() - Free a kset of kobjects * @kset: The kset to destroy * * Fress kobjects created for each attribute_name under attribute type kset
*/ staticvoid destroy_attribute_objs(struct kset *kset)
{ struct kobject *pos, *next;
/** * release_attributes_data() - Clean-up all sysfs directories and files created
*/ staticvoid release_attributes_data(void)
{
mutex_lock(&wmi_priv.mutex);
exit_enum_attributes();
exit_int_attributes();
exit_str_attributes();
exit_po_attributes(); if (wmi_priv.authentication_dir_kset) {
destroy_attribute_objs(wmi_priv.authentication_dir_kset);
kset_unregister(wmi_priv.authentication_dir_kset);
wmi_priv.authentication_dir_kset = NULL;
} if (wmi_priv.main_dir_kset) {
sysfs_remove_file(&wmi_priv.main_dir_kset->kobj, &reset_bios.attr);
sysfs_remove_file(&wmi_priv.main_dir_kset->kobj, &pending_reboot.attr);
destroy_attribute_objs(wmi_priv.main_dir_kset);
kset_unregister(wmi_priv.main_dir_kset);
wmi_priv.main_dir_kset = NULL;
}
mutex_unlock(&wmi_priv.mutex);
}
/** * init_bios_attributes() - Initialize all attributes for a type * @attr_type: The attribute type to initialize * @guid: The WMI GUID associated with this type to initialize * * Initialiaze all 4 types of attributes enumeration, integer, string and password object. * Populates each attrbute typ's respective properties under sysfs files
*/ staticint init_bios_attributes(int attr_type, constchar *guid)
{ struct kobject *attr_name_kobj; //individual attribute names union acpi_object *obj = NULL; union acpi_object *elements; struct kobject *duplicate; struct kset *tmp_set; int min_elements;
/* instance_id needs to be reset for each type GUID * also, instance IDs are unique within GUID but not across
*/ int instance_id = 0; int retval = 0;
retval = alloc_attributes_data(attr_type); if (retval) return retval;
if (obj->package.count < min_elements) {
pr_err("Error: ACPI-package does not have enough elements: %d < %d\n",
obj->package.count, min_elements); goto nextobj;
}
elements = obj->package.elements;
/* sanity checking */ if (elements[ATTR_NAME].type != ACPI_TYPE_STRING) {
pr_debug("incorrect element type\n"); goto nextobj;
} if (strlen(elements[ATTR_NAME].string.pointer) == 0) {
pr_debug("empty attribute found\n"); goto nextobj;
} if (attr_type == PO)
tmp_set = wmi_priv.authentication_dir_kset; else
tmp_set = wmi_priv.main_dir_kset;
duplicate = kset_find_obj(tmp_set, elements[ATTR_NAME].string.pointer); if (duplicate) {
pr_debug("Duplicate attribute name found - %s\n",
elements[ATTR_NAME].string.pointer);
kobject_put(duplicate); goto nextobj;
}
if (!dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL) &&
!dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Alienware", NULL) &&
!dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "www.dell.com", NULL)) {
pr_err("Unable to run on non-Dell system\n"); return -ENODEV;
}
ret = init_bios_attr_set_interface(); if (ret) return ret;
ret = init_bios_attr_pass_interface(); if (ret) goto err_exit_bios_attr_set_interface;
if (!wmi_priv.bios_attr_wdev || !wmi_priv.password_attr_wdev) {
pr_debug("failed to find set or pass interface\n");
ret = -ENODEV; goto err_exit_bios_attr_pass_interface;
}
wmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
NULL, "%s", DRIVER_NAME); if (IS_ERR(wmi_priv.class_dev)) {
ret = PTR_ERR(wmi_priv.class_dev); goto err_exit_bios_attr_pass_interface;
}
wmi_priv.main_dir_kset = kset_create_and_add("attributes", NULL,
&wmi_priv.class_dev->kobj); if (!wmi_priv.main_dir_kset) {
ret = -ENOMEM; goto err_destroy_classdev;
}
wmi_priv.authentication_dir_kset = kset_create_and_add("authentication", NULL,
&wmi_priv.class_dev->kobj); if (!wmi_priv.authentication_dir_kset) {
ret = -ENOMEM; goto err_release_attributes_data;
}
ret = create_attributes_level_sysfs_files(); if (ret) {
pr_debug("could not create reset BIOS attribute\n"); goto err_release_attributes_data;
}
ret = init_bios_attributes(ENUM, DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID); if (ret) {
pr_debug("failed to populate enumeration type attributes\n"); goto err_release_attributes_data;
}
ret = init_bios_attributes(INT, DELL_WMI_BIOS_INTEGER_ATTRIBUTE_GUID); if (ret) {
pr_debug("failed to populate integer type attributes\n"); goto err_release_attributes_data;
}
ret = init_bios_attributes(STR, DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID); if (ret) {
pr_debug("failed to populate string type attributes\n"); goto err_release_attributes_data;
}
ret = init_bios_attributes(PO, DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID); if (ret) {
pr_debug("failed to populate pass object type attributes\n"); goto err_release_attributes_data;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.