mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
component/bt : new architectecture
1st compile ok
This commit is contained in:
parent
118984283a
commit
521ef3f579
@ -1,345 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function esp_ble_config_adv_data
|
||||
**
|
||||
** Description This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** p_adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback)
|
||||
{
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
if(adv_data->adv_name != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
|
||||
BTA_DmSetDeviceName(adv_data->adv_name);
|
||||
}
|
||||
if(adv_data->ble_adv_data.int_range.low != 0 ||
|
||||
adv_data->ble_adv_data.int_range.hi != 0)
|
||||
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
|
||||
|
||||
if(adv_data->ble_adv_data.p_manu != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_MANU;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_services_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_service_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_service_data != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.appearance != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_proprietary != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.tx_power != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
|
||||
}
|
||||
|
||||
BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function esp_ble_set_scan_rsp
|
||||
**
|
||||
** Description This function is called to override the app scan response.
|
||||
**
|
||||
** Parameters Pointer to User defined ADV data structure
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback)
|
||||
{
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
if(scan_rsp_data->adv_name != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
|
||||
BTA_DmSetDeviceName(scan_rsp_data->adv_name);
|
||||
}
|
||||
if(scan_rsp_data->ble_adv_data.int_range.low != 0 ||
|
||||
scan_rsp_data->ble_adv_data.int_range.hi != 0)
|
||||
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_manu != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_MANU;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_services_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_service_data != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.appearance != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_proprietary != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.tx_power != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
|
||||
}
|
||||
|
||||
BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_config_adv_data
|
||||
**
|
||||
** @brief This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** @param[in] adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** @param[in|out] adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback)
|
||||
{
|
||||
if(adv_data != NULL)
|
||||
{
|
||||
ble_config_adv_data(adv_data, adv_data_cback);
|
||||
}else{
|
||||
LOG_ERROR("The adv_data is NULL\n");
|
||||
}
|
||||
|
||||
if(++adv_data != NULL)
|
||||
{
|
||||
ble_set_scan_rsp(adv_data, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_advertising
|
||||
**
|
||||
** @brief This function is called to start advertising.
|
||||
**
|
||||
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params)
|
||||
{
|
||||
if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
|
||||
!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX))
|
||||
{
|
||||
LOG_ERROR("Invalid advertisting interval parameters.\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) &&
|
||||
(ble_adv_params->adv_type > API_BROADCASTER_MODE) )
|
||||
{
|
||||
LOG_ERROR("Invalid advertisting type parameters.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) &&
|
||||
(ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) )
|
||||
{
|
||||
LOG_ERROR("Invalid advertisting type parameters.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_ERROR("API_Ble_AppStartAdvertising\n");
|
||||
|
||||
///
|
||||
BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min,
|
||||
ble_adv_params->adv_int_max,
|
||||
ble_adv_params->adv_type,
|
||||
ble_adv_params->addr_type_own,
|
||||
ble_adv_params->channel_map,
|
||||
ble_adv_params->adv_filter_policy,
|
||||
ble_adv_params->p_dir_bda);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_set_scan_params
|
||||
**
|
||||
** @brief This function is called to set scan parameters
|
||||
**
|
||||
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
|
||||
** memory space can not be freed until scan_param_setup_cback
|
||||
** @param[in] client_if: Client interface ID
|
||||
** @param[in|out] scan_param_setup_status_cback - Set scan param status callback
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if,
|
||||
esp_scan_param_setup_cb_t scan_param_setup_cback)
|
||||
{
|
||||
if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
|
||||
API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) &&
|
||||
(scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS))
|
||||
{
|
||||
BTA_DmSetBleScanFilterParams(client_if,
|
||||
scan_params->scan_intv,
|
||||
scan_params->scan_win,
|
||||
scan_params->scan_type,
|
||||
scan_params->scan_fil_policy,
|
||||
scan_params->addr_type_own,
|
||||
scan_param_setup_cback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_scanning
|
||||
**
|
||||
** @brief This procedure keep the device scanning the peer device whith advertising on the air
|
||||
**
|
||||
** @param[in] duration: Keeping the scaning time, the unit is second.
|
||||
** @param[in|out] results_cb: The scanning function callback when the peer device has been scan
|
||||
** which advertising on the air
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb)
|
||||
{
|
||||
if((duration != 0) && (results_cb != NULL))
|
||||
{
|
||||
///Start scan the device
|
||||
BTA_DmBleObserve(true, duration, results_cb);
|
||||
}else{
|
||||
LOG_ERROR("The scan duration or p_results_cb invalid\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_stop_advertising
|
||||
**
|
||||
** @brief This function is called to stop advertising.
|
||||
**
|
||||
** @param None
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_stop_advertising (void)
|
||||
{
|
||||
bool stop_adv = false;
|
||||
|
||||
BTA_DmBleBroadcast(stop_adv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_common.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
extern int bte_main_boot_entry(void *cb);
|
||||
extern int bte_main_shutdown(void);
|
||||
|
||||
// tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
|
||||
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t *p_cback)
|
||||
{
|
||||
return BTA_EnableBluetooth(p_cback) == BTA_SUCCESS ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_disable_bluetooth(void)
|
||||
{
|
||||
return BTA_DisableBluetooth() == BTA_SUCCESS ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb)
|
||||
{
|
||||
return bte_main_boot_entry(cb) == 0 ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void esp_deinit_bluetooth(void)
|
||||
{
|
||||
bte_main_shutdown();
|
||||
}
|
||||
|
||||
|
175
components/bt/bluedroid/api/esp_gap_ble_api.c
Normal file
175
components/bt/bluedroid/api/esp_gap_ble_api.c
Normal file
@ -0,0 +1,175 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_gap_ble_api.h"
|
||||
#include "bta_api.h"
|
||||
#include "bt_trace.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gap_ble.h"
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
if (adv_data == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
|
||||
memcpy(&arg.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
if (scan_params == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
|
||||
memcpy(&arg.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
|
||||
arg.duration = duration;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_START_ADV;
|
||||
memcpy(&arg.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_stop_advertising(void)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
|
||||
memcpy(&arg.conn_params, params, sizeof(esp_ble_conn_update_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
|
||||
arg.tx_data_length = tx_data_length;
|
||||
memcpy(arg.remote_device, remote_device, ESP_BD_ADDR_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
|
||||
memcpy(arg.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
|
||||
arg.privacy_enable = privacy_enable;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_set_device_name(char *name)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gap_args_t arg;
|
||||
|
||||
if (strlen(name) > ESP_GAP_DEVICE_NAME_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_DEV_NAME;
|
||||
strcpy(arg.device_name, name);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
|
||||
#include "esp_gap_bt_api.h"
|
||||
#include "bta_api.h"
|
||||
#include "bt_trace.h"
|
||||
|
File diff suppressed because it is too large
Load Diff
601
components/bt/bluedroid/api/esp_gattc_api.c
Normal file
601
components/bt/bluedroid/api/esp_gattc_api.c
Normal file
@ -0,0 +1,601 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_gattc_api.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gattc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] callback - pointer to the application callback function.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
if (callback == NULL) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
btc_profile_cb_set(BTC_PID_GATTC, callback);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register
|
||||
**
|
||||
** @brief This function is called to register application
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] app_id : Application Identitfy (UUID), for different application
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_APP_REGISTER;
|
||||
arg.app_id = app_id;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
|
||||
arg.gatt_if = gatt_if;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_conn
|
||||
**
|
||||
** @brief Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application identity.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_OPEN;
|
||||
arg.gatt_if = gatt_if;
|
||||
memcpy(arg.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
arg.is_direct = is_direct;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_close
|
||||
**
|
||||
** @brief Close a connection to a GATT server.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_CLOSE;
|
||||
arg.conn_id = conn_id;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
|
||||
return ESP_GATT_ILLEGAL_PARAMETER;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_CFG_MTU;
|
||||
arg.conn_id = conn_id;
|
||||
arg.mtu = mtu;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_search_service
|
||||
**
|
||||
** @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] filter_uuid: a UUID of the service application is interested in.
|
||||
** If Null, discover for all services.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_SEARCH_SERVICE;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.uuid, filter_uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_characteristic
|
||||
**
|
||||
** @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: serivce ID
|
||||
**
|
||||
** @param[in] start_char_id: the start characteristic ID
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *start_char_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
if (start_char_id) {
|
||||
memcpy(&arg.char_uuid, start_char_id, sizeof(esp_gatt_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_CHAR;
|
||||
} else {
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
|
||||
}
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_descriptor
|
||||
**
|
||||
** @brief This function is called to find the descriptor 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_id: Characteristic ID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] start_descr_id: the sctart descriptor id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *start_descr_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
if (start_descr_id) {
|
||||
memcpy(&arg.descr_uuid, start_descr_id, sizeof(esp_gatt_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_DESCR;
|
||||
} else {
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
|
||||
}
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_include_service
|
||||
**
|
||||
** @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] start_incl_srvc_id: the start include service id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_srvc_id_t *start_incl_srvc_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
if (start_incl_srvc_id) {
|
||||
memcpy(&arg.start_service_uuid, start_incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
msg.act = BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE;
|
||||
} else {
|
||||
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
|
||||
}
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char
|
||||
**
|
||||
** @brief This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteritic ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_READ_CHAR;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.auth_req = auth_req;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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] srvc_id - serivcie ID.
|
||||
** @param[in] descr_id - characteritic descriptor ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_READ_CHAR_DESCR;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(&arg.descr_uuid, descr_id, sizeof(esp_gatt_id_t));
|
||||
arg.auth_req = auth_req;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char
|
||||
**
|
||||
** @brief This function is called to write characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID to write.
|
||||
** @param[in] len: length of the data to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t len,
|
||||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_WRITE_CHAR;
|
||||
arg.conn_id = (uint16_t) conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len;
|
||||
memcpy(arg.value, value, arg.len);
|
||||
arg.auth_req = auth_req;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID.
|
||||
** @param[in] descr_id - characteristic descriptor ID to write.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t len,
|
||||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_WRITE_CHAR_DESCR;
|
||||
arg.conn_id = (uint16_t) conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
memcpy(&arg.descr_uuid, descr_id, sizeof(esp_gatt_id_t));
|
||||
arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len;
|
||||
memcpy(arg.value, value, arg.len);
|
||||
arg.auth_req = auth_req;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_prepare_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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t offset,
|
||||
uint16_t len,
|
||||
uint8_t *data,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
//TODO: Review this function
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_PREPARE_WRITE;
|
||||
arg.conn_id = conn_id;
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.offset = offset;
|
||||
arg.len = len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : len; // length check ?
|
||||
memcpy(arg.value, data, arg.len);
|
||||
arg.auth_req = auth_req;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
|
||||
arg.conn_id = conn_id;
|
||||
arg.is_execute = is_execute;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_register_for_notify
|
||||
**
|
||||
** @brief This function is called to register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if registration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
|
||||
arg.gatt_if = gatt_if;
|
||||
memcpy(&arg.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_unregister_ntf
|
||||
**
|
||||
** @brief This function is called to de-register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if deregistration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gattc_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_UNREG_FOR_NOTIFY;
|
||||
arg.gatt_if = gatt_if;
|
||||
memcpy(&arg.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
|
||||
memcpy(&arg.service_uuid, srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(&arg.char_uuid, char_id, sizeof(esp_gatt_id_t));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
227
components/bt/bluedroid/api/esp_gatts_api.c
Normal file
227
components/bt/bluedroid/api/esp_gatts_api.c
Normal file
@ -0,0 +1,227 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "string.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_gatts_api.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gatts.h"
|
||||
|
||||
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
|
||||
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
uint16_t app_uuid;
|
||||
|
||||
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_APP_REGISTER;
|
||||
arg.app_uuid = app_id;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
|
||||
arg.gatt_if = gatt_if;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_gatt_srvc_id_t *service_uuid, uint16_t num_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
|
||||
arg.gatt_if = gatt_if;
|
||||
arg.num_handle = num_handle;
|
||||
memcpy(&arg.service_uuid, service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_ADD_INCLUDE_SERVICE;
|
||||
arg.service_handle = service_handle;
|
||||
arg.included_service_handle = included_service_handle;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid,
|
||||
esp_gatt_perm_t perm, esp_gatt_char_prop_t property)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_ADD_CHAR;
|
||||
arg.service_handle = service_handle;
|
||||
arg.perm = perm;
|
||||
arg.property = property;
|
||||
memcpy(&arg.uuid, char_uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
|
||||
esp_bt_uuid_t * descr_uuid,
|
||||
esp_gatt_perm_t perm)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_ADD_CHAR_DESCR;
|
||||
arg.service_handle = service_handle;
|
||||
arg.perm = perm;
|
||||
memcpy(&arg.descr_uuid, descr_uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_DELETE_SERVICE;
|
||||
arg.service_handle = service_handle;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_START_SERVICE;
|
||||
arg.service_handle = service_handle;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_STOP_SERVICE;
|
||||
arg.service_handle = service_handle;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t data_len, uint8_t *data, bool need_confirm)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
|
||||
arg.conn_id = conn_id;
|
||||
arg.attr_handle = attr_handle;
|
||||
arg.data_len = data_len;
|
||||
arg.need_confirm = need_confirm;
|
||||
memcpy(&arg.data, data, data_len);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
|
||||
arg.conn_id = conn_id;
|
||||
arg.trans_id = trans_id;
|
||||
arg.status = status;
|
||||
memcpy(&arg.rsp, rsp, sizeof(esp_gatt_rsp_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_OPEN;
|
||||
arg.gatt_if = gatt_if;
|
||||
arg.is_direct = is_direct;
|
||||
memcpy(&arg.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
esp_ble_gatts_args_t arg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CLOSE;
|
||||
arg.conn_id = conn_id;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(esp_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
#ifndef __ESP_ADV_API_H__
|
||||
#define __ESP_ADV_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bt_prf_sys.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_config_adv_data
|
||||
**
|
||||
** @brief This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** @param[in] adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** @param[in|out] adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function esp_ble_set_scan_rsp
|
||||
**
|
||||
** Description This function is called to override the app scan response.
|
||||
**
|
||||
** Parameters Pointer to User defined ADV data structure
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_set_scan_params
|
||||
**
|
||||
** @brief This function is called to set scan parameters
|
||||
**
|
||||
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
|
||||
** memory space can not be freed until scan_param_setup_cback
|
||||
** @param[in] client_if: Client interface ID
|
||||
** @param[in|out] scan_param_setup_status_cback - Set scan param status callback
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if,
|
||||
esp_scan_param_setup_cb_t scan_param_setup_cback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_scanning
|
||||
**
|
||||
** @brief This procedure keep the device scanning the peer device whith advertising on the air
|
||||
**
|
||||
** @param[in] duration: Keeping the scaning time, the unit is second.
|
||||
** @param[in|out] results_cb: The scanning function callback when the peer device has been scan
|
||||
** which advertising on the air
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_advertising
|
||||
**
|
||||
** @brief This function is called to start advertising.
|
||||
**
|
||||
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_stop_advertising
|
||||
**
|
||||
** @brief This function is called to stop advertising.
|
||||
**
|
||||
** @param None
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_stop_advertising (void);
|
||||
|
||||
#endif /* __ESP_ADV_API_H__ */
|
@ -1,84 +0,0 @@
|
||||
#ifndef __ESP_BT_COMMON_H__
|
||||
#define __ESP_BT_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "bta_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
typedef tBT_UUID esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
|
||||
|
||||
typedef BD_ADDR esp_bd_addr_t; /* BD_ADDR in bt_types.h */
|
||||
|
||||
typedef tBTA_DM_SEC_CBACK esp_bt_sec_cb_t;
|
||||
|
||||
typedef void (*bluetooth_init_cb_t)(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_enable_bluetooth
|
||||
**
|
||||
** @brief This function is called to enable bluetooth host. This
|
||||
** function must be called before any other functions in the
|
||||
** API (except esp_bluetooth_init) are called.
|
||||
**
|
||||
** @param[in] p_cback:
|
||||
** security call back function
|
||||
** @param[out] None
|
||||
**
|
||||
** @return ESP_OK - Success; Other - Failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t p_cback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_disable_bluetooth
|
||||
**
|
||||
** @brief This function is called to disable bluetooth host
|
||||
**
|
||||
** @param[in] None
|
||||
**
|
||||
** @param[out] None
|
||||
**
|
||||
** @return ESP_OK - Success; Other - Failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_disable_bluetooth(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_init_bluetooth
|
||||
**
|
||||
** @brief This function is called to init bluetooth host and alloc the
|
||||
** resource. This function must be called before all othor API
|
||||
** are called.
|
||||
**
|
||||
** @param[in] cb: When this function called success, the callback will be called
|
||||
**
|
||||
** @param[out] None
|
||||
**
|
||||
** @return ESP_OK - Success; Other - Failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_deinit_bluetooth
|
||||
**
|
||||
** @brief This function is called to deinit bluetooth host and free the
|
||||
** resource.
|
||||
**
|
||||
** @param[in] None
|
||||
**
|
||||
** @param[out] None
|
||||
**
|
||||
** @return ESP_OK - Success; Other - Failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_deinit_bluetooth(void);
|
||||
|
||||
#endif /* __ESP_BT_COMMON_H__ */
|
@ -1,331 +1,72 @@
|
||||
#ifndef __ESP_BT_DEFS_H__
|
||||
#define __ESP_BT_DEFS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btm_ble_api.h"
|
||||
#include "bta_gatt_api.h"
|
||||
/* Status Return Value */
|
||||
typedef enum {
|
||||
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
|
||||
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
|
||||
ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
|
||||
ESP_BT_STATUS_BUSY = 3,
|
||||
ESP_BT_STATUS_NO_RESOURCES = 4,
|
||||
ESP_BT_STATUS_WRONG_MODE = 5,
|
||||
} esp_bt_status_t;
|
||||
|
||||
#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)
|
||||
#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
|
||||
|
||||
/* 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 struct {
|
||||
#define ESP_UUID_LEN_16 2
|
||||
#define ESP_UUID_LEN_32 4
|
||||
#define ESP_UUID_LEN_128 16
|
||||
uint16_t len;
|
||||
union {
|
||||
uint16_t uuid16;
|
||||
uint32_t uuid32;
|
||||
uint8_t uuid128[ESP_UUID_LEN_128];
|
||||
} uuid;
|
||||
}esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
|
||||
|
||||
typedef tBTA_GATT_STATUS esp_gatt_status_t;
|
||||
typedef enum {
|
||||
ESP_BT_DEVICE_TYPE_BREDR = 0x01,
|
||||
ESP_BT_DEVICE_TYPE_BLE = 0x02,
|
||||
ESP_BT_DEVICE_TYPE_DUMO = 0x03,
|
||||
} esp_bt_dev_type_t;
|
||||
|
||||
#define ESP_BD_ADDR_LEN 6
|
||||
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; /* BD_ADDR in bt_types.h */
|
||||
|
||||
/// Own BD address source of the device
|
||||
typedef enum {
|
||||
/// Public Address
|
||||
BD_ADDR_PUBLIC,
|
||||
/// Provided random address
|
||||
BD_ADDR_PROVIDED_RND,
|
||||
/// Provided static random address
|
||||
BD_ADDR_GEN_STATIC_RND,
|
||||
/// Generated resolvable private random address
|
||||
BD_ADDR_GEN_RSLV,
|
||||
/// Generated non-resolvable private random address
|
||||
BD_ADDR_GEN_NON_RSLV,
|
||||
/// Provided Reconnection address
|
||||
BD_ADDR_PROVIDED_RECON,
|
||||
} esp_bd_addr_type_t;
|
||||
|
||||
typedef enum {
|
||||
BLE_ADDR_TYPE_PUBLIC = 0x00,
|
||||
BLE_ADDR_TYPE_RANDOM = 0x01,
|
||||
BLE_ADDR_TYPE_RPA_PUBLIC = 0x02,
|
||||
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
|
||||
} esp_ble_addr_type_t;
|
||||
|
||||
#define APP_ID_MIN 0x0000
|
||||
#define APP_ID_MAX 0x7fff
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
|
||||
typedef void (* esp_profile_cb_t)(uint32_t event, void *param);
|
||||
|
||||
#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 ///__ESP_BT_DEFS_H__
|
||||
|
@ -1,18 +0,0 @@
|
||||
#ifndef __ESP_GAP_API_H__
|
||||
#define __ESP_GAP_API_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_common.h"
|
||||
|
||||
enum {
|
||||
BT_SCAN_MODE_NONE,
|
||||
BT_SCAN_MODE_CONNECTABLE,
|
||||
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
|
||||
};
|
||||
typedef uint16_t bt_scan_mode_t;
|
||||
|
||||
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
|
||||
|
||||
#endif /* __ESP_GAP_API_H__ */
|
321
components/bt/bluedroid/api/include/esp_gap_ble_api.h
Normal file
321
components/bt/bluedroid/api/include/esp_gap_ble_api.h
Normal file
@ -0,0 +1,321 @@
|
||||
#ifndef __ESP_GAP_BLE_API_H__
|
||||
#define __ESP_GAP_BLE_API_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#define ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
|
||||
#define ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
|
||||
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||
|
||||
typedef uint32_t esp_gap_ble_event_t;
|
||||
|
||||
/// Advertising mode
|
||||
typedef enum {
|
||||
/// Mode in non-discoverable
|
||||
ADV_TYPE_NON_DISCOVERABLE = 0,
|
||||
/// Mode in general discoverable
|
||||
ADV_TYPE_GEN_DISCOVERABLE,
|
||||
/// Mode in limited discoverable
|
||||
ADV_TYPE_LIM_DISCOVERABLE,
|
||||
/// Broadcaster mode which is a non discoverable and non connectable mode.
|
||||
ADV_TYPE_BROADCASTER_MODE,
|
||||
} esp_ble_adv_type_t;
|
||||
|
||||
typedef enum {
|
||||
ADV_CHNL_37 = 0x01,
|
||||
ADV_CHNL_38 = 0x02,
|
||||
ADV_CHNL_39 = 0x03,
|
||||
ADV_CHNL_ALL = 0x07,
|
||||
} esp_ble_adv_channel_t;
|
||||
|
||||
typedef enum {
|
||||
///Allow both scan and connection requests from anyone
|
||||
ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
|
||||
///Allow both scan req from White List devices only and connection req from anyone
|
||||
ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,
|
||||
///Allow both scan req from anyone and connection req from White List devices only
|
||||
ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,
|
||||
///Allow scan and connection requests from White List devices only
|
||||
ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,
|
||||
///Enumeration end value for advertising filter policy value check
|
||||
} esp_ble_adv_filter_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16_t adv_int_min;
|
||||
uint16_t adv_int_max;
|
||||
esp_ble_adv_type_t adv_type;
|
||||
esp_bd_addr_t own_addr;
|
||||
esp_ble_addr_type_t own_addr_type;
|
||||
esp_bd_addr_t peer_addr;
|
||||
esp_ble_addr_type_t peer_addr_type;
|
||||
esp_ble_adv_channel_t channel_map;
|
||||
esp_ble_adv_filter_t adv_filter_policy;
|
||||
}esp_ble_adv_params_t;
|
||||
|
||||
typedef struct {
|
||||
bool set_scan_rsp;
|
||||
bool include_name;
|
||||
bool include_txpower;
|
||||
int min_interval;
|
||||
int max_interval;
|
||||
int appearance;
|
||||
uint16_t manufacturer_len;
|
||||
uint8_t *p_manufacturer_data;
|
||||
uint16_t service_data_len;
|
||||
uint8_t *p_service_data;
|
||||
uint16_t service_uuid_len;
|
||||
uint8_t *p_service_uuid;
|
||||
} esp_ble_adv_data_t;
|
||||
|
||||
typedef enum {
|
||||
BLE_SCAN_TYPE_PASSIVE = 0x0,
|
||||
BLE_SCAN_TYPE_ACTIVE = 0x1,
|
||||
} esp_ble_scan_type_t;
|
||||
|
||||
typedef enum {
|
||||
BLE_SCAN_FILTER_ALLOW_ALL = 0x0,
|
||||
BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1,
|
||||
BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2,
|
||||
BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3,
|
||||
} esp_ble_scan_filter_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
esp_ble_scan_type_t scan_type;
|
||||
esp_ble_addr_type_t own_addr_type;
|
||||
esp_ble_scan_filter_t scan_filter_policy;
|
||||
uint16_t scan_interval;
|
||||
uint16_t scan_window;
|
||||
} esp_ble_scan_params_t;
|
||||
|
||||
typedef struct {
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t min_int;
|
||||
uint16_t max_int;
|
||||
uint16_t latency;
|
||||
uint16_t timeout;
|
||||
} esp_ble_conn_update_params_t;
|
||||
|
||||
typedef void (*esp_gap_ble_cb_t)(esp_gap_ble_event_t event, void *param);
|
||||
|
||||
/* esp_ble_gap_args_t */
|
||||
typedef struct {
|
||||
esp_ble_adv_data_t adv_data;
|
||||
esp_ble_adv_params_t adv_params;
|
||||
esp_ble_scan_params_t scan_params;
|
||||
esp_ble_conn_update_params_t conn_params;
|
||||
esp_bd_addr_t remote_device;
|
||||
esp_bd_addr_t rand_addr;
|
||||
uint32_t duration;
|
||||
uint16_t tx_data_length;
|
||||
bool privacy_enable;
|
||||
#define ESP_GAP_DEVICE_NAME_MAX (32)
|
||||
char device_name[ESP_GAP_DEVICE_NAME_MAX+1];
|
||||
} esp_ble_gap_args_t;
|
||||
|
||||
typedef enum {
|
||||
/* Search callback events */
|
||||
ESP_GAP_SEARCH_INQ_RES_EVT = 0, /* Inquiry result for a peer device. */
|
||||
ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /* Inquiry complete. */
|
||||
ESP_GAP_SEARCH_DISC_RES_EVT = 2, /* Discovery result for a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /* Discovery result for BLE GATT based servoce on a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /* Discovery complete. */
|
||||
ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /* Discovery complete. */
|
||||
ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /* Search cancelled */
|
||||
} esp_gap_search_evt_t;
|
||||
|
||||
typedef union {
|
||||
//ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
|
||||
struct ble_adv_data_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} adv_data_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
|
||||
struct ble_scan_rsp_data_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} scan_rsp_data_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||
struct ble_scan_param_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} scan_param_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||
struct ble_scan_result_evt_param {
|
||||
esp_gap_search_evt_t search_evt;
|
||||
esp_bd_addr_t bda;
|
||||
esp_bt_dev_type_t dev_type;
|
||||
esp_ble_addr_type_t ble_addr_type;
|
||||
int rssi;
|
||||
int flag;
|
||||
int num_resps;
|
||||
} scan_rst;
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_register_callback
|
||||
**
|
||||
** @brief This function is called to occur gap event, such as scan result
|
||||
**
|
||||
** @param[in] callback: callback function
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_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
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_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.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_gap_ble_stop_advertising
|
||||
**
|
||||
** @brief This function is called to stop advertising.
|
||||
**
|
||||
** @param None
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_stop_advertising(void);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_update_conn_params
|
||||
**
|
||||
** @brief Update connection parameters, can only be used when connection is up.
|
||||
**
|
||||
** @param[in] param - connection update params
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_pkt_data_len
|
||||
**
|
||||
** @brief This function is to set maximum LE data packet size
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_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 ESP_OK - success, other - failed
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_config_local_privacy
|
||||
**
|
||||
** @brief Enable/disable privacy on the local device
|
||||
**
|
||||
** @param[in] privacy_enable - enable/disabe privacy on remote device.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_device_name
|
||||
**
|
||||
** @brief Set device name to the local device
|
||||
**
|
||||
** @param[in] name - device name.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_set_device_name(char *name);
|
||||
|
||||
#endif /* __ESP_GAP_BLE_API_H__ */
|
17
components/bt/bluedroid/api/include/esp_gap_bt_api.h
Normal file
17
components/bt/bluedroid/api/include/esp_gap_bt_api.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __ESP_GAP_BT_API_H__
|
||||
#define __ESP_GAP_BT_API_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
typedef enum {
|
||||
BT_SCAN_MODE_NONE = 0,
|
||||
BT_SCAN_MODE_CONNECTABLE,
|
||||
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
|
||||
} bt_scan_mode_t;
|
||||
|
||||
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
|
||||
|
||||
#endif /* __ESP_GAP_BT_API_H__ */
|
@ -1,829 +0,0 @@
|
||||
#ifndef __ESP_GATT_API_H__
|
||||
#define __ESP_GATT_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bt_prf_sys.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @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);
|
||||
|
||||
|
||||
#endif /* __ESP_GATT_API_H__ */
|
134
components/bt/bluedroid/api/include/esp_gatt_defs.h
Normal file
134
components/bt/bluedroid/api/include/esp_gatt_defs.h
Normal file
@ -0,0 +1,134 @@
|
||||
#ifndef __ESP_GATT_DEFS_H__
|
||||
#define __ESP_GATT_DEFS_H__
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
/* attribute request data from the client */
|
||||
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define ESP_GATT_PREP_WRITE_EXEC 0x01
|
||||
|
||||
/* Success code and error codes */
|
||||
typedef enum {
|
||||
ESP_GATT_OK = 0x0,
|
||||
ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */
|
||||
ESP_GATT_READ_NOT_PERMIT = 0x02, /* 0x0002 */
|
||||
ESP_GATT_WRITE_NOT_PERMIT = 0x03, /* 0x0003 */
|
||||
ESP_GATT_INVALID_PDU = 0x04, /* 0x0004 */
|
||||
ESP_GATT_INSUF_AUTHENTICATION = 0x05, /* 0x0005 */
|
||||
ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /* 0x0006 */
|
||||
ESP_GATT_INVALID_OFFSET = 0x07, /* 0x0007 */
|
||||
ESP_GATT_INSUF_AUTHORIZATION = 0x08, /* 0x0008 */
|
||||
ESP_GATT_PREPARE_Q_FULL = 0x09, /* 0x0009 */
|
||||
ESP_GATT_NOT_FOUND = 0x0a, /* 0x000a */
|
||||
ESP_GATT_NOT_LONG = 0x0b, /* 0x000b */
|
||||
ESP_GATT_INSUF_KEY_SIZE = 0x0c, /* 0x000c */
|
||||
ESP_GATT_INVALID_ATTR_LEN = 0x0d, /* 0x000d */
|
||||
ESP_GATT_ERR_UNLIKELY = 0x0e, /* 0x000e */
|
||||
ESP_GATT_INSUF_ENCRYPTION = 0x0f, /* 0x000f */
|
||||
ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /* 0x0010 */
|
||||
ESP_GATT_INSUF_RESOURCE = 0x11, /* 0x0011 */
|
||||
|
||||
ESP_GATT_NO_RESOURCES = 0x80, /* 0x80 */
|
||||
ESP_GATT_INTERNAL_ERROR = 0x81, /* 0x81 */
|
||||
ESP_GATT_WRONG_STATE = 0x82, /* 0x82 */
|
||||
ESP_GATT_DB_FULL = 0x83, /* 0x83 */
|
||||
ESP_GATT_BUSY = 0x84, /* 0x84 */
|
||||
ESP_GATT_ERROR = 0x85, /* 0x85 */
|
||||
ESP_GATT_CMD_STARTED = 0x86, /* 0x86 */
|
||||
ESP_GATT_ILLEGAL_PARAMETER = 0x87, /* 0x87 */
|
||||
ESP_GATT_PENDING = 0x88, /* 0x88 */
|
||||
ESP_GATT_AUTH_FAIL = 0x89, /* 0x89 */
|
||||
ESP_GATT_MORE = 0x8a, /* 0x8a */
|
||||
ESP_GATT_INVALID_CFG = 0x8b, /* 0x8b */
|
||||
ESP_GATT_SERVICE_STARTED = 0x8c, /* 0x8c */
|
||||
ESP_GATT_ENCRYPED_MITM = ESP_GATT_OK,
|
||||
ESP_GATT_ENCRYPED_NO_MITM = 0x8d, /* 0x8d */
|
||||
ESP_GATT_NOT_ENCRYPTED = 0x8e, /* 0x8e */
|
||||
ESP_GATT_CONGESTED = 0x8f, /* 0x8f */
|
||||
ESP_GATT_DUP_REG = 0x90, /* 0x90 */
|
||||
ESP_GATT_ALREADY_OPEN = 0x91, /* 0x91 */
|
||||
ESP_GATT_CANCEL = 0x92, /* 0x92 */
|
||||
|
||||
/* 0xE0 ~ 0xFC reserved for future use */
|
||||
ESP_GATT_CCC_CFG_ERR = 0xfd, /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
|
||||
ESP_GATT_PRC_IN_PROGRESS = 0xfe, /* 0xFE Procedure Already in progress */
|
||||
ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFFAttribute value out of range */
|
||||
} esp_gatt_status_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_GATT_CONN_UNKNOWN = 0,
|
||||
ESP_GATT_CONN_L2C_FAILURE = 1, /* general L2cap failure */
|
||||
ESP_GATT_CONN_TIMEOUT = 0x08, /* 0x08 connection timeout */
|
||||
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /* 0x13 connection terminate by peer user */
|
||||
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /* 0x16 connectionterminated by local host */
|
||||
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /* 0x03E connection fail to establish */
|
||||
// ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /* 0x22 connection fail for LMP response tout */
|
||||
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /* 0x0100 L2CAP connection cancelled */
|
||||
ESP_GATT_CONN_NONE = 0x0101 /* 0x0101 no connection to cancel */
|
||||
} esp_gatt_reason_t;
|
||||
|
||||
typedef struct {
|
||||
esp_bt_uuid_t uuid;
|
||||
uint8_t inst_id;
|
||||
} esp_gatt_id_t;
|
||||
|
||||
typedef struct {
|
||||
esp_gatt_id_t id;
|
||||
uint8_t is_primary;
|
||||
} esp_gatt_srvc_id_t;
|
||||
|
||||
typedef enum {
|
||||
AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might
|
||||
support "role switch during connection" for
|
||||
an incoming connection, when it already has
|
||||
another connection in master role */
|
||||
AUTH_REQ_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have
|
||||
simulateous connection in Master and Slave roles
|
||||
for short period of time */
|
||||
AUTH_REQ_FULL_SCATTERNET /* Device can have simultaneous connection in master
|
||||
and slave roles */
|
||||
} esp_gatt_auth_req_t;
|
||||
|
||||
/* Attribute permissions
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_PERM_READ = (1 << 0), /* bit 0 - 0x0001 */
|
||||
ESP_GATT_PERM_READ_ENCRYPTED = (1 << 1), /* bit 1 - 0x0002 */
|
||||
ESP_GATT_PERM_READ_ENC_MITM = (1 << 2), /* bit 2 - 0x0004 */
|
||||
ESP_GATT_PERM_WRITE = (1 << 4), /* bit 4 - 0x0010 */
|
||||
ESP_GATT_PERM_WRITE_ENCRYPTED = (1 << 5), /* bit 5 - 0x0020 */
|
||||
ESP_GATT_PERM_WRITE_ENC_MITM = (1 << 6), /* bit 6 - 0x0040 */
|
||||
ESP_GATT_PERM_WRITE_SIGNED = (1 << 7), /* bit 7 - 0x0080 */
|
||||
ESP_GATT_PERM_WRITE_SIGNED_MITM = (1 << 8), /* bit 8 - 0x0100 */
|
||||
} esp_gatt_perm_t;
|
||||
|
||||
/* definition of characteristic properties */
|
||||
typedef enum {
|
||||
ESP_GATT_CHAR_PROP_BIT_BROADCAST = (1 << 0), /* 0x01 */
|
||||
ESP_GATT_CHAR_PROP_BIT_READ = (1 << 1), /* 0x02 */
|
||||
ESP_GATT_CHAR_PROP_BIT_WRITE_NR = (1 << 2), /* 0x04 */
|
||||
ESP_GATT_CHAR_PROP_BIT_WRITE = (1 << 3), /* 0x08 */
|
||||
ESP_GATT_CHAR_PROP_BIT_NOTIFY = (1 << 4), /* 0x10 */
|
||||
ESP_GATT_CHAR_PROP_BIT_INDICATE = (1 << 5), /* 0x20 */
|
||||
ESP_GATT_CHAR_PROP_BIT_AUTH = (1 << 6), /* 0x40 */
|
||||
ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */
|
||||
} esp_gatt_char_prop_t;
|
||||
|
||||
#define ESP_GATT_MAX_ATTR_LEN 600
|
||||
typedef struct {
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
uint16_t len;
|
||||
uint8_t auth_req;
|
||||
} esp_gatt_value_t;
|
||||
|
||||
/** GATT remote read request response type */
|
||||
typedef union {
|
||||
esp_gatt_value_t attr_value;
|
||||
uint16_t handle;
|
||||
} esp_gatt_rsp_t;
|
||||
|
||||
typedef uint32_t esp_gatt_if_t;
|
||||
|
||||
#endif /* __ESP_GATT_DEFS_H__ */
|
554
components/bt/bluedroid/api/include/esp_gattc_api.h
Normal file
554
components/bt/bluedroid/api/include/esp_gattc_api.h
Normal file
@ -0,0 +1,554 @@
|
||||
#ifndef __ESP_GATTC_API_H__
|
||||
#define __ESP_GATTC_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/* Client callback function events */
|
||||
#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */
|
||||
#define ESP_GATTC_UNREG_EVT 1 /* GATT client unregistered 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 */
|
||||
|
||||
#define ESP_GATTC_GET_CHAR_EVT 35 /* get characteristic event */
|
||||
#define ESP_GATTC_GET_DESCR_EVT 36 /* get characteristic descriptor event */
|
||||
#define ESP_GATTC_GET_INCL_SRVC_EVT 37 /* get included service event */
|
||||
#define ESP_GATTC_REG_FOR_NOTIF_EVT 38 /* register for notification event */
|
||||
|
||||
|
||||
#define ESP_GATT_DEF_BLE_MTU_SIZE 23
|
||||
#define ESP_GATT_MAX_MTU_SIZE 517
|
||||
|
||||
|
||||
/* esp_ble_gattc_args_t */
|
||||
typedef struct {
|
||||
uint16_t app_id;
|
||||
uint16_t conn_id;
|
||||
uint16_t mtu;
|
||||
uint16_t len;
|
||||
uint16_t offset;
|
||||
esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
|
||||
esp_gatt_srvc_id_t service_uuid;
|
||||
esp_gatt_srvc_id_t start_service_uuid;
|
||||
esp_gatt_id_t char_uuid;
|
||||
esp_gatt_id_t descr_uuid;
|
||||
esp_gatt_auth_req_t auth_req;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_bt_uuid_t uuid;
|
||||
bool is_direct;
|
||||
bool is_execute;
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
} esp_ble_gattc_args_t;
|
||||
|
||||
/* esp_ble_gattc_cb_param_t */
|
||||
typedef union {
|
||||
/*registration data for ESP_GATTC_REG_EVT */
|
||||
struct gattc_reg_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bt_uuid_t uuid; /* btla-specific ++ */
|
||||
} reg;
|
||||
|
||||
/* ESP_GATTC_OPEN_EVT */
|
||||
struct gattc_open_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
uint16_t conn_id;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
// tBTA_TRANSPORT transport;
|
||||
uint16_t mtu;
|
||||
} open;
|
||||
|
||||
/* ESP_GATTC_CLOSE_EVT */
|
||||
struct gattc_close_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
uint16_t conn_id;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_gatt_reason_t reason;
|
||||
} close;
|
||||
|
||||
/* ESP_GATTC_CFG_MTU_EVT */
|
||||
struct gattc_cfg_mtu_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
uint16_t mtu;
|
||||
} cfg_mtu;
|
||||
|
||||
/* ESP_GATTC_SEARCH_CMPL_EVT */
|
||||
struct gattc_search_cmpl_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
} search_cmpl;
|
||||
|
||||
/* ESP_GATTC_SEARCH_RES_EVT */
|
||||
struct gattc_search_res_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_srvc_id_t service_uuid;
|
||||
} search_res;
|
||||
|
||||
/* ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT */
|
||||
struct gattc_read_char_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
uint16_t value_type;
|
||||
uint16_t value_len;
|
||||
} read; /* ESP_GATTC_READ_CHAR_EVT */
|
||||
|
||||
/* ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT */
|
||||
struct gattc_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
} write;
|
||||
|
||||
/* ESP_GATTC_EXEC_EVT */
|
||||
struct gattc_exec_cmpl_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
} exec_cmpl;
|
||||
|
||||
/* ESP_GATTC_NOTIF_EVT */
|
||||
struct gattc_notify_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_bd_addr_t bda;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
uint16_t value_len;
|
||||
UINT8 value[ESP_GATT_MAX_ATTR_LEN];
|
||||
bool is_notify;
|
||||
} notify;
|
||||
|
||||
/* ESP_GATTC_SRVC_CHG_EVT*/
|
||||
struct gattc_srvc_chg_evt_param {
|
||||
esp_bd_addr_t remote_bda;
|
||||
} srvc_chg;
|
||||
|
||||
/* ESP_GATTC_CONGEST_EVT */
|
||||
struct gattc_congest_evt_param {
|
||||
uint16_t conn_id;
|
||||
bool congested;
|
||||
} congest;
|
||||
|
||||
/* ESP_GATTC_GET_CHAR_EVT */
|
||||
struct gattc_get_char_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_char_prop_t char_prop;
|
||||
} get_char;
|
||||
|
||||
/* ESP_GATTC_GET_DESCR_EVT */
|
||||
struct gattc_get_descr_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
} get_descr;
|
||||
|
||||
/* ESP_GATTC_GET_INCL_SRVC_EVT */
|
||||
struct gattc_get_incl_srvc_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_srvc_id_t incl_srvc_id;
|
||||
} get_incl_srvc;
|
||||
|
||||
/* ESP_GATTC_REG_FOR_NOTIF_EVT, ESP_GATTC_UNREG_FOR_NOTIF_EVT */
|
||||
struct gattc_reg_for_notif_evt_param {
|
||||
uint16_t conn_id;
|
||||
bool registered;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
} reg_for_notif;
|
||||
|
||||
} esp_ble_gattc_cb_param_t;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] callback - pointer to the application callback function.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] app_id : Application Identitfy (UUID), for different application
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_unregister
|
||||
**
|
||||
** @brief This function is called to unregister an application
|
||||
** from GATTC module.
|
||||
**
|
||||
** @param[in] gatt_if - app identifier.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_conn
|
||||
**
|
||||
** @brief Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application identity.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool 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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t 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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_search_service
|
||||
**
|
||||
** @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] filter_uuid: a UUID of the service application is interested in.
|
||||
** If Null, discover for all services.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_characteristic
|
||||
**
|
||||
** @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: serivce ID
|
||||
**
|
||||
** @param[in] start_char_id: the start characteristic ID
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *start_char_id);
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_descriptor
|
||||
**
|
||||
** @brief This function is called to find the descriptor 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_id: Characteristic ID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] start_descr_id: the sctart descriptor id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *start_descr_id);
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_include_service
|
||||
**
|
||||
** @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] start_incl_srvc_id: the start include service id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_srvc_id_t *start_incl_srvc_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char
|
||||
**
|
||||
** @brief This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteritic ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_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] srvc_id - serivcie ID.
|
||||
** @param[in] descr_id - characteritic descriptor ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char
|
||||
**
|
||||
** @brief This function is called to write characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID to write.
|
||||
** @param[in] len: length of the data to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
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] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID.
|
||||
** @param[in] descr_id - characteristic descriptor ID to write.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t len,
|
||||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_prepare_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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t offset,
|
||||
uint16_t len,
|
||||
uint8_t *data,
|
||||
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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_register_for_notify
|
||||
**
|
||||
** @brief This function is called to register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if registration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_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] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if deregistration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
||||
|
||||
#endif /* __ESP_GATTC_API_H__ */
|
430
components/bt/bluedroid/api/include/esp_gatts_api.h
Normal file
430
components/bt/bluedroid/api/include/esp_gatts_api.h
Normal file
@ -0,0 +1,430 @@
|
||||
#ifndef __ESP_GATTS_API_H__
|
||||
#define __ESP_GATTS_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/* GATT Server Data Structure */
|
||||
/* Server callback function events */
|
||||
#define ESP_GATTS_REG_EVT 0
|
||||
#define ESP_GATTS_READ_EVT 1
|
||||
#define ESP_GATTS_WRITE_EVT 2
|
||||
#define ESP_GATTS_EXEC_WRITE_EVT 3
|
||||
#define ESP_GATTS_MTU_EVT 4
|
||||
#define ESP_GATTS_CONF_EVT 5
|
||||
#define ESP_GATTS_UNREG_EVT 6
|
||||
#define ESP_GATTS_CREATE_EVT 7
|
||||
#define ESP_GATTS_ADD_INCL_SRVC_EVT 8
|
||||
#define ESP_GATTS_ADD_CHAR_EVT 9
|
||||
#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10
|
||||
#define ESP_GATTS_DELELTE_EVT 11
|
||||
#define ESP_GATTS_START_EVT 12
|
||||
#define ESP_GATTS_STOP_EVT 13
|
||||
#define ESP_GATTS_CONNECT_EVT 14
|
||||
#define ESP_GATTS_DISCONNECT_EVT 15
|
||||
#define ESP_GATTS_OPEN_EVT 16
|
||||
#define ESP_GATTS_CANCEL_OPEN_EVT 17
|
||||
#define ESP_GATTS_CLOSE_EVT 18
|
||||
#define ESP_GATTS_LISTEN_EVT 19
|
||||
#define ESP_GATTS_CONGEST_EVT 20
|
||||
/* following is extra event */
|
||||
#define ESP_GATTS_RESPONSE_EVT 21
|
||||
|
||||
/* esp_ble_gatts_args_t */
|
||||
typedef struct {
|
||||
esp_gatt_if_t gatt_if; /* internal is server_if or client_if */
|
||||
esp_gatt_srvc_id_t service_uuid;
|
||||
esp_gatt_id_t char_uuid;
|
||||
esp_gatt_id_t descr_uuid;
|
||||
esp_bt_uuid_t uuid;
|
||||
esp_gatt_rsp_t rsp;
|
||||
esp_gatt_perm_t perm;
|
||||
esp_gatt_char_prop_t property;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_gatt_status_t status;
|
||||
uint16_t service_handle;
|
||||
uint16_t included_service_handle;
|
||||
uint16_t attr_handle;
|
||||
uint16_t num_handle;
|
||||
uint16_t conn_id;
|
||||
uint16_t trans_id;
|
||||
bool need_confirm;
|
||||
bool is_direct;
|
||||
uint16_t app_uuid;
|
||||
uint16_t data_len;
|
||||
uint8_t data[ESP_GATT_MAX_ATTR_LEN];
|
||||
} esp_ble_gatts_args_t;
|
||||
|
||||
|
||||
/* esp_ble_gatts_cb_param_t */
|
||||
typedef union {
|
||||
//ESP_GATTS_REG_EVT
|
||||
struct gatts_reg_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t app_id;
|
||||
} reg;
|
||||
// param for ESP_GATTS_READ_EVT
|
||||
struct gatts_read_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
bool is_long;
|
||||
} read;
|
||||
// param for ESP_GATTS_WRITE_EVT
|
||||
struct gatts_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
bool need_rsp;
|
||||
bool is_prep;
|
||||
uint16_t len;
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
} write;
|
||||
// param for ESP_GATTS_EXEC_WRITE_EVT
|
||||
struct gatts_exec_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define ESP_GATT_PREP_WRITE_EXEC 0x01
|
||||
uint8_t exec_write_flag;
|
||||
} exec_write;
|
||||
// param for ESP_GATTS_MTU_EVT
|
||||
struct gatts_mtu_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t mtu;
|
||||
} mtu;
|
||||
// param for ESP_GATTS_CONF_EVT
|
||||
struct gatts_conf_evt_param {
|
||||
uint16_t conn_id;
|
||||
int status;
|
||||
} conf;
|
||||
// param for ESP_GATTS_DEREG_EVT, NONE
|
||||
// param for ESP_GATTS_CREATE_EVT
|
||||
struct gatts_create_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
esp_gatt_srvc_id_t service_id; //uuid
|
||||
} create;
|
||||
// param for ESP_GATTS_ADD_INCL_SRVC_EVT
|
||||
struct gatts_add_incl_srvc_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
} add_incl_srvc;
|
||||
// param for ESP_GATTS_ADD_CHAR_EVT
|
||||
struct gatts_add_char_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
esp_bt_uuid_t char_uuid;
|
||||
} add_char;
|
||||
// param for ESP_GATTS_ADD_CHAR_DESCR_EVT
|
||||
struct gatts_add_char_descr_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
esp_bt_uuid_t char_uuid;
|
||||
} add_char_descr;
|
||||
// param for ESP_GATTS_DELELTE_EVT
|
||||
struct gatts_delete_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} del;
|
||||
// param for ESP_GATTS_START_EVT
|
||||
struct gatts_start_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} start;
|
||||
// param for ESP_GATTS_STOP_EVT
|
||||
struct gatts_stop_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} stop;
|
||||
// param for ESP_GATTS_CONNECT_EVT
|
||||
struct gatts_connect_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_connected;
|
||||
} connect;
|
||||
// param for ESP_GATTS_DISCONNECT_EVT
|
||||
struct gatts_disconnect_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_connected;
|
||||
} disconnect;
|
||||
// param for ESP_GATTS_OPEN_EVT none
|
||||
// param for ESP_GATTS_CANCEL_OPEN_EVT none
|
||||
// param for ESP_GATTS_CLOSE_EVT none
|
||||
// param for ESP_GATTS_LISTEN_EVT none
|
||||
// param for ESP_GATTS_CONGEST_EVT
|
||||
struct gatts_congest_evt_param {
|
||||
uint16_t conn_id;
|
||||
bool congested;
|
||||
} congest;
|
||||
// param for ESP_GATTS_RESPONSE_EVT
|
||||
struct gatts_rsp_evt_param {
|
||||
int status; //response status, 0 is success
|
||||
uint16_t handle; //attribute handle which send response
|
||||
} rsp;
|
||||
} esp_ble_gatts_cb_param_t;
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with BTA GATTS module.
|
||||
**
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_register
|
||||
**
|
||||
** @brief This function is called to register application identity
|
||||
**
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_app_register(uint16_t app_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_unregister
|
||||
**
|
||||
** @brief un-register with GATT Server.
|
||||
**
|
||||
** @param[in] gatt_if: gatt interface id.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_create_service
|
||||
**
|
||||
** @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] gatt_if: gatt interface ID
|
||||
** @param[in] service_uuid: service UUID.
|
||||
** @param[in] num_handle: numble of handle requessted for this service.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_gatt_srvc_id_t *service_uuid, uint16_t num_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_include_service
|
||||
**
|
||||
** @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_handle: service handle to which this included service is to
|
||||
** be added.
|
||||
** @param[in] included_service_handle: the service ID to be included.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_char
|
||||
**
|
||||
** @brief This function is called to add a characteristic into a service.
|
||||
**
|
||||
** @param[in] service_handle: service handle 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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, 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_handle: service handle to which this charatceristic descriptor is to
|
||||
** be added.
|
||||
** @param[in] perm: descriptor access permission.
|
||||
** @param[in] descr_uuid: descriptor UUID.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
|
||||
esp_bt_uuid_t *descr_uuid,
|
||||
esp_gatt_perm_t perm);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_delete_service
|
||||
**
|
||||
** @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_handled: service_handle to be deleted.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_start_service
|
||||
**
|
||||
** @brief This function is called to start a service.
|
||||
**
|
||||
** @param[in] service_handle: the service handle to be started.
|
||||
** @param[in] sup_transport: supported trasnport.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_stop_service
|
||||
**
|
||||
** @brief This function is called to stop a service.
|
||||
**
|
||||
** @param[in] service_handle - service to be topped.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_send_indicate
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] conn_id - connection id to indicate.
|
||||
** @param[in] attribute_handle - attribute handle 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 ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t data_len, uint8_t *data, bool 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 - transfe id
|
||||
** @param[in] status - response status
|
||||
** @param[in] rsp - response data.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_open
|
||||
**
|
||||
** @brief Open a direct open connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application ID.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_close
|
||||
**
|
||||
** @brief Close a connection a remote device.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id);
|
||||
|
||||
|
||||
#endif /* __ESP_GATTS_API_H__ */
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_common.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "bta_sdp_api.h"
|
||||
#include "bt_sdp.h"
|
||||
|
||||
|
@ -1000,6 +1000,8 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
|
||||
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;
|
||||
|
||||
bta_sys_sendmsg(p_msg);
|
||||
}
|
||||
|
||||
|
||||
|
26
components/bt/bluedroid/btc/core/btc_main.c
Normal file
26
components/bt/bluedroid/btc/core/btc_main.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "btc_main.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
extern int bte_main_boot_entry(void *cb);
|
||||
extern int bte_main_shutdown(void);
|
||||
|
||||
bt_status_t btc_enable_bluetooth(esp_bt_sec_cb_t *p_cback)
|
||||
{
|
||||
return BTA_EnableBluetooth(p_cback) == BTA_SUCCESS ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
|
||||
}
|
||||
|
||||
bt_status_t btc_disable_bluetooth(void)
|
||||
{
|
||||
return BTA_DisableBluetooth() == BTA_SUCCESS ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
|
||||
}
|
||||
|
||||
bt_status_t btc_init_bluetooth(bluetooth_init_cb_t cb)
|
||||
{
|
||||
return bte_main_boot_entry(cb) == 0 ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void btc_deinit_bluetooth(void)
|
||||
{
|
||||
bte_main_shutdown();
|
||||
}
|
54
components/bt/bluedroid/btc/core/btc_manage.c
Normal file
54
components/bt/bluedroid/btc/core/btc_manage.c
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#include "btc_task.h"
|
||||
#include "bt_trace.h"
|
||||
#include "thread.h"
|
||||
#include "gki.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
|
||||
static esp_profile_cb_t btc_profile_cb_tab[BTC_PID_NUM] = {};
|
||||
|
||||
void esp_profile_cb_reset(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < BTC_PID_NUM; i++) {
|
||||
btc_profile_cb_tab[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
|
||||
{
|
||||
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
btc_profile_cb_tab[profile_id] = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id)
|
||||
{
|
||||
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_profile_cb_tab[profile_id];
|
||||
}
|
||||
|
||||
|
128
components/bt/bluedroid/btc/core/btc_task.c
Normal file
128
components/bt/bluedroid/btc/core/btc_task.c
Normal file
@ -0,0 +1,128 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "btc_task.h"
|
||||
#include "bt_trace.h"
|
||||
#include "thread.h"
|
||||
#include "gki.h"
|
||||
#include "bt_defs.h"
|
||||
#include "btc_gatts.h"
|
||||
#include "btc_gattc.h"
|
||||
#include "btc_gap_ble.h"
|
||||
|
||||
static xTaskHandle xBtcTaskHandle = NULL;
|
||||
static xQueueHandle xBtcQueue = 0;
|
||||
|
||||
static btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
|
||||
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
|
||||
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
|
||||
[BTC_PID_GAP_BT] = {NULL, NULL}, // {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
|
||||
[BTC_PID_SDP] = {NULL, NULL},
|
||||
[BTC_PID_BLE_HID] = {NULL, NULL},
|
||||
[BTC_PID_BT_HID] = {NULL, NULL},
|
||||
[BTC_PID_SPP] = {NULL, NULL},
|
||||
[BTC_PID_SPPLIKE] = {NULL, NULL},
|
||||
[BTC_PID_BLUFI] = {NULL, NULL},
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
**
|
||||
** Function btc_task
|
||||
**
|
||||
** Description Process profile Task Thread.
|
||||
******************************************************************************/
|
||||
static void btc_task(void *arg)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
||||
for (;;) {
|
||||
if (pdTRUE == xQueueReceive(xBtcQueue, &msg, (portTickType)portMAX_DELAY)) {
|
||||
switch (msg.sig) {
|
||||
case BTC_SIG_API_CALL:
|
||||
profile_tab[msg.pid].btc_call(&msg);
|
||||
break;
|
||||
case BTC_SIG_API_CB:
|
||||
profile_tab[msg.pid].btc_cb(&msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (msg.arg) {
|
||||
GKI_freebuf(msg.arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bt_status_t btc_task_post(btc_msg_t *msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
return BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
if (xQueueSend(xBtcQueue, &msg, 10/portTICK_RATE_MS) != pdTRUE) {
|
||||
LOG_ERROR("Btc Post failed\n");
|
||||
return BT_STATUS_BUSY;
|
||||
}
|
||||
|
||||
return BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func)
|
||||
{
|
||||
btc_msg_t lmsg;
|
||||
|
||||
if (msg == NULL) {
|
||||
return BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
LOG_DEBUG("%s msg %u %u %u %08x\n", __func__, msg->sig, msg->pid, msg->act, msg->arg);
|
||||
|
||||
memcpy(&lmsg, msg, sizeof(btc_msg_t));
|
||||
if (arg) {
|
||||
lmsg.arg = (void *)GKI_getbuf(arg_len);
|
||||
if (lmsg.arg == NULL) {
|
||||
return BT_STATUS_NOMEM;
|
||||
}
|
||||
memcpy(lmsg.arg, arg, arg_len);
|
||||
if (copy_func) {
|
||||
copy_func(&lmsg, lmsg.arg, arg);
|
||||
}
|
||||
}
|
||||
|
||||
return btc_task_post(&lmsg);
|
||||
}
|
||||
|
||||
|
||||
int btc_init(void)
|
||||
{
|
||||
xBtcQueue = xQueueCreate(60, sizeof(btc_msg_t));
|
||||
xTaskCreate(btc_task, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xBtcTaskHandle);
|
||||
|
||||
/* TODO: initial the profile_tab */
|
||||
|
||||
return BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void btc_deinit(void)
|
||||
{
|
||||
vTaskDelete(xBtcTaskHandle);
|
||||
vQueueDelete(xBtcQueue);
|
||||
|
||||
xBtcTaskHandle = NULL;
|
||||
xBtcQueue = 0;
|
||||
}
|
17
components/bt/bluedroid/btc/core/include/btc_main.h
Normal file
17
components/bt/bluedroid/btc/core/include/btc_main.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __BTC_BT_COMMON_H__
|
||||
#define __BTC_BT_COMMON_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "bta_api.h"
|
||||
|
||||
typedef tBTA_DM_SEC_CBACK esp_bt_sec_cb_t;
|
||||
|
||||
typedef void (*bluetooth_init_cb_t)(void);
|
||||
|
||||
|
||||
bt_status_t btc_enable_bluetooth(esp_bt_sec_cb_t *p_cback);
|
||||
bt_status_t btc_disable_bluetooth(void);
|
||||
bt_status_t btc_init_bluetooth(bluetooth_init_cb_t cb);
|
||||
void btc_deinit_bluetooth(void);
|
||||
|
||||
#endif /* __BTC_BT_COMMON_H__ */
|
14
components/bt/bluedroid/btc/include/btc_manage.h
Normal file
14
components/bt/bluedroid/btc/include/btc_manage.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __BTC_MANAGE_H__
|
||||
#define __BTC_MANAGE_H__
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btc_task.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
/* reset gatt callback table */
|
||||
void esp_profile_cb_reset(void);
|
||||
|
||||
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb);
|
||||
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id);
|
||||
|
||||
#endif /* __BTC_MANAGE_H__ */
|
48
components/bt/bluedroid/btc/include/btc_task.h
Normal file
48
components/bt/bluedroid/btc/include/btc_task.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef __BTC_TASK_H__
|
||||
#define __BTC_TASK_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bt_defs.h"
|
||||
|
||||
#define BTC_TASK_QUEUE_NUM 20
|
||||
#define BTC_TASK_STACK_SIZE 4096
|
||||
#define BTC_TASK_NAME "btcT"
|
||||
|
||||
typedef struct btc_msg {
|
||||
uint8_t sig; //event signal
|
||||
uint8_t aid; //application id
|
||||
uint8_t pid; //profile id
|
||||
uint8_t act; //profile action, defined in seprerate header files
|
||||
void *arg; //param for btc function or function param
|
||||
} btc_msg_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_SIG_API_CALL = 0, // APP TO STACK
|
||||
BTC_SIG_API_CB, // STACK TO APP
|
||||
BTC_SIG_NUM,
|
||||
} btc_sig_t; //btc message type
|
||||
|
||||
typedef enum {
|
||||
BTC_PID_GATTS = 0,
|
||||
BTC_PID_GATTC,
|
||||
BTC_PID_GAP_BLE,
|
||||
BTC_PID_GAP_BT,
|
||||
BTC_PID_SDP,
|
||||
BTC_PID_BLE_HID,
|
||||
BTC_PID_BT_HID,
|
||||
BTC_PID_SPP,
|
||||
BTC_PID_SPPLIKE,
|
||||
BTC_PID_BLUFI,
|
||||
BTC_PID_NUM,
|
||||
} btc_pid_t; //btc profile id
|
||||
|
||||
typedef struct {
|
||||
void (* btc_call)(btc_msg_t *msg);
|
||||
void (* btc_cb)(btc_msg_t *msg);
|
||||
} btc_func_t;
|
||||
|
||||
typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
|
||||
|
||||
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);
|
||||
|
||||
#endif /* __BTC_TASK_H__ */
|
186
components/bt/bluedroid/btc/profile/esp/blufi/blufi_adv.c
Normal file
186
components/bt/bluedroid/btc/profile/esp/blufi/blufi_adv.c
Normal file
@ -0,0 +1,186 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "blufi_adv.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BlufiConfigadvData
|
||||
**
|
||||
** Description This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** p_adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback)
|
||||
{
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
if(adv_data->adv_name != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
|
||||
BTA_DmSetDeviceName(adv_data->adv_name);
|
||||
}
|
||||
if(adv_data->ble_adv_data.int_range.low != 0 ||
|
||||
adv_data->ble_adv_data.int_range.hi != 0)
|
||||
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
|
||||
|
||||
if(adv_data->ble_adv_data.p_manu != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_MANU;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_services_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_sol_service_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_service_data != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.appearance != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.p_proprietary != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
|
||||
}
|
||||
|
||||
if(adv_data->ble_adv_data.tx_power != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
|
||||
}
|
||||
|
||||
BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BLUFI_BleSetScanRsp
|
||||
**
|
||||
** Description This function is called to override the app scan response.
|
||||
**
|
||||
** Parameters Pointer to User defined ADV data structure
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback)
|
||||
{
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
if(scan_rsp_data->adv_name != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
|
||||
BTA_DmSetDeviceName(scan_rsp_data->adv_name);
|
||||
}
|
||||
if(scan_rsp_data->ble_adv_data.int_range.low != 0 ||
|
||||
scan_rsp_data->ble_adv_data.int_range.hi != 0)
|
||||
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_manu != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_MANU;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_services_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_services != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_service_data != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.appearance != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.p_proprietary != NULL)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
|
||||
}
|
||||
|
||||
if(scan_rsp_data->ble_adv_data.tx_power != 0)
|
||||
{
|
||||
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
|
||||
}
|
||||
|
||||
BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback);
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,6 @@
|
||||
#include "blufi_prf.h"
|
||||
#include "blufi_adv.h"
|
||||
|
||||
#include "esp_adv_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_api.h"
|
||||
|
||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||
|
||||
@ -45,13 +41,13 @@ UINT8 esp32_manu[17] = {0xff,0x20,0x14,0x07,0x22,0x00,0x02,0x5B,0x00,0x33,0x49,0
|
||||
tBTA_BLE_MANU p_esp32_manu = {sizeof(esp32_manu),esp32_manu}; /* manufacturer data */
|
||||
|
||||
tBTA_BLE_SERVICE esp32_service = {
|
||||
0x01, //only one service in the blufi profile
|
||||
0x01, //only one service in the ijiazu button profile
|
||||
false,
|
||||
&esp32_uuid
|
||||
}; /* 16 bits services */
|
||||
|
||||
|
||||
esp_ble_adv_data_cfg_t esp32_adv_data[ADV_SCAN_IDX_MAX] =
|
||||
tBLUFI_BLE_ADV_DATA esp32_adv_data[ADV_SCAN_IDX_MAX] =
|
||||
{
|
||||
[BLE_ADV_DATA_IDX] = {
|
||||
.adv_name = "Espressif_008",
|
||||
@ -91,21 +87,7 @@ esp_ble_adv_data_cfg_t esp32_adv_data[ADV_SCAN_IDX_MAX] =
|
||||
}
|
||||
};
|
||||
|
||||
tBLE_BD_ADDR peer_bda = {
|
||||
.type = API_PUBLIC_ADDR,
|
||||
.bda = {0}
|
||||
};
|
||||
|
||||
esp_ble_adv_params_all_t adv_params =
|
||||
{
|
||||
.adv_int_min = BTM_BLE_ADV_INT_MIN + 0x100,
|
||||
.adv_int_max = BTM_BLE_ADV_INT_MIN + 0x100,
|
||||
.adv_type = API_NON_DISCOVERABLE,
|
||||
.addr_type_own = API_PUBLIC_ADDR,
|
||||
.channel_map = ESP_BLE_ADV_CHNL_MAP,
|
||||
.adv_filter_policy = ADV_ALLOW_SCAN_ANY_CON_ANY,
|
||||
.p_dir_bda = &peer_bda
|
||||
};
|
||||
|
||||
static tBLUFI_CB_ENV blufi_cb_env;
|
||||
|
||||
@ -114,7 +96,7 @@ static tBLUFI_CB_ENV blufi_cb_env;
|
||||
/*****************************************************************************
|
||||
** Constants
|
||||
*****************************************************************************/
|
||||
static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data);
|
||||
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -126,24 +108,24 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data);
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
{
|
||||
esp_gatts_rsp_t rsp;
|
||||
esp_bt_uuid_t uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
tBTA_GATTS_RSP rsp;
|
||||
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
tBLUFI_INST *p_inst = &blufi_cb_env.blufi_inst;
|
||||
UINT8 net_event = 0xff;
|
||||
UINT8 len = 0;
|
||||
UINT8 *p_rec_data = NULL;
|
||||
esp_gatt_status_t status;
|
||||
tBTA_GATT_STATUS status;
|
||||
|
||||
LOG_DEBUG("blufi profile cb event = %x\n",event);
|
||||
switch(event) {
|
||||
case ESP_GATTS_REG_EVT:
|
||||
case BTA_GATTS_REG_EVT:
|
||||
status = p_data->reg_oper.status;
|
||||
|
||||
LOG_DEBUG("p_data->reg_oper.status = %x\n",p_data->reg_oper.status);
|
||||
LOG_DEBUG("(p_data->reg_oper.uuid.uu.uuid16=%x\n",p_data->reg_oper.uuid.uu.uuid16);
|
||||
if(p_data->reg_oper.status != ESP_GATT_OK) {
|
||||
if(p_data->reg_oper.status != BTA_GATT_OK) {
|
||||
LOG_ERROR("blufi profile register failed\n");
|
||||
return;
|
||||
}
|
||||
@ -158,13 +140,14 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
BlufiBleConfigadvData(&esp32_adv_data[BLE_ADV_DATA_IDX], NULL);
|
||||
//set the adversting data to the btm layer
|
||||
BlufiBleSetScanRsp(&esp32_adv_data[BLE_SCAN_RSP_DATA_IDX],NULL);
|
||||
esp_ble_start_advertising(&adv_params);
|
||||
BTA_GATTS_Listen(blufi_cb_env.gatt_if, true, NULL);
|
||||
|
||||
//create the blufi service to the service data base.
|
||||
if(p_data->reg_oper.uuid.uu.uuid16 == SVC_BLUFI_UUID) {
|
||||
blufi_create_service();
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_READ_EVT:
|
||||
case BTA_GATTS_READ_EVT:
|
||||
memset(&rsp, 0, sizeof(tBTA_GATTS_API_RSP));
|
||||
rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle;
|
||||
rsp.attr_value.len = 2;
|
||||
@ -172,11 +155,11 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
//rsp.attr_value.value[1] = 0xed;
|
||||
//rsp.attr_value.value[2] = 0xbe;
|
||||
//rsp.attr_value.value[3] = 0xef;
|
||||
esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id,
|
||||
BTA_GATTS_SendRsp(p_data->req_data.conn_id,p_data->req_data.trans_id,
|
||||
p_data->req_data.status,&rsp);
|
||||
break;
|
||||
case ESP_GATTS_WRITE_EVT:
|
||||
esp_ble_gatts_send_rsp(p_data->req_data.conn_id,p_data->req_data.trans_id,
|
||||
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);
|
||||
|
||||
LOG_DEBUG("Received blufi data:");
|
||||
@ -192,36 +175,36 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
p_inst->blufi_cback(blufi_cb_env.blufi_inst.app_id, net_event, len, p_rec_data);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_CFM_EVT:
|
||||
case BTA_GATTS_CONF_EVT:
|
||||
/* Nothing */
|
||||
break;
|
||||
case ESP_GATTS_CREATE_EVT:
|
||||
case BTA_GATTS_CREATE_EVT:
|
||||
uuid.uu.uuid16 = CHAR_BLUFI_UUID;
|
||||
blufi_cb_env.clcb.cur_srvc_id = p_data->create.service_id;
|
||||
blufi_cb_env.is_primery = p_data->create.is_primary;
|
||||
//start the blufi service after created
|
||||
esp_ble_gatts_start_srvc(p_data->create.service_id);
|
||||
BTA_GATTS_StartService(p_data->create.service_id, BTA_GATT_TRANSPORT_LE);
|
||||
//add the frist blufi characteristic --> write characteristic
|
||||
esp_ble_gatts_add_char(blufi_cb_env.clcb.cur_srvc_id, &uuid,
|
||||
BTA_GATTS_AddCharacteristic(blufi_cb_env.clcb.cur_srvc_id, &uuid,
|
||||
(GATT_PERM_WRITE | GATT_PERM_READ),
|
||||
(GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE | GATT_CHAR_PROP_BIT_NOTIFY));
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_EVT:
|
||||
case BTA_GATTS_ADD_CHAR_EVT:
|
||||
if(p_data->add_result.char_uuid.uu.uuid16 == CHAR_BLUFI_UUID)
|
||||
{
|
||||
//save the att handle to the env
|
||||
blufi_cb_env.blufi_inst.blufi_hdl = p_data->add_result.attr_id;
|
||||
|
||||
uuid.uu.uuid16 = GATT_UUID_CHAR_CLIENT_CONFIG;
|
||||
esp_ble_gatts_add_char_descr(blufi_cb_env.clcb.cur_srvc_id,
|
||||
BTA_GATTS_AddCharDescriptor (blufi_cb_env.clcb.cur_srvc_id,
|
||||
(GATT_PERM_WRITE|GATT_PERM_WRITE),
|
||||
&uuid);
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
/* Nothing */
|
||||
break;
|
||||
case ESP_GATTS_CONNECT_EVT:
|
||||
case BTA_GATTS_CONNECT_EVT:
|
||||
//set the connection flag to true
|
||||
blufi_env_clcb_alloc(p_data->conn.conn_id, p_data->conn.remote_bda);
|
||||
LOG_DEBUG("\ndevice is connected "BT_BD_ADDR_STR", server_if=%d,reason=0x%x,connect_id=%d\n",
|
||||
@ -230,23 +213,24 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
/*return whether the remote device is currently connected*/
|
||||
int is_connected = BTA_DmGetConnectionState(p_data->conn.remote_bda);
|
||||
LOG_DEBUG("is_connected=%d\n",is_connected);
|
||||
esp_ble_stop_advertising(); //stop adv
|
||||
BTA_DmBleBroadcast(0); //stop adv
|
||||
break;
|
||||
case ESP_GATTS_DISCONNECT_EVT:
|
||||
case BTA_GATTS_DISCONNECT_EVT:
|
||||
//set the connection flag to true
|
||||
blufi_cb_env.clcb.connected = false;
|
||||
esp_ble_start_advertising(&adv_params);
|
||||
break;
|
||||
case ESP_GATTS_OPEN_EVT:
|
||||
case BTA_GATTS_OPEN_EVT:
|
||||
break;
|
||||
case ESP_GATTS_CLOSE_EVT:
|
||||
case BTA_GATTS_CLOSE_EVT:
|
||||
if(blufi_cb_env.clcb.connected && (blufi_cb_env.clcb.conn_id == p_data->conn.conn_id))
|
||||
{
|
||||
//set the connection channal congested flag to true
|
||||
blufi_cb_env.clcb.congest = p_data->congest.congested;
|
||||
}
|
||||
break;
|
||||
case ESP_GATTS_CONGEST_EVT:
|
||||
case BTA_GATTS_LISTEN_EVT:
|
||||
break;
|
||||
case BTA_GATTS_CONGEST_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -265,8 +249,8 @@ static void blufi_profile_cb(esp_gatts_evt_t event, esp_gatts_t *p_data)
|
||||
*******************************************************************************/
|
||||
void blufi_create_service(void)
|
||||
{
|
||||
esp_gatts_if_t server_if ;
|
||||
esp_bt_uuid_t uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
tBTA_GATTS_IF server_if ;
|
||||
tBT_UUID uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
UINT16 num_handle = BLUFI_HDL_NUM;
|
||||
UINT8 inst = 0x00;
|
||||
server_if = blufi_cb_env.gatt_if;
|
||||
@ -276,7 +260,7 @@ void blufi_create_service(void)
|
||||
LOG_ERROR("blufi service added error.");
|
||||
return;
|
||||
}
|
||||
esp_ble_gatts_create_srvc(server_if, &uuid, inst, num_handle, true);
|
||||
BTA_GATTS_CreateService(server_if, &uuid, inst, num_handle, true);
|
||||
|
||||
}
|
||||
|
||||
@ -357,9 +341,9 @@ BOOLEAN blufi_env_clcb_dealloc(UINT16 conn_id)
|
||||
** Description Initializa the GATT Service for blufi profiles.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t blufi_profile_init (tBLUFI_CBACK *call_back)
|
||||
tGATT_STATUS blufi_profile_init (tBLUFI_CBACK *call_back)
|
||||
{
|
||||
esp_bt_uuid_t app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
tBT_UUID app_uuid = {LEN_UUID_16, {SVC_BLUFI_UUID}};
|
||||
|
||||
|
||||
if(blufi_cb_env.enabled)
|
||||
@ -379,8 +363,8 @@ esp_gatt_status_t blufi_profile_init (tBLUFI_CBACK *call_back)
|
||||
}
|
||||
|
||||
|
||||
/* register the blufi profile to the ESP_GATTS module*/
|
||||
esp_ble_gatts_app_register(&app_uuid, blufi_profile_cb);
|
||||
/* register the blufi profile to the BTA_GATTS module*/
|
||||
BTA_GATTS_AppRegister(&app_uuid, blufi_profile_cb);
|
||||
|
||||
return GATT_SUCCESS;
|
||||
}
|
||||
@ -398,7 +382,7 @@ void blufi_msg_notify(UINT8 *blufi_msg, UINT8 len)
|
||||
return;
|
||||
}
|
||||
|
||||
esp_ble_gatts_hdl_val_indica(conn_id, attr_id, len,
|
||||
BTA_GATTS_HandleValueIndication (conn_id, attr_id, len,
|
||||
blufi_msg, rsp);
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
#ifndef __BLUFI_ADV_H__
|
||||
#define __BLUFI_ADV_H__
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btm_ble_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
typedef enum {
|
||||
BLE_ADV_DATA_IDX = 0,
|
||||
BLE_SCAN_RSP_DATA_IDX = 1,
|
||||
ADV_SCAN_IDX_MAX,
|
||||
} ADV_SCAN_IDX_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *adv_name; //set the device name to be sent on the advertising
|
||||
tBTA_BLE_ADV_DATA ble_adv_data;
|
||||
}tBLUFI_BLE_ADV_DATA;
|
||||
|
||||
extern void BlufiBleConfigadvData(tBLUFI_BLE_ADV_DATA *adv_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
|
||||
|
||||
extern void BlufiBleSetScanRsp(tBLUFI_BLE_ADV_DATA *scan_rsp_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback);
|
||||
|
||||
#endif /* __BLUFI_ADV_H__ */
|
581
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
Normal file
581
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
Normal file
@ -0,0 +1,581 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btc_task.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gap_ble.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gap_ble_api.h"
|
||||
|
||||
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
|
||||
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
|
||||
|
||||
#define BTC_GAP_BLE_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GAP_BLE))(_event, _param)
|
||||
|
||||
|
||||
static void btc_gap_adv_point_cleanup(void** buf)
|
||||
{
|
||||
if (NULL == *buf) return;
|
||||
GKI_freebuf(*buf);
|
||||
*buf = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void btc_cleanup_adv_data(tBTA_BLE_ADV_DATA *bta_adv_data)
|
||||
{
|
||||
if (bta_adv_data == NULL)
|
||||
return;
|
||||
|
||||
// Manufacturer data cleanup
|
||||
if (bta_adv_data->p_manu != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_manu->p_val);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_manu);
|
||||
}
|
||||
|
||||
// Proprietary data cleanup
|
||||
if (bta_adv_data->p_proprietary != NULL)
|
||||
{
|
||||
int i = 0;
|
||||
tBTA_BLE_PROP_ELEM *p_elem = bta_adv_data->p_proprietary->p_elem;
|
||||
while (i++ != bta_adv_data->p_proprietary->num_elem
|
||||
&& p_elem)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &p_elem->p_val);
|
||||
++p_elem;
|
||||
}
|
||||
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_proprietary->p_elem);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_proprietary);
|
||||
}
|
||||
|
||||
// Service list cleanup
|
||||
if (bta_adv_data->p_services != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_services->p_uuid);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_services);
|
||||
}
|
||||
|
||||
// Service data cleanup
|
||||
if (bta_adv_data->p_service_data != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_service_data->p_val);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_service_data);
|
||||
}
|
||||
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_services_128b);
|
||||
|
||||
if (bta_adv_data->p_service_32b != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_service_32b->p_uuid);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_service_32b);
|
||||
}
|
||||
|
||||
if (bta_adv_data->p_sol_services != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_sol_services->p_uuid);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_sol_services);
|
||||
}
|
||||
|
||||
if (bta_adv_data->p_sol_service_32b != NULL)
|
||||
{
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_sol_service_32b->p_uuid);
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_sol_service_32b);
|
||||
}
|
||||
|
||||
btc_gap_adv_point_cleanup((void**) &bta_adv_data->p_sol_service_128b);
|
||||
}
|
||||
|
||||
|
||||
static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DATA *bta_adv_data, uint32_t *data_mask)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
btc_cleanup_adv_data(bta_adv_data);
|
||||
|
||||
memset(bta_adv_data, 0, sizeof(tBTA_BLE_ADV_DATA));
|
||||
mask = 0;
|
||||
|
||||
if (!p_adv_data->set_scan_rsp)
|
||||
{
|
||||
mask = BTM_BLE_AD_BIT_FLAGS;
|
||||
}
|
||||
|
||||
if (p_adv_data->include_name)
|
||||
mask |= BTM_BLE_AD_BIT_DEV_NAME;
|
||||
|
||||
if (p_adv_data->include_txpower)
|
||||
mask |= BTM_BLE_AD_BIT_TX_PWR;
|
||||
|
||||
if (p_adv_data->min_interval > 0 && p_adv_data->max_interval > 0 &&
|
||||
p_adv_data->max_interval >= p_adv_data->min_interval)
|
||||
{
|
||||
mask |= BTM_BLE_AD_BIT_INT_RANGE;
|
||||
bta_adv_data->int_range.low = p_adv_data->min_interval;
|
||||
bta_adv_data->int_range.hi = p_adv_data->max_interval;
|
||||
}
|
||||
|
||||
if (p_adv_data->include_txpower)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
if (p_adv_data->appearance != 0)
|
||||
{
|
||||
mask |= BTM_BLE_AD_BIT_APPEARANCE;
|
||||
bta_adv_data->appearance = p_adv_data->appearance;
|
||||
}
|
||||
|
||||
if (p_adv_data->manufacturer_len > 0 && p_adv_data->p_manufacturer_data != NULL)
|
||||
{
|
||||
bta_adv_data->p_manu = GKI_getbuf(sizeof(tBTA_BLE_MANU));
|
||||
if (bta_adv_data->p_manu != NULL)
|
||||
{
|
||||
bta_adv_data->p_manu->p_val = GKI_getbuf(p_adv_data->manufacturer_len);
|
||||
if (bta_adv_data->p_manu->p_val != NULL)
|
||||
{
|
||||
mask |= BTM_BLE_AD_BIT_MANU;
|
||||
bta_adv_data->p_manu->len = p_adv_data->manufacturer_len;
|
||||
memcpy(bta_adv_data->p_manu->p_val, p_adv_data->p_manufacturer_data, p_adv_data->manufacturer_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tBTA_BLE_PROP_ELEM *p_elem_service_data = NULL;
|
||||
if (p_adv_data->service_data_len > 0 && p_adv_data->p_service_data != NULL)
|
||||
{
|
||||
p_elem_service_data = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM));
|
||||
if (p_elem_service_data != NULL)
|
||||
{
|
||||
p_elem_service_data->p_val = GKI_getbuf(p_adv_data->service_data_len);
|
||||
if (p_elem_service_data->p_val != NULL)
|
||||
{
|
||||
p_elem_service_data->adv_type = BTM_BLE_AD_TYPE_SERVICE_DATA;
|
||||
p_elem_service_data->len = p_adv_data->service_data_len;
|
||||
memcpy(p_elem_service_data->p_val, p_adv_data->p_service_data,
|
||||
p_adv_data->service_data_len);
|
||||
} else {
|
||||
GKI_freebuf(p_elem_service_data);
|
||||
p_elem_service_data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != p_elem_service_data)
|
||||
{
|
||||
bta_adv_data->p_proprietary = GKI_getbuf(sizeof(tBTA_BLE_PROPRIETARY));
|
||||
if (NULL != bta_adv_data->p_proprietary)
|
||||
{
|
||||
tBTA_BLE_PROP_ELEM *p_elem = NULL;
|
||||
tBTA_BLE_PROPRIETARY *p_prop = bta_adv_data->p_proprietary;
|
||||
p_prop->num_elem = 0;
|
||||
mask |= BTM_BLE_AD_BIT_PROPRIETARY;
|
||||
p_prop->num_elem = 1;
|
||||
p_prop->p_elem = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM) * p_prop->num_elem);
|
||||
p_elem = p_prop->p_elem;
|
||||
if (NULL != p_elem)
|
||||
memcpy(p_elem++, p_elem_service_data, sizeof(tBTA_BLE_PROP_ELEM));
|
||||
GKI_freebuf(p_elem_service_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_adv_data->service_uuid_len && p_adv_data->p_service_uuid)
|
||||
{
|
||||
UINT16 *p_uuid_out16 = NULL;
|
||||
UINT32 *p_uuid_out32 = NULL;
|
||||
for (int position = 0; position < p_adv_data->service_uuid_len; position += LEN_UUID_128)
|
||||
{
|
||||
tBT_UUID bt_uuid;
|
||||
|
||||
memcpy(&bt_uuid.uu, p_adv_data->p_service_uuid + position, LEN_UUID_128);
|
||||
bt_uuid.len = p_adv_data->service_uuid_len;
|
||||
|
||||
switch(bt_uuid.len)
|
||||
{
|
||||
case (LEN_UUID_16):
|
||||
{
|
||||
if (NULL == bta_adv_data->p_services)
|
||||
{
|
||||
bta_adv_data->p_services =
|
||||
GKI_getbuf(sizeof(tBTA_BLE_SERVICE));
|
||||
bta_adv_data->p_services->list_cmpl = FALSE;
|
||||
bta_adv_data->p_services->num_service = 0;
|
||||
bta_adv_data->p_services->p_uuid =
|
||||
GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16);
|
||||
p_uuid_out16 = bta_adv_data->p_services->p_uuid;
|
||||
}
|
||||
|
||||
if (NULL != bta_adv_data->p_services->p_uuid)
|
||||
{
|
||||
LOG_ERROR("%s - In 16-UUID_data", __FUNCTION__);
|
||||
mask |= BTM_BLE_AD_BIT_SERVICE;
|
||||
++bta_adv_data->p_services->num_service;
|
||||
*p_uuid_out16++ = bt_uuid.uu.uuid16;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case (LEN_UUID_32):
|
||||
{
|
||||
if (NULL == bta_adv_data->p_service_32b)
|
||||
{
|
||||
bta_adv_data->p_service_32b =
|
||||
GKI_getbuf(sizeof(tBTA_BLE_32SERVICE));
|
||||
bta_adv_data->p_service_32b->list_cmpl = FALSE;
|
||||
bta_adv_data->p_service_32b->num_service = 0;
|
||||
bta_adv_data->p_service_32b->p_uuid =
|
||||
GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_32);
|
||||
p_uuid_out32 = bta_adv_data->p_service_32b->p_uuid;
|
||||
}
|
||||
|
||||
if (NULL != bta_adv_data->p_service_32b->p_uuid)
|
||||
{
|
||||
LOG_ERROR("%s - In 32-UUID_data", __FUNCTION__);
|
||||
mask |= BTM_BLE_AD_BIT_SERVICE_32;
|
||||
++bta_adv_data->p_service_32b->num_service;
|
||||
*p_uuid_out32++ = bt_uuid.uu.uuid32;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case (LEN_UUID_128):
|
||||
{
|
||||
/* Currently, only one 128-bit UUID is supported */
|
||||
if (NULL == bta_adv_data->p_services_128b)
|
||||
{
|
||||
bta_adv_data->p_services_128b =
|
||||
GKI_getbuf(sizeof(tBTA_BLE_128SERVICE));
|
||||
if (NULL != bta_adv_data->p_services_128b)
|
||||
{
|
||||
LOG_ERROR("%s - In 128-UUID_data", __FUNCTION__);
|
||||
mask |= BTM_BLE_AD_BIT_SERVICE_128;
|
||||
memcpy(bta_adv_data->p_services_128b->uuid128,
|
||||
bt_uuid.uu.uuid128, LEN_UUID_128);
|
||||
LOG_ERROR("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x", bt_uuid.uu.uuid128[0],
|
||||
bt_uuid.uu.uuid128[1],bt_uuid.uu.uuid128[2], bt_uuid.uu.uuid128[3],
|
||||
bt_uuid.uu.uuid128[4],bt_uuid.uu.uuid128[5],bt_uuid.uu.uuid128[6],
|
||||
bt_uuid.uu.uuid128[7],bt_uuid.uu.uuid128[8],bt_uuid.uu.uuid128[9],
|
||||
bt_uuid.uu.uuid128[10],bt_uuid.uu.uuid128[11],bt_uuid.uu.uuid128[12],
|
||||
bt_uuid.uu.uuid128[13],bt_uuid.uu.uuid128[14],bt_uuid.uu.uuid128[15]);
|
||||
bta_adv_data->p_services_128b->list_cmpl = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*data_mask = mask;
|
||||
}
|
||||
|
||||
static void btc_adv_data_callback(tBTA_STATUS status)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT;
|
||||
param.adv_data_cmpl.status = status;
|
||||
|
||||
ret = btc_transfer_context(&msg, ¶m,
|
||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback)
|
||||
{
|
||||
tBTA_BLE_ADV_DATA bta_adv_data; //TODO:must be global, not stack
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
|
||||
btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask);
|
||||
BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback);
|
||||
}
|
||||
|
||||
static void btc_scan_rsp_data_callback(tBTA_STATUS status)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT;
|
||||
param.scan_rsp_data_cmpl.status = status;
|
||||
|
||||
ret = btc_transfer_context(&msg, ¶m,
|
||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_set_scan_rsp_data(esp_ble_adv_data_t *scan_rsp_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback)
|
||||
{
|
||||
tBTA_BLE_AD_MASK data_mask = 0;
|
||||
|
||||
btc_to_bta_adv_data(scan_rsp_data, &gl_bta_scan_rsp_data, &data_mask);
|
||||
BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_scan_rsp_data_cback);
|
||||
}
|
||||
|
||||
static void btc_ble_start_advertising(esp_ble_adv_params_t *ble_adv_params)
|
||||
{
|
||||
tBLE_BD_ADDR bd_addr;
|
||||
|
||||
|
||||
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 < ADV_TYPE_NON_DISCOVERABLE) &&
|
||||
(ble_adv_params->adv_type > ADV_TYPE_BROADCASTER_MODE) )
|
||||
{
|
||||
LOG_ERROR("Invalid advertisting type parameters.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ble_adv_params->adv_filter_policy < ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY) &&
|
||||
(ble_adv_params->adv_filter_policy > ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST) )
|
||||
{
|
||||
LOG_ERROR("Invalid advertisting type parameters.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_ERROR("API_Ble_AppStartAdvertising\n");
|
||||
|
||||
bd_addr.type = ble_adv_params->peer_addr_type;
|
||||
memcpy(&bd_addr.bda, ble_adv_params->peer_addr, sizeof(BD_ADDR));
|
||||
///
|
||||
BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min,
|
||||
ble_adv_params->adv_int_max,
|
||||
ble_adv_params->adv_type,
|
||||
ble_adv_params->own_addr_type,
|
||||
ble_adv_params->channel_map,
|
||||
ble_adv_params->adv_filter_policy,
|
||||
&bd_addr);
|
||||
}
|
||||
|
||||
|
||||
static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT;
|
||||
param.scan_param_cmpl.status = status;
|
||||
|
||||
ret = btc_transfer_context(&msg, ¶m,
|
||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params,
|
||||
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
|
||||
{
|
||||
if (API_BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
|
||||
API_BLE_ISVALID_PARAM(scan_params->scan_window, 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(0 /*client_if*/,
|
||||
scan_params->scan_interval,
|
||||
scan_params->scan_window,
|
||||
scan_params->scan_type,
|
||||
scan_params->own_addr_type,
|
||||
scan_params->scan_filter_policy,
|
||||
scan_param_setup_cback);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
btc_msg_t msg;
|
||||
uint8_t len;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SCAN_RESULT_EVT;
|
||||
|
||||
param.scan_rst.search_evt = event;
|
||||
switch (event) {
|
||||
case BTA_DM_INQ_RES_EVT: {
|
||||
bdcpy(param.scan_rst.bda, p_data->inq_res.bd_addr);
|
||||
param.scan_rst.dev_type = p_data->inq_res.device_type;
|
||||
param.scan_rst.rssi = p_data->inq_res.rssi;
|
||||
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
|
||||
param.scan_rst.flag = p_data->inq_res.flag;
|
||||
break;
|
||||
}
|
||||
case BTA_DM_INQ_CMPL_EVT: {
|
||||
param.scan_rst.num_resps = p_data->inq_cmpl.num_resps;
|
||||
LOG_ERROR("%s BLE observe complete. Num Resp %d", __FUNCTION__,p_data->inq_cmpl.num_resps);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_ERROR("%s : Unknown event 0x%x", __FUNCTION__, event);
|
||||
return;
|
||||
}
|
||||
btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
}
|
||||
|
||||
|
||||
static void btc_ble_start_scanning(uint8_t duration, tBTA_DM_SEARCH_CBACK *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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void btc_ble_stop_advertising(void)
|
||||
{
|
||||
bool stop_adv = false;
|
||||
|
||||
BTA_DmBleBroadcast(stop_adv);
|
||||
}
|
||||
|
||||
static void btc_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);
|
||||
}
|
||||
|
||||
static void btc_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);
|
||||
}
|
||||
|
||||
static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
|
||||
{
|
||||
if (rand_addr != NULL){
|
||||
BTA_DmSetRandAddress(rand_addr);
|
||||
}else{
|
||||
LOG_ERROR("Invalid randrom address.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_config_local_privacy(bool privacy_enable)
|
||||
{
|
||||
BTA_DmBleConfigLocalPrivacy(privacy_enable);
|
||||
}
|
||||
|
||||
|
||||
void btc_gap_ble_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gap_cb_param_t *param = (esp_ble_gap_cb_param_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
|
||||
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT, param);
|
||||
break;
|
||||
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT :
|
||||
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT, param);
|
||||
break;
|
||||
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
|
||||
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, param);
|
||||
break;
|
||||
case ESP_GAP_BLE_SCAN_RESULT_EVT:
|
||||
BTC_GAP_BLE_CB_TO_APP(ESP_GAP_BLE_SCAN_RESULT_EVT, param);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void btc_gap_ble_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gap_args_t *arg = (esp_ble_gap_args_t *)msg->arg;
|
||||
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA:
|
||||
btc_ble_set_adv_data(&arg->adv_data, btc_adv_data_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_SCAN_PARAM:
|
||||
btc_ble_set_scan_rsp_data(&arg->adv_data, btc_adv_data_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_START_SCAN:
|
||||
btc_ble_start_scanning(arg->duration, btc_search_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_STOP_SCAN:
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_START_ADV:
|
||||
btc_ble_start_advertising(&arg->adv_params);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_STOP_ADV:
|
||||
btc_ble_stop_advertising();
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM:
|
||||
btc_ble_update_conn_params(arg->conn_params.bda, arg->conn_params.min_int,
|
||||
arg->conn_params.max_int, arg->conn_params.latency, arg->conn_params.timeout);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN:
|
||||
btc_ble_set_pkt_data_len(arg->remote_device, arg->tx_data_length);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS:
|
||||
btc_ble_set_rand_addr(arg->rand_addr);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
|
||||
btc_ble_config_local_privacy(arg->privacy_enable);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_DEV_NAME:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_gap_api.h"
|
||||
#include "esp_gap_bt_api.h"
|
||||
#include "bta_api.h"
|
||||
#include "bt_trace.h"
|
||||
|
176
components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c
Normal file
176
components/bt/bluedroid/btc/profile/std/gatt/btc_gatt_util.c
Normal file
@ -0,0 +1,176 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "btc_gatt_util.h"
|
||||
|
||||
#define GATTC_READ_VALUE_TYPE_VALUE 0x0000 /* Attribute value itself */
|
||||
#define GATTC_READ_VALUE_TYPE_AGG_FORMAT 0x2905 /* Characteristic Aggregate Format*/
|
||||
|
||||
static unsigned char BASE_UUID[16] = {
|
||||
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
|
||||
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* BTIF -> BTA conversion functions
|
||||
*******************************************************************************/
|
||||
int uuidType(unsigned char* p_uuid)
|
||||
{
|
||||
int i = 0;
|
||||
int match = 0;
|
||||
int all_zero = 1;
|
||||
|
||||
for(i = 0; i != 16; ++i)
|
||||
{
|
||||
if (i == 12 || i == 13)
|
||||
continue;
|
||||
|
||||
if (p_uuid[i] == BASE_UUID[i])
|
||||
++match;
|
||||
|
||||
if (p_uuid[i] != 0)
|
||||
all_zero = 0;
|
||||
}
|
||||
if (all_zero)
|
||||
return 0;
|
||||
if (match == 12)
|
||||
return LEN_UUID_32;
|
||||
if (match == 14)
|
||||
return LEN_UUID_16;
|
||||
return LEN_UUID_128;
|
||||
}
|
||||
|
||||
void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src)
|
||||
{
|
||||
char *p_byte = (char*)p_src;
|
||||
int i = 0;
|
||||
|
||||
p_dest->len = uuidType(p_src->uu);
|
||||
|
||||
switch (p_dest->len)
|
||||
{
|
||||
case LEN_UUID_16:
|
||||
p_dest->uu.uuid16 = (p_src->uu[13] << 8) + p_src->uu[12];
|
||||
break;
|
||||
|
||||
case LEN_UUID_32:
|
||||
p_dest->uu.uuid32 = (p_src->uu[13] << 8) + p_src->uu[12];
|
||||
p_dest->uu.uuid32 += (p_src->uu[15] << 24) + (p_src->uu[14] << 16);
|
||||
break;
|
||||
|
||||
case LEN_UUID_128:
|
||||
for(i = 0; i != 16; ++i)
|
||||
p_dest->uu.uuid128[i] = p_byte[i];
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_ERROR("%s: Unknown UUID length %d!", __FUNCTION__, p_dest->len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* BTC -> BTA conversion functions
|
||||
*******************************************************************************/
|
||||
|
||||
void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_bt_uuid_t));
|
||||
}
|
||||
|
||||
void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_gatt_srvc_id_t));
|
||||
}
|
||||
|
||||
void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_id_t *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_gatt_id_t));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* BTA -> BTC conversion functions
|
||||
*******************************************************************************/
|
||||
void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_bt_uuid_t));
|
||||
}
|
||||
|
||||
void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_gatt_id_t));
|
||||
}
|
||||
|
||||
void bta_to_btc_srvc_id(esp_gatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src)
|
||||
{
|
||||
memcpy(p_dest, p_src, sizeof(esp_gatt_srvc_id_t));
|
||||
}
|
||||
|
||||
void btc_to_bta_response(tBTA_GATTS_RSP *rsp_struct, esp_gatt_rsp_t *p_rsp)
|
||||
{
|
||||
memcpy(rsp_struct, p_rsp, sizeof(esp_gatt_rsp_t));
|
||||
}
|
||||
|
||||
uint16_t get_uuid16(tBT_UUID *p_uuid)
|
||||
{
|
||||
if (p_uuid->len == LEN_UUID_16)
|
||||
{
|
||||
return p_uuid->uu.uuid16;
|
||||
}
|
||||
else if (p_uuid->len == LEN_UUID_128)
|
||||
{
|
||||
UINT16 u16;
|
||||
UINT8 *p = &p_uuid->uu.uuid128[LEN_UUID_128 - 4];
|
||||
STREAM_TO_UINT16(u16, p);
|
||||
return u16;
|
||||
}
|
||||
else /* p_uuid->len == LEN_UUID_32 */
|
||||
{
|
||||
return(UINT16) p_uuid->uu.uuid32;
|
||||
}
|
||||
}
|
||||
uint16_t set_read_value(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
|
||||
{
|
||||
uint16_t descr_type = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
p_dest->read.status = p_src->status;
|
||||
p_dest->read.conn_id = p_src->conn_id;
|
||||
bta_to_btc_srvc_id(&p_dest->read.srvc_id, &p_src->srvc_id);
|
||||
bta_to_btc_gatt_id(&p_dest->read.char_id, &p_src->char_id);
|
||||
bta_to_btc_gatt_id(&p_dest->read.descr_id, &p_src->descr_type);
|
||||
|
||||
descr_type = get_uuid16(&p_src->descr_type.uuid);
|
||||
|
||||
switch (descr_type)
|
||||
{
|
||||
case GATT_UUID_CHAR_AGG_FORMAT:
|
||||
/* not supported */
|
||||
p_dest->read.value_type = GATTC_READ_VALUE_TYPE_AGG_FORMAT;
|
||||
p_dest->read.value_len = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (( p_src->status == BTA_GATT_OK ) &&(p_src->p_value != NULL))
|
||||
{
|
||||
LOG_INFO("%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len);
|
||||
p_dest->read.value_len = p_src->p_value->unformat.len;
|
||||
if ( p_src->p_value->unformat.len > 0 && p_src->p_value->unformat.p_value != NULL )
|
||||
{
|
||||
memcpy(p_dest->read.value, p_src->p_value->unformat.p_value,
|
||||
p_src->p_value->unformat.len);
|
||||
}
|
||||
len += p_src->p_value->unformat.len;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_dest->read.value_len = 0;
|
||||
}
|
||||
|
||||
p_dest->read.value_type = GATTC_READ_VALUE_TYPE_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
585
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
Normal file
585
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c
Normal file
@ -0,0 +1,585 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "btm_ble_api.h"
|
||||
#include "btc_gattc.h"
|
||||
#include "btc_gatt_util.h"
|
||||
#include "btc_manage.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bt_trace.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
#define BTC_GATTC_CB_TO_APP(_event, _param) ((esp_profile_cb_t )btc_profile_cb_get(BTC_PID_GATTC))(_event, _param)
|
||||
|
||||
// TODO: to be finished, used in deep-copying data from lower layer
|
||||
static void btc_gattc_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
tBTA_GATTC *p_dest_data = (tBTA_GATTC*) p_dest;
|
||||
tBTA_GATTC *p_src_data = (tBTA_GATTC*) p_src;
|
||||
|
||||
if (!p_src_data || !p_dest_data)
|
||||
return;
|
||||
|
||||
// Allocate buffer for request data if necessary
|
||||
switch (msg->act) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: to be finished, used to free deep-copied data allocated using btc_gattc_copy_req_data()
|
||||
static void btc_gattc_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
{
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = (uint8_t) event;
|
||||
|
||||
ret = btc_transfer_context(&msg, &p_data, sizeof(tBTA_GATTC), btc_gattc_copy_req_data);
|
||||
|
||||
if (ret)
|
||||
LOG_ERROR("%s transfer failed\n", __func__);
|
||||
}
|
||||
|
||||
static void btc_gattc_app_register(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBT_UUID app_uuid;
|
||||
app_uuid.len = 2;
|
||||
app_uuid.uu.uuid16 = arg->app_id;
|
||||
BTA_GATTC_AppRegister(&app_uuid, btc_gattc_cback);
|
||||
}
|
||||
|
||||
static void btc_gattc_app_unregister(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
BTA_GATTC_AppDeregister(arg->gatt_if);
|
||||
}
|
||||
|
||||
static void btc_gattc_open(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
|
||||
BTA_GATTC_Open(arg->gatt_if, arg->remote_bda, arg->is_direct, transport);
|
||||
}
|
||||
|
||||
static void btc_gattc_close(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
// TODO; Review this call of BTA_API, check the usage of BTA_GATTC_CancelOpen
|
||||
BTA_GATTC_Close(arg->conn_id);
|
||||
}
|
||||
|
||||
static void btc_gattc_cfg_mtu(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
BTA_GATTC_ConfigureMTU (arg->conn_id, arg->mtu);
|
||||
}
|
||||
|
||||
static void btc_gattc_search_service(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBT_UUID *srvc_uuid = (tBT_UUID *)(&arg->uuid);
|
||||
BTA_GATTC_ServiceSearchRequest(arg->conn_id, srvc_uuid);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_first_char(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_id_t char_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_ID out_char_id;
|
||||
tBTA_GATT_CHAR_PROP out_char_prop;
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->service_uuid);
|
||||
status = BTA_GATTC_GetFirstChar(arg->conn_id, &srvc_id, NULL,
|
||||
&out_char_id, &out_char_prop);
|
||||
if (status == 0) {
|
||||
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_char.conn_id = arg->conn_id;
|
||||
param.get_char.status = status;
|
||||
memcpy(¶m.get_char.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
|
||||
param.get_char.char_prop = out_char_prop;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_char(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_id_t char_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
tBTA_GATTC_CHAR_ID out_char_id;
|
||||
tBTA_GATT_CHAR_PROP out_char_prop;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
status = BTA_GATTC_GetNextChar(arg->conn_id, &in_char_id, NULL,
|
||||
&out_char_id, &out_char_prop);
|
||||
|
||||
if (status == 0) {
|
||||
bta_to_btc_gatt_id(&char_id, &out_char_id.char_id);
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_char.conn_id = arg->conn_id;
|
||||
param.get_char.status = status;
|
||||
memcpy(¶m.get_char.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_char.char_id, &char_id, sizeof(esp_gatt_id_t));
|
||||
param.get_char.char_prop = out_char_prop;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_CHAR_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_first_descr(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_id_t descr_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
status = BTA_GATTC_GetFirstCharDescr(arg->conn_id, &in_char_id, NULL,
|
||||
&out_char_descr_id);
|
||||
|
||||
if (status == 0) {
|
||||
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_descr.conn_id = arg->conn_id;
|
||||
param.get_descr.status = status;
|
||||
memcpy(¶m.get_descr.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_descr.char_id, &arg->char_uuid, sizeof(esp_gatt_id_t));
|
||||
memcpy(¶m.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_descr(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_id_t descr_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
|
||||
tBTA_GATTC_CHAR_DESCR_ID out_char_descr_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->char_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.descr_id, &arg->descr_uuid);
|
||||
|
||||
status = BTA_GATTC_GetNextCharDescr(arg->conn_id, &in_char_descr_id
|
||||
, NULL, &out_char_descr_id);
|
||||
if (status == 0) {
|
||||
bta_to_btc_gatt_id(&descr_id, &out_char_descr_id.descr_id);
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_descr.conn_id = arg->conn_id;
|
||||
param.get_descr.status = status;
|
||||
memcpy(¶m.get_descr.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_descr.char_id, &arg->char_uuid, sizeof(esp_gatt_id_t));
|
||||
memcpy(¶m.get_descr.descr_id, &descr_id, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_DESCR_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_first_incl_service(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_srvc_id_t incl_srvc_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->service_uuid);
|
||||
|
||||
status = BTA_GATTC_GetFirstIncludedService(arg->conn_id, &srvc_id,
|
||||
NULL, &out_incl_svc_id);
|
||||
|
||||
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_incl_srvc.conn_id = arg->conn_id;
|
||||
param.get_incl_srvc.status = status;
|
||||
memcpy(¶m.get_incl_srvc.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_get_next_incl_service(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
esp_gatt_srvc_id_t incl_srvc_id;
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_INCL_SVC_ID in_incl_svc_id;
|
||||
tBTA_GATTC_INCL_SVC_ID out_incl_svc_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&in_incl_svc_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_srvc_id(&in_incl_svc_id.incl_svc_id, &arg->start_service_uuid);
|
||||
|
||||
status = BTA_GATTC_GetNextIncludedService(arg->conn_id, &in_incl_svc_id,
|
||||
NULL, &out_incl_svc_id);
|
||||
|
||||
bta_to_btc_srvc_id(&incl_srvc_id, &out_incl_svc_id.incl_svc_id);
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.get_incl_srvc.conn_id = arg->conn_id;
|
||||
param.get_incl_srvc.status = status;
|
||||
memcpy(¶m.get_incl_srvc.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.get_incl_srvc.incl_srvc_id, &incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_GET_INCL_SRVC_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_read_char(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
BTA_GATTC_ReadCharacteristic(arg->conn_id, &in_char_id, arg->auth_req);
|
||||
}
|
||||
|
||||
static void btc_gattc_read_char_descr(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
|
||||
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->char_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.descr_id, &arg->descr_uuid);
|
||||
|
||||
BTA_GATTC_ReadCharDescr(arg->conn_id, &in_char_descr_id, arg->auth_req);
|
||||
}
|
||||
|
||||
static void btc_gattc_write_char(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
//TODO: check the write type
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
tBTA_GATTC_WRITE_TYPE write_type = BTA_GATTC_TYPE_WRITE;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
BTA_GATTC_WriteCharValue(arg->conn_id, &in_char_id,
|
||||
write_type,
|
||||
arg->len,
|
||||
arg->value,
|
||||
arg->auth_req);
|
||||
}
|
||||
|
||||
static void btc_gattc_write_char_descr(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
//TODO: check the write type
|
||||
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
|
||||
tBTA_GATT_UNFMT descr_val;
|
||||
tBTA_GATTC_WRITE_TYPE write_type = BTA_GATTC_TYPE_WRITE;
|
||||
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->char_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.descr_id, &arg->descr_uuid);
|
||||
|
||||
descr_val.len = arg->len;
|
||||
descr_val.p_value = arg->value;
|
||||
|
||||
BTA_GATTC_WriteCharDescr(arg->conn_id, &in_char_descr_id,
|
||||
write_type, &descr_val,
|
||||
arg->auth_req);
|
||||
}
|
||||
|
||||
static void btc_gattc_prepare_write(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
BTA_GATTC_PrepareWrite(arg->conn_id, &in_char_id, arg->offset, arg->len,
|
||||
arg->value, arg->auth_req);
|
||||
}
|
||||
|
||||
static void btc_gattc_execute_wrtie(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
BTA_GATTC_ExecuteWrite(arg->conn_id, arg->is_execute);
|
||||
}
|
||||
|
||||
static void btc_gattc_reg_for_notify(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
status = BTA_GATTC_RegisterForNotifications(arg->gatt_if,
|
||||
arg->remote_bda, &in_char_id);
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.reg_for_notif.conn_id = arg->conn_id;
|
||||
param.reg_for_notif.status = status;
|
||||
param.reg_for_notif.registered = true;
|
||||
memcpy(¶m.reg_for_notif.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.reg_for_notif.char_id, &arg->service_uuid, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIF_EVT, ¶m);
|
||||
}
|
||||
|
||||
static void btc_gattc_unreg_for_notify(esp_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->service_uuid);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->char_uuid);
|
||||
|
||||
status = BTA_GATTC_DeregisterForNotifications(arg->gatt_if,
|
||||
arg->remote_bda, &in_char_id);
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
param.reg_for_notif.conn_id = arg->conn_id;
|
||||
param.reg_for_notif.status = status;
|
||||
param.reg_for_notif.registered = false;
|
||||
memcpy(¶m.reg_for_notif.srvc_id, &arg->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
memcpy(¶m.reg_for_notif.char_id, &arg->service_uuid, sizeof(esp_gatt_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_FOR_NOTIF_EVT, ¶m);
|
||||
}
|
||||
|
||||
void btc_gattc_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gattc_args_t *arg = (esp_ble_gattc_args_t *)(msg->arg);
|
||||
switch (msg->act) {
|
||||
case BTC_GATTC_ACT_APP_REGISTER:
|
||||
btc_gattc_app_register(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_APP_UNREGISTER:
|
||||
btc_gattc_app_unregister(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_OPEN:
|
||||
btc_gattc_open(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_CLOSE:
|
||||
btc_gattc_close(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_CFG_MTU:
|
||||
btc_gattc_cfg_mtu(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_SEARCH_SERVICE:
|
||||
btc_gattc_search_service(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_FIRST_CHAR:
|
||||
btc_gattc_get_first_char(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_NEXT_CHAR:
|
||||
btc_gattc_get_next_char(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_FIRST_DESCR:
|
||||
btc_gattc_get_first_descr(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_NEXT_DESCR:
|
||||
btc_gattc_get_next_descr(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE:
|
||||
btc_gattc_get_first_incl_service(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE:
|
||||
btc_gattc_get_next_incl_service(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_READ_CHAR:
|
||||
btc_gattc_read_char(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_READ_CHAR_DESCR:
|
||||
btc_gattc_read_char_descr(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_WRITE_CHAR:
|
||||
btc_gattc_write_char(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_WRITE_CHAR_DESCR:
|
||||
btc_gattc_write_char_descr(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_PREPARE_WRITE:
|
||||
btc_gattc_prepare_write(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_EXECUTE_WRITE:
|
||||
btc_gattc_execute_wrtie(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_REG_FOR_NOTIFY:
|
||||
btc_gattc_reg_for_notify(arg);
|
||||
break;
|
||||
case BTC_GATTC_ACT_UNREG_FOR_NOTIFY:
|
||||
btc_gattc_unreg_for_notify(arg);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, msg->act);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void btc_gattc_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
tBTA_GATTC *arg = (tBTA_GATTC *)(msg->arg);
|
||||
esp_ble_gattc_cb_param_t param;
|
||||
|
||||
memset(¶m, 0, sizeof(esp_ble_gattc_cb_param_t));
|
||||
|
||||
switch (msg->act) {
|
||||
case BTA_GATTC_REG_EVT: {
|
||||
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
|
||||
param.reg.status = reg_oper->status;
|
||||
param.reg.gatt_if = reg_oper->client_if;
|
||||
memcpy(¶m.reg.uuid, ®_oper->app_uuid, sizeof(esp_bt_uuid_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_DEREG_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_UNREG_EVT, NULL);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_READ_CHAR_EVT: {
|
||||
set_read_value(¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_CHAR_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_WRITE_CHAR_EVT:
|
||||
case BTA_GATTC_PREP_WRITE_EVT: {
|
||||
tBTA_GATTC_WRITE *write = &arg->write;
|
||||
uint32_t ret_evt = (msg->act == BTA_GATTC_WRITE_CHAR_EVT) ?
|
||||
ESP_GATTC_WRITE_CHAR_EVT : ESP_GATTC_PREP_WRITE_EVT;
|
||||
param.write.conn_id = write->conn_id;
|
||||
param.write.status = write->status;
|
||||
bta_to_btc_srvc_id(¶m.write.srvc_id, &write->srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.write.char_id, &write->char_id);
|
||||
BTC_GATTC_CB_TO_APP(ret_evt, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_EXEC_EVT: {
|
||||
tBTA_GATTC_EXEC_CMPL *exec_cmpl = &arg->exec_cmpl;
|
||||
param.exec_cmpl.conn_id = exec_cmpl->conn_id;
|
||||
param.exec_cmpl.status = exec_cmpl->status;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_EXEC_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_SEARCH_CMPL_EVT: {
|
||||
tBTA_GATTC_SEARCH_CMPL *search_cmpl = &arg->search_cmpl;
|
||||
param.search_cmpl.conn_id = search_cmpl->conn_id;
|
||||
param.search_cmpl.status = search_cmpl->status;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_CMPL_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_SEARCH_RES_EVT: {
|
||||
tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res;
|
||||
param.search_res.conn_id = srvc_res->conn_id;
|
||||
memcpy(¶m.search_res.service_uuid, &srvc_res->service_uuid, sizeof(esp_gatt_srvc_id_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_READ_DESCR_EVT: {
|
||||
set_read_value(¶m, &arg->read);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_READ_DESCR_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_WRITE_DESCR_EVT: {
|
||||
tBTA_GATTC_WRITE *write = &arg->write;
|
||||
param.write.conn_id = write->conn_id;
|
||||
param.write.status = write->status;
|
||||
bta_to_btc_srvc_id(¶m.write.srvc_id, &write->srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.write.char_id, &write->char_id);
|
||||
bta_to_btc_gatt_id(¶m.write.descr_id, &write->descr_type);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_WRITE_DESCR_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_NOTIF_EVT: {
|
||||
tBTA_GATTC_NOTIFY *notify = &arg->notify;
|
||||
param.notify.conn_id = notify->conn_id;
|
||||
memcpy(¶m.notify.bda, ¬ify->bda, sizeof(esp_bd_addr_t));
|
||||
bta_to_btc_srvc_id(¶m.notify.srvc_id, ¬ify->char_id.srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.notify.char_id, ¬ify->char_id.char_id);
|
||||
bta_to_btc_gatt_id(¶m.notify.descr_id, ¬ify->descr_type);
|
||||
param.notify.is_notify = (notify->is_notify == TRUE) ? true : false;
|
||||
param.notify.value_len = (notify->len > ESP_GATT_MAX_ATTR_LEN) ? \
|
||||
ESP_GATT_MAX_ATTR_LEN : notify->len;
|
||||
memcpy(¶m.notify.value, notify->value, param.notify.value_len);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_NOTIF_EVT, ¶m);
|
||||
|
||||
if (notify->is_notify == FALSE) {
|
||||
BTA_GATTC_SendIndConfirm(notify->conn_id, ¬ify->char_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_OPEN_EVT: {
|
||||
tBTA_GATTC_OPEN *open = &arg->open;
|
||||
param.open.status = open->status;
|
||||
param.open.conn_id = open->conn_id;
|
||||
param.open.gatt_if = open->client_if;
|
||||
memcpy(¶m.open.remote_bda, &open->remote_bda, sizeof(esp_bd_addr_t));
|
||||
param.open.mtu = open->mtu;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_OPEN_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CLOSE_EVT: {
|
||||
tBTA_GATTC_CLOSE *close = &arg->close;
|
||||
param.close.status = close->status;
|
||||
param.close.conn_id = close->conn_id;
|
||||
param.close.gatt_if = close->client_if;
|
||||
memcpy(¶m.close.remote_bda, &close->remote_bda, sizeof(esp_bd_addr_t));
|
||||
param.close.reason = close->reason;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CLOSE_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_CFG_MTU_EVT: {
|
||||
tBTA_GATTC_CFG_MTU *cfg_mtu = &arg->cfg_mtu;
|
||||
param.cfg_mtu.conn_id = cfg_mtu->conn_id;
|
||||
param.cfg_mtu.status = cfg_mtu->status;
|
||||
param.cfg_mtu.mtu = cfg_mtu->mtu;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CFG_MTU_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
||||
case BTA_GATTC_ACL_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_ACL_EVT, NULL);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CANCEL_OPEN_EVT: {
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CANCEL_OPEN_EVT, NULL);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_CONGEST_EVT: {
|
||||
tBTA_GATTC_CONGEST *congest = &arg->congest;
|
||||
param.congest.conn_id = congest->conn_id;
|
||||
param.congest.congested = (congest->congested == TRUE) ? true : false;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_CONGEST_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_SRVC_CHG_EVT: {
|
||||
memcpy(¶m.srvc_chg.remote_bda, &arg->remote_bda, sizeof(esp_bd_addr_t));
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SRVC_CHG_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_ERROR("%s: Unhandled event (%d)!", __FUNCTION__, msg->act);
|
||||
break;
|
||||
}
|
||||
|
||||
// free the deep-copied data
|
||||
btc_gattc_free_req_data(msg);
|
||||
}
|
379
components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c
Normal file
379
components/bt/bluedroid/btc/profile/std/gatt/btc_gatts.c
Normal file
@ -0,0 +1,379 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "bta_gatt_api.h"
|
||||
|
||||
#include "btc_task.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gatts.h"
|
||||
#include "btc_gatt_util.h"
|
||||
|
||||
#include "esp_gatts_api.h"
|
||||
|
||||
#define BTC_GATTS_CB_TO_APP(_event, _param) ((esp_profile_cb_t)btc_profile_cb_get(BTC_PID_GATTS))(_event, _param)
|
||||
|
||||
#define A2C_GATTS_EVT(_bta_event) (_bta_event) //BTA TO BTC EVT
|
||||
#define C2A_GATTS_EVT(_btc_event) (_btc_event) //BTC TO BTA EVT
|
||||
|
||||
static void btc_gatts_cb_param_copy_req(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
uint16_t event = msg->act;
|
||||
|
||||
tBTA_GATTS *p_dest_data = (tBTA_GATTS*) p_dest;
|
||||
tBTA_GATTS *p_src_data = (tBTA_GATTS*) p_src;
|
||||
|
||||
if (!p_src_data || !p_dest_data)
|
||||
return;
|
||||
|
||||
// Copy basic structure first
|
||||
memcpy(p_dest_data, p_src_data, sizeof(tBTA_GATTS));
|
||||
|
||||
// Allocate buffer for request data if necessary
|
||||
switch (event)
|
||||
{
|
||||
case BTA_GATTS_READ_EVT:
|
||||
case BTA_GATTS_WRITE_EVT:
|
||||
case BTA_GATTS_EXEC_WRITE_EVT:
|
||||
case BTA_GATTS_MTU_EVT:
|
||||
p_dest_data->req_data.p_data = GKI_getbuf(sizeof(tBTA_GATTS_REQ_DATA));
|
||||
if (p_dest_data->req_data.p_data != NULL)
|
||||
{
|
||||
memcpy(p_dest_data->req_data.p_data, p_src_data->req_data.p_data,
|
||||
sizeof(tBTA_GATTS_REQ_DATA));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_gatts_cb_param_copy_free(btc_msg_t *msg, tBTA_GATTS *p_data)
|
||||
{
|
||||
uint16_t event = msg->act;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case BTA_GATTS_READ_EVT:
|
||||
case BTA_GATTS_WRITE_EVT:
|
||||
case BTA_GATTS_EXEC_WRITE_EVT:
|
||||
case BTA_GATTS_MTU_EVT:
|
||||
if (p_data && p_data->req_data.p_data)
|
||||
GKI_freebuf(p_data->req_data.p_data);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void btc_gatts_inter_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
{
|
||||
bt_status_t status;
|
||||
btc_msg_t msg;
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = event;
|
||||
|
||||
status = btc_transfer_context(&msg, p_data,
|
||||
sizeof(tBTA_GATTS), btc_gatts_cb_param_copy_req);
|
||||
|
||||
if (status != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_gatts_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gatts_args_t *arg = (esp_ble_gatts_args_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_GATTS_ACT_APP_REGISTER: {
|
||||
tBT_UUID uuid;
|
||||
|
||||
uuid.len = LEN_UUID_16;
|
||||
uuid.uu.uuid16 = arg->app_uuid;
|
||||
|
||||
BTA_GATTS_AppRegister(&uuid, btc_gatts_inter_cb);
|
||||
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_APP_UNREGISTER:
|
||||
BTA_GATTS_AppDeregister(arg->gatt_if);
|
||||
break;
|
||||
case BTC_GATTS_ACT_CREATE_SERVICE: {
|
||||
tBTA_GATT_SRVC_ID srvc_id;
|
||||
btc_to_bta_srvc_id(&srvc_id, &arg->service_uuid);
|
||||
BTA_GATTS_CreateService(arg->gatt_if, &srvc_id.id.uuid,
|
||||
srvc_id.id.inst_id, arg->num_handle,
|
||||
srvc_id.is_primary);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_DELETE_SERVICE:
|
||||
BTA_GATTS_DeleteService(arg->service_handle);
|
||||
break;
|
||||
case BTC_GATTS_ACT_START_SERVICE:
|
||||
BTA_GATTS_StartService(arg->service_handle, GATT_TRANSPORT_LE);
|
||||
break;
|
||||
case BTC_GATTS_ACT_STOP_SERVICE:
|
||||
BTA_GATTS_StopService(arg->service_handle);
|
||||
break;
|
||||
case BTC_GATTS_ACT_ADD_INCLUDE_SERVICE:
|
||||
BTA_GATTS_AddIncludeService(arg->service_handle, arg->included_service_handle);
|
||||
break;
|
||||
case BTC_GATTS_ACT_ADD_CHAR: {
|
||||
tBT_UUID uuid;
|
||||
btc_to_bta_uuid(&uuid, &arg->uuid);
|
||||
|
||||
BTA_GATTS_AddCharacteristic(arg->service_handle, &uuid,
|
||||
arg->perm, arg->property);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_ADD_CHAR_DESCR: {
|
||||
tBT_UUID uuid;
|
||||
btc_to_bta_uuid(&uuid, &arg->uuid);
|
||||
BTA_GATTS_AddCharDescriptor(arg->service_handle, arg->perm, &uuid);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_SEND_INDICATE:
|
||||
BTA_GATTS_HandleValueIndication(arg->conn_id, arg->attr_handle,
|
||||
arg->data_len, arg->data, arg->need_confirm);
|
||||
break;
|
||||
case BTC_GATTS_ACT_SEND_RESPONSE: {
|
||||
esp_ble_gatts_cb_param_t param;
|
||||
tBTA_GATTS_RSP rsp_struct;
|
||||
esp_gatt_rsp_t *p_rsp = &arg->rsp;
|
||||
btc_to_bta_response(&rsp_struct, p_rsp);
|
||||
|
||||
BTA_GATTS_SendRsp(arg->conn_id, arg->trans_id,
|
||||
arg->status, &rsp_struct);
|
||||
|
||||
param.rsp.status = 0;
|
||||
param.rsp.handle = rsp_struct.attr_value.handle;
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_RESPONSE_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_OPEN: {
|
||||
// Ensure device is in inquiry database
|
||||
int addr_type = 0;
|
||||
int device_type = 0;
|
||||
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
|
||||
|
||||
//TODO : implement address type and device type
|
||||
#if 0
|
||||
if (_get_address_type(arg->remote_bda, &addr_type) &&
|
||||
btif_get_device_type(arg->remote_bda, &device_type) &&
|
||||
device_type != BT_DEVICE_TYPE_BREDR) {
|
||||
BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
|
||||
}
|
||||
#else
|
||||
//BTA_DmAddBleDevice(p_cb->bd_addr.address, addr_type, device_type);
|
||||
#endif
|
||||
// Mark background connections
|
||||
if (!arg->is_direct)
|
||||
BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL);
|
||||
|
||||
transport = BTA_GATT_TRANSPORT_LE;
|
||||
|
||||
// Connect!
|
||||
BTA_GATTS_Open(arg->gatt_if, arg->remote_bda,
|
||||
arg->is_direct, transport);
|
||||
break;
|
||||
}
|
||||
case BTC_GATTS_ACT_CLOSE:
|
||||
// TODO : implement cancel open
|
||||
// Cancel pending foreground/background connections
|
||||
//BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, TRUE);
|
||||
//BTA_GATTS_CancelOpen(p_cb->server_if, p_cb->bd_addr.address, FALSE);
|
||||
|
||||
// Close active connection
|
||||
if (arg->conn_id != 0)
|
||||
BTA_GATTS_Close(arg->conn_id);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void btc_gatts_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_gatts_cb_param_t param;
|
||||
|
||||
tBTA_GATTS *p_data = (tBTA_GATTS *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
case BTA_GATTS_REG_EVT: {
|
||||
param.reg.status = p_data->reg_oper.status;
|
||||
param.reg.gatt_if = p_data->reg_oper.server_if;
|
||||
param.reg.app_id = p_data->reg_oper.uuid.uu.uuid16;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_REG_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_DEREG_EVT:
|
||||
// do nothing
|
||||
break;
|
||||
case BTA_GATTS_READ_EVT: {
|
||||
param.read.conn_id = p_data->req_data.conn_id;
|
||||
param.read.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.read.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.read.handle = p_data->req_data.p_data->read_req.handle,
|
||||
param.read.offset = p_data->req_data.p_data->read_req.offset,
|
||||
param.read.is_long = p_data->req_data.p_data->read_req.is_long,
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_READ_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_WRITE_EVT: {
|
||||
param.write.conn_id = p_data->req_data.conn_id;
|
||||
param.write.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.write.handle = p_data->req_data.p_data->write_req.handle;
|
||||
param.write.offset = p_data->req_data.p_data->write_req.offset;
|
||||
param.write.need_rsp = p_data->req_data.p_data->write_req.need_rsp;
|
||||
param.write.is_prep = p_data->req_data.p_data->write_req.is_prep;
|
||||
param.write.len = p_data->req_data.p_data->write_req.len;
|
||||
memcpy(param.write.value, p_data->req_data.p_data->write_req.value, param.write.len);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_WRITE_EVT, ¶m);
|
||||
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_EXEC_WRITE_EVT: {
|
||||
param.exec_write.conn_id = p_data->req_data.conn_id;
|
||||
param.exec_write.trans_id = p_data->req_data.trans_id;
|
||||
memcpy(param.exec_write.bda, p_data->req_data.remote_bda, ESP_BD_ADDR_LEN);
|
||||
param.exec_write.exec_write_flag = p_data->req_data.p_data->exec_write;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_EXEC_WRITE_EVT, ¶m);
|
||||
|
||||
break;
|
||||
}
|
||||
case BTA_GATTS_MTU_EVT:
|
||||
param.mtu.conn_id = p_data->req_data.conn_id;
|
||||
param.mtu.mtu = p_data->req_data.p_data->mtu;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_MTU_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CONF_EVT:
|
||||
param.conf.conn_id = p_data->req_data.conn_id;
|
||||
param.conf.status = p_data->req_data.status;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONF_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CREATE_EVT:
|
||||
param.create.status = p_data->create.status;
|
||||
param.create.gatt_if = p_data->create.server_if;
|
||||
param.create.service_handle = p_data->create.service_id;
|
||||
param.create.service_id.is_primary = p_data->create.is_primary;
|
||||
param.create.service_id.id.inst_id = p_data->create.svc_instance;
|
||||
memcpy(¶m.create.service_id.id.uuid, &p_data->create.uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CREATE_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_INCL_SRVC_EVT:
|
||||
param.add_incl_srvc.status = p_data->add_result.status;
|
||||
param.add_incl_srvc.gatt_if = p_data->add_result.server_if;
|
||||
param.add_incl_srvc.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_incl_srvc.service_handle = p_data->add_result.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_INCL_SRVC_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_CHAR_EVT:
|
||||
param.add_char.status = p_data->add_result.status;
|
||||
param.add_char.gatt_if = p_data->add_result.server_if;
|
||||
param.add_char.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_char.service_handle = p_data->add_result.service_id;
|
||||
memcpy(¶m.add_char.char_uuid, &p_data->add_result.char_uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_ADD_CHAR_DESCR_EVT:
|
||||
param.add_char_descr.status = p_data->add_result.status;
|
||||
param.add_char_descr.gatt_if = p_data->add_result.server_if;
|
||||
param.add_char_descr.attr_handle = p_data->add_result.attr_id;
|
||||
param.add_char_descr.service_handle = p_data->add_result.service_id;
|
||||
memcpy(¶m.add_char_descr.char_uuid, &p_data->add_result.char_uuid, sizeof(esp_bt_uuid_t));
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_ADD_CHAR_DESCR_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_DELELTE_EVT:
|
||||
param.del.status = p_data->srvc_oper.status;
|
||||
param.del.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.del.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELELTE_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_START_EVT:
|
||||
param.start.status = p_data->srvc_oper.status;
|
||||
param.start.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.start.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_START_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_STOP_EVT:
|
||||
param.stop.status = p_data->srvc_oper.status;
|
||||
param.stop.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.stop.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_STOP_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_CONNECT_EVT:
|
||||
param.connect.conn_id = p_data->conn.conn_id;
|
||||
param.connect.gatt_if = p_data->conn.server_if;
|
||||
param.connect.is_connected = true;
|
||||
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_CONNECT_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_DISCONNECT_EVT:
|
||||
param.connect.conn_id = p_data->conn.conn_id;
|
||||
param.connect.gatt_if = p_data->conn.server_if;
|
||||
param.connect.is_connected = false;
|
||||
memcpy(param.connect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DISCONNECT_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_OPEN_EVT:
|
||||
// do nothing
|
||||
case BTA_GATTS_CANCEL_OPEN_EVT:
|
||||
// do nothing
|
||||
case BTA_GATTS_CLOSE_EVT:
|
||||
// do nothing
|
||||
case BTA_GATTS_LISTEN_EVT:
|
||||
// do nothing
|
||||
break;
|
||||
case BTA_GATTS_CONGEST_EVT:
|
||||
param.congest.conn_id = p_data->congest.conn_id;
|
||||
param.congest.congested = p_data->congest.congested;
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
btc_gatts_cb_param_copy_free(msg, p_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
#ifndef __BTC_GATT_UTIL_H__
|
||||
#define __BTC_GATT_UTIL_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_gatt_defs.h"
|
||||
#include "esp_gattc_api.h"
|
||||
|
||||
void btc_to_bta_uuid(tBT_UUID *p_dest, esp_bt_uuid_t *p_src);
|
||||
void btc_to_bta_gatt_id(tBTA_GATT_ID *p_dest, esp_gatt_id_t *p_src);
|
||||
void btc_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, esp_gatt_srvc_id_t *p_src);
|
||||
void btc_to_bta_response(tBTA_GATTS_RSP *rsp_struct, esp_gatt_rsp_t *p_rsp);
|
||||
|
||||
void bta_to_btc_uuid(esp_bt_uuid_t *p_dest, tBT_UUID *p_src);
|
||||
void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src);
|
||||
void bta_to_btc_srvc_id(esp_gatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src);
|
||||
|
||||
uint16_t set_read_value(esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src);
|
||||
|
||||
#endif /* __BTC_GATT_UTIL_H__*/
|
@ -0,0 +1,21 @@
|
||||
#ifndef __BTC_GAP_BLE_H__
|
||||
#define __BTC_GAP_BLE_H__
|
||||
|
||||
typedef enum {
|
||||
BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0,
|
||||
BTC_GAP_BLE_ACT_SET_SCAN_PARAM,
|
||||
BTC_GAP_BLE_ACT_START_SCAN,
|
||||
BTC_GAP_BLE_ACT_STOP_SCAN,
|
||||
BTC_GAP_BLE_ACT_START_ADV,
|
||||
BTC_GAP_BLE_ACT_STOP_ADV,
|
||||
BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM,
|
||||
BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN,
|
||||
BTC_GAP_BLE_ACT_SET_RAND_ADDRESS,
|
||||
BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY,
|
||||
BTC_GAP_BLE_ACT_SET_DEV_NAME,
|
||||
} btc_gap_ble_act_t;
|
||||
|
||||
void btc_gap_ble_call_handler(btc_msg_t *msg);
|
||||
void btc_gap_ble_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* __BTC_GAP_BLE_H__ */
|
@ -0,0 +1,8 @@
|
||||
#ifndef __BTC_GAP_BT_H__
|
||||
#define __BTC_GAP_BT_H__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define /* __BTC_GAP_BT_H__ */
|
@ -0,0 +1,32 @@
|
||||
#ifndef __BTC_GATTC_H__
|
||||
#define __BTC_GATTC_H__
|
||||
|
||||
#include "btc_task.h"
|
||||
|
||||
typedef enum {
|
||||
BTC_GATTC_ACT_APP_REGISTER,
|
||||
BTC_GATTC_ACT_APP_UNREGISTER,
|
||||
BTC_GATTC_ACT_OPEN,
|
||||
BTC_GATTC_ACT_CLOSE,
|
||||
BTC_GATTC_ACT_CFG_MTU,
|
||||
BTC_GATTC_ACT_SEARCH_SERVICE,
|
||||
BTC_GATTC_ACT_GET_FIRST_CHAR,
|
||||
BTC_GATTC_ACT_GET_NEXT_CHAR,
|
||||
BTC_GATTC_ACT_GET_FIRST_DESCR,
|
||||
BTC_GATTC_ACT_GET_NEXT_DESCR,
|
||||
BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE,
|
||||
BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE,
|
||||
BTC_GATTC_ACT_READ_CHAR,
|
||||
BTC_GATTC_ACT_READ_CHAR_DESCR,
|
||||
BTC_GATTC_ACT_WRITE_CHAR,
|
||||
BTC_GATTC_ACT_WRITE_CHAR_DESCR,
|
||||
BTC_GATTC_ACT_PREPARE_WRITE,
|
||||
BTC_GATTC_ACT_EXECUTE_WRITE,
|
||||
BTC_GATTC_ACT_REG_FOR_NOTIFY,
|
||||
BTC_GATTC_ACT_UNREG_FOR_NOTIFY
|
||||
} btc_gattc_act_t;
|
||||
|
||||
void btc_gattc_call_handler(btc_msg_t *msg);
|
||||
void btc_gattc_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* __BTC_GATTC_H__ */
|
@ -0,0 +1,26 @@
|
||||
#ifndef __BTC_GATTS_H__
|
||||
#define __BTC_GATTS_H__
|
||||
#include "btc_task.h"
|
||||
|
||||
typedef enum {
|
||||
BTC_GATTS_ACT_APP_REGISTER = 0,
|
||||
BTC_GATTS_ACT_APP_UNREGISTER,
|
||||
BTC_GATTS_ACT_CREATE_SERVICE,
|
||||
BTC_GATTS_ACT_DELETE_SERVICE,
|
||||
BTC_GATTS_ACT_START_SERVICE,
|
||||
BTC_GATTS_ACT_STOP_SERVICE,
|
||||
BTC_GATTS_ACT_ADD_INCLUDE_SERVICE,
|
||||
BTC_GATTS_ACT_ADD_CHAR,
|
||||
BTC_GATTS_ACT_ADD_CHAR_DESCR,
|
||||
BTC_GATTS_ACT_SEND_INDICATE,
|
||||
BTC_GATTS_ACT_SEND_RESPONSE,
|
||||
BTC_GATTS_ACT_OPEN,
|
||||
BTC_GATTS_ACT_CLOSE,
|
||||
} btc_gatts_act_t;
|
||||
|
||||
|
||||
|
||||
void btc_gatts_call_handler(btc_msg_t *msg);
|
||||
void btc_gatts_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* __BTC_GATTS_H__ */
|
125
components/bt/bluedroid/btc/profile/std/sdp/btc_sdp.c
Normal file
125
components/bt/bluedroid/btc/profile/std/sdp/btc_sdp.c
Normal file
@ -0,0 +1,125 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_sdp_api.h"
|
||||
|
||||
|
||||
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpEnable((tBTA_SDP_DM_CBACK *)cback);
|
||||
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpSearch(bd_addr, (tSDP_UUID *)uuid);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpCreateRecordByUser(user_data);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpRemoveRecordByUser(user_data);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
||||
/* API into SDP for local service database updates */
|
||||
/* these APIs are indended to be called in callback function in the context of stack task,
|
||||
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
|
||||
*/
|
||||
uint32_t esp_bt_sdp_create_record(void)
|
||||
{
|
||||
return SDP_CreateRecord();
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_delete_record(uint32_t handle)
|
||||
{
|
||||
return SDP_DeleteRecord(handle);
|
||||
}
|
||||
|
||||
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len)
|
||||
{
|
||||
return SDP_ReadRecord(handle, data, data_len);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
|
||||
uint8_t attr_type, uint32_t attr_len,
|
||||
uint8_t *p_val)
|
||||
{
|
||||
return SDP_AddAttribute(handle, attr_id, attr_type, attr_len, p_val);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_elem, uint8_t type[],
|
||||
uint8_t len[], uint8_t *p_val[])
|
||||
{
|
||||
return SDP_AddSequence(handle, attr_id, num_elem, type, len, p_val);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_uuids, uint16_t *p_uuids)
|
||||
{
|
||||
return SDP_AddUuidSequence(handle, attr_id, num_uuids, p_uuids);
|
||||
}
|
||||
|
||||
|
||||
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_elem_t *p_elem_list)
|
||||
{
|
||||
return SDP_AddProtocolList(handle, num_elem, (tSDP_PROTOCOL_ELEM *)p_elem_list);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_list_elem_t *p_proto_list)
|
||||
{
|
||||
return SDP_AddAdditionProtoLists(handle, num_elem, (tSDP_PROTO_LIST_ELEM *)p_proto_list);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
|
||||
uint16_t profile_uuid,
|
||||
uint16_t version)
|
||||
{
|
||||
return SDP_AddProfileDescriptorList(handle, profile_uuid, version);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
|
||||
uint16_t lang, uint16_t char_enc,
|
||||
uint16_t base_id)
|
||||
{
|
||||
return SDP_AddLanguageBaseAttrIDList(handle, lang, char_enc, base_id);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
|
||||
uint16_t num_services,
|
||||
uint16_t *p_service_uuids)
|
||||
{
|
||||
return SDP_AddServiceClassIdList(handle, num_services, p_service_uuids);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id)
|
||||
{
|
||||
return SDP_DeleteAttribute(handle, attr_id);
|
||||
}
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
117
components/bt/bluedroid/btc/profile/std/sdp/include/btc_sdp.h
Normal file
117
components/bt/bluedroid/btc/profile/std/sdp/include/btc_sdp.h
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef __ESP_SDP_API_H__
|
||||
#define __ESP_SDP_API_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_common.h"
|
||||
#include "bta_sdp_api.h"
|
||||
#include "bt_sdp.h"
|
||||
|
||||
#define BT_SDP_STAT_SUCCESS BTA_SDP_SUCCESS
|
||||
#define BT_SDP_STAT_FAILURE BTA_SDP_FAILURE
|
||||
#define BT_SDP_STAT_BUSY BTA_SDP_BUSY
|
||||
|
||||
#define BT_SDP_ENABLE_EVT BTA_SDP_ENABLE_EVT
|
||||
#define BT_SDP_SEARCH_EVT BTA_SDP_SEARCH_EVT
|
||||
#define BT_SDP_SEARCH_COMP_EVT BTA_SDP_SEARCH_COMP_EVT
|
||||
#define BT_SDP_CREATE_RECORD_USER_EVT BTA_SDP_CREATE_RECORD_USER_EVT
|
||||
#define BT_SDP_REMOVE_RECORD_USER_EVT BTA_SDP_REMOVE_RECORD_USER_EVT
|
||||
#define BT_SDP_MAX_EVT BTA_SDP_MAX_EVT
|
||||
|
||||
#define BT_SDP_MAX_RECORDS BTA_SDP_MAX_RECORDS
|
||||
|
||||
typedef tBTA_SDP_STATUS bt_sdp_status_t;
|
||||
|
||||
typedef tBTA_SDP_EVT bt_sdp_evt_t;
|
||||
|
||||
typedef bluetooth_sdp_record bt_sdp_record_t;
|
||||
|
||||
/* tBTA_SEARCH_COMP, bta_sdp_api.h */
|
||||
typedef struct {
|
||||
bt_sdp_status_t status;
|
||||
esp_bd_addr_t remote_addr;
|
||||
esp_bt_uuid_t uuid;
|
||||
int record_count;
|
||||
bt_sdp_record_t records[BT_SDP_MAX_RECORDS];
|
||||
} bt_sdp_search_comp_t;
|
||||
|
||||
/* tBTA_SDP, bta_sdp_api.h */
|
||||
typedef union
|
||||
{
|
||||
bt_sdp_status_t status;
|
||||
bt_sdp_search_comp_t sdp_search_comp;
|
||||
} bt_sdp_t;
|
||||
|
||||
typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data);
|
||||
|
||||
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback);
|
||||
|
||||
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid);
|
||||
|
||||
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data);
|
||||
|
||||
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data);
|
||||
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
||||
/* API into SDP for local service database updates
|
||||
* these APIs are indended to be called in callback function in the context of stack task,
|
||||
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
|
||||
*/
|
||||
|
||||
/* This structure is used to add protocol lists and find protocol elements */
|
||||
#define ESP_BT_SDP_MAX_PROTOCOL_PARAMS SDP_MAX_PROTOCOL_PARAMS // bt_target.h
|
||||
typedef struct {
|
||||
uint16_t protocol_uuid;
|
||||
uint16_t num_params;
|
||||
uint16_t params[ESP_BT_SDP_MAX_PROTOCOL_PARAMS];
|
||||
} sdp_proto_elem_t; // tSDP_PROTOCOL_ELEM, sdp_api.h
|
||||
|
||||
#define ESP_BT_SDP_MAX_LIST_ELEMS SDP_MAX_LIST_ELEMS // sdp_api.h
|
||||
typedef struct
|
||||
{
|
||||
uint16_t num_elems;
|
||||
sdp_proto_elem_t list_elem[ESP_BT_SDP_MAX_LIST_ELEMS];
|
||||
} sdp_proto_list_elem_t; // tSDP_PROTO_LIST_ELEM, sdp_api.h
|
||||
|
||||
|
||||
uint32_t esp_bt_sdp_create_record(void);
|
||||
|
||||
bool esp_bt_sdp_delete_record(uint32_t handle);
|
||||
|
||||
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len);
|
||||
|
||||
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
|
||||
uint8_t attr_type, uint32_t attr_len,
|
||||
uint8_t *p_val);
|
||||
|
||||
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_elem, uint8_t type[],
|
||||
uint8_t len[], uint8_t *p_val[]);
|
||||
|
||||
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_uuids, uint16_t *p_uuids);
|
||||
|
||||
|
||||
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_elem_t *p_elem_list);
|
||||
|
||||
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_list_elem_t *p_proto_list);
|
||||
|
||||
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
|
||||
uint16_t profile_uuid,
|
||||
uint16_t version);
|
||||
|
||||
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
|
||||
uint16_t lang, uint16_t char_enc,
|
||||
uint16_t base_id);
|
||||
|
||||
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
|
||||
uint16_t num_services,
|
||||
uint16_t *p_service_uuids);
|
||||
|
||||
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id);
|
||||
|
||||
#endif /* __ESP_SDP_API_H__ */
|
108
components/bt/bluedroid/btc/profile/std/smp/esp_app_sec.c
Normal file
108
components/bt/bluedroid/btc/profile/std/smp/esp_app_sec.c
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdlib.h> // standard library
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_sec_api.h"
|
||||
|
||||
|
||||
extern void srand (unsigned int seed);
|
||||
extern int random (void);
|
||||
|
||||
/// Application Security Environment Structure
|
||||
tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_tk
|
||||
**
|
||||
** Description This function is called to generate the ble tk
|
||||
**
|
||||
** Returns the generate tk value
|
||||
**
|
||||
*******************************************************************************/
|
||||
UINT32 app_ble_sec_gen_tk(void)
|
||||
{
|
||||
// Generate a PIN Code (Between 100000 and 999999)
|
||||
return (100000 + (random()%900000));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_ltk
|
||||
**
|
||||
** Description This function is called to generate the ble ltk
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size)
|
||||
{
|
||||
// Counter
|
||||
UINT8 i;
|
||||
app_sec_env.key_size = key_size;
|
||||
|
||||
// Randomly generate the LTK and the Random Number
|
||||
for (i = 0; i < RAND_NB_LEN; i++)
|
||||
{
|
||||
app_sec_env.rand_nb.nb[i] = random()%256;
|
||||
}
|
||||
|
||||
// Randomly generate the end of the LTK
|
||||
for (i = 0; i < SEC_KEY_LEN; i++)
|
||||
{
|
||||
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256);
|
||||
}
|
||||
|
||||
// Randomly generate the EDIV
|
||||
app_sec_env.ediv = random()%65536;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_init
|
||||
**
|
||||
** Description This function is init the security env and function
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_init()
|
||||
{
|
||||
// Reset Security Environment
|
||||
memset(&app_sec_env, 0, sizeof(app_sec_env));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_security_start
|
||||
**
|
||||
** Description This function is called by the slave when the seurity start
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_security_start(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
#ifndef __ESP_SEC_API_H__
|
||||
#define __ESP_SEC_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
|
||||
#define APP_SEC_IRK_FLAG (0)
|
||||
#define RAND_NB_LEN 0x08
|
||||
#define SEC_KEY_LEN 0x10
|
||||
|
||||
/*
|
||||
* STRUCTURES DEFINITIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/// Generic Security key structure
|
||||
typedef struct
|
||||
{
|
||||
/// Key value MSB -> LSB
|
||||
UINT8 key[SEC_KEY_LEN];
|
||||
}smp_sec_key;
|
||||
|
||||
///Random number structure
|
||||
typedef struct
|
||||
{
|
||||
///8-byte array for random number
|
||||
UINT8 nb[RAND_NB_LEN];
|
||||
}rand_nb;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LTK
|
||||
smp_sec_key ltk;
|
||||
// Random Number
|
||||
rand_nb rand_nb;
|
||||
// EDIV
|
||||
UINT16 ediv;
|
||||
// LTK key size
|
||||
UINT8 key_size;
|
||||
|
||||
// Last paired peer address type
|
||||
UINT8 peer_addr_type;
|
||||
// Last paired peer address
|
||||
BD_ADDR peer_addr;
|
||||
|
||||
// authentication level
|
||||
UINT8 auth;
|
||||
|
||||
}tAPP_SEC_ENV;
|
||||
|
||||
extern tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
/*
|
||||
* GLOBAL FUNCTIONS DECLARATIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
void app_ble_sec_init(void);
|
||||
|
||||
void app_ble_sec_pairing_cmp_evt_send(UINT8);
|
||||
|
||||
UINT32 app_ble_sec_gen_tk(void);
|
||||
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size);
|
||||
|
||||
void app_ble_security_start(void);
|
||||
|
||||
#endif /* __ESP_SEC_API_H__ */
|
@ -74,7 +74,6 @@ typedef enum {
|
||||
BT_STATUS_AUTH_FAILURE,
|
||||
BT_STATUS_RMT_DEV_DOWN,
|
||||
BT_STATUS_AUTH_REJECTED
|
||||
|
||||
} bt_status_t;
|
||||
|
||||
#ifndef CPU_LITTLE_ENDIAN
|
||||
|
@ -1,155 +0,0 @@
|
||||
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "thread.h"
|
||||
#include "bt_prf_sys.h"
|
||||
#include "fixed_queue.h"
|
||||
#include "bt_prf_task.h"
|
||||
#include "gki.h"
|
||||
#include "bt_trace.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
tBT_PRF_SYS_CB bt_prf_sys_cb;
|
||||
fixed_queue_t *bt_profile_msg_queue;
|
||||
|
||||
|
||||
static const tBT_PRF_SYS_REG bt_prf_sys_reg =
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
void bt_prf_sys_init(void)
|
||||
{
|
||||
LOG_ERROR("bt_prf_sys_init\n");
|
||||
memset(&bt_prf_sys_cb, 0, sizeof(tBT_PRF_SYS_CB));
|
||||
bt_prf_StartUp();
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bt_prf_sys_event
|
||||
**
|
||||
** Description profile task event handler; called from task event handler.
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bt_prf_sys_event(prf_hdr_evt_t *p_msg)
|
||||
{
|
||||
UINT8 id;
|
||||
BOOLEAN freebuf = TRUE;
|
||||
|
||||
LOG_ERROR("profile task got event 0x%x\n", p_msg->event);
|
||||
|
||||
/* get subsystem id from event */
|
||||
id = (UINT8) (p_msg->event >> 8);
|
||||
|
||||
/* verify id and call subsystem event handler */
|
||||
if ((id < PRF_ID_MAX) && (bt_prf_sys_cb.reg[id] != NULL))
|
||||
{
|
||||
freebuf = (*bt_prf_sys_cb.reg[id]->evt_hdlr)(p_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("profile task got unregistered event id %d\n", id);
|
||||
}
|
||||
|
||||
if (freebuf)
|
||||
{
|
||||
GKI_freebuf(p_msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bt_prf_sys_register
|
||||
**
|
||||
** Description Called by other profile subsystems to register their event
|
||||
** handler.
|
||||
**
|
||||
** Parameters id:the Identifiers index of the profile
|
||||
** p_reg:the callback event which has been register to the profile task
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bt_prf_sys_register(UINT8 id, const tBT_PRF_SYS_REG *p_reg)
|
||||
{
|
||||
bt_prf_sys_cb.reg[id] = (tBT_PRF_SYS_REG *) p_reg;
|
||||
bt_prf_sys_cb.is_reg[id] = TRUE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bt_prf_sys_deregister
|
||||
**
|
||||
** Description Called by other profile subsystems to de-register
|
||||
** handler.
|
||||
**
|
||||
** Parameters id:Identifiers index of the profile
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bt_prf_sys_deregister(UINT8 id)
|
||||
{
|
||||
bt_prf_sys_cb.reg[id] = NULL;
|
||||
bt_prf_sys_cb.is_reg[id] = FALSE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bt_prf_sys_is_register
|
||||
**
|
||||
** Description Called by other profile subsystems to get registeration
|
||||
** status.
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
BOOLEAN bt_prf_sys_is_register(UINT8 id)
|
||||
{
|
||||
return bt_prf_sys_cb.is_reg[id];
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bt_prf_sys_sendmsg
|
||||
**
|
||||
** Description Send a message to the profile task.
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
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 |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);
|
||||
|
||||
bt_prf_task_post(SIG_PRF_WORK);
|
||||
}
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "bt_prf_task.h"
|
||||
#include "bt_prf_sys.h"
|
||||
#include "allocator.h"
|
||||
#include "bt_trace.h"
|
||||
#include "thread.h"
|
||||
#include "gki.h"
|
||||
|
||||
//thread_t *bt_workqueue_thread;
|
||||
//static const char *BT_WORKQUEUE_NAME = "bt_workqueue";
|
||||
xTaskHandle xProfileTaskHandle = NULL;
|
||||
xQueueHandle xProfileQueue = 0;
|
||||
|
||||
// Communication queue between bt_proflie_task and app.
|
||||
extern fixed_queue_t *bt_profile_msg_queue;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
**
|
||||
** Function bt_prf_task_thread_handler
|
||||
**
|
||||
** Description Process profile Task Thread.
|
||||
******************************************************************************/
|
||||
void bt_prf_task_thread_handler(void *arg)
|
||||
{
|
||||
BtTaskEvt_t e;
|
||||
|
||||
for (;;) {
|
||||
if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) {
|
||||
|
||||
if (e.sig == SIG_PRF_WORK) {
|
||||
fixed_queue_process(bt_profile_msg_queue);
|
||||
LOG_ERROR("bt_prf_task_thread_handler\n");
|
||||
}
|
||||
else if (e.sig == SIG_PRF_START_UP) {
|
||||
bt_prf_task_start_up();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bt_prf_task_post(uint32_t sig)
|
||||
{
|
||||
BtTaskEvt_t evt;
|
||||
|
||||
evt.sig = sig;
|
||||
evt.par = 0;
|
||||
|
||||
if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
||||
ets_printf("xProfileQueue failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
void bt_profile_msg_ready(fixed_queue_t *queue) {
|
||||
prf_hdr_evt_t *p_msg;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_msg = (prf_hdr_evt_t *)fixed_queue_dequeue(queue);
|
||||
if(p_msg != NULL)
|
||||
{
|
||||
bt_prf_sys_event(p_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void bt_prf_task_shut_down(void)
|
||||
{
|
||||
fixed_queue_unregister_dequeue(bt_profile_msg_queue);
|
||||
|
||||
bt_prf_free_core();
|
||||
}
|
||||
|
||||
|
||||
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(BtTaskEvt_t));
|
||||
xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle);
|
||||
bt_prf_task_post(SIG_PRF_START_UP);
|
||||
return;
|
||||
|
||||
error_exit:
|
||||
LOG_ERROR("%s Unable to allocate resources for bt_workqueue\n", __func__);
|
||||
bt_prf_ShutDown();
|
||||
|
||||
}
|
||||
|
||||
void bt_prf_ShutDown(void)
|
||||
{
|
||||
|
||||
bt_prf_task_shut_down();
|
||||
|
||||
//thread_free(bt_workqueue_thread);
|
||||
vTaskDelete(xProfileTaskHandle);
|
||||
vQueueDelete(xProfileQueue);
|
||||
|
||||
bt_profile_msg_queue = NULL;
|
||||
|
||||
// bt_workqueue_thread = NULL;
|
||||
xProfileTaskHandle = NULL;
|
||||
xProfileQueue = 0;
|
||||
}
|
||||
|
||||
|
||||
void bt_prf_free_core(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,134 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
enum
|
||||
{
|
||||
API_BLE_DEVICE_READY_IND,
|
||||
API_BLE_DM_CMP_EVT,
|
||||
API_BLE_CONN_CMP_EVT,
|
||||
API_BLE_CONN_REQ_IND,
|
||||
API_BLE_DISCONN_IND,
|
||||
API_BLE_MODULE_INIT_CMP_EVT,
|
||||
API_BLE_ADV_REPORT_IND,
|
||||
|
||||
#if (BLE_SEC)
|
||||
API_BLE_BOND_REQ_IND,
|
||||
API_BLE_BOND_REQ_IND,
|
||||
API_BLE_ENCRYPT_REQ_IND,
|
||||
API_BLE_ENCRYPT_IND,
|
||||
#endif ///BLE_SEC
|
||||
|
||||
#if (BLE_DISS_SERVER)
|
||||
API_BLE_CREATE_DB_CFM,
|
||||
API_BLE_DISABLE_IND,
|
||||
#endif ///BLE_DISS_SERVER
|
||||
|
||||
#if (BLE_PROX_REPORTER)
|
||||
API_BLE_PROXR_ALERT_IND,
|
||||
API_BLE_PXP_TIMER,
|
||||
API_BLE_PROXR_CREATE_DB_CFM,
|
||||
API_BLE_PROXR_DISABLE_IND,
|
||||
#endif ///BLE_PROX_REPORTER
|
||||
|
||||
#if (BLE_BUT_SERVER)
|
||||
API_BLE_BUT_VAL_RECEIVCE,
|
||||
API_BLE_CREATE_DB_CFM,
|
||||
API_BLE_VAL_SEND_CFM,
|
||||
#endif ///BLE_BUT_SERVER
|
||||
|
||||
#if (BLE_APP_KEYBOARD)
|
||||
API_BLE_HIDD_CREATE_DB_CFM,
|
||||
API_BLE_DISABLE_IND,
|
||||
API_BLE_NTF_SENT_CFM,
|
||||
API_BLE_HIDD_TIMER,
|
||||
API_BLE_GREEN_LED_TIMER,
|
||||
API_BLE_RED_LED_TIMER,
|
||||
#ifndef MITM_ON
|
||||
API_BLE_HIDD_ENC_TIMER,
|
||||
#endif ///MITM_ON
|
||||
API_BLE_UPDATED_PRIVACY_IND,
|
||||
API_BLE_UPDATED_RECON_ADDR_IND,
|
||||
API_BLE_HID_MSG,
|
||||
#endif ///BLE_APP_KEYBOARD
|
||||
|
||||
#if (BLE_BATT_SERVER)
|
||||
API_BLE_BATT_CREATE_DB_CFM,
|
||||
API_BLE_BATT_LEVEL_UPD_CFM,
|
||||
API_BLE_BATT_LEVEL_NTF_CFG_IND,
|
||||
API_BLE_BATT_TIMER,
|
||||
APP_BLE_ALERT_TIMER,
|
||||
#endif ///BLE_BATT_SERVER
|
||||
|
||||
#if (BLE_FINDME_TARGET)
|
||||
API_BLE_FINDT_ALERT_IND,
|
||||
#endif ///BLE_FINDME_TARGET
|
||||
|
||||
#if (BLE_FINDME_LOCATOR)
|
||||
API_BLE_FINDL_ENABLE_CFM,
|
||||
#endif ///BLE_FINDME_LOCATOR
|
||||
|
||||
#if (HAS_MULTI_BOND)
|
||||
API_BLE_PAIR_TIMER,
|
||||
#endif ///HAS_MULTI_BOND
|
||||
|
||||
#if (BLE_SPOTA_RECEIVER)
|
||||
API_BLE_SPOTAR_PATCH_MEM_DEV_IND,
|
||||
API_BLE_SPOTAR_GPIO_MAP_IND,
|
||||
API_BLE_SPOTAR_PATCH_LEN_IND,
|
||||
API_BLE_SPOTAR_PATCH_DATA_IND,
|
||||
API_BLE_SPOTAR_CREATE_DB_CFM,
|
||||
#endif ///BLE_SPOTA_RECEIVER
|
||||
|
||||
#if (BLE_APP_SMARTTAG)
|
||||
API_BLE_ADV_TIMER,
|
||||
API_BLE_ADV_BLINK_TIMER,
|
||||
API_BLE_WAKEUP_MSG,
|
||||
#endif ///BLE_APP_SMARTTAG
|
||||
|
||||
#if (BLE_APP_PROXR)
|
||||
API_BLE_ADV_TIMER,
|
||||
API_BLE_WAKEUP_MSG,
|
||||
#endif ///BLE_APP_PROXR
|
||||
|
||||
#if (BLE_INTEGRATED_HOST_GTL_CENTRAL)
|
||||
API_BLE_EXT_TEST_REQ,
|
||||
API_BLE_EXT_SCAN_CMD,
|
||||
API_BLE_EXT_CONNECT_CMD,
|
||||
API_BLE_EXT_DISCONNECT_CMD,
|
||||
API_BLE_EXT_TRANSMIT_CMD,
|
||||
#endif ///BLE_INTEGRATED_HOST_GTL
|
||||
|
||||
#if (BLE_APP_THROUGHPUT_PERIPHERAL)
|
||||
API_BLE_EXT_TEST_REQ,
|
||||
API_BLE_EXT_DISCONNECT_CMD,
|
||||
API_BLE_EXT_TRANSMIT_CMD,
|
||||
#endif ///BLE_APP_THROUGHPUT_PERIPHERAL
|
||||
|
||||
#if (BLE_STREAMDATA_HOST)
|
||||
API_BLE_STREAMDATAH_ENABLE_CFM,
|
||||
API_BLE_STREAMDATAH_RCV_DATA_PACKET_IND,
|
||||
#endif ///BLE_STREAMDATA_HOST
|
||||
|
||||
#if (BLE_STREAMDATA_DEVICE)
|
||||
API_BLE_STREAMDATAD_CREATE_DB_CFM,
|
||||
API_BLE_STREAMDATAD_RCV_DATA_PACKET_IND,
|
||||
#endif ///BLE_STREAMDATA_DEVICE
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,90 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _PROFILE_SYS_H__
|
||||
#define _PROFILE_SYS_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "prf_defs.h"
|
||||
|
||||
enum
|
||||
{
|
||||
PRF_ID_SYS,
|
||||
PRF_ID_CONN,
|
||||
PRF_ID_HIDD_LE,
|
||||
PRF_ID_HIDH_LE,
|
||||
PRF_ID_DISS_LE,
|
||||
PRF_ID_DISC_LE,
|
||||
PRF_ID_AIRSYNC_LE,
|
||||
PRF_ID_ANCC_LE,
|
||||
PRF_ID_BUT_LE,
|
||||
|
||||
PRF_ID_MAX
|
||||
};
|
||||
|
||||
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)(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,
|
||||
UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
|
||||
|
||||
/* Calculate start of event enumeration; id is top 8 bits of event */
|
||||
#define BT_PRF_SYS_EVT_START(id) ((id) << 8)
|
||||
|
||||
|
||||
|
||||
/* registration structure */
|
||||
typedef struct
|
||||
{
|
||||
tBT_PRF_SYS_EVT_HDLR *evt_hdlr;
|
||||
tBT_PRF_SYS_DISABLE *disable;
|
||||
} tBT_PRF_SYS_REG;
|
||||
|
||||
/* system manager control block */
|
||||
typedef struct
|
||||
{
|
||||
tBT_PRF_SYS_REG *reg[PRF_ID_MAX]; /* registration structures */
|
||||
BOOLEAN is_reg[PRF_ID_MAX]; /* registration structures */
|
||||
tBT_PRF_SYS_CONN_CBACK *prm_cb; /* role management callback registered by DM */
|
||||
tBT_PRF_SYS_CONN_CBACK *ppm_cb; /* low power management callback registered by DM */
|
||||
tBT_PRF_SYS_CONN_CBACK *p_policy_cb; /* link policy change callback registered by DM */
|
||||
|
||||
} tBT_PRF_SYS_CB;
|
||||
|
||||
|
||||
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(prf_hdr_evt_t *p_msg);
|
||||
|
||||
extern void bt_prf_sys_sendmsg(void *p_msg);
|
||||
|
||||
|
||||
extern void bt_prf_sys_register(uint8_t id, const tBT_PRF_SYS_REG *p_reg);
|
||||
extern void bt_prf_sys_deregister(uint8_t id);
|
||||
extern BOOLEAN bt_prf_sys_is_register(uint8_t id);
|
||||
|
||||
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__
|
@ -1,50 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
#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
|
||||
************************************
|
||||
*/
|
||||
|
||||
|
||||
void bt_prf_task_thread_handler(void *arg);
|
||||
|
||||
void bt_prf_init_core(void);
|
||||
void bt_prf_free_core(void);
|
||||
|
||||
void bt_prf_task_post(uint32_t sig);
|
||||
|
||||
|
||||
void bt_prf_StartUp(void);
|
||||
void bt_prf_ShutDown(void);
|
||||
|
||||
void bt_prf_task_start_up(void);
|
||||
void bt_prf_task_shut_down(void);
|
||||
|
||||
void bt_profile_msg_ready(fixed_queue_t *queue);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /// BT_PRF_TASK_H__
|
@ -1,56 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "blufi_adv.h"
|
||||
#include "esp_adv_api.h"
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BlufiConfigadvData
|
||||
**
|
||||
** Description This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** p_adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BlufiBleConfigadvData(esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback)
|
||||
{
|
||||
esp_ble_config_adv_data(adv_data, p_adv_data_cback);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BLUFI_BleSetScanRsp
|
||||
**
|
||||
** Description This function is called to override the app scan response.
|
||||
**
|
||||
** Parameters Pointer to User defined ADV data structure
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BlufiBleSetScanRsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback)
|
||||
{
|
||||
esp_ble_set_scan_rsp(scan_rsp_data, p_scan_rsp_data_cback);
|
||||
}
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
#ifndef __BLUFI_ADV_H__
|
||||
#define __BLUFI_ADV_H__
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btm_ble_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
extern void BlufiBleConfigadvData(esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback);
|
||||
|
||||
extern void BlufiBleSetScanRsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback);
|
||||
|
||||
#endif /* __BLUFI_ADV_H__ */
|
@ -1,647 +0,0 @@
|
||||
#ifndef PRF_DEFS_H_
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define PRF_DEFS_H_
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "bta_gattc_int.h"
|
||||
#include "bta_gatts_int.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bt_types.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
|
||||
#define ATT_HANDLE_LEN 0x0002
|
||||
#define ATT_UUID_16_LEN 0x0002
|
||||
#define ATT_UUID_128_LEN 0x0010
|
||||
#define ATT_UUID_32_LEN 0x0004
|
||||
|
||||
#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
|
||||
esp_bt_uuid_t *char_uuid;
|
||||
///the permition of the characteristic
|
||||
esp_gatt_perm_t perm;
|
||||
/// the properties of the characteristic
|
||||
esp_gatt_char_prop_t prop;
|
||||
}char_desc_t;
|
||||
|
||||
/// UUID - 128-bit type
|
||||
typedef struct
|
||||
{
|
||||
/// 128-bit UUID
|
||||
uint8_t uuid[ATT_UUID_128_LEN];
|
||||
}uuid_128_t;
|
||||
|
||||
/// UUID - 32-bit type
|
||||
typedef struct
|
||||
{
|
||||
/// 32-bit UUID
|
||||
uint8_t uuid[ATT_UUID_32_LEN];
|
||||
}uuid_32_t;
|
||||
|
||||
/// include service entry element
|
||||
typedef struct
|
||||
{
|
||||
/// start handle value of included service
|
||||
uint16_t start_hdl;
|
||||
/// end handle value of included service
|
||||
uint16_t end_hdl;
|
||||
/// attribute value UUID
|
||||
uint16_t uuid;
|
||||
}incl_svc_desc;
|
||||
|
||||
/// Service Changed type definition
|
||||
typedef struct
|
||||
{
|
||||
/// Service start handle which changed
|
||||
uint16_t start_hdl;
|
||||
/// Service end handle which changed
|
||||
uint16_t end_hdl;
|
||||
}svc_chang_type_t;
|
||||
|
||||
|
||||
|
||||
/// Common 16-bit Universal Unique Identifier
|
||||
enum {
|
||||
ATT_INVALID_UUID = 0,
|
||||
/*----------------- SERVICES ---------------------*/
|
||||
/// Generic Access Profile
|
||||
SVC_GENERIC_ACCESS_UUID = 0x1800,
|
||||
/// Attribute Profile
|
||||
SVC_GENERIC_ATTRIBUTE_UUID,
|
||||
/// Immediate alert Service
|
||||
SVC_IMMEDIATE_ALERT_UUID,
|
||||
/// Link Loss Service
|
||||
SVC_LINK_LOSS_UUID,
|
||||
/// Tx Power Service
|
||||
SVC_TX_POWER_UUID,
|
||||
/// Current Time Service Service
|
||||
SVC_CURRENT_TIME_UUID,
|
||||
/// Reference Time Update Service
|
||||
SVC_REF_TIME_UPDATE_UUID,
|
||||
/// Next DST Change Service
|
||||
SVC_NEXT_DST_CHANGE_UUID,
|
||||
/// Glucose Service
|
||||
SVC_GLUCOSE_UUID = 0x1808,
|
||||
/// Health Thermometer Service
|
||||
SVC_HEALTH_THERMOM_UUID = 0x1809,
|
||||
/// Device Information Service
|
||||
SVC_DEVICE_INFO_UUID = 0x180A,
|
||||
/// Heart Rate Service
|
||||
SVC_HEART_RATE_UUID = 0x180D,
|
||||
/// Phone Alert Status Service
|
||||
SVC_PHONE_ALERT_STATUS_UUID,
|
||||
/// Battery Service
|
||||
SVC_BATTERY_SERVICE_UUID,
|
||||
/// Blood Pressure Service
|
||||
SVC_BLOOD_PRESSURE_UUID = 0x1810,
|
||||
/// Alert Notification Service
|
||||
SVC_ALERT_NTF_UUID = 0x1811,
|
||||
/// HID Service
|
||||
SVC_HID_UUID = 0x1812,
|
||||
/// Scan Parameters Service
|
||||
SVC_SCAN_PARAMETERS_UUID = 0x1813,
|
||||
/// Running Speed and Cadence Service
|
||||
SVC_RUNNING_SPEED_CADENCE_UUID = 0x1814,
|
||||
/// Cycling Speed and Cadence Service
|
||||
SVC_CYCLING_SPEED_CADENCE_UUID = 0x1816,
|
||||
/// Cycling Power Service
|
||||
SVC_CYCLING_POWER_UUID = 0x1818,
|
||||
/// Location and Navigation Service
|
||||
SVC_LOCATION_AND_NAVIGATION_UUID = 0x1819,
|
||||
/// User Data Service
|
||||
SVC_USER_DATA_UUID = 0x181C,
|
||||
/// Weight Scale Service
|
||||
SVC_WEIGHT_SCALE_UUID = 0x181D,
|
||||
|
||||
/*------------------- UNITS ---------------------*/
|
||||
/// No defined unit
|
||||
UNIT_UNITLESS_UUID = 0x2700,
|
||||
/// Length Unit - Metre
|
||||
UNIT_METRE_UUID,
|
||||
//Mass unit - Kilogram
|
||||
UNIT_KG_UUID,
|
||||
///Time unit - second
|
||||
UNIT_SECOND_UUID,
|
||||
///Electric current unit - Ampere
|
||||
UNIT_AMPERE_UUID,
|
||||
///Thermodynamic Temperature unit - Kelvin
|
||||
UNIT_KELVIN_UUID,
|
||||
/// Amount of substance unit - mole
|
||||
UNIT_MOLE_UUID,
|
||||
///Luminous intensity unit - candela
|
||||
UNIT_CANDELA_UUID,
|
||||
///Area unit - square metres
|
||||
UNIT_SQ_METRE_UUID = 0x2710,
|
||||
///Colume unit - cubic metres
|
||||
UNIT_CUBIC_METRE_UUID,
|
||||
///Velocity unit - metres per second
|
||||
UNIT_METRE_PER_SECOND_UUID,
|
||||
///Acceleration unit - metres per second squared
|
||||
UNIT_METRES_PER_SEC_SQ_UUID,
|
||||
///Wavenumber unit - reciprocal metre
|
||||
UNIT_RECIPROCAL_METRE_UUID,
|
||||
///Density unit - kilogram per cubic metre
|
||||
UNIT_DENS_KG_PER_CUBIC_METRE_UUID,
|
||||
///Surface density unit - kilogram per square metre
|
||||
UNIT_KG_PER_SQ_METRE_UUID,
|
||||
///Specific volume unit - cubic metre per kilogram
|
||||
UNIT_CUBIC_METRE_PER_KG_UUID,
|
||||
///Current density unit - ampere per square metre
|
||||
UNIT_AMPERE_PER_SQ_METRE_UUID,
|
||||
///Magnetic field strength unit - Ampere per metre
|
||||
UNIT_AMPERE_PER_METRE_UUID,
|
||||
///Amount concentration unit - mole per cubic metre
|
||||
UNIT_MOLE_PER_CUBIC_METRE_UUID,
|
||||
///Mass Concentration unit - kilogram per cubic metre
|
||||
UNIT_MASS_KG_PER_CUBIC_METRE_UUID,
|
||||
///Luminance unit - candela per square metre
|
||||
UNIT_CANDELA_PER_SQ_METRE_UUID,
|
||||
///Refractive index unit
|
||||
UNIT_REFRACTIVE_INDEX_UUID,
|
||||
///Relative permeability unit
|
||||
UNIT_RELATIVE_PERMEABILITY_UUID,
|
||||
///Plane angle unit - radian
|
||||
UNIT_RADIAN_UUID = 0x2720,
|
||||
///Solid angle unit - steradian
|
||||
UNIT_STERADIAN_UUID,
|
||||
///Frequency unit - Hertz
|
||||
UNIT_HERTZ_UUID,
|
||||
///Force unit - Newton
|
||||
UNIT_NEWTON_UUID,
|
||||
///Pressure unit - Pascal
|
||||
UNIT_PASCAL_UUID,
|
||||
///Energy unit - Joule
|
||||
UNIT_JOULE_UUID,
|
||||
///Power unit - Watt
|
||||
UNIT_WATT_UUID,
|
||||
///electric Charge unit - Coulomb
|
||||
UNIT_COULOMB_UUID,
|
||||
///Electric potential difference - Volt
|
||||
UNIT_VOLT_UUID,
|
||||
///Capacitance unit - Farad
|
||||
UNIT_FARAD_UUID,
|
||||
///electric resistance unit - Ohm
|
||||
UNIT_OHM_UUID,
|
||||
///Electric conductance - Siemens
|
||||
UNIT_SIEMENS_UUID,
|
||||
///Magnetic flux unit - Weber
|
||||
UNIT_WEBER_UUID,
|
||||
///Magnetic flux density unit - Tesla
|
||||
UNIT_TESLA_UUID,
|
||||
///Inductance unit - Henry
|
||||
UNIT_HENRY_UUID,
|
||||
///Temperature unit - degree Celsius
|
||||
UNIT_CELSIUS_UUID,
|
||||
///Luminous flux unit - lumen
|
||||
UNIT_LUMEN_UUID,
|
||||
//Illuminance unit - lux
|
||||
UNIT_LUX_UUID,
|
||||
///Activity referred to a radionuclide unit - becquerel
|
||||
UNIT_BECQUEREL_UUID,
|
||||
///Absorbed dose unit - Gray
|
||||
UNIT_GRAY_UUID,
|
||||
///Dose equivalent unit - Sievert
|
||||
UNIT_SIEVERT_UUID,
|
||||
///Catalytic activity unit - Katal
|
||||
UNIT_KATAL_UUID,
|
||||
///Synamic viscosity unit - Pascal second
|
||||
UNIT_PASCAL_SECOND_UUID = 0x2740,
|
||||
///Moment of force unit - Newton metre
|
||||
UNIT_NEWTON_METRE_UUID,
|
||||
///surface tension unit - Newton per metre
|
||||
UNIT_NEWTON_PER_METRE_UUID,
|
||||
///Angular velocity unit - radian per second
|
||||
UNIT_RADIAN_PER_SECOND_UUID,
|
||||
///Angular acceleration unit - radian per second squared
|
||||
UNIT_RADIAN_PER_SECOND_SQ_UUID,
|
||||
///Heat flux density unit - Watt per square metre
|
||||
UNIT_WATT_PER_SQ_METRE_UUID,
|
||||
///HEat capacity unit - Joule per Kelvin
|
||||
UNIT_JOULE_PER_KELVIN_UUID,
|
||||
///Specific heat capacity unit - Joule per kilogram kelvin
|
||||
UNIT_JOULE_PER_KG_KELVIN_UUID,
|
||||
///Specific Energy unit - Joule per kilogram
|
||||
UNIT_JOULE_PER_KG_UUID,
|
||||
///Thermal conductivity - Watt per metre Kelvin
|
||||
UNIT_WATT_PER_METRE_KELVIN_UUID,
|
||||
///Energy Density unit - joule per cubic metre
|
||||
UNIT_JOULE_PER_CUBIC_METRE_UUID,
|
||||
///Electric field strength unit - volt per metre
|
||||
UNIT_VOLT_PER_METRE_UUID,
|
||||
///Electric charge density unit - coulomb per cubic metre
|
||||
UNIT_COULOMB_PER_CUBIC_METRE_UUID,
|
||||
///Surface charge density unit - coulomb per square metre
|
||||
UNIT_SURF_COULOMB_PER_SQ_METRE_UUID,
|
||||
///Electric flux density unit - coulomb per square metre
|
||||
UNIT_FLUX_COULOMB_PER_SQ_METRE_UUID,
|
||||
///Permittivity unit - farad per metre
|
||||
UNIT_FARAD_PER_METRE_UUID,
|
||||
///Permeability unit - henry per metre
|
||||
UNIT_HENRY_PER_METRE_UUID,
|
||||
///Molar energy unit - joule per mole
|
||||
UNIT_JOULE_PER_MOLE_UUID,
|
||||
///Molar entropy unit - joule per mole kelvin
|
||||
UNIT_JOULE_PER_MOLE_KELVIN_UUID,
|
||||
///Exposure unit - coulomb per kilogram
|
||||
UNIT_COULOMB_PER_KG_UUID,
|
||||
///Absorbed dose rate unit - gray per second
|
||||
UNIT_GRAY_PER_SECOND_UUID,
|
||||
///Radiant intensity unit - watt per steradian
|
||||
UNIT_WATT_PER_STERADIAN_UUID,
|
||||
///Radiance unit - watt per square meter steradian
|
||||
UNIT_WATT_PER_SQ_METRE_STERADIAN_UUID,
|
||||
///Catalytic activity concentration unit - katal per cubic metre
|
||||
UNIT_KATAL_PER_CUBIC_METRE_UUID,
|
||||
///Time unit - minute
|
||||
UNIT_MINUTE_UUID = 0x2760,
|
||||
///Time unit - hour
|
||||
UNIT_HOUR_UUID,
|
||||
///Time unit - day
|
||||
UNIT_DAY_UUID,
|
||||
///Plane angle unit - degree
|
||||
UNIT_ANGLE_DEGREE_UUID,
|
||||
///Plane angle unit - minute
|
||||
UNIT_ANGLE_MINUTE_UUID,
|
||||
///Plane angle unit - second
|
||||
UNIT_ANGLE_SECOND_UUID,
|
||||
///Area unit - hectare
|
||||
UNIT_HECTARE_UUID,
|
||||
///Volume unit - litre
|
||||
UNIT_LITRE_UUID,
|
||||
///Mass unit - tonne
|
||||
UNIT_TONNE_UUID,
|
||||
///Pressure unit - bar
|
||||
UNIT_BAR_UUID = 0x2780,
|
||||
///Pressure unit - millimetre of mercury
|
||||
UNIT_MM_MERCURY_UUID,
|
||||
///Length unit - angstrom
|
||||
UNIT_ANGSTROM_UUID,
|
||||
///Length unit - nautical mile
|
||||
UNIT_NAUTICAL_MILE_UUID,
|
||||
///Area unit - barn
|
||||
UNIT_BARN_UUID,
|
||||
///Velocity unit - knot
|
||||
UNIT_KNOT_UUID,
|
||||
///Logarithmic radio quantity unit - neper
|
||||
UNIT_NEPER_UUID,
|
||||
///Logarithmic radio quantity unit - bel
|
||||
UNIT_BEL_UUID,
|
||||
///Length unit - yard
|
||||
UNIT_YARD_UUID = 0x27A0,
|
||||
///Length unit - parsec
|
||||
UNIT_PARSEC_UUID,
|
||||
///length unit - inch
|
||||
UNIT_INCH_UUID,
|
||||
///length unit - foot
|
||||
UNIT_FOOT_UUID,
|
||||
///length unit - mile
|
||||
UNIT_MILE_UUID,
|
||||
///pressure unit - pound-force per square inch
|
||||
UNIT_POUND_FORCE_PER_SQ_INCH_UUID,
|
||||
///velocity unit - kilometre per hour
|
||||
UNIT_KM_PER_HOUR_UUID,
|
||||
///velocity unit - mile per hour
|
||||
UNIT_MILE_PER_HOUR_UUID,
|
||||
///angular velocity unit - revolution per minute
|
||||
UNIT_REVOLUTION_PER_MINUTE_UUID,
|
||||
///energy unit - gram calorie
|
||||
UNIT_GRAM_CALORIE_UUID,
|
||||
///energy unit - kilogram calorie
|
||||
UNIT_KG_CALORIE_UUID,
|
||||
/// energy unit - kilowatt hour
|
||||
UNIT_KILOWATT_HOUR_UUID,
|
||||
///thermodynamic temperature unit - degree Fahrenheit
|
||||
UNIT_FAHRENHEIT_UUID,
|
||||
///percentage
|
||||
UNIT_PERCENTAGE_UUID,
|
||||
///per mille
|
||||
UNIT_PER_MILLE_UUID,
|
||||
///period unit - beats per minute)
|
||||
UNIT_BEATS_PER_MINUTE_UUID,
|
||||
///electric charge unit - ampere hours
|
||||
UNIT_AMPERE_HOURS_UUID,
|
||||
///mass density unit - milligram per decilitre
|
||||
UNIT_MILLIGRAM_PER_DECILITRE_UUID,
|
||||
///mass density unit - millimole per litre
|
||||
UNIT_MILLIMOLE_PER_LITRE_UUID,
|
||||
///time unit - year
|
||||
UNIT_YEAR_UUID,
|
||||
////time unit - month
|
||||
UNIT_MONTH_UUID,
|
||||
|
||||
|
||||
/*---------------- DECLARATIONS -----------------*/
|
||||
/// Primary service Declaration
|
||||
DECL_PRIMARY_SERVICE_UUID = 0x2800,
|
||||
/// Secondary service Declaration
|
||||
DECL_SECONDARY_SERVICE_UUID,
|
||||
/// Include Declaration
|
||||
DECL_INCLUDE_UUID,
|
||||
/// Characteristic Declaration
|
||||
DECL_CHARACTERISTIC_UUID,
|
||||
|
||||
|
||||
/*----------------- DESCRIPTORS -----------------*/
|
||||
/// Characteristic extended properties
|
||||
DESC_CHAR_EXT_PROPERTIES_UUID = 0x2900,
|
||||
/// Characteristic user description
|
||||
DESC_CHAR_USER_DESCRIPTION_UUID,
|
||||
/// Client characteristic configuration
|
||||
DESC_CLIENT_CHAR_CFG_UUID,
|
||||
/// Server characteristic configuration
|
||||
DESC_SERVER_CHAR_CFG_UUID,
|
||||
/// Characteristic Presentation Format
|
||||
DESC_CHAR_PRES_FORMAT_UUID,
|
||||
/// Characteristic Aggregate Format
|
||||
DESC_CHAR_AGGREGATE_FORMAT_UUID,
|
||||
/// Valid Range
|
||||
DESC_VALID_RANGE_UUID,
|
||||
/// External Report Reference
|
||||
DESC_EXT_REPORT_REF_UUID,
|
||||
/// Report Reference
|
||||
DESC_REPORT_REF_UUID,
|
||||
|
||||
|
||||
/*--------------- CHARACTERISTICS ---------------*/
|
||||
/// Device name
|
||||
CHAR_DEVICE_NAME_UUID = 0x2A00,
|
||||
/// Appearance
|
||||
CHAR_APPEARANCE_UUID = 0x2A01,
|
||||
/// Privacy flag
|
||||
CHAR_PRIVACY_FLAG_UUID = 0x2A02,
|
||||
/// Reconnection address
|
||||
CHAR_RECONNECTION_ADDR_UUID = 0x2A03,
|
||||
/// Peripheral preferred connection parameters
|
||||
CHAR_PERIPH_PREF_CON_PARAM_UUID = 0x2A04,
|
||||
/// Service handles changed
|
||||
CHAR_SERVICE_CHANGED_UUID = 0x2A05,
|
||||
/// Alert Level characteristic
|
||||
CHAR_ALERT_LEVEL_UUID = 0x2A06,
|
||||
/// Tx Power Level
|
||||
CHAR_TX_POWER_LEVEL_UUID = 0x2A07,
|
||||
/// Date Time
|
||||
CHAR_DATE_TIME_UUID = 0x2A08,
|
||||
/// Day of Week
|
||||
CHAR_DAY_WEEK_UUID = 0x2A09,
|
||||
/// Day Date Time
|
||||
CHAR_DAY_DATE_TIME_UUID = 0x2A0A,
|
||||
/// Exact time 256
|
||||
CHAR_EXACT_TIME_256_UUID = 0x2A0C,
|
||||
/// DST Offset
|
||||
CHAR_DST_OFFSET_UUID = 0x2A0D,
|
||||
/// Time zone
|
||||
CHAR_TIME_ZONE_UUID = 0x2A0E,
|
||||
/// Local time Information
|
||||
CHAR_LOCAL_TIME_INFO_UUID = 0x2A0F,
|
||||
/// Time with DST
|
||||
CHAR_TIME_WITH_DST_UUID = 0x2A11,
|
||||
/// Time Accuracy
|
||||
CHAR_TIME_ACCURACY_UUID = 0x2A12,
|
||||
///Time Source
|
||||
CHAR_TIME_SOURCE_UUID = 0x2A13,
|
||||
/// Reference Time Information
|
||||
CHAR_REFERENCE_TIME_INFO_UUID = 0x2A14,
|
||||
/// Time Update Control Point
|
||||
CHAR_TIME_UPDATE_CNTL_POINT_UUID = 0x2A16,
|
||||
/// Time Update State
|
||||
CHAR_TIME_UPDATE_STATE_UUID = 0x2A17,
|
||||
/// Glucose Measurement
|
||||
CHAR_GLUCOSE_MEAS_UUID = 0x2A18,
|
||||
/// Battery Level
|
||||
CHAR_BATTERY_LEVEL_UUID = 0x2A19,
|
||||
/// Temperature Measurement
|
||||
CHAR_TEMPERATURE_MEAS_UUID = 0x2A1C,
|
||||
/// Temperature Type
|
||||
CHAR_TEMPERATURE_TYPE_UUID = 0x2A1D,
|
||||
/// Intermediate Temperature
|
||||
CHAR_INTERMED_TEMPERATURE_UUID = 0x2A1E,
|
||||
/// Measurement Interval
|
||||
CHAR_MEAS_INTERVAL_UUID = 0x2A21,
|
||||
/// Boot Keyboard Input Report
|
||||
CHAR_BOOT_KB_IN_REPORT_UUID = 0x2A22,
|
||||
/// System ID
|
||||
CHAR_SYS_ID_UUID = 0x2A23,
|
||||
/// Model Number String
|
||||
CHAR_MODEL_NB_UUID = 0x2A24,
|
||||
/// Serial Number String
|
||||
CHAR_SERIAL_NB_UUID = 0x2A25,
|
||||
/// Firmware Revision String
|
||||
CHAR_FW_REV_UUID = 0x2A26,
|
||||
/// Hardware revision String
|
||||
CHAR_HW_REV_UUID = 0x2A27,
|
||||
/// Software Revision String
|
||||
CHAR_SW_REV_UUID = 0x2A28,
|
||||
/// Manufacturer Name String
|
||||
CHAR_MANUF_NAME_UUID = 0x2A29,
|
||||
/// IEEE Regulatory Certification Data List
|
||||
CHAR_IEEE_CERTIF_UUID = 0x2A2A,
|
||||
/// CT Time
|
||||
CHAR_CT_TIME_UUID = 0x2A2B,
|
||||
/// Scan Refresh
|
||||
CHAR_SCAN_REFRESH_UUID = 0x2A31,
|
||||
/// Boot Keyboard Output Report
|
||||
CHAR_BOOT_KB_OUT_REPORT_UUID = 0x2A32,
|
||||
/// Boot Mouse Input Report
|
||||
CHAR_BOOT_MOUSE_IN_REPORT_UUID = 0x2A33,
|
||||
/// Glucose Measurement Context
|
||||
CHAR_GLUCOSE_MEAS_CTX_UUID = 0x2A34,
|
||||
/// Blood Pressure Measurement
|
||||
CHAR_BLOOD_PRESSURE_MEAS_UUID = 0x2A35,
|
||||
/// Intermediate Cuff Pressure
|
||||
CHAR_INTERMEDIATE_CUFF_PRESSURE_UUID = 0x2A36,
|
||||
/// Heart Rate Measurement
|
||||
CHAR_HEART_RATE_MEAS_UUID = 0x2A37,
|
||||
/// Body Sensor Location
|
||||
CHAR_BODY_SENSOR_LOCATION_UUID = 0x2A38,
|
||||
/// Heart Rate Control Point
|
||||
CHAR_HEART_RATE_CNTL_POINT_UUID = 0x2A39,
|
||||
/// Alert Status
|
||||
CHAR_ALERT_STATUS_UUID = 0x2A3F,
|
||||
/// Ringer Control Point
|
||||
CHAR_RINGER_CNTL_POINT_UUID = 0x2A40,
|
||||
/// Ringer Setting
|
||||
CHAR_RINGER_SETTING_UUID = 0x2A41,
|
||||
/// Alert Category ID Bit Mask
|
||||
CHAR_ALERT_CAT_ID_BIT_MASK_UUID = 0x2A42,
|
||||
/// Alert Category ID
|
||||
CHAR_ALERT_CAT_ID_UUID = 0x2A43,
|
||||
/// Alert Notification Control Point
|
||||
CHAR_ALERT_NTF_CTNL_PT_UUID = 0x2A44,
|
||||
/// Unread Alert Status
|
||||
CHAR_UNREAD_ALERT_STATUS_UUID = 0x2A45,
|
||||
/// New Alert
|
||||
CHAR_NEW_ALERT_UUID = 0x2A46,
|
||||
/// Supported New Alert Category
|
||||
CHAR_SUP_NEW_ALERT_CAT_UUID = 0x2A47,
|
||||
/// Supported Unread Alert Category
|
||||
CHAR_SUP_UNREAD_ALERT_CAT_UUID = 0x2A48,
|
||||
/// Blood Pressure Feature
|
||||
CHAR_BLOOD_PRESSURE_FEATURE_UUID = 0x2A49,
|
||||
/// HID Information
|
||||
CHAR_HID_INFO_UUID = 0x2A4A,
|
||||
/// Report Map
|
||||
CHAR_REPORT_MAP_UUID = 0x2A4B,
|
||||
/// HID Control Point
|
||||
CHAR_HID_CTNL_PT_UUID = 0x2A4C,
|
||||
/// Report
|
||||
CHAR_REPORT_UUID = 0x2A4D,
|
||||
/// Protocol Mode
|
||||
CHAR_PROTOCOL_MODE_UUID = 0x2A4E,
|
||||
/// Scan Interval Window
|
||||
CHAR_SCAN_INTV_WD_UUID = 0x2A4F,
|
||||
/// PnP ID
|
||||
CHAR_PNP_ID_UUID = 0x2A50,
|
||||
/// Glucose Feature
|
||||
CHAR_GLUCOSE_FEATURE_UUID = 0x2A51,
|
||||
/// Record access control point
|
||||
CHAR_REC_ACCESS_CTRL_PT_UUID = 0x2A52,
|
||||
/// RSC Measurement
|
||||
CHAR_RSC_MEAS_UUID = 0x2A53,
|
||||
/// RSC Feature
|
||||
CHAR_RSC_FEAT_UUID = 0x2A54,
|
||||
/// SC Control Point
|
||||
CHAR_SC_CNTL_PT_UUID = 0x2A55,
|
||||
/// CSC Measurement
|
||||
CHAR_CSC_MEAS_UUID = 0x2A5B,
|
||||
/// CSC Feature
|
||||
CHAR_CSC_FEAT_UUID = 0x2A5C,
|
||||
/// Sensor Location
|
||||
CHAR_SENSOR_LOC_UUID = 0x2A5D,
|
||||
/// CP Measurement
|
||||
CHAR_CP_MEAS_UUID = 0x2A63,
|
||||
/// CP Vector
|
||||
CHAR_CP_VECTOR_UUID = 0x2A64,
|
||||
/// CP Feature
|
||||
CHAR_CP_FEAT_UUID = 0x2A65,
|
||||
/// CP Control Point
|
||||
CHAR_CP_CNTL_PT_UUID = 0x2A66,
|
||||
/// Location and Speed
|
||||
CHAR_LOC_SPEED_UUID = 0x2A67,
|
||||
/// Navigation
|
||||
CHAR_NAVIGATION_UUID = 0x2A68,
|
||||
/// Position Quality
|
||||
CHAR_POS_QUALITY_UUID = 0x2A69,
|
||||
/// LN Feature
|
||||
CHAR_LN_FEAT_UUID = 0x2A6A,
|
||||
/// LN Control Point
|
||||
CHAR_LN_CNTL_PT_UUID = 0x2A6B,
|
||||
|
||||
/// Weight Scale Feature
|
||||
CHAR_WS_FEAT_UUID = 0x2A9E,
|
||||
/// Weight Scale Measurement
|
||||
CHAR_WS_MEAS_UUID = 0x2A9D,
|
||||
/// User height
|
||||
CHAR_UDS_USER_HEIGHT_UUID = 0x2A8E,
|
||||
/// User age
|
||||
CHAR_UDS_USER_AGE_UUID = 0x2A80,
|
||||
/// User date of birth
|
||||
CHAR_UDS_USER_DATE_OF_BIRTH_UUID = 0x2A85,
|
||||
/// User database change increment
|
||||
CHAR_UDS_USER_DB_CHANGE_INCR_UUID = 0x2A99,
|
||||
/// User Data Index
|
||||
CHAR_UDS_USER_DATA_INDEX_UUID = 0x2A9A,
|
||||
/// User Data Control Point
|
||||
CHAR_UDS_USER_CTRL_PT_UUID = 0x2A9F,
|
||||
/// Central Address Resolution
|
||||
CHAR_CENT_ADDR_RES_UUID = 0x2AA6,
|
||||
/// Last define
|
||||
LAST
|
||||
};
|
||||
|
||||
/// Format for Characteristic Presentation
|
||||
enum {
|
||||
/// unsigned 1-bit: true or false
|
||||
FORMAT_BOOL_UUID = 0x01,
|
||||
/// unsigned 2-bit integer
|
||||
FORMAT_2BIT_UUID,
|
||||
/// unsigned 4-bit integer
|
||||
FORMAT_NIBBLE_UUID,
|
||||
/// unsigned 8-bit integer
|
||||
FORMAT_UINT8_UUID,
|
||||
/// unsigned 12-bit integer
|
||||
FORMAT_UINT12_UUID,
|
||||
/// unsigned 16-bit integer
|
||||
FORMAT_UINT16_UUID,
|
||||
/// unsigned 24-bit integer
|
||||
FORMAT_UINT24_UUID,
|
||||
/// unsigned 32-bit integer
|
||||
FORMAT_UINT32_UUID,
|
||||
/// unsigned 48-bit integer
|
||||
FORMAT_UINT48_UUID,
|
||||
/// unsigned 64-bit integer
|
||||
FORMAT_UINT64_UUID,
|
||||
/// unsigned 128-bit integer
|
||||
FORMAT_UINT128_UUID,
|
||||
/// signed 8-bit integer
|
||||
FORMAT_SINT8_UUID,
|
||||
/// signed 12-bit integer
|
||||
FORMAT_SINT12_UUID,
|
||||
/// signed 16-bit integer
|
||||
FORMAT_SINT16_UUID,
|
||||
/// signed 24-bit integer
|
||||
FORMAT_SINT24_UUID,
|
||||
/// signed 32-bit integer
|
||||
FORMAT_SINT32_UUID,
|
||||
/// signed 48-bit integer
|
||||
FORMAT_SINT48_UUID,
|
||||
/// signed 64-bit integer
|
||||
FORMAT_SINT64_UUID,
|
||||
/// signed 128-bit integer
|
||||
FORMAT_SINT128_UUID,
|
||||
/// IEEE-754 32-bit floating point
|
||||
FORMAT_FLOAT32_UUID,
|
||||
/// IEEE-754 64-bit floating point
|
||||
FORMAT_FLOAT64_UUID,
|
||||
/// IEEE-11073 16-bit SFLOAT
|
||||
FORMAT_SFLOAT_UUID,
|
||||
/// IEEE-11073 32-bit FLOAT
|
||||
FORMAT_FLOAT_UUID,
|
||||
/// IEEE-20601 format
|
||||
FORMAT_DUINT16_UUID,
|
||||
/// UTF-8 string
|
||||
FORMAT_UTF8S_UUID,
|
||||
/// UTF-16 string
|
||||
FORMAT_UTF16S_UUID,
|
||||
/// Opaque structure
|
||||
FORMAT_STRUCT_UUID,
|
||||
/// Last format
|
||||
FORMAT_LAST_UUID
|
||||
};
|
||||
|
||||
|
||||
#endif ///PRF_DEFS_H_
|
||||
|
@ -9,15 +9,16 @@ COMPONENT_ADD_INCLUDEDIRS := bluedroid/bta/include \
|
||||
bluedroid/gki/include \
|
||||
bluedroid/hci/include \
|
||||
bluedroid/osi/include \
|
||||
bluedroid/profiles/core/include \
|
||||
bluedroid/profiles/esp/blufi/include \
|
||||
bluedroid/profiles/esp/include \
|
||||
bluedroid/profiles/std/avrc/include \
|
||||
bluedroid/profiles/std/battery/include \
|
||||
bluedroid/profiles/std/dis/include \
|
||||
bluedroid/profiles/std/hid/include \
|
||||
bluedroid/profiles/std/rfcomm/include \
|
||||
bluedroid/profiles/std/include \
|
||||
bluedroid/btc/core/include \
|
||||
bluedroid/btc/profile/esp/blufi/include \
|
||||
bluedroid/btc/profile/esp/include \
|
||||
bluedroid/btc/profile/std/gatt/include \
|
||||
bluedroid/btc/profile/std/gap/include \
|
||||
bluedroid/btc/profile/std/sdp/include \
|
||||
bluedroid/btc/profile/std/include/gatt \
|
||||
bluedroid/btc/profile/std/include/gap \
|
||||
bluedroid/btc/profile/std/include/sdp \
|
||||
bluedroid/btc/include \
|
||||
bluedroid/stack/btm/include \
|
||||
bluedroid/stack/btu/include \
|
||||
bluedroid/stack/gap/include \
|
||||
@ -52,21 +53,12 @@ COMPONENT_SRCDIRS := bluedroid/bta/dm \
|
||||
bluedroid/hci \
|
||||
bluedroid/main \
|
||||
bluedroid/osi \
|
||||
bluedroid/profiles/core \
|
||||
bluedroid/profiles/esp/blufi \
|
||||
bluedroid/profiles/esp/ble_button \
|
||||
bluedroid/profiles/esp/wechat_AirSync \
|
||||
bluedroid/profiles/esp \
|
||||
bluedroid/profiles/std/avrc \
|
||||
bluedroid/profiles/std/battery \
|
||||
bluedroid/profiles/std/dis \
|
||||
bluedroid/profiles/std/hid \
|
||||
bluedroid/profiles/std/hid_le \
|
||||
bluedroid/profiles/std/rfcomm \
|
||||
bluedroid/profiles/std/sdp \
|
||||
bluedroid/profiles/std/gap \
|
||||
bluedroid/profiles/std \
|
||||
bluedroid/profiles \
|
||||
bluedroid/btc/core \
|
||||
bluedroid/btc/profile/esp/blufi \
|
||||
bluedroid/btc/profile/std/gap \
|
||||
bluedroid/btc/profile/std/gap \
|
||||
bluedroid/btc/profile/std/gatt \
|
||||
bluedroid/btc/profile \
|
||||
bluedroid/stack/btm \
|
||||
bluedroid/stack/btu \
|
||||
bluedroid/stack/gap \
|
||||
|
@ -34,17 +34,13 @@
|
||||
#include "bt_trace.h"
|
||||
#include "btm_api.h"
|
||||
#include "bt_types.h"
|
||||
#include "dis_api.h"
|
||||
|
||||
#include "blufi_prf.h"
|
||||
#include "hid_le_prf.h"
|
||||
#include "prf_defs.h"
|
||||
#include "hcimsgs.h"
|
||||
|
||||
#include "blufi.h"
|
||||
#include "blufi_adv.h"
|
||||
|
||||
#include "esp_bt_common.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user