1 /* SPDX-License-Identifier: GPL-2.0
2 * Definitions for kernel modules using Dell WMI System Management Driver
4 * Copyright (c) 2020 Dell Inc.
7 #ifndef _DELL_WMI_BIOS_ATTR_H_
8 #define _DELL_WMI_BIOS_ATTR_H_
10 #include <linux/wmi.h>
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/capability.h>
16 #define DRIVER_NAME "dell-wmi-sysman"
19 #define DELL_WMI_BIOS_ENUMERATION_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF5"
20 #define DELL_WMI_BIOS_INTEGER_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BFA"
21 #define DELL_WMI_BIOS_STRING_ATTRIBUTE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF9"
22 #define DELL_WMI_BIOS_PASSOBJ_ATTRIBUTE_GUID "0894B8D6-44A6-4719-97D7-6AD24108BFD4"
23 #define DELL_WMI_BIOS_ATTRIBUTES_INTERFACE_GUID "F1DDEE52-063C-4784-A11E-8A06684B9BF4"
24 #define DELL_WMI_BIOS_PASSWORD_INTERFACE_GUID "70FE8229-D03B-4214-A1C6-1F884B1A892A"
26 struct enumeration_data {
27 struct kobject *attr_name_kobj;
28 char display_name_language_code[MAX_BUFF];
29 char dell_value_modifier[MAX_BUFF];
30 char possible_values[MAX_BUFF];
31 char attribute_name[MAX_BUFF];
32 char default_value[MAX_BUFF];
33 char dell_modifier[MAX_BUFF];
34 char display_name[MAX_BUFF];
38 struct kobject *attr_name_kobj;
39 char display_name_language_code[MAX_BUFF];
40 char attribute_name[MAX_BUFF];
41 char dell_modifier[MAX_BUFF];
42 char display_name[MAX_BUFF];
50 struct kobject *attr_name_kobj;
51 char display_name_language_code[MAX_BUFF];
52 char attribute_name[MAX_BUFF];
53 char display_name[MAX_BUFF];
54 char default_value[MAX_BUFF];
55 char dell_modifier[MAX_BUFF];
61 struct kobject *attr_name_kobj;
62 char attribute_name[MAX_BUFF];
63 int min_password_length;
64 int max_password_length;
67 struct wmi_sysman_priv {
68 char current_admin_password[MAX_BUFF];
69 char current_system_password[MAX_BUFF];
70 struct wmi_device *password_attr_wdev;
71 struct wmi_device *bios_attr_wdev;
72 struct kset *authentication_dir_kset;
73 struct kset *main_dir_kset;
74 struct device *class_dev;
75 struct enumeration_data *enumeration_data;
76 int enumeration_instances_count;
77 struct integer_data *integer_data;
78 int integer_instances_count;
79 struct str_data *str_data;
80 int str_instances_count;
81 struct po_data *po_data;
82 int po_instances_count;
87 /* global structure used by multiple WMI interfaces */
88 extern struct wmi_sysman_priv wmi_priv;
90 enum { ENUM, INT, STR, PO };
101 #define get_instance_id(type) \
102 static int get_##type##_instance_id(struct kobject *kobj) \
105 for (i = 0; i <= wmi_priv.type##_instances_count; i++) { \
106 if (!(strcmp(kobj->name, wmi_priv.type##_data[i].attribute_name)))\
112 #define attribute_s_property_show(name, type) \
113 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
116 int i = get_##type##_instance_id(kobj); \
118 return sprintf(buf, "%s\n", wmi_priv.type##_data[i].name); \
122 #define attribute_n_property_show(name, type) \
123 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
126 int i = get_##type##_instance_id(kobj); \
128 return sprintf(buf, "%d\n", wmi_priv.type##_data[i].name); \
132 #define attribute_property_store(curr_val, type) \
133 static ssize_t curr_val##_store(struct kobject *kobj, \
134 struct kobj_attribute *attr, \
135 const char *buf, size_t count) \
139 buf_cp = kstrdup(buf, GFP_KERNEL); \
142 p = memchr(buf_cp, '\n', count); \
146 i = get_##type##_instance_id(kobj); \
148 ret = validate_##type##_input(i, buf_cp); \
150 ret = set_attribute(kobj->name, buf_cp); \
152 return ret ? ret : count; \
155 #define check_property_type(attr, prop, valuetype) \
156 (attr##_obj[prop].type != valuetype)
158 union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string);
159 int get_instance_count(const char *guid_string);
160 void strlcpy_attr(char *dest, char *src);
162 int populate_enum_data(union acpi_object *enumeration_obj, int instance_id,
163 struct kobject *attr_name_kobj, u32 enum_property_count);
164 int alloc_enum_data(void);
165 void exit_enum_attributes(void);
167 int populate_int_data(union acpi_object *integer_obj, int instance_id,
168 struct kobject *attr_name_kobj);
169 int alloc_int_data(void);
170 void exit_int_attributes(void);
172 int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobject *attr_name_kobj);
173 int alloc_str_data(void);
174 void exit_str_attributes(void);
176 int populate_po_data(union acpi_object *po_obj, int instance_id, struct kobject *attr_name_kobj);
177 int alloc_po_data(void);
178 void exit_po_attributes(void);
180 int set_attribute(const char *a_name, const char *a_value);
181 int set_bios_defaults(u8 defType);
183 void exit_bios_attr_set_interface(void);
184 int init_bios_attr_set_interface(void);
185 int map_wmi_error(int error_code);
186 size_t calculate_string_buffer(const char *str);
187 size_t calculate_security_buffer(char *authentication);
188 void populate_security_buffer(char *buffer, char *authentication);
189 ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str);
190 int set_new_password(const char *password_type, const char *new);
191 int init_bios_attr_pass_interface(void);
192 void exit_bios_attr_pass_interface(void);