Skip to content

Commit

Permalink
Merge pull request stm32duino#16 from cparata/master
Browse files Browse the repository at this point in the history
Align STM32duinoBLE to current ArduinoBLE master
  • Loading branch information
cparata authored Sep 24, 2020
2 parents e7e1bf7 + 14fd996 commit 61138fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/utility/ATT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/utility/ATT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/utility/GAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/utility/GAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GAPClass {

uint16_t _serviceDataUuid;
const uint8_t* _serviceData;
int _serviceDataLength;
uint32_t _serviceDataLength;

BLEDeviceEventHandler _discoverEventHandler;
BLELinkedList<BLEDevice*> _discoveredDevices;
Expand Down

0 comments on commit 61138fc

Please sign in to comment.