diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index ca673df09..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); @@ -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 @@ -4800,6 +4821,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 /******************************************************************************* ** @@ -4836,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) { @@ -4867,6 +4909,28 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) BTA_DM_BLE_ADV_CHNL_MAP); } +/******************************************************************************* +** +** Function bta_dm_ble_set_adv_params_all +** +** 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 @@ -4927,7 +4991,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..bfae1011d 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; @@ -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 @@ -985,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; @@ -1004,6 +1045,44 @@ 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_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)); + + 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 ********************************************************************************/ @@ -1248,7 +1327,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) { @@ -1498,7 +1577,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 +1613,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 +1651,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 +1688,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 +1718,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; @@ -1893,7 +1973,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); @@ -1991,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 @@ -2089,6 +2169,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..e098353c6 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/dm/bta_dm_int.h @@ -90,15 +90,25 @@ 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 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 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, @@ -469,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 { @@ -511,6 +534,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; @@ -726,10 +763,12 @@ 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; 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; @@ -1123,13 +1162,16 @@ 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); 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_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 40f8e0b21..e896b31f0 100755 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -87,15 +87,20 @@ 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******/ 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 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/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_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/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/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index 4776d5954..b1bd35eed 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. */ @@ -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 @@ -1918,6 +1939,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 @@ -2023,6 +2051,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/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/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/include/bt_target.h b/components/bt/bluedroid/include/bt_target.h index 9af8a2b76..bb9d59860 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 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 54ac507cf..90d3fc1bd 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(); } @@ -48,12 +51,12 @@ 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; - 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(BT_HDR *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) @@ -107,6 +110,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; } @@ -130,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 @@ -140,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); @@ -148,7 +152,3 @@ void bt_prf_sys_sendmsg(void *p_msg) bt_prf_task_post(SIG_PRF_WORK); } } - - - - diff --git a/components/bt/bluedroid/profiles/core/bt_prf_task.c b/components/bt/bluedroid/profiles/core/bt_prf_task.c index 931a7703f..eb0edb930 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); BtTaskEvt_t *e; - for (;;) { + 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); @@ -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); @@ -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 6f6fec0f8..7f10b13b4 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,17 @@ 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_sendmsg(void *p_msg); -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_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_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/core/include/bt_prf_task.h b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h index de11b8eea..d2d9a4bce 100644 --- a/components/bt/bluedroid/profiles/core/include/bt_prf_task.h +++ b/components/bt/bluedroid/profiles/core/include/bt_prf_task.h @@ -1,25 +1,25 @@ -/** - **************************************************************************************** - * - * @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__ - -/* Functions provided by btu_core.c +/** + **************************************************************************************** + * + * @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__ + +/* 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 a4cbfe462..9620ac839 100644 --- a/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c +++ b/components/bt/bluedroid/profiles/esp/ble_button/button_pro.c @@ -35,14 +35,15 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) -tBUTTON_CB_ENV button_cb_env; + button_env_cb_t button_cb_env; + /***************************************************************************** ** 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); /******************************************************************************* @@ -54,14 +55,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"); @@ -70,7 +71,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); @@ -87,16 +88,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; - 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_ERROR("Received button data:"); for(int i = 0; i < p_data->req_data.p_data->write_req.len; i++){ @@ -111,27 +112,27 @@ static void button_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_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 - 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 button characteristic --> write characteristic - BTA_GATTS_AddCharacteristic(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; @@ -140,44 +141,50 @@ 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, + 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; - BTA_GATTS_AddCharDescriptor (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("\n*******Start sent the ADV.*************\n"); + //esp_ble_start_advertising (&adv_params); + //BTA_GATTS_Listen(button_cb_env.gatt_if, true, NULL); break; - case BTA_GATTS_CONNECT_EVT: + 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; - 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 + 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; @@ -196,17 +203,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."); //} - BTA_GATTS_CreateService(server_if,&uuid,inst,num_handle,true); + esp_ble_gatts_create_srvc(server_if,&uuid,inst,num_handle,true); } @@ -219,9 +226,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) @@ -245,10 +252,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++) { @@ -270,32 +277,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++) +BOOLEAN button_env_clcb_dealloc(uint16_t conn_id) +{ + 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)) { - 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)); + memset(p_clcb, 0, sizeof(but_clcb_t)); return TRUE; } } return FALSE; -}*/ - +} /******************************************************************************* ** @@ -304,19 +302,19 @@ 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}}; - + 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 { - memset(&button_cb_env,0,sizeof(tBUTTON_CB_ENV)); + memset(&button_cb_env,0,sizeof(button_env_cb_t)); } @@ -327,27 +325,33 @@ 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); + esp_ble_gatts_app_register(&app_uuid,button_profile_cb); button_cb_env.enabled = TRUE; - return GATT_SUCCESS; + return ESP_GATT_OK; } -void button_msg_notify(UINT8 len, UINT8 *button_msg) +void button_disable(uint16_t connid) +{ + button_env_clcb_dealloc(connid); +} + + +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; } - BTA_GATTS_HandleValueIndication (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/blufi/include/blufi_adv.h b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h index 985ced908..1b1185ee4 100644 --- a/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h +++ b/components/bt/bluedroid/profiles/esp/blufi/include/blufi_adv.h @@ -3,13 +3,7 @@ #include "bta_api.h" #include "btm_ble_api.h" - -enum -{ - BLE_ADV_DATA_IDX, - BLE_SCAN_RSP_DATA_IDX, - ADV_SCAN_IDX_MAX -}; +#include "bt_app_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 d9028830b..8e95a0d99 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 @@ -64,59 +65,61 @@ enum typedef struct { - BD_ADDR remote_bda; - BOOLEAN need_rsp; - UINT16 clt_cfg; -}tBUT_WRITE_DATA; + 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; -}tBUT_CLCB; +}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; - 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*/ - tGATT_IF gatt_if; + but_clcb_t clcb; /* connection link*/ + esp_gatt_if_t gatt_if; BOOLEAN enabled; BOOLEAN is_primery; - tBUT_INST button_inst; - UINT8 inst_id; -}tBUTTON_CB_ENV; + but_inst_t button_inst; + uint8_t inst_id; +}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_msg_notify(UINT8 len, UINT8 *button_msg); +void button_disable(uint16_t connid); -extern tBUTTON_CB_ENV button_cb_env; +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 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 4ccd77da3..74d5dae9f 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 @@ -33,83 +34,82 @@ #define ATT_CHAR_AIRSYNC_WIT 0xFEC7 #define ATT_CHAR_AIRSYBC_NTF 0xFEC8 #define ATT_CHAR_AIRSYNC_READ 0xFEC9 - - -typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data); - - - /// WX AirSync Service Attributes Indexes - enum - { - WX_IDX_SVC, - WX_IDX_AIRSYNC_WIT_CHAR, - WX_IDX_AIRSYNC_WIT_VAL, - WX_IDX_AIRSYNC_NTF_CHAR, - WX_IDX_AIRSYNC_NTF_VAL, - WX_IDX_AIRSYNC_READ_CHAR, - WX_IDX_AIRSYNC_READ_VAL, - WX_IDX_AIRSYNC_NTF_CFG, - - KEY_IDX_NB, - }; - - typedef struct - { - BD_ADDR remote_bda; - BOOLEAN need_rsp; - UINT16 clt_cfg; - }tAirSync_WRITE_DATA; - - typedef struct - { - BOOLEAN in_use; - BOOLEAN congest; - UINT16 conn_id; - BOOLEAN connected; - BD_ADDR remote_bda; - UINT32 trans_id; - UINT8 cur_srvc_id; - - }tAirSync_CLCB; - - - typedef struct - { - UINT8 app_id; - UINT16 airsync_wirt_hdl; - UINT16 airsync_ntf_hdl; - UINT16 airsync_read_hdl; - UINT16 airsync_cfg_hdl; - - tAIRSYNC_CBACK *p_cback; - - }tAirSync_INST; - - - /* service engine control block */ - typedef struct - { - tAirSync_CLCB clcb; /* connection link*/ - tGATT_IF gatt_if; - BOOLEAN enabled; - BOOLEAN is_primery; - tAirSync_INST airsync_inst; - UINT8 inst_id; - }tAIRSYNC_CB_ENV; - - void AirSync_CreateService(void); - - tAirSync_CLCB *airsync_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda); - - UINT16 AirSync_env_find_conn_id_by_bd_adddr(BD_ADDR bda); - - BOOLEAN AirSync_env_clcb_dealloc(UINT16 conn_id); - - tGATT_STATUS AirSync_Init(tAIRSYNC_CBACK *call_back); - - void AirSync_msg_notify(UINT8 len, UINT8 *button_msg); - - extern tAIRSYNC_CB_ENV airsync_cb_env; - #endif ///WX_AIRSYNC_CFG + +typedef void (tAIRSYNC_CBACK)(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *data); + + +/// WX AirSync Service Attributes Indexes +enum +{ + WX_IDX_SVC, + WX_IDX_AIRSYNC_WIT_CHAR, + WX_IDX_AIRSYNC_WIT_VAL, + WX_IDX_AIRSYNC_NTF_CHAR, + WX_IDX_AIRSYNC_NTF_VAL, + WX_IDX_AIRSYNC_READ_CHAR, + WX_IDX_AIRSYNC_READ_VAL, + WX_IDX_AIRSYNC_NTF_CFG, + + WX_IDX_NB, +}; + +typedef struct +{ + BD_ADDR remote_bda; + BOOLEAN need_rsp; + UINT16 clt_cfg; +}tAirSync_WRITE_DATA; + +typedef struct +{ + BOOLEAN in_use; + BOOLEAN congest; + UINT16 conn_id; + BOOLEAN connected; + BD_ADDR remote_bda; + UINT32 trans_id; + UINT8 cur_srvc_id; + +}tAirSync_CLCB; + + +typedef struct +{ + UINT8 app_id; + UINT16 airsync_wirt_hdl; + UINT16 airsync_ntf_hdl; + UINT16 airsync_read_hdl; + UINT16 airsync_cfg_hdl; + tAIRSYNC_CBACK *p_cback; + +}tAirSync_INST; + + +/* service engine control block */ +typedef struct +{ + tAirSync_CLCB clcb; /* connection link*/ + tGATT_IF gatt_if; + BOOLEAN enabled; + BOOLEAN is_primery; + tAirSync_INST airsync_inst; + UINT8 inst_id; +}tAIRSYNC_CB_ENV; + +void AirSync_CreateService(void); + +tAirSync_CLCB *airsync_env_clcb_alloc (UINT16 conn_id, BD_ADDR remote_bda); + +UINT16 AirSync_env_find_conn_id_by_bd_adddr(BD_ADDR bda); + +BOOLEAN AirSync_env_clcb_dealloc(UINT16 conn_id); + +tGATT_STATUS AirSync_Init(tAIRSYNC_CBACK *call_back); + +void AirSync_msg_notify(UINT8 len, UINT8 *button_msg); + +extern tAIRSYNC_CB_ENV airsync_cb_env; + +#endif ///WX_AIRSYNC_CFG 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 1fe8165fd..d970821bb 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}}; - UINT16 num_handle = KEY_IDX_NB; + 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,18 +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/battery/battery_prf.c b/components/bt/bluedroid/profiles/std/battery/battery_prf.c index b1cde82e9..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,20 +151,20 @@ 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); 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; - 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/hid_le/hid_le_prf.c b/components/bt/bluedroid/profiles/std/hid_le/hid_le_prf.c index 61037ae5e..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+5; + 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/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/profiles/std/include/hid_le_prf.h b/components/bt/bluedroid/profiles/std/include/hid_le_prf.h index c38af0208..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 @@ -195,76 +196,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 790bfe2c0..dab333aad 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 @@ -26,59 +27,69 @@ #define ATT_UUID_128_LEN 0x0010 #define ATT_UUID_32_LEN 0x0004 -#define WX_AIRSYNC_CFG 0 -#define BUT_PROFILE_CFG 0 -#define HIDD_LE_PROFILE_CFG 1 +#define WX_AIRSYNC_CFG FALSE +#define BUT_PROFILE_CFG TRUE +#define HIDD_LE_PROFILE_CFG FALSE /* * Type Definition **************************************************************************************** */ +/* 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 { ///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; diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index 974bbfbfa..14216e121 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); } @@ -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_ble_bgconn.c b/components/bt/bluedroid/stack/btm/btm_ble_bgconn.c index b24eee473..e69d44637 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; @@ -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/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index e03aea862..f665998ac 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; @@ -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()) @@ -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()) @@ -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(); @@ -1074,6 +1074,70 @@ 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_BleSetAdvParamsStartAdv\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; + p_cb->afp = afp; + + 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 @@ -1130,7 +1194,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; @@ -1163,12 +1227,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 @@ -1333,7 +1450,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 +1467,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 +1899,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 +1917,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) { @@ -1888,7 +2005,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) @@ -3064,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; @@ -3086,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_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/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index 1b32a8cb3..083c276db 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\n"); + 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\n"); + 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\n"); + 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\n"); + 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/components/bt/bluedroid/stack/btu/btu_hcif.c b/components/bt/bluedroid/stack/btu/btu_hcif.c index d140b8da7..ccbc90a9d 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/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..72f9dfd22 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) @@ -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/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/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index ce55ef6c5..966b85572 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 @@ -1011,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 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/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); diff --git a/components/bt/bluedroid/stack_api/bt_app_api.c b/components/bt/bluedroid/stack_api/bt_app_api.c new file mode 100644 index 000000000..fe309254e --- /dev/null +++ b/components/bt/bluedroid/stack_api/bt_app_api.c @@ -0,0 +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; +} + + + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_sec.c b/components/bt/bluedroid/stack_api/bt_app_sec.c similarity index 100% rename from examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_sec.c rename to components/bt/bluedroid/stack_api/bt_app_sec.c diff --git a/components/bt/bluedroid/stack_api/include/bt_app_api.h b/components/bt/bluedroid/stack_api/include/bt_app_api.h new file mode 100644 index 000000000..dfc2335b4 --- /dev/null +++ b/components/bt/bluedroid/stack_api/include/bt_app_api.h @@ -0,0 +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); + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h b/components/bt/bluedroid/stack_api/include/bt_app_common.h similarity index 100% rename from examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_common.h rename to components/bt/bluedroid/stack_api/include/bt_app_common.h diff --git a/components/bt/bluedroid/stack_api/include/bt_app_defs.h b/components/bt/bluedroid/stack_api/include/bt_app_defs.h new file mode 100644 index 000000000..91ecdcaf1 --- /dev/null +++ b/components/bt/bluedroid/stack_api/include/bt_app_defs.h @@ -0,0 +1,332 @@ + +#ifndef _BT_APP_DEFS_H__ +#define _BT_APP_DEFS_H__ + + +#include "bta_api.h" +#include "btm_ble_api.h" +#include "bta_gatt_api.h" + +#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ + +#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 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; + + + + + + +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; +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_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_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 +#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_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 +{ + BLE_ADV_DATA_IDX, + BLE_SCAN_RSP_DATA_IDX, + 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 +{ + ///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 +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 +{ + char *adv_name; //set the device name to be sent on the advertising + tBTA_BLE_ADV_DATA 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; +}esp_ble_adv_params_t; + +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; +}esp_ble_adv_params_all_t; + +typedef struct +{ + UINT8 scan_type; + UINT16 scan_intv; + UINT16 scan_win; + UINT8 addr_type_own; + UINT8 scan_fil_policy; +}esp_ble_scan_params; + + +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 ble_set_scan_rsp(esp_ble_adv_data_cfg_t *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 diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_sec.h b/components/bt/bluedroid/stack_api/include/bt_app_sec.h similarity index 100% rename from examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_sec.h rename to components/bt/bluedroid/stack_api/include/bt_app_sec.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 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/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_core.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c index 09b7206ef..250427296 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 } @@ -253,7 +253,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_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..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 @@ -15,7 +15,13 @@ ******************************************************************************* ********* */ -#if 0 + + +#include "prf_defs.h" + +#if (BUT_PROFILE_CFG) + + #include #include #include @@ -33,6 +39,118 @@ #include "allocator.h" #include "button_pro.h" +#include "app_button_int.h" + +static const tBT_PRF_SYS_REG but_prf_reg = +{ + ble_but_prf_hdl_event, + ble_but_prf_disable +}; + + + +/******************************************************************************* +** +** Function ble_but_prf_hdl_event +** +** Description button profile main event handling function. +** +** +** Returns BOOLEAN +** +*******************************************************************************/ +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) + { + 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; + } +} + + +/******************************************************************************* +** +** 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) +{ + 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\n"); + return; + } + + 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); + } + bta_sys_deregister(PRF_ID_BUT_LE); + +} + +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); + } +} + + + + + + +#endif ///BUT_PROFILE_CFG + +#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 3f4483409..485d90833 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,9 +30,11 @@ #include "wx_airsync_prf.h" #include "button_pro.h" - +#include "app_button.h" #include "hid_le_prf.h" +#include "bt_app_api.h" + // #include "hcimsgs.h" @@ -78,9 +80,30 @@ 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}; + +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}; -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", @@ -121,7 +144,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, @@ -163,7 +186,7 @@ tESP_BLE_ADV_DATA 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 int uuidType(unsigned char* p_uuid) @@ -222,6 +245,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) { @@ -233,13 +258,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) @@ -250,6 +276,8 @@ 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); } @@ -268,16 +296,16 @@ 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], + esp_ble_config_adv_data(&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; /*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); @@ -286,7 +314,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); } @@ -294,7 +326,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) @@ -321,7 +353,10 @@ 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); + 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/app_button_int.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h new file mode 100644 index 000000000..b64a1ee32 --- /dev/null +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/app_button_int.h @@ -0,0 +1,131 @@ +/** + +******************************************************************************* +********* +* +* @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 + + + 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 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 deleted file mode 100644 index 41c573da1..000000000 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ /dev/null @@ -1,18 +0,0 @@ -/** - **************************************************************************************** - * - * @file bt_app_api.h - * - * @brief Application entry point - * - * Copyright (C) Espressif 2016 - * Created by Yulong at 2016/10/13 - * - * - **************************************************************************************** - */ - - - - - 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 deleted file mode 100644 index 1405cb091..000000000 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "bta_api.h" -#include "btm_ble_api.h" - -enum -{ - BLE_ADV_DATA_IDX, - BLE_SCAN_RSP_DATA_IDX, - ADV_SCAN_IDX_MAX -}; - -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; - -extern void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); - -extern void ESP_AppBleSetScanRsp(tESP_BLE_ADV_DATA *scan_rsp_data, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); - - 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"); } }