Diff between 0fb2aff3164567f000b4ef40b91d41c70287e6c6 and f444a1bd4bd9f6060d3e4374a7af3524f10260a9

Changed Files

File Additions Deletions Status
tools/btmgmt.c +12 -7 modified

Full Patch

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 552f744..e218a87 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -88,6 +88,17 @@ static int pending_index = 0;
 
 #define PROMPT_ON	COLOR_BLUE "[mgmt]" COLOR_OFF "# "
 
+static void set_index(char *arg)
+{
+	if (!arg || !strcmp(arg, "none") || !strcmp(arg, "any") ||
+						!strcmp(arg, "all"))
+		mgmt_index = MGMT_INDEX_NONE;
+	else if (!strncmp(arg, "hci", 3))
+		mgmt_index = atoi(&arg[3]);
+	else
+		mgmt_index = atoi(arg);
+}
+
 static void update_prompt(uint16_t index)
 {
 	char str[32];
@@ -4535,13 +4546,7 @@ static void cmd_select(struct mgmt *mgmt, uint16_t index,
 	mgmt_cancel_all(mgmt);
 	mgmt_unregister_all(mgmt);
 
-	if (!strcmp(argv[1], "none") || !strcmp(argv[1], "any") ||
-						!strcmp(argv[1], "all"))
-		mgmt_index = MGMT_INDEX_NONE;
-	else if (!strncmp(argv[1], "hci", 3))
-		mgmt_index = atoi(&argv[1][3]);
-	else
-		mgmt_index = atoi(argv[1]);
+	set_index(argv[1]);
 
 	register_mgmt_callbacks(mgmt, mgmt_index);