Skip to content

Commit

Permalink
[QPG610x] Move static data to stack (#9982)
Browse files Browse the repository at this point in the history
* * Move static data to stack

* Add TODO to spec miss

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
jimlyall-q and restyled-commits authored Oct 5, 2021
1 parent 05b2c55 commit 3c2b8d1
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/platform/qpg/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,12 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
uint8_t mDeviceNameLength = 0;
uint8_t mDeviceIdInfoLength = 0;

memset(mAdvDataBuf, 0, kMaxAdvertisementDataSetSize);
memset(mScanRespDataBuf, 0, kMaxAdvertisementDataSetSize);
char deviceName[kMaxDeviceNameLength + 1];
uint8_t advDataBuf[kMaxAdvertisementDataSetSize];
uint8_t scanRespDataBuf[kMaxAdvertisementDataSetSize];

memset(advDataBuf, 0, kMaxAdvertisementDataSetSize);
memset(scanRespDataBuf, 0, kMaxAdvertisementDataSetSize);

err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo);
SuccessOrExit(err);
Expand All @@ -444,8 +448,8 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
{
snprintf(mDeviceName, sizeof(mDeviceName), "%s%04" PRIX32, CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, (uint32_t) 0);

mDeviceName[kMaxDeviceNameLength] = 0;
err = MapBLEError(qvCHIP_BleSetDeviceName(mDeviceName));
deviceName[kMaxDeviceNameLength] = 0;
err = MapBLEError(qvCHIP_BleSetDeviceName(deviceName));
SuccessOrExit(err);
}

Expand All @@ -458,31 +462,32 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
"Advertisement data buffer is not big enough");

// Fill in advertising data
index = 0;
mAdvDataBuf[index++] = 0x02; // length
mAdvDataBuf[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags
mAdvDataBuf[index++] = CHIP_ADV_DATA_FLAGS; // AD value

mAdvDataBuf[index++] = static_cast<uint8_t>(mDeviceIdInfoLength + CHIP_ADV_SHORT_UUID_LEN + 1); // AD length
mAdvDataBuf[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data
mAdvDataBuf[index++] = chipUUID_CHIPoBLE_Service[1]; // AD value
mAdvDataBuf[index++] = chipUUID_CHIPoBLE_Service[0];
memcpy(&mAdvDataBuf[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value
index = 0;
advDataBuf[index++] = 0x02; // length
advDataBuf[index++] = CHIP_ADV_DATA_TYPE_FLAGS; // AD type : flags
advDataBuf[index++] = CHIP_ADV_DATA_FLAGS; // AD value

advDataBuf[index++] = static_cast<uint8_t>(mDeviceIdInfoLength + CHIP_ADV_SHORT_UUID_LEN + 1); // AD length
advDataBuf[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data
advDataBuf[index++] = chipUUID_CHIPoBLE_Service[1]; // AD value
advDataBuf[index++] = chipUUID_CHIPoBLE_Service[0];
memcpy(&advDataBuf[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value
index = static_cast<uint8_t>(index + mDeviceIdInfoLength);

mAdvDataBuf[index++] = static_cast<uint8_t>(mDeviceNameLength + 1); // length
mAdvDataBuf[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name
memcpy(&mAdvDataBuf[index], mDeviceName, mDeviceNameLength); // AD value
// TODO remove device name issue #10221
advDataBuf[index++] = static_cast<uint8_t>(mDeviceNameLength + 1); // length
advDataBuf[index++] = CHIP_ADV_DATA_TYPE_NAME; // AD type : name
memcpy(&advDataBuf[index], deviceName, mDeviceNameLength); // AD value
index = static_cast<uint8_t>(index + mDeviceNameLength);

qvCHIP_BleSetAdvData(QV_ADV_DATA_LOC_ADV, index, mAdvDataBuf);

// Fill in scan response data
index = 0;
mScanRespDataBuf[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length
mScanRespDataBuf[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid
mScanRespDataBuf[index++] = chipUUID_CHIPoBLE_Service[1]; // AD value
mScanRespDataBuf[index++] = chipUUID_CHIPoBLE_Service[0];
index = 0;
scanRespDataBuf[index++] = CHIP_ADV_SHORT_UUID_LEN + 1; // AD length
scanRespDataBuf[index++] = CHIP_ADV_DATA_TYPE_UUID; // AD type : uuid
scanRespDataBuf[index++] = chipUUID_CHIPoBLE_Service[1]; // AD value
scanRespDataBuf[index++] = chipUUID_CHIPoBLE_Service[0];

qvCHIP_BleSetAdvData(QV_ADV_DATA_LOC_SCAN, index, mScanRespDataBuf);

Expand Down

0 comments on commit 3c2b8d1

Please sign in to comment.