1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef DYN_CONF_MGR_DYN_CONF_DISPATCH_INF_H 13 #define DYN_CONF_MGR_DYN_CONF_DISPATCH_INF_H 14 15 #include <stdint.h> 16 #include <dlist.h> 17 #include <tee_defines.h> 18 19 #define MAX_IMAGE_LEN 0x800000 20 /* tag(DYN_CONF_TAG_LEN) | type(DYN_CONF_TYPE_LEN) | len(DYN_CONF_LEN_LEN) | value */ 21 #define DYN_CONF_TAG_LEN 3 22 #define DYN_CONF_TYPE_LEN 1 23 #define DYN_CONF_LEN_LEN 4 24 #define DYN_CONF_TAG_MAX 0xffffffff 25 #define DYN_CONF_TYPE_MAX 0xffffffff 26 /* dyn conf must start with gpd.ta.dynConf */ 27 #define DYN_CONF_START "gpd.ta.dynConf" 28 /* the types dyn conf support */ 29 #define TYPE_CLASS 0 30 #define TYPE_BOOL 1 31 #define TYPE_INT 2 32 #define TYPE_CHAR 3 33 /* use to parse str special sym */ 34 #define LEN_OF_HEX_TRIM 2 /* the length of 0x */ 35 #define BIT_NUM_OF_UINT64 64 36 #define BASE_OF_TEN 10 37 #define BASE_OF_HEX 16 38 #define MAX_UINT64_LEN 20 /* the max length of an uint64 num str */ 39 #define MAX_UINT32_LEN 10 /* the max length of an uint32 num str */ 40 41 #define MAX_UINT64_HEX_LEN 16 /* the max length of an uint64 hex num str */ 42 43 #define THREAD_LIMIT_MAX 8 44 #define DRV_CMD_MAX 0xffffffff 45 #define IRQ_MIN 32 46 47 #define MAX_UUID_SIZE 36 48 49 #define UUID_TIMELOW_LEN 8 50 #define UUID_TIMEMID_LEN 4 51 #define UUID_HIVERSION_LEN 4 52 #define UUID_SEQ_LEN 2 53 54 #define UUID_STRUCT_LEN 11 55 #define TIMELOW_MAX 0xFFFFFFFF 56 #define TIMEMID_MAX 0xFFFF 57 #define TIMESEQ_MAX 0xFF 58 #define UUID_SEQ_SIZE 8 59 #define TLV_TRUE '1' 60 61 enum dyn_conf_exception_modes { 62 DYN_CONF_SYSCRASH_TAG = 0, 63 DYN_CONF_RESTART_TAG, 64 DYN_CONF_DDOS_TAG, 65 }; 66 67 enum dyn_conf_data_nums { 68 DATA_TIMELOW_IDX = 0, 69 DATA_TIMEMID_IDX, 70 DATA_HVER_IDX, 71 }; 72 73 /* the struct we use in queue */ 74 struct conf_node_t { 75 struct dlist_node head; 76 uint32_t tag; 77 uint32_t type; 78 uint32_t size; 79 const char *value; 80 }; 81 82 struct conf_queue_t { 83 struct dlist_node queue; 84 }; 85 86 /* load the dyn conf from mani_ext section in sec file */ 87 struct dyn_conf_t { 88 uint32_t dyn_conf_size; 89 char *dyn_conf_buffer; 90 }; 91 92 typedef int32_t (*handler_conf_to_obj)(struct dlist_node **, const struct conf_node_t *, void *, uint32_t); 93 typedef int32_t (*handler_install_obj)(void *, uint32_t, const struct conf_queue_t *); 94 typedef void (*handler_uninstall_obj)(const void *, uint32_t); 95 typedef int32_t (*handler_check_obj)(const void *); 96 97 int32_t register_conf(const struct dyn_conf_t *dyn_conf, handler_install_obj handle, void *obj, uint32_t obj_size); 98 void unregister_conf(handler_uninstall_obj uninstall_obj_func, void *obj, uint32_t obj_size); 99 uint16_t get_num_of_tag(const struct conf_queue_t *conf_queue, uint32_t tag); 100 int32_t handle_conf_node_to_obj(struct dlist_node **pos, handler_conf_to_obj handle, void *obj, uint32_t obj_size); 101 int32_t trans_str_to_int(const char *buff, uint32_t len, uint32_t base, uint64_t *num); 102 int32_t check_item_chip_type(const struct dlist_node *now, uint32_t chip_type_tag); 103 int32_t tlv_to_uuid(const char *uuid_buff, uint32_t size, struct tee_uuid *uuid); 104 105 struct dyn_conf_build_func { 106 uint32_t tag; 107 handler_conf_to_obj handle; 108 handler_check_obj checker; 109 }; 110 #endif 111