From 770e5445eb76ae30f226c01ec790ca375acb8f47 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 30 Nov 2008 23:44:45 +0200 Subject: ix adapter initialization logic The original variable that was used for the initial DEVDOWN ioctl when OffMode=DevDown and the stored mode is "off" can't really be used elsewhere since it gets reset after calling the ioctl even though e.g. drivers haven't been probed yet. This patch renames the old variable (to first_up) and adds a new one for tracking when the adapter initialization has fully been completed. --- src/adapter.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/adapter.c') diff --git a/src/adapter.c b/src/adapter.c index 332b685d..1a04729c 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -119,7 +119,8 @@ struct btd_adapter { struct hci_dev dev; /* hci info */ gboolean pairable; /* pairable state */ - gboolean first_init; /* Needed for offmode=devdown */ + gboolean first_up; /* Needed for offmode=devdown */ + gboolean initialized; }; static void adapter_set_pairable_timeout(struct btd_adapter *adapter, @@ -2517,13 +2518,13 @@ static void adapter_up(struct btd_adapter *adapter, int dd) char mode[14], srcaddr[18]; int i; uint8_t scan_mode; - gboolean powered, first_init = FALSE; + gboolean powered, first_up = FALSE; ba2str(&adapter->bdaddr, srcaddr); - if (adapter->first_init == TRUE) { - first_init = TRUE; - adapter->first_init = FALSE; + if (adapter->first_up == TRUE) { + first_up = TRUE; + adapter->first_up = FALSE; } adapter->up = 1; @@ -2549,7 +2550,7 @@ static void adapter_up(struct btd_adapter *adapter, int dd) adapter->mode = MODE_OFF; scan_mode = SCAN_DISABLED; } else if (main_opts.offmode == HCID_OFFMODE_DEVDOWN) { - if (first_init) { + if (first_up) { ioctl(dd, HCIDEVDOWN, adapter->dev_id); return; } @@ -2578,7 +2579,7 @@ proceed: /* retrieve the active connections: address the scenario where * the are active connections before the daemon've started */ - if (first_init) { + if (adapter->initialized == FALSE) { struct hci_conn_list_req *cl = NULL; struct hci_conn_info *ci; @@ -2602,9 +2603,10 @@ proceed: ADAPTER_INTERFACE, "Powered", DBUS_TYPE_BOOLEAN, &powered); - if (first_init) { + if (adapter->initialized == FALSE) { load_drivers(adapter); load_devices(adapter); + adapter->initialized = TRUE; } } @@ -2932,7 +2934,7 @@ struct btd_adapter *adapter_create(DBusConnection *conn, int id) } adapter->dev_id = id; - adapter->first_init = TRUE; + adapter->first_up = TRUE; adapter->state |= RESOLVE_NAME; adapter->path = g_strdup(path); -- cgit