From f7570e8bd5c26bed5e8f1504d1c35e891b696880 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Thu, 31 Dec 2015 13:54:21 +0000 Subject: [PATCH 1/9] Early whitelisting API --- ble/BLE.h | 6 +-- ble/BLEProtocol.h | 28 +++++++++++++- ble/Gap.h | 93 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 112 insertions(+), 15 deletions(-) diff --git a/ble/BLE.h b/ble/BLE.h index 097e8a4..1d8f3a4 100644 --- a/ble/BLE.h +++ b/ble/BLE.h @@ -239,7 +239,7 @@ public: * ble.setAddress(...) should be replaced with * ble.gap().setAddress(...). */ - ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::Address_t address) { + ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) { return gap().setAddress(type, address); } @@ -252,7 +252,7 @@ public: * ble.getAddress(...) should be replaced with * ble.gap().getAddress(...). */ - ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::Address_t address) { + ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) { return gap().getAddress(typeP, address); } @@ -752,7 +752,7 @@ public: * ble.connect(...) should be replaced with * ble.gap().connect(...). */ - ble_error_t connect(const BLEProtocol::Address_t peerAddr, + ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, BLEProtocol::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC, const Gap::ConnectionParams_t *connectionParams = NULL, const GapScanningParams *scanParams = NULL) { diff --git a/ble/BLEProtocol.h b/ble/BLEProtocol.h index 1454022..fceb5df 100644 --- a/ble/BLEProtocol.h +++ b/ble/BLEProtocol.h @@ -19,6 +19,8 @@ #include #include +#include +#include /** * A common namespace for types and constants used everywhere in BLE API. @@ -43,7 +45,31 @@ namespace BLEProtocol { typedef AddressType::Type AddressType_t; /**< Alias for AddressType::Type */ static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ - typedef uint8_t Address_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ + typedef uint8_t AddressBytes_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ + + /** + * BLE address. It contains an address-type (@ref AddressType_t) and bytes (@ref AddressBytes_t). + */ + struct Address_t { + AddressType_t type; /**< @ref AddressType_t */ + AddressBytes_t address; /**< @ref AddressBytes_t */ + + Address_t(AddressType_t typeIn, const AddressBytes_t& addressIn) : type(typeIn) { + std::copy(addressIn, addressIn + ADDR_LEN, address); + } + + Address_t(void) : type(AddressType::PUBLIC), address() { + } + + bool operator<(const Address_t &rhs) const { + if (type < rhs.type) { + return true; + } else if (type > rhs.type) { + return false; + } + return (memcmp(address, rhs.address, sizeof(AddressBytes_t)) < 0) ? true : false; + } + }; }; #endif /* __BLE_PROTOCOL_H__ */ diff --git a/ble/Gap.h b/ble/Gap.h index 181a3c5..37658f9 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -24,6 +24,7 @@ #include "GapEvents.h" #include "CallChainOfFunctionPointersWithContext.h" #include "FunctionPointerWithContext.h" +#include /* Forward declarations for classes that will only be used for pointers or references in the following. */ class GapAdvertisingParams; @@ -65,8 +66,8 @@ public: }; static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; /**< Length (in octets) of the BLE MAC address. */ - typedef BLEProtocol::Address_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ - typedef BLEProtocol::Address_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ + typedef BLEProtocol::AddressBytes_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ + typedef BLEProtocol::AddressBytes_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ public: enum TimeoutSource_t { @@ -113,7 +114,7 @@ public: }; struct AdvertisementCallbackParams_t { - BLEProtocol::Address_t peerAddr; + BLEProtocol::AddressBytes_t peerAddr; int8_t rssi; bool isScanResponse; GapAdvertisingParams::AdvertisingType_t type; @@ -126,9 +127,9 @@ public: Handle_t handle; Role_t role; BLEProtocol::AddressType_t peerAddrType; - BLEProtocol::Address_t peerAddr; + BLEProtocol::AddressBytes_t peerAddr; BLEProtocol::AddressType_t ownAddrType; - BLEProtocol::Address_t ownAddr; + BLEProtocol::AddressBytes_t ownAddr; const ConnectionParams_t *connectionParams; ConnectionCallbackParams_t(Handle_t handleIn, @@ -190,7 +191,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - virtual ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::Address_t address) { + virtual ble_error_t setAddress(BLEProtocol::AddressType_t type, const BLEProtocol::AddressBytes_t address) { /* avoid compiler warnings about unused variables */ (void)type; (void)address; @@ -203,7 +204,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - virtual ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::Address_t address) { + virtual ble_error_t getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) { /* Avoid compiler warnings about unused variables. */ (void)typeP; (void)address; @@ -262,7 +263,7 @@ public: * successfully. The connectionCallChain (if set) will be invoked upon * a connection event. */ - virtual ble_error_t connect(const BLEProtocol::Address_t peerAddr, + virtual ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams) { @@ -1117,9 +1118,9 @@ public: void processConnectionEvent(Handle_t handle, Role_t role, BLEProtocol::AddressType_t peerAddrType, - const BLEProtocol::Address_t peerAddr, + const BLEProtocol::AddressBytes_t peerAddr, BLEProtocol::AddressType_t ownAddrType, - const BLEProtocol::Address_t ownAddr, + const BLEProtocol::AddressBytes_t ownAddr, const ConnectionParams_t *connectionParams) { state.connected = 1; ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); @@ -1132,7 +1133,7 @@ public: disconnectionCallChain.call(&callbackParams); } - void processAdvertisementReport(const BLEProtocol::Address_t peerAddr, + void processAdvertisementReport(const BLEProtocol::AddressBytes_t peerAddr, int8_t rssi, bool isScanResponse, GapAdvertisingParams::AdvertisingType_t type, @@ -1154,6 +1155,76 @@ public: } } +/////////////////////////////////////////////////// +public: + enum AdvertisingPolicyMode_t { + ADV_POLICY_IGNORE_WHITELIST = 0, + ADV_POLICY_FILTER_SCAN_REQS = 1, + ADV_POLICY_FILTER_CONN_REQS = 2, + ADV_POLICY_FILTER_ALL_REQS = 3, + }; + + enum ScanningPolicyMode_t { + SCAN_POLICY_IGNORE_WHITELIST = 0, + SCAN_POLICY_FILTER_ALL_ADV = 1, + }; + + enum InitiatorPolicyMode_t { + INIT_POLICY_IGNORE_WHITELIST = 0, + INIT_POLICY_FILTER_ALL_ADV = 1, + }; + + // Things to be implemented by the porter + virtual int8_t getMaxWhitelistSize(void) const + { + return BLE_ERROR_NOT_IMPLEMENTED; + } + + virtual ble_error_t getWhitelist(std::set &whitelist) const + { + (void) whitelist; + return BLE_ERROR_NOT_IMPLEMENTED; + } + + virtual ble_error_t setWhitelist(std::set whitelist) + { + (void) whitelist; + return BLE_ERROR_NOT_IMPLEMENTED; + } + + // Accessors + virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) + { + (void) mode; + } + + virtual void setScanningPolicyMode(ScanningPolicyMode_t mode) + { + (void) mode; + } + + virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode) + { + (void) mode; + } + + virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const + { + return ADV_POLICY_IGNORE_WHITELIST; + } + + virtual ScanningPolicyMode_t getScanningPolicyMode(void) const + { + return SCAN_POLICY_IGNORE_WHITELIST; + } + + virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const + { + return INIT_POLICY_IGNORE_WHITELIST; + } + +/////////////////////////////////////////////////// + protected: GapAdvertisingParams _advParams; GapAdvertisingData _advPayload; From 6021b70625d58c7a37d3388b2bbd12c1f15e6d65 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Thu, 31 Dec 2015 14:36:51 +0000 Subject: [PATCH 2/9] Fix Address_t and AddressBytes_t problem in Gap --- ble/Gap.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ble/Gap.h b/ble/Gap.h index fae7934..f9c3b54 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -115,7 +115,7 @@ public: }; struct AdvertisementCallbackParams_t { - BLEProtocol::AddressBytes_t peerAddr; + BLEProtocol::AddressBytes_t peerAddr; int8_t rssi; bool isScanResponse; GapAdvertisingParams::AdvertisingType_t type; @@ -265,9 +265,9 @@ public: * a connection event. */ virtual ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, - BLEProtocol::AddressType_t peerAddrType, - const ConnectionParams_t *connectionParams, - const GapScanningParams *scanParams) { + BLEProtocol::AddressType_t peerAddrType, + const ConnectionParams_t *connectionParams, + const GapScanningParams *scanParams) { /* Avoid compiler warnings about unused variables. */ (void)peerAddr; (void)peerAddrType; @@ -286,10 +286,10 @@ public: const GapScanningParams *scanParams) * to maintain backward compatibility for change from Gap::AddressType_t to BLEProtocol::AddressType_t */ - ble_error_t connect(const BLEProtocol::Address_t peerAddr, - DeprecatedAddressType_t peerAddrType, - const ConnectionParams_t *connectionParams, - const GapScanningParams *scanParams) + ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, + DeprecatedAddressType_t peerAddrType, + const ConnectionParams_t *connectionParams, + const GapScanningParams *scanParams) __deprecated_message("Gap::DeprecatedAddressType_t is deprecated, use BLEProtocol::AddressType_t instead") { return connect(peerAddr, (BLEProtocol::AddressType_t) peerAddrType, connectionParams, scanParams); } From 42a202e04710256cd13827c92494f388fe1227ef Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 5 Jan 2016 16:26:45 +0000 Subject: [PATCH 3/9] Finilise Whitelisting experimental API This is the finilised experimental API that introduces support for whitelisting. The changes are focused in Gap and introduces the following functions, that are expected to be implemented by each of the vendor specific glue code (e.g. ble-nrf51822 module): - getMaxWhitelistSize(): Get the maximum whitelist size, this can be set by using a yotta config definition. - getWhitelist(): Gets a copy of the internal whitelist containing BLE addresses. - setWhitelist(): Replace the whitelist with new addresses. - setAdvertisingPolicyMode(), setScanningPolicyMode() and setInitiatorPolicyMode(): Functions used to set the relevan policy filter mode as described in the BLE Specification v4.2 Vol 6, Part B, Section 4.2.1. - getAdvertisingPolicyMode(), getScanningPolicyMode() and getInitiatorPolicyMode(): Functions used to get the relevan policy filter mode as described in the BLE Specification v4.2 Vol 6, Part B, Section 4.2.1. The following enumerators were added to Gap to describe the desired policy filter mode: - AdvertisingPolicyMode_t - ScanningPolicyMode_t - InitiatorPolicyMode_t Finally, the following typedef was added to provide a view of the underlying implementation's internal whitelist: - Whitelist_t **NOTE:** Clearly, these API additions require changes to the underlying implementation! --- ble/Gap.h | 230 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 159 insertions(+), 71 deletions(-) diff --git a/ble/Gap.h b/ble/Gap.h index f9c3b54..a9fa11b 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -24,7 +24,6 @@ #include "GapEvents.h" #include "CallChainOfFunctionPointersWithContext.h" #include "FunctionPointerWithContext.h" -#include #include "deprecate.h" /* Forward declarations for classes that will only be used for pointers or references in the following. */ @@ -94,6 +93,45 @@ public: CONN_INTERVAL_UNACCEPTABLE = 0x3B, }; + /** + * Enumeration for whitelist advertising policy filter modes. The possible + * filter modes were obtained from the Bluetooth Core Specification + * 4.2 (Vol. 6), Part B, Section 4.3.2. + */ + enum AdvertisingPolicyMode_t { + ADV_POLICY_IGNORE_WHITELIST = 0, + ADV_POLICY_FILTER_SCAN_REQS = 1, + ADV_POLICY_FILTER_CONN_REQS = 2, + ADV_POLICY_FILTER_ALL_REQS = 3, + }; + + /** + * Enumeration for whitelist scanning policy filter modes. The possible + * filter modes were obtained from the Bluetooth Core Specification + * 4.2 (Vol. 6), Part B, Section 4.3.3. + */ + enum ScanningPolicyMode_t { + SCAN_POLICY_IGNORE_WHITELIST = 0, + SCAN_POLICY_FILTER_ALL_ADV = 1, + }; + + /** + * Enumeration for the whitelist initiator policy fiter modes. The possible + * filter modes were obtained from the Bluetooth Core Specification + * 4.2 (vol. 6), Part B, Section 4.4.4. + */ + enum InitiatorPolicyMode_t { + INIT_POLICY_IGNORE_WHITELIST = 0, + INIT_POLICY_FILTER_ALL_ADV = 1, + }; + + /* Representation of a Bluetooth Low Enery Whitelist containing addresses. */ + struct Whitelist_t { + BLEProtocol::Address_t *addresses; + uint8_t size; + }; + + /* Describes the current state of the device (more than one bit can be set). */ struct GapState_t { unsigned advertising : 1; /**< Peripheral is currently advertising. */ @@ -473,6 +511,126 @@ public: *countP = 0; /* Requesting action from porter(s): override this API if this capability is supported. */ } + /** + * @return Maximum size of the whitelist. + */ + virtual uint8_t getMaxWhitelistSize(void) const + { + return BLE_ERROR_NOT_IMPLEMENTED; + } + + /** + * Get the internal whitelist to be used by the Link Layer when scanning, + * advertising or initiating a connection depending on the filter policies. + * + * @param[in/out] whitelist + * (on input) whitelist.size contains the maximum number + * of addresses to be returned. + * (on output) The populated whitelist with copies of the + * addresses in the implementation's whitelist. + * + * @return BLE_ERROR_NONE if the implementation's whitelist was successfully + * copied into the supplied reference. + */ + virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const + { + (void) whitelist; + return BLE_ERROR_NOT_IMPLEMENTED; + } + + /** + * Set the internal whitelist to be used by the Link Layer when scanning, + * advertising or initiating a connection depending on the filter policies. + * + * @param[out] whitelist + * A reference to a whitelist containing the addresses to + * be added to the internal whitelist. + * + * @return BLE_ERROR_NONE if the implementation's whitelist was successfully + * populated with the addresses in the given whitelist. + * + * @note The whitelist must not contain addresses of type @ref + * BLEProtocol::AddressType_t::RANDOM_PRIVATE_NON_RESOLVABLE, this + * this will result in a @ref BLE_ERROR_INVALID_PARAM since the + * remote peer might change its private address at any time and it + * is not possible to resolve it. + * @note If the input whitelist is larger than @ref getMaxWhitelistSize() + * the @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned. + */ + virtual ble_error_t setWhitelist(Whitelist_t &whitelist) + { + (void) whitelist; + return BLE_ERROR_NOT_IMPLEMENTED; + } + + /** + * Set the advertising policy filter mode to be used in the next call + * to startAdvertising(). + * + * @param[in] mode + * The new advertising policy filter mode. + */ + virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) + { + (void) mode; + } + + /** + * Set the scan policy filter mode to be used in the next call + * to startScan(). + * + * @param[in] mode + * The new scan policy filter mode. + */ + virtual void setScanningPolicyMode(ScanningPolicyMode_t mode) + { + (void) mode; + } + + /** + * Set the initiator policy filter mode to be used. + * + * @param[in] mode + * The new initiator policy filter mode. + */ + virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode) + { + (void) mode; + } + + /** + * Get the advertising policy filter mode that will be used in the next + * call to startAdvertising(). + * + * @return The set advertising policy filter mode. + */ + virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const + { + return ADV_POLICY_IGNORE_WHITELIST; + } + + /** + * Get the scan policy filter mode that will be used in the next + * call to startScan(). + * + * @return The set scan policy filter mode. + */ + virtual ScanningPolicyMode_t getScanningPolicyMode(void) const + { + return SCAN_POLICY_IGNORE_WHITELIST; + } + + /** + * Get the initiator policy filter mode that will be used. + * + * @return The set scan policy filter mode. + */ + virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const + { + return INIT_POLICY_IGNORE_WHITELIST; + } + + protected: /* Override the following in the underlying adaptation layer to provide the functionality of scanning. */ virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) { @@ -1173,76 +1331,6 @@ public: } } -/////////////////////////////////////////////////// -public: - enum AdvertisingPolicyMode_t { - ADV_POLICY_IGNORE_WHITELIST = 0, - ADV_POLICY_FILTER_SCAN_REQS = 1, - ADV_POLICY_FILTER_CONN_REQS = 2, - ADV_POLICY_FILTER_ALL_REQS = 3, - }; - - enum ScanningPolicyMode_t { - SCAN_POLICY_IGNORE_WHITELIST = 0, - SCAN_POLICY_FILTER_ALL_ADV = 1, - }; - - enum InitiatorPolicyMode_t { - INIT_POLICY_IGNORE_WHITELIST = 0, - INIT_POLICY_FILTER_ALL_ADV = 1, - }; - - // Things to be implemented by the porter - virtual int8_t getMaxWhitelistSize(void) const - { - return BLE_ERROR_NOT_IMPLEMENTED; - } - - virtual ble_error_t getWhitelist(std::set &whitelist) const - { - (void) whitelist; - return BLE_ERROR_NOT_IMPLEMENTED; - } - - virtual ble_error_t setWhitelist(std::set whitelist) - { - (void) whitelist; - return BLE_ERROR_NOT_IMPLEMENTED; - } - - // Accessors - virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) - { - (void) mode; - } - - virtual void setScanningPolicyMode(ScanningPolicyMode_t mode) - { - (void) mode; - } - - virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode) - { - (void) mode; - } - - virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const - { - return ADV_POLICY_IGNORE_WHITELIST; - } - - virtual ScanningPolicyMode_t getScanningPolicyMode(void) const - { - return SCAN_POLICY_IGNORE_WHITELIST; - } - - virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const - { - return INIT_POLICY_IGNORE_WHITELIST; - } - -/////////////////////////////////////////////////// - protected: GapAdvertisingParams _advParams; GapAdvertisingData _advPayload; From 819a0ca7992a3247451f8e0d7f15625635ee898c Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 5 Jan 2016 16:56:33 +0000 Subject: [PATCH 4/9] Fix comments and add Address_t empty constructor Add an empty constructor to BLEProtocol::Address_t and fixed comments with regards to BLEProtocol::Address_t. --- ble/BLE.h | 8 ++++---- ble/BLEProtocol.h | 39 +++++++++++++++++---------------------- ble/Gap.h | 28 ++++++++++++++-------------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/ble/BLE.h b/ble/BLE.h index 1d8f3a4..424dd28 100644 --- a/ble/BLE.h +++ b/ble/BLE.h @@ -752,10 +752,10 @@ public: * ble.connect(...) should be replaced with * ble.gap().connect(...). */ - ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, - BLEProtocol::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC, - const Gap::ConnectionParams_t *connectionParams = NULL, - const GapScanningParams *scanParams = NULL) { + ble_error_t connect(const BLEProtocol::AddressBytes_t peerAddr, + BLEProtocol::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC, + const Gap::ConnectionParams_t *connectionParams = NULL, + const GapScanningParams *scanParams = NULL) { return gap().connect(peerAddr, peerAddrType, connectionParams, scanParams); } diff --git a/ble/BLEProtocol.h b/ble/BLEProtocol.h index fceb5df..cfa127c 100644 --- a/ble/BLEProtocol.h +++ b/ble/BLEProtocol.h @@ -26,15 +26,19 @@ * A common namespace for types and constants used everywhere in BLE API. */ namespace BLEProtocol { - /**< Address-type for Protocol addresses. */ - struct AddressType { /* Adding a struct to encapsulate the contained enumeration - * prevents polluting the BLEProtocol namespace with the - * enumerated values. It also allows type-aliases for the - * enumeration while retaining the enumerated values. i.e. - * - * doing: - * typedef AddressType_t AliasedType_t; - * would allow the use of AliasedType_t::PUBLIC in code. */ + /**< + * A simple container for the enumeration of address-types for Protocol addresses. + * + * Adding a struct to encapsulate the contained enumeration prevents + * polluting the BLEProtocol namespace with the enumerated values. It also + * allows type-aliases for the enumeration while retaining the enumerated + * values. i.e. doing: + * typedef AddressType AliasedType; + * + * would allow the use of AliasedType::PUBLIC in code. + */ + struct AddressType { + /**< Address-types for Protocol addresses. */ enum Type { PUBLIC = 0, RANDOM_STATIC, @@ -42,10 +46,10 @@ namespace BLEProtocol { RANDOM_PRIVATE_NON_RESOLVABLE }; }; - typedef AddressType::Type AddressType_t; /**< Alias for AddressType::Type */ + typedef AddressType::Type AddressType_t; /**< Alias for AddressType::Type */ - static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ - typedef uint8_t AddressBytes_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ + static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ + typedef uint8_t AddressBytes_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ /** * BLE address. It contains an address-type (@ref AddressType_t) and bytes (@ref AddressBytes_t). @@ -58,16 +62,7 @@ namespace BLEProtocol { std::copy(addressIn, addressIn + ADDR_LEN, address); } - Address_t(void) : type(AddressType::PUBLIC), address() { - } - - bool operator<(const Address_t &rhs) const { - if (type < rhs.type) { - return true; - } else if (type > rhs.type) { - return false; - } - return (memcmp(address, rhs.address, sizeof(AddressBytes_t)) < 0) ? true : false; + Address_t() : type(), address() { } }; }; diff --git a/ble/Gap.h b/ble/Gap.h index a9fa11b..ce36027 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -66,8 +66,8 @@ public: }; static const unsigned ADDR_LEN = BLEProtocol::ADDR_LEN; /**< Length (in octets) of the BLE MAC address. */ - typedef BLEProtocol::AddressBytes_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ - typedef BLEProtocol::AddressBytes_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::Address_t instead. */ + typedef BLEProtocol::AddressBytes_t Address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::AddressBytes_t instead. */ + typedef BLEProtocol::AddressBytes_t address_t; /**< 48-bit address, LSB format. @Note: Deprecated. Use BLEProtocol::AddressBytes_t instead. */ public: enum TimeoutSource_t { @@ -141,9 +141,9 @@ public: typedef uint16_t Handle_t; /* Type for connection handle. */ typedef struct { - uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ - uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ - uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ + uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ + uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ + uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/ } ConnectionParams_t; @@ -166,9 +166,9 @@ public: Handle_t handle; Role_t role; BLEProtocol::AddressType_t peerAddrType; - BLEProtocol::AddressBytes_t peerAddr; + BLEProtocol::AddressBytes_t peerAddr; BLEProtocol::AddressType_t ownAddrType; - BLEProtocol::AddressBytes_t ownAddr; + BLEProtocol::AddressBytes_t ownAddr; const ConnectionParams_t *connectionParams; ConnectionCallbackParams_t(Handle_t handleIn, @@ -226,7 +226,7 @@ public: public: /** * Set the BTLE MAC address and type. Please note that the address format is - * least significant byte first (LSB). Please refer to BLEProtocol::Address_t. + * least significant byte first (LSB). Please refer to BLEProtocol::AddressBytes_t. * * @return BLE_ERROR_NONE on success. */ @@ -1291,13 +1291,13 @@ protected: /* Entry points for the underlying stack to report events back to the user. */ public: - void processConnectionEvent(Handle_t handle, - Role_t role, - BLEProtocol::AddressType_t peerAddrType, + void processConnectionEvent(Handle_t handle, + Role_t role, + BLEProtocol::AddressType_t peerAddrType, const BLEProtocol::AddressBytes_t peerAddr, - BLEProtocol::AddressType_t ownAddrType, + BLEProtocol::AddressType_t ownAddrType, const BLEProtocol::AddressBytes_t ownAddr, - const ConnectionParams_t *connectionParams) { + const ConnectionParams_t *connectionParams) { state.connected = 1; ConnectionCallbackParams_t callbackParams(handle, role, peerAddrType, peerAddr, ownAddrType, ownAddr, connectionParams); connectionCallChain.call(&callbackParams); @@ -1309,7 +1309,7 @@ public: disconnectionCallChain.call(&callbackParams); } - void processAdvertisementReport(const BLEProtocol::AddressBytes_t peerAddr, + void processAdvertisementReport(const BLEProtocol::AddressBytes_t peerAddr, int8_t rssi, bool isScanResponse, GapAdvertisingParams::AdvertisingType_t type, From c56bc430582dff8a9a2fe02b5bd755233e83331d Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 5 Jan 2016 17:00:14 +0000 Subject: [PATCH 5/9] Remove unnecessary include in BLEProtocol --- ble/BLEProtocol.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ble/BLEProtocol.h b/ble/BLEProtocol.h index cfa127c..d5def05 100644 --- a/ble/BLEProtocol.h +++ b/ble/BLEProtocol.h @@ -20,7 +20,6 @@ #include #include #include -#include /** * A common namespace for types and constants used everywhere in BLE API. From a488074d7ad410d8c215e703af04c1989d127901 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Wed, 6 Jan 2016 10:02:04 +0000 Subject: [PATCH 6/9] Change Whitelisting API according to comments --- ble/Gap.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ble/Gap.h b/ble/Gap.h index ce36027..f7735e6 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -516,7 +516,7 @@ public: */ virtual uint8_t getMaxWhitelistSize(void) const { - return BLE_ERROR_NOT_IMPLEMENTED; + return 0; } /** @@ -542,7 +542,7 @@ public: * Set the internal whitelist to be used by the Link Layer when scanning, * advertising or initiating a connection depending on the filter policies. * - * @param[out] whitelist + * @param[in] whitelist * A reference to a whitelist containing the addresses to * be added to the internal whitelist. * @@ -557,7 +557,7 @@ public: * @note If the input whitelist is larger than @ref getMaxWhitelistSize() * the @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned. */ - virtual ble_error_t setWhitelist(Whitelist_t &whitelist) + virtual ble_error_t setWhitelist(const Whitelist_t &whitelist) { (void) whitelist; return BLE_ERROR_NOT_IMPLEMENTED; From 0b2ca7aafdd7ed0b9432666b207b821ae2abab79 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Wed, 6 Jan 2016 10:40:23 +0000 Subject: [PATCH 7/9] Add capacity to whitelist structure --- ble/Gap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ble/Gap.h b/ble/Gap.h index f7735e6..91de6a7 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -129,6 +129,7 @@ public: struct Whitelist_t { BLEProtocol::Address_t *addresses; uint8_t size; + uint8_t capacity; }; @@ -524,7 +525,7 @@ public: * advertising or initiating a connection depending on the filter policies. * * @param[in/out] whitelist - * (on input) whitelist.size contains the maximum number + * (on input) whitelist.capacity contains the maximum number * of addresses to be returned. * (on output) The populated whitelist with copies of the * addresses in the implementation's whitelist. From 706a97bca28a3c54a0d2b5ce71eb16b4a0f93bb7 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Wed, 6 Jan 2016 11:17:14 +0000 Subject: [PATCH 8/9] Add @experimental doxygen tag to new APIs --- ble/Gap.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ble/Gap.h b/ble/Gap.h index 91de6a7..7020c3f 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -97,6 +97,8 @@ public: * Enumeration for whitelist advertising policy filter modes. The possible * filter modes were obtained from the Bluetooth Core Specification * 4.2 (Vol. 6), Part B, Section 4.3.2. + * + * @experimental */ enum AdvertisingPolicyMode_t { ADV_POLICY_IGNORE_WHITELIST = 0, @@ -109,6 +111,8 @@ public: * Enumeration for whitelist scanning policy filter modes. The possible * filter modes were obtained from the Bluetooth Core Specification * 4.2 (Vol. 6), Part B, Section 4.3.3. + * + * @experimental */ enum ScanningPolicyMode_t { SCAN_POLICY_IGNORE_WHITELIST = 0, @@ -119,13 +123,19 @@ public: * Enumeration for the whitelist initiator policy fiter modes. The possible * filter modes were obtained from the Bluetooth Core Specification * 4.2 (vol. 6), Part B, Section 4.4.4. + * + * @experimental */ enum InitiatorPolicyMode_t { INIT_POLICY_IGNORE_WHITELIST = 0, INIT_POLICY_FILTER_ALL_ADV = 1, }; - /* Representation of a Bluetooth Low Enery Whitelist containing addresses. */ + /** + * Representation of a Bluetooth Low Enery Whitelist containing addresses. + * + * @experimental + */ struct Whitelist_t { BLEProtocol::Address_t *addresses; uint8_t size; @@ -514,6 +524,8 @@ public: /** * @return Maximum size of the whitelist. + * + * @experimental */ virtual uint8_t getMaxWhitelistSize(void) const { @@ -532,6 +544,8 @@ public: * * @return BLE_ERROR_NONE if the implementation's whitelist was successfully * copied into the supplied reference. + * + * @experimental */ virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const { @@ -557,6 +571,8 @@ public: * is not possible to resolve it. * @note If the input whitelist is larger than @ref getMaxWhitelistSize() * the @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned. + * + * @experimental */ virtual ble_error_t setWhitelist(const Whitelist_t &whitelist) { @@ -570,6 +586,8 @@ public: * * @param[in] mode * The new advertising policy filter mode. + * + * @experimental */ virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) { @@ -582,6 +600,8 @@ public: * * @param[in] mode * The new scan policy filter mode. + * + * @experimental */ virtual void setScanningPolicyMode(ScanningPolicyMode_t mode) { @@ -593,6 +613,8 @@ public: * * @param[in] mode * The new initiator policy filter mode. + * + * @experimental */ virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode) { @@ -604,6 +626,8 @@ public: * call to startAdvertising(). * * @return The set advertising policy filter mode. + * + * @experimental */ virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const { @@ -615,6 +639,8 @@ public: * call to startScan(). * * @return The set scan policy filter mode. + * + * @experimental */ virtual ScanningPolicyMode_t getScanningPolicyMode(void) const { @@ -625,6 +651,8 @@ public: * Get the initiator policy filter mode that will be used. * * @return The set scan policy filter mode. + * + * @experimental */ virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const { From 0dd7f295189469840c3f40cf5f0ecadc750ab901 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Wed, 6 Jan 2016 13:58:38 +0000 Subject: [PATCH 9/9] Change return value of set.*PolicyMode() functions in Gap --- ble/Gap.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ble/Gap.h b/ble/Gap.h index 7020c3f..123c1aa 100644 --- a/ble/Gap.h +++ b/ble/Gap.h @@ -587,11 +587,15 @@ public: * @param[in] mode * The new advertising policy filter mode. * + * @return BLE_ERROR_NONE if the specified policy filter mode was set + * successfully. + * * @experimental */ - virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) + virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode) { (void) mode; + return BLE_ERROR_NOT_IMPLEMENTED; } /** @@ -601,11 +605,15 @@ public: * @param[in] mode * The new scan policy filter mode. * + * @return BLE_ERROR_NONE if the specified policy filter mode was set + * successfully. + * * @experimental */ - virtual void setScanningPolicyMode(ScanningPolicyMode_t mode) + virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode) { (void) mode; + return BLE_ERROR_NOT_IMPLEMENTED; } /** @@ -614,11 +622,15 @@ public: * @param[in] mode * The new initiator policy filter mode. * + * @return BLE_ERROR_NONE if the specified policy filter mode was set + * successfully. + * * @experimental */ - virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode) + virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode) { (void) mode; + return BLE_ERROR_NOT_IMPLEMENTED; } /**