diff --git a/examples/lighting-app/k32w/BUILD.gn b/examples/lighting-app/k32w/BUILD.gn index 556403709355cb..64883db5d0ada8 100644 --- a/examples/lighting-app/k32w/BUILD.gn +++ b/examples/lighting-app/k32w/BUILD.gn @@ -72,8 +72,8 @@ k32w_executable("light_app") { "${chip_root}/src/lib", "${chip_root}/third_party/mbedtls:mbedtls", "${k32w_platform_dir}/app/support:freertos_mbedtls_utils", - "${openthread_root}:libopenthread-cli-ftd", - "${openthread_root}:libopenthread-ftd", + "${openthread_root}:libopenthread-cli-mtd", + "${openthread_root}:libopenthread-mtd", ] cflags = [ "-Wconversion" ] diff --git a/examples/lighting-app/k32w/main/main.cpp b/examples/lighting-app/k32w/main/main.cpp index 6d5cdd811712a9..ba71649bf68afd 100644 --- a/examples/lighting-app/k32w/main/main.cpp +++ b/examples/lighting-app/k32w/main/main.cpp @@ -98,27 +98,12 @@ extern "C" void main_task(void const * argument) goto exit; } - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice); + ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); if (ret != CHIP_NO_ERROR) { goto exit; } - // Configure the Thread polling behavior for the device. - { - ConnectivityManager::ThreadPollingConfig pollingConfig; - pollingConfig.Clear(); - pollingConfig.ActivePollingIntervalMS = THREAD_ACTIVE_POLLING_INTERVAL_MS; - pollingConfig.InactivePollingIntervalMS = THREAD_INACTIVE_POLLING_INTERVAL_MS; - - ret = ConnectivityMgr().SetThreadPollingConfig(pollingConfig); - if (ret != CHIP_NO_ERROR) - { - K32W_LOG("Error during ConnectivityMgr().SetThreadPollingConfig(pollingConfig)"); - goto exit; - } - } - ret = PlatformMgr().StartEventLoopTask(); if (ret != CHIP_NO_ERROR) { diff --git a/examples/platform/k32w/app/ldscripts/chip-k32w061-linker.ld b/examples/platform/k32w/app/ldscripts/chip-k32w061-linker.ld index 630dbc9f5ee95a..477040162d2fd9 100644 --- a/examples/platform/k32w/app/ldscripts/chip-k32w061-linker.ld +++ b/examples/platform/k32w/app/ldscripts/chip-k32w061-linker.ld @@ -72,7 +72,7 @@ m_fsl_prodInfo_size = m_sector_size; m_fsl_prodInfo_end = m_flash_size - 17 * m_sector_size - 1; m_fsl_prodInfo_start = m_fsl_prodInfo_end - m_fsl_prodInfo_size + 1; -NV_STORAGE_MAX_SECTORS = 32; +NV_STORAGE_MAX_SECTORS = 63; NV_STORAGE_SIZE = NV_STORAGE_MAX_SECTORS * m_sector_size; NV_STORAGE_START_ADDRESS = m_fsl_prodInfo_start - 1; NV_STORAGE_END_ADDRESS = NV_STORAGE_START_ADDRESS - NV_STORAGE_SIZE + 1; diff --git a/examples/platform/k32w/app/project_include/CHIPProjectConfig.h b/examples/platform/k32w/app/project_include/CHIPProjectConfig.h index 9c8a9421e7d0f2..11cff32811191a 100644 --- a/examples/platform/k32w/app/project_include/CHIPProjectConfig.h +++ b/examples/platform/k32w/app/project_include/CHIPProjectConfig.h @@ -27,14 +27,6 @@ #pragma once -#if BUILD_RELEASE // release build - -// Security and Authentication enabled for release build. -#define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 - -#else // development build - // Security and Authentication disabled for development build. // For convenience, enable CHIP Security Test Mode and disable the requirement for // authentication in various protocols. @@ -51,7 +43,7 @@ * * This option is for testing only and should be disabled in production releases. */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 +//#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 // Use a default setup PIN code if one hasn't been provisioned in flash. #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 @@ -68,8 +60,6 @@ */ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" -#endif // BUILD_RELEASE - /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID * @@ -92,7 +82,11 @@ * physical device, a change to its packaging, and/or a change to its marketing presentation. * This value is generally *not* incremented for device software revisions. */ -#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1 +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 100 + +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING +#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING "v0.1.0" +#endif /** * CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING @@ -102,8 +96,21 @@ * {MAJOR_VERSION}.0d{MINOR_VERSION} */ #ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING -#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "0.1ALPHA" +#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "04-2020-te2" #endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION +#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION 42020 +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME "NXP Semiconductors" +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" +#endif + /** * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE * diff --git a/examples/platform/k32w/args.gni b/examples/platform/k32w/args.gni index 9f5900a8cb1f5b..c3bd4812a11d07 100644 --- a/examples/platform/k32w/args.gni +++ b/examples/platform/k32w/args.gni @@ -18,6 +18,7 @@ import("${chip_root}/src/platform/K32W/args.gni") arm_float_abi = "soft" arm_cpu = "cortex-m4" +arm_arch = "armv7e-m" openthread_project_core_config_file = "OpenThreadConfig.h" openthread_core_config_deps = [] diff --git a/scripts/examples/k32w_example.sh b/scripts/examples/k32w_example.sh index 01920dcd7a1483..61d85f171ecc7b 100755 --- a/scripts/examples/k32w_example.sh +++ b/scripts/examples/k32w_example.sh @@ -27,5 +27,5 @@ env "$(dirname "$0")"/../../third_party/k32w_sdk/sdk_fixes/patch_k32w_sdk.sh -gn gen --root="$1" "$2" --args="k32w_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=true" +gn gen --root="$1" "$2" --args="k32w_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=false" ninja -C "$2" diff --git a/src/platform/K32W/CHIPDevicePlatformConfig.h b/src/platform/K32W/CHIPDevicePlatformConfig.h index ed955bb3527189..a4ab609eabeb4d 100644 --- a/src/platform/K32W/CHIPDevicePlatformConfig.h +++ b/src/platform/K32W/CHIPDevicePlatformConfig.h @@ -89,7 +89,7 @@ #endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 -#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 1 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 #define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0 @@ -101,3 +101,5 @@ #define CONFIG_CHIP_NFC_COMMISSIONING 1 #define CHIP_DEVICE_CONFIG_ENABLE_NFC 1 + +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 diff --git a/src/platform/K32W/K32WConfig.cpp b/src/platform/K32W/K32WConfig.cpp index fb3917dc0c8779..e1dea8054ff95d 100644 --- a/src/platform/K32W/K32WConfig.cpp +++ b/src/platform/K32W/K32WConfig.cpp @@ -366,6 +366,20 @@ CHIP_ERROR K32WConfig::FactoryResetConfig(void) { CHIP_ERROR err; + err = FactoryResetConfigInternal(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig); + + if (err == CHIP_NO_ERROR) + { + err = FactoryResetConfigInternal(kMinConfigKey_KVS, kMaxConfigKey_KVS); + } + + return err; +} + +CHIP_ERROR K32WConfig::FactoryResetConfigInternal(Key firstKey, Key lastKey) +{ + CHIP_ERROR err; + // Iterate over all the CHIP Config PDM ID records and delete each one err = ForEachRecord(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig, false, [](const Key & pdmKey, const size_t & length) -> CHIP_ERROR { @@ -413,7 +427,7 @@ bool K32WConfig::ValidConfigKey(Key key) { // Returns true if the key is in the valid CHIP Config PDM key range. - if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_ChipCounter)) + if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS)) { return true; } diff --git a/src/platform/K32W/K32WConfig.h b/src/platform/K32W/K32WConfig.h index 72338d9db3076d..bd7aa8d587735e 100644 --- a/src/platform/K32W/K32WConfig.h +++ b/src/platform/K32W/K32WConfig.h @@ -60,6 +60,8 @@ class K32WConfig * Cleared during factory reset. */ static constexpr uint8_t kPDMId_ChipCounter = 0x03; /**< PDM id for settings containing dynamic counter values set at runtime. * Retained during factory reset. */ + static constexpr uint8_t kPDMId_KVS = 0x04; /**< PDM id for settings containing KVS set at runtime. + * Cleared during factory reset. */ using Key = uint32_t; @@ -121,6 +123,8 @@ class K32WConfig static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x1E); static constexpr Key kMinConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x00); static constexpr Key kMaxConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x1F); // Allows 32 Counters to be created. + static constexpr Key kMinConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0x00); + static constexpr Key kMaxConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0xFF); static CHIP_ERROR Init(void); @@ -154,6 +158,7 @@ class K32WConfig private: static CHIP_ERROR MapPdmStatus(PDM_teStatus pdmStatus); static CHIP_ERROR MapPdmInitStatus(int pdmStatus); + static CHIP_ERROR FactoryResetConfigInternal(Key firstKey, Key lastKey); }; /** diff --git a/src/platform/K32W/KeyValueStoreManagerImpl.cpp b/src/platform/K32W/KeyValueStoreManagerImpl.cpp index 84eff6796744f2..09f52561e13ec9 100644 --- a/src/platform/K32W/KeyValueStoreManagerImpl.cpp +++ b/src/platform/K32W/KeyValueStoreManagerImpl.cpp @@ -20,15 +20,85 @@ * @file * Platform-specific key value storage implementation for K32W */ +/* this file behaves like a config.h, comes first */ +#include +#include "support/CHIPMem.h" +#include #include +#include + +#include "PDM.h" namespace chip { namespace DeviceLayer { namespace PersistedStorage { +/* TODO: adjust this value */ +#define MAX_NO_OF_KEYS 255 + KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; +CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, + size_t offset_bytes) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + std::hash hash_fn; + uint16_t key_id; + uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; + size_t read_bytes; + + VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT); + key_id = hash_fn(key) % MAX_NO_OF_KEYS; + + ChipLogProgress(DeviceLayer, "KVS, get key id:: %i", key_id); + + err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin( + chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id), (uint8_t *) value, value_size, read_bytes); + + *read_bytes_size = read_bytes; + +exit: + return err; +} + +CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + std::hash hash_fn; + uint16_t key_id; + uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; + + VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT); + key_id = hash_fn(key) % MAX_NO_OF_KEYS; + + ChipLogProgress(DeviceLayer, "KVS, put key id:: %i", key_id); + + err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueBin( + chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id), (uint8_t *) value, value_size); + +exit: + return err; +} + +CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + std::hash hash_fn; + uint16_t key_id; + uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; + + VerifyOrExit(key != NULL, err = CHIP_ERROR_INVALID_ARGUMENT); + key_id = hash_fn(key) % MAX_NO_OF_KEYS; + + ChipLogProgress(DeviceLayer, "KVS, deleting key id:: %i", key_id); + + err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id)); + +exit: + return err; +} + } // namespace PersistedStorage } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/K32W/KeyValueStoreManagerImpl.h b/src/platform/K32W/KeyValueStoreManagerImpl.h index 12ed71ef619b31..c62eb65c0bc388 100644 --- a/src/platform/K32W/KeyValueStoreManagerImpl.h +++ b/src/platform/K32W/KeyValueStoreManagerImpl.h @@ -36,14 +36,11 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager public: // NOTE: Currently this platform does not support partial and offset reads // these will return CHIP_ERROR_NOT_IMPLEMENTED. - CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0) - { - return CHIP_ERROR_NOT_IMPLEMENTED; - } + CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, size_t offset); - CHIP_ERROR _Delete(const char * key) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _Delete(const char * key); - CHIP_ERROR _Put(const char * key, const void * value, size_t value_size) { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR _Put(const char * key, const void * value, size_t value_size); private: // ===== Members for internal use by the following friends. @@ -68,7 +65,7 @@ inline KeyValueStoreManager & KeyValueStoreMgr(void) * Returns the platform-specific implementation of the KeyValueStoreManager singleton object. * * Chip applications can use this to gain access to features of the KeyValueStoreManager - * that are specific to the ESP32 platform. + * that are specific to the K32W platform. */ inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void) { diff --git a/src/platform/K32W/args.gni b/src/platform/K32W/args.gni index 996410c604d0ff..45ab5013492c15 100644 --- a/src/platform/K32W/args.gni +++ b/src/platform/K32W/args.gni @@ -28,6 +28,8 @@ chip_inet_config_enable_dns_resolver = false chip_build_tests = false +chip_mdns = "platform" + mbedtls_target = "${chip_root}/third_party/k32w_sdk:mbedtls" openthread_external_mbedtls = mbedtls_target diff --git a/src/platform/K32W/gatt_db.h b/src/platform/K32W/gatt_db.h index a66845e156da50..be0976ff1bffbb 100644 --- a/src/platform/K32W/gatt_db.h +++ b/src/platform/K32W/gatt_db.h @@ -9,7 +9,7 @@ VALUE(value_device_name, gBleSig_GapDeviceName_d, (gPermissionFlagReadable_c), 1 CHARACTERISTIC(char_appearance, gBleSig_GapAppearance_d, (gGattCharPropRead_c)) VALUE(value_appearance, gBleSig_GapAppearance_d, (gPermissionFlagReadable_c), 2, 0x00, 0x00) -PRIMARY_SERVICE(service_chipoble, gBleSig_BtpService_d) +PRIMARY_SERVICE(service_chipoble, gChipoBleService_d) CHARACTERISTIC_UUID128(chipoble_rx, uuid_chipoble_rx, (gGattCharPropWrite_c)) VALUE_UUID128_VARLEN(value_chipoble_rx, uuid_chipoble_rx, (gPermissionFlagWritable_c), gAttMaxMtu_c - 3, gAttMaxMtu_c - 3, 0x00) CHARACTERISTIC_UUID128(chipoble_tx, uuid_chipoble_tx, (gGattCharPropIndicate_c | gGattCharPropRead_c)) diff --git a/src/platform/K32W/gatt_uuid128.h b/src/platform/K32W/gatt_uuid128.h index 2d61c9d128bb3e..442de5a2814186 100644 --- a/src/platform/K32W/gatt_uuid128.h +++ b/src/platform/K32W/gatt_uuid128.h @@ -19,7 +19,7 @@ */ /* Services */ -/* Wireless UART */ -UUID128(uuid_service_chipoble, 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00) +#define gChipoBleService_d 0xFFF6 + UUID128(uuid_chipoble_tx, 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18) UUID128(uuid_chipoble_rx, 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18) diff --git a/third_party/k32w_sdk/BUILD.gn b/third_party/k32w_sdk/BUILD.gn index 0987ba19420bdc..07aa2c2f1aadb3 100644 --- a/third_party/k32w_sdk/BUILD.gn +++ b/third_party/k32w_sdk/BUILD.gn @@ -40,15 +40,20 @@ config("mbedtls_k32w_config") { "MBEDTLS_THREADING_ALT=1", "MBEDTLS_X509_CSR_WRITE_C", "MBEDTLS_X509_CREATE_C", - "MBEDTLS_PK_WRITE_C", - "MBEDTLS_OID_C", "MBEDTLS_PEM_WRITE_C", - "MBEDTLS_BASE64_C", "MBEDTLS_HKDF_C", "MBEDTLS_ERROR_C", "MBEDTLS_PKCS5_C", ] + if (chip_mdns == "none") { + defines += [ + "MBEDTLS_PK_WRITE_C", + "MBEDTLS_OID_C", + "MBEDTLS_BASE64_C", + ] + } + include_dirs = [ chip_root ] } diff --git a/third_party/k32w_sdk/k32w_sdk.gni b/third_party/k32w_sdk/k32w_sdk.gni index e25b8380109e27..9e6fe692f6ea91 100644 --- a/third_party/k32w_sdk/k32w_sdk.gni +++ b/third_party/k32w_sdk/k32w_sdk.gni @@ -16,6 +16,7 @@ import("//build_overrides/k32w_sdk.gni") import("//build_overrides/mbedtls.gni") import("//build_overrides/openthread.gni") import("${chip_root}/src/crypto/crypto.gni") +import("${chip_root}/src/platform/K32W/args.gni") declare_args() { # Location of the k32w SDK. @@ -124,7 +125,7 @@ template("k32w_sdk") { "gUsePdm_d=1", "gLEDSupported_d", "gKeyBoardSupported_d", - "gPdmNbSegments=32", + "gPdmNbSegments=63", "configFRTOS_MEMORY_SCHEME=4", "osCustomStartup=1", "OM15082=1", @@ -155,6 +156,14 @@ template("k32w_sdk") { #TODO: move this define in a MBEDTLS specific GN file "MBEDTLS_FREESCALE_FREERTOS_CALLOC_ALT=1", ] + + if (chip_mdns == "platform") { + defines += [ + "OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE=1", + "OPENTHREAD_CONFIG_ECDSA_ENABLE=1", + ] + } + if (chip_with_se05x == 1) { defines += [ "MBEDTLS_FREESCALE_FREERTOS_CALLOC_ALT=1", @@ -174,6 +183,10 @@ template("k32w_sdk") { "-Wno-sign-compare", "-Wno-clobbered", "-Wno-implicit-fallthrough", + "-fno-optimize-strlen", + "-mthumb", + "-MMD", + "-MP", ] # Now add our "system-header" include dirs