From 76bfabc7a35f4dfcf703d7cbc0fd80a83848a8a8 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 3 Nov 2011 08:17:23 +0200 Subject: [PATCH] mgmt: Update set_discoverable to match new API --- lib/mgmt.h | 4 ++++ mgmt/main.c | 28 +++++++++++++++++++++++++++- plugins/mgmtops.c | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/mgmt.h b/lib/mgmt.h index a3a90e989..e8080e54a 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -79,6 +79,10 @@ struct mgmt_mode { #define MGMT_OP_SET_POWERED 0x0005 #define MGMT_OP_SET_DISCOVERABLE 0x0006 +struct mgmt_cp_set_discoverable { + uint8_t val; + uint16_t timeout; +} __packed; #define MGMT_OP_SET_CONNECTABLE 0x0007 diff --git a/mgmt/main.c b/mgmt/main.c index fb6f6c0c3..f47e3ba74 100644 --- a/mgmt/main.c +++ b/mgmt/main.c @@ -703,7 +703,33 @@ static void cmd_power(int mgmt_sk, uint16_t index, int argc, char **argv) static void cmd_discov(int mgmt_sk, uint16_t index, int argc, char **argv) { - cmd_setting(mgmt_sk, index, MGMT_OP_SET_DISCOVERABLE, argc, argv); + struct mgmt_cp_set_discoverable cp; + + if (argc < 2) { + printf("Usage: btmgmt %s [timeout]\n", argv[0]); + exit(EXIT_FAILURE); + } + + memset(&cp, 0, sizeof(cp)); + + if (strcasecmp(argv[1], "on") == 0) + cp.val = 1; + else if (strcasecmp(argv[1], "off") == 0) + cp.val = 0; + else + cp.val = atoi(argv[1]); + + if (argc > 2) + cp.timeout = htobs(atoi(argv[2])); + + if (index == MGMT_INDEX_NONE) + index = 0; + + if (mgmt_send_cmd(mgmt_sk, MGMT_OP_SET_DISCOVERABLE, index, + &cp, sizeof(cp), setting_rsp, NULL) < 0) { + fprintf(stderr, "Unable to send set_discoverable cmd\n"); + exit(EXIT_FAILURE); + } } static void cmd_connectable(int mgmt_sk, uint16_t index, int argc, char **argv) diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index 0bea368d7..ef49a0d65 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -193,8 +193,23 @@ static int mgmt_set_connectable(int index, gboolean connectable) static int mgmt_set_discoverable(int index, gboolean discoverable) { + char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_discoverable)]; + struct mgmt_hdr *hdr = (void *) buf; + struct mgmt_cp_set_discoverable *cp = (void *) &buf[sizeof(*hdr)]; + DBG("index %d discoverable %d", index, discoverable); - return mgmt_set_mode(index, MGMT_OP_SET_DISCOVERABLE, discoverable); + + memset(buf, 0, sizeof(buf)); + hdr->opcode = htobs(MGMT_OP_SET_DISCOVERABLE); + hdr->index = htobs(index); + hdr->len = htobs(sizeof(*cp)); + + cp->val = discoverable; + + if (write(mgmt_sock, buf, sizeof(buf)) < 0) + return -errno; + + return 0; } static int mgmt_set_pairable(int index, gboolean pairable) -- 2.47.3