diff --git a/android/main.c b/android/main.c
index 72e47f2..994d796 100644
--- a/android/main.c
+++ b/android/main.c
}
static gboolean option_version = FALSE;
+static gint option_index = MGMT_INDEX_NONE;
static GOptionEntry options[] = {
{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
"Show version information and exit", NULL },
+ { "index", 'i', 0, G_OPTION_ARG_INT, &option_index,
+ "Use specified controller", "INDEX"},
{ NULL }
};
static void mgmt_index_added_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
+ uint16_t opt_index = option_index;
+
DBG("index %u", index);
if (adapter_index != MGMT_INDEX_NONE) {
return;
}
+ if (opt_index != MGMT_INDEX_NONE && opt_index != index) {
+ DBG("skip event for index %u (option %u)", index, opt_index);
+ return;
+ }
+
if (adapter_timeout > 0) {
g_source_remove(adapter_timeout);
adapter_timeout = 0;
const void *param, void *user_data)
{
const struct mgmt_rp_read_index_list *rp = param;
+ uint16_t opt_index = option_index;
uint16_t num;
+ int i;
DBG("");
if (adapter_index != MGMT_INDEX_NONE)
return;
- if (num < 1) {
- adapter_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS,
- adapter_timeout_handler, NULL);
- if (adapter_timeout == 0) {
- error("%s: Failed init timeout", __func__);
- goto error;
- }
+ for (i = 0; i < num; i++) {
+ uint16_t index = btohs(rp->index[i]);
+
+ if (opt_index != MGMT_INDEX_NONE && opt_index != index)
+ continue;
+
+ adapter_index = index;
+ bt_adapter_init(adapter_index, mgmt_if, adapter_ready);
return;
}
- adapter_index = btohs(rp->index[0]);
- bt_adapter_init(adapter_index, mgmt_if, adapter_ready);
- return;
+ if (adapter_index != MGMT_INDEX_NONE)
+ return;
+
+ adapter_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS,
+ adapter_timeout_handler, NULL);
+ if (adapter_timeout > 0)
+ return;
+
+ error("%s: Failed init timeout", __func__);
error:
g_main_loop_quit(event_loop);