nrf52-dk

Committer:
mamont090671
Date:
Fri Jun 05 10:49:10 2020 +0000
Revision:
0:70ce6da7a141
nrf52840

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mamont090671 0:70ce6da7a141 1 /* mbed Microcontroller Library
mamont090671 0:70ce6da7a141 2 * Copyright (c) 2006-2013 ARM Limited
mamont090671 0:70ce6da7a141 3 *
mamont090671 0:70ce6da7a141 4 * Licensed under the Apache License, Version 2.0 (the "License");
mamont090671 0:70ce6da7a141 5 * you may not use this file except in compliance with the License.
mamont090671 0:70ce6da7a141 6 * You may obtain a copy of the License at
mamont090671 0:70ce6da7a141 7 *
mamont090671 0:70ce6da7a141 8 * http://www.apache.org/licenses/LICENSE-2.0
mamont090671 0:70ce6da7a141 9 *
mamont090671 0:70ce6da7a141 10 * Unless required by applicable law or agreed to in writing, software
mamont090671 0:70ce6da7a141 11 * distributed under the License is distributed on an "AS IS" BASIS,
mamont090671 0:70ce6da7a141 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mamont090671 0:70ce6da7a141 13 * See the License for the specific language governing permissions and
mamont090671 0:70ce6da7a141 14 * limitations under the License.
mamont090671 0:70ce6da7a141 15 */
mamont090671 0:70ce6da7a141 16 /**
mamont090671 0:70ce6da7a141 17 ******************************************************************************
mamont090671 0:70ce6da7a141 18 * @file BlueNRGGattServer.cpp
mamont090671 0:70ce6da7a141 19 * @author STMicroelectronics
mamont090671 0:70ce6da7a141 20 * @brief Implementation of BlueNRG BLE_API GattServer Class
mamont090671 0:70ce6da7a141 21 ******************************************************************************
mamont090671 0:70ce6da7a141 22 * @copy
mamont090671 0:70ce6da7a141 23 *
mamont090671 0:70ce6da7a141 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
mamont090671 0:70ce6da7a141 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
mamont090671 0:70ce6da7a141 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
mamont090671 0:70ce6da7a141 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
mamont090671 0:70ce6da7a141 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
mamont090671 0:70ce6da7a141 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
mamont090671 0:70ce6da7a141 30 *
mamont090671 0:70ce6da7a141 31 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
mamont090671 0:70ce6da7a141 32 */
mamont090671 0:70ce6da7a141 33
mamont090671 0:70ce6da7a141 34 /** @defgroup BlueNRGGATTClient
mamont090671 0:70ce6da7a141 35 * @brief BlueNRG BLE_API GattClient Adaptation
mamont090671 0:70ce6da7a141 36 * @{
mamont090671 0:70ce6da7a141 37 */
mamont090671 0:70ce6da7a141 38
mamont090671 0:70ce6da7a141 39 #include "BlueNRGGattClient.h"
mamont090671 0:70ce6da7a141 40 #ifdef YOTTA_CFG_MBED_OS
mamont090671 0:70ce6da7a141 41 #include "mbed-drivers/mbed.h"
mamont090671 0:70ce6da7a141 42 #else
mamont090671 0:70ce6da7a141 43 #include "mbed.h"
mamont090671 0:70ce6da7a141 44 #endif
mamont090671 0:70ce6da7a141 45 #include "BlueNRGGap.h"
mamont090671 0:70ce6da7a141 46 #include "ble_utils.h"
mamont090671 0:70ce6da7a141 47 #include "ble_debug.h"
mamont090671 0:70ce6da7a141 48
mamont090671 0:70ce6da7a141 49 #include <new>
mamont090671 0:70ce6da7a141 50 #include <assert.h>
mamont090671 0:70ce6da7a141 51
mamont090671 0:70ce6da7a141 52 ble_error_t BlueNRGGattClient::createGattConnectionClient(Gap::Handle_t connectionHandle)
mamont090671 0:70ce6da7a141 53 {
mamont090671 0:70ce6da7a141 54 if(MAX_ACTIVE_CONNECTIONS <= _numConnections) {
mamont090671 0:70ce6da7a141 55 return BLE_ERROR_OPERATION_NOT_PERMITTED;
mamont090671 0:70ce6da7a141 56 }
mamont090671 0:70ce6da7a141 57
mamont090671 0:70ce6da7a141 58 for(uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 59
mamont090671 0:70ce6da7a141 60 if(_connectionPool[i] == NULL) {
mamont090671 0:70ce6da7a141 61 BlueNRGGattConnectionClient *gattConnectionClient = new(std::nothrow) BlueNRGGattConnectionClient(this, connectionHandle);
mamont090671 0:70ce6da7a141 62
mamont090671 0:70ce6da7a141 63 if (gattConnectionClient == NULL) {
mamont090671 0:70ce6da7a141 64 return BLE_ERROR_NO_MEM;
mamont090671 0:70ce6da7a141 65 }
mamont090671 0:70ce6da7a141 66
mamont090671 0:70ce6da7a141 67 _connectionPool[i] = gattConnectionClient;
mamont090671 0:70ce6da7a141 68 _connectionPool[i]->onServiceDiscoveryTermination(terminationCallback);
mamont090671 0:70ce6da7a141 69 _numConnections++;
mamont090671 0:70ce6da7a141 70
mamont090671 0:70ce6da7a141 71 PRINTF("createGattConnectionClient: _connectionPool index=%d\r\n", i);
mamont090671 0:70ce6da7a141 72 PRINTF("createGattConnectionClient: succesfully added new gattConnectionClient (_numConnections=%d)\r\n", _numConnections);
mamont090671 0:70ce6da7a141 73 break;
mamont090671 0:70ce6da7a141 74 }
mamont090671 0:70ce6da7a141 75 }
mamont090671 0:70ce6da7a141 76
mamont090671 0:70ce6da7a141 77 return BLE_ERROR_NONE;
mamont090671 0:70ce6da7a141 78 }
mamont090671 0:70ce6da7a141 79
mamont090671 0:70ce6da7a141 80 ble_error_t BlueNRGGattClient::removeGattConnectionClient(Gap::Handle_t connectionHandle, uint8_t reason)
mamont090671 0:70ce6da7a141 81 {
mamont090671 0:70ce6da7a141 82
mamont090671 0:70ce6da7a141 83 PRINTF("removeGattConnectionClient: connectionHandle=%d reason=0x%x\r\n", connectionHandle, reason);
mamont090671 0:70ce6da7a141 84
mamont090671 0:70ce6da7a141 85 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 86 PRINTF("removeGattConnectionClient: _connectionPool[%d]->_connectionHandle=%d\r\n", i, _connectionPool[i]->_connectionHandle);
mamont090671 0:70ce6da7a141 87
mamont090671 0:70ce6da7a141 88 if(_connectionPool[i]->_connectionHandle == connectionHandle) {
mamont090671 0:70ce6da7a141 89 PRINTF("removeGattConnectionClient: Found gattConnectionClient\r\n");
mamont090671 0:70ce6da7a141 90 delete _connectionPool[i];
mamont090671 0:70ce6da7a141 91 _connectionPool[i] = NULL;
mamont090671 0:70ce6da7a141 92
mamont090671 0:70ce6da7a141 93 _numConnections--;
mamont090671 0:70ce6da7a141 94 PRINTF("removeGattConnectionClient: succesfully removed gattConnectionClient (_numConnections=%d)\r\n", _numConnections);
mamont090671 0:70ce6da7a141 95
mamont090671 0:70ce6da7a141 96 break;
mamont090671 0:70ce6da7a141 97
mamont090671 0:70ce6da7a141 98 } else {
mamont090671 0:70ce6da7a141 99 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 100 }
mamont090671 0:70ce6da7a141 101 }
mamont090671 0:70ce6da7a141 102
mamont090671 0:70ce6da7a141 103 return BLE_ERROR_NONE;
mamont090671 0:70ce6da7a141 104 }
mamont090671 0:70ce6da7a141 105
mamont090671 0:70ce6da7a141 106 BlueNRGGattConnectionClient * BlueNRGGattClient::getGattConnectionClient(Gap::Handle_t connectionHandle) {
mamont090671 0:70ce6da7a141 107 PRINTF("getGattConnectionClient\r\n");
mamont090671 0:70ce6da7a141 108
mamont090671 0:70ce6da7a141 109 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 110 PRINTF("getGattConnectionClient: _connectionPool[%d]->_connectionHandle=%d\r\n", i, _connectionPool[i]->_connectionHandle);
mamont090671 0:70ce6da7a141 111
mamont090671 0:70ce6da7a141 112 if(_connectionPool[i]->_connectionHandle == connectionHandle) {
mamont090671 0:70ce6da7a141 113 PRINTF("getGattConnectionClient: Found gattConnectionClient\r\n");
mamont090671 0:70ce6da7a141 114 return _connectionPool[i];
mamont090671 0:70ce6da7a141 115 }
mamont090671 0:70ce6da7a141 116 }
mamont090671 0:70ce6da7a141 117
mamont090671 0:70ce6da7a141 118 return NULL;
mamont090671 0:70ce6da7a141 119 }
mamont090671 0:70ce6da7a141 120
mamont090671 0:70ce6da7a141 121 void BlueNRGGattClient::gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code) {
mamont090671 0:70ce6da7a141 122
mamont090671 0:70ce6da7a141 123 if(error_code != BLE_STATUS_SUCCESS) {
mamont090671 0:70ce6da7a141 124 return;
mamont090671 0:70ce6da7a141 125 }
mamont090671 0:70ce6da7a141 126
mamont090671 0:70ce6da7a141 127 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 128
mamont090671 0:70ce6da7a141 129 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 130
mamont090671 0:70ce6da7a141 131 gattConnectionClient->gattProcedureCompleteCB(error_code);
mamont090671 0:70ce6da7a141 132 }
mamont090671 0:70ce6da7a141 133
mamont090671 0:70ce6da7a141 134 void BlueNRGGattClient::primaryServicesCB(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 135 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 136 uint8_t attribute_data_length,
mamont090671 0:70ce6da7a141 137 uint8_t *attribute_data_list) {
mamont090671 0:70ce6da7a141 138
mamont090671 0:70ce6da7a141 139 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 140
mamont090671 0:70ce6da7a141 141 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 142
mamont090671 0:70ce6da7a141 143 gattConnectionClient->primaryServicesCB(event_data_length,
mamont090671 0:70ce6da7a141 144 attribute_data_length,
mamont090671 0:70ce6da7a141 145 attribute_data_list);
mamont090671 0:70ce6da7a141 146 }
mamont090671 0:70ce6da7a141 147
mamont090671 0:70ce6da7a141 148 void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 149 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 150 uint8_t *handles_info_list) {
mamont090671 0:70ce6da7a141 151
mamont090671 0:70ce6da7a141 152 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 153
mamont090671 0:70ce6da7a141 154 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 155
mamont090671 0:70ce6da7a141 156 gattConnectionClient->primaryServiceCB(event_data_length,
mamont090671 0:70ce6da7a141 157 handles_info_list);
mamont090671 0:70ce6da7a141 158 }
mamont090671 0:70ce6da7a141 159
mamont090671 0:70ce6da7a141 160 ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle) {
mamont090671 0:70ce6da7a141 161
mamont090671 0:70ce6da7a141 162 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 163
mamont090671 0:70ce6da7a141 164 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 165 return gattConnectionClient->findServiceChars();
mamont090671 0:70ce6da7a141 166 } else {
mamont090671 0:70ce6da7a141 167 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 168 }
mamont090671 0:70ce6da7a141 169 }
mamont090671 0:70ce6da7a141 170
mamont090671 0:70ce6da7a141 171 void BlueNRGGattClient::serviceCharsCB(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 172 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 173 uint8_t handle_value_pair_length,
mamont090671 0:70ce6da7a141 174 uint8_t *handle_value_pair) {
mamont090671 0:70ce6da7a141 175
mamont090671 0:70ce6da7a141 176 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 177
mamont090671 0:70ce6da7a141 178 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 179
mamont090671 0:70ce6da7a141 180 gattConnectionClient->serviceCharsCB(event_data_length,
mamont090671 0:70ce6da7a141 181 handle_value_pair_length,
mamont090671 0:70ce6da7a141 182 handle_value_pair);
mamont090671 0:70ce6da7a141 183 }
mamont090671 0:70ce6da7a141 184
mamont090671 0:70ce6da7a141 185 void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 186 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 187 uint16_t attr_handle,
mamont090671 0:70ce6da7a141 188 uint8_t *attr_value) {
mamont090671 0:70ce6da7a141 189
mamont090671 0:70ce6da7a141 190 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 191
mamont090671 0:70ce6da7a141 192 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 193
mamont090671 0:70ce6da7a141 194 gattConnectionClient->serviceCharByUUIDCB(event_data_length,
mamont090671 0:70ce6da7a141 195 attr_handle,
mamont090671 0:70ce6da7a141 196 attr_value);
mamont090671 0:70ce6da7a141 197 }
mamont090671 0:70ce6da7a141 198
mamont090671 0:70ce6da7a141 199 void BlueNRGGattClient::discAllCharacDescCB(Gap::Handle_t connHandle,
mamont090671 0:70ce6da7a141 200 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 201 uint8_t format,
mamont090671 0:70ce6da7a141 202 uint8_t *handle_uuid_pair) {
mamont090671 0:70ce6da7a141 203
mamont090671 0:70ce6da7a141 204 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 205
mamont090671 0:70ce6da7a141 206 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 207
mamont090671 0:70ce6da7a141 208 gattConnectionClient->discAllCharacDescCB(event_data_length,
mamont090671 0:70ce6da7a141 209 format,
mamont090671 0:70ce6da7a141 210 handle_uuid_pair);
mamont090671 0:70ce6da7a141 211 }
mamont090671 0:70ce6da7a141 212
mamont090671 0:70ce6da7a141 213 void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle,
mamont090671 0:70ce6da7a141 214 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 215 uint8_t* attribute_value) {
mamont090671 0:70ce6da7a141 216
mamont090671 0:70ce6da7a141 217 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 218
mamont090671 0:70ce6da7a141 219 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 220
mamont090671 0:70ce6da7a141 221 gattConnectionClient->charReadCB(event_data_length,
mamont090671 0:70ce6da7a141 222 attribute_value);
mamont090671 0:70ce6da7a141 223 }
mamont090671 0:70ce6da7a141 224
mamont090671 0:70ce6da7a141 225 void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle,
mamont090671 0:70ce6da7a141 226 uint8_t event_data_length,
mamont090671 0:70ce6da7a141 227 uint16_t attribute_handle,
mamont090671 0:70ce6da7a141 228 uint16_t offset,
mamont090671 0:70ce6da7a141 229 uint8_t *part_attr_value) {
mamont090671 0:70ce6da7a141 230
mamont090671 0:70ce6da7a141 231 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 232
mamont090671 0:70ce6da7a141 233 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 234
mamont090671 0:70ce6da7a141 235 gattConnectionClient->charWritePrepareCB(event_data_length,
mamont090671 0:70ce6da7a141 236 attribute_handle,
mamont090671 0:70ce6da7a141 237 offset,
mamont090671 0:70ce6da7a141 238 part_attr_value);
mamont090671 0:70ce6da7a141 239 }
mamont090671 0:70ce6da7a141 240
mamont090671 0:70ce6da7a141 241 void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle,
mamont090671 0:70ce6da7a141 242 uint8_t event_data_length) {
mamont090671 0:70ce6da7a141 243
mamont090671 0:70ce6da7a141 244 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 245
mamont090671 0:70ce6da7a141 246 assert(gattConnectionClient != NULL);
mamont090671 0:70ce6da7a141 247
mamont090671 0:70ce6da7a141 248 gattConnectionClient->charWriteExecCB(event_data_length);
mamont090671 0:70ce6da7a141 249 }
mamont090671 0:70ce6da7a141 250
mamont090671 0:70ce6da7a141 251 ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 252 ServiceDiscovery::ServiceCallback_t sc,
mamont090671 0:70ce6da7a141 253 ServiceDiscovery::CharacteristicCallback_t cc,
mamont090671 0:70ce6da7a141 254 const UUID &matchingServiceUUID,
mamont090671 0:70ce6da7a141 255 const UUID &matchingCharacteristicUUIDIn)
mamont090671 0:70ce6da7a141 256 {
mamont090671 0:70ce6da7a141 257 PRINTF("BlueNRGGattClient launchServiceDiscovery\n\r");
mamont090671 0:70ce6da7a141 258
mamont090671 0:70ce6da7a141 259 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 260
mamont090671 0:70ce6da7a141 261 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 262 return gattConnectionClient->launchServiceDiscovery(sc, cc, matchingServiceUUID, matchingCharacteristicUUIDIn);
mamont090671 0:70ce6da7a141 263 } else {
mamont090671 0:70ce6da7a141 264 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 265 }
mamont090671 0:70ce6da7a141 266 }
mamont090671 0:70ce6da7a141 267
mamont090671 0:70ce6da7a141 268 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 269 ServiceDiscovery::ServiceCallback_t callback,
mamont090671 0:70ce6da7a141 270 const UUID &matchingServiceUUID)
mamont090671 0:70ce6da7a141 271 {
mamont090671 0:70ce6da7a141 272 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 273
mamont090671 0:70ce6da7a141 274 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 275
mamont090671 0:70ce6da7a141 276 return gattConnectionClient->discoverServices(callback, matchingServiceUUID);
mamont090671 0:70ce6da7a141 277
mamont090671 0:70ce6da7a141 278 } else {
mamont090671 0:70ce6da7a141 279 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 280 }
mamont090671 0:70ce6da7a141 281 }
mamont090671 0:70ce6da7a141 282
mamont090671 0:70ce6da7a141 283 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
mamont090671 0:70ce6da7a141 284 ServiceDiscovery::ServiceCallback_t callback,
mamont090671 0:70ce6da7a141 285 GattAttribute::Handle_t startHandle,
mamont090671 0:70ce6da7a141 286 GattAttribute::Handle_t endHandle)
mamont090671 0:70ce6da7a141 287 {
mamont090671 0:70ce6da7a141 288 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(connectionHandle);
mamont090671 0:70ce6da7a141 289
mamont090671 0:70ce6da7a141 290 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 291
mamont090671 0:70ce6da7a141 292 return gattConnectionClient->discoverServices(callback, startHandle, endHandle);
mamont090671 0:70ce6da7a141 293
mamont090671 0:70ce6da7a141 294 } else {
mamont090671 0:70ce6da7a141 295 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 296 }
mamont090671 0:70ce6da7a141 297 }
mamont090671 0:70ce6da7a141 298
mamont090671 0:70ce6da7a141 299 bool BlueNRGGattClient::isServiceDiscoveryActive(void) const
mamont090671 0:70ce6da7a141 300 {
mamont090671 0:70ce6da7a141 301 bool isSDActive = false;
mamont090671 0:70ce6da7a141 302
mamont090671 0:70ce6da7a141 303 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 304 if (_connectionPool[i]) {
mamont090671 0:70ce6da7a141 305 isSDActive |= _connectionPool[i]->isServiceDiscoveryActive();
mamont090671 0:70ce6da7a141 306 }
mamont090671 0:70ce6da7a141 307 }
mamont090671 0:70ce6da7a141 308
mamont090671 0:70ce6da7a141 309 return isSDActive;
mamont090671 0:70ce6da7a141 310 }
mamont090671 0:70ce6da7a141 311
mamont090671 0:70ce6da7a141 312 void BlueNRGGattClient::terminateServiceDiscovery(void)
mamont090671 0:70ce6da7a141 313 {
mamont090671 0:70ce6da7a141 314 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 315 if (_connectionPool[i]) {
mamont090671 0:70ce6da7a141 316 _connectionPool[i]->terminateServiceDiscovery();
mamont090671 0:70ce6da7a141 317 }
mamont090671 0:70ce6da7a141 318 }
mamont090671 0:70ce6da7a141 319 }
mamont090671 0:70ce6da7a141 320
mamont090671 0:70ce6da7a141 321 void BlueNRGGattClient::onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
mamont090671 0:70ce6da7a141 322 terminationCallback = callback;
mamont090671 0:70ce6da7a141 323 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; ++i) {
mamont090671 0:70ce6da7a141 324 if (_connectionPool[i]) {
mamont090671 0:70ce6da7a141 325 _connectionPool[i]->onServiceDiscoveryTermination(callback);
mamont090671 0:70ce6da7a141 326 }
mamont090671 0:70ce6da7a141 327 }
mamont090671 0:70ce6da7a141 328 }
mamont090671 0:70ce6da7a141 329
mamont090671 0:70ce6da7a141 330 ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const
mamont090671 0:70ce6da7a141 331 {
mamont090671 0:70ce6da7a141 332 BlueNRGGattConnectionClient *gattConnectionClient = const_cast<BlueNRGGattClient*>(this)->getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 333
mamont090671 0:70ce6da7a141 334 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 335
mamont090671 0:70ce6da7a141 336 return gattConnectionClient->read(attributeHandle, offset);
mamont090671 0:70ce6da7a141 337
mamont090671 0:70ce6da7a141 338 } else {
mamont090671 0:70ce6da7a141 339 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 340 }
mamont090671 0:70ce6da7a141 341 }
mamont090671 0:70ce6da7a141 342
mamont090671 0:70ce6da7a141 343 ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd,
mamont090671 0:70ce6da7a141 344 Gap::Handle_t connHandle,
mamont090671 0:70ce6da7a141 345 GattAttribute::Handle_t attributeHandle,
mamont090671 0:70ce6da7a141 346 size_t length,
mamont090671 0:70ce6da7a141 347 const uint8_t *value) const
mamont090671 0:70ce6da7a141 348 {
mamont090671 0:70ce6da7a141 349 BlueNRGGattConnectionClient *gattConnectionClient = const_cast<BlueNRGGattClient*>(this)->getGattConnectionClient(connHandle);
mamont090671 0:70ce6da7a141 350
mamont090671 0:70ce6da7a141 351 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 352
mamont090671 0:70ce6da7a141 353 return gattConnectionClient->write(cmd, attributeHandle, length, value);
mamont090671 0:70ce6da7a141 354
mamont090671 0:70ce6da7a141 355 } else {
mamont090671 0:70ce6da7a141 356 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 357 }
mamont090671 0:70ce6da7a141 358 }
mamont090671 0:70ce6da7a141 359
mamont090671 0:70ce6da7a141 360 ble_error_t BlueNRGGattClient::discoverCharacteristicDescriptors(
mamont090671 0:70ce6da7a141 361 const DiscoveredCharacteristic& characteristic,
mamont090671 0:70ce6da7a141 362 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
mamont090671 0:70ce6da7a141 363 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback)
mamont090671 0:70ce6da7a141 364 {
mamont090671 0:70ce6da7a141 365 BlueNRGGattConnectionClient *gattConnectionClient = getGattConnectionClient(characteristic.getConnectionHandle());
mamont090671 0:70ce6da7a141 366
mamont090671 0:70ce6da7a141 367 if(gattConnectionClient != NULL) {
mamont090671 0:70ce6da7a141 368
mamont090671 0:70ce6da7a141 369 return gattConnectionClient->discoverCharacteristicDescriptors(characteristic, discoveryCallback, terminationCallback);
mamont090671 0:70ce6da7a141 370
mamont090671 0:70ce6da7a141 371 } else {
mamont090671 0:70ce6da7a141 372 return BLE_ERROR_INTERNAL_STACK_FAILURE;
mamont090671 0:70ce6da7a141 373 }
mamont090671 0:70ce6da7a141 374 }
mamont090671 0:70ce6da7a141 375
mamont090671 0:70ce6da7a141 376 /**************************************************************************/
mamont090671 0:70ce6da7a141 377 /*!
mamont090671 0:70ce6da7a141 378 @brief Clear BlueNRGGattClient's state.
mamont090671 0:70ce6da7a141 379
mamont090671 0:70ce6da7a141 380 @returns ble_error_t
mamont090671 0:70ce6da7a141 381
mamont090671 0:70ce6da7a141 382 @retval BLE_ERROR_NONE
mamont090671 0:70ce6da7a141 383 Everything executed properly
mamont090671 0:70ce6da7a141 384 */
mamont090671 0:70ce6da7a141 385 /**************************************************************************/
mamont090671 0:70ce6da7a141 386 ble_error_t BlueNRGGattClient::reset(void)
mamont090671 0:70ce6da7a141 387 {
mamont090671 0:70ce6da7a141 388 PRINTF("BlueNRGGattClient::reset\n");
mamont090671 0:70ce6da7a141 389
mamont090671 0:70ce6da7a141 390 for (uint8_t i = 0; i < MAX_ACTIVE_CONNECTIONS; i++) {
mamont090671 0:70ce6da7a141 391 if(_connectionPool[i] != NULL) {
mamont090671 0:70ce6da7a141 392 _connectionPool[i]->reset();
mamont090671 0:70ce6da7a141 393
mamont090671 0:70ce6da7a141 394 delete _connectionPool[i];
mamont090671 0:70ce6da7a141 395 _connectionPool[i] = NULL;
mamont090671 0:70ce6da7a141 396
mamont090671 0:70ce6da7a141 397 _numConnections--;
mamont090671 0:70ce6da7a141 398 }
mamont090671 0:70ce6da7a141 399 }
mamont090671 0:70ce6da7a141 400
mamont090671 0:70ce6da7a141 401 return BLE_ERROR_NONE;
mamont090671 0:70ce6da7a141 402 }
mamont090671 0:70ce6da7a141 403