Skip to content

Commit 3200016

Browse files
authored
Fix regression for esp32 BLE controller (project-chip#26347)
1 parent 5651875 commit 3200016

File tree

9 files changed

+30
-38
lines changed

9 files changed

+30
-38
lines changed

config/esp32/components/chip/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ if ((CONFIG_BT_ENABLED) AND (CONFIG_ENABLE_CHIPOBLE))
155155
endif()
156156
endif()
157157

158+
if (CONFIG_ENABLE_ESP32_BLE_CONTROLLER)
159+
chip_gn_arg_append("chip_enable_ble_controller" "true")
160+
endif()
161+
158162
if (CONFIG_ENABLE_MATTER_OVER_THREAD)
159163
chip_gn_arg_append("chip_enable_openthread" "true")
160164
else()

config/esp32/components/chip/Kconfig

-7
Original file line numberDiff line numberDiff line change
@@ -917,13 +917,6 @@ menu "CHIP Device Layer"
917917
help
918918
Enable esp32 as a BLE Commissioner.
919919

920-
config ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
921-
bool "Enable Commissionee and Commissioner mode"
922-
default n
923-
depends on ENABLE_ESP32_BLE_Controller
924-
help
925-
Enable including commissioner code (CHIPDeviceController.cpp) in the commissionee (Server.cpp) code.
926-
927920
endmenu
928921

929922
endmenu

src/platform/ESP32/BLEManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class BLEManagerImpl final : public BLEManager,
186186
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
187187

188188
void NewConnection(chip::Ble::BleLayer * bleLayer, void * appState, const SetupDiscriminator & connDiscriminator) override;
189+
void NewConnection(chip::Ble::BleLayer * bleLayer, void * appState, BLE_CONNECTION_OBJECT connObj) override{};
189190
CHIP_ERROR CancelConnection() override;
190191

191192
// ===== Members that implement virtual methods on ChipDeviceScannerDelegate

src/platform/ESP32/BUILD.gn

+14-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ declare_args() {
2727
chip_enable_chipoble = true
2828
chip_bt_nimble_enabled = false
2929
chip_bt_bluedroid_enabled = false
30+
chip_enable_ble_controller = false
3031
chip_use_secure_cert_dac_provider = false
3132
}
3233

@@ -90,20 +91,22 @@ static_library("ESP32") {
9091
}
9192

9293
if (chip_bt_nimble_enabled) {
93-
sources += [
94-
"nimble/BLEManagerImpl.cpp",
95-
"nimble/ChipDeviceScanner.cpp",
96-
"nimble/blecent.h",
97-
"nimble/misc.c",
98-
"nimble/peer.c",
99-
]
94+
sources += [ "nimble/BLEManagerImpl.cpp" ]
95+
if (chip_enable_ble_controller) {
96+
sources += [
97+
"nimble/ChipDeviceScanner.cpp",
98+
"nimble/blecent.h",
99+
"nimble/misc.c",
100+
"nimble/peer.c",
101+
]
102+
}
100103
}
101104

102105
if (chip_bt_bluedroid_enabled) {
103-
sources += [
104-
"bluedroid/BLEManagerImpl.cpp",
105-
"bluedroid/ChipDeviceScanner.cpp",
106-
]
106+
sources += [ "bluedroid/BLEManagerImpl.cpp" ]
107+
if (chip_enable_ble_controller) {
108+
sources += [ "bluedroid/ChipDeviceScanner.cpp" ]
109+
}
107110
}
108111

109112
if (chip_enable_wifi) {

src/platform/ESP32/CHIPDevicePlatformConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@
9797
#define CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION CONFIG_CHIP_KVS_NAMESPACE_PARTITION_LABEL
9898
#define CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
9999
#define CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS CONFIG_CHIP_DISCOVERY_TIMEOUT_SECS
100-
#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
100+
#define CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE CONFIG_ENABLE_ESP32_BLE_CONTROLLER

src/platform/ESP32/nimble/ChipDeviceScanner.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
19-
2018
#include "blecent.h"
2119
#include <lib/support/CodeUtils.h>
2220
#include <lib/support/logging/CHIPLogging.h>
@@ -153,4 +151,3 @@ CHIP_ERROR ChipDeviceScanner::StopScan()
153151
} // namespace Internal
154152
} // namespace DeviceLayer
155153
} // namespace chip
156-
#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER

src/platform/ESP32/nimble/blecent.h

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
* under the License.
3535
*/
3636
#pragma once
37-
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
3837
#include <host/ble_gatt.h>
3938

4039
#ifdef __cplusplus
@@ -107,4 +106,3 @@ struct peer * peer_find(uint16_t conn_handle);
107106
#ifdef __cplusplus
108107
}
109108
#endif
110-
#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER

src/platform/ESP32/nimble/misc.c

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
2019
#include "blecent.h"
2120
#include "host/ble_hs.h"
2221
#include "host/ble_uuid.h"
@@ -216,4 +215,3 @@ void print_adv_fields(const struct ble_hs_adv_fields * fields)
216215
MODLOG_DFLT(DEBUG, "\n");
217216
}
218217
}
219-
#endif // CONFIG_ENABLE_ESP32_BLE_CONTROLLER

src/platform/ESP32/nimble/peer.c

+10-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
21-
2220
#include "blecent.h"
2321
#include "host/ble_hs.h"
2422
#include <assert.h>
@@ -259,7 +257,8 @@ uint16_t chr_end_handle(const struct peer_svc * svc, const struct peer_chr * chr
259257
next_chr = SLIST_NEXT(chr, next);
260258
if (next_chr != NULL)
261259
{
262-
return next_chr->chr.def_handle - 1;
260+
int result = next_chr->chr.def_handle - 1;
261+
return (uint16_t) result;
263262
}
264263
else
265264
{
@@ -763,56 +762,56 @@ int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs)
763762
/* Free memory first in case this function gets called more than once. */
764763
peer_free_mem();
765764

766-
peer_mem = malloc(OS_MEMPOOL_BYTES(max_peers, sizeof(struct peer)));
765+
peer_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_peers, sizeof(struct peer)));
767766
if (peer_mem == NULL)
768767
{
769768
rc = BLE_HS_ENOMEM;
770769
goto err;
771770
}
772771

773-
rc = os_mempool_init(&peer_pool, max_peers, sizeof(struct peer), peer_mem, "peer_pool");
772+
rc = os_mempool_init(&peer_pool, (uint16_t) max_peers, sizeof(struct peer), peer_mem, "peer_pool");
774773
if (rc != 0)
775774
{
776775
rc = BLE_HS_EOS;
777776
goto err;
778777
}
779778

780-
peer_svc_mem = malloc(OS_MEMPOOL_BYTES(max_svcs, sizeof(struct peer_svc)));
779+
peer_svc_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_svcs, sizeof(struct peer_svc)));
781780
if (peer_svc_mem == NULL)
782781
{
783782
rc = BLE_HS_ENOMEM;
784783
goto err;
785784
}
786785

787-
rc = os_mempool_init(&peer_svc_pool, max_svcs, sizeof(struct peer_svc), peer_svc_mem, "peer_svc_pool");
786+
rc = os_mempool_init(&peer_svc_pool, (uint16_t) max_svcs, sizeof(struct peer_svc), peer_svc_mem, "peer_svc_pool");
788787
if (rc != 0)
789788
{
790789
rc = BLE_HS_EOS;
791790
goto err;
792791
}
793792

794-
peer_chr_mem = malloc(OS_MEMPOOL_BYTES(max_chrs, sizeof(struct peer_chr)));
793+
peer_chr_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_chrs, sizeof(struct peer_chr)));
795794
if (peer_chr_mem == NULL)
796795
{
797796
rc = BLE_HS_ENOMEM;
798797
goto err;
799798
}
800799

801-
rc = os_mempool_init(&peer_chr_pool, max_chrs, sizeof(struct peer_chr), peer_chr_mem, "peer_chr_pool");
800+
rc = os_mempool_init(&peer_chr_pool, (uint16_t) max_chrs, sizeof(struct peer_chr), peer_chr_mem, "peer_chr_pool");
802801
if (rc != 0)
803802
{
804803
rc = BLE_HS_EOS;
805804
goto err;
806805
}
807806

808-
peer_dsc_mem = malloc(OS_MEMPOOL_BYTES(max_dscs, sizeof(struct peer_dsc)));
807+
peer_dsc_mem = malloc(OS_MEMPOOL_BYTES((uint16_t) max_dscs, sizeof(struct peer_dsc)));
809808
if (peer_dsc_mem == NULL)
810809
{
811810
rc = BLE_HS_ENOMEM;
812811
goto err;
813812
}
814813

815-
rc = os_mempool_init(&peer_dsc_pool, max_dscs, sizeof(struct peer_dsc), peer_dsc_mem, "peer_dsc_pool");
814+
rc = os_mempool_init(&peer_dsc_pool, (uint16_t) max_dscs, sizeof(struct peer_dsc), peer_dsc_mem, "peer_dsc_pool");
816815
if (rc != 0)
817816
{
818817
rc = BLE_HS_EOS;
@@ -825,4 +824,3 @@ int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs)
825824
peer_free_mem();
826825
return rc;
827826
}
828-
#endif

0 commit comments

Comments
 (0)