You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
287 lines
8.7 KiB
287 lines
8.7 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
* Description: Test the file of the hard only interface.
|
|
* Author: Hisilicon
|
|
* Create: 2019-09-24
|
|
*/
|
|
#include "sample_otp_base.h"
|
|
|
|
static td_s32 get_hard_only_stat(td_s32 argc, td_char *argv[]);
|
|
static td_s32 set_enable_hard_only(td_s32 argc, td_char *argv[]);
|
|
|
|
static otp_sample g_otp_sample_data[] = {
|
|
{ 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_hardonly help" } },
|
|
{
|
|
1, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_AES).",
|
|
"example: ./sample_otp_hardonly set mcipher aes"
|
|
}
|
|
},
|
|
{
|
|
2, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_TDES).",
|
|
"example: ./sample_otp_hardonly set mcipher tdes"
|
|
}
|
|
},
|
|
{
|
|
3, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_SM4).",
|
|
"example: ./sample_otp_hardonly set mcipher sm4"
|
|
}
|
|
},
|
|
{
|
|
4, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_CSA2).",
|
|
"example: ./sample_otp_hardonly set tscipher csa2"
|
|
}
|
|
},
|
|
{
|
|
5, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_CSA3).",
|
|
"example: ./sample_otp_hardonly set tscipher csa3"
|
|
}
|
|
},
|
|
{
|
|
6, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_AES).",
|
|
"example: ./sample_otp_hardonly set tscipher aes"
|
|
}
|
|
},
|
|
{
|
|
7, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_SM4).",
|
|
"example: ./sample_otp_hardonly set tscipher sm4"
|
|
}
|
|
},
|
|
{
|
|
8, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_TDES).",
|
|
"example: ./sample_otp_hardonly set tscipher tdes"
|
|
}
|
|
},
|
|
{
|
|
9, "set", set_enable_hard_only,
|
|
{
|
|
"Set enable hard only --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_MULTI2).",
|
|
"example: ./sample_otp_hardonly set tscipher multi2"
|
|
}
|
|
},
|
|
{
|
|
10, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_AES).",
|
|
"example: ./sample_otp_hardonly get mcipher aes"
|
|
}
|
|
},
|
|
{
|
|
11, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_TDES).",
|
|
"example: ./sample_otp_hardonly get mcipher tdes"
|
|
}
|
|
},
|
|
{
|
|
12, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_ALL) algorithm(EXT_OTP_ALG_SM4).",
|
|
"example: ./sample_otp_hardonly get mcipher sm4"
|
|
}
|
|
},
|
|
{
|
|
13, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_CSA2).",
|
|
"example: ./sample_otp_hardonly get tscipher csa2"
|
|
}
|
|
},
|
|
{
|
|
14, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_CSA3).",
|
|
"example: ./sample_otp_hardonly get tscipher csa3"
|
|
}
|
|
},
|
|
{
|
|
15, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_AES).",
|
|
"example: ./sample_otp_hardonly get tscipher aes"
|
|
}
|
|
},
|
|
{
|
|
16, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_SM4).",
|
|
"example: ./sample_otp_hardonly get tscipher sm4"
|
|
}
|
|
},
|
|
{
|
|
17, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_TDES).",
|
|
"example: ./sample_otp_hardonly get tscipher tdes"
|
|
}
|
|
},
|
|
{
|
|
18, "get", get_hard_only_stat,
|
|
{
|
|
"Get hard only stat --> module(UAPI_OTP_MODULE_TSCIPHER) algorithm(EXT_OTP_ALG_MULTI2).",
|
|
"example: ./sample_otp_hardonly get tscipher multi2"
|
|
}
|
|
},
|
|
};
|
|
|
|
static td_void get_mcipher_algm_type(const td_char *source, uapi_otp_alg_type *algm_type)
|
|
{
|
|
if (case_strcmp("aes", source)) {
|
|
*algm_type = UAPI_OTP_ALG_AES;
|
|
} else if (case_strcmp("tdes", source)) {
|
|
*algm_type = UAPI_OTP_ALG_TDES;
|
|
} else if (case_strcmp("sm4", source)) {
|
|
*algm_type = UAPI_OTP_ALG_SM4;
|
|
} else {
|
|
*algm_type = UAPI_OTP_ALG_MAX;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
static td_void get_tscipher_algm_type(const td_char *source, uapi_otp_alg_type *algm_type)
|
|
{
|
|
if (case_strcmp("csa2", source)) {
|
|
*algm_type = UAPI_OTP_ALG_CSA2;
|
|
} else if (case_strcmp("csa3", source)) {
|
|
*algm_type = UAPI_OTP_ALG_CSA3;
|
|
} else if (case_strcmp("aes", source)) {
|
|
*algm_type = UAPI_OTP_ALG_AES;
|
|
} else if (case_strcmp("sm4", source)) {
|
|
*algm_type = UAPI_OTP_ALG_SM4;
|
|
} else if (case_strcmp("tdes", source)) {
|
|
*algm_type = UAPI_OTP_ALG_TDES;
|
|
} else if (case_strcmp("multi2", source)) {
|
|
*algm_type = UAPI_OTP_ALG_MULTI2;
|
|
} else {
|
|
*algm_type = UAPI_OTP_ALG_MAX;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
static td_void get_type(td_s32 argc, td_char *argv[],
|
|
uapi_otp_module_type *module_type,
|
|
uapi_otp_alg_type *algm_type)
|
|
{
|
|
if (argv[0x2] == TD_NULL || argv[0x3] == TD_NULL) {
|
|
sample_printf("argv[2] or argv[3] is NULL\n");
|
|
goto out;
|
|
}
|
|
|
|
if (module_type == TD_NULL || algm_type == TD_NULL) {
|
|
sample_printf("module_type or algm_type is NULL\n");
|
|
goto out;
|
|
}
|
|
|
|
if (case_strcmp("mcipher", argv[0x2])) {
|
|
*module_type = UAPI_OTP_MODULE_MCIPHER;
|
|
get_mcipher_algm_type(argv[0x3], algm_type);
|
|
} else if (case_strcmp("tscipher", argv[0x2])) {
|
|
*module_type = UAPI_OTP_MODULE_TSCIPHER;
|
|
get_tscipher_algm_type(argv[0x3], algm_type);
|
|
} else {
|
|
*module_type = UAPI_OTP_MODULE_MAX;
|
|
}
|
|
|
|
unused(argc);
|
|
out:
|
|
return;
|
|
}
|
|
|
|
static td_s32 get_hard_only_stat(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
td_bool stat = TD_FAILURE;
|
|
uapi_otp_module_type module_type = UAPI_OTP_MODULE_MAX;
|
|
uapi_otp_alg_type algm_type = UAPI_OTP_ALG_MAX;
|
|
|
|
get_type(argc, argv, &module_type, &algm_type);
|
|
if (module_type == UAPI_OTP_MODULE_MAX || algm_type == UAPI_OTP_ALG_MAX) {
|
|
sample_printf("Don't have module type or algm type\n");
|
|
ret = TD_FAILURE;
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_get_hard_only_stat(module_type, algm_type, &stat);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to get hard only stat, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
sample_printf("Get hard only stat: %d\n", stat);
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
static td_s32 set_enable_hard_only(td_s32 argc, td_char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
uapi_otp_module_type module_type = UAPI_OTP_MODULE_MAX;
|
|
uapi_otp_alg_type algm_type = UAPI_OTP_ALG_MAX;
|
|
|
|
get_type(argc, argv, &module_type, &algm_type);
|
|
if (module_type == UAPI_OTP_MODULE_MAX || algm_type == UAPI_OTP_ALG_MAX) {
|
|
sample_printf("Don't have module type or algm type\n");
|
|
ret = TD_FAILURE;
|
|
goto out;
|
|
}
|
|
|
|
ret = uapi_otp_hard_only_enable(module_type, algm_type);
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("Failed to enable hard only, ret = 0x%x \n", ret);
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
td_s32 main(int argc, char *argv[])
|
|
{
|
|
td_s32 ret;
|
|
|
|
if (argc < 0x4) {
|
|
sample_printf("sample parameter error.\n");
|
|
ret = SOC_ERR_OTP_INVALID_PARA;
|
|
goto out1;
|
|
}
|
|
|
|
if (case_strcmp("help", argv[1])) {
|
|
show_usage(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
|
ret = TD_SUCCESS;
|
|
goto out0;
|
|
}
|
|
|
|
ret = uapi_otp_init();
|
|
if (ret != TD_SUCCESS) {
|
|
sample_printf("OTP init failed, ret = 0x%x \n", ret);
|
|
goto out1;
|
|
}
|
|
|
|
ret = run_cmdline(argc, argv, g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
|
|
|
(td_void)uapi_otp_deinit();
|
|
|
|
out1:
|
|
show_returne_msg(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]), ret);
|
|
out0:
|
|
return ret;
|
|
}
|