adaptation for bkap

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Andrea Palmieri
Date:
Mon Jun 20 14:59:06 2016 +0200
Revision:
242:058b2e731adc
Parent:
177:65d9b1b75fca
Parent:
231:a0d2544b38cd
Child:
243:c56decc9c198
Merge branch 'master' into mbed_classic

Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>

Conflicts:
source/BlueNRGGap.cpp
source/BlueNRGGattClient.cpp
x-nucleo-idb0xa1/BlueNRGGattClient.h

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 ******************************************************************************
Andrea Palmieri 229:9981f62cdb1a 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>
Andrea Palmieri 229:9981f62cdb1a 32 */
Andrea Palmieri 229:9981f62cdb1a 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 */
Andrea Palmieri 229:9981f62cdb1a 38
Andrea Palmieri 229:9981f62cdb1a 39 #include "BlueNRGGattClient.h"
Andrea Palmieri 229:9981f62cdb1a 40 #include "BlueNRGGap.h"
Andrea Palmieri 229:9981f62cdb1a 41 #include "Utils.h"
Andrea Palmieri 229:9981f62cdb1a 42 #include "debug.h"
Andrea Palmieri 229:9981f62cdb1a 43
Andrea Palmieri 229:9981f62cdb1a 44 static uint8_t props_mask[] = {
Andrea Palmieri 229:9981f62cdb1a 45 0x01,
Andrea Palmieri 229:9981f62cdb1a 46 0x02,
Andrea Palmieri 229:9981f62cdb1a 47 0x04,
Andrea Palmieri 229:9981f62cdb1a 48 0x08,
Andrea Palmieri 229:9981f62cdb1a 49 0x10,
Andrea Palmieri 229:9981f62cdb1a 50 0x20,
Andrea Palmieri 229:9981f62cdb1a 51 0x40,
Andrea Palmieri 229:9981f62cdb1a 52 0x80
Andrea Palmieri 229:9981f62cdb1a 53 };
Andrea Palmieri 229:9981f62cdb1a 54
Andrea Palmieri 229:9981f62cdb1a 55 void BlueNRGGattClient::gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code)
Andrea Palmieri 229:9981f62cdb1a 56 {
Andrea Palmieri 229:9981f62cdb1a 57 if(error_code != BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 58 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 59 return;
Andrea Palmieri 229:9981f62cdb1a 60 }
Andrea Palmieri 229:9981f62cdb1a 61
Andrea Palmieri 229:9981f62cdb1a 62 // Service Discovery complete
Andrea Palmieri 229:9981f62cdb1a 63 /*
Andrea Palmieri 229:9981f62cdb1a 64 if(_currentState != GATT_IDLE &&
Andrea Palmieri 229:9981f62cdb1a 65 _currentState != GATT_DISCOVERY_TERMINATED &&
Andrea Palmieri 229:9981f62cdb1a 66 _currentState != GATT_WRITE_CHAR &&
Andrea Palmieri 229:9981f62cdb1a 67 _currentState != GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 68 */
Andrea Palmieri 229:9981f62cdb1a 69 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 70 findServiceChars(connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 71 }
Andrea Palmieri 229:9981f62cdb1a 72
Andrea Palmieri 229:9981f62cdb1a 73 if(_currentState == GATT_CHAR_DESC_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 74 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 75 }
Andrea Palmieri 229:9981f62cdb1a 76
Andrea Palmieri 229:9981f62cdb1a 77 // Read complete
Andrea Palmieri 229:9981f62cdb1a 78 if(_currentState == GATT_READ_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 79 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 80 }
Andrea Palmieri 229:9981f62cdb1a 81
Andrea Palmieri 229:9981f62cdb1a 82 // Write complete
Andrea Palmieri 229:9981f62cdb1a 83 if(_currentState == GATT_WRITE_CHAR) {
Andrea Palmieri 229:9981f62cdb1a 84 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 85 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 86 }
Andrea Palmieri 229:9981f62cdb1a 87 }
Andrea Palmieri 229:9981f62cdb1a 88
Andrea Palmieri 229:9981f62cdb1a 89 void BlueNRGGattClient::primaryServicesCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 90 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 91 uint8_t attribute_data_length,
Andrea Palmieri 229:9981f62cdb1a 92 uint8_t *attribute_data_list)
Andrea Palmieri 229:9981f62cdb1a 93 {
Andrea Palmieri 229:9981f62cdb1a 94 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 95 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 96 uint8_t i, offset, numAttr;
Andrea Palmieri 229:9981f62cdb1a 97 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 98 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 99
Andrea Palmieri 229:9981f62cdb1a 100 numAttr = (event_data_length - 1) / attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 101
Andrea Palmieri 229:9981f62cdb1a 102 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 103 for (i=0; i<numAttr; i++) {
Andrea Palmieri 229:9981f62cdb1a 104 startHandle = attribute_data_list[offset];
Andrea Palmieri 229:9981f62cdb1a 105 endHandle = attribute_data_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 106
Andrea Palmieri 229:9981f62cdb1a 107 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 108 if (attribute_data_length == 6) {
Andrea Palmieri 229:9981f62cdb1a 109
Andrea Palmieri 229:9981f62cdb1a 110 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 111 uuid = attribute_data_list[offset+5]<<8|attribute_data_list[offset+4];
Andrea Palmieri 229:9981f62cdb1a 112 PRINTF("S UUID-%X attrs[%u %u]\r\n", uuid.getShortUUID(), startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 113
Andrea Palmieri 229:9981f62cdb1a 114 } else {
Andrea Palmieri 229:9981f62cdb1a 115
Andrea Palmieri 229:9981f62cdb1a 116 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 117 uuid.setupLong(attribute_data_list+offset+4, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 118
Andrea Palmieri 229:9981f62cdb1a 119 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 120 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 121 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 122 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 123 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 124 }
Andrea Palmieri 229:9981f62cdb1a 125 #endif
Andrea Palmieri 229:9981f62cdb1a 126 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 127
Andrea Palmieri 229:9981f62cdb1a 128 }
Andrea Palmieri 229:9981f62cdb1a 129
Andrea Palmieri 229:9981f62cdb1a 130 PRINTF("Setup serviceIndex = %d\n\r", _numServices);
Andrea Palmieri 229:9981f62cdb1a 131 discoveredService[_numServices].setup(uuid, startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 132
Andrea Palmieri 229:9981f62cdb1a 133 if(serviceDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 134 if(_matchingServiceUUID == BLE_UUID_UNKNOWN || _matchingServiceUUID == discoveredService[_numServices].getUUID()) {
Andrea Palmieri 229:9981f62cdb1a 135 serviceDiscoveryCallback(&discoveredService[_numServices]);
Andrea Palmieri 229:9981f62cdb1a 136 }
Andrea Palmieri 229:9981f62cdb1a 137 }
Andrea Palmieri 229:9981f62cdb1a 138 _numServices++;
Andrea Palmieri 229:9981f62cdb1a 139
Andrea Palmieri 229:9981f62cdb1a 140 offset += attribute_data_length;
Andrea Palmieri 229:9981f62cdb1a 141 }
Andrea Palmieri 229:9981f62cdb1a 142
Andrea Palmieri 229:9981f62cdb1a 143 PRINTF("!!!Service Discovery complete (numAttr=%u)!!!\n\r", numAttr);
Andrea Palmieri 229:9981f62cdb1a 144
Andrea Palmieri 229:9981f62cdb1a 145 }
Andrea Palmieri 229:9981f62cdb1a 146
Andrea Palmieri 229:9981f62cdb1a 147 void BlueNRGGattClient::primaryServiceCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 148 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 149 uint8_t *handles_info_list)
Andrea Palmieri 229:9981f62cdb1a 150 {
Andrea Palmieri 229:9981f62cdb1a 151 GattAttribute::Handle_t startHandle, endHandle;
Andrea Palmieri 229:9981f62cdb1a 152 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 153 uint8_t i, offset, numHandlePairs;
Andrea Palmieri 229:9981f62cdb1a 154 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 155 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 156
Andrea Palmieri 229:9981f62cdb1a 157 numHandlePairs = (event_data_length - 1) / 2;
Andrea Palmieri 229:9981f62cdb1a 158
Andrea Palmieri 229:9981f62cdb1a 159 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 160 for (i=0; i<numHandlePairs; i++) {
Andrea Palmieri 229:9981f62cdb1a 161 startHandle = handles_info_list[offset];
Andrea Palmieri 229:9981f62cdb1a 162 endHandle = handles_info_list[offset+2];
Andrea Palmieri 229:9981f62cdb1a 163
Andrea Palmieri 229:9981f62cdb1a 164 PRINTF("primaryServiceCB attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 165
Andrea Palmieri 229:9981f62cdb1a 166
Andrea Palmieri 229:9981f62cdb1a 167 if (_matchingServiceUUID.shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 168 PRINTF("S UUID-%x attrs[%u %u]\r\n", _matchingServiceUUID.getShortUUID(), startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 169 uuid = _matchingServiceUUID.getShortUUID();
Andrea Palmieri 229:9981f62cdb1a 170 } else {
Andrea Palmieri 229:9981f62cdb1a 171 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 172 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 173 const uint8_t *longUUIDBytes = _matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 174 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 175 PRINTF("%02x", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 176 }
Andrea Palmieri 229:9981f62cdb1a 177 #endif
Andrea Palmieri 229:9981f62cdb1a 178 PRINTF(" attrs[%u %u]\r\n", startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 179 uuid.setupLong(_matchingServiceUUID.getBaseUUID(), UUID::MSB);
Andrea Palmieri 229:9981f62cdb1a 180 }
Andrea Palmieri 229:9981f62cdb1a 181
Andrea Palmieri 229:9981f62cdb1a 182 discoveredService[i].setup(uuid, startHandle, endHandle);
Andrea Palmieri 229:9981f62cdb1a 183
Andrea Palmieri 229:9981f62cdb1a 184 if(serviceDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 185 serviceDiscoveryCallback(&discoveredService[_numServices]);
Andrea Palmieri 229:9981f62cdb1a 186 }
Andrea Palmieri 229:9981f62cdb1a 187 _numServices++;
Andrea Palmieri 229:9981f62cdb1a 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 }
Andrea Palmieri 229:9981f62cdb1a 227
Andrea Palmieri 229:9981f62cdb1a 228 // Properties
Andrea Palmieri 229:9981f62cdb1a 229 DiscoveredCharacteristic::Properties_t p;
Andrea Palmieri 229:9981f62cdb1a 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
Andrea Palmieri 229:9981f62cdb1a 265 if(characteristicDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 266 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Andrea Palmieri 229:9981f62cdb1a 267 }
Andrea Palmieri 229:9981f62cdb1a 268 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 269
Andrea Palmieri 229:9981f62cdb1a 270 offset += handle_value_pair_length;
Andrea Palmieri 229:9981f62cdb1a 271 }
Andrea Palmieri 229:9981f62cdb1a 272 }
Andrea Palmieri 229:9981f62cdb1a 273
Andrea Palmieri 229:9981f62cdb1a 274 void BlueNRGGattClient::serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 275 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 276 uint16_t attr_handle,
Andrea Palmieri 229:9981f62cdb1a 277 uint8_t *attr_value)
Andrea Palmieri 229:9981f62cdb1a 278 {
Andrea Palmieri 229:9981f62cdb1a 279 // Charac Properties(1), Charac Value Handle(2), Charac UUID(2/16)
Andrea Palmieri 229:9981f62cdb1a 280 GattAttribute::Handle_t declHandle, valueHandle, lastHandle;
Andrea Palmieri 229:9981f62cdb1a 281 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 282
Andrea Palmieri 229:9981f62cdb1a 283 PRINTF("serviceCharByUUIDCB\n\r");
Andrea Palmieri 229:9981f62cdb1a 284
Andrea Palmieri 229:9981f62cdb1a 285 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 286 if (event_data_length == 7) {
Andrea Palmieri 229:9981f62cdb1a 287 PRINTF("Char UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 288 uuid = attr_value[4]<<8|attr_value[3];
Andrea Palmieri 229:9981f62cdb1a 289 PRINTF("C UUID-%X\r\n", uuid.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 290 } else {
Andrea Palmieri 229:9981f62cdb1a 291 PRINTF("Char UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 292 uuid.setupLong(attr_value+3, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 293 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 294 PRINTF("C UUID-");
Andrea Palmieri 229:9981f62cdb1a 295 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 296 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 297 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 298 }
Andrea Palmieri 229:9981f62cdb1a 299 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 300 #endif
Andrea Palmieri 229:9981f62cdb1a 301 }
Andrea Palmieri 229:9981f62cdb1a 302
Andrea Palmieri 229:9981f62cdb1a 303 // Properties
Andrea Palmieri 229:9981f62cdb1a 304 DiscoveredCharacteristic::Properties_t p;
Andrea Palmieri 229:9981f62cdb1a 305
Andrea Palmieri 229:9981f62cdb1a 306 p._broadcast = (props_mask[0] & attr_value[0]);
Andrea Palmieri 229:9981f62cdb1a 307 p._read = (props_mask[1] & attr_value[0])>>1;
Andrea Palmieri 229:9981f62cdb1a 308 p._writeWoResp = (props_mask[2] & attr_value[0])>>2;
Andrea Palmieri 229:9981f62cdb1a 309 p._write = (props_mask[3] & attr_value[0])>>3;
Andrea Palmieri 229:9981f62cdb1a 310 p._notify = (props_mask[4] & attr_value[0])>>4;
Andrea Palmieri 229:9981f62cdb1a 311 p._indicate = (props_mask[5] & attr_value[0])>>5;
Andrea Palmieri 229:9981f62cdb1a 312 p._authSignedWrite = (props_mask[6] & attr_value[0])>>6;
Andrea Palmieri 229:9981f62cdb1a 313 PRINTF("p._broadcast=%d\n\r", p._broadcast);
Andrea Palmieri 229:9981f62cdb1a 314 PRINTF("p._read=%d\n\r", p._read);
Andrea Palmieri 229:9981f62cdb1a 315 PRINTF("p._writeWoResp=%d\n\r", p._writeWoResp);
Andrea Palmieri 229:9981f62cdb1a 316 PRINTF("p._write=%d\n\r", p._write);
Andrea Palmieri 229:9981f62cdb1a 317 PRINTF("p._notify=%d\n\r", p._notify);
Andrea Palmieri 229:9981f62cdb1a 318 PRINTF("p._indicate=%d\n\r", p._indicate);
Andrea Palmieri 229:9981f62cdb1a 319 PRINTF("p._authSignedWrite=%d\n\r", p._authSignedWrite);
Andrea Palmieri 229:9981f62cdb1a 320
Andrea Palmieri 229:9981f62cdb1a 321 /*
Andrea Palmieri 229:9981f62cdb1a 322 uint8_t props = attr_value[0];
Andrea Palmieri 229:9981f62cdb1a 323 PRINTF("CHAR PROPS: %d\n\r", props);
Andrea Palmieri 229:9981f62cdb1a 324 */
Andrea Palmieri 229:9981f62cdb1a 325
Andrea Palmieri 229:9981f62cdb1a 326 // Handles
Andrea Palmieri 229:9981f62cdb1a 327 declHandle = attr_handle;
Andrea Palmieri 229:9981f62cdb1a 328 valueHandle = attr_value[1];
Andrea Palmieri 229:9981f62cdb1a 329 lastHandle = valueHandle+1;
Andrea Palmieri 229:9981f62cdb1a 330
Andrea Palmieri 229:9981f62cdb1a 331 discoveredChar[_numChars].setup(this,
Andrea Palmieri 229:9981f62cdb1a 332 connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 333 uuid,
Andrea Palmieri 229:9981f62cdb1a 334 p,
Andrea Palmieri 229:9981f62cdb1a 335 declHandle,
Andrea Palmieri 229:9981f62cdb1a 336 valueHandle,
Andrea Palmieri 229:9981f62cdb1a 337 lastHandle);
Andrea Palmieri 229:9981f62cdb1a 338
Andrea Palmieri 229:9981f62cdb1a 339 if(characteristicDiscoveryCallback) {
Andrea Palmieri 229:9981f62cdb1a 340 characteristicDiscoveryCallback(&discoveredChar[_numChars]);
Andrea Palmieri 229:9981f62cdb1a 341 }
Andrea Palmieri 229:9981f62cdb1a 342 _numChars++;
Andrea Palmieri 229:9981f62cdb1a 343 }
Andrea Palmieri 229:9981f62cdb1a 344
Andrea Palmieri 229:9981f62cdb1a 345 ble_error_t BlueNRGGattClient::findServiceChars(Gap::Handle_t connectionHandle)
Andrea Palmieri 229:9981f62cdb1a 346 {
Andrea Palmieri 229:9981f62cdb1a 347 PRINTF("findServiceChars\n\r");
Andrea Palmieri 229:9981f62cdb1a 348
Andrea Palmieri 229:9981f62cdb1a 349 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 350 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 351 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 352 uint8_t *uuid = NULL;
Andrea Palmieri 229:9981f62cdb1a 353
Andrea Palmieri 229:9981f62cdb1a 354 DiscoveredService *service;
Andrea Palmieri 229:9981f62cdb1a 355
Andrea Palmieri 229:9981f62cdb1a 356 // We finished chars discovery for all services
Andrea Palmieri 229:9981f62cdb1a 357 if(_servIndex >= _numServices) {
Andrea Palmieri 229:9981f62cdb1a 358 PRINTF("!!!We finished chars discovery for all services!!!\n\r");
Andrea Palmieri 229:9981f62cdb1a 359 //_currentState = GATT_CHARS_DISCOVERY_COMPLETE;
Andrea Palmieri 229:9981f62cdb1a 360
Andrea Palmieri 229:9981f62cdb1a 361 terminateServiceDiscovery();
Andrea Palmieri 229:9981f62cdb1a 362
Andrea Palmieri 229:9981f62cdb1a 363 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 364 }
Andrea Palmieri 229:9981f62cdb1a 365
Andrea Palmieri 229:9981f62cdb1a 366 service = &discoveredService[_servIndex];
Andrea Palmieri 229:9981f62cdb1a 367 /*
Andrea Palmieri 229:9981f62cdb1a 368 if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 369 PRINTF("S UUID-%X\r\n", service->getUUID().getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 370 } else {
Andrea Palmieri 229:9981f62cdb1a 371 PRINTF("S UUID-");
Andrea Palmieri 229:9981f62cdb1a 372 const uint8_t *longUUIDBytes = service->getUUID().getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 373 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 374 PRINTF("%02X", longUUIDBytes[i]);
Andrea Palmieri 229:9981f62cdb1a 375 }
Andrea Palmieri 229:9981f62cdb1a 376 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 377 }
Andrea Palmieri 229:9981f62cdb1a 378 */
Andrea Palmieri 229:9981f62cdb1a 379
Andrea Palmieri 229:9981f62cdb1a 380 PRINTF("findServiceChars (_servIndex=%d)\n\r", _servIndex);
Andrea Palmieri 229:9981f62cdb1a 381 //ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Andrea Palmieri 229:9981f62cdb1a 382
Andrea Palmieri 229:9981f62cdb1a 383 if(_matchingCharacteristicUUIDIn == BLE_UUID_UNKNOWN) {
Andrea Palmieri 229:9981f62cdb1a 384 PRINTF("findServiceChars (BLE_UUID_UNKNOWN)\n\r");
Andrea Palmieri 229:9981f62cdb1a 385 ret = aci_gatt_disc_all_charac_of_serv(connectionHandle, service->getStartHandle(), service->getEndHandle());
Andrea Palmieri 229:9981f62cdb1a 386 } else {
Andrea Palmieri 229:9981f62cdb1a 387
Andrea Palmieri 229:9981f62cdb1a 388 uint8_t type = _matchingCharacteristicUUIDIn.shortOrLong();
Andrea Palmieri 229:9981f62cdb1a 389
Andrea Palmieri 229:9981f62cdb1a 390 if(type == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 391 STORE_LE_16(short_uuid, _matchingCharacteristicUUIDIn.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 392
Andrea Palmieri 229:9981f62cdb1a 393 uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 394 uuid = short_uuid;
Andrea Palmieri 229:9981f62cdb1a 395 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 396 PRINTF("findServiceChars C UUID-");
Andrea Palmieri 229:9981f62cdb1a 397 for(unsigned i = 0; i < 2; i++) {
Andrea Palmieri 229:9981f62cdb1a 398 PRINTF("%02X", short_uuid[i]);
Andrea Palmieri 229:9981f62cdb1a 399 }
Andrea Palmieri 229:9981f62cdb1a 400 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 401 #endif
Andrea Palmieri 229:9981f62cdb1a 402 } else if(type==UUID::UUID_TYPE_LONG) {
Andrea Palmieri 229:9981f62cdb1a 403
Andrea Palmieri 229:9981f62cdb1a 404 uuid_type = UUID_TYPE_128;
Andrea Palmieri 229:9981f62cdb1a 405 uuid = (unsigned char*)_matchingCharacteristicUUIDIn.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 406 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 407 PRINTF("(findServiceChars) C UUID-");
Andrea Palmieri 229:9981f62cdb1a 408 for (unsigned i = 0; i < UUID::LENGTH_OF_LONG_UUID; i++) {
Andrea Palmieri 229:9981f62cdb1a 409 PRINTF("%02X", uuid[i]);
Andrea Palmieri 229:9981f62cdb1a 410 }
Andrea Palmieri 229:9981f62cdb1a 411 PRINTF("\r\n");
Andrea Palmieri 229:9981f62cdb1a 412 #endif
Andrea Palmieri 229:9981f62cdb1a 413 }
Andrea Palmieri 229:9981f62cdb1a 414
Andrea Palmieri 229:9981f62cdb1a 415 ret = aci_gatt_disc_charac_by_uuid(connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 416 service->getStartHandle(),
Andrea Palmieri 229:9981f62cdb1a 417 service->getEndHandle(),
Andrea Palmieri 229:9981f62cdb1a 418 uuid_type,
Andrea Palmieri 229:9981f62cdb1a 419 uuid);
Andrea Palmieri 229:9981f62cdb1a 420 }
Andrea Palmieri 229:9981f62cdb1a 421
Andrea Palmieri 229:9981f62cdb1a 422 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 423 _servIndex++;
Andrea Palmieri 229:9981f62cdb1a 424 }
Andrea Palmieri 229:9981f62cdb1a 425
Andrea Palmieri 229:9981f62cdb1a 426 PRINTF("findServiceChars ret=%d\n\r", ret);
Andrea Palmieri 229:9981f62cdb1a 427
Andrea Palmieri 229:9981f62cdb1a 428 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 429 }
Andrea Palmieri 229:9981f62cdb1a 430
Andrea Palmieri 229:9981f62cdb1a 431 ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 432 ServiceDiscovery::ServiceCallback_t sc,
Andrea Palmieri 229:9981f62cdb1a 433 ServiceDiscovery::CharacteristicCallback_t cc,
Andrea Palmieri 229:9981f62cdb1a 434 const UUID &matchingServiceUUID,
Andrea Palmieri 229:9981f62cdb1a 435 const UUID &matchingCharacteristicUUIDIn)
Andrea Palmieri 229:9981f62cdb1a 436 {
Andrea Palmieri 229:9981f62cdb1a 437 PRINTF("launchServiceDiscovery\n\r");
Andrea Palmieri 229:9981f62cdb1a 438
Andrea Palmieri 229:9981f62cdb1a 439 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 440 uint8_t uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 441 uint8_t short_uuid[2];
Andrea Palmieri 229:9981f62cdb1a 442 uint8_t *uuid = NULL;
Andrea Palmieri 229:9981f62cdb1a 443 unsigned j;
Andrea Palmieri 229:9981f62cdb1a 444
Andrea Palmieri 229:9981f62cdb1a 445 if(isServiceDiscoveryActive()) {
Andrea Palmieri 229:9981f62cdb1a 446 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 447 }
Andrea Palmieri 229:9981f62cdb1a 448
Andrea Palmieri 229:9981f62cdb1a 449 if(!sc && !cc) {
Andrea Palmieri 229:9981f62cdb1a 450 // nothing to do
Andrea Palmieri 229:9981f62cdb1a 451 PRINTF("launchServiceDiscovery: nothing to do\n\r");
Andrea Palmieri 229:9981f62cdb1a 452 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 453 }
Andrea Palmieri 229:9981f62cdb1a 454
Andrea Palmieri 229:9981f62cdb1a 455 _connectionHandle = connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 456 serviceDiscoveryCallback = sc;
Andrea Palmieri 229:9981f62cdb1a 457 characteristicDiscoveryCallback = cc;
Andrea Palmieri 229:9981f62cdb1a 458 _matchingServiceUUID = matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 459 _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn;
Andrea Palmieri 229:9981f62cdb1a 460
Andrea Palmieri 229:9981f62cdb1a 461 //reset services
Andrea Palmieri 229:9981f62cdb1a 462 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 463 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 464 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 465 for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) {
Andrea Palmieri 229:9981f62cdb1a 466 discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE);
Andrea Palmieri 229:9981f62cdb1a 467 }
Andrea Palmieri 229:9981f62cdb1a 468
Andrea Palmieri 229:9981f62cdb1a 469 if(matchingServiceUUID == BLE_UUID_UNKNOWN) {
Andrea Palmieri 229:9981f62cdb1a 470
Andrea Palmieri 229:9981f62cdb1a 471 // Wildcard: search for all services
Andrea Palmieri 229:9981f62cdb1a 472 ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 473
Andrea Palmieri 229:9981f62cdb1a 474 } else {
Andrea Palmieri 229:9981f62cdb1a 475
Andrea Palmieri 229:9981f62cdb1a 476 uint8_t type = matchingServiceUUID.shortOrLong();
Andrea Palmieri 229:9981f62cdb1a 477 //PRINTF("AddService(): Type:%d\n\r", type);
Andrea Palmieri 229:9981f62cdb1a 478
Andrea Palmieri 229:9981f62cdb1a 479 if(type == UUID::UUID_TYPE_SHORT) {
Andrea Palmieri 229:9981f62cdb1a 480 STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID());
Andrea Palmieri 229:9981f62cdb1a 481 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 482 PRINTF("launchServiceDiscovery short_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 483 for(j = 0; j < 2; j++) {
Andrea Palmieri 229:9981f62cdb1a 484 PRINTF("%02X", short_uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 485 }
Andrea Palmieri 229:9981f62cdb1a 486 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 487 #endif
Andrea Palmieri 229:9981f62cdb1a 488
Andrea Palmieri 229:9981f62cdb1a 489 uuid_type = UUID_TYPE_16;
Andrea Palmieri 229:9981f62cdb1a 490 uuid = short_uuid;
Andrea Palmieri 229:9981f62cdb1a 491
Andrea Palmieri 229:9981f62cdb1a 492 } else if(type==UUID::UUID_TYPE_LONG) {
Andrea Palmieri 229:9981f62cdb1a 493
Andrea Palmieri 229:9981f62cdb1a 494 uuid_type = UUID_TYPE_128;
Andrea Palmieri 229:9981f62cdb1a 495 uuid = (unsigned char*)matchingServiceUUID.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 496
Andrea Palmieri 229:9981f62cdb1a 497 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 498 PRINTF("launchServiceDiscovery base_uuid=0x");
Andrea Palmieri 229:9981f62cdb1a 499 for(j = 0; j < 16; j++) {
Andrea Palmieri 229:9981f62cdb1a 500 PRINTF("%02X", uuid[j]);
Andrea Palmieri 229:9981f62cdb1a 501 }
Andrea Palmieri 229:9981f62cdb1a 502 PRINTF("\n\r");
Andrea Palmieri 229:9981f62cdb1a 503 #endif
Andrea Palmieri 229:9981f62cdb1a 504 }
Andrea Palmieri 229:9981f62cdb1a 505
Andrea Palmieri 229:9981f62cdb1a 506 // search for specific service by UUID
Andrea Palmieri 229:9981f62cdb1a 507 ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid);
Andrea Palmieri 229:9981f62cdb1a 508 //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 509 }
Andrea Palmieri 229:9981f62cdb1a 510
Andrea Palmieri 229:9981f62cdb1a 511 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 512 _currentState = GATT_SERVICE_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 513 }
Andrea Palmieri 229:9981f62cdb1a 514
Andrea Palmieri 229:9981f62cdb1a 515 PRINTF("launchServiceDiscovery ret=%d\n\r", ret);
Andrea Palmieri 229:9981f62cdb1a 516
Andrea Palmieri 229:9981f62cdb1a 517 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 518 }
Andrea Palmieri 229:9981f62cdb1a 519
Andrea Palmieri 229:9981f62cdb1a 520 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 521 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 522 const UUID &matchingServiceUUID)
Andrea Palmieri 229:9981f62cdb1a 523 {
Andrea Palmieri 229:9981f62cdb1a 524 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 525 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 526 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 527 (void)matchingServiceUUID;
Andrea Palmieri 229:9981f62cdb1a 528
Andrea Palmieri 229:9981f62cdb1a 529 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 530 }
Andrea Palmieri 229:9981f62cdb1a 531
Andrea Palmieri 229:9981f62cdb1a 532 ble_error_t BlueNRGGattClient::discoverServices(Gap::Handle_t connectionHandle,
Andrea Palmieri 229:9981f62cdb1a 533 ServiceDiscovery::ServiceCallback_t callback,
Andrea Palmieri 229:9981f62cdb1a 534 GattAttribute::Handle_t startHandle,
Andrea Palmieri 229:9981f62cdb1a 535 GattAttribute::Handle_t endHandle)
Andrea Palmieri 229:9981f62cdb1a 536 {
Andrea Palmieri 229:9981f62cdb1a 537 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 538 (void)connectionHandle;
Andrea Palmieri 229:9981f62cdb1a 539 (void)callback;
Andrea Palmieri 229:9981f62cdb1a 540 (void)startHandle;
Andrea Palmieri 229:9981f62cdb1a 541 (void)endHandle;
Andrea Palmieri 229:9981f62cdb1a 542
Andrea Palmieri 229:9981f62cdb1a 543 return BLE_ERROR_NOT_IMPLEMENTED;
Andrea Palmieri 229:9981f62cdb1a 544 }
Andrea Palmieri 229:9981f62cdb1a 545
Andrea Palmieri 229:9981f62cdb1a 546 bool BlueNRGGattClient::isServiceDiscoveryActive(void) const
Andrea Palmieri 229:9981f62cdb1a 547 {
Andrea Palmieri 229:9981f62cdb1a 548 if(_currentState == GATT_SERVICE_DISCOVERY) {
Andrea Palmieri 229:9981f62cdb1a 549 return true;
Andrea Palmieri 229:9981f62cdb1a 550 }
Andrea Palmieri 229:9981f62cdb1a 551
Andrea Palmieri 229:9981f62cdb1a 552 return false;
Andrea Palmieri 229:9981f62cdb1a 553 /*
Andrea Palmieri 229:9981f62cdb1a 554 if(_currentState == GATT_IDLE ||
Andrea Palmieri 229:9981f62cdb1a 555 _currentState == GATT_DISCOVERY_TERMINATED ||
Andrea Palmieri 229:9981f62cdb1a 556 _currentState == GATT_READ_CHAR ||
Andrea Palmieri 229:9981f62cdb1a 557 _currentState == GATT_WRITE_CHAR ) {
Andrea Palmieri 229:9981f62cdb1a 558 return false;
Andrea Palmieri 229:9981f62cdb1a 559 }
Andrea Palmieri 229:9981f62cdb1a 560
Andrea Palmieri 229:9981f62cdb1a 561 return true;
Andrea Palmieri 229:9981f62cdb1a 562 */
Andrea Palmieri 229:9981f62cdb1a 563 }
Andrea Palmieri 229:9981f62cdb1a 564
Andrea Palmieri 229:9981f62cdb1a 565 void BlueNRGGattClient::terminateServiceDiscovery(void)
Andrea Palmieri 229:9981f62cdb1a 566 {
Andrea Palmieri 229:9981f62cdb1a 567 _currentState = GATT_IDLE;//GATT_DISCOVERY_TERMINATED;
Andrea Palmieri 229:9981f62cdb1a 568
Andrea Palmieri 229:9981f62cdb1a 569 if (terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 570 terminationCallback(_connectionHandle);
Andrea Palmieri 229:9981f62cdb1a 571 }
Andrea Palmieri 229:9981f62cdb1a 572 }
Andrea Palmieri 229:9981f62cdb1a 573
Andrea Palmieri 229:9981f62cdb1a 574 void BlueNRGGattClient::charReadCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 575 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 576 uint8_t* attribute_value)
Andrea Palmieri 229:9981f62cdb1a 577 {
Andrea Palmieri 229:9981f62cdb1a 578 readCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 579 readCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 580 readCBParams.len = event_data_length;
Andrea Palmieri 229:9981f62cdb1a 581 readCBParams.data = attribute_value;
Andrea Palmieri 229:9981f62cdb1a 582
Andrea Palmieri 229:9981f62cdb1a 583 BlueNRGGattClient::getInstance().processReadResponse(&readCBParams);
Andrea Palmieri 229:9981f62cdb1a 584 }
Andrea Palmieri 229:9981f62cdb1a 585
Andrea Palmieri 229:9981f62cdb1a 586 ble_error_t BlueNRGGattClient::read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const
Andrea Palmieri 229:9981f62cdb1a 587 {
Andrea Palmieri 229:9981f62cdb1a 588 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 589 (void)offset;
Andrea Palmieri 229:9981f62cdb1a 590
Andrea Palmieri 229:9981f62cdb1a 591 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 592
Andrea Palmieri 229:9981f62cdb1a 593 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Andrea Palmieri 229:9981f62cdb1a 594
Andrea Palmieri 229:9981f62cdb1a 595 // Save the attribute_handle not provided by evt_att_read_resp
Andrea Palmieri 229:9981f62cdb1a 596 gattc->readCBParams.handle = attributeHandle;
Andrea Palmieri 229:9981f62cdb1a 597
Andrea Palmieri 229:9981f62cdb1a 598 // FIXME: We need to wait for a while before starting a read
Andrea Palmieri 229:9981f62cdb1a 599 // due to BlueNRG process queue handling
Andrea Palmieri 229:9981f62cdb1a 600 Clock_Wait(100);
Andrea Palmieri 229:9981f62cdb1a 601
Andrea Palmieri 229:9981f62cdb1a 602 ret = aci_gatt_read_charac_val(connHandle, attributeHandle);
Andrea Palmieri 229:9981f62cdb1a 603
Andrea Palmieri 229:9981f62cdb1a 604 if(ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 605 gattc->_currentState = GATT_READ_CHAR;
Andrea Palmieri 229:9981f62cdb1a 606 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 607 }
Andrea Palmieri 229:9981f62cdb1a 608 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 609 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 610 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 611 default:
Andrea Palmieri 229:9981f62cdb1a 612 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 613 }
Andrea Palmieri 229:9981f62cdb1a 614 }
Andrea Palmieri 229:9981f62cdb1a 615
Andrea Palmieri 229:9981f62cdb1a 616 void BlueNRGGattClient::charWritePrepareCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 617 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 618 uint16_t attribute_handle,
Andrea Palmieri 229:9981f62cdb1a 619 uint16_t offset,
Andrea Palmieri 229:9981f62cdb1a 620 uint8_t *part_attr_value)
Andrea Palmieri 229:9981f62cdb1a 621 {
Andrea Palmieri 229:9981f62cdb1a 622 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 623 (void)connHandle;
Andrea Palmieri 229:9981f62cdb1a 624
Andrea Palmieri 229:9981f62cdb1a 625 // Update the write response params
Andrea Palmieri 229:9981f62cdb1a 626 writeCBParams.handle = attribute_handle;
Andrea Palmieri 229:9981f62cdb1a 627 writeCBParams.offset = offset;
Andrea Palmieri 229:9981f62cdb1a 628 writeCBParams.len = event_data_length-4; //(?)
Andrea Palmieri 229:9981f62cdb1a 629 writeCBParams.data = part_attr_value;
Andrea Palmieri 229:9981f62cdb1a 630
Andrea Palmieri 229:9981f62cdb1a 631 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 632 }
Andrea Palmieri 229:9981f62cdb1a 633
Andrea Palmieri 229:9981f62cdb1a 634 void BlueNRGGattClient::charWriteExecCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 635 uint8_t event_data_length)
Andrea Palmieri 229:9981f62cdb1a 636 {
Andrea Palmieri 229:9981f62cdb1a 637 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 638 (void)event_data_length;
Andrea Palmieri 229:9981f62cdb1a 639
Andrea Palmieri 229:9981f62cdb1a 640 writeCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 641
Andrea Palmieri 229:9981f62cdb1a 642 BlueNRGGattClient::getInstance().processWriteResponse(&writeCBParams);
Andrea Palmieri 229:9981f62cdb1a 643 }
Andrea Palmieri 229:9981f62cdb1a 644
Andrea Palmieri 229:9981f62cdb1a 645 ble_error_t BlueNRGGattClient::write(GattClient::WriteOp_t cmd,
Andrea Palmieri 229:9981f62cdb1a 646 Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 647 GattAttribute::Handle_t attributeHandle,
Andrea Palmieri 229:9981f62cdb1a 648 size_t length,
Andrea Palmieri 229:9981f62cdb1a 649 const uint8_t *value) const
Andrea Palmieri 229:9981f62cdb1a 650 {
Andrea Palmieri 229:9981f62cdb1a 651 /* avoid compiler warnings about unused variables */
Andrea Palmieri 229:9981f62cdb1a 652 (void)cmd;
Andrea Palmieri 229:9981f62cdb1a 653
Andrea Palmieri 229:9981f62cdb1a 654 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 655
Andrea Palmieri 229:9981f62cdb1a 656 BlueNRGGattClient *gattc = const_cast<BlueNRGGattClient*>(this);
Andrea Palmieri 229:9981f62cdb1a 657
Andrea Palmieri 229:9981f62cdb1a 658 // We save the write response params (used by the callback) because
Andrea Palmieri 229:9981f62cdb1a 659 // when the aci_gatt_write_charac_value() is used the only event received is the EVT_BLUE_GATT_PROCEDURE_COMPLETE
Andrea Palmieri 229:9981f62cdb1a 660 gattc->writeCBParams.connHandle = connHandle;
Andrea Palmieri 229:9981f62cdb1a 661 gattc->writeCBParams.writeOp = GattWriteCallbackParams::OP_WRITE_CMD;
Andrea Palmieri 229:9981f62cdb1a 662 gattc->writeCBParams.handle = attributeHandle;
Andrea Palmieri 229:9981f62cdb1a 663 gattc->writeCBParams.offset = 0;
Andrea Palmieri 229:9981f62cdb1a 664 gattc->writeCBParams.len = length;
Andrea Palmieri 229:9981f62cdb1a 665 gattc->writeCBParams.data = value;
Andrea Palmieri 229:9981f62cdb1a 666
Andrea Palmieri 229:9981f62cdb1a 667 ret = aci_gatt_write_charac_value(connHandle, attributeHandle, length, const_cast<uint8_t *>(value));
Andrea Palmieri 229:9981f62cdb1a 668 //ret = aci_gatt_write_charac_reliable(connHandle, attributeHandle, 0, length, const_cast<uint8_t *>(value));
Andrea Palmieri 229:9981f62cdb1a 669
Andrea Palmieri 229:9981f62cdb1a 670 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 671 gattc->_currentState = GATT_WRITE_CHAR;
Andrea Palmieri 229:9981f62cdb1a 672 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 673 }
Andrea Palmieri 229:9981f62cdb1a 674 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 675 case BLE_STATUS_BUSY:
Andrea Palmieri 229:9981f62cdb1a 676 return BLE_STACK_BUSY;
Andrea Palmieri 229:9981f62cdb1a 677 default:
Andrea Palmieri 229:9981f62cdb1a 678 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 679 }
Andrea Palmieri 229:9981f62cdb1a 680
Andrea Palmieri 229:9981f62cdb1a 681 }
Andrea Palmieri 229:9981f62cdb1a 682
Andrea Palmieri 229:9981f62cdb1a 683 void BlueNRGGattClient::discAllCharacDescCB(Gap::Handle_t connHandle,
Andrea Palmieri 229:9981f62cdb1a 684 uint8_t event_data_length,
Andrea Palmieri 229:9981f62cdb1a 685 uint8_t format,
Andrea Palmieri 229:9981f62cdb1a 686 uint8_t *handle_uuid_pair) {
Andrea Palmieri 229:9981f62cdb1a 687 GattAttribute::Handle_t attHandle;
Andrea Palmieri 229:9981f62cdb1a 688 UUID uuid;
Andrea Palmieri 229:9981f62cdb1a 689 uint8_t i, numCharacDesc, offset, handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 690
Andrea Palmieri 229:9981f62cdb1a 691 handle_uuid_length = 4; //Handle + UUID_16
Andrea Palmieri 229:9981f62cdb1a 692 if (format == 2)
Andrea Palmieri 229:9981f62cdb1a 693 handle_uuid_length = 18; //Handle + UUID_128
Andrea Palmieri 229:9981f62cdb1a 694
Andrea Palmieri 229:9981f62cdb1a 695 numCharacDesc = (event_data_length - 1) / handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 696
Andrea Palmieri 229:9981f62cdb1a 697 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 698
Andrea Palmieri 229:9981f62cdb1a 699 for (i=0; i<numCharacDesc; i++) {
Andrea Palmieri 229:9981f62cdb1a 700 attHandle = handle_uuid_pair[offset];
Andrea Palmieri 229:9981f62cdb1a 701
Andrea Palmieri 229:9981f62cdb1a 702 // UUID Type
Andrea Palmieri 229:9981f62cdb1a 703 if (handle_uuid_length == 4) {
Andrea Palmieri 229:9981f62cdb1a 704
Andrea Palmieri 229:9981f62cdb1a 705 PRINTF("UUID_TYPE_16\n\r");
Andrea Palmieri 229:9981f62cdb1a 706 uuid = handle_uuid_pair[offset+3]<<8|handle_uuid_pair[offset+2];
Andrea Palmieri 229:9981f62cdb1a 707 PRINTF("D UUID-%X attHandle=%u\r\n", uuid.getShortUUID(), attHandle);
Andrea Palmieri 229:9981f62cdb1a 708
Andrea Palmieri 229:9981f62cdb1a 709 } else {
Andrea Palmieri 229:9981f62cdb1a 710
Andrea Palmieri 229:9981f62cdb1a 711 PRINTF("UUID_TYPE_128\n\r");
Andrea Palmieri 229:9981f62cdb1a 712 uuid.setupLong(handle_uuid_pair+offset+2, UUID::LSB);
Andrea Palmieri 229:9981f62cdb1a 713 #ifdef DEBUG
Andrea Palmieri 229:9981f62cdb1a 714 PRINTF("D UUID-");
Andrea Palmieri 229:9981f62cdb1a 715 const uint8_t *longUUIDBytes = uuid.getBaseUUID();
Andrea Palmieri 229:9981f62cdb1a 716 for (unsigned j = 0; j < UUID::LENGTH_OF_LONG_UUID; j++) {
Andrea Palmieri 229:9981f62cdb1a 717 PRINTF("%02x", longUUIDBytes[j]);
Andrea Palmieri 229:9981f62cdb1a 718 }
Andrea Palmieri 229:9981f62cdb1a 719 #endif
Andrea Palmieri 229:9981f62cdb1a 720 }
Andrea Palmieri 229:9981f62cdb1a 721
Andrea Palmieri 229:9981f62cdb1a 722 if(charDescDiscoveryCallback != NULL) {
Andrea Palmieri 229:9981f62cdb1a 723 CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
Andrea Palmieri 229:9981f62cdb1a 724 _characteristic,
Andrea Palmieri 229:9981f62cdb1a 725 DiscoveredCharacteristicDescriptor(
Andrea Palmieri 229:9981f62cdb1a 726 _characteristic.getGattClient(),
Andrea Palmieri 229:9981f62cdb1a 727 connHandle,
Andrea Palmieri 229:9981f62cdb1a 728 attHandle,
Andrea Palmieri 229:9981f62cdb1a 729 uuid
Andrea Palmieri 229:9981f62cdb1a 730 )
Andrea Palmieri 229:9981f62cdb1a 731 };
Andrea Palmieri 229:9981f62cdb1a 732 charDescDiscoveryCallback(&params);
Andrea Palmieri 229:9981f62cdb1a 733 }
Andrea Palmieri 229:9981f62cdb1a 734
Andrea Palmieri 229:9981f62cdb1a 735 _numCharDesc++;
Andrea Palmieri 229:9981f62cdb1a 736
Andrea Palmieri 229:9981f62cdb1a 737 offset += handle_uuid_length;
Andrea Palmieri 229:9981f62cdb1a 738 }
Andrea Palmieri 229:9981f62cdb1a 739
Andrea Palmieri 229:9981f62cdb1a 740 if(charDescTerminationCallback != NULL) {
Andrea Palmieri 229:9981f62cdb1a 741 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
Andrea Palmieri 229:9981f62cdb1a 742 _characteristic,
Andrea Palmieri 229:9981f62cdb1a 743 BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 744 };
Andrea Palmieri 229:9981f62cdb1a 745 charDescTerminationCallback(&params);
Andrea Palmieri 229:9981f62cdb1a 746 }
Andrea Palmieri 229:9981f62cdb1a 747
Andrea Palmieri 229:9981f62cdb1a 748 }
Andrea Palmieri 229:9981f62cdb1a 749
Andrea Palmieri 229:9981f62cdb1a 750 ble_error_t BlueNRGGattClient::discoverCharacteristicDescriptors(
Andrea Palmieri 229:9981f62cdb1a 751 const DiscoveredCharacteristic& characteristic,
Andrea Palmieri 229:9981f62cdb1a 752 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
Andrea Palmieri 229:9981f62cdb1a 753 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback) {
Andrea Palmieri 229:9981f62cdb1a 754
Andrea Palmieri 229:9981f62cdb1a 755 tBleStatus ret;
Andrea Palmieri 229:9981f62cdb1a 756
Andrea Palmieri 229:9981f62cdb1a 757 if(_currentState != GATT_IDLE) {
Andrea Palmieri 229:9981f62cdb1a 758 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 759 }
Andrea Palmieri 229:9981f62cdb1a 760
Andrea Palmieri 229:9981f62cdb1a 761 charDescDiscoveryCallback = discoveryCallback;
Andrea Palmieri 229:9981f62cdb1a 762 charDescTerminationCallback = terminationCallback;
Andrea Palmieri 229:9981f62cdb1a 763
Andrea Palmieri 229:9981f62cdb1a 764 Gap::Handle_t connHandle = characteristic.getConnectionHandle();
Andrea Palmieri 229:9981f62cdb1a 765 GattAttribute::Handle_t valueHandle = characteristic.getValueHandle();
Andrea Palmieri 229:9981f62cdb1a 766 GattAttribute::Handle_t lastHandle = characteristic.getLastHandle();
Andrea Palmieri 229:9981f62cdb1a 767
Andrea Palmieri 231:a0d2544b38cd 768 PRINTF("Starting aci_gatt_disc_all_charac_descriptors...\n\r");
Andrea Palmieri 229:9981f62cdb1a 769 ret = aci_gatt_disc_all_charac_descriptors(connHandle, valueHandle, lastHandle);
Andrea Palmieri 229:9981f62cdb1a 770
Andrea Palmieri 229:9981f62cdb1a 771 if (ret == BLE_STATUS_SUCCESS) {
Andrea Palmieri 229:9981f62cdb1a 772 _currentState = GATT_CHAR_DESC_DISCOVERY;
Andrea Palmieri 229:9981f62cdb1a 773 _characteristic = characteristic;
Andrea Palmieri 229:9981f62cdb1a 774 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 775 }
Andrea Palmieri 229:9981f62cdb1a 776 switch (ret) {
Andrea Palmieri 229:9981f62cdb1a 777 case BLE_STATUS_INVALID_PARAMS:
Andrea Palmieri 229:9981f62cdb1a 778 return BLE_ERROR_INVALID_PARAM;
Andrea Palmieri 229:9981f62cdb1a 779 default:
Andrea Palmieri 229:9981f62cdb1a 780 return BLE_ERROR_OPERATION_NOT_PERMITTED;
Andrea Palmieri 229:9981f62cdb1a 781 }
Andrea Palmieri 229:9981f62cdb1a 782 }
Andrea Palmieri 229:9981f62cdb1a 783
Andrea Palmieri 229:9981f62cdb1a 784 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 785 /*!
Andrea Palmieri 229:9981f62cdb1a 786 @brief Clear BlueNRGGattServer's state.
Andrea Palmieri 229:9981f62cdb1a 787
Andrea Palmieri 229:9981f62cdb1a 788 @returns ble_error_t
Andrea Palmieri 229:9981f62cdb1a 789
Andrea Palmieri 229:9981f62cdb1a 790 @retval BLE_ERROR_NONE
Andrea Palmieri 229:9981f62cdb1a 791 Everything executed properly
Andrea Palmieri 229:9981f62cdb1a 792 */
Andrea Palmieri 229:9981f62cdb1a 793 /**************************************************************************/
Andrea Palmieri 229:9981f62cdb1a 794 ble_error_t BlueNRGGattClient::reset(void) {
Andrea Palmieri 229:9981f62cdb1a 795 /* Clear all state that is from the parent, including private members */
Andrea Palmieri 229:9981f62cdb1a 796 if (GattClient::reset() != BLE_ERROR_NONE) {
Andrea Palmieri 229:9981f62cdb1a 797 return BLE_ERROR_INVALID_STATE;
Andrea Palmieri 229:9981f62cdb1a 798 }
Andrea Palmieri 229:9981f62cdb1a 799
Andrea Palmieri 229:9981f62cdb1a 800 _currentState = GATT_IDLE;
Andrea Palmieri 229:9981f62cdb1a 801 _matchingServiceUUID = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 802 _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN;
Andrea Palmieri 229:9981f62cdb1a 803
Andrea Palmieri 229:9981f62cdb1a 804 _numServices = 0;
Andrea Palmieri 229:9981f62cdb1a 805 _servIndex = 0;
Andrea Palmieri 229:9981f62cdb1a 806 _numChars = 0;
Andrea Palmieri 229:9981f62cdb1a 807 _numCharDesc = 0;
Andrea Palmieri 229:9981f62cdb1a 808
Andrea Palmieri 229:9981f62cdb1a 809 /* Clear class members */
Andrea Palmieri 229:9981f62cdb1a 810 memset(discoveredService, 0, sizeof(discoveredService));
Andrea Palmieri 229:9981f62cdb1a 811 memset(discoveredChar, 0, sizeof(discoveredChar));
Andrea Palmieri 229:9981f62cdb1a 812
Andrea Palmieri 229:9981f62cdb1a 813 return BLE_ERROR_NONE;
Andrea Palmieri 229:9981f62cdb1a 814 }
Andrea Palmieri 229:9981f62cdb1a 815
Andrea Palmieri 242:058b2e731adc 816 >>>>>>> master