---
Changes in v2:
- remove get_index()
- s/get_index()/mgmt_index/
tools/btmgmt.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 552f74411..e218a87ff 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);
--
2.14.1
Hi Eramoto,
On Fri, Nov 17, 2017 at 9:20 AM, ERAMOTO Masaya
<[email protected]> wrote:
> ---
> Changes in v2:
> - remove get_index()
> - s/get_index()/mgmt_index/
>
> tools/btmgmt.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/tools/btmgmt.c b/tools/btmgmt.c
> index 552f74411..e218a87ff 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);
>
> --
> 2.14.1
Applied, thanks
--
Luiz Augusto von Dentz
The command select can also set the specified index even if prefix hci
includes uppercase characters.
---
Changes in v2:
- s/get_index()/mgmt_index/
tools/btmgmt.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e218a87ff..3911ba268 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -93,7 +93,7 @@ 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))
+ else if(strlen(arg) > 3 && !strncasecmp(arg, "hci", 3))
mgmt_index = atoi(&arg[3]);
else
mgmt_index = atoi(arg);
@@ -4810,18 +4810,13 @@ static void mgmt_debug(const char *str, void *user_data)
int main(int argc, char *argv[])
{
struct io *input;
- uint16_t index = MGMT_INDEX_NONE;
int status, opt;
while ((opt = getopt_long(argc, argv, "+hi:",
main_options, NULL)) != -1) {
switch (opt) {
case 'i':
- if (strlen(optarg) > 3 &&
- strncasecmp(optarg, "hci", 3) == 0)
- index = atoi(optarg + 3);
- else
- index = atoi(optarg);
+ set_index(optarg);
break;
case 'h':
default:
@@ -4855,10 +4850,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- c->func(mgmt, index, argc, argv);
+ c->func(mgmt, mgmt_index, argc, argv);
}
- register_mgmt_callbacks(mgmt, index);
+ register_mgmt_callbacks(mgmt, mgmt_index);
/* Interactive mode */
if (!argc)
@@ -4874,12 +4869,10 @@ int main(int argc, char *argv[])
rl_erase_empty_line = 1;
rl_callback_handler_install(NULL, rl_handler);
- update_prompt(index);
+ update_prompt(mgmt_index);
rl_redisplay();
}
- mgmt_index = index;
-
status = mainloop_run();
if (input) {
--
2.14.1