Skip to content

Commit 2b31728

Browse files
committed
fix: set advertized name fixed length
1 parent 7a40296 commit 2b31728

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/BLEAdvertisingData.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "BLEAdvertisingData.h"
2121

2222
#define AD_FIELD_OVERHEAD (2)
23+
#define AD_NAME_LENGTH (19)
2324

2425
BLEAdvertisingData::BLEAdvertisingData() :
2526
_dataLength(0),
@@ -320,13 +321,11 @@ bool BLEAdvertisingData::hasFlags() const
320321

321322
bool BLEAdvertisingData::addLocalName(const char *localName)
322323
{
323-
bool success = false;
324-
if (strlen(localName) > (MAX_AD_DATA_LENGTH - AD_FIELD_OVERHEAD)) {
325-
success = addField(BLEFieldShortLocalName, (uint8_t*)localName, (MAX_AD_DATA_LENGTH - AD_FIELD_OVERHEAD));
326-
} else {
327-
success = addField(BLEFieldCompleteLocalName, localName);
328-
}
329-
return success;
324+
uint8_t tempData[AD_NAME_LENGTH];
325+
uint8_t tempDataLength = strlen(localName);
326+
memcpy(tempData, (uint8_t*)localName, tempDataLength + 1);
327+
memset(&tempData[tempDataLength + 1], 0x20, AD_NAME_LENGTH - tempDataLength - 1);
328+
return addField(BLEFieldCompleteLocalName, tempData, AD_NAME_LENGTH);
330329
}
331330

332331
bool BLEAdvertisingData::addAdvertisedServiceUuid(const char* advertisedServiceUuid)

0 commit comments

Comments
 (0)