ble_mesh: stack: Fix exceptional list parameters check issue

This commit is contained in:
wangjialiang 2022-10-28 16:22:43 +08:00
parent 6688ba7b8e
commit 9d79c71498
8 changed files with 52 additions and 50 deletions

View File

@ -1959,17 +1959,20 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
} }
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
int bt_mesh_update_exceptional_list(uint8_t sub_code, uint8_t type, void *info) int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
{ {
BD_ADDR value = {0}; BD_ADDR value = {0};
if ((sub_code > BLE_MESH_EXCEP_LIST_CLEAN) || if ((sub_code > BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN) ||
(type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) { (sub_code < BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
type > BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV) ||
(sub_code == BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
!(type & BLE_MESH_EXCEP_LIST_CLEAN_ALL_LIST))) {
BT_ERR("%s, Invalid parameter", __func__); BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL; return -EINVAL;
} }
if (type == BLE_MESH_EXCEP_INFO_MESH_LINK_ID) { if (type == BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID) {
if (!info) { if (!info) {
BT_ERR("Invalid Provisioning Link ID"); BT_ERR("Invalid Provisioning Link ID");
return -EINVAL; return -EINVAL;
@ -1977,7 +1980,7 @@ int bt_mesh_update_exceptional_list(uint8_t sub_code, uint8_t type, void *info)
sys_memcpy_swap(value, info, sizeof(uint32_t)); sys_memcpy_swap(value, info, sizeof(uint32_t));
} }
BT_DBG("%s exceptional list, type 0x%02x", sub_code ? "Remove" : "Add", type); BT_DBG("%s exceptional list, type 0x%08x", sub_code ? "Remove" : "Add", type);
/* The parameter "device_info" can't be NULL in the API */ /* The parameter "device_info" can't be NULL in the API */
BLE_MESH_BTM_CHECK_STATUS(BTM_UpdateBleDuplicateExceptionalList(sub_code, type, value, NULL)); BLE_MESH_BTM_CHECK_STATUS(BTM_UpdateBleDuplicateExceptionalList(sub_code, type, value, NULL));

View File

@ -776,29 +776,28 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]); uint8_t enc_data[16]);
enum { enum {
BLE_MESH_EXCEP_LIST_ADD = 0, BLE_MESH_EXCEP_LIST_SUB_CODE_ADD = 0,
BLE_MESH_EXCEP_LIST_REMOVE, BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_LIST_CLEAN, BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN,
}; };
enum { enum {
BLE_MESH_EXCEP_INFO_ADV_ADDR = 0, BLE_MESH_EXCEP_LIST_TYPE_ADV_ADDR = 0,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID,
BLE_MESH_EXCEP_INFO_MESH_BEACON, BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON,
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV,
BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV,
}; };
enum { #define BLE_MESH_EXCEP_LIST_CLEAN_ADDR_LIST BIT(0)
BLE_MESH_EXCEP_CLEAN_ADDR_LIST = BIT(0), #define BLE_MESH_EXCEP_LIST_CLEAN_MESH_LINK_ID_LIST BIT(1)
BLE_MESH_EXCEP_CLEAN_MESH_LINK_ID_LIST = BIT(1), #define BLE_MESH_EXCEP_LIST_CLEAN_MESH_BEACON_LIST BIT(2)
BLE_MESH_EXCEP_CLEAN_MESH_BEACON_LIST = BIT(2), #define BLE_MESH_EXCEP_LIST_CLEAN_MESH_PROV_ADV_LIST BIT(3)
BLE_MESH_EXCEP_CLEAN_MESH_PROV_ADV_LIST = BIT(3), #define BLE_MESH_EXCEP_LIST_CLEAN_MESH_PROXY_ADV_LIST BIT(4)
BLE_MESH_EXCEP_CLEAN_MESH_PROXY_ADV_LIST = BIT(4), #define BLE_MESH_EXCEP_LIST_CLEAN_ALL_LIST (BIT(0) | BIT(1) | \
BLE_MESH_EXCEP_CLEAN_ALL_LIST = 0xFFFF, BIT(2) | BIT(3) | BIT(4))
};
int bt_mesh_update_exceptional_list(uint8_t sub_code, uint8_t type, void *info); int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -613,14 +613,14 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
(bearers & BLE_MESH_PROV_ADV)) { (bearers & BLE_MESH_PROV_ADV)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON, NULL);
} }
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
(bearers & BLE_MESH_PROV_GATT)) { (bearers & BLE_MESH_PROV_GATT)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV, NULL);
} }
#endif #endif
@ -668,8 +668,8 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
(bearers & BLE_MESH_PROV_GATT)) { (bearers & BLE_MESH_PROV_GATT)) {
bt_mesh_proxy_client_prov_disable(); bt_mesh_proxy_client_prov_disable();
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV, NULL);
#endif #endif
} }
@ -680,8 +680,8 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
(enable & BLE_MESH_PROV_ADV)) { (enable & BLE_MESH_PROV_ADV)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON, NULL);
} }
#endif #endif

View File

@ -1550,8 +1550,8 @@ void bt_mesh_net_start(void)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add Mesh beacon type (Secure Network Beacon) to the exceptional list */ /* Add Mesh beacon type (Secure Network Beacon) to the exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON, NULL);
#endif #endif
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) {

View File

@ -311,8 +311,8 @@ static void reset_adv_link(void)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Remove the link id from exceptional list */ /* Remove the link id from exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link.id);
#endif #endif
reset_state(); reset_state();
@ -1380,8 +1380,8 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add the link id into exceptional list */ /* Add the link id into exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link.id);
#endif #endif
bearer_ctl_send(LINK_ACK, NULL, 0); bearer_ctl_send(LINK_ACK, NULL, 0);
@ -1837,8 +1837,8 @@ int bt_mesh_prov_deinit(void)
k_delayed_work_free(&link.tx.retransmit); k_delayed_work_free(&link.tx.retransmit);
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Remove the link id from exceptional list */ /* Remove the link id from exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link.id);
#endif /* CONFIG_BLE_MESH_USE_DUPLICATE_SCAN */ #endif /* CONFIG_BLE_MESH_USE_DUPLICATE_SCAN */
#endif /* CONFIG_BLE_MESH_PB_ADV */ #endif /* CONFIG_BLE_MESH_PB_ADV */

View File

@ -1318,8 +1318,8 @@ static void reset_link(const uint8_t idx, uint8_t reason)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Remove the link id from exceptional list */ /* Remove the link id from exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link[idx].link_id);
#endif #endif
/* Clear everything except the retransmit delayed work config */ /* Clear everything except the retransmit delayed work config */
@ -1478,8 +1478,8 @@ static void send_link_open(const uint8_t idx)
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
/* Add the link id into exceptional list */ /* Add the link id into exceptional list */
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[idx].link_id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link[idx].link_id);
#endif #endif
bearer_ctl_send(idx, LINK_OPEN, link[idx].uuid, 16); bearer_ctl_send(idx, LINK_OPEN, link[idx].uuid, 16);
@ -3338,8 +3338,8 @@ int bt_mesh_provisioner_prov_reset(bool erase)
#if CONFIG_BLE_MESH_PB_ADV #if CONFIG_BLE_MESH_PB_ADV
prov_clear_tx(i); prov_clear_tx(i);
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN #if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[i].link_id); BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID, &link[i].link_id);
#endif #endif
memset(&link[i], 0, offsetof(struct prov_link, tx.retransmit)); memset(&link[i], 0, offsetof(struct prov_link, tx.retransmit));
link[i].pending_ack = XACT_NVAL; link[i].pending_ack = XACT_NVAL;

View File

@ -983,8 +983,8 @@ int bt_mesh_proxy_client_init(void)
bt_mesh_gattc_conn_cb_register(&conn_callbacks); bt_mesh_gattc_conn_cb_register(&conn_callbacks);
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN && CONFIG_BLE_MESH_GATT_PROXY_CLIENT #if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN && CONFIG_BLE_MESH_GATT_PROXY_CLIENT
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, NULL); BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV, NULL);
#endif #endif
return 0; return 0;

View File

@ -696,7 +696,7 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
int ble_mesh_exceptional_list_test(int argc, char **argv) int ble_mesh_exceptional_list_test(int argc, char **argv)
{ {
esp_err_t err = ESP_FAIL; esp_err_t err = ESP_FAIL;
uint32_t type = BLE_MESH_EXCEP_INFO_MESH_BEACON; uint32_t type = BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON;
uint8_t *info = NULL; uint8_t *info = NULL;
int nerrors = arg_parse(argc, argv, (void **) &exceptional_list_test); int nerrors = arg_parse(argc, argv, (void **) &exceptional_list_test);
@ -718,11 +718,11 @@ int ble_mesh_exceptional_list_test(int argc, char **argv)
} }
if (strcmp(exceptional_list_test.action_type->sval[0], "add") == 0) { if (strcmp(exceptional_list_test.action_type->sval[0], "add") == 0) {
err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, type, info); err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD, type, info);
} else if (strcmp(exceptional_list_test.action_type->sval[0], "remove") == 0) { } else if (strcmp(exceptional_list_test.action_type->sval[0], "remove") == 0) {
err = bt_mesh_update_exceptional_list( BLE_MESH_EXCEP_LIST_REMOVE, type, info); err = bt_mesh_update_exceptional_list( BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE, type, info);
} else if (strcmp(exceptional_list_test.action_type->sval[0], "clean") == 0) { } else if (strcmp(exceptional_list_test.action_type->sval[0], "clean") == 0) {
err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_CLEAN, type, NULL); err = bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN, type, NULL);
} }
if (err == ESP_OK) { if (err == ESP_OK) {