Debian Codegraph @

drivers/platform/x86/hp/hp-bioscfg/bioscfg.h

raw
1 /* SPDX-License-Identifier: GPL-2.0
2 *
3 * Definitions for kernel modules using hp_bioscfg driver
4 *
5 * Copyright (c) 2022 HP Development Company, L.P.
6 */
7
8 #ifndef _HP_BIOSCFG_H_
9 #define _HP_BIOSCFG_H_
10
11 #include <linux/wmi.h>
12 #include <linux/types.h>
13 #include <linux/string.h>
14 #include <linux/device.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/nls.h>
18
19 #define DRIVER_NAME "hp-bioscfg"
20
21 #define MAX_BUFF_SIZE 512
22 #define MAX_KEY_MOD_SIZE 256
23 #define MAX_PASSWD_SIZE 64
24 #define MAX_PREREQUISITES_SIZE 20
25 #define MAX_REQ_ELEM_SIZE 128
26 #define MAX_VALUES_SIZE 16
27 #define MAX_ENCODINGS_SIZE 16
28 #define MAX_ELEMENTS_SIZE 16
29
30 #define SPM_STR_DESC "Secure Platform Management"
31 #define SPM_STR "SPM"
32 #define SURE_START_DESC "Sure Start"
33 #define SURE_START_STR "Sure_Start"
34 #define SETUP_PASSWD "Setup Password"
35 #define POWER_ON_PASSWD "Power-On Password"
36
37 #define LANG_CODE_STR "en_US.UTF-8"
38 #define SCHEDULE_POWER_ON "Scheduled Power-On"
39
40 #define COMMA_SEP ","
41 #define SEMICOLON_SEP ";"
42
43 /* Sure Admin Functions */
44
45 #define UTF_PREFIX "<utf-16/>"
46 #define BEAM_PREFIX "<BEAM/>"
47
48 enum mechanism_values {
49 PASSWORD = 0x00,
50 SIGNING_KEY = 0x01,
51 ENDORSEMENT_KEY = 0x02,
52 };
53
54 #define BIOS_ADMIN "bios-admin"
55 #define POWER_ON "power-on"
56 #define BIOS_SPM "enhanced-bios-auth"
57
58 #define PASSWD_MECHANISM_TYPES "password"
59
60 #define HP_WMI_BIOS_GUID "5FB7F034-2C63-45E9-BE91-3D44E2C707E4"
61
62 #define HP_WMI_BIOS_STRING_GUID "988D08E3-68F4-4C35-AF3E-6A1B8106F83C"
63 #define HP_WMI_BIOS_INTEGER_GUID "8232DE3D-663D-4327-A8F4-E293ADB9BF05"
64 #define HP_WMI_BIOS_ENUMERATION_GUID "2D114B49-2DFB-4130-B8FE-4A3C09E75133"
65 #define HP_WMI_BIOS_ORDERED_LIST_GUID "14EA9746-CE1F-4098-A0E0-7045CB4DA745"
66 #define HP_WMI_BIOS_PASSWORD_GUID "322F2028-0F84-4901-988E-015176049E2D"
67 #define HP_WMI_SET_BIOS_SETTING_GUID "1F4C91EB-DC5C-460B-951D-C7CB9B4B8D5E"
68
69 enum hp_wmi_spm_commandtype {
70 HPWMI_SECUREPLATFORM_GET_STATE = 0x10,
71 HPWMI_SECUREPLATFORM_SET_KEK = 0x11,
72 HPWMI_SECUREPLATFORM_SET_SK = 0x12,
73 };
74
75 enum hp_wmi_surestart_commandtype {
76 HPWMI_SURESTART_GET_LOG_COUNT = 0x01,
77 HPWMI_SURESTART_GET_LOG = 0x02,
78 };
79
80 enum hp_wmi_command {
81 HPWMI_READ = 0x01,
82 HPWMI_WRITE = 0x02,
83 HPWMI_ODM = 0x03,
84 HPWMI_SURESTART = 0x20006,
85 HPWMI_GM = 0x20008,
86 HPWMI_SECUREPLATFORM = 0x20010,
87 };
88
89 struct bios_return {
90 u32 sigpass;
91 u32 return_code;
92 };
93
94 enum wmi_error_values {
95 SUCCESS = 0x00,
96 CMD_FAILED = 0x01,
97 INVALID_SIGN = 0x02,
98 INVALID_CMD_VALUE = 0x03,
99 INVALID_CMD_TYPE = 0x04,
100 INVALID_DATA_SIZE = 0x05,
101 INVALID_CMD_PARAM = 0x06,
102 ENCRYP_CMD_REQUIRED = 0x07,
103 NO_SECURE_SESSION = 0x08,
104 SECURE_SESSION_FOUND = 0x09,
105 SECURE_SESSION_FAILED = 0x0A,
106 AUTH_FAILED = 0x0B,
107 INVALID_BIOS_AUTH = 0x0E,
108 NONCE_DID_NOT_MATCH = 0x18,
109 GENERIC_ERROR = 0x1C,
110 BIOS_ADMIN_POLICY_NOT_MET = 0x28,
111 BIOS_ADMIN_NOT_SET = 0x38,
112 P21_NO_PROVISIONED = 0x1000,
113 P21_PROVISION_IN_PROGRESS = 0x1001,
114 P21_IN_USE = 0x1002,
115 HEP_NOT_ACTIVE = 0x1004,
116 HEP_ALREADY_SET = 0x1006,
117 HEP_CHECK_STATE = 0x1007,
118 };
119
120 struct common_data {
121 u8 display_name[MAX_BUFF_SIZE];
122 u8 path[MAX_BUFF_SIZE];
123 u32 is_readonly;
124 u32 display_in_ui;
125 u32 requires_physical_presence;
126 u32 sequence;
127 u32 prerequisites_size;
128 u8 prerequisites[MAX_PREREQUISITES_SIZE][MAX_BUFF_SIZE];
129 u32 security_level;
130 };
131
132 struct string_data {
133 struct common_data common;
134 struct kobject *attr_name_kobj;
135 u8 current_value[MAX_BUFF_SIZE];
136 u8 new_value[MAX_BUFF_SIZE];
137 u32 min_length;
138 u32 max_length;
139 };
140
141 struct integer_data {
142 struct common_data common;
143 struct kobject *attr_name_kobj;
144 u32 current_value;
145 u32 new_value;
146 u32 lower_bound;
147 u32 upper_bound;
148 u32 scalar_increment;
149 };
150
151 struct enumeration_data {
152 struct common_data common;
153 struct kobject *attr_name_kobj;
154 u8 current_value[MAX_BUFF_SIZE];
155 u8 new_value[MAX_BUFF_SIZE];
156 u32 possible_values_size;
157 u8 possible_values[MAX_VALUES_SIZE][MAX_BUFF_SIZE];
158 };
159
160 struct ordered_list_data {
161 struct common_data common;
162 struct kobject *attr_name_kobj;
163 u8 current_value[MAX_BUFF_SIZE];
164 u8 new_value[MAX_BUFF_SIZE];
165 u32 elements_size;
166 u8 elements[MAX_ELEMENTS_SIZE][MAX_BUFF_SIZE];
167 };
168
169 struct password_data {
170 struct common_data common;
171 struct kobject *attr_name_kobj;
172 u8 current_password[MAX_PASSWD_SIZE];
173 u8 new_password[MAX_PASSWD_SIZE];
174 u32 min_password_length;
175 u32 max_password_length;
176 u32 encodings_size;
177 u8 encodings[MAX_ENCODINGS_SIZE][MAX_BUFF_SIZE];
178 bool is_enabled;
179
180 /*
181 * 'role' identifies the type of authentication.
182 * Two known types are bios-admin and power-on.
183 * 'bios-admin' represents BIOS administrator password
184 * 'power-on' represents a password required to use the system
185 */
186 u32 role;
187
188 /*
189 * 'mechanism' represents the means of authentication.
190 * Only supported type currently is "password"
191 */
192 u32 mechanism;
193 };
194
195 struct secure_platform_data {
196 struct kobject *attr_name_kobj;
197 u8 attribute_name[MAX_BUFF_SIZE];
198 u8 *endorsement_key;
199 u8 *signing_key;
200 u8 *auth_token;
201 bool is_enabled;
202 u32 mechanism;
203 };
204
205 struct bioscfg_priv {
206 struct kset *authentication_dir_kset;
207 struct kset *main_dir_kset;
208 struct device *class_dev;
209 struct string_data *string_data;
210 u32 string_instances_count;
211 struct integer_data *integer_data;
212 u32 integer_instances_count;
213 struct enumeration_data *enumeration_data;
214 u32 enumeration_instances_count;
215 struct ordered_list_data *ordered_list_data;
216 u32 ordered_list_instances_count;
217 struct password_data *password_data;
218 u32 password_instances_count;
219
220 struct kobject *sure_start_attr_kobj;
221 struct secure_platform_data spm_data;
222 u8 display_name_language_code[MAX_BUFF_SIZE];
223 bool pending_reboot;
224 struct mutex mutex;
225 };
226
227 /* global structure used by multiple WMI interfaces */
228 extern struct bioscfg_priv bioscfg_drv;
229
230 enum hp_wmi_data_type {
231 HPWMI_STRING_TYPE,
232 HPWMI_INTEGER_TYPE,
233 HPWMI_ENUMERATION_TYPE,
234 HPWMI_ORDERED_LIST_TYPE,
235 HPWMI_PASSWORD_TYPE,
236 HPWMI_SECURE_PLATFORM_TYPE,
237 HPWMI_SURE_START_TYPE,
238 };
239
240 enum hp_wmi_data_elements {
241 /* Common elements */
242 NAME = 0,
243 VALUE = 1,
244 PATH = 2,
245 IS_READONLY = 3,
246 DISPLAY_IN_UI = 4,
247 REQUIRES_PHYSICAL_PRESENCE = 5,
248 SEQUENCE = 6,
249 PREREQUISITES_SIZE = 7,
250 PREREQUISITES = 8,
251 SECURITY_LEVEL = 9,
252
253 /* String elements */
254 STR_MIN_LENGTH = 10,
255 STR_MAX_LENGTH = 11,
256 STR_ELEM_CNT = 12,
257
258 /* Integer elements */
259 INT_LOWER_BOUND = 10,
260 INT_UPPER_BOUND = 11,
261 INT_SCALAR_INCREMENT = 12,
262 INT_ELEM_CNT = 13,
263
264 /* Enumeration elements */
265 ENUM_CURRENT_VALUE = 10,
266 ENUM_SIZE = 11,
267 ENUM_POSSIBLE_VALUES = 12,
268 ENUM_ELEM_CNT = 13,
269
270 /* Ordered list elements */
271 ORD_LIST_SIZE = 10,
272 ORD_LIST_ELEMENTS = 11,
273 ORD_ELEM_CNT = 12,
274
275 /* Password elements */
276 PSWD_MIN_LENGTH = 10,
277 PSWD_MAX_LENGTH = 11,
278 PSWD_SIZE = 12,
279 PSWD_ENCODINGS = 13,
280 PSWD_IS_SET = 14,
281 PSWD_ELEM_CNT = 15,
282 };
283
284 #define GET_INSTANCE_ID(type) \
285 static int get_##type##_instance_id(struct kobject *kobj) \
286 { \
287 int i; \
288 \
289 for (i = 0; i < bioscfg_drv.type##_instances_count; i++) { \
290 if (bioscfg_drv.type##_data[i].attr_name_kobj && \
291 !strcmp(kobj->name, bioscfg_drv.type##_data[i].attr_name_kobj->name)) \
292 return i; \
293 } \
294 return -EIO; \
295 }
296
297 #define ATTRIBUTE_S_PROPERTY_SHOW(name, type) \
298 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
299 char *buf) \
300 { \
301 int i = get_##type##_instance_id(kobj); \
302 if (i >= 0) \
303 return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].name); \
304 return -EIO; \
305 }
306
307 #define ATTRIBUTE_N_PROPERTY_SHOW(name, type) \
308 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
309 char *buf) \
310 { \
311 int i = get_##type##_instance_id(kobj); \
312 if (i >= 0) \
313 return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data[i].name); \
314 return -EIO; \
315 }
316
317 #define ATTRIBUTE_PROPERTY_STORE(curr_val, type) \
318 static ssize_t curr_val##_store(struct kobject *kobj, \
319 struct kobj_attribute *attr, \
320 const char *buf, size_t count) \
321 { \
322 char *attr_value = NULL; \
323 int i; \
324 int ret = -EIO; \
325 \
326 attr_value = kstrdup(buf, GFP_KERNEL); \
327 if (!attr_value) \
328 return -ENOMEM; \
329 \
330 ret = hp_enforce_single_line_input(attr_value, count); \
331 if (!ret) { \
332 i = get_##type##_instance_id(kobj); \
333 if (i >= 0) \
334 ret = validate_##type##_input(i, attr_value); \
335 } \
336 if (!ret) \
337 ret = hp_set_attribute(kobj->name, attr_value); \
338 if (!ret) { \
339 update_##type##_value(i, attr_value); \
340 if (bioscfg_drv.type##_data[i].common.requires_physical_presence) \
341 hp_set_reboot_and_signal_event(); \
342 } \
343 hp_clear_all_credentials(); \
344 kfree(attr_value); \
345 \
346 return ret ? ret : count; \
347 }
348
349 #define ATTRIBUTE_SPM_N_PROPERTY_SHOW(name, type) \
350 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
351 { \
352 return sysfs_emit(buf, "%d\n", bioscfg_drv.type##_data.name); \
353 }
354
355 #define ATTRIBUTE_SPM_S_PROPERTY_SHOW(name, type) \
356 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) \
357 { \
358 return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data.name); \
359 }
360
361 #define ATTRIBUTE_VALUES_PROPERTY_SHOW(name, type, sep) \
362 static ssize_t name##_show(struct kobject *kobj, \
363 struct kobj_attribute *attr, char *buf) \
364 { \
365 int i; \
366 int len = 0; \
367 int instance_id = get_##type##_instance_id(kobj); \
368 \
369 if (instance_id < 0) \
370 return 0; \
371 \
372 for (i = 0; i < bioscfg_drv.type##_data[instance_id].name##_size; i++) { \
373 if (i) \
374 len += sysfs_emit_at(buf, len, "%s", sep); \
375 \
376 len += sysfs_emit_at(buf, len, "%s", \
377 bioscfg_drv.type##_data[instance_id].name[i]); \
378 } \
379 len += sysfs_emit_at(buf, len, "\n"); \
380 return len; \
381 }
382
383 #define ATTRIBUTE_S_COMMON_PROPERTY_SHOW(name, type) \
384 static ssize_t name##_show(struct kobject *kobj, struct kobj_attribute *attr, \
385 char *buf) \
386 { \
387 int i = get_##type##_instance_id(kobj); \
388 if (i >= 0) \
389 return sysfs_emit(buf, "%s\n", bioscfg_drv.type##_data[i].common.name); \
390 return -EIO; \
391 }
392
393 extern struct kobj_attribute common_display_langcode;
394
395 /* Prototypes */
396
397 /* String attributes */
398 int hp_populate_string_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
399 int instance_id,
400 struct kobject *attr_name_kobj);
401 int hp_alloc_string_data(void);
402 void hp_exit_string_attributes(void);
403 int hp_populate_string_package_data(union acpi_object *str_obj,
404 int instance_id,
405 struct kobject *attr_name_kobj);
406
407 /* Integer attributes */
408 int hp_populate_integer_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
409 int instance_id,
410 struct kobject *attr_name_kobj);
411 int hp_alloc_integer_data(void);
412 void hp_exit_integer_attributes(void);
413 int hp_populate_integer_package_data(union acpi_object *integer_obj,
414 int instance_id,
415 struct kobject *attr_name_kobj);
416
417 /* Enumeration attributes */
418 int hp_populate_enumeration_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
419 int instance_id,
420 struct kobject *attr_name_kobj);
421 int hp_alloc_enumeration_data(void);
422 void hp_exit_enumeration_attributes(void);
423 int hp_populate_enumeration_package_data(union acpi_object *enum_obj,
424 int instance_id,
425 struct kobject *attr_name_kobj);
426
427 /* Ordered list */
428 int hp_populate_ordered_list_buffer_data(u8 *buffer_ptr,
429 u32 *buffer_size,
430 int instance_id,
431 struct kobject *attr_name_kobj);
432 int hp_alloc_ordered_list_data(void);
433 void hp_exit_ordered_list_attributes(void);
434 int hp_populate_ordered_list_package_data(union acpi_object *order_obj,
435 int instance_id,
436 struct kobject *attr_name_kobj);
437
438 /* Password authentication attributes */
439 int hp_populate_password_buffer_data(u8 *buffer_ptr, u32 *buffer_size,
440 int instance_id,
441 struct kobject *attr_name_kobj);
442 int hp_populate_password_package_data(union acpi_object *password_obj,
443 int instance_id,
444 struct kobject *attr_name_kobj);
445 int hp_alloc_password_data(void);
446 int hp_get_password_instance_for_type(const char *name);
447 int hp_clear_all_credentials(void);
448 int hp_set_attribute(const char *a_name, const char *a_value);
449
450 /* SPM attributes */
451 void hp_exit_password_attributes(void);
452 void hp_exit_secure_platform_attributes(void);
453 int hp_populate_secure_platform_data(struct kobject *attr_name_kobj);
454 int hp_populate_security_buffer(u16 *buffer, const char *authentication);
455
456 /* Bios Attributes interface */
457 int hp_wmi_set_bios_setting(u16 *input_buffer, u32 input_size);
458 int hp_wmi_perform_query(int query, enum hp_wmi_command command,
459 void *buffer, u32 insize, u32 outsize);
460
461 /* Sure Start attributes */
462 void hp_exit_sure_start_attributes(void);
463 int hp_populate_sure_start_data(struct kobject *attr_name_kobj);
464
465 /* Bioscfg */
466
467 void hp_exit_attr_set_interface(void);
468 int hp_init_attr_set_interface(void);
469 size_t hp_calculate_string_buffer(const char *str);
470 size_t hp_calculate_security_buffer(const char *authentication);
471 void *hp_ascii_to_utf16_unicode(u16 *p, const u8 *str);
472 int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer);
473 int hp_get_string_from_buffer(u8 **buffer, u32 *buffer_size, char *dst, u32 dst_size);
474 int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *len);
475 int hp_encode_outsize_for_pvsz(int outsize);
476 int hp_enforce_single_line_input(char *buf, size_t count);
477 void hp_set_reboot_and_signal_event(void);
478 ssize_t display_name_language_code_show(struct kobject *kobj,
479 struct kobj_attribute *attr,
480 char *buf);
481 union acpi_object *hp_get_wmiobj_pointer(int instance_id, const char *guid_string);
482 int hp_get_instance_count(const char *guid_string);
483 void hp_update_attribute_permissions(bool isreadonly, struct kobj_attribute *current_val);
484 void hp_friendly_user_name_update(char *path, const char *attr_name,
485 char *attr_display, int attr_size);
486 int hp_wmi_error_and_message(int error_code);
487 int hp_get_common_data_from_buffer(u8 **buffer_ptr, u32 *buffer_size, struct common_data *common);
488
489 #endif