Skip to content

Commit

Permalink
Remove the ifdefs and fix the Zephyr static assert
Browse files Browse the repository at this point in the history
Also, set the default value of chip_enable_additional_data_advertising
to false in src/platform/BUILD.gn. If this flag is set then Linux and
ESP32 set the Additional Data flag and displayes the C3 characteristic.
  • Loading branch information
shubhamdp committed Dec 22, 2021
1 parent 378bdec commit 066c183
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/ble/CHIPBleServiceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ enum chipBLEServiceDataType
*/
struct ChipBLEDeviceIdentificationInfo
{
constexpr static uint16_t kDiscriminatorMask = 0xfff;
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
constexpr static uint16_t kDiscriminatorMask = 0xfff;
constexpr static uint8_t kAdditionalDataFlagMask = 0x1;
#endif

uint8_t OpCode;
uint8_t DeviceDiscriminator[2];
uint8_t DeviceVendorId[2];
uint8_t DeviceProductId[2];
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
uint8_t AdditionalDataFlag;
#endif

void Init() { memset(this, 0, sizeof(*this)); }

Expand All @@ -81,7 +77,6 @@ struct ChipBLEDeviceIdentificationInfo
chip::Encoding::LittleEndian::Put16(DeviceDiscriminator, deviceDiscriminator);
}

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
uint8_t GetAdditionalDataFlag() const { return (AdditionalDataFlag & kAdditionalDataFlagMask); }

void SetAdditionalDataFlag(bool flag)
Expand All @@ -95,7 +90,6 @@ struct ChipBLEDeviceIdentificationInfo
AdditionalDataFlag &= static_cast<uint8_t>(~kAdditionalDataFlagMask);
}
}
#endif
} __attribute__((packed));

} /* namespace Ble */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ GenericConfigurationManagerImpl<ConfigClass>::GetBLEDeviceIdentificationInfo(Ble
SuccessOrExit(err);
deviceIdInfo.SetDeviceDiscriminator(discriminator);

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
deviceIdInfo.SetAdditionalDataFlag(true);
#endif

exit:
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (chip_device_platform != "none") {
chip_bypass_rendezvous = false

# Enable including the additional data in the advertisement packets
chip_enable_additional_data_advertising = true
chip_enable_additional_data_advertising = false

# Enable adding optional rotating device id to the additional data.
chip_enable_rotating_device_id = false
Expand Down
4 changes: 4 additions & 0 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
ExitNow();
}

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
deviceIdInfo.SetAdditionalDataFlag(true);
#endif

VerifyOrExit(index + sizeof(deviceIdInfo) <= sizeof(advData), err = CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG);
memcpy(&advData[index], &deviceIdInfo, sizeof(deviceIdInfo));
index = static_cast<uint8_t>(index + sizeof(deviceIdInfo));
Expand Down
8 changes: 5 additions & 3 deletions src/platform/Linux/bluez/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@

/**
* @file
* Provides Bluez dbus implementatioon for BLE
* Provides Bluez dbus implementation for BLE
*/
#include <platform/CHIPDeviceConfig.h>

#include <ble/BleUUID.h>
#include <ble/CHIPBleServiceData.h>
#include <lib/support/BitFlags.h>
Expand Down Expand Up @@ -1521,6 +1519,10 @@ CHIP_ERROR ConfigureBluezAdv(BLEAdvConfig & aBleAdvConfig, BluezEndpoint * apEnd
err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(apEndpoint->mDeviceIdInfo);
SuccessOrExit(err);

#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
apEndpoint->mDeviceIdInfo.SetAdditionalDataFlag(true);
#endif

exit:
if (nullptr != msg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Zephyr/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
}

// Initialize service data
static_assert(sizeof(serviceData) == 9, "Size of BLE advertisement data changed! Was that intentional?");
static_assert(sizeof(serviceData) == 10, "Size of BLE advertisement data changed! Was that intentional?");
chip::Encoding::LittleEndian::Put16(serviceData.uuid, UUID16_CHIPoBLEService.val);
ReturnErrorOnFailure(ConfigurationMgr().GetBLEDeviceIdentificationInfo(serviceData.deviceIdInfo));

Expand Down

0 comments on commit 066c183

Please sign in to comment.