Merge branch 'bugfix/fix_get_bond_device_list_v4.2' into 'release/v4.2'
bugfix/fix esp_bt_gap_get_bond_device_list bug [backport v4.2] See merge request espressif/esp-idf!9666
This commit is contained in:
commit
15e40f909f
4 changed files with 17 additions and 13 deletions
|
@ -267,6 +267,7 @@ bool config_remove_key(config_t *config, const char *section, const char *key)
|
|||
assert(config != NULL);
|
||||
assert(section != NULL);
|
||||
assert(key != NULL);
|
||||
bool ret;
|
||||
|
||||
section_t *sec = section_find(config, section);
|
||||
entry_t *entry = entry_find(config, section, key);
|
||||
|
@ -274,7 +275,12 @@ bool config_remove_key(config_t *config, const char *section, const char *key)
|
|||
return false;
|
||||
}
|
||||
|
||||
return list_remove(sec->entries, entry);
|
||||
ret = list_remove(sec->entries, entry);
|
||||
if (list_length(sec->entries) == 0) {
|
||||
OSI_TRACE_DEBUG("%s remove section name:%s",__func__, section);
|
||||
ret &= config_remove_section(config, section);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const config_section_node_t *config_section_begin(const config_t *config)
|
||||
|
|
|
@ -246,7 +246,7 @@ esp_err_t esp_bt_gap_remove_bond_device(esp_bd_addr_t bd_addr)
|
|||
int esp_bt_gap_get_bond_device_num(void)
|
||||
{
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_FAIL;
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
return btc_storage_get_num_bt_bond_devices();
|
||||
}
|
||||
|
@ -254,7 +254,6 @@ int esp_bt_gap_get_bond_device_num(void)
|
|||
esp_err_t esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list)
|
||||
{
|
||||
int ret;
|
||||
int dev_num_total;
|
||||
|
||||
if (dev_num == NULL || dev_list == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
|
@ -264,12 +263,7 @@ esp_err_t esp_bt_gap_get_bond_device_list(int *dev_num, esp_bd_addr_t *dev_list)
|
|||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
dev_num_total = btc_storage_get_num_bt_bond_devices();
|
||||
if (*dev_num > dev_num_total) {
|
||||
*dev_num = dev_num_total;
|
||||
}
|
||||
|
||||
ret = btc_storage_get_bonded_bt_devices_list((bt_bdaddr_t *)dev_list, *dev_num);
|
||||
ret = btc_storage_get_bonded_bt_devices_list((bt_bdaddr_t *)dev_list, dev_num);
|
||||
|
||||
return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
|
|
@ -201,7 +201,6 @@ int btc_storage_get_num_bt_bond_devices(void)
|
|||
}
|
||||
}
|
||||
btc_config_unlock();
|
||||
|
||||
return num_dev;
|
||||
}
|
||||
|
||||
|
@ -215,15 +214,17 @@ int btc_storage_get_num_bt_bond_devices(void)
|
|||
** BT_STATUS_FAIL otherwise
|
||||
**
|
||||
*******************************************************************************/
|
||||
bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int dev_num)
|
||||
bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *dev_num)
|
||||
{
|
||||
bt_bdaddr_t bd_addr;
|
||||
int in_dev_num = *dev_num; /* buffer size */
|
||||
int out_dev_num = 0; /* bond_dev size */
|
||||
|
||||
btc_config_lock();
|
||||
for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end();
|
||||
iter = btc_config_section_next(iter)) {
|
||||
|
||||
if (dev_num-- <= 0) {
|
||||
if (in_dev_num <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -236,9 +237,12 @@ bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int de
|
|||
btc_config_exist(name, BTC_STORAGE_LINK_KEY_STR)) {
|
||||
string_to_bdaddr(name, &bd_addr);
|
||||
memcpy(bond_dev, &bd_addr, sizeof(bt_bdaddr_t));
|
||||
in_dev_num--;
|
||||
out_dev_num++;
|
||||
bond_dev++;
|
||||
}
|
||||
}
|
||||
*dev_num = out_dev_num; /* out_dev_num <= in_dev_num */
|
||||
btc_config_unlock();
|
||||
|
||||
return BT_STATUS_SUCCESS;
|
||||
|
|
|
@ -89,6 +89,6 @@ int btc_storage_get_num_bt_bond_devices(void);
|
|||
** BT_STATUS_FAIL otherwise
|
||||
**
|
||||
*******************************************************************************/
|
||||
bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int dev_num);
|
||||
bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *dev_num);
|
||||
|
||||
#endif /* BTC_STORAGE_H */
|
||||
|
|
Loading…
Reference in a new issue