123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- /**
- * \file cli_ps.c
- *
- * This File contains the "Persistent Storage" handlers for the CLI application,
- * to exercise various functionalities of the Mindtree Mesh stack.
- */
- /*
- * Copyright (C) 2017. Mindtree Ltd.
- * All rights reserved.
- */
- /* ------------------------------- Header File Inclusion */
- #include "cli_main.h"
- /* ------------------------------- Global Variables */
- /* Level - Persistent Storage */
- DECL_STATIC CLI_COMMAND cli_ps_cmd_list[] =
- {
- /* Help */
- { "help", "Help", cli_help },
- /* Get Device Key */
- { "getdevkey", "Get Device Key", cli_ps_get_device_key },
- /* Get App Key */
- { "getappkey", "Get App Key", cli_ps_get_app_key },
- /* Get Network Key */
- { "getnetkey", "Get Network Key", cli_ps_get_net_key },
- /* Get Primary Unicast Address */
- { "getprimunicastaddr", "Get Primary Unicast Address", cli_ps_get_primary_unicast_addr },
- /* Back */
- { "back", "One Level Up", cli_back },
- /* Root */
- { "root", "Back to Root", cli_root }
- };
- /* ------------------------------- Functions */
- /* Persistent Storage */
- API_RESULT cli_ps(UINT32 argc, UCHAR *argv[])
- {
- CONSOLE_OUT("In Persistent Storage\n");
- cli_cmd_stack_push(cli_ps_cmd_list, sizeof(cli_ps_cmd_list) / sizeof(CLI_COMMAND));
- cli_help(argc, argv);
- return API_SUCCESS;
- }
- /* Get Device Key */
- API_RESULT cli_ps_get_device_key(UINT32 argc, UCHAR *argv[])
- {
- UINT8 index;
- UINT8 * key;
- API_RESULT retval;
- CONSOLE_OUT("In PS Get Device Key\n");
- if (1 != argc)
- {
- CONSOLE_OUT("Usage: getdevkey <Device Key Index>\n");
- return API_FAILURE;
- }
- index = (UINT8)CLI_strtoi(argv[0], (UINT8)CLI_strlen(argv[0]), 16);
- retval = MS_access_cm_get_device_key
- (
- index,
- &key
- );
- /* Check Retval. Print Device Key */
- if (API_SUCCESS == retval)
- {
- CONSOLE_OUT("Device Key[0x%02X]: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
- index, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
- key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15]);
- }
- else
- {
- CONSOLE_OUT("FAILED. Reason: 0x%04X\n", retval);
- }
- return API_SUCCESS;
- }
- /* Get App Key */
- API_RESULT cli_ps_get_app_key(UINT32 argc, UCHAR *argv[])
- {
- MS_APPKEY_HANDLE handle;
- UINT8 * key;
- UINT8 aid;
- API_RESULT retval;
- CONSOLE_OUT("In PS Get App Key\n");
- if (1 != argc)
- {
- CONSOLE_OUT("Usage: getappkey <App Key Handle>\n");
- return API_FAILURE;
- }
- handle = (MS_APPKEY_HANDLE)CLI_strtoi(argv[0], (UINT16)CLI_strlen(argv[0]), 16);
- retval = MS_access_cm_get_app_key
- (
- handle,
- &key,
- &aid
- );
- /* Check Retval. Print App Key */
- if (API_SUCCESS == retval)
- {
- CONSOLE_OUT("App Key[0x%02X]: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
- handle, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
- key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15]);
- }
- else
- {
- CONSOLE_OUT("FAILED. Reason: 0x%04X\n", retval);
- }
- return API_SUCCESS;
- }
- /* Get Network Key */
- API_RESULT cli_ps_get_net_key(UINT32 argc, UCHAR *argv[])
- {
- MS_SUBNET_HANDLE handle;
- UINT8 key[16];
- API_RESULT retval;
- CONSOLE_OUT("In PS Get Network Key\n");
- if (1 != argc)
- {
- CONSOLE_OUT("Usage: getnetkey <Subnet Handle>\n");
- return API_FAILURE;
- }
- handle = (MS_SUBNET_HANDLE)CLI_strtoi(argv[0], (UINT16)CLI_strlen(argv[0]), 16);
- retval = MS_access_cm_get_netkey_at_offset
- (
- handle,
- 0,
- key
- );
- /* Check Retval. Print Network Key */
- if (API_SUCCESS == retval)
- {
- CONSOLE_OUT("Net Key[0x%02X]: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
- handle, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
- key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15]);
- }
- else
- {
- CONSOLE_OUT("FAILED. Reason: 0x%04X\n", retval);
- }
- return API_SUCCESS;
- }
- /* Get Primary Unicast Address */
- API_RESULT cli_ps_get_primary_unicast_addr(UINT32 argc, UCHAR *argv[])
- {
- MS_NET_ADDR addr;
- API_RESULT retval;
- CONSOLE_OUT("In PS Get Primary Unicast Address\n");
- retval = MS_access_cm_get_primary_unicast_address(&addr);
- /* Check Retval. Print Primary Unicast Address */
- if (API_SUCCESS == retval)
- {
- CONSOLE_OUT("Primary Unicast Address: 0x%04X\n", addr);
- }
- else
- {
- CONSOLE_OUT("FAILED. Reason: 0x%04X\n", retval);
- }
- return API_SUCCESS;
- }
|