This makes hci_suspend_notifier use the hci_*_sync which can be executed synchronously which is allowed in the suspend_notifier and simplifies a lot of the handling since the status of each command can be checked inline so no other work need to be scheduled thus can be performed without using of a state machine.
Unified · Split
| @@ -523,7 +523,6 @@ struct hci_dev { · 522 unmodified lines | |||
| 523 | bool advertising_paused; | 523 | bool advertising_paused; |
| 524 | 524 | ||
| 525 | struct notifier_block suspend_notifier; | 525 | struct notifier_block suspend_notifier; |
| 526 | struct work_struct suspend_prepare; | ||
| 527 | enum suspended_state suspend_state_next; | 526 | enum suspended_state suspend_state_next; |
| 528 | enum suspended_state suspend_state; | 527 | enum suspended_state suspend_state; |
| 529 | bool scanning_paused; | 528 | bool scanning_paused; |
| @@ -532,9 +531,6 @@ struct hci_dev { · 2 unmodified lines | |||
| 532 | bdaddr_t wake_addr; | 531 | bdaddr_t wake_addr; |
| 533 | u8 wake_addr_type; | 532 | u8 wake_addr_type; |
| 534 | 533 | ||
| 535 | wait_queue_head_t suspend_wait_q; | ||
| 536 | DECLARE_BITMAP(suspend_tasks, __SUSPEND_NUM_TASKS); | ||
| 537 | |||
| 538 | struct hci_conn_hash conn_hash; | 534 | struct hci_conn_hash conn_hash; |
| 539 | 535 | ||
| 540 | struct list_head mgmt_pending; | 536 | struct list_head mgmt_pending; |
| @@ -92,3 +92,6 @@ int hci_set_powered_sync(struct hci_dev *hdev, u8 val); · 91 unmodified lines | |||
| 92 | 92 | ||
| 93 | int hci_start_discovery_sync(struct hci_dev *hdev); | 93 | int hci_start_discovery_sync(struct hci_dev *hdev); |
| 94 | int hci_stop_discovery_sync(struct hci_dev *hdev); | 94 | int hci_stop_discovery_sync(struct hci_dev *hdev); |
| 95 | |||
| 96 | int hci_suspend_sync(struct hci_dev *hdev); | ||
| 97 | int hci_resume_sync(struct hci_dev *hdev); | ||
| @@ -900,16 +900,6 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status) · 899 unmodified lines | |||
| 900 | 900 | ||
| 901 | hci_conn_del(conn); | 901 | hci_conn_del(conn); |
| 902 | 902 | ||
| 903 | /* The suspend notifier is waiting for all devices to disconnect and an | ||
| 904 | * LE connect cancel will result in an hci_le_conn_failed. Once the last | ||
| 905 | * connection is deleted, we should also wake the suspend queue to | ||
| 906 | * complete suspend operations. | ||
| 907 | */ | ||
| 908 | if (list_empty(&hdev->conn_hash.list) && | ||
| 909 | test_and_clear_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks)) { | ||
| 910 | wake_up(&hdev->suspend_wait_q); | ||
| 911 | } | ||
| 912 | |||
| 913 | /* Since we may have temporarily stopped the background scanning in | 903 | /* Since we may have temporarily stopped the background scanning in |
| 914 | * favor of connection establishment, we should restart it. | 904 | * favor of connection establishment, we should restart it. |
| 915 | */ | 905 | */ |
| @@ -2374,61 +2374,6 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, · 2373 unmodified lines | |||
| 2374 | } | 2374 | } |
| 2375 | } | 2375 | } |
| 2376 | 2376 | ||
| 2377 | static void hci_suspend_clear_tasks(struct hci_dev *hdev) | ||
| 2378 | { | ||
| 2379 | int i; | ||
| 2380 | |||
| 2381 | for (i = 0; i < __SUSPEND_NUM_TASKS; i++) | ||
| 2382 | clear_bit(i, hdev->suspend_tasks); | ||
| 2383 | |||
| 2384 | wake_up(&hdev->suspend_wait_q); | ||
| 2385 | } | ||
| 2386 | |||
| 2387 | static int hci_suspend_wait_event(struct hci_dev *hdev) | ||
| 2388 | { | ||
| 2389 | #define WAKE_COND \ | ||
| 2390 | (find_first_bit(hdev->suspend_tasks, __SUSPEND_NUM_TASKS) == \ | ||
| 2391 | __SUSPEND_NUM_TASKS) | ||
| 2392 | |||
| 2393 | int i; | ||
| 2394 | int ret = wait_event_timeout(hdev->suspend_wait_q, | ||
| 2395 | WAKE_COND, SUSPEND_NOTIFIER_TIMEOUT); | ||
| 2396 | |||
| 2397 | if (ret == 0) { | ||
| 2398 | bt_dev_err(hdev, "Timed out waiting for suspend events"); | ||
| 2399 | for (i = 0; i < __SUSPEND_NUM_TASKS; ++i) { | ||
| 2400 | if (test_bit(i, hdev->suspend_tasks)) | ||
| 2401 | bt_dev_err(hdev, "Suspend timeout bit: %d", i); | ||
| 2402 | clear_bit(i, hdev->suspend_tasks); | ||
| 2403 | } | ||
| 2404 | |||
| 2405 | ret = -ETIMEDOUT; | ||
| 2406 | } else { | ||
| 2407 | ret = 0; | ||
| 2408 | } | ||
| 2409 | |||
| 2410 | return ret; | ||
| 2411 | } | ||
| 2412 | |||
| 2413 | static void hci_prepare_suspend(struct work_struct *work) | ||
| 2414 | { | ||
| 2415 | struct hci_dev *hdev = | ||
| 2416 | container_of(work, struct hci_dev, suspend_prepare); | ||
| 2417 | |||
| 2418 | hci_dev_lock(hdev); | ||
| 2419 | hci_req_prepare_suspend(hdev, hdev->suspend_state_next); | ||
| 2420 | hci_dev_unlock(hdev); | ||
| 2421 | } | ||
| 2422 | |||
| 2423 | static int hci_change_suspend_state(struct hci_dev *hdev, | ||
| 2424 | enum suspended_state next) | ||
| 2425 | { | ||
| 2426 | hdev->suspend_state_next = next; | ||
| 2427 | set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); | ||
| 2428 | queue_work(hdev->req_workqueue, &hdev->suspend_prepare); | ||
| 2429 | return hci_suspend_wait_event(hdev); | ||
| 2430 | } | ||
| 2431 | |||
| 2432 | static void hci_clear_wake_reason(struct hci_dev *hdev) | 2377 | static void hci_clear_wake_reason(struct hci_dev *hdev) |
| 2433 | { | 2378 | { |
| 2434 | hci_dev_lock(hdev); | 2379 | hci_dev_lock(hdev); |
| @@ -2565,7 +2510,6 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv) · 130 unmodified lines | |||
| 2565 | INIT_WORK(&hdev->tx_work, hci_tx_work); | 2510 | INIT_WORK(&hdev->tx_work, hci_tx_work); |
| 2566 | INIT_WORK(&hdev->power_on, hci_power_on); | 2511 | INIT_WORK(&hdev->power_on, hci_power_on); |
| 2567 | INIT_WORK(&hdev->error_reset, hci_error_reset); | 2512 | INIT_WORK(&hdev->error_reset, hci_error_reset); |
| 2568 | INIT_WORK(&hdev->suspend_prepare, hci_prepare_suspend); | ||
| 2569 | 2513 | ||
| 2570 | hci_cmd_sync_init(hdev); | 2514 | hci_cmd_sync_init(hdev); |
| 2571 | 2515 | ||
| @@ -2576,7 +2520,6 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv) · 4 unmodified lines | |||
| 2576 | skb_queue_head_init(&hdev->raw_q); | 2520 | skb_queue_head_init(&hdev->raw_q); |
| 2577 | 2521 | ||
| 2578 | init_waitqueue_head(&hdev->req_wait_q); | 2522 | init_waitqueue_head(&hdev->req_wait_q); |
| 2579 | init_waitqueue_head(&hdev->suspend_wait_q); | ||
| 2580 | 2523 | ||
| 2581 | INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); | 2524 | INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); |
| 2582 | INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); | 2525 | INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); |
| @@ -2729,11 +2672,8 @@ void hci_unregister_dev(struct hci_dev *hdev) · 146 unmodified lines | |||
| 2729 | 2672 | ||
| 2730 | hci_cmd_sync_clear(hdev); | 2673 | hci_cmd_sync_clear(hdev); |
| 2731 | 2674 | ||
| 2732 | if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { | 2675 | if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) |
| 2733 | hci_suspend_clear_tasks(hdev); | ||
| 2734 | unregister_pm_notifier(&hdev->suspend_notifier); | 2676 | unregister_pm_notifier(&hdev->suspend_notifier); |
| 2735 | cancel_work_sync(&hdev->suspend_prepare); | ||
| 2736 | } | ||
| 2737 | 2677 | ||
| 2738 | msft_unregister(hdev); | 2678 | msft_unregister(hdev); |
| 2739 | 2679 | ||
| @@ -2800,7 +2740,6 @@ EXPORT_SYMBOL(hci_release_dev); · 60 unmodified lines | |||
| 2800 | int hci_suspend_dev(struct hci_dev *hdev) | 2740 | int hci_suspend_dev(struct hci_dev *hdev) |
| 2801 | { | 2741 | { |
| 2802 | int ret; | 2742 | int ret; |
| 2803 | u8 state = BT_RUNNING; | ||
| 2804 | 2743 | ||
| 2805 | bt_dev_dbg(hdev, ""); | 2744 | bt_dev_dbg(hdev, ""); |
| 2806 | 2745 | ||
| @@ -2809,40 +2748,17 @@ int hci_suspend_dev(struct hci_dev *hdev) · 2 unmodified lines | |||
| 2809 | hci_dev_test_flag(hdev, HCI_UNREGISTER)) | 2748 | hci_dev_test_flag(hdev, HCI_UNREGISTER)) |
| 2810 | return 0; | 2749 | return 0; |
| 2811 | 2750 | ||
| 2812 | /* If powering down, wait for completion. */ | 2751 | /* If powering down don't attempt to suspend */ |
| 2813 | if (mgmt_powering_down(hdev)) { | 2752 | if (mgmt_powering_down(hdev)) |
| 2814 | set_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks); | 2753 | return 0; |
| 2815 | ret = hci_suspend_wait_event(hdev); | ||
| 2816 | if (ret) | ||
| 2817 | goto done; | ||
| 2818 | } | ||
| 2819 | |||
| 2820 | /* Suspend consists of two actions: | ||
| 2821 | * - First, disconnect everything and make the controller not | ||
| 2822 | * connectable (disabling scanning) | ||
| 2823 | * - Second, program event filter/accept list and enable scan | ||
| 2824 | */ | ||
| 2825 | ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT); | ||
| 2826 | if (ret) | ||
| 2827 | goto clear; | ||
| 2828 | |||
| 2829 | state = BT_SUSPEND_DISCONNECT; | ||
| 2830 | 2754 | ||
| 2831 | /* Only configure accept list if device may wakeup. */ | 2755 | hci_req_sync_lock(hdev); |
| 2832 | if (hdev->wakeup && hdev->wakeup(hdev)) { | 2756 | ret = hci_suspend_sync(hdev); |
| 2833 | ret = hci_change_suspend_state(hdev, BT_SUSPEND_CONFIGURE_WAKE); | 2757 | hci_req_sync_unlock(hdev); |
| 2834 | if (!ret) | ||
| 2835 | state = BT_SUSPEND_CONFIGURE_WAKE; | ||
| 2836 | } | ||
| 2837 | 2758 | ||
| 2838 | clear: | ||
| 2839 | hci_clear_wake_reason(hdev); | 2759 | hci_clear_wake_reason(hdev); |
| 2840 | mgmt_suspending(hdev, state); | 2760 | mgmt_suspending(hdev, hdev->suspend_state); |
| 2841 | 2761 | ||
| 2842 | done: | ||
| 2843 | /* We always allow suspend even if suspend preparation failed and | ||
| 2844 | * attempt to recover in resume. | ||
| 2845 | */ | ||
| 2846 | hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); | 2762 | hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); |
| 2847 | return ret; | 2763 | return ret; |
| 2848 | } | 2764 | } |
| @@ -2864,10 +2780,12 @@ int hci_resume_dev(struct hci_dev *hdev) · 15 unmodified lines | |||
| 2864 | if (mgmt_powering_down(hdev)) | 2780 | if (mgmt_powering_down(hdev)) |
| 2865 | return 0; | 2781 | return 0; |
| 2866 | 2782 | ||
| 2867 | ret = hci_change_suspend_state(hdev, BT_RUNNING); | 2783 | hci_req_sync_lock(hdev); |
| 2784 | ret = hci_resume_sync(hdev); | ||
| 2785 | hci_req_sync_unlock(hdev); | ||
| 2868 | 2786 | ||
| 2869 | mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, | 2787 | mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, |
| 2870 | hdev->wake_addr_type); | 2788 | hdev->wake_addr_type); |
| 2871 | 2789 | ||
| 2872 | hci_sock_dev_event(hdev, HCI_DEV_RESUME); | 2790 | hci_sock_dev_event(hdev, HCI_DEV_RESUME); |
| 2873 | return ret; | 2791 | return ret; |
| @@ -2414,9 +2414,14 @@ static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) · 2413 unmodified lines | |||
| 2414 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) | 2414 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| 2415 | { | 2415 | { |
| 2416 | struct hci_cp_disconnect *cp; | 2416 | struct hci_cp_disconnect *cp; |
| 2417 | struct hci_conn_params *params; | ||
| 2417 | struct hci_conn *conn; | 2418 | struct hci_conn *conn; |
| 2419 | bool mgmt_conn; | ||
| 2418 | 2420 | ||
| 2419 | if (!status) | 2421 | /* Wait for HCI_EV_DISCONN_COMPLETE if status 0x00 and not suspended |
| 2422 | * otherwise cleanup the connection immediately. | ||
| 2423 | */ | ||
| 2424 | if (!status && !hdev->suspended) | ||
| 2420 | return; | 2425 | return; |
| 2421 | 2426 | ||
| 2422 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); | 2427 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| @@ -2426,7 +2431,10 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) · 3 unmodified lines | |||
| 2426 | hci_dev_lock(hdev); | 2431 | hci_dev_lock(hdev); |
| 2427 | 2432 | ||
| 2428 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); | 2433 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2429 | if (conn) { | 2434 | if (!conn) |
| 2435 | goto unlock; | ||
| 2436 | |||
| 2437 | if (status) { | ||
| 2430 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, | 2438 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
| 2431 | conn->dst_type, status); | 2439 | conn->dst_type, status); |
| 2432 | 2440 | ||
| @@ -2435,14 +2443,48 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) · 2 unmodified lines | |||
| 2435 | hci_enable_advertising(hdev); | 2443 | hci_enable_advertising(hdev); |
| 2436 | } | 2444 | } |
| 2437 | 2445 | ||
| 2438 | /* If the disconnection failed for any reason, the upper layer | 2446 | goto done; |
| 2439 | * does not retry to disconnect in current implementation. | ||
| 2440 | * Hence, we need to do some basic cleanup here and re-enable | ||
| 2441 | * advertising if necessary. | ||
| 2442 | */ | ||
| 2443 | hci_conn_del(conn); | ||
| 2444 | } | 2447 | } |
| 2445 | 2448 | ||
| 2449 | mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); | ||
| 2450 | |||
| 2451 | if (conn->type == ACL_LINK) { | ||
| 2452 | if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) | ||
| 2453 | hci_remove_link_key(hdev, &conn->dst); | ||
| 2454 | } | ||
| 2455 | |||
| 2456 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); | ||
| 2457 | if (params) { | ||
| 2458 | switch (params->auto_connect) { | ||
| 2459 | case HCI_AUTO_CONN_LINK_LOSS: | ||
| 2460 | if (cp->reason != HCI_ERROR_CONNECTION_TIMEOUT) | ||
| 2461 | break; | ||
| 2462 | fallthrough; | ||
| 2463 | |||
| 2464 | case HCI_AUTO_CONN_DIRECT: | ||
| 2465 | case HCI_AUTO_CONN_ALWAYS: | ||
| 2466 | list_del_init(¶ms->action); | ||
| 2467 | list_add(¶ms->action, &hdev->pend_le_conns); | ||
| 2468 | break; | ||
| 2469 | |||
| 2470 | default: | ||
| 2471 | break; | ||
| 2472 | } | ||
| 2473 | } | ||
| 2474 | |||
| 2475 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, | ||
| 2476 | cp->reason, mgmt_conn); | ||
| 2477 | |||
| 2478 | hci_disconn_cfm(conn, cp->reason); | ||
| 2479 | |||
| 2480 | done: | ||
| 2481 | /* If the disconnection failed for any reason, the upper layer | ||
| 2482 | * does not retry to disconnect in current implementation. | ||
| 2483 | * Hence, we need to do some basic cleanup here and re-enable | ||
| 2484 | * advertising if necessary. | ||
| 2485 | */ | ||
| 2486 | hci_conn_del(conn); | ||
| 2487 | unlock: | ||
| 2446 | hci_dev_unlock(hdev); | 2488 | hci_dev_unlock(hdev); |
| 2447 | } | 2489 | } |
| 2448 | 2490 | ||
| @@ -3047,14 +3089,6 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) · 598 unmodified lines | |||
| 3047 | 3089 | ||
| 3048 | hci_conn_del(conn); | 3090 | hci_conn_del(conn); |
| 3049 | 3091 | ||
| 3050 | /* The suspend notifier is waiting for all devices to disconnect so | ||
| 3051 | * clear the bit from pending tasks and inform the wait queue. | ||
| 3052 | */ | ||
| 3053 | if (list_empty(&hdev->conn_hash.list) && | ||
| 3054 | test_and_clear_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks)) { | ||
| 3055 | wake_up(&hdev->suspend_wait_q); | ||
| 3056 | } | ||
| 3057 | |||
| 3058 | unlock: | 3092 | unlock: |
| 3059 | hci_dev_unlock(hdev); | 3093 | hci_dev_unlock(hdev); |
| 3060 | } | 3094 | } |
| @@ -5575,8 +5609,9 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, · 2514 unmodified lines | |||
| 5575 | if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) | 5609 | if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) |
| 5576 | return NULL; | 5610 | return NULL; |
| 5577 | 5611 | ||
| 5578 | /* Ignore if the device is blocked */ | 5612 | /* Ignore if the device is blocked or hdev is suspended */ |
| 5579 | if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type)) | 5613 | if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type) || |
| 5614 | hdev->suspended) | ||
| 5580 | return NULL; | 5615 | return NULL; |
| 5581 | 5616 | ||
| 5582 | /* Most controller will fail if we try to create new connections | 5617 | /* Most controller will fail if we try to create new connections |
| @@ -492,9 +492,6 @@ void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn) · 491 unmodified lines | |||
| 492 | return; | 492 | return; |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | if (hdev->suspended) | ||
| 496 | set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); | ||
| 497 | |||
| 498 | if (use_ext_scan(hdev)) { | 495 | if (use_ext_scan(hdev)) { |
| 499 | struct hci_cp_le_set_ext_scan_enable cp; | 496 | struct hci_cp_le_set_ext_scan_enable cp; |
| 500 | 497 | ||
| @@ -868,8 +865,6 @@ void hci_req_add_le_passive_scan(struct hci_request *req) · 367 unmodified lines | |||
| 868 | if (hdev->suspended) { | 865 | if (hdev->suspended) { |
| 869 | window = hdev->le_scan_window_suspend; | 866 | window = hdev->le_scan_window_suspend; |
| 870 | interval = hdev->le_scan_int_suspend; | 867 | interval = hdev->le_scan_int_suspend; |
| 871 | |||
| 872 | set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); | ||
| 873 | } else if (hci_is_le_conn_scanning(hdev)) { | 868 | } else if (hci_is_le_conn_scanning(hdev)) { |
| 874 | window = hdev->le_scan_window_connect; | 869 | window = hdev->le_scan_window_connect; |
| 875 | interval = hdev->le_scan_int_connect; | 870 | interval = hdev->le_scan_int_connect; |
| @@ -902,59 +897,6 @@ void hci_req_add_le_passive_scan(struct hci_request *req) · 26 unmodified lines | |||
| 902 | addr_resolv); | 897 | addr_resolv); |
| 903 | } | 898 | } |
| 904 | 899 | ||
| 905 | static void hci_req_clear_event_filter(struct hci_request *req) | ||
| 906 | { | ||
| 907 | struct hci_cp_set_event_filter f; | ||
| 908 | |||
| 909 | if (!hci_dev_test_flag(req->hdev, HCI_BREDR_ENABLED)) | ||
| 910 | return; | ||
| 911 | |||
| 912 | if (hci_dev_test_flag(req->hdev, HCI_EVENT_FILTER_CONFIGURED)) { | ||
| 913 | memset(&f, 0, sizeof(f)); | ||
| 914 | f.flt_type = HCI_FLT_CLEAR_ALL; | ||
| 915 | hci_req_add(req, HCI_OP_SET_EVENT_FLT, 1, &f); | ||
| 916 | } | ||
| 917 | } | ||
| 918 | |||
| 919 | static void hci_req_set_event_filter(struct hci_request *req) | ||
| 920 | { | ||
| 921 | struct bdaddr_list_with_flags *b; | ||
| 922 | struct hci_cp_set_event_filter f; | ||
| 923 | struct hci_dev *hdev = req->hdev; | ||
| 924 | u8 scan = SCAN_DISABLED; | ||
| 925 | bool scanning = test_bit(HCI_PSCAN, &hdev->flags); | ||
| 926 | |||
| 927 | if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) | ||
| 928 | return; | ||
| 929 | |||
| 930 | /* Always clear event filter when starting */ | ||
| 931 | hci_req_clear_event_filter(req); | ||
| 932 | |||
| 933 | list_for_each_entry(b, &hdev->accept_list, list) { | ||
| 934 | if (!hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, | ||
| 935 | b->current_flags)) | ||
| 936 | continue; | ||
| 937 | |||
| 938 | memset(&f, 0, sizeof(f)); | ||
| 939 | bacpy(&f.addr_conn_flt.bdaddr, &b->bdaddr); | ||
| 940 | f.flt_type = HCI_FLT_CONN_SETUP; | ||
| 941 | f.cond_type = HCI_CONN_SETUP_ALLOW_BDADDR; | ||
| 942 | f.addr_conn_flt.auto_accept = HCI_CONN_SETUP_AUTO_ON; | ||
| 943 | |||
| 944 | bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); | ||
| 945 | hci_req_add(req, HCI_OP_SET_EVENT_FLT, sizeof(f), &f); | ||
| 946 | scan = SCAN_PAGE; | ||
| 947 | } | ||
| 948 | |||
| 949 | if (scan && !scanning) { | ||
| 950 | set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); | ||
| 951 | hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); | ||
| 952 | } else if (!scan && scanning) { | ||
| 953 | set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); | ||
| 954 | hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); | ||
| 955 | } | ||
| 956 | } | ||
| 957 | |||
| 958 | static void cancel_adv_timeout(struct hci_dev *hdev) | 900 | static void cancel_adv_timeout(struct hci_dev *hdev) |
| 959 | { | 901 | { |
| 960 | if (hdev->adv_instance_timeout) { | 902 | if (hdev->adv_instance_timeout) { |
| @@ -1013,185 +955,6 @@ int hci_req_resume_adv_instances(struct hci_dev *hdev) · 52 unmodified lines | |||
| 1013 | return hci_req_run(&req, NULL); | 955 | return hci_req_run(&req, NULL); |
| 1014 | } | 956 | } |
| 1015 | 957 | ||
| 1016 | static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode) | ||
| 1017 | { | ||
| 1018 | bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode, | ||
| 1019 | status); | ||
| 1020 | if (test_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks) || | ||
| 1021 | test_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks)) { | ||
| 1022 | clear_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); | ||
| 1023 | clear_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); | ||
| 1024 | wake_up(&hdev->suspend_wait_q); | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | if (test_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks)) { | ||
| 1028 | clear_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks); | ||
| 1029 | wake_up(&hdev->suspend_wait_q); | ||
| 1030 | } | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | static void hci_req_prepare_adv_monitor_suspend(struct hci_request *req, | ||
| 1034 | bool suspending) | ||
| 1035 | { | ||
| 1036 | struct hci_dev *hdev = req->hdev; | ||
| 1037 | |||
| 1038 | switch (hci_get_adv_monitor_offload_ext(hdev)) { | ||
| 1039 | case HCI_ADV_MONITOR_EXT_MSFT: | ||
| 1040 | if (suspending) | ||
| 1041 | msft_suspend(hdev); | ||
| 1042 | else | ||
| 1043 | msft_resume(hdev); | ||
| 1044 | break; | ||
| 1045 | default: | ||
| 1046 | return; | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | /* No need to block when enabling since it's on resume path */ | ||
| 1050 | if (hdev->suspended && suspending) | ||
| 1051 | set_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks); | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | /* Call with hci_dev_lock */ | ||
| 1055 | void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) | ||
| 1056 | { | ||
| 1057 | int old_state; | ||
| 1058 | struct hci_conn *conn; | ||
| 1059 | struct hci_request req; | ||
| 1060 | u8 page_scan; | ||
| 1061 | int disconnect_counter; | ||
| 1062 | |||
| 1063 | if (next == hdev->suspend_state) { | ||
| 1064 | bt_dev_dbg(hdev, "Same state before and after: %d", next); | ||
| 1065 | goto done; | ||
| 1066 | } | ||
| 1067 | |||
| 1068 | hdev->suspend_state = next; | ||
| 1069 | hci_req_init(&req, hdev); | ||
| 1070 | |||
| 1071 | if (next == BT_SUSPEND_DISCONNECT) { | ||
| 1072 | /* Mark device as suspended */ | ||
| 1073 | hdev->suspended = true; | ||
| 1074 | |||
| 1075 | /* Pause discovery if not already stopped */ | ||
| 1076 | old_state = hdev->discovery.state; | ||
| 1077 | if (old_state != DISCOVERY_STOPPED) { | ||
| 1078 | set_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks); | ||
| 1079 | hci_discovery_set_state(hdev, DISCOVERY_STOPPING); | ||
| 1080 | queue_work(hdev->req_workqueue, &hdev->discov_update); | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | hdev->discovery_paused = true; | ||
| 1084 | hdev->discovery_old_state = old_state; | ||
| 1085 | |||
| 1086 | /* Stop directed advertising */ | ||
| 1087 | old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); | ||
| 1088 | if (old_state) { | ||
| 1089 | set_bit(SUSPEND_PAUSE_ADVERTISING, hdev->suspend_tasks); | ||
| 1090 | cancel_delayed_work(&hdev->discov_off); | ||
| 1091 | queue_delayed_work(hdev->req_workqueue, | ||
| 1092 | &hdev->discov_off, 0); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | /* Pause other advertisements */ | ||
| 1096 | if (hdev->adv_instance_cnt) | ||
| 1097 | __hci_req_pause_adv_instances(&req); | ||
| 1098 | |||
| 1099 | hdev->advertising_paused = true; | ||
| 1100 | hdev->advertising_old_state = old_state; | ||
| 1101 | |||
| 1102 | /* Disable page scan if enabled */ | ||
| 1103 | if (test_bit(HCI_PSCAN, &hdev->flags)) { | ||
| 1104 | page_scan = SCAN_DISABLED; | ||
| 1105 | hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, | ||
| 1106 | &page_scan); | ||
| 1107 | set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | /* Disable LE passive scan if enabled */ | ||
| 1111 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { | ||
| 1112 | cancel_interleave_scan(hdev); | ||
| 1113 | hci_req_add_le_scan_disable(&req, false); | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | /* Disable advertisement filters */ | ||
| 1117 | hci_req_prepare_adv_monitor_suspend(&req, true); | ||
| 1118 | |||
| 1119 | /* Prevent disconnects from causing scanning to be re-enabled */ | ||
| 1120 | hdev->scanning_paused = true; | ||
| 1121 | |||
| 1122 | /* Run commands before disconnecting */ | ||
| 1123 | hci_req_run(&req, suspend_req_complete); | ||
| 1124 | |||
| 1125 | disconnect_counter = 0; | ||
| 1126 | /* Soft disconnect everything (power off) */ | ||
| 1127 | list_for_each_entry(conn, &hdev->conn_hash.list, list) { | ||
| 1128 | hci_disconnect(conn, HCI_ERROR_REMOTE_POWER_OFF); | ||
| 1129 | disconnect_counter++; | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | if (disconnect_counter > 0) { | ||
| 1133 | bt_dev_dbg(hdev, | ||
| 1134 | "Had %d disconnects. Will wait on them", | ||
| 1135 | disconnect_counter); | ||
| 1136 | set_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks); | ||
| 1137 | } | ||
| 1138 | } else if (next == BT_SUSPEND_CONFIGURE_WAKE) { | ||
| 1139 | /* Unpause to take care of updating scanning params */ | ||
| 1140 | hdev->scanning_paused = false; | ||
| 1141 | /* Enable event filter for paired devices */ | ||
| 1142 | hci_req_set_event_filter(&req); | ||
| 1143 | /* Enable passive scan at lower duty cycle */ | ||
| 1144 | __hci_update_background_scan(&req); | ||
| 1145 | /* Pause scan changes again. */ | ||
| 1146 | hdev->scanning_paused = true; | ||
| 1147 | hci_req_run(&req, suspend_req_complete); | ||
| 1148 | } else { | ||
| 1149 | hdev->suspended = false; | ||
| 1150 | hdev->scanning_paused = false; | ||
| 1151 | |||
| 1152 | /* Clear any event filters and restore scan state */ | ||
| 1153 | hci_req_clear_event_filter(&req); | ||
| 1154 | __hci_req_update_scan(&req); | ||
| 1155 | |||
| 1156 | /* Reset passive/background scanning to normal */ | ||
| 1157 | __hci_update_background_scan(&req); | ||
| 1158 | /* Enable all of the advertisement filters */ | ||
| 1159 | hci_req_prepare_adv_monitor_suspend(&req, false); | ||
| 1160 | |||
| 1161 | /* Unpause directed advertising */ | ||
| 1162 | hdev->advertising_paused = false; | ||
| 1163 | if (hdev->advertising_old_state) { | ||
| 1164 | set_bit(SUSPEND_UNPAUSE_ADVERTISING, | ||
| 1165 | hdev->suspend_tasks); | ||
| 1166 | hci_dev_set_flag(hdev, HCI_ADVERTISING); | ||
| 1167 | queue_work(hdev->req_workqueue, | ||
| 1168 | &hdev->discoverable_update); | ||
| 1169 | hdev->advertising_old_state = 0; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | /* Resume other advertisements */ | ||
| 1173 | if (hdev->adv_instance_cnt) | ||
| 1174 | __hci_req_resume_adv_instances(&req); | ||
| 1175 | |||
| 1176 | /* Unpause discovery */ | ||
| 1177 | hdev->discovery_paused = false; | ||
| 1178 | if (hdev->discovery_old_state != DISCOVERY_STOPPED && | ||
| 1179 | hdev->discovery_old_state != DISCOVERY_STOPPING) { | ||
| 1180 | set_bit(SUSPEND_UNPAUSE_DISCOVERY, hdev->suspend_tasks); | ||
| 1181 | hci_discovery_set_state(hdev, DISCOVERY_STARTING); | ||
| 1182 | queue_work(hdev->req_workqueue, &hdev->discov_update); | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | hci_req_run(&req, suspend_req_complete); | ||
| 1186 | } | ||
| 1187 | |||
| 1188 | hdev->suspend_state = next; | ||
| 1189 | |||
| 1190 | done: | ||
| 1191 | clear_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); | ||
| 1192 | wake_up(&hdev->suspend_wait_q); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | static bool adv_cur_instance_is_scannable(struct hci_dev *hdev) | 958 | static bool adv_cur_instance_is_scannable(struct hci_dev *hdev) |
| 1196 | { | 959 | { |
| 1197 | return hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance); | 960 | return hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance); |
| @@ -1410,9 +1410,6 @@ int hci_scan_disable_sync(struct hci_dev *hdev) · 1409 unmodified lines | |||
| 1410 | return 0; | 1410 | return 0; |
| 1411 | } | 1411 | } |
| 1412 | 1412 | ||
| 1413 | if (hdev->suspended) | ||
| 1414 | set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); | ||
| 1415 | |||
| 1416 | err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); | 1413 | err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); |
| 1417 | if (err) { | 1414 | if (err) { |
| 1418 | bt_dev_err(hdev, "Unable to disable scanning: %d", err); | 1415 | bt_dev_err(hdev, "Unable to disable scanning: %d", err); |
| @@ -1642,10 +1639,11 @@ static int hci_le_add_accept_list_sync(struct hci_dev *hdev, · 223 unmodified lines | |||
| 1642 | return 0; | 1639 | return 0; |
| 1643 | } | 1640 | } |
| 1644 | 1641 | ||
| 1645 | /* This function disables all advertising instances (including 0x00) */ | 1642 | /* This function disables/pause all advertising instances */ |
| 1646 | static int hci_pause_advertising_sync(struct hci_dev *hdev) | 1643 | static int hci_pause_advertising_sync(struct hci_dev *hdev) |
| 1647 | { | 1644 | { |
| 1648 | int err; | 1645 | int err; |
| 1646 | int old_state; | ||
| 1649 | 1647 | ||
| 1650 | /* If there are no instances or advertising has already been paused | 1648 | /* If there are no instances or advertising has already been paused |
| 1651 | * there is nothing to do. | 1649 | * there is nothing to do. |
| @@ -1653,6 +1651,21 @@ static int hci_pause_advertising_sync(struct hci_dev *hdev) · 1 unmodified line | |||
| 1653 | if (!hdev->adv_instance_cnt || hdev->advertising_paused) | 1651 | if (!hdev->adv_instance_cnt || hdev->advertising_paused) |
| 1654 | return 0; | 1652 | return 0; |
| 1655 | 1653 | ||
| 1654 | bt_dev_dbg(hdev, "Pausing directed advertising"); | ||
| 1655 | |||
| 1656 | /* Stop directed advertising */ | ||
| 1657 | old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); | ||
| 1658 | if (old_state) { | ||
| 1659 | /* When discoverable timeout triggers, then just make sure | ||
| 1660 | * the limited discoverable flag is cleared. Even in the case | ||
| 1661 | * of a timeout triggered from general discoverable, it is | ||
| 1662 | * safe to unconditionally clear the flag. | ||
| 1663 | */ | ||
| 1664 | hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); | ||
| 1665 | hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); | ||
| 1666 | hdev->discov_timeout = 0; | ||
| 1667 | } | ||
| 1668 | |||
| 1656 | bt_dev_dbg(hdev, "Pausing advertising instances"); | 1669 | bt_dev_dbg(hdev, "Pausing advertising instances"); |
| 1657 | 1670 | ||
| 1658 | /* Call to disable any advertisements active on the controller. | 1671 | /* Call to disable any advertisements active on the controller. |
| @@ -1667,11 +1680,12 @@ static int hci_pause_advertising_sync(struct hci_dev *hdev) · 8 unmodified lines | |||
| 1667 | cancel_adv_timeout(hdev); | 1680 | cancel_adv_timeout(hdev); |
| 1668 | 1681 | ||
| 1669 | hdev->advertising_paused = true; | 1682 | hdev->advertising_paused = true; |
| 1683 | hdev->advertising_old_state = old_state; | ||
| 1670 | 1684 | ||
| 1671 | return 0; | 1685 | return 0; |
| 1672 | } | 1686 | } |
| 1673 | 1687 | ||
| 1674 | /* This function enables all user advertising instances (excluding 0x00) */ | 1688 | /* This function enables all user advertising instances */ |
| 1675 | static int hci_resume_advertising_sync(struct hci_dev *hdev) | 1689 | static int hci_resume_advertising_sync(struct hci_dev *hdev) |
| 1676 | { | 1690 | { |
| 1677 | struct adv_info *adv, *tmp; | 1691 | struct adv_info *adv, *tmp; |
| @@ -1681,6 +1695,14 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev) · 3 unmodified lines | |||
| 1681 | if (!hdev->advertising_paused) | 1695 | if (!hdev->advertising_paused) |
| 1682 | return 0; | 1696 | return 0; |
| 1683 | 1697 | ||
| 1698 | /* Resume directed advertising */ | ||
| 1699 | hdev->advertising_paused = false; | ||
| 1700 | if (hdev->advertising_old_state) { | ||
| 1701 | hci_dev_set_flag(hdev, HCI_ADVERTISING); | ||
| 1702 | queue_work(hdev->req_workqueue, &hdev->discoverable_update); | ||
| 1703 | hdev->advertising_old_state = 0; | ||
| 1704 | } | ||
| 1705 | |||
| 1684 | bt_dev_dbg(hdev, "Resuming advertising instances"); | 1706 | bt_dev_dbg(hdev, "Resuming advertising instances"); |
| 1685 | 1707 | ||
| 1686 | if (ext_adv_capable(hdev)) { | 1708 | if (ext_adv_capable(hdev)) { |
| @@ -2002,8 +2024,6 @@ int hci_passive_scan_sync(struct hci_dev *hdev) · 315 unmodified lines | |||
| 2002 | if (hdev->suspended) { | 2024 | if (hdev->suspended) { |
| 2003 | window = hdev->le_scan_window_suspend; | 2025 | window = hdev->le_scan_window_suspend; |
| 2004 | interval = hdev->le_scan_int_suspend; | 2026 | interval = hdev->le_scan_int_suspend; |
| 2005 | |||
| 2006 | set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); | ||
| 2007 | } else if (hci_is_le_conn_scanning(hdev)) { | 2027 | } else if (hci_is_le_conn_scanning(hdev)) { |
| 2008 | window = hdev->le_scan_window_connect; | 2028 | window = hdev->le_scan_window_connect; |
| 2009 | interval = hdev->le_scan_int_connect; | 2029 | interval = hdev->le_scan_int_connect; |
| @@ -2937,6 +2957,13 @@ static int hci_set_event_mask_sync(struct hci_dev *hdev) · 927 unmodified lines | |||
| 2937 | 2957 | ||
| 2938 | if (lmp_bredr_capable(hdev)) { | 2958 | if (lmp_bredr_capable(hdev)) { |
| 2939 | events[4] |= 0x01; /* Flow Specification Complete */ | 2959 | events[4] |= 0x01; /* Flow Specification Complete */ |
| 2960 | |||
| 2961 | /* Don't set Disconnect Complete when suspended as that | ||
| 2962 | * would wakeup the host when disconnecting due to | ||
| 2963 | * suspend. | ||
| 2964 | */ | ||
| 2965 | if (hdev->suspended) | ||
| 2966 | events[0] &= 0xef; | ||
| 2940 | } else { | 2967 | } else { |
| 2941 | /* Use a different default for LE-only devices */ | 2968 | /* Use a different default for LE-only devices */ |
| 2942 | memset(events, 0, sizeof(events)); | 2969 | memset(events, 0, sizeof(events)); |
| @@ -2949,7 +2976,12 @@ static int hci_set_event_mask_sync(struct hci_dev *hdev) · 6 unmodified lines | |||
| 2949 | * control related events. | 2976 | * control related events. |
| 2950 | */ | 2977 | */ |
| 2951 | if (hdev->commands[0] & 0x20) { | 2978 | if (hdev->commands[0] & 0x20) { |
| 2952 | events[0] |= 0x10; /* Disconnection Complete */ | 2979 | /* Don't set Disconnect Complete when suspended as that |
| 2980 | * would wakeup the host when disconnecting due to | ||
| 2981 | * suspend. | ||
| 2982 | */ | ||
| 2983 | if (!hdev->suspended) | ||
| 2984 | events[0] |= 0x10; /* Disconnection Complete */ | ||
| 2953 | events[2] |= 0x04; /* Number of Completed Packets */ | 2985 | events[2] |= 0x04; /* Number of Completed Packets */ |
| 2954 | events[3] |= 0x02; /* Data Buffer Overflow */ | 2986 | events[3] |= 0x02; /* Data Buffer Overflow */ |
| 2955 | } | 2987 | } |
| @@ -4033,9 +4065,6 @@ int hci_dev_close_sync(struct hci_dev *hdev) · 1077 unmodified lines | |||
| 4033 | clear_bit(HCI_RUNNING, &hdev->flags); | 4065 | clear_bit(HCI_RUNNING, &hdev->flags); |
| 4034 | hci_sock_dev_event(hdev, HCI_DEV_CLOSE); | 4066 | hci_sock_dev_event(hdev, HCI_DEV_CLOSE); |
| 4035 | 4067 | ||
| 4036 | if (test_and_clear_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks)) | ||
| 4037 | wake_up(&hdev->suspend_wait_q); | ||
| 4038 | |||
| 4039 | /* After this point our queues are empty and no tasks are scheduled. */ | 4068 | /* After this point our queues are empty and no tasks are scheduled. */ |
| 4040 | hdev->close(hdev); | 4069 | hdev->close(hdev); |
| 4041 | 4070 | ||
| @@ -4299,6 +4328,20 @@ static int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, · 257 unmodified lines | |||
| 4299 | return 0; | 4328 | return 0; |
| 4300 | } | 4329 | } |
| 4301 | 4330 | ||
| 4331 | static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) | ||
| 4332 | { | ||
| 4333 | struct hci_conn *conn, *tmp; | ||
| 4334 | int err; | ||
| 4335 | |||
| 4336 | list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) { | ||
| 4337 | err = hci_abort_conn_sync(hdev, conn, reason); | ||
| 4338 | if (err) | ||
| 4339 | return err; | ||
| 4340 | } | ||
| 4341 | |||
| 4342 | return err; | ||
| 4343 | } | ||
| 4344 | |||
| 4302 | /* This function perform power off HCI command sequence as follows: | 4345 | /* This function perform power off HCI command sequence as follows: |
| 4303 | * | 4346 | * |
| 4304 | * Clear Advertising | 4347 | * Clear Advertising |
| @@ -4308,7 +4351,6 @@ static int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, · 3 unmodified lines | |||
| 4308 | */ | 4351 | */ |
| 4309 | static int hci_power_off_sync(struct hci_dev *hdev) | 4352 | static int hci_power_off_sync(struct hci_dev *hdev) |
| 4310 | { | 4353 | { |
| 4311 | struct hci_conn *conn; | ||
| 4312 | int err; | 4354 | int err; |
| 4313 | 4355 | ||
| 4314 | /* If controller is already down there is nothing to do */ | 4356 | /* If controller is already down there is nothing to do */ |
| @@ -4330,10 +4372,10 @@ static int hci_power_off_sync(struct hci_dev *hdev) · 15 unmodified lines | |||
| 4330 | if (err) | 4372 | if (err) |
| 4331 | return err; | 4373 | return err; |
| 4332 | 4374 | ||
| 4333 | list_for_each_entry(conn, &hdev->conn_hash.list, list) { | 4375 | /* Terminated due to Power Off */ |
| 4334 | /* 0x15 == Terminated due to Power Off */ | 4376 | err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); |
| 4335 | hci_abort_conn_sync(hdev, conn, 0x15); | 4377 | if (err) |
| 4336 | } | 4378 | return err; |
| 4337 | 4379 | ||
| 4338 | return hci_dev_close_sync(hdev); | 4380 | return hci_dev_close_sync(hdev); |
| 4339 | } | 4381 | } |
| @@ -4535,3 +4577,223 @@ int hci_start_discovery_sync(struct hci_dev *hdev) · 195 unmodified lines | |||
| 4535 | timeout); | 4577 | timeout); |
| 4536 | return 0; | 4578 | return 0; |
| 4537 | } | 4579 | } |
| 4580 | |||
| 4581 | static void hci_suspend_monitor_sync(struct hci_dev *hdev) | ||
| 4582 | { | ||
| 4583 | switch (hci_get_adv_monitor_offload_ext(hdev)) { | ||
| 4584 | case HCI_ADV_MONITOR_EXT_MSFT: | ||
| 4585 | msft_suspend_sync(hdev); | ||
| 4586 | break; | ||
| 4587 | default: | ||
| 4588 | return; | ||
| 4589 | } | ||
| 4590 | } | ||
| 4591 | |||
| 4592 | /* This function disables discovery and mark it as paused */ | ||
| 4593 | static int hci_pause_discovery_sync(struct hci_dev *hdev) | ||
| 4594 | { | ||
| 4595 | int old_state = hdev->discovery.state; | ||
| 4596 | int err; | ||
| 4597 | |||
| 4598 | /* If discovery already stopped/stopping/paused there nothing to do */ | ||
| 4599 | if (old_state == DISCOVERY_STOPPED || old_state == DISCOVERY_STOPPING || | ||
| 4600 | hdev->discovery_paused) | ||
| 4601 | return 0; | ||
| 4602 | |||
| 4603 | hci_discovery_set_state(hdev, DISCOVERY_STOPPING); | ||
| 4604 | err = hci_stop_discovery_sync(hdev); | ||
| 4605 | if (err) | ||
| 4606 | return err; | ||
| 4607 | |||
| 4608 | hdev->discovery_paused = true; | ||
| 4609 | hdev->discovery_old_state = old_state; | ||
| 4610 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); | ||
| 4611 | |||
| 4612 | return 0; | ||
| 4613 | } | ||
| 4614 | |||
| 4615 | static int hci_update_event_filter_sync(struct hci_dev *hdev) | ||
| 4616 | { | ||
| 4617 | struct bdaddr_list_with_flags *b; | ||
| 4618 | u8 scan = SCAN_DISABLED; | ||
| 4619 | bool scanning = test_bit(HCI_PSCAN, &hdev->flags); | ||
| 4620 | int err; | ||
| 4621 | |||
| 4622 | if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) | ||
| 4623 | return 0; | ||
| 4624 | |||
| 4625 | /* Always clear event filter when starting */ | ||
| 4626 | hci_clear_event_filter_sync(hdev); | ||
| 4627 | |||
| 4628 | list_for_each_entry(b, &hdev->accept_list, list) { | ||
| 4629 | if (!hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, | ||
| 4630 | b->current_flags)) | ||
| 4631 | continue; | ||
| 4632 | |||
| 4633 | bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); | ||
| 4634 | |||
| 4635 | err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, | ||
| 4636 | HCI_CONN_SETUP_ALLOW_BDADDR, | ||
| 4637 | &b->bdaddr, | ||
| 4638 | HCI_CONN_SETUP_AUTO_ON); | ||
| 4639 | if (err) | ||
| 4640 | bt_dev_dbg(hdev, "Failed to set event filter for %pMR", | ||
| 4641 | &b->bdaddr); | ||
| 4642 | else | ||
| 4643 | scan = SCAN_PAGE; | ||
| 4644 | } | ||
| 4645 | |||
| 4646 | if (scan && !scanning) | ||
| 4647 | hci_write_scan_enable_sync(hdev, scan); | ||
| 4648 | else if (!scan && scanning) | ||
| 4649 | hci_write_scan_enable_sync(hdev, scan); | ||
| 4650 | |||
| 4651 | return 0; | ||
| 4652 | } | ||
| 4653 | |||
| 4654 | /* This function performs the HCI suspend procedures in the follow order: | ||
| 4655 | * | ||
| 4656 | * Pause discovery (active scanning/inquiry) | ||
| 4657 | * Pause Directed Advertising/Advertising | ||
| 4658 | * Disconnect all connections | ||
| 4659 | * Set suspend_status to BT_SUSPEND_DISCONNECT if hdev cannot wakeup | ||
| 4660 | * otherwise: | ||
| 4661 | * Update event mask (only set events that are allowed to wake up the host) | ||
| 4662 | * Update event filter (with devices marked with HCI_CONN_FLAG_REMOTE_WAKEUP) | ||
| 4663 | * Update passive scanning (lower duty cycle) | ||
| 4664 | * Set suspend_status to BT_SUSPEND_CONFIGURE_WAKE | ||
| 4665 | */ | ||
| 4666 | int hci_suspend_sync(struct hci_dev *hdev) | ||
| 4667 | { | ||
| 4668 | int err; | ||
| 4669 | |||
| 4670 | /* If marked as suspended there nothing to do */ | ||
| 4671 | if (hdev->suspended) | ||
| 4672 | return 0; | ||
| 4673 | |||
| 4674 | /* Mark device as suspended */ | ||
| 4675 | hdev->suspended = true; | ||
| 4676 | |||
| 4677 | /* Pause discovery if not already stopped */ | ||
| 4678 | hci_pause_discovery_sync(hdev); | ||
| 4679 | |||
| 4680 | /* Pause other advertisements */ | ||
| 4681 | hci_pause_advertising_sync(hdev); | ||
| 4682 | |||
| 4683 | /* Disable page scan if enabled */ | ||
| 4684 | if (test_bit(HCI_PSCAN, &hdev->flags)) | ||
| 4685 | hci_write_scan_enable_sync(hdev, SCAN_DISABLED); | ||
| 4686 | |||
| 4687 | /* Suspend monitor filters */ | ||
| 4688 | hci_suspend_monitor_sync(hdev); | ||
| 4689 | |||
| 4690 | /* Prevent disconnects from causing scanning to be re-enabled */ | ||
| 4691 | hdev->scanning_paused = true; | ||
| 4692 | |||
| 4693 | /* Soft disconnect everything (power off) */ | ||
| 4694 | err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); | ||
| 4695 | if (err) { | ||
| 4696 | /* Set state to BT_RUNNING so resume doesn't notify */ | ||
| 4697 | hdev->suspend_state = BT_RUNNING; | ||
| 4698 | hci_resume_sync(hdev); | ||
| 4699 | return err; | ||
| 4700 | } | ||
| 4701 | |||
| 4702 | /* Only configure accept list if disconnect succeeded and wake | ||
| 4703 | * isn't being prevented. | ||
| 4704 | */ | ||
| 4705 | if (!hdev->wakeup || !hdev->wakeup(hdev)) { | ||
| 4706 | hdev->suspend_state = BT_SUSPEND_DISCONNECT; | ||
| 4707 | return 0; | ||
| 4708 | } | ||
| 4709 | |||
| 4710 | /* Unpause to take care of updating scanning params */ | ||
| 4711 | hdev->scanning_paused = false; | ||
| 4712 | |||
| 4713 | /* Update event mask so only the allowed event can wakeup the host */ | ||
| 4714 | hci_set_event_mask_sync(hdev); | ||
| 4715 | |||
| 4716 | /* Enable event filter for paired devices */ | ||
| 4717 | hci_update_event_filter_sync(hdev); | ||
| 4718 | |||
| 4719 | /* Update LE passive scan if enabled */ | ||
| 4720 | hci_update_passive_scan_sync(hdev); | ||
| 4721 | |||
| 4722 | /* Pause scan changes again. */ | ||
| 4723 | hdev->scanning_paused = true; | ||
| 4724 | |||
| 4725 | hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; | ||
| 4726 | |||
| 4727 | return 0; | ||
| 4728 | } | ||
| 4729 | |||
| 4730 | /* This function resumes discovery */ | ||
| 4731 | static int hci_resume_discovery_sync(struct hci_dev *hdev) | ||
| 4732 | { | ||
| 4733 | int err; | ||
| 4734 | |||
| 4735 | /* If discovery not paused there nothing to do */ | ||
| 4736 | if (!hdev->discovery_paused) | ||
| 4737 | return 0; | ||
| 4738 | |||
| 4739 | hdev->discovery_paused = false; | ||
| 4740 | |||
| 4741 | hci_discovery_set_state(hdev, DISCOVERY_STARTING); | ||
| 4742 | |||
| 4743 | err = hci_start_discovery_sync(hdev); | ||
| 4744 | |||
| 4745 | hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : | ||
| 4746 | DISCOVERY_FINDING); | ||
| 4747 | |||
| 4748 | return err; | ||
| 4749 | } | ||
| 4750 | |||
| 4751 | static void hci_resume_monitor_sync(struct hci_dev *hdev) | ||
| 4752 | { | ||
| 4753 | switch (hci_get_adv_monitor_offload_ext(hdev)) { | ||
| 4754 | case HCI_ADV_MONITOR_EXT_MSFT: | ||
| 4755 | msft_resume_sync(hdev); | ||
| 4756 | break; | ||
| 4757 | default: | ||
| 4758 | return; | ||
| 4759 | } | ||
| 4760 | } | ||
| 4761 | |||
| 4762 | /* This function performs the HCI suspend procedures in the follow order: | ||
| 4763 | * | ||
| 4764 | * Restore event mask | ||
| 4765 | * Clear event filter | ||
| 4766 | * Update passive scanning (normal duty cycle) | ||
| 4767 | * Resume Directed Advertising/Advertising | ||
| 4768 | * Resume discovery (active scanning/inquiry) | ||
| 4769 | */ | ||
| 4770 | int hci_resume_sync(struct hci_dev *hdev) | ||
| 4771 | { | ||
| 4772 | /* If not marked as suspended there nothing to do */ | ||
| 4773 | if (!hdev->suspended) | ||
| 4774 | return 0; | ||
| 4775 | |||
| 4776 | hdev->suspended = false; | ||
| 4777 | hdev->scanning_paused = false; | ||
| 4778 | |||
| 4779 | /* Restore event mask */ | ||
| 4780 | hci_set_event_mask_sync(hdev); | ||
| 4781 | |||
| 4782 | /* Clear any event filters and restore scan state */ | ||
| 4783 | hci_clear_event_filter_sync(hdev); | ||
| 4784 | hci_update_scan_sync(hdev); | ||
| 4785 | |||
| 4786 | /* Reset passive scanning to normal */ | ||
| 4787 | hci_update_passive_scan_sync(hdev); | ||
| 4788 | |||
| 4789 | /* Resume monitor filters */ | ||
| 4790 | hci_resume_monitor_sync(hdev); | ||
| 4791 | |||
| 4792 | /* Resume other advertisements */ | ||
| 4793 | hci_resume_advertising_sync(hdev); | ||
| 4794 | |||
| 4795 | /* Resume discovery */ | ||
| 4796 | hci_resume_discovery_sync(hdev); | ||
| 4797 | |||
| 4798 | return 0; | ||
| 4799 | } | ||
| @@ -5171,13 +5171,6 @@ void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) · 5170 unmodified lines | |||
| 5171 | } | 5171 | } |
| 5172 | 5172 | ||
| 5173 | hci_dev_unlock(hdev); | 5173 | hci_dev_unlock(hdev); |
| 5174 | |||
| 5175 | /* Handle suspend notifier */ | ||
| 5176 | if (test_and_clear_bit(SUSPEND_UNPAUSE_DISCOVERY, | ||
| 5177 | hdev->suspend_tasks)) { | ||
| 5178 | bt_dev_dbg(hdev, "Unpaused discovery"); | ||
| 5179 | wake_up(&hdev->suspend_wait_q); | ||
| 5180 | } | ||
| 5181 | } | 5174 | } |
| 5182 | 5175 | ||
| 5183 | static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, | 5176 | static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, |
| @@ -5217,14 +5210,7 @@ static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) · 33 unmodified lines | |||
| 5217 | cmd->param, 1); | 5210 | cmd->param, 1); |
| 5218 | mgmt_pending_free(cmd); | 5211 | mgmt_pending_free(cmd); |
| 5219 | 5212 | ||
| 5220 | /* Handle suspend notifier */ | 5213 | hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: |
| 5221 | if (test_and_clear_bit(SUSPEND_UNPAUSE_DISCOVERY, | ||
| 5222 | hdev->suspend_tasks)) { | ||
| 5223 | bt_dev_dbg(hdev, "Unpaused discovery"); | ||
| 5224 | wake_up(&hdev->suspend_wait_q); | ||
| 5225 | } | ||
| 5226 | |||
| 5227 | hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : | ||
| 5228 | DISCOVERY_FINDING); | 5214 | DISCOVERY_FINDING); |
| 5229 | } | 5215 | } |
| 5230 | 5216 | ||
| @@ -5446,12 +5432,6 @@ void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) · 215 unmodified lines | |||
| 5446 | } | 5432 | } |
| 5447 | 5433 | ||
| 5448 | hci_dev_unlock(hdev); | 5434 | hci_dev_unlock(hdev); |
| 5449 | |||
| 5450 | /* Handle suspend notifier */ | ||
| 5451 | if (test_and_clear_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks)) { | ||
| 5452 | bt_dev_dbg(hdev, "Paused discovery"); | ||
| 5453 | wake_up(&hdev->suspend_wait_q); | ||
| 5454 | } | ||
| 5455 | } | 5435 | } |
| 5456 | 5436 | ||
| 5457 | static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) | 5437 | static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) |
| @@ -5464,12 +5444,6 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) · 6 unmodified lines | |||
| 5464 | cmd->param, 1); | 5444 | cmd->param, 1); |
| 5465 | mgmt_pending_free(cmd); | 5445 | mgmt_pending_free(cmd); |
| 5466 | 5446 | ||
| 5467 | /* Handle suspend notifier */ | ||
| 5468 | if (test_and_clear_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks)) { | ||
| 5469 | bt_dev_dbg(hdev, "Paused discovery"); | ||
| 5470 | wake_up(&hdev->suspend_wait_q); | ||
| 5471 | } | ||
| 5472 | |||
| 5473 | if (!err) | 5447 | if (!err) |
| 5474 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); | 5448 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 5475 | } | 5449 | } |
| @@ -5709,17 +5683,6 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) · 233 unmodified lines | |||
| 5709 | if (match.sk) | 5683 | if (match.sk) |
| 5710 | sock_put(match.sk); | 5684 | sock_put(match.sk); |
| 5711 | 5685 | ||
| 5712 | /* Handle suspend notifier */ | ||
| 5713 | if (test_and_clear_bit(SUSPEND_PAUSE_ADVERTISING, | ||
| 5714 | hdev->suspend_tasks)) { | ||
| 5715 | bt_dev_dbg(hdev, "Paused advertising"); | ||
| 5716 | wake_up(&hdev->suspend_wait_q); | ||
| 5717 | } else if (test_and_clear_bit(SUSPEND_UNPAUSE_ADVERTISING, | ||
| 5718 | hdev->suspend_tasks)) { | ||
| 5719 | bt_dev_dbg(hdev, "Unpaused advertising"); | ||
| 5720 | wake_up(&hdev->suspend_wait_q); | ||
| 5721 | } | ||
| 5722 | |||
| 5723 | /* If "Set Advertising" was just disabled and instance advertising was | 5686 | /* If "Set Advertising" was just disabled and instance advertising was |
| 5724 | * set up earlier, then re-enable multi-instance advertising. | 5687 | * set up earlier, then re-enable multi-instance advertising. |
| 5725 | */ | 5688 | */ |
| @@ -93,7 +93,7 @@ struct msft_data { · 92 unmodified lines | |||
| 93 | struct list_head handle_map; | 93 | struct list_head handle_map; |
| 94 | __u16 pending_add_handle; | 94 | __u16 pending_add_handle; |
| 95 | __u16 pending_remove_handle; | 95 | __u16 pending_remove_handle; |
| 96 | __u8 reregistering; | 96 | __u8 resuming; |
| 97 | __u8 suspending; | 97 | __u8 suspending; |
| 98 | __u8 filter_enabled; | 98 | __u8 filter_enabled; |
| 99 | }; | 99 | }; |
| @@ -156,7 +156,6 @@ failed: · 56 unmodified lines | |||
| 156 | return false; | 156 | return false; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | /* This function requires the caller holds hdev->lock */ | ||
| 160 | static void reregister_monitor(struct hci_dev *hdev, int handle) | 159 | static void reregister_monitor(struct hci_dev *hdev, int handle) |
| 161 | { | 160 | { |
| 162 | struct adv_monitor *monitor; | 161 | struct adv_monitor *monitor; |
| @@ -166,8 +165,8 @@ static void reregister_monitor(struct hci_dev *hdev, int handle) · 3 unmodified lines | |||
| 166 | while (1) { | 165 | while (1) { |
| 167 | monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); | 166 | monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); |
| 168 | if (!monitor) { | 167 | if (!monitor) { |
| 169 | /* All monitors have been reregistered */ | 168 | /* All monitors have been resumed */ |
| 170 | msft->reregistering = false; | 169 | msft->resuming = false; |
| 171 | hci_update_passive_scan(hdev); | 170 | hci_update_passive_scan(hdev); |
| 172 | return; | 171 | return; |
| 173 | } | 172 | } |
| @@ -185,67 +184,317 @@ static void reregister_monitor(struct hci_dev *hdev, int handle) · 11 unmodified lines | |||
| 185 | } | 184 | } |
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | /* This function requires the caller holds hdev->lock */ | 187 | /* is_mgmt = true matches the handle exposed to userspace via mgmt. |
| 189 | static void remove_monitor_on_suspend(struct hci_dev *hdev, int handle) | 188 | * is_mgmt = false matches the handle used by the msft controller. |
| 189 | * This function requires the caller holds hdev->lock | ||
| 190 | */ | ||
| 191 | static struct msft_monitor_advertisement_handle_data *msft_find_handle_data | ||
| 192 | (struct hci_dev *hdev, u16 handle, bool is_mgmt) | ||
| 193 | { | ||
| 194 | struct msft_monitor_advertisement_handle_data *entry; | ||
| 195 | struct msft_data *msft = hdev->msft_data; | ||
| 196 | |||
| 197 | list_for_each_entry(entry, &msft->handle_map, list) { | ||
| 198 | if (is_mgmt && entry->mgmt_handle == handle) | ||
| 199 | return entry; | ||
| 200 | if (!is_mgmt && entry->msft_handle == handle) | ||
| 201 | return entry; | ||
| 202 | } | ||
| 203 | |||
| 204 | return NULL; | ||
| 205 | } | ||
| 206 | |||
| 207 | static void msft_le_monitor_advertisement_cb(struct hci_dev *hdev, | ||
| 208 | u8 status, u16 opcode, | ||
| 209 | struct sk_buff *skb) | ||
| 210 | { | ||
| 211 | struct msft_rp_le_monitor_advertisement *rp; | ||
| 212 | struct adv_monitor *monitor; | ||
| 213 | struct msft_monitor_advertisement_handle_data *handle_data; | ||
| 214 | struct msft_data *msft = hdev->msft_data; | ||
| 215 | |||
| 216 | hci_dev_lock(hdev); | ||
| 217 | |||
| 218 | monitor = idr_find(&hdev->adv_monitors_idr, msft->pending_add_handle); | ||
| 219 | if (!monitor) { | ||
| 220 | bt_dev_err(hdev, "msft add advmon: monitor %u is not found!", | ||
| 221 | msft->pending_add_handle); | ||
| 222 | status = HCI_ERROR_UNSPECIFIED; | ||
| 223 | goto unlock; | ||
| 224 | } | ||
| 225 | |||
| 226 | if (status) | ||
| 227 | goto unlock; | ||
| 228 | |||
| 229 | rp = (struct msft_rp_le_monitor_advertisement *)skb->data; | ||
| 230 | if (skb->len < sizeof(*rp)) { | ||
| 231 | status = HCI_ERROR_UNSPECIFIED; | ||
| 232 | goto unlock; | ||
| 233 | } | ||
| 234 | |||
| 235 | handle_data = kmalloc(sizeof(*handle_data), GFP_KERNEL); | ||
| 236 | if (!handle_data) { | ||
| 237 | status = HCI_ERROR_UNSPECIFIED; | ||
| 238 | goto unlock; | ||
| 239 | } | ||
| 240 | |||
| 241 | handle_data->mgmt_handle = monitor->handle; | ||
| 242 | handle_data->msft_handle = rp->handle; | ||
| 243 | INIT_LIST_HEAD(&handle_data->list); | ||
| 244 | list_add(&handle_data->list, &msft->handle_map); | ||
| 245 | |||
| 246 | monitor->state = ADV_MONITOR_STATE_OFFLOADED; | ||
| 247 | |||
| 248 | unlock: | ||
| 249 | if (status && monitor) | ||
| 250 | hci_free_adv_monitor(hdev, monitor); | ||
| 251 | |||
| 252 | hci_dev_unlock(hdev); | ||
| 253 | |||
| 254 | if (!msft->resuming) | ||
| 255 | hci_add_adv_patterns_monitor_complete(hdev, status); | ||
| 256 | } | ||
| 257 | |||
| 258 | static void msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, | ||
| 259 | u8 status, u16 opcode, | ||
| 260 | struct sk_buff *skb) | ||
| 190 | { | 261 | { |
| 262 | struct msft_cp_le_cancel_monitor_advertisement *cp; | ||
| 263 | struct msft_rp_le_cancel_monitor_advertisement *rp; | ||
| 191 | struct adv_monitor *monitor; | 264 | struct adv_monitor *monitor; |
| 265 | struct msft_monitor_advertisement_handle_data *handle_data; | ||
| 192 | struct msft_data *msft = hdev->msft_data; | 266 | struct msft_data *msft = hdev->msft_data; |
| 193 | int err; | 267 | int err; |
| 268 | bool pending; | ||
| 194 | 269 | ||
| 195 | while (1) { | 270 | if (status) |
| 196 | monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); | 271 | goto done; |
| 197 | if (!monitor) { | 272 | |
| 198 | /* All monitors have been removed */ | 273 | rp = (struct msft_rp_le_cancel_monitor_advertisement *)skb->data; |
| 199 | msft->suspending = false; | 274 | if (skb->len < sizeof(*rp)) { |
| 200 | hci_update_background_scan(hdev); | 275 | status = HCI_ERROR_UNSPECIFIED; |
| 276 | goto done; | ||
| 277 | } | ||
| 278 | |||
| 279 | hci_dev_lock(hdev); | ||
| 280 | |||
| 281 | cp = hci_sent_cmd_data(hdev, hdev->msft_opcode); | ||
| 282 | handle_data = msft_find_handle_data(hdev, cp->handle, false); | ||
| 283 | |||
| 284 | if (handle_data) { | ||
| 285 | monitor = idr_find(&hdev->adv_monitors_idr, | ||
| 286 | handle_data->mgmt_handle); | ||
| 287 | |||
| 288 | if (monitor && monitor->state == ADV_MONITOR_STATE_OFFLOADED) | ||
| 289 | monitor->state = ADV_MONITOR_STATE_REGISTERED; | ||
| 290 | |||
| 291 | /* Do not free the monitor if it is being removed due to | ||
| 292 | * suspend. It will be re-monitored on resume. | ||
| 293 | */ | ||
| 294 | if (monitor && !msft->suspending) | ||
| 295 | hci_free_adv_monitor(hdev, monitor); | ||
| 296 | |||
| 297 | list_del(&handle_data->list); | ||
| 298 | kfree(handle_data); | ||
| 299 | } | ||
| 300 | |||
| 301 | /* If remove all monitors is required, we need to continue the process | ||
| 302 | * here because the earlier it was paused when waiting for the | ||
| 303 | * response from controller. | ||
| 304 | */ | ||
| 305 | if (msft->pending_remove_handle == 0) { | ||
| 306 | pending = hci_remove_all_adv_monitor(hdev, &err); | ||
| 307 | if (pending) { | ||
| 308 | hci_dev_unlock(hdev); | ||
| 201 | return; | 309 | return; |
| 202 | } | 310 | } |
| 203 | 311 | ||
| 204 | msft->pending_remove_handle = (u16)handle; | 312 | if (err) |
| 205 | err = __msft_remove_monitor(hdev, monitor, handle); | 313 | status = HCI_ERROR_UNSPECIFIED; |
| 314 | } | ||
| 206 | 315 | ||
| 207 | /* If success, return and wait for monitor removed callback */ | 316 | hci_dev_unlock(hdev); |
| 208 | if (!err) | 317 | |
| 209 | return; | 318 | done: |
| 319 | if (!msft->suspending) | ||
| 320 | hci_remove_adv_monitor_complete(hdev, status); | ||
| 321 | } | ||
| 322 | |||
| 323 | static int msft_remove_monitor_sync(struct hci_dev *hdev, | ||
| 324 | struct adv_monitor *monitor) | ||
| 325 | { | ||
| 326 | struct msft_cp_le_cancel_monitor_advertisement cp; | ||
| 327 | struct msft_monitor_advertisement_handle_data *handle_data; | ||
| 328 | struct sk_buff *skb; | ||
| 329 | u8 status; | ||
| 330 | |||
| 331 | handle_data = msft_find_handle_data(hdev, monitor->handle, true); | ||
| 332 | |||
| 333 | /* If no matched handle, just remove without telling controller */ | ||
| 334 | if (!handle_data) | ||
| 335 | return -ENOENT; | ||
| 336 | |||
| 337 | cp.sub_opcode = MSFT_OP_LE_CANCEL_MONITOR_ADVERTISEMENT; | ||
| 338 | cp.handle = handle_data->msft_handle; | ||
| 339 | |||
| 340 | skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, | ||
| 341 | HCI_CMD_TIMEOUT); | ||
| 342 | if (IS_ERR(skb)) | ||
| 343 | return PTR_ERR(skb); | ||
| 344 | |||
| 345 | status = skb->data[0]; | ||
| 346 | skb_pull(skb, 1); | ||
| 347 | |||
| 348 | msft_le_cancel_monitor_advertisement_cb(hdev, status, hdev->msft_opcode, | ||
| 349 | skb); | ||
| 350 | |||
| 351 | return status; | ||
| 352 | } | ||
| 353 | |||
| 354 | /* This function requires the caller holds hci_req_sync_lock */ | ||
| 355 | int msft_suspend_sync(struct hci_dev *hdev) | ||
| 356 | { | ||
| 357 | struct msft_data *msft = hdev->msft_data; | ||
| 358 | struct adv_monitor *monitor; | ||
| 359 | int handle = 0; | ||
| 360 | |||
| 361 | if (!msft || !msft_monitor_supported(hdev)) | ||
| 362 | return 0; | ||
| 363 | |||
| 364 | msft->suspending = true; | ||
| 365 | |||
| 366 | while (1) { | ||
| 367 | monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); | ||
| 368 | if (!monitor) | ||
| 369 | break; | ||
| 370 | |||
| 371 | msft_remove_monitor_sync(hdev, monitor); | ||
| 210 | 372 | ||
| 211 | /* Otherwise free the monitor and keep removing */ | ||
| 212 | hci_free_adv_monitor(hdev, monitor); | ||
| 213 | handle++; | 373 | handle++; |
| 214 | } | 374 | } |
| 375 | |||
| 376 | /* All monitors have been removed */ | ||
| 377 | msft->suspending = false; | ||
| 378 | |||
| 379 | return 0; | ||
| 215 | } | 380 | } |
| 216 | 381 | ||
| 217 | /* This function requires the caller holds hdev->lock */ | 382 | static bool msft_monitor_rssi_valid(struct adv_monitor *monitor) |
| 218 | void msft_suspend(struct hci_dev *hdev) | ||
| 219 | { | 383 | { |
| 220 | struct msft_data *msft = hdev->msft_data; | 384 | struct adv_rssi_thresholds *r = &monitor->rssi; |
| 221 | 385 | ||
| 222 | if (!msft) | 386 | if (r->high_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || |
| 223 | return; | 387 | r->high_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX || |
| 388 | r->low_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || | ||
| 389 | r->low_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX) | ||
| 390 | return false; | ||
| 224 | 391 | ||
| 225 | if (msft_monitor_supported(hdev)) { | 392 | /* High_threshold_timeout is not supported, |
| 226 | msft->suspending = true; | 393 | * once high_threshold is reached, events are immediately reported. |
| 227 | /* Quitely remove all monitors on suspend to avoid waking up | 394 | */ |
| 228 | * the system. | 395 | if (r->high_threshold_timeout != 0) |
| 229 | */ | 396 | return false; |
| 230 | remove_monitor_on_suspend(hdev, 0); | 397 | |
| 398 | if (r->low_threshold_timeout > MSFT_RSSI_LOW_TIMEOUT_MAX) | ||
| 399 | return false; | ||
| 400 | |||
| 401 | /* Sampling period from 0x00 to 0xFF are all allowed */ | ||
| 402 | return true; | ||
| 403 | } | ||
| 404 | |||
| 405 | static bool msft_monitor_pattern_valid(struct adv_monitor *monitor) | ||
| 406 | { | ||
| 407 | return msft_monitor_rssi_valid(monitor); | ||
| 408 | /* No additional check needed for pattern-based monitor */ | ||
| 409 | } | ||
| 410 | |||
| 411 | static int msft_add_monitor_sync(struct hci_dev *hdev, | ||
| 412 | struct adv_monitor *monitor) | ||
| 413 | { | ||
| 414 | struct msft_cp_le_monitor_advertisement *cp; | ||
| 415 | struct msft_le_monitor_advertisement_pattern_data *pattern_data; | ||
| 416 | struct msft_le_monitor_advertisement_pattern *pattern; | ||
| 417 | struct adv_pattern *entry; | ||
| 418 | size_t total_size = sizeof(*cp) + sizeof(*pattern_data); | ||
| 419 | ptrdiff_t offset = 0; | ||
| 420 | u8 pattern_count = 0; | ||
| 421 | struct sk_buff *skb; | ||
| 422 | u8 status; | ||
| 423 | |||
| 424 | if (!msft_monitor_pattern_valid(monitor)) | ||
| 425 | return -EINVAL; | ||
| 426 | |||
| 427 | list_for_each_entry(entry, &monitor->patterns, list) { | ||
| 428 | pattern_count++; | ||
| 429 | total_size += sizeof(*pattern) + entry->length; | ||
| 231 | } | 430 | } |
| 431 | |||
| 432 | cp = kmalloc(total_size, GFP_KERNEL); | ||
| 433 | if (!cp) | ||
| 434 | return -ENOMEM; | ||
| 435 | |||
| 436 | cp->sub_opcode = MSFT_OP_LE_MONITOR_ADVERTISEMENT; | ||
| 437 | cp->rssi_high = monitor->rssi.high_threshold; | ||
| 438 | cp->rssi_low = monitor->rssi.low_threshold; | ||
| 439 | cp->rssi_low_interval = (u8)monitor->rssi.low_threshold_timeout; | ||
| 440 | cp->rssi_sampling_period = monitor->rssi.sampling_period; | ||
| 441 | |||
| 442 | cp->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_PATTERN; | ||
| 443 | |||
| 444 | pattern_data = (void *)cp->data; | ||
| 445 | pattern_data->count = pattern_count; | ||
| 446 | |||
| 447 | list_for_each_entry(entry, &monitor->patterns, list) { | ||
| 448 | pattern = (void *)(pattern_data->data + offset); | ||
| 449 | /* the length also includes data_type and offset */ | ||
| 450 | pattern->length = entry->length + 2; | ||
| 451 | pattern->data_type = entry->ad_type; | ||
| 452 | pattern->start_byte = entry->offset; | ||
| 453 | memcpy(pattern->pattern, entry->value, entry->length); | ||
| 454 | offset += sizeof(*pattern) + entry->length; | ||
| 455 | } | ||
| 456 | |||
| 457 | skb = __hci_cmd_sync(hdev, hdev->msft_opcode, total_size, cp, | ||
| 458 | HCI_CMD_TIMEOUT); | ||
| 459 | kfree(cp); | ||
| 460 | |||
| 461 | if (IS_ERR(skb)) | ||
| 462 | return PTR_ERR(skb); | ||
| 463 | |||
| 464 | status = skb->data[0]; | ||
| 465 | skb_pull(skb, 1); | ||
| 466 | |||
| 467 | msft_le_monitor_advertisement_cb(hdev, status, hdev->msft_opcode, skb); | ||
| 468 | |||
| 469 | return status; | ||
| 232 | } | 470 | } |
| 233 | 471 | ||
| 234 | /* This function requires the caller holds hdev->lock */ | 472 | /* This function requires the caller holds hci_req_sync_lock */ |
| 235 | void msft_resume(struct hci_dev *hdev) | 473 | int msft_resume_sync(struct hci_dev *hdev) |
| 236 | { | 474 | { |
| 237 | struct msft_data *msft = hdev->msft_data; | 475 | struct msft_data *msft = hdev->msft_data; |
| 476 | struct adv_monitor *monitor; | ||
| 477 | int handle = 0; | ||
| 238 | 478 | ||
| 239 | if (!msft) | 479 | if (!msft || !msft_monitor_supported(hdev)) |
| 240 | return; | 480 | return 0; |
| 241 | 481 | ||
| 242 | if (msft_monitor_supported(hdev)) { | 482 | msft->resuming = true; |
| 243 | msft->reregistering = true; | 483 | |
| 244 | /* Monitors are removed on suspend, so we need to add all | 484 | while (1) { |
| 245 | * monitors on resume. | 485 | monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); |
| 246 | */ | 486 | if (!monitor) |
| 247 | reregister_monitor(hdev, 0); | 487 | break; |
| 488 | |||
| 489 | msft_add_monitor_sync(hdev, monitor); | ||
| 490 | |||
| 491 | handle++; | ||
| 248 | } | 492 | } |
| 493 | |||
| 494 | /* All monitors have been resumed */ | ||
| 495 | msft->resuming = false; | ||
| 496 | |||
| 497 | return 0; | ||
| 249 | } | 498 | } |
| 250 | 499 | ||
| 251 | void msft_do_open(struct hci_dev *hdev) | 500 | void msft_do_open(struct hci_dev *hdev) |
| @@ -275,7 +524,7 @@ void msft_do_open(struct hci_dev *hdev) · 23 unmodified lines | |||
| 275 | } | 524 | } |
| 276 | 525 | ||
| 277 | if (msft_monitor_supported(hdev)) { | 526 | if (msft_monitor_supported(hdev)) { |
| 278 | msft->reregistering = true; | 527 | msft->resuming = true; |
| 279 | msft_set_filter_enable(hdev, true); | 528 | msft_set_filter_enable(hdev, true); |
| 280 | /* Monitors get removed on power off, so we need to explicitly | 529 | /* Monitors get removed on power off, so we need to explicitly |
| 281 | * tell the controller to re-monitor. | 530 | * tell the controller to re-monitor. |
| @@ -381,151 +630,6 @@ __u64 msft_get_features(struct hci_dev *hdev) · 99 unmodified lines | |||
| 381 | return msft ? msft->features : 0; | 630 | return msft ? msft->features : 0; |
| 382 | } | 631 | } |
| 383 | 632 | ||
| 384 | /* is_mgmt = true matches the handle exposed to userspace via mgmt. | ||
| 385 | * is_mgmt = false matches the handle used by the msft controller. | ||
| 386 | * This function requires the caller holds hdev->lock | ||
| 387 | */ | ||
| 388 | static struct msft_monitor_advertisement_handle_data *msft_find_handle_data | ||
| 389 | (struct hci_dev *hdev, u16 handle, bool is_mgmt) | ||
| 390 | { | ||
| 391 | struct msft_monitor_advertisement_handle_data *entry; | ||
| 392 | struct msft_data *msft = hdev->msft_data; | ||
| 393 | |||
| 394 | list_for_each_entry(entry, &msft->handle_map, list) { | ||
| 395 | if (is_mgmt && entry->mgmt_handle == handle) | ||
| 396 | return entry; | ||
| 397 | if (!is_mgmt && entry->msft_handle == handle) | ||
| 398 | return entry; | ||
| 399 | } | ||
| 400 | |||
| 401 | return NULL; | ||
| 402 | } | ||
| 403 | |||
| 404 | static void msft_le_monitor_advertisement_cb(struct hci_dev *hdev, | ||
| 405 | u8 status, u16 opcode, | ||
| 406 | struct sk_buff *skb) | ||
| 407 | { | ||
| 408 | struct msft_rp_le_monitor_advertisement *rp; | ||
| 409 | struct adv_monitor *monitor; | ||
| 410 | struct msft_monitor_advertisement_handle_data *handle_data; | ||
| 411 | struct msft_data *msft = hdev->msft_data; | ||
| 412 | |||
| 413 | hci_dev_lock(hdev); | ||
| 414 | |||
| 415 | monitor = idr_find(&hdev->adv_monitors_idr, msft->pending_add_handle); | ||
| 416 | if (!monitor) { | ||
| 417 | bt_dev_err(hdev, "msft add advmon: monitor %u is not found!", | ||
| 418 | msft->pending_add_handle); | ||
| 419 | status = HCI_ERROR_UNSPECIFIED; | ||
| 420 | goto unlock; | ||
| 421 | } | ||
| 422 | |||
| 423 | if (status) | ||
| 424 | goto unlock; | ||
| 425 | |||
| 426 | rp = (struct msft_rp_le_monitor_advertisement *)skb->data; | ||
| 427 | if (skb->len < sizeof(*rp)) { | ||
| 428 | status = HCI_ERROR_UNSPECIFIED; | ||
| 429 | goto unlock; | ||
| 430 | } | ||
| 431 | |||
| 432 | handle_data = kmalloc(sizeof(*handle_data), GFP_KERNEL); | ||
| 433 | if (!handle_data) { | ||
| 434 | status = HCI_ERROR_UNSPECIFIED; | ||
| 435 | goto unlock; | ||
| 436 | } | ||
| 437 | |||
| 438 | handle_data->mgmt_handle = monitor->handle; | ||
| 439 | handle_data->msft_handle = rp->handle; | ||
| 440 | INIT_LIST_HEAD(&handle_data->list); | ||
| 441 | list_add(&handle_data->list, &msft->handle_map); | ||
| 442 | |||
| 443 | monitor->state = ADV_MONITOR_STATE_OFFLOADED; | ||
| 444 | |||
| 445 | unlock: | ||
| 446 | if (status && monitor) | ||
| 447 | hci_free_adv_monitor(hdev, monitor); | ||
| 448 | |||
| 449 | /* If in restart/reregister sequence, keep registering. */ | ||
| 450 | if (msft->reregistering) | ||
| 451 | reregister_monitor(hdev, msft->pending_add_handle + 1); | ||
| 452 | |||
| 453 | hci_dev_unlock(hdev); | ||
| 454 | |||
| 455 | if (!msft->reregistering) | ||
| 456 | hci_add_adv_patterns_monitor_complete(hdev, status); | ||
| 457 | } | ||
| 458 | |||
| 459 | static void msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, | ||
| 460 | u8 status, u16 opcode, | ||
| 461 | struct sk_buff *skb) | ||
| 462 | { | ||
| 463 | struct msft_cp_le_cancel_monitor_advertisement *cp; | ||
| 464 | struct msft_rp_le_cancel_monitor_advertisement *rp; | ||
| 465 | struct adv_monitor *monitor; | ||
| 466 | struct msft_monitor_advertisement_handle_data *handle_data; | ||
| 467 | struct msft_data *msft = hdev->msft_data; | ||
| 468 | int err; | ||
| 469 | bool pending; | ||
| 470 | |||
| 471 | if (status) | ||
| 472 | goto done; | ||
| 473 | |||
| 474 | rp = (struct msft_rp_le_cancel_monitor_advertisement *)skb->data; | ||
| 475 | if (skb->len < sizeof(*rp)) { | ||
| 476 | status = HCI_ERROR_UNSPECIFIED; | ||
| 477 | goto done; | ||
| 478 | } | ||
| 479 | |||
| 480 | hci_dev_lock(hdev); | ||
| 481 | |||
| 482 | cp = hci_sent_cmd_data(hdev, hdev->msft_opcode); | ||
| 483 | handle_data = msft_find_handle_data(hdev, cp->handle, false); | ||
| 484 | |||
| 485 | if (handle_data) { | ||
| 486 | monitor = idr_find(&hdev->adv_monitors_idr, | ||
| 487 | handle_data->mgmt_handle); | ||
| 488 | |||
| 489 | if (monitor && monitor->state == ADV_MONITOR_STATE_OFFLOADED) | ||
| 490 | monitor->state = ADV_MONITOR_STATE_REGISTERED; | ||
| 491 | |||
| 492 | /* Do not free the monitor if it is being removed due to | ||
| 493 | * suspend. It will be re-monitored on resume. | ||
| 494 | */ | ||
| 495 | if (monitor && !msft->suspending) | ||
| 496 | hci_free_adv_monitor(hdev, monitor); | ||
| 497 | |||
| 498 | list_del(&handle_data->list); | ||
| 499 | kfree(handle_data); | ||
| 500 | } | ||
| 501 | |||
| 502 | /* If in suspend/remove sequence, keep removing. */ | ||
| 503 | if (msft->suspending) | ||
| 504 | remove_monitor_on_suspend(hdev, | ||
| 505 | msft->pending_remove_handle + 1); | ||
| 506 | |||
| 507 | /* If remove all monitors is required, we need to continue the process | ||
| 508 | * here because the earlier it was paused when waiting for the | ||
| 509 | * response from controller. | ||
| 510 | */ | ||
| 511 | if (msft->pending_remove_handle == 0) { | ||
| 512 | pending = hci_remove_all_adv_monitor(hdev, &err); | ||
| 513 | if (pending) { | ||
| 514 | hci_dev_unlock(hdev); | ||
| 515 | return; | ||
| 516 | } | ||
| 517 | |||
| 518 | if (err) | ||
| 519 | status = HCI_ERROR_UNSPECIFIED; | ||
| 520 | } | ||
| 521 | |||
| 522 | hci_dev_unlock(hdev); | ||
| 523 | |||
| 524 | done: | ||
| 525 | if (!msft->suspending) | ||
| 526 | hci_remove_adv_monitor_complete(hdev, status); | ||
| 527 | } | ||
| 528 | |||
| 529 | static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev, | 633 | static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev, |
| 530 | u8 status, u16 opcode, | 634 | u8 status, u16 opcode, |
| 531 | struct sk_buff *skb) | 635 | struct sk_buff *skb) |
| @@ -560,35 +664,6 @@ static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev, · 28 unmodified lines | |||
| 560 | hci_dev_unlock(hdev); | 664 | hci_dev_unlock(hdev); |
| 561 | } | 665 | } |
| 562 | 666 | ||
| 563 | static bool msft_monitor_rssi_valid(struct adv_monitor *monitor) | ||
| 564 | { | ||
| 565 | struct adv_rssi_thresholds *r = &monitor->rssi; | ||
| 566 | |||
| 567 | if (r->high_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || | ||
| 568 | r->high_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX || | ||
| 569 | r->low_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || | ||
| 570 | r->low_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX) | ||
| 571 | return false; | ||
| 572 | |||
| 573 | /* High_threshold_timeout is not supported, | ||
| 574 | * once high_threshold is reached, events are immediately reported. | ||
| 575 | */ | ||
| 576 | if (r->high_threshold_timeout != 0) | ||
| 577 | return false; | ||
| 578 | |||
| 579 | if (r->low_threshold_timeout > MSFT_RSSI_LOW_TIMEOUT_MAX) | ||
| 580 | return false; | ||
| 581 | |||
| 582 | /* Sampling period from 0x00 to 0xFF are all allowed */ | ||
| 583 | return true; | ||
| 584 | } | ||
| 585 | |||
| 586 | static bool msft_monitor_pattern_valid(struct adv_monitor *monitor) | ||
| 587 | { | ||
| 588 | return msft_monitor_rssi_valid(monitor); | ||
| 589 | /* No additional check needed for pattern-based monitor */ | ||
| 590 | } | ||
| 591 | |||
| 592 | /* This function requires the caller holds hdev->lock */ | 667 | /* This function requires the caller holds hdev->lock */ |
| 593 | static int __msft_add_monitor_pattern(struct hci_dev *hdev, | 668 | static int __msft_add_monitor_pattern(struct hci_dev *hdev, |
| 594 | struct adv_monitor *monitor) | 669 | struct adv_monitor *monitor) |
| @@ -656,7 +731,7 @@ int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor) · 61 unmodified lines | |||
| 656 | if (!msft) | 731 | if (!msft) |
| 657 | return -EOPNOTSUPP; | 732 | return -EOPNOTSUPP; |
| 658 | 733 | ||
| 659 | if (msft->reregistering || msft->suspending) | 734 | if (msft->resuming || msft->suspending) |
| 660 | return -EBUSY; | 735 | return -EBUSY; |
| 661 | 736 | ||
| 662 | return __msft_add_monitor_pattern(hdev, monitor); | 737 | return __msft_add_monitor_pattern(hdev, monitor); |
| @@ -700,7 +775,7 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, · 37 unmodified lines | |||
| 700 | if (!msft) | 775 | if (!msft) |
| 701 | return -EOPNOTSUPP; | 776 | return -EOPNOTSUPP; |
| 702 | 777 | ||
| 703 | if (msft->reregistering || msft->suspending) | 778 | if (msft->resuming || msft->suspending) |
| 704 | return -EBUSY; | 779 | return -EBUSY; |
| 705 | 780 | ||
| 706 | return __msft_remove_monitor(hdev, monitor, handle); | 781 | return __msft_remove_monitor(hdev, monitor, handle); |
| @@ -24,8 +24,8 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, · 23 unmodified lines | |||
| 24 | u16 handle); | 24 | u16 handle); |
| 25 | void msft_req_add_set_filter_enable(struct hci_request *req, bool enable); | 25 | void msft_req_add_set_filter_enable(struct hci_request *req, bool enable); |
| 26 | int msft_set_filter_enable(struct hci_dev *hdev, bool enable); | 26 | int msft_set_filter_enable(struct hci_dev *hdev, bool enable); |
| 27 | void msft_suspend(struct hci_dev *hdev); | 27 | int msft_suspend_sync(struct hci_dev *hdev); |
| 28 | void msft_resume(struct hci_dev *hdev); | 28 | int msft_resume_sync(struct hci_dev *hdev); |
| 29 | bool msft_curve_validity(struct hci_dev *hdev); | 29 | bool msft_curve_validity(struct hci_dev *hdev); |
| 30 | 30 | ||
| 31 | #else | 31 | #else |
| @@ -61,8 +61,15 @@ static inline int msft_set_filter_enable(struct hci_dev *hdev, bool enable) · 29 unmodified lines | |||
| 61 | return -EOPNOTSUPP; | 61 | return -EOPNOTSUPP; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | static inline void msft_suspend(struct hci_dev *hdev) {} | 64 | static inline int msft_suspend_sync(struct hci_dev *hdev) |
| 65 | static inline void msft_resume(struct hci_dev *hdev) {} | 65 | { |
| 66 | return -EOPNOTSUPP; | ||
| 67 | } | ||
| 68 | |||
| 69 | static inline int msft_resume_sync(struct hci_dev *hdev) | ||
| 70 | { | ||
| 71 | return -EOPNOTSUPP; | ||
| 72 | } | ||
| 66 | 73 | ||
| 67 | static inline bool msft_curve_validity(struct hci_dev *hdev) | 74 | static inline bool msft_curve_validity(struct hci_dev *hdev) |
| 68 | { | 75 | { |