Merge pull request #5739 from pan-/nordic-new-client

BLE: Nordic pal client implementation
pull/5744/merge
Cruz Monrreal 2018-01-11 10:26:47 -06:00 committed by GitHub
commit b32828bc37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 2087 additions and 1919 deletions

View File

@ -17,6 +17,7 @@
#ifndef MBED_UUID_H__
#define MBED_UUID_H__
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>

View File

@ -26,27 +26,12 @@
namespace ble {
namespace generic {
// forward declarations
struct procedure_control_block_t;
struct discovery_control_block_t;
struct read_control_block_t;
struct write_control_block_t;
struct descriptor_discovery_control_block_t;
/**
* Generic implementation of the GattClient.
* It requires a pal::GattClient injected at construction site.
* @attention: Not part of the public interface of BLE API.
*/
class GenericGattClient : public GattClient {
// give access to control block classes
friend struct procedure_control_block_t;
friend struct discovery_control_block_t;
friend struct read_control_block_t;
friend struct write_control_block_t;
friend struct descriptor_discovery_control_block_t;
public:
/**
* Create a GenericGattClient from a pal::GattClient
@ -130,10 +115,16 @@ public:
virtual ble_error_t reset(void);
private:
procedure_control_block_t* get_control_block(Gap::Handle_t connection);
const procedure_control_block_t* get_control_block(Gap::Handle_t connection) const;
void insert_control_block(procedure_control_block_t* cb) const;
void remove_control_block(procedure_control_block_t* cb) const;
struct ProcedureControlBlock;
struct DiscoveryControlBlock;
struct ReadControlBlock;
struct WriteControlBlock;
struct DescriptorDiscoveryControlBlock;
ProcedureControlBlock* get_control_block(Gap::Handle_t connection);
const ProcedureControlBlock* get_control_block(Gap::Handle_t connection) const;
void insert_control_block(ProcedureControlBlock* cb) const;
void remove_control_block(ProcedureControlBlock* cb) const;
void on_termination(Gap::Handle_t connection_handle);
void on_server_message_received(connection_handle_t, const pal::AttServerMessage&);
@ -145,7 +136,8 @@ private:
pal::GattClient* const _pal_client;
ServiceDiscovery::TerminationCallback_t _termination_callback;
mutable procedure_control_block_t* control_blocks;
mutable ProcedureControlBlock* control_blocks;
bool _is_reseting;
};
}

View File

@ -55,14 +55,14 @@ enum procedure_type_t {
/*
* Base class for a procedure control block
*/
struct procedure_control_block_t {
struct GenericGattClient::ProcedureControlBlock {
/*
* Base constructor for procedure control block.
*/
procedure_control_block_t(procedure_type_t type, Gap::Handle_t handle) :
ProcedureControlBlock(procedure_type_t type, Gap::Handle_t handle) :
type(type), connection_handle(handle), next(NULL) { }
virtual ~procedure_control_block_t() { }
virtual ~ProcedureControlBlock() { }
/*
* Entry point of the control block stack machine.
@ -74,23 +74,28 @@ struct procedure_control_block_t {
*/
virtual void handle_timeout_error(GenericGattClient* client) = 0;
/**
* Function called when the procedure is aborted
*/
virtual void abort(GenericGattClient *client) = 0;
procedure_type_t type;
Gap::Handle_t connection_handle;
procedure_control_block_t* next;
ProcedureControlBlock* next;
};
/*
* Procedure control block for the discovery process.
*/
struct discovery_control_block_t : public procedure_control_block_t {
discovery_control_block_t(
struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
DiscoveryControlBlock(
Gap::Handle_t handle,
ServiceDiscovery::ServiceCallback_t service_callback,
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
UUID matching_service_uuid,
UUID matching_characteristic_uuid
) : procedure_control_block_t(COMPLETE_DISCOVERY_PROCEDURE, handle),
) : ProcedureControlBlock(COMPLETE_DISCOVERY_PROCEDURE, handle),
service_callback(service_callback),
characteristic_callback(characteristic_callback),
matching_service_uuid(matching_service_uuid),
@ -99,7 +104,7 @@ struct discovery_control_block_t : public procedure_control_block_t {
done(false) {
}
virtual ~discovery_control_block_t() {
virtual ~DiscoveryControlBlock() {
while(services_discovered) {
service_t* tmp = services_discovered->next;
delete services_discovered;
@ -111,6 +116,10 @@ struct discovery_control_block_t : public procedure_control_block_t {
terminate(client);
}
virtual void abort(GenericGattClient *client) {
terminate(client);
}
virtual void handle(GenericGattClient* client, const AttServerMessage& message) {
// if end of discovery has been requested, ends it immediately
if (done) {
@ -409,15 +418,15 @@ struct discovery_control_block_t : public procedure_control_block_t {
};
struct read_control_block_t : public procedure_control_block_t {
read_control_block_t(
struct GenericGattClient::ReadControlBlock : public ProcedureControlBlock {
ReadControlBlock(
Gap::Handle_t connection_handle, uint16_t attribute_handle, uint16_t offset
) : procedure_control_block_t(READ_PROCEDURE, connection_handle),
) : ProcedureControlBlock(READ_PROCEDURE, connection_handle),
attribute_handle(attribute_handle),
offset(offset), current_offset(offset), data(NULL) {
}
virtual ~read_control_block_t() {
virtual ~ReadControlBlock() {
if (data != NULL) {
free(data);
}
@ -436,6 +445,19 @@ struct read_control_block_t : public procedure_control_block_t {
terminate(client, response);
}
virtual void abort(GenericGattClient *client) {
GattReadCallbackParams response = {
connection_handle,
attribute_handle,
offset,
0, // size of 0
NULL, // no data
BLE_ERROR_INVALID_STATE,
};
terminate(client, response);
}
void terminate(GenericGattClient* client, const GattReadCallbackParams& response) {
client->remove_control_block(this);
client->processReadResponse(&response);
@ -593,16 +615,16 @@ struct read_control_block_t : public procedure_control_block_t {
/*
* Control block for the write process
*/
struct write_control_block_t : public procedure_control_block_t {
write_control_block_t(
struct GenericGattClient::WriteControlBlock : public ProcedureControlBlock {
WriteControlBlock(
Gap::Handle_t connection_handle, uint16_t attribute_handle,
uint8_t* data, uint16_t len
) : procedure_control_block_t(WRITE_PROCEDURE, connection_handle),
) : ProcedureControlBlock(WRITE_PROCEDURE, connection_handle),
attribute_handle(attribute_handle), len(len), offset(0), data(data),
prepare_success(false), status(BLE_ERROR_UNSPECIFIED), error_code(0xFF) {
}
virtual ~write_control_block_t() {
virtual ~WriteControlBlock() {
free(data);
}
@ -617,6 +639,17 @@ struct write_control_block_t : public procedure_control_block_t {
terminate(client, response);
}
virtual void abort(GenericGattClient *client) {
GattWriteCallbackParams response = {
connection_handle,
attribute_handle,
GattWriteCallbackParams::OP_WRITE_REQ,
BLE_ERROR_INVALID_STATE,
0x00
};
terminate(client, response);
}
void terminate(GenericGattClient* client, const GattWriteCallbackParams& response) {
client->remove_control_block(this);
client->processWriteResponse(&response);
@ -785,12 +818,12 @@ struct write_control_block_t : public procedure_control_block_t {
/*
* Control block for the descriptor discovery process
*/
struct descriptor_discovery_control_block_t : public procedure_control_block_t {
descriptor_discovery_control_block_t(
struct GenericGattClient::DescriptorDiscoveryControlBlock : public ProcedureControlBlock {
DescriptorDiscoveryControlBlock(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
) : procedure_control_block_t(DESCRIPTOR_DISCOVERY_PROCEDURE, characteristic.getConnectionHandle()),
) : ProcedureControlBlock(DESCRIPTOR_DISCOVERY_PROCEDURE, characteristic.getConnectionHandle()),
characteristic(characteristic),
discovery_cb(discoveryCallback),
termination_cb(terminationCallback),
@ -798,7 +831,7 @@ struct descriptor_discovery_control_block_t : public procedure_control_block_t {
done(false) {
}
virtual ~descriptor_discovery_control_block_t() { }
virtual ~DescriptorDiscoveryControlBlock() { }
ble_error_t start(GenericGattClient* client) {
return client->_pal_client->discover_characteristics_descriptors(
@ -814,6 +847,10 @@ struct descriptor_discovery_control_block_t : public procedure_control_block_t {
terminate(client, BLE_ERROR_UNSPECIFIED);
}
virtual void abort(GenericGattClient *client) {
terminate(client, BLE_ERROR_INVALID_STATE);
}
virtual void handle(GenericGattClient* client, const AttServerMessage& message) {
if (done) {
terminate(client, BLE_ERROR_NONE);
@ -892,7 +929,8 @@ struct descriptor_discovery_control_block_t : public procedure_control_block_t {
GenericGattClient::GenericGattClient(pal::GattClient* pal_client) :
_pal_client(pal_client),
_termination_callback(),
control_blocks(NULL) {
control_blocks(NULL),
_is_reseting(false) {
_pal_client->when_server_message_received(
mbed::callback(this, &GenericGattClient::on_server_message_received)
);
@ -909,7 +947,7 @@ ble_error_t GenericGattClient::launchServiceDiscovery(
const UUID& matching_characteristic_uuid
) {
// verify that there is no other procedures going on this connection
if (get_control_block(connection_handle)) {
if (_is_reseting || get_control_block(connection_handle)) {
return BLE_ERROR_INVALID_STATE;
}
@ -919,7 +957,7 @@ ble_error_t GenericGattClient::launchServiceDiscovery(
return BLE_ERROR_NONE;
}
discovery_control_block_t* discovery_pcb = new(std::nothrow) discovery_control_block_t(
DiscoveryControlBlock* discovery_pcb = new(std::nothrow) DiscoveryControlBlock(
connection_handle,
service_callback,
characteristic_callback,
@ -959,7 +997,7 @@ ble_error_t GenericGattClient::launchServiceDiscovery(
}
bool GenericGattClient::isServiceDiscoveryActive() const {
procedure_control_block_t* pcb = control_blocks;
ProcedureControlBlock* pcb = control_blocks;
while (pcb) {
if (pcb->type == COMPLETE_DISCOVERY_PROCEDURE) {
@ -973,10 +1011,10 @@ bool GenericGattClient::isServiceDiscoveryActive() const {
void GenericGattClient::terminateServiceDiscovery()
{
procedure_control_block_t* pcb = control_blocks;
ProcedureControlBlock* pcb = control_blocks;
while (pcb) {
if (pcb->type == COMPLETE_DISCOVERY_PROCEDURE) {
static_cast<discovery_control_block_t*>(pcb)->done = true;
static_cast<DiscoveryControlBlock*>(pcb)->done = true;
}
pcb = pcb->next;
}
@ -988,11 +1026,11 @@ ble_error_t GenericGattClient::read(
uint16_t offset) const
{
// verify that there is no other procedures going on this connection
if (get_control_block(connection_handle)) {
if (_is_reseting || get_control_block(connection_handle)) {
return BLE_ERROR_INVALID_STATE;
}
read_control_block_t* read_pcb = new(std::nothrow) read_control_block_t(
ReadControlBlock* read_pcb = new(std::nothrow) ReadControlBlock(
connection_handle,
attribute_handle,
offset
@ -1032,7 +1070,7 @@ ble_error_t GenericGattClient::write(
const uint8_t* value
) const {
// verify that there is no other procedures going on this connection
if (get_control_block(connection_handle)) {
if (_is_reseting || get_control_block(connection_handle)) {
return BLE_ERROR_INVALID_STATE;
}
@ -1058,7 +1096,7 @@ ble_error_t GenericGattClient::write(
memcpy(data, value, length);
}
write_control_block_t* write_pcb = new(std::nothrow) write_control_block_t(
WriteControlBlock* write_pcb = new(std::nothrow) WriteControlBlock(
connection_handle,
attribute_handle,
data,
@ -1111,7 +1149,7 @@ ble_error_t GenericGattClient::discoverCharacteristicDescriptors(
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
) {
// verify that there is no other procedures going on this connection
if (get_control_block(characteristic.getConnectionHandle())) {
if (_is_reseting || get_control_block(characteristic.getConnectionHandle())) {
return BLE_ERROR_INVALID_STATE;
}
@ -1126,8 +1164,8 @@ ble_error_t GenericGattClient::discoverCharacteristicDescriptors(
return BLE_ERROR_NONE;
}
descriptor_discovery_control_block_t* discovery_pcb =
new(std::nothrow) descriptor_discovery_control_block_t(
DescriptorDiscoveryControlBlock* discovery_pcb =
new(std::nothrow) DescriptorDiscoveryControlBlock(
characteristic,
discoveryCallback,
terminationCallback
@ -1152,11 +1190,11 @@ ble_error_t GenericGattClient::discoverCharacteristicDescriptors(
bool GenericGattClient::isCharacteristicDescriptorDiscoveryActive(
const DiscoveredCharacteristic& characteristic
) const {
procedure_control_block_t* pcb = control_blocks;
ProcedureControlBlock* pcb = control_blocks;
while (pcb) {
if (pcb->type == DESCRIPTOR_DISCOVERY_PROCEDURE &&
static_cast<descriptor_discovery_control_block_t*>(pcb)->characteristic == characteristic) {
static_cast<DescriptorDiscoveryControlBlock*>(pcb)->characteristic == characteristic) {
return true;
}
pcb = pcb->next;
@ -1168,12 +1206,12 @@ bool GenericGattClient::isCharacteristicDescriptorDiscoveryActive(
void GenericGattClient::terminateCharacteristicDescriptorDiscovery(
const DiscoveredCharacteristic& characteristic
) {
procedure_control_block_t* pcb = control_blocks;
ProcedureControlBlock* pcb = control_blocks;
while (pcb) {
if (pcb->type == DESCRIPTOR_DISCOVERY_PROCEDURE) {
descriptor_discovery_control_block_t* dpcb =
static_cast<descriptor_discovery_control_block_t*>(pcb);
DescriptorDiscoveryControlBlock* dpcb =
static_cast<DescriptorDiscoveryControlBlock*>(pcb);
if (dpcb->characteristic == characteristic) {
dpcb->done = true;
return;
@ -1186,7 +1224,17 @@ void GenericGattClient::terminateCharacteristicDescriptorDiscovery(
}
ble_error_t GenericGattClient::reset(void) {
return BLE_ERROR_NOT_IMPLEMENTED;
// _is_reseting prevent executions of new procedure while the instance resets.
// otherwise new procedures can be launched from callbacks generated by the
// reset.
_is_reseting = true;
while (control_blocks) {
control_blocks->abort(this);
}
_is_reseting = false;
return BLE_ERROR_NONE;
}
void GenericGattClient::on_termination(Gap::Handle_t connection_handle) {
@ -1230,7 +1278,7 @@ void GenericGattClient::on_server_response(
connection_handle_t connection,
const AttServerMessage& message
) {
procedure_control_block_t* pcb = get_control_block(connection);
ProcedureControlBlock* pcb = get_control_block(connection);
if (pcb == NULL) {
return;
}
@ -1270,7 +1318,7 @@ void GenericGattClient::on_server_event(connection_handle_t connection, const At
}
void GenericGattClient::on_transaction_timeout(connection_handle_t connection) {
procedure_control_block_t* pcb = get_control_block(connection);
ProcedureControlBlock* pcb = get_control_block(connection);
if (pcb == NULL) {
return;
}
@ -1278,36 +1326,36 @@ void GenericGattClient::on_transaction_timeout(connection_handle_t connection) {
pcb->handle_timeout_error(this);
}
procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) {
procedure_control_block_t* it = control_blocks;
GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(Gap::Handle_t connection) {
ProcedureControlBlock* it = control_blocks;
while (it && it->connection_handle != connection) {
it = it->next;
}
return it;
}
const procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) const {
procedure_control_block_t* it = control_blocks;
const GenericGattClient::ProcedureControlBlock* GenericGattClient::get_control_block(Gap::Handle_t connection) const {
ProcedureControlBlock* it = control_blocks;
while (it && it->connection_handle != connection) {
it = it->next;
}
return it;
}
void GenericGattClient::insert_control_block(procedure_control_block_t* cb) const {
void GenericGattClient::insert_control_block(ProcedureControlBlock* cb) const {
if (control_blocks == NULL) {
control_blocks = cb;
return;
}
procedure_control_block_t* current = control_blocks;
ProcedureControlBlock* current = control_blocks;
while (current->next) {
current = current->next;
}
current->next = cb;
}
void GenericGattClient::remove_control_block(procedure_control_block_t* cb) const {
void GenericGattClient::remove_control_block(ProcedureControlBlock* cb) const {
if (control_blocks == NULL) {
return;
}
@ -1317,7 +1365,7 @@ void GenericGattClient::remove_control_block(procedure_control_block_t* cb) cons
return;
}
procedure_control_block_t* current = control_blocks;
ProcedureControlBlock* current = control_blocks;
while (current->next && current->next != cb) {
current = current->next;
}

View File

@ -51,11 +51,9 @@ extern "C" {
}
#include "nrf_ble_hci.h"
#include "btle_discovery.h"
#include "nRF5xGattClient.h"
#include "nRF5xServiceDiscovery.h"
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
#include "nRF5XPalGattClient.h"
bool isEventsSignaled = false;
@ -67,23 +65,6 @@ extern "C" void SD_EVT_IRQHandler(void); // export the softdevice event handler
static void btle_handler(ble_evt_t *p_ble_evt);
#if 0
#define CENTRAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS) /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define PERIPHERAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS) /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define GATTS_ATTR_TAB_SIZE (YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE) /**< GATTS attribite table size. */
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
#else
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
#endif
static void sys_evt_dispatch(uint32_t sys_evt)
{
#if (IS_LEGACY_DEVICE_MANAGER_ENABLED)
@ -121,7 +102,7 @@ error_t btle_init(void)
// register softdevice handler vector
NVIC_SetVector(SD_EVT_IRQn, (uint32_t) SD_EVT_IRQHandler);
// Configure the LF clock according to values provided by btle_clock.h.
// It is input from the chain of the yotta configuration system.
clockConfiguration.source = LFCLK_CONF_SOURCE;
@ -189,6 +170,8 @@ error_t btle_init(void)
static void btle_handler(ble_evt_t *p_ble_evt)
{
using ble::pal::vendor::nordic::nRF5XGattClient;
/* Library service handlers */
#if SDK_CONN_PARAMS_MODULE_ENABLE
ble_conn_params_on_ble_evt(p_ble_evt);
@ -206,7 +189,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
#endif
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
bleGattcEventHandler(p_ble_evt);
nRF5XGattClient::handle_events(p_ble_evt);
#endif
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
@ -229,7 +212,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
#if (NRF_SD_BLE_API_VERSION <= 2)
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
gap.processConnectionEvent(handle,
role,
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
@ -275,9 +258,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
// Close all pending discoveries for this connection
nRF5xGattClient& gattClient = ble.getGattClient();
gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
gattClient.discovery().terminate(handle);
nRF5XGattClient::handle_connection_termination(handle);
#endif
gap.processDisconnectionEvent(handle, reason);

View File

@ -26,6 +26,13 @@ extern "C" {
#include "ble_srv_common.h"
#include "headers/nrf_ble.h"
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
error_t btle_init(void);
// flag indicating if events have been signaled or not

View File

@ -1,147 +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 "nRF5xServiceDiscovery.h"
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
#include "nRF5xGattClient.h"
#include "nRF5xn.h"
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
{
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
nRF5xGattClient &gattClient = (nRF5xGattClient &) ble.getGattClient();
nRF5xServiceDiscovery &sdSingleton = gattClient.discovery();
nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer =
gattClient.characteristicDescriptorDiscoverer();
switch (p_ble_evt->header.evt_id) {
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
case BLE_GATT_STATUS_SUCCESS:
sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
break;
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
default:
sdSingleton.terminate();
break;
}
break;
case BLE_GATTC_EVT_CHAR_DISC_RSP:
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
case BLE_GATT_STATUS_SUCCESS:
sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
break;
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
default:
sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE);
break;
}
break;
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
if (sdSingleton.isActive()) {
sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt);
}
break;
case BLE_GATTC_EVT_READ_RSP: {
GattReadCallbackParams response = {
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
/* .handle = */ p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
/* .offset = */ p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
/* .len = */ p_ble_evt->evt.gattc_evt.params.read_rsp.len,
/* .data = */ p_ble_evt->evt.gattc_evt.params.read_rsp.data,
};
gattClient.processReadResponse(&response);
}
break;
case BLE_GATTC_EVT_WRITE_RSP: {
GattWriteCallbackParams response = {
/* .connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
/* .handle = */ p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
/* .writeOp = */ (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
/* .offset = */ p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
/* .len = */ p_ble_evt->evt.gattc_evt.params.write_rsp.len,
/* .data = */ p_ble_evt->evt.gattc_evt.params.write_rsp.data,
};
gattClient.processWriteResponse(&response);
}
break;
case BLE_GATTC_EVT_HVX: {
GattHVXCallbackParams params = {
/* connHandle = */ p_ble_evt->evt.gattc_evt.conn_handle,
/* handle = */ p_ble_evt->evt.gattc_evt.params.hvx.handle,
/* type = */ static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type),
/* len = */ p_ble_evt->evt.gattc_evt.params.hvx.len,
/* data = */ p_ble_evt->evt.gattc_evt.params.hvx.data
};
gattClient.processHVXEvent(&params);
}
break;
case BLE_GATTC_EVT_DESC_DISC_RSP: {
uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status;
const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp;
switch(status) {
case BLE_GATT_STATUS_SUCCESS:
characteristicDescriptorDiscoverer.process(
conn_handle,
discovered_descriptors
);
break;
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
// end of discovery
characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE);
break;
default:
characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED);
break;
}
} break;
case BLE_GATTC_EVT_ATTR_INFO_DISC_RSP : {
uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status;
const ble_gattc_evt_attr_info_disc_rsp_t& infos = p_ble_evt->evt.gattc_evt.params.attr_info_disc_rsp;
switch(status) {
case BLE_GATT_STATUS_SUCCESS:
characteristicDescriptorDiscoverer.processAttributeInformation(
conn_handle,
infos
);
break;
default:
characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED);
break;
}
} break;
}
sdSingleton.progressCharacteristicDiscovery();
sdSingleton.progressServiceDiscovery();
}
#endif

View File

@ -1,22 +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 _BTLE_DISCOVERY_H_
#define _BTLE_DISCOVERY_H_
void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
#endif /*_BTLE_DISCOVERY_H_*/

View File

@ -0,0 +1,257 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef BLE_NORDIC_PAL_GATT_CLIENT_H_
#define BLE_NORDIC_PAL_GATT_CLIENT_H_
#include "ble/pal/PalGattClient.h"
#include "ble/blecommon.h"
#include "ble/UUID.h"
#include "nrf_ble_gatt.h"
#include "nrf_ble.h"
#include "nrf_ble_types.h"
#include "btle.h"
namespace ble {
namespace pal {
namespace vendor {
namespace nordic {
/**
* Implementation of pal::GattClient for the Nordic stack.
*/
class nRF5XGattClient : public ble::pal::GattClient {
public:
nRF5XGattClient();
virtual ~nRF5XGattClient();
/**
* see pal::GattClient::initialize .
*/
virtual ble_error_t initialize();
/**
* see pal::GattClient::terminate .
*/
virtual ble_error_t terminate();
/**
* see pal::GattClient::exchange_mtu .
*/
virtual ble_error_t exchange_mtu(connection_handle_t connection);
/**
* see pal::GattClient::get_mtu_size .
*/
virtual ble_error_t get_mtu_size(
connection_handle_t connection_handle, uint16_t& mtu_size
);
/**
* see pal::GattClient::discover_primary_service .
*/
virtual ble_error_t discover_primary_service(
connection_handle_t connection,
attribute_handle_t discovery_range_begining
);
/**
* see pal::GattClient::discover_primary_service_by_service_uuid .
*/
virtual ble_error_t discover_primary_service_by_service_uuid(
connection_handle_t connection_handle,
attribute_handle_t discovery_range_beginning,
const UUID& uuid
);
/**
* see pal::GattClient::find_included_service .
*/
virtual ble_error_t find_included_service(
connection_handle_t connection_handle,
attribute_handle_range_t service_range
);
/**
* see pal::GattClient::discover_characteristics_of_a_service .
*/
virtual ble_error_t discover_characteristics_of_a_service(
connection_handle_t connection_handle,
attribute_handle_range_t discovery_range
);
/**
* see pal::GattClient::discover_characteristics_descriptors .
*/
virtual ble_error_t discover_characteristics_descriptors(
connection_handle_t connection_handle,
attribute_handle_range_t descriptors_discovery_range
);
/**
* see pal::GattClient::read_attribute_value .
*/
virtual ble_error_t read_attribute_value(
connection_handle_t connection_handle,
attribute_handle_t attribute_handle
);
/**
* see pal::GattClient::read_using_characteristic_uuid .
*/
virtual ble_error_t read_using_characteristic_uuid(
connection_handle_t connection_handle,
attribute_handle_range_t read_range,
const UUID& uuid
);
/**
* see pal::GattClient::read_attribute_blob .
*/
virtual ble_error_t read_attribute_blob(
connection_handle_t connection,
attribute_handle_t attribute_handle,
uint16_t offset
);
/**
* see pal::GattClient::read_multiple_characteristic_values .
*/
virtual ble_error_t read_multiple_characteristic_values(
connection_handle_t connection,
const ArrayView<const attribute_handle_t>& characteristic_handles
);
/**
* see pal::GattClient::write_without_response .
*/
virtual ble_error_t write_without_response(
connection_handle_t connection_handle,
attribute_handle_t characteristic_value_handle,
const ArrayView<const uint8_t>& value
);
/**
* see pal::GattClient::signed_write_without_response .
*/
virtual ble_error_t signed_write_without_response(
connection_handle_t connection_handle,
attribute_handle_t characteristic_value_handle,
const ArrayView<const uint8_t>& value
);
/**
* see pal::GattClient::write_attribute .
*/
virtual ble_error_t write_attribute(
connection_handle_t connection_handle,
attribute_handle_t attribute_handle,
const ArrayView<const uint8_t>& value
);
/**
* see pal::GattClient::queue_prepare_write .
*/
virtual ble_error_t queue_prepare_write(
connection_handle_t connection_handle,
attribute_handle_t characteristic_value_handle,
const ArrayView<const uint8_t>& value,
uint16_t offset
);
/**
* see pal::GattClient::execute_write_queue .
*/
virtual ble_error_t execute_write_queue(
connection_handle_t connection_handle,
bool execute
);
// singleton of the ARM Cordio client
static nRF5XGattClient& get_client();
/**
* Function call from btle.cpp
*
* Do not call directly.
*/
static void handle_events(const ble_evt_t *p_ble_evt);
/**
* Called by btle.cpp when a disconnection happens.
*/
static void handle_connection_termination(connection_handle_t connection);
private:
struct GattProcedure;
struct RegularGattProcedure;
struct DiscoverPrimaryServiceProcedure;
struct DiscoverPrimaryServiceByUUIDProcedure;
struct FindIncludedServicesProcedure;
struct DiscoverCharacteristicsProcedure;
struct DiscoverDescriptorsProcedure;
struct ReadAttributeProcedure;
struct ReadUsingCharacteristicUUIDProcedure;
struct ReadAttributeBlobProcedure;
struct ReadMultipleCharacteristicsProcedure;
struct WriteAttributeProcedure;
struct QueuePrepareWriteProcedure;
struct ExecuteWriteQueueProcedure;
template<typename ProcType, typename A0>
ble_error_t launch_procedure(connection_handle_t connection, const A0& a0);
template<typename ProcType, typename A0, typename A1>
ble_error_t launch_procedure(
connection_handle_t connection, const A0& a0, const A1& a1
);
template<typename ProcType, typename A0, typename A1, typename A2>
ble_error_t launch_procedure(
connection_handle_t connection,
const A0& a0, const A1& a1, const A2& a2
);
template<typename ProcType, typename A0, typename A1, typename A2, typename A3>
ble_error_t launch_procedure(
connection_handle_t connection,
const A0& a0, const A1& a1, const A2& a2, const A3& a3
);
GattProcedure* get_procedure(connection_handle_t) const;
bool register_procedure(GattProcedure*);
bool remove_procedure(GattProcedure*);
void handle_procedure_event(const ble_evt_t &evt);
void handle_hvx_event(const ble_evt_t &evt);
void handle_timeout_event(const ble_evt_t &evt);
static const size_t max_procedures_count =
CENTRAL_LINK_COUNT + PERIPHERAL_LINK_COUNT;
// Note: Ideally we would have used an array of variant here
GattProcedure* _procedures[max_procedures_count];
};
} // nordic
} // vendor
} // pal
} // ble
#endif /* BLE_NORDIC_PAL_GATT_CLIENT_H_ */

View File

@ -1,325 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 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 "nRF5xCharacteristicDescriptorDiscoverer.h"
#include "headers/nrf_ble_err.h"
#include "ble/DiscoveredCharacteristicDescriptor.h"
nRF5xCharacteristicDescriptorDiscoverer::nRF5xCharacteristicDescriptorDiscoverer() :
discoveryRunning() {
// nothing to do
}
nRF5xCharacteristicDescriptorDiscoverer::~nRF5xCharacteristicDescriptorDiscoverer() {
// nothing to do
}
ble_error_t nRF5xCharacteristicDescriptorDiscoverer::launch(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
) {
Gap::Handle_t connHandle = characteristic.getConnectionHandle();
// it is ok to deduce that the start handle for descriptors is after
// the characteristic declaration and the characteristic value declaration
// see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] (3.3)
Gap::Handle_t descriptorStartHandle = characteristic.getDeclHandle() + 2;
Gap::Handle_t descriptorEndHandle = characteristic.getLastHandle();
// check if there is any descriptor to discover
if (descriptorEndHandle < descriptorStartHandle) {
CharacteristicDescriptorDiscovery::TerminationCallbackParams_t termParams = {
characteristic,
BLE_ERROR_NONE
};
terminationCallback.call(&termParams);
return BLE_ERROR_NONE;
}
// check if we can run this discovery
if (isConnectionInUse(connHandle)) {
return BLE_STACK_BUSY;
}
// get a new discovery slot, if none are available, just return
Discovery* discovery = getAvailableDiscoverySlot();
if(discovery == NULL) {
return BLE_STACK_BUSY;
}
// try to launch the discovery
ble_error_t err = gattc_descriptors_discover(connHandle, descriptorStartHandle, descriptorEndHandle);
if(!err) {
// commit the new discovery to its slot
*discovery = Discovery(characteristic, discoveryCallback, terminationCallback);
}
return err;
}
bool nRF5xCharacteristicDescriptorDiscoverer::isActive(const DiscoveredCharacteristic& characteristic) const {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if(discoveryRunning[i].getCharacteristic() == characteristic) {
return true;
}
}
return false;
}
void nRF5xCharacteristicDescriptorDiscoverer::requestTerminate(const DiscoveredCharacteristic& characteristic) {
Discovery* discovery = findRunningDiscovery(characteristic);
if(discovery) {
// call terminate anyway
terminate(discovery, BLE_ERROR_NONE);
}
}
void nRF5xCharacteristicDescriptorDiscoverer::process(uint16_t connectionHandle, const ble_gattc_evt_desc_disc_rsp_t& descriptors) {
Discovery* discovery = findRunningDiscovery(connectionHandle);
// the discovery has been removed
if(!discovery) {
return;
}
for (uint16_t i = 0; i < descriptors.count; ++i) {
const ble_gattc_desc_t& desc = descriptors.descs[i];
const ble_uuid_t& uuid = desc.uuid;
if (uuid.type == BLE_UUID_TYPE_BLE) {
discovery->process(
desc.handle, UUID(uuid.uuid)
);
} else {
// discover attribute infos of the descriptor
ble_error_t err = gattc_attr_info_discover(connectionHandle, desc.handle, desc.handle);
if (err) {
terminate(discovery, err);
}
return;
}
}
// prepare the next discovery request (if needed)
uint16_t startHandle = descriptors.descs[descriptors.count - 1].handle + 1;
uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
if(startHandle > endHandle) {
terminate(discovery, BLE_ERROR_NONE);
return;
}
ble_error_t err = gattc_descriptors_discover(connectionHandle, startHandle, endHandle);
if(err) {
terminate(discovery, err);
return;
}
}
void nRF5xCharacteristicDescriptorDiscoverer::processAttributeInformation(
uint16_t connectionHandle, const ble_gattc_evt_attr_info_disc_rsp_t& infos) {
Discovery* discovery = findRunningDiscovery(connectionHandle);
// the discovery has been removed
if(!discovery) {
return;
}
#if (NRF_SD_BLE_API_VERSION <= 2)
// for all UUIDS found, process the discovery
for (uint16_t i = 0; i < infos.count; ++i) {
bool use_16bits_uuids = infos.format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT;
const ble_gattc_attr_info_t& attr_info = infos.attr_info[i];
UUID uuid = use_16bits_uuids ? UUID(attr_info.info.uuid16.uuid) : UUID(attr_info.info.uuid128.uuid128, UUID::LSB);
discovery->process(attr_info.handle, uuid);
}
// prepare the next round of descriptors discovery
uint16_t startHandle = infos.attr_info[infos.count - 1].handle + 1;
#else
uint16_t startHandle;
// for all UUIDS found, process the discovery
if (infos.format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT) {
for (uint16_t i = 0; i < infos.count; ++i) {
UUID uuid = UUID(infos.info.attr_info16[i].uuid.uuid);
discovery->process(infos.info.attr_info16[i].handle, uuid);
}
// prepare the next round of descriptors discovery
startHandle = infos.info.attr_info16[infos.count - 1].handle + 1;
} else {
for (uint16_t i = 0; i < infos.count; ++i) {
UUID uuid = UUID(infos.info.attr_info128[i].uuid.uuid128, UUID::LSB);
discovery->process(infos.info.attr_info128[i].handle, uuid);
}
// prepare the next round of descriptors discovery
startHandle = infos.info.attr_info128[infos.count - 1].handle + 1;
}
#endif
uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
if(startHandle > endHandle) {
terminate(discovery, BLE_ERROR_NONE);
return;
}
ble_error_t err = gattc_descriptors_discover(connectionHandle, startHandle, endHandle);
if(err) {
terminate(discovery, err);
return;
}
}
void nRF5xCharacteristicDescriptorDiscoverer::terminate(uint16_t handle, ble_error_t err) {
Discovery* discovery = findRunningDiscovery(handle);
// the discovery has already been terminated
if(!discovery) {
return;
}
terminate(discovery, err);
}
void nRF5xCharacteristicDescriptorDiscoverer::terminate(Discovery* discovery, ble_error_t err) {
// temporary copy, user code can try to launch a new discovery in the onTerminate
// callback. So, this discovery should not appear in such case.
Discovery tmp = *discovery;
*discovery = Discovery();
tmp.terminate(err);
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(const DiscoveredCharacteristic& characteristic) {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if((discoveryRunning[i].getCharacteristic() == characteristic) &&
(discoveryRunning[i].isEmpty() == false)) {
return &discoveryRunning[i];
}
}
return NULL;
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(uint16_t handle) {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if((discoveryRunning[i].getCharacteristic().getConnectionHandle() == handle) &&
(discoveryRunning[i].isEmpty() == false)) {
return &discoveryRunning[i];
}
}
return NULL;
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::getAvailableDiscoverySlot() {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if(discoveryRunning[i].isEmpty()) {
return &discoveryRunning[i];
}
}
return NULL;
}
bool nRF5xCharacteristicDescriptorDiscoverer::isConnectionInUse(uint16_t connHandle) {
return findRunningDiscovery(connHandle) != NULL;
}
ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_descriptors_discover(
uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle) {
ble_gattc_handle_range_t discoveryRange = {
start_handle,
end_handle
};
uint32_t err = sd_ble_gattc_descriptors_discover(connection_handle, &discoveryRange);
switch(err) {
case NRF_SUCCESS:
return BLE_ERROR_NONE;
case BLE_ERROR_INVALID_CONN_HANDLE:
return BLE_ERROR_INVALID_PARAM;
case NRF_ERROR_INVALID_ADDR:
return BLE_ERROR_PARAM_OUT_OF_RANGE;
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
default:
return BLE_ERROR_UNSPECIFIED;
}
}
ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_attr_info_discover(
uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle) {
ble_gattc_handle_range_t handle_range = { start_handle, end_handle };
uint32_t err = sd_ble_gattc_attr_info_discover(connection_handle, &handle_range);
switch(err) {
case NRF_SUCCESS:
return BLE_ERROR_NONE;
case BLE_ERROR_INVALID_CONN_HANDLE:
return BLE_ERROR_INVALID_PARAM;
case NRF_ERROR_INVALID_ADDR:
return BLE_ERROR_PARAM_OUT_OF_RANGE;
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
case NRF_ERROR_INVALID_STATE:
return BLE_ERROR_INVALID_STATE;
default:
return BLE_ERROR_UNSPECIFIED;
}
}
// implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery
nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery() :
characteristic(), onDiscovery(), onTerminate() {
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery(
const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
characteristic(c), onDiscovery(dCb), onTerminate(tCb) {
}
void nRF5xCharacteristicDescriptorDiscoverer::Discovery::process(
GattAttribute::Handle_t handle, const UUID& uuid) {
CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
characteristic,
DiscoveredCharacteristicDescriptor(
characteristic.getGattClient(),
characteristic.getConnectionHandle(),
handle,
uuid
)
};
onDiscovery.call(&params);
}
void nRF5xCharacteristicDescriptorDiscoverer::Discovery::terminate(ble_error_t err) {
CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
characteristic,
err
};
onTerminate.call(&params);
}
bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const {
return *this == Discovery();
}
const DiscoveredCharacteristic& nRF5xCharacteristicDescriptorDiscoverer::Discovery::getCharacteristic() const {
return characteristic;
}

View File

@ -1,227 +0,0 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 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 __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
#define __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
#include "ble/Gap.h"
#include "ble/DiscoveredCharacteristic.h"
#include "ble/CharacteristicDescriptorDiscovery.h"
#include "ble/GattClient.h"
#include "headers/nrf_ble_gattc.h"
/**
* @brief Manage the discovery of Characteristic descriptors
* @details is a bridge between BLE API and Nordic stack regarding Characteristic
* Descriptor discovery. The BLE API can launch, monitor and ask for termination
* of a discovery. The Nordic stack will provide new descriptors and indicate when
* the discovery is done.
*/
class nRF5xCharacteristicDescriptorDiscoverer
{
typedef CharacteristicDescriptorDiscovery::DiscoveryCallback_t DiscoveryCallback_t;
typedef CharacteristicDescriptorDiscovery::TerminationCallback_t TerminationCallback_t;
public:
/**
* @brief Construct a new characteristic descriptor discoverer.
*/
nRF5xCharacteristicDescriptorDiscoverer();
/**
* @brief Destroy a characteristic descriptor discoverer.
*/
~nRF5xCharacteristicDescriptorDiscoverer();
/**
* Launch a new characteristic descriptor discovery for a given DiscoveredCharacteristic.
* @param characteristic The characteristic owning the descriptors to discover.
* @param discoveryCallback The callback called when a descriptor is discovered.
* @param terminationCallback The callback called when the discovery process end.
* @return BLE_ERROR_NONE if characteristic descriptor discovery is launched successfully;
* else an appropriate error.
* @note: this will be called by BLE API side.
*/
ble_error_t launch(
const DiscoveredCharacteristic& characteristic,
const DiscoveryCallback_t& discoveryCallback,
const TerminationCallback_t& terminationCallback
);
/**
* @brief indicate if a characteristic descriptor discovery is active for a
* given DiscoveredCharacteristic.
* @param characteristic The characteristic for whom the descriptor might be
* currently discovered.
* @return true if descriptors of characteristic are discovered, false otherwise.
* @note: this will be called by BLE API side.
*/
bool isActive(const DiscoveredCharacteristic& characteristic) const;
/**
* @brief request the termination of characteristic descriptor discovery
* for a give DiscoveredCharacteristic
* @param characteristic The characteristic for whom the descriptor discovery
* should be stopped.
* @note: this will be called by BLE API side.
*/
void requestTerminate(const DiscoveredCharacteristic& characteristic);
/**
* @brief process descriptors discovered from the Nordic stack.
* @param connectionHandle The connection handle upon which descriptors has been
* discovered.
* @param descriptors Discovered descriptors.
* @note This will be called by the Nordic stack.
*/
void process(uint16_t connectionHandle, const ble_gattc_evt_desc_disc_rsp_t& descriptors);
/**
* @brief Called by the Nordic stack when the discovery is over.
* @param The connection handle upon which the discovery process is done.
* @param err An error if the termination is due to an error.
*/
void terminate(uint16_t connectionHandle, ble_error_t err);
/**
* @brief process attribute informations from the Nordic stack.
* @param connectionHandle The connection handle upon which
* attribute informations has been fetch.
* @param infos Informations around attribute, in that case the
* 128bit UUID of a descriptor.
* @note This will be called by the Nordic stack.
*/
void processAttributeInformation(uint16_t handle, const ble_gattc_evt_attr_info_disc_rsp_t& infos);
private:
// protection against copy construction and assignment
nRF5xCharacteristicDescriptorDiscoverer(const nRF5xCharacteristicDescriptorDiscoverer&);
nRF5xCharacteristicDescriptorDiscoverer& operator=(const nRF5xCharacteristicDescriptorDiscoverer&);
/**
* @brief Discovery process, it store the DiscoveredCharacteristic, the
* discovery callback and the termination callback.
*/
class Discovery {
public:
/**
* @brief Construct an empty discovery, such can be considerate as a not running discovery.
* @note #isEmpty function will return true
*/
Discovery();
/**
* @brief Construct a valid discovery process.
*
* @param c the characteristic from whom descriptors will be discovered.
* @param dCb The discovery callback called each time a descriptor is discovered.
* @param tCb The termination callback called when the discovery terminate.
*
* @note #isEmpty function will return false
*/
Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb);
/**
* @brief Process the discovery of a descriptor.
*
* @param handle The attribute handle of the descriptor found
* @param uuid The UUID of the descriptor found.
*/
void process(GattAttribute::Handle_t handle, const UUID& uuid);
/**
* @brief Terminate the discovery process.
*
* @param err Error associate with the termination
* @note after this call #isEmpty function will return true.
*/
void terminate(ble_error_t err);
/**
* @brief check if the discovery process is empty or not. Empty discovery are
* not running.
*
* @detail Discovery are empty after:
* - a default construction
* - a copy construction form a default constructed
* - an assignment from a default constructed Discovery
* @return true if the Discovery is empty and false otherwise.
*/
bool isEmpty() const;
/**
* @brief return the characteristic from whom descriptors are discovered.
* @return the characteristic from whom descriptors are discovered.
*/
const DiscoveredCharacteristic& getCharacteristic() const;
/**
* @brief equal to operator, test if two discovery process are equal
*
* @param lhs left hand side of the expression
* @param rhs right hand side of the expression
* @return true if lhs == rhs
*/
friend bool operator==(const Discovery& lhs, const Discovery& rhs) {
return lhs.characteristic == rhs.characteristic &&
lhs.onDiscovery == rhs.onDiscovery &&
lhs.onTerminate == rhs.onTerminate;
}
/**
* @brief not equal to operator, test if two discovery process are not equal
*
* @param lhs left hand side of the expression
* @param rhs right hand side of the expression
* @return true if lhs != rhs
*/
friend bool operator!=(const Discovery& lhs, const Discovery& rhs) {
return !(lhs == rhs);
}
private:
DiscoveredCharacteristic characteristic;
DiscoveryCallback_t onDiscovery;
TerminationCallback_t onTerminate;
};
// find a running discovery process
Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic);
Discovery* findRunningDiscovery(uint16_t handle);
// Called to terminate a discovery is over.
void terminate(Discovery* discovery, ble_error_t err);
// get one slot for a discovery process
Discovery* getAvailableDiscoverySlot();
// indicate if a connection is already running a discovery
bool isConnectionInUse(uint16_t connHandle);
// low level start of a discovery
static ble_error_t gattc_descriptors_discover(uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle);
// discovery of 128bits UUIDS
static ble_error_t gattc_attr_info_discover(uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle);
// count of concurrent connections which can run a descriptor discovery process
static const size_t MAXIMUM_CONCURRENT_CONNECTIONS_COUNT = 3;
// array of running discoveries
Discovery discoveryRunning[MAXIMUM_CONCURRENT_CONNECTIONS_COUNT];
};
#endif /*__NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__*/

View File

@ -1,63 +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 "nRF5xDiscoveredCharacteristic.h"
#include "nRF5xGattClient.h"
#include "headers/nrf_ble_gatt.h"
void
nRF5xDiscoveredCharacteristic::setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
{
gattc = gattcIn;
connHandle = connectionHandleIn;
declHandle = declHandleIn;
valueHandle = valueHandleIn;
props._broadcast = propsIn.broadcast;
props._read = propsIn.read;
props._writeWoResp = propsIn.write_wo_resp;
props._write = propsIn.write;
props._notify = propsIn.notify;
props._indicate = propsIn.indicate;
props._authSignedWrite = propsIn.auth_signed_wr;
}
void
nRF5xDiscoveredCharacteristic::setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
UUID::ShortUUIDBytes_t uuidIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn)
{
gattc = gattcIn;
connHandle = connectionHandleIn;
uuid = uuidIn;
declHandle = declHandleIn;
valueHandle = valueHandleIn;
props._broadcast = propsIn.broadcast;
props._read = propsIn.read;
props._writeWoResp = propsIn.write_wo_resp;
props._write = propsIn.write;
props._notify = propsIn.notify;
props._indicate = propsIn.indicate;
props._authSignedWrite = propsIn.auth_signed_wr;
}

View File

@ -1,45 +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 __NRF_DISCOVERED_CHARACTERISTIC_H__
#define __NRF_DISCOVERED_CHARACTERISTIC_H__
#include "ble/DiscoveredCharacteristic.h"
#include "headers/nrf_ble_gatt.h"
class nRF5xGattClient; /* forward declaration */
class nRF5xDiscoveredCharacteristic : public DiscoveredCharacteristic {
public:
void setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn);
void setup(nRF5xGattClient *gattcIn,
Gap::Handle_t connectionHandleIn,
UUID::ShortUUIDBytes_t uuidIn,
ble_gatt_char_props_t propsIn,
GattAttribute::Handle_t declHandleIn,
GattAttribute::Handle_t valueHandleIn);
void setLastHandle(GattAttribute::Handle_t last) {
lastHandle = last;
}
};
#endif /* __NRF_DISCOVERED_CHARACTERISTIC_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.
*/
#include "nRF5xGattClient.h"
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
ble_error_t
nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUIDIn,
const UUID &matchingCharacteristicUUIDIn)
{
return _discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
}
ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback)
{
return _characteristicDescriptorDiscoverer.launch(
characteristic,
discoveryCallback,
terminationCallback
);
}
bool nRF5xGattClient::isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const {
return _characteristicDescriptorDiscoverer.isActive(characteristic);
}
void nRF5xGattClient::terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic) {
return _characteristicDescriptorDiscoverer.requestTerminate(characteristic);
}
#endif

View File

@ -1,218 +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 __NRF51822_GATT_CLIENT_H__
#define __NRF51822_GATT_CLIENT_H__
#include "ble/GattClient.h"
#include "nRF5xServiceDiscovery.h"
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
class nRF5xGattClient : public GattClient
{
public:
/**
* When using S110, all Gatt client features will return
* BLE_ERROR_NOT_IMPLEMENTED
*/
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
/**
* Launch service discovery. Once launched, service discovery will remain
* active with callbacks being issued back into the application for matching
* services/characteristics. isActive() can be used to determine status; and
* a termination callback (if setup) will be invoked at the end. Service
* discovery can be terminated prematurely if needed using terminate().
*
* @param connectionHandle
* Handle for the connection with the peer.
* @param sc
* This is the application callback for matching service. Taken as
* NULL by default. Note: service discovery may still be active
* when this callback is issued; calling asynchronous BLE-stack
* APIs from within this application callback might cause the
* stack to abort service discovery. If this becomes an issue, it
* may be better to make local copy of the discoveredService and
* wait for service discovery to terminate before operating on the
* service.
* @param cc
* This is the application callback for matching characteristic.
* Taken as NULL by default. Note: service discovery may still be
* active when this callback is issued; calling asynchronous
* BLE-stack APIs from within this application callback might cause
* the stack to abort service discovery. If this becomes an issue,
* it may be better to make local copy of the discoveredCharacteristic
* and wait for service discovery to terminate before operating on the
* characteristic.
* @param matchingServiceUUID
* UUID based filter for specifying a service in which the application is
* interested. By default it is set as the wildcard UUID_UNKNOWN,
* in which case it matches all services. If characteristic-UUID
* filter (below) is set to the wildcard value, then a service
* callback will be invoked for the matching service (or for every
* service if the service filter is a wildcard).
* @param matchingCharacteristicUUIDIn
* UUID based filter for specifying characteristic in which the application
* is interested. By default it is set as the wildcard UUID_UKNOWN
* to match against any characteristic. If both service-UUID
* filter and characteristic-UUID filter are used with non- wildcard
* values, then only a single characteristic callback is
* invoked for the matching characteristic.
*
* @Note Using wildcard values for both service-UUID and characteristic-
* UUID will result in complete service discovery--callbacks being
* called for every service and characteristic.
*
* @return
* BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
*/
virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc = NULL,
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
_discovery.onTermination(callback);
}
/**
* Is service-discovery currently active?
*/
virtual bool isServiceDiscoveryActive(void) const {
return _discovery.isActive();
}
/**
* Terminate an ongoing service-discovery. This should result in an
* invocation of the TerminationCallback if service-discovery is active.
*/
virtual void terminateServiceDiscovery(void) {
_discovery.terminate();
}
/**
* @brief Implementation of GattClient::discoverCharacteristicDescriptors
* @see GattClient::discoverCharacteristicDescriptors
*/
virtual ble_error_t discoverCharacteristicDescriptors(
const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
);
/**
* @brief Implementation of GattClient::isCharacteristicDiscoveryActive
* @see GattClient::isCharacteristicDiscoveryActive
*/
virtual bool isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const;
/**
* @brief Implementation of GattClient::terminateCharacteristicDiscovery
* @see GattClient::terminateCharacteristicDiscovery
*/
virtual void terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic);
virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
uint32_t rc = sd_ble_gattc_read(connHandle, attributeHandle, offset);
if (rc == NRF_SUCCESS) {
return BLE_ERROR_NONE;
}
switch (rc) {
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
case BLE_ERROR_INVALID_CONN_HANDLE:
case NRF_ERROR_INVALID_STATE:
case NRF_ERROR_INVALID_ADDR:
default:
return BLE_ERROR_INVALID_STATE;
}
}
virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, size_t length, const uint8_t *value) const {
ble_gattc_write_params_t writeParams;
writeParams.write_op = cmd;
writeParams.flags = 0; /* this is inconsequential */
writeParams.handle = attributeHandle;
writeParams.offset = 0;
writeParams.len = length;
writeParams.p_value = const_cast<uint8_t *>(value);
uint32_t rc = sd_ble_gattc_write(connHandle, &writeParams);
if (rc == NRF_SUCCESS) {
return BLE_ERROR_NONE;
}
switch (rc) {
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
case BLE_ERROR_NO_TX_PACKETS:
return BLE_ERROR_NO_MEM;
case BLE_ERROR_INVALID_CONN_HANDLE:
case NRF_ERROR_INVALID_STATE:
case NRF_ERROR_INVALID_ADDR:
default:
return BLE_ERROR_INVALID_STATE;
}
}
/**
* @brief Clear nRF5xGattClient's state.
*
* @return
* BLE_ERROR_NONE if successful.
*/
virtual ble_error_t reset(void) {
/* Clear all state that is from the parent, including private members */
if (GattClient::reset() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}
/* Clear derived class members */
_discovery.reset();
return BLE_ERROR_NONE;
}
public:
/*
* Allow instantiation from nRF5xn when required.
*/
friend class nRF5xn;
nRF5xGattClient() : _discovery(this) {
/* empty */
}
nRF5xServiceDiscovery& discovery() {
return _discovery;
}
nRF5xCharacteristicDescriptorDiscoverer& characteristicDescriptorDiscoverer() {
return _characteristicDescriptorDiscoverer;
}
private:
nRF5xGattClient(const nRF5xGattClient &);
const nRF5xGattClient& operator=(const nRF5xGattClient &);
private:
nRF5xServiceDiscovery _discovery;
nRF5xCharacteristicDescriptorDiscoverer _characteristicDescriptorDiscoverer;
#endif // if !S110
};
#endif // ifndef __NRF51822_GATT_CLIENT_H__

View File

@ -1,329 +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 "nRF5xServiceDiscovery.h"
ble_error_t
nRF5xServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connectionHandle,
Gap::Handle_t startHandle,
Gap::Handle_t endHandle)
{
characteristicDiscoveryStarted(connectionHandle);
ble_gattc_handle_range_t handleRange = {
(uint16_t) startHandle,
(uint16_t) endHandle
};
uint32_t rc = sd_ble_gattc_characteristics_discover(connectionHandle, &handleRange);
ble_error_t err = BLE_ERROR_NONE;
switch (rc) {
case NRF_SUCCESS:
err = BLE_ERROR_NONE;
break;
case BLE_ERROR_INVALID_CONN_HANDLE:
case NRF_ERROR_INVALID_ADDR:
err = BLE_ERROR_INVALID_PARAM;
break;
case NRF_ERROR_BUSY:
err = BLE_STACK_BUSY;
break;
case NRF_ERROR_INVALID_STATE:
err = BLE_ERROR_INVALID_STATE;
break;
default:
err = BLE_ERROR_UNSPECIFIED;
break;
}
if (err) {
terminateCharacteristicDiscovery(err);
}
return err;
}
void
nRF5xServiceDiscovery::setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response)
{
serviceIndex = 0;
numServices = response->count;
/* Account for the limitation on the number of discovered services we can handle at a time. */
if (numServices > BLE_DB_DISCOVERY_MAX_SRV) {
numServices = BLE_DB_DISCOVERY_MAX_SRV;
}
serviceUUIDDiscoveryQueue.reset();
for (unsigned i = 0; i < numServices; ++i) {
if (response->services[i].uuid.type == BLE_UUID_TYPE_UNKNOWN) {
serviceUUIDDiscoveryQueue.enqueue(i);
services[i].setup(response->services[i].handle_range.start_handle,
response->services[i].handle_range.end_handle);
} else {
services[i].setup(response->services[i].uuid.uuid,
response->services[i].handle_range.start_handle,
response->services[i].handle_range.end_handle);
}
}
/* Trigger discovery of service UUID if necessary. */
if (serviceUUIDDiscoveryQueue.getCount()) {
serviceUUIDDiscoveryQueue.triggerFirst();
}
}
void
nRF5xServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response)
{
numCharacteristics = response->count;
/* Account for the limitation on the number of discovered characteristics we can handle at a time. */
if (numCharacteristics > BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV) {
numCharacteristics = BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV;
}
charUUIDDiscoveryQueue.reset();
for (unsigned charIndex = 0; charIndex < numCharacteristics; charIndex++) {
if (response->chars[charIndex].uuid.type == BLE_UUID_TYPE_UNKNOWN) {
charUUIDDiscoveryQueue.enqueue(charIndex);
characteristics[charIndex].setup(gattc,
connHandle,
response->chars[charIndex].char_props,
response->chars[charIndex].handle_decl,
response->chars[charIndex].handle_value);
} else {
characteristics[charIndex].setup(gattc,
connHandle,
response->chars[charIndex].uuid.uuid,
response->chars[charIndex].char_props,
response->chars[charIndex].handle_decl,
response->chars[charIndex].handle_value);
}
}
/* Trigger discovery of char UUID if necessary. */
if (charUUIDDiscoveryQueue.getCount()) {
charUUIDDiscoveryQueue.triggerFirst();
}
}
void
nRF5xServiceDiscovery::progressCharacteristicDiscovery(void)
{
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
if ((discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) && (numCharacteristics > 0)) {
discoveredCharacteristic.setLastHandle(characteristics[0].getDeclHandle() - 1);
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&discoveredCharacteristic);
}
}
}
for (uint8_t i = 0; i < numCharacteristics; ++i) {
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
if (i == (numCharacteristics - 1)) {
discoveredCharacteristic = characteristics[i];
break;
} else {
characteristics[i].setLastHandle(characteristics[i + 1].getDeclHandle() - 1);
}
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == characteristics[i].getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&characteristics[i]);
}
}
}
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
Gap::Handle_t startHandle = (numCharacteristics > 0) ? characteristics[numCharacteristics - 1].getValueHandle() + 1 : SRV_DISC_END_HANDLE;
Gap::Handle_t endHandle = services[serviceIndex].getEndHandle();
resetDiscoveredCharacteristics(); /* Note: resetDiscoveredCharacteristics() must come after fetching start and end Handles. */
if (startHandle < endHandle) {
ble_gattc_handle_range_t handleRange = {
(uint16_t) startHandle,
(uint16_t) endHandle
};
if (sd_ble_gattc_characteristics_discover(connHandle, &handleRange) != NRF_SUCCESS) {
terminateCharacteristicDiscovery(BLE_ERROR_UNSPECIFIED);
}
} else {
terminateCharacteristicDiscovery(BLE_ERROR_NONE);
}
}
void
nRF5xServiceDiscovery::progressServiceDiscovery(void)
{
/* Iterate through the previously discovered services cached in services[]. */
while ((state == SERVICE_DISCOVERY_ACTIVE) && (serviceIndex < numServices)) {
if ((matchingServiceUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
(matchingServiceUUID == services[serviceIndex].getUUID())) {
if (serviceCallback && (matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN))) {
serviceCallback(&services[serviceIndex]);
}
if ((state == SERVICE_DISCOVERY_ACTIVE) && characteristicCallback) {
launchCharacteristicDiscovery(connHandle, services[serviceIndex].getStartHandle(), services[serviceIndex].getEndHandle());
} else {
serviceIndex++;
}
} else {
serviceIndex++;
}
}
/* Relaunch discovery of new services beyond the last entry cached in services[]. */
if ((state == SERVICE_DISCOVERY_ACTIVE) && (numServices > 0) && (serviceIndex > 0)) {
/* Determine the ending handle of the last cached service. */
Gap::Handle_t endHandle = services[serviceIndex - 1].getEndHandle();
resetDiscoveredServices(); /* Note: resetDiscoveredServices() must come after fetching endHandle. */
if (endHandle == SRV_DISC_END_HANDLE) {
terminateServiceDiscovery();
} else {
// the next service is located after the last handle discovered
// Launch a new discovery from [endHandle + 1 : 0xFFFF]
if (sd_ble_gattc_primary_services_discover(connHandle, endHandle + 1, NULL) != NRF_SUCCESS) {
terminateServiceDiscovery();
}
}
}
}
void
nRF5xServiceDiscovery::ServiceUUIDDiscoveryQueue::triggerFirst(void)
{
while (numIndices) { /* loop until a call to char_value_by_uuid_read() succeeds or we run out of pending indices. */
parentDiscoveryObject->state = DISCOVER_SERVICE_UUIDS;
unsigned serviceIndex = getFirst();
ble_uuid_t uuid = {
.uuid = BLE_UUID_SERVICE_PRIMARY,
.type = BLE_UUID_TYPE_BLE,
};
ble_gattc_handle_range_t handleRange = {
.start_handle = parentDiscoveryObject->services[serviceIndex].getStartHandle(),
.end_handle = parentDiscoveryObject->services[serviceIndex].getEndHandle(),
};
if (sd_ble_gattc_char_value_by_uuid_read(parentDiscoveryObject->connHandle, &uuid, &handleRange) == NRF_SUCCESS) {
return;
}
/* Skip this service if we fail to launch a read for its service-declaration
* attribute. Its UUID will remain INVALID, and it may not match any filters. */
dequeue();
}
/* Switch back to service discovery upon exhausting the service-indices pending UUID discovery. */
if (parentDiscoveryObject->state == DISCOVER_SERVICE_UUIDS) {
parentDiscoveryObject->state = SERVICE_DISCOVERY_ACTIVE;
}
}
void
nRF5xServiceDiscovery::CharUUIDDiscoveryQueue::triggerFirst(void)
{
while (numIndices) { /* loop until a call to char_value_by_uuid_read() succeeds or we run out of pending indices. */
parentDiscoveryObject->state = DISCOVER_CHARACTERISTIC_UUIDS;
unsigned charIndex = getFirst();
ble_uuid_t uuid = {
.uuid = BLE_UUID_CHARACTERISTIC,
.type = BLE_UUID_TYPE_BLE,
};
ble_gattc_handle_range_t handleRange = { };
handleRange.start_handle = parentDiscoveryObject->characteristics[charIndex].getDeclHandle();
handleRange.end_handle = parentDiscoveryObject->characteristics[charIndex].getDeclHandle() + 1;
if (sd_ble_gattc_char_value_by_uuid_read(parentDiscoveryObject->connHandle, &uuid, &handleRange) == NRF_SUCCESS) {
return;
}
/* Skip this service if we fail to launch a read for its service-declaration
* attribute. Its UUID will remain INVALID, and it may not match any filters. */
dequeue();
}
/* Switch back to service discovery upon exhausting the service-indices pending UUID discovery. */
if (parentDiscoveryObject->state == DISCOVER_CHARACTERISTIC_UUIDS) {
parentDiscoveryObject->state = CHARACTERISTIC_DISCOVERY_ACTIVE;
}
}
void
nRF5xServiceDiscovery::processDiscoverUUIDResponse(const ble_gattc_evt_t *p_gattc_evt)
{
const ble_gattc_evt_char_val_by_uuid_read_rsp_t * response = &p_gattc_evt->params.char_val_by_uuid_read_rsp;
if (state == DISCOVER_SERVICE_UUIDS) {
if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID)) {
UUID::LongUUIDBytes_t uuid;
#if (NRF_SD_BLE_API_VERSION >= 3)
ble_gattc_handle_value_t iter;
memset(&iter, 0, sizeof(ble_gattc_handle_value_t));
(void) sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(const_cast<ble_gattc_evt_t*>(p_gattc_evt), &iter);
memcpy(uuid, iter.p_value, UUID::LENGTH_OF_LONG_UUID);
#else
memcpy(uuid, &(response->handle_value[0].p_value[0]), UUID::LENGTH_OF_LONG_UUID);
#endif
unsigned serviceIndex = serviceUUIDDiscoveryQueue.dequeue();
services[serviceIndex].setupLongUUID(uuid, UUID::LSB);
serviceUUIDDiscoveryQueue.triggerFirst();
} else {
serviceUUIDDiscoveryQueue.dequeue();
}
} else if (state == DISCOVER_CHARACTERISTIC_UUIDS) {
if ((response->count == 1) && (response->value_len == UUID::LENGTH_OF_LONG_UUID + 1 /* props */ + 2 /* value handle */)) {
UUID::LongUUIDBytes_t uuid;
#if (NRF_SD_BLE_API_VERSION >= 3)
ble_gattc_handle_value_t iter;
memset(&iter, 0, sizeof(ble_gattc_handle_value_t));
(void) sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(const_cast<ble_gattc_evt_t*>(p_gattc_evt), &iter);
memcpy(uuid, &(iter.p_value[3]), UUID::LENGTH_OF_LONG_UUID);
#else
memcpy(uuid, &(response->handle_value[0].p_value[3]), UUID::LENGTH_OF_LONG_UUID);
#endif
unsigned charIndex = charUUIDDiscoveryQueue.dequeue();
characteristics[charIndex].setupLongUUID(uuid, UUID::LSB);
charUUIDDiscoveryQueue.triggerFirst();
} else {
charUUIDDiscoveryQueue.dequeue();
}
}
}

View File

@ -1,366 +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 __NRF_SERVICE_DISCOVERY_H__
#define __NRF_SERVICE_DISCOVERY_H__
#include "ble/ServiceDiscovery.h"
#include "ble/DiscoveredService.h"
#include "nRF5xDiscoveredCharacteristic.h"
#include "headers/nrf_ble.h"
#include "headers/nrf_ble_gattc.h"
class nRF5xGattClient; /* forward declaration */
class nRF5xServiceDiscovery : public ServiceDiscovery
{
public:
static const uint16_t SRV_DISC_START_HANDLE = 0x0001; /**< The start handle value used during service discovery. */
static const uint16_t SRV_DISC_END_HANDLE = 0xFFFF; /**< The end handle value used during service discovery. */
public:
static const unsigned BLE_DB_DISCOVERY_MAX_SRV = 4; /**< Maximum number of services we can retain information for after a single discovery. */
static const unsigned BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV = 4; /**< Maximum number of characteristics per service we can retain information for. */
public:
nRF5xServiceDiscovery(nRF5xGattClient *gattcIn) :
gattc(gattcIn),
serviceIndex(0),
numServices(0),
numCharacteristics(0),
state(INACTIVE),
services(),
characteristics(),
serviceUUIDDiscoveryQueue(this),
charUUIDDiscoveryQueue(this),
onTerminationCallback(NULL) {
/* empty */
}
virtual ble_error_t launch(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t sc,
ServiceDiscovery::CharacteristicCallback_t cc,
const UUID &matchingServiceUUIDIn,
const UUID &matchingCharacteristicUUIDIn)
{
if (isActive()) {
return BLE_ERROR_INVALID_STATE;
}
serviceCallback = sc;
characteristicCallback = cc;
matchingServiceUUID = matchingServiceUUIDIn;
matchingCharacteristicUUID = matchingCharacteristicUUIDIn;
serviceDiscoveryStarted(connectionHandle);
uint32_t rc;
if ((rc = sd_ble_gattc_primary_services_discover(connectionHandle, SRV_DISC_START_HANDLE, NULL)) != NRF_SUCCESS) {
terminate();
switch (rc) {
case NRF_ERROR_INVALID_PARAM:
case BLE_ERROR_INVALID_CONN_HANDLE:
return BLE_ERROR_INVALID_PARAM;
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
default:
case NRF_ERROR_INVALID_STATE:
return BLE_ERROR_INVALID_STATE;
}
}
return BLE_ERROR_NONE;
}
virtual bool isActive(void) const {
return state != INACTIVE;
}
virtual void terminate(void) {
terminateServiceDiscovery();
}
void terminate(Gap::Handle_t connectionHandle) {
if(connHandle == connectionHandle) {
terminate();
}
}
virtual void onTermination(ServiceDiscovery::TerminationCallback_t callback) {
onTerminationCallback = callback;
}
/**
* @brief Clear nRF5xServiceDiscovery's state.
*
* @return
* BLE_ERROR_NONE if successful.
*/
virtual ble_error_t reset(void) {
/* Clear all state that is from the parent, including private members */
if (ServiceDiscovery::reset() != BLE_ERROR_NONE) {
return BLE_ERROR_INVALID_STATE;
}
/* Clear derived class members */
serviceIndex = 0;
numServices = 0;
numCharacteristics = 0;
state = INACTIVE;
serviceUUIDDiscoveryQueue.reset();
charUUIDDiscoveryQueue.reset();
onTerminationCallback = NULL;
return BLE_ERROR_NONE;
}
private:
ble_error_t launchCharacteristicDiscovery(Gap::Handle_t connectionHandle, Gap::Handle_t startHandle, Gap::Handle_t endHandle);
private:
void setupDiscoveredServices(const ble_gattc_evt_prim_srvc_disc_rsp_t *response);
void setupDiscoveredCharacteristics(const ble_gattc_evt_char_disc_rsp_t *response);
void triggerServiceUUIDDiscovery(void);
void processDiscoverUUIDResponse(const ble_gattc_evt_t *p_gattc_evt);
void removeFirstServiceNeedingUUIDDiscovery(void);
void terminateServiceDiscovery(void) {
discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
bool wasActive = isActive();
state = INACTIVE;
if (wasActive && onTerminationCallback) {
onTerminationCallback(connHandle);
}
}
void terminateCharacteristicDiscovery(ble_error_t err) {
if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
if(discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) {
if(err == BLE_ERROR_NONE) {
// fullfill the last characteristic
discoveredCharacteristic.setLastHandle(services[serviceIndex].getEndHandle());
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&discoveredCharacteristic);
}
}
}
discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
}
state = SERVICE_DISCOVERY_ACTIVE;
}
serviceIndex++; /* Progress service index to keep discovery alive. */
}
private:
void resetDiscoveredServices(void) {
numServices = 0;
serviceIndex = 0;
}
void resetDiscoveredCharacteristics(void) {
numCharacteristics = 0;
}
private:
void serviceDiscoveryStarted(Gap::Handle_t connectionHandle) {
connHandle = connectionHandle;
resetDiscoveredServices();
state = SERVICE_DISCOVERY_ACTIVE;
}
private:
void characteristicDiscoveryStarted(Gap::Handle_t connectionHandle) {
connHandle = connectionHandle;
resetDiscoveredCharacteristics();
state = CHARACTERISTIC_DISCOVERY_ACTIVE;
}
private:
/**
* A datatype to contain service-indices for which long UUIDs need to be
* discovered using read_val_by_uuid().
*/
class ServiceUUIDDiscoveryQueue {
public:
ServiceUUIDDiscoveryQueue(nRF5xServiceDiscovery *parent) :
numIndices(0),
serviceIndices(),
parentDiscoveryObject(parent) {
/* empty */
}
public:
void reset(void) {
numIndices = 0;
for (unsigned i = 0; i < BLE_DB_DISCOVERY_MAX_SRV; i++) {
serviceIndices[i] = INVALID_INDEX;
}
}
void enqueue(int serviceIndex) {
serviceIndices[numIndices++] = serviceIndex;
}
int dequeue(void) {
if (numIndices == 0) {
return INVALID_INDEX;
}
unsigned valueToReturn = serviceIndices[0];
numIndices--;
for (unsigned i = 0; i < numIndices; i++) {
serviceIndices[i] = serviceIndices[i + 1];
}
return valueToReturn;
}
unsigned getFirst(void) const {
return serviceIndices[0];
}
size_t getCount(void) const {
return numIndices;
}
/**
* Trigger UUID discovery for the first of the enqueued ServiceIndices.
*/
void triggerFirst(void);
private:
static const int INVALID_INDEX = -1;
private:
size_t numIndices;
int serviceIndices[BLE_DB_DISCOVERY_MAX_SRV];
nRF5xServiceDiscovery *parentDiscoveryObject;
};
friend class ServiceUUIDDiscoveryQueue;
/**
* A datatype to contain characteristic-indices for which long UUIDs need to
* be discovered using read_val_by_uuid().
*/
class CharUUIDDiscoveryQueue {
public:
CharUUIDDiscoveryQueue(nRF5xServiceDiscovery *parent) :
numIndices(0),
charIndices(),
parentDiscoveryObject(parent) {
/* empty */
}
public:
void reset(void) {
numIndices = 0;
for (unsigned i = 0; i < BLE_DB_DISCOVERY_MAX_SRV; i++) {
charIndices[i] = INVALID_INDEX;
}
}
void enqueue(int serviceIndex) {
charIndices[numIndices++] = serviceIndex;
}
int dequeue(void) {
if (numIndices == 0) {
return INVALID_INDEX;
}
unsigned valueToReturn = charIndices[0];
numIndices--;
for (unsigned i = 0; i < numIndices; i++) {
charIndices[i] = charIndices[i + 1];
}
return valueToReturn;
}
unsigned getFirst(void) const {
return charIndices[0];
}
size_t getCount(void) const {
return numIndices;
}
/**
* Trigger UUID discovery for the first of the enqueued charIndices.
*/
void triggerFirst(void);
private:
static const int INVALID_INDEX = -1;
private:
size_t numIndices;
int charIndices[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
nRF5xServiceDiscovery *parentDiscoveryObject;
};
friend class CharUUIDDiscoveryQueue;
private:
friend void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
void progressCharacteristicDiscovery(void);
void progressServiceDiscovery(void);
private:
nRF5xGattClient *gattc;
private:
uint8_t serviceIndex; /**< Index of the current service being discovered. This is intended for internal use during service discovery.*/
uint8_t numServices; /**< Number of services at the peers GATT database.*/
uint8_t numCharacteristics; /**< Number of characteristics within the service.*/
enum State_t {
INACTIVE,
SERVICE_DISCOVERY_ACTIVE,
CHARACTERISTIC_DISCOVERY_ACTIVE,
DISCOVER_SERVICE_UUIDS,
DISCOVER_CHARACTERISTIC_UUIDS,
} state;
DiscoveredService services[BLE_DB_DISCOVERY_MAX_SRV]; /**< Information related to the current service being discovered.
* This is intended for internal use during service discovery. */
nRF5xDiscoveredCharacteristic characteristics[BLE_DB_DISCOVERY_MAX_CHAR_PER_SRV];
ServiceUUIDDiscoveryQueue serviceUUIDDiscoveryQueue;
CharUUIDDiscoveryQueue charUUIDDiscoveryQueue;
TerminationCallback_t onTerminationCallback;
/*
* The currently discovered characteristic. Discovery of a characteristic
* is a two phase process.
* First, declaration handle is fetched, it provide the UUID, the value handle and
* the properties of a characteristic.
* Second, the next declaration handle is fetched, with its declaration handle, it is
* possible to compute the last handle of the discovered characteristic and fill the
* missing part of the object.
* If there is no remaining characteristic to discover, the last handle of the
* discovered characteristic will be set to the last handle of its enclosing service.
*/
nRF5xDiscoveredCharacteristic discoveredCharacteristic;
};
#endif /*__NRF_SERVICE_DISCOVERY_H__*/

View File

@ -31,6 +31,8 @@ extern "C" {
#include "softdevice_handler.h"
}
#include "nRF5XPalGattClient.h"
/**
* The singleton which represents the nRF51822 transport for the BLE.
*/
@ -60,7 +62,7 @@ nRF5xn::nRF5xn(void) :
instanceID(BLE::DEFAULT_INSTANCE),
gapInstance(),
gattServerInstance(NULL),
gattClientInstance(NULL),
gattClient(&(ble::pal::vendor::nordic::nRF5XGattClient::get_client())),
securityManagerInstance(NULL)
{
}
@ -189,11 +191,9 @@ ble_error_t nRF5xn::shutdown(void)
/* S110 does not support BLE client features, nothing to reset. */
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
if (gattClientInstance != NULL) {
error = gattClientInstance->reset();
if (error != BLE_ERROR_NONE) {
return error;
}
error = getGattClient().reset();
if (error != BLE_ERROR_NONE) {
return error;
}
#endif

View File

@ -20,10 +20,10 @@
#include "ble/BLE.h"
#include "ble/blecommon.h"
#include "ble/BLEInstanceBase.h"
#include "ble/generic/GenericGattClient.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"
#include "nRF5xGattClient.h"
#include "nRF5xSecurityManager.h"
#include "btle.h"
@ -77,11 +77,8 @@ public:
*
* @return A reference to GattClient.
*/
virtual nRF5xGattClient &getGattClient() {
if (gattClientInstance == NULL) {
gattClientInstance = new nRF5xGattClient();
}
return *gattClientInstance;
virtual GattClient &getGattClient() {
return gattClient;
}
/**
@ -171,10 +168,8 @@ private:
* If NULL, then GattServer has not been initialized.
* The pointer has been declared as 'mutable' so that
* it can be assigned inside a 'const' function. */
mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
* If NULL, then GattClient has not been initialized.
* The pointer has been declared as 'mutable' so that
* it can be assigned inside a 'const' function. */
ble::generic::GenericGattClient gattClient;
mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
* If NULL, then SecurityManager has not been initialized.
* The pointer has been declared as 'mutable' so that

View File

@ -1,28 +1,28 @@
/*
/*
* Copyright (c) 2013 Nordic Semiconductor ASA
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list
*
* 1. Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
* integrated circuit in a product or a software update for such product, must reproduce
* the above copyright notice, this list of conditions and the following disclaimer in
* 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
* integrated circuit in a product or a software update for such product, must reproduce
* the above copyright notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* 4. This software, with or without modification, must only be used with a
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary or object form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* 5. Any software provided in binary or object form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -33,7 +33,7 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
@ -57,7 +57,7 @@
#include "app_error.h"
#include "app_util.h"
#define BLE_STACK_EVT_MSG_BUF_SIZE (sizeof(ble_evt_t) + (GATT_MTU_SIZE_DEFAULT)) /**< Size of BLE event message buffer. This will be provided to the SoftDevice while fetching an event. */
#define BLE_STACK_EVT_MSG_BUF_SIZE (sizeof(ble_evt_t) + (3 * sizeof(ble_gattc_attr_info_t)) + (GATT_MTU_SIZE_DEFAULT)) /**< Size of BLE event message buffer. This will be provided to the SoftDevice while fetching an event. */
#define BLE_STACK_HANDLER_SCHED_EVT_SIZE 0 /**< The size of the scheduler event used by SoftDevice handler when passing BLE events using the @ref app_scheduler. */
/**@brief Application stack event handler type. */