Skip to contentSkip to conversation

Add new commands in btmgmt to support adv monitor

PATCH Superseded Michael Sun 3 participants 9 messages Jun 16, 2020 Bluetooth drivers

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add new commands in btmgmt to support adv monitor

Hi linux-bluetooth,

This series of patches add support for new advertisement monitor mgmt opcodes by introducing new btmgmt commands. The new commands are ‘advmon-features’, ‘advmon-add’, and ‘advmon-remove’. They provide the ability for users to query supported advertisement monitoring features and add/remove monitor filters through btmgmt console.

Michael Sun (3):
btmgmt: Add btmgmt command advmon-features
btmgmt: Add btmgmt command advmon-remove
btmgmt: Add btmgmt command advmon-add

 tools/btmgmt.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 294 insertions(+)
Signature · 1 line
2.27.0.290.gba653c62da-goog
#1 lore raw

PATCH 1/3 btmgmt: Add btmgmt command advmon-features

This patch introduces a new btmgmt command ‘advmon-features’ to help user query for supported advertisement features. The command will work with the new MGMT opcode MGMT_OP_READ_ADV_MONITOR_FEATURES.

---

 tools/btmgmt.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
tools/btmgmt.c +81 -0
index 46e7465b3..1aae7098c 100644
@@ -4567,6 +4567,84 @@ static void cmd_wbs(int argc, char **argv)
 	cmd_setting(MGMT_OP_SET_WIDEBAND_SPEECH, argc, argv);
 }
 
+static const char *advmon_features_str[] = {
+	"Pattern monitor with logic OR.",
+};
+
+static const char *advmon_features2str(uint32_t features)
+{
+	static char str[512];
+	int off, i;
+
+	off = 0;
+	snprintf(str, sizeof(str), "\n\tNone");
+
+	for (i = 0; i < NELEM(advmon_features_str); i++) {
+		if ((features & (1 << i)) != 0 && off < sizeof(str))
+			off += snprintf(str + off, sizeof(str) - off, "\n\t%s",
+						advmon_features_str[i]);
+	}
+
+	return str;
+}
+
+static void advmon_features_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_rp_read_adv_monitor_features *rp = param;
+	uint32_t supported_features, enabled_features;
+	uint16_t num_handles;
+	int i;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Reading adv monitor features failed with status 0x%02x "
+					"(%s)", status, mgmt_errstr(status));
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	if (len < sizeof(*rp)) {
+		error("Too small adv monitor features reply (%u bytes)", len);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	if (len < sizeof(*rp) + rp->num_handles * sizeof(uint16_t)) {
+		error("Handles count (%u) doesn't match reply length (%u)",
+							rp->num_handles, len);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	supported_features = le32_to_cpu(rp->supported_features);
+	enabled_features = le32_to_cpu(rp->enabled_features);
+	num_handles = le16_to_cpu(rp->num_handles);
+
+	print("Supported features:%s", advmon_features2str(supported_features));
+	print("Enabled features:%s", advmon_features2str(enabled_features));
+	print("Max number of handles: %u", le16_to_cpu(rp->max_num_handles));
+	print("Max number of patterns: %u", rp->max_num_patterns);
+	print("Handles list with %u item%s", num_handles,
+			num_handles == 0 ? "" : num_handles == 1 ? ":" : "s:");
+	for (i = 0; i < num_handles; i++) {
+		print("\t0x%04x ", le16_to_cpu(rp->handles[i]));
+	}
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_advmon_features(int argc, char **argv)
+{
+	uint16_t index;
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (!mgmt_send(mgmt, MGMT_OP_READ_ADV_MONITOR_FEATURES, index, 0, NULL,
+					advmon_features_rsp, NULL, NULL)) {
+		error("Unable to send advertising monitor features command");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
 static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 {
 	mgmt_register(mgmt, MGMT_EV_CONTROLLER_ERROR, index, controller_error,
@@ -4776,6 +4854,9 @@ static const struct bt_shell_menu main_menu = {
 		cmd_expinfo,		"Show experimental features"	},
 	{ "exp-debug",		"<on/off>",
 		cmd_exp_debug,		"Set debug feature"		},
+	{ "advmon-features",	NULL,
+		cmd_advmon_features,	"Show advertisement monitor "
+					"features"			},
 	{} },
 };
 
Signature · 1 line
2.27.0.290.gba653c62da-goog
#2 lore raw

RE: [bluez,v1,1/3] btmgmt: Add btmgmt command advmon-features

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
checkpatch Failed

Outputs:
WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const #25: FILE: tools/btmgmt.c:4570:
+static const char *advmon_features_str[] = {

WARNING:BRACES: braces {} are not necessary for single statement blocks #81: FILE: tools/btmgmt.c:4626:
+ for (i = 0; i < num_handles; i++) {
+ print("\t0x%04x ", le16_to_cpu(rp->handles[i]));
+ }

- total: 0 errors, 2 warnings, 93 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.

Your patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Michael Sun

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
checkbuild Failed

Outputs:
ar: u' modifier ignored since D' is the default (see `U')
ar: u' modifier ignored since D' is the default (see `U')
ar: u' modifier ignored since D' is the default (see `U')
ar: u' modifier ignored since D' is the default (see `U')
ar: u' modifier ignored since D' is the default (see `U')
tools/btmgmt.c: In function ‘advmon_features2str’:
tools/btmgmt.c:4608:16: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
4608 | for (i = 0; i < NELEM(advmon_features_str); i++) {
| ^
tools/btmgmt.c:4609:41: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Werror=sign-compare]
4609 | if ((features & (1 << i)) != 0 && off < sizeof(str))
| ^
tools/btmgmt.c: In function ‘str2pattern’:
tools/btmgmt.c:4692:44: error: unused variable ‘length’ [-Werror=unused-variable]
4692 | int type_len, offset_len, offset_end_pos, length, str_len;
| ^~~~~~
tools/btmgmt.c: In function ‘cmd_advmon_add’:
tools/btmgmt.c:4771:12: error: invalid application of ‘sizeof’ to incomplete type ‘struct mgmt_cp_add_adv_patterns_monitor’
4771 | sizeof(struct mgmt_cp_add_adv_patterns_monitor) +

      |            ^~~~~~
tools/btmgmt.c:4776:6: error: dereferencing pointer to incomplete type ‘struct mgmt_cp_add_adv_patterns_monitor’
 4776 |      ->pattern_count = pattern_count;
      |      ^~
tools/btmgmt.c:4799:23: error: ‘MGMT_OP_ADD_ADV_PATTERNS_MONITOR’ undeclared (first use in this function); did you mean ‘MGMT_OP_ADD_ADV_MONITOR’?
 4799 |  if (!mgmt_send(mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, index, cp_len,
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                       MGMT_OP_ADD_ADV_MONITOR

tools/btmgmt.c:4799:23: note: each undeclared identifier is reported only once for each function it appears in tools/btmgmt.c:4744:11: error: unused variable ‘i’ [-Werror=unused-variable]
4744 | int opt, i;
| ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:6791: tools/btmgmt.o] Error 1
make: *** [Makefile:4010: all] Error 2

---
Regards,
Linux Bluetooth

#4 lore raw

Re: [bluez PATCH v1 1/3] btmgmt: Add btmgmt command advmon-features

In reply to Michael Sun

Hi Michael,

Quoted 103 lines · Michael Sun

This patch introduces a new btmgmt command ‘advmon-features’ to help user query for supported advertisement features. The command will work with the new MGMT opcode MGMT_OP_READ_ADV_MONITOR_FEATURES.

---

 tools/btmgmt.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
tools/btmgmt.c +78 -0
index 46e7465b3..1aae7098c 100644
@@ -4567,6 +4567,84 @@ static void cmd_wbs(int argc, char **argv)
        cmd_setting(MGMT_OP_SET_WIDEBAND_SPEECH, argc, argv);
 }
 
+static const char *advmon_features_str[] = {
+       "Pattern monitor with logic OR.",
+};
+
+static const char *advmon_features2str(uint32_t features)
+{
+       static char str[512];
+       int off, i;
+
+       off = 0;
+       snprintf(str, sizeof(str), "\n\tNone");
+
+       for (i = 0; i < NELEM(advmon_features_str); i++) {
+               if ((features & (1 << i)) != 0 && off < sizeof(str))
+                       off += snprintf(str + off, sizeof(str) - off, "\n\t%s",
+                                               advmon_features_str[i]);
+       }
+
+       return str;
+}
+
+static void advmon_features_rsp(uint8_t status, uint16_t len, const void *param,
+                                                       void *user_data)
+{
+       const struct mgmt_rp_read_adv_monitor_features *rp = param;
+       uint32_t supported_features, enabled_features;
+       uint16_t num_handles;
+       int i;
+
+       if (status != MGMT_STATUS_SUCCESS) {
+               error("Reading adv monitor features failed with status 0x%02x "
+                                       "(%s)", status, mgmt_errstr(status));
+               return bt_shell_noninteractive_quit(EXIT_FAILURE);
+       }
+
+       if (len < sizeof(*rp)) {
+               error("Too small adv monitor features reply (%u bytes)", len);
+               return bt_shell_noninteractive_quit(EXIT_FAILURE);
+       }
+
+       if (len < sizeof(*rp) + rp->num_handles * sizeof(uint16_t)) {
+               error("Handles count (%u) doesn't match reply length (%u)",
+                                                       rp->num_handles, len);
+               return bt_shell_noninteractive_quit(EXIT_FAILURE);
+       }
+
+       supported_features = le32_to_cpu(rp->supported_features);
+       enabled_features = le32_to_cpu(rp->enabled_features);
+       num_handles = le16_to_cpu(rp->num_handles);
+
+       print("Supported features:%s", advmon_features2str(supported_features));
+       print("Enabled features:%s", advmon_features2str(enabled_features));
+       print("Max number of handles: %u", le16_to_cpu(rp->max_num_handles));
+       print("Max number of patterns: %u", rp->max_num_patterns);
+       print("Handles list with %u item%s", num_handles,
+                       num_handles == 0 ? "" : num_handles == 1 ? ":" : "s:");
+       for (i = 0; i < num_handles; i++) {
+               print("\t0x%04x ", le16_to_cpu(rp->handles[i]));
+       }
+
+       return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_advmon_features(int argc, char **argv)
+{
+       uint16_t index;
+
+       index = mgmt_index;
+       if (index == MGMT_INDEX_NONE)
+               index = 0;
+
+       if (!mgmt_send(mgmt, MGMT_OP_READ_ADV_MONITOR_FEATURES, index, 0, NULL,
+                                       advmon_features_rsp, NULL, NULL)) {
+               error("Unable to send advertising monitor features command");
+               return bt_shell_noninteractive_quit(EXIT_FAILURE);
+       }
+}
+
 static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 {
        mgmt_register(mgmt, MGMT_EV_CONTROLLER_ERROR, index, controller_error,

tools/btmgmt.c static const struct bt_shell_menu main_menu = { · line 4861

Quoted 8 lines
tools/btmgmt.c +3 -0
@@ -4776,6 +4854,9 @@ static const struct bt_shell_menu main_menu = {
                cmd_expinfo,            "Show experimental features"    },
        { "exp-debug",          "<on/off>",
                cmd_exp_debug,          "Set debug feature"             },
+       { "advmon-features",    NULL,
+               cmd_advmon_features,    "Show advertisement monitor "
+                                       "features"                      },
        {} },
 };

It might be a good idea to organize this as a submenu e.g.

Quoted 2 lines

menu monitor
features

That way we can expand the number of commands for adding/removing monitors without making the list of commands way too big to show in one screen (although it already is).

#5 lore raw

PATCH 2/3 btmgmt: Add btmgmt command advmon-remove

In reply to Michael Sun

This patch introduces a new btmgmt command ‘advmon-remove’ to allow users to remove previously added filters along with a event handler to handle kernel issued MGMT_EV_ADV_MONITOR_REMOVED event. The command will work with the new MGMT opcode MGMT_OP_REMOVE_ADV_MONITOR.

---

 tools/btmgmt.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
tools/btmgmt.c +55 -0
index 1aae7098c..719e92196 100644
@@ -1013,6 +1013,19 @@ static void advertising_removed(uint16_t index, uint16_t len,
 	print("hci%u advertising_removed: instance %u", index, ev->instance);
 }
 
+static void advmon_removed(uint16_t index, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_ev_adv_monitor_removed *ev = param;
+
+	if (len < sizeof(*ev)) {
+		error("Too small (%u bytes) advmon_removed event", len);
+		return;
+	}
+
+	print("hci%u advmon_removed: handle %u", index, ev->monitor_handle);
+}
+
 static void version_rsp(uint8_t status, uint16_t len, const void *param,
 							void *user_data)
 {
@@ -4645,6 +4658,44 @@ static void cmd_advmon_features(int argc, char **argv)
 	}
 }
 
+static void advmon_remove_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_rp_remove_adv_monitor *rp = param;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Could not remove advertisement monitor with status "
+				"0x%02x (%s)", status, mgmt_errstr(status));
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	print("Advertisement monitor with handle: 0x%04x removed",
+							rp->monitor_handle);
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_advmon_remove(int argc, char **argv)
+{
+	struct mgmt_cp_remove_adv_monitor cp;
+	uint16_t index, monitor_handle;
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	if (sscanf(argv[1], "%hx", &monitor_handle) != 1) {
+		error("Wrong formatted handle argument");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	cp.monitor_handle = monitor_handle;
+	if (mgmt_send(mgmt, MGMT_OP_REMOVE_ADV_MONITOR, index, sizeof(cp), &cp,
+					advmon_remove_rsp, NULL, NULL) == 0) {
+		error("Unable to send appearance cmd");
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
 static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 {
 	mgmt_register(mgmt, MGMT_EV_CONTROLLER_ERROR, index, controller_error,
@@ -4697,6 +4748,8 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 						advertising_added, NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_ADVERTISING_REMOVED, index,
 					advertising_removed, NULL, NULL);
+	mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_REMOVED, index, advmon_removed,
+								NULL, NULL);
 }
 
 static void cmd_select(int argc, char **argv)
@@ -4857,6 +4910,8 @@ static const struct bt_shell_menu main_menu = {
 	{ "advmon-features",	NULL,
 		cmd_advmon_features,	"Show advertisement monitor "
 					"features"			},
+	{ "advmon-remove",	"<handle>",
+		cmd_advmon_remove,	"Remove advertisement monitor "	},
 	{} },
 };
 
Signature · 1 line
2.27.0.290.gba653c62da-goog
#6 lore raw

RE: [bluez,v1,2/3] btmgmt: Add btmgmt command advmon-remove

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
checkpatch Failed

Outputs:
WARNING:EMBEDDED_FUNCTION_NAME: Prefer using '"%s...", __func__' to using 'advmon_removed', this function's name, in a string #32: FILE: tools/btmgmt.c:1022:
+ error("Too small (%u bytes) advmon_removed event", len);

WARNING:EMBEDDED_FUNCTION_NAME: Prefer using '"%s...", __func__' to using 'advmon_removed', this function's name, in a string #36: FILE: tools/btmgmt.c:1026:
+ print("hci%u advmon_removed: handle %u", index, ev->monitor_handle);

WARNING:SSCANF_TO_KSTRTO: Prefer kstrto<type> to single variable sscanf #71: FILE: tools/btmgmt.c:4686:
+ if (sscanf(argv[1], "%hx", &monitor_handle) != 1) {
+ error("Wrong formatted handle argument");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }

- total: 0 errors, 3 warnings, 79 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.

Your patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#7 lore raw

PATCH 3/3 btmgmt: Add btmgmt command advmon-add

In reply to Michael Sun

This patch introduces a new btmgmt command ‘advmon-add’ to allow users to add advertisement monitor filters and return monitor handlers. An event handler is also added to handle kernel issued MGMT_EV_ADV_MONITOR_ADDED events. The command will work with the new MGMT opcode MGMT_OP_ADD_ADV_MONITOR. This patch only adds support for adding pattern based filters.

---

 tools/btmgmt.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)
tools/btmgmt.c +158 -0
index 719e92196..2bdaf03fa 100644
@@ -1013,6 +1013,19 @@ static void advertising_removed(uint16_t index, uint16_t len,
 	print("hci%u advertising_removed: instance %u", index, ev->instance);
 }
 
+static void advmon_added(uint16_t index, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_ev_adv_monitor_added *ev = param;
+
+	if (len < sizeof(*ev)) {
+		error("Too small (%u bytes) advmon_removed event", len);
+		return;
+	}
+
+	print("hci%u advmon_added: handle %u", index, ev->monitor_handle);
+}
+
 static void advmon_removed(uint16_t index, uint16_t len, const void *param,
 							void *user_data)
 {
@@ -4658,6 +4671,147 @@ static void cmd_advmon_features(int argc, char **argv)
 	}
 }
 
+static void advmon_add_rsp(uint8_t status, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_rp_add_adv_patterns_monitor *rp = param;
+
+	if (status != MGMT_STATUS_SUCCESS) {
+		error("Could not add advertisement monitor with status "
+				"0x%02x (%s)", status, mgmt_errstr(status));
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	print("Advertisement monitor with handle:0x%04x added",
+							rp->monitor_handle);
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static bool str2pattern(struct mgmt_adv_pattern *pattern, const char *str)
+{
+	int type_len, offset_len, offset_end_pos, length, str_len;
+	int i, j;
+	char pattern_str[62] = { 0 };
+	char tmp;
+
+	if (sscanf(str, "%2hhx%n:%2hhx%n:%s", &pattern->ad_type, &type_len,
+			&pattern->offset, &offset_end_pos, pattern_str) != 3)
+		return false;
+
+	offset_len = offset_end_pos - type_len - 1;
+	str_len = strlen(pattern_str);
+	pattern->length = str_len / 2 + str_len % 2;
+
+	if (type_len > 2 || offset_len > 2 ||
+					pattern->offset + pattern->length > 31)
+		return false;
+
+	for (i = 0, j = 0; i < str_len; i++, j++) {
+		if (!sscanf(&pattern_str[i++], "%2hhx", &pattern->value[j]))
+			return false;
+		if (i < str_len && !sscanf(&pattern_str[i], "%1hhx", &tmp))
+			return false;
+	}
+
+	return true;
+}
+
+static void advmon_add_usage(void)
+{
+	bt_shell_usage();
+	print("Options:\n"
+		"\t -P, --pattern <ad_type:offset:pattern> "
+		"Advertising Data bytes\n"
+		"Monitor Types:\n"
+		"\t -p, --pattern-monitor			"
+		"Pattern Monitor\n"
+		"e.g.:\n"
+		"\tadvmon-add -P 0:1:c504 -P 1:a:9a55beef -p");
+}
+
+static struct option advmon_add_options[] =
+					{ { "help", 0, 0, 'h' },
+					{ "pattern-monitor", 0, 0, 'p' },
+					{ "pattern", 1, 0, 'P' },
+					{ 0, 0, 0, 0 } };
+
+static void cmd_advmon_add(int argc, char **argv)
+{
+
+	uint16_t index;
+	void *cp = NULL;
+	struct mgmt_adv_pattern *patterns = NULL;
+	int opt, i;
+	int pattern_count = 0, patterns_len, cp_len;
+	bool success = false, type_selected = false;
+
+	index = mgmt_index;
+	if (index == MGMT_INDEX_NONE)
+		index = 0;
+
+	while ((opt = getopt_long(argc, argv, "P:ph", advmon_add_options,
+								NULL)) != -1) {
+		switch (opt) {
+		case 'P':
+			patterns_len = (pattern_count + 1) *
+					sizeof(struct mgmt_adv_pattern);
+			patterns = realloc(patterns, patterns_len);
+
+			if (!str2pattern(&patterns[pattern_count++], optarg)) {
+				error("Failed to parse monitor patterns.");
+				goto done;
+			}
+			break;
+		case 'p':
+			if (!pattern_count) {
+				advmon_add_usage();
+				goto done;
+			}
+			cp_len =
+				sizeof(struct mgmt_cp_add_adv_patterns_monitor) +
+				patterns_len;
+			cp = realloc(cp, cp_len);
+
+			((struct mgmt_cp_add_adv_patterns_monitor *)cp)
+					->pattern_count = pattern_count;
+
+			memcpy(((struct mgmt_cp_add_adv_patterns_monitor *)cp)
+					->patterns, patterns, patterns_len);
+			type_selected = true;
+			break;
+		case 'h':
+			success = true;
+			/* fall through */
+		default:
+			advmon_add_usage();
+			goto done;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc || !type_selected) {
+		advmon_add_usage();
+		goto done;
+	}
+
+	if (!mgmt_send(mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, index, cp_len,
+					cp, advmon_add_rsp, NULL, NULL)) {
+		error("Unable to send \"Add Advertising Monitor\" command");
+		goto done;
+	}
+
+	success = true;
+
+done:
+	optind = 0;
+	free(patterns);
+	free(cp);
+	if (!success)
+		bt_shell_noninteractive_quit(EXIT_FAILURE);
+}
+
 static void advmon_remove_rsp(uint8_t status, uint16_t len, const void *param,
 							void *user_data)
 {
@@ -4748,6 +4902,8 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 						advertising_added, NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_ADVERTISING_REMOVED, index,
 					advertising_removed, NULL, NULL);
+	mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_ADDED, index, advmon_added,
+								NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_REMOVED, index, advmon_removed,
 								NULL, NULL);
 }
@@ -4910,6 +5066,8 @@ static const struct bt_shell_menu main_menu = {
 	{ "advmon-features",	NULL,
 		cmd_advmon_features,	"Show advertisement monitor "
 					"features"			},
+	{ "advmon-add",		"[options] <-p|-h>",
+		cmd_advmon_add,		"Add advertisement monitor "	},
 	{ "advmon-remove",	"<handle>",
 		cmd_advmon_remove,	"Remove advertisement monitor "	},
 	{} },
Signature · 1 line
2.27.0.290.gba653c62da-goog
#8 lore raw

RE: [bluez,v1,3/3] btmgmt: Add btmgmt command advmon-add

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. While we are preparing for reviewing the patches, we found the following issue/warning.

Test Result:
checkpatch Failed

Outputs:
WARNING:EMBEDDED_FUNCTION_NAME: Prefer using '"%s...", __func__' to using 'advmon_added', this function's name, in a string #38: FILE: tools/btmgmt.c:1026:
+ print("hci%u advmon_added: handle %u", index, ev->monitor_handle);

WARNING:NAKED_SSCANF: unchecked sscanf return value #84: FILE: tools/btmgmt.c:4710:
+ if (!sscanf(&pattern_str[i++], "%2hhx", &pattern->value[j]))
+ return false;

WARNING:NAKED_SSCANF: unchecked sscanf return value #86: FILE: tools/btmgmt.c:4712:
+ if (i < str_len && !sscanf(&pattern_str[i], "%1hhx", &tmp))
+ return false;

ERROR:OPEN_BRACE: that open brace { should be on the previous line #107: FILE: tools/btmgmt.c:4733:
+static struct option advmon_add_options[] =
+ { { "help", 0, 0, 'h' },

WARNING:LONG_LINE: line over 80 characters
#145: FILE: tools/btmgmt.c:4771:
+ sizeof(struct mgmt_cp_add_adv_patterns_monitor) +

WARNING:PREFER_FALLTHROUGH: Prefer 'fallthrough;' over fallthrough comment #158: FILE: tools/btmgmt.c:4784:
+ /* fall through */

- total: 1 errors, 5 warnings, 182 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.

Your patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPLIT_STRING

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth