Early whitelisting API
This commit is contained in:
parent
3036b058fe
commit
f7570e8bd5
|
@ -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) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* 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__ */
|
||||
|
|
93
ble/Gap.h
93
ble/Gap.h
|
@ -24,6 +24,7 @@
|
|||
#include "GapEvents.h"
|
||||
#include "CallChainOfFunctionPointersWithContext.h"
|
||||
#include "FunctionPointerWithContext.h"
|
||||
#include <set>
|
||||
|
||||
/* 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<BLEProtocol::Address_t> &whitelist) const
|
||||
{
|
||||
(void) whitelist;
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
virtual ble_error_t setWhitelist(std::set<BLEProtocol::Address_t> 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;
|
||||
|
|
Loading…
Reference in New Issue