• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tee_huk_get_device_id.h"
13 #include "tee_huk_derive_key.h"
14 #include <securec.h>
15 #include <errno.h>
16 #include <tee_log.h>
17 #include "huk_service_msg.h"
18 #include "huk_service_msg_call.h"
19 
get_device_id_prop(uint8_t * dst,uint32_t len)20 TEE_Result get_device_id_prop(uint8_t *dst, uint32_t len)
21 {
22     if (dst == NULL || len != sizeof(TEE_UUID)) {
23         tloge("invalid param\n");
24         return TEE_ERROR_BAD_PARAMETERS;
25     }
26 
27     struct huk_srv_msg msg;
28     struct huk_srv_rsp rsp;
29     (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
30     (void)memset_s(&rsp, sizeof(rsp), 0, sizeof(rsp));
31 
32     uint8_t *dev_id_shared = huk_alloc_shared_mem(len);
33     if (dev_id_shared == NULL) {
34         tloge("malloc device id buff shared failed, size = 0x%x\n", len);
35         return TEE_ERROR_OUT_OF_MEMORY;
36     }
37 
38     msg.data.deviceid_msg.buf = (uintptr_t)dev_id_shared;
39     msg.data.deviceid_msg.size = len;
40     msg.header.send.msg_id = CMD_HUK_GET_DEVICEID;
41 
42     if (huk_srv_msg_call(&msg, &rsp) < 0)
43         goto clean;
44 
45     if (rsp.data.ret == TEE_SUCCESS) {
46         if (memcpy_s(dst, len, dev_id_shared, len) != EOK) {
47             tloge("copy device id shared failed\n");
48             rsp.data.ret = TEE_ERROR_GENERIC;
49         }
50     }
51 clean:
52     huk_free_shared_mem(dev_id_shared, len);
53     return rsp.data.ret;
54 }
55