Matthew Lister / X_NUCLEO_IDB0XA1
Committer:
Wolfgang Betz
Date:
Tue Oct 06 15:19:19 2015 +0200
Revision:
131:e09947216ccb
Parent:
130:770ce14d3d15
Get a first compilation thru

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 130:770ce14d3d15 1 /* mbed Microcontroller Library
Wolfgang Betz 130:770ce14d3d15 2 * Copyright (c) 2006-2013 ARM Limited
Wolfgang Betz 130:770ce14d3d15 3 *
Wolfgang Betz 130:770ce14d3d15 4 * Licensed under the Apache License, Version 2.0 (the "License");
Wolfgang Betz 130:770ce14d3d15 5 * you may not use this file except in compliance with the License.
Wolfgang Betz 130:770ce14d3d15 6 * You may obtain a copy of the License at
Wolfgang Betz 130:770ce14d3d15 7 *
Wolfgang Betz 130:770ce14d3d15 8 * http://www.apache.org/licenses/LICENSE-2.0
Wolfgang Betz 130:770ce14d3d15 9 *
Wolfgang Betz 130:770ce14d3d15 10 * Unless required by applicable law or agreed to in writing, software
Wolfgang Betz 130:770ce14d3d15 11 * distributed under the License is distributed on an "AS IS" BASIS,
Wolfgang Betz 130:770ce14d3d15 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Wolfgang Betz 130:770ce14d3d15 13 * See the License for the specific language governing permissions and
Wolfgang Betz 130:770ce14d3d15 14 * limitations under the License.
Wolfgang Betz 130:770ce14d3d15 15 */
Wolfgang Betz 130:770ce14d3d15 16
Wolfgang Betz 130:770ce14d3d15 17
Wolfgang Betz 130:770ce14d3d15 18 /**
Wolfgang Betz 130:770ce14d3d15 19 ******************************************************************************
Wolfgang Betz 130:770ce14d3d15 20 * @file btle.cpp
Wolfgang Betz 130:770ce14d3d15 21 * @author STMicroelectronics
Wolfgang Betz 130:770ce14d3d15 22 * @brief Implementation BlueNRG Init and helper functions.
Wolfgang Betz 130:770ce14d3d15 23 ******************************************************************************
Wolfgang Betz 130:770ce14d3d15 24 * @copy
Wolfgang Betz 130:770ce14d3d15 25 *
Wolfgang Betz 130:770ce14d3d15 26 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
Wolfgang Betz 130:770ce14d3d15 27 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
Wolfgang Betz 130:770ce14d3d15 28 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
Wolfgang Betz 130:770ce14d3d15 29 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
Wolfgang Betz 130:770ce14d3d15 30 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
Wolfgang Betz 130:770ce14d3d15 31 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
Wolfgang Betz 130:770ce14d3d15 32 *
Wolfgang Betz 130:770ce14d3d15 33 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
Wolfgang Betz 130:770ce14d3d15 34 */
Wolfgang Betz 130:770ce14d3d15 35
Wolfgang Betz 130:770ce14d3d15 36
Wolfgang Betz 130:770ce14d3d15 37 #include "btle.h"
Wolfgang Betz 130:770ce14d3d15 38 #include "ble/Gap.h"
Wolfgang Betz 130:770ce14d3d15 39 #include "ble/GapEvents.h"
Wolfgang Betz 130:770ce14d3d15 40 #include "BlueNRGGap.h"
Wolfgang Betz 130:770ce14d3d15 41 #include "BlueNRGGattServer.h"
Wolfgang Betz 130:770ce14d3d15 42 #include "Utils.h"
Wolfgang Betz 130:770ce14d3d15 43
Wolfgang Betz 130:770ce14d3d15 44 #ifdef __cplusplus
Wolfgang Betz 130:770ce14d3d15 45 extern "C" {
Wolfgang Betz 130:770ce14d3d15 46 #endif
Wolfgang Betz 130:770ce14d3d15 47
Wolfgang Betz 130:770ce14d3d15 48
Wolfgang Betz 130:770ce14d3d15 49 /* C File Includes ------------------------------------------------------------------*/
Wolfgang Betz 130:770ce14d3d15 50 // ANDREA: Updated includes and changed some types (e.g., tHalUint8 --> uint8_t)
Wolfgang Betz 130:770ce14d3d15 51 #include <stdio.h>
Wolfgang Betz 130:770ce14d3d15 52 #include <string.h>
Wolfgang Betz 130:770ce14d3d15 53 #include "hci.h"
Wolfgang Betz 130:770ce14d3d15 54 #include "hci_const.h"
Wolfgang Betz 130:770ce14d3d15 55 #include "bluenrg_aci.h"
Wolfgang Betz 130:770ce14d3d15 56 #include "bluenrg_hal_aci.h"
Wolfgang Betz 130:770ce14d3d15 57 #include "bluenrg_gap.h"
Wolfgang Betz 130:770ce14d3d15 58 #include "bluenrg_utils.h"
Wolfgang Betz 130:770ce14d3d15 59
Wolfgang Betz 130:770ce14d3d15 60 #include "hal_types.h"
Wolfgang Betz 130:770ce14d3d15 61 #include "hal.h"
Wolfgang Betz 130:770ce14d3d15 62 #include "gp_timer.h"
Wolfgang Betz 130:770ce14d3d15 63 #include "osal.h"
Wolfgang Betz 130:770ce14d3d15 64 #include "sm.h"
Wolfgang Betz 130:770ce14d3d15 65 #include "debug_platform.h"
Wolfgang Betz 130:770ce14d3d15 66
Wolfgang Betz 130:770ce14d3d15 67 #ifdef __cplusplus
Wolfgang Betz 130:770ce14d3d15 68 }
Wolfgang Betz 130:770ce14d3d15 69 #endif
Wolfgang Betz 130:770ce14d3d15 70
Wolfgang Betz 130:770ce14d3d15 71 #define IDB04A1 0
Wolfgang Betz 130:770ce14d3d15 72 #define IDB05A1 1
Wolfgang Betz 130:770ce14d3d15 73
Wolfgang Betz 130:770ce14d3d15 74 // static void btle_handler(/*ble_evt_t * p_ble_evt*/);
Wolfgang Betz 130:770ce14d3d15 75 void HCI_Input(tHciDataPacket * hciReadPacket);
Wolfgang Betz 130:770ce14d3d15 76
Wolfgang Betz 130:770ce14d3d15 77 //#define BDADDR_SIZE 6
Wolfgang Betz 130:770ce14d3d15 78 //tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02};
Wolfgang Betz 130:770ce14d3d15 79
Wolfgang Betz 130:770ce14d3d15 80 uint16_t g_gap_service_handle = 0;
Wolfgang Betz 130:770ce14d3d15 81 uint16_t g_appearance_char_handle = 0;
Wolfgang Betz 130:770ce14d3d15 82 uint16_t g_device_name_char_handle = 0;
Wolfgang Betz 130:770ce14d3d15 83
Wolfgang Betz 130:770ce14d3d15 84 /* Private variables ---------------------------------------------------------*/
Wolfgang Betz 130:770ce14d3d15 85 volatile uint8_t set_connectable = 1;
Wolfgang Betz 130:770ce14d3d15 86 // ANDREA
Wolfgang Betz 130:770ce14d3d15 87 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */
Wolfgang Betz 130:770ce14d3d15 88
Wolfgang Betz 130:770ce14d3d15 89 Gap::Address_t bleAddr;
Wolfgang Betz 130:770ce14d3d15 90 Gap::AddressType_t addr_type = Gap::ADDR_TYPE_PUBLIC;
Wolfgang Betz 130:770ce14d3d15 91
Wolfgang Betz 130:770ce14d3d15 92 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 93 /*!
Wolfgang Betz 130:770ce14d3d15 94 @brief Initialises BTLE and the underlying HW/Device
Wolfgang Betz 130:770ce14d3d15 95 @param isSetAddress boolean if address has been set
Wolfgang Betz 130:770ce14d3d15 96 @param mosi MOSI Pin
Wolfgang Betz 130:770ce14d3d15 97 @param miso MISO Pin
Wolfgang Betz 130:770ce14d3d15 98 @param sclk clock Pin
Wolfgang Betz 130:770ce14d3d15 99 @returns void
Wolfgang Betz 130:770ce14d3d15 100 */
Wolfgang Betz 130:770ce14d3d15 101 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 102 void btle_init(bool isSetAddress)
Wolfgang Betz 130:770ce14d3d15 103 {
Wolfgang Betz 130:770ce14d3d15 104 DEBUG("btle_init>>\n\r");
Wolfgang Betz 130:770ce14d3d15 105
Wolfgang Betz 130:770ce14d3d15 106 int ret;
Wolfgang Betz 130:770ce14d3d15 107 uint8_t hwVersion;
Wolfgang Betz 130:770ce14d3d15 108 uint16_t fwVersion;
Wolfgang Betz 130:770ce14d3d15 109 uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
Wolfgang Betz 130:770ce14d3d15 110
Wolfgang Betz 130:770ce14d3d15 111 /* Delay needed only to be able to acces the JTAG interface after reset
Wolfgang Betz 130:770ce14d3d15 112 if it will be disabled later. */
Wolfgang Betz 130:770ce14d3d15 113 Clock_Wait(500);
Wolfgang Betz 130:770ce14d3d15 114
Wolfgang Betz 130:770ce14d3d15 115 /* Initialize the BlueNRG HCI */
Wolfgang Betz 130:770ce14d3d15 116 HCI_Init();
Wolfgang Betz 130:770ce14d3d15 117
Wolfgang Betz 130:770ce14d3d15 118 /* Reset BlueNRG SPI interface */
Wolfgang Betz 130:770ce14d3d15 119 BlueNRG_RST();
Wolfgang Betz 130:770ce14d3d15 120
Wolfgang Betz 130:770ce14d3d15 121 /* get the BlueNRG HW and FW versions */
Wolfgang Betz 130:770ce14d3d15 122 getBlueNRGVersion(&hwVersion, &fwVersion);
Wolfgang Betz 130:770ce14d3d15 123
Wolfgang Betz 130:770ce14d3d15 124 /*
Wolfgang Betz 130:770ce14d3d15 125 * Reset BlueNRG again otherwise we won't
Wolfgang Betz 130:770ce14d3d15 126 * be able to change its MAC address.
Wolfgang Betz 130:770ce14d3d15 127 * aci_hal_write_config_data() must be the first
Wolfgang Betz 130:770ce14d3d15 128 * command after reset otherwise it will fail.
Wolfgang Betz 130:770ce14d3d15 129 */
Wolfgang Betz 130:770ce14d3d15 130 BlueNRG_RST();
Wolfgang Betz 130:770ce14d3d15 131
Wolfgang Betz 130:770ce14d3d15 132 if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */
Wolfgang Betz 130:770ce14d3d15 133 bnrg_expansion_board = IDB05A1;
Wolfgang Betz 130:770ce14d3d15 134 }
Wolfgang Betz 130:770ce14d3d15 135
Wolfgang Betz 130:770ce14d3d15 136 /* The Nucleo board must be configured as SERVER */
Wolfgang Betz 130:770ce14d3d15 137 //check if isSetAddress is set than set address.
Wolfgang Betz 130:770ce14d3d15 138 // ANDREA
Wolfgang Betz 130:770ce14d3d15 139 if(isSetAddress)
Wolfgang Betz 130:770ce14d3d15 140 {
Wolfgang Betz 130:770ce14d3d15 141 BlueNRGGap::getInstance().getAddress(&addr_type, bleAddr);
Wolfgang Betz 130:770ce14d3d15 142
Wolfgang Betz 130:770ce14d3d15 143 Gap::Address_t bdaddr;
Wolfgang Betz 130:770ce14d3d15 144 Osal_MemCpy(bdaddr, bleAddr, BDADDR_SIZE);
Wolfgang Betz 130:770ce14d3d15 145
Wolfgang Betz 130:770ce14d3d15 146 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
Wolfgang Betz 130:770ce14d3d15 147 CONFIG_DATA_PUBADDR_LEN,
Wolfgang Betz 130:770ce14d3d15 148 bdaddr);
Wolfgang Betz 130:770ce14d3d15 149 } else {
Wolfgang Betz 130:770ce14d3d15 150
Wolfgang Betz 130:770ce14d3d15 151 const Gap::Address_t BLE_address_BE = {0xFD,0x00,0x25,0xAA,0x02,0x04};
Wolfgang Betz 130:770ce14d3d15 152 BlueNRGGap::getInstance().setAddress(Gap::ADDR_TYPE_PUBLIC, BLE_address_BE);
Wolfgang Betz 130:770ce14d3d15 153
Wolfgang Betz 130:770ce14d3d15 154 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET,
Wolfgang Betz 130:770ce14d3d15 155 CONFIG_DATA_PUBADDR_LEN,
Wolfgang Betz 130:770ce14d3d15 156 BLE_address_BE);
Wolfgang Betz 130:770ce14d3d15 157 }
Wolfgang Betz 130:770ce14d3d15 158
Wolfgang Betz 130:770ce14d3d15 159 ret = aci_gatt_init();
Wolfgang Betz 130:770ce14d3d15 160 if(ret){
Wolfgang Betz 130:770ce14d3d15 161 PRINTF("GATT_Init failed.\n");
Wolfgang Betz 130:770ce14d3d15 162 }
Wolfgang Betz 130:770ce14d3d15 163 //GAP is always in PERIPHERAL _ROLE as mbed does not support Master role at the moment
Wolfgang Betz 130:770ce14d3d15 164 if (bnrg_expansion_board == IDB05A1) {
Wolfgang Betz 130:770ce14d3d15 165 ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle);
Wolfgang Betz 130:770ce14d3d15 166 } else {
Wolfgang Betz 130:770ce14d3d15 167 ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle);
Wolfgang Betz 130:770ce14d3d15 168 }
Wolfgang Betz 130:770ce14d3d15 169
Wolfgang Betz 130:770ce14d3d15 170 if(ret != BLE_STATUS_SUCCESS){
Wolfgang Betz 130:770ce14d3d15 171 PRINTF("GAP_Init failed.\n");
Wolfgang Betz 130:770ce14d3d15 172 }
Wolfgang Betz 130:770ce14d3d15 173
Wolfgang Betz 130:770ce14d3d15 174 //ANDREA -- FIXME: Security and passkey set by default
Wolfgang Betz 130:770ce14d3d15 175 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED,
Wolfgang Betz 130:770ce14d3d15 176 OOB_AUTH_DATA_ABSENT,
Wolfgang Betz 130:770ce14d3d15 177 NULL,
Wolfgang Betz 130:770ce14d3d15 178 7,
Wolfgang Betz 130:770ce14d3d15 179 16,
Wolfgang Betz 130:770ce14d3d15 180 USE_FIXED_PIN_FOR_PAIRING,
Wolfgang Betz 130:770ce14d3d15 181 123456,
Wolfgang Betz 130:770ce14d3d15 182 BONDING);
Wolfgang Betz 130:770ce14d3d15 183 if (ret == BLE_STATUS_SUCCESS) {
Wolfgang Betz 130:770ce14d3d15 184 DEBUG("Auth Req set successfully.\n");
Wolfgang Betz 130:770ce14d3d15 185 }
Wolfgang Betz 130:770ce14d3d15 186
Wolfgang Betz 130:770ce14d3d15 187 aci_hal_set_tx_power_level(1,4);
Wolfgang Betz 130:770ce14d3d15 188
Wolfgang Betz 130:770ce14d3d15 189 g_gap_service_handle = service_handle;
Wolfgang Betz 130:770ce14d3d15 190 g_appearance_char_handle = appearance_char_handle;
Wolfgang Betz 130:770ce14d3d15 191 g_device_name_char_handle = dev_name_char_handle;
Wolfgang Betz 130:770ce14d3d15 192 //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API
Wolfgang Betz 130:770ce14d3d15 193 /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0,
Wolfgang Betz 130:770ce14d3d15 194 strlen(name), (tHalUint8 *)name);*/
Wolfgang Betz 130:770ce14d3d15 195
Wolfgang Betz 130:770ce14d3d15 196 return;
Wolfgang Betz 130:770ce14d3d15 197 }
Wolfgang Betz 130:770ce14d3d15 198
Wolfgang Betz 130:770ce14d3d15 199 void User_Process()
Wolfgang Betz 130:770ce14d3d15 200 {
Wolfgang Betz 130:770ce14d3d15 201 if(set_connectable){
Wolfgang Betz 130:770ce14d3d15 202 setConnectable();
Wolfgang Betz 130:770ce14d3d15 203 set_connectable = FALSE;
Wolfgang Betz 130:770ce14d3d15 204 }
Wolfgang Betz 130:770ce14d3d15 205 }
Wolfgang Betz 130:770ce14d3d15 206
Wolfgang Betz 130:770ce14d3d15 207 void setConnectable(void)
Wolfgang Betz 130:770ce14d3d15 208 {
Wolfgang Betz 130:770ce14d3d15 209 tBleStatus ret;
Wolfgang Betz 130:770ce14d3d15 210
Wolfgang Betz 130:770ce14d3d15 211 const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'};
Wolfgang Betz 130:770ce14d3d15 212
Wolfgang Betz 130:770ce14d3d15 213 /* disable scan response */
Wolfgang Betz 130:770ce14d3d15 214 hci_le_set_scan_resp_data(0,NULL);
Wolfgang Betz 130:770ce14d3d15 215
Wolfgang Betz 130:770ce14d3d15 216 //int t = BlueNRGGap::getInstance()::ADV_IND;// advType;
Wolfgang Betz 130:770ce14d3d15 217
Wolfgang Betz 130:770ce14d3d15 218 ret = aci_gap_set_discoverable(BlueNRGGap::getInstance().ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE,
Wolfgang Betz 130:770ce14d3d15 219 sizeof(local_name), local_name, 0, NULL, 0, 0);
Wolfgang Betz 130:770ce14d3d15 220 if (ret != BLE_STATUS_SUCCESS) {
Wolfgang Betz 130:770ce14d3d15 221 DEBUG("Error while setting discoverable mode (%d)\n", ret);
Wolfgang Betz 130:770ce14d3d15 222 }
Wolfgang Betz 130:770ce14d3d15 223
Wolfgang Betz 130:770ce14d3d15 224 }
Wolfgang Betz 130:770ce14d3d15 225
Wolfgang Betz 130:770ce14d3d15 226 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 227 /*!
Wolfgang Betz 130:770ce14d3d15 228 @brief Not Used
Wolfgang Betz 130:770ce14d3d15 229
Wolfgang Betz 130:770ce14d3d15 230 @param[in] void
Wolfgang Betz 130:770ce14d3d15 231
Wolfgang Betz 130:770ce14d3d15 232 @returns
Wolfgang Betz 130:770ce14d3d15 233 */
Wolfgang Betz 130:770ce14d3d15 234 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 235 /*
Wolfgang Betz 130:770ce14d3d15 236 static void btle_handler()
Wolfgang Betz 130:770ce14d3d15 237 {
Wolfgang Betz 130:770ce14d3d15 238
Wolfgang Betz 130:770ce14d3d15 239 }
Wolfgang Betz 130:770ce14d3d15 240 */
Wolfgang Betz 130:770ce14d3d15 241
Wolfgang Betz 130:770ce14d3d15 242 /*!
Wolfgang Betz 130:770ce14d3d15 243 @brief Not Used
Wolfgang Betz 130:770ce14d3d15 244
Wolfgang Betz 130:770ce14d3d15 245 @param[in] void
Wolfgang Betz 130:770ce14d3d15 246
Wolfgang Betz 130:770ce14d3d15 247 @returns
Wolfgang Betz 130:770ce14d3d15 248 */
Wolfgang Betz 130:770ce14d3d15 249 void SPI_Poll(void)
Wolfgang Betz 130:770ce14d3d15 250 {
Wolfgang Betz 130:770ce14d3d15 251 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN);
Wolfgang Betz 130:770ce14d3d15 252 return;
Wolfgang Betz 130:770ce14d3d15 253 }
Wolfgang Betz 130:770ce14d3d15 254
Wolfgang Betz 130:770ce14d3d15 255 void Attribute_Modified_CB(uint16_t attr_handle, uint8_t data_length, uint8_t *att_data, uint8_t offset)
Wolfgang Betz 130:770ce14d3d15 256 {
Wolfgang Betz 130:770ce14d3d15 257 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask
Wolfgang Betz 130:770ce14d3d15 258 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle);
Wolfgang Betz 130:770ce14d3d15 259 if(p_char!=NULL) {
Wolfgang Betz 130:770ce14d3d15 260 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle();
Wolfgang Betz 130:770ce14d3d15 261 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE;
Wolfgang Betz 130:770ce14d3d15 262 DEBUG("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]);
Wolfgang Betz 130:770ce14d3d15 263 DEBUG("getProperties 0x%x\n\r",p_char->getProperties());
Wolfgang Betz 130:770ce14d3d15 264 if(attr_handle == charHandle+CHAR_VALUE_OFFSET) {
Wolfgang Betz 130:770ce14d3d15 265 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE;
Wolfgang Betz 130:770ce14d3d15 266 }
Wolfgang Betz 130:770ce14d3d15 267
Wolfgang Betz 130:770ce14d3d15 268 if(attr_handle == charHandle+CHAR_DESC_OFFSET) {
Wolfgang Betz 130:770ce14d3d15 269 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE;
Wolfgang Betz 130:770ce14d3d15 270 }
Wolfgang Betz 130:770ce14d3d15 271 DEBUG("currentHandle %d\n\r", currentHandle);
Wolfgang Betz 130:770ce14d3d15 272 if((p_char->getProperties() &
Wolfgang Betz 130:770ce14d3d15 273 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) &&
Wolfgang Betz 130:770ce14d3d15 274 currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) {
Wolfgang Betz 130:770ce14d3d15 275
Wolfgang Betz 130:770ce14d3d15 276 DEBUG("*****NOTIFICATION CASE\n\r");
Wolfgang Betz 130:770ce14d3d15 277 //Now Check if data written in Enable or Disable
Wolfgang Betz 130:770ce14d3d15 278 if((uint16_t)att_data[0]==1) {
Wolfgang Betz 130:770ce14d3d15 279 //DEBUG("Notify ENABLED\n\r");
Wolfgang Betz 130:770ce14d3d15 280 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, p_char->getValueAttribute().getHandle());
Wolfgang Betz 130:770ce14d3d15 281 } else {
Wolfgang Betz 130:770ce14d3d15 282 //DEBUG("Notify DISABLED\n\r");
Wolfgang Betz 130:770ce14d3d15 283 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, p_char->getValueAttribute().getHandle());
Wolfgang Betz 130:770ce14d3d15 284 }
Wolfgang Betz 130:770ce14d3d15 285 }
Wolfgang Betz 130:770ce14d3d15 286
Wolfgang Betz 130:770ce14d3d15 287 //Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event
Wolfgang Betz 130:770ce14d3d15 288 if((p_char->getProperties() &
Wolfgang Betz 130:770ce14d3d15 289 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) &&
Wolfgang Betz 130:770ce14d3d15 290 currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) {
Wolfgang Betz 130:770ce14d3d15 291
Wolfgang Betz 130:770ce14d3d15 292 DEBUG("*****WRITE CASE\n\r");
Wolfgang Betz 130:770ce14d3d15 293
Wolfgang Betz 130:770ce14d3d15 294 GattWriteCallbackParams writeParams;
Wolfgang Betz 130:770ce14d3d15 295 writeParams.handle = p_char->getValueAttribute().getHandle();
Wolfgang Betz 130:770ce14d3d15 296 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG?
Wolfgang Betz 130:770ce14d3d15 297 writeParams.len = data_length;
Wolfgang Betz 130:770ce14d3d15 298 writeParams.data = att_data;
Wolfgang Betz 130:770ce14d3d15 299 if (bnrg_expansion_board == IDB05A1) {
Wolfgang Betz 130:770ce14d3d15 300 writeParams.offset = offset;
Wolfgang Betz 130:770ce14d3d15 301 }
Wolfgang Betz 130:770ce14d3d15 302 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams);
Wolfgang Betz 130:770ce14d3d15 303
Wolfgang Betz 130:770ce14d3d15 304 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle);
Wolfgang Betz 130:770ce14d3d15 305 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data
Wolfgang Betz 130:770ce14d3d15 306 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() > 0)) {
Wolfgang Betz 130:770ce14d3d15 307 BlueNRGGattServer::getInstance().write(p_char->getValueAttribute().getHandle(), (uint8_t*)att_data, data_length, false);
Wolfgang Betz 130:770ce14d3d15 308 }
Wolfgang Betz 130:770ce14d3d15 309 }
Wolfgang Betz 130:770ce14d3d15 310 }
Wolfgang Betz 130:770ce14d3d15 311
Wolfgang Betz 130:770ce14d3d15 312 }
Wolfgang Betz 130:770ce14d3d15 313
Wolfgang Betz 130:770ce14d3d15 314 #ifdef __cplusplus
Wolfgang Betz 130:770ce14d3d15 315 extern "C" {
Wolfgang Betz 130:770ce14d3d15 316 #endif
Wolfgang Betz 130:770ce14d3d15 317
Wolfgang Betz 130:770ce14d3d15 318 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 319 /*!
Wolfgang Betz 130:770ce14d3d15 320 @brief Handle HCI Stack Event
Wolfgang Betz 130:770ce14d3d15 321
Wolfgang Betz 130:770ce14d3d15 322 @param[in] pckt
Wolfgang Betz 130:770ce14d3d15 323 Event Packet sent by the stack to be decoded
Wolfgang Betz 130:770ce14d3d15 324
Wolfgang Betz 130:770ce14d3d15 325 @returns
Wolfgang Betz 130:770ce14d3d15 326 */
Wolfgang Betz 130:770ce14d3d15 327 /**************************************************************************/
Wolfgang Betz 130:770ce14d3d15 328 extern void HCI_Event_CB(void *pckt) {
Wolfgang Betz 130:770ce14d3d15 329 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt;
Wolfgang Betz 130:770ce14d3d15 330 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data;
Wolfgang Betz 130:770ce14d3d15 331
Wolfgang Betz 130:770ce14d3d15 332 if(hci_pckt->type != HCI_EVENT_PKT)
Wolfgang Betz 130:770ce14d3d15 333 return;
Wolfgang Betz 130:770ce14d3d15 334
Wolfgang Betz 130:770ce14d3d15 335 switch(event_pckt->evt){
Wolfgang Betz 130:770ce14d3d15 336
Wolfgang Betz 130:770ce14d3d15 337 case EVT_DISCONN_COMPLETE:
Wolfgang Betz 130:770ce14d3d15 338 {
Wolfgang Betz 130:770ce14d3d15 339 DEBUG("EVT_DISCONN_COMPLETE\n");
Wolfgang Betz 130:770ce14d3d15 340
Wolfgang Betz 130:770ce14d3d15 341 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt;
Wolfgang Betz 130:770ce14d3d15 342
Wolfgang Betz 130:770ce14d3d15 343 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, BlueNRGGap::REMOTE_USER_TERMINATED_CONNECTION);
Wolfgang Betz 130:770ce14d3d15 344 }
Wolfgang Betz 130:770ce14d3d15 345 break;
Wolfgang Betz 130:770ce14d3d15 346
Wolfgang Betz 130:770ce14d3d15 347 case EVT_LE_META_EVENT:
Wolfgang Betz 130:770ce14d3d15 348 {
Wolfgang Betz 130:770ce14d3d15 349 DEBUG("EVT_LE_META_EVENT\n");
Wolfgang Betz 130:770ce14d3d15 350
Wolfgang Betz 130:770ce14d3d15 351 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data;
Wolfgang Betz 130:770ce14d3d15 352
Wolfgang Betz 130:770ce14d3d15 353 switch(evt->subevent){
Wolfgang Betz 130:770ce14d3d15 354 // ANDREA
Wolfgang Betz 130:770ce14d3d15 355 case EVT_LE_CONN_COMPLETE:
Wolfgang Betz 130:770ce14d3d15 356 {
Wolfgang Betz 130:770ce14d3d15 357 Gap::AddressType_t peerAddrType = Gap::ADDR_TYPE_PUBLIC;
Wolfgang Betz 130:770ce14d3d15 358 DEBUG("EVT_LE_CONN_COMPLETE\n");
Wolfgang Betz 130:770ce14d3d15 359
Wolfgang Betz 130:770ce14d3d15 360 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data;
Wolfgang Betz 130:770ce14d3d15 361
Wolfgang Betz 130:770ce14d3d15 362 BlueNRGGap::getInstance().setConnectionHandle(cc->handle);
Wolfgang Betz 130:770ce14d3d15 363 BlueNRGGap::ConnectionParams_t connectionParams;
Wolfgang Betz 130:770ce14d3d15 364 BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams);
Wolfgang Betz 130:770ce14d3d15 365 switch (cc->peer_bdaddr_type) {
Wolfgang Betz 130:770ce14d3d15 366 case PUBLIC_ADDR:
Wolfgang Betz 130:770ce14d3d15 367 peerAddrType = Gap::ADDR_TYPE_PUBLIC;
Wolfgang Betz 130:770ce14d3d15 368 break;
Wolfgang Betz 130:770ce14d3d15 369 case STATIC_RANDOM_ADDR:
Wolfgang Betz 130:770ce14d3d15 370 peerAddrType = Gap::ADDR_TYPE_RANDOM_STATIC;
Wolfgang Betz 130:770ce14d3d15 371 break;
Wolfgang Betz 130:770ce14d3d15 372 case RESOLVABLE_PRIVATE_ADDR:
Wolfgang Betz 130:770ce14d3d15 373 peerAddrType = Gap::ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
Wolfgang Betz 130:770ce14d3d15 374 break;
Wolfgang Betz 130:770ce14d3d15 375 case NON_RESOLVABLE_PRIVATE_ADDR:
Wolfgang Betz 130:770ce14d3d15 376 peerAddrType = Gap::ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
Wolfgang Betz 130:770ce14d3d15 377 break;
Wolfgang Betz 130:770ce14d3d15 378 }
Wolfgang Betz 130:770ce14d3d15 379 BlueNRGGap::getInstance().processConnectionEvent(cc->handle, Gap::PERIPHERAL, peerAddrType, cc->peer_bdaddr, addr_type, bleAddr, (const BlueNRGGap::ConnectionParams_t *)&connectionParams);
Wolfgang Betz 130:770ce14d3d15 380 }
Wolfgang Betz 130:770ce14d3d15 381 break;
Wolfgang Betz 130:770ce14d3d15 382 }
Wolfgang Betz 130:770ce14d3d15 383 }
Wolfgang Betz 130:770ce14d3d15 384 break;
Wolfgang Betz 130:770ce14d3d15 385
Wolfgang Betz 130:770ce14d3d15 386 case EVT_VENDOR:
Wolfgang Betz 130:770ce14d3d15 387 {
Wolfgang Betz 130:770ce14d3d15 388 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data;
Wolfgang Betz 130:770ce14d3d15 389 //DEBUG("EVT_VENDOR %d\n", blue_evt->ecode);
Wolfgang Betz 130:770ce14d3d15 390
Wolfgang Betz 130:770ce14d3d15 391 switch(blue_evt->ecode){
Wolfgang Betz 130:770ce14d3d15 392
Wolfgang Betz 130:770ce14d3d15 393 case EVT_BLUE_GATT_READ_PERMIT_REQ:
Wolfgang Betz 130:770ce14d3d15 394 {
Wolfgang Betz 130:770ce14d3d15 395 DEBUG("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r");
Wolfgang Betz 130:770ce14d3d15 396 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data;
Wolfgang Betz 130:770ce14d3d15 397 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle-CHAR_VALUE_OFFSET);
Wolfgang Betz 130:770ce14d3d15 398 }
Wolfgang Betz 130:770ce14d3d15 399 break;
Wolfgang Betz 130:770ce14d3d15 400
Wolfgang Betz 130:770ce14d3d15 401 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
Wolfgang Betz 130:770ce14d3d15 402 {
Wolfgang Betz 130:770ce14d3d15 403 DEBUG("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r");
Wolfgang Betz 130:770ce14d3d15 404 /* this callback is invoked when a GATT attribute is modified
Wolfgang Betz 130:770ce14d3d15 405 extract callback data and pass to suitable handler function */
Wolfgang Betz 130:770ce14d3d15 406 if (bnrg_expansion_board == IDB05A1) {
Wolfgang Betz 130:770ce14d3d15 407 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data;
Wolfgang Betz 130:770ce14d3d15 408 Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data, evt->offset);
Wolfgang Betz 130:770ce14d3d15 409 } else {
Wolfgang Betz 130:770ce14d3d15 410 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data;
Wolfgang Betz 130:770ce14d3d15 411 Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data, 0);
Wolfgang Betz 130:770ce14d3d15 412 }
Wolfgang Betz 130:770ce14d3d15 413 }
Wolfgang Betz 130:770ce14d3d15 414 break;
Wolfgang Betz 130:770ce14d3d15 415
Wolfgang Betz 130:770ce14d3d15 416 //Any cases for Data Sent Notifications?
Wolfgang Betz 130:770ce14d3d15 417 case EVT_BLUE_GATT_NOTIFICATION:
Wolfgang Betz 130:770ce14d3d15 418 //This is only relevant for Client Side Event
Wolfgang Betz 130:770ce14d3d15 419 DEBUG("EVT_BLUE_GATT_NOTIFICATION");
Wolfgang Betz 130:770ce14d3d15 420 break;
Wolfgang Betz 130:770ce14d3d15 421 case EVT_BLUE_GATT_INDICATION:
Wolfgang Betz 130:770ce14d3d15 422 //This is only relevant for Client Side Event
Wolfgang Betz 130:770ce14d3d15 423 DEBUG("EVT_BLUE_GATT_INDICATION");
Wolfgang Betz 130:770ce14d3d15 424 break;
Wolfgang Betz 130:770ce14d3d15 425
Wolfgang Betz 130:770ce14d3d15 426 case EVT_BLUE_GATT_PROCEDURE_COMPLETE:
Wolfgang Betz 130:770ce14d3d15 427 DEBUG("EVT_BLUE_GATT_PROCEDURE_COMPLETE");
Wolfgang Betz 130:770ce14d3d15 428 break;
Wolfgang Betz 130:770ce14d3d15 429 }
Wolfgang Betz 130:770ce14d3d15 430 }
Wolfgang Betz 130:770ce14d3d15 431 break;
Wolfgang Betz 130:770ce14d3d15 432 }
Wolfgang Betz 130:770ce14d3d15 433
Wolfgang Betz 130:770ce14d3d15 434 return ;
Wolfgang Betz 130:770ce14d3d15 435 }
Wolfgang Betz 130:770ce14d3d15 436
Wolfgang Betz 130:770ce14d3d15 437
Wolfgang Betz 130:770ce14d3d15 438 #ifdef __cplusplus
Wolfgang Betz 130:770ce14d3d15 439 }
Wolfgang Betz 130:770ce14d3d15 440 #endif