bluetooth control motor

Dependents:   BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Vincent Coubard
Date:
Thu Sep 15 10:51:36 2016 +0100
Branch:
dc54644b61c51990e49672e5bbce3b95124d6364
Revision:
273:00205952d841
Parent:
264:1e754a01869e
Parent:
272:4639da7705e1
Child:
293:5a1f577bf92f
Sync with dc54644b61c51990e49672e5bbce3b95124d6364

Merge 83c30f290087a6f5a503812f507492e725a3b717 into e9fb3e390284c3f7ef8e1d21cc55deef7558ca3d
2016-07-20 08:50:37+01:00: Vincent Coubard
Merge branch 'workshop-july' into rtos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 132:51056160fa4a 1 /* mbed Microcontroller Library
Wolfgang Betz 132:51056160fa4a 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 132:51056160fa4a 3 *
Wolfgang Betz 132:51056160fa4a 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 132:51056160fa4a 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 132:51056160fa4a 6 * You may obtain a copy of the License at
Wolfgang Betz 132:51056160fa4a 7 *
Wolfgang Betz 132:51056160fa4a 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 132:51056160fa4a 9 *
Wolfgang Betz 132:51056160fa4a 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 132:51056160fa4a 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 132:51056160fa4a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 132:51056160fa4a 13 * See the License for the specific language governing permissions and
Wolfgang Betz 132:51056160fa4a 14 * limitations under the License.
Wolfgang Betz 132:51056160fa4a 15 */
Wolfgang Betz 132:51056160fa4a 16
Wolfgang Betz 132:51056160fa4a 17
Wolfgang Betz 132:51056160fa4a 18 /**
Wolfgang Betz 132:51056160fa4a 19 ******************************************************************************
Vincent Coubard 256:146bb175ce80 20 * @file btle.cpp
Wolfgang Betz 132:51056160fa4a 21 * @author STMicroelectronics
Wolfgang Betz 132:51056160fa4a 22 * @brief Implementation BlueNRG Init and helper functions.
Wolfgang Betz 132:51056160fa4a 23 ******************************************************************************
Wolfgang Betz 132:51056160fa4a 24 * @copy
Wolfgang Betz 132:51056160fa4a 25 *
Wolfgang Betz 132:51056160fa4a 26 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 132:51056160fa4a 27 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 132:51056160fa4a 28 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 132:51056160fa4a 29 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 132:51056160fa4a 30 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 132:51056160fa4a 31 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 132:51056160fa4a 32 *
Wolfgang Betz 132:51056160fa4a 33 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Vincent Coubard 256:146bb175ce80 34 */
Wolfgang Betz 132:51056160fa4a 35
Wolfgang Betz 132:51056160fa4a 36
Wolfgang Betz 132:51056160fa4a 37 #include "btle.h"
Wolfgang Betz 132:51056160fa4a 38 #include "ble/Gap.h"
Wolfgang Betz 132:51056160fa4a 39 #include "ble/GapEvents.h"
Wolfgang Betz 132:51056160fa4a 40 #include "BlueNRGGap.h"
Wolfgang Betz 132:51056160fa4a 41 #include "BlueNRGGattServer.h"
Wolfgang Betz 132:51056160fa4a 42 #include "BlueNRGGattClient.h"
Wolfgang Betz 132:51056160fa4a 43 #include "Utils.h"
Wolfgang Betz 132:51056160fa4a 44
Andrea Palmieri 241:c13c2e31316d 45 #include "x_nucleo_idb0xa1_targets.h"
Andrea Palmieri 241:c13c2e31316d 46
Wolfgang Betz 132:51056160fa4a 47 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 48 extern "C" {
Wolfgang Betz 132:51056160fa4a 49 #endif
Wolfgang Betz 132:51056160fa4a 50
Wolfgang Betz 132:51056160fa4a 51
Wolfgang Betz 132:51056160fa4a 52 /* C File Includes ------------------------------------------------------------------*/
Wolfgang Betz 132:51056160fa4a 53 #include <stdio.h>
Wolfgang Betz 132:51056160fa4a 54 #include <string.h>
Wolfgang Betz 132:51056160fa4a 55 #include "hci.h"
Wolfgang Betz 132:51056160fa4a 56 #include "hci_const.h"
Wolfgang Betz 132:51056160fa4a 57 #include "bluenrg_aci.h"
Wolfgang Betz 132:51056160fa4a 58 #include "bluenrg_hal_aci.h"
Wolfgang Betz 132:51056160fa4a 59 #include "bluenrg_gap.h"
Wolfgang Betz 132:51056160fa4a 60 #include "bluenrg_utils.h"
Wolfgang Betz 132:51056160fa4a 61
Wolfgang Betz 132:51056160fa4a 62 #include "hal_types.h"
Wolfgang Betz 132:51056160fa4a 63 #include "hal.h"
Wolfgang Betz 132:51056160fa4a 64 #include "gp_timer.h"
Wolfgang Betz 132:51056160fa4a 65 #include "osal.h"
Wolfgang Betz 132:51056160fa4a 66 #include "sm.h"
Wolfgang Betz 132:51056160fa4a 67 #include "debug.h"
Wolfgang Betz 132:51056160fa4a 68
Wolfgang Betz 132:51056160fa4a 69 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 70 }
Wolfgang Betz 132:51056160fa4a 71 #endif
Wolfgang Betz 132:51056160fa4a 72
Wolfgang Betz 132:51056160fa4a 73 #define IDB04A1 0
Wolfgang Betz 132:51056160fa4a 74 #define IDB05A1 1
Wolfgang Betz 132:51056160fa4a 75
Andrea Palmieri 241:c13c2e31316d 76 /* See file 'x_nucleo_idb0xa1_targets.h' for details regarding the IDB0XA1 STACK_MODE */
Andrea Palmieri 241:c13c2e31316d 77 #define STACK_MODE IDB0XA1_STACK_MODE
Andrea Palmieri 220:e02936f0d4c7 78
Wolfgang Betz 132:51056160fa4a 79 void HCI_Input(tHciDataPacket * hciReadPacket);
Wolfgang Betz 132:51056160fa4a 80
Wolfgang Betz 132:51056160fa4a 81 uint16_t g_gap_service_handle = 0;
Wolfgang Betz 132:51056160fa4a 82 uint16_t g_appearance_char_handle = 0;
Wolfgang Betz 132:51056160fa4a 83 uint16_t g_device_name_char_handle = 0;
Vincent Coubard 266:b49e28134d83 84 uint16_t g_preferred_connection_parameters_char_handle = 0;
Wolfgang Betz 132:51056160fa4a 85
Wolfgang Betz 132:51056160fa4a 86 /* Private variables ---------------------------------------------------------*/
Wolfgang Betz 132:51056160fa4a 87 volatile uint8_t set_connectable = 1;
Andrea Palmieri 219:d8e8cd4d4521 88
Andrea Palmieri 219:d8e8cd4d4521 89 static char versionString[32];
Wolfgang Betz 132:51056160fa4a 90 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */
Wolfgang Betz 132:51056160fa4a 91
Wolfgang Betz 132:51056160fa4a 92 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 93 /*!
Antonio Vilei 245:6830f71c197c 94 @brief Init the BTLE stack with the specified role
Wolfgang Betz 132:51056160fa4a 95 @returns void
Wolfgang Betz 132:51056160fa4a 96 */
Wolfgang Betz 132:51056160fa4a 97 /**************************************************************************/
Vincent Coubard 271:7dc6261c33e5 98 void btleInit(void)
Wolfgang Betz 132:51056160fa4a 99 {
Andrea Palmieri 219:d8e8cd4d4521 100 PRINTF("btleInit>>\n\r");
Vincent Coubard 256:146bb175ce80 101
Wolfgang Betz 132:51056160fa4a 102 int ret;
Wolfgang Betz 132:51056160fa4a 103 uint8_t hwVersion;
Wolfgang Betz 132:51056160fa4a 104 uint16_t fwVersion;
Wolfgang Betz 132:51056160fa4a 105 uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
Wolfgang Betz 132:51056160fa4a 106
Wolfgang Betz 132:51056160fa4a 107 /* Reset BlueNRG SPI interface */
Wolfgang Betz 132:51056160fa4a 108 BlueNRG_RST();
Wolfgang Betz 132:51056160fa4a 109
Wolfgang Betz 132:51056160fa4a 110 /* get the BlueNRG HW and FW versions */
Wolfgang Betz 132:51056160fa4a 111 getBlueNRGVersion(&hwVersion, &fwVersion);
Wolfgang Betz 132:51056160fa4a 112
Vincent Coubard 256:146bb175ce80 113 /*
Wolfgang Betz 132:51056160fa4a 114 * Reset BlueNRG again otherwise we won't
Wolfgang Betz 132:51056160fa4a 115 * be able to change its MAC address.
Wolfgang Betz 132:51056160fa4a 116 * aci_hal_write_config_data() must be the first
Wolfgang Betz 132:51056160fa4a 117 * command after reset otherwise it will fail.
Wolfgang Betz 132:51056160fa4a 118 */
Wolfgang Betz 132:51056160fa4a 119 BlueNRG_RST();
Wolfgang Betz 132:51056160fa4a 120
Wolfgang Betz 132:51056160fa4a 121 if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */
Wolfgang Betz 132:51056160fa4a 122 bnrg_expansion_board = IDB05A1;
Wolfgang Betz 132:51056160fa4a 123 }
Wolfgang Betz 132:51056160fa4a 124
Andrea Palmieri 219:d8e8cd4d4521 125 /* set BLE version string */
Andrea Palmieri 219:d8e8cd4d4521 126 setVersionString(hwVersion, fwVersion);
Andrea Palmieri 219:d8e8cd4d4521 127
Andrea Palmieri 220:e02936f0d4c7 128 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 220:e02936f0d4c7 129 uint8_t stackMode = STACK_MODE;
Andrea Palmieri 220:e02936f0d4c7 130 ret = aci_hal_write_config_data(CONFIG_DATA_ROLE,
Andrea Palmieri 220:e02936f0d4c7 131 CONFIG_DATA_ROLE_LEN,
Andrea Palmieri 220:e02936f0d4c7 132 &stackMode);
Andrea Palmieri 220:e02936f0d4c7 133 }
Andrea Palmieri 220:e02936f0d4c7 134
Wolfgang Betz 132:51056160fa4a 135 ret = aci_gatt_init();
Vincent Coubard 253:9665a6f8bbdb 136 if(ret != BLE_STATUS_SUCCESS){
Wolfgang Betz 132:51056160fa4a 137 PRINTF("GATT_Init failed.\n");
Wolfgang Betz 132:51056160fa4a 138 }
Wolfgang Betz 132:51056160fa4a 139 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 229:9981f62cdb1a 140 ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1|GAP_OBSERVER_ROLE_IDB05A1,
Andrea Palmieri 229:9981f62cdb1a 141 0,
Andrea Palmieri 229:9981f62cdb1a 142 0x18,
Andrea Palmieri 229:9981f62cdb1a 143 &service_handle,
Andrea Palmieri 229:9981f62cdb1a 144 &dev_name_char_handle,
Andrea Palmieri 229:9981f62cdb1a 145 &appearance_char_handle);
Wolfgang Betz 132:51056160fa4a 146 } else {
Vincent Coubard 271:7dc6261c33e5 147 // IDB04A1 is configured as peripheral by default
Vincent Coubard 271:7dc6261c33e5 148 ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle);
Wolfgang Betz 132:51056160fa4a 149 }
Vincent Coubard 256:146bb175ce80 150
Vincent Coubard 268:c0a1e03c5736 151 // read the default static address and inject it into the GAP object
Vincent Coubard 268:c0a1e03c5736 152 {
Vincent Coubard 268:c0a1e03c5736 153 Gap::Address_t BLE_address_BE = { 0 };
Vincent Coubard 268:c0a1e03c5736 154 uint8_t data_len_out;
Vincent Coubard 268:c0a1e03c5736 155 aci_hal_read_config_data(CONFIG_DATA_RANDOM_ADDRESS_IDB05A1, BDADDR_SIZE, &data_len_out, BLE_address_BE);
Vincent Coubard 268:c0a1e03c5736 156 // FIXME error handling of this function
Vincent Coubard 268:c0a1e03c5736 157 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE);
Vincent Coubard 268:c0a1e03c5736 158 }
Vincent Coubard 268:c0a1e03c5736 159
Wolfgang Betz 132:51056160fa4a 160 if(ret != BLE_STATUS_SUCCESS){
Wolfgang Betz 132:51056160fa4a 161 PRINTF("GAP_Init failed.\n");
Wolfgang Betz 132:51056160fa4a 162 }
Wolfgang Betz 132:51056160fa4a 163
Andrea Palmieri 229:9981f62cdb1a 164 //FIXME: Security and passkey set by default
Wolfgang Betz 132:51056160fa4a 165 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED,
Wolfgang Betz 132:51056160fa4a 166 OOB_AUTH_DATA_ABSENT,
Wolfgang Betz 132:51056160fa4a 167 NULL,
Wolfgang Betz 132:51056160fa4a 168 7,
Wolfgang Betz 132:51056160fa4a 169 16,
Wolfgang Betz 132:51056160fa4a 170 USE_FIXED_PIN_FOR_PAIRING,
Wolfgang Betz 132:51056160fa4a 171 123456,
Wolfgang Betz 132:51056160fa4a 172 BONDING);
Vincent Coubard 253:9665a6f8bbdb 173 if (ret != BLE_STATUS_SUCCESS) {
Vincent Coubard 253:9665a6f8bbdb 174 PRINTF("Auth Req set failed.\n");
Wolfgang Betz 132:51056160fa4a 175 }
Vincent Coubard 256:146bb175ce80 176
Wolfgang Betz 132:51056160fa4a 177 aci_hal_set_tx_power_level(1,4);
Vincent Coubard 256:146bb175ce80 178
Wolfgang Betz 132:51056160fa4a 179 g_gap_service_handle = service_handle;
Wolfgang Betz 132:51056160fa4a 180 g_appearance_char_handle = appearance_char_handle;
Vincent Coubard 256:146bb175ce80 181 g_device_name_char_handle = dev_name_char_handle;
Vincent Coubard 256:146bb175ce80 182 //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API
Wolfgang Betz 132:51056160fa4a 183 /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0,
Wolfgang Betz 132:51056160fa4a 184 strlen(name), (tHalUint8 *)name);*/
Wolfgang Betz 132:51056160fa4a 185
Vincent Coubard 264:1e754a01869e 186 signalEventsToProcess();
Vincent Coubard 266:b49e28134d83 187 // update the peripheral preferred conenction parameters handle
Vincent Coubard 266:b49e28134d83 188 // This value is hardcoded at the moment.
Vincent Coubard 271:7dc6261c33e5 189 g_preferred_connection_parameters_char_handle = 10;
Vincent Coubard 266:b49e28134d83 190
Wolfgang Betz 132:51056160fa4a 191 return;
Wolfgang Betz 132:51056160fa4a 192 }
Wolfgang Betz 132:51056160fa4a 193
Wolfgang Betz 132:51056160fa4a 194 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 195 /*!
Andrea Palmieri 229:9981f62cdb1a 196 @brief mbedOS
Wolfgang Betz 132:51056160fa4a 197
Wolfgang Betz 132:51056160fa4a 198 @param[in] void
Vincent Coubard 256:146bb175ce80 199
Wolfgang Betz 132:51056160fa4a 200 @returns
Wolfgang Betz 132:51056160fa4a 201 */
Wolfgang Betz 132:51056160fa4a 202 /**************************************************************************/
Wolfgang Betz 134:d2f8d5898d04 203 int btle_handler_pending = 0;
Wolfgang Betz 134:d2f8d5898d04 204
Wolfgang Betz 133:1bb8df697f7f 205 void btle_handler(void)
Wolfgang Betz 132:51056160fa4a 206 {
Wolfgang Betz 134:d2f8d5898d04 207 btle_handler_pending = 0;
Vincent Coubard 264:1e754a01869e 208 BlueNRGGap::getInstance().Process();
Wolfgang Betz 132:51056160fa4a 209 HCI_Process();
Wolfgang Betz 132:51056160fa4a 210 }
Wolfgang Betz 132:51056160fa4a 211
Andrea Palmieri 219:d8e8cd4d4521 212 /* set BLE Version string */
Andrea Palmieri 219:d8e8cd4d4521 213 void setVersionString(uint8_t hwVersion, uint16_t fwVersion)
Andrea Palmieri 219:d8e8cd4d4521 214 {
Andrea Palmieri 219:d8e8cd4d4521 215 if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 219:d8e8cd4d4521 216 snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u",
Andrea Palmieri 219:d8e8cd4d4521 217 hwVersion>>4, (hwVersion&0x0F),
Andrea Palmieri 219:d8e8cd4d4521 218 fwVersion>>8, (fwVersion&0x00F0)>>4);
Andrea Palmieri 219:d8e8cd4d4521 219 } else {
Andrea Palmieri 219:d8e8cd4d4521 220 snprintf(versionString, sizeof(versionString), "ST (unknown spec)");
Andrea Palmieri 219:d8e8cd4d4521 221 }
Andrea Palmieri 219:d8e8cd4d4521 222 }
Andrea Palmieri 219:d8e8cd4d4521 223
Andrea Palmieri 219:d8e8cd4d4521 224 /* get BLE Version string */
Andrea Palmieri 219:d8e8cd4d4521 225 const char* getVersionString(void)
Andrea Palmieri 219:d8e8cd4d4521 226 {
Andrea Palmieri 219:d8e8cd4d4521 227 return versionString;
Andrea Palmieri 219:d8e8cd4d4521 228 }
Andrea Palmieri 219:d8e8cd4d4521 229
Andrea Palmieri 219:d8e8cd4d4521 230 tBleStatus btleStartRadioScan(uint8_t scan_type,
Andrea Palmieri 219:d8e8cd4d4521 231 uint16_t scan_interval,
Andrea Palmieri 219:d8e8cd4d4521 232 uint16_t scan_window,
Andrea Palmieri 219:d8e8cd4d4521 233 uint8_t own_address_type)
Andrea Palmieri 219:d8e8cd4d4521 234 {
Andrea Palmieri 219:d8e8cd4d4521 235 tBleStatus ret;
Andrea Palmieri 219:d8e8cd4d4521 236
Andrea Palmieri 219:d8e8cd4d4521 237 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
Andrea Palmieri 219:d8e8cd4d4521 238 if(bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 220:e02936f0d4c7 239 PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window);
Andrea Palmieri 231:a0d2544b38cd 240 PRINTF("scan_type=%d own_address_type=%d\n\r", scan_type, own_address_type);
Andrea Palmieri 219:d8e8cd4d4521 241 ret = aci_gap_start_observation_procedure(scan_interval,
Andrea Palmieri 220:e02936f0d4c7 242 scan_window,
Andrea Palmieri 219:d8e8cd4d4521 243 scan_type,
Andrea Palmieri 220:e02936f0d4c7 244 own_address_type,
Andrea Palmieri 235:31b976a40f43 245 0); // 1 to filter duplicates
Andrea Palmieri 219:d8e8cd4d4521 246 } else {
Andrea Palmieri 219:d8e8cd4d4521 247 ret = BLE_STATUS_INVALID_CID;
Andrea Palmieri 219:d8e8cd4d4521 248 }
Andrea Palmieri 219:d8e8cd4d4521 249
Andrea Palmieri 219:d8e8cd4d4521 250 return ret;
Andrea Palmieri 219:d8e8cd4d4521 251
Andrea Palmieri 219:d8e8cd4d4521 252 }
Wolfgang Betz 132:51056160fa4a 253
Wolfgang Betz 132:51056160fa4a 254 /*!
Wolfgang Betz 132:51056160fa4a 255 @brief Not Used
Wolfgang Betz 132:51056160fa4a 256
Wolfgang Betz 132:51056160fa4a 257 @param[in] void
Vincent Coubard 256:146bb175ce80 258
Wolfgang Betz 132:51056160fa4a 259 @returns
Wolfgang Betz 132:51056160fa4a 260 */
Wolfgang Betz 132:51056160fa4a 261 void SPI_Poll(void)
Wolfgang Betz 132:51056160fa4a 262 {
Wolfgang Betz 132:51056160fa4a 263 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN);
Wolfgang Betz 132:51056160fa4a 264 return;
Wolfgang Betz 132:51056160fa4a 265 }
Vincent Coubard 256:146bb175ce80 266
Andrea Palmieri 229:9981f62cdb1a 267 void Attribute_Modified_CB(evt_blue_aci *blue_evt)
Andrea Palmieri 229:9981f62cdb1a 268 {
Andrea Palmieri 229:9981f62cdb1a 269 uint16_t conn_handle;
Andrea Palmieri 229:9981f62cdb1a 270 uint16_t attr_handle;
Andrea Palmieri 229:9981f62cdb1a 271 uint8_t data_length;
Andrea Palmieri 229:9981f62cdb1a 272 uint8_t *att_data;
Andrea Palmieri 229:9981f62cdb1a 273 uint8_t offset;
Andrea Palmieri 229:9981f62cdb1a 274
Andrea Palmieri 229:9981f62cdb1a 275 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 229:9981f62cdb1a 276 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data;
Andrea Palmieri 229:9981f62cdb1a 277 conn_handle = evt->conn_handle;
Andrea Palmieri 229:9981f62cdb1a 278 attr_handle = evt->attr_handle;
Andrea Palmieri 229:9981f62cdb1a 279 data_length = evt->data_length;
Andrea Palmieri 229:9981f62cdb1a 280 att_data = evt->att_data;
Andrea Palmieri 229:9981f62cdb1a 281 offset = evt->offset;
Andrea Palmieri 229:9981f62cdb1a 282 } else {
Andrea Palmieri 229:9981f62cdb1a 283 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data;
Andrea Palmieri 229:9981f62cdb1a 284 conn_handle = evt->conn_handle;
Andrea Palmieri 229:9981f62cdb1a 285 attr_handle = evt->attr_handle;
Andrea Palmieri 229:9981f62cdb1a 286 data_length = evt->data_length;
Andrea Palmieri 229:9981f62cdb1a 287 att_data = evt->att_data;
Andrea Palmieri 229:9981f62cdb1a 288 offset = 0;
Andrea Palmieri 229:9981f62cdb1a 289 }
Andrea Palmieri 229:9981f62cdb1a 290
Wolfgang Betz 132:51056160fa4a 291 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask
Wolfgang Betz 132:51056160fa4a 292 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle);
Wolfgang Betz 132:51056160fa4a 293 if(p_char!=NULL) {
Andrea Palmieri 229:9981f62cdb1a 294 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE;
Wolfgang Betz 132:51056160fa4a 295 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE;
Wolfgang Betz 132:51056160fa4a 296 PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]);
Wolfgang Betz 132:51056160fa4a 297 PRINTF("getProperties 0x%x\n\r",p_char->getProperties());
Andrea Palmieri 229:9981f62cdb1a 298
Andrea Palmieri 229:9981f62cdb1a 299 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_VALUE_HANDLE) {
Wolfgang Betz 132:51056160fa4a 300 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE;
Wolfgang Betz 132:51056160fa4a 301 }
Wolfgang Betz 132:51056160fa4a 302
Andrea Palmieri 229:9981f62cdb1a 303 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_DESC_HANDLE) {
Wolfgang Betz 132:51056160fa4a 304 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE;
Wolfgang Betz 132:51056160fa4a 305 }
Wolfgang Betz 132:51056160fa4a 306 PRINTF("currentHandle %d\n\r", currentHandle);
Vincent Coubard 256:146bb175ce80 307 if((p_char->getProperties() &
Wolfgang Betz 132:51056160fa4a 308 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) &&
Wolfgang Betz 132:51056160fa4a 309 currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) {
Wolfgang Betz 132:51056160fa4a 310
Andrea Palmieri 229:9981f62cdb1a 311 GattAttribute::Handle_t charDescHandle = p_char->getValueAttribute().getHandle()+1;
Andrea Palmieri 229:9981f62cdb1a 312
Wolfgang Betz 132:51056160fa4a 313 PRINTF("*****NOTIFICATION CASE\n\r");
Wolfgang Betz 132:51056160fa4a 314 //Now Check if data written in Enable or Disable
Wolfgang Betz 132:51056160fa4a 315 if((uint16_t)att_data[0]==1) {
Vincent Coubard 256:146bb175ce80 316 //PRINTF("Notify ENABLED\n\r");
Andrea Palmieri 229:9981f62cdb1a 317 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, charDescHandle);
Wolfgang Betz 132:51056160fa4a 318 } else {
Vincent Coubard 256:146bb175ce80 319 //PRINTF("Notify DISABLED\n\r");
Andrea Palmieri 229:9981f62cdb1a 320 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, charDescHandle);
Wolfgang Betz 132:51056160fa4a 321 }
Vincent Coubard 263:8516afb5e29c 322 return;
Wolfgang Betz 132:51056160fa4a 323 }
Vincent Coubard 256:146bb175ce80 324
Andrea Palmieri 229:9981f62cdb1a 325 //Check if attr handle property is WRITEABLE, in the case generate GATT_EVENT_DATA_WRITTEN Event
Wolfgang Betz 132:51056160fa4a 326 if((p_char->getProperties() &
Wolfgang Betz 132:51056160fa4a 327 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) &&
Wolfgang Betz 132:51056160fa4a 328 currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) {
Vincent Coubard 256:146bb175ce80 329
Wolfgang Betz 132:51056160fa4a 330 PRINTF("*****WRITE CASE\n\r");
Vincent Coubard 256:146bb175ce80 331
Wolfgang Betz 132:51056160fa4a 332 GattWriteCallbackParams writeParams;
Andrea Palmieri 229:9981f62cdb1a 333 writeParams.connHandle = conn_handle;
Wolfgang Betz 132:51056160fa4a 334 writeParams.handle = p_char->getValueAttribute().getHandle();
Wolfgang Betz 132:51056160fa4a 335 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG?
Wolfgang Betz 132:51056160fa4a 336 writeParams.len = data_length;
Andrea Palmieri 229:9981f62cdb1a 337 writeParams.data = att_data;
Andrea Palmieri 229:9981f62cdb1a 338 writeParams.offset = offset;
Andrea Palmieri 229:9981f62cdb1a 339
Andrea Palmieri 229:9981f62cdb1a 340 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, attr_handle);
Wolfgang Betz 132:51056160fa4a 341 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data
Andrea Palmieri 202:caf4864292c1 342 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) {
Vincent Coubard 267:cd7870e466b3 343 BlueNRGGattServer::getInstance().write(
Vincent Coubard 267:cd7870e466b3 344 p_char->getValueAttribute().getHandle(),
Vincent Coubard 267:cd7870e466b3 345 (uint8_t*)att_data,
Vincent Coubard 267:cd7870e466b3 346 data_length,
Vincent Coubard 267:cd7870e466b3 347 false
Vincent Coubard 267:cd7870e466b3 348 );
Vincent Coubard 267:cd7870e466b3 349 }
Vincent Coubard 263:8516afb5e29c 350
Vincent Coubard 263:8516afb5e29c 351 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams);
Vincent Coubard 263:8516afb5e29c 352 } else {
Vincent Coubard 263:8516afb5e29c 353 PRINTF("*****WRITE DESCRIPTOR CASE\n\r");
Vincent Coubard 263:8516afb5e29c 354
Vincent Coubard 263:8516afb5e29c 355 GattWriteCallbackParams writeParams;
Vincent Coubard 263:8516afb5e29c 356 writeParams.connHandle = conn_handle;
Vincent Coubard 263:8516afb5e29c 357 writeParams.handle = attr_handle;
Vincent Coubard 263:8516afb5e29c 358 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG?
Vincent Coubard 263:8516afb5e29c 359 writeParams.len = data_length;
Vincent Coubard 263:8516afb5e29c 360 writeParams.data = att_data;
Vincent Coubard 263:8516afb5e29c 361 writeParams.offset = offset;
Vincent Coubard 263:8516afb5e29c 362
Vincent Coubard 263:8516afb5e29c 363 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams);
Vincent Coubard 256:146bb175ce80 364 }
Wolfgang Betz 132:51056160fa4a 365 }
Wolfgang Betz 132:51056160fa4a 366
Wolfgang Betz 132:51056160fa4a 367 }
Wolfgang Betz 132:51056160fa4a 368
Wolfgang Betz 132:51056160fa4a 369 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 370 extern "C" {
Wolfgang Betz 132:51056160fa4a 371 #endif
Wolfgang Betz 132:51056160fa4a 372
Wolfgang Betz 132:51056160fa4a 373 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 374 /*!
Wolfgang Betz 132:51056160fa4a 375 @brief Handle HCI Stack Event
Wolfgang Betz 132:51056160fa4a 376
Wolfgang Betz 132:51056160fa4a 377 @param[in] pckt
Wolfgang Betz 132:51056160fa4a 378 Event Packet sent by the stack to be decoded
Vincent Coubard 256:146bb175ce80 379
Wolfgang Betz 132:51056160fa4a 380 @returns
Wolfgang Betz 132:51056160fa4a 381 */
Wolfgang Betz 132:51056160fa4a 382 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 383 extern void HCI_Event_CB(void *pckt) {
Wolfgang Betz 132:51056160fa4a 384 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt;
Wolfgang Betz 132:51056160fa4a 385 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data;
Vincent Coubard 256:146bb175ce80 386
Wolfgang Betz 132:51056160fa4a 387 if(hci_pckt->type != HCI_EVENT_PKT)
Andrea Palmieri 221:7896e6d8b652 388 return;
Wolfgang Betz 132:51056160fa4a 389
Wolfgang Betz 132:51056160fa4a 390 switch(event_pckt->evt){
Vincent Coubard 256:146bb175ce80 391
Wolfgang Betz 132:51056160fa4a 392 case EVT_DISCONN_COMPLETE:
Wolfgang Betz 132:51056160fa4a 393 {
Wolfgang Betz 132:51056160fa4a 394 PRINTF("EVT_DISCONN_COMPLETE\n");
Vincent Coubard 256:146bb175ce80 395
Andrea Palmieri 221:7896e6d8b652 396 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt->data;
Vincent Coubard 256:146bb175ce80 397
Andrea Palmieri 221:7896e6d8b652 398 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, (Gap::DisconnectionReason_t)evt->reason);
Wolfgang Betz 132:51056160fa4a 399 }
Wolfgang Betz 132:51056160fa4a 400 break;
Vincent Coubard 256:146bb175ce80 401
Wolfgang Betz 132:51056160fa4a 402 case EVT_LE_META_EVENT:
Wolfgang Betz 132:51056160fa4a 403 {
Wolfgang Betz 132:51056160fa4a 404 PRINTF("EVT_LE_META_EVENT\n");
Vincent Coubard 256:146bb175ce80 405
Wolfgang Betz 132:51056160fa4a 406 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data;
Vincent Coubard 256:146bb175ce80 407
Wolfgang Betz 132:51056160fa4a 408 switch(evt->subevent){
Andrea Palmieri 229:9981f62cdb1a 409
Wolfgang Betz 132:51056160fa4a 410 case EVT_LE_CONN_COMPLETE:
Vincent Coubard 256:146bb175ce80 411 {
Wolfgang Betz 132:51056160fa4a 412 PRINTF("EVT_LE_CONN_COMPLETE\n");
Andrea Palmieri 221:7896e6d8b652 413 Gap::Address_t ownAddr;
Andrea Palmieri 221:7896e6d8b652 414 Gap::AddressType_t ownAddrType;
Andrea Palmieri 221:7896e6d8b652 415 BlueNRGGap::getInstance().getAddress(&ownAddrType, ownAddr);
Andrea Palmieri 221:7896e6d8b652 416
Andrea Palmieri 227:624ae7aa567d 417 Gap::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC;
Wolfgang Betz 132:51056160fa4a 418 Gap::Role_t role;
Vincent Coubard 256:146bb175ce80 419
Wolfgang Betz 132:51056160fa4a 420 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data;
Vincent Coubard 256:146bb175ce80 421
Wolfgang Betz 132:51056160fa4a 422 BlueNRGGap::getInstance().setConnectionHandle(cc->handle);
Vincent Coubard 256:146bb175ce80 423 BlueNRGGap::ConnectionParams_t connectionParams = {
Vincent Coubard 256:146bb175ce80 424 /* minConnectionInterval = */ cc->interval,
Vincent Coubard 272:4639da7705e1 425 /* maxConnectionInterval = */ cc->interval,
Vincent Coubard 256:146bb175ce80 426 /* slaveLatency = */ cc->latency,
Vincent Coubard 256:146bb175ce80 427 /* connectionSupervisionTimeout = */ cc->supervision_timeout
Vincent Coubard 256:146bb175ce80 428 };
Vincent Coubard 256:146bb175ce80 429
Vincent Coubard 256:146bb175ce80 430 BlueNRGGap::getInstance().setConnectionInterval(cc->interval);
Vincent Coubard 256:146bb175ce80 431
Wolfgang Betz 132:51056160fa4a 432 switch (cc->peer_bdaddr_type) {
Wolfgang Betz 132:51056160fa4a 433 case PUBLIC_ADDR:
Andrea Palmieri 210:08c4c85ca679 434 peerAddrType = BLEProtocol::AddressType::PUBLIC;
Wolfgang Betz 132:51056160fa4a 435 break;
Wolfgang Betz 132:51056160fa4a 436 case STATIC_RANDOM_ADDR:
Andrea Palmieri 210:08c4c85ca679 437 peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC;
Wolfgang Betz 132:51056160fa4a 438 break;
Wolfgang Betz 132:51056160fa4a 439 case RESOLVABLE_PRIVATE_ADDR:
Andrea Palmieri 210:08c4c85ca679 440 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE;
Wolfgang Betz 132:51056160fa4a 441 break;
Wolfgang Betz 132:51056160fa4a 442 case NON_RESOLVABLE_PRIVATE_ADDR:
Andrea Palmieri 210:08c4c85ca679 443 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE;
Wolfgang Betz 132:51056160fa4a 444 break;
Vincent Coubard 256:146bb175ce80 445 }
Wolfgang Betz 132:51056160fa4a 446 //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role);
Wolfgang Betz 132:51056160fa4a 447 switch (cc->role) {
Wolfgang Betz 133:1bb8df697f7f 448 case 0: //master
Wolfgang Betz 132:51056160fa4a 449 role = Gap::CENTRAL;
Wolfgang Betz 132:51056160fa4a 450 break;
Wolfgang Betz 133:1bb8df697f7f 451 case 1:
Wolfgang Betz 132:51056160fa4a 452 role = Gap::PERIPHERAL;
Wolfgang Betz 132:51056160fa4a 453 break;
Wolfgang Betz 133:1bb8df697f7f 454 default:
Wolfgang Betz 139:3a75965fd389 455 role = Gap::PERIPHERAL;
Wolfgang Betz 133:1bb8df697f7f 456 break;
Wolfgang Betz 132:51056160fa4a 457 }
Vincent Coubard 272:4639da7705e1 458
Vincent Coubard 272:4639da7705e1 459 BlueNRGGap::getInstance().setGapRole(role);
Vincent Coubard 272:4639da7705e1 460
Andrea Palmieri 221:7896e6d8b652 461 BlueNRGGap::getInstance().processConnectionEvent(cc->handle,
Andrea Palmieri 221:7896e6d8b652 462 role,
Andrea Palmieri 221:7896e6d8b652 463 peerAddrType,
Andrea Palmieri 221:7896e6d8b652 464 cc->peer_bdaddr,
Andrea Palmieri 221:7896e6d8b652 465 ownAddrType,
Andrea Palmieri 221:7896e6d8b652 466 ownAddr,
Andrea Palmieri 221:7896e6d8b652 467 &connectionParams);
Wolfgang Betz 132:51056160fa4a 468 }
Wolfgang Betz 132:51056160fa4a 469 break;
Vincent Coubard 256:146bb175ce80 470
Wolfgang Betz 132:51056160fa4a 471 case EVT_LE_ADVERTISING_REPORT:
Wolfgang Betz 132:51056160fa4a 472 PRINTF("EVT_LE_ADVERTISING_REPORT\n\r");
Wolfgang Betz 132:51056160fa4a 473 /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */
Wolfgang Betz 132:51056160fa4a 474 // This event is generated only by X-NUCLEO-IDB05A1 version but not by X-NUCLEO-IDB04A1 (which generates DEVICE_FOUND EVT)
Wolfgang Betz 132:51056160fa4a 475 // Formally the structure related to both events are identical except that for the ADV REPORT
Wolfgang Betz 132:51056160fa4a 476 // there is one more field (number of reports) which is not forwarded to upper layer.
Vincent Coubard 256:146bb175ce80 477 // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT.
Wolfgang Betz 132:51056160fa4a 478 le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1);
Wolfgang Betz 132:51056160fa4a 479 PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type);
Vincent Coubard 256:146bb175ce80 480
Wolfgang Betz 132:51056160fa4a 481 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND,
Wolfgang Betz 132:51056160fa4a 482 pr->evt_type,
Andrea Palmieri 229:9981f62cdb1a 483 pr->bdaddr_type,
Wolfgang Betz 132:51056160fa4a 484 pr->bdaddr,
Wolfgang Betz 132:51056160fa4a 485 &pr->data_length,
Wolfgang Betz 132:51056160fa4a 486 &pr->data_RSSI[0],
Wolfgang Betz 132:51056160fa4a 487 &pr->data_RSSI[pr->data_length]);
Wolfgang Betz 132:51056160fa4a 488 break;
Wolfgang Betz 132:51056160fa4a 489 }
Wolfgang Betz 132:51056160fa4a 490 }
Wolfgang Betz 132:51056160fa4a 491 break;
Vincent Coubard 256:146bb175ce80 492
Wolfgang Betz 132:51056160fa4a 493 case EVT_VENDOR:
Vincent Coubard 256:146bb175ce80 494 {
Wolfgang Betz 132:51056160fa4a 495 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data;
Wolfgang Betz 132:51056160fa4a 496 //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode);
Vincent Coubard 256:146bb175ce80 497
Wolfgang Betz 132:51056160fa4a 498 switch(blue_evt->ecode){
Vincent Coubard 256:146bb175ce80 499
Vincent Coubard 267:cd7870e466b3 500 case EVT_BLUE_GATT_WRITE_PERMIT_REQ:
Vincent Coubard 267:cd7870e466b3 501 {
Vincent Coubard 267:cd7870e466b3 502 PRINTF("EVT_BLUE_GATT_WRITE_PERMIT_REQ\r\n");
Vincent Coubard 267:cd7870e466b3 503 evt_gatt_write_permit_req* write_req = (evt_gatt_write_permit_req*)blue_evt->data;
Vincent Coubard 267:cd7870e466b3 504
Vincent Coubard 267:cd7870e466b3 505 // ask the local server if the write operation is authorized
Vincent Coubard 267:cd7870e466b3 506 uint8_t err_code = BlueNRGGattServer::getInstance().Write_Request_CB(
Vincent Coubard 267:cd7870e466b3 507 write_req->conn_handle,
Vincent Coubard 267:cd7870e466b3 508 write_req->attr_handle,
Vincent Coubard 267:cd7870e466b3 509 write_req->data_length,
Vincent Coubard 267:cd7870e466b3 510 write_req->data
Vincent Coubard 267:cd7870e466b3 511 );
Vincent Coubard 267:cd7870e466b3 512 uint8_t write_status = err_code == 0 ? 0 : 1;
Vincent Coubard 267:cd7870e466b3 513
Vincent Coubard 267:cd7870e466b3 514 // reply to the shield
Vincent Coubard 269:cd037b36a62b 515 aci_gatt_write_response(
Vincent Coubard 267:cd7870e466b3 516 write_req->conn_handle,
Vincent Coubard 267:cd7870e466b3 517 write_req->attr_handle,
Vincent Coubard 267:cd7870e466b3 518 write_status,
Vincent Coubard 267:cd7870e466b3 519 err_code,
Vincent Coubard 267:cd7870e466b3 520 write_req->data_length,
Vincent Coubard 267:cd7870e466b3 521 write_req->data
Vincent Coubard 267:cd7870e466b3 522 );
Vincent Coubard 267:cd7870e466b3 523 }
Vincent Coubard 267:cd7870e466b3 524 break;
Vincent Coubard 257:90b0bb40fb45 525
Wolfgang Betz 132:51056160fa4a 526 case EVT_BLUE_GATT_READ_PERMIT_REQ:
Wolfgang Betz 132:51056160fa4a 527 {
Wolfgang Betz 132:51056160fa4a 528 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r");
Wolfgang Betz 132:51056160fa4a 529 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data;
Andrea Palmieri 229:9981f62cdb1a 530 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK pr->attr_handle=%u\n\r", pr->attr_handle);
Andrea Palmieri 229:9981f62cdb1a 531 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle);
Wolfgang Betz 132:51056160fa4a 532 }
Wolfgang Betz 132:51056160fa4a 533 break;
Vincent Coubard 256:146bb175ce80 534
Vincent Coubard 256:146bb175ce80 535 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
Wolfgang Betz 132:51056160fa4a 536 {
Wolfgang Betz 132:51056160fa4a 537 PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r");
Wolfgang Betz 132:51056160fa4a 538 /* this callback is invoked when a GATT attribute is modified
Wolfgang Betz 132:51056160fa4a 539 extract callback data and pass to suitable handler function */
Andrea Palmieri 229:9981f62cdb1a 540 Attribute_Modified_CB(blue_evt);
Wolfgang Betz 132:51056160fa4a 541 }
Vincent Coubard 256:146bb175ce80 542 break;
Vincent Coubard 256:146bb175ce80 543
Wolfgang Betz 132:51056160fa4a 544 //Any cases for Data Sent Notifications?
Wolfgang Betz 132:51056160fa4a 545 case EVT_BLUE_GATT_NOTIFICATION:
Wolfgang Betz 132:51056160fa4a 546 //This is only relevant for Client Side Event
Wolfgang Betz 132:51056160fa4a 547 PRINTF("EVT_BLUE_GATT_NOTIFICATION");
Wolfgang Betz 132:51056160fa4a 548 break;
Wolfgang Betz 132:51056160fa4a 549 case EVT_BLUE_GATT_INDICATION:
Wolfgang Betz 132:51056160fa4a 550 //This is only relevant for Client Side Event
Wolfgang Betz 132:51056160fa4a 551 PRINTF("EVT_BLUE_GATT_INDICATION");
Vincent Coubard 256:146bb175ce80 552 break;
Vincent Coubard 256:146bb175ce80 553
Wolfgang Betz 132:51056160fa4a 554 case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP:
Wolfgang Betz 132:51056160fa4a 555 {
Wolfgang Betz 132:51056160fa4a 556 PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 557 evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 558 BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 559 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 560 pr->attribute_data_length,
Wolfgang Betz 132:51056160fa4a 561 pr->attribute_data_list);
Wolfgang Betz 132:51056160fa4a 562 }
Wolfgang Betz 132:51056160fa4a 563 break;
Wolfgang Betz 132:51056160fa4a 564 case EVT_BLUE_ATT_READ_BY_TYPE_RESP:
Wolfgang Betz 132:51056160fa4a 565 {
Wolfgang Betz 132:51056160fa4a 566 PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 567 evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 568 BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 569 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 570 pr->handle_value_pair_length,
Wolfgang Betz 132:51056160fa4a 571 pr->handle_value_pair);
Wolfgang Betz 132:51056160fa4a 572 }
Wolfgang Betz 132:51056160fa4a 573 break;
Wolfgang Betz 132:51056160fa4a 574 case EVT_BLUE_ATT_READ_RESP:
Wolfgang Betz 132:51056160fa4a 575 {
Wolfgang Betz 132:51056160fa4a 576 PRINTF("EVT_BLUE_ATT_READ_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 577 evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 578 BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 579 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 580 pr->attribute_value);
Wolfgang Betz 132:51056160fa4a 581 }
Wolfgang Betz 132:51056160fa4a 582 break;
Wolfgang Betz 132:51056160fa4a 583 case EVT_BLUE_ATT_EXEC_WRITE_RESP:
Wolfgang Betz 132:51056160fa4a 584 {
Wolfgang Betz 132:51056160fa4a 585 PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 586 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 587 BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 588 pr->event_data_length);
Wolfgang Betz 132:51056160fa4a 589 }
Wolfgang Betz 132:51056160fa4a 590 break;
Wolfgang Betz 132:51056160fa4a 591 case EVT_BLUE_ATT_PREPARE_WRITE_RESP:
Wolfgang Betz 132:51056160fa4a 592 {
Wolfgang Betz 132:51056160fa4a 593 PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 594 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 595 BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 596 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 597 pr->attribute_handle,
Wolfgang Betz 132:51056160fa4a 598 pr->offset,
Wolfgang Betz 132:51056160fa4a 599 pr->part_attr_value);
Wolfgang Betz 132:51056160fa4a 600 }
Wolfgang Betz 132:51056160fa4a 601 break;
Wolfgang Betz 132:51056160fa4a 602 case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP:
Wolfgang Betz 132:51056160fa4a 603 {
Wolfgang Betz 132:51056160fa4a 604 PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 605 evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 606 BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 607 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 608 pr->attr_handle,
Wolfgang Betz 132:51056160fa4a 609 pr->attr_value);
Wolfgang Betz 132:51056160fa4a 610 }
Wolfgang Betz 132:51056160fa4a 611 break;
Wolfgang Betz 132:51056160fa4a 612 case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP:
Wolfgang Betz 132:51056160fa4a 613 {
Wolfgang Betz 132:51056160fa4a 614 PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 615 evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 616 BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 617 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 618 pr->handles_info_list);
Wolfgang Betz 132:51056160fa4a 619 }
Wolfgang Betz 132:51056160fa4a 620 break;
Andrea Palmieri 229:9981f62cdb1a 621 case EVT_BLUE_ATT_FIND_INFORMATION_RESP:
Andrea Palmieri 229:9981f62cdb1a 622 {
Andrea Palmieri 229:9981f62cdb1a 623 PRINTF("EVT_BLUE_ATT_FIND_INFORMATION_RESP\n\r");
Andrea Palmieri 229:9981f62cdb1a 624 evt_att_find_information_resp *pr = (evt_att_find_information_resp*)blue_evt->data;
Andrea Palmieri 229:9981f62cdb1a 625 BlueNRGGattClient::getInstance().discAllCharacDescCB(pr->conn_handle,
Andrea Palmieri 229:9981f62cdb1a 626 pr->event_data_length,
Andrea Palmieri 229:9981f62cdb1a 627 pr->format,
Andrea Palmieri 229:9981f62cdb1a 628 pr->handle_uuid_pair);
Andrea Palmieri 229:9981f62cdb1a 629 }
Andrea Palmieri 229:9981f62cdb1a 630 break;
Andrea Palmieri 229:9981f62cdb1a 631 case EVT_BLUE_GATT_PROCEDURE_COMPLETE:
Wolfgang Betz 132:51056160fa4a 632 {
Wolfgang Betz 132:51056160fa4a 633 evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 634 PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code);
Wolfgang Betz 132:51056160fa4a 635 BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code);
Wolfgang Betz 132:51056160fa4a 636 }
Wolfgang Betz 132:51056160fa4a 637 break;
Vincent Coubard 256:146bb175ce80 638
Vincent Coubard 272:4639da7705e1 639 case EVT_BLUE_L2CAP_CONN_UPD_REQ:
Vincent Coubard 272:4639da7705e1 640 {
Vincent Coubard 272:4639da7705e1 641 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_REQ\r\n");
Vincent Coubard 272:4639da7705e1 642 evt_l2cap_conn_upd_req *evt = (evt_l2cap_conn_upd_req*)blue_evt->data;
Vincent Coubard 272:4639da7705e1 643 if(bnrg_expansion_board == IDB05A1) {
Vincent Coubard 272:4639da7705e1 644 // we assume the application accepts the request from the slave
Vincent Coubard 272:4639da7705e1 645 aci_l2cap_connection_parameter_update_response_IDB05A1(evt->conn_handle,
Vincent Coubard 272:4639da7705e1 646 evt->interval_min,
Vincent Coubard 272:4639da7705e1 647 evt->interval_max,
Vincent Coubard 272:4639da7705e1 648 evt->slave_latency,
Vincent Coubard 272:4639da7705e1 649 evt->timeout_mult,
Vincent Coubard 272:4639da7705e1 650 CONN_L1, CONN_L2,
Vincent Coubard 272:4639da7705e1 651 evt->identifier,
Vincent Coubard 272:4639da7705e1 652 0x0000);
Vincent Coubard 272:4639da7705e1 653 }
Vincent Coubard 272:4639da7705e1 654 }
Vincent Coubard 272:4639da7705e1 655 break;
Vincent Coubard 272:4639da7705e1 656
Vincent Coubard 272:4639da7705e1 657 case EVT_BLUE_L2CAP_CONN_UPD_RESP:
Vincent Coubard 272:4639da7705e1 658 {
Vincent Coubard 272:4639da7705e1 659 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_RESP\r\n");
Vincent Coubard 272:4639da7705e1 660 }
Vincent Coubard 272:4639da7705e1 661 break;
Vincent Coubard 272:4639da7705e1 662
Vincent Coubard 272:4639da7705e1 663 case EVT_LE_CONN_UPDATE_COMPLETE:
Vincent Coubard 272:4639da7705e1 664 {
Vincent Coubard 272:4639da7705e1 665 PRINTF("EVT_LE_CONN_UPDATE_COMPLETE\r\n");
Vincent Coubard 272:4639da7705e1 666 }
Vincent Coubard 272:4639da7705e1 667 break;
Vincent Coubard 272:4639da7705e1 668
Wolfgang Betz 132:51056160fa4a 669 case EVT_BLUE_GAP_DEVICE_FOUND:
Wolfgang Betz 132:51056160fa4a 670 {
Wolfgang Betz 132:51056160fa4a 671 evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 672 PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type);
Vincent Coubard 256:146bb175ce80 673
Wolfgang Betz 132:51056160fa4a 674 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND,
Wolfgang Betz 132:51056160fa4a 675 pr->evt_type,
Andrea Palmieri 229:9981f62cdb1a 676 pr->bdaddr_type,
Wolfgang Betz 132:51056160fa4a 677 pr->bdaddr,
Wolfgang Betz 132:51056160fa4a 678 &pr->data_length,
Wolfgang Betz 132:51056160fa4a 679 &pr->data_RSSI[0],
Wolfgang Betz 132:51056160fa4a 680 &pr->data_RSSI[pr->data_length]);
Wolfgang Betz 132:51056160fa4a 681 }
Wolfgang Betz 132:51056160fa4a 682 break;
Vincent Coubard 256:146bb175ce80 683
Wolfgang Betz 132:51056160fa4a 684 case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
Wolfgang Betz 132:51056160fa4a 685 {
Wolfgang Betz 132:51056160fa4a 686 evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data;
Andrea Palmieri 229:9981f62cdb1a 687 //PRINTF("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code);
Vincent Coubard 256:146bb175ce80 688
Wolfgang Betz 132:51056160fa4a 689 switch(pr->procedure_code) {
Andrea Palmieri 219:d8e8cd4d4521 690 case GAP_OBSERVATION_PROC_IDB05A1:
Vincent Coubard 256:146bb175ce80 691
Andrea Palmieri 229:9981f62cdb1a 692 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, 0, NULL, NULL, NULL, NULL);
Wolfgang Betz 132:51056160fa4a 693 break;
Wolfgang Betz 132:51056160fa4a 694 }
Wolfgang Betz 132:51056160fa4a 695 }
Vincent Coubard 256:146bb175ce80 696 break;
Wolfgang Betz 132:51056160fa4a 697 }
Wolfgang Betz 132:51056160fa4a 698 }
Wolfgang Betz 132:51056160fa4a 699 break;
Vincent Coubard 256:146bb175ce80 700 }
Wolfgang Betz 132:51056160fa4a 701 return ;
Wolfgang Betz 132:51056160fa4a 702 }
Wolfgang Betz 132:51056160fa4a 703
Wolfgang Betz 132:51056160fa4a 704
Wolfgang Betz 132:51056160fa4a 705 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 706 }
Vincent Coubard 256:146bb175ce80 707 #endif