mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'fix/ble_mesh_last_param_oob' into 'master'
fix(ble_mesh): index last_param by inst_type, not controller inst_id See merge request espressif/esp-idf!51478
This commit is contained in:
@@ -146,6 +146,16 @@ static struct bt_mesh_adv_inst adv_insts[] = {
|
|||||||
#endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */
|
#endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum bt_mesh_adv_inst_type bt_mesh_get_adv_inst_idx_by_inst_id(uint8_t inst_id)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < ARRAY_SIZE(adv_insts); i++) {
|
||||||
|
if (adv_insts[i].id == inst_id) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BLE_MESH_ADV_INST_TYPES_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
static struct bt_mesh_adv_inst *find_adv_inst_with_inst_id(uint8_t id)
|
static struct bt_mesh_adv_inst *find_adv_inst_with_inst_id(uint8_t id)
|
||||||
{
|
{
|
||||||
BT_DBG("FindAdvInstWithID, InstID %u", id);
|
BT_DBG("FindAdvInstWithID, InstID %u", id);
|
||||||
|
|||||||
@@ -263,6 +263,8 @@ struct bt_mesh_adv_inst *bt_mesh_get_adv_insts_set(void);
|
|||||||
|
|
||||||
bool bt_mesh_is_adv_inst_used(uint8_t inst_id);
|
bool bt_mesh_is_adv_inst_used(uint8_t inst_id);
|
||||||
|
|
||||||
|
enum bt_mesh_adv_inst_type bt_mesh_get_adv_inst_idx_by_inst_id(uint8_t inst_id);
|
||||||
|
|
||||||
int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id);
|
int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id);
|
||||||
|
|
||||||
int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type);
|
int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "mesh/common.h"
|
#include "mesh/common.h"
|
||||||
#include "prov_pvnr.h"
|
#include "prov_pvnr.h"
|
||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
|
#include "adv_common.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "beacon.h"
|
#include "beacon.h"
|
||||||
#include "btc_ble_mesh_ble.h"
|
#include "btc_ble_mesh_ble.h"
|
||||||
@@ -671,6 +672,13 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
|
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
|
||||||
uint16_t interval = 0U;
|
uint16_t interval = 0U;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
enum bt_mesh_adv_inst_type inst_type =
|
||||||
|
bt_mesh_get_adv_inst_idx_by_inst_id(inst_id);
|
||||||
|
|
||||||
|
if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) {
|
||||||
|
BT_ERR("Invalid adv inst id %u", inst_id);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
assert(param);
|
assert(param);
|
||||||
|
|
||||||
@@ -746,17 +754,17 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
ext_adv_params.interval_min = interval;
|
ext_adv_params.interval_min = interval;
|
||||||
ext_adv_params.interval_max = interval;
|
ext_adv_params.interval_max = interval;
|
||||||
|
|
||||||
if (memcmp(&ext_adv_params, &last_param[inst_id].param, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS))) {
|
if (memcmp(&ext_adv_params, &last_param[inst_type].param, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS))) {
|
||||||
if (last_param[inst_id].set) {
|
if (last_param[inst_type].set) {
|
||||||
BTA_DmBleGapExtAdvSetRemove(inst_id);
|
BTA_DmBleGapExtAdvSetRemove(inst_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_param[inst_id].set = true;
|
last_param[inst_type].set = true;
|
||||||
|
|
||||||
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
|
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
|
||||||
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
|
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
|
||||||
|
|
||||||
memcpy(&last_param[inst_id].param, &ext_adv_params, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
|
memcpy(&last_param[inst_type].param, &ext_adv_params, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
|
||||||
}
|
}
|
||||||
|
|
||||||
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, inst_id, ad, ad_len);
|
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, inst_id, ad, ad_len);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "mesh/common.h"
|
#include "mesh/common.h"
|
||||||
#include "prov_pvnr.h"
|
#include "prov_pvnr.h"
|
||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
|
#include "adv_common.h"
|
||||||
#include "btc_ble_mesh_ble.h"
|
#include "btc_ble_mesh_ble.h"
|
||||||
|
|
||||||
/** @def BT_UUID_MESH_PROV
|
/** @def BT_UUID_MESH_PROV
|
||||||
@@ -1184,6 +1185,13 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
uint16_t interval = 0;
|
uint16_t interval = 0;
|
||||||
uint8_t buf_len = 0;
|
uint8_t buf_len = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
enum bt_mesh_adv_inst_type inst_type =
|
||||||
|
bt_mesh_get_adv_inst_idx_by_inst_id(inst_id);
|
||||||
|
|
||||||
|
if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) {
|
||||||
|
BT_ERR("Invalid adv inst id %u", inst_id);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
err = ble_gap_ext_adv_active(inst_id);
|
err = ble_gap_ext_adv_active(inst_id);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -1310,9 +1318,9 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
adv_params.itvl_min = interval;
|
adv_params.itvl_min = interval;
|
||||||
adv_params.itvl_max = interval;
|
adv_params.itvl_max = interval;
|
||||||
|
|
||||||
if (memcmp(&adv_params, &last_param[inst_id].param,
|
if (memcmp(&adv_params, &last_param[inst_type].param,
|
||||||
sizeof(struct ble_gap_ext_adv_params))) {
|
sizeof(struct ble_gap_ext_adv_params))) {
|
||||||
if (last_param[inst_id].set) {
|
if (last_param[inst_type].set) {
|
||||||
err = ble_gap_ext_adv_remove(inst_id);
|
err = ble_gap_ext_adv_remove(inst_id);
|
||||||
if (err != 0 && err != BLE_HS_EALREADY) {
|
if (err != 0 && err != BLE_HS_EALREADY) {
|
||||||
BT_ERR("Advertising rm failed: err %d", err);
|
BT_ERR("Advertising rm failed: err %d", err);
|
||||||
@@ -1323,7 +1331,7 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_param[inst_id].set = true;
|
last_param[inst_type].set = true;
|
||||||
err = ble_gap_ext_adv_configure(inst_id, &adv_params, NULL, gap_event_cb, NULL);
|
err = ble_gap_ext_adv_configure(inst_id, &adv_params, NULL, gap_event_cb, NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
BT_ERR("Advertising config failed: err %d", err);
|
BT_ERR("Advertising config failed: err %d", err);
|
||||||
@@ -1334,7 +1342,7 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&last_param[inst_id].param, &adv_params, sizeof(struct ble_gap_ext_adv_params));
|
memcpy(&last_param[inst_type].param, &adv_params, sizeof(struct ble_gap_ext_adv_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ble_gap_ext_adv_set_data(inst_id, data);
|
err = ble_gap_ext_adv_set_data(inst_id, data);
|
||||||
|
|||||||
Reference in New Issue
Block a user