Skip to content

Commit daa8cfa

Browse files
committed
Merge branch 'bugfix/btdm_fix_stop_adv_no_callback_when_adv_has_been_stoped' into 'master'
Component/bt: fix stop adv no callback when adv has already stoped See merge request !1838
2 parents 4cbc019 + d54e188 commit daa8cfa

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

components/bt/bluedroid/bta/gatt/bta_gattc_act.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
21732173

21742174
cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
21752175
cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start, NULL);
2176-
2176+
//TODO need modify callback if used
21772177
if (p_clreg && p_clreg->p_cback) {
21782178
(*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data);
21792179
}

components/bt/bluedroid/stack/btm/btm_ble_gap.c

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,13 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_s
517517
evt_type = p_cb->scan_rsp ? BTM_BLE_CONNECT_EVT : BTM_BLE_NON_CONNECT_EVT;
518518
}
519519
#endif
520-
520+
// if adv state is BTM_BLE_ADV_PENDING, return immediately
521+
if (p_cb->state == BTM_BLE_ADV_PENDING) {
522+
if (p_stop_adv_cback) {
523+
(*p_stop_adv_cback)(HCI_ERR_ILLEGAL_COMMAND);
524+
}
525+
return BTM_BUSY;
526+
}
521527
if (start && p_cb->adv_mode == BTM_BLE_ADV_DISABLE) {
522528
/* update adv params */
523529
if (!btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min :
@@ -538,17 +544,22 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_s
538544
}
539545

540546
status = btm_ble_start_adv ();
541-
} else if (!start) {
547+
} else if (!start && p_cb->adv_mode == BTM_BLE_ADV_ENABLE) {
542548
//save the stop adv callback to the BTM env.
543549
p_cb->p_stop_adv_cb = p_stop_adv_cback;
544550
status = btm_ble_stop_adv();
545551
#if BLE_PRIVACY_SPT == TRUE
546552
btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE);
547553
#endif
548554
} else {
549-
status = BTM_WRONG_MODE;
550-
BTM_TRACE_ERROR("Can not %s Broadcast, device %s in Broadcast mode",
551-
(start ? "Start" : "Stop"), (start ? "already" : "not"));
555+
/*
556+
1. start adv when adv has already started (not used)
557+
2. stop adv shen adv has already stoped
558+
*/
559+
status = BTM_SUCCESS;
560+
if (p_stop_adv_cback) {
561+
(*p_stop_adv_cback)(status);
562+
}
552563
}
553564
return status;
554565
}
@@ -1217,8 +1228,23 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max,
12171228
}
12181229

12191230
BTM_TRACE_EVENT ("update params for an active adv\n");
1220-
1221-
btm_ble_stop_adv();
1231+
// if adv state is BTM_BLE_ADV_PENDING, return immediately
1232+
if (p_cb->state == BTM_BLE_ADV_PENDING) {
1233+
if (p_cb->p_adv_cb) {
1234+
(*p_cb->p_adv_cb)(HCI_ERR_ILLEGAL_COMMAND);
1235+
}
1236+
return BTM_BUSY;
1237+
}
1238+
/* host will stop adv first and then start adv again if adv has already started
1239+
it will get callback twice.
1240+
*/
1241+
if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) {
1242+
p_cb->adv_callback_twice = TRUE;
1243+
}
1244+
tBTM_STATUS status = btm_ble_stop_adv();
1245+
if (status != BTM_SUCCESS) {
1246+
p_cb->adv_callback_twice = FALSE;
1247+
}
12221248

12231249
/* update adv params */
12241250
btsnd_hcic_ble_write_adv_params (adv_int_min,
@@ -3360,7 +3386,7 @@ tBTM_STATUS btm_ble_start_adv(void)
33603386

33613387
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) {
33623388
p_cb->adv_mode = BTM_BLE_ADV_ENABLE;
3363-
p_cb->state = BTM_BLE_ADVERTISING;
3389+
p_cb->state = BTM_BLE_ADV_PENDING;
33643390
btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type);
33653391
rt = BTM_SUCCESS;
33663392
BTM_TRACE_EVENT ("BTM_SUCCESS\n");
@@ -3389,7 +3415,7 @@ tBTM_STATUS btm_ble_stop_adv(void)
33893415
if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) {
33903416
p_cb->fast_adv_on = FALSE;
33913417
p_cb->adv_mode = BTM_BLE_ADV_DISABLE;
3392-
p_cb->state = BTM_BLE_STOP_ADV;
3418+
p_cb->state = BTM_BLE_ADV_PENDING;
33933419
btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV;
33943420

33953421
/* clear all adv states */
@@ -3563,8 +3589,14 @@ void btm_ble_write_adv_enable_complete(UINT8 *p)
35633589

35643590
// callback to the APP after receive the adv complete from the controller.
35653591
if (p_cb->p_adv_cb && p_cb->adv_mode == BTM_BLE_ADV_ENABLE) {
3566-
(*p_cb->p_adv_cb)(status);
3592+
if (p_cb->adv_callback_twice) {
3593+
p_cb->adv_callback_twice = FALSE;
3594+
}else {
3595+
p_cb->state = BTM_BLE_ADVERTISING;
3596+
(*p_cb->p_adv_cb)(status);
3597+
}
35673598
} else if (p_cb->p_stop_adv_cb && p_cb->adv_mode == BTM_BLE_ADV_DISABLE) {
3599+
p_cb->state = BTM_BLE_STOP_ADV;
35683600
(*p_cb->p_stop_adv_cb)(status);
35693601
}
35703602
/* if write adv enable/disbale not succeed */

components/bt/bluedroid/stack/include/btm_ble_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ typedef struct {
150150
tBTM_START_ADV_CMPL_CBACK *p_adv_cb;
151151
tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cb;
152152
tBLE_ADDR_TYPE adv_addr_type;
153+
BOOLEAN adv_callback_twice;
153154
UINT8 evt_type;
154155
UINT8 adv_mode;
155156
tBLE_BD_ADDR direct_bda;

0 commit comments

Comments
 (0)