diff mbox series

[BlueZ,2/6] tools/mesh-gatt: Fix status messages processing

Message ID 20211207225604.35156-3-daniele.biagetti@cblelectronics.com (mailing list archive)
State Changes Requested
Headers show
Series tools/mesh-gatt meshctl tool improvements | expand

Checks

Context Check Description
tedd_an/checkpatch fail [BlueZ,2/6] tools/mesh-gatt: Fix status messages processing ERROR:SPACING: space required after that ',' (ctx:VxV) #112: FILE: tools/mesh-gatt/node.c:494: + print_byte_array("\t",data, len); ^ WARNING:LONG_LINE_STRING: line length of 81 exceeds 80 columns #142: FILE: tools/mesh-gatt/onoff-model.c:115: + bt_shell_printf("On Off Model Message received (%d) opcode %x\n", ERROR:SPACING: space required after that ',' (ctx:VxV) #144: FILE: tools/mesh-gatt/onoff-model.c:117: + print_byte_array("\t",data, len); ^ ERROR:SPACING: space required after that close brace '}' #162: FILE: tools/mesh-gatt/onoff-model.c:128: + }else /github/workspace/src/12662885.patch total: 3 errors, 1 warnings, 68 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/12662885.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint success Gitlint PASS

Commit Message

Daniele Biagetti Dec. 7, 2021, 10:56 p.m. UTC
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 mbox series

Patch

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;
 	}