mirror of https://github.com/ARMmbed/mbed-os.git
extended advertising scanning and connecting API
parent
0cc134586c
commit
6932789453
|
|
@ -120,6 +120,107 @@ static inline attribute_handle_range_t attribute_handle_range(
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates the peripheral advertising modes.
|
||||
*
|
||||
* It determine how the device appears to other scanner and peripheral
|
||||
* devices in the scanning range.
|
||||
*/
|
||||
enum advertising_type_t {
|
||||
/**
|
||||
* Device is connectable, scannable and doesn't expect connection from a
|
||||
* specific peer.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1.
|
||||
*/
|
||||
ADV_CONNECTABLE_UNDIRECTED,
|
||||
|
||||
/**
|
||||
* Device is connectable and expects connection from a specific peer.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2.
|
||||
*/
|
||||
ADV_CONNECTABLE_DIRECTED,
|
||||
|
||||
/**
|
||||
* Device is scannable but not connectable.
|
||||
*
|
||||
* @see Vol 6, Part B, Section 2.3.1.4.
|
||||
*/
|
||||
ADV_SCANNABLE_UNDIRECTED,
|
||||
|
||||
/**
|
||||
* Device is not connectable and not scannable.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3.
|
||||
*/
|
||||
ADV_NON_CONNECTABLE_UNDIRECTED,
|
||||
|
||||
|
||||
/* extended advertising */
|
||||
EXT_ADV_CONNECTABLE_UNDIRECTED,
|
||||
|
||||
EXT_ADV_NON_CONNECTABLE_DIRECTED,
|
||||
|
||||
EXT_ADV_SCANNABLE_DIRECTED,
|
||||
|
||||
EXT_ADV_HIGH_DUTY_CYCLE_CONNECTABLE_DIRECTED
|
||||
};
|
||||
|
||||
struct advertising_event_t {
|
||||
uint8_t connectable_advertising:1;
|
||||
uint8_t scannable_advertising:1;
|
||||
uint8_t directed_advertising:1;
|
||||
uint8_t scan_response:1;
|
||||
uint8_t legacy:1;
|
||||
uint8_t complete:1;
|
||||
uint8_t last:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Advertising policy filter modes.
|
||||
*
|
||||
* @see Bluetooth Core Specification 4.2 (Vol. 6), Part B, Section 4.3.2.
|
||||
*/
|
||||
enum advertising_policy_mode_t {
|
||||
/**
|
||||
* The whitelist is not used to filter peer request during advertising.
|
||||
*/
|
||||
ADV_POLICY_IGNORE_WHITELIST = 0,
|
||||
|
||||
/**
|
||||
* The whitelist is used to filter peer scan requests.
|
||||
*/
|
||||
ADV_POLICY_FILTER_SCAN_REQS = 1,
|
||||
|
||||
/**
|
||||
* The whitelist is used to filter peer connection requests.
|
||||
*/
|
||||
ADV_POLICY_FILTER_CONN_REQS = 2,
|
||||
|
||||
/**
|
||||
* The whitelist is used to filter peer scan and connection requests.
|
||||
*/
|
||||
ADV_POLICY_FILTER_ALL_REQS = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Scanning policy filter mode.
|
||||
*
|
||||
* @see Bluetooth Core Specification 4.2 (Vol. 6), Part B, Section 4.3.3.
|
||||
*/
|
||||
enum scanning_policy_mode_t {
|
||||
/**
|
||||
* The whitelist is not used for scanning operations.
|
||||
*/
|
||||
SCAN_POLICY_IGNORE_WHITELIST = 0,
|
||||
|
||||
/**
|
||||
* The whitelist is used to filter incoming advertising.
|
||||
*/
|
||||
SCAN_POLICY_FILTER_ALL_ADV = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* Type that describes link's encryption state.
|
||||
*/
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -17,6 +17,9 @@
|
|||
#ifndef MBED_GAP_ADVERTISING_PARAMS_H__
|
||||
#define MBED_GAP_ADVERTISING_PARAMS_H__
|
||||
|
||||
#include "BLETypes.h"
|
||||
#include "BLEProtocol.h"
|
||||
|
||||
/**
|
||||
* @addtogroup ble
|
||||
* @{
|
||||
|
|
@ -28,7 +31,7 @@
|
|||
* Parameters defining the advertising process.
|
||||
*
|
||||
* Advertising parameters are a triplet of three value:
|
||||
* - The Advertising mode modeled after AdvertisingType_t. It defines
|
||||
* - The Advertising mode modeled after ble::advertising_type_t. It defines
|
||||
* if the device is connectable and scannable. This value can be set at
|
||||
* construction time, updated with setAdvertisingType() and queried by
|
||||
* getAdvertisingType().
|
||||
|
|
@ -69,48 +72,18 @@ public:
|
|||
static const unsigned GAP_ADV_PARAMS_TIMEOUT_MAX = 0x3FFF;
|
||||
|
||||
/**
|
||||
* Encapsulates the peripheral advertising modes.
|
||||
*
|
||||
* It determine how the device appears to other scanner and peripheral
|
||||
* devices in the scanning range.
|
||||
*/
|
||||
enum AdvertisingType_t {
|
||||
/**
|
||||
* Device is connectable, scannable and doesn't expect connection from a
|
||||
* specific peer.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1.
|
||||
*/
|
||||
ADV_CONNECTABLE_UNDIRECTED,
|
||||
|
||||
/**
|
||||
* Device is connectable and expects connection from a specific peer.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2.
|
||||
*/
|
||||
ADV_CONNECTABLE_DIRECTED,
|
||||
|
||||
/**
|
||||
* Device is scannable but not connectable.
|
||||
*
|
||||
* @see Vol 6, Part B, Section 2.3.1.4.
|
||||
*/
|
||||
ADV_SCANNABLE_UNDIRECTED,
|
||||
|
||||
/**
|
||||
* Device is not connectable and not scannable.
|
||||
*
|
||||
* @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3.
|
||||
*/
|
||||
ADV_NON_CONNECTABLE_UNDIRECTED
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias for GapAdvertisingParams::AdvertisingType_t.
|
||||
* Alias for GapAdvertisingParams::ble::advertising_type_t.
|
||||
*
|
||||
* @deprecated Future releases will drop this type alias.
|
||||
*/
|
||||
typedef enum AdvertisingType_t AdvertisingType;
|
||||
typedef ble::advertising_type_t AdvertisingType;
|
||||
|
||||
typedef ble::advertising_type_t AdvertisingType_t;
|
||||
|
||||
static const ble::advertising_type_t ADV_CONNECTABLE_UNDIRECTED = ble::ADV_CONNECTABLE_UNDIRECTED;
|
||||
static const ble::advertising_type_t ADV_CONNECTABLE_DIRECTED = ble::ADV_CONNECTABLE_DIRECTED;
|
||||
static const ble::advertising_type_t ADV_SCANNABLE_UNDIRECTED = ble::ADV_SCANNABLE_UNDIRECTED;
|
||||
static const ble::advertising_type_t ADV_NON_CONNECTABLE_UNDIRECTED = ble::ADV_NON_CONNECTABLE_UNDIRECTED;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
@ -125,7 +98,7 @@ public:
|
|||
* @note If value in input are out of range, they will be normalized.
|
||||
*/
|
||||
GapAdvertisingParams(
|
||||
AdvertisingType_t advType = ADV_CONNECTABLE_UNDIRECTED,
|
||||
ble::advertising_type_t advType = ble::ADV_CONNECTABLE_UNDIRECTED,
|
||||
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
|
||||
uint16_t timeout = 0
|
||||
) :
|
||||
|
|
@ -134,10 +107,10 @@ public:
|
|||
_timeout(timeout)
|
||||
{
|
||||
/* Interval checks. */
|
||||
if (_advType == ADV_CONNECTABLE_DIRECTED) {
|
||||
if (_advType == ble::ADV_CONNECTABLE_DIRECTED) {
|
||||
/* Interval must be 0 in directed connectable mode. */
|
||||
_interval = 0;
|
||||
} else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
|
||||
} else if (_advType == ble::ADV_NON_CONNECTABLE_UNDIRECTED) {
|
||||
/* Min interval is slightly larger than in other modes. */
|
||||
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
|
||||
_interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
|
||||
|
|
@ -198,7 +171,7 @@ public:
|
|||
*
|
||||
* @return The advertising type.
|
||||
*/
|
||||
AdvertisingType_t getAdvertisingType(void) const
|
||||
ble::advertising_type_t getAdvertisingType(void) const
|
||||
{
|
||||
return _advType;
|
||||
}
|
||||
|
|
@ -239,7 +212,7 @@ public:
|
|||
*
|
||||
* @param[in] newAdvType The new advertising type.
|
||||
*/
|
||||
void setAdvertisingType(AdvertisingType_t newAdvType)
|
||||
void setAdvertisingType(ble::advertising_type_t newAdvType)
|
||||
{
|
||||
_advType = newAdvType;
|
||||
}
|
||||
|
|
@ -270,7 +243,7 @@ private:
|
|||
/**
|
||||
* The advertising type.
|
||||
*/
|
||||
AdvertisingType_t _advType;
|
||||
ble::advertising_type_t _advType;
|
||||
|
||||
/**
|
||||
* The advertising interval in ADV duration units (in other words, 0.625ms).
|
||||
|
|
@ -283,6 +256,206 @@ private:
|
|||
uint16_t _timeout;
|
||||
};
|
||||
|
||||
class GapExtendedAdvertisingParams : public GapAdvertisingParams {
|
||||
GapExtendedAdvertisingParams()
|
||||
: GapAdvertisingParams(),
|
||||
_minInterval(0),
|
||||
_maxInterval(0),
|
||||
_maxDuration(0),
|
||||
_peerAddressType(),
|
||||
_ownAddressType(),
|
||||
_policy(ble::ADV_POLICY_IGNORE_WHITELIST),
|
||||
_primaryPhy(ble::phy_t::LE_1M),
|
||||
_secondaryPhy(ble::phy_t::LE_1M),
|
||||
_peerAddress(),
|
||||
_maxEvents(0),
|
||||
_txPower(0),
|
||||
_eventNumber(0),
|
||||
_channel37(1),
|
||||
_channel38(1),
|
||||
_channel39(1),
|
||||
_anonymous(0),
|
||||
_notifyOnScan(1) {
|
||||
|
||||
}
|
||||
|
||||
bool getAnonymousAdvertising() {
|
||||
return _anonymous;
|
||||
}
|
||||
|
||||
void setAnonymousAdvertising(
|
||||
bool enable
|
||||
) {
|
||||
_anonymous = enable;
|
||||
}
|
||||
|
||||
ble_error_t getPrimaryAdvertisingInterval(
|
||||
uint32_t *min /* ms */,
|
||||
uint32_t *max /* ms */
|
||||
) {
|
||||
if (!min || !max) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
*min = _minInterval;
|
||||
*max = _maxInterval;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void setPrimaryAdvertisingInterval(
|
||||
uint32_t min /* ms */,
|
||||
uint32_t max /* ms */
|
||||
) {
|
||||
_minInterval = min;
|
||||
_maxInterval = max;
|
||||
}
|
||||
|
||||
ble_error_t getPrimaryAdvertisingChannels(
|
||||
bool *channel37,
|
||||
bool *channel38,
|
||||
bool *channel39
|
||||
) {
|
||||
if (!channel37 || !channel38 || !channel39) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
*channel37 = _channel37;
|
||||
*channel38 = _channel38;
|
||||
*channel39 = _channel39;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void setPrimaryAdvertisingChannels(
|
||||
bool channel37,
|
||||
bool channel38,
|
||||
bool channel39
|
||||
) {
|
||||
_channel37 = channel37;
|
||||
_channel38 = channel38;
|
||||
_channel39 = channel39;
|
||||
}
|
||||
|
||||
BLEProtocol::AddressType::Type getOwnAddressType() {
|
||||
return _ownAddressType;
|
||||
}
|
||||
|
||||
void setOwnAddressType(
|
||||
BLEProtocol::AddressType::Type addressType
|
||||
) {
|
||||
_ownAddressType = addressType;
|
||||
}
|
||||
|
||||
ble_error_t getPeer(
|
||||
BLEProtocol::AddressBytes_t *address,
|
||||
ble::peer_address_type_t *addressType
|
||||
) {
|
||||
if (!address || !addressType) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
memcpy(address, _peerAddress, sizeof(BLEProtocol::AddressBytes_t));
|
||||
*addressType = _peerAddressType;
|
||||
return BLE_ERROR_NONE;
|
||||
};
|
||||
|
||||
void setPeer(
|
||||
const BLEProtocol::AddressBytes_t address,
|
||||
ble::peer_address_type_t addressType
|
||||
) {
|
||||
memcpy(_peerAddress, address, sizeof(BLEProtocol::AddressBytes_t));
|
||||
_peerAddressType = addressType;
|
||||
};
|
||||
|
||||
ble::advertising_policy_mode_t getAdvertisingPolicyMode() {
|
||||
return _policy;
|
||||
}
|
||||
|
||||
void setAdvertisingPolicyMode(
|
||||
ble::advertising_policy_mode_t mode
|
||||
) {
|
||||
_policy = mode;
|
||||
}
|
||||
|
||||
int8_t getAdvertisingTxPower() {
|
||||
return _txPower;
|
||||
}
|
||||
|
||||
void setAdvertisingTxPower(
|
||||
int8_t txPower
|
||||
) {
|
||||
_txPower = txPower;
|
||||
}
|
||||
|
||||
ble_error_t getAdvertisingPhy(
|
||||
ble::phy_t *primaryPhy,
|
||||
ble::phy_t *secondaryPhy
|
||||
) {
|
||||
if (!primaryPhy || !secondaryPhy) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
*primaryPhy = _primaryPhy;
|
||||
*secondaryPhy = _secondaryPhy;
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void setAdvertisingPhy(
|
||||
ble::phy_t primaryPhy,
|
||||
ble::phy_t secondaryPhy
|
||||
) {
|
||||
_primaryPhy = primaryPhy;
|
||||
_secondaryPhy = secondaryPhy;
|
||||
}
|
||||
|
||||
uint8_t getSecondaryAdvertisingMaxSkip() {
|
||||
return _eventNumber;
|
||||
}
|
||||
|
||||
void setSecondaryAdvertisingMaxSkip(
|
||||
uint8_t eventNumber
|
||||
) {
|
||||
_eventNumber = eventNumber;
|
||||
}
|
||||
|
||||
void enableScanRequestNotification(
|
||||
bool enable
|
||||
) {
|
||||
_notifyOnScan = enable;
|
||||
}
|
||||
|
||||
ble_error_t getDuration(
|
||||
uint32_t *maxDuration /* ms */,
|
||||
uint8_t *maxEvents
|
||||
) {
|
||||
if (!maxDuration || !maxEvents) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
void setDuration(
|
||||
uint32_t maxDuration /* ms */,
|
||||
uint8_t maxEvents = 0
|
||||
) {
|
||||
_maxDuration = maxDuration;
|
||||
_maxEvents = maxEvents;
|
||||
}
|
||||
private:
|
||||
uint32_t _minInterval;
|
||||
uint32_t _maxInterval;
|
||||
uint32_t _maxDuration;
|
||||
ble::peer_address_type_t _peerAddressType;
|
||||
BLEProtocol::AddressType_t _ownAddressType;
|
||||
ble::advertising_policy_mode_t _policy;
|
||||
ble::phy_t _primaryPhy;
|
||||
ble::phy_t _secondaryPhy;
|
||||
BLEProtocol::AddressBytes_t _peerAddress;
|
||||
uint8_t _maxEvents;
|
||||
uint8_t _txPower;
|
||||
uint8_t _eventNumber;
|
||||
uint8_t _channel37:1;
|
||||
uint8_t _channel38:1;
|
||||
uint8_t _channel39:1;
|
||||
uint8_t _anonymous:1;
|
||||
uint8_t _notifyOnScan:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
|
|
|||
|
|
@ -206,6 +206,26 @@ public:
|
|||
return _activeScanning;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param phy LE_2m is illegal
|
||||
*/
|
||||
void setScanningPhy(ble::phy_t phy) {
|
||||
_phy = phy;
|
||||
}
|
||||
|
||||
ble::phy_t getScanningPhy() {
|
||||
return _phy;
|
||||
}
|
||||
|
||||
ble::scanning_policy_mode_t getScanningPolicy() {
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setScanningPolicy(ble::scanning_policy_mode_t mode) {
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Scan interval in units of 625us (between 2.5ms and 10.24s).
|
||||
|
|
@ -227,10 +247,10 @@ private:
|
|||
*/
|
||||
bool _activeScanning;
|
||||
|
||||
private:
|
||||
/* Disallow copy constructor. */
|
||||
GapScanningParams(const GapScanningParams &);
|
||||
GapScanningParams& operator =(const GapScanningParams &in);
|
||||
/** Primary channel PHY. */
|
||||
ble::phy_t _phy;
|
||||
|
||||
ble::scanning_policy_mode_t _mode;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_
|
|||
_interval(MSEC_TO_SCAN_DURATION_UNITS(interval)),
|
||||
_window(MSEC_TO_SCAN_DURATION_UNITS(window)),
|
||||
_timeout(timeout),
|
||||
_activeScanning(activeScanning) {
|
||||
_activeScanning(activeScanning),
|
||||
_phy(ble::phy_t::LE_1M),
|
||||
_mode(ble::SCAN_POLICY_IGNORE_WHITELIST) {
|
||||
/* stay within limits */
|
||||
if (_interval < SCAN_INTERVAL_MIN) {
|
||||
_interval = SCAN_INTERVAL_MIN;
|
||||
|
|
|
|||
Loading…
Reference in New Issue