From 0578c3a1267f6e00cd7d50c5553639bffa135999 Mon Sep 17 00:00:00 2001 From: wangjialiang Date: Tue, 27 Jul 2021 16:28:24 +0800 Subject: [PATCH 1/2] ble_mesh: stack: Fix heartbeat filter with accept list --- .../esp_ble_mesh/mesh_core/provisioner_main.c | 114 +++++++++--------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index 4b35f45377..33b431e432 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -1691,55 +1691,65 @@ int bt_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, uint16_t src, uint } } -static bool filter_with_rejectlist(struct heartbeat_filter *filter, - uint16_t hb_src, uint16_t hb_dst) +static bool filter_with_rejectlist(uint16_t hb_src, uint16_t hb_dst) { - switch (filter->type) { - case HEARTBEAT_FILTER_WITH_SRC: - if (hb_src == filter->src) { - return true; + int i; + + for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) { + struct heartbeat_filter *filter = &hb_rx.filter[i]; + + switch (filter->type) { + case HEARTBEAT_FILTER_WITH_SRC: + if (hb_src == filter->src) { + return true; + } + break; + case HEARTBEAT_FILTER_WITH_DST: + if (hb_dst == filter->dst) { + return true; + } + break; + case HEARTBEAT_FILTER_WITH_BOTH: + if (hb_src == filter->src && hb_dst == filter->dst) { + return true; + } + break; + default: + BT_DBG("Unknown filter addr type 0x%02x", filter->type); + break; } - break; - case HEARTBEAT_FILTER_WITH_DST: - if (hb_dst == filter->dst) { - return true; - } - break; - case HEARTBEAT_FILTER_WITH_BOTH: - if (hb_src == filter->src && hb_dst == filter->dst) { - return true; - } - break; - default: - BT_WARN("Unknown filter addr type 0x%02x", filter->type); - break; } return false; } -static bool filter_with_acceptlist(struct heartbeat_filter *filter, - uint16_t hb_src, uint16_t hb_dst) +static bool filter_with_acceptlist(uint16_t hb_src, uint16_t hb_dst) { - switch (filter->type) { - case HEARTBEAT_FILTER_WITH_SRC: - if (hb_src == filter->src) { - return false; + int i; + + for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) { + struct heartbeat_filter *filter = &hb_rx.filter[i]; + + switch (filter->type) { + case HEARTBEAT_FILTER_WITH_SRC: + if (hb_src == filter->src) { + return false; + } + break; + case HEARTBEAT_FILTER_WITH_DST: + if (hb_dst == filter->dst) { + return false; + } + break; + case HEARTBEAT_FILTER_WITH_BOTH: + if (hb_src == filter->src && hb_dst == filter->dst) { + return false; + } + break; + default: + BT_DBG("Unknown filter addr type 0x%02x", filter->type); + break; } - break; - case HEARTBEAT_FILTER_WITH_DST: - if (hb_dst == filter->dst) { - return false; - } - break; - case HEARTBEAT_FILTER_WITH_BOTH: - if (hb_src == filter->src && hb_dst == filter->dst) { - return false; - } - break; - default: - BT_WARN("Unknown filter addr type 0x%02x", filter->type); - return false; } return true; @@ -1749,26 +1759,20 @@ void bt_mesh_provisioner_heartbeat(uint16_t hb_src, uint16_t hb_dst, uint8_t init_ttl, uint8_t rx_ttl, uint8_t hops, uint16_t feat, int8_t rssi) { - int i; - if (hb_rx.cb == NULL) { BT_DBG("Receiving heartbeat is not enabled"); 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 (filter_with_rejectlist(filter, hb_src, hb_dst)) { - BT_DBG("Filtered by rejectlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); - return; - } - } else { - if (filter_with_acceptlist(filter, hb_src, hb_dst)) { - BT_DBG("Filtered by acceptlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); - return; - } + if (hb_rx.type == HEARTBEAT_FILTER_REJECTLIST) { + if (filter_with_rejectlist(hb_src, hb_dst)) { + BT_INFO("Filtered by rejectlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); + return; + } + } else { + if (filter_with_acceptlist(hb_src, hb_dst)) { + BT_INFO("Filtered by acceptlist, src 0x%04x, dst 0x%04x", hb_src, hb_dst); + return; } } From fc97277e2f437c16cfcbc530dda7b65ec0f24324 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 22 Oct 2021 16:11:53 +0800 Subject: [PATCH 2/2] ble_mesh: stack: Update the license of provisioner_main.c --- .../esp_ble_mesh/mesh_core/provisioner_main.c | 18 +++++------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index 33b431e432..3fea8e9b84 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -1,16 +1,8 @@ -// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// 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. +/* + * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 3f07224b50..f722b0e364 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -206,7 +206,6 @@ components/bt/esp_ble_mesh/mesh_core/net.h components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c components/bt/esp_ble_mesh/mesh_core/prov.c components/bt/esp_ble_mesh/mesh_core/prov.h -components/bt/esp_ble_mesh/mesh_core/provisioner_main.c components/bt/esp_ble_mesh/mesh_core/provisioner_main.h components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h