Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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/BLE.h" 00023 #include "ble/BLEProtocol.h" 00024 #include "ble/Gap.h" 00025 #include "ble/pal/PalGap.h" 00026 #include "ble/pal/GapEvents.h" 00027 #include "ble/pal/GapTypes.h" 00028 #include "ble/pal/GenericAccessService.h" 00029 #include "ble/pal/EventQueue.h" 00030 00031 #include "drivers/Timeout.h" 00032 00033 namespace ble { 00034 namespace generic { 00035 00036 /** 00037 * Generic implementation of the Gap class. 00038 * It requires a pal::Gap and a pal::GenericAccessService injected at 00039 * construction site. 00040 * 00041 * @attention: Not part of the public interface of BLE API. 00042 */ 00043 class GenericGap : public ::Gap { 00044 00045 public: 00046 /** 00047 * Construct a GenericGap instance for a given BLE instance ID. 00048 * 00049 * @param ble_instance_id Id of the BLE instance using this instance. 00050 * 00051 * @param pal_gap GAP Platform abstraction instance containing the base GAP 00052 * primitives. 00053 * 00054 * @param generic_access_service Platform abstraction instance managing 00055 * the GATT generic access service. 00056 */ 00057 GenericGap( 00058 pal::EventQueue &event_queue, 00059 pal::Gap &pal_gap, 00060 pal::GenericAccessService &generic_access_service 00061 ); 00062 00063 /** 00064 * @see Gap::~Gap 00065 */ 00066 virtual ~GenericGap (); 00067 00068 /** 00069 * @see Gap::setAddress 00070 */ 00071 virtual ble_error_t setAddress ( 00072 BLEProtocol::AddressType_t type, 00073 const BLEProtocol::AddressBytes_t address 00074 ); 00075 00076 /** 00077 * @see Gap::getAddress 00078 */ 00079 virtual ble_error_t getAddress ( 00080 BLEProtocol::AddressType_t *type, 00081 BLEProtocol::AddressBytes_t address 00082 ); 00083 00084 /** 00085 * @see Gap::getMinAdvertisingInterval 00086 */ 00087 virtual uint16_t getMinAdvertisingInterval () const; 00088 00089 /** 00090 * @see Gap::getMinNonConnectableAdvertisingInterval 00091 */ 00092 virtual uint16_t getMinNonConnectableAdvertisingInterval () const; 00093 00094 /** 00095 * @see Gap::getMaxAdvertisingInterval 00096 */ 00097 virtual uint16_t getMaxAdvertisingInterval () const; 00098 00099 /** 00100 * @see Gap::stopAdvertising 00101 */ 00102 virtual ble_error_t stopAdvertising (); 00103 00104 /** 00105 * @see Gap::stopScan 00106 */ 00107 virtual ble_error_t stopScan (); 00108 00109 /** 00110 * @see Gap::connect 00111 */ 00112 virtual ble_error_t connect ( 00113 const BLEProtocol::AddressBytes_t peerAddr, 00114 BLEProtocol::AddressType_t peerAddrType, 00115 const ConnectionParams_t *connectionParams, 00116 const GapScanningParams *scanParams 00117 ); 00118 00119 /** 00120 * @see Gap::disconnect 00121 */ 00122 virtual ble_error_t disconnect ( 00123 Handle_t connectionHandle, 00124 DisconnectionReason_t reason 00125 ); 00126 00127 /** 00128 * @see Gap::updateConnectionParams 00129 */ 00130 virtual ble_error_t updateConnectionParams ( 00131 Handle_t handle, 00132 const ConnectionParams_t *params 00133 ); 00134 00135 /** 00136 * @see Gap::getPreferredConnectionParams 00137 */ 00138 virtual ble_error_t getPreferredConnectionParams ( 00139 ConnectionParams_t *params 00140 ); 00141 00142 /** 00143 * @see Gap::setPreferredConnectionParams 00144 */ 00145 virtual ble_error_t setPreferredConnectionParams ( 00146 const ConnectionParams_t *params 00147 ); 00148 00149 /** 00150 * @see Gap::setDeviceName 00151 */ 00152 virtual ble_error_t setDeviceName (const uint8_t *deviceName); 00153 00154 /** 00155 * @see Gap::getDeviceName 00156 */ 00157 virtual ble_error_t getDeviceName (uint8_t *deviceName, unsigned *lengthP); 00158 00159 /** 00160 * @see Gap::setAppearance 00161 */ 00162 virtual ble_error_t setAppearance (GapAdvertisingData::Appearance appearance); 00163 00164 /** 00165 * @see Gap::getAppearance 00166 */ 00167 virtual ble_error_t getAppearance (GapAdvertisingData::Appearance *appearanceP); 00168 00169 /** 00170 * @see Gap::setTxPower 00171 */ 00172 virtual ble_error_t setTxPower (int8_t txPower); 00173 00174 /** 00175 * @see Gap::getPermittedTxPowerValues 00176 */ 00177 virtual void getPermittedTxPowerValues (const int8_t **valueArrayPP, size_t *countP); 00178 00179 /** 00180 * @see Gap::getMaxWhitelistSize 00181 */ 00182 virtual uint8_t getMaxWhitelistSize (void) const; 00183 00184 /** 00185 * @see Gap::getWhitelist 00186 */ 00187 virtual ble_error_t getWhitelist (Whitelist_t &whitelist) const; 00188 00189 /** 00190 * @see Gap::setWhitelist 00191 */ 00192 virtual ble_error_t setWhitelist (const Whitelist_t &whitelist); 00193 00194 /** 00195 * @see Gap::setAdvertisingPolicyMode 00196 */ 00197 virtual ble_error_t setAdvertisingPolicyMode (AdvertisingPolicyMode_t mode); 00198 00199 /** 00200 * @see Gap::setScanningPolicyMode 00201 */ 00202 virtual ble_error_t setScanningPolicyMode (ScanningPolicyMode_t mode); 00203 00204 /** 00205 * @see Gap::setInitiatorPolicyMode 00206 */ 00207 virtual ble_error_t setInitiatorPolicyMode (InitiatorPolicyMode_t mode); 00208 00209 /** 00210 * @see Gap::getAdvertisingPolicyMode 00211 */ 00212 virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode (void) const; 00213 00214 /** 00215 * @see Gap::getScanningPolicyMode 00216 */ 00217 virtual ScanningPolicyMode_t getScanningPolicyMode (void) const; 00218 00219 /** 00220 * @see Gap::getInitiatorPolicyMode 00221 */ 00222 virtual InitiatorPolicyMode_t getInitiatorPolicyMode (void) const; 00223 00224 /** 00225 * @see Gap::startRadioScan 00226 */ 00227 virtual ble_error_t startRadioScan (const GapScanningParams &scanningParams); 00228 00229 /** 00230 * @see Gap::initRadioNotification 00231 */ 00232 virtual ble_error_t initRadioNotification (void); 00233 00234 /** 00235 * @see Gap::setAdvertisingData 00236 */ 00237 virtual ble_error_t setAdvertisingData ( 00238 const GapAdvertisingData &advData, 00239 const GapAdvertisingData &scanResponse 00240 ); 00241 00242 /** 00243 * @see Gap::startAdvertising 00244 */ 00245 virtual ble_error_t startAdvertising(const GapAdvertisingParams ¶ms); 00246 00247 /** 00248 * @see Gap::reset 00249 */ 00250 virtual ble_error_t reset (void); 00251 00252 private: 00253 void on_scan_timeout(); 00254 00255 void process_scan_timeout(); 00256 00257 void on_advertising_timeout(); 00258 00259 void process_advertising_timeout(); 00260 00261 void on_gap_event_received(const pal::GapEvent &e); 00262 00263 void on_advertising_report(const pal::GapAdvertisingReportEvent &e); 00264 00265 void on_connection_complete(const pal::GapConnectionCompleteEvent &e); 00266 00267 void on_disconnection_complete(const pal::GapDisconnectionCompleteEvent &e); 00268 00269 void on_connection_parameter_request( 00270 const pal::GapRemoteConnectionParameterRequestEvent &e 00271 ); 00272 00273 void on_connection_update(const pal::GapConnectionUpdateEvent &e); 00274 00275 void on_unexpected_error(const pal::GapUnexpectedErrorEvent &e); 00276 00277 pal::own_address_type_t get_own_address_type(); 00278 00279 bool initialize_whitelist() const; 00280 00281 pal::EventQueue& _event_queue; 00282 pal::Gap &_pal_gap; 00283 pal::GenericAccessService &_gap_service; 00284 BLEProtocol::AddressType_t _address_type; 00285 pal::initiator_policy_t _initiator_policy_mode; 00286 pal::scanning_filter_policy_t _scanning_filter_policy; 00287 pal::advertising_filter_policy_t _advertising_filter_policy; 00288 mutable Whitelist_t _whitelist; 00289 mbed::Timeout _advertising_timeout; 00290 mbed::Timeout _scan_timeout; 00291 }; 00292 00293 } 00294 } 00295 00296 #endif /* MBED_BLE_GENERIC_GAP */
Generated on Tue Jul 12 2022 13:24:43 by
1.7.2