ver:init

Committer:
iv123
Date:
Sun Jun 18 16:10:28 2017 +0000
Revision:
0:88b85febcb45
Initial commit

Who changed what in which revision?

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