| 1 |
/* SPDX-License-Identifier: GPL-2.0 |
| 2 |
* Definitions for kernel modules using Dell WMI System Management Driver |
| 3 |
* |
| 4 |
* Copyright (c) 2020 Dell Inc. |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef _DELL_WMI_BIOS_ATTR_H_ |
| 8 |
#define _DELL_WMI_BIOS_ATTR_H_ |
| 9 |
|
| 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> |
| 15 |
|
| 16 |
#define DRIVER_NAME "dell-wmi-sysman" |
| 17 |
#define MAX_BUFF 512 |
| 18 |
|
| 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" |
| 25 |
|
| 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]; |
| 35 |
}; |
| 36 |
|
| 37 |
struct integer_data { |
| 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]; |
| 43 |
int scalar_increment; |
| 44 |
int default_value; |
| 45 |
int min_value; |
| 46 |
int max_value; |
| 47 |
}; |
| 48 |
|
| 49 |
struct str_data { |
| 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]; |
| 56 |
int min_length; |
| 57 |
int max_length; |
| 58 |
}; |
| 59 |
|
| 60 |
struct po_data { |
| 61 |
struct kobject *attr_name_kobj; |
| 62 |
char attribute_name[MAX_BUFF]; |
| 63 |
int min_password_length; |
| 64 |
int max_password_length; |
| 65 |
}; |
| 66 |
|
| 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; |
| 83 |
bool pending_changes; |
| 84 |
struct mutex mutex; |
| 85 |
}; |
| 86 |
|
| 87 |
/* global structure used by multiple WMI interfaces */ |
| 88 |
extern struct wmi_sysman_priv wmi_priv; |
| 89 |
|
| 90 |
enum { ENUM, INT, STR, PO }; |
| 91 |
|
| 92 |
#define ENUM_MIN_ELEMENTS 8 |
| 93 |
#define INT_MIN_ELEMENTS 9 |
| 94 |
#define STR_MIN_ELEMENTS 8 |
| 95 |
#define PO_MIN_ELEMENTS 4 |
| 96 |
|
| 97 |
enum { |
| 98 |
ATTR_NAME, |
| 99 |
DISPL_NAME_LANG_CODE, |
| 100 |
DISPLAY_NAME, |
| 101 |
DEFAULT_VAL, |
| 102 |
CURRENT_VAL, |
| 103 |
MODIFIER |
| 104 |
}; |
| 105 |
|
| 106 |
#define get_instance_id(type) \ |
| 107 |
static int get_##type##_instance_id(struct kobject *kobj) \ |
| 108 |
{ \ |
| 109 |
int i; \ |
| 110 |
for (i = 0; i <= wmi_priv.type##_instances_count; i++) { \ |
| 111 |
if (!(strcmp(kobj->name, wmi_priv.type##_data[i].attribute_name)))\ |
| 112 |
return i; \ |
| 113 |
} \ |
| 114 |
return -EIO; \ |
| 115 |
} |
| 116 |
|
| 117 |
#define attribute_s_property_show(name, type) \ |
| 118 |
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ |
| 119 |
char *buf) \ |
| 120 |
{ \ |
| 121 |
int i = get_##type##_instance_id(kobj); \ |
| 122 |
if (i >= 0) \ |
| 123 |
return sprintf(buf, "%s\n", wmi_priv.type##_data[i].name); \ |
| 124 |
return 0; \ |
| 125 |
} |
| 126 |
|
| 127 |
#define attribute_n_property_show(name, type) \ |
| 128 |
static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \ |
| 129 |
char *buf) \ |
| 130 |
{ \ |
| 131 |
int i = get_##type##_instance_id(kobj); \ |
| 132 |
if (i >= 0) \ |
| 133 |
return sprintf(buf, "%d\n", wmi_priv.type##_data[i].name); \ |
| 134 |
return 0; \ |
| 135 |
} |
| 136 |
|
| 137 |
#define attribute_property_store(curr_val, type) \ |
| 138 |
static ssize_t curr_val##_store(struct kobject *kobj, \ |
| 139 |
struct kobj_attribute *attr, \ |
| 140 |
const char *buf, size_t count) \ |
| 141 |
{ \ |
| 142 |
char *p, *buf_cp; \ |
| 143 |
int i, ret = -EIO; \ |
| 144 |
buf_cp = kstrdup(buf, GFP_KERNEL); \ |
| 145 |
if (!buf_cp) \ |
| 146 |
return -ENOMEM; \ |
| 147 |
p = memchr(buf_cp, '\n', count); \ |
| 148 |
\ |
| 149 |
if (p != NULL) \ |
| 150 |
*p = '\0'; \ |
| 151 |
i = get_##type##_instance_id(kobj); \ |
| 152 |
if (i >= 0) \ |
| 153 |
ret = validate_##type##_input(i, buf_cp); \ |
| 154 |
if (!ret) \ |
| 155 |
ret = set_attribute(kobj->name, buf_cp); \ |
| 156 |
kfree(buf_cp); \ |
| 157 |
return ret ? ret : count; \ |
| 158 |
} |
| 159 |
|
| 160 |
#define check_property_type(attr, prop, valuetype) \ |
| 161 |
(attr##_obj[prop].type != valuetype) |
| 162 |
|
| 163 |
union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string); |
| 164 |
int get_instance_count(const char *guid_string); |
| 165 |
void strlcpy_attr(char *dest, char *src); |
| 166 |
|
| 167 |
int populate_enum_data(union acpi_object *enumeration_obj, int instance_id, |
| 168 |
struct kobject *attr_name_kobj, u32 enum_property_count); |
| 169 |
int alloc_enum_data(void); |
| 170 |
void exit_enum_attributes(void); |
| 171 |
|
| 172 |
int populate_int_data(union acpi_object *integer_obj, int instance_id, |
| 173 |
struct kobject *attr_name_kobj); |
| 174 |
int alloc_int_data(void); |
| 175 |
void exit_int_attributes(void); |
| 176 |
|
| 177 |
int populate_str_data(union acpi_object *str_obj, int instance_id, struct kobject *attr_name_kobj); |
| 178 |
int alloc_str_data(void); |
| 179 |
void exit_str_attributes(void); |
| 180 |
|
| 181 |
int populate_po_data(union acpi_object *po_obj, int instance_id, struct kobject *attr_name_kobj); |
| 182 |
int alloc_po_data(void); |
| 183 |
void exit_po_attributes(void); |
| 184 |
|
| 185 |
int set_attribute(const char *a_name, const char *a_value); |
| 186 |
int set_bios_defaults(u8 defType); |
| 187 |
|
| 188 |
void exit_bios_attr_set_interface(void); |
| 189 |
int init_bios_attr_set_interface(void); |
| 190 |
int map_wmi_error(int error_code); |
| 191 |
size_t calculate_string_buffer(const char *str); |
| 192 |
size_t calculate_security_buffer(char *authentication); |
| 193 |
void populate_security_buffer(char *buffer, char *authentication); |
| 194 |
ssize_t populate_string_buffer(char *buffer, size_t buffer_len, const char *str); |
| 195 |
int set_new_password(const char *password_type, const char *new); |
| 196 |
int init_bios_attr_pass_interface(void); |
| 197 |
void exit_bios_attr_pass_interface(void); |
| 198 |
|
| 199 |
#endif |