فهرست منبع

Add Lock app example for infineon P6 board (#8268)

* Add Lock app example for infineon P6 board

* P6 lock app changes addressing review comments

* Update Code changes to support new Clock modifications

* Rename repo to p6_sdk along with docker vscode changes

* Update README.md with dockerfile link for software download

* Remove warnings false check for compile

* Update script to remove sudo and cleanup folder names

* Add all Infineon assets as gitsubmodules

* Address review comments cleaning up code

* Cleanup code as per final review comments

* Address BLE configuration comments
Praveen Chandran 4 سال پیش
والد
کامیت
080ae577da
100فایلهای تغییر یافته به همراه11422 افزوده شده و 4 حذف شده
  1. 64 0
      .gitmodules
  2. 15 0
      BUILD.gn
  3. 18 0
      build_overrides/p6.gni
  4. 25 0
      config/p6/toolchain/BUILD.gn
  5. 18 0
      examples/build_overrides/p6.gni
  6. 28 0
      examples/lock-app/p6/.gn
  7. 100 0
      examples/lock-app/p6/BUILD.gn
  8. 166 0
      examples/lock-app/p6/README.md
  9. 20 0
      examples/lock-app/p6/args.gni
  10. 1 0
      examples/lock-app/p6/build_overrides
  11. 68 0
      examples/lock-app/p6/include/AppConfig.h
  12. 56 0
      examples/lock-app/p6/include/AppEvent.h
  13. 93 0
      examples/lock-app/p6/include/AppTask.h
  14. 84 0
      examples/lock-app/p6/include/BoltLockManager.h
  15. 39 0
      examples/lock-app/p6/include/ButtonHandler.h
  16. 111 0
      examples/lock-app/p6/include/CHIPProjectConfig.h
  17. 500 0
      examples/lock-app/p6/src/AppTask.cpp
  18. 225 0
      examples/lock-app/p6/src/BoltLockManager.cpp
  19. 95 0
      examples/lock-app/p6/src/ButtonHandler.cpp
  20. 79 0
      examples/lock-app/p6/src/ZclCallbacks.cpp
  21. 114 0
      examples/lock-app/p6/src/main.cpp
  22. 1 0
      examples/lock-app/p6/third_party/connectedhomeip
  23. 22 0
      examples/platform/p6/BUILD.gn
  24. 83 0
      examples/platform/p6/LEDWidget.cpp
  25. 44 0
      examples/platform/p6/LEDWidget.h
  26. 21 0
      examples/platform/p6/args.gni
  27. 57 0
      examples/platform/p6/init_p6Platform.cpp
  28. 21 0
      examples/platform/p6/init_p6Platform.h
  29. 18 0
      gn_build.sh
  30. 23 0
      integrations/docker/images/chip-build-infineon/Dockerfile
  31. 1 0
      integrations/docker/images/chip-build-infineon/build.sh
  32. 1 0
      integrations/docker/images/chip-build-infineon/run.sh
  33. 1 0
      integrations/docker/images/chip-build-infineon/version
  34. 4 0
      integrations/docker/images/chip-build-vscode/Dockerfile
  35. 1 1
      integrations/docker/images/chip-build/version
  36. 50 0
      scripts/examples/gn_p6_example.sh
  37. 150 0
      scripts/flashing/p6_firmware_utils.py
  38. 7 1
      src/lwip/BUILD.gn
  39. 90 0
      src/lwip/p6/arch/cc.h
  40. 26 0
      src/lwip/p6/arch/perf.h
  41. 208 0
      src/lwip/p6/lwipopts.h
  42. 17 0
      src/lwip/p6/lwippools.h
  43. 7 0
      src/platform/BUILD.gn
  44. 918 0
      src/platform/P6/BLEManagerImpl.cpp
  45. 179 0
      src/platform/P6/BLEManagerImpl.h
  46. 73 0
      src/platform/P6/BUILD.gn
  47. 40 0
      src/platform/P6/BlePlatformConfig.h
  48. 45 0
      src/platform/P6/CHIPDevicePlatformConfig.h
  49. 71 0
      src/platform/P6/CHIPDevicePlatformEvent.h
  50. 76 0
      src/platform/P6/CHIPPlatformConfig.h
  51. 128 0
      src/platform/P6/ConfigurationManagerImpl.cpp
  52. 97 0
      src/platform/P6/ConfigurationManagerImpl.h
  53. 696 0
      src/platform/P6/ConnectivityManagerImpl.cpp
  54. 212 0
      src/platform/P6/ConnectivityManagerImpl.h
  55. 62 0
      src/platform/P6/DeviceNetworkProvisioningDelegateImpl.cpp
  56. 43 0
      src/platform/P6/DeviceNetworkProvisioningDelegateImpl.h
  57. 80 0
      src/platform/P6/Entropy.cpp
  58. 34 0
      src/platform/P6/InetPlatformConfig.h
  59. 175 0
      src/platform/P6/KeyValueStoreManagerImpl.cpp
  60. 82 0
      src/platform/P6/KeyValueStoreManagerImpl.h
  61. 47 0
      src/platform/P6/Logging.cpp
  62. 61 0
      src/platform/P6/LwIPCoreLock.cpp
  63. 108 0
      src/platform/P6/MTBKeyValueStore.cpp
  64. 37 0
      src/platform/P6/MTBKeyValueStore.h
  65. 241 0
      src/platform/P6/P6Config.cpp
  66. 144 0
      src/platform/P6/P6Config.h
  67. 677 0
      src/platform/P6/P6Utils.cpp
  68. 105 0
      src/platform/P6/P6Utils.h
  69. 64 0
      src/platform/P6/PlatformManagerImpl.cpp
  70. 89 0
      src/platform/P6/PlatformManagerImpl.h
  71. 38 0
      src/platform/P6/SoftwareUpdateManagerImpl.cpp
  72. 89 0
      src/platform/P6/SoftwareUpdateManagerImpl.h
  73. 56 0
      src/platform/P6/SystemPlatformConfig.h
  74. 39 0
      src/platform/P6/WarmPlatformConfig.h
  75. 99 0
      src/platform/P6/app_platform_cfg.c
  76. 52 0
      src/platform/P6/app_platform_cfg.h
  77. 32 0
      src/platform/P6/args.gni
  78. 15 0
      src/platform/P6/cy_wcm.h
  79. 298 0
      src/platform/P6/cycfg_bt_settings.cpp
  80. 11 0
      src/platform/P6/cycfg_bt_settings.h
  81. 29 0
      src/platform/P6/cycfg_gap.cpp
  82. 103 0
      src/platform/P6/cycfg_gap.h
  83. 117 0
      src/platform/P6/cycfg_gatt_db.c
  84. 95 0
      src/platform/P6/cycfg_gatt_db.h
  85. 7 0
      src/platform/P6/ethernet.h
  86. 5 2
      src/platform/device.gni
  87. 82 0
      third_party/p6/BUILD.gn
  88. 21 0
      third_party/p6/p6_arm.gni
  89. 26 0
      third_party/p6/p6_board.gni
  90. 55 0
      third_party/p6/p6_executable.gni
  91. 102 0
      third_party/p6/p6_sdk.gni
  92. 148 0
      third_party/p6/p6_sdk/.gitignore
  93. 236 0
      third_party/p6/p6_sdk/Makefile
  94. 506 0
      third_party/p6/p6_sdk/build/CY8CKIT-062S2-43012/Debug/GCC_ARM.json
  95. 506 0
      third_party/p6/p6_sdk/build/CY8CKIT-062S2-43012/Release/GCC_ARM.json
  96. 199 0
      third_party/p6/p6_sdk/configs/FreeRTOSConfig.h
  97. 148 0
      third_party/p6/p6_sdk/configs/iot_config.h
  98. 725 0
      third_party/p6/p6_sdk/configs/mbedtls_user_config.h
  99. 161 0
      third_party/p6/p6_sdk/configs/mqtt_client_config.h
  100. 66 0
      third_party/p6/p6_sdk/configs/wifi_config.h

+ 64 - 0
.gitmodules

@@ -95,3 +95,67 @@
 	path = third_party/mbed-os-posix-socket/repo
 	url = https://github.com/ARMmbed/mbed-os-posix-socket.git
 	branch = main
+[submodule "p6/abstraction-rtos"]
+	path = third_party/p6/p6_sdk/libs/abstraction-rtos
+	url = https://github.com/Infineon/abstraction-rtos
+[submodule "p6/bluetooth-freertos"]
+	path = third_party/p6/p6_sdk/libs/bluetooth-freertos
+	url = https://github.com/Infineon/bluetooth-freertos
+	branch = v2.X
+[submodule "p6/btstack"]
+	path = third_party/p6/p6_sdk/libs/btstack
+	url = https://github.com/Infineon/btstack
+[submodule "p6/clib-support"]
+	path = third_party/p6/p6_sdk/libs/clib-support
+	url = https://github.com/Infineon/clib-support
+[submodule "p6/connectivity-utilities"]
+	path = third_party/p6/p6_sdk/libs/connectivity-utilities
+	url = https://github.com/Infineon/connectivity-utilities
+[submodule "p6/core-lib"]
+	path = third_party/p6/p6_sdk/libs/core-lib
+	url = https://github.com/Infineon/core-lib
+[submodule "p6/core-make"]
+	path = third_party/p6/p6_sdk/libs/core-make
+	url = https://github.com/Infineon/core-make
+[submodule "p6/kv-store"]
+	path = third_party/p6/p6_sdk/libs/kv-store
+	url = https://github.com/Infineon/kv-store
+[submodule "p6/mtb-hal-cat1"]
+	path = third_party/p6/p6_sdk/libs/mtb-hal-cat1
+	url = https://github.com/Infineon/mtb-hal-cat1
+[submodule "p6/mtb-pdl-cat1"]
+	path = third_party/p6/p6_sdk/libs/mtb-pdl-cat1
+	url = https://github.com/Infineon/mtb-pdl-cat1
+[submodule "p6/psoc6cm0p"]
+	path = third_party/p6/p6_sdk/libs/psoc6cm0p
+	url = https://github.com/Infineon/psoc6cm0p
+[submodule "p6/whd-bsp-integration"]
+	path = third_party/p6/p6_sdk/libs/whd-bsp-integration
+	url = https://github.com/Infineon/whd-bsp-integration
+[submodule "p6/wifi-connection-manager"]
+	path = third_party/p6/p6_sdk/libs/wifi-connection-manager
+	url = https://github.com/Infineon/wifi-connection-manager
+[submodule "p6/wifi-host-driver"]
+	path = third_party/p6/p6_sdk/libs/wifi-host-driver
+	url = https://github.com/Infineon/wifi-host-driver
+[submodule "p6/wifi-mw-core"]
+	path = third_party/p6/p6_sdk/libs/wifi-mw-core
+	url = https://github.com/Infineon/wifi-mw-core
+[submodule "p6/TARGET_CY8CKIT-062S2-43012"]
+	path = third_party/p6/p6_sdk/libs/TARGET_CY8CKIT-062S2-43012
+	url = https://github.com/Infineon/TARGET_CY8CKIT-062S2-43012
+[submodule "p6/freertos"]
+	path = third_party/p6/p6_sdk/libs/freertos
+	url = https://github.com/Infineon/freertos
+[submodule "p6/retarget-io"]
+	path = third_party/p6/p6_sdk/libs/retarget-io
+	url = https://github.com/Infineon/retarget-io
+[submodule "p6/mbedtls"]
+	path = third_party/p6/p6_sdk/libs/mbedtls
+	url = https://github.com/ARMmbed/mbedtls
+[submodule "p6/secure-sockets"]
+	path = third_party/p6/p6_sdk/libs/secure-sockets
+	url = https://github.com/Infineon/secure-sockets
+[submodule "p6/recipe-make-cat1a"]
+	path = third_party/p6/p6_sdk/libs/recipe-make-cat1a
+	url = https://github.com/Infineon/recipe-make-cat1a

+ 15 - 0
BUILD.gn

@@ -169,6 +169,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
     # Set this to true to enable efr32 builds by default.
     enable_efr32_builds = false
 
+    # Set this to true to enable p6 builds by default.
+    enable_p6_builds = false
+
     # Set this to true to enable Qorvo qpg builds by default.
     enable_qpg_builds = false
 
@@ -227,6 +230,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
     # Build the efr32 lock app example.
     enable_efr32_lock_app_build = enable_efr32_builds
 
+    # Build the p6 lock app example.
+    enable_p6_lock_app_build = enable_p6_builds
+
     # Build the qpgxxxx lock app example.
     enable_qpg_lock_app_build = enable_qpg_builds && !is_debug
 
@@ -359,6 +365,12 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
     }
   }
 
+  if (enable_p6_lock_app_build) {
+    group("p6_lock_app") {
+      deps = [ "${chip_root}/examples/lock-app/p6(${chip_root}/config/p6/toolchain:p6_lock_app)" ]
+    }
+  }
+
   if (enable_qpg_lock_app_build) {
     group("qpg_lock_app") {
       deps = [ "${chip_root}/examples/lock-app/qpg(${chip_root}/config/qpg/toolchain:qpg_lock_app)" ]
@@ -450,6 +462,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
     if (enable_efr32_window_app_build) {
       deps += [ ":efr32_window_app" ]
     }
+    if (enable_p6_lock_app_build) {
+      deps += [ ":p6_lock_app" ]
+    }
     if (enable_k32w_lighting_app_build) {
       deps += [ ":k32w_lighting_app" ]
     }

+ 18 - 0
build_overrides/p6.gni

@@ -0,0 +1,18 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+declare_args() {
+  # Root directory for p6 SDK build files.
+  p6_sdk_build_root = "//third_party/p6"
+}

+ 25 - 0
config/p6/toolchain/BUILD.gn

@@ -0,0 +1,25 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+
+import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
+
+arm_toolchain("p6_lock_app") {
+  toolchain_args = {
+    current_os = "freertos"
+    import("${chip_root}/examples/lock-app/p6/args.gni")
+  }
+}

+ 18 - 0
examples/build_overrides/p6.gni

@@ -0,0 +1,18 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+declare_args() {
+  # Root directory for P6 SDK.
+  p6_sdk_build_root = "//third_party/connectedhomeip/third_party/p6"
+}

+ 28 - 0
examples/lock-app/p6/.gn

@@ -0,0 +1,28 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+
+# The location of the build configuration file.
+buildconfig = "${build_root}/config/BUILDCONFIG.gn"
+
+# CHIP uses angle bracket includes.
+check_system_includes = true
+
+default_args = {
+  target_cpu = "arm"
+  target_os = "freertos"
+
+  import("//args.gni")
+}

+ 100 - 0
examples/lock-app/p6/BUILD.gn

@@ -0,0 +1,100 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+import("//build_overrides/p6.gni")
+
+import("${build_root}/config/defaults.gni")
+import("${p6_sdk_build_root}/p6_executable.gni")
+import("${p6_sdk_build_root}/p6_sdk.gni")
+
+assert(current_os == "freertos")
+
+p6_project_dir = "${chip_root}/examples/lock-app/p6"
+examples_plat_dir = "${chip_root}/examples/platform/p6"
+
+declare_args() {
+  # Dump memory usage at link time.
+  chip_print_memory_usage = false
+
+  # PIN code for PASE session establishment.
+  setup_pin_code = 20202021
+}
+
+p6_sdk_sources("lock_app_sdk_sources") {
+  include_dirs = [
+    "${chip_root}/src/platform/P6",
+    "${p6_project_dir}/include",
+    "${examples_plat_dir}",
+  ]
+
+  defines = [
+    "BOARD_ID=${p6_board}",
+    "P6_LOG_ENABLED=1",
+    "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setup_pin_code}",
+  ]
+
+  sources = [ "${p6_project_dir}/include/CHIPProjectConfig.h" ]
+
+  public_configs = [ "${chip_root}/third_party/p6:p6_sdk_config" ]
+}
+
+p6_executable("lock_app") {
+  include_dirs = []
+  defines = []
+  output_name = "chip-p6-lock-example.out"
+
+  public_deps = [
+    ":lock_app_sdk_sources",
+    "${chip_root}/examples/common/QRCode",
+    "${chip_root}/examples/lock-app/lock-common",
+    "${chip_root}/src/lib",
+    "${chip_root}/src/setup_payload",
+  ]
+
+  include_dirs += [
+    "include",
+    "${examples_plat_dir}",
+    "${p6_project_dir}/include",
+  ]
+
+  sources = [
+    "${examples_plat_dir}/LEDWidget.cpp",
+    "${examples_plat_dir}/init_p6Platform.cpp",
+    "${p6_project_dir}/include/CHIPProjectConfig.h",
+    "src/AppTask.cpp",
+    "src/BoltLockManager.cpp",
+    "src/ButtonHandler.cpp",
+    "src/ZclCallbacks.cpp",
+    "src/main.cpp",
+  ]
+
+  output_dir = root_out_dir
+
+  if (chip_print_memory_usage) {
+    ldflags = [
+      "-Wl,--print-memory-usage",
+      "-fstack-usage",
+    ]
+  }
+}
+
+group("p6") {
+  deps = [ ":lock_app" ]
+}
+
+group("default") {
+  deps = [ ":p6" ]
+}

+ 166 - 0
examples/lock-app/p6/README.md

@@ -0,0 +1,166 @@
+# Matter P6 Lock Example
+
+An example showing the use of Matter on the Infineon CY8CKIT-062S2-43012 board.
+
+<hr>
+
+-   [Matter P6 Lock Example](#chip-p6-lock-example)
+    -   [Introduction](#introduction)
+    -   [Building](#building)
+    -   [Flashing the Application](#flashing-the-application)
+    -   [Commissioning and cluster control](#commissioning-and-cluster-control)
+        -   [Setting up Python Controller](#setting-up-python-controller)
+        -   [Commissioning over BLE](#commissioning-over-ble)
+            -   [Notes](#notes)
+        -   [Cluster control](#cluster-control)
+
+<hr>
+
+<a name="intro"></a>
+
+## Introduction
+
+The P6 lock example provides a demonstration of a door lock control device,
+built using Matter and the Infineon Modustoolbox SDK. It can be controlled by a
+Matter controller over Wi-Fi network.
+
+The P6 device can be commissioned over Bluetooth Low Energy where the device and
+the Matter controller will exchange security information with the Rendezvous
+procedure. Wi-Fi Network credentials are then provided to the P6 device which
+will then join the network.
+
+<a name="building"></a>
+
+## Building
+
+-   [Modustoolbox Software](https://www.cypress.com/products/modustoolbox)
+
+    Refer to `integrations/docker/images/chip-build-infineon/Dockerfile` or
+    `scripts/examples/gn_p6_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:
+
+          $ cd ~/connectedhomeip
+          $ ./gn_build.sh enable_p6_builds=true
+
+    Or Using P6 build script
+
+          $ ./scripts/examples/gn_p6_example.sh examples/lock-app/p6
+
+-   To delete generated executable, libraries and object files use:
+
+          $ cd ~/connectedhomeip
+          $ rm -rf out/
+
+<a name="flashing"></a>
+
+## 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/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
+
+<a name="Commissioning and cluster control"></a>
+
+## Commissioning and cluster control
+
+Commissioning can be carried out using BLE.
+
+<a name="Setting up Python Controller"></a>
+
+### Setting up Python Controller
+
+Once P6 is up and running, we need to set up a device controller on Raspberry Pi
+4 to perform commissioning and cluster control.
+
+-   Set up python controller.
+
+           $ cd {path-to-connectedhomeip}
+           $ ./scripts/build_python.sh -m platform
+
+-   Execute the controller.
+
+           $ source ./out/python_env/bin/activate
+           $ chip-device-ctrl
+
+<a name="Commissioning over BLE"></a>
+
+### Commissioning over BLE
+
+-   Establish the secure session over BLE.
+
+         - chip-device-ctrl > ble-scan
+         - chip-device-ctrl > connect -ble 3840 20202021 1234
+
+         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 `AddWiFiNetwork` 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 AddWiFiNetwork 1234 0 0 ssid=str:WIFI_SSID credentials=str:WIFI_PASSWORD breadcrumb=0 timeoutMs=1000
+
+         - chip-device-ctrl > zcl NetworkCommissioning EnableNetwork 1234 0 0 networkID=str:WIFI_SSID breadcrumb=0 timeoutMs=1000
+
+-   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 0 1234
+
+<a name="Notes"></a>
+
+#### 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
+
+<a name="Cluster control"></a>
+
+### Cluster control
+
+-   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`
+
+    `chip-device-ctrl > zcl OnOff On 1234 1 0`
+
+-   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`.
+    Press `USER_BTN1` on the board to toggle between lock and unlock states. The
+    Lock/Unlock status of door can be observed with 'LED9' on the board. This
+    LED is configured with `LOCK_STATE_LED` in `include/AppConfig.h`.

+ 20 - 0
examples/lock-app/p6/args.gni

@@ -0,0 +1,20 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/pigweed.gni")
+import("${chip_root}/src/platform/P6/args.gni")
+
+p6_target_project =
+    get_label_info(":lock_app_sdk_sources", "label_no_toolchain")

+ 1 - 0
examples/lock-app/p6/build_overrides

@@ -0,0 +1 @@
+../../build_overrides/

+ 68 - 0
examples/lock-app/p6/include/AppConfig.h

@@ -0,0 +1,68 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include "cybsp.h"
+#include "cyhal.h"
+
+// ---- Lock Example App Config ----
+
+#define APP_TASK_NAME "APP"
+
+#define APP_LOCK_BUTTON_IDX 0
+#define APP_FUNCTION_BUTTON_IDX 1
+
+#define APP_LOCK_BUTTON CYBSP_USER_BTN1
+#define APP_FUNCTION_BUTTON CYBSP_USER_BTN2
+#define APP_BUTTON_DEBOUNCE_PERIOD_MS 50
+
+#define APP_BUTTON_PRESSED 0
+#define APP_BUTTON_RELEASED 1
+
+#define SYSTEM_STATE_LED CYBSP_USER_LED1
+#define LOCK_STATE_LED CYBSP_USER_LED2
+
+// Time it takes in ms for the simulated actuator to move from one
+// state to another.
+#define ACTUATOR_MOVEMENT_PERIOS_MS 2000
+
+// ---- Lock Example SWU Config ----
+#define SWU_INTERVAl_WINDOW_MIN_MS (23 * 60 * 60 * 1000) // 23 hours
+#define SWU_INTERVAl_WINDOW_MAX_MS (24 * 60 * 60 * 1000) // 24 hours
+
+// ---- Thread Polling Config ----
+#define THREAD_ACTIVE_POLLING_INTERVAL_MS 100
+#define THREAD_INACTIVE_POLLING_INTERVAL_MS 1000
+
+// P6 Logging
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void appError(int err);
+void P6Log(const char * aFormat, ...);
+#define P6_LOG(...) P6Log(__VA_ARGS__)
+
+#ifdef __cplusplus
+}
+
+#include <core/CHIPError.h>
+void appError(CHIP_ERROR error);
+#endif

+ 56 - 0
examples/lock-app/p6/include/AppEvent.h

@@ -0,0 +1,56 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+struct AppEvent;
+typedef void (*EventHandler)(AppEvent *);
+
+struct AppEvent
+{
+    enum AppEventTypes
+    {
+        kEventType_Button = 0,
+        kEventType_Timer,
+        kEventType_Lock,
+        kEventType_Install,
+    };
+
+    uint16_t Type;
+
+    union
+    {
+        struct
+        {
+            uint8_t ButtonIdx;
+            uint8_t Action;
+        } ButtonEvent;
+        struct
+        {
+            void * Context;
+        } TimerEvent;
+        struct
+        {
+            uint8_t Action;
+            int32_t Actor;
+        } LockEvent;
+    };
+
+    EventHandler Handler;
+};

+ 93 - 0
examples/lock-app/p6/include/AppTask.h

@@ -0,0 +1,93 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "AppEvent.h"
+#include "BoltLockManager.h"
+
+#include "FreeRTOS.h"
+#include "timers.h" // provides FreeRTOS timer support
+#include <ble/BLEEndPoint.h>
+#include <platform/CHIPDeviceLayer.h>
+
+// Application-defined error codes in the CHIP_ERROR space.
+#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
+#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
+#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
+#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
+#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
+#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)
+
+class AppTask
+{
+
+public:
+    CHIP_ERROR StartAppTask();
+    static void AppTaskMain(void * pvParameter);
+
+    void PostLockActionRequest(int32_t actor, BoltLockManager::Action action);
+    void PostEvent(const AppEvent * event);
+
+    void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction);
+    void UpdateClusterState(void);
+
+private:
+    friend AppTask & GetAppTask(void);
+
+    CHIP_ERROR Init();
+
+    static void ActionInitiated(BoltLockManager::Action action, int32_t actor);
+    static void ActionCompleted(BoltLockManager::Action action);
+
+    void CancelTimer(void);
+
+    void DispatchEvent(AppEvent * event);
+
+    static void FunctionTimerEventHandler(AppEvent * event);
+    static void FunctionHandler(AppEvent * event);
+    static void LockActionEventHandler(AppEvent * event);
+    static void TimerEventHandler(TimerHandle_t timer);
+
+    void StartTimer(uint32_t aTimeoutMs);
+
+    enum class Function
+    {
+        kNoneSelected   = 0,
+        kSoftwareUpdate = 0,
+        kStartBleAdv    = 1,
+        kFactoryReset   = 2,
+
+        kInvalid
+    };
+
+    Function mFunction              = Function::kInvalid;
+    bool mFunctionTimerActive       = false;
+    bool mSyncClusterToButtonAction = false;
+
+    static AppTask sAppTask;
+};
+
+inline AppTask & GetAppTask(void)
+{
+    return AppTask::sAppTask;
+}

+ 84 - 0
examples/lock-app/p6/include/BoltLockManager.h

@@ -0,0 +1,84 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include "AppEvent.h"
+
+#include "FreeRTOS.h"
+#include "timers.h" // provides FreeRTOS timer support
+
+#include <core/CHIPError.h>
+
+class BoltLockManager
+{
+public:
+    enum class Action
+    {
+        kLock = 0,
+        kUnlock,
+        KInvalid
+    };
+
+    enum class State
+    {
+        kLockingInitiated = 0,
+        kLockingCompleted,
+        kUnlockingInitiated,
+        kUnlockingCompleted,
+    };
+
+    CHIP_ERROR Init();
+    bool IsUnlocked();
+    void EnableAutoRelock(bool aOn);
+    void SetAutoLockDuration(uint32_t aDurationInSecs);
+    bool IsActionInProgress();
+    bool InitiateAction(int32_t aActor, Action aAction);
+
+    typedef void (*Callback_fn_initiated)(Action, int32_t aActor);
+    typedef void (*Callback_fn_completed)(Action);
+    void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);
+
+private:
+    friend BoltLockManager & BoltLockMgr(void);
+    State mState = State::kLockingCompleted;
+
+    Callback_fn_initiated mActionInitiated_CB;
+    Callback_fn_completed mActionCompleted_CB;
+
+    bool mAutoRelock           = false;
+    uint32_t mAutoLockDuration = 0;
+    bool mAutoLockTimerArmed   = false;
+
+    void CancelTimer(void);
+    void StartTimer(uint32_t aTimeoutMs);
+
+    static void TimerEventHandler(TimerHandle_t xTimer);
+    static void AutoReLockTimerEventHandler(AppEvent * aEvent);
+    static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
+
+    static BoltLockManager sLock;
+};
+
+inline BoltLockManager & BoltLockMgr(void)
+{
+    return BoltLockManager::sLock;
+}

+ 39 - 0
examples/lock-app/p6/include/ButtonHandler.h

@@ -0,0 +1,39 @@
+/*
+ *
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include "FreeRTOS.h"
+#include "cyhal.h"
+#include "timers.h" // provides FreeRTOS timer support
+
+#define GPIO_INTERRUPT_PRIORITY (5)
+
+class ButtonHandler
+{
+public:
+    static void Init(void);
+
+private:
+    static void GpioInit(void);
+    static void lockbuttonIsr(void * handler_arg, cyhal_gpio_event_t event);
+    static void functionbuttonIsr(void * handler_arg, cyhal_gpio_event_t event);
+    static void TimerCallback(TimerHandle_t xTimer);
+};

+ 111 - 0
examples/lock-app/p6/include/CHIPProjectConfig.h

@@ -0,0 +1,111 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Example project configuration file for CHIP.
+ *
+ *          This is a place to put application or project-specific overrides
+ *          to the default configuration values for general CHIP features.
+ *
+ */
+
+#pragma once
+
+/**
+ * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY
+ *
+ * Enables the use of a hard-coded default Chip device id and credentials if no device id
+ * is found in Chip NV storage.
+ *
+ * This option is for testing only and should be disabled in production releases.
+ */
+#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34
+
+// Use a default pairing code if one hasn't been provisioned in flash.
+#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
+#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
+#endif
+#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
+
+// For convenience, Chip Security Test Mode can be enabled and the
+// requirement for authentication in various protocols can be disabled.
+//
+//    WARNING: These options make it possible to circumvent basic Chip security functionality,
+//    including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS.
+//
+#define CHIP_CONFIG_SECURITY_TEST_MODE 0
+#define CHIP_CONFIG_REQUIRE_AUTH 1
+
+/**
+ * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
+ *
+ * The product revision 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 revisions.
+ */
+#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1
+
+/**
+ * CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
+ *
+ * A string identifying the firmware revision running on the device.
+ * CHIP service currently expects the firmware version to be in the format
+ * {MAJOR_VERSION}.0d{MINOR_VERSION}
+ */
+#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
+#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "0.1ALPHA"
+#endif
+/**
+ * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+ *
+ * Enable support for Chip-over-BLE (CHIPoBLE).
+ */
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1
+
+/**
+ * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC
+ *
+ * Enables synchronizing the device's real time clock with a remote Chip Time service
+ * using the Chip Time Sync protocol.
+ */
+#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0
+
+/**
+ * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
+ *
+ * Enables the use of a hard-coded default serial number if none
+ * is found in Chip NV storage.
+ */
+#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
+
+/**
+ * CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
+ *
+ * Enable recording UTC timestamps.
+ */
+#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
+
+/**
+ * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
+ *
+ * A size, in bytes, of the individual debug event logging buffer.
+ */
+#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512)

+ 500 - 0
examples/lock-app/p6/src/AppTask.cpp

@@ -0,0 +1,500 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "AppTask.h"
+#include "AppConfig.h"
+#include "AppEvent.h"
+#include "ButtonHandler.h"
+#include "LEDWidget.h"
+#include "qrcodegen.h"
+#include <app/common/gen/attribute-id.h>
+#include <app/common/gen/attribute-type.h>
+#include <app/common/gen/cluster-id.h>
+#include <app/server/Mdns.h>
+#include <app/server/OnboardingCodesUtil.h>
+#include <app/server/Server.h>
+#include <app/util/attribute-storage.h>
+#include <assert.h>
+#include <cy_wcm.h>
+#include <platform/CHIPDeviceLayer.h>
+#include <setup_payload/QRCodeSetupPayloadGenerator.h>
+#include <setup_payload/SetupPayload.h>
+
+#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
+#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
+#define APP_TASK_STACK_SIZE (4096)
+#define APP_TASK_PRIORITY 2
+#define APP_EVENT_QUEUE_SIZE 10
+
+namespace {
+
+TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer.
+
+TaskHandle_t sAppTaskHandle;
+QueueHandle_t sAppEventQueue;
+
+LEDWidget sStatusLED;
+LEDWidget sLockLED;
+
+bool sIsWiFiStationProvisioned = false;
+bool sIsWiFiStationEnabled     = false;
+bool sIsWiFiStationConnected   = false;
+bool sHaveBLEConnections       = false;
+bool sHaveServiceConnectivity  = false;
+
+StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
+StaticTask_t appTaskStruct;
+} // namespace
+using namespace chip::TLV;
+using namespace ::chip::DeviceLayer;
+
+AppTask AppTask::sAppTask;
+
+CHIP_ERROR AppTask::StartAppTask()
+{
+    sAppEventQueue = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent));
+    if (sAppEventQueue == NULL)
+    {
+        P6_LOG("Failed to allocate app event queue");
+        appError(APP_ERROR_EVENT_QUEUE_FAILED);
+    }
+
+    // Start App task.
+    sAppTaskHandle = xTaskCreateStatic(AppTaskMain, APP_TASK_NAME, ArraySize(appStack), NULL, 1, appStack, &appTaskStruct);
+    return (sAppTaskHandle == nullptr) ? APP_ERROR_CREATE_TASK_FAILED : CHIP_NO_ERROR;
+}
+
+CHIP_ERROR AppTask::Init()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+
+    // Register the callback to init the MDNS server when connectivity is available
+    PlatformMgr().AddEventHandler(
+        [](const ChipDeviceEvent * event, intptr_t arg) {
+            // Restart the server whenever an ip address is renewed
+            if (event->Type == DeviceEventType::kInternetConnectivityChange)
+            {
+                if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established ||
+                    event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
+                {
+                    chip::app::Mdns::StartServer();
+                }
+            }
+        },
+        0);
+    // Init ZCL Data Model
+    InitServer();
+
+    // Initialise WSTK buttons PB0 and PB1 (including debounce).
+    ButtonHandler::Init();
+
+    // Create FreeRTOS sw timer for Function Selection.
+    sFunctionTimer = xTimerCreate("FnTmr",          // Just a text name, not used by the RTOS kernel
+                                  1,                // == default timer period (mS)
+                                  false,            // no timer reload (==one-shot)
+                                  (void *) this,    // init timer id = app task obj context
+                                  TimerEventHandler // timer callback handler
+    );
+    if (sFunctionTimer == NULL)
+    {
+        P6_LOG("funct timer create failed");
+        appError(APP_ERROR_CREATE_TIMER_FAILED);
+    }
+
+    P6_LOG("Current Firmware Version: %d", CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION);
+    err = BoltLockMgr().Init();
+    if (err != CHIP_NO_ERROR)
+    {
+        P6_LOG("BoltLockMgr().Init() failed");
+        appError(err);
+    }
+
+    BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted);
+
+    // Initialize LEDs
+    sStatusLED.Init(SYSTEM_STATE_LED);
+    sLockLED.Init(LOCK_STATE_LED);
+    sLockLED.Set(!BoltLockMgr().IsUnlocked());
+    UpdateClusterState();
+
+    ConfigurationMgr().LogDeviceConfig();
+
+    // Print setup info
+    PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));
+
+    return err;
+}
+
+void AppTask::AppTaskMain(void * pvParameter)
+{
+    AppEvent event;
+
+    CHIP_ERROR err = sAppTask.Init();
+    if (err != CHIP_NO_ERROR)
+    {
+        P6_LOG("AppTask.Init() failed");
+        appError(err);
+    }
+
+    P6_LOG("App Task started");
+
+    while (true)
+    {
+        BaseType_t eventReceived = xQueueReceive(sAppEventQueue, &event, pdMS_TO_TICKS(10));
+        while (eventReceived == pdTRUE)
+        {
+            sAppTask.DispatchEvent(&event);
+            eventReceived = xQueueReceive(sAppEventQueue, &event, 0);
+        }
+        // Collect connectivity and configuration state from the CHIP stack. Because
+        // the CHIP event loop is being run in a separate task, the stack must be
+        // locked while these values are queried.  However we use a non-blocking
+        // lock request (TryLockCHIPStack()) to avoid blocking other UI activities
+        // when the CHIP task is busy (e.g. with a long crypto operation).
+        if (PlatformMgr().TryLockChipStack())
+        {
+            sIsWiFiStationEnabled     = ConnectivityMgr().IsWiFiStationEnabled();
+            sIsWiFiStationConnected   = ConnectivityMgr().IsWiFiStationConnected();
+            sIsWiFiStationProvisioned = ConnectivityMgr().IsWiFiStationProvisioned();
+            sHaveBLEConnections       = (ConnectivityMgr().NumBLEConnections() != 0);
+            sHaveServiceConnectivity  = ConnectivityMgr().HaveServiceConnectivity();
+            PlatformMgr().UnlockChipStack();
+        }
+
+        // Update the status LED if factory reset has not been initiated.
+        //
+        // If system has "full connectivity", keep the LED On constantly.
+        //
+        // If thread and service provisioned, but not attached to the thread network
+        // yet OR no connectivity to the service OR subscriptions are not fully
+        // established THEN blink the LED Off for a short period of time.
+        //
+        // If the system has ble connection(s) uptill the stage above, THEN blink
+        // the LEDs at an even rate of 100ms.
+        //
+        // Otherwise, blink the LED ON for a very short time.
+        if (sAppTask.mFunction != Function::kFactoryReset)
+        {
+            // Consider the system to be "fully connected" if it has service
+            // connectivity
+            if (sHaveServiceConnectivity)
+            {
+                sStatusLED.Set(true);
+            }
+            else if (sIsWiFiStationEnabled && sIsWiFiStationProvisioned && (!sIsWiFiStationConnected || !sHaveServiceConnectivity))
+            {
+                sStatusLED.Blink(950, 50);
+            }
+            else if (sHaveBLEConnections)
+            {
+                sStatusLED.Blink(100, 100);
+            }
+            else
+            {
+                sStatusLED.Blink(50, 950);
+            }
+        }
+        sStatusLED.Animate();
+        sLockLED.Animate();
+    }
+}
+
+void AppTask::LockActionEventHandler(AppEvent * event)
+{
+    bool initiated                 = false;
+    BoltLockManager::Action action = BoltLockManager::Action::KInvalid;
+    int32_t actor                  = 0;
+    CHIP_ERROR err                 = CHIP_NO_ERROR;
+
+    if (event->Type == AppEvent::kEventType_Lock)
+    {
+        action = static_cast<BoltLockManager::Action>(event->LockEvent.Action);
+        actor  = event->LockEvent.Actor;
+    }
+    else if (event->Type == AppEvent::kEventType_Button)
+    {
+        if (BoltLockMgr().IsUnlocked())
+        {
+            action = BoltLockManager::Action::kLock;
+        }
+        else
+        {
+            action = BoltLockManager::Action::kUnlock;
+        }
+        actor = AppEvent::kEventType_Button;
+    }
+    else
+    {
+        err = APP_ERROR_UNHANDLED_EVENT;
+    }
+
+    if (err == CHIP_NO_ERROR)
+    {
+        initiated = BoltLockMgr().InitiateAction(actor, action);
+
+        if (!initiated)
+        {
+            P6_LOG("Action is already in progress or active.");
+        }
+    }
+}
+
+void AppTask::ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction)
+{
+    if (btnIdx != APP_LOCK_BUTTON_IDX && btnIdx != APP_FUNCTION_BUTTON_IDX)
+    {
+        return;
+    }
+
+    AppEvent button_event              = {};
+    button_event.Type                  = AppEvent::kEventType_Button;
+    button_event.ButtonEvent.ButtonIdx = btnIdx;
+    button_event.ButtonEvent.Action    = btnAction;
+
+    if (btnIdx == APP_LOCK_BUTTON_IDX)
+    {
+        button_event.Handler = LockActionEventHandler;
+        sAppTask.PostEvent(&button_event);
+    }
+    else if (btnIdx == APP_FUNCTION_BUTTON_IDX)
+    {
+        button_event.Handler = FunctionHandler;
+        sAppTask.PostEvent(&button_event);
+    }
+}
+
+void AppTask::TimerEventHandler(TimerHandle_t timer)
+{
+    AppEvent event;
+    event.Type               = AppEvent::kEventType_Timer;
+    event.TimerEvent.Context = (void *) timer;
+    event.Handler            = FunctionTimerEventHandler;
+    sAppTask.PostEvent(&event);
+}
+
+void AppTask::FunctionTimerEventHandler(AppEvent * event)
+{
+    if (event->Type != AppEvent::kEventType_Timer)
+    {
+        return;
+    }
+
+    // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT,
+    // initiate factory reset
+    if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == Function::kStartBleAdv)
+    {
+        P6_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);
+
+        // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to
+        // cancel, if required.
+        sAppTask.StartTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);
+
+        sAppTask.mFunction = Function::kFactoryReset;
+
+        // Turn off all LEDs before starting blink to make sure blink is
+        // co-ordinated.
+        sStatusLED.Set(false);
+        sLockLED.Set(false);
+
+        sStatusLED.Blink(500);
+        sLockLED.Blink(500);
+    }
+    else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == Function::kFactoryReset)
+    {
+        // Actually trigger Factory Reset
+        sAppTask.mFunction = Function::kNoneSelected;
+        ConfigurationMgr().InitiateFactoryReset();
+    }
+}
+
+void AppTask::FunctionHandler(AppEvent * event)
+{
+    if (event->ButtonEvent.ButtonIdx != APP_FUNCTION_BUTTON_IDX)
+    {
+        return;
+    }
+    // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (<
+    // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the
+    // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT +
+    // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after
+    // FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated.
+    // To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs
+    // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT
+    if (event->ButtonEvent.Action == APP_BUTTON_PRESSED)
+    {
+        if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == Function::kNoneSelected)
+        {
+            sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
+            sAppTask.mFunction = Function::kStartBleAdv;
+        }
+    }
+    else
+    {
+        // If the button was released before factory reset got initiated, start Thread Network
+        if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == Function::kStartBleAdv)
+        {
+            sAppTask.CancelTimer();
+            sAppTask.mFunction = Function::kNoneSelected;
+        }
+        else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == Function::kFactoryReset)
+        {
+            // Set lock status LED back to show state of lock.
+            sLockLED.Set(!BoltLockMgr().IsUnlocked());
+
+            sAppTask.CancelTimer();
+
+            // Change the function to none selected since factory reset has been
+            // canceled.
+            sAppTask.mFunction = Function::kNoneSelected;
+
+            P6_LOG("Factory Reset has been Canceled");
+        }
+    }
+}
+
+void AppTask::CancelTimer()
+{
+    if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
+    {
+        P6_LOG("app timer stop() failed");
+        appError(APP_ERROR_STOP_TIMER_FAILED);
+    }
+
+    mFunctionTimerActive = false;
+}
+
+void AppTask::StartTimer(uint32_t aTimeoutInMs)
+{
+    if (xTimerIsTimerActive(sFunctionTimer))
+    {
+        P6_LOG("app timer already started!");
+        CancelTimer();
+    }
+
+    // timer is not active, change its period to required value (== restart).
+    // FreeRTOS- Block for a maximum of 100 ticks if the change period command
+    // cannot immediately be sent to the timer command queue.
+    if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS)
+    {
+        P6_LOG("app timer start() failed");
+        appError(APP_ERROR_START_TIMER_FAILED);
+    }
+
+    mFunctionTimerActive = true;
+}
+
+void AppTask::ActionInitiated(BoltLockManager::Action action, int32_t actor)
+{
+    // If the action has been initiated by the lock, update the bolt lock trait
+    // and start flashing the LEDs rapidly to indicate action initiation.
+    if (action == BoltLockManager::Action::kLock)
+    {
+        P6_LOG("Lock Action has been initiated");
+    }
+    else if (action == BoltLockManager::Action::kUnlock)
+    {
+        P6_LOG("Unlock Action has been initiated");
+    }
+
+    if (actor == AppEvent::kEventType_Button)
+    {
+        sAppTask.mSyncClusterToButtonAction = true;
+    }
+
+    sLockLED.Blink(50, 50);
+}
+
+void AppTask::ActionCompleted(BoltLockManager::Action action)
+{
+    // if the action has been completed by the lock, update the bolt lock trait.
+    // Turn on the lock LED if in a LOCKED state OR
+    // Turn off the lock LED if in an UNLOCKED state.
+    if (action == BoltLockManager::Action::kLock)
+    {
+        P6_LOG("Lock Action has been completed");
+
+        sLockLED.Set(true);
+    }
+    else if (action == BoltLockManager::Action::kUnlock)
+    {
+        P6_LOG("Unlock Action has been completed");
+
+        sLockLED.Set(false);
+    }
+
+    if (sAppTask.mSyncClusterToButtonAction)
+    {
+        sAppTask.UpdateClusterState();
+        sAppTask.mSyncClusterToButtonAction = false;
+    }
+}
+
+void AppTask::PostLockActionRequest(int32_t actor, BoltLockManager::Action action)
+{
+    AppEvent event;
+    event.Type             = AppEvent::kEventType_Lock;
+    event.LockEvent.Actor  = actor;
+    event.LockEvent.Action = static_cast<uint8_t>(action);
+    event.Handler          = LockActionEventHandler;
+    PostEvent(&event);
+}
+
+void AppTask::PostEvent(const AppEvent * event)
+{
+    if (sAppEventQueue != NULL)
+    {
+        if (!xQueueSend(sAppEventQueue, event, 1))
+        {
+            P6_LOG("Failed to post event to app task event queue");
+        }
+    }
+}
+
+void AppTask::DispatchEvent(AppEvent * event)
+{
+    if (event->Handler)
+    {
+        event->Handler(event);
+    }
+    else
+    {
+        P6_LOG("Event received with no handler. Dropping event.");
+    }
+}
+
+void AppTask::UpdateClusterState(void)
+{
+    uint8_t newValue = !BoltLockMgr().IsUnlocked();
+
+    // write the new on/off value
+    EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
+                                                 ZCL_BOOLEAN_ATTRIBUTE_TYPE);
+    if (status != EMBER_ZCL_STATUS_SUCCESS)
+    {
+        P6_LOG("ERR: updating on/off %x", status);
+    }
+}
+void vApplicationStackOverflowHook(TaskHandle_t pxTask, char * pcTaskName)
+{
+    (void) pxTask;
+
+    /* Run time stack overflow checking is performed if
+    configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
+    function is called if a stack overflow is detected. */
+    printf("ERROR: stack overflow with task %s\r\n", pcTaskName);
+}

+ 225 - 0
examples/lock-app/p6/src/BoltLockManager.cpp

@@ -0,0 +1,225 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "BoltLockManager.h"
+
+#include "AppConfig.h"
+#include "AppTask.h"
+#include <FreeRTOS.h>
+
+BoltLockManager BoltLockManager::sLock;
+
+TimerHandle_t sLockTimer;
+
+CHIP_ERROR BoltLockManager::Init()
+{
+    // Create FreeRTOS sw timer for lock timer.
+    sLockTimer = xTimerCreate("lockTmr",        // Just a text name, not used by the RTOS kernel
+                              1,                // == default timer period (mS)
+                              false,            // no timer reload (==one-shot)
+                              (void *) this,    // init timer id = lock obj context
+                              TimerEventHandler // timer callback handler
+    );
+
+    if (sLockTimer == NULL)
+    {
+        P6_LOG("sLockTimer timer create failed");
+        appError(APP_ERROR_CREATE_TIMER_FAILED);
+    }
+
+    mState              = State::kLockingCompleted;
+    mAutoLockTimerArmed = false;
+    mAutoRelock         = false;
+    mAutoLockDuration   = 0;
+
+    return CHIP_NO_ERROR;
+}
+
+void BoltLockManager::SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB)
+{
+    mActionInitiated_CB = aActionInitiated_CB;
+    mActionCompleted_CB = aActionCompleted_CB;
+}
+
+bool BoltLockManager::IsActionInProgress()
+{
+    return (mState == State::kLockingInitiated || mState == State::kUnlockingInitiated);
+}
+
+bool BoltLockManager::IsUnlocked()
+{
+    return (mState == State::kUnlockingCompleted);
+}
+
+void BoltLockManager::EnableAutoRelock(bool aOn)
+{
+    mAutoRelock = aOn;
+}
+
+void BoltLockManager::SetAutoLockDuration(uint32_t aDurationInSecs)
+{
+    mAutoLockDuration = aDurationInSecs;
+}
+
+bool BoltLockManager::InitiateAction(int32_t aActor, Action aAction)
+{
+    bool action_initiated = false;
+    State new_state;
+
+    // Initiate Lock/Unlock Action only when the previous one is complete.
+    if (mState == State::kLockingCompleted && aAction == Action::kUnlock)
+    {
+        action_initiated = true;
+
+        new_state = State::kUnlockingInitiated;
+    }
+    else if (mState == State::kUnlockingCompleted && aAction == Action::kLock)
+    {
+        action_initiated = true;
+
+        new_state = State::kLockingInitiated;
+    }
+
+    if (action_initiated)
+    {
+        if (mAutoLockTimerArmed && new_state == State::kLockingInitiated)
+        {
+            // If auto lock timer has been armed and someone initiates locking,
+            // cancel the timer and continue as normal.
+            mAutoLockTimerArmed = false;
+
+            CancelTimer();
+        }
+
+        StartTimer(ACTUATOR_MOVEMENT_PERIOS_MS);
+
+        // Since the timer started successfully, update the state and trigger callback
+        mState = new_state;
+
+        if (mActionInitiated_CB)
+        {
+            mActionInitiated_CB(aAction, aActor);
+        }
+    }
+
+    return action_initiated;
+}
+
+void BoltLockManager::StartTimer(uint32_t aTimeoutMs)
+{
+    if (xTimerIsTimerActive(sLockTimer))
+    {
+        P6_LOG("app timer already started!");
+        CancelTimer();
+    }
+
+    // timer is not active, change its period to required value (== restart).
+    // FreeRTOS- Block for a maximum of 100 ticks if the change period command
+    // cannot immediately be sent to the timer command queue.
+    if (xTimerChangePeriod(sLockTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
+    {
+        P6_LOG("sLockTimer timer start() failed");
+        appError(APP_ERROR_START_TIMER_FAILED);
+    }
+}
+
+void BoltLockManager::CancelTimer(void)
+{
+    if (xTimerStop(sLockTimer, 0) == pdFAIL)
+    {
+        P6_LOG("Lock timer timer stop() failed");
+        appError(APP_ERROR_STOP_TIMER_FAILED);
+    }
+}
+
+void BoltLockManager::TimerEventHandler(TimerHandle_t xTimer)
+{
+    // Get lock obj context from timer id.
+    BoltLockManager * lock = static_cast<BoltLockManager *>(pvTimerGetTimerID(xTimer));
+
+    // The timer event handler will be called in the context of the timer task
+    // once sLockTimer expires. Post an event to apptask queue with the actual handler
+    // so that the event can be handled in the context of the apptask.
+    AppEvent event;
+    event.Type               = AppEvent::kEventType_Timer;
+    event.TimerEvent.Context = lock;
+    if (lock->mAutoLockTimerArmed)
+    {
+        event.Handler = AutoReLockTimerEventHandler;
+    }
+    else
+    {
+        event.Handler = ActuatorMovementTimerEventHandler;
+    }
+    GetAppTask().PostEvent(&event);
+}
+
+void BoltLockManager::AutoReLockTimerEventHandler(AppEvent * aEvent)
+{
+    BoltLockManager * lock = static_cast<BoltLockManager *>(aEvent->TimerEvent.Context);
+    int32_t actor          = 0;
+
+    // Make sure auto lock timer is still armed.
+    if (!lock->mAutoLockTimerArmed)
+    {
+        return;
+    }
+
+    lock->mAutoLockTimerArmed = false;
+
+    P6_LOG("Auto Re-Lock has been triggered!");
+
+    lock->InitiateAction(actor, Action::kLock);
+}
+
+void BoltLockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)
+{
+    Action actionCompleted = Action::KInvalid;
+
+    BoltLockManager * lock = static_cast<BoltLockManager *>(aEvent->TimerEvent.Context);
+
+    if (lock->mState == State::kLockingInitiated)
+    {
+        lock->mState    = State::kLockingCompleted;
+        actionCompleted = Action::kLock;
+    }
+    else if (lock->mState == State::kUnlockingInitiated)
+    {
+        lock->mState    = State::kUnlockingCompleted;
+        actionCompleted = Action::kUnlock;
+    }
+
+    if (actionCompleted != Action::KInvalid)
+    {
+        if (lock->mActionCompleted_CB)
+        {
+            lock->mActionCompleted_CB(actionCompleted);
+        }
+
+        if (lock->mAutoRelock && actionCompleted == Action::kUnlock)
+        {
+            // Start the timer for auto relock
+            lock->StartTimer(lock->mAutoLockDuration * 1000);
+
+            lock->mAutoLockTimerArmed = true;
+
+            P6_LOG("Auto Re-lock enabled. Will be triggered in %lu seconds", lock->mAutoLockDuration);
+        }
+    }
+}

+ 95 - 0
examples/lock-app/p6/src/ButtonHandler.cpp

@@ -0,0 +1,95 @@
+/*
+ *
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "ButtonHandler.h"
+#include "AppConfig.h"
+#include "AppTask.h"
+
+namespace {
+constexpr int kButtonCount = 2;
+
+TimerHandle_t buttonTimers[kButtonCount]; // FreeRTOS timers used for debouncing
+// buttons. Array to hold handles to
+// the created timers.
+
+} // namespace
+
+void ButtonHandler::Init(void)
+{
+    GpioInit();
+    // Create FreeRTOS sw timers for debouncing buttons.
+    for (uint8_t i = 0; i < kButtonCount; i++)
+    {
+        buttonTimers[i] = xTimerCreate("BtnTmr",                      // Just a text name, not used by the RTOS kernel
+                                       APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period
+                                       false,                         // no timer reload (==one-shot)
+                                       (void *) (int) i,              // init timer id = button index
+                                       TimerCallback                  // timer callback handler (all buttons use
+                                                                      // the same timer cn function)
+        );
+    }
+}
+
+void ButtonHandler::GpioInit(void)
+{
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    // Set up button GPIOs to input with pullups.
+    result = cyhal_gpio_init(APP_LOCK_BUTTON, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        printf(" cyhal_gpio_init failed for APP_LOCK_BUTTON\r\n");
+    }
+    result = cyhal_gpio_init(APP_FUNCTION_BUTTON, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_PULLUP, CYBSP_BTN_OFF);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        printf(" cyhal_gpio_init failed for APP_FUNCTION_BUTTON\r\n");
+    }
+    /* Configure GPIO interrupt. */
+    cyhal_gpio_register_callback(APP_LOCK_BUTTON, lockbuttonIsr, NULL);
+    cyhal_gpio_register_callback(APP_FUNCTION_BUTTON, functionbuttonIsr, NULL);
+    cyhal_gpio_enable_event(APP_LOCK_BUTTON, CYHAL_GPIO_IRQ_FALL, GPIO_INTERRUPT_PRIORITY, true);
+    cyhal_gpio_enable_event(APP_FUNCTION_BUTTON, CYHAL_GPIO_IRQ_FALL, GPIO_INTERRUPT_PRIORITY, true);
+}
+void ButtonHandler::lockbuttonIsr(void * handler_arg, cyhal_gpio_event_t event)
+{
+    portBASE_TYPE taskWoken = pdFALSE;
+    xTimerStartFromISR(buttonTimers[APP_LOCK_BUTTON_IDX], &taskWoken);
+}
+
+void ButtonHandler::functionbuttonIsr(void * handler_arg, cyhal_gpio_event_t event)
+{
+    portBASE_TYPE taskWoken = pdFALSE;
+    xTimerStartFromISR(buttonTimers[APP_FUNCTION_BUTTON_IDX], &taskWoken);
+}
+
+void ButtonHandler::TimerCallback(TimerHandle_t xTimer)
+{
+    // Get the button index of the expired timer and call button event helper.
+    uint32_t timerId;
+    uint8_t buttonevent = 0;
+    timerId             = (uint32_t) pvTimerGetTimerID(xTimer);
+    if (timerId)
+    {
+        buttonevent = cyhal_gpio_read(APP_FUNCTION_BUTTON);
+    }
+    else
+    {
+        buttonevent = cyhal_gpio_read(APP_LOCK_BUTTON);
+    }
+    GetAppTask().ButtonEventHandler(timerId, (buttonevent) ? APP_BUTTON_PRESSED : APP_BUTTON_RELEASED);
+}

+ 79 - 0
examples/lock-app/p6/src/ZclCallbacks.cpp

@@ -0,0 +1,79 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ * @file
+ *   This file implements the handler for data model messages.
+ */
+
+#include "AppConfig.h"
+#include "AppTask.h"
+#include "BoltLockManager.h"
+
+#include <app/chip-zcl-zpro-codec.h>
+#include <app/common/gen/attribute-id.h>
+#include <app/common/gen/cluster-id.h>
+#include <app/util/af-types.h>
+#include <app/util/attribute-storage.h>
+#include <app/util/util.h>
+
+using namespace ::chip;
+
+void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
+                                        uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
+{
+    if (clusterId != ZCL_ON_OFF_CLUSTER_ID)
+    {
+        P6_LOG("Unknown cluster ID: %ld", clusterId);
+        return;
+    }
+
+    if (attributeId != ZCL_ON_OFF_ATTRIBUTE_ID)
+    {
+        P6_LOG("Unknown attribute ID: %ld", attributeId);
+        return;
+    }
+
+    if (*value)
+    {
+        BoltLockMgr().InitiateAction(AppEvent::kEventType_Lock, BoltLockManager::Action::kLock);
+    }
+    else
+    {
+        BoltLockMgr().InitiateAction(AppEvent::kEventType_Lock, BoltLockManager::Action::kUnlock);
+    }
+}
+
+/** @brief OnOff Cluster Init
+ *
+ * This function is called when a specific cluster is initialized. It gives the
+ * application an opportunity to take care of cluster initialization procedures.
+ * It is called exactly once for each endpoint where cluster is present.
+ *
+ * @param endpoint   Ver.: always
+ *
+ * TODO Issue #3841
+ * emberAfOnOffClusterInitCallback happens before the stack initialize the cluster
+ * attributes to the default value.
+ * The logic here expects something similar to the deprecated Plugins callback
+ * emberAfPluginOnOffClusterServerPostInitCallback.
+ *
+ */
+void emberAfOnOffClusterInitCallback(EndpointId endpoint)
+{
+    GetAppTask().UpdateClusterState();
+}

+ 114 - 0
examples/lock-app/p6/src/main.cpp

@@ -0,0 +1,114 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <FreeRTOS.h>
+
+#include <platform/CHIPDeviceLayer.h>
+#include <platform/KeyValueStoreManager.h>
+#include <support/CHIPMem.h>
+#include <support/CHIPPlatformMemory.h>
+
+#include <AppTask.h>
+
+#include "AppConfig.h"
+#include "init_p6Platform.h"
+#include <app/server/Server.h>
+
+using namespace ::chip;
+using namespace ::chip::Inet;
+using namespace ::chip::DeviceLayer;
+
+volatile int apperror_cnt;
+// ================================================================================
+// App Error
+//=================================================================================
+void appError(int err)
+{
+    P6_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err);
+    portDISABLE_INTERRUPTS();
+    while (1)
+        ;
+}
+
+void appError(CHIP_ERROR error)
+{
+    appError(static_cast<int>(error.AsInteger()));
+}
+
+// ================================================================================
+// FreeRTOS Callbacks
+// ================================================================================
+extern "C" void vApplicationIdleHook(void)
+{
+    // FreeRTOS Idle callback
+}
+
+// ================================================================================
+// Main Code
+// ================================================================================
+int main(void)
+{
+    init_p6Platform();
+
+    P6_LOG("==================================================\r\n");
+    P6_LOG("chip-p6-lock-example starting\r\n");
+    P6_LOG("==================================================\r\n");
+
+    // Init Chip memory management before the stack
+    chip::Platform::MemoryInit();
+    // chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
+
+    CHIP_ERROR ret = PlatformMgr().InitChipStack();
+    if (ret != CHIP_NO_ERROR)
+    {
+        P6_LOG("PlatformMgr().InitChipStack() failed");
+        appError(ret);
+    }
+    chip::DeviceLayer::ConnectivityMgr().SetBLEDeviceName("P6_LOCK");
+    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);
+    }
+    /* Start the FreeRTOS scheduler */
+    vTaskStartScheduler();
+
+    chip::Platform::MemoryShutdown();
+    PlatformMgr().StopEventLoopTask();
+    PlatformMgr().Shutdown();
+
+    // Should never get here.
+    P6_LOG("vTaskStartScheduler() failed");
+    appError(ret);
+}

+ 1 - 0
examples/lock-app/p6/third_party/connectedhomeip

@@ -0,0 +1 @@
+../../../../

+ 22 - 0
examples/platform/p6/BUILD.gn

@@ -0,0 +1,22 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/p6.gni")
+
+import("${p6_sdk_build_root}/p6_sdk.gni")
+
+config("chip_examples_project_config") {
+  include_dirs = [ "project_include" ]
+}

+ 83 - 0
examples/platform/p6/LEDWidget.cpp

@@ -0,0 +1,83 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "LEDWidget.h"
+
+#include "cybsp.h"
+#include "cyhal.h"
+#include <platform/CHIPDeviceLayer.h>
+
+void LEDWidget::Init(int ledNum)
+{
+    mLastChangeTimeUS = 0;
+    mBlinkOnTimeMS    = 0;
+    mBlinkOffTimeMS   = 0;
+    mLedNum           = ledNum;
+    mState            = CYBSP_LED_STATE_OFF;
+
+    cyhal_gpio_init((cyhal_gpio_t) ledNum, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, CYBSP_LED_STATE_OFF);
+}
+
+void LEDWidget::Invert(void)
+{
+    Set(!mState);
+}
+
+void LEDWidget::Set(bool state)
+{
+    mLastChangeTimeUS = mBlinkOnTimeMS = mBlinkOffTimeMS = 0;
+    DoSet(state);
+}
+
+void LEDWidget::Blink(uint32_t changeRateMS)
+{
+    Blink(changeRateMS, changeRateMS);
+}
+
+void LEDWidget::Blink(uint32_t onTimeMS, uint32_t offTimeMS)
+{
+    mBlinkOnTimeMS  = onTimeMS;
+    mBlinkOffTimeMS = offTimeMS;
+    Animate();
+}
+
+void LEDWidget::Animate()
+{
+    if (mBlinkOnTimeMS != 0 && mBlinkOffTimeMS != 0)
+    {
+        int64_t nowUS            = ::chip::System::Clock::GetMonotonicMicroseconds();
+        int64_t stateDurUS       = ((mState) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
+        int64_t nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
+
+        if (nowUS > nextChangeTimeUS)
+        {
+            DoSet(!mState);
+            mLastChangeTimeUS = nowUS;
+        }
+    }
+}
+
+void LEDWidget::DoSet(bool state)
+{
+    if (mState != state)
+    {
+        cyhal_gpio_write((cyhal_gpio_t) mLedNum, ((state) ? CYBSP_LED_STATE_ON : CYBSP_LED_STATE_OFF));
+    }
+    mState = state;
+}

+ 44 - 0
examples/platform/p6/LEDWidget.h

@@ -0,0 +1,44 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include "cybsp.h"
+#include <stdint.h>
+
+class LEDWidget
+{
+public:
+    static void InitGpio(void);
+    void Init(int ledNum);
+    void Set(bool state);
+    void Invert(void);
+    void Blink(uint32_t changeRateMS);
+    void Blink(uint32_t onTimeMS, uint32_t offTimeMS);
+    void Animate();
+
+private:
+    int64_t mLastChangeTimeUS = 0;
+    uint32_t mBlinkOnTimeMS   = 0;
+    uint32_t mBlinkOffTimeMS  = 0;
+    int mLedNum               = 0;
+    bool mState               = CYBSP_LED_STATE_OFF;
+
+    void DoSet(bool state);
+};

+ 21 - 0
examples/platform/p6/args.gni

@@ -0,0 +1,21 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+
+chip_ble_project_config_include = "<CHIPProjectConfig.h>"
+chip_device_project_config_include = "<CHIPProjectConfig.h>"
+chip_project_config_include = "<CHIPProjectConfig.h>"
+chip_inet_project_config_include = "<CHIPProjectConfig.h>"
+chip_system_project_config_include = "<CHIPProjectConfig.h>"

+ 57 - 0
examples/platform/p6/init_p6Platform.cpp

@@ -0,0 +1,57 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "AppConfig.h"
+#include <platform/CHIPDeviceLayer.h>
+#include <support/CHIPPlatformMemory.h>
+
+#include <assert.h>
+#include <string.h>
+#if CHIP_ENABLE_OPENTHREAD
+#include <openthread-core-config.h>
+#include <openthread/cli.h>
+#include <openthread/config.h>
+#include <openthread/dataset.h>
+#include <openthread/error.h>
+#include <openthread/heap.h>
+#include <openthread/icmp6.h>
+#include <openthread/instance.h>
+#include <openthread/link.h>
+#include <openthread/platform/openthread-system.h>
+#include <openthread/platform/uart.h>
+#include <openthread/tasklet.h>
+#include <openthread/thread.h>
+
+#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
+#include "openthread/heap.h"
+#include "sl_malloc.h"
+#endif // OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
+#endif // CHIP_ENABLE_OPENTHREAD
+#include <cy_retarget_io.h>
+#include <cybsp.h>
+#include <cyhal.h>
+
+void init_p6Platform(void)
+{
+    /* Initialize the board support package */
+    cybsp_init();
+
+    /* Initialize retarget-io to use the debug UART port */
+    cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
+}

+ 21 - 0
examples/platform/p6/init_p6Platform.h

@@ -0,0 +1,21 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*******************************************************************************/
+#pragma once
+
+void init_p6Platform(void);

+ 18 - 0
gn_build.sh

@@ -103,6 +103,12 @@ for arg; do
         enable_efr32_builds=true)
             efr32_enabled=1
             ;;
+        enable_p6_builds=true)
+            p6_builds_enabled=1
+            ;;
+        p6_board=*)
+            p6_board_selected=1
+            ;;
     esac
     user_args+=" $arg"
 done
@@ -130,6 +136,18 @@ else
     echo "(cd $CHIP_ROOT/examples/lock-app/efr32; gn gen out/debug; ninja -C out/debug)"
 fi
 
+echo
+
+# P6 Build setup
+if [[ -z "$p6_builds_enabled" ]]; then
+    echo "Hint: Pass enable_p6_builds=true to this script to enable building for PSoC6-43012"
+else
+    p6_sdk_args=""
+    if [[ -z "$p6_board_selected" ]]; then
+        p6_sdk_args="p6_board=\"CY8CKIT-062S2-43012\""
+    fi
+fi
+
 # K32W SDK setup
 k32w_sdk_args=""
 

+ 23 - 0
integrations/docker/images/chip-build-infineon/Dockerfile

@@ -0,0 +1,23 @@
+ARG VERSION=latest
+FROM connectedhomeip/chip-build:${VERSION}
+
+# ------------------------------------------------------------------------------
+# Install prerequisites
+RUN apt update -y \
+ && apt install -y curl git make file libglib2.0-0 libusb-1.0-0 libncurses5 \
+ && apt clean
+
+# ------------------------------------------------------------------------------
+# Download and extract ModusToolbox 2.3
+RUN curl --fail --location --silent --show-error http://dlm.cypress.com.edgesuite.net/akdlm/downloadmanager/software/ModusToolbox/ModusToolbox_2.3/ModusToolbox_2.3.0.4276-linux-install.tar.gz -o /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz \
+ && tar -C /opt -zxf /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz \
+ && rm /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz
+
+# ------------------------------------------------------------------------------
+# Execute post-build scripts
+RUN bash -e /opt/ModusToolbox/tools_2.3/modus-shell/postinstall \
+ && bash -e /opt/ModusToolbox/tools_2.3/fw-loader/udev_rules/install_rules.sh
+
+# ------------------------------------------------------------------------------
+# Set environment variable required by ModusToolbox application makefiles
+ENV CY_TOOLS_PATHS="/opt/ModusToolbox/tools_2.3"

+ 1 - 0
integrations/docker/images/chip-build-infineon/build.sh

@@ -0,0 +1 @@
+../../build.sh

+ 1 - 0
integrations/docker/images/chip-build-infineon/run.sh

@@ -0,0 +1 @@
+../../run.sh

+ 1 - 0
integrations/docker/images/chip-build-infineon/version

@@ -0,0 +1 @@
+../chip-build/version

+ 4 - 0
integrations/docker/images/chip-build-vscode/Dockerfile

@@ -5,6 +5,7 @@ FROM connectedhomeip/chip-build-android:${VERSION} AS android
 FROM connectedhomeip/chip-build-esp32-qemu:${VERSION} as esp32
 FROM connectedhomeip/chip-build-mbed-os:${VERSION} AS mbedos
 FROM connectedhomeip/chip-build-telink:${VERSION} AS telink
+FROM connectedhomeip/chip-build-infineon:${VERSION} AS p6
 FROM connectedhomeip/chip-build:${VERSION}
 
 # qemu-src copied over because qemu directory contains symlinks to the src
@@ -24,6 +25,8 @@ COPY --from=mbedos /opt/mbed-os /opt/mbed-os
 COPY --from=mbedos /opt/mbed-os-toolchain/ /opt/mbed-os-toolchain/
 COPY --from=mbedos /opt/openocd/ /opt/openocd/
 
+COPY --from=p6 /opt/ModusToolbox /opt/ModusToolbox
+
 COPY --from=telink /opt/zephyrproject /opt/telink/zephyrproject
 COPY --from=telink /opt/telink/telink_riscv_linux_toolchain /opt/telink/telink_riscv_linux_toolchain
 
@@ -60,3 +63,4 @@ ENV OPENOCD_PATH=/opt/openocd/
 ENV PW_ENVIRONMENT_ROOT=/home/vscode/pigweed/env
 ENV TELINK_ZEPHYR_BASE=/opt/telink/zephyrproject/zephyr
 ENV TELINK_TOOLCHAIN_PATH=/opt/telink/telink_riscv_linux_toolchain/nds32le-elf-mculib-v5f/bin
+ENV CY_TOOLS_PATHS="/opt/ModusToolbox/tools_2.3"

+ 1 - 1
integrations/docker/images/chip-build/version

@@ -1 +1 @@
-0.4.35
+0.4.36

+ 50 - 0
scripts/examples/gn_p6_example.sh

@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+#
+#    Copyright (c) 2021 Project CHIP Authors
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+
+set -e
+# Build script for GN P6 examples GitHub workflow.
+source "$(dirname "$0")/../../scripts/activate.sh"
+
+# Install required software
+if [ -d "/opt/ModusToolbox" ]; then
+    export CY_TOOLS_PATHS="/opt/ModusToolbox/tools_2.3"
+elif [ -d "$HOME/ModusToolbox" ]; then
+    # Set CY TOOLS PATH
+    export CY_TOOLS_PATHS="$HOME/ModusToolbox/tools_2.3"
+else
+    # Install Modustoolbox
+    curl --fail --location --silent --show-error http://dlm.cypress.com.edgesuite.net/akdlm/downloadmanager/software/ModusToolbox/ModusToolbox_2.3/ModusToolbox_2.3.0.4276-linux-install.tar.gz -o /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz &&
+        tar -C "$HOME" -zxf /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz &&
+        rm /tmp/ModusToolbox_2.3.0.4276-linux-install.tar.gz
+
+    # Set CY TOOLS PATH
+    export CY_TOOLS_PATHS="$HOME/ModusToolbox/tools_2.3"
+fi
+
+set -x
+env
+
+# Build steps
+EXAMPLE_DIR=$1
+OUTPUT_DIR=out/lock_app_p6
+P6_BOARD=CY8CKIT-062S2-43012
+
+gn gen --check --fail-on-unused-args "$OUTPUT_DIR" --root="$EXAMPLE_DIR" --args="p6_board=\"$P6_BOARD\""
+ninja -C "$OUTPUT_DIR"
+#print stats
+arm-none-eabi-size -A "$OUTPUT_DIR"/*.out

+ 150 - 0
scripts/flashing/p6_firmware_utils.py

@@ -0,0 +1,150 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Flash an P6 device.
+
+This is layered so that a caller can perform individual operations
+through an `Flasher` instance, or operations according to a command line.
+For `Flasher`, see the class documentation. For the parse_command()
+interface or standalone execution:
+
+usage: p6_firmware_utils.py [-h] [--verbose] [--erase] [--application FILE]
+                               [--verify_application] [--reset] [--skip_reset]
+                               [--device DEVICE]
+
+Flash P6 device
+
+optional arguments:
+  -h, --help            show this help message and exit
+
+configuration:
+  --verbose, -v         Report more verbosely
+  --device DEVICE, -d DEVICE
+                        Device family or platform to target
+
+operations:
+  --erase               Erase device
+  --application FILE    Flash an image
+  --verify_application, --verify-application
+                        Verify the image after flashing
+  --reset               Reset device after flashing
+  --skip_reset, --skip-reset
+                        Do not reset device after flashing
+"""
+
+import sys
+from shutil import which
+
+import firmware_utils
+
+# Additional options that can be use to configure an `Flasher`
+# object (as dictionary keys) and/or passed as command line options.
+P6_OPTIONS = {
+    # Configuration options define properties used in flashing operations.
+    'configuration': {
+        'make': {
+            'help': 'File name of the make executable',
+            'default': None,
+            'argparse': {
+                'metavar': 'FILE',
+            },
+            'command': [
+                "make",
+                "-C",
+                {'option': 'sdk_path'},
+                ['TARGET={device}'],
+                ['CY_OPENOCD_PROGRAM_IMG=../../../{application}'],
+                {'option': 'mtb_target'}
+            ],
+            'verify': ['{make}', '--version'],
+            'error':
+                """\
+                Unable to execute {make}.
+
+                Please ensure that make is installed.
+                """,
+        },
+        'device': {
+            'help': 'Device family or platform to target',
+            'default': 'P6',
+            'alias': ['-d'],
+            'argparse': {
+                'metavar': 'DEVICE'
+            },
+        },
+        'sdk_path': {
+            'help': 'Path to p6 sdk',
+            'default': 'third_party/p6/p6_sdk',
+            'alias': ['-p'],
+            'argparse': {
+                'metavar': 'SDK_PATH'
+            },
+        },
+    },
+}
+
+class Flasher(firmware_utils.Flasher):
+    """Manage P6 flashing."""
+
+    def __init__(self, **options):
+        super().__init__(platform='P6', module=__name__, **options)
+        self.define_options(P6_OPTIONS)
+
+    def erase(self):
+        raise NotImplementedError()
+
+    def verify(self, image):
+        raise NotImplementedError()
+
+    def flash(self, image):
+        """Flash image."""
+        return self.run_tool(
+            'make',
+            [],
+            options={"mtb_target": "qprogram", "application": image},
+            name='Flash')
+
+    def reset(self):
+        raise NotImplementedError()
+
+    def actions(self):
+        """Perform actions on the device according to self.option."""
+        self.log(3, 'Options:', self.option)
+
+        if self.option.erase:
+            if self.erase().err:
+                return self
+
+        application = self.optional_file(self.option.application)
+        if application:
+            if self.flash(application).err:
+                return self
+            if self.option.verify_application:
+                if self.verify(application).err:
+                    return self
+
+        if self.option.reset:
+            if self.reset().err:
+                return self
+
+        return self
+
+    def locate_tool(self, tool):
+        if tool == "make":
+            return which("make")
+        else:
+            return tool
+
+if __name__ == '__main__':
+    sys.exit(Flasher().flash_command(sys.argv))

+ 7 - 1
src/lwip/BUILD.gn

@@ -31,7 +31,7 @@ if (lwip_platform == "") {
 assert(lwip_platform == "external" || lwip_platform == "standalone" ||
            lwip_platform == "cc13x2_26x2" || lwip_platform == "efr32" ||
            lwip_platform == "k32w" || lwip_platform == "qpg" ||
-           lwip_platform == "mbed",
+           lwip_platform == "mbed" || lwip_platform == "p6",
        "Unsupported lwIP platform: ${lwip_platform}")
 
 if (lwip_platform != "external") {
@@ -49,6 +49,8 @@ if (lwip_platform == "cc13x2_26x2") {
   import("//build_overrides/qpg_sdk.gni")
 } else if (lwip_platform == "k32w") {
   import("//build_overrides/k32w_sdk.gni")
+} else if (lwip_platform == "p6") {
+  import("//build_overrides/p6.gni")
 }
 
 buildconfig_header("lwip_buildconfig") {
@@ -125,5 +127,9 @@ if (current_os == "zephyr" || current_os == "mbed") {
       ":lwip_config",
       "${chip_root}/src:includes",
     ]
+
+    if (lwip_platform == "p6") {
+      public_configs += [ "${p6_sdk_build_root}:p6_sdk_config" ]
+    }
   }
 }

+ 90 - 0
src/lwip/p6/arch/cc.h

@@ -0,0 +1,90 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Nest Labs, Inc.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+#ifndef CHIP_LWIP_FREERTOS_ARCH_CC_H
+#define CHIP_LWIP_FREERTOS_ARCH_CC_H
+
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#if CHIP_CONFIG_MEMORY_MGMT_MALLOC
+#include <malloc.h>
+#endif
+
+#if __cplusplus
+extern "C" {
+#endif
+
+#ifndef LWIP_NOASSERT
+#ifdef DEBUG
+#define LWIP_PLATFORM_ASSERT(MSG) assert(MSG);
+#else
+#define LWIP_PLATFORM_ASSERT(MSG)
+#endif
+#else
+#define LWIP_PLATFORM_ASSERT(message)
+#endif
+
+#ifndef BYTE_ORDER
+#if defined(__LITTLE_ENDIAN__)
+#define BYTE_ORDER LITTLE_ENDIAN
+#elif defined(__BIG_ENDIAN__)
+#define BYTE_ORDER BIG_ENDIAN
+#elif defined(__BYTE_ORDER__)
+#define BYTE_ORDER __BYTE_ORDER__
+#endif
+#endif // BYTE_ORDER
+
+#define PACK_STRUCT_STRUCT __attribute__((__packed__))
+#define PACK_STRUCT_FIELD(x) x
+
+extern void LwIPLog(const char * fmt, ...);
+#define LWIP_PLATFORM_DIAG(x)                                                                                                      \
+    do                                                                                                                             \
+    {                                                                                                                              \
+        LwIPLog x;                                                                                                                 \
+    } while (0)
+
+// Place LwIP pools into their own subsections of .bss to make it easier to see
+// their sizes in the linker map file.
+extern uint8_t __attribute__((section(".bss.lwip_ND6_QUEUE"))) memp_memory_ND6_QUEUE_base[];
+extern uint8_t __attribute__((section(".bss.lwip_IP6_REASSDATA"))) memp_memory_IP6_REASSDATA_base[];
+extern uint8_t __attribute__((section(".bss.lwip_RAW_PCB"))) memp_memory_RAW_PCB_base[];
+extern uint8_t __attribute__((section(".bss.lwip_TCP_SEG"))) memp_memory_TCP_SEG_base[];
+extern uint8_t __attribute__((section(".bss.lwip_PBUF_POOL"))) memp_memory_PBUF_POOL_base[];
+extern uint8_t __attribute__((section(".bss.lwip_FRAG_PBUF"))) memp_memory_FRAG_PBUF_base[];
+extern uint8_t __attribute__((section(".bss.lwip_PBUF"))) memp_memory_PBUF_base[];
+extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB_LISTEN"))) memp_memory_TCP_PCB_LISTEN_base[];
+extern uint8_t __attribute__((section(".bss.lwip_REASSDATA"))) memp_memory_REASSDATA_base[];
+extern uint8_t __attribute__((section(".bss.lwip_UDP_PCB"))) memp_memory_UDP_PCB_base[];
+extern uint8_t __attribute__((section(".bss.lwip_MLD6_GROUP"))) memp_memory_MLD6_GROUP_base[];
+extern uint8_t __attribute__((section(".bss.lwip_IGMP_GROUP"))) memp_memory_IGMP_GROUP_base[];
+extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB"))) memp_memory_TCP_PCB_base[];
+extern uint8_t __attribute__((section(".bss.lwip_SYS_TIMEOUT"))) memp_memory_SYS_TIMEOUT_base[];
+
+#if __cplusplus
+}
+#endif
+
+#endif /* CHIP_LWIP_FREERTOS_ARCH_CC_H */

+ 26 - 0
src/lwip/p6/arch/perf.h

@@ -0,0 +1,26 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Nest Labs, Inc.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+#ifndef CHIP_LWIP_FREERTOS_ARCH_PERF_H
+#define CHIP_LWIP_FREERTOS_ARCH_PERF_H
+
+#define PERF_START
+#define PERF_STOP(s)
+
+#endif /* CHIP_LWIP_FREERTOS_ARCH_PERF_H */

+ 208 - 0
src/lwip/p6/lwipopts.h

@@ -0,0 +1,208 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Nest Labs, Inc.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *      Compile-time configuration for LwIP on EFR32 platforms using the
+ *      Silicon Labs EFR32 SDK.
+ *
+ */
+
+#ifndef __LWIPOPTS_H__
+#define __LWIPOPTS_H__
+
+#if CHIP_HAVE_CONFIG_H
+#include <lwip/lwip_buildconfig.h>
+#endif
+
+#include <stdlib.h>
+
+#include <whd_types.h>
+
+#define NO_SYS 0
+#define MEM_ALIGNMENT (4)
+#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN + 1)
+#define LWIP_TIMEVAL_PRIVATE (0)
+#define MEM_LIBC_MALLOC (1)
+#define LWIP_COMPAT_MUTEX (0)
+#define SYS_LIGHTWEIGHT_PROT (1)
+#define LWIP_AUTOIP (0)
+#define LWIP_DHCP_AUTOIP_COOP (0)
+#define LWIP_SOCKET_SET_ERRNO 1
+#define IP_REASS_MAX_PBUFS 0
+#define IP_REASSEMBLY 0
+#define MEMP_NUM_REASSDATA 0
+#define LWIP_SO_RCVTIMEO 1
+#define LWIP_SO_RCVBUF 1
+#define SO_REUSE (1)
+#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS (1)
+#define LWIP_STATS (0)
+#define LWIP_TCPIP_CORE_LOCKING 1
+#define TCP_QUEUE_OOSEQ 0
+#define ARP_QUEUEING (0)
+#define LWIP_TCP_KEEPALIVE (0)
+
+#define LWIP_SOCKET 1
+#define LWIP_NETCONN (1)
+
+#define LWIP_FREERTOS_USE_STATIC_TCPIP_TASK 0
+
+// TODO: seems like this is unnecessary on Thread-only platforms
+#define LWIP_RAW 1
+#define MEMP_NUM_RAW_PCB (5)
+
+// TODO: verify count
+#define MEMP_NUM_UDP_PCB (7)
+
+#define LWIP_HAVE_LOOPIF (0)
+
+#define LWIP_NETIF_API 1
+// TODO: not sure why this is disabled
+#define LWIP_NETIF_LOOPBACK (0)
+#define PBUF_LINK_HLEN (WHD_PHYSICAL_HEADER)
+
+#define MEMP_NUM_NETCONN (16)
+
+#define ETHARP_SUPPORT_STATIC_ENTRIES 1
+
+#define LWIP_IPV4 1
+#define LWIP_IPV6 1
+#define LWIP_ARP (1)
+#define LWIP_DNS (1)
+#define LWIP_ICMP (1)
+#define LWIP_TCP (1)
+#define LWIP_UDP (1)
+#define LWIP_IGMP (1)
+#define LWIP_DHCP (1)
+#define LWIP_IPV6_REASS (0)
+#define LWIP_IPV6_DHCP6 0
+#define LWIP_IPV6_AUTOCONFIG (1)
+#define LWIP_IPV6_ROUTER_SUPPORT 0
+#define LWIP_ND6_LISTEN_RA 0
+
+#define LWIP_SO_SNDTIMEO (1)
+
+#define LWIP_ND6_NUM_NEIGHBORS (0)
+#define LWIP_ND6_NUM_DESTINATIONS (0)
+#define LWIP_ND6_NUM_PREFIXES (0)
+#define LWIP_ND6_NUM_ROUTERS (0)
+#define LWIP_ND6_MAX_MULTICAST_SOLICIT (0)
+#define LWIP_ND6_MAX_UNICAST_SOLICIT (0)
+#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT (0)
+#define LWIP_ND6_TCP_REACHABILITY_HINTS (0)
+
+#ifdef CHIP_CONFIG_EFR32MG21_PBUF_POOLS
+#define MEMP_SEPARATE_POOLS (1)
+#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)
+#define MEMP_USE_CUSTOM_POOLS (0)
+#define PBUF_POOL_SIZE (4)
+#define PBUF_POOL_BUFSIZE (1500)
+#define PBUF_POOL_SIZE_LARGE (1)
+#define PBUF_POOL_SIZE_MEDIUM (2)
+#define PBUF_POOL_SIZE_SMALL (2)
+#define PBUF_POOL_BUFSIZE_LARGE (1280)
+#define PBUF_POOL_BUFSIZE_MEDIUM (640)
+#define PBUF_POOL_BUFSIZE_SMALL (256)
+#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL)
+#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE)
+#else
+#define MEMP_SEPARATE_POOLS (1)
+#define LWIP_PBUF_FROM_CUSTOM_POOLS (0)
+#define MEMP_USE_CUSTOM_POOLS (0)
+#define PBUF_POOL_SIZE (8)
+#define PBUF_POOL_BUFSIZE (1500)
+#define PBUF_POOL_SIZE_LARGE (3)
+#define PBUF_POOL_SIZE_MEDIUM (4)
+#define PBUF_POOL_SIZE_SMALL (5)
+#define PBUF_POOL_BUFSIZE_LARGE (1280)
+#define PBUF_POOL_BUFSIZE_MEDIUM (640)
+#define PBUF_POOL_BUFSIZE_SMALL (256)
+#define PBUF_CUSTOM_POOL_IDX_START (MEMP_PBUF_POOL_SMALL)
+#define PBUF_CUSTOM_POOL_IDX_END (MEMP_PBUF_POOL_LARGE)
+#endif
+
+#define TCP_MSS (1152)
+#define TCP_SND_BUF (4 * TCP_MSS)
+#define TCP_LISTEN_BACKLOG (1)
+
+#define ETH_PAD_SIZE (0)
+#define SUB_ETHERNET_HEADER_SPACE (0)
+
+#define TCPIP_THREAD_STACKSIZE (4096)
+#define TCPIP_THREAD_PRIO (2)
+
+#define NETIF_MAX_HWADDR_LEN 8U
+
+#define LWIP_IPV6_NUM_ADDRESSES 5
+
+#define LWIP_IPV6_ND 1
+#define LWIP_ND6_QUEUEING 0
+
+#define LWIP_MULTICAST_PING 0
+
+#define TCPIP_MBOX_SIZE 6
+#define DEFAULT_RAW_RECVMBOX_SIZE 6
+#define DEFAULT_UDP_RECVMBOX_SIZE 6
+#define DEFAULT_TCP_RECVMBOX_SIZE 6
+
+#ifndef LWIP_DEBUG
+#define LWIP_DEBUG 1
+#endif
+
+#define MEMP_OVERFLOW_CHECK (0)
+#define MEMP_SANITY_CHECK (0)
+#define MEM_DEBUG (LWIP_DBG_OFF)
+#define MEMP_DEBUG (LWIP_DBG_OFF)
+#define PBUF_DEBUG (LWIP_DBG_OFF)
+#define API_LIB_DEBUG (LWIP_DBG_OFF)
+#define API_MSG_DEBUG (LWIP_DBG_OFF)
+#define TCPIP_DEBUG (LWIP_DBG_OFF)
+#define NETIF_DEBUG (LWIP_DBG_OFF)
+#define SOCKETS_DEBUG (LWIP_DBG_OFF)
+#define DEMO_DEBUG (LWIP_DBG_OFF)
+#define DHCP_DEBUG (LWIP_DBG_OFF)
+#define AUTOIP_DEBUG (LWIP_DBG_OFF)
+#define ETHARP_DEBUG (LWIP_DBG_OFF)
+#define IP_DEBUG (LWIP_DBG_OFF)
+#define IP_REASS_DEBUG (LWIP_DBG_OFF)
+#define IP6_DEBUG (LWIP_DBG_OFF)
+#define RAW_DEBUG (LWIP_DBG_OFF)
+#define ICMP_DEBUG (LWIP_DBG_OFF)
+#define UDP_DEBUG (LWIP_DBG_OFF)
+#define TCP_DEBUG (LWIP_DBG_OFF)
+#define TCP_INPUT_DEBUG (LWIP_DBG_OFF)
+#define TCP_OUTPUT_DEBUG (LWIP_DBG_OFF)
+#define TCP_RTO_DEBUG (LWIP_DBG_OFF)
+#define TCP_CWND_DEBUG (LWIP_DBG_OFF)
+#define TCP_WND_DEBUG (LWIP_DBG_OFF)
+#define TCP_FR_DEBUG (LWIP_DBG_OFF)
+#define TCP_QLEN_DEBUG (LWIP_DBG_OFF)
+#define TCP_RST_DEBUG (LWIP_DBG_OFF)
+#define PPP_DEBUG (LWIP_DBG_OFF)
+
+#define LWIP_DBG_TYPES_ON                                                                                                          \
+    (LWIP_DBG_ON | LWIP_DBG_TRACE) /* (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) */
+
+#define LWIP_RAND rand
+#define LWIP_NETIF_LINK_CALLBACK 1
+#define LWIP_NETIF_STATUS_CALLBACK 1
+#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
+#define LWIP_NETIF_REMOVE_CALLBACK 1
+#define netifapi_dhcp_release_and_stop(n) netifapi_dhcp_release(n)
+
+#endif /* __LWIPOPTS_H__ */

+ 17 - 0
src/lwip/p6/lwippools.h

@@ -0,0 +1,17 @@
+/*
+ *   Copyright (c) 2021 Project CHIP Authors
+ *   All rights reserved.
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */

+ 7 - 0
src/platform/BUILD.gn

@@ -144,6 +144,11 @@ if (chip_device_platform != "none") {
         "CHIP_DEVICE_LAYER_TARGET_ESP32=1",
         "CHIP_DEVICE_LAYER_TARGET=ESP32",
       ]
+    } else if (chip_device_platform == "p6") {
+      defines += [
+        "CHIP_DEVICE_LAYER_TARGET_P6=1",
+        "CHIP_DEVICE_LAYER_TARGET=P6",
+      ]
     } else if (chip_device_platform == "linux") {
       defines += [
         "CHIP_DEVICE_LAYER_TARGET_LINUX=1",
@@ -286,6 +291,8 @@ if (chip_device_platform != "none") {
       _platform_target = "mbed"
     } else if (chip_device_platform == "external") {
       _platform_target = chip_platform_target
+    } else if (chip_device_platform == "p6") {
+      _platform_target = "P6"
     } else {
       assert(false, "Unknown chip_device_platform: ${chip_device_platform}")
     }

+ 918 - 0
src/platform/P6/BLEManagerImpl.cpp

@@ -0,0 +1,918 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2020 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides an implementation of the BLEManager singleton object
+ *          for the PSoC6 platform.
+ */
+
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+
+#include <ble/CHIPBleServiceData.h>
+#include <platform/internal/BLEManager.h>
+#include <support/CodeUtils.h>
+#include <support/logging/CHIPLogging.h>
+
+extern "C" {
+#include "app_platform_cfg.h"
+#include "cycfg_bt_settings.h"
+#include "cycfg_gatt_db.h"
+}
+
+#include "cy_utils.h"
+#include "wiced_bt_stack.h"
+
+#include <wiced_bt_ble.h>
+#include <wiced_bt_gatt.h>
+
+using namespace ::chip;
+using namespace ::chip::Ble;
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+namespace {
+const ChipBleUUID chipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F,
+                                                 0x9D, 0x11 } };
+
+const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F,
+                                                 0x9D, 0x12 } };
+
+} // unnamed namespace
+
+BLEManagerImpl BLEManagerImpl::sInstance;
+
+wiced_bt_gatt_status_t app_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t * p_data);
+
+wiced_result_t BLEManagerImpl::BLEManagerCallback(wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t * p_event_data)
+{
+    switch (event)
+    {
+    case BTM_ENABLED_EVT:
+        // Post a event to _OnPlatformEvent.
+        {
+            // Register with stack to receive GATT callback
+            wiced_bt_gatt_register(app_gatts_callback);
+
+            // Inform the stack to use this app GATT database
+            wiced_bt_gatt_db_init(gatt_database, gatt_database_len, NULL);
+
+            ChipDeviceEvent bleEvent;
+            bleEvent.Type = DeviceEventType::kP6BLEEnabledEvt;
+            PlatformMgr().PostEvent(&bleEvent);
+        }
+        break;
+    }
+
+    return WICED_BT_SUCCESS;
+}
+
+CHIP_ERROR BLEManagerImpl::_Init()
+{
+    CHIP_ERROR err;
+
+    // Initialize the CHIP BleLayer.
+    err = BleLayer::Init(this, this, &SystemLayer);
+    SuccessOrExit(err);
+
+    // Configure platform specific settings for Bluetooth
+    cybt_platform_config_init(&bt_platform_cfg_settings);
+
+    // Initialize the Bluetooth stack with a callback function and stack
+    // configuration structure */
+    if (WICED_SUCCESS != wiced_bt_stack_init(BLEManagerCallback, &wiced_bt_cfg_settings))
+    {
+        printf("Error initializing BT stack\n");
+        CY_ASSERT(0);
+    }
+
+    mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
+    if (CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART)
+    {
+        mFlags.Set(Flags::kFlag_AdvertisingEnabled, true);
+    }
+    else
+    {
+        mFlags.Set(Flags::kFlag_AdvertisingEnabled, false);
+    }
+    mNumCons = 0;
+    memset(mCons, 0, sizeof(mCons));
+    memset(mDeviceName, 0, sizeof(mDeviceName));
+
+    ChipLogProgress(DeviceLayer, "BLEManagerImpl::Init() complete");
+
+    PlatformMgr().ScheduleWork(DriveBLEState, 0);
+
+exit:
+    return err;
+}
+
+CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+
+    VerifyOrExit(val != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT);
+    VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
+
+    if (val != mServiceMode)
+    {
+        mServiceMode = val;
+        PlatformMgr().ScheduleWork(DriveBLEState, 0);
+    }
+
+exit:
+    return err;
+}
+
+bool BLEManagerImpl::_IsAdvertisingEnabled(void)
+{
+    return mFlags.Has(Flags::kFlag_AdvertisingEnabled);
+}
+
+CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+
+    VerifyOrExit(mServiceMode != ConnectivityManager::kCHIPoBLEServiceMode_NotSupported, err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
+
+    if (mFlags.Has(Flags::kFlag_AdvertisingEnabled) != val)
+    {
+        mFlags.Set(Flags::kFlag_AdvertisingEnabled, val);
+        PlatformMgr().ScheduleWork(DriveBLEState, 0);
+    }
+
+exit:
+    return err;
+}
+
+/*
+ * TODO
+ */
+CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
+{
+    (void) (mode);
+
+    return CHIP_ERROR_NOT_IMPLEMENTED;
+}
+
+CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize)
+{
+    if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
+    {
+        return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+    }
+    if (strlen(mDeviceName) >= bufSize)
+    {
+        return CHIP_ERROR_BUFFER_TOO_SMALL;
+    }
+    strcpy(buf, mDeviceName);
+    ChipLogProgress(DeviceLayer, "Getting device name to : \"%s\"", mDeviceName);
+    return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
+{
+    if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
+    {
+        return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
+    }
+    if (deviceName != NULL && deviceName[0] != 0)
+    {
+        if (strlen(deviceName) >= kMaxDeviceNameLength)
+        {
+            return CHIP_ERROR_INVALID_ARGUMENT;
+        }
+        memset(mDeviceName, 0, kMaxDeviceNameLength);
+        strncpy(mDeviceName, deviceName, strlen(deviceName));
+        mFlags.Set(Flags::kFlag_DeviceNameSet, true);
+        ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName);
+    }
+    else
+    {
+        wiced_bt_cfg_settings.device_name[0] = 0;
+        mDeviceName[0]                       = 0;
+        mFlags.Set(Flags::kFlag_DeviceNameSet, false);
+    }
+
+    return CHIP_NO_ERROR;
+}
+
+uint16_t BLEManagerImpl::_NumConnections(void)
+{
+    return mNumCons;
+}
+
+void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
+{
+    switch (event->Type)
+    {
+
+    case DeviceEventType::kP6BLEEnabledEvt:
+        mFlags.Set(Flags::kFlag_StackInitialized, true);
+        PlatformMgr().ScheduleWork(DriveBLEState, 0);
+        break;
+
+    case DeviceEventType::kCHIPoBLESubscribe:
+        HandleSubscribeReceived(event->CHIPoBLESubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+        {
+            ChipDeviceEvent _event;
+            _event.Type = DeviceEventType::kCHIPoBLEConnectionEstablished;
+            PlatformMgr().PostEvent(&_event);
+        }
+        break;
+
+    case DeviceEventType::kCHIPoBLEUnsubscribe:
+        HandleUnsubscribeReceived(event->CHIPoBLEUnsubscribe.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+        break;
+
+    case DeviceEventType::kCHIPoBLEWriteReceived:
+        HandleWriteReceived(event->CHIPoBLEWriteReceived.ConId, &CHIP_BLE_SVC_ID, &chipUUID_CHIPoBLEChar_RX,
+                            PacketBufferHandle::Adopt(event->CHIPoBLEWriteReceived.Data));
+        break;
+
+    case DeviceEventType::kCHIPoBLEIndicateConfirm:
+        HandleIndicationConfirmation(event->CHIPoBLEIndicateConfirm.ConId, &CHIP_BLE_SVC_ID, &ChipUUID_CHIPoBLEChar_TX);
+        break;
+
+    case DeviceEventType::kCHIPoBLEConnectionError:
+        HandleConnectionError(event->CHIPoBLEConnectionError.ConId, event->CHIPoBLEConnectionError.Reason);
+        break;
+
+    case DeviceEventType::kFabricMembershipChange:
+    case DeviceEventType::kServiceProvisioningChange:
+    case DeviceEventType::kAccountPairingChange:
+
+        // If CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED is enabled, and there is a change to the
+        // device's provisioning state, then automatically disable CHIPoBLE advertising if the device
+        // is now fully provisioned.
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+        if (ConfigurationMgr().IsFullyProvisioned())
+        {
+            ClearFlag(mFlags, kFlag_AdvertisingEnabled);
+            ChipLogProgress(DeviceLayer, "CHIPoBLE advertising disabled because device is fully provisioned");
+        }
+#endif // CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+
+        // Force the advertising state to be refreshed to reflect new provisioning state.
+        mFlags.Set(Flags::kFlag_AdvertisingRefreshNeeded, true);
+
+        DriveBLEState();
+        break;
+
+    default:
+        break;
+    }
+}
+
+bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+    ChipLogProgress(DeviceLayer, "BLEManagerImpl::SubscribeCharacteristic() not supported");
+    return false;
+}
+
+bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+    ChipLogProgress(DeviceLayer, "BLEManagerImpl::UnsubscribeCharacteristic() not supported");
+    return false;
+}
+
+bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId)
+{
+    ChipLogProgress(DeviceLayer, "Closing BLE GATT connection (con %u)", conId);
+
+    // Initiate a GAP disconnect.
+    wiced_bt_gatt_status_t gatt_err = wiced_bt_gatt_disconnect((uint16_t) conId);
+    if (gatt_err != WICED_BT_GATT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "wiced_bt_gatt_disconnect() failed: %ld", gatt_err);
+    }
+
+    return (gatt_err == WICED_BT_GATT_SUCCESS);
+}
+
+uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const
+{
+    CHIPoBLEConState * p_conn;
+
+    /* Check if target connection state exists. */
+    p_conn = BLEManagerImpl::sInstance.GetConnectionState(conId);
+
+    if (!p_conn)
+    {
+        return wiced_bt_cfg_settings.gatt_cfg.max_mtu_size;
+    }
+    else
+    {
+        return p_conn->Mtu;
+    }
+}
+
+bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+                                    PacketBufferHandle data)
+{
+    CHIP_ERROR err                  = CHIP_NO_ERROR;
+    uint16_t dataLen                = data->DataLength();
+    wiced_bt_gatt_status_t gatt_err = WICED_BT_GATT_SUCCESS;
+    CHIPoBLEConState * conState     = GetConnectionState(conId);
+
+    VerifyOrExit(conState != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);
+
+#ifdef BLE_DEBUG
+    ChipLogDetail(DeviceLayer, "Sending indication for CHIPoBLE TX characteristic (con %u, len %u)", conId, dataLen);
+#endif
+
+    // Send a indication for the CHIPoBLE TX characteristic to the client containing the supplied data.
+    gatt_err = wiced_bt_gatt_send_indication((uint16_t) conId, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, dataLen, data->Start());
+
+exit:
+    if (gatt_err != WICED_BT_GATT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "BLEManagerImpl::SendIndication() failed: %ld", gatt_err);
+        return false;
+    }
+    return err == CHIP_NO_ERROR;
+}
+
+bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+                                      PacketBufferHandle data)
+
+{
+    ChipLogError(DeviceLayer, "BLEManagerImpl::SendWriteRequest() not supported");
+    return false;
+}
+
+bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId,
+                                     PacketBufferHandle data)
+{
+    ChipLogError(DeviceLayer, "BLEManagerImpl::SendReadRequest() not supported");
+    return false;
+}
+
+bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext,
+                                      const ChipBleUUID * svcId, const ChipBleUUID * charId)
+{
+    ChipLogError(DeviceLayer, "BLEManagerImpl::SendReadResponse() not supported");
+    return false;
+}
+
+void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) {}
+
+void BLEManagerImpl::DriveBLEState(void)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+
+    // Exit if Stack not initialized
+    VerifyOrExit(mFlags.Has(Flags::kFlag_StackInitialized), /* */);
+
+    // Perform any initialization actions that must occur after the CHIP task is running.
+    if (!mFlags.Has(Flags::kFlag_AsyncInitCompleted))
+    {
+        mFlags.Set(Flags::kFlag_AsyncInitCompleted, true);
+
+        // If CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED is enabled,
+        // disable CHIPoBLE advertising if the device is fully provisioned.
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+        if (ConfigurationMgr().IsFullyProvisioned())
+        {
+            ClearFlag(mFlags, kFlag_AdvertisingEnabled);
+            ChipLogProgress(DeviceLayer, "CHIPoBLE advertising disabled because device is fully provisioned");
+        }
+#endif // CHIP_DEVICE_CONFIG_CHIPOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED
+    }
+
+    // If the application has enabled CHIPoBLE and BLE advertising...
+    if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled &&
+        mFlags.Has(Flags::kFlag_AdvertisingEnabled)
+#if CHIP_DEVICE_CONFIG_CHIPOBLE_SINGLE_CONNECTION
+        // and no connections are active...
+        && (mNumCons == 0)
+#endif
+    )
+    {
+        // Start/re-start SoftDevice advertising if not already advertising, or if the
+        // advertising state of the SoftDevice needs to be refreshed.
+        if (!mFlags.Has(Flags::kFlag_Advertising) || mFlags.Has(Flags::kFlag_AdvertisingRefreshNeeded))
+        {
+            ChipLogProgress(DeviceLayer, "CHIPoBLE advertising started");
+
+            mFlags.Set(Flags::kFlag_Advertising, true);
+            mFlags.Set(Flags::kFlag_AdvertisingRefreshNeeded, false);
+
+            SetAdvertisingData();
+
+            wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, BLE_ADDR_PUBLIC, NULL);
+
+            // Post a CHIPoBLEAdvertisingChange(Started) event.
+            {
+                ChipDeviceEvent advChange;
+                advChange.Type                             = DeviceEventType::kCHIPoBLEAdvertisingChange;
+                advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started;
+                PlatformMgr().PostEvent(&advChange);
+            }
+        }
+    }
+
+    // Otherwise, stop advertising if currently active.
+    else
+    {
+        if (mFlags.Has(Flags::kFlag_Advertising))
+        {
+            mFlags.Set(Flags::kFlag_Advertising, false);
+
+            ChipLogProgress(DeviceLayer, "CHIPoBLE stop advertising");
+            wiced_bt_start_advertisements(BTM_BLE_ADVERT_OFF, BLE_ADDR_PUBLIC, NULL);
+        }
+    }
+
+exit:
+    if (err != CHIP_NO_ERROR)
+    {
+        ChipLogError(DeviceLayer, "Disabling CHIPoBLE service due to error: %s", ErrorStr(err));
+        mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Disabled;
+    }
+}
+
+/*
+ * This function searches through the GATT DB to point to the attribute
+ * corresponding to the given handle
+ */
+gatt_db_lookup_table_t * BLEManagerImpl::GetGattAttr(uint16_t handle)
+{
+    /* Search for the given handle in the GATT DB and return the pointer to the
+    correct attribute */
+    uint8_t array_index = 0;
+
+    for (array_index = 0; array_index < app_gatt_db_ext_attr_tbl_size; array_index++)
+    {
+        if (app_gatt_db_ext_attr_tbl[array_index].handle == handle)
+        {
+            return (&app_gatt_db_ext_attr_tbl[array_index]);
+        }
+    }
+    return NULL;
+}
+
+/*
+ * Currently there is no reason to pass Read Req to CHIP. Only process request for
+ * attributes in the GATT DB attribute table
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceRead(uint16_t conn_id, wiced_bt_gatt_read_t * p_read_data)
+{
+    gatt_db_lookup_table_t * puAttribute;
+    int attr_len_to_copy;
+
+    /* Get the right address for the handle in Gatt DB */
+    if (NULL == (puAttribute = GetGattAttr(p_read_data->handle)))
+    {
+        ChipLogError(DeviceLayer, "Read handle attribute not found. Handle:0x%X\n", p_read_data->handle);
+        return WICED_BT_GATT_INVALID_HANDLE;
+    }
+
+    attr_len_to_copy = puAttribute->cur_len;
+
+    ChipLogProgress(DeviceLayer, "GATT Read handler: conn_id:%04x handle:%04x len:%d", conn_id, p_read_data->handle,
+                    attr_len_to_copy);
+
+    /* If the incoming offset is greater than the current length in the GATT DB
+    then the data cannot be read back*/
+    if (p_read_data->offset >= puAttribute->cur_len)
+    {
+        attr_len_to_copy = 0;
+    }
+
+    /* Calculate the number of bytes and the position of the data and copy it to
+     the given pointer */
+    if (attr_len_to_copy != 0)
+    {
+        uint8_t * from;
+        int size_to_copy = attr_len_to_copy - p_read_data->offset;
+
+        if (size_to_copy > *p_read_data->p_val_len)
+        {
+            size_to_copy = *p_read_data->p_val_len;
+        }
+
+        from                    = ((uint8_t *) puAttribute->p_data) + p_read_data->offset;
+        *p_read_data->p_val_len = size_to_copy;
+
+        memcpy(p_read_data->p_val, from, size_to_copy);
+    }
+    return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * If Attribute is for CHIP, pass it through. Otherwise process request for
+ * attributes in the GATT DB attribute table.
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceWrite(uint16_t conn_id, wiced_bt_gatt_write_t * p_data)
+{
+    wiced_bt_gatt_status_t result = WICED_BT_GATT_SUCCESS;
+    gatt_db_lookup_table_t * puAttribute;
+    const uint16_t valLen = p_data->val_len;
+
+    // special handling for CHIP RX path
+    if (p_data->handle == HDLC_CHIP_SERVICE_CHAR_C1_VALUE)
+    {
+        chip::System::PacketBuffer * buf;
+        const uint16_t minBufSize = chip::System::PacketBuffer::kMaxSize + valLen;
+
+        // Attempt to allocate a packet buffer with enough space to hold the characteristic value.
+        // Note that we must use pbuf_alloc() directly, as PacketBuffer::New() is not interrupt-safe.
+        if ((buf = (chip::System::PacketBuffer *) pbuf_alloc(PBUF_RAW, minBufSize, PBUF_POOL)) != NULL)
+        {
+            // Copy the characteristic value into the packet buffer.
+            memcpy(buf->Start(), p_data->p_val, valLen);
+            buf->SetDataLength(valLen);
+#ifdef BLE_DEBUG
+            ChipLogDetail(DeviceLayer, "Write received for CHIPoBLE RX characteristic con %04x len %d", conn_id, valLen);
+#endif
+            // Post an event to the CHIP queue to deliver the data into the CHIP stack.
+            {
+                ChipDeviceEvent event;
+                event.Type                        = DeviceEventType::kCHIPoBLEWriteReceived;
+                event.CHIPoBLEWriteReceived.ConId = conn_id;
+                event.CHIPoBLEWriteReceived.Data  = buf;
+                PlatformMgr().PostEvent(&event);
+                buf = NULL;
+            }
+        }
+        else
+        {
+            ChipLogError(DeviceLayer, "BLEManagerImpl: Out of buffers during CHIPoBLE RX");
+        }
+    }
+    else
+    {
+        ChipLogDetail(DeviceLayer, "Write received for CHIPoBLE RX characteristic con:%04x handle:%04x len:%d", conn_id,
+                      p_data->handle, valLen);
+
+        /* Get the right address for the handle in Gatt DB */
+        if (NULL == (puAttribute = GetGattAttr(p_data->handle)))
+        {
+            ChipLogError(DeviceLayer, "BLEManagerImpl: Write wrong handle:%04x", p_data->handle);
+            return WICED_BT_GATT_INVALID_HANDLE;
+        }
+        puAttribute->cur_len = valLen > puAttribute->max_len ? puAttribute->max_len : valLen;
+        memcpy(puAttribute->p_data, p_data->p_val, puAttribute->cur_len);
+
+        // Post an event to the Chip queue to process either a CHIPoBLE Subscribe or Unsubscribe based on
+        // whether the client is enabling or disabling indications.
+        if (p_data->handle == HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG)
+        {
+            ChipDeviceEvent event;
+            event.Type = (app_chip_service_char_tx_client_char_config[0] != 0) ? DeviceEventType::kCHIPoBLESubscribe
+                                                                               : DeviceEventType::kCHIPoBLEUnsubscribe;
+            event.CHIPoBLESubscribe.ConId = conn_id;
+            PlatformMgr().PostEvent(&event);
+        }
+
+        ChipLogProgress(DeviceLayer, "CHIPoBLE %s received",
+                        app_chip_service_char_tx_client_char_config[0] != 0 ? "subscribe" : "unsubscribe");
+    }
+    return result;
+}
+
+/*
+ * Process MTU request received from the GATT client
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceMtuReq(wiced_bt_gatt_attribute_request_t * p_data,
+                                                               CHIPoBLEConState * p_conn)
+{
+    p_data->data.mtu = p_conn->Mtu;
+
+    return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT Indication Confirm from the client
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceIndCfm(uint16_t conn_id, uint16_t handle)
+{
+#ifdef BLE_DEBUG
+    ChipLogDetail(DeviceLayer, "GATT Ind Cfm received con:%04x handle:%d", conn_id, handle);
+#endif
+    if (handle == HDLC_CHIP_SERVICE_CHAR_C2_VALUE)
+    {
+        ChipDeviceEvent event;
+        event.Type                          = DeviceEventType::kCHIPoBLEIndicateConfirm;
+        event.CHIPoBLEIndicateConfirm.ConId = conn_id;
+        PlatformMgr().PostEvent(&event);
+    }
+    return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT attribute requests
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattServiceRequestEvent(wiced_bt_gatt_attribute_request_t * p_request,
+                                                                     CHIPoBLEConState * p_conn)
+{
+    wiced_bt_gatt_status_t result = WICED_BT_GATT_INVALID_PDU;
+
+    switch (p_request->request_type)
+    {
+    case GATTS_REQ_TYPE_READ:
+        result = HandleGattServiceRead(p_request->conn_id, &(p_request->data.read_req));
+        break;
+
+    case GATTS_REQ_TYPE_WRITE:
+        result = HandleGattServiceWrite(p_request->conn_id, &(p_request->data.write_req));
+        break;
+
+    case GATTS_REQ_TYPE_MTU:
+        result = HandleGattServiceMtuReq(p_request, p_conn);
+        break;
+
+    case GATTS_REQ_TYPE_CONF:
+        result = HandleGattServiceIndCfm(p_request->conn_id, p_request->data.handle);
+        break;
+
+    default:
+        break;
+    }
+
+    return result;
+}
+
+/*
+ * Handle GATT connection events from the stack
+ */
+wiced_bt_gatt_status_t BLEManagerImpl::HandleGattConnectEvent(wiced_bt_gatt_connection_status_t * p_conn_status,
+                                                              CHIPoBLEConState * p_conn)
+{
+    if (p_conn_status->connected)
+    {
+        /* Device got connected */
+        p_conn->connected = true;
+        ChipLogProgress(DeviceLayer, "BLE GATT connection up (con %u)", p_conn_status->conn_id);
+    }
+    else /* Device got disconnected */
+    {
+        ChipDeviceEvent event;
+        event.Type                          = DeviceEventType::kCHIPoBLEConnectionError;
+        event.CHIPoBLEConnectionError.ConId = p_conn_status->conn_id;
+
+        switch (p_conn_status->reason)
+        {
+        case GATT_CONN_TERMINATE_PEER_USER:
+            event.CHIPoBLEConnectionError.Reason = BLE_ERROR_REMOTE_DEVICE_DISCONNECTED;
+            break;
+
+        case GATT_CONN_TERMINATE_LOCAL_HOST:
+            event.CHIPoBLEConnectionError.Reason = BLE_ERROR_APP_CLOSED_CONNECTION;
+            break;
+
+        default:
+            event.CHIPoBLEConnectionError.Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
+            break;
+        }
+
+        ChipLogProgress(DeviceLayer, "BLE GATT connection closed (con %u, reason %u)", p_conn_status->conn_id,
+                        p_conn_status->reason);
+
+        PlatformMgr().PostEvent(&event);
+
+        // Arrange to re-enable connectable advertising in case it was disabled due to the
+        // maximum connection limit being reached.
+        mFlags.Set(Flags::kFlag_Advertising, false);
+        PlatformMgr().ScheduleWork(DriveBLEState, 0);
+
+        ReleaseConnectionState(p_conn->ConId);
+    }
+    return WICED_BT_GATT_SUCCESS;
+}
+
+/*
+ * Process GATT requests. Callback is received in the BT stack thread context.
+ *
+ */
+wiced_bt_gatt_status_t app_gatts_callback(wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t * p_data)
+{
+    uint16_t conn_id;
+    BLEManagerImpl::CHIPoBLEConState * p_conn;
+
+    /* Check parameter. */
+    if (!p_data)
+    {
+        return WICED_BT_GATT_ILLEGAL_PARAMETER;
+    }
+
+    /* Check if target connection state exists. */
+    switch (event)
+    {
+    case GATT_CONNECTION_STATUS_EVT:
+        conn_id = p_data->connection_status.conn_id;
+        break;
+
+    case GATT_OPERATION_CPLT_EVT:
+        conn_id = p_data->operation_complete.conn_id;
+        break;
+
+    case GATT_DISCOVERY_RESULT_EVT:
+        conn_id = p_data->discovery_result.conn_id;
+        break;
+
+    case GATT_DISCOVERY_CPLT_EVT:
+        conn_id = p_data->discovery_complete.conn_id;
+        break;
+
+    case GATT_ATTRIBUTE_REQUEST_EVT:
+        conn_id = p_data->attribute_request.conn_id;
+        break;
+
+    case GATT_CONGESTION_EVT:
+        conn_id = p_data->congestion.conn_id;
+        break;
+
+    default:
+        return WICED_BT_GATT_ILLEGAL_PARAMETER;
+    }
+
+    p_conn = BLEManagerImpl::sInstance.GetConnectionState(conn_id);
+
+    /* Allocate connection state if no exist. */
+    if (!p_conn)
+    {
+        p_conn = BLEManagerImpl::sInstance.AllocConnectionState(conn_id);
+
+        if (!p_conn)
+        {
+            return WICED_BT_GATT_INSUF_RESOURCE;
+        }
+    }
+
+    switch (event)
+    {
+    case GATT_CONNECTION_STATUS_EVT:
+        return BLEManagerImpl::sInstance.HandleGattConnectEvent(&p_data->connection_status, p_conn);
+
+    case GATT_ATTRIBUTE_REQUEST_EVT:
+        return BLEManagerImpl::sInstance.HandleGattServiceRequestEvent(&p_data->attribute_request, p_conn);
+
+    default:
+        break;
+    }
+
+    return WICED_BT_GATT_ILLEGAL_PARAMETER;
+}
+
+void BLEManagerImpl::SetAdvertisingData(void)
+{
+    CHIP_ERROR err;
+    wiced_bt_ble_advert_elem_t adv_elem[4];
+    uint8_t num_elem             = 0;
+    uint8_t flag                 = BTM_BLE_GENERAL_DISCOVERABLE_FLAG | BTM_BLE_BREDR_NOT_SUPPORTED;
+    uint8_t chip_service_uuid[2] = { BIT16_TO_8(__UUID16_CHIPoBLEService) };
+    ChipBLEDeviceIdentificationInfo mDeviceIdInfo;
+    uint16_t deviceDiscriminator = 0;
+    uint8_t localDeviceNameLen;
+    uint8_t service_data[9];
+    uint8_t * p = service_data;
+
+    // Initialize the CHIP BLE Device Identification Information block that will be sent as payload
+    // within the BLE service advertisement data.
+    err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo);
+    SuccessOrExit(err);
+
+    // Get device discriminator
+    deviceDiscriminator = mDeviceIdInfo.GetDeviceDiscriminator();
+
+    // Verify device name was not already set
+    if (!sInstance.mFlags.Has(sInstance.Flags::kFlag_DeviceNameSet))
+    {
+        /* Default device name is CHIP-<DISCRIMINATOR> */
+        memset(sInstance.mDeviceName, 0, kMaxDeviceNameLength);
+        snprintf(sInstance.mDeviceName, kMaxDeviceNameLength, "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX,
+                 deviceDiscriminator);
+        localDeviceNameLen = strlen(sInstance.mDeviceName);
+
+        strncpy((char *) app_gap_device_name, sInstance.mDeviceName, sizeof(app_gap_device_name));
+        app_gatt_db_ext_attr_tbl[0].cur_len = app_gatt_db_ext_attr_tbl[0].max_len < strlen(sInstance.mDeviceName)
+            ? app_gatt_db_ext_attr_tbl[0].max_len
+            : strlen(sInstance.mDeviceName);
+
+        ChipLogProgress(DeviceLayer, "SetAdvertisingData: device name set: %s", sInstance.mDeviceName);
+    }
+    else
+    {
+        localDeviceNameLen = strlen(sInstance.mDeviceName);
+    }
+
+    /* First element is the advertisment flags */
+    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_FLAG;
+    adv_elem[num_elem].len         = sizeof(uint8_t);
+    adv_elem[num_elem].p_data      = &flag;
+    num_elem++;
+
+    /* Second element is the service data for CHIP service */
+    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_SERVICE_DATA;
+    adv_elem[num_elem].len         = sizeof(service_data);
+    adv_elem[num_elem].p_data      = service_data;
+    num_elem++;
+    UINT8_TO_STREAM(p, chip_service_uuid[0]);
+    UINT8_TO_STREAM(p, chip_service_uuid[1]);
+    UINT8_TO_STREAM(p, 0); // CHIP BLE Opcode == 0x00 (Uncommissioned)
+    UINT16_TO_STREAM(p, deviceDiscriminator);
+    UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceVendorId[0]);
+    UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceVendorId[1]);
+    UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceProductId[0]);
+    UINT8_TO_STREAM(p, mDeviceIdInfo.DeviceProductId[1]);
+
+    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;
+    adv_elem[num_elem].len         = localDeviceNameLen;
+    adv_elem[num_elem].p_data      = (uint8_t *) sInstance.mDeviceName;
+    num_elem++;
+
+    wiced_bt_ble_set_raw_advertisement_data(num_elem, adv_elem);
+
+    /* Configure Scan Response data */
+    num_elem                       = 0;
+    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;
+    adv_elem[num_elem].len         = localDeviceNameLen;
+    adv_elem[num_elem].p_data      = (uint8_t *) sInstance.mDeviceName;
+    num_elem++;
+
+    wiced_bt_ble_set_raw_scan_response_data(num_elem, adv_elem);
+
+exit:
+    ChipLogProgress(DeviceLayer, "BLEManagerImpl::SetAdvertisingData err:%s", ErrorStr(err));
+}
+
+BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::AllocConnectionState(uint16_t conId)
+{
+    for (uint16_t i = 0; i < kMaxConnections; i++)
+    {
+        if (mCons[i].connected == false)
+        {
+            mCons[i].ConId     = conId;
+            mCons[i].Mtu       = wiced_bt_cfg_settings.gatt_cfg.max_mtu_size;
+            mCons[i].connected = false;
+
+            mNumCons++;
+
+            return &mCons[i];
+        }
+    }
+    ChipLogError(DeviceLayer, "Failed to allocate CHIPoBLEConState");
+    return NULL;
+}
+
+BLEManagerImpl::CHIPoBLEConState * BLEManagerImpl::GetConnectionState(uint16_t conId)
+{
+    for (uint16_t i = 0; i < kMaxConnections; i++)
+    {
+        if (mCons[i].ConId == conId)
+        {
+            return &mCons[i];
+        }
+    }
+    ChipLogError(DeviceLayer, "Failed to find CHIPoBLEConState");
+    return NULL;
+}
+
+bool BLEManagerImpl::ReleaseConnectionState(uint16_t conId)
+{
+    for (uint16_t i = 0; i < kMaxConnections; i++)
+    {
+        if (mCons[i].ConId == conId)
+        {
+            memset(&mCons[i], 0, sizeof(CHIPoBLEConState));
+            mNumCons--;
+            return true;
+        }
+    }
+    ChipLogError(DeviceLayer, "Failed to delete CHIPoBLEConState");
+    return false;
+}
+
+void BLEManagerImpl::DriveBLEState(intptr_t arg)
+{
+    sInstance.DriveBLEState();
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif

+ 179 - 0
src/platform/P6/BLEManagerImpl.h

@@ -0,0 +1,179 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides an implementation of the BLEManager singleton object
+ *          for the PSoC 6 platform.
+ */
+
+#pragma once
+
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+
+#include "cycfg_gatt_db.h"
+#include <wiced_bt_ble.h>
+#include <wiced_bt_gatt.h>
+#include <wiced_bt_stack.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+/**
+ * Concrete implementation of the NetworkProvisioningServer singleton object for the  PSoC 6 platform.
+ */
+class BLEManagerImpl final : public BLEManager,
+                             private Ble::BleLayer,
+                             private Ble::BlePlatformDelegate,
+                             private Ble::BleApplicationDelegate
+{
+    // Allow the BLEManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend BLEManager;
+
+    // ===== Members that implement the BLEManager internal interface.
+
+    CHIP_ERROR _Init(void);
+    CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(void);
+    CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
+    bool _IsAdvertisingEnabled(void);
+    CHIP_ERROR _SetAdvertisingEnabled(bool val);
+    bool _IsFastAdvertisingEnabled(void);
+    bool _IsAdvertising(void);
+    CHIP_ERROR _SetAdvertisingMode(BLEAdvertisingMode mode);
+    CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize);
+    CHIP_ERROR _SetDeviceName(const char * deviceName);
+    uint16_t _NumConnections(void);
+    void _OnPlatformEvent(const ChipDeviceEvent * event);
+    ::chip::Ble::BleLayer * _GetBleLayer(void);
+
+    // ===== Members that implement virtual methods on BlePlatformDelegate.
+
+    bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
+                                 const Ble::ChipBleUUID * charId) override;
+    bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId,
+                                   const Ble::ChipBleUUID * charId) override;
+    bool CloseConnection(BLE_CONNECTION_OBJECT conId) override;
+    uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override;
+    bool SendIndication(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+                        System::PacketBufferHandle data) override;
+    bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+                          System::PacketBufferHandle data) override;
+    bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId,
+                         System::PacketBufferHandle data) override;
+    bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const Ble::ChipBleUUID * svcId,
+                          const Ble::ChipBleUUID * charId) override;
+
+    // ===== Members that implement virtual methods on BleApplicationDelegate.
+
+    void NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) override;
+
+    // ===== Members for internal use by the following friends.
+
+    friend BLEManager & BLEMgr(void);
+    friend BLEManagerImpl & BLEMgrImpl(void);
+
+public:
+    static BLEManagerImpl sInstance;
+
+    // ===== Private members reserved for use by this class only.
+    enum class Flags : uint16_t
+    {
+        kFlag_AsyncInitCompleted     = 0x0001, /**< One-time asynchronous initialization actions have been performed. */
+        kFlag_AdvertisingEnabled     = 0x0002, /**< The application has enabled CHIPoBLE advertising. */
+        kFlag_FastAdvertisingEnabled = 0x0004, /**< The application has enabled fast advertising. */
+        kFlag_Advertising            = 0x0008, /**< The system is currently CHIPoBLE advertising. */
+        kFlag_AdvertisingRefreshNeeded =
+            0x0010, /**< The advertising state/configuration has changed, but the SoftDevice has yet to be updated. */
+        kFlag_DeviceNameSet    = 0x0020,
+        kFlag_StackInitialized = 0x0040,
+    };
+
+    enum
+    {
+        kMaxConnections = BLE_LAYER_NUM_BLE_ENDPOINTS,
+    };
+
+    struct CHIPoBLEConState
+    {
+        // System::PacketBuffer * PendingIndBuf;
+        uint16_t ConId;
+        uint16_t Mtu;
+        bool connected;
+    };
+
+    CHIPoBLEConState mCons[kMaxConnections];
+    uint16_t mNumCons;
+    CHIPoBLEServiceMode mServiceMode;
+    BitFlags<Flags> mFlags;
+    char mDeviceName[kMaxDeviceNameLength + 1];
+
+    void DriveBLEState(void);
+    void SetAdvertisingData(void);
+
+    wiced_bt_gatt_status_t HandleGattConnectEvent(wiced_bt_gatt_connection_status_t * p_conn_status, CHIPoBLEConState * p_conn);
+    wiced_bt_gatt_status_t HandleGattServiceRead(uint16_t conn_id, wiced_bt_gatt_read_t * p_read_data);
+    wiced_bt_gatt_status_t HandleGattServiceWrite(uint16_t conn_id, wiced_bt_gatt_write_t * p_data);
+    wiced_bt_gatt_status_t HandleGattServiceMtuReq(wiced_bt_gatt_attribute_request_t * p_data, CHIPoBLEConState * p_conn);
+    wiced_bt_gatt_status_t HandleGattServiceIndCfm(uint16_t conn_id, uint16_t handle);
+    wiced_bt_gatt_status_t HandleGattServiceRequestEvent(wiced_bt_gatt_attribute_request_t * p_request, CHIPoBLEConState * p_conn);
+
+    static wiced_result_t BLEManagerCallback(wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t * p_event_data);
+
+    CHIPoBLEConState * AllocConnectionState(uint16_t conId);
+    CHIPoBLEConState * GetConnectionState(uint16_t conId);
+    bool ReleaseConnectionState(uint16_t conId);
+    gatt_db_lookup_table_t * GetGattAttr(uint16_t handle);
+
+    static void DriveBLEState(intptr_t arg);
+};
+
+/**
+ * Returns a reference to the public interface of the BLEManager singleton object.
+ *
+ * Internal components should use this to access features of the BLEManager object
+ * that are common to all platforms.
+ */
+inline BLEManager & BLEMgr(void)
+{
+    return BLEManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the BLEManager singleton object.
+ *
+ * Internal components can use this to gain access to features of the BLEManager
+ * that are specific to the PSoC 6 platform.
+ */
+inline BLEManagerImpl & BLEMgrImpl(void)
+{
+    return BLEManagerImpl::sInstance;
+}
+
+inline Ble::BleLayer * BLEManagerImpl::_GetBleLayer()
+{
+    return this;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE

+ 73 - 0
src/platform/P6/BUILD.gn

@@ -0,0 +1,73 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/pigweed.gni")
+
+import("${chip_root}/src/platform/device.gni")
+
+assert(chip_device_platform == "p6")
+
+if (chip_enable_openthread) {
+  import("//build_overrides/openthread.gni")
+}
+
+static_library("P6") {
+  sources = [
+    "../FreeRTOS/SystemTimeSupport.cpp",
+    "BLEManagerImpl.cpp",
+    "BLEManagerImpl.h",
+    "BlePlatformConfig.h",
+    "CHIPDevicePlatformConfig.h",
+    "CHIPDevicePlatformEvent.h",
+    "CHIPPlatformConfig.h",
+    "ConfigurationManagerImpl.cpp",
+    "ConfigurationManagerImpl.h",
+    "ConnectivityManagerImpl.cpp",
+    "ConnectivityManagerImpl.h",
+    "DeviceNetworkProvisioningDelegateImpl.cpp",
+    "DeviceNetworkProvisioningDelegateImpl.h",
+    "InetPlatformConfig.h",
+    "KeyValueStoreManagerImpl.cpp",
+    "KeyValueStoreManagerImpl.h",
+    "Logging.cpp",
+    "LwIPCoreLock.cpp",
+    "MTBKeyValueStore.cpp",
+    "MTBKeyValueStore.h",
+    "P6Config.cpp",
+    "P6Config.h",
+    "P6Utils.cpp",
+    "P6Utils.h",
+    "PlatformManagerImpl.cpp",
+    "PlatformManagerImpl.h",
+    "SoftwareUpdateManagerImpl.cpp",
+    "SoftwareUpdateManagerImpl.h",
+    "SystemPlatformConfig.h",
+    "WarmPlatformConfig.h",
+    "app_platform_cfg.c",
+    "app_platform_cfg.h",
+    "cycfg_bt_settings.cpp",
+    "cycfg_bt_settings.h",
+    "cycfg_gap.cpp",
+    "cycfg_gap.h",
+    "cycfg_gatt_db.c",
+    "cycfg_gatt_db.h",
+  ]
+  deps = [ "${chip_root}/src/lib/mdns:platform_header" ]
+
+  public_deps = [
+    "${chip_root}/src/crypto",
+    "${chip_root}/src/platform:platform_base",
+  ]
+}

+ 40 - 0
src/platform/P6/BlePlatformConfig.h

@@ -0,0 +1,40 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for the CHIP BLE
+ *          Layer on the PSoC6 platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#define BLE_CONNECTION_OBJECT uint16_t
+#define BLE_CONNECTION_UNINITIALIZED ((uint16_t) 0xFFFF)
+#define BLE_MAX_RECEIVE_WINDOW_SIZE 5
+
+#define BLE_CONFIG_ERROR_FORMAT PRId32
+#define BLE_CONFIG_ERROR_TYPE cy_rslt_t
+#define BLE_CONFIG_NO_ERROR CY_RSLT_SUCCESS
+#define BLE_CONFIG_ERROR_MIN 6000000
+#define BLE_CONFIG_ERROR_MAX 6000999
+#define _BLE_CONFIG_ERROR(e) (BLE_CONFIG_ERROR_MIN + (e))

+ 45 - 0
src/platform/P6/CHIPDevicePlatformConfig.h

@@ -0,0 +1,45 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for the Chip Device Layer
+ *          on the PSoC6.
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#define CHIP_DEVICE_CONFIG_LWIP_WIFI_STATION_IF_NAME "infineon"
+
+#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0
+#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x04B4
+#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0xF155
+#define CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX "INF"
+#define CHIP_DEVICE_CONFIG_WIFI_AP_PASSWORD "AP_PASSWORD"
+#define CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL 11
+#define CHIP_DEVICE_CONFIG_WIFI_AP_SECURITY CY_WCM_SECURITY_WPA2_AES_PSK
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 8192
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY 1
+#define CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID ""
+#define CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD ""
+#define CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY CY_WCM_SECURITY_WPA2_AES_PSK
+#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
+#define CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER CONFIG_USE_TEST_SERIAL_NUMBER

+ 71 - 0
src/platform/P6/CHIPDevicePlatformEvent.h

@@ -0,0 +1,71 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Defines platform-specific event types and data for the
+ *          CHIP Device Layer on the PSoC6.
+ */
+
+#pragma once
+
+#include <platform/CHIPDeviceEvent.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+namespace DeviceEventType {
+
+/**
+ * Enumerates platform-specific event types that are visible to the application.
+ */
+enum
+{
+    kP6SystemEvent = kRange_PublicPlatformSpecific,
+};
+
+/**
+ * Enumerates internal platform-specific event types.
+ */
+enum InternalPlatformSpecificEventTypes
+{
+    // TODO: maybe need remove this and handle BLEEnabledEvt direct
+    //      from BLEManagerImpl::BLEManagerCallback.
+    kP6BLEEnabledEvt = kRange_InternalPlatformSpecific,
+    kP6BLEDisabledEvt
+};
+
+} // namespace DeviceEventType
+
+/**
+ * Represents platform-specific event information for the PSoC6 platform.
+ */
+struct ChipDevicePlatformEvent final
+{
+    union
+    {
+        struct
+        {
+            int32_t event_type;
+        } P6SystemEvent;
+    };
+};
+
+} // namespace DeviceLayer
+} // namespace chip

+ 76 - 0
src/platform/P6/CHIPPlatformConfig.h

@@ -0,0 +1,76 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for CHIP on
+ *          the PSoC6 platform.
+ */
+
+#pragma once
+
+#include "cy_result.h"
+
+// ==================== General Platform Adaptations ====================
+
+#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID "enc-msg-counter"
+// The ESP NVS implementation limits key names to 15 characters.
+#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 15
+
+#define CHIP_CONFIG_ERROR_TYPE cy_rslt_t
+#define CHIP_CONFIG_NO_ERROR CY_RSLT_SUCCESS
+#define CHIP_CONFIG_ERROR_MIN 4000000
+#define CHIP_CONFIG_ERROR_MAX 4000999
+#define CHIP_CONFIG_ERROR_FORMAT PRId32
+
+#define ASN1_CONFIG_ERROR_TYPE cy_rslt_t
+#define ASN1_CONFIG_NO_ERROR CY_RSLT_SUCCESS
+#define ASN1_CONFIG_ERROR_MIN 5000000
+#define ASN1_CONFIG_ERROR_MAX 5000999
+
+#define CHIP_LOG_FILTERING 0
+#define CHIP_CONFIG_TIME_ENABLE_CLIENT 1
+#define CHIP_CONFIG_TIME_ENABLE_SERVER 0
+
+#define ChipDie() abort()
+
+// ==================== Security Adaptations ====================
+
+#define CHIP_CONFIG_USE_OPENSSL_ECC 0
+#define CHIP_CONFIG_USE_MICRO_ECC 0
+
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1
+
+#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1
+
+#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0
+#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0
+#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 1
+
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0
+#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1
+
+#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0
+
+#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0

+ 128 - 0
src/platform/P6/ConfigurationManagerImpl.cpp

@@ -0,0 +1,128 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides the implementation of the Device Layer ConfigurationManager object
+ *          for the PSoC6.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/internal/GenericConfigurationManagerImpl.cpp>
+
+#include <platform/ConfigurationManager.h>
+#include <platform/KeyValueStoreManager.h>
+#include <platform/P6/P6Config.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+using namespace ::chip::DeviceLayer::Internal;
+
+/** Singleton instance of the ConfigurationManager implementation object for the PSoC6.
+ */
+ConfigurationManagerImpl ConfigurationManagerImpl::sInstance;
+
+CHIP_ERROR ConfigurationManagerImpl::_Init()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    bool failSafeArmed;
+
+    // Initialize the generic implementation base class.
+    err = Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>::_Init();
+    VerifyOrReturnError(CHIP_NO_ERROR == err, err);
+
+    // If the fail-safe was armed when the device last shutdown, initiate a factory reset.
+    if (_GetFailSafeArmed(failSafeArmed) == CHIP_NO_ERROR && failSafeArmed)
+    {
+        ChipLogProgress(DeviceLayer, "Detected fail-safe armed on reboot; initiating factory reset");
+        _InitiateFactoryReset();
+    }
+
+    return err;
+}
+
+CHIP_ERROR ConfigurationManagerImpl::_GetPrimaryWiFiMACAddress(uint8_t * buf)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    cy_wcm_mac_t mac;
+    result = cy_wcm_get_mac_addr(CY_WCM_INTERFACE_TYPE_STA, &mac, 1);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        err = CHIP_ERROR_INTERNAL;
+        ChipLogError(DeviceLayer, "_GetPrimaryWiFiMACAddress failed: %ld", result);
+        return err;
+    }
+
+    /* Reverse mac address to buf pointer as it is expected by caller */
+    buf[0] = mac[5];
+    buf[1] = mac[4];
+    buf[2] = mac[3];
+    buf[3] = mac[2];
+    buf[4] = mac[1];
+    buf[5] = mac[0];
+
+    return err;
+}
+
+bool ConfigurationManagerImpl::_CanFactoryReset()
+{
+    // TODO: query the application to determine if factory reset is allowed.
+    return true;
+}
+
+void ConfigurationManagerImpl::_InitiateFactoryReset()
+{
+    PlatformMgr().ScheduleWork(DoFactoryReset);
+}
+
+CHIP_ERROR ConfigurationManagerImpl::_ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value)
+{
+    uint32_t in    = 0;
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key, &in, 4);
+    value          = in;
+    return err;
+}
+
+CHIP_ERROR ConfigurationManagerImpl::_WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value)
+{
+    return PersistedStorage::KeyValueStoreMgr().Put(key, static_cast<void *>(&value), 4);
+}
+
+void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
+{
+    CHIP_ERROR err;
+
+    ChipLogProgress(DeviceLayer, "Performing factory reset");
+
+    err = FactoryResetConfig();
+    if (err != CHIP_NO_ERROR)
+    {
+        ChipLogError(DeviceLayer, "FactoryResetConfig() failed: %s", ErrorStr(err));
+    }
+
+    // Restart the system.
+    ChipLogProgress(DeviceLayer, "System restarting");
+    NVIC_SystemReset();
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 97 - 0
src/platform/P6/ConfigurationManagerImpl.h

@@ -0,0 +1,97 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides an implementation of the ConfigurationManager object
+ *          for the PSoC6 platform.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericConfigurationManagerImpl.h>
+
+#include "P6Config.h"
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the ConfigurationManager singleton object for the PSoC6 platform.
+ */
+class ConfigurationManagerImpl final : public ConfigurationManager,
+                                       public Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>,
+                                       private Internal::P6Config
+{
+    // Allow the ConfigurationManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend class ConfigurationManager;
+
+    // Allow the GenericConfigurationManagerImpl base class to access helper methods and types
+    // defined on this class.
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+    friend class Internal::GenericConfigurationManagerImpl<ConfigurationManagerImpl>;
+#endif
+
+private:
+    // ===== Members that implement the ConfigurationManager public interface.
+
+    CHIP_ERROR _Init(void);
+    CHIP_ERROR _GetPrimaryWiFiMACAddress(uint8_t * buf);
+    bool _CanFactoryReset(void);
+    void _InitiateFactoryReset(void);
+    CHIP_ERROR _ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value);
+    CHIP_ERROR _WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value);
+
+    // NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>.
+
+    // ===== Members for internal use by the following friends.
+
+    friend ConfigurationManager & ConfigurationMgr(void);
+    friend ConfigurationManagerImpl & ConfigurationMgrImpl(void);
+
+    static ConfigurationManagerImpl sInstance;
+
+    static void DoFactoryReset(intptr_t arg);
+};
+
+/**
+ * Returns the public interface of the ConfigurationManager singleton object.
+ *
+ * Chip applications should use this to access features of the ConfigurationManager object
+ * that are common to all platforms.
+ */
+inline ConfigurationManager & ConfigurationMgr(void)
+{
+    return ConfigurationManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the ConfigurationManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the ConfigurationManager
+ * that are specific to the PSoC6 platform.
+ */
+inline ConfigurationManagerImpl & ConfigurationMgrImpl(void)
+{
+    return ConfigurationManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 696 - 0
src/platform/P6/ConnectivityManagerImpl.cpp

@@ -0,0 +1,696 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/ConnectivityManager.h>
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.cpp>
+#endif
+#include <platform/internal/GenericConnectivityManagerImpl_WiFi.cpp>
+
+#include <platform/P6/P6Utils.h>
+#include <platform/internal/BLEManager.h>
+#include <support/CodeUtils.h>
+#include <support/logging/CHIPLogging.h>
+
+#include <lwip/dns.h>
+#include <lwip/ip_addr.h>
+#include <lwip/nd6.h>
+#include <lwip/netif.h>
+
+#include "lwip/opt.h"
+#include <cy_lwip.h>
+#include <type_traits>
+
+#if !CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
+#error "WiFi Station support must be enabled when building for PSoC6"
+#endif
+
+#if !CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
+#error "WiFi AP support must be enabled when building for PSoC6"
+#endif
+
+using namespace ::chip;
+using namespace ::chip::Inet;
+using namespace ::chip::System;
+using namespace ::chip::TLV;
+
+namespace chip {
+namespace DeviceLayer {
+
+ConnectivityManagerImpl ConnectivityManagerImpl::sInstance;
+
+ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void)
+{
+    return mWiFiStationMode;
+}
+
+CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(WiFiStationMode val)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    VerifyOrExit(val != kWiFiStationMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT);
+    if (val != kWiFiStationMode_ApplicationControlled)
+    {
+        mWiFiStationMode = val;
+        SystemLayer.ScheduleWork(DriveStationState, NULL);
+    }
+    if (mWiFiStationMode != val)
+    {
+        ChipLogProgress(DeviceLayer, "WiFi station mode change: %s -> %s", WiFiStationModeToStr(mWiFiStationMode),
+                        WiFiStationModeToStr(val));
+    }
+
+    mWiFiStationMode = val;
+exit:
+    return err;
+}
+
+bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void)
+{
+    return GetWiFiStationMode() == kWiFiStationMode_Enabled;
+}
+
+bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void)
+{
+    return Internal::P6Utils::IsStationProvisioned();
+}
+
+void ConnectivityManagerImpl::_ClearWiFiStationProvision(void)
+{
+    if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
+    {
+        wifi_config_t stationConfig;
+
+        memset(&stationConfig, 0, sizeof(stationConfig));
+        Internal::P6Utils::p6_wifi_set_config(WIFI_IF_STA, &stationConfig);
+
+        SystemLayer.ScheduleWork(DriveStationState, NULL);
+        SystemLayer.ScheduleWork(DriveAPState, NULL);
+    }
+}
+
+CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+
+    VerifyOrExit(val != kWiFiAPMode_NotSupported, err = CHIP_ERROR_INVALID_ARGUMENT);
+
+    if (mWiFiAPMode != val)
+    {
+        ChipLogProgress(DeviceLayer, "WiFi AP mode change: %s -> %s", WiFiAPModeToStr(mWiFiAPMode), WiFiAPModeToStr(val));
+    }
+    mWiFiAPMode = val;
+    SystemLayer.ScheduleWork(DriveAPState, NULL);
+exit:
+    return err;
+}
+
+void ConnectivityManagerImpl::_DemandStartWiFiAP(void)
+{
+    if (mWiFiAPMode == kWiFiAPMode_OnDemand || mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision)
+    {
+        mLastAPDemandTime = System::Clock::GetMonotonicMilliseconds();
+        SystemLayer.ScheduleWork(DriveAPState, NULL);
+    }
+}
+
+void ConnectivityManagerImpl::_StopOnDemandWiFiAP(void)
+{
+    if (mWiFiAPMode == kWiFiAPMode_OnDemand || mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision)
+    {
+        mLastAPDemandTime = 0;
+        SystemLayer.ScheduleWork(DriveAPState, NULL);
+    }
+}
+
+void ConnectivityManagerImpl::_MaintainOnDemandWiFiAP(void)
+{
+    if (mWiFiAPMode == kWiFiAPMode_OnDemand || mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision)
+    {
+        if (mWiFiAPState == kWiFiAPState_Activating || mWiFiAPState == kWiFiAPState_Active)
+        {
+            mLastAPDemandTime = System::Clock::GetMonotonicMilliseconds();
+        }
+    }
+}
+
+void ConnectivityManagerImpl::_SetWiFiAPIdleTimeoutMS(uint32_t val)
+{
+    mWiFiAPIdleTimeoutMS = val;
+    SystemLayer.ScheduleWork(DriveAPState, NULL);
+}
+
+CHIP_ERROR ConnectivityManagerImpl::_GetAndLogWifiStatsCounters(void)
+{
+    cy_wcm_associated_ap_info_t ap_info;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+
+    result = cy_wcm_get_associated_ap_info(&ap_info);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "cy_wcm_get_associated_ap_info failed: %d", (int) result);
+        SuccessOrExit(CHIP_ERROR_INTERNAL);
+    }
+
+    ChipLogProgress(DeviceLayer,
+                    "Wifi-Telemetry\n"
+                    "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n"
+                    "RSSI: %d\n"
+                    "Channel: %d\n"
+                    "Channel Width: %d Mhz\n",
+                    ap_info.BSSID[0], ap_info.BSSID[1], ap_info.BSSID[2], ap_info.BSSID[3], ap_info.BSSID[4], ap_info.BSSID[5],
+                    ap_info.signal_strength, ap_info.channel, ap_info.channel_width);
+exit:
+    return CHIP_NO_ERROR;
+}
+
+// ==================== ConnectivityManager Platform Internal Methods ====================
+CHIP_ERROR ConnectivityManagerImpl::_Init()
+{
+    CHIP_ERROR err                  = CHIP_NO_ERROR;
+    cy_rslt_t result                = CY_RSLT_SUCCESS;
+    mLastStationConnectFailTime     = 0;
+    mLastAPDemandTime               = 0;
+    mWiFiStationMode                = kWiFiStationMode_Disabled;
+    mWiFiStationState               = kWiFiStationState_NotConnected;
+    mWiFiAPMode                     = kWiFiAPMode_Disabled;
+    mWiFiAPState                    = kWiFiAPState_NotActive;
+    mWiFiStationReconnectIntervalMS = CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL;
+    mWiFiAPIdleTimeoutMS            = CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT;
+    mFlags.SetRaw(0);
+
+    // Ensure that P6 station mode is enabled.
+    err = Internal::P6Utils::EnableStationMode();
+    SuccessOrExit(err);
+    // If the code has been compiled with a default WiFi station provision, configure that now.
+    if (CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID[0] != 0)
+    {
+        ChipLogProgress(DeviceLayer, "Setting default WiFi station configuration (SSID: %s)", CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID);
+
+        // Set a default station configuration.
+        wifi_config_t wifiConfig;
+        memset(&wifiConfig, 0, sizeof(wifiConfig));
+        memcpy(wifiConfig.sta.ssid, CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID,
+               min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_SSID), sizeof(wifiConfig.sta.ssid)));
+        memcpy(wifiConfig.sta.password, CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD,
+               min(strlen(CHIP_DEVICE_CONFIG_DEFAULT_STA_PASSWORD), sizeof(wifiConfig.sta.password)));
+        wifiConfig.sta.security = CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY;
+        result                  = Internal::P6Utils::p6_wifi_set_config(WIFI_IF_STA, &wifiConfig);
+        if (result != CY_RSLT_SUCCESS)
+        {
+            ChipLogError(DeviceLayer, "p6_wifi_set_config() failed: %d", (int) result);
+            SuccessOrExit(CHIP_ERROR_INTERNAL);
+        }
+        err = CHIP_NO_ERROR;
+    }
+    // Force AP mode off for now.
+    err = Internal::P6Utils::SetAPMode(false);
+    SuccessOrExit(err);
+
+    // Queue work items to bootstrap the station state machines once the Chip event loop is running.
+    err = SystemLayer.ScheduleWork(DriveStationState, NULL);
+    SuccessOrExit(err);
+
+exit:
+    return err;
+}
+
+void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {}
+
+void ConnectivityManagerImpl::wlan_event_cb(cy_wcm_event_t event, cy_wcm_event_data_t * event_data)
+{
+    switch (event)
+    {
+    case CY_WCM_EVENT_CONNECTING:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_CONNECTING");
+        ConnectivityMgrImpl().ChangeWiFiStationState(kWiFiStationState_Connecting);
+        break;
+    case CY_WCM_EVENT_CONNECTED:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_CONNECTED");
+        ConnectivityMgrImpl().ChangeWiFiStationState(kWiFiStationState_Connecting_Succeeded);
+        ConnectivityMgrImpl().DriveStationState();
+        break;
+    case CY_WCM_EVENT_CONNECT_FAILED:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_CONNECT_FAILED");
+        ConnectivityMgrImpl().ChangeWiFiStationState(kWiFiStationState_Connecting_Failed);
+        ConnectivityMgrImpl().DriveStationState();
+        break;
+    case CY_WCM_EVENT_RECONNECTED:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_RECONNECTED");
+        ConnectivityMgrImpl().ChangeWiFiStationState(kWiFiStationState_Connecting_Succeeded);
+        ConnectivityMgrImpl().DriveStationState();
+        break;
+    case CY_WCM_EVENT_DISCONNECTED:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_DISCONNECTED");
+        ConnectivityMgrImpl().ChangeWiFiStationState(kWiFiStationState_Disconnecting);
+        break;
+    case CY_WCM_EVENT_IP_CHANGED:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_IP_CHANGED");
+        ConnectivityMgrImpl().OnIPAddressAvailable();
+        break;
+    case CY_WCM_EVENT_STA_JOINED_SOFTAP:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_STA_JOINED_SOFTAP");
+        break;
+    case CY_WCM_EVENT_STA_LEFT_SOFTAP:
+        ChipLogProgress(DeviceLayer, "CY_WCM_EVENT_STA_LEFT_SOFTAP");
+        break;
+    default:
+        ChipLogProgress(DeviceLayer, "UnSupported Event");
+        break;
+    }
+}
+void ConnectivityManagerImpl::_OnWiFiScanDone()
+{
+    SystemLayer.ScheduleWork(DriveStationState, NULL);
+}
+
+void ConnectivityManagerImpl::_OnWiFiStationProvisionChange()
+{
+    SystemLayer.ScheduleWork(DriveStationState, NULL);
+}
+
+void ConnectivityManagerImpl::DriveStationState(::chip::System::Layer * aLayer, void * aAppState)
+{
+    sInstance.DriveStationState();
+}
+
+void ConnectivityManagerImpl::DriveAPState(::chip::System::Layer * aLayer, void * aAppState)
+{
+    sInstance.DriveAPState();
+}
+
+void ConnectivityManagerImpl::ChangeWiFiStationState(WiFiStationState newState)
+{
+    if (mWiFiStationState != newState)
+    {
+        ChipLogProgress(DeviceLayer, "WiFi station state change: %s -> %s", WiFiStationStateToStr(mWiFiStationState),
+                        WiFiStationStateToStr(newState));
+        mWiFiStationState = newState;
+    }
+}
+
+void ConnectivityManagerImpl::ChangeWiFiAPState(WiFiAPState newState)
+{
+    if (mWiFiAPState != newState)
+    {
+        ChipLogProgress(DeviceLayer, "WiFi AP state change: %s -> %s", WiFiAPStateToStr(mWiFiAPState), WiFiAPStateToStr(newState));
+        mWiFiAPState = newState;
+    }
+}
+
+#define INITIALISER_IPV4_ADDRESS1(addr_var, addr_val) addr_var = { CY_WCM_IP_VER_V4, { .v4 = (uint32_t)(addr_val) } }
+#define MAKE_IPV4_ADDRESS1(a, b, c, d) ((((uint32_t) d) << 24) | (((uint32_t) c) << 16) | (((uint32_t) b) << 8) | ((uint32_t) a))
+static const cy_wcm_ip_setting_t ap_mode_ip_settings = {
+    INITIALISER_IPV4_ADDRESS1(.ip_address, MAKE_IPV4_ADDRESS1(192, 168, 0, 2)),
+    INITIALISER_IPV4_ADDRESS1(.gateway, MAKE_IPV4_ADDRESS1(192, 168, 0, 2)),
+    INITIALISER_IPV4_ADDRESS1(.netmask, MAKE_IPV4_ADDRESS1(255, 255, 255, 0)),
+};
+
+CHIP_ERROR ConnectivityManagerImpl::ConfigureWiFiAP()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    wifi_config_t wifiConfig;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+
+    memset(&wifiConfig.ap, 0, sizeof(wifi_config_ap_t));
+    snprintf((char *) wifiConfig.ap.ssid, sizeof(wifiConfig.ap.ssid), "%s-%04X-%04X", CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX,
+             CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID);
+    memcpy(wifiConfig.ap.password, CHIP_DEVICE_CONFIG_WIFI_AP_PASSWORD, strlen(CHIP_DEVICE_CONFIG_WIFI_AP_PASSWORD));
+    wifiConfig.ap.channel                = CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL;
+    wifiConfig.ap.security               = CHIP_DEVICE_CONFIG_WIFI_AP_SECURITY;
+    wifiConfig.ap.ip_settings.ip_address = ap_mode_ip_settings.ip_address;
+    wifiConfig.ap.ip_settings.netmask    = ap_mode_ip_settings.netmask;
+    wifiConfig.ap.ip_settings.gateway    = ap_mode_ip_settings.gateway;
+
+    ChipLogProgress(DeviceLayer, "Configuring WiFi AP: SSID %s, channel %u", wifiConfig.ap.ssid, wifiConfig.ap.channel);
+    result = Internal::P6Utils::p6_wifi_set_config(WIFI_IF_AP, &wifiConfig);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "p6_wifi_set_config(WIFI_IF_AP) failed: %d", (int) result);
+        err = CHIP_ERROR_INTERNAL;
+        SuccessOrExit(err);
+    }
+
+    err = Internal::P6Utils::p6_start_ap();
+    if (err != CHIP_NO_ERROR)
+    {
+        ChipLogError(DeviceLayer, "p6_start_ap failed: %s", chip::ErrorStr(err));
+    }
+
+exit:
+    return err;
+}
+
+void ConnectivityManagerImpl::DriveAPState()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    WiFiAPState targetState;
+    uint64_t now;
+    uint32_t apTimeout;
+    bool APModeEnabled;
+
+    // Determine if AP mode is currently enabled in the P6 WiFi layer.
+    err = Internal::P6Utils::IsAPEnabled(APModeEnabled);
+    SuccessOrExit(err);
+
+    // Adjust the Connectivity Manager's AP state to match the state in the WiFi layer.
+    if (APModeEnabled && (mWiFiAPState == kWiFiAPState_NotActive || mWiFiAPState == kWiFiAPState_Deactivating))
+    {
+        ChangeWiFiAPState(kWiFiAPState_Activating);
+    }
+    if (!APModeEnabled && (mWiFiAPState == kWiFiAPState_Active || mWiFiAPState == kWiFiAPState_Activating))
+    {
+        ChangeWiFiAPState(kWiFiAPState_Deactivating);
+    }
+    // If the AP interface is not under application control...
+    if (mWiFiAPMode != kWiFiAPMode_ApplicationControlled)
+    {
+        // Determine the target (desired) state for AP interface...
+        // The target state is 'NotActive' if the application has expressly disabled the AP interface.
+        if (mWiFiAPMode == kWiFiAPMode_Disabled)
+        {
+            targetState = kWiFiAPState_NotActive;
+        }
+
+        // The target state is 'Active' if the application has expressly enabled the AP interface.
+        else if (mWiFiAPMode == kWiFiAPMode_Enabled)
+        {
+            targetState = kWiFiAPState_Active;
+        }
+
+        // The target state is 'Active' if the AP mode is 'On demand, when no station is available'
+        // and the station interface is not provisioned or the application has disabled the station
+        // interface.
+        else if (mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision &&
+                 (!IsWiFiStationProvisioned() || GetWiFiStationMode() == kWiFiStationMode_Disabled))
+        {
+            targetState = kWiFiAPState_Active;
+        }
+
+        // The target state is 'Active' if the AP mode is one of the 'On demand' modes and there
+        // has been demand for the AP within the idle timeout period.
+        else if (mWiFiAPMode == kWiFiAPMode_OnDemand || mWiFiAPMode == kWiFiAPMode_OnDemand_NoStationProvision)
+        {
+            now = System::Clock::GetMonotonicMilliseconds();
+
+            if (mLastAPDemandTime != 0 && now < (mLastAPDemandTime + mWiFiAPIdleTimeoutMS))
+            {
+                targetState = kWiFiAPState_Active;
+
+                // Compute the amount of idle time before the AP should be deactivated and
+                // arm a timer to fire at that time.
+                apTimeout = (uint32_t)((mLastAPDemandTime + mWiFiAPIdleTimeoutMS) - now);
+                err       = SystemLayer.StartTimer(apTimeout, DriveAPState, NULL);
+                SuccessOrExit(err);
+                ChipLogProgress(DeviceLayer, "Next WiFi AP timeout in %" PRIu32 " ms", apTimeout);
+            }
+            else
+            {
+                targetState = kWiFiAPState_NotActive;
+            }
+        }
+
+        // Otherwise the target state is 'NotActive'.
+        else
+        {
+            targetState = kWiFiAPState_NotActive;
+        }
+
+        // If the current AP state does not match the target state...
+        if (mWiFiAPState != targetState)
+        {
+            // If the target state is 'Active' and the current state is NOT 'Activating', enable
+            // and configure the AP interface, and then enter the 'Activating' state.  Eventually
+            // a SYSTEM_EVENT_AP_START event will be received from the P6 WiFi layer which will
+            // cause the state to transition to 'Active'.
+            if (targetState == kWiFiAPState_Active)
+            {
+                if (mWiFiAPState != kWiFiAPState_Active)
+                {
+                    err = Internal::P6Utils::SetAPMode(true);
+                    SuccessOrExit(err);
+                    err = ConfigureWiFiAP();
+                    SuccessOrExit(err);
+                    ChangeWiFiAPState(kWiFiAPState_Active);
+                }
+            }
+
+            // Otherwise, if the target state is 'NotActive' and the current state is not 'Deactivating',
+            // disable the AP interface and enter the 'Deactivating' state.  Later a SYSTEM_EVENT_AP_STOP
+            // event will move the AP state to 'NotActive'.
+            else
+            {
+                if (mWiFiAPState != kWiFiAPState_Deactivating)
+                {
+                    err = Internal::P6Utils::SetAPMode(false);
+                    SuccessOrExit(err);
+                    err = Internal::P6Utils::p6_stop_ap();
+                    SuccessOrExit(err);
+                    ChangeWiFiAPState(kWiFiAPState_Deactivating);
+                }
+            }
+        }
+    }
+
+exit:
+    if (err != CHIP_NO_ERROR && mWiFiAPMode != kWiFiAPMode_ApplicationControlled)
+    {
+        SetWiFiAPMode(kWiFiAPMode_Disabled);
+        Internal::P6Utils::SetAPMode(false);
+        Internal::P6Utils::p6_stop_ap();
+    }
+}
+
+void ConnectivityManagerImpl::DriveStationState()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    bool stationConnected;
+
+    // If the station interface is NOT under application control...
+    if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
+    {
+        // Ensure that the P6 WiFi layer is started.
+        err = WiFi_init();
+        SuccessOrExit(err);
+
+        // Ensure that station mode is enabled in the P6 WiFi layer.
+        err = Internal::P6Utils::EnableStationMode();
+        SuccessOrExit(err);
+    }
+
+    // Determine if the P6 WiFi layer thinks the station interface is currently connected.
+    err = Internal::P6Utils::IsStationConnected(stationConnected);
+    SuccessOrExit(err);
+    // If the station interface is currently connected ...
+    if (stationConnected)
+    {
+        // Advance the station state to Connected if it was previously NotConnected or
+        // a previously initiated connect attempt succeeded.
+        if (mWiFiStationState == kWiFiStationState_NotConnected || mWiFiStationState == kWiFiStationState_Connecting_Succeeded)
+        {
+            ChangeWiFiStationState(kWiFiStationState_Connected);
+            ChipLogProgress(DeviceLayer, "WiFi station interface connected");
+            mLastStationConnectFailTime = 0;
+        }
+
+        // If the WiFi station interface is no longer enabled, or no longer provisioned,
+        // disconnect the station from the AP, unless the WiFi station mode is currently
+        // under application control.
+        if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled &&
+            (mWiFiStationMode != kWiFiStationMode_Enabled || !IsWiFiStationProvisioned()))
+        {
+            ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface");
+            err = Internal::P6Utils::p6_wifi_disconnect();
+            if (err != CHIP_NO_ERROR)
+            {
+                ChipLogError(DeviceLayer, "p6_wifi_disconnect() failed: %s", chip::ErrorStr(err));
+            }
+            SuccessOrExit(err);
+
+            ChangeWiFiStationState(kWiFiStationState_Disconnecting);
+        }
+    }
+    // Otherwise the station interface is NOT connected to an AP, so...
+    else
+    {
+        uint32_t now = static_cast<uint32_t>(System::Clock::GetMonotonicMilliseconds());
+
+        // Advance the station state to NotConnected if it was previously Connected or Disconnecting,
+        // or if a previous initiated connect attempt failed.
+        if (mWiFiStationState == kWiFiStationState_Connected || mWiFiStationState == kWiFiStationState_Disconnecting ||
+            mWiFiStationState == kWiFiStationState_Connecting_Failed)
+        {
+            WiFiStationState prevState = mWiFiStationState;
+            ChangeWiFiStationState(kWiFiStationState_NotConnected);
+            if (prevState != kWiFiStationState_Connecting_Failed)
+            {
+                ChipLogProgress(DeviceLayer, "WiFi station interface disconnected");
+                mLastStationConnectFailTime = 0;
+            }
+            else
+            {
+                mLastStationConnectFailTime = now;
+            }
+        }
+        // If the WiFi station interface is now enabled and provisioned (and by implication,
+        // not presently under application control), AND the system is not in the process of
+        // scanning, then...
+        if (mWiFiStationMode == kWiFiStationMode_Enabled && IsWiFiStationProvisioned())
+        {
+            // Initiate a connection to the AP if we haven't done so before, or if enough
+            // time has passed since the last attempt.
+            if (mLastStationConnectFailTime == 0 || now >= mLastStationConnectFailTime + mWiFiStationReconnectIntervalMS)
+            {
+                ChangeWiFiStationState(kWiFiStationState_Connecting);
+                ChipLogProgress(DeviceLayer, "Attempting to connect WiFi station interface");
+                err = Internal::P6Utils::p6_wifi_connect();
+                if (err != CHIP_NO_ERROR)
+                {
+                    ChipLogError(DeviceLayer, "p6_wifi_connect() failed: %s", chip::ErrorStr(err));
+                }
+                SuccessOrExit(err);
+            }
+
+            // Otherwise arrange another connection attempt at a suitable point in the future.
+            else
+            {
+                uint32_t timeToNextConnect = (uint32_t)((mLastStationConnectFailTime + mWiFiStationReconnectIntervalMS) - now);
+                ChipLogProgress(DeviceLayer, "Next WiFi station reconnect in %" PRId32 " ms ", timeToNextConnect);
+
+                err = SystemLayer.StartTimer(timeToNextConnect, DriveStationState, NULL);
+                SuccessOrExit(err);
+            }
+        }
+    }
+
+exit:
+
+    ChipLogProgress(DeviceLayer, "Done driving station state, nothing else to do...");
+    // Kick-off any pending network scan that might have been deferred due to the activity
+    // of the WiFi station.
+}
+
+void ConnectivityManagerImpl::UpdateInternetConnectivityState(void)
+{
+    bool haveIPv4Conn            = false;
+    bool haveIPv6Conn            = false;
+    const bool hadIPv4Conn       = mFlags.Has(ConnectivityFlags::kHaveIPv4InternetConnectivity);
+    const bool hadIPv6Conn       = mFlags.Has(ConnectivityFlags::kHaveIPv6InternetConnectivity);
+    struct netif * net_interface = NULL;
+    IPAddress addr;
+    bool stationConnected;
+    Internal::P6Utils::IsStationConnected(stationConnected);
+
+    ChipLogProgress(DeviceLayer, "UpdateInternetConnectivityState");
+    // If the WiFi station is currently in the connected state...
+    if ((mWiFiStationState == kWiFiStationState_Connected) || stationConnected)
+    {
+        net_interface = cy_lwip_get_interface(CY_LWIP_STA_NW_INTERFACE);
+        if (net_interface != NULL && netif_is_up(net_interface) && netif_is_link_up(net_interface))
+        {
+            if (!ip4_addr_isany(netif_ip4_addr(net_interface)) && !ip4_addr_isany(netif_ip4_gw(net_interface)))
+            {
+                haveIPv4Conn = true;
+                ChipDeviceEvent event;
+                event.Type                           = DeviceEventType::kInterfaceIpAddressChanged;
+                event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV4_Assigned;
+                PlatformMgr().PostEvent(&event);
+            }
+            // Search among the IPv6 addresses assigned to the interface for a Global Unicast
+            // address (2000::/3) that is in the valid state.  If such an address is found...
+            for (uint8_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++)
+            {
+                if (ip6_addr_islinklocal(netif_ip6_addr(net_interface, i)) &&
+                    ip6_addr_isvalid(netif_ip6_addr_state(net_interface, i)))
+                {
+                    haveIPv6Conn = true;
+                    ChipDeviceEvent event;
+                    event.Type                           = DeviceEventType::kInterfaceIpAddressChanged;
+                    event.InterfaceIpAddressChanged.Type = InterfaceIpChangeType::kIpV6_Assigned;
+                    PlatformMgr().PostEvent(&event);
+                }
+            }
+        }
+    }
+    // If the internet connectivity state has changed...
+    if (haveIPv4Conn != hadIPv4Conn || haveIPv6Conn != hadIPv6Conn)
+    {
+        // Update the current state.
+        mFlags.Set(ConnectivityFlags::kHaveIPv4InternetConnectivity, haveIPv4Conn)
+            .Set(ConnectivityFlags::kHaveIPv6InternetConnectivity, haveIPv6Conn);
+
+        // Alert other components of the state change.
+        ChipDeviceEvent event;
+        event.Type                            = DeviceEventType::kInternetConnectivityChange;
+        event.InternetConnectivityChange.IPv4 = GetConnectivityChange(hadIPv4Conn, haveIPv4Conn);
+        event.InternetConnectivityChange.IPv6 = GetConnectivityChange(hadIPv6Conn, haveIPv6Conn);
+        addr.ToString(event.InternetConnectivityChange.address);
+        PlatformMgr().PostEvent(&event);
+
+        if (haveIPv4Conn != hadIPv4Conn)
+        {
+            ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv4", (haveIPv4Conn) ? "ESTABLISHED" : "LOST");
+        }
+
+        if (haveIPv6Conn != hadIPv6Conn)
+        {
+            ChipLogProgress(DeviceLayer, "%s Internet connectivity %s", "IPv6", (haveIPv6Conn) ? "ESTABLISHED" : "LOST");
+        }
+    }
+}
+
+CHIP_ERROR ConnectivityManagerImpl::OnIPAddressAvailable(void)
+{
+    ChipLogProgress(DeviceLayer, "IP address available on WiFi station interface");
+    UpdateInternetConnectivityState();
+    return CHIP_NO_ERROR;
+}
+
+CHIP_ERROR ConnectivityManagerImpl::WiFi_init(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    err              = Internal::P6Utils::StartWiFiLayer();
+    SuccessOrExit(err);
+    /* Register event callback */
+    if (eventcallback == false)
+    {
+        result = cy_wcm_register_event_callback(ConnectivityManagerImpl::wlan_event_cb);
+        if (result != CY_RSLT_SUCCESS)
+        {
+            ChipLogError(DeviceLayer, "cy_wcm_register_event_callback failed....! \r\n");
+            err = CHIP_ERROR_INTERNAL;
+            SuccessOrExit(err);
+        }
+        eventcallback = true;
+    }
+exit:
+    return err;
+}
+
+CHIP_ERROR ConnectivityManagerImpl::ping_thread()
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    err            = Internal::P6Utils::ping_init();
+    return err;
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 212 - 0
src/platform/P6/ConnectivityManagerImpl.h

@@ -0,0 +1,212 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <platform/ConnectivityManager.h>
+#include <platform/internal/GenericConnectivityManagerImpl.h>
+#include <platform/internal/GenericConnectivityManagerImpl_WiFi.h>
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+#include <platform/internal/GenericConnectivityManagerImpl_BLE.h>
+#else
+#include <platform/internal/GenericConnectivityManagerImpl_NoBLE.h>
+#endif
+#include <platform/internal/GenericConnectivityManagerImpl_NoThread.h>
+
+#include <cy_wcm.h>
+#include <support/BitFlags.h>
+
+namespace Inet {
+class IPAddress;
+} // namespace Inet
+
+namespace chip {
+namespace DeviceLayer {
+
+class PlatformManagerImpl;
+
+/**
+ * Concrete implementation of the ConnectivityManager singleton object for the PSoC6 platform.
+ */
+class ConnectivityManagerImpl final : public ConnectivityManager,
+                                      public Internal::GenericConnectivityManagerImpl<ConnectivityManagerImpl>,
+                                      public Internal::GenericConnectivityManagerImpl_WiFi<ConnectivityManagerImpl>,
+#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
+                                      public Internal::GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>,
+#else
+                                      public Internal::GenericConnectivityManagerImpl_NoBLE<ConnectivityManagerImpl>,
+#endif
+                                      public Internal::GenericConnectivityManagerImpl_NoThread<ConnectivityManagerImpl>
+{
+
+    // Allow the ConnectivityManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend class ConnectivityManager;
+
+public:
+    CHIP_ERROR ping_thread(void);
+
+private:
+    using Flags = GenericConnectivityManagerImpl_WiFi::ConnectivityFlags;
+    // ===== Members that implement the ConnectivityManager abstract interface.
+
+    WiFiStationMode _GetWiFiStationMode(void);
+    CHIP_ERROR _SetWiFiStationMode(WiFiStationMode val);
+    bool _IsWiFiStationEnabled(void);
+    bool _IsWiFiStationApplicationControlled(void);
+    bool _IsWiFiStationConnected(void);
+    uint32_t _GetWiFiStationReconnectIntervalMS(void);
+    CHIP_ERROR _SetWiFiStationReconnectIntervalMS(uint32_t val);
+    bool _IsWiFiStationProvisioned(void);
+    void _ClearWiFiStationProvision(void);
+    CHIP_ERROR _GetAndLogWifiStatsCounters(void);
+    void ChangeWiFiStationState(WiFiStationState newState);
+    WiFiAPMode _GetWiFiAPMode(void);
+    CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val);
+    bool _IsWiFiAPActive(void);
+    bool _IsWiFiAPApplicationControlled(void);
+    void _DemandStartWiFiAP(void);
+    void _StopOnDemandWiFiAP(void);
+    void _MaintainOnDemandWiFiAP(void);
+    uint32_t _GetWiFiAPIdleTimeoutMS(void);
+    void _SetWiFiAPIdleTimeoutMS(uint32_t val);
+
+    // Internet connectivity methods
+    bool _HaveIPv4InternetConnectivity();
+    bool _HaveIPv6InternetConnectivity();
+
+    // Service connectivity methods
+    bool _HaveServiceConnectivity();
+
+    CHIP_ERROR _Init(void);
+    void _OnPlatformEvent(const ChipDeviceEvent * event);
+    bool _CanStartWiFiScan();
+    void _OnWiFiScanDone();
+    void _OnWiFiStationProvisionChange();
+
+    // ===== Members for internal use by the following friends.
+
+    friend ConnectivityManager & ConnectivityMgr(void);
+    friend ConnectivityManagerImpl & ConnectivityMgrImpl(void);
+
+    static ConnectivityManagerImpl sInstance;
+
+    // ===== Private members reserved for use by this class only.
+    uint64_t mLastStationConnectFailTime;
+    uint64_t mLastAPDemandTime;
+    WiFiStationMode mWiFiStationMode;
+    WiFiStationState mWiFiStationState;
+    WiFiAPMode mWiFiAPMode;
+    WiFiAPState mWiFiAPState;
+    uint32_t mWiFiStationReconnectIntervalMS;
+    uint32_t mWiFiAPIdleTimeoutMS;
+    BitFlags<Flags> mFlags;
+    bool eventcallback;
+
+    static void DriveStationState(::chip::System::Layer * aLayer, void * aAppState);
+    static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState);
+    void DriveStationState(void);
+    void DriveAPState(void);
+    CHIP_ERROR ConfigureWiFiAP(void);
+    void ChangeWiFiAPState(WiFiAPState newState);
+    void UpdateInternetConnectivityState(void);
+    static void wlan_event_cb(cy_wcm_event_t event, cy_wcm_event_data_t * event_data);
+    CHIP_ERROR WiFi_init(void);
+    CHIP_ERROR OnIPAddressAvailable(void);
+};
+
+inline bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled(void)
+{
+    return mWiFiStationMode == kWiFiStationMode_ApplicationControlled;
+}
+
+inline bool ConnectivityManagerImpl::_IsWiFiStationConnected(void)
+{
+    return mWiFiStationState == kWiFiStationState_Connected;
+}
+
+inline bool ConnectivityManagerImpl::_IsWiFiAPApplicationControlled(void)
+{
+    return mWiFiAPMode == kWiFiAPMode_ApplicationControlled;
+}
+
+inline uint32_t ConnectivityManagerImpl::_GetWiFiStationReconnectIntervalMS(void)
+{
+    return mWiFiStationReconnectIntervalMS;
+}
+
+inline ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode(void)
+{
+    return mWiFiAPMode;
+}
+
+inline bool ConnectivityManagerImpl::_IsWiFiAPActive(void)
+{
+    return mWiFiAPState == kWiFiAPState_Active;
+}
+
+inline uint32_t ConnectivityManagerImpl::_GetWiFiAPIdleTimeoutMS(void)
+{
+    return mWiFiAPIdleTimeoutMS;
+}
+
+inline bool ConnectivityManagerImpl::_HaveIPv4InternetConnectivity(void)
+{
+    return mFlags.Has(Flags::kHaveIPv4InternetConnectivity);
+}
+
+inline bool ConnectivityManagerImpl::_HaveIPv6InternetConnectivity(void)
+{
+    return mFlags.Has(Flags::kHaveIPv6InternetConnectivity);
+}
+
+inline bool ConnectivityManagerImpl::_CanStartWiFiScan()
+{
+    return mWiFiStationState != kWiFiStationState_Connecting;
+}
+
+inline bool ConnectivityManagerImpl::_HaveServiceConnectivity(void)
+{
+    return HaveServiceConnectivityViaThread();
+}
+
+/**
+ * Returns the public interface of the ConnectivityManager singleton object.
+ *
+ * Chip applications should use this to access features of the ConnectivityManager object
+ * that are common to all platforms.
+ */
+inline ConnectivityManager & ConnectivityMgr(void)
+{
+    return ConnectivityManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the ConnectivityManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the ConnectivityManager
+ * that are specific to the PSoC6 platform.
+ */
+inline ConnectivityManagerImpl & ConnectivityMgrImpl(void)
+{
+    return ConnectivityManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 62 - 0
src/platform/P6/DeviceNetworkProvisioningDelegateImpl.cpp

@@ -0,0 +1,62 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <support/ErrorStr.h>
+#include <support/logging/CHIPLogging.h>
+
+#include "DeviceNetworkProvisioningDelegateImpl.h"
+#include "platform/P6/P6Utils.h"
+
+namespace chip {
+namespace DeviceLayer {
+
+CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionWiFiNetwork(const char * ssid, const char * passwd)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    cy_rslt_t rslt = CY_RSLT_SUCCESS;
+
+    ChipLogProgress(NetworkProvisioning, "P6NetworkProvisioningDelegate: SSID: %s", ssid);
+    err = ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled);
+    SuccessOrExit(err);
+
+    // Set the wifi configuration
+    wifi_config_t wifi_config;
+    Internal::P6Utils::populate_wifi_config_t(&wifi_config, WIFI_IF_STA, (const cy_wcm_ssid_t *) ssid,
+                                              (const cy_wcm_passphrase_t *) passwd, CHIP_DEVICE_CONFIG_DEFAULT_STA_SECURITY);
+
+    rslt = Internal::P6Utils::p6_wifi_set_config(WIFI_IF_STA, &wifi_config);
+    if (rslt != CY_RSLT_SUCCESS)
+    {
+        err = CHIP_ERROR_INTERNAL;
+        ChipLogError(DeviceLayer, "p6_wifi_set_config() failed");
+    }
+    SuccessOrExit(err);
+
+    err = ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled);
+    SuccessOrExit(err);
+
+exit:
+    if (err != CHIP_NO_ERROR)
+    {
+        ChipLogError(NetworkProvisioning, "Failed to connect to WiFi network: %s", chip::ErrorStr(err));
+    }
+
+    return err;
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 43 - 0
src/platform/P6/DeviceNetworkProvisioningDelegateImpl.h

@@ -0,0 +1,43 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericDeviceNetworkProvisioningDelegateImpl.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+namespace Internal {
+
+template <class ImplClass>
+class GenericDeviceNetworkProvisioningDelegateImpl;
+
+} // namespace Internal
+
+class DeviceNetworkProvisioningDelegateImpl final
+    : public Internal::GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>
+{
+private:
+    friend class GenericDeviceNetworkProvisioningDelegateImpl<DeviceNetworkProvisioningDelegateImpl>;
+
+    CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd);
+    CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData) { return CHIP_ERROR_NOT_IMPLEMENTED; }
+};
+
+} // namespace DeviceLayer
+} // namespace chip

+ 80 - 0
src/platform/P6/Entropy.cpp

@@ -0,0 +1,80 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides implementations for the CHIP entropy sourcing functions
+ *          on the PSoC6 platform.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include "cyhal_trng.h"
+
+using namespace ::chip;
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+namespace {
+
+cyhal_trng_t trng;
+
+int GetEntropy_P6(uint8_t * buf, size_t bufSize)
+{
+    while (bufSize > 0)
+    {
+        uint32_t val = cyhal_trng_generate(&trng);
+        size_t n     = chip::min(bufSize, sizeof(uint32_t));
+        memcpy(buf, static_cast<void *>(&val), n);
+
+        buf += n;
+        bufSize -= n;
+    }
+
+    return 0;
+}
+
+} // unnamed namespace
+
+CHIP_ERROR InitEntropy()
+{
+    CHIP_ERROR err;
+
+    err = (cyhal_trng_init(&trng) == CY_RSLT_SUCCESS) ? CHIP_NO_ERROR : CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED;
+    SuccessOrExit(err);
+
+    // Initialize the source used by Chip to get secure random data.
+    err = ::chip::Platform::Security::InitSecureRandomDataSource(GetEntropy_P6, 64, NULL, 0);
+    SuccessOrExit(err);
+
+    // Seed the standard rand() pseudo-random generator with data from the secure random source.
+    unsigned int seed;
+    err = ::chip::Platform::Security::GetSecureRandomData((uint8_t *) &seed, sizeof(seed));
+    SuccessOrExit(err);
+    srand(seed);
+
+exit:
+    return err;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip

+ 34 - 0
src/platform/P6/InetPlatformConfig.h

@@ -0,0 +1,34 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for the CHIP Inet
+ *          Layer on the PSoC6 platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#define INET_CONFIG_ERROR_TYPE cy_rslt_t
+#define INET_CONFIG_NO_ERROR CY_RSLT_SUCCESS
+#define INET_CONFIG_ERROR_MIN 1000000
+#define INET_CONFIG_ERROR_MAX 1000999

+ 175 - 0
src/platform/P6/KeyValueStoreManagerImpl.cpp

@@ -0,0 +1,175 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific key value storage implementation for P6
+ */
+
+#include "cy_result.h"
+#include <platform/KeyValueStoreManager.h>
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
+namespace chip {
+namespace DeviceLayer {
+namespace PersistedStorage {
+
+KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance;
+
+KeyValueStoreManagerImpl::KeyValueStoreManagerImpl()
+{
+    cy_rslt_t result = mtb_key_value_store_init(&kvstore_obj);
+    init_success     = (CY_RSLT_SUCCESS == result) ? true : false;
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,
+                                          size_t offset_bytes) const
+{
+    uint8_t * local_value;
+    uint32_t actual_size;
+    uint32_t size;
+    cy_rslt_t result;
+
+    if (!init_success)
+    {
+        return CHIP_ERROR_WELL_UNINITIALIZED;
+    }
+
+    // Get the value size
+    result = mtb_kvstore_read(const_cast<mtb_kvstore_t *>(&kvstore_obj), key, NULL, &actual_size);
+
+    if ((result != CY_RSLT_SUCCESS) || (value == NULL))
+    {
+        if (read_bytes_size != nullptr)
+        {
+            *read_bytes_size = static_cast<size_t>(actual_size);
+        }
+
+        return ConvertCyResultToChip(result);
+    }
+
+    if ((actual_size > value_size) || (offset_bytes != 0))
+    {
+        size = actual_size;
+
+        local_value = (uint8_t *) malloc(actual_size);
+
+        if (local_value == NULL)
+        {
+            return CHIP_ERROR_INTERNAL;
+        }
+    }
+    else
+    {
+        size = value_size;
+
+        local_value = (uint8_t *) value;
+
+        if (actual_size < value_size)
+        {
+            // They may ask for more than what was originally stored, so we need to zero out the
+            // entire value to account for that.
+            memset(&((uint8_t *) value)[actual_size], 0, value_size - actual_size);
+        }
+    }
+
+    // Read the value
+    result = mtb_kvstore_read(const_cast<mtb_kvstore_t *>(&kvstore_obj), key, local_value, &size);
+
+    if (result != CY_RSLT_SUCCESS)
+    {
+        return ConvertCyResultToChip(result);
+    }
+
+    if (local_value != value)
+    {
+        memcpy(value, &local_value[offset_bytes], value_size);
+        free(local_value);
+    }
+
+    if (actual_size > value_size)
+    {
+        if (read_bytes_size != nullptr)
+        {
+            *read_bytes_size = static_cast<size_t>(value_size);
+        }
+
+        if ((actual_size - offset_bytes) > value_size)
+        {
+            return CHIP_ERROR_BUFFER_TOO_SMALL;
+        }
+    }
+    else if (read_bytes_size != nullptr)
+    {
+        *read_bytes_size = static_cast<size_t>(size);
+    }
+
+    return ConvertCyResultToChip(result);
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
+{
+    if (!init_success)
+    {
+        return CHIP_ERROR_WELL_UNINITIALIZED;
+    }
+
+    cy_rslt_t result = mtb_kvstore_write(&kvstore_obj, key, static_cast<const uint8_t *>(value), value_size);
+    return ConvertCyResultToChip(result);
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
+{
+    if (!init_success)
+    {
+        return CHIP_ERROR_WELL_UNINITIALIZED;
+    }
+
+    cy_rslt_t result = mtb_kvstore_delete(&kvstore_obj, key);
+    return ConvertCyResultToChip(result);
+}
+
+CHIP_ERROR KeyValueStoreManagerImpl::ConvertCyResultToChip(cy_rslt_t err) const
+{
+    switch (err)
+    {
+    case CY_RSLT_SUCCESS:
+        return CHIP_NO_ERROR;
+    case MTB_KVSTORE_BAD_PARAM_ERROR:
+        return CHIP_ERROR_INVALID_ARGUMENT;
+    case MTB_KVSTORE_STORAGE_FULL_ERROR: // Can't find a better CHIP error to translate this into
+    case MTB_KVSTORE_MEM_ALLOC_ERROR:
+        return CHIP_ERROR_BUFFER_TOO_SMALL;
+    case MTB_KVSTORE_INVALID_DATA_ERROR:
+    case MTB_KVSTORE_ERASED_DATA_ERROR:
+        return CHIP_ERROR_INTEGRITY_CHECK_FAILED;
+    case MTB_KVSTORE_ITEM_NOT_FOUND_ERROR:
+        return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
+    case MTB_KVSTORE_ALIGNMENT_ERROR:
+    default:
+        return CHIP_ERROR_INTERNAL;
+    }
+    return CHIP_ERROR_INTERNAL;
+}
+
+} // namespace PersistedStorage
+} // namespace DeviceLayer
+} // namespace chip

+ 82 - 0
src/platform/P6/KeyValueStoreManagerImpl.h

@@ -0,0 +1,82 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific key value storage implementation for P6.
+ *
+ */
+
+#pragma once
+
+#include "MTBKeyValueStore.h"
+
+namespace chip {
+namespace DeviceLayer {
+namespace PersistedStorage {
+
+class KeyValueStoreManagerImpl final : public KeyValueStoreManager
+{
+    // Allow the KeyValueStoreManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend class KeyValueStoreManager;
+
+public:
+    KeyValueStoreManagerImpl();
+    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);
+
+private:
+    // ===== Members for internal use by the following friends.
+    friend KeyValueStoreManager & KeyValueStoreMgr();
+    friend KeyValueStoreManagerImpl & KeyValueStoreMgrImpl();
+
+    static KeyValueStoreManagerImpl sInstance;
+
+    CHIP_ERROR ConvertCyResultToChip(cy_rslt_t err) const;
+
+    mtb_kvstore_t kvstore_obj;
+    bool init_success = false;
+};
+
+/**
+ * Returns the public interface of the KeyValueStoreManager singleton object.
+ *
+ * Chip applications should use this to access features of the KeyValueStoreManager object
+ * that are common to all platforms.
+ */
+inline KeyValueStoreManager & KeyValueStoreMgr(void)
+{
+    return KeyValueStoreManagerImpl::sInstance;
+}
+
+/**
+ * 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 P6 platform.
+ */
+inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void)
+{
+    return KeyValueStoreManagerImpl::sInstance;
+}
+
+} // namespace PersistedStorage
+} // namespace DeviceLayer
+} // namespace chip

+ 47 - 0
src/platform/P6/Logging.cpp

@@ -0,0 +1,47 @@
+#include <platform/logging/LogV.h>
+#include <stdio.h>
+#include <support/logging/CHIPLogging.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Called whenever a log message is emitted by Chip or LwIP.
+ *
+ * This function is intended be overridden by the application to, e.g.,
+ * schedule output of queued log entries.
+ */
+void __attribute__((weak)) OnLogOutput(void) {}
+
+} // namespace DeviceLayer
+} // namespace chip
+
+namespace chip {
+namespace Logging {
+namespace Platform {
+
+/**
+ * CHIP log output functions.
+ */
+void LogV(const char * module, uint8_t category, const char * msg, va_list v)
+{
+#if P6_LOG_ENABLED && _CHIP_USE_LOGGING
+    printf("CHIP:%s: ", module);
+    vprintf(msg, v);
+    printf("\n");
+    // Let the application know that a log message has been emitted.
+    DeviceLayer::OnLogOutput();
+#endif
+}
+
+extern "C" void P6Log(const char * aFormat, ...)
+{
+    va_list v;
+    va_start(v, aFormat);
+    LogV("P6", chip::Logging::kLogCategory_Progress, aFormat, v);
+    va_end(v);
+}
+
+} // namespace Platform
+} // namespace Logging
+} // namespace chip

+ 61 - 0
src/platform/P6/LwIPCoreLock.cpp

@@ -0,0 +1,61 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <support/logging/CHIPLogging.h>
+
+namespace {
+
+SemaphoreHandle_t LwIPCoreLock;
+
+}
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+CHIP_ERROR InitLwIPCoreLock(void)
+{
+    if (LwIPCoreLock == NULL)
+    {
+        LwIPCoreLock = xSemaphoreCreateMutex();
+        if (LwIPCoreLock == NULL)
+        {
+            ChipLogError(DeviceLayer, "Failed to create LwIP core lock");
+            return CHIP_ERROR_NO_MEMORY;
+        }
+    }
+
+    return CHIP_NO_ERROR;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip
+
+extern "C" void lock_lwip_core()
+{
+    xSemaphoreTake(LwIPCoreLock, portMAX_DELAY);
+}
+
+extern "C" void unlock_lwip_core()
+{
+    xSemaphoreGive(LwIPCoreLock);
+}

+ 108 - 0
src/platform/P6/MTBKeyValueStore.cpp

@@ -0,0 +1,108 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Implementation of a key-value store using mtb_kvstore lib
+ *
+ */
+
+#include "MTBKeyValueStore.h"
+
+namespace {
+cyhal_flash_block_info_t block_info;
+cyhal_flash_t flash_obj;
+mtb_kvstore_bd_t block_device;
+} // namespace
+
+cy_rslt_t mtb_key_value_store_init(mtb_kvstore_t * kvstore_obj)
+{
+    cyhal_flash_info_t flash_info;
+
+    // Initialize the block device
+    cy_rslt_t result = cyhal_flash_init(&flash_obj);
+    if (CY_RSLT_SUCCESS != result)
+    {
+        return result;
+    }
+
+    block_device.read         = bd_read;
+    block_device.program      = bd_program;
+    block_device.erase        = bd_erase;
+    block_device.read_size    = bd_read_size;
+    block_device.program_size = bd_program_size;
+    block_device.erase_size   = bd_erase_size;
+    block_device.context      = &flash_obj;
+
+    cyhal_flash_get_info(&flash_obj, &flash_info);
+    block_info = flash_info.blocks[flash_info.block_count - 1];
+
+    // Initialize the kv-store library
+    result = mtb_kvstore_init(kvstore_obj, block_info.start_address, block_info.size, &block_device);
+    if (CY_RSLT_SUCCESS != result)
+    {
+        cyhal_flash_free(&flash_obj);
+    }
+
+    return result;
+}
+
+uint32_t bd_read_size(void * context, uint32_t addr)
+{
+    return 1;
+}
+
+uint32_t bd_program_size(void * context, uint32_t addr)
+{
+    return block_info.page_size;
+}
+
+uint32_t bd_erase_size(void * context, uint32_t addr)
+{
+    return block_info.sector_size;
+}
+
+cy_rslt_t bd_read(void * context, uint32_t addr, uint32_t length, uint8_t * buf)
+{
+    memcpy(buf, (const uint8_t *) (addr), length);
+    return CY_RSLT_SUCCESS;
+}
+
+cy_rslt_t bd_program(void * context, uint32_t addr, uint32_t length, const uint8_t * buf)
+{
+    uint32_t prog_size = bd_program_size(context, addr);
+    CY_ASSERT(0 == (length % prog_size));
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    for (uint32_t loc = addr; (result == CY_RSLT_SUCCESS) && (loc < addr + length); loc += prog_size, buf += prog_size)
+    {
+        result = cyhal_flash_program((cyhal_flash_t *) context, loc, (const uint32_t *) buf);
+    }
+    return result;
+}
+
+cy_rslt_t bd_erase(void * context, uint32_t addr, uint32_t length)
+{
+    uint32_t erase_size = bd_erase_size(context, addr);
+    CY_ASSERT(0 == (length % erase_size));
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    for (uint32_t loc = addr; (result == CY_RSLT_SUCCESS) && (loc < addr + length); loc += erase_size)
+    {
+        result = cyhal_flash_erase((cyhal_flash_t *) context, loc);
+    }
+    return result;
+}

+ 37 - 0
src/platform/P6/MTBKeyValueStore.h

@@ -0,0 +1,37 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Implementation of a key-value store using mtb_kvstore lib
+ *
+ */
+
+#pragma once
+
+#include "cy_result.h"
+#include "cyhal_flash.h"
+#include "mtb_kvstore.h"
+
+cy_rslt_t mtb_key_value_store_init(mtb_kvstore_t * kvstore_obj);
+uint32_t bd_read_size(void * context, uint32_t addr);
+uint32_t bd_program_size(void * context, uint32_t addr);
+uint32_t bd_erase_size(void * context, uint32_t addr);
+cy_rslt_t bd_read(void * context, uint32_t addr, uint32_t length, uint8_t * buf);
+cy_rslt_t bd_program(void * context, uint32_t addr, uint32_t length, const uint8_t * buf);
+cy_rslt_t bd_erase(void * context, uint32_t addr, uint32_t length);

+ 241 - 0
src/platform/P6/P6Config.cpp

@@ -0,0 +1,241 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019-2020 Google LLC.
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Utilities for interacting with the the P6 key-value store.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <platform/KeyValueStoreManager.h>
+
+#include <platform/P6/P6Config.h>
+
+#include <core/CHIPEncoding.h>
+#include <platform/P6/P6Utils.h>
+#include <support/CHIPMem.h>
+#include <support/CHIPMemString.h>
+#include <support/CodeUtils.h>
+#include <support/logging/CHIPLogging.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices.
+
+// Namespaces used to store device configuration information.
+const char P6Config::kConfigNamespace_ChipFactory[]  = "chip-factory";
+const char P6Config::kConfigNamespace_ChipConfig[]   = "chip-config";
+const char P6Config::kConfigNamespace_ChipCounters[] = "chip-counters";
+
+// Keys stored in the chip-factory namespace
+const P6Config::Key P6Config::kConfigKey_SerialNum           = { kConfigNamespace_ChipFactory, "serial-num" };
+const P6Config::Key P6Config::kConfigKey_MfrDeviceId         = { kConfigNamespace_ChipFactory, "device-id" };
+const P6Config::Key P6Config::kConfigKey_MfrDeviceCert       = { kConfigNamespace_ChipFactory, "device-cert" };
+const P6Config::Key P6Config::kConfigKey_MfrDeviceICACerts   = { kConfigNamespace_ChipFactory, "device-ca-certs" };
+const P6Config::Key P6Config::kConfigKey_MfrDevicePrivateKey = { kConfigNamespace_ChipFactory, "device-key" };
+const P6Config::Key P6Config::kConfigKey_ProductRevision     = { kConfigNamespace_ChipFactory, "product-rev" };
+const P6Config::Key P6Config::kConfigKey_ManufacturingDate   = { kConfigNamespace_ChipFactory, "mfg-date" };
+const P6Config::Key P6Config::kConfigKey_SetupPinCode        = { kConfigNamespace_ChipFactory, "pin-code" };
+const P6Config::Key P6Config::kConfigKey_SetupDiscriminator  = { kConfigNamespace_ChipFactory, "discriminator" };
+const P6Config::Key P6Config::kConfigKey_RegulatoryLocation  = { kConfigNamespace_ChipConfig, "regulatory-location" };
+const P6Config::Key P6Config::kConfigKey_CountryCode         = { kConfigNamespace_ChipConfig, "country-code" };
+const P6Config::Key P6Config::kConfigKey_Breadcrumb          = { kConfigNamespace_ChipConfig, "breadcrumb" };
+
+// Keys stored in the chip-config namespace
+const P6Config::Key P6Config::kConfigKey_FabricId                    = { kConfigNamespace_ChipConfig, "fabric-id" };
+const P6Config::Key P6Config::kConfigKey_ServiceConfig               = { kConfigNamespace_ChipConfig, "service-config" };
+const P6Config::Key P6Config::kConfigKey_PairedAccountId             = { kConfigNamespace_ChipConfig, "account-id" };
+const P6Config::Key P6Config::kConfigKey_ServiceId                   = { kConfigNamespace_ChipConfig, "service-id" };
+const P6Config::Key P6Config::kConfigKey_GroupKeyIndex               = { kConfigNamespace_ChipConfig, "group-key-index" };
+const P6Config::Key P6Config::kConfigKey_LastUsedEpochKeyId          = { kConfigNamespace_ChipConfig, "last-ek-id" };
+const P6Config::Key P6Config::kConfigKey_FailSafeArmed               = { kConfigNamespace_ChipConfig, "fail-safe-armed" };
+const P6Config::Key P6Config::kConfigKey_WiFiStationSecType          = { kConfigNamespace_ChipConfig, "sta-sec-type" };
+const P6Config::Key P6Config::kConfigKey_OperationalDeviceId         = { kConfigNamespace_ChipConfig, "op-device-id" };
+const P6Config::Key P6Config::kConfigKey_OperationalDeviceCert       = { kConfigNamespace_ChipConfig, "op-device-cert" };
+const P6Config::Key P6Config::kConfigKey_OperationalDeviceICACerts   = { kConfigNamespace_ChipConfig, "op-device-ca-certs" };
+const P6Config::Key P6Config::kConfigKey_OperationalDevicePrivateKey = { kConfigNamespace_ChipConfig, "op-device-key" };
+
+// Prefix used for keys that contain Chip group encryption keys.
+const char P6Config::kGroupKeyNamePrefix[] = "gk-";
+
+CHIP_ERROR P6Config::ReadConfigValue(Key key, bool & val)
+{
+    bool in;
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key_str, static_cast<void *>(&in), sizeof(bool));
+    val            = in;
+    if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Config::ReadConfigValue(Key key, uint32_t & val)
+{
+    uint32_t in;
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key_str, static_cast<void *>(&in), 4);
+    val            = in;
+    if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Config::ReadConfigValue(Key key, uint64_t & val)
+{
+    uint64_t in;
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key_str, static_cast<void *>(&in), 8);
+    val            = in;
+    if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Config::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key_str, buf, bufSize, &outLen);
+    if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    CHIP_ERROR err = PersistedStorage::KeyValueStoreMgr().Get(key_str, buf, bufSize, &outLen);
+    if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Config::WriteConfigValue(Key key, bool val)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, static_cast<void *>(&val), sizeof(bool));
+}
+
+CHIP_ERROR P6Config::WriteConfigValue(Key key, uint32_t val)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, static_cast<void *>(&val), 4);
+}
+
+CHIP_ERROR P6Config::WriteConfigValue(Key key, uint64_t val)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, static_cast<void *>(&val), 8);
+}
+
+CHIP_ERROR P6Config::WriteConfigValueStr(Key key, const char * str)
+{
+    size_t size                            = strlen(str) + 1;
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, str, size);
+}
+
+CHIP_ERROR P6Config::WriteConfigValueStr(Key key, const char * str, size_t strLen)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, str, strLen);
+}
+CHIP_ERROR P6Config::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Put(key_str, static_cast<void *>(&data), dataLen);
+}
+
+CHIP_ERROR P6Config::ClearConfigValue(Key key)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    return PersistedStorage::KeyValueStoreMgr().Delete(key_str);
+}
+
+bool P6Config::ConfigValueExists(Key key)
+{
+    char key_str[MTB_KVSTORE_MAX_KEY_SIZE] = { 0 };
+    key.to_str(key_str, MTB_KVSTORE_MAX_KEY_SIZE);
+    if (PersistedStorage::KeyValueStoreMgr().Get(key_str, NULL, 0) == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
+    {
+        return false;
+    }
+
+    return true;
+}
+
+// Clear out keys in config namespace
+CHIP_ERROR P6Config::FactoryResetConfig(void)
+{
+    const Key * config_keys[] = { &kConfigKey_FabricId,
+                                  &kConfigKey_ServiceConfig,
+                                  &kConfigKey_PairedAccountId,
+                                  &kConfigKey_ServiceId,
+                                  &kConfigKey_GroupKeyIndex,
+                                  &kConfigKey_LastUsedEpochKeyId,
+                                  &kConfigKey_FailSafeArmed,
+                                  &kConfigKey_WiFiStationSecType,
+                                  &kConfigKey_OperationalDeviceId,
+                                  &kConfigKey_OperationalDeviceCert,
+                                  &kConfigKey_OperationalDeviceICACerts,
+                                  &kConfigKey_OperationalDevicePrivateKey };
+
+    for (uint32_t i = 0; i < (sizeof(config_keys) / sizeof(config_keys[0])); i++)
+    {
+        CHIP_ERROR err = ClearConfigValue(*config_keys[i]);
+        // Something unexpected happened
+        if (err != CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND && err != CHIP_NO_ERROR)
+        {
+            return err;
+        }
+    }
+
+    return CHIP_NO_ERROR;
+}
+
+void P6Config::RunConfigUnitTest() {}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip

+ 144 - 0
src/platform/P6/P6Config.h

@@ -0,0 +1,144 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019-2020 Google LLC.
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Utilities for interacting with the the P6 key-value store.
+ */
+
+#pragma once
+
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <mtb_kvstore.h>
+#include <string.h>
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+/**
+ * Provides functions and definitions for accessing device configuration information on the P6.
+ *
+ * This class is designed to be mixed-in to concrete implementation classes as a means to
+ * provide access to configuration information to generic base classes.
+ */
+class P6Config
+{
+public:
+    struct Key;
+
+    // Maximum length of a key name
+    static constexpr size_t kMaxConfigKeyNameLength = MTB_KVSTORE_MAX_KEY_SIZE;
+
+    // Namespaces used to store device configuration information.
+    static const char kConfigNamespace_ChipFactory[];
+    static const char kConfigNamespace_ChipConfig[];
+    static const char kConfigNamespace_ChipCounters[];
+
+    // Key definitions for well-known keys.
+    static const Key kConfigKey_SerialNum;
+    static const Key kConfigKey_MfrDeviceId;
+    static const Key kConfigKey_MfrDeviceCert;
+    static const Key kConfigKey_MfrDeviceICACerts;
+    static const Key kConfigKey_MfrDevicePrivateKey;
+    static const Key kConfigKey_ProductRevision;
+    static const Key kConfigKey_ManufacturingDate;
+    static const Key kConfigKey_SetupPinCode;
+    static const Key kConfigKey_FabricId;
+    static const Key kConfigKey_ServiceConfig;
+    static const Key kConfigKey_PairedAccountId;
+    static const Key kConfigKey_ServiceId;
+    static const Key kConfigKey_FabricSecret;
+    static const Key kConfigKey_GroupKeyIndex;
+    static const Key kConfigKey_LastUsedEpochKeyId;
+    static const Key kConfigKey_FailSafeArmed;
+    static const Key kConfigKey_WiFiStationSecType;
+    static const Key kConfigKey_OperationalDeviceId;
+    static const Key kConfigKey_OperationalDeviceCert;
+    static const Key kConfigKey_OperationalDeviceICACerts;
+    static const Key kConfigKey_OperationalDevicePrivateKey;
+    static const Key kConfigKey_SetupDiscriminator;
+    static const Key kConfigKey_RegulatoryLocation;
+    static const Key kConfigKey_CountryCode;
+    static const Key kConfigKey_Breadcrumb;
+
+    static const char kGroupKeyNamePrefix[];
+
+    // Config value accessors.
+    static CHIP_ERROR ReadConfigValue(Key key, bool & val);
+    static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val);
+    static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val);
+    static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen);
+    static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen);
+    static CHIP_ERROR WriteConfigValue(Key key, bool val);
+    static CHIP_ERROR WriteConfigValue(Key key, uint32_t val);
+    static CHIP_ERROR WriteConfigValue(Key key, uint64_t val);
+    static CHIP_ERROR WriteConfigValueStr(Key key, const char * str);
+    static CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen);
+    static CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen);
+    static CHIP_ERROR ClearConfigValue(Key key);
+    static bool ConfigValueExists(Key key);
+
+    static CHIP_ERROR FactoryResetConfig(void);
+
+    static void RunConfigUnitTest(void);
+};
+
+struct P6Config::Key
+{
+    const char * Namespace;
+    const char * Name;
+
+    CHIP_ERROR to_str(char * buf, size_t buf_size) const;
+    size_t len() const;
+    bool operator==(const Key & other) const;
+};
+
+inline CHIP_ERROR P6Config::Key::to_str(char * buf, size_t buf_size) const
+{
+    if (buf_size < len() + 1)
+    {
+        return CHIP_ERROR_BUFFER_TOO_SMALL;
+    }
+
+    strcpy(buf, Namespace);
+    strcat(buf, ";");
+    strcat(buf, Name);
+
+    return CHIP_NO_ERROR;
+}
+
+// Length of key str (not including terminating null char)
+inline size_t P6Config::Key::len() const
+{
+    // + 1 for separating ';'
+    size_t out_size = strlen(Namespace) + strlen(Name) + 1;
+    return out_size;
+}
+
+inline bool P6Config::Key::operator==(const Key & other) const
+{
+    return strcmp(Namespace, other.Namespace) == 0 && strcmp(Name, other.Name) == 0;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip

+ 677 - 0
src/platform/P6/P6Utils.cpp

@@ -0,0 +1,677 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          General utility methods for the P6 platform.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <cy_lwip.h>
+#include <cy_wcm.h>
+#include <platform/P6/P6Utils.h>
+#include <support/CodeUtils.h>
+#include <support/ErrorStr.h>
+#include <support/logging/CHIPLogging.h>
+
+#include "lwip/icmp.h"
+#include "lwip/inet.h"
+#include "lwip/inet_chksum.h"
+#include "lwip/mem.h"
+#include "lwip/netif.h"
+#include "lwip/opt.h"
+#include "lwip/prot/ip4.h"
+#include "lwip/raw.h"
+#include "lwip/sockets.h"
+#include "lwip/sys.h"
+#include "lwip/timeouts.h"
+
+using namespace ::chip::DeviceLayer::Internal;
+using chip::DeviceLayer::Internal::DeviceNetworkInfo;
+
+/** ping delay - in milliseconds */
+#ifndef PING_DELAY
+#define PING_DELAY 2000
+#endif
+
+/** ping identifier - must fit on a u16_t */
+#ifndef PING_ID
+#define PING_ID 0xAFAF
+#endif
+
+/** ping additional data size to include in the packet */
+#ifndef PING_DATA_SIZE
+#define PING_DATA_SIZE 64
+#endif
+
+/** ping receive timeout - in milliseconds */
+#ifndef PING_RCV_TIMEO
+#define PING_RCV_TIMEO 5000
+#endif
+
+/* Ping IP Header len for IPv4 */
+#define IP_HDR_LEN 20
+
+/* Ping Response length */
+#define PING_RESPONSE_LEN 64
+
+/* Enable Ping via Socket API or RAW API */
+#define PING_USE_SOCKETS 1
+
+namespace {
+wifi_config_t wifi_conf;
+wifi_mode_t WiFiMode;
+bool wcm_init_done;
+/* ping variables */
+const ip_addr_t * ping_target;
+u16_t ping_seq_num;
+u32_t ping_time;
+#if !PING_USE_SOCKETS
+struct raw_pcb * ping_pcb;
+#endif /* PING_USE_SOCKETS */
+} // namespace
+
+typedef struct
+{
+    struct icmp_echo_hdr hdr;
+    uint8_t data[PING_DATA_SIZE];
+} icmp_packet_t;
+
+CHIP_ERROR P6Utils::IsAPEnabled(bool & apEnabled)
+{
+    apEnabled = (WiFiMode == WIFI_MODE_AP || WiFiMode == WIFI_MODE_APSTA);
+    return CHIP_NO_ERROR;
+}
+
+bool P6Utils::IsStationProvisioned(void)
+{
+    wifi_config_t stationConfig;
+    return (p6_wifi_get_config(WIFI_IF_STA, &stationConfig) == CY_RSLT_SUCCESS &&
+            strlen((const char *) stationConfig.sta.ssid) != 0);
+}
+
+CHIP_ERROR P6Utils::IsStationConnected(bool & connected)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    connected      = cy_wcm_is_connected_to_ap();
+    return err;
+}
+
+CHIP_ERROR P6Utils::StartWiFiLayer(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    cy_wcm_config_t wcm_config;
+
+    wcm_config.interface = CY_WCM_INTERFACE_TYPE_AP_STA;
+    ChipLogProgress(DeviceLayer, "Starting P6 WiFi layer");
+
+    if (wcm_init_done == false)
+    {
+        result = cy_wcm_init(&wcm_config);
+        if (result != CY_RSLT_SUCCESS)
+        {
+            err = CHIP_ERROR_INTERNAL;
+            ChipLogError(DeviceLayer, "StartWiFiLayer() P6 Wi-Fi Started Failed: %s", chip::ErrorStr(err));
+            SuccessOrExit(err);
+        }
+        wcm_init_done = true;
+    }
+
+exit:
+    return err;
+}
+
+CHIP_ERROR P6Utils::EnableStationMode(void)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    ChipLogProgress(DeviceLayer, "EnableStationMode");
+    /* If Station Mode is already set , update Mode to APSTA Mode */
+    if (WiFiMode == WIFI_MODE_AP)
+    {
+        WiFiMode = WIFI_MODE_APSTA;
+    }
+    else
+    {
+        WiFiMode = WIFI_MODE_STA;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Utils::SetAPMode(bool enabled)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    ChipLogProgress(DeviceLayer, "SetAPMode");
+    /* If AP Mode is already set , update Mode to APSTA Mode */
+    if (enabled)
+    {
+        if (WiFiMode == WIFI_MODE_STA)
+        {
+            WiFiMode = WIFI_MODE_APSTA;
+        }
+        else
+        {
+            WiFiMode = WIFI_MODE_AP;
+        }
+    }
+    else
+    {
+        if (WiFiMode == WIFI_MODE_APSTA)
+        {
+            WiFiMode = WIFI_MODE_STA;
+        }
+        else if (WiFiMode == WIFI_MODE_AP)
+        {
+            WiFiMode = WIFI_MODE_NULL;
+        }
+    }
+    return err;
+}
+
+const char * P6Utils::WiFiModeToStr(wifi_mode_t wifiMode)
+{
+    switch (wifiMode)
+    {
+    case WIFI_MODE_NULL:
+        return "NULL";
+    case WIFI_MODE_STA:
+        return "STA";
+    case WIFI_MODE_AP:
+        return "AP";
+    case WIFI_MODE_APSTA:
+        return "STA+AP";
+    default:
+        return "(unknown)";
+    }
+}
+cy_rslt_t P6Utils::p6_wifi_set_config(wifi_interface_t interface, wifi_config_t * conf)
+{
+    if (interface == WIFI_IF_STA)
+    {
+        populate_wifi_config_t(&wifi_conf, interface, &conf->sta.ssid, &conf->sta.password, conf->sta.security);
+        ChipLogProgress(DeviceLayer, "STA %s : [%s] [%s] \r\n", __func__, wifi_conf.sta.ssid, wifi_conf.sta.password);
+    }
+    else
+    {
+        populate_wifi_config_t(&wifi_conf, interface, &conf->ap.ssid, &conf->ap.password, conf->ap.security);
+        wifi_conf.ap.channel                = conf->ap.channel;
+        wifi_conf.ap.ip_settings.ip_address = conf->ap.ip_settings.ip_address;
+        wifi_conf.ap.ip_settings.netmask    = conf->ap.ip_settings.netmask;
+        wifi_conf.ap.ip_settings.gateway    = conf->ap.ip_settings.gateway;
+        ChipLogProgress(DeviceLayer, "AP %s : [%s] [%s] channel %d\r\n", __func__, wifi_conf.ap.ssid, wifi_conf.ap.password,
+                        wifi_conf.ap.channel);
+    }
+    return CY_RSLT_SUCCESS;
+}
+
+cy_rslt_t P6Utils::p6_wifi_get_config(wifi_interface_t interface, wifi_config_t * conf)
+{
+    if (interface == WIFI_IF_STA)
+    {
+        populate_wifi_config_t(conf, interface, &wifi_conf.sta.ssid, &wifi_conf.sta.password, wifi_conf.sta.security);
+    }
+    else
+    {
+        populate_wifi_config_t(conf, interface, &wifi_conf.ap.ssid, &wifi_conf.ap.password, wifi_conf.ap.security);
+        conf->ap.channel                = wifi_conf.ap.channel;
+        conf->ap.ip_settings.ip_address = wifi_conf.ap.ip_settings.ip_address;
+        conf->ap.ip_settings.netmask    = wifi_conf.ap.ip_settings.netmask;
+        conf->ap.ip_settings.gateway    = wifi_conf.ap.ip_settings.gateway;
+        ChipLogProgress(DeviceLayer, "AP %s [%s] [%s] channel %d\r\n", __func__, wifi_conf.ap.ssid, wifi_conf.ap.password,
+                        wifi_conf.ap.channel);
+    }
+    return CY_RSLT_SUCCESS;
+}
+
+CHIP_ERROR P6Utils::GetWiFiStationProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    wifi_config_t stationConfig;
+
+    result = p6_wifi_get_config(WIFI_IF_STA, &stationConfig);
+    VerifyOrExit(result == CY_RSLT_SUCCESS, err = CHIP_ERROR_INTERNAL);
+
+    ChipLogProgress(DeviceLayer, "GetWiFiStationProvision");
+    VerifyOrExit(strlen((const char *) stationConfig.sta.ssid) != 0, err = CHIP_ERROR_INCORRECT_STATE);
+
+    netInfo.NetworkId              = kWiFiStationNetworkId;
+    netInfo.FieldPresent.NetworkId = true;
+    memcpy(netInfo.WiFiSSID, stationConfig.sta.ssid,
+           min(strlen(reinterpret_cast<char *>(stationConfig.sta.ssid)) + 1, sizeof(netInfo.WiFiSSID)));
+
+    // Enforce that netInfo wifiSSID is null terminated
+    netInfo.WiFiSSID[kMaxWiFiSSIDLength] = '\0';
+
+    if (includeCredentials)
+    {
+        static_assert(sizeof(netInfo.WiFiKey) < 255, "Our min might not fit in netInfo.WiFiKeyLen");
+        netInfo.WiFiKeyLen = static_cast<uint8_t>(min(strlen((char *) stationConfig.sta.password), sizeof(netInfo.WiFiKey)));
+        memcpy(netInfo.WiFiKey, stationConfig.sta.password, netInfo.WiFiKeyLen);
+    }
+
+exit:
+    return err;
+}
+
+CHIP_ERROR P6Utils::SetWiFiStationProvision(const Internal::DeviceNetworkInfo & netInfo)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    wifi_config_t wifiConfig;
+    ChipLogProgress(DeviceLayer, "SetWiFiStationProvision");
+    char wifiSSID[kMaxWiFiSSIDLength + 1];
+    size_t netInfoSSIDLen = strlen(netInfo.WiFiSSID);
+
+    // Ensure that P6 station mode is enabled.  This is required before p6_wifi_set_config
+    // can be called.
+    err = P6Utils::EnableStationMode();
+    SuccessOrExit(err);
+
+    // Enforce that wifiSSID is null terminated before copying it
+    memcpy(wifiSSID, netInfo.WiFiSSID, min(netInfoSSIDLen + 1, sizeof(wifiSSID)));
+    if (netInfoSSIDLen + 1 < sizeof(wifiSSID))
+    {
+        wifiSSID[netInfoSSIDLen] = '\0';
+    }
+    else
+    {
+        wifiSSID[kMaxWiFiSSIDLength] = '\0';
+    }
+
+    // Initialize an P6 wifi_config_t structure based on the new provision information.
+    populate_wifi_config_t(&wifiConfig, WIFI_IF_STA, (cy_wcm_ssid_t *) wifiSSID, (cy_wcm_passphrase_t *) netInfo.WiFiKey);
+
+    // Configure the P6 WiFi interface.
+    result = p6_wifi_set_config(WIFI_IF_STA, &wifiConfig);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "p6_wifi_set_config() failed ");
+        err = CHIP_ERROR_INTERNAL;
+    }
+    SuccessOrExit(err);
+
+    ChipLogProgress(DeviceLayer, "WiFi station provision set (SSID: %s)", netInfo.WiFiSSID);
+
+exit:
+    return err;
+}
+
+CHIP_ERROR P6Utils::ClearWiFiStationProvision(void)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    wifi_config_t stationConfig;
+    ChipLogProgress(DeviceLayer, "ClearWiFiStationProvision");
+    // Clear the P6 WiFi station configuration.
+    memset(&stationConfig.sta, 0, sizeof(stationConfig.sta));
+    p6_wifi_set_config(WIFI_IF_STA, &stationConfig);
+    return err;
+}
+
+CHIP_ERROR P6Utils::p6_wifi_disconnect(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    ChipLogProgress(DeviceLayer, "p6_wifi_disconnect");
+    result = cy_wcm_disconnect_ap();
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "p6_wifi_disconnect() failed result %ld", result);
+        err = CHIP_ERROR_INTERNAL;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Utils::p6_wifi_connect(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    wifi_config_t stationConfig;
+    cy_wcm_connect_params_t connect_param;
+    cy_wcm_ip_address_t ip_addr;
+
+    p6_wifi_get_config(WIFI_IF_STA, &stationConfig);
+    memset(&connect_param, 0, sizeof(cy_wcm_connect_params_t));
+    memset(&ip_addr, 0, sizeof(cy_wcm_ip_address_t));
+    memcpy(&connect_param.ap_credentials.SSID, &stationConfig.sta.ssid, strlen((char *) stationConfig.sta.ssid));
+    memcpy(&connect_param.ap_credentials.password, &stationConfig.sta.password, strlen((char *) stationConfig.sta.password));
+    connect_param.ap_credentials.security = stationConfig.sta.security;
+
+    ChipLogProgress(DeviceLayer, "p6_wifi_connect ssid %s pass %s sec %d \r\n", connect_param.ap_credentials.SSID,
+                    connect_param.ap_credentials.password, connect_param.ap_credentials.security);
+
+    result = cy_wcm_connect_ap(&connect_param, &ip_addr);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "p6_wifi_connect() failed result %ld", result);
+        err = CHIP_ERROR_INTERNAL;
+    }
+    return err;
+}
+
+#define INITIALISER_IPV4_ADDRESS1(addr_var, addr_val) addr_var = { CY_WCM_IP_VER_V4, { .v4 = (uint32_t)(addr_val) } }
+#define MAKE_IPV4_ADDRESS1(a, b, c, d) ((((uint32_t) d) << 24) | (((uint32_t) c) << 16) | (((uint32_t) b) << 8) | ((uint32_t) a))
+static const cy_wcm_ip_setting_t ap_mode_ip_settings2 = {
+    INITIALISER_IPV4_ADDRESS1(.ip_address, MAKE_IPV4_ADDRESS1(192, 168, 0, 2)),
+    INITIALISER_IPV4_ADDRESS1(.gateway, MAKE_IPV4_ADDRESS1(192, 168, 0, 2)),
+    INITIALISER_IPV4_ADDRESS1(.netmask, MAKE_IPV4_ADDRESS1(255, 255, 255, 0)),
+};
+
+CHIP_ERROR P6Utils::p6_start_ap(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+
+    wifi_config_t stationConfig;
+    memset(&stationConfig, 0, sizeof(stationConfig));
+    p6_wifi_get_config(WIFI_IF_AP, &stationConfig);
+
+    cy_wcm_ap_config_t ap_conf;
+    memset(&ap_conf, 0, sizeof(cy_wcm_ap_config_t));
+    memcpy(ap_conf.ap_credentials.SSID, &stationConfig.ap.ssid, strlen((const char *) stationConfig.ap.ssid));
+    memcpy(ap_conf.ap_credentials.password, &stationConfig.ap.password, strlen((const char *) stationConfig.ap.password));
+    memcpy(&ap_conf.ip_settings, &stationConfig.ap.ip_settings, sizeof(stationConfig.ap.ip_settings));
+    ap_conf.ap_credentials.security = stationConfig.ap.security;
+    ap_conf.channel                 = stationConfig.ap.channel;
+    ChipLogProgress(DeviceLayer, "p6_start_ap %s %s \r\n", ap_conf.ap_credentials.SSID, ap_conf.ap_credentials.password);
+
+    /* Start AP */
+    result = cy_wcm_start_ap(&ap_conf);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "cy_wcm_start_ap() failed result %ld", result);
+        err = CHIP_ERROR_INTERNAL;
+    }
+    /* Link Local IPV6 AP address for AP */
+    cy_wcm_ip_address_t ipv6_addr;
+    result = cy_wcm_get_ipv6_addr(CY_WCM_INTERFACE_TYPE_AP, CY_WCM_IPV6_LINK_LOCAL, &ipv6_addr, 1);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "cy_wcm_get_ipv6_addr() failed result %ld", result);
+        err = CHIP_ERROR_INTERNAL;
+    }
+    return err;
+}
+
+CHIP_ERROR P6Utils::p6_stop_ap(void)
+{
+    CHIP_ERROR err   = CHIP_NO_ERROR;
+    cy_rslt_t result = CY_RSLT_SUCCESS;
+    /* Stop AP */
+    result = cy_wcm_stop_ap();
+    if (result != CY_RSLT_SUCCESS)
+    {
+        ChipLogError(DeviceLayer, "cy_wcm_stop_ap failed result %ld", result);
+        err = CHIP_ERROR_INTERNAL;
+    }
+    return err;
+}
+
+void P6Utils::populate_wifi_config_t(wifi_config_t * wifi_config, wifi_interface_t interface, const cy_wcm_ssid_t * ssid,
+                                     const cy_wcm_passphrase_t * password, cy_wcm_security_t security)
+{
+    CY_ASSERT(wifi_config != NULL);
+
+    // Use interface param to determine which config to fill out
+    if (interface == WIFI_IF_STA || interface == WIFI_IF_STA_AP)
+    {
+        memset(&wifi_config->sta, 0, sizeof(wifi_config_sta_t));
+        memcpy(wifi_config->sta.ssid, ssid, chip::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t)));
+        memcpy(wifi_config->sta.password, password, chip::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t)));
+        wifi_config->sta.security = security;
+    }
+
+    if (interface == WIFI_IF_AP || interface == WIFI_IF_STA_AP)
+    {
+        memset(&wifi_config->ap, 0, sizeof(wifi_config_ap_t));
+        memcpy(wifi_config->ap.ssid, ssid, chip::min(strlen((char *) ssid) + 1, sizeof(cy_wcm_ssid_t)));
+        memcpy(wifi_config->ap.password, password, chip::min(strlen((char *) password) + 1, sizeof(cy_wcm_ssid_t)));
+        wifi_config->ap.security = security;
+    }
+}
+
+/* Ping implementation
+ *
+ */
+
+static void print_ip4(uint32_t ip)
+{
+    unsigned int bytes[4];
+    bytes[0] = ip & 0xFF;
+    bytes[1] = (ip >> 8) & 0xFF;
+    bytes[2] = (ip >> 16) & 0xFF;
+    bytes[3] = (ip >> 24) & 0xFF;
+    printf("Addr = %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
+}
+
+static void ping_prepare_echo(icmp_packet_t * iecho, uint16_t len)
+{
+    int i;
+    ICMPH_TYPE_SET(&iecho->hdr, ICMP_ECHO);
+    ICMPH_CODE_SET(&iecho->hdr, 0);
+    iecho->hdr.chksum = 0;
+    iecho->hdr.id     = PING_ID;
+    iecho->hdr.seqno  = htons(++(ping_seq_num));
+
+    /* fill the additional data buffer with some data */
+    for (i = 0; i < (int) sizeof(iecho->data); i++)
+    {
+        iecho->data[i] = (uint8_t) i;
+    }
+
+    iecho->hdr.chksum = inet_chksum(iecho, len);
+}
+
+/* Ping using socket API */
+#if PING_USE_SOCKETS
+
+static err_t ping_send(int s, const ip_addr_t * addr)
+{
+    int err;
+    icmp_packet_t iecho;
+    struct sockaddr_in to;
+
+    ping_prepare_echo(&iecho, (u16_t) sizeof(icmp_packet_t));
+
+    printf("\r\nPinging to Gateway ");
+    print_ip4(addr->u_addr.ip4.addr);
+
+    /* Send the ping request */
+    to.sin_len    = sizeof(to);
+    to.sin_family = AF_INET;
+    inet_addr_from_ip4addr(&to.sin_addr, ip_2_ip4(addr));
+    err = lwip_sendto(s, &iecho, sizeof(icmp_packet_t), 0, (struct sockaddr *) &to, sizeof(to));
+
+    return (err ? ERR_OK : ERR_VAL);
+}
+
+static void ping_recv(int s)
+{
+    char buf[PING_RESPONSE_LEN];
+    int fromlen;
+    int len;
+    struct sockaddr_in from;
+    struct ip_hdr * iphdr;
+    struct icmp_echo_hdr * iecho;
+
+    do
+    {
+        len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *) &from, (socklen_t *) &fromlen);
+        if (len >= (int) (sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr)))
+        {
+            iphdr = (struct ip_hdr *) buf;
+            iecho = (struct icmp_echo_hdr *) (buf + (IPH_HL(iphdr) * 4));
+
+            if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num)) && (ICMPH_TYPE(iecho) == ICMP_ER))
+            {
+                printf("Ping was successful Elapsed time : %" U32_F " ms\n", sys_now() - ping_time);
+                return; /* Echo reply received - return success */
+            }
+        }
+    } while (len > 0);
+
+    if (len == 0)
+    {
+        printf("ping: recv - %" U32_F " ms - timeout\r\n", (sys_now() - ping_time));
+    }
+}
+
+static void ping_socket()
+{
+    int s;
+    int ret;
+
+#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
+    int timeout = PING_RCV_TIMEO;
+#else
+    struct timeval timeout;
+    timeout.tv_sec  = PING_RCV_TIMEO / 1000;
+    timeout.tv_usec = (PING_RCV_TIMEO % 1000) * 1000;
+#endif
+
+    s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP);
+    if (s < 0)
+    {
+        return;
+    }
+
+    ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+    LWIP_ASSERT("setting receive timeout failed", ret == 0);
+    LWIP_UNUSED_ARG(ret);
+
+    while (1)
+    {
+        if (ping_send(s, ping_target) == ERR_OK)
+        {
+            ping_time = sys_now();
+            ping_recv(s);
+        }
+        else
+        {
+            printf("ping: send  error");
+        }
+        sys_msleep(PING_DELAY);
+    }
+}
+#else
+
+/* Ping using the raw ip */
+static u8_t ping_recv_raw(void * arg, struct raw_pcb * pcb, struct pbuf * p, const ip_addr_t * addr)
+{
+    struct icmp_echo_hdr * iecho;
+    LWIP_UNUSED_ARG(arg);
+    LWIP_UNUSED_ARG(pcb);
+    LWIP_UNUSED_ARG(addr);
+    LWIP_ASSERT("p != NULL", p != NULL);
+
+    if ((p->tot_len >= (IP_HDR_LEN + sizeof(struct icmp_echo_hdr))) && pbuf_header(p, -IP_HDR_LEN) == 0)
+    {
+
+        iecho = (struct icmp_echo_hdr *) p->payload;
+
+        if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num)))
+        {
+
+            printf("Ping was successful Elapsed time : %" U32_F " ms\n", sys_now() - ping_time);
+
+            /* do some ping result processing */
+            pbuf_free(p);
+            return 1; /* eat the packet */
+        }
+        /* not eaten, restore original packet */
+        pbuf_header(p, IP_HDR_LEN);
+    }
+
+    return 0; /* don't eat the packet */
+}
+
+static void ping_send_raw(struct raw_pcb * raw, const ip_addr_t * addr)
+{
+    struct pbuf * p;
+    icmp_packet_t * iecho;
+    size_t ping_size = sizeof(icmp_packet_t);
+
+    printf("\r\nPinging to Gateway ");
+    print_ip4(addr->u_addr.ip4.addr);
+    LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff);
+
+    p = pbuf_alloc(PBUF_IP, (u16_t) ping_size, PBUF_RAM);
+    if (!p)
+    {
+        return;
+    }
+    if ((p->len == p->tot_len) && (p->next == NULL))
+    {
+        iecho = (icmp_packet_t *) p->payload;
+
+        ping_prepare_echo(iecho, (u16_t) ping_size);
+
+        raw_sendto(raw, p, addr);
+        ping_time = sys_now();
+    }
+    pbuf_free(p);
+}
+
+static void ping_timeout(void * arg)
+{
+    struct raw_pcb * pcb = (struct raw_pcb *) arg;
+
+    LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
+
+    ping_send_raw(pcb, ping_target);
+
+    sys_timeout(PING_DELAY, ping_timeout, pcb);
+}
+
+void ping_raw(void)
+{
+    ping_pcb = raw_new(IP_PROTO_ICMP);
+    LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
+
+    raw_recv(ping_pcb, ping_recv_raw, NULL);
+    raw_bind(ping_pcb, IP_ADDR_ANY);
+    ping_send_raw(ping_pcb, ping_target);
+    sys_timeout(PING_DELAY, ping_timeout, ping_pcb);
+}
+#endif
+
+CHIP_ERROR P6Utils::ping_init(void)
+{
+    CHIP_ERROR err               = CHIP_NO_ERROR;
+    struct netif * net_interface = NULL;
+    net_interface                = cy_lwip_get_interface(CY_LWIP_STA_NW_INTERFACE);
+    ping_target                  = &net_interface->gw;
+
+    /* Ping to Gateway address */
+    if (ping_target)
+    {
+#if PING_USE_SOCKETS
+        ping_socket();
+#else
+        ping_raw();
+#endif
+    }
+    else
+    {
+        ChipLogError(DeviceLayer, "ping_thread failed: Invalid IP address for Ping");
+        err = CHIP_ERROR_INTERNAL;
+    }
+    return err;
+}

+ 105 - 0
src/platform/P6/P6Utils.h

@@ -0,0 +1,105 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include "platform/internal/DeviceNetworkInfo.h"
+#include <cy_wcm.h>
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+typedef struct
+{
+    cy_wcm_ssid_t ssid;           /**< SSID of the Wi-Fi network to join; should be a null-terminated string. */
+    cy_wcm_passphrase_t password; /**< Password needed to join the AP; should be a null-terminated string. */
+    cy_wcm_security_t security;   /**< Wi-Fi Security. @see cy_wcm_security_t. */
+    cy_wcm_mac_t BSSID;
+    cy_wcm_ip_setting_t * static_ip_settings;
+} wifi_config_sta_t;
+
+typedef struct
+{
+    cy_wcm_ssid_t ssid;           /**< SSID of the Wi-Fi network to join; should be a null-terminated string. */
+    cy_wcm_passphrase_t password; /**< Password needed to join the AP; should be a null-terminated string. */
+    cy_wcm_security_t security;   /**< Wi-Fi Security. @see cy_wcm_security_t. */
+    uint8_t channel;
+    cy_wcm_ip_setting_t ip_settings;
+} wifi_config_ap_t;
+
+typedef struct
+{
+    wifi_config_sta_t sta; /**< configuration of STA */
+    wifi_config_ap_t ap;   /**< configuration of AP */
+} wifi_config_t;
+
+typedef enum
+{
+    WIFI_MODE_NULL = 0, /**< null mode */
+    WIFI_MODE_STA,      /**< WiFi station mode */
+    WIFI_MODE_AP,       /**< WiFi soft-AP mode */
+    WIFI_MODE_APSTA,    /**< WiFi station + soft-AP mode */
+    WIFI_MODE_MAX
+} wifi_mode_t;
+
+typedef enum
+{
+    WIFI_IF_STA    = CY_WCM_INTERFACE_TYPE_STA,
+    WIFI_IF_AP     = CY_WCM_INTERFACE_TYPE_AP,
+    WIFI_IF_STA_AP = CY_WCM_INTERFACE_TYPE_AP_STA,
+} wifi_interface_t;
+
+namespace chip {
+namespace DeviceLayer {
+namespace Internal {
+
+class P6Utils
+{
+public:
+    static CHIP_ERROR IsAPEnabled(bool & apEnabled);
+    static bool IsStationProvisioned(void);
+    static CHIP_ERROR IsStationConnected(bool & connected);
+    static CHIP_ERROR StartWiFiLayer(void);
+    static CHIP_ERROR EnableStationMode(void);
+    static CHIP_ERROR SetAPMode(bool enabled);
+    static int OrderScanResultsByRSSI(const void * _res1, const void * _res2);
+    static const char * WiFiModeToStr(wifi_mode_t wifiMode);
+    static struct netif * GetNetif(const char * ifKey);
+    static struct netif * GetStationNetif(void);
+    static bool IsInterfaceUp(const char * ifKey);
+    static bool HasIPv6LinkLocalAddress(const char * ifKey);
+
+    static CHIP_ERROR GetWiFiStationProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials);
+    static CHIP_ERROR SetWiFiStationProvision(const Internal::DeviceNetworkInfo & netInfo);
+    static CHIP_ERROR ClearWiFiStationProvision(void);
+    static cy_rslt_t p6_wifi_get_config(wifi_interface_t interface, wifi_config_t * conf);
+    static cy_rslt_t p6_wifi_set_config(wifi_interface_t interface, wifi_config_t * conf);
+    static CHIP_ERROR p6_wifi_disconnect(void);
+    static CHIP_ERROR p6_wifi_connect(void);
+    static CHIP_ERROR p6_start_ap(void);
+    static CHIP_ERROR p6_stop_ap(void);
+    // Fills out some common fields in a wifi_config_t. Use interface param to
+    // select whether sta or ap config is populated.
+    static void populate_wifi_config_t(wifi_config_t * wifi_config, wifi_interface_t interface, const cy_wcm_ssid_t * ssid,
+                                       const cy_wcm_passphrase_t * password, cy_wcm_security_t security = CY_WCM_SECURITY_OPEN);
+    static CHIP_ERROR OnIPAddressAvailable(void);
+    static CHIP_ERROR ping_init(void);
+};
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace chip

+ 64 - 0
src/platform/P6/PlatformManagerImpl.cpp

@@ -0,0 +1,64 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides an implementation of the PlatformManager object
+ *          for the PSoC6 platform.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#include <crypto/CHIPCryptoPAL.h>
+#include <platform/PlatformManager.h>
+#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp>
+
+namespace chip {
+namespace DeviceLayer {
+
+namespace Internal {
+extern CHIP_ERROR InitLwIPCoreLock(void);
+}
+
+PlatformManagerImpl PlatformManagerImpl::sInstance;
+
+CHIP_ERROR PlatformManagerImpl::_InitChipStack(void)
+{
+    CHIP_ERROR err;
+
+    // Make sure the LwIP core lock has been initialized
+    err = Internal::InitLwIPCoreLock();
+    SuccessOrExit(err);
+
+    // Call _InitChipStack() on the generic implementation base class
+    // to finish the initialization process.
+    err = Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>::_InitChipStack();
+    SuccessOrExit(err);
+
+exit:
+    return err;
+}
+
+CHIP_ERROR PlatformManagerImpl::InitLwIPCoreLock(void)
+{
+    return Internal::InitLwIPCoreLock();
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 89 - 0
src/platform/P6/PlatformManagerImpl.h

@@ -0,0 +1,89 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Provides an implementation of the PlatformManager object
+ *          for the PSoC6 platform.
+ */
+
+#pragma once
+
+#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the PlatformManager singleton object for the PSoC6 platform.
+ */
+class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>
+{
+    // Allow the PlatformManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend PlatformManager;
+
+    // Allow the generic implementation base class to call helper methods on
+    // this class.
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+    friend Internal::GenericPlatformManagerImpl_FreeRTOS<PlatformManagerImpl>;
+#endif
+
+public:
+    // ===== Platform-specific members that may be accessed directly by the application.
+
+    CHIP_ERROR InitLwIPCoreLock(void);
+
+private:
+    // ===== Methods that implement the PlatformManager abstract interface.
+
+    CHIP_ERROR _InitChipStack(void);
+
+    // ===== Members for internal use by the following friends.
+
+    friend PlatformManager & PlatformMgr(void);
+    friend PlatformManagerImpl & PlatformMgrImpl(void);
+
+    static PlatformManagerImpl sInstance;
+};
+
+/**
+ * Returns the public interface of the PlatformManager singleton object.
+ *
+ * Chip applications should use this to access features of the PlatformManager object
+ * that are common to all platforms.
+ */
+inline PlatformManager & PlatformMgr(void)
+{
+    return PlatformManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the PlatformManager singleton object.
+ *
+ * Chip applications can use this to gain access to features of the PlatformManager
+ * that are specific to the PSoC6 platform.
+ */
+inline PlatformManagerImpl & PlatformMgrImpl(void)
+{
+    return PlatformManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip

+ 38 - 0
src/platform/P6/SoftwareUpdateManagerImpl.cpp

@@ -0,0 +1,38 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/* this file behaves like a config.h, comes first */
+#include <platform/internal/CHIPDeviceLayerInternal.h>
+
+#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER
+
+namespace chip {
+namespace DeviceLayer {
+
+SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance;
+
+CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void)
+{
+    CHIP_ERROR err = CHIP_NO_ERROR;
+    return err;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER

+ 89 - 0
src/platform/P6/SoftwareUpdateManagerImpl.h

@@ -0,0 +1,89 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2019 Google LLC.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER
+
+#include <platform/internal/GenericSoftwareUpdateManagerImpl.h>
+#include <platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h>
+
+namespace chip {
+namespace DeviceLayer {
+
+/**
+ * Concrete implementation of the SoftwareUpdateManager singleton object for the
+ * PSoC6 platforms.
+ */
+class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager,
+                                        public Internal::GenericSoftwareUpdateManagerImpl<SoftwareUpdateManagerImpl>,
+                                        public Internal::GenericSoftwareUpdateManagerImpl_BDX<SoftwareUpdateManagerImpl>
+{
+    // Allow the SoftwareUpdateManager interface class to delegate method calls to
+    // the implementation methods provided by this class.
+    friend class SoftwareUpdateManager;
+
+    // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods
+    // and types defined on this class.
+    friend class Internal::GenericSoftwareUpdateManagerImpl<SoftwareUpdateManagerImpl>;
+
+    // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods
+    // and types defined on this class.
+    friend class Internal::GenericSoftwareUpdateManagerImpl_BDX<SoftwareUpdateManagerImpl>;
+
+public:
+    // ===== Members for internal use by the following friends.
+
+    friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void);
+    friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void);
+
+    static SoftwareUpdateManagerImpl sInstance;
+
+private:
+    // ===== Members that implement the SoftwareUpdateManager abstract interface.
+
+    CHIP_ERROR _Init(void);
+};
+
+/**
+ * Returns a reference to the public interface of the SoftwareUpdateManager singleton object.
+ *
+ * Internal components should use this to access features of the SoftwareUpdateManager object
+ * that are common to all platforms.
+ */
+inline SoftwareUpdateManager & SoftwareUpdateMgr(void)
+{
+    return SoftwareUpdateManagerImpl::sInstance;
+}
+
+/**
+ * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object.
+ *
+ * Internal components can use this to gain access to features of the SoftwareUpdateManager
+ * that are specific to the PSoC6 platform.
+ */
+inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void)
+{
+    return SoftwareUpdateManagerImpl::sInstance;
+}
+
+} // namespace DeviceLayer
+} // namespace chip
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER

+ 56 - 0
src/platform/P6/SystemPlatformConfig.h

@@ -0,0 +1,56 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for the CHIP System
+ *          Layer on the PSoC6 platform.
+ *
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+namespace chip {
+namespace DeviceLayer {
+struct ChipDeviceEvent;
+} // namespace DeviceLayer
+} // namespace chip
+
+// ==================== Platform Adaptations ====================
+
+#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_EVENT_FUNCTIONS 1
+#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 0
+#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_TYPE int
+#define CHIP_SYSTEM_CONFIG_LWIP_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *
+#define CHIP_SYSTEM_CONFIG_EVENT_OBJECT_TYPE const struct ::chip::DeviceLayer::ChipDeviceEvent *
+#define CHIP_SYSTEM_CONFIG_ERROR_TYPE cy_rslt_t
+#define CHIP_SYSTEM_CONFIG_NO_ERROR CY_RSLT_SUCCESS
+#define CHIP_SYSTEM_CONFIG_ERROR_MIN 7000000
+#define CHIP_SYSTEM_CONFIG_ERROR_MAX 7000999
+#define _CHIP_SYSTEM_CONFIG_ERROR(e) (CHIP_SYSTEM_CONFIG_ERROR_MIN + (e))
+#define CHIP_SYSTEM_LWIP_ERROR_MIN 3000000
+#define CHIP_SYSTEM_LWIP_ERROR_MAX 3000128
+
+// ==================== General Configuration Overrides ====================
+
+#ifndef CHIP_SYSTEM_CONFIG_NUM_TIMERS
+#define CHIP_SYSTEM_CONFIG_NUM_TIMERS 16
+#endif // CHIP_SYSTEM_CONFIG_NUM_TIMERS

+ 39 - 0
src/platform/P6/WarmPlatformConfig.h

@@ -0,0 +1,39 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *    Copyright (c) 2018 Nest Labs, Inc.
+ *    All rights reserved.
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+/**
+ *    @file
+ *          Platform-specific configuration overrides for the Chip
+ *          Addressing and Routing Module (WARM) on the PSoC6 platform.
+ *
+ */
+
+#pragma once
+
+// ==================== Platform Adaptations ====================
+
+#define WARM_CONFIG_SUPPORT_THREAD 0
+#define WARM_CONFIG_SUPPORT_THREAD_ROUTING 0
+#define WARM_CONFIG_SUPPORT_LEGACY6LOWPAN_NETWORK 0
+#define WARM_CONFIG_SUPPORT_WIFI 1
+#define WARM_CONFIG_SUPPORT_CELLULAR 0
+
+// ========== Platform-specific Configuration Overrides =========
+
+/* none so far */

+ 99 - 0
src/platform/P6/app_platform_cfg.c

@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+/*******************************************************************************
+ * File Name: app_platform_cfg.c
+ * Version: 1.0
+ *
+ * Description:
+ *   Runtime Bluetooth stack configuration parameters
+ *
+ *******************************************************************************/
+#include "app_platform_cfg.h"
+#include "wiced_bt_dev.h"
+
+const cybt_platform_config_t bt_platform_cfg_settings =
+{
+    .hci_config =
+    {
+        .hci_transport = CYBT_HCI_UART,
+
+        .hci =
+        {
+            .hci_uart =
+            {
+                .uart_tx_pin = CYBSP_BT_UART_TX,
+                .uart_rx_pin = CYBSP_BT_UART_RX,
+                .uart_rts_pin = CYBSP_BT_UART_RTS,
+                .uart_cts_pin = CYBSP_BT_UART_CTS,
+
+                .baud_rate_for_fw_download = 3000000,
+                .baud_rate_for_feature     = 115200,
+
+                .data_bits = 8,
+                .stop_bits = 1,
+                .parity = CYHAL_UART_PARITY_NONE,
+                .flow_control = WICED_TRUE
+            }
+        }
+    },
+
+    .controller_config =
+    {
+        .bt_power_pin      = CYBSP_BT_POWER,
+        .sleep_mode =
+        {
+#if (bt_0_power_0_ENABLED == 1)
+#if (CYCFG_BT_LP_ENABLED == 1)
+                 .sleep_mode_enabled   = CYCFG_BT_LP_ENABLED,
+                 .device_wakeup_pin    = CYCFG_BT_DEV_WAKE_GPIO,
+                 .host_wakeup_pin      = CYCFG_BT_HOST_WAKE_GPIO,
+                 .device_wake_polarity = CYCFG_BT_DEV_WAKE_POLARITY,
+                 .host_wake_polarity   = CYCFG_BT_HOST_WAKE_IRQ_EVENT
+
+#else
+                 .sleep_mode_enabled   = WICED_FALSE
+#endif
+#else
+                .sleep_mode_enabled   = WICED_TRUE,
+                .device_wakeup_pin    = CYBSP_BT_DEVICE_WAKE,
+                .host_wakeup_pin      = CYBSP_BT_HOST_WAKE,
+                .device_wake_polarity = CYBT_WAKE_ACTIVE_LOW,
+                .host_wake_polarity   = CYBT_WAKE_ACTIVE_LOW
+#endif
+        }
+    },
+
+    .task_mem_pool_size    = 2048
+};
+
+/* [] END OF FILE */

+ 52 - 0
src/platform/P6/app_platform_cfg.h

@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+/*******************************************************************************
+ * File Name: app_platform_cfg.h
+ * Version: 1.0
+ *
+ * Description:
+ *   Header file for runtime Bluetooth stack configuration parameters
+ *
+ *******************************************************************************/
+
+#ifndef APP_PLATFORM_CFG_H_
+#define APP_PLATFORM_CFG_H_
+
+#include "cybt_platform_config.h"
+#include "cycfg_pins.h"
+
+extern const cybt_platform_config_t bt_platform_cfg_settings;
+
+#endif /* APP_BT_CFG_H_ */
+
+/* [] END OF FILE */

+ 32 - 0
src/platform/P6/args.gni

@@ -0,0 +1,32 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/p6.gni")
+
+import("${chip_root}/examples/platform/p6/args.gni")
+
+# ARM architecture flags will be set based on p6_family.
+arm_platform_config = "${p6_sdk_build_root}/p6_arm.gni"
+
+mbedtls_target = "${p6_sdk_build_root}:p6_build"
+
+chip_device_platform = "p6"
+
+lwip_platform = "p6"
+
+chip_inet_config_enable_ipv4 = true
+chip_inet_config_enable_dns_resolver = false
+
+chip_build_tests = false

+ 15 - 0
src/platform/P6/cy_wcm.h

@@ -0,0 +1,15 @@
+#ifndef CY_WCM_SHIM
+#define CY_WCM_SHIM
+
+// Shim to get cy wcm code to compile using the (older) CHIP-provided lwip.
+struct ifreq
+{
+    char ifr_name[6];
+};
+
+#define SO_BINDTODEVICE 42
+
+// Include the real cy_wcm.h
+#include "libs/wifi-connection-manager/include/cy_wcm.h"
+
+#endif

+ 298 - 0
src/platform/P6/cycfg_bt_settings.cpp

@@ -0,0 +1,298 @@
+/*******************************************************************************
+ * (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+/*******************************************************************************
+ * File Name: cycfg_bt_settings.c
+ * Version: 2.40.0.4650
+ *
+ * Description:
+ *   Runtime Bluetooth stack configuration parameters.
+ *
+ *******************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "cycfg_bt_settings.h"
+#include "cycfg_gap.h"
+
+#include "wiced_bt_ble.h"
+#include "wiced_bt_cfg.h"
+#include "wiced_bt_dev.h"
+#include "wiced_bt_gatt.h"
+
+#if !defined(WICED_BTSTACK_VERSION_MAJOR)
+#define WICED_BTSTACK_VERSION_MAJOR (2)
+#endif
+
+/*****************************************************************************
+ * wiced_bt core stack configuration
+ ****************************************************************************/
+#if (WICED_BTSTACK_VERSION_MAJOR >= 3)
+/* BLE scan settings  */
+const wiced_bt_cfg_ble_scan_settings_t cy_bt_cfg_scan_settings = {
+    .scan_mode =
+        CY_BT_SCAN_MODE, /* BLE scan mode (BTM_BLE_SCAN_MODE_PASSIVE, BTM_BLE_SCAN_MODE_ACTIVE, or BTM_BLE_SCAN_MODE_NONE) */
+
+    /* Advertisement scan configuration */
+    .high_duty_scan_interval = CY_BT_HIGH_DUTY_SCAN_INTERVAL, /* High duty scan interval (in slots (1 slot = 0.625 ms)) */
+    .high_duty_scan_window   = CY_BT_HIGH_DUTY_SCAN_WINDOW,   /* High duty scan window (in slots (1 slot = 0.625 ms)) */
+    .high_duty_scan_duration = CY_BT_HIGH_DUTY_SCAN_DURATION, /* High duty scan duration in seconds (0 for infinite) */
+
+    .low_duty_scan_interval = CY_BT_LOW_DUTY_SCAN_INTERVAL, /* Low duty scan interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_scan_window   = CY_BT_LOW_DUTY_SCAN_WINDOW,   /* Low duty scan window (in slots (1 slot = 0.625 ms)) */
+    .low_duty_scan_duration = CY_BT_LOW_DUTY_SCAN_DURATION, /* Low duty scan duration in seconds (0 for infinite) */
+
+    /* Connection scan configuration */
+    .high_duty_conn_scan_interval =
+        CY_BT_HIGH_DUTY_CONN_SCAN_INTERVAL, /* High duty cycle connection scan interval (in slots (1 slot = 0.625 ms)) */
+    .high_duty_conn_scan_window =
+        CY_BT_HIGH_DUTY_CONN_SCAN_WINDOW, /* High duty cycle connection scan window (in slots (1 slot = 0.625 ms)) */
+    .high_duty_conn_duration =
+        CY_BT_HIGH_DUTY_CONN_SCAN_DURATION, /* High duty cycle connection duration in seconds (0 for infinite) */
+
+    .low_duty_conn_scan_interval =
+        CY_BT_LOW_DUTY_CONN_SCAN_INTERVAL, /* Low duty cycle connection scan interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_conn_scan_window =
+        CY_BT_LOW_DUTY_CONN_SCAN_WINDOW, /* Low duty cycle connection scan window (in slots (1 slot = 0.625 ms)) */
+    .low_duty_conn_duration =
+        CY_BT_LOW_DUTY_CONN_SCAN_DURATION, /* Low duty cycle connection duration in seconds (0 for infinite) */
+
+    /* Connection configuration */
+    .conn_min_interval        = CY_BT_CONN_MIN_INTERVAL,        /* Minimum connection interval (in slots (1 slot = 1.25 ms)) */
+    .conn_max_interval        = CY_BT_CONN_MAX_INTERVAL,        /* Maximum connection interval (in slots (1 slot = 1.25 ms)) */
+    .conn_latency             = CY_BT_CONN_LATENCY,             /* Connection latency */
+    .conn_supervision_timeout = CY_BT_CONN_SUPERVISION_TIMEOUT, /* Connection link supervision timeout (in 10 ms) */
+};
+
+/* BLE advertisement settings */
+const wiced_bt_cfg_ble_advert_settings_t cy_bt_cfg_adv_settings = {
+    .channel_map = CY_BT_CHANNEL_MAP, /* Advertising channel map (mask of BTM_BLE_ADVERT_CHNL_37, BTM_BLE_ADVERT_CHNL_38,
+                                         BTM_BLE_ADVERT_CHNL_39) */
+
+    .high_duty_min_interval = CY_BT_HIGH_DUTY_ADV_MIN_INTERVAL, /* High duty undirected connectable minimum advertising interval (in
+                                                                   slots (1 slot = 0.625 ms)) */
+    .high_duty_max_interval = CY_BT_HIGH_DUTY_ADV_MAX_INTERVAL, /* High duty undirected connectable maximum advertising interval (in
+                                                                   slots (1 slot = 0.625 ms)) */
+    .high_duty_duration =
+        CY_BT_HIGH_DUTY_ADV_DURATION, /* High duty undirected connectable advertising duration in seconds (0 for infinite) */
+
+    .low_duty_min_interval = CY_BT_LOW_DUTY_ADV_MIN_INTERVAL, /* Low duty undirected connectable minimum advertising interval (in
+                                                                 slots (1 slot = 0.625 ms)) */
+    .low_duty_max_interval = CY_BT_LOW_DUTY_ADV_MAX_INTERVAL, /* Low duty undirected connectable maximum advertising interval (in
+                                                                 slots (1 slot = 0.625 ms)) */
+    .low_duty_duration =
+        CY_BT_LOW_DUTY_ADV_DURATION, /* Low duty undirected connectable advertising duration in seconds (0 for infinite) */
+
+    .high_duty_directed_min_interval =
+        CY_BT_HIGH_DUTY_DIRECTED_ADV_MIN_INTERVAL, /* High duty directed connectable minimum advertising interval (in slots (1 slot
+                                                      = 0.625 ms)) */
+    .high_duty_directed_max_interval =
+        CY_BT_HIGH_DUTY_DIRECTED_ADV_MAX_INTERVAL, /* High duty directed connectable maximum advertising interval (in slots (1 slot
+                                                      = 0.625 ms)) */
+
+    .low_duty_directed_min_interval = CY_BT_LOW_DUTY_DIRECTED_ADV_MIN_INTERVAL, /* Low duty directed connectable minimum advertising
+                                                                                   interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_directed_max_interval = CY_BT_LOW_DUTY_DIRECTED_ADV_MAX_INTERVAL, /* Low duty directed connectable maximum advertising
+                                                                                   interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_directed_duration =
+        CY_BT_LOW_DUTY_DIRECTED_ADV_DURATION, /* Low duty directed connectable advertising duration in seconds (0 for infinite) */
+
+    .high_duty_nonconn_min_interval = CY_BT_HIGH_DUTY_NONCONN_ADV_MIN_INTERVAL, /* High duty non-connectable minimum advertising
+                                                                                   interval (in slots (1 slot = 0.625 ms)) */
+    .high_duty_nonconn_max_interval = CY_BT_HIGH_DUTY_NONCONN_ADV_MAX_INTERVAL, /* High duty non-connectable maximum advertising
+                                                                                   interval (in slots (1 slot = 0.625 ms)) */
+    .high_duty_nonconn_duration =
+        CY_BT_HIGH_DUTY_NONCONN_ADV_DURATION, /* High duty non-connectable advertising duration in seconds (0 for infinite) */
+
+    .low_duty_nonconn_min_interval = CY_BT_LOW_DUTY_NONCONN_ADV_MIN_INTERVAL, /* Low duty non-connectable minimum advertising
+                                                                                 interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_nonconn_max_interval = CY_BT_LOW_DUTY_NONCONN_ADV_MAX_INTERVAL, /* Low duty non-connectable maximum advertising
+                                                                                 interval (in slots (1 slot = 0.625 ms)) */
+    .low_duty_nonconn_duration =
+        CY_BT_LOW_DUTY_NONCONN_ADV_DURATION /* Low duty non-connectable advertising duration in seconds (0 for infinite) */
+};
+
+/* BLE configuration settings */
+const wiced_bt_cfg_ble_t cy_bt_cfg_ble = {
+    .ble_max_simultaneous_links =
+        (CY_BT_CLIENT_MAX_LINKS +
+         CY_BT_SERVER_MAX_LINKS),                      /* Max number for simultaneous connections for a layer, profile, protocol */
+    .ble_max_rx_pdu_size = CY_BT_L2CAP_MTU_SIZE,       /* Maximum size allowed for any received L2CAP PDU
+                                                        * Minimum value - 65 (to support SM)
+                                                        * Maximum GATT MTU over legacy bearers shall be set to <= this value
+                                                        * Maximum MPS for EATT channels shall be set to <= this value */
+    .appearance                   = CY_BT_APPEARANCE,  /* GATT appearance (see gatt_appearance_e) */
+    .rpa_refresh_timeout          = CY_BT_RPA_TIMEOUT, /* Interval of  random address refreshing - secs */
+    .host_addr_resolution_db_size = 5, /* LE Address Resolution DB settings - effective only for pre 4.2 controller */
+    .p_ble_scan_cfg               = &cy_bt_cfg_scan_settings, /* BLE scan settings */
+    .p_ble_advert_cfg             = &cy_bt_cfg_adv_settings,  /* BLE advertisement settings */
+    .default_ble_power_level      = CY_BT_TX_POWER, /* Default LE power level, Refer lm_TxPwrTable table for the power range */
+};
+
+/* GATT settings */
+const wiced_bt_cfg_gatt_t cy_bt_cfg_gatt = {
+    .max_db_service_modules = 0, /* Maximum number of service modules in the DB*/
+    .max_eatt_bearers       = 0, /* Maximum number of allowed gatt bearers */
+};
+
+/* Application-managed L2CAP protocol configuration */
+const wiced_bt_cfg_l2cap_application_t cy_bt_cfg_l2cap = {
+    .max_app_l2cap_psms              = CY_BT_L2CAP_MAX_LE_PSM,      /* Maximum number of application-managed PSMs */
+    .max_app_l2cap_channels          = CY_BT_L2CAP_MAX_LE_CHANNELS, /* Maximum number of application-managed channels */
+    .max_app_l2cap_le_fixed_channels = 0, /* Maximum number of application-managed fixed channels supported */
+};
+
+/* Bluetooth stack configuration */
+const wiced_bt_cfg_settings_t wiced_bt_cfg_settings = {
+    .device_name       = (uint8_t *) app_gap_device_name, /* Local device name (NULL terminated) */
+    .security_required = CY_BT_SECURITY_LEVEL,            /* BTM_SEC_BEST_EFFORT is recommended choice for most applications,
+                                                           * to connect to the widest range of devices. Allows stack to choose
+                                                           * the highest level of security possible between the two devices */
+    .p_ble_cfg       = &cy_bt_cfg_ble,                    /* BLE related configuration */
+    .p_gatt_cfg      = &cy_bt_cfg_gatt,                   /* GATT settings */
+    .p_l2cap_app_cfg = &cy_bt_cfg_l2cap,                  /* Application-managed L2CAP protocol configuration */
+};
+#else
+/* Bluetooth stack configuration */
+const wiced_bt_cfg_settings_t wiced_bt_cfg_settings =
+    {
+        .device_name                         = (uint8_t*)app_gap_device_name,                             /* Local device name (NULL terminated) */
+        .device_class                        = {0x00, 0x00, 0x00},                                        /* Local device class */
+        .security_requirement_mask           = BTM_SEC_NONE,                                              /* Security requirements mask (BTM_SEC_NONE, or combination of BTM_SEC_IN_AUTHENTICATE, BTM_SEC_OUT_AUTHENTICATE, BTM_SEC_ENCRYPT (see #wiced_bt_sec_level_e)) */
+
+        .max_simultaneous_links              = (CY_BT_CLIENT_MAX_LINKS + CY_BT_SERVER_MAX_LINKS),         /* Maximum number simultaneous links to different devices */
+
+        /* BLE scan settings  */
+        .ble_scan_cfg =
+        {
+            .scan_mode                       = CY_BT_SCAN_MODE,                                           /* BLE scan mode (BTM_BLE_SCAN_MODE_PASSIVE, BTM_BLE_SCAN_MODE_ACTIVE, or BTM_BLE_SCAN_MODE_NONE) */
+
+            /* Advertisement scan configuration */
+            .high_duty_scan_interval         = CY_BT_HIGH_DUTY_SCAN_INTERVAL,                             /* High duty scan interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_scan_window           = CY_BT_HIGH_DUTY_SCAN_WINDOW,                               /* High duty scan window (in slots (1 slot = 0.625 ms)) */
+            .high_duty_scan_duration         = CY_BT_HIGH_DUTY_SCAN_DURATION,                             /* High duty scan duration in seconds (0 for infinite) */
+
+            .low_duty_scan_interval          = CY_BT_LOW_DUTY_SCAN_INTERVAL,                              /* Low duty scan interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_scan_window            = CY_BT_LOW_DUTY_SCAN_WINDOW,                                /* Low duty scan window (in slots (1 slot = 0.625 ms)) */
+            .low_duty_scan_duration          = CY_BT_LOW_DUTY_SCAN_DURATION,                              /* Low duty scan duration in seconds (0 for infinite) */
+
+            /* Connection scan configuration */
+            .high_duty_conn_scan_interval    = CY_BT_HIGH_DUTY_CONN_SCAN_INTERVAL,                        /* High duty cycle connection scan interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_conn_scan_window      = CY_BT_HIGH_DUTY_CONN_SCAN_WINDOW,                          /* High duty cycle connection scan window (in slots (1 slot = 0.625 ms)) */
+            .high_duty_conn_duration         = CY_BT_HIGH_DUTY_CONN_SCAN_DURATION,                        /* High duty cycle connection duration in seconds (0 for infinite) */
+
+            .low_duty_conn_scan_interval     = CY_BT_LOW_DUTY_CONN_SCAN_INTERVAL,                         /* Low duty cycle connection scan interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_conn_scan_window       = CY_BT_LOW_DUTY_CONN_SCAN_WINDOW,                           /* Low duty cycle connection scan window (in slots (1 slot = 0.625 ms)) */
+            .low_duty_conn_duration          = CY_BT_LOW_DUTY_CONN_SCAN_DURATION,                         /* Low duty cycle connection duration in seconds (0 for infinite) */
+
+            /* Connection configuration */
+            .conn_min_interval               = CY_BT_CONN_MIN_INTERVAL,                                   /* Minimum connection interval (in slots (1 slot = 1.25 ms)) */
+            .conn_max_interval               = CY_BT_CONN_MAX_INTERVAL,                                   /* Maximum connection interval (in slots (1 slot = 1.25 ms)) */
+            .conn_latency                    = CY_BT_CONN_LATENCY,                                        /* Connection latency */
+            .conn_supervision_timeout        = CY_BT_CONN_SUPERVISION_TIMEOUT,                            /* Connection link supervision timeout (in 10 ms) */
+        },
+
+        /* BLE advertisement settings */
+        .ble_advert_cfg =
+        {
+            .channel_map                     = CY_BT_CHANNEL_MAP,                                         /* Advertising channel map (mask of BTM_BLE_ADVERT_CHNL_37, BTM_BLE_ADVERT_CHNL_38, BTM_BLE_ADVERT_CHNL_39) */
+
+            .high_duty_min_interval          = CY_BT_HIGH_DUTY_ADV_MIN_INTERVAL,                          /* High duty undirected connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_max_interval          = CY_BT_HIGH_DUTY_ADV_MAX_INTERVAL,                          /* High duty undirected connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_duration              = CY_BT_HIGH_DUTY_ADV_DURATION,                              /* High duty undirected connectable advertising duration in seconds (0 for infinite) */
+
+            .low_duty_min_interval           = CY_BT_LOW_DUTY_ADV_MIN_INTERVAL,                           /* Low duty undirected connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_max_interval           = CY_BT_LOW_DUTY_ADV_MAX_INTERVAL,                           /* Low duty undirected connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_duration               = CY_BT_LOW_DUTY_ADV_DURATION,                               /* Low duty undirected connectable advertising duration in seconds (0 for infinite) */
+
+            .high_duty_directed_min_interval = CY_BT_HIGH_DUTY_DIRECTED_ADV_MIN_INTERVAL,                 /* High duty directed connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_directed_max_interval = CY_BT_HIGH_DUTY_DIRECTED_ADV_MAX_INTERVAL,                 /* High duty directed connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+
+            .low_duty_directed_min_interval  = CY_BT_LOW_DUTY_DIRECTED_ADV_MIN_INTERVAL,                  /* Low duty directed connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_directed_max_interval  = CY_BT_LOW_DUTY_DIRECTED_ADV_MAX_INTERVAL,                  /* Low duty directed connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_directed_duration      = CY_BT_LOW_DUTY_DIRECTED_ADV_DURATION,                      /* Low duty directed connectable advertising duration in seconds (0 for infinite) */
+
+            .high_duty_nonconn_min_interval  = CY_BT_HIGH_DUTY_NONCONN_ADV_MIN_INTERVAL,                  /* High duty non-connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_nonconn_max_interval  = CY_BT_HIGH_DUTY_NONCONN_ADV_MAX_INTERVAL,                  /* High duty non-connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .high_duty_nonconn_duration      = CY_BT_HIGH_DUTY_NONCONN_ADV_DURATION,                      /* High duty non-connectable advertising duration in seconds (0 for infinite) */
+
+            .low_duty_nonconn_min_interval   = CY_BT_LOW_DUTY_NONCONN_ADV_MIN_INTERVAL,                   /* Low duty non-connectable minimum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_nonconn_max_interval   = CY_BT_LOW_DUTY_NONCONN_ADV_MAX_INTERVAL,                   /* Low duty non-connectable maximum advertising interval (in slots (1 slot = 0.625 ms)) */
+            .low_duty_nonconn_duration       = CY_BT_LOW_DUTY_NONCONN_ADV_DURATION                        /* Low duty non-connectable advertising duration in seconds (0 for infinite) */
+        },
+
+        /* GATT configuration */
+        .gatt_cfg =
+        {
+            .appearance                     = CY_BT_APPEARANCE,                                           /* GATT appearance (see gatt_appearance_e) */
+            .client_max_links               = CY_BT_CLIENT_MAX_LINKS,                                     /* Client config: maximum number of servers that local client can connect to  */
+            .server_max_links               = CY_BT_SERVER_MAX_LINKS,                                     /* Server config: maximum number of remote clients connections allowed by the local */
+            .max_attr_len                   = CY_BT_MAX_ATTR_LEN,                                         /* Maximum attribute length; gki_cfg must have a corresponding buffer pool that can hold this length */
+            .max_mtu_size                   = CY_BT_MTU_SIZE                                              /* Maximum MTU size for GATT connections, should be between 23 and (max_attr_len + 5) */
+        },
+
+        /* RFCOMM configuration */
+        .rfcomm_cfg =
+        {
+            .max_links                      = 0,                                                          /* Maximum number of simultaneous connected remote devices */
+            .max_ports                      = 0                                                           /* Maximum number of simultaneous RFCOMM ports */
+        },
+
+        /* Application-managed L2CAP protocol configuration */
+        .l2cap_application =
+        {
+            .max_links                      = 0,                                                          /* Maximum number of application-managed l2cap links (BR/EDR and LE) */
+
+            /* BR EDR l2cap configuration */
+            .max_psm                        = 0,                                                          /* Maximum number of application-managed BR/EDR PSMs */
+            .max_channels                   = 0,                                                          /* Maximum number of application-managed BR/EDR channels */
+
+            /* LE L2cap connection-oriented channels configuration */
+            .max_le_psm                     = CY_BT_L2CAP_MAX_LE_PSM,                                     /* Maximum number of application-managed LE PSMs */
+            .max_le_channels                = CY_BT_L2CAP_MAX_LE_CHANNELS,                                /* Maximum number of application-managed LE channels */
+            /* LE L2cap fixed channel configuration */
+            .max_le_l2cap_fixed_channels    = 0,                                                          /* Maximum number of application-managed fixed channels supported (in addition to mandatory channels 4, 5 and 6) */
+            .max_rx_mtu                     = CY_BT_L2CAP_MTU_SIZE                                        /* Maximum RX MTU allowed */
+        },
+
+        .addr_resolution_db_size            = 5,                                                          /* LE Address Resolution DB settings - effective only for pre 4.2 controller */
+        .rpa_refresh_timeout                = CY_BT_RPA_TIMEOUT,                                          /* Interval of  random address refreshing - secs */
+        .stack_scratch_size                 = WICED_BT_CFG_DEFAULT_STACK_SCRATCH_SIZE,                    /* Memory area reserved for the stack transient memory requirements */
+        .ble_white_list_size                = CY_BT_WHITE_LIST_SIZE,                                      /* Maximum number of white list devices allowed. Cannot be more than 128 */
+        .default_ble_power_level            = CY_BT_TX_POWER                                              /* Default LE power level */
+    };
+#endif
+
+#ifdef __cplusplus
+}
+#endif

+ 11 - 0
src/platform/P6/cycfg_bt_settings.h

@@ -0,0 +1,11 @@
+#if !defined(CYCFG_BT_SETTINGS_H)
+#define CYCFG_BT_SETTINGS_H
+
+#include "wiced_bt_cfg.h"
+#include "wiced_bt_constants.h"
+
+extern const wiced_bt_cfg_settings_t wiced_bt_cfg_settings;
+
+#endif /* CYCFG_BT_SETTINGS_H */
+
+/* [] END OF FILE */

+ 29 - 0
src/platform/P6/cycfg_gap.cpp

@@ -0,0 +1,29 @@
+#include "cycfg_gap.h"
+
+/* Device address */
+const wiced_bt_device_address_t cy_bt_device_address = { 0x00, 0xA0, 0x50, 0x00, 0x00, 0x00 };
+
+const uint8_t cy_bt_adv_packet_elem_0[1]           = { 0x06 };
+const uint8_t cy_bt_adv_packet_elem_1[7]           = { 0x62, 0x6C, 0x65, 0x50, 0x72, 0x6F, 0x76 };
+const uint8_t cy_bt_adv_packet_elem_2[16]          = { 0x5B, 0x19, 0xBA, 0xE4, 0xE4, 0x52, 0xA9, 0x96,
+                                              0xF1, 0x4A, 0x84, 0xC8, 0x09, 0x4D, 0xC0, 0x21 };
+wiced_bt_ble_advert_elem_t cy_bt_adv_packet_data[] = {
+    /* Flags */
+    {
+        .p_data      = (uint8_t *) cy_bt_adv_packet_elem_0,
+        .len         = 1,
+        .advert_type = BTM_BLE_ADVERT_TYPE_FLAG,
+    },
+    /* Complete local name */
+    {
+        .p_data      = (uint8_t *) cy_bt_adv_packet_elem_1,
+        .len         = 7,
+        .advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE,
+    },
+    /* Complete list of 128-bit UUIDs available */
+    {
+        .p_data      = (uint8_t *) cy_bt_adv_packet_elem_2,
+        .len         = 16,
+        .advert_type = BTM_BLE_ADVERT_TYPE_128SRV_COMPLETE,
+    },
+};

+ 103 - 0
src/platform/P6/cycfg_gap.h

@@ -0,0 +1,103 @@
+#if !defined(CYCFG_GAP_H)
+#define CYCFG_GAP_H
+
+#include "cycfg_gatt_db.h"
+#include "stdint.h"
+#include "wiced_bt_ble.h"
+#include <platform/CHIPDeviceConfig.h>
+
+/* Silicon generated 'Company assigned' part of device address */
+#define CY_BT_SILICON_DEVICE_ADDRESS_EN 0
+
+/* Appearance */
+#define CY_BT_APPEARANCE 0
+
+/* TX Power Level */
+#define CY_BT_TX_POWER 0
+
+/* Interval of random address refreshing */
+#define CY_BT_RPA_TIMEOUT 0
+
+/* Maximum attribute length */
+#define CY_BT_MAX_ATTR_LEN 512
+/* Maximum attribute MTU size */
+#define CY_BT_MTU_SIZE 23
+
+/* Maximum connections */
+#define CY_BT_SERVER_MAX_LINKS 1
+#define CY_BT_CLIENT_MAX_LINKS 0
+
+/* BLE white list size */
+#define CY_BT_WHITE_LIST_SIZE 0
+
+/* L2CAP configuration */
+#define CY_BT_L2CAP_MAX_LE_PSM 1
+#define CY_BT_L2CAP_MAX_LE_CHANNELS 1
+#define CY_BT_L2CAP_MTU_SIZE 517
+
+/* Security level */
+#define CY_BT_SECURITY_LEVEL BTM_SEC_BEST_EFFORT
+
+/* Scan configuration */
+#define CY_BT_SCAN_MODE BTM_BLE_SCAN_MODE_PASSIVE
+
+#define CY_BT_HIGH_DUTY_SCAN_INTERVAL WICED_BT_CFG_DEFAULT_HIGH_DUTY_SCAN_INTERVAL
+#define CY_BT_HIGH_DUTY_SCAN_WINDOW WICED_BT_CFG_DEFAULT_HIGH_DUTY_SCAN_WINDOW
+#define CY_BT_HIGH_DUTY_SCAN_DURATION 5
+
+#define CY_BT_LOW_DUTY_SCAN_INTERVAL WICED_BT_CFG_DEFAULT_LOW_DUTY_SCAN_INTERVAL
+#define CY_BT_LOW_DUTY_SCAN_WINDOW WICED_BT_CFG_DEFAULT_LOW_DUTY_SCAN_WINDOW
+#define CY_BT_LOW_DUTY_SCAN_DURATION 60
+
+#define CY_BT_HIGH_DUTY_CONN_SCAN_INTERVAL WICED_BT_CFG_DEFAULT_HIGH_DUTY_CONN_SCAN_INTERVAL
+#define CY_BT_HIGH_DUTY_CONN_SCAN_WINDOW WICED_BT_CFG_DEFAULT_HIGH_DUTY_CONN_SCAN_WINDOW
+#define CY_BT_HIGH_DUTY_CONN_SCAN_DURATION 30
+
+#define CY_BT_LOW_DUTY_CONN_SCAN_INTERVAL WICED_BT_CFG_DEFAULT_LOW_DUTY_CONN_SCAN_INTERVAL
+#define CY_BT_LOW_DUTY_CONN_SCAN_WINDOW WICED_BT_CFG_DEFAULT_LOW_DUTY_CONN_SCAN_WINDOW
+#define CY_BT_LOW_DUTY_CONN_SCAN_DURATION 30
+
+/* Connection configuration */
+#define CY_BT_CONN_MIN_INTERVAL WICED_BT_CFG_DEFAULT_CONN_MIN_INTERVAL
+#define CY_BT_CONN_MAX_INTERVAL WICED_BT_CFG_DEFAULT_CONN_MAX_INTERVAL
+#define CY_BT_CONN_LATENCY WICED_BT_CFG_DEFAULT_CONN_LATENCY
+#define CY_BT_CONN_SUPERVISION_TIMEOUT WICED_BT_CFG_DEFAULT_CONN_SUPERVISION_TIMEOUT
+
+/* Advertisement settings */
+#define CY_BT_CHANNEL_MAP (BTM_BLE_ADVERT_CHNL_37 | BTM_BLE_ADVERT_CHNL_38 | BTM_BLE_ADVERT_CHNL_39)
+
+#define CY_BT_HIGH_DUTY_ADV_MIN_INTERVAL CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN
+#define CY_BT_HIGH_DUTY_ADV_MAX_INTERVAL CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX
+#define CY_BT_HIGH_DUTY_ADV_DURATION CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME / 1000
+
+#define CY_BT_LOW_DUTY_ADV_MIN_INTERVAL CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN
+#define CY_BT_LOW_DUTY_ADV_MAX_INTERVAL CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX
+#define CY_BT_LOW_DUTY_ADV_DURATION                                                                                                \
+    (CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT - CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME) / 1000
+
+#define CY_BT_HIGH_DUTY_DIRECTED_ADV_MIN_INTERVAL 400
+#define CY_BT_HIGH_DUTY_DIRECTED_ADV_MAX_INTERVAL 800
+
+#define CY_BT_LOW_DUTY_DIRECTED_ADV_MIN_INTERVAL 48
+#define CY_BT_LOW_DUTY_DIRECTED_ADV_MAX_INTERVAL 48
+#define CY_BT_LOW_DUTY_DIRECTED_ADV_DURATION 30
+
+#define CY_BT_HIGH_DUTY_NONCONN_ADV_MIN_INTERVAL 160
+#define CY_BT_HIGH_DUTY_NONCONN_ADV_MAX_INTERVAL 160
+#define CY_BT_HIGH_DUTY_NONCONN_ADV_DURATION 30
+
+#define CY_BT_LOW_DUTY_NONCONN_ADV_MIN_INTERVAL 2048
+#define CY_BT_LOW_DUTY_NONCONN_ADV_MAX_INTERVAL 2048
+#define CY_BT_LOW_DUTY_NONCONN_ADV_DURATION 30
+
+/* Advertisement and scan response packets defines */
+#define CY_BT_ADV_PACKET_DATA_SIZE 3
+
+/* cy_bt_device_name is obsolete. Use app_gap_device_name instead. */
+#define cy_bt_device_name app_gap_device_name
+
+/* External definitions */
+extern const wiced_bt_device_address_t cy_bt_device_address;
+extern wiced_bt_ble_advert_elem_t cy_bt_adv_packet_data[];
+
+#endif /* CYCFG_GAP_H */

+ 117 - 0
src/platform/P6/cycfg_gatt_db.c

@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+/*******************************************************************************
+ * File Name: cycfg_gatt_db.c
+ * Version: 2.1
+ *
+ * Description:
+ *   BLE device's GATT database and device configuration.
+ *
+ *******************************************************************************/
+
+#include "cycfg_gatt_db.h"
+#include "wiced_bt_gatt.h"
+#include "wiced_bt_uuid.h"
+
+/*************************************************************************************
+ * GATT server definitions
+ *************************************************************************************/
+
+const uint8_t gatt_database[] = {
+    /* Primary Service: Generic Access */
+    PRIMARY_SERVICE_UUID16(HDLS_GAP, __UUID_SERVICE_GENERIC_ACCESS),
+
+    /* Characteristic: Device Name */
+    CHARACTERISTIC_UUID16(HDLC_GAP_DEVICE_NAME, HDLC_GAP_DEVICE_NAME_VALUE, __UUID_CHARACTERISTIC_DEVICE_NAME,
+                          LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE),
+
+    /* Characteristic: Appearance */
+    CHARACTERISTIC_UUID16(HDLC_GAP_APPEARANCE, HDLC_GAP_APPEARANCE_VALUE, __UUID_CHARACTERISTIC_APPEARANCE, LEGATTDB_CHAR_PROP_READ,
+                          LEGATTDB_PERM_READABLE),
+
+    /* Primary Service: Generic Attribute */
+    PRIMARY_SERVICE_UUID16(HDLS_GATT, __UUID_SERVICE_GENERIC_ATTRIBUTE),
+
+    /* Primary Service: Custom Service */
+    PRIMARY_SERVICE_UUID16(HDLS_CHIP_SERVICE, __UUID16_CHIPoBLEService),
+
+    /* Characteristic: C1 */
+    CHARACTERISTIC_UUID128_WRITABLE(HDLC_CHIP_SERVICE_CHAR_C1, HDLC_CHIP_SERVICE_CHAR_C1_VALUE, __UUID128_CHIPoBLEChar_C1,
+                                    LEGATTDB_CHAR_PROP_WRITE,
+                                    LEGATTDB_PERM_VARIABLE_LENGTH | LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ),
+    /* Characteristic: C2 */
+    CHARACTERISTIC_UUID128_WRITABLE(HDLC_CHIP_SERVICE_CHAR_C2, HDLC_CHIP_SERVICE_CHAR_C2_VALUE, __UUID128_CHIPoBLEChar_C2,
+                                    LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY,
+                                    LEGATTDB_PERM_RELIABLE_WRITE | LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITABLE),
+
+    /* Descriptor: Client Characteristic Configuration */
+    CHAR_DESCRIPTOR_UUID16_WRITABLE(HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG, __UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION,
+                                    LEGATTDB_PERM_AUTH_READABLE | LEGATTDB_PERM_WRITE_REQ),
+};
+
+/* Length of the GATT database */
+const uint16_t gatt_database_len = sizeof(gatt_database);
+
+/*************************************************************************************
+ * GATT Initial Value Arrays
+ ************************************************************************************/
+
+uint8_t app_gap_device_name[kMaxDeviceNameLength] = { 'I', 'F', 'X', ' ', 'C', 'H', 'I', 'P' };
+uint8_t app_gap_appearance[]                      = {
+    0x00,
+    0x00,
+};
+uint8_t app_chip_service_char_tx_client_char_config[] = {
+    0x00,
+    0x00,
+};
+
+/************************************************************************************
+ * GATT Lookup Table
+ ************************************************************************************/
+
+gatt_db_lookup_table_t app_gatt_db_ext_attr_tbl[] = {
+    /* { attribute handle,                                       maxlen, curlen, attribute data } */
+    { HDLC_GAP_DEVICE_NAME_VALUE, sizeof(app_gap_device_name), sizeof(app_gap_device_name), app_gap_device_name },
+    { HDLC_GAP_APPEARANCE_VALUE, sizeof(app_gap_appearance), sizeof(app_gap_appearance), app_gap_appearance },
+    { HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG, sizeof(app_chip_service_char_tx_client_char_config),
+      sizeof(app_chip_service_char_tx_client_char_config), app_chip_service_char_tx_client_char_config },
+};
+
+/* Number of Lookup Table entries */
+const uint16_t app_gatt_db_ext_attr_tbl_size = (sizeof(app_gatt_db_ext_attr_tbl) / sizeof(gatt_db_lookup_table_t));
+
+/* Number of GATT initial value arrays entries */
+const uint16_t app_gap_device_name_len                         = (sizeof(app_gap_device_name));
+const uint16_t app_gap_appearance_len                          = (sizeof(app_gap_appearance));
+const uint16_t app_chip_service_char_tx_client_char_config_len = (sizeof(app_chip_service_char_tx_client_char_config));

+ 95 - 0
src/platform/P6/cycfg_gatt_db.h

@@ -0,0 +1,95 @@
+/***************************************************************************/
+/**
+ * File Name: cycfg_gatt_db.h
+ * Version: 2.1
+ *
+ * Description:
+ * Definitions for constants used in the device's GATT
+ *database and function prototypes. This file should
+ *not be modified. It was automatically generated by
+ * Bluetooth Configurator 2.1.0.2188
+ *
+ ********************************************************************************
+ * Copyright 2020 Cypress Semiconductor Corporation
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in
+ *compliance with the License. You may obtain a copy
+ *of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in
+ *writing, software distributed under the License is
+ *distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ *OR CONDITIONS OF ANY KIND, either express or
+ *implied. See the License for the specific language
+ *governing permissions and limitations under the
+ *License.
+ *******************************************************************************/
+
+#if !defined(CYCFG_GATT_DB_H)
+#define CYCFG_GATT_DB_H
+
+#include "stdint.h"
+
+#define __UUID_SERVICE_GENERIC_ACCESS 0x1800
+#define __UUID_CHARACTERISTIC_DEVICE_NAME 0x2A00
+#define __UUID_CHARACTERISTIC_APPEARANCE 0x2A01
+#define __UUID_SERVICE_GENERIC_ATTRIBUTE 0x1801
+#define __UUID16_CHIPoBLEService 0xFFF6
+#define __UUID128_CHIPoBLEChar_C1 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
+#define __UUID128_CHIPoBLEChar_C2 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18
+#define __UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION 0x2902
+
+/* Service Generic Access */
+#define HDLS_GAP 0x01
+/* Characteristic Device Name */
+#define HDLC_GAP_DEVICE_NAME 0x02
+#define HDLC_GAP_DEVICE_NAME_VALUE 0x03
+/* Characteristic Appearance */
+#define HDLC_GAP_APPEARANCE 0x04
+#define HDLC_GAP_APPEARANCE_VALUE 0x05
+
+/* Service Generic Attribute */
+#define HDLS_GATT 0x06
+
+/* Service CHIP Service */
+#define HDLS_CHIP_SERVICE 0x07
+
+/* Characteristic CHIP C1 */
+#define HDLC_CHIP_SERVICE_CHAR_C1 0x08
+#define HDLC_CHIP_SERVICE_CHAR_C1_VALUE 0x09
+
+/* Characteristic CHIP C2 */
+#define HDLC_CHIP_SERVICE_CHAR_C2 0x0A
+#define HDLC_CHIP_SERVICE_CHAR_C2_VALUE 0x0B
+
+/* Descriptor Client Characteristic Configuration */
+#define HDLD_CHIP_SERVICE_RX_CLIENT_CHAR_CONFIG 0x0C
+
+/* External Lookup Table Entry */
+typedef struct
+{
+    uint16_t handle;
+    uint16_t max_len;
+    uint16_t cur_len;
+    uint8_t * p_data;
+} gatt_db_lookup_table_t;
+
+#define kMaxDeviceNameLength 32
+
+/* External definitions */
+extern const uint8_t gatt_database[];
+extern const uint16_t gatt_database_len;
+extern gatt_db_lookup_table_t app_gatt_db_ext_attr_tbl[];
+extern const uint16_t app_gatt_db_ext_attr_tbl_size;
+extern uint8_t app_gap_device_name[kMaxDeviceNameLength];
+extern const uint16_t app_gap_device_name_len;
+extern uint8_t app_gap_appearance[];
+extern const uint16_t app_gap_appearance_len;
+extern uint8_t app_chip_service_char_tx_client_char_config[];
+extern const uint16_t app_chip_service_char_tx_client_char_config_len;
+
+#endif /* CYCFG_GATT_DB_H */

+ 7 - 0
src/platform/P6/ethernet.h

@@ -0,0 +1,7 @@
+#ifndef CY_ETHERNET_SHIM
+#define CY_ETHERNET_SHIM
+
+// Shim for cy secure-sockets which includes <ethernet.h> (with no path) but should be <netif/ethernet.h>
+#include <netif/ethernet.h>
+
+#endif

+ 5 - 2
src/platform/device.gni

@@ -50,7 +50,7 @@ declare_args() {
 
   # Select DNS-SD implementation
   if (chip_device_platform == "linux" || chip_device_platform == "esp32" ||
-      chip_device_platform == "mbed") {
+      chip_device_platform == "mbed" || chip_device_platform == "p6") {
     chip_mdns = "minimal"
   } else if (chip_device_platform == "darwin" ||
              chip_device_platform == "cc13x2_26x2" || current_os == "android") {
@@ -84,6 +84,8 @@ if (chip_device_platform == "cc13x2_26x2") {
   _chip_device_layer = "telink"
 } else if (chip_device_platform == "mbed") {
   _chip_device_layer = "mbed"
+} else if (chip_device_platform == "p6") {
+  _chip_device_layer = "P6"
 }
 
 if (chip_device_platform != "external") {
@@ -123,5 +125,6 @@ assert(
         chip_device_platform == "linux" ||
         chip_device_platform == "nrfconnect" ||
         chip_device_platform == "k32w" || chip_device_platform == "qpg" ||
-        chip_device_platform == "telink" || chip_device_platform == "mbed",
+        chip_device_platform == "telink" || chip_device_platform == "mbed" ||
+        chip_device_platform == "p6",
     "Please select a valid value for chip_device_platform")

+ 82 - 0
third_party/p6/BUILD.gn

@@ -0,0 +1,82 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/p6.gni")
+import("${p6_sdk_build_root}/p6_sdk.gni")
+
+declare_args() {
+  # Build target to use for p6 SDK. Use this to set global SDK defines.
+  p6_target_project = ""
+}
+
+assert(p6_target_project != "", "p6_target_project must be specified")
+
+# Add includes, cflags, asmflags, etc in config
+config("p6_sdk_config") {
+  # Pull out includes from generated json
+  # Treat these includes as system includes, so warnings in them are not fatal.
+  _include_dirs = []
+  foreach(inc, mtb_json.includes) {
+    # Strip off leading -I part
+    _include_dirs += [ "/" + rebase_path(string_replace(inc, "-I", "", 1),
+                                         "/",
+                                         "${p6_sdk_build_root}/p6_sdk/") ]
+  }
+
+  # Also add project include path (passed in from project build)
+  proj_path = get_label_info(p6_target_project, "dir")
+  _include_dirs += [ "/" + rebase_path("${proj_path}/include", "/", ".") ]
+
+  cflags = []
+  foreach(include_dir, _include_dirs) {
+    cflags += [ "-isystem" + include_dir ]
+  }
+
+  # Pull out defines from generated json
+  defines = []
+  foreach(def, mtb_json.defines) {
+    # Strip off leading -D part
+    defines += [ string_replace(def, "-D", "", 1) ]
+  }
+
+  # Pull out static libs (.a files) from generated json
+  libs = []
+  foreach(lib, mtb_json.libs) {
+    libs += [ "/" + rebase_path(lib, "/", "${p6_sdk_build_root}/p6_sdk/") ]
+  }
+
+  cflags_c = mtb_json.cflags
+  cflags_cc = mtb_json.cxxflags
+  asmflags = mtb_json.asflags
+  ldflags = filter_exclude(mtb_json.ldflags, [ "-T*" ])
+
+  # Pull out linker flags with paths (-T flags) and make paths absolute
+  linker_script_flags = filter_include(mtb_json.ldflags, [ "-T*" ])
+  foreach(flag, linker_script_flags) {
+    ldflags += [ "-T/" + rebase_path(string_replace(flag, "-T", "", 1),
+                                     "/",
+                                     "${p6_sdk_build_root}/p6_sdk/") ]
+  }
+
+  # --specs=nano.specs is getting added twice and causing compile issues so remove from cxx flags here.
+  cflags_c -= [ "--specs=nano.specs" ]
+  cflags_cc -= [ "--specs=nano.specs" ]
+  asmflags -= [ "--specs=nano.specs" ]
+  ldflags -= [ "--specs=nano.specs" ]
+}
+
+group("p6_build") {
+  public_configs = [ ":p6_sdk_config" ]
+  public_deps = [ p6_target_project ]
+}

+ 21 - 0
third_party/p6/p6_arm.gni

@@ -0,0 +1,21 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("p6_board.gni")
+
+arm_arch = "armv7e-m"
+arm_abi = "aapcs"
+arm_cpu = "cortex-m4"
+arm_float_abi = "softfp"
+arm_fpu = "fpv4-sp-d16"

+ 26 - 0
third_party/p6/p6_board.gni

@@ -0,0 +1,26 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+declare_args() {
+  # P6 board used
+  p6_board = ""
+}
+
+if (p6_board == "") {
+  p6_board = getenv("P6_BOARD")
+}
+
+assert(p6_board != "", "P6_BOARD must be specified")
+
+board_defines = []

+ 55 - 0
third_party/p6/p6_executable.gni

@@ -0,0 +1,55 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/build.gni")
+import("//build_overrides/chip.gni")
+import("${build_root}/toolchain/flashable_executable.gni")
+
+import("p6_board.gni")
+
+template("p6_executable") {
+  output_base_name = get_path_info(invoker.output_name, "name")
+
+  objcopy_image_name = output_base_name + ".hex"
+  objcopy_image_format = "ihex"
+  objcopy = "arm-none-eabi-objcopy"
+
+  #Copy flashing dependencies to the output directory so that the output
+  #is collectively self-contained; this allows flashing to work reliably
+  #even if the build and flashing steps take place on different machines
+  #or in different containers.
+
+  flashing_runtime_target = target_name + ".flashing_runtime"
+  copy(flashing_runtime_target) {
+    sources = [
+      "${chip_root}/scripts/flashing/firmware_utils.py",
+      "${chip_root}/scripts/flashing/p6_firmware_utils.py",
+    ]
+    outputs = [ "${root_out_dir}/{{source_file_part}}" ]
+  }
+
+  flashing_script_generator =
+      "${chip_root}/scripts/flashing/gen_flashing_script.py"
+  flashing_script_name = output_base_name + ".flash.py"
+  flashing_options = [
+    "p6",
+    "--device",
+    "${p6_board}",
+  ]
+
+  flashable_executable(target_name) {
+    forward_variables_from(invoker, "*")
+    data_deps = [ ":${flashing_runtime_target}" ]
+  }
+}

+ 102 - 0
third_party/p6/p6_sdk.gni

@@ -0,0 +1,102 @@
+# Copyright (c) 2021 Project CHIP Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build_overrides/chip.gni")
+import("//build_overrides/jlink.gni")
+import("//build_overrides/mbedtls.gni")
+
+import("//build_overrides/p6.gni")
+import("p6_board.gni")
+
+# TODO: Don't hardcode config/toolchain
+# TODO: Convert to GN action?
+if (is_debug) {
+  debug_str = "Debug"
+} else {
+  debug_str = "Release"
+}
+
+mtb_json = read_file(
+        "$p6_sdk_build_root/p6_sdk/build/${p6_board}/$debug_str/GCC_ARM.json",
+        "json")
+
+# Defines an p6 SDK build target.
+#
+# Parameters:
+#   sources - The sources files to build.
+#
+template("p6_sdk_sources") {
+  if (defined(invoker.p6_project_dir)) {
+    p6_project_dir = invoker.p6_project_dir
+  }
+
+  # While most p6 sdk includes come from the p6_sdk_config config (in
+  # BUILD.gn), this template gets instantiated by each project each of which
+  # provides a few extra includes/defines. Handle those here.
+  config("project_configs") {
+    include_dirs = []
+    if (defined(invoker.include_dirs)) {
+      include_dirs += invoker.include_dirs
+    }
+    include_dirs += [ "${p6_project_dir}/include" ]
+
+    defines = []
+    if (defined(invoker.defines)) {
+      defines += invoker.defines
+    }
+  }
+
+  sdk_target_name = target_name
+
+  # Add sources here
+  source_set(sdk_target_name) {
+    sources = []
+    if (defined(invoker.sources)) {
+      sources += invoker.sources
+    }
+
+    # Pull out c sources from generated json
+    foreach(src, mtb_json.c_source) {
+      sources += [ rebase_path(src,
+                               "${p6_project_dir}",
+                               "${p6_sdk_build_root}/p6_sdk/") ]
+    }
+
+    # Pull out cpp sources from generated json
+    foreach(src, mtb_json.cxx_source) {
+      sources += [ rebase_path(src,
+                               "${p6_project_dir}",
+                               "${p6_sdk_build_root}/p6_sdk/") ]
+    }
+
+    # Pull out .S files from generated json
+    foreach(asm, mtb_json.asm_source) {
+      sources += [ rebase_path(asm,
+                               "${p6_project_dir}",
+                               "${p6_sdk_build_root}/p6_sdk/") ]
+    }
+
+    public_deps = []
+    if (defined(invoker.public_deps)) {
+      public_deps += invoker.public_deps
+    }
+
+    public_deps += [ "${chip_root}/src/lwip:lwip" ]
+
+    public_configs = [ ":project_configs" ]
+    if (defined(invoker.public_configs)) {
+      public_configs += invoker.public_configs
+    }
+  }
+}

+ 148 - 0
third_party/p6/p6_sdk/.gitignore

@@ -0,0 +1,148 @@
+# This list of files to ignore includes common, tool- or user-specific files that
+# are typically not checked into a version control system (VCS). It is a superset
+# of such files. You may want to add others, especially if you use a tool not listed
+# here. You can remove those that do not apply to you.
+#
+# The .gitignore file is intended for the git VCS. For another VCS you would specify
+# which files to ignore in whatever form your VCS requires. If you do not check your
+# code into a VCS, you can ignore the .gitignore file.
+
+# ModusToolbox library repos or information about library dependencies
+libs/
+
+# Eclipse IDE for ModusToolbox files
+.metadata/
+# .cyignore
+# .settings/
+# .cproject
+# .project
+# .mtbLaunchConfigs/
+
+# ModusToolbox Configurator generated code
+GeneratedSource/
+
+# ModusToolbox build system output
+build/
+Debug/
+Release/
+*_build/
+
+# Visual Studio Code
+openocd.tcl
+.vscode/
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+
+# IAR Embedded Workbench files
+
+# IAR Project file.
+# *.ewp
+
+# IAR Settings
+/settings/
+
+# Uncomment this if not using project connections
+# *.ipcf
+
+# Comment this out if using custom argument variables
+*.custom_argvars
+
+# IAR Debugger Settings
+# *.ewd
+
+# Comment this out if you use C-Stat or C-Run to compile/analyze your project
+*.ewt
+
+# IAR Workspace files
+# *.eww
+
+# IAR Debug Exe
+/Debug/Exe/
+
+# IAR Debug List
+/Debug/List
+
+# IAR Debug Obj
+/Obj/*.pbd
+/Obj/*.pbd.*
+/Obj/*.pbi
+/Obj/*.pbi.*
+
+# Log files
+*.log
+
+# IAR backup files
+Backup*
+
+# IAR dependency files
+*.dep
+
+# Compiled Binaries
+*.bin
+*.elf
+*.hex
+*.map
+
+# Trash files
+*.bak
+
+
+# Keil uVision files
+
+# Project and package description files
+*.cpdsc
+*.gpdsc
+
+# uVision Project file (generated by uVision). Uncomment this if do not want to track the Keil uVision project file
+# *.uvprojx (is used to build the project from scratch)
+
+# Project options file (contains information about the debugger and trace configuration)
+# *.uvoptx
+
+# Project file for multi-project workspaces
+# *.uvmpw
+
+# Project screen layout file
+*.uvguix.*
+
+# Configuration files for the run-time environment
+# RTE/
+
+# Generated output files
+*.lst
+*.map
+
+# Eclipse workspace/user-specific files/settings/caches
+.metadata/
+# .settings/
+
+# Vi and Emacs backup files
+*~
+\#*\#
+[._]*.s[a-v][a-z]
+[._]*.sw[a-p]
+[._]s[a-rt-v][a-z]
+[._]ss[a-gi-z]
+[._]sw[a-p]
+
+# Created by git when using merge tools for conflicts
+*.BACKUP.*
+*.BASE.*
+*.LOCAL.*
+*.REMOTE.*
+*_BACKUP_*.txt
+*_BASE_*.txt
+*_LOCAL_*.txt
+*_REMOTE_*.txt
+
+# macOS Finder incidental files
+.DS_Store
+
+# Windows Explorer incidental files
+Thumbs.db
+Thumbs.db:encryptable
+ehthumbs.db
+ehthumbs_vista.db
+[Dd]esktop.ini

+ 236 - 0
third_party/p6/p6_sdk/Makefile

@@ -0,0 +1,236 @@
+################################################################################
+# \file Makefile
+# \version 1.0
+#
+# \brief
+# Top-level application make file.
+#
+################################################################################
+# \copyright
+# Copyright 2018-2021 Cypress Semiconductor Corporation
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+
+
+################################################################################
+# Basic Configuration
+################################################################################
+
+# Target board/hardware (BSP).
+# To change the target, it is recommended to use the Library manager 
+# ('make modlibs' from command line), which will also update Eclipse IDE launch 
+# configurations. If TARGET is manually edited, ensure TARGET_<BSP>.mtb with a 
+# valid URL exists in the application, run 'make getlibs' to fetch BSP contents
+# and update or regenerate launch configurations for your IDE.
+TARGET=$(error TARGET should be set on make command-line)
+
+APPNAME=mtb-chip-sdk
+
+# Name of toolchain to use. Options include:
+#
+# GCC_ARM -- GCC provided with ModusToolbox IDE
+# ARM     -- ARM Compiler (must be installed separately)
+# IAR     -- IAR Compiler (must be installed separately)
+#
+# See also: CY_COMPILER_PATH below
+TOOLCHAIN=GCC_ARM
+
+# Default build configuration. Options include:
+#
+# Debug -- build with minimal optimizations, focus on debugging.
+# Release -- build with full optimizations
+# Custom -- build with custom configuration, set the optimization flag in CFLAGS
+# 
+# If CONFIG is manually edited, ensure to update or regenerate launch configurations 
+# for your IDE.
+CONFIG=Debug
+
+# If set to "true" or "1", display full command-lines when building.
+VERBOSE=
+
+# The MQTT Client library does not support secure connections to the Mosquitto
+# broker by default, because the server uses the SHA1 hashing algorithm which 
+# is considered  a weak message digest and is therefore not enabled by default.
+# However, if it is required to connect securely to the Mosquitto Broker set  
+# this macro to "true" or "1".
+ENABLE_SECURE_MOSQUITTO_BROKER_SUPPORT=0
+
+################################################################################
+# Advanced Configuration
+################################################################################
+
+# Enable optional code that is ordinarily disabled by default.
+#
+# Available components depend on the specific targeted hardware and firmware
+# in use. In general, if you have
+#
+#    COMPONENTS=foo bar
+#
+# ... then code in directories named COMPONENT_foo and COMPONENT_bar will be
+# added to the build
+#
+COMPONENTS=FREERTOS LWIP MBEDTLS RTOS_AWARE WICED_BLE
+
+# CHIP: ModusToolbox 2.2 & 2.3 do not have a way to disable indirect library
+# dependencies.  This causes trouble for CHIP because we need to use its
+# bundled version of LwIP.
+#
+# As a work-around, we enable "QUICK_MODE" for the "getlibs" target. This
+# tells it to skip automatic generation of .mtb files for indirect
+# dependencies. We list everything we need as a direct dependency.
+#
+# This isn't ideal (it means have to manually manage dependencies), but it's
+# the best we can do for these versions of ModusToolbox.
+ifeq ($(filter getlibs,$(MAKECMDGOALS)),getlibs)
+QUICK_MODE=true
+endif
+
+# Like COMPONENTS, but disable optional code that was enabled by default.
+DISABLE_COMPONENTS=
+
+# By default the build system automatically looks in the Makefile's directory
+# tree for source code and builds it. The SOURCES variable can be used to
+# manually add source code to the build process from a location not searched
+# by default, or otherwise not found by the build system.
+SOURCES=
+
+# Like SOURCES, but for include directories. Value should be paths to
+# directories (without a leading -I).
+INCLUDES=./configs
+
+# Custom configuration of mbedtls library.
+MBEDTLSFLAGS = MBEDTLS_USER_CONFIG_FILE=<mbedtls_user_config.h>
+
+# Add additional defines to the build process (without a leading -D).
+DEFINES=$(MBEDTLSFLAGS) CYBSP_WIFI_CAPABLE CY_RETARGET_IO_CONVERT_LF_TO_CRLF CY_RTOS_AWARE
+
+# Enable support for Mosquitto Broker based on 'ENABLE_SECURE_MOSQUITTO_BROKER_
+# SUPPORT' variable. See the MQTT Client library's README for more information.
+ifneq (,$(filter $(ENABLE_SECURE_MOSQUITTO_BROKER_SUPPORT),true 1))
+DEFINES+=CY_MQTT_ENABLE_SECURE_TEST_MOSQUITTO_SUPPORT 
+endif
+
+# CY8CPROTO-062-4343W board shares the same GPIO for the user button (USER BTN1)
+# and the CYW4343W host wake up pin. Since this example uses the GPIO for  
+# interfacing with the user button, the SDIO interrupt to wake up the host is
+# disabled by setting CY_WIFI_HOST_WAKE_SW_FORCE to '0'.
+ifeq ($(TARGET), CY8CPROTO-062-4343W)
+DEFINES+=CY_WIFI_HOST_WAKE_SW_FORCE=0
+endif
+
+# Select softfp or hardfp floating point. Default is softfp.
+VFP_SELECT=
+
+COMMON_WARNING_FLAGS = -Wall -Werror=all \
+        -Wno-error=unused-function \
+        -Wno-error=unused-but-set-variable \
+        -Wno-error=unused-variable \
+        -Wno-error=deprecated-declarations \
+        -Wextra \
+        -Wno-unused-parameter -Wno-sign-compare \
+        -Wno-shadow \
+        -Wno-maybe-uninitialized \
+        -Wno-incompatible-pointer-types \
+        -Wno-type-limits \
+        -Wno-conversion
+
+# Additional / custom C compiler flags.
+#
+# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
+# above.
+CFLAGS=$(COMMON_WARNING_FLAGS)
+
+# Additional / custom C++ compiler flags.
+#
+# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
+# above.
+CXXFLAGS=
+
+# Additional / custom assembler flags.
+#
+# NOTE: Includes and defines should use the INCLUDES and DEFINES variable
+# above.
+ASFLAGS=
+
+# Additional / custom linker flags.
+LDFLAGS=
+
+# Additional / custom libraries to link in to the application.
+LDLIBS=
+
+# Path to the linker script to use (if empty, use the default linker script).
+LINKER_SCRIPT=
+
+# Custom pre-build commands to run.
+PREBUILD=
+
+# Custom post-build commands to run.
+POSTBUILD=
+
+
+################################################################################
+# Paths
+################################################################################
+
+# Relative path to the project directory (default is the Makefile's directory).
+#
+# This controls where automatic source code discovery looks for code.
+CY_APP_PATH=
+
+# Relative path to the shared repo location.
+#
+# All .mtb files have the format, <URI>#<COMMIT>#<LOCATION>. If the <LOCATION> field 
+# begins with $$ASSET_REPO$$, then the repo is deposited in the path specified by 
+# the CY_GETLIBS_SHARED_PATH variable. The default location is one directory level 
+# above the current app directory.
+# This is used with CY_GETLIBS_SHARED_NAME variable, which specifies the directory name.
+CY_GETLIBS_SHARED_PATH=../
+
+# Directory name of the shared repo location.
+#
+CY_GETLIBS_SHARED_NAME=mtb_shared
+
+# Absolute path to the compiler's "bin" directory.
+#
+# The default depends on the selected TOOLCHAIN (GCC_ARM uses the ModusToolbox
+# IDE provided compiler by default).
+CY_COMPILER_PATH=
+
+
+# Locate ModusToolbox IDE helper tools folders in default installation
+# locations for Windows, Linux, and macOS.
+CY_WIN_HOME=$(subst \,/,$(USERPROFILE))
+CY_TOOLS_PATHS ?= $(wildcard \
+    $(CY_WIN_HOME)/ModusToolbox/tools_* \
+    $(HOME)/ModusToolbox/tools_* \
+    /Applications/ModusToolbox/tools_*)
+
+# If you install ModusToolbox IDE in a custom location, add the path to its
+# "tools_X.Y" folder (where X and Y are the version number of the tools
+# folder). Make sure you use forward slashes.
+CY_TOOLS_PATHS+=
+
+# Default to the newest installed tools folder, or the users override (if it's
+# found).
+CY_TOOLS_DIR=$(lastword $(sort $(wildcard $(CY_TOOLS_PATHS))))
+
+ifeq ($(CY_TOOLS_DIR),)
+$(error Unable to find any of the available CY_TOOLS_PATHS -- $(CY_TOOLS_PATHS). On Windows, use forward slashes.)
+endif
+
+$(info Tools Directory: $(CY_TOOLS_DIR))
+
+include $(CY_TOOLS_DIR)/make/start.mk
+

+ 506 - 0
third_party/p6/p6_sdk/build/CY8CKIT-062S2-43012/Debug/GCC_ARM.json

@@ -0,0 +1,506 @@
+{
+    "cflags": [
+        "-Wall",
+        "-Werror=all",
+        "-Wno-error=unused-function",
+        "-Wno-error=unused-but-set-variable",
+        "-Wno-error=unused-variable",
+        "-Wno-error=deprecated-declarations",
+        "-Wextra",
+        "-Wno-unused-parameter",
+        "-Wno-sign-compare",
+        "-Wno-shadow",
+        "-Wno-maybe-uninitialized",
+        "-Wno-incompatible-pointer-types",
+        "-Wno-type-limits",
+        "-Wno-conversion",
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-Og",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall"
+    ],
+    "cxxflags": [
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-Og",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall",
+        "-fno-rtti",
+        "-fno-exceptions"
+    ],
+    "asflags": [
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall"
+    ],
+    "ldflags": [
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall",
+        "-Wl,--gc-sections",
+        "-T./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/cy8c6xxa_cm4_dual.ld"
+    ],
+    "includes": [
+        "-I./configs",
+        "-I.",
+        "-I./configs",
+        "-I./libs",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/bluetooth",
+        "-I./libs/abstraction-rtos",
+        "-I./libs/abstraction-rtos/include",
+        "-I./libs/abstraction-rtos/include/COMPONENT_FREERTOS",
+        "-I./libs/abstraction-rtos/include/Template",
+        "-I./libs/bluetooth-freertos",
+        "-I./libs/bluetooth-freertos/platform",
+        "-I./libs/bluetooth-freertos/platform/common",
+        "-I./libs/bluetooth-freertos/platform/include",
+        "-I./libs/btstack",
+        "-I./libs/btstack/wiced_include",
+        "-I./libs/clib-support",
+        "-I./libs/clib-support/TOOLCHAIN_GCC_ARM",
+        "-I./libs/connectivity-utilities",
+        "-I./libs/connectivity-utilities/JSON_parser",
+        "-I./libs/connectivity-utilities/cy_log",
+        "-I./libs/connectivity-utilities/cy_string",
+        "-I./libs/connectivity-utilities/linked_list",
+        "-I./libs/connectivity-utilities/network",
+        "-I./libs/core-lib",
+        "-I./libs/core-lib/include",
+        "-I./libs/freertos",
+        "-I./libs/freertos/Source",
+        "-I./libs/freertos/Source/include",
+        "-I./libs/freertos/Source/portable",
+        "-I./libs/freertos/Source/portable/COMPONENT_CM4",
+        "-I./libs/freertos/Source/portable/COMPONENT_CM4/TOOLCHAIN_GCC_ARM",
+        "-I./libs/kv-store",
+        "-I./libs/mbedtls",
+        "-I./libs/mbedtls/include",
+        "-I./libs/mbedtls/include/mbedtls",
+        "-I./libs/mtb-hal-cat1",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include/pin_packages",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include/triggers",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/include",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source",
+        "-I./libs/mtb-hal-cat1/include",
+        "-I./libs/mtb-pdl-cat1",
+        "-I./libs/mtb-pdl-cat1/cmsis",
+        "-I./libs/mtb-pdl-cat1/cmsis/include",
+        "-I./libs/mtb-pdl-cat1/devices",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include/ip",
+        "-I./libs/mtb-pdl-cat1/drivers",
+        "-I./libs/mtb-pdl-cat1/drivers/include",
+        "-I./libs/retarget-io",
+        "-I./libs/secure-sockets",
+        "-I./libs/secure-sockets/include",
+        "-I./libs/whd-bsp-integration",
+        "-I./libs/wifi-connection-manager",
+        "-I./libs/wifi-connection-manager/include",
+        "-I./libs/wifi-connection-manager/source",
+        "-I./libs/wifi-connection-manager/source/COMPONENT_43012",
+        "-I./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS",
+        "-I./libs/wifi-host-driver",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/inc",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/nvram",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/nvram/TARGET_CY8CKIT_062S2_43012",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/resource_imp",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src/include",
+        "-I./libs/wifi-mw-core",
+        "-I./libs/wifi-mw-core/lwip-whd-port",
+        "-I./libs/wifi-mw-core/lwip-whd-port/COMPONENT_FREERTOS"
+    ],
+    "defines": [
+        "-DMBEDTLS_USER_CONFIG_FILE=<mbedtls_user_config.h>",
+        "-DCYBSP_WIFI_CAPABLE",
+        "-DCY_RETARGET_IO_CONVERT_LF_TO_CRLF",
+        "-DCY_RTOS_AWARE",
+        "-DCY_USING_HAL",
+        "-DCY_APPNAME_mtb_chip_sdk",
+        "-DCY8C624ABZI_S2D44",
+        "-DCY_TARGET_DEVICE=CY8C624ABZI_S2D44",
+        "-DTARGET_CY8CKIT_062S2_43012",
+        "-DCY_TARGET_BOARD=CY8CKIT_062S2_43012",
+        "-DCOMPONENT_43012",
+        "-DCOMPONENT_BSP_DESIGN_MODUS",
+        "-DCOMPONENT_CAT1",
+        "-DCOMPONENT_CAT1A",
+        "-DCOMPONENT_CM0P_SLEEP",
+        "-DCOMPONENT_CM4",
+        "-DCOMPONENT_CY8CKIT_062S2_43012",
+        "-DCOMPONENT_FREERTOS",
+        "-DCOMPONENT_LWIP",
+        "-DCOMPONENT_MBEDTLS",
+        "-DCOMPONENT_PSOC6HAL",
+        "-DCOMPONENT_RTOS_AWARE",
+        "-DCOMPONENT_SOFTFP",
+        "-DCOMPONENT_WICED_BLE",
+        "-DCOMPONENT_WLCSP",
+        "-DDEBUG"
+    ],
+    "c_source": [
+        "./libs/abstraction-rtos/source/cy_worker_thread.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_hci_rx_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_hci_tx_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_host_stack_platform_interface.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_patchram_download.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_main.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_trace.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_prm.c",
+        "./libs/bluetooth-freertos/platform/freertos/cybt_platform_freertos.c",
+        "./libs/clib-support/cy_mutex_pool.c",
+        "./libs/clib-support/cy_time.c",
+        "./libs/connectivity-utilities/JSON_parser/cy_json_parser.c",
+        "./libs/connectivity-utilities/cy_log/cy_log.c",
+        "./libs/connectivity-utilities/cy_string/cy_string_utils.c",
+        "./libs/connectivity-utilities/linked_list/cy_linked_list.c",
+        "./libs/freertos/Source/croutine.c",
+        "./libs/freertos/Source/event_groups.c",
+        "./libs/freertos/Source/list.c",
+        "./libs/freertos/Source/portable/MemMang/heap_1.c",
+        "./libs/freertos/Source/portable/MemMang/heap_2.c",
+        "./libs/freertos/Source/portable/MemMang/heap_3.c",
+        "./libs/freertos/Source/portable/MemMang/heap_4.c",
+        "./libs/freertos/Source/portable/MemMang/heap_5.c",
+        "./libs/freertos/Source/queue.c",
+        "./libs/freertos/Source/stream_buffer.c",
+        "./libs/freertos/Source/tasks.c",
+        "./libs/freertos/Source/timers.c",
+        "./libs/kv-store/mtb_kvstore.c",
+        "./libs/mbedtls/library/aes.c",
+        "./libs/mbedtls/library/aesni.c",
+        "./libs/mbedtls/library/arc4.c",
+        "./libs/mbedtls/library/aria.c",
+        "./libs/mbedtls/library/asn1parse.c",
+        "./libs/mbedtls/library/asn1write.c",
+        "./libs/mbedtls/library/base64.c",
+        "./libs/mbedtls/library/bignum.c",
+        "./libs/mbedtls/library/blowfish.c",
+        "./libs/mbedtls/library/camellia.c",
+        "./libs/mbedtls/library/ccm.c",
+        "./libs/mbedtls/library/certs.c",
+        "./libs/mbedtls/library/chacha20.c",
+        "./libs/mbedtls/library/chachapoly.c",
+        "./libs/mbedtls/library/cipher.c",
+        "./libs/mbedtls/library/cipher_wrap.c",
+        "./libs/mbedtls/library/cmac.c",
+        "./libs/mbedtls/library/ctr_drbg.c",
+        "./libs/mbedtls/library/debug.c",
+        "./libs/mbedtls/library/des.c",
+        "./libs/mbedtls/library/dhm.c",
+        "./libs/mbedtls/library/ecdh.c",
+        "./libs/mbedtls/library/ecdsa.c",
+        "./libs/mbedtls/library/ecjpake.c",
+        "./libs/mbedtls/library/ecp.c",
+        "./libs/mbedtls/library/ecp_curves.c",
+        "./libs/mbedtls/library/entropy.c",
+        "./libs/mbedtls/library/entropy_poll.c",
+        "./libs/mbedtls/library/error.c",
+        "./libs/mbedtls/library/gcm.c",
+        "./libs/mbedtls/library/havege.c",
+        "./libs/mbedtls/library/hkdf.c",
+        "./libs/mbedtls/library/hmac_drbg.c",
+        "./libs/mbedtls/library/md.c",
+        "./libs/mbedtls/library/md2.c",
+        "./libs/mbedtls/library/md4.c",
+        "./libs/mbedtls/library/md5.c",
+        "./libs/mbedtls/library/md_wrap.c",
+        "./libs/mbedtls/library/memory_buffer_alloc.c",
+        "./libs/mbedtls/library/nist_kw.c",
+        "./libs/mbedtls/library/oid.c",
+        "./libs/mbedtls/library/padlock.c",
+        "./libs/mbedtls/library/pem.c",
+        "./libs/mbedtls/library/pk.c",
+        "./libs/mbedtls/library/pk_wrap.c",
+        "./libs/mbedtls/library/pkcs11.c",
+        "./libs/mbedtls/library/pkcs12.c",
+        "./libs/mbedtls/library/pkcs5.c",
+        "./libs/mbedtls/library/pkparse.c",
+        "./libs/mbedtls/library/pkwrite.c",
+        "./libs/mbedtls/library/platform.c",
+        "./libs/mbedtls/library/platform_util.c",
+        "./libs/mbedtls/library/poly1305.c",
+        "./libs/mbedtls/library/ripemd160.c",
+        "./libs/mbedtls/library/rsa.c",
+        "./libs/mbedtls/library/rsa_internal.c",
+        "./libs/mbedtls/library/sha1.c",
+        "./libs/mbedtls/library/sha256.c",
+        "./libs/mbedtls/library/sha512.c",
+        "./libs/mbedtls/library/ssl_cache.c",
+        "./libs/mbedtls/library/ssl_ciphersuites.c",
+        "./libs/mbedtls/library/ssl_cli.c",
+        "./libs/mbedtls/library/ssl_cookie.c",
+        "./libs/mbedtls/library/ssl_srv.c",
+        "./libs/mbedtls/library/ssl_ticket.c",
+        "./libs/mbedtls/library/ssl_tls.c",
+        "./libs/mbedtls/library/threading.c",
+        "./libs/mbedtls/library/timing.c",
+        "./libs/mbedtls/library/version.c",
+        "./libs/mbedtls/library/version_features.c",
+        "./libs/mbedtls/library/x509.c",
+        "./libs/mbedtls/library/x509_create.c",
+        "./libs/mbedtls/library/x509_crl.c",
+        "./libs/mbedtls/library/x509_crt.c",
+        "./libs/mbedtls/library/x509_csr.c",
+        "./libs/mbedtls/library/x509write_crt.c",
+        "./libs/mbedtls/library/x509write_csr.c",
+        "./libs/mbedtls/library/xtea.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ble_clk.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_canfd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_aes_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_aes_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_cmac_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_cmac_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_crc_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_crc_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_des_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_des_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_domain_params.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_ecdsa.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_key_gen.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_nist_p.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hmac_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hmac_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hw.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hw_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_mem_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_mem_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_prng_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_prng_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_rsa.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_sha_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_sha_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_trng_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_trng_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_vu.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_server.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_csd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ctb.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ctdac.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_dma.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_dmac.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_efuse.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_flash.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_gpio.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_i2s.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_drv.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_pipe.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_sema.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_lpcomp.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_lvd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_mcwdt.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pdm_pcm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pra.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pra_cfg.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_profile.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_prot.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_rtc.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sar.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_common.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_ezi2c.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_i2c.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_spi.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_uart.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sd_host.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_seglcd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smartio.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smif.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smif_memslot.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysanalog.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysclk.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysint.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_syslib.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_syspm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_systick.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_counter.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_pwm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_quaddec.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_shiftreg.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_trigmux.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv_io.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv_io_dma.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_wdt.c",
+        "./libs/retarget-io/cy_retarget_io.c",
+        "./libs/secure-sockets/source/cy_tls_weak.c",
+        "./libs/whd-bsp-integration/cy_network_buffer.c",
+        "./libs/whd-bsp-integration/cybsp_wifi.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/resource_imp/whd_resources.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_common.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_sdio_protocol.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_spi_protocol.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_ap.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_buffer_api.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_cdc_bdc.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_chip.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_chip_constants.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_clm.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_debug.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_events.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_logging.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_management.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_network_if.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_resource_if.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_sdpcm.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_thread.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_utils.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi_api.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi_p2p.c",
+        "./libs/wifi-mw-core/lwip-whd-port/cy_lwip.c",
+        "./libs/wifi-mw-core/lwip-whd-port/cy_lwip_dhcp_server.c",
+        "./libs/clib-support/TOOLCHAIN_GCC_ARM/cy_newlib_freertos.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/bluetooth/cybsp_bt_config.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/cybsp.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_clocks.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_connectivity_bt.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_peripherals.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_pins.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_qspi_memslot.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_routing.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_system.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/system_psoc6_cm4.c",
+        "./libs/abstraction-rtos/source/COMPONENT_FREERTOS/cyabs_freertos_helpers.c",
+        "./libs/abstraction-rtos/source/COMPONENT_FREERTOS/cyabs_rtos_freertos.c",
+        "./libs/bluetooth-freertos/firmware/COMPONENT_43012/TARGET_CY8CKIT_062S2_43012/w_bt_firmware_controller.c",
+        "./libs/connectivity-utilities/network/COMPONENT_LWIP/cy_nw_helper.c",
+        "./libs/freertos/Source/portable/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/port.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/cyhal_deprecated.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_104_m_csp_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_104_m_csp_ble_usb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_116_bga_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_116_bga_usb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_124_bga.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_124_bga_sip.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_43_smt.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_68_qfn_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_80_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_100_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_124_bga.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_128_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_100_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_49_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_64_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_80_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_01.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_03.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_04.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_adc_mic.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_adc_sar.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_analog_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_audio_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_clock.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp_ctb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp_lp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_crc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_crypto_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dac.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma_dmac.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma_dw.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_ezi2c.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_flash.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_gpio.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_hwmgr.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_i2c.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_i2s.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_interconnect.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_keyscan.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_lptimer.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_opamp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_pdmpcm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_pwm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_qspi.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_quaddec.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_rtc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_scb_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_sdhc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_spi.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_syspm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_system.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_tcpwm_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_tdm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_timer.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_trng.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_uart.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_udb_sdio.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_usb_dev.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_utils.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_utils_psoc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_wdt.c",
+        "./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_01_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_02_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_03_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_04_cm0p_sleep.c",
+        "./libs/secure-sockets/source/COMPONENT_LWIP/cy_secure_sockets.c",
+        "./libs/secure-sockets/source/COMPONENT_MBEDTLS/cy_tls.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_LWIP/cy_wcm.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS/cy_wps_aes_ctr_ccm.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS/cy_wps_crypto.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0-mfgtest_bin.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0-mfgtest_clm_blob.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0_bin.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0_clm_blob.c"
+    ],
+    "cxx_source": [],
+    "asm_source": [
+        "./libs/mtb-pdl-cat1/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/startup_psoc6_02_cm4.S"
+    ],
+    "libs": [
+        "./libs/btstack/stack/COMPONENT_WICED_BLE/COMPONENT_CM4/COMPONENT_SOFTFP/TOOLCHAIN_GCC_ARM/libbtstack.a"
+    ],
+    "objs": []
+}

+ 506 - 0
third_party/p6/p6_sdk/build/CY8CKIT-062S2-43012/Release/GCC_ARM.json

@@ -0,0 +1,506 @@
+{
+    "cflags": [
+        "-Wall",
+        "-Werror=all",
+        "-Wno-error=unused-function",
+        "-Wno-error=unused-but-set-variable",
+        "-Wno-error=unused-variable",
+        "-Wno-error=deprecated-declarations",
+        "-Wextra",
+        "-Wno-unused-parameter",
+        "-Wno-sign-compare",
+        "-Wno-shadow",
+        "-Wno-maybe-uninitialized",
+        "-Wno-incompatible-pointer-types",
+        "-Wno-type-limits",
+        "-Wno-conversion",
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-Os",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall"
+    ],
+    "cxxflags": [
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-Os",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall",
+        "-fno-rtti",
+        "-fno-exceptions"
+    ],
+    "asflags": [
+        "-c",
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall"
+    ],
+    "ldflags": [
+        "-mcpu=cortex-m4",
+        "--specs=nano.specs",
+        "-mfloat-abi=softfp",
+        "-mfpu=fpv4-sp-d16",
+        "-mthumb",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-ffat-lto-objects",
+        "-g",
+        "-Wall",
+        "-Wl,--gc-sections",
+        "-T./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/cy8c6xxa_cm4_dual.ld"
+    ],
+    "includes": [
+        "-I./configs",
+        "-I.",
+        "-I./configs",
+        "-I./libs",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource",
+        "-I./libs/TARGET_CY8CKIT-062S2-43012/bluetooth",
+        "-I./libs/abstraction-rtos",
+        "-I./libs/abstraction-rtos/include",
+        "-I./libs/abstraction-rtos/include/COMPONENT_FREERTOS",
+        "-I./libs/abstraction-rtos/include/Template",
+        "-I./libs/bluetooth-freertos",
+        "-I./libs/bluetooth-freertos/platform",
+        "-I./libs/bluetooth-freertos/platform/common",
+        "-I./libs/bluetooth-freertos/platform/include",
+        "-I./libs/btstack",
+        "-I./libs/btstack/wiced_include",
+        "-I./libs/clib-support",
+        "-I./libs/clib-support/TOOLCHAIN_GCC_ARM",
+        "-I./libs/connectivity-utilities",
+        "-I./libs/connectivity-utilities/JSON_parser",
+        "-I./libs/connectivity-utilities/cy_log",
+        "-I./libs/connectivity-utilities/cy_string",
+        "-I./libs/connectivity-utilities/linked_list",
+        "-I./libs/connectivity-utilities/network",
+        "-I./libs/core-lib",
+        "-I./libs/core-lib/include",
+        "-I./libs/freertos",
+        "-I./libs/freertos/Source",
+        "-I./libs/freertos/Source/include",
+        "-I./libs/freertos/Source/portable",
+        "-I./libs/freertos/Source/portable/COMPONENT_CM4",
+        "-I./libs/freertos/Source/portable/COMPONENT_CM4/TOOLCHAIN_GCC_ARM",
+        "-I./libs/kv-store",
+        "-I./libs/mbedtls",
+        "-I./libs/mbedtls/include",
+        "-I./libs/mbedtls/include/mbedtls",
+        "-I./libs/mtb-hal-cat1",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include/pin_packages",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/include/triggers",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/include",
+        "-I./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source",
+        "-I./libs/mtb-hal-cat1/include",
+        "-I./libs/mtb-pdl-cat1",
+        "-I./libs/mtb-pdl-cat1/cmsis",
+        "-I./libs/mtb-pdl-cat1/cmsis/include",
+        "-I./libs/mtb-pdl-cat1/devices",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include",
+        "-I./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include/ip",
+        "-I./libs/mtb-pdl-cat1/drivers",
+        "-I./libs/mtb-pdl-cat1/drivers/include",
+        "-I./libs/retarget-io",
+        "-I./libs/secure-sockets",
+        "-I./libs/secure-sockets/include",
+        "-I./libs/whd-bsp-integration",
+        "-I./libs/wifi-connection-manager",
+        "-I./libs/wifi-connection-manager/include",
+        "-I./libs/wifi-connection-manager/source",
+        "-I./libs/wifi-connection-manager/source/COMPONENT_43012",
+        "-I./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS",
+        "-I./libs/wifi-host-driver",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/inc",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/nvram",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/nvram/TARGET_CY8CKIT_062S2_43012",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/resources/resource_imp",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols",
+        "-I./libs/wifi-host-driver/WiFi_Host_Driver/src/include",
+        "-I./libs/wifi-mw-core",
+        "-I./libs/wifi-mw-core/lwip-whd-port",
+        "-I./libs/wifi-mw-core/lwip-whd-port/COMPONENT_FREERTOS"
+    ],
+    "defines": [
+        "-DMBEDTLS_USER_CONFIG_FILE=<mbedtls_user_config.h>",
+        "-DCYBSP_WIFI_CAPABLE",
+        "-DCY_RETARGET_IO_CONVERT_LF_TO_CRLF",
+        "-DCY_RTOS_AWARE",
+        "-DCY_USING_HAL",
+        "-DCY_APPNAME_mtb_chip_sdk",
+        "-DCY8C624ABZI_S2D44",
+        "-DCY_TARGET_DEVICE=CY8C624ABZI_S2D44",
+        "-DTARGET_CY8CKIT_062S2_43012",
+        "-DCY_TARGET_BOARD=CY8CKIT_062S2_43012",
+        "-DCOMPONENT_43012",
+        "-DCOMPONENT_BSP_DESIGN_MODUS",
+        "-DCOMPONENT_CAT1",
+        "-DCOMPONENT_CAT1A",
+        "-DCOMPONENT_CM0P_SLEEP",
+        "-DCOMPONENT_CM4",
+        "-DCOMPONENT_CY8CKIT_062S2_43012",
+        "-DCOMPONENT_FREERTOS",
+        "-DCOMPONENT_LWIP",
+        "-DCOMPONENT_MBEDTLS",
+        "-DCOMPONENT_PSOC6HAL",
+        "-DCOMPONENT_RTOS_AWARE",
+        "-DCOMPONENT_SOFTFP",
+        "-DCOMPONENT_WICED_BLE",
+        "-DCOMPONENT_WLCSP",
+        "-DNDEBUG"
+    ],
+    "c_source": [
+        "./libs/abstraction-rtos/source/cy_worker_thread.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_hci_rx_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_hci_tx_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_host_stack_platform_interface.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_patchram_download.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_main.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_task.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_platform_trace.c",
+        "./libs/bluetooth-freertos/platform/common/cybt_prm.c",
+        "./libs/bluetooth-freertos/platform/freertos/cybt_platform_freertos.c",
+        "./libs/clib-support/cy_mutex_pool.c",
+        "./libs/clib-support/cy_time.c",
+        "./libs/connectivity-utilities/JSON_parser/cy_json_parser.c",
+        "./libs/connectivity-utilities/cy_log/cy_log.c",
+        "./libs/connectivity-utilities/cy_string/cy_string_utils.c",
+        "./libs/connectivity-utilities/linked_list/cy_linked_list.c",
+        "./libs/freertos/Source/croutine.c",
+        "./libs/freertos/Source/event_groups.c",
+        "./libs/freertos/Source/list.c",
+        "./libs/freertos/Source/portable/MemMang/heap_1.c",
+        "./libs/freertos/Source/portable/MemMang/heap_2.c",
+        "./libs/freertos/Source/portable/MemMang/heap_3.c",
+        "./libs/freertos/Source/portable/MemMang/heap_4.c",
+        "./libs/freertos/Source/portable/MemMang/heap_5.c",
+        "./libs/freertos/Source/queue.c",
+        "./libs/freertos/Source/stream_buffer.c",
+        "./libs/freertos/Source/tasks.c",
+        "./libs/freertos/Source/timers.c",
+        "./libs/kv-store/mtb_kvstore.c",
+        "./libs/mbedtls/library/aes.c",
+        "./libs/mbedtls/library/aesni.c",
+        "./libs/mbedtls/library/arc4.c",
+        "./libs/mbedtls/library/aria.c",
+        "./libs/mbedtls/library/asn1parse.c",
+        "./libs/mbedtls/library/asn1write.c",
+        "./libs/mbedtls/library/base64.c",
+        "./libs/mbedtls/library/bignum.c",
+        "./libs/mbedtls/library/blowfish.c",
+        "./libs/mbedtls/library/camellia.c",
+        "./libs/mbedtls/library/ccm.c",
+        "./libs/mbedtls/library/certs.c",
+        "./libs/mbedtls/library/chacha20.c",
+        "./libs/mbedtls/library/chachapoly.c",
+        "./libs/mbedtls/library/cipher.c",
+        "./libs/mbedtls/library/cipher_wrap.c",
+        "./libs/mbedtls/library/cmac.c",
+        "./libs/mbedtls/library/ctr_drbg.c",
+        "./libs/mbedtls/library/debug.c",
+        "./libs/mbedtls/library/des.c",
+        "./libs/mbedtls/library/dhm.c",
+        "./libs/mbedtls/library/ecdh.c",
+        "./libs/mbedtls/library/ecdsa.c",
+        "./libs/mbedtls/library/ecjpake.c",
+        "./libs/mbedtls/library/ecp.c",
+        "./libs/mbedtls/library/ecp_curves.c",
+        "./libs/mbedtls/library/entropy.c",
+        "./libs/mbedtls/library/entropy_poll.c",
+        "./libs/mbedtls/library/error.c",
+        "./libs/mbedtls/library/gcm.c",
+        "./libs/mbedtls/library/havege.c",
+        "./libs/mbedtls/library/hkdf.c",
+        "./libs/mbedtls/library/hmac_drbg.c",
+        "./libs/mbedtls/library/md.c",
+        "./libs/mbedtls/library/md2.c",
+        "./libs/mbedtls/library/md4.c",
+        "./libs/mbedtls/library/md5.c",
+        "./libs/mbedtls/library/md_wrap.c",
+        "./libs/mbedtls/library/memory_buffer_alloc.c",
+        "./libs/mbedtls/library/nist_kw.c",
+        "./libs/mbedtls/library/oid.c",
+        "./libs/mbedtls/library/padlock.c",
+        "./libs/mbedtls/library/pem.c",
+        "./libs/mbedtls/library/pk.c",
+        "./libs/mbedtls/library/pk_wrap.c",
+        "./libs/mbedtls/library/pkcs11.c",
+        "./libs/mbedtls/library/pkcs12.c",
+        "./libs/mbedtls/library/pkcs5.c",
+        "./libs/mbedtls/library/pkparse.c",
+        "./libs/mbedtls/library/pkwrite.c",
+        "./libs/mbedtls/library/platform.c",
+        "./libs/mbedtls/library/platform_util.c",
+        "./libs/mbedtls/library/poly1305.c",
+        "./libs/mbedtls/library/ripemd160.c",
+        "./libs/mbedtls/library/rsa.c",
+        "./libs/mbedtls/library/rsa_internal.c",
+        "./libs/mbedtls/library/sha1.c",
+        "./libs/mbedtls/library/sha256.c",
+        "./libs/mbedtls/library/sha512.c",
+        "./libs/mbedtls/library/ssl_cache.c",
+        "./libs/mbedtls/library/ssl_ciphersuites.c",
+        "./libs/mbedtls/library/ssl_cli.c",
+        "./libs/mbedtls/library/ssl_cookie.c",
+        "./libs/mbedtls/library/ssl_srv.c",
+        "./libs/mbedtls/library/ssl_ticket.c",
+        "./libs/mbedtls/library/ssl_tls.c",
+        "./libs/mbedtls/library/threading.c",
+        "./libs/mbedtls/library/timing.c",
+        "./libs/mbedtls/library/version.c",
+        "./libs/mbedtls/library/version_features.c",
+        "./libs/mbedtls/library/x509.c",
+        "./libs/mbedtls/library/x509_create.c",
+        "./libs/mbedtls/library/x509_crl.c",
+        "./libs/mbedtls/library/x509_crt.c",
+        "./libs/mbedtls/library/x509_csr.c",
+        "./libs/mbedtls/library/x509write_crt.c",
+        "./libs/mbedtls/library/x509write_csr.c",
+        "./libs/mbedtls/library/xtea.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ble_clk.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_canfd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_aes_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_aes_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_cmac_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_cmac_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_crc_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_crc_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_des_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_des_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_domain_params.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_ecdsa.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_key_gen.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_ecc_nist_p.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hmac_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hmac_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hw.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_hw_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_mem_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_mem_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_prng_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_prng_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_rsa.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_sha_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_sha_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_trng_v1.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_trng_v2.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_core_vu.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_crypto_server.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_csd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ctb.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ctdac.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_dma.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_dmac.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_efuse.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_flash.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_gpio.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_i2s.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_drv.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_pipe.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_ipc_sema.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_lpcomp.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_lvd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_mcwdt.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pdm_pcm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pra.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_pra_cfg.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_profile.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_prot.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_rtc.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sar.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_common.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_ezi2c.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_i2c.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_spi.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_scb_uart.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sd_host.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_seglcd.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smartio.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smif.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_smif_memslot.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysanalog.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysclk.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_sysint.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_syslib.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_syspm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_systick.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_counter.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_pwm.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_quaddec.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_tcpwm_shiftreg.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_trigmux.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv_io.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_usbfs_dev_drv_io_dma.c",
+        "./libs/mtb-pdl-cat1/drivers/source/cy_wdt.c",
+        "./libs/retarget-io/cy_retarget_io.c",
+        "./libs/secure-sockets/source/cy_tls_weak.c",
+        "./libs/whd-bsp-integration/cy_network_buffer.c",
+        "./libs/whd-bsp-integration/cybsp_wifi.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/resource_imp/whd_resources.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_common.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_sdio_protocol.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/bus_protocols/whd_bus_spi_protocol.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_ap.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_buffer_api.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_cdc_bdc.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_chip.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_chip_constants.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_clm.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_debug.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_events.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_logging.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_management.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_network_if.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_resource_if.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_sdpcm.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_thread.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_utils.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi_api.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/src/whd_wifi_p2p.c",
+        "./libs/wifi-mw-core/lwip-whd-port/cy_lwip.c",
+        "./libs/wifi-mw-core/lwip-whd-port/cy_lwip_dhcp_server.c",
+        "./libs/clib-support/TOOLCHAIN_GCC_ARM/cy_newlib_freertos.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/bluetooth/cybsp_bt_config.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/cybsp.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_clocks.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_connectivity_bt.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_peripherals.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_pins.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_qspi_memslot.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_routing.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_BSP_DESIGN_MODUS/GeneratedSource/cycfg_system.c",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/system_psoc6_cm4.c",
+        "./libs/abstraction-rtos/source/COMPONENT_FREERTOS/cyabs_freertos_helpers.c",
+        "./libs/abstraction-rtos/source/COMPONENT_FREERTOS/cyabs_rtos_freertos.c",
+        "./libs/bluetooth-freertos/firmware/COMPONENT_43012/TARGET_CY8CKIT_062S2_43012/w_bt_firmware_controller.c",
+        "./libs/connectivity-utilities/network/COMPONENT_LWIP/cy_nw_helper.c",
+        "./libs/freertos/Source/portable/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/port.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/cyhal_deprecated.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_104_m_csp_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_104_m_csp_ble_usb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_116_bga_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_116_bga_usb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_124_bga.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_124_bga_sip.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_43_smt.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_68_qfn_ble.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_80_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_100_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_124_bga.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_128_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_100_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_49_wlcsp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_64_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_68_qfn.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_80_tqfp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_01.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_03.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_04.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_adc_mic.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_adc_sar.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_analog_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_audio_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_clock.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp_ctb.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_comp_lp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_crc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_crypto_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dac.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma_dmac.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_dma_dw.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_ezi2c.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_flash.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_gpio.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_hwmgr.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_i2c.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_i2s.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_interconnect.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_keyscan.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_lptimer.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_opamp.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_pdmpcm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_pwm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_qspi.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_quaddec.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_rtc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_scb_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_sdhc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_spi.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_syspm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_system.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_tcpwm_common.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_tdm.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_timer.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_trng.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_uart.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_udb_sdio.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_usb_dev.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_utils.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_utils_psoc.c",
+        "./libs/mtb-hal-cat1/COMPONENT_PSOC6HAL/source/cyhal_wdt.c",
+        "./libs/mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_01_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_02_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_03_cm0p_sleep.c",
+        "./libs/psoc6cm0p/COMPONENT_CM0P_SLEEP/psoc6_04_cm0p_sleep.c",
+        "./libs/secure-sockets/source/COMPONENT_LWIP/cy_secure_sockets.c",
+        "./libs/secure-sockets/source/COMPONENT_MBEDTLS/cy_tls.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_LWIP/cy_wcm.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS/cy_wps_aes_ctr_ccm.c",
+        "./libs/wifi-connection-manager/source/COMPONENT_MBEDTLS/cy_wps_crypto.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0-mfgtest_bin.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0-mfgtest_clm_blob.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0_bin.c",
+        "./libs/wifi-host-driver/WiFi_Host_Driver/resources/firmware/COMPONENT_43012/43012C0_clm_blob.c"
+    ],
+    "cxx_source": [],
+    "asm_source": [
+        "./libs/mtb-pdl-cat1/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S",
+        "./libs/TARGET_CY8CKIT-062S2-43012/COMPONENT_CM4/TOOLCHAIN_GCC_ARM/startup_psoc6_02_cm4.S"
+    ],
+    "libs": [
+        "./libs/btstack/stack/COMPONENT_WICED_BLE/COMPONENT_CM4/COMPONENT_SOFTFP/TOOLCHAIN_GCC_ARM/libbtstack.a"
+    ],
+    "objs": []
+}

+ 199 - 0
third_party/p6/p6_sdk/configs/FreeRTOSConfig.h

@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2019-2021 Cypress Semiconductor Corporation. or a subsidiary of
+ * Cypress Semiconductor Corporation.  All Rights Reserved.
+ *
+ * Updated configuration to support PSoC 6 MCU.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://www.Cypress.com
+ *
+ *
+ */
+
+#ifndef FREERTOS_CONFIG_H
+#define FREERTOS_CONFIG_H
+
+#if defined(__ICCARM__) || defined(__GNUC__)
+#include "cy_pdl.h"
+#endif
+
+/*-----------------------------------------------------------
+ * Application specific definitions.
+ *
+ * These definitions should be adjusted for your particular hardware and
+ * application requirements.
+ *
+ * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
+ * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
+ *
+ * See http://www.freertos.org/a00110.html.
+ *----------------------------------------------------------*/
+
+/* Ensure stdint is only used by the compiler, and not the assembler. */
+#ifdef __ICCARM__
+#include <stdint.h>
+extern uint32_t SystemCoreClock;
+#endif
+
+#include "cycfg_system.h"
+
+#define configUSE_PREEMPTION 1
+
+#define configCPU_CLOCK_HZ SystemCoreClock
+#define configTICK_RATE_HZ 1000u
+#define configMAX_PRIORITIES 7
+#define configMINIMAL_STACK_SIZE 128
+#define configMAX_TASK_NAME_LEN 16
+#define configUSE_16_BIT_TICKS 0
+#define configIDLE_SHOULD_YIELD 1
+#define configUSE_MUTEXES 1
+#define configUSE_RECURSIVE_MUTEXES 1
+#define configUSE_COUNTING_SEMAPHORES 1
+#define configQUEUE_REGISTRY_SIZE 10
+#define configUSE_NEWLIB_REENTRANT 1
+#define configENABLE_BACKWARD_COMPATIBILITY 1
+
+/* Memory allocation related definitions. */
+#define configSUPPORT_STATIC_ALLOCATION 1
+#define configSUPPORT_DYNAMIC_ALLOCATION 1
+#define configTOTAL_HEAP_SIZE ((size_t)(CY_SRAM_SIZE - (64 * 1024)))
+/* Hook function related definitions. */
+#define configUSE_IDLE_HOOK 0
+#define configUSE_TICK_HOOK 0
+#define configCHECK_FOR_STACK_OVERFLOW 2
+
+#define configUSE_MALLOC_FAILED_HOOK 1
+#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
+#define configUSE_APPLICATION_TASK_TAG 0
+
+/* Run time and task stats gathering related definitions. */
+#define configGENERATE_RUN_TIME_STATS 0
+#define configUSE_TRACE_FACILITY 1
+
+#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 16
+
+/* Co-routine related definitions. */
+#define configUSE_CO_ROUTINES 0
+#define configMAX_CO_ROUTINE_PRIORITIES 2
+
+/* Software timer related definitions. */
+#define configUSE_TIMERS 1
+#define configTIMER_TASK_PRIORITY 2
+#define configTIMER_QUEUE_LENGTH 10
+#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2)
+
+/* Queue Creation Fix to not use static queue */
+#define LWIP_FREERTOS_USE_STATIC_TCPIP_QUEUE 0
+
+/*
+Interrupt nesting behavior configuration.
+This is explained here: http://www.freertos.org/a00110.html
+
+Priorities are controlled by two macros:
+- configKERNEL_INTERRUPT_PRIORITY determines the priority of the RTOS daemon task
+- configMAX_API_CALL_INTERRUPT_PRIORITY dictates the priority of ISRs that make API calls
+
+Notes:
+1. Interrupts that do not call API functions should be >= configKERNEL_INTERRUPT_PRIORITY
+   and will nest.
+2. Interrupts that call API functions must have priority between KERNEL_INTERRUPT_PRIORITY
+   and MAX_API_CALL_INTERRUPT_PRIORITY (inclusive).
+3. Interrupts running above MAX_API_CALL_INTERRUPT_PRIORITY are never delayed by the OS.
+*/
+/*
+PSoC 6 __NVIC_PRIO_BITS = 3
+
+0 (high)
+1           MAX_API_CALL_INTERRUPT_PRIORITY 001xxxxx (0x3F)
+2
+3
+4
+5
+6
+7 (low)     KERNEL_INTERRUPT_PRIORITY       111xxxxx (0xFF)
+
+!!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
+See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
+*/
+
+/* Put KERNEL_INTERRUPT_PRIORITY in top __NVIC_PRIO_BITS bits of CM4 register */
+#define configKERNEL_INTERRUPT_PRIORITY 0xFF
+/*
+Put MAX_SYSCALL_INTERRUPT_PRIORITY in top __NVIC_PRIO_BITS bits of CM4 register
+NOTE For IAR compiler make sure that changes of this macro is reflected in
+file portable\IAR\CM4F\portasm.s in PendSV_Handler: routine
+*/
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x3F
+/* configMAX_API_CALL_INTERRUPT_PRIORITY is a new name for configMAX_SYSCALL_INTERRUPT_PRIORITY
+ that is used by newer ports only. The two are equivalent. */
+#define configMAX_API_CALL_INTERRUPT_PRIORITY configMAX_SYSCALL_INTERRUPT_PRIORITY
+
+/* Set the following definitions to 1 to include the API function, or zero
+to exclude the API function. */
+#define INCLUDE_vTaskPrioritySet 1
+#define INCLUDE_uxTaskPriorityGet 1
+#define INCLUDE_vTaskDelete 1
+#define INCLUDE_vTaskCleanUpResources 1
+#define INCLUDE_vTaskSuspend 1
+#define INCLUDE_vTaskDelayUntil 1
+#define INCLUDE_vTaskDelay 1
+#define INCLUDE_xTaskIsTaskFinished 1
+#define INCLUDE_xTimerPendFunctionCall 1
+
+/* Normal assert() semantics without relying on the provision of an assert.h
+header file. */
+#define configASSERT(x)                                                                                                            \
+    if ((x) == 0)                                                                                                                  \
+    {                                                                                                                              \
+        taskDISABLE_INTERRUPTS();                                                                                                  \
+        for (;;)                                                                                                                   \
+            ;                                                                                                                      \
+    }
+
+/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
+standard names - or at least those used in the unmodified vector table. */
+#define vPortSVCHandler SVC_Handler
+#define xPortPendSVHandler PendSV_Handler
+#define xPortSysTickHandler SysTick_Handler
+
+/* Dynamic Memory Allocation Schemes */
+#define HEAP_ALLOCATION_TYPE1 (1) /* heap_1.c*/
+#define HEAP_ALLOCATION_TYPE2 (2) /* heap_2.c*/
+#define HEAP_ALLOCATION_TYPE3 (3) /* heap_3.c*/
+#define HEAP_ALLOCATION_TYPE4 (4) /* heap_4.c*/
+#define HEAP_ALLOCATION_TYPE5 (5) /* heap_5.c*/
+#define NO_HEAP_ALLOCATION (0)
+
+#define configHEAP_ALLOCATION_SCHEME (HEAP_ALLOCATION_TYPE3)
+
+#if defined(CY_CFG_PWR_SYS_IDLE_MODE) &&                                                                                           \
+    ((CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_SLEEP) || (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP))
+extern void vApplicationSleep(uint32_t xExpectedIdleTime);
+#define portSUPPRESS_TICKS_AND_SLEEP(xIdleTime) vApplicationSleep(xIdleTime)
+#define configUSE_TICKLESS_IDLE 2
+#else
+#define configUSE_TICKLESS_IDLE 0
+#endif
+
+/* Deep Sleep Latency Configuration */
+#if CY_CFG_PWR_DEEPSLEEP_LATENCY > 0
+#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CY_CFG_PWR_DEEPSLEEP_LATENCY
+#endif
+
+#endif /* FREERTOS_CONFIG_H */

+ 148 - 0
third_party/p6/p6_sdk/configs/iot_config.h

@@ -0,0 +1,148 @@
+/*
+ * Copyright 2020-2021, Cypress Semiconductor Corporation or a subsidiary of
+ * Cypress Semiconductor Corporation. All Rights Reserved.
+ *
+ * This software, including source code, documentation and related
+ * materials ("Software"), is owned by Cypress Semiconductor Corporation
+ * or one of its subsidiaries ("Cypress") and is protected by and subject to
+ * worldwide patent protection (United States and foreign),
+ * United States copyright laws and international treaty provisions.
+ * Therefore, you may use this Software only as provided in the license
+ * agreement accompanying the software package from which you
+ * obtained this Software ("EULA").
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software
+ * source code solely for use in connection with Cypress's
+ * integrated circuit products. Any reproduction, modification, translation,
+ * compilation, or representation of this Software except as specified
+ * above is prohibited without the express written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer
+ * of such system or application assumes all risk of such use and in doing
+ * so agrees to indemnify Cypress against all liability.
+ */
+/*
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file iot_config.h
+ * @brief This file contains configuration settings for the MQTT Library.
+ */
+
+#ifndef IOT_CONFIG_H_
+#define IOT_CONFIG_H_
+
+#include "cy_iot_platform_types.h"
+
+#include <assert.h>
+#include <stdlib.h>
+
+/**
+ * @addtogroup mqtt_cyport_config
+ * @{
+ */
+/**
+ * @brief Default thread priority for the threads created by AWS IoT Device SDK.
+ */
+#define IOT_THREAD_DEFAULT_PRIORITY (CY_RTOS_PRIORITY_NORMAL)
+/**
+ * @brief Default thread stack size for the threads created by AWS IoT Device SDK.
+ * The stack size may be tuned to suit the desired use case.
+ */
+#define IOT_THREAD_DEFAULT_STACK_SIZE (2048)
+
+/**
+ * @brief Default wait time (in milliseconds) to receive keep-alive responses from the MQTT broker. This value may be adjusted to
+ * suit the use case and network environment. Refer aws-iot-device-sdk-embedded-C/doc/lib/mqtt.txt for additional info.
+ */
+#define IOT_MQTT_RESPONSE_WAIT_MS (5000U)
+
+/**
+ * \cond
+ * @brief Macros to enable/disable asserts in the IoT Device SDK library.
+ * Asserts are disabled by default; to enable asserts, modify these macros to 1.
+ */
+#define IOT_CONTAINERS_ENABLE_ASSERTS (0)
+#define IOT_MQTT_ENABLE_ASSERTS (0)
+#define IOT_TASKPOOL_ENABLE_ASSERTS (0)
+#define AWS_IOT_SHADOW_ENABLE_ASSERTS (0)
+#define AWS_IOT_DEFENDER_ENABLE_ASSERTS (0)
+#define AWS_IOT_JOBS_ENABLE_ASSERTS (0)
+/**
+ * \endcond
+ */
+
+/**
+ * @brief Insert program diagnostics. This function should have the same signature as
+ * [assert](https://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html)
+ */
+#if (IOT_CONTAINERS_ENABLE_ASSERTS == 1) || (IOT_MQTT_ENABLE_ASSERTS == 1) || (IOT_TASKPOOL_ENABLE_ASSERTS == 1) ||                \
+    (AWS_IOT_SHADOW_ENABLE_ASSERTS == 1) || (AWS_IOT_DEFENDER_ENABLE_ASSERTS == 1) || (AWS_IOT_JOBS_ENABLE_ASSERTS == 1)
+#define Iot_DefaultAssert assert
+#else
+#define Iot_DefaultAssert
+#endif
+
+/**
+ * @brief Memory allocation. This function should have the same signature as
+ * [malloc](http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html)
+ */
+#define Iot_DefaultMalloc malloc
+
+/**
+ * @brief Free memory. This function should have the same signature as
+ * [free](http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html)
+ */
+#define Iot_DefaultFree free
+
+/**
+ * \cond
+ * @brief Library logging configuration. Configure the below macros to enable/disable debug logs in the library
+ * Refer aws-iot-device-sdk-embedded-C/libraries/standard/common/include/iot_logging.h
+ * for supported log levels.
+ */
+#define IOT_LOG_LEVEL_GLOBAL IOT_LOG_ERROR
+#define IOT_LOG_LEVEL_DEMO IOT_LOG_ERROR
+#define IOT_LOG_LEVEL_PLATFORM IOT_LOG_ERROR
+#define IOT_LOG_LEVEL_NETWORK IOT_LOG_ERROR
+#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_ERROR
+#define IOT_LOG_LEVEL_MQTT IOT_LOG_ERROR
+#define AWS_IOT_LOG_LEVEL_SHADOW IOT_LOG_ERROR
+#define AWS_IOT_LOG_LEVEL_DEFENDER IOT_LOG_ERROR
+#define AWS_IOT_LOG_LEVEL_JOBS IOT_LOG_ERROR
+/**
+ * \endcond
+ */
+
+/**
+ * @}
+ */
+
+#endif /* ifndef IOT_CONFIG_H_ */

+ 725 - 0
third_party/p6/p6_sdk/configs/mbedtls_user_config.h

@@ -0,0 +1,725 @@
+/**
+ * \file mbedtls_user_config.h
+ *
+ * \brief Configuration options (set of defines)
+ *
+ *  This set of compile-time options may be used to enable
+ *  or disable features selectively, and reduce the global
+ *  memory footprint.
+ */
+/*
+ *  Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  This file is part of mbed TLS (https://tls.mbed.org)
+ */
+
+#ifndef MBEDTLS_USER_CONFIG_HEADER
+#define MBEDTLS_USER_CONFIG_HEADER
+
+/**
+ * \def MBEDTLS_HAVE_TIME_DATE
+ *
+ * System has time.h, time(), and an implementation for
+ * mbedtls_platform_gmtime_r() (see below).
+ * The time needs to be correct (not necessarily very accurate, but at least
+ * the date should be correct). This is used to verify the validity period of
+ * X.509 certificates.
+ *
+ * Comment if your system does not have a correct clock.
+ *
+ * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h that
+ * behaves similarly to the gmtime_r() function from the C standard. Refer to
+ * the documentation for mbedtls_platform_gmtime_r() for more information.
+ *
+ * \note It is possible to configure an implementation for
+ * mbedtls_platform_gmtime_r() at compile-time by using the macro
+ * MBEDTLS_PLATFORM_GMTIME_R_ALT.
+ */
+#undef MBEDTLS_HAVE_TIME_DATE
+
+/**
+ * \def MBEDTLS_PLATFORM_EXIT_ALT
+ *
+ * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
+ * function in the platform abstraction layer.
+ *
+ * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
+ * provide a function "mbedtls_platform_set_printf()" that allows you to set an
+ * alternative printf function pointer.
+ *
+ * All these define require MBEDTLS_PLATFORM_C to be defined!
+ *
+ * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
+ * it will be enabled automatically by check_config.h
+ *
+ * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
+ * MBEDTLS_PLATFORM_XXX_MACRO!
+ *
+ * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
+ *
+ * Uncomment a macro to enable alternate implementation of specific base
+ * platform function
+ */
+//#define MBEDTLS_PLATFORM_EXIT_ALT
+#define MBEDTLS_PLATFORM_TIME_ALT
+//#define MBEDTLS_PLATFORM_FPRINTF_ALT
+//#define MBEDTLS_PLATFORM_PRINTF_ALT
+//#define MBEDTLS_PLATFORM_SNPRINTF_ALT
+//#define MBEDTLS_PLATFORM_NV_SEED_ALT
+//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
+
+/**
+ * \def MBEDTLS_ENTROPY_HARDWARE_ALT
+ *
+ * Uncomment this macro to let mbed TLS use your own implementation of a
+ * hardware entropy collector.
+ *
+ * Your function must be called \c mbedtls_hardware_poll(), have the same
+ * prototype as declared in entropy_poll.h, and accept NULL as first argument.
+ *
+ * Uncomment to use your own hardware entropy collector.
+ */
+#define MBEDTLS_ENTROPY_HARDWARE_ALT
+/**
+ * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
+ *
+ * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve
+ * module.  By default all supported curves are enabled.
+ *
+ * Comment macros to disable the curve and functions for it
+ */
+#undef MBEDTLS_ECP_DP_SECP192R1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP224R1_ENABLED
+//#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP384R1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP521R1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP192K1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP224K1_ENABLED
+#undef MBEDTLS_ECP_DP_SECP256K1_ENABLED
+#undef MBEDTLS_ECP_DP_BP256R1_ENABLED
+#undef MBEDTLS_ECP_DP_BP384R1_ENABLED
+#undef MBEDTLS_ECP_DP_BP512R1_ENABLED
+//#undef MBEDTLS_ECP_DP_CURVE25519_ENABLED
+#undef MBEDTLS_ECP_DP_CURVE448_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+ *
+ * Enable the PSK based ciphersuite modes in SSL / TLS.
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ *      MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
+ *      MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
+ *      MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
+ *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ *      MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
+ *      MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
+ *      MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
+ *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ *      MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
+ *      MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
+ */
+#undef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_PK_PARSE_EC_EXTENDED
+ *
+ * Enhance support for reading EC keys using variants of SEC1 not allowed by
+ * RFC 5915 and RFC 5480.
+ *
+ * Currently this means parsing the SpecifiedECDomain choice of EC
+ * parameters (only known groups are supported, not arbitrary domains, to
+ * avoid validation issues).
+ *
+ * Disable if you only need to support RFC 5915 + 5480 key formats.
+ */
+#undef MBEDTLS_PK_PARSE_EC_EXTENDED
+
+#undef MBEDTLS_FS_IO
+
+/**
+ * \def MBEDTLS_NO_PLATFORM_ENTROPY
+ *
+ * Do not use built-in platform entropy functions.
+ * This is useful if your platform does not support
+ * standards like the /dev/urandom or Windows CryptoAPI.
+ *
+ * Uncomment this macro to disable the built-in platform entropy functions.
+ */
+#define MBEDTLS_NO_PLATFORM_ENTROPY
+
+/**
+ * \def MBEDTLS_ENTROPY_FORCE_SHA256
+ *
+ * Force the entropy accumulator to use a SHA-256 accumulator instead of the
+ * default SHA-512 based one (if both are available).
+ *
+ * Requires: MBEDTLS_SHA256_C
+ *
+ * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option
+ * if you have performance concerns.
+ *
+ * This option is only useful if both MBEDTLS_SHA256_C and
+ * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used.
+ */
+#define MBEDTLS_ENTROPY_FORCE_SHA256
+
+/**
+ * \def MBEDTLS_SELF_TEST
+ *
+ * Enable the checkup functions (*_self_test).
+ */
+#undef MBEDTLS_SELF_TEST
+
+/**
+ * \def MBEDTLS_SSL_FALLBACK_SCSV
+ *
+ * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00).
+ *
+ * For servers, it is recommended to always enable this, unless you support
+ * only one version of TLS, or know for sure that none of your clients
+ * implements a fallback strategy.
+ *
+ * For clients, you only need this if you're using a fallback strategy, which
+ * is not recommended in the first place, unless you absolutely need it to
+ * interoperate with buggy (version-intolerant) servers.
+ *
+ * Comment this macro to disable support for FALLBACK_SCSV
+ */
+#undef MBEDTLS_SSL_FALLBACK_SCSV
+
+/**
+ * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
+ *
+ * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
+ *
+ * This is a countermeasure to the BEAST attack, which also minimizes the risk
+ * of interoperability issues compared to sending 0-length records.
+ *
+ * Comment this macro to disable 1/n-1 record splitting.
+ */
+#undef MBEDTLS_SSL_CBC_RECORD_SPLITTING
+
+/**
+ * \def MBEDTLS_SSL_RENEGOTIATION
+ *
+ * Enable support for TLS renegotiation.
+ *
+ * The two main uses of renegotiation are (1) refresh keys on long-lived
+ * connections and (2) client authentication after the initial handshake.
+ * If you don't need renegotiation, it's probably better to disable it, since
+ * it has been associated with security issues in the past and is easy to
+ * misuse/misunderstand.
+ *
+ * Comment this to disable support for renegotiation.
+ *
+ * \note   Even if this option is disabled, both client and server are aware
+ *         of the Renegotiation Indication Extension (RFC 5746) used to
+ *         prevent the SSL renegotiation attack (see RFC 5746 Sect. 1).
+ *         (See \c mbedtls_ssl_conf_legacy_renegotiation for the
+ *          configuration of this extension).
+ *
+ */
+#undef MBEDTLS_SSL_RENEGOTIATION
+
+/**
+ * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
+ *
+ * Enable support for receiving and parsing SSLv2 Client Hello messages for the
+ * SSL Server module (MBEDTLS_SSL_SRV_C).
+ *
+ * Uncomment this macro to enable support for SSLv2 Client Hello messages.
+ */
+//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
+
+/**
+ * \def MBEDTLS_SSL_PROTO_TLS1
+ *
+ * Enable support for TLS 1.0.
+ *
+ * Requires: MBEDTLS_MD5_C
+ *           MBEDTLS_SHA1_C
+ *
+ * Comment this macro to disable support for TLS 1.0
+ */
+#undef MBEDTLS_SSL_PROTO_TLS1
+
+/**
+ * \def MBEDTLS_SSL_PROTO_TLS1_1
+ *
+ * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled).
+ *
+ * Requires: MBEDTLS_MD5_C
+ *           MBEDTLS_SHA1_C
+ *
+ * Comment this macro to disable support for TLS 1.1 / DTLS 1.0
+ */
+#undef MBEDTLS_SSL_PROTO_TLS1_1
+
+/**
+ * \def MBEDTLS_SSL_PROTO_DTLS
+ *
+ * Enable support for DTLS (all available versions).
+ *
+ * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0,
+ * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2.
+ *
+ * Requires: MBEDTLS_SSL_PROTO_TLS1_1
+ *        or MBEDTLS_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for DTLS
+ */
+#undef MBEDTLS_SSL_PROTO_DTLS
+
+/**
+ * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
+ *
+ * Enable support for the anti-replay mechanism in DTLS.
+ *
+ * Requires: MBEDTLS_SSL_TLS_C
+ *           MBEDTLS_SSL_PROTO_DTLS
+ *
+ * \warning Disabling this is often a security risk!
+ * See mbedtls_ssl_conf_dtls_anti_replay() for details.
+ *
+ * Comment this to disable anti-replay in DTLS.
+ */
+#undef MBEDTLS_SSL_DTLS_ANTI_REPLAY
+
+/**
+ * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY
+ *
+ * Enable support for HelloVerifyRequest on DTLS servers.
+ *
+ * This feature is highly recommended to prevent DTLS servers being used as
+ * amplifiers in DoS attacks against other hosts. It should always be enabled
+ * unless you know for sure amplification cannot be a problem in the
+ * environment in which your server operates.
+ *
+ * \warning Disabling this can ba a security risk! (see above)
+ *
+ * Requires: MBEDTLS_SSL_PROTO_DTLS
+ *
+ * Comment this to disable support for HelloVerifyRequest.
+ */
+#undef MBEDTLS_SSL_DTLS_HELLO_VERIFY
+
+/**
+ * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
+ *
+ * Enable server-side support for clients that reconnect from the same port.
+ *
+ * Some clients unexpectedly close the connection and try to reconnect using the
+ * same source port. This needs special support from the server to handle the
+ * new connection securely, as described in section 4.2.8 of RFC 6347. This
+ * flag enables that support.
+ *
+ * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY
+ *
+ * Comment this to disable support for clients reusing the source port.
+ */
+#undef MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
+
+/**
+ * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT
+ *
+ * Enable support for a limit of records with bad MAC.
+ *
+ * See mbedtls_ssl_conf_dtls_badmac_limit().
+ *
+ * Requires: MBEDTLS_SSL_PROTO_DTLS
+ */
+#undef MBEDTLS_SSL_DTLS_BADMAC_LIMIT
+
+/**
+ * \def MBEDTLS_SSL_SESSION_TICKETS
+ *
+ * Enable support for RFC 5077 session tickets in SSL.
+ * Client-side, provides full support for session tickets (maintenance of a
+ * session store remains the responsibility of the application, though).
+ * Server-side, you also need to provide callbacks for writing and parsing
+ * tickets, including authenticated encryption and key management. Example
+ * callbacks are provided by MBEDTLS_SSL_TICKET_C.
+ *
+ * Comment this macro to disable support for SSL session tickets
+ */
+#undef MBEDTLS_SSL_SESSION_TICKETS
+
+/**
+ * \def MBEDTLS_SSL_EXPORT_KEYS
+ *
+ * Enable support for exporting key block and master secret.
+ * This is required for certain users of TLS, e.g. EAP-TLS.
+ *
+ * Comment this macro to disable support for key export
+ */
+#undef MBEDTLS_SSL_EXPORT_KEYS
+
+/**
+ * \def MBEDTLS_SSL_TRUNCATED_HMAC
+ *
+ * Enable support for RFC 6066 truncated HMAC in SSL.
+ *
+ * Comment this macro to disable support for truncated HMAC in SSL
+ */
+#undef MBEDTLS_SSL_TRUNCATED_HMAC
+
+/**
+ * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT
+ *
+ * Enable parsing and verification of X.509 certificates, CRLs and CSRS
+ * signed with RSASSA-PSS (aka PKCS#1 v2.1).
+ *
+ * Comment this macro to disallow using RSASSA-PSS in certificates.
+ */
+#undef MBEDTLS_X509_RSASSA_PSS_SUPPORT
+
+/**
+ * \def MBEDTLS_AESNI_C
+ *
+ * Enable AES-NI support on x86-64.
+ *
+ * Module:  library/aesni.c
+ * Caller:  library/aes.c
+ *
+ * Requires: MBEDTLS_HAVE_ASM
+ *
+ * This modules adds support for the AES-NI instructions on x86-64
+ */
+#undef MBEDTLS_AESNI_C
+
+/**
+ * \def MBEDTLS_NET_C
+ *
+ * Enable the TCP and UDP over IPv6/IPv4 networking routines.
+ *
+ * \note This module only works on POSIX/Unix (including Linux, BSD and OS X)
+ * and Windows. For other platforms, you'll want to disable it, and write your
+ * own networking callbacks to be passed to \c mbedtls_ssl_set_bio().
+ *
+ * \note See also our Knowledge Base article about porting to a new
+ * environment:
+ * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
+ *
+ * Module:  library/net_sockets.c
+ *
+ * This module provides networking routines.
+ */
+#undef MBEDTLS_NET_C
+
+/**
+ * \def MBEDTLS_SSL_COOKIE_C
+ *
+ * Enable basic implementation of DTLS cookies for hello verification.
+ *
+ * Module:  library/ssl_cookie.c
+ * Caller:
+ */
+#undef MBEDTLS_SSL_COOKIE_C
+
+/**
+ * \def MBEDTLS_TIMING_C
+ *
+ * Enable the semi-portable timing interface.
+ *
+ * \note The provided implementation only works on POSIX/Unix (including Linux,
+ * BSD and OS X) and Windows. On other platforms, you can either disable that
+ * module and provide your own implementations of the callbacks needed by
+ * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide
+ * your own implementation of the whole module by setting
+ * \c MBEDTLS_TIMING_ALT in the current file.
+ *
+ * \note See also our Knowledge Base article about porting to a new
+ * environment:
+ * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
+ *
+ * Module:  library/timing.c
+ * Caller:  library/havege.c
+ *
+ * This module is used by the HAVEGE random number generator.
+ */
+#undef MBEDTLS_TIMING_C
+
+/**
+ * \def MBEDTLS_X509_CRL_PARSE_C
+ *
+ * Enable X.509 CRL parsing.
+ *
+ * Module:  library/x509_crl.c
+ * Caller:  library/x509_crt.c
+ *
+ * Requires: MBEDTLS_X509_USE_C
+ *
+ * This module is required for X.509 CRL parsing.
+ */
+#undef MBEDTLS_X509_CRL_PARSE_C
+
+/**
+ * \def MBEDTLS_X509_CSR_PARSE_C
+ *
+ * Enable X.509 Certificate Signing Request (CSR) parsing.
+ *
+ * Module:  library/x509_csr.c
+ * Caller:  library/x509_crt_write.c
+ *
+ * Requires: MBEDTLS_X509_USE_C
+ *
+ * This module is used for reading X.509 certificate request.
+ */
+//#undef MBEDTLS_X509_CSR_PARSE_C
+
+/**
+ * \def MBEDTLS_X509_CREATE_C
+ *
+ * Enable X.509 core for creating certificates.
+ *
+ * Module:  library/x509_create.c
+ *
+ * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C
+ *
+ * This module is the basis for creating X.509 certificates and CSRs.
+ */
+//#undef MBEDTLS_X509_CREATE_C
+
+/**
+ * \def MBEDTLS_X509_CSR_WRITE_C
+ *
+ * Enable creating X.509 Certificate Signing Requests (CSR).
+ *
+ * Module:  library/x509_csr_write.c
+ *
+ * Requires: MBEDTLS_X509_CREATE_C
+ *
+ * This module is required for X.509 certificate request writing.
+ */
+//#undef MBEDTLS_X509_CSR_WRITE_C
+
+/**
+ * \def MBEDTLS_X509_CRT_WRITE_C
+ *
+ * Enable creating X.509 certificates.
+ *
+ * Module:  library/x509_crt_write.c
+ *
+ * Requires: MBEDTLS_X509_CREATE_C
+ *
+ * This module is required for X.509 certificate creation.
+ */
+#undef MBEDTLS_X509_CRT_WRITE_C
+
+/**
+ * \def MBEDTLS_CERTS_C
+ *
+ * Enable the test certificates.
+ *
+ * Module:  library/certs.c
+ * Caller:
+ *
+ * This module is used for testing (ssl_client/server).
+ */
+#undef MBEDTLS_CERTS_C
+
+/**
+ * \def MBEDTLS_ERROR_C
+ *
+ * Enable error code to error string conversion.
+ *
+ * Module:  library/error.c
+ * Caller:
+ *
+ * This module enables mbedtls_strerror().
+ */
+#undef MBEDTLS_ERROR_C
+
+/**
+ * \def MBEDTLS_PADLOCK_C
+ *
+ * Enable VIA Padlock support on x86.
+ *
+ * Module:  library/padlock.c
+ * Caller:  library/aes.c
+ *
+ * Requires: MBEDTLS_HAVE_ASM
+ *
+ * This modules adds support for the VIA PadLock on x86.
+ */
+#undef MBEDTLS_PADLOCK_C
+
+/**
+ * \def MBEDTLS_RIPEMD160_C
+ *
+ * Enable the RIPEMD-160 hash algorithm.
+ *
+ * Module:  library/ripemd160.c
+ * Caller:  library/md.c
+ *
+ */
+#undef MBEDTLS_RIPEMD160_C
+
+/**
+ * \def MBEDTLS_PK_RSA_ALT_SUPPORT
+ *
+ * Support external private RSA keys (eg from a HSM) in the PK layer.
+ *
+ * Comment this macro to disable support for external private RSA keys.
+ */
+#undef MBEDTLS_PK_RSA_ALT_SUPPORT
+
+/**
+ * \def MBEDTLS_ARC4_C
+ *
+ * Enable the ARCFOUR stream cipher.
+ *
+ * Module:  library/arc4.c
+ * Caller:  library/cipher.c
+ *
+ * This module enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ *      MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
+ *      MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
+ *      MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
+ *
+ * \warning   ARC4 is considered a weak cipher and its use constitutes a
+ *            security risk. If possible, we recommend avoidng dependencies on
+ *            it, and considering stronger ciphers instead.
+ *
+ */
+#undef MBEDTLS_ARC4_C
+
+/**
+ * \def MBEDTLS_XTEA_C
+ *
+ * Enable the XTEA block cipher.
+ *
+ * Module:  library/xtea.c
+ * Caller:
+ */
+#undef MBEDTLS_XTEA_C
+
+/**
+ * \def MBEDTLS_BLOWFISH_C
+ *
+ * Enable the Blowfish block cipher.
+ *
+ * Module:  library/blowfish.c
+ */
+#undef MBEDTLS_BLOWFISH_C
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
+ *
+ * Enable the DHE-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_DHM_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
+ *      MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ *      MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
+ *      MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
+ *      MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ *      MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ *      MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
+ *      MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
+ *
+ * \warning    Using DHE constitutes a security risk as it
+ *             is not possible to validate custom DH parameters.
+ *             If possible, it is recommended users should consider
+ *             preferring other methods of key exchange.
+ *             See dhm.h for more details.
+ *
+ */
+#undef MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
+ *
+ * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_ECDH_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
+ *      MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
+ */
+#undef MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
+
+/**
+ * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
+ *
+ * Enable the RSA-PSK based ciphersuite modes in SSL / TLS.
+ *
+ * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
+ *           MBEDTLS_X509_CRT_PARSE_C
+ *
+ * This enables the following ciphersuites (if other requisites are
+ * enabled as well):
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
+ *      MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
+ *      MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
+ *      MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
+ *      MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
+ *      MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
+ *      MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
+ *      MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
+ */
+#undef MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
+
+/**
+ * Allow SHA-1 in the default TLS configuration for certificate signing if
+ * enabled in the application Makefile.
+ *
+ * Without this build-time option, SHA-1 support must be activated explicitly
+ * through mbedtls_ssl_conf_cert_profile. Turning on this option is not
+ * recommended because of it is possible to generate SHA-1 collisions, however
+ * this may be safe for legacy infrastructure where additional controls apply.
+ *
+ * \warning   SHA-1 is considered a weak message digest and its use constitutes
+ *            a security risk. If possible, we recommend avoiding dependencies
+ *            on it, and considering stronger message digests instead.
+ *
+ */
+#ifdef CY_MQTT_ENABLE_SECURE_TEST_MOSQUITTO_SUPPORT
+#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
+#endif
+
+#endif /* MBEDTLS_USER_CONFIG_HEADER */

+ 161 - 0
third_party/p6/p6_sdk/configs/mqtt_client_config.h

@@ -0,0 +1,161 @@
+/******************************************************************************
+ * File Name: mqtt_client_config.h
+ *
+ * Description: This file contains all the configuration macros used by the
+ *              MQTT client in this example.
+ *
+ * Related Document: See README.md
+ *
+ *******************************************************************************
+ * (c) 2020-2021, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+#ifndef MQTT_CLIENT_CONFIG_H_
+#define MQTT_CLIENT_CONFIG_H_
+
+#include "iot_mqtt.h"
+
+/*******************************************************************************
+ * Macros
+ ********************************************************************************/
+/* MQTT Broker/Server address and port used for the MQTT connection. */
+#define MQTT_BROKER_ADDRESS "MY_AWS_IOT_ENDPOINT_ADDRESS"
+#define MQTT_PORT 8883
+
+/* Set this macro to 1 if the MQTT Broker being used is hosted by AWS IoT
+ * Core service, else 0.
+ */
+#define AWS_IOT_MQTT_MODE (1)
+
+/* Set this macro to 1 if a secure (TLS) connection to the MQTT Broker is
+ * required to be established, else 0.
+ */
+#define MQTT_SECURE_CONNECTION (1)
+
+/* The MQTT topic on which the LED control messages will be published and
+ * subscribed.
+ */
+#define MQTT_TOPIC "ledstatus"
+
+/* Configuration for the 'Last Will and Testament (LWT)'. It is an MQTT message
+ * that will be published by the MQTT broker if the MQTT connection is
+ * unexpectedly closed. This configuration is sent to the MQTT broker during
+ * MQTT connect operation and the MQTT broker will publish the Will message on
+ * the Will topic when it recognizes an unexpected disconnection from the client.
+ *
+ * If you want to use the last will message, set this macro to 1, else 0.
+ */
+#define ENABLE_LWT_MESSAGE (0)
+#if ENABLE_LWT_MESSAGE
+#define MQTT_WILL_TOPIC_NAME MQTT_TOPIC "/will"
+#define MQTT_WILL_MESSAGE ("MQTT client unexpectedly disconnected!")
+#endif
+
+/* Set the QoS that is associated with the MQTT publish, and subscribe messages.
+ * Valid choices are 0, and 1. The MQTT library currently does not support
+ * QoS 2, and hence should not be used in this macro.
+ */
+#define MQTT_MESSAGES_QOS (1)
+
+/* Configure the user credentials to be sent as part of MQTT CONNECT packet */
+#define MQTT_USERNAME "User"
+#define MQTT_PASSWORD ""
+
+/* The timeout in milliseconds for MQTT operations in this example. */
+#define MQTT_TIMEOUT_MS (5000)
+
+/* The keep-alive interval in seconds used for MQTT ping request. */
+#define MQTT_KEEP_ALIVE_SECONDS (60)
+
+/* A unique client identifier to be used for every MQTT connection. */
+#define MQTT_CLIENT_IDENTIFIER "psoc6-mqtt-client"
+
+/* Every active MQTT connection must have a unique client identifier. If you
+ * are using the above 'MQTT_CLIENT_IDENTIFIER' as client ID for multiple MQTT
+ * connections simultaneously, set this macro to 1. The device will then
+ * generate a unique client identifier by appending a timestamp to the
+ * 'MQTT_CLIENT_IDENTIFIER' string. Example: 'psoc6-mqtt-client5927'
+ */
+#define GENERATE_UNIQUE_CLIENT_ID (1)
+
+/* The longest client identifier that an MQTT server must accept (as defined
+ * by the MQTT 3.1.1 spec) is 23 characters. Add 1 to include the length of the
+ * NULL terminator.
+ */
+#define MQTT_CLIENT_IDENTIFIER_MAX_LEN (24)
+
+/* MQTT messages which are published and subscribed on the MQTT_TOPIC that
+ * controls the device (user LED in this example) state.
+ */
+#define MQTT_DEVICE_ON_MESSAGE "TURN ON"
+#define MQTT_DEVICE_OFF_MESSAGE "TURN OFF"
+
+/* As per Internet Assigned Numbers Authority (IANA) the port numbers assigned
+ * for MQTT protocol are 1883 for non-secure connections and 8883 for secure
+ * connections. In some cases there is a need to use other ports for MQTT like
+ * port 443 (which is reserved for HTTPS). Application Layer Protocol
+ * Negotiation (ALPN) is an extension to TLS that allows many protocols to be
+ * used over a secure connection. The ALPN ProtocolNameList specifies the
+ * protocols that the client would like to use to communicate over TLS.
+ *
+ * This macro specifies the ALPN Protocol Name to be used that is supported
+ * by the MQTT broker in use.
+ * Note: For AWS IoT, currently "x-amzn-mqtt-ca" is the only supported ALPN
+ *       ProtocolName and it is only supported on port 443.
+ */
+#define MQTT_ALPN_PROTOCOL_NAME "x-amzn-mqtt-ca"
+
+/* Configure the below credentials in case of a secure MQTT connection. */
+/* PEM-encoded client certificate */
+#define CLIENT_CERTIFICATE                                                                                                         \
+    "-----BEGIN CERTIFICATE-----\n"                                                                                                \
+    "........base64 data........\n"                                                                                                \
+    "-----END CERTIFICATE-----"
+
+/* PEM-encoded client private key */
+#define CLIENT_PRIVATE_KEY                                                                                                         \
+    "-----BEGIN RSA PRIVATE KEY-----\n"                                                                                            \
+    "..........base64 data..........\n"                                                                                            \
+    "-----END RSA PRIVATE KEY-----"
+
+/* PEM-encoded Root CA certificate */
+#define ROOT_CA_CERTIFICATE                                                                                                        \
+    "-----BEGIN CERTIFICATE-----\n"                                                                                                \
+    "........base64 data........\n"                                                                                                \
+    "-----END CERTIFICATE-----"
+
+/******************************************************************************
+ * Global Variables
+ *******************************************************************************/
+extern IotMqttNetworkInfo_t networkInfo;
+extern IotMqttConnectInfo_t connectionInfo;
+
+#endif /* MQTT_CLIENT_CONFIG_H_ */

+ 66 - 0
third_party/p6/p6_sdk/configs/wifi_config.h

@@ -0,0 +1,66 @@
+/******************************************************************************
+ * File Name: wifi_config.h
+ *
+ * Description: This file contains the configuration macros required for the
+ *              Wi-Fi connection.
+ *
+ * Related Document: See README.md
+ *
+ *******************************************************************************
+ * (c) 2020-2021, Cypress Semiconductor Corporation. All rights reserved.
+ *******************************************************************************
+ * This software, including source code, documentation and related materials
+ * ("Software"), is owned by Cypress Semiconductor Corporation or one of its
+ * subsidiaries ("Cypress") and is protected by and subject to worldwide patent
+ * protection (United States and foreign), United States copyright laws and
+ * international treaty provisions. Therefore, you may use this Software only
+ * as provided in the license agreement accompanying the software package from
+ * which you obtained this Software ("EULA").
+ *
+ * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
+ * non-transferable license to copy, modify, and compile the Software source
+ * code solely for use in connection with Cypress's integrated circuit products.
+ * Any reproduction, modification, translation, compilation, or representation
+ * of this Software except as specified above is prohibited without the express
+ * written permission of Cypress.
+ *
+ * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+ * reserves the right to make changes to the Software without notice. Cypress
+ * does not assume any liability arising out of the application or use of the
+ * Software or any product or circuit described in the Software. Cypress does
+ * not authorize its products for use in any products where a malfunction or
+ * failure of the Cypress product may reasonably be expected to result in
+ * significant property damage, injury or death ("High Risk Product"). By
+ * including Cypress's product in a High Risk Product, the manufacturer of such
+ * system or application assumes all risk of such use and in doing so agrees to
+ * indemnify Cypress against all liability.
+ *******************************************************************************/
+
+#ifndef WIFI_CONFIG_H_
+#define WIFI_CONFIG_H_
+
+#include "cy_wcm.h"
+
+/*******************************************************************************
+ * Macros
+ ********************************************************************************/
+/* SSID of the Wi-Fi Access Point to which the MQTT client connects. */
+#define WIFI_SSID "MY_WIFI_SSID"
+
+/* Passkey of the above mentioned Wi-Fi SSID. */
+#define WIFI_PASSWORD "MY_WIFI_PASSWORD"
+
+/* Security type of the Wi-Fi access point. See 'cy_wcm_security_t' structure
+ * in "cy_wcm.h" for more details.
+ */
+#define WIFI_SECURITY CY_WCM_SECURITY_WPA2_AES_PSK
+
+/* Maximum Wi-Fi re-connection limit. */
+#define MAX_WIFI_CONN_RETRIES (10u)
+
+/* Wi-Fi re-connection time interval in milliseconds. */
+#define WIFI_CONN_RETRY_INTERVAL_MS (2000)
+
+#endif /* WIFI_CONFIG_H_ */

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است