Skip to content

Commit

Permalink
Remove a #ifdef since the bug was fixed in gsdk for mg24, Remove BLE …
Browse files Browse the repository at this point in the history
…name from gat and ADV data and set it in the scan response data (#18330)
  • Loading branch information
jmartinez-silabs authored May 11, 2022
1 parent 4d01abf commit 3783cfe
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions src/platform/EFR32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize)

CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
{
sl_status_t ret;
CHIP_ERROR err = CHIP_NO_ERROR;
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_NotSupported)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
Expand All @@ -413,20 +411,14 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
}
strcpy(mDeviceName, deviceName);
mFlags.Set(Flags::kDeviceNameSet);
ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName);
static_assert(kMaxDeviceNameLength <= UINT16_MAX, "deviceName length might not fit in a uint8_t");
ret = sl_bt_gatt_server_write_attribute_value(gattdb_device_name, 0, strlen(deviceName), (uint8_t *) deviceName);
if (ret != SL_STATUS_OK)
{
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_gatt_server_write_attribute_value() failed: %s", ErrorStr(err));
return err;
}
mFlags.Set(Flags::kRestartAdvertising);
ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", mDeviceName);
}
else
{
mDeviceName[0] = 0;
}
PlatformMgr().ScheduleWork(DriveBLEState, 0);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -661,14 +653,6 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
mDeviceNameLength = strlen(mDeviceName);

VerifyOrExit(mDeviceNameLength < kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT);

ret = sl_bt_gatt_server_write_attribute_value(gattdb_device_name, 0, mDeviceNameLength, (uint8_t *) mDeviceName);
if (ret != SL_STATUS_OK)
{
err = MapBLEError(ret);
ChipLogError(DeviceLayer, "sl_bt_gatt_server_write_attribute_value() failed: %s", ErrorStr(err));
return err;
}
}

mDeviceNameLength = strlen(mDeviceName); // Device Name length + length field
Expand All @@ -689,11 +673,6 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value
index += mDeviceIdInfoLength;

advData[index++] = static_cast<uint8_t>(mDeviceNameLength + 1); // length
advData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name
memcpy(&advData[index], mDeviceName, mDeviceNameLength); // AD value
index += mDeviceNameLength;

if (0xff != advertising_set_handle)
{
sl_bt_advertiser_delete_set(advertising_set_handle);
Expand Down Expand Up @@ -723,6 +702,11 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
responseData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value
responseData[index++] = ShortUUID_CHIPoBLEService[1];

responseData[index++] = static_cast<uint8_t>(mDeviceNameLength + 1); // length
responseData[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name
memcpy(&responseData[index], mDeviceName, mDeviceNameLength); // AD value
index += mDeviceNameLength;

ret = sl_bt_advertiser_set_data(advertising_set_handle, CHIP_ADV_SCAN_RESPONSE_DATA, index, (uint8_t *) responseData);

if (ret != SL_STATUS_OK)
Expand Down Expand Up @@ -759,14 +743,10 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
ChipLogDetail(DeviceLayer, "Start BLE advertissement");
}

#ifndef EFR32MG24
// set_random_address call causes problems with MG24 family.
// Todo fix in GSDK.
const uint8_t kResolvableRandomAddrType = 2; // Private resolvable random address type
bd_addr unusedBdAddr; // We can ignore this field when setting random address.
sl_bt_advertiser_set_random_address(advertising_set_handle, kResolvableRandomAddrType, unusedBdAddr, &unusedBdAddr);
(void) unusedBdAddr;
#endif

err = ConfigureAdvertisingData();
SuccessOrExit(err);
Expand Down

0 comments on commit 3783cfe

Please sign in to comment.