mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-09-25 13:31:15 +02:00
Support up to 1650 bytes of advertisement with extended advertising.
This commit is contained in:
@@ -752,7 +752,7 @@ std::string NimBLEAdvertisedDevice::toString() const {
|
|||||||
* @brief Get the length of the advertisement data in the payload.
|
* @brief Get the length of the advertisement data in the payload.
|
||||||
* @return The number of bytes in the payload that is from the advertisement.
|
* @return The number of bytes in the payload that is from the advertisement.
|
||||||
*/
|
*/
|
||||||
uint8_t NimBLEAdvertisedDevice::getAdvLength() const {
|
uint16_t NimBLEAdvertisedDevice::getAdvLength() const {
|
||||||
return m_advLength;
|
return m_advLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -69,7 +69,7 @@ class NimBLEAdvertisedDevice {
|
|||||||
NimBLEAddress getTargetAddress(uint8_t index = 0) const;
|
NimBLEAddress getTargetAddress(uint8_t index = 0) const;
|
||||||
uint8_t getTargetAddressCount() const;
|
uint8_t getTargetAddressCount() const;
|
||||||
int8_t getTXPower() const;
|
int8_t getTXPower() const;
|
||||||
uint8_t getAdvLength() const;
|
uint16_t getAdvLength() const;
|
||||||
uint8_t getAddressType() const;
|
uint8_t getAddressType() const;
|
||||||
bool isAdvertisingService(const NimBLEUUID& uuid) const;
|
bool isAdvertisingService(const NimBLEUUID& uuid) const;
|
||||||
bool haveAppearance() const;
|
bool haveAppearance() const;
|
||||||
@@ -162,7 +162,7 @@ class NimBLEAdvertisedDevice {
|
|||||||
uint8_t m_advType{};
|
uint8_t m_advType{};
|
||||||
int8_t m_rssi{};
|
int8_t m_rssi{};
|
||||||
uint8_t m_callbackSent{};
|
uint8_t m_callbackSent{};
|
||||||
uint8_t m_advLength{};
|
uint16_t m_advLength{};
|
||||||
|
|
||||||
# if MYNEWT_VAL(BLE_EXT_ADV)
|
# if MYNEWT_VAL(BLE_EXT_ADV)
|
||||||
bool m_isLegacyAdv{};
|
bool m_isLegacyAdv{};
|
||||||
|
@@ -616,6 +616,11 @@ bool NimBLEExtAdvertisement::setFlags(uint8_t flag) {
|
|||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
bool NimBLEExtAdvertisement::setManufacturerData(const uint8_t* data, size_t length) {
|
bool NimBLEExtAdvertisement::setManufacturerData(const uint8_t* data, size_t length) {
|
||||||
|
if (length > 0xFF - 1) {
|
||||||
|
NIMBLE_LOGE(LOG_TAG, "Manufacturer data too long!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t header[2];
|
uint8_t header[2];
|
||||||
header[0] = length + 1;
|
header[0] = length + 1;
|
||||||
header[1] = BLE_HS_ADV_TYPE_MFG_DATA;
|
header[1] = BLE_HS_ADV_TYPE_MFG_DATA;
|
||||||
@@ -652,6 +657,11 @@ bool NimBLEExtAdvertisement::setManufacturerData(const std::vector<uint8_t>& dat
|
|||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
bool NimBLEExtAdvertisement::setURI(const std::string& uri) {
|
bool NimBLEExtAdvertisement::setURI(const std::string& uri) {
|
||||||
|
if (uri.length() > 0xFF - 1) {
|
||||||
|
NIMBLE_LOGE(LOG_TAG, "URI too long!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t header[2];
|
uint8_t header[2];
|
||||||
header[0] = uri.length() + 1;
|
header[0] = uri.length() + 1;
|
||||||
header[1] = BLE_HS_ADV_TYPE_URI;
|
header[1] = BLE_HS_ADV_TYPE_URI;
|
||||||
@@ -670,6 +680,11 @@ bool NimBLEExtAdvertisement::setURI(const std::string& uri) {
|
|||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
bool NimBLEExtAdvertisement::setName(const std::string& name, bool isComplete) {
|
bool NimBLEExtAdvertisement::setName(const std::string& name, bool isComplete) {
|
||||||
|
if (name.length() > 0xFF - 1) {
|
||||||
|
NIMBLE_LOGE(LOG_TAG, "Name too long!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t header[2];
|
uint8_t header[2];
|
||||||
header[0] = name.length() + 1;
|
header[0] = name.length() + 1;
|
||||||
header[1] = isComplete ? BLE_HS_ADV_TYPE_COMP_NAME : BLE_HS_ADV_TYPE_INCOMP_NAME;
|
header[1] = isComplete ? BLE_HS_ADV_TYPE_COMP_NAME : BLE_HS_ADV_TYPE_INCOMP_NAME;
|
||||||
@@ -917,8 +932,12 @@ bool NimBLEExtAdvertisement::setServices(bool complete, uint8_t size, const std:
|
|||||||
*/
|
*/
|
||||||
bool NimBLEExtAdvertisement::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length) {
|
bool NimBLEExtAdvertisement::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length) {
|
||||||
uint8_t uuidBytes = uuid.bitSize() / 8;
|
uint8_t uuidBytes = uuid.bitSize() / 8;
|
||||||
uint8_t sDataLen = 2 + uuidBytes + length;
|
if (length + uuidBytes + 2 > 0xFF) {
|
||||||
|
NIMBLE_LOGE(LOG_TAG, "Service data too long!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sDataLen = 2 + uuidBytes + length;
|
||||||
if (m_payload.size() + sDataLen > MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)) {
|
if (m_payload.size() + sDataLen > MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -115,12 +115,6 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
|
|||||||
advertisedDevice = new NimBLEAdvertisedDevice(event, event_type);
|
advertisedDevice = new NimBLEAdvertisedDevice(event, event_type);
|
||||||
pScan->m_scanResults.m_deviceVec.push_back(advertisedDevice);
|
pScan->m_scanResults.m_deviceVec.push_back(advertisedDevice);
|
||||||
NIMBLE_LOGI(LOG_TAG, "New advertiser: %s", advertisedAddress.toString().c_str());
|
NIMBLE_LOGI(LOG_TAG, "New advertiser: %s", advertisedAddress.toString().c_str());
|
||||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
|
||||||
if (advertisedDevice->getDataStatus() == BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE) {
|
|
||||||
NIMBLE_LOGI(LOG_TAG, " EXT ADV data incomplete, waiting for more...");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
advertisedDevice->update(event, event_type);
|
advertisedDevice->update(event, event_type);
|
||||||
if (isLegacyAdv) {
|
if (isLegacyAdv) {
|
||||||
@@ -132,6 +126,13 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||||
|
if (advertisedDevice->getDataStatus() == BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE) {
|
||||||
|
NIMBLE_LOGD(LOG_TAG, "EXT ADV data incomplete, waiting for more");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
if (!advertisedDevice->m_callbackSent) {
|
if (!advertisedDevice->m_callbackSent) {
|
||||||
advertisedDevice->m_callbackSent++;
|
advertisedDevice->m_callbackSent++;
|
||||||
pScan->m_pScanCallbacks->onDiscovered(advertisedDevice);
|
pScan->m_pScanCallbacks->onDiscovered(advertisedDevice);
|
||||||
|
Reference in New Issue
Block a user