BLE_API wrapper library for STMicroelectronics' BlueNRG Bluetooth Low Energy expansion board shield (Component)
Dependents: Nucleo_Zumo_BLE_IDB04A1 contest_IOT5 contest_IOT6 contest_IOT_10 ... more
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 "ble_utils.h" 00044 00045 #include "x_nucleo_idb0xa1_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 'x_nucleo_idb0xa1_targets.h' for details regarding the IDB0XA1 STACK_MODE */ 00077 #define STACK_MODE IDB0XA1_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_ROLE, 00131 CONFIG_DATA_ROLE_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_IDB05A1, 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_Process(); 00210 } 00211 00212 /* set BLE Version string */ 00213 void setVersionString(uint8_t hwVersion, uint16_t fwVersion) 00214 { 00215 if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) { 00216 snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u", 00217 hwVersion>>4, (hwVersion&0x0F), 00218 fwVersion>>8, (fwVersion&0x00F0)>>4); 00219 } else { 00220 snprintf(versionString, sizeof(versionString), "ST (unknown spec)"); 00221 } 00222 } 00223 00224 /* get BLE Version string */ 00225 const char* getVersionString(void) 00226 { 00227 return versionString; 00228 } 00229 00230 tBleStatus btleStartRadioScan(uint8_t scan_type, 00231 uint16_t scan_interval, 00232 uint16_t scan_window, 00233 uint8_t own_address_type) 00234 { 00235 tBleStatus ret; 00236 00237 // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED 00238 if(bnrg_expansion_board == IDB05A1) { 00239 PRINTF("scan_interval=%d scan_window=%d\n\r", scan_interval, scan_window); 00240 PRINTF("scan_type=%d own_address_type=%d\n\r", scan_type, own_address_type); 00241 ret = aci_gap_start_observation_procedure(scan_interval, 00242 scan_window, 00243 scan_type, 00244 own_address_type, 00245 0); // 1 to filter duplicates 00246 } else { 00247 ret = BLE_STATUS_INVALID_CID; 00248 } 00249 00250 return ret; 00251 00252 } 00253 00254 /*! 00255 @brief Not Used 00256 00257 @param[in] void 00258 00259 @returns 00260 */ 00261 void SPI_Poll(void) 00262 { 00263 //HAL_GPIO_EXTI_Callback_Poll(BNRG_SPI_EXTI_PIN); 00264 return; 00265 } 00266 00267 void Attribute_Modified_CB(evt_blue_aci *blue_evt) 00268 { 00269 uint16_t conn_handle; 00270 uint16_t attr_handle; 00271 uint8_t data_length; 00272 uint8_t *att_data; 00273 uint8_t offset; 00274 00275 if (bnrg_expansion_board == IDB05A1) { 00276 evt_gatt_attr_modified_IDB05A1 *evt = (evt_gatt_attr_modified_IDB05A1*)blue_evt->data; 00277 conn_handle = evt->conn_handle; 00278 attr_handle = evt->attr_handle; 00279 data_length = evt->data_length; 00280 att_data = evt->att_data; 00281 offset = evt->offset; 00282 } else { 00283 evt_gatt_attr_modified_IDB04A1 *evt = (evt_gatt_attr_modified_IDB04A1*)blue_evt->data; 00284 conn_handle = evt->conn_handle; 00285 attr_handle = evt->attr_handle; 00286 data_length = evt->data_length; 00287 att_data = evt->att_data; 00288 offset = 0; 00289 } 00290 00291 //Extract the GattCharacteristic from p_characteristics[] and find the properties mask 00292 GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(attr_handle); 00293 if(p_char!=NULL) { 00294 GattAttribute::Handle_t charHandle = p_char->getValueAttribute().getHandle()-BlueNRGGattServer::CHAR_VALUE_HANDLE; 00295 BlueNRGGattServer::HandleEnum_t currentHandle = BlueNRGGattServer::CHAR_HANDLE; 00296 PRINTF("CharHandle %d, length: %d, Data: %d\n\r", charHandle, data_length, (uint16_t)att_data[0]); 00297 PRINTF("getProperties 0x%x\n\r",p_char->getProperties()); 00298 00299 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_VALUE_HANDLE) { 00300 currentHandle = BlueNRGGattServer::CHAR_VALUE_HANDLE; 00301 } 00302 00303 if(attr_handle == charHandle+BlueNRGGattServer::CHAR_DESC_HANDLE) { 00304 currentHandle = BlueNRGGattServer::CHAR_DESC_HANDLE; 00305 } 00306 PRINTF("currentHandle %d\n\r", currentHandle); 00307 if((p_char->getProperties() & 00308 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) && 00309 currentHandle == BlueNRGGattServer::CHAR_DESC_HANDLE) { 00310 00311 GattAttribute::Handle_t charDescHandle = p_char->getValueAttribute().getHandle()+1; 00312 00313 PRINTF("*****NOTIFICATION CASE\n\r"); 00314 //Now Check if data written in Enable or Disable 00315 if((uint16_t)att_data[0]==1) { 00316 //PRINTF("Notify ENABLED\n\r"); 00317 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, charDescHandle); 00318 } else { 00319 //PRINTF("Notify DISABLED\n\r"); 00320 BlueNRGGattServer::getInstance().HCIEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, charDescHandle); 00321 } 00322 return; 00323 } 00324 00325 //Check if attr handle property is WRITEABLE, in the case generate GATT_EVENT_DATA_WRITTEN Event 00326 if((p_char->getProperties() & 00327 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)) && 00328 currentHandle == BlueNRGGattServer::CHAR_VALUE_HANDLE) { 00329 00330 PRINTF("*****WRITE CASE\n\r"); 00331 00332 GattWriteCallbackParams writeParams; 00333 writeParams.connHandle = conn_handle; 00334 writeParams.handle = p_char->getValueAttribute().getHandle(); 00335 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? 00336 writeParams.len = data_length; 00337 writeParams.data = att_data; 00338 writeParams.offset = offset; 00339 00340 //BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, attr_handle); 00341 //Write the actual Data to the Attr Handle? (uint8_1[])att_data contains the data 00342 if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getLength() > 0)) { 00343 BlueNRGGattServer::getInstance().write( 00344 p_char->getValueAttribute().getHandle(), 00345 (uint8_t*)att_data, 00346 data_length, 00347 false 00348 ); 00349 } 00350 00351 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); 00352 } else { 00353 PRINTF("*****WRITE DESCRIPTOR CASE\n\r"); 00354 00355 GattWriteCallbackParams writeParams; 00356 writeParams.connHandle = conn_handle; 00357 writeParams.handle = attr_handle; 00358 writeParams.writeOp = GattWriteCallbackParams::OP_WRITE_REQ;//Where to find this property in BLUENRG? 00359 writeParams.len = data_length; 00360 writeParams.data = att_data; 00361 writeParams.offset = offset; 00362 00363 BlueNRGGattServer::getInstance().HCIDataWrittenEvent(&writeParams); 00364 } 00365 } 00366 00367 } 00368 00369 #ifdef __cplusplus 00370 extern "C" { 00371 #endif 00372 00373 /**************************************************************************/ 00374 /*! 00375 @brief Handle HCI Stack Event 00376 00377 @param[in] pckt 00378 Event Packet sent by the stack to be decoded 00379 00380 @returns 00381 */ 00382 /**************************************************************************/ 00383 extern void HCI_Event_CB(void *pckt) { 00384 hci_uart_pckt *hci_pckt = (hci_uart_pckt*)pckt; 00385 hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data; 00386 00387 if(hci_pckt->type != HCI_EVENT_PKT) 00388 return; 00389 00390 switch(event_pckt->evt){ 00391 00392 case EVT_DISCONN_COMPLETE: 00393 { 00394 PRINTF("EVT_DISCONN_COMPLETE\n"); 00395 00396 evt_disconn_complete *evt = (evt_disconn_complete*)event_pckt->data; 00397 00398 BlueNRGGap::getInstance().processDisconnectionEvent(evt->handle, (Gap::DisconnectionReason_t)evt->reason); 00399 } 00400 break; 00401 00402 case EVT_LE_META_EVENT: 00403 { 00404 PRINTF("EVT_LE_META_EVENT\n"); 00405 00406 evt_le_meta_event *evt = (evt_le_meta_event *)event_pckt->data; 00407 00408 switch(evt->subevent){ 00409 00410 case EVT_LE_CONN_COMPLETE: 00411 { 00412 PRINTF("EVT_LE_CONN_COMPLETE\n"); 00413 Gap::Address_t ownAddr; 00414 Gap::AddressType_t ownAddrType; 00415 BlueNRGGap::getInstance().getAddress(&ownAddrType, ownAddr); 00416 00417 Gap::AddressType_t peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00418 Gap::Role_t role; 00419 00420 evt_le_connection_complete *cc = (evt_le_connection_complete *)evt->data; 00421 00422 BlueNRGGap::getInstance().setConnectionHandle(cc->handle); 00423 BlueNRGGap::ConnectionParams_t connectionParams = { 00424 /* minConnectionInterval = */ cc->interval, 00425 /* maxConnectionInterval = */ cc->interval, 00426 /* slaveLatency = */ cc->latency, 00427 /* connectionSupervisionTimeout = */ cc->supervision_timeout 00428 }; 00429 00430 BlueNRGGap::getInstance().setConnectionInterval(cc->interval); 00431 00432 switch (cc->peer_bdaddr_type) { 00433 case PUBLIC_ADDR: 00434 peerAddrType = BLEProtocol::AddressType::PUBLIC; 00435 break; 00436 case STATIC_RANDOM_ADDR: 00437 peerAddrType = BLEProtocol::AddressType::RANDOM_STATIC; 00438 break; 00439 case RESOLVABLE_PRIVATE_ADDR: 00440 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE; 00441 break; 00442 case NON_RESOLVABLE_PRIVATE_ADDR: 00443 peerAddrType = BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE; 00444 break; 00445 } 00446 //PRINTF("EVT_LE_CONN_COMPLETE LL role=%d\n", cc->role); 00447 switch (cc->role) { 00448 case 0: //master 00449 role = Gap::CENTRAL; 00450 break; 00451 case 1: 00452 role = Gap::PERIPHERAL; 00453 break; 00454 default: 00455 role = Gap::PERIPHERAL; 00456 break; 00457 } 00458 00459 BlueNRGGap::getInstance().setGapRole(role); 00460 00461 BlueNRGGap::getInstance().processConnectionEvent(cc->handle, 00462 role, 00463 peerAddrType, 00464 cc->peer_bdaddr, 00465 ownAddrType, 00466 ownAddr, 00467 &connectionParams); 00468 } 00469 break; 00470 00471 case EVT_LE_ADVERTISING_REPORT: 00472 PRINTF("EVT_LE_ADVERTISING_REPORT\n\r"); 00473 /* FIXME: comment this otherwise it will be obscure and error prone if BlueNRG FW will be updated */ 00474 // This event is generated only by X-NUCLEO-IDB05A1 version but not by X-NUCLEO-IDB04A1 (which generates DEVICE_FOUND EVT) 00475 // Formally the structure related to both events are identical except that for the ADV REPORT 00476 // there is one more field (number of reports) which is not forwarded to upper layer. 00477 // Thus we need to move one byte over (((uint8_t*)evt->data)+1) before persing the ADV REPORT. 00478 le_advertising_info *pr = (le_advertising_info*) (((uint8_t*)evt->data)+1); 00479 PRINTF("EVT_LE_ADVERTISING_REPORT evt_type=%d\n\r", pr->evt_type); 00480 00481 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00482 pr->evt_type, 00483 pr->bdaddr_type, 00484 pr->bdaddr, 00485 &pr->data_length, 00486 &pr->data_RSSI[0], 00487 &pr->data_RSSI[pr->data_length]); 00488 break; 00489 } 00490 } 00491 break; 00492 00493 case EVT_VENDOR: 00494 { 00495 evt_blue_aci *blue_evt = (evt_blue_aci*)event_pckt->data; 00496 //PRINTF("EVT_VENDOR %d\n", blue_evt->ecode); 00497 00498 switch(blue_evt->ecode){ 00499 00500 case EVT_BLUE_GATT_WRITE_PERMIT_REQ: 00501 { 00502 PRINTF("EVT_BLUE_GATT_WRITE_PERMIT_REQ\r\n"); 00503 evt_gatt_write_permit_req* write_req = (evt_gatt_write_permit_req*)blue_evt->data; 00504 00505 // ask the local server if the write operation is authorized 00506 uint8_t err_code = BlueNRGGattServer::getInstance().Write_Request_CB( 00507 write_req->conn_handle, 00508 write_req->attr_handle, 00509 write_req->data_length, 00510 write_req->data 00511 ); 00512 uint8_t write_status = err_code == 0 ? 0 : 1; 00513 00514 // reply to the shield 00515 aci_gatt_write_response( 00516 write_req->conn_handle, 00517 write_req->attr_handle, 00518 write_status, 00519 err_code, 00520 write_req->data_length, 00521 write_req->data 00522 ); 00523 } 00524 break; 00525 00526 case EVT_BLUE_GATT_READ_PERMIT_REQ: 00527 { 00528 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r"); 00529 evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data; 00530 PRINTF("EVT_BLUE_GATT_READ_PERMIT_REQ_OK pr->attr_handle=%u\n\r", pr->attr_handle); 00531 BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle); 00532 } 00533 break; 00534 00535 case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED: 00536 { 00537 PRINTF("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r"); 00538 /* this callback is invoked when a GATT attribute is modified 00539 extract callback data and pass to suitable handler function */ 00540 Attribute_Modified_CB(blue_evt); 00541 } 00542 break; 00543 00544 //Any cases for Data Sent Notifications? 00545 case EVT_BLUE_GATT_NOTIFICATION: 00546 //This is only relevant for Client Side Event 00547 PRINTF("EVT_BLUE_GATT_NOTIFICATION"); 00548 break; 00549 case EVT_BLUE_GATT_INDICATION: 00550 //This is only relevant for Client Side Event 00551 PRINTF("EVT_BLUE_GATT_INDICATION"); 00552 break; 00553 00554 case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP: 00555 { 00556 PRINTF("EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP\n\r"); 00557 evt_att_read_by_group_resp *pr = (evt_att_read_by_group_resp*)blue_evt->data; 00558 BlueNRGGattClient::getInstance().primaryServicesCB(pr->conn_handle, 00559 pr->event_data_length, 00560 pr->attribute_data_length, 00561 pr->attribute_data_list); 00562 } 00563 break; 00564 case EVT_BLUE_ATT_READ_BY_TYPE_RESP: 00565 { 00566 PRINTF("EVT_BLUE_ATT_READ_BY_TYPE_RESP\n\r"); 00567 evt_att_read_by_type_resp *pr = (evt_att_read_by_type_resp*)blue_evt->data; 00568 BlueNRGGattClient::getInstance().serviceCharsCB(pr->conn_handle, 00569 pr->event_data_length, 00570 pr->handle_value_pair_length, 00571 pr->handle_value_pair); 00572 } 00573 break; 00574 case EVT_BLUE_ATT_READ_RESP: 00575 { 00576 PRINTF("EVT_BLUE_ATT_READ_RESP\n\r"); 00577 evt_att_read_resp *pr = (evt_att_read_resp*)blue_evt->data; 00578 BlueNRGGattClient::getInstance().charReadCB(pr->conn_handle, 00579 pr->event_data_length, 00580 pr->attribute_value); 00581 } 00582 break; 00583 case EVT_BLUE_ATT_EXEC_WRITE_RESP: 00584 { 00585 PRINTF("EVT_BLUE_ATT_EXEC_WRITE_RESP\n\r"); 00586 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00587 BlueNRGGattClient::getInstance().charWriteExecCB(pr->conn_handle, 00588 pr->event_data_length); 00589 } 00590 break; 00591 case EVT_BLUE_ATT_PREPARE_WRITE_RESP: 00592 { 00593 PRINTF("EVT_BLUE_ATT_PREPARE_WRITE_RESP\n\r"); 00594 evt_att_prepare_write_resp *pr = (evt_att_prepare_write_resp*)blue_evt->data; 00595 BlueNRGGattClient::getInstance().charWritePrepareCB(pr->conn_handle, 00596 pr->event_data_length, 00597 pr->attribute_handle, 00598 pr->offset, 00599 pr->part_attr_value); 00600 } 00601 break; 00602 case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP: 00603 { 00604 PRINTF("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n\r"); 00605 evt_gatt_disc_read_char_by_uuid_resp *pr = (evt_gatt_disc_read_char_by_uuid_resp*)blue_evt->data; 00606 BlueNRGGattClient::getInstance().serviceCharByUUIDCB(pr->conn_handle, 00607 pr->event_data_length, 00608 pr->attr_handle, 00609 pr->attr_value); 00610 } 00611 break; 00612 case EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP: 00613 { 00614 PRINTF("EVT_BLUE_ATT_FIND_BY_TYPE_VAL_RESP\n\r"); 00615 evt_att_find_by_type_val_resp *pr = (evt_att_find_by_type_val_resp*)blue_evt->data; 00616 BlueNRGGattClient::getInstance().primaryServiceCB(pr->conn_handle, 00617 pr->event_data_length, 00618 pr->handles_info_list); 00619 } 00620 break; 00621 case EVT_BLUE_ATT_FIND_INFORMATION_RESP: 00622 { 00623 PRINTF("EVT_BLUE_ATT_FIND_INFORMATION_RESP\n\r"); 00624 evt_att_find_information_resp *pr = (evt_att_find_information_resp*)blue_evt->data; 00625 BlueNRGGattClient::getInstance().discAllCharacDescCB(pr->conn_handle, 00626 pr->event_data_length, 00627 pr->format, 00628 pr->handle_uuid_pair); 00629 } 00630 break; 00631 case EVT_BLUE_GATT_PROCEDURE_COMPLETE: 00632 { 00633 evt_gatt_procedure_complete *evt = (evt_gatt_procedure_complete*)blue_evt->data; 00634 PRINTF("EVT_BLUE_GATT_PROCEDURE_COMPLETE error_code=%d\n\r", evt->error_code); 00635 BlueNRGGattClient::getInstance().gattProcedureCompleteCB(evt->conn_handle, evt->error_code); 00636 } 00637 break; 00638 00639 case EVT_BLUE_L2CAP_CONN_UPD_REQ: 00640 { 00641 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_REQ\r\n"); 00642 evt_l2cap_conn_upd_req *evt = (evt_l2cap_conn_upd_req*)blue_evt->data; 00643 if(bnrg_expansion_board == IDB05A1) { 00644 // we assume the application accepts the request from the slave 00645 aci_l2cap_connection_parameter_update_response_IDB05A1(evt->conn_handle, 00646 evt->interval_min, 00647 evt->interval_max, 00648 evt->slave_latency, 00649 evt->timeout_mult, 00650 CONN_L1, CONN_L2, 00651 evt->identifier, 00652 0x0000); 00653 } 00654 } 00655 break; 00656 00657 case EVT_BLUE_L2CAP_CONN_UPD_RESP: 00658 { 00659 PRINTF("EVT_BLUE_L2CAP_CONN_UPD_RESP\r\n"); 00660 } 00661 break; 00662 00663 case EVT_LE_CONN_UPDATE_COMPLETE: 00664 { 00665 PRINTF("EVT_LE_CONN_UPDATE_COMPLETE\r\n"); 00666 } 00667 break; 00668 00669 case EVT_BLUE_GAP_DEVICE_FOUND: 00670 { 00671 evt_gap_device_found *pr = (evt_gap_device_found*)blue_evt->data; 00672 PRINTF("EVT_BLUE_GAP_DEVICE_FOUND evt_type=%d\n\r", pr->evt_type); 00673 00674 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DEVICE_FOUND, 00675 pr->evt_type, 00676 pr->bdaddr_type, 00677 pr->bdaddr, 00678 &pr->data_length, 00679 &pr->data_RSSI[0], 00680 &pr->data_RSSI[pr->data_length]); 00681 } 00682 break; 00683 00684 case EVT_BLUE_GAP_PROCEDURE_COMPLETE: 00685 { 00686 evt_gap_procedure_complete *pr = (evt_gap_procedure_complete*)blue_evt->data; 00687 //PRINTF("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code); 00688 00689 switch(pr->procedure_code) { 00690 case GAP_OBSERVATION_PROC_IDB05A1: 00691 00692 BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, 0, NULL, NULL, NULL, NULL); 00693 break; 00694 } 00695 } 00696 break; 00697 } 00698 } 00699 break; 00700 } 00701 return ; 00702 } 00703 00704 00705 #ifdef __cplusplus 00706 } 00707 #endif
Generated on Tue Jul 12 2022 18:15:59 by 1.7.2