Diff between 35c7dd410f7d09c9d69f86f8d70a786c0f7f25ce and 76bfabc7a35f4dfcf703d7cbc0fd80a83848a8a8

Changed Files

File Additions Deletions Status
lib/mgmt.h +4 -0 modified
mgmt/main.c +27 -1 modified
plugins/mgmtops.c +16 -1 modified

Full Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index a3a90e9..e8080e5 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 fb6f6c0..f47e3ba 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 <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
@@ -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)