fix(bt/bluedroid): enable sniff power management for PBAP client

This commit is contained in:
linruihao
2026-09-14 10:19:23 +08:00
parent 7a2d687f53
commit 47472bb9e2
3 changed files with 36 additions and 3 deletions
@@ -117,13 +117,21 @@ tBTA_DM_CFG *const p_bta_dm_cfg = (tBTA_DM_CFG *) &bta_dm_cfg;
tBTA_DM_RM *const p_bta_dm_rm_cfg = (tBTA_DM_RM *) &bta_dm_rm_cfg; tBTA_DM_RM *const p_bta_dm_rm_cfg = (tBTA_DM_RM *) &bta_dm_rm_cfg;
#if BLE_INCLUDED == TRUE #if BLE_INCLUDED == TRUE
# define BTA_DM_NUM_PM_ENTRY 10 /* number of entries in bta_dm_pm_cfg except the first */ # define BTA_DM_NUM_PM_ENTRY_BASE 10 /* number of entries in bta_dm_pm_cfg except the first */
# define BTA_DM_NUM_PM_SPEC 10 /* number of entries in bta_dm_pm_spec */ # define BTA_DM_NUM_PM_SPEC 10 /* number of entries in bta_dm_pm_spec */
#else #else
# define BTA_DM_NUM_PM_ENTRY 8 /* number of entries in bta_dm_pm_cfg except the first */ # define BTA_DM_NUM_PM_ENTRY_BASE 8 /* number of entries in bta_dm_pm_cfg except the first */
# define BTA_DM_NUM_PM_SPEC 8 /* number of entries in bta_dm_pm_spec */ # define BTA_DM_NUM_PM_SPEC 8 /* number of entries in bta_dm_pm_spec */
#endif #endif
#if (BTA_PBA_CLIENT_INCLUDED == TRUE)
# define BTA_DM_NUM_PM_PBC_ENTRY 1
#else
# define BTA_DM_NUM_PM_PBC_ENTRY 0
#endif
#define BTA_DM_NUM_PM_ENTRY (BTA_DM_NUM_PM_ENTRY_BASE + BTA_DM_NUM_PM_PBC_ENTRY)
#if (BTA_DM_PM_INCLUDED == TRUE) #if (BTA_DM_PM_INCLUDED == TRUE)
tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1] = { tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1] = {
@@ -140,6 +148,9 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1]
, {BTA_ID_GATTC, BTA_ALL_APP_ID, 8} /* gattc spec table */ , {BTA_ID_GATTC, BTA_ALL_APP_ID, 8} /* gattc spec table */
, {BTA_ID_GATTS, BTA_ALL_APP_ID, 9} /* gatts spec table */ , {BTA_ID_GATTS, BTA_ALL_APP_ID, 9} /* gatts spec table */
#endif #endif
#if (BTA_PBA_CLIENT_INCLUDED == TRUE)
, {BTA_ID_PBC, BTA_ALL_APP_ID, 2} /* pbc reuses ftc/opc spec table */
#endif
}; };
#define BTA_DM_PM_SPEC_TO_OFFSET (197) /* timeout offset to avoid conflict with other bluedroid host */ #define BTA_DM_PM_SPEC_TO_OFFSET (197) /* timeout offset to avoid conflict with other bluedroid host */
@@ -182,7 +193,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] = {
} }
}, },
/* FTC, OPC, JV : 2 */ /* FTC, OPC, JV, PBC : 2 */
{ {
(BTA_DM_PM_SNIFF), /* allow sniff */ (BTA_DM_PM_SNIFF), /* allow sniff */
#if (BTM_SSR_INCLUDED == TRUE) #if (BTM_SSR_INCLUDED == TRUE)
@@ -25,6 +25,14 @@ static const char *type_pull_vcard_entry = "x-bt/vcard";
#define TYPE_LEN_PULL_VCARD_LISTING 19 #define TYPE_LEN_PULL_VCARD_LISTING 19
#define TYPE_LEN_PULL_VCARD_ENTRY 11 #define TYPE_LEN_PULL_VCARD_ENTRY 11
static void bta_pba_client_pm_conn_close(tBTA_PBA_CLIENT_CCB *p_ccb)
{
if (p_ccb->pm_open) {
bta_sys_conn_close(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
p_ccb->pm_open = FALSE;
}
}
static void free_ccb(tBTA_PBA_CLIENT_CCB *p_ccb) static void free_ccb(tBTA_PBA_CLIENT_CCB *p_ccb)
{ {
UINT8 sdp_seq; UINT8 sdp_seq;
@@ -52,6 +60,8 @@ static void close_goepc_and_report(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_E
conn.error = reason; conn.error = reason;
bdcpy(conn.bd_addr, p_ccb->bd_addr); bdcpy(conn.bd_addr, p_ccb->bd_addr);
bta_pba_client_pm_conn_close(p_ccb);
/* free ccb */ /* free ccb */
free_ccb(p_ccb); free_ccb(p_ccb);
@@ -425,6 +435,7 @@ void bta_pba_client_api_req(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DATA *p_
if (ret != GOEP_SUCCESS) { if (ret != GOEP_SUCCESS) {
goto error; goto error;
} }
bta_sys_busy(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
return; return;
error: error:
@@ -550,6 +561,11 @@ void bta_pba_client_authenticate(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DAT
void bta_pba_client_connect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DATA *p_data) void bta_pba_client_connect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DATA *p_data)
{ {
tBTA_PBA_CLIENT_CONN conn; tBTA_PBA_CLIENT_CONN conn;
UNUSED(p_data);
bta_sys_conn_open(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
p_ccb->pm_open = TRUE;
conn.handle = p_ccb->allocated; conn.handle = p_ccb->allocated;
conn.peer_supported_repo = p_ccb->peer_supported_repo; conn.peer_supported_repo = p_ccb->peer_supported_repo;
conn.peer_supported_feat = p_ccb->peer_supported_feat; conn.peer_supported_feat = p_ccb->peer_supported_feat;
@@ -680,6 +696,7 @@ void bta_pba_client_response_final(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_D
} }
bta_pba_client_report_get_headers(p_ccb, p_data->goep_response.pkt, &info, TRUE); bta_pba_client_report_get_headers(p_ccb, p_data->goep_response.pkt, &info, TRUE);
p_data->goep_response.pkt = NULL; p_data->goep_response.pkt = NULL;
bta_sys_idle(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
return; return;
} }
/* unexpected response code or body data not found */ /* unexpected response code or body data not found */
@@ -687,6 +704,7 @@ void bta_pba_client_response_final(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_D
report_error_data_event(p_ccb, reason); report_error_data_event(p_ccb, reason);
osi_free(p_data->goep_response.pkt); osi_free(p_data->goep_response.pkt);
p_data->goep_response.pkt = NULL; p_data->goep_response.pkt = NULL;
bta_sys_idle(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
/* state machine is good, don't goto error */ /* state machine is good, don't goto error */
} }
@@ -699,6 +717,7 @@ void bta_pba_client_response_final(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_D
report_error_data_event(p_ccb, reason); report_error_data_event(p_ccb, reason);
} }
osi_free(p_data->goep_response.pkt); osi_free(p_data->goep_response.pkt);
bta_sys_idle(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr);
} }
else if (p_data->goep_response.opcode == OBEX_OPCODE_DISCONNECT) { else if (p_data->goep_response.opcode == OBEX_OPCODE_DISCONNECT) {
/* received disconnect response, close goep connection now */ /* received disconnect response, close goep connection now */
@@ -756,6 +775,7 @@ void bta_pba_client_goep_connect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DAT
void bta_pba_client_goep_disconnect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DATA *p_data) void bta_pba_client_goep_disconnect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_DATA *p_data)
{ {
UNUSED(p_data);
p_ccb->goep_handle = 0; p_ccb->goep_handle = 0;
/* report connection closed event */ /* report connection closed event */
@@ -763,6 +783,7 @@ void bta_pba_client_goep_disconnect(tBTA_PBA_CLIENT_CCB *p_ccb, tBTA_PBA_CLIENT_
conn.handle = p_ccb->allocated; conn.handle = p_ccb->allocated;
bdcpy(conn.bd_addr, p_ccb->bd_addr); bdcpy(conn.bd_addr, p_ccb->bd_addr);
conn.error = BTA_PBA_CLIENT_GOEP_ERROR; conn.error = BTA_PBA_CLIENT_GOEP_ERROR;
bta_pba_client_pm_conn_close(p_ccb);
free_ccb(p_ccb); free_ccb(p_ccb);
bta_pba_client_cb.p_cback(BTA_PBA_CLIENT_CONN_CLOSE_EVT, (tBTA_PBA_CLIENT *)&conn); bta_pba_client_cb.p_cback(BTA_PBA_CLIENT_CONN_CLOSE_EVT, (tBTA_PBA_CLIENT *)&conn);
} }
@@ -127,6 +127,7 @@ typedef struct {
UINT16 max_rx; /* max rx bytes */ UINT16 max_rx; /* max rx bytes */
UINT16 max_tx; /* max tx bytes */ UINT16 max_tx; /* max tx bytes */
BOOLEAN authenticate; /* whether we are authenticated */ BOOLEAN authenticate; /* whether we are authenticated */
BOOLEAN pm_open; /* TRUE after bta_sys_conn_open until conn_close */
tBTA_PBA_CLIENT_OP operation; /* ongoing or last operations */ tBTA_PBA_CLIENT_OP operation; /* ongoing or last operations */
UINT8 state; /* main state machine */ UINT8 state; /* main state machine */
UINT8 allocated; /* index + 1 if allocated, otherwise 0 */ UINT8 allocated; /* index + 1 if allocated, otherwise 0 */