BLE: Remove LegacyGap and related types

pull/12730/head
Lingkai Dong 2020-03-26 15:38:48 +00:00
parent af6f32e584
commit d2d09b2bce
7 changed files with 2 additions and 3052 deletions

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

@ -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;
}

View File

@ -1,391 +0,0 @@
/* 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.h"
namespace ble {
namespace interface {
template<class Impl>
void LegacyGap<Impl>::processConnectionEvent(
Handle_t handle,
Role_t role,
PeerAddressType_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
) {
/* Update Gap state */
state.advertising = 0;
state.connected = 1;
++connectionCount;
ConnectionCallbackParams_t callbackParams(
handle,
role,
peerAddrType,
peerAddr,
ownAddrType,
ownAddr,
connectionParams,
peerResolvableAddr,
localResolvableAddr
);
connectionCallChain.call(&callbackParams);
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getAddress(
BLEProtocol::AddressType_t *typeP,
BLEProtocol::AddressBytes_t address
) {
return impl()->getAddress_(typeP, address);
}
template<class Impl>
LegacyGap<Impl>::AdvertisementCallbackParams_t::AdvertisementCallbackParams_t() :
peerAddr(),
rssi(),
isScanResponse(),
type(),
advertisingDataLen(0),
advertisingData(NULL)
{
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getRandomAddressType(
const BLEProtocol::AddressBytes_t address,
RandomAddressType_t* type
) {
// see section Device address in Bluetooth Link Layer specification
// (Vol 6 - Part B)
switch (address[5] >> 6) {
case 0x03:
*type = RandomAddressType_t::STATIC;
return BLE_ERROR_NONE;
case 0x00:
*type = RandomAddressType_t::NON_RESOLVABLE_PRIVATE;
return BLE_ERROR_NONE;
case 0x01:
*type = RandomAddressType_t::RESOLVABLE_PRIVATE;
return BLE_ERROR_NONE;
default:
return BLE_ERROR_INVALID_PARAM;
}
}
template<class Impl>
LegacyGap<Impl>::ConnectionCallbackParams_t::ConnectionCallbackParams_t(
Handle_t handleIn,
Role_t roleIn,
PeerAddressType_t peerAddrTypeIn,
const uint8_t *peerAddrIn,
BLEProtocol::AddressType_t ownAddrTypeIn,
const uint8_t *ownAddrIn,
const ConnectionParams_t *connectionParamsIn,
const uint8_t *peerResolvableAddrIn,
const uint8_t *localResolvableAddrIn
) : handle(handleIn),
role(roleIn),
peerAddr(),
ownAddrType(ownAddrTypeIn),
connectionParams(connectionParamsIn),
peerResolvableAddr(),
localResolvableAddr(),
peerAddressType(peerAddrTypeIn)
{
constructor_helper(
peerAddrIn,
ownAddrIn,
peerResolvableAddrIn,
localResolvableAddrIn
);
}
template <class Impl>
void LegacyGap<Impl>::ConnectionCallbackParams_t::constructor_helper(
const uint8_t *peerAddrIn,
const uint8_t *ownAddrIn,
const uint8_t *peerResolvableAddrIn,
const uint8_t *localResolvableAddrIn
) {
memcpy(peerAddr, peerAddrIn, ADDR_LEN);
if (peerResolvableAddrIn) {
memcpy(peerResolvableAddr, peerResolvableAddrIn, ADDR_LEN);
}
if (localResolvableAddrIn) {
memcpy(localResolvableAddr, localResolvableAddrIn, ADDR_LEN);
}
}
template<class Impl>
void LegacyGap<Impl>::processAdvertisementReport(
const BLEProtocol::AddressBytes_t peerAddr,
int8_t rssi,
bool isScanResponse,
GapAdvertisingParams::AdvertisingType_t type,
uint8_t advertisingDataLen,
const uint8_t *advertisingData,
PeerAddressType_t addressType
) {
AdvertisementCallbackParams_t params;
memcpy(params.peerAddr, peerAddr, ADDR_LEN);
params.rssi = rssi;
params.isScanResponse = isScanResponse;
params.type = type;
params.advertisingDataLen = advertisingDataLen;
params.advertisingData = advertisingData;
onAdvertisementReport.call(&params);
}
#if BLE_ROLE_BROADCASTER
template<class Impl>
uint16_t LegacyGap<Impl>::getMinAdvertisingInterval(void) const
{
return impl()->getMinAdvertisingInterval_();
}
template<class Impl>
uint16_t LegacyGap<Impl>::getMinNonConnectableAdvertisingInterval(void) const
{
return impl()->getMinNonConnectableAdvertisingInterval_();
}
template<class Impl>
uint16_t LegacyGap<Impl>::getMaxAdvertisingInterval(void) const
{
return impl()->getMaxAdvertisingInterval_();
}
#endif // BLE_ROLE_BROADCASTER
#if BLE_FEATURE_CONNECTABLE
template<class Impl>
ble_error_t LegacyGap<Impl>::getPreferredConnectionParams(ConnectionParams_t *params)
{
return impl()->getPreferredConnectionParams_(params);
}
template<class Impl>
ble_error_t LegacyGap<Impl>::setPreferredConnectionParams(
const ConnectionParams_t *params
)
{
return impl()->setPreferredConnectionParams_(params);
}
#endif // BLE_FEATURE_CONNECTABLE
#if BLE_FEATURE_GATT_SERVER
template<class Impl>
ble_error_t LegacyGap<Impl>::setDeviceName(const uint8_t *deviceName)
{
return impl()->setDeviceName_(deviceName);
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
{
return impl()->getDeviceName_(deviceName, lengthP);
}
template<class Impl>
ble_error_t LegacyGap<Impl>::setAppearance(GapAdvertisingData::Appearance appearance)
{
return impl()->setAppearance_(appearance);
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getAppearance(GapAdvertisingData::Appearance *appearanceP)
{
return impl()->getAppearance_(appearanceP);
}
#endif // BLE_FEATURE_GATT_SERVER
template<class Impl>
ble_error_t LegacyGap<Impl>::reset(void)
{
return impl()->reset_();
}
template<class Impl>
LegacyGap<Impl>::LegacyGap() :
_advParams(),
_advPayload(),
_scanningParams(),
_scanResponse(),
connectionCount(0),
state(),
scanningActive(false),
timeoutCallbackChain(),
radioNotificationCallback(),
onAdvertisementReport(),
connectionCallChain(),
disconnectionCallChain()
{
#if BLE_ROLE_BROADCASTER
_advPayload.clear();
_scanResponse.clear();
#endif // BLE_ROLE_BROADCASTER
}
template<class Impl>
void LegacyGap<Impl>::processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason)
{
/* Update Gap state */
--connectionCount;
if (!connectionCount) {
state.connected = 0;
}
DisconnectionCallbackParams_t callbackParams(handle, reason);
disconnectionCallChain.call(&callbackParams);
}
template<class Impl>
void LegacyGap<Impl>::processTimeoutEvent(TimeoutSource_t source)
{
if (source == TIMEOUT_SRC_ADVERTISING) {
/* Update gap state if the source is an advertising timeout */
state.advertising = 0;
}
if (timeoutCallbackChain) {
timeoutCallbackChain(source);
}
}
template<class Impl>
uint16_t LegacyGap<Impl>::getMinAdvertisingInterval_(void) const
{
return 0;
}
template<class Impl>
uint16_t LegacyGap<Impl>::getMinNonConnectableAdvertisingInterval_(void) const
{
return 0;
}
template<class Impl>
uint16_t LegacyGap<Impl>::getMaxAdvertisingInterval_(void) const
{
return 0xFFFF;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::reset_(void)
{
/* Notify that the instance is about to shut down */
shutdownCallChain.call(this);
shutdownCallChain.clear();
/* Clear Gap state */
state.advertising = 0;
state.connected = 0;
#if BLE_FEATURE_CONNECTABLE
connectionCount = 0;
#endif
/* Clear scanning state */
#if BLE_ROLE_OBSERVER
scanningActive = false;
#endif
#if BLE_ROLE_BROADCASTER
/* Clear advertising and scanning data */
_advPayload.clear();
_scanResponse.clear();
#endif // BLE_ROLE_BROADCASTER
/* Clear callbacks */
timeoutCallbackChain.clear();
#if BLE_FEATURE_CONNECTABLE
connectionCallChain.clear();
disconnectionCallChain.clear();
#endif // BLE_FEATURE_CONNECTABLE
radioNotificationCallback = NULL;
#if BLE_ROLE_OBSERVER
onAdvertisementReport = NULL;
#endif
this->_eventHandler = NULL;
return BLE_ERROR_NONE;
}
// -----------------------------------------------------------------------------
/* ------------------------- Default implementations ------------------------ */
// -----------------------------------------------------------------------------
template<class Impl>
ble_error_t LegacyGap<Impl>::getAddress_(
BLEProtocol::AddressType_t *typeP,
BLEProtocol::AddressBytes_t address
) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getPreferredConnectionParams_(ConnectionParams_t *params)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::setPreferredConnectionParams_(
const ConnectionParams_t *params
)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::setDeviceName_(const uint8_t *deviceName)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getDeviceName_(uint8_t *deviceName, unsigned *lengthP)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::setAppearance_(GapAdvertisingData::Appearance appearance)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t LegacyGap<Impl>::getAppearance_(GapAdvertisingData::Appearance *appearanceP)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
} // namespace interface
} // namespace ble