Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_IDB0XA1 by
btle.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 00018 /** 00019 ****************************************************************************** 00020 * @file btle.cpp 00021 * @author STMicroelectronics 00022 * @brief Implementation BlueNRG Init and helper functions. 00023 ****************************************************************************** 00024 * @copy 00025 * 00026 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00027 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00028 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00029 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00030 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00031 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00032 * 00033 * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> 00034 */ 00035 00036 00037 #include "btle.h" 00038 #include "ble/Gap.h" 00039 #include "ble/GapEvents.h" 00040 #include "BlueNRGGap.h" 00041 #include "BlueNRGGattServer.h" 00042 #include "BlueNRGGattClient.h" 00043 #include "Utils.h" 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 00050 /* C File Includes ------------------------------------------------------------------*/ 00051 #include <stdio.h> 00052 #include <string.h> 00053 #include "hci.h" 00054 #include "hci_const.h" 00055 #include "bluenrg_aci.h" 00056 #include "bluenrg_hal_aci.h" 00057 #include "bluenrg_gap.h" 00058 #include "bluenrg_utils.h" 00059 00060 #include "hal_types.h" 00061 #include "hal.h" 00062 #include "gp_timer.h" 00063 #include "osal.h" 00064 #include "sm.h" 00065 #include "debug.h" 00066 00067 #ifdef __cplusplus 00068 } 00069 #endif 00070 00071 #define IDB04A1 0 00072 #define IDB05A1 1 00073 00074 // Stack Mode 0x04 allows Simultaneous Scanning and Advertisement (SSAdv) 00075 #define STACK_MODE (0x04) 00076 00077 void HCI_Input(tHciDataPacket * hciReadPacket); 00078 00079 uint16_t g_gap_service_handle = 0; 00080 uint16_t g_appearance_char_handle = 0; 00081 uint16_t g_device_name_char_handle = 0; 00082 00083 /* Private variables ---------------------------------------------------------*/ 00084 volatile uint8_t set_connectable = 1; 00085 00086 static char versionString[32]; 00087 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */ 00088 00089 /**************************************************************************/ 00090 /*! 00091 @brief Prepare communication between the host and the BTLE HW device 00092 @returns void 00093 */ 00094 /**************************************************************************/ 00095 void btleInitHW(void) 00096 { 00097 PRINTF("btleInitHW>>\n\r"); 00098 00099 /* Delay needed only to be able to acces the JTAG interface after reset 00100 if it will be disabled later. */ 00101 //Clock_Wait(500); FIXME: // check if I can remove this 00102 00103 /* Initialize the BlueNRG HCI */ 00104 HCI_Init(); 00105 } 00106 00107 /**************************************************************************/ 00108 /*! 00109 * @brief Flash a new firmware using internal bootloader. 00110 * @param fw_image Pointer to the firmware image (raw binary data, 00111 * little-endian). 00112 * @param fw_size Size of the firmware image. The firmware image size shall 00113 * be multiple of 4 bytes. 00114 * @retval int It returns 0 if successful, or a number not equal to 0 in 00115 * case of error (ACI_ERROR, UNSUPPORTED_VERSION, 00116 * WRONG_IMAGE_SIZE, CRC_ERROR) 00117 */ 00118 /**************************************************************************/ 00119 00120 int btleUpdateFirmware(const uint8_t *fw_image, uint32_t fw_size) 00121 { 00122 int status = program_device(fw_image, fw_size); 00123 00124 return (status); 00125 } 00126 00127 /**************************************************************************/ 00128 /*! 00129 * @brief Get BlueNRG HW updater version 00130 * @param version This parameter returns the updater HW version. 00131 * @retval Status of the call 00132 */ 00133 /**************************************************************************/ 00134 uint8_t btleGetUpdaterHWVersion(uint8_t *upd_hw_version) 00135 { 00136 uint8_t status; 00137 00138 status = getBlueNRGUpdaterHWVersion(upd_hw_version); 00139 00140 return (status); 00141 } 00142 00143 00144 /**************************************************************************/ 00145 /*! 00146 @brief Start the BTLE stack with the specified role 00147 @param isSetAddress boolean if address has been set 00148 @param role The device role 00149 @returns void 00150 */ 00151 /**************************************************************************/ 00152 void btleStart(bool isSetAddress, uint8_t role) 00153 { 00154 /* Avoid compiler warnings about unused variables. */ 00155 (void)isSetAddress; 00156 00157 int ret; 00158 uint8_t hwVersion; 00159 uint16_t fwVersion; 00160 uint16_t service_handle, dev_name_char_handle, appearance_char_handle; 00161 00162 /* Reset BlueNRG SPI interface */ 00163 BlueNRG_RST(); 00164 00165 /* get the BlueNRG HW and FW versions */ 00166 getBlueNRGVersion(&hwVersion, &fwVersion); 00167 00168 /* 00169 * Reset BlueNRG again otherwise we won't 00170 * be able to change its MAC address. 00171 * aci_hal_write_config_data() must be the first 00172 * command after reset otherwise it will fail. 00173 */ 00174 BlueNRG_RST(); 00175 00176 if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ 00177 bnrg_expansion_board = IDB05A1; 00178 } 00179 00180 /* set BLE version string */ 00181 setVersionString(hwVersion, fwVersion); 00182 00183 if (bnrg_expansion_board == IDB05A1) { 00184 uint8_t stackMode = STACK_MODE; 00185 ret = aci_hal_write_config_data(CONFIG_DATA_ROLE, 00186 CONFIG_DATA_ROLE_LEN, 00187 &stackMode); 00188 } 00189 00190 /* The Nucleo board must be configured as SERVER */ 00191 //check if isSetAddress is set then set address. 00192 #if 0 00193 if(isSetAddress) 00194 { 00195 Gap::Address_t bleAddr; 00196 Gap::AddressType_t addr_type; 00197 00198 BlueNRGGap::getInstance().getAddress(&addr_type, bleAddr); 00199 00200 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, 00201 CONFIG_DATA_PUBADDR_LEN, 00202 bleAddr); 00203 } else { 00204 00205 const Gap::Address_t BLE_address_BE = {0xFD,0x66,0x05,0x13,0xBE,0xBA}; 00206 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE); 00207 00208 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, 00209 CONFIG_DATA_PUBADDR_LEN, 00210 BLE_address_BE); 00211 } 00212 #endif 00213 00214 const Gap::Address_t BLE_address_BE = {0xFD,0x66,0x05,0x13,0xBE,0xBA}; 00215 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE); 00216 00217 ret = aci_gatt_init(); 00218 if(ret){ 00219 PRINTF("GATT_Init failed.\n"); 00220 } 00221 if (bnrg_expansion_board == IDB05A1) { 00222 ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1|GAP_OBSERVER_ROLE_IDB05A1, 00223 0, 00224 0x18, 00225 &service_handle, 00226 &dev_name_char_handle, 00227 &appearance_char_handle); 00228 } else { 00229 ret = aci_gap_init_IDB04A1(role, &service_handle, &dev_name_char_handle, &appearance_char_handle); 00230 } 00231 00232 if(ret != BLE_STATUS_SUCCESS){ 00233 PRINTF("GAP_Init failed.\n"); 00234 } 00235 00236 //FIXME: Security and passkey set by default 00237 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, 00238 OOB_AUTH_DATA_ABSENT, 00239 NULL, 00240 7, 00241 16, 00242 USE_FIXED_PIN_FOR_PAIRING, 00243 123456, 00244 BONDING); 00245 if (ret == BLE_STATUS_SUCCESS) { 00246 PRINTF("Auth Req set successfully.\n"); 00247 } 00248 00249 aci_hal_set_tx_power_level(1,4); 00250 00251 g_gap_service_handle = service_handle; 00252 g_appearance_char_handle = appearance_char_handle; 00253 g_device_name_char_handle = dev_name_char_handle; 00254 //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API 00255 /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, 00256 strlen(name), (tHalUint8 *)name);*/ 00257 00258 #ifdef AST_FOR_MBED_OS 00259 minar::Scheduler::postCallback(btle_handler); 00260 #endif 00261 return; 00262 } 00263 00264 /**************************************************************************/ 00265 /*! 00266 @brief mbedOS 00267 00268 @param[in] void 00269 00270 @returns 00271 */ 00272 /**************************************************************************/ 00273 #ifdef AST_FOR_MBED_OS 00274 int btle_handler_pending = 0; 00275 00276 void btle_handler(void) 00277 { 00278 btle_handler_pending = 0; 00279 HCI_Process(); 00280 } 00281 #endif 00282 00283 /* set BLE Version string */ 00284 void setVersionString(uint8_t hwVersion, uint16_t fwVersion) 00285 { 00286 if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) { 00287 snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u", 00288 hwVersion>>4, (hwVersion&0x0F), 00289 fwVersion>>8, (fwVersion&0x00F0)>>4); 00290 } else { 00291 snprintf(versionString, sizeof(versionString), "ST (unknown spec)"); 00292 } 00293 } 00294 00295 /* get BLE Version string */ 00296 const char* getVersionString(void) 00297 { 00298 return versionString; 00299 } 00300 00301 tBleStatus btleStartRadioScan(uint8_t scan_type, 00302 uint16_t scan_interval, 00303 uint16_t scan_window, 00304 uint8_t own_address_type) 00305 { 00306 tBleStatus ret; 00307 00308 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED 00309 if(bnrg_expansion_board == IDB05A1) { 00310 PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window); 00311 PRINTF("scan_type=%d own_address_type=%d\n\r", scan_type, own_address_type); 00312 ret = aci_gap_start_observation_procedure(scan_interval, 00313 scan_window, 00314 scan_type, 00315 own_address_type, 00316 0); // 1 to filter duplicates 00317 } else { 00318 ret = BLE_STATUS_INVALID_CID; 00319 } 00320 00321 return ret; 00322 00323 } 00324 00325 /*! 00326 @brief Not Used 00327 00328 @param[in] void 00329 00330 @returns 00331 */ 00332 void SPI_Poll(void) 00333 { 00334 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); 00335 return; 00336 } 00337 00338 void Attribute_Modified_CB(evt_blue_aci *blue_evt) 00339 { 00340 uint16_t conn_handle; 00341 uint16_t attr_handle; 00342 uint8_t data_length; 00343 uint8_t *att_data; 00344 uint8_t offset; 00345 00346 if (bnrg_expansion_board == IDB05A1) { 00347 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data; 00348 conn_handle = evt->conn_handle; 00349 attr_handle = evt->attr_handle; 00350 data_length = evt->data_length; 00351 att_data = evt->att_data; 00352 offset = evt->offset; 00353 } else { 00354 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data; 00355 conn_handle = evt->conn_handle; 00356 attr_handle = evt->attr_handle; 00357 data_length = evt->data_length; 00358 att_data = evt->att_data; 00359 offset = 0; 00360 } 00361 00362 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask 00363 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle); 00364 if(p_char!=NULL) { 00365 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE; 00366 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE; 00367 PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]); 00368 PRINTF("getProperties 0x%x\n\r",p_char->getProperties()); 00369 00370 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_VALUE_HANDLE) { 00371 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE; 00372 } 00373 00374 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_DESC_HANDLE) { 00375 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE; 00376 } 00377 PRINTF("currentHandle %d\n\r", currentHandle); 00378 if((p_char->getProperties() & 00379 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) && 00380 currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) { 00381 00382 GattAttribute::Handle_t charDescHandle = p_char->getValueAttribute().getHandle()+1; 00383 00384 PRINTF("*****NOTIFICATION CASE\n\r"); 00385 //Now Check if data written in Enable or Disable 00386 if((uint16_t)att_data[0]==1) { 00387 //PRINTF("Notify ENABLED\n\r"); 00388 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, charDescHandle); 00389 } else { 00390 //PRINTF("Notify DISABLED\n\r"); 00391 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, charDescHandle); 00392 } 00393 } 00394 00395 //Check if attr handle property is WRITEABLE, in the case generate GATT_EVENT_DATA_WRITTEN Event 00396 if((p_char->getProperties() & 00397 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) && 00398 currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) { 00399 00400 PRINTF("*****WRITE CASE\n\r"); 00401 00402 GattWriteCallbackParams writeParams; 00403 writeParams.connHandle = conn_handle; 00404 writeParams.handle = p_char->getValueAttribute().getHandle(); 00405 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? 00406 writeParams.len = data_length; 00407 writeParams.data = att_data; 00408 writeParams.offset = offset; 00409 00410 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); 00411 00412 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, attr_handle); 00413 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data 00414 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) { 00415 BlueNRGGattServer::getInstance().write(p_char->getValueAttribute().getHandle(), 00416 (uint8_t*)att_data, 00417 data_length, 00418 false); 00419 } 00420 } 00421 } 00422 00423 } 00424 00425 #ifdef __cplusplus 00426 extern "C" { 00427 #endif 00428 00429 /**************************************************************************/ 00430 /*! 00431 @brief Handle HCI Stack Event 00432 00433 @param[in] pckt 00434 Event Packet sent by the stack to be decoded 00435 00436 @returns 00437 */ 00438 /**************************************************************************/ 00439 extern void HCI_Event_CB(void *pckt) { 00440 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; 00441 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; 00442 00443 if(hci_pckt->type != HCI_EVENT_PKT) 00444 return; 00445 00446 switch(event_pckt->evt){ 00447 00448 case EVT_DISCONN_COMPLETE: 00449 { 00450 PRINTF("EVT_DISCONN_COMPLETE\n"); 00451 00452 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt->data; 00453 00454 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, (Gap::DisconnectionReason_t)evt->reason); 00455 } 00456 break; 00457 00458 case EVT_LE_META_EVENT: 00459 { 00460 PRINTF("EVT_LE_META_EVENT\n"); 00461 00462 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; 00463 00464 switch(evt->subevent){ 00465 00466 case EVT_LE_CONN_COMPLETE: 00467 { 00468 PRINTF("EVT_LE_CONN_COMPLETE\n"); 00469 Gap::Address_t ownAddr; 00470 Gap::AddressType_t ownAddrType; 00471 BlueNRGGap::getInstance().getAddress(&ownAddrType, ownAddr); 00472 00473 Gap::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00474 Gap::Role_t role; 00475 00476 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; 00477 00478 BlueNRGGap::getInstance().setConnectionHandle(cc->handle); 00479 BlueNRGGap::ConnectionParams_t connectionParams; 00480 BlueNRGGap::getInstance().getPreferredConnectionParams(&connectionParams); 00481 switch (cc->peer_bdaddr_type) { 00482 case PUBLIC_ADDR: 00483 peerAddrType = BLEProtocol::AddressType::PUBLIC; 00484 break; 00485 case STATIC_RANDOM_ADDR: 00486 peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00487 break; 00488 case RESOLVABLE_PRIVATE_ADDR: 00489 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE; 00490 break; 00491 case NON_RESOLVABLE_PRIVATE_ADDR: 00492 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE; 00493 break; 00494 } 00495 //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role); 00496 switch (cc->role) { 00497 case 0: //master 00498 role = Gap::CENTRAL; 00499 break; 00500 case 1: 00501 role = Gap::PERIPHERAL; 00502 break; 00503 default: 00504 role = Gap::PERIPHERAL; 00505 break; 00506 } 00507 //PRINTF("EVT_LE_CONN_COMPLETE GAP role=%d\n", role); 00508 BlueNRGGap::getInstance().processConnectionEvent(cc->handle, 00509 role, 00510 peerAddrType, 00511 cc->peer_bdaddr, 00512 ownAddrType, 00513 ownAddr, 00514 &connectionParams); 00515 } 00516 break; 00517 00518 case EVT_LE_ADVERTISING_REPORT: 00519 PRINTF("EVT_LE_ADVERTISING_REPORT\n\r"); 00520 /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */ 00521 // This event is generated only by X-NUCLEO-IDB05A1 version but not by X-NUCLEO-IDB04A1 (which generates DEVICE_FOUND EVT) 00522 // Formally the structure related to both events are identical except that for the ADV REPORT 00523 // there is one more field (number of reports) which is not forwarded to upper layer. 00524 // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT. 00525 le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1); 00526 PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type); 00527 00528 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00529 pr->evt_type, 00530 pr->bdaddr_type, 00531 pr->bdaddr, 00532 &pr->data_length, 00533 &pr->data_RSSI[0], 00534 &pr->data_RSSI[pr->data_length]); 00535 break; 00536 } 00537 } 00538 break; 00539 00540 case EVT_VENDOR: 00541 { 00542 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; 00543 //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode); 00544 00545 switch(blue_evt->ecode){ 00546 00547 case EVT_BLUE_GATT_READ_PERMIT_REQ: 00548 { 00549 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); 00550 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; 00551 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK pr->attr_handle=%u\n\r", pr->attr_handle); 00552 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle); 00553 } 00554 break; 00555 00556 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: 00557 { 00558 PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); 00559 /* this callback is invoked when a GATT attribute is modified 00560 extract callback data and pass to suitable handler function */ 00561 Attribute_Modified_CB(blue_evt); 00562 } 00563 break; 00564 00565 //Any cases for Data Sent Notifications? 00566 case EVT_BLUE_GATT_NOTIFICATION: 00567 //This is only relevant for Client Side Event 00568 PRINTF("EVT_BLUE_GATT_NOTIFICATION"); 00569 break; 00570 case EVT_BLUE_GATT_INDICATION: 00571 //This is only relevant for Client Side Event 00572 PRINTF("EVT_BLUE_GATT_INDICATION"); 00573 break; 00574 00575 case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP: 00576 { 00577 PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r"); 00578 evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data; 00579 BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle, 00580 pr->event_data_length, 00581 pr->attribute_data_length, 00582 pr->attribute_data_list); 00583 } 00584 break; 00585 case EVT_BLUE_ATT_READ_BY_TYPE_RESP: 00586 { 00587 PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r"); 00588 evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data; 00589 BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle, 00590 pr->event_data_length, 00591 pr->handle_value_pair_length, 00592 pr->handle_value_pair); 00593 } 00594 break; 00595 case EVT_BLUE_ATT_READ_RESP: 00596 { 00597 PRINTF("EVT_BLUE_ATT_READ_RESP\n\r"); 00598 evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data; 00599 BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle, 00600 pr->event_data_length, 00601 pr->attribute_value); 00602 } 00603 break; 00604 case EVT_BLUE_ATT_EXEC_WRITE_RESP: 00605 { 00606 PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r"); 00607 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00608 BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle, 00609 pr->event_data_length); 00610 } 00611 break; 00612 case EVT_BLUE_ATT_PREPARE_WRITE_RESP: 00613 { 00614 PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r"); 00615 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00616 BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle, 00617 pr->event_data_length, 00618 pr->attribute_handle, 00619 pr->offset, 00620 pr->part_attr_value); 00621 } 00622 break; 00623 case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP: 00624 { 00625 PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r"); 00626 evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data; 00627 BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle, 00628 pr->event_data_length, 00629 pr->attr_handle, 00630 pr->attr_value); 00631 } 00632 break; 00633 case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP: 00634 { 00635 PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r"); 00636 evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data; 00637 BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle, 00638 pr->event_data_length, 00639 pr->handles_info_list); 00640 } 00641 break; 00642 case EVT_BLUE_ATT_FIND_INFORMATION_RESP: 00643 { 00644 PRINTF("EVT_BLUE_ATT_FIND_INFORMATION_RESP\n\r"); 00645 evt_att_find_information_resp *pr = (evt_att_find_information_resp*)blue_evt->data; 00646 BlueNRGGattClient::getInstance().discAllCharacDescCB(pr->conn_handle, 00647 pr->event_data_length, 00648 pr->format, 00649 pr->handle_uuid_pair); 00650 } 00651 break; 00652 case EVT_BLUE_GATT_PROCEDURE_COMPLETE: 00653 { 00654 evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data; 00655 PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code); 00656 BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code); 00657 } 00658 break; 00659 00660 case EVT_BLUE_GAP_DEVICE_FOUND: 00661 { 00662 evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data; 00663 PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type); 00664 00665 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00666 pr->evt_type, 00667 pr->bdaddr_type, 00668 pr->bdaddr, 00669 &pr->data_length, 00670 &pr->data_RSSI[0], 00671 &pr->data_RSSI[pr->data_length]); 00672 } 00673 break; 00674 00675 case EVT_BLUE_GAP_PROCEDURE_COMPLETE: 00676 { 00677 evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data; 00678 //PRINTF("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code); 00679 00680 switch(pr->procedure_code) { 00681 case GAP_OBSERVATION_PROC_IDB05A1: 00682 00683 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, 0, NULL, NULL, NULL, NULL); 00684 break; 00685 } 00686 } 00687 break; 00688 } 00689 } 00690 break; 00691 } 00692 return ; 00693 } 00694 00695 00696 #ifdef __cplusplus 00697 } 00698 #endif
Generated on Tue Jul 12 2022 16:31:45 by
