cloud/dps_demo/dps_demo_cli_variables.c

/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#include "gos.h"
#include "dps_demo_common.h"
GOS_CMD_CREATE_GETTER_SETTER(dps, hostname, "dps.hostname", SC2('d', 'p', 'h'), 0, 1);
GOS_CMD_CREATE_GETTER_SETTER(dps, port, "dps.port", SC2('d', 'p', 'p'), 0, 1);
GOS_CMD_CREATE_GETTER_SETTER(dps, connector, "dps.connector", SC2('d', 'p', 'n'), 0, 1);
GOS_CMD_CREATE_GETTER_SETTER(dps, ca_cert, "dps.ca_cert", SC2('d', 'p', 'a'), 0, 1);
GOS_CMD_CREATE_GETTER_SETTER(dps, key_filename, "dps.key_filename", SC2('d', 'p', 'k'), 0, 1);
GOS_CMD_CREATE_GETTER_SETTER(dps, cert_filename, "dps.cert_filename", SC2('d', 'p', 'c'), 0, 1);
/******************************************************************************
* Hostname or IP address of the broker/server
*/
GOS_DEFINE_GETTER(dps, hostname)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%s", dps_settings->hostname);
}
GOS_DEFINE_SETTER(dps, hostname)
{
if(strlen(argv[1]) > sizeof(dps_settings->hostname))
{
GOS_LOG("Failed (maximum length is %u)", sizeof(dps_settings->hostname));
}
else
{
strcpy((char*)dps_settings->hostname, argv[1]);
}
}
/******************************************************************************
* Port of the provisioning server/broker
*/
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%d", dps_settings->port);
}
{
GOS_CMD_PARSE_INT_ARG_WITH_VAR(uint16_t, dps_settings->port, argv[1], 0, 65535);
}
/******************************************************************************
* DMS connector code
*/
GOS_DEFINE_GETTER(dps, connector)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%s", dps_settings->connector);
}
GOS_DEFINE_SETTER(dps, connector)
{
if(strlen(argv[1]) > sizeof(dps_settings->connector))
{
GOS_LOG("Failed (maximum length is %u)", sizeof(dps_settings->connector));
}
else
{
strcpy((char*)dps_settings->connector, argv[1]);
}
}
/******************************************************************************
* CA cert filename
*/
GOS_DEFINE_GETTER(dps, ca_cert)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%s", dps_settings->ca_cert);
}
GOS_DEFINE_SETTER(dps, ca_cert)
{
if(strlen(argv[1]) > sizeof(dps_settings->ca_cert))
{
GOS_LOG("Failed (maximum length is %u)", sizeof(dps_settings->ca_cert));
}
else
{
strcpy((char*)dps_settings->ca_cert, argv[1]);
}
}
/******************************************************************************
* Device/client key filename
*/
GOS_DEFINE_GETTER(dps, key_filename)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%s", dps_settings->key_filename);
}
GOS_DEFINE_SETTER(dps, key_filename)
{
if(strlen(argv[1]) > sizeof(dps_settings->key_filename))
{
GOS_LOG("Failed (maximum length is %u)", sizeof(dps_settings->key_filename));
}
else
{
strcpy((char*)dps_settings->key_filename, argv[1]);
}
}
/******************************************************************************
* Device/client certificate filename
*/
GOS_DEFINE_GETTER(dps, cert_filename)
{
gos_cmd_format_response(GOS_CMD_SUCCESS, "%s", dps_settings->cert_filename);
}
GOS_DEFINE_SETTER(dps, cert_filename)
{
if(strlen(argv[1]) > sizeof(dps_settings->cert_filename))
{
GOS_LOG("Failed (maximum length is %u)", sizeof(dps_settings->cert_filename));
}
else
{
strcpy((char*)dps_settings->cert_filename, argv[1]);
}
}