From f7e768338003d28ebfa2eb9816d5229e7f81e0e6 Mon Sep 17 00:00:00 2001 From: linruihao Date: Fri, 4 Sep 2026 10:23:13 +0800 Subject: [PATCH] fix(bt/bluedroid): enable sniff power management for PBAP client --- .../bt/host/bluedroid/bta/dm/bta_dm_cfg.c | 17 ++++++++++++--- .../bluedroid/bta/pba/bta_pba_client_act.c | 21 +++++++++++++++++++ .../bta/pba/include/bta_pba_client_int.h | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_cfg.c b/components/bt/host/bluedroid/bta/dm/bta_dm_cfg.c index 81bbd4667f8..40435d81d14 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_cfg.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_cfg.c @@ -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; #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 */ #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 */ #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) 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_GATTS, BTA_ALL_APP_ID, 9} /* gatts spec table */ #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 */ @@ -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 */ #if (BTM_SSR_INCLUDED == TRUE) diff --git a/components/bt/host/bluedroid/bta/pba/bta_pba_client_act.c b/components/bt/host/bluedroid/bta/pba/bta_pba_client_act.c index 82b000b99de..a94f6603152 100644 --- a/components/bt/host/bluedroid/bta/pba/bta_pba_client_act.c +++ b/components/bt/host/bluedroid/bta/pba/bta_pba_client_act.c @@ -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_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) { 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; bdcpy(conn.bd_addr, p_ccb->bd_addr); + bta_pba_client_pm_conn_close(p_ccb); + /* free 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) { goto error; } + bta_sys_busy(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr); return; 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) { 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.peer_supported_repo = p_ccb->peer_supported_repo; 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); p_data->goep_response.pkt = NULL; + bta_sys_idle(BTA_ID_PBC, p_ccb->allocated, p_ccb->bd_addr); return; } /* 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); osi_free(p_data->goep_response.pkt); 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 */ } @@ -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); } 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) { /* 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) { + UNUSED(p_data); p_ccb->goep_handle = 0; /* 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; bdcpy(conn.bd_addr, p_ccb->bd_addr); conn.error = BTA_PBA_CLIENT_GOEP_ERROR; + bta_pba_client_pm_conn_close(p_ccb); free_ccb(p_ccb); bta_pba_client_cb.p_cback(BTA_PBA_CLIENT_CONN_CLOSE_EVT, (tBTA_PBA_CLIENT *)&conn); } diff --git a/components/bt/host/bluedroid/bta/pba/include/bta_pba_client_int.h b/components/bt/host/bluedroid/bta/pba/include/bta_pba_client_int.h index 7ef99554626..6827bcaee88 100644 --- a/components/bt/host/bluedroid/bta/pba/include/bta_pba_client_int.h +++ b/components/bt/host/bluedroid/bta/pba/include/bta_pba_client_int.h @@ -127,6 +127,7 @@ typedef struct { UINT16 max_rx; /* max rx bytes */ UINT16 max_tx; /* max tx bytes */ 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 */ UINT8 state; /* main state machine */ UINT8 allocated; /* index + 1 if allocated, otherwise 0 */