Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GenericGap.h Source File

GenericGap.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017-2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef MBED_BLE_GENERIC_GAP
00018 #define MBED_BLE_GENERIC_GAP
00019 
00020 #include <algorithm>
00021 
00022 #include "ble/BLEProtocol.h"
00023 #include "ble/Gap.h"
00024 #include "ble/pal/PalGap.h"
00025 #include "ble/pal/GapEvents.h"
00026 #include "ble/pal/GapTypes.h"
00027 #include "ble/BLETypes.h"
00028 #include "ble/pal/GenericAccessService.h"
00029 #include "ble/pal/EventQueue.h"
00030 #include "ble/pal/ConnectionEventMonitor.h"
00031 #include "ble/pal/Deprecated.h"
00032 
00033 #include "drivers/LowPowerTimeout.h"
00034 #include "drivers/LowPowerTicker.h"
00035 #include "platform/mbed_error.h"
00036 
00037 namespace ble {
00038 namespace generic {
00039 /**
00040  * Generic implementation of the Gap class.
00041  * It requires a pal::Gap and a pal::GenericAccessService injected at
00042  * construction site.
00043  *
00044  * @attention: Not part of the public interface of BLE API.
00045  */
00046 template<
00047     template<class> class TPalGap,
00048     class PalSecurityManager,
00049     class ConnectionEventMonitorEventHandler
00050 >
00051 class GenericGap :
00052     public interface::LegacyGap<
00053         GenericGap<TPalGap, PalSecurityManager, ConnectionEventMonitorEventHandler>
00054     >,
00055     public pal::ConnectionEventMonitor <
00056         ConnectionEventMonitorEventHandler
00057     >,
00058     public pal::GapEventHandler<
00059         GenericGap<TPalGap, PalSecurityManager, ConnectionEventMonitorEventHandler>
00060     >
00061 {
00062     // Typedef of base and companion classes .
00063     typedef ::ble::interface::LegacyGap<GenericGap> LegacyGap;
00064     typedef ::ble::interface::Gap<GenericGap> Gap;
00065     typedef pal::ConnectionEventMonitor<ConnectionEventMonitorEventHandler>  ConnectionEventMonitor ;
00066     typedef TPalGap<GenericGap> PalGap;
00067     typedef pal::GapEventHandler<GenericGap> PalGapEventHandler;
00068 
00069     // Friendship with base classes
00070     friend LegacyGap;
00071     friend Gap;
00072     friend ConnectionEventMonitor ;
00073     friend pal::GapEventHandler<GenericGap>;
00074     friend PalGap;
00075 
00076     // Imports from LegacyGap
00077     using LegacyGap::_eventHandler;
00078     using LegacyGap::default_peripheral_privacy_configuration;
00079     using LegacyGap::default_central_privacy_configuration;
00080     using LegacyGap::state;
00081 
00082     typedef typename LegacyGap::Address_t Address_t;
00083     typedef typename LegacyGap::PeerAddressType_t PeerAddressType_t;
00084     typedef typename LegacyGap::ConnectionParams_t ConnectionParams_t;
00085     typedef typename LegacyGap::Handle_t Handle_t;
00086     typedef typename LegacyGap::CodedSymbolPerBit_t CodedSymbolPerBit_t;
00087     typedef typename LegacyGap::Whitelist_t Whitelist_t;
00088     typedef typename LegacyGap::DisconnectionReason_t DisconnectionReason_t;
00089     typedef typename LegacyGap::AdvertisingPolicyMode_t AdvertisingPolicyMode_t;
00090     typedef typename LegacyGap::ScanningPolicyMode_t ScanningPolicyMode_t;
00091     typedef typename LegacyGap::InitiatorPolicyMode_t InitiatorPolicyMode_t;
00092     typedef typename LegacyGap::PeripheralPrivacyConfiguration_t PeripheralPrivacyConfiguration_t;
00093     typedef typename LegacyGap::CentralPrivacyConfiguration_t CentralPrivacyConfiguration_t;
00094     typedef typename LegacyGap::Role_t Role_t;
00095 
00096     // Imports from Gap
00097 #if BLE_ROLE_BROADCASTER
00098     using ble::interface::Gap<GenericGap>::getMaxAdvertisingSetNumber;
00099     using ble::interface::Gap<GenericGap>::getMaxAdvertisingDataLength;
00100 #endif // BLE_ROLE_BROADCASTER
00101     using ble::interface::Gap<GenericGap>::isFeatureSupported;
00102     using ble::interface::Gap<GenericGap>::useVersionOneAPI;
00103     using ble::interface::Gap<GenericGap>::useVersionTwoAPI;
00104 
00105     // Imports from PalGap EventHandler
00106     using PalGapEventHandler::on_scan_timeout;
00107 
00108     // Imports from ConnectionEventMonitor
00109     using ConnectionEventMonitor::_connection_event_handler;
00110     using ConnectionEventMonitor::set_connection_event_handler;
00111 
00112 public:
00113     /* TODO: move to config */
00114     static const uint8_t MAX_ADVERTISING_SETS = 15;
00115 
00116     /**
00117      * Construct a GenericGap.
00118      *
00119      * @param event_queue Event queue used to serialise execution.
00120      *
00121      * @param pal_gap GAP Platform abstraction instance containing the base GAP
00122      * primitives.
00123      *
00124      * @param generic_access_service Platform abstraction instance managing
00125      * the GATT generic access service.
00126      *
00127      * @param pal_sm Security Manager Platform abstraction instance containing the base
00128      * Security Manager primitives.
00129      */
00130     GenericGap(
00131         pal::EventQueue &event_queue,
00132         PalGap &pal_gap,
00133         pal::GenericAccessService &generic_access_service,
00134         PalSecurityManager &pal_sm
00135     );
00136 
00137     /**
00138      * @see Gap::~Gap
00139      */
00140     ~GenericGap ();
00141 
00142     /** @copydoc Gap::IsFeatureSupported
00143      */
00144     bool isFeatureSupported_ (
00145         controller_supported_features_t feature
00146     );
00147 
00148     /** @copydoc Gap::getMaxAdvertisingSetNumber
00149      */
00150     uint8_t getMaxAdvertisingSetNumber_ ();
00151 
00152     /** @copydoc Gap::getMaxAdvertisingDataLength
00153      */
00154     uint16_t getMaxAdvertisingDataLength_ ();
00155 
00156     /** @copydoc Gap::getMaxConnectableAdvertisingDataLength
00157      */
00158     uint16_t getMaxConnectableAdvertisingDataLength_ ();
00159 
00160     /** @copydoc Gap::getMaxActiveSetAdvertisingDataLength
00161      */
00162     uint16_t getMaxActiveSetAdvertisingDataLength_ ();
00163 
00164     /** @copydoc Gap::createAdvertisingSet
00165      */
00166     ble_error_t createAdvertisingSet_ (
00167         advertising_handle_t *handle,
00168         const AdvertisingParameters &parameters
00169     );
00170 
00171     /** @copydoc Gap::destroyAdvertisingSet
00172      */
00173     ble_error_t destroyAdvertisingSet_ (advertising_handle_t handle);
00174 
00175     /** @copydoc Gap::setAdvertisingParams
00176      */
00177     ble_error_t setAdvertisingParameters_ (
00178         advertising_handle_t handle,
00179         const AdvertisingParameters &params
00180     );
00181 
00182     /** @copydoc Gap::setAdvertisingPayload
00183      */
00184     ble_error_t setAdvertisingPayload_ (
00185         advertising_handle_t handle,
00186         Span<const uint8_t> payload
00187     );
00188 
00189     /** @copydoc Gap::setAdvertisingScanResponse
00190      */
00191     ble_error_t setAdvertisingScanResponse_ (
00192         advertising_handle_t handle,
00193         Span<const uint8_t> response
00194     );
00195 
00196     /** @copydoc Gap::startAdvertising
00197      */
00198     ble_error_t startAdvertising_ (
00199         advertising_handle_t handle,
00200         adv_duration_t maxDuration,
00201         uint8_t maxEvents
00202     );
00203 
00204     /** @copydoc Gap::stopAdvertising
00205      */
00206     ble_error_t stopAdvertising_ (advertising_handle_t handle);
00207 
00208     /** @copydoc Gap::isAdvertisingActive
00209      */
00210     bool isAdvertisingActive_ (advertising_handle_t handle);
00211 
00212     /** @copydoc Gap::setPeriodicAdvertisingParameters
00213      */
00214     ble_error_t setPeriodicAdvertisingParameters_ (
00215         advertising_handle_t handle,
00216         periodic_interval_t periodicAdvertisingIntervalMin,
00217         periodic_interval_t periodicAdvertisingIntervalMax,
00218         bool advertiseTxPower
00219     );
00220 
00221     /** @copydoc Gap::setPeriodicAdvertisingPayload
00222      */
00223     ble_error_t setPeriodicAdvertisingPayload_ (
00224         advertising_handle_t handle,
00225         Span<const uint8_t> payload
00226     );
00227 
00228     /** @copydoc Gap::startPeriodicAdvertising
00229      */
00230     ble_error_t startPeriodicAdvertising_ (advertising_handle_t handle);
00231 
00232     /** @copydoc Gap::stopPeriodicAdvertising
00233      */
00234     ble_error_t stopPeriodicAdvertising_ (advertising_handle_t handle);
00235 
00236     /** @copydoc Gap::isPeriodicAdvertisingActive
00237      */
00238     bool isPeriodicAdvertisingActive_ (advertising_handle_t handle);
00239 
00240     /** @copydoc Gap::setScanParameters
00241      */
00242     ble_error_t setScanParameters_ (const ScanParameters &params);
00243 
00244     /** @copydoc Gap::startScan
00245      */
00246     ble_error_t startScan_ (
00247         scan_duration_t duration,
00248         duplicates_filter_t filtering,
00249         scan_period_t period
00250     );
00251 
00252     /** @copydoc Gap::createSync
00253      */
00254     ble_error_t createSync_ (
00255         peer_address_type_t peerAddressType,
00256         const ble::address_t &peerAddress,
00257         advertising_sid_t sid,
00258         slave_latency_t  maxPacketSkip,
00259         sync_timeout_t timeout
00260     );
00261 
00262     /** @copydoc Gap::createSync
00263      */
00264     ble_error_t createSync_ (
00265         slave_latency_t  maxPacketSkip,
00266         sync_timeout_t timeout
00267     );
00268 
00269     /** @copydoc Gap::cancelCreateSync
00270      */
00271     ble_error_t cancelCreateSync_ ();
00272 
00273     /** @copydoc Gap::terminateSync
00274      */
00275     ble_error_t terminateSync_ (periodic_sync_handle_t handle);
00276 
00277     /** @copydoc Gap::addDeviceToPeriodicAdvertiserList
00278      */
00279     ble_error_t addDeviceToPeriodicAdvertiserList_ (
00280         peer_address_type_t peerAddressType,
00281         const ble::address_t &peerAddress,
00282         advertising_sid_t sid
00283     );
00284 
00285     /** @copydoc Gap::removeDeviceFromPeriodicAdvertiserList
00286      */
00287     ble_error_t removeDeviceFromPeriodicAdvertiserList_ (
00288         peer_address_type_t peerAddressType,
00289         const ble::address_t &peerAddress,
00290         advertising_sid_t sid
00291     );
00292 
00293     /** @copydoc Gap::clearPeriodicAdvertiserList
00294      */
00295     ble_error_t clearPeriodicAdvertiserList_ ();
00296 
00297     /** @copydoc Gap::getMaxPeriodicAdvertiserListSize
00298      */
00299     uint8_t getMaxPeriodicAdvertiserListSize_ ();
00300 
00301     /**
00302      * @see Gap::setAddress
00303      */
00304     ble_error_t setAddress_ (
00305         BLEProtocol::AddressType_t type,
00306         const BLEProtocol::AddressBytes_t address
00307     );
00308 
00309     /**
00310      * @see Gap::getAddress
00311      */
00312     ble_error_t getAddress_ (
00313         BLEProtocol::AddressType_t *type,
00314         BLEProtocol::AddressBytes_t address
00315     );
00316 
00317     /**
00318      * @see Gap::getMinAdvertisingInterval
00319      */
00320     uint16_t getMinAdvertisingInterval_ () const;
00321 
00322     /**
00323      * @see Gap::getMinNonConnectableAdvertisingInterval
00324      */
00325     uint16_t getMinNonConnectableAdvertisingInterval_ () const;
00326 
00327     /**
00328      * @see Gap::getMaxAdvertisingInterval
00329      */
00330     uint16_t getMaxAdvertisingInterval_ () const;
00331 
00332     /**
00333      * @see Gap::stopAdvertising
00334      */
00335     ble_error_t stopAdvertising_ ();
00336 
00337     /**
00338      * @see Gap::stopScan
00339      */
00340     ble_error_t stopScan_ ();
00341 
00342     /**
00343      * @see Gap::connect
00344      */
00345     ble_error_t connect_ (
00346         const BLEProtocol::AddressBytes_t peerAddr,
00347         PeerAddressType_t peerAddrType,
00348         const ConnectionParams_t *connectionParams,
00349         const GapScanningParams *scanParams
00350     );
00351 
00352     /**
00353      * @see Gap::connect
00354      */
00355     ble_error_t connect_ (
00356         const BLEProtocol::AddressBytes_t peerAddr,
00357         BLEProtocol::AddressType_t peerAddrType,
00358         const ConnectionParams_t *connectionParams,
00359         const GapScanningParams *scanParams
00360     );
00361 
00362     /**
00363      * @see Gap::connect
00364      */
00365     ble_error_t connect_ (
00366         peer_address_type_t peerAddressType,
00367         const ble::address_t &peerAddress,
00368         const ConnectionParameters &connectionParams
00369     );
00370 
00371     /**
00372      * @see Gap::cancelConnect
00373      */
00374     ble_error_t cancelConnect_ ();
00375 
00376     ble_error_t manageConnectionParametersUpdateRequest_(
00377         bool userManageConnectionUpdateRequest
00378     );
00379 
00380     ble_error_t updateConnectionParameters_(
00381         connection_handle_t connectionHandle,
00382         conn_interval_t  minConnectionInterval,
00383         conn_interval_t  maxConnectionInterval,
00384         slave_latency_t  slaveLatency,
00385         supervision_timeout_t  supervisionTimeout,
00386         conn_event_length_t minConnectionEventLength,
00387         conn_event_length_t maxConnectionEventLength
00388     );
00389 
00390     ble_error_t acceptConnectionParametersUpdate_(
00391         connection_handle_t connectionHandle,
00392         conn_interval_t  minConnectionInterval,
00393         conn_interval_t  maxConnectionInterval,
00394         slave_latency_t  slaveLatency,
00395         supervision_timeout_t  supervisionTimeout,
00396         conn_event_length_t minConnectionEventLength,
00397         conn_event_length_t maxConnectionEventLength
00398     );
00399 
00400     ble_error_t rejectConnectionParametersUpdate_(
00401         connection_handle_t connectionHandle
00402     );
00403 
00404     /**
00405      * @see Gap::readPhy
00406      */
00407     ble_error_t readPhy_ (Handle_t connection);
00408 
00409     /**
00410     * @see Gap::setPreferredPhys
00411     */
00412     ble_error_t setPreferredPhys_ (
00413         const phy_set_t *txPhys,
00414         const phy_set_t *rxPhys
00415     );
00416 
00417     /**
00418     * @see Gap::setPhy
00419     */
00420     ble_error_t setPhy_ (
00421         Handle_t connection,
00422         const phy_set_t *txPhys,
00423         const phy_set_t *rxPhys,
00424         CodedSymbolPerBit_t codedSymbol
00425     );
00426 
00427     ble_error_t disconnect_(
00428         connection_handle_t connectionHandle,
00429         local_disconnection_reason_t reason
00430     );
00431 
00432     /**
00433      * @see Gap::disconnect
00434      */
00435     ble_error_t disconnect_(
00436         Handle_t connectionHandle,
00437         DisconnectionReason_t reason
00438     );
00439 
00440     /**
00441      * @see Gap::disconnect
00442      */
00443     ble_error_t disconnect_(DisconnectionReason_t reason);
00444 
00445     /**
00446      * @see Gap::updateConnectionParams
00447      */
00448     ble_error_t updateConnectionParams_ (
00449         Handle_t handle,
00450         const ConnectionParams_t *params
00451     );
00452 
00453     /**
00454      * @see Gap::getPreferredConnectionParams
00455      */
00456     ble_error_t getPreferredConnectionParams_ (
00457         ConnectionParams_t *params
00458     );
00459 
00460     /**
00461      * @see Gap::setPreferredConnectionParams
00462      */
00463     ble_error_t setPreferredConnectionParams_ (
00464         const ConnectionParams_t *params
00465     );
00466 
00467     /**
00468      * @see Gap::setDeviceName
00469      */
00470     ble_error_t setDeviceName_ (const uint8_t *deviceName);
00471 
00472     /**
00473      * @see Gap::getDeviceName
00474      */
00475     ble_error_t getDeviceName_ (uint8_t *deviceName, unsigned *lengthP);
00476 
00477     /**
00478      * @see Gap::setAppearance
00479      */
00480     ble_error_t setAppearance_ (GapAdvertisingData::Appearance appearance);
00481 
00482     /**
00483      * @see Gap::getAppearance
00484      */
00485     ble_error_t getAppearance_ (GapAdvertisingData::Appearance *appearanceP);
00486 
00487     /**
00488      * @see Gap::setTxPower
00489      */
00490     ble_error_t setTxPower_ (int8_t txPower);
00491 
00492     /**
00493      * @see Gap::getPermittedTxPowerValues
00494      */
00495     void getPermittedTxPowerValues_ (const int8_t **valueArrayPP, size_t *countP);
00496 
00497     /**
00498      * @see Gap::getMaxWhitelistSize
00499      */
00500     uint8_t getMaxWhitelistSize_ (void) const;
00501 
00502     /**
00503      * @see Gap::getWhitelist
00504      */
00505     ble_error_t getWhitelist_ (Whitelist_t &whitelist) const;
00506 
00507     /**
00508      * @see Gap::setWhitelist
00509      */
00510     ble_error_t setWhitelist_ (const Whitelist_t &whitelist);
00511 
00512     /**
00513      * @see Gap::setAdvertisingPolicyMode
00514      */
00515     ble_error_t setAdvertisingPolicyMode_ (AdvertisingPolicyMode_t mode);
00516 
00517     /**
00518      * @see Gap::setScanningPolicyMode
00519      */
00520     ble_error_t setScanningPolicyMode_ (ScanningPolicyMode_t mode);
00521 
00522     /**
00523      * @see Gap::setInitiatorPolicyMode
00524      */
00525     ble_error_t setInitiatorPolicyMode_ (InitiatorPolicyMode_t mode);
00526 
00527     /**
00528      * @see Gap::getAdvertisingPolicyMode
00529      */
00530     AdvertisingPolicyMode_t getAdvertisingPolicyMode_ (void) const;
00531 
00532     /**
00533      * @see Gap::getScanningPolicyMode
00534      */
00535     ScanningPolicyMode_t getScanningPolicyMode_ (void) const;
00536 
00537     /**
00538      * @see Gap::getInitiatorPolicyMode
00539      */
00540     InitiatorPolicyMode_t getInitiatorPolicyMode_ (void) const;
00541 
00542     /**
00543      * @see Gap::startRadioScan
00544      */
00545     ble_error_t startRadioScan_ (const GapScanningParams &scanningParams);
00546 
00547     /**
00548      * @see Gap::initRadioNotification
00549      */
00550     ble_error_t initRadioNotification_ (void);
00551 
00552     /**
00553      * @see Gap::enablePrivacy
00554      */
00555     ble_error_t enablePrivacy_ (bool enable);
00556 
00557     /**
00558      * @see Gap::setPeripheralPrivacyConfiguration
00559      */
00560     ble_error_t setPeripheralPrivacyConfiguration_ (
00561         const PeripheralPrivacyConfiguration_t *configuration
00562     );
00563 
00564     /**
00565      * @see Gap::getPeripheralPrivacyConfiguration
00566      */
00567     ble_error_t getPeripheralPrivacyConfiguration_ (
00568         PeripheralPrivacyConfiguration_t *configuration
00569     );
00570 
00571     /**
00572      * @see Gap::setCentralPrivacyConfiguration
00573      */
00574     ble_error_t setCentralPrivacyConfiguration_ (
00575         const CentralPrivacyConfiguration_t *configuration
00576     );
00577 
00578     /**
00579      * @see Gap::getCentralPrivacyConfiguration
00580      */
00581     ble_error_t getCentralPrivacyConfiguration_ (
00582         CentralPrivacyConfiguration_t *configuration
00583     );
00584 
00585     /**
00586      * @see Gap::setAdvertisingData
00587      */
00588     ble_error_t setAdvertisingData_ (
00589         const GapAdvertisingData &advData,
00590         const GapAdvertisingData &scanResponse
00591     );
00592 
00593     /**
00594      * @see Gap::startAdvertising
00595      */
00596     ble_error_t startAdvertising_ (const GapAdvertisingParams &params);
00597 
00598     /**
00599      * @see Gap::reset
00600      */
00601     ble_error_t reset_ (void);
00602 
00603     /**
00604      * @copydoc ::Gap::processConnectionEvent
00605      */
00606     void processConnectionEvent (
00607         Handle_t handle,
00608         Role_t role,
00609         peer_address_type_t peerAddrType,
00610         const BLEProtocol::AddressBytes_t peerAddr,
00611         BLEProtocol::AddressType_t ownAddrType,
00612         const BLEProtocol::AddressBytes_t ownAddr,
00613         const ConnectionParams_t *connectionParams,
00614         const uint8_t *peerResolvableAddr,
00615         const uint8_t *localResolvableAddr
00616     );
00617 
00618     /**
00619      * @copydoc ::Gap::processDisconnectionEvent
00620      */
00621     void processDisconnectionEvent (
00622         Handle_t handle,
00623         DisconnectionReason_t reason
00624     );
00625 
00626 private:
00627     ble_error_t setAdvertisingData(
00628         advertising_handle_t handle,
00629         Span<const uint8_t> payload,
00630         bool minimiseFragmentation,
00631         bool scan_response
00632     );
00633 
00634     void process_scan_timeout();
00635 
00636     void on_advertising_timeout();
00637 
00638     void process_advertising_timeout();
00639 
00640     void on_gap_event_received(const pal::GapEvent &e);
00641 
00642     void on_advertising_report(const pal::GapAdvertisingReportEvent &e);
00643 
00644     void on_connection_complete(const pal::GapConnectionCompleteEvent &e);
00645 
00646     void on_disconnection_complete(const pal::GapDisconnectionCompleteEvent &e);
00647 
00648     void on_connection_parameter_request(
00649         const pal::GapRemoteConnectionParameterRequestEvent &e
00650     );
00651 
00652     void on_connection_update(const pal::GapConnectionUpdateEvent &e);
00653 
00654     void on_unexpected_error(const pal::GapUnexpectedErrorEvent &e);
00655 
00656     enum AddressUseType_t {
00657         CENTRAL_CONNECTION,
00658         CENTRAL_SCAN,
00659         PERIPHERAL_CONNECTABLE,
00660         PERIPHERAL_NON_CONNECTABLE
00661     };
00662 
00663     pal::own_address_type_t get_own_address_type(AddressUseType_t address_use_type);
00664 
00665     bool initialize_whitelist() const;
00666 
00667     ble_error_t update_address_resolution_setting();
00668 
00669     void set_random_address_rotation(bool enable);
00670 
00671     void update_random_address();
00672 
00673     bool getUnresolvableRandomAddress(ble::address_t &address);
00674 
00675     void on_address_rotation_timeout();
00676 
00677     void useVersionOneAPI_() const;
00678 
00679     void useVersionTwoAPI_() const;
00680 
00681     /* implements pal::Gap::EventHandler */
00682 private:
00683     void on_read_phy_(
00684         pal::hci_error_code_t hci_status,
00685         Handle_t connection_handle,
00686         phy_t tx_phy,
00687         phy_t rx_phy
00688     );
00689 
00690     void on_data_length_change_(
00691         connection_handle_t connection_handle,
00692         uint16_t tx_size,
00693         uint16_t rx_size
00694     );
00695 
00696     void on_phy_update_complete_(
00697         pal::hci_error_code_t hci_status,
00698         Handle_t connection_handle,
00699         phy_t tx_phy,
00700         phy_t rx_phy
00701     );
00702 
00703     void on_enhanced_connection_complete_(
00704         pal::hci_error_code_t status,
00705         connection_handle_t connection_handle,
00706         pal::connection_role_t own_role,
00707         pal::connection_peer_address_type_t peer_address_type,
00708         const ble::address_t &peer_address,
00709         const ble::address_t &local_resolvable_private_address,
00710         const ble::address_t &peer_resolvable_private_address,
00711         uint16_t connection_interval,
00712         uint16_t connection_latency,
00713         uint16_t supervision_timeout,
00714         pal::clock_accuracy_t master_clock_accuracy
00715     );
00716 
00717     void on_extended_advertising_report_(
00718         advertising_event_t event_type,
00719         const pal::connection_peer_address_type_t *address_type,
00720         const ble::address_t &address,
00721         phy_t primary_phy,
00722         const phy_t *secondary_phy,
00723         advertising_sid_t advertising_sid,
00724         pal::advertising_power_t tx_power,
00725         pal::rssi_t rssi,
00726         uint16_t periodic_advertising_interval,
00727         pal::direct_address_type_t direct_address_type,
00728         const ble::address_t &direct_address,
00729         uint8_t data_length,
00730         const uint8_t *data
00731     );
00732 
00733     void on_periodic_advertising_sync_established_(
00734         pal::hci_error_code_t error,
00735         pal::sync_handle_t sync_handle,
00736         advertising_sid_t advertising_sid,
00737         pal::connection_peer_address_type_t advertiser_address_type,
00738         const ble::address_t &advertiser_address,
00739         phy_t advertiser_phy,
00740         uint16_t periodic_advertising_interval,
00741         pal::clock_accuracy_t clock_accuracy
00742     );
00743 
00744     void on_periodic_advertising_report_(
00745         pal::sync_handle_t sync_handle,
00746         pal::advertising_power_t tx_power,
00747         pal::rssi_t rssi,
00748         pal::advertising_data_status_t data_status,
00749         uint8_t data_length,
00750         const uint8_t *data
00751     );
00752 
00753     void on_periodic_advertising_sync_loss_(pal::sync_handle_t sync_handle);
00754 
00755     void on_advertising_set_terminated_(
00756         pal::hci_error_code_t status,
00757         advertising_handle_t advertising_handle,
00758         connection_handle_t connection_handle,
00759         uint8_t number_of_completed_extended_advertising_events
00760     );
00761 
00762     void on_scan_request_received_(
00763         advertising_handle_t advertising_handle,
00764         pal::connection_peer_address_type_t scanner_address_type,
00765         const ble::address_t &address
00766     );
00767 
00768     void on_connection_update_complete_(
00769         pal::hci_error_code_t status,
00770         connection_handle_t connection_handle,
00771         uint16_t connection_interval,
00772         uint16_t connection_latency,
00773         uint16_t supervision_timeout
00774     );
00775 
00776     void on_remote_connection_parameter_(
00777         connection_handle_t connection_handle,
00778         uint16_t connection_interval_min,
00779         uint16_t connection_interval_max,
00780         uint16_t connection_latency,
00781         uint16_t supervision_timeout
00782     );
00783 
00784     void on_scan_timeout_();
00785     void process_legacy_scan_timeout();
00786 
00787 private:
00788     pal::EventQueue &_event_queue;
00789     PalGap &_pal_gap;
00790     pal::GenericAccessService &_gap_service;
00791     PalSecurityManager &_pal_sm;
00792     BLEProtocol::AddressType_t _address_type;
00793     ble::address_t _address;
00794     pal::initiator_policy_t _initiator_policy_mode;
00795     pal::scanning_filter_policy_t _scanning_filter_policy;
00796     pal::advertising_filter_policy_t _advertising_filter_policy;
00797     mutable Whitelist_t _whitelist;
00798 
00799     bool _privacy_enabled;
00800     PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration;
00801     CentralPrivacyConfiguration_t _central_privacy_configuration;
00802     ble::address_t _random_static_identity_address;
00803     bool _random_address_rotating;
00804 
00805     bool _scan_enabled;
00806     mbed::LowPowerTimeout _advertising_timeout;
00807     mbed::LowPowerTimeout _scan_timeout;
00808     mbed::LowPowerTicker _address_rotation_ticker;
00809 
00810     template<size_t bit_size>
00811     struct BitArray {
00812         BitArray() : data()
00813         {
00814         }
00815 
00816         bool get(size_t index) const
00817         {
00818             position p(index);
00819             return (data[p.byte_index] >> p.bit_index) & 0x01;
00820         }
00821 
00822         void set(size_t index)
00823         {
00824             position p(index);
00825             data[p.byte_index] |= (0x01 << p.bit_index);
00826         }
00827 
00828         void clear(size_t index)
00829         {
00830             position p(index);
00831             data[p.byte_index] &= ~(0x01 << p.bit_index);
00832         }
00833 
00834         void clear()
00835         {
00836             for (size_t i = 0; i < (bit_size / 8 + 1); ++i) {
00837                 data[i] = 0;
00838             }
00839         }
00840 
00841     private:
00842         struct position {
00843             position(size_t bit_number) :
00844                 byte_index(bit_number / 8),
00845                 bit_index(bit_number % 8)
00846             {
00847             }
00848 
00849             size_t byte_index;
00850             uint8_t bit_index;
00851         };
00852 
00853         uint8_t data[bit_size / 8 + 1];
00854     };
00855 
00856     BitArray<MAX_ADVERTISING_SETS> _existing_sets;
00857     BitArray<MAX_ADVERTISING_SETS> _active_sets;
00858     BitArray<MAX_ADVERTISING_SETS> _active_periodic_sets;
00859     BitArray<MAX_ADVERTISING_SETS> _connectable_payload_size_exceeded;
00860     BitArray<MAX_ADVERTISING_SETS> _set_is_connectable;
00861 
00862     // deprecation flags
00863     mutable bool _deprecated_scan_api_used : 1;
00864     mutable bool _non_deprecated_scan_api_used : 1;
00865     bool _user_manage_connection_parameter_requests : 1;
00866 
00867 private:
00868     ble_error_t setExtendedAdvertisingParameters(
00869         advertising_handle_t handle,
00870         const AdvertisingParameters &parameters
00871     );
00872 
00873     bool is_extended_advertising_available();
00874 };
00875 
00876 } // namespace generic
00877 } // namespace ble
00878 
00879 #endif /* MBED_BLE_GENERIC_GAP */