From 2182b69b3d776775fb3040d974807b0c8514ae79 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 18 Oct 2016 05:22:36 -0400 Subject: [PATCH 01/31] component bt:added the button profile event & process method to the project --- .../bt/bluedroid/bta/gatt/bta_gattc_act.c | 1 + .../bt/bluedroid/bta/gatt/bta_gattc_main.c | 4 +- .../profiles/esp/ble_button/button_pro.c | 21 ++-- .../profiles/esp/include/button_pro.h | 2 + .../profiles/esp/include/wx_airsync_prf.h | 2 +- .../esp/wechat_AirSync/wx_airsync_prf.c | 2 +- .../profiles/std/hid_le/hid_le_prf.c | 2 +- .../bluedroid/profiles/std/include/prf_defs.h | 4 +- .../bt/bluedroid/stack/btm/btm_ble_privacy.c | 14 +-- .../bluedroid_demos/app_core/bt_app_api.c | 19 +++ .../app_sample_button/app_button.c | 47 ++++++- .../app_project/SampleServerProject.c | 2 +- .../bluedroid_demos/include/app_button_int.h | 117 ++++++++++++++++++ .../bluedroid_demos/include/app_wechat_util.h | 2 +- 14 files changed, 210 insertions(+), 29 deletions(-) create mode 100644 examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c create mode 100644 examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 116641ebb..c7546404e 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -271,6 +271,7 @@ void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",p_msg->int_start_if.client_if ); } } + /******************************************************************************* ** ** Function bta_gattc_deregister diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c index 7885fa685..bb45445a4 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c @@ -364,7 +364,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) tBTA_GATTC_RCB *p_clreg; BOOLEAN rt = TRUE; #if BTA_GATT_DEBUG == TRUE - APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]", gattc_evt_code(p_msg->event)); + APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]\n", gattc_evt_code(p_msg->event)); #endif switch (p_msg->event) { @@ -424,7 +424,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg) } else { - APPL_TRACE_DEBUG("Ignore unknown conn ID: %d", p_msg->layer_specific); + APPL_TRACE_DEBUG("Ignore unknown conn ID: %d\n", p_msg->layer_specific); } break; diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 9fa1c9aed..b11e30e7a 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -284,32 +284,23 @@ UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) ** Returns True the deallocation is successful ** *******************************************************************************/ -/* + BOOLEAN button_env_clcb_dealloc(UINT16 conn_id) { UINT8 i_clcb = 0; tBUT_CLCB *p_clcb = NULL; - for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < BUTT_MAX_APPS; i_clcb++, p_clcb++) + for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < 1; i_clcb++, p_clcb++) { if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id)) { - unsigned j; - for(j = 0; j < ARRAY_SIZE(p_clcb->button_value.data_string);j++) - { - if(p_clcb->button_value.data_string[j]) - { - GKI_freebuf(p_clcb->button_value.data_string[j]); - } - } memset(p_clcb, 0, sizeof(tBUT_CLCB)); return TRUE; } } return FALSE; -}*/ - +} /******************************************************************************* ** @@ -348,6 +339,12 @@ tGATT_STATUS button_init (tBU_CBACK *call_back) return GATT_SUCCESS; } +void button_disable(UINT16 connid) +{ + button_env_clcb_dealloc(connid); +} + + void button_msg_notify(UINT8 len, UINT8 *button_msg) { BOOLEAN conn_status = button_cb_env.clcb.connected; diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index d9028830b..023e248af 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -115,6 +115,8 @@ BOOLEAN button_env_clcb_dealloc(UINT16 conn_id); tGATT_STATUS button_init(tBU_CBACK *call_back); +void button_disable(UINT16 connid); + void button_msg_notify(UINT8 len, UINT8 *button_msg); extern tBUTTON_CB_ENV button_cb_env; diff --git a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h index 1883b839c..8323ae8b8 100644 --- a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h +++ b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h @@ -50,7 +50,7 @@ typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data) WX_IDX_AIRSYNC_READ_VAL, WX_IDX_AIRSYNC_NTF_CFG, - KEY_IDX_NB, + WX_IDX_NB, }; typedef struct diff --git a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c index 821195d44..dc1e557b9 100644 --- a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c +++ b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c @@ -184,7 +184,7 @@ void AirSync_CreateService(void) { tBTA_GATTS_IF server_if ; tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; - UINT16 num_handle = KEY_IDX_NB; + UINT16 num_handle = WX_IDX_NB; UINT8 inst = 0x00; server_if = airsync_cb_env.gatt_if; airsync_cb_env.inst_id = inst; diff --git a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c index 61037ae5e..4b225132b 100644 --- a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c +++ b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c @@ -458,7 +458,7 @@ void hidd_le_CreateService(BOOLEAN is_primary) tBTA_GATTS_IF server_if ; tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}}; //the number of the hid device attributes in the hid service. - UINT16 num_handle = HIDD_LE_IDX_NB+5; + UINT16 num_handle = HIDD_LE_IDX_NB; UINT8 inst = 0x00; server_if = hidd_le_env.gatt_if; hidd_le_env.inst_id = inst; diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 790bfe2c0..921477d02 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -26,8 +26,8 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 0 +#define WX_AIRSYNC_CFG 1 +#define BUT_PROFILE_CFG 1 #define HIDD_LE_PROFILE_CFG 1 /* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c index c7362a7b9..e0bbcf89d 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_privacy.c @@ -760,14 +760,14 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) BOOLEAN rt = FALSE; UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state; - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n", __func__, btm_cb.ble_ctr_cb.privacy_mode); /* if controller does not support RPA offloading or privacy 1.2, skip */ if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) return FALSE; - BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", + BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d\n", __func__, btm_cb.ble_ctr_cb.privacy_mode); /* only add RPA enabled device into resolving list */ @@ -801,7 +801,7 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type; } - BTM_TRACE_DEBUG("%s:adding device to controller resolving list", __func__); + BTM_TRACE_DEBUG("%s:adding device to controller resolving list\n", __func__); // use identical IRK for now rt = btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr, peer_irk, local_irk); @@ -837,13 +837,13 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) } else { - BTM_TRACE_ERROR("Device already in Resolving list"); + BTM_TRACE_ERROR("Device already in Resolving list\n"); rt = TRUE; } } else { - BTM_TRACE_DEBUG("Device not a RPA enabled device"); + BTM_TRACE_DEBUG("Device not a RPA enabled device\n"); } return rt; } @@ -863,7 +863,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) { UINT8 rl_mask = btm_cb.ble_ctr_cb.rl_state; - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); if (rl_mask) { if (!btm_ble_disable_resolving_list (rl_mask, FALSE)) @@ -879,7 +879,7 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC *p_dev_rec) } else { - BTM_TRACE_DEBUG("Device not in resolving list"); + BTM_TRACE_DEBUG("Device not in resolving list\n"); } /* if resolving list has been turned on, re-enable it */ diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c new file mode 100644 index 000000000..687c5dae4 --- /dev/null +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -0,0 +1,19 @@ +/** + **************************************************************************************** + * + * @file bt_app_api.c + * + * @brief Application entry point + * + * Copyright (C) Espressif 2016 + * Created by Yulong at 2016/10/17 + * + * + **************************************************************************************** + */ + +#include "bt_app_api.h" + + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index 38f5f950e..825a5647a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -15,7 +15,6 @@ ******************************************************************************* ********* */ -#if 0 #include #include #include @@ -33,6 +32,52 @@ #include "allocator.h" #include "button_pro.h" +#include "app_button_int.h" + + +/******************************************************************************* +** +** Function ble_but_prf_hdl_event +** +** Description button profile main event handling function. +** +** +** Returns BOOLEAN +** +*******************************************************************************/ +BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data) +{ + UINT16 connid = 0; + switch(msg_data->event) + { + case BLE_BUT_CREATE_DB_REQ_EVT: + Button_CreateService(); + break; + case BLE_BUT_VAL_SEND_CFM_EVT: + break; + case BLE_BUT_SET_CHAR_VAL_REQ_EVT: + button_msg_notify(msg_data->len,msg_data->data); + break; + case BLE_BUT_ENABLE_REQ_EVT: + button_init(NULL); + break; + case BLE_BUT_DISABLE_IND_EVT: + button_disable(connid); + break; + case BLE_BUT_CHAR_WRITE_IND_EVT: + + break; + case BLE_BUT_ERROR_IND_EVT: + break; + default: + break; + } +} + + + +#if 0 + #define GPIO_INUM 8 #define TABLE_ELEMENT_CNT(table) ((sizeof(table))/(sizeof(table[0]))); app_key_env key_press; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index d5c0264be..b9cac08a7 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -238,7 +238,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) DIS_SrInit(dis_attr_mask); */ /*instantiate a battery service*/ - //bas_register(); + bas_register(); /*instantiate the driver for button profile*/ //app_button_init(); #if (BUT_PROFILE_CFG) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h new file mode 100644 index 000000000..5bfb430fd --- /dev/null +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -0,0 +1,117 @@ +/** + +******************************************************************************* +********* +* +* @file app_button_int.h +* +* @brief button Service Application entry point +* +* Copyright (C) ESPRESSSIF 2016 +* Created by Yulong at 2016/10/17 +* +******************************************************************************* +**********/ + +#include "prf_defs.h" +#include "bt_prf_sys.h" +#include "bt_types.h" + +#if (BUT_PROFILE_CFG) + +/// Messages for Device Information Service Server +enum +{ + ///Add a BUTTON instance into the database + BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE), + ///Send key value confirm to APP so stable values can be erased + ///if correctly sent. + BLE_BUT_VAL_SEND_CFM_EVT, + ///Set the value of an attribute + BLE_BUT_SET_CHAR_VAL_REQ_EVT, + + ///Start the button notify Service Task - at connection + BLE_BUT_ENABLE_REQ_EVT, + + /// Inform the application that the profile service role task has been disabled after a disconnection + BLE_BUT_DISABLE_IND_EVT, + /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client + BLE_BUT_CHAR_WRITE_IND_EVT, + ///Error indication to Host + BLE_BUT_ERROR_IND_EVT, +}; + +/// Parameters of the @ref KEY_CREATE_DB_REQ message +typedef struct +{ + ///Database configuration + uint16_t features; +}tBUT_CRT_DB_REQ; + +/// Parameters of the @ref KEY_CREATE_DB_CFM message +typedef struct +{ + ///Status + uint8_t status; +}tBUT_CRT_DB_CFM; + +///Parameters of the @ref key_CFG_INDNTF_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; + /// characteristics + uint8_t char_code; +}tBUT_CFG_NTF_IND; + + +/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated +typedef struct +{ + /// Characteristic Code + //uint8_t char_code; + uint8_t conhdl; + uint8_t key_val_len; + uint8_t key_val[2]; +}tBUT_SND_CHAR_VAL_REQ; + +/// Parameters of the @ref KEY_ENABLE_REQ message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together + uint8_t sec_lvl; + ///Type of connection + uint8_t con_type; +}tBUT_ENABLE_REQ; + +///Parameters of the @ref KEY_VAL_SEND_CFM message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Status + uint8_t status; +}tBUT_VAL_SND_CFM; + + +/// Parameters of the @ref KEY_DISABLE_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; +}tBUT_DISABLE_IND; + + + +BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data); + + + +#endif ///BUT_PROFILE_CFG + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h index 5de417deb..3b048c3f1 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_wechat_util.h @@ -2,7 +2,7 @@ #define __APP_WECHAT_UTIL_H__ #include "prf_defs.h" -if (WX_AIRSYNC_CFG) +#if (WX_AIRSYNC_CFG) #include #include From fcf664276f83fba0251770f8118f32ded079ead3 Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 19 Oct 2016 01:55:14 -0400 Subject: [PATCH 02/31] component bt:added the stop adverstising API to the BTA module --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 23 +++++++++++++++- components/bt/bluedroid/bta/dm/bta_dm_api.c | 26 +++++++++++++++++++ components/bt/bluedroid/bta/dm/bta_dm_int.h | 4 +++ components/bt/bluedroid/bta/dm/bta_dm_main.c | 3 +++ components/bt/bluedroid/bta/include/bta_api.h | 2 ++ components/bt/bluedroid/stack/btm/btm_ble.c | 2 +- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 10 +++---- components/bt/bluedroid/stack/btm/btm_sec.c | 2 +- components/bt/bluedroid/stack/gatt/gatt_sr.c | 4 +-- components/bt/bluedroid/stack/smp/smp_l2c.c | 2 +- 10 files changed, 67 insertions(+), 11 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index ca673df09..e7b141f1a 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4800,6 +4800,27 @@ void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data) } +/******************************************************************************* +** +** Function bta_dm_ble_stop_advertising +** +** Description This function stop the BLE avdertising for the device. +** +** Parameters: void +** Explanation: This function added by Yulong at 2016/10/19 +*******************************************************************************/ +void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data) +{ + if(p_data->hdr.event != BTA_DM_API_BLE_STOP_ADV_EVT) + { + APPL_TRACE_ERROR("Invalid BTA event,cann't stop the BLE adverting\n"); + } + + btm_ble_stop_adv(); +} + + + #if BLE_PRIVACY_SPT == TRUE /******************************************************************************* ** @@ -4927,7 +4948,7 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) if (BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, p_data->ble_set_data_length.tx_data_length) != BTM_SUCCESS) { - APPL_TRACE_ERROR("%s failed", __FUNCTION__); + APPL_TRACE_ERROR("%s failed\n", __FUNCTION__); } } diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 5dd94b6ac..9579843c5 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -2089,6 +2089,32 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, } } +/******************************************************************************* +** +** Function BTA_DmBleStopAdvertising +** +** Description This function set the random address for the APP +** +** Parameters void +** +** Returns void +** +** +*******************************************************************************/ +extern void BTA_DmBleStopAdvertising(void) +{ + BT_HDR *p_msg; + + APPL_TRACE_API("BTA_DmBleStopAdvertising\n"); + + if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) + { + memset(p_msg, 0, sizeof(BT_HDR)); + p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT; + bta_sys_sendmsg(p_msg); + } +} + /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index 7b407440f..08cbb907d 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -95,6 +95,9 @@ enum /*******This event added by Yulong at 2016/9/9 to support the random address setting for the APP******/ BTA_DM_API_SET_RAND_ADDR_EVT, + /*******This event added by Yulong at 2016/10/19 to + support stop the ble advertising setting by the APP******/ + BTA_DM_API_BLE_STOP_ADV_EVT, #if BLE_PRIVACY_SPT == TRUE BTA_DM_API_LOCAL_PRIVACY_EVT, #endif @@ -1128,6 +1131,7 @@ extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data); extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data); extern void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data); extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index 40f8e0b21..ef4033134 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -92,6 +92,9 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = /*******This handler function added by Yulong at 2016/9/9 to support the random address setting for the APP******/ bta_dm_ble_set_rand_address, /*BTA_DM_API_SET_RAND_ADDR_EVT*/ + /*******This handler function added by Yulong at 2016/10/19 to + support stop the ble advertising setting by the APP******/ + bta_dm_ble_stop_advertising, /*BTA_DM_API_BLE_STOP_ADV_EVT*/ #if BLE_PRIVACY_SPT == TRUE bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ #endif diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index 4776d5954..8a5b11ad5 100755 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -2023,6 +2023,8 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb); +extern void BTA_DmBleStopAdvertising(void); + extern void BTA_DmSetRandAddress(BD_ADDR rand_addr); #endif diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index 974bbfbfa..f12b960c0 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -453,7 +453,7 @@ void BTM_BleConfirmReply (BD_ADDR bd_addr, UINT8 res) } p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; - BTM_TRACE_DEBUG ("%s", __func__); + BTM_TRACE_DEBUG ("%s\n", __func__); SMP_ConfirmReply(bd_addr, res_smp); } diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index a12e074ba..540baf571 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -659,7 +659,7 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode) #if BLE_PRIVACY_SPT == TRUE tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); /* if LE is not supported, return error */ if (!controller_get_interface()->supports_ble()) @@ -1333,7 +1333,7 @@ UINT8 *BTM_CheckAdvData( UINT8 *p_adv, UINT8 type, UINT8 *p_length) *******************************************************************************/ UINT16 BTM_BleReadDiscoverability() { - BTM_TRACE_API("%s", __FUNCTION__); + BTM_TRACE_API("%s\n", __FUNCTION__); return (btm_cb.ble_ctr_cb.inq_var.discoverable_mode); } @@ -1350,7 +1350,7 @@ UINT16 BTM_BleReadDiscoverability() *******************************************************************************/ UINT16 BTM_BleReadConnectability() { - BTM_TRACE_API ("%s", __FUNCTION__); + BTM_TRACE_API ("%s\n", __FUNCTION__); return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); } @@ -1782,7 +1782,7 @@ tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode) own_addr_type = p_addr_cb->own_addr_type; UINT16 adv_int_min, adv_int_max; - BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode); + BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x\n", __FUNCTION__, mode, combined_mode); /*** Check mode parameter ***/ if (mode > BTM_BLE_MAX_DISCOVERABLE) @@ -1800,7 +1800,7 @@ tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode) btu_stop_timer(&p_cb->fast_adv_timer); /* update adv params if start advertising */ - BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x ", evt_type, p_cb->evt_type); + BTM_TRACE_EVENT ("evt_type=0x%x p-cb->evt_type=0x%x\n ", evt_type, p_cb->evt_type); if (new_mode == BTM_BLE_ADV_ENABLE) { diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index 4ba8f2847..bf16e0fb3 100755 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -447,7 +447,7 @@ void BTM_SetPairableMode (BOOLEAN allow_pairing, BOOLEAN connect_only_paired) *******************************************************************************/ void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode) { - BTM_TRACE_API("%s: Mode : %u", __FUNCTION__, + BTM_TRACE_API("%s: Mode : %u\n", __FUNCTION__, secure_connections_only_mode); btm_cb.devcb.secure_connections_only = secure_connections_only_mode; diff --git a/components/bt/bluedroid/stack/gatt/gatt_sr.c b/components/bt/bluedroid/stack/gatt/gatt_sr.c index 7e6417bab..a48d8896f 100755 --- a/components/bt/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_sr.c @@ -919,7 +919,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data) } else if (len < GATT_MTU_REQ_MIN_LEN) { - GATT_TRACE_ERROR("invalid MTU request PDU received."); + GATT_TRACE_ERROR("invalid MTU request PDU received.\n"); gatt_send_error_rsp (p_tcb, GATT_INVALID_PDU, GATT_REQ_MTU, 0, FALSE); } else @@ -933,7 +933,7 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data) else p_tcb->payload_size = mtu; - GATT_TRACE_ERROR("MTU request PDU with MTU size %d", p_tcb->payload_size); + GATT_TRACE_ERROR("MTU request PDU with MTU size %d\n", p_tcb->payload_size); l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); diff --git a/components/bt/bluedroid/stack/smp/smp_l2c.c b/components/bt/bluedroid/stack/smp/smp_l2c.c index 0aa5ee095..8988983bd 100755 --- a/components/bt/bluedroid/stack/smp/smp_l2c.c +++ b/components/bt/bluedroid/stack/smp/smp_l2c.c @@ -296,7 +296,7 @@ static void smp_br_data_received(UINT16 channel, BD_ADDR bd_addr, BT_HDR *p_buf) tSMP_CB *p_cb = &smp_cb; UINT8 *p = (UINT8 *)(p_buf + 1) + p_buf->offset; UINT8 cmd ; - SMP_TRACE_EVENT ("SMDBG l2c %s", __func__); + SMP_TRACE_EVENT ("SMDBG l2c %s\n", __func__); STREAM_TO_UINT8(cmd, p); From 94442708f549e9148e6b16e551f5d4d6f40d49d3 Mon Sep 17 00:00:00 2001 From: yulong Date: Fri, 21 Oct 2016 02:16:01 -0400 Subject: [PATCH 03/31] component bt:added the advertising & scanning API to the bt project --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 22 ++++++ components/bt/bluedroid/bta/dm/bta_dm_api.c | 45 +++++++++++-- components/bt/bluedroid/bta/dm/bta_dm_int.h | 20 ++++++ components/bt/bluedroid/bta/dm/bta_dm_main.c | 1 + components/bt/bluedroid/bta/include/bta_api.h | 9 ++- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 67 ++++++++++++++++++- .../bt/bluedroid/stack/include/btm_ble_api.h | 18 +++++ .../bluedroid_demos/app_core/bt_app_api.c | 57 +++++++++++++++- .../bluedroid_demos/include/bt_app_api.h | 32 ++++++++- .../bluedroid_demos/include/bt_app_defs.h | 51 ++++++++++++++ 10 files changed, 312 insertions(+), 10 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index e7b141f1a..8ddc09dc3 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4888,6 +4888,28 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) BTA_DM_BLE_ADV_CHNL_MAP); } +/******************************************************************************* +** +** Function BTM_BleSetAdvParamsStartAdv +** +** Description This function is called to set all of the advertising parameters. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data) +{ + BTM_BleSetAdvParamsStartAdv(p_data->ble_set_adv_params_all.adv_int_min, + p_data->ble_set_adv_params_all.adv_int_max, + p_data->ble_set_adv_params_all.adv_type, + p_data->ble_set_adv_params_all.addr_type_own, + p_data->ble_set_adv_params_all.p_dir_bda, + p_data->ble_set_adv_params_all.channel_map, + p_data->ble_set_adv_params_all.adv_filter_policy); +} + /******************************************************************************* ** ** Function bta_dm_ble_set_adv_config diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 9579843c5..1765e936e 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -1004,6 +1004,42 @@ void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, } #endif } + +void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, + UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, + tBLE_BD_ADDR *p_dir_bda) +{ +#if BLE_INCLUDED == TRUE + tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg; + + APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max); + + if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL))) != NULL) + { + memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)); + + p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT; + + p_msg->adv_int_min = adv_int_min; + p_msg->adv_int_max = adv_int_max; + p_msg->adv_type = adv_type; + p_msg->addr_type_own = addr_type_own; + p_msg->channel_map = chnl_map; + p_msg->adv_filter_policy = adv_fil_pol; + if (p_dir_bda != NULL) + { + p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1); + memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); + } + + bta_sys_sendmsg(p_msg); + } +#endif +} + + + /******************************************************************************* ** BLE ADV data management API ********************************************************************************/ @@ -1498,7 +1534,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int, ** *******************************************************************************/ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) -{ +{ ///This function used the irk to generate the resolve address #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE tBTA_DM_API_LOCAL_PRIVACY *p_msg; @@ -1534,7 +1570,7 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params, tBTA_BLE_MULTI_ADV_CBACK *p_cback, void *p_ref) -{ +{ ///This function just used for vendor debug tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg; UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB); @@ -1572,6 +1608,7 @@ void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params, *******************************************************************************/ void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params) { + ///This function just used for vendor debug tBTA_DM_API_BLE_MULTI_ADV_PARAM *p_msg; UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM); @@ -1608,7 +1645,7 @@ void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params) void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp, tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_data) -{ +{ ///This function just used for vendor debug tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg; UINT16 len = sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ; @@ -1638,7 +1675,7 @@ void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp, ** Returns BTA_SUCCESS if command started sucessfully; otherwise failure. ** *******************************************************************************/ -void BTA_BleDisableAdvInstance (UINT8 inst_id) +void BTA_BleDisableAdvInstance (UINT8 inst_id) //this function just used for vendor debug { tBTA_DM_API_BLE_MULTI_ADV_DISABLE *p_msg; diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index 08cbb907d..f76446def 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -102,6 +102,10 @@ enum BTA_DM_API_LOCAL_PRIVACY_EVT, #endif BTA_DM_API_BLE_ADV_PARAM_EVT, + + /*******This event added by Yulong at 2016/10/20 to + support setting the ble advertising param by the APP******/ + BTA_DM_API_BLE_ADV_PARAM_All_EVT, BTA_DM_API_BLE_SET_ADV_CONFIG_EVT, BTA_DM_API_BLE_SET_SCAN_RSP_EVT, BTA_DM_API_BLE_BROADCAST_EVT, @@ -514,6 +518,20 @@ typedef struct tBLE_BD_ADDR *p_dir_bda; }tBTA_DM_API_BLE_ADV_PARAMS; +/* set adv parameter for BLE advertising */ +typedef struct +{ + BT_HDR hdr; + UINT16 adv_int_min; + UINT16 adv_int_max; + UINT8 adv_type; + tBLE_ADDR_TYPE addr_type_own; + tBTM_BLE_ADV_CHNL_MAP channel_map; + tBTM_BLE_AFP adv_filter_policy; + tBLE_BD_ADDR *p_dir_bda; +}tBTA_DM_API_BLE_ADV_PARAMS_ALL; + + typedef struct { BT_HDR hdr; @@ -733,6 +751,7 @@ typedef union tBTA_DM_API_ENABLE_PRIVACY ble_remote_privacy; tBTA_DM_API_LOCAL_PRIVACY ble_local_privacy; tBTA_DM_API_BLE_ADV_PARAMS ble_set_adv_params; + tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all; tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data; #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE tBTA_DM_API_SCAN_FILTER_PARAM_SETUP ble_scan_filt_param_setup; @@ -1134,6 +1153,7 @@ extern void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data); extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data); extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data); +extern void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data); extern void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index ef4033134..8b389c714 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -99,6 +99,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ #endif bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */ + bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */ bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */ bta_dm_ble_set_scan_rsp, /* BTA_DM_API_BLE_SET_SCAN_RSPT */ bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */ diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index 8a5b11ad5..167a47592 100755 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -921,7 +921,7 @@ typedef struct } tBTA_DM_BOND_CANCEL_CMPL; /* Union of all security callback structures */ -typedef union + typedef union { tBTA_DM_ENABLE enable; /* BTA enabled */ tBTA_DM_PIN_REQ pin_req; /* PIN request. */ @@ -1918,6 +1918,13 @@ extern void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, *******************************************************************************/ extern void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, tBLE_BD_ADDR *p_dir_bda); + +extern void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, + UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, + tBLE_BD_ADDR *p_dir_bda); + + /******************************************************************************* ** ** Function BTA_DmSearchExt diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 540baf571..838a0c8b2 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -256,7 +256,7 @@ void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy) BD_ADDR p_addr_ptr= {0}; UINT8 adv_mode = p_cb->adv_mode; - BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy"); + BTM_TRACE_EVENT ("BTM_BleUpdateAdvFilterPolicy\n"); if (!controller_get_interface()->supports_ble()) return; @@ -1074,6 +1074,69 @@ tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, return status; } + +/******************************************************************************* +** +** Function BTM_BleSetAdvParamsStartAdv +** +** Description This function is called to set all of the advertising parameters. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, + tBLE_ADDR_TYPE own_bda_type, tBLE_BD_ADDR *p_dir_bda, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp) +{ + tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; + tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; + tBTM_STATUS status = BTM_SUCCESS; + + BTM_TRACE_EVENT ("BTM_BleSetAdvParams\n"); + + if (!controller_get_interface()->supports_ble()) + return BTM_ILLEGAL_VALUE; + + if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || + !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) + { + return BTM_ILLEGAL_VALUE; + } + + p_cb->adv_interval_min = adv_int_min; + p_cb->adv_interval_max = adv_int_max; + p_cb->adv_chnl_map = chnl_map; + p_addr_cb->own_addr_type = own_bda_type; + p_cb->evt_type = adv_type; + p_cb->adv_mode = BTM_BLE_ADV_ENABLE; + + if (p_dir_bda) + { + memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); + } + + BTM_TRACE_EVENT ("update params for an active adv\n"); + + btm_ble_stop_adv(); + + /* update adv params */ + btsnd_hcic_ble_write_adv_params (adv_int_min, + adv_int_max, + adv_type, + own_bda_type, + p_dir_bda->type, + p_dir_bda->bda, + chnl_map, + p_cb->afp); + + btm_ble_start_adv(); +} + + + + /******************************************************************************* ** ** Function BTM_BleReadAdvParams @@ -1888,7 +1951,7 @@ tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode) own_addr_type = p_addr_cb->own_addr_type; UINT16 adv_int_min, adv_int_max; - BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x", __FUNCTION__, mode, combined_mode); + BTM_TRACE_EVENT ("%s mode=0x%0x combined_mode=0x%x\n", __FUNCTION__, mode, combined_mode); /*** Check mode parameter ***/ if (mode > BTM_BLE_MAX_CONNECTABLE) diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index ce55ef6c5..208edbf1e 100755 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -941,6 +941,24 @@ BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, tBLE_BD_ADDR *p_dir_bda, tBTM_BLE_ADV_CHNL_MAP chnl_map); + + +/******************************************************************************* +** +** Function BTM_BleSetAdvParamsStartAdv +** +** Description This function is called to set all of the advertising parameters. +** +** Parameters: None. +** +** Returns void +** +*******************************************************************************/ +tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, + tBLE_ADDR_TYPE own_bda_type, tBLE_BD_ADDR *p_dir_bda, + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp); + + /******************************************************************************* ** ** Function BTM_BleWriteAdvData diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 687c5dae4..3ecf3012e 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -13,7 +13,62 @@ */ #include "bt_app_api.h" +#include "btm_ble_api.h" + +void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, + tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) +{ + if(adv_data != NULL) + { + ESP_AppBleConfigadvData(adv_data, p_adv_data_cback); + }else{ + LOG_ERROR("The adv_data is NULL\n"); + } + + if(++adv_data != NULL) + { + ESP_AppBleSetScanRsp(adv_data,NULL); + } + +} + + +void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) +{ + if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || + !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) + { + LOG_ERROR("Invalid advertisting interval parameters.\n"); + return ; + } + + if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) && + (ble_adv_params->adv_type > API_BROADCASTER_MODE) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + if ((ble_adv_params->adv_filter_policy < API_ADV_NON_CONN) && + (ble_adv_params->adv_filter_policy > API_ADV_DIRECT) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + /// + BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, + ble_adv_params->adv_int_max, + ble_adv_params->adv_type, + ble_adv_params->addr_type_own, + ble_adv_params->channel_map, + ble_adv_params->adv_filter_policy, + ble_adv_params->p_dir_bda); + + +} + + - diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index 41c573da1..e26bd398b 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -12,7 +12,35 @@ **************************************************************************************** */ +#include "bt_types.h" +#include "bt_app_defs.h" - +typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; +typedef tBTA_STATUS tAPI_STATUS; - +extern void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, + tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + +extern void API_Ble_SetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg, + tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + +extern void API_Ble_SetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_mode, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); + + +extern void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params); + +extern void API_Ble_AppStopAdvertising(void); + +extern void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, + UINT16 max_int, UINT16 latency, UINT16 timeout); + +extern void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length); + +extern void API_Ble_SetRandAddress(BD_ADDR rand_addr); + +extern void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable); + + +void API_Ble_PrfEnable(); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index 1405cb091..eeb036d32 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -1,6 +1,12 @@ #include "bta_api.h" #include "btm_ble_api.h" +#define API_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ + + +#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == API_BLE_CONN_PARAM_UNDEF)) + + enum { BLE_ADV_DATA_IDX, @@ -8,12 +14,57 @@ enum ADV_SCAN_IDX_MAX }; +/// Advertising mode +enum api_adv_type +{ + /// Mode in non-discoverable + API_NON_DISCOVERABLE, + /// Mode in general discoverable + API_GEN_DISCOVERABLE, + /// Mode in limited discoverable + API_LIM_DISCOVERABLE, + /// Broadcaster mode which is a non discoverable and non connectable mode. + API_BROADCASTER_MODE, +}; + +enum api_adv_filter +{ + /// Start non connectable advertising + API_ADV_NON_CONN, + /// Start undirected connectable advertising + API_ADV_UNDIRECT, + /// Start directed connectable advertising + API_ADV_DIRECT_LOW_DUTY, + /// Start directed connectable advertising + API_ADV_DIRECT +}; + + typedef struct { char *adv_name; //set the device name to be sent on the advertising tBTA_BLE_ADV_DATA ble_adv_data; }tESP_BLE_ADV_DATA; +typedef struct +{ + UINT16 adv_int_min; + UINT16 adv_int_max; + tBLE_BD_ADDR *p_dir_bda; +}tESP_BLE_ADV_PARAM; + +typedef struct +{ + UINT16 adv_int_min; + UINT16 adv_int_max; + UINT8 adv_type; + tBLE_ADDR_TYPE addr_type_own; + tBTM_BLE_ADV_CHNL_MAP channel_map; + tBTM_BLE_AFP adv_filter_policy; + tBLE_BD_ADDR *p_dir_bda; +}tESP_API_BLE_ADV_PARAMS_ALL; + + extern void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); From 78d1fd53065d18e4bdea672f6a30c2b3f1bddcd6 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 25 Oct 2016 05:07:36 -0400 Subject: [PATCH 04/31] component bt:Added the BLE scan API to the bt project --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 25 +++++++- components/bt/bluedroid/bta/dm/bta_dm_api.c | 42 ++++++++++++- components/bt/bluedroid/bta/dm/bta_dm_int.h | 18 ++++++ components/bt/bluedroid/bta/dm/bta_dm_main.c | 3 +- components/bt/bluedroid/bta/include/bta_api.h | 21 +++++++ .../bluedroid/profiles/std/include/prf_defs.h | 4 +- .../bt/bluedroid/stack/btm/btm_ble_bgconn.c | 2 +- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 59 ++++++++++++++++++- components/bt/bluedroid/stack/gap/gap_ble.c | 8 +-- components/bt/bluedroid/stack/gatt/gatt_api.c | 4 +- .../bt/bluedroid/stack/include/btm_ble_api.h | 24 ++++++++ 11 files changed, 194 insertions(+), 16 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 8ddc09dc3..a48f51225 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4738,6 +4738,27 @@ void bta_dm_ble_set_scan_params(tBTA_DM_MSG *p_data) p_data->ble_set_scan_params.scan_param_setup_cback); } +/******************************************************************************* +** +** Function bta_dm_ble_set_scan_fil_params +** +** Description This function sets BLE scan filter & parameters. +** +** Parameters: +** +*******************************************************************************/ +void bta_dm_ble_set_scan_fil_params(tBTA_DM_MSG *p_data) +{ + BTM_BleSetScanFilterParams (p_data->ble_set_scan_fil_params.client_if, + p_data->ble_set_scan_fil_params.scan_int, + p_data->ble_set_scan_fil_params.scan_window, + p_data->ble_set_scan_fil_params.scan_mode, + p_data->ble_set_scan_fil_params.addr_type_own, + p_data->ble_set_scan_fil_params.scan_filter_policy, + p_data->ble_set_scan_fil_params.scan_param_setup_cback); +} + + /******************************************************************************* ** ** Function bta_dm_ble_set_conn_scan_params @@ -4857,7 +4878,7 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data) bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb))!= BTM_CMD_STARTED) { tBTA_DM_SEARCH data; - APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d",__FUNCTION__,status); + APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d\n",__FUNCTION__,status); data.inq_cmpl.num_resps = 0; if (bta_dm_search_cb.p_scan_cback) { @@ -4890,7 +4911,7 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) /******************************************************************************* ** -** Function BTM_BleSetAdvParamsStartAdv +** Function bta_dm_ble_set_adv_params_all ** ** Description This function is called to set all of the advertising parameters. ** diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 1765e936e..16cba33ed 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -860,6 +860,8 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res) } #endif } + + /******************************************************************************* ** ** Function BTA_DmSetBlePrefConnParams @@ -965,6 +967,44 @@ void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, } } + +/******************************************************************************* +** +** Function BTA_DmSetBleScanFilterParams +** +** Description This function is called to set scan parameters +** +** Parameters: client_if - Client IF +** scan_interval - scan interval +** scan_window - scan window +** scan_mode - scan mode +** scan_param_setup_status_cback - Set scan param status callback +** +** Returns void +** +*******************************************************************************/ +void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy, + UINT8 addr_type_own, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +{ + tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) + { + memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS)); + p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT; + p_msg->client_if = client_if; + p_msg->scan_int = scan_interval; + p_msg->scan_window = scan_window; + p_msg->scan_mode = scan_mode; + p_msg->addr_type_own = addr_type_own; + p_msg->scan_filter_policy = scan_fil_poilcy; + p_msg->scan_param_setup_cback = scan_param_setup_cback; + } + + +} + /******************************************************************************* ** ** Function BTA_DmSetBleAdvParams @@ -1930,7 +1970,7 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb { #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg; - APPL_TRACE_API ("BTA_DmEnableScanFilter: %d", action); + APPL_TRACE_API ("BTA_DmEnableScanFilter: %d\n", action); UINT16 len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/dm/bta_dm_int.h index f76446def..e098353c6 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -90,6 +90,9 @@ enum BTA_DM_API_BLE_CONN_PARAM_EVT, BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT, BTA_DM_API_BLE_SCAN_PARAM_EVT, + /*******This event added by Yulong at 2016/10/25 to + support the scan filter setting for the APP******/ + BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT, BTA_DM_API_BLE_OBSERVE_EVT, BTA_DM_API_UPDATE_CONN_PARAM_EVT, /*******This event added by Yulong at 2016/9/9 to @@ -476,6 +479,19 @@ typedef struct tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback; }tBTA_DM_API_BLE_SCAN_PARAMS; +typedef struct +{ + BT_HDR hdr; + tBTA_GATTC_IF client_if; + UINT32 scan_int; + UINT32 scan_window; + tBLE_SCAN_MODE scan_mode; + UINT8 addr_type_own; + UINT8 scan_filter_policy; + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback; +}tBTA_DM_API_BLE_SCAN_FILTER_PARAMS; + + /* set scan parameter for BLE connections */ typedef struct { @@ -747,6 +763,7 @@ typedef union tBTA_DM_API_BLE_CONN_PARAMS ble_set_conn_params; tBTA_DM_API_BLE_CONN_SCAN_PARAMS ble_set_conn_scan_params; tBTA_DM_API_BLE_SCAN_PARAMS ble_set_scan_params; + tBTA_DM_API_BLE_SCAN_FILTER_PARAMS ble_set_scan_fil_params; tBTA_DM_API_BLE_OBSERVE ble_observe; tBTA_DM_API_ENABLE_PRIVACY ble_remote_privacy; tBTA_DM_API_LOCAL_PRIVACY ble_local_privacy; @@ -1145,6 +1162,7 @@ extern void bta_dm_security_grant (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_bg_conn_type (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_scan_params(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_set_scan_fil_params(tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_conn_scan_params (tBTA_DM_MSG *p_data); extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data); extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index 8b389c714..e896b31f0 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -87,7 +87,8 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = bta_dm_ble_set_conn_params, /* BTA_DM_API_BLE_CONN_PARAM_EVT */ bta_dm_ble_set_conn_scan_params, /* BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT */ bta_dm_ble_set_scan_params, /* BTA_DM_API_BLE_SCAN_PARAM_EVT */ - bta_dm_ble_observe, + bta_dm_ble_set_scan_fil_params, /* BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT */ + bta_dm_ble_observe, /* BTA_DM_API_BLE_OBSERVE_EVT*/ bta_dm_ble_update_conn_params, /* BTA_DM_API_UPDATE_CONN_PARAM_EVT */ /*******This handler function added by Yulong at 2016/9/9 to support the random address setting for the APP******/ diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index 167a47592..b1bd35eed 100755 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -1901,6 +1901,27 @@ extern void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, tBLE_SCAN_MODE scan_mode, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_status_cback); + +/******************************************************************************* +** +** Function BTA_DmSetBleScanFilterParams +** +** Description This function is called to set scan parameters +** +** Parameters: client_if - Client IF +** scan_interval - scan interval +** scan_window - scan window +** scan_mode - scan mode +** scan_param_setup_status_cback - Set scan param status callback +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, + UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy, + UINT8 addr_type_own, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); + + /******************************************************************************* ** ** Function BTA_DmSetBleAdvParams diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 921477d02..351657b6b 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -26,9 +26,9 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG 1 +#define WX_AIRSYNC_CFG 0 #define BUT_PROFILE_CFG 1 -#define HIDD_LE_PROFILE_CFG 1 +#define HIDD_LE_PROFILE_CFG 0 /* * Type Definition diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index b24eee473..b5eef2ecc 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -120,7 +120,7 @@ void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) UINT32 scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; UINT32 scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); p_inq->sfp = scan_policy; p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE ? BTM_BLE_SCAN_MODE_ACTI : p_inq->scan_type; diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 838a0c8b2..2c5829966 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -351,7 +351,7 @@ tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT8 duration, UINT32 scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval; UINT32 scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window; - BTM_TRACE_EVENT ("%s : scan_type:%d, %d, %d", __func__, btm_cb.btm_inq_vars.scan_type, + BTM_TRACE_EVENT ("%s : scan_type:%d, %d, %d\n", __func__, btm_cb.btm_inq_vars.scan_type, p_inq->scan_interval, p_inq->scan_window); if (!controller_get_interface()->supports_ble()) @@ -1193,7 +1193,7 @@ void BTM_BleSetScanParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_ UINT32 max_scan_interval; UINT32 max_scan_window; - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); if (!controller_get_interface()->supports_ble()) return; @@ -1226,12 +1226,65 @@ void BTM_BleSetScanParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_ if (scan_setup_status_cback != NULL) scan_setup_status_cback(client_if, BTM_ILLEGAL_VALUE); - BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d", + BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d\n", scan_interval, scan_window); } } +void BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, + tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, tBTM_BLE_SFP scan_filter_policy, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback) +{ + tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; + UINT32 max_scan_interval; + UINT32 max_scan_window; + + BTM_TRACE_EVENT ("%s\n", __func__); + if (!controller_get_interface()->supports_ble()) + return; + + /* If not supporting extended scan support, use the older range for checking */ + if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) + { + max_scan_interval = BTM_BLE_SCAN_INT_MAX; + max_scan_window = BTM_BLE_SCAN_WIN_MAX; + } + else + { + /* If supporting extended scan support, use the new extended range for checking */ + max_scan_interval = BTM_BLE_EXT_SCAN_INT_MAX; + max_scan_window = BTM_BLE_EXT_SCAN_WIN_MAX; + } + + if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, max_scan_interval) && + BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, max_scan_window) && + (scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS)) + { + p_cb->scan_type = scan_mode; + p_cb->scan_interval = scan_interval; + p_cb->scan_window = scan_window; + p_cb->sfp = scan_filter_policy; + + btsnd_hcic_ble_set_scan_params(p_cb->scan_type, (UINT16)scan_interval, + (UINT16)scan_window, + addr_type_own, + scan_filter_policy); + + if (scan_setup_status_cback != NULL) + scan_setup_status_cback(client_if, BTM_SUCCESS); + } + else + { + if (scan_setup_status_cback != NULL) + scan_setup_status_cback(client_if, BTM_ILLEGAL_VALUE); + + BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d\n", + scan_interval, scan_window); + } +} + + /******************************************************************************* ** ** Function BTM_BleWriteScanRsp diff --git a/components/bt/bluedroid/stack/gap/gap_ble.c b/components/bt/bluedroid/stack/gap/gap_ble.c index 16ef02dad..690f6982b 100755 --- a/components/bt/bluedroid/stack/gap/gap_ble.c +++ b/components/bt/bluedroid/stack/gap/gap_ble.c @@ -464,13 +464,13 @@ void GAP_BleAttrDBUpdate(UINT16 attr_uuid, tGAP_BLE_ATTR_VALUE *p_value) tGAP_ATTR *p_db_attr = gap_cb.gatt_attr; UINT8 i = 0; - GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x", attr_uuid); + GAP_TRACE_EVENT("GAP_BleAttrDBUpdate attr_uuid=0x%04x\n", attr_uuid); for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) { if (p_db_attr->uuid == attr_uuid) { - GAP_TRACE_EVENT("Found attr_uuid=0x%04x", attr_uuid); + GAP_TRACE_EVENT("Found attr_uuid=0x%04x\n", attr_uuid); switch (attr_uuid) { @@ -630,7 +630,7 @@ static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS op_type = p_clcb->cl_op_uuid; - GAP_TRACE_EVENT ("gap_ble_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x read_type: 0x%04x", op, status, op_type); + GAP_TRACE_EVENT ("gap_ble_c_cmpl_cback() - op_code: 0x%02x status: 0x%02x read_type: 0x%04x\n", op, status, op_type); /* Currently we only issue read commands */ if (op != GATTC_OPTYPE_READ) return; @@ -660,7 +660,7 @@ static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS break; case GATT_UUID_GAP_DEVICE_NAME: - GAP_TRACE_EVENT ("GATT_UUID_GAP_DEVICE_NAME"); + GAP_TRACE_EVENT ("GATT_UUID_GAP_DEVICE_NAME\n"); len = (UINT16)strlen((char *)pp); if (len > GAP_CHAR_DEV_NAME_SIZE) len = GAP_CHAR_DEV_NAME_SIZE; diff --git a/components/bt/bluedroid/stack/gatt/gatt_api.c b/components/bt/bluedroid/stack/gatt/gatt_api.c index d5ddb19b8..ee140057a 100755 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -680,7 +680,7 @@ tGATT_STATUS GATTS_HandleValueNotification (UINT16 conn_id, UINT16 attr_handle, if ( (p_reg == NULL) || (p_tcb == NULL)) { - GATT_TRACE_ERROR ("GATTS_HandleValueNotification Unknown conn_id: %u ", conn_id); + GATT_TRACE_ERROR ("GATTS_HandleValueNotification Unknown conn_id: %u \n", conn_id); return(tGATT_STATUS) GATT_INVALID_CONN_ID; } @@ -689,7 +689,7 @@ tGATT_STATUS GATTS_HandleValueNotification (UINT16 conn_id, UINT16 attr_handle, notif.handle = attr_handle; notif.len = val_len; memcpy (notif.value, p_val, val_len); - notif.auth_req = GATT_AUTH_REQ_NONE;; + notif.auth_req = GATT_AUTH_REQ_NONE; if ((p_buf = attp_build_sr_msg (p_tcb, GATT_HANDLE_VALUE_NOTIF, (tGATT_SR_MSG *)¬if)) != NULL) diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index 208edbf1e..966b85572 100755 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -1029,6 +1029,30 @@ void BTM_BleSetScanParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, tBLE_SCAN_MODE scan_type, tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); + + +/******************************************************************************* +** +** Function BTM_BleSetScanFilterParams +** +** Description This function is called to set Scan Filter & parameters. +** +** Parameters client_if - Client IF value +** scan_interval - Scan interval +** scan_window - Scan window +** scan_type - Scan type +** addr_type_own - owner address type +** scan_filter_policy - scan filter policy +** scan_setup_status_cback - Scan setup status callback +** +** Returns void +** +*******************************************************************************/ +void BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, + tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, tBTM_BLE_SFP scan_filter_policy, + tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); + + /******************************************************************************* ** ** Function BTM_BleGetVendorCapabilities From 86dc0ae80858e1658626f3ad7a25693239cf3060 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 25 Oct 2016 09:12:10 -0400 Subject: [PATCH 05/31] component bt: Added the param len & connect API to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 95 +++++++++++++++++++ .../bluedroid_demos/include/bt_app_api.h | 3 + .../bluedroid_demos/include/bt_app_defs.h | 9 ++ 3 files changed, 107 insertions(+) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 3ecf3012e..71dce9f55 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -14,6 +14,8 @@ #include "bt_app_api.h" #include "btm_ble_api.h" +//#include "btm_ble_int.h" + void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) @@ -69,6 +71,99 @@ void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) } +void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_if, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +{ + if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && + API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && + (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) + { + BTA_DmSetBleScanFilterParams(client_if, + scan_params->scan_intv, + scan_params->scan_win, + scan_params->scan_type, + scan_params->scan_fil_policy, + scan_params->addr_type_own, + scan_param_setup_cback); + } +} + + +void API_Ble_StartScanning (UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb) +{ + if((duration != 0) && (p_results_cb != NULL)) + { + ///Start scan the device + BTA_DmBleObserve(true, duration, p_results_cb); + }else{ + LOG_ERROR("The scan duration or p_results_cb invalid\n"); + } +} + +void API_Ble_AppStopAdvertising(void) +{ + bool stop_adv = true; + + BTA_DmBleBroadcast(stop_adv); +} + +void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, + UINT16 max_int, UINT16 latency, UINT16 timeout) +{ + if (min_int > max_int){ + min_int = max_int; + } + + if (min_int < BTM_BLE_CONN_INT_MIN || max_int > BTM_BLE_CONN_INT_MAX){ + LOG_ERROR("Invalid interval value.\n"); + } + + BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int, + latency, timeout); + +} + +void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length) +{ + if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ + tx_data_length = BTM_BLE_DATA_SIZE_MAX; + }else if (tx_data_length < BTM_BLE_DATA_SIZE_MIN){ + tx_data_length = BTM_BLE_DATA_SIZE_MIN; + } + + BTA_DmBleSetDataLength(remote_device, tx_data_length); +} + + +void API_Ble_SetRandAddress(BD_ADDR rand_addr) +{ + if (rand_addr != NULL){ + BTA_DmSetRandAddress(rand_addr); + }else{ + LOG_ERROR("Invalid randrom address.\n"); + } +} + +void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable) +{ + BTA_DmBleConfigLocalPrivacy(privacy_enable); +} + + + + +void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) +{ + if (p_app_uuid != NULL) + { + BTA_GATTC_AppRegister(p_app_uuid, *p_client_cb); + }else{ + LOG_ERROR("The app uuid invalid.\n"); + } +} + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index e26bd398b..3cb14974a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -14,6 +14,7 @@ #include "bt_types.h" #include "bt_app_defs.h" +#include "bta_gatt_api.h" typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; typedef tBTA_STATUS tAPI_STATUS; @@ -42,5 +43,7 @@ extern void API_Ble_SetRandAddress(BD_ADDR rand_addr); extern void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable); +extern void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); + void API_Ble_PrfEnable(); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index eeb036d32..d2aa9c2f4 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -64,6 +64,15 @@ typedef struct tBLE_BD_ADDR *p_dir_bda; }tESP_API_BLE_ADV_PARAMS_ALL; +typedef struct +{ + UINT8 scan_type; + UINT16 scan_intv; + UINT16 scan_win; + UINT8 addr_type_own; + UINT8 scan_fil_policy; +}tESP_BLE_SCAN_PARAMS; + extern void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); From fd064e5d8814d9f8fda3a25baab61619fc0795b6 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 25 Oct 2016 23:56:45 -0400 Subject: [PATCH 06/31] component bt: Added the Gatt client API to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 133 +++++++++++++++++- .../bluedroid_demos/include/bt_app_api.h | 106 +++++++++++--- 2 files changed, 222 insertions(+), 17 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 71dce9f55..8e2e7ffca 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -152,7 +152,7 @@ void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable) -void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) +void API_Ble_GattcAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) { if (p_app_uuid != NULL) { @@ -162,6 +162,137 @@ void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_ } } +void API_Ble_GattcAppDeregister(tBTA_GATTC_IF client_if) +{ + +} + +void API_Ble_GattcOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, + BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport) +{ + +} + +void API_GattcCancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + +} + +void API_Ble_GattcClose(UINT16 conn_id) +{ + +} + + +void API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu) +{ + +} + +tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property) +{ + +} + +tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_start_char_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property) +{ + +} + +tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_start_descr_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result) +{ + +} + +tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result) +{ + +} + +void API_Ble_GattcReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + + +void API_Ble_GattcReadCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_id, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + +void API_Ble_GattcReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + +void API_Ble_GattcWriteCharValue ( UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATTC_WRITE_TYPE write_type, + UINT16 len, + UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + +void API_Ble_GattcWriteCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, + tBTA_GATTC_WRITE_TYPE write_type, + tBTA_GATT_UNFMT *p_data, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + + +void API_Ble_GattcPrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + UINT16 offset, UINT16 len, UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req) +{ + +} + +void API_Ble_GattcExecuteWrite (UINT16 conn_id, BOOLEAN is_execute) +{ + +} + +void API_Ble_GattcSendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id) +{ + +} + +tBTA_GATT_STATUS API_Ble_GattcRegisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR bda, + tBTA_GATTC_CHAR_ID *p_char_id) +{ + +} + +tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR bda, + tBTA_GATTC_CHAR_ID *p_char_id) +{ + +} + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index 3cb14974a..fad2e79be 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -16,34 +16,108 @@ #include "bt_app_defs.h" #include "bta_gatt_api.h" -typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; +typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; typedef tBTA_STATUS tAPI_STATUS; -extern void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, - tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); +extern void API_Ble_AppConfigAdvData (tESP_BLE_ADV_DATA *adv_data, + tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); extern void API_Ble_SetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); - -extern void API_Ble_SetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, - UINT32 scan_window, tBLE_SCAN_MODE scan_mode, - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); + tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); -extern void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params); +extern void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_if, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); -extern void API_Ble_AppStopAdvertising(void); +extern void API_Ble_StartScanning (UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb); -extern void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, + +extern void API_Ble_AppStartAdvertising (tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params); + +extern void API_Ble_AppStopAdvertising (void); + +extern void API_Ble_AppUpdateConnectionParams (BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int, UINT16 latency, UINT16 timeout); -extern void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length); +extern void API_Ble_SetPacketDataLength (BD_ADDR remote_device, UINT16 tx_data_length); -extern void API_Ble_SetRandAddress(BD_ADDR rand_addr); +extern void API_Ble_SetRandAddress (BD_ADDR rand_addr); -extern void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable); +extern void API_Ble_ConfigLocalPrivacy (BOOLEAN privacy_enable); -extern void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); +extern void API_Ble_GattcAppRegister (tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); + +extern void API_Ble_GattcAppDeregister (tBTA_GATTC_IF client_if); + +extern void API_Ble_GattcOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, + BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); + +extern void API_GattcCancelOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + +extern void API_Ble_GattcClose (UINT16 conn_id); + +extern void API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu); + +extern void API_Ble_GattcServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid); + +extern tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property); + +extern tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_start_char_id, + tBT_UUID *p_char_uuid_cond, + tBTA_GATTC_CHAR_ID *p_char_result, + tBTA_GATT_CHAR_PROP *p_property); + +extern tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_start_descr_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); + +extern tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, + tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result); + +extern void API_Ble_GattcReadCharacteristic (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcReadCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_id, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcReadMultiple (UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcWriteCharValue ( UINT16 conn_id, + tBTA_GATTC_CHAR_ID *p_char_id, + tBTA_GATTC_WRITE_TYPE write_type, + UINT16 len, + UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcWriteCharDescr (UINT16 conn_id, + tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, + tBTA_GATTC_WRITE_TYPE write_type, + tBTA_GATT_UNFMT *p_data, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcPrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + UINT16 offset, UINT16 len, UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req); + +extern void API_Ble_GattcExecuteWrite (UINT16 conn_id, BOOLEAN is_execute); + +extern void API_Ble_GattcSendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id); + +extern tBTA_GATT_STATUS API_Ble_GattcRegisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR bda, + tBTA_GATTC_CHAR_ID *p_char_id); + +extern tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_if, + BD_ADDR bda, + tBTA_GATTC_CHAR_ID *p_char_id); -void API_Ble_PrfEnable(); + +void API_Ble_PrfEnable (void); From a799bb85197f7b67568aaec38e9cb8b2c51c9a4d Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 26 Oct 2016 05:50:23 -0400 Subject: [PATCH 07/31] component bt:Finished Adding the GATTC API to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 220 ++++++++++++++++-- .../bluedroid_demos/include/bt_app_api.h | 55 ++++- 2 files changed, 254 insertions(+), 21 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 8e2e7ffca..70f1098b0 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -164,39 +164,93 @@ void API_Ble_GattcAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_c void API_Ble_GattcAppDeregister(tBTA_GATTC_IF client_if) { - + BTA_GATTC_AppDeregister(client_if); } -void API_Ble_GattcOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, - BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport) +void API_Ble_GattcOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { + tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; + if(remote_bda == NULL ){ + LOG_ERROR("Invaild address data \n"); + return; + } + + BTA_GATTC_Open(client_if, remote_bda, is_direct, transport); + + + } void API_GattcCancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { - + if(remote_bda == NULL ){ + LOG_ERROR("Invaild address data \n"); + return; + } + + BTA_GATTC_CancelOpen(client_if, remote_bda, is_direct); } void API_Ble_GattcClose(UINT16 conn_id) { - + BTA_GATTC_Close(conn_id); } -void API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu) +tGATT_STATUS API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu) { + if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ + LOG_ERROR("Invalid MTU parameters\n"); + return GATT_ILLEGAL_PARAMETER; + } + + BTA_GATTC_ConfigureMTU (conn_id, mtu); } +void API_Ble_GattcServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid) +{ + BTA_GATTC_ServiceSearchRequest(conn_id, p_srvc_uuid); +} + + tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, tBT_UUID *p_char_uuid_cond, tBTA_GATTC_CHAR_ID *p_char_result, tBTA_GATT_CHAR_PROP *p_property) { + tBTA_GATT_STATUS status = 0; + + if (!p_srvc_id || !p_char_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstChar (conn_id, p_srvc_id, p_char_uuid_cond, + p_char_result, p_property); + + return status; + } +tBTA_GATT_STATUS API_Ble_GattcGetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result) +{ + tBTA_GATT_STATUS status; + + if (!p_char_id || !p_descr_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstCharDescr (conn_id, p_char_id, p_descr_uuid_cond, p_descr_result); + + return status; + +} + + tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_start_char_id, tBT_UUID *p_char_uuid_cond, @@ -204,6 +258,17 @@ tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, tBTA_GATT_CHAR_PROP *p_property) { + tBTA_GATT_STATUS status; + + if (!p_start_char_id || !p_char_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextChar(conn_id, p_start_char_id, p_char_uuid_cond, + p_char_result, p_property); + + return status; + } tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, @@ -211,19 +276,54 @@ tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, tBT_UUID *p_descr_uuid_cond, tBTA_GATTC_CHAR_DESCR_ID *p_descr_result) { + tBTA_GATT_STATUS status; + + if (!p_start_descr_id || !p_descr_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextCharDescr (conn_id, p_start_descr_id, p_descr_uuid_cond, p_descr_result); + + return status; } -tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, +tBTA_GATT_STATUS API_Ble_GattcGetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result) { + tBTA_GATT_STATUS status; + + if (!p_srvc_id || !p_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstIncludedService(conn_id, p_srvc_id, p_uuid_cond, p_result); + + return status; } +tBTA_GATT_STATUS API_Ble_GattcGetNextIncludedService(UINT16 conn_id, + tBTA_GATTC_INCL_SVC_ID *p_start_id, + tBT_UUID *p_uuid_cond, + tBTA_GATTC_INCL_SVC_ID *p_result) +{ + tBTA_GATT_STATUS status; + + if (!p_start_id || !p_result){ + return BTA_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextIncludedService(conn_id, p_start_id, p_uuid_cond, p_result); + + return status; +} + + void API_Ble_GattcReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_ReadCharacteristic(conn_id, p_char_id, auth_req); } @@ -231,13 +331,13 @@ void API_Ble_GattcReadCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_DESCR_ID *p_descr_id, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_ReadCharDescr (conn_id, p_descr_id, auth_req); } void API_Ble_GattcReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_ReadMultiple(conn_id, p_read_multi, auth_req); } void API_Ble_GattcWriteCharValue ( UINT16 conn_id, @@ -247,7 +347,7 @@ void API_Ble_GattcWriteCharValue ( UINT16 conn_id, UINT8 *p_value, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_WriteCharValue (conn_id, p_char_id, write_type, len, p_value, auth_req); } void API_Ble_GattcWriteCharDescr (UINT16 conn_id, @@ -256,7 +356,7 @@ void API_Ble_GattcWriteCharDescr (UINT16 conn_id, tBTA_GATT_UNFMT *p_data, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_WriteCharDescr (conn_id, p_char_descr_id, write_type, p_data, auth_req); } @@ -264,37 +364,123 @@ void API_Ble_GattcPrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, UINT16 offset, UINT16 len, UINT8 *p_value, tBTA_GATT_AUTH_REQ auth_req) { - + BTA_GATTC_PrepareWrite (conn_id, p_char_id, offset, len, p_value, auth_req); } void API_Ble_GattcExecuteWrite (UINT16 conn_id, BOOLEAN is_execute) { - + BTA_GATTC_ExecuteWrite (conn_id, is_execute); } void API_Ble_GattcSendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id) { - + BTA_GATTC_SendIndConfirm (conn_id, p_char_id); } tBTA_GATT_STATUS API_Ble_GattcRegisterForNotifications (tBTA_GATTC_IF client_if, BD_ADDR bda, tBTA_GATTC_CHAR_ID *p_char_id) { - + tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; + status = BTA_GATTC_RegisterForNotifications (client_if, bda, p_char_id); + + return status; } tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_if, BD_ADDR bda, tBTA_GATTC_CHAR_ID *p_char_id) { + tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; + status = BTA_GATTC_DeregisterForNotifications (client_if, bda, p_char_id); + + return status; +} + +void API_Ble_GattsDisable(void) +{ + // TODO: +} + +void API_Ble_GattsAppDeregister(tBTA_GATTS_IF server_if) +{ + // TODO: +} + +void API_Ble_GattsCreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, + UINT16 num_handle, BOOLEAN is_primary) +{ + // TODO: +} + + +void API_Ble_GattsAddIncludeService(UINT16 service_id, UINT16 included_service_id) +{ + // TODO: +} + + +void API_Ble_GattsAddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, + tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property) +{ + // TODO: +} + +void API_Ble_GattsAddCharDescriptor (UINT16 service_id, + tBTA_GATT_PERM perm, + tBT_UUID * p_descr_uuid) +{ } +void API_Ble_GattsDeleteService(UINT16 service_id) +{ + // TODO: +} + +void API_Ble_GattsStartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport) +{ + +} + + +void API_Ble_GattsStopService(UINT16 service_id) +{ + // TODO: +} + + +void API_Ble_GattsHandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len, + UINT8 *p_data, BOOLEAN need_confirm) +{ + // TODO: +} + +void API_Ble_GattsSendRsp (UINT16 conn_id, UINT32 trans_id, + tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg) +{ + // TODO: +} + +void API_Ble_GattsOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct, + tBTA_GATT_TRANSPORT transport) +{ + // TODO: +} + +void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + // TODO: +} + +void API_Ble_GattsClose(UINT16 conn_id) +{ + // TODO: +} + - diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index fad2e79be..a95b9942d 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -49,14 +49,13 @@ extern void API_Ble_GattcAppRegister (tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_ extern void API_Ble_GattcAppDeregister (tBTA_GATTC_IF client_if); -extern void API_Ble_GattcOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, - BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport); +extern void API_Ble_GattcOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); extern void API_GattcCancelOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); extern void API_Ble_GattcClose (UINT16 conn_id); -extern void API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu); +extern tGATT_STATUS API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu); extern void API_Ble_GattcServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid); @@ -65,6 +64,15 @@ extern tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SR tBTA_GATTC_CHAR_ID *p_char_result, tBTA_GATT_CHAR_PROP *p_property); +extern tBTA_GATT_STATUS API_Ble_GattcGetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, + tBT_UUID *p_descr_uuid_cond, + tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); + +extern tBTA_GATT_STATUS API_Ble_GattcGetNextIncludedService(UINT16 conn_id, + tBTA_GATTC_INCL_SVC_ID *p_start_id, + tBT_UUID *p_uuid_cond, + tBTA_GATTC_INCL_SVC_ID *p_result); + extern tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_start_char_id, tBT_UUID *p_char_uuid_cond, @@ -76,7 +84,7 @@ extern tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, tBT_UUID *p_descr_uuid_cond, tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); -extern tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, +extern tBTA_GATT_STATUS API_Ble_GattcGetFirstIncludedService (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result); extern void API_Ble_GattcReadCharacteristic (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, @@ -118,6 +126,45 @@ extern tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF c BD_ADDR bda, tBTA_GATTC_CHAR_ID *p_char_id); +extern void API_Ble_GattsDisable(void); + + +extern void API_Ble_GattsAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback); + +extern void API_Ble_GattsAppDeregister(tBTA_GATTS_IF server_if); + +extern void API_Ble_GattsCreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, + UINT16 num_handle, BOOLEAN is_primary); + +extern void API_Ble_GattsAddIncludeService(UINT16 service_id, UINT16 included_service_id); + +extern void API_Ble_GattsAddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, + tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property); + + +extern void API_Ble_GattsAddCharDescriptor (UINT16 service_id, + tBTA_GATT_PERM perm, + tBT_UUID * p_descr_uuid); + + +extern void API_Ble_GattsDeleteService(UINT16 service_id); + +extern void API_Ble_GattsStartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport); + +extern void API_Ble_GattsStopService(UINT16 service_id); + +extern void API_Ble_GattsHandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len, + UINT8 *p_data, BOOLEAN need_confirm); + +extern void API_Ble_GattsSendRsp (UINT16 conn_id, UINT32 trans_id, + tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg); + +extern void API_Ble_GattsOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct, + tBTA_GATT_TRANSPORT transport); + +extern void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + +extern void API_Ble_GattsClose(UINT16 conn_id); void API_Ble_PrfEnable (void); From 3cd8149288670de9387e5b1c3bd0dd5b13c097fe Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 26 Oct 2016 06:16:43 -0400 Subject: [PATCH 08/31] component bt:Finished Adding all the GATTS API to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 70f1098b0..3ce437a39 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -399,83 +399,89 @@ tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_i void API_Ble_GattsDisable(void) { - // TODO: + BTA_GATTS_Disable(); } +void API_Ble_GattsAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback) +{ + BTA_GATTS_AppRegister(p_app_uuid, p_cback); +} + + void API_Ble_GattsAppDeregister(tBTA_GATTS_IF server_if) { - // TODO: + BTA_GATTS_AppDeregister(server_if); } void API_Ble_GattsCreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, UINT16 num_handle, BOOLEAN is_primary) { - // TODO: + BTA_GATTS_CreateService(server_if, p_service_uuid, inst, num_handle, is_primary); } void API_Ble_GattsAddIncludeService(UINT16 service_id, UINT16 included_service_id) { - // TODO: + BTA_GATTS_AddIncludeService(service_id, included_service_id); } void API_Ble_GattsAddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property) { - // TODO: + BTA_GATTS_AddCharacteristic (service_id, p_char_uuid, perm, property); } void API_Ble_GattsAddCharDescriptor (UINT16 service_id, tBTA_GATT_PERM perm, tBT_UUID * p_descr_uuid) { - + BTA_GATTS_AddCharDescriptor (service_id, perm, p_descr_uuid); } void API_Ble_GattsDeleteService(UINT16 service_id) { - // TODO: + BTA_GATTS_DeleteService(service_id); } void API_Ble_GattsStartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport) { - + BTA_GATTS_StartService(service_id, sup_transport); } void API_Ble_GattsStopService(UINT16 service_id) { - // TODO: + BTA_GATTS_StopService(service_id); } void API_Ble_GattsHandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len, UINT8 *p_data, BOOLEAN need_confirm) { - // TODO: + BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, p_data, need_confirm); } void API_Ble_GattsSendRsp (UINT16 conn_id, UINT32 trans_id, tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg) { - // TODO: + BTA_GATTS_SendRsp (conn_id, trans_id, status, p_msg); } void API_Ble_GattsOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport) { - // TODO: + BTA_GATTS_Open(server_if, remote_bda, is_direct, transport); } void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct) { - // TODO: + BTA_GATTS_CancelOpen(server_if, remote_bda, is_direct); } void API_Ble_GattsClose(UINT16 conn_id) { - // TODO: + BTA_GATTS_Close(conn_id); } From 5ede46f2133f96ff86ef874c9c9f877a987209f3 Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 26 Oct 2016 08:19:48 -0400 Subject: [PATCH 09/31] component bt:Change the profile & app interface to new API --- components/bt/bluedroid/bta/dm/bta_dm_api.c | 2 +- .../bt/bluedroid/bta/gatt/bta_gattc_api.c | 2 +- .../profiles/esp/ble_button/button_pro.c | 21 +++++++----- .../profiles/std/battery/battery_prf.c | 4 +-- .../app_project/SampleServerProject.c | 22 ++++++++++--- .../bluedroid_demos/include/bt_app_defs.h | 33 +++++++++++++++++++ 6 files changed, 67 insertions(+), 17 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 16cba33ed..610661387 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -1324,7 +1324,7 @@ extern void BTA_DmBleBroadcast (BOOLEAN start) { tBTA_DM_API_BLE_OBSERVE *p_msg; - APPL_TRACE_API("BTA_DmBleBroadcast: start = %d ", start); + APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start); if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) { diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_api.c b/components/bt/bluedroid/bta/gatt/bta_gattc_api.c index 36e7b7d1a..150b14a29 100755 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_api.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_api.c @@ -60,7 +60,7 @@ void BTA_GATTC_Disable(void) if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) { - APPL_TRACE_WARNING("GATTC Module not enabled/already disabled"); + APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n"); return; } if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index b11e30e7a..726201fe6 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -26,6 +26,7 @@ #include "bta_api.h" #include "bta_gatt_api.h" #include "bta_gatts_int.h" +#include "bt_app_api.h" #include "button_pro.h" #include "prf_defs.h" @@ -92,11 +93,11 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) memset(&rsp,0,sizeof(tBTA_GATTS_API_RSP)); rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle; rsp.attr_value.len = 2; - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + API_Ble_GattsSendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,&rsp); break; case BTA_GATTS_WRITE_EVT: - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + API_Ble_GattsSendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,NULL); LOG_ERROR("Received button data:"); for(int i = 0; i < p_data->req_data.p_data->write_req.len; i++){ @@ -138,9 +139,9 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) button_cb_env.is_primery = p_data->create.is_primary; //uuid = {LEN_UUID_16, {ATT_CHAR_BUTTON_WIT}}; //start the button service after created - BTA_GATTS_StartService(p_data->create.service_id,BTA_GATT_TRANSPORT_LE); + API_Ble_GattsStartService(p_data->create.service_id,BTA_GATT_TRANSPORT_LE); //add the frist button characteristic --> write characteristic - BTA_GATTS_AddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, + API_Ble_GattsAddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, (GATT_PERM_WRITE|GATT_PERM_READ), (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE)); break; @@ -154,13 +155,13 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //save the att handle to the env button_cb_env.button_inst.but_wirt_hdl = p_data->add_result.attr_id; //add the frist button characteristic --> Notify characteristic - BTA_GATTS_AddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, + API_Ble_GattsAddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, GATT_PERM_READ,(GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_NOTIFY)); }else if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_BUTTON_NTF){ // add the gattc config descriptor to the notify charateristic //tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_WRITE); uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; button_cb_env.button_inst.but_ntf_hdl = p_data->add_result.attr_id; - BTA_GATTS_AddCharDescriptor (button_cb_env.clcb.cur_srvc_id, + API_Ble_GattsAddCharDescriptor (button_cb_env.clcb.cur_srvc_id, (GATT_PERM_WRITE|GATT_PERM_WRITE), &uuid); } @@ -181,6 +182,8 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) button_cb_env.clcb.connected = false; break; case BTA_GATTS_OPEN_EVT: + ///stop the advertising after connected + API_Ble_AppStopAdvertising(); break; case BTA_GATTS_CLOSE_EVT: if(button_cb_env.clcb.connected && (button_cb_env.clcb.conn_id == p_data->conn.conn_id)) @@ -220,7 +223,7 @@ void Button_CreateService(void) //{ // LOG_ERROR("button service added error."); //} - BTA_GATTS_CreateService(server_if,&uuid,inst,num_handle,true); + API_Ble_GattsCreateService(server_if,&uuid,inst,num_handle,true); } @@ -332,7 +335,7 @@ tGATT_STATUS button_init (tBU_CBACK *call_back) /* register the button profile to the BTA_GATTS module*/ - BTA_GATTS_AppRegister(&app_uuid,button_profile_cb); + API_Ble_GattsAppRegister(&app_uuid,button_profile_cb); button_cb_env.enabled = TRUE; @@ -358,7 +361,7 @@ void button_msg_notify(UINT8 len, UINT8 *button_msg) return; } - BTA_GATTS_HandleValueIndication (conn_id, attr_id, len, + API_Ble_GattsHandleValueIndication (conn_id, attr_id, len, button_msg, rsp); } diff --git a/components/bt/bluedroid/profiles/std/battery/battery_prf.c b/components/bt/bluedroid/profiles/std/battery/battery_prf.c index b1cde82e9..b82fbd5e4 100644 --- a/components/bt/bluedroid/profiles/std/battery/battery_prf.c +++ b/components/bt/bluedroid/profiles/std/battery/battery_prf.c @@ -158,8 +158,8 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) bas_service_cmpl(p_data->srvc_oper.service_id, p_data->srvc_oper.status); /*start advertising*/ - if(p_data->srvc_oper.status == GATT_SUCCESS) - BTA_GATTS_Listen(server_if, true, NULL); + //if(p_data->srvc_oper.status == GATT_SUCCESS) + // BTA_GATTS_Listen(server_if, true, NULL); // BTA_GATTC_Broadcast(client_if, true); //non-connectable } break; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index b9cac08a7..69b49e746 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -33,6 +33,8 @@ #include "hid_le_prf.h" +#include "bt_app_api.h" + // #include "hcimsgs.h" @@ -78,6 +80,18 @@ UINT8 wechat_manu[] = {0x00,0x00,0x18,0xfe,0x34,0x6a,0x86,0x2e}; tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufacturer data */ tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu}; +tESP_API_BLE_ADV_PARAMS_ALL adv_params = +{ + .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_type = API_GEN_DISCOVERABLE, + .addr_type_own = API_PUBLIC_ADDR, + .channel_map = API_BLE_ADV_CHNL_MAP, + .adv_filter_policy = API_ADV_UNDIRECT, + {API_PUBLIC_ADDR,NULL} +}; + + BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55}; tESP_BLE_ADV_DATA ijiazu_adv_data[ADV_SCAN_IDX_MAX] = @@ -254,6 +268,8 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) #if (WX_AIRSYNC_CFG) AirSync_Init(NULL); #endif ///WX_AIRSYNC_CFG + + API_Ble_AppStartAdvertising(&adv_params); /*start advetising*/ // BTA_GATTS_Listen(server_if, true, NULL); } @@ -272,10 +288,8 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) LOG_ERROR("set advertising parameters\n"); //set the advertising data to the btm layer - ESP_AppBleConfigadvData(&wechat_adv_data[BLE_ADV_DATA_IDX], + API_Ble_AppConfigAdvData(&wechat_adv_data[BLE_ADV_DATA_IDX], bta_gatts_set_adv_data_cback); - //set the adversting data to the btm layer - ESP_AppBleSetScanRsp(&wechat_adv_data[BLE_SCAN_RSP_DATA_IDX],NULL); } break; @@ -325,7 +339,7 @@ static void ble_server_appRegister(void) btif_to_bta_uuid(&t_uuid, &uuid); LOG_ERROR("register gatts application\n"); - BTA_GATTS_AppRegister(&t_uuid, bta_gatts_callback); + API_Ble_GattsAppRegister(&t_uuid, bta_gatts_callback); } void gatts_server_test(void) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index d2aa9c2f4..bae84150b 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -1,8 +1,20 @@ + +#ifndef _BT_APP_DEFS_H__ +#define _BT_APP_DEFS_H__ + + #include "bta_api.h" #include "btm_ble_api.h" #define API_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ +#define API_BLE_ADV_CHNL_MAP (API_BLE_ADV_CHNL_37|API_BLE_ADV_CHNL_38|API_BLE_ADV_CHNL_39) + +/* advertising channel map */ +#define API_BLE_ADV_CHNL_37 (0x01 << 0) +#define API_BLE_ADV_CHNL_38 (0x01 << 1) +#define API_BLE_ADV_CHNL_39 (0x01 << 2) + #define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == API_BLE_CONN_PARAM_UNDEF)) @@ -39,6 +51,24 @@ enum api_adv_filter API_ADV_DIRECT }; +/// Own BD address source of the device +enum api_own_addr_src +{ + /// Public Address + API_PUBLIC_ADDR, + /// Provided random address + API_PROVIDED_RND_ADDR, + /// Provided static random address + API_GEN_STATIC_RND_ADDR, + /// Generated resolvable private random address + API_GEN_RSLV_ADDR, + /// Generated non-resolvable private random address + API_GEN_NON_RSLV_ADDR, + /// Provided Reconnection address + API_PROVIDED_RECON_ADDR, +}; + + typedef struct { @@ -81,3 +111,6 @@ extern void ESP_AppBleSetScanRsp(tESP_BLE_ADV_DATA *scan_rsp_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); + + +#endif ///_BT_APP_DEFS_H__ \ No newline at end of file From d6db871068a40484665109bc801eb2781c3ba134 Mon Sep 17 00:00:00 2001 From: yulong Date: Fri, 28 Oct 2016 01:54:42 -0400 Subject: [PATCH 10/31] component bt:Change the profile function method to new API --- components/bt/bluedroid/bta/dm/bta_dm_api.c | 17 ++++++++++------- components/bt/bluedroid/include/bt_target.h | 2 +- .../profiles/esp/ble_button/button_pro.c | 19 +++++++++++++++++++ .../bt/bluedroid/stack/btm/btm_ble_gap.c | 8 +++++--- components/bt/bluedroid/stack/btm/btm_sec.c | 13 +++++++------ .../bluedroid_demos/app_core/bt_app_api.c | 2 ++ .../bluedroid_demos/app_core/bt_app_core.c | 2 +- .../app_project/SampleServerProject.c | 13 ++----------- .../bluedroid_demos/include/bt_app_api.h | 2 -- .../bluedroid_demos/include/bt_app_defs.h | 18 ++++++++++-------- examples/06_bluedroid_demos/main/demo_main.c | 2 +- 11 files changed, 58 insertions(+), 40 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 610661387..e557dd5e4 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -207,7 +207,7 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p tBTA_DM_API_SET_VISIBILITY *p_msg; - if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) + if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) { p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT; p_msg->disc_mode = disc_mode; @@ -690,7 +690,7 @@ void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param) { tBTA_DM_API_EXECUTE_CBACK *p_msg; - if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) + if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) { p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT; p_msg->p_param= p_param; @@ -1025,9 +1025,10 @@ void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max, APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max); - if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS))) != NULL) + if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + + sizeof(tBLE_BD_ADDR))) != NULL) { - memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS)); + memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS)+sizeof(tBLE_BD_ADDR)); p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT; @@ -1053,9 +1054,11 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, #if BLE_INCLUDED == TRUE tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg; - APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max); - - if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL))) != NULL) + APPL_TRACE_ERROR ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max); + APPL_TRACE_ERROR ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n", + adv_type,addr_type_own,chnl_map,adv_fil_pol); + if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL) + + sizeof(tBLE_BD_ADDR))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)); diff --git a/components/bt/bluedroid/include/bt_target.h b/components/bt/bluedroid/include/bt_target.h index 9af8a2b76..f6216dd33 100755 --- a/components/bt/bluedroid/include/bt_target.h +++ b/components/bt/bluedroid/include/bt_target.h @@ -790,7 +790,7 @@ * resolution, local address rotation etc. */ #ifndef BLE_PRIVACY_SPT -#define BLE_PRIVACY_SPT TRUE +#define BLE_PRIVACY_SPT FALSE #endif /* diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 726201fe6..1806d4e9a 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -38,6 +38,22 @@ tBUTTON_CB_ENV button_cb_env; +tBLE_BD_ADDR p_peer_bda = { + .type = API_PUBLIC_ADDR, + .bda = {0} +}; + +tESP_API_BLE_ADV_PARAMS_ALL adv_params = +{ + .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_type = API_NON_DISCOVERABLE, + .addr_type_own = API_PUBLIC_ADDR, + .channel_map = API_BLE_ADV_CHNL_MAP, + .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY, + .p_dir_bda = &p_peer_bda +}; + /***************************************************************************** @@ -172,6 +188,9 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) { button_cb_env.button_inst.but_cfg_hdl = p_data->add_result.attr_id; } + ///Start advertising + LOG_ERROR("\nStart sent the ADV.\n"); + API_Ble_AppStartAdvertising(&adv_params); break; case BTA_GATTS_CONNECT_EVT: //set the connection flag to true diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 2c5829966..117f7f368 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -1051,7 +1051,7 @@ tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); } - BTM_TRACE_EVENT ("update params for an active adv"); + BTM_TRACE_EVENT ("update params for an active adv\n"); btm_ble_stop_adv(); @@ -1094,7 +1094,7 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; tBTM_STATUS status = BTM_SUCCESS; - BTM_TRACE_EVENT ("BTM_BleSetAdvParams\n"); + BTM_TRACE_EVENT ("BTM_BleSetAdvParamsStartAdv\n"); if (!controller_get_interface()->supports_ble()) return BTM_ILLEGAL_VALUE; @@ -1111,6 +1111,7 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, p_addr_cb->own_addr_type = own_bda_type; p_cb->evt_type = adv_type; p_cb->adv_mode = BTM_BLE_ADV_ENABLE; + p_cb->afp = afp; if (p_dir_bda) { @@ -3180,7 +3181,7 @@ tBTM_STATUS btm_ble_start_adv(void) { tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; tBTM_STATUS rt = BTM_NO_RESOURCES; - + BTM_TRACE_EVENT ("btm_ble_start_adv\n"); if (!btm_ble_adv_states_operation (btm_ble_topology_check, p_cb->evt_type)) return BTM_WRONG_MODE; @@ -3202,6 +3203,7 @@ tBTM_STATUS btm_ble_start_adv(void) p_cb->adv_mode = BTM_BLE_ADV_ENABLE; btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); rt = BTM_SUCCESS; + BTM_TRACE_EVENT ("BTM_SUCCESS\n"); } else { diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index bf16e0fb3..b4d66031b 100755 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -2731,11 +2731,11 @@ tBTM_STATUS btm_sec_mx_access_request (BD_ADDR bd_addr, UINT16 psm, BOOLEAN is_o void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); - + BTM_TRACE_ERROR ("%s\n",__func__); /* Some device may request a connection before we are done with the HCI_Reset sequence */ if (!controller_get_interface()->get_is_ready()) { - BTM_TRACE_EVENT ("Security Manager: connect request when device not ready"); + BTM_TRACE_ERROR ("Security Manager: connect request when device not ready\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2747,7 +2747,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) { if (!p_dev_rec || !(p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_AUTHED)) { - BTM_TRACE_EVENT ("Security Manager: connect request from non-paired device"); + BTM_TRACE_ERROR ("Security Manager: connect request from non-paired device\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2759,7 +2759,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) { if (!p_dev_rec) { - BTM_TRACE_EVENT ("Security Manager: connect request from not paired device"); + BTM_TRACE_ERROR ("Security Manager: connect request from not paired device\n"); btsnd_hcic_reject_conn (bda, HCI_ERR_HOST_REJECT_DEVICE); return; } @@ -2770,7 +2770,7 @@ void btm_sec_conn_req (UINT8 *bda, UINT8 *dc) &&(btm_cb.pairing_flags & BTM_PAIR_FLAGS_WE_STARTED_DD) &&(!memcmp (btm_cb.pairing_bda, bda, BD_ADDR_LEN))) { - BTM_TRACE_EVENT ("Security Manager: reject connect request from bonding device"); + BTM_TRACE_ERROR ("Security Manager: reject connect request from bonding device\n"); /* incoming connection from bonding device is rejected */ btm_cb.pairing_flags |= BTM_PAIR_FLAGS_REJECTED_CONNECT; @@ -4426,7 +4426,8 @@ void btm_sec_connected (UINT8 *bda, UINT16 handle, UINT8 status, UINT8 enc_mode) UINT8 bit_shift = 0; btm_acl_resubmit_page(); - + + BTM_TRACE_ERROR ("%s\n",__func__); /* Commenting out trace due to obf/compilation problems. */ #if (BT_USE_TRACES == TRUE) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 3ce437a39..fd4453e24 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -58,6 +58,8 @@ void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) return; } + LOG_ERROR("API_Ble_AppStartAdvertising\n"); + /// BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, ble_adv_params->adv_int_max, diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index 7e7f73db1..84a244943 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -252,7 +252,7 @@ static void bt_app_dm_upstreams_evt(UINT16 event, char *p_param) /*set connectable,discoverable, pairable and paired only modes of local device*/ tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE; tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE; - BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL); + //BTA_DmSetVisibility(disc_mode, conn_mode, (UINT8)BTA_DM_NON_PAIRABLE, (UINT8)BTA_DM_CONN_ALL); #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) /* Enable local privacy */ diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index 69b49e746..1be9198e1 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -80,16 +80,7 @@ UINT8 wechat_manu[] = {0x00,0x00,0x18,0xfe,0x34,0x6a,0x86,0x2e}; tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufacturer data */ tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu}; -tESP_API_BLE_ADV_PARAMS_ALL adv_params = -{ - .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, - .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, - .adv_type = API_GEN_DISCOVERABLE, - .addr_type_own = API_PUBLIC_ADDR, - .channel_map = API_BLE_ADV_CHNL_MAP, - .adv_filter_policy = API_ADV_UNDIRECT, - {API_PUBLIC_ADDR,NULL} -}; + BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55}; @@ -269,7 +260,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) AirSync_Init(NULL); #endif ///WX_AIRSYNC_CFG - API_Ble_AppStartAdvertising(&adv_params); + //API_Ble_AppStartAdvertising(&adv_params); /*start advetising*/ // BTA_GATTS_Listen(server_if, true, NULL); } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index a95b9942d..d48c17cb4 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -166,5 +166,3 @@ extern void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, extern void API_Ble_GattsClose(UINT16 conn_id); - -void API_Ble_PrfEnable (void); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index bae84150b..0dd19298a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -41,14 +41,16 @@ enum api_adv_type enum api_adv_filter { - /// Start non connectable advertising - API_ADV_NON_CONN, - /// Start undirected connectable advertising - API_ADV_UNDIRECT, - /// Start directed connectable advertising - API_ADV_DIRECT_LOW_DUTY, - /// Start directed connectable advertising - API_ADV_DIRECT + ///Allow both scan and connection requests from anyone + ADV_ALLOW_SCAN_ANY_CON_ANY = 0x00, + ///Allow both scan req from White List devices only and connection req from anyone + ADV_ALLOW_SCAN_WLST_CON_ANY, + ///Allow both scan req from anyone and connection req from White List devices only + ADV_ALLOW_SCAN_ANY_CON_WLST, + ///Allow scan and connection requests from White List devices only + ADV_ALLOW_SCAN_WLST_CON_WLST, + ///Enumeration end value for advertising filter policy value check + ADV_ALLOW_SCAN_END }; /// Own BD address source of the device diff --git a/examples/06_bluedroid_demos/main/demo_main.c b/examples/06_bluedroid_demos/main/demo_main.c index 4c9e71a16..fe62f89b7 100644 --- a/examples/06_bluedroid_demos/main/demo_main.c +++ b/examples/06_bluedroid_demos/main/demo_main.c @@ -15,7 +15,7 @@ void pingTask(void *pvParameters) { while (1) { vTaskDelay(1000 / portTICK_PERIOD_MS); - printf("ping\n"); + //printf("ping\n"); } } From 3053518f8ae075727a6f86cb0319b36ae8623bd6 Mon Sep 17 00:00:00 2001 From: yulong Date: Mon, 31 Oct 2016 06:55:54 -0400 Subject: [PATCH 11/31] component bt:modified the API format to the standard format --- .../bt/bluedroid/bta/include/bta_gatt_api.h | 2 +- .../bluedroid/profiles/std/include/prf_defs.h | 2 +- components/bt/bluedroid/stack/gatt/gatt_api.c | 2 +- .../bluedroid_demos/app_core/bt_app.c | 4 +- .../bluedroid_demos/app_core/bt_app_api.c | 268 ++--- .../app_sample_button/app_button.c | 9 + .../app_project/SampleServerProject.c | 8 +- .../bluedroid_demos/include/bt_app_api.h | 942 ++++++++++++++++-- .../bluedroid_demos/include/bt_app_defs.h | 239 ++++- 9 files changed, 1220 insertions(+), 256 deletions(-) diff --git a/components/bt/bluedroid/bta/include/bta_gatt_api.h b/components/bt/bluedroid/bta/include/bta_gatt_api.h index 5ef9ad74c..668f23c16 100755 --- a/components/bt/bluedroid/bta/include/bta_gatt_api.h +++ b/components/bt/bluedroid/bta/include/bta_gatt_api.h @@ -523,7 +523,7 @@ typedef tGATTS_RSP tBTA_GATTS_RSP; typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG; /* read request always based on UUID */ -typedef tGATT_READ_REQ tTA_GBATT_READ_REQ; +typedef tGATT_READ_REQ tBTA_GATT_READ_REQ; /* write request data */ typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ; diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 351657b6b..807b767d2 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -27,7 +27,7 @@ #define ATT_UUID_32_LEN 0x0004 #define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 1 +#define BUT_PROFILE_CFG 0 #define HIDD_LE_PROFILE_CFG 0 /* diff --git a/components/bt/bluedroid/stack/gatt/gatt_api.c b/components/bt/bluedroid/stack/gatt/gatt_api.c index ee140057a..72f9dfd22 100755 --- a/components/bt/bluedroid/stack/gatt/gatt_api.c +++ b/components/bt/bluedroid/stack/gatt/gatt_api.c @@ -1582,7 +1582,7 @@ BOOLEAN GATT_GetConnIdIfConnected(tGATT_IF gatt_if, BD_ADDR bd_addr, UINT16 *p_c status = TRUE; } - GATT_TRACE_API ("GATT_GetConnIdIfConnected status=%d", status); + GATT_TRACE_API ("GATT_GetConnIdIfConnected status=%d\n", status); return status; } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c index 854dab47a..d3a4b4291 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c @@ -29,7 +29,7 @@ ** Returns None ** *******************************************************************************/ - void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, + void ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) { tBTA_BLE_AD_MASK data_mask = 0; @@ -112,7 +112,7 @@ ** Returns None ** *******************************************************************************/ -void ESP_AppBleSetScanRsp(tESP_BLE_ADV_DATA *scan_rsp_data, +void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback) { tBTA_BLE_AD_MASK data_mask = 0; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index fd4453e24..635a504ad 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -17,25 +17,25 @@ //#include "btm_ble_int.h" -void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, - tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) { if(adv_data != NULL) { - ESP_AppBleConfigadvData(adv_data, p_adv_data_cback); + ble_config_adv_data(adv_data, adv_data_cback); }else{ LOG_ERROR("The adv_data is NULL\n"); } if(++adv_data != NULL) { - ESP_AppBleSetScanRsp(adv_data,NULL); + ble_set_scan_rsp(adv_data,NULL); } } -void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) { if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) @@ -51,8 +51,8 @@ void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) return; } - if ((ble_adv_params->adv_filter_policy < API_ADV_NON_CONN) && - (ble_adv_params->adv_filter_policy > API_ADV_DIRECT) ) + if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) && + (ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) ) { LOG_ERROR("Invalid advertisting type parameters.\n"); return; @@ -73,8 +73,8 @@ void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) } -void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_if, - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback) { if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && @@ -91,26 +91,26 @@ void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_i } -void API_Ble_StartScanning (UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb) +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) { - if((duration != 0) && (p_results_cb != NULL)) + if((duration != 0) && (results_cb != NULL)) { ///Start scan the device - BTA_DmBleObserve(true, duration, p_results_cb); + BTA_DmBleObserve(true, duration, results_cb); }else{ LOG_ERROR("The scan duration or p_results_cb invalid\n"); } } -void API_Ble_AppStopAdvertising(void) +void esp_ble_stop_advertising (void) { bool stop_adv = true; BTA_DmBleBroadcast(stop_adv); } -void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, - UINT16 max_int, UINT16 latency, UINT16 timeout) +void esp_ble_update_conec_params (BD_ADDR bd_addr, uint16_t min_int, + uint16_t max_int, uint16_t latency, uint16_t timeout) { if (min_int > max_int){ min_int = max_int; @@ -125,7 +125,7 @@ void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, } -void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length) +void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length) { if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ tx_data_length = BTM_BLE_DATA_SIZE_MAX; @@ -137,7 +137,7 @@ void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length) } -void API_Ble_SetRandAddress(BD_ADDR rand_addr) +void esp_ble_set_rand_addr (BD_ADDR rand_addr) { if (rand_addr != NULL){ BTA_DmSetRandAddress(rand_addr); @@ -146,7 +146,7 @@ void API_Ble_SetRandAddress(BD_ADDR rand_addr) } } -void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable) +void esp_ble_config_local_privacy (BOOLEAN privacy_enable) { BTA_DmBleConfigLocalPrivacy(privacy_enable); } @@ -154,22 +154,22 @@ void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable) -void API_Ble_GattcAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) +void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb) { - if (p_app_uuid != NULL) + if (app_uuid != NULL) { - BTA_GATTC_AppRegister(p_app_uuid, *p_client_cb); + BTA_GATTC_AppRegister(app_uuid, client_cb); }else{ LOG_ERROR("The app uuid invalid.\n"); } } -void API_Ble_GattcAppDeregister(tBTA_GATTC_IF client_if) +void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if) { BTA_GATTC_AppDeregister(client_if); } -void API_Ble_GattcOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) +void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; if(remote_bda == NULL ){ @@ -184,7 +184,7 @@ void API_Ble_GattcOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_d } -void API_GattcCancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) +void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { if(remote_bda == NULL ){ LOG_ERROR("Invaild address data \n"); @@ -194,13 +194,13 @@ void API_GattcCancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is BTA_GATTC_CancelOpen(client_if, remote_bda, is_direct); } -void API_Ble_GattcClose(UINT16 conn_id) +void esp_ble_gattc_close (uint16_t conn_id) { BTA_GATTC_Close(conn_id); } -tGATT_STATUS API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu) +tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) { if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ LOG_ERROR("Invalid MTU parameters\n"); @@ -211,277 +211,279 @@ tGATT_STATUS API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu) } -void API_Ble_GattcServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid) +void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid) { - BTA_GATTC_ServiceSearchRequest(conn_id, p_srvc_uuid); + BTA_GATTC_ServiceSearchRequest(conn_id, srvc_uuid); } -tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property) +tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property) { tBTA_GATT_STATUS status = 0; - if (!p_srvc_id || !p_char_result){ + if (!srvc_id || !char_result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetFirstChar (conn_id, p_srvc_id, p_char_uuid_cond, - p_char_result, p_property); + status = BTA_GATTC_GetFirstChar (conn_id, srvc_id, char_uuid_cond, + char_result, property); return status; } -tBTA_GATT_STATUS API_Ble_GattcGetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - tBT_UUID *p_descr_uuid_cond, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_result) +tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result) { tBTA_GATT_STATUS status; - if (!p_char_id || !p_descr_result){ + if (!char_id || !descr_result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetFirstCharDescr (conn_id, p_char_id, p_descr_uuid_cond, p_descr_result); + status = BTA_GATTC_GetFirstCharDescr (conn_id, char_id, descr_uuid_cond, descr_result); return status; } -tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_start_char_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property) +tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, + esp_gattc_char_id_t *start_char_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property) { tBTA_GATT_STATUS status; - if (!p_start_char_id || !p_char_result){ + if (!start_char_id || !char_result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetNextChar(conn_id, p_start_char_id, p_char_uuid_cond, - p_char_result, p_property); + status = BTA_GATTC_GetNextChar(conn_id, start_char_id, char_uuid_cond, + char_result, property); return status; } -tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_start_descr_id, - tBT_UUID *p_descr_uuid_cond, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_result) +tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *start_descr_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result) { tBTA_GATT_STATUS status; - if (!p_start_descr_id || !p_descr_result){ + if (!start_descr_id || !descr_result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetNextCharDescr (conn_id, p_start_descr_id, p_descr_uuid_cond, p_descr_result); + status = BTA_GATTC_GetNextCharDescr (conn_id, start_descr_id, descr_uuid_cond, descr_result); return status; } -tBTA_GATT_STATUS API_Ble_GattcGetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result) +tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) { tBTA_GATT_STATUS status; - if (!p_srvc_id || !p_result){ + if (!srvc_id || !result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetFirstIncludedService(conn_id, p_srvc_id, p_uuid_cond, p_result); + status = BTA_GATTC_GetFirstIncludedService(conn_id, srvc_id, uuid_cond, result); return status; } -tBTA_GATT_STATUS API_Ble_GattcGetNextIncludedService(UINT16 conn_id, - tBTA_GATTC_INCL_SVC_ID *p_start_id, - tBT_UUID *p_uuid_cond, - tBTA_GATTC_INCL_SVC_ID *p_result) +tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, + esp_gattc_incl_srvc_id_t *start_id, + esp_bt_uuid_t *uuid_cond, + esp_gattc_incl_srvc_id_t *result) { tBTA_GATT_STATUS status; - if (!p_start_id || !p_result){ + if (!start_id || !result){ return BTA_GATT_ILLEGAL_PARAMETER; } - status = BTA_GATTC_GetNextIncludedService(conn_id, p_start_id, p_uuid_cond, p_result); + status = BTA_GATTC_GetNextIncludedService(conn_id, start_id, uuid_cond, result); return status; } -void API_Ble_GattcReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - tBTA_GATT_AUTH_REQ auth_req) +void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_gatt_auth_req_t auth_req) { - BTA_GATTC_ReadCharacteristic(conn_id, p_char_id, auth_req); + BTA_GATTC_ReadCharacteristic(conn_id, char_id, auth_req); } -void API_Ble_GattcReadCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_id, - tBTA_GATT_AUTH_REQ auth_req) +void esp_ble_gattc_read_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *descr_id, + esp_gatt_auth_req_t auth_req) { - BTA_GATTC_ReadCharDescr (conn_id, p_descr_id, auth_req); + BTA_GATTC_ReadCharDescr (conn_id, descr_id, auth_req); } -void API_Ble_GattcReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, - tBTA_GATT_AUTH_REQ auth_req) +void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, + esp_gatt_auth_req_t auth_req) { - BTA_GATTC_ReadMultiple(conn_id, p_read_multi, auth_req); + BTA_GATTC_ReadMultiple(conn_id, read_multi, auth_req); } -void API_Ble_GattcWriteCharValue ( UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_char_id, - tBTA_GATTC_WRITE_TYPE write_type, - UINT16 len, - UINT8 *p_value, - tBTA_GATT_AUTH_REQ auth_req) +void esp_ble_gattc_write_char_val ( uint16_t conn_id, + esp_gattc_char_id_t *char_id, + esp_gattc_write_type_t write_type, + uint16_t len, + uint8_t *value, + esp_gatt_auth_req_t auth_req) { - BTA_GATTC_WriteCharValue (conn_id, p_char_id, write_type, len, p_value, auth_req); -} - -void API_Ble_GattcWriteCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, - tBTA_GATTC_WRITE_TYPE write_type, - tBTA_GATT_UNFMT *p_data, - tBTA_GATT_AUTH_REQ auth_req) -{ - BTA_GATTC_WriteCharDescr (conn_id, p_char_descr_id, write_type, p_data, auth_req); + BTA_GATTC_WriteCharValue (conn_id, char_id, write_type, len, value, auth_req); } -void API_Ble_GattcPrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - UINT16 offset, UINT16 len, UINT8 *p_value, - tBTA_GATT_AUTH_REQ auth_req) +void esp_ble_gattc_write_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *char_descr_id, + esp_gattc_write_type_t write_type, + esp_gatt_unfmt_t *data, + esp_gatt_auth_req_t auth_req) { - BTA_GATTC_PrepareWrite (conn_id, p_char_id, offset, len, p_value, auth_req); + BTA_GATTC_WriteCharDescr (conn_id, char_descr_id, write_type, data, auth_req); } -void API_Ble_GattcExecuteWrite (UINT16 conn_id, BOOLEAN is_execute) + +void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, + uint16_t offset, uint16_t len, uint8_t *value, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_PrepareWrite (conn_id, char_id, offset, len, value, auth_req); +} + +void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute) { BTA_GATTC_ExecuteWrite (conn_id, is_execute); } -void API_Ble_GattcSendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id) +void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) { - BTA_GATTC_SendIndConfirm (conn_id, p_char_id); + BTA_GATTC_SendIndConfirm (conn_id, char_id); } -tBTA_GATT_STATUS API_Ble_GattcRegisterForNotifications (tBTA_GATTC_IF client_if, +tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, BD_ADDR bda, - tBTA_GATTC_CHAR_ID *p_char_id) + esp_gattc_char_id_t *char_id) { tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; - status = BTA_GATTC_RegisterForNotifications (client_if, bda, p_char_id); + status = BTA_GATTC_RegisterForNotifications (client_if, bda, char_id); return status; } -tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_if, - BD_ADDR bda, - tBTA_GATTC_CHAR_ID *p_char_id) +tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, + BD_ADDR bda, + esp_gattc_char_id_t *char_id) { tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; - status = BTA_GATTC_DeregisterForNotifications (client_if, bda, p_char_id); + status = BTA_GATTC_DeregisterForNotifications (client_if, bda, char_id); return status; } -void API_Ble_GattsDisable(void) +void esp_ble_gatts_disale(void) { BTA_GATTS_Disable(); } -void API_Ble_GattsAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback) +void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback) { - BTA_GATTS_AppRegister(p_app_uuid, p_cback); + BTA_GATTS_AppRegister(app_uuid, cback); } -void API_Ble_GattsAppDeregister(tBTA_GATTS_IF server_if) +void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if) { BTA_GATTS_AppDeregister(server_if); } -void API_Ble_GattsCreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, - UINT16 num_handle, BOOLEAN is_primary) +void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, + uint16_t num_handle, BOOLEAN is_primary) { - BTA_GATTS_CreateService(server_if, p_service_uuid, inst, num_handle, is_primary); + BTA_GATTS_CreateService(server_if, service_uuid, inst, num_handle, is_primary); } -void API_Ble_GattsAddIncludeService(UINT16 service_id, UINT16 included_service_id) +void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id) { BTA_GATTS_AddIncludeService(service_id, included_service_id); } -void API_Ble_GattsAddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, - tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property) +void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, + esp_gatt_perm_t perm, esp_gatt_char_prop_t property) { - BTA_GATTS_AddCharacteristic (service_id, p_char_uuid, perm, property); + BTA_GATTS_AddCharacteristic (service_id, char_uuid, perm, property); } -void API_Ble_GattsAddCharDescriptor (UINT16 service_id, - tBTA_GATT_PERM perm, - tBT_UUID * p_descr_uuid) +void esp_ble_gatts_add_char_descr (uint16_t service_id, + esp_gatt_perm_t perm, + esp_bt_uuid_t * descr_uuid) { - BTA_GATTS_AddCharDescriptor (service_id, perm, p_descr_uuid); + BTA_GATTS_AddCharDescriptor (service_id, perm, descr_uuid); } -void API_Ble_GattsDeleteService(UINT16 service_id) +void esp_ble_gatts_dele_srvc (uint16_t service_id) { BTA_GATTS_DeleteService(service_id); } -void API_Ble_GattsStartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport) +void esp_ble_gatts_start_srvc(uint16_t service_id) { - BTA_GATTS_StartService(service_id, sup_transport); + tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; + BTA_GATTS_StartService(service_id, transport); } -void API_Ble_GattsStopService(UINT16 service_id) +void esp_ble_gatts_stop_srvc(uint16_t service_id) { BTA_GATTS_StopService(service_id); } -void API_Ble_GattsHandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len, - UINT8 *p_data, BOOLEAN need_confirm) +void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, + uint8_t *data, BOOLEAN need_confirm) { - BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, p_data, need_confirm); + BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, data, need_confirm); } -void API_Ble_GattsSendRsp (UINT16 conn_id, UINT32 trans_id, - tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg) +void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, + esp_gatt_status_t status, esp_gatts_rsp_t *msg) { - BTA_GATTS_SendRsp (conn_id, trans_id, status, p_msg); + BTA_GATTS_SendRsp (conn_id, trans_id, status, msg); } -void API_Ble_GattsOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct, - tBTA_GATT_TRANSPORT transport) +void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) { + tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; BTA_GATTS_Open(server_if, remote_bda, is_direct, transport); } -void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct) +void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) { BTA_GATTS_CancelOpen(server_if, remote_bda, is_direct); } -void API_Ble_GattsClose(UINT16 conn_id) +void esp_ble_gatts_close(uint16_t conn_id) { BTA_GATTS_Close(conn_id); } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index 825a5647a..c685e8e44 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -15,6 +15,13 @@ ******************************************************************************* ********* */ + + +#include "prf_defs.h" + +#if (BUT_PROFILE_CFG) + + #include #include #include @@ -76,6 +83,8 @@ BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data) +#endif ///BUT_PROFILE_CFG + #if 0 #define GPIO_INUM 8 diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index 1be9198e1..6c24854dd 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -85,7 +85,7 @@ tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu}; BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55}; -tESP_BLE_ADV_DATA ijiazu_adv_data[ADV_SCAN_IDX_MAX] = +esp_ble_adv_data_cfg_t ijiazu_adv_data[ADV_SCAN_IDX_MAX] = { [BLE_ADV_DATA_IDX] = { .adv_name = "Espressif_007", @@ -126,7 +126,7 @@ tESP_BLE_ADV_DATA ijiazu_adv_data[ADV_SCAN_IDX_MAX] = } }; -tESP_BLE_ADV_DATA wechat_adv_data[ADV_SCAN_IDX_MAX] = +esp_ble_adv_data_cfg_t wechat_adv_data[ADV_SCAN_IDX_MAX] = { [BLE_ADV_DATA_IDX] = { .adv_name = NULL, @@ -279,7 +279,7 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) LOG_ERROR("set advertising parameters\n"); //set the advertising data to the btm layer - API_Ble_AppConfigAdvData(&wechat_adv_data[BLE_ADV_DATA_IDX], + esp_ble_config_adv_data(&wechat_adv_data[BLE_ADV_DATA_IDX], bta_gatts_set_adv_data_cback); } @@ -330,7 +330,7 @@ static void ble_server_appRegister(void) btif_to_bta_uuid(&t_uuid, &uuid); LOG_ERROR("register gatts application\n"); - API_Ble_GattsAppRegister(&t_uuid, bta_gatts_callback); + esp_ble_gatts_app_register(&t_uuid, bta_gatts_callback); } void gatts_server_test(void) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index d48c17cb4..e0f9e3449 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -16,153 +16,891 @@ #include "bt_app_defs.h" #include "bta_gatt_api.h" -typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; -typedef tBTA_STATUS tAPI_STATUS; - -extern void API_Ble_AppConfigAdvData (tESP_BLE_ADV_DATA *adv_data, - tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); - -extern void API_Ble_SetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); -extern void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_if, - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); - -extern void API_Ble_StartScanning (UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb); +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback); -extern void API_Ble_AppStartAdvertising (tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params); -extern void API_Ble_AppStopAdvertising (void); +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback); -extern void API_Ble_AppUpdateConnectionParams (BD_ADDR bd_addr, UINT16 min_int, - UINT16 max_int, UINT16 latency, UINT16 timeout); -extern void API_Ble_SetPacketDataLength (BD_ADDR remote_device, UINT16 tx_data_length); +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb); -extern void API_Ble_SetRandAddress (BD_ADDR rand_addr); -extern void API_Ble_ConfigLocalPrivacy (BOOLEAN privacy_enable); -extern void API_Ble_GattcAppRegister (tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params); -extern void API_Ble_GattcAppDeregister (tBTA_GATTC_IF client_if); -extern void API_Ble_GattcOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); -extern void API_GattcCancelOpen (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct); +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ +void esp_ble_stop_advertising (void); -extern void API_Ble_GattcClose (UINT16 conn_id); -extern tGATT_STATUS API_Ble_GattcConfigureMTU (UINT16 conn_id, UINT16 mtu); -extern void API_Ble_GattcServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid); +/******************************************************************************* +** +** @function esp_ble_update_conec_params +** +** @brief Update connection parameters, can only be used when connection is up. +** +** @param[in] bd_addr - BD address of the peer +** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] +** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] +** @param[in] latency - slave latency [0 ~ 500] +** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] +** +** @return None +** +*******************************************************************************/ +void esp_ble_update_conec_params (BD_ADDR bd_addr, uint16_t min_int, + uint16_t max_int, uint16_t latency, uint16_t timeout); -extern tBTA_GATT_STATUS API_Ble_GattcGetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property); -extern tBTA_GATT_STATUS API_Ble_GattcGetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - tBT_UUID *p_descr_uuid_cond, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); +/******************************************************************************* +** +** @function esp_ble_set_pkt_data_len +** +** @brief This function is to set maximum LE data packet size +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length); -extern tBTA_GATT_STATUS API_Ble_GattcGetNextIncludedService(UINT16 conn_id, - tBTA_GATTC_INCL_SVC_ID *p_start_id, - tBT_UUID *p_uuid_cond, - tBTA_GATTC_INCL_SVC_ID *p_result); -extern tBTA_GATT_STATUS API_Ble_GattcGetNextChar (UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_start_char_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property); -extern tBTA_GATT_STATUS API_Ble_GattcGetNextCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_start_descr_id, - tBT_UUID *p_descr_uuid_cond, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); +/******************************************************************************* +** +** @function esp_ble_set_rand_addr +** +** @brief This function set the random address for the appliction +** +** @param[in] rand_addr: the random address whith should be setting +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_rand_addr (BD_ADDR rand_addr); -extern tBTA_GATT_STATUS API_Ble_GattcGetFirstIncludedService (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_uuid_cond, tBTA_GATTC_INCL_SVC_ID *p_result); -extern void API_Ble_GattcReadCharacteristic (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - tBTA_GATT_AUTH_REQ auth_req); -extern void API_Ble_GattcReadCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_id, - tBTA_GATT_AUTH_REQ auth_req); +/******************************************************************************* +** +** @function esp_ble_config_local_privacy +** +** @brief Enable/disable privacy on the local device +** +** @param[in] privacy_enable - enable/disabe privacy on remote device. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_local_privacy (BOOLEAN privacy_enable); -extern void API_Ble_GattcReadMultiple (UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, - tBTA_GATT_AUTH_REQ auth_req); -extern void API_Ble_GattcWriteCharValue ( UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_char_id, - tBTA_GATTC_WRITE_TYPE write_type, - UINT16 len, - UINT8 *p_value, - tBTA_GATT_AUTH_REQ auth_req); -extern void API_Ble_GattcWriteCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, - tBTA_GATTC_WRITE_TYPE write_type, - tBTA_GATT_UNFMT *p_data, - tBTA_GATT_AUTH_REQ auth_req); +/******************************************************************************* +** @function esp_gattc_disable +** @brief This function is called by application to disable GATTC module +** +** @param NULL +** +** @return None. +** +*******************************************************************************/ +void esp_gattc_disable(void); -extern void API_Ble_GattcPrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - UINT16 offset, UINT16 len, UINT8 *p_value, - tBTA_GATT_AUTH_REQ auth_req); -extern void API_Ble_GattcExecuteWrite (UINT16 conn_id, BOOLEAN is_execute); +/******************************************************************************* +** +** @function esp_ble_gattc_app_register +** +** @brief This function is called to register application callbacks +** with GATTC module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] client_cb - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb); -extern void API_Ble_GattcSendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id); -extern tBTA_GATT_STATUS API_Ble_GattcRegisterForNotifications (tBTA_GATTC_IF client_if, +/******************************************************************************* +** +** @function esp_ble_gattc_app_unregister +** +** @brief This function is called to unregister an application +** from GATTC module. +** +** @param[in] client_if - client interface identifier. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if); + + +/******************************************************************************* +** +** @function esp_ble_gattc_conn +** +** @brief Open a direct connection or add a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gattc_close +** +** @brief Close a connection to a GATT server. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_close (uint16_t conn_id); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_config_mtu +** +** @brief Configure the MTU size in the GATT channel. This can be done +** only once per connection. +** +** @param[in] conn_id: connection ID. +** mtu: desired MTU size to use. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid +** +*******************************************************************************/ +tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu); + + +/******************************************************************************* +** +** @function esp_ble_gattc_svc_search_req +** +** @brief This function is called to request a GATT service discovery +** on a GATT server. This function report service search result +** by a callback event, and followed by a service search complete +** event. +** +** @param[in] conn_id: connection ID. +** @param[in] srvc_uuid: a UUID of the service application is interested in. +** If Null, discover for all services. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid); + + +/**************************************************************************************************** +** +** @function esp_ble_gattc_get_first_char +** +** @brief This function is called to find the first characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. +** +*****************************************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_char_descr +** +** @brief This function is called to find the first characteristic descriptor of the +** characteristic on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. +** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available +** characteristic. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_inclu_srvc +** +** @brief This function is called to find the next included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_id: start the search from the next record +** after the one identified by p_start_id. +** @param[in] uuid_cond: Included service UUID, if NULL find the first available +** included service. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. + +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, + esp_gattc_incl_srvc_id_t *start_id, + esp_bt_uuid_t *uuid_cond, + esp_gattc_incl_srvc_id_t *result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char +** +** @brief This function is called to find the next characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_char_id: start the characteristic search from the next record +** after the one identified by char_id. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, + esp_gattc_char_id_t *start_char_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char_descr +** +** @brief This function is called to find the next characteristic descriptor +** of the characterisctic. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_descr_id: start the descriptor search from the next record +** after the one identified by p_start_descr_id. +** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find +** the first available characteristic descriptor. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *start_descr_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_inclu_srvc +** +** @brief This function is called to find the first included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. +** +*******************************************************************************/ +extern tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char +** +** @brief This function is called to read a service's characteristics of +** the given characteritisc ID. +** +** @param[in] conn_id - connectino ID. +** @param[in] char_id - characteritic ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char_descr +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] conn_id - connection ID. +** @param[in] descr_id - characteritic descriptor ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *descr_id, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_multi +** +** @brief This function is called to read multiple characteristic or +** characteristic descriptors. +** +** @param[in] conn_id - connectino ID. +** @param[in] read_multi - pointer to the read multiple parameter. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_val +** +** @brief This function is called to write characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to write. +** @param[in] write_type - type of write. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_val ( uint16_t conn_id, + esp_gattc_char_id_t *char_id, + esp_gattc_write_type_t write_type, + uint16_t len, + uint8_t *value, + esp_gatt_auth_req_t auth_req); + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_descr +** +** @brief This function is called to write characteristic descriptor value. +** +** @param[in] conn_id - connection ID +** @param[in] char_descr_id - characteristic descriptor ID to write. +** @param[in] write_type - write type. +** @param[in] data - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *char_descr_id, + esp_gattc_write_type_t write_type, + esp_gatt_unfmt_t *data, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_prepa_write +** +** @brief This function is called to prepare write a characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - GATT characteritic ID of the service. +** @param[in] offset - offset of the write value. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, + uint16_t offset, uint16_t len, uint8_t *value, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_execu_write +** +** @brief This function is called to execute write a prepare write sequence. +** +** @param[in] conn_id - connection ID. +** @param[in] is_execute - execute or cancel. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_send_ind_cfm +** +** @brief This function is called to send handle value confirmation. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to confirm. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id); + + + + +/******************************************************************************* +** +** @function esp_ble_gattc_register_ntf +** +** @brief This function is called to register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if registration succeed, otherwise failed. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, BD_ADDR bda, - tBTA_GATTC_CHAR_ID *p_char_id); + esp_gattc_char_id_t *char_id); -extern tBTA_GATT_STATUS API_Ble_GattcDeregisterForNotifications (tBTA_GATTC_IF client_if, + + +/******************************************************************************* +** +** @function esp_ble_gattc_unregister_ntf +** +** @brief This function is called to de-register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if deregistration succeed, otherwise failed. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, BD_ADDR bda, - tBTA_GATTC_CHAR_ID *p_char_id); - -extern void API_Ble_GattsDisable(void); + esp_gattc_char_id_t *char_id); -extern void API_Ble_GattsAppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback); - -extern void API_Ble_GattsAppDeregister(tBTA_GATTS_IF server_if); - -extern void API_Ble_GattsCreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid, UINT8 inst, - UINT16 num_handle, BOOLEAN is_primary); - -extern void API_Ble_GattsAddIncludeService(UINT16 service_id, UINT16 included_service_id); - -extern void API_Ble_GattsAddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid, - tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property); +/******************************************************************************* +** +** @function esp_ble_gatts_disale +** +** @brief This function is called to disable GATTS module +** +** @param[in] None. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_disale(void); -extern void API_Ble_GattsAddCharDescriptor (UINT16 service_id, - tBTA_GATT_PERM perm, - tBT_UUID * p_descr_uuid); + + +/******************************************************************************* +** +** @function esp_ble_gatts_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback); -extern void API_Ble_GattsDeleteService(UINT16 service_id); -extern void API_Ble_GattsStartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport); +/******************************************************************************* +** +** @function esp_ble_gatts_app_unregister +** +** @brief un-register with GATT Server. +** +** @param[in] server_if: service interface id. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if); -extern void API_Ble_GattsStopService(UINT16 service_id); -extern void API_Ble_GattsHandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 data_len, - UINT8 *p_data, BOOLEAN need_confirm); -extern void API_Ble_GattsSendRsp (UINT16 conn_id, UINT32 trans_id, - tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg); +/******************************************************************************* +** +** @function esp_ble_gatts_create_srvc +** +** @brief Create a service. When service creation is done, a callback +** event BTA_GATTS_CREATE_SRVC_EVT is called to report status +** and service ID to the profile. The service ID obtained in +** the callback function needs to be used when adding included +** service and characteristics/descriptors into the service. +** +** @param[in] server_if: Profile ID this service is belonged to. +** @param[in] service_uuid: service UUID. +** @param[in] inst: instance ID number of this service. +** @param[in] num_handle: numble of handle requessted for this service. +** @param[in] is_primary: is this service a primary one or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, + uint16_t num_handle, BOOLEAN is_primary); -extern void API_Ble_GattsOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct, - tBTA_GATT_TRANSPORT transport); -extern void API_Ble_GattsCancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct); -extern void API_Ble_GattsClose(UINT16 conn_id); +/******************************************************************************* +** +** @function esp_ble_gatts_add_inclu_srvc +** +** @brief This function is called to add an included service. After included +** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT +** is reported the included service ID. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] included_service_id: the service ID to be included. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char +** +** @brief This function is called to add a characteristic into a service. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] char_uuid : Characteristic UUID. +** @param[in] perm : Characteristic value declaration attribute permission. +** @param[in] property : Characteristic Properties +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, + esp_gatt_perm_t perm, esp_gatt_char_prop_t property); + + + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char_descr +** +** @brief This function is called to add characteristic descriptor. When +** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called +** to report the status and an ID number for this descriptor. +** +** @param[in] service_id: service ID to which this charatceristic descriptor is to +** be added. +** @param[in] perm: descriptor access permission. +** @param[in] descr_uuid: descriptor UUID. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char_descr (uint16_t service_id, + esp_gatt_perm_t perm, + esp_bt_uuid_t * descr_uuid); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_dele_srvc +** +** @brief This function is called to delete a service. When this is done, +** a callback event BTA_GATTS_DELETE_EVT is report with the status. +** +** @param[in] service_id: service_id to be deleted. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_dele_srvc (uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_start_srvc +** +** @brief This function is called to start a service. +** +** @param[in] service_id: the service ID to be started. +** @param[in] sup_transport: supported trasnport. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_start_srvc(uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_stop_srvc +** +** @brief This function is called to stop a service. +** +** @param[in] service_id - service to be topped. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_stop_srvc(uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_hdl_val_indica +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] bda - remote device bd address to indicate. +** @param[in] attr_id - attribute ID to indicate. +** @param[in] data_len - indicate data length. +** @param[in] data: data to indicate. +** @param[in] need_confirm - if this indication expects a confirmation or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, + uint8_t *data, BOOLEAN need_confirm); + + +/******************************************************************************* +** +** @function esp_ble_gatts_send_rsp +** +** @brief This function is called to send a response to a request. +** +** @param[in] conn_id - connection identifier. +** @param[in] trans_id - transaction ID. +** @param[in] status - response status +** @param[in] msg - response data. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, + esp_gatt_status_t status, esp_gatts_rsp_t *msg); + + +/******************************************************************************* +** +** @function esp_ble_gatts_conn +** +** @brief Open a direct open connection or add a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gatts_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gatts_close +** +** @param[in] Close a connection a remote device. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_close(uint16_t conn_id); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index 0dd19298a..f2012dca5 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -5,18 +5,233 @@ #include "bta_api.h" #include "btm_ble_api.h" +#include "bta_gatt_api.h" -#define API_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ +#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ -#define API_BLE_ADV_CHNL_MAP (API_BLE_ADV_CHNL_37|API_BLE_ADV_CHNL_38|API_BLE_ADV_CHNL_39) +#define ESP_BLE_ADV_CHNL_MAP (ESP_BLE_ADV_CHNL_37|ESP_BLE_ADV_CHNL_38|ESP_BLE_ADV_CHNL_39) /* advertising channel map */ -#define API_BLE_ADV_CHNL_37 (0x01 << 0) -#define API_BLE_ADV_CHNL_38 (0x01 << 1) -#define API_BLE_ADV_CHNL_39 (0x01 << 2) +#define ESP_BLE_ADV_CHNL_37 (0x01 << 0) +#define ESP_BLE_ADV_CHNL_38 (0x01 << 1) +#define ESP_BLE_ADV_CHNL_39 (0x01 << 2) + +typedef tBTA_GATT_STATUS esp_gatt_status_t; -#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == API_BLE_CONN_PARAM_UNDEF)) + + + + +typedef UINT16 gatt_size_t; +typedef tBT_UUID esp_bt_uuid_t; + +typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t; +typedef tGATT_IF esp_gatt_if_t; +typedef tBTA_GATT_SRVC_ID esp_gatt_srvc_id_t; +typedef tBTA_GATTC_CHAR_ID esp_gattc_char_id_t; +typedef tBTA_GATTC_CHAR_DESCR_ID esp_gattc_char_descr_id_t; +typedef tBTA_GATTC_INCL_SVC_ID esp_gattc_incl_srvc_id_t; +typedef tBTA_GATT_AUTH_REQ esp_gatt_auth_req_t; +typedef tBTA_GATTC_MULTI esp_gattc_multi_t; +typedef tBTA_GATTC_WRITE_TYPE esp_gattc_write_type_t; +typedef tBTA_GATT_UNFMT esp_gatt_unfmt_t; +typedef tBTA_GATT_PERM esp_gatt_perm_t; +typedef tBTA_GATT_CHAR_PROP esp_gatt_char_prop_t; +typedef tBTA_GATTC esp_gattc_t; + +typedef tBTA_GATTC_EVT esp_gattc_evt_t; + +typedef tBTA_GATTC_IF esp_gattc_if_t; + + + +/* Client callback function events */ +#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */ +#define ESP_GATTC_DEREG_EVT 1 /* GATT client deregistered event */ +#define ESP_GATTC_OPEN_EVT 2 /* GATTC open request status event */ +#define ESP_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */ +#define ESP_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */ +#define ESP_GATTC_CLOSE_EVT 5 /* GATTC close request status event */ +#define ESP_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */ +#define ESP_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */ +#define ESP_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */ +#define ESP_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */ +#define ESP_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */ +#define ESP_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */ +#define ESP_GATTC_EXEC_EVT 12 /* execute write complete event */ +#define ESP_GATTC_ACL_EVT 13 /* ACL up event */ +#define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ +#define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */ +#define ESP_GATTC_LISTEN_EVT 16 /* listen event */ +#define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */ +#define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */ +#define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */ +#define ESP_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */ +#define ESP_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */ +#define ESP_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */ +#define ESP_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */ +#define ESP_GATTC_CONGEST_EVT 24 /* Congestion event */ +#define ESP_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */ +#define ESP_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */ +#define ESP_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */ +#define ESP_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */ +#define ESP_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */ +#define ESP_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */ +#define ESP_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */ +#define ESP_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */ +#define ESP_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */ +#define ESP_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */ + + +/* GATT Server Data Structure */ +/* Server callback function events */ +#define ESP_GATTS_REG_EVT 0 +#define ESP_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */ +#define ESP_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */ +#define ESP_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */ +#define ESP_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */ +#define ESP_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF /* 5 */ +#define ESP_GATTS_DEREG_EVT 6 +#define ESP_GATTS_CREATE_EVT 7 +#define ESP_GATTS_ADD_INCL_SRVC_EVT 8 +#define ESP_GATTS_ADD_CHAR_EVT 9 +#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10 +#define ESP_GATTS_DELELTE_EVT 11 +#define ESP_GATTS_START_EVT 12 +#define ESP_GATTS_STOP_EVT 13 +#define ESP_GATTS_CONNECT_EVT 14 +#define ESP_GATTS_DISCONNECT_EVT 15 +#define ESP_GATTS_OPEN_EVT 16 +#define ESP_GATTS_CANCEL_OPEN_EVT 17 +#define ESP_GATTS_CLOSE_EVT 18 +#define ESP_GATTS_LISTEN_EVT 19 +#define ESP_GATTS_CONGEST_EVT 20 + +/* Attribute permissions +*/ +#define ESP_GATT_PERM_READ BTA_GATT_PERM_READ /* bit 0 - 0x0001 */ +#define ESP_GATT_PERM_READ_ENCRYPTED BTA_GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */ +#define ESP_GATT_PERM_READ_ENC_MITM BTA_GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */ +#define ESP_GATT_PERM_WRITE BTA_GATT_PERM_WRITE /* bit 4 - 0x0010 */ +#define ESP_GATT_PERM_WRITE_ENCRYPTED BTA_GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */ +#define ESP_GATT_PERM_WRITE_ENC_MITM BTA_GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */ +#define ESP_GATT_PERM_WRITE_SIGNED BTA_GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */ +#define ESP_GATT_PERM_WRITE_SIGNED_MITM BTA_GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */ + +#define ESP_GATTS_INVALID_APP 0xff + +#define ESP_GATTS_INVALID_IF 0 + +/* definition of characteristic properties */ +#define ESP_GATT_CHAR_PROP_BIT_BROADCAST BTA_GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */ +#define ESP_GATT_CHAR_PROP_BIT_READ BTA_GATT_CHAR_PROP_BIT_READ /* 0x02 */ +#define ESP_GATT_CHAR_PROP_BIT_WRITE_NR BTA_GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */ +#define ESP_GATT_CHAR_PROP_BIT_WRITE BTA_GATT_CHAR_PROP_BIT_WRITE /* 0x08 */ +#define ESP_GATT_CHAR_PROP_BIT_NOTIFY BTA_GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */ +#define ESP_GATT_CHAR_PROP_BIT_INDICATE BTA_GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */ +#define ESP_GATT_CHAR_PROP_BIT_AUTH BTA_GATT_CHAR_PROP_BIT_AUTH /* 0x40 */ +#define ESP_GATT_CHAR_PROP_BIT_EXT_PROP BTA_GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */ + +typedef tBTA_GATTS_EVT esp_gatts_evt_t; +typedef tBTA_GATTS_IF esp_gatts_if_t; + +/* attribute value */ +typedef tBTA_GATT_VALUE esp_gatt_value_t; + +/* attribute response data */ +typedef tBTA_GATTS_RSP esp_gatts_rsp_t; + +typedef tBTA_GATTS esp_gatts_t; + +/* attribute request data from the client */ +#define ESP_GATT_PREP_WRITE_CANCEL 0x00 +#define ESP_GATT_PREP_WRITE_EXEC 0x01 +typedef tBTA_GATT_EXEC_FLAG esp_gatt_exec_flag_t; + +/* read request always based on UUID */ +typedef tBTA_GATT_READ_REQ esp_gatt_read_req_t; + +/* write request data */ +typedef tBTA_GATT_WRITE_REQ esp_gatt_write_req_t; + +/* callback data for server access request from client */ +typedef tBTA_GATTS_REQ_DATA esp_gatts_req_data_t; + + +/* Search callback */ +typedef tBTA_DM_SEARCH_CBACK esp_dm_search_cb_t; + +typedef tBLE_SCAN_PARAM_SETUP_CBACK esp_scan_param_setup_cb_t; + + +typedef tBTA_SET_ADV_DATA_CMPL_CBACK esp_ble_set_adv_data_cmpl_cb_t; + +/* GATTC enable callback function */ +typedef void (esp_gattc_enb_cb_t)(esp_gatt_status_t status); + +/* Client callback function */ +typedef void (esp_gattc_cb_t)(esp_gattc_evt_t event, esp_gattc_t *cb_data); + + +/* GATTS enable callback function */ +typedef void (esp_gatts_enb_cb_t)(esp_gatt_status_t status); + +/* Server callback function */ +typedef void (esp_gatts_cb_t)(esp_gatts_evt_t event, esp_gatts_t *cb_data); + + +/* Success code and error codes */ +#define ESP_GATT_OK BTA_GATT_OK +#define ESP_GATT_INVALID_HANDLE BTA_GATT_INVALID_HANDLE /* 0x0001 */ +#define ESP_GATT_READ_NOT_PERMIT BTA_GATT_READ_NOT_PERMIT /* 0x0002 */ +#define ESP_GATT_WRITE_NOT_PERMIT BTA_GATT_WRITE_NOT_PERMIT /* 0x0003 */ +#define ESP_GATT_INVALID_PDU BTA_GATT_INVALID_PDU /* 0x0004 */ +#define ESP_GATT_INSUF_AUTHENTICATION BTA_GATT_INSUF_AUTHENTICATION /* 0x0005 */ +#define ESP_GATT_REQ_NOT_SUPPORTED BTA_GATT_REQ_NOT_SUPPORTED /* 0x0006 */ +#define ESP_GATT_INVALID_OFFSET BTA_GATT_INVALID_OFFSET /* 0x0007 */ +#define ESP_GATT_INSUF_AUTHORIZATION BTA_GATT_INSUF_AUTHORIZATION /* 0x0008 */ +#define ESP_GATT_PREPARE_Q_FULL BTA_GATT_PREPARE_Q_FULL /* 0x0009 */ +#define ESP_GATT_NOT_FOUND BTA_GATT_NOT_FOUND /* 0x000a */ +#define ESP_GATT_NOT_LONG BTA_GATT_NOT_LONG /* 0x000b */ +#define ESP_GATT_INSUF_KEY_SIZE BTA_GATT_INSUF_KEY_SIZE /* 0x000c */ +#define ESP_GATT_INVALID_ATTR_LEN BTA_GATT_INVALID_ATTR_LEN /* 0x000d */ +#define ESP_GATT_ERR_UNLIKELY BTA_GATT_ERR_UNLIKELY /* 0x000e */ +#define ESP_GATT_INSUF_ENCRYPTION BTA_GATT_INSUF_ENCRYPTION /* 0x000f */ +#define ESP_GATT_UNSUPPORT_GRP_TYPE BTA_GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */ +#define ESP_GATT_INSUF_RESOURCE BTA_GATT_INSUF_RESOURCE /* 0x0011 */ + + +#define ESP_GATT_NO_RESOURCES BTA_GATT_NO_RESOURCES /* 0x80 */ +#define ESP_GATT_INTERNAL_ERROR BTA_GATT_INTERNAL_ERROR /* 0x81 */ +#define ESP_GATT_WRONG_STATE BTA_GATT_WRONG_STATE /* 0x82 */ +#define ESP_GATT_DB_FULL BTA_GATT_DB_FULL /* 0x83 */ +#define ESP_GATT_BUSY BTA_GATT_BUSY /* 0x84 */ +#define ESP_GATT_ERROR BTA_GATT_ERROR /* 0x85 */ +#define ESP_GATT_CMD_STARTED BTA_GATT_CMD_STARTED /* 0x86 */ +#define ESP_GATT_ILLEGAL_PARAMETER BTA_GATT_ILLEGAL_PARAMETER /* 0x87 */ +#define ESP_GATT_PENDING BTA_GATT_PENDING /* 0x88 */ +#define ESP_GATT_AUTH_FAIL BTA_GATT_AUTH_FAIL /* 0x89 */ +#define ESP_GATT_MORE BTA_GATT_MORE /* 0x8a */ +#define ESP_GATT_INVALID_CFG BTA_GATT_INVALID_CFG /* 0x8b */ +#define ESP_GATT_SERVICE_STARTED BTA_GATT_SERVICE_STARTED /* 0x8c */ +#define ESP_GATT_ENCRYPED_MITM BTA_GATT_ENCRYPED_MITM /* GATT_SUCCESS */ +#define ESP_GATT_ENCRYPED_NO_MITM BTA_GATT_ENCRYPED_NO_MITM /* 0x8d */ +#define ESP_GATT_NOT_ENCRYPTED BTA_GATT_NOT_ENCRYPTED /* 0x8e */ +#define ESP_GATT_CONGESTED BTA_GATT_CONGESTED /* 0x8f */ + +#define ESP_GATT_DUP_REG BTA_GATT_DUP_REG /* 0x90 */ +#define ESP_GATT_ALREADY_OPEN BTA_GATT_ALREADY_OPEN /* 0x91 */ +#define ESP_GATT_CANCEL BTA_GATT_CANCEL /* 0x92 */ + + /* 0xE0 ~ 0xFC reserved for future use */ +#define ESP_GATT_CCC_CFG_ERR BTA_GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */ +#define ESP_GATT_PRC_IN_PROGRESS BTA_GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */ +#define ESP_GATT_OUT_OF_RANGE BTA_GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */ + + + +#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) enum @@ -76,14 +291,14 @@ typedef struct { char *adv_name; //set the device name to be sent on the advertising tBTA_BLE_ADV_DATA ble_adv_data; -}tESP_BLE_ADV_DATA; +}esp_ble_adv_data_cfg_t; typedef struct { UINT16 adv_int_min; UINT16 adv_int_max; tBLE_BD_ADDR *p_dir_bda; -}tESP_BLE_ADV_PARAM; +}esp_ble_adv_params_t; typedef struct { @@ -94,7 +309,7 @@ typedef struct tBTM_BLE_ADV_CHNL_MAP channel_map; tBTM_BLE_AFP adv_filter_policy; tBLE_BD_ADDR *p_dir_bda; -}tESP_API_BLE_ADV_PARAMS_ALL; +}esp_ble_adv_params_all_t; typedef struct { @@ -103,13 +318,13 @@ typedef struct UINT16 scan_win; UINT8 addr_type_own; UINT8 scan_fil_policy; -}tESP_BLE_SCAN_PARAMS; +}esp_ble_scan_params; -extern void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, +extern void ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); -extern void ESP_AppBleSetScanRsp(tESP_BLE_ADV_DATA *scan_rsp_data, +extern void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); From 1cc3858dc8be71b26ecd922503165abdfd7802f6 Mon Sep 17 00:00:00 2001 From: yulong Date: Mon, 31 Oct 2016 07:24:03 -0400 Subject: [PATCH 12/31] component bt:Modified the API method to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 711 +++++++++++++++++- .../bluedroid_demos/include/bt_app_api.h | 4 +- 2 files changed, 710 insertions(+), 5 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 635a504ad..52fb3014d 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -17,6 +17,21 @@ //#include "btm_ble_int.h" + +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) { @@ -35,6 +50,17 @@ void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, } +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) { if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || @@ -73,6 +99,20 @@ void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) } +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, esp_scan_param_setup_cb_t scan_param_setup_cback) { @@ -91,6 +131,19 @@ void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t c } +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) { if((duration != 0) && (results_cb != NULL)) @@ -102,6 +155,18 @@ void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) } } + +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ void esp_ble_stop_advertising (void) { bool stop_adv = true; @@ -109,7 +174,23 @@ void esp_ble_stop_advertising (void) BTA_DmBleBroadcast(stop_adv); } -void esp_ble_update_conec_params (BD_ADDR bd_addr, uint16_t min_int, + +/******************************************************************************* +** +** @function esp_ble_update_conn_params +** +** @brief Update connection parameters, can only be used when connection is up. +** +** @param[in] bd_addr - BD address of the peer +** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] +** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] +** @param[in] latency - slave latency [0 ~ 500] +** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] +** +** @return None +** +*******************************************************************************/ +void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, uint16_t max_int, uint16_t latency, uint16_t timeout) { if (min_int > max_int){ @@ -125,6 +206,18 @@ void esp_ble_update_conec_params (BD_ADDR bd_addr, uint16_t min_int, } + + +/******************************************************************************* +** +** @function esp_ble_set_pkt_data_len +** +** @brief This function is to set maximum LE data packet size +** +** @return None +** +** +*******************************************************************************/ void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length) { if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ @@ -137,6 +230,19 @@ void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length) } + +/******************************************************************************* +** +** @function esp_ble_set_rand_addr +** +** @brief This function set the random address for the appliction +** +** @param[in] rand_addr: the random address whith should be setting +** +** @return None +** +** +*******************************************************************************/ void esp_ble_set_rand_addr (BD_ADDR rand_addr) { if (rand_addr != NULL){ @@ -146,14 +252,52 @@ void esp_ble_set_rand_addr (BD_ADDR rand_addr) } } + +/******************************************************************************* +** +** @function esp_ble_config_local_privacy +** +** @brief Enable/disable privacy on the local device +** +** @param[in] privacy_enable - enable/disabe privacy on remote device. +** +** @return None +** +*******************************************************************************/ void esp_ble_config_local_privacy (BOOLEAN privacy_enable) { BTA_DmBleConfigLocalPrivacy(privacy_enable); } +/******************************************************************************* +** @function esp_gattc_disable +** @brief This function is called by application to disable GATTC module +** +** @param NULL +** +** @return None. +** +*******************************************************************************/ +void esp_gattc_disable(void) +{ + // TODO: This API funciton didn't finish, will be added it in future +} +/******************************************************************************* +** +** @function esp_ble_gattc_app_register +** +** @brief This function is called to register application callbacks +** with GATTC module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] client_cb - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb) { if (app_uuid != NULL) @@ -164,11 +308,39 @@ void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_ } } + +/******************************************************************************* +** +** @function esp_ble_gattc_app_unregister +** +** @brief This function is called to unregister an application +** from GATTC module. +** +** @param[in] client_if - client interface identifier. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if) { BTA_GATTC_AppDeregister(client_if); } + +/******************************************************************************* +** +** @function esp_ble_gattc_conn +** +** @brief Open a direct connection or add a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; @@ -184,6 +356,21 @@ void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is } + +/******************************************************************************* +** +** @function esp_ble_gattc_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) { if(remote_bda == NULL ){ @@ -194,12 +381,39 @@ void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BO BTA_GATTC_CancelOpen(client_if, remote_bda, is_direct); } + +/******************************************************************************* +** +** @function esp_ble_gattc_close +** +** @brief Close a connection to a GATT server. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_close (uint16_t conn_id) { BTA_GATTC_Close(conn_id); } +/******************************************************************************* +** +** @function esp_ble_gattc_config_mtu +** +** @brief Configure the MTU size in the GATT channel. This can be done +** only once per connection. +** +** @param[in] conn_id: connection ID. +** mtu: desired MTU size to use. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid +** +*******************************************************************************/ tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) { if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ @@ -211,12 +425,49 @@ tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) } + +/******************************************************************************* +** +** @function esp_ble_gattc_svc_search_req +** +** @brief This function is called to request a GATT service discovery +** on a GATT server. This function report service search result +** by a callback event, and followed by a service search complete +** event. +** +** @param[in] conn_id: connection ID. +** @param[in] srvc_uuid: a UUID of the service application is interested in. +** If Null, discover for all services. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid) { BTA_GATTC_ServiceSearchRequest(conn_id, srvc_uuid); } +/**************************************************************************************************** +** +** @function esp_ble_gattc_get_first_char +** +** @brief This function is called to find the first characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. +** +*****************************************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *char_uuid_cond, esp_gattc_char_id_t *char_result, @@ -236,6 +487,26 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_ } + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_char_descr +** +** @brief This function is called to find the first characteristic descriptor of the +** characteristic on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. +** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available +** characteristic. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. +** +*******************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, esp_bt_uuid_t *descr_uuid_cond, esp_gattc_char_descr_id_t *descr_result) @@ -253,6 +524,28 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gatt } +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char +** +** @brief This function is called to find the next characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_char_id: start the characteristic search from the next record +** after the one identified by char_id. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. +** +*******************************************************************************/ + tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, esp_gattc_char_id_t *start_char_id, esp_bt_uuid_t *char_uuid_cond, @@ -273,6 +566,28 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, } + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char_descr +** +** @brief This function is called to find the next characteristic descriptor +** of the characterisctic. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_descr_id: start the descriptor search from the next record +** after the one identified by p_start_descr_id. +** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find +** the first available characteristic descriptor. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. +** +*******************************************************************************/ + tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, esp_gattc_char_descr_id_t *start_descr_id, esp_bt_uuid_t *descr_uuid_cond, @@ -290,6 +605,26 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, } + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_inclu_srvc +** +** @brief This function is called to find the first included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. +** +*******************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) { @@ -305,6 +640,27 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt return status; } + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_inclu_srvc +** +** @brief This function is called to find the next included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_id: start the search from the next record +** after the one identified by p_start_id. +** @param[in] uuid_cond: Included service UUID, if NULL find the first available +** included service. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. + +*******************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, esp_gattc_incl_srvc_id_t *start_id, esp_bt_uuid_t *uuid_cond, @@ -322,6 +678,19 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, } +/******************************************************************************* +** +** @function esp_ble_gattc_read_char +** +** @brief This function is called to read a service's characteristics of +** the given characteritisc ID. +** +** @param[in] conn_id - connectino ID. +** @param[in] char_id - characteritic ID to read. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, esp_gatt_auth_req_t auth_req) { @@ -329,6 +698,18 @@ void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, } +/******************************************************************************* +** +** @function esp_ble_gattc_read_char_descr +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] conn_id - connection ID. +** @param[in] descr_id - characteritic descriptor ID to read. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_read_char_descr (uint16_t conn_id, esp_gattc_char_descr_id_t *descr_id, esp_gatt_auth_req_t auth_req) @@ -336,12 +717,42 @@ void esp_ble_gattc_read_char_descr (uint16_t conn_id, BTA_GATTC_ReadCharDescr (conn_id, descr_id, auth_req); } + +/******************************************************************************* +** +** @function esp_ble_gattc_read_multi +** +** @brief This function is called to read multiple characteristic or +** characteristic descriptors. +** +** @param[in] conn_id - connectino ID. +** @param[in] read_multi - pointer to the read multiple parameter. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, esp_gatt_auth_req_t auth_req) { BTA_GATTC_ReadMultiple(conn_id, read_multi, auth_req); } + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_val +** +** @brief This function is called to write characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to write. +** @param[in] write_type - type of write. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_write_char_val ( uint16_t conn_id, esp_gattc_char_id_t *char_id, esp_gattc_write_type_t write_type, @@ -353,6 +764,20 @@ void esp_ble_gattc_write_char_val ( uint16_t conn_id, } +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_descr +** +** @brief This function is called to write characteristic descriptor value. +** +** @param[in] conn_id - connection ID +** @param[in] char_descr_id - characteristic descriptor ID to write. +** @param[in] write_type - write type. +** @param[in] data - the value to be written. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_write_char_descr (uint16_t conn_id, esp_gattc_char_descr_id_t *char_descr_id, esp_gattc_write_type_t write_type, @@ -363,6 +788,21 @@ void esp_ble_gattc_write_char_descr (uint16_t conn_id, } +/******************************************************************************* +** +** @function esp_ble_gattc_prepa_write +** +** @brief This function is called to prepare write a characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - GATT characteritic ID of the service. +** @param[in] offset - offset of the write value. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, uint16_t offset, uint16_t len, uint8_t *value, esp_gatt_auth_req_t auth_req) @@ -370,16 +810,56 @@ void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, BTA_GATTC_PrepareWrite (conn_id, char_id, offset, len, value, auth_req); } + +/******************************************************************************* +** +** @function esp_ble_gattc_execu_write +** +** @brief This function is called to execute write a prepare write sequence. +** +** @param[in] conn_id - connection ID. +** @param[in] is_execute - execute or cancel. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute) { BTA_GATTC_ExecuteWrite (conn_id, is_execute); } + +/******************************************************************************* +** +** @function esp_ble_gattc_send_ind_cfm +** +** @brief This function is called to send handle value confirmation. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to confirm. +** +** @return None +** +*******************************************************************************/ void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) { BTA_GATTC_SendIndConfirm (conn_id, char_id); } + +/******************************************************************************* +** +** @function esp_ble_gattc_register_ntf +** +** @brief This function is called to register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if registration succeed, otherwise failed. +** +*******************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, BD_ADDR bda, esp_gattc_char_id_t *char_id) @@ -390,6 +870,20 @@ tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, return status; } + +/******************************************************************************* +** +** @function esp_ble_gattc_unregister_ntf +** +** @brief This function is called to de-register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if deregistration succeed, otherwise failed. +** +*******************************************************************************/ tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, BD_ADDR bda, esp_gattc_char_id_t *char_id) @@ -400,22 +894,79 @@ tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, return status; } + +/******************************************************************************* +** +** @function esp_ble_gatts_disale +** +** @brief This function is called to disable GATTS module +** +** @param[in] None. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_disale(void) { BTA_GATTS_Disable(); } + +/******************************************************************************* +** +** @function esp_ble_gatts_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback) { BTA_GATTS_AppRegister(app_uuid, cback); } +/******************************************************************************* +** +** @function esp_ble_gatts_app_unregister +** +** @brief un-register with GATT Server. +** +** @param[in] server_if: service interface id. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if) { BTA_GATTS_AppDeregister(server_if); } + +/******************************************************************************* +** +** @function esp_ble_gatts_create_srvc +** +** @brief Create a service. When service creation is done, a callback +** event BTA_GATTS_CREATE_SRVC_EVT is called to report status +** and service ID to the profile. The service ID obtained in +** the callback function needs to be used when adding included +** service and characteristics/descriptors into the service. +** +** @param[in] server_if: Profile ID this service is belonged to. +** @param[in] service_uuid: service UUID. +** @param[in] inst: instance ID number of this service. +** @param[in] num_handle: numble of handle requessted for this service. +** @param[in] is_primary: is this service a primary one or not. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, uint16_t num_handle, BOOLEAN is_primary) { @@ -423,18 +974,64 @@ void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_ } +/******************************************************************************* +** +** @function esp_ble_gatts_add_inclu_srvc +** +** @brief This function is called to add an included service. After included +** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT +** is reported the included service ID. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] included_service_id: the service ID to be included. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id) { BTA_GATTS_AddIncludeService(service_id, included_service_id); } - +/******************************************************************************* +** +** @function esp_ble_gatts_add_char +** +** @brief This function is called to add a characteristic into a service. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] char_uuid : Characteristic UUID. +** @param[in] perm : Characteristic value declaration attribute permission. +** @param[in] property : Characteristic Properties +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, esp_gatt_perm_t perm, esp_gatt_char_prop_t property) { BTA_GATTS_AddCharacteristic (service_id, char_uuid, perm, property); } + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char_descr +** +** @brief This function is called to add characteristic descriptor. When +** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called +** to report the status and an ID number for this descriptor. +** +** @param[in] service_id: service ID to which this charatceristic descriptor is to +** be added. +** @param[in] perm: descriptor access permission. +** @param[in] descr_uuid: descriptor UUID. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_add_char_descr (uint16_t service_id, esp_gatt_perm_t perm, esp_bt_uuid_t * descr_uuid) @@ -442,47 +1039,155 @@ void esp_ble_gatts_add_char_descr (uint16_t service_id, BTA_GATTS_AddCharDescriptor (service_id, perm, descr_uuid); } + +/******************************************************************************* +** +** @function esp_ble_gatts_dele_srvc +** +** @brief This function is called to delete a service. When this is done, +** a callback event BTA_GATTS_DELETE_EVT is report with the status. +** +** @param[in] service_id: service_id to be deleted. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_dele_srvc (uint16_t service_id) { BTA_GATTS_DeleteService(service_id); } + +/******************************************************************************* +** +** @function esp_ble_gatts_start_srvc +** +** @brief This function is called to start a service. +** +** @param[in] service_id: the service ID to be started. +** @param[in] sup_transport: supported trasnport. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_start_srvc(uint16_t service_id) { tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; BTA_GATTS_StartService(service_id, transport); } - +/******************************************************************************* +** +** @function esp_ble_gatts_stop_srvc +** +** @brief This function is called to stop a service. +** +** @param[in] service_id - service to be topped. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_stop_srvc(uint16_t service_id) { BTA_GATTS_StopService(service_id); } +/******************************************************************************* +** +** @function esp_ble_gatts_hdl_val_indica +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] bda - remote device bd address to indicate. +** @param[in] attr_id - attribute ID to indicate. +** @param[in] data_len - indicate data length. +** @param[in] data: data to indicate. +** @param[in] need_confirm - if this indication expects a confirmation or not. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, uint8_t *data, BOOLEAN need_confirm) { BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, data, need_confirm); } + +/******************************************************************************* +** +** @function esp_ble_gatts_send_rsp +** +** @brief This function is called to send a response to a request. +** +** @param[in] conn_id - connection identifier. +** @param[in] trans_id - transaction ID. +** @param[in] status - response status +** @param[in] msg - response data. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, esp_gatt_status_t status, esp_gatts_rsp_t *msg) { BTA_GATTS_SendRsp (conn_id, trans_id, status, msg); } + +/******************************************************************************* +** +** @function esp_ble_gatts_conn +** +** @brief Open a direct open connection or add a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) { tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; BTA_GATTS_Open(server_if, remote_bda, is_direct, transport); } + +/******************************************************************************* +** +** @function esp_ble_gatts_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) { BTA_GATTS_CancelOpen(server_if, remote_bda, is_direct); } + +/******************************************************************************* +** +** @function esp_ble_gatts_close +** +** @param[in] Close a connection a remote device. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ void esp_ble_gatts_close(uint16_t conn_id) { BTA_GATTS_Close(conn_id); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index e0f9e3449..dd68b98c7 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -104,7 +104,7 @@ void esp_ble_stop_advertising (void); /******************************************************************************* ** -** @function esp_ble_update_conec_params +** @function esp_ble_update_conn_params ** ** @brief Update connection parameters, can only be used when connection is up. ** @@ -117,7 +117,7 @@ void esp_ble_stop_advertising (void); ** @return None ** *******************************************************************************/ -void esp_ble_update_conec_params (BD_ADDR bd_addr, uint16_t min_int, +void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, uint16_t max_int, uint16_t latency, uint16_t timeout); From c85be70b9fe8093336733f6f599c1242af374343 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 1 Nov 2016 00:07:34 -0400 Subject: [PATCH 13/31] component bt:Add the CLASSIC_BT_INCLUDED Macro to the project --- components/bt/bluedroid/include/bt_target.h | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/components/bt/bluedroid/include/bt_target.h b/components/bt/bluedroid/include/bt_target.h index f6216dd33..5c402cee8 100755 --- a/components/bt/bluedroid/include/bt_target.h +++ b/components/bt/bluedroid/include/bt_target.h @@ -40,6 +40,11 @@ #include "gki_target.h" #include "dyn_mem.h" /* defines static and/or dynamic memory for components */ + +#ifndef CLASSIC_BT_INCLUDED +#define CLASSIC_BT_INCLUDED TRUE +#endif ///CLASSIC_BT_INCLUDED + //------------------Added from bdroid_buildcfg.h--------------------- #ifndef L2CAP_EXTFEA_SUPPORTED_MASK #define L2CAP_EXTFEA_SUPPORTED_MASK (L2CAP_EXTFEA_ENH_RETRANS | L2CAP_EXTFEA_STREAM_MODE | L2CAP_EXTFEA_NO_CRC | L2CAP_EXTFEA_FIXED_CHNLS) @@ -895,6 +900,33 @@ #define GATT_MAX_BG_CONN_DEV 8 /*MAX is 32*/ #endif +/****************************************************************************** +** +** GATT +** +******************************************************************************/ +#ifndef GATTC_INCLUDED +#if BLE_INCLUDED == TRUE +#define GATTC_INCLUDED TRUE +#else +#define GATTC_INCLUDED FALSE +#endif +#endif + +#ifndef GATTS_INCLUDED +#if BLE_INCLUDED == TRUE +#define GATTS_INCLUDED TRUE +#else +#define GATTS_INCLUDED FALSE +#endif +#endif + + +#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE +#error "can't have SMP without BLE" +#endif + + /****************************************************************************** ** ** SMP From 97c75a88ae9a68a5786f80b43adb7ab22dcfc3e1 Mon Sep 17 00:00:00 2001 From: yulong Date: Wed, 2 Nov 2016 02:05:30 -0400 Subject: [PATCH 14/31] component bt:Change the button profile function to the new API function --- .../bt/bluedroid/bta/sys/bta_sys_main.c | 12 +- .../bluedroid/profiles/core/bt_prf_sys_main.c | 1 + .../profiles/esp/ble_button/button_pro.c | 114 +++++++++--------- .../profiles/esp/include/button_pro.h | 31 ++--- .../bluedroid/profiles/std/include/prf_defs.h | 2 +- .../bt/bluedroid/stack/btm/btm_ble_bgconn.c | 2 +- components/bt/bluedroid/stack/btu/btu_hcif.c | 2 +- .../bt/bluedroid/stack/include/l2cdefs.h | 1 + .../bt/bluedroid/stack/l2cap/l2c_link.c | 26 ++-- .../bt/bluedroid/stack/l2cap/l2cap_client.c | 12 +- .../app_project/SampleServerProject.c | 4 +- .../bluedroid_demos/include/bt_app_defs.h | 4 +- 12 files changed, 105 insertions(+), 106 deletions(-) diff --git a/components/bt/bluedroid/bta/sys/bta_sys_main.c b/components/bt/bluedroid/bta/sys/bta_sys_main.c index 36901e39d..b78b4116e 100755 --- a/components/bt/bluedroid/bta/sys/bta_sys_main.c +++ b/components/bt/bluedroid/bta/sys/bta_sys_main.c @@ -318,7 +318,7 @@ void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg) UINT8 module_index; UNUSED(p_sys_hw_msg); - APPL_TRACE_DEBUG("%s", __FUNCTION__); + APPL_TRACE_DEBUG("%s\n", __FUNCTION__); for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES; module_index++) { @@ -377,7 +377,7 @@ void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg ) bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]( BTA_SYS_HW_ON_EVT ); } - APPL_TRACE_EVENT ("bta_sys_hw_api_enable for %d, active modules 0x%04X", + APPL_TRACE_EVENT ("bta_sys_hw_api_enable for %d, active modules 0x%04X\n", p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active); } @@ -394,7 +394,7 @@ void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg ) *******************************************************************************/ void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg) { - APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X", + APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X\n", p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active ); /* make sure the related SW blocks were stopped */ @@ -442,7 +442,7 @@ void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg) *******************************************************************************/ void bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) { - APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i", p_sys_hw_msg->hw_module); + APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i\n", p_sys_hw_msg->hw_module); BTM_DeviceReset( NULL ); } @@ -461,7 +461,7 @@ void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) { UINT8 hw_module_index; - APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X", p_sys_hw_msg->hw_module); + APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X\n", p_sys_hw_msg->hw_module); for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++) { @@ -485,7 +485,7 @@ void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) UINT8 hw_module_index; UNUSED(p_sys_hw_msg); - APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers"); + APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers\n"); for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++ ) { diff --git a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c index d2eb922d7..48b2825eb 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c @@ -107,6 +107,7 @@ void bt_prf_sys_register(UINT8 id, const tBT_PRF_SYS_REG *p_reg) *******************************************************************************/ void bt_prf_sys_deregister(UINT8 id) { + bt_prf_sys_cb.reg[id] = NULL; bt_prf_sys_cb.is_reg[id] = FALSE; } diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 1806d4e9a..a19856d17 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -36,20 +36,20 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) -tBUTTON_CB_ENV button_cb_env; + button_env_cb_t button_cb_env; tBLE_BD_ADDR p_peer_bda = { .type = API_PUBLIC_ADDR, .bda = {0} }; -tESP_API_BLE_ADV_PARAMS_ALL adv_params = +esp_ble_adv_params_all_t adv_params = { .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, .adv_type = API_NON_DISCOVERABLE, .addr_type_own = API_PUBLIC_ADDR, - .channel_map = API_BLE_ADV_CHNL_MAP, + .channel_map = ESP_BLE_ADV_CHNL_MAP, .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY, .p_dir_bda = &p_peer_bda }; @@ -59,7 +59,7 @@ tESP_API_BLE_ADV_PARAMS_ALL adv_params = /***************************************************************************** ** Constants *****************************************************************************/ -static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); +static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data); /******************************************************************************* @@ -71,14 +71,14 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); ** Returns NULL ** *******************************************************************************/ -static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) +static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) { - tBTA_GATTS_RSP rsp; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; - tBUT_INST *p_inst = &button_cb_env.button_inst; - UINT8 net_event = 0xff; - UINT8 len = 0; - UINT8 *p_rec_data = NULL; + esp_gatts_rsp_t rsp; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; + but_inst_t *p_inst = &button_cb_env.button_inst; + uint8_t net_event = 0xff; + uint8_t len = 0; + uint8_t *p_rec_data = NULL; //LOG_ERROR("p_data->status = %x\n",p_data->status); //if(p_data->status != BTA_GATT_OK){ // LOG_ERROR("button profile register failed\n"); @@ -87,7 +87,7 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) LOG_ERROR("button profile cb event = %x\n",event); switch(event) { - case BTA_GATTS_REG_EVT: + case ESP_GATTS_REG_EVT: LOG_ERROR("p_data->reg_oper.status = %x\n",p_data->reg_oper.status); LOG_ERROR("(p_data->reg_oper.uuid.uu.uuid16=%x\n",p_data->reg_oper.uuid.uu.uuid16); @@ -104,16 +104,16 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) Button_CreateService(); } break; - case BTA_GATTS_READ_EVT: + case ESP_GATTS_READ_EVT: //tBTA_GATTS_RSP rsp; memset(&rsp,0,sizeof(tBTA_GATTS_API_RSP)); rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle; rsp.attr_value.len = 2; - API_Ble_GattsSendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,&rsp); break; - case BTA_GATTS_WRITE_EVT: - API_Ble_GattsSendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + case ESP_GATTS_WRITE_EVT: + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,NULL); LOG_ERROR("Received button data:"); for(int i = 0; i < p_data->req_data.p_data->write_req.len; i++){ @@ -142,27 +142,27 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) (*p_inst->p_cback)(button_cb_env.button_inst.app_id,net_event,len,p_rec_data); } break; - case BTA_GATTS_CONF_EVT: + case ESP_GATTS_CFM_EVT: break; - case BTA_GATTS_CREATE_EVT: + case ESP_GATTS_CREATE_EVT: //tBT_UUID uuid_butt_write; uuid.uu.uuid16 = ATT_CHAR_BUTTON_WIT; //tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_READ); //tBTA_GATT_CHAR_PROP prop = (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE); - //uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; + //uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; button_cb_env.clcb.cur_srvc_id= p_data->create.service_id; button_cb_env.is_primery = p_data->create.is_primary; //uuid = {LEN_UUID_16, {ATT_CHAR_BUTTON_WIT}}; //start the button service after created - API_Ble_GattsStartService(p_data->create.service_id,BTA_GATT_TRANSPORT_LE); + esp_ble_gatts_start_srvc(p_data->create.service_id); //add the frist button characteristic --> write characteristic - API_Ble_GattsAddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, + esp_ble_gatts_add_char(button_cb_env.clcb.cur_srvc_id,&uuid, (GATT_PERM_WRITE|GATT_PERM_READ), (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE)); break; - case BTA_GATTS_ADD_CHAR_EVT: + case ESP_GATTS_ADD_CHAR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_BUTTON_WIT) { uuid.uu.uuid16 = ATT_CHAR_BUTTON_NTF; @@ -171,49 +171,47 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //save the att handle to the env button_cb_env.button_inst.but_wirt_hdl = p_data->add_result.attr_id; //add the frist button characteristic --> Notify characteristic - API_Ble_GattsAddCharacteristic(button_cb_env.clcb.cur_srvc_id,&uuid, + esp_ble_gatts_add_char(button_cb_env.clcb.cur_srvc_id,&uuid, GATT_PERM_READ,(GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_NOTIFY)); }else if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_BUTTON_NTF){ // add the gattc config descriptor to the notify charateristic //tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_WRITE); uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; button_cb_env.button_inst.but_ntf_hdl = p_data->add_result.attr_id; - API_Ble_GattsAddCharDescriptor (button_cb_env.clcb.cur_srvc_id, + esp_ble_gatts_add_char_descr (button_cb_env.clcb.cur_srvc_id, (GATT_PERM_WRITE|GATT_PERM_WRITE), &uuid); } break; - case BTA_GATTS_ADD_CHAR_DESCR_EVT: + case ESP_GATTS_ADD_CHAR_DESCR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) { button_cb_env.button_inst.but_cfg_hdl = p_data->add_result.attr_id; } ///Start advertising LOG_ERROR("\nStart sent the ADV.\n"); - API_Ble_AppStartAdvertising(&adv_params); + esp_ble_start_advertising (&adv_params); break; - case BTA_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: //set the connection flag to true button_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda); break; - case BTA_GATTS_DISCONNECT_EVT: + case ESP_GATTS_DISCONNECT_EVT: //set the connection flag to true button_cb_env.clcb.connected = false; break; - case BTA_GATTS_OPEN_EVT: + case ESP_GATTS_OPEN_EVT: ///stop the advertising after connected - API_Ble_AppStopAdvertising(); + esp_ble_stop_advertising(); break; - case BTA_GATTS_CLOSE_EVT: + case ESP_GATTS_CLOSE_EVT: if(button_cb_env.clcb.connected && (button_cb_env.clcb.conn_id == p_data->conn.conn_id)) { //set the connection channal congested flag to true button_cb_env.clcb.congest = p_data->congest.congested; } break; - case BTA_GATTS_LISTEN_EVT: - break; - case BTA_GATTS_CONGEST_EVT: + case ESP_GATTS_CONGEST_EVT: break; default: break; @@ -232,17 +230,17 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) *******************************************************************************/ void Button_CreateService(void) { - tBTA_GATTS_IF server_if ; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; - UINT16 num_handle = KEY_IDX_NB; - UINT8 inst = 0x00; + esp_gatts_if_t server_if ; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_BUTTON}}; + uint16_t num_handle = KEY_IDX_NB; + uint8_t inst = 0x00; server_if = button_cb_env.gatt_if; button_cb_env.inst_id = inst; //if(!button_cb_env.enabled) //{ // LOG_ERROR("button service added error."); //} - API_Ble_GattsCreateService(server_if,&uuid,inst,num_handle,true); + esp_ble_gatts_create_srvc(server_if,&uuid,inst,num_handle,true); } @@ -255,9 +253,9 @@ void Button_CreateService(void) ** Returns NULL if not found. Otherwise pointer to the connection link block. ** *******************************************************************************/ -tBUT_CLCB *button_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda) +but_clcb_t *button_env_clcb_alloc (uint16_t conn_id, BD_ADDR remote_bda) { - tBUT_CLCB *p_clcb = NULL; + but_clcb_t *p_clcb = NULL; p_clcb = &button_cb_env.clcb; if(!p_clcb->in_use) @@ -281,10 +279,10 @@ tBUT_CLCB *button_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda) ** Returns total number of clcb found. ** *******************************************************************************/ -UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) +uint16_t button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) { - UINT8 i_clcb; - tBUT_CLCB *p_clcb = NULL; + uint8_t i_clcb; + but_clcb_t *p_clcb = NULL; for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < BUTT_MAX_APPS; i_clcb++, p_clcb++) { @@ -307,16 +305,16 @@ UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) ** *******************************************************************************/ -BOOLEAN button_env_clcb_dealloc(UINT16 conn_id) +BOOLEAN button_env_clcb_dealloc(uint16_t conn_id) { - UINT8 i_clcb = 0; - tBUT_CLCB *p_clcb = NULL; + uint16_t i_clcb = 0; + but_clcb_t *p_clcb = NULL; for(i_clcb = 0, p_clcb = &button_cb_env.clcb; i_clcb < 1; i_clcb++, p_clcb++) { if(p_clcb->in_use && p_clcb->connected && (p_clcb->conn_id == conn_id)) { - memset(p_clcb, 0, sizeof(tBUT_CLCB)); + memset(p_clcb, 0, sizeof(but_clcb_t)); return TRUE; } } @@ -331,7 +329,7 @@ BOOLEAN button_env_clcb_dealloc(UINT16 conn_id) ** Description Initializa the GATT Service for button profiles. ** *******************************************************************************/ -tGATT_STATUS button_init (tBU_CBACK *call_back) +esp_gatt_status_t button_init (but_prf_cb_t call_back) { tBT_UUID app_uuid = {LEN_UUID_16,{ATT_SVC_BUTTON}}; @@ -343,7 +341,7 @@ tGATT_STATUS button_init (tBU_CBACK *call_back) } else { - memset(&button_cb_env,0,sizeof(tBUTTON_CB_ENV)); + memset(&button_cb_env,0,sizeof(button_env_cb_t)); } @@ -354,33 +352,33 @@ tGATT_STATUS button_init (tBU_CBACK *call_back) /* register the button profile to the BTA_GATTS module*/ - API_Ble_GattsAppRegister(&app_uuid,button_profile_cb); + esp_ble_gatts_app_register(&app_uuid,button_profile_cb); button_cb_env.enabled = TRUE; - return GATT_SUCCESS; + return ESP_GATT_OK; } -void button_disable(UINT16 connid) +void button_disable(uint16_t connid) { button_env_clcb_dealloc(connid); } -void button_msg_notify(UINT8 len, UINT8 *button_msg) +void button_msg_notify(uint16_t len, uint8_t *button_msg) { BOOLEAN conn_status = button_cb_env.clcb.connected; - UINT16 conn_id = button_cb_env.clcb.conn_id; - UINT16 attr_id = button_cb_env.button_inst.but_ntf_hdl; + uint16_t conn_id = button_cb_env.clcb.conn_id; + uint16_t attr_id = button_cb_env.button_inst.but_ntf_hdl; //notify rsp==false; indicate rsp==true. BOOLEAN rsp = false; if(!conn_status && button_cb_env.clcb.congest) { - LOG_ERROR("the conneciton for button profile has been loss"); + LOG_ERROR("the conneciton for button profile has been loss\n"); return; } - API_Ble_GattsHandleValueIndication (conn_id, attr_id, len, + esp_ble_gatts_hdl_val_indica (conn_id, attr_id, len, button_msg, rsp); } diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index 023e248af..08ca83cd1 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -17,6 +17,7 @@ #include "bt_target.h" #include "gatt_api.h" #include "gattdefs.h" +#include "bt_app_api.h" #define KEY_SUCCESS GATT_SUCCESS #define KEY_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER @@ -36,7 +37,7 @@ #define BUT_MAX_STRING_DATA 7 -typedef void (tBU_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data); +typedef void (*but_prf_cb_t)(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *value); #ifndef BUT_MAX_INT_NUM #define BUT_MAX_INT_NUM 4 @@ -67,7 +68,7 @@ typedef struct BD_ADDR remote_bda; BOOLEAN need_rsp; UINT16 clt_cfg; -}tBUT_WRITE_DATA; +}but_write_data_t; typedef struct { @@ -79,7 +80,7 @@ typedef struct UINT32 trans_id; UINT8 cur_srvc_id; -}tBUT_CLCB; +}but_clcb_t; typedef struct @@ -89,36 +90,36 @@ typedef struct UINT16 but_ntf_hdl; UINT16 but_cfg_hdl; - tBU_CBACK *p_cback; + but_prf_cb_t p_cback; -}tBUT_INST; +}but_inst_t; /* service engine control block */ typedef struct { - tBUT_CLCB clcb; /* connection link*/ + but_clcb_t clcb; /* connection link*/ tGATT_IF gatt_if; BOOLEAN enabled; BOOLEAN is_primery; - tBUT_INST button_inst; + but_inst_t button_inst; UINT8 inst_id; -}tBUTTON_CB_ENV; +}button_env_cb_t; void Button_CreateService(void); -tBUT_CLCB *button_env_clcb_alloc(UINT16 conn_id, BD_ADDR bda); +but_clcb_t *button_env_clcb_alloc(uint16_t conn_id, BD_ADDR bda); -UINT16 button_env_find_conn_id_by_bd_adddr(BD_ADDR bda); +uint16_t button_env_find_conn_id_by_bd_adddr(BD_ADDR bda); -BOOLEAN button_env_clcb_dealloc(UINT16 conn_id); +BOOLEAN button_env_clcb_dealloc(uint16_t conn_id); -tGATT_STATUS button_init(tBU_CBACK *call_back); +esp_gatt_status_t button_init(but_prf_cb_t call_back); -void button_disable(UINT16 connid); +void button_disable(uint16_t connid); -void button_msg_notify(UINT8 len, UINT8 *button_msg); +void button_msg_notify(uint16_t len, uint8_t *button_msg); -extern tBUTTON_CB_ENV button_cb_env; +extern button_env_cb_t button_cb_env; #endif ///BUT_PROFILE_CFG \ No newline at end of file diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 807b767d2..351657b6b 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -27,7 +27,7 @@ #define ATT_UUID_32_LEN 0x0004 #define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 0 +#define BUT_PROFILE_CFG 1 #define HIDD_LE_PROFILE_CFG 0 /* diff --git a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index b5eef2ecc..e69d44637 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c @@ -581,7 +581,7 @@ void btm_ble_initiate_select_conn(BD_ADDR bda) *******************************************************************************/ BOOLEAN btm_ble_suspend_bg_conn(void) { - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) return btm_ble_start_auto_conn(FALSE); diff --git a/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index 4644d7a27..4c1a40f1d 100755 --- a/components/bt/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/bluedroid/stack/btu/btu_hcif.c @@ -1196,7 +1196,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c *******************************************************************************/ static void btu_hcif_hardware_error_evt (UINT8 *p) { - HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p); + HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x\n", *p); /* If anyone wants device status notifications, give him one. */ btm_report_device_status (BTM_DEV_STATUS_DOWN); diff --git a/components/bt/bluedroid/stack/include/l2cdefs.h b/components/bt/bluedroid/stack/include/l2cdefs.h index a6e25eb9e..b4b6f5138 100755 --- a/components/bt/bluedroid/stack/include/l2cdefs.h +++ b/components/bt/bluedroid/stack/include/l2cdefs.h @@ -38,6 +38,7 @@ #define L2CAP_CMD_AMP_MOVE_RSP 0x0F #define L2CAP_CMD_AMP_MOVE_CFM 0x10 #define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11 + #define L2CAP_CMD_BLE_UPDATE_REQ 0x12 #define L2CAP_CMD_BLE_UPDATE_RSP 0x13 diff --git a/components/bt/bluedroid/stack/l2cap/l2c_link.c b/components/bt/bluedroid/stack/l2cap/l2c_link.c index 40696ad20..9cf80c3ea 100755 --- a/components/bt/bluedroid/stack/l2cap/l2c_link.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_link.c @@ -134,7 +134,7 @@ BOOLEAN l2c_link_hci_conn_req (BD_ADDR bd_addr) } else { - L2CAP_TRACE_ERROR("L2CAP got conn_req while connected (state:%d). Reject it", + L2CAP_TRACE_ERROR("L2CAP got conn_req while connected (state:%d). Reject it\n", p_lcb->link_state); /* Reject the connection with ACL Connection Already exist reason */ //counter_add("l2cap.conn.reject.exists", 1); @@ -172,13 +172,13 @@ BOOLEAN l2c_link_hci_conn_comp (UINT8 status, UINT16 handle, BD_ADDR p_bda) /* If we don't have one, this is an error */ if (!p_lcb) { - L2CAP_TRACE_WARNING ("L2CAP got conn_comp for unknown BD_ADDR"); + L2CAP_TRACE_WARNING ("L2CAP got conn_comp for unknown BD_ADDR\n"); return (FALSE); } if (p_lcb->link_state != LST_CONNECTING) { - L2CAP_TRACE_ERROR ("L2CAP got conn_comp in bad state: %d status: 0x%d", p_lcb->link_state, status); + L2CAP_TRACE_ERROR ("L2CAP got conn_comp in bad state: %d status: 0x%d\n", p_lcb->link_state, status); if (status != HCI_SUCCESS) l2c_link_hci_disc_comp (p_lcb->handle, status); @@ -314,7 +314,7 @@ void l2c_link_sec_comp (BD_ADDR p_bda, tBT_TRANSPORT transport, void *p_ref_data /* If we don't have one, this is an error */ if (!p_lcb) { - L2CAP_TRACE_WARNING ("L2CAP got sec_comp for unknown BD_ADDR"); + L2CAP_TRACE_WARNING ("L2CAP got sec_comp for unknown BD_ADDR\n"); return; } @@ -774,7 +774,7 @@ void l2c_link_adjust_allocation (void) qq = qq_remainder = 1; } - L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u", + L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation num_hipri: %u num_lowpri: %u low_quota: %u round_robin_quota: %u qq: %u\n", num_hipri_links, num_lowpri_links, low_quota, l2cb.round_robin_quota, qq); @@ -803,10 +803,10 @@ void l2c_link_adjust_allocation (void) } } - L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d", + L2CAP_TRACE_EVENT ("l2c_link_adjust_allocation LCB %d Priority: %d XmitQuota: %d\n", yy, p_lcb->acl_priority, p_lcb->link_xmit_quota); - L2CAP_TRACE_EVENT (" SentNotAcked: %d RRUnacked: %d", + L2CAP_TRACE_EVENT (" SentNotAcked: %d RRUnacked: %d\n", p_lcb->sent_not_acked, l2cb.round_robin_unacked); /* There is a special case where we have readjusted the link quotas and */ @@ -1081,7 +1081,7 @@ BOOLEAN l2c_link_check_power_mode (tL2C_LCB *p_lcb) { if ( mode == BTM_PM_STS_PENDING ) { - L2CAP_TRACE_DEBUG ("LCB(0x%x) is in PM pending state", p_lcb->handle); + L2CAP_TRACE_DEBUG ("LCB(0x%x) is in PM pending state\n", p_lcb->handle); return TRUE; } @@ -1510,7 +1510,7 @@ void l2c_link_process_num_completed_pkts (UINT8 *p) #if (BLE_INCLUDED == TRUE) if (p_lcb->transport == BT_TRANSPORT_LE) { - L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", + L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d\n", l2cb.controller_le_xmit_window, p_lcb->handle, p_lcb->sent_not_acked, l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked); @@ -1518,7 +1518,7 @@ void l2c_link_process_num_completed_pkts (UINT8 *p) else #endif { - L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d", + L2CAP_TRACE_DEBUG ("TotalWin=%d,LinkUnack(0x%x)=%d,RRCheck=%d,RRUnack=%d\n", l2cb.controller_xmit_window, p_lcb->handle, p_lcb->sent_not_acked, l2cb.check_round_robin, l2cb.round_robin_unacked); @@ -1528,13 +1528,13 @@ void l2c_link_process_num_completed_pkts (UINT8 *p) else { #if (BLE_INCLUDED == TRUE) - L2CAP_TRACE_DEBUG ("TotalWin=%d LE_Win: %d, Handle=0x%x, RRCheck=%d, RRUnack=%d", + L2CAP_TRACE_DEBUG ("TotalWin=%d LE_Win: %d, Handle=0x%x, RRCheck=%d, RRUnack=%d\n", l2cb.controller_xmit_window, l2cb.controller_le_xmit_window, handle, l2cb.ble_check_round_robin, l2cb.ble_round_robin_unacked); #else - L2CAP_TRACE_DEBUG ("TotalWin=%d Handle=0x%x RRCheck=%d RRUnack=%d", + L2CAP_TRACE_DEBUG ("TotalWin=%d Handle=0x%x RRCheck=%d RRUnack=%d\n", l2cb.controller_xmit_window, handle, l2cb.check_round_robin, l2cb.round_robin_unacked); @@ -1572,7 +1572,7 @@ void l2c_link_segments_xmitted (BT_HDR *p_msg) /* Find the LCB based on the handle */ if ((p_lcb = l2cu_find_lcb_by_handle (handle)) == NULL) { - L2CAP_TRACE_WARNING ("L2CAP - rcvd segment complete, unknown handle: %d", handle); + L2CAP_TRACE_WARNING ("L2CAP - rcvd segment complete, unknown handle: %d\n", handle); GKI_freebuf (p_msg); return; } diff --git a/components/bt/bluedroid/stack/l2cap/l2cap_client.c b/components/bt/bluedroid/stack/l2cap/l2cap_client.c index 4b64e1198..086500276 100755 --- a/components/bt/bluedroid/stack/l2cap/l2cap_client.c +++ b/components/bt/bluedroid/stack/l2cap/l2cap_client.c @@ -268,7 +268,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego case L2CAP_CFG_UNACCEPTABLE_PARAMS: // TODO: see if we can renegotiate parameters instead of dropping the connection. - LOG_WARN("%s dropping L2CAP connection due to unacceptable config parameters.", __func__); + LOG_WARN("%s dropping L2CAP connection due to unacceptable config parameters.\n", __func__); l2cap_client_disconnect(client); break; @@ -281,7 +281,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego // Failure, no further parameter negotiation possible. default: - LOG_WARN("%s L2CAP parameter negotiation failed with error code %d.", __func__, negotiated_parameters->result); + LOG_WARN("%s L2CAP parameter negotiation failed with error code %d.\n", __func__, negotiated_parameters->result); l2cap_client_disconnect(client); break; } @@ -290,7 +290,7 @@ static void config_completed_cb(uint16_t local_channel_id, tL2CAP_CFG_INFO *nego static void disconnect_request_cb(uint16_t local_channel_id, bool ack_required) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.\n", __func__, local_channel_id); return; } @@ -309,7 +309,7 @@ static void disconnect_completed_cb(uint16_t local_channel_id, UNUSED_ATTR uint1 l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR("%s unable to find L2CAP client with LCID 0x%04x.\n", __func__, local_channel_id); return; } @@ -324,7 +324,7 @@ static void congestion_cb(uint16_t local_channel_id, bool is_congested) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.\n", __func__, local_channel_id); return; } @@ -345,7 +345,7 @@ static void read_ready_cb(uint16_t local_channel_id, BT_HDR *packet) { l2cap_client_t *client = find(local_channel_id); if (!client) { - LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.", __func__, local_channel_id); + LOG_ERROR("%s unable to find L2CAP client matching LCID 0x%04x.\n", __func__, local_channel_id); return; } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index 6c24854dd..2e0b742a3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -168,7 +168,7 @@ esp_ble_adv_data_cfg_t wechat_adv_data[ADV_SCAN_IDX_MAX] = }; #if (BUT_PROFILE_CFG) -static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data); +static void SimpleDataCallBack(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *p_data); #endif typedef struct { @@ -303,7 +303,7 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } #if (BUT_PROFILE_CFG) -static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data) +static void SimpleDataCallBack(uint8_t app_id, uint8_t event, uint16_t len, uint8_t *p_data) { LOG_ERROR("the event value is:%x\n",event); switch(event) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index f2012dca5..265c014ad 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -63,7 +63,6 @@ typedef tBTA_GATTC_IF esp_gattc_if_t; #define ESP_GATTC_ACL_EVT 13 /* ACL up event */ #define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */ #define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */ -#define ESP_GATTC_LISTEN_EVT 16 /* listen event */ #define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */ #define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */ #define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */ @@ -91,7 +90,7 @@ typedef tBTA_GATTC_IF esp_gattc_if_t; #define ESP_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */ #define ESP_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */ #define ESP_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */ -#define ESP_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF /* 5 */ +#define ESP_GATTS_CFM_EVT GATTS_REQ_TYPE_CONF /* 5 */ #define ESP_GATTS_DEREG_EVT 6 #define ESP_GATTS_CREATE_EVT 7 #define ESP_GATTS_ADD_INCL_SRVC_EVT 8 @@ -105,7 +104,6 @@ typedef tBTA_GATTC_IF esp_gattc_if_t; #define ESP_GATTS_OPEN_EVT 16 #define ESP_GATTS_CANCEL_OPEN_EVT 17 #define ESP_GATTS_CLOSE_EVT 18 -#define ESP_GATTS_LISTEN_EVT 19 #define ESP_GATTS_CONGEST_EVT 20 /* Attribute permissions From 2cea783ca1639df0b2ffe80d2f421234175ff80f Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 2 Nov 2016 02:21:31 -0400 Subject: [PATCH 15/31] component bt:Added the app_button event process function to the bt project --- .../profiles/esp/include/button_pro.h | 26 ++++++------ .../app_sample_button/app_button.c | 41 +++++++++++++++++++ .../bluedroid_demos/include/app_button_int.h | 14 +++++++ 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index 08ca83cd1..8e95a0d99 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -65,30 +65,30 @@ enum typedef struct { - BD_ADDR remote_bda; - BOOLEAN need_rsp; - UINT16 clt_cfg; + BD_ADDR remote_bda; + BOOLEAN need_rsp; + uint16_t clt_cfg; }but_write_data_t; typedef struct { BOOLEAN in_use; BOOLEAN congest; - UINT16 conn_id; + uint16_t conn_id; BOOLEAN connected; BD_ADDR remote_bda; - UINT32 trans_id; - UINT8 cur_srvc_id; + uint32_t trans_id; + uint8_t cur_srvc_id; }but_clcb_t; typedef struct { - UINT8 app_id; - UINT16 but_wirt_hdl; - UINT16 but_ntf_hdl; - UINT16 but_cfg_hdl; + uint8_t app_id; + uint16_t but_wirt_hdl; + uint16_t but_ntf_hdl; + uint16_t but_cfg_hdl; but_prf_cb_t p_cback; @@ -99,11 +99,11 @@ typedef struct typedef struct { but_clcb_t clcb; /* connection link*/ - tGATT_IF gatt_if; + esp_gatt_if_t gatt_if; BOOLEAN enabled; BOOLEAN is_primery; - but_inst_t button_inst; - UINT8 inst_id; + but_inst_t button_inst; + uint8_t inst_id; }button_env_cb_t; void Button_CreateService(void); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index c685e8e44..c224e7031 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -41,6 +41,13 @@ #include "button_pro.h" #include "app_button_int.h" +static const tBTA_SYS_REG bta_gatts_reg = +{ + ble_but_prf_hdl_event, + ble_but_prf_disable +}; + + /******************************************************************************* ** @@ -82,6 +89,40 @@ BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data) } +/******************************************************************************* +** +** Function ble_but_prf_disable +** +** Description This function is called to disable the button profile modlue +** +** Parameters None. +** +** Returns None +** +*******************************************************************************/ +void ble_but_prf_disable(void) +{ + BT_HDR *p_buf; + + if (bt_prf_sys_is_register(PRF_ID_BUT_LE) == FALSE) + { + APPL_TRACE_WARNING("button profile Module not enabled/already disabled"); + return; + } + + if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) + { + p_buf->event = BTA_GATTS_API_DISABLE_EVT; + bta_sys_sendmsg(p_buf); + } + bta_sys_deregister(PRF_ID_BUT_LE); + +} + + + + + #endif ///BUT_PROFILE_CFG diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h index 5bfb430fd..bfd7c4708 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -105,10 +105,24 @@ typedef struct uint16_t conhdl; }tBUT_DISABLE_IND; +typedef union +{ + uint16_t conhdl; + tBUT_CRT_DB_REQ but_crt_db_req; + tBUT_CRT_DB_CFM but_crt_db_cfm; + tBUT_CFG_NTF_IND but_cfg_ntf_ind; + tBUT_SND_CHAR_VAL_REQ but_snd_char_val_req; + tBUT_ENABLE_REQ but_enable_req; + tBUT_VAL_SND_CFM but_val_snd_cfm; + tBUT_DISABLE_IND but_disable_ind; +}tBUT_PRF_MSG; + BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data); +void ble_but_prf_disable(void); + #endif ///BUT_PROFILE_CFG From a0007ceb79e3e7559ffa318a9e6e8823ac73a2d3 Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 2 Nov 2016 03:45:00 -0400 Subject: [PATCH 16/31] component bt:Change the HIDD profile function to the new api function --- .../profiles/std/hid_le/hid_le_prf.c | 160 +++++++++--------- .../profiles/std/include/hid_le_prf.h | 64 +++---- .../bluedroid/profiles/std/include/prf_defs.h | 31 ++-- 3 files changed, 128 insertions(+), 127 deletions(-) diff --git a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c index 4b225132b..550dcf716 100644 --- a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c +++ b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c @@ -16,14 +16,14 @@ #include "prf_defs.h" #if (HIDD_LE_PROFILE_CFG) -tHIDD_LE_ENV hidd_le_env; +hidd_le_env_t hidd_le_env; #define HI_UINT16(a) (((a) >> 8) & 0xFF) #define LO_UINT16(a) ((a) & 0xFF) // HID Information characteristic value -static const UINT8 hidInfo[HID_INFORMATION_LEN] = +static const uint8_t hidInfo[HID_INFORMATION_LEN] = { LO_UINT16(0x0111), HI_UINT16(0x0111), // bcdHID (USB HID version) 0x00, // bCountryCode @@ -32,7 +32,7 @@ static const UINT8 hidInfo[HID_INFORMATION_LEN] = // HID Report Map characteristic value // Keyboard report descriptor (using format for Boot interface descriptor) -static const UINT8 hidReportMap[] = +static const uint8_t hidReportMap[] = { 0x05, 0x01, // Usage Page (Generic Desktop) 0x09, 0x02, // Usage (Mouse) @@ -169,27 +169,27 @@ static const UINT8 hidReportMap[] = }; // HID report map length -UINT8 hidReportMapLen = sizeof(hidReportMap); +uint8_t hidReportMapLen = sizeof(hidReportMap); -UINT8 hidProtocolMode = HID_PROTOCOL_MODE_REPORT; +uint8_t hidProtocolMode = HID_PROTOCOL_MODE_REPORT; // HID report mapping table static hidRptMap_t hidRptMap[HID_NUM_REPORTS]; -tBT_UUID char_info_uuid = {LEN_UUID_16, {CHAR_HID_INFO_UUID}}; -tBT_UUID char_ctnl_pt_uuid = {LEN_UUID_16, {CHAR_HID_CTNL_PT_UUID}}; -tBT_UUID char_report_map_uuid = {LEN_UUID_16, {CHAR_REPORT_MAP_UUID}}; -tBT_UUID char_report_uuid = {LEN_UUID_16, {CHAR_REPORT_UUID}}; -tBT_UUID char_proto_mode_uuid = {LEN_UUID_16, {CHAR_PROTOCOL_MODE_UUID}}; -tBT_UUID char_kb_in_report_uuid = {LEN_UUID_16, {CHAR_BOOT_KB_IN_REPORT_UUID}}; -tBT_UUID char_kb_out_report_uuid = {LEN_UUID_16,{CHAR_BOOT_KB_OUT_REPORT_UUID}}; -tBT_UUID char_mouse_in_report_uuid = {LEN_UUID_16,{CHAR_BOOT_MOUSE_IN_REPORT_UUID}}; +esp_bt_uuid_t char_info_uuid = {LEN_UUID_16, {CHAR_HID_INFO_UUID}}; +esp_bt_uuid_t char_ctnl_pt_uuid = {LEN_UUID_16, {CHAR_HID_CTNL_PT_UUID}}; +esp_bt_uuid_t char_report_map_uuid = {LEN_UUID_16, {CHAR_REPORT_MAP_UUID}}; +esp_bt_uuid_t char_report_uuid = {LEN_UUID_16, {CHAR_REPORT_UUID}}; +esp_bt_uuid_t char_proto_mode_uuid = {LEN_UUID_16, {CHAR_PROTOCOL_MODE_UUID}}; +esp_bt_uuid_t char_kb_in_report_uuid = {LEN_UUID_16, {CHAR_BOOT_KB_IN_REPORT_UUID}}; +esp_bt_uuid_t char_kb_out_report_uuid = {LEN_UUID_16,{CHAR_BOOT_KB_OUT_REPORT_UUID}}; +esp_bt_uuid_t char_mouse_in_report_uuid = {LEN_UUID_16,{CHAR_BOOT_MOUSE_IN_REPORT_UUID}}; /// Full HID device Database Description - Used to add attributes into the database -const tCHAR_DESC hids_char_db[HIDD_LE_CHAR_MAX] = +const char_desc_t hids_char_db[HIDD_LE_CHAR_MAX] = { // HID Information Characteristic Value [HIDD_LE_INFO_CHAR] = { @@ -247,25 +247,25 @@ const tCHAR_DESC hids_char_db[HIDD_LE_CHAR_MAX] = }, }; -static void HID_AddCharacteristic(const tCHAR_DESC *char_desc); +static void hidd_add_characterisitc(const char_desc_t *char_desc); /***************************************************************************** ** Constants *****************************************************************************/ -static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); +static void hidd_le_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data); /******************************************************************************* ** -** Function hidd_le_profile_cb +** Function hidd_add_characterisitc ** ** Description the callback function after the hid device profile has been register to the BTA manager module ** ** Returns NULL ** *******************************************************************************/ -static void HID_AddCharacteristic(const tCHAR_DESC *char_desc) +static void hidd_add_characterisitc(const char_desc_t *char_desc) { - UINT16 service_id; + uint16_t service_id; if(char_desc == NULL) { LOG_ERROR("Invalid hid characteristic\n"); @@ -282,7 +282,7 @@ static void HID_AddCharacteristic(const tCHAR_DESC *char_desc) if(char_desc->char_uuid != 0x00) { // start added the charact to the data base - BTA_GATTS_AddCharacteristic(service_id, + esp_ble_gatts_add_char (service_id, char_desc->char_uuid, char_desc->perm, char_desc->prop); @@ -299,19 +299,19 @@ static void HID_AddCharacteristic(const tCHAR_DESC *char_desc) ** Returns NULL ** *******************************************************************************/ -static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) +static void hidd_le_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) { - tBTA_GATTS_RSP rsp; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}}; - static UINT8 hid_char_idx; - tHIDD_CLCB *p_clcb = NULL; - UINT8 app_id = 0xff; + esp_gatts_rsp_t rsp; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_HID}}; + static uint8_t hid_char_idx; + hidd_clcb_t *p_clcb = NULL; + uint8_t app_id = 0xff; switch(event) { - case BTA_GATTS_REG_EVT: + case ESP_GATTS_REG_EVT: //check the register of the hid device profile has been succeess or not - if(p_data->reg_oper.status != BTA_GATT_OK) + if(p_data->reg_oper.status != ESP_GATT_OK) { LOG_ERROR("hidd profile register failed\n"); } @@ -323,27 +323,27 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //create the hid device service to the service data base. if(p_data->reg_oper.uuid.uu.uuid16 == ATT_SVC_HID) { - hidd_le_CreateService(true); + hidd_le_create_service(true); } break; - case BTA_GATTS_CREATE_EVT: + case ESP_GATTS_CREATE_EVT: if(p_data->create.uuid.uu.uuid16 == ATT_SVC_HID) { ///store the service id to the env hidd_le_env.hidd_clcb.cur_srvc_id = p_data->create.service_id; //start the button service after created - BTA_GATTS_StartService(p_data->create.service_id,BTA_GATT_TRANSPORT_LE); + esp_ble_gatts_start_srvc(p_data->create.service_id); hid_char_idx = HIDD_LE_INFO_CHAR; //added the info character to the data base. - HID_AddCharacteristic(&hids_char_db[hid_char_idx]); + hidd_add_characterisitc(&hids_char_db[hid_char_idx]); hid_char_idx++; } break; - case BTA_GATTS_ADD_INCL_SRVC_EVT: + case ESP_GATTS_ADD_INCL_SRVC_EVT: break; - case BTA_GATTS_ADD_CHAR_EVT: + case ESP_GATTS_ADD_CHAR_EVT: //save the charateristic handle to the env hidd_le_env.hidd_inst.att_tbl[hid_char_idx-1] = p_data->add_result.attr_id; LOG_ERROR("hanlder = %x, p_data->add_result.char_uuid.uu.uuid16 = %x\n",p_data->add_result.attr_id, @@ -360,18 +360,18 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; LOG_ERROR("p_data->add_result.char_uuid.uu.uuid16 = %x\n", p_data->add_result.char_uuid.uu.uuid16); - BTA_GATTS_AddCharDescriptor (hidd_le_env.hidd_clcb.cur_srvc_id, + esp_ble_gatts_add_char_descr (hidd_le_env.hidd_clcb.cur_srvc_id, GATT_PERM_WRITE, &uuid); break; } - HID_AddCharacteristic(&hids_char_db[hid_char_idx]); + hidd_add_characterisitc(&hids_char_db[hid_char_idx]); } hid_char_idx++; break; - case BTA_GATTS_ADD_CHAR_DESCR_EVT: + case ESP_GATTS_ADD_CHAR_DESCR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) { uuid.uu.uuid16 = GATT_UUID_RPT_REF_DESCR; @@ -385,12 +385,12 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) { if(hid_char_idx < HIDD_LE_CHAR_MAX) { - HID_AddCharacteristic(&hids_char_db[hid_char_idx]); + hidd_add_characterisitc(&hids_char_db[hid_char_idx]); hid_char_idx++; } } break; - case BTA_GATTS_READ_EVT: + case ESP_GATTS_READ_EVT: { LOG_ERROR("Hidd profile BTA_GATTS_READ_EVT\n"); UINT32 trans_id = p_data->req_data.trans_id; @@ -403,11 +403,11 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) hidd_read_attr_value(p_data->req_data.p_data,trans_id); } break; - case BTA_GATTS_WRITE_EVT: - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, - p_data->req_data.status,NULL); + case ESP_GATTS_WRITE_EVT: + esp_ble_gatts_send_rsp (p_data->req_data.conn_id,p_data->req_data.trans_id, + p_data->req_data.status,NULL); break; - case BTA_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: p_clcb = &hidd_le_env.hidd_clcb; if(!p_clcb->in_use) @@ -419,16 +419,16 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) memcpy(p_clcb->remote_bda, p_data->conn.remote_bda,BD_ADDR_LEN); } break; - case BTA_GATTS_DISCONNECT_EVT: + case ESP_GATTS_DISCONNECT_EVT: p_clcb = &hidd_le_env.hidd_clcb; //set the connection flag to true p_clcb->connected = false; p_clcb->in_use = TRUE; - memset(p_clcb->remote_bda,0,BD_ADDR_LEN); + memset(p_clcb->remote_bda, 0, BD_ADDR_LEN); break; - case BTA_GATTS_START_EVT: + case ESP_GATTS_START_EVT: break; - case BTA_GATTS_CONGEST_EVT: + case ESP_GATTS_CONGEST_EVT: if(hidd_le_env.hidd_clcb.connected && (hidd_le_env.hidd_clcb.conn_id == p_data->conn.conn_id)) { //set the connection channal congested flag to true @@ -442,7 +442,7 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) /******************************************************************************* ** -** Function hidd_le_CreateService +** Function hidd_le_create_service ** ** Description Create a Service for the hid device profile ** @@ -453,17 +453,17 @@ static void hidd_le_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) ** Returns NULL ** *******************************************************************************/ -void hidd_le_CreateService(BOOLEAN is_primary) +void hidd_le_create_service(BOOLEAN is_primary) { - tBTA_GATTS_IF server_if ; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_HID}}; + esp_gatts_if_t server_if ; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_HID}}; //the number of the hid device attributes in the hid service. UINT16 num_handle = HIDD_LE_IDX_NB; UINT8 inst = 0x00; server_if = hidd_le_env.gatt_if; hidd_le_env.inst_id = inst; //start create the hid device service - BTA_GATTS_CreateService(server_if,&uuid,inst,num_handle,is_primary); + esp_ble_gatts_create_srvc (server_if,&uuid,inst,num_handle,is_primary); } @@ -472,16 +472,16 @@ void hidd_le_CreateService(BOOLEAN is_primary) ** ** Description it will be called when client sends a read request ******************************************************************************/ -void hidd_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id) +void hidd_read_attr_value(tGATTS_DATA *p_data, uint32_t trans_id) { - tHIDD_INST *p_inst = &hidd_le_env.hidd_inst; - UINT8 i; - UINT8 status = GATT_SUCCESS; - UINT8 app_id = hidd_le_env.hidd_inst.app_id; + hidd_inst_t *p_inst = &hidd_le_env.hidd_inst; + uint8_t i; + uint8_t status = ESP_GATT_OK; + uint8_t app_id = hidd_le_env.hidd_inst.app_id; - tGATT_STATUS st = GATT_NOT_FOUND; - UINT16 handle = p_data->read_req.handle; - UINT16 conn_id = hidd_le_env.hidd_clcb.conn_id; + esp_gatt_status_t st = ESP_GATT_NOT_FOUND; + uint16_t handle = p_data->read_req.handle; + uint16_t conn_id = hidd_le_env.hidd_clcb.conn_id; if (handle == p_inst->att_tbl[HIDD_LE_INFO_CHAR]) { @@ -512,22 +512,22 @@ void hidd_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id) } //start build the rsp message - Hidd_Rsp(trans_id,conn_id,app_id,status, p_inst->pending_evt,p_data); + hidd_rsp(trans_id, conn_id, app_id, status, p_inst->pending_evt, p_data); } /******************************************************************************* ** -** Function Hidd_Rsp +** Function hidd_rsp ** ** Description Respond to a hid device service request ** *******************************************************************************/ -void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, - tGATT_STATUS status, UINT8 event, tGATTS_DATA *p_rsp) +void hidd_rsp (uint32_t trans_id, uint16_t conn_id, uint8_t app_id, + esp_gatt_status_t status, uint8_t event, tGATTS_DATA *p_rsp) { - tHIDD_INST *p_inst = &hidd_le_env.hidd_inst; + hidd_inst_t *p_inst = &hidd_le_env.hidd_inst; tGATTS_RSP rsp; - UINT8 *pp; + uint8_t *pp; LOG_ERROR("conn_id = %x, trans_id = %x, event = %x\n", conn_id,trans_id,event); @@ -548,7 +548,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, //copy the infomation value to the att value to sent to the peer device memcpy(rsp.attr_value.value,hidInfo,HID_INFORMATION_LEN); //start send the rsp to the peer device - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_READ_CTNL_PT_EVT: @@ -557,7 +557,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.handle = p_inst->att_tbl[HIDD_LE_CTNL_PT_CHAR]; rsp.attr_value.len = 0; //start send the rsp to the peer device - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_READ_REPORT_MAP_EVT: @@ -568,7 +568,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, //copy the infomation value to the att value to sent to the peer device memcpy(rsp.attr_value.value,hidReportMap,hidReportMapLen); //start send the rsp to the peer device - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_READ_REPORT_EVT: LOG_ERROR("p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR] = %x\n", @@ -576,7 +576,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.handle = p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR]; rsp.attr_value.len = 0; - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_READ_PROTO_MODE_EVT: LOG_ERROR("p_inst->att_tbl[HIDD_LE_PROTO_MODE_CHAR] = %x\n", @@ -586,7 +586,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, pp = rsp.attr_value.value; //copy the infomation value to the att value to sent to the peer device memcpy(rsp.attr_value.value,&hidProtocolMode,rsp.attr_value.len); - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_BOOT_KB_IN_REPORT_EVT: LOG_ERROR("p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR] = %x\n", @@ -594,7 +594,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.handle = p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR]; rsp.attr_value.len = 0; - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_BOOT_KB_OUT_REPORT_EVT: LOG_ERROR("p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR] = %x\n", @@ -602,7 +602,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.handle = p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR]; rsp.attr_value.len = 0; - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; case HIDD_LE_BOOT_MOUSE_IN_REPORT_EVT: LOG_ERROR("p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR] = %x\n", @@ -610,7 +610,7 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.handle = p_inst->att_tbl[HIDD_LE_BOOT_KB_IN_REPORT_CHAR]; rsp.attr_value.len = 0; - BTA_GATTS_SendRsp(conn_id, trans_id, status, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, status, &rsp); break; default: break; @@ -630,28 +630,28 @@ void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, ** Description Initializa the GATT Service for button profiles. ** Returns NULL *******************************************************************************/ -tGATT_STATUS hidd_le_init (void) +esp_gatt_status_t hidd_le_init (void) { tBT_UUID app_uuid = {LEN_UUID_16,{ATT_SVC_HID}}; if(hidd_le_env.enabled) { - LOG_ERROR("hid device svc already initaliezd"); - return GATT_ERROR; + LOG_ERROR("hid device svc already initaliezd\n"); + return ESP_GATT_ERROR; } else { - memset(&hidd_le_env,0,sizeof(tHIDD_LE_ENV)); + memset(&hidd_le_env,0,sizeof(hidd_le_env_t)); } /* register the hid deivce profile to the BTA_GATTS module*/ - BTA_GATTS_AppRegister(&app_uuid,hidd_le_profile_cb); + esp_ble_gatts_app_register(&app_uuid, hidd_le_profile_cb); hidd_le_env.enabled = TRUE; - return GATT_SUCCESS; + return ESP_GATT_OK; } diff --git a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h index c38af0208..753a2f66e 100644 --- a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h +++ b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h @@ -195,76 +195,76 @@ enum typedef struct { /// Service Features - UINT8 svc_features; + uint8_t svc_features; /// Number of Report Char. instances to add in the database - UINT8 report_nb; + uint8_t report_nb; /// Report Char. Configuration - UINT8 report_char_cfg[HIDD_LE_NB_REPORT_INST_MAX]; - }tHIDD_FEATURE; + uint8_t report_char_cfg[HIDD_LE_NB_REPORT_INST_MAX]; + }hidd_feature_t; typedef struct { BOOLEAN in_use; BOOLEAN congest; - UINT16 conn_id; + uint16_t conn_id; BOOLEAN connected; BD_ADDR remote_bda; - UINT32 trans_id; - UINT8 cur_srvc_id; + uint32_t trans_id; + uint8_t cur_srvc_id; - }tHIDD_CLCB; + }hidd_clcb_t; // HID report mapping table typedef struct { - UINT16 handle; // Handle of report characteristic - UINT16 cccdHandle; // Handle of CCCD for report characteristic - UINT8 id; // Report ID - UINT8 type; // Report type - UINT8 mode; // Protocol mode (report or boot) + uint16_t handle; // Handle of report characteristic + uint16_t cccdHandle; // Handle of CCCD for report characteristic + uint8_t id; // Report ID + uint8_t type; // Report type + uint8_t mode; // Protocol mode (report or boot) } hidRptMap_t; typedef struct { /// hidd profile id - UINT8 app_id; + uint8_t app_id; /// Notified handle - UINT16 ntf_handle; + uint16_t ntf_handle; ///Attribute handle Table - UINT16 att_tbl[HIDD_LE_CHAR_MAX]; + uint16_t att_tbl[HIDD_LE_CHAR_MAX]; /// Supported Features - tHIDD_FEATURE hidd_feature[HIDD_LE_NB_HIDS_INST_MAX]; + hidd_feature_t hidd_feature[HIDD_LE_NB_HIDS_INST_MAX]; /// Current Protocol Mode - UINT8 proto_mode[HIDD_LE_NB_HIDS_INST_MAX]; + uint8_t proto_mode[HIDD_LE_NB_HIDS_INST_MAX]; /// Number of HIDS added in the database - UINT8 hids_nb; - UINT8 pending_evt; - UINT16 pending_hal; - }tHIDD_INST; + uint8_t hids_nb; + uint8_t pending_evt; + uint16_t pending_hal; + }hidd_inst_t; /* service engine control block */ typedef struct { - tHIDD_CLCB hidd_clcb; /* connection link*/ - tGATT_IF gatt_if; + hidd_clcb_t hidd_clcb; /* connection link*/ + esp_gatt_if_t gatt_if; BOOLEAN enabled; BOOLEAN is_primery; - tHIDD_INST hidd_inst; - UINT8 inst_id; - }tHIDD_LE_ENV; + hidd_inst_t hidd_inst; + uint8_t inst_id; + }hidd_le_env_t; - extern tHIDD_LE_ENV hidd_le_env; + extern hidd_le_env_t hidd_le_env; - void hidd_le_CreateService(BOOLEAN is_primary); + void hidd_le_create_service(BOOLEAN is_primary); - void Hidd_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, - tGATT_STATUS status, UINT8 event, tGATTS_DATA *p_rsp); + void hidd_rsp (uint32_t trans_id, uint16_t conn_id, uint8_t app_id, + esp_gatt_status_t status, uint8_t event, tGATTS_DATA *p_rsp); - void hidd_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id); + void hidd_read_attr_value(tGATTS_DATA *p_data, uint32_t trans_id); tGATT_STATUS hidd_le_init (void); diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 351657b6b..6fb53d73b 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -19,6 +19,7 @@ #include "bta_gatts_int.h" #include "bta_gatt_api.h" #include "bt_types.h" +#include "bt_app_defs.h" #define ATT_HANDLE_LEN 0x0002 @@ -39,46 +40,46 @@ typedef struct { ///characteristic uuid - tBT_UUID *char_uuid; + esp_bt_uuid_t *char_uuid; ///the permition of the characteristic - tBTA_GATT_PERM perm; + esp_gatt_perm_t perm; /// the properties of the characteristic - tBTA_GATT_CHAR_PROP prop; -}tCHAR_DESC; + esp_gatt_char_prop_t prop; +}char_desc_t; /// UUID - 128-bit type typedef struct { /// 128-bit UUID - UINT8 uuid[ATT_UUID_128_LEN]; -}tUUID_128; + uint8_t uuid[ATT_UUID_128_LEN]; +}uuid_128_t; /// UUID - 32-bit type typedef struct { /// 32-bit UUID - UINT8 uuid[ATT_UUID_32_LEN]; -}tUUID_32; + uint8_t uuid[ATT_UUID_32_LEN]; +}uuid_32_t; /// include service entry element typedef struct { /// start handle value of included service - UINT16 start_hdl; + uint16_t start_hdl; /// end handle value of included service - UINT16 end_hdl; + uint16_t end_hdl; /// attribute value UUID - UINT16 uuid; -}tSVC_INCL_DESC; + uint16_t uuid; +}incl_svc_desc; /// Service Changed type definition typedef struct { /// Service start handle which changed - UINT16 start_hdl; + uint16_t start_hdl; /// Service end handle which changed - UINT16 end_hdl; -}tSVC_CHANG; + uint16_t end_hdl; +}svc_chang_type_t; From bc604d14ff5c5467df86933842ff90501b023a3d Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 2 Nov 2016 06:14:02 -0400 Subject: [PATCH 17/31] component bt: Change the battery function to the new API function --- .../profiles/std/battery/battery_prf.c | 91 ++++++++++--------- .../bluedroid/profiles/std/dis/dis_profile.c | 30 +++--- .../bluedroid/profiles/std/include/dis_api.h | 1 + components/bt/bluedroid/stack/btm/btm_ble.c | 12 +-- components/bt/bluedroid/stack/btm/btm_sec.c | 2 +- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/components/bt/bluedroid/profiles/std/battery/battery_prf.c b/components/bt/bluedroid/profiles/std/battery/battery_prf.c index b82fbd5e4..383bd5dfd 100644 --- a/components/bt/bluedroid/profiles/std/battery/battery_prf.c +++ b/components/bt/bluedroid/profiles/std/battery/battery_prf.c @@ -35,7 +35,7 @@ #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] -tBTA_GATTS_IF server_if; +esp_gatts_if_t server_if; tBATTERY_CB battery_cb; tGATT_CHAR_PROP prop = GATT_CHAR_PROP_BIT_READ; @@ -43,19 +43,19 @@ tBA_REG_INFO ba_reg_info; UINT8 attr_handle_bit = 0x00; extern tDIS_CB dis_cb; -tBT_UUID bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}}; +esp_bt_uuid_t bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}}; /****************************************************************************** ** Function bas_gatts_callback ** ** Description battery service register callback function *******************************************************************************/ -static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) +static void bas_gatts_callback(esp_gatts_evt_t event, tBTA_GATTS* p_data) { switch (event) { - case BTA_GATTS_REG_EVT: + case ESP_GATTS_REG_EVT: { - tBTA_GATT_STATUS status = p_data->reg_oper.status; + esp_gatt_status_t status = p_data->reg_oper.status; server_if = p_data->reg_oper.server_if; LOG_ERROR("BAS register completed: event=%d, status=%d, server_if=%d\n", event, status, server_if); @@ -69,7 +69,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) break; /*connect callback*/ - case BTA_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: { LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n", BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if, @@ -81,7 +81,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) break; /*create service callback*/ - case BTA_GATTS_CREATE_EVT: + case ESP_GATTS_CREATE_EVT: { LOG_ERROR("create service:server_if=%d,service_id=0x%x,service_uuid=0x%x\n", p_data->create.server_if, p_data->create.service_id, @@ -103,7 +103,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_ADD_CHAR_EVT: + case ESP_GATTS_ADD_CHAR_EVT: { LOG_ERROR("create characteristic:server_if=%d,service_id=0x%x,char_uuid=0x%x\n", p_data->add_result.server_if, p_data->add_result.service_id, @@ -141,7 +141,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_ADD_CHAR_DESCR_EVT: + case ESP_GATTS_ADD_CHAR_DESCR_EVT: { LOG_ERROR("create descriptor:server_if=%d,service_id=0x%x,attr_id=0x%x,char_uuid=0x%x\n", @@ -151,7 +151,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_START_EVT: + case ESP_GATTS_START_EVT: { LOG_ERROR("start service:server_if=%d,service_id=0x%x\n", p_data->srvc_oper.server_if, p_data->srvc_oper.service_id); @@ -164,7 +164,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_READ_EVT: + case ESP_GATTS_READ_EVT: { UINT32 trans_id = p_data->req_data.trans_id; UINT16 conn_id = p_data->req_data.conn_id; @@ -186,7 +186,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_WRITE_EVT: + case ESP_GATTS_WRITE_EVT: { UINT32 trans_id = p_data->req_data.trans_id; @@ -199,7 +199,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_EXEC_WRITE_EVT: + case ESP_GATTS_EXEC_WRITE_EVT: { UINT32 trans_id = p_data->req_data.trans_id; UINT16 conn_id = p_data->req_data.conn_id; @@ -209,7 +209,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_MTU_EVT: + case ESP_GATTS_MTU_EVT: { UINT32 trans_id = p_data->req_data.trans_id; UINT16 conn_id = p_data->req_data.conn_id; @@ -219,7 +219,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) } break; - case BTA_GATTS_CONF_EVT: + case ESP_GATTS_CFM_EVT: { UINT32 trans_id = p_data->req_data.trans_id; @@ -231,6 +231,7 @@ static void bas_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) default: LOG_ERROR("unsettled event: %d\n", event); + break; } } @@ -243,7 +244,7 @@ static void bas_callback(UINT32 trans_id, UINT16 conn_id, UINT8 app_id, UINT8 event, tBA_WRITE_DATA *p_data) { tBA_RSP_DATA p_rsp; - tGATT_STATUS st = GATT_SUCCESS; + tGATT_STATUS st = ESP_GATT_OK; switch(event) { case BA_READ_LEVEL_REQ : @@ -299,10 +300,10 @@ static void bas_callback(UINT32 trans_id, UINT16 conn_id, UINT8 app_id, void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id) { - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - UINT8 i; - tGATT_STATUS st = GATT_NOT_FOUND; - UINT16 handle = p_data->read_req.handle; + tBA_INST *p_inst = &battery_cb.battery_inst[0]; + UINT8 i; + esp_gatt_status_t st = ESP_GATT_NOT_FOUND; + UINT16 handle = p_data->read_req.handle; for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++) @@ -314,7 +315,7 @@ void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id) handle == p_inst->pres_fmt_hdl) { if (p_data->read_req.is_long) - st = GATT_NOT_LONG; + st = ESP_GATT_NOT_LONG; if (p_inst->p_cback) { @@ -329,7 +330,7 @@ void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id) (*p_inst->p_cback)(trans_id, conn_id, p_inst->app_id, p_inst->pending_evt, NULL); } else /* application is not registered */ - st = GATT_ERR_UNLIKELY; + st = ESP_GATT_ERR_UNLIKELY; break; } /* else attribute not found */ @@ -343,12 +344,12 @@ void bas_s_read_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id) ******************************************************************************/ void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id, BD_ADDR bd_addr) { - tBA_WRITE_DATA cfg; - UINT8 *p = p_data->write_req.value; - tBA_INST *p_inst = &battery_cb.battery_inst[0]; - UINT8 i; - tGATT_STATUS st = GATT_NOT_FOUND; - UINT16 handle = p_data->write_req.handle; + tBA_WRITE_DATA cfg; + UINT8 *p = p_data->write_req.value; + tBA_INST *p_inst = &battery_cb.battery_inst[0]; + UINT8 i; + esp_gatt_status_t st = ESP_GATT_NOT_FOUND; + UINT16 handle = p_data->write_req.handle; for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++) @@ -366,7 +367,7 @@ void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id (*p_inst->p_cback)(trans_id, conn_id, p_inst->app_id, p_inst->pending_evt, &cfg); } else /* all other handle is not writable */ - st = GATT_WRITE_NOT_PERMIT; + st = ESP_GATT_WRITE_NOT_PERMIT; break; } @@ -381,7 +382,7 @@ void bas_s_write_attr_value(tGATTS_DATA *p_data, UINT32 trans_id, UINT16 conn_id ****************************************************************/ void bas_register(void) { - BTA_GATTS_AppRegister(&bas_uuid, bas_gatts_callback); + esp_ble_gatts_app_register(&bas_uuid, bas_gatts_callback); } /*************************************************************** @@ -410,7 +411,7 @@ void bas_init(tBTA_GATTS_IF gatt_if, UINT16 app_id) LOG_ERROR("create battery service\n"); LOG_ERROR("inst_id=%d\n", battery_cb.inst_id); - BTA_GATTS_CreateService (gatt_if, &bas_uuid, battery_cb.inst_id , + esp_ble_gatts_create_srvc (gatt_if, &bas_uuid, battery_cb.inst_id , BA_MAX_ATTR_NUM, ba_reg_info.is_pri); battery_cb.inst_id ++; @@ -432,7 +433,7 @@ void bas_AddChar(UINT16 service_id, tBT_UUID *char_uuid) if (ba_reg_info.ba_level_descr & BA_LEVEL_NOTIFY) prop |= GATT_CHAR_PROP_BIT_NOTIFY; attr_handle_bit = 0x01; - BTA_GATTS_AddCharacteristic(service_id, char_uuid, BATTER_LEVEL_PERM, prop); + esp_ble_gatts_add_char(service_id, char_uuid, BATTER_LEVEL_PERM, prop); } @@ -468,7 +469,7 @@ void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id) uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; ba_reg_info.ba_level_descr &= 0xfe; attr_handle_bit = 0x02; - BTA_GATTS_AddCharDescriptor(service_id, (GATT_PERM_READ|GATT_PERM_WRITE), &uuid); + esp_ble_gatts_add_char_descr(service_id, (GATT_PERM_READ|GATT_PERM_WRITE), &uuid); return; } @@ -476,7 +477,7 @@ void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id) if (ba_reg_info.ba_level_descr & BA_LEVEL_PRE_FMT) { uuid.uu.uuid16 = GATT_UUID_CHAR_PRESENT_FORMAT; - BTA_GATTS_AddCharDescriptor(service_id, GATT_PERM_READ, &uuid); + esp_ble_gatts_add_char_descr(service_id, GATT_PERM_READ, &uuid); ba_reg_info.ba_level_descr &= 0xfd; attr_handle_bit = 0x04; return; @@ -486,14 +487,14 @@ void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id) { uuid.uu.uuid16 = GATT_UUID_RPT_REF_DESCR; ba_reg_info.ba_level_descr &= 0xfb; - BTA_GATTS_AddCharDescriptor(service_id, GATT_PERM_READ, &uuid); + esp_ble_gatts_add_char_descr(service_id, GATT_PERM_READ, &uuid); attr_handle_bit = 0x08; return; } } else - BTA_GATTS_StartService(service_id, ba_reg_info.transport); + esp_ble_gatts_start_srvc(service_id); } @@ -504,12 +505,12 @@ void bas_AddCharDescr(UINT16 service_id, UINT16 attr_id) ** Description create battery service complete ** ****************************************************************/ -void bas_service_cmpl(UINT16 service_id, tBTA_GATT_STATUS status) +void bas_service_cmpl(UINT16 service_id, esp_gatt_status_t status) { - if(status != GATT_SUCCESS) + if(status != ESP_GATT_OK) { battery_cb.inst_id --; - BTA_GATTS_DeleteService(service_id); + esp_ble_gatts_dele_srvc(service_id); } } @@ -521,7 +522,7 @@ void bas_service_cmpl(UINT16 service_id, tBTA_GATT_STATUS status) ** *******************************************************************************/ void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, - tGATT_STATUS st, UINT8 event, tBA_RSP_DATA *p_rsp) + esp_gatt_status_t st, UINT8 event, tBA_RSP_DATA *p_rsp) { tBA_INST *p_inst = &battery_cb.battery_inst[0]; tGATTS_RSP rsp; @@ -549,7 +550,7 @@ void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.len = 2; pp = rsp.attr_value.value; UINT16_TO_STREAM(pp, p_rsp->clt_cfg); - BTA_GATTS_SendRsp(conn_id, trans_id, st, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, st, &rsp); //srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); break; @@ -558,12 +559,12 @@ void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, rsp.attr_value.len = 1; pp = rsp.attr_value.value; UINT8_TO_STREAM(pp, p_rsp->ba_level); - BTA_GATTS_SendRsp(conn_id, trans_id, st, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, st, &rsp); //srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); break; case BA_WRITE_CLT_CFG_REQ: - BTA_GATTS_SendRsp(conn_id, trans_id, st, NULL); + esp_ble_gatts_send_rsp(conn_id, trans_id, st, NULL); //srvc_sr_rsp(p_inst->pending_clcb_idx, st, NULL); break; @@ -573,7 +574,7 @@ void Battery_Rsp (UINT32 trans_id, UINT16 conn_id, UINT8 app_id, pp = rsp.attr_value.value; UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_id); UINT8_TO_STREAM(pp, p_rsp->rpt_ref.rpt_type); - BTA_GATTS_SendRsp(conn_id, trans_id, st, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, st, &rsp); //srvc_sr_rsp(p_inst->pending_clcb_idx, st, &rsp); break; @@ -607,7 +608,7 @@ void Battery_Notify (UINT16 conn_id, UINT8 app_id, BD_ADDR remote_bda, UINT8 bat if (i == BA_MAX_INT_NUM || p_inst->clt_cfg_hdl == 0) return; - BTA_GATTS_HandleValueIndication(conn_id, p_inst->ba_level_hdl, 1, &battery_level, false); + esp_ble_gatts_hdl_val_indica(conn_id, p_inst->ba_level_hdl, 1, &battery_level, false); //srvc_sr_notify(remote_bda, p_inst->ba_level_hdl, 1, &battery_level); } diff --git a/components/bt/bluedroid/profiles/std/dis/dis_profile.c b/components/bt/bluedroid/profiles/std/dis/dis_profile.c index fb00bf311..f5b076caa 100644 --- a/components/bt/bluedroid/profiles/std/dis/dis_profile.c +++ b/components/bt/bluedroid/profiles/std/dis/dis_profile.c @@ -44,10 +44,10 @@ #define STREAM_TO_UINT64(u64, p) {u64 = (((UINT64)(*(p))) + ((((UINT64)(*((p) + 1)))) << 8) + ((((UINT64)(*((p) + 2)))) << 16) + ((((UINT64)(*((p) + 3)))) << 24) \ + ((((UINT64)(*((p) + 4)))) << 32) + ((((UINT64)(*((p) + 5)))) << 40) + ((((UINT64)(*((p) + 6)))) << 48) + ((((UINT64)(*((p) + 7)))) << 56)); (p) += 8;} -tBT_UUID uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}}; -UINT16 i = 0; -tDIS_ATTR_MASK dis_mask; -static const UINT16 dis_attr_uuid[DIS_MAX_CHAR_NUM] = +esp_bt_uuid_t uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}}; +UINT16 i = 0; +tDIS_ATTR_MASK dis_mask; +static const UINT16 dis_attr_uuid[DIS_MAX_CHAR_NUM] = { GATT_UUID_SYSTEM_ID, GATT_UUID_MODEL_NUMBER_STR, @@ -106,12 +106,12 @@ BOOLEAN dis_valid_handle_range(UINT16 handle) ** ** Process write DIS attribute request. *******************************************************************************/ -UINT8 dis_write_attr_value(tGATT_WRITE_REQ * p_data, tGATT_STATUS *p_status) +UINT8 dis_write_attr_value(tGATT_WRITE_REQ * p_data, esp_gatt_status_t *p_status) { UNUSED(p_data); *p_status = GATT_WRITE_NOT_PERMIT; - return GATT_SUCCESS; + return ESP_GATT_OK; } /******************************************************************************* ** DIS Attributes Database Server Request callback @@ -127,7 +127,7 @@ void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, UINT32 tr tDIS_DB_ENTRY *p_db_attr = dis_cb.dis_attr; UINT8 *p = p_value->value, i, *pp; UINT16 offset = p_data->read_req.offset; - tGATT_STATUS st = GATT_NOT_FOUND; + tGATT_STATUS st = ESP_GATT_NOT_FOUND; UINT16 handle = p_data->read_req.handle; bool is_long = p_data->read_req.is_long; @@ -138,10 +138,10 @@ void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, UINT32 tr if ((p_db_attr->uuid == GATT_UUID_PNP_ID || p_db_attr->uuid == GATT_UUID_SYSTEM_ID)&& is_long == TRUE) { - st = GATT_NOT_LONG; + st = ESP_GATT_NOT_LONG; break; } - st = GATT_SUCCESS; + st = ESP_GATT_NOT_FOUND; switch (p_db_attr->uuid) { @@ -165,7 +165,7 @@ void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, UINT32 tr if (offset > p_value->len) { - st = GATT_INVALID_OFFSET; + st = ESP_GATT_INVALID_OFFSET; break; } else @@ -197,7 +197,7 @@ void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, UINT32 tr } tGATTS_RSP rsp; rsp.attr_value = *p_value; - BTA_GATTS_SendRsp(conn_id, trans_id, st, &rsp); + esp_ble_gatts_send_rsp(conn_id, trans_id, st, &rsp); } @@ -209,7 +209,7 @@ void dis_s_read_attr_value (tGATTS_DATA *p_data, tGATT_VALUE *p_value, UINT32 tr ** Description Initialize the Device Information Service Server. ** *******************************************************************************/ -void DIS_Init (tBTA_GATTS_IF gatt_if, tDIS_ATTR_MASK dis_attr_mask) +void DIS_Init (esp_gatts_if_t gatt_if, tDIS_ATTR_MASK dis_attr_mask) { tGATT_STATUS status; @@ -222,7 +222,7 @@ void DIS_Init (tBTA_GATTS_IF gatt_if, tDIS_ATTR_MASK dis_attr_mask) memset(&dis_cb, 0, sizeof(tDIS_CB)); - BTA_GATTS_CreateService (gatt_if , &uuid, 0, DIS_MAX_ATTR_NUM, TRUE); + esp_ble_gatts_create_srvc (gatt_if , &uuid, 0, DIS_MAX_ATTR_NUM, TRUE); } /******************************************************************************* @@ -241,14 +241,14 @@ void dis_AddChar(UINT16 service_id) while(dis_mask != 0 && i < DIS_MAX_CHAR_NUM) { uuid.uu.uuid16 = p_db_attr->uuid = dis_attr_uuid[i]; - BTA_GATTS_AddCharacteristic(dis_cb.service_handle, &uuid, GATT_PERM_READ, + esp_ble_gatts_add_char(dis_cb.service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); p_db_attr ++; i ++; dis_mask >>= 1; } /*start service*/ - BTA_GATTS_StartService(dis_cb.service_handle, GATT_TRANSPORT_LE_BR_EDR); + esp_ble_gatts_start_srvc(dis_cb.service_handle); dis_cb.enabled = TRUE; } /******************************************************************************* diff --git a/components/bt/bluedroid/profiles/std/include/dis_api.h b/components/bt/bluedroid/profiles/std/include/dis_api.h index 095a76c50..f84a7e62f 100644 --- a/components/bt/bluedroid/profiles/std/include/dis_api.h +++ b/components/bt/bluedroid/profiles/std/include/dis_api.h @@ -28,6 +28,7 @@ #include "bt_target.h" #include "gatt_api.h" #include "gattdefs.h" +#include "bt_app_api.h" #define DIS_SUCCESS GATT_SUCCESS #define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index f12b960c0..14216e121 100755 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -1620,12 +1620,12 @@ UINT8 btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p p_data->resp_keys = 0; } - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 3: auth_req:%d", p_data->auth_req); - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x", + BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 3: auth_req:%d\n", p_data->auth_req); + BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x\n", p_data->init_keys, p_data->resp_keys); - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d", + BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d\n", p_data->io_cap, p_data->auth_req); /* remove MITM protection requirement if IO cap does not allow it */ @@ -1644,7 +1644,7 @@ UINT8 btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p p_data->resp_keys &= ~SMP_SEC_KEY_TYPE_LK; } - BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:0x%02x", + BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:0x%02x\n", p_data->io_cap, p_data->oob_data, p_data->auth_req); } return callback_rc; @@ -1663,7 +1663,7 @@ UINT8 btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p UINT8 btm_ble_br_keys_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p_data) { UINT8 callback_rc = BTM_SUCCESS; - BTM_TRACE_DEBUG ("%s", __func__); + BTM_TRACE_DEBUG ("%s\n", __func__); if (btm_cb.api.p_le_callback) { /* the callback function implementation may change the IO capability... */ @@ -1705,7 +1705,7 @@ static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) handle = HCID_GET_HANDLE (handle); - BTM_TRACE_EVENT ("%s", __func__); + BTM_TRACE_EVENT ("%s\n", __func__); if (match_rec) { diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index b4d66031b..e1f81d494 100755 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -1447,7 +1447,7 @@ tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport, tBTM_SE else { rc = BTM_WRONG_MODE; - BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL", __FUNCTION__); + BTM_TRACE_WARNING("%s: cannot call btm_ble_set_encryption, p is NULL\n", __FUNCTION__); } } else From cdd65095e3ac398b5ecc0675a3b0c411189b8672 Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 2 Nov 2016 06:48:17 -0400 Subject: [PATCH 18/31] component bt:Change the wx_airsync_prf to the new API function --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 6 +- components/bt/bluedroid/bta/dm/bta_dm_api.c | 2 +- .../profiles/esp/include/wx_airsync_prf.h | 1 + .../esp/wechat_AirSync/wx_airsync_prf.c | 68 +++++++++---------- .../profiles/std/include/hid_le_prf.h | 1 + .../bluedroid/profiles/std/include/prf_defs.h | 6 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index a48f51225..76dd5ff9b 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4295,10 +4295,10 @@ void bta_dm_set_encryption (tBTA_DM_MSG *p_data) { UINT8 i ; - APPL_TRACE_DEBUG("bta_dm_set_encryption"); //todo + APPL_TRACE_DEBUG("bta_dm_set_encryption\n"); //todo if (!p_data->set_encryption.p_callback) { - APPL_TRACE_ERROR("bta_dm_set_encryption callback is not provided"); + APPL_TRACE_ERROR("bta_dm_set_encryption callback is not provided\n"); return; } for (i=0; iset_encryption.p_callback)(p_data->set_encryption.bd_addr, p_data->set_encryption.transport, BTA_BUSY); diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index e557dd5e4..bfae1011d 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -2071,7 +2071,7 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length) ** p_callback - Pointer to callback function to indicat the ** link encryption status ** sec_act - This is the security action to indicate -** what knid of BLE security level is required for +** what kind of BLE security level is required for ** the BLE link if the BLE is supported ** Note: This parameter is ignored for the BR/EDR link ** or the BLE is not supported diff --git a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h index 8323ae8b8..50fe37f18 100644 --- a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h +++ b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h @@ -19,6 +19,7 @@ #include "bt_target.h" #include "gatt_api.h" #include "gattdefs.h" +#include "bt_app_api.h" /// Maximum Transmission Unit diff --git a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c index dc1e557b9..302290fad 100644 --- a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c +++ b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c @@ -37,7 +37,7 @@ tAIRSYNC_CB_ENV airsync_cb_env; /***************************************************************************** ** Constants *****************************************************************************/ -static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); +static void airsync_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data); /******************************************************************************* @@ -49,17 +49,17 @@ static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); ** Returns NULL ** *******************************************************************************/ -static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) +static void airsync_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) { - tBTA_GATTS_RSP rsp; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; + esp_gatts_rsp_t rsp; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; tAirSync_INST *p_inst = &airsync_cb_env.airsync_inst; LOG_ERROR("airsync profile cb event = %x\n",event); switch(event) { - case BTA_GATTS_REG_EVT: + case ESP_GATTS_REG_EVT: if(p_data->reg_oper.status != BTA_GATT_OK) { @@ -73,41 +73,41 @@ static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) AirSync_CreateService(); } break; - case BTA_GATTS_READ_EVT: + case ESP_GATTS_READ_EVT: if(airsync_cb_env.clcb.connected && airsync_cb_env.enabled){ //tBTA_GATTS_RSP rsp; memset(&rsp,0,sizeof(tBTA_GATTS_API_RSP)); rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle; rsp.attr_value.len = 2; - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,&rsp); } break; - case BTA_GATTS_WRITE_EVT: + case ESP_GATTS_WRITE_EVT: if(airsync_cb_env.clcb.connected && airsync_cb_env.enabled){ - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,NULL); } break; - case BTA_GATTS_CONF_EVT: + case ESP_GATTS_CFM_EVT: break; - case BTA_GATTS_CREATE_EVT: + case ESP_GATTS_CREATE_EVT: uuid.uu.uuid16 = ATT_CHAR_AIRSYNC_WIT; airsync_cb_env.clcb.cur_srvc_id= p_data->create.service_id; airsync_cb_env.is_primery = p_data->create.is_primary; //start the airsync service after created - BTA_GATTS_StartService(p_data->create.service_id,BTA_GATT_TRANSPORT_LE); + esp_ble_gatts_start_srvc(p_data->create.service_id); //add the frist airsync characteristic --> write characteristic - BTA_GATTS_AddCharacteristic(airsync_cb_env.clcb.cur_srvc_id,&uuid, + esp_ble_gatts_add_char(airsync_cb_env.clcb.cur_srvc_id,&uuid, (GATT_PERM_WRITE|GATT_PERM_READ), (GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_WRITE)); break; - case BTA_GATTS_ADD_CHAR_EVT: + case ESP_GATTS_ADD_CHAR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_AIRSYNC_WIT) { uuid.uu.uuid16 = ATT_CHAR_AIRSYBC_NTF; @@ -116,19 +116,19 @@ static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //save the att handle to the env airsync_cb_env.airsync_inst.airsync_wirt_hdl = p_data->add_result.attr_id; //add the second airsync characteristic --> Notify characteristic - BTA_GATTS_AddCharacteristic(airsync_cb_env.clcb.cur_srvc_id,&uuid, + esp_ble_gatts_add_char(airsync_cb_env.clcb.cur_srvc_id,&uuid, GATT_PERM_READ,(GATT_CHAR_PROP_BIT_READ|GATT_CHAR_PROP_BIT_INDICATE)); }else if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_AIRSYBC_NTF){ //tBTA_GATT_PERM perm = (GATT_PERM_WRITE|GATT_PERM_WRITE); uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; airsync_cb_env.airsync_inst.airsync_ntf_hdl = p_data->add_result.attr_id; - BTA_GATTS_AddCharDescriptor (airsync_cb_env.clcb.cur_srvc_id, + esp_ble_gatts_add_char_descr (airsync_cb_env.clcb.cur_srvc_id, (GATT_PERM_WRITE|GATT_PERM_WRITE), &uuid); uuid.uu.uuid16 = ATT_CHAR_AIRSYNC_READ; //add the third airsync characteristic --> Read characteristic - BTA_GATTS_AddCharacteristic(airsync_cb_env.clcb.cur_srvc_id,&uuid, + esp_ble_gatts_add_char(airsync_cb_env.clcb.cur_srvc_id,&uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); }else if(p_data->add_result.char_uuid.uu.uuid16 == ATT_CHAR_AIRSYNC_READ){ @@ -136,32 +136,30 @@ static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) } break; - case BTA_GATTS_ADD_CHAR_DESCR_EVT: + case ESP_GATTS_ADD_CHAR_DESCR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) { airsync_cb_env.airsync_inst.airsync_cfg_hdl = p_data->add_result.attr_id; } break; - case BTA_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: //set the connection flag to true airsync_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda); break; - case BTA_GATTS_DISCONNECT_EVT: + case ESP_GATTS_DISCONNECT_EVT: //set the connection flag to true airsync_cb_env.clcb.connected = false; break; - case BTA_GATTS_OPEN_EVT: + case ESP_GATTS_OPEN_EVT: break; - case BTA_GATTS_CLOSE_EVT: + case ESP_GATTS_CLOSE_EVT: if(airsync_cb_env.clcb.connected && (airsync_cb_env.clcb.conn_id == p_data->conn.conn_id)) { //set the connection channal congested flag to true airsync_cb_env.clcb.congest = p_data->congest.congested; } break; - case BTA_GATTS_LISTEN_EVT: - break; - case BTA_GATTS_CONGEST_EVT: + case ESP_GATTS_CONGEST_EVT: //set the congest flag airsync_cb_env.clcb.congest = p_data->congest.congested; break; @@ -182,14 +180,14 @@ static void airsync_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) *******************************************************************************/ void AirSync_CreateService(void) { - tBTA_GATTS_IF server_if ; - tBT_UUID uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; + esp_gatts_if_t server_if ; + esp_bt_uuid_t uuid = {LEN_UUID_16, {ATT_SVC_AIRSYNC}}; UINT16 num_handle = WX_IDX_NB; UINT8 inst = 0x00; server_if = airsync_cb_env.gatt_if; airsync_cb_env.inst_id = inst; - BTA_GATTS_CreateService(server_if,&uuid,inst,num_handle,true); + esp_ble_gatts_create_srvc(server_if,&uuid,inst,num_handle,true); } @@ -254,13 +252,13 @@ UINT16 airsync_env_find_conn_id_by_bd_adddr(BD_ADDR remote_bda) *******************************************************************************/ tGATT_STATUS AirSync_Init(tAIRSYNC_CBACK *call_back) { - tBT_UUID app_uuid = {LEN_UUID_16,{ATT_SVC_AIRSYNC}}; + esp_bt_uuid_t app_uuid = {LEN_UUID_16,{ATT_SVC_AIRSYNC}}; if(airsync_cb_env.enabled) { LOG_ERROR("airsync svc already initaliezd\n"); - return GATT_ERROR; + return ESP_GATT_ERROR; } else { @@ -269,17 +267,17 @@ tGATT_STATUS AirSync_Init(tAIRSYNC_CBACK *call_back) if(call_back != NULL) - { - airsync_cb_env.airsync_inst.p_cback = call_back; - } + { + airsync_cb_env.airsync_inst.p_cback = call_back; + } /* register the airsync profile to the BTA_GATTS module*/ - BTA_GATTS_AppRegister(&app_uuid,airsync_profile_cb); + esp_ble_gatts_app_register(&app_uuid,airsync_profile_cb); airsync_cb_env.enabled = TRUE; - return GATT_SUCCESS; + return ESP_GATT_OK; } #endif ///WX_AIRSYNC_CFG diff --git a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h index 753a2f66e..3c17edbbf 100644 --- a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h +++ b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h @@ -19,6 +19,7 @@ #include "bt_types.h" #include "bta_api.h" #include "gatt_api.h" +#include "bt_app_api.h" /// Maximal number of HIDS that can be added in the DB #ifndef USE_ONE_HIDS_INSTANCE diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 6fb53d73b..b84eae2ab 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -27,9 +27,9 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 1 -#define HIDD_LE_PROFILE_CFG 0 +#define WX_AIRSYNC_CFG TRUE +#define BUT_PROFILE_CFG TRUE +#define HIDD_LE_PROFILE_CFG TRUE /* * Type Definition From 57f8128718d706431b385381951fdea69b13eba7 Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 2 Nov 2016 07:04:11 -0400 Subject: [PATCH 19/31] component bt:Change the battery client profile to the new API --- .../app_client_profiles/battery_c/battery_c.c | 37 ++++++++++--------- .../bluedroid_demos/include/bt_app_defs.h | 1 + 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c index afb3905a6..409fa828c 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c @@ -17,14 +17,15 @@ #include "btm_api.h" #include "bt_types.h" #include "gattc_profile.h" +#include "bt_app_api.h" #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] -tBTA_GATTC_IF client_if; +esp_gattc_if_t client_if; -tBT_UUID bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}}; +esp_bt_uuid_t bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}}; -uint16_t get_uuid16(tBT_UUID* p_uuid) +uint16_t get_uuid16(esp_bt_uuid_t* p_uuid) { if(p_uuid->len == LEN_UUID_16) { @@ -52,17 +53,17 @@ void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_outp } /*fill a service ID structure with a 16 bits service UUID*/ -void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, tBTA_GATT_SRVC_ID* p_output) +void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, esp_gatt_srvc_id_t* p_output) { - memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID)); + memset((void *)p_output, 0, sizeof(esp_gatt_srvc_id_t)); p_output->is_primary = is_pri; bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id); } /*fill a char ID structure with a 16 bits char UUID*/ -void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p_output) +void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, esp_gatt_id_t* p_output) { - memset((void *)p_output, 0, sizeof(tBTA_GATT_ID)); + memset((void *)p_output, 0, sizeof(esp_gatt_id_t)); bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output); } @@ -71,13 +72,13 @@ void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p ** ** Description battery service register callback function *******************************************************************************/ -static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) +static void bas_gattc_callback(esp_gattc_evt_t event, esp_gattc_t* p_data) { switch (event) { - case BTA_GATTC_REG_EVT: + case ESP_GATTC_REG_EVT: { - tBTA_GATT_STATUS status = p_data->reg_oper.status; + esp_gatt_status_t status = p_data->reg_oper.status; client_if = p_data->reg_oper.client_if; LOG_ERROR("BAS register completed: event=%d, status=%d, client_if=%d\n", event, status, client_if); @@ -86,7 +87,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) break; /*connect callback*/ - case BTA_GATTC_OPEN_EVT: + case ESP_GATTC_OPEN_EVT: { LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n", @@ -101,12 +102,12 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) int conn_id = p_data->open.conn_id; /*discover service*/ - BTA_GATTC_ServiceSearchRequest(conn_id, NULL); + esp_ble_gattc_svc_search_req(conn_id, NULL); } break; - case BTA_GATTC_SEARCH_RES_EVT: + case ESP_GATTC_SEARCH_RES_EVT: { // tBTA_GATTC_SRVC_RES service_result; LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n", @@ -115,7 +116,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) } break; - case BTA_GATTC_SEARCH_CMPL_EVT: + case ESP_GATTC_SEARCH_CMPL_EVT: { LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id, p_data->search_cmpl.status); @@ -127,7 +128,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) tBTA_GATTC_CHAR_ID out_char_id; tGATT_CHAR_PROP out_char_prop; bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id); - status = BTA_GATTC_GetFirstChar(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL, + status = esp_ble_gattc_get_first_char(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL, &out_char_id, &out_char_prop); if(status == 0) { @@ -139,13 +140,13 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id); bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id); - BTA_GATTC_ReadCharacteristic(p_data->search_cmpl.conn_id, &battery_char_id, + esp_ble_gattc_read_char(p_data->search_cmpl.conn_id, &battery_char_id, BTA_GATT_AUTH_REQ_NONE); } } break; - case BTA_GATTC_READ_CHAR_EVT: + case ESP_GATTC_READ_CHAR_EVT: { LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n", @@ -179,7 +180,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) ****************************************************************/ void bac_register(void) { - BTA_GATTC_AppRegister(&bas_uuid, bas_gattc_callback); + esp_ble_gattc_app_register(&bas_uuid, bas_gattc_callback); } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index 265c014ad..91ecdcaf1 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -25,6 +25,7 @@ typedef tBTA_GATT_STATUS esp_gatt_status_t; typedef UINT16 gatt_size_t; typedef tBT_UUID esp_bt_uuid_t; +typedef tBTA_GATT_ID esp_gatt_id_t; typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t; typedef tGATT_IF esp_gatt_if_t; From c377650cddf92f104434d1e02d4c2018d39baa12 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 3 Nov 2016 04:27:44 -0400 Subject: [PATCH 20/31] component bt:Added the profile task to the bt project --- .../bluedroid/profiles/core/bt_prf_sys_main.c | 2 +- .../bt/bluedroid/profiles/core/bt_prf_task.c | 6 ++-- .../profiles/core/include/bt_prf_sys.h | 15 ++++---- .../profiles/esp/ble_button/button_pro.c | 1 - .../bluedroid/profiles/std/include/prf_defs.h | 10 ++++++ .../bluedroid_demos/app_core/bt_app_api.c | 35 +++++++++++++++++++ .../bluedroid_demos/app_core/bt_app_core.c | 10 +++--- .../app_sample_button/app_button.c | 6 ++-- .../bluedroid_demos/include/app_button_int.h | 2 +- .../bluedroid_demos/include/bt_app_api.h | 22 ++++++++++-- 10 files changed, 86 insertions(+), 23 deletions(-) diff --git a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c index 48b2825eb..cce2f14ed 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c @@ -48,7 +48,7 @@ void bt_prf_sys_init(void) ** Returns void ** *******************************************************************************/ -void bt_prf_sys_event(BT_HDR *p_msg) +void bt_prf_sys_event(prf_hdr_evt_t *p_msg) { UINT8 id; BOOLEAN freebuf = TRUE; diff --git a/components/bt/bluedroid/profiles/core/bt_prf_task.c b/components/bt/bluedroid/profiles/core/bt_prf_task.c index 035c8d4eb..a611ccb0b 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_task.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_task.c @@ -38,7 +38,7 @@ //ke_event_clear(KE_EVENT_BTU_TASK_THREAD); TaskEvt_t *e; - for (;;) { + for (;;) { if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) { if (e->sig == SIG_BTU_WORK) { @@ -68,10 +68,10 @@ } void bt_profile_msg_ready(fixed_queue_t *queue) { - BT_HDR *p_msg; + prf_hdr_evt_t *p_msg; while (!fixed_queue_is_empty(queue)) { - p_msg = (BT_HDR *)fixed_queue_dequeue(queue); + p_msg = (prf_hdr_evt_t *)fixed_queue_dequeue(queue); if(p_msg != NULL) { bt_prf_sys_event(p_msg); diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h index 9043e8e82..a28eb4ebf 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h @@ -16,6 +16,7 @@ #define _PROFILE_SYS_H__ #include "bt_types.h" +#include "prf_defs.h" enum { @@ -38,7 +39,7 @@ typedef UINT8 tBT_PRF_SYS_CONN_STATUS; /* disable function type */ typedef void (tBT_PRF_SYS_DISABLE)(void); /* event handler function type */ -typedef BOOLEAN (tBT_PRF_SYS_EVT_HDLR)(BT_HDR *p_msg); +typedef BOOLEAN (tBT_PRF_SYS_EVT_HDLR)(prf_hdr_evt_t *p_msg); /* conn callback for role / low power manager*/ typedef void (tBT_PRF_SYS_CONN_CBACK)(tBT_PRF_SYS_CONN_STATUS status, @@ -73,14 +74,14 @@ extern tBT_PRF_SYS_CB bt_prf_sys_cb; extern void bt_prf_sys_init(void); extern void bt_prf_sys_free(void); -extern void bt_prf_sys_event(BT_HDR *p_msg); +extern void bt_prf_sys_event(prf_hdr_evt_t *p_msg); -extern void bt_prf_sys_register(UINT8 id, const tBT_PRF_SYS_REG *p_reg); -extern void bt_prf_sys_deregister(UINT8 id); -extern BOOLEAN bt_prf_sys_is_register(UINT8 id); +extern void bt_prf_sys_register(uint8_t id, const tBT_PRF_SYS_REG *p_reg); +extern void bt_prf_sys_deregister(uint8_t id); +extern BOOLEAN bt_prf_sys_is_register(uint8_t id); -extern void bt_prf_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); -extern void bt_prf_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr); +extern void bt_prf_sys_idle(uint8_t id, uint8_t app_id, BD_ADDR peer_addr); +extern void bt_prf_sys_busy(uint8_t id, uint8_t app_id, BD_ADDR peer_addr); #endif ///_PROFILE_SYS_H__ diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index a19856d17..df878c9e4 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -26,7 +26,6 @@ #include "bta_api.h" #include "bta_gatt_api.h" #include "bta_gatts_int.h" -#include "bt_app_api.h" #include "button_pro.h" #include "prf_defs.h" diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index b84eae2ab..34012a2fb 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -36,6 +36,16 @@ **************************************************************************************** */ +/* Define the header of each buffer used in the profile stack. +*/ +typedef struct +{ + uint16_t event; + uint16_t len; + uint8_t data[]; +} prf_hdr_evt_t; + + /// Characteristic Value Descriptor typedef struct { diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 52fb3014d..93914fe7e 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -1194,6 +1194,41 @@ void esp_ble_gatts_close(uint16_t conn_id) } +/******************************************************************************* +** +** @function esp_prf_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] p_app_uuid - applicaiton UUID +** @param[in] p_cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_prf_app_register(uint8_t prf_id, void *p_cback) +{ + //tBTA_GATTS_API_REG *p_buf; + + /* register with BTA system manager */ + if (bt_prf_sys_is_register(PRF_ID_SYS) == FALSE) + { + bt_prf_sys_register(PRF_ID_SYS, NULL); + } + +// if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) +// { +// p_buf->hdr.event = BTA_GATTS_API_REG_EVT; + +// if (p_app_uuid != NULL) +// memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); +// p_buf->p_cback = p_cback; + +// bta_sys_sendmsg(p_buf); +// } + return; +} diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index 84a244943..8ac03bed3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -68,13 +68,13 @@ static void bt_app_task_handler(void *arg) fixed_queue_process(bt_app_general_alarm_queue); } #if (BUT_PROFILE_CFG) - else if(e->sig == BUTTON_PRESS_EVT){ - LOG_ERROR("button_press_event come in,button_value=%x\n",e->par); - button_msg[1] = e->par; - button_msg_notify(2,button_msg); + // else if(e->sig == BUTTON_PRESS_EVT){ + // LOG_ERROR("button_press_event come in,button_value=%x\n",e->par); + // button_msg[1] = e->par; + // button_msg_notify(2,button_msg); - } + //} #endif ///BUT_PROFILE_CFG } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index c224e7031..bcd4d00ac 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -41,7 +41,7 @@ #include "button_pro.h" #include "app_button_int.h" -static const tBTA_SYS_REG bta_gatts_reg = +static const tBT_PRF_SYS_REG bta_gatts_reg = { ble_but_prf_hdl_event, ble_but_prf_disable @@ -59,7 +59,7 @@ static const tBTA_SYS_REG bta_gatts_reg = ** Returns BOOLEAN ** *******************************************************************************/ -BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data) +BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data) { UINT16 connid = 0; switch(msg_data->event) @@ -112,7 +112,7 @@ void ble_but_prf_disable(void) if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) { - p_buf->event = BTA_GATTS_API_DISABLE_EVT; + p_buf->event = BLE_BUT_DISABLE_IND_EVT; bta_sys_sendmsg(p_buf); } bta_sys_deregister(PRF_ID_BUT_LE); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h index bfd7c4708..b64a1ee32 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -119,7 +119,7 @@ typedef union -BOOLEAN ble_but_prf_hdl_event(BT_HDR *msg_data); +BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data); void ble_but_prf_disable(void); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index dd68b98c7..2abce8791 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -15,7 +15,7 @@ #include "bt_types.h" #include "bt_app_defs.h" #include "bta_gatt_api.h" - +#include "bt_prf_sys.h" /******************************************************************************* @@ -895,7 +895,7 @@ void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BO ** ** @function esp_ble_gatts_close ** -** @param[in] Close a connection a remote device. +** @brief Close a connection a remote device. ** ** @param[in] conn_id: connectino ID to be closed. ** @@ -904,3 +904,21 @@ void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BO *******************************************************************************/ void esp_ble_gatts_close(uint16_t conn_id); + +/******************************************************************************* +** +** @function esp_prf_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] prf_id - the profile identification +** @param[in] p_cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_prf_app_register(uint8_t prf_id, void *p_cback); + + + From 1540469598220fe5923b21e54ee7de4a0fc7622e Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Thu, 3 Nov 2016 16:28:04 +0800 Subject: [PATCH 21/31] component/esp32 component/bt : seperate phy init --- components/bt/component.mk | 2 +- components/bt/lib | 2 +- components/esp32/component.mk | 2 +- components/esp32/lib | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/bt/component.mk b/components/bt/component.mk index 1926f857d..5bb01a813 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -33,7 +33,7 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \ CFLAGS += -Wno-error=unused-label -Wno-error=return-type -Wno-error=missing-braces -Wno-error=pointer-sign -Wno-error=parentheses -LIBS := btdm_app +LIBS := btdm_app coexist COMPONENT_ADD_LDFLAGS := -lbt -L$(abspath lib) \ $(addprefix -l,$(LIBS)) \ diff --git a/components/bt/lib b/components/bt/lib index 116bca549..0f11ccac9 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit 116bca54958c21b8b5b5f79a427744131e21f12a +Subproject commit 0f11ccac9a5f39e28e5d8904634c54acd4f140fd diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 788f88012..249d533fa 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -10,7 +10,7 @@ COMPONENT_SRCDIRS := . hwcrypto -LIBS := crypto core net80211 phy rtc pp wpa smartconfig +LIBS := crypto core net80211 phy rtc pp wpa smartconfig coexist LINKER_SCRIPTS += -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld diff --git a/components/esp32/lib b/components/esp32/lib index 01d2e6e22..2afb6bb13 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 01d2e6e22e439edcdc289991b667d13a0908128d +Subproject commit 2afb6bb13ec50bf46128331fa7b6835d672c0414 From 90d9f1a74e7c78ca4ab5b83867e05f24313d75cb Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 4 Nov 2016 02:34:52 -0400 Subject: [PATCH 22/31] component bt:debug the profile task can work --- .../bluedroid/profiles/core/bt_prf_sys_main.c | 13 +++-- .../bt/bluedroid/profiles/core/bt_prf_task.c | 16 ++++--- .../profiles/core/include/bt_prf_sys.h | 3 ++ .../profiles/core/include/bt_prf_task.h | 2 +- .../profiles/esp/ble_button/button_pro.c | 11 +++-- .../bluedroid/profiles/std/include/prf_defs.h | 4 +- .../bluedroid_demos/app_core/bt_app_api.c | 48 +++++++++---------- .../app_sample_button/app_button.c | 33 +++++++++++-- .../app_project/SampleServerProject.c | 12 +++-- .../bluedroid_demos/include/app_button.h | 3 ++ .../bluedroid_demos/include/bt_app_api.h | 16 +++---- 11 files changed, 102 insertions(+), 59 deletions(-) diff --git a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c index cce2f14ed..f61d316d4 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c @@ -17,6 +17,7 @@ #include "fixed_queue.h" #include "bt_prf_task.h" #include "gki.h" +#include "bt_trace.h" #include @@ -34,7 +35,9 @@ static const tBT_PRF_SYS_REG bt_prf_sys_reg = void bt_prf_sys_init(void) { - memset(&bt_prf_sys_cb,0,sizeof(tBT_PRF_SYS_CB)); + LOG_ERROR("bt_prf_sys_init\n"); + memset(&bt_prf_sys_cb, 0, sizeof(tBT_PRF_SYS_CB)); + bt_prf_StartUp(); } @@ -53,7 +56,7 @@ void bt_prf_sys_event(prf_hdr_evt_t *p_msg) UINT8 id; BOOLEAN freebuf = TRUE; - APPL_TRACE_EVENT("profile task got event 0x%x\n", p_msg->event); + LOG_ERROR("profile task got event 0x%x\n", p_msg->event); /* get subsystem id from event */ id = (UINT8) (p_msg->event >> 8); @@ -65,7 +68,7 @@ void bt_prf_sys_event(prf_hdr_evt_t *p_msg) } else { - APPL_TRACE_WARNING("profile task got unregistered event id %d\n", id); + LOG_ERROR("profile task got unregistered event id %d\n", id); } if (freebuf) @@ -131,7 +134,7 @@ BOOLEAN bt_prf_sys_is_register(UINT8 id) ** ** Function bt_prf_sys_sendmsg ** -** Description Send a GKI message to the profile task. +** Description Send a message to the profile task. ** ** ** Returns void @@ -141,7 +144,7 @@ void bt_prf_sys_sendmsg(void *p_msg) { // There is a race condition that occurs if the stack is shut down while // there is a procedure in progress that can schedule a task via this - // message queue. This causes |btu_bta_msg_queue| to get cleaned up before + // message queue. This causes |bt_profile_msg_queue| to get cleaned up before // it gets used here; hence we check for NULL before using it. if (bt_profile_msg_queue) { fixed_queue_enqueue(bt_profile_msg_queue, p_msg); diff --git a/components/bt/bluedroid/profiles/core/bt_prf_task.c b/components/bt/bluedroid/profiles/core/bt_prf_task.c index a611ccb0b..a503a4fcc 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_task.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_task.c @@ -15,6 +15,7 @@ #include "bt_prf_task.h" #include "bt_prf_sys.h" #include "allocator.h" +#include "bt_trace.h" #include "thread.h" #include "gki.h" @@ -35,17 +36,16 @@ ******************************************************************************/ void bt_prf_task_thread_handler(void *arg) { - //ke_event_clear(KE_EVENT_BTU_TASK_THREAD); TaskEvt_t *e; for (;;) { if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == SIG_BTU_WORK) { + if (e->sig == SIG_PRF_WORK) { fixed_queue_process(bt_profile_msg_queue); - + LOG_ERROR("bt_prf_task_thread_handler\n"); } - else if (e->sig == SIG_BTU_START_UP) { + else if (e->sig == SIG_PRF_START_UP) { bt_prf_task_start_up(); } osi_free(e); @@ -82,6 +82,7 @@ void bt_profile_msg_ready(fixed_queue_t *queue) { void bt_prf_task_start_up(void) { + LOG_ERROR("bt_prf_task_start_up\n"); fixed_queue_register_dequeue(bt_profile_msg_queue, bt_profile_msg_ready); } @@ -98,10 +99,13 @@ void bt_prf_StartUp(void) bt_profile_msg_queue = fixed_queue_new(SIZE_MAX); if (bt_profile_msg_queue == NULL) goto error_exit; - + + xProfileQueue = xQueueCreate(60, sizeof(void *)); + xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle); + bt_prf_task_post(SIG_PRF_START_UP); return; -error_exit:; +error_exit: LOG_ERROR("%s Unable to allocate resources for bt_workqueue\n", __func__); bt_prf_ShutDown(); diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h index a28eb4ebf..700537de3 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h @@ -76,6 +76,9 @@ extern void bt_prf_sys_init(void); extern void bt_prf_sys_free(void); extern void bt_prf_sys_event(prf_hdr_evt_t *p_msg); +extern void bt_prf_sys_sendmsg(void *p_msg); + + extern void bt_prf_sys_register(uint8_t id, const tBT_PRF_SYS_REG *p_reg); extern void bt_prf_sys_deregister(uint8_t id); extern BOOLEAN bt_prf_sys_is_register(uint8_t id); diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_task.h b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h index 407798769..34398983d 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_task.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h @@ -19,7 +19,7 @@ #ifndef BT_PRF_TASK_H__ #define BT_PRF_TASK_H__ -/* Functions provided by btu_core.c +/* Functions provided by bt_prf_task.c ************************************ */ diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index df878c9e4..2fffa816a 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -188,8 +188,9 @@ static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) button_cb_env.button_inst.but_cfg_hdl = p_data->add_result.attr_id; } ///Start advertising - LOG_ERROR("\nStart sent the ADV.\n"); - esp_ble_start_advertising (&adv_params); + LOG_ERROR("\n*******Start sent the ADV.*************\n"); + //esp_ble_start_advertising (&adv_params); + BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL); break; case ESP_GATTS_CONNECT_EVT: //set the connection flag to true @@ -332,11 +333,11 @@ esp_gatt_status_t button_init (but_prf_cb_t call_back) { tBT_UUID app_uuid = {LEN_UUID_16,{ATT_SVC_BUTTON}}; - + LOG_ERROR("\n=============================button_init==============================================\n"); if(button_cb_env.enabled) { - LOG_ERROR("button svc already initaliezd"); - return GATT_ERROR; + LOG_ERROR("button svc already initaliezd\n"); + return ESP_GATT_ERROR; } else { diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 34012a2fb..dab333aad 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -27,9 +27,9 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG TRUE +#define WX_AIRSYNC_CFG FALSE #define BUT_PROFILE_CFG TRUE -#define HIDD_LE_PROFILE_CFG TRUE +#define HIDD_LE_PROFILE_CFG FALSE /* * Type Definition diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 93914fe7e..a8588bbb3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -44,7 +44,7 @@ void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, if(++adv_data != NULL) { - ble_set_scan_rsp(adv_data,NULL); + ble_set_scan_rsp(adv_data, NULL); } } @@ -414,11 +414,11 @@ void esp_ble_gattc_close (uint16_t conn_id) ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid ** *******************************************************************************/ -tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) +esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) { if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ LOG_ERROR("Invalid MTU parameters\n"); - return GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } BTA_GATTC_ConfigureMTU (conn_id, mtu); @@ -468,15 +468,15 @@ void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid) ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. ** *****************************************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, +esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *char_uuid_cond, esp_gattc_char_id_t *char_result, esp_gatt_char_prop_t *property) { - tBTA_GATT_STATUS status = 0; + esp_gatt_status_t status = 0; if (!srvc_id || !char_result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetFirstChar (conn_id, srvc_id, char_uuid_cond, @@ -507,14 +507,14 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_ ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, +esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, esp_bt_uuid_t *descr_uuid_cond, esp_gattc_char_descr_id_t *descr_result) { - tBTA_GATT_STATUS status; + esp_gatt_status_t status; if (!char_id || !descr_result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetFirstCharDescr (conn_id, char_id, descr_uuid_cond, descr_result); @@ -546,17 +546,17 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gatt ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, esp_gattc_char_id_t *start_char_id, esp_bt_uuid_t *char_uuid_cond, esp_gattc_char_id_t *char_result, esp_gatt_char_prop_t *property) { - tBTA_GATT_STATUS status; + esp_gatt_status_t status; if (!start_char_id || !char_result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetNextChar(conn_id, start_char_id, char_uuid_cond, @@ -588,15 +588,15 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, esp_gattc_char_descr_id_t *start_descr_id, esp_bt_uuid_t *descr_uuid_cond, esp_gattc_char_descr_id_t *descr_result) { - tBTA_GATT_STATUS status; + esp_gatt_status_t status; if (!start_descr_id || !descr_result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetNextCharDescr (conn_id, start_descr_id, descr_uuid_cond, descr_result); @@ -625,14 +625,14 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, +esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) { - tBTA_GATT_STATUS status; + esp_gatt_status_t status; if (!srvc_id || !result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetFirstIncludedService(conn_id, srvc_id, uuid_cond, result); @@ -661,15 +661,15 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, esp_gattc_incl_srvc_id_t *start_id, esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) { - tBTA_GATT_STATUS status; + esp_gatt_status_t status; if (!start_id || !result){ - return BTA_GATT_ILLEGAL_PARAMETER; + return ESP_GATT_ILLEGAL_PARAMETER; } status = BTA_GATTC_GetNextIncludedService(conn_id, start_id, uuid_cond, result); @@ -860,11 +860,11 @@ void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) ** @return OK if registration succeed, otherwise failed. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, +esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, BD_ADDR bda, esp_gattc_char_id_t *char_id) { - tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; + esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; status = BTA_GATTC_RegisterForNotifications (client_if, bda, char_id); return status; @@ -888,7 +888,7 @@ tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, BD_ADDR bda, esp_gattc_char_id_t *char_id) { - tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; + esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; status = BTA_GATTC_DeregisterForNotifications (client_if, bda, char_id); return status; diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index bcd4d00ac..df280cf4f 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -41,7 +41,7 @@ #include "button_pro.h" #include "app_button_int.h" -static const tBT_PRF_SYS_REG bta_gatts_reg = +static const tBT_PRF_SYS_REG but_prf_reg = { ble_but_prf_hdl_event, ble_but_prf_disable @@ -61,6 +61,8 @@ static const tBT_PRF_SYS_REG bta_gatts_reg = *******************************************************************************/ BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data) { + LOG_ERROR("###################ble_but_prf_hdl_event#####################################\n"); + UINT16 connid = 0; switch(msg_data->event) { @@ -102,15 +104,16 @@ BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data) *******************************************************************************/ void ble_but_prf_disable(void) { - BT_HDR *p_buf; - + prf_hdr_evt_t *p_buf; + LOG_ERROR("ble_but_prf_disable\n"); + if (bt_prf_sys_is_register(PRF_ID_BUT_LE) == FALSE) { - APPL_TRACE_WARNING("button profile Module not enabled/already disabled"); + APPL_TRACE_WARNING("button profile Module not enabled/already disabled\n"); return; } - if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) + if ((p_buf = (prf_hdr_evt_t *) GKI_getbuf(sizeof(prf_hdr_evt_t))) != NULL) { p_buf->event = BLE_BUT_DISABLE_IND_EVT; bta_sys_sendmsg(p_buf); @@ -119,6 +122,26 @@ void ble_but_prf_disable(void) } +void ble_but_prf_enable(void) +{ + bt_prf_sys_register(PRF_ID_BUT_LE,&but_prf_reg); +} + +void ble_but_create_svc(void) +{ + prf_hdr_evt_t *p_msg; + + LOG_ERROR("ble_but_create_svc\n"); //todo + if ((p_msg = (prf_hdr_evt_t *) GKI_getbuf(sizeof(prf_hdr_evt_t))) != NULL) + { + memset(p_msg, 0, sizeof(prf_hdr_evt_t)); + + p_msg->event = BLE_BUT_ENABLE_REQ_EVT; + + bt_prf_sys_sendmsg(p_msg); + } +} + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index 2e0b742a3..a757da20c 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -30,7 +30,7 @@ #include "wx_airsync_prf.h" #include "button_pro.h" - +#include "app_button.h" #include "hid_le_prf.h" #include "bt_app_api.h" @@ -231,6 +231,8 @@ void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) break; } } + + /*set advertising config callback*/ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) { @@ -242,13 +244,14 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT; DIS_SrInit(dis_attr_mask); */ + ble_but_create_svc(); /*instantiate a battery service*/ - bas_register(); + //bas_register(); /*instantiate the driver for button profile*/ //app_button_init(); #if (BUT_PROFILE_CFG) /*instantiate a button service*/ - button_init(SimpleDataCallBack); + //button_init(SimpleDataCallBack); #endif ///BUT_PROFILE_CFG #if (HIDD_LE_PROFILE_CFG) @@ -331,6 +334,9 @@ static void ble_server_appRegister(void) LOG_ERROR("register gatts application\n"); esp_ble_gatts_app_register(&t_uuid, bta_gatts_callback); + + bt_prf_sys_init(); + ble_but_prf_enable(); } void gatts_server_test(void) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h index cde5c9efe..ea77c4476 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h @@ -57,6 +57,9 @@ extern app_key_env key_press; uint8_t check_sum(uint8_t *check_array,uint8_t len); + void ble_but_prf_enable(void); + + void ble_but_create_svc(void); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index 2abce8791..dfc2335b4 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -274,7 +274,7 @@ void esp_ble_gattc_close (uint16_t conn_id); ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid ** *******************************************************************************/ -tGATT_STATUS esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu); +esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu); /******************************************************************************* @@ -316,7 +316,7 @@ void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid); ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. ** *****************************************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, +esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *char_uuid_cond, esp_gattc_char_id_t *char_result, esp_gatt_char_prop_t *property); @@ -341,7 +341,7 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_ ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, +esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, esp_bt_uuid_t *descr_uuid_cond, esp_gattc_char_descr_id_t *descr_result); @@ -366,7 +366,7 @@ tBTA_GATT_STATUS esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gatt ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, esp_gattc_incl_srvc_id_t *start_id, esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result); @@ -393,7 +393,7 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, esp_gattc_char_id_t *start_char_id, esp_bt_uuid_t *char_uuid_cond, esp_gattc_char_id_t *char_result, @@ -420,7 +420,7 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char (uint16_t conn_id, ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, +esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, esp_gattc_char_descr_id_t *start_descr_id, esp_bt_uuid_t *descr_uuid_cond, esp_gattc_char_descr_id_t *descr_result); @@ -445,7 +445,7 @@ tBTA_GATT_STATUS esp_ble_gattc_get_next_char_descr (uint16_t conn_id, ** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. ** *******************************************************************************/ -extern tBTA_GATT_STATUS esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, +esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result); @@ -615,7 +615,7 @@ void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) ** @return OK if registration succeed, otherwise failed. ** *******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, +esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, BD_ADDR bda, esp_gattc_char_id_t *char_id); From 1544965b21ae9802b6ebfea46378c4ce307b933a Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 4 Nov 2016 04:52:23 -0400 Subject: [PATCH 23/31] componet bt:debug the advertising issues,it can works in this version --- components/bt/bluedroid/include/bt_target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/bluedroid/include/bt_target.h b/components/bt/bluedroid/include/bt_target.h index 5c402cee8..bb9d59860 100755 --- a/components/bt/bluedroid/include/bt_target.h +++ b/components/bt/bluedroid/include/bt_target.h @@ -795,7 +795,7 @@ * resolution, local address rotation etc. */ #ifndef BLE_PRIVACY_SPT -#define BLE_PRIVACY_SPT FALSE +#define BLE_PRIVACY_SPT TRUE #endif /* From b83b0ed06a9be85161c918249a9ac2c9832d8d78 Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 4 Nov 2016 05:36:32 -0400 Subject: [PATCH 24/31] commpnent bt:Added the stop advertising to the bt project --- .../profiles/esp/ble_button/button_pro.c | 21 +++--------- .../bluedroid_demos/app_core/bt_app_api.c | 2 +- .../app_project/SampleServerProject.c | 32 ++++++++++++++++--- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 2fffa816a..e539db659 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -37,21 +37,6 @@ button_env_cb_t button_cb_env; -tBLE_BD_ADDR p_peer_bda = { - .type = API_PUBLIC_ADDR, - .bda = {0} -}; - -esp_ble_adv_params_all_t adv_params = -{ - .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, - .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, - .adv_type = API_NON_DISCOVERABLE, - .addr_type_own = API_PUBLIC_ADDR, - .channel_map = ESP_BLE_ADV_CHNL_MAP, - .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY, - .p_dir_bda = &p_peer_bda -}; @@ -190,9 +175,11 @@ static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) ///Start advertising LOG_ERROR("\n*******Start sent the ADV.*************\n"); //esp_ble_start_advertising (&adv_params); - BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL); + //BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL); break; case ESP_GATTS_CONNECT_EVT: + LOG_ERROR("############BUTTON CONNCET EVT################\n"); + //esp_ble_stop_advertising(); //set the connection flag to true button_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda); break; @@ -202,7 +189,7 @@ static void button_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) break; case ESP_GATTS_OPEN_EVT: ///stop the advertising after connected - esp_ble_stop_advertising(); + break; case ESP_GATTS_CLOSE_EVT: if(button_cb_env.clcb.connected && (button_cb_env.clcb.conn_id == p_data->conn.conn_id)) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index a8588bbb3..fe309254e 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -169,7 +169,7 @@ void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) *******************************************************************************/ void esp_ble_stop_advertising (void) { - bool stop_adv = true; + bool stop_adv = false; BTA_DmBleBroadcast(stop_adv); } diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index a757da20c..85eb90a2a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -81,6 +81,24 @@ tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufactur tBTA_BLE_MANU p_wechat_manu = {sizeof(wechat_manu),wechat_manu}; +tBLE_BD_ADDR p_peer_bda = { + .type = API_PUBLIC_ADDR, + .bda = {0} +}; + +esp_ble_adv_params_all_t adv_params = +{ + .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_type = API_NON_DISCOVERABLE, + .addr_type_own = API_PUBLIC_ADDR, + .channel_map = ESP_BLE_ADV_CHNL_MAP, + .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY, + .p_dir_bda = &p_peer_bda +}; + + + BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55}; @@ -244,9 +262,9 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT; DIS_SrInit(dis_attr_mask); */ - ble_but_create_svc(); + //ble_but_create_svc(); /*instantiate a battery service*/ - //bas_register(); + bas_register(); /*instantiate the driver for button profile*/ //app_button_init(); #if (BUT_PROFILE_CFG) @@ -262,7 +280,7 @@ static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) #if (WX_AIRSYNC_CFG) AirSync_Init(NULL); #endif ///WX_AIRSYNC_CFG - + esp_ble_start_advertising(&adv_params); //API_Ble_AppStartAdvertising(&adv_params); /*start advetising*/ // BTA_GATTS_Listen(server_if, true, NULL); @@ -290,6 +308,8 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) /*connect callback*/ case BTA_GATTS_CONNECT_EVT: { + ///Stop the advertising when the connection is establish + esp_ble_stop_advertising(); LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n", BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if, p_data->conn.reason, p_data->conn.conn_id); @@ -298,7 +318,11 @@ void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) LOG_ERROR("is_connected=%d\n",is_connected); } break; - + + case BTA_GATTS_DISCONNECT_EVT: + ///start the advertising again when lose the connection + esp_ble_start_advertising(&adv_params); + break; default: LOG_ERROR("unsettled event: %d\n", event); } From 4ea38327b6f2c081bbb95df3e6fcbaaa860670ae Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Fri, 4 Nov 2016 17:50:40 +0800 Subject: [PATCH 25/31] component:bt delete old demo trash --- .../app_project/SampleClientProject.c | 377 ------------------ .../app_project/SampleServerProject.c | 295 -------------- .../bluedroid_demos/include/bt_app_common.h | 31 -- 3 files changed, 703 deletions(-) delete mode 100644 examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c delete mode 100644 examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c delete mode 100644 examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h diff --git a/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c b/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c deleted file mode 100644 index be179f501..000000000 --- a/examples/07_blufi/components/bluedroid_demos/app_project/SampleClientProject.c +++ /dev/null @@ -1,377 +0,0 @@ -/**************************************************************************** -* -* This file is for gatt client. It can scan ble device, connect one device, -* -****************************************************************************/ - -#include -#include -#include -#include - -#include "bta_api.h" -#include "bta_gatt_api.h" -#include "controller.h" - -#include "bt_trace.h" -#include "btm_api.h" -#include "bt_types.h" -#include "gattc_profile.h" - -#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" -#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] - -tBTA_GATTC_IF client_if; -BD_ADDR obj_addr; -static unsigned char BASE_UUID[16] = { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - -int uuidType(unsigned char* p_uuid) -{ - int i = 0; - int match = 0; - int all_zero = 1; - - for(i = 0; i != 16; ++i) - { - if (i == 12 || i == 13) - continue; - - if (p_uuid[i] == BASE_UUID[i]) - ++match; - - if (p_uuid[i] != 0) - all_zero = 0; - } - if (all_zero) - return 0; - if (match == 12) - return LEN_UUID_32; - if (match == 14) - return LEN_UUID_16; - return LEN_UUID_128; -} - -static void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) -{ - char *p_byte = (char*)p_src; - - int i = 0; - - p_dest->len = uuidType(p_src->uu); - - switch (p_dest->len) - { - case LEN_UUID_16: - p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12]; - break; - - case LEN_UUID_32: - p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12]; - p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16); - break; - - case LEN_UUID_128: - for(i = 0; i != 16; ++i) - p_dest->uu.uuid128[i] = p_byte[i]; - break; - - default: - LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len); - break; - } -} -/* -uint16_t get_uuid16(tBT_UUID* p_uuid) -{ - if(p_uuid->len == LEN_UUID_16) - { - return p_uuid->uu.uuid16; - } - else if(p_uuid->len == LEN_UUID_128) - { - UINT16 u16; - UINT8 *p = &p_uuid->uu.uuid128[LEN_UUID_128 - 4]; - STREAM_TO_UINT16(u16, p); - return u16; - } - else - { - return (UINT16)p_uuid->uu.uuid32; - } -} - -//fill a GATT ID structure -void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_output) -{ - p_output->inst_id = inst_id; - p_output->uuid.len = LEN_UUID_16; - p_output->uuid.uu.uuid16 = uuid; -} - -//fill a service ID structure with a 16 bits service UUID -void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, tBTA_GATT_SRVC_ID* p_output) -{ - memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID)); - p_output->is_primary = is_pri; - bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id); -} - -//fill a char ID structure with a 16 bits char UUID -void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p_output) -{ - memset((void *)p_output, 0, sizeof(tBTA_GATT_ID)); - bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output); -} -*/ -/*get remote name*/ -static bool check_remote_name(tBTA_DM_INQ_RES* result, uint8_t* rmt_name, uint8_t* rmt_name_len) -{ - uint8_t *p_rmt_name = NULL; - uint8_t remote_name_len = 0; - - if (result->p_eir) { - p_rmt_name = BTM_CheckEirData(result->p_eir, - BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, - &remote_name_len); - if (!p_rmt_name) - p_rmt_name = BTM_CheckEirData(result->p_eir, - BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, - &remote_name_len); - if (p_rmt_name) { - if (remote_name_len > BD_NAME_LEN) - remote_name_len = BD_NAME_LEN; - if (rmt_name && rmt_name_len) { - memcpy(rmt_name, p_rmt_name, remote_name_len); - *(rmt_name + remote_name_len) = 0; - *rmt_name_len = remote_name_len; - } - return true; - } - } - return false; -} - -/************************************************************************************ -* * Function bta_scan_recult_callback -* * -* * Description scan result.it will be called when device scaned a peer device -* * -* * Return NULL -**************************************************************************************/ -static void bta_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) -{ - uint8_t len; - BD_ADDR bd_addr; - char dev_name[32]; - tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; - //char obj_name[] = "Find Me"; - char obj_name[] = "SimpleBLEPeripheral"; - uint8_t dev_name_len; - - switch (event) - { - case BTA_DM_INQ_RES_EVT: - { - LOG_ERROR("scan result: event=%d, "BT_BD_ADDR_STR", device_type=%d\n", - event, BT_BD_ADDR_HEX(p_data->inq_res.bd_addr), p_data->inq_res.device_type); - - bdcpy(bd_addr, p_data->inq_res.bd_addr); - if (p_data->inq_res.p_eir) - { - if (BTM_CheckEirData(p_data->inq_res.p_eir, BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &len)) - { - p_data->inq_res.remt_name_not_required = TRUE; - } - } - - if(check_remote_name(&(p_data->inq_res), dev_name, &dev_name_len)) - { - LOG_ERROR("scan device name len=%d, name = %s\n", dev_name_len, dev_name); - } - - if(strcmp(dev_name, obj_name) == 0) - { - bdcpy(obj_addr, bd_addr); - LOG_ERROR("find the device, obj_addr="BT_BD_ADDR_STR"\n", BT_BD_ADDR_HEX(obj_addr)); -// BTA_GATTC_Open(client_if, obj_addr, true, transport); - } - } - break; - - case BTA_DM_INQ_CMPL_EVT: - { - LOG_ERROR("%s-BLE observe complete. Num Resp %d\n", __FUNCTION__, p_data->inq_cmpl.num_resps); - - LOG_ERROR("connect the device "BT_BD_ADDR_STR", client_if=%d\n", - BT_BD_ADDR_HEX(obj_addr), client_if); - -/* scan complete, start connect*/ - BTA_GATTC_Open(client_if, obj_addr, true, transport); - } - break; - - default: - LOG_ERROR("%s : unknown event 0x%x", __FUNCTION__, event); - } -} - -/************************************************************************************ -* * Function bta_scan_param_setup_cback -* * -* * Description set scan param callback.it will be called after setting scan parameter -* * -* * Return NULL -**************************************************************************************/ -static void bta_scan_param_setup_cback(tGATT_IF c_client_if, tBTM_STATUS status) -{ - client_if = c_client_if; - LOG_ERROR("\nset scan params complete: status=%d, client_if=%d\n", status, client_if); - /*start scan*/ - BTA_DmBleObserve(true, 8, bta_scan_result_callback); -} - -/************************************************************************************ -* * Function bta_gattc_callback -* * -* * Description app register callback -* * -* * Return NULL -**************************************************************************************/ -static void bta_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) -{ - switch (event) - { - case BTA_GATTC_REG_EVT: - { - tBTA_GATT_STATUS status = p_data->reg_oper.status; - client_if = p_data->reg_oper.client_if; - LOG_ERROR("%s:register complete: event=%d, status=%d, client_if=%d\n", __FUNCTION__, event, status, client_if); - UINT8 scan_interval = 0x50; - UINT8 scan_window = 0x30; - tBLE_SCAN_MODE scan_mode = BTM_BLE_SCAN_MODE_ACTI; - - bac_register(); - /*register complete,set scan parameter*/ - BTA_DmSetBleScanParams(client_if, scan_interval, scan_window, scan_mode, - bta_scan_param_setup_cback); - - } - break; - - /*connect callback*/ - case BTA_GATTC_OPEN_EVT: - { - - LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n", - __FUNCTION__, BT_BD_ADDR_HEX(p_data->open.remote_bda), p_data->open.client_if, - p_data->open.status, p_data->open.conn_id); - /*return whether the remote device is currently connected*/ - int is_connected = BTA_DmGetConnectionState(p_data->open.remote_bda); - LOG_ERROR("is_connected=%d\n",is_connected); - /*get the energy info of the controller*/ - - /*read battery level*/ - int conn_id = p_data->open.conn_id; - - /*discover service*/ - // BTA_GATTC_ServiceSearchRequest(conn_id, NULL); - - } - break; -/* - case BTA_GATTC_SEARCH_RES_EVT: - { - // tBTA_GATTC_SRVC_RES service_result; - LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n", - get_uuid16(&p_data->srvc_res.service_uuid.id.uuid), - p_data->srvc_res.service_uuid.is_primary); - } - break; - - case BTA_GATTC_SEARCH_CMPL_EVT: - { - LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id, - p_data->search_cmpl.status); - - //get first characteristic of battey service - LOG_ERROR("get first characteristic of battery service\n"); - tBTA_GATT_STATUS status; - tBTA_GATT_SRVC_ID battery_srvc_id; - tBTA_GATTC_CHAR_ID out_char_id; - tGATT_CHAR_PROP out_char_prop; - bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id); - status = BTA_GATTC_GetFirstChar(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL, - &out_char_id, &out_char_prop); - if(status == 0) - { - LOG_ERROR("the first char:srvc_id=0x%x,char_id=0x%x, property = %d\n", - get_uuid16(&out_char_id.srvc_id.id.uuid), get_uuid16(&out_char_id.char_id.uuid), - out_char_prop); - //read battery level - tBTA_GATTC_CHAR_ID battery_char_id; - bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id); - bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id); - - BTA_GATTC_ReadCharacteristic(p_data->search_cmpl.conn_id, &battery_char_id, - BTA_GATT_AUTH_REQ_NONE); - } - } - break; - - case BTA_GATTC_READ_CHAR_EVT: - { - - LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n", - p_data->read.conn_id, p_data->read.status); - LOG_ERROR("srvc_id=0x%x,char_id=0x%x,descr_type=0x%x\n", - get_uuid16(&p_data->read.srvc_id.id.uuid), - get_uuid16(&p_data->read.char_id.uuid), - get_uuid16(&p_data->read.descr_type.uuid)); - if(get_uuid16(&p_data->read.descr_type.uuid) != GATT_UUID_CHAR_AGG_FORMAT - && p_data->read.p_value->unformat.len > 0 - && p_data->read.p_value->unformat.p_value != NULL) - { - LOG_ERROR("read the value: len=%d, value=%d\n", p_data->read.p_value->unformat.len, - *(p_data->read.p_value->unformat.p_value)); - } - } - break; -*/ - default: - LOG_ERROR("%s:unknown event: %d\n", __FUNCTION__, event); - } - -} - -/************************************************************************************ -* * Function ble_client_appRegister -* * -* * Description app register function -* * -* * Return NULL -**************************************************************************************/ -void ble_client_appRegister(void) -{ - - bt_uuid_t uuid; - tBT_UUID t_uuid; - memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t)); - btif_to_bta_uuid(&t_uuid, &uuid); - - LOG_ERROR("register application\n"); - BTA_GATTC_AppRegister(&t_uuid, bta_gattc_callback); - - /*battery service register*/ -// bac_register(); - -} - -void gattc_client_test(void) -{ - BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG); - - ble_client_appRegister(); -} diff --git a/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c deleted file mode 100644 index 8ed96b04c..000000000 --- a/examples/07_blufi/components/bluedroid_demos/app_project/SampleServerProject.c +++ /dev/null @@ -1,295 +0,0 @@ -/*************************************************************** -* -* This file is for gatt server device. It instantiates BATTERY -* sevice. It can be scanned and connected by central device, -* and the client will get the BAS value. It calls the API bta -* layer provides. -* -****************************************************************/ - -#include -#include -#include -#include - -#include "prf_defs.h" - -#include "bta_api.h" -#include "bta_gatt_api.h" -#include "controller.h" - -#include "gatt_int.h" -#include "bt_trace.h" -#include "btm_api.h" -#include "bt_types.h" -#include "dis_api.h" -#include "bt_app_common.h" - -//#include "app_button.h" -#include "button_pro.h" -#include "hid_le_prf.h" - -#include "hcimsgs.h" -#include "bt_app_defs.h" - - -#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" -#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] -tBTA_GATTS_IF server_if; - -static unsigned char DIS_UUID[16] = { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x0a, 0x18, 0x00, 0x00 - }; -static unsigned char BASE_UUID[16] = { - 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, - 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - -UINT16 ijiazu_uuid = 0xffff; -tBTA_BLE_SERVICE ijiazu_service = { - 0x01, //only one service in the ijiazu button profile - false, - &ijiazu_uuid - }; /* 16 bits services */ - - -UINT8 beacon_manu[25] = {0x4c, 0x00,0x02, 0x15, 0xfd, 0xa5, 0x06, 0x93, 0xa4, 0xe2, - 0x4f, 0xb1, 0xaf, 0xcf, 0xc6, 0xeb, 0x07, 0x64, 0x78, 0x25, - 0x27, 0x32, 0xe6, 0x08, 0xc5}; - -//UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31}; -UINT8 ijiazu_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0x31,0x30,0x4a,0x30,0x30,0x31}; -tBTA_BLE_MANU p_ijiazu_manu = {sizeof(ijiazu_manu),ijiazu_manu}; /* manufacturer data */ - - -BD_ADDR rand_ijiazu_addr = {0x00,0x02,0x5B,0x00,0x32,0x55}; - -tESP_BLE_ADV_DATA ijiazu_adv_data[ADV_SCAN_IDX_MAX] = -{ - [BLE_ADV_DATA_IDX] = { - .adv_name = "Espressif_008", - { - {0,0}, - NULL, //no manufature data to be setting in the ijiazu adervetisiing datas - &ijiazu_service, - NULL, //the 128 bits service uuid set to null(not used) - NULL, //the 32 bits Service UUID set to null(not used) - NULL, //16 bits services Solicitation UUIDs set to null(not used) - NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used) - NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used) - NULL, //proprietary data set to null(not used) - NULL, //service data set not null(no service data to be sent) - 0x0200, //device type : generic display - BTA_DM_GENERAL_DISC, // General discoverable. - 0xFE //the tx power value,defult value is 0 - }, - - }, - [BLE_SCAN_RSP_DATA_IDX] = { - .adv_name = NULL, - { - {0,0}, - &p_ijiazu_manu, - NULL, - NULL, //the 128 bits service uuid set to null(not used) - NULL, //the 32 bits Service UUID set to null(not used) - NULL, //16 bits services Solicitation UUIDs set to null(not used) - NULL, //List of 32 bit Service Solicitation UUIDs set to null(not used) - NULL, //List of 128 bit Service Solicitation UUIDs set to null(not used) - NULL, //proprietary data set to null(not used) - NULL, //service data set not null(no service data to be sent) - 0x0000, //device type : generic display - 0x00, // General discoverable. - 0x00}, //the tx power value,defult value is 0 - - } -}; - -#if (BUT_PROFILE_CFG) -static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data); -#endif - -int uuidType(unsigned char* p_uuid) -{ - int i = 0; - int match = 0; - int all_zero = 1; - - for(i = 0; i != 16; ++i) - { - if (i == 12 || i == 13) - continue; - - if (p_uuid[i] == BASE_UUID[i]) - ++match; - - if (p_uuid[i] != 0) - all_zero = 0; - } - if (all_zero) - return 0; - if (match == 12) - return LEN_UUID_32; - if (match == 14) - return LEN_UUID_16; - return LEN_UUID_128; -} - -/*16-bits uuid to the structure of holding any type of UUID*/ -void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) -{ - char *p_byte = (char*)p_src; - - int i = 0; - - p_dest->len = uuidType(p_src->uu); - - switch (p_dest->len) - { - case LEN_UUID_16: - p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12]; - break; - - case LEN_UUID_32: - p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12]; - p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16); - break; - - case LEN_UUID_128: - for(i = 0; i != 16; ++i) - p_dest->uu.uuid128[i] = p_byte[i]; - break; - - default: - LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len); - break; - } -} -/*set advertising config callback*/ -static void bta_gatts_set_adv_data_cback(tBTA_STATUS call_status) -{ - LOG_ERROR("set advertising config:status=%d\n", call_status); - /*dis init*/ -/* tDIS_ATTR_MASK dis_attr_mask; - dis_attr_mask = DIS_ATTR_SYS_ID_BIT | DIS_ATTR_MODEL_NUM_BIT | DIS_ATTR_SERIAL_NUM_BIT | - DIS_ATTR_FW_NUM_BIT | DIS_ATTR_HW_NUM_BIT | DIS_ATTR_SW_NUM_BIT | DIS_ATTR_MANU_NAME_BIT | - DIS_ATTR_IEEE_DATA_BIT | DIS_ATTR_PNP_ID_BIT; - DIS_SrInit(dis_attr_mask); -*/ - /*instantiate a battery service*/ - //bas_register(); - /*instantiate the driver for button profile*/ - //app_button_init(); -#if (BUT_PROFILE_CFG) - /*instantiate a button service*/ - button_init(SimpleDataCallBack); -#endif ///BUT_PROFILE_CFG - - /*instantiate a hid device service*/ - //hidd_le_init(); - /*start advetising*/ - //BTA_GATTS_Listen(server_if, true, NULL); -} - -/*register callback*/ -void bta_gatts_callback(tBTA_GATTS_EVT event, tBTA_GATTS* p_data) -{ - switch (event) - { - case BTA_GATTS_REG_EVT: - { - tBTA_GATT_STATUS status = p_data->reg_oper.status; - server_if = p_data->reg_oper.server_if; - LOG_ERROR("register complete: event=%d, status=%d, server_if=%d\n", - event, status, server_if); - - LOG_ERROR("set advertising parameters\n"); - //set the advertising data to the btm layer - ESP_AppBleConfigadvData(&ijiazu_adv_data[BLE_ADV_DATA_IDX], - bta_gatts_set_adv_data_cback); - //set the adversting data to the btm layer - ESP_AppBleSetScanRsp(&ijiazu_adv_data[BLE_SCAN_RSP_DATA_IDX],NULL); - BTA_GATTS_Listen(server_if, true, NULL); - } - break; - /*connect callback*/ - case BTA_GATTS_CONNECT_EVT: - { - LOG_ERROR("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n", - BT_BD_ADDR_HEX(p_data->conn.remote_bda), p_data->conn.server_if, - p_data->conn.reason, p_data->conn.conn_id); - /*return whether the remote device is currently connected*/ - int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda); - LOG_ERROR("is_connected=%d\n",is_connected); - } - break; - - default: - LOG_ERROR("unsettled event: %d\n", event); - } - -} - -#if (BUT_PROFILE_CFG) -#define HEADER_SSID "ssid" -#define HEADER_PASSWD "passwd" -#define HEADER_CONFIRM "confirm" -extern void wifi_set_blue_config(char *ssid, char *passwd); -static char tmp_ssid[33]; -static char tmp_passwd[33]; - -static void SimpleDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data) -{ - char *p = NULL; - LOG_ERROR("the data is:%s\n", p_data); -#if 0 - switch(event) - { - case RECEIVE_NET_PASSWD_EVT: - LOG_ERROR("Received the network passwork"); - break; - case RECEIVE_NET_SSD_EVT: - LOG_ERROR("Received the network SSID"); - break; - default: - break; - } -#endif - p = strstr(p_data, HEADER_SSID); - if (p) { - ets_printf("SSID: %s\n", p+strlen(HEADER_SSID)+1); - strcpy(tmp_ssid, p+strlen(HEADER_SSID)+1); - } - p = strstr(p_data, HEADER_PASSWD); - if (p) { - ets_printf("PASSWORD: %s\n", p+strlen(HEADER_PASSWD)+1); - strcpy(tmp_passwd, p+strlen(HEADER_PASSWD)+1); - } - p = strstr(p_data, HEADER_CONFIRM); - if (p) { - ets_printf("CONFIRM\n"); - wifi_set_blue_config(tmp_ssid, tmp_passwd); - } - -} -#endif ///BUT_PROFILE_CFG - -static void ble_server_appRegister(void) -{ - bt_uuid_t uuid; - tBT_UUID t_uuid; - memcpy(&uuid, BASE_UUID, sizeof(bt_uuid_t)); - //memcpy(&uuid, DIS_UUID, sizeof(bt_uuid_t)); - btif_to_bta_uuid(&t_uuid, &uuid); - - LOG_ERROR("register gatts application\n"); - BTA_GATTS_AppRegister(&t_uuid, bta_gatts_callback); -} - -void gatts_server_test(void) -{ - BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG); - - ble_server_appRegister(); -} diff --git a/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h b/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h deleted file mode 100644 index d0eb314bb..000000000 --- a/examples/07_blufi/components/bluedroid_demos/include/bt_app_common.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __BT_APP_COMMON_H__ -#define __BT_APP_COMMON_H__ - -#include -#include "osi.h" -#include "bt_common_types.h" -#include "bt_defs.h" - -/* BT APP Events */ -#define BT_EVT_APP (0xB000) -#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP) - -typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param); -typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src); - -typedef struct -{ - BT_HDR hdr; - tBTAPP_CBACK* p_cb; /* context switch callback */ - - /* parameters passed to callback */ - UINT16 event; /* message event id */ - char p_param[0]; /* parameter area needs to be last */ -} tBTAPP_CONTEXT_SWITCH_CBACK; - -bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback); - -void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param); - -void bt_app_task_start_up(void); -#endif /* __BT_APP_COMMON_H__ */ From aa6fe0414887d0238c0d1fbc64f39de8528bf8b9 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Sat, 5 Nov 2016 02:48:16 +0800 Subject: [PATCH 26/31] component/bt : cleanup the liscence header --- .../bluedroid/profiles/core/bt_prf_sys_main.c | 27 +- .../bt/bluedroid/profiles/core/bt_prf_task.c | 26 +- .../bluedroid/profiles/core/bt_profile_act.c | 26 +- .../profiles/core/include/bt_prf_evt.h | 26 +- .../profiles/core/include/bt_prf_sys.h | 26 +- .../profiles/core/include/bt_prf_task.h | 42 +- .../profiles/esp/ble_button/button_pro.c | 26 +- .../profiles/esp/include/button_pro.h | 27 +- .../profiles/esp/include/wx_airsync_prf.h | 26 +- .../esp/wechat_AirSync/wx_airsync_prf.c | 27 +- .../profiles/std/battery/battery_prf.c | 19 +- .../profiles/std/hid_le/hid_le_prf.c | 27 +- .../profiles/std/include/hid_le_prf.h | 26 +- .../bluedroid/profiles/std/include/prf_defs.h | 27 +- .../bt/bluedroid/stack_api/bt_app_api.c | 2472 ++++++++--------- .../bt/bluedroid/stack_api/bt_app_sec.c | 216 +- .../bt/bluedroid/stack_api/bt_gap_api.c | 14 + .../bt/bluedroid/stack_api/bt_sdp_api.c | 14 + .../bluedroid/stack_api/include/bt_app_api.h | 1848 ++++++------ .../bluedroid/stack_api/include/bt_app_sec.h | 156 +- examples/05_ble_adv/main/app_bt.c | 14 + .../app_client_profiles/battery_c/battery_c.c | 14 + .../bluedroid_demos/app_core/bt_app.c | 26 +- .../bluedroid_demos/app_core/bt_app_core.c | 14 + .../app_WX_airsync/app_airsync_md5.c | 261 +- .../app_WX_airsync/app_airsync_prf.c | 313 +-- .../app_sample_button/app_button.c | 30 +- .../app_project/SampleClientProject.c | 14 + .../app_project/SampleServerProject.c | 14 + .../bluedroid_demos/include/app_airsync_md5.h | 91 +- .../bluedroid_demos/include/app_airsync_prf.h | 82 +- .../bluedroid_demos/include/app_button.h | 14 - .../bluedroid_demos/include/app_button_int.h | 247 +- examples/06_bluedroid_demos/main/demo_main.c | 14 + examples/07_blufi/components/blufi/blufi.c | 14 + .../07_blufi/components/blufi/blufi_task.c | 14 + examples/07_blufi/main/demo_main.c | 14 + 37 files changed, 3200 insertions(+), 3088 deletions(-) diff --git a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c index 90d3fc1bd..e1b34254d 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_sys_main.c @@ -1,17 +1,18 @@ -/** - **************************************************************************************** - * - * @file bt_prf_sys_main.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "thread.h" #include "bt_prf_sys.h" #include "fixed_queue.h" diff --git a/components/bt/bluedroid/profiles/core/bt_prf_task.c b/components/bt/bluedroid/profiles/core/bt_prf_task.c index eb0edb930..cf5c44177 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_task.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_task.c @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file bt_prf_task.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/11 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "bt_prf_task.h" #include "bt_prf_sys.h" diff --git a/components/bt/bluedroid/profiles/core/bt_profile_act.c b/components/bt/bluedroid/profiles/core/bt_profile_act.c index a0a4b813f..934ee0f41 100644 --- a/components/bt/bluedroid/profiles/core/bt_profile_act.c +++ b/components/bt/bluedroid/profiles/core/bt_profile_act.c @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file bt_profile_act.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_evt.h b/components/bt/bluedroid/profiles/core/include/bt_prf_evt.h index 3af0939b8..a0fafde08 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_evt.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_evt.h @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file bt_prf_task.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/12 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h index 7f10b13b4..57ed50679 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_sys.h @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file bt_prf_sys.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/12 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #ifndef _PROFILE_SYS_H__ #define _PROFILE_SYS_H__ diff --git a/components/bt/bluedroid/profiles/core/include/bt_prf_task.h b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h index d2d9a4bce..5db370ce6 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_task.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h @@ -1,24 +1,24 @@ -/** - **************************************************************************************** - * - * @file bt_prf_task.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/11 - * - * - **************************************************************************************** - */ - -#include -#include "bt_defs.h" -#include "fixed_queue.h" - -#ifndef BT_PRF_TASK_H__ -#define BT_PRF_TASK_H__ - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "bt_defs.h" +#include "fixed_queue.h" + +#ifndef BT_PRF_TASK_H__ +#define BT_PRF_TASK_H__ + /* Functions provided by bt_prf_task.c ************************************ */ diff --git a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c index 9620ac839..55f9a8b50 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file button_pro.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/8/18 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index 8e95a0d99..67d4de4e4 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -1,17 +1,18 @@ -/** - **************************************************************************************** - * - * @file button_pro.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/8/18 - * - * - **************************************************************************************** - */ #include "prf_defs.h" +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #if (BUT_PROFILE_CFG) #include "bt_target.h" diff --git a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h index 74d5dae9f..89d65282d 100644 --- a/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h +++ b/components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file wx_airsync_prf.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/29 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "prf_defs.h" diff --git a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c index d970821bb..ac7efe58d 100644 --- a/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c +++ b/components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c @@ -1,17 +1,18 @@ -/** - **************************************************************************************** - * - * @file wx_airsync_prf.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/29 - * - * - **************************************************************************************** - */ #include "wx_airsync_prf.h" +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #if (WX_AIRSYNC_CFG) diff --git a/components/bt/bluedroid/profiles/std/battery/battery_prf.c b/components/bt/bluedroid/profiles/std/battery/battery_prf.c index 383bd5dfd..ed32ff2f0 100644 --- a/components/bt/bluedroid/profiles/std/battery/battery_prf.c +++ b/components/bt/bluedroid/profiles/std/battery/battery_prf.c @@ -1,9 +1,18 @@ -/*************************************************************** -* * -* * This file is for battery service based on bta layer -* * -***************************************************************/ #include +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include diff --git a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c index 550dcf716..9978524dd 100644 --- a/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c +++ b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c @@ -1,17 +1,18 @@ -/** - **************************************************************************************** - * - * @file hid_le_prf.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/7 - * - * - **************************************************************************************** - */ #include +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "hid_le_prf.h" #include "prf_defs.h" diff --git a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h index 3c17edbbf..15591ed1a 100644 --- a/components/bt/bluedroid/profiles/std/include/hid_le_prf.h +++ b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file button_pro.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/7 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "prf_defs.h" diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index dab333aad..8b9ed62ef 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -1,17 +1,18 @@ -/** - **************************************************************************************** - * - * @file prf_defs.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/8 - * - * - **************************************************************************************** - */ #ifndef PRF_DEFS_H_ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #define PRF_DEFS_H_ #include "bta_api.h" diff --git a/components/bt/bluedroid/stack_api/bt_app_api.c b/components/bt/bluedroid/stack_api/bt_app_api.c index fe309254e..7b23880d1 100644 --- a/components/bt/bluedroid/stack_api/bt_app_api.c +++ b/components/bt/bluedroid/stack_api/bt_app_api.c @@ -1,1236 +1,1236 @@ -/** - **************************************************************************************** - * - * @file bt_app_api.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/17 - * - * - **************************************************************************************** - */ - -#include "bt_app_api.h" -#include "btm_ble_api.h" -//#include "btm_ble_int.h" - - - -/******************************************************************************* -** -** @function esp_ble_config_adv_data -** -** @brief This function is called to override the BTA default ADV parameters. -** -** @param[in] adv_data: Pointer to User defined ADV data structure. This -** memory space can not be freed until p_adv_data_cback -** is received. -** @param[in|out] adv_data_cback: set adv data complete callback. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, - esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) -{ - if(adv_data != NULL) - { - ble_config_adv_data(adv_data, adv_data_cback); - }else{ - LOG_ERROR("The adv_data is NULL\n"); - } - - if(++adv_data != NULL) - { - ble_set_scan_rsp(adv_data, NULL); - } - -} - - -/******************************************************************************* -** -** @function esp_ble_start_advertising -** -** @brief This function is called to start advertising. -** -** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) -{ - if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || - !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) - { - LOG_ERROR("Invalid advertisting interval parameters.\n"); - return ; - } - - if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) && - (ble_adv_params->adv_type > API_BROADCASTER_MODE) ) - { - LOG_ERROR("Invalid advertisting type parameters.\n"); - return; - } - - if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) && - (ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) ) - { - LOG_ERROR("Invalid advertisting type parameters.\n"); - return; - } - - LOG_ERROR("API_Ble_AppStartAdvertising\n"); - - /// - BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, - ble_adv_params->adv_int_max, - ble_adv_params->adv_type, - ble_adv_params->addr_type_own, - ble_adv_params->channel_map, - ble_adv_params->adv_filter_policy, - ble_adv_params->p_dir_bda); - - -} - - -/******************************************************************************* -** -** @function esp_ble_set_scan_params -** -** @brief This function is called to set scan parameters -** -** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This -** memory space can not be freed until scan_param_setup_cback -** @param[in] client_if: Client interface ID -** @param[in|out] scan_param_setup_status_cback - Set scan param status callback -** -** @return None -** -*******************************************************************************/ -void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, - esp_scan_param_setup_cb_t scan_param_setup_cback) -{ - if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && - API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && - (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) - { - BTA_DmSetBleScanFilterParams(client_if, - scan_params->scan_intv, - scan_params->scan_win, - scan_params->scan_type, - scan_params->scan_fil_policy, - scan_params->addr_type_own, - scan_param_setup_cback); - } -} - - -/******************************************************************************* -** -** @function esp_ble_start_scanning -** -** @brief This procedure keep the device scanning the peer device whith advertising on the air -** -** @param[in] duration: Keeping the scaning time, the unit is second. -** @param[in|out] results_cb: The scanning function callback when the peer device has been scan -** which advertising on the air -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) -{ - if((duration != 0) && (results_cb != NULL)) - { - ///Start scan the device - BTA_DmBleObserve(true, duration, results_cb); - }else{ - LOG_ERROR("The scan duration or p_results_cb invalid\n"); - } -} - - -/******************************************************************************* -** -** @function esp_ble_stop_advertising -** -** @brief This function is called to stop advertising. -** -** @param None -** -** @return None -** -*******************************************************************************/ -void esp_ble_stop_advertising (void) -{ - bool stop_adv = false; - - BTA_DmBleBroadcast(stop_adv); -} - - -/******************************************************************************* -** -** @function esp_ble_update_conn_params -** -** @brief Update connection parameters, can only be used when connection is up. -** -** @param[in] bd_addr - BD address of the peer -** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] -** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] -** @param[in] latency - slave latency [0 ~ 500] -** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] -** -** @return None -** -*******************************************************************************/ -void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, - uint16_t max_int, uint16_t latency, uint16_t timeout) -{ - if (min_int > max_int){ - min_int = max_int; - } - - if (min_int < BTM_BLE_CONN_INT_MIN || max_int > BTM_BLE_CONN_INT_MAX){ - LOG_ERROR("Invalid interval value.\n"); - } - - BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int, - latency, timeout); - -} - - - -/******************************************************************************* -** -** @function esp_ble_set_pkt_data_len -** -** @brief This function is to set maximum LE data packet size -** -** @return None -** -** -*******************************************************************************/ -void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length) -{ - if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ - tx_data_length = BTM_BLE_DATA_SIZE_MAX; - }else if (tx_data_length < BTM_BLE_DATA_SIZE_MIN){ - tx_data_length = BTM_BLE_DATA_SIZE_MIN; - } - - BTA_DmBleSetDataLength(remote_device, tx_data_length); -} - - - -/******************************************************************************* -** -** @function esp_ble_set_rand_addr -** -** @brief This function set the random address for the appliction -** -** @param[in] rand_addr: the random address whith should be setting -** -** @return None -** -** -*******************************************************************************/ -void esp_ble_set_rand_addr (BD_ADDR rand_addr) -{ - if (rand_addr != NULL){ - BTA_DmSetRandAddress(rand_addr); - }else{ - LOG_ERROR("Invalid randrom address.\n"); - } -} - - -/******************************************************************************* -** -** @function esp_ble_config_local_privacy -** -** @brief Enable/disable privacy on the local device -** -** @param[in] privacy_enable - enable/disabe privacy on remote device. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_local_privacy (BOOLEAN privacy_enable) -{ - BTA_DmBleConfigLocalPrivacy(privacy_enable); -} - - -/******************************************************************************* -** @function esp_gattc_disable -** @brief This function is called by application to disable GATTC module -** -** @param NULL -** -** @return None. -** -*******************************************************************************/ -void esp_gattc_disable(void) -{ - // TODO: This API funciton didn't finish, will be added it in future -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_app_register -** -** @brief This function is called to register application callbacks -** with GATTC module. -** -** @param[in] app_uuid - applicaiton UUID -** @param[in] client_cb - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb) -{ - if (app_uuid != NULL) - { - BTA_GATTC_AppRegister(app_uuid, client_cb); - }else{ - LOG_ERROR("The app uuid invalid.\n"); - } -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_app_unregister -** -** @brief This function is called to unregister an application -** from GATTC module. -** -** @param[in] client_if - client interface identifier. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if) -{ - BTA_GATTC_AppDeregister(client_if); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_conn -** -** @brief Open a direct connection or add a background auto connection -** bd address -** -** @param[in] client_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) -{ - tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; - if(remote_bda == NULL ){ - LOG_ERROR("Invaild address data \n"); - return; - } - - BTA_GATTC_Open(client_if, remote_bda, is_direct, transport); - - - - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_cancel_conn -** -** @brief Cancel a direct open connection or remove a background auto connection -** bd address -** -** @param[in] client_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) -{ - if(remote_bda == NULL ){ - LOG_ERROR("Invaild address data \n"); - return; - } - - BTA_GATTC_CancelOpen(client_if, remote_bda, is_direct); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_close -** -** @brief Close a connection to a GATT server. -** -** @param[in] conn_id: connectino ID to be closed. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_close (uint16_t conn_id) -{ - BTA_GATTC_Close(conn_id); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_config_mtu -** -** @brief Configure the MTU size in the GATT channel. This can be done -** only once per connection. -** -** @param[in] conn_id: connection ID. -** mtu: desired MTU size to use. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) -{ - if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ - LOG_ERROR("Invalid MTU parameters\n"); - return ESP_GATT_ILLEGAL_PARAMETER; - } - - BTA_GATTC_ConfigureMTU (conn_id, mtu); - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_svc_search_req -** -** @brief This function is called to request a GATT service discovery -** on a GATT server. This function report service search result -** by a callback event, and followed by a service search complete -** event. -** -** @param[in] conn_id: connection ID. -** @param[in] srvc_uuid: a UUID of the service application is interested in. -** If Null, discover for all services. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid) -{ - BTA_GATTC_ServiceSearchRequest(conn_id, srvc_uuid); -} - - -/**************************************************************************************************** -** -** @function esp_ble_gattc_get_first_char -** -** @brief This function is called to find the first characteristic of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] srvc_id: the service ID of which the characteristic is belonged to. -** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] char_result: output parameter which will store the GATT -** characteristic ID. -** @param[in] property: output parameter to carry the characteristic property. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. -** -*****************************************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, - esp_bt_uuid_t *char_uuid_cond, - esp_gattc_char_id_t *char_result, - esp_gatt_char_prop_t *property) -{ - esp_gatt_status_t status = 0; - - if (!srvc_id || !char_result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetFirstChar (conn_id, srvc_id, char_uuid_cond, - char_result, property); - - return status; - - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_first_char_descr -** -** @brief This function is called to find the first characteristic descriptor of the -** characteristic on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. -** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available -** characteristic. -** @param[in] descr_result: output parameter which will store the GATT -** characteristic descriptor ID. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, - esp_bt_uuid_t *descr_uuid_cond, - esp_gattc_char_descr_id_t *descr_result) -{ - esp_gatt_status_t status; - - if (!char_id || !descr_result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetFirstCharDescr (conn_id, char_id, descr_uuid_cond, descr_result); - - return status; - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_char -** -** @brief This function is called to find the next characteristic of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_char_id: start the characteristic search from the next record -** after the one identified by char_id. -** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] char_result: output parameter which will store the GATT -** characteristic ID. -** @param[in] property: output parameter to carry the characteristic property. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. -** -*******************************************************************************/ - -esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, - esp_gattc_char_id_t *start_char_id, - esp_bt_uuid_t *char_uuid_cond, - esp_gattc_char_id_t *char_result, - esp_gatt_char_prop_t *property) -{ - - esp_gatt_status_t status; - - if (!start_char_id || !char_result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetNextChar(conn_id, start_char_id, char_uuid_cond, - char_result, property); - - return status; - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_char_descr -** -** @brief This function is called to find the next characteristic descriptor -** of the characterisctic. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_descr_id: start the descriptor search from the next record -** after the one identified by p_start_descr_id. -** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find -** the first available characteristic descriptor. -** @param[in] descr_result: output parameter which will store the GATT -** characteristic descriptor ID. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. -** -*******************************************************************************/ - -esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *start_descr_id, - esp_bt_uuid_t *descr_uuid_cond, - esp_gattc_char_descr_id_t *descr_result) -{ - esp_gatt_status_t status; - - if (!start_descr_id || !descr_result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetNextCharDescr (conn_id, start_descr_id, descr_uuid_cond, descr_result); - - return status; - -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_first_inclu_srvc -** -** @brief This function is called to find the first included service of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] srvc_id: the service ID of which the characteristic is belonged to. -** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] result: output parameter which will store the GATT ID -** of the included service found. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, - esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) -{ - - esp_gatt_status_t status; - - if (!srvc_id || !result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetFirstIncludedService(conn_id, srvc_id, uuid_cond, result); - - return status; -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_inclu_srvc -** -** @brief This function is called to find the next included service of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_id: start the search from the next record -** after the one identified by p_start_id. -** @param[in] uuid_cond: Included service UUID, if NULL find the first available -** included service. -** @param[in] result: output parameter which will store the GATT ID -** of the included service found. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. - -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, - esp_gattc_incl_srvc_id_t *start_id, - esp_bt_uuid_t *uuid_cond, - esp_gattc_incl_srvc_id_t *result) -{ - esp_gatt_status_t status; - - if (!start_id || !result){ - return ESP_GATT_ILLEGAL_PARAMETER; - } - - status = BTA_GATTC_GetNextIncludedService(conn_id, start_id, uuid_cond, result); - - return status; -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_char -** -** @brief This function is called to read a service's characteristics of -** the given characteritisc ID. -** -** @param[in] conn_id - connectino ID. -** @param[in] char_id - characteritic ID to read. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_ReadCharacteristic(conn_id, char_id, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_char_descr -** -** @brief This function is called to read a characteristics descriptor. -** -** @param[in] conn_id - connection ID. -** @param[in] descr_id - characteritic descriptor ID to read. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *descr_id, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_ReadCharDescr (conn_id, descr_id, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_multi -** -** @brief This function is called to read multiple characteristic or -** characteristic descriptors. -** -** @param[in] conn_id - connectino ID. -** @param[in] read_multi - pointer to the read multiple parameter. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_ReadMultiple(conn_id, read_multi, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_write_char_val -** -** @brief This function is called to write characteristic value. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - characteristic ID to write. -** @param[in] write_type - type of write. -** @param[in] len: length of the data to be written. -** @param[in] value - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_write_char_val ( uint16_t conn_id, - esp_gattc_char_id_t *char_id, - esp_gattc_write_type_t write_type, - uint16_t len, - uint8_t *value, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_WriteCharValue (conn_id, char_id, write_type, len, value, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_write_char_descr -** -** @brief This function is called to write characteristic descriptor value. -** -** @param[in] conn_id - connection ID -** @param[in] char_descr_id - characteristic descriptor ID to write. -** @param[in] write_type - write type. -** @param[in] data - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_write_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *char_descr_id, - esp_gattc_write_type_t write_type, - esp_gatt_unfmt_t *data, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_WriteCharDescr (conn_id, char_descr_id, write_type, data, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_prepa_write -** -** @brief This function is called to prepare write a characteristic value. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - GATT characteritic ID of the service. -** @param[in] offset - offset of the write value. -** @param[in] len: length of the data to be written. -** @param[in] value - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, - uint16_t offset, uint16_t len, uint8_t *value, - esp_gatt_auth_req_t auth_req) -{ - BTA_GATTC_PrepareWrite (conn_id, char_id, offset, len, value, auth_req); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_execu_write -** -** @brief This function is called to execute write a prepare write sequence. -** -** @param[in] conn_id - connection ID. -** @param[in] is_execute - execute or cancel. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute) -{ - BTA_GATTC_ExecuteWrite (conn_id, is_execute); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_send_ind_cfm -** -** @brief This function is called to send handle value confirmation. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - characteristic ID to confirm. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) -{ - BTA_GATTC_SendIndConfirm (conn_id, char_id); -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_register_ntf -** -** @brief This function is called to register for notification of a service. -** -** @param[in] client_if - client interface. -** @param[in] bda - target GATT server. -** @param[in] char_id - pointer to GATT characteristic ID. -** -** @return OK if registration succeed, otherwise failed. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, - BD_ADDR bda, - esp_gattc_char_id_t *char_id) -{ - esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; - status = BTA_GATTC_RegisterForNotifications (client_if, bda, char_id); - - return status; -} - - -/******************************************************************************* -** -** @function esp_ble_gattc_unregister_ntf -** -** @brief This function is called to de-register for notification of a service. -** -** @param[in] client_if - client interface. -** @param[in] bda - target GATT server. -** @param[in] char_id - pointer to GATT characteristic ID. -** -** @return OK if deregistration succeed, otherwise failed. -** -*******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, - BD_ADDR bda, - esp_gattc_char_id_t *char_id) -{ - esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; - status = BTA_GATTC_DeregisterForNotifications (client_if, bda, char_id); - - return status; -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_disale -** -** @brief This function is called to disable GATTS module -** -** @param[in] None. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_disale(void) -{ - BTA_GATTS_Disable(); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_app_register -** -** @brief This function is called to register application callbacks -** with BTA GATTS module. -** -** @param[in] app_uuid - applicaiton UUID -** @param[in] cback - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback) -{ - BTA_GATTS_AppRegister(app_uuid, cback); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_app_unregister -** -** @brief un-register with GATT Server. -** -** @param[in] server_if: service interface id. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if) -{ - BTA_GATTS_AppDeregister(server_if); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_create_srvc -** -** @brief Create a service. When service creation is done, a callback -** event BTA_GATTS_CREATE_SRVC_EVT is called to report status -** and service ID to the profile. The service ID obtained in -** the callback function needs to be used when adding included -** service and characteristics/descriptors into the service. -** -** @param[in] server_if: Profile ID this service is belonged to. -** @param[in] service_uuid: service UUID. -** @param[in] inst: instance ID number of this service. -** @param[in] num_handle: numble of handle requessted for this service. -** @param[in] is_primary: is this service a primary one or not. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, - uint16_t num_handle, BOOLEAN is_primary) -{ - BTA_GATTS_CreateService(server_if, service_uuid, inst, num_handle, is_primary); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_add_inclu_srvc -** -** @brief This function is called to add an included service. After included -** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT -** is reported the included service ID. -** -** @param[in] service_id: service ID to which this included service is to -** be added. -** @param[in] included_service_id: the service ID to be included. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id) -{ - BTA_GATTS_AddIncludeService(service_id, included_service_id); -} - -/******************************************************************************* -** -** @function esp_ble_gatts_add_char -** -** @brief This function is called to add a characteristic into a service. -** -** @param[in] service_id: service ID to which this included service is to -** be added. -** @param[in] char_uuid : Characteristic UUID. -** @param[in] perm : Characteristic value declaration attribute permission. -** @param[in] property : Characteristic Properties -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, - esp_gatt_perm_t perm, esp_gatt_char_prop_t property) -{ - BTA_GATTS_AddCharacteristic (service_id, char_uuid, perm, property); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_add_char_descr -** -** @brief This function is called to add characteristic descriptor. When -** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called -** to report the status and an ID number for this descriptor. -** -** @param[in] service_id: service ID to which this charatceristic descriptor is to -** be added. -** @param[in] perm: descriptor access permission. -** @param[in] descr_uuid: descriptor UUID. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_char_descr (uint16_t service_id, - esp_gatt_perm_t perm, - esp_bt_uuid_t * descr_uuid) -{ - BTA_GATTS_AddCharDescriptor (service_id, perm, descr_uuid); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_dele_srvc -** -** @brief This function is called to delete a service. When this is done, -** a callback event BTA_GATTS_DELETE_EVT is report with the status. -** -** @param[in] service_id: service_id to be deleted. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_dele_srvc (uint16_t service_id) -{ - BTA_GATTS_DeleteService(service_id); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_start_srvc -** -** @brief This function is called to start a service. -** -** @param[in] service_id: the service ID to be started. -** @param[in] sup_transport: supported trasnport. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_start_srvc(uint16_t service_id) -{ - tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; - BTA_GATTS_StartService(service_id, transport); -} - -/******************************************************************************* -** -** @function esp_ble_gatts_stop_srvc -** -** @brief This function is called to stop a service. -** -** @param[in] service_id - service to be topped. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_stop_srvc(uint16_t service_id) -{ - BTA_GATTS_StopService(service_id); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_hdl_val_indica -** -** @brief This function is called to read a characteristics descriptor. -** -** @param[in] bda - remote device bd address to indicate. -** @param[in] attr_id - attribute ID to indicate. -** @param[in] data_len - indicate data length. -** @param[in] data: data to indicate. -** @param[in] need_confirm - if this indication expects a confirmation or not. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, - uint8_t *data, BOOLEAN need_confirm) -{ - BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, data, need_confirm); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_send_rsp -** -** @brief This function is called to send a response to a request. -** -** @param[in] conn_id - connection identifier. -** @param[in] trans_id - transaction ID. -** @param[in] status - response status -** @param[in] msg - response data. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, - esp_gatt_status_t status, esp_gatts_rsp_t *msg) -{ - BTA_GATTS_SendRsp (conn_id, trans_id, status, msg); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_conn -** -** @brief Open a direct open connection or add a background auto connection -** bd address -** -** @param[in] server_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) -{ - tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; - BTA_GATTS_Open(server_if, remote_bda, is_direct, transport); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_cancel_conn -** -** @brief Cancel a direct open connection or remove a background auto connection -** bd address -** -** @param[in] server_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) -{ - BTA_GATTS_CancelOpen(server_if, remote_bda, is_direct); -} - - -/******************************************************************************* -** -** @function esp_ble_gatts_close -** -** @param[in] Close a connection a remote device. -** -** @param[in] conn_id: connectino ID to be closed. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_close(uint16_t conn_id) -{ - BTA_GATTS_Close(conn_id); -} - - -/******************************************************************************* -** -** @function esp_prf_app_register -** -** @brief This function is called to register application callbacks -** with BTA GATTS module. -** -** @param[in] p_app_uuid - applicaiton UUID -** @param[in] p_cback - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_prf_app_register(uint8_t prf_id, void *p_cback) -{ - //tBTA_GATTS_API_REG *p_buf; - - /* register with BTA system manager */ - if (bt_prf_sys_is_register(PRF_ID_SYS) == FALSE) - { - bt_prf_sys_register(PRF_ID_SYS, NULL); - } - -// if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) -// { -// p_buf->hdr.event = BTA_GATTS_API_REG_EVT; - -// if (p_app_uuid != NULL) -// memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); -// p_buf->p_cback = p_cback; - -// bta_sys_sendmsg(p_buf); -// } - return; -} - - - - - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bt_app_api.h" +#include "btm_ble_api.h" +//#include "btm_ble_int.h" + + + +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) +{ + if(adv_data != NULL) + { + ble_config_adv_data(adv_data, adv_data_cback); + }else{ + LOG_ERROR("The adv_data is NULL\n"); + } + + if(++adv_data != NULL) + { + ble_set_scan_rsp(adv_data, NULL); + } + +} + + +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) +{ + if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || + !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) + { + LOG_ERROR("Invalid advertisting interval parameters.\n"); + return ; + } + + if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) && + (ble_adv_params->adv_type > API_BROADCASTER_MODE) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) && + (ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + LOG_ERROR("API_Ble_AppStartAdvertising\n"); + + /// + BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, + ble_adv_params->adv_int_max, + ble_adv_params->adv_type, + ble_adv_params->addr_type_own, + ble_adv_params->channel_map, + ble_adv_params->adv_filter_policy, + ble_adv_params->p_dir_bda); + + +} + + +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback) +{ + if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && + API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && + (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) + { + BTA_DmSetBleScanFilterParams(client_if, + scan_params->scan_intv, + scan_params->scan_win, + scan_params->scan_type, + scan_params->scan_fil_policy, + scan_params->addr_type_own, + scan_param_setup_cback); + } +} + + +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) +{ + if((duration != 0) && (results_cb != NULL)) + { + ///Start scan the device + BTA_DmBleObserve(true, duration, results_cb); + }else{ + LOG_ERROR("The scan duration or p_results_cb invalid\n"); + } +} + + +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ +void esp_ble_stop_advertising (void) +{ + bool stop_adv = false; + + BTA_DmBleBroadcast(stop_adv); +} + + +/******************************************************************************* +** +** @function esp_ble_update_conn_params +** +** @brief Update connection parameters, can only be used when connection is up. +** +** @param[in] bd_addr - BD address of the peer +** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] +** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] +** @param[in] latency - slave latency [0 ~ 500] +** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] +** +** @return None +** +*******************************************************************************/ +void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, + uint16_t max_int, uint16_t latency, uint16_t timeout) +{ + if (min_int > max_int){ + min_int = max_int; + } + + if (min_int < BTM_BLE_CONN_INT_MIN || max_int > BTM_BLE_CONN_INT_MAX){ + LOG_ERROR("Invalid interval value.\n"); + } + + BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int, + latency, timeout); + +} + + + +/******************************************************************************* +** +** @function esp_ble_set_pkt_data_len +** +** @brief This function is to set maximum LE data packet size +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length) +{ + if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ + tx_data_length = BTM_BLE_DATA_SIZE_MAX; + }else if (tx_data_length < BTM_BLE_DATA_SIZE_MIN){ + tx_data_length = BTM_BLE_DATA_SIZE_MIN; + } + + BTA_DmBleSetDataLength(remote_device, tx_data_length); +} + + + +/******************************************************************************* +** +** @function esp_ble_set_rand_addr +** +** @brief This function set the random address for the appliction +** +** @param[in] rand_addr: the random address whith should be setting +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_rand_addr (BD_ADDR rand_addr) +{ + if (rand_addr != NULL){ + BTA_DmSetRandAddress(rand_addr); + }else{ + LOG_ERROR("Invalid randrom address.\n"); + } +} + + +/******************************************************************************* +** +** @function esp_ble_config_local_privacy +** +** @brief Enable/disable privacy on the local device +** +** @param[in] privacy_enable - enable/disabe privacy on remote device. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_local_privacy (BOOLEAN privacy_enable) +{ + BTA_DmBleConfigLocalPrivacy(privacy_enable); +} + + +/******************************************************************************* +** @function esp_gattc_disable +** @brief This function is called by application to disable GATTC module +** +** @param NULL +** +** @return None. +** +*******************************************************************************/ +void esp_gattc_disable(void) +{ + // TODO: This API funciton didn't finish, will be added it in future +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_app_register +** +** @brief This function is called to register application callbacks +** with GATTC module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] client_cb - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb) +{ + if (app_uuid != NULL) + { + BTA_GATTC_AppRegister(app_uuid, client_cb); + }else{ + LOG_ERROR("The app uuid invalid.\n"); + } +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_app_unregister +** +** @brief This function is called to unregister an application +** from GATTC module. +** +** @param[in] client_if - client interface identifier. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if) +{ + BTA_GATTC_AppDeregister(client_if); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_conn +** +** @brief Open a direct connection or add a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE; + if(remote_bda == NULL ){ + LOG_ERROR("Invaild address data \n"); + return; + } + + BTA_GATTC_Open(client_if, remote_bda, is_direct, transport); + + + + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + if(remote_bda == NULL ){ + LOG_ERROR("Invaild address data \n"); + return; + } + + BTA_GATTC_CancelOpen(client_if, remote_bda, is_direct); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_close +** +** @brief Close a connection to a GATT server. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_close (uint16_t conn_id) +{ + BTA_GATTC_Close(conn_id); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_config_mtu +** +** @brief Configure the MTU size in the GATT channel. This can be done +** only once per connection. +** +** @param[in] conn_id: connection ID. +** mtu: desired MTU size to use. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu) +{ + if ((mtu < GATT_DEF_BLE_MTU_SIZE) || (mtu > GATT_MAX_MTU_SIZE)){ + LOG_ERROR("Invalid MTU parameters\n"); + return ESP_GATT_ILLEGAL_PARAMETER; + } + + BTA_GATTC_ConfigureMTU (conn_id, mtu); + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_svc_search_req +** +** @brief This function is called to request a GATT service discovery +** on a GATT server. This function report service search result +** by a callback event, and followed by a service search complete +** event. +** +** @param[in] conn_id: connection ID. +** @param[in] srvc_uuid: a UUID of the service application is interested in. +** If Null, discover for all services. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid) +{ + BTA_GATTC_ServiceSearchRequest(conn_id, srvc_uuid); +} + + +/**************************************************************************************************** +** +** @function esp_ble_gattc_get_first_char +** +** @brief This function is called to find the first characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. +** +*****************************************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property) +{ + esp_gatt_status_t status = 0; + + if (!srvc_id || !char_result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstChar (conn_id, srvc_id, char_uuid_cond, + char_result, property); + + return status; + + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_char_descr +** +** @brief This function is called to find the first characteristic descriptor of the +** characteristic on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. +** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available +** characteristic. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result) +{ + esp_gatt_status_t status; + + if (!char_id || !descr_result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstCharDescr (conn_id, char_id, descr_uuid_cond, descr_result); + + return status; + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char +** +** @brief This function is called to find the next characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_char_id: start the characteristic search from the next record +** after the one identified by char_id. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. +** +*******************************************************************************/ + +esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, + esp_gattc_char_id_t *start_char_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property) +{ + + esp_gatt_status_t status; + + if (!start_char_id || !char_result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextChar(conn_id, start_char_id, char_uuid_cond, + char_result, property); + + return status; + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char_descr +** +** @brief This function is called to find the next characteristic descriptor +** of the characterisctic. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_descr_id: start the descriptor search from the next record +** after the one identified by p_start_descr_id. +** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find +** the first available characteristic descriptor. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. +** +*******************************************************************************/ + +esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *start_descr_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result) +{ + esp_gatt_status_t status; + + if (!start_descr_id || !descr_result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextCharDescr (conn_id, start_descr_id, descr_uuid_cond, descr_result); + + return status; + +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_inclu_srvc +** +** @brief This function is called to find the first included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result) +{ + + esp_gatt_status_t status; + + if (!srvc_id || !result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetFirstIncludedService(conn_id, srvc_id, uuid_cond, result); + + return status; +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_inclu_srvc +** +** @brief This function is called to find the next included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_id: start the search from the next record +** after the one identified by p_start_id. +** @param[in] uuid_cond: Included service UUID, if NULL find the first available +** included service. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. + +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, + esp_gattc_incl_srvc_id_t *start_id, + esp_bt_uuid_t *uuid_cond, + esp_gattc_incl_srvc_id_t *result) +{ + esp_gatt_status_t status; + + if (!start_id || !result){ + return ESP_GATT_ILLEGAL_PARAMETER; + } + + status = BTA_GATTC_GetNextIncludedService(conn_id, start_id, uuid_cond, result); + + return status; +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char +** +** @brief This function is called to read a service's characteristics of +** the given characteritisc ID. +** +** @param[in] conn_id - connectino ID. +** @param[in] char_id - characteritic ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_ReadCharacteristic(conn_id, char_id, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char_descr +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] conn_id - connection ID. +** @param[in] descr_id - characteritic descriptor ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *descr_id, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_ReadCharDescr (conn_id, descr_id, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_multi +** +** @brief This function is called to read multiple characteristic or +** characteristic descriptors. +** +** @param[in] conn_id - connectino ID. +** @param[in] read_multi - pointer to the read multiple parameter. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_ReadMultiple(conn_id, read_multi, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_val +** +** @brief This function is called to write characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to write. +** @param[in] write_type - type of write. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_val ( uint16_t conn_id, + esp_gattc_char_id_t *char_id, + esp_gattc_write_type_t write_type, + uint16_t len, + uint8_t *value, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_WriteCharValue (conn_id, char_id, write_type, len, value, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_descr +** +** @brief This function is called to write characteristic descriptor value. +** +** @param[in] conn_id - connection ID +** @param[in] char_descr_id - characteristic descriptor ID to write. +** @param[in] write_type - write type. +** @param[in] data - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *char_descr_id, + esp_gattc_write_type_t write_type, + esp_gatt_unfmt_t *data, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_WriteCharDescr (conn_id, char_descr_id, write_type, data, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_prepa_write +** +** @brief This function is called to prepare write a characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - GATT characteritic ID of the service. +** @param[in] offset - offset of the write value. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, + uint16_t offset, uint16_t len, uint8_t *value, + esp_gatt_auth_req_t auth_req) +{ + BTA_GATTC_PrepareWrite (conn_id, char_id, offset, len, value, auth_req); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_execu_write +** +** @brief This function is called to execute write a prepare write sequence. +** +** @param[in] conn_id - connection ID. +** @param[in] is_execute - execute or cancel. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute) +{ + BTA_GATTC_ExecuteWrite (conn_id, is_execute); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_send_ind_cfm +** +** @brief This function is called to send handle value confirmation. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to confirm. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id) +{ + BTA_GATTC_SendIndConfirm (conn_id, char_id); +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_register_ntf +** +** @brief This function is called to register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if registration succeed, otherwise failed. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, + BD_ADDR bda, + esp_gattc_char_id_t *char_id) +{ + esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; + status = BTA_GATTC_RegisterForNotifications (client_if, bda, char_id); + + return status; +} + + +/******************************************************************************* +** +** @function esp_ble_gattc_unregister_ntf +** +** @brief This function is called to de-register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if deregistration succeed, otherwise failed. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, + BD_ADDR bda, + esp_gattc_char_id_t *char_id) +{ + esp_gatt_status_t status = ESP_GATT_ILLEGAL_PARAMETER; + status = BTA_GATTC_DeregisterForNotifications (client_if, bda, char_id); + + return status; +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_disale +** +** @brief This function is called to disable GATTS module +** +** @param[in] None. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_disale(void) +{ + BTA_GATTS_Disable(); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback) +{ + BTA_GATTS_AppRegister(app_uuid, cback); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_app_unregister +** +** @brief un-register with GATT Server. +** +** @param[in] server_if: service interface id. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if) +{ + BTA_GATTS_AppDeregister(server_if); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_create_srvc +** +** @brief Create a service. When service creation is done, a callback +** event BTA_GATTS_CREATE_SRVC_EVT is called to report status +** and service ID to the profile. The service ID obtained in +** the callback function needs to be used when adding included +** service and characteristics/descriptors into the service. +** +** @param[in] server_if: Profile ID this service is belonged to. +** @param[in] service_uuid: service UUID. +** @param[in] inst: instance ID number of this service. +** @param[in] num_handle: numble of handle requessted for this service. +** @param[in] is_primary: is this service a primary one or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, + uint16_t num_handle, BOOLEAN is_primary) +{ + BTA_GATTS_CreateService(server_if, service_uuid, inst, num_handle, is_primary); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_inclu_srvc +** +** @brief This function is called to add an included service. After included +** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT +** is reported the included service ID. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] included_service_id: the service ID to be included. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id) +{ + BTA_GATTS_AddIncludeService(service_id, included_service_id); +} + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char +** +** @brief This function is called to add a characteristic into a service. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] char_uuid : Characteristic UUID. +** @param[in] perm : Characteristic value declaration attribute permission. +** @param[in] property : Characteristic Properties +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, + esp_gatt_perm_t perm, esp_gatt_char_prop_t property) +{ + BTA_GATTS_AddCharacteristic (service_id, char_uuid, perm, property); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char_descr +** +** @brief This function is called to add characteristic descriptor. When +** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called +** to report the status and an ID number for this descriptor. +** +** @param[in] service_id: service ID to which this charatceristic descriptor is to +** be added. +** @param[in] perm: descriptor access permission. +** @param[in] descr_uuid: descriptor UUID. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char_descr (uint16_t service_id, + esp_gatt_perm_t perm, + esp_bt_uuid_t * descr_uuid) +{ + BTA_GATTS_AddCharDescriptor (service_id, perm, descr_uuid); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_dele_srvc +** +** @brief This function is called to delete a service. When this is done, +** a callback event BTA_GATTS_DELETE_EVT is report with the status. +** +** @param[in] service_id: service_id to be deleted. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_dele_srvc (uint16_t service_id) +{ + BTA_GATTS_DeleteService(service_id); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_start_srvc +** +** @brief This function is called to start a service. +** +** @param[in] service_id: the service ID to be started. +** @param[in] sup_transport: supported trasnport. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_start_srvc(uint16_t service_id) +{ + tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; + BTA_GATTS_StartService(service_id, transport); +} + +/******************************************************************************* +** +** @function esp_ble_gatts_stop_srvc +** +** @brief This function is called to stop a service. +** +** @param[in] service_id - service to be topped. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_stop_srvc(uint16_t service_id) +{ + BTA_GATTS_StopService(service_id); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_hdl_val_indica +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] bda - remote device bd address to indicate. +** @param[in] attr_id - attribute ID to indicate. +** @param[in] data_len - indicate data length. +** @param[in] data: data to indicate. +** @param[in] need_confirm - if this indication expects a confirmation or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, + uint8_t *data, BOOLEAN need_confirm) +{ + BTA_GATTS_HandleValueIndication (conn_id, attr_id, data_len, data, need_confirm); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_send_rsp +** +** @brief This function is called to send a response to a request. +** +** @param[in] conn_id - connection identifier. +** @param[in] trans_id - transaction ID. +** @param[in] status - response status +** @param[in] msg - response data. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, + esp_gatt_status_t status, esp_gatts_rsp_t *msg) +{ + BTA_GATTS_SendRsp (conn_id, trans_id, status, msg); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_conn +** +** @brief Open a direct open connection or add a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + tBTA_GATT_TRANSPORT transport = BT_TRANSPORT_LE; + BTA_GATTS_Open(server_if, remote_bda, is_direct, transport); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct) +{ + BTA_GATTS_CancelOpen(server_if, remote_bda, is_direct); +} + + +/******************************************************************************* +** +** @function esp_ble_gatts_close +** +** @param[in] Close a connection a remote device. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_close(uint16_t conn_id) +{ + BTA_GATTS_Close(conn_id); +} + + +/******************************************************************************* +** +** @function esp_prf_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] p_app_uuid - applicaiton UUID +** @param[in] p_cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_prf_app_register(uint8_t prf_id, void *p_cback) +{ + //tBTA_GATTS_API_REG *p_buf; + + /* register with BTA system manager */ + if (bt_prf_sys_is_register(PRF_ID_SYS) == FALSE) + { + bt_prf_sys_register(PRF_ID_SYS, NULL); + } + +// if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) +// { +// p_buf->hdr.event = BTA_GATTS_API_REG_EVT; + +// if (p_app_uuid != NULL) +// memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); +// p_buf->p_cback = p_cback; + +// bta_sys_sendmsg(p_buf); +// } + return; +} + + + + + diff --git a/components/bt/bluedroid/stack_api/bt_app_sec.c b/components/bt/bluedroid/stack_api/bt_app_sec.c index 7662e6e68..fa4831650 100644 --- a/components/bt/bluedroid/stack_api/bt_app_sec.c +++ b/components/bt/bluedroid/stack_api/bt_app_sec.c @@ -1,108 +1,108 @@ -/** - **************************************************************************************** - * - * @file bt_app_sec.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ - -#include "bt_app_sec.h" -#include // standard library -#include - - - -extern void srand (unsigned int seed); -extern int random (void); - -/// Application Security Environment Structure -tAPP_SEC_ENV app_sec_env; - - -/******************************************************************************* -** -** Function app_ble_sec_gen_tk -** -** Description This function is called to generate the ble tk -** -** Returns the generate tk value -** -*******************************************************************************/ -UINT32 app_ble_sec_gen_tk(void) -{ - // Generate a PIN Code (Between 100000 and 999999) - return (100000 + (random()%900000)); -} - -/******************************************************************************* -** -** Function app_ble_sec_gen_ltk -** -** Description This function is called to generate the ble ltk -** -** Returns NULL -** -*******************************************************************************/ -void app_ble_sec_gen_ltk(UINT8 key_size) -{ - // Counter - UINT8 i; - app_sec_env.key_size = key_size; - - // Randomly generate the LTK and the Random Number - for (i = 0; i < RAND_NB_LEN; i++) - { - app_sec_env.rand_nb.nb[i] = random()%256; - } - - // Randomly generate the end of the LTK - for (i = 0; i < SEC_KEY_LEN; i++) - { - app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256); - } - - // Randomly generate the EDIV - app_sec_env.ediv = random()%65536; -} - - -/******************************************************************************* -** -** Function app_ble_sec_init -** -** Description This function is init the security env and function -** -** Returns NULL -** -*******************************************************************************/ -void app_ble_sec_init() -{ - // Reset Security Environment - memset(&app_sec_env, 0, sizeof(app_sec_env)); -} - - -/******************************************************************************* -** -** Function app_ble_security_start -** -** Description This function is called by the slave when the seurity start -** -** Returns NULL -** -*******************************************************************************/ -void app_ble_security_start(void) -{ - -} - - - - - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bt_app_sec.h" +#include // standard library +#include + + + +extern void srand (unsigned int seed); +extern int random (void); + +/// Application Security Environment Structure +tAPP_SEC_ENV app_sec_env; + + +/******************************************************************************* +** +** Function app_ble_sec_gen_tk +** +** Description This function is called to generate the ble tk +** +** Returns the generate tk value +** +*******************************************************************************/ +UINT32 app_ble_sec_gen_tk(void) +{ + // Generate a PIN Code (Between 100000 and 999999) + return (100000 + (random()%900000)); +} + +/******************************************************************************* +** +** Function app_ble_sec_gen_ltk +** +** Description This function is called to generate the ble ltk +** +** Returns NULL +** +*******************************************************************************/ +void app_ble_sec_gen_ltk(UINT8 key_size) +{ + // Counter + UINT8 i; + app_sec_env.key_size = key_size; + + // Randomly generate the LTK and the Random Number + for (i = 0; i < RAND_NB_LEN; i++) + { + app_sec_env.rand_nb.nb[i] = random()%256; + } + + // Randomly generate the end of the LTK + for (i = 0; i < SEC_KEY_LEN; i++) + { + app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256); + } + + // Randomly generate the EDIV + app_sec_env.ediv = random()%65536; +} + + +/******************************************************************************* +** +** Function app_ble_sec_init +** +** Description This function is init the security env and function +** +** Returns NULL +** +*******************************************************************************/ +void app_ble_sec_init() +{ + // Reset Security Environment + memset(&app_sec_env, 0, sizeof(app_sec_env)); +} + + +/******************************************************************************* +** +** Function app_ble_security_start +** +** Description This function is called by the slave when the seurity start +** +** Returns NULL +** +*******************************************************************************/ +void app_ble_security_start(void) +{ + +} + + + + + diff --git a/components/bt/bluedroid/stack_api/bt_gap_api.c b/components/bt/bluedroid/stack_api/bt_gap_api.c index 47ab0730b..65feb289b 100644 --- a/components/bt/bluedroid/stack_api/bt_gap_api.c +++ b/components/bt/bluedroid/stack_api/bt_gap_api.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "bt_gap_api.h" #include "bta_api.h" #include "bt_trace.h" diff --git a/components/bt/bluedroid/stack_api/bt_sdp_api.c b/components/bt/bluedroid/stack_api/bt_sdp_api.c index 6cee6650d..66330bb29 100644 --- a/components/bt/bluedroid/stack_api/bt_sdp_api.c +++ b/components/bt/bluedroid/stack_api/bt_sdp_api.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "bt_sdp_api.h" diff --git a/components/bt/bluedroid/stack_api/include/bt_app_api.h b/components/bt/bluedroid/stack_api/include/bt_app_api.h index dfc2335b4..fc557e3aa 100644 --- a/components/bt/bluedroid/stack_api/include/bt_app_api.h +++ b/components/bt/bluedroid/stack_api/include/bt_app_api.h @@ -1,924 +1,924 @@ -/** - **************************************************************************************** - * - * @file bt_app_api.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ - -#include "bt_types.h" -#include "bt_app_defs.h" -#include "bta_gatt_api.h" -#include "bt_prf_sys.h" - - -/******************************************************************************* -** -** @function esp_ble_config_adv_data -** -** @brief This function is called to override the BTA default ADV parameters. -** -** @param[in] adv_data: Pointer to User defined ADV data structure. This -** memory space can not be freed until p_adv_data_cback -** is received. -** @param[in|out] adv_data_cback: set adv data complete callback. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, - esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback); - - - -/******************************************************************************* -** -** @function esp_ble_set_scan_params -** -** @brief This function is called to set scan parameters -** -** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This -** memory space can not be freed until scan_param_setup_cback -** @param[in] client_if: Client interface ID -** @param[in|out] scan_param_setup_status_cback - Set scan param status callback -** -** @return None -** -*******************************************************************************/ -void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, - esp_scan_param_setup_cb_t scan_param_setup_cback); - - -/******************************************************************************* -** -** @function esp_ble_start_scanning -** -** @brief This procedure keep the device scanning the peer device whith advertising on the air -** -** @param[in] duration: Keeping the scaning time, the unit is second. -** @param[in|out] results_cb: The scanning function callback when the peer device has been scan -** which advertising on the air -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb); - - - -/******************************************************************************* -** -** @function esp_ble_start_advertising -** -** @brief This function is called to start advertising. -** -** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params); - - - -/******************************************************************************* -** -** @function esp_ble_stop_advertising -** -** @brief This function is called to stop advertising. -** -** @param None -** -** @return None -** -*******************************************************************************/ -void esp_ble_stop_advertising (void); - - - -/******************************************************************************* -** -** @function esp_ble_update_conn_params -** -** @brief Update connection parameters, can only be used when connection is up. -** -** @param[in] bd_addr - BD address of the peer -** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] -** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] -** @param[in] latency - slave latency [0 ~ 500] -** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] -** -** @return None -** -*******************************************************************************/ -void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, - uint16_t max_int, uint16_t latency, uint16_t timeout); - - -/******************************************************************************* -** -** @function esp_ble_set_pkt_data_len -** -** @brief This function is to set maximum LE data packet size -** -** @return None -** -** -*******************************************************************************/ -void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length); - - - -/******************************************************************************* -** -** @function esp_ble_set_rand_addr -** -** @brief This function set the random address for the appliction -** -** @param[in] rand_addr: the random address whith should be setting -** -** @return None -** -** -*******************************************************************************/ -void esp_ble_set_rand_addr (BD_ADDR rand_addr); - - - -/******************************************************************************* -** -** @function esp_ble_config_local_privacy -** -** @brief Enable/disable privacy on the local device -** -** @param[in] privacy_enable - enable/disabe privacy on remote device. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_local_privacy (BOOLEAN privacy_enable); - - - -/******************************************************************************* -** @function esp_gattc_disable -** @brief This function is called by application to disable GATTC module -** -** @param NULL -** -** @return None. -** -*******************************************************************************/ -void esp_gattc_disable(void); - - -/******************************************************************************* -** -** @function esp_ble_gattc_app_register -** -** @brief This function is called to register application callbacks -** with GATTC module. -** -** @param[in] app_uuid - applicaiton UUID -** @param[in] client_cb - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb); - - -/******************************************************************************* -** -** @function esp_ble_gattc_app_unregister -** -** @brief This function is called to unregister an application -** from GATTC module. -** -** @param[in] client_if - client interface identifier. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if); - - -/******************************************************************************* -** -** @function esp_ble_gattc_conn -** -** @brief Open a direct connection or add a background auto connection -** bd address -** -** @param[in] client_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_cancel_conn -** -** @brief Cancel a direct open connection or remove a background auto connection -** bd address -** -** @param[in] client_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); - - -/******************************************************************************* -** -** @function esp_ble_gattc_close -** -** @brief Close a connection to a GATT server. -** -** @param[in] conn_id: connectino ID to be closed. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_close (uint16_t conn_id); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_config_mtu -** -** @brief Configure the MTU size in the GATT channel. This can be done -** only once per connection. -** -** @param[in] conn_id: connection ID. -** mtu: desired MTU size to use. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu); - - -/******************************************************************************* -** -** @function esp_ble_gattc_svc_search_req -** -** @brief This function is called to request a GATT service discovery -** on a GATT server. This function report service search result -** by a callback event, and followed by a service search complete -** event. -** -** @param[in] conn_id: connection ID. -** @param[in] srvc_uuid: a UUID of the service application is interested in. -** If Null, discover for all services. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid); - - -/**************************************************************************************************** -** -** @function esp_ble_gattc_get_first_char -** -** @brief This function is called to find the first characteristic of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] srvc_id: the service ID of which the characteristic is belonged to. -** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] char_result: output parameter which will store the GATT -** characteristic ID. -** @param[in] property: output parameter to carry the characteristic property. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. -** -*****************************************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, - esp_bt_uuid_t *char_uuid_cond, - esp_gattc_char_id_t *char_result, - esp_gatt_char_prop_t *property); - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_first_char_descr -** -** @brief This function is called to find the first characteristic descriptor of the -** characteristic on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. -** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available -** characteristic. -** @param[in] descr_result: output parameter which will store the GATT -** characteristic descriptor ID. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, - esp_bt_uuid_t *descr_uuid_cond, - esp_gattc_char_descr_id_t *descr_result); - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_inclu_srvc -** -** @brief This function is called to find the next included service of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_id: start the search from the next record -** after the one identified by p_start_id. -** @param[in] uuid_cond: Included service UUID, if NULL find the first available -** included service. -** @param[in] result: output parameter which will store the GATT ID -** of the included service found. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. - -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, - esp_gattc_incl_srvc_id_t *start_id, - esp_bt_uuid_t *uuid_cond, - esp_gattc_incl_srvc_id_t *result); - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_char -** -** @brief This function is called to find the next characteristic of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_char_id: start the characteristic search from the next record -** after the one identified by char_id. -** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] char_result: output parameter which will store the GATT -** characteristic ID. -** @param[in] property: output parameter to carry the characteristic property. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, - esp_gattc_char_id_t *start_char_id, - esp_bt_uuid_t *char_uuid_cond, - esp_gattc_char_id_t *char_result, - esp_gatt_char_prop_t *property); - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_next_char_descr -** -** @brief This function is called to find the next characteristic descriptor -** of the characterisctic. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] start_descr_id: start the descriptor search from the next record -** after the one identified by p_start_descr_id. -** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find -** the first available characteristic descriptor. -** @param[in] descr_result: output parameter which will store the GATT -** characteristic descriptor ID. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *start_descr_id, - esp_bt_uuid_t *descr_uuid_cond, - esp_gattc_char_descr_id_t *descr_result); - - -/******************************************************************************* -** -** @function esp_ble_gattc_get_first_inclu_srvc -** -** @brief This function is called to find the first included service of the -** service on the given server. -** -** @param[in] conn_id: connection ID which identify the server. -** @param[in] srvc_id: the service ID of which the characteristic is belonged to. -** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** @param[in] result: output parameter which will store the GATT ID -** of the included service found. -** -** @return Command status code: -** - @ref ESP_GATT_OK: If request succeeds -** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, - esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result); - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_char -** -** @brief This function is called to read a service's characteristics of -** the given characteritisc ID. -** -** @param[in] conn_id - connectino ID. -** @param[in] char_id - characteritic ID to read. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, - esp_gatt_auth_req_t auth_req); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_char_descr -** -** @brief This function is called to read a characteristics descriptor. -** -** @param[in] conn_id - connection ID. -** @param[in] descr_id - characteritic descriptor ID to read. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *descr_id, - esp_gatt_auth_req_t auth_req); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_read_multi -** -** @brief This function is called to read multiple characteristic or -** characteristic descriptors. -** -** @param[in] conn_id - connectino ID. -** @param[in] read_multi - pointer to the read multiple parameter. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, - esp_gatt_auth_req_t auth_req); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_write_char_val -** -** @brief This function is called to write characteristic value. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - characteristic ID to write. -** @param[in] write_type - type of write. -** @param[in] len: length of the data to be written. -** @param[in] value - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_write_char_val ( uint16_t conn_id, - esp_gattc_char_id_t *char_id, - esp_gattc_write_type_t write_type, - uint16_t len, - uint8_t *value, - esp_gatt_auth_req_t auth_req); - - -/******************************************************************************* -** -** @function esp_ble_gattc_write_char_descr -** -** @brief This function is called to write characteristic descriptor value. -** -** @param[in] conn_id - connection ID -** @param[in] char_descr_id - characteristic descriptor ID to write. -** @param[in] write_type - write type. -** @param[in] data - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_write_char_descr (uint16_t conn_id, - esp_gattc_char_descr_id_t *char_descr_id, - esp_gattc_write_type_t write_type, - esp_gatt_unfmt_t *data, - esp_gatt_auth_req_t auth_req); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_prepa_write -** -** @brief This function is called to prepare write a characteristic value. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - GATT characteritic ID of the service. -** @param[in] offset - offset of the write value. -** @param[in] len: length of the data to be written. -** @param[in] value - the value to be written. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, - uint16_t offset, uint16_t len, uint8_t *value, - esp_gatt_auth_req_t auth_req); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_execu_write -** -** @brief This function is called to execute write a prepare write sequence. -** -** @param[in] conn_id - connection ID. -** @param[in] is_execute - execute or cancel. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_send_ind_cfm -** -** @brief This function is called to send handle value confirmation. -** -** @param[in] conn_id - connection ID. -** @param[in] char_id - characteristic ID to confirm. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id); - - - - -/******************************************************************************* -** -** @function esp_ble_gattc_register_ntf -** -** @brief This function is called to register for notification of a service. -** -** @param[in] client_if - client interface. -** @param[in] bda - target GATT server. -** @param[in] char_id - pointer to GATT characteristic ID. -** -** @return OK if registration succeed, otherwise failed. -** -*******************************************************************************/ -esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, - BD_ADDR bda, - esp_gattc_char_id_t *char_id); - - - -/******************************************************************************* -** -** @function esp_ble_gattc_unregister_ntf -** -** @brief This function is called to de-register for notification of a service. -** -** @param[in] client_if - client interface. -** @param[in] bda - target GATT server. -** @param[in] char_id - pointer to GATT characteristic ID. -** -** @return OK if deregistration succeed, otherwise failed. -** -*******************************************************************************/ -tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, - BD_ADDR bda, - esp_gattc_char_id_t *char_id); - - -/******************************************************************************* -** -** @function esp_ble_gatts_disale -** -** @brief This function is called to disable GATTS module -** -** @param[in] None. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_disale(void); - - - - -/******************************************************************************* -** -** @function esp_ble_gatts_app_register -** -** @brief This function is called to register application callbacks -** with BTA GATTS module. -** -** @param[in] app_uuid - applicaiton UUID -** @param[in] cback - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_app_unregister -** -** @brief un-register with GATT Server. -** -** @param[in] server_if: service interface id. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_create_srvc -** -** @brief Create a service. When service creation is done, a callback -** event BTA_GATTS_CREATE_SRVC_EVT is called to report status -** and service ID to the profile. The service ID obtained in -** the callback function needs to be used when adding included -** service and characteristics/descriptors into the service. -** -** @param[in] server_if: Profile ID this service is belonged to. -** @param[in] service_uuid: service UUID. -** @param[in] inst: instance ID number of this service. -** @param[in] num_handle: numble of handle requessted for this service. -** @param[in] is_primary: is this service a primary one or not. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, - uint16_t num_handle, BOOLEAN is_primary); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_add_inclu_srvc -** -** @brief This function is called to add an included service. After included -** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT -** is reported the included service ID. -** -** @param[in] service_id: service ID to which this included service is to -** be added. -** @param[in] included_service_id: the service ID to be included. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_add_char -** -** @brief This function is called to add a characteristic into a service. -** -** @param[in] service_id: service ID to which this included service is to -** be added. -** @param[in] char_uuid : Characteristic UUID. -** @param[in] perm : Characteristic value declaration attribute permission. -** @param[in] property : Characteristic Properties -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, - esp_gatt_perm_t perm, esp_gatt_char_prop_t property); - - - - -/******************************************************************************* -** -** @function esp_ble_gatts_add_char_descr -** -** @brief This function is called to add characteristic descriptor. When -** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called -** to report the status and an ID number for this descriptor. -** -** @param[in] service_id: service ID to which this charatceristic descriptor is to -** be added. -** @param[in] perm: descriptor access permission. -** @param[in] descr_uuid: descriptor UUID. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_add_char_descr (uint16_t service_id, - esp_gatt_perm_t perm, - esp_bt_uuid_t * descr_uuid); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_dele_srvc -** -** @brief This function is called to delete a service. When this is done, -** a callback event BTA_GATTS_DELETE_EVT is report with the status. -** -** @param[in] service_id: service_id to be deleted. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_dele_srvc (uint16_t service_id); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_start_srvc -** -** @brief This function is called to start a service. -** -** @param[in] service_id: the service ID to be started. -** @param[in] sup_transport: supported trasnport. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_start_srvc(uint16_t service_id); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_stop_srvc -** -** @brief This function is called to stop a service. -** -** @param[in] service_id - service to be topped. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_stop_srvc(uint16_t service_id); - - - -/******************************************************************************* -** -** @function esp_ble_gatts_hdl_val_indica -** -** @brief This function is called to read a characteristics descriptor. -** -** @param[in] bda - remote device bd address to indicate. -** @param[in] attr_id - attribute ID to indicate. -** @param[in] data_len - indicate data length. -** @param[in] data: data to indicate. -** @param[in] need_confirm - if this indication expects a confirmation or not. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, - uint8_t *data, BOOLEAN need_confirm); - - -/******************************************************************************* -** -** @function esp_ble_gatts_send_rsp -** -** @brief This function is called to send a response to a request. -** -** @param[in] conn_id - connection identifier. -** @param[in] trans_id - transaction ID. -** @param[in] status - response status -** @param[in] msg - response data. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, - esp_gatt_status_t status, esp_gatts_rsp_t *msg); - - -/******************************************************************************* -** -** @function esp_ble_gatts_conn -** -** @brief Open a direct open connection or add a background auto connection -** bd address -** -** @param[in] server_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); - - -/******************************************************************************* -** -** @function esp_ble_gatts_cancel_conn -** -** @brief Cancel a direct open connection or remove a background auto connection -** bd address -** -** @param[in] server_if: server interface. -** @param[in] remote_bda: remote device BD address. -** @param[in] is_direct: direct connection or background auto connection -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); - - -/******************************************************************************* -** -** @function esp_ble_gatts_close -** -** @brief Close a connection a remote device. -** -** @param[in] conn_id: connectino ID to be closed. -** -** @return None -** -*******************************************************************************/ -void esp_ble_gatts_close(uint16_t conn_id); - - -/******************************************************************************* -** -** @function esp_prf_app_register -** -** @brief This function is called to register application callbacks -** with BTA GATTS module. -** -** @param[in] prf_id - the profile identification -** @param[in] p_cback - pointer to the application callback function. -** -** @return None -** -*******************************************************************************/ -void esp_prf_app_register(uint8_t prf_id, void *p_cback); - - - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bt_types.h" +#include "bt_app_defs.h" +#include "bta_gatt_api.h" +#include "bt_prf_sys.h" + + +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback); + + + +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback); + + +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb); + + + +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params); + + + +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ +void esp_ble_stop_advertising (void); + + + +/******************************************************************************* +** +** @function esp_ble_update_conn_params +** +** @brief Update connection parameters, can only be used when connection is up. +** +** @param[in] bd_addr - BD address of the peer +** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000] +** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000] +** @param[in] latency - slave latency [0 ~ 500] +** @param[in] timeout - supervision timeout [0x000a ~ 0xc80] +** +** @return None +** +*******************************************************************************/ +void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int, + uint16_t max_int, uint16_t latency, uint16_t timeout); + + +/******************************************************************************* +** +** @function esp_ble_set_pkt_data_len +** +** @brief This function is to set maximum LE data packet size +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length); + + + +/******************************************************************************* +** +** @function esp_ble_set_rand_addr +** +** @brief This function set the random address for the appliction +** +** @param[in] rand_addr: the random address whith should be setting +** +** @return None +** +** +*******************************************************************************/ +void esp_ble_set_rand_addr (BD_ADDR rand_addr); + + + +/******************************************************************************* +** +** @function esp_ble_config_local_privacy +** +** @brief Enable/disable privacy on the local device +** +** @param[in] privacy_enable - enable/disabe privacy on remote device. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_local_privacy (BOOLEAN privacy_enable); + + + +/******************************************************************************* +** @function esp_gattc_disable +** @brief This function is called by application to disable GATTC module +** +** @param NULL +** +** @return None. +** +*******************************************************************************/ +void esp_gattc_disable(void); + + +/******************************************************************************* +** +** @function esp_ble_gattc_app_register +** +** @brief This function is called to register application callbacks +** with GATTC module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] client_cb - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb); + + +/******************************************************************************* +** +** @function esp_ble_gattc_app_unregister +** +** @brief This function is called to unregister an application +** from GATTC module. +** +** @param[in] client_if - client interface identifier. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if); + + +/******************************************************************************* +** +** @function esp_ble_gattc_conn +** +** @brief Open a direct connection or add a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] client_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gattc_close +** +** @brief Close a connection to a GATT server. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_close (uint16_t conn_id); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_config_mtu +** +** @brief Configure the MTU size in the GATT channel. This can be done +** only once per connection. +** +** @param[in] conn_id: connection ID. +** mtu: desired MTU size to use. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu); + + +/******************************************************************************* +** +** @function esp_ble_gattc_svc_search_req +** +** @brief This function is called to request a GATT service discovery +** on a GATT server. This function report service search result +** by a callback event, and followed by a service search complete +** event. +** +** @param[in] conn_id: connection ID. +** @param[in] srvc_uuid: a UUID of the service application is interested in. +** If Null, discover for all services. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid); + + +/**************************************************************************************************** +** +** @function esp_ble_gattc_get_first_char +** +** @brief This function is called to find the first characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL. +** +*****************************************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_char_descr +** +** @brief This function is called to find the first characteristic descriptor of the +** characteristic on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] char_id: the characteristic ID of which the descriptor is belonged to. +** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available +** characteristic. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_inclu_srvc +** +** @brief This function is called to find the next included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_id: start the search from the next record +** after the one identified by p_start_id. +** @param[in] uuid_cond: Included service UUID, if NULL find the first available +** included service. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL. + +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id, + esp_gattc_incl_srvc_id_t *start_id, + esp_bt_uuid_t *uuid_cond, + esp_gattc_incl_srvc_id_t *result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char +** +** @brief This function is called to find the next characteristic of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_char_id: start the characteristic search from the next record +** after the one identified by char_id. +** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] char_result: output parameter which will store the GATT +** characteristic ID. +** @param[in] property: output parameter to carry the characteristic property. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id, + esp_gattc_char_id_t *start_char_id, + esp_bt_uuid_t *char_uuid_cond, + esp_gattc_char_id_t *char_result, + esp_gatt_char_prop_t *property); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_next_char_descr +** +** @brief This function is called to find the next characteristic descriptor +** of the characterisctic. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] start_descr_id: start the descriptor search from the next record +** after the one identified by p_start_descr_id. +** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find +** the first available characteristic descriptor. +** @param[in] descr_result: output parameter which will store the GATT +** characteristic descriptor ID. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *start_descr_id, + esp_bt_uuid_t *descr_uuid_cond, + esp_gattc_char_descr_id_t *descr_result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_get_first_inclu_srvc +** +** @brief This function is called to find the first included service of the +** service on the given server. +** +** @param[in] conn_id: connection ID which identify the server. +** @param[in] srvc_id: the service ID of which the characteristic is belonged to. +** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available +** characteristic. +** @param[in] result: output parameter which will store the GATT ID +** of the included service found. +** +** @return Command status code: +** - @ref ESP_GATT_OK: If request succeeds +** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id, + esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result); + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char +** +** @brief This function is called to read a service's characteristics of +** the given characteritisc ID. +** +** @param[in] conn_id - connectino ID. +** @param[in] char_id - characteritic ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_char_descr +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] conn_id - connection ID. +** @param[in] descr_id - characteritic descriptor ID to read. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *descr_id, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_read_multi +** +** @brief This function is called to read multiple characteristic or +** characteristic descriptors. +** +** @param[in] conn_id - connectino ID. +** @param[in] read_multi - pointer to the read multiple parameter. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_val +** +** @brief This function is called to write characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to write. +** @param[in] write_type - type of write. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_val ( uint16_t conn_id, + esp_gattc_char_id_t *char_id, + esp_gattc_write_type_t write_type, + uint16_t len, + uint8_t *value, + esp_gatt_auth_req_t auth_req); + + +/******************************************************************************* +** +** @function esp_ble_gattc_write_char_descr +** +** @brief This function is called to write characteristic descriptor value. +** +** @param[in] conn_id - connection ID +** @param[in] char_descr_id - characteristic descriptor ID to write. +** @param[in] write_type - write type. +** @param[in] data - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_write_char_descr (uint16_t conn_id, + esp_gattc_char_descr_id_t *char_descr_id, + esp_gattc_write_type_t write_type, + esp_gatt_unfmt_t *data, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_prepa_write +** +** @brief This function is called to prepare write a characteristic value. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - GATT characteritic ID of the service. +** @param[in] offset - offset of the write value. +** @param[in] len: length of the data to be written. +** @param[in] value - the value to be written. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id, + uint16_t offset, uint16_t len, uint8_t *value, + esp_gatt_auth_req_t auth_req); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_execu_write +** +** @brief This function is called to execute write a prepare write sequence. +** +** @param[in] conn_id - connection ID. +** @param[in] is_execute - execute or cancel. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_send_ind_cfm +** +** @brief This function is called to send handle value confirmation. +** +** @param[in] conn_id - connection ID. +** @param[in] char_id - characteristic ID to confirm. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id); + + + + +/******************************************************************************* +** +** @function esp_ble_gattc_register_ntf +** +** @brief This function is called to register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if registration succeed, otherwise failed. +** +*******************************************************************************/ +esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if, + BD_ADDR bda, + esp_gattc_char_id_t *char_id); + + + +/******************************************************************************* +** +** @function esp_ble_gattc_unregister_ntf +** +** @brief This function is called to de-register for notification of a service. +** +** @param[in] client_if - client interface. +** @param[in] bda - target GATT server. +** @param[in] char_id - pointer to GATT characteristic ID. +** +** @return OK if deregistration succeed, otherwise failed. +** +*******************************************************************************/ +tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if, + BD_ADDR bda, + esp_gattc_char_id_t *char_id); + + +/******************************************************************************* +** +** @function esp_ble_gatts_disale +** +** @brief This function is called to disable GATTS module +** +** @param[in] None. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_disale(void); + + + + +/******************************************************************************* +** +** @function esp_ble_gatts_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] app_uuid - applicaiton UUID +** @param[in] cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_app_unregister +** +** @brief un-register with GATT Server. +** +** @param[in] server_if: service interface id. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_create_srvc +** +** @brief Create a service. When service creation is done, a callback +** event BTA_GATTS_CREATE_SRVC_EVT is called to report status +** and service ID to the profile. The service ID obtained in +** the callback function needs to be used when adding included +** service and characteristics/descriptors into the service. +** +** @param[in] server_if: Profile ID this service is belonged to. +** @param[in] service_uuid: service UUID. +** @param[in] inst: instance ID number of this service. +** @param[in] num_handle: numble of handle requessted for this service. +** @param[in] is_primary: is this service a primary one or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst, + uint16_t num_handle, BOOLEAN is_primary); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_inclu_srvc +** +** @brief This function is called to add an included service. After included +** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT +** is reported the included service ID. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] included_service_id: the service ID to be included. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char +** +** @brief This function is called to add a characteristic into a service. +** +** @param[in] service_id: service ID to which this included service is to +** be added. +** @param[in] char_uuid : Characteristic UUID. +** @param[in] perm : Characteristic value declaration attribute permission. +** @param[in] property : Characteristic Properties +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid, + esp_gatt_perm_t perm, esp_gatt_char_prop_t property); + + + + +/******************************************************************************* +** +** @function esp_ble_gatts_add_char_descr +** +** @brief This function is called to add characteristic descriptor. When +** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called +** to report the status and an ID number for this descriptor. +** +** @param[in] service_id: service ID to which this charatceristic descriptor is to +** be added. +** @param[in] perm: descriptor access permission. +** @param[in] descr_uuid: descriptor UUID. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_add_char_descr (uint16_t service_id, + esp_gatt_perm_t perm, + esp_bt_uuid_t * descr_uuid); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_dele_srvc +** +** @brief This function is called to delete a service. When this is done, +** a callback event BTA_GATTS_DELETE_EVT is report with the status. +** +** @param[in] service_id: service_id to be deleted. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_dele_srvc (uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_start_srvc +** +** @brief This function is called to start a service. +** +** @param[in] service_id: the service ID to be started. +** @param[in] sup_transport: supported trasnport. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_start_srvc(uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_stop_srvc +** +** @brief This function is called to stop a service. +** +** @param[in] service_id - service to be topped. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_stop_srvc(uint16_t service_id); + + + +/******************************************************************************* +** +** @function esp_ble_gatts_hdl_val_indica +** +** @brief This function is called to read a characteristics descriptor. +** +** @param[in] bda - remote device bd address to indicate. +** @param[in] attr_id - attribute ID to indicate. +** @param[in] data_len - indicate data length. +** @param[in] data: data to indicate. +** @param[in] need_confirm - if this indication expects a confirmation or not. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len, + uint8_t *data, BOOLEAN need_confirm); + + +/******************************************************************************* +** +** @function esp_ble_gatts_send_rsp +** +** @brief This function is called to send a response to a request. +** +** @param[in] conn_id - connection identifier. +** @param[in] trans_id - transaction ID. +** @param[in] status - response status +** @param[in] msg - response data. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id, + esp_gatt_status_t status, esp_gatts_rsp_t *msg); + + +/******************************************************************************* +** +** @function esp_ble_gatts_conn +** +** @brief Open a direct open connection or add a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gatts_cancel_conn +** +** @brief Cancel a direct open connection or remove a background auto connection +** bd address +** +** @param[in] server_if: server interface. +** @param[in] remote_bda: remote device BD address. +** @param[in] is_direct: direct connection or background auto connection +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct); + + +/******************************************************************************* +** +** @function esp_ble_gatts_close +** +** @brief Close a connection a remote device. +** +** @param[in] conn_id: connectino ID to be closed. +** +** @return None +** +*******************************************************************************/ +void esp_ble_gatts_close(uint16_t conn_id); + + +/******************************************************************************* +** +** @function esp_prf_app_register +** +** @brief This function is called to register application callbacks +** with BTA GATTS module. +** +** @param[in] prf_id - the profile identification +** @param[in] p_cback - pointer to the application callback function. +** +** @return None +** +*******************************************************************************/ +void esp_prf_app_register(uint8_t prf_id, void *p_cback); + + + diff --git a/components/bt/bluedroid/stack_api/include/bt_app_sec.h b/components/bt/bluedroid/stack_api/include/bt_app_sec.h index 6c003ae0c..6b7310fd9 100644 --- a/components/bt/bluedroid/stack_api/include/bt_app_sec.h +++ b/components/bt/bluedroid/stack_api/include/bt_app_sec.h @@ -1,78 +1,78 @@ -/** - **************************************************************************************** - * - * @file bt_app_sec.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ - -#include "bt_types.h" - -#define APP_SEC_IRK_FLAG (0) -#define RAND_NB_LEN 0x08 -#define SEC_KEY_LEN 0x10 - - /* - * STRUCTURES DEFINITIONS - **************************************************************************************** - */ - - - /// Generic Security key structure -typedef struct - { - /// Key value MSB -> LSB - UINT8 key[SEC_KEY_LEN]; - }smp_sec_key; - - ///Random number structure -typedef struct -{ - ///8-byte array for random number - UINT8 nb[RAND_NB_LEN]; -}rand_nb; - - typedef struct - { - // LTK - smp_sec_key ltk; - // Random Number - rand_nb rand_nb; - // EDIV - UINT16 ediv; - // LTK key size - UINT8 key_size; - - // Last paired peer address type - UINT8 peer_addr_type; - // Last paired peer address - BD_ADDR peer_addr; - - // authentication level - UINT8 auth; - - }tAPP_SEC_ENV; - - extern tAPP_SEC_ENV app_sec_env; - - /* - * GLOBAL FUNCTIONS DECLARATIONS - **************************************************************************************** - */ - -void app_ble_sec_init(void); - -void app_ble_sec_pairing_cmp_evt_send(UINT8); - -UINT32 app_ble_sec_gen_tk(void); - -void app_ble_sec_gen_ltk(UINT8 key_size); - -void app_ble_security_start(void); - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bt_types.h" + +#define APP_SEC_IRK_FLAG (0) +#define RAND_NB_LEN 0x08 +#define SEC_KEY_LEN 0x10 + + /* + * STRUCTURES DEFINITIONS + **************************************************************************************** + */ + + + /// Generic Security key structure +typedef struct + { + /// Key value MSB -> LSB + UINT8 key[SEC_KEY_LEN]; + }smp_sec_key; + + ///Random number structure +typedef struct +{ + ///8-byte array for random number + UINT8 nb[RAND_NB_LEN]; +}rand_nb; + + typedef struct + { + // LTK + smp_sec_key ltk; + // Random Number + rand_nb rand_nb; + // EDIV + UINT16 ediv; + // LTK key size + UINT8 key_size; + + // Last paired peer address type + UINT8 peer_addr_type; + // Last paired peer address + BD_ADDR peer_addr; + + // authentication level + UINT8 auth; + + }tAPP_SEC_ENV; + + extern tAPP_SEC_ENV app_sec_env; + + /* + * GLOBAL FUNCTIONS DECLARATIONS + **************************************************************************************** + */ + +void app_ble_sec_init(void); + +void app_ble_sec_pairing_cmp_evt_send(UINT8); + +UINT32 app_ble_sec_gen_tk(void); + +void app_ble_sec_gen_ltk(UINT8 key_size); + +void app_ble_security_start(void); + diff --git a/examples/05_ble_adv/main/app_bt.c b/examples/05_ble_adv/main/app_bt.c index 7f5dda5ec..810b53207 100755 --- a/examples/05_ble_adv/main/app_bt.c +++ b/examples/05_ble_adv/main/app_bt.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c index 409fa828c..f5cd9964b 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /*************************************************************** * * * * This file is for client to execute battery-related operation diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c index d3a4b4291..7507aa844 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c @@ -1,16 +1,16 @@ -/** - **************************************************************************************** - * - * @file bt_app.c - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/9/9 - * - * - **************************************************************************************** - */ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "bt_app_defs.h" diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index 250427296..badd92f58 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_md5.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_md5.c index 7271f6473..d8ecda9b3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_md5.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_md5.c @@ -1,130 +1,131 @@ -/** - **************************************************************************************** - * - * @file app_airsync_md5.h - * - * @brief Application airsync md5 generation Entry Point - * - * Copyright (C) ESPRESSIF 2016 - * Created by Yulong at 2016/10/9 - * - **************************************************************************************** - */ - -#include "prf_defs.h" -#if (WX_AIRSYNC_CFG) - - -#include -#include -#include -#include "gki.h" -#include "app_airsync_md5.h" - -const uint32_t X[4][2] = {{0, 1}, {1, 5}, {5, 3}, {0, 7}}; -const uint32_t S[4][4] = {{ 7, 12, 17, 22 },{ 5, 9 , 14, 20 },{ 4, 11, 16, 23 },{ 6, 10, 15, 21 }}; -uint32_t F( uint32_t X, uint32_t Y, uint32_t Z ) -{ - return ( X & Y ) | ( ~X & Z ); -} -uint32_t G( uint32_t X, uint32_t Y, uint32_t Z ) - { - return ( X & Z ) | ( Y & ~Z ); - } -uint32_t H( uint32_t X, uint32_t Y, uint32_t Z ) -{ - return X ^ Y ^ Z; -} -uint32_t I( uint32_t X, uint32_t Y, uint32_t Z ) -{ - return Y ^ ( X | ~Z ); -} - // rotates x left s bits. -uint32_t rotate_left( uint32_t x, uint32_t s ) -{ - return ( x << s ) | ( x >> ( 32 - s ) ); -} - - // Pre-processin -uint32_t count_padding_bits ( uint32_t length ) -{ -// uint32_t div = length * BITS / BLOCK_SIZE; - uint32_t mod = length * BITS % BLOCK_SIZE; - uint32_t c_bits; - if ( mod == 0 ) - { - c_bits = MOD_SIZE; - } - else - { - c_bits = ( MOD_SIZE + BLOCK_SIZE - mod ) % BLOCK_SIZE; - } - return c_bits / BITS; -} - -MD5String append_padding_bits ( char * argv ) -{ - uint32_t msg_length = strlen ( argv ); - uint32_t bit_length = count_padding_bits ( msg_length ); - uint64_t app_length = msg_length * BITS; - MD5String string; - string.str = (char *)GKI_getbuf(msg_length + bit_length + APP_SIZE / BITS); - strncpy ( string.str, argv, msg_length ); - memset ( string.str + msg_length, 0, bit_length ); - string.str [ msg_length ] = SINGLE_ONE_BIT; - memmove ( string.str + msg_length + bit_length, (char *)&app_length, sizeof( uint64_t ) ); - string.len = msg_length + bit_length + sizeof( uint64_t ); - return string; -} - -int32_t wechat_md5 (char *argv, uint8_t *md5_32) -{ - MD5String string; - uint32_t w[16]; - uint32_t chain[4]; - uint32_t state[4]; - - uint32_t ( *auxi[ 4 ])( uint32_t, uint32_t, uint32_t ) = { F, G, H, I }; - int sIdx; - int wIdx; - string = append_padding_bits ( argv ); - chain[0] = A; - chain[1] = B; - chain[2] = C; - chain[3] = D; - for (uint32_t j = 0; j < string.len; j += BLOCK_SIZE / BITS) - { - memmove ( (char *)w, string.str + j, BLOCK_SIZE / BITS ); - memmove ( state, chain, sizeof(chain) ); - for ( uint8_t roundIdx = 0; roundIdx < 4; roundIdx++ ) - { - wIdx = X[ roundIdx ][ 0 ]; - sIdx = 0; - for (uint8_t i = 0; i < 16; i++ ) - { - state[sIdx] = state [(sIdx + 1)%4] + rotate_left( state[sIdx] +(*auxi[ roundIdx])( state[(sIdx+1) % 4], - state[(sIdx+2) % 4], - state[(sIdx+3) % 4]) + w[ wIdx ] + (uint32_t)floor((1ULL << 32) * fabs(sin( roundIdx * 16 + i + 1 )) ), - S[ roundIdx ][ i % 4 ]); - sIdx = ( sIdx + 3 ) % 4; - wIdx = ( wIdx + X[ roundIdx ][ 1 ] ) & 0xF; - } - } - chain[ 0 ] += state[ 0 ]; - chain[ 1 ] += state[ 1 ]; - chain[ 2 ] += state[ 2 ]; - chain[ 3 ] += state[ 3 ]; - } - memmove ( md5_32 + 0, (char *)&chain[0], sizeof(uint32_t) ); - memmove ( md5_32 + 4, (char *)&chain[1], sizeof(uint32_t) ); - memmove ( md5_32 + 8, (char *)&chain[2], sizeof(uint32_t) ); - memmove ( md5_32 + 12, (char *)&chain[3], sizeof(uint32_t) ); - free(string.str); - string.str = NULL; - return EXIT_SUCCESS; - -} - - -#endif ///WX_AIRSYNC_CFG - +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "prf_defs.h" +#if (WX_AIRSYNC_CFG) + + +#include +#include +#include +#include "gki.h" +#include "app_airsync_md5.h" + +const uint32_t X[4][2] = {{0, 1}, {1, 5}, {5, 3}, {0, 7}}; +const uint32_t S[4][4] = {{ 7, 12, 17, 22 },{ 5, 9 , 14, 20 },{ 4, 11, 16, 23 },{ 6, 10, 15, 21 }}; +uint32_t F( uint32_t X, uint32_t Y, uint32_t Z ) +{ + return ( X & Y ) | ( ~X & Z ); +} +uint32_t G( uint32_t X, uint32_t Y, uint32_t Z ) + { + return ( X & Z ) | ( Y & ~Z ); + } +uint32_t H( uint32_t X, uint32_t Y, uint32_t Z ) +{ + return X ^ Y ^ Z; +} +uint32_t I( uint32_t X, uint32_t Y, uint32_t Z ) +{ + return Y ^ ( X | ~Z ); +} + // rotates x left s bits. +uint32_t rotate_left( uint32_t x, uint32_t s ) +{ + return ( x << s ) | ( x >> ( 32 - s ) ); +} + + // Pre-processin +uint32_t count_padding_bits ( uint32_t length ) +{ +// uint32_t div = length * BITS / BLOCK_SIZE; + uint32_t mod = length * BITS % BLOCK_SIZE; + uint32_t c_bits; + if ( mod == 0 ) + { + c_bits = MOD_SIZE; + } + else + { + c_bits = ( MOD_SIZE + BLOCK_SIZE - mod ) % BLOCK_SIZE; + } + return c_bits / BITS; +} + +MD5String append_padding_bits ( char * argv ) +{ + uint32_t msg_length = strlen ( argv ); + uint32_t bit_length = count_padding_bits ( msg_length ); + uint64_t app_length = msg_length * BITS; + MD5String string; + string.str = (char *)GKI_getbuf(msg_length + bit_length + APP_SIZE / BITS); + strncpy ( string.str, argv, msg_length ); + memset ( string.str + msg_length, 0, bit_length ); + string.str [ msg_length ] = SINGLE_ONE_BIT; + memmove ( string.str + msg_length + bit_length, (char *)&app_length, sizeof( uint64_t ) ); + string.len = msg_length + bit_length + sizeof( uint64_t ); + return string; +} + +int32_t wechat_md5 (char *argv, uint8_t *md5_32) +{ + MD5String string; + uint32_t w[16]; + uint32_t chain[4]; + uint32_t state[4]; + + uint32_t ( *auxi[ 4 ])( uint32_t, uint32_t, uint32_t ) = { F, G, H, I }; + int sIdx; + int wIdx; + string = append_padding_bits ( argv ); + chain[0] = A; + chain[1] = B; + chain[2] = C; + chain[3] = D; + for (uint32_t j = 0; j < string.len; j += BLOCK_SIZE / BITS) + { + memmove ( (char *)w, string.str + j, BLOCK_SIZE / BITS ); + memmove ( state, chain, sizeof(chain) ); + for ( uint8_t roundIdx = 0; roundIdx < 4; roundIdx++ ) + { + wIdx = X[ roundIdx ][ 0 ]; + sIdx = 0; + for (uint8_t i = 0; i < 16; i++ ) + { + state[sIdx] = state [(sIdx + 1)%4] + rotate_left( state[sIdx] +(*auxi[ roundIdx])( state[(sIdx+1) % 4], + state[(sIdx+2) % 4], + state[(sIdx+3) % 4]) + w[ wIdx ] + (uint32_t)floor((1ULL << 32) * fabs(sin( roundIdx * 16 + i + 1 )) ), + S[ roundIdx ][ i % 4 ]); + sIdx = ( sIdx + 3 ) % 4; + wIdx = ( wIdx + X[ roundIdx ][ 1 ] ) & 0xF; + } + } + chain[ 0 ] += state[ 0 ]; + chain[ 1 ] += state[ 1 ]; + chain[ 2 ] += state[ 2 ]; + chain[ 3 ] += state[ 3 ]; + } + memmove ( md5_32 + 0, (char *)&chain[0], sizeof(uint32_t) ); + memmove ( md5_32 + 4, (char *)&chain[1], sizeof(uint32_t) ); + memmove ( md5_32 + 8, (char *)&chain[2], sizeof(uint32_t) ); + memmove ( md5_32 + 12, (char *)&chain[3], sizeof(uint32_t) ); + free(string.str); + string.str = NULL; + return EXIT_SUCCESS; + +} + + +#endif ///WX_AIRSYNC_CFG + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_prf.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_prf.c index 60cc8329f..893c71dbe 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_prf.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_WX_airsync/app_airsync_prf.c @@ -1,160 +1,161 @@ -/** - **************************************************************************************** - * - * @file app_airsync_prf.c - * - * @brief Application Security Entry Point - * - * Copyright (C) ESPRESSIF 2016 - * Created by Yulong at 2016/9/30 - * - **************************************************************************************** - */ - -#include "prf_defs.h" -#if (WX_AIRSYNC_CFG) - -#include "app_airsync_prf.h" -#include "wx_airsync_prf.h" -#include "app_wechat_util.h" -#include "gki.h" -#include "mpbledemo2.h" - -/***************************************************************************** -* data handle -*****************************************************************************/ -data_info g_send_data; - -static data_info g_rcv_data; -data_handler *pDataHandler; - - -static void airsync_process_msgreceive_cb(UINT8 app_id, - UINT8 conn_id,uint8_t *pData, uint16_t length); - -///function for register all products -static void register_all_products(void) -{ - REGISTER(mpbledemo2); - // could register more products if defined -} - -void app_wechat_init(void) -{ - register_all_products(); - - data_handler_init(&m_mpbledemo2_handler,PRODUCT_TYPE_MPBLEDEMO2); - m_mpbledemo2_handler->m_data_init_func(); - m_mpbledemo2_handler->m_data_init_peripheral_func(); - - app_wechat_SetDatahandler(m_mpbledemo2_handler); -} - -int ble_wechat_indicate_data_chunk(void) -{ - uint16_t chunk_len = 0; - chunk_len = g_send_data.len - g_send_data.offset; - chunk_len = chunk_len > BLE_WECHAT_MAX_DATA_LEN?BLE_WECHAT_MAX_DATA_LEN:chunk_len; - - if(chunk_len == 0) - { - app_wechat_datahandler()->m_data_free_func(g_send_data.data,g_send_data.len); - g_send_data.data = NULL; - g_send_data.len = 0; - g_send_data.offset = 0; - return 0; - } - - g_send_data.offset += chunk_len; - return 1; -} - - - /******************************************************************************* +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "prf_defs.h" +#if (WX_AIRSYNC_CFG) + +#include "app_airsync_prf.h" +#include "wx_airsync_prf.h" +#include "app_wechat_util.h" +#include "gki.h" +#include "mpbledemo2.h" + +/***************************************************************************** +* data handle +*****************************************************************************/ +data_info g_send_data; + +static data_info g_rcv_data; +data_handler *pDataHandler; + + +static void airsync_process_msgreceive_cb(UINT8 app_id, + UINT8 conn_id,uint8_t *pData, uint16_t length); + +///function for register all products +static void register_all_products(void) +{ + REGISTER(mpbledemo2); + // could register more products if defined +} + +void app_wechat_init(void) +{ + register_all_products(); + + data_handler_init(&m_mpbledemo2_handler,PRODUCT_TYPE_MPBLEDEMO2); + m_mpbledemo2_handler->m_data_init_func(); + m_mpbledemo2_handler->m_data_init_peripheral_func(); + + app_wechat_SetDatahandler(m_mpbledemo2_handler); +} + +int ble_wechat_indicate_data_chunk(void) +{ + uint16_t chunk_len = 0; + chunk_len = g_send_data.len - g_send_data.offset; + chunk_len = chunk_len > BLE_WECHAT_MAX_DATA_LEN?BLE_WECHAT_MAX_DATA_LEN:chunk_len; + + if(chunk_len == 0) + { + app_wechat_datahandler()->m_data_free_func(g_send_data.data,g_send_data.len); + g_send_data.data = NULL; + g_send_data.len = 0; + g_send_data.offset = 0; + return 0; + } + + g_send_data.offset += chunk_len; + return 1; +} + + + /******************************************************************************* ** -** Function airsync_msgreceive_cb +** Function airsync_msgreceive_cb ** -** Description the callback function after the airsync profile have been -** receive the data from the peer device -** parms appid:the appid have been register to the gatt database -** conn_id:the current connection index -** msg_val:the airsync value receive from peer device +** Description the callback function after the airsync profile have been +** receive the data from the peer device +** parms appid:the appid have been register to the gatt database +** conn_id:the current connection index +** msg_val:the airsync value receive from peer device ** Returns NULL ** -*******************************************************************************/ -static void airsync_process_msgreceive_cb(UINT8 app_id, - UINT8 conn_id,uint8_t *pData, uint16_t length) -{ - int error_code; - int chunk_size = 0; - if(length <= BLE_WECHAT_MAX_DATA_LEN) - { - if(g_rcv_data.len == 0) - { - BpFixHead *fix_head = (BpFixHead *)pData; - g_rcv_data.len = ntohs(fix_head->nLength); - g_rcv_data.offset = 0; - g_rcv_data.data = (uint8_t *)GKI_getbuf(g_rcv_data.len); - } - - chunk_size = g_rcv_data.len - g_rcv_data.offset; - chunk_size = chunk_size < length ? chunk_size : length; - memcpy(g_rcv_data.data + g_rcv_data.offset, pData, chunk_size); - g_rcv_data.offset += chunk_size; - - if (g_rcv_data.len <= g_rcv_data.offset) - { - error_code = app_wechat_datahandler()->m_data_consume_func(g_rcv_data.data, g_rcv_data.len); - app_wechat_datahandler()->m_data_free_func(g_rcv_data.data,g_rcv_data.len); - wechat_error_chack(app_wechat_datahandler(), error_code); - g_rcv_data.len = 0; - g_rcv_data.offset = 0; - - app_wechat_datahandler()->m_data_main_process_func(); - } - - - } - - -} - - void app_wechat_SetDatahandler(data_handler* pHandler) -{ - pDataHandler = pHandler; -} - -bool ble_wechat_is_last_data_sent_out(void) -{ - return (g_send_data.len == 0 && g_send_data.offset == 0 ) || \ - (g_send_data.len != 0 && g_send_data.len == g_send_data.offset); -} - -//device sent data on the indicate characteristic -int ble_wechat_indicate_data(uint8_t *data, int len) -{ - if(data == NULL || len == 0) - { - return 0; - } - - if(!ble_wechat_is_last_data_sent_out()) - { - return 0; - } - - g_send_data.data = data; - g_send_data.len = len; - g_send_data.offset = 0; - - return (ble_wechat_indicate_data_chunk()); -} - -data_handler *app_wechat_datahandler(void) -{ - return pDataHandler; -} - - -#endif ///WX_AIRSYNC_CFG - +*******************************************************************************/ +static void airsync_process_msgreceive_cb(UINT8 app_id, + UINT8 conn_id,uint8_t *pData, uint16_t length) +{ + int error_code; + int chunk_size = 0; + if(length <= BLE_WECHAT_MAX_DATA_LEN) + { + if(g_rcv_data.len == 0) + { + BpFixHead *fix_head = (BpFixHead *)pData; + g_rcv_data.len = ntohs(fix_head->nLength); + g_rcv_data.offset = 0; + g_rcv_data.data = (uint8_t *)GKI_getbuf(g_rcv_data.len); + } + + chunk_size = g_rcv_data.len - g_rcv_data.offset; + chunk_size = chunk_size < length ? chunk_size : length; + memcpy(g_rcv_data.data + g_rcv_data.offset, pData, chunk_size); + g_rcv_data.offset += chunk_size; + + if (g_rcv_data.len <= g_rcv_data.offset) + { + error_code = app_wechat_datahandler()->m_data_consume_func(g_rcv_data.data, g_rcv_data.len); + app_wechat_datahandler()->m_data_free_func(g_rcv_data.data,g_rcv_data.len); + wechat_error_chack(app_wechat_datahandler(), error_code); + g_rcv_data.len = 0; + g_rcv_data.offset = 0; + + app_wechat_datahandler()->m_data_main_process_func(); + } + + + } + + +} + + void app_wechat_SetDatahandler(data_handler* pHandler) +{ + pDataHandler = pHandler; +} + +bool ble_wechat_is_last_data_sent_out(void) +{ + return (g_send_data.len == 0 && g_send_data.offset == 0 ) || \ + (g_send_data.len != 0 && g_send_data.len == g_send_data.offset); +} + +//device sent data on the indicate characteristic +int ble_wechat_indicate_data(uint8_t *data, int len) +{ + if(data == NULL || len == 0) + { + return 0; + } + + if(!ble_wechat_is_last_data_sent_out()) + { + return 0; + } + + g_send_data.data = data; + g_send_data.len = len; + g_send_data.offset = 0; + + return (ble_wechat_indicate_data_chunk()); +} + +data_handler *app_wechat_datahandler(void) +{ + return pDataHandler; +} + + +#endif ///WX_AIRSYNC_CFG + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c index df280cf4f..fc6735179 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_profiles/app_sample_button/app_button.c @@ -1,20 +1,16 @@ -/** - -******************************************************************************* -********* - * - * @file app_button.c - * - * @brief button Service Application entry point - * - * Copyright (C) ESPRESSSIF 2016 - * Created by Yulong at 2016/08/24 - * - * - -******************************************************************************* -********* -*/ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #include "prf_defs.h" diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c index be179f501..7e2808c39 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleClientProject.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /**************************************************************************** * * This file is for gatt client. It can scan ble device, connect one device, diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index 485d90833..c631cac1e 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /*************************************************************** * * This file is for gatt server device. It instantiates BATTERY diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_md5.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_md5.h index 6fe956d61..6a1e70914 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_md5.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_md5.h @@ -1,52 +1,39 @@ -/** - **************************************************************************************** - * - * @file app_airsync_md5.h - * - * @brief Application airsync md5 generation head Entry Point - * - * Copyright (C) ESPRESSIF 2016 - * Created by Yulong at 2016/10/9 - * - **************************************************************************************** - */ - -#ifndef __APP_AIRSYNC_MD5__ -#define __APP_AIRSYNC_MD5__ - -#include "prf_defs.h" -#if (WX_AIRSYNC_CFG) - - -#include -#include -#include -#include - -#define SINGLE_ONE_BIT 0x80 -#define BLOCK_SIZE 512 -#define MOD_SIZE 448 -#define APP_SIZE 64 -#define BITS 8 - -// MD5 Chaining Variable -#define A 0x67452301UL -#define B 0xEFCDAB89UL -#define C 0x98BADCFEUL -#define D 0x10325476UL - -typedef struct -{ - char *str; - uint32_t len; -}MD5String; - - -int32_t wechat_md5 ( char *argv, uint8_t *md5_32); - - -#endif ///WX_AIRSYNC_CFG - -#endif /// __APP_AIRSYNC_MD5__ - - +#ifndef __APP_AIRSYNC_MD5__ +#define __APP_AIRSYNC_MD5__ + +#include "prf_defs.h" +#if (WX_AIRSYNC_CFG) + + +#include +#include +#include +#include + +#define SINGLE_ONE_BIT 0x80 +#define BLOCK_SIZE 512 +#define MOD_SIZE 448 +#define APP_SIZE 64 +#define BITS 8 + +// MD5 Chaining Variable +#define A 0x67452301UL +#define B 0xEFCDAB89UL +#define C 0x98BADCFEUL +#define D 0x10325476UL + +typedef struct +{ + char *str; + uint32_t len; +}MD5String; + + +int32_t wechat_md5 ( char *argv, uint8_t *md5_32); + + +#endif ///WX_AIRSYNC_CFG + +#endif /// __APP_AIRSYNC_MD5__ + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_prf.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_prf.h index 5e5699d56..39d1913dd 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_prf.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_airsync_prf.h @@ -1,47 +1,35 @@ -/** - **************************************************************************************** - * - * @file app_airsync_prf.h - * - * @brief Application Security Entry Point - * - * Copyright (C) ESPRESSIF 2016 - * Created by Yulong at 2016/9/30 - * - **************************************************************************************** - */ -#ifndef _APP_AIRSYNC_PRF_H__ -#define _APP_AIRSYNC_PRF_H__ - -#include "prf_defs.h" -#if (WX_AIRSYNC_CFG) - - -#include "app_wechat_util.h" -#include -#include - -#define MAGIC_NUMBER 0xFE - -/** - **************************************************************************************** - * @brief Create Wechat Database - * - **************************************************************************************** - */ -void app_wechat_create_db(void); - -void app_wechat_SetDatahandler(data_handler* pHandler); -int ble_wechat_indicate_data(uint8_t *data, int len); -int ble_wechat_indicate_data_chunk(void); -void ble_wechat_process_received_data(uint8_t* pData, uint32_t length); -data_handler* app_wechat_datahandler(void); -bool ble_wechat_is_last_data_sent_out(void); - - -#endif ///WX_AIRSYNC_CFG - -#endif ///_APP_AIRSYNC_PRF_H__ - - - +#ifndef _APP_AIRSYNC_PRF_H__ +#define _APP_AIRSYNC_PRF_H__ + +#include "prf_defs.h" +#if (WX_AIRSYNC_CFG) + + +#include "app_wechat_util.h" +#include +#include + +#define MAGIC_NUMBER 0xFE + +/** + **************************************************************************************** + * @brief Create Wechat Database + * + **************************************************************************************** + */ +void app_wechat_create_db(void); + +void app_wechat_SetDatahandler(data_handler* pHandler); +int ble_wechat_indicate_data(uint8_t *data, int len); +int ble_wechat_indicate_data_chunk(void); +void ble_wechat_process_received_data(uint8_t* pData, uint32_t length); +data_handler* app_wechat_datahandler(void); +bool ble_wechat_is_last_data_sent_out(void); + + +#endif ///WX_AIRSYNC_CFG + +#endif ///_APP_AIRSYNC_PRF_H__ + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h index ea77c4476..dfebee0c3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button.h @@ -1,17 +1,3 @@ -/** - **************************************************************************************** - * - * @file app_button.h - * - * @brief button Service Application entry point - * - * Copyright (C) ESPRESSIF 2016 - * Created by Yulong at 2016/02/24 - * - * - **************************************************************************************** - */ - /* * DEFINES **************************************************************************************** diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h index b64a1ee32..616497bd9 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -1,131 +1,116 @@ -/** - -******************************************************************************* -********* -* -* @file app_button_int.h -* -* @brief button Service Application entry point -* -* Copyright (C) ESPRESSSIF 2016 -* Created by Yulong at 2016/10/17 -* -******************************************************************************* -**********/ - -#include "prf_defs.h" -#include "bt_prf_sys.h" -#include "bt_types.h" - -#if (BUT_PROFILE_CFG) - -/// Messages for Device Information Service Server -enum -{ - ///Add a BUTTON instance into the database - BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE), - ///Send key value confirm to APP so stable values can be erased - ///if correctly sent. - BLE_BUT_VAL_SEND_CFM_EVT, - ///Set the value of an attribute - BLE_BUT_SET_CHAR_VAL_REQ_EVT, - - ///Start the button notify Service Task - at connection - BLE_BUT_ENABLE_REQ_EVT, - - /// Inform the application that the profile service role task has been disabled after a disconnection - BLE_BUT_DISABLE_IND_EVT, - /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client - BLE_BUT_CHAR_WRITE_IND_EVT, - ///Error indication to Host - BLE_BUT_ERROR_IND_EVT, -}; - -/// Parameters of the @ref KEY_CREATE_DB_REQ message -typedef struct -{ - ///Database configuration - uint16_t features; -}tBUT_CRT_DB_REQ; - -/// Parameters of the @ref KEY_CREATE_DB_CFM message -typedef struct -{ - ///Status - uint8_t status; -}tBUT_CRT_DB_CFM; - -///Parameters of the @ref key_CFG_INDNTF_IND message -typedef struct -{ - ///Connection handle - uint16_t conhdl; - ///Stop/notify/indicate value to configure into the peer characteristic - uint16_t cfg_val; - /// characteristics - uint8_t char_code; -}tBUT_CFG_NTF_IND; - - -/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated -typedef struct -{ - /// Characteristic Code - //uint8_t char_code; - uint8_t conhdl; - uint8_t key_val_len; - uint8_t key_val[2]; -}tBUT_SND_CHAR_VAL_REQ; - -/// Parameters of the @ref KEY_ENABLE_REQ message -typedef struct -{ - ///Connection handle - uint16_t conhdl; - /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together - uint8_t sec_lvl; - ///Type of connection - uint8_t con_type; -}tBUT_ENABLE_REQ; - -///Parameters of the @ref KEY_VAL_SEND_CFM message -typedef struct -{ - ///Connection handle - uint16_t conhdl; - ///Status - uint8_t status; -}tBUT_VAL_SND_CFM; - - -/// Parameters of the @ref KEY_DISABLE_IND message -typedef struct -{ - ///Connection handle - uint16_t conhdl; -}tBUT_DISABLE_IND; - -typedef union -{ - uint16_t conhdl; - tBUT_CRT_DB_REQ but_crt_db_req; - tBUT_CRT_DB_CFM but_crt_db_cfm; - tBUT_CFG_NTF_IND but_cfg_ntf_ind; - tBUT_SND_CHAR_VAL_REQ but_snd_char_val_req; - tBUT_ENABLE_REQ but_enable_req; - tBUT_VAL_SND_CFM but_val_snd_cfm; - tBUT_DISABLE_IND but_disable_ind; -}tBUT_PRF_MSG; - - - -BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data); - -void ble_but_prf_disable(void); - - - -#endif ///BUT_PROFILE_CFG - - - +#include "prf_defs.h" +#include "bt_prf_sys.h" +#include "bt_types.h" + +#if (BUT_PROFILE_CFG) + +/// Messages for Device Information Service Server +enum +{ + ///Add a BUTTON instance into the database + BLE_BUT_CREATE_DB_REQ_EVT = BT_PRF_SYS_EVT_START(PRF_ID_BUT_LE), + ///Send key value confirm to APP so stable values can be erased + ///if correctly sent. + BLE_BUT_VAL_SEND_CFM_EVT, + ///Set the value of an attribute + BLE_BUT_SET_CHAR_VAL_REQ_EVT, + + ///Start the button notify Service Task - at connection + BLE_BUT_ENABLE_REQ_EVT, + + /// Inform the application that the profile service role task has been disabled after a disconnection + BLE_BUT_DISABLE_IND_EVT, + /// Inform the application that the profile service has been reiceivd the charateristic write commamd from Client + BLE_BUT_CHAR_WRITE_IND_EVT, + ///Error indication to Host + BLE_BUT_ERROR_IND_EVT, +}; + +/// Parameters of the @ref KEY_CREATE_DB_REQ message +typedef struct +{ + ///Database configuration + uint16_t features; +}tBUT_CRT_DB_REQ; + +/// Parameters of the @ref KEY_CREATE_DB_CFM message +typedef struct +{ + ///Status + uint8_t status; +}tBUT_CRT_DB_CFM; + +///Parameters of the @ref key_CFG_INDNTF_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Stop/notify/indicate value to configure into the peer characteristic + uint16_t cfg_val; + /// characteristics + uint8_t char_code; +}tBUT_CFG_NTF_IND; + + +/// Parameters of the @ref KEY_SET_CHAR_VAL_REQ message - shall be dynamically allocated +typedef struct +{ + /// Characteristic Code + //uint8_t char_code; + uint8_t conhdl; + uint8_t key_val_len; + uint8_t key_val[2]; +}tBUT_SND_CHAR_VAL_REQ; + +/// Parameters of the @ref KEY_ENABLE_REQ message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + /// security level: b0= nothing, b1=unauthenticated, b2=authenticated, b3=authorized; b1 or b2 and b3 can go together + uint8_t sec_lvl; + ///Type of connection + uint8_t con_type; +}tBUT_ENABLE_REQ; + +///Parameters of the @ref KEY_VAL_SEND_CFM message +typedef struct +{ + ///Connection handle + uint16_t conhdl; + ///Status + uint8_t status; +}tBUT_VAL_SND_CFM; + + +/// Parameters of the @ref KEY_DISABLE_IND message +typedef struct +{ + ///Connection handle + uint16_t conhdl; +}tBUT_DISABLE_IND; + +typedef union +{ + uint16_t conhdl; + tBUT_CRT_DB_REQ but_crt_db_req; + tBUT_CRT_DB_CFM but_crt_db_cfm; + tBUT_CFG_NTF_IND but_cfg_ntf_ind; + tBUT_SND_CHAR_VAL_REQ but_snd_char_val_req; + tBUT_ENABLE_REQ but_enable_req; + tBUT_VAL_SND_CFM but_val_snd_cfm; + tBUT_DISABLE_IND but_disable_ind; +}tBUT_PRF_MSG; + + + +BOOLEAN ble_but_prf_hdl_event(prf_hdr_evt_t *msg_data); + +void ble_but_prf_disable(void); + + + +#endif ///BUT_PROFILE_CFG + + + diff --git a/examples/06_bluedroid_demos/main/demo_main.c b/examples/06_bluedroid_demos/main/demo_main.c index fe62f89b7..7ea523c0e 100644 --- a/examples/06_bluedroid_demos/main/demo_main.c +++ b/examples/06_bluedroid_demos/main/demo_main.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include diff --git a/examples/07_blufi/components/blufi/blufi.c b/examples/07_blufi/components/blufi/blufi.c index 65ccd4030..304fcf80c 100644 --- a/examples/07_blufi/components/blufi/blufi.c +++ b/examples/07_blufi/components/blufi/blufi.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /*************************************************************** * * This file is for gatt server device. It instantiates BATTERY diff --git a/examples/07_blufi/components/blufi/blufi_task.c b/examples/07_blufi/components/blufi/blufi_task.c index daa60db6e..49aa253bd 100644 --- a/examples/07_blufi/components/blufi/blufi_task.c +++ b/examples/07_blufi/components/blufi/blufi_task.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include diff --git a/examples/07_blufi/main/demo_main.c b/examples/07_blufi/main/demo_main.c index 54eabe93c..ac52c8ab3 100644 --- a/examples/07_blufi/main/demo_main.c +++ b/examples/07_blufi/main/demo_main.c @@ -1,3 +1,17 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include #include #include From 5c3ce5b26978373202d5ddc648239af0efb14749 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Sat, 5 Nov 2016 02:50:51 +0800 Subject: [PATCH 27/31] component/bt : demo compile fix --- .../components/bluedroid_demos/app_core/bt_app_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index badd92f58..0c3d8ef4e 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -73,7 +73,7 @@ extern void ble_server_test(void); static void bt_app_task_handler(void *arg) { - TaskEvt_t *e; + BtTaskEvt_t *e; UINT8 button_msg[2] = {0x01,0x00}; for (;;) { if (pdTRUE == xQueueReceive(xBtaApp1Queue, &e, (portTickType)portMAX_DELAY)) { @@ -99,7 +99,7 @@ static void bt_app_task_handler(void *arg) static void bt_app_task_post(void) { - TaskEvt_t *evt = (TaskEvt_t *)osi_malloc(sizeof(TaskEvt_t)); + BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); if (evt == NULL) return; From 084248e211a84769d8f963ec569e7d90854ca45d Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Sat, 5 Nov 2016 19:57:53 +0800 Subject: [PATCH 28/31] component/bt : cleanup task evt --- components/bt/bluedroid/hci/hci_hal_h4.c | 25 ++++++++----------- components/bt/bluedroid/hci/hci_layer.c | 17 ++++++------- .../bt/bluedroid/profiles/core/bt_prf_task.c | 19 ++++++-------- components/bt/bluedroid/stack/btu/btu_init.c | 2 +- components/bt/bluedroid/stack/btu/btu_task.c | 17 +++++-------- .../bluedroid_demos/app_core/bt_app_core.c | 22 +++++++--------- .../07_blufi/components/blufi/blufi_task.c | 24 ++++++++---------- 7 files changed, 51 insertions(+), 75 deletions(-) diff --git a/components/bt/bluedroid/hci/hci_hal_h4.c b/components/bt/bluedroid/hci/hci_hal_h4.c index b3cd5d296..7fabf83a9 100755 --- a/components/bt/bluedroid/hci/hci_hal_h4.c +++ b/components/bt/bluedroid/hci/hci_hal_h4.c @@ -91,13 +91,14 @@ static void hci_hal_env_deinit(void) { fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free); } -static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) { +static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) +{ assert(upper_callbacks != NULL); callbacks = upper_callbacks; hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX); - xHciH4Queue = xQueueCreate(60, sizeof(void *)); + xHciH4Queue = xQueueCreate(60, sizeof(BtTaskEvt_t)); xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 4096+2048, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle); //register vhci host cb @@ -105,10 +106,6 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) { return true; - -error: - interface.close(); - return false; } static void hal_close() { @@ -156,27 +153,25 @@ static uint16_t transmit_data(serial_data_type_t type, } // Internal functions -static void hci_hal_h4_rx_handler(void *arg) { - BtTaskEvt_t *e; +static void hci_hal_h4_rx_handler(void *arg) +{ + BtTaskEvt_t e; for (;;) { if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == 0xff) { + if (e.sig == 0xff) { fixed_queue_process(hci_hal_env.rx_q); } - osi_free(e); } } } void hci_hal_h4_task_post(void) { - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return; + BtTaskEvt_t evt; - evt->sig = 0xff; - evt->par = 0; + evt.sig = 0xff; + evt.par = 0; if (xQueueSend(xHciH4Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { LOG_ERROR("xHciH4Queue failed\n"); diff --git a/components/bt/bluedroid/hci/hci_layer.c b/components/bt/bluedroid/hci/hci_layer.c index d9c73d8b1..cc9a0ab84 100755 --- a/components/bt/bluedroid/hci/hci_layer.c +++ b/components/bt/bluedroid/hci/hci_layer.c @@ -111,7 +111,7 @@ int hci_start_up(void) { if (hci_layer_init_env()) goto error; - xHciHostQueue = xQueueCreate(60, sizeof(void *)); + xHciHostQueue = xQueueCreate(60, sizeof(BtTaskEvt_t)); xTaskCreate(hci_host_thread_handler, "HciHostT", (4096+2048), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle); packet_fragmenter->init(&packet_fragmenter_callbacks); @@ -139,15 +139,13 @@ void hci_shut_down(void) { void hci_host_task_post(void) { + BtTaskEvt_t evt; + if (hci_host_startup_flag == false) return; - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return; - - evt->sig = 0xff; - evt->par = 0; + evt.sig = 0xff; + evt.par = 0; if (xQueueSend(xHciHostQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { LOG_ERROR("xHciHostQueue failed\n"); @@ -223,12 +221,12 @@ static void hci_host_thread_handler(void *arg) * H4 type header added (1 byte). */ - BtTaskEvt_t *e; + BtTaskEvt_t e; for (;;) { if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == 0xff) { + if (e.sig == 0xff) { if (API_vhci_host_check_send_available()) { /*Now Target only allowed one packet per TX*/ BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); @@ -243,7 +241,6 @@ static void hci_host_thread_handler(void *arg) } } } - osi_free(e); } } } diff --git a/components/bt/bluedroid/profiles/core/bt_prf_task.c b/components/bt/bluedroid/profiles/core/bt_prf_task.c index cf5c44177..3c32bb1f6 100644 --- a/components/bt/bluedroid/profiles/core/bt_prf_task.c +++ b/components/bt/bluedroid/profiles/core/bt_prf_task.c @@ -36,31 +36,28 @@ ******************************************************************************/ void bt_prf_task_thread_handler(void *arg) { - - BtTaskEvt_t *e; + BtTaskEvt_t e; + for (;;) { if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == SIG_PRF_WORK) { + if (e.sig == SIG_PRF_WORK) { fixed_queue_process(bt_profile_msg_queue); LOG_ERROR("bt_prf_task_thread_handler\n"); } - else if (e->sig == SIG_PRF_START_UP) { + else if (e.sig == SIG_PRF_START_UP) { bt_prf_task_start_up(); } - osi_free(e); } } } void bt_prf_task_post(uint32_t sig) { - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return; + BtTaskEvt_t evt; - evt->sig = sig; - evt->par = 0; + evt.sig = sig; + evt.par = 0; if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { ets_printf("xProfileQueue failed\n"); @@ -100,7 +97,7 @@ void bt_prf_StartUp(void) if (bt_profile_msg_queue == NULL) goto error_exit; - xProfileQueue = xQueueCreate(60, sizeof(void *)); + xProfileQueue = xQueueCreate(60, sizeof(BtTaskEvt_t)); xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle); bt_prf_task_post(SIG_PRF_START_UP); return; diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index 9ac18a86a..d8171aa91 100755 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -193,7 +193,7 @@ void BTU_StartUp(void) if (btu_l2cap_alarm_queue == NULL) goto error_exit; - xBtuQueue = xQueueCreate(60, sizeof(void *)); + xBtuQueue = xQueueCreate(60, sizeof(BtTaskEvt_t)); xTaskCreate(btu_task_thread_handler, "BtuT", 8192, NULL, configMAX_PRIORITIES - 1, &xBtuTaskHandle); btu_task_post(SIG_BTU_START_UP); /* diff --git a/components/bt/bluedroid/stack/btu/btu_task.c b/components/bt/bluedroid/stack/btu/btu_task.c index 05231e08f..9e7996cea 100755 --- a/components/bt/bluedroid/stack/btu/btu_task.c +++ b/components/bt/bluedroid/stack/btu/btu_task.c @@ -304,14 +304,12 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) { ******************************************************************************/ void btu_task_thread_handler(void *arg) { - //ke_event_clear(KE_EVENT_BTU_TASK_THREAD); - - BtTaskEvt_t *e; + BtTaskEvt_t e; for (;;) { if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == SIG_BTU_WORK) { + if (e.sig == SIG_BTU_WORK) { fixed_queue_process(btu_hci_msg_queue); #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) fixed_queue_process(btu_bta_msg_queue); @@ -321,10 +319,9 @@ void btu_task_thread_handler(void *arg) fixed_queue_process(btu_oneshot_alarm_queue); fixed_queue_process(btu_l2cap_alarm_queue); } - else if (e->sig == SIG_BTU_START_UP) { + else if (e.sig == SIG_BTU_START_UP) { btu_task_start_up(); } - osi_free(e); } } } @@ -332,12 +329,10 @@ void btu_task_thread_handler(void *arg) void btu_task_post(uint32_t sig) { - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return; + BtTaskEvt_t evt; - evt->sig = sig; - evt->par = 0; + evt.sig = sig; + evt.par = 0; if (xQueueSend(xBtuQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { LOG_ERROR("xBtuQueue failed\n"); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index 0c3d8ef4e..ee57954c3 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c @@ -73,18 +73,18 @@ extern void ble_server_test(void); static void bt_app_task_handler(void *arg) { - BtTaskEvt_t *e; + BtTaskEvt_t e; UINT8 button_msg[2] = {0x01,0x00}; for (;;) { if (pdTRUE == xQueueReceive(xBtaApp1Queue, &e, (portTickType)portMAX_DELAY)) { - if (e->sig == 0xff) { + if (e.sig == 0xff) { fixed_queue_process(bta_app_msg_queue); fixed_queue_process(bt_app_general_alarm_queue); } #if (BUT_PROFILE_CFG) - // else if(e->sig == BUTTON_PRESS_EVT){ - // LOG_ERROR("button_press_event come in,button_value=%x\n",e->par); - // button_msg[1] = e->par; + // else if(e.sig == BUTTON_PRESS_EVT){ + // LOG_ERROR("button_press_event come in,button_value=%x\n",e.par); + // button_msg[1] = e.par; // button_msg_notify(2,button_msg); @@ -92,19 +92,15 @@ static void bt_app_task_handler(void *arg) #endif ///BUT_PROFILE_CFG } - osi_free(e); } } static void bt_app_task_post(void) { + BtTaskEvt_t evt; - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return; - - evt->sig = 0xff; - evt->par = 0; + evt.sig = 0xff; + evt.par = 0; if (xQueueSend(xBtaApp1Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { ets_printf("btdm_post failed\n"); @@ -188,7 +184,7 @@ void bt_app_task_start_up(void) goto error_exit; //ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler); - xBtaApp1Queue = xQueueCreate(3, sizeof(void *)); + xBtaApp1Queue = xQueueCreate(3, sizeof(BtTaskEvt_t)); xTaskCreate(bt_app_task_handler, "BtaApp1T", 8192, NULL, configMAX_PRIORITIES - 3, xBtaApp1TaskHandle); fixed_queue_register_dequeue(bta_app_msg_queue, bta_app_msg_ready); diff --git a/examples/07_blufi/components/blufi/blufi_task.c b/examples/07_blufi/components/blufi/blufi_task.c index 49aa253bd..a1d0f0a2f 100644 --- a/examples/07_blufi/components/blufi/blufi_task.c +++ b/examples/07_blufi/components/blufi/blufi_task.c @@ -43,35 +43,31 @@ extern void ble_server_test(void); static void blufi_task(void *arg) { - BtTaskEvt_t *e; + BtTaskEvt_t e; for (;;) { if (pdTRUE == xQueueReceive(xBlufiTaskQueue, &e, (portTickType)portMAX_DELAY)) { - switch (e->sig) { + switch (e.sig) { case BLUFI_SIG_SWITCH_CONTEXT: - if (e->cb) { - ((BtTaskCb_t)e->cb)(e->arg); + if (e.cb) { + ((BtTaskCb_t)e.cb)(e.arg); } break; default: break; } - osi_free(e); } } } static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg) { + BtTaskEvt_t evt; - BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); - if (evt == NULL) - return -1; - - evt->sig = sig; - evt->par = par; - evt->cb = cb; - evt->arg = arg; + evt.sig = sig; + evt.par = par; + evt.cb = cb; + evt.arg = arg; if (xQueueSend(xBlufiTaskQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { LOG_ERROR("Blufi Post failed\n"); @@ -97,7 +93,7 @@ static void blufi_task_deinit(void) static void blufi_task_init(void) { - xBlufiTaskQueue = xQueueCreate(10, sizeof(void *)); + xBlufiTaskQueue = xQueueCreate(10, sizeof(BtTaskEvt_t)); xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle); } From 224acf37f6e9e6e2a5b959c9e713564ea3fc2266 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Sat, 5 Nov 2016 20:40:07 +0800 Subject: [PATCH 29/31] component/bt : api category --- .../bt_app_sec.c => api/esp_app_sec.c} | 2 +- .../bt_gap_api.c => api/esp_gap_api.c} | 2 +- .../bt_app_api.c => api/esp_gatt_api.c} | 2 +- .../bt_sdp_api.c => api/esp_sdp_api.c} | 2 +- .../include/esp_bt_common.h} | 6 +++--- .../include/esp_bt_defs.h} | 7 +++---- .../include/esp_gap_api.h} | 8 ++++---- .../include/esp_gatt_api.h} | 19 ++++--------------- .../include/esp_sdp_api.h} | 11 +++++------ .../include/esp_sec_api.h} | 16 +++------------- .../profiles/esp/blufi/include/blufi_adv.h | 2 +- .../profiles/esp/include/button_pro.h | 4 ++-- .../bluedroid/profiles/std/include/dis_api.h | 2 +- .../bluedroid/profiles/std/include/prf_defs.h | 2 +- components/bt/component.mk | 4 ++-- .../app_client_profiles/battery_c/battery_c.c | 2 +- .../bluedroid_demos/app_core/bt_app.c | 2 +- .../app_project/SampleServerProject.c | 4 ++-- .../bluedroid_demos}/include/bt_app_common.h | 0 19 files changed, 37 insertions(+), 60 deletions(-) rename components/bt/bluedroid/{stack_api/bt_app_sec.c => api/esp_app_sec.c} (99%) rename components/bt/bluedroid/{stack_api/bt_gap_api.c => api/esp_gap_api.c} (98%) rename components/bt/bluedroid/{stack_api/bt_app_api.c => api/esp_gatt_api.c} (99%) rename components/bt/bluedroid/{stack_api/bt_sdp_api.c => api/esp_sdp_api.c} (99%) rename components/bt/bluedroid/{stack_api/include/bt_api_common.h => api/include/esp_bt_common.h} (66%) rename components/bt/bluedroid/{stack_api/include/bt_app_defs.h => api/include/esp_bt_defs.h} (99%) rename components/bt/bluedroid/{stack_api/include/bt_gap_api.h => api/include/esp_gap_api.h} (68%) rename components/bt/bluedroid/{stack_api/include/bt_app_api.h => api/include/esp_gatt_api.h} (98%) rename components/bt/bluedroid/{stack_api/include/bt_sdp_api.h => api/include/esp_sdp_api.h} (93%) rename components/bt/bluedroid/{stack_api/include/bt_app_sec.h => api/include/esp_sec_api.h} (65%) rename {components/bt/bluedroid/stack_api => examples/06_bluedroid_demos/components/bluedroid_demos}/include/bt_app_common.h (100%) diff --git a/components/bt/bluedroid/stack_api/bt_app_sec.c b/components/bt/bluedroid/api/esp_app_sec.c similarity index 99% rename from components/bt/bluedroid/stack_api/bt_app_sec.c rename to components/bt/bluedroid/api/esp_app_sec.c index fa4831650..60d48bf04 100644 --- a/components/bt/bluedroid/stack_api/bt_app_sec.c +++ b/components/bt/bluedroid/api/esp_app_sec.c @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_app_sec.h" #include // standard library #include +#include "esp_sec_api.h" extern void srand (unsigned int seed); diff --git a/components/bt/bluedroid/stack_api/bt_gap_api.c b/components/bt/bluedroid/api/esp_gap_api.c similarity index 98% rename from components/bt/bluedroid/stack_api/bt_gap_api.c rename to components/bt/bluedroid/api/esp_gap_api.c index 65feb289b..7313e4a17 100644 --- a/components/bt/bluedroid/stack_api/bt_gap_api.c +++ b/components/bt/bluedroid/api/esp_gap_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_gap_api.h" +#include "esp_gap_api.h" #include "bta_api.h" #include "bt_trace.h" diff --git a/components/bt/bluedroid/stack_api/bt_app_api.c b/components/bt/bluedroid/api/esp_gatt_api.c similarity index 99% rename from components/bt/bluedroid/stack_api/bt_app_api.c rename to components/bt/bluedroid/api/esp_gatt_api.c index 7b23880d1..20e2b1ad4 100644 --- a/components/bt/bluedroid/stack_api/bt_app_api.c +++ b/components/bt/bluedroid/api/esp_gatt_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_app_api.h" +#include "esp_gatt_api.h" #include "btm_ble_api.h" //#include "btm_ble_int.h" diff --git a/components/bt/bluedroid/stack_api/bt_sdp_api.c b/components/bt/bluedroid/api/esp_sdp_api.c similarity index 99% rename from components/bt/bluedroid/stack_api/bt_sdp_api.c rename to components/bt/bluedroid/api/esp_sdp_api.c index 66330bb29..a64988226 100644 --- a/components/bt/bluedroid/stack_api/bt_sdp_api.c +++ b/components/bt/bluedroid/api/esp_sdp_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_sdp_api.h" +#include "esp_sdp_api.h" esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback) diff --git a/components/bt/bluedroid/stack_api/include/bt_api_common.h b/components/bt/bluedroid/api/include/esp_bt_common.h similarity index 66% rename from components/bt/bluedroid/stack_api/include/bt_api_common.h rename to components/bt/bluedroid/api/include/esp_bt_common.h index 7c4859db2..ea9404ff1 100644 --- a/components/bt/bluedroid/stack_api/include/bt_api_common.h +++ b/components/bt/bluedroid/api/include/esp_bt_common.h @@ -1,5 +1,5 @@ -#ifndef __BT_API_COMMON_H__ -#define __BT_API_COMMON_H__ +#ifndef __ESP_BT_COMMON_H__ +#define __ESP_BT_COMMON_H__ #include @@ -10,4 +10,4 @@ typedef tBT_UUID esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */ typedef BD_ADDR esp_bd_addr_t; /* BD_ADDR in bt_types.h */ -#endif /* __BT_API_COMMON_H__ */ +#endif /* __ESP_BT_COMMON_H__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_app_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h similarity index 99% rename from components/bt/bluedroid/stack_api/include/bt_app_defs.h rename to components/bt/bluedroid/api/include/esp_bt_defs.h index 91ecdcaf1..a6fee49bc 100644 --- a/components/bt/bluedroid/stack_api/include/bt_app_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -1,6 +1,5 @@ - -#ifndef _BT_APP_DEFS_H__ -#define _BT_APP_DEFS_H__ +#ifndef __ESP_BT_DEFS_H__ +#define __ESP_BT_DEFS_H__ #include "bta_api.h" @@ -329,4 +328,4 @@ extern void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, -#endif ///_BT_APP_DEFS_H__ \ No newline at end of file +#endif ///__ESP_BT_DEFS_H__ diff --git a/components/bt/bluedroid/stack_api/include/bt_gap_api.h b/components/bt/bluedroid/api/include/esp_gap_api.h similarity index 68% rename from components/bt/bluedroid/stack_api/include/bt_gap_api.h rename to components/bt/bluedroid/api/include/esp_gap_api.h index ac74996f5..809da0a19 100644 --- a/components/bt/bluedroid/stack_api/include/bt_gap_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_api.h @@ -1,10 +1,10 @@ -#ifndef __BT_GAP_API_H__ -#define __BT_GAP_API_H__ +#ifndef __ESP_GAP_API_H__ +#define __ESP_GAP_API_H__ #include #include "esp_err.h" -#include "bt_api_common.h" +#include "esp_bt_common.h" enum { BT_SCAN_MODE_NONE, @@ -15,4 +15,4 @@ typedef uint16_t bt_scan_mode_t; esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode); -#endif /* __BT_GAP_API_H__ */ +#endif /* __ESP_GAP_API_H__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_app_api.h b/components/bt/bluedroid/api/include/esp_gatt_api.h similarity index 98% rename from components/bt/bluedroid/stack_api/include/bt_app_api.h rename to components/bt/bluedroid/api/include/esp_gatt_api.h index fc557e3aa..7a0992165 100644 --- a/components/bt/bluedroid/stack_api/include/bt_app_api.h +++ b/components/bt/bluedroid/api/include/esp_gatt_api.h @@ -1,19 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +#ifndef __ESP_GATT_API_H__ +#define __ESP_GATT_API_H__ #include "bt_types.h" -#include "bt_app_defs.h" +#include "esp_bt_defs.h" #include "bta_gatt_api.h" #include "bt_prf_sys.h" @@ -921,4 +910,4 @@ void esp_ble_gatts_close(uint16_t conn_id); void esp_prf_app_register(uint8_t prf_id, void *p_cback); - +#endif /* __ESP_GATT_API_H__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_sdp_api.h b/components/bt/bluedroid/api/include/esp_sdp_api.h similarity index 93% rename from components/bt/bluedroid/stack_api/include/bt_sdp_api.h rename to components/bt/bluedroid/api/include/esp_sdp_api.h index a4b8f2d2a..3b5b587ad 100644 --- a/components/bt/bluedroid/stack_api/include/bt_sdp_api.h +++ b/components/bt/bluedroid/api/include/esp_sdp_api.h @@ -1,9 +1,9 @@ -#ifndef __BT_SDP_API_H__ -#define __BT_SDP_API_H__ +#ifndef __ESP_SDP_API_H__ +#define __ESP_SDP_API_H__ #include #include "esp_err.h" -#include "bt_api_common.h" +#include "esp_bt_common.h" #include "bta_sdp_api.h" #include "bt_sdp.h" @@ -113,6 +113,5 @@ bool esp_bt_sdp_add_service_class_id_list(uint32_t handle, uint16_t *p_service_uuids); bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id); -/**********************************************************************************************/ -/**********************************************************************************************/ -#endif /* __BT_SDP_API_H__ */ + +#endif /* __ESP_SDP_API_H__ */ diff --git a/components/bt/bluedroid/stack_api/include/bt_app_sec.h b/components/bt/bluedroid/api/include/esp_sec_api.h similarity index 65% rename from components/bt/bluedroid/stack_api/include/bt_app_sec.h rename to components/bt/bluedroid/api/include/esp_sec_api.h index 6b7310fd9..e078d73ff 100644 --- a/components/bt/bluedroid/stack_api/include/bt_app_sec.h +++ b/components/bt/bluedroid/api/include/esp_sec_api.h @@ -1,16 +1,5 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +#ifndef __ESP_SEC_API_H__ +#define __ESP_SEC_API_H__ #include "bt_types.h" @@ -76,3 +65,4 @@ void app_ble_sec_gen_ltk(UINT8 key_size); void app_ble_security_start(void); +#endif /* __ESP_SEC_API_H__ */ diff --git a/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h index 1b1185ee4..a01b288c4 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h +++ b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h @@ -3,7 +3,7 @@ #include "bta_api.h" #include "btm_ble_api.h" -#include "bt_app_defs.h" +#include "esp_bt_defs.h" typedef struct { diff --git a/components/bt/bluedroid/profiles/esp/include/button_pro.h b/components/bt/bluedroid/profiles/esp/include/button_pro.h index 67d4de4e4..f6397f253 100644 --- a/components/bt/bluedroid/profiles/esp/include/button_pro.h +++ b/components/bt/bluedroid/profiles/esp/include/button_pro.h @@ -18,7 +18,7 @@ #include "bt_target.h" #include "gatt_api.h" #include "gattdefs.h" -#include "bt_app_api.h" +#include "esp_gatt_api.h" #define KEY_SUCCESS GATT_SUCCESS #define KEY_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER @@ -123,4 +123,4 @@ void button_msg_notify(uint16_t len, uint8_t *button_msg); extern button_env_cb_t button_cb_env; -#endif ///BUT_PROFILE_CFG \ No newline at end of file +#endif ///BUT_PROFILE_CFG diff --git a/components/bt/bluedroid/profiles/std/include/dis_api.h b/components/bt/bluedroid/profiles/std/include/dis_api.h index f84a7e62f..95bf24ac5 100644 --- a/components/bt/bluedroid/profiles/std/include/dis_api.h +++ b/components/bt/bluedroid/profiles/std/include/dis_api.h @@ -28,7 +28,7 @@ #include "bt_target.h" #include "gatt_api.h" #include "gattdefs.h" -#include "bt_app_api.h" +#include "esp_gatt_api.h" #define DIS_SUCCESS GATT_SUCCESS #define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER diff --git a/components/bt/bluedroid/profiles/std/include/prf_defs.h b/components/bt/bluedroid/profiles/std/include/prf_defs.h index 8b9ed62ef..242bb27fa 100644 --- a/components/bt/bluedroid/profiles/std/include/prf_defs.h +++ b/components/bt/bluedroid/profiles/std/include/prf_defs.h @@ -20,7 +20,7 @@ #include "bta_gatts_int.h" #include "bta_gatt_api.h" #include "bt_types.h" -#include "bt_app_defs.h" +#include "esp_bt_defs.h" #define ATT_HANDLE_LEN 0x0002 diff --git a/components/bt/component.mk b/components/bt/component.mk index 5bb01a813..9ba0d1664 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -27,7 +27,7 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \ bluedroid/stack/sdp/include \ bluedroid/stack/smp/include \ bluedroid/stack/include \ - bluedroid/stack_api/include \ + bluedroid/api/include \ bluedroid/include \ include @@ -77,7 +77,7 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \ bluedroid/stack/sdp \ bluedroid/stack/smp \ bluedroid/stack \ - bluedroid/stack_api \ + bluedroid/api \ bluedroid \ . diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c index f5cd9964b..9500f7709 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_client_profiles/battery_c/battery_c.c @@ -31,7 +31,7 @@ #include "btm_api.h" #include "bt_types.h" #include "gattc_profile.h" -#include "bt_app_api.h" +#include "esp_gatt_api.h" #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c index 7507aa844..1f699201f 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_app_defs.h" +#include "esp_bt_defs.h" /******************************************************************************* diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c index c631cac1e..e87f33783 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_project/SampleServerProject.c @@ -47,12 +47,12 @@ #include "app_button.h" #include "hid_le_prf.h" -#include "bt_app_api.h" +#include "esp_gatt_api.h" // #include "hcimsgs.h" -#include "bt_app_defs.h" +#include "esp_bt_defs.h" #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" diff --git a/components/bt/bluedroid/stack_api/include/bt_app_common.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h similarity index 100% rename from components/bt/bluedroid/stack_api/include/bt_app_common.h rename to examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h From 3b489f04f0b8e5a77225f84c573b7706e31c3e51 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Sun, 6 Nov 2016 23:31:50 +0800 Subject: [PATCH 30/31] component:bt : change adv api --- components/bt/bluedroid/api/esp_adv_api.c | 345 ++++++++++++++++++ components/bt/bluedroid/api/esp_gatt_api.c | 159 -------- .../bt/bluedroid/api/include/esp_adv_api.h | 106 ++++++ .../bt/bluedroid/api/include/esp_gatt_api.h | 84 ----- .../bluedroid_demos/app_core/bt_app.c | 186 ---------- 5 files changed, 451 insertions(+), 429 deletions(-) create mode 100644 components/bt/bluedroid/api/esp_adv_api.c create mode 100644 components/bt/bluedroid/api/include/esp_adv_api.h delete mode 100644 examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c diff --git a/components/bt/bluedroid/api/esp_adv_api.c b/components/bt/bluedroid/api/esp_adv_api.c new file mode 100644 index 000000000..81eb91286 --- /dev/null +++ b/components/bt/bluedroid/api/esp_adv_api.c @@ -0,0 +1,345 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "esp_bt_defs.h" + + + /******************************************************************************* + ** + ** Function esp_ble_config_adv_data + ** + ** Description This function is called to override the BTA default ADV parameters. + ** + ** adv_data: Pointer to User defined ADV data structure. This + ** memory space can not be freed until p_adv_data_cback + ** is received. + ** p_adv_data_cback: set adv data complete callback. + ** + ** Returns None + ** + *******************************************************************************/ + void esp_ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback) +{ + tBTA_BLE_AD_MASK data_mask = 0; + if(adv_data->adv_name != NULL) + { + data_mask |= BTM_BLE_AD_BIT_DEV_NAME; + BTA_DmSetDeviceName(adv_data->adv_name); + } + if(adv_data->ble_adv_data.int_range.low != 0 || + adv_data->ble_adv_data.int_range.hi != 0) + data_mask |= BTM_BLE_AD_BIT_INT_RANGE; + + if(adv_data->ble_adv_data.p_manu != NULL) + { + data_mask |= BTM_BLE_AD_BIT_MANU; + } + + if(adv_data->ble_adv_data.p_services != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE; + } + + if(adv_data->ble_adv_data.p_service_32b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_32; + } + + if(adv_data->ble_adv_data.p_services_128b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_128; + } + + if(adv_data->ble_adv_data.p_sol_services != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; + } + + if(adv_data->ble_adv_data.p_sol_service_32b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; + } + + if(adv_data->ble_adv_data.p_sol_service_128b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; + } + + if(adv_data->ble_adv_data.p_service_data != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; + } + + if(adv_data->ble_adv_data.appearance != 0) + { + data_mask |= BTM_BLE_AD_BIT_APPEARANCE; + } + + if(adv_data->ble_adv_data.p_proprietary != NULL) + { + data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; + } + + if(adv_data->ble_adv_data.tx_power != 0) + { + data_mask |= BTM_BLE_AD_BIT_TX_PWR; + } + + BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback); +} + + +/******************************************************************************* +** +** Function esp_ble_set_scan_rsp +** +** Description This function is called to override the app scan response. +** +** Parameters Pointer to User defined ADV data structure +** +** Returns None +** +*******************************************************************************/ +void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, + esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback) +{ + tBTA_BLE_AD_MASK data_mask = 0; + if(scan_rsp_data->adv_name != NULL) + { + data_mask |= BTM_BLE_AD_BIT_DEV_NAME; + BTA_DmSetDeviceName(scan_rsp_data->adv_name); + } + if(scan_rsp_data->ble_adv_data.int_range.low != 0 || + scan_rsp_data->ble_adv_data.int_range.hi != 0) + data_mask |= BTM_BLE_AD_BIT_INT_RANGE; + + if(scan_rsp_data->ble_adv_data.p_manu != NULL) + { + data_mask |= BTM_BLE_AD_BIT_MANU; + } + + if(scan_rsp_data->ble_adv_data.p_services != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE; + } + + if(scan_rsp_data->ble_adv_data.p_service_32b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_32; + } + + if(scan_rsp_data->ble_adv_data.p_services_128b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_128; + } + + if(scan_rsp_data->ble_adv_data.p_sol_services != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; + } + + if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; + } + + if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; + } + + if(scan_rsp_data->ble_adv_data.p_service_data != NULL) + { + data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; + } + + if(scan_rsp_data->ble_adv_data.appearance != 0) + { + data_mask |= BTM_BLE_AD_BIT_APPEARANCE; + } + + if(scan_rsp_data->ble_adv_data.p_proprietary != NULL) + { + data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; + } + + if(scan_rsp_data->ble_adv_data.tx_power != 0) + { + data_mask |= BTM_BLE_AD_BIT_TX_PWR; + } + + BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback); +} + +#if 0 + +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) +{ + if(adv_data != NULL) + { + ble_config_adv_data(adv_data, adv_data_cback); + }else{ + LOG_ERROR("The adv_data is NULL\n"); + } + + if(++adv_data != NULL) + { + ble_set_scan_rsp(adv_data, NULL); + } + +} +#endif + +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) +{ + if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || + !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) + { + LOG_ERROR("Invalid advertisting interval parameters.\n"); + return ; + } + + if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) && + (ble_adv_params->adv_type > API_BROADCASTER_MODE) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) && + (ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) ) + { + LOG_ERROR("Invalid advertisting type parameters.\n"); + return; + } + + LOG_ERROR("API_Ble_AppStartAdvertising\n"); + + /// + BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, + ble_adv_params->adv_int_max, + ble_adv_params->adv_type, + ble_adv_params->addr_type_own, + ble_adv_params->channel_map, + ble_adv_params->adv_filter_policy, + ble_adv_params->p_dir_bda); + + +} + + +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback) +{ + if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && + API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && + (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) + { + BTA_DmSetBleScanFilterParams(client_if, + scan_params->scan_intv, + scan_params->scan_win, + scan_params->scan_type, + scan_params->scan_fil_policy, + scan_params->addr_type_own, + scan_param_setup_cback); + } +} + + +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) +{ + if((duration != 0) && (results_cb != NULL)) + { + ///Start scan the device + BTA_DmBleObserve(true, duration, results_cb); + }else{ + LOG_ERROR("The scan duration or p_results_cb invalid\n"); + } +} + + +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ +void esp_ble_stop_advertising (void) +{ + bool stop_adv = false; + + BTA_DmBleBroadcast(stop_adv); +} + + + diff --git a/components/bt/bluedroid/api/esp_gatt_api.c b/components/bt/bluedroid/api/esp_gatt_api.c index 20e2b1ad4..b322c6dae 100644 --- a/components/bt/bluedroid/api/esp_gatt_api.c +++ b/components/bt/bluedroid/api/esp_gatt_api.c @@ -16,165 +16,6 @@ #include "btm_ble_api.h" //#include "btm_ble_int.h" - - -/******************************************************************************* -** -** @function esp_ble_config_adv_data -** -** @brief This function is called to override the BTA default ADV parameters. -** -** @param[in] adv_data: Pointer to User defined ADV data structure. This -** memory space can not be freed until p_adv_data_cback -** is received. -** @param[in|out] adv_data_cback: set adv data complete callback. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, - esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback) -{ - if(adv_data != NULL) - { - ble_config_adv_data(adv_data, adv_data_cback); - }else{ - LOG_ERROR("The adv_data is NULL\n"); - } - - if(++adv_data != NULL) - { - ble_set_scan_rsp(adv_data, NULL); - } - -} - - -/******************************************************************************* -** -** @function esp_ble_start_advertising -** -** @brief This function is called to start advertising. -** -** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params) -{ - if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || - !API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) - { - LOG_ERROR("Invalid advertisting interval parameters.\n"); - return ; - } - - if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) && - (ble_adv_params->adv_type > API_BROADCASTER_MODE) ) - { - LOG_ERROR("Invalid advertisting type parameters.\n"); - return; - } - - if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) && - (ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) ) - { - LOG_ERROR("Invalid advertisting type parameters.\n"); - return; - } - - LOG_ERROR("API_Ble_AppStartAdvertising\n"); - - /// - BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, - ble_adv_params->adv_int_max, - ble_adv_params->adv_type, - ble_adv_params->addr_type_own, - ble_adv_params->channel_map, - ble_adv_params->adv_filter_policy, - ble_adv_params->p_dir_bda); - - -} - - -/******************************************************************************* -** -** @function esp_ble_set_scan_params -** -** @brief This function is called to set scan parameters -** -** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This -** memory space can not be freed until scan_param_setup_cback -** @param[in] client_if: Client interface ID -** @param[in|out] scan_param_setup_status_cback - Set scan param status callback -** -** @return None -** -*******************************************************************************/ -void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, - esp_scan_param_setup_cb_t scan_param_setup_cback) -{ - if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && - API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && - (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) - { - BTA_DmSetBleScanFilterParams(client_if, - scan_params->scan_intv, - scan_params->scan_win, - scan_params->scan_type, - scan_params->scan_fil_policy, - scan_params->addr_type_own, - scan_param_setup_cback); - } -} - - -/******************************************************************************* -** -** @function esp_ble_start_scanning -** -** @brief This procedure keep the device scanning the peer device whith advertising on the air -** -** @param[in] duration: Keeping the scaning time, the unit is second. -** @param[in|out] results_cb: The scanning function callback when the peer device has been scan -** which advertising on the air -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb) -{ - if((duration != 0) && (results_cb != NULL)) - { - ///Start scan the device - BTA_DmBleObserve(true, duration, results_cb); - }else{ - LOG_ERROR("The scan duration or p_results_cb invalid\n"); - } -} - - -/******************************************************************************* -** -** @function esp_ble_stop_advertising -** -** @brief This function is called to stop advertising. -** -** @param None -** -** @return None -** -*******************************************************************************/ -void esp_ble_stop_advertising (void) -{ - bool stop_adv = false; - - BTA_DmBleBroadcast(stop_adv); -} - - /******************************************************************************* ** ** @function esp_ble_update_conn_params diff --git a/components/bt/bluedroid/api/include/esp_adv_api.h b/components/bt/bluedroid/api/include/esp_adv_api.h new file mode 100644 index 000000000..88790183b --- /dev/null +++ b/components/bt/bluedroid/api/include/esp_adv_api.h @@ -0,0 +1,106 @@ +#ifndef __ESP_ADV_API_H__ +#define __ESP_ADV_API_H__ + +#include "bt_types.h" +#include "esp_bt_defs.h" +#include "bta_gatt_api.h" +#include "bt_prf_sys.h" + + +/******************************************************************************* +** +** @function esp_ble_config_adv_data +** +** @brief This function is called to override the BTA default ADV parameters. +** +** @param[in] adv_data: Pointer to User defined ADV data structure. This +** memory space can not be freed until p_adv_data_cback +** is received. +** @param[in|out] adv_data_cback: set adv data complete callback. +** +** @return None +** +*******************************************************************************/ +void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback); + + +/******************************************************************************* +** +** Function esp_ble_set_scan_rsp +** +** Description This function is called to override the app scan response. +** +** Parameters Pointer to User defined ADV data structure +** +** Returns None +** +*******************************************************************************/ +void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, + esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback); + + +/******************************************************************************* +** +** @function esp_ble_set_scan_params +** +** @brief This function is called to set scan parameters +** +** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This +** memory space can not be freed until scan_param_setup_cback +** @param[in] client_if: Client interface ID +** @param[in|out] scan_param_setup_status_cback - Set scan param status callback +** +** @return None +** +*******************************************************************************/ +void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, + esp_scan_param_setup_cb_t scan_param_setup_cback); + + +/******************************************************************************* +** +** @function esp_ble_start_scanning +** +** @brief This procedure keep the device scanning the peer device whith advertising on the air +** +** @param[in] duration: Keeping the scaning time, the unit is second. +** @param[in|out] results_cb: The scanning function callback when the peer device has been scan +** which advertising on the air +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb); + + + +/******************************************************************************* +** +** @function esp_ble_start_advertising +** +** @brief This function is called to start advertising. +** +** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. +** +** @return None +** +*******************************************************************************/ +void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params); + + + +/******************************************************************************* +** +** @function esp_ble_stop_advertising +** +** @brief This function is called to stop advertising. +** +** @param None +** +** @return None +** +*******************************************************************************/ +void esp_ble_stop_advertising (void); + +#endif /* __ESP_ADV_API_H__ */ diff --git a/components/bt/bluedroid/api/include/esp_gatt_api.h b/components/bt/bluedroid/api/include/esp_gatt_api.h index 7a0992165..53fcf7a2c 100644 --- a/components/bt/bluedroid/api/include/esp_gatt_api.h +++ b/components/bt/bluedroid/api/include/esp_gatt_api.h @@ -7,90 +7,6 @@ #include "bt_prf_sys.h" -/******************************************************************************* -** -** @function esp_ble_config_adv_data -** -** @brief This function is called to override the BTA default ADV parameters. -** -** @param[in] adv_data: Pointer to User defined ADV data structure. This -** memory space can not be freed until p_adv_data_cback -** is received. -** @param[in|out] adv_data_cback: set adv data complete callback. -** -** @return None -** -*******************************************************************************/ -void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data, - esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback); - - - -/******************************************************************************* -** -** @function esp_ble_set_scan_params -** -** @brief This function is called to set scan parameters -** -** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This -** memory space can not be freed until scan_param_setup_cback -** @param[in] client_if: Client interface ID -** @param[in|out] scan_param_setup_status_cback - Set scan param status callback -** -** @return None -** -*******************************************************************************/ -void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if, - esp_scan_param_setup_cb_t scan_param_setup_cback); - - -/******************************************************************************* -** -** @function esp_ble_start_scanning -** -** @brief This procedure keep the device scanning the peer device whith advertising on the air -** -** @param[in] duration: Keeping the scaning time, the unit is second. -** @param[in|out] results_cb: The scanning function callback when the peer device has been scan -** which advertising on the air -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb); - - - -/******************************************************************************* -** -** @function esp_ble_start_advertising -** -** @brief This function is called to start advertising. -** -** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure. -** -** @return None -** -*******************************************************************************/ -void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params); - - - -/******************************************************************************* -** -** @function esp_ble_stop_advertising -** -** @brief This function is called to stop advertising. -** -** @param None -** -** @return None -** -*******************************************************************************/ -void esp_ble_stop_advertising (void); - - - /******************************************************************************* ** ** @function esp_ble_update_conn_params diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c deleted file mode 100644 index 1f699201f..000000000 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app.c +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "esp_bt_defs.h" - - - /******************************************************************************* - ** - ** Function ESP_AppConfigadvData - ** - ** Description This function is called to override the BTA default ADV parameters. - ** - ** adv_data: Pointer to User defined ADV data structure. This - ** memory space can not be freed until p_adv_data_cback - ** is received. - ** p_adv_data_cback: set adv data complete callback. - ** - ** Returns None - ** - *******************************************************************************/ - void ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) -{ - tBTA_BLE_AD_MASK data_mask = 0; - if(adv_data->adv_name != NULL) - { - data_mask |= BTM_BLE_AD_BIT_DEV_NAME; - BTA_DmSetDeviceName(adv_data->adv_name); - } - if(adv_data->ble_adv_data.int_range.low != 0 || - adv_data->ble_adv_data.int_range.hi != 0) - data_mask |= BTM_BLE_AD_BIT_INT_RANGE; - - if(adv_data->ble_adv_data.p_manu != NULL) - { - data_mask |= BTM_BLE_AD_BIT_MANU; - } - - if(adv_data->ble_adv_data.p_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE; - } - - if(adv_data->ble_adv_data.p_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32; - } - - if(adv_data->ble_adv_data.p_services_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128; - } - - if(adv_data->ble_adv_data.p_sol_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; - } - - if(adv_data->ble_adv_data.p_sol_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; - } - - if(adv_data->ble_adv_data.p_sol_service_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; - } - - if(adv_data->ble_adv_data.p_service_data != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; - } - - if(adv_data->ble_adv_data.appearance != 0) - { - data_mask |= BTM_BLE_AD_BIT_APPEARANCE; - } - - if(adv_data->ble_adv_data.p_proprietary != NULL) - { - data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; - } - - if(adv_data->ble_adv_data.tx_power != 0) - { - data_mask |= BTM_BLE_AD_BIT_TX_PWR; - } - - BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback); -} - - -/******************************************************************************* -** -** Function ESP_BleSetScanRsp -** -** Description This function is called to override the app scan response. -** -** Parameters Pointer to User defined ADV data structure -** -** Returns None -** -*******************************************************************************/ -void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback) -{ - tBTA_BLE_AD_MASK data_mask = 0; - if(scan_rsp_data->adv_name != NULL) - { - data_mask |= BTM_BLE_AD_BIT_DEV_NAME; - BTA_DmSetDeviceName(scan_rsp_data->adv_name); - } - if(scan_rsp_data->ble_adv_data.int_range.low != 0 || - scan_rsp_data->ble_adv_data.int_range.hi != 0) - data_mask |= BTM_BLE_AD_BIT_INT_RANGE; - - if(scan_rsp_data->ble_adv_data.p_manu != NULL) - { - data_mask |= BTM_BLE_AD_BIT_MANU; - } - - if(scan_rsp_data->ble_adv_data.p_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE; - } - - if(scan_rsp_data->ble_adv_data.p_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32; - } - - if(scan_rsp_data->ble_adv_data.p_services_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128; - } - - if(scan_rsp_data->ble_adv_data.p_sol_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; - } - - if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; - } - - if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; - } - - if(scan_rsp_data->ble_adv_data.p_service_data != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; - } - - if(scan_rsp_data->ble_adv_data.appearance != 0) - { - data_mask |= BTM_BLE_AD_BIT_APPEARANCE; - } - - if(scan_rsp_data->ble_adv_data.p_proprietary != NULL) - { - data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; - } - - if(scan_rsp_data->ble_adv_data.tx_power != 0) - { - data_mask |= BTM_BLE_AD_BIT_TX_PWR; - } - - BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback); -} - - From 118984283aec37fbdf16f28fe3bdbe881377c5f4 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Mon, 7 Nov 2016 02:16:00 +0800 Subject: [PATCH 31/31] component/bt : blufi use api 1. use api 2. bluetooth init/deinit/enable/disable wrap api(1st version) 3. bluetooth deinit(free resource) still some problem --- components/bt/bluedroid/api/esp_bt_common.c | 30 ++++ .../bt/bluedroid/api/include/esp_bt_common.h | 73 ++++++++- components/bt/bluedroid/main/bte_main.c | 24 ++- .../bluedroid/profiles/esp/blufi/blufi_adv.c | 144 +----------------- .../bluedroid/profiles/esp/blufi/blufi_prf.c | 92 ++++++----- .../profiles/esp/blufi/include/blufi_adv.h | 14 +- examples/07_blufi/components/blufi/blufi.c | 27 +++- .../07_blufi/components/blufi/blufi_task.c | 12 +- .../07_blufi/components/blufi/include/blufi.h | 11 +- examples/07_blufi/main/demo_main.c | 14 +- 10 files changed, 230 insertions(+), 211 deletions(-) create mode 100644 components/bt/bluedroid/api/esp_bt_common.c diff --git a/components/bt/bluedroid/api/esp_bt_common.c b/components/bt/bluedroid/api/esp_bt_common.c new file mode 100644 index 000000000..868b6a7a9 --- /dev/null +++ b/components/bt/bluedroid/api/esp_bt_common.c @@ -0,0 +1,30 @@ +#include "esp_bt_defs.h" +#include "esp_bt_common.h" +#include "esp_err.h" + +extern int bte_main_boot_entry(void *cb); +extern int bte_main_shutdown(void); + +// tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback) +esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t *p_cback) +{ + return BTA_EnableBluetooth(p_cback) == BTA_SUCCESS ? ESP_OK : ESP_FAIL; +} + +esp_err_t esp_disable_bluetooth(void) +{ + return BTA_DisableBluetooth() == BTA_SUCCESS ? ESP_OK : ESP_FAIL; +} + +esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb) +{ + return bte_main_boot_entry(cb) == 0 ? ESP_OK : ESP_FAIL; +} + + +void esp_deinit_bluetooth(void) +{ + bte_main_shutdown(); +} + + diff --git a/components/bt/bluedroid/api/include/esp_bt_common.h b/components/bt/bluedroid/api/include/esp_bt_common.h index ea9404ff1..4886b12bb 100644 --- a/components/bt/bluedroid/api/include/esp_bt_common.h +++ b/components/bt/bluedroid/api/include/esp_bt_common.h @@ -4,10 +4,81 @@ #include #include "bt_types.h" - +#include "bta_api.h" +#include "esp_err.h" typedef tBT_UUID esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */ typedef BD_ADDR esp_bd_addr_t; /* BD_ADDR in bt_types.h */ +typedef tBTA_DM_SEC_CBACK esp_bt_sec_cb_t; + +typedef void (*bluetooth_init_cb_t)(void); + +/******************************************************************************* +** +** @function esp_enable_bluetooth +** +** @brief This function is called to enable bluetooth host. This +** function must be called before any other functions in the +** API (except esp_bluetooth_init) are called. +** +** @param[in] p_cback: +** security call back function +** @param[out] None +** +** @return ESP_OK - Success; Other - Failed +** +*******************************************************************************/ +esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t p_cback); + + +/******************************************************************************* +** +** @function esp_disable_bluetooth +** +** @brief This function is called to disable bluetooth host +** +** @param[in] None +** +** @param[out] None +** +** @return ESP_OK - Success; Other - Failed +** +*******************************************************************************/ +esp_err_t esp_disable_bluetooth(void); + +/******************************************************************************* +** +** @function esp_init_bluetooth +** +** @brief This function is called to init bluetooth host and alloc the +** resource. This function must be called before all othor API +** are called. +** +** @param[in] cb: When this function called success, the callback will be called +** +** @param[out] None +** +** @return ESP_OK - Success; Other - Failed +** +*******************************************************************************/ +esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb); + +/******************************************************************************* +** +** @function esp_deinit_bluetooth +** +** @brief This function is called to deinit bluetooth host and free the +** resource. +** +** @param[in] None +** +** @param[out] None +** +** @return ESP_OK - Success; Other - Failed +** +*******************************************************************************/ +void esp_deinit_bluetooth(void); + #endif /* __ESP_BT_COMMON_H__ */ diff --git a/components/bt/bluedroid/main/bte_main.c b/components/bt/bluedroid/main/bte_main.c index 0ad3cee60..bbe509a50 100755 --- a/components/bt/bluedroid/main/bte_main.c +++ b/components/bt/bluedroid/main/bte_main.c @@ -89,10 +89,12 @@ ** Static variables *******************************************************************************/ static const hci_t *hci; -static void bte_main_enable(void); + /******************************************************************************* ** Static functions *******************************************************************************/ +static void bte_main_disable(void); +static void bte_main_enable(void); /******************************************************************************* ** Externs @@ -111,19 +113,23 @@ bluedroid_init_done_cb_t bluedroid_init_done_cb; ** Returns None ** ******************************************************************************/ -void bte_main_boot_entry(bluedroid_init_done_cb_t cb) +int bte_main_boot_entry(bluedroid_init_done_cb_t cb) { - if (gki_init()) + if (gki_init()) { LOG_ERROR("%s: Init GKI Module Failure.\n", __func__); + return -1; + } hci = hci_layer_get_interface(); - if (!hci) + if (!hci) { LOG_ERROR("%s could not get hci layer interface.\n", __func__); + return -2; + } btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); if (btu_hci_msg_queue == NULL) { LOG_ERROR("%s unable to allocate hci message queue.\n", __func__); - return; + return -3; } bluedroid_init_done_cb = cb; @@ -140,6 +146,8 @@ void bte_main_boot_entry(bluedroid_init_done_cb_t cb) //Enbale HCI bte_main_enable(); + + return 0; } /****************************************************************************** @@ -151,7 +159,7 @@ void bte_main_boot_entry(bluedroid_init_done_cb_t cb) ** Returns None ** ******************************************************************************/ -void bte_main_shutdown() +void bte_main_shutdown(void) { //data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL); hci->set_data_queue(NULL); @@ -167,6 +175,8 @@ void bte_main_shutdown() */ gki_clean_up(); + + bte_main_disable(); } /****************************************************************************** @@ -202,7 +212,7 @@ static void bte_main_enable(void) ** Returns None ** ******************************************************************************/ -void bte_main_disable(void) +static void bte_main_disable(void) { /* APPL_TRACE_DEBUG("%s", __FUNCTION__); diff --git a/components/bt/bluedroid/profiles/esp/blufi/blufi_adv.c b/components/bt/bluedroid/profiles/esp/blufi/blufi_adv.c index ee95d89b5..2944177f5 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/blufi_adv.c +++ b/components/bt/bluedroid/profiles/esp/blufi/blufi_adv.c @@ -13,7 +13,7 @@ // limitations under the License. #include "blufi_adv.h" - +#include "esp_adv_api.h" /******************************************************************************* ** @@ -29,75 +29,10 @@ ** Returns None ** *******************************************************************************/ - void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) + void BlufiBleConfigadvData(esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback) { - tBTA_BLE_AD_MASK data_mask = 0; - if(adv_data->adv_name != NULL) - { - data_mask |= BTM_BLE_AD_BIT_DEV_NAME; - BTA_DmSetDeviceName(adv_data->adv_name); - } - if(adv_data->ble_adv_data.int_range.low != 0 || - adv_data->ble_adv_data.int_range.hi != 0) - data_mask |= BTM_BLE_AD_BIT_INT_RANGE; - - if(adv_data->ble_adv_data.p_manu != NULL) - { - data_mask |= BTM_BLE_AD_BIT_MANU; - } - - if(adv_data->ble_adv_data.p_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE; - } - - if(adv_data->ble_adv_data.p_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32; - } - - if(adv_data->ble_adv_data.p_services_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128; - } - - if(adv_data->ble_adv_data.p_sol_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; - } - - if(adv_data->ble_adv_data.p_sol_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; - } - - if(adv_data->ble_adv_data.p_sol_service_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; - } - - if(adv_data->ble_adv_data.p_service_data != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; - } - - if(adv_data->ble_adv_data.appearance != 0) - { - data_mask |= BTM_BLE_AD_BIT_APPEARANCE; - } - - if(adv_data->ble_adv_data.p_proprietary != NULL) - { - data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; - } - - if(adv_data->ble_adv_data.tx_power != 0) - { - data_mask |= BTM_BLE_AD_BIT_TX_PWR; - } - - BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback); + esp_ble_config_adv_data(adv_data, p_adv_data_cback); } @@ -112,75 +47,10 @@ ** Returns None ** *******************************************************************************/ -void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback) +void BlufiBleSetScanRsp(esp_ble_adv_data_cfg_t *scan_rsp_data, + esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback) { - tBTA_BLE_AD_MASK data_mask = 0; - if(scan_rsp_data->adv_name != NULL) - { - data_mask |= BTM_BLE_AD_BIT_DEV_NAME; - BTA_DmSetDeviceName(scan_rsp_data->adv_name); - } - if(scan_rsp_data->ble_adv_data.int_range.low != 0 || - scan_rsp_data->ble_adv_data.int_range.hi != 0) - data_mask |= BTM_BLE_AD_BIT_INT_RANGE; - - if(scan_rsp_data->ble_adv_data.p_manu != NULL) - { - data_mask |= BTM_BLE_AD_BIT_MANU; - } - - if(scan_rsp_data->ble_adv_data.p_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE; - } - - if(scan_rsp_data->ble_adv_data.p_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32; - } - - if(scan_rsp_data->ble_adv_data.p_services_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128; - } - - if(scan_rsp_data->ble_adv_data.p_sol_services != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL; - } - - if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL; - } - - if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL; - } - - if(scan_rsp_data->ble_adv_data.p_service_data != NULL) - { - data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA; - } - - if(scan_rsp_data->ble_adv_data.appearance != 0) - { - data_mask |= BTM_BLE_AD_BIT_APPEARANCE; - } - - if(scan_rsp_data->ble_adv_data.p_proprietary != NULL) - { - data_mask |= BTM_BLE_AD_BIT_PROPRIETARY; - } - - if(scan_rsp_data->ble_adv_data.tx_power != 0) - { - data_mask |= BTM_BLE_AD_BIT_TX_PWR; - } - - BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback); + esp_ble_set_scan_rsp(scan_rsp_data, p_scan_rsp_data_cback); } diff --git a/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c b/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c index 70237a6e7..7b1fb9c50 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/profiles/esp/blufi/blufi_prf.c @@ -30,6 +30,10 @@ #include "blufi_prf.h" #include "blufi_adv.h" +#include "esp_adv_api.h" +#include "esp_bt_defs.h" +#include "esp_gatt_api.h" + #define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] @@ -41,13 +45,13 @@ UINT8 esp32_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0 tBTA_BLE_MANU p_esp32_manu = {sizeof(esp32_manu),esp32_manu}; /* manufacturer data */ tBTA_BLE_SERVICE esp32_service = { - 0x01, //only one service in the ijiazu button profile + 0x01, //only one service in the blufi profile false, &esp32_uuid }; /* 16 bits services */ -tBLUFI_BLE_ADV_DATA esp32_adv_data[ADV_SCAN_IDX_MAX] = +esp_ble_adv_data_cfg_t esp32_adv_data[ADV_SCAN_IDX_MAX] = { [BLE_ADV_DATA_IDX] = { .adv_name = "Espressif_008", @@ -87,7 +91,21 @@ tBLUFI_BLE_ADV_DATA esp32_adv_data[ADV_SCAN_IDX_MAX] = } }; +tBLE_BD_ADDR peer_bda = { + .type = API_PUBLIC_ADDR, + .bda = {0} +}; +esp_ble_adv_params_all_t adv_params = +{ + .adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100, + .adv_type = API_NON_DISCOVERABLE, + .addr_type_own = API_PUBLIC_ADDR, + .channel_map = ESP_BLE_ADV_CHNL_MAP, + .adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY, + .p_dir_bda = &peer_bda +}; static tBLUFI_CB_ENV blufi_cb_env; @@ -96,7 +114,7 @@ static tBLUFI_CB_ENV blufi_cb_env; /***************************************************************************** ** Constants *****************************************************************************/ -static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); +static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data); /******************************************************************************* @@ -108,24 +126,24 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); ** Returns NULL ** *******************************************************************************/ -static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) +static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data) { - tBTA_GATTS_RSP rsp; - tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; + esp_gatts_rsp_t rsp; + esp_bt_uuid_t uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; tBLUFI_INST *p_inst = &blufi_cb_env.blufi_inst; UINT8 net_event = 0xff; UINT8 len = 0; UINT8 *p_rec_data = NULL; - tBTA_GATT_STATUS status; + esp_gatt_status_t status; LOG_DEBUG("blufi profile cb event = %x\n",event); switch(event) { - case BTA_GATTS_REG_EVT: + case ESP_GATTS_REG_EVT: status = p_data->reg_oper.status; LOG_DEBUG("p_data->reg_oper.status = %x\n",p_data->reg_oper.status); LOG_DEBUG("(p_data->reg_oper.uuid.uu.uuid16=%x\n",p_data->reg_oper.uuid.uu.uuid16); - if(p_data->reg_oper.status != BTA_GATT_OK) { + if(p_data->reg_oper.status != ESP_GATT_OK) { LOG_ERROR("blufi profile register failed\n"); return; } @@ -140,14 +158,13 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) BlufiBleConfigadvData(&esp32_adv_data[BLE_ADV_DATA_IDX], NULL); //set the adversting data to the btm layer BlufiBleSetScanRsp(&esp32_adv_data[BLE_SCAN_RSP_DATA_IDX],NULL); - BTA_GATTS_Listen(blufi_cb_env.gatt_if, true, NULL); - + esp_ble_start_advertising(&adv_params); //create the blufi service to the service data base. if(p_data->reg_oper.uuid.uu.uuid16 == SVC_BLUFI_UUID) { blufi_create_service(); } break; - case BTA_GATTS_READ_EVT: + case ESP_GATTS_READ_EVT: memset(&rsp, 0, sizeof(tBTA_GATTS_API_RSP)); rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle; rsp.attr_value.len = 2; @@ -155,11 +172,11 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) //rsp.attr_value.value[1] = 0xed; //rsp.attr_value.value[2] = 0xbe; //rsp.attr_value.value[3] = 0xef; - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,&rsp); break; - case BTA_GATTS_WRITE_EVT: - BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id, + case ESP_GATTS_WRITE_EVT: + esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id, p_data->req_data.status,NULL); LOG_DEBUG("Received blufi data:"); @@ -175,36 +192,36 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) p_inst->blufi_cback(blufi_cb_env.blufi_inst.app_id, net_event, len, p_rec_data); } break; - case BTA_GATTS_CONF_EVT: + case ESP_GATTS_CFM_EVT: /* Nothing */ break; - case BTA_GATTS_CREATE_EVT: + case ESP_GATTS_CREATE_EVT: uuid.uu.uuid16 = CHAR_BLUFI_UUID; blufi_cb_env.clcb.cur_srvc_id = p_data->create.service_id; blufi_cb_env.is_primery = p_data->create.is_primary; //start the blufi service after created - BTA_GATTS_StartService(p_data->create.service_id, BTA_GATT_TRANSPORT_LE); + esp_ble_gatts_start_srvc(p_data->create.service_id); //add the frist blufi characteristic --> write characteristic - BTA_GATTS_AddCharacteristic(blufi_cb_env.clcb.cur_srvc_id, &uuid, + esp_ble_gatts_add_char(blufi_cb_env.clcb.cur_srvc_id, &uuid, (GATT_PERM_WRITE | GATT_PERM_READ), (GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE | GATT_CHAR_PROP_BIT_NOTIFY)); break; - case BTA_GATTS_ADD_CHAR_EVT: + case ESP_GATTS_ADD_CHAR_EVT: if(p_data->add_result.char_uuid.uu.uuid16 == CHAR_BLUFI_UUID) { //save the att handle to the env blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id; uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG; - BTA_GATTS_AddCharDescriptor (blufi_cb_env.clcb.cur_srvc_id, + esp_ble_gatts_add_char_descr(blufi_cb_env.clcb.cur_srvc_id, (GATT_PERM_WRITE|GATT_PERM_WRITE), &uuid); } break; - case BTA_GATTS_ADD_CHAR_DESCR_EVT: + case ESP_GATTS_ADD_CHAR_DESCR_EVT: /* Nothing */ break; - case BTA_GATTS_CONNECT_EVT: + case ESP_GATTS_CONNECT_EVT: //set the connection flag to true blufi_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda); LOG_DEBUG("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n", @@ -213,24 +230,23 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) /*return whether the remote device is currently connected*/ int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda); LOG_DEBUG("is_connected=%d\n",is_connected); - BTA_DmBleBroadcast(0); //stop adv + esp_ble_stop_advertising(); //stop adv break; - case BTA_GATTS_DISCONNECT_EVT: + case ESP_GATTS_DISCONNECT_EVT: //set the connection flag to true blufi_cb_env.clcb.connected = false; + esp_ble_start_advertising(&adv_params); break; - case BTA_GATTS_OPEN_EVT: + case ESP_GATTS_OPEN_EVT: break; - case BTA_GATTS_CLOSE_EVT: + case ESP_GATTS_CLOSE_EVT: if(blufi_cb_env.clcb.connected && (blufi_cb_env.clcb.conn_id == p_data->conn.conn_id)) { //set the connection channal congested flag to true blufi_cb_env.clcb.congest = p_data->congest.congested; } break; - case BTA_GATTS_LISTEN_EVT: - break; - case BTA_GATTS_CONGEST_EVT: + case ESP_GATTS_CONGEST_EVT: break; default: break; @@ -249,8 +265,8 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) *******************************************************************************/ void blufi_create_service(void) { - tBTA_GATTS_IF server_if ; - tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; + esp_gatts_if_t server_if ; + esp_bt_uuid_t uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; UINT16 num_handle = BLUFI_HDL_NUM; UINT8 inst = 0x00; server_if = blufi_cb_env.gatt_if; @@ -260,7 +276,7 @@ void blufi_create_service(void) LOG_ERROR("blufi service added error."); return; } - BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true); + esp_ble_gatts_create_srvc(server_if, &uuid, inst, num_handle, true); } @@ -341,9 +357,9 @@ BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id) ** Description Initializa the GATT Service for blufi profiles. ** *******************************************************************************/ -tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back) +esp_gatt_status_t blufi_profile_init (tBLUFI_CBACK *call_back) { - tBT_UUID app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; + esp_bt_uuid_t app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}}; if(blufi_cb_env.enabled) @@ -363,8 +379,8 @@ tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back) } - /* register the blufi profile to the BTA_GATTS module*/ - BTA_GATTS_AppRegister(&app_uuid, blufi_profile_cb); + /* register the blufi profile to the ESP_GATTS module*/ + esp_ble_gatts_app_register(&app_uuid, blufi_profile_cb); return GATT_SUCCESS; } @@ -382,7 +398,7 @@ void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len) return; } - BTA_GATTS_HandleValueIndication (conn_id, attr_id, len, + esp_ble_gatts_hdl_val_indica(conn_id, attr_id, len, blufi_msg, rsp); } diff --git a/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h index a01b288c4..172586cdc 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h +++ b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h @@ -5,16 +5,10 @@ #include "btm_ble_api.h" #include "esp_bt_defs.h" -typedef struct -{ - char *adv_name; //set the device name to be sent on the advertising - tBTA_BLE_ADV_DATA ble_adv_data; -}tBLUFI_BLE_ADV_DATA; +extern void BlufiBleConfigadvData(esp_ble_adv_data_cfg_t *adv_data, + esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback); -extern void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); - -extern void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); +extern void BlufiBleSetScanRsp(esp_ble_adv_data_cfg_t *scan_rsp_data, + esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback); #endif /* __BLUFI_ADV_H__ */ diff --git a/examples/07_blufi/components/blufi/blufi.c b/examples/07_blufi/components/blufi/blufi.c index 304fcf80c..057a5c413 100644 --- a/examples/07_blufi/components/blufi/blufi.c +++ b/examples/07_blufi/components/blufi/blufi.c @@ -44,6 +44,8 @@ #include "blufi.h" #include "blufi_adv.h" +#include "esp_bt_common.h" + static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data); struct dm_evt { @@ -93,7 +95,7 @@ static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_dat } -static bt_status_t blufi_dm_upstreams_evt(void *arg) +static esp_err_t blufi_dm_upstreams_evt(void *arg) { struct dm_evt *evt = (struct dm_evt *)arg; @@ -124,7 +126,7 @@ static bt_status_t blufi_dm_upstreams_evt(void *arg) GKI_freebuf(evt); - return BT_STATUS_SUCCESS; + return ESP_OK; } @@ -144,10 +146,27 @@ void blufi_bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) blufi_transfer_context(blufi_dm_upstreams_evt, evt); } -bt_status_t blufi_enable(void *arg) +esp_err_t blufi_enable(void *arg) { + esp_err_t err; + BTM_SetTraceLevel(BT_TRACE_LEVEL_ERROR); - BTA_EnableBluetooth(blufi_bte_dm_evt); + err = esp_enable_bluetooth(blufi_bte_dm_evt); vTaskDelay(1000 / portTICK_PERIOD_MS); + + return err; +} + +esp_err_t blufi_disable(void *arg) +{ + esp_err_t err; + + err = esp_disable_bluetooth(); + + if (arg) { + ((void (*)(void))arg)(); + } + + return err; } diff --git a/examples/07_blufi/components/blufi/blufi_task.c b/examples/07_blufi/components/blufi/blufi_task.c index a1d0f0a2f..f02a8143f 100644 --- a/examples/07_blufi/components/blufi/blufi_task.c +++ b/examples/07_blufi/components/blufi/blufi_task.c @@ -60,7 +60,7 @@ static void blufi_task(void *arg) } } -static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg) +static esp_err_t blufi_task_post(uint32_t sig, void *par, void *cb, void *arg) { BtTaskEvt_t evt; @@ -71,13 +71,13 @@ static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg) if (xQueueSend(xBlufiTaskQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { LOG_ERROR("Blufi Post failed\n"); - return -1; + return ESP_FAIL; } - return 0; + return ESP_OK; } -bt_status_t blufi_transfer_context(BtTaskCb_t cb, void *arg) +esp_err_t blufi_transfer_context(blufi_task_cb_t cb, void *arg) { LOG_DEBUG("%s cb %08x, arg %u\n", __func__, cb, arg); @@ -102,3 +102,7 @@ void blufi_init(void) { blufi_transfer_context(blufi_enable, NULL); } +void blufi_deinit(void) { + blufi_transfer_context(blufi_disable, blufi_task_deinit); +} + diff --git a/examples/07_blufi/components/blufi/include/blufi.h b/examples/07_blufi/components/blufi/include/blufi.h index 61a1c1c24..abccc144a 100644 --- a/examples/07_blufi/components/blufi/include/blufi.h +++ b/examples/07_blufi/components/blufi/include/blufi.h @@ -4,6 +4,7 @@ #include #include "osi.h" #include "bt_common_types.h" +#include "esp_err.h" enum BLUFI_SIG { BLUFI_SIG_SWITCH_CONTEXT = 0, @@ -11,8 +12,14 @@ enum BLUFI_SIG { BLUFI_SIG_DISABLE, }; +typedef esp_err_t (*blufi_task_cb_t)(void *arg); + void blufi_init(void); -bt_status_t blufi_enable(void *arg); -bt_status_t blufi_transfer_context(BtTaskCb_t cb, void *arg); +void blufi_deinit(void); + +esp_err_t blufi_enable(void *arg); +esp_err_t blufi_disable(void *arg); + +esp_err_t blufi_transfer_context(blufi_task_cb_t cb, void *arg); #endif /* __BT_APP_COMMON_H__ */ diff --git a/examples/07_blufi/main/demo_main.c b/examples/07_blufi/main/demo_main.c index ac52c8ab3..3aeea617a 100644 --- a/examples/07_blufi/main/demo_main.c +++ b/examples/07_blufi/main/demo_main.c @@ -26,10 +26,8 @@ #include "bt.h" #include "bta_api.h" -extern tBTA_STATUS BTA_DisableBluetooth(void); -extern void phy_set_wifi_mode_only(bool wifi_only); -extern void bte_main_boot_entry(void *); -extern void blufi_init(void); +#include "esp_bt_common.h" +#include "blufi.h" #define WIFI_LIST_NUM 10 @@ -71,7 +69,8 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) case SYSTEM_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); blufi_config_success(); - BTA_DisableBluetooth(); + esp_disable_bluetooth(); //close bluetooth function + //esp_deinit_bluetooth(); //free bluetooth resource break; case SYSTEM_EVENT_STA_DISCONNECTED: /* This is a workaround as ESP32 WiFi libs don't currently @@ -107,7 +106,6 @@ void wifiTestTask(void *pvParameters) vTaskDelay(1000 / portTICK_PERIOD_MS); if (confirm) { confirm = false; - //BTA_DisableBluetooth(); strcpy(sta_config.sta.ssid, tmp_ssid); strcpy(sta_config.sta.password, tmp_passwd); @@ -138,6 +136,6 @@ void app_main() bt_controller_init(); xTaskCreatePinnedToCore(&wifiTestTask, "wifiTestTask", 2048, NULL, 20, NULL, 0); - // bt_app_task_start_up(); - bte_main_boot_entry(blufi_init); + + esp_init_bluetooth(blufi_init); }