2021-05-26 05:14:58

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: [PATCH V2 1/4] tools/btmgmt: Add device flags commands

From: Tedd Ho-Jeong An <[email protected]>

This patch adds commands for get/set device flags mgmt ops.

Usage:

get-flags [-t type] <address>
-t type Address Type
0 BR/EDR
1 LE Public
2 LE Random

set-flags [-f flags] [-t type] <address>
-t type Address Type
0 BR/EDR
1 LE Public
2 LE Random
-f flags Device flag.
1 Remote Wake Enable
---
tools/btmgmt.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 174 insertions(+)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index bf3b460d0..a6ac026dc 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -1000,6 +1000,24 @@ static void advertising_removed(uint16_t index, uint16_t len,
print("hci%u advertising_removed: instance %u", index, ev->instance);
}

+static void flags_changed(uint16_t index, uint16_t len, const void *param,
+ void *user_data)
+{
+ const struct mgmt_ev_device_flags_changed *ev = param;
+ char addr[18];
+
+ if (len < sizeof(*ev)) {
+ error("Too small (%u bytes) %s event", len, __func__);
+ return;
+ }
+
+ ba2str(&ev->addr.bdaddr, addr);
+ print("hci%u device_flags_changed: %s (%s)", index, addr,
+ typestr(ev->addr.type));
+ print(" supp: 0x%08x curr: 0x%08x",
+ ev->supported_flags, ev->current_flags);
+}
+
static void advmon_added(uint16_t index, uint16_t len, const void *param,
void *user_data)
{
@@ -2110,6 +2128,156 @@ static void cmd_auto_power(int argc, char **argv)
}
}

+static void get_flags_rsp(uint8_t status, uint16_t len, const void *param,
+ void *user_data)
+{
+ const struct mgmt_rp_get_device_flags *rp = param;
+
+ if (status != 0) {
+ error("Get device flags failed with status 0x%02x (%s)",
+ status, mgmt_errstr(status));
+ bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ print("Supported Flags: 0x%08x", rp->supported_flags);
+ print("Current Flags: 0x%08x", rp->current_flags);
+ bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static struct option get_flags_options[] = {
+ { "help", 0, 0, 'h' },
+ { "type", 1, 0, 't' },
+ { 0, 0, 0, 0 }
+};
+
+static void cmd_get_flags(int argc, char **argv)
+{
+ struct mgmt_cp_get_device_flags cp;
+ uint8_t type = BDADDR_BREDR;
+ char addr[18];
+ int opt;
+ uint16_t index;
+
+ while ((opt = getopt_long(argc, argv, "+t:h", get_flags_options,
+ NULL)) != -1) {
+ switch (opt) {
+ case 't':
+ type = strtol(optarg, NULL, 0);
+ break;
+ case 'h':
+ bt_shell_usage();
+ optind = 0;
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+ default:
+ bt_shell_usage();
+ optind = 0;
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
+ if (argc < 1) {
+ bt_shell_usage();
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ index = mgmt_index;
+ if (index == MGMT_INDEX_NONE)
+ index = 0;
+
+ memset(&cp, 0, sizeof(cp));
+ str2ba(argv[0], &cp.addr.bdaddr);
+ cp.addr.type = type;
+
+ ba2str(&cp.addr.bdaddr, addr);
+ print("Get device flag of %s (%s)", addr, typestr(cp.addr.type));
+
+ if (mgmt_send(mgmt, MGMT_OP_GET_DEVICE_FLAGS, index, sizeof(cp), &cp,
+ get_flags_rsp, NULL, NULL) == 0) {
+ error("Unable to send Get Device Flags command");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+}
+
+static void set_flags_rsp(uint8_t status, uint16_t len, const void *param,
+ void *user_data)
+{
+ if (status != 0) {
+ error("Set device flags failed with status 0x%02x (%s)",
+ status, mgmt_errstr(status));
+ bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+ bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static struct option set_flags_options[] = {
+ { "help", 0, 0, 'h' },
+ { "type", 1, 0, 't' },
+ { "flags", 1, 0, 'f' },
+ { 0, 0, 0, 0 }
+};
+
+static void cmd_set_flags(int argc, char **argv)
+{
+ struct mgmt_cp_set_device_flags cp;
+ uint8_t type = BDADDR_BREDR;
+ uint32_t flags = 0;
+ char addr[18];
+ int opt;
+ uint16_t index;
+
+ while ((opt = getopt_long(argc, argv, "+f:t:h", set_flags_options,
+ NULL)) != -1) {
+ switch (opt) {
+ case 'f':
+ flags = strtol(optarg, NULL, 0);
+ break;
+ case 't':
+ type = strtol(optarg, NULL, 0);
+ break;
+ case 'h':
+ bt_shell_usage();
+ optind = 0;
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+ default:
+ bt_shell_usage();
+ optind = 0;
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
+ if (argc < 1) {
+ bt_shell_usage();
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ index = mgmt_index;
+ if (index == MGMT_INDEX_NONE)
+ index = 0;
+
+ memset(&cp, 0, sizeof(cp));
+ str2ba(argv[0], &cp.addr.bdaddr);
+ cp.addr.type = type;
+ cp.current_flags = flags;
+
+ ba2str(&cp.addr.bdaddr, addr);
+ print("Set device flag of %s (%s)", addr, typestr(cp.addr.type));
+
+ if (mgmt_send(mgmt, MGMT_OP_SET_DEVICE_FLAGS, index, sizeof(cp), &cp,
+ set_flags_rsp, NULL, NULL) == 0) {
+ error("Unable to send Set Device Flags command");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+}
+
/* Wrapper to get the index and opcode to the response callback */
struct command_data {
uint16_t id;
@@ -5197,6 +5365,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_DEVICE_FLAGS_CHANGED, index,
+ flags_changed, 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,
@@ -5381,6 +5551,10 @@ static const struct bt_shell_menu main_menu = {
cmd_read_sysconfig, "Read System Configuration" },
{ "set-sysconfig", "<-v|-h> [options...]",
cmd_set_sysconfig, "Set System Configuration" },
+ { "get-flags", "[-t type] <address>",
+ cmd_get_flags, "Get device flags" },
+ { "set-flags", "[-f flags] [-t type] <address>",
+ cmd_set_flags, "Set device flags" },
{} },
};

--
2.26.3


2021-05-26 05:14:58

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: [PATCH V2 2/4] lib: Align mgmt header with document

From: Tedd Ho-Jeong An <[email protected]>

This patch updates the mgmt header to align with the mgmt api document
(doc/mgmt-api.txt)
---
lib/mgmt.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index a85f891c5..0a6349321 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -1087,11 +1087,13 @@ static const char *mgmt_op[] = {
"Set PHY Configuration",
"Set Blocked Keys",
"Set Wideband Speech",
- "Read Security Information", /* 0x0048 */
+ "Read Controller Capabilities Information", /* 0x0048 */
"Read Experimental Features Information",
"Set Experimental Feature",
"Read Default System Configuration",
"Set Default System Configuration",
+ "Read Default Runtime Configuration",
+ "Set Default Runtime Configuration",
"Get Device Flags",
"Set Device Flags", /* 0x0050 */
"Read Advertisement Monitor Features",
@@ -1143,6 +1145,8 @@ static const char *mgmt_ev[] = {
"Extended Controller Information Changed",
"PHY Configuration Changed",
"Experimental Feature Changed",
+ "Default System Configuration Changed", /* 0x0028 */
+ "Default Runtime Configuration Changed",
"Device Flags Changed",
"Advertisement Monitor Added", /* 0x002b */
"Advertisement Monitor Removed",
@@ -1172,6 +1176,7 @@ static const char *mgmt_status[] = {
"Blocked through rfkill",
"Already Paired",
"Permission Denied",
+ "Connection Not Established",
};

#ifndef NELEM
--
2.26.3

2021-05-26 05:16:20

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: [PATCH V2 3/4] tools/mgmt-tester: Print hexdump if mgmt event parameters not match

From: Tedd Ho-Jeong An <[email protected]>

This patch displays the hexdump of expected and received mgmt event
parameters.
---
tools/mgmt-tester.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index c9de770c1..767e010a6 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -6780,6 +6780,9 @@ static bool verify_alt_ev(const void *param, uint16_t length)
if (test->expect_alt_ev_param &&
memcmp(test->expect_alt_ev_param, param, length)) {
tester_warn("Event parameters do not match");
+ util_hexdump('>', param, length, print_debug, "");
+ util_hexdump('!', test->expect_alt_ev_param, length,
+ print_debug, "");
return false;
}

--
2.26.3

2021-05-26 05:17:19

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: [PATCH V2 4/4] tools/mgmt-tester: Add test cases for get/set device flags

From: Tedd Ho-Jeong An <[email protected]>

This patch adds test cases for get/set device flags commands.
---
tools/mgmt-tester.c | 182 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 182 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 767e010a6..4550d6e9c 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -8990,6 +8990,140 @@ static void setup_phy_configuration(const void *test_data)
NULL, NULL);
}

+static const uint8_t get_dev_flags_param[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+};
+
+static const uint8_t get_dev_flags_rsp_param[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+ 0x01, 0x00, 0x00, 0x00, /* Supported Flages */
+ 0x00, 0x00, 0x00, 0x00, /* Current Flages */
+};
+
+static const struct generic_data get_dev_flags_success = {
+ .send_opcode = MGMT_OP_GET_DEVICE_FLAGS,
+ .send_param = get_dev_flags_param,
+ .send_len = sizeof(get_dev_flags_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = get_dev_flags_rsp_param,
+ .expect_len = sizeof(get_dev_flags_rsp_param),
+};
+
+static const uint8_t get_dev_flags_param_fail_1[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+};
+
+static const struct generic_data get_dev_flags_fail_1 = {
+ .send_opcode = MGMT_OP_GET_DEVICE_FLAGS,
+ .send_param = get_dev_flags_param_fail_1,
+ .send_len = sizeof(get_dev_flags_param_fail_1),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static void setup_get_dev_flags(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ unsigned char param[] = { 0x01 };
+ const unsigned char *add_param;
+ size_t add_param_len;
+
+ tester_print("Powering on controller (with added device)");
+
+ if (data->hciemu_type == HCIEMU_TYPE_LE) {
+ add_param = add_device_success_param_2;
+ add_param_len = sizeof(add_device_success_param_2);
+ } else {
+ add_param = add_device_success_param_1;
+ add_param_len = sizeof(add_device_success_param_1);
+ }
+
+ mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index,
+ add_param_len, add_param, NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
+ sizeof(param), param,
+ setup_powered_callback, NULL, NULL);
+}
+
+static const uint8_t set_dev_flags_param[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+ 0x01, 0x00, 0x00, 0x00, /* Current Flages */
+};
+
+static const uint8_t set_dev_flags_rsp_param[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+};
+
+static const uint8_t dev_flags_changed_param[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+ 0x01, 0x00, 0x00, 0x00, /* Supported Flages */
+ 0x01, 0x00, 0x00, 0x00, /* Current Flages */
+};
+
+static const struct generic_data set_dev_flags_success = {
+ .send_opcode = MGMT_OP_SET_DEVICE_FLAGS,
+ .send_param = set_dev_flags_param,
+ .send_len = sizeof(set_dev_flags_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_dev_flags_rsp_param,
+ .expect_len = sizeof(set_dev_flags_rsp_param),
+ .expect_alt_ev = MGMT_EV_DEVICE_FLAGS_CHANGED,
+ .expect_alt_ev_param = dev_flags_changed_param,
+ .expect_alt_ev_len = sizeof(dev_flags_changed_param),
+};
+
+static const uint8_t set_dev_flags_param_fail_1[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+};
+
+static const struct generic_data set_dev_flags_fail_1 = {
+ .send_opcode = MGMT_OP_SET_DEVICE_FLAGS,
+ .send_param = set_dev_flags_param_fail_1,
+ .send_len = sizeof(set_dev_flags_param_fail_1),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const uint8_t set_dev_flags_param_fail_2[] = {
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+ 0x03, 0x00, 0x00, 0x00, /* Current Flages */
+};
+
+static const struct generic_data set_dev_flags_fail_2 = {
+ .send_opcode = MGMT_OP_SET_DEVICE_FLAGS,
+ .send_param = set_dev_flags_param_fail_2,
+ .send_len = sizeof(set_dev_flags_param_fail_2),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+ .expect_param = set_dev_flags_rsp_param,
+ .expect_len = sizeof(set_dev_flags_rsp_param),
+};
+
+static const uint8_t set_dev_flags_param_fail_3[] = {
+ 0x11, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+ 0x01, 0x00, 0x00, 0x00, /* Current Flages */
+};
+
+static const uint8_t set_dev_flags_rsp_param_fail_3[] = {
+ 0x11, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */
+ 0x00, /* Type */
+};
+
+static const struct generic_data set_dev_flags_fail_3 = {
+ .send_opcode = MGMT_OP_SET_DEVICE_FLAGS,
+ .send_param = set_dev_flags_param_fail_3,
+ .send_len = sizeof(set_dev_flags_param_fail_3),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+ .expect_param = set_dev_flags_rsp_param_fail_3,
+ .expect_len = sizeof(set_dev_flags_rsp_param_fail_3),
+};
+
static bool power_off(uint16_t index)
{
int sk, err;
@@ -11010,5 +11144,53 @@ int main(int argc, char *argv[])
NULL,
test_command_generic);

+ /* MGMT_OP_GET_DEVICE_FLAGS
+ * Success
+ */
+ test_bredrle50("Get Device Flags - Success",
+ &get_dev_flags_success,
+ setup_get_dev_flags,
+ test_command_generic);
+
+ /* MGMT_OP_GET_DEVICE_FLAGS
+ * Fail - Invalid parameter
+ */
+ test_bredrle50("Get Device Flags - Invalid Parameter",
+ &get_dev_flags_fail_1,
+ setup_get_dev_flags,
+ test_command_generic);
+
+ /* MGMT_OP_SET_DEVICE_FLAGS
+ * Success
+ */
+ test_bredrle50("Set Device Flags - Success",
+ &set_dev_flags_success,
+ setup_get_dev_flags,
+ test_command_generic);
+
+ /* MGMT_OP_SET_DEVICE_FLAGS
+ * Invalid Parameter - Missing parameter
+ */
+ test_bredrle50("Set Device Flags - Invalid Parameter 1",
+ &set_dev_flags_fail_1,
+ setup_get_dev_flags,
+ test_command_generic);
+
+ /* MGMT_OP_SET_DEVICE_FLAGS
+ * Invalid Parameter - Not supported value
+ */
+ test_bredrle50("Set Device Flags - Invalid Parameter 2",
+ &set_dev_flags_fail_2,
+ setup_get_dev_flags,
+ test_command_generic);
+
+ /* MGMT_OP_SET_DEVICE_FLAGS
+ * Device not exist
+ */
+ test_bredrle50("Set Device Flags - Device not found",
+ &set_dev_flags_fail_3,
+ setup_get_dev_flags,
+ test_command_generic);
+
return tester_run();
}
--
2.26.3

2021-05-26 07:54:08

by bluez.test.bot

[permalink] [raw]
Subject: RE: [V2,1/4] tools/btmgmt: Add device flags commands

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.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=488567

---Test result---

Test Summary:
CheckPatch PASS 1.38 seconds
GitLint PASS 0.46 seconds
Prep - Setup ELL PASS 45.66 seconds
Build - Prep PASS 0.10 seconds
Build - Configure PASS 7.83 seconds
Build - Make PASS 190.51 seconds
Make Check PASS 9.47 seconds
Make Distcheck PASS 225.24 seconds
Build w/ext ELL - Configure PASS 7.66 seconds
Build w/ext ELL - Make PASS 177.05 seconds

Details
##############################
Test: CheckPatch - PASS
Desc: Run checkpatch.pl script with rule in .checkpatch.conf

##############################
Test: GitLint - PASS
Desc: Run gitlint with rule in .gitlint

##############################
Test: Prep - Setup ELL - PASS
Desc: Clone, build, and install ELL

##############################
Test: Build - Prep - PASS
Desc: Prepare environment for build

##############################
Test: Build - Configure - PASS
Desc: Configure the BlueZ source tree

##############################
Test: Build - Make - PASS
Desc: Build the BlueZ source tree

##############################
Test: Make Check - PASS
Desc: Run 'make check'

##############################
Test: Make Distcheck - PASS
Desc: Run distcheck to check the distribution

##############################
Test: Build w/ext ELL - Configure - PASS
Desc: Configure BlueZ source with '--enable-external-ell' configuration

##############################
Test: Build w/ext ELL - Make - PASS
Desc: Build BlueZ source with '--enable-external-ell' configuration



---
Regards,
Linux Bluetooth

2021-05-26 21:39:34

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [V2,1/4] tools/btmgmt: Add device flags commands

Hi Tedd,

On Wed, May 26, 2021 at 12:54 AM <[email protected]> wrote:
>
> 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.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=488567
>
> ---Test result---
>
> Test Summary:
> CheckPatch PASS 1.38 seconds
> GitLint PASS 0.46 seconds
> Prep - Setup ELL PASS 45.66 seconds
> Build - Prep PASS 0.10 seconds
> Build - Configure PASS 7.83 seconds
> Build - Make PASS 190.51 seconds
> Make Check PASS 9.47 seconds
> Make Distcheck PASS 225.24 seconds
> Build w/ext ELL - Configure PASS 7.66 seconds
> Build w/ext ELL - Make PASS 177.05 seconds
>
> Details
> ##############################
> Test: CheckPatch - PASS
> Desc: Run checkpatch.pl script with rule in .checkpatch.conf
>
> ##############################
> Test: GitLint - PASS
> Desc: Run gitlint with rule in .gitlint
>
> ##############################
> Test: Prep - Setup ELL - PASS
> Desc: Clone, build, and install ELL
>
> ##############################
> Test: Build - Prep - PASS
> Desc: Prepare environment for build
>
> ##############################
> Test: Build - Configure - PASS
> Desc: Configure the BlueZ source tree
>
> ##############################
> Test: Build - Make - PASS
> Desc: Build the BlueZ source tree
>
> ##############################
> Test: Make Check - PASS
> Desc: Run 'make check'
>
> ##############################
> Test: Make Distcheck - PASS
> Desc: Run distcheck to check the distribution
>
> ##############################
> Test: Build w/ext ELL - Configure - PASS
> Desc: Configure BlueZ source with '--enable-external-ell' configuration
>
> ##############################
> Test: Build w/ext ELL - Make - PASS
> Desc: Build BlueZ source with '--enable-external-ell' configuration
>
>
>
> ---
> Regards,
> Linux Bluetooth

Applied, thanks.


--
Luiz Augusto von Dentz