From d6db871068a40484665109bc801eb2781c3ba134 Mon Sep 17 00:00:00 2001 From: yulong Date: Fri, 28 Oct 2016 01:54:42 -0400 Subject: [PATCH] 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"); } }