Skip to content

Commit aec7b2f

Browse files
[nxp fromtree] [NXP] Add multiple ble connections support (project-chip#35645)
* [nxp][examples][platform][common] Add BLEApplicationManager interface and empty implementation Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][platform][common][ble] Add BLEManagerCommon multiple connections changes * Make gatt attribute read/write handles generic * Update mServiceMode to support multiple ble connections * Create mDeviceIds set * Update flow to handle multiple ble connections Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][mcxw71_k32w1] Multiple ble connections changes * Add button handle to enable multiple ble connections (start advertisement) * Add app_ble/BLEApplicationManager.* to handle check & start advertisement Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][common][lock-app] Add call to BLEApplicationManager Init Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][mcxw71] Multiple ble connections changes * lock-app: * Add extra gatt headers to include demo gatt service * Add build changes * Update readme * other apps: * Add BLEApplicationManagerEmpty Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][k32w1] Multiple ble connections changes * lock-app: * Add extra gatt headers to include demo gatt service * Add build changes * Update readme * other apps: * Add BLEApplicationManagerEmpty Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * Restyled by clang-format * Restyled by gn * [nxp][examples][mcxw71][lock-app] Multiple ble connections changes * Add extra gatt headers to include demo gatt service * Add build changes * Update readme Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * [nxp][examples][k32w1][lock-app] Multiple ble connections changes * Add extra gatt headers to include demo gatt service * Add build changes * Update readme Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> * Restyled by gn * Restyled by prettier-markdown --------- Signed-off-by: Andrei Menzopol <andrei.menzopol@nxp.com> Co-authored-by: Andrei Menzopol <andrei.menzopol@nxp.com> Co-authored-by: Restyled.io <commits@restyled.io> (cherry picked from commit 317f1a9)
1 parent c8c31ea commit aec7b2f

File tree

17 files changed

+373
-31
lines changed

17 files changed

+373
-31
lines changed

examples/contact-sensor-app/nxp/k32w1/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ mcxw71_k32w1_executable("contact_sensor_app") {
139139
"${common_example_dir}/low_power/include",
140140
"${common_example_dir}/operational_keystore/include",
141141
"${common_example_dir}/ui_feedback/include",
142+
"${common_example_dir}/app_ble/include",
142143
]
143144

144145
sources += [
146+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
145147
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
146148
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
147149
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",

examples/contact-sensor-app/nxp/mcxw71/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ mcxw71_k32w1_executable("contact_sensor_app") {
138138
"${common_example_dir}/low_power/include",
139139
"${common_example_dir}/operational_keystore/include",
140140
"${common_example_dir}/ui_feedback/include",
141+
"${common_example_dir}/app_ble/include",
141142
]
142143

143144
sources += [
145+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
144146
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
145147
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
146148
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",

examples/lighting-app/nxp/k32w1/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ mcxw71_k32w1_executable("light_app") {
146146
"${common_example_dir}/operational_keystore/include",
147147
"${common_example_dir}/rpc/include",
148148
"${common_example_dir}/ui_feedback/include",
149+
"${common_example_dir}/app_ble/include",
149150
]
150151

151152
sources += [
153+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
152154
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
153155
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
154156
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",

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

+2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ mcxw71_k32w1_executable("light_app") {
146146
"${common_example_dir}/operational_keystore/include",
147147
"${common_example_dir}/rpc/include",
148148
"${common_example_dir}/ui_feedback/include",
149+
"${common_example_dir}/app_ble/include",
149150
]
150151

151152
sources += [
153+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
152154
"${common_example_dir}/app_task/source/AppTaskBase.cpp",
153155
"${common_example_dir}/app_task/source/AppTaskFreeRTOS.cpp",
154156
"${common_example_dir}/clusters/source/ZclCallbacks.cpp",

examples/lock-app/nxp/common/main/AppTask.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include "AppTask.h"
22+
#include "BLEApplicationManager.h"
2223
#include "CHIPDeviceManager.h"
2324
#include "LockManager.h"
2425
#include <app-common/zap-generated/attributes/Accessors.h>
@@ -115,6 +116,9 @@ static CHIP_ERROR cliDoorLock(int argc, char * argv[])
115116
void LockApp::AppTask::PreInitMatterStack()
116117
{
117118
ChipLogProgress(DeviceLayer, "Welcome to NXP Lock Demo App");
119+
120+
/* BLEApplicationManager implemented per platform or left blank */
121+
chip::NXP::App::BleAppMgr().Init();
118122
}
119123

120124
void LockApp::AppTask::PostInitMatterStack()

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

+18
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ mcxw71_k32w1_sdk("sdk") {
9292
"${example_platform_dir}/board/peripherals.h",
9393
]
9494
}
95+
96+
if (nxp_multiple_ble_connections) {
97+
include_dirs += [ "${example_platform_dir}/app_ble/include" ]
98+
defines += [
99+
"EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
100+
"EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
101+
]
102+
}
95103
}
96104

97105
mcxw71_k32w1_executable("lock_app") {
@@ -140,6 +148,7 @@ mcxw71_k32w1_executable("lock_app") {
140148
"${common_example_dir}/low_power/include",
141149
"${common_example_dir}/operational_keystore/include",
142150
"${common_example_dir}/ui_feedback/include",
151+
"${common_example_dir}/app_ble/include",
143152
]
144153

145154
sources += [
@@ -189,6 +198,15 @@ mcxw71_k32w1_executable("lock_app") {
189198
deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ]
190199
}
191200

201+
if (nxp_multiple_ble_connections) {
202+
sources +=
203+
[ "${example_platform_dir}/app_ble/source/BLEApplicationManager.cpp" ]
204+
} else {
205+
sources += [
206+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
207+
]
208+
}
209+
192210
if (chip_with_diag_logs_demo) {
193211
sources += [
194212
"${common_example_dir}/diagnostic_logs/source/DiagnosticLogsDemo.cpp",

examples/lock-app/nxp/k32w1/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For generic information related to door lock application, please see the
1212
- [Flashing the host image](#flashing-the-host-image)
1313
- [Debugging](#debugging)
1414
- [OTA](#ota)
15+
- [Multiple BLE connections](#multiple-ble-connections)
1516

1617
## Introduction
1718

@@ -163,3 +164,15 @@ Run -> Debug Configurations... -> C/C++ Application
163164
164165
Please see
165166
[k32w1 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md).
167+
168+
## Multiple BLE connections
169+
170+
To compile with the Multiple BLE connections support demo example add the gn
171+
argument `nxp_multiple_ble_connections=true`.
172+
173+
The application will accept multiple BLE connections after commissioning, by
174+
pressing the BLE advertise button again. Once discovered by a BLE central, a
175+
custom GATT service will be visible on the device.
176+
177+
The user can change the default behavior by implementing the class defined in
178+
[BLEApplicationManager.h](../../../platform/nxp/common/app_ble/include/BLEApplicationManager.h)

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

+18
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ mcxw71_k32w1_sdk("sdk") {
9292
"${example_platform_dir}/board/peripherals.h",
9393
]
9494
}
95+
96+
if (nxp_multiple_ble_connections) {
97+
include_dirs += [ "${example_platform_dir}/app_ble/include" ]
98+
defines += [
99+
"EXTRA_GATT_DB_HEADER=\"extra_gatt_db.h\"",
100+
"EXTRA_GATT_UUID_HEADER=\"extra_gatt_uuid128.h\"",
101+
]
102+
}
95103
}
96104

97105
mcxw71_k32w1_executable("lock_app") {
@@ -140,6 +148,7 @@ mcxw71_k32w1_executable("lock_app") {
140148
"${common_example_dir}/low_power/include",
141149
"${common_example_dir}/operational_keystore/include",
142150
"${common_example_dir}/ui_feedback/include",
151+
"${common_example_dir}/app_ble/include",
143152
]
144153

145154
sources += [
@@ -189,6 +198,15 @@ mcxw71_k32w1_executable("lock_app") {
189198
deps += [ "${chip_root}/src/platform/nxp:nxp_ota" ]
190199
}
191200

201+
if (nxp_multiple_ble_connections) {
202+
sources +=
203+
[ "${example_platform_dir}/app_ble/source/BLEApplicationManager.cpp" ]
204+
} else {
205+
sources += [
206+
"${common_example_dir}/app_ble/source/BLEApplicationManagerEmpty.cpp",
207+
]
208+
}
209+
192210
if (chip_with_diag_logs_demo) {
193211
sources += [
194212
"${common_example_dir}/diagnostic_logs/source/DiagnosticLogsDemo.cpp",

examples/lock-app/nxp/mcxw71/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For generic information related to door lock application, please see the
1212
- [Flashing the host image](#flashing-the-host-image)
1313
- [Debugging](#debugging)
1414
- [OTA](#ota)
15+
- [Multiple BLE connections](#multiple-ble-connections)
1516

1617
## Introduction
1718

@@ -195,3 +196,15 @@ Run -> Debug Configurations... -> C/C++ Application
195196
196197
Please see
197198
[mcxw71 OTA guide](../../../../docs/guides/nxp/nxp_mcxw71_ota_guide.md).
199+
200+
## Multiple BLE connections
201+
202+
To compile with the Multiple BLE connections support demo example add the gn
203+
argument `nxp_multiple_ble_connections=true`.
204+
205+
The application will accept multiple BLE connections after commissioning, by
206+
pressing the BLE advertise button again. Once discovered by a BLE central, a
207+
custom GATT service will be visible on the device.
208+
209+
The user can change the default behavior by implementing the class defined in
210+
[BLEApplicationManager.h](../../../platform/nxp/common/app_ble/include/BLEApplicationManager.h)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* Copyright 2024 NXP
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <stdint.h>
23+
24+
namespace chip::NXP::App {
25+
26+
/**
27+
* @brief This class describes a manager for extra application BLE-related
28+
* functionality (e.g multiple BLE connections).
29+
*
30+
*/
31+
class BLEApplicationManager
32+
{
33+
public:
34+
void Init();
35+
void EnableMultipleConnectionsHandler();
36+
37+
private:
38+
static void EnableMultipleConnections(intptr_t arg);
39+
40+
friend BLEApplicationManager & BleAppMgr();
41+
static BLEApplicationManager sInstance;
42+
};
43+
44+
inline BLEApplicationManager & BleAppMgr()
45+
{
46+
return BLEApplicationManager::sInstance;
47+
}
48+
49+
} // namespace chip::NXP::App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* Copyright 2024 NXP
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "BLEApplicationManager.h"
21+
22+
using namespace ::chip::NXP::App;
23+
24+
BLEApplicationManager BLEApplicationManager::sInstance;
25+
26+
void BLEApplicationManager::Init(void)
27+
{
28+
/*Empty implementation. Intentionally left blank */
29+
}
30+
31+
void BLEApplicationManager::EnableMultipleConnectionsHandler(void)
32+
{
33+
/*Empty implementation. Intentionally left blank */
34+
}
35+
36+
void BLEApplicationManager::EnableMultipleConnections(intptr_t arg)
37+
{
38+
/*Empty implementation. Intentionally left blank */
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PRIMARY_SERVICE_UUID128(service_wireless_uart, uuid_service_wireless_uart)
2+
CHARACTERISTIC_UUID128(char_uart_stream, uuid_uart_stream, (gGattCharPropWriteWithoutRsp_c))
3+
VALUE_UUID128_VARLEN(value_uart_stream, uuid_uart_stream, (gPermissionFlagWritable_c), gAttMaxWriteDataSize_d(gAttMaxMtu_c), 1,
4+
0x00)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Declare all custom 128-bit UUIDs here using the format:
3+
*
4+
* UUID128(name, bytes)
5+
*
6+
* where:
7+
* -name : an unique tag for the newly defined UUID;
8+
will be used to reference this UUID when defining
9+
services and characteristics in <<gattDb.h>>
10+
* -bytes: 16 bytes representing the 128-bit value
11+
*
12+
* One definition per line. No semicolon required after each definition.
13+
*
14+
* example:
15+
* UUID128(uuid_service_robot_characteristics, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB,
16+
0xCD, 0xEF)
17+
* UUID128(uuid_char_robot_direction, 0x12, 0x34, 0x50, 0x00, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,
18+
0xEF)
19+
*/
20+
/* Services */
21+
22+
UUID128(uuid_service_wireless_uart, 0xE0, 0x1C, 0x4B, 0x5E, 0x1E, 0xEB, 0xA1, 0x5C, 0xEE, 0xF4, 0x5E, 0xBA, 0x00, 0x01, 0xFF, 0x01)
23+
UUID128(uuid_uart_stream, 0xE0, 0x1C, 0x4B, 0x5E, 0x1E, 0xEB, 0xA1, 0x5C, 0xEE, 0xF4, 0x5E, 0xBA, 0x01, 0x01, 0xFF, 0x01)

0 commit comments

Comments
 (0)