From: Inga Stotland <inga.stotland@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@gmail.com, brian.gix@intel.com,
Inga Stotland <inga.stotland@gmail.com>
Subject: [PATCH BlueZ v2 1/2] tools/mesh-cfgclient: Prevent storing duplicate models
Date: Thu, 16 Mar 2023 14:33:11 -0700 [thread overview]
Message-ID: <20230316213312.159370-1-inga.stotland@gmail.com> (raw)
This fixes the situation when subsequent requests to get a node
composition result in appending element's model list with duplicate models.
This adds a check for a presence of a model on an element when attempting
to add a new model ID to a model list on this element.
---
tools/mesh/mesh-db.c | 17 ++++++++++++-----
tools/mesh/remote.c | 9 +++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c
index c0c05a29a..1d047691d 100644
--- a/tools/mesh/mesh-db.c
+++ b/tools/mesh/mesh-db.c
@@ -1964,28 +1964,35 @@ bool mesh_db_node_set_composition(uint16_t unicast, uint8_t *data, uint16_t len)
while (len >= 2 && m--) {
mod_id = l_get_le16(data);
+ data += 2;
+ len -= 2;
+
+ jobj = get_model(unicast, unicast + i, mod_id, false);
+ if (jobj)
+ continue;
jobj = init_model(mod_id);
if (!jobj)
goto fail;
json_object_array_add(jmods, jobj);
- data += 2;
- len -= 2;
}
while (len >= 4 && v--) {
mod_id = l_get_le16(data + 2);
mod_id = l_get_le16(data) << 16 | mod_id;
+ data += 4;
+ len -= 4;
+
+ jobj = get_model(unicast, unicast + i, mod_id, true);
+ if (jobj)
+ continue;
jobj = init_vendor_model(mod_id);
if (!jobj)
goto fail;
json_object_array_add(jmods, jobj);
-
- data += 4;
- len -= 4;
}
i++;
diff --git a/tools/mesh/remote.c b/tools/mesh/remote.c
index cee711dec..b917ae9df 100644
--- a/tools/mesh/remote.c
+++ b/tools/mesh/remote.c
@@ -54,6 +54,11 @@ struct rejected_addr {
static struct l_queue *nodes;
static struct l_queue *reject_list;
+static bool match_mod_id(const void *a, const void *b)
+{
+ return a == b;
+}
+
static int compare_mod_id(const void *a, const void *b, void *user_data)
{
uint32_t id1 = L_PTR_TO_UINT(a);
@@ -227,6 +232,10 @@ bool remote_set_model(uint16_t unicast, uint8_t ele_idx, uint32_t mod_id,
if (!vendor)
mod_id = VENDOR_ID_MASK | mod_id;
+ if (l_queue_find(rmt->els[ele_idx], match_mod_id,
+ L_UINT_TO_PTR(mod_id)))
+ return true;
+
l_queue_insert(rmt->els[ele_idx], L_UINT_TO_PTR(mod_id),
compare_mod_id, NULL);
--
2.39.2
next reply other threads:[~2023-03-16 21:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 21:33 Inga Stotland [this message]
2023-03-16 21:33 ` [PATCH BlueZ v2 2/2] tools/mesh-cfgclient: Auto request own composition data Inga Stotland
2023-03-16 23:24 ` [BlueZ,v2,1/2] tools/mesh-cfgclient: Prevent storing duplicate models bluez.test.bot
2023-03-17 20:30 ` [PATCH BlueZ v2 1/2] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230316213312.159370-1-inga.stotland@gmail.com \
--to=inga.stotland@gmail.com \
--cc=brian.gix@gmail.com \
--cc=brian.gix@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox