All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniele Biagetti <dbiagio79@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Daniele Biagetti <daniele.biagetti@cblelectronics.com>
Subject: [PATCH BlueZ 2/6] tools/mesh-gatt: Fix status messages processing
Date: Tue,  7 Dec 2021 23:56:00 +0100	[thread overview]
Message-ID: <20211207225604.35156-3-daniele.biagetti@cblelectronics.com> (raw)
In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com>

The status messages was processed and displayed even if they do
not belong to the present model. This fix ensure that the status
messages are processed only if they have the correct opcode.
---
 tools/mesh-gatt/node.c        | 11 +++++++++++
 tools/mesh-gatt/onoff-model.c | 23 ++++++++++++-----------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/tools/mesh-gatt/node.c b/tools/mesh-gatt/node.c
index 356e1cd1a..4d0cc21e9 100644
--- a/tools/mesh-gatt/node.c
+++ b/tools/mesh-gatt/node.c
@@ -470,6 +470,8 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src,
 				uint16_t app_idx, uint8_t *data, uint16_t len)
 {
 	GList *l;
+	uint32_t opcode;
+	int n;
 
 	for(l = element->models; l; l = l->next) {
 		struct mesh_model *model = l->data;
@@ -482,6 +484,15 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src,
 			return true;
 	}
 
+	if (mesh_opcode_get(data, len, &opcode, &n)) {
+		len -= n;
+		data += n;
+	} else
+		return false;
+	bt_shell_printf("Unknown Model Message received (%d) opcode %x\n",
+						len, opcode);
+	print_byte_array("\t",data, len);
+
 	return false;
 }
 
diff --git a/tools/mesh-gatt/onoff-model.c b/tools/mesh-gatt/onoff-model.c
index 13ff4bbe3..1c9676e03 100644
--- a/tools/mesh-gatt/onoff-model.c
+++ b/tools/mesh-gatt/onoff-model.c
@@ -99,6 +99,7 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
 {
 	uint32_t opcode;
 	int n;
+	char s[128];
 
 	if (mesh_opcode_get(data, len, &opcode, &n)) {
 		len -= n;
@@ -106,27 +107,27 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
 	} else
 		return false;
 
-	bt_shell_printf("On Off Model Message received (%d) opcode %x\n",
-								len, opcode);
-	print_byte_array("\t",data, len);
-
 	switch (opcode) {
 	default:
 		return false;
 
 	case OP_GENERIC_ONOFF_STATUS:
+		bt_shell_printf("On Off Model Message received (%d) opcode %x\n",
+			len, opcode);
+		print_byte_array("\t",data, len);
 		if (len != 1 && len != 3)
 			break;
 
-		bt_shell_printf("Node %4.4x: Off Status present = %s",
-						src, data[0] ? "ON" : "OFF");
-
+		snprintf(s, sizeof(s), "Node %4.4x: On Off Status present = %s",
+			src, data[0] ? "ON" : "OFF");
 		if (len == 3) {
-			bt_shell_printf(", target = %s",
-					data[1] ? "ON" : "OFF");
+			snprintf(s + strlen(s), sizeof(s), ", target = %s",
+				data[1] ? "ON" : "OFF");
+			bt_shell_printf("%s\n", s);
 			print_remaining_time(data[2]);
-		} else
-			bt_shell_printf("\n");
+		}else
+			bt_shell_printf("%s\n", s);
+
 		break;
 	}
 
-- 
2.25.1


  parent reply	other threads:[~2021-12-07 22:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07 22:55 [PATCH BlueZ 0/6] tools/mesh-gatt meshctl tool improvements Daniele Biagetti
2021-12-07 22:55 ` [PATCH BlueZ 1/6] tools/mesh-gatt: Add onoff set unack message to onoff client model Daniele Biagetti
2021-12-07 23:39   ` tools/mesh-gatt meshctl tool improvements bluez.test.bot
2021-12-07 22:56 ` Daniele Biagetti [this message]
2021-12-07 22:56 ` [PATCH BlueZ 3/6] tools/mesh-gatt: Fix unwanted return in onoff client model Daniele Biagetti
2021-12-07 22:56 ` [PATCH BlueZ 4/6] tools/mesh-gatt: Add subscription delete message to config " Daniele Biagetti
2021-12-07 22:56 ` [PATCH BlueZ 5/6] tools/mesh-gatt: Add generic level model support Daniele Biagetti
2021-12-07 22:56 ` [PATCH BlueZ 6/6] tools/mesh-gatt: Add generic power onoff client model Daniele Biagetti
2021-12-09 20:15 ` [PATCH BlueZ 0/6] tools/mesh-gatt meshctl tool improvements Tedd Ho-Jeong An

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=20211207225604.35156-3-daniele.biagetti@cblelectronics.com \
    --to=dbiagio79@gmail.com \
    --cc=daniele.biagetti@cblelectronics.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.