Skip to content

Commit

Permalink
[ESP32]: Add way to configure scan response.
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Aug 2, 2023
1 parent 67324e6 commit 1170275
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
12 changes: 11 additions & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <examples/platform/esp32/mode-support/static-supported-modes-manager.h>
#include <platform/ESP32/BLEManagerImpl.h>
#include <platform/ESP32/ESP32Utils.h>
#include <static-supported-temperature-levels.h>

Expand Down Expand Up @@ -118,6 +119,16 @@ static void InitServer(intptr_t context)
{
Esp32AppServer::Init(&sCallbacks); // Init ZCL Data Model and CHIP App Server AND Initialize device attestation config

uint8_t arr[31]; // 0x05, 0x09, a, b, c, d
arr[0] = 0x05;
arr[1] = 0x09;
arr[2] = 0x61;
arr[3] = 0x62;
arr[4] = 0x63;
arr[5] = 0x64;
chip::ByteSpan data(arr); // Use byte span instead
chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureScanResponseData(data);

#if !(CHIP_DEVICE_CONFIG_ENABLE_WIFI && CHIP_DEVICE_CONFIG_ENABLE_THREAD)
// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
Expand Down Expand Up @@ -225,7 +236,6 @@ extern "C" void app_main()
return;
}
#endif

chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class BLEManagerImpl final : public BLEManager,
#endif
{
public:
void ConfigureScanResponseData(ByteSpan data);
BLEManagerImpl() {}
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
CHIP_ERROR ConfigureBle(uint32_t aAdapterId, bool aIsCentral);
Expand All @@ -141,6 +142,7 @@ class BLEManagerImpl final : public BLEManager,
#endif

private:
chip::Optional<chip::ByteSpan> scanResponse;
// Allow the BLEManager interface class to delegate method calls to
// the implementation methods provided by this class.
friend BLEManager;
Expand Down
15 changes: 14 additions & 1 deletion src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,11 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
return err;
}

void BLEManagerImpl::ConfigureScanResponseData(ByteSpan data)
{
scanResponse = chip::Optional(data);
}

void BLEManagerImpl::HandleRXCharWrite(struct ble_gatt_char_context * param)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1587,7 +1592,15 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
err = MapBLEError(ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, &adv_params, ble_svr_gap_event, NULL));
if (err == CHIP_NO_ERROR)
{
return CHIP_NO_ERROR;
if (scanResponse.HasValue())
{
err = MapBLEError(ble_gap_adv_rsp_set_data(scanResponse.Value().data(), scanResponse.Value().size()));
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ble_gap_adv_rsp_set_data failed: %s", ErrorStr(err));
}
}
return err;
}
else
{
Expand Down

0 comments on commit 1170275

Please sign in to comment.