HW layer for the Nucleo board, it only work with old BLE_API
Dependents: Hello_BLE F446RE-BLE
Fork of X_NUCLEO_IDB0XA1 by
platform/src/btle.cpp@64:6d7b775c3f6d, 2014-11-19 (annotated)
- Committer:
- mridup
- Date:
- Wed Nov 19 11:24:37 2014 +0000
- Revision:
- 64:6d7b775c3f6d
- Child:
- 65:f9958b8f2548
Changed directory structure to support STM32Cube BlueNRG module, platform module and BLE_API adaptation module as separate entities. Added Doxygen support to Adaptation and used HCI components.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 64:6d7b775c3f6d | 1 | /* mbed Microcontroller Library |
mridup | 64:6d7b775c3f6d | 2 | * Copyright (c) 2006-2013 ARM Limited |
mridup | 64:6d7b775c3f6d | 3 | * |
mridup | 64:6d7b775c3f6d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mridup | 64:6d7b775c3f6d | 5 | * you may not use this file except in compliance with the License. |
mridup | 64:6d7b775c3f6d | 6 | * You may obtain a copy of the License at |
mridup | 64:6d7b775c3f6d | 7 | * |
mridup | 64:6d7b775c3f6d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mridup | 64:6d7b775c3f6d | 9 | * |
mridup | 64:6d7b775c3f6d | 10 | * Unless required by applicable law or agreed to in writing, software |
mridup | 64:6d7b775c3f6d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mridup | 64:6d7b775c3f6d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mridup | 64:6d7b775c3f6d | 13 | * See the License for the specific language governing permissions and |
mridup | 64:6d7b775c3f6d | 14 | * limitations under the License. |
mridup | 64:6d7b775c3f6d | 15 | */ |
mridup | 64:6d7b775c3f6d | 16 | |
mridup | 64:6d7b775c3f6d | 17 | |
mridup | 64:6d7b775c3f6d | 18 | /** |
mridup | 64:6d7b775c3f6d | 19 | ****************************************************************************** |
mridup | 64:6d7b775c3f6d | 20 | * @file btle.cpp |
mridup | 64:6d7b775c3f6d | 21 | * @author STMicroelectronics |
mridup | 64:6d7b775c3f6d | 22 | * @brief Implementation BlueNRG Init and helper functions. |
mridup | 64:6d7b775c3f6d | 23 | ****************************************************************************** |
mridup | 64:6d7b775c3f6d | 24 | * @copy |
mridup | 64:6d7b775c3f6d | 25 | * |
mridup | 64:6d7b775c3f6d | 26 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
mridup | 64:6d7b775c3f6d | 27 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
mridup | 64:6d7b775c3f6d | 28 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
mridup | 64:6d7b775c3f6d | 29 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
mridup | 64:6d7b775c3f6d | 30 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
mridup | 64:6d7b775c3f6d | 31 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
mridup | 64:6d7b775c3f6d | 32 | * |
mridup | 64:6d7b775c3f6d | 33 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
mridup | 64:6d7b775c3f6d | 34 | */ |
mridup | 64:6d7b775c3f6d | 35 | |
mridup | 64:6d7b775c3f6d | 36 | |
mridup | 64:6d7b775c3f6d | 37 | #include "btle.h" |
mridup | 64:6d7b775c3f6d | 38 | #include "public/Gap.h" |
mridup | 64:6d7b775c3f6d | 39 | #include "public/GapEvents.h" |
mridup | 64:6d7b775c3f6d | 40 | #include "BlueNRGGap.h" |
mridup | 64:6d7b775c3f6d | 41 | #include "BlueNRGGattServer.h" |
mridup | 64:6d7b775c3f6d | 42 | #include "Utils.h" |
mridup | 64:6d7b775c3f6d | 43 | |
mridup | 64:6d7b775c3f6d | 44 | #ifdef __cplusplus |
mridup | 64:6d7b775c3f6d | 45 | extern "C" { |
mridup | 64:6d7b775c3f6d | 46 | #endif |
mridup | 64:6d7b775c3f6d | 47 | |
mridup | 64:6d7b775c3f6d | 48 | |
mridup | 64:6d7b775c3f6d | 49 | /* C File Includes ------------------------------------------------------------------*/ |
mridup | 64:6d7b775c3f6d | 50 | #include "hal_types.h" |
mridup | 64:6d7b775c3f6d | 51 | #include "hci.h" |
mridup | 64:6d7b775c3f6d | 52 | #include "bluenrg_hci.h" |
mridup | 64:6d7b775c3f6d | 53 | #include "gp_timer.h" |
mridup | 64:6d7b775c3f6d | 54 | #include "hal.h" |
mridup | 64:6d7b775c3f6d | 55 | #include "osal.h" |
mridup | 64:6d7b775c3f6d | 56 | #include "hci_internal.h" |
mridup | 64:6d7b775c3f6d | 57 | #include "bluenrg_hci_internal.h" |
mridup | 64:6d7b775c3f6d | 58 | #include "bluenrg_gap.h" |
mridup | 64:6d7b775c3f6d | 59 | #include "sm.h" |
mridup | 64:6d7b775c3f6d | 60 | #include <stdio.h> |
mridup | 64:6d7b775c3f6d | 61 | #include <string.h> |
mridup | 64:6d7b775c3f6d | 62 | //#include "role_type.h" |
mridup | 64:6d7b775c3f6d | 63 | #include "debug.h" |
mridup | 64:6d7b775c3f6d | 64 | |
mridup | 64:6d7b775c3f6d | 65 | #ifdef __cplusplus |
mridup | 64:6d7b775c3f6d | 66 | } |
mridup | 64:6d7b775c3f6d | 67 | #endif |
mridup | 64:6d7b775c3f6d | 68 | |
mridup | 64:6d7b775c3f6d | 69 | |
mridup | 64:6d7b775c3f6d | 70 | static void btle_handler(/*ble_evt_t * p_ble_evt*/); |
mridup | 64:6d7b775c3f6d | 71 | void HCI_Input(tHciDataPacket * hciReadPacket); |
mridup | 64:6d7b775c3f6d | 72 | |
mridup | 64:6d7b775c3f6d | 73 | //#define BDADDR_SIZE 6 |
mridup | 64:6d7b775c3f6d | 74 | //tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02}; |
mridup | 64:6d7b775c3f6d | 75 | |
mridup | 64:6d7b775c3f6d | 76 | uint16_t g_gap_service_handle = 0; |
mridup | 64:6d7b775c3f6d | 77 | uint16_t g_appearance_char_handle = 0; |
mridup | 64:6d7b775c3f6d | 78 | uint16_t g_device_name_char_handle = 0; |
mridup | 64:6d7b775c3f6d | 79 | |
mridup | 64:6d7b775c3f6d | 80 | /* Private variables ---------------------------------------------------------*/ |
mridup | 64:6d7b775c3f6d | 81 | volatile uint8_t set_connectable = 1; |
mridup | 64:6d7b775c3f6d | 82 | |
mridup | 64:6d7b775c3f6d | 83 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 84 | /*! |
mridup | 64:6d7b775c3f6d | 85 | @brief Initialises BTLE and the underlying HW/Device |
mridup | 64:6d7b775c3f6d | 86 | @param isSetAddress boolean if address has been set |
mridup | 64:6d7b775c3f6d | 87 | @param mosi MOSI Pin |
mridup | 64:6d7b775c3f6d | 88 | @param miso MISO Pin |
mridup | 64:6d7b775c3f6d | 89 | @param sclk clock Pin |
mridup | 64:6d7b775c3f6d | 90 | @returns void |
mridup | 64:6d7b775c3f6d | 91 | */ |
mridup | 64:6d7b775c3f6d | 92 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 93 | void btle_init(bool isSetAddress, PinName mosi, PinName miso, PinName sclk) |
mridup | 64:6d7b775c3f6d | 94 | { |
mridup | 64:6d7b775c3f6d | 95 | DEBUG("btle_init>>\n\r"); |
mridup | 64:6d7b775c3f6d | 96 | tHalUint8 *bleAddr; |
mridup | 64:6d7b775c3f6d | 97 | int ret; |
mridup | 64:6d7b775c3f6d | 98 | uint16_t service_handle, dev_name_char_handle, appearance_char_handle; |
mridup | 64:6d7b775c3f6d | 99 | |
mridup | 64:6d7b775c3f6d | 100 | //HAL_Init(); |
mridup | 64:6d7b775c3f6d | 101 | |
mridup | 64:6d7b775c3f6d | 102 | /* Configure the User Button in GPIO Mode */ |
mridup | 64:6d7b775c3f6d | 103 | //BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); |
mridup | 64:6d7b775c3f6d | 104 | |
mridup | 64:6d7b775c3f6d | 105 | /* Configure the system clock */ |
mridup | 64:6d7b775c3f6d | 106 | //SystemClock_Config(); |
mridup | 64:6d7b775c3f6d | 107 | |
mridup | 64:6d7b775c3f6d | 108 | /* Delay needed only to be able to acces the JTAG interface after reset |
mridup | 64:6d7b775c3f6d | 109 | if it will be disabled later. */ |
mridup | 64:6d7b775c3f6d | 110 | Clock_Wait(500); |
mridup | 64:6d7b775c3f6d | 111 | |
mridup | 64:6d7b775c3f6d | 112 | /* Initialize the BlueNRG SPI driver */ |
mridup | 64:6d7b775c3f6d | 113 | BNRG_SPI_Init(D11, D12, D3); |
mridup | 64:6d7b775c3f6d | 114 | |
mridup | 64:6d7b775c3f6d | 115 | /* Initialize the BlueNRG HCI */ |
mridup | 64:6d7b775c3f6d | 116 | HCI_Init(); |
mridup | 64:6d7b775c3f6d | 117 | |
mridup | 64:6d7b775c3f6d | 118 | /* Reset BlueNRG SPI interface */ |
mridup | 64:6d7b775c3f6d | 119 | BlueNRG_RST(); |
mridup | 64:6d7b775c3f6d | 120 | |
mridup | 64:6d7b775c3f6d | 121 | /* The Nucleo board must be configured as SERVER */ |
mridup | 64:6d7b775c3f6d | 122 | //check if issetAddress is set than set address. |
mridup | 64:6d7b775c3f6d | 123 | if(isSetAddress) |
mridup | 64:6d7b775c3f6d | 124 | { |
mridup | 64:6d7b775c3f6d | 125 | bleAddr = BlueNRGGap::getInstance().getAddress(); |
mridup | 64:6d7b775c3f6d | 126 | |
mridup | 64:6d7b775c3f6d | 127 | tHalUint8 bdaddr[BDADDR_SIZE]; |
mridup | 64:6d7b775c3f6d | 128 | Osal_MemCpy(bdaddr, bleAddr, BDADDR_SIZE); |
mridup | 64:6d7b775c3f6d | 129 | |
mridup | 64:6d7b775c3f6d | 130 | ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, |
mridup | 64:6d7b775c3f6d | 131 | CONFIG_DATA_PUBADDR_LEN, |
mridup | 64:6d7b775c3f6d | 132 | bdaddr); |
mridup | 64:6d7b775c3f6d | 133 | } |
mridup | 64:6d7b775c3f6d | 134 | |
mridup | 64:6d7b775c3f6d | 135 | ret = aci_gatt_init(); |
mridup | 64:6d7b775c3f6d | 136 | //GAP is always in PERIPHERAL _ROLE as mbed does not support Master role at the moment |
mridup | 64:6d7b775c3f6d | 137 | ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, &dev_name_char_handle, &appearance_char_handle); |
mridup | 64:6d7b775c3f6d | 138 | |
mridup | 64:6d7b775c3f6d | 139 | g_gap_service_handle = service_handle; |
mridup | 64:6d7b775c3f6d | 140 | g_appearance_char_handle = appearance_char_handle; |
mridup | 64:6d7b775c3f6d | 141 | g_device_name_char_handle = dev_name_char_handle; |
mridup | 64:6d7b775c3f6d | 142 | //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API |
mridup | 64:6d7b775c3f6d | 143 | /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, |
mridup | 64:6d7b775c3f6d | 144 | strlen(name), (tHalUint8 *)name);*/ |
mridup | 64:6d7b775c3f6d | 145 | |
mridup | 64:6d7b775c3f6d | 146 | return; |
mridup | 64:6d7b775c3f6d | 147 | } |
mridup | 64:6d7b775c3f6d | 148 | |
mridup | 64:6d7b775c3f6d | 149 | void User_Process() |
mridup | 64:6d7b775c3f6d | 150 | { |
mridup | 64:6d7b775c3f6d | 151 | if(set_connectable){ |
mridup | 64:6d7b775c3f6d | 152 | setConnectable(); |
mridup | 64:6d7b775c3f6d | 153 | set_connectable = FALSE; |
mridup | 64:6d7b775c3f6d | 154 | } |
mridup | 64:6d7b775c3f6d | 155 | } |
mridup | 64:6d7b775c3f6d | 156 | |
mridup | 64:6d7b775c3f6d | 157 | void setConnectable(void) |
mridup | 64:6d7b775c3f6d | 158 | { |
mridup | 64:6d7b775c3f6d | 159 | tBleStatus ret; |
mridup | 64:6d7b775c3f6d | 160 | |
mridup | 64:6d7b775c3f6d | 161 | const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G', '1', '2'}; |
mridup | 64:6d7b775c3f6d | 162 | |
mridup | 64:6d7b775c3f6d | 163 | /* disable scan response */ |
mridup | 64:6d7b775c3f6d | 164 | hci_le_set_scan_resp_data(0,NULL); |
mridup | 64:6d7b775c3f6d | 165 | |
mridup | 64:6d7b775c3f6d | 166 | |
mridup | 64:6d7b775c3f6d | 167 | ret = aci_gap_set_discoverable(ADV_IND, 0, 0, PUBLIC_ADDR, NO_WHITE_LIST_USE, |
mridup | 64:6d7b775c3f6d | 168 | 8, local_name, 0, NULL, 0, 0); |
mridup | 64:6d7b775c3f6d | 169 | |
mridup | 64:6d7b775c3f6d | 170 | } |
mridup | 64:6d7b775c3f6d | 171 | |
mridup | 64:6d7b775c3f6d | 172 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 173 | /*! |
mridup | 64:6d7b775c3f6d | 174 | @brief Not Used |
mridup | 64:6d7b775c3f6d | 175 | |
mridup | 64:6d7b775c3f6d | 176 | @param[in] void |
mridup | 64:6d7b775c3f6d | 177 | |
mridup | 64:6d7b775c3f6d | 178 | @returns |
mridup | 64:6d7b775c3f6d | 179 | */ |
mridup | 64:6d7b775c3f6d | 180 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 181 | static void btle_handler() |
mridup | 64:6d7b775c3f6d | 182 | { |
mridup | 64:6d7b775c3f6d | 183 | |
mridup | 64:6d7b775c3f6d | 184 | } |
mridup | 64:6d7b775c3f6d | 185 | |
mridup | 64:6d7b775c3f6d | 186 | /*! |
mridup | 64:6d7b775c3f6d | 187 | @brief Not Used |
mridup | 64:6d7b775c3f6d | 188 | |
mridup | 64:6d7b775c3f6d | 189 | @param[in] void |
mridup | 64:6d7b775c3f6d | 190 | |
mridup | 64:6d7b775c3f6d | 191 | @returns |
mridup | 64:6d7b775c3f6d | 192 | */ |
mridup | 64:6d7b775c3f6d | 193 | void SPI_Poll(void) |
mridup | 64:6d7b775c3f6d | 194 | { |
mridup | 64:6d7b775c3f6d | 195 | //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); |
mridup | 64:6d7b775c3f6d | 196 | return; |
mridup | 64:6d7b775c3f6d | 197 | } |
mridup | 64:6d7b775c3f6d | 198 | |
mridup | 64:6d7b775c3f6d | 199 | #ifdef __cplusplus |
mridup | 64:6d7b775c3f6d | 200 | extern "C" { |
mridup | 64:6d7b775c3f6d | 201 | #endif |
mridup | 64:6d7b775c3f6d | 202 | |
mridup | 64:6d7b775c3f6d | 203 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 204 | /*! |
mridup | 64:6d7b775c3f6d | 205 | @brief Handle HCI Stack Event |
mridup | 64:6d7b775c3f6d | 206 | |
mridup | 64:6d7b775c3f6d | 207 | @param[in] pckt |
mridup | 64:6d7b775c3f6d | 208 | Event Packet sent by the stack to be decoded |
mridup | 64:6d7b775c3f6d | 209 | |
mridup | 64:6d7b775c3f6d | 210 | @returns |
mridup | 64:6d7b775c3f6d | 211 | */ |
mridup | 64:6d7b775c3f6d | 212 | /**************************************************************************/ |
mridup | 64:6d7b775c3f6d | 213 | extern void HCI_Event_CB(void *pckt) { |
mridup | 64:6d7b775c3f6d | 214 | |
mridup | 64:6d7b775c3f6d | 215 | hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; |
mridup | 64:6d7b775c3f6d | 216 | hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; |
mridup | 64:6d7b775c3f6d | 217 | |
mridup | 64:6d7b775c3f6d | 218 | if(hci_pckt->type != HCI_EVENT_PKT) |
mridup | 64:6d7b775c3f6d | 219 | return; |
mridup | 64:6d7b775c3f6d | 220 | |
mridup | 64:6d7b775c3f6d | 221 | switch(event_pckt->evt){ |
mridup | 64:6d7b775c3f6d | 222 | |
mridup | 64:6d7b775c3f6d | 223 | case EVT_DISCONN_COMPLETE: |
mridup | 64:6d7b775c3f6d | 224 | { |
mridup | 64:6d7b775c3f6d | 225 | evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt; |
mridup | 64:6d7b775c3f6d | 226 | |
mridup | 64:6d7b775c3f6d | 227 | BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, BlueNRGGap::REMOTE_USER_TERMINATED_CONNECTION); |
mridup | 64:6d7b775c3f6d | 228 | } |
mridup | 64:6d7b775c3f6d | 229 | break; |
mridup | 64:6d7b775c3f6d | 230 | |
mridup | 64:6d7b775c3f6d | 231 | case EVT_LE_META_EVENT: |
mridup | 64:6d7b775c3f6d | 232 | { |
mridup | 64:6d7b775c3f6d | 233 | evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; |
mridup | 64:6d7b775c3f6d | 234 | |
mridup | 64:6d7b775c3f6d | 235 | switch(evt->subevent){ |
mridup | 64:6d7b775c3f6d | 236 | case EVT_LE_CONN_COMPLETE: |
mridup | 64:6d7b775c3f6d | 237 | { |
mridup | 64:6d7b775c3f6d | 238 | evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; |
mridup | 64:6d7b775c3f6d | 239 | |
mridup | 64:6d7b775c3f6d | 240 | BlueNRGGap::getInstance().setConnectionHandle(cc->handle); |
mridup | 64:6d7b775c3f6d | 241 | BlueNRGGap::ConnectionParams_t connectionParams; |
mridup | 64:6d7b775c3f6d | 242 | BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams); |
mridup | 64:6d7b775c3f6d | 243 | BlueNRGGap::getInstance().processConnectionEvent(cc->handle, (const BlueNRGGap::ConnectionParams_t *)&connectionParams); |
mridup | 64:6d7b775c3f6d | 244 | } |
mridup | 64:6d7b775c3f6d | 245 | break; |
mridup | 64:6d7b775c3f6d | 246 | } |
mridup | 64:6d7b775c3f6d | 247 | } |
mridup | 64:6d7b775c3f6d | 248 | break; |
mridup | 64:6d7b775c3f6d | 249 | |
mridup | 64:6d7b775c3f6d | 250 | case EVT_VENDOR: |
mridup | 64:6d7b775c3f6d | 251 | { |
mridup | 64:6d7b775c3f6d | 252 | evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; |
mridup | 64:6d7b775c3f6d | 253 | switch(blue_evt->ecode){ |
mridup | 64:6d7b775c3f6d | 254 | |
mridup | 64:6d7b775c3f6d | 255 | case EVT_BLUE_GATT_READ_PERMIT_REQ: |
mridup | 64:6d7b775c3f6d | 256 | { |
mridup | 64:6d7b775c3f6d | 257 | DEBUG("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); |
mridup | 64:6d7b775c3f6d | 258 | evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; |
mridup | 64:6d7b775c3f6d | 259 | BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle); |
mridup | 64:6d7b775c3f6d | 260 | } |
mridup | 64:6d7b775c3f6d | 261 | break; |
mridup | 64:6d7b775c3f6d | 262 | |
mridup | 64:6d7b775c3f6d | 263 | case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: |
mridup | 64:6d7b775c3f6d | 264 | { |
mridup | 64:6d7b775c3f6d | 265 | /* this callback is invoked when a GATT attribute is modified |
mridup | 64:6d7b775c3f6d | 266 | extract callback data and pass to suitable handler function */ |
mridup | 64:6d7b775c3f6d | 267 | evt_gatt_attr_modified *evt = (evt_gatt_attr_modified*)blue_evt->data; |
mridup | 64:6d7b775c3f6d | 268 | DEBUG("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); |
mridup | 64:6d7b775c3f6d | 269 | //DEBUG("CharHandle 0x%x, length: 0x%x, Data: 0x%x\n\r",evt->attr_handle, evt->data_length, (uint16_t)evt->att_data[0]); |
mridup | 64:6d7b775c3f6d | 270 | DEBUG("CharHandle %d, length: %d, Data: %d\n\r",evt->attr_handle, evt->data_length, (uint16_t)evt->att_data[0]); |
mridup | 64:6d7b775c3f6d | 271 | |
mridup | 64:6d7b775c3f6d | 272 | //Extract the GattCharacteristic from p_characteristics[] and find the properties mask |
mridup | 64:6d7b775c3f6d | 273 | GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(evt->attr_handle); |
mridup | 64:6d7b775c3f6d | 274 | if(p_char!=NULL) { |
mridup | 64:6d7b775c3f6d | 275 | DEBUG("getProperties 0x%x\n\r",p_char->getProperties()); |
mridup | 64:6d7b775c3f6d | 276 | if((p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
mridup | 64:6d7b775c3f6d | 277 | | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) { |
mridup | 64:6d7b775c3f6d | 278 | |
mridup | 64:6d7b775c3f6d | 279 | //Now Check if data written in Enable or Disable |
mridup | 64:6d7b775c3f6d | 280 | if((uint16_t)evt->att_data[0]==1) { |
mridup | 64:6d7b775c3f6d | 281 | //DEBUG("Notify ENABLED\n\r"); |
mridup | 64:6d7b775c3f6d | 282 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, evt->attr_handle); |
mridup | 64:6d7b775c3f6d | 283 | } |
mridup | 64:6d7b775c3f6d | 284 | else { |
mridup | 64:6d7b775c3f6d | 285 | //DEBUG("Notify DISABLED\n\r"); |
mridup | 64:6d7b775c3f6d | 286 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, evt->attr_handle); |
mridup | 64:6d7b775c3f6d | 287 | } |
mridup | 64:6d7b775c3f6d | 288 | } |
mridup | 64:6d7b775c3f6d | 289 | |
mridup | 64:6d7b775c3f6d | 290 | //Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event |
mridup | 64:6d7b775c3f6d | 291 | if((p_char->getProperties() & |
mridup | 64:6d7b775c3f6d | 292 | (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE| |
mridup | 64:6d7b775c3f6d | 293 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE))) { |
mridup | 64:6d7b775c3f6d | 294 | |
mridup | 64:6d7b775c3f6d | 295 | BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle); |
mridup | 64:6d7b775c3f6d | 296 | //Write the actual Data to the Attr Handle? (uint8_1[])evt->att_data contains the data |
mridup | 64:6d7b775c3f6d | 297 | if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() > 0)) { |
mridup | 64:6d7b775c3f6d | 298 | BlueNRGGattServer::getInstance().updateValue(p_char->getValueAttribute().getHandle(), |
mridup | 64:6d7b775c3f6d | 299 | p_char->getValueAttribute().getValuePtr(), p_char->getValueAttribute().getInitialLength(), false /* localOnly */); |
mridup | 64:6d7b775c3f6d | 300 | } |
mridup | 64:6d7b775c3f6d | 301 | } |
mridup | 64:6d7b775c3f6d | 302 | } |
mridup | 64:6d7b775c3f6d | 303 | } |
mridup | 64:6d7b775c3f6d | 304 | break; |
mridup | 64:6d7b775c3f6d | 305 | |
mridup | 64:6d7b775c3f6d | 306 | //Any cases for Data Sent Notifications? |
mridup | 64:6d7b775c3f6d | 307 | case EVT_BLUE_GATT_NOTIFICATION: |
mridup | 64:6d7b775c3f6d | 308 | //This is only relevant for Client Side Event |
mridup | 64:6d7b775c3f6d | 309 | DEBUG("EVT_BLUE_GATT_NOTIFICATION"); |
mridup | 64:6d7b775c3f6d | 310 | break; |
mridup | 64:6d7b775c3f6d | 311 | case EVT_BLUE_GATT_INDICATION: |
mridup | 64:6d7b775c3f6d | 312 | //This is only relevant for Client Side Event |
mridup | 64:6d7b775c3f6d | 313 | DEBUG("EVT_BLUE_GATT_INDICATION"); |
mridup | 64:6d7b775c3f6d | 314 | break; |
mridup | 64:6d7b775c3f6d | 315 | |
mridup | 64:6d7b775c3f6d | 316 | case EVT_BLUE_GATT_PROCEDURE_COMPLETE: |
mridup | 64:6d7b775c3f6d | 317 | DEBUG("EVT_BLUE_GATT_PROCEDURE_COMPLETE"); |
mridup | 64:6d7b775c3f6d | 318 | break; |
mridup | 64:6d7b775c3f6d | 319 | } |
mridup | 64:6d7b775c3f6d | 320 | } |
mridup | 64:6d7b775c3f6d | 321 | break; |
mridup | 64:6d7b775c3f6d | 322 | } |
mridup | 64:6d7b775c3f6d | 323 | |
mridup | 64:6d7b775c3f6d | 324 | return ; |
mridup | 64:6d7b775c3f6d | 325 | } |
mridup | 64:6d7b775c3f6d | 326 | |
mridup | 64:6d7b775c3f6d | 327 | |
mridup | 64:6d7b775c3f6d | 328 | #ifdef __cplusplus |
mridup | 64:6d7b775c3f6d | 329 | } |
mridup | 64:6d7b775c3f6d | 330 | #endif |