// Copyright 2020-2021 Beken // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "cli.h" #include "driver/securityip.h" static void cli_securityip_help(void) { CLI_LOGI("securityip_driver init/deinit\r\n"); CLI_LOGI("securityip_trng cfg/get\r\n"); } static void cli_securityip_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { if (argc < 2) { cli_securityip_help(); return; } if (os_strcmp(argv[1], "init") == 0) { BK_LOG_ON_ERR(bk_securityip_driver_init()); } else if (os_strcmp(argv[1], "deinit") == 0) { BK_LOG_ON_ERR(bk_securityip_driver_deinit()); } else { cli_securityip_help(); return; } } static void cli_securityip_system_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { if (argc < 2) { cli_securityip_help(); return; } if (os_strcmp(argv[1], "version") == 0) { CLI_LOGI("get securityip system version sucess!\r\n"); } else if (os_strcmp(argv[1], "state") == 0) { CLI_LOGI("get securityip system state sucess!\r\n"); } else if (os_strcmp(argv[1], "reset") == 0) { CLI_LOGI("securityip system reset!\r\n"); } else { cli_securityip_help(); return; } } static void cli_securityip_trng_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { if (argc < 2) { cli_securityip_help(); return; } if (os_strcmp(argv[1], "cfg") == 0) { BK_LOG_ON_ERR(bk_securityip_trng_def_cfg()); } else if (os_strcmp(argv[1], "get") == 0) { uint8_t * RandNum_p; uint8_t * Num_p; uint32_t random_size = os_strtoul(argv[2], NULL, 10)&0xffff; Num_p = RandNum_p = (uint8_t *)malloc(random_size+4); memset(RandNum_p, 0xaa, random_size+4); BK_LOG_ON_ERR(bk_securityip_get_trng(random_size, RandNum_p)); CLI_LOGI("get random num is \r\n"); for(int i=0; i