Merge branch 'bugfix/heartbeat_filter_with_acceptlist_v4.4' into 'release/v4.4'

ble_mesh: stack: Fix heartbeat filter with accept list (v4.4)

See merge request espressif/esp-idf!15675
This commit is contained in:
liulinyan
2021-11-03 06:21:32 +00:00

View File

@@ -1,16 +1,8 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@@ -1691,9 +1683,13 @@ int bt_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, uint16_t src, uint
} }
} }
static bool filter_with_rejectlist(struct heartbeat_filter *filter, static bool filter_with_rejectlist(uint16_t hb_src, uint16_t hb_dst)
uint16_t hb_src, uint16_t hb_dst)
{ {
int i;
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
struct heartbeat_filter *filter = &hb_rx.filter[i];
switch (filter->type) { switch (filter->type) {
case HEARTBEAT_FILTER_WITH_SRC: case HEARTBEAT_FILTER_WITH_SRC:
if (hb_src == filter->src) { if (hb_src == filter->src) {
@@ -1711,16 +1707,21 @@ static bool filter_with_rejectlist(struct heartbeat_filter *filter,
} }
break; break;
default: default:
BT_WARN("Unknown filter addr type 0x%02x", filter->type); BT_DBG("Unknown filter addr type 0x%02x", filter->type);
break; break;
} }
}
return false; return false;
} }
static bool filter_with_acceptlist(struct heartbeat_filter *filter, static bool filter_with_acceptlist(uint16_t hb_src, uint16_t hb_dst)
uint16_t hb_src, uint16_t hb_dst)
{ {
int i;
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
struct heartbeat_filter *filter = &hb_rx.filter[i];
switch (filter->type) { switch (filter->type) {
case HEARTBEAT_FILTER_WITH_SRC: case HEARTBEAT_FILTER_WITH_SRC:
if (hb_src == filter->src) { if (hb_src == filter->src) {
@@ -1738,8 +1739,9 @@ static bool filter_with_acceptlist(struct heartbeat_filter *filter,
} }
break; break;
default: default:
BT_WARN("Unknown filter addr type 0x%02x", filter->type); BT_DBG("Unknown filter addr type 0x%02x", filter->type);
return false; break;
}
} }
return true; return true;
@@ -1749,28 +1751,22 @@ void bt_mesh_provisioner_heartbeat(uint16_t hb_src, uint16_t hb_dst,
uint8_t init_ttl, uint8_t rx_ttl, uint8_t init_ttl, uint8_t rx_ttl,
uint8_t hops, uint16_t feat, int8_t rssi) uint8_t hops, uint16_t feat, int8_t rssi)
{ {
int i;
if (hb_rx.cb == NULL) { if (hb_rx.cb == NULL) {
BT_DBG("Receiving heartbeat is not enabled"); BT_DBG("Receiving heartbeat is not enabled");
return; return;
} }
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
struct heartbeat_filter *filter = &hb_rx.filter[i];
if (hb_rx.type == HEARTBEAT_FILTER_REJECTLIST) { if (hb_rx.type == HEARTBEAT_FILTER_REJECTLIST) {
if (filter_with_rejectlist(filter, hb_src, hb_dst)) { if (filter_with_rejectlist(hb_src, hb_dst)) {
BT_DBG("Filtered by rejectlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); BT_INFO("Filtered by rejectlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst);
return; return;
} }
} else { } else {
if (filter_with_acceptlist(filter, hb_src, hb_dst)) { if (filter_with_acceptlist(hb_src, hb_dst)) {
BT_DBG("Filtered by acceptlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); BT_INFO("Filtered by acceptlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst);
return; return;
} }
} }
}
if (hb_rx.cb) { if (hb_rx.cb) {
hb_rx.cb(hb_src, hb_dst, init_ttl, rx_ttl, hops, feat, rssi); hb_rx.cb(hb_src, hb_dst, init_ttl, rx_ttl, hops, feat, rssi);