Skip to content

Align STM32duinoBLE to current ArduinoBLE master #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Central/Scan/Scan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/Central/ScanCallback/ScanCallback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
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