From 29861193f31221645a9b8c70fac8acc49e8ebb61 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Mon, 2 Nov 2020 15:30:38 +0100 Subject: [PATCH 001/112] Add enhanced advertising examples While the old way of preparing advertising data is still supported, an alternative enhanced method to build advertising packets is now available. It consists in defining and configuring an object of type 'BLEAdvertisingData' to build the desired packet. When it has been configured, by setting the appropriate parameters, it can be used to populate the advertising data packet or the scan response data packet. Following this way, the user can decide in which packet each parameter should be put. Also, it is now possible to configure an advertising packet (advertising or scan response) by passing a raw data packet. If an advertising packet has a raw data parameter set, all its other parameters will be ignored. Also, advertising parameters such as manufacturer data, service data or raw data should have a GLOBAL scope, because they are passed as pointers and are not copied internally. --- .../EnhancedAdvertising.ino | 44 +++++++++++++++++++ .../RawDataAdvertising/RawDataAdvertising.ino | 41 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino create mode 100644 examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino diff --git a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino new file mode 100644 index 00000000..979b69a8 --- /dev/null +++ b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -0,0 +1,44 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t manufactData[4] = {0x01, 0x02, 0x03, 0x04}; +const uint8_t serviceData[3] = {0x00, 0x01, 0x02}; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1); + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build scan response data packet + BLEAdvertisingData scanData; + // Set parameters for scan response packet + scanData.setLocalName("Test enhanced advertising"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + // Build advertising data packet + BLEAdvertisingData advData; + // Set parameters for advertising packet + advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData)); + advData.setAdvertisedService(myService); + advData.setAdvertisedServiceData(0xfff0, serviceData, sizeof(serviceData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + BLE.advertise(); + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} diff --git a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino new file mode 100644 index 00000000..d025dd62 --- /dev/null +++ b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -0,0 +1,41 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05}; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1); + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build advertising data packet + BLEAdvertisingData advData; + // If a packet has a raw data parameter, then all the other parameters of the packet will be ignored + advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + // Build scan response data packet + BLEAdvertisingData scanData; + scanData.setLocalName("Test advertising raw data"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + BLE.advertise(); + + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} From c66379882f727276b74c319c1ec9fa824fc96bf1 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Fri, 1 Jan 2021 11:22:34 +0000 Subject: [PATCH 002/112] Initial - encrypted read --- src/ArduinoBLE.h | 1 + src/BLEProperty.h | 40 ++- src/local/BLELocalDevice.cpp | 4 + src/local/BLELocalDevice.h | 1 + src/utility/ATT.cpp | 132 +++++++- src/utility/ATT.h | 23 +- src/utility/HCI.cpp | 571 ++++++++++++++++++++++++++++----- src/utility/HCI.h | 37 ++- src/utility/L2CAPSignaling.cpp | 204 +++++++++++- src/utility/L2CAPSignaling.h | 22 ++ src/utility/btct.cpp | 322 +++++++++++++++++++ src/utility/btct.h | 26 ++ 12 files changed, 1301 insertions(+), 82 deletions(-) create mode 100644 src/utility/btct.cpp create mode 100644 src/utility/btct.h diff --git a/src/ArduinoBLE.h b/src/ArduinoBLE.h index dc6e8188..588d5cb1 100644 --- a/src/ArduinoBLE.h +++ b/src/ArduinoBLE.h @@ -24,5 +24,6 @@ #include "BLEProperty.h" #include "BLEStringCharacteristic.h" #include "BLETypedCharacteristics.h" +#include "utility/btct.h" #endif diff --git a/src/BLEProperty.h b/src/BLEProperty.h index 6cdd888f..aeee4c85 100644 --- a/src/BLEProperty.h +++ b/src/BLEProperty.h @@ -17,6 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +// #include + #ifndef _BLE_PROPERTY_H_ #define _BLE_PROPERTY_H_ @@ -26,7 +28,43 @@ enum BLEProperty { BLEWriteWithoutResponse = 0x04, BLEWrite = 0x08, BLENotify = 0x10, - BLEIndicate = 0x20 + BLEIndicate = 0x20, + BLEAuth = 1 << 6, + BLEExtProp = 1 << 7, +}; + +#define ESP_GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) /* 0x01 */ /* relate to BTA_GATT_CHAR_PROP_BIT_BROADCAST in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_READ (1 << 1) /* 0x02 */ /* relate to BTA_GATT_CHAR_PROP_BIT_READ in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) /* 0x04 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE_NR in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_WRITE (1 << 3) /* 0x08 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_NOTIFY (1 << 4) /* 0x10 */ /* relate to BTA_GATT_CHAR_PROP_BIT_NOTIFY in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_INDICATE (1 << 5) /* 0x20 */ /* relate to BTA_GATT_CHAR_PROP_BIT_INDICATE in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_AUTH (1 << 6) /* 0x40 */ /* relate to BTA_GATT_CHAR_PROP_BIT_AUTH in bta/bta_gatt_api.h */ +#define ESP_GATT_CHAR_PROP_BIT_EXT_PROP (1 << 7) /* 0x80 */ /* relate to BTA_GATT_CHAR_PROP_BIT_EXT_PROP in bta/bta_gatt_api.h */ + +#define ESP_GATT_PERM_READ (1 << 0) /* bit 0 - 0x0001 */ /* relate to BTA_GATT_PERM_READ in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_READ_ENCRYPTED (1 << 1) /* bit 1 - 0x0002 */ /* relate to BTA_GATT_PERM_READ_ENCRYPTED in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_READ_ENC_MITM (1 << 2) /* bit 2 - 0x0004 */ /* relate to BTA_GATT_PERM_READ_ENC_MITM in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_WRITE (1 << 4) /* bit 4 - 0x0010 */ /* relate to BTA_GATT_PERM_WRITE in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_WRITE_ENCRYPTED (1 << 5) /* bit 5 - 0x0020 */ /* relate to BTA_GATT_PERM_WRITE_ENCRYPTED in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_WRITE_ENC_MITM (1 << 6) /* bit 6 - 0x0040 */ /* relate to BTA_GATT_PERM_WRITE_ENC_MITM in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_WRITE_SIGNED (1 << 7) /* bit 7 - 0x0080 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_WRITE_SIGNED_MITM (1 << 8) /* bit 8 - 0x0100 */ /* relate to BTA_GATT_PERM_WRITE_SIGNED_MITM in bta/bta_gatt_api.h */ +#define ESP_GATT_PERM_READ_AUTHORIZATION (1 << 9) /* bit 9 - 0x0200 */ +#define ESP_GATT_PERM_WRITE_AUTHORIZATION (1 << 10) /* bit 10 - 0x0400 */ + +enum BLE_GATT_PERM_ { + READ = 1 << 0, + READ_ENCRYPTED = 1 << 1, + READ_ENC_MITM = 1 << 2, + WRITE = 1 << 4, + WRITE_ENCRYPTED = 1 << 5, + WRITE_ENC_MITM = 1 << 6, + WRITE_SIGNED = 1 << 7, + WRITE_SIGNED_MITM = 1 << 8, + READ_AUTHORIZATION = 1 << 9, + WRITE_AUTHORIZATION = 1 << 10, }; + #endif diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 57477e23..e83c4b0d 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -107,6 +107,10 @@ int BLELocalDevice::begin() end(); return 0; } + if (HCI.setLeEventMask(0x00000000000001FF) != 0) { + end(); + return 0; + } uint16_t pktLen; uint8_t maxPkt; diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 20837c14..1a927420 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -74,6 +74,7 @@ class BLELocalDevice { void debug(Stream& stream); void noDebug(); + uint8_t BDaddress[6]; private: }; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 2696960e..af0129a7 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -95,6 +95,7 @@ ATTClass::ATTClass() : memset(_peers[i].address, 0x00, sizeof(_peers[i].address)); _peers[i].mtu = 23; _peers[i].device = NULL; + _peers[i].encryption = 0x0; } memset(_eventHandlers, 0x00, sizeof(_eventHandlers)); @@ -267,12 +268,22 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ uint16_t mtu = this->mtu(connectionHandle); +#ifdef _BLE_TRACE_ + Serial.print("data opcode: 0x"); + Serial.println(opcode, HEX); +#endif switch (opcode) { case ATT_OP_ERROR: +#ifdef _BLE_TRACE_ + Serial.println("[Info] data error"); +#endif error(connectionHandle, dlen, data); break; case ATT_OP_MTU_REQ: +#ifdef _BLE_TRACE_ + Serial.println("MTU"); +#endif mtuReq(connectionHandle, dlen, data); break; @@ -281,6 +292,9 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ break; case ATT_OP_FIND_INFO_REQ: +#ifdef _BLE_TRACE_ + Serial.println("Find info"); +#endif findInfoReq(connectionHandle, mtu, dlen, data); break; @@ -293,6 +307,9 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ break; case ATT_OP_READ_BY_TYPE_REQ: +#ifdef _BLE_TRACE_ + Serial.println("By type"); +#endif readByTypeReq(connectionHandle, mtu, dlen, data); break; @@ -319,6 +336,9 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ case ATT_OP_WRITE_REQ: case ATT_OP_WRITE_CMD: +#ifdef _BLE_TRACE_ + Serial.println("Write req"); +#endif writeReqOrCmd(connectionHandle, mtu, opcode, dlen, data); break; @@ -346,6 +366,9 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ case ATT_OP_READ_MULTI_REQ: case ATT_OP_SIGNED_WRITE_CMD: default: +#ifdef _BLE_TRACE_ + Serial.println("[Info] Unhandled dara"); +#endif sendError(connectionHandle, opcode, 0x00, ATT_ECODE_REQ_NOT_SUPP); break; } @@ -398,6 +421,10 @@ void ATTClass::removeConnection(uint16_t handle, uint8_t /*reason*/) _peers[peerIndex].addressType = 0x00; memset(_peers[peerIndex].address, 0x00, sizeof(_peers[peerIndex].address)); _peers[peerIndex].mtu = 23; + _peers[peerIndex].encryption = PEER_ENCRYPTION::NO_ENCRYPTION; + _peers[peerIndex].IOCap[0] = 0; + _peers[peerIndex].IOCap[1] = 0; + _peers[peerIndex].IOCap[2] = 0; if (_peers[peerIndex].device) { delete _peers[peerIndex].device; @@ -807,6 +834,14 @@ void ATTClass::readByGroupReq(uint16_t connectionHandle, uint16_t mtu, uint8_t d uint16_t endHandle; uint16_t uuid; } *readByGroupReq = (ReadByGroupReq*)data; +#ifdef _BLE_TRACE_ + Serial.print("readByGroupReq: start: 0x"); + Serial.println(readByGroupReq->startHandle,HEX); + Serial.print("readByGroupReq: end: 0x"); + Serial.println(readByGroupReq->endHandle,HEX); + Serial.print("readByGroupReq: UUID: 0x"); + Serial.println(readByGroupReq->uuid,HEX); +#endif if (dlen != sizeof(ReadByGroupReq) || (readByGroupReq->uuid != BLETypeService && readByGroupReq->uuid != 0x2801)) { sendError(connectionHandle, ATT_OP_READ_BY_GROUP_REQ, readByGroupReq->startHandle, ATT_ECODE_UNSUPP_GRP_TYPE); @@ -819,7 +854,10 @@ void ATTClass::readByGroupReq(uint16_t connectionHandle, uint16_t mtu, uint8_t d response[0] = ATT_OP_READ_BY_GROUP_RESP; response[1] = 0x00; responseLength = 2; - +#ifdef _BLE_TRACE_ + Serial.print("readByGroupReq: attrcount: "); + Serial.println(GATT.attributeCount()); +#endif for (uint16_t i = (readByGroupReq->startHandle - 1); i < GATT.attributeCount() && i <= (readByGroupReq->endHandle - 1); i++) { BLELocalAttribute* attribute = GATT.attribute(i); @@ -906,6 +944,8 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ return; } } + /// if auth error, hold the response in a buffer. + bool holdResponse = false; uint16_t handle = *(uint16_t*)data; uint16_t offset = (opcode == ATT_OP_READ_REQ) ? 0 : *(uint16_t*)&data[sizeof(handle)]; @@ -962,6 +1002,11 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ sendError(connectionHandle, opcode, handle, ATT_ECODE_READ_NOT_PERM); return; } + // If characteristic requires encryption send error & hold response until encrypted + if ((characteristic->properties() & BLEAuth) > 0 && (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES)==0) { + holdResponse = true; + sendError(connectionHandle, opcode, handle, ATT_ECODE_INSUFF_ENC); + } uint16_t valueLength = characteristic->valueLength(); @@ -994,8 +1039,12 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ memcpy(&response[responseLength], descriptor->value() + offset, valueLength); responseLength += valueLength; } - - HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response); + if(holdResponse){ + memcpy(holdBuffer, response, responseLength); + holdBufferSize = responseLength; + }else{ + HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response); + } } void ATTClass::readResp(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) @@ -1687,4 +1736,81 @@ void ATTClass::writeCmd(uint16_t connectionHandle, uint16_t handle, const uint8_ sendReq(connectionHandle, &writeReq, 3 + dataLen, NULL); } +// Set encryption state for a peer +int ATTClass::setPeerEncryption(uint16_t connectionHandle, uint8_t encryption){ + for(int i=0; i 0){ + return _peers[i].connectionHandle; + } + } + return ATT_MAX_PEERS + 1; +} +// Get the encryption state for a particular peer / connection handle +uint8_t ATTClass::getPeerEncryption(uint16_t connectionHandle) { + for(int i=0; i ", sizeof(aclHdr) + plen, txBuffer); } +#ifdef _BLE_TRACE_ + Serial.print("Data tx -> "); + for(int i=0; i< sizeof(aclHdr) + plen;i++){ + Serial.print(" 0x"); + Serial.print(txBuffer[i],HEX); + } + Serial.println("."); +#endif _pendingPkt++; HCITransport.write(txBuffer, sizeof(aclHdr) + plen); @@ -476,7 +521,15 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) if (_debug) { dumpPkt("HCI COMMAND TX -> ", sizeof(pktHdr) + plen, txBuffer); } - +#ifdef _BLE_TRACE_ + Serial.print("Command tx -> "); + for(int i=0; i< sizeof(pktHdr) + plen;i++){ + Serial.print(" 0x"); + Serial.print(txBuffer[i],HEX); + + } + Serial.println(""); +#endif HCITransport.write(txBuffer, sizeof(pktHdr) + plen); _cmdCompleteOpcode = 0xffff; @@ -498,6 +551,9 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t cid; } *aclHdr = (HCIACLHdr*)pdata; +#ifdef _BLE_TRACE_ + Serial.println("Received data"); +#endif uint16_t aclFlags = (aclHdr->handle & 0xf000) >> 12; if ((aclHdr->dlen - 4) != aclHdr->len) { @@ -530,8 +586,18 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); } } else if (aclHdr->cid == SIGNALING_CID) { +#ifdef _BLE_TRACE_ + Serial.println("Signalling"); +#endif L2CAPSignaling.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); - } else { + } else if (aclHdr->cid == SECURITY_CID){ + // Security manager +#ifdef _BLE_TRACE_ + Serial.println("Security data"); +#endif + L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); + + }else { struct __attribute__ ((packed)) { uint8_t op; uint8_t id; @@ -540,6 +606,10 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t localCid; uint16_t remoteCid; } l2capRejectCid= { 0x01, 0x00, 0x006, 0x0002, aclHdr->cid, 0x0000 }; +#ifdef _BLE_TRACE_ + Serial.print("rejecting packet cid: 0x"); + Serial.println(aclHdr->cid,HEX); +#endif sendAclPkt(aclHdr->handle & 0x0fff, 0x0005, sizeof(l2capRejectCid), &l2capRejectCid); } @@ -560,8 +630,13 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t evt; uint8_t plen; } *eventHdr = (HCIEventHdr*)pdata; +#ifdef _BLE_TRACE_ + Serial.print("HCI event: "); + Serial.println(eventHdr->evt, HEX); +#endif - if (eventHdr->evt == EVT_DISCONN_COMPLETE) { + if (eventHdr->evt == EVT_DISCONN_COMPLETE) + { struct __attribute__ ((packed)) DisconnComplete { uint8_t status; uint16_t handle; @@ -572,99 +647,447 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) L2CAPSignaling.removeConnection(disconnComplete->handle, disconnComplete->reason); HCI.leSetAdvertiseEnable(0x01); - } else if (eventHdr->evt == EVT_CMD_COMPLETE) { + } + else if (eventHdr->evt == EVT_ENCRYPTION_CHANGE) + { + struct __attribute__ ((packed)) EncryptionChange { + uint8_t status; + uint16_t connectionHandle; + uint8_t enabled; + } *encryptionChange = (EncryptionChange*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.println("[Info] Encryption changed"); + Serial.print("status : "); + btct.printBytes(&encryptionChange->status,1); + Serial.print("handle : "); + btct.printBytes((uint8_t*)&encryptionChange->connectionHandle,2); + Serial.print("enabled: "); + btct.printBytes(&encryptionChange->enabled,1); +#endif + if(encryptionChange->enabled>0){ + ATT.setPeerEncryption(encryptionChange->connectionHandle, PEER_ENCRYPTION::ENCRYPTED_AES); + }else{ + ATT.setPeerEncryption(encryptionChange->connectionHandle, PEER_ENCRYPTION::NO_ENCRYPTION); + } + if(ATT.holdBufferSize>0){ + HCI.sendAclPkt(encryptionChange->connectionHandle, ATT_CID, ATT.holdBufferSize, ATT.holdBuffer); + ATT.holdBufferSize = 0; + } + } + else if (eventHdr->evt == EVT_CMD_COMPLETE) + { struct __attribute__ ((packed)) CmdComplete { uint8_t ncmd; uint16_t opcode; uint8_t status; } *cmdCompleteHeader = (CmdComplete*)&pdata[sizeof(HCIEventHdr)]; - +#ifdef _BLE_TRACE_ + Serial.print("E ncmd: 0x"); + Serial.println(cmdCompleteHeader->ncmd,HEX); + Serial.print("E opcode: 0x"); + Serial.println(cmdCompleteHeader->opcode, HEX); + Serial.print("E status: 0x"); + Serial.println(cmdCompleteHeader->status, HEX); +#endif _cmdCompleteOpcode = cmdCompleteHeader->opcode; _cmdCompleteStatus = cmdCompleteHeader->status; _cmdResponseLen = pdata[1] - sizeof(CmdComplete); _cmdResponse = &pdata[sizeof(HCIEventHdr) + sizeof(CmdComplete)]; - } else if (eventHdr->evt == EVT_CMD_STATUS) { + } + else if (eventHdr->evt == EVT_CMD_STATUS) + { struct __attribute__ ((packed)) CmdStatus { uint8_t status; uint8_t ncmd; uint16_t opcode; } *cmdStatusHeader = (CmdStatus*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.print("F n cmd: 0x"); + Serial.println(cmdStatusHeader->ncmd, HEX); + Serial.print("F status: 0x"); + Serial.println(cmdStatusHeader->status, HEX); + Serial.print("F opcode: 0x"); + Serial.println(cmdStatusHeader->opcode, HEX); +#endif _cmdCompleteOpcode = cmdStatusHeader->opcode; _cmdCompleteStatus = cmdStatusHeader->status; _cmdResponseLen = 0; - } else if (eventHdr->evt == EVT_NUM_COMP_PKTS) { + } + else if (eventHdr->evt == EVT_NUM_COMP_PKTS) + { uint8_t numHandles = pdata[sizeof(HCIEventHdr)]; uint16_t* data = (uint16_t*)&pdata[sizeof(HCIEventHdr) + sizeof(numHandles)]; for (uint8_t i = 0; i < numHandles; i++) { handleNumCompPkts(data[0], data[1]); - +#ifdef _BLE_TRACE_ + Serial.print("Outstanding packets: "); + Serial.println(_pendingPkt); + Serial.print("Data[0]: 0x"); + Serial.println(data[0]); + Serial.print("Data[1]: 0x"); + Serial.println(data[1]); +#endif data += 2; } - } else if (eventHdr->evt == EVT_LE_META_EVENT) { + } + else if(eventHdr->evt == 0x10) + { + struct __attribute__ ((packed)) CmdHardwareError { + uint8_t hardwareCode; + } *cmdHardwareError = (CmdHardwareError*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.print("Bluetooth hardware error."); + Serial.print(" Code: 0x"); + Serial.println(cmdHardwareError->hardwareCode, HEX); +#endif + } + else if (eventHdr->evt == EVT_LE_META_EVENT) + { struct __attribute__ ((packed)) LeMetaEventHeader { uint8_t subevent; } *leMetaHeader = (LeMetaEventHeader*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.print("\tSubEvent: 0x"); + Serial.println(leMetaHeader->subevent,HEX); +#endif + switch((LE_META_EVENT)leMetaHeader->subevent){ + case CONN_COMPLETE:{ + struct __attribute__ ((packed)) EvtLeConnectionComplete { + uint8_t status; + uint16_t handle; + uint8_t role; + uint8_t peerBdaddrType; + uint8_t peerBdaddr[6]; + uint16_t interval; + uint16_t latency; + uint16_t supervisionTimeout; + uint8_t masterClockAccuracy; + } *leConnectionComplete = (EvtLeConnectionComplete*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; + + if (leConnectionComplete->status == 0x00) { + ATT.addConnection(leConnectionComplete->handle, + leConnectionComplete->role, + leConnectionComplete->peerBdaddrType, + leConnectionComplete->peerBdaddr, + leConnectionComplete->interval, + leConnectionComplete->latency, + leConnectionComplete->supervisionTimeout, + leConnectionComplete->masterClockAccuracy); + + L2CAPSignaling.addConnection(leConnectionComplete->handle, + leConnectionComplete->role, + leConnectionComplete->peerBdaddrType, + leConnectionComplete->peerBdaddr, + leConnectionComplete->interval, + leConnectionComplete->latency, + leConnectionComplete->supervisionTimeout, + leConnectionComplete->masterClockAccuracy); + } + break; + } + case ADVERTISING_REPORT:{ + struct __attribute__ ((packed)) EvtLeAdvertisingReport { + uint8_t status; + uint8_t type; + uint8_t peerBdaddrType; + uint8_t peerBdaddr[6]; + uint8_t eirLength; + uint8_t eirData[31]; + } *leAdvertisingReport = (EvtLeAdvertisingReport*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; + + if (leAdvertisingReport->status == 0x01) { + // last byte is RSSI + int8_t rssi = leAdvertisingReport->eirData[leAdvertisingReport->eirLength]; + + GAP.handleLeAdvertisingReport(leAdvertisingReport->type, + leAdvertisingReport->peerBdaddrType, + leAdvertisingReport->peerBdaddr, + leAdvertisingReport->eirLength, + leAdvertisingReport->eirData, + rssi); + } + break; + } + case LONG_TERM_KEY_REQUEST: + { + struct __attribute__ ((packed)) LTKRequest + { + uint8_t subEventCode; + uint16_t connectionHandle; + uint8_t randomNumber[8]; + uint8_t encryptedDiversifier[2]; + } *ltkRequest = (LTKRequest*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.println("LTK request received"); + Serial.print("Connection Handle: "); + btct.printBytes((uint8_t*)<kRequest->connectionHandle,2); + Serial.print("Random Number : "); + btct.printBytes(ltkRequest->randomNumber,8); + Serial.print("EDIV : "); + btct.printBytes(ltkRequest->encryptedDiversifier,2); +#endif - if (leMetaHeader->subevent == EVT_LE_CONN_COMPLETE) { - struct __attribute__ ((packed)) EvtLeConnectionComplete { - uint8_t status; - uint16_t handle; - uint8_t role; - uint8_t peerBdaddrType; - uint8_t peerBdaddr[6]; - uint16_t interval; - uint16_t latency; - uint16_t supervisionTimeout; - uint8_t masterClockAccuracy; - } *leConnectionComplete = (EvtLeConnectionComplete*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; - - if (leConnectionComplete->status == 0x00) { - ATT.addConnection(leConnectionComplete->handle, - leConnectionComplete->role, - leConnectionComplete->peerBdaddrType, - leConnectionComplete->peerBdaddr, - leConnectionComplete->interval, - leConnectionComplete->latency, - leConnectionComplete->supervisionTimeout, - leConnectionComplete->masterClockAccuracy); - - L2CAPSignaling.addConnection(leConnectionComplete->handle, - leConnectionComplete->role, - leConnectionComplete->peerBdaddrType, - leConnectionComplete->peerBdaddr, - leConnectionComplete->interval, - leConnectionComplete->latency, - leConnectionComplete->supervisionTimeout, - leConnectionComplete->masterClockAccuracy); + // Send our LTK back + struct __attribute__ ((packed)) LTKReply + { + uint16_t connectionHandle; + uint8_t LTK[16]; + } ltkReply = {0,0}; + ltkReply.connectionHandle = ATT.getPeerEncrptingConnectionHandle(); + for(int i=0; i<16; i++) ltkReply.LTK[15-i] = HCI.LTK[i]; + int result = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::LONG_TERM_KEY_REPLY,sizeof(ltkReply), <kReply); + +#ifdef _BLE_TRACE_ + Serial.println("Sending LTK as: "); + btct.printBytes(ltkReply.LTK,16); +#endif + + if(result == 0){ + struct __attribute__ ((packed)) LTKReplyResult + { + uint8_t status; + uint16_t connectionHandle; + } ltkReplyResult = {0,0}; + memcpy(<kReplyResult, _cmdResponse, 3); + +#ifdef _BLE_TRACE_ + Serial.println("LTK send success"); + Serial.print("status : "); + btct.printBytes(<kReplyResult.status,1); + Serial.print("Conn Handle: "); + btct.printBytes((uint8_t*)<kReplyResult.connectionHandle,2); +#endif + }else{ +#ifdef _BLE_TRACE_ + Serial.print("Failed to send LTK...: "); + btct.printBytes((uint8_t*)&result,2); +#endif + } + break; } - } else if (leMetaHeader->subevent == EVT_LE_ADVERTISING_REPORT) { - struct __attribute__ ((packed)) EvtLeAdvertisingReport { - uint8_t status; - uint8_t type; - uint8_t peerBdaddrType; - uint8_t peerBdaddr[6]; - uint8_t eirLength; - uint8_t eirData[31]; - } *leAdvertisingReport = (EvtLeAdvertisingReport*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; - - if (leAdvertisingReport->status == 0x01) { - // last byte is RSSI - int8_t rssi = leAdvertisingReport->eirData[leAdvertisingReport->eirLength]; - - GAP.handleLeAdvertisingReport(leAdvertisingReport->type, - leAdvertisingReport->peerBdaddrType, - leAdvertisingReport->peerBdaddr, - leAdvertisingReport->eirLength, - leAdvertisingReport->eirData, - rssi); + case REMOTE_CONN_PARAM_REQ: + { + struct __attribute__ ((packed)) RemoteConnParamReq { + uint8_t subEventCode; + uint16_t connectionHandle; + uint16_t intervalMin; + uint16_t intervalMax; + uint16_t latency; + uint16_t timeOut; + } *remoteConnParamReq = (RemoteConnParamReq*)&pdata[sizeof(HCIEventHdr)]; +#ifdef _BLE_TRACE_ + Serial.println("--- Remtoe conn param req"); + Serial.print("Handle : "); + btct.printBytes((uint8_t*)&remoteConnParamReq->connectionHandle,2); + Serial.print("Interval min: "); + btct.printBytes((uint8_t*)&remoteConnParamReq->intervalMin,2); + Serial.print("Interval max: "); + btct.printBytes((uint8_t*)&remoteConnParamReq->intervalMax,2); + Serial.print("Latency : "); + btct.printBytes((uint8_t*)&remoteConnParamReq->latency,2); + Serial.print("Timeout : "); + btct.printBytes((uint8_t*)&remoteConnParamReq->timeOut,2); +#endif + + struct __attribute__ ((packed)) RemoteConnParamReqReply { + uint16_t connectionHandle; + uint16_t intervalMin; + uint16_t intervalMax; + uint16_t latency; + uint16_t timeOut; + uint16_t minLength; + uint16_t maxLength; + } remoteConnParamReqReply; + memcpy(&remoteConnParamReqReply, &remoteConnParamReq->connectionHandle, sizeof(remoteConnParamReq-1)); + remoteConnParamReqReply.minLength = 0x000F; + remoteConnParamReqReply.maxLength = 0x0FFF; + sendCommand(OGF_LE_CTL << 10 | 0x20, sizeof(remoteConnParamReqReply), &remoteConnParamReqReply); + break; + } + case READ_LOCAL_P256_COMPLETE: + { + struct __attribute__ ((packed)) EvtReadLocalP256Complete{ + uint8_t subEventCode; + uint8_t status; + uint8_t localPublicKey[64]; + } *evtReadLocalP256Complete = (EvtReadLocalP256Complete*)&pdata[sizeof(HCIEventHdr)]; + if(evtReadLocalP256Complete->status == 0x0){ +#ifdef _BLE_TRACE_ + Serial.println("Key read success"); +#endif + struct __attribute__ ((packed)) PairingPublicKey + { + uint8_t code; + uint8_t publicKey[64]; + } pairingPublicKey = {CONNECTION_PAIRING_PUBLIC_KEY,0}; + memcpy(pairingPublicKey.publicKey,evtReadLocalP256Complete->localPublicKey,64); + + // Send the local public key to the remote + uint16_t connectionHandle = ATT.getPeerEncrptingConnectionHandle(); + if(connectionHandle>ATT_MAX_PEERS){ +#ifdef _BLE_TRACE_ + Serial.println("failed to find connection handle"); +#endif + break; + } + HCI.sendAclPkt(connectionHandle,SECURITY_CID,sizeof(PairingPublicKey),&pairingPublicKey); + uint8_t encryption = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::SENT_PUBKEY; + ATT.setPeerEncryption(connectionHandle, encryption); + + + uint8_t Z = 0; + for(int i=0; i<16; i++){ + Nb[i] = rand(); //// Should use ESP or ECCx08 + } +#ifdef _BLE_TRACE_ + Serial.print("nb: "); + btct.printBytes(Nb, 16); +#endif + struct __attribute__ ((packed)) F4Params + { + uint8_t U[32]; + uint8_t V[32]; + uint8_t Z; + } f4Params = {0,0,Z}; + for(int i=0; i<32; i++){ + f4Params.U[31-i] = pairingPublicKey.publicKey[i]; + f4Params.V[31-i] = HCI.remotePublicKeyBuffer[i]; + } + + struct __attribute__ ((packed)) PairingConfirm + { + uint8_t code; + uint8_t cb[16]; + } pairingConfirm = {CONNECTION_PAIRING_CONFIRM,0}; + + btct.AES_CMAC(Nb,(unsigned char *)&f4Params,sizeof(f4Params),pairingConfirm.cb); + +#ifdef _BLE_TRACE_ + Serial.print("cb: "); + btct.printBytes(pairingConfirm.cb, 16); +#endif + uint8_t cb_temp[sizeof(pairingConfirm.cb)]; + for(int i=0; istatus,HEX); + for(int i=0; i<64; i++){ + Serial.print(" 0x"); + Serial.print(evtReadLocalP256Complete->localPublicKey[i],HEX); + } + Serial.println("."); +#endif + } + break; + } + case GENERATE_DH_KEY_COMPLETE: + { + struct __attribute__ ((packed)) EvtLeDHKeyComplete{ + uint8_t subEventCode; + uint8_t status; + uint8_t DHKey[32]; + } *evtLeDHKeyComplete = (EvtLeDHKeyComplete*)&pdata[sizeof(HCIEventHdr)]; + if(evtLeDHKeyComplete->status == 0x0){ +#ifdef _BLE_TRACE_ + Serial.println("DH key generated"); +#endif + uint16_t connectionHandle = ATT.getPeerEncrptingConnectionHandle(); + if(connectionHandle>ATT_MAX_PEERS){ +#ifdef _BLE_TRACE_ + Serial.println("Failed to find connection handle DH key check"); +#endif + break; + } + + uint8_t encryption = ATT.getPeerEncryption(connectionHandle); + + for(int i=0; i<32; i++) DHKey[31-i] = evtLeDHKeyComplete->DHKey[i]; + +#ifdef _BLE_TRACE_ + Serial.println("Stored our DHKey:"); + btct.printBytes(DHKey,32); +#endif + encryption |= PEER_ENCRYPTION::DH_KEY_CALULATED; + ATT.setPeerEncryption(connectionHandle, encryption); +#ifdef _BLE_TRACE_ + if(encryption | PEER_ENCRYPTION::RECEIVED_DH_CHECK){ + Serial.println("Recieved DHKey check already so calculate f5, f6."); + }else{ + Serial.println("Waiting on other DHKey check before calculating."); + } + }else{ + Serial.print("Key generation error: 0x"); + Serial.println(evtLeDHKeyComplete->status, HEX); +#endif + } + break; + } + default: + { +#ifdef _BLE_TRACE_ + Serial.println("[Info] Unhandled meta event"); +#endif } } + }else{ +#ifdef _BLE_TRACE_ + Serial.println("[Info] Unhandled event"); +#endif } } +int HCIClass::leEncrypt(uint8_t* key, uint8_t* plaintext, uint8_t* status, uint8_t* ciphertext){ + struct __attribute__ ((packed)) LeEncryptCommand + { + uint8_t key[16]; + uint8_t plaintext[16]; + } leEncryptCommand = {0,0}; + for(int i=0; i<16; i++){ + leEncryptCommand.key[15-i] = key[i]; + leEncryptCommand.plaintext[15-i] = plaintext[i]; + } + + int res = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::ENCRYPT, sizeof(leEncryptCommand), &leEncryptCommand); + if(res == 0){ +#ifdef _BLE_TRACE_ + Serial.print("Copying from command Response length: "); + Serial.println(_cmdResponseLen); + Serial.println("."); + for(int i=0; i<20; i++){ + Serial.print(" 0x"); + Serial.print(_cmdResponse[i],HEX); + } + Serial.println("."); +#endif + for(int i=0; i<16; i++){ + ciphertext[15-i] = _cmdResponse[i]; + } + return 1; + } +#ifdef _BLE_TRACE_ + Serial.print("Error with AES: 0x"); + Serial.println(res, HEX); +#endif + return res; +} void HCIClass::dumpPkt(const char* prefix, uint8_t plen, uint8_t pdata[]) { diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 86ec679c..c58b7572 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -22,6 +22,30 @@ #include +#define OGF_LINK_CTL 0x01 +#define OGF_HOST_CTL 0x03 +#define OGF_INFO_PARAM 0x04 +#define OGF_STATUS_PARAM 0x05 +#define OGF_LE_CTL 0x08 + +enum LE_COMMAND { + ENCRYPT = 0x0017, + LONG_TERM_KEY_REPLY = 0x001A, + READ_LOCAL_P256 = 0x0025, + GENERATE_DH_KEY_V1 = 0x0026, + GENERATE_DH_KEY_V2 = 0x005E +}; +enum LE_META_EVENT { + CONN_COMPLETE = 0x01, + ADVERTISING_REPORT = 0x02, + LONG_TERM_KEY_REQUEST = 0x05, + REMOTE_CONN_PARAM_REQ = 0x06, + READ_LOCAL_P256_COMPLETE = 0x08, + GENERATE_DH_KEY_COMPLETE = 0x09 +}; +String metaEventToString(LE_META_EVENT event); +String commandToString(LE_COMMAND command); + class HCIClass { public: HCIClass(); @@ -37,10 +61,12 @@ class HCIClass { int readLocalVersion(uint8_t& hciVer, uint16_t& hciRev, uint8_t& lmpVer, uint16_t& manufacturer, uint16_t& lmpSubVer); int readBdAddr(uint8_t addr[6]); + int readBdAddr(); int readRssi(uint16_t handle); int setEventMask(uint64_t eventMask); + int setLeEventMask(uint64_t leEventMask); int readLeBufferSize(uint16_t& pktLen, uint8_t& maxPkt); int leSetRandomAddress(uint8_t addr[6]); @@ -62,7 +88,7 @@ class HCIClass { int leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t supervisionTimeout); int leCancelConn(); - + int leEncrypt(uint8_t* Key, uint8_t* plaintext, uint8_t* status, uint8_t* ciphertext); int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data); @@ -71,8 +97,15 @@ class HCIClass { void debug(Stream& stream); void noDebug(); -private: + // TODO: Send command be private again & use ATT implementation within ATT. int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); + uint8_t remotePublicKeyBuffer[64]; + uint8_t Na[16]; + uint8_t Nb[16]; + uint8_t DHKey[32]; + uint8_t localAddr[6]; + uint8_t LTK[16]; +private: void handleAclDataPkt(uint8_t plen, uint8_t pdata[]); void handleNumCompPkts(uint16_t handle, uint16_t numPkts); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index f650cab2..45208514 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -18,7 +18,8 @@ */ #include "HCI.h" - +#include "ATT.h" +#include "btct.h" #include "L2CAPSignaling.h" #define CONNECTION_PARAMETER_UPDATE_REQUEST 0x12 @@ -97,6 +98,207 @@ void L2CAPSignalingClass::handleData(uint16_t connectionHandle, uint8_t dlen, ui connectionParameterUpdateResponse(connectionHandle, identifier, length, data); } } +void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) +{ + struct __attribute__ ((packed)) L2CAPSignalingHdr { + uint8_t code; + uint8_t data[64]; + } *l2capSignalingHdr = (L2CAPSignalingHdr*)data; +#ifdef _BLE_TRACE_ + Serial.print("dlen: "); + Serial.println(dlen); +#endif + uint8_t code = l2capSignalingHdr->code; + +#ifdef _BLE_TRACE_ + Serial.print("handleSecurityData: code: 0x"); + Serial.println(code, HEX); + Serial.print("rx security:"); + btct.printBytes(data,dlen); +#endif + if (code == CONNECTION_PAIRING_REQUEST) { + // 0x1 + struct __attribute__ ((packed)) PairingRequest { + uint8_t ioCapability; + uint8_t oobDataFlag; + uint8_t authReq; + uint8_t maxEncSize; + uint8_t initiatorKeyDistribution; + uint8_t responderKeyDistribution; + } *pairingRequest = (PairingRequest*)l2capSignalingHdr->data; + + uint8_t peerIOCap[3]; + peerIOCap[0] = pairingRequest->authReq; + peerIOCap[1] = pairingRequest->oobDataFlag; + peerIOCap[2] = pairingRequest->ioCapability; + ATT.setPeerIOCap(connectionHandle, peerIOCap); + + struct __attribute__ ((packed)) PairingResponse { + uint8_t code; + uint8_t ioCapability; + uint8_t oobDataFlag; + uint8_t authReq; + uint8_t maxEncSize; + uint8_t initiatorKeyDistribution; + uint8_t responderKeyDistribution; + } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, 0b1011, 0b1011}; + + HCI.sendAclPkt(connectionHandle, 0x06, sizeof(response), &response); + } + else if (code == CONNECTION_PAIRING_RANDOM) + { + struct __attribute__ ((packed)) PairingRandom { + uint8_t Na[16]; + } *pairingRandom = (PairingRandom*)l2capSignalingHdr->data; + for(int i=0; i<16; i++){ + HCI.Na[15-i] = pairingRandom->Na[i]; + } +#ifdef _BLE_TRACE_ + Serial.println("[Info] Pairing random."); +#endif + struct __attribute__ ((packed)) PairingResponse { + uint8_t code; + uint8_t Nb[16]; + } response = { CONNECTION_PAIRING_RANDOM, 0}; + for(int i=0; i< 16; i++) response.Nb[15-i] = HCI.Nb[i]; + + HCI.sendAclPkt(connectionHandle, 0x06, sizeof(response), &response); + } + else if (code == CONNECTION_PAIRING_RESPONSE) + { + } + else if(code == CONNECTION_PAIRING_FAILED) + { + struct __attribute__ ((packed)) PairingFailed + { + uint8_t code; + uint8_t reason; + } *pairingFailed = (PairingFailed*)data; +#ifdef _BLE_TRACE_ + Serial.print("Pairing failed with code: 0x"); + Serial.println(pairingFailed->reason,HEX); +#endif + } + else if (code == CONNECTION_PAIRING_PUBLIC_KEY){ + /// Received a public key + struct __attribute__ ((packed)) ConnectionPairingPublicKey { + uint8_t x[32]; + uint8_t y[32]; + } *connectionPairingPublicKey = (ConnectionPairingPublicKey*)l2capSignalingHdr->data; + struct __attribute__ ((packed)) GenerateDHKeyCommand { + uint8_t x[32]; + uint8_t y[32]; + } generateDHKeyCommand = { + 0x00, + 0x00, + }; + memcpy(generateDHKeyCommand.x,connectionPairingPublicKey->x,32); + memcpy(generateDHKeyCommand.y,connectionPairingPublicKey->y,32); + struct __attribute__ ((packed)) ReadPublicKeyCommand { + uint8_t code; + } readPublicKeyCommand = { + LE_COMMAND::READ_LOCAL_P256, + }; + + if(ATT.setPeerEncryption(connectionHandle,PEER_ENCRYPTION::REQUESTED_ENCRYPTION)){ +#ifdef _BLE_TRACE_ + Serial.println("[Info] Pairing public key"); + Serial.println("Requested encryption stored."); +#endif + }else{ +#ifdef _BLE_TRACE_ + Serial.println("[Info] Pairing public key"); + Serial.print("Failed to store encryption request with handle: 0x"); + Serial.println(connectionHandle,HEX); +#endif + } + + memcpy(HCI.remotePublicKeyBuffer,&generateDHKeyCommand,sizeof(generateDHKeyCommand)); + HCI.sendCommand( (OGF_LE_CTL << 10 )| LE_COMMAND::READ_LOCAL_P256, 0); + } + else if(code == CONNECTION_PAIRING_DHKEY_CHECK) + { + uint8_t RemoteDHKeyCheck[16]; + uint8_t BD_ADDR_REMOTE[7]; + ATT.getPeerAddrWithType(connectionHandle, BD_ADDR_REMOTE); + for(int i=0; i<16; i++) RemoteDHKeyCheck[15-i] = l2capSignalingHdr->data[i]; + uint8_t encryptionState = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::RECEIVED_DH_CHECK; + + +#ifdef _BLE_TRACE_ + Serial.println("[Info] DH Key check"); + Serial.print("Remote DHKey Check: "); + btct.printBytes(RemoteDHKeyCheck, 16); +#endif + + HCI.readBdAddr(); + ATT.setPeerEncryption(connectionHandle, encryptionState); + if(encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED > 0){ + // We've already calculated the DHKey so we can calculate our check and send it. + + uint8_t MacKey[16]; + uint8_t localAddress[7]; + + memcpy(&localAddress[1],HCI.localAddr,6); + localAddress[0] = 0; // IOT 33 uses a static address + + btct.f5(HCI.DHKey,HCI.Na,HCI.Nb,BD_ADDR_REMOTE,localAddress,MacKey,HCI.LTK); + + uint8_t Ea[16]; + uint8_t Eb[16]; + uint8_t R[16]; + uint8_t MasterIOCap[3]; + uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; + + ATT.getPeerIOCap(connectionHandle, MasterIOCap); + for(int i=0; i<16; i++) R[i] = 0; + + btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, BD_ADDR_REMOTE, localAddress, Ea); + btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, BD_ADDR_REMOTE, Eb); + + +#ifdef _BLE_TRACE_ + Serial.println("Calculate f5, f6:"); + Serial.print("DH : "); + btct.printBytes(HCI.DHKey,32); + Serial.println("Na : "); + btct.printBytes(HCI.Na,16); + Serial.println("Nb : "); + btct.printBytes(HCI.Nb,16); + Serial.print("MAC : "); + btct.printBytes(MacKey,16); + // Serial.print("Expected MAC: "); + // printBytes(EXPECTED_MAC, 16); + Serial.print("LTK : "); + btct.printBytes(HCI.LTK,16); + // Serial.print("Expected LTK: "); + // printBytes(EXPECTED_LTK, 16); + Serial.print("Expected Ex : "); + btct.printBytes(RemoteDHKeyCheck, 16); + Serial.print("Ea : "); + btct.printBytes(Ea, 16); + Serial.print("Eb : "); + btct.printBytes(Eb,16); + Serial.print("Local Addr : "); + btct.printBytes(localAddress, 7); + Serial.print("LocalIOCap : "); + btct.printBytes(SlaveIOCap, 3); + Serial.print("MasterAddr : "); + btct.printBytes(BD_ADDR_REMOTE, 7); + Serial.print("MasterIOCAP : "); + btct.printBytes(MasterIOCap, 3); + Serial.println("Send Eb Back."); +#endif + + uint8_t ret[17]; + ret[0] = 0x0d; + for(int i=0; i #define SIGNALING_CID 0x0005 +#define SECURITY_CID 0x0006 + + +#define CONNECTION_PAIRING_REQUEST 0x01 +#define CONNECTION_PAIRING_RESPONSE 0x02 +#define CONNECTION_PAIRING_CONFIRM 0x03 +#define CONNECTION_PAIRING_RANDOM 0x04 +#define CONNECTION_PAIRING_FAILED 0x05 +#define CONNECTION_ENCRYPTION_INFORMATION 0x06 +#define CONNECTION_MASTER_IDENTIFICATION 0x07 +#define CONNECTION_IDENTITY_INFORMATION 0x08 +#define CONNECTION_IDENTITY_ADDRESS 0x09 +#define CONNECTION_SIGNING_INFORMATION 0x0A +#define CONNECTION_SECURITY_REQUEST 0x0B +#define CONNECTION_PAIRING_PUBLIC_KEY 0x0C +#define CONNECTION_PAIRING_DHKEY_CHECK 0x0D +#define CONNECTION_PAIRING_KEYPRESS 0x0E + +#define LOCAL_AUTHREQ 0b00101101 +#define LOCAL_IOCAP 0x3 class L2CAPSignalingClass { public: @@ -36,6 +56,8 @@ class L2CAPSignalingClass { void handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); + void handleSecurityData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); + void removeConnection(uint8_t handle, uint16_t reason); void setConnectionInterval(uint16_t minInterval, uint16_t maxInterval); diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp new file mode 100644 index 00000000..8fad5173 --- /dev/null +++ b/src/utility/btct.cpp @@ -0,0 +1,322 @@ +#include "btct.h" +#include +#include "HCI.h" +#include "ArduinoBLE.h" +BluetoothCryptoToolbox::BluetoothCryptoToolbox(){} +// In step 1, AES-128 with key K is applied to an all-zero input block. +// In step 2, K1 is derived through the following operation: +// If the most significant bit of L is equal to 0, K1 is the left-shift +// of L by 1 bit. +// Otherwise, K1 is the exclusive-OR of const_Rb and the left-shift of L +// by 1 bit. +// In step 3, K2 is derived through the following operation: +// If the most significant bit of K1 is equal to 0, K2 is the left-shift +// of K1 by 1 bit. +// Otherwise, K2 is the exclusive-OR of const_Rb and the left-shift of +// K1 by 1 bit. +// In step 4, (K1,K2) := Generate_Subkey(K) is returned. +unsigned char const_Rb[16] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87 + }; + +#define DHKEY_LENGTH 32 +#define N_LEN 16 +#define ADDR_LEN 6 +#define LEN_LTK 16 +#define LEN_MAC_KEY 16 + +void BluetoothCryptoToolbox::printBytes(uint8_t bytes[], uint8_t length){ + for(int i=0; i0){ + Serial.print(", 0x"); + }else{ + Serial.print("0x"); + } + Serial.print(bytes[i],HEX); + } + Serial.print('\n'); +} +int BluetoothCryptoToolbox::f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_slave[], + uint8_t BD_ADDR_master[], uint8_t BD_ADDR_slave[], uint8_t MacKey[], uint8_t LTK[]) +{ + uint8_t SALT[16] = {0x6C, 0x88, 0x83, 0x91, 0xAA, 0xF5, 0xA5, 0x38, 0x60, 0x37, 0x0B, 0xDB, 0x5A, 0x60, 0x83, 0xBE}; + uint8_t keyID[4] = {0x62, 0x74, 0x6c, 0x65}; + uint8_t length[2]; + length[0] = 0x01; + length[1] = 0x00; +#ifdef _BLE_TRACE_ + Serial.print("Starting f5 calculation"); + Serial.print("Using DHKey: "); + printBytes(DHKey, DHKEY_LENGTH); + Serial.print("Using N_Master: "); + printBytes(N_master, N_LEN); + Serial.print("Using N_Slave: "); + printBytes(N_slave, N_LEN); + + Serial.println("Using BD_ADDR_MASTER: "); + printBytes(BD_ADDR_master, ADDR_LEN); + Serial.println("Using BD_ADDR_SLAVE: "); + printBytes(BD_ADDR_slave, ADDR_LEN); +#endif + + uint8_t ADD_M[7]; + uint8_t ADD_S[7]; + uint8_t T[16]; + + for(int i=0; i<6; i++){ + ADD_M[1+i] = BD_ADDR_master[i]; + ADD_M[0] = 0x00; + ADD_S[i+1] = BD_ADDR_slave[i]; + ADD_S[0] = 0x00; + } + struct __attribute__ ((packed)) CmacInput + { + uint8_t counter; + uint8_t keyID[4]; + uint8_t N1[16]; + uint8_t N2[16]; + uint8_t A1[7]; + uint8_t A2[7]; + uint8_t length[2]; + } cmacInput = {0,0,0,0,0,0,0}; + cmacInput.counter = 0; + memcpy(cmacInput.keyID, keyID, 4); + memcpy(cmacInput.N1,N_master,16); + memcpy(cmacInput.N2,N_slave,16); + memcpy(cmacInput.A1,BD_ADDR_master,7); + memcpy(cmacInput.A2,BD_ADDR_slave,7); + memcpy(cmacInput.length,length,2); + AES_CMAC(SALT, DHKey, 32, T); + + AES_CMAC(T, (uint8_t*)&cmacInput,sizeof(cmacInput), MacKey); + cmacInput.counter=1; + AES_CMAC(T, (uint8_t*)&cmacInput, sizeof(cmacInput), LTK); + + return 1; +} +int BluetoothCryptoToolbox::f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[], uint8_t IOCap[], uint8_t A1[], uint8_t A2[], uint8_t Ex[]) +{ + struct __attribute__ ((packed)) F6Input + { + uint8_t N1[16]; + uint8_t N2[16]; + uint8_t R[16]; + uint8_t IOCap[3]; + uint8_t A1[7]; + uint8_t A2[7]; + } f6Input = {0,0,0,0,0,0}; + + memcpy(f6Input.N1, N1, 16); + memcpy(f6Input.N2, N2, 16); + memcpy(f6Input.R, R, 16); + memcpy(f6Input.IOCap, IOCap, 3); + memcpy(f6Input.A1, A1, 7); + memcpy(f6Input.A2, A2, 7); + + + AES_CMAC(W, (uint8_t*)&f6Input, sizeof(f6Input),Ex); + return 1; +} +// AES_CMAC from RFC +void BluetoothCryptoToolbox::AES_CMAC ( unsigned char *key, unsigned char *input, int length, + unsigned char *mac ) +{ + unsigned char X[16],Y[16], M_last[16], padded[16]; + unsigned char K1[16], K2[16]; + int n, i, flag; + generateSubkey(key,K1,K2); + + n = (length+15) / 16; /* n is number of rounds */ + + if ( n == 0 ) { + n = 1; + flag = 0; + } else { + if ( (length%16) == 0 ) { /* last block is a complete block */ + flag = 1; + } else { /* last block is not complete block */ + flag = 0; + } + } + + if ( flag ) { /* last block is complete block */ + xor_128(&input[16*(n-1)],K1,M_last); + } else { + padding(&input[16*(n-1)],padded,length%16); + xor_128(padded,K2,M_last); + } + + for ( i=0; i<16; i++ ) X[i] = 0; + for ( i=0; i=0; i-- ) { + output[i] = input[i] << 1; + output[i] |= overflow; + overflow = (input[i] & 0x80)?1:0; + } + return; +} +// From RFC +void BluetoothCryptoToolbox::xor_128(unsigned char *a, unsigned char *b, unsigned char *out) +{ + int i; + for (i=0;i<16; i++) + { + out[i] = a[i] ^ b[i]; + } +} +BluetoothCryptoToolbox btct; \ No newline at end of file diff --git a/src/utility/btct.h b/src/utility/btct.h new file mode 100644 index 00000000..87e515af --- /dev/null +++ b/src/utility/btct.h @@ -0,0 +1,26 @@ +#ifndef _BTCT_H_ +#define _BTCT_H_ +#include + +// Implementation of functions defined in BTLE standard +class BluetoothCryptoToolbox{ +public: + BluetoothCryptoToolbox(); + void printBytes(uint8_t bytes[], uint8_t length); + void generateSubkey(uint8_t* K, uint8_t* K1, uint8_t* K2); + void AES_CMAC ( unsigned char *key, unsigned char *input, int length, + unsigned char *mac ); + int f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_slave[], + uint8_t BD_ADDR_master[], uint8_t BD_ADDR_slave[], uint8_t MacKey[], uint8_t LTK[]); + int f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[], uint8_t IOCap[], uint8_t A1[], uint8_t A2[], uint8_t Ex[]); + void test(); + void testF5(); + void testF6(); +private: + int AES_128(uint8_t key[], uint8_t data_in[], uint8_t data_out[]); + void leftshift_onebit(unsigned char *input,unsigned char *output); + void xor_128(unsigned char *a, unsigned char *b, unsigned char *out); + void padding ( unsigned char *lastb, unsigned char *pad, int length ); +}; +extern BluetoothCryptoToolbox btct; +#endif \ No newline at end of file From 97571e37dfb16f84db83050d638af61f6b37f368 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Fri, 1 Jan 2021 14:41:48 +0000 Subject: [PATCH 003/112] With write encryptionn requirement --- src/utility/ATT.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++-- src/utility/ATT.h | 3 +++ src/utility/HCI.cpp | 16 +++++++++--- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 4c755615..5bd5e2aa 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -276,6 +276,8 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ case ATT_OP_ERROR: #ifdef _BLE_TRACE_ Serial.println("[Info] data error"); + // Serial.print("Error: "); + // btct.printBytes(data, dlen); #endif error(connectionHandle, dlen, data); break; @@ -559,6 +561,7 @@ bool ATTClass::handleNotify(uint16_t handle, const uint8_t* value, int length) memcpy(¬ification[notificationLength], value, length); notificationLength += length; + /// TODO: Set encyption requirement on notify. HCI.sendAclPkt(_peers[i].connectionHandle, ATT_CID, notificationLength, notification); numNotifications++; @@ -1214,6 +1217,7 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op uint8_t* value = &data[sizeof(handle)]; BLELocalAttribute* attribute = GATT.attribute(handle - 1); + bool holdResponse = false; if (attribute->type() == BLETypeCharacteristic) { BLELocalCharacteristic* characteristic = (BLELocalCharacteristic*)attribute; @@ -1226,10 +1230,33 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op } return; } + // Check permssion + if((characteristic->properties() & BLEProperty::BLEAuth)> 0 && (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES) == 0){ + holdResponse = true; + sendError(connectionHandle, ATT_OP_WRITE_REQ, handle, ATT_ECODE_INSUFF_ENC); + } for (int i = 0; i < ATT_MAX_PEERS; i++) { if (_peers[i].connectionHandle == connectionHandle) { - characteristic->writeValue(BLEDevice(_peers[i].addressType, _peers[i].address), value, valueLength); + if(holdResponse){ + + writeBufferSize = 0; + memcpy(writeBuffer, &handle, 2); + writeBufferSize+=2; + + writeBuffer[writeBufferSize++] = _peers[i].addressType; + + memcpy(&writeBuffer[writeBufferSize], _peers[i].address, sizeof(_peers[i].address)); + writeBufferSize += sizeof(_peers[i].address); + + writeBuffer[writeBufferSize] = valueLength; + writeBufferSize += sizeof(valueLength); + + memcpy(&writeBuffer[writeBufferSize], value, valueLength); + writeBufferSize += valueLength; + }else{ + characteristic->writeValue(BLEDevice(_peers[i].addressType, _peers[i].address), value, valueLength); + } break; } } @@ -1276,8 +1303,36 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op response[0] = ATT_OP_WRITE_RESP; responseLength = 1; - HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response); + if(holdResponse){ + memcpy(holdBuffer, response, responseLength); + holdBufferSize = responseLength; + }else{ + HCI.sendAclPkt(connectionHandle, ATT_CID, responseLength, response); + } + } +} +int ATTClass::processWriteBuffer(){ + if(writeBufferSize==0){ + return 0; } + + struct __attribute__ ((packed)) WriteBuffer { + uint16_t handle; + uint8_t addressType; + uint8_t address[6]; + uint8_t valueLength; + uint8_t value[]; + } *writeBufferStruct = (WriteBuffer*)&ATT.writeBuffer; + // uint8_t value[writeBufferStruct->valueLength]; + // memcpy(value, writeBufferStruct->value, writeBufferStruct->valueLength); + BLELocalAttribute* attribute = GATT.attribute(writeBufferStruct->handle-1); + BLELocalCharacteristic* characteristic = (BLELocalCharacteristic*)attribute; +#ifdef _BLE_TRACE_ + Serial.println("Writing value"); +#endif + characteristic->writeValue(BLEDevice(writeBufferStruct->addressType, writeBufferStruct->address), writeBufferStruct->value, writeBufferStruct->valueLength); + writeBufferSize = 0; + return 1; } void ATTClass::writeResp(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) diff --git a/src/utility/ATT.h b/src/utility/ATT.h index a7d802d1..09d396ca 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -95,7 +95,10 @@ class ATTClass { virtual int setPeerIOCap(uint16_t connectionHandle, uint8_t IOCap[]); virtual int getPeerIOCap(uint16_t connectionHandle, uint8_t IOCap[]); uint8_t holdBuffer[64]; + uint8_t writeBuffer[64]; uint8_t holdBufferSize; + uint8_t writeBufferSize; + virtual int processWriteBuffer(); private: virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index bd02764b..805a2c3d 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -666,13 +666,20 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) #endif if(encryptionChange->enabled>0){ ATT.setPeerEncryption(encryptionChange->connectionHandle, PEER_ENCRYPTION::ENCRYPTED_AES); + if(ATT.writeBufferSize > 0){ + ATT.processWriteBuffer(); + } + if(ATT.holdBufferSize>0){ +#ifdef _BLE_TRACE_ + Serial.print("Sending queued response size: "); + Serial.println(ATT.holdBufferSize); +#endif + HCI.sendAclPkt(encryptionChange->connectionHandle, ATT_CID, ATT.holdBufferSize, ATT.holdBuffer); + ATT.holdBufferSize = 0; + } }else{ ATT.setPeerEncryption(encryptionChange->connectionHandle, PEER_ENCRYPTION::NO_ENCRYPTION); } - if(ATT.holdBufferSize>0){ - HCI.sendAclPkt(encryptionChange->connectionHandle, ATT_CID, ATT.holdBufferSize, ATT.holdBuffer); - ATT.holdBufferSize = 0; - } } else if (eventHdr->evt == EVT_CMD_COMPLETE) { @@ -940,6 +947,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t Z = 0; for(int i=0; i<16; i++){ + /// TODO: Implement secure random Nb[i] = rand(); //// Should use ESP or ECCx08 } #ifdef _BLE_TRACE_ From fa42bb26cf49216b359999df944df4b868ae137a Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Sat, 2 Jan 2021 20:15:00 +0000 Subject: [PATCH 004/112] Write encryption & visible LTK / IRK --- .../EncryptedBatteryMonitor.ino | 209 ++++++++++++ src/BLECharacteristic.cpp | 8 +- src/BLECharacteristic.h | 4 +- src/BLEProperty.h | 11 +- src/BLETypedCharacteristic.h | 6 +- src/BLETypedCharacteristics.cpp | 28 +- src/BLETypedCharacteristics.h | 28 +- src/local/BLELocalCharacteristic.cpp | 18 +- src/local/BLELocalCharacteristic.h | 6 +- src/local/BLELocalDevice.cpp | 69 +++- src/local/BLELocalDevice.h | 7 +- src/remote/BLERemoteCharacteristic.cpp | 5 +- src/remote/BLERemoteCharacteristic.h | 4 +- src/utility/ATT.cpp | 45 ++- src/utility/ATT.h | 19 +- src/utility/HCI.cpp | 315 +++++++++++++++++- src/utility/HCI.h | 17 + src/utility/L2CAPSignaling.cpp | 45 ++- src/utility/btct.cpp | 32 ++ src/utility/btct.h | 2 + src/utility/keyDistribution.cpp | 24 ++ src/utility/keyDistribution.h | 29 ++ 22 files changed, 855 insertions(+), 76 deletions(-) create mode 100644 examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino create mode 100644 src/utility/keyDistribution.cpp create mode 100644 src/utility/keyDistribution.h diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino new file mode 100644 index 00000000..338a374e --- /dev/null +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -0,0 +1,209 @@ +/* + Battery Monitor + + This example creates a BLE peripheral with the standard battery service and + level characteristic. The A0 pin is used to calculate the battery level. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic BLE central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + + + // BLE Battery Service +BLEService batteryService("180F"); + +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes +BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); + + +// Add BLEEncryption tag to require pairing. This controls the LED. +BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); + +int oldBatteryLevel = 0; // last battery level reading from analog input +long previousMillis = 0; // last time the battery level was checked, in ms + +void setup() { + Serial.begin(9600); // initialize serial communication + while (!Serial); + + pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + + + Serial.println("Serial connected"); + + // IRKs are keys that identify the true owner of a random mac address. + // Add IRKs of devices you are bonded with. + BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BADDR_TYPES, uint8_t*** BDAddrs, uint8_t*** IRKs){ + // Set to number of devices + *nIRKs = 2; + + *BDAddrs = new uint8_t*[*nIRKs]; + *IRKs = new uint8_t*[*nIRKs]; + *BADDR_TYPES = new uint8_t[*nIRKs]; + + // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. + uint8_t iPhoneMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t iPhoneIRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + uint8_t iPadMac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t iPadIRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + + + (*BADDR_TYPES)[0] = 0; + (*IRKs)[0] = new uint8_t[16]; + memcpy((*IRKs)[0],iPhoneIRK,16); + (*BDAddrs)[0] = new uint8_t[6]; + memcpy((*BDAddrs)[0], iPhoneMac, 6); + + + (*BADDR_TYPES)[1] = 0; + (*IRKs)[1] = new uint8_t[16]; + memcpy((*IRKs)[1],iPadIRK,16); + (*BDAddrs)[1] = new uint8_t[6]; + memcpy((*BDAddrs)[1], iPadMac, 6); + + + return 1; + }); + // The LTK is the secret key which is used to encrypt bluetooth traffic + BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ + // address is input + Serial.print("Recieved request for address: "); + btct.printBytes(address,6); + + // Set these to the MAC and LTK of your devices after bonding. + uint8_t iPhoneMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t iPhoneLTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t iPadMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t iPadLTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + + if(memcmp(iPhoneMac, address, 6)==0){ + memcpy(LTK, iPhoneLTK, 16); + return 1; + }else if(memcmp(iPadMac, address, 6)==0){ + memcpy(LTK, iPadLTK, 16); + } + return 0; + }); + BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK){ + Serial.print(F("New device with MAC : ")); + btct.printBytes(address,6); + Serial.print(F("Need to store IRK : ")); + btct.printBytes(IRK,16); + return 1; + }); + BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK){ + Serial.print(F("New device with MAC : ")); + btct.printBytes(address,6); + Serial.print(F("Need to store LTK : ")); + btct.printBytes(LTK,16); + return 1; + }); + + while(1){// begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + delay(200); + continue; + } + Serial.println("BT init"); + delay(200); + + /* Set a local name for the BLE device + This name will appear in advertising packets + and can be used by remote devices to identify this BLE device + The name can be changed but maybe be truncated based on space left in advertisement packet + */ + + BLE.setDeviceName("Arduino"); + BLE.setLocalName("BatteryMonitor"); + + BLE.setAdvertisedService(batteryService); // add the service UUID + batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic + batteryService.addCharacteristic(stringcharacteristic); + batteryService.addCharacteristic(secretValue); + + BLE.addService(batteryService); // Add the battery service + batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic + char* stringCharValue = new char[32]; + stringCharValue = "string"; + stringcharacteristic.writeValue(stringCharValue); + secretValue.writeValue(0); + + delay(1000); + + /* Start advertising BLE. It will start continuously transmitting BLE + advertising packets and will be visible to remote BLE central devices + until it receives a new connection */ + + // start advertising + if(!BLE.advertise()){ + Serial.println("failed to advertise bluetooth."); + BLE.stopAdvertise(); + delay(500); + }else{ + Serial.println("advertising..."); + break; + } + BLE.end(); + delay(100); + } +} + + +void loop() { + // wait for a BLE central + BLEDevice central = BLE.central(); + + // if a central is connected to the peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + + // check the battery level every 200ms + // while the central is connected: + while (central.connected()) { + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 1000) { + previousMillis = currentMillis; + updateBatteryLevel(); + if(secretValue.value()>0){ + digitalWrite(13,HIGH); + }else{ + digitalWrite(13,LOW); + } + } + } + Serial.print("Disconnected from central: "); + Serial.println(central.address()); + } +} + +void updateBatteryLevel() { + /* Read the current voltage level on the A0 analog input pin. + This is used here to simulate the charge level of a battery. + */ + int battery = analogRead(A0); + int batteryLevel = map(battery, 0, 1023, 0, 100); + + if (batteryLevel != oldBatteryLevel) { // if the battery level has changed + // Serial.print("Battery Level % is now: "); // print it + // Serial.println(batteryLevel); + batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic + oldBatteryLevel = batteryLevel; // save the level for next comparison + } +} diff --git a/src/BLECharacteristic.cpp b/src/BLECharacteristic.cpp index 9a07cb9d..1cfbf489 100644 --- a/src/BLECharacteristic.cpp +++ b/src/BLECharacteristic.cpp @@ -47,13 +47,13 @@ BLECharacteristic::BLECharacteristic(BLERemoteCharacteristic* remote) : } } -BLECharacteristic::BLECharacteristic(const char* uuid, uint8_t properties, int valueSize, bool fixedLength) : - BLECharacteristic(new BLELocalCharacteristic(uuid, properties, valueSize, fixedLength)) +BLECharacteristic::BLECharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) : + BLECharacteristic(new BLELocalCharacteristic(uuid, permissions, valueSize, fixedLength)) { } -BLECharacteristic::BLECharacteristic(const char* uuid, uint8_t properties, const char* value) : - BLECharacteristic(new BLELocalCharacteristic(uuid, properties, value)) +BLECharacteristic::BLECharacteristic(const char* uuid, uint16_t permissions, const char* value) : + BLECharacteristic(new BLELocalCharacteristic(uuid, permissions, value)) { } diff --git a/src/BLECharacteristic.h b/src/BLECharacteristic.h index 2ac30b05..da9721e0 100644 --- a/src/BLECharacteristic.h +++ b/src/BLECharacteristic.h @@ -45,8 +45,8 @@ class BLERemoteCharacteristic; class BLECharacteristic { public: BLECharacteristic(); - BLECharacteristic(const char* uuid, uint8_t properties, int valueSize, bool fixedLength = false); - BLECharacteristic(const char* uuid, uint8_t properties, const char* value); + BLECharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength = false); + BLECharacteristic(const char* uuid, uint16_t permissions, const char* value); BLECharacteristic(const BLECharacteristic& other); virtual ~BLECharacteristic(); diff --git a/src/BLEProperty.h b/src/BLEProperty.h index aeee4c85..434bd2aa 100644 --- a/src/BLEProperty.h +++ b/src/BLEProperty.h @@ -29,10 +29,19 @@ enum BLEProperty { BLEWrite = 0x08, BLENotify = 0x10, BLEIndicate = 0x20, - BLEAuth = 1 << 6, + BLEAuthSignedWrite = 1 << 6, BLEExtProp = 1 << 7, }; +enum BLEPermission { + BLEEncryption = 1 << 9, + BLEAuthentication = 1 << 10, + BLEAuthorization = 1 << 11, + // BLEWriteEncryption = 1 << 11, + // BLEWriteAuthentication = 1 << 12, + // BLEWriteAuthorization = 1 << 13, +}; + #define ESP_GATT_CHAR_PROP_BIT_BROADCAST (1 << 0) /* 0x01 */ /* relate to BTA_GATT_CHAR_PROP_BIT_BROADCAST in bta/bta_gatt_api.h */ #define ESP_GATT_CHAR_PROP_BIT_READ (1 << 1) /* 0x02 */ /* relate to BTA_GATT_CHAR_PROP_BIT_READ in bta/bta_gatt_api.h */ #define ESP_GATT_CHAR_PROP_BIT_WRITE_NR (1 << 2) /* 0x04 */ /* relate to BTA_GATT_CHAR_PROP_BIT_WRITE_NR in bta/bta_gatt_api.h */ diff --git a/src/BLETypedCharacteristic.h b/src/BLETypedCharacteristic.h index d6e6e4a1..7777d360 100644 --- a/src/BLETypedCharacteristic.h +++ b/src/BLETypedCharacteristic.h @@ -25,7 +25,7 @@ template class BLETypedCharacteristic : public BLECharacteristic { public: - BLETypedCharacteristic(const char* uuid, unsigned char properties); + BLETypedCharacteristic(const char* uuid, unsigned int permissions); int writeValue(T value); int setValue(T value) { return writeValue(value); } @@ -43,8 +43,8 @@ template class BLETypedCharacteristic : public BLECharacteristic T byteSwap(T value); }; -template BLETypedCharacteristic::BLETypedCharacteristic(const char* uuid, unsigned char properties) : - BLECharacteristic(uuid, properties, sizeof(T), true) +template BLETypedCharacteristic::BLETypedCharacteristic(const char* uuid, unsigned int permissions) : + BLECharacteristic(uuid, permissions, sizeof(T), true) { T value; memset(&value, 0x00, sizeof(value)); diff --git a/src/BLETypedCharacteristics.cpp b/src/BLETypedCharacteristics.cpp index 976f6159..800574eb 100644 --- a/src/BLETypedCharacteristics.cpp +++ b/src/BLETypedCharacteristics.cpp @@ -21,72 +21,72 @@ #include "BLETypedCharacteristics.h" -BLEBoolCharacteristic::BLEBoolCharacteristic(const char* uuid, unsigned char properties) : +BLEBoolCharacteristic::BLEBoolCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEBooleanCharacteristic::BLEBooleanCharacteristic(const char* uuid, unsigned char properties) : +BLEBooleanCharacteristic::BLEBooleanCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLECharCharacteristic::BLECharCharacteristic(const char* uuid, unsigned char properties) : +BLECharCharacteristic::BLECharCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEUnsignedCharCharacteristic::BLEUnsignedCharCharacteristic(const char* uuid, unsigned char properties) : +BLEUnsignedCharCharacteristic::BLEUnsignedCharCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEByteCharacteristic::BLEByteCharacteristic(const char* uuid, unsigned char properties) : +BLEByteCharacteristic::BLEByteCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEShortCharacteristic::BLEShortCharacteristic(const char* uuid, unsigned char properties) : +BLEShortCharacteristic::BLEShortCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEUnsignedShortCharacteristic::BLEUnsignedShortCharacteristic(const char* uuid, unsigned char properties) : +BLEUnsignedShortCharacteristic::BLEUnsignedShortCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEWordCharacteristic::BLEWordCharacteristic(const char* uuid, unsigned char properties) : +BLEWordCharacteristic::BLEWordCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEIntCharacteristic::BLEIntCharacteristic(const char* uuid, unsigned char properties) : +BLEIntCharacteristic::BLEIntCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEUnsignedIntCharacteristic::BLEUnsignedIntCharacteristic(const char* uuid, unsigned char properties) : +BLEUnsignedIntCharacteristic::BLEUnsignedIntCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLELongCharacteristic::BLELongCharacteristic(const char* uuid, unsigned char properties) : +BLELongCharacteristic::BLELongCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEUnsignedLongCharacteristic::BLEUnsignedLongCharacteristic(const char* uuid, unsigned char properties) : +BLEUnsignedLongCharacteristic::BLEUnsignedLongCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEFloatCharacteristic::BLEFloatCharacteristic(const char* uuid, unsigned char properties) : +BLEFloatCharacteristic::BLEFloatCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } -BLEDoubleCharacteristic::BLEDoubleCharacteristic(const char* uuid, unsigned char properties) : +BLEDoubleCharacteristic::BLEDoubleCharacteristic(const char* uuid, unsigned int properties) : BLETypedCharacteristic(uuid, properties) { } diff --git a/src/BLETypedCharacteristics.h b/src/BLETypedCharacteristics.h index 465fc046..df8482cf 100644 --- a/src/BLETypedCharacteristics.h +++ b/src/BLETypedCharacteristics.h @@ -24,72 +24,72 @@ class BLEBoolCharacteristic : public BLETypedCharacteristic { public: - BLEBoolCharacteristic(const char* uuid, unsigned char properties); + BLEBoolCharacteristic(const char* uuid, unsigned int permissions); }; class BLEBooleanCharacteristic : public BLETypedCharacteristic { public: - BLEBooleanCharacteristic(const char* uuid, unsigned char properties); + BLEBooleanCharacteristic(const char* uuid, unsigned int permissions); }; class BLECharCharacteristic : public BLETypedCharacteristic { public: - BLECharCharacteristic(const char* uuid, unsigned char properties); + BLECharCharacteristic(const char* uuid, unsigned int permissions); }; class BLEUnsignedCharCharacteristic : public BLETypedCharacteristic { public: - BLEUnsignedCharCharacteristic(const char* uuid, unsigned char properties); + BLEUnsignedCharCharacteristic(const char* uuid, unsigned int permissions); }; class BLEByteCharacteristic : public BLETypedCharacteristic { public: - BLEByteCharacteristic(const char* uuid, unsigned char properties); + BLEByteCharacteristic(const char* uuid, unsigned int permissions); }; class BLEShortCharacteristic : public BLETypedCharacteristic { public: - BLEShortCharacteristic(const char* uuid, unsigned char properties); + BLEShortCharacteristic(const char* uuid, unsigned int permissions); }; class BLEUnsignedShortCharacteristic : public BLETypedCharacteristic { public: - BLEUnsignedShortCharacteristic(const char* uuid, unsigned char properties); + BLEUnsignedShortCharacteristic(const char* uuid, unsigned int permissions); }; class BLEWordCharacteristic : public BLETypedCharacteristic { public: - BLEWordCharacteristic(const char* uuid, unsigned char properties); + BLEWordCharacteristic(const char* uuid, unsigned int permissions); }; class BLEIntCharacteristic : public BLETypedCharacteristic { public: - BLEIntCharacteristic(const char* uuid, unsigned char properties); + BLEIntCharacteristic(const char* uuid, unsigned int permissions); }; class BLEUnsignedIntCharacteristic : public BLETypedCharacteristic { public: - BLEUnsignedIntCharacteristic(const char* uuid, unsigned char properties); + BLEUnsignedIntCharacteristic(const char* uuid, unsigned int permissions); }; class BLELongCharacteristic : public BLETypedCharacteristic { public: - BLELongCharacteristic(const char* uuid, unsigned char properties); + BLELongCharacteristic(const char* uuid, unsigned int permissions); }; class BLEUnsignedLongCharacteristic : public BLETypedCharacteristic { public: - BLEUnsignedLongCharacteristic(const char* uuid, unsigned char properties); + BLEUnsignedLongCharacteristic(const char* uuid, unsigned int permissions); }; class BLEFloatCharacteristic : public BLETypedCharacteristic { public: - BLEFloatCharacteristic(const char* uuid, unsigned char properties); + BLEFloatCharacteristic(const char* uuid, unsigned int permissions); }; class BLEDoubleCharacteristic : public BLETypedCharacteristic { public: - BLEDoubleCharacteristic(const char* uuid, unsigned char properties); + BLEDoubleCharacteristic(const char* uuid, unsigned int permissions); }; #endif diff --git a/src/local/BLELocalCharacteristic.cpp b/src/local/BLELocalCharacteristic.cpp index 333d00b2..2cd801b2 100644 --- a/src/local/BLELocalCharacteristic.cpp +++ b/src/local/BLELocalCharacteristic.cpp @@ -29,20 +29,21 @@ #include "BLELocalCharacteristic.h" -BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint8_t properties, int valueSize, bool fixedLength) : +BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) : BLELocalAttribute(uuid), - _properties(properties), + _properties((uint8_t)(permissions&0x000FF)), _valueSize(min(valueSize, 512)), _valueLength(0), _fixedLength(fixedLength), _handle(0x0000), _broadcast(false), _written(false), - _cccdValue(0x0000) + _cccdValue(0x0000), + _permissions((uint8_t)((permissions&0xFF00)>>8)) { memset(_eventHandlers, 0x00, sizeof(_eventHandlers)); - if (properties & (BLENotify | BLEIndicate)) { + if (permissions & (BLENotify | BLEIndicate)) { BLELocalDescriptor* cccd = new BLELocalDescriptor("2902", (uint8_t*)&_cccdValue, sizeof(_cccdValue)); _descriptors.add(cccd); @@ -51,12 +52,11 @@ BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint8_t propert _value = (uint8_t*)malloc(valueSize); } -BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint8_t properties, const char* value) : - BLELocalCharacteristic(uuid, properties, strlen(value)) +BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, const char* value) : + BLELocalCharacteristic(uuid, permissions, strlen(value)) { writeValue(value); } - BLELocalCharacteristic::~BLELocalCharacteristic() { for (unsigned int i = 0; i < descriptorCount(); i++) { @@ -84,6 +84,10 @@ uint8_t BLELocalCharacteristic::properties() const return _properties; } +uint8_t BLELocalCharacteristic::permissions() const { + return _permissions; +} + int BLELocalCharacteristic::valueSize() const { return _valueSize; diff --git a/src/local/BLELocalCharacteristic.h b/src/local/BLELocalCharacteristic.h index ee42390a..331cdd5c 100644 --- a/src/local/BLELocalCharacteristic.h +++ b/src/local/BLELocalCharacteristic.h @@ -33,13 +33,14 @@ class BLELocalDescriptor; class BLELocalCharacteristic : public BLELocalAttribute { public: - BLELocalCharacteristic(const char* uuid, uint8_t properties, int valueSize, bool fixedLength = false); - BLELocalCharacteristic(const char* uuid, uint8_t properties, const char* value); + BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength = false); + BLELocalCharacteristic(const char* uuid, uint16_t permissions, const char* value); virtual ~BLELocalCharacteristic(); virtual enum BLEAttributeType type() const; uint8_t properties() const; + uint8_t permissions() const; int valueSize() const; const uint8_t* value() const; @@ -75,6 +76,7 @@ class BLELocalCharacteristic : public BLELocalAttribute { private: uint8_t _properties; + uint8_t _permissions; int _valueSize; uint8_t* _value; uint16_t _valueLength; diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index df11e971..49cc6603 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -108,7 +108,7 @@ int BLELocalDevice::begin() end(); return 0; } - if (HCI.setLeEventMask(0x00000000000001FF) != 0) { + if (HCI.setLeEventMask(0x00000000000003FF) != 0) { end(); return 0; } @@ -121,6 +121,59 @@ int BLELocalDevice::begin() return 0; } + /// The HCI should allow automatic address resolution. + + // // If we have callbacks to rememember bonded devices: + // if(HCI._getIRKs!=0){ + // uint8_t nIRKs = 0; + // uint8_t** BADDR_Type = new uint8_t*; + // uint8_t*** BADDRs = new uint8_t**; + // uint8_t*** IRKs = new uint8_t**; + // uint8_t* memcheck; + + + // if(!HCI._getIRKs(&nIRKs, BADDR_Type, BADDRs, IRKs)){ + // Serial.println("error"); + // } + // for(int i=0; i>8)), _valueHandle(valueHandle), _value(NULL), _valueLength(0), diff --git a/src/remote/BLERemoteCharacteristic.h b/src/remote/BLERemoteCharacteristic.h index d0ac09bc..b53ab031 100644 --- a/src/remote/BLERemoteCharacteristic.h +++ b/src/remote/BLERemoteCharacteristic.h @@ -29,10 +29,11 @@ class BLERemoteCharacteristic : public BLERemoteAttribute { public: - BLERemoteCharacteristic(const uint8_t uuid[], uint8_t uuidLen, uint16_t connectionHandle, uint16_t startHandle, uint8_t properties, uint16_t valueHandle); + BLERemoteCharacteristic(const uint8_t uuid[], uint8_t uuidLen, uint16_t connectionHandle, uint16_t startHandle, uint16_t permissions, uint16_t valueHandle); virtual ~BLERemoteCharacteristic(); uint8_t properties() const; + uint8_t permissions() const; const uint8_t* value() const; int valueLength() const; @@ -66,6 +67,7 @@ class BLERemoteCharacteristic : public BLERemoteAttribute { uint16_t _connectionHandle; uint16_t _startHandle; uint8_t _properties; + uint8_t _permissions; uint16_t _valueHandle; uint8_t* _value; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 5bd5e2aa..6ef6bc31 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -253,6 +253,15 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy _peers[peerIndex].mtu = 23; _peers[peerIndex].addressType = peerBdaddrType; memcpy(_peers[peerIndex].address, peerBdaddr, sizeof(_peers[peerIndex].address)); + uint8_t BDADDr[6]; + for(int i=0; i<6; i++) BDADDr[5-i] = peerBdaddr[i]; + if(HCI.tryResolveAddress(BDADDr,_peers[peerIndex].resolvedAddress)){ +#ifdef _BLE_TRACE_ + Serial.println("Found match."); +#endif + }else{ + memset(_peers[peerIndex].resolvedAddress, 0, 6); + } if (_eventHandlers[BLEConnected]) { _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); @@ -515,6 +524,7 @@ bool ATTClass::disconnect() _peers[i].role = 0x00; _peers[i].addressType = 0x00; memset(_peers[i].address, 0x00, sizeof(_peers[i].address)); + memset(_peers[i].resolvedAddress, 0x00, sizeof(_peers[i].resolvedAddress)); _peers[i].mtu = 23; if (_peers[i].device) { @@ -1007,7 +1017,8 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ return; } // If characteristic requires encryption send error & hold response until encrypted - if ((characteristic->properties() & BLEAuth) > 0 && (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES)==0) { + if ((characteristic->permissions() & (BLEPermission::BLEEncryption >> 8)) > 0 && + (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES)==0 ) { holdResponse = true; sendError(connectionHandle, opcode, handle, ATT_ECODE_INSUFF_ENC); } @@ -1231,7 +1242,8 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op return; } // Check permssion - if((characteristic->properties() & BLEProperty::BLEAuth)> 0 && (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES) == 0){ + if((characteristic->permissions() &( BLEPermission::BLEEncryption >> 8)) > 0 && + (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES) == 0){ holdResponse = true; sendError(connectionHandle, ATT_OP_WRITE_REQ, handle, ATT_ECODE_INSUFF_ENC); } @@ -1817,7 +1829,7 @@ int ATTClass::setPeerIOCap(uint16_t connectionHandle, uint8_t IOCap[3]){ // Return the connection handle for the first peer that is requesting encryption uint16_t ATTClass::getPeerEncrptingConnectionHandle(){ for(int i=0; i 0){ + if((_peers[i].encryption & PEER_ENCRYPTION::REQUESTED_ENCRYPTION) > 0){ return _peers[i].connectionHandle; } } @@ -1861,7 +1873,7 @@ int ATTClass::getPeerAddrWithType(uint16_t connectionHandle, uint8_t peerAddr[]) peerAddr[6-k] = _peers[i].address[k]; } if(_peers[i].addressType){ - peerAddr[0] = 0x01; + peerAddr[0] = _peers[i].addressType; }else{ peerAddr[0] = 0x00; } @@ -1869,6 +1881,31 @@ int ATTClass::getPeerAddrWithType(uint16_t connectionHandle, uint8_t peerAddr[]) } return 0; } +// Get the resolved address for a peer if it exists +int ATTClass::getPeerResolvedAddress(uint16_t connectionHandle, uint8_t resolvedAddress[]){ + for(int i=0; i #include "BLEDevice.h" +#include "keyDistribution.h" #define ATT_CID 0x0004 #define BLE_CTL 0x0008 @@ -37,11 +38,12 @@ enum PEER_ENCRYPTION { NO_ENCRYPTION = 0, - REQUESTED_ENCRYPTION = 1 << 0, - SENT_PUBKEY = 1 << 1, - DH_KEY_CALULATED = 1 << 2, - RECEIVED_DH_CHECK = 1 << 3, - SENT_DH_CHECK = 1 << 4, + PAIRING_REQUEST = 1 << 0, + REQUESTED_ENCRYPTION = 1 << 1, + SENT_PUBKEY = 1 << 2, + DH_KEY_CALULATED = 1 << 3, + RECEIVED_DH_CHECK = 1 << 4, + SENT_DH_CHECK = 1 << 5, ENCRYPTED_AES = 1 << 7 }; @@ -94,11 +96,17 @@ class ATTClass { virtual int getPeerAddrWithType(uint16_t connectionHandle, uint8_t peerAddr[]); virtual int setPeerIOCap(uint16_t connectionHandle, uint8_t IOCap[]); virtual int getPeerIOCap(uint16_t connectionHandle, uint8_t IOCap[]); + virtual int getPeerResolvedAddress(uint16_t connectionHandle, uint8_t* resolvedAddress); uint8_t holdBuffer[64]; uint8_t writeBuffer[64]; uint8_t holdBufferSize; uint8_t writeBufferSize; virtual int processWriteBuffer(); + KeyDistribution remoteKeyDistribution; + KeyDistribution localKeyDistribution; + uint8_t peerIRK[16]; + /// This is just a random number... Not sure it has use unless privacy mode is active. + uint8_t localIRK[16] = {0x54,0x83,0x63,0x7c,0xc5,0x1e,0xf7,0xec,0x32,0xdd,0xad,0x51,0x89,0x4b,0x9e,0x07}; private: virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); @@ -139,6 +147,7 @@ class ATTClass { uint8_t role; uint8_t addressType; uint8_t address[6]; + uint8_t resolvedAddress[6]; uint16_t mtu; BLERemoteDevice* device; uint8_t encryption; diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 805a2c3d..c3d66848 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -34,6 +34,7 @@ #define EVT_CMD_COMPLETE 0x0e #define EVT_CMD_STATUS 0x0f #define EVT_NUM_COMP_PKTS 0x13 +#define EVT_RETURN_LINK_KEYS 0x15 #define EVT_UNKNOWN 0x10 #define EVT_LE_META_EVENT 0x3e @@ -449,6 +450,161 @@ int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxIn return sendCommand(OGF_LE_CTL << 10 | OCF_LE_CONN_UPDATE, sizeof(leConnUpdateData), &leConnUpdateData); } +int HCIClass::saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* localIrk){ + if(_storeIRK!=0){ + _storeIRK(address, peerIrk); + } + // Again... this should work + // leAddResolvingAddress(addressType, address, peerIrk, localIrk); +} +int HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress, uint8_t* peerIrk, uint8_t* localIrk){ + leStopResolvingAddresses(); + + struct __attribute__ ((packed)) AddDevice { + uint8_t peerAddressType; + uint8_t peerAddress[6]; + uint8_t peerIRK[16]; + uint8_t localIRK[16]; + } addDevice; + addDevice.peerAddressType = addressType; + for(int i=0; i<6; i++) addDevice.peerAddress[5-i] = peerAddress[i]; + for(int i=0; i<16; i++) { + addDevice.peerIRK[15-i] = peerIrk[i]; + addDevice.localIRK[15-i] = localIrk[i]; + } + Serial.print("ADDTYPE :"); + btct.printBytes(&addDevice.peerAddressType,1); + Serial.print("adddddd :"); + btct.printBytes(addDevice.peerAddress,6); + Serial.print("Peer IRK :"); + btct.printBytes(addDevice.peerIRK,16); + Serial.print("localIRK :"); + btct.printBytes(addDevice.localIRK,16); + sendCommand(OGF_LE_CTL << 10 | 0x27, sizeof(addDevice), &addDevice); + + leStartResolvingAddresses(); +} +int HCIClass::leStopResolvingAddresses(){ + uint8_t enable = 0; + return HCI.sendCommand(OGF_LE_CTL << 10 | 0x2D, 1,&enable); // Disable address resolution +} +int HCIClass::leStartResolvingAddresses(){ + uint8_t enable = 1; + return HCI.sendCommand(OGF_LE_CTL << 10 | 0x2D, 1,&enable); // Disable address resolution +} +int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peerIdentityAddress, uint8_t* peerResolvableAddress){ + struct __attribute__ ((packed)) Request { + uint8_t addressType; + uint8_t identityAddress[6]; + } request; + request.addressType = peerAddressType; + for(int i=0; i<6; i++) request.identityAddress[5-i] = peerIdentityAddress[i]; + + + int res = sendCommand(OGF_LE_CTL << 10 | 0x2B, sizeof(request), &request); + Serial.print("res: 0x"); + Serial.println(res, HEX); + if(res==0){ + struct __attribute__ ((packed)) Response { + uint8_t status; + uint8_t peerResolvableAddress[6]; + } *response = (Response*)_cmdResponse; + Serial.print("Address resolution status: 0x"); + Serial.println(response->status, HEX); + Serial.print("peer resolvable address: "); + btct.printBytes(response->peerResolvableAddress,6); + } + return res; +} + +int HCIClass::writeLK(uint8_t peerAddress[], uint8_t LK[]){ + struct __attribute__ ((packed)) StoreLK { + uint8_t nKeys; + uint8_t BD_ADDR[6]; + uint8_t LTK[16]; + } storeLK; + storeLK.nKeys = 1; + memcpy(storeLK.BD_ADDR, peerAddress, 6); + for(int i=0; i<16; i++) storeLK.LTK[15-i] = LK[i]; + HCI.sendCommand(OGF_HOST_CTL << 10 | 0x11, sizeof(storeLK), &storeLK); +} +int HCIClass::readStoredLKs(){ + uint8_t BD_ADDR[6]; + readStoredLK(BD_ADDR, 1); +} +int HCIClass::readStoredLK(uint8_t BD_ADDR[], uint8_t read_all ){ + struct __attribute__ ((packed)) Request { + uint8_t BD_ADDR[6]; + uint8_t read_a; + } request = {0,0}; + for(int i=0; i<6; i++) request.BD_ADDR[5-i] = BD_ADDR[i]; + request.read_a = read_all; + return sendCommand(OGF_HOST_CTL << 10 | 0xD, sizeof(request), &request); +} + +int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){ + uint8_t iphone[16] = {0xA6, 0xD2, 0xD, 0xD3, 0x4F, 0x13, 0x42, 0x4F, 0xE1, 0xC1, 0xFD, 0x22, 0x2E, 0xC5, 0x6A, 0x2D}; + uint8_t irk[16]; + for(int i=0; i<16; i++) irk[15-i] = iphone[i]; + bool foundMatch = false; + if(HCI._getIRKs!=0){ + uint8_t nIRKs = 0; + uint8_t** BDAddrType = new uint8_t*; + uint8_t*** BADDRs = new uint8_t**; + uint8_t*** IRKs = new uint8_t**; + uint8_t* memcheck; + + + if(!HCI._getIRKs(&nIRKs, BDAddrType, BADDRs, IRKs)){ + Serial.println("error getting IRKs."); + } + for(int i=0; ienabled,1); #endif if(encryptionChange->enabled>0){ + // 0001 1110 + if((ATT.getPeerEncryption(encryptionChange->connectionHandle)&PEER_ENCRYPTION::PAIRING_REQUEST)>0){ + if(ATT.localKeyDistribution.EncKey()){ +#ifdef _BLE_TRACE_ + Serial.println("Enc key set but sould be ignored"); +#endif + }else{ +#ifdef _BLE_TRACE_ + Serial.println("No enc key distribution"); +#endif + } + // From page 1681 bluetooth standard - order matters + if(ATT.localKeyDistribution.IdKey()){ + /// We shall distribute IRK and address using identity information + { + uint8_t response[17]; + response[0] = CONNECTION_IDENTITY_INFORMATION; // Identity information. + for(int i=0; i<16; i++) response[16-i] = ATT.localIRK[i]; + HCI.sendAclPkt(encryptionChange->connectionHandle, SECURITY_CID, sizeof(response), response); +#ifdef _BLE_TRACE_ + Serial.println("Distribute ID Key"); +#endif + } + { + uint8_t response[8]; + response[0] = CONNECTION_IDENTITY_ADDRESS; // Identity address information + response[1] = 0x00; // Static local address + for(int i=0; i<6; i++) response[7-i] = HCI.localAddr[i]; + HCI.sendAclPkt(encryptionChange->connectionHandle, SECURITY_CID, sizeof(response), response); + } + } + if(ATT.localKeyDistribution.SignKey()){ + /// We shall distribut CSRK +#ifdef _BLE_TRACE_ + Serial.println("We shall distribute CSRK // not implemented"); +#endif + + }else{ + // Serial.println("We don't want to distribute CSRK"); + } + if(ATT.localKeyDistribution.LinkKey()){ +#ifdef _BLE_TRACE_ + Serial.println("We would like to use LTK to generate BR/EDR // not implemented"); +#endif + } + }else{ +#ifdef _BLE_TRACE_ + Serial.println("Reconnection, not pairing so no keys"); + Serial.println(ATT.getPeerEncryption(encryptionChange->connectionHandle),HEX); +#endif + } + ATT.setPeerEncryption(encryptionChange->connectionHandle, PEER_ENCRYPTION::ENCRYPTED_AES); if(ATT.writeBufferSize > 0){ ATT.processWriteBuffer(); @@ -740,6 +948,27 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) data += 2; } } + else if(eventHdr->evt == EVT_RETURN_LINK_KEYS) + { + uint8_t num_keys = (uint8_t)pdata[sizeof(HCIEventHdr)]; + // Serial.print("N keys: "); + // Serial.println(num_keys); + uint8_t BD_ADDRs[num_keys][6]; + uint8_t LKs[num_keys][16]; + auto nAddresss = [pdata](uint8_t nAddr)->uint8_t*{ + return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + nAddr*6 + nAddr*16; + }; + auto nLK = [pdata](uint8_t nLK)->uint8_t*{ + return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + (nLK+1)*6 + nLK*16; + }; + // Serial.println("Stored LKs are: "); + // for(int i=0; ievt == 0x10) { struct __attribute__ ((packed)) CmdHardwareError { @@ -761,6 +990,57 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.println(leMetaHeader->subevent,HEX); #endif switch((LE_META_EVENT)leMetaHeader->subevent){ + case 0x0A:{ + struct __attribute__ ((packed)) EvtLeConnectionComplete { + uint8_t status; + uint16_t handle; + uint8_t role; + uint8_t peerBdaddrType; + uint8_t peerBdaddr[6]; + uint8_t localResolvablePrivateAddress[6]; + uint8_t peerResolvablePrivateAddress[6]; + uint16_t interval; + uint16_t latency; + uint16_t supervisionTimeout; + uint8_t masterClockAccuracy; + } *leConnectionComplete = (EvtLeConnectionComplete*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; + + if (leConnectionComplete->status == 0x00) { + ATT.addConnection(leConnectionComplete->handle, + leConnectionComplete->role, + leConnectionComplete->peerBdaddrType, + leConnectionComplete->peerBdaddr, + leConnectionComplete->interval, + leConnectionComplete->latency, + leConnectionComplete->supervisionTimeout, + leConnectionComplete->masterClockAccuracy); + + L2CAPSignaling.addConnection(leConnectionComplete->handle, + leConnectionComplete->role, + leConnectionComplete->peerBdaddrType, + leConnectionComplete->peerBdaddr, + leConnectionComplete->interval, + leConnectionComplete->latency, + leConnectionComplete->supervisionTimeout, + leConnectionComplete->masterClockAccuracy); + } + // uint8_t address[6]; + // uint8_t BDAddr[6]; + // for(int i=0; i<6; i++) BDAddr[5-i] = leConnectionComplete->peerBdaddr[i]; + // leReadPeerResolvableAddress(leConnectionComplete->peerBdaddrType,BDAddr,address); + // Serial.print("Resolving address: "); + // btct.printBytes(BDAddr, 6); + // Serial.print("BT answer : "); + // btct.printBytes(address, 6); + +#ifdef _BLE_TRACE_ + Serial.print("Resolved peer : "); + btct.printBytes(leConnectionComplete->peerResolvablePrivateAddress,6); + Serial.print("Resolved local : "); + btct.printBytes(leConnectionComplete->localResolvablePrivateAddress,6); +#endif + break; + } case CONN_COMPLETE:{ struct __attribute__ ((packed)) EvtLeConnectionComplete { uint8_t status; @@ -793,6 +1073,14 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) leConnectionComplete->supervisionTimeout, leConnectionComplete->masterClockAccuracy); } + uint8_t address[6]; + uint8_t BDAddr[6]; + for(int i=0; i<6; i++) BDAddr[5-i] = leConnectionComplete->peerBdaddr[i]; + // leReadPeerResolvableAddress(leConnectionComplete->peerBdaddrType,BDAddr,address); + // Serial.print("Resolving address: "); + // btct.printBytes(BDAddr, 6); + // Serial.print("BT answer : "); + // btct.printBytes(address, 6); break; } case ADVERTISING_REPORT:{ @@ -818,8 +1106,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) } break; } - case LONG_TERM_KEY_REQUEST: - { + case LONG_TERM_KEY_REQUEST:{ struct __attribute__ ((packed)) LTKRequest { uint8_t subEventCode; @@ -836,14 +1123,25 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.print("EDIV : "); btct.printBytes(ltkRequest->encryptedDiversifier,2); #endif - + // Load our LTK for this connection. + uint8_t peerAddr[7]; + uint8_t resolvableAddr[6]; + ATT.getPeerAddrWithType(ltkRequest->connectionHandle, peerAddr); + + if(ATT.getPeerResolvedAddress(ltkRequest->connectionHandle, resolvableAddr) + && !((ATT.getPeerEncryption(ltkRequest->connectionHandle) & PEER_ENCRYPTION::PAIRING_REQUEST)>0)){ + _getLTK(resolvableAddr, HCI.LTK); + }else{ + _getLTK(&peerAddr[1], HCI.LTK); + } + // } // Send our LTK back struct __attribute__ ((packed)) LTKReply { uint16_t connectionHandle; uint8_t LTK[16]; } ltkReply = {0,0}; - ltkReply.connectionHandle = ATT.getPeerEncrptingConnectionHandle(); + ltkReply.connectionHandle = ltkRequest->connectionHandle; for(int i=0; i<16; i++) ltkReply.LTK[15-i] = HCI.LTK[i]; int result = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::LONG_TERM_KEY_REPLY,sizeof(ltkReply), <kReply); @@ -875,8 +1173,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) } break; } - case REMOTE_CONN_PARAM_REQ: - { + case REMOTE_CONN_PARAM_REQ:{ struct __attribute__ ((packed)) RemoteConnParamReq { uint8_t subEventCode; uint16_t connectionHandle; @@ -914,8 +1211,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) sendCommand(OGF_LE_CTL << 10 | 0x20, sizeof(remoteConnParamReqReply), &remoteConnParamReqReply); break; } - case READ_LOCAL_P256_COMPLETE: - { + case READ_LOCAL_P256_COMPLETE:{ struct __attribute__ ((packed)) EvtReadLocalP256Complete{ uint8_t subEventCode; uint8_t status; @@ -1007,8 +1303,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) } break; } - case GENERATE_DH_KEY_COMPLETE: - { + case GENERATE_DH_KEY_COMPLETE:{ struct __attribute__ ((packed)) EvtLeDHKeyComplete{ uint8_t subEventCode; uint8_t status; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0b9c8302..de15bdf8 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -90,6 +90,17 @@ class HCIClass { virtual int leCancelConn(); virtual int leEncrypt(uint8_t* Key, uint8_t* plaintext, uint8_t* status, uint8_t* ciphertext); + virtual int saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); + virtual int leAddResolvingAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); + virtual int leStopResolvingAddresses(); + virtual int leStartResolvingAddresses(); + virtual int leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peerIdentityAddress, uint8_t* peerResolvableAddress); + + virtual int readStoredLKs(); + virtual int readStoredLK(uint8_t BD_ADDR[], uint8_t read_all = 0); + virtual int writeLK(uint8_t peerAddress[], uint8_t LK[]); + virtual int tryResolveAddress(uint8_t* BDAddr, uint8_t* address); + virtual int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data); virtual int disconnect(uint16_t handle); @@ -105,6 +116,12 @@ class HCIClass { uint8_t DHKey[32]; uint8_t localAddr[6]; uint8_t LTK[16]; + + int (*_storeIRK)(uint8_t* address, uint8_t* peerIrk); + int (*_getIRKs)(uint8_t* nIRKs,uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs); + int (*_storeLTK)(uint8_t*, uint8_t*); + int (*_getLTK)(uint8_t*, uint8_t*); + private: virtual void handleAclDataPkt(uint8_t plen, uint8_t pdata[]); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 3779eb29..512e7665 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -21,6 +21,7 @@ #include "ATT.h" #include "btct.h" #include "L2CAPSignaling.h" +#include "keyDistribution.h" #define CONNECTION_PARAMETER_UPDATE_REQUEST 0x12 #define CONNECTION_PARAMETER_UPDATE_RESPONSE 0x13 @@ -137,13 +138,22 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t initiatorKeyDistribution; uint8_t responderKeyDistribution; } *pairingRequest = (PairingRequest*)l2capSignalingHdr->data; + + + ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution); + ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); + KeyDistribution rkd(pairingRequest->responderKeyDistribution); uint8_t peerIOCap[3]; peerIOCap[0] = pairingRequest->authReq; peerIOCap[1] = pairingRequest->oobDataFlag; peerIOCap[2] = pairingRequest->ioCapability; ATT.setPeerIOCap(connectionHandle, peerIOCap); - + ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::PAIRING_REQUEST); +#ifdef _BLE_TRACE_ + Serial.print("Peer encryption : 0b"); + Serial.print(ATT.getPeerEncryption(connectionHandle), BIN); +#endif struct __attribute__ ((packed)) PairingResponse { uint8_t code; uint8_t ioCapability; @@ -154,7 +164,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t responderKeyDistribution; } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, 0b1011, 0b1011}; - HCI.sendAclPkt(connectionHandle, 0x06, sizeof(response), &response); + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); } else if (code == CONNECTION_PAIRING_RANDOM) { @@ -173,7 +183,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t } response = { CONNECTION_PAIRING_RANDOM, 0}; for(int i=0; i< 16; i++) response.Nb[15-i] = HCI.Nb[i]; - HCI.sendAclPkt(connectionHandle, 0x06, sizeof(response), &response); + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); } else if (code == CONNECTION_PAIRING_RESPONSE) { @@ -190,6 +200,31 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t Serial.println(pairingFailed->reason,HEX); #endif } + else if (code == CONNECTION_IDENTITY_INFORMATION){ + struct __attribute__ ((packed)) IdentityInformation { + uint8_t code; + uint8_t PeerIRK[16]; + } *identityInformation = (IdentityInformation*)data; + for(int i=0; i<16; i++) ATT.peerIRK[15-i] = identityInformation->PeerIRK[i]; +#ifdef _BLE_TRACE_ + Serial.println("Saved peer IRK"); +#endif + } + else if (code == CONNECTION_IDENTITY_ADDRESS){ + struct __attribute__ ((packed)) IdentityAddress { + uint8_t code; + uint8_t addressType; + uint8_t address[6]; + } *identityAddress = (IdentityAddress*)data; + // we can save this information now. + uint8_t peerAddress[6]; + for(int i; i<6; i++) peerAddress[5-i] = identityAddress->address[i]; + + HCI.saveNewAddress(identityAddress->addressType, peerAddress, ATT.peerIRK, ATT.localIRK); + if(HCI._storeLTK!=0){ + HCI._storeLTK(peerAddress, HCI.LTK); + } + } else if (code == CONNECTION_PAIRING_PUBLIC_KEY){ /// Received a public key struct __attribute__ ((packed)) ConnectionPairingPublicKey { @@ -211,7 +246,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t LE_COMMAND::READ_LOCAL_P256, }; - if(ATT.setPeerEncryption(connectionHandle,PEER_ENCRYPTION::REQUESTED_ENCRYPTION)){ + if(ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::REQUESTED_ENCRYPTION)){ #ifdef _BLE_TRACE_ Serial.println("[Info] Pairing public key"); Serial.println("Requested encryption stored."); @@ -244,7 +279,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t HCI.readBdAddr(); ATT.setPeerEncryption(connectionHandle, encryptionState); - if(encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED > 0){ + if((encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED) > 0){ // We've already calculated the DHKey so we can calculate our check and send it. uint8_t MacKey[16]; diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index 8fad5173..d78e328e 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -119,6 +119,38 @@ int BluetoothCryptoToolbox::f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[ return 1; } // AES_CMAC from RFC +int BluetoothCryptoToolbox::ah(uint8_t k[16], uint8_t r[3], uint8_t* result) +{ + uint8_t r_[16]; + int i=0; + for(i=0; i<16; i++) r_[i] = 0; + for(i=0; i<3; i++) r_[i+13] = r[i]; + uint8_t intermediate[16]; + AES_128(k,r_,intermediate); + for(i=0; i<3; i++){ + result[i] = intermediate[i+13]; + } + return 1; +} +void BluetoothCryptoToolbox::testAh() +{ + uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b}; + uint8_t r[3] = {0x70,0x81,0x94}; + uint8_t expected_AES[16] = {0x15,0x9d,0x5f,0xb7,0x2e,0xbe,0x23,0x11,0xa4,0x8c,0x1b,0xdc,0xc4,0x0d,0xfb,0xaa}; + uint8_t expected_final[3] = {0x0d,0xfb,0xaa}; + + for(int i=0; i<3; i++) r[2-i] = expected_final[3+i]; + uint8_t ourResult[3]; + ah(irk, expected_final, ourResult); + + + Serial.print("Expected : "); + printBytes(&expected_final[3], 3); + Serial.print("Actual : "); + printBytes(ourResult, 3); +} + + void BluetoothCryptoToolbox::AES_CMAC ( unsigned char *key, unsigned char *input, int length, unsigned char *mac ) { diff --git a/src/utility/btct.h b/src/utility/btct.h index 87e515af..43c0b0d6 100644 --- a/src/utility/btct.h +++ b/src/utility/btct.h @@ -13,9 +13,11 @@ class BluetoothCryptoToolbox{ int f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_slave[], uint8_t BD_ADDR_master[], uint8_t BD_ADDR_slave[], uint8_t MacKey[], uint8_t LTK[]); int f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[], uint8_t IOCap[], uint8_t A1[], uint8_t A2[], uint8_t Ex[]); + int ah(uint8_t k[16], uint8_t r[3], uint8_t result[3]); void test(); void testF5(); void testF6(); + void testAh(); private: int AES_128(uint8_t key[], uint8_t data_in[], uint8_t data_out[]); void leftshift_onebit(unsigned char *input,unsigned char *output); diff --git a/src/utility/keyDistribution.cpp b/src/utility/keyDistribution.cpp new file mode 100644 index 00000000..1a9fe099 --- /dev/null +++ b/src/utility/keyDistribution.cpp @@ -0,0 +1,24 @@ +#include "keyDistribution.h" + +KeyDistribution::KeyDistribution(){} +KeyDistribution::KeyDistribution(uint8_t octet):_octet(octet){} + +#define ENCKEY 0b00000001 +#define IDKEY 0b00000010 +#define SIGNKEY 0b00000100 +#define LINKKEY 0b00001000 +void KeyDistribution::setOctet( uint8_t octet){_octet = octet;} +uint8_t KeyDistribution::getOctet() {return _octet;} +// Ignored when SMP is on LE transport +bool KeyDistribution::EncKey(){ return (_octet & ENCKEY)>0;} +// Device shall distribute IRK using Identity information command followed by its address using Identity address information +bool KeyDistribution::IdKey(){ return (_octet & IDKEY)>0;} +// Device shall distribute CSRK using signing information command +bool KeyDistribution::SignKey(){ return (_octet & SIGNKEY)>0;} +// Device would like to derive BR/EDR from LTK +bool KeyDistribution::LinkKey(){ return (_octet & LINKKEY)>0;} + +void KeyDistribution::setEncKey(bool state) { _octet= state? _octet|ENCKEY : _octet&~ENCKEY;} +void KeyDistribution::setIdKey(bool state) { _octet= state? _octet|IDKEY : _octet&~IDKEY;} +void KeyDistribution::setSignKey(bool state){ _octet= state? _octet|SIGNKEY : _octet&~SIGNKEY;} +void KeyDistribution::setLinkKey(bool state){ _octet= state? _octet|LINKKEY : _octet&~LINKKEY;} \ No newline at end of file diff --git a/src/utility/keyDistribution.h b/src/utility/keyDistribution.h new file mode 100644 index 00000000..d78fcc1a --- /dev/null +++ b/src/utility/keyDistribution.h @@ -0,0 +1,29 @@ +#ifndef _KEY_DISTRIBUTION_H_ +#define _KEY_DISTRIBUTION_H_ +#include + +class KeyDistribution{ +public: + KeyDistribution(); + KeyDistribution(uint8_t octet); + void setOctet( uint8_t octet); + uint8_t getOctet(); + // Ignored when SMP is on LE transport + bool EncKey(); + // Device shall distribute IRK using Identity information command followed by its address using Identity address information + bool IdKey(); + // Device shall distribute CSRK using signing information command + bool SignKey(); + // Device would like to derive BR/EDR from LTK + bool LinkKey(); + + void setEncKey(bool state); + void setIdKey(bool state); + void setSignKey(bool state); + void setLinkKey(bool state); +private: + uint8_t _octet; + // 1. IRK by the slave2. BD ADDR by the slave3. CSRK by the slave4. IRK by the master5. BD_ADDR by the master6. CSRK by the master +}; + +#endif \ No newline at end of file From 1431f3de4f6a4d733b1438bb3fe72a3ea2b614d9 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Sat, 2 Jan 2021 23:08:27 +0000 Subject: [PATCH 005/112] Fixed packet fragmentation --- src/utility/HCI.cpp | 21 +++++++++++++---- src/utility/L2CAPSignaling.cpp | 13 +++++++++-- src/utility/bitDescriptions.cpp | 30 ++++++++++++++++++++++++ src/utility/bitDescriptions.h | 41 +++++++++++++++++++++++++++++++++ src/utility/keyDistribution.cpp | 2 +- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/utility/bitDescriptions.cpp create mode 100644 src/utility/bitDescriptions.h diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index c3d66848..376cfb9c 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -707,9 +707,7 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t cid; } *aclHdr = (HCIACLHdr*)pdata; -#ifdef _BLE_TRACE_ - Serial.println("Received data"); -#endif + uint16_t aclFlags = (aclHdr->handle & 0xf000) >> 12; if ((aclHdr->dlen - 4) != aclHdr->len) { @@ -729,6 +727,17 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) } if ((aclHdr->dlen - 4) != aclHdr->len) { +#ifdef _BLE_TRACE_ + Serial.println("Don't have full packet yet"); + Serial.print("Handle: "); + btct.printBytes((uint8_t*)&aclHdr->handle,2); + Serial.print("dlen: "); + btct.printBytes((uint8_t*)&aclHdr->dlen,2); + Serial.print("len: "); + btct.printBytes((uint8_t*)&aclHdr->len,2); + Serial.print("cid: "); + btct.printBytes((uint8_t*)&aclHdr->cid,2); +#endif // don't have the full packet yet return; } @@ -751,7 +760,11 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) #ifdef _BLE_TRACE_ Serial.println("Security data"); #endif - L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); + if (aclFlags == 0x1){ + L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_aclPktBuffer[sizeof(HCIACLHdr)]); + }else{ + L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); + } }else { struct __attribute__ ((packed)) { diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 512e7665..7d9c2c47 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -22,7 +22,7 @@ #include "btct.h" #include "L2CAPSignaling.h" #include "keyDistribution.h" - +#include "bitDescriptions.h" #define CONNECTION_PARAMETER_UPDATE_REQUEST 0x12 #define CONNECTION_PARAMETER_UPDATE_RESPONSE 0x13 @@ -143,6 +143,15 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution); ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); KeyDistribution rkd(pairingRequest->responderKeyDistribution); + AuthReq req(pairingRequest->authReq); +#ifdef _BLE_TRACE_ + Serial.print("Req has properties: "); + Serial.print(req.Bonding()?"bonding, ":"no bonding, "); + Serial.print(req.CT2()?"CT2, ":"no CT2, "); + Serial.print(req.KeyPress()?"KeyPress, ":"no KeyPress, "); + Serial.print(req.MITM()?"MITM, ":"no MITM, "); + Serial.print(req.SC()?"SC, ":"no SC, "); +#endif uint8_t peerIOCap[3]; peerIOCap[0] = pairingRequest->authReq; @@ -152,7 +161,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::PAIRING_REQUEST); #ifdef _BLE_TRACE_ Serial.print("Peer encryption : 0b"); - Serial.print(ATT.getPeerEncryption(connectionHandle), BIN); + Serial.println(ATT.getPeerEncryption(connectionHandle), BIN); #endif struct __attribute__ ((packed)) PairingResponse { uint8_t code; diff --git a/src/utility/bitDescriptions.cpp b/src/utility/bitDescriptions.cpp new file mode 100644 index 00000000..bf896bc1 --- /dev/null +++ b/src/utility/bitDescriptions.cpp @@ -0,0 +1,30 @@ +#include "bitDescriptions.h" + + +#define BONDING_BIT 0b00000001 +#define MITM_BIT 0b00000100 +#define SC_BIT 0b00001000 +#define KEYPRESS_BIT 0b00010000 +#define CT2_BIT 0b00100000 + + +AuthReq::AuthReq(){} +AuthReq::AuthReq(uint8_t octet):_octet(octet){} +bool AuthReq::Bonding(){ return (_octet & BONDING_BIT)>0;} +bool AuthReq::MITM(){ return (_octet & MITM_BIT)>0;} +bool AuthReq::SC(){ return (_octet & SC_BIT)>0;} +bool AuthReq::KeyPress(){ return (_octet & KEYPRESS_BIT)>0;} +bool AuthReq::CT2(){ return (_octet & CT2_BIT)>0;} + + +void AuthReq::setBonding(bool state) { _octet= state? _octet|BONDING_BIT : _octet&~BONDING_BIT;} +void AuthReq::setMITM(bool state) { _octet= state? _octet|MITM_BIT : _octet&~MITM_BIT;} +void AuthReq::setSC(bool state){ _octet= state? _octet|SC_BIT : _octet&~SC_BIT;} +void AuthReq::setKeyPress(bool state){ _octet= state? _octet|KEYPRESS_BIT : _octet&~KEYPRESS_BIT;} +void AuthReq::setCT2(bool state){ _octet= state? _octet|CT2_BIT : _octet&~CT2_BIT;} + +uint8_t _octet; + + +void AuthReq::setOctet( uint8_t octet){_octet = octet;} +uint8_t AuthReq::getOctet() {return _octet;} diff --git a/src/utility/bitDescriptions.h b/src/utility/bitDescriptions.h new file mode 100644 index 00000000..6d32c52a --- /dev/null +++ b/src/utility/bitDescriptions.h @@ -0,0 +1,41 @@ +#ifndef _BIT_DESCRIPTIONS_H_ +#define _BIT_DESCRIPTIONS_H_ +#include + +class AuthReq{ +public: + AuthReq(); + AuthReq(uint8_t octet); + void setOctet( uint8_t octet); + uint8_t getOctet(); + + + // The Bonding_Flags field is a 2-bit field that indicates the type of bonding being requested by the initiating device + bool Bonding(); + // The MITM field is a 1-bit flag that is set to one if the device is requesting MITM protection + bool MITM(); + // The SC field is a 1 bit flag. If LE Secure Connections pairing is supported by the device, then the SC field shall be set to 1, otherwise it shall be set to 0. + bool SC(); + // The keypress field is a 1-bit flag that is used only in the Passkey Entry protocol and shall be ignored in other protocols. + bool KeyPress(); + // The CT2 field is a 1-bit flag that shall be set to 1 upon transmission to indicate support for the h7 function. + bool CT2(); + + void setBonding(bool state); + void setMITM(bool state); + void setSC(bool state); + void setKeyPress(bool state); + void setCT2(bool state); +private: + uint8_t _octet; +}; + +enum IOCap { + DisplayOnly, + DisplayYesNo, + KeyboardOnly, + NoInputNoOutput, + KeyboardDisplay +}; + +#endif \ No newline at end of file diff --git a/src/utility/keyDistribution.cpp b/src/utility/keyDistribution.cpp index 1a9fe099..f754366c 100644 --- a/src/utility/keyDistribution.cpp +++ b/src/utility/keyDistribution.cpp @@ -1,6 +1,6 @@ #include "keyDistribution.h" -KeyDistribution::KeyDistribution(){} +KeyDistribution::KeyDistribution():_octet(0){} KeyDistribution::KeyDistribution(uint8_t octet):_octet(octet){} #define ENCKEY 0b00000001 From 6ef59a51a0bf12a12a76e4311ce6080a9f1bbfc4 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Sun, 3 Jan 2021 20:02:31 +0000 Subject: [PATCH 006/112] Android bugfix --- .../EncryptedBatteryMonitor.ino | 50 ++++++++++--------- src/utility/ATT.cpp | 5 +- src/utility/HCI.cpp | 7 +-- src/utility/L2CAPSignaling.cpp | 8 +-- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino index 338a374e..d4953b03 100644 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -44,34 +44,34 @@ void setup() { // IRKs are keys that identify the true owner of a random mac address. // Add IRKs of devices you are bonded with. - BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BADDR_TYPES, uint8_t*** BDAddrs, uint8_t*** IRKs){ + BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs){ // Set to number of devices *nIRKs = 2; *BDAddrs = new uint8_t*[*nIRKs]; *IRKs = new uint8_t*[*nIRKs]; - *BADDR_TYPES = new uint8_t[*nIRKs]; + *BDaddrTypes = new uint8_t[*nIRKs]; // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. - uint8_t iPhoneMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPhoneIRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPadMac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPadIRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; + uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - (*BADDR_TYPES)[0] = 0; - (*IRKs)[0] = new uint8_t[16]; - memcpy((*IRKs)[0],iPhoneIRK,16); + (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random (*BDAddrs)[0] = new uint8_t[6]; - memcpy((*BDAddrs)[0], iPhoneMac, 6); + (*IRKs)[0] = new uint8_t[16]; + memcpy((*IRKs)[0] , device1IRK,16); + memcpy((*BDAddrs)[0], device1Mac, 6); - (*BADDR_TYPES)[1] = 0; - (*IRKs)[1] = new uint8_t[16]; - memcpy((*IRKs)[1],iPadIRK,16); + (*BDaddrTypes)[1] = 0; (*BDAddrs)[1] = new uint8_t[6]; - memcpy((*BDAddrs)[1], iPadMac, 6); + (*IRKs)[1] = new uint8_t[16]; + memcpy((*IRKs)[1] , device2IRK,16); + memcpy((*BDAddrs)[1], device2Mac, 6); return 1; @@ -83,17 +83,18 @@ void setup() { btct.printBytes(address,6); // Set these to the MAC and LTK of your devices after bonding. - uint8_t iPhoneMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPhoneLTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPadMac [6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t iPadLTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if(memcmp(iPhoneMac, address, 6)==0){ - memcpy(LTK, iPhoneLTK, 16); + if(memcmp(device1Mac, address, 6) == 0) { + memcpy(LTK, device1LTK, 16); + return 1; + }else if(memcmp(device2Mac, address, 6) == 0) { + memcpy(LTK, device2LTK, 16); return 1; - }else if(memcmp(iPadMac, address, 6)==0){ - memcpy(LTK, iPadLTK, 16); } return 0; }); @@ -112,7 +113,8 @@ void setup() { return 1; }); - while(1){// begin initialization + while(1){ + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); delay(200); @@ -135,7 +137,7 @@ void setup() { batteryService.addCharacteristic(stringcharacteristic); batteryService.addCharacteristic(secretValue); - BLE.addService(batteryService); // Add the battery service + BLE.addService(batteryService); // Add the battery service batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic char* stringCharValue = new char[32]; stringCharValue = "string"; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 6ef6bc31..18556413 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -260,7 +260,10 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy Serial.println("Found match."); #endif }else{ - memset(_peers[peerIndex].resolvedAddress, 0, 6); +#ifdef _BLE_TRACE_ + Serial.println("No matching MAC"); +#endif + memset(&_peers[peerIndex].resolvedAddress, 0, 6); } if (_eventHandlers[BLEConnected]) { diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 376cfb9c..4dc78460 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -1218,10 +1218,11 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t minLength; uint16_t maxLength; } remoteConnParamReqReply; - memcpy(&remoteConnParamReqReply, &remoteConnParamReq->connectionHandle, sizeof(remoteConnParamReq-1)); + memcpy(&remoteConnParamReqReply, &remoteConnParamReq->connectionHandle, sizeof(RemoteConnParamReq)-1); + remoteConnParamReqReply.minLength = 0x000F; remoteConnParamReqReply.maxLength = 0x0FFF; - sendCommand(OGF_LE_CTL << 10 | 0x20, sizeof(remoteConnParamReqReply), &remoteConnParamReqReply); + sendCommand(OGF_LE_CTL << 10 | 0x20, sizeof(RemoteConnParamReqReply), &remoteConnParamReqReply); break; } case READ_LOCAL_P256_COMPLETE:{ @@ -1381,7 +1382,7 @@ int HCIClass::leEncrypt(uint8_t* key, uint8_t* plaintext, uint8_t* status, uint8 leEncryptCommand.plaintext[15-i] = plaintext[i]; } - int res = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::ENCRYPT, sizeof(leEncryptCommand), &leEncryptCommand); + int res = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::ENCRYPT, 32, &leEncryptCommand); if(res == 0){ #ifdef _BLE_TRACE_ Serial.print("Copying from command Response length: "); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 7d9c2c47..f7f93b84 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -144,6 +144,8 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); KeyDistribution rkd(pairingRequest->responderKeyDistribution); AuthReq req(pairingRequest->authReq); + KeyDistribution responseKD = KeyDistribution(); + responseKD.setIdKey(true); #ifdef _BLE_TRACE_ Serial.print("Req has properties: "); Serial.print(req.Bonding()?"bonding, ":"no bonding, "); @@ -171,7 +173,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t maxEncSize; uint8_t initiatorKeyDistribution; uint8_t responderKeyDistribution; - } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, 0b1011, 0b1011}; + } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, responseKD.getOctet(), responseKD.getOctet()}; HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); } @@ -316,9 +318,9 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t Serial.println("Calculate f5, f6:"); Serial.print("DH : "); btct.printBytes(HCI.DHKey,32); - Serial.println("Na : "); + Serial.print("Na : "); btct.printBytes(HCI.Na,16); - Serial.println("Nb : "); + Serial.print("Nb : "); btct.printBytes(HCI.Nb,16); Serial.print("MAC : "); btct.printBytes(MacKey,16); From 0aa2e87a7c322931793657b8096afd8930a312d4 Mon Sep 17 00:00:00 2001 From: eltos Date: Sun, 3 Jan 2021 23:25:59 +0100 Subject: [PATCH 007/112] Handle remote DHKey confirmation before own DHKey --- src/utility/HCI.cpp | 74 +++++++++++++++++++++++++++++++++- src/utility/HCI.h | 1 + src/utility/L2CAPSignaling.cpp | 12 +++++- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 4dc78460..014e25a3 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -1345,13 +1345,83 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) #endif encryption |= PEER_ENCRYPTION::DH_KEY_CALULATED; ATT.setPeerEncryption(connectionHandle, encryption); + + if((encryption & PEER_ENCRYPTION::RECEIVED_DH_CHECK) > 0){ +#ifdef _BLE_TRACE_ + Serial.println("Recieved DHKey check already so calculate f5, f6 now."); +#endif + + uint8_t BD_ADDR_REMOTE[7]; + ATT.getPeerAddrWithType(connectionHandle, BD_ADDR_REMOTE); + + + uint8_t MacKey[16]; + uint8_t localAddress[7]; + + memcpy(&localAddress[1],HCI.localAddr,6); + localAddress[0] = 0; // IOT 33 uses a static address + + btct.f5(HCI.DHKey,HCI.Na,HCI.Nb,BD_ADDR_REMOTE,localAddress,MacKey,HCI.LTK); + + uint8_t Ea[16]; + uint8_t Eb[16]; + uint8_t R[16]; + uint8_t MasterIOCap[3]; + uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; + + ATT.getPeerIOCap(connectionHandle, MasterIOCap); + for(int i=0; i<16; i++) R[i] = 0; + + btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, BD_ADDR_REMOTE, localAddress, Ea); + btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, BD_ADDR_REMOTE, Eb); + + #ifdef _BLE_TRACE_ - if(encryption | PEER_ENCRYPTION::RECEIVED_DH_CHECK){ - Serial.println("Recieved DHKey check already so calculate f5, f6."); + Serial.println("Calculate f5, f6:"); + Serial.print("DH : "); + btct.printBytes(HCI.DHKey,32); + Serial.print("Na : "); + btct.printBytes(HCI.Na,16); + Serial.print("Nb : "); + btct.printBytes(HCI.Nb,16); + Serial.print("MAC : "); + btct.printBytes(MacKey,16); + // Serial.print("Expected MAC: "); + // printBytes(EXPECTED_MAC, 16); + Serial.print("LTK : "); + btct.printBytes(HCI.LTK,16); + // Serial.print("Expected LTK: "); + // printBytes(EXPECTED_LTK, 16); + Serial.print("Expected Ex : "); + btct.printBytes(HCI.remoteDHKeyCheckBuffer, 16); + Serial.print("Ea : "); + btct.printBytes(Ea, 16); + Serial.print("Eb : "); + btct.printBytes(Eb,16); + Serial.print("Local Addr : "); + btct.printBytes(localAddress, 7); + Serial.print("LocalIOCap : "); + btct.printBytes(SlaveIOCap, 3); + Serial.print("MasterAddr : "); + btct.printBytes(BD_ADDR_REMOTE, 7); + Serial.print("MasterIOCAP : "); + btct.printBytes(MasterIOCap, 3); + Serial.println("Send Eb Back."); +#endif + uint8_t ret[17]; + ret[0] = 0x0d; + for(int i=0; istatus, HEX); #endif diff --git a/src/utility/HCI.h b/src/utility/HCI.h index de15bdf8..4ed9e82e 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -111,6 +111,7 @@ class HCIClass { // TODO: Send command be private again & use ATT implementation within ATT. virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); uint8_t remotePublicKeyBuffer[64]; + uint8_t remoteDHKeyCheckBuffer[16]; uint8_t Na[16]; uint8_t Nb[16]; uint8_t DHKey[32]; diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index f7f93b84..60152a7d 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -290,7 +290,14 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t HCI.readBdAddr(); ATT.setPeerEncryption(connectionHandle, encryptionState); - if((encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED) > 0){ + if((encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED) == 0){ +#ifdef _BLE_TRACE_ + Serial.println("DHKey not yet ready, will calculate f5, f6 later"); +#endif + // store RemoteDHKeyCheck for later check + memcpy(HCI.remoteDHKeyCheckBuffer,RemoteDHKeyCheck,16); + + } else { // We've already calculated the DHKey so we can calculate our check and send it. uint8_t MacKey[16]; @@ -312,7 +319,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, BD_ADDR_REMOTE, localAddress, Ea); btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, BD_ADDR_REMOTE, Eb); - + #ifdef _BLE_TRACE_ Serial.println("Calculate f5, f6:"); @@ -353,6 +360,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t ret[sizeof(Eb)-i] = Eb[i]; } HCI.sendAclPkt(connectionHandle, 0x06, sizeof(ret), ret ); + ATT.setPeerEncryption(connectionHandle, encryptionState | PEER_ENCRYPTION::SENT_DH_CHECK); } } } From 750b7f179546520f6929db2485fd40ba747ebe2f Mon Sep 17 00:00:00 2001 From: eltos Date: Sun, 3 Jan 2021 23:45:38 +0100 Subject: [PATCH 008/112] Actually check remote DHKey --- src/utility/HCI.cpp | 35 +++++++++++++++++++++++++++------ src/utility/L2CAPSignaling.cpp | 36 +++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 014e25a3..157ed7d3 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -24,6 +24,8 @@ #include "btct.h" #include "HCI.h" +//#define _BLE_TRACE_ + #define HCI_COMMAND_PKT 0x01 #define HCI_ACLDATA_PKT 0x02 #define HCI_EVENT_PKT 0x04 @@ -1408,13 +1410,34 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) btct.printBytes(MasterIOCap, 3); Serial.println("Send Eb Back."); #endif - uint8_t ret[17]; - ret[0] = 0x0d; - for(int i=0; i Date: Mon, 4 Jan 2021 11:07:36 +0100 Subject: [PATCH 009/112] Move LTK signaling and confirm to separate method --- src/utility/HCI.cpp | 89 +------------------ src/utility/HCI.h | 2 + src/utility/L2CAPSignaling.cpp | 150 +++++++++++++++------------------ src/utility/L2CAPSignaling.h | 6 ++ 4 files changed, 80 insertions(+), 167 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 157ed7d3..4c97f79d 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -1337,7 +1337,6 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) break; } - uint8_t encryption = ATT.getPeerEncryption(connectionHandle); for(int i=0; i<32; i++) DHKey[31-i] = evtLeDHKeyComplete->DHKey[i]; @@ -1345,98 +1344,14 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.println("Stored our DHKey:"); btct.printBytes(DHKey,32); #endif - encryption |= PEER_ENCRYPTION::DH_KEY_CALULATED; + uint8_t encryption = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::DH_KEY_CALULATED; ATT.setPeerEncryption(connectionHandle, encryption); if((encryption & PEER_ENCRYPTION::RECEIVED_DH_CHECK) > 0){ #ifdef _BLE_TRACE_ Serial.println("Recieved DHKey check already so calculate f5, f6 now."); #endif - - uint8_t BD_ADDR_REMOTE[7]; - ATT.getPeerAddrWithType(connectionHandle, BD_ADDR_REMOTE); - - - uint8_t MacKey[16]; - uint8_t localAddress[7]; - - memcpy(&localAddress[1],HCI.localAddr,6); - localAddress[0] = 0; // IOT 33 uses a static address - - btct.f5(HCI.DHKey,HCI.Na,HCI.Nb,BD_ADDR_REMOTE,localAddress,MacKey,HCI.LTK); - - uint8_t Ea[16]; - uint8_t Eb[16]; - uint8_t R[16]; - uint8_t MasterIOCap[3]; - uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; - - ATT.getPeerIOCap(connectionHandle, MasterIOCap); - for(int i=0; i<16; i++) R[i] = 0; - - btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, BD_ADDR_REMOTE, localAddress, Ea); - btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, BD_ADDR_REMOTE, Eb); - - -#ifdef _BLE_TRACE_ - Serial.println("Calculate f5, f6:"); - Serial.print("DH : "); - btct.printBytes(HCI.DHKey,32); - Serial.print("Na : "); - btct.printBytes(HCI.Na,16); - Serial.print("Nb : "); - btct.printBytes(HCI.Nb,16); - Serial.print("MAC : "); - btct.printBytes(MacKey,16); - // Serial.print("Expected MAC: "); - // printBytes(EXPECTED_MAC, 16); - Serial.print("LTK : "); - btct.printBytes(HCI.LTK,16); - // Serial.print("Expected LTK: "); - // printBytes(EXPECTED_LTK, 16); - Serial.print("Expected Ex : "); - btct.printBytes(HCI.remoteDHKeyCheckBuffer, 16); - Serial.print("Ea : "); - btct.printBytes(Ea, 16); - Serial.print("Eb : "); - btct.printBytes(Eb,16); - Serial.print("Local Addr : "); - btct.printBytes(localAddress, 7); - Serial.print("LocalIOCap : "); - btct.printBytes(SlaveIOCap, 3); - Serial.print("MasterAddr : "); - btct.printBytes(BD_ADDR_REMOTE, 7); - Serial.print("MasterIOCAP : "); - btct.printBytes(MasterIOCap, 3); - Serial.println("Send Eb Back."); -#endif - // Check if RemoteDHKeyCheck = Ea - bool EaCheck = true; - for(int i = 0; i < 16; i++){ - if (Ea[i] != HCI.remoteDHKeyCheckBuffer[i]){ - EaCheck = false; - } - } - - if (EaCheck){ - // Send our confirmation value to complete authentication stage 2 - uint8_t ret[17]; - ret[0] = CONNECTION_PAIRING_DHKEY_CHECK; - for(int i=0; i +#include "L2CAPSignaling.h" + #define OGF_LINK_CTL 0x01 #define OGF_HOST_CTL 0x03 #define OGF_INFO_PARAM 0x04 diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 322bd13d..4adeaa0d 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -278,11 +278,8 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t else if(code == CONNECTION_PAIRING_DHKEY_CHECK) { uint8_t RemoteDHKeyCheck[16]; - uint8_t BD_ADDR_REMOTE[7]; - ATT.getPeerAddrWithType(connectionHandle, BD_ADDR_REMOTE); for(int i=0; i<16; i++) RemoteDHKeyCheck[15-i] = l2capSignalingHdr->data[i]; - uint8_t encryptionState = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::RECEIVED_DH_CHECK; - + #ifdef _BLE_TRACE_ Serial.println("[Info] DH Key check"); @@ -290,7 +287,9 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t btct.printBytes(RemoteDHKeyCheck, 16); #endif - HCI.readBdAddr(); + + + uint8_t encryptionState = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::RECEIVED_DH_CHECK; ATT.setPeerEncryption(connectionHandle, encryptionState); if((encryptionState & PEER_ENCRYPTION::DH_KEY_CALULATED) == 0){ #ifdef _BLE_TRACE_ @@ -301,89 +300,80 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t } else { // We've already calculated the DHKey so we can calculate our check and send it. + smCalculateLTKandConfirm(connectionHandle, RemoteDHKeyCheck); - uint8_t MacKey[16]; - uint8_t localAddress[7]; - - memcpy(&localAddress[1],HCI.localAddr,6); - localAddress[0] = 0; // IOT 33 uses a static address + } + } +} - btct.f5(HCI.DHKey,HCI.Na,HCI.Nb,BD_ADDR_REMOTE,localAddress,MacKey,HCI.LTK); - - uint8_t Ea[16]; - uint8_t Eb[16]; - uint8_t R[16]; - uint8_t MasterIOCap[3]; - uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; - - ATT.getPeerIOCap(connectionHandle, MasterIOCap); - for(int i=0; i<16; i++) R[i] = 0; - - btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, BD_ADDR_REMOTE, localAddress, Ea); - btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, BD_ADDR_REMOTE, Eb); - +void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expectedEa[]) +{ // Authentication stage 2: LTK Calculation + + uint8_t localAddress[7]; + uint8_t remoteAddress[7]; + ATT.getPeerAddrWithType(handle, remoteAddress); + + HCI.readBdAddr(); + memcpy(&localAddress[1],HCI.localAddr,6); + localAddress[0] = 0; // IOT 33 uses a static address // TODO: confirm for Nano BLE + + // Compute the LTK and MacKey + uint8_t MacKey[16]; + btct.f5(HCI.DHKey, HCI.Na, HCI.Nb, remoteAddress, localAddress, MacKey, HCI.LTK); + + // Compute Ea and Eb + uint8_t Ea[16]; + uint8_t Eb[16]; + uint8_t R[16]; + uint8_t MasterIOCap[3]; + uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; + + ATT.getPeerIOCap(handle, MasterIOCap); + for(int i=0; i<16; i++) R[i] = 0; + + btct.f6(MacKey, HCI.Na,HCI.Nb,R, MasterIOCap, remoteAddress, localAddress, Ea); + btct.f6(MacKey, HCI.Nb,HCI.Na,R, SlaveIOCap, localAddress, remoteAddress, Eb); #ifdef _BLE_TRACE_ - Serial.println("Calculate f5, f6:"); - Serial.print("DH : "); - btct.printBytes(HCI.DHKey,32); - Serial.print("Na : "); - btct.printBytes(HCI.Na,16); - Serial.print("Nb : "); - btct.printBytes(HCI.Nb,16); - Serial.print("MAC : "); - btct.printBytes(MacKey,16); - // Serial.print("Expected MAC: "); - // printBytes(EXPECTED_MAC, 16); - Serial.print("LTK : "); - btct.printBytes(HCI.LTK,16); - // Serial.print("Expected LTK: "); - // printBytes(EXPECTED_LTK, 16); - Serial.print("Expected Ex : "); - btct.printBytes(RemoteDHKeyCheck, 16); - Serial.print("Ea : "); - btct.printBytes(Ea, 16); - Serial.print("Eb : "); - btct.printBytes(Eb,16); - Serial.print("Local Addr : "); - btct.printBytes(localAddress, 7); - Serial.print("LocalIOCap : "); - btct.printBytes(SlaveIOCap, 3); - Serial.print("MasterAddr : "); - btct.printBytes(BD_ADDR_REMOTE, 7); - Serial.print("MasterIOCAP : "); - btct.printBytes(MasterIOCap, 3); - Serial.println("Send Eb Back."); + Serial.println("Calculate and confirm LTK via f5, f6:"); + Serial.print("DHKey : "); btct.printBytes(HCI.DHKey,32); + Serial.print("Na : "); btct.printBytes(HCI.Na,16); + Serial.print("Nb : "); btct.printBytes(HCI.Nb,16); + Serial.print("MacKey : "); btct.printBytes(MacKey,16); + Serial.print("LTK : "); btct.printBytes(HCI.LTK,16); + Serial.print("Expected Ea: "); btct.printBytes(expectedEa, 16); + Serial.print("Ea : "); btct.printBytes(Ea, 16); + Serial.print("Eb : "); btct.printBytes(Eb,16); + Serial.print("Local Addr : "); btct.printBytes(localAddress, 7); + Serial.print("LocalIOCap : "); btct.printBytes(SlaveIOCap, 3); + Serial.print("MasterAddr : "); btct.printBytes(remoteAddress, 7); + Serial.print("MasterIOCAP: "); btct.printBytes(MasterIOCap, 3); #endif - // Check if RemoteDHKeyCheck = Ea - bool EaCheck = true; - for(int i = 0; i < 16; i++){ - if (Ea[i] != RemoteDHKeyCheck[i]){ - EaCheck = false; - } - } - - if (EaCheck){ - // Send our confirmation value to complete authentication stage 2 - uint8_t ret[17]; - ret[0] = CONNECTION_PAIRING_DHKEY_CHECK; - for(int i=0; i Date: Mon, 4 Jan 2021 12:20:06 +0100 Subject: [PATCH 010/112] Add method to control and query pairing --- .../EncryptedBatteryMonitor.ino | 67 +++++++---- keywords.txt | 3 + src/local/BLELocalDevice.cpp | 26 +++++ src/local/BLELocalDevice.h | 10 ++ src/utility/ATT.cpp | 26 +++++ src/utility/ATT.h | 2 + src/utility/L2CAPSignaling.cpp | 105 +++++++++++------- src/utility/L2CAPSignaling.h | 13 ++- 8 files changed, 190 insertions(+), 62 deletions(-) diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino index d4953b03..fd40f5ee 100644 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -18,6 +18,14 @@ #include +#define PAIR_BUTTON D3 // button for pairing +#define PAIR_LED 24 // LED used to signal pairing +#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic +#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms + +#define CTRL_LED LED_BUILTIN + + // BLE Battery Service BLEService batteryService("180F"); @@ -31,13 +39,17 @@ BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); int oldBatteryLevel = 0; // last battery level reading from analog input -long previousMillis = 0; // last time the battery level was checked, in ms +unsigned long previousMillis = 0; // last time the battery level was checked, in ms +unsigned long pairingStarted = 0; // pairing start time when button is pressed +bool wasConnected = 0; void setup() { Serial.begin(9600); // initialize serial communication while (!Serial); - pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + pinMode(PAIR_LED, OUTPUT); + pinMode(PAIR_BUTTON, INPUT_PULLUP); Serial.println("Serial connected"); @@ -145,6 +157,9 @@ void setup() { secretValue.writeValue(0); delay(1000); + + // prevent pairing until button is pressed (will show a pairing rejected message) + BLE.setPairable(false); /* Start advertising BLE. It will start continuously transmitting BLE advertising packets and will be visible to remote BLE central devices @@ -169,30 +184,44 @@ void loop() { // wait for a BLE central BLEDevice central = BLE.central(); + + // If button is pressed, allow pairing for 30 sec + if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ + pairingStarted = millis(); + BLE.setPairable(Pairable::ONCE); + Serial.println("Accepting pairing for 30s"); + } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ + BLE.setPairable(false); + Serial.println("No longer accepting pairing"); + } + // Make LED blink while pairing is allowed + digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); + + // if a central is connected to the peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's BT address: - Serial.println(central.address()); + if (central && central.connected()) { + if (!wasConnected){ + wasConnected = true; + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + } // check the battery level every 200ms // while the central is connected: - while (central.connected()) { - long currentMillis = millis(); - // if 200ms have passed, check the battery level: - if (currentMillis - previousMillis >= 1000) { - previousMillis = currentMillis; - updateBatteryLevel(); - if(secretValue.value()>0){ - digitalWrite(13,HIGH); - }else{ - digitalWrite(13,LOW); - } - } + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 1000) { + previousMillis = currentMillis; + updateBatteryLevel(); + digitalWrite(CTRL_LED, secretValue.value()>0 ? HIGH : LOW); } + } else if (wasConnected){ + wasConnected = false; Serial.print("Disconnected from central: "); Serial.println(central.address()); } + } void updateBatteryLevel() { @@ -208,4 +237,4 @@ void updateBatteryLevel() { batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic oldBatteryLevel = batteryLevel; // save the level for next comparison } -} +} \ No newline at end of file diff --git a/keywords.txt b/keywords.txt index 464cac72..effdfbca 100644 --- a/keywords.txt +++ b/keywords.txt @@ -77,9 +77,12 @@ setEventHandler KEYWORD2 setAdvertisingInterval KEYWORD2 setConnectionInterval KEYWORD2 setConnectable KEYWORD2 +setPairable KEYWORD2 setTimeout KEYWORD2 debug KEYWORD2 noDebug KEYWORD2 +pairable KEYWORD2 +paired KEYWORD2 properties KEYWORD2 valueSize KEYWORD2 diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 49cc6603..029fb488 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -214,6 +214,16 @@ bool BLELocalDevice::connected() const return ATT.connected(); } +/* + * Whether there is at least one paired device + */ +bool BLELocalDevice::paired() +{ + HCI.poll(); + + return ATT.paired(); +} + bool BLELocalDevice::disconnect() { return ATT.disconnect(); @@ -395,6 +405,22 @@ void BLELocalDevice::setTimeout(unsigned long timeout) ATT.setTimeout(timeout); } +/* + * Control whether pairing is allowed or rejected + * Use true/false or the Pairable enum + */ +void BLELocalDevice::setPairable(uint8_t pairable) +{ + L2CAPSignaling.setPairingEnabled(pairable); +} + +/* + * Whether pairing is currently allowed + */ +bool BLELocalDevice::pairable() +{ + return L2CAPSignaling.isPairingEnabled(); +} void BLELocalDevice::setGetIRKs(int (*getIRKs)(uint8_t* nIRKs, uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs)){ HCI._getIRKs = getIRKs; diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 22a5f589..0c471938 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -24,6 +24,12 @@ #include "BLEService.h" #include "BLEAdvertisingData.h" +enum Pairable { + NO = 0, + YES = 1, + ONCE = 2, +}; + class BLELocalDevice { public: BLELocalDevice(); @@ -80,6 +86,10 @@ class BLELocalDevice { virtual void debug(Stream& stream); virtual void noDebug(); + + virtual void setPairable(uint8_t pairable); + virtual bool pairable(); + virtual bool paired(); /// TODO: Put in actual variable names virtual void setStoreIRK(int (*storeIRK)(uint8_t*, uint8_t*)); diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 18556413..a5166217 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -497,6 +497,32 @@ bool ATTClass::connected(uint16_t handle) const return false; } +/* + * Return true if any of the known devices is paired (peer encrypted) + * Does not check if the paired device is also connected + */ +bool ATTClass::paired() const +{ + for(int i=0; i 0){ + return true; + } + } + return false; +} + +/* + * Return true if the specified device is paired (peer encrypted) + */ +bool ATTClass::paired(uint16_t handle) const +{ + for(int i=0; i 0; + } + return false; // unknown handle +} + uint16_t ATTClass::mtu(uint16_t handle) const { for (int i = 0; i < ATT_MAX_PEERS; i++) { diff --git a/src/utility/ATT.h b/src/utility/ATT.h index 1c8910c3..c9f007f9 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -75,6 +75,8 @@ class ATTClass { virtual bool connected() const; virtual bool connected(uint8_t addressType, const uint8_t address[6]) const; virtual bool connected(uint16_t handle) const; + virtual bool paired() const; + virtual bool paired(uint16_t handle) const; virtual uint16_t mtu(uint16_t handle) const; virtual bool disconnect(); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 4adeaa0d..622f2178 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -32,6 +32,7 @@ L2CAPSignalingClass::L2CAPSignalingClass() : _minInterval(0), _maxInterval(0), _supervisionTimeout(0) + ,_pairing_enabled(1) { } @@ -131,53 +132,64 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t btct.printBytes(data,dlen); #endif if (code == CONNECTION_PAIRING_REQUEST) { - // 0x1 - struct __attribute__ ((packed)) PairingRequest { - uint8_t ioCapability; - uint8_t oobDataFlag; - uint8_t authReq; - uint8_t maxEncSize; - uint8_t initiatorKeyDistribution; - uint8_t responderKeyDistribution; - } *pairingRequest = (PairingRequest*)l2capSignalingHdr->data; - - - ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution); - ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); - KeyDistribution rkd(pairingRequest->responderKeyDistribution); - AuthReq req(pairingRequest->authReq); - KeyDistribution responseKD = KeyDistribution(); - responseKD.setIdKey(true); + + if (isPairingEnabled()){ + if (_pairing_enabled >= 2) _pairing_enabled = 0; // 2 = pair once only + + // 0x1 + struct __attribute__ ((packed)) PairingRequest { + uint8_t ioCapability; + uint8_t oobDataFlag; + uint8_t authReq; + uint8_t maxEncSize; + uint8_t initiatorKeyDistribution; + uint8_t responderKeyDistribution; + } *pairingRequest = (PairingRequest*)l2capSignalingHdr->data; + + + ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution); + ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); + KeyDistribution rkd(pairingRequest->responderKeyDistribution); + AuthReq req(pairingRequest->authReq); + KeyDistribution responseKD = KeyDistribution(); + responseKD.setIdKey(true); #ifdef _BLE_TRACE_ - Serial.print("Req has properties: "); - Serial.print(req.Bonding()?"bonding, ":"no bonding, "); - Serial.print(req.CT2()?"CT2, ":"no CT2, "); - Serial.print(req.KeyPress()?"KeyPress, ":"no KeyPress, "); - Serial.print(req.MITM()?"MITM, ":"no MITM, "); - Serial.print(req.SC()?"SC, ":"no SC, "); + Serial.print("Req has properties: "); + Serial.print(req.Bonding()?"bonding, ":"no bonding, "); + Serial.print(req.CT2()?"CT2, ":"no CT2, "); + Serial.print(req.KeyPress()?"KeyPress, ":"no KeyPress, "); + Serial.print(req.MITM()?"MITM, ":"no MITM, "); + Serial.print(req.SC()?"SC, ":"no SC, "); #endif - uint8_t peerIOCap[3]; - peerIOCap[0] = pairingRequest->authReq; - peerIOCap[1] = pairingRequest->oobDataFlag; - peerIOCap[2] = pairingRequest->ioCapability; - ATT.setPeerIOCap(connectionHandle, peerIOCap); - ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::PAIRING_REQUEST); + uint8_t peerIOCap[3]; + peerIOCap[0] = pairingRequest->authReq; + peerIOCap[1] = pairingRequest->oobDataFlag; + peerIOCap[2] = pairingRequest->ioCapability; + ATT.setPeerIOCap(connectionHandle, peerIOCap); + ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::PAIRING_REQUEST); #ifdef _BLE_TRACE_ - Serial.print("Peer encryption : 0b"); - Serial.println(ATT.getPeerEncryption(connectionHandle), BIN); + Serial.print("Peer encryption : 0b"); + Serial.println(ATT.getPeerEncryption(connectionHandle), BIN); #endif - struct __attribute__ ((packed)) PairingResponse { - uint8_t code; - uint8_t ioCapability; - uint8_t oobDataFlag; - uint8_t authReq; - uint8_t maxEncSize; - uint8_t initiatorKeyDistribution; - uint8_t responderKeyDistribution; - } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, responseKD.getOctet(), responseKD.getOctet()}; - - HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); + struct __attribute__ ((packed)) PairingResponse { + uint8_t code; + uint8_t ioCapability; + uint8_t oobDataFlag; + uint8_t authReq; + uint8_t maxEncSize; + uint8_t initiatorKeyDistribution; + uint8_t responderKeyDistribution; + } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, responseKD.getOctet(), responseKD.getOctet()}; + + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); + + } else { + // Pairing not enabled + uint8_t ret[2] = {CONNECTION_PAIRING_FAILED, 0x05}; // reqect pairing + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(ret), ret); + ATT.setPeerEncryption(connectionHandle, NO_ENCRYPTION); + } } else if (code == CONNECTION_PAIRING_RANDOM) { @@ -392,6 +404,15 @@ void L2CAPSignalingClass::setSupervisionTimeout(uint16_t supervisionTimeout) _supervisionTimeout = supervisionTimeout; } +void L2CAPSignalingClass::setPairingEnabled(uint8_t enabled) +{ + _pairing_enabled = enabled; +} +bool L2CAPSignalingClass::isPairingEnabled() +{ + return _pairing_enabled > 0; +} + void L2CAPSignalingClass::connectionParameterUpdateRequest(uint16_t handle, uint8_t identifier, uint8_t dlen, uint8_t data[]) { struct __attribute__ ((packed)) L2CAPConnectionParameterUpdateRequest { diff --git a/src/utility/L2CAPSignaling.h b/src/utility/L2CAPSignaling.h index 7fc64d4f..f8a361ee 100644 --- a/src/utility/L2CAPSignaling.h +++ b/src/utility/L2CAPSignaling.h @@ -41,8 +41,15 @@ #define CONNECTION_PAIRING_DHKEY_CHECK 0x0D #define CONNECTION_PAIRING_KEYPRESS 0x0E +#define IOCAP_DISPLAY_ONLY 0x00 +#define IOCAP_DISPLAY_YES_NO 0x01 +#define IOCAP_KEYBOARD_ONLY 0x02 +#define IOCAP_NO_INPUT_NO_OUTPUT 0x03 +#define IOCAP_KEYBOARD_DISPLAY 0x04 + + #define LOCAL_AUTHREQ 0b00101101 -#define LOCAL_IOCAP 0x3 +#define LOCAL_IOCAP IOCAP_NO_INPUT_NO_OUTPUT // will use JustWorks pairing class L2CAPSignalingClass { public: @@ -63,6 +70,9 @@ class L2CAPSignalingClass { virtual void setConnectionInterval(uint16_t minInterval, uint16_t maxInterval); virtual void setSupervisionTimeout(uint16_t supervisionTimeout); + + virtual void setPairingEnabled(uint8_t enabled); + virtual bool isPairingEnabled(); @@ -78,6 +88,7 @@ class L2CAPSignalingClass { uint16_t _minInterval; uint16_t _maxInterval; uint16_t _supervisionTimeout; + uint8_t _pairing_enabled; }; extern L2CAPSignalingClass& L2CAPSignaling; From d9fb4bcfbf394d98aac93b9b3d4b087552cf4a22 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Mon, 4 Jan 2021 19:04:01 +0000 Subject: [PATCH 011/112] Secure random & reject unknown LTK --- src/local/BLELocalDevice.h | 18 +++-- src/utility/HCI.cpp | 132 +++++++++++++++++++++++---------- src/utility/HCI.h | 30 +++++--- src/utility/L2CAPSignaling.cpp | 18 +++-- 4 files changed, 137 insertions(+), 61 deletions(-) diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 22a5f589..d06664da 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -81,11 +81,19 @@ class BLELocalDevice { virtual void debug(Stream& stream); virtual void noDebug(); -/// TODO: Put in actual variable names - virtual void setStoreIRK(int (*storeIRK)(uint8_t*, uint8_t*)); - virtual void setGetIRKs(int (*getIRKs)(uint8_t* nIRKs, uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs)); - virtual void setStoreLTK(int (*storeLTK)(uint8_t*, uint8_t*)); - virtual void setGetLTK(int (*getLTK)(uint8_t*, uint8_t*)); + // address - The mac to store + // IRK - The IRK to store with this mac + virtual void setStoreIRK(int (*storeIRK)(uint8_t* address, uint8_t* IRK)); + // nIRKs - the number of IRKs being provided. + // BDAddrType - an array containing the type of each address (0 public, 1 static random) + // BDAddrs - an array containing the list of addresses + virtual void setGetIRKs(int (*getIRKs)(uint8_t* nIRKs, uint8_t** BDAddrType, uint8_t*** BDAddrs, uint8_t*** IRKs)); + // address - the address to store [6 bytes] + // LTK - the LTK to store with this mac [16 bytes] + virtual void setStoreLTK(int (*storeLTK)(uint8_t* address, uint8_t* LTK)); + // address - The mac address needing its LTK + // LTK - 16 octet LTK for the mac address + virtual void setGetLTK(int (*getLTK)(uint8_t* address, uint8_t* LTK)); uint8_t BDaddress[6]; protected: diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 4dc78460..1a604d79 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -23,6 +23,8 @@ #include "L2CAPSignaling.h" #include "btct.h" #include "HCI.h" +#include "bitDescriptions.h" +// #define _BLE_TRACE_ #define HCI_COMMAND_PKT 0x01 #define HCI_ACLDATA_PKT 0x02 @@ -1139,50 +1141,63 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) // Load our LTK for this connection. uint8_t peerAddr[7]; uint8_t resolvableAddr[6]; + uint8_t foundLTK; ATT.getPeerAddrWithType(ltkRequest->connectionHandle, peerAddr); - if(ATT.getPeerResolvedAddress(ltkRequest->connectionHandle, resolvableAddr) - && !((ATT.getPeerEncryption(ltkRequest->connectionHandle) & PEER_ENCRYPTION::PAIRING_REQUEST)>0)){ - _getLTK(resolvableAddr, HCI.LTK); + if((ATT.getPeerEncryption(ltkRequest->connectionHandle) & PEER_ENCRYPTION::PAIRING_REQUEST)>0){ + // Pairing request - LTK is one in buffer already + foundLTK = 1; }else{ - _getLTK(&peerAddr[1], HCI.LTK); + if(ATT.getPeerResolvedAddress(ltkRequest->connectionHandle, resolvableAddr)){ + foundLTK = getLTK(resolvableAddr, HCI.LTK); + }else{ + foundLTK = getLTK(&peerAddr[1], HCI.LTK); + } } - // } + // } //2d // Send our LTK back - struct __attribute__ ((packed)) LTKReply - { - uint16_t connectionHandle; - uint8_t LTK[16]; - } ltkReply = {0,0}; - ltkReply.connectionHandle = ltkRequest->connectionHandle; - for(int i=0; i<16; i++) ltkReply.LTK[15-i] = HCI.LTK[i]; - int result = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::LONG_TERM_KEY_REPLY,sizeof(ltkReply), <kReply); - -#ifdef _BLE_TRACE_ - Serial.println("Sending LTK as: "); - btct.printBytes(ltkReply.LTK,16); -#endif - - if(result == 0){ - struct __attribute__ ((packed)) LTKReplyResult + if(foundLTK){ + struct __attribute__ ((packed)) LTKReply { - uint8_t status; uint16_t connectionHandle; - } ltkReplyResult = {0,0}; - memcpy(<kReplyResult, _cmdResponse, 3); - -#ifdef _BLE_TRACE_ - Serial.println("LTK send success"); - Serial.print("status : "); - btct.printBytes(<kReplyResult.status,1); - Serial.print("Conn Handle: "); - btct.printBytes((uint8_t*)<kReplyResult.connectionHandle,2); -#endif + uint8_t LTK[16]; + } ltkReply = {0,0}; + ltkReply.connectionHandle = ltkRequest->connectionHandle; + for(int i=0; i<16; i++) ltkReply.LTK[15-i] = HCI.LTK[i]; + int result = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::LONG_TERM_KEY_REPLY,sizeof(ltkReply), <kReply); + + #ifdef _BLE_TRACE_ + Serial.println("Sending LTK as: "); + btct.printBytes(ltkReply.LTK,16); + #endif + + if(result == 0){ + struct __attribute__ ((packed)) LTKReplyResult + { + uint8_t status; + uint16_t connectionHandle; + } ltkReplyResult = {0,0}; + memcpy(<kReplyResult, _cmdResponse, 3); + + #ifdef _BLE_TRACE_ + Serial.println("LTK send success"); + Serial.print("status : "); + btct.printBytes(<kReplyResult.status,1); + Serial.print("Conn Handle: "); + btct.printBytes((uint8_t*)<kReplyResult.connectionHandle,2); + #endif + }else{ + #ifdef _BLE_TRACE_ + Serial.print("Failed to send LTK...: "); + btct.printBytes((uint8_t*)&result,2); + #endif + } }else{ + /// do LTK rejection #ifdef _BLE_TRACE_ - Serial.print("Failed to send LTK...: "); - btct.printBytes((uint8_t*)&result,2); + Serial.println("LTK not found, rejecting"); #endif + sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::LONG_TERM_KEY_NEGATIVE_REPLY,2, <kRequest->connectionHandle); } break; } @@ -1256,10 +1271,10 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t Z = 0; - for(int i=0; i<16; i++){ - /// TODO: Implement secure random - Nb[i] = rand(); //// Should use ESP or ECCx08 - } + + HCI.leRand(Nb); + HCI.leRand(&Nb[8]); + #ifdef _BLE_TRACE_ Serial.print("nb: "); btct.printBytes(Nb, 16); @@ -1405,6 +1420,47 @@ int HCIClass::leEncrypt(uint8_t* key, uint8_t* plaintext, uint8_t* status, uint8 #endif return res; } +int HCIClass::leRand(uint8_t rand[]){ + int res = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::RANDOM); + if(res == 0){ + memcpy(rand,_cmdResponse, 8); /// backwards but it's a random number + } + return res; +} +int HCIClass::getLTK(uint8_t* address, uint8_t* LTK){ + if(_getLTK!=0){ + return _getLTK(address, LTK); + }else{ + return 0; + } +} +int HCIClass::storeIRK(uint8_t* address, uint8_t* IRK){ + if(_storeIRK!=0){ + return _storeIRK(address, IRK); + }else{ + return 0; + } +} +int HCIClass::storeLTK(uint8_t* address, uint8_t* LTK){ + if(_storeLTK!=0){ + return _storeLTK(address, LTK); + }else{ + return 0; + } +} + +/// Stub function to generate parameters for local authreq +AuthReq HCIClass::localAuthreq(){ + // If get, set, IRK, LTK all set then we can bond. + AuthReq local = AuthReq(); + if(_storeIRK!=0 && _storeLTK!=0 && _getLTK!=0 && _getIRKs!=0){ + local.setBonding(true); + } + local.setSC(true); + local.setMITM(true); + local.setCT2(true); + return LOCAL_AUTHREQ; +} void HCIClass::dumpPkt(const char* prefix, uint8_t plen, uint8_t pdata[]) { diff --git a/src/utility/HCI.h b/src/utility/HCI.h index de15bdf8..b8671303 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -21,6 +21,7 @@ #define _HCI_H_ #include +#include "bitDescriptions.h" #define OGF_LINK_CTL 0x01 #define OGF_HOST_CTL 0x03 @@ -29,11 +30,13 @@ #define OGF_LE_CTL 0x08 enum LE_COMMAND { - ENCRYPT = 0x0017, - LONG_TERM_KEY_REPLY = 0x001A, - READ_LOCAL_P256 = 0x0025, - GENERATE_DH_KEY_V1 = 0x0026, - GENERATE_DH_KEY_V2 = 0x005E + ENCRYPT = 0x0017, + RANDOM = 0x0018, + LONG_TERM_KEY_REPLY = 0x001A, + LONG_TERM_KEY_NEGATIVE_REPLY = 0x1B, + READ_LOCAL_P256 = 0x0025, + GENERATE_DH_KEY_V1 = 0x0026, + GENERATE_DH_KEY_V2 = 0x005E }; enum LE_META_EVENT { CONN_COMPLETE = 0x01, @@ -89,6 +92,9 @@ class HCIClass { uint16_t latency, uint16_t supervisionTimeout); virtual int leCancelConn(); virtual int leEncrypt(uint8_t* Key, uint8_t* plaintext, uint8_t* status, uint8_t* ciphertext); + // Generate a 64 bit random number + virtual int leRand(uint8_t rand[]); + virtual AuthReq localAuthreq(); virtual int saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); virtual int leAddResolvingAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); @@ -108,7 +114,7 @@ class HCIClass { virtual void debug(Stream& stream); virtual void noDebug(); - // TODO: Send command be private again & use ATT implementation within ATT. + // TODO: Send command be private again & use ATT implementation of send command within ATT. virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); uint8_t remotePublicKeyBuffer[64]; uint8_t Na[16]; @@ -116,11 +122,13 @@ class HCIClass { uint8_t DHKey[32]; uint8_t localAddr[6]; uint8_t LTK[16]; - - int (*_storeIRK)(uint8_t* address, uint8_t* peerIrk); - int (*_getIRKs)(uint8_t* nIRKs,uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs); - int (*_storeLTK)(uint8_t*, uint8_t*); - int (*_getLTK)(uint8_t*, uint8_t*); + virtual int getLTK(uint8_t* address, uint8_t* LTK); + virtual int storeLTK(uint8_t* address, uint8_t* LTK); + virtual int storeIRK(uint8_t* address, uint8_t* IRK); + int (*_storeIRK)(uint8_t* address, uint8_t* peerIrk) = 0; + int (*_getIRKs)(uint8_t* nIRKs,uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs) = 0; + int (*_storeLTK)(uint8_t*, uint8_t*) = 0; + int (*_getLTK)(uint8_t*, uint8_t*) = 0; private: diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index f7f93b84..9d9efd81 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -26,6 +26,9 @@ #define CONNECTION_PARAMETER_UPDATE_REQUEST 0x12 #define CONNECTION_PARAMETER_UPDATE_RESPONSE 0x13 + +// #define _BLE_TRACE_ + L2CAPSignalingClass::L2CAPSignalingClass() : _minInterval(0), _maxInterval(0), @@ -139,13 +142,14 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t responderKeyDistribution; } *pairingRequest = (PairingRequest*)l2capSignalingHdr->data; - - ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution); - ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution); - KeyDistribution rkd(pairingRequest->responderKeyDistribution); - AuthReq req(pairingRequest->authReq); KeyDistribution responseKD = KeyDistribution(); responseKD.setIdKey(true); + + ATT.remoteKeyDistribution = responseKD;// KeyDistribution(pairingRequest->initiatorKeyDistribution); + ATT.localKeyDistribution = responseKD; //KeyDistribution(pairingRequest->responderKeyDistribution); + // KeyDistribution rkd(pairingRequest->responderKeyDistribution); + AuthReq req(pairingRequest->authReq); + #ifdef _BLE_TRACE_ Serial.print("Req has properties: "); Serial.print(req.Bonding()?"bonding, ":"no bonding, "); @@ -173,7 +177,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t maxEncSize; uint8_t initiatorKeyDistribution; uint8_t responderKeyDistribution; - } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, LOCAL_AUTHREQ, 0x10, responseKD.getOctet(), responseKD.getOctet()}; + } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, HCI.localAuthreq().getOctet(), 0x10, responseKD.getOctet(), responseKD.getOctet()}; HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); } @@ -305,7 +309,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t Eb[16]; uint8_t R[16]; uint8_t MasterIOCap[3]; - uint8_t SlaveIOCap[3] = {LOCAL_AUTHREQ, 0x0, LOCAL_IOCAP}; + uint8_t SlaveIOCap[3] = {HCI.localAuthreq().getOctet(), 0x0, LOCAL_IOCAP}; ATT.getPeerIOCap(connectionHandle, MasterIOCap); for(int i=0; i<16; i++) R[i] = 0; From e2868a7108fec2bd6349c48ee556e5fe446daad0 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Thu, 7 Jan 2021 10:43:23 +0000 Subject: [PATCH 012/112] Pairing code & binary confirm callbacks --- src/local/BLELocalDevice.cpp | 6 ++++ src/local/BLELocalDevice.h | 3 ++ src/utility/ATT.cpp | 2 ++ src/utility/HCI.cpp | 15 +++++++++- src/utility/HCI.h | 4 +++ src/utility/L2CAPSignaling.cpp | 54 ++++++++++++++++++++++++++++++++-- src/utility/L2CAPSignaling.h | 2 +- src/utility/btct.cpp | 36 +++++++++++++++++++++++ src/utility/btct.h | 2 ++ 9 files changed, 120 insertions(+), 4 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 029fb488..d83c1cb3 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -434,6 +434,12 @@ void BLELocalDevice::setStoreLTK(int (*storeLTK)(uint8_t*, uint8_t*)){ void BLELocalDevice::setStoreIRK(int (*storeIRK)(uint8_t*, uint8_t*)){ HCI._storeIRK = storeIRK; } +void BLELocalDevice::setDisplayCode(void (*displayCode)(uint32_t confirmationCode)){ + HCI._displayCode = displayCode; +} +void BLELocalDevice::setBinaryConfirmPairing(bool (*binaryConfirmPairing)()){ + HCI._binaryConfirmPairing = binaryConfirmPairing; +} void BLELocalDevice::debug(Stream& stream) { diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 75e7dc31..6c45c063 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -104,6 +104,9 @@ class BLELocalDevice { // address - The mac address needing its LTK // LTK - 16 octet LTK for the mac address virtual void setGetLTK(int (*getLTK)(uint8_t* address, uint8_t* LTK)); + + virtual void setDisplayCode(void (*displayCode)(uint32_t confirmationCode)); + virtual void setBinaryConfirmPairing(bool (*binaryConfirmPairing)()); uint8_t BDaddress[6]; protected: diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index a5166217..91ffeed0 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -81,6 +81,8 @@ #define ATT_ECODE_UNSUPP_GRP_TYPE 0x10 #define ATT_ECODE_INSUFF_RESOURCES 0x11 +// #define _BLE_TRACE_ + ATTClass::ATTClass() : _maxMtu(23), _timeout(5000), diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 9bcec4e1..82303ed3 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -26,7 +26,6 @@ #include "bitDescriptions.h" // #define _BLE_TRACE_ -//#define _BLE_TRACE_ #define HCI_COMMAND_PKT 0x01 #define HCI_ACLDATA_PKT 0x02 @@ -1258,6 +1257,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t publicKey[64]; } pairingPublicKey = {CONNECTION_PAIRING_PUBLIC_KEY,0}; memcpy(pairingPublicKey.publicKey,evtReadLocalP256Complete->localPublicKey,64); + memcpy(localPublicKeyBuffer, evtReadLocalP256Complete->localPublicKey,64); // Send the local public key to the remote uint16_t connectionHandle = ATT.getPeerEncrptingConnectionHandle(); @@ -1456,6 +1456,19 @@ int HCIClass::storeLTK(uint8_t* address, uint8_t* LTK){ return 0; } } +uint8_t HCIClass::localIOCap(){ + if(_displayCode!=0){ + /// We have a display + if(_binaryConfirmPairing!=0){ + return IOCAP_DISPLAY_YES_NO; + }else{ + return IOCAP_DISPLAY_ONLY; + } + }else{ + // We have no display + return IOCAP_NO_INPUT_NO_OUTPUT; + } +} /// Stub function to generate parameters for local authreq AuthReq HCIClass::localAuthreq(){ diff --git a/src/utility/HCI.h b/src/utility/HCI.h index f2bc535e..af46265a 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -97,6 +97,7 @@ class HCIClass { // Generate a 64 bit random number virtual int leRand(uint8_t rand[]); virtual AuthReq localAuthreq(); + virtual uint8_t localIOCap(); virtual int saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); virtual int leAddResolvingAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); @@ -119,6 +120,7 @@ class HCIClass { // TODO: Send command be private again & use ATT implementation of send command within ATT. virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); uint8_t remotePublicKeyBuffer[64]; + uint8_t localPublicKeyBuffer[64]; uint8_t remoteDHKeyCheckBuffer[16]; uint8_t Na[16]; uint8_t Nb[16]; @@ -132,6 +134,8 @@ class HCIClass { int (*_getIRKs)(uint8_t* nIRKs,uint8_t** BADDR_type, uint8_t*** BADDRs, uint8_t*** IRKs) = 0; int (*_storeLTK)(uint8_t*, uint8_t*) = 0; int (*_getLTK)(uint8_t*, uint8_t*) = 0; + void (*_displayCode)(uint32_t confirmationCode) = 0; + bool (*_binaryConfirmPairing)() = 0; private: diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index f7712051..2ef08b62 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -180,7 +180,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t maxEncSize; uint8_t initiatorKeyDistribution; uint8_t responderKeyDistribution; - } response = { CONNECTION_PAIRING_RESPONSE, LOCAL_IOCAP, 0, HCI.localAuthreq().getOctet(), 0x10, responseKD.getOctet(), responseKD.getOctet()}; + } response = { CONNECTION_PAIRING_RESPONSE, HCI.localIOCap(), 0, HCI.localAuthreq().getOctet(), 0x10, responseKD.getOctet(), responseKD.getOctet()}; HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); @@ -209,6 +209,55 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t for(int i=0; i< 16; i++) response.Nb[15-i] = HCI.Nb[i]; HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(response), &response); + + // We now have all needed for compare value + uint8_t g2Result[4]; + uint8_t U[32]; + uint8_t V[32]; + + for(int i=0; i<32; i++){ + U[31-i] = HCI.remotePublicKeyBuffer[i]; + V[31-i] = HCI.localPublicKeyBuffer[i]; + } + + btct.g2(U,V,HCI.Na,HCI.Nb, g2Result); + uint32_t result = 0; + for(int i=0; i<4; i++) result += g2Result[3-i] << 8*i; + +#ifdef _BLE_TRACE_ + Serial.print("U : "); + btct.printBytes(U,32); + Serial.print("V : "); + btct.printBytes(V,32); + Serial.print("X : "); + btct.printBytes(X,16); + Serial.print("Y : "); + btct.printBytes(Y,16); + Serial.print("g2res : "); + btct.printBytes(g2Result,4); + Serial.print("Result : "); + Serial.println(result); +#endif + + if(HCI._displayCode!=0){ + HCI._displayCode(result%1000000); + } + if(HCI._binaryConfirmPairing!=0){ + if(!HCI._binaryConfirmPairing()){ +#ifdef _BLE_TRACE_ + Serial.println("User rejection"); +#endif + uint8_t rejection[2]; + rejection[0] = CONNECTION_PAIRING_FAILED; + rejection[1] = 0x0C; // Numeric comparison failed + HCI.sendAclPkt(connectionHandle, SECURITY_CID, 2, rejection); + ATT.setPeerEncryption(connectionHandle, PEER_ENCRYPTION::NO_ENCRYPTION); + }else{ +#ifdef _BLE_TRACE_ + Serial.println("User did confirm"); +#endif + } + } } else if (code == CONNECTION_PAIRING_RESPONSE) { @@ -224,6 +273,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t Serial.print("Pairing failed with code: 0x"); Serial.println(pairingFailed->reason,HEX); #endif + ATT.setPeerEncryption(connectionHandle, PEER_ENCRYPTION::NO_ENCRYPTION); } else if (code == CONNECTION_IDENTITY_INFORMATION){ struct __attribute__ ((packed)) IdentityInformation { @@ -338,7 +388,7 @@ void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expe uint8_t Eb[16]; uint8_t R[16]; uint8_t MasterIOCap[3]; - uint8_t SlaveIOCap[3] = {HCI.localAuthreq().getOctet(), 0x0, LOCAL_IOCAP}; + uint8_t SlaveIOCap[3] = {HCI.localAuthreq().getOctet(), 0x0, HCI.localIOCap()}; ATT.getPeerIOCap(handle, MasterIOCap); for(int i=0; i<16; i++) R[i] = 0; diff --git a/src/utility/L2CAPSignaling.h b/src/utility/L2CAPSignaling.h index f8a361ee..26042167 100644 --- a/src/utility/L2CAPSignaling.h +++ b/src/utility/L2CAPSignaling.h @@ -49,7 +49,7 @@ #define LOCAL_AUTHREQ 0b00101101 -#define LOCAL_IOCAP IOCAP_NO_INPUT_NO_OUTPUT // will use JustWorks pairing +// #define LOCAL_IOCAP IOCAP_DISPLAY_ONLY // will use JustWorks pairing class L2CAPSignalingClass { public: diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index d78e328e..b4faf053 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -150,6 +150,42 @@ void BluetoothCryptoToolbox::testAh() printBytes(ourResult, 3); } +int BluetoothCryptoToolbox::g2(uint8_t U[], uint8_t V[], uint8_t X[], uint8_t Y[], uint8_t out[4]) +{ + struct __attribute__ ((packed)) CmacInput { + uint8_t U[32]; + uint8_t V[32]; + uint8_t Y[16]; + } cmacInput= {0,0,0}; + memcpy(cmacInput.U,U,32); + memcpy(cmacInput.V,V,32); + memcpy(cmacInput.Y,Y,16); + uint8_t intermediate[16]; + AES_CMAC(X,(uint8_t*)&cmacInput,sizeof(CmacInput),intermediate); + memcpy(out,&intermediate[12],4); + return 1; +} +void BluetoothCryptoToolbox::testg2(){ + uint8_t U[32] = {0x20,0xb0,0x03,0xd2,0xf2,0x97,0xbe,0x2c,0x5e,0x2c,0x83,0xa7,0xe9,0xf9,0xa5,0xb9,0xef,0xf4,0x91,0x11,0xac,0xf4,0xfd,0xdb,0xcc,0x03,0x01,0x48,0x0e,0x35,0x9d,0xe6}; + uint8_t V[32] = {0x55,0x18,0x8b,0x3d,0x32,0xf6,0xbb,0x9a,0x90,0x0a,0xfc,0xfb,0xee,0xd4,0xe7,0x2a,0x59,0xcb,0x9a,0xc2,0xf1,0x9d,0x7c,0xfb,0x6b,0x4f,0xdd,0x49,0xf4,0x7f,0xc5,0xfd}; + uint8_t X[16] = {0xd5,0xcb,0x84,0x54,0xd1,0x77,0x73,0x3e,0xff,0xff,0xb2,0xec,0x71,0x2b,0xae,0xab}; + uint8_t Y[16] = {0xa6,0xe8,0xe7,0xcc,0x25,0xa7,0x5f,0x6e,0x21,0x65,0x83,0xf7,0xff,0x3d,0xc4,0xcf}; + uint8_t AES[16] = {0x15,0x36,0xd1,0x8d,0xe3,0xd2,0x0d,0xf9,0x9b,0x70,0x44,0xc1,0x2f,0x9e,0xd5,0xba}; + uint8_t out[4]; + + + uint32_t expected = 0; + g2(U,V,X,Y,out); + uint32_t result = 0; + for(int i=0; i<4; i++) result += out[i] << 8*i; + + Serial.print("Expected : "); + Serial.println(expected); + Serial.print("Result : "); + Serial.println(result); + Serial.println(); + +} void BluetoothCryptoToolbox::AES_CMAC ( unsigned char *key, unsigned char *input, int length, unsigned char *mac ) diff --git a/src/utility/btct.h b/src/utility/btct.h index 43c0b0d6..08f8f192 100644 --- a/src/utility/btct.h +++ b/src/utility/btct.h @@ -13,11 +13,13 @@ class BluetoothCryptoToolbox{ int f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_slave[], uint8_t BD_ADDR_master[], uint8_t BD_ADDR_slave[], uint8_t MacKey[], uint8_t LTK[]); int f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[], uint8_t IOCap[], uint8_t A1[], uint8_t A2[], uint8_t Ex[]); + int g2(uint8_t U[], uint8_t V[], uint8_t X[], uint8_t Y[], uint8_t out[4]); int ah(uint8_t k[16], uint8_t r[3], uint8_t result[3]); void test(); void testF5(); void testF6(); void testAh(); + void testg2(); private: int AES_128(uint8_t key[], uint8_t data_in[], uint8_t data_out[]); void leftshift_onebit(unsigned char *input,unsigned char *output); From 6b08d21480d00d2842f6641cf06d7aa48a7ec219 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Thu, 7 Jan 2021 10:48:26 +0000 Subject: [PATCH 013/112] Updated example sketch --- .../EncryptedBatteryMonitor.ino | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino index fd40f5ee..dd3afbf6 100644 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -18,7 +18,7 @@ #include -#define PAIR_BUTTON D3 // button for pairing +#define PAIR_BUTTON 3 // button for pairing #define PAIR_LED 24 // LED used to signal pairing #define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic #define PAIR_INTERVAL 30000 // interval for pairing after button press in ms @@ -42,6 +42,7 @@ int oldBatteryLevel = 0; // last battery level reading from analog input unsigned long previousMillis = 0; // last time the battery level was checked, in ms unsigned long pairingStarted = 0; // pairing start time when button is pressed bool wasConnected = 0; +bool acceptOrReject = true; void setup() { Serial.begin(9600); // initialize serial communication @@ -53,6 +54,30 @@ void setup() { Serial.println("Serial connected"); + + // Callback function with confirmation code when new device is pairing. + BLE.setDisplayCode([](uint32_t confirmCode){ + Serial.println("New device pairing request."); + Serial.print("Confirm code matches pairing device: "); + char code[6]; + sprintf(code, "%06d", confirmCode); + Serial.println(code); + }); + + // Callback to allow accepting or rejecting pairing + BLE.setBinaryConfirmPairing([&acceptOrReject](){ + Serial.print("Should we confirm pairing? "); + delay(5000); + if(acceptOrReject){ + acceptOrReject = false; + Serial.println("yes"); + return true; + }else{ + acceptOrReject = true; + Serial.println("no"); + return false; + } + }); // IRKs are keys that identify the true owner of a random mac address. // Add IRKs of devices you are bonded with. From 3dd53d1ba67450a26a80ec6768667a662d157496 Mon Sep 17 00:00:00 2001 From: unknownconstant Date: Sun, 24 Jan 2021 10:03:17 +0000 Subject: [PATCH 014/112] Spellcheck fixes --- .../EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino | 2 +- src/local/BLELocalDevice.cpp | 2 +- src/utility/ATT.cpp | 2 +- src/utility/HCI.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino index dd3afbf6..9f9d453b 100644 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -116,7 +116,7 @@ void setup() { // The LTK is the secret key which is used to encrypt bluetooth traffic BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ // address is input - Serial.print("Recieved request for address: "); + Serial.print("Received request for address: "); btct.printBytes(address,6); // Set these to the MAC and LTK of your devices after bonding. diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index d83c1cb3..8c1758b0 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -123,7 +123,7 @@ int BLELocalDevice::begin() /// The HCI should allow automatic address resolution. - // // If we have callbacks to rememember bonded devices: + // // If we have callbacks to remember bonded devices: // if(HCI._getIRKs!=0){ // uint8_t nIRKs = 0; // uint8_t** BADDR_Type = new uint8_t*; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 91ffeed0..f6ab392f 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -602,7 +602,7 @@ bool ATTClass::handleNotify(uint16_t handle, const uint8_t* value, int length) memcpy(¬ification[notificationLength], value, length); notificationLength += length; - /// TODO: Set encyption requirement on notify. + /// TODO: Set encryption requirement on notify. HCI.sendAclPkt(_peers[i].connectionHandle, ATT_CID, notificationLength, notification); numNotifications++; diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 82303ed3..96948b85 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -841,7 +841,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) if((ATT.getPeerEncryption(encryptionChange->connectionHandle)&PEER_ENCRYPTION::PAIRING_REQUEST)>0){ if(ATT.localKeyDistribution.EncKey()){ #ifdef _BLE_TRACE_ - Serial.println("Enc key set but sould be ignored"); + Serial.println("Enc key set but should be ignored"); #endif }else{ #ifdef _BLE_TRACE_ @@ -1364,7 +1364,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) if((encryption & PEER_ENCRYPTION::RECEIVED_DH_CHECK) > 0){ #ifdef _BLE_TRACE_ - Serial.println("Recieved DHKey check already so calculate f5, f6 now."); + Serial.println("Received DHKey check already so calculate f5, f6 now."); #endif L2CAPSignaling.smCalculateLTKandConfirm(connectionHandle, HCI.remoteDHKeyCheckBuffer); From 55d5bf2c0dea092b8efbec9b444432a68a86c4f3 Mon Sep 17 00:00:00 2001 From: Tim Lossen Date: Sat, 26 Dec 2020 22:05:11 +0100 Subject: [PATCH 015/112] add access to raw advertisement data --- src/BLEDevice.cpp | 11 +++++++++++ src/BLEDevice.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index fa806104..4fb2562d 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -184,6 +184,17 @@ String BLEDevice::advertisedServiceUuid(int index) const return serviceUuid; } +int BLEDevice::advertisementData(uint8_t value[], int length) +{ + if (_eirDataLength > length) return 0; // Check that buffer size is sufficient + + if (_eirDataLength) { + memcpy(value, _eirData, _eirDataLength); + } + + return _eirDataLength; +} + int BLEDevice::rssi() { uint16_t handle = ATT.connectionHandle(_addressType, _address); diff --git a/src/BLEDevice.h b/src/BLEDevice.h index cbe79c71..508d46c1 100644 --- a/src/BLEDevice.h +++ b/src/BLEDevice.h @@ -59,6 +59,8 @@ class BLEDevice { String advertisedServiceUuid() const; String advertisedServiceUuid(int index) const; + int advertisementData(uint8_t value[], int length); + virtual int rssi(); bool connect(); From a9550cf9a27334db6e71cbddc6be0348274bd541 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 20 Apr 2021 17:24:22 +0200 Subject: [PATCH 016/112] Saturate length of retrieved advertisement data --- src/BLEDevice.cpp | 10 +++++----- src/BLEDevice.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index 4fb2562d..4ac0785f 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -184,15 +184,15 @@ String BLEDevice::advertisedServiceUuid(int index) const return serviceUuid; } -int BLEDevice::advertisementData(uint8_t value[], int length) +int BLEDevice::advertisementData(uint8_t value[], int length) const { - if (_eirDataLength > length) return 0; // Check that buffer size is sufficient + if (length > _eirDataLength) length = _eirDataLength; - if (_eirDataLength) { - memcpy(value, _eirData, _eirDataLength); + if (length) { + memcpy(value, _eirData, length); } - return _eirDataLength; + return length; } int BLEDevice::rssi() diff --git a/src/BLEDevice.h b/src/BLEDevice.h index 508d46c1..84fb8f15 100644 --- a/src/BLEDevice.h +++ b/src/BLEDevice.h @@ -59,7 +59,7 @@ class BLEDevice { String advertisedServiceUuid() const; String advertisedServiceUuid(int index) const; - int advertisementData(uint8_t value[], int length); + int advertisementData(uint8_t value[], int length) const; virtual int rssi(); From bd492be549e05f48679d4fa797f99e1370bb7eaa Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 20 Apr 2021 17:34:37 +0200 Subject: [PATCH 017/112] Add advertisement data auxiliary functions --- src/BLEDevice.cpp | 10 ++++++++++ src/BLEDevice.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index 4ac0785f..31fae719 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -184,6 +184,16 @@ String BLEDevice::advertisedServiceUuid(int index) const return serviceUuid; } +bool BLEDevice::hasAdvertisementData() const +{ + return (_eirDataLength > 0); +} + +int BLEDevice::advertisementDataLength() const +{ + return _eirDataLength; +} + int BLEDevice::advertisementData(uint8_t value[], int length) const { if (length > _eirDataLength) length = _eirDataLength; diff --git a/src/BLEDevice.h b/src/BLEDevice.h index 84fb8f15..054c49bc 100644 --- a/src/BLEDevice.h +++ b/src/BLEDevice.h @@ -59,6 +59,8 @@ class BLEDevice { String advertisedServiceUuid() const; String advertisedServiceUuid(int index) const; + bool hasAdvertisementData() const; + int advertisementDataLength() const; int advertisementData(uint8_t value[], int length) const; virtual int rssi(); From b5d1b738d2b28ee513e841e93cd3ea88dccaba28 Mon Sep 17 00:00:00 2001 From: per1234 Date: Wed, 28 Apr 2021 02:16:05 -0700 Subject: [PATCH 018/112] Add Nano RP2040 Connect to "smoke test" examples compilation CI workflow --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index abb566da..a14882ff 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -14,6 +14,7 @@ jobs: - arduino:samd:nano_33_iot - arduino:megaavr:uno2018:mode=on - arduino:mbed:nano33ble + - arduino:mbed_nano:nanorp2040connect steps: - uses: actions/checkout@v2 From e080601da73f5ec8cf8a6d999783c0c1c5593945 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 20 Apr 2021 17:53:05 +0200 Subject: [PATCH 019/112] Add retrieval of manufacturer data --- src/BLEDevice.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/BLEDevice.h | 4 ++++ 2 files changed, 47 insertions(+) diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index 31fae719..5f64c1d6 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -205,6 +205,49 @@ int BLEDevice::advertisementData(uint8_t value[], int length) const return length; } +bool BLEDevice::hasManufacturerData() const +{ + return (manufacturerDataLength() > 0); +} + +int BLEDevice::manufacturerDataLength() const +{ + int length = 0; + + for (int i = 0; i < _eirDataLength;) { + int eirLength = _eirData[i++]; + int eirType = _eirData[i++]; + + if (eirType == 0xFF) { + length = (eirLength - 1); + break; + } + + i += (eirLength - 1); + } + + return length; +} + +int BLEDevice::manufacturerData(uint8_t value[], int length) const +{ + for (int i = 0; i < _eirDataLength;) { + int eirLength = _eirData[i++]; + int eirType = _eirData[i++]; + + if (eirType == 0xFF) { + if (length > (eirLength - 1)) length = (eirLength - 1); + + memcpy(value, &_eirData[i], length); + break; + } + + i += (eirLength - 1); + } + + return length; +} + int BLEDevice::rssi() { uint16_t handle = ATT.connectionHandle(_addressType, _address); diff --git a/src/BLEDevice.h b/src/BLEDevice.h index 054c49bc..bf710744 100644 --- a/src/BLEDevice.h +++ b/src/BLEDevice.h @@ -63,6 +63,10 @@ class BLEDevice { int advertisementDataLength() const; int advertisementData(uint8_t value[], int length) const; + bool hasManufacturerData() const; + int manufacturerDataLength() const; + int manufacturerData(uint8_t value[], int length) const; + virtual int rssi(); bool connect(); From e1b0d81c279f1d75ecb0cc87cc4daa88adf6a096 Mon Sep 17 00:00:00 2001 From: LiamAljundi <46995170+LiamAljundi@users.noreply.github.com> Date: Fri, 6 Aug 2021 11:43:08 +0200 Subject: [PATCH 020/112] moved BLE library to markdown --- docs/api.md | 3826 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/readme.md | 91 ++ 2 files changed, 3917 insertions(+) create mode 100644 docs/api.md create mode 100644 docs/readme.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 00000000..fc0e9c07 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,3826 @@ +# ArduinoBLE library + +## BLE class + +Used to enable the BLE module. + +### `begin()` + +Initializes the BLE device. + +#### Syntax + +``` +BLE.begin() + +``` + +#### Parameters + +None + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } +… + +``` + +### `end()` + +Stops the BLE device. + +#### Syntax + +``` +BLE.end() + +``` + +#### Parameters + +None + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // .... + + BLE.end(); +… + +``` + +### `poll()` + +Poll for BLE radio events and handle them. + +#### Syntax + +``` +BLE.poll() BLE.poll(timeout) + +``` + +#### Parameters + +**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. + +Returns +Nothing + +#### Example + +```Arduino +… + // assign event handlers for connected, disconnected to peripheral + BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); + BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); + + // … + + BLE.poll(); +… + +``` + +### `setEventHandler()` + +Set the event handler (callback) function that will be called when the specified event occurs. + +#### Syntax + +``` +BLE.setEventHandler(eventType, callback) + +``` + +#### Parameters + +**eventType**: event type (BLEConnected, BLEDisconnected) +**callback**: function to call when event occurs +Returns +Nothing. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + // assign event handlers for connected, disconnected to peripheral + BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); + BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); + + // … + + +void blePeripheralConnectHandler(BLEDevice central) { + // central connected event handler + Serial.print("Connected event, central: "); + Serial.println(central.address()); +} + +void blePeripheralDisconnectHandler(BLEDevice central) { + // central disconnected event handler + Serial.print("Disconnected event, central: "); + Serial.println(central.address()); +} +… + +``` + +### `connected()` + +Query if another BLE device is connected + +#### Syntax + +``` +BLE.connected() + +``` + +#### Parameters + +None + +Returns +**true** if another BLE device is connected, otherwise **false**. + +#### Example + +```Arduino +… + // while the central is still connected to peripheral: + while (BLE.connected()) { + + // ... + } +… + +``` + +### `disconnect()` + +Disconnect any BLE devices that are connected + +#### Syntax + +``` +BLE.disconnect() + +``` + +#### Parameters + +None + +Returns +**true** if any BLE device that was previously connected was disconnected, otherwise **false**. + +#### Example + +```Arduino +… + if (BLE.connected()) { + // … + + BLE.disconnect(); + } +… + +``` + +### `address()` + +Query the Bluetooth address of the BLE device. + +#### Syntax + +``` +BLE.address() + +``` + +#### Parameters + +None + +Returns +The **Bluetooth address** of the BLE device (as a String). + +#### Example + +```Arduino +… + **String** address = BLE.address(); + + Serial.print(“Local address is: “); + Serial.println(address); +… + +``` + +### `rssi()` + +Query the RSSI (Received signal strength indication) of the connected BLE device. + +#### Syntax + +``` +BLE.rssi() + +``` + +#### Parameters + +None + +Returns +The **RSSI** of the connected BLE device, 127 if no BLE device is connected. + +#### Example + +```Arduino +… + if (BLE.connected()) { + // … + + Serial.print(“RSSI = “); + Serial.println(BLE.rssi()); + } +… + +``` + +### `setAdvertisedServiceUuid()` + +Set the advertised service UUID used when advertising. + +#### Syntax + +``` +BLE.setAdvertisedServiceUuid(uuid) + +``` + +#### Parameters + +**uuid:** 16-bit or 128-bit BLE UUID in **String** format + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + BLE.setAdvertisedServiceUuid(“19B10000-E8F2-537E-4F6C-D104768A1214"); + + // ... + + // start advertising + BLE.advertise(); +… + +``` + +### `setAdvertisedService()` + +Set the advertised service UUID used when advertising to the value of the BLEService provided. + +#### Syntax + +``` +BLE.setAdvertisedService(bleService) + +``` + +#### Parameters + +**bleService:** BLEService to use UUID from + +Returns +Nothing + +#### Example + +```Arduino +… +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service + +// ... + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + BLE.setAdvertisedService(ledService); + + // ... + + // start advertising + BLE.advertise(); +… + +``` + +### `setManufacturerData()` + +Set the manufacturer data value used when advertising. + +#### Syntax + +``` +BLE.setManufacturerData(data, length) + +``` + +#### Parameters + +**data:** byte array containing manufacturer data +**length:** length of manufacturer data array + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + byte data[5] = { 0x01, 0x02, 0x03, 0x04, 0x05}; + + BLE.setManufacturerData(data, 5); + + // ... + + // start advertising + BLE.advertise(); + +… + +``` + +### `setLocalName()` + +Set the local value used when advertising. + +#### Syntax + +``` +BLE.setLocalName(name) + +``` + +#### Parameters + +**name:** local name value to use when advertising + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + BLE.setLocalName("LED"); + + // ... + + // start advertising + BLE.advertise(); + +… + +``` + +### `setDeviceName()` + +Set the device name in the built in device name characteristic. If not set, the value defaults “Arduino”. + +#### Syntax + +``` +BLE.setDeviceName(name) + +``` + +#### Parameters + +**name:** device name value + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + BLE.setDeviceName("LED"); + + // ... + + // start advertising + BLE.advertise(); + +… + +``` + +### `setAppearance()` + +Set the appearance in the built in appearance characteristic. If not set, the value defaults 0x0000. + +#### Syntax + +``` +BLE.setAppearance(appearance) + +``` + +#### Parameters + +**appearance:** appearance value + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + BLE.setAppearance(0x8000); + + // ... + + // start advertising + BLE.advertise(); + +… + +``` + +### `addService()` + +Add a BLEService to the set of services the BLE device provides + +#### Syntax + +``` +BLE.addService(service) + +``` + +#### Parameters + +**service:** BLEService to add + +Returns +Nothing + +#### Example + +```Arduino +… +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service + +// … + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.addService(ledService); + + // ... +… + +``` + +### `advertise()` + +Start advertising. + +#### Syntax + +``` +BLE.advertise() + +``` + +#### Parameters + +None + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.advertise(); + + // ... +… + +``` + +### `stopAdvertise()` + +Stop advertising. + +#### Syntax + +``` +BLE.stopAdvertise() + +``` + +#### Parameters + +None + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.advertise(); + + // ... + + BLE.stopAdvertise(); +… + +``` + +### `central()` + +Query the central BLE device connected. + +#### Syntax + +``` +BLE.central() + +``` + +#### Parameters + +None + +Returns +**BLEDevice** representing the central. + +#### Example + +```Arduino +… + // listen for BLE peripherals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's MAC address: + Serial.println(central.address()); + + // … + } +… + +``` + +### `setAdvertisingInterval()` + +Set the advertising interval in units of 0.625 ms. Defaults to 100ms (160 * 0.625 ms) if not provided. + +#### Syntax + +``` +BLE.setAdvertisingInterval(advertisingInterval) + +``` + +#### Parameters + +**advertisingInterval:** advertising interval in units of 0.625 ms + +Returns +Nothing. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.setAdvertisingInterval(320); // 200 * 0.625 ms + + BLE.advertise(); +… + +``` + +### `setConnectionInterval()` + +Set the minimum and maximum desired connection intervals in units of 1.25 ms. + +#### Syntax + +``` +BLE.setConnectionInterval(minimum, maximum) + +``` + +#### Parameters + +**minimum:** minimum desired connection interval in units of 1.25 ms +**maximum:** maximum desired connection interval in units of 1.25 ms + +Returns +Nothing. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.setConnectionInterval(0x0006, 0x0c80); // 7.5 ms minimum, 4 s maximum + +… + +``` + +### `setConnectable()` + +Set if the device is connectable after advertising, defaults to **true**. + +#### Syntax + +``` +BLE.setConnectable(connectable) + +``` + +#### Parameters + +**true**: the device will be connectable when advertising +**false**: the device will NOT be connectable when advertising + +Returns +Nothing. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + // ... + + BLE.setConnectable(false); // make the device unconnectable when advertising + +… + +``` + +### `scan()` + +Start scanning for BLE devices that are advertising. + +#### Syntax + +``` +BLE.scan() +BLE.scan(withDuplicates) + +``` + +#### Parameters + +**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + } +… + +``` + +### `scanForName()` + +Start scanning for BLE devices that are advertising with a particular (local) name. + +#### Syntax + +``` +BLE.scanForName(name) +BLE.scanForName(name, withDuplicates) + +``` + +#### Parameters + +**name:** (local) name of device (as a **String**) to filter for +**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scanForName("LED"); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + } +… + +``` + +### `scanForAddress()` + +Start scanning for BLE devices that are advertising with a particular (Bluetooth) address. + +#### Syntax + +``` +BLE.scanForAddress(address) +BLE.scanForAddress(address, withDuplicates) + +``` + +#### Parameters + +**address:** (Bluetooth) address (as a String) to filter for +**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + } +… + +``` + +### `scanForUuid()` + +Start scanning for BLE devices that are advertising with a particular (service) UUID. + +#### Syntax + +``` +BLE.scanForUuid(uuid) +BLE.scanForUuid(uuid, withDuplicates) + +``` + +#### Parameters + +**uuid:** (service) UUID (as a **String**) to filter for +**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. + +Returns +1 on success, 0 on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scanForUuid("aa10"); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + } +… + +``` + +### `stopScan()` + +Stop scanning for BLE devices that are advertising. + +#### Syntax + +``` +BLE.stopScan() + +``` + +#### Parameters + +None + +Returns +Nothing + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + BLE.stopScan(); +… + +``` + +### `available()` + +Query for a discovered BLE device that was found during scanning. + +#### Syntax + +``` +BLE.available() + +``` + +#### Parameters + +Nothing + +Returns +**BLEDevice** representing the discovered device. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + } +… + +``` + +## BLEDevice Class + +Used to get information about the devices connected or discovered while scanning + +### `poll()` + +Poll for BLE radio events for the specified BLE device and handle them. + +#### Syntax + +``` +bleDevice.poll() +bleDevice.poll(timeout) + +``` + +#### Parameters + +**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. + +Returns +Nothing + +#### Example + +```Arduino +… + // listen for BLE centrals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + // … + + central.poll(); + + // ... + } +… + +``` + +### `connected()` + +Query if a BLE device is connected + +#### Syntax + +``` +bleDevice.connected() + +``` + +#### Parameters + +None + +Returns +**true** if the BLE device is connected, otherwise **false**. + +#### Example + +```Arduino +… + // listen for BLE centrals to connect: + BLEDevice central = BLE.central(); + + // while the central is still connected + while (central.connected()) { + + // ... + } +… + +``` + +### `disconnect()` + +Disconnect the BLE device, if connected + +#### Syntax + +``` +bleDevice.disconnect() + +``` + +#### Parameters + +None + +Returns +**true** if the BLE device was disconnected, otherwise **false**. + +#### Example + +```Arduino +… + // listen for BLE centrals to connect: + BLEDevice central = BLE.central(); + + // … + + central.disconnect(); +… + +``` + +### `address()` + +Query the Bluetooth address of the BLE device. + +#### Syntax + +``` +bleDevice.address() + +``` + +#### Parameters + +None + +Returns +The **Bluetooth address** of the BLE device (as a String). + +#### Example + +```Arduino +… + // listen for BLE peripherals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's MAC address: + Serial.println(central.address()); + + // …. + } +… + +``` + +### `rssi()` + +Query the RSSI (Received signal strength indication) of the BLE device. + +#### Syntax + +``` +bleDevice.rssi() + +``` + +#### Parameters + +None + +Returns +The **RSSI** of the connected BLE device, 127 if the BLE device is not connected. + +#### Example + +```Arduino +… + if (bleDevice.connected()) { + // … + + Serial.print(“RSSI = “); + Serial.println(bleDevice.rssi()); + } +… + +``` + +### `characteristic()` + +Get a BLECharacteristic representing a BLE characteristic the device provides. + +#### Syntax + +``` +bleDevice.characteristic(index) +bleDevice.characteristic(uuid) +bleDevice.characteristic(uuid, index) + +``` + +#### Parameters + +**index**: index of characteristic +**uuid**: uuid (as a **String**) + +Returns +**BLECharacteristic** for provided parameters + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + BLECharacteristic batteryLevelCharacterisic = peripheral.characteristic("2a19"); + + if (batteryLevelCharacterisic) { + // use the characteristic + } else { + Serial.println("Peripheral does NOT have battery level characteristic"); + } + + // ... + } +… + +``` + +### `discoverAttributes()` + +Discover all of the attributes of BLE device. + +#### Syntax + +``` +bleDevice.discoverAttributes() + +``` + +#### Parameters + +None + +Returns +**true**, if successful, **false** on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // ... + } +… + +``` + +### `discoverService()` + +Discover the attributes of a particular service on the BLE device. + +#### Syntax + +``` +bleDevice.discoverService(serviceUuid) + +``` + +#### Parameters + +**serviceUuid:** service UUID to discover (as a **String**) + +Returns +**true**, if successful, **false** on failure. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover service attributes + Serial.println("Discovering service attributes ..."); + if (peripheral.serviceUuid("fffe")) { + Serial.println("Service attributes discovered"); + } else { + Serial.println("Service attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // ... + } +… + +``` + +### `deviceName()` + +Query the device name (BLE characteristic UUID 0x2a00) of a BLE device. + +#### Syntax + +``` +bleDevice.deviceName() + +``` + +#### Parameters + +None + +Returns +**Device name** (as a String). + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // read and print device name of peripheral + Serial.println(); + Serial.print("Device name: "); + Serial.println(peripheral.deviceName()); + Serial.print("Appearance: 0x"); + Serial.println(peripheral.appearance(), HEX); + Serial.println(); + + // ... + } +… + +``` + +### `appearance()` + +Query the appearance (BLE characteristic UUID 0x2a01) of a BLE device. + +#### Syntax + +``` +bleDevice.appearance() + +``` + +#### Parameters + +None + +Returns +**Appearance value** (as a number). + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // read and print device name of peripheral + Serial.println(); + Serial.print("Device name: "); + Serial.println(peripheral.deviceName()); + Serial.print("Appearance: 0x"); + Serial.println(peripheral.appearance(), HEX); + Serial.println(); + + // ... + } +… + +``` + +### `serviceCount()` + +Query the number of services discovered for the BLE device. + +#### Syntax + +``` +bleDevice.serviceCount() + +``` + +#### Parameters + +None + +Returns +The number of **services discovered** for the BLE device. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + int serviceCount = peripheral.serviceCount(); + + Serial.print(serviceCount); + Serial.println(" services discovered"); + + // ... + } +… + +``` + +### `hasService()` + +Query if the BLE device has a particular service. + +#### Syntax + +``` +bleDevice.hasService(uuid) +bleDevice.hasService(uuid, index) + +``` + +#### Parameters + +**uuid**: uuid to check (as a **String**) +**index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. + +Returns +**true**, if the device provides the service, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + if (peripheral.hasService("180f")) { + Serial.println("Peripheral has battery service"); + } + + // ... + } +… + +``` + +### `service()` + +Get a BLEService representing a BLE service the device provides. + +#### Syntax + +``` +bleDevice.service(index) +bleDevice.service(uuid) +bleDevice.service(uuid, index) + +``` + +#### Parameters + +**index**: index of service +**uuid**: uuid (as a **String**) + +Returns +**BLEService** for provided parameters + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + BLEService batteryService = peripheral.service("180f"); + + if (batteryService) { + // use the service + } else { + Serial.println("Peripheral does NOT have battery service"); + } + + // ... + } +… + +``` + +### `characteristicCount()` + +Query the number of characteristics discovered for the BLE device. + +#### Syntax + +``` +bleDevice.characteristicCount() + +``` + +#### Parameters + +None + +Returns +The **number of characteristics** discovered for the BLE device. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + int characteristicCount = peripheral.characteristicCount(); + + Serial.print(characteristicCount); + Serial.println(" characteristis discovered"); + + // ... + } +… + +``` + +### `hasCharacteristic()` + +Query if the BLE device has a particular characteristic. + +#### Syntax + +``` +bleDevice.hasCharacteristic(uuid) +bleDevice.hasCharacteristic(uuid, index) + +``` + +#### Parameters + +**uuid**: uuid to check (as a **String**) +**index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. + +Returns +**true**, if the device provides the characteristic, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + if (peripheral.hasCharacteristic("2a19")) { + Serial.println("Peripheral has battery level characteristic"); + } + + // ... + } +… + +``` + +### `hasLocalName()` + +Query if a discovered BLE device is advertising a local name. + +#### Syntax + +``` +bleDevice.hasLocalName() + +``` + +#### Parameters + +Nothing + +Returns +**true**, if the device is advertising a local name, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // ... + } +… + +``` + +### `hasAdvertisedServiceUuid()` + +Query if a discovered BLE device is advertising a service UUID. + +#### Syntax + +``` +bleDevice.hasAdvertisedServiceUuid() +bleDevice.hasAdvertisedServiceUuid(index) + +``` + +#### Parameters + +**index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. + +Returns +**true**, if the device is advertising a service UUID, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // ... + } +… + +``` + +### `advertisedServiceUuidCount()` + +Query the number of advertised services a discovered BLE device is advertising. + +#### Syntax + +``` +bleDevice.advertisedServiceUuidCount() + +``` + +#### Parameters + +None + +Returns +The **number of advertised services** a discovered BLE device is advertising. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // ... + } +… + +``` + +### `localName()` + +Query the local name a discovered BLE device is advertising with. + +#### Syntax + +``` +bleDevice.localName() + +``` + +#### Parameters + +Nothing + +Returns +**Advertised local name** (as a String). + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // ... + } +… + +``` + +### `advertisedServiceUuid()` + +Query an advertised service UUID discovered BLE device is advertising. + +#### Syntax + +``` +bleDevice.advertisedServiceUuid() +bleDevice.advertisedServiceUuid(index) + +``` + +#### Parameters + +**index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. + +Returns +Advertised service **UUID** (as a String). + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // ... + } +… + +``` + +### `connect()` + +Connect to a BLE device. + +#### Syntax + +``` +bleDevice.connect() + +``` + +#### Parameters + +None + +Returns +**true**, if the connection was successful, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // ... + } +… + +``` + +## BLEService Class + +Used to enable the services board provides or interact with services a remote board provides. + +### `BLEService()` + +Create a new BLE service. + +#### Syntax + +``` +BLEService(uuid) + +``` + +#### Parameters + +**uuid**: 16-bit or 128-bit UUID in **String** format + +Returns +New **BLEService** with the specified **UUID** + +#### Example + +```Arduino +… +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +… + +``` + +### `uuid()` + +Query the UUID of the specified BLEService. + +#### Syntax + +``` +bleService.uuid() + +``` + +#### Parameters + +None + +Returns +UUID of the BLE service as a **String**. + +#### Example + +```Arduino +… +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service + +// … +Serial.print(“LED service UUID = “); +Serial.println(ledService.uuid()); + +… + +``` + +### `addCharacteristic()` + +Add a BLECharateristic to the BLE service. + +#### Syntax + +``` +bleService.addCharacteristic(bleCharacteristic) + +``` + +#### Parameters + +None + +Returns +Nothing + +#### Example + +```Arduino +… +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service + +// BLE LED Switch Characteristic - custom 128-bit UUID, readable and writable by central +BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); + + +// … + +// add the characteristic to the service +ledService.addCharacteristic(switchCharacteristic); + +… + +``` + +### `characteristicCount()` + +Query the number of characteristics discovered for the BLE service. + +#### Syntax + +``` +bleService.characteristicCount() + +``` + +#### Parameters + +None + +Returns +The **number of characteristics** discovered for the BLE service. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + BLEService batteryService = peripheral.service("180f"); + + if (batteryService) { + // use the service + int characteristicCount = batteryService.characteristicCount(); + + Serial.print(characteristicCount); + Serial.println(" characteristics discovered in battery service"); + } else { + Serial.println("Peripheral does NOT have battery service"); + } + + // ... + } +… + +``` + +### `hasCharacteristic()` + +Query if the BLE service has a particular characteristic. + +#### Syntax + +``` +bleService.hasCharacteristic(uuid) +bleService.hasCharacteristic(uuid, index) + +``` + +#### Parameters + +**uuid**: uuid to check (as a **String**) +**index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. + +Returns +**true**, if the service provides the characteristic, **false** otherwise. + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + BLEService batteryService = peripheral.service("180f"); + + if (batteryService) { + // use the service + if (batteryService.hasCharacteristic("2a19")) { + Serial.println("Battery service has battery level characteristic"); + } + } else { + Serial.println("Peripheral does NOT have battery service"); + } + + // ... + } +… + +``` + +### `characteristic()` + +Get a BLECharacteristic representing a BLE characteristic the service provides. + +#### Syntax + +``` +bleService.characteristic(index) +bleService.characteristic(uuid) +bleService.characteristic(uuid, index) + +``` + +#### Parameters + +**index**: index of characteristic +**uuid**: uuid (as a **String**) + +Returns +**BLECharacteristic** for provided parameters + +#### Example + +```Arduino +… + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + Serial.println("BLE Central scan"); + + // start scanning for peripheral + BLE.scan(); + + // … + + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // ... + + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + BLEService batteryService = peripheral.service("180f"); + + if (batteryService) { + // use the service + BLECharacteristic batteryLevelCharacterisic = peripheral.characteristic("2a19"); + + if (batteryLevelCharacterisic) { + // use the characteristic + } else { + Serial.println("Peripheral does NOT have battery level characteristic"); + } + } else { + Serial.println("Peripheral does NOT have battery service"); + } + + // ... + } +… + +``` + +## BLECharacteristic Class + +Used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. + +### `BLECharacteristic()` + +Create a new BLE characteristic. + +#### Syntax + +``` +BLECharacteristic(uuid, properties, value, valueSize) +BLECharacteristic(uuid, properties, stringValue) + +BLEBoolCharacteristic(uuid, properties) +BLEBooleanCharacteristic(uuid, properties) +BLECharCharacteristic(uuid, properties) +BLEUnsignedCharCharacteristic(uuid, properties) +BLEByteCharacteristic(uuid, properties) +BLEShortCharacteristic(uuid, properties) +BLEUnsignedShortCharacteristic(uuid, properties) +BLEWordCharacteristic(uuid, properties) +BLEIntCharacteristic(uuid, properties) +BLEUnsignedIntCharacteristic(uuid, properties) +BLELongCharacteristic(uuid, properties) +BLEUnsignedLongCharacteristic(uuid, properties) +BLEFloatCharacteristic(uuid, properties) +BLEDoubleCharacteristic(uuid, properties) +``` + +#### Parameters + +**uuid**: 16-bit or 128-bit UUID in **String** format +**properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) +**valueSize**: (maximum) size of characteristic value +**stringValue**: value as a string + +Returns +New **BLECharacteristic** with the specified **UUID** and value + +#### Example + +```Arduino +… +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes + +… + +``` + +### `uuid()` + +Query the UUID of the specified BLECharacteristic. + +#### Syntax + +``` +bleCharacteristic.uuid() + +``` + +#### Parameters + +None + +Returns +**UUID** of the BLE service as a **String**. + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +// … +Serial.print(“Switch characteristic UUID = “); +Serial.println(switchCharacteristic.uuid()); + +… + +``` + +### `properties()` + +Query the property mask of the specified BLECharacteristic. + +#### Syntax + +``` +bleCharacteristic.properties() + +``` + +#### Parameters + +None + +Returns +**Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +// … +byte properties = switchCharacteristic.properties(); + +if (properties & BLERead) { + // characteristic is readable ... +} + +if (properties & (BLEWrite | BLEWriteWithoutResponse)) { + // characteristic is writable ... +} +… + +``` + +### `valueSize()` + +Query the maximum value size of the specified BLECharacteristic. + +#### Syntax + +``` +bleCharacteristic.valueSize() + +``` + +#### Parameters + +None + +Returns +The **maximum value** size of the characteristic (in bytes) + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +// … + +Serial.print(“value size = “); +Serial.println(switchCharacteristic.valueSize()); +… + +``` + +### `value()` + +Query the current value of the specified BLECharacteristic. + +#### Syntax + +``` +bleCharacteristic.value() + +``` + +#### Parameters + +None + +Returns +The **current value** of the characteristic, value type depends on the constructor used + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +// … + + if (switchCharacteristic.value()) { // any value other than 0 + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); // will turn the LED on + } else { // a 0 value + Serial.println(F("LED off")); + digitalWrite(ledPin, LOW); // will turn the LED off + } + +… + +``` + +### `valueLength()` + +Query the current value size of the specified BLECharacteristic. + +#### Syntax + +``` +bleCharacteristic.valueLength() + +``` + +#### Parameters + +None + +Returns +The **current value** size of the characteristic (in bytes) + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +// … + +Serial.print(“value length = “); +Serial.println(switchCharacteristic.valueLength()); +… + +``` + +### `readValue()` + +Read the current value of the characteristic. If the characteristic is on a remote device, a read request will be sent. + +#### Syntax + +``` +bleCharacteristic.readValue(buffer, length) +bleCharacteristic.readValue(value) + +``` + +#### Parameters + +**buffer:** byte array to read value into length: size of buffer argument in bytes +**value**: variable to read value into (by reference) + +Returns +Number of bytes read + +#### Example + +```Arduino +… + while (peripheral.connected()) { + // while the peripheral is connected + + // check if the value of the simple key characteristic has been updated + if (simpleKeyCharacteristic.valueUpdated()) { + // yes, get the value, characteristic is 1 byte so use byte value + byte value = 0; + + simpleKeyCharacteristic.readValue(value); + + if (value & 0x01) { + // first bit corresponds to the right button + Serial.println("Right button pressed"); + } + + if (value & 0x02) { + // second bit corresponds to the left button + Serial.println("Left button pressed"); + } + } + } +… + +``` + +### `writeValue()` + +Write the value of the characteristic. If the characteristic is on a remote device, a write request or command will be sent. + +#### Syntax + +``` +bleCharacteristic.writeValue(buffer, length) +bleCharacteristic.writeValue(value) + +``` + +#### Parameters + +**buffer**: byte array to write value with +**length**: number of bytes of the buffer argument to write +**value**: value to write + +Returns +1 on success, 0 on failure + +#### Example + +```Arduino +… + // read the button pin + int buttonState = digitalRead(buttonPin); + + if (oldButtonState != buttonState) { + // button changed + oldButtonState = buttonState; + + if (buttonState) { + Serial.println("button pressed"); + + // button is pressed, write 0x01 to turn the LED on + ledCharacteristic.writeValue((byte)0x01); + } else { + Serial.println("button released"); + + // button is released, write 0x00 to turn the LED off + ledCharacteristic.writeValue((byte)0x00); + } + } +… + +``` + +### `setEventHandler()` + +Set the event handler (callback) function that will be called when the specified event occurs. + +#### Syntax + +``` +bleCharacteristic.setEventHandler(eventType, callback) + +``` + +#### Parameters + +**eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) +**callback**: function to call when the event occurs + +Returns +Nothing + +#### Example + +```Arduino +… +// create switch characteristic and allow remote device to read and write +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + + +// … + + // assign event handlers for characteristic + switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); + +// … + +void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { + // central wrote new value to characteristic, update LED + Serial.print("Characteristic event, written: "); + + if (switchCharacteristic.value()) { + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); + } else { + Serial.println("LED off"); + digitalWrite(ledPin, LOW); + } +} + + … + +``` + +### `broadcast()` + +Broadcast the characteristics value as service data when advertising. + +#### Syntax + +``` +bleCharacteristic.broadcast() + +``` + +#### Parameters + +None + +Returns +1 on success, 0 on failure + +#### Example + +```Arduino +… +// create button characteristic and allow remote device to get notifications +BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify | BLEBroadcast); + +// … + +buttonCharacteristic.broadcast(); + +… + +``` + +### `written()` + +Query if the characteristic value has been written by another BLE device. + +#### Syntax + +``` +bleCharacteristic.written() + +``` + +#### Parameters + +None + +Returns +**true** if the characteristic value has been written by another BLE device, **false** otherwise + +#### Example + +```Arduino +… +// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + + +// … + + // listen for BLE peripherals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's MAC address: + Serial.println(central.address()); + + // while the central is still connected to peripheral: + while (central.connected()) { + // if the remote device wrote to the characteristic, + // use the value to control the LED: + if (switchCharacteristic.written()) { + if (switchCharacteristic.value()) { // any value other than 0 + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); // will turn the LED on + } else { // a 0 value + Serial.println(F("LED off")); + digitalWrite(ledPin, LOW); // will turn the LED off + } + } + } + + // when the central disconnects, print it out: + Serial.print(F("Disconnected from central: ")); + Serial.println(central.address()); + } + + +… + +``` + +### `subscribed()` + +Query if the characteristic has been subscribed to by another BLE device. + +#### Syntax + +``` +bleCharacteristic.subscribed() + +``` + +#### Parameters + +None + +Returns +**true** if the characteristic value has been subscribed to by another BLE device, **false** otherwise + +#### Example + +```Arduino +… +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes + + + +// … + + if (batteryLevelChar.subscribed()) { + // set a new value , that well be pushed to subscribed BLE devices + batteryLevelChar.writeValue(0xab); + } +… + +``` + +### `addDescriptor()` + +Add a BLEDescriptor to the characteristic. + +#### Syntax + +``` +bleCharacteristic.addDescriptor(bleDescriptor) + +``` + +#### Parameters + +**bleDescriptor**: descriptor to add to the characteristic + +Returns +Nothing + +#### Example + +```Arduino +… +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes + +BLEDescriptor batteryLevelDescriptor("2901", "millis"); + + + +// … + + batteryLevelChar.addDescriptor(batteryLevelDescriptor); +… + +``` + +### `descriptorCount` + +Query the number of BLE descriptors discovered for the characteristic. + +#### Syntax + +``` +bleCharacteristic.descriptorCount() + +``` + +#### Parameters + +None + +Returns +The **number of BLE descriptors** discovered for the characteristic + +#### Example + +```Arduino +… + // loop the descriptors of the characteristic and explore each + for (int i = 0; i < characteristic.descriptorCount(); i++) { + BLEDescriptor descriptor = characteristic.descriptor(i); + + // ... + } +… + +``` + +### `hasDescriptor` + +Check if a characteristic has a particular descriptor. + +#### Syntax + +``` +bleCharacteristic.hasDescriptor(uuid) +bleCharacteristic.hasDescriptor(uuid, index) + +``` + +#### Parameters + +**index**: index of descriptor +**uuid**: uuid (as a **String**) + +Returns +**true**, if the characteristic has a matching descriptor, otherwise **false**. + +#### Example + +```Arduino +… + if (characteristic.hasDescriptor("2901")) { + Serial.println("characteristic has description descriptor"); + } +… + +``` + +### `descriptor()` + +Get a BLEDescriptor that represents a characteristics BLE descriptor. + +#### Syntax + +``` +bleCharacteristic.descriptor(index) +bleCharacteristic.descriptor(uuid) +bleCharacteristic.descriptor(uuid, index) + +``` + +#### Parameters + +**index**: index of descriptor +**uuid**: uuid (as a **String**) + +Returns +BLEDescriptor that represents a characteristics BLE descriptor + +#### Example + +```Arduino +… + if (characteristic.hasDescriptor("2901")) { + Serial.println("characteristic has description descriptor"); + } +… + +``` + +### `canRead()` + +Query if a BLE characteristic is readable. + +#### Syntax + +``` +bleCharacteristic.canRead() + +``` + +#### Parameters + +None + +Returns +**true**, if characteristic is readable, **false** otherwise + +#### Example + +```Arduino +… + if (characteristic.canRead("2901")) { + Serial.println("characteristic is readable"); + } +… + +``` + +read + +Perform a read request for the characteristic. + +#### Syntax + +``` +bleCharacteristic.read() + +``` + +#### Parameters + +None + +Returns +**true**, if successful, **false** on failure + +#### Example + +```Arduino +… + if (characteristic.read()) { + Serial.println("characteristic value read"); + + // ... + } else { + Serial.println("error reading characteristic value"); + } +… + +``` + +### `canWrite()` + +Query if a BLE characteristic is writable. + +#### Syntax + +``` +bleCharacteristic.canWrite() + +``` + +#### Parameters + +None + +Returns +**true**, if characteristic is writable, **false** otherwise + +#### Example + +```Arduino +… + if (characteristic.canWrite()) { + Serial.println("characteristic is writable"); + } +… + +``` + +### `canSubscribe()` + +Query if a BLE characteristic is subscribable. + +#### Syntax + +``` +bleCharacteristic.canSubscribe() + +``` + +#### Parameters + +None + +Returns +**true**, if characteristic is subscribable, **false** otherwise + +#### Example + +```Arduino +… + if (characteristic.canSubscribe()) { + Serial.println("characteristic is subscribable"); + } +… + +``` + +### `subscribe()` + +Subscribe to a BLE characteristics notification or indications. + +#### Syntax + +``` +bleCharacteristic.subscribe() + +``` + +#### Parameters + +None + +Returns +**true**, on success, **false** on failure + +#### Example + +```Arduino +… + // ... + + // retrieve the simple key characteristic + BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); + + // subscribe to the simple key characteristic + Serial.println("Subscribing to simple key characteristic ..."); + if (!simpleKeyCharacteristic) { + Serial.println("no simple key characteristic found!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.canSubscribe()) { + Serial.println("simple key characteristic is not subscribable!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.subscribe()) { + Serial.println("subscription failed!"); + peripheral.disconnect(); + return; + } + + // ... +… + +``` + +### `canUnsubscribe()` + +Query if a BLE characteristic is unsubscribable. + +#### Syntax + +``` +bleCharacteristic.canUnsubscribe() + +``` + +#### Parameters + +None + +Returns +**true**, if characteristic is unsubscribable, **false** otherwise + +#### Example + +```Arduino +… + if (characteristic.canUnsubscribe()) { + Serial.println("characteristic is unsubscribable"); + } +… + +``` + +### `unsubscribe()` + +Unsubscribe to a BLE characteristics notifications or indications. + +#### Syntax + +``` +bleCharacteristic.unsubscribe() + +``` + +#### Parameters + +None + +Returns +**true**, on success, **false** on failure + +#### Example + +```Arduino +… + // ... + + // retrieve the simple key characteristic + BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); + + // subscribe to the simple key characteristic + Serial.println("Subscribing to simple key characteristic ..."); + if (!simpleKeyCharacteristic) { + Serial.println("no simple key characteristic found!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.canSubscribe()) { + Serial.println("simple key characteristic is not subscribable!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.subscribe()) { + Serial.println("subscription failed!"); + peripheral.disconnect(); + return; + } + + // ... + + simpleKeyCharacteristic.unsubscribe(); +… + +``` + +### `valueUpdated()` + +Has the characteristics value been updated via a notification or indication. + +#### Syntax + +``` +bleCharacteristic.valueUpdated() + +``` + +#### Parameters + +None + +Returns +**true**, if the characteristics value been updated via a notification or indication + +#### Example + +```Arduino +… + while (peripheral.connected()) { + // while the peripheral is connected + + // check if the value of the simple key characteristic has been updated + if (simpleKeyCharacteristic.valueUpdated()) { + // yes, get the value, characteristic is 1 byte so use byte value + byte value = 0; + + simpleKeyCharacteristic.readValue(value); + + if (value & 0x01) { + // first bit corresponds to the right button + Serial.println("Right button pressed"); + } + + if (value & 0x02) { + // second bit corresponds to the left button + Serial.println("Left button pressed"); + } + } + } +… + +``` + +## BLEDescriptor Class + +Used to describe a characteristic the board offers + +### `BLEDescriptor()` + +Create a new BLE descriptor. + +#### Syntax + +``` +BLEDescriptor(uuid, value, valueSize) +BLEDescriptor(uuid, stringValue) + +``` + +#### Parameters + +**uuid**: 16-bit or 128-bit UUID in string format +**value**: byte array value +**valueSize**: size of byte array value +**stringValue**: value as a string + +Returns +New **BLEDescriptor** with the specified **UUID** and value + +#### Example + +```Arduino +… +BLEDescriptor millisLabelDescriptor("2901", "millis"); +… + +``` + +### `uuid()` + +Query the UUID of the specified BLEDescriptor. + +#### Syntax + +``` +bleDescriptor.uuid() + +``` + +#### Parameters + +None + +Returns +**UUID** of the BLE descriptor (as a String). + +#### Example + +```Arduino +… +BLEDescriptor millisLabelDescriptor("2901", "millis"); + +// … +Serial.print(“millis label descriptor UUID = “); +Serial.println(millisLabelDescriptor.uuid()); + +… + +``` + +### `valueSize()` + +Query the value size of the specified BLEDescriptor. + +#### Syntax + +``` +bleDescriptor.valueSize() + +``` + +#### Parameters + +None + +Returns +**Value size** (in bytes) of the BLE descriptor. + +#### Example + +```Arduino +… +BLEDescriptor millisLabelDescriptor("2901", "millis"); + +// … +Serial.print(“millis label descriptor value size = “); +Serial.println(millisLabelDescriptor.valueSize()); + +… + +``` + +### `valueLength()` + +Query the length, in bytes, of the descriptor current value. + +#### Syntax + +``` +bleDescriptor.valueLength() + +``` + +#### Parameters + +None + +Returns +**Length of descriptor** value in bytes. + +#### Example + +```Arduino +… + // read the descriptor value + descriptor.read(); + + // print out the value of the descriptor + Serial.print(", value 0x"); + printData(descriptor.value(), descriptor.valueLength()); + + // ... + + void printData(const unsigned char data[], int length) { + for (int i = 0; i < length; i++) { + unsigned char b = data[i]; + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + } +… + +``` + +### `value()` + +Query the value of the specified BLEDescriptor. + +#### Syntax + +``` +bleDescriptor.value() + +``` + +#### Parameters + +None + +Returns +Value byte array of the **BLE descriptor**. + +#### Example + +```Arduino +… +BLEDescriptor millisLabelDescriptor("2901", "millis"); + +// … + + int descriptorValueSize = millisLabelDescriptor.valueSize(); + byte descriptorValue[descriptorValueSize]; + + for (int i = 0; i < descriptorValueSize; i++) { + descriptorValue[i] = millisLabelDescriptor.value()[i]; + } + +… + +``` + +### `readValue()` + +Read the current value of the descriptor. If the descriptor is on a remote device, a read request will be sent. + +#### Syntax + +``` +bleDescriptor.readValue(buffer, length) +bleDescriptor.readValue(value) + +``` + +#### Parameters + +**buffer**: byte array to read value into +**length**: size of buffer argument in bytes +**value**: variable to read value into (by reference) + +Returns +**Number of bytes** read + +#### Example + +```Arduino +… + byte value = 0; + + /get the value, descriptor is 1 byte so use byte value + descriptor.readValue(value); +… + +``` + +### `read()` + +Perform a read request for the descriptor. + +#### Syntax + +``` +bleDescriptor.read() + +``` + +#### Parameters + +None + +Returns +**true**, if successful, **false** on failure + +#### Example + +```Arduino +… + if (descriptor.read()) { + Serial.println("descriptor value read"); + + // ... + } else { + Serial.println("error reading descriptor value"); + } +… +``` diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 00000000..86949a50 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,91 @@ +# ArduinoBLE library + +This library supports all the Arduino boards that have the hardware enabled for BLE and Bluetooth 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010. + +To use this library +``#include `` + +## A quick introduction to BLE + +Bluetooth 4.0 includes both traditional Bluetooth, now labeled "Bluetooth Classic", and the Bluetooth Low Energy (Bluetooth LE, or BLE). BLE is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. + +Unlike standard bluetooth communication basically based on an asynchronous serial connection (UART) a Bluetooth LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth LE world because they read information available from the peripherals. + +![Communication between central and peripheral devices](www.arduino.cc/en/uploads/Reference/ble-bulletin-board-model.png) + +Think of a Bluetooth LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. + +The information presented by a peripheral is structured as **services**, each of which is subdivided into **characteristics**. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices. If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not. If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it. + +## Notify + +The Bluetooth LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgement of the pushed data. + +The client-server structure of Bluetooth LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. + +## Update a characteristic + +Your peripheral should update characteristics when there's a significant change to them. For example, when a switch changes from off to on, update its characteristic. When an analog sensor changes by a significant amount, update its characteristic. + +Just as with writing to a characteristic, you could update your characteristics on a regular interval, but this wastes processing power and energy if the characteristic has not changed. + +## Central and Peripheral Devices + +**Central** devices are **clients**. They read and write data from peripheral devices. **Peripheral** devices are **servers**. They provide data from sensors as readable characteristics, and provide read/writable characteristics to control actuators like motors, lights, and so forth. + +## Services, characteristics, and UUIDs + +A BLE peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use [standard services](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx). + +Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. + +## Service design patterns + +A characteristic value can be up to 512 bytes long. This is a key constraint in designing services. Given this limit, you should consider how best to store data about your sensors and actuators most effectively for your application. The simplest design pattern is to store one sensor or actuator value per characteristic, in ASCII encoded values. + +|**Characteristic**|**Value**| +|------------------|---------| +|Accelerometer X|200| +|Accelerometer Y|134| +|Accelerometer Z|150| + +This is also the most expensive in memory terms, and would take the longest to read. But it's the simplest for development and debugging. + +You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it. + +|**Characteristic**|**Value**| +|------------------|---------| +|Motor Speed, Direction|150,1| +|Accelerometer X, Y, Z|200,133,150| + +This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as a ASCII-encoded string. + +## Read/write/notify/indicate + +There are 4 things a central device can do with a characteristic: + +- **Read:** ask the peripheral to send back the current value of the characteristic. Often used for characteristics that don't change very often, for example characteristics used for configuration, version numbers, etc. +- **Write:** modify the value of the characteristic. Often used for things that are like commands, for example telling the peripheral to turn a motor on or off. +- **Indicate** and **Notify:** ask the peripheral to continuously send updated values of the characteristic, without the central having to constantly ask for it. + +## Advertising and GAP + +BLE devices let other devices know that they exist by advertising using the **General Advertising Profile (GAP)**. Advertising packets can contain a device name, some other information, and also a list of the services it provides. + +Advertising packets have a limited size. You will only be able to fit a single 128-bit service UUID in the packet. Make sure the device name is not too long, or you won't even be able to fit that. + +You can provide additional services that are not advertised. Central devices will learn about these through the connection/bonding process. Non-advertised services cannot be used to discover devices, though. Sometimes this is not an issue. For example, you may have a custom peripheral device with a custom service, but in your central device app you may know that it also provides the Battery Service and other services. + +## GATT + +The Bluetooth LE protocol operates on multiple layers. **General Attribute Profile (GATT)** is the layer that defines services and characteristics and enables read/write/notify/indicate operations on them. When reading more about GATT, you may encounter GATT concepts of a "server" and "client". These don't always correspond to central and peripherals. In most cases, though, the peripheral is the GATT server (since it provides the services and characteristics), while the central is the GATT client. + +## Library structure + +As the library enables multiple types of functionality, there are a number of different classes. + +- BLE used to enable the BLE module. +- BLEDevice used to get information about the devices connected or discovered while scanning. +- BLEService used to enable the services board provides or interact with services a remote board provides. +- BLECharacteristic used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. +- BLEDescriptor used to describe a characteristic the board offers. From ceb39326ec0c7801d8ff9a468057a616dfdcbbb8 Mon Sep 17 00:00:00 2001 From: LiamAljundi <46995170+LiamAljundi@users.noreply.github.com> Date: Mon, 23 Aug 2021 11:44:35 +0200 Subject: [PATCH 021/112] updated content --- docs/api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api.md b/docs/api.md index fc0e9c07..8356b310 100644 --- a/docs/api.md +++ b/docs/api.md @@ -3783,6 +3783,7 @@ Returns #### Example + ```Arduino … byte value = 0; From 21a332fa2a37be592c536da1f6e560276e92b321 Mon Sep 17 00:00:00 2001 From: LiamAljundi <46995170+LiamAljundi@users.noreply.github.com> Date: Tue, 24 Aug 2021 11:07:18 +0200 Subject: [PATCH 022/112] fixed suggestions from Karl's review --- docs/api.md | 782 ++++++++++++++++++++++++++-------------------------- 1 file changed, 391 insertions(+), 391 deletions(-) diff --git a/docs/api.md b/docs/api.md index 8356b310..dab294ab 100644 --- a/docs/api.md +++ b/docs/api.md @@ -19,20 +19,20 @@ BLE.begin() None -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); while (1); } -… + ``` @@ -51,13 +51,13 @@ BLE.end() None -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -68,7 +68,7 @@ Nothing // .... BLE.end(); -… + ``` @@ -87,21 +87,21 @@ BLE.poll() BLE.poll(timeout) **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // assign event handlers for connected, disconnected to peripheral BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - // … + BLE.poll(); -… + ``` @@ -120,13 +120,13 @@ BLE.setEventHandler(eventType, callback) **eventType**: event type (BLEConnected, BLEDisconnected) **callback**: function to call when event occurs -Returns +#### Returns Nothing. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -140,7 +140,7 @@ Nothing. BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - // … + void blePeripheralConnectHandler(BLEDevice central) { @@ -154,7 +154,7 @@ void blePeripheralDisconnectHandler(BLEDevice central) { Serial.print("Disconnected event, central: "); Serial.println(central.address()); } -… + ``` @@ -173,19 +173,19 @@ BLE.connected() None -Returns +#### Returns **true** if another BLE device is connected, otherwise **false**. #### Example -```Arduino -… +```arduino + // while the central is still connected to peripheral: while (BLE.connected()) { // ... } -… + ``` @@ -204,19 +204,19 @@ BLE.disconnect() None -Returns +#### Returns **true** if any BLE device that was previously connected was disconnected, otherwise **false**. #### Example -```Arduino -… +```arduino + if (BLE.connected()) { - // … + BLE.disconnect(); } -… + ``` @@ -235,18 +235,18 @@ BLE.address() None -Returns +#### Returns The **Bluetooth address** of the BLE device (as a String). #### Example -```Arduino -… +```arduino + **String** address = BLE.address(); Serial.print(“Local address is: “); Serial.println(address); -… + ``` @@ -265,20 +265,20 @@ BLE.rssi() None -Returns +#### Returns The **RSSI** of the connected BLE device, 127 if no BLE device is connected. #### Example -```Arduino -… +```arduino + if (BLE.connected()) { - // … + Serial.print(“RSSI = “); Serial.println(BLE.rssi()); } -… + ``` @@ -297,13 +297,13 @@ BLE.setAdvertisedServiceUuid(uuid) **uuid:** 16-bit or 128-bit BLE UUID in **String** format -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -317,7 +317,7 @@ Nothing // start advertising BLE.advertise(); -… + ``` @@ -336,13 +336,13 @@ BLE.setAdvertisedService(bleService) **bleService:** BLEService to use UUID from -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service // ... @@ -360,7 +360,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Servic // start advertising BLE.advertise(); -… + ``` @@ -380,13 +380,13 @@ BLE.setManufacturerData(data, length) **data:** byte array containing manufacturer data **length:** length of manufacturer data array -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -403,7 +403,7 @@ Nothing // start advertising BLE.advertise(); -… + ``` @@ -422,13 +422,13 @@ BLE.setLocalName(name) **name:** local name value to use when advertising -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -443,7 +443,7 @@ Nothing // start advertising BLE.advertise(); -… + ``` @@ -462,13 +462,13 @@ BLE.setDeviceName(name) **name:** device name value -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -483,7 +483,7 @@ Nothing // start advertising BLE.advertise(); -… + ``` @@ -502,13 +502,13 @@ BLE.setAppearance(appearance) **appearance:** appearance value -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -523,7 +523,7 @@ Nothing // start advertising BLE.advertise(); -… + ``` @@ -542,16 +542,16 @@ BLE.addService(service) **service:** BLEService to add -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service -// … + // begin initialization if (!BLE.begin()) { @@ -565,7 +565,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Servic BLE.addService(ledService); // ... -… + ``` @@ -584,13 +584,13 @@ BLE.advertise() None -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -603,7 +603,7 @@ Returns BLE.advertise(); // ... -… + ``` @@ -622,13 +622,13 @@ BLE.stopAdvertise() None -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -643,7 +643,7 @@ Nothing // ... BLE.stopAdvertise(); -… + ``` @@ -662,13 +662,13 @@ BLE.central() None -Returns +#### Returns **BLEDevice** representing the central. #### Example -```Arduino -… +```arduino + // listen for BLE peripherals to connect: BLEDevice central = BLE.central(); @@ -678,9 +678,9 @@ Returns // print the central's MAC address: Serial.println(central.address()); - // … + } -… + ``` @@ -699,13 +699,13 @@ BLE.setAdvertisingInterval(advertisingInterval) **advertisingInterval:** advertising interval in units of 0.625 ms -Returns +#### Returns Nothing. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -718,7 +718,7 @@ Nothing. BLE.setAdvertisingInterval(320); // 200 * 0.625 ms BLE.advertise(); -… + ``` @@ -738,13 +738,13 @@ BLE.setConnectionInterval(minimum, maximum) **minimum:** minimum desired connection interval in units of 1.25 ms **maximum:** maximum desired connection interval in units of 1.25 ms -Returns +#### Returns Nothing. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -756,7 +756,7 @@ Nothing. BLE.setConnectionInterval(0x0006, 0x0c80); // 7.5 ms minimum, 4 s maximum -… + ``` @@ -776,13 +776,13 @@ BLE.setConnectable(connectable) **true**: the device will be connectable when advertising **false**: the device will NOT be connectable when advertising -Returns +#### Returns Nothing. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -794,7 +794,7 @@ Nothing. BLE.setConnectable(false); // make the device unconnectable when advertising -… + ``` @@ -814,13 +814,13 @@ BLE.scan(withDuplicates) **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -833,14 +833,14 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { // ... } -… + ``` @@ -861,13 +861,13 @@ BLE.scanForName(name, withDuplicates) **name:** (local) name of device (as a **String**) to filter for **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -880,14 +880,14 @@ Returns // start scanning for peripheral BLE.scanForName("LED"); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { // ... } -… + ``` @@ -908,13 +908,13 @@ BLE.scanForAddress(address, withDuplicates) **address:** (Bluetooth) address (as a String) to filter for **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -927,14 +927,14 @@ Returns // start scanning for peripheral BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { // ... } -… + ``` @@ -955,13 +955,13 @@ BLE.scanForUuid(uuid, withDuplicates) **uuid:** (service) UUID (as a **String**) to filter for **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. -Returns +#### Returns 1 on success, 0 on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -974,14 +974,14 @@ Returns // start scanning for peripheral BLE.scanForUuid("aa10"); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { // ... } -… + ``` @@ -1000,13 +1000,13 @@ BLE.stopScan() None -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1019,9 +1019,9 @@ Nothing // start scanning for peripheral BLE.scan(); - // … + BLE.stopScan(); -… + ``` @@ -1040,13 +1040,13 @@ BLE.available() Nothing -Returns +#### Returns **BLEDevice** representing the discovered device. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1059,14 +1059,14 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { // ... } -… + ``` @@ -1090,25 +1090,25 @@ bleDevice.poll(timeout) **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // listen for BLE centrals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: if (central) { - // … + central.poll(); // ... } -… + ``` @@ -1127,13 +1127,13 @@ bleDevice.connected() None -Returns +#### Returns **true** if the BLE device is connected, otherwise **false**. #### Example -```Arduino -… +```arduino + // listen for BLE centrals to connect: BLEDevice central = BLE.central(); @@ -1142,7 +1142,7 @@ Returns // ... } -… + ``` @@ -1161,20 +1161,20 @@ bleDevice.disconnect() None -Returns +#### Returns **true** if the BLE device was disconnected, otherwise **false**. #### Example -```Arduino -… +```arduino + // listen for BLE centrals to connect: BLEDevice central = BLE.central(); - // … + central.disconnect(); -… + ``` @@ -1193,13 +1193,13 @@ bleDevice.address() None -Returns +#### Returns The **Bluetooth address** of the BLE device (as a String). #### Example -```Arduino -… +```arduino + // listen for BLE peripherals to connect: BLEDevice central = BLE.central(); @@ -1209,9 +1209,9 @@ The **Bluetooth address** of the BLE device (as a String). // print the central's MAC address: Serial.println(central.address()); - // …. + . } -… + ``` @@ -1230,20 +1230,20 @@ bleDevice.rssi() None -Returns +#### Returns The **RSSI** of the connected BLE device, 127 if the BLE device is not connected. #### Example -```Arduino -… +```arduino + if (bleDevice.connected()) { - // … + Serial.print(“RSSI = “); Serial.println(bleDevice.rssi()); } -… + ``` @@ -1265,13 +1265,13 @@ bleDevice.characteristic(uuid, index) **index**: index of characteristic **uuid**: uuid (as a **String**) -Returns +#### Returns **BLECharacteristic** for provided parameters #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1284,7 +1284,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1320,7 +1320,7 @@ Returns // ... } -… + ``` @@ -1339,13 +1339,13 @@ bleDevice.discoverAttributes() None -Returns +#### Returns **true**, if successful, **false** on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1358,7 +1358,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1386,7 +1386,7 @@ Returns // ... } -… + ``` @@ -1405,13 +1405,13 @@ bleDevice.discoverService(serviceUuid) **serviceUuid:** service UUID to discover (as a **String**) -Returns +#### Returns **true**, if successful, **false** on failure. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1424,7 +1424,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1452,7 +1452,7 @@ Returns // ... } -… + ``` @@ -1471,13 +1471,13 @@ bleDevice.deviceName() None -Returns +#### Returns **Device name** (as a String). #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1490,7 +1490,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1526,7 +1526,7 @@ Returns // ... } -… + ``` @@ -1545,13 +1545,13 @@ bleDevice.appearance() None -Returns +#### Returns **Appearance value** (as a number). #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1564,7 +1564,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1600,7 +1600,7 @@ Returns // ... } -… + ``` @@ -1619,13 +1619,13 @@ bleDevice.serviceCount() None -Returns +#### Returns The number of **services discovered** for the BLE device. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1638,7 +1638,7 @@ The number of **services discovered** for the BLE device. // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1671,7 +1671,7 @@ The number of **services discovered** for the BLE device. // ... } -… + ``` @@ -1692,13 +1692,13 @@ bleDevice.hasService(uuid, index) **uuid**: uuid to check (as a **String**) **index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. -Returns +#### Returns **true**, if the device provides the service, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1711,7 +1711,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1743,7 +1743,7 @@ Returns // ... } -… + ``` @@ -1765,13 +1765,13 @@ bleDevice.service(uuid, index) **index**: index of service **uuid**: uuid (as a **String**) -Returns +#### Returns **BLEService** for provided parameters #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1784,7 +1784,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1820,7 +1820,7 @@ Returns // ... } -… + ``` @@ -1839,13 +1839,13 @@ bleDevice.characteristicCount() None -Returns +#### Returns The **number of characteristics** discovered for the BLE device. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1858,7 +1858,7 @@ The **number of characteristics** discovered for the BLE device. // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1891,7 +1891,7 @@ The **number of characteristics** discovered for the BLE device. // ... } -… + ``` @@ -1912,13 +1912,13 @@ bleDevice.hasCharacteristic(uuid, index) **uuid**: uuid to check (as a **String**) **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. -Returns +#### Returns **true**, if the device provides the characteristic, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -1931,7 +1931,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -1963,7 +1963,7 @@ Returns // ... } -… + ``` @@ -1982,13 +1982,13 @@ bleDevice.hasLocalName() Nothing -Returns +#### Returns **true**, if the device is advertising a local name, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2001,7 +2001,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2016,7 +2016,7 @@ Returns // ... } -… + ``` @@ -2036,13 +2036,13 @@ bleDevice.hasAdvertisedServiceUuid(index) **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. -Returns +#### Returns **true**, if the device is advertising a service UUID, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2055,7 +2055,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2074,7 +2074,7 @@ Returns // ... } -… + ``` @@ -2093,13 +2093,13 @@ bleDevice.advertisedServiceUuidCount() None -Returns +#### Returns The **number of advertised services** a discovered BLE device is advertising. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2112,7 +2112,7 @@ The **number of advertised services** a discovered BLE device is advertising. // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2131,7 +2131,7 @@ The **number of advertised services** a discovered BLE device is advertising. // ... } -… + ``` @@ -2150,13 +2150,13 @@ bleDevice.localName() Nothing -Returns +#### Returns **Advertised local name** (as a String). #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2169,7 +2169,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2184,7 +2184,7 @@ Returns // ... } -… + ``` @@ -2204,13 +2204,13 @@ bleDevice.advertisedServiceUuid(index) **index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. -Returns +#### Returns Advertised service **UUID** (as a String). #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2223,7 +2223,7 @@ Advertised service **UUID** (as a String). // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2242,7 +2242,7 @@ Advertised service **UUID** (as a String). // ... } -… + ``` @@ -2261,13 +2261,13 @@ bleDevice.connect() None -Returns +#### Returns **true**, if the connection was successful, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2280,7 +2280,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2298,7 +2298,7 @@ Returns // ... } -… + ``` @@ -2321,15 +2321,15 @@ BLEService(uuid) **uuid**: 16-bit or 128-bit UUID in **String** format -Returns +#### Returns New **BLEService** with the specified **UUID** #### Example -```Arduino -… +```arduino + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service -… + ``` @@ -2348,20 +2348,20 @@ bleService.uuid() None -Returns +#### Returns UUID of the BLE service as a **String**. #### Example -```Arduino -… +```arduino + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service -// … + Serial.print(“LED service UUID = “); Serial.println(ledService.uuid()); -… + ``` @@ -2380,25 +2380,25 @@ bleService.addCharacteristic(bleCharacteristic) None -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service // BLE LED Switch Characteristic - custom 128-bit UUID, readable and writable by central BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); -// … + // add the characteristic to the service ledService.addCharacteristic(switchCharacteristic); -… + ``` @@ -2417,13 +2417,13 @@ bleService.characteristicCount() None -Returns +#### Returns The **number of characteristics** discovered for the BLE service. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2436,7 +2436,7 @@ The **number of characteristics** discovered for the BLE service. // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2476,7 +2476,7 @@ The **number of characteristics** discovered for the BLE service. // ... } -… + ``` @@ -2497,13 +2497,13 @@ bleService.hasCharacteristic(uuid, index) **uuid**: uuid to check (as a **String**) **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. -Returns +#### Returns **true**, if the service provides the characteristic, **false** otherwise. #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2516,7 +2516,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); if (peripheral) { @@ -2554,7 +2554,7 @@ Returns // ... } -… + ``` @@ -2576,13 +2576,13 @@ bleService.characteristic(uuid, index) **index**: index of characteristic **uuid**: uuid (as a **String**) -Returns +#### Returns **BLECharacteristic** for provided parameters #### Example -```Arduino -… +```arduino + // begin initialization if (!BLE.begin()) { Serial.println("starting BLE failed!"); @@ -2595,7 +2595,7 @@ Returns // start scanning for peripheral BLE.scan(); - // … + BLEDevice peripheral = BLE.available(); @@ -2638,7 +2638,7 @@ Returns // ... } -… + ``` @@ -2679,18 +2679,18 @@ BLEDoubleCharacteristic(uuid, properties) **valueSize**: (maximum) size of characteristic value **stringValue**: value as a string -Returns +#### Returns New **BLECharacteristic** with the specified **UUID** and value #### Example -```Arduino -… +```arduino + // BLE Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes -… + ``` @@ -2709,21 +2709,21 @@ bleCharacteristic.uuid() None -Returns +#### Returns **UUID** of the BLE service as a **String**. #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + Serial.print(“Switch characteristic UUID = “); Serial.println(switchCharacteristic.uuid()); -… + ``` @@ -2742,17 +2742,17 @@ bleCharacteristic.properties() None -Returns +#### Returns **Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + byte properties = switchCharacteristic.properties(); if (properties & BLERead) { @@ -2762,7 +2762,7 @@ if (properties & BLERead) { if (properties & (BLEWrite | BLEWriteWithoutResponse)) { // characteristic is writable ... } -… + ``` @@ -2781,21 +2781,21 @@ bleCharacteristic.valueSize() None -Returns +#### Returns The **maximum value** size of the characteristic (in bytes) #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + Serial.print(“value size = “); Serial.println(switchCharacteristic.valueSize()); -… + ``` @@ -2814,17 +2814,17 @@ bleCharacteristic.value() None -Returns +#### Returns The **current value** of the characteristic, value type depends on the constructor used #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + if (switchCharacteristic.value()) { // any value other than 0 Serial.println("LED on"); @@ -2834,7 +2834,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 digitalWrite(ledPin, LOW); // will turn the LED off } -… + ``` @@ -2853,21 +2853,21 @@ bleCharacteristic.valueLength() None -Returns +#### Returns The **current value** size of the characteristic (in bytes) #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + Serial.print(“value length = “); Serial.println(switchCharacteristic.valueLength()); -… + ``` @@ -2888,13 +2888,13 @@ bleCharacteristic.readValue(value) **buffer:** byte array to read value into length: size of buffer argument in bytes **value**: variable to read value into (by reference) -Returns +#### Returns Number of bytes read #### Example -```Arduino -… +```arduino + while (peripheral.connected()) { // while the peripheral is connected @@ -2916,7 +2916,7 @@ Number of bytes read } } } -… + ``` @@ -2938,13 +2938,13 @@ bleCharacteristic.writeValue(value) **length**: number of bytes of the buffer argument to write **value**: value to write -Returns +#### Returns 1 on success, 0 on failure #### Example -```Arduino -… +```arduino + // read the button pin int buttonState = digitalRead(buttonPin); @@ -2964,7 +2964,7 @@ Returns ledCharacteristic.writeValue((byte)0x00); } } -… + ``` @@ -2984,23 +2984,23 @@ bleCharacteristic.setEventHandler(eventType, callback) **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) **callback**: function to call when the event occurs -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // create switch characteristic and allow remote device to read and write BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + // assign event handlers for characteristic switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); -// … + void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { // central wrote new value to characteristic, update LED @@ -3015,7 +3015,7 @@ void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteri } } - … + ``` @@ -3034,21 +3034,21 @@ bleCharacteristic.broadcast() None -Returns +#### Returns 1 on success, 0 on failure #### Example -```Arduino -… +```arduino + // create button characteristic and allow remote device to get notifications BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify | BLEBroadcast); -// … + buttonCharacteristic.broadcast(); -… + ``` @@ -3067,18 +3067,18 @@ bleCharacteristic.written() None -Returns +#### Returns **true** if the characteristic value has been written by another BLE device, **false** otherwise #### Example -```Arduino -… +```arduino + // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -// … + // listen for BLE peripherals to connect: BLEDevice central = BLE.central(); @@ -3110,7 +3110,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 } -… + ``` @@ -3129,26 +3129,26 @@ bleCharacteristic.subscribed() None -Returns +#### Returns **true** if the characteristic value has been subscribed to by another BLE device, **false** otherwise #### Example -```Arduino -… +```arduino + // BLE Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes -// … + if (batteryLevelChar.subscribed()) { // set a new value , that well be pushed to subscribed BLE devices batteryLevelChar.writeValue(0xab); } -… + ``` @@ -3167,13 +3167,13 @@ bleCharacteristic.addDescriptor(bleDescriptor) **bleDescriptor**: descriptor to add to the characteristic -Returns +#### Returns Nothing #### Example -```Arduino -… +```arduino + // BLE Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes @@ -3182,10 +3182,10 @@ BLEDescriptor batteryLevelDescriptor("2901", "millis"); -// … + batteryLevelChar.addDescriptor(batteryLevelDescriptor); -… + ``` @@ -3204,20 +3204,20 @@ bleCharacteristic.descriptorCount() None -Returns +#### Returns The **number of BLE descriptors** discovered for the characteristic #### Example -```Arduino -… +```arduino + // loop the descriptors of the characteristic and explore each for (int i = 0; i < characteristic.descriptorCount(); i++) { BLEDescriptor descriptor = characteristic.descriptor(i); // ... } -… + ``` @@ -3238,17 +3238,17 @@ bleCharacteristic.hasDescriptor(uuid, index) **index**: index of descriptor **uuid**: uuid (as a **String**) -Returns +#### Returns **true**, if the characteristic has a matching descriptor, otherwise **false**. #### Example -```Arduino -… +```arduino + if (characteristic.hasDescriptor("2901")) { Serial.println("characteristic has description descriptor"); } -… + ``` @@ -3270,17 +3270,17 @@ bleCharacteristic.descriptor(uuid, index) **index**: index of descriptor **uuid**: uuid (as a **String**) -Returns +#### Returns BLEDescriptor that represents a characteristics BLE descriptor #### Example -```Arduino -… +```arduino + if (characteristic.hasDescriptor("2901")) { Serial.println("characteristic has description descriptor"); } -… + ``` @@ -3299,17 +3299,17 @@ bleCharacteristic.canRead() None -Returns +#### Returns **true**, if characteristic is readable, **false** otherwise #### Example -```Arduino -… +```arduino + if (characteristic.canRead("2901")) { Serial.println("characteristic is readable"); } -… + ``` @@ -3328,13 +3328,13 @@ bleCharacteristic.read() None -Returns +#### Returns **true**, if successful, **false** on failure #### Example -```Arduino -… +```arduino + if (characteristic.read()) { Serial.println("characteristic value read"); @@ -3342,7 +3342,7 @@ Returns } else { Serial.println("error reading characteristic value"); } -… + ``` @@ -3361,17 +3361,17 @@ bleCharacteristic.canWrite() None -Returns +#### Returns **true**, if characteristic is writable, **false** otherwise #### Example -```Arduino -… +```arduino + if (characteristic.canWrite()) { Serial.println("characteristic is writable"); } -… + ``` @@ -3390,17 +3390,17 @@ bleCharacteristic.canSubscribe() None -Returns +#### Returns **true**, if characteristic is subscribable, **false** otherwise #### Example -```Arduino -… +```arduino + if (characteristic.canSubscribe()) { Serial.println("characteristic is subscribable"); } -… + ``` @@ -3419,13 +3419,13 @@ bleCharacteristic.subscribe() None -Returns +#### Returns **true**, on success, **false** on failure #### Example -```Arduino -… +```arduino + // ... // retrieve the simple key characteristic @@ -3448,7 +3448,7 @@ Returns } // ... -… + ``` @@ -3467,17 +3467,17 @@ bleCharacteristic.canUnsubscribe() None -Returns +#### Returns **true**, if characteristic is unsubscribable, **false** otherwise #### Example -```Arduino -… +```arduino + if (characteristic.canUnsubscribe()) { Serial.println("characteristic is unsubscribable"); } -… + ``` @@ -3496,13 +3496,13 @@ bleCharacteristic.unsubscribe() None -Returns +#### Returns **true**, on success, **false** on failure #### Example -```Arduino -… +```arduino + // ... // retrieve the simple key characteristic @@ -3527,7 +3527,7 @@ Returns // ... simpleKeyCharacteristic.unsubscribe(); -… + ``` @@ -3546,13 +3546,13 @@ bleCharacteristic.valueUpdated() None -Returns +#### Returns **true**, if the characteristics value been updated via a notification or indication #### Example -```Arduino -… +```arduino + while (peripheral.connected()) { // while the peripheral is connected @@ -3574,7 +3574,7 @@ Returns } } } -… + ``` @@ -3601,15 +3601,15 @@ BLEDescriptor(uuid, stringValue) **valueSize**: size of byte array value **stringValue**: value as a string -Returns +#### Returns New **BLEDescriptor** with the specified **UUID** and value #### Example -```Arduino -… +```arduino + BLEDescriptor millisLabelDescriptor("2901", "millis"); -… + ``` @@ -3628,20 +3628,20 @@ bleDescriptor.uuid() None -Returns +#### Returns **UUID** of the BLE descriptor (as a String). #### Example -```Arduino -… +```arduino + BLEDescriptor millisLabelDescriptor("2901", "millis"); -// … + Serial.print(“millis label descriptor UUID = “); Serial.println(millisLabelDescriptor.uuid()); -… + ``` @@ -3660,20 +3660,20 @@ bleDescriptor.valueSize() None -Returns +#### Returns **Value size** (in bytes) of the BLE descriptor. #### Example -```Arduino -… +```arduino + BLEDescriptor millisLabelDescriptor("2901", "millis"); -// … + Serial.print(“millis label descriptor value size = “); Serial.println(millisLabelDescriptor.valueSize()); -… + ``` @@ -3692,13 +3692,13 @@ bleDescriptor.valueLength() None -Returns +#### Returns **Length of descriptor** value in bytes. #### Example -```Arduino -… +```arduino + // read the descriptor value descriptor.read(); @@ -3719,7 +3719,7 @@ Returns Serial.print(b, HEX); } } -… + ``` @@ -3738,16 +3738,16 @@ bleDescriptor.value() None -Returns +#### Returns Value byte array of the **BLE descriptor**. #### Example -```Arduino -… +```arduino + BLEDescriptor millisLabelDescriptor("2901", "millis"); -// … + int descriptorValueSize = millisLabelDescriptor.valueSize(); byte descriptorValue[descriptorValueSize]; @@ -3756,7 +3756,7 @@ BLEDescriptor millisLabelDescriptor("2901", "millis"); descriptorValue[i] = millisLabelDescriptor.value()[i]; } -… + ``` @@ -3778,19 +3778,19 @@ bleDescriptor.readValue(value) **length**: size of buffer argument in bytes **value**: variable to read value into (by reference) -Returns +#### Returns **Number of bytes** read #### Example -```Arduino -… +```arduino + byte value = 0; /get the value, descriptor is 1 byte so use byte value descriptor.readValue(value); -… + ``` @@ -3809,13 +3809,13 @@ bleDescriptor.read() None -Returns +#### Returns **true**, if successful, **false** on failure #### Example -```Arduino -… +```arduino + if (descriptor.read()) { Serial.println("descriptor value read"); @@ -3823,5 +3823,5 @@ Returns } else { Serial.println("error reading descriptor value"); } -… + ``` From 236aeda3009545d9efa540b9b992843449d9a5a6 Mon Sep 17 00:00:00 2001 From: Andrea Richetta Date: Mon, 30 Aug 2021 10:27:39 +0200 Subject: [PATCH 023/112] updated library properties and readme added mbed_nicla as compatible architecture to avoid warning during compilation. updated readme adding compatibility with Nicla Sense ME --- .gitignore | 2 ++ docs/readme.md | 2 +- library.properties | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9bea4330 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/docs/readme.md b/docs/readme.md index 86949a50..e9e36fc3 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,6 +1,6 @@ # ArduinoBLE library -This library supports all the Arduino boards that have the hardware enabled for BLE and Bluetooth 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010. +This library supports all the Arduino boards that have the hardware enabled for BLE and Bluetooth 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010, Nicla Sense ME. To use this library ``#include `` diff --git a/library.properties b/library.properties index b6d464cc..601474c6 100644 --- a/library.properties +++ b/library.properties @@ -2,9 +2,9 @@ name=ArduinoBLE version=1.2.1 author=Arduino maintainer=Arduino -sentence=Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. +sentence=Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla includes=ArduinoBLE.h From b15524683d8d0f66095e97f2ae1cbdaa08425918 Mon Sep 17 00:00:00 2001 From: Lukas Kvasnica Date: Wed, 8 Dec 2021 07:56:49 +0100 Subject: [PATCH 024/112] fix of bad indexing in ATTClass::handleNotifyOrInd which affected BLE in central mode --- src/utility/ATT.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index a1028f76..bca006c5 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1359,14 +1359,14 @@ void ATTClass::handleNotifyOrInd(uint16_t connectionHandle, uint8_t opcode, uint uint16_t handle; } *handleNotifyOrInd = (HandleNotifyOrInd*)data; - uint8_t handle = handleNotifyOrInd->handle; + uint16_t handle = handleNotifyOrInd->handle; - for (int i = 0; i < ATT_MAX_PEERS; i++) { - if (_peers[i].connectionHandle != connectionHandle) { + for (int peer = 0; peer < ATT_MAX_PEERS; peer++) { + if (_peers[peer].connectionHandle != connectionHandle) { continue; } - BLERemoteDevice* device = _peers[i].device; + BLERemoteDevice* device = _peers[peer].device; if (!device) { break; @@ -1384,7 +1384,7 @@ void ATTClass::handleNotifyOrInd(uint16_t connectionHandle, uint8_t opcode, uint BLERemoteCharacteristic* c = s->characteristic(j); if (c->valueHandle() == handle) { - c->writeValue(BLEDevice(_peers[i].addressType, _peers[i].address), &data[2], dlen - 2); + c->writeValue(BLEDevice(_peers[peer].addressType, _peers[peer].address), &data[2], dlen - 2); } } From c8de77559a95aca5a022e1bde7936a01223afd7b Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 14 Dec 2021 13:13:38 +0100 Subject: [PATCH 025/112] Replace boolean with standard bool (#42) https://github.com/arduino/Arduino/issues/4673 Signed-off-by: Frederic Pillon --- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- src/BLETypedCharacteristics.h | 2 +- src/utility/ATT.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index bd373731..659d466a 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -72,7 +72,7 @@ void loop() { char buttonValue = digitalRead(buttonPin); // has the value changed since the last read - boolean buttonChanged = (buttonCharacteristic.value() != buttonValue); + bool buttonChanged = (buttonCharacteristic.value() != buttonValue); if (buttonChanged) { // button state changed, update characteristics diff --git a/src/BLETypedCharacteristics.h b/src/BLETypedCharacteristics.h index 465fc046..8bd98c78 100644 --- a/src/BLETypedCharacteristics.h +++ b/src/BLETypedCharacteristics.h @@ -27,7 +27,7 @@ class BLEBoolCharacteristic : public BLETypedCharacteristic { BLEBoolCharacteristic(const char* uuid, unsigned char properties); }; -class BLEBooleanCharacteristic : public BLETypedCharacteristic { +class BLEBooleanCharacteristic : public BLETypedCharacteristic { public: BLEBooleanCharacteristic(const char* uuid, unsigned char properties); }; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index bca006c5..5e298081 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1143,7 +1143,7 @@ void ATTClass::readByTypeResp(uint16_t connectionHandle, uint8_t dlen, uint8_t d void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op, uint8_t dlen, uint8_t data[]) { - boolean withResponse = (op == ATT_OP_WRITE_REQ); + bool withResponse = (op == ATT_OP_WRITE_REQ); if (dlen < sizeof(uint16_t)) { if (withResponse) { From 14596d4154f5394214bb984fa17953401467bcf6 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 14 Dec 2021 13:15:24 +0100 Subject: [PATCH 026/112] Adding sync-labels workflow for sharing one set of labels across all repos. (#212) --- .github/workflows/sync-labels.yml | 138 ++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 .github/workflows/sync-labels.yml diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 00000000..fe53570f --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,138 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v1.0.3 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v1.0.3 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v2 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download configuration files artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v1 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} From af4d848a7fbab355f3be1e12f5e45462f0b889ce Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 20 Dec 2021 04:57:32 -0800 Subject: [PATCH 027/112] Use major version ref of `carlosperate/download-file-action` (#215) The `carlosperate/download-file-action` action is used in the GitHub Actions workflows as a convenient way to download external resources. A major version ref has been added to that repository. It will always point to the latest release of the "1" major version series. This means it is no longer necessary to do a full pin of the action version in use as before. Use of the major version ref will cause the workflow to use a stable version of the action, while also benefiting from ongoing development to the action up until such time as a new major release of an action is made. At that time we would need to evaluate whether any changes to the workflow are required by the breaking change that triggered the major release before manually updating the major ref (e.g., uses: `carlosperate/download-file-action@v2`). I think this approach strikes the right balance between stability and maintainability for these workflows. --- .github/workflows/sync-labels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index fe53570f..3ee6febd 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -31,7 +31,7 @@ jobs: - name: Download JSON schema for labels configuration file id: download-schema - uses: carlosperate/download-file-action@v1.0.3 + uses: carlosperate/download-file-action@v1 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json location: ${{ runner.temp }}/label-configuration-schema @@ -65,7 +65,7 @@ jobs: steps: - name: Download - uses: carlosperate/download-file-action@v1.0.3 + uses: carlosperate/download-file-action@v1 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} From 95b24499a0946994ee5fe2eab6eec15c87c6fc76 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 20 Dec 2021 04:59:05 -0800 Subject: [PATCH 028/112] Configure Dependabot to check for outdated actions used in workflows (#216) Dependabot will periodically check the versions of all actions used in the repository's workflows. If any are found to be outdated, it will submit a pull request to update them. NOTE: Dependabot's PRs will occasionally propose to pin to the patch version of the action (e.g., updating `uses: foo/bar@v1` to `uses: foo/bar@v2.3.4`). When the action author has provided a major version ref, use that instead (e.g., `uses: foo/bar@v2`). Dependabot will automatically close its PR once the workflow has been updated. More information: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot --- .github/dependabot.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..f2bfa724 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +# See: https://docs.github.com/en/code-security/supply-chain-security/configuration-options-for-dependency-updates#about-the-dependabotyml-file +version: 2 + +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md + # See: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: github-actions + directory: / # Check the repository's workflows under /.github/workflows/ + schedule: + interval: daily + labels: + - "topic: infrastructure" From 8d4d1dcca552f33871181fa18f6558b016ab16a2 Mon Sep 17 00:00:00 2001 From: BBear <13687227078@163.com> Date: Wed, 22 Dec 2021 13:52:58 +0800 Subject: [PATCH 029/112] fix potential arrary overflow problem of _recvBuffer (#214) * fix potential arrary overflow problem of _recvBuffer * Update src/utility/HCI.cpp make the code eaiser to read Co-authored-by: Alexander Entinger * optimize code of potential overflow _recvBuffer * add the debug msg when the _recvBuffer overflow Co-authored-by: Alexander Entinger --- src/utility/HCI.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 233dd1a5..f158d035 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -112,6 +112,13 @@ void HCIClass::poll(unsigned long timeout) while (HCITransport.available()) { byte b = HCITransport.read(); + + if (_recvIndex >= sizeof(_recvBuffer)) { + _recvIndex = 0; + if (_debug) { + _debug->println("_recvBuffer overflow"); + } + } _recvBuffer[_recvIndex++] = b; From ed61a17cbbffafb3dc77cfd0d70ad7da46c5c9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:27:14 +0100 Subject: [PATCH 030/112] Bluetooth trademark fix --- README.md | 4 +- docs/api.md | 279 +++++++++--------- docs/readme.md | 24 +- examples/Central/LedControl/LedControl.ino | 8 +- .../PeripheralExplorer/PeripheralExplorer.ino | 6 +- examples/Central/Scan/Scan.ino | 6 +- .../Central/ScanCallback/ScanCallback.ino | 6 +- .../SensorTagButton/SensorTagButton.ino | 6 +- .../BatteryMonitor/BatteryMonitor.ino | 20 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 10 +- .../Peripheral/CallbackLED/CallbackLED.ino | 10 +- examples/Peripheral/LED/LED.ino | 12 +- library.properties | 4 +- 13 files changed, 198 insertions(+), 197 deletions(-) diff --git a/README.md b/README.md index b2f649ca..9ec934a3 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) -Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. +Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. -This library supports creating a BLE peripheral and BLE central mode. +This library supports creating a Bluetooth® Low Energy peripheral & central mode. For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. diff --git a/docs/api.md b/docs/api.md index dab294ab..df285806 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2,11 +2,11 @@ ## BLE class -Used to enable the BLE module. +Used to enable the Bluetooth® Low Energy module. ### `begin()` -Initializes the BLE device. +Initializes the Bluetooth® Low Energy device. #### Syntax @@ -28,7 +28,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -38,7 +38,7 @@ None ### `end()` -Stops the BLE device. +Stops the Bluetooth® Low Energy device. #### Syntax @@ -60,7 +60,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -74,12 +74,13 @@ Nothing ### `poll()` -Poll for BLE radio events and handle them. +Poll for Bluetooth® Low Energy radio events and handle them. #### Syntax ``` -BLE.poll() BLE.poll(timeout) +BLE.poll() +BLE.poll(timeout) ``` @@ -129,7 +130,7 @@ Nothing. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -160,7 +161,7 @@ void blePeripheralDisconnectHandler(BLEDevice central) { ### `connected()` -Query if another BLE device is connected +Query if another Bluetooth® Low Energy device is connected #### Syntax @@ -174,7 +175,7 @@ BLE.connected() None #### Returns -**true** if another BLE device is connected, otherwise **false**. +**true** if another Bluetooth® Low Energy device is connected, otherwise **false**. #### Example @@ -191,7 +192,7 @@ None ### `disconnect()` -Disconnect any BLE devices that are connected +Disconnect any Bluetooth® Low Energy devices that are connected #### Syntax @@ -205,7 +206,7 @@ BLE.disconnect() None #### Returns -**true** if any BLE device that was previously connected was disconnected, otherwise **false**. +**true** if any Bluetooth® Low Energy device that was previously connected was disconnected, otherwise **false**. #### Example @@ -222,7 +223,7 @@ None ### `address()` -Query the Bluetooth address of the BLE device. +Query the Bluetooth® address of the Bluetooth® Low Energy device. #### Syntax @@ -236,7 +237,7 @@ BLE.address() None #### Returns -The **Bluetooth address** of the BLE device (as a String). +The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). #### Example @@ -252,7 +253,7 @@ The **Bluetooth address** of the BLE device (as a String). ### `rssi()` -Query the RSSI (Received signal strength indication) of the connected BLE device. +Query the RSSI (Received signal strength indication) of the connected Bluetooth® Low Energy device. #### Syntax @@ -266,7 +267,7 @@ BLE.rssi() None #### Returns -The **RSSI** of the connected BLE device, 127 if no BLE device is connected. +The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. #### Example @@ -295,7 +296,7 @@ BLE.setAdvertisedServiceUuid(uuid) #### Parameters -**uuid:** 16-bit or 128-bit BLE UUID in **String** format +**uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format #### Returns Nothing @@ -306,7 +307,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -343,13 +344,13 @@ Nothing ```arduino -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service // ... // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -389,7 +390,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -431,7 +432,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -471,7 +472,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -511,7 +512,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -529,7 +530,7 @@ Nothing ### `addService()` -Add a BLEService to the set of services the BLE device provides +Add a BLEService to the set of services the Bluetooth® Low Energy device provides #### Syntax @@ -549,13 +550,13 @@ Nothing ```arduino -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -593,7 +594,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -631,7 +632,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -649,7 +650,7 @@ Nothing ### `central()` -Query the central BLE device connected. +Query the central Bluetooth® Low Energy device connected. #### Syntax @@ -669,7 +670,7 @@ None ```arduino - // listen for BLE peripherals to connect: + // listen for Bluetooth® Low Energy peripherals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: @@ -708,7 +709,7 @@ Nothing. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -747,7 +748,7 @@ Nothing. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -785,7 +786,7 @@ Nothing. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -800,7 +801,7 @@ Nothing. ### `scan()` -Start scanning for BLE devices that are advertising. +Start scanning for Bluetooth® Low Energy devices that are advertising. #### Syntax @@ -823,7 +824,7 @@ BLE.scan(withDuplicates) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -846,7 +847,7 @@ BLE.scan(withDuplicates) ### `scanForName()` -Start scanning for BLE devices that are advertising with a particular (local) name. +Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (local) name. #### Syntax @@ -870,7 +871,7 @@ BLE.scanForName(name, withDuplicates) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -893,7 +894,7 @@ BLE.scanForName(name, withDuplicates) ### `scanForAddress()` -Start scanning for BLE devices that are advertising with a particular (Bluetooth) address. +Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (Bluetooth®) address. #### Syntax @@ -905,7 +906,7 @@ BLE.scanForAddress(address, withDuplicates) #### Parameters -**address:** (Bluetooth) address (as a String) to filter for +**address:** (Bluetooth®) address (as a String) to filter for **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered #### Returns @@ -917,7 +918,7 @@ BLE.scanForAddress(address, withDuplicates) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -940,7 +941,7 @@ BLE.scanForAddress(address, withDuplicates) ### `scanForUuid()` -Start scanning for BLE devices that are advertising with a particular (service) UUID. +Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (service) UUID. #### Syntax @@ -964,7 +965,7 @@ BLE.scanForUuid(uuid, withDuplicates) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -987,7 +988,7 @@ BLE.scanForUuid(uuid, withDuplicates) ### `stopScan()` -Stop scanning for BLE devices that are advertising. +Stop scanning for Bluetooth® Low Energy devices that are advertising. #### Syntax @@ -1009,7 +1010,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1027,7 +1028,7 @@ Nothing ### `available()` -Query for a discovered BLE device that was found during scanning. +Query for a discovered Bluetooth® Low Energy device that was found during scanning. #### Syntax @@ -1049,7 +1050,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1076,7 +1077,7 @@ Used to get information about the devices connected or discovered while scanning ### `poll()` -Poll for BLE radio events for the specified BLE device and handle them. +Poll for Bluetooth® Low Energy radio events for the specified Bluetooth® Low Energy device and handle them. #### Syntax @@ -1097,7 +1098,7 @@ Nothing ```arduino - // listen for BLE centrals to connect: + // listen for Bluetooth® Low Energy centrals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: @@ -1114,7 +1115,7 @@ Nothing ### `connected()` -Query if a BLE device is connected +Query if a Bluetooth® Low Energy device is connected #### Syntax @@ -1128,13 +1129,13 @@ bleDevice.connected() None #### Returns -**true** if the BLE device is connected, otherwise **false**. +**true** if the Bluetooth® Low Energy device is connected, otherwise **false**. #### Example ```arduino - // listen for BLE centrals to connect: + // listen for Bluetooth® Low Energy centrals to connect: BLEDevice central = BLE.central(); // while the central is still connected @@ -1148,7 +1149,7 @@ None ### `disconnect()` -Disconnect the BLE device, if connected +Disconnect the Bluetooth® Low Energy device, if connected #### Syntax @@ -1162,13 +1163,13 @@ bleDevice.disconnect() None #### Returns -**true** if the BLE device was disconnected, otherwise **false**. +**true** if the Bluetooth® Low Energy device was disconnected, otherwise **false**. #### Example ```arduino - // listen for BLE centrals to connect: + // listen for Bluetooth® Low Energy centrals to connect: BLEDevice central = BLE.central(); @@ -1180,7 +1181,7 @@ None ### `address()` -Query the Bluetooth address of the BLE device. +Query the Bluetooth® address of the Bluetooth® Low Energy device. #### Syntax @@ -1194,13 +1195,13 @@ bleDevice.address() None #### Returns -The **Bluetooth address** of the BLE device (as a String). +The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). #### Example ```arduino - // listen for BLE peripherals to connect: + // listen for Bluetooth® Low Energy peripherals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: @@ -1217,7 +1218,7 @@ The **Bluetooth address** of the BLE device (as a String). ### `rssi()` -Query the RSSI (Received signal strength indication) of the BLE device. +Query the RSSI (Received signal strength indication) of the Bluetooth® Low Energy device. #### Syntax @@ -1231,7 +1232,7 @@ bleDevice.rssi() None #### Returns -The **RSSI** of the connected BLE device, 127 if the BLE device is not connected. +The **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. #### Example @@ -1249,7 +1250,7 @@ The **RSSI** of the connected BLE device, 127 if the BLE device is not connected ### `characteristic()` -Get a BLECharacteristic representing a BLE characteristic the device provides. +Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the device provides. #### Syntax @@ -1274,7 +1275,7 @@ bleDevice.characteristic(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1326,7 +1327,7 @@ bleDevice.characteristic(uuid, index) ### `discoverAttributes()` -Discover all of the attributes of BLE device. +Discover all of the attributes of Bluetooth® Low Energy device. #### Syntax @@ -1348,7 +1349,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1392,7 +1393,7 @@ None ### `discoverService()` -Discover the attributes of a particular service on the BLE device. +Discover the attributes of a particular service on the Bluetooth® Low Energy device. #### Syntax @@ -1414,7 +1415,7 @@ bleDevice.discoverService(serviceUuid) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1458,7 +1459,7 @@ bleDevice.discoverService(serviceUuid) ### `deviceName()` -Query the device name (BLE characteristic UUID 0x2a00) of a BLE device. +Query the device name (BLE characteristic UUID 0x2a00) of a Bluetooth® Low Energy device. #### Syntax @@ -1480,7 +1481,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1532,7 +1533,7 @@ None ### `appearance()` -Query the appearance (BLE characteristic UUID 0x2a01) of a BLE device. +Query the appearance (BLE characteristic UUID 0x2a01) of a Bluetooth® Low Energy device. #### Syntax @@ -1554,7 +1555,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1606,7 +1607,7 @@ None ### `serviceCount()` -Query the number of services discovered for the BLE device. +Query the number of services discovered for the Bluetooth® Low Energy device. #### Syntax @@ -1620,7 +1621,7 @@ bleDevice.serviceCount() None #### Returns -The number of **services discovered** for the BLE device. +The number of **services discovered** for the Bluetooth® Low Energy device. #### Example @@ -1628,7 +1629,7 @@ The number of **services discovered** for the BLE device. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1677,7 +1678,7 @@ The number of **services discovered** for the BLE device. ### `hasService()` -Query if the BLE device has a particular service. +Query if the Bluetooth® Low Energy device has a particular service. #### Syntax @@ -1701,7 +1702,7 @@ bleDevice.hasService(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1749,7 +1750,7 @@ bleDevice.hasService(uuid, index) ### `service()` -Get a BLEService representing a BLE service the device provides. +Get a BLEService representing a Bluetooth® Low Energy service the device provides. #### Syntax @@ -1774,7 +1775,7 @@ bleDevice.service(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1826,7 +1827,7 @@ bleDevice.service(uuid, index) ### `characteristicCount()` -Query the number of characteristics discovered for the BLE device. +Query the number of characteristics discovered for the Bluetooth® Low Energy device. #### Syntax @@ -1840,7 +1841,7 @@ bleDevice.characteristicCount() None #### Returns -The **number of characteristics** discovered for the BLE device. +The **number of characteristics** discovered for the Bluetooth® Low Energy device. #### Example @@ -1848,7 +1849,7 @@ The **number of characteristics** discovered for the BLE device. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1897,7 +1898,7 @@ The **number of characteristics** discovered for the BLE device. ### `hasCharacteristic()` -Query if the BLE device has a particular characteristic. +Query if the Bluetooth® Low Energy device has a particular characteristic. #### Syntax @@ -1921,7 +1922,7 @@ bleDevice.hasCharacteristic(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -1969,7 +1970,7 @@ bleDevice.hasCharacteristic(uuid, index) ### `hasLocalName()` -Query if a discovered BLE device is advertising a local name. +Query if a discovered Bluetooth® Low Energy device is advertising a local name. #### Syntax @@ -1991,7 +1992,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2022,7 +2023,7 @@ Nothing ### `hasAdvertisedServiceUuid()` -Query if a discovered BLE device is advertising a service UUID. +Query if a discovered Bluetooth® Low Energy device is advertising a service UUID. #### Syntax @@ -2045,7 +2046,7 @@ bleDevice.hasAdvertisedServiceUuid(index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2080,7 +2081,7 @@ bleDevice.hasAdvertisedServiceUuid(index) ### `advertisedServiceUuidCount()` -Query the number of advertised services a discovered BLE device is advertising. +Query the number of advertised services a discovered Bluetooth® Low Energy device is advertising. #### Syntax @@ -2094,7 +2095,7 @@ bleDevice.advertisedServiceUuidCount() None #### Returns -The **number of advertised services** a discovered BLE device is advertising. +The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. #### Example @@ -2102,7 +2103,7 @@ The **number of advertised services** a discovered BLE device is advertising. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2137,7 +2138,7 @@ The **number of advertised services** a discovered BLE device is advertising. ### `localName()` -Query the local name a discovered BLE device is advertising with. +Query the local name a discovered Bluetooth® Low Energy device is advertising with. #### Syntax @@ -2159,7 +2160,7 @@ Nothing // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2190,7 +2191,7 @@ Nothing ### `advertisedServiceUuid()` -Query an advertised service UUID discovered BLE device is advertising. +Query an advertised service UUID discovered Bluetooth® Low Energy device is advertising. #### Syntax @@ -2213,7 +2214,7 @@ Advertised service **UUID** (as a String). // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2248,7 +2249,7 @@ Advertised service **UUID** (as a String). ### `connect()` -Connect to a BLE device. +Connect to a Bluetooth® Low Energy device. #### Syntax @@ -2270,7 +2271,7 @@ None // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2308,7 +2309,7 @@ Used to enable the services board provides or interact with services a remote bo ### `BLEService()` -Create a new BLE service. +Create a new Bluetooth® Low Energy service. #### Syntax @@ -2328,7 +2329,7 @@ New **BLEService** with the specified **UUID** ```arduino -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service ``` @@ -2349,13 +2350,13 @@ bleService.uuid() None #### Returns -UUID of the BLE service as a **String**. +UUID of the Bluetooth® Low Energy service as a **String**. #### Example ```arduino -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service Serial.print(“LED service UUID = “); @@ -2367,7 +2368,7 @@ Serial.println(ledService.uuid()); ### `addCharacteristic()` -Add a BLECharateristic to the BLE service. +Add a BLECharateristic to the Bluetooth® Low Energy service. #### Syntax @@ -2387,9 +2388,9 @@ Nothing ```arduino -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service -// BLE LED Switch Characteristic - custom 128-bit UUID, readable and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, readable and writable by central BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); @@ -2404,7 +2405,7 @@ ledService.addCharacteristic(switchCharacteristic); ### `characteristicCount()` -Query the number of characteristics discovered for the BLE service. +Query the number of characteristics discovered for the Bluetooth® Low Energy service. #### Syntax @@ -2418,7 +2419,7 @@ bleService.characteristicCount() None #### Returns -The **number of characteristics** discovered for the BLE service. +The **number of characteristics** discovered for the Bluetooth® Low Energy service. #### Example @@ -2426,7 +2427,7 @@ The **number of characteristics** discovered for the BLE service. // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2482,7 +2483,7 @@ The **number of characteristics** discovered for the BLE service. ### `hasCharacteristic()` -Query if the BLE service has a particular characteristic. +Query if the Bluetooth® Low Energy service has a particular characteristic. #### Syntax @@ -2506,7 +2507,7 @@ bleService.hasCharacteristic(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2560,7 +2561,7 @@ bleService.hasCharacteristic(uuid, index) ### `characteristic()` -Get a BLECharacteristic representing a BLE characteristic the service provides. +Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the service provides. #### Syntax @@ -2585,7 +2586,7 @@ bleService.characteristic(uuid, index) // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -2648,7 +2649,7 @@ Used to enable the characteristics board offers in a service or interact with ch ### `BLECharacteristic()` -Create a new BLE characteristic. +Create a new Bluetooth® Low Energy characteristic. #### Syntax @@ -2686,7 +2687,7 @@ New **BLECharacteristic** with the specified **UUID** and value ```arduino -// BLE Battery Level Characteristic +// Bluetooth® Low Energy Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes @@ -2710,13 +2711,13 @@ bleCharacteristic.uuid() None #### Returns -**UUID** of the BLE service as a **String**. +**UUID** of the Bluetooth® Low Energy service as a **String**. #### Example ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); @@ -2749,7 +2750,7 @@ None ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); @@ -2788,7 +2789,7 @@ The **maximum value** size of the characteristic (in bytes) ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); @@ -2821,7 +2822,7 @@ The **current value** of the characteristic, value type depends on the construct ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); @@ -2860,7 +2861,7 @@ The **current value** size of the characteristic (in bytes) ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); @@ -3054,7 +3055,7 @@ buttonCharacteristic.broadcast(); ### `written()` -Query if the characteristic value has been written by another BLE device. +Query if the characteristic value has been written by another Bluetooth® Low Energy device. #### Syntax @@ -3068,19 +3069,19 @@ bleCharacteristic.written() None #### Returns -**true** if the characteristic value has been written by another BLE device, **false** otherwise +**true** if the characteristic value has been written by another Bluetooth® Low Energy device, **false** otherwise #### Example ```arduino -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - // listen for BLE peripherals to connect: + // listen for Bluetooth® Low Energy peripherals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: @@ -3116,7 +3117,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 ### `subscribed()` -Query if the characteristic has been subscribed to by another BLE device. +Query if the characteristic has been subscribed to by another Bluetooth® Low Energy device. #### Syntax @@ -3130,13 +3131,13 @@ bleCharacteristic.subscribed() None #### Returns -**true** if the characteristic value has been subscribed to by another BLE device, **false** otherwise +**true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, **false** otherwise #### Example ```arduino -// BLE Battery Level Characteristic +// Bluetooth® Low Energy Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes @@ -3145,7 +3146,7 @@ BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit chara if (batteryLevelChar.subscribed()) { - // set a new value , that well be pushed to subscribed BLE devices + // set a new value , that well be pushed to subscribed Bluetooth® Low Energy devices batteryLevelChar.writeValue(0xab); } @@ -3174,7 +3175,7 @@ Nothing ```arduino -// BLE Battery Level Characteristic +// Bluetooth® Low Energy Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes @@ -3191,7 +3192,7 @@ BLEDescriptor batteryLevelDescriptor("2901", "millis"); ### `descriptorCount` -Query the number of BLE descriptors discovered for the characteristic. +Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. #### Syntax @@ -3205,7 +3206,7 @@ bleCharacteristic.descriptorCount() None #### Returns -The **number of BLE descriptors** discovered for the characteristic +The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic #### Example @@ -3254,7 +3255,7 @@ bleCharacteristic.hasDescriptor(uuid, index) ### `descriptor()` -Get a BLEDescriptor that represents a characteristics BLE descriptor. +Get a BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor. #### Syntax @@ -3271,7 +3272,7 @@ bleCharacteristic.descriptor(uuid, index) **uuid**: uuid (as a **String**) #### Returns -BLEDescriptor that represents a characteristics BLE descriptor +BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor #### Example @@ -3286,7 +3287,7 @@ BLEDescriptor that represents a characteristics BLE descriptor ### `canRead()` -Query if a BLE characteristic is readable. +Query if a Bluetooth® Low Energy characteristic is readable. #### Syntax @@ -3348,7 +3349,7 @@ None ### `canWrite()` -Query if a BLE characteristic is writable. +Query if a Bluetooth® Low Energy characteristic is writable. #### Syntax @@ -3377,7 +3378,7 @@ None ### `canSubscribe()` -Query if a BLE characteristic is subscribable. +Query if a Bluetooth® Low Energy characteristic is subscribable. #### Syntax @@ -3406,7 +3407,7 @@ None ### `subscribe()` -Subscribe to a BLE characteristics notification or indications. +Subscribe to a Bluetooth® Low Energy characteristics notification or indications. #### Syntax @@ -3454,7 +3455,7 @@ None ### `canUnsubscribe()` -Query if a BLE characteristic is unsubscribable. +Query if a Bluetooth® Low Energy characteristic is unsubscribable. #### Syntax @@ -3483,7 +3484,7 @@ None ### `unsubscribe()` -Unsubscribe to a BLE characteristics notifications or indications. +Unsubscribe to a Bluetooth® Low Energy characteristics notifications or indications. #### Syntax @@ -3584,7 +3585,7 @@ Used to describe a characteristic the board offers ### `BLEDescriptor()` -Create a new BLE descriptor. +Create a new Bluetooth® Low Energy descriptor. #### Syntax @@ -3629,7 +3630,7 @@ bleDescriptor.uuid() None #### Returns -**UUID** of the BLE descriptor (as a String). +**UUID** of the Bluetooth® Low Energy descriptor (as a String). #### Example @@ -3661,7 +3662,7 @@ bleDescriptor.valueSize() None #### Returns -**Value size** (in bytes) of the BLE descriptor. +**Value size** (in bytes) of the Bluetooth® Low Energy descriptor. #### Example diff --git a/docs/readme.md b/docs/readme.md index e9e36fc3..bfd1496b 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,27 +1,27 @@ # ArduinoBLE library -This library supports all the Arduino boards that have the hardware enabled for BLE and Bluetooth 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010, Nicla Sense ME. +This library supports all the Arduino boards that have the hardware enabled for Bluetooth® Low Energy and Bluetooth® 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010, Nicla Sense ME. To use this library ``#include `` ## A quick introduction to BLE -Bluetooth 4.0 includes both traditional Bluetooth, now labeled "Bluetooth Classic", and the Bluetooth Low Energy (Bluetooth LE, or BLE). BLE is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. +Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Classic", and the Bluetooth® Low Energy. Bluetooth® Low Energy is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. -Unlike standard bluetooth communication basically based on an asynchronous serial connection (UART) a Bluetooth LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth LE world because they read information available from the peripherals. +Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. ![Communication between central and peripheral devices](www.arduino.cc/en/uploads/Reference/ble-bulletin-board-model.png) -Think of a Bluetooth LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. +Think of a Bluetooth® LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. The information presented by a peripheral is structured as **services**, each of which is subdivided into **characteristics**. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices. If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not. If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it. ## Notify -The Bluetooth LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgement of the pushed data. +The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgement of the pushed data. -The client-server structure of Bluetooth LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. +The client-server structure of Bluetooth® LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. ## Update a characteristic @@ -35,7 +35,7 @@ Just as with writing to a characteristic, you could update your characteristics ## Services, characteristics, and UUIDs -A BLE peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use [standard services](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx). +A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use [standard services](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx). Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. @@ -84,8 +84,8 @@ The Bluetooth LE protocol operates on multiple layers. **General Attribute Profi As the library enables multiple types of functionality, there are a number of different classes. -- BLE used to enable the BLE module. -- BLEDevice used to get information about the devices connected or discovered while scanning. -- BLEService used to enable the services board provides or interact with services a remote board provides. -- BLECharacteristic used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. -- BLEDescriptor used to describe a characteristic the board offers. +- `BLE` used to enable the Bluetooth® Low Energy module. +- `BLEDevice` used to get information about the devices connected or discovered while scanning. +- `BLEService` used to enable the services board provides or interact with services a remote board provides. +- `BLECharacteristic` used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. +- `BLEDescriptor` used to describe a characteristic the board offers. diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 8301a311..953de7d8 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -1,9 +1,9 @@ /* LED Control - This example scans for BLE peripherals until one with the advertised service + This example scans for Bluetooth® Low Energy peripherals until one with the advertised service "19b10000-e8f2-537e-4f6c-d104768a1214" UUID is found. Once discovered and connected, - it will remotely control the BLE Peripheral's LED, when the button is pressed or released. + it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. The circuit: - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, @@ -29,10 +29,10 @@ void setup() { // configure the button pin as input pinMode(buttonPin, INPUT); - // initialize the BLE hardware + // initialize the Bluetooth® Low Energy hardware BLE.begin(); - Serial.println("BLE Central - LED control"); + Serial.println("Bluetooth® Low Energy Central - LED control"); // start scanning for peripherals BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 100225d6..919cdde0 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -1,7 +1,7 @@ /* Peripheral Explorer - This example scans for BLE peripherals until one with a particular name ("LED") + This example scans for Bluetooth® Low Energy peripherals until one with a particular name ("LED") is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: @@ -22,12 +22,12 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } - Serial.println("BLE Central - Peripheral Explorer"); + Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer"); // start scanning for peripherals BLE.scan(); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 3126d1a6..162e3c07 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -1,7 +1,7 @@ /* Scan - This example scans for BLE peripherals and prints out their advertising details: + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: address, local name, advertised service UUID's. The circuit: @@ -19,12 +19,12 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } - Serial.println("BLE Central scan"); + Serial.println("Bluetooth® Low Energy Central scan"); // start scanning for peripheral BLE.scan(); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 28ab9e9e..2687a3b9 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -1,7 +1,7 @@ /* Scan Callback - This example scans for BLE peripherals and prints out their advertising details: + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: 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. @@ -21,12 +21,12 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } - Serial.println("BLE Central scan callback"); + Serial.println("Bluetooth® Low Energy Central scan callback"); // set the discovered event handle BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 72dad90b..a56504f6 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -1,7 +1,7 @@ /* SensorTag Button - This example scans for BLE peripherals until a TI SensorTag is discovered. + This example scans for Bluetooth® Low Energy peripherals until a TI SensorTag is discovered. It then connects to it, discovers the attributes of the 0xffe0 service, subscribes to the Simple Key Characteristic (UUID 0xffe1). When a button is pressed on the SensorTag a notification is received and the button state is @@ -23,12 +23,12 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } - Serial.println("BLE Central - SensorTag button"); + Serial.println("Bluetooth® Low Energy Central - SensorTag button"); Serial.println("Make sure to turn on the device."); // start scanning for peripheral diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino index 6c5d3d30..f013c6f5 100644 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -1,14 +1,14 @@ /* Battery Monitor - This example creates a BLE peripheral with the standard battery service and + This example creates a Bluetooth® Low Energy peripheral with the standard battery service and level characteristic. The A0 pin is used to calculate the battery level. The circuit: - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - You can use a generic BLE central app, like LightBlue (iOS and Android) or + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics created in this sketch. @@ -17,10 +17,10 @@ #include - // BLE Battery Service + // Bluetooth® Low Energy Battery Service BLEService batteryService("180F"); -// BLE Battery Level Characteristic +// Bluetooth® Low Energy Battery Level Characteristic BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes @@ -40,9 +40,9 @@ void setup() { while (1); } - /* Set a local name for the BLE device + /* Set a local name for the Bluetooth® Low Energy device This name will appear in advertising packets - and can be used by remote devices to identify this BLE device + and can be used by remote devices to identify this Bluetooth® Low Energy device The name can be changed but maybe be truncated based on space left in advertisement packet */ BLE.setLocalName("BatteryMonitor"); @@ -51,18 +51,18 @@ void setup() { BLE.addService(batteryService); // Add the battery service batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic - /* Start advertising BLE. It will start continuously transmitting BLE - advertising packets and will be visible to remote BLE central devices + /* Start advertising Bluetooth® Low Energy. It will start continuously transmitting Bluetooth® Low Energy + advertising packets and will be visible to remote Bluetooth® Low Energy central devices until it receives a new connection */ // start advertising BLE.advertise(); - Serial.println("Bluetooth device active, waiting for connections..."); + Serial.println("Bluetooth® device active, waiting for connections..."); } void loop() { - // wait for a BLE central + // wait for a Bluetooth® Low Energy central BLEDevice central = BLE.central(); // if a central is connected to the peripheral: diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 659d466a..cbc14dd8 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -1,7 +1,7 @@ /* Button LED - This example creates a BLE peripheral with service that contains a + This example creates a Bluetooth® Low Energy peripheral with service that contains a characteristic to control an LED and another characteristic that represents the state of the button. @@ -10,7 +10,7 @@ Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - Button connected to pin 4 - You can use a generic BLE central app, like LightBlue (iOS and Android) or + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics created in this sketch. @@ -38,7 +38,7 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -61,11 +61,11 @@ void setup() { // start advertising BLE.advertise(); - Serial.println("Bluetooth device active, waiting for connections..."); + Serial.println("Bluetooth® device active, waiting for connections..."); } void loop() { - // poll for BLE events + // poll for Bluetooth® Low Energy events BLE.poll(); // read the current button pin state diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index a874a77b..23f67bc3 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -1,7 +1,7 @@ /* Callback LED - This example creates a BLE peripheral with service that contains a + This example creates a Bluetooth® Low Energy peripheral with service that contains a characteristic to control an LED. The callback features of the library are used. @@ -9,7 +9,7 @@ - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - You can use a generic BLE central app, like LightBlue (iOS and Android) or + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics created in this sketch. @@ -33,7 +33,7 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -61,11 +61,11 @@ void setup() { // start advertising BLE.advertise(); - Serial.println(("Bluetooth device active, waiting for connections...")); + Serial.println(("Bluetooth® device active, waiting for connections...")); } void loop() { - // poll for BLE events + // poll for Bluetooth® Low Energy events BLE.poll(); } diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 1ede6535..2e6d6db9 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -1,14 +1,14 @@ /* LED - This example creates a BLE peripheral with service that contains a + This example creates a Bluetooth® Low Energy peripheral with service that contains a characteristic to control an LED. The circuit: - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - You can use a generic BLE central app, like LightBlue (iOS and Android) or + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics created in this sketch. @@ -17,9 +17,9 @@ #include -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); const int ledPin = LED_BUILTIN; // pin to use for the LED @@ -33,7 +33,7 @@ void setup() { // begin initialization if (!BLE.begin()) { - Serial.println("starting BLE failed!"); + Serial.println("starting Bluetooth® Low Energy module failed!"); while (1); } @@ -58,7 +58,7 @@ void setup() { } void loop() { - // listen for BLE peripherals to connect: + // listen for Bluetooth® Low Energy peripherals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: diff --git a/library.properties b/library.properties index 601474c6..8d8a9d1c 100644 --- a/library.properties +++ b/library.properties @@ -2,8 +2,8 @@ name=ArduinoBLE version=1.2.1 author=Arduino maintainer=Arduino -sentence=Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. -paragraph=This library supports creating a BLE peripheral and BLE central mode. +sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. +paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla From 57ce5149d944932740401ab7952d3f745bc9652a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 09:03:48 +0000 Subject: [PATCH 031/112] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index a14882ff..a1faf997 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -17,7 +17,7 @@ jobs: - arduino:mbed_nano:nanorp2040connect steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 6c44bcfb..0cbdde58 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Spell check uses: arduino/actions/libraries/spell-check@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 3ee6febd..4ea57559 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download configuration files artifact uses: actions/download-artifact@v2 From c9bfd21ed1f927603460b3e00fc673009aad4330 Mon Sep 17 00:00:00 2001 From: "Ho Yun \"Bobby" Date: Fri, 18 Mar 2022 20:58:54 -0600 Subject: [PATCH 032/112] Update readme.md image from Arduino's assets folder not linking properly --- docs/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index bfd1496b..5a52d988 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -11,7 +11,7 @@ Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. -![Communication between central and peripheral devices](www.arduino.cc/en/uploads/Reference/ble-bulletin-board-model.png) +![Communication between central and peripheral devices](https://www.arduino.cc/en/uploads/Reference/ble-bulletin-board-model.png) Think of a Bluetooth® LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. From c925d8251ac31e715a19b63cbf279c7be2a576a1 Mon Sep 17 00:00:00 2001 From: giulcioffi Date: Thu, 24 Mar 2022 16:15:56 +0100 Subject: [PATCH 033/112] Add compatibility with Nicla Vision --- src/utility/HCICordioTransport.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 01788238..28eb97be 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -25,7 +25,7 @@ #include #include -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #include "ble/BLE.h" #include #endif @@ -181,7 +181,7 @@ HCICordioTransportClass::~HCICordioTransportClass() { } -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { eventQueue.call(mbed::Callback(&context->ble, &BLE::processEvents)); @@ -201,7 +201,7 @@ int HCICordioTransportClass::begin() init_wsf(bufPoolDesc); #endif -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) BLE &ble = BLE::Instance(); ble.onEventsToProcess(scheduleMbedBleEvents); From c12774c09cb96cf91911ee73613783b5602d3161 Mon Sep 17 00:00:00 2001 From: giulcioffi Date: Thu, 24 Mar 2022 16:18:49 +0100 Subject: [PATCH 034/112] Release 1.2.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 8d8a9d1c..e8859d8e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.2.1 +version=1.2.2 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From bfc3202668332c857c46c4502be5127cbe6da597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Hyl=C3=A9n?= <60390259+jacobhylen@users.noreply.github.com> Date: Thu, 31 Mar 2022 16:27:49 +0200 Subject: [PATCH 035/112] Update api.md --- docs/api.md | 162 ++++++++++++++++++++++++++-------------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/docs/api.md b/docs/api.md index df285806..b8fa1d5f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,7 +4,7 @@ Used to enable the Bluetooth® Low Energy module. -### `begin()` +### `BLE.begin()` Initializes the Bluetooth® Low Energy device. @@ -36,7 +36,7 @@ None ``` -### `end()` +### `BLE.end()` Stops the Bluetooth® Low Energy device. @@ -72,7 +72,7 @@ Nothing ``` -### `poll()` +### `BLE.poll()` Poll for Bluetooth® Low Energy radio events and handle them. @@ -106,7 +106,7 @@ Nothing ``` -### `setEventHandler()` +### `BLE.setEventHandler()` Set the event handler (callback) function that will be called when the specified event occurs. @@ -159,7 +159,7 @@ void blePeripheralDisconnectHandler(BLEDevice central) { ``` -### `connected()` +### `BLE.connected()` Query if another Bluetooth® Low Energy device is connected @@ -190,7 +190,7 @@ None ``` -### `disconnect()` +### `BLE.disconnect()` Disconnect any Bluetooth® Low Energy devices that are connected @@ -221,7 +221,7 @@ None ``` -### `address()` +### `BLE.address()` Query the Bluetooth® address of the Bluetooth® Low Energy device. @@ -251,7 +251,7 @@ The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). ``` -### `rssi()` +### `BLE.rssi()` Query the RSSI (Received signal strength indication) of the connected Bluetooth® Low Energy device. @@ -283,7 +283,7 @@ The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth ``` -### `setAdvertisedServiceUuid()` +### `BLE.setAdvertisedServiceUuid()` Set the advertised service UUID used when advertising. @@ -322,7 +322,7 @@ Nothing ``` -### `setAdvertisedService()` +### `BLE.setAdvertisedService()` Set the advertised service UUID used when advertising to the value of the BLEService provided. @@ -365,7 +365,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Lo ``` -### `setManufacturerData()` +### `BLE.setManufacturerData()` Set the manufacturer data value used when advertising. @@ -408,7 +408,7 @@ Nothing ``` -### `setLocalName()` +### `BLE.setLocalName()` Set the local value used when advertising. @@ -448,7 +448,7 @@ Nothing ``` -### `setDeviceName()` +### `BLE.setDeviceName()` Set the device name in the built in device name characteristic. If not set, the value defaults “Arduino”. @@ -488,7 +488,7 @@ Nothing ``` -### `setAppearance()` +### `BLE.setAppearance()` Set the appearance in the built in appearance characteristic. If not set, the value defaults 0x0000. @@ -528,7 +528,7 @@ Nothing ``` -### `addService()` +### `BLE.addService()` Add a BLEService to the set of services the Bluetooth® Low Energy device provides @@ -570,7 +570,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Lo ``` -### `advertise()` +### `BLE.advertise()` Start advertising. @@ -608,7 +608,7 @@ None ``` -### `stopAdvertise()` +### `BLE.stopAdvertise()` Stop advertising. @@ -648,7 +648,7 @@ Nothing ``` -### `central()` +### `BLE.central()` Query the central Bluetooth® Low Energy device connected. @@ -685,7 +685,7 @@ None ``` -### `setAdvertisingInterval()` +### `BLE.setAdvertisingInterval()` Set the advertising interval in units of 0.625 ms. Defaults to 100ms (160 * 0.625 ms) if not provided. @@ -723,7 +723,7 @@ Nothing. ``` -### `setConnectionInterval()` +### `BLE.setConnectionInterval()` Set the minimum and maximum desired connection intervals in units of 1.25 ms. @@ -761,7 +761,7 @@ Nothing. ``` -### `setConnectable()` +### `BLE.setConnectable()` Set if the device is connectable after advertising, defaults to **true**. @@ -799,7 +799,7 @@ Nothing. ``` -### `scan()` +### `BLE.scan()` Start scanning for Bluetooth® Low Energy devices that are advertising. @@ -845,7 +845,7 @@ BLE.scan(withDuplicates) ``` -### `scanForName()` +### `BLE.scanForName()` Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (local) name. @@ -892,7 +892,7 @@ BLE.scanForName(name, withDuplicates) ``` -### `scanForAddress()` +### `BLE.scanForAddress()` Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (Bluetooth®) address. @@ -939,7 +939,7 @@ BLE.scanForAddress(address, withDuplicates) ``` -### `scanForUuid()` +### `BLE.scanForUuid()` Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (service) UUID. @@ -986,7 +986,7 @@ BLE.scanForUuid(uuid, withDuplicates) ``` -### `stopScan()` +### `BLE.stopScan()` Stop scanning for Bluetooth® Low Energy devices that are advertising. @@ -1026,7 +1026,7 @@ Nothing ``` -### `available()` +### `BLE.available()` Query for a discovered Bluetooth® Low Energy device that was found during scanning. @@ -1075,7 +1075,7 @@ Nothing Used to get information about the devices connected or discovered while scanning -### `poll()` +### `bleDevice.poll()` Poll for Bluetooth® Low Energy radio events for the specified Bluetooth® Low Energy device and handle them. @@ -1113,7 +1113,7 @@ Nothing ``` -### `connected()` +### `bleDevice.connected()` Query if a Bluetooth® Low Energy device is connected @@ -1147,7 +1147,7 @@ None ``` -### `disconnect()` +### `bleDevice.disconnect()` Disconnect the Bluetooth® Low Energy device, if connected @@ -1179,7 +1179,7 @@ None ``` -### `address()` +### `bleDevice.address()` Query the Bluetooth® address of the Bluetooth® Low Energy device. @@ -1216,7 +1216,7 @@ The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). ``` -### `rssi()` +### `bleDevice.rssi()` Query the RSSI (Received signal strength indication) of the Bluetooth® Low Energy device. @@ -1248,7 +1248,7 @@ The **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetoot ``` -### `characteristic()` +### `bleDevice.characteristic()` Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the device provides. @@ -1325,7 +1325,7 @@ bleDevice.characteristic(uuid, index) ``` -### `discoverAttributes()` +### `bleDevice.discoverAttributes()` Discover all of the attributes of Bluetooth® Low Energy device. @@ -1391,7 +1391,7 @@ None ``` -### `discoverService()` +### `bleDevice.discoverService()` Discover the attributes of a particular service on the Bluetooth® Low Energy device. @@ -1457,7 +1457,7 @@ bleDevice.discoverService(serviceUuid) ``` -### `deviceName()` +### `bleDevice.deviceName()` Query the device name (BLE characteristic UUID 0x2a00) of a Bluetooth® Low Energy device. @@ -1531,7 +1531,7 @@ None ``` -### `appearance()` +### `bleDevice.appearance()` Query the appearance (BLE characteristic UUID 0x2a01) of a Bluetooth® Low Energy device. @@ -1605,7 +1605,7 @@ None ``` -### `serviceCount()` +### `bleDevice.serviceCount()` Query the number of services discovered for the Bluetooth® Low Energy device. @@ -1676,7 +1676,7 @@ The number of **services discovered** for the Bluetooth® Low Energy device. ``` -### `hasService()` +### `bleDevice.hasService()` Query if the Bluetooth® Low Energy device has a particular service. @@ -1748,7 +1748,7 @@ bleDevice.hasService(uuid, index) ``` -### `service()` +### `bleDevice.service()` Get a BLEService representing a Bluetooth® Low Energy service the device provides. @@ -1825,7 +1825,7 @@ bleDevice.service(uuid, index) ``` -### `characteristicCount()` +### `bleDevice.characteristicCount()` Query the number of characteristics discovered for the Bluetooth® Low Energy device. @@ -1896,7 +1896,7 @@ The **number of characteristics** discovered for the Bluetooth® Low Energy devi ``` -### `hasCharacteristic()` +### `bleDevice.hasCharacteristic()` Query if the Bluetooth® Low Energy device has a particular characteristic. @@ -1968,7 +1968,7 @@ bleDevice.hasCharacteristic(uuid, index) ``` -### `hasLocalName()` +### `bleDevice.hasLocalName()` Query if a discovered Bluetooth® Low Energy device is advertising a local name. @@ -2021,7 +2021,7 @@ Nothing ``` -### `hasAdvertisedServiceUuid()` +### `bleDevice.hasAdvertisedServiceUuid()` Query if a discovered Bluetooth® Low Energy device is advertising a service UUID. @@ -2079,7 +2079,7 @@ bleDevice.hasAdvertisedServiceUuid(index) ``` -### `advertisedServiceUuidCount()` +### `bleDevice.advertisedServiceUuidCount()` Query the number of advertised services a discovered Bluetooth® Low Energy device is advertising. @@ -2136,7 +2136,7 @@ The **number of advertised services** a discovered Bluetooth® Low Energy device ``` -### `localName()` +### `bleDevice.localName()` Query the local name a discovered Bluetooth® Low Energy device is advertising with. @@ -2189,7 +2189,7 @@ Nothing ``` -### `advertisedServiceUuid()` +### `bleDevice.advertisedServiceUuid()` Query an advertised service UUID discovered Bluetooth® Low Energy device is advertising. @@ -2247,7 +2247,7 @@ Advertised service **UUID** (as a String). ``` -### `connect()` +### `bleDevice.connect()` Connect to a Bluetooth® Low Energy device. @@ -2334,7 +2334,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Lo ``` -### `uuid()` +### `bleService.uuid()` Query the UUID of the specified BLEService. @@ -2366,7 +2366,7 @@ Serial.println(ledService.uuid()); ``` -### `addCharacteristic()` +### `bleService.addCharacteristic()` Add a BLECharateristic to the Bluetooth® Low Energy service. @@ -2403,7 +2403,7 @@ ledService.addCharacteristic(switchCharacteristic); ``` -### `characteristicCount()` +### `bleService.characteristicCount()` Query the number of characteristics discovered for the Bluetooth® Low Energy service. @@ -2481,7 +2481,7 @@ The **number of characteristics** discovered for the Bluetooth® Low Energy serv ``` -### `hasCharacteristic()` +### `bleService.hasCharacteristic()` Query if the Bluetooth® Low Energy service has a particular characteristic. @@ -2559,7 +2559,7 @@ bleService.hasCharacteristic(uuid, index) ``` -### `characteristic()` +### `bleService.characteristic()` Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the service provides. @@ -2695,7 +2695,7 @@ BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit chara ``` -### `uuid()` +### `bleCharacteristic.uuid()` Query the UUID of the specified BLECharacteristic. @@ -2728,7 +2728,7 @@ Serial.println(switchCharacteristic.uuid()); ``` -### `properties()` +### `bleCharacteristic.properties()` Query the property mask of the specified BLECharacteristic. @@ -2767,7 +2767,7 @@ if (properties & (BLEWrite | BLEWriteWithoutResponse)) { ``` -### `valueSize()` +### `bleCharacteristic.valueSize()` Query the maximum value size of the specified BLECharacteristic. @@ -2800,7 +2800,7 @@ Serial.println(switchCharacteristic.valueSize()); ``` -### `value()` +### `bleCharacteristic.value()` Query the current value of the specified BLECharacteristic. @@ -2839,7 +2839,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 ``` -### `valueLength()` +### `bleCharacteristic.valueLength()` Query the current value size of the specified BLECharacteristic. @@ -2872,7 +2872,7 @@ Serial.println(switchCharacteristic.valueLength()); ``` -### `readValue()` +### `bleCharacteristic.readValue()` Read the current value of the characteristic. If the characteristic is on a remote device, a read request will be sent. @@ -2921,7 +2921,7 @@ Number of bytes read ``` -### `writeValue()` +### `bleCharacteristic.writeValue()` Write the value of the characteristic. If the characteristic is on a remote device, a write request or command will be sent. @@ -2969,7 +2969,7 @@ bleCharacteristic.writeValue(value) ``` -### `setEventHandler()` +### `bleCharacteristic.setEventHandler()` Set the event handler (callback) function that will be called when the specified event occurs. @@ -3020,7 +3020,7 @@ void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteri ``` -### `broadcast()` +### `bleCharacteristic.broadcast()` Broadcast the characteristics value as service data when advertising. @@ -3053,7 +3053,7 @@ buttonCharacteristic.broadcast(); ``` -### `written()` +### `bleCharacteristic.written()` Query if the characteristic value has been written by another Bluetooth® Low Energy device. @@ -3115,7 +3115,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 ``` -### `subscribed()` +### `bleCharacteristic.subscribed()` Query if the characteristic has been subscribed to by another Bluetooth® Low Energy device. @@ -3153,7 +3153,7 @@ BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit chara ``` -### `addDescriptor()` +### `bleCharacteristic.addDescriptor()` Add a BLEDescriptor to the characteristic. @@ -3190,7 +3190,7 @@ BLEDescriptor batteryLevelDescriptor("2901", "millis"); ``` -### `descriptorCount` +### `bleCharacteristic.descriptorCount` Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. @@ -3222,7 +3222,7 @@ The **number of Bluetooth® Low Energy descriptors** discovered for the characte ``` -### `hasDescriptor` +### `bleCharacteristic.hasDescriptor` Check if a characteristic has a particular descriptor. @@ -3253,7 +3253,7 @@ bleCharacteristic.hasDescriptor(uuid, index) ``` -### `descriptor()` +### `bleCharacteristic.descriptor()` Get a BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor. @@ -3285,7 +3285,7 @@ BLEDescriptor that represents a characteristics Bluetooth® Low Energy descripto ``` -### `canRead()` +### `bleCharacteristic.canRead()` Query if a Bluetooth® Low Energy characteristic is readable. @@ -3347,7 +3347,7 @@ None ``` -### `canWrite()` +### `bleCharacteristic.canWrite()` Query if a Bluetooth® Low Energy characteristic is writable. @@ -3376,7 +3376,7 @@ None ``` -### `canSubscribe()` +### `bleCharacteristic.canSubscribe()` Query if a Bluetooth® Low Energy characteristic is subscribable. @@ -3405,7 +3405,7 @@ None ``` -### `subscribe()` +### `bleCharacteristic.subscribe()` Subscribe to a Bluetooth® Low Energy characteristics notification or indications. @@ -3453,7 +3453,7 @@ None ``` -### `canUnsubscribe()` +### `bleCharacteristic.canUnsubscribe()` Query if a Bluetooth® Low Energy characteristic is unsubscribable. @@ -3482,7 +3482,7 @@ None ``` -### `unsubscribe()` +### `bleCharacteristic.unsubscribe()` Unsubscribe to a Bluetooth® Low Energy characteristics notifications or indications. @@ -3532,7 +3532,7 @@ None ``` -### `valueUpdated()` +### `bleCharacteristic.valueUpdated()` Has the characteristics value been updated via a notification or indication. @@ -3614,7 +3614,7 @@ BLEDescriptor millisLabelDescriptor("2901", "millis"); ``` -### `uuid()` +### `bleDescriptor.uuid()` Query the UUID of the specified BLEDescriptor. @@ -3646,7 +3646,7 @@ Serial.println(millisLabelDescriptor.uuid()); ``` -### `valueSize()` +### `bleDescriptor.valueSize()` Query the value size of the specified BLEDescriptor. @@ -3678,7 +3678,7 @@ Serial.println(millisLabelDescriptor.valueSize()); ``` -### `valueLength()` +### `bleDescriptor.valueLength()` Query the length, in bytes, of the descriptor current value. @@ -3724,7 +3724,7 @@ None ``` -### `value()` +### `bleDescriptor.value()` Query the value of the specified BLEDescriptor. @@ -3761,7 +3761,7 @@ BLEDescriptor millisLabelDescriptor("2901", "millis"); ``` -### `readValue()` +### `bleDescriptor.readValue()` Read the current value of the descriptor. If the descriptor is on a remote device, a read request will be sent. @@ -3795,7 +3795,7 @@ bleDescriptor.readValue(value) ``` -### `read()` +### `bleDescriptor.read()` Perform a read request for the descriptor. From 4cf376eb39ae1ae623ade8d48f03f729aae44124 Mon Sep 17 00:00:00 2001 From: Maciej Klemarczyk Date: Thu, 7 Apr 2022 20:10:01 +0200 Subject: [PATCH 036/112] Unification of documentation --- docs/api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index b8fa1d5f..f3a7bc43 100644 --- a/docs/api.md +++ b/docs/api.md @@ -3190,7 +3190,7 @@ BLEDescriptor batteryLevelDescriptor("2901", "millis"); ``` -### `bleCharacteristic.descriptorCount` +### `bleCharacteristic.descriptorCount()` Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. @@ -3222,7 +3222,7 @@ The **number of Bluetooth® Low Energy descriptors** discovered for the characte ``` -### `bleCharacteristic.hasDescriptor` +### `bleCharacteristic.hasDescriptor()` Check if a characteristic has a particular descriptor. From 6438f81904d1cc4b63fcd2ca669c9893a9a950c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:39:54 +0000 Subject: [PATCH 037/112] Bump actions/download-artifact from 2 to 3 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea57559..e84e803e 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v3 - name: Download configuration files artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From 785ef5cbb3622dff711f619467b742641847df2c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:39:58 +0000 Subject: [PATCH 038/112] Bump actions/upload-artifact from 2 to 3 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea57559..1d969d57 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: path: | *.yaml From b94ff5f28e6d39fb39aa6de339113540bd3e294c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Hyl=C3=A9n?= <60390259+jacobhylen@users.noreply.github.com> Date: Fri, 29 Apr 2022 11:23:39 +0200 Subject: [PATCH 039/112] Update api.md Bullet points in ### Parameters and ### Returns. --- docs/api.md | 287 +++++++++++++++++++++++++++++----------------------- 1 file changed, 159 insertions(+), 128 deletions(-) diff --git a/docs/api.md b/docs/api.md index df285806..1ed8e6bb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -20,7 +20,8 @@ BLE.begin() None #### Returns -1 on success, 0 on failure. +- 1 on success +- 0 on failure #### Example @@ -119,8 +120,8 @@ BLE.setEventHandler(eventType, callback) #### Parameters -**eventType**: event type (BLEConnected, BLEDisconnected) -**callback**: function to call when event occurs +- **eventType**: event type (BLEConnected, BLEDisconnected) +- **callback**: function to call when event occurs #### Returns Nothing. @@ -175,7 +176,8 @@ BLE.connected() None #### Returns -**true** if another Bluetooth® Low Energy device is connected, otherwise **false**. +- **true** if another Bluetooth® Low Energy device is connected, +- otherwise **false**. #### Example @@ -206,7 +208,8 @@ BLE.disconnect() None #### Returns -**true** if any Bluetooth® Low Energy device that was previously connected was disconnected, otherwise **false**. +- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, +- otherwise **false**. #### Example @@ -237,7 +240,7 @@ BLE.address() None #### Returns -The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). +- The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). #### Example @@ -267,7 +270,7 @@ BLE.rssi() None #### Returns -The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. +- The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. #### Example @@ -296,7 +299,7 @@ BLE.setAdvertisedServiceUuid(uuid) #### Parameters -**uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format +- **uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format #### Returns Nothing @@ -335,7 +338,7 @@ BLE.setAdvertisedService(bleService) #### Parameters -**bleService:** BLEService to use UUID from +- **bleService:** BLEService to use UUID from #### Returns Nothing @@ -378,8 +381,8 @@ BLE.setManufacturerData(data, length) #### Parameters -**data:** byte array containing manufacturer data -**length:** length of manufacturer data array +- **data:** byte array containing manufacturer data +- **length:** length of manufacturer data array #### Returns Nothing @@ -421,7 +424,7 @@ BLE.setLocalName(name) #### Parameters -**name:** local name value to use when advertising +- **name:** local name value to use when advertising #### Returns Nothing @@ -461,7 +464,7 @@ BLE.setDeviceName(name) #### Parameters -**name:** device name value +- **name:** device name value #### Returns Nothing @@ -501,7 +504,7 @@ BLE.setAppearance(appearance) #### Parameters -**appearance:** appearance value +- **appearance:** appearance value #### Returns Nothing @@ -541,7 +544,7 @@ BLE.addService(service) #### Parameters -**service:** BLEService to add +- **service:** BLEService to add #### Returns Nothing @@ -586,7 +589,8 @@ BLE.advertise() None #### Returns -1 on success, 0 on failure. +- 1 on success, +- 0 on failure. #### Example @@ -664,7 +668,7 @@ BLE.central() None #### Returns -**BLEDevice** representing the central. +- **BLEDevice** representing the central. #### Example @@ -698,7 +702,7 @@ BLE.setAdvertisingInterval(advertisingInterval) #### Parameters -**advertisingInterval:** advertising interval in units of 0.625 ms +- **advertisingInterval:** advertising interval in units of 0.625 ms #### Returns Nothing. @@ -736,8 +740,8 @@ BLE.setConnectionInterval(minimum, maximum) #### Parameters -**minimum:** minimum desired connection interval in units of 1.25 ms -**maximum:** maximum desired connection interval in units of 1.25 ms +- **minimum:** minimum desired connection interval in units of 1.25 ms +- **maximum:** maximum desired connection interval in units of 1.25 ms #### Returns Nothing. @@ -774,8 +778,8 @@ BLE.setConnectable(connectable) #### Parameters -**true**: the device will be connectable when advertising -**false**: the device will NOT be connectable when advertising +- **true**: the device will be connectable when advertising +- **false**: the device will NOT be connectable when advertising #### Returns Nothing. @@ -813,10 +817,11 @@ BLE.scan(withDuplicates) #### Parameters -**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered +- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered #### Returns -1 on success, 0 on failure. +- 1 on success, +- 0 on failure. #### Example @@ -859,11 +864,12 @@ BLE.scanForName(name, withDuplicates) #### Parameters -**name:** (local) name of device (as a **String**) to filter for -**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. +- **name:** (local) name of device (as a **String**) to filter for +- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. #### Returns -1 on success, 0 on failure. +- 1 on success, +- 0 on failure. #### Example @@ -906,11 +912,12 @@ BLE.scanForAddress(address, withDuplicates) #### Parameters -**address:** (Bluetooth®) address (as a String) to filter for -**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered +- **address:** (Bluetooth®) address (as a String) to filter for +- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered #### Returns -1 on success, 0 on failure. +- 1 on success, +- 0 on failure. #### Example @@ -953,11 +960,12 @@ BLE.scanForUuid(uuid, withDuplicates) #### Parameters -**uuid:** (service) UUID (as a **String**) to filter for -**withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. +- **uuid:** (service) UUID (as a **String**) to filter for +- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. #### Returns -1 on success, 0 on failure. +- 1 on success, +- 0 on failure. #### Example @@ -1042,7 +1050,7 @@ BLE.available() Nothing #### Returns -**BLEDevice** representing the discovered device. +- **BLEDevice** representing the discovered device. #### Example @@ -1089,7 +1097,7 @@ bleDevice.poll(timeout) #### Parameters -**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. +- **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. #### Returns Nothing @@ -1129,7 +1137,8 @@ bleDevice.connected() None #### Returns -**true** if the Bluetooth® Low Energy device is connected, otherwise **false**. +- **true** if the Bluetooth® Low Energy device is connected, +- otherwise **false**. #### Example @@ -1163,7 +1172,8 @@ bleDevice.disconnect() None #### Returns -**true** if the Bluetooth® Low Energy device was disconnected, otherwise **false**. +- **true** if the Bluetooth® Low Energy device was disconnected, +- otherwise **false**. #### Example @@ -1195,7 +1205,7 @@ bleDevice.address() None #### Returns -The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). +- **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). #### Example @@ -1232,7 +1242,7 @@ bleDevice.rssi() None #### Returns -The **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. +- **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. #### Example @@ -1263,11 +1273,11 @@ bleDevice.characteristic(uuid, index) #### Parameters -**index**: index of characteristic -**uuid**: uuid (as a **String**) +- **index**: index of characteristic +- **uuid**: uuid (as a **String**) #### Returns -**BLECharacteristic** for provided parameters +- **BLECharacteristic** for provided parameters #### Example @@ -1341,7 +1351,8 @@ bleDevice.discoverAttributes() None #### Returns -**true**, if successful, **false** on failure. +- **true**, if successful, +- **false** on failure. #### Example @@ -1404,10 +1415,11 @@ bleDevice.discoverService(serviceUuid) #### Parameters -**serviceUuid:** service UUID to discover (as a **String**) +- **serviceUuid:** service UUID to discover (as a **String**) #### Returns -**true**, if successful, **false** on failure. +- **true**, if successful, +- **false** on failure. #### Example @@ -1473,7 +1485,7 @@ bleDevice.deviceName() None #### Returns -**Device name** (as a String). +- **Device name** (as a String). #### Example @@ -1547,7 +1559,7 @@ bleDevice.appearance() None #### Returns -**Appearance value** (as a number). +- **Appearance value** (as a number). #### Example @@ -1621,7 +1633,7 @@ bleDevice.serviceCount() None #### Returns -The number of **services discovered** for the Bluetooth® Low Energy device. +- The number of **services discovered** for the Bluetooth® Low Energy device. #### Example @@ -1690,11 +1702,12 @@ bleDevice.hasService(uuid, index) #### Parameters -**uuid**: uuid to check (as a **String**) -**index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. +- **uuid**: uuid to check (as a **String**) +- **index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. #### Returns -**true**, if the device provides the service, **false** otherwise. +- **true**, if the device provides the service, +- **false** otherwise. #### Example @@ -1763,11 +1776,11 @@ bleDevice.service(uuid, index) #### Parameters -**index**: index of service -**uuid**: uuid (as a **String**) +- **index**: index of service +- **uuid**: uuid (as a **String**) #### Returns -**BLEService** for provided parameters +- **BLEService** for provided parameters #### Example @@ -1841,7 +1854,7 @@ bleDevice.characteristicCount() None #### Returns -The **number of characteristics** discovered for the Bluetooth® Low Energy device. +- The **number of characteristics** discovered for the Bluetooth® Low Energy device. #### Example @@ -1910,11 +1923,12 @@ bleDevice.hasCharacteristic(uuid, index) #### Parameters -**uuid**: uuid to check (as a **String**) -**index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. +- **uuid**: uuid to check (as a **String**) +- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. #### Returns -**true**, if the device provides the characteristic, **false** otherwise. +- **true**, if the device provides the characteristic, +- **false** otherwise. #### Example @@ -1984,7 +1998,8 @@ bleDevice.hasLocalName() Nothing #### Returns -**true**, if the device is advertising a local name, **false** otherwise. +- **true**, if the device is advertising a local name, +- **false** otherwise. #### Example @@ -2035,10 +2050,11 @@ bleDevice.hasAdvertisedServiceUuid(index) #### Parameters -**index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. +- **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. #### Returns -**true**, if the device is advertising a service UUID, **false** otherwise. +- **true**, if the device is advertising a service UUID, +- **false** otherwise. #### Example @@ -2095,7 +2111,7 @@ bleDevice.advertisedServiceUuidCount() None #### Returns -The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. +- The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. #### Example @@ -2152,7 +2168,7 @@ bleDevice.localName() Nothing #### Returns -**Advertised local name** (as a String). +- **Advertised local name** (as a String). #### Example @@ -2203,10 +2219,10 @@ bleDevice.advertisedServiceUuid(index) #### Parameters -**index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. +- **index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. #### Returns -Advertised service **UUID** (as a String). +- Advertised service **UUID** (as a String). #### Example @@ -2263,7 +2279,8 @@ bleDevice.connect() None #### Returns -**true**, if the connection was successful, **false** otherwise. +- **true**, if the connection was successful, +- **false** otherwise. #### Example @@ -2320,10 +2337,10 @@ BLEService(uuid) #### Parameters -**uuid**: 16-bit or 128-bit UUID in **String** format +- **uuid**: 16-bit or 128-bit UUID in **String** format #### Returns -New **BLEService** with the specified **UUID** +- New **BLEService** with the specified **UUID** #### Example @@ -2350,7 +2367,7 @@ bleService.uuid() None #### Returns -UUID of the Bluetooth® Low Energy service as a **String**. +- UUID of the Bluetooth® Low Energy service as a **String**. #### Example @@ -2419,7 +2436,7 @@ bleService.characteristicCount() None #### Returns -The **number of characteristics** discovered for the Bluetooth® Low Energy service. +- The **number of characteristics** discovered for the Bluetooth® Low Energy service. #### Example @@ -2495,11 +2512,12 @@ bleService.hasCharacteristic(uuid, index) #### Parameters -**uuid**: uuid to check (as a **String**) -**index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. +- **uuid**: uuid to check (as a **String**) +- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. #### Returns -**true**, if the service provides the characteristic, **false** otherwise. +- **true**, if the service provides the characteristic, +- **false** otherwise. #### Example @@ -2574,11 +2592,11 @@ bleService.characteristic(uuid, index) #### Parameters -**index**: index of characteristic -**uuid**: uuid (as a **String**) +- **index**: index of characteristic +- **uuid**: uuid (as a **String**) #### Returns -**BLECharacteristic** for provided parameters +- **BLECharacteristic** for provided parameters #### Example @@ -2675,13 +2693,13 @@ BLEDoubleCharacteristic(uuid, properties) #### Parameters -**uuid**: 16-bit or 128-bit UUID in **String** format -**properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) -**valueSize**: (maximum) size of characteristic value -**stringValue**: value as a string +- **uuid**: 16-bit or 128-bit UUID in **String** format +- **properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) +- **valueSize**: (maximum) size of characteristic value +- **stringValue**: value as a string #### Returns -New **BLECharacteristic** with the specified **UUID** and value +- New **BLECharacteristic** with the specified **UUID** and value #### Example @@ -2711,7 +2729,7 @@ bleCharacteristic.uuid() None #### Returns -**UUID** of the Bluetooth® Low Energy service as a **String**. +- **UUID** of the Bluetooth® Low Energy service as a **String**. #### Example @@ -2744,7 +2762,7 @@ bleCharacteristic.properties() None #### Returns -**Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) +- **Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) #### Example @@ -2783,7 +2801,7 @@ bleCharacteristic.valueSize() None #### Returns -The **maximum value** size of the characteristic (in bytes) +- The **maximum value** size of the characteristic (in bytes) #### Example @@ -2816,7 +2834,7 @@ bleCharacteristic.value() None #### Returns -The **current value** of the characteristic, value type depends on the constructor used +- The **current value** of the characteristic, value type depends on the constructor used #### Example @@ -2855,7 +2873,7 @@ bleCharacteristic.valueLength() None #### Returns -The **current value** size of the characteristic (in bytes) +- The **current value** size of the characteristic (in bytes) #### Example @@ -2886,11 +2904,11 @@ bleCharacteristic.readValue(value) #### Parameters -**buffer:** byte array to read value into length: size of buffer argument in bytes -**value**: variable to read value into (by reference) +- **buffer:** byte array to read value into length: size of buffer argument in bytes +- **value**: variable to read value into (by reference) #### Returns -Number of bytes read +- **Number of bytes** read #### Example @@ -2935,12 +2953,13 @@ bleCharacteristic.writeValue(value) #### Parameters -**buffer**: byte array to write value with -**length**: number of bytes of the buffer argument to write -**value**: value to write +- **buffer**: byte array to write value with +- **length**: number of bytes of the buffer argument to write +- **value**: value to write #### Returns -1 on success, 0 on failure +- 1 on success, +- 0 on failure #### Example @@ -2982,8 +3001,8 @@ bleCharacteristic.setEventHandler(eventType, callback) #### Parameters -**eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) -**callback**: function to call when the event occurs +- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) +- **callback**: function to call when the event occurs #### Returns Nothing @@ -3036,7 +3055,8 @@ bleCharacteristic.broadcast() None #### Returns -1 on success, 0 on failure +- 1 on success, +- 0 on failure #### Example @@ -3069,7 +3089,8 @@ bleCharacteristic.written() None #### Returns -**true** if the characteristic value has been written by another Bluetooth® Low Energy device, **false** otherwise +- **true** if the characteristic value has been written by another Bluetooth® Low Energy device, +- **false** otherwise #### Example @@ -3131,7 +3152,8 @@ bleCharacteristic.subscribed() None #### Returns -**true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, **false** otherwise +- **true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, +- **false** otherwise #### Example @@ -3166,7 +3188,7 @@ bleCharacteristic.addDescriptor(bleDescriptor) #### Parameters -**bleDescriptor**: descriptor to add to the characteristic +- **bleDescriptor**: descriptor to add to the characteristic #### Returns Nothing @@ -3206,7 +3228,7 @@ bleCharacteristic.descriptorCount() None #### Returns -The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic +- The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic #### Example @@ -3236,11 +3258,12 @@ bleCharacteristic.hasDescriptor(uuid, index) #### Parameters -**index**: index of descriptor -**uuid**: uuid (as a **String**) +- **index**: index of descriptor +- **uuid**: uuid (as a **String**) #### Returns -**true**, if the characteristic has a matching descriptor, otherwise **false**. +- **true**, if the characteristic has a matching descriptor, +- otherwise **false**. #### Example @@ -3268,11 +3291,11 @@ bleCharacteristic.descriptor(uuid, index) #### Parameters -**index**: index of descriptor -**uuid**: uuid (as a **String**) +- **index**: index of descriptor +- **uuid**: uuid (as a **String**) #### Returns -BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor +- BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor #### Example @@ -3301,7 +3324,8 @@ bleCharacteristic.canRead() None #### Returns -**true**, if characteristic is readable, **false** otherwise +- **true**, if characteristic is readable, +- **false** otherwise #### Example @@ -3330,7 +3354,8 @@ bleCharacteristic.read() None #### Returns -**true**, if successful, **false** on failure +- **true**, if successful, +- **false** on failure #### Example @@ -3363,7 +3388,8 @@ bleCharacteristic.canWrite() None #### Returns -**true**, if characteristic is writable, **false** otherwise +- **true**, if characteristic is writable, +- **false** otherwise #### Example @@ -3392,7 +3418,8 @@ bleCharacteristic.canSubscribe() None #### Returns -**true**, if characteristic is subscribable, **false** otherwise +- **true**, if characteristic is subscribable, +- **false** otherwise #### Example @@ -3421,7 +3448,8 @@ bleCharacteristic.subscribe() None #### Returns -**true**, on success, **false** on failure +- **true**, on success, +- **false** on failure #### Example @@ -3469,7 +3497,8 @@ bleCharacteristic.canUnsubscribe() None #### Returns -**true**, if characteristic is unsubscribable, **false** otherwise +- **true**, if characteristic is unsubscribable, +- **false** otherwise #### Example @@ -3498,7 +3527,8 @@ bleCharacteristic.unsubscribe() None #### Returns -**true**, on success, **false** on failure +- **true**, on success, +- **false** on failure #### Example @@ -3548,7 +3578,7 @@ bleCharacteristic.valueUpdated() None #### Returns -**true**, if the characteristics value been updated via a notification or indication +- **true**, if the characteristics value been updated via a notification or indication #### Example @@ -3597,13 +3627,13 @@ BLEDescriptor(uuid, stringValue) #### Parameters -**uuid**: 16-bit or 128-bit UUID in string format -**value**: byte array value -**valueSize**: size of byte array value -**stringValue**: value as a string +- **uuid**: 16-bit or 128-bit UUID in string format +- **value**: byte array value +- **valueSize**: size of byte array value +- **stringValue**: value as a string #### Returns -New **BLEDescriptor** with the specified **UUID** and value +- New **BLEDescriptor** with the specified **UUID** and value #### Example @@ -3630,7 +3660,7 @@ bleDescriptor.uuid() None #### Returns -**UUID** of the Bluetooth® Low Energy descriptor (as a String). +- **UUID** of the Bluetooth® Low Energy descriptor (as a String). #### Example @@ -3662,7 +3692,7 @@ bleDescriptor.valueSize() None #### Returns -**Value size** (in bytes) of the Bluetooth® Low Energy descriptor. +- **Value size** (in bytes) of the Bluetooth® Low Energy descriptor. #### Example @@ -3694,7 +3724,7 @@ bleDescriptor.valueLength() None #### Returns -**Length of descriptor** value in bytes. +- **Length of descriptor** value in bytes. #### Example @@ -3740,7 +3770,7 @@ bleDescriptor.value() None #### Returns -Value byte array of the **BLE descriptor**. +- Value byte array of the **BLE descriptor**. #### Example @@ -3775,12 +3805,12 @@ bleDescriptor.readValue(value) #### Parameters -**buffer**: byte array to read value into -**length**: size of buffer argument in bytes -**value**: variable to read value into (by reference) +- **buffer**: byte array to read value into +- **length**: size of buffer argument in bytes +- **value**: variable to read value into (by reference) #### Returns -**Number of bytes** read +- **Number of bytes** read #### Example @@ -3811,7 +3841,8 @@ bleDescriptor.read() None #### Returns -**true**, if successful, **false** on failure +- **true**, if successful, +- **false** on failure #### Example From b39ac7ebf27635ad418c2e5fc2a48c14ef7a2eaa Mon Sep 17 00:00:00 2001 From: giulcioffi Date: Tue, 21 Sep 2021 14:50:24 +0200 Subject: [PATCH 040/112] Add support for NICLA VISION --- src/local/BLELocalDevice.cpp | 9 ++++++--- src/utility/HCIUartTransport.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 45d975a5..bb337a2b 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -29,6 +29,10 @@ #ifndef BT_REG_ON #define BT_REG_ON PJ_12 #endif +#elif defined(ARDUINO_NICLA_VISION) +#ifndef BT_REG_ON +#define BT_REG_ON PF_14 +#endif #endif BLELocalDevice::BLELocalDevice() @@ -61,7 +65,7 @@ int BLELocalDevice::begin() delay(100); digitalWrite(NINA_RESETN, HIGH); delay(750); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, HIGH); @@ -134,8 +138,7 @@ void BLELocalDevice::end() #elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) // disable the NINA digitalWrite(NINA_RESETN, LOW); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) - // BT_REG_ON -> LOW +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) digitalWrite(BT_REG_ON, LOW); #endif } diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 67bc173f..37ce95e7 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -27,7 +27,7 @@ // SerialHCI is already defined in the variant #elif defined(ARDUINO_PORTENTA_H7_M4) // SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M7) +#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #define SerialHCI Serial2 #else #error "Unsupported board selected!" From 58136fca11465a5b6703b386d9b1f0f1c13ccedf Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 May 2022 10:18:17 +0200 Subject: [PATCH 041/112] Bugfix: memory leak caused by variables not being deleted in end(). #192 --- src/utility/GATT.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 373213b9..50af4f6c 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -70,7 +70,12 @@ void GATTClass::begin() void GATTClass::end() { - _attributes.clear(); + delete(_genericAccessService); + delete(_deviceNameCharacteristic); + delete(_appearanceCharacteristic); + delete(_genericAttributeService); + delete(_servicesChangedCharacteristic); + clearAttributes(); } void GATTClass::setDeviceName(const char* deviceName) From 3c6a53ae7856ccf7189df7adc9f38079c8371432 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 May 2022 14:01:21 +0200 Subject: [PATCH 042/112] Respect refcounting before freeing dynamically allocated variables --- src/utility/GATT.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 50af4f6c..5db7ec55 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -70,11 +70,21 @@ void GATTClass::begin() void GATTClass::end() { - delete(_genericAccessService); - delete(_deviceNameCharacteristic); - delete(_appearanceCharacteristic); - delete(_genericAttributeService); - delete(_servicesChangedCharacteristic); + if (_genericAccessService->release() <= 0) + delete(_genericAccessService); + + if (_deviceNameCharacteristic->release() <= 0) + delete(_deviceNameCharacteristic); + + if (_appearanceCharacteristic->release() <= 0) + delete(_appearanceCharacteristic); + + if (_genericAttributeService->release() <= 0) + delete(_genericAttributeService); + + if (_servicesChangedCharacteristic->release() <= 0) + delete(_servicesChangedCharacteristic); + clearAttributes(); } From 122319959ddeb317b2e76ffc4c350f4f2f5804d4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 May 2022 18:12:46 +0200 Subject: [PATCH 043/112] Call end() upon destruction --- src/utility/GATT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 5db7ec55..3874fb6f 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -38,7 +38,7 @@ GATTClass::GATTClass() : GATTClass::~GATTClass() { - clearAttributes(); + end(); } void GATTClass::begin() From f24ba26576fdb74e6be4ec9f704042f059bdd6e6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 12 May 2022 15:12:16 +0200 Subject: [PATCH 044/112] Prevent double object deletion --- src/BLECharacteristic.cpp | 4 ++-- src/BLEDescriptor.cpp | 4 ++-- src/BLEService.cpp | 4 ++-- src/local/BLELocalCharacteristic.cpp | 2 +- src/local/BLELocalService.cpp | 2 +- src/remote/BLERemoteCharacteristic.cpp | 2 +- src/remote/BLERemoteDevice.cpp | 2 +- src/remote/BLERemoteService.cpp | 2 +- src/utility/GATT.cpp | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/BLECharacteristic.cpp b/src/BLECharacteristic.cpp index 1cfbf489..cb9783ce 100644 --- a/src/BLECharacteristic.cpp +++ b/src/BLECharacteristic.cpp @@ -72,11 +72,11 @@ BLECharacteristic::BLECharacteristic(const BLECharacteristic& other) BLECharacteristic::~BLECharacteristic() { - if (_local && _local->release() <= 0) { + if (_local && _local->release() == 0) { delete _local; } - if (_remote && _remote->release() <= 0) { + if (_remote && _remote->release() == 0) { delete _remote; } } diff --git a/src/BLEDescriptor.cpp b/src/BLEDescriptor.cpp index 7a6736b0..366b89aa 100644 --- a/src/BLEDescriptor.cpp +++ b/src/BLEDescriptor.cpp @@ -72,11 +72,11 @@ BLEDescriptor::BLEDescriptor(const BLEDescriptor& other) BLEDescriptor::~BLEDescriptor() { - if (_local && _local->release() <= 0) { + if (_local && _local->release() == 0) { delete _local; } - if (_remote && _remote->release() <= 0) { + if (_remote && _remote->release() == 0) { delete _remote; } } diff --git a/src/BLEService.cpp b/src/BLEService.cpp index 7b5df148..b3f33739 100644 --- a/src/BLEService.cpp +++ b/src/BLEService.cpp @@ -65,11 +65,11 @@ BLEService::BLEService(const BLEService& other) BLEService::~BLEService() { - if (_local && _local->release() <= 0) { + if (_local && _local->release() == 0) { delete _local; } - if (_remote && _remote->release() <= 0) { + if (_remote && _remote->release() == 0) { delete _remote; } } diff --git a/src/local/BLELocalCharacteristic.cpp b/src/local/BLELocalCharacteristic.cpp index 2cd801b2..63208b05 100644 --- a/src/local/BLELocalCharacteristic.cpp +++ b/src/local/BLELocalCharacteristic.cpp @@ -62,7 +62,7 @@ BLELocalCharacteristic::~BLELocalCharacteristic() for (unsigned int i = 0; i < descriptorCount(); i++) { BLELocalDescriptor* d = descriptor(i); - if (d->release() <= 0) { + if (d->release() == 0) { delete d; } } diff --git a/src/local/BLELocalService.cpp b/src/local/BLELocalService.cpp index 442c5422..58957342 100644 --- a/src/local/BLELocalService.cpp +++ b/src/local/BLELocalService.cpp @@ -33,7 +33,7 @@ BLELocalService::~BLELocalService() for (unsigned int i = 0; i < characteristicCount(); i++) { BLELocalCharacteristic* c = characteristic(i); - if (c->release() <= 0) { + if (c->release() == 0) { delete c; } } diff --git a/src/remote/BLERemoteCharacteristic.cpp b/src/remote/BLERemoteCharacteristic.cpp index e8ac733f..454438b6 100644 --- a/src/remote/BLERemoteCharacteristic.cpp +++ b/src/remote/BLERemoteCharacteristic.cpp @@ -44,7 +44,7 @@ BLERemoteCharacteristic::~BLERemoteCharacteristic() for (unsigned int i = 0; i < descriptorCount(); i++) { BLERemoteDescriptor* d = descriptor(i); - if (d->release() <= 0) { + if (d->release() == 0) { delete d; } } diff --git a/src/remote/BLERemoteDevice.cpp b/src/remote/BLERemoteDevice.cpp index 5a49f26f..1a4a67ab 100644 --- a/src/remote/BLERemoteDevice.cpp +++ b/src/remote/BLERemoteDevice.cpp @@ -50,7 +50,7 @@ void BLERemoteDevice::clearServices() for (unsigned int i = 0; i < serviceCount(); i++) { BLERemoteService* s = service(i); - if (s->release() <= 0) { + if (s->release() == 0) { delete s; } } diff --git a/src/remote/BLERemoteService.cpp b/src/remote/BLERemoteService.cpp index fd5c0ba6..f7461290 100644 --- a/src/remote/BLERemoteService.cpp +++ b/src/remote/BLERemoteService.cpp @@ -31,7 +31,7 @@ BLERemoteService::~BLERemoteService() for (unsigned int i = 0; i < characteristicCount(); i++) { BLERemoteCharacteristic* c = characteristic(i); - if (c->release() <= 0) { + if (c->release() == 0) { delete c; } } diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 3874fb6f..35adb5f7 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -179,7 +179,7 @@ void GATTClass::clearAttributes() for (unsigned int i = 0; i < attributeCount(); i++) { BLELocalAttribute* a = attribute(i); - if (a->release() <= 0) { + if (a->release() == 0) { delete a; } } From 2b72c948b3f2da4287ce69488da9804bb4bb8e5f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 23 May 2022 18:11:19 +0200 Subject: [PATCH 045/112] Don't double-free characteristics --- src/utility/GATT.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 35adb5f7..98d5f4ad 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -70,19 +70,19 @@ void GATTClass::begin() void GATTClass::end() { - if (_genericAccessService->release() <= 0) + if (_genericAccessService->release() == 0) delete(_genericAccessService); - if (_deviceNameCharacteristic->release() <= 0) + if (_deviceNameCharacteristic->release() == 0) delete(_deviceNameCharacteristic); - if (_appearanceCharacteristic->release() <= 0) + if (_appearanceCharacteristic->release() == 0) delete(_appearanceCharacteristic); - if (_genericAttributeService->release() <= 0) + if (_genericAttributeService->release() == 0) delete(_genericAttributeService); - if (_servicesChangedCharacteristic->release() <= 0) + if (_servicesChangedCharacteristic->release() == 0) delete(_servicesChangedCharacteristic); clearAttributes(); From afccc49f94fcac2d961e74309b100ba7c9e961d1 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 23 May 2022 18:12:01 +0200 Subject: [PATCH 046/112] Don't terminate CordioHCIHook::getDriver() on end() for Murata chips --- src/utility/HCICordioTransport.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 28eb97be..4dc8d45e 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -234,7 +234,10 @@ void HCICordioTransportClass::end() delete bleLoopThread; bleLoopThread = NULL; } + +#if !defined(ARDUINO_PORTENTA_H7_M4) && !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION) CordioHCIHook::getDriver().terminate(); +#endif _begun = false; } From f0747240daef118d8039280d0a87ab2b40f3d9ea Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 30 May 2022 14:55:10 +0200 Subject: [PATCH 047/112] Release 1.3.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e8859d8e..35afbfaf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.2.2 +version=1.3.0 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From d5bc5b850636be9da59a6c6e147e9d2585433ee4 Mon Sep 17 00:00:00 2001 From: giulcioffi Date: Tue, 31 May 2022 11:37:52 +0200 Subject: [PATCH 048/112] Prepend 'BLE_GATT_' to READ and WRITE enums to avoid clashes with ArduinoIoTCloud lib --- src/BLEProperty.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BLEProperty.h b/src/BLEProperty.h index 434bd2aa..b9238ba9 100644 --- a/src/BLEProperty.h +++ b/src/BLEProperty.h @@ -63,10 +63,10 @@ enum BLEPermission { #define ESP_GATT_PERM_WRITE_AUTHORIZATION (1 << 10) /* bit 10 - 0x0400 */ enum BLE_GATT_PERM_ { - READ = 1 << 0, + BLE_GATT_READ = 1 << 0, READ_ENCRYPTED = 1 << 1, READ_ENC_MITM = 1 << 2, - WRITE = 1 << 4, + BLE_GATT_WRITE = 1 << 4, WRITE_ENCRYPTED = 1 << 5, WRITE_ENC_MITM = 1 << 6, WRITE_SIGNED = 1 << 7, From f24f335c54311ef05c99102ba5714fe99340f2db Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 31 May 2022 18:19:56 +0200 Subject: [PATCH 049/112] Publish 1.3.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 35afbfaf..e2a3f15f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.3.0 +version=1.3.1 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From 9bf21b767bbc380f69dbfad7168dcc4f469c93b6 Mon Sep 17 00:00:00 2001 From: Karthik <101386306+laviator98@users.noreply.github.com> Date: Thu, 9 Jun 2022 12:50:54 +0530 Subject: [PATCH 050/112] Fix Long Term Key Request Negative Reply Command Kindly See the Docs, https://www.bluetooth.com/specifications/specs/core-specification-4-2/ In Pg. No: 1316/2772, you Can See "7.8.26 LE Long Term Key Request Negative Reply Command". Kindly See the OFC Code, it is 0x001B. --- src/utility/HCI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/HCI.h b/src/utility/HCI.h index af46265a..b8f88538 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -35,7 +35,7 @@ enum LE_COMMAND { ENCRYPT = 0x0017, RANDOM = 0x0018, LONG_TERM_KEY_REPLY = 0x001A, - LONG_TERM_KEY_NEGATIVE_REPLY = 0x1B, + LONG_TERM_KEY_NEGATIVE_REPLY = 0x001B, READ_LOCAL_P256 = 0x0025, GENERATE_DH_KEY_V1 = 0x0026, GENERATE_DH_KEY_V2 = 0x005E From fae1e36beeadffadd01624c0c8355ecf0d216149 Mon Sep 17 00:00:00 2001 From: dominsch Date: Tue, 23 Aug 2022 05:46:47 -0300 Subject: [PATCH 051/112] Change non returning functions to void + spelling (#251) --- src/utility/ATT.cpp | 4 ++-- src/utility/HCI.cpp | 8 ++++---- src/utility/HCI.h | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 439b88e8..acdf5a9f 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1272,7 +1272,7 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op } return; } - // Check permssion + // Check permission if((characteristic->permissions() &( BLEPermission::BLEEncryption >> 8)) > 0 && (getPeerEncryption(connectionHandle) & PEER_ENCRYPTION::ENCRYPTED_AES) == 0){ holdResponse = true; @@ -1941,4 +1941,4 @@ int ATTClass::getPeerResolvedAddress(uint16_t connectionHandle, uint8_t resolved #if !defined(FAKE_ATT) ATTClass ATTObj; ATTClass& ATT = ATTObj; -#endif \ No newline at end of file +#endif diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 773f4f18..bc7bc2da 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -460,14 +460,14 @@ int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxIn return sendCommand(OGF_LE_CTL << 10 | OCF_LE_CONN_UPDATE, sizeof(leConnUpdateData), &leConnUpdateData); } -int HCIClass::saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* localIrk){ +void HCIClass::saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* localIrk){ if(_storeIRK!=0){ _storeIRK(address, peerIrk); } // Again... this should work // leAddResolvingAddress(addressType, address, peerIrk, localIrk); } -int HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress, uint8_t* peerIrk, uint8_t* localIrk){ +void HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress, uint8_t* peerIrk, uint8_t* localIrk){ leStopResolvingAddresses(); struct __attribute__ ((packed)) AddDevice { @@ -527,7 +527,7 @@ int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peer return res; } -int HCIClass::writeLK(uint8_t peerAddress[], uint8_t LK[]){ +void HCIClass::writeLK(uint8_t peerAddress[], uint8_t LK[]){ struct __attribute__ ((packed)) StoreLK { uint8_t nKeys; uint8_t BD_ADDR[6]; @@ -538,7 +538,7 @@ int HCIClass::writeLK(uint8_t peerAddress[], uint8_t LK[]){ for(int i=0; i<16; i++) storeLK.LTK[15-i] = LK[i]; HCI.sendCommand(OGF_HOST_CTL << 10 | 0x11, sizeof(storeLK), &storeLK); } -int HCIClass::readStoredLKs(){ +void HCIClass::readStoredLKs(){ uint8_t BD_ADDR[6]; readStoredLK(BD_ADDR, 1); } diff --git a/src/utility/HCI.h b/src/utility/HCI.h index b8f88538..0a530ceb 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -99,15 +99,15 @@ class HCIClass { virtual AuthReq localAuthreq(); virtual uint8_t localIOCap(); - virtual int saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); - virtual int leAddResolvingAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); + virtual void saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); + virtual void leAddResolvingAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* remoteIrk); virtual int leStopResolvingAddresses(); virtual int leStartResolvingAddresses(); virtual int leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peerIdentityAddress, uint8_t* peerResolvableAddress); - virtual int readStoredLKs(); + virtual void readStoredLKs(); virtual int readStoredLK(uint8_t BD_ADDR[], uint8_t read_all = 0); - virtual int writeLK(uint8_t peerAddress[], uint8_t LK[]); + virtual void writeLK(uint8_t peerAddress[], uint8_t LK[]); virtual int tryResolveAddress(uint8_t* BDAddr, uint8_t* address); virtual int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data); From 991f0763bf172cebfebb7cdccbd289ccb2893263 Mon Sep 17 00:00:00 2001 From: dominsch Date: Tue, 23 Aug 2022 05:49:29 -0300 Subject: [PATCH 052/112] Support esp32, esp32-C3, esp32-S3 (#252) * add esp32 support * Update HCIVirtualTransport.cpp * Update HCIVirtualTransport.cpp add ESP32-C3 support * Revert "Update HCIVirtualTransport.cpp" This reverts commit 9af9bea9beb9bc63f9aab68893d414b9a22dacd6. * Update HCIVirtualTransport.cpp * Update library.properties * fix crash on restart * Update ATT.cpp spelling * support more espressif chips * Create compile-for-esp.yaml don't know what I'm doing * skip failing examples * Update compile-for-esp.yaml * Update compile-for-esp.yaml * Update compile-for-esp.yaml * Update compile-for-esp.yaml * Update compile-for-esp.yaml * Update compile-examples.yml * Delete compile-for-esp.yaml --- .github/workflows/compile-examples.yml | 33 ++++++ library.properties | 2 +- src/utility/HCIUartTransport.cpp | 2 +- src/utility/HCIVirtualTransport.cpp | 142 +++++++++++++++++++++++++ src/utility/HCIVirtualTransport.h | 50 +++++++++ 5 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 src/utility/HCIVirtualTransport.cpp create mode 100644 src/utility/HCIVirtualTransport.h diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index a1faf997..b33d6c75 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -22,3 +22,36 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} + + build-for-esp32: + runs-on: ubuntu-latest + + strategy: + matrix: + fqbn: + - esp32:esp32:esp32 + - esp32:esp32:esp32s3 + - esp32:esp32:esp32c3 + # future bluetooth chips + #- esp32:esp32:esp32c2 + #- esp32:esp32:esp32c6 + #- esp32:esp32:esp32h2 + + steps: + - uses: actions/checkout@v3 + - uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.fqbn }} + platforms: | + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketch-paths: | + - examples/Central/Scan + - examples/Central/PeripheralExplorer + - examples/Central/ScanCallback + - examples/Central/SensorTagButton + - examples/Peripheral/Advertising/EnhancedAdvertising + - examples/Peripheral/Advertising/RawDataAdvertising + cli-compile-flags: | + - --warnings="none" diff --git a/library.properties b/library.properties index e2a3f15f..467d9eaf 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 101 paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32 includes=ArduinoBLE.h diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 37ce95e7..1b1a513a 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if !defined(ARDUINO_ARCH_MBED) || defined(TARGET_NANO_RP2040_CONNECT) +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) || defined(TARGET_NANO_RP2040_CONNECT) #include "HCIUartTransport.h" diff --git a/src/utility/HCIVirtualTransport.cpp b/src/utility/HCIVirtualTransport.cpp new file mode 100644 index 00000000..046a0e72 --- /dev/null +++ b/src/utility/HCIVirtualTransport.cpp @@ -0,0 +1,142 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(ESP32) + +#include "HCIVirtualTransport.h" + +StreamBufferHandle_t rec_buffer; +StreamBufferHandle_t send_buffer; +TaskHandle_t bleHandle; + + +static void notify_host_send_available(void) +{ +} + +static int notify_host_recv(uint8_t *data, uint16_t length) +{ + xStreamBufferSend(rec_buffer,data,length,portMAX_DELAY); // !!!potentially waiting forever + return 0; +} + +static esp_vhci_host_callback_t vhci_host_cb = { + notify_host_send_available, + notify_host_recv +}; + +void bleTask(void *pvParameters) +{ + esp_vhci_host_register_callback(&vhci_host_cb); + size_t length; + uint8_t mybuf[258]; + + while(true){ + length = xStreamBufferReceive(send_buffer,mybuf,258,portMAX_DELAY); + while (!esp_vhci_host_check_send_available()) {} + esp_vhci_host_send_packet(mybuf, length); + } +} + + +HCIVirtualTransportClass::HCIVirtualTransportClass() +{ +} + +HCIVirtualTransportClass::~HCIVirtualTransportClass() +{ +} + +int HCIVirtualTransportClass::begin() +{ + btStarted(); // this somehow stops the arduino ide from initializing bluedroid + + rec_buffer = xStreamBufferCreate(258, 1); + send_buffer = xStreamBufferCreate(258, 1); + + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + +#if CONFIG_IDF_TARGET_ESP32 + bt_cfg.mode = ESP_BT_MODE_BLE; //original esp32 chip +#else + bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE; //different api for newer models +#endif + + esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); + esp_bt_controller_init(&bt_cfg); + esp_bt_controller_enable(ESP_BT_MODE_BLE); + xTaskCreatePinnedToCore(&bleTask, "bleTask", 2048, NULL, 5, &bleHandle, 0); + return 1; +} + +void HCIVirtualTransportClass::end() +{ + vStreamBufferDelete(rec_buffer); + vStreamBufferDelete(send_buffer); + esp_bt_controller_disable(); + esp_bt_controller_deinit(); + vTaskDelete(bleHandle); +} + +void HCIVirtualTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = (esp_timer_get_time() / 1000ULL); ((esp_timer_get_time() / 1000ULL) - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCIVirtualTransportClass::available() +{ + size_t bytes = xStreamBufferBytesAvailable(rec_buffer); + return bytes; +} + +// never called +int HCIVirtualTransportClass::peek() +{ + return -1; +} + +int HCIVirtualTransportClass::read() +{ + uint8_t c; + if(xStreamBufferReceive(rec_buffer, &c, 1, portMAX_DELAY)) { + return c; + } + return -1; +} + +size_t HCIVirtualTransportClass::write(const uint8_t* data, size_t length) +{ + size_t result = xStreamBufferSend(send_buffer,data,length,portMAX_DELAY); + return result; +} + +HCIVirtualTransportClass HCIVirtualTransport; + +HCITransportInterface& HCITransport = HCIVirtualTransport; + +#endif diff --git a/src/utility/HCIVirtualTransport.h b/src/utility/HCIVirtualTransport.h new file mode 100644 index 00000000..0da43cac --- /dev/null +++ b/src/utility/HCIVirtualTransport.h @@ -0,0 +1,50 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "HCITransport.h" +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/stream_buffer.h" + +#include "esp_bt.h" +#include "nvs_flash.h" + +#include "esp32-hal-bt.h" // this is needed to disable bluedroid + + +class HCIVirtualTransportClass : public HCITransportInterface { +public: + HCIVirtualTransportClass(); + virtual ~HCIVirtualTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); +}; \ No newline at end of file From cd9cbad71af82c939455b8ad446da766adc17a71 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti Date: Tue, 30 Aug 2022 11:55:17 +0200 Subject: [PATCH 053/112] Fix hard fault when str is NULL --- src/utility/BLEUuid.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utility/BLEUuid.cpp b/src/utility/BLEUuid.cpp index fba6244a..0465ea9a 100644 --- a/src/utility/BLEUuid.cpp +++ b/src/utility/BLEUuid.cpp @@ -30,6 +30,11 @@ BLEUuid::BLEUuid(const char * str) : memset(_data, 0x00, sizeof(_data)); _length = 0; + + if (str == NULL) { + return; + } + for (int i = strlen(str) - 1; i >= 0 && _length < BLE_UUID_MAX_LENGTH; i -= 2) { if (str[i] == '-') { i++; From 6e97bf2a3753ffff071b60a762f8178084f702b2 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 31 Aug 2022 18:05:06 +0200 Subject: [PATCH 054/112] Fix memory leak on end() -> begin() -> end() Only tested in Peripheral mode, with services and characteristics allocated: * as global objects (arduino way) * in function stack * in heap On mbed-enabled platforms, the memory check can be activated via ``` .... mbed_stats_heap_t heap_stats; mbed_stats_heap_get(&heap_stats); Serial.print("Heap size: "); Serial.print(heap_stats.current_size); Serial.print(" / "); Serial.println(heap_stats.reserved_size); .... ``` --- src/BLEService.cpp | 7 +++++++ src/BLEService.h | 1 + src/local/BLELocalAttribute.cpp | 5 +++++ src/local/BLELocalAttribute.h | 1 + src/local/BLELocalCharacteristic.cpp | 1 + src/local/BLELocalService.cpp | 9 +++++++-- src/local/BLELocalService.h | 1 + src/utility/GATT.cpp | 9 ++++++++- src/utility/GATT.h | 1 + 9 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/BLEService.cpp b/src/BLEService.cpp index b3f33739..ed54f9ff 100644 --- a/src/BLEService.cpp +++ b/src/BLEService.cpp @@ -63,6 +63,13 @@ BLEService::BLEService(const BLEService& other) } } +void BLEService::clear() +{ + if (_local) { + _local->clear(); + } +} + BLEService::~BLEService() { if (_local && _local->release() == 0) { diff --git a/src/BLEService.h b/src/BLEService.h index a8d8b010..5b2440d8 100644 --- a/src/BLEService.h +++ b/src/BLEService.h @@ -33,6 +33,7 @@ class BLEService { virtual ~BLEService(); const char* uuid() const; + void clear(); void addCharacteristic(BLECharacteristic& characteristic); diff --git a/src/local/BLELocalAttribute.cpp b/src/local/BLELocalAttribute.cpp index ce3010a0..9929fa41 100644 --- a/src/local/BLELocalAttribute.cpp +++ b/src/local/BLELocalAttribute.cpp @@ -56,6 +56,11 @@ int BLELocalAttribute::retain() return _refCount; } +bool BLELocalAttribute::active() +{ + return _refCount > 0; +} + int BLELocalAttribute::release() { _refCount--; diff --git a/src/local/BLELocalAttribute.h b/src/local/BLELocalAttribute.h index 2af948c3..53a0abfe 100644 --- a/src/local/BLELocalAttribute.h +++ b/src/local/BLELocalAttribute.h @@ -44,6 +44,7 @@ class BLELocalAttribute int retain(); int release(); + bool active(); protected: friend class ATTClass; diff --git a/src/local/BLELocalCharacteristic.cpp b/src/local/BLELocalCharacteristic.cpp index 63208b05..ef19e726 100644 --- a/src/local/BLELocalCharacteristic.cpp +++ b/src/local/BLELocalCharacteristic.cpp @@ -46,6 +46,7 @@ BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permis if (permissions & (BLENotify | BLEIndicate)) { BLELocalDescriptor* cccd = new BLELocalDescriptor("2902", (uint8_t*)&_cccdValue, sizeof(_cccdValue)); + cccd->retain(); _descriptors.add(cccd); } diff --git a/src/local/BLELocalService.cpp b/src/local/BLELocalService.cpp index 58957342..7fda3cb4 100644 --- a/src/local/BLELocalService.cpp +++ b/src/local/BLELocalService.cpp @@ -28,6 +28,12 @@ BLELocalService::BLELocalService(const char* uuid) : { } +void BLELocalService::clear() { + _characteristics.clear(); + _startHandle = 0; + _endHandle = 0; +} + BLELocalService::~BLELocalService() { for (unsigned int i = 0; i < characteristicCount(); i++) { @@ -37,8 +43,7 @@ BLELocalService::~BLELocalService() delete c; } } - - _characteristics.clear(); + clear(); } enum BLEAttributeType BLELocalService::type() const diff --git a/src/local/BLELocalService.h b/src/local/BLELocalService.h index e0179a93..f17c610c 100644 --- a/src/local/BLELocalService.h +++ b/src/local/BLELocalService.h @@ -36,6 +36,7 @@ class BLELocalService : public BLELocalAttribute { virtual enum BLEAttributeType type() const; void addCharacteristic(BLECharacteristic& characteristic); + void clear(); protected: friend class ATTClass; diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index 98d5f4ad..be914f6f 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -149,6 +149,7 @@ void GATTClass::addService(BLELocalService* service) { service->retain(); _attributes.add(service); + _services.add(service); uint16_t startHandle = attributeCount(); @@ -160,6 +161,7 @@ void GATTClass::addService(BLELocalService* service) characteristic->setHandle(attributeCount()); // add the characteristic again to make space of the characteristic value handle + characteristic->retain(); _attributes.add(characteristic); for (unsigned int j = 0; j < characteristic->descriptorCount(); j++) { @@ -183,8 +185,13 @@ void GATTClass::clearAttributes() delete a; } } - _attributes.clear(); + + for (unsigned int i = 0; i < _services.size(); i++) { + _services.get(i)->clear(); + } + _services.clear(); + } #if !defined(FAKE_GATT) diff --git a/src/utility/GATT.h b/src/utility/GATT.h index fd916709..51d1537e 100644 --- a/src/utility/GATT.h +++ b/src/utility/GATT.h @@ -59,6 +59,7 @@ class GATTClass { private: BLELinkedList _attributes; + BLELinkedList _services; BLELocalService* _genericAccessService; BLELocalCharacteristic* _deviceNameCharacteristic; From b5fc368db01e67fc706e231d5fd70ee4ec50353d Mon Sep 17 00:00:00 2001 From: BBear <13687227078@163.com> Date: Wed, 31 Aug 2022 19:13:15 +0200 Subject: [PATCH 055/112] fix the potential overflow problem of leAdvertisingReport->eirData --- src/utility/HCI.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index bc7bc2da..1902abe7 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -1116,6 +1116,10 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t eirData[31]; } *leAdvertisingReport = (EvtLeAdvertisingReport*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; + if(leAdvertisingReport->eirLength > sizeof(leAdvertisingReport->eirData)){ + return ; + } + if (leAdvertisingReport->status == 0x01) { // last byte is RSSI int8_t rssi = leAdvertisingReport->eirData[leAdvertisingReport->eirLength]; From dd56eb7e13213a477ad57171c2e334897892fad0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 5 Sep 2022 14:43:17 +0200 Subject: [PATCH 056/112] Release 1.3.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 467d9eaf..0648b56a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.3.1 +version=1.3.2 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From 07d249acb64f07b2fa338355c7852d519d328b72 Mon Sep 17 00:00:00 2001 From: Steve Allasia <40604011+sallasia@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:07:44 +0200 Subject: [PATCH 057/112] Fix BLE scanning block after few minutes --- src/utility/GAP.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index f3ee32fa..08c9c3f0 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -22,7 +22,7 @@ #include "GAP.h" -#define GAP_MAX_DISCOVERED_QUEUE_SIZE 5 +#define GAP_MAX_DISCOVERED_QUEUE_SIZE 32 #define GAP_ADV_IND (0x00) #define GAP_ADV_SCAN_IND (0x02) @@ -86,8 +86,14 @@ int GAPClass::scan(bool withDuplicates) { HCI.leSetScanEnable(false, true); - // active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter - if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) { + // active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter + /* + Warning (from BLUETOOTH SPECIFICATION 5.x): + - scan interval: mandatory range from 0x0012 to 0x1000; only even values are valid + - scan window: mandatory range from 0x0011 to 0x1000 + - The scan window can only be less than or equal to the scan interval + */ + if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) { return false; } @@ -216,8 +222,11 @@ void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint if (discoveredDevice == NULL) { if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) { - // drop - return; + // delete data in first list posistion + BLEDevice* device_first = _discoveredDevices.remove(0); + if (device_first != NULL) { + delete device_first; + } } discoveredDevice = new BLEDevice(addressType, address); From c928892cc1eb89de2a112bdf0844fc5252067ccc Mon Sep 17 00:00:00 2001 From: Steve Allasia <40604011+sallasia@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:26:48 +0200 Subject: [PATCH 058/112] Update GAP.cpp Removed comment --- src/utility/GAP.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index 08c9c3f0..f1bf02fe 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -222,7 +222,6 @@ void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint if (discoveredDevice == NULL) { if (_discoveredDevices.size() >= GAP_MAX_DISCOVERED_QUEUE_SIZE) { - // delete data in first list posistion BLEDevice* device_first = _discoveredDevices.remove(0); if (device_first != NULL) { delete device_first; From 1ec7d0046e20a8c78cf40d4bec5bbadfa4bb27bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 08:41:37 +0000 Subject: [PATCH 059/112] Bump geekyeggo/delete-artifact from 1 to 2 Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 1 to 2. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v1...v2) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 986bda6f..10abaeac 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v1 + uses: geekyeggo/delete-artifact@v2 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 8ae816ce7b45b801d58ec30241a6405fd3b3b4eb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:23:57 +0000 Subject: [PATCH 060/112] Bump carlosperate/download-file-action from 1 to 2 Bumps [carlosperate/download-file-action](https://github.com/carlosperate/download-file-action) from 1 to 2. - [Release notes](https://github.com/carlosperate/download-file-action/releases) - [Commits](https://github.com/carlosperate/download-file-action/compare/v1...v2) --- updated-dependencies: - dependency-name: carlosperate/download-file-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 10abaeac..94938f35 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -31,7 +31,7 @@ jobs: - name: Download JSON schema for labels configuration file id: download-schema - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json location: ${{ runner.temp }}/label-configuration-schema @@ -65,7 +65,7 @@ jobs: steps: - name: Download - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} From f852716d0bab16a5d0f87b0dc1bace871a38a686 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 10 Mar 2023 15:11:01 +0100 Subject: [PATCH 061/112] Add compatibility with Giga --- library.properties | 2 +- src/local/BLELocalDevice.cpp | 8 ++++++-- src/utility/HCICordioTransport.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/library.properties b/library.properties index 0648b56a..9135fc90 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 101 paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32 +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga includes=ArduinoBLE.h diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 91cc8695..20de8222 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -33,6 +33,10 @@ #ifndef BT_REG_ON #define BT_REG_ON PF_14 #endif +#elif defined(ARDUINO_GIGA) +#ifndef BT_REG_ON +#define BT_REG_ON PA_10 +#endif #endif BLELocalDevice::BLELocalDevice() @@ -65,7 +69,7 @@ int BLELocalDevice::begin() delay(100); digitalWrite(NINA_RESETN, HIGH); delay(750); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, HIGH); @@ -195,7 +199,7 @@ void BLELocalDevice::end() #elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) // disable the NINA digitalWrite(NINA_RESETN, LOW); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) digitalWrite(BT_REG_ON, LOW); #endif } diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 4dc8d45e..0e67dae7 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -25,7 +25,7 @@ #include #include -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) #include "ble/BLE.h" #include #endif @@ -181,7 +181,7 @@ HCICordioTransportClass::~HCICordioTransportClass() { } -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { eventQueue.call(mbed::Callback(&context->ble, &BLE::processEvents)); @@ -201,7 +201,7 @@ int HCICordioTransportClass::begin() init_wsf(bufPoolDesc); #endif -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) BLE &ble = BLE::Instance(); ble.onEventsToProcess(scheduleMbedBleEvents); @@ -235,7 +235,7 @@ void HCICordioTransportClass::end() bleLoopThread = NULL; } -#if !defined(ARDUINO_PORTENTA_H7_M4) && !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) CordioHCIHook::getDriver().terminate(); #endif From 289d3d6335a3f85581fa937d148b0d72958cdc5d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 10 Mar 2023 15:11:23 +0100 Subject: [PATCH 062/112] Publish version 1.3.3 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9135fc90..547ddb7d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.3.2 +version=1.3.3 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From a263bc760a0773eaad1ba3fa862726ee8ce3592b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 27 Mar 2023 14:38:23 +0200 Subject: [PATCH 063/112] Restore logic for end() on STM32H7 boards (1DX module) Amends https://github.com/arduino-libraries/ArduinoBLE/commit/f852716d0bab16a5d0f87b0dc1bace871a38a686 and fixes https://github.com/arduino-libraries/ArduinoBLE/issues/292 --- src/utility/HCICordioTransport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 0e67dae7..e78a44ea 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -235,7 +235,7 @@ void HCICordioTransportClass::end() bleLoopThread = NULL; } -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#if !defined(TARGET_STM32H7) CordioHCIHook::getDriver().terminate(); #endif From 55e7bb6a625f8ef8fab2a72e21ab1185dfcd70c0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 27 Mar 2023 14:39:44 +0200 Subject: [PATCH 064/112] Publish 1.3.4 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 547ddb7d..3da861aa 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.3.3 +version=1.3.4 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. From 9aa695e95ef1fe39884bd49f8810afd50dcda01f Mon Sep 17 00:00:00 2001 From: Joso Eterovic Date: Sun, 28 May 2023 21:55:01 -0700 Subject: [PATCH 065/112] Fix warnings: - Reorder member initialization on BLELocalCharacteristic - Remove unused variables in: - HCIClass::tryResolveAddress - HCIClass::handleEventPkt (the whole else if statement did nothing) - L2CAPSignalingClass::handleSecurityData (one initialization should be inside of _BLE_TRACE_ - BluetoothCryptoToolbox::f5 - BluetoothCryptoToolbox::testAh - BluetoothCryptoToolbox::testg2 - Uninitialized variable in L2CAPSignalingClass::handleSecurityData --- src/local/BLELocalCharacteristic.cpp | 4 ++-- src/utility/HCI.cpp | 34 +--------------------------- src/utility/L2CAPSignaling.cpp | 9 ++------ src/utility/btct.cpp | 12 ---------- 4 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/local/BLELocalCharacteristic.cpp b/src/local/BLELocalCharacteristic.cpp index ef19e726..207425bd 100644 --- a/src/local/BLELocalCharacteristic.cpp +++ b/src/local/BLELocalCharacteristic.cpp @@ -32,14 +32,14 @@ BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) : BLELocalAttribute(uuid), _properties((uint8_t)(permissions&0x000FF)), + _permissions((uint8_t)((permissions&0xFF00)>>8)), _valueSize(min(valueSize, 512)), _valueLength(0), _fixedLength(fixedLength), _handle(0x0000), _broadcast(false), _written(false), - _cccdValue(0x0000), - _permissions((uint8_t)((permissions&0xFF00)>>8)) + _cccdValue(0x0000) { memset(_eventHandlers, 0x00, sizeof(_eventHandlers)); diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 1902abe7..af9ffad8 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -554,15 +554,12 @@ int HCIClass::readStoredLK(uint8_t BD_ADDR[], uint8_t read_all ){ int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){ uint8_t iphone[16] = {0xA6, 0xD2, 0xD, 0xD3, 0x4F, 0x13, 0x42, 0x4F, 0xE1, 0xC1, 0xFD, 0x22, 0x2E, 0xC5, 0x6A, 0x2D}; - uint8_t irk[16]; - for(int i=0; i<16; i++) irk[15-i] = iphone[i]; bool foundMatch = false; if(HCI._getIRKs!=0){ uint8_t nIRKs = 0; uint8_t** BDAddrType = new uint8_t*; uint8_t*** BADDRs = new uint8_t**; uint8_t*** IRKs = new uint8_t**; - uint8_t* memcheck; if(!HCI._getIRKs(&nIRKs, BDAddrType, BADDRs, IRKs)){ @@ -971,33 +968,12 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) data += 2; } } - else if(eventHdr->evt == EVT_RETURN_LINK_KEYS) - { - uint8_t num_keys = (uint8_t)pdata[sizeof(HCIEventHdr)]; - // Serial.print("N keys: "); - // Serial.println(num_keys); - uint8_t BD_ADDRs[num_keys][6]; - uint8_t LKs[num_keys][16]; - auto nAddresss = [pdata](uint8_t nAddr)->uint8_t*{ - return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + nAddr*6 + nAddr*16; - }; - auto nLK = [pdata](uint8_t nLK)->uint8_t*{ - return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + (nLK+1)*6 + nLK*16; - }; - // Serial.println("Stored LKs are: "); - // for(int i=0; ievt == 0x10) { +#ifdef _BLE_TRACE_ struct __attribute__ ((packed)) CmdHardwareError { uint8_t hardwareCode; } *cmdHardwareError = (CmdHardwareError*)&pdata[sizeof(HCIEventHdr)]; -#ifdef _BLE_TRACE_ Serial.print("Bluetooth hardware error."); Serial.print(" Code: 0x"); Serial.println(cmdHardwareError->hardwareCode, HEX); @@ -1096,9 +1072,6 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) leConnectionComplete->supervisionTimeout, leConnectionComplete->masterClockAccuracy); } - uint8_t address[6]; - uint8_t BDAddr[6]; - for(int i=0; i<6; i++) BDAddr[5-i] = leConnectionComplete->peerBdaddr[i]; // leReadPeerResolvableAddress(leConnectionComplete->peerBdaddrType,BDAddr,address); // Serial.print("Resolving address: "); // btct.printBytes(BDAddr, 6); @@ -1325,11 +1298,6 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) // Send Pairing confirm response HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(pairingConfirm), &pairingConfirm); - // Start calculating DH Key - uint8_t remotePublicKeyReversed[sizeof(HCI.remotePublicKeyBuffer)]; - for(int i=0; ireason,HEX); #endif @@ -293,7 +293,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t } *identityAddress = (IdentityAddress*)data; // we can save this information now. uint8_t peerAddress[6]; - for(int i; i<6; i++) peerAddress[5-i] = identityAddress->address[i]; + for(int i=0; i<6; i++) peerAddress[5-i] = identityAddress->address[i]; HCI.saveNewAddress(identityAddress->addressType, peerAddress, ATT.peerIRK, ATT.localIRK); if(HCI._storeLTK!=0){ @@ -315,11 +315,6 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t }; memcpy(generateDHKeyCommand.x,connectionPairingPublicKey->x,32); memcpy(generateDHKeyCommand.y,connectionPairingPublicKey->y,32); - struct __attribute__ ((packed)) ReadPublicKeyCommand { - uint8_t code; - } readPublicKeyCommand = { - LE_COMMAND::READ_LOCAL_P256, - }; if(ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::REQUESTED_ENCRYPTION)){ #ifdef _BLE_TRACE_ diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index b4faf053..6829494c 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -60,16 +60,8 @@ int BluetoothCryptoToolbox::f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_sla printBytes(BD_ADDR_slave, ADDR_LEN); #endif - uint8_t ADD_M[7]; - uint8_t ADD_S[7]; uint8_t T[16]; - for(int i=0; i<6; i++){ - ADD_M[1+i] = BD_ADDR_master[i]; - ADD_M[0] = 0x00; - ADD_S[i+1] = BD_ADDR_slave[i]; - ADD_S[0] = 0x00; - } struct __attribute__ ((packed)) CmacInput { uint8_t counter; @@ -135,11 +127,8 @@ int BluetoothCryptoToolbox::ah(uint8_t k[16], uint8_t r[3], uint8_t* result) void BluetoothCryptoToolbox::testAh() { uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b}; - uint8_t r[3] = {0x70,0x81,0x94}; - uint8_t expected_AES[16] = {0x15,0x9d,0x5f,0xb7,0x2e,0xbe,0x23,0x11,0xa4,0x8c,0x1b,0xdc,0xc4,0x0d,0xfb,0xaa}; uint8_t expected_final[3] = {0x0d,0xfb,0xaa}; - for(int i=0; i<3; i++) r[2-i] = expected_final[3+i]; uint8_t ourResult[3]; ah(irk, expected_final, ourResult); @@ -170,7 +159,6 @@ void BluetoothCryptoToolbox::testg2(){ uint8_t V[32] = {0x55,0x18,0x8b,0x3d,0x32,0xf6,0xbb,0x9a,0x90,0x0a,0xfc,0xfb,0xee,0xd4,0xe7,0x2a,0x59,0xcb,0x9a,0xc2,0xf1,0x9d,0x7c,0xfb,0x6b,0x4f,0xdd,0x49,0xf4,0x7f,0xc5,0xfd}; uint8_t X[16] = {0xd5,0xcb,0x84,0x54,0xd1,0x77,0x73,0x3e,0xff,0xff,0xb2,0xec,0x71,0x2b,0xae,0xab}; uint8_t Y[16] = {0xa6,0xe8,0xe7,0xcc,0x25,0xa7,0x5f,0x6e,0x21,0x65,0x83,0xf7,0xff,0x3d,0xc4,0xcf}; - uint8_t AES[16] = {0x15,0x36,0xd1,0x8d,0xe3,0xd2,0x0d,0xf9,0x9b,0x70,0x44,0xc1,0x2f,0x9e,0xd5,0xba}; uint8_t out[4]; From 1dfbf629d6b86d9e58a594d3588d5d0850783856 Mon Sep 17 00:00:00 2001 From: Joso Eterovic Date: Sun, 28 May 2023 21:58:22 -0700 Subject: [PATCH 066/112] Remove another unused variable --- src/utility/HCI.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index af9ffad8..e9743758 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -553,7 +553,6 @@ int HCIClass::readStoredLK(uint8_t BD_ADDR[], uint8_t read_all ){ } int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){ - uint8_t iphone[16] = {0xA6, 0xD2, 0xD, 0xD3, 0x4F, 0x13, 0x42, 0x4F, 0xE1, 0xC1, 0xFD, 0x22, 0x2E, 0xC5, 0x6A, 0x2D}; bool foundMatch = false; if(HCI._getIRKs!=0){ uint8_t nIRKs = 0; From 0ad2d7dce3ec9d3541c09fe9404dab97d8c02073 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 4 Apr 2023 18:51:34 +0200 Subject: [PATCH 067/112] Support C33 --- src/local/BLELocalDevice.cpp | 20 ++++++++++++++++++++ src/utility/HCIUartTransport.cpp | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 20de8222..79e43bf5 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -73,6 +73,26 @@ int BLELocalDevice::begin() // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, HIGH); +#elif defined(ARDUINO_PORTENTA_C33) +#define NINA_GPIO0 (100) +#define NINA_RESETN (101) + pinMode(NINA_GPIO0, OUTPUT); + pinMode(NINA_RESETN, OUTPUT); + Serial5.begin(921600); + + digitalWrite(NINA_GPIO0, HIGH); + delay(100); + digitalWrite(NINA_RESETN, HIGH); + digitalWrite(NINA_RESETN, LOW); + digitalWrite(NINA_RESETN, HIGH); + auto _start = millis(); + while (millis() - _start < 500) { + if (Serial5.available()) { + Serial5.read(); + } + } + //pinMode(94, OUTPUT); + //digitalWrite(94, LOW); #endif diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 1b1a513a..1cd44495 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -29,6 +29,8 @@ // SerialHCI is already defined in the variant #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #define SerialHCI Serial2 +#elif defined(ARDUINO_PORTENTA_C33) +#define SerialHCI Serial5 #else #error "Unsupported board selected!" #endif From 0753ec0fe43c22600df09c7b8eb7e7a0b870500b Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 2 Jul 2023 07:39:28 -0700 Subject: [PATCH 068/112] Fix broken image embed in documentation The file previously targeted by the embed has been lost or moved. Experience shows that this is is a common occurrence with the files hosted by Arduino, and will be especially problematic in cases like this where the file may appear to be superfluous to the website maintainers due to the lack of any internal references to it, so the only way to ensure the file will continue to be available is by hosting alongside the documentation content in the repository. I was able to recover the lost file from the Internet Archive Wayback Machine's 2023-06-18 archive of the previous URL: https://web.archive.org/web/20230618230604/https://www.arduino.cc/en/uploads/Reference/ble-bulletin-board-model.png The absolute URL of the file was intentionally used in the markup instead of what would normally be the best practices of using the relative path. The reason is because the documentation content will be published at https://reference.arduino.cc/reference/en/libraries/arduinoble/ and the publishing system doesn't have any capability for handling asset files. --- docs/assets/ble-bulletin-board-model.png | Bin 0 -> 41914 bytes docs/readme.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 docs/assets/ble-bulletin-board-model.png diff --git a/docs/assets/ble-bulletin-board-model.png b/docs/assets/ble-bulletin-board-model.png new file mode 100644 index 0000000000000000000000000000000000000000..409ae9e89385b0c27d8331f7d52fff2a8f71e097 GIT binary patch literal 41914 zcmc$`WmuJ6*Y6Fulu}Akx_f~%NO!1!(%nc)mz2`o9nzqHbayw>B_J)GO3ORf<#pfk zKF{8tw+C|ImeJM``iSO0Q>e14f#-o4#UEkWrsLaYH5>dnSzoQ4Est zRzUFgrEwC!FNuvwuVSRs3NIBvVJLx(`r*C7H1aWqLU)^@xWxKGs0H#tG3Uu*@=cHW z((Go<^sMQD$80S+m)lef_hE#!jtO*))Qp6OaJ zBuK^}4|6)vZ2d>C$>mYS>kEUYjIkXrmIGa$kDOLM3}?mj{$dj^0Z*-NmGmZRub60W zPkn0R%|*-X5{c*Q8-ZT8E9E1a-H~*W&~)`B%iSWDCS15*R2nJ770q$VaFtdMgx8mg z3wx#UHWAzCmvq{P=y; zBB4eozFw2dUie(JhyTexcok}85PNL|;KV5JQCSPQA$aU)Vmw9ZZEk#1 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#`M0;Q<|HPllJr0%X{|tI_2eNyBK`iAWQF>LG`+U)jxPY@uPYW zBJ9i^9rD_Sq!i^srzcU8KLJymkI9Zw7~k+P6XD;tz$@c}Ss~SKZ~Vro{UnummI%pM z18<|cXCq4#?tn9Xc~bkOMb177Vq{fZP8djR-&-kBP16?Q)_O>O?l8P(lw+7-6$7SO z`oPw+D4Wmk?3f@Uc_oB1muE@W{fU0Ve)X+Pocl1zRBn8^suw#s65JseWcMB>RFdM$w+LBnW^d zy;H$(R6LS-`3%9WFryfN$Y!lT0M~(cV2XRMbqg~0jJl28SP$!Eudvz5JukD*o4$Zcx83fBza*u8Uln&H=fXjt8BBoXTeU@5Rc;=ohhC z`iNEG!2A<1BmK);57&GzHJj-9w#EexY(#mn*#44}b?G*PfS zs;MEqRaOA%g6%1P?NJlnD`rS`?)dBdS?2DKxj}n}O| Date: Sun, 2 Jul 2023 07:46:33 -0700 Subject: [PATCH 069/112] Fix broken link in documentation The previous target of this link is no longer available. I found that there is no longer an authoritative web page that provides a list of standard GATT service UUIDs, equivalent to the previous target of that link: https://web.archive.org/web/20160305021019/https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx The Bluetooth Special Interest Group has since moved this information into the "Assigned Numbers" pdf, so I replaced the broken link with a link to the download page for that document and noted its location in that document. --- docs/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index 7451e015..5ba0dfb4 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -35,7 +35,7 @@ Just as with writing to a characteristic, you could update your characteristics ## Services, characteristics, and UUIDs -A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use [standard services](https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx). +A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use standard services (see section 3.4 in the [Assigned Numbers document](https://www.bluetooth.com/specifications/assigned-numbers/)). Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. From 8ca541559676bc88dce841a889d80ba557fb0399 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 11 Jul 2023 15:13:48 +0200 Subject: [PATCH 070/112] Update library.properties --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 3da861aa..a08e251c 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=ArduinoBLE -version=1.3.4 +version=1.3.5 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta includes=ArduinoBLE.h From c0cd781374c36bf1309529d09ad88c098fdbf45a Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Thu, 24 Aug 2023 11:49:50 +0200 Subject: [PATCH 071/112] Add support for OPTA --- library.properties | 2 +- src/local/BLELocalDevice.cpp | 6 +++--- src/utility/HCICordioTransport.cpp | 6 +++--- src/utility/HCIUartTransport.cpp | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/library.properties b/library.properties index a08e251c..929fa0fd 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 101 paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta includes=ArduinoBLE.h diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 79e43bf5..146d99b9 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -25,7 +25,7 @@ #include "BLELocalDevice.h" -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA) #ifndef BT_REG_ON #define BT_REG_ON PJ_12 #endif @@ -69,7 +69,7 @@ int BLELocalDevice::begin() delay(100); digitalWrite(NINA_RESETN, HIGH); delay(750); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, HIGH); @@ -219,7 +219,7 @@ void BLELocalDevice::end() #elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) // disable the NINA digitalWrite(NINA_RESETN, LOW); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) digitalWrite(BT_REG_ON, LOW); #endif } diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index e78a44ea..947378cf 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -25,7 +25,7 @@ #include #include -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) #include "ble/BLE.h" #include #endif @@ -181,7 +181,7 @@ HCICordioTransportClass::~HCICordioTransportClass() { } -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { eventQueue.call(mbed::Callback(&context->ble, &BLE::processEvents)); @@ -201,7 +201,7 @@ int HCICordioTransportClass::begin() init_wsf(bufPoolDesc); #endif -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) +#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) BLE &ble = BLE::Instance(); ble.onEventsToProcess(scheduleMbedBleEvents); diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 1cd44495..3219268d 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -29,6 +29,8 @@ // SerialHCI is already defined in the variant #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #define SerialHCI Serial2 +#elif defined(ARDUINO_OPTA) +#define SerialHCI Serial3 #elif defined(ARDUINO_PORTENTA_C33) #define SerialHCI Serial5 #else From 2a35e72af28904a247f01d4a18a6d1e5a1daea62 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 3 Jul 2023 20:03:55 +0200 Subject: [PATCH 072/112] wip: add support for UNO R4 WiFi Needs UNOR4USBBridge firmware >= 0.2.0 --- src/utility/HCIUartTransport.cpp | 2 +- src/utility/HCIVirtualTransportAT.cpp | 112 ++++++++++++++++++++++++++ src/utility/HCIVirtualTransportAT.h | 42 ++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/utility/HCIVirtualTransportAT.cpp create mode 100644 src/utility/HCIVirtualTransportAT.h diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 3219268d..d3c44d8f 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) || defined(TARGET_NANO_RP2040_CONNECT) +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) #include "HCIUartTransport.h" diff --git a/src/utility/HCIVirtualTransportAT.cpp b/src/utility/HCIVirtualTransportAT.cpp new file mode 100644 index 00000000..7b3a24a9 --- /dev/null +++ b/src/utility/HCIVirtualTransportAT.cpp @@ -0,0 +1,112 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(ARDUINO_UNOR4_WIFI) + +#include "HCIVirtualTransportAT.h" + +extern ModemClass modem; + +HCIVirtualTransportATClass::HCIVirtualTransportATClass() +{ +} + +HCIVirtualTransportATClass::~HCIVirtualTransportATClass() +{ +} + +static RingBufferN<258> buf; + +int HCIVirtualTransportATClass::begin() +{ + // TODO: add this helper + //modem.debug(Serial); + buf.clear(); + //modem.debug(true); + std::string res = ""; + modem.begin(); + if (modem.write(std::string(PROMPT(_HCI_BEGIN)), res, CMD(_HCI_BEGIN))) { + return 1; + } + return 0; +} + +void HCIVirtualTransportATClass::end() +{ +} + +void HCIVirtualTransportATClass::wait(unsigned long timeout) +{ + std::string res = ""; + modem.write(std::string(PROMPT(_HCI_WAIT)), res, "%d\n\r", CMD_WRITE(_HCI_WAIT), timeout); +} + +int HCIVirtualTransportATClass::available() +{ + std::string res = ""; + if (buf.available()) { + return buf.available(); + } + if (modem.write(std::string(PROMPT(_HCI_AVAILABLE)), res, CMD_READ(_HCI_AVAILABLE))) { + return atoi(res.c_str()); + } + + return 0; +} + +// never called +int HCIVirtualTransportATClass::peek() +{ + return -1; +} + +int HCIVirtualTransportATClass::read() +{ + uint8_t c; + std::string res = ""; + if (buf.available()) { + return buf.read_char(); + } + modem.avoid_trim_results(); + modem.read_using_size(); + if (modem.write(std::string(PROMPT(_HCI_READ)), res, CMD(_HCI_READ))) { + for(int i = 0; i < res.size(); i++) { + buf.store_char((uint8_t)res[i]); + } + return buf.read_char(); + } + + return -1; +} + +size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length) +{ + std::string res = ""; + modem.write_nowait(std::string(PROMPT(_HCI_WRITE)), res, "%s%d\r\n" , CMD_WRITE(_HCI_WRITE), length); + if(modem.passthrough(data, length)) { + return length; + } + return 0; +} + +HCIVirtualTransportATClass HCIVirtualTransportAT; + +HCITransportInterface& HCITransport = HCIVirtualTransportAT; + +#endif diff --git a/src/utility/HCIVirtualTransportAT.h b/src/utility/HCIVirtualTransportAT.h new file mode 100644 index 00000000..8e29801d --- /dev/null +++ b/src/utility/HCIVirtualTransportAT.h @@ -0,0 +1,42 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "HCITransport.h" +#include +#include +#include + +#include "WiFiS3.h" + +class HCIVirtualTransportATClass : public HCITransportInterface { +public: + HCIVirtualTransportATClass(); + virtual ~HCIVirtualTransportATClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); +}; \ No newline at end of file From 742ba783a17fce4ce8d3ddf8992573718f99d37f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 11 Jul 2023 09:30:29 +0200 Subject: [PATCH 073/112] unor4wifi: fix metadata and gh action --- .github/workflows/compile-examples.yml | 1 + README.md | 4 +++- library.properties | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b33d6c75..81e843dd 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -15,6 +15,7 @@ jobs: - arduino:megaavr:uno2018:mode=on - arduino:mbed:nano33ble - arduino:mbed_nano:nanorp2040connect + - arduino:renesas_uno:unor4wifi steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 9ec934a3..6808502c 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,14 @@ [![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) -Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. +Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. This library supports creating a Bluetooth® Low Energy peripheral & central mode. For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. +For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later. + For more information about this library please visit us at: https://www.arduino.cc/en/Reference/ArduinoBLE diff --git a/library.properties b/library.properties index 929fa0fd..718b6066 100644 --- a/library.properties +++ b/library.properties @@ -2,9 +2,9 @@ name=ArduinoBLE version=1.3.5 author=Arduino maintainer=Arduino -sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE and Nicla Sense ME. +sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno includes=ArduinoBLE.h From 56dbfb33aef47489cfbfb26a4e32c8e6d123c9ff Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 30 Aug 2023 14:43:44 +0200 Subject: [PATCH 074/112] Publish 1.3.6 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 718b6066..5f238fde 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoBLE -version=1.3.5 +version=1.3.6 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. From 304386172a90c47c474e6416151fb69c942ee846 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 08:16:41 +0000 Subject: [PATCH 075/112] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 4 ++-- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 81e843dd..7f2ed318 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -18,7 +18,7 @@ jobs: - arduino:renesas_uno:unor4wifi steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -39,7 +39,7 @@ jobs: #- esp32:esp32:esp32h2 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 0cbdde58..94b57020 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Spell check uses: arduino/actions/libraries/spell-check@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 94938f35..9cde1acc 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download configuration files artifact uses: actions/download-artifact@v3 From de0bcbbe5ef3522eb2c0652b99d5351212765e95 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 26 Oct 2023 17:06:06 +0200 Subject: [PATCH 076/112] Fix functionality on Giga CM4 core Requires https://github.com/arduino/ArduinoCore-mbed/pull/741 --- src/local/BLELocalDevice.cpp | 3 +++ src/utility/CordioHCICustomDriver.h | 17 +++++++++++++++++ src/utility/HCICordioTransport.cpp | 10 ++++++---- src/utility/HCIUartTransport.cpp | 4 +++- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/utility/CordioHCICustomDriver.h diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 146d99b9..be603364 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -72,7 +72,10 @@ int BLELocalDevice::begin() #elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); + digitalWrite(BT_REG_ON, LOW); + delay(500); digitalWrite(BT_REG_ON, HIGH); + delay(500); #elif defined(ARDUINO_PORTENTA_C33) #define NINA_GPIO0 (100) #define NINA_RESETN (101) diff --git a/src/utility/CordioHCICustomDriver.h b/src/utility/CordioHCICustomDriver.h new file mode 100644 index 00000000..fc062ee8 --- /dev/null +++ b/src/utility/CordioHCICustomDriver.h @@ -0,0 +1,17 @@ +#if defined(CORE_CM4) + +#include "CyH4TransportDriver.h" + +ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver() +{ + static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver( + /* TX */ CYBSP_BT_UART_TX, /* RX */ CYBSP_BT_UART_RX, + /* cts */ CYBSP_BT_UART_CTS, /* rts */ CYBSP_BT_UART_RTS, NC, DEF_BT_BAUD_RATE, + CYBSP_BT_HOST_WAKE, CYBSP_BT_DEVICE_WAKE + ); + return s_transport_driver; +} + +#define CUSTOM_HCI_DRIVER + +#endif \ No newline at end of file diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp index 947378cf..7848712f 100644 --- a/src/utility/HCICordioTransport.cpp +++ b/src/utility/HCICordioTransport.cpp @@ -17,8 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(ARDUINO_ARCH_MBED) && !defined(TARGET_NANO_RP2040_CONNECT) - +#if defined(ARDUINO_ARCH_MBED) && !defined(TARGET_NANO_RP2040_CONNECT) // && !defined(CORE_CM4) #include #include @@ -53,6 +52,8 @@ #define BLE_NAMESPACE ble::vendor::cordio #endif +#include "CordioHCICustomDriver.h" + extern BLE_NAMESPACE::CordioHCIDriver& ble_cordio_get_hci_driver(); namespace BLE_NAMESPACE { @@ -181,7 +182,7 @@ HCICordioTransportClass::~HCICordioTransportClass() { } -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) +#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { eventQueue.call(mbed::Callback(&context->ble, &BLE::processEvents)); @@ -201,7 +202,8 @@ int HCICordioTransportClass::begin() init_wsf(bufPoolDesc); #endif -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) +#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) + BLE &ble = BLE::Instance(); ble.onEventsToProcess(scheduleMbedBleEvents); diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index d3c44d8f..d6f9ec3e 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) #include "HCIUartTransport.h" @@ -33,6 +33,8 @@ #define SerialHCI Serial3 #elif defined(ARDUINO_PORTENTA_C33) #define SerialHCI Serial5 +#elif defined(ARDUINO_GIGA) +arduino::UART SerialHCI(CYBSP_BT_UART_TX, CYBSP_BT_UART_RX, CYBSP_BT_UART_RTS, CYBSP_BT_UART_CTS); #else #error "Unsupported board selected!" #endif From 93802d08dbf2e2b4e61bac8c4098eb502cc212e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 06:29:02 +0100 Subject: [PATCH 077/112] Bump actions/download-artifact from 3 to 4 (#336) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 9cde1acc..885a8ac0 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From 416506ef203dbbf3549ffabeb82ab96d1291ea6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 06:29:12 +0100 Subject: [PATCH 078/112] Bump actions/upload-artifact from 3 to 4 (#337) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 885a8ac0..2e1d6e05 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: | *.yaml From 37337ad2405109e573eaaafb49dfac4b6a5eec23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 06:29:28 +0100 Subject: [PATCH 079/112] Bump geekyeggo/delete-artifact from 2 to 4 (#340) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 2 to 4. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v2...v4) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 2e1d6e05..47ac50a4 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 99159f05e19b583e1464e3087fcbd7071f1e8ea4 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 21 Feb 2024 10:55:28 +0100 Subject: [PATCH 080/112] Portenta_H7_M4: provide the correct define Fixes #333 again (not only for Giga) --- src/local/BLELocalDevice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index be603364..1d1036be 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -25,7 +25,7 @@ #include "BLELocalDevice.h" -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA) +#if defined(PORTENTA_H7_PINS) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_OPTA) #ifndef BT_REG_ON #define BT_REG_ON PJ_12 #endif @@ -69,7 +69,7 @@ int BLELocalDevice::begin() delay(100); digitalWrite(NINA_RESETN, HIGH); delay(750); -#elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) +#elif defined(PORTENTA_H7_PINS) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) // BT_REG_ON -> HIGH pinMode(BT_REG_ON, OUTPUT); digitalWrite(BT_REG_ON, LOW); From 4a85fec0ae95462b2d96e824ff6fad6aae6e156a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 19 Mar 2024 14:45:48 +0100 Subject: [PATCH 081/112] CI: Add arduino/report-size-deltas action. (#354) This action comments on the pull request with a report on the resulting change in memory usage of the Arduino sketches compiled by the arduino/compile-sketches action. --- .github/workflows/compile-examples.yml | 83 ++++++++++++++++++++---- .github/workflows/report-size-deltas.yml | 24 +++++++ 2 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/report-size-deltas.yml diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 7f2ed318..706ccb4c 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -1,29 +1,86 @@ name: Compile Examples + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows on: - - push - - pull_request + push: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + pull_request: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: jobs: build: + name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest + env: + SKETCHES_REPORTS_PATH: sketches-reports + strategy: + fail-fast: false + matrix: - fqbn: - - arduino:samd:mkrwifi1010 - - arduino:samd:nano_33_iot - - arduino:megaavr:uno2018:mode=on - - arduino:mbed:nano33ble - - arduino:mbed_nano:nanorp2040connect - - arduino:renesas_uno:unor4wifi + board: + - fqbn: arduino:samd:mkrwifi1010 + platforms: | + - name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwifi1010 + - fqbn: arduino:samd:nano_33_iot + platforms: | + - name: arduino:samd + artifact-name-suffix: arduino-samd-nano_33_iot + - fqbn: arduino:megaavr:uno2018:mode=on + platforms: | + - name: arduino:megaavr + artifact-name-suffix: arduino-megaavr-uno2018 + - fqbn: arduino:mbed_nano:nano33ble + platforms: | + - name: arduino:mbed_nano + artifact-name-suffix: arduino-mbed_nano-nano33ble + - fqbn: arduino:mbed_nano:nanorp2040connect + platforms: | + - name: arduino:mbed_nano + artifact-name-suffix: arduino-mbed_nano-nanorp2040connect + - fqbn: arduino:renesas_uno:unor4wifi + platforms: | + - name: arduino:renesas_uno + artifact-name-suffix: arduino-renesas_uno-unor4wifi steps: - - uses: actions/checkout@v4 - - uses: arduino/compile-sketches@v1 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Compile examples + uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} - + fqbn: ${{ matrix.board.fqbn }} + platforms: ${{ matrix.board.platforms }} + libraries: | + # Install the library from the local path. + - source-path: ./ + sketch-paths: | + - examples + enable-deltas-report: true + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + + - name: Save sketches report as workflow artifact + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + path: ${{ env.SKETCHES_REPORTS_PATH }} + name: sketches-report-${{ matrix.board.artifact-name-suffix }} + build-for-esp32: runs-on: ubuntu-latest diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml new file mode 100644 index 00000000..39e2a0ad --- /dev/null +++ b/.github/workflows/report-size-deltas.yml @@ -0,0 +1,24 @@ +name: Report Size Deltas + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/report-size-deltas.yml" + schedule: + # Run at the minimum interval allowed by GitHub Actions. + # Note: GitHub Actions periodically has outages which result in workflow failures. + # In this event, the workflows will start passing again once the service recovers. + - cron: "*/5 * * * *" + workflow_dispatch: + repository_dispatch: + +jobs: + report: + runs-on: ubuntu-latest + steps: + - name: Comment size deltas reports to PRs + uses: arduino/report-size-deltas@v1 + with: + # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow + sketches-reports-source: ^sketches-report-.+ From 98ff550988912ffbaeb1d877970e9e05f1de0599 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:46:11 +0100 Subject: [PATCH 082/112] Bump geekyeggo/delete-artifact from 4 to 5 (#356) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 4 to 5. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 47ac50a4..53a9f54f 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v4 + uses: geekyeggo/delete-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 93315a9d727902b1a5c7dcf3f10ac280e07be20f Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis Date: Fri, 7 Jun 2024 17:01:30 +0200 Subject: [PATCH 083/112] add support for silabs core --- src/BLECharacteristic.cpp | 2 + src/BLEDevice.cpp | 2 + src/BLEService.cpp | 2 + src/utility/ATT.cpp | 2 + src/utility/HCISilabsTransport.cpp | 130 +++++++++++++++++++++++++++++ src/utility/HCISilabsTransport.h | 42 ++++++++++ src/utility/HCIUartTransport.cpp | 2 +- 7 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/utility/HCISilabsTransport.cpp create mode 100644 src/utility/HCISilabsTransport.h diff --git a/src/BLECharacteristic.cpp b/src/BLECharacteristic.cpp index cb9783ce..bfaee3ff 100644 --- a/src/BLECharacteristic.cpp +++ b/src/BLECharacteristic.cpp @@ -24,6 +24,8 @@ #include "BLECharacteristic.h" +extern "C" int strcasecmp(char const *a, char const *b); + BLECharacteristic::BLECharacteristic() : BLECharacteristic((BLELocalCharacteristic*)NULL) { diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index 5f64c1d6..e9ca9b99 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -25,6 +25,8 @@ #include "BLEDevice.h" +extern "C" int strcasecmp(char const *a, char const *b); + BLEDevice::BLEDevice() : _advertisementTypeMask(0), _eirDataLength(0), diff --git a/src/BLEService.cpp b/src/BLEService.cpp index ed54f9ff..88687b61 100644 --- a/src/BLEService.cpp +++ b/src/BLEService.cpp @@ -22,6 +22,8 @@ #include "BLEService.h" +extern "C" int strcasecmp(char const *a, char const *b); + BLEService::BLEService() : BLEService((BLELocalService*)NULL) { diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index acdf5a9f..b1796c90 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -34,6 +34,8 @@ #include "ATT.h" +extern "C" int strcasecmp(char const *a, char const *b); + #define ATT_OP_ERROR 0x01 #define ATT_OP_MTU_REQ 0x02 #define ATT_OP_MTU_RESP 0x03 diff --git a/src/utility/HCISilabsTransport.cpp b/src/utility/HCISilabsTransport.cpp new file mode 100644 index 00000000..135fd020 --- /dev/null +++ b/src/utility/HCISilabsTransport.cpp @@ -0,0 +1,130 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2024 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#if defined(ARDUINO_SILABS) + +#include "HCISilabsTransport.h" +#include "sl_string.h" + +extern "C" { +#include "sl_btctrl_linklayer.h" +#include "sl_hci_common_transport.h" +} + +extern "C" int strcasecmp(char const *a, char const *b) { + return sl_strcasecmp(a, b); +} + +static RingBufferN<512> buf; + +HCISilabsTransportClass::HCISilabsTransportClass() +{ +} + +HCISilabsTransportClass::~HCISilabsTransportClass() +{ +} + +int HCISilabsTransportClass::begin() +{ + if(!sl_btctrl_is_initialized()) { + sl_bt_controller_init(); + } + + /* Initialize adv & scan components */ + sl_btctrl_init_adv(); + sl_btctrl_init_scan(); + sl_btctrl_init_conn(); + sl_btctrl_init_adv_ext(); + sl_btctrl_init_scan_ext(); + + /* Initialize HCI controller */ + sl_bthci_init_upper(); + sl_btctrl_hci_parser_init_default(); + sl_btctrl_hci_parser_init_conn(); + sl_btctrl_hci_parser_init_adv(); + sl_btctrl_hci_parser_init_phy(); + + return 1; +} + +void HCISilabsTransportClass::end() +{ + sl_bt_controller_deinit(); +} + +void HCISilabsTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISilabsTransportClass::available() +{ + return buf.available(); +} + +int HCISilabsTransportClass::peek() +{ + return buf.peek(); +} + +int HCISilabsTransportClass::read() +{ + return buf.read_char(); +} + +size_t HCISilabsTransportClass::write(const uint8_t* data, size_t len) +{ + int ret = 0; + ret = hci_common_transport_receive((uint8_t *)data, len, true); + + if (ret == 0) return len; + + return 0; +} + +extern "C" { + /** + * @brief Transmit HCI message using the currently used transport layer. + * The HCI calls this function to transmit a full HCI message. + * @param[in] data Packet type followed by HCI packet data. + * @param[in] len Length of the `data` parameter + * @return 0 - on success, or non-zero on failure. + */ + uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len) + { + for (int i = 0; i < len; i++) { + buf.store_char(data[i]); + if (buf.isFull()) return SL_STATUS_FAIL; + } + + sl_btctrl_hci_transmit_complete(0); + return 0; + } +} + +HCISilabsTransportClass HCISilabsTransport; + +HCITransportInterface& HCITransport = HCISilabsTransport; + +#endif diff --git a/src/utility/HCISilabsTransport.h b/src/utility/HCISilabsTransport.h new file mode 100644 index 00000000..2061e782 --- /dev/null +++ b/src/utility/HCISilabsTransport.h @@ -0,0 +1,42 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SILABS_TRANSPORT_H_ +#define _HCI_SILABS_TRANSPORT_H_ + +#include "HCITransport.h" + +class HCISilabsTransportClass : public HCITransportInterface { +public: + HCISilabsTransportClass(); + virtual ~HCISilabsTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); +}; + +#endif \ No newline at end of file diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index d6f9ec3e..191811a7 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_SILABS) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) #include "HCIUartTransport.h" From 29bef40e214b96dfe0a9043d791ae15b3934cd19 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:24:40 +0200 Subject: [PATCH 084/112] Publish 1.3.7 --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 5f238fde..543998b7 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=ArduinoBLE -version=1.3.6 +version=1.3.7 author=Arduino maintainer=Arduino sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno +architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno,silabs includes=ArduinoBLE.h From 910dd44389ea5b00a1e09cbdf4ae7a041e6ee2b5 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 4 Sep 2024 16:18:56 +0200 Subject: [PATCH 085/112] clear advertising data when BLE end is called --- src/local/BLELocalDevice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 1d1036be..5792353f 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -224,7 +224,9 @@ void BLELocalDevice::end() digitalWrite(NINA_RESETN, LOW); #elif defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) digitalWrite(BT_REG_ON, LOW); -#endif +#endif + _advertisingData.clear(); + _scanResponseData.clear(); } void BLELocalDevice::poll() From 5a531356080351ac03ea0258d82d3842f23db5d8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 4 Feb 2025 18:16:56 -0800 Subject: [PATCH 086/112] Modernize spell checking infrastructure The repository contains a CI workflow to check for commonly misspelled words in the project files. This is done using the "codespell" tool. A GitHub Actions action handles the installation and execution of the tool. At the time Arduino started setting up such infrastructure in project repositories, no such action was available and so Arduino created an action. Since that time, the codespell developers created an equivalent action and so Arduino's action was abandoned. Most of the libraries were migrated to the new action, but somehow this repository is still using the abandoned action. Due to bit rot, Arduino's action now fails to initialize: ``` #8 [3/4] RUN pip3 install codespell #8 0.401 error: externally-managed-environment [...] ERROR: failed to solve: process "/bin/sh -c pip3 install codespell" did not complete successfully: exit code: 1 Error: Docker build failed with exit code 1 ``` The problem is solved by migrating the spell check workflow to using the codespell action. --- .codespellrc | 9 +++++++++ .github/workflows/spell-check.yml | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .codespellrc diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 00000000..cffc2173 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,9 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check/.codespellrc +# See: https://github.com/codespell-project/codespell#using-a-config-file +[codespell] +# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: +ignore-words-list = , +skip = ./.git,./.licenses,__pycache__,node_modules,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock,./extras/test +builtin = clear,informal,en-GB_to_en-US +check-filenames = +check-hidden = diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 94b57020..6faf09c8 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -1,16 +1,25 @@ +# Source: https://github.com/per1234/.github/blob/main/workflow-templates/spell-check.md name: Spell Check -on: [push, pull_request] +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: jobs: - build: + spellcheck: runs-on: ubuntu-latest + permissions: + contents: read steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - name: Spell check - uses: arduino/actions/libraries/spell-check@master - with: - skip-paths: ./extras/test \ No newline at end of file + uses: codespell-project/actions-codespell@v2 From 0178fdfc2cdb101a08d30a6481c621e78f5bc5ee Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 4 Feb 2025 19:03:19 -0800 Subject: [PATCH 087/112] Fix typos The "codespell" spellchecker tool is used to automatically detect commonly misspelled words in the files of this project. The misspelled words dictionary was expanded in recent releases of codespell, which resulted in the detection of misspelled words in the project files: > Error: ./src/utility/HCI.cpp:761: Signalling ==> Signaling > Error: ./docs/readme.md:22: acknowledgement ==> acknowledgment The typos are hereby corrected, which will restore the spell check to a passing state. --- I supplemented the correction of the automatically detected typos with a general review of the project content, fixing the additional typos I identified during that review. --- CHANGELOG | 2 +- README.md | 4 +- docs/api.md | 143 +++++++----------- docs/readme.md | 8 +- .../SensorTagButton/SensorTagButton.ino | 2 +- .../RawDataAdvertising/RawDataAdvertising.ino | 6 +- .../BatteryMonitor/BatteryMonitor.ino | 4 +- .../Peripheral/CallbackLED/CallbackLED.ino | 2 +- .../EncryptedBatteryMonitor.ino | 22 +-- examples/Peripheral/LED/LED.ino | 2 +- library.properties | 2 +- src/utility/HCI.cpp | 51 +++---- 12 files changed, 103 insertions(+), 145 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a29f8598..d8a84716 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ ArduinoBLE ?.?.? - ????.??.?? ArduinoBLE 1.1.2 - 2019.11.12 -* cordio: switch to lower power when polling with timeout +* cordio: switch to lower power when polling with timeout * Fixed issue with wrong types for disconnection event handling. Thanks @cparata ArduinoBLE 1.1.1 - 2019.09.05 diff --git a/README.md b/README.md index 6808502c..b0027583 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ [![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) -Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. +Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. This library supports creating a Bluetooth® Low Energy peripheral & central mode. -For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. +For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later. diff --git a/docs/api.md b/docs/api.md index 636fe52c..c9f41840 100644 --- a/docs/api.md +++ b/docs/api.md @@ -80,7 +80,7 @@ Poll for Bluetooth® Low Energy radio events and handle them. #### Syntax ``` -BLE.poll() +BLE.poll() BLE.poll(timeout) ``` @@ -100,7 +100,6 @@ Nothing BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - BLE.poll(); @@ -142,7 +141,6 @@ Nothing. BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - void blePeripheralConnectHandler(BLEDevice central) { @@ -176,7 +174,7 @@ BLE.connected() None #### Returns -- **true** if another Bluetooth® Low Energy device is connected, +- **true** if another Bluetooth® Low Energy device is connected, - otherwise **false**. #### Example @@ -208,7 +206,7 @@ BLE.disconnect() None #### Returns -- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, +- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, - otherwise **false**. #### Example @@ -216,8 +214,6 @@ None ```arduino if (BLE.connected()) { - - BLE.disconnect(); } @@ -246,9 +242,9 @@ None ```arduino - **String** address = BLE.address(); + String address = BLE.address(); - Serial.print(“Local address is: “); + Serial.print("Local address is: "); Serial.println(address); @@ -277,9 +273,7 @@ None ```arduino if (BLE.connected()) { - - - Serial.print(“RSSI = “); + Serial.print("RSSI = "); Serial.println(BLE.rssi()); } @@ -315,9 +309,9 @@ Nothing while (1); } - BLE.setAdvertisedServiceUuid(“19B10000-E8F2-537E-4F6C-D104768A1214"); + BLE.setAdvertisedServiceUuid("19B10000-E8F2-537E-4F6C-D104768A1214"); - // ... + // ... // start advertising BLE.advertise(); @@ -360,7 +354,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Lo BLE.setAdvertisedService(ledService); - // ... + // ... // start advertising BLE.advertise(); @@ -402,7 +396,7 @@ Nothing BLE.setManufacturerData(data, 5); - // ... + // ... // start advertising BLE.advertise(); @@ -442,7 +436,7 @@ Nothing BLE.setLocalName("LED"); - // ... + // ... // start advertising BLE.advertise(); @@ -453,7 +447,7 @@ Nothing ### `BLE.setDeviceName()` -Set the device name in the built in device name characteristic. If not set, the value defaults “Arduino”. +Set the device name in the built in device name characteristic. If not set, the value defaults to “Arduino”. #### Syntax @@ -482,7 +476,7 @@ Nothing BLE.setDeviceName("LED"); - // ... + // ... // start advertising BLE.advertise(); @@ -493,7 +487,7 @@ Nothing ### `BLE.setAppearance()` -Set the appearance in the built in appearance characteristic. If not set, the value defaults 0x0000. +Set the appearance in the built in appearance characteristic. If not set, the value defaults to 0x0000. #### Syntax @@ -522,7 +516,7 @@ Nothing BLE.setAppearance(0x8000); - // ... + // ... // start advertising BLE.advertise(); @@ -568,7 +562,7 @@ BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Lo BLE.addService(ledService); - // ... + // ... ``` @@ -607,7 +601,7 @@ None BLE.advertise(); - // ... + // ... ``` @@ -645,7 +639,7 @@ Nothing BLE.advertise(); - // ... + // ... BLE.stopAdvertise(); @@ -682,8 +676,6 @@ None Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); - - } @@ -820,7 +812,7 @@ BLE.scan(withDuplicates) - **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered #### Returns -- 1 on success, +- 1 on success, - 0 on failure. #### Example @@ -839,7 +831,6 @@ BLE.scan(withDuplicates) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -887,7 +878,6 @@ BLE.scanForName(name, withDuplicates) // start scanning for peripheral BLE.scanForName("LED"); - BLEDevice peripheral = BLE.available(); @@ -916,7 +906,7 @@ BLE.scanForAddress(address, withDuplicates) - **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered #### Returns -- 1 on success, +- 1 on success, - 0 on failure. #### Example @@ -935,7 +925,6 @@ BLE.scanForAddress(address, withDuplicates) // start scanning for peripheral BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); - BLEDevice peripheral = BLE.available(); @@ -983,7 +972,6 @@ BLE.scanForUuid(uuid, withDuplicates) // start scanning for peripheral BLE.scanForUuid("aa10"); - BLEDevice peripheral = BLE.available(); @@ -1028,7 +1016,6 @@ Nothing // start scanning for peripheral BLE.scan(); - BLE.stopScan(); @@ -1068,7 +1055,6 @@ Nothing // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1111,8 +1097,6 @@ Nothing // if a central is connected to peripheral: if (central) { - - central.poll(); // ... @@ -1182,7 +1166,6 @@ None // listen for Bluetooth® Low Energy centrals to connect: BLEDevice central = BLE.central(); - central.disconnect(); @@ -1219,8 +1202,6 @@ None Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); - - . } @@ -1249,9 +1230,7 @@ None ```arduino if (bleDevice.connected()) { - - - Serial.print(“RSSI = “); + Serial.print("RSSI = "); Serial.println(bleDevice.rssi()); } @@ -1295,7 +1274,6 @@ bleDevice.characteristic(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1321,9 +1299,9 @@ bleDevice.characteristic(uuid, index) return; } - BLECharacteristic batteryLevelCharacterisic = peripheral.characteristic("2a19"); + BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - if (batteryLevelCharacterisic) { + if (batteryLevelCharacteristic) { // use the characteristic } else { Serial.println("Peripheral does NOT have battery level characteristic"); @@ -1351,7 +1329,7 @@ bleDevice.discoverAttributes() None #### Returns -- **true**, if successful, +- **true**, if successful, - **false** on failure. #### Example @@ -1370,7 +1348,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1437,7 +1414,6 @@ bleDevice.discoverService(serviceUuid) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1503,7 +1479,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1577,7 +1552,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1651,7 +1625,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1725,7 +1698,6 @@ bleDevice.hasService(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1798,7 +1770,6 @@ bleDevice.service(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1872,7 +1843,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1901,7 +1871,7 @@ None int characteristicCount = peripheral.characteristicCount(); Serial.print(characteristicCount); - Serial.println(" characteristis discovered"); + Serial.println(" characteristics discovered"); // ... } @@ -1927,7 +1897,7 @@ bleDevice.hasCharacteristic(uuid, index) - **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. #### Returns -- **true**, if the device provides the characteristic, +- **true**, if the device provides the characteristic, - **false** otherwise. #### Example @@ -1946,7 +1916,6 @@ bleDevice.hasCharacteristic(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -1998,7 +1967,7 @@ bleDevice.hasLocalName() Nothing #### Returns -- **true**, if the device is advertising a local name, +- **true**, if the device is advertising a local name, - **false** otherwise. #### Example @@ -2017,7 +1986,6 @@ Nothing // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2053,7 +2021,7 @@ bleDevice.hasAdvertisedServiceUuid(index) - **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. #### Returns -- **true**, if the device is advertising a service UUID, +- **true**, if the device is advertising a service UUID, - **false** otherwise. #### Example @@ -2072,7 +2040,6 @@ bleDevice.hasAdvertisedServiceUuid(index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2129,7 +2096,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2186,7 +2152,6 @@ Nothing // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2240,7 +2205,6 @@ bleDevice.advertisedServiceUuid(index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2279,7 +2243,7 @@ bleDevice.connect() None #### Returns -- **true**, if the connection was successful, +- **true**, if the connection was successful, - **false** otherwise. #### Example @@ -2298,7 +2262,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2376,7 +2339,7 @@ None BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service -Serial.print(“LED service UUID = “); +Serial.print("LED service UUID = "); Serial.println(ledService.uuid()); @@ -2385,7 +2348,7 @@ Serial.println(ledService.uuid()); ### `bleService.addCharacteristic()` -Add a BLECharateristic to the Bluetooth® Low Energy service. +Add a BLECharacteristic to the Bluetooth® Low Energy service. #### Syntax @@ -2454,7 +2417,6 @@ None // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2535,7 +2497,6 @@ bleService.hasCharacteristic(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); if (peripheral) { @@ -2614,7 +2575,6 @@ bleService.characteristic(uuid, index) // start scanning for peripheral BLE.scan(); - BLEDevice peripheral = BLE.available(); @@ -2644,9 +2604,9 @@ bleService.characteristic(uuid, index) if (batteryService) { // use the service - BLECharacteristic batteryLevelCharacterisic = peripheral.characteristic("2a19"); + BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - if (batteryLevelCharacterisic) { + if (batteryLevelCharacteristic) { // use the characteristic } else { Serial.println("Peripheral does NOT have battery level characteristic"); @@ -2739,7 +2699,7 @@ None BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); -Serial.print(“Switch characteristic UUID = “); +Serial.print("Switch characteristic UUID = "); Serial.println(switchCharacteristic.uuid()); @@ -2812,7 +2772,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 -Serial.print(“value size = “); +Serial.print("value size = "); Serial.println(switchCharacteristic.valueSize()); @@ -2845,13 +2805,13 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } + if (switchCharacteristic.value()) { // any value other than 0 + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); // will turn the LED on + } else { // a 0 value + Serial.println(F("LED off")); + digitalWrite(ledPin, LOW); // will turn the LED off + } @@ -2884,7 +2844,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 -Serial.print(“value length = “); +Serial.print("value length = "); Serial.println(switchCharacteristic.valueLength()); @@ -2904,7 +2864,7 @@ bleCharacteristic.readValue(value) #### Parameters -- **buffer:** byte array to read value into length: size of buffer argument in bytes +- **buffer:** byte array to read value into length: size of buffer argument in bytes - **value**: variable to read value into (by reference) #### Returns @@ -2958,7 +2918,7 @@ bleCharacteristic.writeValue(value) - **value**: value to write #### Returns -- 1 on success, +- 1 on success, - 0 on failure #### Example @@ -3001,7 +2961,7 @@ bleCharacteristic.setEventHandler(eventType, callback) #### Parameters -- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) +- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) - **callback**: function to call when the event occurs #### Returns @@ -3035,7 +2995,6 @@ void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteri } } - ``` @@ -3324,7 +3283,7 @@ bleCharacteristic.canRead() None #### Returns -- **true**, if characteristic is readable, +- **true**, if characteristic is readable, - **false** otherwise #### Example @@ -3354,7 +3313,7 @@ bleCharacteristic.read() None #### Returns -- **true**, if successful, +- **true**, if successful, - **false** on failure #### Example @@ -3669,7 +3628,7 @@ None BLEDescriptor millisLabelDescriptor("2901", "millis"); -Serial.print(“millis label descriptor UUID = “); +Serial.print("millis label descriptor UUID = "); Serial.println(millisLabelDescriptor.uuid()); @@ -3701,7 +3660,7 @@ None BLEDescriptor millisLabelDescriptor("2901", "millis"); -Serial.print(“millis label descriptor value size = “); +Serial.print("millis label descriptor value size = "); Serial.println(millisLabelDescriptor.valueSize()); @@ -3819,7 +3778,7 @@ bleDescriptor.readValue(value) byte value = 0; - /get the value, descriptor is 1 byte so use byte value + // get the value, descriptor is 1 byte so use byte value descriptor.readValue(value); diff --git a/docs/readme.md b/docs/readme.md index 5ba0dfb4..b584d71e 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,6 +1,6 @@ # ArduinoBLE library -This library supports all the Arduino boards that have the hardware enabled for Bluetooth® Low Energy and Bluetooth® 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev 2, MKR WiFi 1010, Nicla Sense ME. +This library supports all the Arduino boards that have the hardware enabled for Bluetooth® Low Energy and Bluetooth® 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev2, MKR WiFi 1010, Nicla Sense ME. To use this library ``#include `` @@ -9,7 +9,7 @@ To use this library Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Classic", and the Bluetooth® Low Energy. Bluetooth® Low Energy is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. -Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Blueooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. +Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Bluetooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. ![Communication between central and peripheral devices](https://raw.githubusercontent.com/arduino-libraries/ArduinoBLE/master/docs/assets/ble-bulletin-board-model.png) @@ -19,7 +19,7 @@ The information presented by a peripheral is structured as **services**, each of ## Notify -The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgement of the pushed data. +The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgment of the pushed data. The client-server structure of Bluetooth® LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. @@ -58,7 +58,7 @@ You could also combine readings into a single characteristic, when a given senso |Motor Speed, Direction|150,1| |Accelerometer X, Y, Z|200,133,150| -This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as a ASCII-encoded string. +This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as an ASCII-encoded string. ## Read/write/notify/indicate diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index a56504f6..27c421fe 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -114,7 +114,7 @@ void monitorSensorTagButtons(BLEDevice peripheral) { if (simpleKeyCharacteristic.valueUpdated()) { // yes, get the value, characteristic is 1 byte so use byte value byte value = 0; - + simpleKeyCharacteristic.readValue(value); if (value & 0x01) { diff --git a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino index d025dd62..5e7ba7f3 100644 --- a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino +++ b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -4,7 +4,7 @@ BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); // Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' -const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05}; +const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05}; void setup() { Serial.begin(9600); @@ -21,7 +21,7 @@ void setup() { // Build advertising data packet BLEAdvertisingData advData; // If a packet has a raw data parameter, then all the other parameters of the packet will be ignored - advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData)); + advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData)); // Copy set parameters in the actual advertising packet BLE.setAdvertisingData(advData); @@ -30,7 +30,7 @@ void setup() { scanData.setLocalName("Test advertising raw data"); // Copy set parameters in the actual scan response packet BLE.setScanResponseData(scanData); - + BLE.advertise(); Serial.println("advertising ..."); diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino index f013c6f5..0d786627 100644 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -73,11 +73,11 @@ void loop() { // turn on the LED to indicate the connection: digitalWrite(LED_BUILTIN, HIGH); - // check the battery level every 200ms + // check the battery level every 200 ms // while the central is connected: while (central.connected()) { long currentMillis = millis(); - // if 200ms have passed, check the battery level: + // if 200 ms have passed, check the battery level: if (currentMillis - previousMillis >= 200) { previousMillis = currentMillis; updateBatteryLevel(); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 23f67bc3..59bda5ed 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -28,7 +28,7 @@ const int ledPin = LED_BUILTIN; // pin to use for the LED void setup() { Serial.begin(9600); while (!Serial); - + pinMode(ledPin, OUTPUT); // use the LED pin as an output // begin initialization diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino index 9f9d453b..dfc9f4a0 100644 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -54,7 +54,7 @@ void setup() { Serial.println("Serial connected"); - + // Callback function with confirmation code when new device is pairing. BLE.setDisplayCode([](uint32_t confirmCode){ Serial.println("New device pairing request."); @@ -63,7 +63,7 @@ void setup() { sprintf(code, "%06d", confirmCode); Serial.println(code); }); - + // Callback to allow accepting or rejecting pairing BLE.setBinaryConfirmPairing([&acceptOrReject](){ Serial.print("Should we confirm pairing? "); @@ -98,7 +98,7 @@ void setup() { (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random - (*BDAddrs)[0] = new uint8_t[6]; + (*BDAddrs)[0] = new uint8_t[6]; (*IRKs)[0] = new uint8_t[16]; memcpy((*IRKs)[0] , device1IRK,16); memcpy((*BDAddrs)[0], device1Mac, 6); @@ -124,7 +124,7 @@ void setup() { uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - + if(memcmp(device1Mac, address, 6) == 0) { memcpy(LTK, device1LTK, 16); @@ -159,7 +159,7 @@ void setup() { } Serial.println("BT init"); delay(200); - + /* Set a local name for the BLE device This name will appear in advertising packets and can be used by remote devices to identify this BLE device @@ -180,16 +180,16 @@ void setup() { stringCharValue = "string"; stringcharacteristic.writeValue(stringCharValue); secretValue.writeValue(0); - + delay(1000); // prevent pairing until button is pressed (will show a pairing rejected message) BLE.setPairable(false); - + /* Start advertising BLE. It will start continuously transmitting BLE advertising packets and will be visible to remote BLE central devices until it receives a new connection */ - + // start advertising if(!BLE.advertise()){ Serial.println("failed to advertise bluetooth."); @@ -214,13 +214,13 @@ void loop() { if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ pairingStarted = millis(); BLE.setPairable(Pairable::ONCE); - Serial.println("Accepting pairing for 30s"); + Serial.println("Accepting pairing for 30 s"); } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ BLE.setPairable(false); Serial.println("No longer accepting pairing"); } // Make LED blink while pairing is allowed - digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); + digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); // if a central is connected to the peripheral: @@ -246,7 +246,7 @@ void loop() { Serial.print("Disconnected from central: "); Serial.println(central.address()); } - + } void updateBatteryLevel() { diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 2e6d6db9..65b88605 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -48,7 +48,7 @@ void setup() { // add service BLE.addService(ledService); - // set the initial value for the characeristic: + // set the initial value for the characteristic: switchCharacteristic.writeValue(0); // start advertising diff --git a/library.properties b/library.properties index 543998b7..6e248f5f 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=ArduinoBLE version=1.3.7 author=Arduino maintainer=Arduino -sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. +sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index e9743758..fb30b3ca 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -137,7 +137,7 @@ void HCIClass::poll(unsigned long timeout) while (HCITransport.available()) { byte b = HCITransport.read(); - + if (_recvIndex >= sizeof(_recvBuffer)) { _recvIndex = 0; if (_debug) { @@ -161,7 +161,7 @@ void HCIClass::poll(unsigned long timeout) handleAclDataPkt(pktLen, &_recvBuffer[1]); #ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, LOW); + digitalWrite(NINA_RTS, LOW); #endif } } else if (_recvBuffer[0] == HCI_EVENT_PKT) { @@ -363,7 +363,7 @@ int HCIClass::leSetAdvertiseEnable(uint8_t enable) return sendCommand(OGF_LE_CTL << 10 | OCF_LE_SET_ADVERTISE_ENABLE, sizeof(enable), &enable); } -int HCIClass::leSetScanParameters(uint8_t type, uint16_t interval, uint16_t window, +int HCIClass::leSetScanParameters(uint8_t type, uint16_t interval, uint16_t window, uint8_t ownBdaddrType, uint8_t filter) { struct __attribute__ ((packed)) HCILeSetScanParameters { @@ -437,7 +437,7 @@ int HCIClass::leCancelConn() return sendCommand(OGF_LE_CTL << 10 | OCF_LE_CANCEL_CONN, 0, NULL); } -int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxInterval, +int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t supervisionTimeout) { struct __attribute__ ((packed)) HCILeConnUpdateData { @@ -464,7 +464,7 @@ void HCIClass::saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* pe if(_storeIRK!=0){ _storeIRK(address, peerIrk); } - // Again... this should work + // Again... this should work // leAddResolvingAddress(addressType, address, peerIrk, localIrk); } void HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress, uint8_t* peerIrk, uint8_t* localIrk){ @@ -490,7 +490,7 @@ void HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress, btct.printBytes(addDevice.peerIRK,16); Serial.print("localIRK :"); btct.printBytes(addDevice.localIRK,16); - sendCommand(OGF_LE_CTL << 10 | 0x27, sizeof(addDevice), &addDevice); + sendCommand(OGF_LE_CTL << 10 | 0x27, sizeof(addDevice), &addDevice); leStartResolvingAddresses(); } @@ -509,7 +509,7 @@ int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peer } request; request.addressType = peerAddressType; for(int i=0; i<6; i++) request.identityAddress[5-i] = peerIdentityAddress[i]; - + int res = sendCommand(OGF_LE_CTL << 10 | 0x2B, sizeof(request), &request); Serial.print("res: 0x"); @@ -604,7 +604,7 @@ int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){ delete BADDRs; delete[] (*IRKs); delete IRKs; - + if(foundMatch){ return 1; } @@ -688,7 +688,6 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) for(int i=0; i< sizeof(pktHdr) + plen;i++){ Serial.print(" 0x"); Serial.print(txBuffer[i],HEX); - } Serial.println(""); #endif @@ -758,7 +757,7 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[]) } } else if (aclHdr->cid == SIGNALING_CID) { #ifdef _BLE_TRACE_ - Serial.println("Signalling"); + Serial.println("Signaling"); #endif L2CAPSignaling.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]); } else if (aclHdr->cid == SECURITY_CID){ @@ -853,7 +852,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) } // From page 1681 bluetooth standard - order matters if(ATT.localKeyDistribution.IdKey()){ - /// We shall distribute IRK and address using identity information + /// We shall distribute IRK and address using identity information { uint8_t response[17]; response[0] = CONNECTION_IDENTITY_INFORMATION; // Identity information. @@ -1002,7 +1001,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t supervisionTimeout; uint8_t masterClockAccuracy; } *leConnectionComplete = (EvtLeConnectionComplete*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; - + if (leConnectionComplete->status == 0x00) { ATT.addConnection(leConnectionComplete->handle, leConnectionComplete->role, @@ -1051,7 +1050,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint16_t supervisionTimeout; uint8_t masterClockAccuracy; } *leConnectionComplete = (EvtLeConnectionComplete*)&pdata[sizeof(HCIEventHdr) + sizeof(LeMetaEventHeader)]; - + if (leConnectionComplete->status == 0x00) { ATT.addConnection(leConnectionComplete->handle, leConnectionComplete->role, @@ -1127,7 +1126,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t resolvableAddr[6]; uint8_t foundLTK; ATT.getPeerAddrWithType(ltkRequest->connectionHandle, peerAddr); - + if((ATT.getPeerEncryption(ltkRequest->connectionHandle) & PEER_ENCRYPTION::PAIRING_REQUEST)>0){ // Pairing request - LTK is one in buffer already foundLTK = 1; @@ -1207,7 +1206,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.print("Timeout : "); btct.printBytes((uint8_t*)&remoteConnParamReq->timeOut,2); #endif - + struct __attribute__ ((packed)) RemoteConnParamReqReply { uint16_t connectionHandle; uint16_t intervalMin; @@ -1253,13 +1252,13 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) HCI.sendAclPkt(connectionHandle,SECURITY_CID,sizeof(PairingPublicKey),&pairingPublicKey); uint8_t encryption = ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::SENT_PUBKEY; ATT.setPeerEncryption(connectionHandle, encryption); - + uint8_t Z = 0; - + HCI.leRand(Nb); HCI.leRand(&Nb[8]); - + #ifdef _BLE_TRACE_ Serial.print("nb: "); btct.printBytes(Nb, 16); @@ -1271,16 +1270,16 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t Z; } f4Params = {0,0,Z}; for(int i=0; i<32; i++){ - f4Params.U[31-i] = pairingPublicKey.publicKey[i]; + f4Params.U[31-i] = pairingPublicKey.publicKey[i]; f4Params.V[31-i] = HCI.remotePublicKeyBuffer[i]; } - + struct __attribute__ ((packed)) PairingConfirm { uint8_t code; uint8_t cb[16]; } pairingConfirm = {CONNECTION_PAIRING_CONFIRM,0}; - + btct.AES_CMAC(Nb,(unsigned char *)&f4Params,sizeof(f4Params),pairingConfirm.cb); #ifdef _BLE_TRACE_ @@ -1297,7 +1296,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) // Send Pairing confirm response HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(pairingConfirm), &pairingConfirm); - + HCI.sendCommand( (OGF_LE_CTL << 10) | LE_COMMAND::GENERATE_DH_KEY_V1, sizeof(HCI.remotePublicKeyBuffer), HCI.remotePublicKeyBuffer); }else{ #ifdef _BLE_TRACE_ @@ -1329,8 +1328,8 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) #endif break; } - - + + for(int i=0; i<32; i++) DHKey[31-i] = evtLeDHKeyComplete->DHKey[i]; #ifdef _BLE_TRACE_ @@ -1345,7 +1344,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.println("Received DHKey check already so calculate f5, f6 now."); #endif L2CAPSignaling.smCalculateLTKandConfirm(connectionHandle, HCI.remoteDHKeyCheckBuffer); - + }else{ #ifdef _BLE_TRACE_ Serial.println("Waiting on other DHKey check before calculating."); @@ -1382,7 +1381,7 @@ int HCIClass::leEncrypt(uint8_t* key, uint8_t* plaintext, uint8_t* status, uint8 leEncryptCommand.key[15-i] = key[i]; leEncryptCommand.plaintext[15-i] = plaintext[i]; } - + int res = sendCommand(OGF_LE_CTL << 10 | LE_COMMAND::ENCRYPT, 32, &leEncryptCommand); if(res == 0){ #ifdef _BLE_TRACE_ From eef16ce34abb977d147d637c6751b69bf5b1161b Mon Sep 17 00:00:00 2001 From: fabik111 Date: Thu, 3 Oct 2024 14:52:10 +0200 Subject: [PATCH 088/112] fix crashes on M0 board when assigning the BLE handle from the received data buffer --- src/utility/ATT.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index b1796c90..9367cfbf 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -993,8 +993,8 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_ } /// if auth error, hold the response in a buffer. bool holdResponse = false; - - uint16_t handle = *(uint16_t*)data; + uint16_t handle; + memcpy(&handle, data, sizeof(handle)); uint16_t offset = (opcode == ATT_OP_READ_REQ) ? 0 : *(uint16_t*)&data[sizeof(handle)]; if ((uint16_t)(handle - 1) > GATT.attributeCount()) { @@ -1248,7 +1248,8 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op return; } - uint16_t handle = *(uint16_t*)data; + uint16_t handle; + memcpy(&handle, data, sizeof(handle)); if ((uint16_t)(handle - 1) > GATT.attributeCount()) { if (withResponse) { From 3fd5a50fd18c2b0644d1a8e2d74045fa9beafd96 Mon Sep 17 00:00:00 2001 From: Carlo Parata Date: Thu, 19 Sep 2019 10:33:53 +0200 Subject: [PATCH 089/112] feat: add HCISpiTransport To support to STBTLE-RF, STBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0. Signed-off-by: Carlo Parata Co-authored-by: Frederic Pillon --- keywords.txt | 9 + src/utility/HCISpiTransport.cpp | 1399 +++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.h | 83 ++ 3 files changed, 1491 insertions(+) create mode 100644 src/utility/HCISpiTransport.cpp create mode 100644 src/utility/HCISpiTransport.h diff --git a/keywords.txt b/keywords.txt index effdfbca..ecfbafbf 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,6 +30,8 @@ BLEFloatCharacteristic KEYWORD1 BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 +HCISpiTransportClass KEYWORD1 + ####################################### # Methods and Functions (KEYWORD2) ####################################### @@ -136,3 +138,10 @@ BLEUnsubscribed LITERAL1 BLEWritten LITERAL1 BLEUpdated LITERAL1 +SPBTLE_RF LITERAL1 +SPBTLE_1S LITERAL1 +BLUENRG_M2SP LITERAL1 +BLUENRG_M0 LITERAL1 +BLUENRG_LP LITERAL1 +BLEChip_t LITERAL1 + diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp new file mode 100644 index 00000000..91c2c5dc --- /dev/null +++ b/src/utility/HCISpiTransport.cpp @@ -0,0 +1,1399 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "HCISpiTransport.h" + +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ +SPIClass SpiHCI(PC12, PC11, PC10); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); +#elif defined(ARDUINO_STM32L562E_DK) +/* STM32L562E-DK */ +SPIClass SpiHCI(PG4, PG3, PG2); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, PG5, PG6, PG8, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D3) +/* Shield IDB05A2 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D13) +/* Shield IDB05A2 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D3) +/* Shield IDB05A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D13) +/* Shield IDB05A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(BNRG2A1_CLOCK_D3) +/* Shield BNRG2A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#elif defined(BNRG2A1_CLOCK_D13) +/* Shield BNRG2A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#else +#error "Unsupported board or shield selected!" +#endif + +volatile int data_avail = 0; + +HCISpiTransportClass::HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : + _spi(&spi), + _ble_chip(ble_chip), + _cs_pin(cs_pin), + _spi_irq(spi_irq), + _ble_rst(ble_rst) +{ + _spiSettings = SPISettings(frequency, (BitOrder)BLE_SPI_BYTE_ORDER, spi_mode); + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + _random_addr_done = false; +} + +HCISpiTransportClass::~HCISpiTransportClass() +{ +} + +extern "C" void SPI_Irq_Callback(void) +{ + data_avail = 1; +} + +int HCISpiTransportClass::begin() +{ + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + memset(_rxbuff, 0, sizeof(_rxbuff)); + pinMode(_cs_pin, OUTPUT); + digitalWrite(_cs_pin, HIGH); + + _spi->begin(); + + pinMode(_spi_irq, INPUT); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + // Reset chip + pinMode(_ble_rst, OUTPUT); + digitalWrite(_ble_rst, LOW); + delay(5); + digitalWrite(_ble_rst, HIGH); + delay(5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + // Wait for Blue Initialize + wait_for_blue_initialize(); + } else if (_ble_chip == SPBTLE_1S) { + // Wait a while for the reset of the BLE module + delay(300); + } else { + // BLE chip not supported + return 0; + } + + return 1; +} + +void HCISpiTransportClass::end() +{ + detachInterrupt(_spi_irq); + _spi->end(); +} + +void HCISpiTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISpiTransportClass::available() +{ + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + if (_read_index != _write_index) { + return 1; + } else if (data_avail) { + int ble_reset = 0; + + if (digitalRead(_spi_irq) == 0) { + return 0; + } + + data_avail = 0; + + // Wait for BlueNRG-LP to be ready (needs to be done after each HCI RESET) + if (_ble_chip == BLUENRG_LP && _initial_phase) { + delay(100); + } + + while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a Blue Initialize */ + /* If so we need to send the command to enable LL_ONLY */ + if (byte_count == 6) { + if (_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a CMD_COMPLETE */ + /* We suppose that the first CMD is always a HCI_RESET */ + if (byte_count == 7) { + if (_rxbuff[_write_index_initial - 7] == 0x04 && + _rxbuff[_write_index_initial - 6] == 0x0E && + _rxbuff[_write_index_initial - 5] == 0x04 && + _rxbuff[_write_index_initial - 4] == 0x01 && + _rxbuff[_write_index_initial - 3] == 0x03 && + _rxbuff[_write_index_initial - 2] == 0x0C && + _rxbuff[_write_index_initial - 1] == 0x00) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + + if (ble_reset) { + if (_ble_chip == BLUENRG_M2SP) { + wait_for_blue_initialize(); + } + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + /* BLE chip was reset: we need to enable LL_ONLY */ + enable_ll_only(); + wait_for_enable_ll_only(); + } else if (_ble_chip == SPBTLE_1S) { + /* BLE chip was reset: we need to wait for a while */ + delay(300); + } + + /* Call Gatt Init and Gap Init to activate the random BLE address */ + if (!_random_addr_done) { + aci_gatt_init(); + wait_for_aci_gatt_init(); + aci_gap_init(); + wait_for_aci_gap_init(); + /* Call Read Config Parameter to retrieve the random BLE address */ + aci_read_config_parameter(); + wait_for_aci_read_config_parameter(); + if (_ble_chip == BLUENRG_LP) { + hci_reset(); + _read_index = _write_index = _write_index_initial = 0; + _initial_phase = 1; + } else { + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } else { + set_address(); + wait_for_set_address(); + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } + + if (_read_index != _write_index) { + return 1; + } else { + return 0; + } + } else { + return 0; + } +} + +int HCISpiTransportClass::peek() +{ + int peek_val = -1; + + if (_read_index != _write_index) { + peek_val = _rxbuff[_read_index]; + } + + return peek_val; +} + +int HCISpiTransportClass::read() +{ + int read_val = -1; + + if (_read_index != _write_index) { + read_val = _rxbuff[_read_index]; + _read_index++; + if (_read_index == _write_index) { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + + return read_val; +} + +size_t HCISpiTransportClass::write(const uint8_t *data, size_t length) +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + void *my_data = (void *)data; + int result = 0; + uint32_t tickstart = millis(); + + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + if (header_master[1] >= length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* + * Wait until BlueNRG-1 is ready. + * When ready it will raise the IRQ pin. + */ + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= (int)length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } + } while (result < 0); + + if (result < 0) { + return 0; + } else { + return length; + } +} + +void HCISpiTransportClass::wait_for_blue_initialize() +{ + int event_blue_initialize = 0; + uint8_t event[16]; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } else if (_ble_chip == BLUENRG_LP) { + uint8_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 7) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x82 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x00 && + event[4] == 0x01 && + event[5] == 0x00 && + event[6] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!event_blue_initialize); +} + +void HCISpiTransportClass::wait_for_enable_ll_only() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::enable_ll_only() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[7] = {0x01, 0x0C, 0xFC, 0x03, 0x2C, 0x01, 0x01}; // Enable LL_ONLY + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gatt_init() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gatt_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x01, 0xFD, 0x00}; // ACI_GATT_INIT + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gap_init() +{ + uint8_t data[14]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gap_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t cmd_others[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t *cmd, cmd_size; + if (_ble_chip == BLUENRG_LP) { + cmd = cmd_lp; + cmd_size = 8; + } else { + cmd = cmd_others; + cmd_size = 7; + } + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_read_config_parameter() +{ + uint8_t data[15]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[7], 6); + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 14) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0B && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[8], 6); + status = 1; + _random_addr_done = true; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_read_config_parameter() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[5] = {0x01, 0x0D, 0xFC, 0x01, 0x80}; // ACI_READ_CONFIG_PARAMETER + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::hci_reset() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x03, 0x0C, 0x00}; // HCI_RESET + int result = 0; + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::set_address() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[10] = {0x01, 0x05, 0x20, 0x06}; // SET ADDR + int result = 0; + memcpy(&cmd[4], _random_addr, 6); + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 10) { + /* Write the data */ + _spi->transfer((void *)cmd, 10); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_set_address() +{ + uint8_t data[15]; + int status = 0; + + if (_ble_chip != BLUENRG_LP) { + return; + } + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + uint16_t byte_count = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { // 040E0401052000 + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x05 && + data[5] == 0x20 && + data[6] == 0x00) { + status = 1; + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (!status); +} + +HCITransportInterface& HCITransport = HCISpiTransport; diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h new file mode 100644 index 00000000..34af1aa9 --- /dev/null +++ b/src/utility/HCISpiTransport.h @@ -0,0 +1,83 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SPI_TRANSPORT_H_ +#define _HCI_SPI_TRANSPORT_H_ + +#include "HCITransport.h" +#include "SPI.h" + +typedef enum BLEChip_s { + SPBTLE_RF, + SPBTLE_1S, + BLUENRG_M2SP, + BLUENRG_M0, + BLUENRG_LP +} BLEChip_t; + +#ifndef BLE_SPI_BYTE_ORDER + #define BLE_SPI_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SPI_BUFFER_SIZE 128 + +class HCISpiTransportClass : public HCITransportInterface { + public: + HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); + virtual ~HCISpiTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t *data, size_t length); + + private: + void wait_for_blue_initialize(); + void wait_for_enable_ll_only(); + void enable_ll_only(); + void wait_for_aci_gatt_init(); + void aci_gatt_init(); + void wait_for_aci_gap_init(); + void aci_gap_init(); + void wait_for_aci_read_config_parameter(); + void aci_read_config_parameter(); + void hci_reset(); + void set_address(); + void wait_for_set_address(); + SPIClass *_spi; + SPISettings _spiSettings; + BLEChip_t _ble_chip; + uint8_t _cs_pin; + uint8_t _spi_irq; + uint8_t _ble_rst; + uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; + uint16_t _read_index; + uint16_t _write_index; + uint16_t _write_index_initial; + uint8_t _initial_phase; + uint8_t _random_addr[6]; + bool _random_addr_done; +}; + +#endif /* _HCI_SPI_TRANSPORT_H_ */ From f5e86b919317620ab4cc9e88c76bc66d17897948 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Wed, 26 Mar 2025 09:03:20 +0100 Subject: [PATCH 090/112] chore: moved to STM32duinoBLE Signed-off-by: Frederic Pillon --- .github/dependabot.yml | 13 - .github/workflows/compile-examples.yml | 98 - .github/workflows/report-size-deltas.yml | 24 - .github/workflows/sync-labels.yml | 138 - README.md | 28 +- docs/api.md | 3818 ---- docs/assets/ble-bulletin-board-model.png | Bin 41914 -> 0 bytes docs/readme.md | 91 - examples/Central/LedControl/LedControl.ino | 6 +- .../PeripheralExplorer/PeripheralExplorer.ino | 5 +- examples/Central/Scan/Scan.ino | 5 +- .../Central/ScanCallback/ScanCallback.ino | 5 +- .../SensorTagButton/SensorTagButton.ino | 5 +- .../EnhancedAdvertising.ino | 2 +- .../RawDataAdvertising/RawDataAdvertising.ino | 2 +- .../BatteryMonitor/BatteryMonitor.ino | 5 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 6 +- .../Peripheral/CallbackLED/CallbackLED.ino | 5 +- .../EncryptedBatteryMonitor.ino | 265 - examples/Peripheral/LED/LED.ino | 5 +- extras/arduino-ble-parser.py | 85 - extras/test/.gitignore | 1 - extras/test/CMakeLists.txt | 126 - .../external/catch/v2.12.1/include/catch.hpp | 17698 ---------------- extras/test/include/Arduino.h | 45 - .../FakeBLELocalDevice.h | 35 - .../include/test_discovered_device/FakeGAP.h | 33 - extras/test/include/util/Common.h | 167 - extras/test/include/util/HCIFakeTransport.h | 19 - extras/test/include/util/Stream.h | 40 - extras/test/include/util/String.h | 248 - extras/test/include/util/TestUtil.h | 3 - extras/test/include/util/itoa.h | 37 - extras/test/src/Arduino.cpp | 44 - .../FakeBLELocalDevice.cpp | 40 - .../test_advertising_data.cpp | 184 - .../test_advertising_data/test_local_name.cpp | 82 - .../test_manufacturer.cpp | 146 - .../test_advertising_data/test_service.cpp | 149 - .../src/test_discovered_device/FakeGAP.cpp | 31 - .../test_discovered_device.cpp | 52 - extras/test/src/test_main.cpp | 21 - extras/test/src/test_uuid/test_uuid.cpp | 52 - extras/test/src/util/Common.cpp | 34 - extras/test/src/util/HCIFakeTransport.cpp | 23 - extras/test/src/util/String.cpp | 755 - extras/test/src/util/TestUtil.cpp | 3 - extras/test/src/util/itoa.c | 126 - keywords.txt | 4 +- library.properties | 14 +- src/{ArduinoBLE.h => STM32duinoBLE.h} | 4 +- src/utility/CordioHCICustomDriver.h | 17 - src/utility/HCICordioTransport.cpp | 314 - src/utility/HCICordioTransport.h | 54 - src/utility/HCISilabsTransport.cpp | 130 - src/utility/HCISilabsTransport.h | 42 - src/utility/HCIUartTransport.cpp | 109 - src/utility/HCIUartTransport.h | 46 - src/utility/HCIVirtualTransport.cpp | 142 - src/utility/HCIVirtualTransport.h | 50 - src/utility/HCIVirtualTransportAT.cpp | 112 - src/utility/HCIVirtualTransportAT.h | 42 - src/utility/btct.cpp | 2 +- 63 files changed, 53 insertions(+), 25834 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/report-size-deltas.yml delete mode 100644 .github/workflows/sync-labels.yml delete mode 100644 docs/api.md delete mode 100644 docs/assets/ble-bulletin-board-model.png delete mode 100644 docs/readme.md delete mode 100644 examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino delete mode 100644 extras/arduino-ble-parser.py delete mode 100644 extras/test/.gitignore delete mode 100644 extras/test/CMakeLists.txt delete mode 100644 extras/test/external/catch/v2.12.1/include/catch.hpp delete mode 100644 extras/test/include/Arduino.h delete mode 100644 extras/test/include/test_advertising_data/FakeBLELocalDevice.h delete mode 100644 extras/test/include/test_discovered_device/FakeGAP.h delete mode 100644 extras/test/include/util/Common.h delete mode 100644 extras/test/include/util/HCIFakeTransport.h delete mode 100644 extras/test/include/util/Stream.h delete mode 100644 extras/test/include/util/String.h delete mode 100644 extras/test/include/util/TestUtil.h delete mode 100644 extras/test/include/util/itoa.h delete mode 100644 extras/test/src/Arduino.cpp delete mode 100644 extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp delete mode 100644 extras/test/src/test_advertising_data/test_advertising_data.cpp delete mode 100644 extras/test/src/test_advertising_data/test_local_name.cpp delete mode 100644 extras/test/src/test_advertising_data/test_manufacturer.cpp delete mode 100644 extras/test/src/test_advertising_data/test_service.cpp delete mode 100644 extras/test/src/test_discovered_device/FakeGAP.cpp delete mode 100644 extras/test/src/test_discovered_device/test_discovered_device.cpp delete mode 100644 extras/test/src/test_main.cpp delete mode 100644 extras/test/src/test_uuid/test_uuid.cpp delete mode 100644 extras/test/src/util/Common.cpp delete mode 100644 extras/test/src/util/HCIFakeTransport.cpp delete mode 100644 extras/test/src/util/String.cpp delete mode 100644 extras/test/src/util/TestUtil.cpp delete mode 100644 extras/test/src/util/itoa.c rename src/{ArduinoBLE.h => STM32duinoBLE.h} (94%) delete mode 100644 src/utility/CordioHCICustomDriver.h delete mode 100644 src/utility/HCICordioTransport.cpp delete mode 100644 src/utility/HCICordioTransport.h delete mode 100644 src/utility/HCISilabsTransport.cpp delete mode 100644 src/utility/HCISilabsTransport.h delete mode 100644 src/utility/HCIUartTransport.cpp delete mode 100644 src/utility/HCIUartTransport.h delete mode 100644 src/utility/HCIVirtualTransport.cpp delete mode 100644 src/utility/HCIVirtualTransport.h delete mode 100644 src/utility/HCIVirtualTransportAT.cpp delete mode 100644 src/utility/HCIVirtualTransportAT.h diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f2bfa724..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,13 +0,0 @@ -# See: https://docs.github.com/en/code-security/supply-chain-security/configuration-options-for-dependency-updates#about-the-dependabotyml-file -version: 2 - -updates: - # Configure check for outdated GitHub Actions actions in workflows. - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md - # See: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot - - package-ecosystem: github-actions - directory: / # Check the repository's workflows under /.github/workflows/ - schedule: - interval: daily - labels: - - "topic: infrastructure" diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 706ccb4c..c298c638 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -12,104 +12,6 @@ on: - ".github/workflows/compile-examples.yml" - "examples/**" - "src/**" - schedule: - # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). - - cron: "0 8 * * TUE" workflow_dispatch: - repository_dispatch: jobs: - build: - name: ${{ matrix.board.fqbn }} - runs-on: ubuntu-latest - - env: - SKETCHES_REPORTS_PATH: sketches-reports - - strategy: - fail-fast: false - - matrix: - board: - - fqbn: arduino:samd:mkrwifi1010 - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-mkrwifi1010 - - fqbn: arduino:samd:nano_33_iot - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-nano_33_iot - - fqbn: arduino:megaavr:uno2018:mode=on - platforms: | - - name: arduino:megaavr - artifact-name-suffix: arduino-megaavr-uno2018 - - fqbn: arduino:mbed_nano:nano33ble - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nano33ble - - fqbn: arduino:mbed_nano:nanorp2040connect - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nanorp2040connect - - fqbn: arduino:renesas_uno:unor4wifi - platforms: | - - name: arduino:renesas_uno - artifact-name-suffix: arduino-renesas_uno-unor4wifi - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Compile examples - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.board.fqbn }} - platforms: ${{ matrix.board.platforms }} - libraries: | - # Install the library from the local path. - - source-path: ./ - sketch-paths: | - - examples - enable-deltas-report: true - sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - - - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v4 - with: - if-no-files-found: error - path: ${{ env.SKETCHES_REPORTS_PATH }} - name: sketches-report-${{ matrix.board.artifact-name-suffix }} - - build-for-esp32: - runs-on: ubuntu-latest - - strategy: - matrix: - fqbn: - - esp32:esp32:esp32 - - esp32:esp32:esp32s3 - - esp32:esp32:esp32c3 - # future bluetooth chips - #- esp32:esp32:esp32c2 - #- esp32:esp32:esp32c6 - #- esp32:esp32:esp32h2 - - steps: - - uses: actions/checkout@v4 - - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} - platforms: | - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - sketch-paths: | - - examples/Central/Scan - - examples/Central/PeripheralExplorer - - examples/Central/ScanCallback - - examples/Central/SensorTagButton - - examples/Peripheral/Advertising/EnhancedAdvertising - - examples/Peripheral/Advertising/RawDataAdvertising - cli-compile-flags: | - - --warnings="none" diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml deleted file mode 100644 index 39e2a0ad..00000000 --- a/.github/workflows/report-size-deltas.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Report Size Deltas - -# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/report-size-deltas.yml" - schedule: - # Run at the minimum interval allowed by GitHub Actions. - # Note: GitHub Actions periodically has outages which result in workflow failures. - # In this event, the workflows will start passing again once the service recovers. - - cron: "*/5 * * * *" - workflow_dispatch: - repository_dispatch: - -jobs: - report: - runs-on: ubuntu-latest - steps: - - name: Comment size deltas reports to PRs - uses: arduino/report-size-deltas@v1 - with: - # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow - sketches-reports-source: ^sketches-report-.+ diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml deleted file mode 100644 index 53a9f54f..00000000 --- a/.github/workflows/sync-labels.yml +++ /dev/null @@ -1,138 +0,0 @@ -# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md -name: Sync Labels - -# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - pull_request: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - schedule: - # Run daily at 8 AM UTC to sync with changes to shared label configurations. - - cron: "0 8 * * *" - workflow_dispatch: - repository_dispatch: - -env: - CONFIGURATIONS_FOLDER: .github/label-configuration-files - CONFIGURATIONS_ARTIFACT: label-configuration-files - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download JSON schema for labels configuration file - id: download-schema - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json - location: ${{ runner.temp }}/label-configuration-schema - - - name: Install JSON schema validator - run: | - sudo npm install \ - --global \ - ajv-cli \ - ajv-formats - - - name: Validate local labels configuration - run: | - # See: https://github.com/ajv-validator/ajv-cli#readme - ajv validate \ - --all-errors \ - -c ajv-formats \ - -s "${{ steps.download-schema.outputs.file-path }}" \ - -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" - - download: - needs: check - runs-on: ubuntu-latest - - strategy: - matrix: - filename: - # Filenames of the shared configurations to apply to the repository in addition to the local configuration. - # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels - - universal.yml - - steps: - - name: Download - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - - - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 - with: - path: | - *.yaml - *.yml - if-no-files-found: error - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - sync: - needs: download - runs-on: ubuntu-latest - - steps: - - name: Set environment variables - run: | - # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable - echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" - - - name: Determine whether to dry run - id: dry-run - if: > - github.event_name == 'pull_request' || - ( - ( - github.event_name == 'push' || - github.event_name == 'workflow_dispatch' - ) && - github.ref != format('refs/heads/{0}', github.event.repository.default_branch) - ) - run: | - # Use of this flag in the github-label-sync command will cause it to only check the validity of the - # configuration. - echo "::set-output name=flag::--dry-run" - - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download configuration files artifact - uses: actions/download-artifact@v4 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - path: ${{ env.CONFIGURATIONS_FOLDER }} - - - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v5 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - - name: Merge label configuration files - run: | - # Merge all configuration files - shopt -s extglob - cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" - - - name: Install github-label-sync - run: sudo npm install --global github-label-sync - - - name: Sync labels - env: - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # See: https://github.com/Financial-Times/github-label-sync - github-label-sync \ - --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ - ${{ steps.dry-run.outputs.flag }} \ - ${{ github.repository }} diff --git a/README.md b/README.md index b0027583..e9f3a948 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,24 @@ -# ArduinoBLE +# STM32duinoBLE -[![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) +This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. -Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. +It was successfully tested with the [X-NUCLEO-IDB05A2] or [X-NUCLEO-IDB05A1] or [X-NUCLEO-BNRG2A1] expansion board and a [NUCLEO-F401RE] or [NUCLEO-L476RG] or [NUCLEO-L053R8], with [B-L475E-IOT01A], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. -This library supports creating a Bluetooth® Low Energy peripheral & central mode. + - In order to use this library with [STEVAL-MKSBOX1V1], you need to update the firmware of the SPBTLE-1S BLE module mounted on that board as described in the following wiki page: -For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-steval_mksbox1v1 -For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later. +- In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module mounted on that expansion board as described in the following wiki page: +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-x-nucleo-bnrg2a1 -For more information about this library please visit us at: +For more information about ArduinoBLE library please visit the official web page at: https://www.arduino.cc/en/Reference/ArduinoBLE ## License ``` +Copyright (c) 2019 STMicroelectronics. All rights reserved. Copyright (c) 2019 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or @@ -33,3 +35,15 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + +B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html +B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html +NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html +NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html +NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html +STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html +STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html +X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html +X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html \ No newline at end of file diff --git a/docs/api.md b/docs/api.md deleted file mode 100644 index c9f41840..00000000 --- a/docs/api.md +++ /dev/null @@ -1,3818 +0,0 @@ -# ArduinoBLE library - -## BLE class - -Used to enable the Bluetooth® Low Energy module. - -### `BLE.begin()` - -Initializes the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.begin() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success -- 0 on failure - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - -``` - -### `BLE.end()` - -Stops the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.end() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // .... - - BLE.end(); - - -``` - -### `BLE.poll()` - -Poll for Bluetooth® Low Energy radio events and handle them. - -#### Syntax - -``` -BLE.poll() -BLE.poll(timeout) - -``` - -#### Parameters - -**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - BLE.poll(); - - -``` - -### `BLE.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -BLE.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLEConnected, BLEDisconnected) -- **callback**: function to call when event occurs -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - -void blePeripheralConnectHandler(BLEDevice central) { - // central connected event handler - Serial.print("Connected event, central: "); - Serial.println(central.address()); -} - -void blePeripheralDisconnectHandler(BLEDevice central) { - // central disconnected event handler - Serial.print("Disconnected event, central: "); - Serial.println(central.address()); -} - - -``` - -### `BLE.connected()` - -Query if another Bluetooth® Low Energy device is connected - -#### Syntax - -``` -BLE.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if another Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // while the central is still connected to peripheral: - while (BLE.connected()) { - - // ... - } - - -``` - -### `BLE.disconnect()` - -Disconnect any Bluetooth® Low Energy devices that are connected - -#### Syntax - -``` -BLE.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - if (BLE.connected()) { - BLE.disconnect(); - } - - -``` - -### `BLE.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.address() - -``` - -#### Parameters - -None - -#### Returns -- The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - String address = BLE.address(); - - Serial.print("Local address is: "); - Serial.println(address); - - -``` - -### `BLE.rssi()` - -Query the RSSI (Received signal strength indication) of the connected Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.rssi() - -``` - -#### Parameters - -None - -#### Returns -- The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. - -#### Example - -```arduino - - if (BLE.connected()) { - Serial.print("RSSI = "); - Serial.println(BLE.rssi()); - } - - -``` - -### `BLE.setAdvertisedServiceUuid()` - -Set the advertised service UUID used when advertising. - -#### Syntax - -``` -BLE.setAdvertisedServiceUuid(uuid) - -``` - -#### Parameters - -- **uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedServiceUuid("19B10000-E8F2-537E-4F6C-D104768A1214"); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setAdvertisedService()` - -Set the advertised service UUID used when advertising to the value of the BLEService provided. - -#### Syntax - -``` -BLE.setAdvertisedService(bleService) - -``` - -#### Parameters - -- **bleService:** BLEService to use UUID from - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// ... - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedService(ledService); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setManufacturerData()` - -Set the manufacturer data value used when advertising. - -#### Syntax - -``` -BLE.setManufacturerData(data, length) - -``` - -#### Parameters - -- **data:** byte array containing manufacturer data -- **length:** length of manufacturer data array - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - byte data[5] = { 0x01, 0x02, 0x03, 0x04, 0x05}; - - BLE.setManufacturerData(data, 5); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setLocalName()` - -Set the local value used when advertising. - -#### Syntax - -``` -BLE.setLocalName(name) - -``` - -#### Parameters - -- **name:** local name value to use when advertising - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setLocalName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setDeviceName()` - -Set the device name in the built in device name characteristic. If not set, the value defaults to “Arduino”. - -#### Syntax - -``` -BLE.setDeviceName(name) - -``` - -#### Parameters - -- **name:** device name value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setDeviceName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setAppearance()` - -Set the appearance in the built in appearance characteristic. If not set, the value defaults to 0x0000. - -#### Syntax - -``` -BLE.setAppearance(appearance) - -``` - -#### Parameters - -- **appearance:** appearance value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAppearance(0x8000); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.addService()` - -Add a BLEService to the set of services the Bluetooth® Low Energy device provides - -#### Syntax - -``` -BLE.addService(service) - -``` - -#### Parameters - -- **service:** BLEService to add - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.addService(ledService); - - // ... - - -``` - -### `BLE.advertise()` - -Start advertising. - -#### Syntax - -``` -BLE.advertise() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - -``` - -### `BLE.stopAdvertise()` - -Stop advertising. - -#### Syntax - -``` -BLE.stopAdvertise() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - BLE.stopAdvertise(); - - -``` - -### `BLE.central()` - -Query the central Bluetooth® Low Energy device connected. - -#### Syntax - -``` -BLE.central() - -``` - -#### Parameters - -None - -#### Returns -- **BLEDevice** representing the central. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `BLE.setAdvertisingInterval()` - -Set the advertising interval in units of 0.625 ms. Defaults to 100ms (160 * 0.625 ms) if not provided. - -#### Syntax - -``` -BLE.setAdvertisingInterval(advertisingInterval) - -``` - -#### Parameters - -- **advertisingInterval:** advertising interval in units of 0.625 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setAdvertisingInterval(320); // 200 * 0.625 ms - - BLE.advertise(); - - -``` - -### `BLE.setConnectionInterval()` - -Set the minimum and maximum desired connection intervals in units of 1.25 ms. - -#### Syntax - -``` -BLE.setConnectionInterval(minimum, maximum) - -``` - -#### Parameters - -- **minimum:** minimum desired connection interval in units of 1.25 ms -- **maximum:** maximum desired connection interval in units of 1.25 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectionInterval(0x0006, 0x0c80); // 7.5 ms minimum, 4 s maximum - - - -``` - -### `BLE.setConnectable()` - -Set if the device is connectable after advertising, defaults to **true**. - -#### Syntax - -``` -BLE.setConnectable(connectable) - -``` - -#### Parameters - -- **true**: the device will be connectable when advertising -- **false**: the device will NOT be connectable when advertising - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectable(false); // make the device unconnectable when advertising - - - -``` - -### `BLE.scan()` - -Start scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.scan() -BLE.scan(withDuplicates) - -``` - -#### Parameters - -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForName()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (local) name. - -#### Syntax - -``` -BLE.scanForName(name) -BLE.scanForName(name, withDuplicates) - -``` - -#### Parameters - -- **name:** (local) name of device (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForName("LED"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForAddress()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (Bluetooth®) address. - -#### Syntax - -``` -BLE.scanForAddress(address) -BLE.scanForAddress(address, withDuplicates) - -``` - -#### Parameters - -- **address:** (Bluetooth®) address (as a String) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForUuid()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (service) UUID. - -#### Syntax - -``` -BLE.scanForUuid(uuid) -BLE.scanForUuid(uuid, withDuplicates) - -``` - -#### Parameters - -- **uuid:** (service) UUID (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForUuid("aa10"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.stopScan()` - -Stop scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.stopScan() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLE.stopScan(); - - -``` - -### `BLE.available()` - -Query for a discovered Bluetooth® Low Energy device that was found during scanning. - -#### Syntax - -``` -BLE.available() - -``` - -#### Parameters - -Nothing - -#### Returns -- **BLEDevice** representing the discovered device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -## BLEDevice Class - -Used to get information about the devices connected or discovered while scanning - -### `bleDevice.poll()` - -Poll for Bluetooth® Low Energy radio events for the specified Bluetooth® Low Energy device and handle them. - -#### Syntax - -``` -bleDevice.poll() -bleDevice.poll(timeout) - -``` - -#### Parameters - -- **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - central.poll(); - - // ... - } - - -``` - -### `bleDevice.connected()` - -Query if a Bluetooth® Low Energy device is connected - -#### Syntax - -``` -bleDevice.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // while the central is still connected - while (central.connected()) { - - // ... - } - - -``` - -### `bleDevice.disconnect()` - -Disconnect the Bluetooth® Low Energy device, if connected - -#### Syntax - -``` -bleDevice.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - - central.disconnect(); - - -``` - -### `bleDevice.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.address() - -``` - -#### Parameters - -None - -#### Returns -- **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `bleDevice.rssi()` - -Query the RSSI (Received signal strength indication) of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.rssi() - -``` - -#### Parameters - -None - -#### Returns -- **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. - -#### Example - -```arduino - - if (bleDevice.connected()) { - Serial.print("RSSI = "); - Serial.println(bleDevice.rssi()); - } - - -``` - -### `bleDevice.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the device provides. - -#### Syntax - -``` -bleDevice.characteristic(index) -bleDevice.characteristic(uuid) -bleDevice.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.discoverAttributes()` - -Discover all of the attributes of Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverAttributes() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.discoverService()` - -Discover the attributes of a particular service on the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverService(serviceUuid) - -``` - -#### Parameters - -- **serviceUuid:** service UUID to discover (as a **String**) - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover service attributes - Serial.println("Discovering service attributes ..."); - if (peripheral.serviceUuid("fffe")) { - Serial.println("Service attributes discovered"); - } else { - Serial.println("Service attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.deviceName()` - -Query the device name (BLE characteristic UUID 0x2a00) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.deviceName() - -``` - -#### Parameters - -None - -#### Returns -- **Device name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.appearance()` - -Query the appearance (BLE characteristic UUID 0x2a01) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.appearance() - -``` - -#### Parameters - -None - -#### Returns -- **Appearance value** (as a number). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.serviceCount()` - -Query the number of services discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.serviceCount() - -``` - -#### Parameters - -None - -#### Returns -- The number of **services discovered** for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int serviceCount = peripheral.serviceCount(); - - Serial.print(serviceCount); - Serial.println(" services discovered"); - - // ... - } - - -``` - -### `bleDevice.hasService()` - -Query if the Bluetooth® Low Energy device has a particular service. - -#### Syntax - -``` -bleDevice.hasService(uuid) -bleDevice.hasService(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the service, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasService("180f")) { - Serial.println("Peripheral has battery service"); - } - - // ... - } - - -``` - -### `bleDevice.service()` - -Get a BLEService representing a Bluetooth® Low Energy service the device provides. - -#### Syntax - -``` -bleDevice.service(index) -bleDevice.service(uuid) -bleDevice.service(uuid, index) - -``` - -#### Parameters - -- **index**: index of service -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLEService** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleDevice.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int characteristicCount = peripheral.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered"); - - // ... - } - - -``` - -### `bleDevice.hasCharacteristic()` - -Query if the Bluetooth® Low Energy device has a particular characteristic. - -#### Syntax - -``` -bleDevice.hasCharacteristic(uuid) -bleDevice.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasCharacteristic("2a19")) { - Serial.println("Peripheral has battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.hasLocalName()` - -Query if a discovered Bluetooth® Low Energy device is advertising a local name. - -#### Syntax - -``` -bleDevice.hasLocalName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **true**, if the device is advertising a local name, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.hasAdvertisedServiceUuid()` - -Query if a discovered Bluetooth® Low Energy device is advertising a service UUID. - -#### Syntax - -``` -bleDevice.hasAdvertisedServiceUuid() -bleDevice.hasAdvertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. - -#### Returns -- **true**, if the device is advertising a service UUID, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuidCount()` - -Query the number of advertised services a discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuidCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.localName()` - -Query the local name a discovered Bluetooth® Low Energy device is advertising with. - -#### Syntax - -``` -bleDevice.localName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **Advertised local name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuid()` - -Query an advertised service UUID discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuid() -bleDevice.advertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. - -#### Returns -- Advertised service **UUID** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.connect()` - -Connect to a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.connect() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the connection was successful, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // ... - } - - -``` - -## BLEService Class - -Used to enable the services board provides or interact with services a remote board provides. - -### `BLEService()` - -Create a new Bluetooth® Low Energy service. - -#### Syntax - -``` -BLEService(uuid) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format - -#### Returns -- New **BLEService** with the specified **UUID** - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -``` - -### `bleService.uuid()` - -Query the UUID of the specified BLEService. - -#### Syntax - -``` -bleService.uuid() - -``` - -#### Parameters - -None - -#### Returns -- UUID of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -Serial.print("LED service UUID = "); -Serial.println(ledService.uuid()); - - - -``` - -### `bleService.addCharacteristic()` - -Add a BLECharacteristic to the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.addCharacteristic(bleCharacteristic) - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, readable and writable by central -BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); - - - - -// add the characteristic to the service -ledService.addCharacteristic(switchCharacteristic); - - - -``` - -### `bleService.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy service. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - int characteristicCount = batteryService.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered in battery service"); - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.hasCharacteristic()` - -Query if the Bluetooth® Low Energy service has a particular characteristic. - -#### Syntax - -``` -bleService.hasCharacteristic(uuid) -bleService.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the service provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - if (batteryService.hasCharacteristic("2a19")) { - Serial.println("Battery service has battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the service provides. - -#### Syntax - -``` -bleService.characteristic(index) -bleService.characteristic(uuid) -bleService.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -## BLECharacteristic Class - -Used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. - -### `BLECharacteristic()` - -Create a new Bluetooth® Low Energy characteristic. - -#### Syntax - -``` -BLECharacteristic(uuid, properties, value, valueSize) -BLECharacteristic(uuid, properties, stringValue) - -BLEBoolCharacteristic(uuid, properties) -BLEBooleanCharacteristic(uuid, properties) -BLECharCharacteristic(uuid, properties) -BLEUnsignedCharCharacteristic(uuid, properties) -BLEByteCharacteristic(uuid, properties) -BLEShortCharacteristic(uuid, properties) -BLEUnsignedShortCharacteristic(uuid, properties) -BLEWordCharacteristic(uuid, properties) -BLEIntCharacteristic(uuid, properties) -BLEUnsignedIntCharacteristic(uuid, properties) -BLELongCharacteristic(uuid, properties) -BLEUnsignedLongCharacteristic(uuid, properties) -BLEFloatCharacteristic(uuid, properties) -BLEDoubleCharacteristic(uuid, properties) -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format -- **properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) -- **valueSize**: (maximum) size of characteristic value -- **stringValue**: value as a string - -#### Returns -- New **BLECharacteristic** with the specified **UUID** and value - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - -``` - -### `bleCharacteristic.uuid()` - -Query the UUID of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -Serial.print("Switch characteristic UUID = "); -Serial.println(switchCharacteristic.uuid()); - - - -``` - -### `bleCharacteristic.properties()` - -Query the property mask of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.properties() - -``` - -#### Parameters - -None - -#### Returns -- **Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -byte properties = switchCharacteristic.properties(); - -if (properties & BLERead) { - // characteristic is readable ... -} - -if (properties & (BLEWrite | BLEWriteWithoutResponse)) { - // characteristic is writable ... -} - - -``` - -### `bleCharacteristic.valueSize()` - -Query the maximum value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- The **maximum value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value size = "); -Serial.println(switchCharacteristic.valueSize()); - - -``` - -### `bleCharacteristic.value()` - -Query the current value of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.value() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** of the characteristic, value type depends on the constructor used - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - - - -``` - -### `bleCharacteristic.valueLength()` - -Query the current value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value length = "); -Serial.println(switchCharacteristic.valueLength()); - - -``` - -### `bleCharacteristic.readValue()` - -Read the current value of the characteristic. If the characteristic is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleCharacteristic.readValue(buffer, length) -bleCharacteristic.readValue(value) - -``` - -#### Parameters - -- **buffer:** byte array to read value into length: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -### `bleCharacteristic.writeValue()` - -Write the value of the characteristic. If the characteristic is on a remote device, a write request or command will be sent. - -#### Syntax - -``` -bleCharacteristic.writeValue(buffer, length) -bleCharacteristic.writeValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to write value with -- **length**: number of bytes of the buffer argument to write -- **value**: value to write - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - - // read the button pin - int buttonState = digitalRead(buttonPin); - - if (oldButtonState != buttonState) { - // button changed - oldButtonState = buttonState; - - if (buttonState) { - Serial.println("button pressed"); - - // button is pressed, write 0x01 to turn the LED on - ledCharacteristic.writeValue((byte)0x01); - } else { - Serial.println("button released"); - - // button is released, write 0x00 to turn the LED off - ledCharacteristic.writeValue((byte)0x00); - } - } - - -``` - -### `bleCharacteristic.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -bleCharacteristic.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) -- **callback**: function to call when the event occurs - -#### Returns -Nothing - -#### Example - -```arduino - -// create switch characteristic and allow remote device to read and write -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // assign event handlers for characteristic - switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); - - - -void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { - // central wrote new value to characteristic, update LED - Serial.print("Characteristic event, written: "); - - if (switchCharacteristic.value()) { - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); - } else { - Serial.println("LED off"); - digitalWrite(ledPin, LOW); - } -} - - -``` - -### `bleCharacteristic.broadcast()` - -Broadcast the characteristics value as service data when advertising. - -#### Syntax - -``` -bleCharacteristic.broadcast() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - -// create button characteristic and allow remote device to get notifications -BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify | BLEBroadcast); - - - -buttonCharacteristic.broadcast(); - - - -``` - -### `bleCharacteristic.written()` - -Query if the characteristic value has been written by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.written() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been written by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - - // while the central is still connected to peripheral: - while (central.connected()) { - // if the remote device wrote to the characteristic, - // use the value to control the LED: - if (switchCharacteristic.written()) { - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - } - } - - // when the central disconnects, print it out: - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } - - - - -``` - -### `bleCharacteristic.subscribed()` - -Query if the characteristic has been subscribed to by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.subscribed() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - - - - if (batteryLevelChar.subscribed()) { - // set a new value , that well be pushed to subscribed Bluetooth® Low Energy devices - batteryLevelChar.writeValue(0xab); - } - - -``` - -### `bleCharacteristic.addDescriptor()` - -Add a BLEDescriptor to the characteristic. - -#### Syntax - -``` -bleCharacteristic.addDescriptor(bleDescriptor) - -``` - -#### Parameters - -- **bleDescriptor**: descriptor to add to the characteristic - -#### Returns -Nothing - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - -BLEDescriptor batteryLevelDescriptor("2901", "millis"); - - - - - - batteryLevelChar.addDescriptor(batteryLevelDescriptor); - - -``` - -### `bleCharacteristic.descriptorCount()` - -Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. - -#### Syntax - -``` -bleCharacteristic.descriptorCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic - -#### Example - -```arduino - - // loop the descriptors of the characteristic and explore each - for (int i = 0; i < characteristic.descriptorCount(); i++) { - BLEDescriptor descriptor = characteristic.descriptor(i); - - // ... - } - - -``` - -### `bleCharacteristic.hasDescriptor()` - -Check if a characteristic has a particular descriptor. - -#### Syntax - -``` -bleCharacteristic.hasDescriptor(uuid) -bleCharacteristic.hasDescriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- **true**, if the characteristic has a matching descriptor, -- otherwise **false**. - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.descriptor()` - -Get a BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -bleCharacteristic.descriptor(index) -bleCharacteristic.descriptor(uuid) -bleCharacteristic.descriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.canRead()` - -Query if a Bluetooth® Low Energy characteristic is readable. - -#### Syntax - -``` -bleCharacteristic.canRead() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is readable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canRead("2901")) { - Serial.println("characteristic is readable"); - } - - -``` - -read - -Perform a read request for the characteristic. - -#### Syntax - -``` -bleCharacteristic.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (characteristic.read()) { - Serial.println("characteristic value read"); - - // ... - } else { - Serial.println("error reading characteristic value"); - } - - -``` - -### `bleCharacteristic.canWrite()` - -Query if a Bluetooth® Low Energy characteristic is writable. - -#### Syntax - -``` -bleCharacteristic.canWrite() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is writable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canWrite()) { - Serial.println("characteristic is writable"); - } - - -``` - -### `bleCharacteristic.canSubscribe()` - -Query if a Bluetooth® Low Energy characteristic is subscribable. - -#### Syntax - -``` -bleCharacteristic.canSubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is subscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canSubscribe()) { - Serial.println("characteristic is subscribable"); - } - - -``` - -### `bleCharacteristic.subscribe()` - -Subscribe to a Bluetooth® Low Energy characteristics notification or indications. - -#### Syntax - -``` -bleCharacteristic.subscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - -``` - -### `bleCharacteristic.canUnsubscribe()` - -Query if a Bluetooth® Low Energy characteristic is unsubscribable. - -#### Syntax - -``` -bleCharacteristic.canUnsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is unsubscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canUnsubscribe()) { - Serial.println("characteristic is unsubscribable"); - } - - -``` - -### `bleCharacteristic.unsubscribe()` - -Unsubscribe to a Bluetooth® Low Energy characteristics notifications or indications. - -#### Syntax - -``` -bleCharacteristic.unsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - simpleKeyCharacteristic.unsubscribe(); - - -``` - -### `bleCharacteristic.valueUpdated()` - -Has the characteristics value been updated via a notification or indication. - -#### Syntax - -``` -bleCharacteristic.valueUpdated() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the characteristics value been updated via a notification or indication - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -## BLEDescriptor Class - -Used to describe a characteristic the board offers - -### `BLEDescriptor()` - -Create a new Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -BLEDescriptor(uuid, value, valueSize) -BLEDescriptor(uuid, stringValue) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in string format -- **value**: byte array value -- **valueSize**: size of byte array value -- **stringValue**: value as a string - -#### Returns -- New **BLEDescriptor** with the specified **UUID** and value - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -``` - -### `bleDescriptor.uuid()` - -Query the UUID of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy descriptor (as a String). - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor UUID = "); -Serial.println(millisLabelDescriptor.uuid()); - - - -``` - -### `bleDescriptor.valueSize()` - -Query the value size of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- **Value size** (in bytes) of the Bluetooth® Low Energy descriptor. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor value size = "); -Serial.println(millisLabelDescriptor.valueSize()); - - - -``` - -### `bleDescriptor.valueLength()` - -Query the length, in bytes, of the descriptor current value. - -#### Syntax - -``` -bleDescriptor.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- **Length of descriptor** value in bytes. - -#### Example - -```arduino - - // read the descriptor value - descriptor.read(); - - // print out the value of the descriptor - Serial.print(", value 0x"); - printData(descriptor.value(), descriptor.valueLength()); - - // ... - - void printData(const unsigned char data[], int length) { - for (int i = 0; i < length; i++) { - unsigned char b = data[i]; - - if (b < 16) { - Serial.print("0"); - } - - Serial.print(b, HEX); - } - } - - -``` - -### `bleDescriptor.value()` - -Query the value of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.value() - -``` - -#### Parameters - -None - -#### Returns -- Value byte array of the **BLE descriptor**. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - - - int descriptorValueSize = millisLabelDescriptor.valueSize(); - byte descriptorValue[descriptorValueSize]; - - for (int i = 0; i < descriptorValueSize; i++) { - descriptorValue[i] = millisLabelDescriptor.value()[i]; - } - - - -``` - -### `bleDescriptor.readValue()` - -Read the current value of the descriptor. If the descriptor is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleDescriptor.readValue(buffer, length) -bleDescriptor.readValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to read value into -- **length**: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - - -```arduino - - byte value = 0; - - // get the value, descriptor is 1 byte so use byte value - descriptor.readValue(value); - - -``` - -### `bleDescriptor.read()` - -Perform a read request for the descriptor. - -#### Syntax - -``` -bleDescriptor.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (descriptor.read()) { - Serial.println("descriptor value read"); - - // ... - } else { - Serial.println("error reading descriptor value"); - } - -``` diff --git a/docs/assets/ble-bulletin-board-model.png b/docs/assets/ble-bulletin-board-model.png deleted file mode 100644 index 409ae9e89385b0c27d8331f7d52fff2a8f71e097..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 41914 zcmc$`WmuJ6*Y6Fulu}Akx_f~%NO!1!(%nc)mz2`o9nzqHbayw>B_J)GO3ORf<#pfk zKF{8tw+C|ImeJM``iSO0Q>e14f#-o4#UEkWrsLaYH5>dnSzoQ4Est zRzUFgrEwC!FNuvwuVSRs3NIBvVJLx(`r*C7H1aWqLU)^@xWxKGs0H#tG3Uu*@=cHW z((Go<^sMQD$80S+m)lef_hE#!jtO*))Qp6OaJ zB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#_7BakRR=P=p1b92&9r(I-@J&F`G1xB~e==d9(X8xJ7g;0EBY#9mj zvKlL5a66`tH?dU`OmPGI%#J|*Z%1!t5y)A@6)+0cAvJTR3vK6Z9d5M^$!ybcE7xa6 zgKz_(6^~+cq3gi%m8)!DeP0NbJu;Y%GP5Tev=jZ_G$Z&R)=n2$om=lbey(2LU|N*< z{8cEY5Ckxbm=mNw#`M0;Q<|HPllJr0%X{|tI_2eNyBK`iAWQF>LG`+U)jxPY@uPYW zBJ9i^9rD_Sq!i^srzcU8KLJymkI9Zw7~k+P6XD;tz$@c}Ss~SKZ~Vro{UnummI%pM z18<|cXCq4#?tn9Xc~bkOMb177Vq{fZP8djR-&-kBP16?Q)_O>O?l8P(lw+7-6$7SO z`oPw+D4Wmk?3f@Uc_oB1muE@W{fU0Ve)X+Pocl1zRBn8^suw#s65JseWcMB>RFdM$w+LBnW^d zy;H$(R6LS-`3%9WFryfN$Y!lT0M~(cV2XRMbqg~0jJl28SP$!Eudvz5JukD*o4$Zcx83fBza*u8Uln&H=fXjt8BBoXTeU@5Rc;=ohhC z`iNEG!2A<1BmK);57&GzHJj-9w#EexY(#mn*#44}b?G*PfS zs;MEqRaOA%g6%1P?NJlnD`rS`?)dBdS?2DKxj}n}O|`` - -## A quick introduction to BLE - -Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Classic", and the Bluetooth® Low Energy. Bluetooth® Low Energy is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. - -Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Bluetooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. - -![Communication between central and peripheral devices](https://raw.githubusercontent.com/arduino-libraries/ArduinoBLE/master/docs/assets/ble-bulletin-board-model.png) - -Think of a Bluetooth® LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. - -The information presented by a peripheral is structured as **services**, each of which is subdivided into **characteristics**. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices. If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not. If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it. - -## Notify - -The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgment of the pushed data. - -The client-server structure of Bluetooth® LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. - -## Update a characteristic - -Your peripheral should update characteristics when there's a significant change to them. For example, when a switch changes from off to on, update its characteristic. When an analog sensor changes by a significant amount, update its characteristic. - -Just as with writing to a characteristic, you could update your characteristics on a regular interval, but this wastes processing power and energy if the characteristic has not changed. - -## Central and Peripheral Devices - -**Central** devices are **clients**. They read and write data from peripheral devices. **Peripheral** devices are **servers**. They provide data from sensors as readable characteristics, and provide read/writable characteristics to control actuators like motors, lights, and so forth. - -## Services, characteristics, and UUIDs - -A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use standard services (see section 3.4 in the [Assigned Numbers document](https://www.bluetooth.com/specifications/assigned-numbers/)). - -Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. - -## Service design patterns - -A characteristic value can be up to 512 bytes long. This is a key constraint in designing services. Given this limit, you should consider how best to store data about your sensors and actuators most effectively for your application. The simplest design pattern is to store one sensor or actuator value per characteristic, in ASCII encoded values. - -|**Characteristic**|**Value**| -|------------------|---------| -|Accelerometer X|200| -|Accelerometer Y|134| -|Accelerometer Z|150| - -This is also the most expensive in memory terms, and would take the longest to read. But it's the simplest for development and debugging. - -You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it. - -|**Characteristic**|**Value**| -|------------------|---------| -|Motor Speed, Direction|150,1| -|Accelerometer X, Y, Z|200,133,150| - -This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as an ASCII-encoded string. - -## Read/write/notify/indicate - -There are 4 things a central device can do with a characteristic: - -- **Read:** ask the peripheral to send back the current value of the characteristic. Often used for characteristics that don't change very often, for example characteristics used for configuration, version numbers, etc. -- **Write:** modify the value of the characteristic. Often used for things that are like commands, for example telling the peripheral to turn a motor on or off. -- **Indicate** and **Notify:** ask the peripheral to continuously send updated values of the characteristic, without the central having to constantly ask for it. - -## Advertising and GAP - -BLE devices let other devices know that they exist by advertising using the **General Advertising Profile (GAP)**. Advertising packets can contain a device name, some other information, and also a list of the services it provides. - -Advertising packets have a limited size. You will only be able to fit a single 128-bit service UUID in the packet. Make sure the device name is not too long, or you won't even be able to fit that. - -You can provide additional services that are not advertised. Central devices will learn about these through the connection/bonding process. Non-advertised services cannot be used to discover devices, though. Sometimes this is not an issue. For example, you may have a custom peripheral device with a custom service, but in your central device app you may know that it also provides the Battery Service and other services. - -## GATT - -The Bluetooth LE protocol operates on multiple layers. **General Attribute Profile (GATT)** is the layer that defines services and characteristics and enables read/write/notify/indicate operations on them. When reading more about GATT, you may encounter GATT concepts of a "server" and "client". These don't always correspond to central and peripherals. In most cases, though, the peripheral is the GATT server (since it provides the services and characteristics), while the central is the GATT client. - -## Library structure - -As the library enables multiple types of functionality, there are a number of different classes. - -- `BLE` used to enable the Bluetooth® Low Energy module. -- `BLEDevice` used to get information about the devices connected or discovered while scanning. -- `BLEService` used to enable the services board provides or interact with services a remote board provides. -- `BLECharacteristic` used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. -- `BLEDescriptor` used to describe a characteristic the board offers. diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 953de7d8..064bb29e 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,9 +6,7 @@ it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button with pull-up resistor connected to pin 2. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -16,7 +14,7 @@ This example code is in the public domain. */ -#include +#include // variables for button const int buttonPin = 2; diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 919cdde0..4a72a697 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,8 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -14,7 +13,7 @@ This example code is in the public domain. */ -#include +#include void setup() { Serial.begin(9600); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 162e3c07..99e13696 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,13 +5,12 @@ address, local name, advertised service UUID's. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include +#include void setup() { Serial.begin(9600); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 2687a3b9..63ab2753 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,13 +7,12 @@ reported for every single advertisement it makes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include +#include void setup() { Serial.begin(9600); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 27c421fe..26ee667d 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,14 +8,13 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. - TI SensorTag This example code is in the public domain. */ -#include +#include void setup() { Serial.begin(9600); diff --git a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino index 979b69a8..806c41bd 100644 --- a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino +++ b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -1,4 +1,4 @@ -#include +#include BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino index 5e7ba7f3..88b17e29 100644 --- a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino +++ b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -1,4 +1,4 @@ -#include +#include BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino index 0d786627..3413127e 100644 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -5,8 +5,7 @@ level characteristic. The A0 pin is used to calculate the battery level. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include +#include // Bluetooth® Low Energy Battery Service BLEService batteryService("180F"); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index cbc14dd8..baa64b87 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,9 +6,7 @@ represents the state of the button. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button connected to pin 4 + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -17,7 +15,7 @@ This example code is in the public domain. */ -#include +#include const int ledPin = LED_BUILTIN; // set ledPin to on-board LED const int buttonPin = 4; // set buttonPin to digital pin 4 diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 59bda5ed..8bb90106 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,8 +6,7 @@ library are used. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -16,7 +15,7 @@ This example code is in the public domain. */ -#include +#include BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino deleted file mode 100644 index dfc9f4a0..00000000 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ /dev/null @@ -1,265 +0,0 @@ -/* - Battery Monitor - - This example creates a BLE peripheral with the standard battery service and - level characteristic. The A0 pin is used to calculate the battery level. - - The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - You can use a generic BLE central app, like LightBlue (iOS and Android) or - nRF Connect (Android), to interact with the services and characteristics - created in this sketch. - - This example code is in the public domain. -*/ - -#include - - -#define PAIR_BUTTON 3 // button for pairing -#define PAIR_LED 24 // LED used to signal pairing -#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic -#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms - -#define CTRL_LED LED_BUILTIN - - - // BLE Battery Service -BLEService batteryService("180F"); - -// BLE Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes -BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); - - -// Add BLEEncryption tag to require pairing. This controls the LED. -BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); - -int oldBatteryLevel = 0; // last battery level reading from analog input -unsigned long previousMillis = 0; // last time the battery level was checked, in ms -unsigned long pairingStarted = 0; // pairing start time when button is pressed -bool wasConnected = 0; -bool acceptOrReject = true; - -void setup() { - Serial.begin(9600); // initialize serial communication - while (!Serial); - - pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected - pinMode(PAIR_LED, OUTPUT); - pinMode(PAIR_BUTTON, INPUT_PULLUP); - - - Serial.println("Serial connected"); - - // Callback function with confirmation code when new device is pairing. - BLE.setDisplayCode([](uint32_t confirmCode){ - Serial.println("New device pairing request."); - Serial.print("Confirm code matches pairing device: "); - char code[6]; - sprintf(code, "%06d", confirmCode); - Serial.println(code); - }); - - // Callback to allow accepting or rejecting pairing - BLE.setBinaryConfirmPairing([&acceptOrReject](){ - Serial.print("Should we confirm pairing? "); - delay(5000); - if(acceptOrReject){ - acceptOrReject = false; - Serial.println("yes"); - return true; - }else{ - acceptOrReject = true; - Serial.println("no"); - return false; - } - }); - - // IRKs are keys that identify the true owner of a random mac address. - // Add IRKs of devices you are bonded with. - BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs){ - // Set to number of devices - *nIRKs = 2; - - *BDAddrs = new uint8_t*[*nIRKs]; - *IRKs = new uint8_t*[*nIRKs]; - *BDaddrTypes = new uint8_t[*nIRKs]; - - // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random - (*BDAddrs)[0] = new uint8_t[6]; - (*IRKs)[0] = new uint8_t[16]; - memcpy((*IRKs)[0] , device1IRK,16); - memcpy((*BDAddrs)[0], device1Mac, 6); - - - (*BDaddrTypes)[1] = 0; - (*BDAddrs)[1] = new uint8_t[6]; - (*IRKs)[1] = new uint8_t[16]; - memcpy((*IRKs)[1] , device2IRK,16); - memcpy((*BDAddrs)[1], device2Mac, 6); - - - return 1; - }); - // The LTK is the secret key which is used to encrypt bluetooth traffic - BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ - // address is input - Serial.print("Received request for address: "); - btct.printBytes(address,6); - - // Set these to the MAC and LTK of your devices after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - if(memcmp(device1Mac, address, 6) == 0) { - memcpy(LTK, device1LTK, 16); - return 1; - }else if(memcmp(device2Mac, address, 6) == 0) { - memcpy(LTK, device2LTK, 16); - return 1; - } - return 0; - }); - BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store IRK : ")); - btct.printBytes(IRK,16); - return 1; - }); - BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store LTK : ")); - btct.printBytes(LTK,16); - return 1; - }); - - while(1){ - // begin initialization - if (!BLE.begin()) { - Serial.println("starting BLE failed!"); - delay(200); - continue; - } - Serial.println("BT init"); - delay(200); - - /* Set a local name for the BLE device - This name will appear in advertising packets - and can be used by remote devices to identify this BLE device - The name can be changed but maybe be truncated based on space left in advertisement packet - */ - - BLE.setDeviceName("Arduino"); - BLE.setLocalName("BatteryMonitor"); - - BLE.setAdvertisedService(batteryService); // add the service UUID - batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic - batteryService.addCharacteristic(stringcharacteristic); - batteryService.addCharacteristic(secretValue); - - BLE.addService(batteryService); // Add the battery service - batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic - char* stringCharValue = new char[32]; - stringCharValue = "string"; - stringcharacteristic.writeValue(stringCharValue); - secretValue.writeValue(0); - - delay(1000); - - // prevent pairing until button is pressed (will show a pairing rejected message) - BLE.setPairable(false); - - /* Start advertising BLE. It will start continuously transmitting BLE - advertising packets and will be visible to remote BLE central devices - until it receives a new connection */ - - // start advertising - if(!BLE.advertise()){ - Serial.println("failed to advertise bluetooth."); - BLE.stopAdvertise(); - delay(500); - }else{ - Serial.println("advertising..."); - break; - } - BLE.end(); - delay(100); - } -} - - -void loop() { - // wait for a BLE central - BLEDevice central = BLE.central(); - - - // If button is pressed, allow pairing for 30 sec - if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ - pairingStarted = millis(); - BLE.setPairable(Pairable::ONCE); - Serial.println("Accepting pairing for 30 s"); - } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ - BLE.setPairable(false); - Serial.println("No longer accepting pairing"); - } - // Make LED blink while pairing is allowed - digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); - - - // if a central is connected to the peripheral: - if (central && central.connected()) { - if (!wasConnected){ - wasConnected = true; - Serial.print("Connected to central: "); - // print the central's BT address: - Serial.println(central.address()); - } - - // check the battery level every 200ms - // while the central is connected: - long currentMillis = millis(); - // if 200ms have passed, check the battery level: - if (currentMillis - previousMillis >= 1000) { - previousMillis = currentMillis; - updateBatteryLevel(); - digitalWrite(CTRL_LED, secretValue.value()>0 ? HIGH : LOW); - } - } else if (wasConnected){ - wasConnected = false; - Serial.print("Disconnected from central: "); - Serial.println(central.address()); - } - -} - -void updateBatteryLevel() { - /* Read the current voltage level on the A0 analog input pin. - This is used here to simulate the charge level of a battery. - */ - int battery = analogRead(A0); - int batteryLevel = map(battery, 0, 1023, 0, 100); - - if (batteryLevel != oldBatteryLevel) { // if the battery level has changed - // Serial.print("Battery Level % is now: "); // print it - // Serial.println(batteryLevel); - batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic - oldBatteryLevel = batteryLevel; // save the level for next comparison - } -} \ No newline at end of file diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 65b88605..7223365f 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,8 +5,7 @@ characteristic to control an LED. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include +#include BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service diff --git a/extras/arduino-ble-parser.py b/extras/arduino-ble-parser.py deleted file mode 100644 index 8f678711..00000000 --- a/extras/arduino-ble-parser.py +++ /dev/null @@ -1,85 +0,0 @@ -''' -Convert ArduinoBLE debug files into Btsnoop files ready to be analyzed using wireshark or hcidump -Btsnoop file format reference - https://www.fte.com/WebHelpII/Sodera/Content/Technical_Information/BT_Snoop_File_Format.htm -''' - -import os -import argparse - -DEBUG = False - -parser = argparse.ArgumentParser() -parser.add_argument('-i', dest='inputPath', type=str, required=True, help='input file containing debug log') -parser.add_argument('-o', dest='outputPath', type=str, required=True, help='result file that will contain the btsnoop encoded debug file') -args = parser.parse_args() - -# Extract only hci debug messages -def extractHCIDebugPrint(inputPath, outputPath): - inputFile = open(inputPath, 'r') - outputFile = open(outputPath, 'w') - for inputLine in inputFile: - lineItems = inputLine.split() - if (len(lineItems) < 7) or (lineItems[1] != "->") or (lineItems[2] != "HCI"): - if (len(lineItems) < 4) or (lineItems[0] != "HCI") or ((lineItems[3] != "<-") and (lineItems[3] != "->")): - continue - outputFile.write(inputLine) - outputFile.close() - -# Return packet in btsnoop format -def buildBinaryPacket(hciMessage, hciDirection, hciType): - commandFlag = 1 if (hciType == "COMMAND" or hciType == "EVENT") else 0 - directionFlag = 0 if (hciDirection == "TX") else 1 - flagHex = ("0" * 7) + str((commandFlag * 2) + directionFlag) - timestampHex = "0" * 16 - packetDropHex = "0" * 8 - dataLengthHex = format( (int(len(hciMessage) / 2)), 'x') - packetLengthHex = ("0" * (8 - len(dataLengthHex))) + dataLengthHex - binaryPacket = bytearray.fromhex(packetLengthHex + packetLengthHex + flagHex + packetDropHex + timestampHex + hciMessage) - if DEBUG: - print(len(hciMessage)) - print(dataLengthHex) - print(packetLengthHex) - print(flagHex) - print('\n') - return binaryPacket - -def buildBinaryHeader(): - defaultHeader = "6274736e6f6f700000000001000003ea" - binaryHeader = bytearray.fromhex(defaultHeader) - return binaryHeader - -def convertToBtsnoop(inputPath, outputPath): - # Open output file and write the Btsnoop header - outputFile = open(outputPath,'wb') - header = buildBinaryHeader() - outputFile.write(header) - - # Open input file containing HCI debug packets - inputFile = open(inputPath, 'r') - for inputLine in inputFile: - lineItems = inputLine.split() - # For a safer script, do not use indexes but look for symbols in the line - baseIndex = lineItems.index("HCI") - hciMessage = lineItems[baseIndex + 4] - hciDirection = lineItems[baseIndex + 2] - hciType = lineItems[baseIndex + 1] - # Build and write the encoded line - btsnoopPacket = buildBinaryPacket(hciMessage, hciDirection, hciType) - outputFile.write(btsnoopPacket) - if DEBUG: - print(hciDirection) - print(hciMessage) - print(hciType) - print('\n') - outputFile.close() - -inputPath = args.inputPath -outputPath = args.outputPath -tempFile = "temp-debug-print.txt" -# Run -extractHCIDebugPrint(inputPath,tempFile) -convertToBtsnoop(tempFile, outputPath) -# Delete temp file -os.remove(tempFile) - diff --git a/extras/test/.gitignore b/extras/test/.gitignore deleted file mode 100644 index c795b054..00000000 --- a/extras/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt deleted file mode 100644 index bbba16ca..00000000 --- a/extras/test/CMakeLists.txt +++ /dev/null @@ -1,126 +0,0 @@ -########################################################################## - -set(CMAKE_VERBOSE_MAKEFILE ON) -cmake_minimum_required(VERSION 2.8) - -########################################################################## - -project(testArduinoBLE) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -set(COMMON_TEST_SRCS - src/test_main.cpp - src/Arduino.cpp - src/util/itoa.c - src/util/TestUtil.cpp - src/util/String.cpp - src/util/Common.cpp -) - -set(DUT_SRCS - ../../src/utility/BLEUuid.cpp - ../../src/BLEDevice.cpp - ../../src/BLECharacteristic.cpp - ../../src/BLEDescriptor.cpp - ../../src/BLEService.cpp - ../../src/BLEAdvertisingData.cpp - ../../src/utility/ATT.cpp - ../../src/utility/GAP.cpp - ../../src/utility/HCI.cpp - ../../src/utility/GATT.cpp - ../../src/utility/L2CAPSignaling.cpp - ../../src/local/BLELocalAttribute.cpp - ../../src/local/BLELocalCharacteristic.cpp - ../../src/local/BLELocalDescriptor.cpp - ../../src/local/BLELocalDevice.cpp - ../../src/local/BLELocalService.cpp - ../../src/remote/BLERemoteAttribute.cpp - ../../src/remote/BLERemoteCharacteristic.cpp - ../../src/remote/BLERemoteDescriptor.cpp - ../../src/remote/BLERemoteDevice.cpp - ../../src/remote/BLERemoteService.cpp - ../../src/BLEStringCharacteristic.cpp - ../../src/BLETypedCharacteristics.cpp -) - -set(TEST_TARGET_UUID_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_uuid/test_uuid.cpp - # DUT files - #${DUT_SRCS} - ../../src/utility/BLEUuid.cpp -) - -set(TEST_TARGET_DISC_DEVICE_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_discovered_device/test_discovered_device.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_discovered_device/FakeGAP.cpp -) - -set(TEST_TARGET_ADVERTISING_DATA_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_advertising_data/test_advertising_data.cpp - src/test_advertising_data/test_service.cpp - src/test_advertising_data/test_local_name.cpp - src/test_advertising_data/test_manufacturer.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_advertising_data/FakeBLELocalDevice.cpp -) - -########################################################################## - -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage") - -########################################################################## - -add_executable(TEST_TARGET_UUID ${TEST_TARGET_UUID_SRCS}) -add_executable(TEST_TARGET_DISC_DEVICE ${TEST_TARGET_DISC_DEVICE_SRCS}) -add_executable(TEST_TARGET_ADVERTISING_DATA ${TEST_TARGET_ADVERTISING_DATA_SRCS}) - -########################################################################## - -include_directories(include) -include_directories(include/util) -include_directories(../../src) -include_directories(../../src/local) -include_directories(../../src/remote) -include_directories(../../src/utility) -include_directories(external/catch/v2.12.1/include) - -target_include_directories(TEST_TARGET_DISC_DEVICE PUBLIC include/test_discovered_device) -target_include_directories(TEST_TARGET_ADVERTISING_DATA PUBLIC include/test_advertising_data) - -########################################################################## - -target_compile_definitions(TEST_TARGET_DISC_DEVICE PUBLIC FAKE_GAP) -target_compile_definitions(TEST_TARGET_ADVERTISING_DATA PUBLIC FAKE_BLELOCALDEVICE) - -########################################################################## - -# Build unit tests as a post build step -add_custom_command(TARGET TEST_TARGET_UUID POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_UUID -) -add_custom_command(TARGET TEST_TARGET_DISC_DEVICE POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_DISC_DEVICE -) -add_custom_command(TARGET TEST_TARGET_ADVERTISING_DATA POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_ADVERTISING_DATA -) diff --git a/extras/test/external/catch/v2.12.1/include/catch.hpp b/extras/test/external/catch/v2.12.1/include/catch.hpp deleted file mode 100644 index 1d2c9bb6..00000000 --- a/extras/test/external/catch/v2.12.1/include/catch.hpp +++ /dev/null @@ -1,17698 +0,0 @@ -/* - * Catch v2.12.1 - * Generated: 2020-04-21 19:29:20.964532 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -// start catch.hpp - - -#define CATCH_VERSION_MAJOR 2 -#define CATCH_VERSION_MINOR 12 -#define CATCH_VERSION_PATCH 1 - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// start catch_suppress_warnings.h - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wswitch-enum" -# pragma clang diagnostic ignored "-Wcovered-switch-default" -# endif -#elif defined __GNUC__ - // Because REQUIREs trigger GCC's -Wparentheses, and because still - // supported version of g++ have only buggy support for _Pragmas, - // Wparentheses have to be suppressed globally. -# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details - -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wpadded" -#endif -// end catch_suppress_warnings.h -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -# define CATCH_CONFIG_ALL_PARTS -#endif - -// In the impl file, we want to have access to all parts of the headers -// Can also be used to sanely support PCHs -#if defined(CATCH_CONFIG_ALL_PARTS) -# define CATCH_CONFIG_EXTERNAL_INTERFACES -# if defined(CATCH_CONFIG_DISABLE_MATCHERS) -# undef CATCH_CONFIG_DISABLE_MATCHERS -# endif -# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -# endif -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) -// start catch_platform.h - -#ifdef __APPLE__ -# include -# if TARGET_OS_OSX == 1 -# define CATCH_PLATFORM_MAC -# elif TARGET_OS_IPHONE == 1 -# define CATCH_PLATFORM_IPHONE -# endif - -#elif defined(linux) || defined(__linux) || defined(__linux__) -# define CATCH_PLATFORM_LINUX - -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) -# define CATCH_PLATFORM_WINDOWS -#endif - -// end catch_platform.h - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// start catch_user_interfaces.h - -namespace Catch { - unsigned int rngSeed(); -} - -// end catch_user_interfaces.h -// start catch_tag_alias_autoregistrar.h - -// start catch_common.h - -// start catch_compiler_capabilities.h - -// Detect a number of compiler features - by compiler -// The following features are defined: -// -// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? -// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? -// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? -// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? -// **************** -// Note to maintainers: if new toggles are added please document them -// in configuration.md, too -// **************** - -// In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -#ifdef __cplusplus - -# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) -# define CATCH_CPP14_OR_GREATER -# endif - -# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) -# define CATCH_CPP17_OR_GREATER -# endif - -#endif - -#if defined(__cpp_lib_uncaught_exceptions) -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -// We have to avoid both ICC and Clang, because they try to mask themselves -// as gcc, and we want only GCC in this block -#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) - -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) - -#endif - -#if defined(__clang__) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) - -// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug -// which results in calls to destructors being emitted for each temporary, -// without a matching initialization. In practice, this can result in something -// like `std::string::~string` being called on an uninitialized value. -// -// For example, this code will likely segfault under IBM XL: -// ``` -// REQUIRE(std::string("12") + "34" == "1234") -// ``` -// -// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. -# if !defined(__ibmxl__) -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg) */ -# endif - -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ - _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) - -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Assume that non-Windows platforms support posix signals by default -#if !defined(CATCH_PLATFORM_WINDOWS) - #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS -#endif - -//////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) - #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -#endif - -#ifdef __OS400__ -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# define CATCH_CONFIG_COLOUR_NONE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Android somehow still does not support std::to_string -#if defined(__ANDROID__) -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING -# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Not all Windows environments support SEH properly -#if defined(__MINGW32__) -# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH -#endif - -//////////////////////////////////////////////////////////////////////////////// -// PS4 -#if defined(__ORBIS__) -# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Cygwin -#ifdef __CYGWIN__ - -// Required for some versions of Cygwin to declare gettimeofday -// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin -# define _BSD_SOURCE -// some versions of cygwin (most) do not support std::to_string. Use the libstd check. -// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 -# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ - && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) - -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING - -# endif -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#if defined(_MSC_VER) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) - -# if _MSC_VER >= 1900 // Visual Studio 2015 or newer -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -# endif - -// Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define CATCH_CONFIG_COLOUR_NONE -# else -# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH -# endif - -// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ -// _MSVC_TRADITIONAL == 0 means new conformant preprocessor -// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor -# if !defined(__clang__) // Handle Clang masquerading for msvc -# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) -# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -# endif // MSVC_TRADITIONAL -# endif // __clang__ - -#endif // _MSC_VER - -#if defined(_REENTRANT) || defined(_MSC_VER) -// Enable async processing, as -pthread is specified or no additional linking is required -# define CATCH_INTERNAL_CONFIG_USE_ASYNC -#endif // _MSC_VER - -//////////////////////////////////////////////////////////////////////////////// -// Check if we are compiled with -fno-exceptions or equivalent -#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) -# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED -#endif - -//////////////////////////////////////////////////////////////////////////////// -// DJGPP -#ifdef __DJGPP__ -# define CATCH_INTERNAL_CONFIG_NO_WCHAR -#endif // __DJGPP__ - -//////////////////////////////////////////////////////////////////////////////// -// Embarcadero C++Build -#if defined(__BORLANDC__) - #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// Use of __COUNTER__ is suppressed during code analysis in -// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly -// handled by it. -// Otherwise all supported compilers support COUNTER macro, -// but user still might want to turn it off -#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) - #define CATCH_INTERNAL_CONFIG_COUNTER -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// RTX is a special version of Windows that is real time. -// This means that it is detected as Windows, but does not provide -// the same set of capabilities as real Windows does. -#if defined(UNDER_RTSS) || defined(RTX64_BUILD) - #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH - #define CATCH_INTERNAL_CONFIG_NO_ASYNC - #define CATCH_CONFIG_COLOUR_NONE -#endif - -#if !defined(_GLIBCXX_USE_C99_MATH_TR1) -#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Various stdlib support checks that require __has_include -#if defined(__has_include) - // Check if string_view is available and usable - #if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW - #endif - - // Check if optional is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) - - // Check if byte is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_BYTE - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) - - // Check if variant is available and usable - # if __has_include() && defined(CATCH_CPP17_OR_GREATER) - # if defined(__clang__) && (__clang_major__ < 8) - // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 - // fix should be in clang 8, workaround in libstdc++ 8.2 - # include - # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # define CATCH_CONFIG_NO_CPP17_VARIANT - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__clang__) && (__clang_major__ < 8) - # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) -#endif // defined(__has_include) - -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) -# define CATCH_CONFIG_COUNTER -#endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH -#endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS -#endif -// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. -#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) -# define CATCH_CONFIG_WCHAR -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) -# define CATCH_CONFIG_CPP11_TO_STRING -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) -# define CATCH_CONFIG_CPP17_OPTIONAL -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) -# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) -# define CATCH_CONFIG_CPP17_STRING_VIEW -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) -# define CATCH_CONFIG_CPP17_VARIANT -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) -# define CATCH_CONFIG_CPP17_BYTE -#endif - -#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) -# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) -# define CATCH_CONFIG_NEW_CAPTURE -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -# define CATCH_CONFIG_DISABLE_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) -# define CATCH_CONFIG_POLYFILL_ISNAN -#endif - -#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) -# define CATCH_CONFIG_USE_ASYNC -#endif - -#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) -# define CATCH_CONFIG_ANDROID_LOGWRITE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) -# define CATCH_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Even if we do not think the compiler has that warning, we still have -// to provide a macro that can be used by the code. -#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS -#endif - -// The goal of this macro is to avoid evaluation of the arguments, but -// still have the compiler warn on problems inside... -#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) -#endif - -#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#elif defined(__clang__) && (__clang_major__ < 5) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -#define CATCH_TRY if ((true)) -#define CATCH_CATCH_ALL if ((false)) -#define CATCH_CATCH_ANON(type) if ((false)) -#else -#define CATCH_TRY try -#define CATCH_CATCH_ALL catch (...) -#define CATCH_CATCH_ANON(type) catch (type) -#endif - -#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) -#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#endif - -// end catch_compiler_capabilities.h -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#ifdef CATCH_CONFIG_COUNTER -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) -#else -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) -#endif - -#include -#include -#include - -// We need a dummy global operator<< so we can bring it into Catch namespace later -struct Catch_global_namespace_dummy {}; -std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); - -namespace Catch { - - struct CaseSensitive { enum Choice { - Yes, - No - }; }; - - class NonCopyable { - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; - - protected: - NonCopyable(); - virtual ~NonCopyable(); - }; - - struct SourceLineInfo { - - SourceLineInfo() = delete; - SourceLineInfo( char const* _file, std::size_t _line ) noexcept - : file( _file ), - line( _line ) - {} - - SourceLineInfo( SourceLineInfo const& other ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo( SourceLineInfo&& ) noexcept = default; - SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - - bool empty() const noexcept { return file[0] == '\0'; } - bool operator == ( SourceLineInfo const& other ) const noexcept; - bool operator < ( SourceLineInfo const& other ) const noexcept; - - char const* file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // Bring in operator<< from global namespace into Catch namespace - // This is necessary because the overload of operator<< above makes - // lookup stop at namespace Catch - using ::operator<<; - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() const; - }; - template - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO \ - ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) - -// end catch_common.h -namespace Catch { - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -// end catch_tag_alias_autoregistrar.h -// start catch_test_registry.h - -// start catch_interfaces_testcase.h - -#include - -namespace Catch { - - class TestSpec; - - struct ITestInvoker { - virtual void invoke () const = 0; - virtual ~ITestInvoker(); - }; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; - }; - - bool isThrowSafe( TestCase const& testCase, IConfig const& config ); - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector const& getAllTestCasesSorted( IConfig const& config ); - -} - -// end catch_interfaces_testcase.h -// start catch_stringref.h - -#include -#include -#include -#include - -namespace Catch { - - /// A non-owning string class (similar to the forthcoming std::string_view) - /// Note that, because a StringRef may be a substring of another string, - /// it may not be null terminated. - class StringRef { - public: - using size_type = std::size_t; - using const_iterator = const char*; - - private: - static constexpr char const* const s_empty = ""; - - char const* m_start = s_empty; - size_type m_size = 0; - - public: // construction - constexpr StringRef() noexcept = default; - - StringRef( char const* rawChars ) noexcept; - - constexpr StringRef( char const* rawChars, size_type size ) noexcept - : m_start( rawChars ), - m_size( size ) - {} - - StringRef( std::string const& stdString ) noexcept - : m_start( stdString.c_str() ), - m_size( stdString.size() ) - {} - - explicit operator std::string() const { - return std::string(m_start, m_size); - } - - public: // operators - auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator != (StringRef const& other) const noexcept -> bool { - return !(*this == other); - } - - auto operator[] ( size_type index ) const noexcept -> char { - assert(index < m_size); - return m_start[index]; - } - - public: // named queries - constexpr auto empty() const noexcept -> bool { - return m_size == 0; - } - constexpr auto size() const noexcept -> size_type { - return m_size; - } - - // Returns the current start pointer. If the StringRef is not - // null-terminated, throws std::domain_exception - auto c_str() const -> char const*; - - public: // substrings and searches - // Returns a substring of [start, start + length). - // If start + length > size(), then the substring is [start, size()). - // If start > size(), then the substring is empty. - auto substr( size_type start, size_type length ) const noexcept -> StringRef; - - // Returns the current start pointer. May not be null-terminated. - auto data() const noexcept -> char const*; - - constexpr auto isNullTerminated() const noexcept -> bool { - return m_start[m_size] == '\0'; - } - - public: // iterators - constexpr const_iterator begin() const { return m_start; } - constexpr const_iterator end() const { return m_start + m_size; } - }; - - auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; - auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - - constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { - return StringRef( rawChars, size ); - } -} // namespace Catch - -constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { - return Catch::StringRef( rawChars, size ); -} - -// end catch_stringref.h -// start catch_preprocessor.hpp - - -#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ -#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) - -#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ -// MSVC needs more evaluations -#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) -#else -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) -#endif - -#define CATCH_REC_END(...) -#define CATCH_REC_OUT - -#define CATCH_EMPTY() -#define CATCH_DEFER(id) id CATCH_EMPTY() - -#define CATCH_REC_GET_END2() 0, CATCH_REC_END -#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 -#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 -#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT -#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) -#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) - -#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) - -#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) - -// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, -// and passes userdata as the first parameter to each invocation, -// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) -#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) -#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ -#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ -#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) -#else -// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) -#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) -#endif - -#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ -#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) - -#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) -#else -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) -#endif - -#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ - CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) - -#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) -#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) -#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) -#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) -#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) -#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) -#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _4, _5, _6) -#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) -#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) -#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) -#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) - -#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N - -#define INTERNAL_CATCH_TYPE_GEN\ - template struct TypeList {};\ - template\ - constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ - template class...> struct TemplateTypeList{};\ - template class...Cs>\ - constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ - template\ - struct append;\ - template\ - struct rewrap;\ - template class, typename...>\ - struct create;\ - template class, typename>\ - struct convert;\ - \ - template \ - struct append { using type = T; };\ - template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ - struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ - template< template class L1, typename...E1, typename...Rest>\ - struct append, TypeList, Rest...> { using type = L1; };\ - \ - template< template class Container, template class List, typename...elems>\ - struct rewrap, List> { using type = TypeList>; };\ - template< template class Container, template class List, class...Elems, typename...Elements>\ - struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ - \ - template