diff options
-rw-r--r-- | hcid/dbus-adapter.c | 8 | ||||
-rw-r--r-- | hcid/main.c | 20 |
2 files changed, 21 insertions, 7 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index c7bc7671..bc45da9a 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -397,6 +397,7 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, const char* scan_mode; uint8_t hci_mode; const uint8_t current_mode = adapter->mode; + bdaddr_t local; int dd; dbus_error_init(&err); @@ -422,6 +423,8 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, else return error_invalid_arguments(conn, msg); + str2ba(adapter->address, &local); + dd = hci_open_dev(adapter->dev_id); if (dd < 0) return error_no_such_adapter(conn, msg); @@ -430,9 +433,6 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, (hcid.offmode == HCID_OFFMODE_NOSCAN || (hcid.offmode == HCID_OFFMODE_DEVDOWN && hci_mode != SCAN_DISABLED))) { - bdaddr_t local; - - str2ba(adapter->address, &local); /* The new value will be loaded when the adapter comes UP */ write_device_mode(&local, scan_mode); @@ -457,6 +457,8 @@ static DBusHandlerResult adapter_set_mode(DBusConnection *conn, return error_failed(conn, msg, errno); } + write_device_mode(&local, scan_mode); + goto done; } diff --git a/hcid/main.c b/hcid/main.c index 8abd3d40..5f05543b 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -302,10 +302,12 @@ static void configure_device(int hdev) } } - dr.dev_opt = device_opts->scan; - if (ioctl(s, HCISETSCAN, (unsigned long) &dr) < 0) { - error("Can't set scan mode on hci%d: %s (%d)", - hdev, strerror(errno), errno); + if (!(hcid.offmode == HCID_OFFMODE_DEVDOWN && !strcmp(mode, MODE_OFF))) { + dr.dev_opt = device_opts->scan; + if (ioctl(s, HCISETSCAN, (unsigned long) &dr) < 0) { + error("Can't set scan mode on hci%d: %s (%d)", + hdev, strerror(errno), errno); + } } /* Set device name */ @@ -417,6 +419,16 @@ static void init_device(int hdev) if (hci_test_bit(HCI_RAW, &di.flags)) exit(0); + if (hcid.offmode == HCID_OFFMODE_DEVDOWN) { + char mode[16]; + + if (read_device_mode(&di.bdaddr, mode, sizeof(mode)) == 0 + && strcmp(mode, "off") == 0) { + ioctl(dd, HCIDEVDOWN, dev_id); + exit(0); + } + } + memset(&dr, 0, sizeof(dr)); dr.dev_id = dev_id; device_opts = get_device_opts(dd, dev_id); |