mirror of https://github.com/ARMmbed/mbed-os.git
extended connection API
parent
afadc1d8c0
commit
4c4743db7b
|
@ -955,6 +955,28 @@ struct peer_address_type_t :SafeEnum<peer_address_type_t, uint8_t> {
|
|||
SafeEnum<peer_address_type_t, uint8_t>(PUBLIC) { }
|
||||
};
|
||||
|
||||
struct own_address_type_t : ble::SafeEnum<own_address_type_t, uint8_t> {
|
||||
enum type {
|
||||
PUBLIC = 0, /**< Public Device Address. */
|
||||
RANDOM, /**< Random Device Address. */
|
||||
RANDOM_RESOLVABLE_PUBLIC_FALLBACK, /**< Controller generates the Resolvable Private Address based on
|
||||
the local IRK from the resolving list. If the resolving list
|
||||
contains no matching entry, use the public address. */
|
||||
RANDOM_RESOLVABLE_RANDOM_FALLBACK /**< Controller generates the Resolvable Private Address based on
|
||||
the local IRK from the resolving list. If the resolving list
|
||||
contains no matching entry, use previously set random address. */
|
||||
};
|
||||
own_address_type_t(type value) : ble::SafeEnum<own_address_type_t, uint8_t>(value) { }
|
||||
};
|
||||
|
||||
struct target_peer_address_type_t : ble::SafeEnum<target_peer_address_type_t, uint8_t> {
|
||||
enum type {
|
||||
PUBLIC = 0, /**< Public Device Address or Public Identity Address. */
|
||||
RANDOM /**< Random Device Address or Random (static) Identity Address. */
|
||||
};
|
||||
target_peer_address_type_t(type value) : ble::SafeEnum<target_peer_address_type_t, uint8_t>(value) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Type that describes a bluetooth PHY(sical) transport.
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "BLEProtocol.h"
|
||||
#include "GapAdvertisingData.h"
|
||||
#include "ble/gap/AdvertisingDataBuilder.h"
|
||||
#include "ble/gap/ExtendedConnectParameters.h"
|
||||
#include "GapAdvertisingParams.h"
|
||||
#include "GapScanningParams.h"
|
||||
#include "GapEvents.h"
|
||||
|
@ -564,6 +565,21 @@ public:
|
|||
*/
|
||||
typedef ble::peer_address_type_t PeerAddressType_t;
|
||||
|
||||
/**
|
||||
* Enumeration of own address types
|
||||
*/
|
||||
typedef ble::own_address_type_t OwnAddressType_t;
|
||||
|
||||
/**
|
||||
* Enumeration of peer address types
|
||||
*/
|
||||
typedef ble::target_peer_address_type_t TargetPeerAddressType_t;
|
||||
|
||||
/**
|
||||
* Scanning filter policy based on the whitelist
|
||||
*/
|
||||
typedef ble::scanning_policy_mode_t ScanningPolicyMode_t;
|
||||
|
||||
/**
|
||||
* Enumeration of BLE PHY
|
||||
*/
|
||||
|
@ -1513,23 +1529,17 @@ public:
|
|||
* a connection event.
|
||||
*/
|
||||
virtual ble_error_t connect(
|
||||
const BLEProtocol::AddressBytes_t peerAddr,
|
||||
PeerAddressType_t peerAddrType,
|
||||
const ConnectionParams_t *connectionParams1M,
|
||||
const GapScanningParams *scanParams1M,
|
||||
const ConnectionParams_t *connectionParams2M = NULL,
|
||||
const GapScanningParams *scanParams2M = NULL,
|
||||
const ConnectionParams_t *connectionParamsCoded = NULL,
|
||||
const GapScanningParams *scanParamsCoded = NULL
|
||||
TargetPeerAddressType_t peerAddressType,
|
||||
const BLEProtocol::AddressBytes_t peerAddress,
|
||||
const ExtendedConnectParameters_t &connectionParams
|
||||
) {
|
||||
(void)peerAddr;
|
||||
(void)peerAddrType;
|
||||
(void)filterPolicy;
|
||||
(void)ownAddressType;
|
||||
(void)peerAddressType;
|
||||
(void)peerAddress;
|
||||
(void)connectionParams1M;
|
||||
(void)scanParams1M;
|
||||
(void)connectionParams2M;
|
||||
(void)scanParams2M;
|
||||
(void)connectionParamsCoded;
|
||||
(void)scanParamsCoded;
|
||||
|
||||
/* Requesting action from porter(s): override this API if this capability is supported. */
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -95,28 +95,6 @@ public:
|
|||
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;
|
||||
|
||||
struct own_address_type_t : ble::SafeEnum<own_address_type_t, uint8_t> {
|
||||
enum type {
|
||||
PUBLIC = 0, /**< Public Device Address. */
|
||||
RANDOM, /**< Random Device Address. */
|
||||
RANDOM_RESOLVABLE_PUBLIC_FALLBACK, /**< Controller generates the Resolvable Private Address based on
|
||||
the local IRK from the resolving list. If the resolving list
|
||||
contains no matching entry, use the public address. */
|
||||
RANDOM_RESOLVABLE_RANDOM_FALLBACK /**< Controller generates the Resolvable Private Address based on
|
||||
the local IRK from the resolving list. If the resolving list
|
||||
contains no matching entry, use previously set random address. */
|
||||
};
|
||||
own_address_type_t(type value) : ble::SafeEnum<own_address_type_t, uint8_t>(value) { }
|
||||
};
|
||||
|
||||
struct peer_address_type_t : ble::SafeEnum<peer_address_type_t, uint8_t> {
|
||||
enum type {
|
||||
PUBLIC = 0, /**< Public Device Address or Public Identity Address. */
|
||||
RANDOM /**< Random Device Address or Random (static) Identity Address. */
|
||||
};
|
||||
peer_address_type_t(type value) : ble::SafeEnum<peer_address_type_t, uint8_t>(value) { }
|
||||
};
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct an instance of GapAdvertisingParams.
|
||||
|
@ -139,8 +117,8 @@ public:
|
|||
_minInterval(minInterval),
|
||||
_maxInterval(maxInterval),
|
||||
_timeout(timeout),
|
||||
_peerAddressType(peer_address_type_t::PUBLIC),
|
||||
_ownAddressType(own_address_type_t::PUBLIC),
|
||||
_peerAddressType(ble::target_peer_address_type_t::PUBLIC),
|
||||
_ownAddressType(ble::own_address_type_t::PUBLIC),
|
||||
_policy(ble::ADV_POLICY_IGNORE_WHITELIST),
|
||||
_primaryPhy(ble::phy_t::LE_1M),
|
||||
_secondaryPhy(ble::phy_t::LE_1M),
|
||||
|
@ -422,14 +400,14 @@ public:
|
|||
*
|
||||
* @return Addres tpe used.
|
||||
*/
|
||||
own_address_type_t getOwnAddressType() const {
|
||||
ble::own_address_type_t getOwnAddressType() const {
|
||||
return _ownAddressType;
|
||||
}
|
||||
|
||||
/** Get what type of address is to be used as your own address during advertising.
|
||||
*/
|
||||
void setOwnAddressType(
|
||||
own_address_type_t addressType
|
||||
ble::own_address_type_t addressType
|
||||
) {
|
||||
_ownAddressType = addressType;
|
||||
}
|
||||
|
@ -443,7 +421,7 @@ public:
|
|||
*/
|
||||
ble_error_t getPeer(
|
||||
BLEProtocol::AddressBytes_t *address,
|
||||
peer_address_type_t *addressType
|
||||
ble::target_peer_address_type_t *addressType
|
||||
) const {
|
||||
if (!address || !addressType) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
|
@ -460,7 +438,7 @@ public:
|
|||
*/
|
||||
void setPeer(
|
||||
const BLEProtocol::AddressBytes_t address,
|
||||
peer_address_type_t addressType
|
||||
ble::target_peer_address_type_t addressType
|
||||
) {
|
||||
memcpy(_peerAddress, address, sizeof(BLEProtocol::AddressBytes_t));
|
||||
_peerAddressType = addressType;
|
||||
|
@ -650,7 +628,7 @@ public:
|
|||
*
|
||||
* @return Peer address type.
|
||||
*/
|
||||
peer_address_type_t getPeerAddressType() const {
|
||||
ble::target_peer_address_type_t getPeerAddressType() const {
|
||||
return _peerAddressType;
|
||||
};
|
||||
|
||||
|
@ -704,8 +682,8 @@ private:
|
|||
uint32_t _maxInterval;
|
||||
/* The advertising timeout in ADV duration units (in other words, 0.625ms). */
|
||||
uint16_t _timeout;
|
||||
peer_address_type_t _peerAddressType;
|
||||
own_address_type_t _ownAddressType;
|
||||
ble::target_peer_address_type_t _peerAddressType;
|
||||
ble::own_address_type_t _ownAddressType;
|
||||
ble::advertising_policy_mode_t _policy;
|
||||
ble::phy_t _primaryPhy;
|
||||
ble::phy_t _secondaryPhy;
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MBED_EXTENDED_CONNECT_PARAMETERS_H__
|
||||
#define MBED_EXTENDED_CONNECT_PARAMETERS_H__
|
||||
|
||||
/**
|
||||
* @addtogroup ble
|
||||
* @{
|
||||
* @addtogroup gap
|
||||
* @{
|
||||
*/
|
||||
|
||||
class ExtendedConnectParameters_t {
|
||||
const size_t MAX_PARAM_PHYS = 3;
|
||||
public:
|
||||
ExtendedConnectParameters_t() :
|
||||
_filterPolicy(ble::scanning_policy_mode_t::SCAN_POLICY_FILTER_ALL_ADV),
|
||||
_ownAddressType(ble::own_address_type_t::PUBLIC)
|
||||
{
|
||||
for (int i = 0; i < MAX_PARAM_PHYS; ++i) {
|
||||
_scanInterval[i] = 4;
|
||||
_scanWindow[i] = 4;
|
||||
_minConnectionInterval[i] = 6;
|
||||
_maxConnectionInterval[i] = 6;
|
||||
_slaveLatency[i] = 0;
|
||||
_connectionSupervisionTimeout[i] = 0xC80;
|
||||
_minimumEventLength[i] = 0;
|
||||
_maximumEventLength[i] = 0xFFFF;
|
||||
}
|
||||
};
|
||||
|
||||
ExtendedConnectParameters_t& setScanParamteres(
|
||||
uint32_t scanInterval,
|
||||
uint32_t scanWindow,
|
||||
ble::phy_t phy = ble::phy_t::LE_1M
|
||||
) {
|
||||
_enabledPhy[phy] = true;
|
||||
scanInterval = scanInterval[phy];
|
||||
scanWindow = scanWindow[phy];
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExtendedConnectParameters_t& setConnectionParamteres(
|
||||
uint16_t minConnectionInterval,
|
||||
uint16_t maxConnectionInterval,
|
||||
uint16_t slaveLatency,
|
||||
uint16_t connectionSupervisionTimeout,
|
||||
uint32_t _minimumEventLength,
|
||||
uint32_t _maximumEventLength,
|
||||
ble::phy_t phy = ble::phy_t::LE_1M
|
||||
) {
|
||||
_enabledPhy[phy] = true;
|
||||
_minConnectionInterval = minConnectionInterval[phy];
|
||||
maxConnectionInterval = maxConnectionInterval[phy];
|
||||
slaveLatency = slaveLatency[phy];
|
||||
connectionSupervisionTimeout = connectionSupervisionTimeout[phy];
|
||||
_minimumEventLength = _minimumEventLength[phy];
|
||||
_maximumEventLength = _maximumEventLength[phy];
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExtendedConnectParameters_t& setScanParamteres(
|
||||
ble::own_address_type_t ownAddress
|
||||
) {
|
||||
_ownAddressType = ownAddress;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ExtendedConnectParameters_t& setScanParamteres(
|
||||
ble::scanning_policy_mode_t filterPolicy
|
||||
) {
|
||||
_filterPolicy = filterPolicy;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
ble::scanning_policy_mode_t _filterPolicy;
|
||||
ble::own_address_type_t _ownAddressType;
|
||||
uint32_t _scanInterval[MAX_PARAM_PHYS];
|
||||
uint32_t _scanWindow[MAX_PARAM_PHYS];
|
||||
uint16_t _minConnectionInterval[MAX_PARAM_PHYS];
|
||||
uint16_t _maxConnectionInterval[MAX_PARAM_PHYS];
|
||||
uint16_t _slaveLatency[MAX_PARAM_PHYS];
|
||||
uint16_t _connectionSupervisionTimeout[MAX_PARAM_PHYS];
|
||||
uint32_t _minimumEventLength[MAX_PARAM_PHYS];
|
||||
uint32_t _maximumEventLength[MAX_PARAM_PHYS];
|
||||
bool _enabledPhy[MAX_PARAM_PHYS];
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* ifndef MBED_EXTENDED_CONNECT_PARAMETERS_H__ */
|
Loading…
Reference in New Issue