BLE_API wrapper library for STMicroelectronics' BlueNRG Bluetooth Low Energy expansion board shield

Fork of X_NUCLEO_IDB0XA1 by ST Expansion SW Team

Committer:
avilei
Date:
Fri Jun 17 16:07:05 2016 +0000
Revision:
232:f2a7da5d24e1
Parent:
225:31b976a40f43
Add firmware update capabilities

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 ******************************************************************************
Wolfgang Betz 132:51056160fa4a 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>
Wolfgang Betz 132:51056160fa4a 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
Wolfgang Betz 132:51056160fa4a 45 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 46 extern "C" {
Wolfgang Betz 132:51056160fa4a 47 #endif
Wolfgang Betz 132:51056160fa4a 48
Wolfgang Betz 132:51056160fa4a 49
Wolfgang Betz 132:51056160fa4a 50 /* C File Includes ------------------------------------------------------------------*/
Wolfgang Betz 132:51056160fa4a 51 #include <stdio.h>
Wolfgang Betz 132:51056160fa4a 52 #include <string.h>
Wolfgang Betz 132:51056160fa4a 53 #include "hci.h"
Wolfgang Betz 132:51056160fa4a 54 #include "hci_const.h"
Wolfgang Betz 132:51056160fa4a 55 #include "bluenrg_aci.h"
Wolfgang Betz 132:51056160fa4a 56 #include "bluenrg_hal_aci.h"
Wolfgang Betz 132:51056160fa4a 57 #include "bluenrg_gap.h"
Wolfgang Betz 132:51056160fa4a 58 #include "bluenrg_utils.h"
Wolfgang Betz 132:51056160fa4a 59
Wolfgang Betz 132:51056160fa4a 60 #include "hal_types.h"
Wolfgang Betz 132:51056160fa4a 61 #include "hal.h"
Wolfgang Betz 132:51056160fa4a 62 #include "gp_timer.h"
Wolfgang Betz 132:51056160fa4a 63 #include "osal.h"
Wolfgang Betz 132:51056160fa4a 64 #include "sm.h"
Wolfgang Betz 132:51056160fa4a 65 #include "debug.h"
Wolfgang Betz 132:51056160fa4a 66
Wolfgang Betz 132:51056160fa4a 67 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 68 }
Wolfgang Betz 132:51056160fa4a 69 #endif
Wolfgang Betz 132:51056160fa4a 70
Wolfgang Betz 132:51056160fa4a 71 #define IDB04A1 0
Wolfgang Betz 132:51056160fa4a 72 #define IDB05A1 1
Wolfgang Betz 132:51056160fa4a 73
Andrea Palmieri 213:36df860f7ffc 74 // Stack Mode 0x04 allows Simultaneous Scanning and Advertisement (SSAdv)
Andrea Palmieri 213:36df860f7ffc 75 #define STACK_MODE (0x04)
Andrea Palmieri 210:e02936f0d4c7 76
Wolfgang Betz 132:51056160fa4a 77 void HCI_Input(tHciDataPacket * hciReadPacket);
Wolfgang Betz 132:51056160fa4a 78
Wolfgang Betz 132:51056160fa4a 79 uint16_t g_gap_service_handle = 0;
Wolfgang Betz 132:51056160fa4a 80 uint16_t g_appearance_char_handle = 0;
Wolfgang Betz 132:51056160fa4a 81 uint16_t g_device_name_char_handle = 0;
Wolfgang Betz 132:51056160fa4a 82
Wolfgang Betz 132:51056160fa4a 83 /* Private variables ---------------------------------------------------------*/
Wolfgang Betz 132:51056160fa4a 84 volatile uint8_t set_connectable = 1;
Andrea Palmieri 209:d8e8cd4d4521 85
Andrea Palmieri 209:d8e8cd4d4521 86 static char versionString[32];
Wolfgang Betz 132:51056160fa4a 87 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */
Wolfgang Betz 132:51056160fa4a 88
Wolfgang Betz 132:51056160fa4a 89 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 90 /*!
avilei 232:f2a7da5d24e1 91 @brief Prepare communication between the host and the BTLE HW device
Wolfgang Betz 132:51056160fa4a 92 @returns void
Wolfgang Betz 132:51056160fa4a 93 */
Wolfgang Betz 132:51056160fa4a 94 /**************************************************************************/
avilei 232:f2a7da5d24e1 95 void btleInitHW(void)
avilei 232:f2a7da5d24e1 96 {
avilei 232:f2a7da5d24e1 97 PRINTF("btleInitHW>>\n\r");
avilei 232:f2a7da5d24e1 98
avilei 232:f2a7da5d24e1 99 /* Delay needed only to be able to acces the JTAG interface after reset
avilei 232:f2a7da5d24e1 100 if it will be disabled later. */
avilei 232:f2a7da5d24e1 101 //Clock_Wait(500); FIXME: // check if I can remove this
avilei 232:f2a7da5d24e1 102
avilei 232:f2a7da5d24e1 103 /* Initialize the BlueNRG HCI */
avilei 232:f2a7da5d24e1 104 HCI_Init();
avilei 232:f2a7da5d24e1 105 }
avilei 232:f2a7da5d24e1 106
avilei 232:f2a7da5d24e1 107 /**************************************************************************/
avilei 232:f2a7da5d24e1 108 /*!
avilei 232:f2a7da5d24e1 109 * @brief Flash a new firmware using internal bootloader.
avilei 232:f2a7da5d24e1 110 * @param fw_image Pointer to the firmware image (raw binary data,
avilei 232:f2a7da5d24e1 111 * little-endian).
avilei 232:f2a7da5d24e1 112 * @param fw_size Size of the firmware image. The firmware image size shall
avilei 232:f2a7da5d24e1 113 * be multiple of 4 bytes.
avilei 232:f2a7da5d24e1 114 * @retval int It returns 0 if successful, or a number not equal to 0 in
avilei 232:f2a7da5d24e1 115 * case of error (ACI_ERROR, UNSUPPORTED_VERSION,
avilei 232:f2a7da5d24e1 116 * WRONG_IMAGE_SIZE, CRC_ERROR)
avilei 232:f2a7da5d24e1 117 */
avilei 232:f2a7da5d24e1 118 /**************************************************************************/
avilei 232:f2a7da5d24e1 119
avilei 232:f2a7da5d24e1 120 int btleUpdateFirmware(const uint8_t *fw_image, uint32_t fw_size)
Wolfgang Betz 132:51056160fa4a 121 {
avilei 232:f2a7da5d24e1 122 int status = program_device(fw_image, fw_size);
avilei 232:f2a7da5d24e1 123
avilei 232:f2a7da5d24e1 124 return (status);
avilei 232:f2a7da5d24e1 125 }
avilei 232:f2a7da5d24e1 126
avilei 232:f2a7da5d24e1 127 /**************************************************************************/
avilei 232:f2a7da5d24e1 128 /*!
avilei 232:f2a7da5d24e1 129 * @brief Get BlueNRG HW updater version
avilei 232:f2a7da5d24e1 130 * @param version This parameter returns the updater HW version.
avilei 232:f2a7da5d24e1 131 * @retval Status of the call
avilei 232:f2a7da5d24e1 132 */
avilei 232:f2a7da5d24e1 133 /**************************************************************************/
avilei 232:f2a7da5d24e1 134 uint8_t btleGetUpdaterHWVersion(uint8_t *upd_hw_version)
avilei 232:f2a7da5d24e1 135 {
avilei 232:f2a7da5d24e1 136 uint8_t status;
avilei 232:f2a7da5d24e1 137
avilei 232:f2a7da5d24e1 138 status = getBlueNRGUpdaterHWVersion(upd_hw_version);
avilei 232:f2a7da5d24e1 139
avilei 232:f2a7da5d24e1 140 return (status);
avilei 232:f2a7da5d24e1 141 }
avilei 232:f2a7da5d24e1 142
avilei 232:f2a7da5d24e1 143
avilei 232:f2a7da5d24e1 144 /**************************************************************************/
avilei 232:f2a7da5d24e1 145 /*!
avilei 232:f2a7da5d24e1 146 @brief Start the BTLE stack with the specified role
avilei 232:f2a7da5d24e1 147 @param isSetAddress boolean if address has been set
avilei 232:f2a7da5d24e1 148 @param role The device role
avilei 232:f2a7da5d24e1 149 @returns void
avilei 232:f2a7da5d24e1 150 */
avilei 232:f2a7da5d24e1 151 /**************************************************************************/
avilei 232:f2a7da5d24e1 152 void btleStart(bool isSetAddress, uint8_t role)
avilei 232:f2a7da5d24e1 153 {
Andrea Palmieri 219:9981f62cdb1a 154 /* Avoid compiler warnings about unused variables. */
Andrea Palmieri 219:9981f62cdb1a 155 (void)isSetAddress;
Wolfgang Betz 132:51056160fa4a 156
Wolfgang Betz 132:51056160fa4a 157 int ret;
Wolfgang Betz 132:51056160fa4a 158 uint8_t hwVersion;
Wolfgang Betz 132:51056160fa4a 159 uint16_t fwVersion;
Wolfgang Betz 132:51056160fa4a 160 uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
Wolfgang Betz 132:51056160fa4a 161
Wolfgang Betz 132:51056160fa4a 162 /* Reset BlueNRG SPI interface */
Wolfgang Betz 132:51056160fa4a 163 BlueNRG_RST();
Wolfgang Betz 132:51056160fa4a 164
Wolfgang Betz 132:51056160fa4a 165 /* get the BlueNRG HW and FW versions */
Wolfgang Betz 132:51056160fa4a 166 getBlueNRGVersion(&hwVersion, &fwVersion);
Wolfgang Betz 132:51056160fa4a 167
Wolfgang Betz 132:51056160fa4a 168 /*
Wolfgang Betz 132:51056160fa4a 169 * Reset BlueNRG again otherwise we won't
Wolfgang Betz 132:51056160fa4a 170 * be able to change its MAC address.
Wolfgang Betz 132:51056160fa4a 171 * aci_hal_write_config_data() must be the first
Wolfgang Betz 132:51056160fa4a 172 * command after reset otherwise it will fail.
Wolfgang Betz 132:51056160fa4a 173 */
Wolfgang Betz 132:51056160fa4a 174 BlueNRG_RST();
Wolfgang Betz 132:51056160fa4a 175
Wolfgang Betz 132:51056160fa4a 176 if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */
Wolfgang Betz 132:51056160fa4a 177 bnrg_expansion_board = IDB05A1;
Wolfgang Betz 132:51056160fa4a 178 }
Wolfgang Betz 132:51056160fa4a 179
Andrea Palmieri 209:d8e8cd4d4521 180 /* set BLE version string */
Andrea Palmieri 209:d8e8cd4d4521 181 setVersionString(hwVersion, fwVersion);
Andrea Palmieri 209:d8e8cd4d4521 182
Andrea Palmieri 210:e02936f0d4c7 183 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 210:e02936f0d4c7 184 uint8_t stackMode = STACK_MODE;
Andrea Palmieri 210:e02936f0d4c7 185 ret = aci_hal_write_config_data(CONFIG_DATA_ROLE,
Andrea Palmieri 210:e02936f0d4c7 186 CONFIG_DATA_ROLE_LEN,
Andrea Palmieri 210:e02936f0d4c7 187 &stackMode);
Andrea Palmieri 210:e02936f0d4c7 188 }
Andrea Palmieri 210:e02936f0d4c7 189
Wolfgang Betz 132:51056160fa4a 190 /* The Nucleo board must be configured as SERVER */
Andrea Palmieri 209:d8e8cd4d4521 191 //check if isSetAddress is set then set address.
Andrea Palmieri 217:624ae7aa567d 192 #if 0
Wolfgang Betz 132:51056160fa4a 193 if(isSetAddress)
Wolfgang Betz 132:51056160fa4a 194 {
Andrea Palmieri 211:7896e6d8b652 195 Gap::Address_t bleAddr;
Andrea Palmieri 211:7896e6d8b652 196 Gap::AddressType_t addr_type;
Andrea Palmieri 211:7896e6d8b652 197
Wolfgang Betz 132:51056160fa4a 198 BlueNRGGap::getInstance().getAddress(&addr_type, bleAddr);
Andrea Palmieri 217:624ae7aa567d 199
Wolfgang Betz 132:51056160fa4a 200 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
Wolfgang Betz 132:51056160fa4a 201 CONFIG_DATA_PUBADDR_LEN,
Andrea Palmieri 211:7896e6d8b652 202 bleAddr);
Wolfgang Betz 132:51056160fa4a 203 } else {
Wolfgang Betz 132:51056160fa4a 204
Wolfgang Betz 140:0cd922dca83c 205 const Gap::Address_t BLE_address_BE = {0xFD,0x66,0x05,0x13,0xBE,0xBA};
Andrea Palmieri 217:624ae7aa567d 206 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE);
Wolfgang Betz 132:51056160fa4a 207
Wolfgang Betz 132:51056160fa4a 208 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
Wolfgang Betz 132:51056160fa4a 209 CONFIG_DATA_PUBADDR_LEN,
Wolfgang Betz 132:51056160fa4a 210 BLE_address_BE);
Wolfgang Betz 132:51056160fa4a 211 }
Andrea Palmieri 217:624ae7aa567d 212 #endif
Andrea Palmieri 219:9981f62cdb1a 213
Andrea Palmieri 219:9981f62cdb1a 214 const Gap::Address_t BLE_address_BE = {0xFD,0x66,0x05,0x13,0xBE,0xBA};
Andrea Palmieri 219:9981f62cdb1a 215 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE);
Wolfgang Betz 132:51056160fa4a 216
Wolfgang Betz 132:51056160fa4a 217 ret = aci_gatt_init();
Wolfgang Betz 132:51056160fa4a 218 if(ret){
Wolfgang Betz 132:51056160fa4a 219 PRINTF("GATT_Init failed.\n");
Wolfgang Betz 132:51056160fa4a 220 }
Wolfgang Betz 132:51056160fa4a 221 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 219:9981f62cdb1a 222 ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1|GAP_OBSERVER_ROLE_IDB05A1,
Andrea Palmieri 219:9981f62cdb1a 223 0,
Andrea Palmieri 219:9981f62cdb1a 224 0x18,
Andrea Palmieri 219:9981f62cdb1a 225 &service_handle,
Andrea Palmieri 219:9981f62cdb1a 226 &dev_name_char_handle,
Andrea Palmieri 219:9981f62cdb1a 227 &appearance_char_handle);
Wolfgang Betz 132:51056160fa4a 228 } else {
Wolfgang Betz 132:51056160fa4a 229 ret = aci_gap_init_IDB04A1(role, &service_handle, &dev_name_char_handle, &appearance_char_handle);
Wolfgang Betz 132:51056160fa4a 230 }
Wolfgang Betz 132:51056160fa4a 231
Wolfgang Betz 132:51056160fa4a 232 if(ret != BLE_STATUS_SUCCESS){
Wolfgang Betz 132:51056160fa4a 233 PRINTF("GAP_Init failed.\n");
Wolfgang Betz 132:51056160fa4a 234 }
Wolfgang Betz 132:51056160fa4a 235
Andrea Palmieri 219:9981f62cdb1a 236 //FIXME: Security and passkey set by default
Wolfgang Betz 132:51056160fa4a 237 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED,
Wolfgang Betz 132:51056160fa4a 238 OOB_AUTH_DATA_ABSENT,
Wolfgang Betz 132:51056160fa4a 239 NULL,
Wolfgang Betz 132:51056160fa4a 240 7,
Wolfgang Betz 132:51056160fa4a 241 16,
Wolfgang Betz 132:51056160fa4a 242 USE_FIXED_PIN_FOR_PAIRING,
Wolfgang Betz 132:51056160fa4a 243 123456,
Wolfgang Betz 132:51056160fa4a 244 BONDING);
Wolfgang Betz 132:51056160fa4a 245 if (ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 132:51056160fa4a 246 PRINTF("Auth Req set successfully.\n");
Wolfgang Betz 132:51056160fa4a 247 }
Wolfgang Betz 132:51056160fa4a 248
Wolfgang Betz 132:51056160fa4a 249 aci_hal_set_tx_power_level(1,4);
Wolfgang Betz 132:51056160fa4a 250
Wolfgang Betz 132:51056160fa4a 251 g_gap_service_handle = service_handle;
Wolfgang Betz 132:51056160fa4a 252 g_appearance_char_handle = appearance_char_handle;
Wolfgang Betz 132:51056160fa4a 253 g_device_name_char_handle = dev_name_char_handle;
Wolfgang Betz 132:51056160fa4a 254 //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API
Wolfgang Betz 132:51056160fa4a 255 /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0,
Wolfgang Betz 132:51056160fa4a 256 strlen(name), (tHalUint8 *)name);*/
Wolfgang Betz 132:51056160fa4a 257
Wolfgang Betz 138:32e3c4ca7a45 258 #ifdef AST_FOR_MBED_OS
Wolfgang Betz 132:51056160fa4a 259 minar::Scheduler::postCallback(btle_handler);
Wolfgang Betz 132:51056160fa4a 260 #endif
Wolfgang Betz 132:51056160fa4a 261 return;
Wolfgang Betz 132:51056160fa4a 262 }
Wolfgang Betz 132:51056160fa4a 263
Wolfgang Betz 132:51056160fa4a 264 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 265 /*!
Andrea Palmieri 219:9981f62cdb1a 266 @brief mbedOS
Wolfgang Betz 132:51056160fa4a 267
Wolfgang Betz 132:51056160fa4a 268 @param[in] void
Wolfgang Betz 132:51056160fa4a 269
Wolfgang Betz 132:51056160fa4a 270 @returns
Wolfgang Betz 132:51056160fa4a 271 */
Wolfgang Betz 132:51056160fa4a 272 /**************************************************************************/
Wolfgang Betz 138:32e3c4ca7a45 273 #ifdef AST_FOR_MBED_OS
Wolfgang Betz 134:d2f8d5898d04 274 int btle_handler_pending = 0;
Wolfgang Betz 134:d2f8d5898d04 275
Wolfgang Betz 133:1bb8df697f7f 276 void btle_handler(void)
Wolfgang Betz 132:51056160fa4a 277 {
Wolfgang Betz 134:d2f8d5898d04 278 btle_handler_pending = 0;
Wolfgang Betz 132:51056160fa4a 279 HCI_Process();
Wolfgang Betz 132:51056160fa4a 280 }
Wolfgang Betz 132:51056160fa4a 281 #endif
Wolfgang Betz 132:51056160fa4a 282
Andrea Palmieri 209:d8e8cd4d4521 283 /* set BLE Version string */
Andrea Palmieri 209:d8e8cd4d4521 284 void setVersionString(uint8_t hwVersion, uint16_t fwVersion)
Andrea Palmieri 209:d8e8cd4d4521 285 {
Andrea Palmieri 209:d8e8cd4d4521 286 if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 209:d8e8cd4d4521 287 snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u",
Andrea Palmieri 209:d8e8cd4d4521 288 hwVersion>>4, (hwVersion&0x0F),
Andrea Palmieri 209:d8e8cd4d4521 289 fwVersion>>8, (fwVersion&0x00F0)>>4);
Andrea Palmieri 209:d8e8cd4d4521 290 } else {
Andrea Palmieri 209:d8e8cd4d4521 291 snprintf(versionString, sizeof(versionString), "ST (unknown spec)");
Andrea Palmieri 209:d8e8cd4d4521 292 }
Andrea Palmieri 209:d8e8cd4d4521 293 }
Andrea Palmieri 209:d8e8cd4d4521 294
Andrea Palmieri 209:d8e8cd4d4521 295 /* get BLE Version string */
Andrea Palmieri 209:d8e8cd4d4521 296 const char* getVersionString(void)
Andrea Palmieri 209:d8e8cd4d4521 297 {
Andrea Palmieri 209:d8e8cd4d4521 298 return versionString;
Andrea Palmieri 209:d8e8cd4d4521 299 }
Andrea Palmieri 209:d8e8cd4d4521 300
Andrea Palmieri 209:d8e8cd4d4521 301 tBleStatus btleStartRadioScan(uint8_t scan_type,
Andrea Palmieri 209:d8e8cd4d4521 302 uint16_t scan_interval,
Andrea Palmieri 209:d8e8cd4d4521 303 uint16_t scan_window,
Andrea Palmieri 209:d8e8cd4d4521 304 uint8_t own_address_type)
Andrea Palmieri 209:d8e8cd4d4521 305 {
Andrea Palmieri 209:d8e8cd4d4521 306 tBleStatus ret;
Andrea Palmieri 209:d8e8cd4d4521 307
Andrea Palmieri 209:d8e8cd4d4521 308 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
Andrea Palmieri 209:d8e8cd4d4521 309 if(bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 210:e02936f0d4c7 310 PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window);
Andrea Palmieri 221:a0d2544b38cd 311 PRINTF("scan_type=%d own_address_type=%d\n\r", scan_type, own_address_type);
Andrea Palmieri 209:d8e8cd4d4521 312 ret = aci_gap_start_observation_procedure(scan_interval,
Andrea Palmieri 210:e02936f0d4c7 313 scan_window,
Andrea Palmieri 209:d8e8cd4d4521 314 scan_type,
Andrea Palmieri 210:e02936f0d4c7 315 own_address_type,
Andrea Palmieri 225:31b976a40f43 316 0); // 1 to filter duplicates
Andrea Palmieri 209:d8e8cd4d4521 317 } else {
Andrea Palmieri 209:d8e8cd4d4521 318 ret = BLE_STATUS_INVALID_CID;
Andrea Palmieri 209:d8e8cd4d4521 319 }
Andrea Palmieri 209:d8e8cd4d4521 320
Andrea Palmieri 209:d8e8cd4d4521 321 return ret;
Andrea Palmieri 209:d8e8cd4d4521 322
Andrea Palmieri 209:d8e8cd4d4521 323 }
Wolfgang Betz 132:51056160fa4a 324
Wolfgang Betz 132:51056160fa4a 325 /*!
Wolfgang Betz 132:51056160fa4a 326 @brief Not Used
Wolfgang Betz 132:51056160fa4a 327
Wolfgang Betz 132:51056160fa4a 328 @param[in] void
Wolfgang Betz 132:51056160fa4a 329
Wolfgang Betz 132:51056160fa4a 330 @returns
Wolfgang Betz 132:51056160fa4a 331 */
Wolfgang Betz 132:51056160fa4a 332 void SPI_Poll(void)
Wolfgang Betz 132:51056160fa4a 333 {
Wolfgang Betz 132:51056160fa4a 334 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN);
Wolfgang Betz 132:51056160fa4a 335 return;
Wolfgang Betz 132:51056160fa4a 336 }
Wolfgang Betz 132:51056160fa4a 337
Andrea Palmieri 219:9981f62cdb1a 338 void Attribute_Modified_CB(evt_blue_aci *blue_evt)
Andrea Palmieri 219:9981f62cdb1a 339 {
Andrea Palmieri 219:9981f62cdb1a 340 uint16_t conn_handle;
Andrea Palmieri 219:9981f62cdb1a 341 uint16_t attr_handle;
Andrea Palmieri 219:9981f62cdb1a 342 uint8_t data_length;
Andrea Palmieri 219:9981f62cdb1a 343 uint8_t *att_data;
Andrea Palmieri 219:9981f62cdb1a 344 uint8_t offset;
Andrea Palmieri 219:9981f62cdb1a 345
Andrea Palmieri 219:9981f62cdb1a 346 if (bnrg_expansion_board == IDB05A1) {
Andrea Palmieri 219:9981f62cdb1a 347 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data;
Andrea Palmieri 219:9981f62cdb1a 348 conn_handle = evt->conn_handle;
Andrea Palmieri 219:9981f62cdb1a 349 attr_handle = evt->attr_handle;
Andrea Palmieri 219:9981f62cdb1a 350 data_length = evt->data_length;
Andrea Palmieri 219:9981f62cdb1a 351 att_data = evt->att_data;
Andrea Palmieri 219:9981f62cdb1a 352 offset = evt->offset;
Andrea Palmieri 219:9981f62cdb1a 353 } else {
Andrea Palmieri 219:9981f62cdb1a 354 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data;
Andrea Palmieri 219:9981f62cdb1a 355 conn_handle = evt->conn_handle;
Andrea Palmieri 219:9981f62cdb1a 356 attr_handle = evt->attr_handle;
Andrea Palmieri 219:9981f62cdb1a 357 data_length = evt->data_length;
Andrea Palmieri 219:9981f62cdb1a 358 att_data = evt->att_data;
Andrea Palmieri 219:9981f62cdb1a 359 offset = 0;
Andrea Palmieri 219:9981f62cdb1a 360 }
Andrea Palmieri 219:9981f62cdb1a 361
Wolfgang Betz 132:51056160fa4a 362 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask
Wolfgang Betz 132:51056160fa4a 363 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle);
Wolfgang Betz 132:51056160fa4a 364 if(p_char!=NULL) {
Andrea Palmieri 219:9981f62cdb1a 365 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE;
Wolfgang Betz 132:51056160fa4a 366 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE;
Wolfgang Betz 132:51056160fa4a 367 PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]);
Wolfgang Betz 132:51056160fa4a 368 PRINTF("getProperties 0x%x\n\r",p_char->getProperties());
Andrea Palmieri 219:9981f62cdb1a 369
Andrea Palmieri 219:9981f62cdb1a 370 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_VALUE_HANDLE) {
Wolfgang Betz 132:51056160fa4a 371 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE;
Wolfgang Betz 132:51056160fa4a 372 }
Wolfgang Betz 132:51056160fa4a 373
Andrea Palmieri 219:9981f62cdb1a 374 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_DESC_HANDLE) {
Wolfgang Betz 132:51056160fa4a 375 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE;
Wolfgang Betz 132:51056160fa4a 376 }
Wolfgang Betz 132:51056160fa4a 377 PRINTF("currentHandle %d\n\r", currentHandle);
Wolfgang Betz 132:51056160fa4a 378 if((p_char->getProperties() &
Wolfgang Betz 132:51056160fa4a 379 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) &&
Wolfgang Betz 132:51056160fa4a 380 currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) {
Wolfgang Betz 132:51056160fa4a 381
Andrea Palmieri 219:9981f62cdb1a 382 GattAttribute::Handle_t charDescHandle = p_char->getValueAttribute().getHandle()+1;
Andrea Palmieri 219:9981f62cdb1a 383
Wolfgang Betz 132:51056160fa4a 384 PRINTF("*****NOTIFICATION CASE\n\r");
Wolfgang Betz 132:51056160fa4a 385 //Now Check if data written in Enable or Disable
Wolfgang Betz 132:51056160fa4a 386 if((uint16_t)att_data[0]==1) {
Wolfgang Betz 132:51056160fa4a 387 //PRINTF("Notify ENABLED\n\r");
Andrea Palmieri 219:9981f62cdb1a 388 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, charDescHandle);
Wolfgang Betz 132:51056160fa4a 389 } else {
Wolfgang Betz 132:51056160fa4a 390 //PRINTF("Notify DISABLED\n\r");
Andrea Palmieri 219:9981f62cdb1a 391 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, charDescHandle);
Wolfgang Betz 132:51056160fa4a 392 }
Wolfgang Betz 132:51056160fa4a 393 }
Wolfgang Betz 132:51056160fa4a 394
Andrea Palmieri 219:9981f62cdb1a 395 //Check if attr handle property is WRITEABLE, in the case generate GATT_EVENT_DATA_WRITTEN Event
Wolfgang Betz 132:51056160fa4a 396 if((p_char->getProperties() &
Wolfgang Betz 132:51056160fa4a 397 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) &&
Wolfgang Betz 132:51056160fa4a 398 currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) {
Wolfgang Betz 132:51056160fa4a 399
Wolfgang Betz 132:51056160fa4a 400 PRINTF("*****WRITE CASE\n\r");
Wolfgang Betz 132:51056160fa4a 401
Wolfgang Betz 132:51056160fa4a 402 GattWriteCallbackParams writeParams;
Andrea Palmieri 219:9981f62cdb1a 403 writeParams.connHandle = conn_handle;
Wolfgang Betz 132:51056160fa4a 404 writeParams.handle = p_char->getValueAttribute().getHandle();
Wolfgang Betz 132:51056160fa4a 405 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG?
Wolfgang Betz 132:51056160fa4a 406 writeParams.len = data_length;
Andrea Palmieri 219:9981f62cdb1a 407 writeParams.data = att_data;
Andrea Palmieri 219:9981f62cdb1a 408 writeParams.offset = offset;
Andrea Palmieri 219:9981f62cdb1a 409
Wolfgang Betz 132:51056160fa4a 410 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams);
Wolfgang Betz 132:51056160fa4a 411
Andrea Palmieri 219:9981f62cdb1a 412 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, attr_handle);
Wolfgang Betz 132:51056160fa4a 413 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data
Andrea Palmieri 197:caf4864292c1 414 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) {
Andrea Palmieri 219:9981f62cdb1a 415 BlueNRGGattServer::getInstance().write(p_char->getValueAttribute().getHandle(),
Andrea Palmieri 219:9981f62cdb1a 416 (uint8_t*)att_data,
Andrea Palmieri 219:9981f62cdb1a 417 data_length,
Andrea Palmieri 219:9981f62cdb1a 418 false);
Wolfgang Betz 132:51056160fa4a 419 }
Wolfgang Betz 132:51056160fa4a 420 }
Wolfgang Betz 132:51056160fa4a 421 }
Wolfgang Betz 132:51056160fa4a 422
Wolfgang Betz 132:51056160fa4a 423 }
Wolfgang Betz 132:51056160fa4a 424
Wolfgang Betz 132:51056160fa4a 425 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 426 extern "C" {
Wolfgang Betz 132:51056160fa4a 427 #endif
Wolfgang Betz 132:51056160fa4a 428
Wolfgang Betz 132:51056160fa4a 429 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 430 /*!
Wolfgang Betz 132:51056160fa4a 431 @brief Handle HCI Stack Event
Wolfgang Betz 132:51056160fa4a 432
Wolfgang Betz 132:51056160fa4a 433 @param[in] pckt
Wolfgang Betz 132:51056160fa4a 434 Event Packet sent by the stack to be decoded
Wolfgang Betz 132:51056160fa4a 435
Wolfgang Betz 132:51056160fa4a 436 @returns
Wolfgang Betz 132:51056160fa4a 437 */
Wolfgang Betz 132:51056160fa4a 438 /**************************************************************************/
Wolfgang Betz 132:51056160fa4a 439 extern void HCI_Event_CB(void *pckt) {
Wolfgang Betz 132:51056160fa4a 440 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt;
Wolfgang Betz 132:51056160fa4a 441 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data;
Wolfgang Betz 132:51056160fa4a 442
Wolfgang Betz 132:51056160fa4a 443 if(hci_pckt->type != HCI_EVENT_PKT)
Andrea Palmieri 211:7896e6d8b652 444 return;
Wolfgang Betz 132:51056160fa4a 445
Wolfgang Betz 132:51056160fa4a 446 switch(event_pckt->evt){
Wolfgang Betz 132:51056160fa4a 447
Wolfgang Betz 132:51056160fa4a 448 case EVT_DISCONN_COMPLETE:
Wolfgang Betz 132:51056160fa4a 449 {
Wolfgang Betz 132:51056160fa4a 450 PRINTF("EVT_DISCONN_COMPLETE\n");
Wolfgang Betz 132:51056160fa4a 451
Andrea Palmieri 211:7896e6d8b652 452 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt->data;
Wolfgang Betz 132:51056160fa4a 453
Andrea Palmieri 211:7896e6d8b652 454 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, (Gap::DisconnectionReason_t)evt->reason);
Wolfgang Betz 132:51056160fa4a 455 }
Wolfgang Betz 132:51056160fa4a 456 break;
Wolfgang Betz 132:51056160fa4a 457
Wolfgang Betz 132:51056160fa4a 458 case EVT_LE_META_EVENT:
Wolfgang Betz 132:51056160fa4a 459 {
Wolfgang Betz 132:51056160fa4a 460 PRINTF("EVT_LE_META_EVENT\n");
Wolfgang Betz 132:51056160fa4a 461
Wolfgang Betz 132:51056160fa4a 462 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data;
Wolfgang Betz 132:51056160fa4a 463
Wolfgang Betz 132:51056160fa4a 464 switch(evt->subevent){
Andrea Palmieri 219:9981f62cdb1a 465
Wolfgang Betz 132:51056160fa4a 466 case EVT_LE_CONN_COMPLETE:
Wolfgang Betz 132:51056160fa4a 467 {
Wolfgang Betz 132:51056160fa4a 468 PRINTF("EVT_LE_CONN_COMPLETE\n");
Andrea Palmieri 211:7896e6d8b652 469 Gap::Address_t ownAddr;
Andrea Palmieri 211:7896e6d8b652 470 Gap::AddressType_t ownAddrType;
Andrea Palmieri 211:7896e6d8b652 471 BlueNRGGap::getInstance().getAddress(&ownAddrType, ownAddr);
Andrea Palmieri 211:7896e6d8b652 472
Andrea Palmieri 217:624ae7aa567d 473 Gap::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC;
Wolfgang Betz 132:51056160fa4a 474 Gap::Role_t role;
Wolfgang Betz 132:51056160fa4a 475
Wolfgang Betz 132:51056160fa4a 476 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data;
Wolfgang Betz 132:51056160fa4a 477
Wolfgang Betz 132:51056160fa4a 478 BlueNRGGap::getInstance().setConnectionHandle(cc->handle);
Wolfgang Betz 132:51056160fa4a 479 BlueNRGGap::ConnectionParams_t connectionParams;
Wolfgang Betz 132:51056160fa4a 480 BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams);
Wolfgang Betz 132:51056160fa4a 481 switch (cc->peer_bdaddr_type) {
Wolfgang Betz 132:51056160fa4a 482 case PUBLIC_ADDR:
Andrea Palmieri 202:08c4c85ca679 483 peerAddrType = BLEProtocol::AddressType::PUBLIC;
Wolfgang Betz 132:51056160fa4a 484 break;
Wolfgang Betz 132:51056160fa4a 485 case STATIC_RANDOM_ADDR:
Andrea Palmieri 202:08c4c85ca679 486 peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC;
Wolfgang Betz 132:51056160fa4a 487 break;
Wolfgang Betz 132:51056160fa4a 488 case RESOLVABLE_PRIVATE_ADDR:
Andrea Palmieri 202:08c4c85ca679 489 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE;
Wolfgang Betz 132:51056160fa4a 490 break;
Wolfgang Betz 132:51056160fa4a 491 case NON_RESOLVABLE_PRIVATE_ADDR:
Andrea Palmieri 202:08c4c85ca679 492 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE;
Wolfgang Betz 132:51056160fa4a 493 break;
Wolfgang Betz 132:51056160fa4a 494 }
Wolfgang Betz 132:51056160fa4a 495 //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role);
Wolfgang Betz 132:51056160fa4a 496 switch (cc->role) {
Wolfgang Betz 133:1bb8df697f7f 497 case 0: //master
Wolfgang Betz 132:51056160fa4a 498 role = Gap::CENTRAL;
Wolfgang Betz 132:51056160fa4a 499 break;
Wolfgang Betz 133:1bb8df697f7f 500 case 1:
Wolfgang Betz 132:51056160fa4a 501 role = Gap::PERIPHERAL;
Wolfgang Betz 132:51056160fa4a 502 break;
Wolfgang Betz 133:1bb8df697f7f 503 default:
Wolfgang Betz 139:3a75965fd389 504 role = Gap::PERIPHERAL;
Wolfgang Betz 133:1bb8df697f7f 505 break;
Wolfgang Betz 132:51056160fa4a 506 }
Wolfgang Betz 132:51056160fa4a 507 //PRINTF("EVT_LE_CONN_COMPLETE GAP role=%d\n", role);
Andrea Palmieri 211:7896e6d8b652 508 BlueNRGGap::getInstance().processConnectionEvent(cc->handle,
Andrea Palmieri 211:7896e6d8b652 509 role,
Andrea Palmieri 211:7896e6d8b652 510 peerAddrType,
Andrea Palmieri 211:7896e6d8b652 511 cc->peer_bdaddr,
Andrea Palmieri 211:7896e6d8b652 512 ownAddrType,
Andrea Palmieri 211:7896e6d8b652 513 ownAddr,
Andrea Palmieri 211:7896e6d8b652 514 &connectionParams);
Wolfgang Betz 132:51056160fa4a 515 }
Wolfgang Betz 132:51056160fa4a 516 break;
Wolfgang Betz 132:51056160fa4a 517
Wolfgang Betz 132:51056160fa4a 518 case EVT_LE_ADVERTISING_REPORT:
Wolfgang Betz 132:51056160fa4a 519 PRINTF("EVT_LE_ADVERTISING_REPORT\n\r");
Wolfgang Betz 132:51056160fa4a 520 /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */
Wolfgang Betz 132:51056160fa4a 521 // 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 522 // Formally the structure related to both events are identical except that for the ADV REPORT
Wolfgang Betz 132:51056160fa4a 523 // there is one more field (number of reports) which is not forwarded to upper layer.
Wolfgang Betz 132:51056160fa4a 524 // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT.
Wolfgang Betz 132:51056160fa4a 525 le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1);
Wolfgang Betz 132:51056160fa4a 526 PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type);
Wolfgang Betz 132:51056160fa4a 527
Wolfgang Betz 132:51056160fa4a 528 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND,
Wolfgang Betz 132:51056160fa4a 529 pr->evt_type,
Andrea Palmieri 219:9981f62cdb1a 530 pr->bdaddr_type,
Wolfgang Betz 132:51056160fa4a 531 pr->bdaddr,
Wolfgang Betz 132:51056160fa4a 532 &pr->data_length,
Wolfgang Betz 132:51056160fa4a 533 &pr->data_RSSI[0],
Wolfgang Betz 132:51056160fa4a 534 &pr->data_RSSI[pr->data_length]);
Wolfgang Betz 132:51056160fa4a 535 break;
Wolfgang Betz 132:51056160fa4a 536 }
Wolfgang Betz 132:51056160fa4a 537 }
Wolfgang Betz 132:51056160fa4a 538 break;
Wolfgang Betz 132:51056160fa4a 539
Wolfgang Betz 132:51056160fa4a 540 case EVT_VENDOR:
Wolfgang Betz 132:51056160fa4a 541 {
Wolfgang Betz 132:51056160fa4a 542 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data;
Wolfgang Betz 132:51056160fa4a 543 //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode);
Wolfgang Betz 132:51056160fa4a 544
Wolfgang Betz 132:51056160fa4a 545 switch(blue_evt->ecode){
Wolfgang Betz 132:51056160fa4a 546
Wolfgang Betz 132:51056160fa4a 547 case EVT_BLUE_GATT_READ_PERMIT_REQ:
Wolfgang Betz 132:51056160fa4a 548 {
Wolfgang Betz 132:51056160fa4a 549 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r");
Wolfgang Betz 132:51056160fa4a 550 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data;
Andrea Palmieri 219:9981f62cdb1a 551 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK pr->attr_handle=%u\n\r", pr->attr_handle);
Andrea Palmieri 219:9981f62cdb1a 552 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle);
Wolfgang Betz 132:51056160fa4a 553 }
Wolfgang Betz 132:51056160fa4a 554 break;
Wolfgang Betz 132:51056160fa4a 555
Wolfgang Betz 132:51056160fa4a 556 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
Wolfgang Betz 132:51056160fa4a 557 {
Wolfgang Betz 132:51056160fa4a 558 PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r");
Wolfgang Betz 132:51056160fa4a 559 /* this callback is invoked when a GATT attribute is modified
Wolfgang Betz 132:51056160fa4a 560 extract callback data and pass to suitable handler function */
Andrea Palmieri 219:9981f62cdb1a 561 Attribute_Modified_CB(blue_evt);
Wolfgang Betz 132:51056160fa4a 562 }
Wolfgang Betz 132:51056160fa4a 563 break;
Wolfgang Betz 132:51056160fa4a 564
Wolfgang Betz 132:51056160fa4a 565 //Any cases for Data Sent Notifications?
Wolfgang Betz 132:51056160fa4a 566 case EVT_BLUE_GATT_NOTIFICATION:
Wolfgang Betz 132:51056160fa4a 567 //This is only relevant for Client Side Event
Wolfgang Betz 132:51056160fa4a 568 PRINTF("EVT_BLUE_GATT_NOTIFICATION");
Wolfgang Betz 132:51056160fa4a 569 break;
Wolfgang Betz 132:51056160fa4a 570 case EVT_BLUE_GATT_INDICATION:
Wolfgang Betz 132:51056160fa4a 571 //This is only relevant for Client Side Event
Wolfgang Betz 132:51056160fa4a 572 PRINTF("EVT_BLUE_GATT_INDICATION");
Wolfgang Betz 132:51056160fa4a 573 break;
Wolfgang Betz 132:51056160fa4a 574
Wolfgang Betz 132:51056160fa4a 575 case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP:
Wolfgang Betz 132:51056160fa4a 576 {
Wolfgang Betz 132:51056160fa4a 577 PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 578 evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 579 BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 580 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 581 pr->attribute_data_length,
Wolfgang Betz 132:51056160fa4a 582 pr->attribute_data_list);
Wolfgang Betz 132:51056160fa4a 583 }
Wolfgang Betz 132:51056160fa4a 584 break;
Wolfgang Betz 132:51056160fa4a 585 case EVT_BLUE_ATT_READ_BY_TYPE_RESP:
Wolfgang Betz 132:51056160fa4a 586 {
Wolfgang Betz 132:51056160fa4a 587 PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 588 evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 589 BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 590 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 591 pr->handle_value_pair_length,
Wolfgang Betz 132:51056160fa4a 592 pr->handle_value_pair);
Wolfgang Betz 132:51056160fa4a 593 }
Wolfgang Betz 132:51056160fa4a 594 break;
Wolfgang Betz 132:51056160fa4a 595 case EVT_BLUE_ATT_READ_RESP:
Wolfgang Betz 132:51056160fa4a 596 {
Wolfgang Betz 132:51056160fa4a 597 PRINTF("EVT_BLUE_ATT_READ_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 598 evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 599 BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 600 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 601 pr->attribute_value);
Wolfgang Betz 132:51056160fa4a 602 }
Wolfgang Betz 132:51056160fa4a 603 break;
Wolfgang Betz 132:51056160fa4a 604 case EVT_BLUE_ATT_EXEC_WRITE_RESP:
Wolfgang Betz 132:51056160fa4a 605 {
Wolfgang Betz 132:51056160fa4a 606 PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 607 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 608 BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 609 pr->event_data_length);
Wolfgang Betz 132:51056160fa4a 610 }
Wolfgang Betz 132:51056160fa4a 611 break;
Wolfgang Betz 132:51056160fa4a 612 case EVT_BLUE_ATT_PREPARE_WRITE_RESP:
Wolfgang Betz 132:51056160fa4a 613 {
Wolfgang Betz 132:51056160fa4a 614 PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 615 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 616 BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 617 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 618 pr->attribute_handle,
Wolfgang Betz 132:51056160fa4a 619 pr->offset,
Wolfgang Betz 132:51056160fa4a 620 pr->part_attr_value);
Wolfgang Betz 132:51056160fa4a 621 }
Wolfgang Betz 132:51056160fa4a 622 break;
Wolfgang Betz 132:51056160fa4a 623 case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP:
Wolfgang Betz 132:51056160fa4a 624 {
Wolfgang Betz 132:51056160fa4a 625 PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 626 evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 627 BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 628 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 629 pr->attr_handle,
Wolfgang Betz 132:51056160fa4a 630 pr->attr_value);
Wolfgang Betz 132:51056160fa4a 631 }
Wolfgang Betz 132:51056160fa4a 632 break;
Wolfgang Betz 132:51056160fa4a 633 case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP:
Wolfgang Betz 132:51056160fa4a 634 {
Wolfgang Betz 132:51056160fa4a 635 PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r");
Wolfgang Betz 132:51056160fa4a 636 evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 637 BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle,
Wolfgang Betz 132:51056160fa4a 638 pr->event_data_length,
Wolfgang Betz 132:51056160fa4a 639 pr->handles_info_list);
Wolfgang Betz 132:51056160fa4a 640 }
Wolfgang Betz 132:51056160fa4a 641 break;
Andrea Palmieri 219:9981f62cdb1a 642 case EVT_BLUE_ATT_FIND_INFORMATION_RESP:
Andrea Palmieri 219:9981f62cdb1a 643 {
Andrea Palmieri 219:9981f62cdb1a 644 PRINTF("EVT_BLUE_ATT_FIND_INFORMATION_RESP\n\r");
Andrea Palmieri 219:9981f62cdb1a 645 evt_att_find_information_resp *pr = (evt_att_find_information_resp*)blue_evt->data;
Andrea Palmieri 219:9981f62cdb1a 646 BlueNRGGattClient::getInstance().discAllCharacDescCB(pr->conn_handle,
Andrea Palmieri 219:9981f62cdb1a 647 pr->event_data_length,
Andrea Palmieri 219:9981f62cdb1a 648 pr->format,
Andrea Palmieri 219:9981f62cdb1a 649 pr->handle_uuid_pair);
Andrea Palmieri 219:9981f62cdb1a 650 }
Andrea Palmieri 219:9981f62cdb1a 651 break;
Andrea Palmieri 219:9981f62cdb1a 652 case EVT_BLUE_GATT_PROCEDURE_COMPLETE:
Wolfgang Betz 132:51056160fa4a 653 {
Wolfgang Betz 132:51056160fa4a 654 evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 655 PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code);
Wolfgang Betz 132:51056160fa4a 656 BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code);
Wolfgang Betz 132:51056160fa4a 657 }
Wolfgang Betz 132:51056160fa4a 658 break;
Wolfgang Betz 132:51056160fa4a 659
Wolfgang Betz 132:51056160fa4a 660 case EVT_BLUE_GAP_DEVICE_FOUND:
Wolfgang Betz 132:51056160fa4a 661 {
Wolfgang Betz 132:51056160fa4a 662 evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data;
Wolfgang Betz 132:51056160fa4a 663 PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type);
Wolfgang Betz 132:51056160fa4a 664
Wolfgang Betz 132:51056160fa4a 665 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND,
Wolfgang Betz 132:51056160fa4a 666 pr->evt_type,
Andrea Palmieri 219:9981f62cdb1a 667 pr->bdaddr_type,
Wolfgang Betz 132:51056160fa4a 668 pr->bdaddr,
Wolfgang Betz 132:51056160fa4a 669 &pr->data_length,
Wolfgang Betz 132:51056160fa4a 670 &pr->data_RSSI[0],
Wolfgang Betz 132:51056160fa4a 671 &pr->data_RSSI[pr->data_length]);
Wolfgang Betz 132:51056160fa4a 672 }
Wolfgang Betz 132:51056160fa4a 673 break;
Wolfgang Betz 132:51056160fa4a 674
Wolfgang Betz 132:51056160fa4a 675 case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
Wolfgang Betz 132:51056160fa4a 676 {
Wolfgang Betz 132:51056160fa4a 677 evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data;
Andrea Palmieri 219:9981f62cdb1a 678 //PRINTF("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code);
Wolfgang Betz 132:51056160fa4a 679
Wolfgang Betz 132:51056160fa4a 680 switch(pr->procedure_code) {
Andrea Palmieri 209:d8e8cd4d4521 681 case GAP_OBSERVATION_PROC_IDB05A1:
Wolfgang Betz 132:51056160fa4a 682
Andrea Palmieri 219:9981f62cdb1a 683 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, 0, NULL, NULL, NULL, NULL);
Wolfgang Betz 132:51056160fa4a 684 break;
Wolfgang Betz 132:51056160fa4a 685 }
Wolfgang Betz 132:51056160fa4a 686 }
Wolfgang Betz 132:51056160fa4a 687 break;
Wolfgang Betz 132:51056160fa4a 688 }
Wolfgang Betz 132:51056160fa4a 689 }
Wolfgang Betz 132:51056160fa4a 690 break;
Wolfgang Betz 132:51056160fa4a 691 }
Wolfgang Betz 132:51056160fa4a 692 return ;
Wolfgang Betz 132:51056160fa4a 693 }
Wolfgang Betz 132:51056160fa4a 694
Wolfgang Betz 132:51056160fa4a 695
Wolfgang Betz 132:51056160fa4a 696 #ifdef __cplusplus
Wolfgang Betz 132:51056160fa4a 697 }
Wolfgang Betz 132:51056160fa4a 698 #endif