Skip to content

Commit 61138fc

Browse files
authored
Merge pull request arduino-libraries#16 from cparata/master
Align STM32duinoBLE to current ArduinoBLE master
2 parents e7e1bf7 + 14fd996 commit 61138fc

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duinoBLE
2-
version=1.2.0
2+
version=1.2.1
33
author=Arduino, SRA
44
maintainer=stm32duino
55
sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules.

src/utility/ATT.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ void ATTClass::findByTypeReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dl
756756
} *findByTypeReq = (FindByTypeReq*)data;
757757

758758
if (dlen < sizeof(FindByTypeReq)) {
759-
sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_RESP, findByTypeReq->startHandle, ATT_ECODE_INVALID_PDU);
759+
sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_REQ, findByTypeReq->startHandle, ATT_ECODE_INVALID_PDU);
760760
return;
761761
}
762762

@@ -794,7 +794,7 @@ void ATTClass::findByTypeReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dl
794794
}
795795

796796
if (responseLength == 1) {
797-
sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_RESP, findByTypeReq->startHandle, ATT_ECODE_ATTR_NOT_FOUND);
797+
sendError(connectionHandle, ATT_OP_FIND_BY_TYPE_REQ, findByTypeReq->startHandle, ATT_ECODE_ATTR_NOT_FOUND);
798798
} else {
799799
HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response);
800800
}
@@ -1561,7 +1561,7 @@ bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* d
15611561

15621562
for (int j = 0; j < characteristicCount; j++) {
15631563
BLERemoteCharacteristic* characteristic = service->characteristic(j);
1564-
BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j);
1564+
BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j + 1);
15651565

15661566
reqStartHandle = characteristic->valueHandle() + 1;
15671567
reqEndHandle = nextCharacteristic ? nextCharacteristic->valueHandle() : serviceEndHandle;

src/utility/ATT.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
#define ATT_CID 0x0004
2828

29-
#ifdef DM_CONN_MAX
29+
#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
30+
#define ATT_MAX_PEERS 7
31+
#elif DM_CONN_MAX
3032
#define ATT_MAX_PEERS DM_CONN_MAX // Mbed + Cordio
3133
#else
3234
#define ATT_MAX_PEERS 3

src/utility/GAP.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void GAPClass::setManufacturerData(const uint8_t manufacturerData[], int manufac
5656

5757
void GAPClass::setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength)
5858
{
59-
uint8_t tmpManufacturerData[manufacturerDataLength + 2];
59+
uint8_t* tmpManufacturerData = (uint8_t*)malloc(manufacturerDataLength + 2);
6060
tmpManufacturerData[0] = companyId & 0xff;
6161
tmpManufacturerData[1] = companyId >> 8;
6262
memcpy(&tmpManufacturerData[2], manufacturerData, manufacturerDataLength);
@@ -79,7 +79,7 @@ int GAPClass::advertise()
7979

8080
uint8_t type = (_connectable) ? 0x00 : (_localName ? 0x02 : 0x03);
8181

82-
_advertising = false;
82+
stopAdvertise();
8383

8484
if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) {
8585
return 0;
@@ -97,20 +97,20 @@ int GAPClass::advertise()
9797
BLEUuid uuid(_advertisedServiceUuid);
9898
int uuidLen = uuid.length();
9999

100-
advertisingData[3] = 1 + uuidLen;
101-
advertisingData[4] = (uuidLen > 2) ? 0x06 : 0x02;
102-
memcpy(&advertisingData[5], uuid.data(), uuidLen);
100+
advertisingData[advertisingDataLen++] = 1 + uuidLen;
101+
advertisingData[advertisingDataLen++] = (uuidLen > 2) ? 0x06 : 0x02;
102+
memcpy(&advertisingData[advertisingDataLen], uuid.data(), uuidLen);
103103

104-
advertisingDataLen += (2 + uuidLen);
104+
advertisingDataLen += uuidLen;
105105
} else if (_manufacturerData && _manufacturerDataLength) {
106-
advertisingData[3] = 1 + _manufacturerDataLength;
107-
advertisingData[4] = 0xff;
108-
memcpy(&advertisingData[5], _manufacturerData, _manufacturerDataLength);
106+
advertisingData[advertisingDataLen++] = 1 + _manufacturerDataLength;
107+
advertisingData[advertisingDataLen++] = 0xff;
108+
memcpy(&advertisingData[advertisingDataLen], _manufacturerData, _manufacturerDataLength);
109109

110-
advertisingDataLen += (2 + _manufacturerDataLength);
110+
advertisingDataLen += _manufacturerDataLength;
111111
}
112112

113-
if (_serviceData && _serviceDataLength > 0 && advertisingDataLen >= (_serviceDataLength + 4)) {
113+
if (_serviceData && _serviceDataLength > 0 && (sizeof(advertisingData) - advertisingDataLen) >= (_serviceDataLength + 4)) {
114114
advertisingData[advertisingDataLen++] = _serviceDataLength + 3;
115115
advertisingData[advertisingDataLen++] = 0x16;
116116

src/utility/GAP.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class GAPClass {
7777

7878
uint16_t _serviceDataUuid;
7979
const uint8_t* _serviceData;
80-
int _serviceDataLength;
80+
uint32_t _serviceDataLength;
8181

8282
BLEDeviceEventHandler _discoverEventHandler;
8383
BLELinkedList<BLEDevice*> _discoveredDevices;

0 commit comments

Comments
 (0)