BLE: Move new version of ::GAP in a new class ::ble::Gap .

pull/8738/head
Vincent Coubard 2018-11-19 15:05:52 +00:00
parent 84dd169d14
commit 02d61cfe24
12 changed files with 1071 additions and 1012 deletions

View File

@ -19,15 +19,6 @@
#include "BLETypes.h"
#include "BLEProtocol.h"
// gap headers
#include "ble/gap/AdvertisingDataBuilder.h"
#include "ble/gap/ConnectionParameters.h"
#include "ble/gap/ScanParameters.h"
#include "ble/gap/AdvertisingParameters.h"
#include "ble/gap/Events.h"
// leagacy gap headers
#include "ble/GapAdvertisingData.h"
#include "ble/GapAdvertisingParams.h"
#include "ble/GapScanningParams.h"
@ -37,6 +28,7 @@
#include "FunctionPointerWithContext.h"
#include "platform/mbed_toolchain.h"
#include "ble/gap/Gap.h"
/**
* @addtogroup ble
@ -268,622 +260,8 @@
* PHY and of any changes to PHYs which may be triggered autonomously by the
* controller or by the peer.
*/
class Gap {
class Gap : public ble::Gap {
public:
/**
* Definition of the general handler of Gap related events.
*/
struct EventHandler {
/** Called when a scanning device request a scan response.
*
* @param event Scan request event: @see ScanRequestEvent_t for details.
*/
virtual void onScanRequest(const ble::ScanRequestEvent_t& event) { }
/** Called when advertising ends.
*
* @param event Advertising end event: @see AdvertisingEndEvent_t for details.
*/
virtual void onAdvertisingEnd(const ble::AdvertisingEndEvent_t& event)
{ }
/** Called when scanning reads an advertising packet during passive scan or receives
* a scan response during an active scan.
*
* @param event Advertising report @see AdvertisingReportEvent_t for details.
*/
void onAdvertisingReport(const ble::AdvertisingReportEvent &event) { }
/** Called when scan times out.
*/
virtual void onScanTimeout(const ble::ScanTimeoutEvent &) { }
/** Called when first advertising packet in periodic advertising is received.
*
* @param event Periodic advertising sync event @see PeriodicAdvertisingSyncEstablishedEvent.
*/
virtual void onPeriodicAdvertisingSyncEstablished(
const ble::PeriodicAdvertisingSyncEstablishedEvent &event
) { }
/** Called when a periodic advertising packet is received.
*
* @param event Periodic advertisement event.
*/
virtual void onPeriodicAdvertisingReportEvent(
const ble::PeriodicAdvertisingReportEvent & event
) { }
virtual void onPeriodicAdvertisingSyncLoss(
const ble::PeriodicAdvertisingSyncLoss &event
) { }
/** Called when connection attempt ends.
*
* @param event Connection event @see ConnectionCompleteEvent_t for details.
*/
virtual void onConnectionComplete(const ble::ConnectionCompleteEvent &event) { }
virtual void onUpdateConnectionParametersRequest(
const ble::UpdateConnectionParametersRequestEvent &event
) { }
virtual void onConnectionParametersUpdateComplete(
const ble::ConnectionParametersUpdateCompleteEvent &event
) { }
virtual void onDisconnection(const ble::DisconnectionEvent &event) { }
/**
* Function invoked when the current transmitter and receiver PHY have
* been read for a given connection.
*
* @param status Status of the operation: BLE_ERROR_NONE in case of
* success or an appropriate error code.
*
* @param connectionHandle: The handle of the connection for which the
* PHYs have been read.
*
* @param txPhy PHY used by the transmitter.
*
* @param rxPhy PHY used by the receiver.
*/
virtual void onReadPhy(
ble_error_t status,
ble::connection_handle_t connectionHandle,
ble::phy_t txPhy,
ble::phy_t rxPhy
) { }
/**
* Function invoked when the update process of the PHY has been completed.
*
* The process can be initiated by a call to the function setPhy, the
* local bluetooth subsystem or the peer.
*
* @param status Status of the operation: BLE_ERROR_NONE in case of
* success or an appropriate error code.
*
* @param connectionHandle: The handle of the connection on which the
* operation was made.
*
* @param txPhy PHY used by the transmitter.
*
* @param rxPhy PHY used by the receiver.
*
* @note Success doesn't mean the PHY has been updated it means both
* ends have negotiated the best PHY according to their configuration and
* capabilities. The PHY currently used are present in the txPhy and
* rxPhy parameters.
*/
virtual void onPhyUpdateComplete(
ble_error_t status,
ble::connection_handle_t connectionHandle,
ble::phy_t txPhy,
ble::phy_t rxPhy
) { }
protected:
/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
* as the Gap class will never delete the instance it contains.
*/
~EventHandler() { }
};
/**
* Representation of a whitelist of addresses.
*/
struct Whitelist_t {
/**
* Pointer to the array of the addresses composing the whitelist.
*/
BLEProtocol::Address_t *addresses;
/**
* Number addresses in this whitelist.
*/
uint8_t size;
/**
* Capacity of the array holding the addresses.
*/
uint8_t capacity;
};
/** Check controller support for a specific feature.
*
* @param feature Feature to check.
* @return True if feature is supported.
*/
virtual bool isFeatureSupported(ble::controller_supported_features_t feature)
{
// TODO: deal with legacy implementation
}
/* advertising */
/** Return currently available number of supported advertising sets.
* This may change at runtime.
*
* @return Number of advertising sets that may be created at the same time.
*/
virtual uint8_t getMaxAdvertisingSetNumber();
/** Return maximum advertising data length supported.
*
* @return Maximum advertising data length supported.
*/
virtual uint8_t getMaxAdvertisingDataLength();
/** Create an advertising set and apply the passed in parameters. The handle returned
* by this function must be used for all other calls that accept an advertising handle.
* When done with advertising, remove from the system using destroyAdvertisingSet().
*
* @note The exception is the ble::LEGACY_ADVERTISING_HANDLE which may be used at any time.
*
* @param[out] handle Advertising handle returned, valid only if function returned success.
* @param parameters Advertising parameters for the newly created set.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createAdvertisingSet(
ble::advertising_handle_t *handle,
const ble::AdvertisingParameters &parameters
);
/** Remove the advertising set (resets its set parameters). The advertising set must not
* be active.
*
* @note ble::LEGACY_ADVERTISING_HANDLE may not be destroyed.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t destroyAdvertisingSet(ble::advertising_handle_t handle);
/** Set advertising parameters of an existing set.
*
* @param handle Advertising set handle.
* @param params New advertising parameters.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingParameters(
ble::advertising_handle_t handle,
const ble::AdvertisingParameters &params
);
/** Set new advertising payload for a given advertising set.
*
* @param handle Advertising set handle.
* @param payload Advertising payload.
* @param minimiseFragmentation Preference for fragmentation.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingPayload(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> payload,
bool minimiseFragmentation = false
);
/** Set new advertising scan response for a given advertising set. This will be sent to
* device who perform active scanning.
*
* @param handle Advertising set handle.
* @param response Advertising scan response.
* @param minimiseFragmentation Preference for fragmentation.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingScanResponse(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> response,
bool minimiseFragmentation = false
);
/** Start advertising using the given advertising set.
*
* @param handle Advertising set handle.
* @param maxDuration Max duration for advertising (in units of 10ms) - 0 means no limit.
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startAdvertising(
ble::advertising_handle_t handle,
ble::adv_duration_t maxDuration = ble::adv_duration_t(0),
uint8_t maxEvents = 0
);
/** Stop advertising given advertising set. This is separate from periodic advertising
* which will not be affected.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t stopAdvertising(ble::advertising_handle_t handle);
/** Check if advertising is active for a given advertising set.
*
* @param handle Advertising set handle.
* @return True if advertising is active on this set.
*/
virtual bool isAdvertisingActive(ble::advertising_handle_t handle);
/** Set periodic advertising parameters for a given advertising set.
*
* @param handle Advertising set handle.
* @param periodicAdvertisingIntervalMin Minimum interval for periodic advertising.
* @param periodicAdvertisingIntervalMax Maximum interval for periodic advertising.
* @param advertiseTxPower Include transmission power in the advertisements.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setPeriodicAdvertisingParameters(
ble::advertising_handle_t handle,
ble::periodic_interval_t periodicAdvertisingIntervalMin,
ble::periodic_interval_t periodicAdvertisingIntervalMax,
bool advertiseTxPower = true
);
/** Set new periodic advertising payload for a given advertising set.
*
* @param handle Advertising set handle.
* @param payload Advertising payload.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setPeriodicAdvertisingPayload(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> payload
);
/** Start periodic advertising for a given set. Periodic advertising will not start until
* normal advertising is running but will continue to run after normal advertising has stopped.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startPeriodicAdvertising(ble::advertising_handle_t handle);
/** Stop periodic advertising for a given set.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t stopPeriodicAdvertising(ble::advertising_handle_t handle);
/** Check if periodic advertising is active for a given advertising set.
*
* @param handle Advertising set handle.
* @return True if periodic advertising is active on this set.
*/
virtual bool isPeriodicAdvertisingActive(ble::advertising_handle_t handle);
/* scanning */
/** Set new scan parameters.
*
* @param params Scan parameters, @see GapScanParameters for details.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setScanParameters(const ble::ScanParameters& params);
/** Start scanning.
*
* @param filtering Filtering policy.
* @param duration How long to scan for. Special value 0 means scan forever.
* @param period How long to scan for in single period. If the period is 0 and duration
* is nonzero the scan will last for single duration.
*
* @note When the duration and period parameters are non-zero scanning will last for
* the duration within the period. After the scan period has expired a new scan period
* will begin and scanning. This will repeat until stopScan() is called.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startScan(
ble::duplicates_filter_t filtering = ble::duplicates_filter_t::DISABLE,
ble::scan_duration_t duration = ble::scan_duration_t(0),
ble::scan_period_t period = ble::scan_period_t(0)
);
/** Synchronise with periodic advertising from an advertiser and begin receiving periodic
* advertising packets.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
* may skip after successfully receiving a periodic advertising packet.
* @param timeout Maximum permitted time between successful receptions. If this time is
* exceeded, synchronisation is lost.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createSync(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
uint8_t sid,
ble::slave_latency_t maxPacketSkip,
ble::sync_timeout_t timeout
);
/** Synchronise with periodic advertising from an advertiser and begin receiving periodic
* advertising packets. Use periodic advertising sync list to determine who to sync with.
*
* @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
* may skip after successfully receiving a periodic advertising packet.
* @param timeout Maximum permitted time between successful receives.
* If this time is exceeded, synchronisation is lost.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createSync(
ble::slave_latency_t maxPacketSkip,
ble::sync_timeout_t timeout
);
/** Cancel sync attempt.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t cancelCreateSync();
/** Stop reception of the periodic advertising identified by the handle.
*
* @param handle Periodic advertising synchronisation handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t terminateSync(ble::periodic_sync_handle_t handle);
/** Add device to the periodic advertiser list. Cannot be called when sync is ongoing.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t addDeviceToPeriodicAdvertiserList(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
ble::advertising_sid_t sid
);
/** Remove device from the periodic advertiser list. Cannot be called when sync is ongoing.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t removeDeviceFromPeriodicAdvertiserList(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
ble::advertising_sid_t sid
);
/** Remove all devices from periodic advertiser list.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t clearPeriodicAdvertiserList();
/** Get 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.
*/
virtual uint8_t getMaxPeriodicAdvertiserListSize();
/**
* Initiate a connection to a peer.
*
* Once the connection is established an onConnectionComplete in the event handler
* will be called.
*
* @param peerAddressType
* @param peerAddress
* @param connectionParams
*
* @return BLE_ERROR_NONE if connection establishment procedure is started
* successfully. The connectionCallChain (if set) is invoked upon
* a connection event.
*/
virtual ble_error_t connect(
ble::target_peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
const ble::ConnectionParameters &connectionParams
);
/** Cancel the connection attempt. This is not guaranteed to succeed. As a result
* onConnectionComplete in the event handler will be called. Check the success parameter
* to see if the connection was created.
*
* @return BLE_ERROR_NONE if the connection attempt has been requested to be cancelled.
*/
virtual ble_error_t cancelConnect();
virtual ble_error_t updateConnectionParameters(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervision_timeout,
ble::conn_event_length_t minConnectionEventLength = ble::conn_event_length_t(0),
ble::conn_event_length_t maxConnectionEventLength = ble::conn_event_length_t(0)
);
virtual ble_error_t manageConnectionParametersUpdateRequest(
bool userManageConnectionUpdateRequest
);
virtual ble_error_t acceptConnectionParametersUpdate(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervision_timeout,
ble::conn_event_length_t minConnectionEventLength = ble::conn_event_length_t(0),
ble::conn_event_length_t maxConnectionEventLength = ble::conn_event_length_t(0)
);
virtual ble_error_t rejectConnectionParametersUpdate(
ble::connection_handle_t connectionHandle
);
/**
* Initiate a disconnection procedure.
*
* Once the disconnection procedure has completed a
* DisconnectionCallbackParams_t, the event is emitted to handlers that
* have been registered with onDisconnection().
*
* @param[in] reason Reason of the disconnection transmitted to the peer.
* @param[in] connectionHandle Handle of the connection to end.
*
* @return BLE_ERROR_NONE if the disconnection procedure successfully
* started.
*/
virtual ble_error_t disconnect(
ble::connection_handle_t connectionHandle,
ble::local_disconnection_reason_t reason
);
/**
* Read the PHY used by the transmitter and the receiver on a connection.
*
* Once the PHY has been read, it is reported back via the function onPhyRead
* of the event handler registered by the application.
*
* @param connection Handle of the connection for which the PHY being used is
* queried.
*
* @return BLE_ERROR_NONE if the read PHY procedure has been started or an
* appropriate error code.
*/
virtual ble_error_t readPhy(ble::connection_handle_t connection);
/**
* Set the preferred PHYs to use in a connection.
*
* @param txPhys: Set of PHYs preferred for tx operations. If NULL then no
* preferred PHYs are set and the default value of the subsystem is used.
*
* @param rxPhys: Set of PHYs preferred for rx operations. If NULL then no
* preferred PHYs are set and the default value of the subsystem is used.
*
* @return BLE_ERROR_NONE if the preferences have been set or an appropriate
* error code.
*/
virtual ble_error_t setPreferredPhys(
const ble::phy_set_t *txPhys,
const ble::phy_set_t *rxPhys
);
/**
* Update the PHY used by a connection.
*
* Once the update process has been completed, it is reported back to the
* application via the function onPhyUpdateComplete of the event handler
* registered by the application.
*
* @param connection Handle of the connection to update.
*
* @param txPhys Set of PHYs preferred for tx operations. If NULL then the
* choice is up to the Bluetooth subsystem.
*
* @param rxPhys Set of PHYs preferred for rx operations. If NULL then the
* choice is up to the Bluetooth subsystem.
*
* @param codedSymbol Number of symbols used to code a bit when le coded is
* used. If the value is UNDEFINED then the choice is up to the Bluetooth
* subsystem.
*
* @return BLE_ERROR_NONE if the update PHY procedure has been successfully
* started or an error code.
*/
virtual ble_error_t setPhy(
ble::connection_handle_t connection,
const ble::phy_set_t *txPhys,
const ble::phy_set_t *rxPhys,
ble::coded_symbol_per_bit_t codedSymbol
);
/**
* Get the maximum size of the whitelist.
*
* @return Maximum size of the whitelist.
*
* @note If using Mbed OS, you can configure the size of the whitelist by
* setting the YOTTA_CFG_WHITELIST_MAX_SIZE macro in your yotta config file.
*/
virtual uint8_t getMaxWhitelistSize(void) const;
/**
* Get the Link Layer to use the internal whitelist when scanning,
* advertising or initiating a connection depending on the filter policies.
*
* @param[in,out] whitelist Define the whitelist instance which is used
* to store the whitelist requested. In input, the caller provisions memory.
*
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
* copied into the supplied reference.
*/
virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const;
/**
* Set the value of the whitelist to be used during GAP procedures.
*
* @param[in] whitelist A reference to a whitelist containing the addresses
* to be copied to the internal whitelist.
*
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
* populated with the addresses in the given whitelist.
*
* @note The whitelist must not contain addresses of type @ref
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
* change its private address at any time, and it is not possible to resolve
* it.
*
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
*/
virtual ble_error_t setWhitelist(const Whitelist_t &whitelist);
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.
* This guards against mixed use of deprecated and nondeprecated API.
*/
virtual void useVersionOneAPI() const { }
/** Can only be called if use_deprecated_scan_api() hasn't been called.
* This guards against mixed use of deprecated and nondeprecated API.
*/
virtual void useVersionTwoAPI() const { }
/*
* DEPRECATION ALERT: all of the APIs in this `public` block are deprecated.
* They have been relocated to the class BLEProtocol.
*/
public:
/**
* Address-type for BLEProtocol addresses.
@ -1071,6 +449,26 @@ public:
INIT_POLICY_FILTER_ALL_ADV = 1,
};
/**
* Representation of a whitelist of addresses.
*/
struct Whitelist_t {
/**
* Pointer to the array of the addresses composing the whitelist.
*/
BLEProtocol::Address_t *addresses;
/**
* Number addresses in this whitelist.
*/
uint8_t size;
/**
* Capacity of the array holding the addresses.
*/
uint8_t capacity;
};
/**
* Description of the states of the device.
*/
@ -2174,6 +1572,48 @@ public:
*countP = 0;
}
/**
* Get the maximum size of the whitelist.
*
* @return Maximum size of the whitelist.
*
* @note If using Mbed OS, you can configure the size of the whitelist by
* setting the YOTTA_CFG_WHITELIST_MAX_SIZE macro in your yotta config file.
*/
virtual uint8_t getMaxWhitelistSize(void) const;
/**
* Get the Link Layer to use the internal whitelist when scanning,
* advertising or initiating a connection depending on the filter policies.
*
* @param[in,out] whitelist Define the whitelist instance which is used
* to store the whitelist requested. In input, the caller provisions memory.
*
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
* copied into the supplied reference.
*/
virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const;
/**
* Set the value of the whitelist to be used during GAP procedures.
*
* @param[in] whitelist A reference to a whitelist containing the addresses
* to be copied to the internal whitelist.
*
* @return BLE_ERROR_NONE if the implementation's whitelist was successfully
* populated with the addresses in the given whitelist.
*
* @note The whitelist must not contain addresses of type @ref
* BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE. This
* results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
* change its private address at any time, and it is not possible to resolve
* it.
*
* @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
* then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
*/
virtual ble_error_t setWhitelist(const Whitelist_t &whitelist);
/**
* Set the advertising policy filter mode to be used during the next
* advertising procedure.
@ -3192,16 +2632,6 @@ public:
/* Event handlers. */
public:
/**
* Assign the event handler implementation that will be used by the gap
* module to signal events back to the application.
*
* @param handler Application implementation of an Eventhandler.
*/
void setEventHandler(EventHandler* handler) {
_eventHandler = handler;
}
/**
* Register a callback handling timeout events.
*
@ -3451,8 +2881,7 @@ protected:
radioNotificationCallback(),
onAdvertisementReport(),
connectionCallChain(),
disconnectionCallChain(),
_eventHandler(NULL) {
disconnectionCallChain() {
_advPayload.clear();
_scanResponse.clear();
}
@ -3608,7 +3037,7 @@ public:
uint8_t advertisingDataLen,
const uint8_t *advertisingData,
BLEProtocol::AddressType_t addressType = BLEProtocol::AddressType::RANDOM_STATIC
);
);
/**
* Notify the occurrence of a timeout event to all registered timeout events
@ -3696,11 +3125,6 @@ protected:
*/
DisconnectionEventCallbackChain_t disconnectionCallChain;
/**
* Event handler provided by the application.
*/
EventHandler* _eventHandler;
private:
/**
* Callchain containing all registered callback handlers for shutdown

View File

@ -0,0 +1,602 @@
/* mbed Microcontroller Library
* Copyright (c) 2018-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.
*/
#ifndef BLE_GAP_GAP_H
#define BLE_GAP_GAP_H
#include "ble/BLETypes.h"
#include "ble/BLEProtocol.h"
#include "ble/gap/AdvertisingDataBuilder.h"
#include "ble/gap/ConnectionParameters.h"
#include "ble/gap/ScanParameters.h"
#include "ble/gap/AdvertisingParameters.h"
#include "ble/gap/Events.h"
namespace ble {
class Gap {
public:
/**
* Definition of the general handler of Gap related events.
*/
struct EventHandler {
/** Called when a scanning device request a scan response.
*
* @param event Scan request event: @see ScanRequestEvent_t for details.
*/
virtual void onScanRequest(const ScanRequestEvent_t &event) { }
/** Called when advertising ends.
*
* @param event Advertising end event: @see AdvertisingEndEvent_t for details.
*/
virtual void onAdvertisingEnd(const AdvertisingEndEvent_t &event) { }
/** Called when scanning reads an advertising packet during passive scan or receives
* a scan response during an active scan.
*
* @param event Advertising report @see AdvertisingReportEvent_t for details.
*/
void onAdvertisingReport(const AdvertisingReportEvent &event) { }
/** Called when scan times out.
*/
virtual void onScanTimeout(const ScanTimeoutEvent &) { }
/** Called when first advertising packet in periodic advertising is received.
*
* @param event Periodic advertising sync event @see PeriodicAdvertisingSyncEstablishedEvent.
*/
virtual void onPeriodicAdvertisingSyncEstablished(
const PeriodicAdvertisingSyncEstablishedEvent &event
) { }
/** Called when a periodic advertising packet is received.
*
* @param event Periodic advertisement event.
*/
virtual void onPeriodicAdvertisingReportEvent(
const PeriodicAdvertisingReportEvent &event
) { }
virtual void onPeriodicAdvertisingSyncLoss(
const PeriodicAdvertisingSyncLoss &event
) { }
/** Called when connection attempt ends.
*
* @param event Connection event @see ConnectionCompleteEvent_t for details.
*/
virtual void onConnectionComplete(const ConnectionCompleteEvent &event) { }
virtual void onUpdateConnectionParametersRequest(
const UpdateConnectionParametersRequestEvent &event
) { }
virtual void onConnectionParametersUpdateComplete(
const ConnectionParametersUpdateCompleteEvent &event
) { }
virtual void onDisconnection(const DisconnectionEvent &event) { }
/**
* Function invoked when the current transmitter and receiver PHY have
* been read for a given connection.
*
* @param status Status of the operation: BLE_ERROR_NONE in case of
* success or an appropriate error code.
*
* @param connectionHandle: The handle of the connection for which the
* PHYs have been read.
*
* @param txPhy PHY used by the transmitter.
*
* @param rxPhy PHY used by the receiver.
*/
virtual void onReadPhy(
ble_error_t status,
connection_handle_t connectionHandle,
phy_t txPhy,
phy_t rxPhy
) { }
/**
* Function invoked when the update process of the PHY has been completed.
*
* The process can be initiated by a call to the function setPhy, the
* local bluetooth subsystem or the peer.
*
* @param status Status of the operation: BLE_ERROR_NONE in case of
* success or an appropriate error code.
*
* @param connectionHandle: The handle of the connection on which the
* operation was made.
*
* @param txPhy PHY used by the transmitter.
*
* @param rxPhy PHY used by the receiver.
*
* @note Success doesn't mean the PHY has been updated it means both
* ends have negotiated the best PHY according to their configuration and
* capabilities. The PHY currently used are present in the txPhy and
* rxPhy parameters.
*/
virtual void onPhyUpdateComplete(
ble_error_t status,
connection_handle_t connectionHandle,
phy_t txPhy,
phy_t rxPhy
) { }
protected:
/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
* as the Gap class will never delete the instance it contains.
*/
~EventHandler() { }
};
/**
* Assign the event handler implementation that will be used by the gap
* module to signal events back to the application.
*
* @param handler Application implementation of an Eventhandler.
*/
void setEventHandler(EventHandler *handler)
{
_eventHandler = handler;
}
/** Check controller support for a specific feature.
*
* @param feature Feature to check.
* @return True if feature is supported.
*/
virtual bool isFeatureSupported(controller_supported_features_t feature)
{
// TODO: deal with legacy implementation
}
/* advertising */
/** Return currently available number of supported advertising sets.
* This may change at runtime.
*
* @return Number of advertising sets that may be created at the same time.
*/
virtual uint8_t getMaxAdvertisingSetNumber();
/** Return maximum advertising data length supported.
*
* @return Maximum advertising data length supported.
*/
virtual uint8_t getMaxAdvertisingDataLength();
/** Create an advertising set and apply the passed in parameters. The handle returned
* by this function must be used for all other calls that accept an advertising handle.
* When done with advertising, remove from the system using destroyAdvertisingSet().
*
* @note The exception is the LEGACY_ADVERTISING_HANDLE which may be used at any time.
*
* @param[out] handle Advertising handle returned, valid only if function returned success.
* @param parameters Advertising parameters for the newly created set.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createAdvertisingSet(
advertising_handle_t *handle,
const AdvertisingParameters &parameters
);
/** Remove the advertising set (resets its set parameters). The advertising set must not
* be active.
*
* @note LEGACY_ADVERTISING_HANDLE may not be destroyed.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t destroyAdvertisingSet(advertising_handle_t handle);
/** Set advertising parameters of an existing set.
*
* @param handle Advertising set handle.
* @param params New advertising parameters.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingParameters(
advertising_handle_t handle,
const AdvertisingParameters &params
);
/** Set new advertising payload for a given advertising set.
*
* @param handle Advertising set handle.
* @param payload Advertising payload.
* @param minimiseFragmentation Preference for fragmentation.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingPayload(
advertising_handle_t handle,
mbed::Span<uint8_t> payload,
bool minimiseFragmentation = false
);
/** Set new advertising scan response for a given advertising set. This will be sent to
* device who perform active scanning.
*
* @param handle Advertising set handle.
* @param response Advertising scan response.
* @param minimiseFragmentation Preference for fragmentation.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAdvertisingScanResponse(
advertising_handle_t handle,
mbed::Span<uint8_t> response,
bool minimiseFragmentation = false
);
/** Start advertising using the given advertising set.
*
* @param handle Advertising set handle.
* @param maxDuration Max duration for advertising (in units of 10ms) - 0 means no limit.
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startAdvertising(
advertising_handle_t handle,
adv_duration_t maxDuration = adv_duration_t(0),
uint8_t maxEvents = 0
);
/** Stop advertising given advertising set. This is separate from periodic advertising
* which will not be affected.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t stopAdvertising(advertising_handle_t handle);
/** Check if advertising is active for a given advertising set.
*
* @param handle Advertising set handle.
* @return True if advertising is active on this set.
*/
virtual bool isAdvertisingActive(advertising_handle_t handle);
/** Set periodic advertising parameters for a given advertising set.
*
* @param handle Advertising set handle.
* @param periodicAdvertisingIntervalMin Minimum interval for periodic advertising.
* @param periodicAdvertisingIntervalMax Maximum interval for periodic advertising.
* @param advertiseTxPower Include transmission power in the advertisements.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setPeriodicAdvertisingParameters(
advertising_handle_t handle,
periodic_interval_t periodicAdvertisingIntervalMin,
periodic_interval_t periodicAdvertisingIntervalMax,
bool advertiseTxPower = true
);
/** Set new periodic advertising payload for a given advertising set.
*
* @param handle Advertising set handle.
* @param payload Advertising payload.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setPeriodicAdvertisingPayload(
advertising_handle_t handle,
mbed::Span<uint8_t> payload
);
/** Start periodic advertising for a given set. Periodic advertising will not start until
* normal advertising is running but will continue to run after normal advertising has stopped.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startPeriodicAdvertising(advertising_handle_t handle);
/** Stop periodic advertising for a given set.
*
* @param handle Advertising set handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t stopPeriodicAdvertising(advertising_handle_t handle);
/** Check if periodic advertising is active for a given advertising set.
*
* @param handle Advertising set handle.
* @return True if periodic advertising is active on this set.
*/
virtual bool isPeriodicAdvertisingActive(advertising_handle_t handle);
/* scanning */
/** Set new scan parameters.
*
* @param params Scan parameters, @see GapScanParameters for details.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setScanParameters(const ScanParameters &params);
/** Start scanning.
*
* @param filtering Filtering policy.
* @param duration How long to scan for. Special value 0 means scan forever.
* @param period How long to scan for in single period. If the period is 0 and duration
* is nonzero the scan will last for single duration.
*
* @note When the duration and period parameters are non-zero scanning will last for
* the duration within the period. After the scan period has expired a new scan period
* will begin and scanning. This will repeat until stopScan() is called.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t startScan(
duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
scan_duration_t duration = scan_duration_t(0),
scan_period_t period = scan_period_t(0)
);
/** Synchronise with periodic advertising from an advertiser and begin receiving periodic
* advertising packets.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
* may skip after successfully receiving a periodic advertising packet.
* @param timeout Maximum permitted time between successful receptions. If this time is
* exceeded, synchronisation is lost.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createSync(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
uint8_t sid,
slave_latency_t maxPacketSkip,
sync_timeout_t timeout
);
/** Synchronise with periodic advertising from an advertiser and begin receiving periodic
* advertising packets. Use periodic advertising sync list to determine who to sync with.
*
* @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
* may skip after successfully receiving a periodic advertising packet.
* @param timeout Maximum permitted time between successful receives.
* If this time is exceeded, synchronisation is lost.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t createSync(
slave_latency_t maxPacketSkip,
sync_timeout_t timeout
);
/** Cancel sync attempt.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t cancelCreateSync();
/** Stop reception of the periodic advertising identified by the handle.
*
* @param handle Periodic advertising synchronisation handle.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t terminateSync(periodic_sync_handle_t handle);
/** Add device to the periodic advertiser list. Cannot be called when sync is ongoing.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t addDeviceToPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
advertising_sid_t sid
);
/** Remove device from the periodic advertiser list. Cannot be called when sync is ongoing.
*
* @param peerAddressType Peer address type.
* @param peerAddress Peer address.
* @param sid Advertiser set identifier.
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t removeDeviceFromPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
advertising_sid_t sid
);
/** Remove all devices from periodic advertiser list.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t clearPeriodicAdvertiserList();
/** Get 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.
*/
virtual uint8_t getMaxPeriodicAdvertiserListSize();
/**
* Initiate a connection to a peer.
*
* Once the connection is established an onConnectionComplete in the event handler
* will be called.
*
* @param peerAddressType
* @param peerAddress
* @param connectionParams
*
* @return BLE_ERROR_NONE if connection establishment procedure is started
* successfully. The connectionCallChain (if set) is invoked upon
* a connection event.
*/
virtual ble_error_t connect(
target_peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ConnectionParameters &connectionParams
);
/** Cancel the connection attempt. This is not guaranteed to succeed. As a result
* onConnectionComplete in the event handler will be called. Check the success parameter
* to see if the connection was created.
*
* @return BLE_ERROR_NONE if the connection attempt has been requested to be cancelled.
*/
virtual ble_error_t cancelConnect();
virtual ble_error_t 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(0),
conn_event_length_t maxConnectionEventLength = conn_event_length_t(0)
);
virtual ble_error_t manageConnectionParametersUpdateRequest(
bool userManageConnectionUpdateRequest
);
virtual ble_error_t 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(0),
conn_event_length_t maxConnectionEventLength = conn_event_length_t(0)
);
virtual ble_error_t rejectConnectionParametersUpdate(
connection_handle_t connectionHandle
);
/**
* Initiate a disconnection procedure.
*
* Once the disconnection procedure has completed a
* DisconnectionCallbackParams_t, the event is emitted to handlers that
* have been registered with onDisconnection().
*
* @param[in] reason Reason of the disconnection transmitted to the peer.
* @param[in] connectionHandle Handle of the connection to end.
*
* @return BLE_ERROR_NONE if the disconnection procedure successfully
* started.
*/
virtual ble_error_t disconnect(
connection_handle_t connectionHandle,
local_disconnection_reason_t reason
);
/**
* Read the PHY used by the transmitter and the receiver on a connection.
*
* Once the PHY has been read, it is reported back via the function onPhyRead
* of the event handler registered by the application.
*
* @param connection Handle of the connection for which the PHY being used is
* queried.
*
* @return BLE_ERROR_NONE if the read PHY procedure has been started or an
* appropriate error code.
*/
virtual ble_error_t readPhy(connection_handle_t connection);
/**
* Set the preferred PHYs to use in a connection.
*
* @param txPhys: Set of PHYs preferred for tx operations. If NULL then no
* preferred PHYs are set and the default value of the subsystem is used.
*
* @param rxPhys: Set of PHYs preferred for rx operations. If NULL then no
* preferred PHYs are set and the default value of the subsystem is used.
*
* @return BLE_ERROR_NONE if the preferences have been set or an appropriate
* error code.
*/
virtual ble_error_t setPreferredPhys(
const phy_set_t *txPhys,
const phy_set_t *rxPhys
);
/**
* Update the PHY used by a connection.
*
* Once the update process has been completed, it is reported back to the
* application via the function onPhyUpdateComplete of the event handler
* registered by the application.
*
* @param connection Handle of the connection to update.
*
* @param txPhys Set of PHYs preferred for tx operations. If NULL then the
* choice is up to the Bluetooth subsystem.
*
* @param rxPhys Set of PHYs preferred for rx operations. If NULL then the
* choice is up to the Bluetooth subsystem.
*
* @param codedSymbol Number of symbols used to code a bit when le coded is
* used. If the value is UNDEFINED then the choice is up to the Bluetooth
* subsystem.
*
* @return BLE_ERROR_NONE if the update PHY procedure has been successfully
* started or an error code.
*/
virtual ble_error_t setPhy(
connection_handle_t connection,
const phy_set_t *txPhys,
const phy_set_t *rxPhys,
coded_symbol_per_bit_t codedSymbol
);
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.
* This guards against mixed use of deprecated and nondeprecated API.
*/
virtual void useVersionOneAPI() const { }
/** Can only be called if use_deprecated_scan_api() hasn't been called.
* This guards against mixed use of deprecated and nondeprecated API.
*/
virtual void useVersionTwoAPI() const { }
/**
* Construct a Gap instance.
*/
Gap() : _eventHandler(NULL) { }
/**
* Event handler provided by the application.
*/
EventHandler *_eventHandler;
};
} // namespace ble
#endif //BLE_GAP_GAP_H

View File

@ -79,7 +79,7 @@ public:
/** @copydoc Gap::IsFeatureSupported
*/
bool isFeatureSupported(
ble::controller_supported_features_t feature
controller_supported_features_t feature
);
/** @copydoc Gap::getMaxAdvertisingSetNumber
@ -184,7 +184,7 @@ public:
*/
virtual ble_error_t createSync(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ble::address_t &peerAddress,
advertising_sid_t sid,
slave_latency_t maxPacketSkip,
sync_timeout_t timeout
@ -209,7 +209,7 @@ public:
*/
virtual ble_error_t addDeviceToPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ble::address_t &peerAddress,
advertising_sid_t sid
);
@ -217,7 +217,7 @@ public:
*/
virtual ble_error_t removeDeviceFromPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ble::address_t &peerAddress,
advertising_sid_t sid
);
@ -294,7 +294,7 @@ public:
* @see Gap::connect
*/
virtual ble_error_t connect(
ble::target_peer_address_type_t peerAddressType,
target_peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
const ConnectionParameters &connectionParams
);
@ -309,27 +309,27 @@ public:
);
virtual ble_error_t updateConnectionParameters(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervisionTimeout,
ble::conn_event_length_t minConnectionEventLength,
ble::conn_event_length_t maxConnectionEventLength
connection_handle_t connectionHandle,
conn_interval_t minConnectionInterval,
conn_interval_t maxConnectionInterval,
slave_latency_t slaveLatency,
supervision_timeout_t supervisionTimeout,
conn_event_length_t minConnectionEventLength,
conn_event_length_t maxConnectionEventLength
);
virtual ble_error_t acceptConnectionParametersUpdate(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervisionTimeout,
ble::conn_event_length_t minConnectionEventLength,
ble::conn_event_length_t maxConnectionEventLength
connection_handle_t connectionHandle,
conn_interval_t minConnectionInterval,
conn_interval_t maxConnectionInterval,
slave_latency_t slaveLatency,
supervision_timeout_t supervisionTimeout,
conn_event_length_t minConnectionEventLength,
conn_event_length_t maxConnectionEventLength
);
virtual ble_error_t rejectConnectionParametersUpdate(
ble::connection_handle_t connectionHandle
connection_handle_t connectionHandle
);
/**
@ -355,6 +355,11 @@ public:
CodedSymbolPerBit_t codedSymbol
);
virtual ble_error_t disconnect(
connection_handle_t connectionHandle,
local_disconnection_reason_t reason
);
/**
* @see Gap::disconnect
*/
@ -611,15 +616,15 @@ private:
virtual void on_read_phy(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
ble::phy_t tx_phy,
ble::phy_t rx_phy
phy_t tx_phy,
phy_t rx_phy
);
virtual void on_phy_update_complete(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
ble::phy_t tx_phy,
ble::phy_t rx_phy
phy_t tx_phy,
phy_t rx_phy
);
virtual void on_enhanced_connection_complete(
@ -702,7 +707,6 @@ private:
uint16_t connection_latency,
uint16_t supervision_timeout
);
private:
pal::EventQueue& _event_queue;
pal::Gap &_pal_gap;

View File

@ -44,7 +44,7 @@ public:
* @see GattClient::launchServiceDiscovery
*/
virtual ble_error_t launchServiceDiscovery(
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
ServiceDiscovery::ServiceCallback_t service_callback,
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
const UUID& matching_service_uuid,
@ -65,7 +65,7 @@ public:
* @see GattClient::read
*/
virtual ble_error_t read(
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
GattAttribute::Handle_t attribute_handle,
uint16_t offset
) const;
@ -75,7 +75,7 @@ public:
*/
virtual ble_error_t write(
GattClient::WriteOp_t cmd,
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
GattAttribute::Handle_t attribute_handle,
size_t length,
const uint8_t* value
@ -128,18 +128,18 @@ private:
struct WriteControlBlock;
struct DescriptorDiscoveryControlBlock;
ProcedureControlBlock* get_control_block(Gap::Handle_t connection);
const ProcedureControlBlock* get_control_block(Gap::Handle_t connection) const;
ProcedureControlBlock* get_control_block(connection_handle_t connection);
const ProcedureControlBlock* get_control_block(connection_handle_t connection) const;
void insert_control_block(ProcedureControlBlock* cb) const;
void remove_control_block(ProcedureControlBlock* cb) const;
void on_termination(Gap::Handle_t connection_handle);
void on_termination(connection_handle_t connection_handle);
void on_server_message_received(connection_handle_t, const pal::AttServerMessage&);
void on_server_response(connection_handle_t, const pal::AttServerMessage&);
void on_server_event(connection_handle_t, const pal::AttServerMessage&);
void on_transaction_timeout(connection_handle_t);
uint16_t get_mtu(Gap::Handle_t connection) const;
uint16_t get_mtu(connection_handle_t connection) const;
pal::GattClient* const _pal_client;
ServiceDiscovery::TerminationCallback_t _termination_callback;

View File

@ -68,7 +68,7 @@ public:
virtual ble_error_t purgeAllBondingState();
virtual ble_error_t generateWhitelistFromBondTable(
Gap::Whitelist_t *whitelist
::Gap::Whitelist_t *whitelist
) const;
////////////////////////////////////////////////////////////////////////////
@ -398,12 +398,12 @@ private:
*/
virtual void on_connected(
connection_handle_t connection,
Gap::Role_t role,
::Gap::Role_t role,
peer_address_type_t peer_address_type,
const BLEProtocol::AddressBytes_t peer_address,
BLEProtocol::AddressType_t local_address_type,
const BLEProtocol::AddressBytes_t local_address,
const Gap::ConnectionParams_t *connection_params
const ::Gap::ConnectionParams_t *connection_params
);
/**
@ -415,7 +415,7 @@ private:
*/
virtual void on_disconnected(
connection_handle_t connection,
Gap::DisconnectionReason_t reason
::Gap::DisconnectionReason_t reason
);
/**

View File

@ -70,271 +70,7 @@ Gap::PeerAddressType_t convert_legacy_address_type(
}
}
}
uint8_t Gap::getMaxAdvertisingSetNumber()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 1;
}
uint8_t Gap::getMaxAdvertisingDataLength()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 0x1F;
}
ble_error_t Gap::createAdvertisingSet(
ble::advertising_handle_t *handle,
const ble::AdvertisingParameters &parameters
)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::destroyAdvertisingSet(ble::advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingParameters(
ble::advertising_handle_t handle,
const ble::AdvertisingParameters &params
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingPayload(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> payload,
bool minimiseFragmentation
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingScanResponse(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> response,
bool minimiseFragmentation
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::startAdvertising(
ble::advertising_handle_t handle,
ble::adv_duration_t maxDuration,
uint8_t maxEvents
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::stopAdvertising(ble::advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
bool Gap::isAdvertisingActive(ble::advertising_handle_t handle) {
return false;
}
ble_error_t Gap::setPeriodicAdvertisingParameters(
ble::advertising_handle_t handle,
ble::periodic_interval_t periodicAdvertisingIntervalMin,
ble::periodic_interval_t periodicAdvertisingIntervalMax,
bool advertiseTxPower
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setPeriodicAdvertisingPayload(
ble::advertising_handle_t handle,
mbed::Span<uint8_t> payload
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::startPeriodicAdvertising(ble::advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::stopPeriodicAdvertising(ble::advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
bool Gap::isPeriodicAdvertisingActive(ble::advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return false;
}
ble_error_t Gap::setScanParameters(const ble::ScanParameters& params)
{
useVersionTwoAPI();
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
};
ble_error_t Gap::startScan(
ble::duplicates_filter_t filtering,
ble::scan_duration_t duration,
ble::scan_period_t period
) {
useVersionTwoAPI();
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
};
ble_error_t Gap::createSync(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
uint8_t sid,
ble::slave_latency_t maxPacketSkip,
ble::sync_timeout_t timeout
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::createSync(
ble::slave_latency_t maxPacketSkip,
ble::sync_timeout_t timeout
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::cancelCreateSync()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::terminateSync(ble::periodic_sync_handle_t handle) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::addDeviceToPeriodicAdvertiserList(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
ble::advertising_sid_t sid
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::removeDeviceFromPeriodicAdvertiserList(
ble::peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
ble::advertising_sid_t sid
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::clearPeriodicAdvertiserList()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
uint8_t Gap::getMaxPeriodicAdvertiserListSize()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 0;
}
ble_error_t Gap::connect(
ble::target_peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
const ble::ConnectionParameters &connectionParams
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::cancelConnect() {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::updateConnectionParameters(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervision_timeout,
ble::conn_event_length_t minConnectionEventLength,
ble::conn_event_length_t maxConnectionEventLength
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::manageConnectionParametersUpdateRequest(
bool userManageConnectionUpdateRequest
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::acceptConnectionParametersUpdate(
ble::connection_handle_t connectionHandle,
ble::conn_interval_t minConnectionInterval,
ble::conn_interval_t maxConnectionInterval,
ble::slave_latency_t slaveLatency,
ble::supervision_timeout_t supervision_timeout,
ble::conn_event_length_t minConnectionEventLength,
ble::conn_event_length_t maxConnectionEventLength
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::rejectConnectionParametersUpdate(
ble::connection_handle_t connectionHandle
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::disconnect(
ble::connection_handle_t connectionHandle,
ble::local_disconnection_reason_t reason
) {
// Forward to the old implementation for now.
return disconnect(connectionHandle, (Gap::DisconnectionReason_t) reason.value());
}
ble_error_t Gap::readPhy(ble::connection_handle_t connection)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setPreferredPhys(
const ble::phy_set_t *txPhys,
const ble::phy_set_t *rxPhys
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setPhy(
ble::connection_handle_t connection,
const ble::phy_set_t *txPhys,
const ble::phy_set_t *rxPhys,
ble::coded_symbol_per_bit_t codedSymbol
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
} // end of anonymous namespace
uint8_t Gap::getMaxWhitelistSize(void) const
{

View File

@ -0,0 +1,286 @@
/* 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 {
uint8_t Gap::getMaxAdvertisingSetNumber()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 1;
}
uint8_t Gap::getMaxAdvertisingDataLength()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 0x1F;
}
ble_error_t Gap::createAdvertisingSet(
advertising_handle_t *handle,
const AdvertisingParameters &parameters
)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::destroyAdvertisingSet(advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingParameters(
advertising_handle_t handle,
const AdvertisingParameters &params
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingPayload(
advertising_handle_t handle,
mbed::Span<uint8_t> payload,
bool minimiseFragmentation
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setAdvertisingScanResponse(
advertising_handle_t handle,
mbed::Span<uint8_t> response,
bool minimiseFragmentation
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::startAdvertising(
advertising_handle_t handle,
adv_duration_t maxDuration,
uint8_t maxEvents
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::stopAdvertising(advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
bool Gap::isAdvertisingActive(advertising_handle_t handle) {
return false;
}
ble_error_t Gap::setPeriodicAdvertisingParameters(
advertising_handle_t handle,
periodic_interval_t periodicAdvertisingIntervalMin,
periodic_interval_t periodicAdvertisingIntervalMax,
bool advertiseTxPower
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setPeriodicAdvertisingPayload(
advertising_handle_t handle,
mbed::Span<uint8_t> payload
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::startPeriodicAdvertising(advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::stopPeriodicAdvertising(advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
bool Gap::isPeriodicAdvertisingActive(advertising_handle_t handle)
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return false;
}
ble_error_t Gap::setScanParameters(const ScanParameters& params)
{
useVersionTwoAPI();
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
};
ble_error_t Gap::startScan(
duplicates_filter_t filtering,
scan_duration_t duration,
scan_period_t period
) {
useVersionTwoAPI();
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
};
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
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::createSync(
slave_latency_t maxPacketSkip,
sync_timeout_t timeout
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::cancelCreateSync()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::terminateSync(periodic_sync_handle_t handle) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::addDeviceToPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
advertising_sid_t sid
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::removeDeviceFromPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
advertising_sid_t sid
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::clearPeriodicAdvertiserList()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
uint8_t Gap::getMaxPeriodicAdvertiserListSize()
{
/* Requesting action from porter(s): override this API if this capability is supported. */
return 0;
}
ble_error_t Gap::connect(
target_peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ConnectionParameters &connectionParams
) {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::cancelConnect() {
/* Requesting action from porter(s): override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED;
}
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;
}
ble_error_t Gap::manageConnectionParametersUpdateRequest(
bool userManageConnectionUpdateRequest
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
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;
}
ble_error_t Gap::rejectConnectionParametersUpdate(
connection_handle_t connectionHandle
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::disconnect(
connection_handle_t connectionHandle,
local_disconnection_reason_t reason
) {
// Forward to the old implementation for now.
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::readPhy(connection_handle_t connection)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
ble_error_t Gap::setPreferredPhys(
const phy_set_t *txPhys,
const phy_set_t *rxPhys
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
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;
}
} // namespace ble

View File

@ -50,7 +50,7 @@ static const uint16_t advertising_interval_max = 0x4000;
static const uint16_t supervision_timeout_min = 0x000A;
static const uint16_t supervision_timeout_max = 0x0C80;
static const Gap::ConnectionParams_t default_connection_params = {
static const ::Gap::ConnectionParams_t default_connection_params = {
/* min conn interval */ 50,
/* max conn interval */ 100,
/* slave latency */ 0,
@ -96,7 +96,7 @@ static bool is_scan_params_valid(const GapScanningParams* params)
/*
* Return true if the connection parameters are valid or false otherwise.
*/
static bool is_connection_params_valid(const Gap::ConnectionParams_t* params)
static bool is_connection_params_valid(const ::Gap::ConnectionParams_t* params)
{
if (params == NULL) {
return false;
@ -139,7 +139,7 @@ static bool is_connection_params_valid(const Gap::ConnectionParams_t* params)
* timeout to be equal to 0xFFFF. When it is the case that value can be
* interpreted as "non specific".
*/
static bool is_preferred_connection_params_valid(const Gap::ConnectionParams_t* params)
static bool is_preferred_connection_params_valid(const ::Gap::ConnectionParams_t* params)
{
if (params == NULL) {
return false;
@ -286,7 +286,7 @@ static bool is_random_address(const BLEProtocol::AddressBytes_t address)
/*
* Check disconnection reason validity.
*/
static bool is_disconnection_reason_valid(Gap::DisconnectionReason_t reason)
static bool is_disconnection_reason_valid(::Gap::DisconnectionReason_t reason)
{
switch (reason) {
/**
@ -302,10 +302,10 @@ static bool is_disconnection_reason_valid(Gap::DisconnectionReason_t reason)
*/
// TODO Fix Disconnectionreason_t which expose invalid value
case Gap::REMOTE_USER_TERMINATED_CONNECTION:
case Gap::REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES:
case Gap::REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF:
case Gap::CONN_INTERVAL_UNACCEPTABLE:
case ::Gap::REMOTE_USER_TERMINATED_CONNECTION:
case ::Gap::REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES:
case ::Gap::REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF:
case ::Gap::CONN_INTERVAL_UNACCEPTABLE:
return true;
default:
return false;
@ -315,7 +315,7 @@ static bool is_disconnection_reason_valid(Gap::DisconnectionReason_t reason)
/*
* Return true if the whitelist in input is valid or false otherwise.
*/
static bool is_whitelist_valid(const Gap::Whitelist_t& whitelist)
static bool is_whitelist_valid(const ::Gap::Whitelist_t& whitelist)
{
if (whitelist.size > whitelist.capacity) {
return false;
@ -342,7 +342,7 @@ static bool is_whitelist_valid(const Gap::Whitelist_t& whitelist)
* Return true if device is present in the whitelist.
*/
static bool is_in_whitelist(
const BLEProtocol::Address_t& device, const Gap::Whitelist_t& whitelist
const BLEProtocol::Address_t& device, const ::Gap::Whitelist_t& whitelist
) {
for (size_t i = 0; i < whitelist.size; ++i) {
const BLEProtocol::Address_t& potential_device = whitelist.addresses[i];
@ -446,7 +446,7 @@ GenericGap::~GenericGap()
}
bool GenericGap::isFeatureSupported(
ble::controller_supported_features_t feature
controller_supported_features_t feature
) {
return _pal_gap.is_feature_supported(feature);
}
@ -615,7 +615,7 @@ ble_error_t GenericGap::connect(
ble_error_t GenericGap::connect(
ble::target_peer_address_type_t peerAddressType,
target_peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
const ConnectionParameters &connectionParams
) {
@ -624,7 +624,7 @@ ble_error_t GenericGap::connect(
}
if (!is_extended_advertising_available()) {
ble::phy_set_t set(connectionParams.getPhySet());
phy_set_t set(connectionParams.getPhySet());
if (set.count() != 1 || set.get_1m() == false) {
return BLE_ERROR_INVALID_PARAM;
}
@ -633,9 +633,9 @@ ble_error_t GenericGap::connect(
return _pal_gap.extended_create_connection(
connectionParams.getFilterPolicy(),
connectionParams.getOwnAddressType(),
(ble::peer_address_type_t::type)peerAddressType.value(),
(peer_address_type_t::type)peerAddressType.value(),
peerAddress,
(ble::phy_set_t)connectionParams.getPhySet(),
(phy_set_t)connectionParams.getPhySet(),
connectionParams.getScanIntervalArray(),
connectionParams.getScanWindowArray(),
connectionParams.getMinConnectionIntervalArray(),
@ -700,7 +700,7 @@ ble_error_t GenericGap::acceptConnectionParametersUpdate(
}
ble_error_t GenericGap::rejectConnectionParametersUpdate(
ble::connection_handle_t connectionHandle
connection_handle_t connectionHandle
) {
return _pal_gap.reject_connection_parameter_request(
connectionHandle,
@ -741,8 +741,8 @@ ble_error_t GenericGap::setPhy(
void GenericGap::on_read_phy(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
ble::phy_t tx_phy,
ble::phy_t rx_phy
phy_t tx_phy,
phy_t rx_phy
) {
ble_error_t status = BLE_ERROR_NONE;
if (pal::hci_error_code_t::SUCCESS != hci_status) {
@ -757,8 +757,8 @@ void GenericGap::on_read_phy(
void GenericGap::on_phy_update_complete(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
ble::phy_t tx_phy,
ble::phy_t rx_phy
phy_t tx_phy,
phy_t rx_phy
) {
ble_error_t status = BLE_ERROR_NONE;
if (pal::hci_error_code_t::SUCCESS != hci_status) {
@ -770,6 +770,13 @@ void GenericGap::on_phy_update_complete(
}
}
ble_error_t GenericGap::disconnect(
connection_handle_t connectionHandle,
local_disconnection_reason_t reason
) {
return _pal_gap.disconnect(connectionHandle, reason);
}
ble_error_t GenericGap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
{
if (is_disconnection_reason_valid(reason) == false) {
@ -994,7 +1001,7 @@ ble_error_t GenericGap::setWhitelist(const Whitelist_t &whitelist)
ble_error_t GenericGap::setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode)
{
if (mode > Gap::ADV_POLICY_FILTER_ALL_REQS) {
if (mode > ::Gap::ADV_POLICY_FILTER_ALL_REQS) {
return BLE_ERROR_INVALID_PARAM;
}
@ -1006,7 +1013,7 @@ ble_error_t GenericGap::setScanningPolicyMode(ScanningPolicyMode_t mode)
{
useVersionOneAPI();
if (mode > Gap::SCAN_POLICY_FILTER_ALL_ADV) {
if (mode > ::Gap::SCAN_POLICY_FILTER_ALL_ADV) {
return BLE_ERROR_INVALID_PARAM;
}
@ -1016,7 +1023,7 @@ ble_error_t GenericGap::setScanningPolicyMode(ScanningPolicyMode_t mode)
ble_error_t GenericGap::setInitiatorPolicyMode(InitiatorPolicyMode_t mode)
{
if (mode > Gap::INIT_POLICY_FILTER_ALL_ADV) {
if (mode > ::Gap::INIT_POLICY_FILTER_ALL_ADV) {
return BLE_ERROR_INVALID_PARAM;
}
@ -1024,18 +1031,18 @@ ble_error_t GenericGap::setInitiatorPolicyMode(InitiatorPolicyMode_t mode)
return BLE_ERROR_NONE;
}
Gap::AdvertisingPolicyMode_t GenericGap::getAdvertisingPolicyMode(void) const
::Gap::AdvertisingPolicyMode_t GenericGap::getAdvertisingPolicyMode(void) const
{
return (AdvertisingPolicyMode_t) _advertising_filter_policy.value();
}
Gap::ScanningPolicyMode_t GenericGap::getScanningPolicyMode(void) const
::Gap::ScanningPolicyMode_t GenericGap::getScanningPolicyMode(void) const
{
useVersionOneAPI();
return (ScanningPolicyMode_t) _scanning_filter_policy.value();
}
Gap::InitiatorPolicyMode_t GenericGap::getInitiatorPolicyMode(void) const
::Gap::InitiatorPolicyMode_t GenericGap::getInitiatorPolicyMode(void) const
{
return (InitiatorPolicyMode_t) _initiator_policy_mode.value();
}
@ -1235,7 +1242,7 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams& params)
ble_error_t GenericGap::reset(void)
{
Gap::reset();
::Gap::reset();
_advertising_timeout.detach();
_scan_timeout.detach();
_pal_gap.clear_advertising_sets();
@ -1294,7 +1301,7 @@ void GenericGap::processDisconnectionEvent(
_eventHandler->onDisconnection(
DisconnectionEvent(
handle,
(ble::disconnection_reason_t::type) reason
(disconnection_reason_t::type) reason
)
);
}
@ -1320,7 +1327,7 @@ void GenericGap::process_scan_timeout()
if (err) {
// TODO: define the mechanism signaling the error
}
processTimeoutEvent(Gap::TIMEOUT_SRC_SCAN);
processTimeoutEvent(::Gap::TIMEOUT_SRC_SCAN);
}
void GenericGap::on_advertising_timeout()
@ -1338,7 +1345,7 @@ void GenericGap::process_advertising_timeout()
// Stop address rotation if required
set_random_address_rotation(false);
processTimeoutEvent(Gap::TIMEOUT_SRC_ADVERTISING);
processTimeoutEvent(::Gap::TIMEOUT_SRC_ADVERTISING);
}
void GenericGap::on_gap_event_received(const pal::GapEvent& e)
@ -1412,7 +1419,7 @@ void GenericGap::on_connection_complete(const pal::GapConnectionCompleteEvent& e
// event
// TODO: Define events in case of connection faillure
processTimeoutEvent(Gap::TIMEOUT_SRC_CONN);
processTimeoutEvent(::Gap::TIMEOUT_SRC_CONN);
return;
}
@ -1507,7 +1514,7 @@ void GenericGap::on_disconnection_complete(const pal::GapDisconnectionCompleteEv
if (e.status == pal::hci_error_code_t::SUCCESS) {
processDisconnectionEvent(
e.connection_handle,
(Gap::DisconnectionReason_t) e.reason
(::Gap::DisconnectionReason_t) e.reason
);
} else {
// TODO: define what to do in case of faillure
@ -2275,9 +2282,9 @@ void GenericGap::on_enhanced_connection_complete(
_eventHandler->onConnectionComplete(
ConnectionCompleteEvent(
(status == pal::hci_error_code_t::SUCCESS) ? BLE_ERROR_NONE : BLE_ERROR_INTERNAL_STACK_FAILURE,
(ble::connection_handle_t)connection_handle,
(connection_handle_t)connection_handle,
own_role,
(ble::peer_address_type_t::type)peer_address_type.value(),
(peer_address_type_t::type)peer_address_type.value(),
peer_address,
local_resolvable_private_address,
peer_resolvable_private_address,
@ -2321,7 +2328,7 @@ void GenericGap::on_extended_advertising_report(
advertising_sid,
tx_power,
rssi,
ble::periodic_interval_t(periodic_advertising_interval),
periodic_interval_t(periodic_advertising_interval),
(PeerAddressType_t::type)direct_address_type.value(),
(BLEProtocol::AddressBytes_t&)direct_address,
mbed::make_Span(data, data_length)
@ -2430,7 +2437,7 @@ void GenericGap::on_scan_request_received(
_eventHandler->onScanRequest(
ScanRequestEvent_t(
advertising_handle,
(ble::peer_address_type_t::type) scanner_address_type.value(),
(peer_address_type_t::type) scanner_address_type.value(),
address
)
);
@ -2586,8 +2593,8 @@ ble_error_t GenericGap::startScan(
}
ble_error_t GenericGap::createSync(
ble::peer_address_type_t peerAddressType,
const address_t &peerAddress,
peer_address_type_t peerAddressType,
const ble::address_t &peerAddress,
advertising_sid_t sid,
slave_latency_t maxPacketSkip,
sync_timeout_t timeout
@ -2655,7 +2662,7 @@ ble_error_t GenericGap::terminateSync(periodic_sync_handle_t handle)
ble_error_t GenericGap::addDeviceToPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ble::address_t &peerAddress,
advertising_sid_t sid
)
{
@ -2682,7 +2689,7 @@ ble_error_t GenericGap::addDeviceToPeriodicAdvertiserList(
ble_error_t GenericGap::removeDeviceFromPeriodicAdvertiserList(
peer_address_type_t peerAddressType,
const address_t &peerAddress,
const ble::address_t &peerAddress,
advertising_sid_t sid
)
{
@ -2744,7 +2751,7 @@ void GenericGap::useVersionTwoAPI() const
bool GenericGap::is_extended_advertising_available()
{
return isFeatureSupported(
ble::controller_supported_features_t::LE_EXTENDED_ADVERTISING
controller_supported_features_t::LE_EXTENDED_ADVERTISING
);
}

View File

@ -66,7 +66,7 @@ struct GenericGattClient::ProcedureControlBlock {
/*
* Base constructor for procedure control block.
*/
ProcedureControlBlock(procedure_type_t type, Gap::Handle_t handle) :
ProcedureControlBlock(procedure_type_t type, connection_handle_t handle) :
type(type), connection_handle(handle), next(NULL) { }
virtual ~ProcedureControlBlock() { }
@ -87,7 +87,7 @@ struct GenericGattClient::ProcedureControlBlock {
virtual void abort(GenericGattClient *client) = 0;
procedure_type_t type;
Gap::Handle_t connection_handle;
connection_handle_t connection_handle;
ProcedureControlBlock* next;
};
@ -97,7 +97,7 @@ struct GenericGattClient::ProcedureControlBlock {
*/
struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
DiscoveryControlBlock(
Gap::Handle_t handle,
connection_handle_t handle,
ServiceDiscovery::ServiceCallback_t service_callback,
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
UUID matching_service_uuid,
@ -307,7 +307,7 @@ struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
void terminate(GenericGattClient* client) {
// unknown error, terminate the procedure immediately
client->remove_control_block(this);
Gap::Handle_t handle = connection_handle;
connection_handle_t handle = connection_handle;
delete this;
client->on_termination(handle);
}
@ -356,7 +356,7 @@ struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
characteristic_t(
GattClient* client,
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
uint16_t decl_handle,
const ArrayView<const uint8_t> value
) : DiscoveredCharacteristic() {
@ -428,7 +428,7 @@ struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
struct GenericGattClient::ReadControlBlock : public ProcedureControlBlock {
ReadControlBlock(
Gap::Handle_t connection_handle, uint16_t attribute_handle, uint16_t offset
connection_handle_t connection_handle, uint16_t attribute_handle, uint16_t offset
) : ProcedureControlBlock(READ_PROCEDURE, connection_handle),
attribute_handle(attribute_handle),
offset(offset), current_offset(offset), data(NULL) {
@ -625,7 +625,7 @@ struct GenericGattClient::ReadControlBlock : public ProcedureControlBlock {
*/
struct GenericGattClient::WriteControlBlock : public ProcedureControlBlock {
WriteControlBlock(
Gap::Handle_t connection_handle, uint16_t attribute_handle,
connection_handle_t connection_handle, uint16_t attribute_handle,
uint8_t* data, uint16_t len
) : ProcedureControlBlock(WRITE_PROCEDURE, connection_handle),
attribute_handle(attribute_handle), len(len), offset(0), data(data),
@ -949,7 +949,7 @@ GenericGattClient::GenericGattClient(pal::GattClient* pal_client) :
}
ble_error_t GenericGattClient::launchServiceDiscovery(
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
ServiceDiscovery::ServiceCallback_t service_callback,
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
const UUID& matching_service_uuid,
@ -1030,7 +1030,7 @@ void GenericGattClient::terminateServiceDiscovery()
}
ble_error_t GenericGattClient::read(
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
GattAttribute::Handle_t attribute_handle,
uint16_t offset) const
{
@ -1073,7 +1073,7 @@ ble_error_t GenericGattClient::read(
ble_error_t GenericGattClient::write(
GattClient::WriteOp_t cmd,
Gap::Handle_t connection_handle,
connection_handle_t connection_handle,
GattAttribute::Handle_t attribute_handle,
size_t length,
const uint8_t* value
@ -1279,7 +1279,7 @@ void GenericGattClient::set_signing_event_handler(
_signing_event_handler = signing_event_handler;
}
void GenericGattClient::on_termination(Gap::Handle_t connection_handle) {
void GenericGattClient::on_termination(connection_handle_t connection_handle) {
if (_termination_callback) {
_termination_callback(connection_handle);
}
@ -1330,7 +1330,7 @@ void GenericGattClient::on_server_response(
void GenericGattClient::on_server_event(connection_handle_t connection, const AttServerMessage& message) {
GattHVXCallbackParams callbacks_params = {
(Gap::Handle_t) connection, 0
(connection_handle_t) connection, 0
};
switch (message.opcode) {
@ -1368,7 +1368,7 @@ void GenericGattClient::on_transaction_timeout(connection_handle_t connection) {
pcb->handle_timeout_error(this);
}
GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(Gap::Handle_t connection) {
GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(connection_handle_t connection) {
ProcedureControlBlock* it = control_blocks;
while (it && it->connection_handle != connection) {
it = it->next;
@ -1376,7 +1376,7 @@ GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(G
return it;
}
const GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(Gap::Handle_t connection) const {
const GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(connection_handle_t connection) const {
ProcedureControlBlock* it = control_blocks;
while (it && it->connection_handle != connection) {
it = it->next;
@ -1420,7 +1420,7 @@ void GenericGattClient::remove_control_block(ProcedureControlBlock* cb) const {
cb->next = NULL;
}
uint16_t GenericGattClient::get_mtu(Gap::Handle_t connection) const {
uint16_t GenericGattClient::get_mtu(connection_handle_t connection) const {
uint16_t result = 23;
if(_pal_client->get_mtu_size((connection_handle_t) connection, result) != BLE_ERROR_NONE) {
result = 23;

View File

@ -139,7 +139,7 @@ ble_error_t GenericSecurityManager::purgeAllBondingState(void) {
return BLE_ERROR_NONE;
}
ble_error_t GenericSecurityManager::generateWhitelistFromBondTable(Gap::Whitelist_t *whitelist) const {
ble_error_t GenericSecurityManager::generateWhitelistFromBondTable(::Gap::Whitelist_t *whitelist) const {
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
if (eventHandler) {
if (!whitelist) {
@ -1033,12 +1033,12 @@ void GenericSecurityManager::set_mitm_performed(connection_handle_t connection,
void GenericSecurityManager::on_connected(
connection_handle_t connection,
Gap::Role_t role,
::Gap::Role_t role,
peer_address_type_t peer_address_type,
const BLEProtocol::AddressBytes_t peer_address,
BLEProtocol::AddressType_t local_address_type,
const BLEProtocol::AddressBytes_t local_address,
const Gap::ConnectionParams_t *connection_params
const ::Gap::ConnectionParams_t *connection_params
) {
MBED_ASSERT(_db);
ControlBlock_t *cb = acquire_control_block(connection);
@ -1048,7 +1048,7 @@ void GenericSecurityManager::on_connected(
// setup the control block
cb->local_address = local_address;
cb->is_master = (role == Gap::CENTRAL);
cb->is_master = (role == ::Gap::CENTRAL);
// get the associated db handle and the distribution flags if any
cb->db_entry = _db->open_entry(peer_address_type, peer_address);
@ -1074,7 +1074,7 @@ void GenericSecurityManager::on_connected(
void GenericSecurityManager::on_disconnected(
connection_handle_t connection,
Gap::DisconnectionReason_t reason
::Gap::DisconnectionReason_t reason
) {
MBED_ASSERT(_db);
ControlBlock_t *cb = get_control_block(connection);

View File

@ -86,7 +86,7 @@ public:
* @see ::GattServer::read
*/
virtual ble_error_t read(
Gap::Handle_t connectionHandle,
connection_handle_t connectionHandle,
GattAttribute::Handle_t attributeHandle,
uint8_t buffer[], uint16_t *lengthP
);
@ -104,7 +104,7 @@ public:
* @see ::GattServer::write
*/
virtual ble_error_t write(
Gap::Handle_t connectionHandle,
connection_handle_t connectionHandle,
GattAttribute::Handle_t,
const uint8_t[],
uint16_t,
@ -122,7 +122,7 @@ public:
* @see ::GattServer::areUpdatesEnabled
*/
virtual ble_error_t areUpdatesEnabled(
Gap::Handle_t connectionHandle,
connection_handle_t connectionHandle,
const GattCharacteristic &characteristic,
bool *enabledP
);
@ -224,7 +224,7 @@ private:
GattCharacteristic* get_auth_char(uint16_t value_handle);
bool get_cccd_index_by_cccd_handle(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
bool get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t& idx) const;
bool is_update_authorized(Gap::Handle_t connection, GattAttribute::Handle_t value_handle);
bool is_update_authorized(connection_handle_t connection, GattAttribute::Handle_t value_handle);
struct alloc_block_t {
alloc_block_t* next;

View File

@ -553,7 +553,7 @@ ble_error_t GattServer::read(
}
ble_error_t GattServer::read(
Gap::Handle_t connection,
connection_handle_t connection,
GattAttribute::Handle_t att_handle,
uint8_t buffer[],
uint16_t *buffer_length
@ -652,7 +652,7 @@ ble_error_t GattServer::write(
}
ble_error_t GattServer::write(
Gap::Handle_t connection,
connection_handle_t connection,
GattAttribute::Handle_t att_handle,
const uint8_t buffer[],
uint16_t len,
@ -733,7 +733,7 @@ ble_error_t GattServer::areUpdatesEnabled(
}
ble_error_t GattServer::areUpdatesEnabled(
Gap::Handle_t connectionHandle,
connection_handle_t connectionHandle,
const GattCharacteristic &characteristic,
bool *enabled
) {
@ -1232,7 +1232,7 @@ bool GattServer::get_cccd_index_by_value_handle(GattAttribute::Handle_t char_han
}
bool GattServer::is_update_authorized(
Gap::Handle_t connection,
connection_handle_t connection,
GattAttribute::Handle_t value_handle
) {
GattCharacteristic* auth_char = get_auth_char(value_handle);