From c863b07ea45588fb4d3c95a1baaab647b3bf3bed Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 28 Jun 2014 17:51:47 +0300 Subject: [PATCH] tools/btmgmt: Add basic support for Get Clock Info command --- tools/btmgmt.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 8f5a98165..611234611 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -2423,6 +2423,49 @@ static void cmd_scan_params(struct mgmt *mgmt, uint16_t index, } } +static void clock_info_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + const struct mgmt_rp_get_clock_info *rp = param; + + if (len < sizeof(*rp)) { + fprintf(stderr, "Unexpected Get Clock Info len %u\n", len); + exit(EXIT_FAILURE); + } + + if (status) { + fprintf(stderr, "Get Clock Info failed with status 0x%02x (%s)\n", + status, mgmt_errstr(status)); + exit(EXIT_FAILURE); + } + + printf("Local Clock: %u\n", le32_to_cpu(rp->local_clock)); + printf("Piconet Clock: %u\n", le32_to_cpu(rp->piconet_clock)); + printf("Accurary: %u\n", le16_to_cpu(rp->accuracy)); + + mainloop_quit(); +} + +static void cmd_clock_info(struct mgmt *mgmt, uint16_t index, + int argc, char **argv) +{ + struct mgmt_cp_get_clock_info cp; + + if (index == MGMT_INDEX_NONE) + index = 0; + + memset(&cp, 0, sizeof(cp)); + + if (argc > 1) + str2ba(argv[1], &cp.addr.bdaddr); + + if (mgmt_send(mgmt, MGMT_OP_GET_CLOCK_INFO, index, sizeof(cp), &cp, + clock_info_rsp, NULL, NULL) == 0) { + fprintf(stderr, "Unable to send get_clock_info cmd\n"); + exit(EXIT_FAILURE); + } +} + static struct { char *cmd; void (*func)(struct mgmt *mgmt, uint16_t index, int argc, char **argv); @@ -2468,6 +2511,7 @@ static struct { { "conn-info", cmd_conn_info, "Get connection information" }, { "io-cap", cmd_io_cap, "Set IO Capability" }, { "scan-params",cmd_scan_params,"Set Scan Parameters" }, + { "get-clock", cmd_clock_info, "Get Clock Information" }, { } }; -- 2.47.3