Merge pull request #12730 from LDong-Arm/gap_deprecation_cleanup

BLE Gap deprecation cleanup/rework
pull/12872/head
Martin Kojtal 2020-04-27 11:46:12 +02:00 committed by GitHub
commit 28ef7535e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 631 additions and 7125 deletions

View File

@ -465,12 +465,6 @@ private:
bool event_signaled;
};
/**
* @deprecated This type alias is retained for the sake of compatibility with
* older code. This will be dropped at some point.
*/
typedef BLE BLEDevice;
/**
* @namespace ble Entry namespace for all %BLE API definitions.
*/

View File

@ -240,17 +240,6 @@ public:
virtual const SecurityManager &getSecurityManager(void) const = 0;
#endif // BLE_FEATURE_SECURITY
/**
* Process pending events present in the vendor subsystem; then, put the MCU
* to sleep until an external source wakes it up.
*
* @attention This function is deprecated in the BLE class. It will be
* removed from this interface once it is removed from BLE.
*
* @see BLE::waitForEvent() BLE::processEvents()
*/
virtual void waitForEvent(void) = 0;
private:
// this class is not a value type.
// prohibit copy construction and copy assignement

View File

@ -1,158 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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 MBED_BLE_PROTOCOL_H__
#define MBED_BLE_PROTOCOL_H__
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
/**
* @addtogroup ble
* @{
* @addtogroup common
* @{
*/
/**
* Common namespace for types and constants used everywhere in BLE API.
*/
namespace BLEProtocol {
/**
* Container for the enumeration of BLE address types.
*
* @note Adding a struct to encapsulate the contained enumeration prevents
* polluting the BLEProtocol namespace with the enumerated values. It also
* allows type-aliases for the enumeration while retaining the enumerated
* values. i.e. doing:
*
* @code
* typedef AddressType AliasedType;
* @endcode
*
* would allow the use of AliasedType::PUBLIC in code.
*
* @note see Bluetooth Standard version 4.2 [Vol 6, Part B] section 1.3 .
*/
struct AddressType {
/**
* Address-types for Protocol addresses.
*/
enum Type {
/**
* Public device address.
*/
PUBLIC = 0,
/**
* Random static device address.
*
* @deprecated This enumeration value is not relevant anymore.
* Advertising reporting and the connection procedure should rely
* on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
* type of the random address.
*/
RANDOM_STATIC,
/**
* Private resolvable device address.
*
* @deprecated This enumeration value is not relevant anymore.
* Advertising reporting and the connection procedure should rely
* on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
* type of the random address.
*/
RANDOM_PRIVATE_RESOLVABLE,
/**
* Private non-resolvable device address.
*
* @deprecated This enumeration value is not relevant anymore.
* Advertising reporting and the connection procedure should rely
* on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
* type of the random address.
*/
RANDOM_PRIVATE_NON_RESOLVABLE
};
};
/**
* Alias for AddressType::Type
*/
typedef AddressType::Type AddressType_t;
/**
* Length (in octets) of the BLE MAC address.
*/
static const size_t ADDR_LEN = 6;
/**
* 48-bit address, in LSB format.
*/
typedef uint8_t AddressBytes_t[ADDR_LEN];
/**
* BLE address representation.
*
* It contains an address-type (::AddressType_t) and the address value
* (::AddressBytes_t).
*/
struct Address_t {
/**
* Construct an Address_t object with the supplied type and address.
*
* @param[in] typeIn The BLE address type.
* @param[in] addressIn The BLE address.
*
* @post type is equal to typeIn and address is equal to the content
* present in addressIn.
*/
Address_t(AddressType_t typeIn, const AddressBytes_t &addressIn) :
type(typeIn) {
std::copy(addressIn, addressIn + ADDR_LEN, address);
}
/**
* Empty constructor.
*
* @note The address constructed with the empty constructor is not
* valid.
*
* @post type is equal to PUBLIC and the address value is equal to
* 00:00:00:00:00:00
*/
Address_t(void) : type(), address() { }
/**
* Type of the BLE device address.
*/
AddressType_t type;
/**
* Value of the device address.
*/
AddressBytes_t address;
};
};
/**
* @}
* @}
*/
#endif /* MBED_BLE_PROTOCOL_H__ */

View File

@ -831,6 +831,70 @@ struct coded_symbol_per_bit_t :SafeEnum<coded_symbol_per_bit_t, uint8_t> {
SafeEnum<coded_symbol_per_bit_t, uint8_t>(value) { }
};
/**
* Representation of a whitelist of addresses.
*/
struct whitelist_t {
/**
* BLE address representation.
*
* It contains an address-type (peer_address_type_t) and the address value
* (address_t).
*/
struct entry_t {
/**
* Construct an entry_t object with the supplied type and address.
*
* @param[in] typeIn The peer address type.
* @param[in] addressIn The peer address.
*
* @post type is equal to typeIn and address is equal to the content
* present in addressIn.
*/
entry_t(peer_address_type_t typeIn, const address_t &addressIn) :
type(typeIn),
address(addressIn)
{ }
/**
* Empty constructor.
*
* @note The address constructed with the empty constructor is not
* valid.
*
* @post type is equal to PUBLIC and the address value is equal to
* 00:00:00:00:00:00
*/
entry_t(void) : type(), address() { }
/**
* Type of the peer address.
*/
peer_address_type_t type;
/**
* Value of the peer address.
*/
address_t address;
};
/**
* Pointer to the array of the addresses composing the whitelist.
*/
entry_t *addresses;
/**
* Number addresses in this whitelist.
*/
uint8_t size;
/**
* Capacity of the array holding the addresses.
*/
uint8_t capacity;
};
} // namespace ble
/**

File diff suppressed because it is too large Load Diff

View File

@ -1,928 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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 MBED_GAP_ADVERTISING_DATA__LEGACY_H__
#define MBED_GAP_ADVERTISING_DATA__LEGACY_H__
#include <stdint.h>
#include <string.h>
#include "blecommon.h"
/**
* @addtogroup ble
* @{
* @addtogroup gap
* @{
*/
#define GAP_ADVERTISING_DATA_MAX_PAYLOAD (31)
/**
* GAP advertising data builder.
*
* Advertising data are used by broadcaster or peripheral to advertise state
* about the device. This class offers the function to add and update states present
* in an advertisement payload.
*
* After construction, the advertising payload contained in the instance of
* GapAdvertisingData is empty. Adding new states and named fields can be
* achieved by invoking the function addData(), and updating existing state
* involves calling the function updateData().
*
* Fields present in the payload can be retrieved by a call to the function
* findField.
*
* This class includes shorthand for the most common fields:
* - FLAGS: addFlags().
* - APPEARANCE: addAppearance().
* - TX_POWER_LEVEL: addTxPower().
*
* @code
*
* Gap &gap;
*
* static const uint8_t device_name[] = "HRM";
*
* // construct an empty advertising payload
* GapAdvertisingData advertising_data;
*
* // set the flags of the advertising device
* advertising_data.addFlags(
* GapAdvertisingData::LE_GENERAL_DISCOVERABLE |
* GapAdvertisingData::BREDR_NOT_SUPPORTED
* );
*
* // set the advertised name of the device
* advertising_data.addData(
* GapAdvertisingData::COMPLETE_LOCAL_NAME,
* device_name,
* sizeof(device_name)
* );
*
* // update the advertising data of the gap payload
* gap.setAdvertisingPayload(advertising_data);
*
* @endcode
*
* @note See Bluetooth Specification 4.0 (Vol. 3), Part C, Sections 11 and 18
* for further information on advertising and scan response data.
*
* @par Advertising and Scan Response Payloads
* Advertising data and scan response data are organized around a set of
* data types called 'AD types' in Bluetooth 4.0 (see the Bluetooth Core
* Specification v4.0, Vol. 3, Part C, Sections 11 and 18).
*
* @par
* Each AD type has its own standardized assigned number, as
* the Bluetooth SIG defines:
* https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile.
*
* @par
* For convenience, all appropriate AD types are encapsulated in
* GapAdvertisingData::DataType.
*
* @par
* Before the AD Types and their payload (if any) can be inserted into
* the advertising or scan response frames, they need to be formatted as
* follows:
*
* @li @c Record length (1 byte).
* @li @c AD Type (1 byte).
* @li @c AD payload (optional; only present if record length > 1).
*
* @par
* This class takes care of properly formatting the payload, performs
* some basic checks on the payload length and tries to avoid common
* errors such as adding an exclusive AD field twice in the advertising
* or scan response payload.
*
* @deprecated Use AdvertisingData instead.
* This version provides the buffer backing for the advertising data
* but it's only big enough for legacy advertising.
*/
class GapAdvertisingData
{
public:
/*!
* List of standard Advertising Data types.
*
* These AD types are used to describe the capabilities of the peripheral
* and are inserted inside the advertising or scan response payloads.
*
* @par Source
*
* @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18.
* @li @c https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile.
*/
enum DataType_t {
/**
* Flags, refer to GapAdvertisingData::Flags_t.
*/
FLAGS = 0x01,
/**
* Incomplete list of 16-bit Service IDs.
*/
INCOMPLETE_LIST_16BIT_SERVICE_IDS = 0x02,
/**
* Complete list of 16-bit Service IDs.
*/
COMPLETE_LIST_16BIT_SERVICE_IDS = 0x03,
/**
* Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0).
*/
INCOMPLETE_LIST_32BIT_SERVICE_IDS = 0x04,
/**
* Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0).
*/
COMPLETE_LIST_32BIT_SERVICE_IDS = 0x05,
/**
* Incomplete list of 128-bit Service IDs.
*/
INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06,
/**
* Complete list of 128-bit Service IDs.
*/
COMPLETE_LIST_128BIT_SERVICE_IDS = 0x07,
/**
* Shortened Local Name.
*/
SHORTENED_LOCAL_NAME = 0x08,
/**
* Complete Local Name.
*/
COMPLETE_LOCAL_NAME = 0x09,
/**
* TX Power Level (in dBm).
*/
TX_POWER_LEVEL = 0x0A,
/**
* Device ID.
*/
DEVICE_ID = 0x10,
/**
* Slave Connection Interval Range.
*/
SLAVE_CONNECTION_INTERVAL_RANGE = 0x12,
/**
* List of 128-bit service UUIDs the device is looking for.
*/
LIST_128BIT_SOLICITATION_IDS = 0x15,
/**
* Service Data.
*/
SERVICE_DATA = 0x16,
/**
* Appearance, refer to GapAdvertisingData::Appearance_t.
*/
APPEARANCE = 0x19,
/**
* Advertising Interval.
*/
ADVERTISING_INTERVAL = 0x1A,
/**
* Manufacturer Specific Data.
*/
MANUFACTURER_SPECIFIC_DATA = 0xFF
};
/**
* Alias for GapAdvertisingData::DataType_t.
*
* @deprecated Future releases will drop this type alias.
*/
typedef enum DataType_t DataType;
/**
* Enumeration of allowed flags for DataType_t::FLAGS.
*
* @note DataType_t::FLAGS may contain several flags that the bitwise
* and operator (ex.LE_GENERAL_DISCOVERABLE & BREDR_NOT_SUPPORTED) assembled.
*
* @par Source
*
* @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 18.1.
*/
enum Flags_t {
/**
* Peripheral device is discoverable for a limited period of time.
*/
LE_LIMITED_DISCOVERABLE = 0x01,
/**
* Peripheral device is discoverable at any moment.
*/
LE_GENERAL_DISCOVERABLE = 0x02,
/**
* Peripheral device is LE only and does not support Bluetooth Enhanced
* DataRate.
*/
BREDR_NOT_SUPPORTED = 0x04,
/**
* Not relevant - dual mode only.
*/
SIMULTANEOUS_LE_BREDR_C = 0x08,
/**
* Not relevant - dual mode only.
*/
SIMULTANEOUS_LE_BREDR_H = 0x10
};
/**
* Alias for GapAdvertisingData::Flags_t.
*
* @deprecated Future releases will drop this type alias.
*/
typedef enum Flags_t Flags;
/**
* Enumeration of values for the DataType_t::APPEARANCE.
*
* These values describe the physical shape or appearance of the device.
*
* @par Source
*
* @li @c Bluetooth Core Specification Supplement, Part A, Section 1.12.
* @li @c Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 12.2.
* @li @c https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml.
*/
enum Appearance_t {
/**
* Unknown or unspecified appearance type.
*/
UNKNOWN = 0,
/**
* Generic Phone.
*/
GENERIC_PHONE = 64,
/**
* Generic Computer.
*/
GENERIC_COMPUTER = 128,
/**
* Generic Watch.
*/
GENERIC_WATCH = 192,
/**
* Sports Watch.
*/
WATCH_SPORTS_WATCH = 193,
/**
* Generic Clock.
*/
GENERIC_CLOCK = 256,
/**
* Generic Display.
*/
GENERIC_DISPLAY = 320,
/**
* Generic Remote Control.
*/
GENERIC_REMOTE_CONTROL = 384,
/**
* Generic Eye Glasses.
*/
GENERIC_EYE_GLASSES = 448,
/**
* Generic Tag.
*/
GENERIC_TAG = 512,
/**
* Generic Keyring.
*/
GENERIC_KEYRING = 576,
/**
* Generic Media Player.
*/
GENERIC_MEDIA_PLAYER = 640,
/**
* Generic Bar Code Scanner.
*/
GENERIC_BARCODE_SCANNER = 704,
/**
* Generic Thermometer.
*/
GENERIC_THERMOMETER = 768,
/**
* Ear Thermometer.
*/
THERMOMETER_EAR = 769,
/**
* Generic Heart Rate Sensor.
*/
GENERIC_HEART_RATE_SENSOR = 832,
/**
* Belt Heart Rate Sensor.
*/
HEART_RATE_SENSOR_HEART_RATE_BELT = 833,
/**
* Generic Blood Pressure.
*/
GENERIC_BLOOD_PRESSURE = 896,
/**
* Arm Blood Pressure.
*/
BLOOD_PRESSURE_ARM = 897,
/**
* Wrist Blood Pressure.
*/
BLOOD_PRESSURE_WRIST = 898,
/**
* Human Interface Device (HID).
*/
HUMAN_INTERFACE_DEVICE_HID = 960,
/**
* Keyboard.
*/
KEYBOARD = 961,
/**
* Mouse.
*/
MOUSE = 962,
/**
* Joystick.
*/
JOYSTICK = 963,
/**
* Gamepad.
*/
GAMEPAD = 964,
/**
* Digitizer Tablet.
*/
DIGITIZER_TABLET = 965,
/**
* Card Reader.
*/
CARD_READER = 966,
/**
* Digital Pen.
*/
DIGITAL_PEN = 967,
/**
* Bar Code Scanner.
*/
BARCODE_SCANNER = 968,
/**
* Generic Glucose Meter.
*/
GENERIC_GLUCOSE_METER = 1024,
/**
* Generic Running/Walking Sensor.
*/
GENERIC_RUNNING_WALKING_SENSOR = 1088,
/**
* In Shoe Running/Walking Sensor.
*/
RUNNING_WALKING_SENSOR_IN_SHOE = 1089,
/**
* On Shoe Running/Walking Sensor.
*/
RUNNING_WALKING_SENSOR_ON_SHOE = 1090,
/**
* On Hip Running/Walking Sensor.
*/
RUNNING_WALKING_SENSOR_ON_HIP = 1091,
/**
* Generic Cycling.
*/
GENERIC_CYCLING = 1152,
/**
* Cycling Computer.
*/
CYCLING_CYCLING_COMPUTER = 1153,
/**
* Cycling Speed Sensor.
*/
CYCLING_SPEED_SENSOR = 1154,
/**
* Cycling Cadence Sensor.
*/
CYCLING_CADENCE_SENSOR = 1155,
/**
* Cycling Power Sensor.
*/
CYCLING_POWER_SENSOR = 1156,
/**
* Cycling Speed and Cadence Sensor.
*/
CYCLING_SPEED_AND_CADENCE_SENSOR = 1157,
/**
* Generic Pulse Oximeter.
*/
PULSE_OXIMETER_GENERIC = 3136,
/**
* Fingertip Pulse Oximeter.
*/
PULSE_OXIMETER_FINGERTIP = 3137,
/**
* Wrist Worn Pulse Oximeter.
*/
PULSE_OXIMETER_WRIST_WORN = 3138,
/**
* Generic Weight Scale.
*/
GENERIC_WEIGHT_SCALE = 3200,
/**
* Generic Outdoor.
*/
OUTDOOR_GENERIC = 5184,
/**
* Outdoor Location Display Device.
*/
OUTDOOR_LOCATION_DISPLAY_DEVICE = 5185,
/**
* Outdoor Location and Navigation Display Device.
*/
OUTDOOR_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE = 5186,
/**
* Outdoor Location Pod.
*/
OUTDOOR_LOCATION_POD = 5187,
/**
* Outdoor Location and Navigation Pod.
*/
OUTDOOR_LOCATION_AND_NAVIGATION_POD = 5188
};
/**
* Alias for GapAdvertisingData::Appearance_t.
*
* @deprecated Future releases will drop this type alias.
*/
typedef enum Appearance_t Appearance;
/**
* Construct a GapAdvertising instance with an empty payload.
*/
GapAdvertisingData(void) :
_payload(),
_payloadLen(0),
_appearance(GENERIC_TAG) {
}
/**
* Adds a new field into the payload.
*
* If the supplied advertising data type is already present in the
* advertising payload, then the value is updated.
*
* @param[in] advDataType The type of the field to add.
* @param[in] payload Pointer to the value of the field to add.
* @param[in] len Size in bytes of the value to add.
*
* @return BLE_ERROR_NONE on success.
* @return BLE_ERROR_BUFFER_OVERFLOW if the new value causes the advertising
* buffer to overflow.
*
* @note When the specified data type is INCOMPLETE_LIST_16BIT_SERVICE_IDS,
* COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS,
* COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS,
* COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS, the
* supplied value is appended to the values present in the payload.
*/
ble_error_t addData(DataType_t advDataType, const uint8_t *payload, uint8_t len)
{
/* Find field */
uint8_t* field = findField(advDataType);
if (field) {
/* Field type already exists, either add to field or replace */
return addField(advDataType, payload, len, field);
} else {
/* Field doesn't exist, insert new */
return appendField(advDataType, payload, len);
}
}
/**
* Update a specific field in the advertising payload.
*
* @param[in] advDataType The type of the field to update.
* @param[in] payload Pointer to the updated value of the field.
* @param[in] len Size of the new value in bytes.
*
* @return BLE_ERROR_NONE returned on success.
* @return BLE_ERROR_UNSPECIFIED if the specified field is not found,
* @return BLE_ERROR_BUFFER_OVERFLOW if the new value causes the
* advertising buffer to overflow.
*/
ble_error_t updateData(DataType_t advDataType, const uint8_t *payload, uint8_t len)
{
/* Find field */
uint8_t* field = findField(advDataType);
if (field) {
/* Field type already exists, replace field contents */
return updateField(advDataType, payload, len, field);
} else {
/* field doesn't exist, return an error */
return BLE_ERROR_UNSPECIFIED;
}
}
/**
* Add device appearance in the advertising payload.
*
* @param[in] appearance The appearance to advertise.
*
* @return BLE_ERROR_NONE on success.
* @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
* advertising buffer to overflow.
*
* @note This call is equivalent to calling addData() with
* GapAdvertisingData::APPEARANCE as the field type.
*/
ble_error_t addAppearance(Appearance appearance = GENERIC_TAG)
{
_appearance = appearance;
return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
}
/**
* Add BLE flags in the advertising payload.
*
* @param[in] flags Bitfield describing the capability of the device. See
* allowed flags in Flags_t.
*
* @return BLE_ERROR_NONE on success.
* @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
* advertising buffer to overflow.
*
* @note This call is equivalent to calling addData() with
* GapAdvertisingData::FLAGS as the field type.
*/
ble_error_t addFlags(uint8_t flags = LE_GENERAL_DISCOVERABLE)
{
return addData(GapAdvertisingData::FLAGS, &flags, 1);
}
/**
* Add the advertising TX in the advertising payload.
*
* @param[in] txPower Transmission power level in dB.
*
* @return BLE_ERROR_NONE on success.
* @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
* advertising buffer to overflow.
*
* @note This call is equivalent to calling addData() with
* GapAdvertisingData::TX_POWER_LEVEL as the field type.
*/
ble_error_t addTxPower(int8_t txPower)
{
/* To Do: Basic error checking to make sure txPower is in range. */
return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
}
/**
* Clears the advertising data payload.
*
* @post getPayloadLen() returns 0.
*/
void clear(void)
{
memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
_payloadLen = 0;
}
/**
* Get the pointer to the advertising payload bytes.
*
* @return A pointer to the payload.
*/
const uint8_t *getPayload(void) const
{
return _payload;
}
/**
* Get the payload length.
*
* @return The payload length in bytes.
*/
uint8_t getPayloadLen(void) const
{
return _payloadLen;
}
/**
* Get the appearance set.
*
* If no value has been set, this function returns GENERIC_TAG.
*
* @return The appearance value set for this device.
*/
uint16_t getAppearance(void) const
{
return (uint16_t)_appearance;
}
/**
* Search advertisement data for a specific field.
*
* @param[in] type The type of the field to find.
*
* @return A pointer to the first element in the field if found. The first
* element being the length of the field followed by the value of the field.
* @return NULL if the field is not present in the payload.
*/
const uint8_t* findField(DataType_t type) const
{
/* Scan through advertisement data */
for (uint8_t idx = 0; idx < _payloadLen; ) {
uint8_t fieldType = _payload[idx + 1];
if (fieldType == type) {
return &_payload[idx];
}
/* Advance to next field */
idx += _payload[idx] + 1;
}
/* Field not found */
return NULL;
}
private:
/**
* Append advertising data based on the specified type.
*
* @param[in] advDataType Type of the new data.
* @param[in] payload Pointer to the data to be appended to the advertising
* payload.
* @param[in] len Length of the data pointed to by @p payload.
*
* @return BLE_ERROR_NONE on success.
* @return BLE_ERROR_BUFFER_OVERFLOW if the specified data would cause the
* advertising buffer to overflow.
*/
ble_error_t appendField(DataType advDataType, const uint8_t *payload, uint8_t len)
{
/* Make sure we don't exceed the 31-byte payload limit */
if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
return BLE_ERROR_BUFFER_OVERFLOW;
}
/* Field length. */
memset(&_payload[_payloadLen], len + 1, 1);
_payloadLen++;
/* Field ID. */
memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
_payloadLen++;
/* Payload. */
memcpy(&_payload[_payloadLen], payload, len);
_payloadLen += len;
return BLE_ERROR_NONE;
}
/**
* Search advertisement data for a specific field.
*
* @param[in] type The type of the field to find.
*
* @return A pointer to the first element in the field if found. The first
* element being the length of the field followed by the value of the field.
* @return NULL if the field is not present in the payload.
*/
uint8_t* findField(DataType_t type)
{
return const_cast<uint8_t*>(
static_cast<const GapAdvertisingData*>(this)->findField(type)
);
}
/**
* Update in place the value of a field in the advertising payload.
*
* @param[in] advDataType Type of the new data.
* @param[in] payload Pointer to the data to be added to the advertising
* payload.
* @param[in] len Length of the data pointed to by @p payload.
* @param[in] field Pointer to the field of type @p advDataType in the
* advertising buffer.
*
* @note When the specified AD type is INCOMPLETE_LIST_16BIT_SERVICE_IDS,
* COMPLETE_LIST_16BIT_SERVICE_IDS, INCOMPLETE_LIST_32BIT_SERVICE_IDS,
* COMPLETE_LIST_32BIT_SERVICE_IDS, INCOMPLETE_LIST_128BIT_SERVICE_IDS,
* COMPLETE_LIST_128BIT_SERVICE_IDS or LIST_128BIT_SOLICITATION_IDS, the
* supplied value is appended to the values previously added to the
* payload.
*
* @return BLE_ERROR_NONE on success.
*/
ble_error_t addField(
DataType_t advDataType,
const uint8_t *payload,
uint8_t len,
uint8_t* field
) {
ble_error_t result = BLE_ERROR_BUFFER_OVERFLOW;
switch(advDataType) {
/* These fields have the new data appended if there is sufficient space. */
case INCOMPLETE_LIST_16BIT_SERVICE_IDS:
case COMPLETE_LIST_16BIT_SERVICE_IDS:
case INCOMPLETE_LIST_32BIT_SERVICE_IDS:
case COMPLETE_LIST_32BIT_SERVICE_IDS:
case INCOMPLETE_LIST_128BIT_SERVICE_IDS:
case COMPLETE_LIST_128BIT_SERVICE_IDS:
case LIST_128BIT_SOLICITATION_IDS: {
/* Check if data fits */
if ((_payloadLen + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
/*
* Make room for new field by moving the remainder of the
* advertisement payload "to the right" starting after the
* TYPE field.
*/
uint8_t* end = &_payload[_payloadLen];
while (&field[1] < end) {
end[len] = *end;
end--;
}
/* Insert new data */
for (uint8_t idx = 0; idx < len; idx++) {
field[2 + idx] = payload[idx];
}
/* Increment lengths */
field[0] += len;
_payloadLen += len;
result = BLE_ERROR_NONE;
}
break;
}
/* These fields are overwritten with the new value */
default: {
result = updateField(advDataType, payload, len, field);
break;
}
}
return result;
}
/**
* Update in place the value of a field in the advertising payload.
*
* @param[in] advDataType Type of the new data.
* @param[in] payload Pointer to the data to be added to the advertising
* payload.
* @param[in] len Length of the data pointed to by @p payload.
* @param[in] field Pointer to the field of type @p advDataType in the
* advertising buffer.
*
* @return BLE_ERROR_NONE on success.
*/
ble_error_t updateField(
DataType_t advDataType,
const uint8_t *payload,
uint8_t len,
uint8_t* field
) {
ble_error_t result = BLE_ERROR_BUFFER_OVERFLOW;
uint8_t dataLength = field[0] - 1;
/* New data has same length, do in-order replacement */
if (len == dataLength) {
for (uint8_t idx = 0; idx < dataLength; idx++) {
field[2 + idx] = payload[idx];
}
result = BLE_ERROR_NONE;
} else {
/* Check if data fits */
if ((_payloadLen - dataLength + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
/* Remove old field */
while ((field + dataLength + 2) < &_payload[_payloadLen]) {
*field = field[dataLength + 2];
field++;
}
/* Reduce length */
_payloadLen -= dataLength + 2;
/* Add new field */
result = appendField(advDataType, payload, len);
}
}
return result;
}
/**
* Advertising data buffer.
*/
uint8_t _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
/**
* Length of the data added to the advertising buffer.
*/
uint8_t _payloadLen;
/**
* Appearance value.
*/
uint16_t _appearance;
};
/**
* @}
* @}
*/
#endif /* ifndef MBED_GAP_ADVERTISING_DATA__LEGACY_H__ */

View File

@ -1,291 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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 MBED_GAP_ADVERTISING_PARAMS_H__
#define MBED_GAP_ADVERTISING_PARAMS_H__
/**
* @addtogroup ble
* @{
* @addtogroup gap
* @{
*/
/**
* Parameters defining the advertising process.
*
* Advertising parameters are a triplet of three value:
* - The Advertising mode modeled after AdvertisingType_t. It defines
* if the device is connectable and scannable. This value can be set at
* construction time, updated with setAdvertisingType() and queried by
* getAdvertisingType().
* - Time interval between advertisement. It can be set at construction time,
* updated by setInterval() and obtained from getInterval().
* - Duration of the advertising process. As others, it can be set at
* construction time, modified by setTimeout() and retrieved by getTimeout().
*/
class GapAdvertisingParams {
public:
/**
* Minimum Advertising interval for connectable undirected and connectable
* directed events in 625us units.
*
* @note Equal to 20 ms.
*/
static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN = 0x0020;
/**
* Minimum Advertising interval for scannable and nonconnectable
* undirected events in 625us units.
*
* @note Equal to 100ms.
*/
static const unsigned GAP_ADV_PARAMS_INTERVAL_MIN_NONCON = 0x00A0;
/**
* Maximum Advertising interval in 625us units.
*
* @note Equal to 10.24s.
*/
static const unsigned GAP_ADV_PARAMS_INTERVAL_MAX = 0x4000;
/**
* Maximum advertising timeout allowed; in seconds.
*/
static const unsigned GAP_ADV_PARAMS_TIMEOUT_MAX = 0x3FFF;
/**
* Encapsulates the peripheral advertising modes.
*
* It determine how the device appears to other scanner and peripheral
* devices in the scanning range.
*/
enum AdvertisingType_t {
/**
* Device is connectable, scannable and doesn't expect connection from a
* specific peer.
*
* @see Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1.
*/
ADV_CONNECTABLE_UNDIRECTED,
/**
* Device is connectable and expects connection from a specific peer.
*
* @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2.
*/
ADV_CONNECTABLE_DIRECTED,
/**
* Device is scannable but not connectable.
*
* @see Vol 6, Part B, Section 2.3.1.4.
*/
ADV_SCANNABLE_UNDIRECTED,
/**
* Device is not connectable and not scannable.
*
* @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3.
*/
ADV_NON_CONNECTABLE_UNDIRECTED
};
/**
* Alias for GapAdvertisingParams::AdvertisingType_t.
*
* @deprecated Future releases will drop this type alias.
*/
typedef enum AdvertisingType_t AdvertisingType;
public:
/**
* Construct an instance of GapAdvertisingParams.
*
* @param[in] advType Type of advertising.
* @param[in] interval Time interval between two advertisement in units of
* 0.625ms.
* @param[in] timeout Duration in seconds of the advertising process. A
* value of 0 indicate that there is no timeout of the advertising process.
*
* @note If value in input are out of range, they will be normalized.
*/
GapAdvertisingParams(
AdvertisingType_t advType = ADV_CONNECTABLE_UNDIRECTED,
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
uint16_t timeout = 0
) :
_advType(advType),
_interval(interval),
_timeout(timeout)
{
/* Interval checks. */
if (_advType == ADV_CONNECTABLE_DIRECTED) {
/* Interval must be 0 in directed connectable mode. */
_interval = 0;
} else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
/* Min interval is slightly larger than in other modes. */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
} else {
/* Stay within interval limits. */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
}
/* Timeout checks. */
if (timeout) {
/* Stay within timeout limits. */
if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
_timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
}
}
}
/**
* Number of microseconds in 0.625 milliseconds.
*/
static const uint16_t UNIT_0_625_MS = 625;
/**
* Convert milliseconds to units of 0.625ms.
*
* @param[in] durationInMillis Number of milliseconds to convert.
*
* @return The value of @p durationInMillis in units of 0.625ms.
*/
static uint16_t MSEC_TO_ADVERTISEMENT_DURATION_UNITS(uint32_t durationInMillis)
{
return (durationInMillis * 1000) / UNIT_0_625_MS;
}
/**
* Convert units of 0.625ms to milliseconds.
*
* @param[in] gapUnits The number of units of 0.625ms to convert.
*
* @return The value of @p gapUnits in milliseconds.
*/
static uint16_t ADVERTISEMENT_DURATION_UNITS_TO_MS(uint16_t gapUnits)
{
return (gapUnits * UNIT_0_625_MS) / 1000;
}
/**
* Get the advertising type.
*
* @return The advertising type.
*/
AdvertisingType_t getAdvertisingType(void) const
{
return _advType;
}
/**
* Get the advertising interval in milliseconds.
*
* @return The advertisement interval (in milliseconds).
*/
uint16_t getInterval(void) const
{
return ADVERTISEMENT_DURATION_UNITS_TO_MS(_interval);
}
/**
* Get the advertisement interval in units of 0.625ms.
*
* @return The advertisement interval in advertisement duration units
* (0.625ms units).
*/
uint16_t getIntervalInADVUnits(void) const
{
return _interval;
}
/**
* Get the advertising timeout.
*
* @return The advertising timeout (in seconds).
*/
uint16_t getTimeout(void) const
{
return _timeout;
}
/**
* Update the advertising type.
*
* @param[in] newAdvType The new advertising type.
*/
void setAdvertisingType(AdvertisingType_t newAdvType)
{
_advType = newAdvType;
}
/**
* Update the advertising interval in milliseconds.
*
* @param[in] newInterval The new advertising interval in milliseconds.
*/
void setInterval(uint16_t newInterval)
{
_interval = MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newInterval);
}
/**
* Update the advertising timeout.
*
* @param[in] newTimeout The new advertising timeout (in seconds).
*
* @note 0 is a special value meaning the advertising process never ends.
*/
void setTimeout(uint16_t newTimeout)
{
_timeout = newTimeout;
}
private:
/**
* The advertising type.
*/
AdvertisingType_t _advType;
/**
* The advertising interval in ADV duration units (in other words, 0.625ms).
*/
uint16_t _interval;
/**
* The advertising timeout in seconds.
*/
uint16_t _timeout;
};
/**
* @}
* @}
*/
#endif /* ifndef MBED_GAP_ADVERTISING_PARAMS_H__ */

View File

@ -1,50 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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 MBED_GAP_EVENTS_H__
#define MBED_GAP_EVENTS_H__
#include "blecommon.h"
/// @cond INVALID_SECTIONS
/*!
\brief
The base class used to abstract away the callback events that can be
triggered with the GAP.
@deprecated Do not use; it is not used by BLE API.
*/
class GapEvents
{
public:
/*!
\brief
Identifies GAP events generated by the radio HW when an event
callback occurs.
@deprecated Do not use; it is not used by BLE API.
*/
typedef enum gapEvent_e {
GAP_EVENT_TIMEOUT = 1, /**< Advertising timed out before a connection could be established. */
GAP_EVENT_CONNECTED = 2, /**< A connection was established with a central device. */
GAP_EVENT_DISCONNECTED = 3 /**< A connection was closed or lost with a central device. */
} gapEvent_t;
};
/// @endcond
#endif // ifndef MBED_GAP_EVENTS_H__

View File

@ -1,241 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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 MBED_GAP_SCANNING_PARAMS_H__
#define MBED_GAP_SCANNING_PARAMS_H__
/**
* @addtogroup ble
* @{
* @addtogroup gap
* @{
*/
/**
* Parameters defining the scan process.
*
* Four distinct parameters define the scan procedure:
* - Scan window: Period during which the scanner listens to advertising
* channels. That value is in the range of 2.5ms to 10.24s. This value
* can be set at construction time, updated by calling setWindow() and
* retrieved by invoking getWindow().
*
* - Scan interval: Interval between the start of two consecutive scan windows.
* That value shall be greater or equal to the scan window value. The
* maximum allowed value is 10.24ms. The scan interval value can be set at
* construction time, updated with a call to setInterval() and queried by a
* call to getInterval().
*
* - Timeout: The duration of the scan procedure if any. It can be set at
* construction time, updated with setTimeout() and obtained from
* getTimeout().
*
* - Active scanning: If set, then the scanner sends scan requests to a scannable
* or connectable advertiser. Advertisers may respond to the scan request
* by a scan response containing the scan response payload. If not set, then
* the scanner does not send any request. This flag is set at construction
* time, may be updated with the help of setActiveScanning() and retrieved
* by getActiveScanning().
*
* @note If the scan window's duration is equal to the scan interval, then the
* device listens continuously during the scan procedure.
*/
class GapScanningParams {
public:
/**
* Minimum Scan interval in 625us units - 2.5ms.
*/
static const unsigned SCAN_INTERVAL_MIN = 0x0004;
/**
* Maximum Scan interval in 625us units - 10.24s.
*/
static const unsigned SCAN_INTERVAL_MAX = 0x4000;
/**
* Minimum Scan window in 625us units - 2.5ms.
*/
static const unsigned SCAN_WINDOW_MIN = 0x0004;
/**
* Maximum Scan window in 625us units - 10.24s.
*/
static const unsigned SCAN_WINDOW_MAX = 0x4000;
/**
* Minimum Scan duration in seconds.
*/
static const unsigned SCAN_TIMEOUT_MIN = 0x0001;
/**
* Maximum Scan duration in seconds.
*/
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF;
public:
/**
* Construct an instance of GapScanningParams.
*
* @param[in] interval Milliseconds interval between the start of two
* consecutive scan windows. The value passed is between the scan
* window value and 10.24 seconds.
*
* @param[in] window Milliseconds period during which the device
* listens to advertising channels. The value of the scan window is in
* the range of 2.5ms to 10.24s.
*
* @param[in] timeout Duration in seconds of the scan procedure. The special
* value 0 may be used when the scan procedure is not time bounded.
*
* @param[in] activeScanning If true, then the scanner sends scan requests to
* to scannable or connectable advertiser. Advertisers may respond to the
* scan request by a scan response containing the scan response payload. If
* false, the scanner does not send any request.
*
* @note If interval is equal to window
*/
GapScanningParams(
uint16_t interval = SCAN_INTERVAL_MAX,
uint16_t window = SCAN_WINDOW_MAX,
uint16_t timeout = 0,
bool activeScanning = false
);
/**
* Number of microseconds in 0.625 milliseconds.
*/
static const uint16_t UNIT_0_625_MS = 625;
/**
* Convert milliseconds to units of 0.625ms.
*
* @param[in] durationInMillis Milliseconds to convert.
*
* @return The value of @p durationInMillis in units of 0.625ms.
*/
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis)
{
return (durationInMillis * 1000) / UNIT_0_625_MS;
}
/**
* Update the scan interval.
*
* @param[in] newIntervalInMS New scan interval in milliseconds.
*
* @return BLE_ERROR_NONE if the new scan interval was set successfully.
*/
ble_error_t setInterval(uint16_t newIntervalInMS);
/**
* Update the scan window.
*
* @param[in] newWindowInMS New scan window in milliseconds.
*
* @return BLE_ERROR_NONE if the new scan window was set successfully.
*/
ble_error_t setWindow(uint16_t newWindowInMS);
/**
* Update the scan timeout.
*
* @param[in] newTimeout New scan timeout in seconds.
*
* @return BLE_ERROR_NONE if the new scan window was set successfully.
*/
ble_error_t setTimeout(uint16_t newTimeout);
/**
* Update the active scanning flag.
*
* @param[in] activeScanning New boolean value of active scanning.
*/
void setActiveScanning(bool activeScanning);
public:
/**
* Get the scan interval.
*
* @return the scan interval in units of 0.625ms.
*/
uint16_t getInterval(void) const
{
return _interval;
}
/**
* Get the scan window.
*
* @return the scan window in units of 0.625ms.
*/
uint16_t getWindow(void) const
{
return _window;
}
/**
* Get the scan timeout.
*
* @return The scan timeout in seconds.
*/
uint16_t getTimeout(void) const
{
return _timeout;
}
/**
* Check whether active scanning is set.
*
* @return True if active scanning is set, false otherwise.
*/
bool getActiveScanning(void) const
{
return _activeScanning;
}
private:
/**
* Scan interval in units of 625us (between 2.5ms and 10.24s).
*/
uint16_t _interval;
/**
* Scan window in units of 625us (between 2.5ms and 10.24s).
*/
uint16_t _window;
/**
* Scan timeout between 0x0001 and 0xFFFF in seconds; 0x0000 disables timeout.
*/
uint16_t _timeout;
/**
* Obtain the peer device's advertising data and (if possible) scanResponse.
*/
bool _activeScanning;
private:
/* Disallow copy constructor. */
GapScanningParams(const GapScanningParams &);
GapScanningParams& operator =(const GapScanningParams &in);
};
/**
* @}
* @}
*/
#endif /* ifndef MBED_GAP_SCANNING_PARAMS_H__ */

View File

@ -294,7 +294,7 @@ public:
*
* @param[in] whitelist pointer to the whitelist filled with entries based on bonding information
*/
virtual void whitelistFromBondTable(::Gap::Whitelist_t* whitelist) {
virtual void whitelistFromBondTable(::ble::whitelist_t* whitelist) {
(void)whitelist;
}
@ -516,7 +516,7 @@ public:
*
* @retval BLE_ERROR_NONE On success, else an error code indicating reason for failure
*/
ble_error_t generateWhitelistFromBondTable(::Gap::Whitelist_t *whitelist) const;
ble_error_t generateWhitelistFromBondTable(::ble::whitelist_t *whitelist) const;
////////////////////////////////////////////////////////////////////////////
// Pairing
@ -884,7 +884,7 @@ protected:
ble_error_t purgeAllBondingState_(void);
ble_error_t generateWhitelistFromBondTable_(
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) const;
ble_error_t requestPairing_(

View File

@ -20,7 +20,6 @@
#include <algorithm>
#include "BLETypes.h"
#include "BLEProtocol.h"
#include "blecommon.h"
#include "SafeEnum.h"

View File

@ -20,7 +20,7 @@
#include "BLERoles.h"
#include "ble/common/StaticInterface.h"
#include "ble/BLETypes.h"
#include "ble/BLEProtocol.h"
#include "ble/CallChainOfFunctionPointersWithContext.h"
#include "ble/gap/AdvertisingDataBuilder.h"
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
#include "ble/gap/ConnectionParameters.h"
@ -279,6 +279,21 @@ class Gap : public StaticInterface<Impl, Gap> {
#endif
using StaticInterface<Impl, ::ble::interface::Gap>::impl;
/**
* Gap shutdown event handler.
*
* @see Gap::onShutdown().
*/
typedef FunctionPointerWithContext<const Gap *> GapShutdownCallback_t;
/**
* Callchain of gap shutdown event handler.
*
* @see Gap::onShutdown().
*/
typedef CallChainOfFunctionPointersWithContext<const Gap *>
GapShutdownCallbackChain_t;
public:
/**
@ -532,6 +547,53 @@ public:
}
};
/**
* Preferred connection parameter display in Generic Access Service.
*/
typedef struct {
/**
* Minimum interval between two connection events allowed for a
* connection.
*
* It shall be less than or equal to maxConnectionInterval. This value,
* in units of 1.25ms, is included in the range [0x0006 : 0x0C80].
*/
uint16_t minConnectionInterval;
/**
* Maximum interval between two connection events allowed for a
* connection.
*
* It shall be greater than or equal to minConnectionInterval. This
* value is in unit of 1.25ms and is in the range [0x0006 : 0x0C80].
*/
uint16_t maxConnectionInterval;
/**
* Number of connection events the slave can drop if it has nothing to
* communicate to the master.
*
* This value shall be in the range [0x0000 : 0x01F3].
*/
uint16_t slaveLatency;
/**
* Link supervision timeout for the connection.
*
* Time after which the connection is considered lost if the device
* didn't receive a packet from its peer.
*
* It is larger than:
* (1 + slaveLatency) * maxConnectionInterval * 2
*
* This value is in the range [0x000A : 0x0C80] and is in unit of
* 10 ms.
*
* @note maxConnectionInterval is in ms in the formulae above.
*/
uint16_t connectionSupervisionTimeout;
} PreferredConnectionParams_t;
/**
* Assign the event handler implementation that will be used by the gap
* module to signal events back to the application.
@ -1165,7 +1227,7 @@ public:
/**
* Default peripheral privacy configuration.
*/
static const central_privay_configuration_t
static const central_privacy_configuration_t
default_central_privacy_configuration;
@ -1239,7 +1301,7 @@ public:
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
*/
ble_error_t setCentralPrivacyConfiguration(
const central_privay_configuration_t *configuration
const central_privacy_configuration_t *configuration
);
/**
@ -1251,11 +1313,140 @@ public:
* @return BLE_ERROR_NONE in case of success or an appropriate error code.
*/
ble_error_t getCentralPrivacyConfiguration(
central_privay_configuration_t *configuration
central_privacy_configuration_t *configuration
);
#endif // BLE_ROLE_OBSERVER
#endif // BLE_FEATURE_PRIVACY
#if BLE_FEATURE_WHITELIST
/**
* Get the maximum size of the whitelist.
*
* @return Maximum size of the whitelist.
*/
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.
*/
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 non-resolvable addresses. 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.
*/
ble_error_t setWhitelist(const whitelist_t &whitelist);
#endif // BLE_FEATURE_WHITELIST
/**
* Fetch the current address and its type.
*
* @param[out] typeP Type of the current address set.
* @param[out] address Value of the current address.
*
* @note If privacy is enabled the device address may be unavailable to
* application code.
*
* @return BLE_ERROR_NONE on success.
*/
ble_error_t getAddress(
own_address_type_t &typeP,
address_t &address
);
/**
* Return the type of a random address.
*
* @param[in] address The random address to retrieve the type from. The
* address must be ordered in little endian.
*
* @param[out] addressType Type of the address to fill.
*
* @return BLE_ERROR_NONE in case of success or BLE_ERROR_INVALID_PARAM if
* the address in input was not identifiable as a random address.
*/
static ble_error_t getRandomAddressType(
const ble::address_t address,
ble::random_address_type_t *addressType
);
/**
* Reset the Gap instance.
*
* Reset process starts by notifying all registered shutdown event handlers
* that the Gap instance is about to be shut down. Then, it clears all Gap state
* of the associated object and then cleans the state present in the vendor
* implementation.
*
* This function is meant to be overridden in the platform-specific
* subclass. Nevertheless, the subclass only resets its
* state and not the data held in Gap members. This is achieved by a
* call to Gap::reset() from the subclass' reset() implementation.
*
* @return BLE_ERROR_NONE on success.
*
* @note Currently, a call to reset() does not reset the advertising and
* scan parameters to default values.
*/
ble_error_t reset(void);
/**
* Register a Gap shutdown event handler.
*
* The handler is called when the Gap instance is about to shut down.
* It is usually issued after a call to BLE::shutdown().
*
* @param[in] callback Shutdown event handler to register.
*
* @note To unregister a shutdown event handler, use
* onShutdown().detach(callback).
*/
void onShutdown(const GapShutdownCallback_t &callback);
/**
* Register a Gap shutdown event handler.
*
* @param[in] objPtr Instance used to invoke @p memberPtr.
* @param[in] memberPtr Shutdown event handler to register.
*/
template<typename T>
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *))
{
shutdownCallChain.add(objPtr, memberPtr);
}
/**
* Access the callchain of shutdown event handler.
*
* @note To register callbacks, use onShutdown().add(callback).
*
* @note To unregister callbacks, use onShutdown().detach(callback).
*
* @return A reference to the shutdown event callback chain.
*/
GapShutdownCallbackChain_t &onShutdown();
#if !defined(DOXYGEN_ONLY)
/*
* API reserved for the controller driver to set the random static address.
@ -1265,21 +1456,13 @@ public:
ble_error_t setRandomStaticAddress(const ble::address_t& address);
protected:
/** Can only be called if use_non_deprecated_scan_api() hasn't been called.
* This guards against mixed use of deprecated and nondeprecated API.
*/
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.
*/
void useVersionTwoAPI() const;
/**
* Construct a Gap instance.
*/
Gap();
/* ----------------- API to override in derived class -------------- */
bool isFeatureSupported_(controller_supported_features_t feature);
@ -1409,16 +1592,32 @@ protected:
peripheral_privacy_configuration_t *configuration
);
ble_error_t setCentralPrivacyConfiguration_(
const central_privay_configuration_t *configuration
const central_privacy_configuration_t *configuration
);
ble_error_t getCentralPrivacyConfiguration_(
central_privay_configuration_t *configuration
central_privacy_configuration_t *configuration
);
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
void useVersionOneAPI_() const;
void useVersionTwoAPI_() const;
uint8_t getMaxWhitelistSize_(void) const;
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
ble_error_t setWhitelist_(const whitelist_t &whitelist);
ble_error_t getAddress_(
own_address_type_t &typeP,
address_t &address
);
/* Note: Implementation must call the base class reset_ */
ble_error_t reset_(void);
protected:
/**
* Callchain containing all registered callback handlers for shutdown
* events.
*/
GapShutdownCallbackChain_t shutdownCallChain;
/**
* Event handler provided by the application.
*/

View File

@ -578,6 +578,12 @@ struct own_address_type_t : SafeEnum<own_address_type_t, uint8_t> {
own_address_type_t(type value) : SafeEnum(value)
{
}
/**
* Default initialization of own_address_type_t.
*/
own_address_type_t() :
SafeEnum<own_address_type_t, uint8_t>(PUBLIC) { }
};
/**
@ -854,7 +860,20 @@ struct disconnection_reason_t : SafeEnum<disconnection_reason_t, uint8_t> {
disconnection_reason_t(type value) : SafeEnum(value)
{
}
#if !defined(DOXYGEN_ONLY)
/**
* Construct a new instance of disconnection_reason_t.
*
* @param value The value of the local_disconnection_reason_t created.
*
* @note This should only be used for casting raw values from HCI.
*/
explicit disconnection_reason_t(uint8_t value) : SafeEnum(value)
{
}
};
#endif // !defined(DOXYGEN_ONLY)
/**
* Privacy Configuration of the peripheral role.
@ -901,9 +920,6 @@ struct peripheral_privacy_configuration_t {
PERFORM_AUTHENTICATION_PROCEDURE
};
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
typedef resolution_strategy_t ResolutionStrategy;
/**
* Connection strategy to use when a connection request contains a
* private resolvable address.
@ -917,7 +933,7 @@ struct peripheral_privacy_configuration_t {
* @note This configuration is also used when the local device operates as
* an observer.
*/
struct central_privay_configuration_t {
struct central_privacy_configuration_t {
/**
* Indicates if nonresolvable random address should be used when the
* central or observer sends scan request packets.
@ -954,9 +970,6 @@ struct central_privay_configuration_t {
RESOLVE_AND_FILTER
};
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Use resolution_strategy_t instead.")
typedef resolution_strategy_t ResolutionStrategy;
/**
* Resolution strategy applied to advertising packets received by the
* local device.

View File

@ -19,7 +19,6 @@
#include <algorithm>
#include "ble/BLEProtocol.h"
#include "ble/Gap.h"
#include "ble/pal/PalGap.h"
#include "ble/pal/GapEvents.h"
@ -28,7 +27,6 @@
#include "ble/pal/GenericAccessService.h"
#include "ble/pal/EventQueue.h"
#include "ble/pal/ConnectionEventMonitor.h"
#include "ble/pal/Deprecated.h"
#include "drivers/LowPowerTimeout.h"
#include "drivers/LowPowerTicker.h"
@ -49,7 +47,7 @@ template<
class ConnectionEventMonitorEventHandler
>
class GenericGap :
public interface::LegacyGap<
public interface::Gap<
GenericGap<TPalGap, PalSecurityManager, ConnectionEventMonitorEventHandler>
>,
public pal::ConnectionEventMonitor<
@ -60,38 +58,24 @@ class GenericGap :
>
{
// Typedef of base and companion classes .
typedef ::ble::interface::LegacyGap<GenericGap> LegacyGap;
typedef ::ble::interface::Gap<GenericGap> Gap;
typedef pal::ConnectionEventMonitor<ConnectionEventMonitorEventHandler> ConnectionEventMonitor;
typedef TPalGap<GenericGap> PalGap;
typedef pal::GapEventHandler<GenericGap> PalGapEventHandler;
// Friendship with base classes
friend LegacyGap;
friend Gap;
friend ConnectionEventMonitor;
friend pal::GapEventHandler<GenericGap>;
friend PalGap;
// Imports from LegacyGap
using LegacyGap::_eventHandler;
using LegacyGap::default_peripheral_privacy_configuration;
using LegacyGap::default_central_privacy_configuration;
using LegacyGap::state;
using Gap::_eventHandler;
using Gap::default_peripheral_privacy_configuration;
using Gap::default_central_privacy_configuration;
typedef typename LegacyGap::Address_t Address_t;
typedef typename LegacyGap::PeerAddressType_t PeerAddressType_t;
typedef typename LegacyGap::ConnectionParams_t ConnectionParams_t;
typedef typename LegacyGap::Handle_t Handle_t;
typedef typename LegacyGap::CodedSymbolPerBit_t CodedSymbolPerBit_t;
typedef typename LegacyGap::Whitelist_t Whitelist_t;
typedef typename LegacyGap::DisconnectionReason_t DisconnectionReason_t;
typedef typename LegacyGap::AdvertisingPolicyMode_t AdvertisingPolicyMode_t;
typedef typename LegacyGap::ScanningPolicyMode_t ScanningPolicyMode_t;
typedef typename LegacyGap::InitiatorPolicyMode_t InitiatorPolicyMode_t;
typedef typename LegacyGap::PeripheralPrivacyConfiguration_t PeripheralPrivacyConfiguration_t;
typedef typename LegacyGap::CentralPrivacyConfiguration_t CentralPrivacyConfiguration_t;
typedef typename LegacyGap::Role_t Role_t;
typedef typename ble::whitelist_t whitelist_t;
typedef typename Gap::PreferredConnectionParams_t PreferredConnectionParams_t;
// Imports from Gap
#if BLE_ROLE_BROADCASTER
@ -99,8 +83,6 @@ class GenericGap :
using ble::interface::Gap<GenericGap>::getMaxAdvertisingDataLength;
#endif // BLE_ROLE_BROADCASTER
using ble::interface::Gap<GenericGap>::isFeatureSupported;
using ble::interface::Gap<GenericGap>::useVersionOneAPI;
using ble::interface::Gap<GenericGap>::useVersionTwoAPI;
// Imports from PalGap EventHandler
using PalGapEventHandler::on_scan_timeout;
@ -298,14 +280,6 @@ public:
*/
uint8_t getMaxPeriodicAdvertiserListSize_();
/**
* @see Gap::setAddress
*/
ble_error_t setAddress_(
BLEProtocol::AddressType_t type,
const BLEProtocol::AddressBytes_t address
);
/**
* @see Gap::setRandomStaticAddress
*/
@ -315,55 +289,15 @@ public:
* @see Gap::getAddress
*/
ble_error_t getAddress_(
BLEProtocol::AddressType_t *type,
BLEProtocol::AddressBytes_t address
own_address_type_t &type,
address_t &address
);
/**
* @see Gap::getMinAdvertisingInterval
*/
uint16_t getMinAdvertisingInterval_() const;
/**
* @see Gap::getMinNonConnectableAdvertisingInterval
*/
uint16_t getMinNonConnectableAdvertisingInterval_() const;
/**
* @see Gap::getMaxAdvertisingInterval
*/
uint16_t getMaxAdvertisingInterval_() const;
/**
* @see Gap::stopAdvertising
*/
ble_error_t stopAdvertising_();
/**
* @see Gap::stopScan
*/
ble_error_t stopScan_();
/**
* @see Gap::connect
*/
ble_error_t connect_(
const BLEProtocol::AddressBytes_t peerAddr,
PeerAddressType_t peerAddrType,
const ConnectionParams_t *connectionParams,
const GapScanningParams *scanParams
);
/**
* @see Gap::connect
*/
ble_error_t connect_(
const BLEProtocol::AddressBytes_t peerAddr,
BLEProtocol::AddressType_t peerAddrType,
const ConnectionParams_t *connectionParams,
const GapScanningParams *scanParams
);
/**
* @see Gap::connect
*/
@ -409,7 +343,7 @@ public:
/**
* @see Gap::readPhy
*/
ble_error_t readPhy_(Handle_t connection);
ble_error_t readPhy_(connection_handle_t connection);
/**
* @see Gap::setPreferredPhys
@ -423,10 +357,10 @@ public:
* @see Gap::setPhy
*/
ble_error_t setPhy_(
Handle_t connection,
connection_handle_t connection,
const phy_set_t *txPhys,
const phy_set_t *rxPhys,
CodedSymbolPerBit_t codedSymbol
ble::coded_symbol_per_bit_t codedSymbol
);
ble_error_t disconnect_(
@ -434,71 +368,6 @@ public:
local_disconnection_reason_t reason
);
/**
* @see Gap::disconnect
*/
ble_error_t disconnect_(
Handle_t connectionHandle,
DisconnectionReason_t reason
);
/**
* @see Gap::disconnect
*/
ble_error_t disconnect_(DisconnectionReason_t reason);
/**
* @see Gap::updateConnectionParams
*/
ble_error_t updateConnectionParams_(
Handle_t handle,
const ConnectionParams_t *params
);
/**
* @see Gap::getPreferredConnectionParams
*/
ble_error_t getPreferredConnectionParams_(
ConnectionParams_t *params
);
/**
* @see Gap::setPreferredConnectionParams
*/
ble_error_t setPreferredConnectionParams_(
const ConnectionParams_t *params
);
/**
* @see Gap::setDeviceName
*/
ble_error_t setDeviceName_(const uint8_t *deviceName);
/**
* @see Gap::getDeviceName
*/
ble_error_t getDeviceName_(uint8_t *deviceName, unsigned *lengthP);
/**
* @see Gap::setAppearance
*/
ble_error_t setAppearance_(GapAdvertisingData::Appearance appearance);
/**
* @see Gap::getAppearance
*/
ble_error_t getAppearance_(GapAdvertisingData::Appearance *appearanceP);
/**
* @see Gap::setTxPower
*/
ble_error_t setTxPower_(int8_t txPower);
/**
* @see Gap::getPermittedTxPowerValues
*/
void getPermittedTxPowerValues_(const int8_t **valueArrayPP, size_t *countP);
/**
* @see Gap::getMaxWhitelistSize
*/
@ -507,126 +376,47 @@ public:
/**
* @see Gap::getWhitelist
*/
ble_error_t getWhitelist_(Whitelist_t &whitelist) const;
ble_error_t getWhitelist_(whitelist_t &whitelist) const;
/**
* @see Gap::setWhitelist
*/
ble_error_t setWhitelist_(const Whitelist_t &whitelist);
/**
* @see Gap::setAdvertisingPolicyMode
*/
ble_error_t setAdvertisingPolicyMode_(AdvertisingPolicyMode_t mode);
/**
* @see Gap::setScanningPolicyMode
*/
ble_error_t setScanningPolicyMode_(ScanningPolicyMode_t mode);
/**
* @see Gap::setInitiatorPolicyMode
*/
ble_error_t setInitiatorPolicyMode_(InitiatorPolicyMode_t mode);
/**
* @see Gap::getAdvertisingPolicyMode
*/
AdvertisingPolicyMode_t getAdvertisingPolicyMode_(void) const;
/**
* @see Gap::getScanningPolicyMode
*/
ScanningPolicyMode_t getScanningPolicyMode_(void) const;
/**
* @see Gap::getInitiatorPolicyMode
*/
InitiatorPolicyMode_t getInitiatorPolicyMode_(void) const;
/**
* @see Gap::startRadioScan
*/
ble_error_t startRadioScan_(const GapScanningParams &scanningParams);
/**
* @see Gap::initRadioNotification
*/
ble_error_t initRadioNotification_(void);
ble_error_t setWhitelist_(const whitelist_t &whitelist);
/**
* @see Gap::enablePrivacy
*/
ble_error_t enablePrivacy_(bool enable);
/**
* @see Gap::setPeripheralPrivacyConfiguration
*/
ble_error_t setPeripheralPrivacyConfiguration_(
const PeripheralPrivacyConfiguration_t *configuration
const peripheral_privacy_configuration_t *configuration
);
/**
* @see Gap::getPeripheralPrivacyConfiguration
*/
ble_error_t getPeripheralPrivacyConfiguration_(
PeripheralPrivacyConfiguration_t *configuration
peripheral_privacy_configuration_t *configuration
);
/**
* @see Gap::setCentralPrivacyConfiguration
*/
ble_error_t setCentralPrivacyConfiguration_(
const CentralPrivacyConfiguration_t *configuration
const central_privacy_configuration_t *configuration
);
/**
* @see Gap::getCentralPrivacyConfiguration
*/
ble_error_t getCentralPrivacyConfiguration_(
CentralPrivacyConfiguration_t *configuration
central_privacy_configuration_t *configuration
);
/**
* @see Gap::setAdvertisingData
*/
ble_error_t setAdvertisingData_(
const GapAdvertisingData &advData,
const GapAdvertisingData &scanResponse
ble_error_t getAddress(
own_address_type_t &typeP,
address_t &address
);
/**
* @see Gap::startAdvertising
*/
ble_error_t startAdvertising_(const GapAdvertisingParams &params);
static ble_error_t getRandomAddressType(
const ble::address_t address,
ble::random_address_type_t *addressType
);
/**
* @see Gap::reset
*/
ble_error_t reset_(void);
/**
* @copydoc ::Gap::processConnectionEvent
*/
void processConnectionEvent(
Handle_t handle,
Role_t role,
peer_address_type_t peerAddrType,
const BLEProtocol::AddressBytes_t peerAddr,
BLEProtocol::AddressType_t ownAddrType,
const BLEProtocol::AddressBytes_t ownAddr,
const ConnectionParams_t *connectionParams,
const uint8_t *peerResolvableAddr,
const uint8_t *localResolvableAddr
);
/**
* @copydoc ::Gap::processDisconnectionEvent
*/
void processDisconnectionEvent(
Handle_t handle,
DisconnectionReason_t reason
);
private:
ble_error_t setAdvertisingData(
@ -636,8 +426,6 @@ private:
bool scan_response
);
void process_scan_timeout();
void on_advertising_timeout();
void process_advertising_timeout();
@ -679,15 +467,11 @@ private:
void on_address_rotation_timeout();
void useVersionOneAPI_() const;
void useVersionTwoAPI_() const;
/* implements pal::Gap::EventHandler */
private:
void on_read_phy_(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
connection_handle_t connection_handle,
phy_t tx_phy,
phy_t rx_phy
);
@ -700,7 +484,7 @@ private:
void on_phy_update_complete_(
pal::hci_error_code_t hci_status,
Handle_t connection_handle,
connection_handle_t connection_handle,
phy_t tx_phy,
phy_t rx_phy
);
@ -794,16 +578,16 @@ private:
PalGap &_pal_gap;
pal::GenericAccessService &_gap_service;
PalSecurityManager &_pal_sm;
BLEProtocol::AddressType_t _address_type;
ble::own_address_type_t _address_type;
ble::address_t _address;
pal::initiator_policy_t _initiator_policy_mode;
pal::scanning_filter_policy_t _scanning_filter_policy;
pal::advertising_filter_policy_t _advertising_filter_policy;
mutable Whitelist_t _whitelist;
mutable whitelist_t _whitelist;
bool _privacy_enabled;
PeripheralPrivacyConfiguration_t _peripheral_privacy_configuration;
CentralPrivacyConfiguration_t _central_privacy_configuration;
peripheral_privacy_configuration_t _peripheral_privacy_configuration;
central_privacy_configuration_t _central_privacy_configuration;
ble::address_t _random_static_identity_address;
bool _random_address_rotating;
@ -864,9 +648,6 @@ private:
BitArray<MAX_ADVERTISING_SETS> _connectable_payload_size_exceeded;
BitArray<MAX_ADVERTISING_SETS> _set_is_connectable;
// deprecation flags
mutable bool _deprecated_scan_api_used : 1;
mutable bool _non_deprecated_scan_api_used : 1;
bool _user_manage_connection_parameter_requests : 1;
private:
@ -876,6 +657,8 @@ private:
);
bool is_extended_advertising_available();
void prepare_legacy_advertising_set();
};
} // namespace generic

View File

@ -101,7 +101,7 @@ public:
ble_error_t purgeAllBondingState_();
ble_error_t generateWhitelistFromBondTable_(
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) const;
////////////////////////////////////////////////////////////////////////////
@ -431,12 +431,11 @@ private:
*/
void on_connected_(
connection_handle_t connection,
::Gap::Role_t role,
connection_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
address_t peer_address,
own_address_type_t local_address_type,
address_t local_address
);
/**
@ -448,7 +447,7 @@ private:
*/
void on_disconnected_(
connection_handle_t connection,
::Gap::DisconnectionReason_t reason
disconnection_reason_t reason
);
/**

View File

@ -123,7 +123,7 @@ public:
SecurityEntryIdentityDbCb_t;
typedef mbed::Callback<void(Span<SecurityEntryIdentity_t>&, size_t count)>
IdentitylistDbCb_t;
typedef mbed::Callback<void(::Gap::Whitelist_t*)>
typedef mbed::Callback<void(::ble::whitelist_t*)>
WhitelistDbCb_t;
SecurityDb() : _local_sign_counter(0) { };
@ -567,7 +567,7 @@ public:
*/
virtual void get_whitelist(
WhitelistDbCb_t cb,
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) {
/*TODO: fill whitelist*/
cb(whitelist);
@ -582,7 +582,7 @@ public:
*/
virtual void generate_whitelist_from_bond_table(
WhitelistDbCb_t cb,
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) {
for (size_t i = 0; i < get_entry_count() && whitelist->size < whitelist->capacity; i++) {
entry_handle_t db_handle = get_entry_handle_by_index(i);
@ -597,16 +597,12 @@ public:
continue;
}
memcpy(
whitelist->addresses[whitelist->size].address,
identity->identity_address.data(),
sizeof(BLEProtocol::AddressBytes_t)
);
whitelist->addresses[whitelist->size].address = identity->identity_address;
if (identity->identity_address_is_public) {
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::PUBLIC;
whitelist->addresses[whitelist->size].type = peer_address_type_t::PUBLIC_IDENTITY;
} else {
whitelist->addresses[whitelist->size].type = BLEProtocol::AddressType::RANDOM_STATIC;
whitelist->addresses[whitelist->size].type = peer_address_type_t::RANDOM_STATIC_IDENTITY;
}
whitelist->size++;
@ -620,7 +616,7 @@ public:
*
* @param[in] whitelist
*/
virtual void set_whitelist(const ::Gap::Whitelist_t &whitelist) { };
virtual void set_whitelist(const ::ble::whitelist_t &whitelist) { };
/**
* Add a new entry to the whitelist in the NVM.

View File

@ -17,7 +17,6 @@
#ifndef MBED_BLE_CONNECTION_EVENT_MONITOR
#define MBED_BLE_CONNECTION_EVENT_MONITOR
#include "ble/BLEProtocol.h"
#include "ble/Gap.h"
#include "ble/BLETypes.h"
@ -51,12 +50,11 @@ public:
*/
void on_connected(
connection_handle_t connection,
::Gap::Role_t role,
connection_role_t role,
ble::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
address_t peer_address,
own_address_type_t local_address_type,
const address_t local_address
) {
self()->on_connected_(
connection,
@ -64,8 +62,7 @@ public:
peer_address_type,
peer_address,
local_address_type,
local_address,
connection_params
local_address
);
}
@ -77,7 +74,7 @@ public:
*/
void on_disconnected(
connection_handle_t connection,
::Gap::DisconnectionReason_t reason
ble::disconnection_reason_t reason
) {
self()->on_disconnected_(connection, reason);
}

View File

@ -228,7 +228,9 @@ struct hci_error_code_t : SafeEnum<hci_error_code_t, uint8_t> {
};
typedef ble::local_disconnection_reason_t disconnection_reason_t;
typedef ble::local_disconnection_reason_t local_disconnection_reason_t;
typedef ble::disconnection_reason_t disconnection_reason_t;
typedef ble::advertising_filter_policy_t advertising_filter_policy_t;

View File

@ -20,7 +20,6 @@
#include "GapTypes.h"
#include "ble/BLETypes.h"
#include "ble/blecommon.h"
#include "ble/GapAdvertisingData.h"
#include "ble/Gap.h"
namespace ble {
@ -45,84 +44,11 @@ struct GenericAccessService {
virtual ~GenericAccessService() { }
/**
* Acquire the length of the device name.
* The length can range from 0 (no device name) to 248 octets
*
* @param length The length of the device name currently stored in the GAP
* service.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
*
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
*/
virtual ble_error_t get_device_name_length(uint8_t& length) = 0;
/**
* Get the current device name.
* The result is stored in the array pass in input if the operation
* succeed. Prior to this call the length of the device name can be acquired
* with a call to get_device_name_length.
*
* @param The array which will host the device name
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
*
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
*/
virtual ble_error_t get_device_name(Span<uint8_t>& array) = 0;
/**
* Set the value of the device name characteristic exposed by the GAP GATT
* service.
*
* @param device_name The name of the device. If NULL the device name
* value has a length of 0.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
*
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
*/
virtual ble_error_t set_device_name(const uint8_t* device_name) = 0;
/**
* Acquire the appearance stored in the appearance characteristic of the GAP
* GATT service.
*
* @param appearance: If the call succeed will contain the value of the
* appearance characteristic.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
*
* @see Bluetooth 4.2 Vol 3 PartC: 12.2 - Appearance Characteristic
*/
virtual ble_error_t get_appearance(
GapAdvertisingData::Appearance& appearance
) = 0;
/**
* Set the value of the appearance characteristic of the GAP GATT service.
*
* @param appearance: The appearance to set.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
*
* @see Bluetooth 4.2 Vol 3 PartC: 12.2 - Appearance Characteristic
*/
virtual ble_error_t set_appearance(
GapAdvertisingData::Appearance appearance
) = 0;
/**
* Acquire the peripheral prefered connection parameters stored in the GAP
* Acquire the peripheral preferred connection parameters stored in the GAP
* GATT service.
*
* @param parameters: If the call succeed will contain the value of
* the peripheral prefered connection parameters characteristic.
* the peripheral preferred connection parameters characteristic.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
* otherwise.
@ -130,15 +56,15 @@ struct GenericAccessService {
* @see Bluetooth 4.2 Vol 3 PartC: 12.3 - Peripheral Preferred Connection
* Parameters Characteristic
*/
virtual ble_error_t get_peripheral_prefered_connection_parameters(
::Gap::ConnectionParams_t& parameters
virtual ble_error_t get_peripheral_preferred_connection_parameters(
::Gap::PreferredConnectionParams_t& parameters
) = 0;
/**
* set the value of the peripheral prefered connection parameters stored in
* set the value of the peripheral preferred connection parameters stored in
* the GAP GATT service.
*
* @param parameters: If the peripheral prefered connection parameters
* @param parameters: If the peripheral preferred connection parameters
* to set.
*
* @return BLE_ERROR_NONE in case of success or the appropriate error code
@ -147,8 +73,8 @@ struct GenericAccessService {
* @see Bluetooth 4.2 Vol 3 PartC: 12.3 - Peripheral Preferred Connection
* Parameters Characteristic
*/
virtual ble_error_t set_peripheral_prefered_connection_parameters(
const ::Gap::ConnectionParams_t& parameters
virtual ble_error_t set_peripheral_preferred_connection_parameters(
const ::Gap::PreferredConnectionParams_t& parameters
) = 0;
private:

View File

@ -1881,7 +1881,7 @@ public:
*/
ble_error_t disconnect(
connection_handle_t connection,
disconnection_reason_t disconnection_reason
local_disconnection_reason_t disconnection_reason
) {
return impl()->disconnect_(connection, disconnection_reason);
}

View File

@ -21,7 +21,6 @@
#include "platform/Callback.h"
#include "platform/NonCopyable.h"
#include "ble/BLETypes.h"
#include "ble/BLEProtocol.h"
#include "ble/SecurityManager.h"
#include "ble/pal/GapTypes.h"

View File

@ -27,7 +27,8 @@
* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.link_loss.xml
* Alertness Level Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.alert_level.xml
*/
class LinkLossService {
class LinkLossService : public ble::Gap::EventHandler
{
public:
enum AlertLevel_t {
NO_ALERT = 0,
@ -59,7 +60,7 @@ public:
ble.gattServer().addService(linkLossService);
serviceAdded = true;
ble.gap().onDisconnection(this, &LinkLossService::onDisconnectionFilter);
ble.gap().setEventHandler(this);
ble.gattServer().onDataWritten(this, &LinkLossService::onDataWritten);
}
@ -90,7 +91,7 @@ protected:
}
}
void onDisconnectionFilter(const Gap::DisconnectionCallbackParams_t *params) {
virtual void onDisconnectionComplete(const ble::DisconnectionCompleteEvent &) {
if (alertLevel != NO_ALERT) {
callback(alertLevel);
}

View File

@ -18,7 +18,6 @@
#include "ble/BLE.h"
#include "ble/BLEInstanceBase.h"
#include "platform/mbed_critical.h"
#include "Deprecated.h"
#if defined(TARGET_OTA_ENABLED)
#include "ble/services/DFUService.h"

View File

@ -1,75 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 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.h"
#include "ble/GapScanningParams.h"
GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) :
_interval(MSEC_TO_SCAN_DURATION_UNITS(interval)),
_window(MSEC_TO_SCAN_DURATION_UNITS(window)),
_timeout(timeout),
_activeScanning(activeScanning) {
/* stay within limits */
if (_interval < SCAN_INTERVAL_MIN) {
_interval = SCAN_INTERVAL_MIN;
}
if (_interval > SCAN_INTERVAL_MAX) {
_interval = SCAN_INTERVAL_MAX;
}
if (_window < SCAN_WINDOW_MIN) {
_window = SCAN_WINDOW_MIN;
}
if (_window > SCAN_WINDOW_MAX) {
_window = SCAN_WINDOW_MAX;
}
}
ble_error_t
GapScanningParams::setInterval(uint16_t newIntervalInMS)
{
uint16_t newInterval = MSEC_TO_SCAN_DURATION_UNITS(newIntervalInMS);
if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
_interval = newInterval;
return BLE_ERROR_NONE;
}
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
ble_error_t
GapScanningParams::setWindow(uint16_t newWindowInMS)
{
uint16_t newWindow = MSEC_TO_SCAN_DURATION_UNITS(newWindowInMS);
if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
_window = newWindow;
return BLE_ERROR_NONE;
}
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
ble_error_t
GapScanningParams::setTimeout(uint16_t newTimeout)
{
_timeout = newTimeout;
return BLE_ERROR_NONE;
}
void
GapScanningParams::setActiveScanning(bool activeScanning)
{
_activeScanning = activeScanning;
}

File diff suppressed because it is too large Load Diff

View File

@ -71,7 +71,7 @@ ble_error_t SecurityManager<Impl>::purgeAllBondingState(void) {
template <class Impl>
ble_error_t SecurityManager<Impl>::generateWhitelistFromBondTable(
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) const {
return impl()->generateWhitelistFromBondTable_(whitelist);
}
@ -278,7 +278,7 @@ ble_error_t SecurityManager<Impl>::purgeAllBondingState_(void) {
template <class Impl>
ble_error_t SecurityManager<Impl>::generateWhitelistFromBondTable_(
::Gap::Whitelist_t *whitelist
::ble::whitelist_t *whitelist
) const {
return BLE_ERROR_NOT_IMPLEMENTED;
}

View File

@ -315,6 +315,7 @@ ble_error_t Gap<Impl>::cancelConnect()
#endif
#if BLE_FEATURE_CONNECTABLE
template<class Impl>
ble_error_t Gap<Impl>::updateConnectionParameters(
connection_handle_t connectionHandle,
@ -418,26 +419,11 @@ ble_error_t Gap<Impl>::setPhy(
}
#endif // BLE_FEATURE_PHY_MANAGEMENT
template<class Impl>
void Gap<Impl>::useVersionOneAPI() const
{
return impl()->useVersionOneAPI_();
}
template<class Impl>
void Gap<Impl>::useVersionTwoAPI() const
{
return impl()->useVersionTwoAPI_();
}
template<class Impl>
Gap<Impl>::Gap() : _eventHandler(NULL)
{
}
/* -------------------- Future deprecation ------------------------- */
template<class Impl>
const peripheral_privacy_configuration_t Gap<Impl>::default_peripheral_privacy_configuration = {
/* use_non_resolvable_random_address */ false,
@ -445,9 +431,9 @@ const peripheral_privacy_configuration_t Gap<Impl>::default_peripheral_privacy_c
};
template<class Impl>
const central_privay_configuration_t Gap<Impl>::default_central_privacy_configuration = {
const central_privacy_configuration_t Gap<Impl>::default_central_privacy_configuration = {
/* use_non_resolvable_random_address */ false,
/* resolution_strategy */ central_privay_configuration_t::RESOLVE_AND_FORWARD
/* resolution_strategy */ central_privacy_configuration_t::RESOLVE_AND_FORWARD
};
#if BLE_FEATURE_PRIVACY
@ -478,7 +464,7 @@ ble_error_t Gap<Impl>::getPeripheralPrivacyConfiguration(
#if BLE_ROLE_OBSERVER
template<class Impl>
ble_error_t Gap<Impl>::setCentralPrivacyConfiguration(
const central_privay_configuration_t *configuration
const central_privacy_configuration_t *configuration
)
{
return impl()->setCentralPrivacyConfiguration_(configuration);
@ -486,7 +472,7 @@ ble_error_t Gap<Impl>::setCentralPrivacyConfiguration(
template<class Impl>
ble_error_t Gap<Impl>::getCentralPrivacyConfiguration(
central_privay_configuration_t *configuration
central_privacy_configuration_t *configuration
)
{
return impl()->getCentralPrivacyConfiguration_(configuration);
@ -500,6 +486,30 @@ ble_error_t Gap<Impl>::setRandomStaticAddress(const ble::address_t& address)
return impl()->setRandomStaticAddress_(address);
}
#if BLE_FEATURE_WHITELIST
template<class Impl>
uint8_t Gap<Impl>::getMaxWhitelistSize(void) const {
return impl()->getMaxWhitelistSize_();
}
template<class Impl>
ble_error_t Gap<Impl>::getWhitelist(whitelist_t &whitelist) const {
return impl()->getWhitelist_(whitelist);
}
template<class Impl>
ble_error_t Gap<Impl>::setWhitelist(const whitelist_t &whitelist) {
return impl()->setWhitelist_(whitelist);
}
#endif // BLE_FEATURE_WHITELIST
template<class Impl>
ble_error_t Gap<Impl>::reset(void)
{
return impl()->reset_();
}
// -----------------------------------------------------------------------------
/* ------------------------- Default implementations ------------------------ */
// -----------------------------------------------------------------------------
@ -819,16 +829,6 @@ ble_error_t Gap<Impl>::setPhy_(
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
void Gap<Impl>::useVersionOneAPI_() const
{
}
template<class Impl>
void Gap<Impl>::useVersionTwoAPI_() const
{
}
template<class Impl>
ble_error_t Gap<Impl>::enablePrivacy_(bool enable)
{
@ -853,7 +853,7 @@ ble_error_t Gap<Impl>::getPeripheralPrivacyConfiguration_(
template<class Impl>
ble_error_t Gap<Impl>::setCentralPrivacyConfiguration_(
const central_privay_configuration_t *configuration
const central_privacy_configuration_t *configuration
)
{
return BLE_ERROR_NOT_IMPLEMENTED;
@ -861,12 +861,32 @@ ble_error_t Gap<Impl>::setCentralPrivacyConfiguration_(
template<class Impl>
ble_error_t Gap<Impl>::getCentralPrivacyConfiguration_(
central_privay_configuration_t *configuration
central_privacy_configuration_t *configuration
)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t Gap<Impl>::getAddress(
own_address_type_t &typeP,
address_t &address
) {
return impl()->getAddress_(typeP, address);
}
template<class Impl>
ble_error_t Gap<Impl>::reset_(void)
{
/* Notify that the instance is about to shut down */
shutdownCallChain.call(this);
shutdownCallChain.clear();
this->_eventHandler = NULL;
return BLE_ERROR_NONE;
}
template<class Impl>
ble_error_t Gap<Impl>::setRandomStaticAddress_(const ble::address_t& address)
{

File diff suppressed because it is too large Load Diff

View File

@ -165,7 +165,7 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::purgeAl
}
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::Gap::Whitelist_t *whitelist) const {
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::generateWhitelistFromBondTable_(::ble::whitelist_t *whitelist) const {
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
if (eventHandler) {
if (!whitelist) {
@ -1104,12 +1104,11 @@ void GenericSecurityManager<TPalSecurityManager, SigningMonitor>::set_mitm_perfo
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
void GenericSecurityManager<TPalSecurityManager, SigningMonitor>::on_connected_(
connection_handle_t connection,
::Gap::Role_t role,
connection_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
address_t peer_address,
own_address_type_t local_address_type,
address_t local_address
) {
#if BLE_FEATURE_SECURITY
MBED_ASSERT(_db);
@ -1120,7 +1119,7 @@ void GenericSecurityManager<TPalSecurityManager, SigningMonitor>::on_connected_(
// setup the control block
cb->local_address = local_address;
cb->is_master = (role == ::Gap::CENTRAL);
cb->is_master = (role == connection_role_t::CENTRAL);
// get the associated db handle and the distribution flags if any
cb->db_entry = _db->open_entry(peer_address_type, peer_address);
@ -1150,7 +1149,7 @@ void GenericSecurityManager<TPalSecurityManager, SigningMonitor>::on_connected_(
template<template<class> class TPalSecurityManager, template<class> class SigningMonitor>
void GenericSecurityManager<TPalSecurityManager, SigningMonitor>::on_disconnected_(
connection_handle_t connection,
::Gap::DisconnectionReason_t reason
disconnection_reason_t reason
) {
#if BLE_FEATURE_SECURITY
MBED_ASSERT(_db);

View File

@ -142,13 +142,14 @@ public:
/**
* @see ::GattServer::getPreferredConnectionParams
*/
::Gap::ConnectionParams_t getPreferredConnectionParams();
::Gap::PreferredConnectionParams_t getPreferredConnectionParams();
/**
* @see ::GattServer::setPreferredConnectionParams
*/
void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
void setPreferredConnectionParams(const ::Gap::PreferredConnectionParams_t& params);
#if 0 // Disabled until reworked and reintroduced to GattServer API
/**
* @see ::GattServer::setDeviceName
*/
@ -169,6 +170,8 @@ public:
*/
GapAdvertisingData::Appearance getAppearance();
#endif // Disabled until reworked and reintroduced to GattServer API
/**
* @see ::GattServer::reset
*/

View File

@ -126,7 +126,7 @@ public:
ble_error_t disconnect_(
connection_handle_t connection,
disconnection_reason_t disconnection_reason
local_disconnection_reason_t disconnection_reason
);
bool is_privacy_supported_();

View File

@ -19,6 +19,8 @@ public:
virtual ~GenericAccessService() { }
#if 0 // Disabled until reworked and reintroduced to GattServer API
virtual ble_error_t get_device_name_length(uint8_t& length) {
#if BLE_FEATURE_GATT_SERVER
const uint8_t* name = NULL;
@ -82,8 +84,10 @@ public:
#endif // BLE_FEATURE_GATT_SERVER
}
virtual ble_error_t get_peripheral_prefered_connection_parameters(
::Gap::ConnectionParams_t& parameters
#endif // Disabled until reworked and reintroduced to GattServer API
virtual ble_error_t get_peripheral_preferred_connection_parameters(
::Gap::PreferredConnectionParams_t& parameters
) {
#if BLE_FEATURE_GATT_SERVER
parameters = gatt_server().getPreferredConnectionParams();
@ -93,8 +97,8 @@ public:
#endif // BLE_FEATURE_GATT_SERVER
}
virtual ble_error_t set_peripheral_prefered_connection_parameters(
const ::Gap::ConnectionParams_t& parameters
virtual ble_error_t set_peripheral_preferred_connection_parameters(
const ::Gap::PreferredConnectionParams_t& parameters
) {
#if BLE_FEATURE_GATT_SERVER
gatt_server().setPreferredConnectionParams(parameters);

View File

@ -800,9 +800,9 @@ bool GattServer::isOnDataReadAvailable_() const
return true;
}
::Gap::ConnectionParams_t GattServer::getPreferredConnectionParams()
::Gap::PreferredConnectionParams_t GattServer::getPreferredConnectionParams()
{
::Gap::ConnectionParams_t params = { 0 };
::Gap::PreferredConnectionParams_t params = { 0 };
memcpy(&params.minConnectionInterval, generic_access_service.ppcp, 2);
memcpy(&params.maxConnectionInterval, generic_access_service.ppcp + 2, 2);
memcpy(&params.slaveLatency, generic_access_service.ppcp + 4, 2);
@ -810,7 +810,7 @@ bool GattServer::isOnDataReadAvailable_() const
return params;
}
void GattServer::setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params)
void GattServer::setPreferredConnectionParams(const ::Gap::PreferredConnectionParams_t& params)
{
memcpy(generic_access_service.ppcp, &params.minConnectionInterval, 2);
memcpy(generic_access_service.ppcp + 2, &params.maxConnectionInterval, 2);
@ -818,6 +818,8 @@ void GattServer::setPreferredConnectionParams(const ::Gap::ConnectionParams_t& p
memcpy(generic_access_service.ppcp + 6, &params.connectionSupervisionTimeout, 2);
}
#if 0 // Disabled until reworked and reintroduced to GattServer API
ble_error_t GattServer::setDeviceName(const uint8_t *deviceName)
{
size_t length = 0;
@ -859,6 +861,8 @@ GapAdvertisingData::Appearance GattServer::getAppearance()
return (GapAdvertisingData::Appearance) generic_access_service.appearance;
}
#endif // Disabled until reworked and reintroduced to GattServer API
ble_error_t GattServer::reset_(void)
{
Base::reset_();
@ -1131,7 +1135,7 @@ void GattServer::add_generic_access_service()
current_attribute->permissions = ATTS_PERMIT_READ;
// peripheral prefered connection parameters declaration
// peripheral preferred connection parameters declaration
currentHandle += 2; // note: incremented by two to get a pointer to the value handle
++current_attribute;
@ -1149,7 +1153,7 @@ void GattServer::add_generic_access_service()
current_attribute->settings = 0;
current_attribute->permissions = ATTS_PERMIT_READ;
// peripheral prefered connection parameters value
// peripheral preferred connection parameters value
++current_attribute;
const uint8_t default_ppcp_value[] = {
0xFF, 0xFF, // no specific min connection interval

View File

@ -26,7 +26,6 @@
#include "ble/pal/AttClientToGattClientAdapter.h"
#include "ble/pal/PalGap.h"
#include "source/LegacyGap.tpp"
#include "source/gap/Gap.tpp"
#include "source/GattClient.tpp"
#include "source/SecurityManager.tpp"
@ -121,14 +120,3 @@ template class ble::interface::Gap<
SecurityManagerImpl
>
>;
template class ble::interface::LegacyGap<
ble::generic::GenericGap<
ble::pal::vendor::cordio::Gap,
SecurityManagerImpl::PalSecurityManager,
SecurityManagerImpl
>
>;

View File

@ -394,7 +394,7 @@ ble_error_t Gap<EventHandler>::reject_connection_parameter_request_(
template<class EventHandler>
ble_error_t Gap<EventHandler>::disconnect_(
connection_handle_t connection,
disconnection_reason_t disconnection_reason
local_disconnection_reason_t disconnection_reason
)
{
DmConnClose(