Diff between 4b294a9486f751ff987777599091529adf8f9e00 and aca6d609da4ebfb23a995c76efa90b0c3e424151

Changed Files

File Additions Deletions Status
tools/btmgmt.c +36 -4 modified

Full Patch

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 50c00b5..aee6841 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -1186,21 +1186,53 @@ done:
 	mainloop_quit();
 }
 
+static void disconnect_usage(void)
+{
+	printf("Usage: btmgmt disconnect [-t type] <remote address>\n");
+}
+
+static struct option disconnect_options[] = {
+	{ "help",	0, 0, 'h' },
+	{ "type",	1, 0, 't' },
+	{ 0, 0, 0, 0 }
+};
+
 static void cmd_disconnect(struct mgmt *mgmt, uint16_t index, int argc,
 								char **argv)
 {
 	struct mgmt_cp_disconnect cp;
+	uint8_t type = BDADDR_BREDR;
+	int opt;
 
-	if (argc < 2) {
-		printf("Usage: btmgmt %s <address>\n", argv[0]);
-		exit(EXIT_FAILURE);
+	while ((opt = getopt_long(argc, argv, "+t:h", disconnect_options,
+								NULL)) != -1) {
+		switch (opt) {
+		case 't':
+			type = strtol(optarg, NULL, 0);
+			break;
+		case 'h':
+		default:
+			disconnect_usage();
+			exit(EXIT_SUCCESS);
+		}
 	}
 
-	str2ba(argv[1], &cp.addr.bdaddr);
+	argc -= optind;
+	argv += optind;
+	optind = 0;
+
+	if (argc < 1) {
+		disconnect_usage();
+		exit(EXIT_FAILURE);
+	}
 
 	if (index == MGMT_INDEX_NONE)
 		index = 0;
 
+	memset(&cp, 0, sizeof(cp));
+	str2ba(argv[0], &cp.addr.bdaddr);
+	cp.addr.type = type;
+
 	if (mgmt_send(mgmt, MGMT_OP_DISCONNECT, index, sizeof(cp), &cp,
 					disconnect_rsp, NULL, NULL) == 0) {
 		fprintf(stderr, "Unable to send disconnect cmd\n");