From e1dc76907d32bb58580a6377f81b14b709a5988c Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 22 Feb 2014 16:36:53 +0200 Subject: [PATCH] tools/btmgmt: Add support for Set Privacy command --- tools/btmgmt.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 50b90ab24..9a5e9717d 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -1034,6 +1036,48 @@ static void cmd_bredr(struct mgmt *mgmt, uint16_t index, int argc, char **argv) cmd_setting(mgmt, index, MGMT_OP_SET_BREDR, argc, argv); } +static void cmd_privacy(struct mgmt *mgmt, uint16_t index, int argc, + char **argv) +{ + struct mgmt_cp_set_privacy cp; + int fd; + + if (argc < 2) { + printf("Specify \"on\" or \"off\"\n"); + exit(EXIT_FAILURE); + } + + if (strcasecmp(argv[1], "on") == 0 || strcasecmp(argv[1], "yes") == 0) + cp.privacy = 0x01; + else if (strcasecmp(argv[1], "off") == 0) + cp.privacy = 0x00; + else + cp.privacy = atoi(argv[1]); + + if (index == MGMT_INDEX_NONE) + index = 0; + + fd = open("/dev/urandom", O_RDONLY); + if (fd < 0) { + fprintf(stderr, "open(/dev/urandom): %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + if (read(fd, cp.irk, sizeof(cp.irk)) != sizeof(cp.irk)) { + fprintf(stderr, "Reading from urandom failed\n"); + close(fd); + exit(EXIT_FAILURE); + } + + close(fd); + + if (send_cmd(mgmt, MGMT_OP_SET_PRIVACY, index, sizeof(cp), &cp, + setting_rsp) == 0) { + fprintf(stderr, "Unable to send Set Privacy command\n"); + exit(EXIT_FAILURE); + } +} + static void class_rsp(uint16_t op, uint16_t id, uint8_t status, uint16_t len, const void *param) { @@ -2050,6 +2094,7 @@ static struct { { "le", cmd_le, "Toggle LE support" }, { "advertising",cmd_advertising,"Toggle LE advertising", }, { "bredr", cmd_bredr, "Toggle BR/EDR support", }, + { "privacy", cmd_privacy, "Toggle privacy support" }, { "class", cmd_class, "Set device major/minor class" }, { "disconnect", cmd_disconnect, "Disconnect device" }, { "con", cmd_con, "List connections" }, -- 2.47.3