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