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