Skip to content

Commit

Permalink
Clear FabricID during factory reset for Infineon P6 Platform (#14483)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenCY authored and pull[bot] committed Aug 4, 2023
1 parent 179655c commit 4257127
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 115 deletions.
46 changes: 13 additions & 33 deletions examples/all-clusters-app/p6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Setting up Python Controller](#setting-up-python-controller)
- [Setting up chip-tool](#setting-up-chip-tool)
- [Commissioning over BLE](#commissioning-over-ble)
- [Notes](#notes)

Expand Down Expand Up @@ -74,57 +74,37 @@ will then join the network.

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>
<a name="Setting up chip-tool"></a>

### Setting up Python Controller
### Setting up Chip tool

Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.
Once P6 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/build_python.sh -m platform
$ ./scripts/examples/gn_build_example.sh examples/chip-tool out/debug

- Execute the controller.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl
$ ./out/debug/chip-tool

<a name="Commissioning over BLE"></a>

### Commissioning over BLE

- Establish the secure session 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.

- chip-device-ctrl > ble-scan
- chip-device-ctrl > connect -ble 3840 20202021 1234
$ ./out/debug/chip-tool pairing ble-wifi 1234 ${SSID} ${PASSWORD} 20202021 3840

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: Optional.
If not passed in this command, then it is auto-generated by the controller and
displayed in the output of connect.
The same value should be used in the next commands.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddOrUpdateWiFiNetwork` command and then enable the P6 to connect to it
using `EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID`
and `WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddOrUpdateWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0

- chip-device-ctrl > zcl NetworkCommissioning ConnectNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0

- Close the BLE connection to P6, as it is not required hereafter.

- chip-device-ctrl > close-ble

- Resolve DNS-SD name and update address of the node in the device controller.

- chip-device-ctrl > resolve 1234
3. Node ID: 1234 (you can assign any node id)
4. SSID : Wi-Fi SSID
5. PASSWORD : Wi-Fi Password

<a name="Notes"></a>

Expand Down
50 changes: 15 additions & 35 deletions examples/lighting-app/p6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Setting up Python Controller](#setting-up-python-controller)
- [Setting up chip-tool](#setting-up-chip-tool)
- [Commissioning over BLE](#commissioning-over-ble)
- [Notes](#notes)
- [Cluster control](#cluster-control)
Expand Down Expand Up @@ -75,57 +75,37 @@ will then join the network.

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>
<a name="Setting up chip-tool"></a>

### Setting up Python Controller
### Setting up Chip tool

Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.
Once P6 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/build_python.sh -m platform
$ ./scripts/examples/gn_build_example.sh examples/chip-tool out/debug

- Execute the controller.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl
$ ./out/debug/chip-tool

<a name="Commissioning over BLE"></a>

### Commissioning over BLE

- Establish the secure session 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.

- chip-device-ctrl > ble-scan
- chip-device-ctrl > connect -ble 3840 20202021 1234
$ ./out/debug/chip-tool pairing ble-wifi 1234 ${SSID} ${PASSWORD} 20202021 3840

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: Optional.
If not passed in this command, then it is auto-generated by the controller and
displayed in the output of connect.
The same value should be used in the next commands.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddOrUpdateWiFiNetwork` command and then enable the P6 to connect to it
using `EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID`
and `WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddOrUpdateWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0

- chip-device-ctrl > zcl NetworkCommissioning ConnectNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0

- Close the BLE connection to P6, as it is not required hereafter.

- chip-device-ctrl > close-ble

- Resolve DNS-SD name and update address of the node in the device controller.

- chip-device-ctrl > resolve 1234
3. Node ID: 1234 (you can assign any node id)
4. SSID : Wi-Fi SSID
5. PASSWORD : Wi-Fi Password

<a name="Notes"></a>

Expand All @@ -145,9 +125,9 @@ commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.
- After successful commissioning, use the OnOff cluster command to toggle
device between On or Off states.

`chip-device-ctrl > zcl OnOff Off 1234 1 0`
`$ ./out/debug/chip-tool onoff on 1234 1`

`chip-device-ctrl > zcl OnOff On 1234 1 0`
`$ ./out/debug/chip-tool onoff off 1234 1`

- Cluster OnOff can also be done using the `USER_BTN1` button on the board.
This button is configured with `APP_LIGHT_BUTTON` in `include/AppConfig.h`.
Expand Down
60 changes: 15 additions & 45 deletions examples/lock-app/p6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Commissioning and cluster control](#commissioning-and-cluster-control)
- [Setting up Python Controller](#setting-up-python-controller)
- [Setting up chip-tool](#setting-up-chip-tool)
- [Commissioning over BLE](#commissioning-over-ble)
- [Notes](#notes)
- [Cluster control](#cluster-control)
Expand Down Expand Up @@ -49,11 +49,6 @@ will then join the network.

* Build the example application:

$ cd ~/connectedhomeip
$ ./gn_build.sh enable_p6_builds=true

Or Using P6 build script

$ ./scripts/examples/gn_p6_example.sh examples/lock-app/p6 out/lock_app_p6

- To delete generated executable, libraries and object files use:
Expand All @@ -71,11 +66,6 @@ will then join the network.

- On the command line:

$ cd ~/connectedhomeip
$ python3 out/debug/p6_lock_app/chip-p6-lock-example.flash.py

Or when using P6 Build script

$ cd ~/connectedhomeip
$ python3 out/lock_app_p6/chip-p6-lock-example.flash.py

Expand All @@ -85,57 +75,37 @@ will then join the network.

Commissioning can be carried out using BLE.

<a name="Setting up Python Controller"></a>
<a name="Setting up chip-tool"></a>

### Setting up Python Controller
### Setting up Chip tool

Once P6 is up and running, we need to set up a device controller on Raspberry Pi
4 to perform commissioning and cluster control.
Once P6 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/build_python.sh -m platform
$ ./scripts/examples/gn_build_example.sh examples/chip-tool out/debug

- Execute the controller.

$ source ./out/python_env/bin/activate
$ chip-device-ctrl
$ ./out/debug/chip-tool

<a name="Commissioning over BLE"></a>

### Commissioning over BLE

- Establish the secure session 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.

- chip-device-ctrl > ble-scan
- chip-device-ctrl > connect -ble 3840 20202021 1234
$ ./out/debug/chip-tool pairing ble-wifi 1234 ${SSID} ${PASSWORD} 20202021 3840

Parameters:
1. Discriminator: 3840
2. Setup-pin-code: 20202021
3. Node ID: Optional.
If not passed in this command, then it is auto-generated by the controller and
displayed in the output of connect.
The same value should be used in the next commands.
We have chosen a random node ID which is 1234.

- Add credentials of the Wi-Fi network you want the P6 to connect to, using
the `AddOrUpdateWiFiNetwork` command and then enable the P6 to connect to it
using `EnableWiFiNetwork` command. In this example, we have used `WIFI_SSID`
and `WIFI_PASSWORD` as the SSID and passphrase respectively.

- chip-device-ctrl > zcl NetworkCommissioning AddOrUpdateWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0

- chip-device-ctrl > zcl NetworkCommissioning ConnectNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0

- Close the BLE connection to P6, as it is not required hereafter.

- chip-device-ctrl > close-ble

- Resolve DNS-SD name and update address of the node in the device controller.

- chip-device-ctrl > resolve 1234
3. Node ID: 1234 (you can assign any node id)
4. SSID : Wi-Fi SSID
5. PASSWORD : Wi-Fi Password

<a name="Notes"></a>

Expand All @@ -155,9 +125,9 @@ commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.
- After successful commissioning, use the OnOff cluster command to toggle
device between On or Off states.

`chip-device-ctrl > zcl OnOff Off 1234 1 0`
`$ ./out/debug/chip-tool onoff on 1234 1`

`chip-device-ctrl > zcl OnOff On 1234 1 0`
`$ ./out/debug/chip-tool onoff off 1234 1`

- Cluster OnOff can also be done using the `USER_BTN1` button on the board.
This button is configured with `APP_LOCK_BUTTON` in `include/AppConfig.h`.
Expand Down
1 change: 0 additions & 1 deletion examples/platform/p6/LEDWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ void LEDWidget::SetBrightness(uint32_t led_brightness)
{
printf("PWM failed to set dutycycle!");
}
PWM_start();
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/platform/P6/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ CHIP_ERROR KeyValueStoreManagerImpl::ConvertCyResultToChip(cy_rslt_t err) const
return CHIP_ERROR_INTERNAL;
}

CHIP_ERROR KeyValueStoreManagerImpl::Erase(void)
{
if (!init_success)
{
return CHIP_ERROR_WELL_UNINITIALIZED;
}

cy_rslt_t result = mtb_kvstore_reset(&kvstore_obj);
return ConvertCyResultToChip(result);
}
} // namespace PersistedStorage
} // namespace DeviceLayer
} // namespace chip
1 change: 1 addition & 0 deletions src/platform/P6/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager
CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0) const;
CHIP_ERROR _Delete(const char * key);
CHIP_ERROR _Put(const char * key, const void * value, size_t value_size);
CHIP_ERROR Erase(void);

private:
// ===== Members for internal use by the following friends.
Expand Down
10 changes: 9 additions & 1 deletion src/platform/P6/P6Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,29 @@ bool P6Config::ConfigValueExists(Key key)
// Clear out keys in config namespace
CHIP_ERROR P6Config::FactoryResetConfig(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
const Key * config_keys[] = { &kConfigKey_FabricId, &kConfigKey_ServiceConfig, &kConfigKey_PairedAccountId,
&kConfigKey_ServiceId, &kConfigKey_GroupKeyIndex, &kConfigKey_LastUsedEpochKeyId,
&kConfigKey_FailSafeArmed, &kConfigKey_WiFiStationSecType, &kConfigKey_WiFiSSID,
&kConfigKey_WiFiPassword, &kConfigKey_WiFiSecurity, &kConfigKey_WiFiMode };

for (uint32_t i = 0; i < (sizeof(config_keys) / sizeof(config_keys[0])); i++)
{
CHIP_ERROR err = ClearConfigValue(*config_keys[i]);
err = ClearConfigValue(*config_keys[i]);
// Something unexpected happened
if (err != CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND && err != CHIP_NO_ERROR)
{
return err;
}
}

// Erase all key-values including fabric info.
err = PersistedStorage::KeyValueStoreMgrImpl().Erase();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Clear Key-Value Storage failed");
}

return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 4257127

Please sign in to comment.