X_NUCLEO_IDB05A1
Dependencies: mbed-os-example-ble-Advertising
source/BlueNRGGattServer.cpp@229:9981f62cdb1a, 2016-05-16 (annotated)
- Committer:
- Andrea Palmieri
- Date:
- Mon May 16 17:22:03 2016 +0200
- Revision:
- 229:9981f62cdb1a
- Parent:
- 207:b9df918d6d5a
- Child:
- 233:488e0e8b9b43
Fix issues and add features
- Fix handles management
- Fix UUIDs management
- Implement API to read random address
- Fix clearing/setting of ADV payload
- Fix scanning behaviour
- Fix scanning while a connection is ongoing
- Implement Char Descriptor discovery
- Implement scanning/advertising filter policy (White List partial management)
- Update underlying BlueNRG stack
- Cosmetics
Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
130:770ce14d3d15 | 1 | /* mbed Microcontroller Library |
Wolfgang Betz |
130:770ce14d3d15 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Wolfgang Betz |
130:770ce14d3d15 | 3 | * |
Wolfgang Betz |
130:770ce14d3d15 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Wolfgang Betz |
130:770ce14d3d15 | 5 | * you may not use this file except in compliance with the License. |
Wolfgang Betz |
130:770ce14d3d15 | 6 | * You may obtain a copy of the License at |
Wolfgang Betz |
130:770ce14d3d15 | 7 | * |
Wolfgang Betz |
130:770ce14d3d15 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wolfgang Betz |
130:770ce14d3d15 | 9 | * |
Wolfgang Betz |
130:770ce14d3d15 | 10 | * Unless required by applicable law or agreed to in writing, software |
Wolfgang Betz |
130:770ce14d3d15 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Wolfgang Betz |
130:770ce14d3d15 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Wolfgang Betz |
130:770ce14d3d15 | 13 | * See the License for the specific language governing permissions and |
Wolfgang Betz |
130:770ce14d3d15 | 14 | * limitations under the License. |
Wolfgang Betz |
130:770ce14d3d15 | 15 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 16 | /** |
Wolfgang Betz |
130:770ce14d3d15 | 17 | ****************************************************************************** |
Wolfgang Betz |
130:770ce14d3d15 | 18 | * @file BlueNRGGattServer.cpp |
Wolfgang Betz |
130:770ce14d3d15 | 19 | * @author STMicroelectronics |
Wolfgang Betz |
130:770ce14d3d15 | 20 | * @brief Implementation of BlueNRG BLE_API GattServer Class |
Wolfgang Betz |
130:770ce14d3d15 | 21 | ****************************************************************************** |
Wolfgang Betz |
130:770ce14d3d15 | 22 | * @copy |
Wolfgang Betz |
130:770ce14d3d15 | 23 | * |
Wolfgang Betz |
130:770ce14d3d15 | 24 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
Wolfgang Betz |
130:770ce14d3d15 | 25 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
Wolfgang Betz |
130:770ce14d3d15 | 26 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
Wolfgang Betz |
130:770ce14d3d15 | 27 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
Wolfgang Betz |
130:770ce14d3d15 | 28 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
Wolfgang Betz |
130:770ce14d3d15 | 29 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
Wolfgang Betz |
130:770ce14d3d15 | 30 | * |
Wolfgang Betz |
130:770ce14d3d15 | 31 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
Andrea Palmieri |
229:9981f62cdb1a | 32 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 33 | |
Wolfgang Betz |
130:770ce14d3d15 | 34 | /** @defgroup BlueNRGGATTSERVER |
Wolfgang Betz |
130:770ce14d3d15 | 35 | * @brief BlueNRG BLE_API GattServer Adaptation |
Wolfgang Betz |
130:770ce14d3d15 | 36 | * @{ |
Wolfgang Betz |
130:770ce14d3d15 | 37 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 38 | |
Wolfgang Betz |
130:770ce14d3d15 | 39 | #include "BlueNRGGattServer.h" |
Wolfgang Betz |
144:bdf5e8432131 | 40 | #include "mbed-drivers/mbed.h" |
Wolfgang Betz |
130:770ce14d3d15 | 41 | #include "BlueNRGGap.h" |
Wolfgang Betz |
130:770ce14d3d15 | 42 | #include "Utils.h" |
Wolfgang Betz |
132:51056160fa4a | 43 | #include "debug.h" |
Wolfgang Betz |
130:770ce14d3d15 | 44 | |
Wolfgang Betz |
130:770ce14d3d15 | 45 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 46 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 47 | @brief Adds a new service to the GATT table on the peripheral |
Wolfgang Betz |
130:770ce14d3d15 | 48 | |
Wolfgang Betz |
130:770ce14d3d15 | 49 | @params[in] service |
Wolfgang Betz |
130:770ce14d3d15 | 50 | Pointer to instance of the Gatt Server to add |
Wolfgang Betz |
130:770ce14d3d15 | 51 | |
Wolfgang Betz |
130:770ce14d3d15 | 52 | @returns ble_error_t |
Wolfgang Betz |
130:770ce14d3d15 | 53 | |
Wolfgang Betz |
130:770ce14d3d15 | 54 | @retval BLE_ERROR_NONE |
Wolfgang Betz |
130:770ce14d3d15 | 55 | Everything executed properly |
Wolfgang Betz |
130:770ce14d3d15 | 56 | |
Wolfgang Betz |
130:770ce14d3d15 | 57 | @section EXAMPLE |
Wolfgang Betz |
130:770ce14d3d15 | 58 | |
Wolfgang Betz |
130:770ce14d3d15 | 59 | @code |
Wolfgang Betz |
130:770ce14d3d15 | 60 | |
Wolfgang Betz |
130:770ce14d3d15 | 61 | @endcode |
Wolfgang Betz |
130:770ce14d3d15 | 62 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 63 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 64 | ble_error_t BlueNRGGattServer::addService(GattService &service) |
Wolfgang Betz |
130:770ce14d3d15 | 65 | { |
Wolfgang Betz |
130:770ce14d3d15 | 66 | /* ToDo: Make sure we don't overflow the array, etc. */ |
Wolfgang Betz |
130:770ce14d3d15 | 67 | /* ToDo: Make sure this service UUID doesn't already exist (?) */ |
Wolfgang Betz |
130:770ce14d3d15 | 68 | /* ToDo: Basic validation */ |
Wolfgang Betz |
130:770ce14d3d15 | 69 | |
Wolfgang Betz |
130:770ce14d3d15 | 70 | tBleStatus ret; |
Wolfgang Betz |
130:770ce14d3d15 | 71 | uint8_t type; |
Wolfgang Betz |
130:770ce14d3d15 | 72 | uint16_t short_uuid; |
Wolfgang Betz |
130:770ce14d3d15 | 73 | uint8_t primary_short_uuid[2]; |
Wolfgang Betz |
130:770ce14d3d15 | 74 | uint8_t primary_base_uuid[16]; |
Wolfgang Betz |
130:770ce14d3d15 | 75 | uint8_t char_base_uuid[16]; |
Wolfgang Betz |
130:770ce14d3d15 | 76 | const uint8_t *base_uuid; |
Wolfgang Betz |
130:770ce14d3d15 | 77 | const uint8_t *base_char_uuid; |
Wolfgang Betz |
130:770ce14d3d15 | 78 | |
Wolfgang Betz |
130:770ce14d3d15 | 79 | uint8_t charsCount = 0; |
Wolfgang Betz |
130:770ce14d3d15 | 80 | uint8_t maxAttrRecords = 0; |
Wolfgang Betz |
130:770ce14d3d15 | 81 | |
Wolfgang Betz |
130:770ce14d3d15 | 82 | type = (service.getUUID()).shortOrLong(); |
Wolfgang Betz |
132:51056160fa4a | 83 | PRINTF("AddService(): Type:%d\n\r", type); |
Wolfgang Betz |
130:770ce14d3d15 | 84 | |
Wolfgang Betz |
130:770ce14d3d15 | 85 | /* Add the service to the BlueNRG */ |
Wolfgang Betz |
130:770ce14d3d15 | 86 | short_uuid = (service.getUUID()).getShortUUID(); |
Wolfgang Betz |
130:770ce14d3d15 | 87 | STORE_LE_16(primary_short_uuid, short_uuid); |
Wolfgang Betz |
130:770ce14d3d15 | 88 | |
Wolfgang Betz |
130:770ce14d3d15 | 89 | if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
130:770ce14d3d15 | 90 | base_uuid = (service.getUUID()).getBaseUUID(); |
Wolfgang Betz |
130:770ce14d3d15 | 91 | |
Andrea Palmieri |
207:b9df918d6d5a | 92 | COPY_UUID_128(primary_base_uuid, base_uuid[15],base_uuid[14],primary_short_uuid[1],primary_short_uuid[0],base_uuid[11],base_uuid[10],base_uuid[9],base_uuid[8],base_uuid[7],base_uuid[6],base_uuid[5],base_uuid[4],base_uuid[3],base_uuid[2],base_uuid[1],base_uuid[0]); |
Wolfgang Betz |
130:770ce14d3d15 | 93 | } |
Wolfgang Betz |
130:770ce14d3d15 | 94 | |
Wolfgang Betz |
130:770ce14d3d15 | 95 | charsCount = service.getCharacteristicCount(); |
Wolfgang Betz |
130:770ce14d3d15 | 96 | //1(service record)+2records*char+1record*char_desc |
Wolfgang Betz |
130:770ce14d3d15 | 97 | maxAttrRecords = 1+3*charsCount; |
Wolfgang Betz |
130:770ce14d3d15 | 98 | |
Wolfgang Betz |
130:770ce14d3d15 | 99 | if(type==UUID::UUID_TYPE_SHORT) { |
Wolfgang Betz |
130:770ce14d3d15 | 100 | ret = aci_gatt_add_serv(UUID_TYPE_16, |
Wolfgang Betz |
130:770ce14d3d15 | 101 | primary_short_uuid, |
Wolfgang Betz |
130:770ce14d3d15 | 102 | PRIMARY_SERVICE, |
Wolfgang Betz |
130:770ce14d3d15 | 103 | maxAttrRecords/*7*/, |
Wolfgang Betz |
130:770ce14d3d15 | 104 | &servHandle); |
Wolfgang Betz |
132:51056160fa4a | 105 | PRINTF("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); |
Wolfgang Betz |
130:770ce14d3d15 | 106 | } |
Wolfgang Betz |
130:770ce14d3d15 | 107 | else if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
130:770ce14d3d15 | 108 | ret = aci_gatt_add_serv(UUID_TYPE_128, |
Wolfgang Betz |
130:770ce14d3d15 | 109 | primary_base_uuid, |
Wolfgang Betz |
130:770ce14d3d15 | 110 | PRIMARY_SERVICE, |
Wolfgang Betz |
130:770ce14d3d15 | 111 | maxAttrRecords/*7*/, |
Wolfgang Betz |
130:770ce14d3d15 | 112 | &servHandle); |
Wolfgang Betz |
132:51056160fa4a | 113 | PRINTF("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); |
Wolfgang Betz |
130:770ce14d3d15 | 114 | } |
Wolfgang Betz |
130:770ce14d3d15 | 115 | |
Wolfgang Betz |
130:770ce14d3d15 | 116 | service.setHandle(servHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 117 | //serviceHandleVector.push_back(servHandle); |
Wolfgang Betz |
132:51056160fa4a | 118 | PRINTF("added servHandle handle =%u\n\r", servHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 119 | uint16_t bleCharacteristic; |
Wolfgang Betz |
130:770ce14d3d15 | 120 | |
Wolfgang Betz |
130:770ce14d3d15 | 121 | //iterate to include all characteristics |
Wolfgang Betz |
130:770ce14d3d15 | 122 | for (uint8_t i = 0; i < charsCount; i++) { |
Wolfgang Betz |
130:770ce14d3d15 | 123 | GattCharacteristic *p_char = service.getCharacteristic(i); |
Andrea Palmieri |
229:9981f62cdb1a | 124 | uint16_t char_uuid = (p_char->getValueAttribute().getUUID()).getShortUUID(); |
Andrea Palmieri |
229:9981f62cdb1a | 125 | |
Wolfgang Betz |
130:770ce14d3d15 | 126 | uint8_t int_8_uuid[2]; |
Wolfgang Betz |
130:770ce14d3d15 | 127 | STORE_LE_16(int_8_uuid, char_uuid); |
Andrea Palmieri |
229:9981f62cdb1a | 128 | |
Andrea Palmieri |
229:9981f62cdb1a | 129 | type = (p_char->getValueAttribute().getUUID()).shortOrLong(); |
Andrea Palmieri |
229:9981f62cdb1a | 130 | |
Wolfgang Betz |
130:770ce14d3d15 | 131 | if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
130:770ce14d3d15 | 132 | base_char_uuid = (p_char->getValueAttribute().getUUID()).getBaseUUID(); |
Andrea Palmieri |
229:9981f62cdb1a | 133 | #ifdef DEBUG |
Andrea Palmieri |
229:9981f62cdb1a | 134 | for(uint8_t j=0; j<16; j++) { |
Andrea Palmieri |
229:9981f62cdb1a | 135 | PRINTF("base_char_uuid[%d] 0x%02x ", j, base_char_uuid[j]); |
Andrea Palmieri |
229:9981f62cdb1a | 136 | } |
Andrea Palmieri |
229:9981f62cdb1a | 137 | PRINTF("\n\r"); |
Andrea Palmieri |
229:9981f62cdb1a | 138 | #endif |
Andrea Palmieri |
207:b9df918d6d5a | 139 | COPY_UUID_128(char_base_uuid,base_char_uuid[15],base_char_uuid[14],int_8_uuid[1],int_8_uuid[0],base_char_uuid[11],base_char_uuid[10],base_char_uuid[9],base_char_uuid[8],base_char_uuid[7],base_char_uuid[6],base_char_uuid[5],base_char_uuid[4],base_char_uuid[3],base_char_uuid[2],base_char_uuid[1],base_char_uuid[0]); |
Wolfgang Betz |
130:770ce14d3d15 | 140 | } |
Wolfgang Betz |
130:770ce14d3d15 | 141 | |
Wolfgang Betz |
132:51056160fa4a | 142 | PRINTF("Char Properties 0x%x\n\r", p_char->getProperties()); |
Wolfgang Betz |
130:770ce14d3d15 | 143 | /* |
Wolfgang Betz |
130:770ce14d3d15 | 144 | * Gatt_Evt_Mask -> HardCoded (0) |
Wolfgang Betz |
130:770ce14d3d15 | 145 | * Encryption_Key_Size -> Hardcoded (16) |
Wolfgang Betz |
130:770ce14d3d15 | 146 | * isVariable (variable length value field) -> Hardcoded (1) |
Wolfgang Betz |
130:770ce14d3d15 | 147 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 148 | uint8_t Gatt_Evt_Mask = 0x0; |
Wolfgang Betz |
130:770ce14d3d15 | 149 | |
Wolfgang Betz |
130:770ce14d3d15 | 150 | if((p_char->getProperties() & |
Wolfgang Betz |
130:770ce14d3d15 | 151 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE| |
Wolfgang Betz |
130:770ce14d3d15 | 152 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE))) { |
Wolfgang Betz |
132:51056160fa4a | 153 | PRINTF("Setting up Gatt GATT_NOTIFY_ATTRIBUTE_WRITE Mask\n\r"); |
Wolfgang Betz |
130:770ce14d3d15 | 154 | Gatt_Evt_Mask = Gatt_Evt_Mask | GATT_NOTIFY_ATTRIBUTE_WRITE; |
Wolfgang Betz |
130:770ce14d3d15 | 155 | } |
Wolfgang Betz |
130:770ce14d3d15 | 156 | if((p_char->getProperties() & |
Wolfgang Betz |
130:770ce14d3d15 | 157 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ| |
Wolfgang Betz |
130:770ce14d3d15 | 158 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY| GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) { |
Wolfgang Betz |
132:51056160fa4a | 159 | PRINTF("Setting up Gatt GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP Mask\n\r"); |
Wolfgang Betz |
130:770ce14d3d15 | 160 | Gatt_Evt_Mask = Gatt_Evt_Mask | GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP; |
Wolfgang Betz |
130:770ce14d3d15 | 161 | } //This will support also GATT_SERVER_ATTR_READ_WRITE since it will be covered by previous if() check. |
Wolfgang Betz |
130:770ce14d3d15 | 162 | |
Wolfgang Betz |
130:770ce14d3d15 | 163 | if(type==UUID::UUID_TYPE_SHORT) { |
Wolfgang Betz |
130:770ce14d3d15 | 164 | ret = aci_gatt_add_char(service.getHandle(), |
Wolfgang Betz |
130:770ce14d3d15 | 165 | UUID_TYPE_16, |
Wolfgang Betz |
130:770ce14d3d15 | 166 | int_8_uuid, |
Wolfgang Betz |
130:770ce14d3d15 | 167 | p_char->getValueAttribute().getMaxLength() /*2*/ /*Value Length*/, |
Wolfgang Betz |
130:770ce14d3d15 | 168 | p_char->getProperties(), |
Wolfgang Betz |
130:770ce14d3d15 | 169 | ATTR_PERMISSION_NONE, |
Wolfgang Betz |
130:770ce14d3d15 | 170 | Gatt_Evt_Mask /*Gatt_Evt_Mask*/, |
Wolfgang Betz |
130:770ce14d3d15 | 171 | 16 /*Encryption_Key_Size*/, |
Wolfgang Betz |
130:770ce14d3d15 | 172 | 1 /*isVariable*/, |
Wolfgang Betz |
130:770ce14d3d15 | 173 | &bleCharacteristic); |
Wolfgang Betz |
130:770ce14d3d15 | 174 | |
Andrea Palmieri |
229:9981f62cdb1a | 175 | PRINTF("aci_gatt_add_char UUID_TYPE_16 props=%d MaxLength=%d ret=%d\n\r", |
Andrea Palmieri |
229:9981f62cdb1a | 176 | p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); |
Wolfgang Betz |
130:770ce14d3d15 | 177 | |
Wolfgang Betz |
130:770ce14d3d15 | 178 | } else if(type==UUID::UUID_TYPE_LONG) { |
Wolfgang Betz |
130:770ce14d3d15 | 179 | ret = aci_gatt_add_char(service.getHandle(), |
Wolfgang Betz |
130:770ce14d3d15 | 180 | UUID_TYPE_128, |
Wolfgang Betz |
130:770ce14d3d15 | 181 | char_base_uuid, |
Wolfgang Betz |
130:770ce14d3d15 | 182 | p_char->getValueAttribute().getMaxLength() /*2*/ /*Value Length*/, |
Wolfgang Betz |
130:770ce14d3d15 | 183 | p_char->getProperties(), |
Wolfgang Betz |
130:770ce14d3d15 | 184 | ATTR_PERMISSION_NONE, |
Wolfgang Betz |
130:770ce14d3d15 | 185 | Gatt_Evt_Mask /*Gatt_Evt_Mask*/, |
Wolfgang Betz |
130:770ce14d3d15 | 186 | 16 /*Encryption_Key_Size*/, |
Wolfgang Betz |
130:770ce14d3d15 | 187 | 1 /*isVariable*/, |
Wolfgang Betz |
130:770ce14d3d15 | 188 | &bleCharacteristic); |
Wolfgang Betz |
130:770ce14d3d15 | 189 | |
Andrea Palmieri |
229:9981f62cdb1a | 190 | PRINTF("aci_gatt_add_char UUID_TYPE_128 props=%d MaxLength=%d ret=%d\n\r", |
Andrea Palmieri |
229:9981f62cdb1a | 191 | p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); |
Wolfgang Betz |
130:770ce14d3d15 | 192 | } |
Wolfgang Betz |
130:770ce14d3d15 | 193 | |
Andrea Palmieri |
229:9981f62cdb1a | 194 | bleCharHandleMap.insert(std::pair<uint16_t, uint16_t>(bleCharacteristic, servHandle)); |
Wolfgang Betz |
130:770ce14d3d15 | 195 | |
Wolfgang Betz |
130:770ce14d3d15 | 196 | p_characteristics[characteristicCount++] = p_char; |
Andrea Palmieri |
229:9981f62cdb1a | 197 | /* Set the characteristic value handle */ |
Andrea Palmieri |
229:9981f62cdb1a | 198 | p_char->getValueAttribute().setHandle(bleCharacteristic+BlueNRGGattServer::CHAR_VALUE_HANDLE); |
Andrea Palmieri |
229:9981f62cdb1a | 199 | PRINTF("added bleCharacteristic (value handle =%u)\n\r", p_char->getValueAttribute().getHandle()); |
Wolfgang Betz |
130:770ce14d3d15 | 200 | |
Andrea Palmieri |
202:caf4864292c1 | 201 | if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) { |
Andrea Palmieri |
229:9981f62cdb1a | 202 | write(p_char->getValueAttribute().getHandle(), |
Andrea Palmieri |
229:9981f62cdb1a | 203 | p_char->getValueAttribute().getValuePtr(), |
Andrea Palmieri |
229:9981f62cdb1a | 204 | p_char->getValueAttribute().getLength(), false /* localOnly */); |
Wolfgang Betz |
130:770ce14d3d15 | 205 | } |
Wolfgang Betz |
130:770ce14d3d15 | 206 | |
Wolfgang Betz |
130:770ce14d3d15 | 207 | // add descriptors now |
Wolfgang Betz |
130:770ce14d3d15 | 208 | uint16_t descHandle = 0; |
Wolfgang Betz |
132:51056160fa4a | 209 | PRINTF("p_char->getDescriptorCount()=%d\n\r", p_char->getDescriptorCount()); |
Wolfgang Betz |
130:770ce14d3d15 | 210 | |
Wolfgang Betz |
130:770ce14d3d15 | 211 | for(uint8_t descIndex=0; descIndex<p_char->getDescriptorCount(); descIndex++) { |
Wolfgang Betz |
130:770ce14d3d15 | 212 | GattAttribute *descriptor = p_char->getDescriptor(descIndex); |
Wolfgang Betz |
130:770ce14d3d15 | 213 | uint16_t shortUUID = descriptor->getUUID().getShortUUID(); |
Wolfgang Betz |
130:770ce14d3d15 | 214 | const uint8_t uuidArray[] = {(uint8_t)((shortUUID>>8)&0xFF), (uint8_t)((shortUUID&0xFF))}; |
Andrea Palmieri |
229:9981f62cdb1a | 215 | ret = aci_gatt_add_char_desc(service.getHandle(), |
Andrea Palmieri |
229:9981f62cdb1a | 216 | bleCharacteristic, |
Andrea Palmieri |
229:9981f62cdb1a | 217 | CHAR_DESC_TYPE_16_BIT, |
Andrea Palmieri |
229:9981f62cdb1a | 218 | uuidArray, |
Andrea Palmieri |
229:9981f62cdb1a | 219 | descriptor->getMaxLength(), |
Andrea Palmieri |
229:9981f62cdb1a | 220 | descriptor->getLength(), |
Andrea Palmieri |
229:9981f62cdb1a | 221 | descriptor->getValuePtr(), |
Andrea Palmieri |
229:9981f62cdb1a | 222 | CHAR_DESC_SECURITY_PERMISSION, |
Andrea Palmieri |
229:9981f62cdb1a | 223 | CHAR_DESC_ACCESS_PERMISSION, |
Andrea Palmieri |
229:9981f62cdb1a | 224 | GATT_NOTIFY_ATTRIBUTE_WRITE, |
Andrea Palmieri |
229:9981f62cdb1a | 225 | MIN_ENCRY_KEY_SIZE, |
Andrea Palmieri |
229:9981f62cdb1a | 226 | CHAR_ATTRIBUTE_LEN_IS_FIXED, |
Andrea Palmieri |
229:9981f62cdb1a | 227 | &descHandle); |
Wolfgang Betz |
132:51056160fa4a | 228 | PRINTF("Adding Descriptor descriptor handle=%d ret=%d\n\r", descHandle, ret); |
Wolfgang Betz |
130:770ce14d3d15 | 229 | if(ret==(tBleStatus)0) { |
Wolfgang Betz |
132:51056160fa4a | 230 | PRINTF("Descriptor added successfully, descriptor handle=%d\n\r", descHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 231 | descriptor->setHandle(descHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 232 | } |
Wolfgang Betz |
130:770ce14d3d15 | 233 | } |
Wolfgang Betz |
130:770ce14d3d15 | 234 | |
Wolfgang Betz |
130:770ce14d3d15 | 235 | } |
Wolfgang Betz |
130:770ce14d3d15 | 236 | |
Wolfgang Betz |
130:770ce14d3d15 | 237 | serviceCount++; |
Wolfgang Betz |
130:770ce14d3d15 | 238 | |
Wolfgang Betz |
130:770ce14d3d15 | 239 | //FIXME: There is no GattService pointer array in GattServer. |
Wolfgang Betz |
130:770ce14d3d15 | 240 | // There should be one? (Only the user is aware of GattServices!) Report to forum. |
Wolfgang Betz |
130:770ce14d3d15 | 241 | |
Wolfgang Betz |
130:770ce14d3d15 | 242 | return BLE_ERROR_NONE; |
Wolfgang Betz |
130:770ce14d3d15 | 243 | } |
Wolfgang Betz |
130:770ce14d3d15 | 244 | |
Wolfgang Betz |
130:770ce14d3d15 | 245 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 246 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 247 | @brief Reads the value of a characteristic, based on the service |
Wolfgang Betz |
130:770ce14d3d15 | 248 | and characteristic index fields |
Wolfgang Betz |
130:770ce14d3d15 | 249 | |
Wolfgang Betz |
130:770ce14d3d15 | 250 | @param[in] charHandle |
Wolfgang Betz |
130:770ce14d3d15 | 251 | The handle of the GattCharacteristic to read from |
Wolfgang Betz |
130:770ce14d3d15 | 252 | @param[in] buffer |
Wolfgang Betz |
130:770ce14d3d15 | 253 | Buffer to hold the the characteristic's value |
Wolfgang Betz |
130:770ce14d3d15 | 254 | (raw byte array in LSB format) |
Wolfgang Betz |
130:770ce14d3d15 | 255 | @param[in] lengthP |
Wolfgang Betz |
130:770ce14d3d15 | 256 | The number of bytes read into the buffer |
Wolfgang Betz |
130:770ce14d3d15 | 257 | |
Wolfgang Betz |
130:770ce14d3d15 | 258 | @returns ble_error_t |
Wolfgang Betz |
130:770ce14d3d15 | 259 | |
Wolfgang Betz |
130:770ce14d3d15 | 260 | @retval BLE_ERROR_NONE |
Wolfgang Betz |
130:770ce14d3d15 | 261 | Everything executed properly |
Wolfgang Betz |
130:770ce14d3d15 | 262 | |
Wolfgang Betz |
130:770ce14d3d15 | 263 | @section EXAMPLE |
Wolfgang Betz |
130:770ce14d3d15 | 264 | |
Wolfgang Betz |
130:770ce14d3d15 | 265 | @code |
Wolfgang Betz |
130:770ce14d3d15 | 266 | |
Wolfgang Betz |
130:770ce14d3d15 | 267 | @endcode |
Wolfgang Betz |
130:770ce14d3d15 | 268 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 269 | /**************************************************************************/ |
Andrea Palmieri |
229:9981f62cdb1a | 270 | ble_error_t BlueNRGGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) |
Wolfgang Betz |
130:770ce14d3d15 | 271 | { |
Andrea Palmieri |
204:6a6d2f041905 | 272 | tBleStatus ret; |
Andrea Palmieri |
229:9981f62cdb1a | 273 | uint16_t charHandle = attributeHandle-BlueNRGGattServer::CHAR_VALUE_HANDLE; |
Andrea Palmieri |
204:6a6d2f041905 | 274 | |
Andrea Palmieri |
229:9981f62cdb1a | 275 | ret = aci_gatt_read_handle_value(charHandle, *lengthP, lengthP, buffer); |
Andrea Palmieri |
142:adf1567d3900 | 276 | |
Andrea Palmieri |
204:6a6d2f041905 | 277 | if(ret == BLE_STATUS_SUCCESS) { |
Andrea Palmieri |
204:6a6d2f041905 | 278 | return BLE_ERROR_NONE; |
Andrea Palmieri |
204:6a6d2f041905 | 279 | } |
Andrea Palmieri |
204:6a6d2f041905 | 280 | switch (ret) { |
Andrea Palmieri |
204:6a6d2f041905 | 281 | case ERR_INVALID_HCI_CMD_PARAMS: |
Andrea Palmieri |
204:6a6d2f041905 | 282 | return BLE_ERROR_INVALID_PARAM; |
Andrea Palmieri |
204:6a6d2f041905 | 283 | default: |
Andrea Palmieri |
204:6a6d2f041905 | 284 | return BLE_ERROR_UNSPECIFIED; |
Andrea Palmieri |
204:6a6d2f041905 | 285 | } |
Wolfgang Betz |
130:770ce14d3d15 | 286 | } |
Wolfgang Betz |
130:770ce14d3d15 | 287 | |
Wolfgang Betz |
130:770ce14d3d15 | 288 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 289 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 290 | @brief Updates the value of a characteristic, based on the service |
Wolfgang Betz |
130:770ce14d3d15 | 291 | and characteristic index fields |
Wolfgang Betz |
130:770ce14d3d15 | 292 | |
Wolfgang Betz |
130:770ce14d3d15 | 293 | @param[in] charHandle |
Wolfgang Betz |
130:770ce14d3d15 | 294 | The handle of the GattCharacteristic to write to |
Wolfgang Betz |
130:770ce14d3d15 | 295 | @param[in] buffer |
Wolfgang Betz |
130:770ce14d3d15 | 296 | Data to use when updating the characteristic's value |
Wolfgang Betz |
130:770ce14d3d15 | 297 | (raw byte array in LSB format) |
Wolfgang Betz |
130:770ce14d3d15 | 298 | @param[in] len |
Wolfgang Betz |
130:770ce14d3d15 | 299 | The number of bytes in buffer |
Wolfgang Betz |
130:770ce14d3d15 | 300 | |
Wolfgang Betz |
130:770ce14d3d15 | 301 | @returns ble_error_t |
Wolfgang Betz |
130:770ce14d3d15 | 302 | |
Wolfgang Betz |
130:770ce14d3d15 | 303 | @retval BLE_ERROR_NONE |
Wolfgang Betz |
130:770ce14d3d15 | 304 | Everything executed properly |
Wolfgang Betz |
130:770ce14d3d15 | 305 | |
Wolfgang Betz |
130:770ce14d3d15 | 306 | @section EXAMPLE |
Wolfgang Betz |
130:770ce14d3d15 | 307 | |
Wolfgang Betz |
130:770ce14d3d15 | 308 | @code |
Wolfgang Betz |
130:770ce14d3d15 | 309 | |
Wolfgang Betz |
130:770ce14d3d15 | 310 | @endcode |
Wolfgang Betz |
130:770ce14d3d15 | 311 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 312 | /**************************************************************************/ |
Andrea Palmieri |
229:9981f62cdb1a | 313 | ble_error_t BlueNRGGattServer::read(Gap::Handle_t connectionHandle, |
Andrea Palmieri |
229:9981f62cdb1a | 314 | GattAttribute::Handle_t attributeHandle, |
Andrea Palmieri |
229:9981f62cdb1a | 315 | uint8_t buffer[], |
Andrea Palmieri |
229:9981f62cdb1a | 316 | uint16_t *lengthP) { |
Andrea Palmieri |
142:adf1567d3900 | 317 | |
Andrea Palmieri |
142:adf1567d3900 | 318 | /* avoid compiler warnings about unused variables */ |
Andrea Palmieri |
142:adf1567d3900 | 319 | (void)connectionHandle; |
Andrea Palmieri |
142:adf1567d3900 | 320 | (void)attributeHandle; |
Andrea Palmieri |
142:adf1567d3900 | 321 | (void)buffer; |
Andrea Palmieri |
142:adf1567d3900 | 322 | (void)lengthP; |
Andrea Palmieri |
142:adf1567d3900 | 323 | |
Andrea Palmieri |
142:adf1567d3900 | 324 | return BLE_ERROR_NONE; |
Wolfgang Betz |
130:770ce14d3d15 | 325 | } |
Wolfgang Betz |
130:770ce14d3d15 | 326 | |
Andrea Palmieri |
229:9981f62cdb1a | 327 | ble_error_t BlueNRGGattServer::write(Gap::Handle_t connectionHandle, |
Andrea Palmieri |
229:9981f62cdb1a | 328 | GattAttribute::Handle_t, |
Andrea Palmieri |
229:9981f62cdb1a | 329 | const uint8_t[], |
Andrea Palmieri |
229:9981f62cdb1a | 330 | uint16_t, bool localOnly) { |
Andrea Palmieri |
142:adf1567d3900 | 331 | /* avoid compiler warnings about unused variables */ |
Andrea Palmieri |
142:adf1567d3900 | 332 | (void)connectionHandle; |
Andrea Palmieri |
142:adf1567d3900 | 333 | (void)localOnly; |
Andrea Palmieri |
142:adf1567d3900 | 334 | |
Andrea Palmieri |
142:adf1567d3900 | 335 | return BLE_ERROR_NONE; |
Wolfgang Betz |
130:770ce14d3d15 | 336 | } |
Wolfgang Betz |
130:770ce14d3d15 | 337 | |
Andrea Palmieri |
229:9981f62cdb1a | 338 | ble_error_t BlueNRGGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly) |
Wolfgang Betz |
130:770ce14d3d15 | 339 | { |
Andrea Palmieri |
142:adf1567d3900 | 340 | /* avoid compiler warnings about unused variables */ |
Andrea Palmieri |
142:adf1567d3900 | 341 | (void)localOnly; |
Andrea Palmieri |
142:adf1567d3900 | 342 | |
Andrea Palmieri |
142:adf1567d3900 | 343 | tBleStatus ret; |
Andrea Palmieri |
229:9981f62cdb1a | 344 | |
Andrea Palmieri |
229:9981f62cdb1a | 345 | uint16_t charHandle = attributeHandle-BlueNRGGattServer::CHAR_VALUE_HANDLE; |
Wolfgang Betz |
130:770ce14d3d15 | 346 | |
Andrea Palmieri |
229:9981f62cdb1a | 347 | PRINTF("updating bleCharacteristic valueHandle=%u,\ |
Andrea Palmieri |
229:9981f62cdb1a | 348 | corresponding serviceHandle=%u len=%d\n\r", |
Andrea Palmieri |
229:9981f62cdb1a | 349 | attributeHandle, bleCharHandleMap.find(charHandle)->second, len); |
Andrea Palmieri |
229:9981f62cdb1a | 350 | |
Andrea Palmieri |
229:9981f62cdb1a | 351 | ret = aci_gatt_update_char_value(bleCharHandleMap.find(charHandle)->second, charHandle, 0, len, buffer); |
Wolfgang Betz |
130:770ce14d3d15 | 352 | |
Wolfgang Betz |
130:770ce14d3d15 | 353 | if (ret != BLE_STATUS_SUCCESS){ |
Andrea Palmieri |
207:b9df918d6d5a | 354 | PRINTF("Error while updating characteristic (ret=0x%x).\n\r", ret); |
Andrea Palmieri |
207:b9df918d6d5a | 355 | switch (ret) { |
Andrea Palmieri |
207:b9df918d6d5a | 356 | case BLE_STATUS_INVALID_HANDLE: |
Andrea Palmieri |
207:b9df918d6d5a | 357 | case BLE_STATUS_INVALID_PARAMETER: |
Andrea Palmieri |
207:b9df918d6d5a | 358 | return BLE_ERROR_INVALID_PARAM; |
Andrea Palmieri |
207:b9df918d6d5a | 359 | default: |
Andrea Palmieri |
207:b9df918d6d5a | 360 | return BLE_STACK_BUSY; |
Andrea Palmieri |
207:b9df918d6d5a | 361 | } |
Wolfgang Betz |
130:770ce14d3d15 | 362 | } |
Wolfgang Betz |
130:770ce14d3d15 | 363 | |
Wolfgang Betz |
130:770ce14d3d15 | 364 | //Generate Data Sent Event Here? (GattServerEvents::GATT_EVENT_DATA_SENT) //FIXME: Is this correct? |
Wolfgang Betz |
130:770ce14d3d15 | 365 | //Check if characteristic property is NOTIFY|INDICATE, if yes generate event |
Wolfgang Betz |
130:770ce14d3d15 | 366 | GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(charHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 367 | if(p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
Wolfgang Betz |
130:770ce14d3d15 | 368 | | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) { |
Wolfgang Betz |
132:51056160fa4a | 369 | PRINTF("Generate event after updating\n\r"); |
Wolfgang Betz |
130:770ce14d3d15 | 370 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_SENT, charHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 371 | } |
Wolfgang Betz |
130:770ce14d3d15 | 372 | |
Wolfgang Betz |
130:770ce14d3d15 | 373 | return BLE_ERROR_NONE; |
Wolfgang Betz |
130:770ce14d3d15 | 374 | } |
Wolfgang Betz |
130:770ce14d3d15 | 375 | |
Wolfgang Betz |
130:770ce14d3d15 | 376 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 377 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 378 | @brief Reads a value according to the handle provided |
Wolfgang Betz |
130:770ce14d3d15 | 379 | |
Andrea Palmieri |
229:9981f62cdb1a | 380 | @param[in] attributeHandle |
Andrea Palmieri |
229:9981f62cdb1a | 381 | The handle of the attribute to read from |
Wolfgang Betz |
130:770ce14d3d15 | 382 | |
Wolfgang Betz |
130:770ce14d3d15 | 383 | @returns ble_error_t |
Wolfgang Betz |
130:770ce14d3d15 | 384 | |
Wolfgang Betz |
130:770ce14d3d15 | 385 | @retval BLE_ERROR_NONE |
Wolfgang Betz |
130:770ce14d3d15 | 386 | Everything executed properly |
Wolfgang Betz |
130:770ce14d3d15 | 387 | |
Wolfgang Betz |
130:770ce14d3d15 | 388 | @section EXAMPLE |
Wolfgang Betz |
130:770ce14d3d15 | 389 | |
Wolfgang Betz |
130:770ce14d3d15 | 390 | @code |
Wolfgang Betz |
130:770ce14d3d15 | 391 | |
Wolfgang Betz |
130:770ce14d3d15 | 392 | @endcode |
Wolfgang Betz |
130:770ce14d3d15 | 393 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 394 | /**************************************************************************/ |
Andrea Palmieri |
229:9981f62cdb1a | 395 | ble_error_t BlueNRGGattServer::Read_Request_CB(uint16_t attributeHandle) |
Wolfgang Betz |
130:770ce14d3d15 | 396 | { |
Wolfgang Betz |
130:770ce14d3d15 | 397 | uint16_t gapConnectionHandle = BlueNRGGap::getInstance().getConnectionHandle(); |
Wolfgang Betz |
130:770ce14d3d15 | 398 | |
Wolfgang Betz |
130:770ce14d3d15 | 399 | GattReadCallbackParams readParams; |
Andrea Palmieri |
229:9981f62cdb1a | 400 | readParams.handle = attributeHandle; |
Wolfgang Betz |
130:770ce14d3d15 | 401 | |
Andrea Palmieri |
229:9981f62cdb1a | 402 | //PRINTF("readParams.handle = %d\n\r", readParams.handle); |
Wolfgang Betz |
130:770ce14d3d15 | 403 | HCIDataReadEvent(&readParams); |
Wolfgang Betz |
130:770ce14d3d15 | 404 | |
Wolfgang Betz |
130:770ce14d3d15 | 405 | //EXIT: |
Wolfgang Betz |
130:770ce14d3d15 | 406 | if(gapConnectionHandle != 0){ |
Wolfgang Betz |
132:51056160fa4a | 407 | //PRINTF("Calling aci_gatt_allow_read\n\r"); |
Wolfgang Betz |
130:770ce14d3d15 | 408 | aci_gatt_allow_read(gapConnectionHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 409 | } |
Wolfgang Betz |
130:770ce14d3d15 | 410 | |
Wolfgang Betz |
130:770ce14d3d15 | 411 | return BLE_ERROR_NONE; |
Wolfgang Betz |
130:770ce14d3d15 | 412 | } |
Wolfgang Betz |
130:770ce14d3d15 | 413 | |
Wolfgang Betz |
130:770ce14d3d15 | 414 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 415 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 416 | @brief Returns the GattCharacteristic according to the handle provided |
Wolfgang Betz |
130:770ce14d3d15 | 417 | |
Andrea Palmieri |
229:9981f62cdb1a | 418 | @param[in] attrHandle |
Andrea Palmieri |
229:9981f62cdb1a | 419 | The handle of the attribute |
Wolfgang Betz |
130:770ce14d3d15 | 420 | |
Wolfgang Betz |
130:770ce14d3d15 | 421 | @returns ble_error_t |
Wolfgang Betz |
130:770ce14d3d15 | 422 | |
Wolfgang Betz |
130:770ce14d3d15 | 423 | @retval BLE_ERROR_NONE |
Wolfgang Betz |
130:770ce14d3d15 | 424 | Everything executed properly |
Wolfgang Betz |
130:770ce14d3d15 | 425 | |
Wolfgang Betz |
130:770ce14d3d15 | 426 | @section EXAMPLE |
Wolfgang Betz |
130:770ce14d3d15 | 427 | |
Wolfgang Betz |
130:770ce14d3d15 | 428 | @code |
Wolfgang Betz |
130:770ce14d3d15 | 429 | |
Wolfgang Betz |
130:770ce14d3d15 | 430 | @endcode |
Wolfgang Betz |
130:770ce14d3d15 | 431 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 432 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 433 | GattCharacteristic* BlueNRGGattServer::getCharacteristicFromHandle(uint16_t attrHandle) |
Wolfgang Betz |
130:770ce14d3d15 | 434 | { |
Wolfgang Betz |
130:770ce14d3d15 | 435 | GattCharacteristic *p_char = NULL; |
Wolfgang Betz |
130:770ce14d3d15 | 436 | int i; |
Wolfgang Betz |
130:770ce14d3d15 | 437 | uint16_t handle, handle_1; |
Wolfgang Betz |
130:770ce14d3d15 | 438 | |
Andrea Palmieri |
229:9981f62cdb1a | 439 | PRINTF("BlueNRGGattServer::getCharacteristicFromHandle()>>Attr Handle received %d\n\r",attrHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 440 | for(i=0; i<characteristicCount; i++) |
Wolfgang Betz |
130:770ce14d3d15 | 441 | { |
Andrea Palmieri |
229:9981f62cdb1a | 442 | handle = p_characteristics[i]->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE; |
Wolfgang Betz |
132:51056160fa4a | 443 | PRINTF("handle(%d)=%d\n\r", i, handle); |
Wolfgang Betz |
130:770ce14d3d15 | 444 | if(i==characteristicCount-1)//Last Characteristic check |
Wolfgang Betz |
130:770ce14d3d15 | 445 | { |
Wolfgang Betz |
130:770ce14d3d15 | 446 | if(attrHandle>=handle) |
Wolfgang Betz |
130:770ce14d3d15 | 447 | { |
Wolfgang Betz |
130:770ce14d3d15 | 448 | p_char = p_characteristics[i]; |
Wolfgang Betz |
132:51056160fa4a | 449 | PRINTF("Found Characteristic Properties 0x%x (handle=%d)\n\r",p_char->getProperties(), handle); |
Wolfgang Betz |
130:770ce14d3d15 | 450 | break; |
Wolfgang Betz |
130:770ce14d3d15 | 451 | } |
Wolfgang Betz |
130:770ce14d3d15 | 452 | } |
Wolfgang Betz |
130:770ce14d3d15 | 453 | else { |
Andrea Palmieri |
229:9981f62cdb1a | 454 | handle_1 = p_characteristics[i+1]->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE; |
Wolfgang Betz |
130:770ce14d3d15 | 455 | //Testing if attribute handle is between two Characteristic Handles |
Wolfgang Betz |
130:770ce14d3d15 | 456 | if(attrHandle>=handle && attrHandle<handle_1) |
Wolfgang Betz |
130:770ce14d3d15 | 457 | { |
Wolfgang Betz |
130:770ce14d3d15 | 458 | p_char = p_characteristics[i]; |
Wolfgang Betz |
132:51056160fa4a | 459 | PRINTF("Found Characteristic Properties 0x%x (handle=%d handle_1=%d)\n\r",p_char->getProperties(), handle, handle_1); |
Wolfgang Betz |
130:770ce14d3d15 | 460 | break; |
Wolfgang Betz |
130:770ce14d3d15 | 461 | } else continue; |
Wolfgang Betz |
130:770ce14d3d15 | 462 | } |
Wolfgang Betz |
130:770ce14d3d15 | 463 | } |
Wolfgang Betz |
130:770ce14d3d15 | 464 | |
Wolfgang Betz |
130:770ce14d3d15 | 465 | return p_char; |
Wolfgang Betz |
130:770ce14d3d15 | 466 | } |
Wolfgang Betz |
130:770ce14d3d15 | 467 | |
Wolfgang Betz |
130:770ce14d3d15 | 468 | void BlueNRGGattServer::HCIDataWrittenEvent(const GattWriteCallbackParams *params) { |
Wolfgang Betz |
130:770ce14d3d15 | 469 | this->handleDataWrittenEvent(params); |
Wolfgang Betz |
130:770ce14d3d15 | 470 | } |
Wolfgang Betz |
130:770ce14d3d15 | 471 | |
Wolfgang Betz |
130:770ce14d3d15 | 472 | void BlueNRGGattServer::HCIDataReadEvent(const GattReadCallbackParams *params) { |
Wolfgang Betz |
132:51056160fa4a | 473 | PRINTF("Called HCIDataReadEvent\n\r"); |
Wolfgang Betz |
130:770ce14d3d15 | 474 | this->handleDataReadEvent(params); |
Wolfgang Betz |
130:770ce14d3d15 | 475 | } |
Wolfgang Betz |
130:770ce14d3d15 | 476 | |
Wolfgang Betz |
130:770ce14d3d15 | 477 | void BlueNRGGattServer::HCIEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) { |
Wolfgang Betz |
130:770ce14d3d15 | 478 | this->handleEvent(type, charHandle); |
Wolfgang Betz |
130:770ce14d3d15 | 479 | } |
Wolfgang Betz |
130:770ce14d3d15 | 480 | |
Wolfgang Betz |
130:770ce14d3d15 | 481 | void BlueNRGGattServer::HCIDataSentEvent(unsigned count) { |
Wolfgang Betz |
130:770ce14d3d15 | 482 | this->handleDataSentEvent(count); |
Wolfgang Betz |
130:770ce14d3d15 | 483 | } |
Wolfgang Betz |
130:770ce14d3d15 | 484 | |
Wolfgang Betz |
130:770ce14d3d15 | 485 | |
Wolfgang Betz |
130:770ce14d3d15 | 486 | ble_error_t BlueNRGGattServer::initializeGATTDatabase(void) { |
Wolfgang Betz |
130:770ce14d3d15 | 487 | // <TODO> |
Wolfgang Betz |
130:770ce14d3d15 | 488 | return (ble_error_t)0; |
Wolfgang Betz |
130:770ce14d3d15 | 489 | } |
Andrea Palmieri |
229:9981f62cdb1a | 490 | |
Andrea Palmieri |
229:9981f62cdb1a | 491 | /**************************************************************************/ |
Andrea Palmieri |
229:9981f62cdb1a | 492 | /*! |
Andrea Palmieri |
229:9981f62cdb1a | 493 | @brief Clear BlueNRGGattServer's state. |
Andrea Palmieri |
229:9981f62cdb1a | 494 | |
Andrea Palmieri |
229:9981f62cdb1a | 495 | @returns ble_error_t |
Andrea Palmieri |
229:9981f62cdb1a | 496 | |
Andrea Palmieri |
229:9981f62cdb1a | 497 | @retval BLE_ERROR_NONE |
Andrea Palmieri |
229:9981f62cdb1a | 498 | Everything executed properly |
Andrea Palmieri |
229:9981f62cdb1a | 499 | */ |
Andrea Palmieri |
229:9981f62cdb1a | 500 | /**************************************************************************/ |
Andrea Palmieri |
229:9981f62cdb1a | 501 | ble_error_t BlueNRGGattServer::reset(void) |
Andrea Palmieri |
229:9981f62cdb1a | 502 | { |
Andrea Palmieri |
229:9981f62cdb1a | 503 | /* Clear all state that is from the parent, including private members */ |
Andrea Palmieri |
229:9981f62cdb1a | 504 | if (GattServer::reset() != BLE_ERROR_NONE) { |
Andrea Palmieri |
229:9981f62cdb1a | 505 | return BLE_ERROR_INVALID_STATE; |
Andrea Palmieri |
229:9981f62cdb1a | 506 | } |
Andrea Palmieri |
229:9981f62cdb1a | 507 | |
Andrea Palmieri |
229:9981f62cdb1a | 508 | /* Clear class members */ |
Andrea Palmieri |
229:9981f62cdb1a | 509 | memset(p_characteristics, 0, sizeof(p_characteristics)); |
Andrea Palmieri |
229:9981f62cdb1a | 510 | memset(bleCharacteristicHandles, 0, sizeof(bleCharacteristicHandles)); |
Andrea Palmieri |
229:9981f62cdb1a | 511 | serviceCount = 0; |
Andrea Palmieri |
229:9981f62cdb1a | 512 | characteristicCount = 0; |
Andrea Palmieri |
229:9981f62cdb1a | 513 | |
Andrea Palmieri |
229:9981f62cdb1a | 514 | return BLE_ERROR_NONE; |
Andrea Palmieri |
229:9981f62cdb1a | 515 | } |