diff --git a/lib/mgmt.h b/lib/mgmt.h
index a3a90e9..e8080e5 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
#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 fb6f6c0..f47e3ba 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
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 <yes/no> [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 0bea368..ef49a0d 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
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)