[PATCH 2/6] tools/mesh: Fix status messages processing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Daniele <dbiagio@xxxxxxxxxx>

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/node.c        | 11 +++++++++++
 tools/mesh/onoff-model.c | 19 ++++++++++++-------
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/tools/mesh/node.c b/tools/mesh/node.c
index d23315ce4..3171ef01a 100644
--- a/tools/mesh/node.c
+++ b/tools/mesh/node.c
@@ -475,6 +475,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;
@@ -487,6 +489,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/onoff-model.c b/tools/mesh/onoff-model.c
index 6236e1fea..a6baeb0c5 100644
--- a/tools/mesh/onoff-model.c
+++ b/tools/mesh/onoff-model.c
@@ -111,6 +111,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;
@@ -127,18 +128,22 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
 		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");
-
+		sprintf(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");
+			sprintf(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.20.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux