diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e218a87..3911ba2 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
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);
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:
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)
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) {