mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-23 15:18:16 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
815c5556e0 | ||
|
|
14f8737c41 | ||
|
|
5b4e4bd7dc | ||
|
|
91f9b979d4 |
@@ -1,6 +1,15 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [2.3.3] 2025-09-05
|
||||
|
||||
## Fixed
|
||||
- NimBLEAdvertisedDevice::isConnectable returning incorrect result.
|
||||
- Extended advertisements not reporting full data.
|
||||
|
||||
## Added
|
||||
- Support up to 1650 bytes of advertisement with extended advertising
|
||||
|
||||
## [2.3.2] 2025-09-02
|
||||
|
||||
## Fixed
|
||||
|
||||
@@ -48,7 +48,7 @@ PROJECT_NAME = esp-nimble-cpp
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 2.3.2
|
||||
PROJECT_NUMBER = 2.3.3
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
# quick idea about the purpose of the project. Keep the description short.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "2.3.2"
|
||||
version: "2.3.3"
|
||||
license: "Apache-2.0"
|
||||
description: "C++ wrapper for the NimBLE BLE stack"
|
||||
url: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "esp-nimble-cpp",
|
||||
"version": "2.3.2",
|
||||
"version": "2.3.3",
|
||||
"description": "C++ wrapper for the NimBLE BLE stack",
|
||||
"keywords": [
|
||||
"BLE",
|
||||
|
||||
@@ -38,6 +38,7 @@ NimBLEAdvertisedDevice::NimBLEAdvertisedDevice(const ble_gap_event* event, uint8
|
||||
m_callbackSent{0},
|
||||
m_advLength{event->ext_disc.length_data},
|
||||
m_isLegacyAdv{!!(event->ext_disc.props & BLE_HCI_ADV_LEGACY_MASK)},
|
||||
m_dataStatus{event->ext_disc.data_status},
|
||||
m_sid{event->ext_disc.sid},
|
||||
m_primPhy{event->ext_disc.prim_phy},
|
||||
m_secPhy{event->ext_disc.sec_phy},
|
||||
@@ -60,7 +61,16 @@ NimBLEAdvertisedDevice::NimBLEAdvertisedDevice(const ble_gap_event* event, uint8
|
||||
void NimBLEAdvertisedDevice::update(const ble_gap_event* event, uint8_t eventType) {
|
||||
# if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
const auto& disc = event->ext_disc;
|
||||
m_isLegacyAdv = disc.props & BLE_HCI_ADV_LEGACY_MASK;
|
||||
if (m_dataStatus == BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE) {
|
||||
m_payload.reserve(m_advLength + disc.length_data);
|
||||
m_payload.insert(m_payload.end(), disc.data, disc.data + disc.length_data);
|
||||
m_dataStatus = disc.data_status;
|
||||
m_advLength = m_payload.size();
|
||||
return;
|
||||
}
|
||||
|
||||
m_dataStatus = disc.data_status;
|
||||
m_isLegacyAdv = disc.props & BLE_HCI_ADV_LEGACY_MASK;
|
||||
# else
|
||||
const auto& disc = event->disc;
|
||||
# endif
|
||||
@@ -86,11 +96,11 @@ const NimBLEAddress& NimBLEAdvertisedDevice::getAddress() const {
|
||||
/**
|
||||
* @brief Get the advertisement type.
|
||||
* @return The advertising type the device is reporting:
|
||||
* * BLE_HCI_ADV_TYPE_ADV_IND (0) - indirect advertising
|
||||
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertising - high duty cycle
|
||||
* * BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) - indirect scan response
|
||||
* * BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertising - not connectable
|
||||
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) - direct advertising - low duty cycle
|
||||
* * BLE_HCI_ADV_RPT_EVTYPE_ADV_IND (0) - indirect advertising - connectable and scannable
|
||||
* * BLE_HCI_ADV_RPT_EVTYPE_DIR_IND (1) - direct advertising - connectable
|
||||
* * BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND (2) - indirect scan response - not connectable - scannable
|
||||
* * BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND (3) - beacon only - not connectable - not scannable
|
||||
* * BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP (4) - scan response
|
||||
*/
|
||||
uint8_t NimBLEAdvertisedDevice::getAdvType() const {
|
||||
return m_advType;
|
||||
@@ -617,6 +627,18 @@ uint8_t NimBLEAdvertisedDevice::getSecondaryPhy() const {
|
||||
uint16_t NimBLEAdvertisedDevice::getPeriodicInterval() const {
|
||||
return m_periodicItvl;
|
||||
} // getPeriodicInterval
|
||||
|
||||
/**
|
||||
* @brief Get the advertisement data status.
|
||||
* @return The advertisement data status.
|
||||
* One of:
|
||||
* * BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE (0) - Complete extended advertising data
|
||||
* * BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE (1) - Incomplete extended advertising data, more to come
|
||||
* * BLE_GAP_EXT_ADV_DATA_STATUS_TRUNCATED (2) - Incomplete extended advertising data, no more to come
|
||||
*/
|
||||
uint8_t NimBLEAdvertisedDevice::getDataStatus() const {
|
||||
return m_dataStatus;
|
||||
} // getDataStatus
|
||||
# endif
|
||||
|
||||
uint8_t NimBLEAdvertisedDevice::findAdvField(uint8_t type, uint8_t index, size_t* data_loc) const {
|
||||
@@ -730,7 +752,7 @@ std::string NimBLEAdvertisedDevice::toString() const {
|
||||
* @brief Get the length of the advertisement data in the payload.
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -752,11 +774,12 @@ uint8_t NimBLEAdvertisedDevice::getAddressType() const {
|
||||
*/
|
||||
bool NimBLEAdvertisedDevice::isConnectable() const {
|
||||
# if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
if (m_isLegacyAdv) {
|
||||
return m_advType == BLE_HCI_ADV_RPT_EVTYPE_ADV_IND || m_advType == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND;
|
||||
if (!m_isLegacyAdv) {
|
||||
return (m_advType & BLE_HCI_ADV_CONN_MASK) || (m_advType & BLE_HCI_ADV_DIRECT_MASK);
|
||||
}
|
||||
# endif
|
||||
return (m_advType & BLE_HCI_ADV_CONN_MASK) || (m_advType & BLE_HCI_ADV_DIRECT_MASK);
|
||||
|
||||
return m_advType == BLE_HCI_ADV_RPT_EVTYPE_ADV_IND || m_advType == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND;
|
||||
} // isConnectable
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,7 @@ class NimBLEAdvertisedDevice {
|
||||
NimBLEAddress getTargetAddress(uint8_t index = 0) const;
|
||||
uint8_t getTargetAddressCount() const;
|
||||
int8_t getTXPower() const;
|
||||
uint8_t getAdvLength() const;
|
||||
uint16_t getAdvLength() const;
|
||||
uint8_t getAddressType() const;
|
||||
bool isAdvertisingService(const NimBLEUUID& uuid) const;
|
||||
bool haveAppearance() const;
|
||||
@@ -92,6 +92,7 @@ class NimBLEAdvertisedDevice {
|
||||
uint8_t getPrimaryPhy() const;
|
||||
uint8_t getSecondaryPhy() const;
|
||||
uint16_t getPeriodicInterval() const;
|
||||
uint8_t getDataStatus() const;
|
||||
# endif
|
||||
operator NimBLEAddress() const;
|
||||
|
||||
@@ -161,10 +162,11 @@ class NimBLEAdvertisedDevice {
|
||||
uint8_t m_advType{};
|
||||
int8_t m_rssi{};
|
||||
uint8_t m_callbackSent{};
|
||||
uint8_t m_advLength{};
|
||||
uint16_t m_advLength{};
|
||||
|
||||
# if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
bool m_isLegacyAdv{};
|
||||
uint8_t m_dataStatus{};
|
||||
uint8_t m_sid{};
|
||||
uint8_t m_primPhy{};
|
||||
uint8_t m_secPhy{};
|
||||
|
||||
@@ -616,6 +616,11 @@ bool NimBLEExtAdvertisement::setFlags(uint8_t flag) {
|
||||
* @return True if successful.
|
||||
*/
|
||||
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];
|
||||
header[0] = length + 1;
|
||||
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.
|
||||
*/
|
||||
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];
|
||||
header[0] = uri.length() + 1;
|
||||
header[1] = BLE_HS_ADV_TYPE_URI;
|
||||
@@ -670,6 +680,11 @@ bool NimBLEExtAdvertisement::setURI(const std::string& uri) {
|
||||
* @return True if successful.
|
||||
*/
|
||||
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];
|
||||
header[0] = name.length() + 1;
|
||||
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) {
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -117,13 +117,22 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
|
||||
NIMBLE_LOGI(LOG_TAG, "New advertiser: %s", advertisedAddress.toString().c_str());
|
||||
} else {
|
||||
advertisedDevice->update(event, event_type);
|
||||
if (isLegacyAdv && event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
||||
NIMBLE_LOGI(LOG_TAG, "Scan response from: %s", advertisedAddress.toString().c_str());
|
||||
} else {
|
||||
NIMBLE_LOGI(LOG_TAG, "Duplicate; updated: %s", advertisedAddress.toString().c_str());
|
||||
if (isLegacyAdv) {
|
||||
if (event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
||||
NIMBLE_LOGI(LOG_TAG, "Scan response from: %s", advertisedAddress.toString().c_str());
|
||||
} else {
|
||||
NIMBLE_LOGI(LOG_TAG, "Duplicate; updated: %s", advertisedAddress.toString().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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) {
|
||||
advertisedDevice->m_callbackSent++;
|
||||
pScan->m_pScanCallbacks->onDiscovered(advertisedDevice);
|
||||
|
||||
Reference in New Issue
Block a user