BLE test
Fork of X_NUCLEO_IDB0XA1 by
source/platform/btle.cpp@133:1bb8df697f7f, 2015-10-07 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Oct 07 09:08:22 2015 +0200
- Revision:
- 133:1bb8df697f7f
- Parent:
- 132:51056160fa4a
- Child:
- 134:d2f8d5898d04
Add callback after IRQ
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 | // ANDREA: Updated includes and changed some types (e.g., tHalUint8 --> uint8_t) |
Wolfgang Betz |
132:51056160fa4a | 52 | #include <stdio.h> |
Wolfgang Betz |
132:51056160fa4a | 53 | #include <string.h> |
Wolfgang Betz |
132:51056160fa4a | 54 | #include "hci.h" |
Wolfgang Betz |
132:51056160fa4a | 55 | #include "hci_const.h" |
Wolfgang Betz |
132:51056160fa4a | 56 | #include "bluenrg_aci.h" |
Wolfgang Betz |
132:51056160fa4a | 57 | #include "bluenrg_hal_aci.h" |
Wolfgang Betz |
132:51056160fa4a | 58 | #include "bluenrg_gap.h" |
Wolfgang Betz |
132:51056160fa4a | 59 | #include "bluenrg_utils.h" |
Wolfgang Betz |
132:51056160fa4a | 60 | |
Wolfgang Betz |
132:51056160fa4a | 61 | #include "hal_types.h" |
Wolfgang Betz |
132:51056160fa4a | 62 | #include "hal.h" |
Wolfgang Betz |
132:51056160fa4a | 63 | #include "gp_timer.h" |
Wolfgang Betz |
132:51056160fa4a | 64 | #include "osal.h" |
Wolfgang Betz |
132:51056160fa4a | 65 | #include "sm.h" |
Wolfgang Betz |
132:51056160fa4a | 66 | #include "debug.h" |
Wolfgang Betz |
132:51056160fa4a | 67 | |
Wolfgang Betz |
132:51056160fa4a | 68 | #ifdef __cplusplus |
Wolfgang Betz |
132:51056160fa4a | 69 | } |
Wolfgang Betz |
132:51056160fa4a | 70 | #endif |
Wolfgang Betz |
132:51056160fa4a | 71 | |
Wolfgang Betz |
132:51056160fa4a | 72 | #define IDB04A1 0 |
Wolfgang Betz |
132:51056160fa4a | 73 | #define IDB05A1 1 |
Wolfgang Betz |
132:51056160fa4a | 74 | |
Wolfgang Betz |
132:51056160fa4a | 75 | void HCI_Input(tHciDataPacket * hciReadPacket); |
Wolfgang Betz |
132:51056160fa4a | 76 | |
Wolfgang Betz |
132:51056160fa4a | 77 | //#define BDADDR_SIZE 6 |
Wolfgang Betz |
132:51056160fa4a | 78 | //tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02}; |
Wolfgang Betz |
132:51056160fa4a | 79 | |
Wolfgang Betz |
132:51056160fa4a | 80 | uint16_t g_gap_service_handle = 0; |
Wolfgang Betz |
132:51056160fa4a | 81 | uint16_t g_appearance_char_handle = 0; |
Wolfgang Betz |
132:51056160fa4a | 82 | uint16_t g_device_name_char_handle = 0; |
Wolfgang Betz |
132:51056160fa4a | 83 | |
Wolfgang Betz |
132:51056160fa4a | 84 | /* Private variables ---------------------------------------------------------*/ |
Wolfgang Betz |
132:51056160fa4a | 85 | volatile uint8_t set_connectable = 1; |
Wolfgang Betz |
132:51056160fa4a | 86 | // ANDREA |
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 | Gap::Address_t bleAddr; |
Wolfgang Betz |
132:51056160fa4a | 90 | Gap::AddressType_t addr_type = Gap::ADDR_TYPE_PUBLIC; |
Wolfgang Betz |
132:51056160fa4a | 91 | |
Wolfgang Betz |
132:51056160fa4a | 92 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 93 | /*! |
Wolfgang Betz |
132:51056160fa4a | 94 | @brief Initialises BTLE and the underlying HW/Device |
Wolfgang Betz |
132:51056160fa4a | 95 | @param isSetAddress boolean if address has been set |
Wolfgang Betz |
132:51056160fa4a | 96 | @param mosi MOSI Pin |
Wolfgang Betz |
132:51056160fa4a | 97 | @param miso MISO Pin |
Wolfgang Betz |
132:51056160fa4a | 98 | @param sclk clock Pin |
Wolfgang Betz |
132:51056160fa4a | 99 | @returns void |
Wolfgang Betz |
132:51056160fa4a | 100 | */ |
Wolfgang Betz |
132:51056160fa4a | 101 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 102 | void btle_init(bool isSetAddress, uint8_t role) |
Wolfgang Betz |
132:51056160fa4a | 103 | { |
Wolfgang Betz |
132:51056160fa4a | 104 | PRINTF("btle_init>>\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 105 | |
Wolfgang Betz |
132:51056160fa4a | 106 | int ret; |
Wolfgang Betz |
132:51056160fa4a | 107 | uint8_t hwVersion; |
Wolfgang Betz |
132:51056160fa4a | 108 | uint16_t fwVersion; |
Wolfgang Betz |
132:51056160fa4a | 109 | uint16_t service_handle, dev_name_char_handle, appearance_char_handle; |
Wolfgang Betz |
132:51056160fa4a | 110 | |
Wolfgang Betz |
132:51056160fa4a | 111 | /* Delay needed only to be able to acces the JTAG interface after reset |
Wolfgang Betz |
132:51056160fa4a | 112 | if it will be disabled later. */ |
Wolfgang Betz |
132:51056160fa4a | 113 | Clock_Wait(500); |
Wolfgang Betz |
132:51056160fa4a | 114 | |
Wolfgang Betz |
132:51056160fa4a | 115 | /* Initialize the BlueNRG HCI */ |
Wolfgang Betz |
132:51056160fa4a | 116 | HCI_Init(); |
Wolfgang Betz |
132:51056160fa4a | 117 | |
Wolfgang Betz |
132:51056160fa4a | 118 | /* Reset BlueNRG SPI interface */ |
Wolfgang Betz |
132:51056160fa4a | 119 | BlueNRG_RST(); |
Wolfgang Betz |
132:51056160fa4a | 120 | |
Wolfgang Betz |
132:51056160fa4a | 121 | /* get the BlueNRG HW and FW versions */ |
Wolfgang Betz |
132:51056160fa4a | 122 | getBlueNRGVersion(&hwVersion, &fwVersion); |
Wolfgang Betz |
132:51056160fa4a | 123 | |
Wolfgang Betz |
132:51056160fa4a | 124 | /* |
Wolfgang Betz |
132:51056160fa4a | 125 | * Reset BlueNRG again otherwise we won't |
Wolfgang Betz |
132:51056160fa4a | 126 | * be able to change its MAC address. |
Wolfgang Betz |
132:51056160fa4a | 127 | * aci_hal_write_config_data() must be the first |
Wolfgang Betz |
132:51056160fa4a | 128 | * command after reset otherwise it will fail. |
Wolfgang Betz |
132:51056160fa4a | 129 | */ |
Wolfgang Betz |
132:51056160fa4a | 130 | BlueNRG_RST(); |
Wolfgang Betz |
132:51056160fa4a | 131 | |
Wolfgang Betz |
132:51056160fa4a | 132 | if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ |
Wolfgang Betz |
132:51056160fa4a | 133 | bnrg_expansion_board = IDB05A1; |
Wolfgang Betz |
132:51056160fa4a | 134 | } |
Wolfgang Betz |
132:51056160fa4a | 135 | |
Wolfgang Betz |
132:51056160fa4a | 136 | /* The Nucleo board must be configured as SERVER */ |
Wolfgang Betz |
132:51056160fa4a | 137 | //check if isSetAddress is set than set address. |
Wolfgang Betz |
132:51056160fa4a | 138 | // ANDREA |
Wolfgang Betz |
132:51056160fa4a | 139 | if(isSetAddress) |
Wolfgang Betz |
132:51056160fa4a | 140 | { |
Wolfgang Betz |
132:51056160fa4a | 141 | BlueNRGGap::getInstance().getAddress(&addr_type, bleAddr); |
Wolfgang Betz |
132:51056160fa4a | 142 | |
Wolfgang Betz |
132:51056160fa4a | 143 | Gap::Address_t bdaddr; |
Wolfgang Betz |
132:51056160fa4a | 144 | Osal_MemCpy(bdaddr, bleAddr, BDADDR_SIZE); |
Wolfgang Betz |
132:51056160fa4a | 145 | |
Wolfgang Betz |
132:51056160fa4a | 146 | ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, |
Wolfgang Betz |
132:51056160fa4a | 147 | CONFIG_DATA_PUBADDR_LEN, |
Wolfgang Betz |
132:51056160fa4a | 148 | bdaddr); |
Wolfgang Betz |
132:51056160fa4a | 149 | } else { |
Wolfgang Betz |
132:51056160fa4a | 150 | |
Wolfgang Betz |
132:51056160fa4a | 151 | const Gap::Address_t BLE_address_BE = {0xFD,0x00,0x25,0xAA,0x02,0x04}; |
Wolfgang Betz |
132:51056160fa4a | 152 | BlueNRGGap::getInstance().setAddress(Gap::ADDR_TYPE_PUBLIC, BLE_address_BE); |
Wolfgang Betz |
132:51056160fa4a | 153 | |
Wolfgang Betz |
132:51056160fa4a | 154 | ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, |
Wolfgang Betz |
132:51056160fa4a | 155 | CONFIG_DATA_PUBADDR_LEN, |
Wolfgang Betz |
132:51056160fa4a | 156 | BLE_address_BE); |
Wolfgang Betz |
132:51056160fa4a | 157 | } |
Wolfgang Betz |
132:51056160fa4a | 158 | |
Wolfgang Betz |
132:51056160fa4a | 159 | ret = aci_gatt_init(); |
Wolfgang Betz |
132:51056160fa4a | 160 | if(ret){ |
Wolfgang Betz |
132:51056160fa4a | 161 | PRINTF("GATT_Init failed.\n"); |
Wolfgang Betz |
132:51056160fa4a | 162 | } |
Wolfgang Betz |
132:51056160fa4a | 163 | if (bnrg_expansion_board == IDB05A1) { |
Wolfgang Betz |
132:51056160fa4a | 164 | ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle); |
Wolfgang Betz |
132:51056160fa4a | 165 | } else { |
Wolfgang Betz |
132:51056160fa4a | 166 | ret = aci_gap_init_IDB04A1(role, &service_handle, &dev_name_char_handle, &appearance_char_handle); |
Wolfgang Betz |
132:51056160fa4a | 167 | } |
Wolfgang Betz |
132:51056160fa4a | 168 | |
Wolfgang Betz |
132:51056160fa4a | 169 | if(ret != BLE_STATUS_SUCCESS){ |
Wolfgang Betz |
132:51056160fa4a | 170 | PRINTF("GAP_Init failed.\n"); |
Wolfgang Betz |
132:51056160fa4a | 171 | } |
Wolfgang Betz |
132:51056160fa4a | 172 | |
Wolfgang Betz |
132:51056160fa4a | 173 | //ANDREA -- FIXME: Security and passkey set by default |
Wolfgang Betz |
132:51056160fa4a | 174 | ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, |
Wolfgang Betz |
132:51056160fa4a | 175 | OOB_AUTH_DATA_ABSENT, |
Wolfgang Betz |
132:51056160fa4a | 176 | NULL, |
Wolfgang Betz |
132:51056160fa4a | 177 | 7, |
Wolfgang Betz |
132:51056160fa4a | 178 | 16, |
Wolfgang Betz |
132:51056160fa4a | 179 | USE_FIXED_PIN_FOR_PAIRING, |
Wolfgang Betz |
132:51056160fa4a | 180 | 123456, |
Wolfgang Betz |
132:51056160fa4a | 181 | BONDING); |
Wolfgang Betz |
132:51056160fa4a | 182 | if (ret == BLE_STATUS_SUCCESS) { |
Wolfgang Betz |
132:51056160fa4a | 183 | PRINTF("Auth Req set successfully.\n"); |
Wolfgang Betz |
132:51056160fa4a | 184 | } |
Wolfgang Betz |
132:51056160fa4a | 185 | |
Wolfgang Betz |
132:51056160fa4a | 186 | aci_hal_set_tx_power_level(1,4); |
Wolfgang Betz |
132:51056160fa4a | 187 | |
Wolfgang Betz |
132:51056160fa4a | 188 | g_gap_service_handle = service_handle; |
Wolfgang Betz |
132:51056160fa4a | 189 | g_appearance_char_handle = appearance_char_handle; |
Wolfgang Betz |
132:51056160fa4a | 190 | g_device_name_char_handle = dev_name_char_handle; |
Wolfgang Betz |
132:51056160fa4a | 191 | //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API |
Wolfgang Betz |
132:51056160fa4a | 192 | /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, |
Wolfgang Betz |
132:51056160fa4a | 193 | strlen(name), (tHalUint8 *)name);*/ |
Wolfgang Betz |
132:51056160fa4a | 194 | |
Wolfgang Betz |
132:51056160fa4a | 195 | // Andrea: mbedOS |
Wolfgang Betz |
132:51056160fa4a | 196 | #ifdef YOTTA_CFG |
Wolfgang Betz |
132:51056160fa4a | 197 | minar::Scheduler::postCallback(btle_handler); |
Wolfgang Betz |
132:51056160fa4a | 198 | #endif |
Wolfgang Betz |
132:51056160fa4a | 199 | return; |
Wolfgang Betz |
132:51056160fa4a | 200 | } |
Wolfgang Betz |
132:51056160fa4a | 201 | |
Wolfgang Betz |
132:51056160fa4a | 202 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 203 | /*! |
Wolfgang Betz |
132:51056160fa4a | 204 | @brief Andrea: mbedOS |
Wolfgang Betz |
132:51056160fa4a | 205 | |
Wolfgang Betz |
132:51056160fa4a | 206 | @param[in] void |
Wolfgang Betz |
132:51056160fa4a | 207 | |
Wolfgang Betz |
132:51056160fa4a | 208 | @returns |
Wolfgang Betz |
132:51056160fa4a | 209 | */ |
Wolfgang Betz |
132:51056160fa4a | 210 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 211 | #ifdef YOTTA_CFG |
Wolfgang Betz |
133:1bb8df697f7f | 212 | void btle_handler(void) |
Wolfgang Betz |
132:51056160fa4a | 213 | { |
Wolfgang Betz |
132:51056160fa4a | 214 | HCI_Process(); |
Wolfgang Betz |
132:51056160fa4a | 215 | } |
Wolfgang Betz |
132:51056160fa4a | 216 | #endif |
Wolfgang Betz |
132:51056160fa4a | 217 | |
Wolfgang Betz |
132:51056160fa4a | 218 | |
Wolfgang Betz |
132:51056160fa4a | 219 | /*! |
Wolfgang Betz |
132:51056160fa4a | 220 | @brief Not Used |
Wolfgang Betz |
132:51056160fa4a | 221 | |
Wolfgang Betz |
132:51056160fa4a | 222 | @param[in] void |
Wolfgang Betz |
132:51056160fa4a | 223 | |
Wolfgang Betz |
132:51056160fa4a | 224 | @returns |
Wolfgang Betz |
132:51056160fa4a | 225 | */ |
Wolfgang Betz |
132:51056160fa4a | 226 | void SPI_Poll(void) |
Wolfgang Betz |
132:51056160fa4a | 227 | { |
Wolfgang Betz |
132:51056160fa4a | 228 | //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); |
Wolfgang Betz |
132:51056160fa4a | 229 | return; |
Wolfgang Betz |
132:51056160fa4a | 230 | } |
Wolfgang Betz |
132:51056160fa4a | 231 | |
Wolfgang Betz |
132:51056160fa4a | 232 | void Attribute_Modified_CB(uint16_t attr_handle, uint8_t data_length, uint8_t *att_data, uint8_t offset) |
Wolfgang Betz |
132:51056160fa4a | 233 | { |
Wolfgang Betz |
132:51056160fa4a | 234 | //Extract the GattCharacteristic from p_characteristics[] and find the properties mask |
Wolfgang Betz |
132:51056160fa4a | 235 | GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle); |
Wolfgang Betz |
132:51056160fa4a | 236 | if(p_char!=NULL) { |
Wolfgang Betz |
132:51056160fa4a | 237 | GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle(); |
Wolfgang Betz |
132:51056160fa4a | 238 | BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE; |
Wolfgang Betz |
132:51056160fa4a | 239 | PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]); |
Wolfgang Betz |
132:51056160fa4a | 240 | PRINTF("getProperties 0x%x\n\r",p_char->getProperties()); |
Wolfgang Betz |
132:51056160fa4a | 241 | if(attr_handle == charHandle+CHAR_VALUE_OFFSET) { |
Wolfgang Betz |
132:51056160fa4a | 242 | currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE; |
Wolfgang Betz |
132:51056160fa4a | 243 | } |
Wolfgang Betz |
132:51056160fa4a | 244 | |
Wolfgang Betz |
132:51056160fa4a | 245 | if(attr_handle == charHandle+CHAR_DESC_OFFSET) { |
Wolfgang Betz |
132:51056160fa4a | 246 | currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE; |
Wolfgang Betz |
132:51056160fa4a | 247 | } |
Wolfgang Betz |
132:51056160fa4a | 248 | PRINTF("currentHandle %d\n\r", currentHandle); |
Wolfgang Betz |
132:51056160fa4a | 249 | if((p_char->getProperties() & |
Wolfgang Betz |
132:51056160fa4a | 250 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) && |
Wolfgang Betz |
132:51056160fa4a | 251 | currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) { |
Wolfgang Betz |
132:51056160fa4a | 252 | |
Wolfgang Betz |
132:51056160fa4a | 253 | PRINTF("*****NOTIFICATION CASE\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 254 | //Now Check if data written in Enable or Disable |
Wolfgang Betz |
132:51056160fa4a | 255 | if((uint16_t)att_data[0]==1) { |
Wolfgang Betz |
132:51056160fa4a | 256 | //PRINTF("Notify ENABLED\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 257 | BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, p_char->getValueAttribute().getHandle()); |
Wolfgang Betz |
132:51056160fa4a | 258 | } else { |
Wolfgang Betz |
132:51056160fa4a | 259 | //PRINTF("Notify DISABLED\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 260 | BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, p_char->getValueAttribute().getHandle()); |
Wolfgang Betz |
132:51056160fa4a | 261 | } |
Wolfgang Betz |
132:51056160fa4a | 262 | } |
Wolfgang Betz |
132:51056160fa4a | 263 | |
Wolfgang Betz |
132:51056160fa4a | 264 | //Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event |
Wolfgang Betz |
132:51056160fa4a | 265 | if((p_char->getProperties() & |
Wolfgang Betz |
132:51056160fa4a | 266 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) && |
Wolfgang Betz |
132:51056160fa4a | 267 | currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) { |
Wolfgang Betz |
132:51056160fa4a | 268 | |
Wolfgang Betz |
132:51056160fa4a | 269 | PRINTF("*****WRITE CASE\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 270 | |
Wolfgang Betz |
132:51056160fa4a | 271 | GattWriteCallbackParams writeParams; |
Wolfgang Betz |
132:51056160fa4a | 272 | writeParams.handle = p_char->getValueAttribute().getHandle(); |
Wolfgang Betz |
132:51056160fa4a | 273 | writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? |
Wolfgang Betz |
132:51056160fa4a | 274 | writeParams.len = data_length; |
Wolfgang Betz |
132:51056160fa4a | 275 | writeParams.data = att_data; |
Wolfgang Betz |
132:51056160fa4a | 276 | if (bnrg_expansion_board == IDB05A1) { |
Wolfgang Betz |
132:51056160fa4a | 277 | writeParams.offset = offset; |
Wolfgang Betz |
132:51056160fa4a | 278 | } else { |
Wolfgang Betz |
132:51056160fa4a | 279 | writeParams.offset = 0; |
Wolfgang Betz |
132:51056160fa4a | 280 | } |
Wolfgang Betz |
132:51056160fa4a | 281 | BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); |
Wolfgang Betz |
132:51056160fa4a | 282 | |
Wolfgang Betz |
132:51056160fa4a | 283 | //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle); |
Wolfgang Betz |
132:51056160fa4a | 284 | //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data |
Wolfgang Betz |
132:51056160fa4a | 285 | if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() > 0)) { |
Wolfgang Betz |
132:51056160fa4a | 286 | BlueNRGGattServer::getInstance().write(p_char->getValueAttribute().getHandle(), (uint8_t*)att_data, data_length, false); |
Wolfgang Betz |
132:51056160fa4a | 287 | } |
Wolfgang Betz |
132:51056160fa4a | 288 | } |
Wolfgang Betz |
132:51056160fa4a | 289 | } |
Wolfgang Betz |
132:51056160fa4a | 290 | |
Wolfgang Betz |
132:51056160fa4a | 291 | } |
Wolfgang Betz |
132:51056160fa4a | 292 | |
Wolfgang Betz |
132:51056160fa4a | 293 | #ifdef __cplusplus |
Wolfgang Betz |
132:51056160fa4a | 294 | extern "C" { |
Wolfgang Betz |
132:51056160fa4a | 295 | #endif |
Wolfgang Betz |
132:51056160fa4a | 296 | |
Wolfgang Betz |
132:51056160fa4a | 297 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 298 | /*! |
Wolfgang Betz |
132:51056160fa4a | 299 | @brief Handle HCI Stack Event |
Wolfgang Betz |
132:51056160fa4a | 300 | |
Wolfgang Betz |
132:51056160fa4a | 301 | @param[in] pckt |
Wolfgang Betz |
132:51056160fa4a | 302 | Event Packet sent by the stack to be decoded |
Wolfgang Betz |
132:51056160fa4a | 303 | |
Wolfgang Betz |
132:51056160fa4a | 304 | @returns |
Wolfgang Betz |
132:51056160fa4a | 305 | */ |
Wolfgang Betz |
132:51056160fa4a | 306 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 307 | extern void HCI_Event_CB(void *pckt) { |
Wolfgang Betz |
132:51056160fa4a | 308 | hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; |
Wolfgang Betz |
132:51056160fa4a | 309 | hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; |
Wolfgang Betz |
132:51056160fa4a | 310 | |
Wolfgang Betz |
132:51056160fa4a | 311 | if(hci_pckt->type != HCI_EVENT_PKT) |
Wolfgang Betz |
132:51056160fa4a | 312 | return; |
Wolfgang Betz |
132:51056160fa4a | 313 | |
Wolfgang Betz |
132:51056160fa4a | 314 | switch(event_pckt->evt){ |
Wolfgang Betz |
132:51056160fa4a | 315 | |
Wolfgang Betz |
132:51056160fa4a | 316 | case EVT_DISCONN_COMPLETE: |
Wolfgang Betz |
132:51056160fa4a | 317 | { |
Wolfgang Betz |
132:51056160fa4a | 318 | PRINTF("EVT_DISCONN_COMPLETE\n"); |
Wolfgang Betz |
132:51056160fa4a | 319 | |
Wolfgang Betz |
132:51056160fa4a | 320 | evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt; |
Wolfgang Betz |
132:51056160fa4a | 321 | |
Wolfgang Betz |
132:51056160fa4a | 322 | BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, BlueNRGGap::REMOTE_USER_TERMINATED_CONNECTION); |
Wolfgang Betz |
132:51056160fa4a | 323 | } |
Wolfgang Betz |
132:51056160fa4a | 324 | break; |
Wolfgang Betz |
132:51056160fa4a | 325 | |
Wolfgang Betz |
132:51056160fa4a | 326 | case EVT_LE_META_EVENT: |
Wolfgang Betz |
132:51056160fa4a | 327 | { |
Wolfgang Betz |
132:51056160fa4a | 328 | PRINTF("EVT_LE_META_EVENT\n"); |
Wolfgang Betz |
132:51056160fa4a | 329 | |
Wolfgang Betz |
132:51056160fa4a | 330 | evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; |
Wolfgang Betz |
132:51056160fa4a | 331 | |
Wolfgang Betz |
132:51056160fa4a | 332 | switch(evt->subevent){ |
Wolfgang Betz |
132:51056160fa4a | 333 | // ANDREA |
Wolfgang Betz |
132:51056160fa4a | 334 | case EVT_LE_CONN_COMPLETE: |
Wolfgang Betz |
132:51056160fa4a | 335 | { |
Wolfgang Betz |
132:51056160fa4a | 336 | PRINTF("EVT_LE_CONN_COMPLETE\n"); |
Wolfgang Betz |
132:51056160fa4a | 337 | Gap::AddressType_t peerAddrType = Gap::ADDR_TYPE_PUBLIC; |
Wolfgang Betz |
132:51056160fa4a | 338 | Gap::Role_t role; |
Wolfgang Betz |
132:51056160fa4a | 339 | |
Wolfgang Betz |
132:51056160fa4a | 340 | evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; |
Wolfgang Betz |
132:51056160fa4a | 341 | |
Wolfgang Betz |
132:51056160fa4a | 342 | BlueNRGGap::getInstance().setConnectionHandle(cc->handle); |
Wolfgang Betz |
132:51056160fa4a | 343 | BlueNRGGap::ConnectionParams_t connectionParams; |
Wolfgang Betz |
132:51056160fa4a | 344 | BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams); |
Wolfgang Betz |
132:51056160fa4a | 345 | switch (cc->peer_bdaddr_type) { |
Wolfgang Betz |
132:51056160fa4a | 346 | case PUBLIC_ADDR: |
Wolfgang Betz |
132:51056160fa4a | 347 | peerAddrType = Gap::ADDR_TYPE_PUBLIC; |
Wolfgang Betz |
132:51056160fa4a | 348 | break; |
Wolfgang Betz |
132:51056160fa4a | 349 | case STATIC_RANDOM_ADDR: |
Wolfgang Betz |
132:51056160fa4a | 350 | peerAddrType = Gap::ADDR_TYPE_RANDOM_STATIC; |
Wolfgang Betz |
132:51056160fa4a | 351 | break; |
Wolfgang Betz |
132:51056160fa4a | 352 | case RESOLVABLE_PRIVATE_ADDR: |
Wolfgang Betz |
132:51056160fa4a | 353 | peerAddrType = Gap::ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE; |
Wolfgang Betz |
132:51056160fa4a | 354 | break; |
Wolfgang Betz |
132:51056160fa4a | 355 | case NON_RESOLVABLE_PRIVATE_ADDR: |
Wolfgang Betz |
132:51056160fa4a | 356 | peerAddrType = Gap::ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE; |
Wolfgang Betz |
132:51056160fa4a | 357 | break; |
Wolfgang Betz |
132:51056160fa4a | 358 | } |
Wolfgang Betz |
132:51056160fa4a | 359 | //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role); |
Wolfgang Betz |
132:51056160fa4a | 360 | switch (cc->role) { |
Wolfgang Betz |
133:1bb8df697f7f | 361 | case 0: //master |
Wolfgang Betz |
132:51056160fa4a | 362 | role = Gap::CENTRAL; |
Wolfgang Betz |
132:51056160fa4a | 363 | break; |
Wolfgang Betz |
133:1bb8df697f7f | 364 | case 1: |
Wolfgang Betz |
132:51056160fa4a | 365 | role = Gap::PERIPHERAL; |
Wolfgang Betz |
132:51056160fa4a | 366 | break; |
Wolfgang Betz |
133:1bb8df697f7f | 367 | default: |
Wolfgang Betz |
133:1bb8df697f7f | 368 | role = Gap::CENTRAL; |
Wolfgang Betz |
133:1bb8df697f7f | 369 | break; |
Wolfgang Betz |
132:51056160fa4a | 370 | } |
Wolfgang Betz |
132:51056160fa4a | 371 | //PRINTF("EVT_LE_CONN_COMPLETE GAP role=%d\n", role); |
Wolfgang Betz |
132:51056160fa4a | 372 | BlueNRGGap::getInstance().processConnectionEvent(cc->handle, role/*Gap::PERIPHERAL*/, peerAddrType, cc->peer_bdaddr, addr_type, bleAddr, (const BlueNRGGap::ConnectionParams_t *)&connectionParams); |
Wolfgang Betz |
132:51056160fa4a | 373 | } |
Wolfgang Betz |
132:51056160fa4a | 374 | break; |
Wolfgang Betz |
132:51056160fa4a | 375 | |
Wolfgang Betz |
132:51056160fa4a | 376 | case EVT_LE_ADVERTISING_REPORT: |
Wolfgang Betz |
132:51056160fa4a | 377 | PRINTF("EVT_LE_ADVERTISING_REPORT\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 378 | /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */ |
Wolfgang Betz |
132:51056160fa4a | 379 | // 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 | 380 | // Formally the structure related to both events are identical except that for the ADV REPORT |
Wolfgang Betz |
132:51056160fa4a | 381 | // there is one more field (number of reports) which is not forwarded to upper layer. |
Wolfgang Betz |
132:51056160fa4a | 382 | // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT. |
Wolfgang Betz |
132:51056160fa4a | 383 | le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1); |
Wolfgang Betz |
132:51056160fa4a | 384 | PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type); |
Wolfgang Betz |
132:51056160fa4a | 385 | |
Wolfgang Betz |
132:51056160fa4a | 386 | BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, |
Wolfgang Betz |
132:51056160fa4a | 387 | pr->evt_type, |
Wolfgang Betz |
132:51056160fa4a | 388 | &pr->bdaddr_type, |
Wolfgang Betz |
132:51056160fa4a | 389 | pr->bdaddr, |
Wolfgang Betz |
132:51056160fa4a | 390 | &pr->data_length, |
Wolfgang Betz |
132:51056160fa4a | 391 | &pr->data_RSSI[0], |
Wolfgang Betz |
132:51056160fa4a | 392 | &pr->data_RSSI[pr->data_length]); |
Wolfgang Betz |
132:51056160fa4a | 393 | break; |
Wolfgang Betz |
132:51056160fa4a | 394 | } |
Wolfgang Betz |
132:51056160fa4a | 395 | } |
Wolfgang Betz |
132:51056160fa4a | 396 | break; |
Wolfgang Betz |
132:51056160fa4a | 397 | |
Wolfgang Betz |
132:51056160fa4a | 398 | case EVT_VENDOR: |
Wolfgang Betz |
132:51056160fa4a | 399 | { |
Wolfgang Betz |
132:51056160fa4a | 400 | evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; |
Wolfgang Betz |
132:51056160fa4a | 401 | //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode); |
Wolfgang Betz |
132:51056160fa4a | 402 | |
Wolfgang Betz |
132:51056160fa4a | 403 | switch(blue_evt->ecode){ |
Wolfgang Betz |
132:51056160fa4a | 404 | |
Wolfgang Betz |
132:51056160fa4a | 405 | case EVT_BLUE_GATT_READ_PERMIT_REQ: |
Wolfgang Betz |
132:51056160fa4a | 406 | { |
Wolfgang Betz |
132:51056160fa4a | 407 | PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 408 | evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 409 | BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle-CHAR_VALUE_OFFSET); |
Wolfgang Betz |
132:51056160fa4a | 410 | } |
Wolfgang Betz |
132:51056160fa4a | 411 | break; |
Wolfgang Betz |
132:51056160fa4a | 412 | |
Wolfgang Betz |
132:51056160fa4a | 413 | case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: |
Wolfgang Betz |
132:51056160fa4a | 414 | { |
Wolfgang Betz |
132:51056160fa4a | 415 | PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 416 | /* this callback is invoked when a GATT attribute is modified |
Wolfgang Betz |
132:51056160fa4a | 417 | extract callback data and pass to suitable handler function */ |
Wolfgang Betz |
132:51056160fa4a | 418 | if (bnrg_expansion_board == IDB05A1) { |
Wolfgang Betz |
132:51056160fa4a | 419 | evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 420 | Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data, evt->offset); |
Wolfgang Betz |
132:51056160fa4a | 421 | } else { |
Wolfgang Betz |
132:51056160fa4a | 422 | evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 423 | Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data, 0); |
Wolfgang Betz |
132:51056160fa4a | 424 | } |
Wolfgang Betz |
132:51056160fa4a | 425 | } |
Wolfgang Betz |
132:51056160fa4a | 426 | break; |
Wolfgang Betz |
132:51056160fa4a | 427 | |
Wolfgang Betz |
132:51056160fa4a | 428 | //Any cases for Data Sent Notifications? |
Wolfgang Betz |
132:51056160fa4a | 429 | case EVT_BLUE_GATT_NOTIFICATION: |
Wolfgang Betz |
132:51056160fa4a | 430 | //This is only relevant for Client Side Event |
Wolfgang Betz |
132:51056160fa4a | 431 | PRINTF("EVT_BLUE_GATT_NOTIFICATION"); |
Wolfgang Betz |
132:51056160fa4a | 432 | break; |
Wolfgang Betz |
132:51056160fa4a | 433 | case EVT_BLUE_GATT_INDICATION: |
Wolfgang Betz |
132:51056160fa4a | 434 | //This is only relevant for Client Side Event |
Wolfgang Betz |
132:51056160fa4a | 435 | PRINTF("EVT_BLUE_GATT_INDICATION"); |
Wolfgang Betz |
132:51056160fa4a | 436 | break; |
Wolfgang Betz |
132:51056160fa4a | 437 | |
Wolfgang Betz |
132:51056160fa4a | 438 | case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP: |
Wolfgang Betz |
132:51056160fa4a | 439 | { |
Wolfgang Betz |
132:51056160fa4a | 440 | PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 441 | evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 442 | BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 443 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 444 | pr->attribute_data_length, |
Wolfgang Betz |
132:51056160fa4a | 445 | pr->attribute_data_list); |
Wolfgang Betz |
132:51056160fa4a | 446 | } |
Wolfgang Betz |
132:51056160fa4a | 447 | break; |
Wolfgang Betz |
132:51056160fa4a | 448 | case EVT_BLUE_ATT_READ_BY_TYPE_RESP: |
Wolfgang Betz |
132:51056160fa4a | 449 | { |
Wolfgang Betz |
132:51056160fa4a | 450 | PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 451 | evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 452 | BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 453 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 454 | pr->handle_value_pair_length, |
Wolfgang Betz |
132:51056160fa4a | 455 | pr->handle_value_pair); |
Wolfgang Betz |
132:51056160fa4a | 456 | } |
Wolfgang Betz |
132:51056160fa4a | 457 | break; |
Wolfgang Betz |
132:51056160fa4a | 458 | case EVT_BLUE_ATT_READ_RESP: |
Wolfgang Betz |
132:51056160fa4a | 459 | { |
Wolfgang Betz |
132:51056160fa4a | 460 | PRINTF("EVT_BLUE_ATT_READ_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 461 | evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 462 | BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 463 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 464 | pr->attribute_value); |
Wolfgang Betz |
132:51056160fa4a | 465 | } |
Wolfgang Betz |
132:51056160fa4a | 466 | break; |
Wolfgang Betz |
132:51056160fa4a | 467 | case EVT_BLUE_ATT_EXEC_WRITE_RESP: |
Wolfgang Betz |
132:51056160fa4a | 468 | { |
Wolfgang Betz |
132:51056160fa4a | 469 | PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 470 | evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 471 | BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 472 | pr->event_data_length); |
Wolfgang Betz |
132:51056160fa4a | 473 | } |
Wolfgang Betz |
132:51056160fa4a | 474 | break; |
Wolfgang Betz |
132:51056160fa4a | 475 | case EVT_BLUE_ATT_PREPARE_WRITE_RESP: |
Wolfgang Betz |
132:51056160fa4a | 476 | { |
Wolfgang Betz |
132:51056160fa4a | 477 | PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 478 | evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 479 | BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 480 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 481 | pr->attribute_handle, |
Wolfgang Betz |
132:51056160fa4a | 482 | pr->offset, |
Wolfgang Betz |
132:51056160fa4a | 483 | pr->part_attr_value); |
Wolfgang Betz |
132:51056160fa4a | 484 | } |
Wolfgang Betz |
132:51056160fa4a | 485 | break; |
Wolfgang Betz |
132:51056160fa4a | 486 | case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP: |
Wolfgang Betz |
132:51056160fa4a | 487 | { |
Wolfgang Betz |
132:51056160fa4a | 488 | PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 489 | evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 490 | BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 491 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 492 | pr->attr_handle, |
Wolfgang Betz |
132:51056160fa4a | 493 | pr->attr_value); |
Wolfgang Betz |
132:51056160fa4a | 494 | } |
Wolfgang Betz |
132:51056160fa4a | 495 | break; |
Wolfgang Betz |
132:51056160fa4a | 496 | case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP: |
Wolfgang Betz |
132:51056160fa4a | 497 | { |
Wolfgang Betz |
132:51056160fa4a | 498 | PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 499 | evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 500 | BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle, |
Wolfgang Betz |
132:51056160fa4a | 501 | pr->event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 502 | pr->handles_info_list); |
Wolfgang Betz |
132:51056160fa4a | 503 | } |
Wolfgang Betz |
132:51056160fa4a | 504 | break; |
Wolfgang Betz |
132:51056160fa4a | 505 | case EVT_BLUE_GATT_PROCEDURE_COMPLETE: |
Wolfgang Betz |
132:51056160fa4a | 506 | { |
Wolfgang Betz |
132:51056160fa4a | 507 | //PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 508 | evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 509 | PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code); |
Wolfgang Betz |
132:51056160fa4a | 510 | BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code); |
Wolfgang Betz |
132:51056160fa4a | 511 | } |
Wolfgang Betz |
132:51056160fa4a | 512 | break; |
Wolfgang Betz |
132:51056160fa4a | 513 | |
Wolfgang Betz |
132:51056160fa4a | 514 | case EVT_BLUE_GAP_DEVICE_FOUND: |
Wolfgang Betz |
132:51056160fa4a | 515 | { |
Wolfgang Betz |
132:51056160fa4a | 516 | PRINTF("EVT_BLUE_GAP_DEVICE_FOUND\n\r"); |
Wolfgang Betz |
132:51056160fa4a | 517 | evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 518 | PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type); |
Wolfgang Betz |
132:51056160fa4a | 519 | |
Wolfgang Betz |
132:51056160fa4a | 520 | BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, |
Wolfgang Betz |
132:51056160fa4a | 521 | pr->evt_type, |
Wolfgang Betz |
132:51056160fa4a | 522 | &pr->bdaddr_type, |
Wolfgang Betz |
132:51056160fa4a | 523 | pr->bdaddr, |
Wolfgang Betz |
132:51056160fa4a | 524 | &pr->data_length, |
Wolfgang Betz |
132:51056160fa4a | 525 | &pr->data_RSSI[0], |
Wolfgang Betz |
132:51056160fa4a | 526 | &pr->data_RSSI[pr->data_length]); |
Wolfgang Betz |
132:51056160fa4a | 527 | } |
Wolfgang Betz |
132:51056160fa4a | 528 | break; |
Wolfgang Betz |
132:51056160fa4a | 529 | |
Wolfgang Betz |
132:51056160fa4a | 530 | case EVT_BLUE_GAP_PROCEDURE_COMPLETE: |
Wolfgang Betz |
132:51056160fa4a | 531 | { |
Wolfgang Betz |
132:51056160fa4a | 532 | evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data; |
Wolfgang Betz |
132:51056160fa4a | 533 | //printf("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code); |
Wolfgang Betz |
132:51056160fa4a | 534 | |
Wolfgang Betz |
132:51056160fa4a | 535 | switch(pr->procedure_code) { |
Wolfgang Betz |
132:51056160fa4a | 536 | case GAP_LIMITED_DISCOVERY_PROC: |
Wolfgang Betz |
132:51056160fa4a | 537 | case GAP_GENERAL_DISCOVERY_PROC: |
Wolfgang Betz |
132:51056160fa4a | 538 | |
Wolfgang Betz |
132:51056160fa4a | 539 | BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, NULL, NULL, NULL, NULL, NULL); |
Wolfgang Betz |
132:51056160fa4a | 540 | break; |
Wolfgang Betz |
132:51056160fa4a | 541 | } |
Wolfgang Betz |
132:51056160fa4a | 542 | } |
Wolfgang Betz |
132:51056160fa4a | 543 | break; |
Wolfgang Betz |
132:51056160fa4a | 544 | } |
Wolfgang Betz |
132:51056160fa4a | 545 | } |
Wolfgang Betz |
132:51056160fa4a | 546 | break; |
Wolfgang Betz |
132:51056160fa4a | 547 | } |
Wolfgang Betz |
132:51056160fa4a | 548 | return ; |
Wolfgang Betz |
132:51056160fa4a | 549 | } |
Wolfgang Betz |
132:51056160fa4a | 550 | |
Wolfgang Betz |
132:51056160fa4a | 551 | |
Wolfgang Betz |
132:51056160fa4a | 552 | #ifdef __cplusplus |
Wolfgang Betz |
132:51056160fa4a | 553 | } |
Wolfgang Betz |
132:51056160fa4a | 554 | #endif |