17 #ifndef MBED_BLE_GAP_H__ 18 #define MBED_BLE_GAP_H__ 21 #include "ble/common/StaticInterface.h" 23 #include "BLEProtocol.h" 24 #include "ble/GapAdvertisingData.h" 25 #include "ble/GapAdvertisingParams.h" 26 #include "ble/GapScanningParams.h" 27 #include "ble/GapEvents.h" 29 #include "CallChainOfFunctionPointersWithContext.h" 31 #include "platform/mbed_toolchain.h" 33 #include "ble/gap/Gap.h" 34 #include "BleImplementationForward.h" 43 #if !defined(DOXYGEN_ONLY) 51 #if defined(DOXYGEN_ONLY) 57 public ble::interface::Gap<Impl>
63 #if BLE_ROLE_BROADCASTER 64 using ble::interface::Gap<Impl>::setAdvertisingParameters;
65 using ble::interface::Gap<Impl>::setAdvertisingPayload;
66 using ble::interface::Gap<Impl>::setAdvertisingScanResponse;
67 using ble::interface::Gap<Impl>::startAdvertising;
68 using ble::interface::Gap<Impl>::stopAdvertising;
69 #endif // BLE_ROLE_BROADCASTER 71 using ble::interface::Gap<Impl>::connect;
73 #if BLE_FEATURE_CONNECTABLE 74 using ble::interface::Gap<Impl>::disconnect;
77 using ble::interface::Gap<Impl>::startScan;
135 TIMEOUT_SRC_ADVERTISING = 0x00,
140 TIMEOUT_SRC_SECURITY_REQUEST = 0x01,
145 TIMEOUT_SRC_SCAN = 0x02,
150 TIMEOUT_SRC_CONN = 0x03,
166 AUTHENTICATION_FAILURE = 0x05,
173 CONNECTION_TIMEOUT = 0x08,
178 REMOTE_USER_TERMINATED_CONNECTION = 0x13,
183 REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES = 0x14,
188 REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF = 0x15,
196 LOCAL_HOST_TERMINATED_CONNECTION = 0x16,
201 CONN_INTERVAL_UNACCEPTABLE = 0x3B,
213 ADV_POLICY_IGNORE_WHITELIST = 0,
218 ADV_POLICY_FILTER_SCAN_REQS = 1,
223 ADV_POLICY_FILTER_CONN_REQS = 2,
228 ADV_POLICY_FILTER_ALL_REQS = 3,
240 SCAN_POLICY_IGNORE_WHITELIST = 0,
245 SCAN_POLICY_FILTER_ALL_ADV = 1,
257 INIT_POLICY_IGNORE_WHITELIST = 0,
263 INIT_POLICY_FILTER_ALL_ADV = 1,
293 unsigned advertising : 1;
298 unsigned connected : 1;
465 "addressType won't work in connect when privacy is enabled; please" 468 AddressType_t addressType;
476 PeerAddressType_t peerAddrType;
514 "The type BLEProtocol::AddressType_t is not suitable when privacy is " 515 "enabled. Use peerAddressType instead." 539 "A Bluetooth controller is not supposed to return the address it used"
540 "to connect. With privacy enabled the controller address may be unknown"
541 "to the host. There is no replacement for this deprecation."
567 PeerAddressType_t peerAddressType;
585 ConnectionCallbackParams_t(
588 PeerAddressType_t peerAddrTypeIn,
589 const uint8_t *peerAddrIn,
591 const uint8_t *ownAddrIn,
593 const uint8_t *peerResolvableAddrIn = NULL,
594 const uint8_t *localResolvableAddrIn = NULL
619 "The type
BLEProtocol::AddressType_t is not suitable when privacy is "
620 "enabled. Use the constructor that accepts a PeerAddressType_t instead."
622 ConnectionCallbackParams_t(
626 const uint8_t *peerAddrIn,
628 const uint8_t *ownAddrIn,
630 const uint8_t *peerResolvableAddrIn = NULL,
631 const uint8_t *localResolvableAddrIn = NULL
635 void constructor_helper(
636 const uint8_t *peerAddrIn,
637 const uint8_t *ownAddrIn,
638 const uint8_t *peerResolvableAddrIn,
639 const uint8_t *localResolvableAddrIn
672 ) : handle(handleIn),
691 static const uint16_t UNIT_1_25_MS = 1250;
705 return (durationInMillis * 1000) / UNIT_1_25_MS;
817 "Non portable API, use enablePrivacy to enable use of private addresses" 853 RandomAddressType_t *addressType
856 #if BLE_ROLE_BROADCASTER 864 uint16_t getMinAdvertisingInterval(
void)
const;
873 uint16_t getMinNonConnectableAdvertisingInterval(
void)
const;
880 uint16_t getMaxAdvertisingInterval(
void)
const;
895 "Deprecated since addition of extended advertising support." 896 "Use stopAdvertising(advertising_handle_t) instead." 899 #endif //BLE_ROLE_BROADCASTER 922 "Deprecated since addition of extended advertising support." 923 "Use connect(target_peer_address_type_t, address_t, ConnectionParameters) instead." 927 PeerAddressType_t peerAddrType,
953 "This function won't work if privacy is enabled; You must use the overload "
954 "accepting PeerAddressType_t."
984 #endif // BLE_ROLE_CENTRAL 986 #if BLE_FEATURE_CONNECTABLE 1005 "Deprecated since addition of extended advertising support." 1006 "Use disconnect(connection_handle_t, local_disconnection_reason_t) instead." 1076 "Deprecated since addition of extended advertising support."
1085 #endif // BLE_FEATURE_CONNECTABLE 1086 #if BLE_FEATURE_GATT_SERVER 1096 ble_error_t setDeviceName(
const uint8_t *deviceName);
1120 ble_error_t getDeviceName(uint8_t *deviceName,
unsigned *lengthP);
1140 #endif // BLE_FEATURE_GATT_SERVER 1155 "Deprecated since addition of extended advertising support." 1156 "See ble::AdvertisingParameters and setAdvertisingParameters." 1170 "Deprecated since addition of extended advertising support."
1172 void getPermittedTxPowerValues(
1173 const int8_t **valueArrayPP,
size_t *countP
1176 #if BLE_FEATURE_WHITELIST 1185 uint8_t getMaxWhitelistSize(
void)
const;
1233 "Deprecated since addition of extended advertising support." 1234 "This setting is now part of ble::AdvertisingParameters." 1251 "Deprecated since addition of extended advertising support."
1252 "This setting is now part of
ble::ScanParameters."
1270 "Deprecated since addition of extended advertising support."
1271 "This setting is now part of
ble::ConnectionParameters."
1284 "Deprecated since addition of extended advertising support."
1297 "Deprecated since addition of extended advertising support."
1310 "Deprecated since addition of extended advertising support."
1313 #endif // BLE_FEATURE_WHITELIST 1316 #if BLE_ROLE_OBSERVER 1333 "Deprecated since addition of extended advertising support. " 1334 "Vendors should use the cordio hci interface or the ble::pal or " 1335 "implement startScan(duplicates_filter_t, scan_duration_t, period)" 1338 #endif // BLE_ROLE_OBSERVER 1356 "Deprecated since addition of extended advertising support. " 1357 "Replace getState().advertising with isAdvertisingActive()." 1358 "Replace getState().connected with your own record and update during callbacks." 1362 #if BLE_ROLE_BROADCASTER 1373 "Deprecated since addition of extended advertising support. " 1374 "This option is now part of ble::AdvertisingParameters" 1399 "Deprecated since addition of extended advertising support. "
1400 "This option is now part of
ble::AdvertisingParameters"
1402 void setAdvertisingInterval(uint16_t interval);
1417 "Deprecated since addition of extended advertising support. "
1418 "This option is now part of
ble::AdvertisingParameters"
1420 void setAdvertisingTimeout(uint16_t timeout);
1432 "Deprecated since addition of extended advertising support. "
1446 "Deprecated since addition of extended advertising support. "
1447 "Use setAdvertisingPayload(
ble::advertising_handle_t, Span<uint8_t>,"
1450 void clearAdvertisingPayload(
void);
1475 "Deprecated since addition of extended advertising support."
1476 "Use
ble::AdvertisingDataBuilder instead."
1478 ble_error_t accumulateAdvertisingPayload(uint8_t flags);
1503 "Deprecated since addition of extended advertising support. "
1504 "Use
ble::AdvertisingDataBuilder instead."
1531 "Deprecated since addition of extended advertising support. "
1532 "Use
ble::AdvertisingDataBuilder instead."
1534 ble_error_t accumulateAdvertisingPayloadTxPower(int8_t power);
1567 "Deprecated since addition of extended advertising support. "
1568 "Use
ble::AdvertisingDataBuilder instead."
1603 "Deprecated since addition of extended advertising support. "
1604 " Use
ble::AdvertisingDataBuilder instead."
1624 "Deprecated since addition of extended advertising support. "
1625 "Use
ble::AdvertisingDataBuilder instead."
1638 "Deprecated since addition of extended advertising support."
1657 "Deprecated since addition of extended advertising support."
1658 "Use
ble::AdvertisingDataBuilder instead."
1675 "Deprecated since addition of extended advertising support. "
1676 "Use setAdvertisingScanResponse() instead."
1678 void clearScanResponse(
void);
1679 #endif // BLE_ROLE_BROADCASTER 1680 #if BLE_ROLE_OBSERVER 1718 "Deprecated since addition of extended advertising support. " 1719 "Use setScanParameters(const ScanParameters &) instead." 1724 uint16_t timeout = 0,
1725 bool activeScanning = false
1743 "Deprecated since addition of extended advertising support. "
1744 "Use setScanParameters(const ScanParameters &) instead."
1762 "Deprecated since addition of extended advertising support. "
1763 "Use setScanParameters(const ScanParameters &) instead."
1783 "Deprecated since addition of extended advertising support. "
1784 "Use setScanParameters(const ScanParameters &) instead."
1804 "Deprecated since addition of extended advertising support. "
1805 "Use setScanParameters(const ScanParameters &) instead."
1826 "Deprecated since addition of extended advertising support. "
1827 "Use setScanParameters(const ScanParameters &) instead."
1829 ble_error_t setActiveScanning(
bool activeScanning);
1850 "Deprecated since addition of extended advertising support. "
1880 template<typename T>
1883 "Deprecated since addition of extended advertising support. "
1884 "Use startScan(duplicates_filter_t, scan_duration_t,
scan_period_t) instead."
1890 #endif // BLE_ROLE_OBSERVER 1911 "Deprecated since addition of extended advertising support. " 1916 #if BLE_ROLE_BROADCASTER 1932 "Deprecated since addition of extended advertising support. " 1933 "Implement setAdvertisingPayload() and setAdvertisingScanResponse() instead." 1956 "Deprecated since addition of extended advertising support. "
1957 "Implement startAdvertising(advertising_handle_t, adv_duration_t, uint8_t)"
1972 "Deprecated since addition of extended advertising support."
1985 "Deprecated since addition of extended advertising support."
1999 "Deprecated since addition of extended advertising support."
2000 "Use setAdvertisingParameters() instead."
2003 #endif // BLE_ROLE_BROADCASTER 2021 "Deprecated since addition of extended advertising support. " 2022 "Use setEventHandler() instead." 2024 void onTimeout(TimeoutEventCallback_t
callback);
2040 "Deprecated since addition of extended advertising support. "
2041 "Use setEventHandler() instead."
2044 #if BLE_FEATURE_CONNECTABLE 2057 "Deprecated since addition of extended advertising support. " 2058 "Use setEventHandler() instead." 2073 template<typename T>
2076 "Deprecated since addition of extended advertising support. "
2077 "Use setEventHandler() instead."
2079 void onConnection(T *tptr,
void (T::*mptr)(const ConnectionCallbackParams_t *));
2095 "Deprecated since addition of extended advertising support. "
2096 "Use setEventHandler() instead."
2112 "Deprecated since addition of extended advertising support. "
2113 "Use setEventHandler() instead."
2128 template<typename T>
2131 "Deprecated since addition of extended advertising support. "
2132 "Use setEventHandler() instead."
2150 "Deprecated since addition of extended advertising support. "
2151 "Use setEventHandler() instead."
2154 #endif //BLE_FEATURE_CONNECTABLE 2176 "Deprecated since addition of extended advertising support. " 2178 void onRadioNotification(
void (*callback)(
bool param));
2190 template<typename T>
2193 "Deprecated since addition of extended advertising support. "
2194 "Use setEventHandler() instead."
2196 void onRadioNotification(T *tptr,
void (T::*mptr)(
bool));
2209 void onShutdown(const GapShutdownCallback_t &callback);
2217 template<typename T>
2218 void onShutdown(T *objPtr,
void (T::*memberPtr)(const LegacyGap *))
2220 shutdownCallChain.add(objPtr, memberPtr);
2286 "Deprecated since addition of extended advertising support. " 2287 "Use EventHandler::onConnectionComplete() instead" 2289 void processConnectionEvent(
2292 PeerAddressType_t peerAddrType,
2297 const uint8_t *peerResolvableAddr = NULL,
2298 const uint8_t *localResolvableAddr = NULL
2324 "The type BLEProtocol::AddressType_t is not suitable when privacy is " 2325 "enabled. Use the overload that accepts a PeerAddressType_t instead." 2327 void processConnectionEvent(
2335 const uint8_t *peerResolvableAddr = NULL,
2336 const uint8_t *localResolvableAddr = NULL
2353 "Deprecated since addition of extended advertising support. " 2354 "Use EventHandler::onDisconnectionComplete() instead" 2380 "Deprecated since addition of extended advertising support. " 2381 "Use EventHandler::onAdvertisingReport() instead" 2383 void processAdvertisementReport(
2386 bool isScanResponse,
2388 uint8_t advertisingDataLen,
2389 const uint8_t *advertisingData,
2390 PeerAddressType_t addressType
2415 "The type BLEProtocol::AddressType_t is not suitable when privacy is " 2416 "enabled. Use the overload that accepts a PeerAddressType_t instead." 2418 void processAdvertisementReport(
2421 bool isScanResponse,
2423 uint8_t advertisingDataLen,
2424 const uint8_t *advertisingData,
2442 "Deprecated since addition of extended advertising support. " 2443 "Use EventHandler instead" 2522 LegacyGap(
const LegacyGap &);
2524 LegacyGap &operator=(
const LegacyGap &);
2528 using ble::interface::Gap<Impl>::startAdvertising_;
2529 using ble::interface::Gap<Impl>::stopAdvertising_;
2530 using ble::interface::Gap<Impl>::connect_;
2531 using ble::interface::Gap<Impl>::disconnect_;
2534 uint16_t getMinAdvertisingInterval_(
void)
const;
2536 uint16_t getMinNonConnectableAdvertisingInterval_(
void)
const;
2538 uint16_t getMaxAdvertisingInterval_(
void)
const;
2545 uint8_t getMaxWhitelistSize_(
void)
const;
2565 PeerAddressType_t peerAddrType,
2590 void getPermittedTxPowerValues_(
2591 const int8_t **valueArrayPP,
size_t *countP
2616 ble_error_t setDeviceName_(
const uint8_t *deviceName);
2618 ble_error_t getDeviceName_(uint8_t *deviceName,
unsigned *lengthP);
2639 #if defined(__GNUC__) && !defined(__CC_ARM) 2640 #pragma GCC diagnostic push 2641 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 2642 #elif defined(__CC_ARM) 2644 #pragma diag_suppress 1361 2647 #if BLE_ROLE_OBSERVER 2648 template<
class Impl>
2649 template<
typename T>
2656 if (
object && callbackMember) {
2658 scanningActive =
true;
2659 onAdvertisementReport.attach(
object, callbackMember);
2665 #endif // BLE_ROLE_OBSERVER 2667 #if BLE_FEATURE_CONNECTABLE 2668 template<
class Impl>
2669 template<
typename T>
2670 void LegacyGap<Impl>::onConnection(T *tptr,
void (T::*mptr)(
const ConnectionCallbackParams_t *))
2672 connectionCallChain.add(tptr, mptr);
2675 template<
class Impl>
2676 template<
typename T>
2679 disconnectionCallChain.add(tptr, mptr);
2681 #endif //BLE_FEATURE_CONNECTABLE 2683 template<
class Impl>
2684 template<
typename T>
2685 void LegacyGap<Impl>::onRadioNotification(T *tptr,
void (T::*mptr)(
bool))
2687 radioNotificationCallback.attach(tptr, mptr);
2690 #if defined(__GNUC__) && !defined(__CC_ARM) 2691 #pragma GCC diagnostic pop 2692 #elif defined(__CC_ARM) 2700 typedef ble::impl::LegacyGap
Gap;
2704 typedef impl::Gap Gap;
2708 #endif // ifndef MBED_BLE_GAP_H__ BLEProtocol::Address_t * addresses
Pointer to the array of the addresses composing the whitelist.
ble::coded_symbol_per_bit_t CodedSymbolPerBit_t
Enumeration of type of symbols that can be used with LE coded PHY.
BLE address representation.
BLEProtocol::AddressType_t AddressType_t
Address-type for BLEProtocol addresses.
InitiatorPolicyMode_t
Connection initiation policy filter mode.
ble::central_privay_configuration_t CentralPrivacyConfiguration_t
Privacy configuration of the central role.
Function like object adapter over freestanding and member functions.
Common namespace for types and constants used everywhere in BLE API.
ScanningPolicyMode_t
Scanning policy filter mode.
Define device discovery, connection and link management procedures.
Duration< uint16_t, 10000, Range< 0x00, 0xFFFF >, Value< uint16_t, 0x0000 > > scan_duration_t
Scan process duration.
BLEProtocol::AddressBytes_t address_t
48-bit address, LSB format.
GapAdvertisingData _advPayload
Current advertising data.
uintptr_t connection_handle_t
Opaque reference to a connection.
Static Interface helper class.
uint16_t connectionSupervisionTimeout
Link supervision timeout for the connection.
uint8_t advertisingDataLen
Length of the advertisement data.
ble::peer_address_type_t PeerAddressType_t
Enumeration of peer address types.
uint16_t slaveLatency
Number of connection events the slave can drop if it has nothing to communicate to the master...
Duration< uint16_t, 10000, Range< 0x0A, 0x0C80 > > supervision_timeout_t
Time after which a connection is loss of devices have not exchanged data.
Type that describes a random device address type.
ble::connection_handle_t Handle_t
Opaque value type representing a connection handle.
uint16_t maxConnectionInterval
Maximum interval between two connection events allowed for a connection.
Parameters defining the advertising process.
Type describing the number of symbols per bit in le coded PHY.
Random static device address.
DisconnectionCallbackParams_t(Handle_t handleIn, DisconnectionReason_t reasonIn)
Construct a DisconnectionCallbackParams_t.
TimeoutEventCallbackChain_t timeoutCallbackChain
Callchain containing all registered callback handlers for timeout events.
CallChainOfFunctionPointersWithContext< const DisconnectionCallbackParams_t * > DisconnectionEventCallbackChain_t
Callchain of disconnection event handlers.
Parameters defining the scan process.
FunctionPointerWithContext< const LegacyGap * > GapShutdownCallback_t
Gap shutdown event handler.
Duration< uint16_t, 1250, Range< 0x06, 0x0C80 > > conn_interval_t
Time interval between two connection events.
BLEProtocol::AddressType_t addr_type_t
Address-type for BLEProtocol addresses.
Private resolvable device address.
Duration< uint16_t, 625, Range< 0, 0xFFFF > > conn_event_length_t
Duration of a connection event.
Handle_t handle
Connection handle.
Role_t role
Connection Role of the local device.
static const size_t ADDR_LEN
Length (in octets) of the BLE MAC address.
GAP advertising data builder.
FunctionPointerWithContext< const DisconnectionCallbackParams_t * > DisconnectionEventCallback_t
Disconnection event handler.
Define device discovery, connection and link management procedures.
ConnectionEventCallbackChain_t connectionCallChain
Callchain containing all registered callback handlers for connection events.
bool scanningActive
Active scanning flag.
static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis)
Convert milliseconds into 1.25ms units.
Description of the states of the device.
GapState_t state
Current GAP state.
GapAdvertisingParams _advParams
Current advertising parameters.
Type that describes a bluetooth PHY(sical) transport.
Duration< uint16_t, 1280000, Range< 0x00, 0xFFFF > > scan_period_t
Time interval between two scan processes.
DeprecatedAddressType_t
Address-type for BLEProtocol addresses.
BLEProtocol::AddressBytes_t Address_t
48-bit address, LSB format.
ble::phy_t Phy_t
Enumeration of BLE PHY.
bool isScanResponse
Flag indicating if the packet is a response to a scan request.
CallChainOfFunctionPointersWithContext< const LegacyGap * > GapShutdownCallbackChain_t
Callchain of gap shutdown event handler.
Representation of a scanned advertising packet.
uint8_t advertising_handle_t
Handle of an advertising set.
int8_t rssi
RSSI value of the packet.
FunctionPointerWithContext< bool > RadioNotificationEventCallback_t
Radio notification event handler.
Parameters of a BLE connection.
CallChainOfFunctionPointersWithContext< const ConnectionCallbackParams_t * > ConnectionEventCallbackChain_t
Callchain of connection event handlers.
GapAdvertisingParams::AdvertisingType_t type
Type of advertisement.
ble::phy_set_t PhySet_t
Set of BLE PHYs.
ble::random_address_type_t RandomAddressType_t
Enumeration of random address types.
GapScanningParams _scanningParams
Current scanning parameters.
DisconnectionReason_t
Enumeration of disconnection reasons.
uint8_t connectionCount
Number of open connections.
AdvertisingType_t
Encapsulates the peripheral advertising modes.
Type that describes a peer device address type.
enum Appearance_t Appearance
Alias for GapAdvertisingData::Appearance_t.
const uint8_t * advertisingData
Pointer to the advertisement packet's data.
Representation of a whitelist of addresses.
Type that describe a set of PHY(sical) transports.
uint16_t minConnectionInterval
Minimum interval between two connection events allowed for a connection.
RadioNotificationEventCallback_t radioNotificationCallback
The registered callback handler for radio notification events.
DisconnectionEventCallbackChain_t disconnectionCallChain
Callchain containing all registered callback handlers for disconnection events.
FunctionPointerWithContext< const ConnectionCallbackParams_t * > ConnectionEventCallback_t
Connection event handler.
GapAdvertisingData _scanResponse
Current scan response.
Bounded< uint16_t, 0, 0x01F3 > slave_latency_t
Number of connection events that can be skipped by the slave.
Private non-resolvable device address.
FunctionPointerWithContext< TimeoutSource_t > TimeoutEventCallback_t
Timeout event handler.
ble::peripheral_privacy_configuration_t PeripheralPrivacyConfiguration_t
Privacy Configuration of the peripheral role.
Privacy configuration of the central role.
Handle_t handle
ID of the connection that has ended.
AdvertisementReportCallback_t onAdvertisementReport
The registered callback handler for scanned advertisement packet notifications.
TimeoutSource_t
Enumeration of possible timeout sources.
AdvertisingPolicyMode_t
Advertising policy filter modes.
Privacy Configuration of the peripheral role.
BLEProtocol::AddressBytes_t peerAddr
BLE address of the device that has advertised the packet.
uint8_t AddressBytes_t[ADDR_LEN]
48-bit address, in LSB format.
uint8_t size
Number addresses in this whitelist.
Entry namespace for all BLE API definitions.
uint8_t capacity
Capacity of the array holding the addresses.
Type
Address-types for Protocol addresses.
DisconnectionReason_t reason
Reason of the disconnection.
Role_t
Enumeration of GAP roles.
CallChainOfFunctionPointersWithContext< TimeoutSource_t > TimeoutEventCallbackChain_t
Callchain of timeout event handlers.
Duration< uint16_t, 10000, Range< 0x00, 0xFFFF >, Value< uint16_t, 0x0000 > > adv_duration_t
Advertising process duration.
ble_error_t
Error codes for the BLE API.