BLE: Conditionally compile PAL depending on the feature selected.

Previously (most) of the code was not pulled in because the pal interface was not virtual.
pull/13811/head
Vincent Coubard 2020-10-23 12:17:31 +01:00
parent 26300912d3
commit 2e859cdab4
6 changed files with 157 additions and 33 deletions

View File

@ -414,6 +414,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
void BLEInstanceBase::device_manager_cb(dmEvt_t *dm_event) void BLEInstanceBase::device_manager_cb(dmEvt_t *dm_event)
{ {
#if BLE_FEATURE_CONNECTABLE
if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) { if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) {
// this event can only happen after a connection has been established therefore gap is present // this event can only happen after a connection has been established therefore gap is present
ble::PalGapEventHandler *handler; ble::PalGapEventHandler *handler;
@ -427,6 +428,7 @@ void BLEInstanceBase::device_manager_cb(dmEvt_t *dm_event)
} }
return; return;
} }
#endif
BLEInstanceBase::deviceInstance().stack_handler(0, &dm_event->hdr); BLEInstanceBase::deviceInstance().stack_handler(0, &dm_event->hdr);
} }

View File

@ -104,7 +104,7 @@ ble_error_t PalGap::set_random_address(const address_t &address)
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#if BLE_ROLE_BROADCASTER
ble_error_t PalGap::set_advertising_parameters( ble_error_t PalGap::set_advertising_parameters(
uint16_t advertising_interval_min, uint16_t advertising_interval_min,
uint16_t advertising_interval_max, uint16_t advertising_interval_max,
@ -233,8 +233,9 @@ ble_error_t PalGap::advertising_enable(bool enable)
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
ble_error_t PalGap::set_scan_parameters( ble_error_t PalGap::set_scan_parameters(
bool active_scanning, bool active_scanning,
uint16_t scan_interval, uint16_t scan_interval,
@ -276,8 +277,9 @@ ble_error_t PalGap::scan_enable(
} }
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_CENTRAL
ble_error_t PalGap::create_connection( ble_error_t PalGap::create_connection(
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
@ -342,8 +344,9 @@ ble_error_t PalGap::cancel_connection_creation()
return error; return error;
} }
#endif // BLE_ROLE_CENTRAL
#if BLE_FEATURE_WHITELIST
uint8_t PalGap::read_white_list_capacity() uint8_t PalGap::read_white_list_capacity()
{ {
return HciGetWhiteListSize(); return HciGetWhiteListSize();
@ -381,8 +384,9 @@ ble_error_t PalGap::remove_device_from_whitelist(
); );
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_WHITELIST
#if BLE_FEATURE_CONNECTABLE
ble_error_t PalGap::connection_parameters_update( ble_error_t PalGap::connection_parameters_update(
connection_handle_t connection, connection_handle_t connection,
uint16_t connection_interval_min, uint16_t connection_interval_min,
@ -463,6 +467,9 @@ ble_error_t PalGap::disconnect(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT
ble_error_t PalGap::read_phy(connection_handle_t connection) ble_error_t PalGap::read_phy(connection_handle_t connection)
{ {
if (is_feature_supported(controller_supported_features_t::LE_2M_PHY) if (is_feature_supported(controller_supported_features_t::LE_2M_PHY)
@ -514,6 +521,7 @@ ble_error_t PalGap::set_phy(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_PHY_MANAGEMENT
// singleton of the ARM Cordio client // singleton of the ARM Cordio client
@ -766,6 +774,7 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
} }
break; break;
#if BLE_ROLE_PERIPHERAL
case DM_CONN_CLOSE_IND: { case DM_CONN_CLOSE_IND: {
// Intercept connection close indication received when direct advertising timeout. // Intercept connection close indication received when direct advertising timeout.
// Leave the rest of the processing to the event handlers bellow. // Leave the rest of the processing to the event handlers bellow.
@ -775,16 +784,21 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
get_gap().get_running_conn_direct_adv_cb(evt->hdr.param); get_gap().get_running_conn_direct_adv_cb(evt->hdr.param);
if (adv_cb) { if (adv_cb) {
adv_cb->state = direct_adv_cb_t::free; adv_cb->state = direct_adv_cb_t::free;
#if BLE_ROLE_BROADCASTER
if (handler) { if (handler) {
handler->on_advertising_set_terminated( #if BLE_FEATURE_EXTENDED_ADVERTISING
hci_error_code_t(evt->status), if (get_gap().is_feature_supported(controller_supported_features_t::LE_EXTENDED_ADVERTISING)) {
adv_cb->advertising_handle, handler->on_advertising_set_terminated(
DM_CONN_ID_NONE, hci_error_code_t(evt->status),
0 adv_cb->advertising_handle,
); DM_CONN_ID_NONE,
0
);
} else
#endif
{
handler->on_legacy_advertising_stopped();
}
} }
#endif // BLE_ROLE_BROADCASTER
} }
} }
} }
@ -801,6 +815,7 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
} }
} }
break; break;
#endif // BLE_ROLE_PERIPHERAL
#endif // BLE_FEATURE_CONNECTABLE #endif // BLE_FEATURE_CONNECTABLE
} }
@ -843,7 +858,8 @@ bool PalGap::event_handler(const wsfMsgHdr_t *msg)
return false; return false;
} }
#if BLE_ROLE_BROADCASTER
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::set_advertising_set_random_address( ble_error_t PalGap::set_advertising_set_random_address(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
const address_t &address const address_t &address
@ -853,7 +869,6 @@ ble_error_t PalGap::set_advertising_set_random_address(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::set_extended_advertising_parameters( ble_error_t PalGap::set_extended_advertising_parameters(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_event_properties_t event_properties, advertising_event_properties_t event_properties,
@ -995,6 +1010,7 @@ ble_error_t PalGap::set_extended_advertising_parameters(
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING #endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t PalGap::set_periodic_advertising_parameters( ble_error_t PalGap::set_periodic_advertising_parameters(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
periodic_advertising_interval_t periodic_advertising_min, periodic_advertising_interval_t periodic_advertising_min,
@ -1012,8 +1028,9 @@ ble_error_t PalGap::set_periodic_advertising_parameters(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::set_extended_advertising_data( ble_error_t PalGap::set_extended_advertising_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
@ -1037,8 +1054,9 @@ ble_error_t PalGap::set_extended_advertising_data(
); );
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // #if BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t PalGap::set_periodic_advertising_data( ble_error_t PalGap::set_periodic_advertising_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t fragment_description, advertising_fragment_description_t fragment_description,
@ -1054,8 +1072,9 @@ ble_error_t PalGap::set_periodic_advertising_data(
); );
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::set_extended_scan_response_data( ble_error_t PalGap::set_extended_scan_response_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
@ -1170,8 +1189,9 @@ ble_error_t PalGap::extended_advertising_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t PalGap::periodic_advertising_enable( ble_error_t PalGap::periodic_advertising_enable(
bool enable, bool enable,
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
@ -1185,7 +1205,7 @@ ble_error_t PalGap::periodic_advertising_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif
uint16_t PalGap::get_maximum_advertising_data_length() uint16_t PalGap::get_maximum_advertising_data_length()
{ {
@ -1210,7 +1230,7 @@ uint8_t PalGap::get_max_number_of_advertising_sets()
return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS); return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS);
} }
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::remove_advertising_set(advertising_handle_t advertising_handle) ble_error_t PalGap::remove_advertising_set(advertising_handle_t advertising_handle)
{ {
DmAdvRemoveAdvSet(advertising_handle); DmAdvRemoveAdvSet(advertising_handle);
@ -1223,8 +1243,11 @@ ble_error_t PalGap::clear_advertising_sets()
DmAdvClearAdvSets(); DmAdvClearAdvSets();
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::set_extended_scan_parameters( ble_error_t PalGap::set_extended_scan_parameters(
own_address_type_t own_address_type, own_address_type_t own_address_type,
scanning_filter_policy_t filter_policy, scanning_filter_policy_t filter_policy,
@ -1287,8 +1310,9 @@ ble_error_t PalGap::extended_scan_enable(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t PalGap::periodic_advertising_create_sync( ble_error_t PalGap::periodic_advertising_create_sync(
bool use_periodic_advertiser_list, bool use_periodic_advertiser_list,
uint8_t advertising_sid, uint8_t advertising_sid,
@ -1376,8 +1400,10 @@ uint8_t PalGap::read_periodic_advertiser_list_size()
{ {
return HciGetPerAdvListSize(); return HciGetPerAdvListSize();
} }
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_CENTRAL && BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::extended_create_connection( ble_error_t PalGap::extended_create_connection(
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
own_address_type_t own_address_type, own_address_type_t own_address_type,
@ -1430,6 +1456,7 @@ ble_error_t PalGap::extended_create_connection(
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
#endif // BLE_ROLE_CENTRAL && BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t PalGap::update_direct_advertising_parameters( ble_error_t PalGap::update_direct_advertising_parameters(

View File

@ -50,6 +50,7 @@ public:
ble_error_t set_random_address(const address_t &address) final; ble_error_t set_random_address(const address_t &address) final;
#if BLE_ROLE_BROADCASTER
ble_error_t set_advertising_parameters( ble_error_t set_advertising_parameters(
uint16_t advertising_interval_min, uint16_t advertising_interval_min,
uint16_t advertising_interval_max, uint16_t advertising_interval_max,
@ -72,7 +73,9 @@ public:
) final; ) final;
ble_error_t advertising_enable(bool enable) final; ble_error_t advertising_enable(bool enable) final;
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
ble_error_t set_scan_parameters( ble_error_t set_scan_parameters(
bool active_scanning, bool active_scanning,
uint16_t scan_interval, uint16_t scan_interval,
@ -85,7 +88,9 @@ public:
bool enable, bool enable,
bool filter_duplicates bool filter_duplicates
) final; ) final;
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_CENTRAL
ble_error_t create_connection( ble_error_t create_connection(
uint16_t scan_interval, uint16_t scan_interval,
uint16_t scan_window, uint16_t scan_window,
@ -102,7 +107,9 @@ public:
) final; ) final;
ble_error_t cancel_connection_creation(); ble_error_t cancel_connection_creation();
#endif
#if BLE_FEATURE_WHITELIST
uint8_t read_white_list_capacity() final; uint8_t read_white_list_capacity() final;
ble_error_t clear_whitelist() final; ble_error_t clear_whitelist() final;
@ -116,7 +123,9 @@ public:
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
) final; ) final;
#endif // BLE_FEATURE_WHITELIST
#if BLE_FEATURE_CONNECTABLE
ble_error_t connection_parameters_update( ble_error_t connection_parameters_update(
connection_handle_t connection, connection_handle_t connection,
uint16_t connection_interval_min, uint16_t connection_interval_min,
@ -146,7 +155,9 @@ public:
connection_handle_t connection, connection_handle_t connection,
local_disconnection_reason_t disconnection_reason local_disconnection_reason_t disconnection_reason
) final; ) final;
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT
ble_error_t read_phy(connection_handle_t connection) final; ble_error_t read_phy(connection_handle_t connection) final;
ble_error_t set_preferred_phys( ble_error_t set_preferred_phys(
@ -160,6 +171,7 @@ public:
const phy_set_t &rx_phys, const phy_set_t &rx_phys,
coded_symbol_per_bit_t coded_symbol coded_symbol_per_bit_t coded_symbol
) final; ) final;
#endif // BLE_FEATURE_PHY_MANAGEMENT
// singleton of the ARM Cordio client // singleton of the ARM Cordio client
static PalGap &get_gap(); static PalGap &get_gap();
@ -169,12 +181,13 @@ public:
*/ */
static void gap_handler(const wsfMsgHdr_t *msg); static void gap_handler(const wsfMsgHdr_t *msg);
#if BLE_ROLE_BROADCASTER
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t set_advertising_set_random_address( ble_error_t set_advertising_set_random_address(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
const address_t &address const address_t &address
) final; ) final;
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t set_extended_advertising_parameters( ble_error_t set_extended_advertising_parameters(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_event_properties_t event_properties, advertising_event_properties_t event_properties,
@ -194,13 +207,17 @@ public:
) final; ) final;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING #endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t set_periodic_advertising_parameters( ble_error_t set_periodic_advertising_parameters(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
periodic_advertising_interval_t periodic_advertising_min, periodic_advertising_interval_t periodic_advertising_min,
periodic_advertising_interval_t periodic_advertising_max, periodic_advertising_interval_t periodic_advertising_max,
bool advertise_power bool advertise_power
) final; ) final;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t set_extended_advertising_data( ble_error_t set_extended_advertising_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
@ -208,14 +225,18 @@ public:
uint8_t advertising_data_size, uint8_t advertising_data_size,
const uint8_t *advertising_data const uint8_t *advertising_data
) final; ) final;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t set_periodic_advertising_data( ble_error_t set_periodic_advertising_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t fragment_description, advertising_fragment_description_t fragment_description,
uint8_t advertising_data_size, uint8_t advertising_data_size,
const uint8_t *advertising_data const uint8_t *advertising_data
) final; ) final;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t set_extended_scan_response_data( ble_error_t set_extended_scan_response_data(
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
advertising_fragment_description_t operation, advertising_fragment_description_t operation,
@ -231,11 +252,14 @@ public:
const uint16_t *durations, const uint16_t *durations,
const uint8_t *max_extended_advertising_events const uint8_t *max_extended_advertising_events
) final; ) final;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t periodic_advertising_enable( ble_error_t periodic_advertising_enable(
bool enable, bool enable,
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
) final; ) final;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
uint16_t get_maximum_advertising_data_length() final; uint16_t get_maximum_advertising_data_length() final;
@ -245,12 +269,17 @@ public:
uint8_t get_max_number_of_advertising_sets() final; uint8_t get_max_number_of_advertising_sets() final;
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t remove_advertising_set( ble_error_t remove_advertising_set(
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
) final; ) final;
ble_error_t clear_advertising_sets() final; ble_error_t clear_advertising_sets() final;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
#if BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t set_extended_scan_parameters( ble_error_t set_extended_scan_parameters(
own_address_type_t own_address_type, own_address_type_t own_address_type,
scanning_filter_policy_t filter_policy, scanning_filter_policy_t filter_policy,
@ -266,7 +295,9 @@ public:
uint16_t duration, uint16_t duration,
uint16_t period uint16_t period
) final; ) final;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
ble_error_t periodic_advertising_create_sync( ble_error_t periodic_advertising_create_sync(
bool use_periodic_advertiser_list, bool use_periodic_advertiser_list,
uint8_t advertising_sid, uint8_t advertising_sid,
@ -297,7 +328,10 @@ public:
ble_error_t clear_periodic_advertiser_list() final; ble_error_t clear_periodic_advertiser_list() final;
uint8_t read_periodic_advertiser_list_size() final; uint8_t read_periodic_advertiser_list_size() final;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_CENTRAL && BLE_FEATURE_EXTENDED_ADVERTISING
ble_error_t extended_create_connection( ble_error_t extended_create_connection(
initiator_policy_t initiator_policy, initiator_policy_t initiator_policy,
own_address_type_t own_address_type, own_address_type_t own_address_type,
@ -313,6 +347,7 @@ public:
const uint16_t *minimum_connection_event_lengths, const uint16_t *minimum_connection_event_lengths,
const uint16_t *maximum_connection_event_lengths const uint16_t *maximum_connection_event_lengths
) final; ) final;
#endif // BLE_ROLE_CENTRAL && BLE_FEATURE_EXTENDED_ADVERTISING
void when_gap_event_received(mbed::Callback<void(const GapEvent &)> cb) final; void when_gap_event_received(mbed::Callback<void(const GapEvent &)> cb) final;

View File

@ -494,9 +494,12 @@ ble_error_t Gap::stopScan()
_scan_requested = false; _scan_requested = false;
if (_scan_state == ScanState::scan) { if (_scan_state == ScanState::scan) {
#if BLE_FEATURE_EXTENDED_ADVERTISING
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
err = _pal_gap.extended_scan_enable(false, duplicates_filter_t::DISABLE, 0, 0); err = _pal_gap.extended_scan_enable(false, duplicates_filter_t::DISABLE, 0, 0);
} else { } else
#endif
{
err = _pal_gap.scan_enable(false, false); err = _pal_gap.scan_enable(false, false);
} }
@ -616,7 +619,9 @@ ble_error_t Gap::connect(
connectionParams.getMaxConnectionIntervalArray()[0] connectionParams.getMaxConnectionIntervalArray()[0]
); );
} }
} else { }
#if BLE_FEATURE_EXTENDED_ADVERTISING
else {
// set the correct mac address before starting scanning. // set the correct mac address before starting scanning.
if (_scan_state == ScanState::idle) { if (_scan_state == ScanState::idle) {
_pal_gap.set_random_address(*address); _pal_gap.set_random_address(*address);
@ -659,6 +664,7 @@ ble_error_t Gap::connect(
); );
} }
} }
#endif
if (ret == BLE_ERROR_NONE) { if (ret == BLE_ERROR_NONE) {
_initiating = true; _initiating = true;
@ -808,6 +814,7 @@ void Gap::on_read_phy(
} }
#endif // BLE_FEATURE_PHY_MANAGEMENT #endif // BLE_FEATURE_PHY_MANAGEMENT
#if BLE_FEATURE_CONNECTABLE
void Gap::on_data_length_change( void Gap::on_data_length_change(
connection_handle_t connection_handle, connection_handle_t connection_handle,
uint16_t tx_size, uint16_t tx_size,
@ -818,6 +825,7 @@ void Gap::on_data_length_change(
_event_handler->onDataLengthChange(connection_handle, tx_size, rx_size); _event_handler->onDataLengthChange(connection_handle, tx_size, rx_size);
} }
} }
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_PHY_MANAGEMENT #if BLE_FEATURE_PHY_MANAGEMENT
void Gap::on_phy_update_complete( void Gap::on_phy_update_complete(
@ -1083,13 +1091,12 @@ ble_error_t Gap::reset()
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
#endif // BLE_FEATURE_PRIVACY #endif // BLE_FEATURE_PRIVACY
#if BLE_ROLE_BROADCASTER
_advertising_timeout.detach();
#endif
#if BLE_ROLE_OBSERVER #if BLE_ROLE_OBSERVER
_scan_timeout.detach(); _scan_timeout.detach();
#endif #endif
#if BLE_ROLE_BROADCASTER
_advertising_timeout.detach();
#if BLE_FEATURE_EXTENDED_ADVERTISING #if BLE_FEATURE_EXTENDED_ADVERTISING
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
/* stop all advertising sets */ /* stop all advertising sets */
@ -1120,6 +1127,7 @@ ble_error_t Gap::reset()
_active_periodic_sets.clear(); _active_periodic_sets.clear();
#endif #endif
if (_active_sets.get(LEGACY_ADVERTISING_HANDLE)) { if (_active_sets.get(LEGACY_ADVERTISING_HANDLE)) {
#if BLE_FEATURE_EXTENDED_ADVERTISING
_pal_gap.extended_advertising_enable( _pal_gap.extended_advertising_enable(
/* enable */ false, /* enable */ false,
/* number of advertising sets */ 1, /* number of advertising sets */ 1,
@ -1127,6 +1135,9 @@ ble_error_t Gap::reset()
nullptr, nullptr,
nullptr nullptr
); );
#else
_pal_gap.advertising_enable(false);
#endif
} }
_active_sets.clear(); _active_sets.clear();
_pending_sets.clear(); _pending_sets.clear();
@ -1135,11 +1146,12 @@ ble_error_t Gap::reset()
_connectable_payload_size_exceeded.clear(); _connectable_payload_size_exceeded.clear();
_set_is_connectable.clear(); _set_is_connectable.clear();
#if BLE_FEATURE_EXTENDED_ADVERTISING
/* clear advertising set data on the controller */ /* clear advertising set data on the controller */
_pal_gap.clear_advertising_sets(); _pal_gap.clear_advertising_sets();
#if BLE_FEATURE_EXTENDED_ADVERTISING
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING #endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // #BLE_ROLE_BROADCASTER
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
@ -2854,6 +2866,7 @@ void Gap::on_legacy_advertising_stopped()
} }
} }
#if BLE_FEATURE_EXTENDED_ADVERTISING
void Gap::on_advertising_set_started(const mbed::Span<const uint8_t>& handles) void Gap::on_advertising_set_started(const mbed::Span<const uint8_t>& handles)
{ {
for (const auto &handle : handles) { for (const auto &handle : handles) {
@ -2919,6 +2932,7 @@ void Gap::on_scan_request_received(
) )
); );
} }
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER #endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_CONNECTABLE
@ -2985,6 +2999,7 @@ ble_error_t Gap::setScanParameters(const ScanParameters &params)
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }
#if BLE_FEATURE_EXTENDED_ADVERTISING
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
bool active_scanning[] = { bool active_scanning[] = {
params.get1mPhyConfiguration().isActiveScanningSet(), params.get1mPhyConfiguration().isActiveScanningSet(),
@ -3009,7 +3024,9 @@ ble_error_t Gap::setScanParameters(const ScanParameters &params)
scan_interval, scan_interval,
scan_window scan_window
); );
} else { } else
#endif
{
if (params.getPhys().get_coded()) { if (params.getPhys().get_coded()) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }

View File

@ -702,11 +702,13 @@ private:
) override; ) override;
#endif // BLE_FEATURE_PHY_MANAGEMENT #endif // BLE_FEATURE_PHY_MANAGEMENT
#if BLE_FEATURE_CONNECTABLE
void on_data_length_change( void on_data_length_change(
connection_handle_t connection_handle, connection_handle_t connection_handle,
uint16_t tx_size, uint16_t tx_size,
uint16_t rx_size uint16_t rx_size
) override; ) override;
#endif
#if BLE_FEATURE_PHY_MANAGEMENT #if BLE_FEATURE_PHY_MANAGEMENT
void on_phy_update_complete( void on_phy_update_complete(
@ -766,6 +768,7 @@ private:
void on_legacy_advertising_stopped() override; void on_legacy_advertising_stopped() override;
#if BLE_FEATURE_EXTENDED_ADVERTISING
void on_advertising_set_started(const mbed::Span<const uint8_t>& handles) override; void on_advertising_set_started(const mbed::Span<const uint8_t>& handles) override;
void on_advertising_set_terminated( void on_advertising_set_terminated(
@ -780,6 +783,7 @@ private:
connection_peer_address_type_t scanner_address_type, connection_peer_address_type_t scanner_address_type,
const ble::address_t &address const ble::address_t &address
) override; ) override;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER #endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_CONNECTABLE

View File

@ -43,6 +43,7 @@ public:
) = 0; ) = 0;
#endif // BLE_FEATURE_PHY_MANAGEMENT #endif // BLE_FEATURE_PHY_MANAGEMENT
#if BLE_FEATURE_CONNECTABLE
/** /**
* @copydoc PalGap::EventHandler::onDataLengthChange * @copydoc PalGap::EventHandler::onDataLengthChange
*/ */
@ -51,6 +52,7 @@ public:
uint16_t tx_size, uint16_t tx_size,
uint16_t rx_size uint16_t rx_size
) = 0; ) = 0;
#endif
#if BLE_FEATURE_PHY_MANAGEMENT #if BLE_FEATURE_PHY_MANAGEMENT
/** /**
@ -183,6 +185,7 @@ public:
*/ */
virtual void on_legacy_advertising_stopped() = 0; virtual void on_legacy_advertising_stopped() = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Called when extended advertising has been started. * Called when extended advertising has been started.
*/ */
@ -213,6 +216,7 @@ public:
connection_peer_address_type_t scanner_address_type, connection_peer_address_type_t scanner_address_type,
const address_t &address const address_t &address
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER #endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_CONNECTABLE
@ -302,6 +306,8 @@ public:
*/ */
virtual ble_error_t set_random_address(const address_t &address) = 0; virtual ble_error_t set_random_address(const address_t &address) = 0;
#if BLE_ROLE_BROADCASTER
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Set the random device address used by an advertising set. * Set the random device address used by an advertising set.
* *
@ -326,6 +332,7 @@ public:
advertising_handle_t advertising_handle, advertising_handle_t advertising_handle,
const address_t &address const address_t &address
) = 0; ) = 0;
#endif
/** /**
* Set the advertising parameters which will be used during the advertising * Set the advertising parameters which will be used during the advertising
@ -474,6 +481,7 @@ public:
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING #endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Configure periodic advertising parameters of an advertising set. * Configure periodic advertising parameters of an advertising set.
* *
@ -506,6 +514,7 @@ public:
periodic_advertising_interval_t periodic_advertising_max, periodic_advertising_interval_t periodic_advertising_max,
bool advertise_power bool advertise_power
) = 0; ) = 0;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Set the data sends in advertising packet. If the advertising is * Set the data sends in advertising packet. If the advertising is
@ -529,6 +538,7 @@ public:
const advertising_data_t &advertising_data const advertising_data_t &advertising_data
) = 0; ) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Set data in advertising PDUs. * Set data in advertising PDUs.
* *
@ -567,7 +577,9 @@ public:
uint8_t advertising_data_size, uint8_t advertising_data_size,
const uint8_t *advertising_data const uint8_t *advertising_data
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Set the data used in periodic advertising PDUs. * Set the data used in periodic advertising PDUs.
* *
@ -599,6 +611,7 @@ public:
uint8_t advertising_data_size, uint8_t advertising_data_size,
const uint8_t *advertising_data const uint8_t *advertising_data
) = 0; ) = 0;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Set the data sends in scan response packets. If the advertising is * Set the data sends in scan response packets. If the advertising is
@ -622,6 +635,7 @@ public:
const advertising_data_t &scan_response_data const advertising_data_t &scan_response_data
) = 0; ) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Set the data sends in extended scan response packets. If the advertising * Set the data sends in extended scan response packets. If the advertising
* is currently enabled, the data shall be used when a new extended scan * is currently enabled, the data shall be used when a new extended scan
@ -654,6 +668,7 @@ public:
uint8_t scan_response_data_size, uint8_t scan_response_data_size,
const uint8_t *scan_response_data const uint8_t *scan_response_data
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Start or stop advertising. * Start or stop advertising.
@ -697,6 +712,7 @@ public:
*/ */
virtual ble_error_t advertising_enable(bool enable) = 0; virtual ble_error_t advertising_enable(bool enable) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Start of stop advertising of extended advertising sets. * Start of stop advertising of extended advertising sets.
* *
@ -739,7 +755,9 @@ public:
const uint16_t *durations, const uint16_t *durations,
const uint8_t *max_extended_advertising_events const uint8_t *max_extended_advertising_events
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Enable or disable periodic advertising of an advertising set. * Enable or disable periodic advertising of an advertising set.
* *
@ -759,6 +777,7 @@ public:
bool enable, bool enable,
advertising_handle_t advertising_handle advertising_handle_t advertising_handle
) = 0; ) = 0;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Query the maximum data length the controller supports in an advertising * Query the maximum data length the controller supports in an advertising
@ -801,6 +820,7 @@ public:
*/ */
virtual uint8_t get_max_number_of_advertising_sets() = 0; virtual uint8_t get_max_number_of_advertising_sets() = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Remove an advertising set from the controller. * Remove an advertising set from the controller.
* *
@ -835,8 +855,10 @@ public:
* command. * command.
*/ */
virtual ble_error_t clear_advertising_sets() = 0; virtual ble_error_t clear_advertising_sets() = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#endif // BLE_ROLE_BROADCASTER
#if BLE_ROLE_OBSERVER
/** /**
* Set the parameter of the scan process. * Set the parameter of the scan process.
* *
@ -872,6 +894,7 @@ public:
scanning_filter_policy_t filter_policy scanning_filter_policy_t filter_policy
) = 0; ) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Set extended scan parameters to be used on advertising channels. * Set extended scan parameters to be used on advertising channels.
* *
@ -908,6 +931,7 @@ public:
const uint16_t *scan_interval, const uint16_t *scan_interval,
const uint16_t *scan_window const uint16_t *scan_window
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Start/stop scanning process. * Start/stop scanning process.
@ -935,6 +959,7 @@ public:
bool filter_duplicates bool filter_duplicates
) = 0; ) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Enable or disable extended scanning. * Enable or disable extended scanning.
* *
@ -962,7 +987,9 @@ public:
uint16_t duration, uint16_t duration,
uint16_t period uint16_t period
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
#if BLE_FEATURE_PERIODIC_ADVERTISING
/** /**
* Synchronize an observer with a periodic advertising broadcaster. * Synchronize an observer with a periodic advertising broadcaster.
* *
@ -1107,7 +1134,10 @@ public:
* @note We (wrongfully) assume that value doesn't change over time. * @note We (wrongfully) assume that value doesn't change over time.
*/ */
virtual uint8_t read_periodic_advertiser_list_size() = 0; virtual uint8_t read_periodic_advertiser_list_size() = 0;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
#endif // BLE_ROLE_OBSERVER
#if BLE_ROLE_CENTRAL
/** /**
* Create a new le connection to a connectable advertiser. * Create a new le connection to a connectable advertiser.
* *
@ -1194,6 +1224,7 @@ public:
uint16_t maximum_connection_event_length uint16_t maximum_connection_event_length
) = 0; ) = 0;
#if BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Create a new le connection to a connectable advertiser. * Create a new le connection to a connectable advertiser.
* *
@ -1286,6 +1317,7 @@ public:
const uint16_t *minimum_connection_event_lengths, const uint16_t *minimum_connection_event_lengths,
const uint16_t *maximum_connection_event_lengths const uint16_t *maximum_connection_event_lengths
) = 0; ) = 0;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
/** /**
* Cancel the ongoing connection creation process. * Cancel the ongoing connection creation process.
@ -1297,7 +1329,9 @@ public:
* command. * command.
*/ */
virtual ble_error_t cancel_connection_creation() = 0; virtual ble_error_t cancel_connection_creation() = 0;
#endif // BLE_ROLE_CENTRAL
#if BLE_FEATURE_WHITELIST
/** /**
* Return the number of total whitelist entries that can be stored in the * Return the number of total whitelist entries that can be stored in the
* le subsystem. * le subsystem.
@ -1368,7 +1402,9 @@ public:
whitelist_address_type_t address_type, whitelist_address_type_t address_type,
address_t address address_t address
) = 0; ) = 0;
#endif // BLE_FEATURE_WHITELIST
#if BLE_FEATURE_CONNECTABLE
/** /**
* Start a connection update procedure. * Start a connection update procedure.
* *
@ -1543,6 +1579,7 @@ public:
connection_handle_t connection, connection_handle_t connection,
local_disconnection_reason_t disconnection_reason local_disconnection_reason_t disconnection_reason
) = 0; ) = 0;
#endif
/** /**
* Checked support for a feature in the link controller. * Checked support for a feature in the link controller.
@ -1554,6 +1591,7 @@ public:
controller_supported_features_t feature controller_supported_features_t feature
) = 0; ) = 0;
#if BLE_FEATURE_PHY_MANAGEMENT
/** /**
* @see PalGap::readPhy * @see PalGap::readPhy
*/ */
@ -1576,6 +1614,7 @@ public:
const phy_set_t &rx_phys, const phy_set_t &rx_phys,
coded_symbol_per_bit_t coded_symbol coded_symbol_per_bit_t coded_symbol
) = 0; ) = 0;
#endif // BLE_FEATURE_PHY_MANAGEMENT
/** /**
* Register a callback which will handle PalGap events. * Register a callback which will handle PalGap events.