-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[MATTER] Implement platform layer for network commissioning #39957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1.3-branch
Are you sure you want to change the base?
Conversation
JoeJoeChiang
commented
Jul 11, 2025
New features: - Include wise-sdk inside third_party as a submodule. - Support building flashable binary image for example apps such as lighting-app. Changes: Fixes: Issues: - Resolves Senscomm/wise#2812
New features: Changes: - Enable events to be delivered from wise-sdk. - Disable log redirection so that we could just use chip::Logging::Platform::LogV instead. Fixes: - Enable use of wrapper functions for vsnprintf and vsprintf which are provided by wise-sdk. Issues: - Resolves Senscomm/wise/project-chip#2816
[Platform] Deliver system event from wise-sdk
github-actions seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds platform layer support for network commissioning on the Senscomm SCM1612S. The changes are extensive and introduce a new platform, including build configurations, example applications, and platform-specific driver implementations.
My review identified several areas for improvement, primarily related to code cleanup and correctness:
- Critical Issue: There are hardcoded Wi-Fi credentials in the
NetworkCommissioningWiFiDriver.cpp
, which poses a security risk and must be removed. - High Severity Issues: Many files, particularly in the example applications, appear to be copied from the
psoc6
platform without being updated. This includes incorrect README files, wrong copyright headers, and platform-specific code that will not work forsenscomm
. The build scripts also contain incorrect application name prefixes. - Medium Severity Issues: There are several instances of debug code,
TODO
comments, and unprofessional comments that should be cleaned up. I've also pointed out some areas where code could be made more robust or readable, such as improving a macro definition and avoidinggoto
.
Overall, this is a substantial contribution, but it needs significant cleanup to ensure correctness, security, and maintainability before it can be merged.
#if 1 | ||
err = SCM1612SConfig::WriteConfigValueStr(SCM1612SConfig::kConfigKey_WiFiSSID, "ax3"); | ||
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_NO_ERROR); | ||
err = SCM1612SConfig::WriteConfigValueStr(SCM1612SConfig::kConfigKey_WiFiPSK, "12345678"); | ||
VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_NO_ERROR); | ||
uint8_t auth = 2; | ||
err = SCM1612SConfig::WriteConfigValueBin(SCM1612SConfig::kConfigKey_WiFiSEC, &auth, sizeof(auth)); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sWiFiNetworkCommissioningInstance.Init(); | ||
#endif | ||
|
||
vTaskDelay(10000); // TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
procedure. Wi-Fi Network credentials are then provided to the PSoC6 device which | ||
will then join the network. | ||
|
||
## Building | ||
|
||
- [Modustoolbox Software](https://www.cypress.com/products/modustoolbox) | ||
|
||
Refer to `integrations/docker/images/chip-build-infineon/Dockerfile` or | ||
`scripts/examples/gn_psoc6_example.sh` for downloading the Software and | ||
related tools. | ||
|
||
- Install some additional tools (likely already present for Matter | ||
developers): | ||
|
||
``` | ||
sudo apt install gcc g++ clang ninja-build python \ | ||
python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake \ | ||
python3-pip | ||
``` | ||
|
||
- Supported hardware: | ||
[CY8CKIT-062S2-43012](https://www.cypress.com/CY8CKIT-062S2-43012) | ||
|
||
* Build the example application: | ||
|
||
$ source scripts/activate.sh | ||
$ scripts/build/build_examples.py --no-log-timestamps --target 'infineon-psoc6-all-clusters' build | ||
|
||
- To delete generated executable, libraries and object files use: | ||
|
||
$ cd ~/connectedhomeip | ||
$ rm -rf out/ | ||
|
||
## Flashing the Application | ||
|
||
- Put CY8CKIT-062S2-43012 board on KitProg3 CMSIS-DAP Mode by pressing the | ||
`MODE SELECT` button. `KITPROG3 STATUS` LED is ON confirms board is in | ||
proper mode. | ||
|
||
- On the command line: | ||
|
||
$ cd ~/connectedhomeip | ||
$ python3 out/infineon-psoc6-all-clusters/chip-psoc6-clusters-example.flash.py | ||
|
||
## Commissioning and cluster control | ||
|
||
Commissioning can be carried out using BLE. | ||
|
||
### Setting up Chip tool | ||
|
||
Once PSoC6 is up and running, we need to set up chip-tool on Raspberry Pi 4 to | ||
perform commissioning and cluster control. | ||
|
||
- Set up python controller. | ||
|
||
$ cd {path-to-connectedhomeip} | ||
$ ./scripts/examples/gn_build_example.sh examples/chip-tool out/debug | ||
|
||
- Execute the controller. | ||
|
||
$ ./out/debug/chip-tool | ||
|
||
### Commissioning over BLE | ||
|
||
Run the built executable and pass it the discriminator and pairing code of the | ||
remote device, as well as the network credentials to use. | ||
|
||
$ ./out/debug/chip-tool pairing ble-wifi 1234 ${SSID} ${PASSWORD} 20202021 3840 | ||
|
||
Parameters: | ||
1. Discriminator: 3840 | ||
2. Setup-pin-code: 20202021 | ||
3. Node ID: 1234 (you can assign any node id) | ||
4. SSID : Wi-Fi SSID | ||
5. PASSWORD : Wi-Fi Password | ||
|
||
#### Notes | ||
|
||
Raspberry Pi 4 BLE connection issues can be avoided by running the following | ||
commands. These power cycle the BlueTooth hardware and disable BR/EDR mode. | ||
|
||
$ sudo btmgmt -i hci0 power off | ||
$ sudo btmgmt -i hci0 bredr off | ||
$ sudo btmgmt -i hci0 power on | ||
|
||
### Factory Reset | ||
|
||
- Commissioned Wi-Fi Credentials can be cleared by pressing `USER_BTN2` button | ||
on the board. All the data configured on the device during the initial | ||
commissioning will be deleted and device will be ready for commissioning | ||
again. | ||
|
||
- Pressing the button again within 5 seconds will cancel the factory reset of | ||
the board. | ||
|
||
## OTA Software Update | ||
|
||
For the description of Software Update process with infineon PSoC6 example | ||
applications see | ||
[Infineon PSoC6 OTA Software Update](../../../../docs/guides/infineon_psoc6_software_update.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This README file seems to be a copy from the PSoC6 platform. It contains incorrect information regarding the hardware (e.g., Infineon CY8CKIT-062S2-43012
), SDK (Modustoolbox
), and build/flash instructions. This will be very confusing for developers. Please update this file with the correct information for the senscomm/scm1612s
platform.
#include <platform/Infineon/PSOC6/NetworkCommissioningDriver.h> | ||
#include <static-supported-temperature-levels.h> | ||
|
||
/* OTA related includes */ | ||
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR | ||
#include <app/clusters/ota-requestor/BDXDownloader.h> | ||
#include <app/clusters/ota-requestor/DefaultOTARequestor.h> | ||
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h> | ||
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h> | ||
#include <platform/Infineon/PSOC6/OTAImageProcessorImpl.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file includes headers from the psoc6
platform (e.g., <platform/Infineon/PSOC6/NetworkCommissioningDriver.h>
) and has copyright headers from Cypress. This is incorrect for the senscomm
platform and will likely cause build failures or incorrect behavior.
This issue seems to be present in other files within this example directory as well. Please review all files in examples/all-clusters-app/senscomm/scm1612s/
for similar copy-paste errors from the psoc6
platform and correct them.
; | ||
} | ||
|
||
void appError(CHIP_ERROR error) | ||
{ | ||
appError(static_cast<int>(error.AsInteger())); | ||
} | ||
|
||
// ================================================================================ | ||
// FreeRTOS Callbacks | ||
// ================================================================================ | ||
extern "C" void vApplicationIdleHook(void) | ||
{ | ||
// FreeRTOS Idle callback | ||
} | ||
|
||
extern "C" void vApplicationDaemonTaskStartupHook() | ||
{ | ||
// Init Chip memory management before the stack | ||
chip::Platform::MemoryInit(); | ||
|
||
/* Create the Main task. */ | ||
xTaskCreate(main_task, "Main task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, NULL); | ||
} | ||
|
||
static void main_task(void * pvParameters) | ||
{ | ||
CHIP_ERROR ret = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(); | ||
if (ret != CHIP_NO_ERROR) | ||
{ | ||
P6_LOG("PersistedStorage::KeyValueStoreMgrImpl().Init() failed"); | ||
appError(ret); | ||
} | ||
|
||
ret = PlatformMgr().InitChipStack(); | ||
if (ret != CHIP_NO_ERROR) | ||
{ | ||
P6_LOG("PlatformMgr().InitChipStack() failed"); | ||
appError(ret); | ||
} | ||
|
||
ret = chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("P6_CLUSTERS"); | ||
if (ret != CHIP_NO_ERROR) | ||
{ | ||
P6_LOG("ConnectivityMgr().SetBLEDeviceName() failed"); | ||
appError(ret); | ||
} | ||
|
||
P6_LOG("Starting Platform Manager Event Loop"); | ||
ret = PlatformMgr().StartEventLoopTask(); | ||
if (ret != CHIP_NO_ERROR) | ||
{ | ||
P6_LOG("PlatformMgr().StartEventLoopTask() failed"); | ||
appError(ret); | ||
} | ||
ret = GetAppTask().StartAppTask(); | ||
if (ret != CHIP_NO_ERROR) | ||
{ | ||
P6_LOG("GetAppTask().Init() failed"); | ||
appError(ret); | ||
} | ||
|
||
/* Delete task */ | ||
vTaskDelete(NULL); | ||
} | ||
|
||
#endif | ||
|
||
// ================================================================================ | ||
// Main Code | ||
// ================================================================================ | ||
int main(void) | ||
{ | ||
//KJW - test | ||
#if 0 | ||
init_p6Platform(); | ||
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR | ||
// Clear watchdog timer (started by bootloader) so that it doesn't trigger a reset | ||
cyhal_wdt_t wdt_obj; | ||
cyhal_wdt_init(&wdt_obj, cyhal_wdt_get_max_timeout_ms()); | ||
cyhal_wdt_free(&wdt_obj); | ||
#endif | ||
#ifdef HEAP_MONITORING | ||
MemMonitoring::startHeapMonitoring(); | ||
#endif | ||
|
||
P6_LOG("==================================================\r\n"); | ||
P6_LOG("chip-p6-all-clusters-example starting Version %d\r\n", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION); | ||
P6_LOG("==================================================\r\n"); | ||
|
||
/* Start the FreeRTOS scheduler */ | ||
vTaskStartScheduler(); | ||
|
||
chip::Platform::MemoryShutdown(); | ||
PlatformMgr().StopEventLoopTask(); | ||
PlatformMgr().Shutdown(); | ||
|
||
// Should never get here. | ||
P6_LOG("vTaskStartScheduler() failed"); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#config("psoc6_ota_config") { | ||
# linker_script = "${psoc6_sdk_root}/ota/cy8c6xxa_cm4_dual_ota_int.ld" | ||
# | ||
# ldflags = [ "-T" + rebase_path(linker_script, root_build_dir) ] | ||
# | ||
# ldflags += [ "-Wl,--defsym,MCUBOOT_HEADER_SIZE=0x400,--defsym,MCUBOOT_BOOTLOADER_SIZE=0x18000,--defsym,CY_BOOT_PRIMARY_1_SIZE=0x1C0000" ] | ||
# | ||
# defines = [ | ||
# "P6_OTA", | ||
# "OTA_SUPPORT ", | ||
# "OTA_USE_EXTERNAL_FLASH", | ||
# "CY_BOOT_USE_EXTERNAL_FLASH", | ||
# "MCUBOOT_HEADER_SIZE=0x400", | ||
# "MCUBOOT_MAX_IMG_SECTORS=3584", | ||
# "CY_BOOT_SCRATCH_SIZE=0x00004000", | ||
# "MCUBOOT_BOOTLOADER_SIZE=0x00018000", | ||
# "CY_BOOT_BOOTLOADER_SIZE=0x00018000", | ||
# "CY_BOOT_PRIMARY_1_START=0x00018000", | ||
# "CY_BOOT_PRIMARY_1_SIZE=0x1C0000", | ||
# "CY_BOOT_SECONDARY_1_START=0x00000000", | ||
# "CY_BOOT_SECONDARY_1_SIZE=0x001C0000", | ||
# "CY_FLASH_ERASE_VALUE=0xFF", | ||
# "MCUBOOT_IMAGE_NUMBER=1", | ||
# "MCUBOOT_SLOT_SIZE=0x1C0000", | ||
# "MCUBOOT_SCRATCH_SIZE=0x4000", | ||
# "MCUBOOT_SECTOR_SIZE = 512", | ||
# "APP_VERSION_MAJOR=1", | ||
# "APP_VERSION_MINOR=0", | ||
# "APP_VERSION_BUILD=0", | ||
# "MCUBOOT_OVERWRITE_ONLY", | ||
# "CY_ENABLE_XIP_PROGRAM", | ||
# ] | ||
# | ||
# if (build_update_image) { | ||
# defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=2" ] | ||
# } | ||
#} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extern "C" int (*printk)(const char *const fmt, ...); | ||
|
||
void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) | ||
{ | ||
//KJW - test | ||
printk("[%s, %d]\n", __func__, __LINE__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# if (chip_enable_ota_requestor) { | ||
# public_configs += [ ":psoc6_ota_config" ] | ||
# } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1596,6 +1596,8 @@ CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg) | |||
MATTER_TRACE_COUNTER("Sigma3"); | |||
|
|||
auto helper = WorkHelper<HandleSigma3Data>::Create(*this, &HandleSigma3b, &CASESession::HandleSigma3c); | |||
|
|||
printf("!!!!!!HandleSigma3a 1\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//ReturnErrorOnFailure(mValidContext.SetEffectiveTimeFromUnixTime<CurrentChipEpochTime>(currentUnixTime)); | ||
err = mValidContext.SetEffectiveTimeFromUnixTime<CurrentChipEpochTime>(currentUnixTime); | ||
if (err == CHIP_ERROR_INVALID_TIME) | ||
goto try_again; | ||
else | ||
return err; | ||
} | ||
else | ||
{ | ||
try_again: | ||
// If we don't have wall clock time, the spec dictates that we should | ||
// fall back to Last Known Good Time. Ultimately, the calling application's | ||
// validity policy will determine whether this is permissible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
|
|
New features: - implement SCM1612SConfig, KeyValueStoreManagerImpl - implement softAP - implement scm connectivity related functions - implement NetworkCommissioningWiFiDriver.cpp - change _IsWiFiStationProvisioned to use FS check - update NetworkCommissioning - update ConnectWiFiNetwork - refine got ip event - support minimal mdns - fix ecdsa not support issue Changes: Fixes: Issues:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not platform layer bits. Why is this hidden inside this PR?