summaryrefslogtreecommitdiff
path: root/tools/btmgmt.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2020-04-02 15:20:53 +0200
committerMarcel Holtmann <marcel@holtmann.org>2020-04-02 15:20:53 +0200
commit47b5609d0b2ab37d5a472978649216eb02badda0 (patch)
treee93bc7e97270d46aa3b44c266c4fd7dce4120913 /tools/btmgmt.c
parent9c9e8419e309544871cdff9832e1cba0a8432b56 (diff)
downloadbluez-47b5609d0b2ab37d5a472978649216eb02badda0.tar.gz
tools: Add command for reading the security information
Diffstat (limited to 'tools/btmgmt.c')
-rw-r--r--tools/btmgmt.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e40dbd199..fac01b116 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -1489,6 +1489,101 @@ static void cmd_extinfo(int argc, char **argv)
}
}
+static void sec_info_rsp(uint8_t status, uint16_t len, const void *param,
+ void *user_data)
+{
+ const struct mgmt_rp_read_security_info *rp = param;
+ uint16_t index = PTR_TO_UINT(user_data);
+
+ if (status != 0) {
+ error("Reading hci%u security failed with status 0x%02x (%s)",
+ index, status, mgmt_errstr(status));
+ goto done;
+ }
+
+ if (len < sizeof(*rp)) {
+ error("Too small info reply (%u bytes)", len);
+ goto done;
+ }
+
+ print("Primary controller (hci%u)", index);
+ print("\tSecurity info length: %u", le16_to_cpu(rp->sec_len));
+
+done:
+ pending_index--;
+
+ if (pending_index > 0)
+ return;
+
+ bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void sec_index_rsp(uint8_t status, uint16_t len, const void *param,
+ void *user_data)
+{
+ const struct mgmt_rp_read_ext_index_list *rp = param;
+ uint16_t count;
+ unsigned int i;
+
+ if (status != 0) {
+ error("Reading ext index list failed with status 0x%02x (%s)",
+ status, mgmt_errstr(status));
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ if (len < sizeof(*rp)) {
+ error("Too small ext index list reply (%u bytes)", len);
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ count = get_le16(&rp->num_controllers);
+
+ if (len < sizeof(*rp) + count * (sizeof(uint16_t) + sizeof(uint8_t))) {
+ error("Index count (%u) doesn't match reply length (%u)",
+ count, len);
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ for (i = 0; i < count; i++) {
+ uint16_t index = le16_to_cpu(rp->entry[i].index);
+
+ if (rp->entry[i].type != 0x00)
+ continue;
+
+ if (!mgmt_send(mgmt, MGMT_OP_READ_SECURITY_INFO,
+ index, 0, NULL, sec_info_rsp,
+ UINT_TO_PTR(index), NULL)) {
+ error("Unable to send read_security_info cmd");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+ pending_index++;
+ }
+
+ if (!count)
+ bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
+static void cmd_secinfo(int argc, char **argv)
+{
+ if (mgmt_index == MGMT_INDEX_NONE) {
+ if (!mgmt_send(mgmt, MGMT_OP_READ_EXT_INDEX_LIST,
+ MGMT_INDEX_NONE, 0, NULL,
+ sec_index_rsp, mgmt, NULL)) {
+ error("Unable to send ext_index_list cmd");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+
+ return;
+ }
+
+ if (!mgmt_send(mgmt, MGMT_OP_READ_SECURITY_INFO, mgmt_index, 0, NULL,
+ sec_info_rsp,
+ UINT_TO_PTR(mgmt_index), NULL)) {
+ error("Unable to send read_security_info cmd");
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ }
+}
+
static void auto_power_enable_rsp(uint8_t status, uint16_t len,
const void *param, void *user_data)
{
@@ -4533,6 +4628,8 @@ static const struct bt_shell_menu main_menu = {
cmd_phy, "Get/Set PHY Configuration" },
{ "wbs", "<on/off>",
cmd_wbs, "Toggle Wideband-Speech support"},
+ { "secinfo", NULL,
+ cmd_secinfo, "Show security information" },
{} },
};