guard class fields with ifs

pull/9790/head
paul-szczepanek-arm 2019-02-11 14:36:59 +00:00 committed by Vincent Coubard
parent 33e8826361
commit 3e03c11832
8 changed files with 185 additions and 69 deletions

View File

@ -59,14 +59,20 @@ class LegacyGap :
using ble::StaticInterface<Impl, ::ble::interface::LegacyGap>::impl; using ble::StaticInterface<Impl, ::ble::interface::LegacyGap>::impl;
public: public:
#if BLE_ROLE_BROADCASTER
using ble::interface::Gap<Impl>::setAdvertisingParameters; using ble::interface::Gap<Impl>::setAdvertisingParameters;
using ble::interface::Gap<Impl>::setAdvertisingPayload; using ble::interface::Gap<Impl>::setAdvertisingPayload;
using ble::interface::Gap<Impl>::setAdvertisingScanResponse; using ble::interface::Gap<Impl>::setAdvertisingScanResponse;
using ble::interface::Gap<Impl>::startAdvertising; using ble::interface::Gap<Impl>::startAdvertising;
using ble::interface::Gap<Impl>::stopAdvertising; using ble::interface::Gap<Impl>::stopAdvertising;
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE
using ble::interface::Gap<Impl>::connect; using ble::interface::Gap<Impl>::connect;
using ble::interface::Gap<Impl>::disconnect; using ble::interface::Gap<Impl>::disconnect;
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_ROLE_OBSERVER
using ble::interface::Gap<Impl>::startScan; using ble::interface::Gap<Impl>::startScan;
#endif
/** /**
* Address-type for BLEProtocol addresses. * Address-type for BLEProtocol addresses.
@ -400,6 +406,7 @@ public:
CENTRAL = 0x2, CENTRAL = 0x2,
}; };
#if BLE_ROLE_BROADCASTER
/** /**
* Representation of a scanned advertising packet. * Representation of a scanned advertising packet.
* *
@ -474,7 +481,9 @@ public:
*/ */
typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *>
AdvertisementReportCallback_t; AdvertisementReportCallback_t;
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE
/** /**
* Connection events. * Connection events.
* *
@ -665,6 +674,7 @@ public:
{ {
} }
}; };
#endif // BLE_FEATURE_CONNECTABLE
/** /**
* @copydoc ble::peripheral_privacy_configuration_t * @copydoc ble::peripheral_privacy_configuration_t
@ -844,6 +854,7 @@ public:
RandomAddressType_t *addressType RandomAddressType_t *addressType
); );
#if BLE_ROLE_BROADCASTER
/** /**
* Get the minimum advertising interval in milliseconds, which can be used * Get the minimum advertising interval in milliseconds, which can be used
* for connectable advertising types. * for connectable advertising types.
@ -886,7 +897,8 @@ public:
"Use stopAdvertising(advertising_handle_t) instead." "Use stopAdvertising(advertising_handle_t) instead."
) )
ble_error_t stopAdvertising(void); ble_error_t stopAdvertising(void);
#endif //BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE
/** /**
* Initiate a connection to a peer. * Initiate a connection to a peer.
* *
@ -1069,7 +1081,8 @@ public:
Handle_t handle, Handle_t handle,
const ConnectionParams_t *params const ConnectionParams_t *params
); );
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_GATT_SERVER
/** /**
* Set the value of the device name characteristic in the Generic Access * Set the value of the device name characteristic in the Generic Access
* Service. * Service.
@ -1123,7 +1136,8 @@ public:
* from the underlying BLE stack. * from the underlying BLE stack.
*/ */
ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
#endif // BLE_FEATURE_GATT_SERVER
#if BLE_ROLE_BROADCASTER
/** /**
* Set the radio's transmit power. * Set the radio's transmit power.
* *
@ -1157,7 +1171,8 @@ public:
void getPermittedTxPowerValues( void getPermittedTxPowerValues(
const int8_t **valueArrayPP, size_t *countP const int8_t **valueArrayPP, size_t *countP
); );
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_WHITELIST
/** /**
* Get the maximum size of the whitelist. * Get the maximum size of the whitelist.
* *
@ -1294,8 +1309,10 @@ public:
"Deprecated since addition of extended advertising support." "Deprecated since addition of extended advertising support."
) )
InitiatorPolicyMode_t getInitiatorPolicyMode(void) const; InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
#endif // BLE_FEATURE_WHITELIST
protected: protected:
#if BLE_ROLE_OBSERVER
/* Override the following in the underlying adaptation layer to provide the /* Override the following in the underlying adaptation layer to provide the
functionality of scanning. */ functionality of scanning. */
@ -1317,6 +1334,7 @@ protected:
"implement startScan(duplicates_filter_t, scan_duration_t, period)" "implement startScan(duplicates_filter_t, scan_duration_t, period)"
) )
ble_error_t startRadioScan(const GapScanningParams &scanningParams); ble_error_t startRadioScan(const GapScanningParams &scanningParams);
#endif // BLE_ROLE_OBSERVER
/* /*
* APIs with nonvirtual implementations. * APIs with nonvirtual implementations.
@ -1338,6 +1356,7 @@ public:
) )
GapState_t getState(void) const; GapState_t getState(void) const;
#if BLE_ROLE_BROADCASTER
/** /**
* Set the advertising type to use during the advertising procedure. * Set the advertising type to use during the advertising procedure.
* *
@ -1654,7 +1673,8 @@ public:
"Use setAdvertisingScanResponse() instead." "Use setAdvertisingScanResponse() instead."
) )
void clearScanResponse(void); void clearScanResponse(void);
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
/** /**
* Set the parameters used during a scan procedure. * Set the parameters used during a scan procedure.
* *
@ -1864,6 +1884,7 @@ public:
T *object, T *object,
void (T::*callbackMember)(const AdvertisementCallbackParams_t *params) void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)
); );
#endif // BLE_ROLE_OBSERVER
/** /**
* Enable radio-notification events. * Enable radio-notification events.
@ -1889,6 +1910,7 @@ public:
ble_error_t initRadioNotification(void); ble_error_t initRadioNotification(void);
private: private:
#if BLE_ROLE_BROADCASTER
/** /**
* Set the advertising data and scan response in the vendor subsytem. * Set the advertising data and scan response in the vendor subsytem.
* *
@ -1975,7 +1997,7 @@ public:
"Use setAdvertisingParameters() instead." "Use setAdvertisingParameters() instead."
) )
void setAdvertisingParams(const GapAdvertisingParams &newParams); void setAdvertisingParams(const GapAdvertisingParams &newParams);
#endif // BLE_ROLE_BROADCASTER
/* Event handlers. */ /* Event handlers. */
public: public:
@ -2016,7 +2038,7 @@ public:
"Use setEventHandler() instead." "Use setEventHandler() instead."
) )
TimeoutEventCallbackChain_t &onTimeout(); TimeoutEventCallbackChain_t &onTimeout();
#if BLE_FEATURE_CONNECTABLE
/** /**
* Register a callback handling connection events. * Register a callback handling connection events.
* *
@ -2126,7 +2148,7 @@ public:
"Use setEventHandler() instead." "Use setEventHandler() instead."
) )
DisconnectionEventCallbackChain_t &onDisconnection(); DisconnectionEventCallbackChain_t &onDisconnection();
#endif //BLE_FEATURE_CONNECTABLE
/** /**
* Set the radio-notification events handler. * Set the radio-notification events handler.
* *
@ -2235,6 +2257,7 @@ protected:
/* Entry points for the underlying stack to report events back to the user. */ /* Entry points for the underlying stack to report events back to the user. */
public: public:
#if BLE_FEATURE_CONNECTABLE
/** /**
* Notify all registered connection event handlers of a connection event. * Notify all registered connection event handlers of a connection event.
* *
@ -2329,7 +2352,8 @@ public:
"Use EventHandler::onDisconnectionComplete() instead" "Use EventHandler::onDisconnectionComplete() instead"
) )
void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason); void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason);
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_ROLE_OBSERVER
/** /**
* Forward a received advertising packet to all registered event handlers * Forward a received advertising packet to all registered event handlers
* listening for scanned packet events. * listening for scanned packet events.
@ -2399,7 +2423,7 @@ public:
const uint8_t *advertisingData, const uint8_t *advertisingData,
BLEProtocol::AddressType_t addressType = BLEProtocol::AddressType::RANDOM_STATIC BLEProtocol::AddressType_t addressType = BLEProtocol::AddressType::RANDOM_STATIC
); );
#endif // BLE_ROLE_OBSERVER
/** /**
* Notify the occurrence of a timeout event to all registered timeout events * Notify the occurrence of a timeout event to all registered timeout events
* handler. * handler.
@ -2420,6 +2444,7 @@ public:
void processTimeoutEvent(TimeoutSource_t source); void processTimeoutEvent(TimeoutSource_t source);
protected: protected:
#if BLE_ROLE_BROADCASTER
/** /**
* Current advertising parameters. * Current advertising parameters.
*/ */
@ -2429,31 +2454,36 @@ protected:
* Current advertising data. * Current advertising data.
*/ */
GapAdvertisingData _advPayload; GapAdvertisingData _advPayload;
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
/** /**
* Current scanning parameters. * Current scanning parameters.
*/ */
GapScanningParams _scanningParams; GapScanningParams _scanningParams;
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_BROADCASTER
/** /**
* Current scan response. * Current scan response.
*/ */
GapAdvertisingData _scanResponse; GapAdvertisingData _scanResponse;
#endif BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE
/** /**
* Number of open connections. * Number of open connections.
*/ */
uint8_t connectionCount; uint8_t connectionCount;
#endif // BLE_FEATURE_CONNECTABLE
/** /**
* Current GAP state. * Current GAP state.
*/ */
GapState_t state; GapState_t state;
#if BLE_ROLE_OBSERVER
/** /**
* Active scanning flag. * Active scanning flag.
*/ */
bool scanningActive; bool scanningActive;
#endif // BLE_ROLE_OBSERVER
protected: protected:
/** /**
@ -2467,12 +2497,14 @@ protected:
*/ */
RadioNotificationEventCallback_t radioNotificationCallback; RadioNotificationEventCallback_t radioNotificationCallback;
#if BLE_ROLE_OBSERVER
/** /**
* The registered callback handler for scanned advertisement packet * The registered callback handler for scanned advertisement packet
* notifications. * notifications.
*/ */
AdvertisementReportCallback_t onAdvertisementReport; AdvertisementReportCallback_t onAdvertisementReport;
#endif // BLE_ROLE_OBSERVER
#if BLE_FEATURE_CONNECTABLE
/** /**
* Callchain containing all registered callback handlers for connection * Callchain containing all registered callback handlers for connection
* events. * events.
@ -2484,7 +2516,7 @@ protected:
* events. * events.
*/ */
DisconnectionEventCallbackChain_t disconnectionCallChain; DisconnectionEventCallbackChain_t disconnectionCallChain;
#endif // BLE_FEATURE_CONNECTABLE
private: private:
/** /**
* Callchain containing all registered callback handlers for shutdown * Callchain containing all registered callback handlers for shutdown
@ -2619,6 +2651,7 @@ protected:
#pragma diag_suppress 1361 #pragma diag_suppress 1361
#endif #endif
#if BLE_ROLE_OBSERVER
template<class Impl> template<class Impl>
template<typename T> template<typename T>
ble_error_t LegacyGap<Impl>::startScan( ble_error_t LegacyGap<Impl>::startScan(
@ -2636,7 +2669,9 @@ ble_error_t LegacyGap<Impl>::startScan(
return err; return err;
} }
#endif // BLE_ROLE_OBSERVER
#if BLE_FEATURE_CONNECTABLE
template<class Impl> template<class Impl>
template<typename T> template<typename T>
void LegacyGap<Impl>::onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t *)) void LegacyGap<Impl>::onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t *))
@ -2650,6 +2685,7 @@ void LegacyGap<Impl>::onDisconnection(T *tptr, void (T::*mptr)(const Disconnecti
{ {
disconnectionCallChain.add(tptr, mptr); disconnectionCallChain.add(tptr, mptr);
} }
#endif //BLE_FEATURE_CONNECTABLE
template<class Impl> template<class Impl>
template<typename T> template<typename T>

View File

@ -319,7 +319,6 @@ public:
return _channel37; return _channel37;
} }
/** Check if channel 38 is used for primary advertising. /** Check if channel 38 is used for primary advertising.
* *
* @return True if channel used. * @return True if channel used.
@ -329,7 +328,6 @@ public:
return _channel38; return _channel38;
} }
/** Check if channel 39 is used for primary advertising. /** Check if channel 39 is used for primary advertising.
* *
* @return True if channel used. * @return True if channel used.
@ -394,7 +392,6 @@ public:
return _peerAddressType; return _peerAddressType;
}; };
#if BLE_FEATURE_WHITELIST
/** Set the filter policy of whitelist use during advertising; /** Set the filter policy of whitelist use during advertising;
* *
* @param mode Policy to use. * @param mode Policy to use.
@ -403,8 +400,12 @@ public:
*/ */
AdvertisingParameters &setFilter(advertising_filter_policy_t mode) AdvertisingParameters &setFilter(advertising_filter_policy_t mode)
{ {
#if BLE_FEATURE_WHITELIST
_policy = mode; _policy = mode;
return *this; return *this;
#else
#error "Whitelist feature disabled"
#endif // BLE_FEATURE_WHITELIST
} }
/** Get the filter policy of whitelist use during advertising; /** Get the filter policy of whitelist use during advertising;
@ -413,23 +414,15 @@ public:
*/ */
advertising_filter_policy_t getFilter() const advertising_filter_policy_t getFilter() const
{ {
#if BLE_FEATURE_WHITELIST
return _policy; return _policy;
}
#else #else
AdvertisingParameters &setFilter(advertising_filter_policy_t mode)
{
#error "Whitelist feature disabled"
}
advertising_filter_policy_t getFilter() const
{
return advertising_filter_policy_t::NO_FILTER; return advertising_filter_policy_t::NO_FILTER;
}
#endif // BLE_FEATURE_WHITELIST #endif // BLE_FEATURE_WHITELIST
}
/* Extended advertising parameters */ /* Extended advertising parameters */
/** Get PHYs used on primary and secondary advertising channels. /** Get PHYs used on primary and secondary advertising channels.
* *
* @param primaryPhy Primary advertising channels PHY. * @param primaryPhy Primary advertising channels PHY.

View File

@ -26,6 +26,7 @@
#include "ble/gap/ScanParameters.h" #include "ble/gap/ScanParameters.h"
#include "ble/gap/AdvertisingParameters.h" #include "ble/gap/AdvertisingParameters.h"
#include "ble/gap/Events.h" #include "ble/gap/Events.h"
#include "BLERoles.h"
namespace ble { namespace ble {
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)
@ -284,6 +285,7 @@ public:
* Definition of the general handler of Gap related events. * Definition of the general handler of Gap related events.
*/ */
struct EventHandler { struct EventHandler {
#if BLE_ROLE_BROADCASTER
/** /**
* Called when an advertising device receive a scan response. * Called when an advertising device receive a scan response.
* *
@ -312,7 +314,8 @@ public:
virtual void onAdvertisingEnd(const AdvertisingEndEvent &event) virtual void onAdvertisingEnd(const AdvertisingEndEvent &event)
{ {
} }
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
/** /**
* Called when a scanner receives an advertising or a scan response packet. * Called when a scanner receives an advertising or a scan response packet.
* *
@ -334,7 +337,8 @@ public:
virtual void onScanTimeout(const ScanTimeoutEvent &event) virtual void onScanTimeout(const ScanTimeoutEvent &event)
{ {
} }
#endif // BLE_ROLE_OBSERVER
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Called when first advertising packet in periodic advertising is received. * Called when first advertising packet in periodic advertising is received.
* *
@ -379,7 +383,8 @@ public:
) )
{ {
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_CONNECTABLE
/** /**
* Called when connection attempt ends or an advertising device has been * Called when connection attempt ends or an advertising device has been
* connected. * connected.
@ -440,7 +445,8 @@ public:
virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event) virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event)
{ {
} }
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT
/** /**
* Function invoked when the current transmitter and receiver PHY have * Function invoked when the current transmitter and receiver PHY have
* been read for a given connection. * been read for a given connection.
@ -521,7 +527,7 @@ public:
) )
{ {
} }
#endif // BLE_FEATURE_PHY_MANAGEMENT
protected: protected:
/** /**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor * Prevent polymorphic deletion and avoid unnecessary virtual destructor
@ -551,7 +557,7 @@ public:
bool isFeatureSupported(controller_supported_features_t feature); bool isFeatureSupported(controller_supported_features_t feature);
/* advertising */ /* advertising */
#if BLE_ROLE_BROADCASTER
/** Return currently available number of supported advertising sets. /** Return currently available number of supported advertising sets.
* This may change at runtime. * This may change at runtime.
* *
@ -689,7 +695,8 @@ public:
* @return True if advertising is active on this set. * @return True if advertising is active on this set.
*/ */
bool isAdvertisingActive(advertising_handle_t handle); bool isAdvertisingActive(advertising_handle_t handle);
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** Set periodic advertising parameters for a given advertising set. /** Set periodic advertising parameters for a given advertising set.
* *
* @param handle Advertising set handle. * @param handle Advertising set handle.
@ -754,9 +761,9 @@ public:
* @version 5+ * @version 5+
*/ */
bool isPeriodicAdvertisingActive(advertising_handle_t handle); bool isPeriodicAdvertisingActive(advertising_handle_t handle);
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
/* scanning */ /* scanning */
#if BLE_ROLE_OBSERVER
/** Set new scan parameters. /** Set new scan parameters.
* *
* @param params Scan parameters, @see GapScanParameters for details. * @param params Scan parameters, @see GapScanParameters for details.
@ -794,7 +801,8 @@ public:
* @retval BLE_ERROR_NONE if successfully stopped scanning procedure. * @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
*/ */
ble_error_t stopScan(); ble_error_t stopScan();
#endif // BLE_ROLE_OBSERVER
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** Synchronize with periodic advertising from an advertiser and begin receiving periodic /** Synchronize with periodic advertising from an advertiser and begin receiving periodic
* advertising packets. * advertising packets.
* *
@ -896,7 +904,8 @@ public:
* @return Number of devices that can be added to the periodic advertiser list. * @return Number of devices that can be added to the periodic advertiser list.
*/ */
uint8_t getMaxPeriodicAdvertiserListSize(); uint8_t getMaxPeriodicAdvertiserListSize();
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_CONNECTABLE
/** /**
* Initiate a connection to a peer. * Initiate a connection to a peer.
* *
@ -1069,7 +1078,8 @@ public:
connection_handle_t connectionHandle, connection_handle_t connectionHandle,
local_disconnection_reason_t reason local_disconnection_reason_t reason
); );
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT
/** /**
* Read the PHY used by the transmitter and the receiver on a connection. * Read the PHY used by the transmitter and the receiver on a connection.
* *
@ -1138,7 +1148,8 @@ public:
const phy_set_t *rxPhys, const phy_set_t *rxPhys,
coded_symbol_per_bit_t codedSymbol coded_symbol_per_bit_t codedSymbol
); );
#endif // BLE_FEATURE_PHY_MANAGEMENT
#if BLE_FEATURE_PRIVACY
/** /**
* Default peripheral privacy configuration. * Default peripheral privacy configuration.
*/ */
@ -1231,14 +1242,10 @@ public:
ble_error_t getCentralPrivacyConfiguration( ble_error_t getCentralPrivacyConfiguration(
central_privay_configuration_t *configuration central_privay_configuration_t *configuration
); );
#endif // BLE_FEATURE_PRIVACY
protected:
#if !defined(DOXYGEN_ONLY) #if !defined(DOXYGEN_ONLY)
protected:
/* Override the following in the underlying adaptation layer to provide the
* functionality of scanning. */
/** Can only be called if use_non_deprecated_scan_api() hasn't been called. /** Can only be called if use_non_deprecated_scan_api() hasn't been called.
* This guards against mixed use of deprecated and nondeprecated API. * This guards against mixed use of deprecated and nondeprecated API.
*/ */
@ -1249,12 +1256,6 @@ protected:
*/ */
void useVersionTwoAPI() const; void useVersionTwoAPI() const;
#endif
protected:
#if !defined(DOXYGEN_ONLY)
/** /**
* Construct a Gap instance. * Construct a Gap instance.
*/ */
@ -1396,13 +1397,13 @@ protected:
); );
void useVersionOneAPI_() const; void useVersionOneAPI_() const;
void useVersionTwoAPI_() const; void useVersionTwoAPI_() const;
#endif // !defined(DOXYGEN_ONLY)
protected:
/** /**
* Event handler provided by the application. * Event handler provided by the application.
*/ */
EventHandler *_eventHandler; EventHandler *_eventHandler;
#endif
}; };
/** /**

View File

@ -389,7 +389,7 @@ struct advertising_filter_policy_t : SafeEnum<advertising_filter_policy_t, uint8
* not used. * not used.
*/ */
NO_FILTER = 0x00, NO_FILTER = 0x00,
#if BLE_FEATURE_WHITELIST
/** /**
* Process connection requests from all devices but filter out scan requests * Process connection requests from all devices but filter out scan requests
* of devices that are not in the whitelist. * of devices that are not in the whitelist.
@ -407,6 +407,7 @@ struct advertising_filter_policy_t : SafeEnum<advertising_filter_policy_t, uint8
* whitelist. * whitelist.
*/ */
FILTER_SCAN_AND_CONNECTION_REQUESTS = 0x03 FILTER_SCAN_AND_CONNECTION_REQUESTS = 0x03
#endif // BLE_FEATURE_WHITELIST
}; };
/** /**
@ -431,7 +432,7 @@ struct scanning_filter_policy_t : SafeEnum<scanning_filter_policy_t, uint8_t> {
* addressed to this device. * addressed to this device.
*/ */
NO_FILTER = 0x00, NO_FILTER = 0x00,
#if BLE_FEATURE_WHITELIST
/** /**
* Accept only advertising packets from devices in the whitelist except * Accept only advertising packets from devices in the whitelist except
* directed advertising packets not addressed to this device. * directed advertising packets not addressed to this device.
@ -458,6 +459,7 @@ struct scanning_filter_policy_t : SafeEnum<scanning_filter_policy_t, uint8_t> {
* resolvable private address that cannot be resolved are also accepted. * resolvable private address that cannot be resolved are also accepted.
*/ */
FILTER_ADVERTISING_INCLUDE_UNRESOLVABLE_DIRECTED = 3 FILTER_ADVERTISING_INCLUDE_UNRESOLVABLE_DIRECTED = 3
#endif // BLE_FEATURE_WHITELIST
}; };
/** /**
@ -480,11 +482,12 @@ struct initiator_filter_policy_t : SafeEnum<initiator_filter_policy_t, uint8_t>
* The whitelist is not used to determine which advertiser to connect to. * The whitelist is not used to determine which advertiser to connect to.
*/ */
NO_FILTER, NO_FILTER,
#if BLE_FEATURE_WHITELIST
/** /**
* The whitelist is used to determine which advertiser to connect to. * The whitelist is used to determine which advertiser to connect to.
*/ */
USE_WHITE_LIST USE_WHITE_LIST
#endif // BLE_FEATURE_WHITELIST
}; };
/** /**

View File

@ -785,31 +785,39 @@ private:
private: private:
pal::EventQueue &_event_queue; pal::EventQueue &_event_queue;
#if BLE_FEATURE_GATT_SERVER
PalGap &_pal_gap; PalGap &_pal_gap;
pal::GenericAccessService &_gap_service; pal::GenericAccessService &_gap_service;
#endif
#if BLE_FEATURE_SECURITY #if BLE_FEATURE_SECURITY
PalSecurityManager &_pal_sm; PalSecurityManager &_pal_sm;
#endif #endif
BLEProtocol::AddressType_t _address_type; BLEProtocol::AddressType_t _address_type;
ble::address_t _address; ble::address_t _address;
#if BLE_FEATURE_WHITELIST
pal::initiator_policy_t _initiator_policy_mode; pal::initiator_policy_t _initiator_policy_mode;
pal::scanning_filter_policy_t _scanning_filter_policy; pal::scanning_filter_policy_t _scanning_filter_policy;
pal::advertising_filter_policy_t _advertising_filter_policy; pal::advertising_filter_policy_t _advertising_filter_policy;
#if BLE_FEATURE_WHITELIST
mutable Whitelist_t _whitelist; mutable Whitelist_t _whitelist;
#endif #endif // BLE_FEATURE_WHITELIST
#if BLE_FEATURE_PRIVACY
bool _privacy_enabled; bool _privacy_enabled;
PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration; PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration;
CentralPrivacyConfiguration_t _central_privacy_configuration; CentralPrivacyConfiguration_t _central_privacy_configuration;
#endif // BLE_FEATURE_PRIVACY
ble::address_t _random_static_identity_address; ble::address_t _random_static_identity_address;
bool _random_address_rotating; bool _random_address_rotating;
bool _scan_enabled; bool _scan_enabled;
#if BLE_ROLE_BROADCASTER
mbed::Timeout _advertising_timeout; mbed::Timeout _advertising_timeout;
#endif
#if BLE_ROLE_OBSERVER
mbed::Timeout _scan_timeout; mbed::Timeout _scan_timeout;
#endif
mbed::Ticker _address_rotation_ticker; mbed::Ticker _address_rotation_ticker;
#if BLE_FEATURE_EXTENDED_ADVERTISING
template<size_t bit_size> template<size_t bit_size>
struct BitArray { struct BitArray {
BitArray() : data() BitArray() : data()
@ -861,6 +869,7 @@ private:
BitArray<MAX_ADVERTISING_SETS> _active_periodic_sets; BitArray<MAX_ADVERTISING_SETS> _active_periodic_sets;
BitArray<MAX_ADVERTISING_SETS> _connectable_payload_size_exceeded; BitArray<MAX_ADVERTISING_SETS> _connectable_payload_size_exceeded;
BitArray<MAX_ADVERTISING_SETS> _set_is_connectable; BitArray<MAX_ADVERTISING_SETS> _set_is_connectable;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
// deprecation flags // deprecation flags
mutable bool _deprecated_scan_api_used : 1; mutable bool _deprecated_scan_api_used : 1;

View File

@ -906,18 +906,32 @@ ble_error_t LegacyGap<Impl>::reset(void)
template<class Impl> template<class Impl>
LegacyGap<Impl>::LegacyGap() : LegacyGap<Impl>::LegacyGap() :
#if BLE_ROLE_BROADCASTER
_advParams(), _advParams(),
_advPayload(), _advPayload(),
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
_scanningParams(), _scanningParams(),
#endif
#if BLE_ROLE_BROADCASTER
_scanResponse(), _scanResponse(),
#endif
#if BLE_FEATURE_CONNECTABLE
connectionCount(0), connectionCount(0),
#endif
state(), state(),
#if BLE_ROLE_OBSERVER
scanningActive(false), scanningActive(false),
#endif
timeoutCallbackChain(), timeoutCallbackChain(),
radioNotificationCallback(), radioNotificationCallback()
onAdvertisementReport(), #if BLE_ROLE_OBSERVER
connectionCallChain(), , onAdvertisementReport()
disconnectionCallChain() #endif
#if BLE_FEATURE_CONNECTABLE
, connectionCallChain()
, disconnectionCallChain()
#endif // BLE_FEATURE_CONNECTABLE
{ {
_advPayload.clear(); _advPayload.clear();
_scanResponse.clear(); _scanResponse.clear();
@ -977,19 +991,28 @@ ble_error_t LegacyGap<Impl>::reset_(void)
/* Clear Gap state */ /* Clear Gap state */
state.advertising = 0; state.advertising = 0;
state.connected = 0; state.connected = 0;
#if BLE_FEATURE_CONNECTABLE
connectionCount = 0; connectionCount = 0;
#endif
/* Clear scanning state */ /* Clear scanning state */
#if BLE_ROLE_OBSERVER
scanningActive = false; scanningActive = false;
#endif
#if BLE_ROLE_BROADCASTER
/* Clear advertising and scanning data */ /* Clear advertising and scanning data */
_advPayload.clear(); _advPayload.clear();
_scanResponse.clear(); _scanResponse.clear();
#endif // BLE_ROLE_BROADCASTER
/* Clear callbacks */ /* Clear callbacks */
timeoutCallbackChain.clear(); timeoutCallbackChain.clear();
#if BLE_FEATURE_CONNECTABLE
connectionCallChain.clear(); connectionCallChain.clear();
disconnectionCallChain.clear(); disconnectionCallChain.clear();
#endif // BLE_FEATURE_CONNECTABLE
radioNotificationCallback = NULL; radioNotificationCallback = NULL;
onAdvertisementReport = NULL; onAdvertisementReport = NULL;
ble::interface::Gap<Impl>::_eventHandler = NULL; ble::interface::Gap<Impl>::_eventHandler = NULL;

View File

@ -112,7 +112,9 @@ bool Gap<Impl>::isAdvertisingActive(advertising_handle_t handle)
{ {
return impl()->isAdvertisingActive_(handle); return impl()->isAdvertisingActive_(handle);
} }
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_PERIODIC_ADVERTISING
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::setPeriodicAdvertisingParameters( ble_error_t Gap<Impl>::setPeriodicAdvertisingParameters(
advertising_handle_t handle, advertising_handle_t handle,
@ -155,7 +157,9 @@ bool Gap<Impl>::isPeriodicAdvertisingActive(advertising_handle_t handle)
{ {
return impl()->isPeriodicAdvertisingActive_(handle); return impl()->isPeriodicAdvertisingActive_(handle);
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_ROLE_OBSERVER
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::setScanParameters(const ScanParameters &params) ble_error_t Gap<Impl>::setScanParameters(const ScanParameters &params)
{ {
@ -177,7 +181,8 @@ ble_error_t Gap<Impl>::stopScan()
{ {
return impl()->stopScan_(); return impl()->stopScan_();
} }
#endif // BLE_ROLE_OBSERVER
#if BLE_FEATURE_PERIODIC_ADVERTISING
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::createSync( ble_error_t Gap<Impl>::createSync(
peer_address_type_t peerAddressType, peer_address_type_t peerAddressType,
@ -256,7 +261,9 @@ uint8_t Gap<Impl>::getMaxPeriodicAdvertiserListSize()
{ {
return impl()->getMaxPeriodicAdvertiserListSize_(); return impl()->getMaxPeriodicAdvertiserListSize_();
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_CONNECTABLE
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::connect( ble_error_t Gap<Impl>::connect(
peer_address_type_t peerAddressType, peer_address_type_t peerAddressType,
@ -345,7 +352,9 @@ ble_error_t Gap<Impl>::disconnect(
{ {
return impl()->disconnect_(connectionHandle, reason); return impl()->disconnect_(connectionHandle, reason);
} }
#endif BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::readPhy(connection_handle_t connection) ble_error_t Gap<Impl>::readPhy(connection_handle_t connection)
{ {
@ -393,6 +402,7 @@ template<class Impl>
Gap<Impl>::Gap() : _eventHandler(NULL) Gap<Impl>::Gap() : _eventHandler(NULL)
{ {
} }
#endif // BLE_FEATURE_PHY_MANAGEMENT
/* -------------------- Future deprecation ------------------------- */ /* -------------------- Future deprecation ------------------------- */
@ -408,6 +418,7 @@ const central_privay_configuration_t Gap<Impl>::default_central_privacy_configur
/* resolution_strategy */ central_privay_configuration_t::RESOLVE_AND_FORWARD /* resolution_strategy */ central_privay_configuration_t::RESOLVE_AND_FORWARD
}; };
#if BLE_FEATURE_PRIVACY
template<class Impl> template<class Impl>
ble_error_t Gap<Impl>::enablePrivacy(bool enable) ble_error_t Gap<Impl>::enablePrivacy(bool enable)
{ {
@ -445,6 +456,7 @@ ble_error_t Gap<Impl>::getCentralPrivacyConfiguration(
{ {
return impl()->getCentralPrivacyConfiguration_(configuration); return impl()->getCentralPrivacyConfiguration_(configuration);
} }
#endif // BLE_FEATURE_PRIVACY
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/* ------------------------- Default implementations ------------------------ */ /* ------------------------- Default implementations ------------------------ */
@ -456,6 +468,7 @@ bool Gap<Impl>::isFeatureSupported_(controller_supported_features_t feature)
return false; return false;
} }
#if BLE_ROLE_BROADCASTER
template<class Impl> template<class Impl>
uint8_t Gap<Impl>::getMaxAdvertisingSetNumber_() uint8_t Gap<Impl>::getMaxAdvertisingSetNumber_()
{ {

View File

@ -436,17 +436,25 @@ GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::
_pal_sm(pal_sm), _pal_sm(pal_sm),
#endif #endif
_address_type(LegacyAddressType::PUBLIC), _address_type(LegacyAddressType::PUBLIC),
#if BLE_FEATURE_WHITELIST
_initiator_policy_mode(pal::initiator_policy_t::NO_FILTER), _initiator_policy_mode(pal::initiator_policy_t::NO_FILTER),
_scanning_filter_policy(pal::scanning_filter_policy_t::NO_FILTER), _scanning_filter_policy(pal::scanning_filter_policy_t::NO_FILTER),
_advertising_filter_policy(pal::advertising_filter_policy_t::NO_FILTER), _advertising_filter_policy(pal::advertising_filter_policy_t::NO_FILTER),
_whitelist(), _whitelist(),
#endif // BLE_FEATURE_WHITELIST
#if BLE_FEATURE_PRIVACY
_privacy_enabled(false), _privacy_enabled(false),
_peripheral_privacy_configuration(default_peripheral_privacy_configuration), _peripheral_privacy_configuration(default_peripheral_privacy_configuration),
_central_privacy_configuration(default_central_privacy_configuration), _central_privacy_configuration(default_central_privacy_configuration),
#endif //BLE_FEATURE_PRIVACY
_random_address_rotating(false), _random_address_rotating(false),
_scan_enabled(false), _scan_enabled(false),
#if BLE_ROLE_BROADCASTER
_advertising_timeout(), _advertising_timeout(),
#endif
#if BLE_ROLE_OBSERVER
_scan_timeout(), _scan_timeout(),
#endif
_deprecated_scan_api_used(false), _deprecated_scan_api_used(false),
_non_deprecated_scan_api_used(false), _non_deprecated_scan_api_used(false),
_user_manage_connection_parameter_requests(false) _user_manage_connection_parameter_requests(false)
@ -639,7 +647,11 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
return _pal_gap.create_connection( return _pal_gap.create_connection(
scanParams->getInterval(), scanParams->getInterval(),
scanParams->getWindow(), scanParams->getWindow(),
#if BLE_FEATURE_WHITELIST
_initiator_policy_mode, _initiator_policy_mode,
#else
pal::initiator_policy_t::NO_FILTER,
#endif
(pal::connection_peer_address_type_t::type) peerAddrType.value(), (pal::connection_peer_address_type_t::type) peerAddrType.value(),
ble::address_t(peerAddr), ble::address_t(peerAddr),
get_own_address_type(CENTRAL_CONNECTION /* requires resolvable address */), get_own_address_type(CENTRAL_CONNECTION /* requires resolvable address */),
@ -1187,8 +1199,6 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
{ {
useVersionOneAPI(); useVersionOneAPI();
useVersionOneAPI();
if (mode > LegacyGap::SCAN_POLICY_FILTER_ALL_ADV) { if (mode > LegacyGap::SCAN_POLICY_FILTER_ALL_ADV) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }
@ -1240,24 +1250,32 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }
#if BLE_FEATURE_WHITELIST
if (_scanning_filter_policy == pal::scanning_filter_policy_t::FILTER_ADVERTISING && if (_scanning_filter_policy == pal::scanning_filter_policy_t::FILTER_ADVERTISING &&
_whitelist.size == 0) { _whitelist.size == 0) {
return BLE_ERROR_INVALID_STATE; return BLE_ERROR_INVALID_STATE;
} }
#endif // BLE_FEATURE_WHITELIST
pal::own_address_type_t own_address_type = get_own_address_type(CENTRAL_SCAN /* central, can use non resolvable address for scan requests */); pal::own_address_type_t own_address_type = get_own_address_type(CENTRAL_SCAN /* central, can use non resolvable address for scan requests */);
#if BLE_FEATURE_PRIVACY
if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) { if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) {
// Use non-resolvable static random address // Use non-resolvable static random address
set_random_address_rotation(true); set_random_address_rotation(true);
} }
#endif // BLE_FEATURE_PRIVACY
ble_error_t err = _pal_gap.set_scan_parameters( ble_error_t err = _pal_gap.set_scan_parameters(
scanningParams.getActiveScanning(), scanningParams.getActiveScanning(),
scanningParams.getInterval(), scanningParams.getInterval(),
scanningParams.getWindow(), scanningParams.getWindow(),
own_address_type, own_address_type,
#if BLE_FEATURE_WHITELIST
_scanning_filter_policy _scanning_filter_policy
#else
pal::scanning_filter_policy_t::NO_FILTER
#endif // BLE_FEATURE_WHITELIST
); );
if (err) { if (err) {
@ -1391,10 +1409,12 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
pal::own_address_type_t own_address_type = get_own_address_type(address_use_type); pal::own_address_type_t own_address_type = get_own_address_type(address_use_type);
#if BLE_FEATURE_PRIVACY
if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) { if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) {
// Use non-resolvable static random address // Use non-resolvable static random address
set_random_address_rotation(true); set_random_address_rotation(true);
} }
#endif // BLE_FEATURE_PRIVACY
// TODO: fix the high level API to have a min/max range // TODO: fix the high level API to have a min/max range
// Going against recommendations (The Advertising_Interval_Min and // Going against recommendations (The Advertising_Interval_Min and
@ -1410,7 +1430,11 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
pal::advertising_peer_address_type_t::PUBLIC, pal::advertising_peer_address_type_t::PUBLIC,
ble::address_t(), ble::address_t(),
pal::advertising_channel_map_t::ALL_ADVERTISING_CHANNELS, pal::advertising_channel_map_t::ALL_ADVERTISING_CHANNELS,
#if BLE_FEATURE_WHITELIST
_advertising_filter_policy _advertising_filter_policy
#else
pal::advertising_filter_policy_t::NO_FILTER
#endif
); );
if (err) { if (err) {
@ -1441,8 +1465,12 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
{ {
LegacyGap::reset_(); LegacyGap::reset_();
#if BLE_ROLE_BROADCASTER
_advertising_timeout.detach(); _advertising_timeout.detach();
#endif
#if BLE_ROLE_OBSERVER
_scan_timeout.detach(); _scan_timeout.detach();
#endif
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
/* stop all advertising sets */ /* stop all advertising sets */
@ -1650,6 +1678,7 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
for (size_t i = 0; i < e.size(); ++i) { for (size_t i = 0; i < e.size(); ++i) {
pal::GapAdvertisingReportEvent::advertising_t advertising = e[i]; pal::GapAdvertisingReportEvent::advertising_t advertising = e[i];
#if BLE_FEATURE_PRIVACY
// Check if the address hasn't been resolved // Check if the address hasn't been resolved
if (_privacy_enabled && if (_privacy_enabled &&
_central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER && _central_privacy_configuration.resolution_strategy == CentralPrivacyConfiguration_t::RESOLVE_AND_FILTER &&
@ -1659,6 +1688,7 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
// Filter it out // Filter it out
continue; continue;
} }
#endif // BLE_FEATURE_PRIVACY
// note 1-to-1 conversion between connection_peer_address_type_t and // note 1-to-1 conversion between connection_peer_address_type_t and
// peer_address_type_t // peer_address_type_t
@ -1756,6 +1786,8 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
bool needs_pairing = false; bool needs_pairing = false;
bool needs_authentication = false; bool needs_authentication = false;
#if BLE_ROLE_PERIPHERAL
#if BLE_FEATURE_PRIVACY
if (_privacy_enabled && if (_privacy_enabled &&
e.role.value() == e.role.PERIPHERAL && e.role.value() == e.role.PERIPHERAL &&
e.peer_address_type == peer_address_type_t::RANDOM e.peer_address_type == peer_address_type_t::RANDOM
@ -1791,6 +1823,7 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
} }
} }
} }
#endif // BLE_FEATURE_PRIVACY
if (e.role.value() == e.role.PERIPHERAL) { if (e.role.value() == e.role.PERIPHERAL) {
_advertising_timeout.detach(); _advertising_timeout.detach();
@ -1799,6 +1832,7 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
// Stop address rotation if required // Stop address rotation if required
set_random_address_rotation(false); set_random_address_rotation(false);
} }
#endif // BLE_ROLE_PERIPHERAL
// using these parameters if stupid, there is no range for the // using these parameters if stupid, there is no range for the
// connection interval when the connection is established // connection interval when the connection is established
@ -1932,6 +1966,7 @@ void GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandl
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
pal::own_address_type_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::get_own_address_type(AddressUseType_t address_use_type) pal::own_address_type_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::get_own_address_type(AddressUseType_t address_use_type)
{ {
#if BLE_FEATURE_PRIVACY
if (_privacy_enabled) { if (_privacy_enabled) {
bool use_non_resolvable_address = false; bool use_non_resolvable_address = false;
if (address_use_type == CENTRAL_SCAN) { if (address_use_type == CENTRAL_SCAN) {
@ -1952,6 +1987,7 @@ pal::own_address_type_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEve
return pal::own_address_type_t::RESOLVABLE_PRIVATE_ADDRESS_RANDOM_FALLBACK; return pal::own_address_type_t::RESOLVABLE_PRIVATE_ADDRESS_RANDOM_FALLBACK;
} }
} }
#endif // BLE_FEATURE_PRIVACY
switch (_address_type) { switch (_address_type) {
case BLEProtocol::AddressType::PUBLIC: case BLEProtocol::AddressType::PUBLIC:
@ -3092,9 +3128,11 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
{ {
useVersionTwoAPI(); useVersionTwoAPI();
#if BLE_FEATURE_PRIVACY
if (_privacy_enabled && _central_privacy_configuration.use_non_resolvable_random_address) { if (_privacy_enabled && _central_privacy_configuration.use_non_resolvable_random_address) {
set_random_address_rotation(true); set_random_address_rotation(true);
} }
#endif // BLE_FEATURE_PRIVACY
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
ble_error_t err = _pal_gap.extended_scan_enable( ble_error_t err = _pal_gap.extended_scan_enable(