1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2017, Linaro Limited 4 */ 5 6 #include <tee/tadb.h> 7 #include <kernel/ts_store.h> 8 #include <kernel/user_ta.h> 9 #include <initcall.h> 10 11 static TEE_Result secstor_ta_open(const TEE_UUID *uuid, 12 struct ts_store_handle **handle) 13 { 14 TEE_Result res; 15 struct tee_tadb_ta_read *ta; 16 size_t l; 17 const struct tee_tadb_property *prop; 18 19 res = tee_tadb_ta_open(uuid, &ta); 20 if (res) 21 return res; 22 prop = tee_tadb_ta_get_property(ta); 23 24 l = prop->custom_size; 25 res = tee_tadb_ta_read(ta, NULL, NULL, &l); 26 if (res) 27 goto err; 28 if (l != prop->custom_size) { 29 res = TEE_ERROR_CORRUPT_OBJECT; 30 goto err; 31 } 32 33 *handle = (struct ts_store_handle *)ta; 34 35 return TEE_SUCCESS; 36 err: 37 tee_tadb_ta_close(ta); 38 return res; 39 } 40 41 static TEE_Result secstor_ta_get_size(const struct ts_store_handle *h, 42 size_t *size) 43 { 44 struct tee_tadb_ta_read *ta = (struct tee_tadb_ta_read *)h; 45 const struct tee_tadb_property *prop = tee_tadb_ta_get_property(ta); 46 47 *size = prop->bin_size; 48 49 return TEE_SUCCESS; 50 } 51 52 static TEE_Result secstor_ta_get_tag(const struct ts_store_handle *h, 53 uint8_t *tag, unsigned int *tag_len) 54 { 55 return tee_tadb_get_tag((struct tee_tadb_ta_read *)h, tag, tag_len); 56 } 57 58 static TEE_Result secstor_ta_read(struct ts_store_handle *h, void *data_core, 59 void *data_user, size_t len) 60 { 61 struct tee_tadb_ta_read *ta = (struct tee_tadb_ta_read *)h; 62 size_t l = len; 63 TEE_Result res = tee_tadb_ta_read(ta, data_core, data_user, &l); 64 65 if (res) 66 return res; 67 if (l != len) 68 return TEE_ERROR_BAD_PARAMETERS; 69 70 return TEE_SUCCESS; 71 } 72 73 static void secstor_ta_close(struct ts_store_handle *h) 74 { 75 struct tee_tadb_ta_read *ta = (struct tee_tadb_ta_read *)h; 76 77 tee_tadb_ta_close(ta); 78 } 79 80 REGISTER_TA_STORE(4) = { 81 .description = "Secure Storage TA", 82 .open = secstor_ta_open, 83 .get_size = secstor_ta_get_size, 84 .get_tag = secstor_ta_get_tag, 85 .read = secstor_ta_read, 86 .close = secstor_ta_close, 87 }; 88