/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved. * Description: Test the file of the root key slot flag interface. * Author: Hisilicon * Create: 2019-09-24 */ #include "sample_otp_base.h" #include "securec.h" static td_s32 get_root_key_slot_flag(td_s32 argc, td_char *argv[]); static td_s32 set_root_key_slot_flag(td_s32 argc, td_char *argv[]); static otp_sample g_otp_sample_data[] = { { 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_rootkeyslotflag help" } }, { 1, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_BOOT_ROOTKEY.", "example: ./sample_otp_rootkeyslotflag set boot" } }, { 2, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_OEM_ROOTKEY.", "example: ./sample_otp_rootkeyslotflag set OEM" } }, { 3, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY0.", "example: ./sample_otp_rootkeyslotflag set cas0" } }, { 4, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY1.", "example: ./sample_otp_rootkeyslotflag set cas1" } }, { 5, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY2.", "example: ./sample_otp_rootkeyslotflag set cas2" } }, { 6, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY3.", "example: ./sample_otp_rootkeyslotflag set cas3" } }, { 7, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY4.", "example: ./sample_otp_rootkeyslotflag set cas4" } }, { 8, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY5.", "example: ./sample_otp_rootkeyslotflag set cas5" } }, { 9, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY6.", "example: ./sample_otp_rootkeyslotflag set cas6" } }, { 10, "set", set_root_key_slot_flag, { "Set root key slot flag --> UAPI_OTP_CAS_ROOTKEY7.", "example: ./sample_otp_rootkeyslotflag set cas7" } }, { 11, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_BOOT_ROOTKEY.", "example: ./sample_otp_rootkeyslotflag get boot" } }, { 12, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_OEM_ROOTKEY.", "example: ./sample_otp_rootkeyslotflag get OEM" } }, { 13, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY0.", "example: ./sample_otp_rootkeyslotflag get cas0" } }, { 14, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY1.", "example: ./sample_otp_rootkeyslotflag get cas1" } }, { 15, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY2.", "example: ./sample_otp_rootkeyslotflag get cas2" } }, { 16, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY3.", "example: ./sample_otp_rootkeyslotflag get cas3" } }, { 17, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY4.", "example: ./sample_otp_rootkeyslotflag get cas4" } }, { 18, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY5.", "example: ./sample_otp_rootkeyslotflag get cas5" } }, { 19, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY6.", "example: ./sample_otp_rootkeyslotflag get cas6" } }, { 20, "get", get_root_key_slot_flag, { "Get root key slot flag --> UAPI_OTP_CAS_ROOTKEY7.", "example: ./sample_otp_rootkeyslotflagget cas7" } }, }; static td_void get_type(td_s32 argc, td_char *argv[], uapi_otp_rootkey *key_type) { if (argv[0x2] == TD_NULL) { sample_printf("argv[0x2] is NULL\n"); goto out; } if (key_type == TD_NULL) { sample_printf("key_type is NULL\n"); goto out; } if (case_strcmp("boot", argv[0x2])) { *key_type = UAPI_OTP_BOOT_ROOTKEY; } else if (case_strcmp("OEM", argv[0x2])) { *key_type = UAPI_OTP_OEM_ROOTKEY; } else if (case_strcmp("cas0", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY0; } else if (case_strcmp("cas1", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY1; } else if (case_strcmp("cas2", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY2; } else if (case_strcmp("cas3", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY3; } else if (case_strcmp("cas4", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY4; } else if (case_strcmp("cas5", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY5; } else if (case_strcmp("cas6", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY6; } else if (case_strcmp("cas7", argv[0x2])) { *key_type = UAPI_OTP_CAS_ROOTKEY7; } else { *key_type = UAPI_OTP_ROOTKEY_MAX; } unused(argc); out: return; } static td_s32 get_root_key_slot_flag(td_s32 argc, td_char *argv[]) { td_s32 ret = TD_FAILURE; uapi_otp_rootkey key_type = UAPI_OTP_ROOTKEY_MAX; uapi_otp_rootkey_slot_flag flag; get_type(argc, argv, &key_type); if (key_type == UAPI_OTP_ROOTKEY_MAX) { sample_printf("Don't have key type\n"); ret = TD_FAILURE; goto out; } if (memset_s(&flag, sizeof(flag), 0x0, sizeof(flag) != EOK)) { sample_printf("Failed to memset_s\n"); goto out; } ret = uapi_otp_get_root_key_slot_flag(key_type, &flag); if (ret != TD_SUCCESS) { sample_printf("Failed to get root key slot flag, ret = 0x%x \n", ret); goto out; } sample_printf("Get root key slot flag: 0x%08x\n", flag.slot_flag); out: return ret; } static td_s32 set_root_key_slot_flag(td_s32 argc, td_char *argv[]) { td_s32 ret = TD_FAILURE; uapi_otp_rootkey key_type = UAPI_OTP_ROOTKEY_MAX; uapi_otp_rootkey_slot_flag flag; get_type(argc, argv, &key_type); if (key_type == UAPI_OTP_ROOTKEY_MAX) { sample_printf("Don't have key type\n"); ret = TD_FAILURE; goto out; } if (memset_s(&flag, sizeof(flag), 0x0, sizeof(flag) != EOK)) { sample_printf("Failed to memset_s\n"); goto out; } flag.slot_flag = 0x30234354; ret = uapi_otp_set_root_key_slot_flag(key_type, &flag); if (ret != TD_SUCCESS) { sample_printf("Failed to set root key slot flag, ret = 0x%x \n", ret); goto out; } sample_printf("Set root key slot flag: 0x%08x\n", flag.slot_flag); out: return ret; } td_s32 main(int argc, char *argv[]) { td_s32 ret; if (argc < 0x3) { 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; }