Skip to content

Commit

Permalink
complete audit with chip_support_enable_storage_api_audit=true
Browse files Browse the repository at this point in the history
  • Loading branch information
srickardti committed Aug 17, 2022
1 parent 07ddad4 commit 9c53c33
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 98 deletions.
13 changes: 0 additions & 13 deletions examples/persistent-storage/KeyValueStorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ CHIP_ERROR TestMultiRead()
return CHIP_NO_ERROR;
}

CHIP_ERROR TestZeroLength()
{
const char * kTestKey = "zero_key";
char read_value[10] = {0};
size_t read_size;
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, NULL, 0U));
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
ReturnErrorCodeIf(read_size != 0U, CHIP_ERROR_INTERNAL);
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
return CHIP_NO_ERROR;
}

} // namespace

void RunKvsTest(TestConfigurations test_config)
Expand All @@ -172,7 +160,6 @@ void RunKvsTest(TestConfigurations test_config)
RUN_TEST(TestArray());
RUN_TEST(TestStruct());
RUN_TEST(TestUpdateValue());
RUN_TEST(TestZeroLength());
if (test_config != SKIP_MULTI_READ_TEST)
{
RUN_TEST(TestMultiRead());
Expand Down
29 changes: 8 additions & 21 deletions examples/persistent-storage/cc13x2x7_26x2x7/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import("//build_overrides/ti_simplelink_sdk.gni")

import("${build_root}/config/defaults.gni")

import("${chip_root}/src/platform/device.gni")

import("${ti_simplelink_sdk_build_root}/ti_simplelink_executable.gni")
import("${ti_simplelink_sdk_build_root}/ti_simplelink_sdk.gni")

Expand All @@ -30,33 +28,22 @@ project_dir = "${chip_root}/examples/persistent-storage/cc13x2x7_26x2x7"

ti_simplelink_sdk("sdk") {
include_dirs = [ "${project_dir}/include" ]
public_configs = [ ":sysconfig_config" ]

defines = []
if (is_debug) {
defines += [ "BUILD_RELEASE=0" ]
} else {
defines += [ "BUILD_RELEASE=1" ]
}
}

ti_sysconfig("sysconfig") {
sources = [ "${project_dir}/chip.syscfg" ]

outputs = [
"ti_radio_config.c",
"ti_radio_config.h",
"ti_devices_config.c",
"ti_drivers_config.c",
"ti_drivers_config.h",
"ti_ble_config.c",
"ti_ble_config.h",
"ti_dmm_application_policy.c",
"ti_dmm_application_policy.h",

# disabled until upstream generation is aligned
#"tiop_config.h",
#"tiop_config.c",

# not traditional source files
#"ti_utils_build_linker.cmd.genlibs",
#"syscfg_c.rov.xs",
#"ti_utils_runtime_model.gv",
#"ti_utils_runtime_Makefile",
#"ti_ble_app_config.opt",
#"ti_build_config.opt",
]

public_configs = [ ":sdk_dmm_config" ]
Expand Down
25 changes: 3 additions & 22 deletions examples/persistent-storage/cc13x2x7_26x2x7/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,9 @@ ti_simplelink_sysconfig_target =

ti_simplelink_board = "LP_CC2652R7"

# Size Optimizations
# use -Os instead of -Og, LWIP release build
optimize_debug_level = "s"
lwip_debug = false

chip_enable_ota_requestor = true

# Disable CHIP Logging
#chip_progress_logging = false
chip_detail_logging = false
chip_automation_logging = false
# use -Os instead of -Og
#optimize_debug_level = "s"
#lwip_debug = false

# BLE options
chip_config_network_layer_ble = true

# Disable lock tracking, since our FreeRTOS configuration does not set
# INCLUDE_xSemaphoreGetMutexHolder
chip_stack_lock_tracking = "none"

chip_enable_openthread = false

matter_device_vid = "0xFFF1"
matter_device_pid = "0xFFFF"
matter_software_ver = "0x0001"
matter_software_ver_str = "1.0d1"
17 changes: 8 additions & 9 deletions examples/persistent-storage/cc13x2x7_26x2x7/chip.syscfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var AESCCM = scripting.addModule("/ti/drivers/AESCCM");
var AESECB = scripting.addModule("/ti/drivers/AESECB");
var Button = scripting.addModule("/ti/drivers/apps/Button");
var ECJPAKE = scripting.addModule("/ti/drivers/ECJPAKE");
var LED = scripting.addModule("/ti/drivers/apps/LED");
var NVS = scripting.addModule("/ti/drivers/NVS");
var RF = scripting.addModule("/ti/drivers/RF");
Expand All @@ -42,8 +43,8 @@ var AESECB1 = AESECB.addInstance();
var AESECB2 = AESECB.addInstance();
var Button1 = Button.addInstance();
var Button2 = Button.addInstance();
var ECJPAKE = ECJPAKE.addInstance();
var NVS1 = NVS.addInstance();
var NVS2 = NVS.addInstance();
var SHA21 = SHA2.addInstance();
var LED1 = LED.addInstance();
var LED2 = LED.addInstance();
Expand Down Expand Up @@ -83,25 +84,23 @@ Button2.gpioPin.interruptTrigger = "Falling Edge";

/* ======== CCFG ======== */
var CCFG = scripting.addModule("/ti/devices/CCFG");
const deviceName = system.getScript("/ti/ti154stack/ti154stack_common.js").getLaunchPadFromDevice();
const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings;
for(var setting in ccfgSettings)
{
CCFG[setting] = ccfgSettings[setting];
}

// Disable CCFG generation, this is added by the BIM project
CCFG.enableCodeGeneration = false;

// Update LF Clock Source for CC2652RB devices
if(deviceName.includes("RB"))
{
CCFG.srcClkLF = "Derived from HF XOSC";
}
/* NVS */
NVS1.$name = "CONFIG_NVSINTERNAL";

NVS1.internalFlash.regionBase = 0xAA000;
NVS1.internalFlash.regionSize = 0x4000;

NVS2.$name = "CONFIG_NVSEXTERNAL";
NVS2.nvsType = "External"; // NVS Region Type
NVS2.$hardware = system.deviceData.board.components.MX25R8035F;

/* RF */
/* if an antenna component exists, assign it to the rf instance */
if (system.deviceData.board && system.deviceData.board.components.RF) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,39 @@
#endif // BUILD_RELEASE

/**
* Values set by args.gni:
* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
*
* 0xFFF1: Test vendor.
*/
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1

/**
* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID
* CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
* CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
*
* 0x8009: example persistent-storage
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8009

/**
* CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION
*
* The hardware version number assigned to device or product by the device vendor. This
* number is scoped to the device product id, and typically corresponds to a revision of the
* physical device, a change to its packaging, and/or a change to its marketing presentation.
* This value is generally *not* incremented for device software versions.
*/
#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1

/**
* CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
*
* A string identifying the software version running on the device.
* CHIP currently expects the software version to be in the format
* {MAJOR_VERSION}.0d{MINOR_VERSION}
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "1.0d1"
#endif
/**
* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
*
Expand All @@ -89,8 +115,6 @@
*/
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512)

#define MATTER_CC13X2_26X2_PLATFORM_LOG_ENABLED 1

/**
* CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,38 @@
*
*/

#pragma once
#ifndef OPENTHREAD_PLATFORM_CONFIG_H
#define OPENTHREAD_PLATFORM_CONFIG_H

// Disable the Nordic-supplied OpenThread logging facilities and use
// the facilities provided by the CHIP Device Layer
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_APP

// When operating in a less than ideal RF environment, having a more forgiving configuration
// of OpenThread makes thread a great deal more reliable.
#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY 120 // default is 28800
#define OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_DIRECT 15 // default is 3
#define OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_INDIRECT 1 // default is 0
#define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 16 // default is 4

// Enable periodic parent search to speed up finding a better parent.
#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 1 // default is 0
#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -45 // default is -65
#define OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH 1 // default is 0

// Use smaller maximum interval to speed up reattaching.
#define OPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_MAXIMUM_INTERVAL (60 * 10 * 1000) // default 1200000 ms

#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
#define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 0
#define UART_AS_SERIAL_TRANSPORT 1
#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1

#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1
#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1
#define OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE 1

// Use the TI-supplied default platform configuration for remainder
#include "openthread-core-cc13x2_26x2-config.h"

#endif // OPENTHREAD_PLATFORM_CONFIG_H
17 changes: 8 additions & 9 deletions src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <platform/internal/testing/ConfigUnitTest.h>

#include <lib/core/CHIPEncoding.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/support/CodeUtils.h>
#include <platform/cc13x2_26x2/CC13X2_26X2Config.h>

Expand Down Expand Up @@ -165,7 +166,7 @@ CHIP_ERROR CC13X2_26X2Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t
/* Iterate through the key range to find a key that matches. */
static uint8_t FindKVSSubID(const char * key, uint16_t & subID)
{
char key_scratch[32]; // 32 characters seems large enough for a key
char key_scratch[PersistentStorageDelegate::kKeyLengthMax + 1];
NVINTF_nvProxy_t nvProxy = { 0 };
uint8_t status = NVINTF_SUCCESS;

Expand Down Expand Up @@ -210,19 +211,15 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val

len = sNvoctpFps.getItemLen(val_item);

if (offset_bytes < len && (offset_bytes + value_size) > len)
if (value_size >= (len - offset_bytes))
{
// trying to read up to the end of the element
// reading to end of element
read_len = len - offset_bytes;
}
else if (value_size > len)
{
// reading the whole element
read_len = len;
}
else
{
read_len = value_size;
err = CHIP_ERROR_BUFFER_TOO_SMALL;
}

if (read_len > 0)
Expand Down Expand Up @@ -337,7 +334,7 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data,

CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key)
{
CHIP_ERROR err = CHIP_NO_ERROR;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
uint16_t subID;
NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID;
NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID;
Expand All @@ -360,6 +357,8 @@ CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key)
{
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

err = CHIP_NO_ERROR;
}

return err;
Expand Down
13 changes: 4 additions & 9 deletions src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
CHIP_ERROR err;

VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
if (0U != value_size)
{
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
}

err = CC13X2_26X2Config::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes);

Expand All @@ -58,14 +61,6 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
if (0U == value_size)
{
VerifyOrReturnError(nullptr == value, CHIP_ERROR_INVALID_ARGUMENT);
}
else
{
VerifyOrReturnError(nullptr != value, CHIP_ERROR_INVALID_ARGUMENT);
}

return CC13X2_26X2Config::WriteKVS(key, value, value_size);
}
Expand Down
13 changes: 4 additions & 9 deletions src/platform/cc32xx/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,17 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
size_t offset_bytes) const
{
VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
if (0U != value_size)
{
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);
}

return CC32XXConfig::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes);
}

CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT);
if (0U == value_size)
{
VerifyOrReturnError(nullptr == value, CHIP_ERROR_INVALID_ARGUMENT);
}
else
{
VerifyOrReturnError(nullptr != value, CHIP_ERROR_INVALID_ARGUMENT);
}

return CC32XXConfig::WriteKVS(key, value, value_size);
}
Expand Down

0 comments on commit 9c53c33

Please sign in to comment.