btmgmt: Add command read-sysconfig
authorHoward Chung <howardchung@google.com>
Tue, 5 Jan 2021 03:12:55 +0000 (11:12 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
Add command read-sysconfig in btmgmt

Example usage:
localhost ~ # btmgmt
[mgmt]# read-sysconfig
Type: 0x0000    Length: 02      Value: 0000
Type: 0x0001    Length: 02      Value: 0008
...
Type: 0x001f    Length: 01      Value: 01

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/btmgmt.c

index 903decc..081d730 100755 (executable)
@@ -1751,6 +1751,52 @@ static void cmd_exp_debug(int argc, char **argv)
        }
 }
 
+static void print_mgmt_tlv(void *data, void *user_data)
+{
+       const struct mgmt_tlv *entry = data;
+       char buf[256];
+
+       bin2hex(entry->value, entry->length, buf, sizeof(buf));
+       print("Type: 0x%04x\tLength: %02hhu\tValue: %s", entry->type,
+                                                       entry->length, buf);
+}
+
+static void read_sysconfig_rsp(uint8_t status, uint16_t len, const void *param,
+                                                       void *user_data)
+{
+       struct mgmt_tlv_list *tlv_list;
+
+       if (status != 0) {
+               error("Read system configuration failed with status "
+                               "0x%02x (%s)", status, mgmt_errstr(status));
+               return;
+       }
+
+       tlv_list = mgmt_tlv_list_load_from_buf(param, len);
+       if (!tlv_list) {
+               error("Unable to parse response of read system configuration");
+               return;
+       }
+
+       mgmt_tlv_list_foreach(tlv_list, print_mgmt_tlv, NULL);
+       mgmt_tlv_list_free(tlv_list);
+}
+
+static void cmd_read_sysconfig(int argc, char **argv)
+{
+       uint16_t index;
+
+       index = mgmt_index;
+       if (index == MGMT_INDEX_NONE)
+               index = 0;
+
+       if (!mgmt_send(mgmt, MGMT_OP_READ_DEF_SYSTEM_CONFIG, index,
+                       0, NULL, read_sysconfig_rsp, NULL, NULL)) {
+               error("Unable to send read system configuration 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)
 {
@@ -5031,6 +5077,8 @@ static const struct bt_shell_menu main_menu = {
                cmd_expinfo,            "Show experimental features"    },
        { "exp-debug",          "<on/off>",
                cmd_exp_debug,          "Set debug feature"             },
+       { "read-sysconfig",     NULL,
+               cmd_read_sysconfig,     "Read System Configuration"     },
        {} },
 };