diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 0d2377a8..e477a26c 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -2,7 +2,7 @@ Scan This example scans for BLE peripherals and prints out their advertising details: - address, local name, adverised service UUID's. + address, local name, advertised service UUID's. The circuit: - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 104591a7..178c51ae 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -2,7 +2,7 @@ Scan Callback This example scans for BLE peripherals and prints out their advertising details: - address, local name, adverised service UUIDs. Unlike the Scan example, it uses + address, local name, advertised service UUIDs. Unlike the Scan example, it uses the callback style APIs and disables filtering so the peripheral discovery is reported for every single advertisement it makes. diff --git a/library.properties b/library.properties index 909871e2..73aa266e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.0 +version=1.2.1 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules. diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 6605a8a3..7d039584 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -756,7 +756,7 @@ void ATTClass::findByTypeReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dl } *findByTypeReq = (FindByTypeReq*)data; if (dlen < sizeof(FindByTypeReq)) { - sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_RESP, findByTypeReq->startHandle, ATT_ECODE_INVALID_PDU); + sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_REQ, findByTypeReq->startHandle, ATT_ECODE_INVALID_PDU); return; } @@ -794,7 +794,7 @@ void ATTClass::findByTypeReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dl } if (responseLength == 1) { - sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_RESP, findByTypeReq->startHandle, ATT_ECODE_ATTR_NOT_FOUND); + sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_REQ, findByTypeReq->startHandle, ATT_ECODE_ATTR_NOT_FOUND); } else { HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response); } @@ -1561,7 +1561,7 @@ bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* d for (int j = 0; j < characteristicCount; j++) { BLERemoteCharacteristic* characteristic = service->characteristic(j); - BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j); + BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j + 1); reqStartHandle = characteristic->valueHandle() + 1; reqEndHandle = nextCharacteristic ? nextCharacteristic->valueHandle() : serviceEndHandle; diff --git a/src/utility/ATT.h b/src/utility/ATT.h index 2d006841..6a1611aa 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -26,7 +26,9 @@ #define ATT_CID 0x0004 -#ifdef DM_CONN_MAX +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#define ATT_MAX_PEERS 7 +#elif DM_CONN_MAX #define ATT_MAX_PEERS DM_CONN_MAX // Mbed + Cordio #else #define ATT_MAX_PEERS 3 diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index 2948a38a..96f48fb9 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -56,7 +56,7 @@ void GAPClass::setManufacturerData(const uint8_t manufacturerData[], int manufac void GAPClass::setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength) { - uint8_t tmpManufacturerData[manufacturerDataLength + 2]; + uint8_t* tmpManufacturerData = (uint8_t*)malloc(manufacturerDataLength + 2); tmpManufacturerData[0] = companyId & 0xff; tmpManufacturerData[1] = companyId >> 8; memcpy(&tmpManufacturerData[2], manufacturerData, manufacturerDataLength); @@ -79,7 +79,7 @@ int GAPClass::advertise() uint8_t type = (_connectable) ? 0x00 : (_localName ? 0x02 : 0x03); - _advertising = false; + stopAdvertise(); if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) { return 0; @@ -97,20 +97,20 @@ int GAPClass::advertise() BLEUuid uuid(_advertisedServiceUuid); int uuidLen = uuid.length(); - advertisingData[3] = 1 + uuidLen; - advertisingData[4] = (uuidLen > 2) ? 0x06 : 0x02; - memcpy(&advertisingData[5], uuid.data(), uuidLen); + advertisingData[advertisingDataLen++] = 1 + uuidLen; + advertisingData[advertisingDataLen++] = (uuidLen > 2) ? 0x06 : 0x02; + memcpy(&advertisingData[advertisingDataLen], uuid.data(), uuidLen); - advertisingDataLen += (2 + uuidLen); + advertisingDataLen += uuidLen; } else if (_manufacturerData && _manufacturerDataLength) { - advertisingData[3] = 1 + _manufacturerDataLength; - advertisingData[4] = 0xff; - memcpy(&advertisingData[5], _manufacturerData, _manufacturerDataLength); + advertisingData[advertisingDataLen++] = 1 + _manufacturerDataLength; + advertisingData[advertisingDataLen++] = 0xff; + memcpy(&advertisingData[advertisingDataLen], _manufacturerData, _manufacturerDataLength); - advertisingDataLen += (2 + _manufacturerDataLength); + advertisingDataLen += _manufacturerDataLength; } - if (_serviceData && _serviceDataLength > 0 && advertisingDataLen >= (_serviceDataLength + 4)) { + if (_serviceData && _serviceDataLength > 0 && (sizeof(advertisingData) - advertisingDataLen) >= (_serviceDataLength + 4)) { advertisingData[advertisingDataLen++] = _serviceDataLength + 3; advertisingData[advertisingDataLen++] = 0x16; diff --git a/src/utility/GAP.h b/src/utility/GAP.h index b1b1cf48..cc64aab5 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -77,7 +77,7 @@ class GAPClass { uint16_t _serviceDataUuid; const uint8_t* _serviceData; - int _serviceDataLength; + uint32_t _serviceDataLength; BLEDeviceEventHandler _discoverEventHandler; BLELinkedList _discoveredDevices;