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.
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 "ble_utils.h" 00044 00045 #include "bluenrg_targets.h" 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 00052 /* C File Includes ------------------------------------------------------------------*/ 00053 #include <stdio.h> 00054 #include <string.h> 00055 #include "ble_hci.h" 00056 #include "ble_hci_const.h" 00057 #include "bluenrg_aci.h" 00058 #include "bluenrg_hal_aci.h" 00059 #include "bluenrg_gap.h" 00060 #include "bluenrg_utils.h" 00061 00062 #include "ble_hal_types.h" 00063 #include "ble_hal.h" 00064 #include "ble_gp_timer.h" 00065 #include "ble_osal.h" 00066 #include "ble_sm.h" 00067 #include "ble_debug.h" 00068 00069 #ifdef __cplusplus 00070 } 00071 #endif 00072 00073 #define IDB04A1 0 00074 #define IDB05A1 1 00075 00076 /* See file 'bluenrg_targets.h' for details regarding the BLUENRG_STACK_MODE */ 00077 #define STACK_MODE BLUENRG_STACK_MODE 00078 00079 void HCI_Input(tHciDataPacket * hciReadPacket); 00080 00081 uint16_t g_gap_service_handle = 0; 00082 uint16_t g_appearance_char_handle = 0; 00083 uint16_t g_device_name_char_handle = 0; 00084 uint16_t g_preferred_connection_parameters_char_handle = 0; 00085 00086 /* Private variables ---------------------------------------------------------*/ 00087 volatile uint8_t set_connectable = 1; 00088 00089 static char versionString[32]; 00090 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */ 00091 00092 /**************************************************************************/ 00093 /*! 00094 @brief Init the BTLE stack with the specified role 00095 @returns void 00096 */ 00097 /**************************************************************************/ 00098 void btleInit(void) 00099 { 00100 PRINTF("btleInit>>\n\r"); 00101 00102 int ret; 00103 uint8_t hwVersion; 00104 uint16_t fwVersion; 00105 uint16_t service_handle, dev_name_char_handle, appearance_char_handle; 00106 00107 /* Reset BlueNRG SPI interface */ 00108 BlueNRG_RST(); 00109 00110 /* get the BlueNRG HW and FW versions */ 00111 getBlueNRGVersion(&hwVersion, &fwVersion); 00112 00113 /* 00114 * Reset BlueNRG again otherwise we won't 00115 * be able to change its MAC address. 00116 * aci_hal_write_config_data() must be the first 00117 * command after reset otherwise it will fail. 00118 */ 00119 BlueNRG_RST(); 00120 00121 if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ 00122 bnrg_expansion_board = IDB05A1; 00123 } 00124 00125 /* set BLE version string */ 00126 setVersionString(hwVersion, fwVersion); 00127 00128 if (bnrg_expansion_board == IDB05A1) { 00129 uint8_t stackMode = STACK_MODE; 00130 ret = aci_hal_write_config_data(CONFIG_DATA_MODE_OFFSET, 00131 CONFIG_DATA_MODE_LEN, 00132 &stackMode); 00133 } 00134 00135 ret = aci_gatt_init(); 00136 if(ret != BLE_STATUS_SUCCESS){ 00137 PRINTF("GATT_Init failed.\n"); 00138 } 00139 if (bnrg_expansion_board == IDB05A1) { 00140 ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1|GAP_OBSERVER_ROLE_IDB05A1, 00141 0, 00142 0x18, 00143 &service_handle, 00144 &dev_name_char_handle, 00145 &appearance_char_handle); 00146 } else { 00147 // IDB04A1 is configured as peripheral by default 00148 ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle); 00149 } 00150 00151 // read the default static address and inject it into the GAP object 00152 { 00153 Gap::Address_t BLE_address_BE = { 0 }; 00154 uint8_t data_len_out; 00155 aci_hal_read_config_data(CONFIG_DATA_RANDOM_ADDRESS, BDADDR_SIZE, &data_len_out, BLE_address_BE); 00156 // FIXME error handling of this function 00157 BlueNRGGap::getInstance().setAddress(BLEProtocol::AddressType::RANDOM_STATIC, BLE_address_BE); 00158 } 00159 00160 if(ret != BLE_STATUS_SUCCESS){ 00161 PRINTF("GAP_Init failed.\n"); 00162 } 00163 00164 //FIXME: Security and passkey set by default 00165 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, 00166 OOB_AUTH_DATA_ABSENT, 00167 NULL, 00168 7, 00169 16, 00170 USE_FIXED_PIN_FOR_PAIRING, 00171 123456, 00172 BONDING); 00173 if (ret != BLE_STATUS_SUCCESS) { 00174 PRINTF("Auth Req set failed.\n"); 00175 } 00176 00177 aci_hal_set_tx_power_level(1,4); 00178 00179 g_gap_service_handle = service_handle; 00180 g_appearance_char_handle = appearance_char_handle; 00181 g_device_name_char_handle = dev_name_char_handle; 00182 //Device Name is set from Accumulate Adv Data Payload or through setDeviceName API 00183 /*ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, 00184 strlen(name), (tHalUint8 *)name);*/ 00185 00186 signalEventsToProcess(); 00187 // update the peripheral preferred conenction parameters handle 00188 // This value is hardcoded at the moment. 00189 g_preferred_connection_parameters_char_handle = 10; 00190 00191 return; 00192 } 00193 00194 /**************************************************************************/ 00195 /*! 00196 @brief mbedOS 00197 00198 @param[in] void 00199 00200 @returns 00201 */ 00202 /**************************************************************************/ 00203 int btle_handler_pending = 0; 00204 00205 void btle_handler(void) 00206 { 00207 btle_handler_pending = 0; 00208 BlueNRGGap::getInstance().Process(); 00209 HCI_HandleSPI(); 00210 HCI_Process(); 00211 } 00212 00213 /* set BLE Version string */ 00214 void setVersionString(uint8_t hwVersion, uint16_t fwVersion) 00215 { 00216 if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) { 00217 snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u", 00218 hwVersion>>4, (hwVersion&0x0F), 00219 fwVersion>>8, (fwVersion&0x00F0)>>4); 00220 } else { 00221 snprintf(versionString, sizeof(versionString), "ST (unknown spec)"); 00222 } 00223 } 00224 00225 /* get BLE Version string */ 00226 const char* getVersionString(void) 00227 { 00228 return versionString; 00229 } 00230 00231 tBleStatus btleStartRadioScan(uint8_t scan_type, 00232 uint16_t scan_interval, 00233 uint16_t scan_window, 00234 uint8_t own_address_type) 00235 { 00236 tBleStatus ret; 00237 00238 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED 00239 if(bnrg_expansion_board == IDB05A1) { 00240 PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window); 00241 PRINTF("scan_type=%d own_address_type=%d\n\r", scan_type, own_address_type); 00242 ret = aci_gap_start_observation_procedure(scan_interval, 00243 scan_window, 00244 scan_type, 00245 own_address_type, 00246 1); // 1 to filter duplicates 00247 } else { 00248 ret = BLE_STATUS_INVALID_CID; 00249 } 00250 00251 return ret; 00252 00253 } 00254 00255 /*! 00256 @brief Not Used 00257 00258 @param[in] void 00259 00260 @returns 00261 */ 00262 void SPI_Poll(void) 00263 { 00264 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); 00265 return; 00266 } 00267 00268 void Attribute_Modified_CB(evt_blue_aci *blue_evt) 00269 { 00270 uint16_t conn_handle; 00271 uint16_t attr_handle; 00272 uint8_t data_length; 00273 uint8_t *att_data; 00274 uint8_t offset; 00275 00276 if (bnrg_expansion_board == IDB05A1) { 00277 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data; 00278 conn_handle = evt->conn_handle; 00279 attr_handle = evt->attr_handle; 00280 data_length = evt->data_length; 00281 att_data = evt->att_data; 00282 offset = evt->offset; 00283 } else { 00284 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data; 00285 conn_handle = evt->conn_handle; 00286 attr_handle = evt->attr_handle; 00287 data_length = evt->data_length; 00288 att_data = evt->att_data; 00289 offset = 0; 00290 } 00291 00292 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask 00293 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle); 00294 if(p_char!=NULL) { 00295 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE; 00296 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE; 00297 PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]); 00298 PRINTF("getProperties 0x%x\n\r",p_char->getProperties()); 00299 00300 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_VALUE_HANDLE) { 00301 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE; 00302 } 00303 00304 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_DESC_HANDLE) { 00305 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE; 00306 } 00307 PRINTF("currentHandle %d\n\r", currentHandle); 00308 00309 00310 00311 00312 00313 00314 //Check if attr handle property is WRITEABLE, in the case generate GATT_EVENT_DATA_WRITTEN Event 00315 if((currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE)) { 00316 00317 PRINTF("*****WRITE CASE\n\r"); 00318 00319 GattWriteCallbackParams writeParams; 00320 writeParams.connHandle = conn_handle; 00321 writeParams.handle = p_char->getValueAttribute().getHandle(); 00322 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? 00323 writeParams.len = data_length; 00324 writeParams.data = att_data; 00325 writeParams.offset = offset; 00326 00327 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, attr_handle); 00328 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data 00329 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) { 00330 BlueNRGGattServer::getInstance().write( 00331 p_char->getValueAttribute().getHandle(), 00332 (uint8_t*)att_data, 00333 data_length, 00334 false 00335 ); 00336 } 00337 00338 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); 00339 } else { 00340 PRINTF("*****WRITE DESCRIPTOR CASE\n\r"); 00341 00342 GattWriteCallbackParams writeParams; 00343 writeParams.connHandle = conn_handle; 00344 writeParams.handle = attr_handle; 00345 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? 00346 writeParams.len = data_length; 00347 writeParams.data = att_data; 00348 writeParams.offset = offset; 00349 00350 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); 00351 00352 }//WRITE 00353 00354 }//if-pChar 00355 } 00356 00357 #ifdef __cplusplus 00358 extern "C" { 00359 #endif 00360 00361 /**************************************************************************/ 00362 /*! 00363 @brief Handle HCI Stack Event 00364 00365 @param[in] pckt 00366 Event Packet sent by the stack to be decoded 00367 00368 @returns 00369 */ 00370 /**************************************************************************/ 00371 extern void HCI_Event_CB(void *pckt) { 00372 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; 00373 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; 00374 00375 if(hci_pckt->type != HCI_EVENT_PKT) 00376 return; 00377 00378 switch(event_pckt->evt){ 00379 00380 case EVT_DISCONN_COMPLETE: 00381 { 00382 PRINTF("EVT_DISCONN_COMPLETE\n"); 00383 00384 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt->data; 00385 BlueNRGGattClient::getInstance().removeGattConnectionClient(evt->handle, evt->reason); 00386 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, (Gap::DisconnectionReason_t)evt->reason); 00387 } 00388 break; 00389 00390 case EVT_LE_META_EVENT: 00391 { 00392 PRINTF("EVT_LE_META_EVENT\n"); 00393 00394 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; 00395 00396 switch(evt->subevent){ 00397 00398 case EVT_LE_CONN_COMPLETE: 00399 { 00400 PRINTF("EVT_LE_CONN_COMPLETE\n"); 00401 Gap::Address_t ownAddr; 00402 Gap::AddressType_t ownAddrType; 00403 BlueNRGGap::getInstance().getAddress(&ownAddrType, ownAddr); 00404 00405 Gap::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00406 Gap::Role_t role; 00407 00408 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; 00409 00410 BlueNRGGap::getInstance().setConnectionHandle(cc->handle); 00411 BlueNRGGap::ConnectionParams_t connectionParams = { 00412 /* minConnectionInterval = */ cc->interval, 00413 /* maxConnectionInterval = */ cc->interval, 00414 /* slaveLatency = */ cc->latency, 00415 /* connectionSupervisionTimeout = */ cc->supervision_timeout 00416 }; 00417 00418 BlueNRGGap::getInstance().setConnectionInterval(cc->interval); 00419 00420 switch (cc->peer_bdaddr_type) { 00421 case PUBLIC_ADDR: 00422 peerAddrType = BLEProtocol::AddressType::PUBLIC; 00423 break; 00424 case STATIC_RANDOM_ADDR: 00425 peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00426 break; 00427 case RESOLVABLE_PRIVATE_ADDR: 00428 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE; 00429 break; 00430 case NON_RESOLVABLE_PRIVATE_ADDR: 00431 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE; 00432 break; 00433 } 00434 //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role); 00435 switch (cc->role) { 00436 case 0: //master 00437 role = Gap::CENTRAL; 00438 break; 00439 case 1: 00440 role = Gap::PERIPHERAL; 00441 break; 00442 default: 00443 role = Gap::PERIPHERAL; 00444 break; 00445 } 00446 BlueNRGGattClient::getInstance().createGattConnectionClient(cc->handle); 00447 00448 BlueNRGGap::getInstance().setGapRole(role); 00449 00450 BlueNRGGap::getInstance().processConnectionEvent(cc->handle, 00451 role, 00452 peerAddrType, 00453 cc->peer_bdaddr, 00454 ownAddrType, 00455 ownAddr, 00456 &connectionParams); 00457 } 00458 break; 00459 00460 case EVT_LE_ADVERTISING_REPORT: 00461 PRINTF("EVT_LE_ADVERTISING_REPORT\n\r"); 00462 /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */ 00463 // This event is generated only by X-NUCLEO-IDB05A1 version but not by X-NUCLEO-IDB04A1 (which generates DEVICE_FOUND EVT) 00464 // Formally the structure related to both events are identical except that for the ADV REPORT 00465 // there is one more field (number of reports) which is not forwarded to upper layer. 00466 // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT. 00467 le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1); 00468 PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type); 00469 00470 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00471 pr->evt_type, 00472 pr->bdaddr_type, 00473 pr->bdaddr, 00474 &pr->data_length, 00475 &pr->data_RSSI[0], 00476 &pr->data_RSSI[pr->data_length]); 00477 break; 00478 } 00479 } 00480 break; 00481 00482 case EVT_VENDOR: 00483 { 00484 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; 00485 //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode); 00486 00487 switch(blue_evt->ecode){ 00488 00489 case EVT_BLUE_GATT_WRITE_PERMIT_REQ: 00490 { 00491 PRINTF("EVT_BLUE_GATT_WRITE_PERMIT_REQ\r\n"); 00492 evt_gatt_write_permit_req* write_req = (evt_gatt_write_permit_req*)blue_evt->data; 00493 00494 // ask the local server if the write operation is authorized 00495 uint8_t err_code = BlueNRGGattServer::getInstance().Write_Request_CB( 00496 write_req->conn_handle, 00497 write_req->attr_handle, 00498 write_req->data_length, 00499 write_req->data 00500 ); 00501 uint8_t write_status = err_code == 0 ? 0 : 1; 00502 00503 // reply to the shield 00504 aci_gatt_write_response( 00505 write_req->conn_handle, 00506 write_req->attr_handle, 00507 write_status, 00508 err_code, 00509 write_req->data_length, 00510 write_req->data 00511 ); 00512 } 00513 break; 00514 00515 case EVT_BLUE_GATT_READ_PERMIT_REQ: 00516 { 00517 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); 00518 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; 00519 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK pr->attr_handle=%u\n\r", pr->attr_handle); 00520 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle); 00521 } 00522 break; 00523 00524 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: 00525 { 00526 PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); 00527 /* this callback is invoked when a GATT attribute is modified 00528 extract callback data and pass to suitable handler function */ 00529 Attribute_Modified_CB(blue_evt); 00530 } 00531 break; 00532 00533 //Any cases for Data Sent Notifications? 00534 case EVT_BLUE_GATT_NOTIFICATION: 00535 { 00536 PRINTF("EVT_BLUE_GATT_NOTIFICATION"); 00537 00538 evt_gatt_attr_notification *notification = (evt_gatt_attr_notification*)blue_evt->data; 00539 00540 GattHVXCallbackParams params; 00541 params.connHandle = notification->conn_handle; 00542 params.handle = notification->attr_handle; 00543 params.type = BLE_HVX_NOTIFICATION; 00544 params.len = notification->event_data_length - 2; 00545 params.data = notification->attr_value; 00546 00547 BlueNRGGattClient::getInstance().processHVXEvent(¶ms); 00548 } 00549 break; 00550 00551 case EVT_BLUE_GATT_INDICATION: 00552 { 00553 PRINTF("EVT_BLUE_GATT_INDICATION"); 00554 evt_gatt_indication *indication = (evt_gatt_indication*)blue_evt->data; 00555 00556 GattHVXCallbackParams params; 00557 params.connHandle = indication->conn_handle; 00558 params.handle = indication->attr_handle; 00559 params.type = BLE_HVX_INDICATION; 00560 params.len = indication->event_data_length - 2; 00561 params.data = indication->attr_value; 00562 00563 BlueNRGGattClient::getInstance().processHVXEvent(¶ms); 00564 aci_gatt_confirm_indication(params.connHandle); 00565 } 00566 break; 00567 00568 case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP: 00569 { 00570 PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r"); 00571 evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data; 00572 BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle, 00573 pr->event_data_length, 00574 pr->attribute_data_length, 00575 pr->attribute_data_list); 00576 } 00577 break; 00578 case EVT_BLUE_ATT_READ_BY_TYPE_RESP: 00579 { 00580 PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r"); 00581 evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data; 00582 BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle, 00583 pr->event_data_length, 00584 pr->handle_value_pair_length, 00585 pr->handle_value_pair); 00586 } 00587 break; 00588 case EVT_BLUE_ATT_READ_RESP: 00589 { 00590 PRINTF("EVT_BLUE_ATT_READ_RESP\n\r"); 00591 evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data; 00592 BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle, 00593 pr->event_data_length, 00594 pr->attribute_value); 00595 } 00596 break; 00597 case EVT_BLUE_ATT_EXEC_WRITE_RESP: 00598 { 00599 PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r"); 00600 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00601 BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle, 00602 pr->event_data_length); 00603 } 00604 break; 00605 case EVT_BLUE_ATT_PREPARE_WRITE_RESP: 00606 { 00607 PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r"); 00608 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00609 BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle, 00610 pr->event_data_length, 00611 pr->attribute_handle, 00612 pr->offset, 00613 pr->part_attr_value); 00614 } 00615 break; 00616 case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP: 00617 { 00618 PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r"); 00619 evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data; 00620 BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle, 00621 pr->event_data_length, 00622 pr->attr_handle, 00623 pr->attr_value); 00624 } 00625 break; 00626 case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP: 00627 { 00628 PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r"); 00629 evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data; 00630 BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle, 00631 pr->event_data_length, 00632 pr->handles_info_list); 00633 } 00634 break; 00635 case EVT_BLUE_ATT_FIND_INFORMATION_RESP: 00636 { 00637 PRINTF("EVT_BLUE_ATT_FIND_INFORMATION_RESP\n\r"); 00638 evt_att_find_information_resp *pr = (evt_att_find_information_resp*)blue_evt->data; 00639 BlueNRGGattClient::getInstance().discAllCharacDescCB(pr->conn_handle, 00640 pr->event_data_length, 00641 pr->format, 00642 pr->handle_uuid_pair); 00643 } 00644 break; 00645 case EVT_BLUE_GATT_PROCEDURE_COMPLETE: 00646 { 00647 evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data; 00648 PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code); 00649 BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code); 00650 } 00651 break; 00652 00653 case EVT_BLUE_L2CAP_CONN_UPD_REQ: 00654 { 00655 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_REQ\r\n"); 00656 evt_l2cap_conn_upd_req *evt = (evt_l2cap_conn_upd_req*)blue_evt->data; 00657 if(bnrg_expansion_board == IDB05A1) { 00658 // we assume the application accepts the request from the slave 00659 aci_l2cap_connection_parameter_update_response_IDB05A1(evt->conn_handle, 00660 evt->interval_min, 00661 evt->interval_max, 00662 evt->slave_latency, 00663 evt->timeout_mult, 00664 CONN_L1, CONN_L2, 00665 evt->identifier, 00666 0x0000); 00667 } 00668 } 00669 break; 00670 00671 case EVT_BLUE_L2CAP_CONN_UPD_RESP: 00672 { 00673 evt_l2cap_conn_upd_resp *evt = (evt_l2cap_conn_upd_resp*)blue_evt->data; 00674 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_RESP code=0x%x, result=0x%x\r\n", evt->code, evt->result); 00675 } 00676 break; 00677 00678 case EVT_LE_CONN_UPDATE_COMPLETE: 00679 { 00680 evt_le_connection_update_complete *evt = (evt_le_connection_update_complete*)blue_evt->data; 00681 PRINTF("EVT_LE_CONN_UPDATE_COMPLETE status=0x%x\r\n", evt->status); 00682 } 00683 break; 00684 00685 case EVT_BLUE_GAP_DEVICE_FOUND: 00686 { 00687 evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data; 00688 PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type); 00689 00690 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00691 pr->evt_type, 00692 pr->bdaddr_type, 00693 pr->bdaddr, 00694 &pr->data_length, 00695 &pr->data_RSSI[0], 00696 &pr->data_RSSI[pr->data_length]); 00697 } 00698 break; 00699 00700 case EVT_BLUE_GAP_PROCEDURE_COMPLETE: 00701 { 00702 evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data; 00703 //PRINTF("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code); 00704 00705 switch(pr->procedure_code) { 00706 case GAP_OBSERVATION_PROC_IDB05A1: 00707 00708 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, 0, NULL, NULL, NULL, NULL); 00709 break; 00710 } 00711 } 00712 break; 00713 } 00714 } 00715 break; 00716 } 00717 return ; 00718 } 00719 00720 00721 #ifdef __cplusplus 00722 } 00723 #endif
Generated on Tue Jul 12 2022 21:44:00 by
1.7.2