From a932e781ec34a469b483b4db8ef42a60e7218743 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 May 2022 16:10:35 -0400 Subject: [PATCH] Fix BLE device name for qpg and EFR32 to match the other platforms. (#18006) 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));