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