Skip to content

Commit 9323ad6

Browse files
[NXP] Add BLE pairing and bonding after commissioning (project-chip#40704)
* [nxp][platform][common][ble] Temporary fix for multiple ble connections. * this bug was introduced in the initial multiple ble connections PR, blekw_stop_advertising should be called only when there was no successful connection. When a connection is made, advertising is stoped by the lib. If called in this case, it will cause an error which doesn't any effect, it just shows in the logs. * this will work only for the first connection, if multiple connections are made, the function will be called on successful connection showing the error. A rework of this feature is needed. Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][platform][common][ble] Add ble pairing and bonding changes * allow device to use random ble address when matter commissioning and public ble address in extra ble connections, this is needed for pairing and bonding. This is a workaround. Setting of ble advertising data at runtime is needed in the future. * don't send Gap_RejectPairing when pairing enabled, the pairing request will be acceped from the ble host code. * add DisconnectAndUnbond to allow disconnecting and removing ble bonding data when factory resetting. Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][examples][platform][common] Add FactoryReset in BLEApplicationManager * feature can be used by each application to implement its factory reset mechanism in BLEApplicationManager (e.g. erasing ble bonding data) * add dummy FactoryReset implementation in BLEApplicationManagerEmpty * add dummy FactoryReset implementation in BleZephyrManagerApp * call FactoryReset BLEApplicationManager in AppTaskBase::FactoryResetHandler * call FactoryResetHandler in ButtonBle to align with matter cli Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][examples][platform][mcxw] BLEApplicationManager changes * add FactoryReset function to disconnect and erase bounding data for all ble connections * move BLEApplicationManager.cpp to NXPHostBLEApplicationManager.cpp in common/app_ble/source directory Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][gn][examples][lock-app][mcxw71] BLE changes * use ble bonding nvm functions (App_NvmRead, App_NvmWrite, App_NvmErase) implementation * align extra gatt macros with cmake kconfigs * use common NXPHostBLEApplicationManager.cpp (originating from mcxw71 BLEApplicationManager.cpp) Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][cmake][config] Add multiple ble connections kconfig * add kconfigs for ble pairing and bonding Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][cmake][examples][platform][common] Rework CHIP_APP_BLE_MANAGER_SELECTION & add kconfigs * change CHIP_APP_BLE_MANAGER_CUSTOM to CHIP_APP_BLE_MANAGER_CUSTOM_BLE_ZEPHYR * add CHIP_APP_BLE_MANAGER_CUSTOM_NXP_BLE_HOST which currently depends on CHIP_NXP_MULTIPLE_BLE_CONNECTIONS and not on CHIP_CUSTOM_BLE_ADV_DATA as it doesn't yet have custom ble adv data * use common app_ble/source/NXPHostBLEApplicationManager.cpp when CHIP_APP_BLE_MANAGER_CUSTOM_NXP_BLE_HOST * add kconfigs for extra gatt db header and gatt uuid header Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][common] Update nxp_matter_support repo Signed-off-by: Andrei Menzopol <[email protected]> * Restyled by whitespace * Restyled by clang-format * Restyled by gn * [nxp][cmake][examples][platform][common] Fix typo Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][examples][all-clusters-app][zephyr] Add BLE application manager Signed-off-by: Andrei Menzopol <[email protected]> * [nxp][examples][laundry-washer-app][zephyr] Add BLE application manager Signed-off-by: Andrei Menzopol <[email protected]> --------- Signed-off-by: Andrei Menzopol <[email protected]> Co-authored-by: Restyled.io <[email protected]>
1 parent 2ed6d78 commit 9323ad6

File tree

16 files changed

+146
-15
lines changed

16 files changed

+146
-15
lines changed

config/nxp/chip-cmake-freertos/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ matter_add_gn_arg_bool("nxp_use_factory_data" ${CONFIG_CHIP_FACTORY_DATA})
5252
matter_add_gn_arg_bool("nxp_enable_secure_whole_factory_data" ${CONFIG_CHIP_ENABLE_SECURE_WHOLE_FACTORY_DATA})
5353
matter_add_gn_arg_bool("nxp_enable_secure_EL2GO_factory_data" ${CONFIG_CHIP_ENABLE_EL2GO_FACTORY_DATA})
5454
matter_add_gn_arg_bool("nxp_enable_matter_cli" CONFIG_CHIP_LIB_SHELL)
55+
matter_add_gn_arg_bool("nxp_multiple_ble_connections" CONFIG_CHIP_NXP_MULTIPLE_BLE_CONNECTIONS)
5556
matter_add_gn_arg_bool("nxp_enable_pairing_autostart" CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART)
5657
matter_add_gn_arg_bool("nxp_use_low_power" CONFIG_NXP_USE_LOW_POWER)
5758
matter_add_gn_arg_bool("nxp_use_plain_dac_key" CONFIG_NXP_USE_PLAIN_DAC_KEY)

config/nxp/cmake/Kconfig.matter.nxp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,24 @@ choice CHIP_OTA_REQUEST_UPGRADE_TYPE
272272

273273
endchoice
274274

275+
config CHIP_NXP_MULTIPLE_BLE_CONNECTIONS
276+
bool "Use Multiple BLE connections after commissioning"
277+
depends on CHIP_NXP_PLATFORM_MCXW71 || CHIP_NXP_PLATFORM_MCXW72
278+
help
279+
Enable app usage of Multiple BLE connections after commissioning.
280+
281+
config CHIP_NXP_BLE_PAIRING
282+
bool "Enable BLE Pairing"
283+
default y if CHIP_NXP_MULTIPLE_BLE_CONNECTIONS
284+
help
285+
Enable BLE Pairing for Multiple BLE connections after commissioning.
286+
287+
config CHIP_NXP_BLE_BONDING
288+
bool "Enable BLE Bonding"
289+
default y if CHIP_NXP_MULTIPLE_BLE_CONNECTIONS
290+
help
291+
Enable BLE Bonding for Multiple BLE connections after commissioning.
292+
275293
config NXP_USE_SMU2_STATIC
276294
bool "Use SMU2"
277295
depends on CHIP_NXP_PLATFORM_MCXW71 || CHIP_NXP_PLATFORM_MCXW72

examples/all-clusters-app/nxp/zephyr/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ target_include_directories(app
5151
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/include
5252
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/factory_data/include
5353
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/include
54+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/include
5455
)
5556

5657
target_sources(app
@@ -67,6 +68,16 @@ target_sources(app
6768
${EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR}/factory_data/source/AppFactoryDataExample.cpp
6869
)
6970

71+
if(CONFIG_CHIP_CUSTOM_BLE_ADV_DATA)
72+
target_sources(app PRIVATE
73+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/source/BleZephyrManagerApp.cpp
74+
)
75+
else()
76+
target_sources(app PRIVATE
77+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/source/BLEApplicationManagerEmpty.cpp
78+
)
79+
endif()
80+
7081
if(CONFIG_CHIP_OTA_REQUESTOR)
7182
target_sources(app PRIVATE
7283
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorCommon.cpp

examples/laundry-washer-app/nxp/zephyr/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ target_include_directories(app
5353
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/include
5454
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/factory_data/include
5555
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/include
56+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/include
5657
)
5758

5859
target_sources(app
@@ -69,6 +70,16 @@ target_sources(app
6970
${EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR}/factory_data/source/AppFactoryDataExample.cpp
7071
)
7172

73+
if(CONFIG_CHIP_CUSTOM_BLE_ADV_DATA)
74+
target_sources(app PRIVATE
75+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/source/BleZephyrManagerApp.cpp
76+
)
77+
else()
78+
target_sources(app PRIVATE
79+
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_ble/source/BLEApplicationManagerEmpty.cpp
80+
)
81+
endif()
82+
7283
if(CONFIG_CHIP_OTA_REQUESTOR)
7384
target_sources(app PRIVATE
7485
${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorCommon.cpp

examples/lock-app/nxp/mcxw71/BUILD.gn

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ mcxw71_sdk("sdk") {
9393
if (nxp_multiple_ble_connections) {
9494
include_dirs += [ "${example_platform_dir}/app_ble/include" ]
9595
defines += [
96-
"EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
97-
"EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
96+
"CONFIG_CHIP_APP_EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
97+
"CONFIG_CHIP_APP_EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
9898
]
99+
sources += [ "${support_common_platform_dir}/ble/ble_nvm_bonding.c" ]
99100
}
100101
}
101102

@@ -199,8 +200,9 @@ mcxw71_executable("lock_app") {
199200
}
200201

201202
if (nxp_multiple_ble_connections) {
202-
sources +=
203-
[ "${example_platform_dir}/app_ble/source/BLEApplicationManager.cpp" ]
203+
sources += [
204+
"${common_example_dir}/app_ble/source/NXPHostBLEApplicationManager.cpp",
205+
]
204206
} else {
205207
sources += [
206208
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",

examples/platform/nxp/common/Kconfig

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,40 @@ config CHIP_APP_BLE_MANAGER
4848
if CHIP_APP_BLE_MANAGER
4949
choice CHIP_APP_BLE_MANAGER_SELECTION
5050
prompt "Select Application BLE Manager"
51-
52-
config CHIP_APP_BLE_MANAGER_CUSTOM
53-
bool "App Custom BLE Manager"
51+
52+
config CHIP_APP_BLE_MANAGER_CUSTOM_BLE_ZEPHYR
53+
bool "App Custom BLE Manager Zephyr"
5454
depends on CHIP_CUSTOM_BLE_ADV_DATA && CHIP_DEVICE_USE_ZEPHYR_BLE
5555
help
56-
Enable application custom BLE manager.
56+
Enable application custom Zephyr BLE manager.
5757

58+
config CHIP_APP_BLE_MANAGER_CUSTOM_NXP_BLE_HOST
59+
bool "App Custom BLE Manager MCXW7x"
60+
depends on CHIP_NXP_MULTIPLE_BLE_CONNECTIONS && !CHIP_DEVICE_USE_ZEPHYR_BLE
61+
help
62+
Enable application custom MCXW7x BLE manager.
63+
5864
config CHIP_APP_BLE_MANAGER_EMPTY
5965
bool "App BLE Manager Empty"
6066
help
6167
Enable application BLE manager empty implementation.
6268

6369
endchoice # CHIP_APP_BLE_MANAGER
70+
71+
config CHIP_APP_EXTRA_GATT_DB_HEADER
72+
string "Extra application Gatt db header"
73+
default "<$(CHIP_ROOT)/examples/platform/nxp/mcxw71/app_ble/include/extra_gatt_db.h>" if CHIP_NXP_PLATFORM_MCXW71 || CHIP_NXP_PLATFORM_MCXW72
74+
depends on CHIP_NXP_MULTIPLE_BLE_CONNECTIONS
75+
help
76+
Set path to extra application Gatt db header.
77+
78+
config CHIP_APP_EXTRA_GATT_UUID_HEADER
79+
string "Extra application Gatt UUID header"
80+
default "<$(CHIP_ROOT)/examples/platform/nxp/mcxw71/app_ble/include/extra_gatt_uuid128.h>" if CHIP_NXP_PLATFORM_MCXW71 || CHIP_NXP_PLATFORM_MCXW72
81+
depends on CHIP_NXP_MULTIPLE_BLE_CONNECTIONS
82+
help
83+
Set path to extra application Gatt UUID header.
84+
6485
endif # CHIP_APP_BLE_MANAGER
6586

6687
config DIAG_LOGS_DEMO

examples/platform/nxp/common/app_ble/include/BLEApplicationManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BLEApplicationManager
3333
public:
3434
void Init();
3535
void EnableMultipleConnectionsHandler();
36+
void FactoryReset();
3637

3738
private:
3839
static void EnableMultipleConnections(intptr_t arg);

examples/platform/nxp/common/app_ble/source/BLEApplicationManagerEmpty.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ void BLEApplicationManager::EnableMultipleConnections(intptr_t arg)
3737
{
3838
/*Empty implementation. Intentionally left blank */
3939
}
40+
41+
void BLEApplicationManager::FactoryReset(void)
42+
{
43+
/*Empty implementation. Intentionally left blank */
44+
}

examples/platform/nxp/common/app_ble/source/BleZephyrManagerApp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ void BLEApplicationManager::Init(void)
9898
chip::DeviceLayer::Internal::BLEMgrImpl().SetCustomAdvertising(Span<bt_data>(advertisingData));
9999
chip::DeviceLayer::Internal::BLEMgrImpl().SetCustomScanResponse(Span<bt_data>(scanResponseData));
100100
}
101+
102+
void BLEApplicationManager::FactoryReset(void)
103+
{
104+
/*Empty implementation. Intentionally left blank */
105+
}

examples/platform/nxp/mcxw71/app_ble/source/BLEApplicationManager.cpp renamed to examples/platform/nxp/common/app_ble/source/NXPHostBLEApplicationManager.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*
33
* Copyright (c) 2024 Project CHIP Authors
4-
* Copyright 2024 NXP
4+
* Copyright 2024-2025 NXP
55
* All rights reserved.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +27,9 @@
2727
#include "gatt_db_app_interface.h"
2828
#include "gatt_db_handles.h"
2929

30+
extern "C" void btSettingsInit(void);
31+
extern "C" void btSettingsWipe(void);
32+
3033
using namespace ::chip::DeviceLayer;
3134
using namespace ::chip::DeviceLayer::Internal;
3235
using namespace ::chip::NXP::App;
@@ -63,6 +66,10 @@ void BLEApplicationManager::Init(void)
6366
{
6467
ChipLogError(DeviceLayer, "Error while adding BLE write notification handle");
6568
}
69+
70+
#if gAppUseBonding_d
71+
btSettingsInit();
72+
#endif
6673
}
6774

6875
void BLEApplicationManager::EnableMultipleConnectionsHandler(void)
@@ -92,3 +99,18 @@ void BLEApplicationManager::EnableMultipleConnections(intptr_t arg)
9299
ChipLogProgress(DeviceLayer, "Device must be commissioned before adding multiple BLE connections");
93100
}
94101
}
102+
103+
void BLEApplicationManager::FactoryReset(void)
104+
{
105+
CHIP_ERROR err = CHIP_NO_ERROR;
106+
107+
err = DeviceLayer::Internal::BLEMgrImpl().DisconnectAndUnbond();
108+
if (err != CHIP_NO_ERROR)
109+
{
110+
ChipLogError(DeviceLayer, "Error during BLEMgrImpl().DisconnectAndUnbond()");
111+
}
112+
113+
#if gAppUseBonding_d
114+
btSettingsWipe();
115+
#endif
116+
}

0 commit comments

Comments
 (0)