From 267c460974917dfb8ca22bc510ea513947b97a22 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 3 May 2022 13:48:27 -0400 Subject: [PATCH] Fix BLE device name for qpg and EFR32 to match the other platforms. These had hardcoded 0, while other platforms use the discriminator. Fixes https://github.com/project-chip/connectedhomeip/issues/112 --- src/include/platform/CHIPDeviceConfig.h | 2 +- src/platform/EFR32/BLEManagerImpl.cpp | 7 ++++++- src/platform/qpg/BLEManagerImpl.cpp | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 105cf23e25af52..b65eadee3f6784 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -500,7 +500,7 @@ * CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX * * A prefix string used in forming the BLE device name. The remainder of the name - * consists of the final two bytes of the device's chip node id in hex. + * typically contains the setup discriminator as a 4-digit decimal number. * * NOTE: The device layer limits the total length of a device name to 16 characters. * However, due to other data sent in CHIPoBLE advertise packets, the device name diff --git a/src/platform/EFR32/BLEManagerImpl.cpp b/src/platform/EFR32/BLEManagerImpl.cpp index 3d9f0fd5099d83..627c4d1d3aaccd 100644 --- a/src/platform/EFR32/BLEManagerImpl.cpp +++ b/src/platform/EFR32/BLEManagerImpl.cpp @@ -37,7 +37,9 @@ #include #include #include +#include #include + using namespace ::chip; using namespace ::chip::Ble; @@ -650,7 +652,10 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) if (!mFlags.Has(Flags::kDeviceNameSet)) { - snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0); + uint16_t discriminator; + SuccessOrExit(err = GetCommissionableDataProvider()->GetSetupDiscriminator(discriminator)); + + snprintf(mDeviceName, sizeof(mDeviceName), "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator); mDeviceName[kMaxDeviceNameLength] = 0; mDeviceNameLength = strlen(mDeviceName); diff --git a/src/platform/qpg/BLEManagerImpl.cpp b/src/platform/qpg/BLEManagerImpl.cpp index d35cd56917a21d..1bbd60d707ec20 100644 --- a/src/platform/qpg/BLEManagerImpl.cpp +++ b/src/platform/qpg/BLEManagerImpl.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -459,7 +460,10 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void) if (!mFlags.Has(Flags::kDeviceNameSet)) { - snprintf(deviceName, sizeof(deviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0); + uint16_t discriminator; + SuccessOrExit(err = GetCommissionableDataProvider()->GetSetupDiscriminator(discriminator)); + + snprintf(deviceName, sizeof(deviceName), "%s%04u", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, discriminator); deviceName[kMaxDeviceNameLength] = 0; err = MapBLEError(qvCHIP_BleSetDeviceName(deviceName));