bluedroid: add config for GAP service and periodic adv sync transfer

This commit is contained in:
chenjianhua 2022-12-08 19:52:28 +08:00
parent c479918f2b
commit 14c2f27f3e
11 changed files with 160 additions and 63 deletions

View File

@ -193,6 +193,20 @@ config BT_GATTS_ROBUST_CACHING_ENABLED
help
This option enable gatt robust caching feature on server
config BT_GATTS_DEVICE_NAME_WRITABLE
bool "Allow to write device name by GATT clients"
depends on BT_GATTS_ENABLE
default n
help
Enabling this option allows remote GATT clients to write device name
config BT_GATTS_APPEARANCE_WRITABLE
bool "Allow to write appearance by GATT clients"
depends on BT_GATTS_ENABLE
default n
help
Enabling this option allows remote GATT clients to write appearance
config BT_GATTC_ENABLE
bool "Include GATT client module(GATTC)"
depends on BT_BLE_ENABLED
@ -1079,7 +1093,7 @@ config BT_BLE_RPA_SUPPORTED
two modes according to their own needs. So this option is enabled by default.
config BT_BLE_RPA_TIMEOUT
int "timeout of resolvable private address"
int "Timeout of resolvable private address"
depends on BT_BLUEDROID_ENABLED
range 1 3600
default 900

View File

@ -3158,6 +3158,9 @@ void BTA_DmBleGapExtConnect(tBLE_ADDR_TYPE own_addr_type, const BD_ADDR peer_add
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
uint8_t BTA_DmBlePeriodicAdvSetInfoTrans(uint8_t addr[6], uint16_t service_data, uint8_t adv_handle)
{
BTM_BlePeriodicAdvSetInfoTrans(addr, service_data, adv_handle);
@ -3169,7 +3172,6 @@ uint8_t BTA_DmBleSetPeriodicAdvSyncTransParams(uint8_t addr[6], uint8_t mode, ui
BTM_BleSetPeriodicAdvSyncTransParams(addr, mode, skip, sync_timeout, 0);
return 0;
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#endif

View File

@ -271,7 +271,19 @@
#ifdef CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED
#define UC_BT_GATTS_ROBUST_CACHING_ENABLED CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED
#else
#define UC_BT_GATTS_ROBUST_CACHING_ENABLED 0
#define UC_BT_GATTS_ROBUST_CACHING_ENABLED FALSE
#endif
#ifdef CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE
#define UC_BT_GATTS_DEVICE_NAME_WRITABLE CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE
#else
#define UC_BT_GATTS_DEVICE_NAME_WRITABLE FALSE
#endif
#ifdef CONFIG_BT_GATTS_APPEARANCE_WRITABLE
#define UC_BT_GATTS_APPEARANCE_WRITABLE CONFIG_BT_GATTS_APPEARANCE_WRITABLE
#else
#define UC_BT_GATTS_APPEARANCE_WRITABLE FALSE
#endif
#ifdef CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN

View File

@ -461,8 +461,22 @@
#define GATTS_SEND_SERVICE_CHANGE_MODE UC_BT_GATTS_SEND_SERVICE_CHANGE_MODE
#endif
#ifdef UC_BT_GATTS_ROBUST_CACHING_ENABLED
#define GATTS_ROBUST_CACHING_ENABLED UC_BT_GATTS_ROBUST_CACHING_ENABLED
#if (UC_BT_GATTS_ROBUST_CACHING_ENABLED == TRUE)
#define GATTS_ROBUST_CACHING_ENABLED TRUE
#else
#define GATTS_ROBUST_CACHING_ENABLED FALSE
#endif
#if (UC_BT_GATTS_DEVICE_NAME_WRITABLE == TRUE)
#define GATTS_DEVICE_NAME_WRITABLE TRUE
#else
#define GATTS_DEVICE_NAME_WRITABLE FALSE
#endif
#if (UC_BT_GATTS_APPEARANCE_WRITABLE == TRUE)
#define GATTS_APPEARANCE_WRITABLE TRUE
#else
#define GATTS_APPEARANCE_WRITABLE FALSE
#endif
#ifdef UC_BT_BLE_ACT_SCAN_REP_ADV_SCAN
@ -2154,6 +2168,9 @@ The maximum number of payload octets that the local device can receive in a sing
#define HEAP_ALLOCATION_FROM_SPIRAM_FIRST FALSE
#endif
// TODO: add menuconfig and api for periodic adv sync transfer
#define BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER FALSE
#include "common/bt_trace.h"
#endif /* BT_TARGET_H */

View File

@ -1040,34 +1040,6 @@ void BTM_BleSetPreferExtenedConnParams (BD_ADDR bd_addr, tBTM_EXT_CONN_PARAMS *p
return;
}
void BTM_BlePeriodicAdvSetInfoTrans(BD_ADDR bd_addr, UINT16 service_data, UINT8 adv_handle)
{
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
if (!p_lcb) {
BTM_TRACE_ERROR("%s, invalid parameters", __func__);
return;
}
if (!btsnd_hcic_ble_periodic_adv_set_info_trans(p_lcb->handle, service_data, adv_handle)) {
BTM_TRACE_ERROR("%s, hci cmd error", __func__);
}
}
void BTM_BleSetPeriodicAdvSyncTransParams(BD_ADDR bd_addr, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type)
{
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
if (!p_lcb) {
BTM_TRACE_ERROR("%s, invalid parameters", __func__);
return;
}
if (!btsnd_hcic_ble_set_periodic_adv_sync_trans_params(p_lcb->handle, mode, skip, sync_timeout, cte_type)) {
BTM_TRACE_ERROR("%s, hci cmd error", __func__);
}
}
void btm_ble_extended_init(void)
{
@ -1318,3 +1290,33 @@ void btm_ble_periodic_adv_sync_establish_evt(tBTM_BLE_PERIOD_ADV_SYNC_ESTAB *par
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
void BTM_BlePeriodicAdvSetInfoTrans(BD_ADDR bd_addr, UINT16 service_data, UINT8 adv_handle)
{
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
if (!p_lcb) {
BTM_TRACE_ERROR("%s, invalid parameters", __func__);
return;
}
if (!btsnd_hcic_ble_periodic_adv_set_info_trans(p_lcb->handle, service_data, adv_handle)) {
BTM_TRACE_ERROR("%s, hci cmd error", __func__);
}
}
void BTM_BleSetPeriodicAdvSyncTransParams(BD_ADDR bd_addr, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type)
{
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
if (!p_lcb) {
BTM_TRACE_ERROR("%s, invalid parameters", __func__);
return;
}
if (!btsnd_hcic_ble_set_periodic_adv_sync_trans_params(p_lcb->handle, mode, skip, sync_timeout, cte_type)) {
BTM_TRACE_ERROR("%s, hci cmd error", __func__);
}
}
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)

View File

@ -145,8 +145,10 @@ static void btu_ble_periodic_adv_sync_lost_evt(UINT8 *p);
static void btu_ble_scan_timeout_evt(UINT8 *p);
static void btu_ble_adv_set_terminate_evt(UINT8 *p);
static void btu_ble_scan_req_received_evt(UINT8 *p);
static void btu_ble_periodic_adv_sync_trans_recv(UINT8 *p);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
static void btu_ble_periodic_adv_sync_trans_recv(UINT8 *p);
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
extern osi_sem_t adv_enable_sem;
extern osi_sem_t adv_data_sem;
@ -412,10 +414,12 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
break;
case HCI_BLE_CHANNEL_SELECT_ALG:
break;
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
case HCI_BLE_PERIOD_ADV_SYNC_TRANS_RECV_EVT:
btu_ble_periodic_adv_sync_trans_recv(p);
break;
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
}
break;
#endif /* BLE_INCLUDED */
@ -2308,7 +2312,9 @@ static void btu_ble_scan_req_received_evt(UINT8 *p)
btm_ble_scan_req_received_evt(&req_received);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
static void btu_ble_periodic_adv_sync_trans_recv(UINT8 *p)
{
tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV recv = {0};
@ -2326,7 +2332,8 @@ static void btu_ble_periodic_adv_sync_trans_recv(UINT8 *p)
HCI_TRACE_DEBUG("%s status %x, conn handle %x, sync handle %x", recv.status, recv.conn_handle, recv.sync_handle);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/**********************************************
** End of BLE Events Handler
***********************************************/

View File

@ -298,12 +298,34 @@ UINT8 gap_proc_write_req( tGATTS_REQ_TYPE type, tGATT_WRITE_REQ *p_data)
UNUSED(type);
for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++) {
if (p_data-> handle == p_db_attr->handle) {
if (p_data->handle == p_db_attr->handle) {
switch (p_db_attr->uuid) {
#if (GATTS_DEVICE_NAME_WRITABLE == TRUE)
case GATT_UUID_GAP_DEVICE_NAME: {
UINT8 *p_val = p_data->value;
p_val[p_data->len] = '\0';
BTM_SetLocalDeviceName((char *)p_val);
return GATT_SUCCESS;
}
#endif
#if (GATTS_APPEARANCE_WRITABLE == TRUE)
case GATT_UUID_GAP_ICON: {
UINT8 *p_val = p_data->value;
if (p_data->len != sizeof(UINT16)) {
return GATT_INVALID_ATTR_LEN;
}
STREAM_TO_UINT16(p_db_attr->attr_value.icon, p_val);
return GATT_SUCCESS;
}
#endif
default:
break;
}
return GATT_WRITE_NOT_PERMIT;
}
}
return GATT_NOT_FOUND;
return GATT_NOT_FOUND;
}
/******************************************************************************
@ -393,17 +415,26 @@ void gap_attr_db_init(void)
*/
uuid.len = LEN_UUID_16;
uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_DEVICE_NAME;
p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ,
p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid,
#if (GATTS_DEVICE_NAME_WRITABLE == TRUE)
GATT_PERM_READ | GATT_PERM_WRITE,
GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE_NR,
#else
GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ,
#endif
NULL, NULL);
p_db_attr ++;
/* add Icon characteristic
*/
uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_ICON;
p_db_attr->handle = GATTS_AddCharacteristic(service_handle,
&uuid,
GATT_PERM_READ,
GATT_CHAR_PROP_BIT_READ,
p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid,
#if (GATTS_APPEARANCE_WRITABLE == TRUE)
GATT_PERM_READ | GATT_PERM_WRITE,
GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE_NR,
#else
GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ,
#endif
NULL, NULL);
p_db_attr ++;

View File

@ -1775,7 +1775,9 @@ UINT8 btsnd_hcic_ble_write_rf_path_compensation(UINT16 rf_tx_path, UINT16 rf_rx_
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
UINT8 btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle, UINT8 enable)
{
BT_HDR *p;
@ -1856,5 +1858,5 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_sync_trans_params(UINT16 conn_handle, UINT
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#endif

View File

@ -1230,19 +1230,6 @@ typedef struct {
UINT8 adv_clk_accuracy;
} tBTM_BLE_PERIOD_ADV_SYNC_ESTAB;
typedef struct {
UINT8 status;
UINT16 conn_handle;
UINT16 service_data;
UINT16 sync_handle;
UINT8 adv_sid;
UINT8 adv_addr_type;
BD_ADDR adv_addr;
UINT8 adv_phy;
UINT16 period_adv_interval;
UINT8 adv_clk_accuracy;
} tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV;
typedef struct {
UINT16 scan_interval;
UINT16 scan_window;
@ -1301,6 +1288,21 @@ typedef void (*tBTM_BLE_5_HCI_CBACK)(tBTM_BLE_5_GAP_EVENT event, tBTM_BLE_5_GAP_
#endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
typedef struct {
UINT8 status;
UINT16 conn_handle;
UINT16 service_data;
UINT16 sync_handle;
UINT8 adv_sid;
UINT8 adv_addr_type;
BD_ADDR adv_addr;
UINT8 adv_phy;
UINT16 period_adv_interval;
UINT8 adv_clk_accuracy;
} tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV;
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/*****************************************************************************
** EXTERNAL FUNCTION DECLARATIONS
*****************************************************************************/
@ -2650,10 +2652,12 @@ tBTM_STATUS BTM_BleSetExtendedScanParams(tBTM_BLE_EXT_SCAN_PARAMS *params);
tBTM_STATUS BTM_BleExtendedScan(BOOLEAN enable, UINT16 duration, UINT16 period);
void BTM_BleSetPreferExtenedConnParams(BD_ADDR bd_addr, tBTM_EXT_CONN_PARAMS *params);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
void BTM_BlePeriodicAdvSetInfoTrans(BD_ADDR bd_addr, UINT16 service_data, UINT8 adv_handle);
void BTM_BleSetPeriodicAdvSyncTransParams(BD_ADDR bd_addr, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#endif

View File

@ -384,11 +384,13 @@
#define HCI_BLE_RD_RF_PATH_COMPENSATION (0x004C | HCI_GRP_BLE_CMDS)
#define HCI_BLE_WR_RF_PATH_COMPENSATION (0x004D | HCI_GRP_BLE_CMDS)
#define HCI_BLE_SET_PRIVACY_MODE (0x004E | HCI_GRP_BLE_CMDS)
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#define HCI_BLE_SET_PERIOD_ADV_RECV_ENABLE (0x0059 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_PERIOD_ADV_SYNC_TRANS (0x005A | HCI_GRP_BLE_CMDS)
#define HCI_BLE_PERIOD_ADV_SET_INFO_TRANS (0x005B | HCI_GRP_BLE_CMDS)
#define HCI_BLE_SET_PERIOD_ADV_SYNC_TRANS_PARAMS (0x005C | HCI_GRP_BLE_CMDS)
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
// Vendor OGF define
#define HCI_VENDOR_OGF 0x3F
@ -805,8 +807,10 @@
#define HCI_BLE_ADV_SET_TERMINATED_EVT 0x12
#define HCI_BLE_SCAN_REQ_RECEIVED_EVT 0x13
#define HCI_BLE_CHANNEL_SELECT_ALG 0x14
#define HCI_BLE_PERIOD_ADV_SYNC_TRANS_RECV_EVT 0x18
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#define HCI_BLE_PERIOD_ADV_SYNC_TRANS_RECV_EVT 0x18
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
/* Definitions for LE Channel Map */
#define HCI_BLE_CHNL_MAP_SIZE 5

View File

@ -1032,6 +1032,8 @@ UINT8 btsnd_hcic_ble_read_rf_path_compensation(void);
UINT8 btsnd_hcic_ble_write_rf_path_compensation(UINT16 rf_tx_path, UINT16 rf_rx_path);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
UINT8 btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle, UINT8 enable);
UINT8 btsnd_hcic_ble_periodic_adv_sync_trans(UINT16 conn_handle, UINT16 service_data, UINT16 sync_handle);
@ -1039,7 +1041,7 @@ UINT8 btsnd_hcic_ble_periodic_adv_sync_trans(UINT16 conn_handle, UINT16 service_
UINT8 btsnd_hcic_ble_periodic_adv_set_info_trans(UINT16 conn_handle, UINT16 service_data, UINT8 adv_handle);
UINT8 btsnd_hcic_ble_set_periodic_adv_sync_trans_params(UINT16 conn_handle, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
#define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4
#define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_HANDLE_OFF 0