• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Decription: check compatibility between tzdriver and tee.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  */
14 
15 #include "tee_compat_check.h"
16 #include <linux/types.h>
17 #include <linux/err.h>
18 #include "teek_ns_client.h"
19 #include "tc_ns_log.h"
20 
check_teeos_compat_level(const uint32_t * buffer,uint32_t size)21 int32_t check_teeos_compat_level(const uint32_t *buffer, uint32_t size)
22 {
23 	const uint16_t major = TEEOS_COMPAT_LEVEL_MAJOR;
24 	const uint16_t minor = TEEOS_COMPAT_LEVEL_MINOR;
25 
26 	if (!buffer || size != COMPAT_LEVEL_BUF_LEN) {
27 		tloge("check teeos compat level failed, invalid param\n");
28 		return -EINVAL;
29 	}
30 
31 	if (buffer[0] != VER_CHECK_MAGIC_NUM) {
32 		tloge("check ver magic num %u failed\n", buffer[0]);
33 		return -EPERM;
34 	}
35 	if (buffer[1] != major) {
36 		tloge("check major ver failed, tzdriver expect teeos version=%u, actual teeos version=%u\n",
37 			major, buffer[1]);
38 		return -EPERM;
39 	}
40 	/* just print warning */
41 	if (buffer[2] != minor)
42 		tlogw("check minor ver failed, tzdriver expect teeos minor version=%u, actual minor teeos version=%u\n",
43 			minor, buffer[2]);
44 
45 	return 0;
46 }