Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 1 | From 977321f2c7f974ea68a3d90df296c66189a3f254 Mon Sep 17 00:00:00 2001 |
| 2 | From: Lei Maohui <leimaohui@cn.fujitsu.com> |
| 3 | Date: Fri, 21 Jun 2019 17:57:35 +0900 |
| 4 | Subject: [PATCH] CVE-2018-10910 |
| 5 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 6 | A bug in Bluez may allow for the Bluetooth Discoverable state being set to on |
| 7 | when no Bluetooth agent is registered with the system. This situation could |
| 8 | lead to the unauthorized pairing of certain Bluetooth devices without any |
| 9 | form of authentication. |
| 10 | |
| 11 | CVE: CVE-2018-10910 |
| 12 | Upstream-Status: Backport |
| 13 | Signed-off-by: Ross Burton <ross.burton@intel.com> |
| 14 | |
| 15 | Subject: [PATCH BlueZ 1/4] client: Add discoverable-timeout command |
| 16 | From: Luiz Augusto von Dentz <luiz.dentz () gmail ! com> |
| 17 | Date: 2018-07-25 10:20:32 |
| 18 | Message-ID: 20180725102035.19439-1-luiz.dentz () gmail ! com |
| 19 | [Download RAW message or body] |
| 20 | |
| 21 | From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> |
| 22 | |
| 23 | This adds discoverable-timeout command which can be used to get/set |
| 24 | DiscoverableTimeout property: |
| 25 | |
| 26 | [bluetooth]# discoverable-timeout 180 |
| 27 | Changing discoverable-timeout 180 succeeded |
| 28 | --- |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 29 | client/main.c | 82 +++++++++++++++++++++++++++++++++- |
| 30 | doc/adapter-api.txt | 6 +++ |
| 31 | src/adapter.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++------ |
| 32 | 3 files changed, 198 insertions(+), 15 deletions(-) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 33 | |
| 34 | diff --git a/client/main.c b/client/main.c |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 35 | index 87323d8..1a66a3a 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | --- a/client/main.c |
| 37 | +++ b/client/main.c |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 38 | @@ -877,6 +877,7 @@ static void cmd_show(int argc, char *argv[]) |
| 39 | print_property(proxy, "Class"); |
| 40 | print_property(proxy, "Powered"); |
| 41 | print_property(proxy, "Discoverable"); |
| 42 | + print_property(proxy, "DiscoverableTimeout"); |
| 43 | print_property(proxy, "Pairable"); |
| 44 | print_uuids(proxy); |
| 45 | print_property(proxy, "Modalias"); |
| 46 | @@ -1061,6 +1062,47 @@ static void cmd_discoverable(int argc, char *argv[]) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 47 | return bt_shell_noninteractive_quit(EXIT_FAILURE); |
| 48 | } |
| 49 | |
| 50 | +static void cmd_discoverable_timeout(int argc, char *argv[]) |
| 51 | +{ |
| 52 | + uint32_t value; |
| 53 | + char *endptr = NULL; |
| 54 | + char *str; |
| 55 | + |
| 56 | + if (argc < 2) { |
| 57 | + DBusMessageIter iter; |
| 58 | + |
| 59 | + if (!g_dbus_proxy_get_property(default_ctrl->proxy, |
| 60 | + "DiscoverableTimeout", &iter)) { |
| 61 | + bt_shell_printf("Unable to get DiscoverableTimeout\n"); |
| 62 | + return bt_shell_noninteractive_quit(EXIT_FAILURE); |
| 63 | + } |
| 64 | + |
| 65 | + dbus_message_iter_get_basic(&iter, &value); |
| 66 | + |
| 67 | + bt_shell_printf("DiscoverableTimeout: %d seconds\n", value); |
| 68 | + |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + value = strtol(argv[1], &endptr, 0); |
| 73 | + if (!endptr || *endptr != '\0' || value > UINT32_MAX) { |
| 74 | + bt_shell_printf("Invalid argument\n"); |
| 75 | + return bt_shell_noninteractive_quit(EXIT_FAILURE); |
| 76 | + } |
| 77 | + |
| 78 | + str = g_strdup_printf("discoverable-timeout %d", value); |
| 79 | + |
| 80 | + if (g_dbus_proxy_set_property_basic(default_ctrl->proxy, |
| 81 | + "DiscoverableTimeout", |
| 82 | + DBUS_TYPE_UINT32, &value, |
| 83 | + generic_callback, str, g_free)) |
| 84 | + return; |
| 85 | + |
| 86 | + g_free(str); |
| 87 | + |
| 88 | + return bt_shell_noninteractive_quit(EXIT_FAILURE); |
| 89 | +} |
| 90 | + |
| 91 | static void cmd_agent(int argc, char *argv[]) |
| 92 | { |
| 93 | dbus_bool_t enable; |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 94 | @@ -1124,6 +1166,7 @@ static struct set_discovery_filter_args { |
| 95 | char **uuids; |
| 96 | size_t uuids_len; |
| 97 | dbus_bool_t duplicate; |
| 98 | + dbus_bool_t discoverable; |
| 99 | bool set; |
| 100 | } filter = { |
| 101 | .rssi = DISTANCE_VAL_INVALID, |
| 102 | @@ -1163,6 +1206,11 @@ static void set_discovery_filter_setup(DBusMessageIter *iter, void *user_data) |
| 103 | DBUS_TYPE_BOOLEAN, |
| 104 | &args->duplicate); |
| 105 | |
| 106 | + if (args->discoverable) |
| 107 | + g_dbus_dict_append_entry(&dict, "Discoverable", |
| 108 | + DBUS_TYPE_BOOLEAN, |
| 109 | + &args->discoverable); |
| 110 | + |
| 111 | dbus_message_iter_close_container(iter, &dict); |
| 112 | } |
| 113 | |
| 114 | @@ -1320,6 +1368,26 @@ static void cmd_scan_filter_duplicate_data(int argc, char *argv[]) |
| 115 | filter.set = false; |
| 116 | } |
| 117 | |
| 118 | +static void cmd_scan_filter_discoverable(int argc, char *argv[]) |
| 119 | +{ |
| 120 | + if (argc < 2 || !strlen(argv[1])) { |
| 121 | + bt_shell_printf("Discoverable: %s\n", |
| 122 | + filter.discoverable ? "on" : "off"); |
| 123 | + return bt_shell_noninteractive_quit(EXIT_SUCCESS); |
| 124 | + } |
| 125 | + |
| 126 | + if (!strcmp(argv[1], "on")) |
| 127 | + filter.discoverable = true; |
| 128 | + else if (!strcmp(argv[1], "off")) |
| 129 | + filter.discoverable = false; |
| 130 | + else { |
| 131 | + bt_shell_printf("Invalid option: %s\n", argv[1]); |
| 132 | + return bt_shell_noninteractive_quit(EXIT_FAILURE); |
| 133 | + } |
| 134 | + |
| 135 | + filter.set = false; |
| 136 | +} |
| 137 | + |
| 138 | static void filter_clear_uuids(void) |
| 139 | { |
| 140 | g_strfreev(filter.uuids); |
| 141 | @@ -1348,6 +1416,11 @@ static void filter_clear_duplicate(void) |
| 142 | filter.duplicate = false; |
| 143 | } |
| 144 | |
| 145 | +static void filter_clear_discoverable(void) |
| 146 | +{ |
| 147 | + filter.discoverable = false; |
| 148 | +} |
| 149 | + |
| 150 | struct clear_entry { |
| 151 | const char *name; |
| 152 | void (*clear) (void); |
| 153 | @@ -1359,6 +1432,7 @@ static const struct clear_entry filter_clear[] = { |
| 154 | { "pathloss", filter_clear_pathloss }, |
| 155 | { "transport", filter_clear_transport }, |
| 156 | { "duplicate-data", filter_clear_duplicate }, |
| 157 | + { "discoverable", filter_clear_discoverable }, |
| 158 | {} |
| 159 | }; |
| 160 | |
| 161 | @@ -2468,7 +2542,11 @@ static const struct bt_shell_menu scan_menu = { |
| 162 | { "duplicate-data", "[on/off]", cmd_scan_filter_duplicate_data, |
| 163 | "Set/Get duplicate data filter", |
| 164 | NULL }, |
| 165 | - { "clear", "[uuids/rssi/pathloss/transport/duplicate-data]", |
| 166 | + { "discoverable", "[on/off]", cmd_scan_filter_discoverable, |
| 167 | + "Set/Get discoverable filter", |
| 168 | + NULL }, |
| 169 | + { "clear", |
| 170 | + "[uuids/rssi/pathloss/transport/duplicate-data/discoverable]", |
| 171 | cmd_scan_filter_clear, |
| 172 | "Clears discovery filter.", |
| 173 | filter_clear_generator }, |
| 174 | @@ -2549,6 +2627,8 @@ static const struct bt_shell_menu main_menu = { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 175 | { "discoverable", "<on/off>", cmd_discoverable, |
| 176 | "Set controller discoverable mode", |
| 177 | NULL }, |
| 178 | + { "discoverable-timeout", "[value]", cmd_discoverable_timeout, |
| 179 | + "Set discoverable timeout", NULL }, |
| 180 | { "agent", "<on/off/capability>", cmd_agent, |
| 181 | "Enable/disable agent with given capability", |
| 182 | capability_generator}, |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 183 | diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt |
| 184 | index d14d0ca..4791af2 100644 |
| 185 | --- a/doc/adapter-api.txt |
| 186 | +++ b/doc/adapter-api.txt |
| 187 | @@ -113,6 +113,12 @@ Methods void StartDiscovery() |
| 188 | generated for either ManufacturerData and |
| 189 | ServiceData everytime they are discovered. |
| 190 | |
| 191 | + bool Discoverable (Default: false) |
| 192 | + |
| 193 | + Make adapter discoverable while discovering, |
| 194 | + if the adapter is already discoverable this |
| 195 | + setting this filter won't do anything. |
| 196 | + |
| 197 | When discovery filter is set, Device objects will be |
| 198 | created as new devices with matching criteria are |
| 199 | discovered regardless of they are connectable or |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 200 | diff --git a/src/adapter.c b/src/adapter.c |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 201 | index af340fd..822bd34 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 202 | --- a/src/adapter.c |
| 203 | +++ b/src/adapter.c |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 204 | @@ -157,6 +157,7 @@ struct discovery_filter { |
| 205 | int16_t rssi; |
| 206 | GSList *uuids; |
| 207 | bool duplicate; |
| 208 | + bool discoverable; |
| 209 | }; |
| 210 | |
| 211 | struct watch_client { |
| 212 | @@ -196,6 +197,7 @@ struct btd_adapter { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 213 | char *name; /* controller device name */ |
| 214 | char *short_name; /* controller short name */ |
| 215 | uint32_t supported_settings; /* controller supported settings */ |
| 216 | + uint32_t pending_settings; /* pending controller settings */ |
| 217 | uint32_t current_settings; /* current controller settings */ |
| 218 | |
| 219 | char *path; /* adapter object path */ |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 220 | @@ -213,6 +215,7 @@ struct btd_adapter { |
| 221 | |
| 222 | bool discovering; /* discovering property state */ |
| 223 | bool filtered_discovery; /* we are doing filtered discovery */ |
| 224 | + bool filtered_discoverable; /* we are doing filtered discovery */ |
| 225 | bool no_scan_restart_delay; /* when this flag is set, restart scan |
| 226 | * without delay */ |
| 227 | uint8_t discovery_type; /* current active discovery type */ |
| 228 | @@ -509,8 +512,10 @@ static void settings_changed(struct btd_adapter *adapter, uint32_t settings) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 229 | changed_mask = adapter->current_settings ^ settings; |
| 230 | |
| 231 | adapter->current_settings = settings; |
| 232 | + adapter->pending_settings &= ~changed_mask; |
| 233 | |
| 234 | DBG("Changed settings: 0x%08x", changed_mask); |
| 235 | + DBG("Pending settings: 0x%08x", adapter->pending_settings); |
| 236 | |
| 237 | if (changed_mask & MGMT_SETTING_POWERED) { |
| 238 | g_dbus_emit_property_changed(dbus_conn, adapter->path, |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 239 | @@ -596,10 +601,31 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 240 | uint8_t mode) |
| 241 | { |
| 242 | struct mgmt_mode cp; |
| 243 | + uint32_t setting = 0; |
| 244 | |
| 245 | memset(&cp, 0, sizeof(cp)); |
| 246 | cp.val = mode; |
| 247 | |
| 248 | + switch (mode) { |
| 249 | + case MGMT_OP_SET_POWERED: |
| 250 | + setting = MGMT_SETTING_POWERED; |
| 251 | + break; |
| 252 | + case MGMT_OP_SET_CONNECTABLE: |
| 253 | + setting = MGMT_SETTING_CONNECTABLE; |
| 254 | + break; |
| 255 | + case MGMT_OP_SET_FAST_CONNECTABLE: |
| 256 | + setting = MGMT_SETTING_FAST_CONNECTABLE; |
| 257 | + break; |
| 258 | + case MGMT_OP_SET_DISCOVERABLE: |
| 259 | + setting = MGMT_SETTING_DISCOVERABLE; |
| 260 | + break; |
| 261 | + case MGMT_OP_SET_BONDABLE: |
| 262 | + setting = MGMT_SETTING_DISCOVERABLE; |
| 263 | + break; |
| 264 | + } |
| 265 | + |
| 266 | + adapter->pending_settings |= setting; |
| 267 | + |
| 268 | DBG("sending set mode command for index %u", adapter->dev_id); |
| 269 | |
| 270 | if (mgmt_send(adapter->mgmt, opcode, |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 271 | @@ -1818,7 +1844,17 @@ static void discovery_free(void *user_data) |
| 272 | g_free(client); |
| 273 | } |
| 274 | |
| 275 | -static void discovery_remove(struct watch_client *client) |
| 276 | +static bool set_filtered_discoverable(struct btd_adapter *adapter, bool enable) |
| 277 | +{ |
| 278 | + if (adapter->filtered_discoverable == enable) |
| 279 | + return true; |
| 280 | + |
| 281 | + adapter->filtered_discoverable = enable; |
| 282 | + |
| 283 | + return set_discoverable(adapter, enable, 0); |
| 284 | +} |
| 285 | + |
| 286 | +static void discovery_remove(struct watch_client *client, bool exit) |
| 287 | { |
| 288 | struct btd_adapter *adapter = client->adapter; |
| 289 | |
| 290 | @@ -1830,7 +1866,27 @@ static void discovery_remove(struct watch_client *client) |
| 291 | adapter->discovery_list = g_slist_remove(adapter->discovery_list, |
| 292 | client); |
| 293 | |
| 294 | - discovery_free(client); |
| 295 | + if (adapter->filtered_discoverable && |
| 296 | + client->discovery_filter->discoverable) { |
| 297 | + GSList *l; |
| 298 | + |
| 299 | + for (l = adapter->discovery_list; l; l = g_slist_next(l)) { |
| 300 | + struct watch_client *client = l->data; |
| 301 | + |
| 302 | + if (client->discovery_filter->discoverable) |
| 303 | + break; |
| 304 | + } |
| 305 | + |
| 306 | + /* Disable filtered discoverable if there are no clients */ |
| 307 | + if (!l) |
| 308 | + set_filtered_discoverable(adapter, false); |
| 309 | + } |
| 310 | + |
| 311 | + if (!exit && client->discovery_filter) |
| 312 | + adapter->set_filter_list = g_slist_prepend( |
| 313 | + adapter->set_filter_list, client); |
| 314 | + else |
| 315 | + discovery_free(client); |
| 316 | |
| 317 | /* |
| 318 | * If there are other client discoveries in progress, then leave |
| 319 | @@ -1859,8 +1915,11 @@ static void stop_discovery_complete(uint8_t status, uint16_t length, |
| 320 | goto done; |
| 321 | } |
| 322 | |
| 323 | - if (client->msg) |
| 324 | + if (client->msg) { |
| 325 | g_dbus_send_reply(dbus_conn, client->msg, DBUS_TYPE_INVALID); |
| 326 | + dbus_message_unref(client->msg); |
| 327 | + client->msg = NULL; |
| 328 | + } |
| 329 | |
| 330 | adapter->discovery_type = 0x00; |
| 331 | adapter->discovery_enable = 0x00; |
| 332 | @@ -1873,7 +1932,7 @@ static void stop_discovery_complete(uint8_t status, uint16_t length, |
| 333 | trigger_passive_scanning(adapter); |
| 334 | |
| 335 | done: |
| 336 | - discovery_remove(client); |
| 337 | + discovery_remove(client, false); |
| 338 | } |
| 339 | |
| 340 | static int compare_sender(gconstpointer a, gconstpointer b) |
| 341 | @@ -2094,14 +2153,14 @@ static int update_discovery_filter(struct btd_adapter *adapter) |
| 342 | return -EINPROGRESS; |
| 343 | } |
| 344 | |
| 345 | -static int discovery_stop(struct watch_client *client) |
| 346 | +static int discovery_stop(struct watch_client *client, bool exit) |
| 347 | { |
| 348 | struct btd_adapter *adapter = client->adapter; |
| 349 | struct mgmt_cp_stop_discovery cp; |
| 350 | |
| 351 | /* Check if there are more client discovering */ |
| 352 | if (g_slist_next(adapter->discovery_list)) { |
| 353 | - discovery_remove(client); |
| 354 | + discovery_remove(client, exit); |
| 355 | update_discovery_filter(adapter); |
| 356 | return 0; |
| 357 | } |
| 358 | @@ -2111,7 +2170,7 @@ static int discovery_stop(struct watch_client *client) |
| 359 | * and so it is enough to send out the signal and just return. |
| 360 | */ |
| 361 | if (adapter->discovery_enable == 0x00) { |
| 362 | - discovery_remove(client); |
| 363 | + discovery_remove(client, exit); |
| 364 | adapter->discovering = false; |
| 365 | g_dbus_emit_property_changed(dbus_conn, adapter->path, |
| 366 | ADAPTER_INTERFACE, "Discovering"); |
| 367 | @@ -2136,7 +2195,7 @@ static void discovery_disconnect(DBusConnection *conn, void *user_data) |
| 368 | |
| 369 | DBG("owner %s", client->owner); |
| 370 | |
| 371 | - discovery_stop(client); |
| 372 | + discovery_stop(client, true); |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | @@ -2200,6 +2259,15 @@ static DBusMessage *start_discovery(DBusConnection *conn, |
| 377 | adapter->set_filter_list, client); |
| 378 | adapter->discovery_list = g_slist_prepend( |
| 379 | adapter->discovery_list, client); |
| 380 | + |
| 381 | + /* Reset discoverable filter if already set */ |
| 382 | + if (adapter->current_settings & MGMT_OP_SET_DISCOVERABLE) |
| 383 | + goto done; |
| 384 | + |
| 385 | + /* Set discoverable if filter requires and it*/ |
| 386 | + if (client->discovery_filter->discoverable) |
| 387 | + set_filtered_discoverable(adapter, true); |
| 388 | + |
| 389 | goto done; |
| 390 | } |
| 391 | |
| 392 | @@ -2324,6 +2392,17 @@ static bool parse_duplicate_data(DBusMessageIter *value, |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | +static bool parse_discoverable(DBusMessageIter *value, |
| 397 | + struct discovery_filter *filter) |
| 398 | +{ |
| 399 | + if (dbus_message_iter_get_arg_type(value) != DBUS_TYPE_BOOLEAN) |
| 400 | + return false; |
| 401 | + |
| 402 | + dbus_message_iter_get_basic(value, &filter->discoverable); |
| 403 | + |
| 404 | + return true; |
| 405 | +} |
| 406 | + |
| 407 | struct filter_parser { |
| 408 | const char *name; |
| 409 | bool (*func)(DBusMessageIter *iter, struct discovery_filter *filter); |
| 410 | @@ -2333,6 +2412,7 @@ struct filter_parser { |
| 411 | { "Pathloss", parse_pathloss }, |
| 412 | { "Transport", parse_transport }, |
| 413 | { "DuplicateData", parse_duplicate_data }, |
| 414 | + { "Discoverable", parse_discoverable }, |
| 415 | { } |
| 416 | }; |
| 417 | |
| 418 | @@ -2372,6 +2452,7 @@ static bool parse_discovery_filter_dict(struct btd_adapter *adapter, |
| 419 | (*filter)->rssi = DISTANCE_VAL_INVALID; |
| 420 | (*filter)->type = get_scan_type(adapter); |
| 421 | (*filter)->duplicate = false; |
| 422 | + (*filter)->discoverable = false; |
| 423 | |
| 424 | dbus_message_iter_init(msg, &iter); |
| 425 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || |
| 426 | @@ -2417,8 +2498,10 @@ static bool parse_discovery_filter_dict(struct btd_adapter *adapter, |
| 427 | goto invalid_args; |
| 428 | |
| 429 | DBG("filtered discovery params: transport: %d rssi: %d pathloss: %d " |
| 430 | - " duplicate data: %s ", (*filter)->type, (*filter)->rssi, |
| 431 | - (*filter)->pathloss, (*filter)->duplicate ? "true" : "false"); |
| 432 | + " duplicate data: %s discoverable %s", (*filter)->type, |
| 433 | + (*filter)->rssi, (*filter)->pathloss, |
| 434 | + (*filter)->duplicate ? "true" : "false", |
| 435 | + (*filter)->discoverable ? "true" : "false"); |
| 436 | |
| 437 | return true; |
| 438 | |
| 439 | @@ -2510,7 +2593,7 @@ static DBusMessage *stop_discovery(DBusConnection *conn, |
| 440 | if (client->msg) |
| 441 | return btd_error_busy(msg); |
| 442 | |
| 443 | - err = discovery_stop(client); |
| 444 | + err = discovery_stop(client, false); |
| 445 | switch (err) { |
| 446 | case 0: |
| 447 | return dbus_message_new_method_return(msg); |
| 448 | @@ -2739,13 +2822,15 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 449 | else |
| 450 | current_enable = FALSE; |
| 451 | |
| 452 | - if (enable == current_enable) { |
| 453 | + if (enable == current_enable || adapter->pending_settings & setting) { |
| 454 | g_dbus_pending_property_success(id); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | mode = (enable == TRUE) ? 0x01 : 0x00; |
| 459 | |
| 460 | + adapter->pending_settings |= setting; |
| 461 | + |
| 462 | switch (setting) { |
| 463 | case MGMT_SETTING_POWERED: |
| 464 | opcode = MGMT_OP_SET_POWERED; |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 465 | @@ -2798,7 +2883,7 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 466 | data->id = id; |
| 467 | |
| 468 | if (mgmt_send(adapter->mgmt, opcode, adapter->dev_id, len, param, |
| 469 | - property_set_mode_complete, data, g_free) > 0) |
| 470 | + property_set_mode_complete, data, g_free) > 0) |
| 471 | return; |
| 472 | |
| 473 | g_free(data); |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 474 | @@ -2875,6 +2960,7 @@ static void property_set_discoverable_timeout( |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 475 | GDBusPendingPropertySet id, void *user_data) |
| 476 | { |
| 477 | struct btd_adapter *adapter = user_data; |
| 478 | + bool enabled; |
| 479 | dbus_uint32_t value; |
| 480 | |
| 481 | dbus_message_iter_get_basic(iter, &value); |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 482 | @@ -2888,8 +2974,19 @@ static void property_set_discoverable_timeout( |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 483 | g_dbus_emit_property_changed(dbus_conn, adapter->path, |
| 484 | ADAPTER_INTERFACE, "DiscoverableTimeout"); |
| 485 | |
| 486 | + if (adapter->pending_settings & MGMT_SETTING_DISCOVERABLE) { |
| 487 | + if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE) |
| 488 | + enabled = false; |
| 489 | + else |
| 490 | + enabled = true; |
| 491 | + } else { |
| 492 | + if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE) |
| 493 | + enabled = true; |
| 494 | + else |
| 495 | + enabled = false; |
| 496 | + } |
| 497 | |
| 498 | - if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE) |
| 499 | + if (enabled) |
| 500 | set_discoverable(adapter, 0x01, adapter->discoverable_timeout); |
| 501 | } |
| 502 | |
| 503 | -- |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 504 | 2.7.4 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 505 | |