adaptation for bkap

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Vincent Coubard
Date:
Thu Sep 15 10:51:24 2016 +0100
Branch:
a38223e17a624c1ac4d9e2589f363d2e202f12a5
Revision:
262:a3460768f3b7
Parent:
259:323f588e5f57
Child:
278:a5209d8cfd61
Sync with a38223e17a624c1ac4d9e2589f363d2e202f12a5

2016-07-08 18:04:01+01:00: Vincent Coubard
Fix characteristic descriptor discovery

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Andrea Palmieri 229:9981f62cdb1a 1 /* mbed Microcontroller Library
Andrea Palmieri 229:9981f62cdb1a 2 * Copyright (c) 2006-2013 ARM Limited
Andrea Palmieri 229:9981f62cdb1a 3 *
Andrea Palmieri 229:9981f62cdb1a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Andrea Palmieri 229:9981f62cdb1a 5 * you may not use this file except in compliance with the License.
Andrea Palmieri 229:9981f62cdb1a 6 * You may obtain a copy of the License at
Andrea Palmieri 229:9981f62cdb1a 7 *
Andrea Palmieri 229:9981f62cdb1a 8 * http://www.apache.org/licenses/LICENSE-2.0
Andrea Palmieri 229:9981f62cdb1a 9 *
Andrea Palmieri 229:9981f62cdb1a 10 * Unless required by applicable law or agreed to in writing, software
Andrea Palmieri 229:9981f62cdb1a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Andrea Palmieri 229:9981f62cdb1a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Andrea Palmieri 229:9981f62cdb1a 13 * See the License for the specific language governing permissions and
Andrea Palmieri 229:9981f62cdb1a 14 * limitations under the License.
Andrea Palmieri 229:9981f62cdb1a 15 */
Andrea Palmieri 229:9981f62cdb1a 16 /**
Andrea Palmieri 229:9981f62cdb1a 17 ******************************************************************************
Vincent Coubard 259:323f588e5f57 18 * @file BlueNRGGattServer.cpp
Andrea Palmieri 229:9981f62cdb1a 19 * @author STMicroelectronics
Andrea Palmieri 229:9981f62cdb1a 20 * @brief Implementation of BlueNRG BLE_API GattServer Class
Andrea Palmieri 229:9981f62cdb1a 21 ******************************************************************************
Andrea Palmieri 229:9981f62cdb1a 22 * @copy
Andrea Palmieri 229:9981f62cdb1a 23 *
Andrea Palmieri 229:9981f62cdb1a 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Andrea Palmieri 229:9981f62cdb1a 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Andrea Palmieri 229:9981f62cdb1a 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Andrea Palmieri 229:9981f62cdb1a 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Andrea Palmieri 229:9981f62cdb1a 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Andrea Palmieri 229:9981f62cdb1a 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Andrea Palmieri 229:9981f62cdb1a 30 *
Andrea Palmieri 229:9981f62cdb1a 31 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Vincent Coubard 259:323f588e5f57 32 */
Vincent Coubard 259:323f588e5f57 33
Andrea Palmieri 229:9981f62cdb1a 34 /** @defgroup BlueNRGGATTClient
Andrea Palmieri 229:9981f62cdb1a 35 * @brief BlueNRG BLE_API GattClient Adaptation
Andrea Palmieri 229:9981f62cdb1a 36 * @{
Andrea Palmieri 229:9981f62cdb1a 37 */
Vincent Coubard 259:323f588e5f57 38
Andrea Palmieri 229:9981f62cdb1a 39 #include "BlueNRGGattClient.h"
Vincent Coubard 253:9665a6f8bbdb 40 #include "mbed-drivers/mbed.h"
Andrea Palmieri 229:9981f62cdb1a 41 #include "BlueNRGGap.h"
Andrea Palmieri 229:9981f62cdb1a 42 #include "Utils.h"
Andrea Palmieri 229:9981f62cdb1a 43 #include "debug.h"
Andrea Palmieri 229:9981f62cdb1a 44
Andrea Palmieri 229:9981f62cdb1a 45 static uint8_t props_mask[] = {
Andrea Palmieri 229:9981f62cdb1a 46 0x01,
Andrea Palmieri 229:9981f62cdb1a 47 0x02,
Andrea Palmieri 229:9981f62cdb1a 48 0x04,
Andrea Palmieri 229:9981f62cdb1a 49 0x08,
Andrea Palmieri 229:9981f62cdb1a 50 0x10,
Andrea Palmieri 229:9981f62cdb1a 51 0x20,
Andrea Palmieri 229:9981f62cdb1a 52 0x40,
Andrea Palmieri 229:9981f62cdb1a 53 0x80
Andrea Palmieri 229:9981f62cdb1a 54 };
Andrea Palmieri 229:9981f62cdb1a 55
Andrea Palmieri 229:9981f62cdb1a 56 void BlueNRGGattClient::gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code)
Andrea Palmieri 229:9981f62cdb1a 57 {
Andrea Palmieri 229:9981f62cdb1a 58 if(error_code != BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 59 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 60 return;
Andrea Palmieri 229:9981f62cdb1a 61 }
Vincent Coubard 259:323f588e5f57 62
Andrea Palmieri 229:9981f62cdb1a 63 // Service Discovery complete
Andrea Palmieri 229:9981f62cdb1a 64 /*
Vincent Coubard 259:323f588e5f57 65 if(_currentState != GATT_IDLE &&
Andrea Palmieri 229:9981f62cdb1a 66 _currentState != GATT_DISCOVERY_TERMINATED &&
Andrea Palmieri 229:9981f62cdb1a 67 _currentState != GATT_WRITE_CHAR &&
Andrea Palmieri 229:9981f62cdb1a 68 _currentState != GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 69 */
Andrea Palmieri 229:9981f62cdb1a 70 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 71 findServiceChars(connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 72 }
Andrea Palmieri 229:9981f62cdb1a 73
Andrea Palmieri 229:9981f62cdb1a 74 if(_currentState == GATT_CHAR_DESC_DISCOVERY) {
Vincent Coubard 262:a3460768f3b7 75 if(charDescTerminationCallback != NULL) {
Vincent Coubard 262:a3460768f3b7 76 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
Vincent Coubard 262:a3460768f3b7 77 _characteristic,
Vincent Coubard 262:a3460768f3b7 78 BLE_ERROR_NONE
Vincent Coubard 262:a3460768f3b7 79 };
Vincent Coubard 262:a3460768f3b7 80 charDescTerminationCallback(&params);
Vincent Coubard 262:a3460768f3b7 81 }
Andrea Palmieri 229:9981f62cdb1a 82 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 83 }
Andrea Palmieri 229:9981f62cdb1a 84
Andrea Palmieri 229:9981f62cdb1a 85 // Read complete
Andrea Palmieri 229:9981f62cdb1a 86 if(_currentState == GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 87 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 88 }
Andrea Palmieri 229:9981f62cdb1a 89
Andrea Palmieri 229:9981f62cdb1a 90 // Write complete
Andrea Palmieri 229:9981f62cdb1a 91 if(_currentState == GATT_WRITE_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 92 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 93 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 94 }
Andrea Palmieri 229:9981f62cdb1a 95 }
Vincent Coubard 259:323f588e5f57 96
Andrea Palmieri 229:9981f62cdb1a 97 void BlueNRGGattClient::primaryServicesCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 98 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 99 uint8_t attribute_data_length,
Andrea Palmieri 229:9981f62cdb1a 100 uint8_t *attribute_data_list)
Andrea Palmieri 229:9981f62cdb1a 101 {
Andrea Palmieri 229:9981f62cdb1a 102 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 103 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 104 uint8_t i, offset, numAttr;
Andrea Palmieri 229:9981f62cdb1a 105 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 106 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 107
Andrea Palmieri 229:9981f62cdb1a 108 numAttr = (event_data_length - 1) / attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 109
Andrea Palmieri 229:9981f62cdb1a 110 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 111 for (i=0; i<numAttr; i++) {
Andrea Palmieri 229:9981f62cdb1a 112 startHandle = attribute_data_list[offset];
Andrea Palmieri 229:9981f62cdb1a 113 endHandle = attribute_data_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 114
Andrea Palmieri 229:9981f62cdb1a 115 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 116 if (attribute_data_length == 6) {
Vincent Coubard 259:323f588e5f57 117
Andrea Palmieri 229:9981f62cdb1a 118 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 119 uuid = attribute_data_list[offset+5]<<8|attribute_data_list[offset+4];
Andrea Palmieri 229:9981f62cdb1a 120 PRINTF("S UUID-%X attrs[%u %u]\r\n", uuid.getShortUUID(), startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 121
Andrea Palmieri 229:9981f62cdb1a 122 } else {
Vincent Coubard 259:323f588e5f57 123
Andrea Palmieri 229:9981f62cdb1a 124 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 125 uuid.setupLong(attribute_data_list+offset+4, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 126
Andrea Palmieri 229:9981f62cdb1a 127 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 128 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 129 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 130 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 131 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 132 }
Andrea Palmieri 229:9981f62cdb1a 133 #endif
Andrea Palmieri 229:9981f62cdb1a 134 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 135
Andrea Palmieri 229:9981f62cdb1a 136 }
Vincent Coubard 259:323f588e5f57 137
Andrea Palmieri 229:9981f62cdb1a 138 PRINTF("Setup serviceIndex = %d\n\r", _numServices);
Andrea Palmieri 229:9981f62cdb1a 139 discoveredService[_numServices].setup(uuid, startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 140
Andrea Palmieri 229:9981f62cdb1a 141 _numServices++;
Andrea Palmieri 229:9981f62cdb1a 142
Andrea Palmieri 229:9981f62cdb1a 143 offset += attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 144 }
Andrea Palmieri 229:9981f62cdb1a 145
Andrea Palmieri 229:9981f62cdb1a 146 PRINTF("!!!Service Discovery complete (numAttr=%u)!!!\n\r", numAttr);
Andrea Palmieri 229:9981f62cdb1a 147
Andrea Palmieri 229:9981f62cdb1a 148 }
Andrea Palmieri 229:9981f62cdb1a 149
Andrea Palmieri 229:9981f62cdb1a 150 void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 151 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 152 uint8_t *handles_info_list)
Andrea Palmieri 229:9981f62cdb1a 153 {
Andrea Palmieri 229:9981f62cdb1a 154 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 155 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 156 uint8_t i, offset, numHandlePairs;
Andrea Palmieri 229:9981f62cdb1a 157 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 158 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 159
Andrea Palmieri 229:9981f62cdb1a 160 numHandlePairs = (event_data_length - 1) / 2;
Andrea Palmieri 229:9981f62cdb1a 161
Andrea Palmieri 229:9981f62cdb1a 162 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 163 for (i=0; i<numHandlePairs; i++) {
Andrea Palmieri 229:9981f62cdb1a 164 startHandle = handles_info_list[offset];
Andrea Palmieri 229:9981f62cdb1a 165 endHandle = handles_info_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 166
Andrea Palmieri 229:9981f62cdb1a 167 PRINTF("primaryServiceCB attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 168
Andrea Palmieri 229:9981f62cdb1a 169
Andrea Palmieri 229:9981f62cdb1a 170 if (_matchingServiceUUID.shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 171 PRINTF("S UUID-%x attrs[%u %u]\r\n", _matchingServiceUUID.getShortUUID(), startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 172 uuid = _matchingServiceUUID.getShortUUID();
Andrea Palmieri 229:9981f62cdb1a 173 } else {
Andrea Palmieri 229:9981f62cdb1a 174 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 175 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 176 const uint8_t *longUUIDBytes = _matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 177 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 178 PRINTF("%02x", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 179 }
Andrea Palmieri 229:9981f62cdb1a 180 #endif
Andrea Palmieri 229:9981f62cdb1a 181 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 182 uuid.setupLong(_matchingServiceUUID.getBaseUUID(), UUID::MSB);
Andrea Palmieri 229:9981f62cdb1a 183 }
Andrea Palmieri 229:9981f62cdb1a 184
Andrea Palmieri 229:9981f62cdb1a 185 discoveredService[i].setup(uuid, startHandle, endHandle);
Vincent Coubard 259:323f588e5f57 186
Andrea Palmieri 229:9981f62cdb1a 187 _numServices++;
Vincent Coubard 259:323f588e5f57 188
Andrea Palmieri 229:9981f62cdb1a 189 offset += 4;
Andrea Palmieri 229:9981f62cdb1a 190 }
Andrea Palmieri 229:9981f62cdb1a 191 }
Andrea Palmieri 229:9981f62cdb1a 192
Andrea Palmieri 229:9981f62cdb1a 193 void BlueNRGGattClient::serviceCharsCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 194 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 195 uint8_t handle_value_pair_length,
Andrea Palmieri 229:9981f62cdb1a 196 uint8_t *handle_value_pair)
Andrea Palmieri 229:9981f62cdb1a 197 {
Andrea Palmieri 229:9981f62cdb1a 198 // Charac Handle (2), Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Andrea Palmieri 229:9981f62cdb1a 199
Andrea Palmieri 229:9981f62cdb1a 200 GattAttribute::Handle_t declHandle, valueHandle, lastHandle;
Andrea Palmieri 229:9981f62cdb1a 201 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 202 uint8_t i, numChar, offset;
Andrea Palmieri 229:9981f62cdb1a 203
Andrea Palmieri 229:9981f62cdb1a 204 numChar = (event_data_length - 1) / handle_value_pair_length;
Andrea Palmieri 229:9981f62cdb1a 205
Andrea Palmieri 229:9981f62cdb1a 206 PRINTF("event_data_length=%d handle_value_pair_length=%d numChar=%d\n\r", event_data_length, handle_value_pair_length, numChar);
Andrea Palmieri 229:9981f62cdb1a 207
Andrea Palmieri 229:9981f62cdb1a 208 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 209 for (i=0; i<numChar; i++) {
Andrea Palmieri 229:9981f62cdb1a 210 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 211 if (handle_value_pair_length == 7) {
Andrea Palmieri 229:9981f62cdb1a 212 PRINTF("Char UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 213 uuid = handle_value_pair[offset+6]<<8|handle_value_pair[offset+5];
Andrea Palmieri 229:9981f62cdb1a 214 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 215 } else {
Andrea Palmieri 229:9981f62cdb1a 216 PRINTF("Char UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 217 uuid.setupLong(handle_value_pair+offset+5, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 218 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 219 PRINTF("C UUID-");
Andrea Palmieri 229:9981f62cdb1a 220 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 221 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 222 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 223 }
Andrea Palmieri 229:9981f62cdb1a 224 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 225 #endif
Andrea Palmieri 229:9981f62cdb1a 226 }
Vincent Coubard 259:323f588e5f57 227
Andrea Palmieri 229:9981f62cdb1a 228 // Properties
Andrea Palmieri 229:9981f62cdb1a 229 DiscoveredCharacteristic::Properties_t p;
Vincent Coubard 259:323f588e5f57 230
Andrea Palmieri 229:9981f62cdb1a 231 p._broadcast = (props_mask[0] & handle_value_pair[offset+2]);
Andrea Palmieri 229:9981f62cdb1a 232 p._read = (props_mask[1] & handle_value_pair[offset+2])>>1;
Andrea Palmieri 229:9981f62cdb1a 233 p._writeWoResp = (props_mask[2] & handle_value_pair[offset+2])>>2;
Andrea Palmieri 229:9981f62cdb1a 234 p._write = (props_mask[3] & handle_value_pair[offset+2])>>3;
Andrea Palmieri 229:9981f62cdb1a 235 p._notify = (props_mask[4] & handle_value_pair[offset+2])>>4;
Andrea Palmieri 229:9981f62cdb1a 236 p._indicate = (props_mask[5] & handle_value_pair[offset+2])>>5;
Andrea Palmieri 229:9981f62cdb1a 237 p._authSignedWrite = (props_mask[6] & handle_value_pair[offset+2])>>6;
Andrea Palmieri 229:9981f62cdb1a 238 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Andrea Palmieri 229:9981f62cdb1a 239 PRINTF("p._read=%d\n\r", p._read);
Andrea Palmieri 229:9981f62cdb1a 240 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Andrea Palmieri 229:9981f62cdb1a 241 PRINTF("p._write=%d\n\r", p._write);
Andrea Palmieri 229:9981f62cdb1a 242 PRINTF("p._notify=%d\n\r", p._notify);
Andrea Palmieri 229:9981f62cdb1a 243 PRINTF("p._indicate=%d\n\r", p._indicate);
Andrea Palmieri 229:9981f62cdb1a 244 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Andrea Palmieri 229:9981f62cdb1a 245
Andrea Palmieri 229:9981f62cdb1a 246 /*
Andrea Palmieri 229:9981f62cdb1a 247 uint8_t props = handle_value_pair[offset+2];
Andrea Palmieri 229:9981f62cdb1a 248 PRINTF("CHAR PROPS: %d\n\r", props);
Andrea Palmieri 229:9981f62cdb1a 249 */
Andrea Palmieri 229:9981f62cdb1a 250
Andrea Palmieri 229:9981f62cdb1a 251 // Handles
Andrea Palmieri 229:9981f62cdb1a 252 declHandle = handle_value_pair[offset];
Andrea Palmieri 229:9981f62cdb1a 253 valueHandle = handle_value_pair[offset+3];
Andrea Palmieri 229:9981f62cdb1a 254 lastHandle = valueHandle+1;
Andrea Palmieri 229:9981f62cdb1a 255 PRINTF("declHandle: %u valueHandle=%u lastHandle=%u\n\r", declHandle, valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 256
Andrea Palmieri 229:9981f62cdb1a 257 discoveredChar[_numChars].setup(this,
Andrea Palmieri 229:9981f62cdb1a 258 connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 259 uuid,
Andrea Palmieri 229:9981f62cdb1a 260 p,
Andrea Palmieri 229:9981f62cdb1a 261 declHandle,
Andrea Palmieri 229:9981f62cdb1a 262 valueHandle,
Andrea Palmieri 229:9981f62cdb1a 263 lastHandle);
Andrea Palmieri 229:9981f62cdb1a 264
Vincent Coubard 259:323f588e5f57 265 if (_numChars != 0) {
Vincent Coubard 259:323f588e5f57 266 discoveredChar[_numChars - 1].setLastHandle(declHandle - 1);
Vincent Coubard 259:323f588e5f57 267
Vincent Coubard 259:323f588e5f57 268 if(characteristicDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 269 characteristicDiscoveryCallback(&discoveredChar[_numChars - 1]);
Vincent Coubard 259:323f588e5f57 270 }
Andrea Palmieri 229:9981f62cdb1a 271 }
Vincent Coubard 259:323f588e5f57 272
Andrea Palmieri 229:9981f62cdb1a 273 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 274
Andrea Palmieri 229:9981f62cdb1a 275 offset += handle_value_pair_length;
Andrea Palmieri 229:9981f62cdb1a 276 }
Andrea Palmieri 229:9981f62cdb1a 277 }
Andrea Palmieri 229:9981f62cdb1a 278
Andrea Palmieri 229:9981f62cdb1a 279 void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 280 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 281 uint16_t attr_handle,
Andrea Palmieri 229:9981f62cdb1a 282 uint8_t *attr_value)
Andrea Palmieri 229:9981f62cdb1a 283 {
Andrea Palmieri 229:9981f62cdb1a 284 // Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Andrea Palmieri 229:9981f62cdb1a 285 GattAttribute::Handle_t declHandle, valueHandle, lastHandle;
Andrea Palmieri 229:9981f62cdb1a 286 UUID uuid;
Vincent Coubard 259:323f588e5f57 287
Andrea Palmieri 229:9981f62cdb1a 288 PRINTF("serviceCharByUUIDCB\n\r");
Vincent Coubard 259:323f588e5f57 289
Andrea Palmieri 229:9981f62cdb1a 290 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 291 if (event_data_length == 7) {
Andrea Palmieri 229:9981f62cdb1a 292 PRINTF("Char UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 293 uuid = attr_value[4]<<8|attr_value[3];
Andrea Palmieri 229:9981f62cdb1a 294 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 295 } else {
Andrea Palmieri 229:9981f62cdb1a 296 PRINTF("Char UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 297 uuid.setupLong(attr_value+3, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 298 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 299 PRINTF("C UUID-");
Andrea Palmieri 229:9981f62cdb1a 300 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 301 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 302 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 303 }
Andrea Palmieri 229:9981f62cdb1a 304 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 305 #endif
Andrea Palmieri 229:9981f62cdb1a 306 }
Andrea Palmieri 229:9981f62cdb1a 307
Andrea Palmieri 229:9981f62cdb1a 308 // Properties
Andrea Palmieri 229:9981f62cdb1a 309 DiscoveredCharacteristic::Properties_t p;
Vincent Coubard 259:323f588e5f57 310
Andrea Palmieri 229:9981f62cdb1a 311 p._broadcast = (props_mask[0] & attr_value[0]);
Andrea Palmieri 229:9981f62cdb1a 312 p._read = (props_mask[1] & attr_value[0])>>1;
Andrea Palmieri 229:9981f62cdb1a 313 p._writeWoResp = (props_mask[2] & attr_value[0])>>2;
Andrea Palmieri 229:9981f62cdb1a 314 p._write = (props_mask[3] & attr_value[0])>>3;
Andrea Palmieri 229:9981f62cdb1a 315 p._notify = (props_mask[4] & attr_value[0])>>4;
Andrea Palmieri 229:9981f62cdb1a 316 p._indicate = (props_mask[5] & attr_value[0])>>5;
Andrea Palmieri 229:9981f62cdb1a 317 p._authSignedWrite = (props_mask[6] & attr_value[0])>>6;
Andrea Palmieri 229:9981f62cdb1a 318 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Andrea Palmieri 229:9981f62cdb1a 319 PRINTF("p._read=%d\n\r", p._read);
Andrea Palmieri 229:9981f62cdb1a 320 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Andrea Palmieri 229:9981f62cdb1a 321 PRINTF("p._write=%d\n\r", p._write);
Andrea Palmieri 229:9981f62cdb1a 322 PRINTF("p._notify=%d\n\r", p._notify);
Andrea Palmieri 229:9981f62cdb1a 323 PRINTF("p._indicate=%d\n\r", p._indicate);
Andrea Palmieri 229:9981f62cdb1a 324 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Andrea Palmieri 229:9981f62cdb1a 325
Andrea Palmieri 229:9981f62cdb1a 326 /*
Andrea Palmieri 229:9981f62cdb1a 327 uint8_t props = attr_value[0];
Andrea Palmieri 229:9981f62cdb1a 328 PRINTF("CHAR PROPS: %d\n\r", props);
Andrea Palmieri 229:9981f62cdb1a 329 */
Andrea Palmieri 229:9981f62cdb1a 330
Andrea Palmieri 229:9981f62cdb1a 331 // Handles
Andrea Palmieri 229:9981f62cdb1a 332 declHandle = attr_handle;
Andrea Palmieri 229:9981f62cdb1a 333 valueHandle = attr_value[1];
Andrea Palmieri 229:9981f62cdb1a 334 lastHandle = valueHandle+1;
Andrea Palmieri 229:9981f62cdb1a 335
Andrea Palmieri 229:9981f62cdb1a 336 discoveredChar[_numChars].setup(this,
Andrea Palmieri 229:9981f62cdb1a 337 connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 338 uuid,
Andrea Palmieri 229:9981f62cdb1a 339 p,
Andrea Palmieri 229:9981f62cdb1a 340 declHandle,
Andrea Palmieri 229:9981f62cdb1a 341 valueHandle,
Andrea Palmieri 229:9981f62cdb1a 342 lastHandle);
Vincent Coubard 259:323f588e5f57 343
Andrea Palmieri 229:9981f62cdb1a 344 if(characteristicDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 345 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Andrea Palmieri 229:9981f62cdb1a 346 }
Andrea Palmieri 229:9981f62cdb1a 347 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 348 }
Andrea Palmieri 229:9981f62cdb1a 349
Andrea Palmieri 229:9981f62cdb1a 350 ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle)
Andrea Palmieri 229:9981f62cdb1a 351 {
Andrea Palmieri 229:9981f62cdb1a 352 PRINTF("findServiceChars\n\r");
Vincent Coubard 259:323f588e5f57 353
Andrea Palmieri 229:9981f62cdb1a 354 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 355 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 356 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 357 uint8_t *uuid = NULL;
Vincent Coubard 259:323f588e5f57 358
Andrea Palmieri 229:9981f62cdb1a 359 DiscoveredService *service;
Vincent Coubard 259:323f588e5f57 360
Vincent Coubard 259:323f588e5f57 361 // complete the discovery of the last characteristic of the previous service.
Vincent Coubard 259:323f588e5f57 362 // Its last handle wasn't known before this point
Vincent Coubard 259:323f588e5f57 363 // update the handle and call the characteristic discovery callback.
Vincent Coubard 259:323f588e5f57 364 if (_servIndex != 0 && _numChars != 0) {
Vincent Coubard 259:323f588e5f57 365 discoveredChar[_numChars - 1].setLastHandle(discoveredService[_servIndex - 1].getEndHandle());
Vincent Coubard 259:323f588e5f57 366
Vincent Coubard 259:323f588e5f57 367 if(characteristicDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 368 characteristicDiscoveryCallback(&discoveredChar[_numChars - 1]);
Vincent Coubard 259:323f588e5f57 369 }
Vincent Coubard 259:323f588e5f57 370 }
Vincent Coubard 259:323f588e5f57 371
Vincent Coubard 259:323f588e5f57 372 _numChars = 0;
Vincent Coubard 259:323f588e5f57 373
Andrea Palmieri 229:9981f62cdb1a 374 // We finished chars discovery for all services
Andrea Palmieri 229:9981f62cdb1a 375 if(_servIndex >= _numServices) {
Andrea Palmieri 229:9981f62cdb1a 376 PRINTF("!!!We finished chars discovery for all services!!!\n\r");
Andrea Palmieri 229:9981f62cdb1a 377 //_currentState = GATT_CHARS_DISCOVERY_COMPLETE;
Vincent Coubard 259:323f588e5f57 378
Andrea Palmieri 229:9981f62cdb1a 379 terminateServiceDiscovery();
Vincent Coubard 259:323f588e5f57 380
Andrea Palmieri 229:9981f62cdb1a 381 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 382 }
Vincent Coubard 259:323f588e5f57 383
Andrea Palmieri 229:9981f62cdb1a 384 service = &discoveredService[_servIndex];
Andrea Palmieri 229:9981f62cdb1a 385 /*
Andrea Palmieri 229:9981f62cdb1a 386 if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 387 PRINTF("S UUID-%X\r\n", service->getUUID().getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 388 } else {
Andrea Palmieri 229:9981f62cdb1a 389 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 390 const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 391 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 392 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 393 }
Andrea Palmieri 229:9981f62cdb1a 394 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 395 }
Andrea Palmieri 229:9981f62cdb1a 396 */
Vincent Coubard 259:323f588e5f57 397
Vincent Coubard 259:323f588e5f57 398 if(serviceDiscoveryCallback) {
Vincent Coubard 259:323f588e5f57 399 serviceDiscoveryCallback(service);
Vincent Coubard 259:323f588e5f57 400 }
Vincent Coubard 259:323f588e5f57 401
Andrea Palmieri 229:9981f62cdb1a 402 PRINTF("findServiceChars (_servIndex=%d)\n\r", _servIndex);
Andrea Palmieri 229:9981f62cdb1a 403 //ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Andrea Palmieri 229:9981f62cdb1a 404
Vincent Coubard 259:323f588e5f57 405 if(_matchingCharacteristicUUIDIn == BLE_UUID_UNKNOWN) {
Vincent Coubard 259:323f588e5f57 406 PRINTF("findServiceChars (BLE_UUID_UNKNOWN)\n\r");
Vincent Coubard 259:323f588e5f57 407 ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Vincent Coubard 259:323f588e5f57 408 } else {
Vincent Coubard 259:323f588e5f57 409
Vincent Coubard 259:323f588e5f57 410 uint8_t type = _matchingCharacteristicUUIDIn.shortOrLong();
Vincent Coubard 259:323f588e5f57 411
Vincent Coubard 259:323f588e5f57 412 if(type == UUID::UUID_TYPE_SHORT) {
Vincent Coubard 259:323f588e5f57 413 STORE_LE_16(short_uuid, _matchingCharacteristicUUIDIn.getShortUUID());
Vincent Coubard 259:323f588e5f57 414
Vincent Coubard 259:323f588e5f57 415 uuid_type = UUID_TYPE_16;
Vincent Coubard 259:323f588e5f57 416 uuid = short_uuid;
Andrea Palmieri 229:9981f62cdb1a 417 #ifdef DEBUG
Vincent Coubard 259:323f588e5f57 418 PRINTF("findServiceChars C UUID-");
Vincent Coubard 259:323f588e5f57 419 for(unsigned i = 0; i < 2; i++) {
Vincent Coubard 259:323f588e5f57 420 PRINTF("%02X", short_uuid[i]);
Vincent Coubard 259:323f588e5f57 421 }
Vincent Coubard 259:323f588e5f57 422 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 423 #endif
Vincent Coubard 259:323f588e5f57 424 } else if(type==UUID::UUID_TYPE_LONG) {
Vincent Coubard 259:323f588e5f57 425
Vincent Coubard 259:323f588e5f57 426 uuid_type = UUID_TYPE_128;
Vincent Coubard 259:323f588e5f57 427 uuid = (unsigned char*)_matchingCharacteristicUUIDIn.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 428 #ifdef DEBUG
Vincent Coubard 259:323f588e5f57 429 PRINTF("(findServiceChars) C UUID-");
Vincent Coubard 259:323f588e5f57 430 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Vincent Coubard 259:323f588e5f57 431 PRINTF("%02X", uuid[i]);
Vincent Coubard 259:323f588e5f57 432 }
Vincent Coubard 259:323f588e5f57 433 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 434 #endif
Vincent Coubard 259:323f588e5f57 435 }
Vincent Coubard 259:323f588e5f57 436
Vincent Coubard 259:323f588e5f57 437 ret = aci_gatt_disc_charac_by_uuid(connectionHandle,
Vincent Coubard 259:323f588e5f57 438 service->getStartHandle(),
Vincent Coubard 259:323f588e5f57 439 service->getEndHandle(),
Vincent Coubard 259:323f588e5f57 440 uuid_type,
Vincent Coubard 259:323f588e5f57 441 uuid);
Andrea Palmieri 229:9981f62cdb1a 442 }
Andrea Palmieri 229:9981f62cdb1a 443
Andrea Palmieri 229:9981f62cdb1a 444 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 445 _servIndex++;
Andrea Palmieri 229:9981f62cdb1a 446 }
Vincent Coubard 259:323f588e5f57 447
Andrea Palmieri 229:9981f62cdb1a 448 PRINTF("findServiceChars ret=%d\n\r", ret);
Vincent Coubard 259:323f588e5f57 449
Andrea Palmieri 229:9981f62cdb1a 450 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 451 }
Andrea Palmieri 229:9981f62cdb1a 452
Andrea Palmieri 229:9981f62cdb1a 453 ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 454 ServiceDiscovery::ServiceCallback_t sc,
Andrea Palmieri 229:9981f62cdb1a 455 ServiceDiscovery::CharacteristicCallback_t cc,
Andrea Palmieri 229:9981f62cdb1a 456 const UUID &matchingServiceUUID,
Andrea Palmieri 229:9981f62cdb1a 457 const UUID &matchingCharacteristicUUIDIn)
Andrea Palmieri 229:9981f62cdb1a 458 {
Andrea Palmieri 229:9981f62cdb1a 459 PRINTF("launchServiceDiscovery\n\r");
Vincent Coubard 259:323f588e5f57 460
Andrea Palmieri 229:9981f62cdb1a 461 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 462 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 463 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 464 uint8_t *uuid = NULL;
Andrea Palmieri 229:9981f62cdb1a 465 unsigned j;
Andrea Palmieri 229:9981f62cdb1a 466
Andrea Palmieri 229:9981f62cdb1a 467 if(isServiceDiscoveryActive()) {
Andrea Palmieri 229:9981f62cdb1a 468 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 469 }
Andrea Palmieri 229:9981f62cdb1a 470
Andrea Palmieri 229:9981f62cdb1a 471 if(!sc && !cc) {
Andrea Palmieri 229:9981f62cdb1a 472 // nothing to do
Andrea Palmieri 229:9981f62cdb1a 473 PRINTF("launchServiceDiscovery: nothing to do\n\r");
Andrea Palmieri 229:9981f62cdb1a 474 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 475 }
Andrea Palmieri 229:9981f62cdb1a 476
Andrea Palmieri 229:9981f62cdb1a 477 _connectionHandle = connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 478 serviceDiscoveryCallback = sc;
Andrea Palmieri 229:9981f62cdb1a 479 characteristicDiscoveryCallback = cc;
Andrea Palmieri 229:9981f62cdb1a 480 _matchingServiceUUID = matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 481 _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn;
Andrea Palmieri 229:9981f62cdb1a 482
Andrea Palmieri 229:9981f62cdb1a 483 //reset services
Andrea Palmieri 229:9981f62cdb1a 484 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 485 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 486 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 487 for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) {
Andrea Palmieri 229:9981f62cdb1a 488 discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE);
Andrea Palmieri 229:9981f62cdb1a 489 }
Vincent Coubard 259:323f588e5f57 490
Andrea Palmieri 229:9981f62cdb1a 491 if(matchingServiceUUID == BLE_UUID_UNKNOWN) {
Vincent Coubard 259:323f588e5f57 492
Andrea Palmieri 229:9981f62cdb1a 493 // Wildcard: search for all services
Andrea Palmieri 229:9981f62cdb1a 494 ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Vincent Coubard 259:323f588e5f57 495
Andrea Palmieri 229:9981f62cdb1a 496 } else {
Vincent Coubard 259:323f588e5f57 497
Andrea Palmieri 229:9981f62cdb1a 498 uint8_t type = matchingServiceUUID.shortOrLong();
Andrea Palmieri 229:9981f62cdb1a 499 //PRINTF("AddService(): Type:%d\n\r", type);
Vincent Coubard 259:323f588e5f57 500
Andrea Palmieri 229:9981f62cdb1a 501 if(type == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 502 STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 503 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 504 PRINTF("launchServiceDiscovery short_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 505 for(j = 0; j < 2; j++) {
Andrea Palmieri 229:9981f62cdb1a 506 PRINTF("%02X", short_uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 507 }
Andrea Palmieri 229:9981f62cdb1a 508 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 509 #endif
Vincent Coubard 259:323f588e5f57 510
Andrea Palmieri 229:9981f62cdb1a 511 uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 512 uuid = short_uuid;
Vincent Coubard 259:323f588e5f57 513
Andrea Palmieri 229:9981f62cdb1a 514 } else if(type==UUID::UUID_TYPE_LONG) {
Andrea Palmieri 229:9981f62cdb1a 515
Andrea Palmieri 229:9981f62cdb1a 516 uuid_type = UUID_TYPE_128;
Andrea Palmieri 229:9981f62cdb1a 517 uuid = (unsigned char*)matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 518
Andrea Palmieri 229:9981f62cdb1a 519 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 520 PRINTF("launchServiceDiscovery base_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 521 for(j = 0; j < 16; j++) {
Andrea Palmieri 229:9981f62cdb1a 522 PRINTF("%02X", uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 523 }
Andrea Palmieri 229:9981f62cdb1a 524 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 525 #endif
Andrea Palmieri 229:9981f62cdb1a 526 }
Vincent Coubard 259:323f588e5f57 527
Andrea Palmieri 229:9981f62cdb1a 528 // search for specific service by UUID
Andrea Palmieri 229:9981f62cdb1a 529 ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid);
Andrea Palmieri 229:9981f62cdb1a 530 //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 531 }
Vincent Coubard 259:323f588e5f57 532
Andrea Palmieri 229:9981f62cdb1a 533 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 534 _currentState = GATT_SERVICE_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 535 }
Vincent Coubard 259:323f588e5f57 536
Andrea Palmieri 229:9981f62cdb1a 537 PRINTF("launchServiceDiscovery ret=%d\n\r", ret);
Vincent Coubard 259:323f588e5f57 538
Andrea Palmieri 229:9981f62cdb1a 539 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 540 }
Andrea Palmieri 229:9981f62cdb1a 541
Andrea Palmieri 229:9981f62cdb1a 542 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 543 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 544 const UUID &matchingServiceUUID)
Andrea Palmieri 229:9981f62cdb1a 545 {
Andrea Palmieri 229:9981f62cdb1a 546 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 547 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 548 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 549 (void)matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 550
Andrea Palmieri 229:9981f62cdb1a 551 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 552 }
Andrea Palmieri 229:9981f62cdb1a 553
Andrea Palmieri 229:9981f62cdb1a 554 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 555 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 556 GattAttribute::Handle_t startHandle,
Andrea Palmieri 229:9981f62cdb1a 557 GattAttribute::Handle_t endHandle)
Andrea Palmieri 229:9981f62cdb1a 558 {
Andrea Palmieri 229:9981f62cdb1a 559 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 560 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 561 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 562 (void)startHandle;
Andrea Palmieri 229:9981f62cdb1a 563 (void)endHandle;
Andrea Palmieri 229:9981f62cdb1a 564
Andrea Palmieri 229:9981f62cdb1a 565 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 566 }
Andrea Palmieri 229:9981f62cdb1a 567
Andrea Palmieri 229:9981f62cdb1a 568 bool BlueNRGGattClient::isServiceDiscoveryActive(void) const
Andrea Palmieri 229:9981f62cdb1a 569 {
Andrea Palmieri 229:9981f62cdb1a 570 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 571 return true;
Andrea Palmieri 229:9981f62cdb1a 572 }
Andrea Palmieri 229:9981f62cdb1a 573
Andrea Palmieri 229:9981f62cdb1a 574 return false;
Andrea Palmieri 229:9981f62cdb1a 575 /*
Andrea Palmieri 229:9981f62cdb1a 576 if(_currentState == GATT_IDLE ||
Andrea Palmieri 229:9981f62cdb1a 577 _currentState == GATT_DISCOVERY_TERMINATED ||
Andrea Palmieri 229:9981f62cdb1a 578 _currentState == GATT_READ_CHAR ||
Andrea Palmieri 229:9981f62cdb1a 579 _currentState == GATT_WRITE_CHAR ) {
Andrea Palmieri 229:9981f62cdb1a 580 return false;
Andrea Palmieri 229:9981f62cdb1a 581 }
Vincent Coubard 259:323f588e5f57 582
Andrea Palmieri 229:9981f62cdb1a 583 return true;
Andrea Palmieri 229:9981f62cdb1a 584 */
Andrea Palmieri 229:9981f62cdb1a 585 }
Andrea Palmieri 229:9981f62cdb1a 586
Andrea Palmieri 229:9981f62cdb1a 587 void BlueNRGGattClient::terminateServiceDiscovery(void)
Andrea Palmieri 229:9981f62cdb1a 588 {
Andrea Palmieri 229:9981f62cdb1a 589 _currentState = GATT_IDLE;//GATT_DISCOVERY_TERMINATED;
Vincent Coubard 259:323f588e5f57 590
Andrea Palmieri 229:9981f62cdb1a 591 if (terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 592 terminationCallback(_connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 593 }
Andrea Palmieri 229:9981f62cdb1a 594 }
Andrea Palmieri 229:9981f62cdb1a 595
Andrea Palmieri 229:9981f62cdb1a 596 void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 597 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 598 uint8_t* attribute_value)
Andrea Palmieri 229:9981f62cdb1a 599 {
Andrea Palmieri 229:9981f62cdb1a 600 readCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 601 readCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 602 readCBParams.len = event_data_length;
Andrea Palmieri 229:9981f62cdb1a 603 readCBParams.data = attribute_value;
Andrea Palmieri 229:9981f62cdb1a 604
Andrea Palmieri 229:9981f62cdb1a 605 BlueNRGGattClient::getInstance().processReadResponse(&readCBParams);
Andrea Palmieri 229:9981f62cdb1a 606 }
Andrea Palmieri 229:9981f62cdb1a 607
Andrea Palmieri 229:9981f62cdb1a 608 ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const
Andrea Palmieri 229:9981f62cdb1a 609 {
Andrea Palmieri 229:9981f62cdb1a 610 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 611 (void)offset;
Andrea Palmieri 229:9981f62cdb1a 612
Andrea Palmieri 229:9981f62cdb1a 613 tBleStatus ret;
Vincent Coubard 259:323f588e5f57 614
Andrea Palmieri 229:9981f62cdb1a 615 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Vincent Coubard 259:323f588e5f57 616
Vincent Coubard 259:323f588e5f57 617 // Save the attribute_handle not provided by evt_att_read_resp
Andrea Palmieri 229:9981f62cdb1a 618 gattc->readCBParams.handle = attributeHandle;
Vincent Coubard 259:323f588e5f57 619
Andrea Palmieri 229:9981f62cdb1a 620 // FIXME: We need to wait for a while before starting a read
Andrea Palmieri 229:9981f62cdb1a 621 // due to BlueNRG process queue handling
Andrea Palmieri 229:9981f62cdb1a 622 Clock_Wait(100);
Andrea Palmieri 229:9981f62cdb1a 623
Andrea Palmieri 229:9981f62cdb1a 624 ret = aci_gatt_read_charac_val(connHandle, attributeHandle);
Vincent Coubard 259:323f588e5f57 625
Andrea Palmieri 229:9981f62cdb1a 626 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 627 gattc->_currentState = GATT_READ_CHAR;
Andrea Palmieri 229:9981f62cdb1a 628 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 629 }
Andrea Palmieri 229:9981f62cdb1a 630 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 631 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 632 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 633 default:
Andrea Palmieri 229:9981f62cdb1a 634 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 635 }
Andrea Palmieri 229:9981f62cdb1a 636 }
Andrea Palmieri 229:9981f62cdb1a 637
Andrea Palmieri 229:9981f62cdb1a 638 void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 639 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 640 uint16_t attribute_handle,
Andrea Palmieri 229:9981f62cdb1a 641 uint16_t offset,
Andrea Palmieri 229:9981f62cdb1a 642 uint8_t *part_attr_value)
Andrea Palmieri 229:9981f62cdb1a 643 {
Andrea Palmieri 229:9981f62cdb1a 644 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 645 (void)connHandle;
Andrea Palmieri 229:9981f62cdb1a 646
Andrea Palmieri 229:9981f62cdb1a 647 // Update the write response params
Andrea Palmieri 229:9981f62cdb1a 648 writeCBParams.handle = attribute_handle;
Andrea Palmieri 229:9981f62cdb1a 649 writeCBParams.offset = offset;
Andrea Palmieri 229:9981f62cdb1a 650 writeCBParams.len = event_data_length-4; //(?)
Andrea Palmieri 229:9981f62cdb1a 651 writeCBParams.data = part_attr_value;
Andrea Palmieri 229:9981f62cdb1a 652
Andrea Palmieri 229:9981f62cdb1a 653 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 654 }
Andrea Palmieri 229:9981f62cdb1a 655
Andrea Palmieri 229:9981f62cdb1a 656 void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 657 uint8_t event_data_length)
Andrea Palmieri 229:9981f62cdb1a 658 {
Andrea Palmieri 229:9981f62cdb1a 659 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 660 (void)event_data_length;
Andrea Palmieri 229:9981f62cdb1a 661
Andrea Palmieri 229:9981f62cdb1a 662 writeCBParams.connHandle = connHandle;
Vincent Coubard 259:323f588e5f57 663
Andrea Palmieri 229:9981f62cdb1a 664 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 665 }
Andrea Palmieri 229:9981f62cdb1a 666
Andrea Palmieri 229:9981f62cdb1a 667 ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd,
Andrea Palmieri 229:9981f62cdb1a 668 Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 669 GattAttribute::Handle_t attributeHandle,
Andrea Palmieri 229:9981f62cdb1a 670 size_t length,
Andrea Palmieri 229:9981f62cdb1a 671 const uint8_t *value) const
Andrea Palmieri 229:9981f62cdb1a 672 {
Andrea Palmieri 229:9981f62cdb1a 673 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 674 (void)cmd;
Andrea Palmieri 229:9981f62cdb1a 675
Andrea Palmieri 229:9981f62cdb1a 676 tBleStatus ret;
Vincent Coubard 259:323f588e5f57 677
Andrea Palmieri 229:9981f62cdb1a 678 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Vincent Coubard 259:323f588e5f57 679
Andrea Palmieri 229:9981f62cdb1a 680 // We save the write response params (used by the callback) because
Andrea Palmieri 229:9981f62cdb1a 681 // when the aci_gatt_write_charac_value() is used the only event received is the EVT_BLUE_GATT_PROCEDURE_COMPLETE
Andrea Palmieri 229:9981f62cdb1a 682 gattc->writeCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 683 gattc->writeCBParams.writeOp = GattWriteCallbackParams::OP_WRITE_CMD;
Andrea Palmieri 229:9981f62cdb1a 684 gattc->writeCBParams.handle = attributeHandle;
Andrea Palmieri 229:9981f62cdb1a 685 gattc->writeCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 686 gattc->writeCBParams.len = length;
Andrea Palmieri 229:9981f62cdb1a 687 gattc->writeCBParams.data = value;
Vincent Coubard 259:323f588e5f57 688
Andrea Palmieri 229:9981f62cdb1a 689 ret = aci_gatt_write_charac_value(connHandle, attributeHandle, length, const_cast<uint8_t *>(value));
Andrea Palmieri 229:9981f62cdb1a 690 //ret = aci_gatt_write_charac_reliable(connHandle, attributeHandle, 0, length, const_cast<uint8_t *>(value));
Vincent Coubard 259:323f588e5f57 691
Andrea Palmieri 229:9981f62cdb1a 692 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 693 gattc->_currentState = GATT_WRITE_CHAR;
Andrea Palmieri 229:9981f62cdb1a 694 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 695 }
Andrea Palmieri 229:9981f62cdb1a 696 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 697 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 698 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 699 default:
Andrea Palmieri 229:9981f62cdb1a 700 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 701 }
Andrea Palmieri 229:9981f62cdb1a 702
Andrea Palmieri 229:9981f62cdb1a 703 }
Andrea Palmieri 229:9981f62cdb1a 704
Andrea Palmieri 229:9981f62cdb1a 705 void BlueNRGGattClient::discAllCharacDescCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 706 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 707 uint8_t format,
Andrea Palmieri 229:9981f62cdb1a 708 uint8_t *handle_uuid_pair) {
Andrea Palmieri 229:9981f62cdb1a 709 GattAttribute::Handle_t attHandle;
Andrea Palmieri 229:9981f62cdb1a 710 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 711 uint8_t i, numCharacDesc, offset, handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 712
Andrea Palmieri 229:9981f62cdb1a 713 handle_uuid_length = 4; //Handle + UUID_16
Andrea Palmieri 229:9981f62cdb1a 714 if (format == 2)
Andrea Palmieri 229:9981f62cdb1a 715 handle_uuid_length = 18; //Handle + UUID_128
Andrea Palmieri 229:9981f62cdb1a 716
Andrea Palmieri 229:9981f62cdb1a 717 numCharacDesc = (event_data_length - 1) / handle_uuid_length;
Vincent Coubard 259:323f588e5f57 718
Andrea Palmieri 229:9981f62cdb1a 719 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 720
Vincent Coubard 262:a3460768f3b7 721 PRINTF("\r\ncharacteristic descriptor discovered: data length %u, format %u\r\n",
Vincent Coubard 262:a3460768f3b7 722 event_data_length, format);
Vincent Coubard 262:a3460768f3b7 723
Vincent Coubard 262:a3460768f3b7 724
Andrea Palmieri 229:9981f62cdb1a 725 for (i=0; i<numCharacDesc; i++) {
Vincent Coubard 262:a3460768f3b7 726 memcpy(&attHandle, handle_uuid_pair + offset, sizeof(attHandle));
Andrea Palmieri 229:9981f62cdb1a 727
Andrea Palmieri 229:9981f62cdb1a 728 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 729 if (handle_uuid_length == 4) {
Vincent Coubard 259:323f588e5f57 730
Andrea Palmieri 229:9981f62cdb1a 731 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 732 uuid = handle_uuid_pair[offset+3]<<8|handle_uuid_pair[offset+2];
Andrea Palmieri 229:9981f62cdb1a 733 PRINTF("D UUID-%X attHandle=%u\r\n", uuid.getShortUUID(), attHandle);
Vincent Coubard 259:323f588e5f57 734
Andrea Palmieri 229:9981f62cdb1a 735 } else {
Vincent Coubard 259:323f588e5f57 736
Andrea Palmieri 229:9981f62cdb1a 737 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 738 uuid.setupLong(handle_uuid_pair+offset+2, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 739 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 740 PRINTF("D UUID-");
Andrea Palmieri 229:9981f62cdb1a 741 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 742 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 743 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 744 }
Andrea Palmieri 229:9981f62cdb1a 745 #endif
Andrea Palmieri 229:9981f62cdb1a 746 }
Andrea Palmieri 229:9981f62cdb1a 747
Andrea Palmieri 229:9981f62cdb1a 748 if(charDescDiscoveryCallback != NULL) {
Andrea Palmieri 229:9981f62cdb1a 749 CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
Andrea Palmieri 229:9981f62cdb1a 750 _characteristic,
Andrea Palmieri 229:9981f62cdb1a 751 DiscoveredCharacteristicDescriptor(
Andrea Palmieri 229:9981f62cdb1a 752 _characteristic.getGattClient(),
Andrea Palmieri 229:9981f62cdb1a 753 connHandle,
Andrea Palmieri 229:9981f62cdb1a 754 attHandle,
Andrea Palmieri 229:9981f62cdb1a 755 uuid
Andrea Palmieri 229:9981f62cdb1a 756 )
Andrea Palmieri 229:9981f62cdb1a 757 };
Andrea Palmieri 229:9981f62cdb1a 758 charDescDiscoveryCallback(&params);
Andrea Palmieri 229:9981f62cdb1a 759 }
Andrea Palmieri 229:9981f62cdb1a 760
Andrea Palmieri 229:9981f62cdb1a 761 _numCharDesc++;
Andrea Palmieri 229:9981f62cdb1a 762
Andrea Palmieri 229:9981f62cdb1a 763 offset += handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 764 }
Andrea Palmieri 229:9981f62cdb1a 765 }
Andrea Palmieri 229:9981f62cdb1a 766
Andrea Palmieri 229:9981f62cdb1a 767 ble_error_t BlueNRGGattClient::discoverCharacteristicDescriptors(
Andrea Palmieri 229:9981f62cdb1a 768 const DiscoveredCharacteristic& characteristic,
Andrea Palmieri 229:9981f62cdb1a 769 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
Andrea Palmieri 229:9981f62cdb1a 770 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 771
Andrea Palmieri 229:9981f62cdb1a 772 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 773
Andrea Palmieri 229:9981f62cdb1a 774 if(_currentState != GATT_IDLE) {
Andrea Palmieri 229:9981f62cdb1a 775 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 776 }
Andrea Palmieri 229:9981f62cdb1a 777
Andrea Palmieri 229:9981f62cdb1a 778 charDescDiscoveryCallback = discoveryCallback;
Andrea Palmieri 229:9981f62cdb1a 779 charDescTerminationCallback = terminationCallback;
Andrea Palmieri 229:9981f62cdb1a 780
Andrea Palmieri 229:9981f62cdb1a 781 Gap::Handle_t connHandle = characteristic.getConnectionHandle();
Andrea Palmieri 229:9981f62cdb1a 782 GattAttribute::Handle_t valueHandle = characteristic.getValueHandle();
Andrea Palmieri 229:9981f62cdb1a 783 GattAttribute::Handle_t lastHandle = characteristic.getLastHandle();
Andrea Palmieri 229:9981f62cdb1a 784
Vincent Coubard 262:a3460768f3b7 785 PRINTF("Starting aci_gatt_disc_all_charac_descriptors... [%u : %u]\n\r", valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 786 ret = aci_gatt_disc_all_charac_descriptors(connHandle, valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 787
Andrea Palmieri 229:9981f62cdb1a 788 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 789 _currentState = GATT_CHAR_DESC_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 790 _characteristic = characteristic;
Andrea Palmieri 229:9981f62cdb1a 791 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 792 }
Andrea Palmieri 229:9981f62cdb1a 793 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 794 case BLE_STATUS_INVALID_PARAMS:
Andrea Palmieri 229:9981f62cdb1a 795 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 229:9981f62cdb1a 796 default:
Andrea Palmieri 229:9981f62cdb1a 797 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 798 }
Andrea Palmieri 229:9981f62cdb1a 799 }
Andrea Palmieri 229:9981f62cdb1a 800
Andrea Palmieri 229:9981f62cdb1a 801 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 802 /*!
Andrea Palmieri 229:9981f62cdb1a 803 @brief Clear BlueNRGGattServer's state.
Andrea Palmieri 229:9981f62cdb1a 804
Andrea Palmieri 229:9981f62cdb1a 805 @returns ble_error_t
Andrea Palmieri 229:9981f62cdb1a 806
Andrea Palmieri 229:9981f62cdb1a 807 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 808 Everything executed properly
Andrea Palmieri 229:9981f62cdb1a 809 */
Andrea Palmieri 229:9981f62cdb1a 810 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 811 ble_error_t BlueNRGGattClient::reset(void) {
Andrea Palmieri 229:9981f62cdb1a 812 /* Clear all state that is from the parent, including private members */
Andrea Palmieri 229:9981f62cdb1a 813 if (GattClient::reset() != BLE_ERROR_NONE) {
Andrea Palmieri 229:9981f62cdb1a 814 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 815 }
Andrea Palmieri 229:9981f62cdb1a 816
Andrea Palmieri 229:9981f62cdb1a 817 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 818 _matchingServiceUUID = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 819 _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 820
Andrea Palmieri 229:9981f62cdb1a 821 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 822 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 823 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 824 _numCharDesc = 0;
Andrea Palmieri 229:9981f62cdb1a 825
Andrea Palmieri 229:9981f62cdb1a 826 /* Clear class members */
Andrea Palmieri 229:9981f62cdb1a 827 memset(discoveredService, 0, sizeof(discoveredService));
Andrea Palmieri 229:9981f62cdb1a 828 memset(discoveredChar, 0, sizeof(discoveredChar));
Andrea Palmieri 229:9981f62cdb1a 829
Andrea Palmieri 229:9981f62cdb1a 830 return BLE_ERROR_NONE;
Vincent Coubard 259:323f588e5f57 831 }