/* mbed Microcontroller Library * Copyright (c) 2018 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ble/gap/Gap.h" namespace ble { namespace interface { template bool Gap::isFeatureSupported(controller_supported_features_t feature) { #if !BLE_FEATURE_PHY_MANAGEMENT if (feature == ble::controller_supported_features_t::LE_CODED_PHY || feature == ble::controller_supported_features_t::LE_2M_PHY ) { return false; } #endif #if !BLE_FEATURE_EXTENDED_ADVERTISING if (feature == ble::controller_supported_features_t::LE_EXTENDED_ADVERTISING) { return false; } #endif #if !BLE_FEATURE_PERIODIC_ADVERTISING if (feature == ble::controller_supported_features_t::LE_PERIODIC_ADVERTISING) { return false; } #endif #if !BLE_FEATURE_PRIVACY if (feature == ble::controller_supported_features_t::LL_PRIVACY) { return false; } #endif return impl()->isFeatureSupported_(feature); } #if BLE_ROLE_BROADCASTER template uint8_t Gap::getMaxAdvertisingSetNumber() { return impl()->getMaxAdvertisingSetNumber_(); } template uint16_t Gap::getMaxAdvertisingDataLength() { return impl()->getMaxAdvertisingDataLength_(); } template uint16_t Gap::getMaxConnectableAdvertisingDataLength() { return impl()->getMaxConnectableAdvertisingDataLength_(); } template uint16_t Gap::getMaxActiveSetAdvertisingDataLength() { return impl()->getMaxActiveSetAdvertisingDataLength_(); } #if BLE_FEATURE_EXTENDED_ADVERTISING template ble_error_t Gap::createAdvertisingSet( advertising_handle_t *handle, const AdvertisingParameters ¶meters ) { return impl()->createAdvertisingSet_(handle, parameters); } template ble_error_t Gap::destroyAdvertisingSet(advertising_handle_t handle) { return impl()->destroyAdvertisingSet_(handle); } #endif // BLE_FEATURE_EXTENDED_ADVERTISING template ble_error_t Gap::setAdvertisingParameters( advertising_handle_t handle, const AdvertisingParameters ¶ms ) { return impl()->setAdvertisingParameters_(handle, params); } template ble_error_t Gap::setAdvertisingPayload( advertising_handle_t handle, mbed::Span payload ) { return impl()->setAdvertisingPayload_(handle, payload); } template ble_error_t Gap::setAdvertisingScanResponse( advertising_handle_t handle, mbed::Span response ) { return impl()->setAdvertisingScanResponse_(handle, response); } template ble_error_t Gap::startAdvertising( advertising_handle_t handle, adv_duration_t maxDuration, uint8_t maxEvents ) { return impl()->startAdvertising_(handle, maxDuration, maxEvents); } template ble_error_t Gap::stopAdvertising(advertising_handle_t handle) { return impl()->stopAdvertising_(handle); } template bool Gap::isAdvertisingActive(advertising_handle_t handle) { return impl()->isAdvertisingActive_(handle); } #endif // BLE_ROLE_BROADCASTER #if BLE_FEATURE_PERIODIC_ADVERTISING template ble_error_t Gap::setPeriodicAdvertisingParameters( advertising_handle_t handle, periodic_interval_t periodicAdvertisingIntervalMin, periodic_interval_t periodicAdvertisingIntervalMax, bool advertiseTxPower ) { return impl()->setPeriodicAdvertisingParameters_( handle, periodicAdvertisingIntervalMin, periodicAdvertisingIntervalMax, advertiseTxPower ); } template ble_error_t Gap::setPeriodicAdvertisingPayload( advertising_handle_t handle, mbed::Span payload ) { return impl()->setPeriodicAdvertisingPayload_(handle, payload); } template ble_error_t Gap::startPeriodicAdvertising(advertising_handle_t handle) { return impl()->startPeriodicAdvertising_(handle); } template ble_error_t Gap::stopPeriodicAdvertising(advertising_handle_t handle) { return impl()->stopPeriodicAdvertising_(handle); } template bool Gap::isPeriodicAdvertisingActive(advertising_handle_t handle) { return impl()->isPeriodicAdvertisingActive_(handle); } #endif // BLE_FEATURE_PERIODIC_ADVERTISING #if BLE_ROLE_OBSERVER template ble_error_t Gap::setScanParameters(const ScanParameters ¶ms) { return impl()->setScanParameters_(params); } template ble_error_t Gap::startScan( scan_duration_t duration, duplicates_filter_t filtering, scan_period_t period ) { return impl()->startScan_(duration, filtering, period); } template ble_error_t Gap::stopScan() { return impl()->stopScan_(); } #endif // BLE_ROLE_OBSERVER #if BLE_FEATURE_PERIODIC_ADVERTISING template ble_error_t Gap::createSync( peer_address_type_t peerAddressType, const address_t &peerAddress, uint8_t sid, slave_latency_t maxPacketSkip, sync_timeout_t timeout ) { return impl()->createSync_( peerAddressType, peerAddress, sid, maxPacketSkip, timeout ); } template ble_error_t Gap::createSync( slave_latency_t maxPacketSkip, sync_timeout_t timeout ) { return impl()->createSync_(maxPacketSkip, timeout); } template ble_error_t Gap::cancelCreateSync() { return impl()->cancelCreateSync_(); } template ble_error_t Gap::terminateSync(periodic_sync_handle_t handle) { return impl()->terminateSync_(handle); } template ble_error_t Gap::addDeviceToPeriodicAdvertiserList( peer_address_type_t peerAddressType, const address_t &peerAddress, advertising_sid_t sid ) { return impl()->addDeviceToPeriodicAdvertiserList_( peerAddressType, peerAddress, sid ); } template ble_error_t Gap::removeDeviceFromPeriodicAdvertiserList( peer_address_type_t peerAddressType, const address_t &peerAddress, advertising_sid_t sid ) { return impl()->removeDeviceFromPeriodicAdvertiserList_( peerAddressType, peerAddress, sid ); } template ble_error_t Gap::clearPeriodicAdvertiserList() { return impl()->clearPeriodicAdvertiserList_(); } template uint8_t Gap::getMaxPeriodicAdvertiserListSize() { return impl()->getMaxPeriodicAdvertiserListSize_(); } #endif // BLE_FEATURE_PERIODIC_ADVERTISING #if BLE_ROLE_CENTRAL template ble_error_t Gap::connect( peer_address_type_t peerAddressType, const address_t &peerAddress, const ConnectionParameters &connectionParams ) { return impl()->connect_( peerAddressType, peerAddress, connectionParams ); } template ble_error_t Gap::cancelConnect() { return impl()->cancelConnect_(); } #endif #if BLE_FEATURE_CONNECTABLE template ble_error_t Gap::updateConnectionParameters( connection_handle_t connectionHandle, conn_interval_t minConnectionInterval, conn_interval_t maxConnectionInterval, slave_latency_t slaveLatency, supervision_timeout_t supervision_timeout, conn_event_length_t minConnectionEventLength, conn_event_length_t maxConnectionEventLength ) { return impl()->updateConnectionParameters_( connectionHandle, minConnectionInterval, maxConnectionInterval, slaveLatency, supervision_timeout, minConnectionEventLength, maxConnectionEventLength ); } template ble_error_t Gap::manageConnectionParametersUpdateRequest( bool userManageConnectionUpdateRequest ) { return impl()->manageConnectionParametersUpdateRequest_(userManageConnectionUpdateRequest); } template ble_error_t Gap::acceptConnectionParametersUpdate( connection_handle_t connectionHandle, conn_interval_t minConnectionInterval, conn_interval_t maxConnectionInterval, slave_latency_t slaveLatency, supervision_timeout_t supervision_timeout, conn_event_length_t minConnectionEventLength, conn_event_length_t maxConnectionEventLength ) { return impl()->acceptConnectionParametersUpdate_( connectionHandle, minConnectionInterval, maxConnectionInterval, slaveLatency, supervision_timeout, minConnectionEventLength, maxConnectionEventLength ); } template ble_error_t Gap::rejectConnectionParametersUpdate( connection_handle_t connectionHandle ) { return impl()->rejectConnectionParametersUpdate_(connectionHandle); } template ble_error_t Gap::disconnect( connection_handle_t connectionHandle, local_disconnection_reason_t reason ) { return impl()->disconnect_(connectionHandle, reason); } #endif // BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_PHY_MANAGEMENT template ble_error_t Gap::readPhy(connection_handle_t connection) { return impl()->readPhy_(connection); } template ble_error_t Gap::setPreferredPhys( const phy_set_t *txPhys, const phy_set_t *rxPhys ) { return impl()->setPreferredPhys_(txPhys, rxPhys); } template ble_error_t Gap::setPhy( connection_handle_t connection, const phy_set_t *txPhys, const phy_set_t *rxPhys, coded_symbol_per_bit_t codedSymbol ) { return impl()->setPhy_( connection, txPhys, rxPhys, codedSymbol ); } #endif // BLE_FEATURE_PHY_MANAGEMENT template void Gap::useVersionOneAPI() const { return impl()->useVersionOneAPI_(); } template void Gap::useVersionTwoAPI() const { return impl()->useVersionTwoAPI_(); } template Gap::Gap() : _eventHandler(NULL) { } /* -------------------- Future deprecation ------------------------- */ template const peripheral_privacy_configuration_t Gap::default_peripheral_privacy_configuration = { /* use_non_resolvable_random_address */ false, /* resolution_strategy */ peripheral_privacy_configuration_t::PERFORM_PAIRING_PROCEDURE }; template const central_privay_configuration_t Gap::default_central_privacy_configuration = { /* use_non_resolvable_random_address */ false, /* resolution_strategy */ central_privay_configuration_t::RESOLVE_AND_FORWARD }; #if BLE_FEATURE_PRIVACY template ble_error_t Gap::enablePrivacy(bool enable) { return impl()->enablePrivacy_(enable); } #if BLE_ROLE_BROADCASTER template ble_error_t Gap::setPeripheralPrivacyConfiguration( const peripheral_privacy_configuration_t *configuration ) { return impl()->setPeripheralPrivacyConfiguration_(configuration); } template ble_error_t Gap::getPeripheralPrivacyConfiguration( peripheral_privacy_configuration_t *configuration ) { return impl()->getPeripheralPrivacyConfiguration_(configuration); } #endif // BLE_ROLE_BROADCASTER #if BLE_ROLE_OBSERVER template ble_error_t Gap::setCentralPrivacyConfiguration( const central_privay_configuration_t *configuration ) { return impl()->setCentralPrivacyConfiguration_(configuration); } template ble_error_t Gap::getCentralPrivacyConfiguration( central_privay_configuration_t *configuration ) { return impl()->getCentralPrivacyConfiguration_(configuration); } #endif // BLE_ROLE_OBSERVER #endif // BLE_FEATURE_PRIVACY // ----------------------------------------------------------------------------- /* ------------------------- Default implementations ------------------------ */ // ----------------------------------------------------------------------------- template bool Gap::isFeatureSupported_(controller_supported_features_t feature) { return false; } template uint8_t Gap::getMaxAdvertisingSetNumber_() { return 1; } template uint16_t Gap::getMaxAdvertisingDataLength_() { return LEGACY_ADVERTISING_MAX_SIZE; } template uint16_t Gap::getMaxConnectableAdvertisingDataLength_() { return LEGACY_ADVERTISING_MAX_SIZE; } template uint16_t Gap::getMaxActiveSetAdvertisingDataLength_() { return LEGACY_ADVERTISING_MAX_SIZE; } template ble_error_t Gap::createAdvertisingSet_( advertising_handle_t *handle, const AdvertisingParameters ¶meters ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::destroyAdvertisingSet_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setAdvertisingParameters_( advertising_handle_t handle, const AdvertisingParameters ¶ms ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setAdvertisingPayload_( advertising_handle_t handle, mbed::Span payload ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setAdvertisingScanResponse_( advertising_handle_t handle, mbed::Span response ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::startAdvertising_( advertising_handle_t handle, adv_duration_t maxDuration, uint8_t maxEvents ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::stopAdvertising_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template bool Gap::isAdvertisingActive_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setPeriodicAdvertisingParameters_( advertising_handle_t handle, periodic_interval_t periodicAdvertisingIntervalMin, periodic_interval_t periodicAdvertisingIntervalMax, bool advertiseTxPower ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setPeriodicAdvertisingPayload_( advertising_handle_t handle, mbed::Span payload ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::startPeriodicAdvertising_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::stopPeriodicAdvertising_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template bool Gap::isPeriodicAdvertisingActive_(advertising_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setScanParameters_(const ScanParameters ¶ms) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::startScan_( scan_duration_t duration, duplicates_filter_t filtering, scan_period_t period ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::stopScan_() { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::createSync_( peer_address_type_t peerAddressType, const address_t &peerAddress, uint8_t sid, slave_latency_t maxPacketSkip, sync_timeout_t timeout ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::createSync_( slave_latency_t maxPacketSkip, sync_timeout_t timeout ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::cancelCreateSync_() { return impl()->cancelCreateSync_(); } template ble_error_t Gap::terminateSync_(periodic_sync_handle_t handle) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::addDeviceToPeriodicAdvertiserList_( peer_address_type_t peerAddressType, const address_t &peerAddress, advertising_sid_t sid ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::removeDeviceFromPeriodicAdvertiserList_( peer_address_type_t peerAddressType, const address_t &peerAddress, advertising_sid_t sid ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::clearPeriodicAdvertiserList_() { return BLE_ERROR_NOT_IMPLEMENTED; } template uint8_t Gap::getMaxPeriodicAdvertiserListSize_() { return 0; } template ble_error_t Gap::connect_( peer_address_type_t peerAddressType, const address_t &peerAddress, const ConnectionParameters &connectionParams ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::cancelConnect_() { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::updateConnectionParameters_( connection_handle_t connectionHandle, conn_interval_t minConnectionInterval, conn_interval_t maxConnectionInterval, slave_latency_t slaveLatency, supervision_timeout_t supervision_timeout, conn_event_length_t minConnectionEventLength, conn_event_length_t maxConnectionEventLength ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::manageConnectionParametersUpdateRequest_( bool userManageConnectionUpdateRequest ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::acceptConnectionParametersUpdate_( connection_handle_t connectionHandle, conn_interval_t minConnectionInterval, conn_interval_t maxConnectionInterval, slave_latency_t slaveLatency, supervision_timeout_t supervision_timeout, conn_event_length_t minConnectionEventLength, conn_event_length_t maxConnectionEventLength ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::rejectConnectionParametersUpdate_( connection_handle_t connectionHandle ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::disconnect_( connection_handle_t connectionHandle, local_disconnection_reason_t reason ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::readPhy_(connection_handle_t connection) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setPreferredPhys_( const phy_set_t *txPhys, const phy_set_t *rxPhys ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setPhy_( connection_handle_t connection, const phy_set_t *txPhys, const phy_set_t *rxPhys, coded_symbol_per_bit_t codedSymbol ) { return BLE_ERROR_NOT_IMPLEMENTED; } template void Gap::useVersionOneAPI_() const { } template void Gap::useVersionTwoAPI_() const { } template ble_error_t Gap::enablePrivacy_(bool enable) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setPeripheralPrivacyConfiguration_( const peripheral_privacy_configuration_t *configuration ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::getPeripheralPrivacyConfiguration_( peripheral_privacy_configuration_t *configuration ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::setCentralPrivacyConfiguration_( const central_privay_configuration_t *configuration ) { return BLE_ERROR_NOT_IMPLEMENTED; } template ble_error_t Gap::getCentralPrivacyConfiguration_( central_privay_configuration_t *configuration ) { return BLE_ERROR_NOT_IMPLEMENTED; } } // namespace interface } // namespace ble