From 84beb3c00c4eb89c752222aa1cce7e81902ce297 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 2 Oct 2013 06:13:55 -0700 Subject: [PATCH] tools/btmgmt: Add support for setting static address --- tools/btmgmt.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 1d45349c6..d2547960f 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1774,6 +1774,46 @@ done: } } +static void static_addr_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + if (status != 0) + fprintf(stderr, "Set static address failed " + "with status 0x%02x (%s)\n", + status, mgmt_errstr(status)); + else + printf("Static address successfully set\n"); + + g_main_loop_quit(event_loop); +} + +static void static_addr_usage(void) +{ + printf("Usage: btmgmt static-addr
\n"); +} + +static void cmd_static_addr(struct mgmt *mgmt, uint16_t index, + int argc, char **argv) +{ + struct mgmt_cp_set_static_address cp; + + if (argc < 2) { + static_addr_usage(); + exit(EXIT_FAILURE); + } + + if (index == MGMT_INDEX_NONE) + index = 0; + + str2ba(argv[1], &cp.bdaddr); + + if (mgmt_send(mgmt, MGMT_OP_SET_STATIC_ADDRESS, index, sizeof(cp), &cp, + static_addr_rsp, NULL, NULL) == 0) { + fprintf(stderr, "Unable to send set_static_address cmd\n"); + exit(EXIT_FAILURE); + } +} + static struct { char *cmd; void (*func)(struct mgmt *mgmt, uint16_t index, int argc, char **argv); @@ -1809,6 +1849,7 @@ static struct { { "rm-uuid", cmd_remove_uuid, "Remove UUID" }, { "clr-uuids", cmd_clr_uuids, "Clear UUIDs", }, { "did", cmd_did, "Set Device ID", }, + { "static-addr",cmd_static_addr,"Set static address", }, { NULL, NULL, 0 } }; -- 2.11.0