host/mesh: Add friend_is_allocated utility
Friend structure allocaction logic is implemented over and over
throughout the friend module. Move it into a static utility function for
readability.
This is port of
@@ -72,6 +72,11 @@ static struct bt_mesh_adv *adv_alloc(int id)
return &adv_pool[id].adv;
}
+static bool friend_is_allocated(const struct bt_mesh_friend *frnd)
+{
+ return frnd->subnet != NULL;
+}
+
static bool is_lpn_unicast(struct bt_mesh_friend *frnd, uint16_t addr)
{
if (frnd->lpn == BT_MESH_ADDR_UNASSIGNED) {
@@ -91,7 +96,7 @@ struct bt_mesh_friend *bt_mesh_friend_find(uint16_t net_idx, uint16_t lpn_addr,
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
- if (valid && !frnd->subnet) {
+ if (valid && !friend_is_allocated(frnd)) {
continue;
}
@@ -193,7 +198,7 @@ void bt_mesh_friends_clear(void)
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
- if (!frnd->subnet) {
+ if (!friend_is_allocated(frnd)) {
continue;
}
@@ -212,7 +217,7 @@ void bt_mesh_friend_sec_update(uint16_t net_idx)
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
- if (!frnd->subnet) {
+ if (!friend_is_allocated(frnd)) {
continue;
}
@@ -548,7 +553,7 @@ static struct os_mbuf *encode_update(struct bt_mesh_friend *frnd, uint8_t md)
struct os_mbuf *sdu = NET_BUF_SIMPLE(1 + sizeof(*upd));
struct os_mbuf *buf;
- __ASSERT_NO_MSG(frnd->subnet);
+ __ASSERT_NO_MSG(friend_is_allocated(frnd));
BT_DBG("lpn 0x%04x md 0x%02x", frnd->lpn, md);
