Skip to content

[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

Draft
wants to merge 13 commits into
base: v1.3-branch
Choose a base branch
from

Conversation

JoeJoeChiang
Copy link

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:

thomaskang and others added 12 commits June 23, 2025 11:00
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
@CLAassistant
Copy link

CLAassistant commented Jul 11, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 3 committers have signed the CLA.

❌ github-actions
❌ JoeJoeChiang
❌ thomaskang


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.

Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 for senscomm. 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 avoiding goto.

Overall, this is a substantial contribution, but it needs significant cleanup to ensure correctness, security, and maintainability before it can be merged.

Comment on lines 56 to 63
#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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file contains hardcoded Wi-Fi credentials inside an #if 1 block. This is a significant security risk and will cause the device to always try to connect to this network, overriding any provisioned credentials. This block must be removed.

sWiFiNetworkCommissioningInstance.Init();
#endif

vTaskDelay(10000); // TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

A hardcoded 10-second delay (vTaskDelay(10000)) is present in the Init function, marked with a // TODO. This will significantly slow down device startup and should be replaced with a more robust synchronization mechanism if waiting for an event is necessary.

Comment on lines +1 to +127
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Comment on lines +42 to +51
#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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Comment on lines +31 to +165
;
}

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The entire content of this main function is disabled with an #if 0 block. The code within also refers to psoc6 platform specifics. This file should contain the correct and active entry point for the application on the senscomm platform.

Comment on lines +44 to +80
#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" ]
# }
#}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file contains a large block of commented-out code that appears to be from the psoc6 platform. To improve readability and maintainability, this unused code should be removed.

Comment on lines +80 to +81
extern "C" int (*printk)(const char *const fmt, ...);

void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
{
//KJW - test
printk("[%s, %d]\n", __func__, __LINE__);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file contains debug printk statements and comments (//KJW - test). These should be removed before merging to keep the codebase clean.

Comment on lines +62 to +64
# if (chip_enable_ota_requestor) {
# public_configs += [ ":psoc6_ota_config" ]
# }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file contains a commented-out block related to psoc6_ota_config. This appears to be a remnant from another platform and should be removed to improve code clarity.

@@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This printf statement appears to be for debugging. Please remove it and other similar debug prints throughout this function to keep the code clean.

Comment on lines +1935 to 1931
//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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of goto here makes the control flow harder to follow. While the logic to fall back to "Last Known Good Time" is reasonable, it could be restructured to avoid the goto for better readability. Consider using a boolean flag to control the flow.

Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

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:
Copy link

mergify bot commented Jul 11, 2025

⚠️ The sha of the head commit of this PR conflicts with #39956. Mergify cannot evaluate rules on this PR. ⚠️

Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants