Diff between 56a7c39040f347e4e7b755cc24d6420ee58f1508 and 5876b5407ce48f4089b30712fec21efbf5edc4a1

Changed Files

File Additions Deletions Status
mgmt/main.c +32 -0 modified

Full Patch

diff --git a/mgmt/main.c b/mgmt/main.c
index 12ec8a9..2b88b0f 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
@@ -875,6 +875,37 @@ static void cmd_monitor(int mgmt_sk, uint16_t index, int argc, char **argv)
 	monitor = true;
 }
 
+static void version_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
+				void *rsp, uint16_t len, void *user_data)
+{
+	struct mgmt_rp_read_version *rp = rsp;
+
+	if (status != 0) {
+		fprintf(stderr, "Reading mgmt version failed with status"
+			" 0x%02x (%s)\n", status, mgmt_errstr(status));
+		exit(EXIT_FAILURE);
+	}
+
+	if (len < sizeof(*rp)) {
+		fprintf(stderr, "Too small version reply (%u bytes)\n", len);
+		exit(EXIT_FAILURE);
+	}
+
+	printf("MGMT Version %u, revision %u\n", rp->version,
+						bt_get_le16(&rp->revision));
+
+	exit(EXIT_SUCCESS);
+}
+
+static void cmd_version(int mgmt_sk, uint16_t index, int argc, char **argv)
+{
+	if (mgmt_send_cmd(mgmt_sk, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE,
+					NULL, 0, version_rsp, NULL) < 0) {
+		fprintf(stderr, "Unable to send read_version cmd\n");
+		exit(EXIT_FAILURE);
+	}
+}
+
 static void commands_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 				void *rsp, uint16_t len, void *user_data)
 {
@@ -1706,6 +1737,7 @@ static struct {
 	char *doc;
 } command[] = {
 	{ "monitor",	cmd_monitor,	"Monitor events"		},
+	{ "version",	cmd_version,	"Get the MGMT Version"		},
 	{ "commands",	cmd_commands,	"List supported commands"	},
 	{ "info",	cmd_info,	"Show controller info"		},
 	{ "power",	cmd_power,	"Toggle powered state"		},