Skip to content

Commit ab48bfb

Browse files
committed
ble_mesh: stack: Update the heartbeat filter entry add/remove handling
1 parent 7534dac commit ab48bfb

File tree

1 file changed

+12
-70
lines changed

1 file changed

+12
-70
lines changed

components/bt/esp_ble_mesh/mesh_core/provisioner_main.c

Lines changed: 12 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,13 +1547,8 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
15471547
#define HEARTBEAT_FILTER_ADD 0x00
15481548
#define HEARTBEAT_FILTER_REMOVE 0x01
15491549

1550-
#define HEARTBEAT_FILTER_WITH_SRC BIT(0)
1551-
#define HEARTBEAT_FILTER_WITH_DST BIT(1)
1552-
#define HEARTBEAT_FILTER_WITH_BOTH (BIT(1) | BIT(0))
1553-
15541550
static struct heartbeat_recv {
15551551
struct heartbeat_filter {
1556-
uint8_t type; /* Indicate if using src or dst or both to filter heartbeat messages */
15571552
uint16_t src; /* Heartbeat source address (unicast address) */
15581553
uint16_t dst; /* Heartbeat destination address (unicast address or group address) */
15591554
} filter[CONFIG_BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE];
@@ -1590,19 +1585,6 @@ int bt_mesh_provisioner_set_heartbeat_filter_type(uint8_t type)
15901585
return 0;
15911586
}
15921587

1593-
static inline uint8_t get_filter_addr_type(uint16_t src, uint16_t dst)
1594-
{
1595-
if (BLE_MESH_ADDR_IS_UNICAST(src)) {
1596-
if (BLE_MESH_ADDR_IS_UNICAST(dst) || BLE_MESH_ADDR_IS_GROUP(dst)) {
1597-
return HEARTBEAT_FILTER_WITH_BOTH;
1598-
} else {
1599-
return HEARTBEAT_FILTER_WITH_SRC;
1600-
}
1601-
} else {
1602-
return HEARTBEAT_FILTER_WITH_DST;
1603-
}
1604-
}
1605-
16061588
static int hb_filter_alloc(uint16_t src, uint16_t dst)
16071589
{
16081590
int i;
@@ -1612,7 +1594,6 @@ static int hb_filter_alloc(uint16_t src, uint16_t dst)
16121594

16131595
if (filter->src == BLE_MESH_ADDR_UNASSIGNED &&
16141596
filter->dst == BLE_MESH_ADDR_UNASSIGNED) {
1615-
filter->type = get_filter_addr_type(src, dst);
16161597
filter->src = src;
16171598
filter->dst = dst;
16181599
return 0;
@@ -1627,8 +1608,8 @@ static int hb_filter_add(uint16_t src, uint16_t dst)
16271608
{
16281609
int i;
16291610

1630-
if (!BLE_MESH_ADDR_IS_UNICAST(src) &&
1631-
!BLE_MESH_ADDR_IS_UNICAST(dst) && !BLE_MESH_ADDR_IS_GROUP(dst)) {
1611+
if (!(BLE_MESH_ADDR_IS_UNICAST(src) &&
1612+
(BLE_MESH_ADDR_IS_UNICAST(dst) || BLE_MESH_ADDR_IS_GROUP(dst)))) {
16321613
BT_ERR("Invalid filter address, src 0x%04x, dst 0x%04x", src, dst);
16331614
return -EINVAL;
16341615
}
@@ -1637,10 +1618,9 @@ static int hb_filter_add(uint16_t src, uint16_t dst)
16371618
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
16381619
struct heartbeat_filter *filter = &hb_rx.filter[i];
16391620

1640-
if ((BLE_MESH_ADDR_IS_UNICAST(src) && filter->src == src) ||
1641-
((BLE_MESH_ADDR_IS_UNICAST(dst) || BLE_MESH_ADDR_IS_GROUP(dst)) &&
1642-
filter->dst == dst)) {
1643-
memset(filter, 0, sizeof(struct heartbeat_filter));
1621+
if (filter->src == src && filter->dst == dst) {
1622+
BT_WARN("Filter already exists, src 0x%04x dst 0x%04x", filter->src, filter->dst);
1623+
return 0;
16441624
}
16451625
}
16461626

@@ -1651,18 +1631,16 @@ static int hb_filter_remove(uint16_t src, uint16_t dst)
16511631
{
16521632
int i;
16531633

1654-
if (!BLE_MESH_ADDR_IS_UNICAST(src) &&
1655-
!BLE_MESH_ADDR_IS_UNICAST(dst) && !BLE_MESH_ADDR_IS_GROUP(dst)) {
1634+
if (!(BLE_MESH_ADDR_IS_UNICAST(src) &&
1635+
(BLE_MESH_ADDR_IS_UNICAST(dst) || BLE_MESH_ADDR_IS_GROUP(dst)))) {
16561636
BT_ERR("Invalid filter address, src 0x%04x, dst 0x%04x", src, dst);
16571637
return -EINVAL;
16581638
}
16591639

16601640
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
16611641
struct heartbeat_filter *filter = &hb_rx.filter[i];
16621642

1663-
if ((BLE_MESH_ADDR_IS_UNICAST(src) && filter->src == src) ||
1664-
((BLE_MESH_ADDR_IS_UNICAST(dst) || BLE_MESH_ADDR_IS_GROUP(dst)) &&
1665-
filter->dst == dst)) {
1643+
if (filter->src == src && filter->dst == dst) {
16661644
memset(filter, 0, sizeof(struct heartbeat_filter));
16671645
}
16681646
}
@@ -1689,26 +1667,8 @@ static bool filter_with_rejectlist(uint16_t hb_src, uint16_t hb_dst)
16891667

16901668
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
16911669
struct heartbeat_filter *filter = &hb_rx.filter[i];
1692-
1693-
switch (filter->type) {
1694-
case HEARTBEAT_FILTER_WITH_SRC:
1695-
if (hb_src == filter->src) {
1696-
return true;
1697-
}
1698-
break;
1699-
case HEARTBEAT_FILTER_WITH_DST:
1700-
if (hb_dst == filter->dst) {
1701-
return true;
1702-
}
1703-
break;
1704-
case HEARTBEAT_FILTER_WITH_BOTH:
1705-
if (hb_src == filter->src && hb_dst == filter->dst) {
1706-
return true;
1707-
}
1708-
break;
1709-
default:
1710-
BT_DBG("Unknown filter addr type 0x%02x", filter->type);
1711-
break;
1670+
if (hb_src == filter->src && hb_dst == filter->dst) {
1671+
return true;
17121672
}
17131673
}
17141674

@@ -1721,26 +1681,8 @@ static bool filter_with_acceptlist(uint16_t hb_src, uint16_t hb_dst)
17211681

17221682
for (i = 0; i < ARRAY_SIZE(hb_rx.filter); i++) {
17231683
struct heartbeat_filter *filter = &hb_rx.filter[i];
1724-
1725-
switch (filter->type) {
1726-
case HEARTBEAT_FILTER_WITH_SRC:
1727-
if (hb_src == filter->src) {
1728-
return false;
1729-
}
1730-
break;
1731-
case HEARTBEAT_FILTER_WITH_DST:
1732-
if (hb_dst == filter->dst) {
1733-
return false;
1734-
}
1735-
break;
1736-
case HEARTBEAT_FILTER_WITH_BOTH:
1737-
if (hb_src == filter->src && hb_dst == filter->dst) {
1738-
return false;
1739-
}
1740-
break;
1741-
default:
1742-
BT_DBG("Unknown filter addr type 0x%02x", filter->type);
1743-
break;
1684+
if (hb_src == filter->src && hb_dst == filter->dst) {
1685+
return false;
17441686
}
17451687
}
17461688

0 commit comments

Comments
 (0)