Skip to content

Commit

Permalink
bluedroid: support periodic advertising sync transfer cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
esp-cjh committed Sep 6, 2023
1 parent 33c8ffa commit a1ffb25
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 1 deletion.
12 changes: 12 additions & 0 deletions components/bt/host/bluedroid/bta/dm/bta_dm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,18 @@ void BTA_DmBleGapExtConnect(tBLE_ADDR_TYPE own_addr_type, const BD_ADDR peer_add

}

uint8_t BTA_DmBlePeriodicAdvSetInfoTrans(uint8_t addr[6], uint16_t service_data, uint8_t adv_handle)
{
BTM_BlePeriodicAdvSetInfoTrans(addr, service_data, adv_handle);
return 0;
}

uint8_t BTA_DmBleSetPeriodicAdvSyncTransParams(uint8_t addr[6], uint8_t mode, uint16_t skip, uint16_t sync_timeout)
{
BTM_BleSetPeriodicAdvSyncTransParams(addr, mode, skip, sync_timeout, 0);
return 0;
}

#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

#endif
27 changes: 27 additions & 0 deletions components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,33 @@ 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)
{
Expand Down
23 changes: 22 additions & 1 deletion components/bt/host/bluedroid/stack/btu/btu_hcif.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ 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)

extern osi_sem_t adv_enable_sem;
Expand Down Expand Up @@ -412,6 +412,9 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
break;
case HCI_BLE_CHANNEL_SELECT_ALG:
break;
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)
}
break;
Expand Down Expand Up @@ -2305,6 +2308,24 @@ static void btu_ble_scan_req_received_evt(UINT8 *p)

btm_ble_scan_req_received_evt(&req_received);
}

static void btu_ble_periodic_adv_sync_trans_recv(UINT8 *p)
{
tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV recv = {0};

STREAM_TO_UINT8(recv.status, p);
STREAM_TO_UINT16(recv.conn_handle, p);
STREAM_TO_UINT16(recv.service_data, p);
STREAM_TO_UINT16(recv.sync_handle, p);
STREAM_TO_UINT8(recv.adv_sid, p);
STREAM_TO_UINT8(recv.adv_addr_type, p);
STREAM_TO_BDADDR(recv.adv_addr, p);
STREAM_TO_UINT8(recv.adv_phy, p);
STREAM_TO_UINT16(recv.period_adv_interval, p);
STREAM_TO_UINT8(recv.adv_clk_accuracy, 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)
/**********************************************
** End of BLE Events Handler
Expand Down
81 changes: 81 additions & 0 deletions components/bt/host/bluedroid/stack/hcic/hciblecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,5 +1775,86 @@ 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);
}

UINT8 btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle, UINT8 enable)
{
BT_HDR *p;
UINT8 *pp;

HCIC_BLE_CMD_CREATED(p, pp, 3);

pp = (UINT8 *)(p + 1);

UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_RECV_ENABLE);
UINT8_TO_STREAM(pp, 3);

UINT16_TO_STREAM(pp, sync_handle);
UINT8_TO_STREAM(pp, enable);

return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

UINT8 btsnd_hcic_ble_periodic_adv_sync_trans(UINT16 conn_handle, UINT16 service_data, UINT16 sync_handle)
{
BT_HDR *p;
UINT8 *pp;

HCIC_BLE_CMD_CREATED(p, pp, 6);

pp = (UINT8 *)(p + 1);

UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_SYNC_TRANS);
UINT8_TO_STREAM(pp, 6);

UINT16_TO_STREAM(pp, conn_handle);
UINT16_TO_STREAM(pp, service_data);
UINT16_TO_STREAM(pp, sync_handle);

return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

UINT8 btsnd_hcic_ble_periodic_adv_set_info_trans(UINT16 conn_handle, UINT16 service_data, UINT8 adv_handle)
{
BT_HDR *p;
UINT8 *pp;

HCI_TRACE_DEBUG("%s conn handle %x, adv handle %x", __func__, conn_handle, adv_handle);

HCIC_BLE_CMD_CREATED(p, pp, 5);

pp = (UINT8 *)(p + 1);

UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_SET_INFO_TRANS);
UINT8_TO_STREAM(pp, 5);

UINT16_TO_STREAM(pp, conn_handle);
UINT16_TO_STREAM(pp, service_data);
UINT8_TO_STREAM(pp, adv_handle);

return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}

UINT8 btsnd_hcic_ble_set_periodic_adv_sync_trans_params(UINT16 conn_handle, UINT8 mode, UINT16 skip, UINT16 sync_timeout, UINT8 cte_type)
{
BT_HDR *p;
UINT8 *pp;

HCI_TRACE_DEBUG("%s conn handle %x, mode %x, sync timeout %x", __func__, conn_handle, mode, sync_timeout);

HCIC_BLE_CMD_CREATED(p, pp, 8);

pp = (UINT8 *)(p + 1);

UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_SYNC_TRANS_PARAMS);
UINT8_TO_STREAM(pp, 8);

UINT16_TO_STREAM(pp, conn_handle);
UINT8_TO_STREAM(pp, mode);
UINT16_TO_STREAM(pp, skip);
UINT16_TO_STREAM(pp, sync_timeout);
UINT8_TO_STREAM(pp, cte_type);

return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#endif
16 changes: 16 additions & 0 deletions components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,19 @@ 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;
Expand Down Expand Up @@ -2642,6 +2655,9 @@ tBTM_STATUS BTM_BleExtendedScan(BOOLEAN enable, UINT16 duration, UINT16 period);

void BTM_BleSetPreferExtenedConnParams(BD_ADDR bd_addr, tBTM_EXT_CONN_PARAMS *params);

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
5 changes: 5 additions & 0 deletions components/bt/host/bluedroid/stack/include/stack/hcidefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@
#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)
#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)
// Vendor OGF define
#define HCI_VENDOR_OGF 0x3F
Expand Down Expand Up @@ -801,6 +805,7 @@
#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)

/* Definitions for LE Channel Map */
Expand Down
8 changes: 8 additions & 0 deletions components/bt/host/bluedroid/stack/include/stack/hcimsgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,14 @@ UINT8 btsnd_hcic_ble_read_trans_power(void);
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);

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);

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)
#define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4

Expand Down

0 comments on commit a1ffb25

Please sign in to comment.