Johan Hedberg says: ==================== pull request: bluetooth-next 2020-07-31 Here's the main bluetooth-next pull request for 5.9: - Fix firmware filenames for Marvell chipsets - Several suspend-related fixes - Addedd mgmt commands for runtime configuration - Multiple fixes for Qualcomm-based controllers - Add new monitoring feature for mgmt - Fix handling of legacy cipher (E4) together with security level 4 - Add support for Realtek 8822CE controller - Fix issues with Chinese controllers using fake VID/PID values - Multiple other smaller fixes & improvements ====================
Unified · Split
| @@ -44,7 +44,7 @@ examples: · 43 unmodified lines | ||
| 44 | 44 | uart1 { |
| 45 | 45 | pinctrl-names = "default"; |
| 46 | 46 | pinctrl-0 = <&uart1_pins>, <&uart1_rts_cts_pins>; |
| 47 | − uart-has-rtscts = <1>; | |
| 47 | + uart-has-rtscts; | |
| 48 | 48 | |
| 49 | 49 | bluetooth { |
| 50 | 50 | compatible = "realtek,rtl8723bs-bt"; |
| @@ -106,7 +106,7 @@ static void bcm203x_complete(struct urb *urb) · 105 unmodified lines | ||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | data->state = BCM203X_LOAD_FIRMWARE; |
| 109 | − /* fall through */ | |
| 109 | + fallthrough; | |
| 110 | 110 | case BCM203X_LOAD_FIRMWARE: |
| 111 | 111 | if (data->fw_sent == data->fw_size) { |
| 112 | 112 | usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP), |
| @@ -295,7 +295,6 @@ static void bluecard_write_wakeup(struct bluecard_info *info) · 294 unmodified lines | ||
| 295 | 295 | baud_reg = REG_CONTROL_BAUD_RATE_115200; |
| 296 | 296 | break; |
| 297 | 297 | case PKT_BAUD_RATE_57600: |
| 298 | − /* Fall through... */ | |
| 299 | 298 | default: |
| 300 | 299 | baud_reg = REG_CONTROL_BAUD_RATE_57600; |
| 301 | 300 | break; |
| @@ -585,7 +584,6 @@ static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud) · 283 unmodified lines | ||
| 585 | 584 | hci_skb_pkt_type(skb) = PKT_BAUD_RATE_115200; |
| 586 | 585 | break; |
| 587 | 586 | case 57600: |
| 588 | − /* Fall through... */ | |
| 589 | 587 | default: |
| 590 | 588 | cmd[4] = 0x03; |
| 591 | 589 | hci_skb_pkt_type(skb) = PKT_BAUD_RATE_57600; |
| @@ -754,6 +754,65 @@ void btintel_reset_to_bootloader(struct hci_dev *hdev) · 753 unmodified lines | ||
| 754 | 754 | } |
| 755 | 755 | EXPORT_SYMBOL_GPL(btintel_reset_to_bootloader); |
| 756 | 756 | |
| 757 | +int btintel_read_debug_features(struct hci_dev *hdev, | |
| 758 | + struct intel_debug_features *features) | |
| 759 | +{ | |
| 760 | + struct sk_buff *skb; | |
| 761 | + u8 page_no = 1; | |
| 762 | + | |
| 763 | + /* Intel controller supports two pages, each page is of 128-bit | |
| 764 | + * feature bit mask. And each bit defines specific feature support | |
| 765 | + */ | |
| 766 | + skb = __hci_cmd_sync(hdev, 0xfca6, sizeof(page_no), &page_no, | |
| 767 | + HCI_INIT_TIMEOUT); | |
| 768 | + if (IS_ERR(skb)) { | |
| 769 | + bt_dev_err(hdev, "Reading supported features failed (%ld)", | |
| 770 | + PTR_ERR(skb)); | |
| 771 | + return PTR_ERR(skb); | |
| 772 | + } | |
| 773 | + | |
| 774 | + if (skb->len != (sizeof(features->page1) + 3)) { | |
| 775 | + bt_dev_err(hdev, "Supported features event size mismatch"); | |
| 776 | + kfree_skb(skb); | |
| 777 | + return -EILSEQ; | |
| 778 | + } | |
| 779 | + | |
| 780 | + memcpy(features->page1, skb->data + 3, sizeof(features->page1)); | |
| 781 | + | |
| 782 | + /* Read the supported features page2 if required in future. | |
| 783 | + */ | |
| 784 | + kfree_skb(skb); | |
| 785 | + return 0; | |
| 786 | +} | |
| 787 | +EXPORT_SYMBOL_GPL(btintel_read_debug_features); | |
| 788 | + | |
| 789 | +int btintel_set_debug_features(struct hci_dev *hdev, | |
| 790 | + const struct intel_debug_features *features) | |
| 791 | +{ | |
| 792 | + u8 mask[11] = { 0x0a, 0x92, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, | |
| 793 | + 0x00, 0x00, 0x00 }; | |
| 794 | + struct sk_buff *skb; | |
| 795 | + | |
| 796 | + if (!features) | |
| 797 | + return -EINVAL; | |
| 798 | + | |
| 799 | + if (!(features->page1[0] & 0x3f)) { | |
| 800 | + bt_dev_info(hdev, "Telemetry exception format not supported"); | |
| 801 | + return 0; | |
| 802 | + } | |
| 803 | + | |
| 804 | + skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT); | |
| 805 | + if (IS_ERR(skb)) { | |
| 806 | + bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)", | |
| 807 | + PTR_ERR(skb)); | |
| 808 | + return PTR_ERR(skb); | |
| 809 | + } | |
| 810 | + | |
| 811 | + kfree_skb(skb); | |
| 812 | + return 0; | |
| 813 | +} | |
| 814 | +EXPORT_SYMBOL_GPL(btintel_set_debug_features); | |
| 815 | + | |
| 757 | 816 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 758 | 817 | MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION); |
| 759 | 818 | MODULE_VERSION(VERSION); |
| @@ -62,6 +62,10 @@ struct intel_reset { · 61 unmodified lines | ||
| 62 | 62 | __le32 boot_param; |
| 63 | 63 | } __packed; |
| 64 | 64 | |
| 65 | +struct intel_debug_features { | |
| 66 | + __u8 page1[16]; | |
| 67 | +} __packed; | |
| 68 | + | |
| 65 | 69 | #if IS_ENABLED(CONFIG_BT_INTEL) |
| 66 | 70 | |
| 67 | 71 | int btintel_check_bdaddr(struct hci_dev *hdev); |
| @@ -88,6 +92,10 @@ int btintel_read_boot_params(struct hci_dev *hdev, · 20 unmodified lines | ||
| 88 | 92 | int btintel_download_firmware(struct hci_dev *dev, const struct firmware *fw, |
| 89 | 93 | u32 *boot_param); |
| 90 | 94 | void btintel_reset_to_bootloader(struct hci_dev *hdev); |
| 95 | +int btintel_read_debug_features(struct hci_dev *hdev, | |
| 96 | + struct intel_debug_features *features); | |
| 97 | +int btintel_set_debug_features(struct hci_dev *hdev, | |
| 98 | + const struct intel_debug_features *features); | |
| 91 | 99 | #else |
| 92 | 100 | |
| 93 | 101 | static inline int btintel_check_bdaddr(struct hci_dev *hdev) |
| @@ -186,4 +194,17 @@ static inline int btintel_download_firmware(struct hci_dev *dev, · 92 unmodified lines | ||
| 186 | 194 | static inline void btintel_reset_to_bootloader(struct hci_dev *hdev) |
| 187 | 195 | { |
| 188 | 196 | } |
| 197 | + | |
| 198 | +static inline int btintel_read_debug_features(struct hci_dev *hdev, | |
| 199 | + struct intel_debug_features *features) | |
| 200 | +{ | |
| 201 | + return -EOPNOTSUPP; | |
| 202 | +} | |
| 203 | + | |
| 204 | +static inline int btintel_set_debug_features(struct hci_dev *hdev, | |
| 205 | + const struct intel_debug_features *features) | |
| 206 | +{ | |
| 207 | + return -EOPNOTSUPP; | |
| 208 | +} | |
| 209 | + | |
| 189 | 210 | #endif |
| @@ -587,6 +587,14 @@ static int btmrvl_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) · 586 unmodified lines | ||
| 587 | 587 | return 0; |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | +static bool btmrvl_prevent_wake(struct hci_dev *hdev) | |
| 591 | +{ | |
| 592 | + struct btmrvl_private *priv = hci_get_drvdata(hdev); | |
| 593 | + struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; | |
| 594 | + | |
| 595 | + return !device_may_wakeup(&card->func->dev); | |
| 596 | +} | |
| 597 | + | |
| 590 | 598 | /* |
| 591 | 599 | * This function handles the event generated by firmware, rx data |
| 592 | 600 | * received from firmware, and tx data sent from kernel. |
| @@ -669,6 +677,7 @@ static int btmrvl_service_main_thread(void *data) · 76 unmodified lines | ||
| 669 | 677 | int btmrvl_register_hdev(struct btmrvl_private *priv) |
| 670 | 678 | { |
| 671 | 679 | struct hci_dev *hdev = NULL; |
| 680 | + struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; | |
| 672 | 681 | int ret; |
| 673 | 682 | |
| 674 | 683 | hdev = hci_alloc_dev(); |
| @@ -687,6 +696,8 @@ int btmrvl_register_hdev(struct btmrvl_private *priv) · 12 unmodified lines | ||
| 687 | 696 | hdev->send = btmrvl_send_frame; |
| 688 | 697 | hdev->setup = btmrvl_setup; |
| 689 | 698 | hdev->set_bdaddr = btmrvl_set_bdaddr; |
| 699 | + hdev->prevent_wake = btmrvl_prevent_wake; | |
| 700 | + SET_HCIDEV_DEV(hdev, &card->func->dev); | |
| 690 | 701 | |
| 691 | 702 | hdev->dev_type = priv->btmrvl_dev.dev_type; |
| 692 | 703 | |
| @@ -111,6 +111,9 @@ static int btmrvl_sdio_probe_of(struct device *dev, · 110 unmodified lines | ||
| 111 | 111 | "Failed to request irq_bt %d (%d)\n", |
| 112 | 112 | cfg->irq_bt, ret); |
| 113 | 113 | } |
| 114 | + | |
| 115 | + /* Configure wakeup (enabled by default) */ | |
| 116 | + device_init_wakeup(dev, true); | |
| 114 | 117 | disable_irq(cfg->irq_bt); |
| 115 | 118 | } |
| 116 | 119 | } |
| @@ -328,7 +331,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = { · 211 unmodified lines | ||
| 328 | 331 | |
| 329 | 332 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8977 = { |
| 330 | 333 | .helper = NULL, |
| 331 | − .firmware = "mrvl/sd8977_uapsta.bin", | |
| 334 | + .firmware = "mrvl/sdsd8977_combo_v2.bin", | |
| 332 | 335 | .reg = &btmrvl_reg_8977, |
| 333 | 336 | .support_pscan_win_report = true, |
| 334 | 337 | .sd_blksz_fw_dl = 256, |
| @@ -346,7 +349,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8987 = { · 11 unmodified lines | ||
| 346 | 349 | |
| 347 | 350 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8997 = { |
| 348 | 351 | .helper = NULL, |
| 349 | − .firmware = "mrvl/sd8997_uapsta.bin", | |
| 352 | + .firmware = "mrvl/sdsd8997_combo_v4.bin", | |
| 350 | 353 | .reg = &btmrvl_reg_8997, |
| 351 | 354 | .support_pscan_win_report = true, |
| 352 | 355 | .sd_blksz_fw_dl = 256, |
| @@ -1654,6 +1657,7 @@ static void btmrvl_sdio_remove(struct sdio_func *func) · 1301 unmodified lines | ||
| 1654 | 1657 | MODULE_SHUTDOWN_REQ); |
| 1655 | 1658 | btmrvl_sdio_disable_host_int(card); |
| 1656 | 1659 | } |
| 1660 | + | |
| 1657 | 1661 | BT_DBG("unregister dev"); |
| 1658 | 1662 | card->priv->surprise_removed = true; |
| 1659 | 1663 | btmrvl_sdio_unregister_dev(card); |
| @@ -1690,7 +1694,8 @@ static int btmrvl_sdio_suspend(struct device *dev) · 30 unmodified lines | ||
| 1690 | 1694 | } |
| 1691 | 1695 | |
| 1692 | 1696 | /* Enable platform specific wakeup interrupt */ |
| 1693 | − if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0) { | |
| 1697 | + if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0 && | |
| 1698 | + device_may_wakeup(dev)) { | |
| 1694 | 1699 | card->plt_wake_cfg->wake_by_bt = false; |
| 1695 | 1700 | enable_irq(card->plt_wake_cfg->irq_bt); |
| 1696 | 1701 | enable_irq_wake(card->plt_wake_cfg->irq_bt); |
| @@ -1707,7 +1712,8 @@ static int btmrvl_sdio_suspend(struct device *dev) · 10 unmodified lines | ||
| 1707 | 1712 | BT_ERR("HS not activated, suspend failed!"); |
| 1708 | 1713 | /* Disable platform specific wakeup interrupt */ |
| 1709 | 1714 | if (card->plt_wake_cfg && |
| 1710 | − card->plt_wake_cfg->irq_bt >= 0) { | |
| 1715 | + card->plt_wake_cfg->irq_bt >= 0 && | |
| 1716 | + device_may_wakeup(dev)) { | |
| 1711 | 1717 | disable_irq_wake(card->plt_wake_cfg->irq_bt); |
| 1712 | 1718 | disable_irq(card->plt_wake_cfg->irq_bt); |
| 1713 | 1719 | } |
| @@ -1767,7 +1773,8 @@ static int btmrvl_sdio_resume(struct device *dev) · 53 unmodified lines | ||
| 1767 | 1773 | hci_resume_dev(hcidev); |
| 1768 | 1774 | |
| 1769 | 1775 | /* Disable platform specific wakeup interrupt */ |
| 1770 | − if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0) { | |
| 1776 | + if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0 && | |
| 1777 | + device_may_wakeup(dev)) { | |
| 1771 | 1778 | disable_irq_wake(card->plt_wake_cfg->irq_bt); |
| 1772 | 1779 | disable_irq(card->plt_wake_cfg->irq_bt); |
| 1773 | 1780 | if (card->plt_wake_cfg->wake_by_bt) |
| @@ -1831,6 +1838,6 @@ MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); · 57 unmodified lines | ||
| 1831 | 1838 | MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin"); |
| 1832 | 1839 | MODULE_FIRMWARE("mrvl/sd8887_uapsta.bin"); |
| 1833 | 1840 | MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin"); |
| 1834 | −MODULE_FIRMWARE("mrvl/sd8977_uapsta.bin"); | |
| 1841 | +MODULE_FIRMWARE("mrvl/sdsd8977_combo_v2.bin"); | |
| 1835 | 1842 | MODULE_FIRMWARE("mrvl/sd8987_uapsta.bin"); |
| 1836 | −MODULE_FIRMWARE("mrvl/sd8997_uapsta.bin"); | |
| 1843 | +MODULE_FIRMWARE("mrvl/sdsd8997_combo_v4.bin"); | |
| @@ -685,7 +685,7 @@ static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 684 unmodified lines | ||
| 685 | 685 | const u8 *fw_ptr; |
| 686 | 686 | size_t fw_size; |
| 687 | 687 | int err, dlen; |
| 688 | − u8 flag; | |
| 688 | + u8 flag, param; | |
| 689 | 689 | |
| 690 | 690 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 691 | 691 | if (err < 0) { |
| @@ -693,6 +693,20 @@ static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 1 unmodified line | ||
| 693 | 693 | return err; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | + /* Power on data RAM the firmware relies on. */ | |
| 697 | + param = 1; | |
| 698 | + wmt_params.op = MTK_WMT_FUNC_CTRL; | |
| 699 | + wmt_params.flag = 3; | |
| 700 | + wmt_params.dlen = sizeof(param); | |
| 701 | + wmt_params.data = ¶m; | |
| 702 | + wmt_params.status = NULL; | |
| 703 | + | |
| 704 | + err = mtk_hci_wmt_sync(hdev, &wmt_params); | |
| 705 | + if (err < 0) { | |
| 706 | + bt_dev_err(hdev, "Failed to power on data RAM (%d)", err); | |
| 707 | + return err; | |
| 708 | + } | |
| 709 | + | |
| 696 | 710 | fw_ptr = fw->data; |
| 697 | 711 | fw_size = fw->size; |
| 698 | 712 | |
| @@ -400,6 +400,27 @@ out: · 399 unmodified lines | ||
| 400 | 400 | return ret; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | +static int qca_disable_soc_logging(struct hci_dev *hdev) | |
| 404 | +{ | |
| 405 | + struct sk_buff *skb; | |
| 406 | + u8 cmd[2]; | |
| 407 | + int err; | |
| 408 | + | |
| 409 | + cmd[0] = QCA_DISABLE_LOGGING_SUB_OP; | |
| 410 | + cmd[1] = 0x00; | |
| 411 | + skb = __hci_cmd_sync_ev(hdev, QCA_DISABLE_LOGGING, sizeof(cmd), cmd, | |
| 412 | + HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); | |
| 413 | + if (IS_ERR(skb)) { | |
| 414 | + err = PTR_ERR(skb); | |
| 415 | + bt_dev_err(hdev, "QCA Failed to disable soc logging(%d)", err); | |
| 416 | + return err; | |
| 417 | + } | |
| 418 | + | |
| 419 | + kfree_skb(skb); | |
| 420 | + | |
| 421 | + return 0; | |
| 422 | +} | |
| 423 | + | |
| 403 | 424 | int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 404 | 425 | { |
| 405 | 426 | struct sk_buff *skb; |
| @@ -486,6 +507,12 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, · 80 unmodified lines | ||
| 486 | 507 | return err; |
| 487 | 508 | } |
| 488 | 509 | |
| 510 | + if (soc_type >= QCA_WCN3991) { | |
| 511 | + err = qca_disable_soc_logging(hdev); | |
| 512 | + if (err < 0) | |
| 513 | + return err; | |
| 514 | + } | |
| 515 | + | |
| 489 | 516 | /* Perform HCI reset */ |
| 490 | 517 | err = qca_send_reset(hdev); |
| 491 | 518 | if (err < 0) { |
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #define EDL_NVM_ACCESS_SET_REQ_CMD (0x01) |
| 15 | 15 | #define MAX_SIZE_PER_TLV_SEGMENT (243) |
| 16 | 16 | #define QCA_PRE_SHUTDOWN_CMD (0xFC08) |
| 17 | +#define QCA_DISABLE_LOGGING (0xFC17) | |
| 17 | 18 | |
| 18 | 19 | #define EDL_CMD_REQ_RES_EVT (0x00) |
| 19 | 20 | #define EDL_PATCH_VER_RES_EVT (0x19) |
| @@ -22,6 +23,7 @@ · 2 unmodified lines | ||
| 22 | 23 | #define EDL_CMD_EXE_STATUS_EVT (0x00) |
| 23 | 24 | #define EDL_SET_BAUDRATE_RSP_EVT (0x92) |
| 24 | 25 | #define EDL_NVM_ACCESS_CODE_EVT (0x0B) |
| 26 | +#define QCA_DISABLE_LOGGING_SUB_OP (0x14) | |
| 25 | 27 | |
| 26 | 28 | #define EDL_TAG_ID_HCI (17) |
| 27 | 29 | #define EDL_TAG_ID_DEEP_SLEEP (27) |
| @@ -359,6 +359,10 @@ static const struct usb_device_id blacklist_table[] = { · 358 unmodified lines | ||
| 359 | 359 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
| 360 | 360 | .driver_info = BTUSB_IGNORE }, |
| 361 | 361 | |
| 362 | + /* Realtek 8822CE Bluetooth devices */ | |
| 363 | + { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | | |
| 364 | + BTUSB_WIDEBAND_SPEECH }, | |
| 365 | + | |
| 362 | 366 | /* Realtek Bluetooth devices */ |
| 363 | 367 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), |
| 364 | 368 | .driver_info = BTUSB_REALTEK }, |
| @@ -453,6 +457,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { · 88 unmodified lines | ||
| 453 | 457 | #define BTUSB_HW_RESET_ACTIVE 12 |
| 454 | 458 | #define BTUSB_TX_WAIT_VND_EVT 13 |
| 455 | 459 | #define BTUSB_WAKEUP_DISABLE 14 |
| 460 | +#define BTUSB_USE_ALT1_FOR_WBS 15 | |
| 456 | 461 | |
| 457 | 462 | struct btusb_data { |
| 458 | 463 | struct hci_dev *hdev; |
| @@ -511,7 +516,6 @@ struct btusb_data { · 52 unmodified lines | ||
| 511 | 516 | unsigned cmd_timeout_cnt; |
| 512 | 517 | }; |
| 513 | 518 | |
| 514 | − | |
| 515 | 519 | static void btusb_intel_cmd_timeout(struct hci_dev *hdev) |
| 516 | 520 | { |
| 517 | 521 | struct btusb_data *data = hci_get_drvdata(hdev); |
| @@ -573,6 +577,23 @@ static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) · 55 unmodified lines | ||
| 573 | 577 | gpiod_set_value_cansleep(reset_gpio, 0); |
| 574 | 578 | } |
| 575 | 579 | |
| 580 | +static void btusb_qca_cmd_timeout(struct hci_dev *hdev) | |
| 581 | +{ | |
| 582 | + struct btusb_data *data = hci_get_drvdata(hdev); | |
| 583 | + int err; | |
| 584 | + | |
| 585 | + if (++data->cmd_timeout_cnt < 5) | |
| 586 | + return; | |
| 587 | + | |
| 588 | + bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device."); | |
| 589 | + /* This is not an unbalanced PM reference since the device will reset */ | |
| 590 | + err = usb_autopm_get_interface(data->intf); | |
| 591 | + if (!err) | |
| 592 | + usb_queue_reset_device(data->intf); | |
| 593 | + else | |
| 594 | + bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err); | |
| 595 | +} | |
| 596 | + | |
| 576 | 597 | static inline void btusb_free_frags(struct btusb_data *data) |
| 577 | 598 | { |
| 578 | 599 | unsigned long flags; |
| @@ -1666,14 +1687,15 @@ static void btusb_work(struct work_struct *work) · 1087 unmodified lines | ||
| 1666 | 1687 | new_alts = data->sco_num; |
| 1667 | 1688 | } |
| 1668 | 1689 | } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { |
| 1669 | − | |
| 1670 | − data->usb_alt6_packet_flow = true; | |
| 1671 | − | |
| 1672 | 1690 | /* Check if Alt 6 is supported for Transparent audio */ |
| 1673 | − if (btusb_find_altsetting(data, 6)) | |
| 1691 | + if (btusb_find_altsetting(data, 6)) { | |
| 1692 | + data->usb_alt6_packet_flow = true; | |
| 1674 | 1693 | new_alts = 6; |
| 1675 | − else | |
| 1694 | + } else if (test_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags)) { | |
| 1695 | + new_alts = 1; | |
| 1696 | + } else { | |
| 1676 | 1697 | bt_dev_err(hdev, "Device does not support ALT setting 6"); |
| 1698 | + } | |
| 1677 | 1699 | } |
| 1678 | 1700 | |
| 1679 | 1701 | if (btusb_switch_alt_setting(hdev, new_alts) < 0) |
| @@ -1720,6 +1742,7 @@ static int btusb_setup_csr(struct hci_dev *hdev) · 40 unmodified lines | ||
| 1720 | 1742 | { |
| 1721 | 1743 | struct hci_rp_read_local_version *rp; |
| 1722 | 1744 | struct sk_buff *skb; |
| 1745 | + bool is_fake = false; | |
| 1723 | 1746 | |
| 1724 | 1747 | BT_DBG("%s", hdev->name); |
| 1725 | 1748 | |
| @@ -1739,18 +1762,69 @@ static int btusb_setup_csr(struct hci_dev *hdev) · 13 unmodified lines | ||
| 1739 | 1762 | |
| 1740 | 1763 | rp = (struct hci_rp_read_local_version *)skb->data; |
| 1741 | 1764 | |
| 1742 | − /* Detect controllers which aren't real CSR ones. */ | |
| 1765 | + /* Detect a wide host of Chinese controllers that aren't CSR. | |
| 1766 | + * | |
| 1767 | + * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 | |
| 1768 | + * | |
| 1769 | + * The main thing they have in common is that these are really popular low-cost | |
| 1770 | + * options that support newer Bluetooth versions but rely on heavy VID/PID | |
| 1771 | + * squatting of this poor old Bluetooth 1.1 device. Even sold as such. | |
| 1772 | + * | |
| 1773 | + * We detect actual CSR devices by checking that the HCI manufacturer code | |
| 1774 | + * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and | |
| 1775 | + * HCI rev values always match. As they both store the firmware number. | |
| 1776 | + */ | |
| 1743 | 1777 | if (le16_to_cpu(rp->manufacturer) != 10 || |
| 1744 | − le16_to_cpu(rp->lmp_subver) == 0x0c5c) { | |
| 1778 | + le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver)) | |
| 1779 | + is_fake = true; | |
| 1780 | + | |
| 1781 | + /* Known legit CSR firmware build numbers and their supported BT versions: | |
| 1782 | + * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e | |
| 1783 | + * - 1.2 (0x2) -> 0x04d9, 0x0529 | |
| 1784 | + * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c | |
| 1785 | + * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External) | |
| 1786 | + * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb | |
| 1787 | + * | |
| 1788 | + * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that | |
| 1789 | + * support BT 1.1 only; so it's a dead giveaway when some | |
| 1790 | + * third-party BT 4.0 dongle reuses it. | |
| 1791 | + */ | |
| 1792 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x034e && | |
| 1793 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1) | |
| 1794 | + is_fake = true; | |
| 1795 | + | |
| 1796 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 && | |
| 1797 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2) | |
| 1798 | + is_fake = true; | |
| 1799 | + | |
| 1800 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c && | |
| 1801 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0) | |
| 1802 | + is_fake = true; | |
| 1803 | + | |
| 1804 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 && | |
| 1805 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1) | |
| 1806 | + is_fake = true; | |
| 1807 | + | |
| 1808 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb && | |
| 1809 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0) | |
| 1810 | + is_fake = true; | |
| 1811 | + | |
| 1812 | + if (is_fake) { | |
| 1813 | + bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds..."); | |
| 1814 | + | |
| 1815 | + /* Generally these clones have big discrepancies between | |
| 1816 | + * advertised features and what's actually supported. | |
| 1817 | + * Probably will need to be expanded in the future; | |
| 1818 | + * without these the controller will lock up. | |
| 1819 | + */ | |
| 1820 | + set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); | |
| 1821 | + set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks); | |
| 1822 | + | |
| 1745 | 1823 | /* Clear the reset quirk since this is not an actual |
| 1746 | 1824 | * early Bluetooth 1.1 device from CSR. |
| 1747 | 1825 | */ |
| 1748 | 1826 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
| 1749 | − | |
| 1750 | − /* These fake CSR controllers have all a broken | |
| 1751 | − * stored link key handling and so just disable it. | |
| 1752 | − */ | |
| 1753 | − set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); | |
| 1827 | + clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); | |
| 1754 | 1828 | } |
| 1755 | 1829 | |
| 1756 | 1830 | kfree_skb(skb); |
| @@ -2262,45 +2336,25 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, · 505 unmodified lines | ||
| 2262 | 2336 | return true; |
| 2263 | 2337 | } |
| 2264 | 2338 | |
| 2265 | −static int btusb_setup_intel_new(struct hci_dev *hdev) | |
| 2339 | +static int btusb_intel_download_firmware(struct hci_dev *hdev, | |
| 2340 | + struct intel_version *ver, | |
| 2341 | + struct intel_boot_params *params) | |
| 2266 | 2342 | { |
| 2267 | − struct btusb_data *data = hci_get_drvdata(hdev); | |
| 2268 | − struct intel_version ver; | |
| 2269 | − struct intel_boot_params params; | |
| 2270 | 2343 | const struct firmware *fw; |
| 2271 | 2344 | u32 boot_param; |
| 2272 | 2345 | char fwname[64]; |
| 2273 | − ktime_t calltime, delta, rettime; | |
| 2274 | − unsigned long long duration; | |
| 2275 | 2346 | int err; |
| 2347 | + struct btusb_data *data = hci_get_drvdata(hdev); | |
| 2276 | 2348 | |
| 2277 | − BT_DBG("%s", hdev->name); | |
| 2278 | − | |
| 2279 | − /* Set the default boot parameter to 0x0 and it is updated to | |
| 2280 | − * SKU specific boot parameter after reading Intel_Write_Boot_Params | |
| 2281 | − * command while downloading the firmware. | |
| 2282 | − */ | |
| 2283 | − boot_param = 0x00000000; | |
| 2284 | − | |
| 2285 | − calltime = ktime_get(); | |
| 2286 | − | |
| 2287 | − /* Read the Intel version information to determine if the device | |
| 2288 | − * is in bootloader mode or if it already has operational firmware | |
| 2289 | − * loaded. | |
| 2290 | − */ | |
| 2291 | − err = btintel_read_version(hdev, &ver); | |
| 2292 | − if (err) { | |
| 2293 | − bt_dev_err(hdev, "Intel Read version failed (%d)", err); | |
| 2294 | − btintel_reset_to_bootloader(hdev); | |
| 2295 | − return err; | |
| 2296 | − } | |
| 2349 | + if (!ver || !params) | |
| 2350 | + return -EINVAL; | |
| 2297 | 2351 | |
| 2298 | 2352 | /* The hardware platform number has a fixed value of 0x37 and |
| 2299 | 2353 | * for now only accept this single value. |
| 2300 | 2354 | */ |
| 2301 | − if (ver.hw_platform != 0x37) { | |
| 2355 | + if (ver->hw_platform != 0x37) { | |
| 2302 | 2356 | bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)", |
| 2303 | − ver.hw_platform); | |
| 2357 | + ver->hw_platform); | |
| 2304 | 2358 | return -EINVAL; |
| 2305 | 2359 | } |
| 2306 | 2360 | |
| @@ -2310,7 +2364,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 3 unmodified lines | ||
| 2310 | 2364 | * This check has been put in place to ensure correct forward |
| 2311 | 2365 | * compatibility options when newer hardware variants come along. |
| 2312 | 2366 | */ |
| 2313 | − switch (ver.hw_variant) { | |
| 2367 | + switch (ver->hw_variant) { | |
| 2314 | 2368 | case 0x0b: /* SfP */ |
| 2315 | 2369 | case 0x0c: /* WsP */ |
| 2316 | 2370 | case 0x11: /* JfP */ |
| @@ -2320,11 +2374,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 3 unmodified lines | ||
| 2320 | 2374 | break; |
| 2321 | 2375 | default: |
| 2322 | 2376 | bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)", |
| 2323 | − ver.hw_variant); | |
| 2377 | + ver->hw_variant); | |
| 2324 | 2378 | return -EINVAL; |
| 2325 | 2379 | } |
| 2326 | 2380 | |
| 2327 | − btintel_version_info(hdev, &ver); | |
| 2381 | + btintel_version_info(hdev, ver); | |
| 2328 | 2382 | |
| 2329 | 2383 | /* The firmware variant determines if the device is in bootloader |
| 2330 | 2384 | * mode or is running operational firmware. The value 0x06 identifies |
| @@ -2339,25 +2393,25 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 8 unmodified lines | ||
| 2339 | 2393 | * It is not possible to use the Secure Boot Parameters in this |
| 2340 | 2394 | * case since that command is only available in bootloader mode. |
| 2341 | 2395 | */ |
| 2342 | − if (ver.fw_variant == 0x23) { | |
| 2396 | + if (ver->fw_variant == 0x23) { | |
| 2343 | 2397 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2344 | 2398 | btintel_check_bdaddr(hdev); |
| 2345 | − goto finish; | |
| 2399 | + return 0; | |
| 2346 | 2400 | } |
| 2347 | 2401 | |
| 2348 | 2402 | /* If the device is not in bootloader mode, then the only possible |
| 2349 | 2403 | * choice is to return an error and abort the device initialization. |
| 2350 | 2404 | */ |
| 2351 | − if (ver.fw_variant != 0x06) { | |
| 2405 | + if (ver->fw_variant != 0x06) { | |
| 2352 | 2406 | bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)", |
| 2353 | − ver.fw_variant); | |
| 2407 | + ver->fw_variant); | |
| 2354 | 2408 | return -ENODEV; |
| 2355 | 2409 | } |
| 2356 | 2410 | |
| 2357 | 2411 | /* Read the secure boot parameters to identify the operating |
| 2358 | 2412 | * details of the bootloader. |
| 2359 | 2413 | */ |
| 2360 | − err = btintel_read_boot_params(hdev, ¶ms); | |
| 2414 | + err = btintel_read_boot_params(hdev, params); | |
| 2361 | 2415 | if (err) |
| 2362 | 2416 | return err; |
| 2363 | 2417 | |
| @@ -2365,16 +2419,16 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 1 unmodified line | ||
| 2365 | 2419 | * with a command complete event. If the boot parameters indicate |
| 2366 | 2420 | * that this bootloader does not send them, then abort the setup. |
| 2367 | 2421 | */ |
| 2368 | − if (params.limited_cce != 0x00) { | |
| 2422 | + if (params->limited_cce != 0x00) { | |
| 2369 | 2423 | bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)", |
| 2370 | − params.limited_cce); | |
| 2424 | + params->limited_cce); | |
| 2371 | 2425 | return -EINVAL; |
| 2372 | 2426 | } |
| 2373 | 2427 | |
| 2374 | 2428 | /* If the OTP has no valid Bluetooth device address, then there will |
| 2375 | 2429 | * also be no valid address for the operational firmware. |
| 2376 | 2430 | */ |
| 2377 | − if (!bacmp(¶ms.otp_bdaddr, BDADDR_ANY)) { | |
| 2431 | + if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) { | |
| 2378 | 2432 | bt_dev_info(hdev, "No device address configured"); |
| 2379 | 2433 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 2380 | 2434 | } |
| @@ -2400,7 +2454,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 19 unmodified lines | ||
| 2400 | 2454 | * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. |
| 2401 | 2455 | * |
| 2402 | 2456 | */ |
| 2403 | − err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, | |
| 2457 | + err = btusb_setup_intel_new_get_fw_name(ver, params, fwname, | |
| 2404 | 2458 | sizeof(fwname), "sfi"); |
| 2405 | 2459 | if (!err) { |
| 2406 | 2460 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
| @@ -2415,16 +2469,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 8 unmodified lines | ||
| 2415 | 2469 | |
| 2416 | 2470 | bt_dev_info(hdev, "Found device firmware: %s", fwname); |
| 2417 | 2471 | |
| 2418 | − /* Save the DDC file name for later use to apply once the firmware | |
| 2419 | − * downloading is done. | |
| 2420 | − */ | |
| 2421 | − err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, | |
| 2422 | − sizeof(fwname), "ddc"); | |
| 2423 | − if (!err) { | |
| 2424 | − bt_dev_err(hdev, "Unsupported Intel firmware naming"); | |
| 2425 | − return -EINVAL; | |
| 2426 | − } | |
| 2427 | − | |
| 2428 | 2472 | if (fw->size < 644) { |
| 2429 | 2473 | bt_dev_err(hdev, "Invalid size of firmware file (%zu)", |
| 2430 | 2474 | fw->size); |
| @@ -2479,18 +2523,58 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 48 unmodified lines | ||
| 2479 | 2523 | goto done; |
| 2480 | 2524 | } |
| 2481 | 2525 | |
| 2526 | +done: | |
| 2527 | + release_firmware(fw); | |
| 2528 | + return err; | |
| 2529 | +} | |
| 2530 | + | |
| 2531 | +static int btusb_setup_intel_new(struct hci_dev *hdev) | |
| 2532 | +{ | |
| 2533 | + struct btusb_data *data = hci_get_drvdata(hdev); | |
| 2534 | + struct intel_version ver; | |
| 2535 | + struct intel_boot_params params; | |
| 2536 | + u32 boot_param; | |
| 2537 | + char ddcname[64]; | |
| 2538 | + ktime_t calltime, delta, rettime; | |
| 2539 | + unsigned long long duration; | |
| 2540 | + int err; | |
| 2541 | + struct intel_debug_features features; | |
| 2542 | + | |
| 2543 | + BT_DBG("%s", hdev->name); | |
| 2544 | + | |
| 2545 | + /* Set the default boot parameter to 0x0 and it is updated to | |
| 2546 | + * SKU specific boot parameter after reading Intel_Write_Boot_Params | |
| 2547 | + * command while downloading the firmware. | |
| 2548 | + */ | |
| 2549 | + boot_param = 0x00000000; | |
| 2550 | + | |
| 2551 | + calltime = ktime_get(); | |
| 2552 | + | |
| 2553 | + /* Read the Intel version information to determine if the device | |
| 2554 | + * is in bootloader mode or if it already has operational firmware | |
| 2555 | + * loaded. | |
| 2556 | + */ | |
| 2557 | + err = btintel_read_version(hdev, &ver); | |
| 2558 | + if (err) { | |
| 2559 | + bt_dev_err(hdev, "Intel Read version failed (%d)", err); | |
| 2560 | + btintel_reset_to_bootloader(hdev); | |
| 2561 | + return err; | |
| 2562 | + } | |
| 2563 | + | |
| 2564 | + err = btusb_intel_download_firmware(hdev, &ver, ¶ms); | |
| 2565 | + if (err) | |
| 2566 | + return err; | |
| 2567 | + | |
| 2568 | + /* controller is already having an operational firmware */ | |
| 2569 | + if (ver.fw_variant == 0x23) | |
| 2570 | + goto finish; | |
| 2571 | + | |
| 2482 | 2572 | rettime = ktime_get(); |
| 2483 | 2573 | delta = ktime_sub(rettime, calltime); |
| 2484 | 2574 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2485 | 2575 | |
| 2486 | 2576 | bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); |
| 2487 | 2577 | |
| 2488 | −done: | |
| 2489 | − release_firmware(fw); | |
| 2490 | − | |
| 2491 | − if (err < 0) | |
| 2492 | − return err; | |
| 2493 | − | |
| 2494 | 2578 | calltime = ktime_get(); |
| 2495 | 2579 | |
| 2496 | 2580 | set_bit(BTUSB_BOOTING, &data->flags); |
| @@ -2534,13 +2618,28 @@ done: · 37 unmodified lines | ||
| 2534 | 2618 | |
| 2535 | 2619 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2536 | 2620 | |
| 2537 | − /* Once the device is running in operational mode, it needs to apply | |
| 2538 | − * the device configuration (DDC) parameters. | |
| 2539 | − * | |
| 2540 | − * The device can work without DDC parameters, so even if it fails | |
| 2541 | − * to load the file, no need to fail the setup. | |
| 2621 | + err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, ddcname, | |
| 2622 | + sizeof(ddcname), "ddc"); | |
| 2623 | + | |
| 2624 | + if (!err) { | |
| 2625 | + bt_dev_err(hdev, "Unsupported Intel firmware naming"); | |
| 2626 | + } else { | |
| 2627 | + /* Once the device is running in operational mode, it needs to | |
| 2628 | + * apply the device configuration (DDC) parameters. | |
| 2629 | + * | |
| 2630 | + * The device can work without DDC parameters, so even if it | |
| 2631 | + * fails to load the file, no need to fail the setup. | |
| 2632 | + */ | |
| 2633 | + btintel_load_ddc_config(hdev, ddcname); | |
| 2634 | + } | |
| 2635 | + | |
| 2636 | + /* Read the Intel supported features and if new exception formats | |
| 2637 | + * supported, need to load the additional DDC config to enable. | |
| 2542 | 2638 | */ |
| 2543 | − btintel_load_ddc_config(hdev, fwname); | |
| 2639 | + btintel_read_debug_features(hdev, &features); | |
| 2640 | + | |
| 2641 | + /* Set DDC mask for available debug features */ | |
| 2642 | + btintel_set_debug_features(hdev, &features); | |
| 2544 | 2643 | |
| 2545 | 2644 | /* Read the Intel version information after loading the FW */ |
| 2546 | 2645 | err = btintel_read_version(hdev, &ver); |
| @@ -2925,7 +3024,7 @@ static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 378 unmodified lines | ||
| 2925 | 3024 | const u8 *fw_ptr; |
| 2926 | 3025 | size_t fw_size; |
| 2927 | 3026 | int err, dlen; |
| 2928 | − u8 flag; | |
| 3027 | + u8 flag, param; | |
| 2929 | 3028 | |
| 2930 | 3029 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2931 | 3030 | if (err < 0) { |
| @@ -2933,6 +3032,20 @@ static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 1 unmodified line | ||
| 2933 | 3032 | return err; |
| 2934 | 3033 | } |
| 2935 | 3034 | |
| 3035 | + /* Power on data RAM the firmware relies on. */ | |
| 3036 | + param = 1; | |
| 3037 | + wmt_params.op = BTMTK_WMT_FUNC_CTRL; | |
| 3038 | + wmt_params.flag = 3; | |
| 3039 | + wmt_params.dlen = sizeof(param); | |
| 3040 | + wmt_params.data = ¶m; | |
| 3041 | + wmt_params.status = NULL; | |
| 3042 | + | |
| 3043 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); | |
| 3044 | + if (err < 0) { | |
| 3045 | + bt_dev_err(hdev, "Failed to power on data RAM (%d)", err); | |
| 3046 | + return err; | |
| 3047 | + } | |
| 3048 | + | |
| 2936 | 3049 | fw_ptr = fw->data; |
| 2937 | 3050 | fw_size = fw->size; |
| 2938 | 3051 | |
| @@ -3704,6 +3817,9 @@ static bool btusb_prevent_wake(struct hci_dev *hdev) · 765 unmodified lines | ||
| 3704 | 3817 | { |
| 3705 | 3818 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3706 | 3819 | |
| 3820 | + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) | |
| 3821 | + return true; | |
| 3822 | + | |
| 3707 | 3823 | return !device_may_wakeup(&data->udev->dev); |
| 3708 | 3824 | } |
| 3709 | 3825 | |
| @@ -3941,10 +4057,20 @@ static int btusb_probe(struct usb_interface *intf, · 231 unmodified lines | ||
| 3941 | 4057 | if (id->driver_info & BTUSB_QCA_ROME) { |
| 3942 | 4058 | data->setup_on_usb = btusb_setup_qca; |
| 3943 | 4059 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
| 4060 | + hdev->cmd_timeout = btusb_qca_cmd_timeout; | |
| 3944 | 4061 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
| 3945 | 4062 | btusb_check_needs_reset_resume(intf); |
| 3946 | 4063 | } |
| 3947 | 4064 | |
| 4065 | + if (id->driver_info & BTUSB_AMP) { | |
| 4066 | + /* AMP controllers do not support SCO packets */ | |
| 4067 | + data->isoc = NULL; | |
| 4068 | + } else { | |
| 4069 | + /* Interface orders are hardcoded in the specification */ | |
| 4070 | + data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); | |
| 4071 | + data->isoc_ifnum = ifnum_base + 1; | |
| 4072 | + } | |
| 4073 | + | |
| 3948 | 4074 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && |
| 3949 | 4075 | (id->driver_info & BTUSB_REALTEK)) { |
| 3950 | 4076 | hdev->setup = btrtl_setup_realtek; |
| @@ -3956,19 +4082,10 @@ static int btusb_probe(struct usb_interface *intf, · 5 unmodified lines | ||
| 3956 | 4082 | * (DEVICE_REMOTE_WAKEUP) |
| 3957 | 4083 | */ |
| 3958 | 4084 | set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); |
| 3959 | − | |
| 3960 | − err = usb_autopm_get_interface(intf); | |
| 3961 | − if (err < 0) | |
| 3962 | − goto out_free_dev; | |
| 3963 | − } | |
| 3964 | − | |
| 3965 | − if (id->driver_info & BTUSB_AMP) { | |
| 3966 | − /* AMP controllers do not support SCO packets */ | |
| 3967 | − data->isoc = NULL; | |
| 3968 | − } else { | |
| 3969 | − /* Interface orders are hardcoded in the specification */ | |
| 3970 | − data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); | |
| 3971 | − data->isoc_ifnum = ifnum_base + 1; | |
| 4085 | + if (btusb_find_altsetting(data, 1)) | |
| 4086 | + set_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags); | |
| 4087 | + else | |
| 4088 | + bt_dev_err(hdev, "Device does not support ALT setting 1"); | |
| 3972 | 4089 | } |
| 3973 | 4090 | |
| 3974 | 4091 | if (!reset) |
| @@ -4001,11 +4118,13 @@ static int btusb_probe(struct usb_interface *intf, · 26 unmodified lines | ||
| 4001 | 4118 | if (bcdDevice < 0x117) |
| 4002 | 4119 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
| 4003 | 4120 | |
| 4121 | + /* This must be set first in case we disable it for fakes */ | |
| 4122 | + set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); | |
| 4123 | + | |
| 4004 | 4124 | /* Fake CSR devices with broken commands */ |
| 4005 | − if (bcdDevice <= 0x100 || bcdDevice == 0x134) | |
| 4125 | + if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 && | |
| 4126 | + le16_to_cpu(udev->descriptor.idProduct) == 0x0001) | |
| 4006 | 4127 | hdev->setup = btusb_setup_csr; |
| 4007 | − | |
| 4008 | − set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); | |
| 4009 | 4128 | } |
| 4010 | 4129 | |
| 4011 | 4130 | if (id->driver_info & BTUSB_SNIFFER) { |
| @@ -793,7 +793,7 @@ static int h5_serdev_probe(struct serdev_device *serdev) · 792 unmodified lines | ||
| 793 | 793 | if (!h5) |
| 794 | 794 | return -ENOMEM; |
| 795 | 795 | |
| 796 | − set_bit(HCI_UART_RESET_ON_INIT, &h5->serdev_hu.flags); | |
| 796 | + set_bit(HCI_UART_RESET_ON_INIT, &h5->serdev_hu.hdev_flags); | |
| 797 | 797 | |
| 798 | 798 | h5->hu = &h5->serdev_hu; |
| 799 | 799 | h5->serdev_hu.serdev = serdev; |
| @@ -219,7 +219,7 @@ static void ll_device_want_to_wakeup(struct hci_uart *hu) · 218 unmodified lines | ||
| 219 | 219 | * perfectly safe to always send one. |
| 220 | 220 | */ |
| 221 | 221 | BT_DBG("dual wake-up-indication"); |
| 222 | − /* fall through */ | |
| 222 | + fallthrough; | |
| 223 | 223 | case HCILL_ASLEEP: |
| 224 | 224 | /* acknowledge device wake up */ |
| 225 | 225 | if (send_hcill_cmd(HCILL_WAKE_UP_ACK, hu) < 0) { |
| @@ -46,7 +46,7 @@ · 45 unmodified lines | ||
| 46 | 46 | #define HCI_MAX_IBS_SIZE 10 |
| 47 | 47 | |
| 48 | 48 | #define IBS_WAKE_RETRANS_TIMEOUT_MS 100 |
| 49 | −#define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 40 | |
| 49 | +#define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 200 | |
| 50 | 50 | #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000 |
| 51 | 51 | #define CMD_TRANS_TIMEOUT_MS 100 |
| 52 | 52 | #define MEMDUMP_TIMEOUT_MS 8000 |
| @@ -72,7 +72,8 @@ enum qca_flags { · 19 unmodified lines | ||
| 72 | 72 | QCA_DROP_VENDOR_EVENT, |
| 73 | 73 | QCA_SUSPENDING, |
| 74 | 74 | QCA_MEMDUMP_COLLECTION, |
| 75 | − QCA_HW_ERROR_EVENT | |
| 75 | + QCA_HW_ERROR_EVENT, | |
| 76 | + QCA_SSR_TRIGGERED | |
| 76 | 77 | }; |
| 77 | 78 | |
| 78 | 79 | enum qca_capabilities { |
| @@ -289,25 +290,21 @@ static void serial_clock_vote(unsigned long vote, struct hci_uart *hu) · 210 unmodified lines | ||
| 289 | 290 | case HCI_IBS_TX_VOTE_CLOCK_ON: |
| 290 | 291 | qca->tx_vote = true; |
| 291 | 292 | qca->tx_votes_on++; |
| 292 | − new_vote = true; | |
| 293 | 293 | break; |
| 294 | 294 | |
| 295 | 295 | case HCI_IBS_RX_VOTE_CLOCK_ON: |
| 296 | 296 | qca->rx_vote = true; |
| 297 | 297 | qca->rx_votes_on++; |
| 298 | − new_vote = true; | |
| 299 | 298 | break; |
| 300 | 299 | |
| 301 | 300 | case HCI_IBS_TX_VOTE_CLOCK_OFF: |
| 302 | 301 | qca->tx_vote = false; |
| 303 | 302 | qca->tx_votes_off++; |
| 304 | − new_vote = qca->rx_vote | qca->tx_vote; | |
| 305 | 303 | break; |
| 306 | 304 | |
| 307 | 305 | case HCI_IBS_RX_VOTE_CLOCK_OFF: |
| 308 | 306 | qca->rx_vote = false; |
| 309 | 307 | qca->rx_votes_off++; |
| 310 | − new_vote = qca->rx_vote | qca->tx_vote; | |
| 311 | 308 | break; |
| 312 | 309 | |
| 313 | 310 | default: |
| @@ -315,6 +312,8 @@ static void serial_clock_vote(unsigned long vote, struct hci_uart *hu) · 1 unmodified line | ||
| 315 | 312 | return; |
| 316 | 313 | } |
| 317 | 314 | |
| 315 | + new_vote = qca->rx_vote | qca->tx_vote; | |
| 316 | + | |
| 318 | 317 | if (new_vote != old_vote) { |
| 319 | 318 | if (new_vote) |
| 320 | 319 | __serial_clock_on(hu->tty); |
| @@ -474,8 +473,6 @@ static void hci_ibs_tx_idle_timeout(struct timer_list *t) · 153 unmodified lines | ||
| 474 | 473 | |
| 475 | 474 | case HCI_IBS_TX_ASLEEP: |
| 476 | 475 | case HCI_IBS_TX_WAKING: |
| 477 | − /* Fall through */ | |
| 478 | − | |
| 479 | 476 | default: |
| 480 | 477 | BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); |
| 481 | 478 | break; |
| @@ -518,8 +515,6 @@ static void hci_ibs_wake_retrans_timeout(struct timer_list *t) · 36 unmodified lines | ||
| 518 | 515 | |
| 519 | 516 | case HCI_IBS_TX_ASLEEP: |
| 520 | 517 | case HCI_IBS_TX_AWAKE: |
| 521 | − /* Fall through */ | |
| 522 | − | |
| 523 | 518 | default: |
| 524 | 519 | BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); |
| 525 | 520 | break; |
| @@ -837,8 +832,6 @@ static void device_woke_up(struct hci_uart *hu) · 311 unmodified lines | ||
| 837 | 832 | break; |
| 838 | 833 | |
| 839 | 834 | case HCI_IBS_TX_ASLEEP: |
| 840 | − /* Fall through */ | |
| 841 | − | |
| 842 | 835 | default: |
| 843 | 836 | BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d", |
| 844 | 837 | qca->tx_ibs_state); |
| @@ -862,6 +855,13 @@ static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb) · 17 unmodified lines | ||
| 862 | 855 | BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb, |
| 863 | 856 | qca->tx_ibs_state); |
| 864 | 857 | |
| 858 | + if (test_bit(QCA_SSR_TRIGGERED, &qca->flags)) { | |
| 859 | + /* As SSR is in progress, ignore the packets */ | |
| 860 | + bt_dev_dbg(hu->hdev, "SSR is in progress"); | |
| 861 | + kfree_skb(skb); | |
| 862 | + return 0; | |
| 863 | + } | |
| 864 | + | |
| 865 | 865 | /* Prepend skb with frame type */ |
| 866 | 866 | memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); |
| 867 | 867 | |
| @@ -983,8 +983,11 @@ static void qca_controller_memdump(struct work_struct *work) · 115 unmodified lines | ||
| 983 | 983 | while ((skb = skb_dequeue(&qca->rx_memdump_q))) { |
| 984 | 984 | |
| 985 | 985 | mutex_lock(&qca->hci_memdump_lock); |
| 986 | − /* Skip processing the received packets if timeout detected. */ | |
| 987 | − if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT) { | |
| 986 | + /* Skip processing the received packets if timeout detected | |
| 987 | + * or memdump collection completed. | |
| 988 | + */ | |
| 989 | + if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || | |
| 990 | + qca->memdump_state == QCA_MEMDUMP_COLLECTED) { | |
| 988 | 991 | mutex_unlock(&qca->hci_memdump_lock); |
| 989 | 992 | return; |
| 990 | 993 | } |
| @@ -1128,6 +1131,7 @@ static int qca_controller_memdump_event(struct hci_dev *hdev, · 137 unmodified lines | ||
| 1128 | 1131 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1129 | 1132 | struct qca_data *qca = hu->priv; |
| 1130 | 1133 | |
| 1134 | + set_bit(QCA_SSR_TRIGGERED, &qca->flags); | |
| 1131 | 1135 | skb_queue_tail(&qca->rx_memdump_q, skb); |
| 1132 | 1136 | queue_work(qca->workqueue, &qca->ctrl_memdump_evt); |
| 1133 | 1137 | |
| @@ -1485,9 +1489,8 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) · 351 unmodified lines | ||
| 1485 | 1489 | { |
| 1486 | 1490 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1487 | 1491 | struct qca_data *qca = hu->priv; |
| 1488 | − struct qca_memdump_data *qca_memdump = qca->qca_memdump; | |
| 1489 | − char *memdump_buf = NULL; | |
| 1490 | 1492 | |
| 1493 | + set_bit(QCA_SSR_TRIGGERED, &qca->flags); | |
| 1491 | 1494 | set_bit(QCA_HW_ERROR_EVENT, &qca->flags); |
| 1492 | 1495 | bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state); |
| 1493 | 1496 | |
| @@ -1509,19 +1512,23 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) · 15 unmodified lines | ||
| 1509 | 1512 | qca_wait_for_dump_collection(hdev); |
| 1510 | 1513 | } |
| 1511 | 1514 | |
| 1515 | + mutex_lock(&qca->hci_memdump_lock); | |
| 1512 | 1516 | if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) { |
| 1513 | 1517 | bt_dev_err(hu->hdev, "clearing allocated memory due to memdump timeout"); |
| 1514 | − mutex_lock(&qca->hci_memdump_lock); | |
| 1515 | − if (qca_memdump) | |
| 1516 | − memdump_buf = qca_memdump->memdump_buf_head; | |
| 1517 | − vfree(memdump_buf); | |
| 1518 | − kfree(qca_memdump); | |
| 1519 | − qca->qca_memdump = NULL; | |
| 1518 | + if (qca->qca_memdump) { | |
| 1519 | + vfree(qca->qca_memdump->memdump_buf_head); | |
| 1520 | + kfree(qca->qca_memdump); | |
| 1521 | + qca->qca_memdump = NULL; | |
| 1522 | + } | |
| 1520 | 1523 | qca->memdump_state = QCA_MEMDUMP_TIMEOUT; |
| 1521 | 1524 | cancel_delayed_work(&qca->ctrl_memdump_timeout); |
| 1522 | − skb_queue_purge(&qca->rx_memdump_q); | |
| 1523 | − mutex_unlock(&qca->hci_memdump_lock); | |
| 1525 | + } | |
| 1526 | + mutex_unlock(&qca->hci_memdump_lock); | |
| 1527 | + | |
| 1528 | + if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || | |
| 1529 | + qca->memdump_state == QCA_MEMDUMP_COLLECTED) { | |
| 1524 | 1530 | cancel_work_sync(&qca->ctrl_memdump_evt); |
| 1531 | + skb_queue_purge(&qca->rx_memdump_q); | |
| 1525 | 1532 | } |
| 1526 | 1533 | |
| 1527 | 1534 | clear_bit(QCA_HW_ERROR_EVENT, &qca->flags); |
| @@ -1532,10 +1539,30 @@ static void qca_cmd_timeout(struct hci_dev *hdev) · 4 unmodified lines | ||
| 1532 | 1539 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1533 | 1540 | struct qca_data *qca = hu->priv; |
| 1534 | 1541 | |
| 1535 | − if (qca->memdump_state == QCA_MEMDUMP_IDLE) | |
| 1542 | + set_bit(QCA_SSR_TRIGGERED, &qca->flags); | |
| 1543 | + if (qca->memdump_state == QCA_MEMDUMP_IDLE) { | |
| 1544 | + set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); | |
| 1536 | 1545 | qca_send_crashbuffer(hu); |
| 1537 | − else | |
| 1538 | − bt_dev_info(hdev, "Dump collection is in process"); | |
| 1546 | + qca_wait_for_dump_collection(hdev); | |
| 1547 | + } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) { | |
| 1548 | + /* Let us wait here until memory dump collected or | |
| 1549 | + * memory dump timer expired. | |
| 1550 | + */ | |
| 1551 | + bt_dev_info(hdev, "waiting for dump to complete"); | |
| 1552 | + qca_wait_for_dump_collection(hdev); | |
| 1553 | + } | |
| 1554 | + | |
| 1555 | + mutex_lock(&qca->hci_memdump_lock); | |
| 1556 | + if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) { | |
| 1557 | + qca->memdump_state = QCA_MEMDUMP_TIMEOUT; | |
| 1558 | + if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) { | |
| 1559 | + /* Inject hw error event to reset the device | |
| 1560 | + * and driver. | |
| 1561 | + */ | |
| 1562 | + hci_reset_dev(hu->hdev); | |
| 1563 | + } | |
| 1564 | + } | |
| 1565 | + mutex_unlock(&qca->hci_memdump_lock); | |
| 1539 | 1566 | } |
| 1540 | 1567 | |
| 1541 | 1568 | static int qca_wcn3990_init(struct hci_uart *hu) |
| @@ -1641,11 +1668,15 @@ static int qca_setup(struct hci_uart *hu) · 99 unmodified lines | ||
| 1641 | 1668 | bt_dev_info(hdev, "setting up %s", |
| 1642 | 1669 | qca_is_wcn399x(soc_type) ? "wcn399x" : "ROME/QCA6390"); |
| 1643 | 1670 | |
| 1671 | + qca->memdump_state = QCA_MEMDUMP_IDLE; | |
| 1672 | + | |
| 1644 | 1673 | retry: |
| 1645 | 1674 | ret = qca_power_on(hdev); |
| 1646 | 1675 | if (ret) |
| 1647 | 1676 | return ret; |
| 1648 | 1677 | |
| 1678 | + clear_bit(QCA_SSR_TRIGGERED, &qca->flags); | |
| 1679 | + | |
| 1649 | 1680 | if (qca_is_wcn399x(soc_type)) { |
| 1650 | 1681 | set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); |
| 1651 | 1682 | |
| @@ -1788,9 +1819,6 @@ static void qca_power_shutdown(struct hci_uart *hu) · 136 unmodified lines | ||
| 1788 | 1819 | qca_flush(hu); |
| 1789 | 1820 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 1790 | 1821 | |
| 1791 | − hu->hdev->hw_error = NULL; | |
| 1792 | − hu->hdev->cmd_timeout = NULL; | |
| 1793 | − | |
| 1794 | 1822 | /* Non-serdev device usually is powered by external power |
| 1795 | 1823 | * and don't need additional action in driver for power down |
| 1796 | 1824 | */ |
| @@ -1812,6 +1840,9 @@ static int qca_power_off(struct hci_dev *hdev) · 15 unmodified lines | ||
| 1812 | 1840 | struct qca_data *qca = hu->priv; |
| 1813 | 1841 | enum qca_btsoc_type soc_type = qca_soc_type(hu); |
| 1814 | 1842 | |
| 1843 | + hu->hdev->hw_error = NULL; | |
| 1844 | + hu->hdev->cmd_timeout = NULL; | |
| 1845 | + | |
| 1815 | 1846 | /* Stop sending shutdown command if soc crashes. */ |
| 1816 | 1847 | if (soc_type != QCA_ROME |
| 1817 | 1848 | && qca->memdump_state == QCA_MEMDUMP_IDLE) { |
| @@ -1819,7 +1850,6 @@ static int qca_power_off(struct hci_dev *hdev) · 1 unmodified line | ||
| 1819 | 1850 | usleep_range(8000, 10000); |
| 1820 | 1851 | } |
| 1821 | 1852 | |
| 1822 | − qca->memdump_state = QCA_MEMDUMP_IDLE; | |
| 1823 | 1853 | qca_power_shutdown(hu); |
| 1824 | 1854 | return 0; |
| 1825 | 1855 | } |
| @@ -1962,17 +1992,17 @@ static int qca_serdev_probe(struct serdev_device *serdev) · 136 unmodified lines | ||
| 1962 | 1992 | } |
| 1963 | 1993 | |
| 1964 | 1994 | qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL); |
| 1965 | − if (!qcadev->susclk) { | |
| 1995 | + if (IS_ERR(qcadev->susclk)) { | |
| 1966 | 1996 | dev_warn(&serdev->dev, "failed to acquire clk\n"); |
| 1967 | − } else { | |
| 1968 | − err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ); | |
| 1969 | − if (err) | |
| 1970 | − return err; | |
| 1971 | − | |
| 1972 | − err = clk_prepare_enable(qcadev->susclk); | |
| 1973 | − if (err) | |
| 1974 | − return err; | |
| 1997 | + return PTR_ERR(qcadev->susclk); | |
| 1975 | 1998 | } |
| 1999 | + err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ); | |
| 2000 | + if (err) | |
| 2001 | + return err; | |
| 2002 | + | |
| 2003 | + err = clk_prepare_enable(qcadev->susclk); | |
| 2004 | + if (err) | |
| 2005 | + return err; | |
| 1976 | 2006 | |
| 1977 | 2007 | err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); |
| 1978 | 2008 | if (err) { |
| @@ -2050,6 +2080,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 71 unmodified lines | ||
| 2050 | 2080 | struct hci_uart *hu = &qcadev->serdev_hu; |
| 2051 | 2081 | struct qca_data *qca = hu->priv; |
| 2052 | 2082 | unsigned long flags; |
| 2083 | + bool tx_pending = false; | |
| 2053 | 2084 | int ret = 0; |
| 2054 | 2085 | u8 cmd; |
| 2055 | 2086 | |
| @@ -2068,7 +2099,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 12 unmodified lines | ||
| 2068 | 2099 | switch (qca->tx_ibs_state) { |
| 2069 | 2100 | case HCI_IBS_TX_WAKING: |
| 2070 | 2101 | del_timer(&qca->wake_retrans_timer); |
| 2071 | − /* Fall through */ | |
| 2102 | + fallthrough; | |
| 2072 | 2103 | case HCI_IBS_TX_AWAKE: |
| 2073 | 2104 | del_timer(&qca->tx_idle_timer); |
| 2074 | 2105 | |
| @@ -2083,8 +2114,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 8 unmodified lines | ||
| 2083 | 2114 | |
| 2084 | 2115 | qca->tx_ibs_state = HCI_IBS_TX_ASLEEP; |
| 2085 | 2116 | qca->ibs_sent_slps++; |
| 2086 | − | |
| 2087 | − qca_wq_serial_tx_clock_vote_off(&qca->ws_tx_vote_off); | |
| 2117 | + tx_pending = true; | |
| 2088 | 2118 | break; |
| 2089 | 2119 | |
| 2090 | 2120 | case HCI_IBS_TX_ASLEEP: |
| @@ -2101,22 +2131,24 @@ static int __maybe_unused qca_suspend(struct device *dev) · 10 unmodified lines | ||
| 2101 | 2131 | if (ret < 0) |
| 2102 | 2132 | goto error; |
| 2103 | 2133 | |
| 2104 | − serdev_device_wait_until_sent(hu->serdev, | |
| 2105 | − msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); | |
| 2134 | + if (tx_pending) { | |
| 2135 | + serdev_device_wait_until_sent(hu->serdev, | |
| 2136 | + msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); | |
| 2137 | + serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu); | |
| 2138 | + } | |
| 2106 | 2139 | |
| 2107 | 2140 | /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going |
| 2108 | 2141 | * to sleep, so that the packet does not wake the system later. |
| 2109 | 2142 | */ |
| 2110 | − | |
| 2111 | 2143 | ret = wait_event_interruptible_timeout(qca->suspend_wait_q, |
| 2112 | 2144 | qca->rx_ibs_state == HCI_IBS_RX_ASLEEP, |
| 2113 | 2145 | msecs_to_jiffies(IBS_BTSOC_TX_IDLE_TIMEOUT_MS)); |
| 2114 | − | |
| 2115 | − if (ret > 0) | |
| 2116 | − return 0; | |
| 2117 | − | |
| 2118 | − if (ret == 0) | |
| 2146 | + if (ret == 0) { | |
| 2119 | 2147 | ret = -ETIMEDOUT; |
| 2148 | + goto error; | |
| 2149 | + } | |
| 2150 | + | |
| 2151 | + return 0; | |
| 2120 | 2152 | |
| 2121 | 2153 | error: |
| 2122 | 2154 | clear_bit(QCA_SUSPENDING, &qca->flags); |
| @@ -355,7 +355,8 @@ void hci_uart_unregister_device(struct hci_uart *hu) · 354 unmodified lines | ||
| 355 | 355 | struct hci_dev *hdev = hu->hdev; |
| 356 | 356 | |
| 357 | 357 | clear_bit(HCI_UART_PROTO_READY, &hu->flags); |
| 358 | − hci_unregister_dev(hdev); | |
| 358 | + if (test_bit(HCI_UART_REGISTERED, &hu->flags)) | |
| 359 | + hci_unregister_dev(hdev); | |
| 359 | 360 | hci_free_dev(hdev); |
| 360 | 361 | |
| 361 | 362 | cancel_work_sync(&hu->write_work); |
| @@ -36,9 +36,9 @@ · 35 unmodified lines | ||
| 36 | 36 | #define SD8897_DEFAULT_FW_NAME "mrvl/sd8897_uapsta.bin" |
| 37 | 37 | #define SD8887_DEFAULT_FW_NAME "mrvl/sd8887_uapsta.bin" |
| 38 | 38 | #define SD8801_DEFAULT_FW_NAME "mrvl/sd8801_uapsta.bin" |
| 39 | −#define SD8977_DEFAULT_FW_NAME "mrvl/sd8977_uapsta.bin" | |
| 39 | +#define SD8977_DEFAULT_FW_NAME "mrvl/sdsd8977_combo_v2.bin" | |
| 40 | 40 | #define SD8987_DEFAULT_FW_NAME "mrvl/sd8987_uapsta.bin" |
| 41 | −#define SD8997_DEFAULT_FW_NAME "mrvl/sd8997_uapsta.bin" | |
| 41 | +#define SD8997_DEFAULT_FW_NAME "mrvl/sdsd8997_combo_v4.bin" | |
| 42 | 42 | |
| 43 | 43 | #define BLOCK_MODE 1 |
| 44 | 44 | #define BYTE_MODE 0 |
| @@ -41,6 +41,8 @@ · 40 unmodified lines | ||
| 41 | 41 | #define BLUETOOTH_VER_1_1 1 |
| 42 | 42 | #define BLUETOOTH_VER_1_2 2 |
| 43 | 43 | #define BLUETOOTH_VER_2_0 3 |
| 44 | +#define BLUETOOTH_VER_2_1 4 | |
| 45 | +#define BLUETOOTH_VER_4_0 6 | |
| 44 | 46 | |
| 45 | 47 | /* Reserv for core and drivers use */ |
| 46 | 48 | #define BT_SKB_RESERVE 8 |
| @@ -147,6 +149,10 @@ struct bt_voice { · 100 unmodified lines | ||
| 147 | 149 | #define BT_MODE_LE_FLOWCTL 0x03 |
| 148 | 150 | #define BT_MODE_EXT_FLOWCTL 0x04 |
| 149 | 151 | |
| 152 | +#define BT_PKT_STATUS 16 | |
| 153 | + | |
| 154 | +#define BT_SCM_PKT_STATUS 0x03 | |
| 155 | + | |
| 150 | 156 | __printf(1, 2) |
| 151 | 157 | void bt_info(const char *fmt, ...); |
| 152 | 158 | __printf(1, 2) |
| @@ -286,6 +292,7 @@ struct bt_sock { · 133 unmodified lines | ||
| 286 | 292 | struct sock *parent; |
| 287 | 293 | unsigned long flags; |
| 288 | 294 | void (*skb_msg_name)(struct sk_buff *, void *, int *); |
| 295 | + void (*skb_put_cmsg)(struct sk_buff *, struct msghdr *, struct sock *); | |
| 289 | 296 | }; |
| 290 | 297 | |
| 291 | 298 | enum { |
| @@ -335,6 +342,10 @@ struct l2cap_ctrl { · 43 unmodified lines | ||
| 335 | 342 | struct l2cap_chan *chan; |
| 336 | 343 | }; |
| 337 | 344 | |
| 345 | +struct sco_ctrl { | |
| 346 | + u8 pkt_status; | |
| 347 | +}; | |
| 348 | + | |
| 338 | 349 | struct hci_dev; |
| 339 | 350 | |
| 340 | 351 | typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode); |
| @@ -361,6 +372,7 @@ struct bt_skb_cb { · 20 unmodified lines | ||
| 361 | 372 | u8 incoming:1; |
| 362 | 373 | union { |
| 363 | 374 | struct l2cap_ctrl l2cap; |
| 375 | + struct sco_ctrl sco; | |
| 364 | 376 | struct hci_ctrl hci; |
| 365 | 377 | }; |
| 366 | 378 | }; |
| @@ -227,6 +227,17 @@ enum { · 226 unmodified lines | ||
| 227 | 227 | * supported. |
| 228 | 228 | */ |
| 229 | 229 | HCI_QUIRK_VALID_LE_STATES, |
| 230 | + | |
| 231 | + /* When this quirk is set, then erroneous data reporting | |
| 232 | + * is ignored. This is mainly due to the fact that the HCI | |
| 233 | + * Read Default Erroneous Data Reporting command is advertised, | |
| 234 | + * but not supported; these controllers often reply with unknown | |
| 235 | + * command and tend to lock up randomly. Needing a hard reset. | |
| 236 | + * | |
| 237 | + * This quirk can be set before hci_register_dev is called or | |
| 238 | + * during the hdev->setup vendor callback. | |
| 239 | + */ | |
| 240 | + HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, | |
| 230 | 241 | }; |
| 231 | 242 | |
| 232 | 243 | /* HCI device flags */ |
| @@ -307,6 +318,7 @@ enum { · 74 unmodified lines | ||
| 307 | 318 | HCI_FORCE_BREDR_SMP, |
| 308 | 319 | HCI_FORCE_STATIC_ADDR, |
| 309 | 320 | HCI_LL_RPA_RESOLUTION, |
| 321 | + HCI_ENABLE_LL_PRIVACY, | |
| 310 | 322 | HCI_CMD_PENDING, |
| 311 | 323 | HCI_FORCE_NO_MITM, |
| 312 | 324 | |
| @@ -1637,6 +1649,8 @@ struct hci_rp_le_read_resolv_list_size { · 1324 unmodified lines | ||
| 1637 | 1649 | |
| 1638 | 1650 | #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d |
| 1639 | 1651 | |
| 1652 | +#define HCI_OP_LE_SET_RPA_TIMEOUT 0x202e | |
| 1653 | + | |
| 1640 | 1654 | #define HCI_OP_LE_READ_MAX_DATA_LEN 0x202f |
| 1641 | 1655 | struct hci_rp_le_read_max_data_len { |
| 1642 | 1656 | __u8 status; |
| @@ -2268,8 +2282,10 @@ struct hci_ev_le_conn_complete { · 625 unmodified lines | ||
| 2268 | 2282 | #define LE_EXT_ADV_SCAN_RSP 0x0008 |
| 2269 | 2283 | #define LE_EXT_ADV_LEGACY_PDU 0x0010 |
| 2270 | 2284 | |
| 2271 | −#define ADDR_LE_DEV_PUBLIC 0x00 | |
| 2272 | −#define ADDR_LE_DEV_RANDOM 0x01 | |
| 2285 | +#define ADDR_LE_DEV_PUBLIC 0x00 | |
| 2286 | +#define ADDR_LE_DEV_RANDOM 0x01 | |
| 2287 | +#define ADDR_LE_DEV_PUBLIC_RESOLVED 0x02 | |
| 2288 | +#define ADDR_LE_DEV_RANDOM_RESOLVED 0x03 | |
| 2273 | 2289 | |
| 2274 | 2290 | #define HCI_EV_LE_ADVERTISING_REPORT 0x02 |
| 2275 | 2291 | struct hci_ev_le_advertising_info { |
| @@ -2516,4 +2532,12 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb) · 240 unmodified lines | ||
| 2516 | 2532 | #define hci_iso_data_len(h) ((h) & 0x3fff) |
| 2517 | 2533 | #define hci_iso_data_flags(h) ((h) >> 14) |
| 2518 | 2534 | |
| 2535 | +/* le24 support */ | |
| 2536 | +static inline void hci_cpu_to_le24(__u32 val, __u8 dst[3]) | |
| 2537 | +{ | |
| 2538 | + dst[0] = val & 0xff; | |
| 2539 | + dst[1] = (val & 0xff00) >> 8; | |
| 2540 | + dst[2] = (val & 0xff0000) >> 16; | |
| 2541 | +} | |
| 2542 | + | |
| 2519 | 2543 | #endif /* __HCI_H */ |
| @@ -25,6 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | #ifndef __HCI_CORE_H |
| 26 | 26 | #define __HCI_CORE_H |
| 27 | 27 | |
| 28 | +#include <linux/idr.h> | |
| 28 | 29 | #include <linux/leds.h> |
| 29 | 30 | #include <linux/rculist.h> |
| 30 | 31 | |
| @@ -136,6 +137,23 @@ struct bdaddr_list_with_irk { · 105 unmodified lines | ||
| 136 | 137 | u8 local_irk[16]; |
| 137 | 138 | }; |
| 138 | 139 | |
| 140 | +struct bdaddr_list_with_flags { | |
| 141 | + struct list_head list; | |
| 142 | + bdaddr_t bdaddr; | |
| 143 | + u8 bdaddr_type; | |
| 144 | + u32 current_flags; | |
| 145 | +}; | |
| 146 | + | |
| 147 | +enum hci_conn_flags { | |
| 148 | + HCI_CONN_FLAG_REMOTE_WAKEUP, | |
| 149 | + HCI_CONN_FLAG_MAX | |
| 150 | +}; | |
| 151 | + | |
| 152 | +#define hci_conn_test_flag(nr, flags) ((flags) & (1U << nr)) | |
| 153 | + | |
| 154 | +/* Make sure number of flags doesn't exceed sizeof(current_flags) */ | |
| 155 | +static_assert(HCI_CONN_FLAG_MAX < 32); | |
| 156 | + | |
| 139 | 157 | struct bt_uuid { |
| 140 | 158 | struct list_head list; |
| 141 | 159 | u8 uuid[16]; |
| @@ -220,6 +238,24 @@ struct adv_info { · 78 unmodified lines | ||
| 220 | 238 | #define HCI_MAX_ADV_INSTANCES 5 |
| 221 | 239 | #define HCI_DEFAULT_ADV_DURATION 2 |
| 222 | 240 | |
| 241 | +struct adv_pattern { | |
| 242 | + struct list_head list; | |
| 243 | + __u8 ad_type; | |
| 244 | + __u8 offset; | |
| 245 | + __u8 length; | |
| 246 | + __u8 value[HCI_MAX_AD_LENGTH]; | |
| 247 | +}; | |
| 248 | + | |
| 249 | +struct adv_monitor { | |
| 250 | + struct list_head patterns; | |
| 251 | + bool active; | |
| 252 | + __u16 handle; | |
| 253 | +}; | |
| 254 | + | |
| 255 | +#define HCI_MIN_ADV_MONITOR_HANDLE 1 | |
| 256 | +#define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32 | |
| 257 | +#define HCI_MAX_ADV_MONITOR_NUM_PATTERNS 16 | |
| 258 | + | |
| 223 | 259 | #define HCI_MAX_SHORT_NAME_LENGTH 10 |
| 224 | 260 | |
| 225 | 261 | /* Min encryption key size to match with SMP */ |
| @@ -295,6 +331,14 @@ struct hci_dev { · 69 unmodified lines | ||
| 295 | 331 | __u8 le_scan_type; |
| 296 | 332 | __u16 le_scan_interval; |
| 297 | 333 | __u16 le_scan_window; |
| 334 | + __u16 le_scan_int_suspend; | |
| 335 | + __u16 le_scan_window_suspend; | |
| 336 | + __u16 le_scan_int_discovery; | |
| 337 | + __u16 le_scan_window_discovery; | |
| 338 | + __u16 le_scan_int_adv_monitor; | |
| 339 | + __u16 le_scan_window_adv_monitor; | |
| 340 | + __u16 le_scan_int_connect; | |
| 341 | + __u16 le_scan_window_connect; | |
| 298 | 342 | __u16 le_conn_min_interval; |
| 299 | 343 | __u16 le_conn_max_interval; |
| 300 | 344 | __u16 le_conn_latency; |
| @@ -323,6 +367,17 @@ struct hci_dev { · 22 unmodified lines | ||
| 323 | 367 | __u16 devid_product; |
| 324 | 368 | __u16 devid_version; |
| 325 | 369 | |
| 370 | + __u8 def_page_scan_type; | |
| 371 | + __u16 def_page_scan_int; | |
| 372 | + __u16 def_page_scan_window; | |
| 373 | + __u8 def_inq_scan_type; | |
| 374 | + __u16 def_inq_scan_int; | |
| 375 | + __u16 def_inq_scan_window; | |
| 376 | + __u16 def_br_lsto; | |
| 377 | + __u16 def_page_timeout; | |
| 378 | + __u16 def_multi_adv_rotation_duration; | |
| 379 | + __u16 def_le_autoconnect_timeout; | |
| 380 | + | |
| 326 | 381 | __u16 pkt_type; |
| 327 | 382 | __u16 esco_type; |
| 328 | 383 | __u16 link_policy; |
| @@ -438,7 +493,6 @@ struct hci_dev { · 109 unmodified lines | ||
| 438 | 493 | struct list_head mgmt_pending; |
| 439 | 494 | struct list_head blacklist; |
| 440 | 495 | struct list_head whitelist; |
| 441 | − struct list_head wakeable; | |
| 442 | 496 | struct list_head uuids; |
| 443 | 497 | struct list_head link_keys; |
| 444 | 498 | struct list_head long_term_keys; |
| @@ -477,6 +531,9 @@ struct hci_dev { · 32 unmodified lines | ||
| 477 | 531 | __u16 adv_instance_timeout; |
| 478 | 532 | struct delayed_work adv_instance_expire; |
| 479 | 533 | |
| 534 | + struct idr adv_monitors_idr; | |
| 535 | + unsigned int adv_monitors_cnt; | |
| 536 | + | |
| 480 | 537 | __u8 irk[16]; |
| 481 | 538 | __u32 rpa_timeout; |
| 482 | 539 | struct delayed_work rpa_expired; |
| @@ -508,6 +565,12 @@ struct hci_dev { · 25 unmodified lines | ||
| 508 | 565 | |
| 509 | 566 | #define HCI_PHY_HANDLE(handle) (handle & 0xff) |
| 510 | 567 | |
| 568 | +enum conn_reasons { | |
| 569 | + CONN_REASON_PAIR_DEVICE, | |
| 570 | + CONN_REASON_L2CAP_CHAN, | |
| 571 | + CONN_REASON_SCO_CONNECT, | |
| 572 | +}; | |
| 573 | + | |
| 511 | 574 | struct hci_conn { |
| 512 | 575 | struct list_head list; |
| 513 | 576 | |
| @@ -559,6 +622,8 @@ struct hci_conn { · 45 unmodified lines | ||
| 559 | 622 | __s8 max_tx_power; |
| 560 | 623 | unsigned long flags; |
| 561 | 624 | |
| 625 | + enum conn_reasons conn_reason; | |
| 626 | + | |
| 562 | 627 | __u32 clock; |
| 563 | 628 | __u16 clock_accuracy; |
| 564 | 629 | |
| @@ -626,7 +691,7 @@ struct hci_conn_params { · 61 unmodified lines | ||
| 626 | 691 | |
| 627 | 692 | struct hci_conn *conn; |
| 628 | 693 | bool explicit_connect; |
| 629 | − bool wakeable; | |
| 694 | + u32 current_flags; | |
| 630 | 695 | }; |
| 631 | 696 | |
| 632 | 697 | extern struct list_head hci_dev_list; |
| @@ -984,12 +1049,14 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); · 351 unmodified lines | ||
| 984 | 1049 | |
| 985 | 1050 | struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, |
| 986 | 1051 | u8 dst_type, u8 sec_level, |
| 987 | − u16 conn_timeout); | |
| 1052 | + u16 conn_timeout, | |
| 1053 | + enum conn_reasons conn_reason); | |
| 988 | 1054 | struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, |
| 989 | 1055 | u8 dst_type, u8 sec_level, u16 conn_timeout, |
| 990 | 1056 | u8 role, bdaddr_t *direct_rpa); |
| 991 | 1057 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, |
| 992 | − u8 sec_level, u8 auth_type); | |
| 1058 | + u8 sec_level, u8 auth_type, | |
| 1059 | + enum conn_reasons conn_reason); | |
| 993 | 1060 | struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, |
| 994 | 1061 | __u16 setting); |
| 995 | 1062 | int hci_conn_check_link_mode(struct hci_conn *conn); |
| @@ -1151,12 +1218,19 @@ struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list, · 155 unmodified lines | ||
| 1151 | 1218 | struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( |
| 1152 | 1219 | struct list_head *list, bdaddr_t *bdaddr, |
| 1153 | 1220 | u8 type); |
| 1221 | +struct bdaddr_list_with_flags * | |
| 1222 | +hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr, | |
| 1223 | + u8 type); | |
| 1154 | 1224 | int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type); |
| 1155 | 1225 | int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr, |
| 1156 | − u8 type, u8 *peer_irk, u8 *local_irk); | |
| 1226 | + u8 type, u8 *peer_irk, u8 *local_irk); | |
| 1227 | +int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr, | |
| 1228 | + u8 type, u32 flags); | |
| 1157 | 1229 | int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type); |
| 1158 | 1230 | int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, |
| 1159 | − u8 type); | |
| 1231 | + u8 type); | |
| 1232 | +int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr, | |
| 1233 | + u8 type); | |
| 1160 | 1234 | void hci_bdaddr_list_clear(struct list_head *list); |
| 1161 | 1235 | |
| 1162 | 1236 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, |
| @@ -1217,6 +1291,12 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 54 unmodified lines | ||
| 1217 | 1291 | int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); |
| 1218 | 1292 | void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); |
| 1219 | 1293 | |
| 1294 | +void hci_adv_monitors_clear(struct hci_dev *hdev); | |
| 1295 | +void hci_free_adv_monitor(struct adv_monitor *monitor); | |
| 1296 | +int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor); | |
| 1297 | +int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle); | |
| 1298 | +bool hci_is_adv_monitoring(struct hci_dev *hdev); | |
| 1299 | + | |
| 1220 | 1300 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); |
| 1221 | 1301 | |
| 1222 | 1302 | void hci_init_sysfs(struct hci_dev *hdev); |
| @@ -1279,6 +1359,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn); · 56 unmodified lines | ||
| 1279 | 1359 | #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ |
| 1280 | 1360 | ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) |
| 1281 | 1361 | |
| 1362 | +/* Use LL Privacy based address resolution if supported */ | |
| 1363 | +#define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY) | |
| 1364 | + | |
| 1282 | 1365 | /* Use ext scanning if set ext scan param and ext scan enable is supported */ |
| 1283 | 1366 | #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \ |
| 1284 | 1367 | ((dev)->commands[37] & 0x40)) |
| @@ -1387,7 +1470,7 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 102 unmodified lines | ||
| 1387 | 1470 | __u8 encrypt; |
| 1388 | 1471 | |
| 1389 | 1472 | if (conn->state == BT_CONFIG) { |
| 1390 | − if (status) | |
| 1473 | + if (!status) | |
| 1391 | 1474 | conn->state = BT_CONNECTED; |
| 1392 | 1475 | |
| 1393 | 1476 | hci_connect_cfm(conn, status); |
| @@ -1402,11 +1485,13 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 8 unmodified lines | ||
| 1402 | 1485 | else |
| 1403 | 1486 | encrypt = 0x01; |
| 1404 | 1487 | |
| 1405 | − if (conn->sec_level == BT_SECURITY_SDP) | |
| 1406 | − conn->sec_level = BT_SECURITY_LOW; | |
| 1488 | + if (!status) { | |
| 1489 | + if (conn->sec_level == BT_SECURITY_SDP) | |
| 1490 | + conn->sec_level = BT_SECURITY_LOW; | |
| 1407 | 1491 | |
| 1408 | − if (conn->pending_sec_level > conn->sec_level) | |
| 1409 | − conn->sec_level = conn->pending_sec_level; | |
| 1492 | + if (conn->pending_sec_level > conn->sec_level) | |
| 1493 | + conn->sec_level = conn->pending_sec_level; | |
| 1494 | + } | |
| 1410 | 1495 | |
| 1411 | 1496 | mutex_lock(&hci_cb_list_lock); |
| 1412 | 1497 | list_for_each_entry(cb, &hci_cb_list, list) { |
| @@ -31,8 +31,8 @@ · 30 unmodified lines | ||
| 31 | 31 | #define HCI_TIME_STAMP 3 |
| 32 | 32 | |
| 33 | 33 | /* CMSG flags */ |
| 34 | −#define HCI_CMSG_DIR 0x0001 | |
| 35 | −#define HCI_CMSG_TSTAMP 0x0002 | |
| 34 | +#define HCI_CMSG_DIR 0x01 | |
| 35 | +#define HCI_CMSG_TSTAMP 0x02 | |
| 36 | 36 | |
| 37 | 37 | struct sockaddr_hci { |
| 38 | 38 | sa_family_t hci_family; |
| @@ -52,6 +52,12 @@ struct mgmt_hdr { · 51 unmodified lines | ||
| 52 | 52 | __le16 len; |
| 53 | 53 | } __packed; |
| 54 | 54 | |
| 55 | +struct mgmt_tlv { | |
| 56 | + __le16 type; | |
| 57 | + __u8 length; | |
| 58 | + __u8 value[]; | |
| 59 | +} __packed; | |
| 60 | + | |
| 55 | 61 | struct mgmt_addr_info { |
| 56 | 62 | bdaddr_t bdaddr; |
| 57 | 63 | __u8 type; |
| @@ -702,6 +708,78 @@ struct mgmt_rp_set_exp_feature { · 644 unmodified lines | ||
| 702 | 708 | __le32 flags; |
| 703 | 709 | } __packed; |
| 704 | 710 | |
| 711 | +#define MGMT_OP_READ_DEF_SYSTEM_CONFIG 0x004b | |
| 712 | +#define MGMT_READ_DEF_SYSTEM_CONFIG_SIZE 0 | |
| 713 | + | |
| 714 | +#define MGMT_OP_SET_DEF_SYSTEM_CONFIG 0x004c | |
| 715 | +#define MGMT_SET_DEF_SYSTEM_CONFIG_SIZE 0 | |
| 716 | + | |
| 717 | +#define MGMT_OP_READ_DEF_RUNTIME_CONFIG 0x004d | |
| 718 | +#define MGMT_READ_DEF_RUNTIME_CONFIG_SIZE 0 | |
| 719 | + | |
| 720 | +#define MGMT_OP_SET_DEF_RUNTIME_CONFIG 0x004e | |
| 721 | +#define MGMT_SET_DEF_RUNTIME_CONFIG_SIZE 0 | |
| 722 | + | |
| 723 | +#define MGMT_OP_GET_DEVICE_FLAGS 0x004F | |
| 724 | +#define MGMT_GET_DEVICE_FLAGS_SIZE 7 | |
| 725 | +struct mgmt_cp_get_device_flags { | |
| 726 | + struct mgmt_addr_info addr; | |
| 727 | +} __packed; | |
| 728 | +struct mgmt_rp_get_device_flags { | |
| 729 | + struct mgmt_addr_info addr; | |
| 730 | + __le32 supported_flags; | |
| 731 | + __le32 current_flags; | |
| 732 | +} __packed; | |
| 733 | + | |
| 734 | +#define MGMT_OP_SET_DEVICE_FLAGS 0x0050 | |
| 735 | +#define MGMT_SET_DEVICE_FLAGS_SIZE 11 | |
| 736 | +struct mgmt_cp_set_device_flags { | |
| 737 | + struct mgmt_addr_info addr; | |
| 738 | + __le32 current_flags; | |
| 739 | +} __packed; | |
| 740 | +struct mgmt_rp_set_device_flags { | |
| 741 | + struct mgmt_addr_info addr; | |
| 742 | +} __packed; | |
| 743 | + | |
| 744 | +#define MGMT_ADV_MONITOR_FEATURE_MASK_OR_PATTERNS BIT(0) | |
| 745 | + | |
| 746 | +#define MGMT_OP_READ_ADV_MONITOR_FEATURES 0x0051 | |
| 747 | +#define MGMT_READ_ADV_MONITOR_FEATURES_SIZE 0 | |
| 748 | +struct mgmt_rp_read_adv_monitor_features { | |
| 749 | + __le32 supported_features; | |
| 750 | + __le32 enabled_features; | |
| 751 | + __le16 max_num_handles; | |
| 752 | + __u8 max_num_patterns; | |
| 753 | + __le16 num_handles; | |
| 754 | + __le16 handles[]; | |
| 755 | +} __packed; | |
| 756 | + | |
| 757 | +struct mgmt_adv_pattern { | |
| 758 | + __u8 ad_type; | |
| 759 | + __u8 offset; | |
| 760 | + __u8 length; | |
| 761 | + __u8 value[31]; | |
| 762 | +} __packed; | |
| 763 | + | |
| 764 | +#define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052 | |
| 765 | +struct mgmt_cp_add_adv_patterns_monitor { | |
| 766 | + __u8 pattern_count; | |
| 767 | + struct mgmt_adv_pattern patterns[]; | |
| 768 | +} __packed; | |
| 769 | +#define MGMT_ADD_ADV_PATTERNS_MONITOR_SIZE 1 | |
| 770 | +struct mgmt_rp_add_adv_patterns_monitor { | |
| 771 | + __le16 monitor_handle; | |
| 772 | +} __packed; | |
| 773 | + | |
| 774 | +#define MGMT_OP_REMOVE_ADV_MONITOR 0x0053 | |
| 775 | +struct mgmt_cp_remove_adv_monitor { | |
| 776 | + __le16 monitor_handle; | |
| 777 | +} __packed; | |
| 778 | +#define MGMT_REMOVE_ADV_MONITOR_SIZE 2 | |
| 779 | +struct mgmt_rp_remove_adv_monitor { | |
| 780 | + __le16 monitor_handle; | |
| 781 | +} __packed; | |
| 782 | + | |
| 705 | 783 | #define MGMT_EV_CMD_COMPLETE 0x0001 |
| 706 | 784 | struct mgmt_ev_cmd_complete { |
| 707 | 785 | __le16 opcode; |
| @@ -933,3 +1011,20 @@ struct mgmt_ev_exp_feature_changed { · 225 unmodified lines | ||
| 933 | 1011 | __u8 uuid[16]; |
| 934 | 1012 | __le32 flags; |
| 935 | 1013 | } __packed; |
| 1014 | + | |
| 1015 | +#define MGMT_EV_DEVICE_FLAGS_CHANGED 0x002a | |
| 1016 | +struct mgmt_ev_device_flags_changed { | |
| 1017 | + struct mgmt_addr_info addr; | |
| 1018 | + __le32 supported_flags; | |
| 1019 | + __le32 current_flags; | |
| 1020 | +} __packed; | |
| 1021 | + | |
| 1022 | +#define MGMT_EV_ADV_MONITOR_ADDED 0x002b | |
| 1023 | +struct mgmt_ev_adv_monitor_added { | |
| 1024 | + __le16 monitor_handle; | |
| 1025 | +} __packed; | |
| 1026 | + | |
| 1027 | +#define MGMT_EV_ADV_MONITOR_REMOVED 0x002c | |
| 1028 | +struct mgmt_ev_adv_monitor_removed { | |
| 1029 | + __le16 monitor_handle; | |
| 1030 | +} __packed; | |
| @@ -46,4 +46,6 @@ struct sco_conninfo { · 45 unmodified lines | ||
| 46 | 46 | __u8 dev_class[3]; |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | +#define SCO_CMSG_PKT_STATUS 0x01 | |
| 50 | + | |
| 49 | 51 | #endif /* __SCO_H */ |
| @@ -50,6 +50,7 @@ static bool enable_6lowpan; · 49 unmodified lines | ||
| 50 | 50 | /* We are listening incoming connections via this channel |
| 51 | 51 | */ |
| 52 | 52 | static struct l2cap_chan *listen_chan; |
| 53 | +static DEFINE_MUTEX(set_lock); | |
| 53 | 54 | |
| 54 | 55 | struct lowpan_peer { |
| 55 | 56 | struct list_head list; |
| @@ -1078,12 +1079,14 @@ static void do_enable_set(struct work_struct *work) · 1022 unmodified lines | ||
| 1078 | 1079 | |
| 1079 | 1080 | enable_6lowpan = set_enable->flag; |
| 1080 | 1081 | |
| 1082 | + mutex_lock(&set_lock); | |
| 1081 | 1083 | if (listen_chan) { |
| 1082 | 1084 | l2cap_chan_close(listen_chan, 0); |
| 1083 | 1085 | l2cap_chan_put(listen_chan); |
| 1084 | 1086 | } |
| 1085 | 1087 | |
| 1086 | 1088 | listen_chan = bt_6lowpan_listen(); |
| 1089 | + mutex_unlock(&set_lock); | |
| 1087 | 1090 | |
| 1088 | 1091 | kfree(set_enable); |
| 1089 | 1092 | } |
| @@ -1135,11 +1138,13 @@ static ssize_t lowpan_control_write(struct file *fp, · 45 unmodified lines | ||
| 1135 | 1138 | if (ret == -EINVAL) |
| 1136 | 1139 | return ret; |
| 1137 | 1140 | |
| 1141 | + mutex_lock(&set_lock); | |
| 1138 | 1142 | if (listen_chan) { |
| 1139 | 1143 | l2cap_chan_close(listen_chan, 0); |
| 1140 | 1144 | l2cap_chan_put(listen_chan); |
| 1141 | 1145 | listen_chan = NULL; |
| 1142 | 1146 | } |
| 1147 | + mutex_unlock(&set_lock); | |
| 1143 | 1148 | |
| 1144 | 1149 | if (conn) { |
| 1145 | 1150 | struct lowpan_peer *peer; |
| @@ -21,7 +21,7 @@ menuconfig BT · 20 unmodified lines | ||
| 21 | 21 | It was designed as a replacement for cables and other short-range |
| 22 | 22 | technologies like IrDA. Bluetooth operates in personal area range |
| 23 | 23 | that typically extends up to 10 meters. More information about |
| 24 | − Bluetooth can be found at <http://www.bluetooth.com/>. | |
| 24 | + Bluetooth can be found at <https://www.bluetooth.com/>. | |
| 25 | 25 | |
| 26 | 26 | Linux Bluetooth subsystem consist of several layers: |
| 27 | 27 | Bluetooth Core |
| @@ -14,7 +14,7 @@ bluetooth_6lowpan-y := 6lowpan.o · 13 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ |
| 16 | 16 | hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o lib.o \ |
| 17 | − ecdh_helper.o hci_request.o mgmt_util.o | |
| 17 | + ecdh_helper.o hci_request.o mgmt_util.o mgmt_config.o | |
| 18 | 18 | |
| 19 | 19 | bluetooth-$(CONFIG_BT_BREDR) += sco.o |
| 20 | 20 | bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o |
| @@ -286,6 +286,9 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, · 285 unmodified lines | ||
| 286 | 286 | if (msg->msg_name && bt_sk(sk)->skb_msg_name) |
| 287 | 287 | bt_sk(sk)->skb_msg_name(skb, msg->msg_name, |
| 288 | 288 | &msg->msg_namelen); |
| 289 | + | |
| 290 | + if (bt_sk(sk)->skb_put_cmsg) | |
| 291 | + bt_sk(sk)->skb_put_cmsg(skb, msg, sk); | |
| 289 | 292 | } |
| 290 | 293 | |
| 291 | 294 | skb_free_datagram(sk, skb); |
| @@ -453,8 +456,6 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock, · 161 unmodified lines | ||
| 453 | 456 | struct sock *sk = sock->sk; |
| 454 | 457 | __poll_t mask = 0; |
| 455 | 458 | |
| 456 | − BT_DBG("sock %p, sk %p", sock, sk); | |
| 457 | − | |
| 458 | 459 | poll_wait(file, sk_sleep(sk), wait); |
| 459 | 460 | |
| 460 | 461 | if (sk->sk_state == BT_LISTEN) |
| @@ -789,11 +789,8 @@ static void set_ext_conn_params(struct hci_conn *conn, · 788 unmodified lines | ||
| 789 | 789 | |
| 790 | 790 | memset(p, 0, sizeof(*p)); |
| 791 | 791 | |
| 792 | − /* Set window to be the same value as the interval to | |
| 793 | − * enable continuous scanning. | |
| 794 | − */ | |
| 795 | − p->scan_interval = cpu_to_le16(hdev->le_scan_interval); | |
| 796 | − p->scan_window = p->scan_interval; | |
| 792 | + p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); | |
| 793 | + p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); | |
| 797 | 794 | p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); |
| 798 | 795 | p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); |
| 799 | 796 | p->conn_latency = cpu_to_le16(conn->le_conn_latency); |
| @@ -875,11 +872,8 @@ static void hci_req_add_le_create_conn(struct hci_request *req, · 75 unmodified lines | ||
| 875 | 872 | |
| 876 | 873 | memset(&cp, 0, sizeof(cp)); |
| 877 | 874 | |
| 878 | − /* Set window to be the same value as the interval to enable | |
| 879 | − * continuous scanning. | |
| 880 | − */ | |
| 881 | − cp.scan_interval = cpu_to_le16(hdev->le_scan_interval); | |
| 882 | − cp.scan_window = cp.scan_interval; | |
| 875 | + cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); | |
| 876 | + cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); | |
| 883 | 877 | |
| 884 | 878 | bacpy(&cp.peer_addr, &conn->dst); |
| 885 | 879 | cp.peer_addr_type = conn->dst_type; |
| @@ -937,7 +931,7 @@ static void hci_req_directed_advertising(struct hci_request *req, · 51 unmodified lines | ||
| 937 | 931 | * So it is required to remove adv set for handle 0x00. since we use |
| 938 | 932 | * instance 0 for directed adv. |
| 939 | 933 | */ |
| 940 | − hci_req_add(req, HCI_OP_LE_REMOVE_ADV_SET, sizeof(cp.handle), &cp.handle); | |
| 934 | + __hci_req_remove_ext_adv_instance(req, cp.handle); | |
| 941 | 935 | |
| 942 | 936 | hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp); |
| 943 | 937 | |
| @@ -1009,6 +1003,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, · 65 unmodified lines | ||
| 1009 | 1003 | struct hci_request req; |
| 1010 | 1004 | int err; |
| 1011 | 1005 | |
| 1006 | + /* This ensures that during disable le_scan address resolution | |
| 1007 | + * will not be disabled if it is followed by le_create_conn | |
| 1008 | + */ | |
| 1009 | + bool rpa_le_conn = true; | |
| 1010 | + | |
| 1012 | 1011 | /* Let's make sure that le is enabled.*/ |
| 1013 | 1012 | if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { |
| 1014 | 1013 | if (lmp_le_capable(hdev)) |
| @@ -1109,7 +1108,7 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, · 94 unmodified lines | ||
| 1109 | 1108 | * state. |
| 1110 | 1109 | */ |
| 1111 | 1110 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { |
| 1112 | − hci_req_add_le_scan_disable(&req); | |
| 1111 | + hci_req_add_le_scan_disable(&req, rpa_le_conn); | |
| 1113 | 1112 | hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); |
| 1114 | 1113 | } |
| 1115 | 1114 | |
| @@ -1180,7 +1179,8 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev, · 64 unmodified lines | ||
| 1180 | 1179 | /* This function requires the caller holds hdev->lock */ |
| 1181 | 1180 | struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, |
| 1182 | 1181 | u8 dst_type, u8 sec_level, |
| 1183 | − u16 conn_timeout) | |
| 1182 | + u16 conn_timeout, | |
| 1183 | + enum conn_reasons conn_reason) | |
| 1184 | 1184 | { |
| 1185 | 1185 | struct hci_conn *conn; |
| 1186 | 1186 | |
| @@ -1225,6 +1225,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, · 38 unmodified lines | ||
| 1225 | 1225 | conn->sec_level = BT_SECURITY_LOW; |
| 1226 | 1226 | conn->pending_sec_level = sec_level; |
| 1227 | 1227 | conn->conn_timeout = conn_timeout; |
| 1228 | + conn->conn_reason = conn_reason; | |
| 1228 | 1229 | |
| 1229 | 1230 | hci_update_background_scan(hdev); |
| 1230 | 1231 | |
| @@ -1234,7 +1235,8 @@ done: · 3 unmodified lines | ||
| 1234 | 1235 | } |
| 1235 | 1236 | |
| 1236 | 1237 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, |
| 1237 | − u8 sec_level, u8 auth_type) | |
| 1238 | + u8 sec_level, u8 auth_type, | |
| 1239 | + enum conn_reasons conn_reason) | |
| 1238 | 1240 | { |
| 1239 | 1241 | struct hci_conn *acl; |
| 1240 | 1242 | |
| @@ -1254,6 +1256,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, · 13 unmodified lines | ||
| 1254 | 1256 | |
| 1255 | 1257 | hci_conn_hold(acl); |
| 1256 | 1258 | |
| 1259 | + acl->conn_reason = conn_reason; | |
| 1257 | 1260 | if (acl->state == BT_OPEN || acl->state == BT_CLOSED) { |
| 1258 | 1261 | acl->sec_level = BT_SECURITY_LOW; |
| 1259 | 1262 | acl->pending_sec_level = sec_level; |
| @@ -1270,7 +1273,8 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, · 10 unmodified lines | ||
| 1270 | 1273 | struct hci_conn *acl; |
| 1271 | 1274 | struct hci_conn *sco; |
| 1272 | 1275 | |
| 1273 | − acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING); | |
| 1276 | + acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING, | |
| 1277 | + CONN_REASON_SCO_CONNECT); | |
| 1274 | 1278 | if (IS_ERR(acl)) |
| 1275 | 1279 | return acl; |
| 1276 | 1280 | |
| @@ -1323,6 +1327,23 @@ int hci_conn_check_link_mode(struct hci_conn *conn) · 46 unmodified lines | ||
| 1323 | 1327 | return 0; |
| 1324 | 1328 | } |
| 1325 | 1329 | |
| 1330 | + /* AES encryption is required for Level 4: | |
| 1331 | + * | |
| 1332 | + * BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C | |
| 1333 | + * page 1319: | |
| 1334 | + * | |
| 1335 | + * 128-bit equivalent strength for link and encryption keys | |
| 1336 | + * required using FIPS approved algorithms (E0 not allowed, | |
| 1337 | + * SAFER+ not allowed, and P-192 not allowed; encryption key | |
| 1338 | + * not shortened) | |
| 1339 | + */ | |
| 1340 | + if (conn->sec_level == BT_SECURITY_FIPS && | |
| 1341 | + !test_bit(HCI_CONN_AES_CCM, &conn->flags)) { | |
| 1342 | + bt_dev_err(conn->hdev, | |
| 1343 | + "Invalid security: Missing AES-CCM usage"); | |
| 1344 | + return 0; | |
| 1345 | + } | |
| 1346 | + | |
| 1326 | 1347 | if (hci_conn_ssp_enabled(conn) && |
| 1327 | 1348 | !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) |
| 1328 | 1349 | return 0; |
| @@ -26,7 +26,6 @@ · 25 unmodified lines | ||
| 26 | 26 | /* Bluetooth HCI core. */ |
| 27 | 27 | |
| 28 | 28 | #include <linux/export.h> |
| 29 | −#include <linux/idr.h> | |
| 30 | 29 | #include <linux/rfkill.h> |
| 31 | 30 | #include <linux/debugfs.h> |
| 32 | 31 | #include <linux/crypto.h> |
| @@ -606,7 +605,8 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) · 573 unmodified lines | ||
| 606 | 605 | if (hdev->commands[8] & 0x01) |
| 607 | 606 | hci_req_add(req, HCI_OP_READ_PAGE_SCAN_ACTIVITY, 0, NULL); |
| 608 | 607 | |
| 609 | − if (hdev->commands[18] & 0x04) | |
| 608 | + if (hdev->commands[18] & 0x04 && | |
| 609 | + !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) | |
| 610 | 610 | hci_req_add(req, HCI_OP_READ_DEF_ERR_DATA_REPORTING, 0, NULL); |
| 611 | 611 | |
| 612 | 612 | /* Some older Broadcom based Bluetooth 1.2 controllers do not |
| @@ -763,6 +763,14 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) · 150 unmodified lines | ||
| 763 | 763 | hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL); |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | + if (hdev->commands[35] & 0x40) { | |
| 767 | + __le16 rpa_timeout = cpu_to_le16(hdev->rpa_timeout); | |
| 768 | + | |
| 769 | + /* Set RPA timeout */ | |
| 770 | + hci_req_add(req, HCI_OP_LE_SET_RPA_TIMEOUT, 2, | |
| 771 | + &rpa_timeout); | |
| 772 | + } | |
| 773 | + | |
| 766 | 774 | if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { |
| 767 | 775 | /* Read LE Maximum Data Length */ |
| 768 | 776 | hci_req_add(req, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL); |
| @@ -851,7 +859,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt) · 82 unmodified lines | ||
| 851 | 859 | /* Set erroneous data reporting if supported to the wideband speech |
| 852 | 860 | * setting value |
| 853 | 861 | */ |
| 854 | − if (hdev->commands[18] & 0x08) { | |
| 862 | + if (hdev->commands[18] & 0x08 && | |
| 863 | + !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) { | |
| 855 | 864 | bool enabled = hci_dev_test_flag(hdev, |
| 856 | 865 | HCI_WIDEBAND_SPEECH_ENABLED); |
| 857 | 866 | |
| @@ -2982,7 +2991,7 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 2124 unmodified lines | ||
| 2982 | 2991 | adv_instance->remaining_time = timeout; |
| 2983 | 2992 | |
| 2984 | 2993 | if (duration == 0) |
| 2985 | − adv_instance->duration = HCI_DEFAULT_ADV_DURATION; | |
| 2994 | + adv_instance->duration = hdev->def_multi_adv_rotation_duration; | |
| 2986 | 2995 | else |
| 2987 | 2996 | adv_instance->duration = duration; |
| 2988 | 2997 | |
| @@ -2996,6 +3005,94 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 7 unmodified lines | ||
| 2996 | 3005 | return 0; |
| 2997 | 3006 | } |
| 2998 | 3007 | |
| 3008 | +/* This function requires the caller holds hdev->lock */ | |
| 3009 | +void hci_adv_monitors_clear(struct hci_dev *hdev) | |
| 3010 | +{ | |
| 3011 | + struct adv_monitor *monitor; | |
| 3012 | + int handle; | |
| 3013 | + | |
| 3014 | + idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) | |
| 3015 | + hci_free_adv_monitor(monitor); | |
| 3016 | + | |
| 3017 | + idr_destroy(&hdev->adv_monitors_idr); | |
| 3018 | +} | |
| 3019 | + | |
| 3020 | +void hci_free_adv_monitor(struct adv_monitor *monitor) | |
| 3021 | +{ | |
| 3022 | + struct adv_pattern *pattern; | |
| 3023 | + struct adv_pattern *tmp; | |
| 3024 | + | |
| 3025 | + if (!monitor) | |
| 3026 | + return; | |
| 3027 | + | |
| 3028 | + list_for_each_entry_safe(pattern, tmp, &monitor->patterns, list) | |
| 3029 | + kfree(pattern); | |
| 3030 | + | |
| 3031 | + kfree(monitor); | |
| 3032 | +} | |
| 3033 | + | |
| 3034 | +/* This function requires the caller holds hdev->lock */ | |
| 3035 | +int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) | |
| 3036 | +{ | |
| 3037 | + int min, max, handle; | |
| 3038 | + | |
| 3039 | + if (!monitor) | |
| 3040 | + return -EINVAL; | |
| 3041 | + | |
| 3042 | + min = HCI_MIN_ADV_MONITOR_HANDLE; | |
| 3043 | + max = HCI_MIN_ADV_MONITOR_HANDLE + HCI_MAX_ADV_MONITOR_NUM_HANDLES; | |
| 3044 | + handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max, | |
| 3045 | + GFP_KERNEL); | |
| 3046 | + if (handle < 0) | |
| 3047 | + return handle; | |
| 3048 | + | |
| 3049 | + hdev->adv_monitors_cnt++; | |
| 3050 | + monitor->handle = handle; | |
| 3051 | + | |
| 3052 | + hci_update_background_scan(hdev); | |
| 3053 | + | |
| 3054 | + return 0; | |
| 3055 | +} | |
| 3056 | + | |
| 3057 | +static int free_adv_monitor(int id, void *ptr, void *data) | |
| 3058 | +{ | |
| 3059 | + struct hci_dev *hdev = data; | |
| 3060 | + struct adv_monitor *monitor = ptr; | |
| 3061 | + | |
| 3062 | + idr_remove(&hdev->adv_monitors_idr, monitor->handle); | |
| 3063 | + hci_free_adv_monitor(monitor); | |
| 3064 | + | |
| 3065 | + return 0; | |
| 3066 | +} | |
| 3067 | + | |
| 3068 | +/* This function requires the caller holds hdev->lock */ | |
| 3069 | +int hci_remove_adv_monitor(struct hci_dev *hdev, u16 handle) | |
| 3070 | +{ | |
| 3071 | + struct adv_monitor *monitor; | |
| 3072 | + | |
| 3073 | + if (handle) { | |
| 3074 | + monitor = idr_find(&hdev->adv_monitors_idr, handle); | |
| 3075 | + if (!monitor) | |
| 3076 | + return -ENOENT; | |
| 3077 | + | |
| 3078 | + idr_remove(&hdev->adv_monitors_idr, monitor->handle); | |
| 3079 | + hci_free_adv_monitor(monitor); | |
| 3080 | + } else { | |
| 3081 | + /* Remove all monitors if handle is 0. */ | |
| 3082 | + idr_for_each(&hdev->adv_monitors_idr, &free_adv_monitor, hdev); | |
| 3083 | + } | |
| 3084 | + | |
| 3085 | + hci_update_background_scan(hdev); | |
| 3086 | + | |
| 3087 | + return 0; | |
| 3088 | +} | |
| 3089 | + | |
| 3090 | +/* This function requires the caller holds hdev->lock */ | |
| 3091 | +bool hci_is_adv_monitoring(struct hci_dev *hdev) | |
| 3092 | +{ | |
| 3093 | + return !idr_is_empty(&hdev->adv_monitors_idr); | |
| 3094 | +} | |
| 3095 | + | |
| 2999 | 3096 | struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *bdaddr_list, |
| 3000 | 3097 | bdaddr_t *bdaddr, u8 type) |
| 3001 | 3098 | { |
| @@ -3023,6 +3120,20 @@ struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( · 21 unmodified lines | ||
| 3023 | 3120 | return NULL; |
| 3024 | 3121 | } |
| 3025 | 3122 | |
| 3123 | +struct bdaddr_list_with_flags * | |
| 3124 | +hci_bdaddr_list_lookup_with_flags(struct list_head *bdaddr_list, | |
| 3125 | + bdaddr_t *bdaddr, u8 type) | |
| 3126 | +{ | |
| 3127 | + struct bdaddr_list_with_flags *b; | |
| 3128 | + | |
| 3129 | + list_for_each_entry(b, bdaddr_list, list) { | |
| 3130 | + if (!bacmp(&b->bdaddr, bdaddr) && b->bdaddr_type == type) | |
| 3131 | + return b; | |
| 3132 | + } | |
| 3133 | + | |
| 3134 | + return NULL; | |
| 3135 | +} | |
| 3136 | + | |
| 3026 | 3137 | void hci_bdaddr_list_clear(struct list_head *bdaddr_list) |
| 3027 | 3138 | { |
| 3028 | 3139 | struct bdaddr_list *b, *n; |
| @@ -3084,6 +3195,30 @@ int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr, · 55 unmodified lines | ||
| 3084 | 3195 | return 0; |
| 3085 | 3196 | } |
| 3086 | 3197 | |
| 3198 | +int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr, | |
| 3199 | + u8 type, u32 flags) | |
| 3200 | +{ | |
| 3201 | + struct bdaddr_list_with_flags *entry; | |
| 3202 | + | |
| 3203 | + if (!bacmp(bdaddr, BDADDR_ANY)) | |
| 3204 | + return -EBADF; | |
| 3205 | + | |
| 3206 | + if (hci_bdaddr_list_lookup(list, bdaddr, type)) | |
| 3207 | + return -EEXIST; | |
| 3208 | + | |
| 3209 | + entry = kzalloc(sizeof(*entry), GFP_KERNEL); | |
| 3210 | + if (!entry) | |
| 3211 | + return -ENOMEM; | |
| 3212 | + | |
| 3213 | + bacpy(&entry->bdaddr, bdaddr); | |
| 3214 | + entry->bdaddr_type = type; | |
| 3215 | + entry->current_flags = flags; | |
| 3216 | + | |
| 3217 | + list_add(&entry->list, list); | |
| 3218 | + | |
| 3219 | + return 0; | |
| 3220 | +} | |
| 3221 | + | |
| 3087 | 3222 | int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type) |
| 3088 | 3223 | { |
| 3089 | 3224 | struct bdaddr_list *entry; |
| @@ -3123,6 +3258,26 @@ int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, · 33 unmodified lines | ||
| 3123 | 3258 | return 0; |
| 3124 | 3259 | } |
| 3125 | 3260 | |
| 3261 | +int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr, | |
| 3262 | + u8 type) | |
| 3263 | +{ | |
| 3264 | + struct bdaddr_list_with_flags *entry; | |
| 3265 | + | |
| 3266 | + if (!bacmp(bdaddr, BDADDR_ANY)) { | |
| 3267 | + hci_bdaddr_list_clear(list); | |
| 3268 | + return 0; | |
| 3269 | + } | |
| 3270 | + | |
| 3271 | + entry = hci_bdaddr_list_lookup_with_flags(list, bdaddr, type); | |
| 3272 | + if (!entry) | |
| 3273 | + return -ENOENT; | |
| 3274 | + | |
| 3275 | + list_del(&entry->list); | |
| 3276 | + kfree(entry); | |
| 3277 | + | |
| 3278 | + return 0; | |
| 3279 | +} | |
| 3280 | + | |
| 3126 | 3281 | /* This function requires the caller holds hdev->lock */ |
| 3127 | 3282 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, |
| 3128 | 3283 | bdaddr_t *addr, u8 addr_type) |
| @@ -3145,6 +3300,15 @@ struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list, · 16 unmodified lines | ||
| 3145 | 3300 | { |
| 3146 | 3301 | struct hci_conn_params *param; |
| 3147 | 3302 | |
| 3303 | + switch (addr_type) { | |
| 3304 | + case ADDR_LE_DEV_PUBLIC_RESOLVED: | |
| 3305 | + addr_type = ADDR_LE_DEV_PUBLIC; | |
| 3306 | + break; | |
| 3307 | + case ADDR_LE_DEV_RANDOM_RESOLVED: | |
| 3308 | + addr_type = ADDR_LE_DEV_RANDOM; | |
| 3309 | + break; | |
| 3310 | + } | |
| 3311 | + | |
| 3148 | 3312 | list_for_each_entry(param, list, action) { |
| 3149 | 3313 | if (bacmp(¶m->addr, addr) == 0 && |
| 3150 | 3314 | param->addr_type == addr_type) |
| @@ -3289,10 +3453,10 @@ static int hci_suspend_wait_event(struct hci_dev *hdev) · 138 unmodified lines | ||
| 3289 | 3453 | WAKE_COND, SUSPEND_NOTIFIER_TIMEOUT); |
| 3290 | 3454 | |
| 3291 | 3455 | if (ret == 0) { |
| 3292 | − bt_dev_dbg(hdev, "Timed out waiting for suspend"); | |
| 3456 | + bt_dev_err(hdev, "Timed out waiting for suspend events"); | |
| 3293 | 3457 | for (i = 0; i < __SUSPEND_NUM_TASKS; ++i) { |
| 3294 | 3458 | if (test_bit(i, hdev->suspend_tasks)) |
| 3295 | − bt_dev_dbg(hdev, "Bit %d is set", i); | |
| 3459 | + bt_dev_err(hdev, "Suspend timeout bit: %d", i); | |
| 3296 | 3460 | clear_bit(i, hdev->suspend_tasks); |
| 3297 | 3461 | } |
| 3298 | 3462 | |
| @@ -3360,12 +3524,15 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, · 61 unmodified lines | ||
| 3360 | 3524 | ret = hci_change_suspend_state(hdev, BT_RUNNING); |
| 3361 | 3525 | } |
| 3362 | 3526 | |
| 3363 | − /* If suspend failed, restore it to running */ | |
| 3364 | − if (ret && action == PM_SUSPEND_PREPARE) | |
| 3365 | − hci_change_suspend_state(hdev, BT_RUNNING); | |
| 3366 | − | |
| 3367 | 3527 | done: |
| 3368 | − return ret ? notifier_from_errno(-EBUSY) : NOTIFY_STOP; | |
| 3528 | + /* We always allow suspend even if suspend preparation failed and | |
| 3529 | + * attempt to recover in resume. | |
| 3530 | + */ | |
| 3531 | + if (ret) | |
| 3532 | + bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", | |
| 3533 | + action, ret); | |
| 3534 | + | |
| 3535 | + return NOTIFY_DONE; | |
| 3369 | 3536 | } |
| 3370 | 3537 | |
| 3371 | 3538 | /* Alloc HCI device */ |
| @@ -3397,6 +3564,12 @@ struct hci_dev *hci_alloc_dev(void) · 25 unmodified lines | ||
| 3397 | 3564 | hdev->le_adv_max_interval = 0x0800; |
| 3398 | 3565 | hdev->le_scan_interval = 0x0060; |
| 3399 | 3566 | hdev->le_scan_window = 0x0030; |
| 3567 | + hdev->le_scan_int_suspend = 0x0400; | |
| 3568 | + hdev->le_scan_window_suspend = 0x0012; | |
| 3569 | + hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; | |
| 3570 | + hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; | |
| 3571 | + hdev->le_scan_int_connect = 0x0060; | |
| 3572 | + hdev->le_scan_window_connect = 0x0060; | |
| 3400 | 3573 | hdev->le_conn_min_interval = 0x0018; |
| 3401 | 3574 | hdev->le_conn_max_interval = 0x0028; |
| 3402 | 3575 | hdev->le_conn_latency = 0x0000; |
| @@ -3412,6 +3585,8 @@ struct hci_dev *hci_alloc_dev(void) · 9 unmodified lines | ||
| 3412 | 3585 | hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; |
| 3413 | 3586 | hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; |
| 3414 | 3587 | hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; |
| 3588 | + hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; | |
| 3589 | + hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT; | |
| 3415 | 3590 | |
| 3416 | 3591 | hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; |
| 3417 | 3592 | hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; |
| @@ -3420,13 +3595,17 @@ struct hci_dev *hci_alloc_dev(void) · 2 unmodified lines | ||
| 3420 | 3595 | hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; |
| 3421 | 3596 | hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; |
| 3422 | 3597 | |
| 3598 | + /* default 1.28 sec page scan */ | |
| 3599 | + hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; | |
| 3600 | + hdev->def_page_scan_int = 0x0800; | |
| 3601 | + hdev->def_page_scan_window = 0x0012; | |
| 3602 | + | |
| 3423 | 3603 | mutex_init(&hdev->lock); |
| 3424 | 3604 | mutex_init(&hdev->req_lock); |
| 3425 | 3605 | |
| 3426 | 3606 | INIT_LIST_HEAD(&hdev->mgmt_pending); |
| 3427 | 3607 | INIT_LIST_HEAD(&hdev->blacklist); |
| 3428 | 3608 | INIT_LIST_HEAD(&hdev->whitelist); |
| 3429 | − INIT_LIST_HEAD(&hdev->wakeable); | |
| 3430 | 3609 | INIT_LIST_HEAD(&hdev->uuids); |
| 3431 | 3610 | INIT_LIST_HEAD(&hdev->link_keys); |
| 3432 | 3611 | INIT_LIST_HEAD(&hdev->long_term_keys); |
| @@ -3574,6 +3753,8 @@ int hci_register_dev(struct hci_dev *hdev) · 141 unmodified lines | ||
| 3574 | 3753 | |
| 3575 | 3754 | queue_work(hdev->req_workqueue, &hdev->power_on); |
| 3576 | 3755 | |
| 3756 | + idr_init(&hdev->adv_monitors_idr); | |
| 3757 | + | |
| 3577 | 3758 | return id; |
| 3578 | 3759 | |
| 3579 | 3760 | err_wqueue: |
| @@ -3603,9 +3784,10 @@ void hci_unregister_dev(struct hci_dev *hdev) · 23 unmodified lines | ||
| 3603 | 3784 | |
| 3604 | 3785 | cancel_work_sync(&hdev->power_on); |
| 3605 | 3786 | |
| 3606 | − hci_dev_do_close(hdev); | |
| 3607 | − | |
| 3608 | 3787 | unregister_pm_notifier(&hdev->suspend_notifier); |
| 3788 | + cancel_work_sync(&hdev->suspend_prepare); | |
| 3789 | + | |
| 3790 | + hci_dev_do_close(hdev); | |
| 3609 | 3791 | |
| 3610 | 3792 | if (!test_bit(HCI_INIT, &hdev->flags) && |
| 3611 | 3793 | !hci_dev_test_flag(hdev, HCI_SETUP) && |
| @@ -3644,6 +3826,7 @@ void hci_unregister_dev(struct hci_dev *hdev) · 32 unmodified lines | ||
| 3644 | 3826 | hci_smp_irks_clear(hdev); |
| 3645 | 3827 | hci_remote_oob_data_clear(hdev); |
| 3646 | 3828 | hci_adv_instances_clear(hdev); |
| 3829 | + hci_adv_monitors_clear(hdev); | |
| 3647 | 3830 | hci_bdaddr_list_clear(&hdev->le_white_list); |
| 3648 | 3831 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| 3649 | 3832 | hci_conn_params_clear_all(hdev); |
| @@ -4551,6 +4734,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) · 901 unmodified lines | ||
| 4551 | 4734 | |
| 4552 | 4735 | if (conn) { |
| 4553 | 4736 | /* Send to upper protocol */ |
| 4737 | + bt_cb(skb)->sco.pkt_status = flags & 0x03; | |
| 4554 | 4738 | sco_recv_scodata(conn, skb); |
| 4555 | 4739 | return; |
| 4556 | 4740 | } else { |
| @@ -2296,6 +2296,22 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, · 2295 unmodified lines | ||
| 2296 | 2296 | if (!conn) |
| 2297 | 2297 | return; |
| 2298 | 2298 | |
| 2299 | + /* When using controller based address resolution, then the new | |
| 2300 | + * address types 0x02 and 0x03 are used. These types need to be | |
| 2301 | + * converted back into either public address or random address type | |
| 2302 | + */ | |
| 2303 | + if (use_ll_privacy(hdev) && | |
| 2304 | + hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { | |
| 2305 | + switch (own_address_type) { | |
| 2306 | + case ADDR_LE_DEV_PUBLIC_RESOLVED: | |
| 2307 | + own_address_type = ADDR_LE_DEV_PUBLIC; | |
| 2308 | + break; | |
| 2309 | + case ADDR_LE_DEV_RANDOM_RESOLVED: | |
| 2310 | + own_address_type = ADDR_LE_DEV_RANDOM; | |
| 2311 | + break; | |
| 2312 | + } | |
| 2313 | + } | |
| 2314 | + | |
| 2299 | 2315 | /* Store the initiator and responder address information which |
| 2300 | 2316 | * is needed for SMP. These values will not change during the |
| 2301 | 2317 | * lifetime of the connection. |
| @@ -2517,7 +2533,7 @@ static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) · 215 unmodified lines | ||
| 2517 | 2533 | |
| 2518 | 2534 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2519 | 2535 | |
| 2520 | − if (!num_rsp) | |
| 2536 | + if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) | |
| 2521 | 2537 | return; |
| 2522 | 2538 | |
| 2523 | 2539 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
| @@ -2697,10 +2713,10 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) · 173 unmodified lines | ||
| 2697 | 2713 | */ |
| 2698 | 2714 | if (hci_dev_test_flag(hdev, HCI_MGMT) && |
| 2699 | 2715 | !hci_dev_test_flag(hdev, HCI_CONNECTABLE) && |
| 2700 | − !hci_bdaddr_list_lookup(&hdev->whitelist, &ev->bdaddr, | |
| 2701 | − BDADDR_BREDR)) { | |
| 2702 | − hci_reject_conn(hdev, &ev->bdaddr); | |
| 2703 | − return; | |
| 2716 | + !hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, &ev->bdaddr, | |
| 2717 | + BDADDR_BREDR)) { | |
| 2718 | + hci_reject_conn(hdev, &ev->bdaddr); | |
| 2719 | + return; | |
| 2704 | 2720 | } |
| 2705 | 2721 | |
| 2706 | 2722 | /* Connection accepted */ |
| @@ -2825,7 +2841,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) · 118 unmodified lines | ||
| 2825 | 2841 | case HCI_AUTO_CONN_LINK_LOSS: |
| 2826 | 2842 | if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| 2827 | 2843 | break; |
| 2828 | − /* Fall through */ | |
| 2844 | + fallthrough; | |
| 2829 | 2845 | |
| 2830 | 2846 | case HCI_AUTO_CONN_DIRECT: |
| 2831 | 2847 | case HCI_AUTO_CONN_ALWAYS: |
| @@ -3065,27 +3081,23 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) · 233 unmodified lines | ||
| 3065 | 3081 | |
| 3066 | 3082 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 3067 | 3083 | |
| 3084 | + /* Check link security requirements are met */ | |
| 3085 | + if (!hci_conn_check_link_mode(conn)) | |
| 3086 | + ev->status = HCI_ERROR_AUTH_FAILURE; | |
| 3087 | + | |
| 3068 | 3088 | if (ev->status && conn->state == BT_CONNECTED) { |
| 3069 | 3089 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3070 | 3090 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3071 | 3091 | |
| 3092 | + /* Notify upper layers so they can cleanup before | |
| 3093 | + * disconnecting. | |
| 3094 | + */ | |
| 3095 | + hci_encrypt_cfm(conn, ev->status); | |
| 3072 | 3096 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 3073 | 3097 | hci_conn_drop(conn); |
| 3074 | 3098 | goto unlock; |
| 3075 | 3099 | } |
| 3076 | 3100 | |
| 3077 | − /* In Secure Connections Only mode, do not allow any connections | |
| 3078 | − * that are not encrypted with AES-CCM using a P-256 authenticated | |
| 3079 | − * combination key. | |
| 3080 | − */ | |
| 3081 | − if (hci_dev_test_flag(hdev, HCI_SC_ONLY) && | |
| 3082 | − (!test_bit(HCI_CONN_AES_CCM, &conn->flags) || | |
| 3083 | − conn->key_type != HCI_LK_AUTH_COMBINATION_P256)) { | |
| 3084 | − hci_connect_cfm(conn, HCI_ERROR_AUTH_FAILURE); | |
| 3085 | − hci_conn_drop(conn); | |
| 3086 | − goto unlock; | |
| 3087 | − } | |
| 3088 | − | |
| 3089 | 3101 | /* Try reading the encryption key size for encrypted ACL links */ |
| 3090 | 3102 | if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { |
| 3091 | 3103 | struct hci_cp_read_enc_key_size cp; |
| @@ -4163,6 +4175,9 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 1071 unmodified lines | ||
| 4163 | 4175 | struct inquiry_info_with_rssi_and_pscan_mode *info; |
| 4164 | 4176 | info = (void *) (skb->data + 1); |
| 4165 | 4177 | |
| 4178 | + if (skb->len < num_rsp * sizeof(*info) + 1) | |
| 4179 | + goto unlock; | |
| 4180 | + | |
| 4166 | 4181 | for (; num_rsp; num_rsp--, info++) { |
| 4167 | 4182 | u32 flags; |
| 4168 | 4183 | |
| @@ -4184,6 +4199,9 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 15 unmodified lines | ||
| 4184 | 4199 | } else { |
| 4185 | 4200 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); |
| 4186 | 4201 | |
| 4202 | + if (skb->len < num_rsp * sizeof(*info) + 1) | |
| 4203 | + goto unlock; | |
| 4204 | + | |
| 4187 | 4205 | for (; num_rsp; num_rsp--, info++) { |
| 4188 | 4206 | u32 flags; |
| 4189 | 4207 | |
| @@ -4204,6 +4222,7 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 14 unmodified lines | ||
| 4204 | 4222 | } |
| 4205 | 4223 | } |
| 4206 | 4224 | |
| 4225 | +unlock: | |
| 4207 | 4226 | hci_dev_unlock(hdev); |
| 4208 | 4227 | } |
| 4209 | 4228 | |
| @@ -4324,7 +4343,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, · 114 unmodified lines | ||
| 4324 | 4343 | if (hci_setup_sync(conn, conn->link->handle)) |
| 4325 | 4344 | goto unlock; |
| 4326 | 4345 | } |
| 4327 | − /* fall through */ | |
| 4346 | + fallthrough; | |
| 4328 | 4347 | |
| 4329 | 4348 | default: |
| 4330 | 4349 | conn->state = BT_CLOSED; |
| @@ -4379,7 +4398,7 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · 48 unmodified lines | ||
| 4379 | 4398 | |
| 4380 | 4399 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 4381 | 4400 | |
| 4382 | − if (!num_rsp) | |
| 4401 | + if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) | |
| 4383 | 4402 | return; |
| 4384 | 4403 | |
| 4385 | 4404 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
| @@ -5209,6 +5228,11 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, · 823 unmodified lines | ||
| 5209 | 5228 | le16_to_cpu(ev->interval), |
| 5210 | 5229 | le16_to_cpu(ev->latency), |
| 5211 | 5230 | le16_to_cpu(ev->supervision_timeout)); |
| 5231 | + | |
| 5232 | + if (use_ll_privacy(hdev) && | |
| 5233 | + hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && | |
| 5234 | + hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) | |
| 5235 | + hci_req_disable_address_resolution(hdev); | |
| 5212 | 5236 | } |
| 5213 | 5237 | |
| 5214 | 5238 | static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| @@ -5319,7 +5343,7 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, · 104 unmodified lines | ||
| 5319 | 5343 | } |
| 5320 | 5344 | |
| 5321 | 5345 | conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, |
| 5322 | − HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER, | |
| 5346 | + hdev->def_le_autoconnect_timeout, HCI_ROLE_MASTER, | |
| 5323 | 5347 | direct_rpa); |
| 5324 | 5348 | if (!IS_ERR(conn)) { |
| 5325 | 5349 | /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned |
| @@ -5447,14 +5471,15 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, · 121 unmodified lines | ||
| 5447 | 5471 | |
| 5448 | 5472 | /* Passive scanning shouldn't trigger any device found events, |
| 5449 | 5473 | * except for devices marked as CONN_REPORT for which we do send |
| 5450 | − * device found events. | |
| 5474 | + * device found events, or advertisement monitoring requested. | |
| 5451 | 5475 | */ |
| 5452 | 5476 | if (hdev->le_scan_type == LE_SCAN_PASSIVE) { |
| 5453 | 5477 | if (type == LE_ADV_DIRECT_IND) |
| 5454 | 5478 | return; |
| 5455 | 5479 | |
| 5456 | 5480 | if (!hci_pend_le_action_lookup(&hdev->pend_le_reports, |
| 5457 | − bdaddr, bdaddr_type)) | |
| 5481 | + bdaddr, bdaddr_type) && | |
| 5482 | + idr_is_empty(&hdev->adv_monitors_idr)) | |
| 5458 | 5483 | return; |
| 5459 | 5484 | |
| 5460 | 5485 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND) |
| @@ -34,9 +34,6 @@ · 33 unmodified lines | ||
| 34 | 34 | #define HCI_REQ_PEND 1 |
| 35 | 35 | #define HCI_REQ_CANCELED 2 |
| 36 | 36 | |
| 37 | −#define LE_SUSPEND_SCAN_WINDOW 0x0012 | |
| 38 | −#define LE_SUSPEND_SCAN_INTERVAL 0x0400 | |
| 39 | − | |
| 40 | 37 | void hci_req_init(struct hci_request *req, struct hci_dev *hdev) |
| 41 | 38 | { |
| 42 | 39 | skb_queue_head_init(&req->cmd_q); |
| @@ -366,13 +363,11 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable) · 323 unmodified lines | ||
| 366 | 363 | /* 160 msec page scan interval */ |
| 367 | 364 | acp.interval = cpu_to_le16(0x0100); |
| 368 | 365 | } else { |
| 369 | − type = PAGE_SCAN_TYPE_STANDARD; /* default */ | |
| 370 | − | |
| 371 | − /* default 1.28 sec page scan */ | |
| 372 | − acp.interval = cpu_to_le16(0x0800); | |
| 366 | + type = hdev->def_page_scan_type; | |
| 367 | + acp.interval = cpu_to_le16(hdev->def_page_scan_int); | |
| 373 | 368 | } |
| 374 | 369 | |
| 375 | − acp.window = cpu_to_le16(0x0012); | |
| 370 | + acp.window = cpu_to_le16(hdev->def_page_scan_window); | |
| 376 | 371 | |
| 377 | 372 | if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval || |
| 378 | 373 | __cpu_to_le16(hdev->page_scan_window) != acp.window) |
| @@ -418,18 +413,22 @@ static void __hci_update_background_scan(struct hci_request *req) · 39 unmodified lines | ||
| 418 | 413 | */ |
| 419 | 414 | hci_discovery_filter_clear(hdev); |
| 420 | 415 | |
| 416 | + BT_DBG("%s ADV monitoring is %s", hdev->name, | |
| 417 | + hci_is_adv_monitoring(hdev) ? "on" : "off"); | |
| 418 | + | |
| 421 | 419 | if (list_empty(&hdev->pend_le_conns) && |
| 422 | − list_empty(&hdev->pend_le_reports)) { | |
| 420 | + list_empty(&hdev->pend_le_reports) && | |
| 421 | + !hci_is_adv_monitoring(hdev)) { | |
| 423 | 422 | /* If there is no pending LE connections or devices |
| 424 | − * to be scanned for, we should stop the background | |
| 425 | − * scanning. | |
| 423 | + * to be scanned for or no ADV monitors, we should stop the | |
| 424 | + * background scanning. | |
| 426 | 425 | */ |
| 427 | 426 | |
| 428 | 427 | /* If controller is not scanning we are done. */ |
| 429 | 428 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) |
| 430 | 429 | return; |
| 431 | 430 | |
| 432 | − hci_req_add_le_scan_disable(req); | |
| 431 | + hci_req_add_le_scan_disable(req, false); | |
| 433 | 432 | |
| 434 | 433 | BT_DBG("%s stopping background scanning", hdev->name); |
| 435 | 434 | } else { |
| @@ -448,7 +447,7 @@ static void __hci_update_background_scan(struct hci_request *req) · 12 unmodified lines | ||
| 448 | 447 | * don't miss any advertising (due to duplicates filter). |
| 449 | 448 | */ |
| 450 | 449 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) |
| 451 | − hci_req_add_le_scan_disable(req); | |
| 450 | + hci_req_add_le_scan_disable(req, false); | |
| 452 | 451 | |
| 453 | 452 | hci_req_add_le_passive_scan(req); |
| 454 | 453 | |
| @@ -653,7 +652,7 @@ void __hci_req_update_eir(struct hci_request *req) · 198 unmodified lines | ||
| 653 | 652 | hci_req_add(req, HCI_OP_WRITE_EIR, sizeof(cp), &cp); |
| 654 | 653 | } |
| 655 | 654 | |
| 656 | −void hci_req_add_le_scan_disable(struct hci_request *req) | |
| 655 | +void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn) | |
| 657 | 656 | { |
| 658 | 657 | struct hci_dev *hdev = req->hdev; |
| 659 | 658 | |
| @@ -676,6 +675,15 @@ void hci_req_add_le_scan_disable(struct hci_request *req) · 16 unmodified lines | ||
| 676 | 675 | cp.enable = LE_SCAN_DISABLE; |
| 677 | 676 | hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp); |
| 678 | 677 | } |
| 678 | + | |
| 679 | + /* Disable address resolution */ | |
| 680 | + if (use_ll_privacy(hdev) && | |
| 681 | + hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && | |
| 682 | + hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) { | |
| 683 | + __u8 enable = 0x00; | |
| 684 | + | |
| 685 | + hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable); | |
| 686 | + } | |
| 679 | 687 | } |
| 680 | 688 | |
| 681 | 689 | static void del_from_white_list(struct hci_request *req, bdaddr_t *bdaddr, |
| @@ -689,6 +697,21 @@ static void del_from_white_list(struct hci_request *req, bdaddr_t *bdaddr, · 7 unmodified lines | ||
| 689 | 697 | bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from whitelist", &cp.bdaddr, |
| 690 | 698 | cp.bdaddr_type); |
| 691 | 699 | hci_req_add(req, HCI_OP_LE_DEL_FROM_WHITE_LIST, sizeof(cp), &cp); |
| 700 | + | |
| 701 | + if (use_ll_privacy(req->hdev)) { | |
| 702 | + struct smp_irk *irk; | |
| 703 | + | |
| 704 | + irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type); | |
| 705 | + if (irk) { | |
| 706 | + struct hci_cp_le_del_from_resolv_list cp; | |
| 707 | + | |
| 708 | + cp.bdaddr_type = bdaddr_type; | |
| 709 | + bacpy(&cp.bdaddr, bdaddr); | |
| 710 | + | |
| 711 | + hci_req_add(req, HCI_OP_LE_DEL_FROM_RESOLV_LIST, | |
| 712 | + sizeof(cp), &cp); | |
| 713 | + } | |
| 714 | + } | |
| 692 | 715 | } |
| 693 | 716 | |
| 694 | 717 | /* Adds connection to white list if needed. On error, returns -1. */ |
| @@ -709,13 +732,14 @@ static int add_to_white_list(struct hci_request *req, · 14 unmodified lines | ||
| 709 | 732 | return -1; |
| 710 | 733 | |
| 711 | 734 | /* White list can not be used with RPAs */ |
| 712 | − if (!allow_rpa && | |
| 735 | + if (!allow_rpa && !use_ll_privacy(hdev) && | |
| 713 | 736 | hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) { |
| 714 | 737 | return -1; |
| 715 | 738 | } |
| 716 | 739 | |
| 717 | 740 | /* During suspend, only wakeable devices can be in whitelist */ |
| 718 | − if (hdev->suspended && !params->wakeable) | |
| 741 | + if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, | |
| 742 | + params->current_flags)) | |
| 719 | 743 | return 0; |
| 720 | 744 | |
| 721 | 745 | *num_entries += 1; |
| @@ -726,6 +750,28 @@ static int add_to_white_list(struct hci_request *req, · 4 unmodified lines | ||
| 726 | 750 | cp.bdaddr_type); |
| 727 | 751 | hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp); |
| 728 | 752 | |
| 753 | + if (use_ll_privacy(hdev)) { | |
| 754 | + struct smp_irk *irk; | |
| 755 | + | |
| 756 | + irk = hci_find_irk_by_addr(hdev, ¶ms->addr, | |
| 757 | + params->addr_type); | |
| 758 | + if (irk) { | |
| 759 | + struct hci_cp_le_add_to_resolv_list cp; | |
| 760 | + | |
| 761 | + cp.bdaddr_type = params->addr_type; | |
| 762 | + bacpy(&cp.bdaddr, ¶ms->addr); | |
| 763 | + memcpy(cp.peer_irk, irk->val, 16); | |
| 764 | + | |
| 765 | + if (hci_dev_test_flag(hdev, HCI_PRIVACY)) | |
| 766 | + memcpy(cp.local_irk, hdev->irk, 16); | |
| 767 | + else | |
| 768 | + memset(cp.local_irk, 0, 16); | |
| 769 | + | |
| 770 | + hci_req_add(req, HCI_OP_LE_ADD_TO_RESOLV_LIST, | |
| 771 | + sizeof(cp), &cp); | |
| 772 | + } | |
| 773 | + } | |
| 774 | + | |
| 729 | 775 | return 0; |
| 730 | 776 | } |
| 731 | 777 | |
| @@ -766,7 +812,7 @@ static u8 update_white_list(struct hci_request *req) · 34 unmodified lines | ||
| 766 | 812 | } |
| 767 | 813 | |
| 768 | 814 | /* White list can not be used with RPAs */ |
| 769 | − if (!allow_rpa && | |
| 815 | + if (!allow_rpa && !use_ll_privacy(hdev) && | |
| 770 | 816 | hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { |
| 771 | 817 | return 0x00; |
| 772 | 818 | } |
| @@ -798,6 +844,14 @@ static u8 update_white_list(struct hci_request *req) · 25 unmodified lines | ||
| 798 | 844 | return 0x00; |
| 799 | 845 | } |
| 800 | 846 | |
| 847 | + /* Once the controller offloading of advertisement monitor is in place, | |
| 848 | + * the if condition should include the support of MSFT extension | |
| 849 | + * support. If suspend is ongoing, whitelist should be the default to | |
| 850 | + * prevent waking by random advertisements. | |
| 851 | + */ | |
| 852 | + if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended) | |
| 853 | + return 0x00; | |
| 854 | + | |
| 801 | 855 | /* Select filter policy to use white list */ |
| 802 | 856 | return 0x01; |
| 803 | 857 | } |
| @@ -808,10 +862,24 @@ static bool scan_use_rpa(struct hci_dev *hdev) · 4 unmodified lines | ||
| 808 | 862 | } |
| 809 | 863 | |
| 810 | 864 | static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, |
| 811 | − u16 window, u8 own_addr_type, u8 filter_policy) | |
| 865 | + u16 window, u8 own_addr_type, u8 filter_policy, | |
| 866 | + bool addr_resolv) | |
| 812 | 867 | { |
| 813 | 868 | struct hci_dev *hdev = req->hdev; |
| 814 | 869 | |
| 870 | + if (hdev->scanning_paused) { | |
| 871 | + bt_dev_dbg(hdev, "Scanning is paused for suspend"); | |
| 872 | + return; | |
| 873 | + } | |
| 874 | + | |
| 875 | + if (use_ll_privacy(hdev) && | |
| 876 | + hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && | |
| 877 | + addr_resolv) { | |
| 878 | + u8 enable = 0x01; | |
| 879 | + | |
| 880 | + hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable); | |
| 881 | + } | |
| 882 | + | |
| 815 | 883 | /* Use ext scanning if set ext scan param and ext scan enable is |
| 816 | 884 | * supported |
| 817 | 885 | */ |
| @@ -885,12 +953,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · 67 unmodified lines | ||
| 885 | 953 | } |
| 886 | 954 | } |
| 887 | 955 | |
| 956 | +/* Returns true if an le connection is in the scanning state */ | |
| 957 | +static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) | |
| 958 | +{ | |
| 959 | + struct hci_conn_hash *h = &hdev->conn_hash; | |
| 960 | + struct hci_conn *c; | |
| 961 | + | |
| 962 | + rcu_read_lock(); | |
| 963 | + | |
| 964 | + list_for_each_entry_rcu(c, &h->list, list) { | |
| 965 | + if (c->type == LE_LINK && c->state == BT_CONNECT && | |
| 966 | + test_bit(HCI_CONN_SCANNING, &c->flags)) { | |
| 967 | + rcu_read_unlock(); | |
| 968 | + return true; | |
| 969 | + } | |
| 970 | + } | |
| 971 | + | |
| 972 | + rcu_read_unlock(); | |
| 973 | + | |
| 974 | + return false; | |
| 975 | +} | |
| 976 | + | |
| 977 | +/* Ensure to call hci_req_add_le_scan_disable() first to disable the | |
| 978 | + * controller based address resolution to be able to reconfigure | |
| 979 | + * resolving list. | |
| 980 | + */ | |
| 888 | 981 | void hci_req_add_le_passive_scan(struct hci_request *req) |
| 889 | 982 | { |
| 890 | 983 | struct hci_dev *hdev = req->hdev; |
| 891 | 984 | u8 own_addr_type; |
| 892 | 985 | u8 filter_policy; |
| 893 | 986 | u16 window, interval; |
| 987 | + /* Background scanning should run with address resolution */ | |
| 988 | + bool addr_resolv = true; | |
| 894 | 989 | |
| 895 | 990 | if (hdev->scanning_paused) { |
| 896 | 991 | bt_dev_dbg(hdev, "Scanning is paused for suspend"); |
| @@ -927,8 +1022,11 @@ void hci_req_add_le_passive_scan(struct hci_request *req) · 30 unmodified lines | ||
| 927 | 1022 | filter_policy |= 0x02; |
| 928 | 1023 | |
| 929 | 1024 | if (hdev->suspended) { |
| 930 | − window = LE_SUSPEND_SCAN_WINDOW; | |
| 931 | − interval = LE_SUSPEND_SCAN_INTERVAL; | |
| 1025 | + window = hdev->le_scan_window_suspend; | |
| 1026 | + interval = hdev->le_scan_int_suspend; | |
| 1027 | + } else if (hci_is_le_conn_scanning(hdev)) { | |
| 1028 | + window = hdev->le_scan_window_connect; | |
| 1029 | + interval = hdev->le_scan_int_connect; | |
| 932 | 1030 | } else { |
| 933 | 1031 | window = hdev->le_scan_window; |
| 934 | 1032 | interval = hdev->le_scan_interval; |
| @@ -936,7 +1034,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req) · 1 unmodified line | ||
| 936 | 1034 | |
| 937 | 1035 | bt_dev_dbg(hdev, "LE passive scan with whitelist = %d", filter_policy); |
| 938 | 1036 | hci_req_start_scan(req, LE_SCAN_PASSIVE, interval, window, |
| 939 | − own_addr_type, filter_policy); | |
| 1037 | + own_addr_type, filter_policy, addr_resolv); | |
| 940 | 1038 | } |
| 941 | 1039 | |
| 942 | 1040 | static u8 get_adv_instance_scan_rsp_len(struct hci_dev *hdev, u8 instance) |
| @@ -973,15 +1071,19 @@ static void hci_req_clear_event_filter(struct hci_request *req) · 30 unmodified lines | ||
| 973 | 1071 | |
| 974 | 1072 | static void hci_req_set_event_filter(struct hci_request *req) |
| 975 | 1073 | { |
| 976 | − struct bdaddr_list *b; | |
| 1074 | + struct bdaddr_list_with_flags *b; | |
| 977 | 1075 | struct hci_cp_set_event_filter f; |
| 978 | 1076 | struct hci_dev *hdev = req->hdev; |
| 979 | − u8 scan; | |
| 1077 | + u8 scan = SCAN_DISABLED; | |
| 980 | 1078 | |
| 981 | 1079 | /* Always clear event filter when starting */ |
| 982 | 1080 | hci_req_clear_event_filter(req); |
| 983 | 1081 | |
| 984 | − list_for_each_entry(b, &hdev->wakeable, list) { | |
| 1082 | + list_for_each_entry(b, &hdev->whitelist, list) { | |
| 1083 | + if (!hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, | |
| 1084 | + b->current_flags)) | |
| 1085 | + continue; | |
| 1086 | + | |
| 985 | 1087 | memset(&f, 0, sizeof(f)); |
| 986 | 1088 | bacpy(&f.addr_conn_flt.bdaddr, &b->bdaddr); |
| 987 | 1089 | f.flt_type = HCI_FLT_CONN_SETUP; |
| @@ -990,16 +1092,17 @@ static void hci_req_set_event_filter(struct hci_request *req) · 2 unmodified lines | ||
| 990 | 1092 | |
| 991 | 1093 | bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); |
| 992 | 1094 | hci_req_add(req, HCI_OP_SET_EVENT_FLT, sizeof(f), &f); |
| 1095 | + scan = SCAN_PAGE; | |
| 993 | 1096 | } |
| 994 | 1097 | |
| 995 | − scan = !list_empty(&hdev->wakeable) ? SCAN_PAGE : SCAN_DISABLED; | |
| 996 | 1098 | hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); |
| 997 | 1099 | } |
| 998 | 1100 | |
| 999 | 1101 | static void hci_req_config_le_suspend_scan(struct hci_request *req) |
| 1000 | 1102 | { |
| 1001 | − /* Can't change params without disabling first */ | |
| 1002 | − hci_req_add_le_scan_disable(req); | |
| 1103 | + /* Before changing params disable scan if enabled */ | |
| 1104 | + if (hci_dev_test_flag(req->hdev, HCI_LE_SCAN)) | |
| 1105 | + hci_req_add_le_scan_disable(req, false); | |
| 1003 | 1106 | |
| 1004 | 1107 | /* Configure params and enable scanning */ |
| 1005 | 1108 | hci_req_add_le_passive_scan(req); |
| @@ -1065,8 +1168,9 @@ void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) · 59 unmodified lines | ||
| 1065 | 1168 | page_scan = SCAN_DISABLED; |
| 1066 | 1169 | hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &page_scan); |
| 1067 | 1170 | |
| 1068 | − /* Disable LE passive scan */ | |
| 1069 | − hci_req_add_le_scan_disable(&req); | |
| 1171 | + /* Disable LE passive scan if enabled */ | |
| 1172 | + if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) | |
| 1173 | + hci_req_add_le_scan_disable(&req, false); | |
| 1070 | 1174 | |
| 1071 | 1175 | /* Mark task needing completion */ |
| 1072 | 1176 | set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); |
| @@ -1160,13 +1264,8 @@ static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) · 87 unmodified lines | ||
| 1160 | 1264 | void __hci_req_disable_advertising(struct hci_request *req) |
| 1161 | 1265 | { |
| 1162 | 1266 | if (ext_adv_capable(req->hdev)) { |
| 1163 | − struct hci_cp_le_set_ext_adv_enable cp; | |
| 1164 | − | |
| 1165 | − cp.enable = 0x00; | |
| 1166 | − /* Disable all sets since we only support one set at the moment */ | |
| 1167 | − cp.num_of_sets = 0x00; | |
| 1267 | + __hci_req_disable_ext_adv_instance(req, 0x00); | |
| 1168 | 1268 | |
| 1169 | − hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(cp), &cp); | |
| 1170 | 1269 | } else { |
| 1171 | 1270 | u8 enable = 0x00; |
| 1172 | 1271 | |
| @@ -1627,6 +1726,28 @@ int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) · 454 unmodified lines | ||
| 1627 | 1726 | return hci_req_run(&req, NULL); |
| 1628 | 1727 | } |
| 1629 | 1728 | |
| 1729 | +static void enable_addr_resolution_complete(struct hci_dev *hdev, u8 status, | |
| 1730 | + u16 opcode) | |
| 1731 | +{ | |
| 1732 | + BT_DBG("%s status %u", hdev->name, status); | |
| 1733 | +} | |
| 1734 | + | |
| 1735 | +void hci_req_disable_address_resolution(struct hci_dev *hdev) | |
| 1736 | +{ | |
| 1737 | + struct hci_request req; | |
| 1738 | + __u8 enable = 0x00; | |
| 1739 | + | |
| 1740 | + if (!use_ll_privacy(hdev) && | |
| 1741 | + !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) | |
| 1742 | + return; | |
| 1743 | + | |
| 1744 | + hci_req_init(&req, hdev); | |
| 1745 | + | |
| 1746 | + hci_req_add(&req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, 1, &enable); | |
| 1747 | + | |
| 1748 | + hci_req_run(&req, enable_addr_resolution_complete); | |
| 1749 | +} | |
| 1750 | + | |
| 1630 | 1751 | static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) |
| 1631 | 1752 | { |
| 1632 | 1753 | BT_DBG("%s status %u", hdev->name, status); |
| @@ -1786,8 +1907,6 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) · 153 unmodified lines | ||
| 1786 | 1907 | int err; |
| 1787 | 1908 | struct adv_info *adv_instance; |
| 1788 | 1909 | bool secondary_adv; |
| 1789 | − /* In ext adv set param interval is 3 octets */ | |
| 1790 | − const u8 adv_interval[3] = { 0x00, 0x08, 0x00 }; | |
| 1791 | 1910 | |
| 1792 | 1911 | if (instance > 0) { |
| 1793 | 1912 | adv_instance = hci_find_adv_instance(hdev, instance); |
| @@ -1820,8 +1939,9 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) · 26 unmodified lines | ||
| 1820 | 1939 | |
| 1821 | 1940 | memset(&cp, 0, sizeof(cp)); |
| 1822 | 1941 | |
| 1823 | − memcpy(cp.min_interval, adv_interval, sizeof(cp.min_interval)); | |
| 1824 | − memcpy(cp.max_interval, adv_interval, sizeof(cp.max_interval)); | |
| 1942 | + /* In ext adv set param interval is 3 octets */ | |
| 1943 | + hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); | |
| 1944 | + hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); | |
| 1825 | 1945 | |
| 1826 | 1946 | secondary_adv = (flags & MGMT_ADV_FLAG_SEC_MASK); |
| 1827 | 1947 | |
| @@ -1932,13 +2052,59 @@ int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance) · 104 unmodified lines | ||
| 1932 | 2052 | return 0; |
| 1933 | 2053 | } |
| 1934 | 2054 | |
| 2055 | +int __hci_req_disable_ext_adv_instance(struct hci_request *req, u8 instance) | |
| 2056 | +{ | |
| 2057 | + struct hci_dev *hdev = req->hdev; | |
| 2058 | + struct hci_cp_le_set_ext_adv_enable *cp; | |
| 2059 | + struct hci_cp_ext_adv_set *adv_set; | |
| 2060 | + u8 data[sizeof(*cp) + sizeof(*adv_set) * 1]; | |
| 2061 | + u8 req_size; | |
| 2062 | + | |
| 2063 | + /* If request specifies an instance that doesn't exist, fail */ | |
| 2064 | + if (instance > 0 && !hci_find_adv_instance(hdev, instance)) | |
| 2065 | + return -EINVAL; | |
| 2066 | + | |
| 2067 | + memset(data, 0, sizeof(data)); | |
| 2068 | + | |
| 2069 | + cp = (void *)data; | |
| 2070 | + adv_set = (void *)cp->data; | |
| 2071 | + | |
| 2072 | + /* Instance 0x00 indicates all advertising instances will be disabled */ | |
| 2073 | + cp->num_of_sets = !!instance; | |
| 2074 | + cp->enable = 0x00; | |
| 2075 | + | |
| 2076 | + adv_set->handle = instance; | |
| 2077 | + | |
| 2078 | + req_size = sizeof(*cp) + sizeof(*adv_set) * cp->num_of_sets; | |
| 2079 | + hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE, req_size, data); | |
| 2080 | + | |
| 2081 | + return 0; | |
| 2082 | +} | |
| 2083 | + | |
| 2084 | +int __hci_req_remove_ext_adv_instance(struct hci_request *req, u8 instance) | |
| 2085 | +{ | |
| 2086 | + struct hci_dev *hdev = req->hdev; | |
| 2087 | + | |
| 2088 | + /* If request specifies an instance that doesn't exist, fail */ | |
| 2089 | + if (instance > 0 && !hci_find_adv_instance(hdev, instance)) | |
| 2090 | + return -EINVAL; | |
| 2091 | + | |
| 2092 | + hci_req_add(req, HCI_OP_LE_REMOVE_ADV_SET, sizeof(instance), &instance); | |
| 2093 | + | |
| 2094 | + return 0; | |
| 2095 | +} | |
| 2096 | + | |
| 1935 | 2097 | int __hci_req_start_ext_adv(struct hci_request *req, u8 instance) |
| 1936 | 2098 | { |
| 1937 | 2099 | struct hci_dev *hdev = req->hdev; |
| 2100 | + struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance); | |
| 1938 | 2101 | int err; |
| 1939 | 2102 | |
| 1940 | − if (hci_dev_test_flag(hdev, HCI_LE_ADV)) | |
| 1941 | − __hci_req_disable_advertising(req); | |
| 2103 | + /* If instance isn't pending, the chip knows about it, and it's safe to | |
| 2104 | + * disable | |
| 2105 | + */ | |
| 2106 | + if (adv_instance && !adv_instance->pending) | |
| 2107 | + __hci_req_disable_ext_adv_instance(req, instance); | |
| 1942 | 2108 | |
| 1943 | 2109 | err = __hci_req_setup_ext_adv_instance(req, instance); |
| 1944 | 2110 | if (err < 0) |
| @@ -2086,7 +2252,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, · 141 unmodified lines | ||
| 2086 | 2252 | hci_dev_test_flag(hdev, HCI_ADVERTISING)) |
| 2087 | 2253 | return; |
| 2088 | 2254 | |
| 2089 | − if (next_instance) | |
| 2255 | + if (next_instance && !ext_adv_capable(hdev)) | |
| 2090 | 2256 | __hci_req_schedule_adv_instance(req, next_instance->instance, |
| 2091 | 2257 | false); |
| 2092 | 2258 | } |
| @@ -2128,7 +2294,13 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, · 35 unmodified lines | ||
| 2128 | 2294 | if (use_rpa) { |
| 2129 | 2295 | int to; |
| 2130 | 2296 | |
| 2131 | − *own_addr_type = ADDR_LE_DEV_RANDOM; | |
| 2297 | + /* If Controller supports LL Privacy use own address type is | |
| 2298 | + * 0x03 | |
| 2299 | + */ | |
| 2300 | + if (use_ll_privacy(hdev)) | |
| 2301 | + *own_addr_type = ADDR_LE_DEV_RANDOM_RESOLVED; | |
| 2302 | + else | |
| 2303 | + *own_addr_type = ADDR_LE_DEV_RANDOM; | |
| 2132 | 2304 | |
| 2133 | 2305 | if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && |
| 2134 | 2306 | !bacmp(&hdev->random_addr, &hdev->rpa)) |
| @@ -2547,7 +2719,7 @@ static void bg_scan_update(struct work_struct *work) · 412 unmodified lines | ||
| 2547 | 2719 | |
| 2548 | 2720 | static int le_scan_disable(struct hci_request *req, unsigned long opt) |
| 2549 | 2721 | { |
| 2550 | − hci_req_add_le_scan_disable(req); | |
| 2722 | + hci_req_add_le_scan_disable(req, false); | |
| 2551 | 2723 | return 0; |
| 2552 | 2724 | } |
| 2553 | 2725 | |
| @@ -2645,7 +2817,12 @@ static int le_scan_restart(struct hci_request *req, unsigned long opt) · 91 unmodified lines | ||
| 2645 | 2817 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) |
| 2646 | 2818 | return 0; |
| 2647 | 2819 | |
| 2648 | − hci_req_add_le_scan_disable(req); | |
| 2820 | + if (hdev->scanning_paused) { | |
| 2821 | + bt_dev_dbg(hdev, "Scanning is paused for suspend"); | |
| 2822 | + return 0; | |
| 2823 | + } | |
| 2824 | + | |
| 2825 | + hci_req_add_le_scan_disable(req, false); | |
| 2649 | 2826 | |
| 2650 | 2827 | if (use_ext_scan(hdev)) { |
| 2651 | 2828 | struct hci_cp_le_set_ext_scan_enable ext_enable_cp; |
| @@ -2725,6 +2902,8 @@ static int active_scan(struct hci_request *req, unsigned long opt) · 73 unmodified lines | ||
| 2725 | 2902 | u8 own_addr_type; |
| 2726 | 2903 | /* White list is not used for discovery */ |
| 2727 | 2904 | u8 filter_policy = 0x00; |
| 2905 | + /* Discovery doesn't require controller address resolution */ | |
| 2906 | + bool addr_resolv = false; | |
| 2728 | 2907 | int err; |
| 2729 | 2908 | |
| 2730 | 2909 | BT_DBG("%s", hdev->name); |
| @@ -2734,7 +2913,7 @@ static int active_scan(struct hci_request *req, unsigned long opt) · 3 unmodified lines | ||
| 2734 | 2913 | * discovery scanning parameters. |
| 2735 | 2914 | */ |
| 2736 | 2915 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) |
| 2737 | − hci_req_add_le_scan_disable(req); | |
| 2916 | + hci_req_add_le_scan_disable(req, false); | |
| 2738 | 2917 | |
| 2739 | 2918 | /* All active scans will be done with either a resolvable private |
| 2740 | 2919 | * address (when privacy feature has been enabled) or non-resolvable |
| @@ -2745,8 +2924,9 @@ static int active_scan(struct hci_request *req, unsigned long opt) · 4 unmodified lines | ||
| 2745 | 2924 | if (err < 0) |
| 2746 | 2925 | own_addr_type = ADDR_LE_DEV_PUBLIC; |
| 2747 | 2926 | |
| 2748 | − hci_req_start_scan(req, LE_SCAN_ACTIVE, interval, DISCOV_LE_SCAN_WIN, | |
| 2749 | − own_addr_type, filter_policy); | |
| 2927 | + hci_req_start_scan(req, LE_SCAN_ACTIVE, interval, | |
| 2928 | + hdev->le_scan_window_discovery, own_addr_type, | |
| 2929 | + filter_policy, addr_resolv); | |
| 2750 | 2930 | return 0; |
| 2751 | 2931 | } |
| 2752 | 2932 | |
| @@ -2793,18 +2973,18 @@ static void start_discovery(struct hci_dev *hdev, u8 *status) · 40 unmodified lines | ||
| 2793 | 2973 | * to do BR/EDR inquiry. |
| 2794 | 2974 | */ |
| 2795 | 2975 | hci_req_sync(hdev, interleaved_discov, |
| 2796 | − DISCOV_LE_SCAN_INT * 2, HCI_CMD_TIMEOUT, | |
| 2976 | + hdev->le_scan_int_discovery * 2, HCI_CMD_TIMEOUT, | |
| 2797 | 2977 | status); |
| 2798 | 2978 | break; |
| 2799 | 2979 | } |
| 2800 | 2980 | |
| 2801 | 2981 | timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); |
| 2802 | − hci_req_sync(hdev, active_scan, DISCOV_LE_SCAN_INT, | |
| 2982 | + hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, | |
| 2803 | 2983 | HCI_CMD_TIMEOUT, status); |
| 2804 | 2984 | break; |
| 2805 | 2985 | case DISCOV_TYPE_LE: |
| 2806 | 2986 | timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT); |
| 2807 | − hci_req_sync(hdev, active_scan, DISCOV_LE_SCAN_INT, | |
| 2987 | + hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, | |
| 2808 | 2988 | HCI_CMD_TIMEOUT, status); |
| 2809 | 2989 | break; |
| 2810 | 2990 | default: |
| @@ -2848,14 +3028,14 @@ bool hci_req_stop_discovery(struct hci_request *req) · 37 unmodified lines | ||
| 2848 | 3028 | |
| 2849 | 3029 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { |
| 2850 | 3030 | cancel_delayed_work(&hdev->le_scan_disable); |
| 2851 | − hci_req_add_le_scan_disable(req); | |
| 3031 | + hci_req_add_le_scan_disable(req, false); | |
| 2852 | 3032 | } |
| 2853 | 3033 | |
| 2854 | 3034 | ret = true; |
| 2855 | 3035 | } else { |
| 2856 | 3036 | /* Passive scanning */ |
| 2857 | 3037 | if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { |
| 2858 | − hci_req_add_le_scan_disable(req); | |
| 3038 | + hci_req_add_le_scan_disable(req, false); | |
| 2859 | 3039 | ret = true; |
| 2860 | 3040 | } |
| 2861 | 3041 | } |
| @@ -65,11 +65,12 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable); · 64 unmodified lines | ||
| 65 | 65 | void __hci_req_update_name(struct hci_request *req); |
| 66 | 66 | void __hci_req_update_eir(struct hci_request *req); |
| 67 | 67 | |
| 68 | −void hci_req_add_le_scan_disable(struct hci_request *req); | |
| 68 | +void hci_req_add_le_scan_disable(struct hci_request *req, bool rpa_le_conn); | |
| 69 | 69 | void hci_req_add_le_passive_scan(struct hci_request *req); |
| 70 | 70 | |
| 71 | 71 | void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next); |
| 72 | 72 | |
| 73 | +void hci_req_disable_address_resolution(struct hci_dev *hdev); | |
| 73 | 74 | void hci_req_reenable_advertising(struct hci_dev *hdev); |
| 74 | 75 | void __hci_req_enable_advertising(struct hci_request *req); |
| 75 | 76 | void __hci_req_disable_advertising(struct hci_request *req); |
| @@ -86,6 +87,8 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, · 10 unmodified lines | ||
| 86 | 87 | int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance); |
| 87 | 88 | int __hci_req_start_ext_adv(struct hci_request *req, u8 instance); |
| 88 | 89 | int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance); |
| 90 | +int __hci_req_disable_ext_adv_instance(struct hci_request *req, u8 instance); | |
| 91 | +int __hci_req_remove_ext_adv_instance(struct hci_request *req, u8 instance); | |
| 89 | 92 | void __hci_req_clear_ext_adv_sets(struct hci_request *req); |
| 90 | 93 | int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, |
| 91 | 94 | bool use_rpa, struct adv_info *adv_instance, |
| @@ -52,7 +52,7 @@ struct hci_pinfo { · 51 unmodified lines | ||
| 52 | 52 | struct bt_sock bt; |
| 53 | 53 | struct hci_dev *hdev; |
| 54 | 54 | struct hci_filter filter; |
| 55 | − __u32 cmsg_mask; | |
| 55 | + __u8 cmsg_mask; | |
| 56 | 56 | unsigned short channel; |
| 57 | 57 | unsigned long flags; |
| 58 | 58 | __u32 cookie; |
| @@ -443,8 +443,7 @@ static struct sk_buff *create_monitor_event(struct hci_dev *hdev, int event) · 384 unmodified lines | ||
| 443 | 443 | case HCI_DEV_SETUP: |
| 444 | 444 | if (hdev->manufacturer == 0xffff) |
| 445 | 445 | return NULL; |
| 446 | − | |
| 447 | − /* fall through */ | |
| 446 | + fallthrough; | |
| 448 | 447 | |
| 449 | 448 | case HCI_DEV_UP: |
| 450 | 449 | skb = bt_skb_alloc(HCI_MON_INDEX_INFO_SIZE, GFP_ATOMIC); |
| @@ -1399,7 +1398,7 @@ done: · 948 unmodified lines | ||
| 1399 | 1398 | static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, |
| 1400 | 1399 | struct sk_buff *skb) |
| 1401 | 1400 | { |
| 1402 | − __u32 mask = hci_pi(sk)->cmsg_mask; | |
| 1401 | + __u8 mask = hci_pi(sk)->cmsg_mask; | |
| 1403 | 1402 | |
| 1404 | 1403 | if (mask & HCI_CMSG_DIR) { |
| 1405 | 1404 | int incoming = bt_cb(skb)->incoming; |
| @@ -666,8 +666,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err) · 665 unmodified lines | ||
| 666 | 666 | |
| 667 | 667 | l2cap_seq_list_free(&chan->srej_list); |
| 668 | 668 | l2cap_seq_list_free(&chan->retrans_list); |
| 669 | − | |
| 670 | − /* fall through */ | |
| 669 | + fallthrough; | |
| 671 | 670 | |
| 672 | 671 | case L2CAP_MODE_STREAMING: |
| 673 | 672 | skb_queue_purge(&chan->tx_q); |
| @@ -872,7 +871,8 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) · 198 unmodified lines | ||
| 872 | 871 | else |
| 873 | 872 | return HCI_AT_NO_BONDING; |
| 874 | 873 | } |
| 875 | − /* fall through */ | |
| 874 | + fallthrough; | |
| 875 | + | |
| 876 | 876 | default: |
| 877 | 877 | switch (chan->sec_level) { |
| 878 | 878 | case BT_SECURITY_HIGH: |
| @@ -2983,8 +2983,7 @@ static void l2cap_tx_state_wait_f(struct l2cap_chan *chan, · 2104 unmodified lines | ||
| 2983 | 2983 | break; |
| 2984 | 2984 | case L2CAP_EV_RECV_REQSEQ_AND_FBIT: |
| 2985 | 2985 | l2cap_process_reqseq(chan, control->reqseq); |
| 2986 | − | |
| 2987 | − /* Fall through */ | |
| 2986 | + fallthrough; | |
| 2988 | 2987 | |
| 2989 | 2988 | case L2CAP_EV_RECV_FBIT: |
| 2990 | 2989 | if (control && control->final) { |
| @@ -3311,7 +3310,7 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask) · 320 unmodified lines | ||
| 3311 | 3310 | case L2CAP_MODE_ERTM: |
| 3312 | 3311 | if (l2cap_mode_supported(mode, remote_feat_mask)) |
| 3313 | 3312 | return mode; |
| 3314 | − /* fall through */ | |
| 3313 | + fallthrough; | |
| 3315 | 3314 | default: |
| 3316 | 3315 | return L2CAP_MODE_BASIC; |
| 3317 | 3316 | } |
| @@ -3447,7 +3446,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data, size_t data · 129 unmodified lines | ||
| 3447 | 3446 | if (__l2cap_efs_supported(chan->conn)) |
| 3448 | 3447 | set_bit(FLAG_EFS_ENABLE, &chan->flags); |
| 3449 | 3448 | |
| 3450 | − /* fall through */ | |
| 3449 | + fallthrough; | |
| 3451 | 3450 | default: |
| 3452 | 3451 | chan->mode = l2cap_select_mode(rfc.mode, chan->conn->feat_mask); |
| 3453 | 3452 | break; |
| @@ -4539,7 +4538,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, · 1085 unmodified lines | ||
| 4539 | 4538 | goto done; |
| 4540 | 4539 | break; |
| 4541 | 4540 | } |
| 4542 | − /* fall through */ | |
| 4541 | + fallthrough; | |
| 4543 | 4542 | |
| 4544 | 4543 | default: |
| 4545 | 4544 | l2cap_chan_set_err(chan, ECONNRESET); |
| @@ -7719,7 +7718,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) · 3173 unmodified lines | ||
| 7719 | 7718 | conn->mtu = hcon->hdev->le_mtu; |
| 7720 | 7719 | break; |
| 7721 | 7720 | } |
| 7722 | − /* fall through */ | |
| 7721 | + fallthrough; | |
| 7723 | 7722 | default: |
| 7724 | 7723 | conn->mtu = hcon->hdev->acl_mtu; |
| 7725 | 7724 | break; |
| @@ -7841,7 +7840,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, · 115 unmodified lines | ||
| 7841 | 7840 | case L2CAP_MODE_STREAMING: |
| 7842 | 7841 | if (!disable_ertm) |
| 7843 | 7842 | break; |
| 7844 | − /* fall through */ | |
| 7843 | + fallthrough; | |
| 7845 | 7844 | default: |
| 7846 | 7845 | err = -EOPNOTSUPP; |
| 7847 | 7846 | goto done; |
| @@ -7893,11 +7892,13 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, · 45 unmodified lines | ||
| 7893 | 7892 | else |
| 7894 | 7893 | hcon = hci_connect_le_scan(hdev, dst, dst_type, |
| 7895 | 7894 | chan->sec_level, |
| 7896 | − HCI_LE_CONN_TIMEOUT); | |
| 7895 | + HCI_LE_CONN_TIMEOUT, | |
| 7896 | + CONN_REASON_L2CAP_CHAN); | |
| 7897 | 7897 | |
| 7898 | 7898 | } else { |
| 7899 | 7899 | u8 auth_type = l2cap_get_auth_type(chan); |
| 7900 | − hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type); | |
| 7900 | + hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type, | |
| 7901 | + CONN_REASON_L2CAP_CHAN); | |
| 7901 | 7902 | } |
| 7902 | 7903 | |
| 7903 | 7904 | if (IS_ERR(hcon)) { |
| @@ -284,7 +284,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog) · 283 unmodified lines | ||
| 284 | 284 | case L2CAP_MODE_STREAMING: |
| 285 | 285 | if (!disable_ertm) |
| 286 | 286 | break; |
| 287 | − /* fall through */ | |
| 287 | + fallthrough; | |
| 288 | 288 | default: |
| 289 | 289 | err = -EOPNOTSUPP; |
| 290 | 290 | goto done; |
| @@ -760,7 +760,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, · 469 unmodified lines | ||
| 760 | 760 | case L2CAP_MODE_STREAMING: |
| 761 | 761 | if (!disable_ertm) |
| 762 | 762 | break; |
| 763 | − /* fall through */ | |
| 763 | + fallthrough; | |
| 764 | 764 | default: |
| 765 | 765 | err = -EINVAL; |
| 766 | 766 | break; |
| @@ -36,9 +36,11 @@ · 35 unmodified lines | ||
| 36 | 36 | #include "hci_request.h" |
| 37 | 37 | #include "smp.h" |
| 38 | 38 | #include "mgmt_util.h" |
| 39 | +#include "mgmt_config.h" | |
| 40 | +#include "msft.h" | |
| 39 | 41 | |
| 40 | 42 | #define MGMT_VERSION 1 |
| 41 | −#define MGMT_REVISION 17 | |
| 43 | +#define MGMT_REVISION 18 | |
| 42 | 44 | |
| 43 | 45 | static const u16 mgmt_commands[] = { |
| 44 | 46 | MGMT_OP_READ_INDEX_LIST, |
| @@ -111,6 +113,15 @@ static const u16 mgmt_commands[] = { · 66 unmodified lines | ||
| 111 | 113 | MGMT_OP_READ_SECURITY_INFO, |
| 112 | 114 | MGMT_OP_READ_EXP_FEATURES_INFO, |
| 113 | 115 | MGMT_OP_SET_EXP_FEATURE, |
| 116 | + MGMT_OP_READ_DEF_SYSTEM_CONFIG, | |
| 117 | + MGMT_OP_SET_DEF_SYSTEM_CONFIG, | |
| 118 | + MGMT_OP_READ_DEF_RUNTIME_CONFIG, | |
| 119 | + MGMT_OP_SET_DEF_RUNTIME_CONFIG, | |
| 120 | + MGMT_OP_GET_DEVICE_FLAGS, | |
| 121 | + MGMT_OP_SET_DEVICE_FLAGS, | |
| 122 | + MGMT_OP_READ_ADV_MONITOR_FEATURES, | |
| 123 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 124 | + MGMT_OP_REMOVE_ADV_MONITOR, | |
| 114 | 125 | }; |
| 115 | 126 | |
| 116 | 127 | static const u16 mgmt_events[] = { |
| @@ -151,6 +162,7 @@ static const u16 mgmt_events[] = { · 34 unmodified lines | ||
| 151 | 162 | MGMT_EV_EXT_INFO_CHANGED, |
| 152 | 163 | MGMT_EV_PHY_CONFIGURATION_CHANGED, |
| 153 | 164 | MGMT_EV_EXP_FEATURE_CHANGED, |
| 165 | + MGMT_EV_DEVICE_FLAGS_CHANGED, | |
| 154 | 166 | }; |
| 155 | 167 | |
| 156 | 168 | static const u16 mgmt_untrusted_commands[] = { |
| @@ -162,6 +174,8 @@ static const u16 mgmt_untrusted_commands[] = { · 5 unmodified lines | ||
| 162 | 174 | MGMT_OP_READ_EXT_INFO, |
| 163 | 175 | MGMT_OP_READ_SECURITY_INFO, |
| 164 | 176 | MGMT_OP_READ_EXP_FEATURES_INFO, |
| 177 | + MGMT_OP_READ_DEF_SYSTEM_CONFIG, | |
| 178 | + MGMT_OP_READ_DEF_RUNTIME_CONFIG, | |
| 165 | 179 | }; |
| 166 | 180 | |
| 167 | 181 | static const u16 mgmt_untrusted_events[] = { |
| @@ -177,6 +191,8 @@ static const u16 mgmt_untrusted_events[] = { · 9 unmodified lines | ||
| 177 | 191 | MGMT_EV_EXT_INDEX_REMOVED, |
| 178 | 192 | MGMT_EV_EXT_INFO_CHANGED, |
| 179 | 193 | MGMT_EV_EXP_FEATURE_CHANGED, |
| 194 | + MGMT_EV_ADV_MONITOR_ADDED, | |
| 195 | + MGMT_EV_ADV_MONITOR_REMOVED, | |
| 180 | 196 | }; |
| 181 | 197 | |
| 182 | 198 | #define CACHE_TIMEOUT msecs_to_jiffies(2 * 1000) |
| @@ -779,10 +795,15 @@ static u32 get_supported_settings(struct hci_dev *hdev) · 596 unmodified lines | ||
| 779 | 795 | |
| 780 | 796 | if (lmp_le_capable(hdev)) { |
| 781 | 797 | settings |= MGMT_SETTING_LE; |
| 782 | − settings |= MGMT_SETTING_ADVERTISING; | |
| 783 | 798 | settings |= MGMT_SETTING_SECURE_CONN; |
| 784 | 799 | settings |= MGMT_SETTING_PRIVACY; |
| 785 | 800 | settings |= MGMT_SETTING_STATIC_ADDRESS; |
| 801 | + | |
| 802 | + /* When the experimental feature for LL Privacy support is | |
| 803 | + * enabled, then advertising is no longer supported. | |
| 804 | + */ | |
| 805 | + if (!hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 806 | + settings |= MGMT_SETTING_ADVERTISING; | |
| 786 | 807 | } |
| 787 | 808 | |
| 788 | 809 | if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || |
| @@ -2915,7 +2936,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, · 2126 unmodified lines | ||
| 2915 | 2936 | |
| 2916 | 2937 | if (cp->addr.type == BDADDR_BREDR) { |
| 2917 | 2938 | conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, |
| 2918 | − auth_type); | |
| 2939 | + auth_type, CONN_REASON_PAIR_DEVICE); | |
| 2919 | 2940 | } else { |
| 2920 | 2941 | u8 addr_type = le_addr_type(cp->addr.type); |
| 2921 | 2942 | struct hci_conn_params *p; |
| @@ -2934,9 +2955,9 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, · 12 unmodified lines | ||
| 2934 | 2955 | if (p->auto_connect == HCI_AUTO_CONN_EXPLICIT) |
| 2935 | 2956 | p->auto_connect = HCI_AUTO_CONN_DISABLED; |
| 2936 | 2957 | |
| 2937 | − conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, | |
| 2938 | − addr_type, sec_level, | |
| 2939 | − HCI_LE_CONN_TIMEOUT); | |
| 2958 | + conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, | |
| 2959 | + sec_level, HCI_LE_CONN_TIMEOUT, | |
| 2960 | + CONN_REASON_PAIR_DEVICE); | |
| 2940 | 2961 | } |
| 2941 | 2962 | |
| 2942 | 2963 | if (IS_ERR(conn)) { |
| @@ -3037,6 +3058,20 @@ static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, · 94 unmodified lines | ||
| 3037 | 3058 | |
| 3038 | 3059 | err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, |
| 3039 | 3060 | addr, sizeof(*addr)); |
| 3061 | + | |
| 3062 | + /* Since user doesn't want to proceed with the connection, abort any | |
| 3063 | + * ongoing pairing and then terminate the link if it was created | |
| 3064 | + * because of the pair device action. | |
| 3065 | + */ | |
| 3066 | + if (addr->type == BDADDR_BREDR) | |
| 3067 | + hci_remove_link_key(hdev, &addr->bdaddr); | |
| 3068 | + else | |
| 3069 | + smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, | |
| 3070 | + le_addr_type(addr->type)); | |
| 3071 | + | |
| 3072 | + if (conn->conn_reason == CONN_REASON_PAIR_DEVICE) | |
| 3073 | + hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM); | |
| 3074 | + | |
| 3040 | 3075 | unlock: |
| 3041 | 3076 | hci_dev_unlock(hdev); |
| 3042 | 3077 | return err; |
| @@ -3723,12 +3758,25 @@ static const u8 debug_uuid[16] = { · 680 unmodified lines | ||
| 3723 | 3758 | }; |
| 3724 | 3759 | #endif |
| 3725 | 3760 | |
| 3761 | +/* 671b10b5-42c0-4696-9227-eb28d1b049d6 */ | |
| 3762 | +static const u8 simult_central_periph_uuid[16] = { | |
| 3763 | + 0xd6, 0x49, 0xb0, 0xd1, 0x28, 0xeb, 0x27, 0x92, | |
| 3764 | + 0x96, 0x46, 0xc0, 0x42, 0xb5, 0x10, 0x1b, 0x67, | |
| 3765 | +}; | |
| 3766 | + | |
| 3767 | +/* 15c0a148-c273-11ea-b3de-0242ac130004 */ | |
| 3768 | +static const u8 rpa_resolution_uuid[16] = { | |
| 3769 | + 0x04, 0x00, 0x13, 0xac, 0x42, 0x02, 0xde, 0xb3, | |
| 3770 | + 0xea, 0x11, 0x73, 0xc2, 0x48, 0xa1, 0xc0, 0x15, | |
| 3771 | +}; | |
| 3772 | + | |
| 3726 | 3773 | static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, |
| 3727 | 3774 | void *data, u16 data_len) |
| 3728 | 3775 | { |
| 3729 | − char buf[42]; | |
| 3776 | + char buf[62]; /* Enough space for 3 features */ | |
| 3730 | 3777 | struct mgmt_rp_read_exp_features_info *rp = (void *)buf; |
| 3731 | 3778 | u16 idx = 0; |
| 3779 | + u32 flags; | |
| 3732 | 3780 | |
| 3733 | 3781 | bt_dev_dbg(hdev, "sock %p", sk); |
| 3734 | 3782 | |
| @@ -3736,7 +3784,7 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · 1 unmodified line | ||
| 3736 | 3784 | |
| 3737 | 3785 | #ifdef CONFIG_BT_FEATURE_DEBUG |
| 3738 | 3786 | if (!hdev) { |
| 3739 | − u32 flags = bt_dbg_get() ? BIT(0) : 0; | |
| 3787 | + flags = bt_dbg_get() ? BIT(0) : 0; | |
| 3740 | 3788 | |
| 3741 | 3789 | memcpy(rp->features[idx].uuid, debug_uuid, 16); |
| 3742 | 3790 | rp->features[idx].flags = cpu_to_le32(flags); |
| @@ -3744,6 +3792,31 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · 1 unmodified line | ||
| 3744 | 3792 | } |
| 3745 | 3793 | #endif |
| 3746 | 3794 | |
| 3795 | + if (hdev) { | |
| 3796 | + if (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && | |
| 3797 | + (hdev->le_states[4] & 0x08) && /* Central */ | |
| 3798 | + (hdev->le_states[4] & 0x40) && /* Peripheral */ | |
| 3799 | + (hdev->le_states[3] & 0x10)) /* Simultaneous */ | |
| 3800 | + flags = BIT(0); | |
| 3801 | + else | |
| 3802 | + flags = 0; | |
| 3803 | + | |
| 3804 | + memcpy(rp->features[idx].uuid, simult_central_periph_uuid, 16); | |
| 3805 | + rp->features[idx].flags = cpu_to_le32(flags); | |
| 3806 | + idx++; | |
| 3807 | + } | |
| 3808 | + | |
| 3809 | + if (hdev && use_ll_privacy(hdev)) { | |
| 3810 | + if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 3811 | + flags = BIT(0) | BIT(1); | |
| 3812 | + else | |
| 3813 | + flags = BIT(1); | |
| 3814 | + | |
| 3815 | + memcpy(rp->features[idx].uuid, rpa_resolution_uuid, 16); | |
| 3816 | + rp->features[idx].flags = cpu_to_le32(flags); | |
| 3817 | + idx++; | |
| 3818 | + } | |
| 3819 | + | |
| 3747 | 3820 | rp->feature_count = cpu_to_le16(idx); |
| 3748 | 3821 | |
| 3749 | 3822 | /* After reading the experimental features information, enable |
| @@ -3756,6 +3829,21 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · 6 unmodified lines | ||
| 3756 | 3829 | 0, rp, sizeof(*rp) + (20 * idx)); |
| 3757 | 3830 | } |
| 3758 | 3831 | |
| 3832 | +static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, | |
| 3833 | + struct sock *skip) | |
| 3834 | +{ | |
| 3835 | + struct mgmt_ev_exp_feature_changed ev; | |
| 3836 | + | |
| 3837 | + memset(&ev, 0, sizeof(ev)); | |
| 3838 | + memcpy(ev.uuid, rpa_resolution_uuid, 16); | |
| 3839 | + ev.flags = cpu_to_le32((enabled ? BIT(0) : 0) | BIT(1)); | |
| 3840 | + | |
| 3841 | + return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, | |
| 3842 | + &ev, sizeof(ev), | |
| 3843 | + HCI_MGMT_EXP_FEATURE_EVENTS, skip); | |
| 3844 | + | |
| 3845 | +} | |
| 3846 | + | |
| 3759 | 3847 | #ifdef CONFIG_BT_FEATURE_DEBUG |
| 3760 | 3848 | static int exp_debug_feature_changed(bool enabled, struct sock *skip) |
| 3761 | 3849 | { |
| @@ -3794,6 +3882,16 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · 32 unmodified lines | ||
| 3794 | 3882 | } |
| 3795 | 3883 | #endif |
| 3796 | 3884 | |
| 3885 | + if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { | |
| 3886 | + bool changed = hci_dev_test_flag(hdev, | |
| 3887 | + HCI_ENABLE_LL_PRIVACY); | |
| 3888 | + | |
| 3889 | + hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); | |
| 3890 | + | |
| 3891 | + if (changed) | |
| 3892 | + exp_ll_privacy_feature_changed(false, hdev, sk); | |
| 3893 | + } | |
| 3894 | + | |
| 3797 | 3895 | hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS); |
| 3798 | 3896 | |
| 3799 | 3897 | return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, |
| @@ -3844,11 +3942,401 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · 44 unmodified lines | ||
| 3844 | 3942 | } |
| 3845 | 3943 | #endif |
| 3846 | 3944 | |
| 3945 | + if (!memcmp(cp->uuid, rpa_resolution_uuid, 16)) { | |
| 3946 | + bool val, changed; | |
| 3947 | + int err; | |
| 3948 | + u32 flags; | |
| 3949 | + | |
| 3950 | + /* Command requires to use the controller index */ | |
| 3951 | + if (!hdev) | |
| 3952 | + return mgmt_cmd_status(sk, MGMT_INDEX_NONE, | |
| 3953 | + MGMT_OP_SET_EXP_FEATURE, | |
| 3954 | + MGMT_STATUS_INVALID_INDEX); | |
| 3955 | + | |
| 3956 | + /* Changes can only be made when controller is powered down */ | |
| 3957 | + if (hdev_is_powered(hdev)) | |
| 3958 | + return mgmt_cmd_status(sk, hdev->id, | |
| 3959 | + MGMT_OP_SET_EXP_FEATURE, | |
| 3960 | + MGMT_STATUS_NOT_POWERED); | |
| 3961 | + | |
| 3962 | + /* Parameters are limited to a single octet */ | |
| 3963 | + if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1) | |
| 3964 | + return mgmt_cmd_status(sk, hdev->id, | |
| 3965 | + MGMT_OP_SET_EXP_FEATURE, | |
| 3966 | + MGMT_STATUS_INVALID_PARAMS); | |
| 3967 | + | |
| 3968 | + /* Only boolean on/off is supported */ | |
| 3969 | + if (cp->param[0] != 0x00 && cp->param[0] != 0x01) | |
| 3970 | + return mgmt_cmd_status(sk, hdev->id, | |
| 3971 | + MGMT_OP_SET_EXP_FEATURE, | |
| 3972 | + MGMT_STATUS_INVALID_PARAMS); | |
| 3973 | + | |
| 3974 | + val = !!cp->param[0]; | |
| 3975 | + | |
| 3976 | + if (val) { | |
| 3977 | + changed = !hci_dev_test_flag(hdev, | |
| 3978 | + HCI_ENABLE_LL_PRIVACY); | |
| 3979 | + hci_dev_set_flag(hdev, HCI_ENABLE_LL_PRIVACY); | |
| 3980 | + hci_dev_clear_flag(hdev, HCI_ADVERTISING); | |
| 3981 | + | |
| 3982 | + /* Enable LL privacy + supported settings changed */ | |
| 3983 | + flags = BIT(0) | BIT(1); | |
| 3984 | + } else { | |
| 3985 | + changed = hci_dev_test_flag(hdev, | |
| 3986 | + HCI_ENABLE_LL_PRIVACY); | |
| 3987 | + hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); | |
| 3988 | + | |
| 3989 | + /* Disable LL privacy + supported settings changed */ | |
| 3990 | + flags = BIT(1); | |
| 3991 | + } | |
| 3992 | + | |
| 3993 | + memcpy(rp.uuid, rpa_resolution_uuid, 16); | |
| 3994 | + rp.flags = cpu_to_le32(flags); | |
| 3995 | + | |
| 3996 | + hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS); | |
| 3997 | + | |
| 3998 | + err = mgmt_cmd_complete(sk, hdev->id, | |
| 3999 | + MGMT_OP_SET_EXP_FEATURE, 0, | |
| 4000 | + &rp, sizeof(rp)); | |
| 4001 | + | |
| 4002 | + if (changed) | |
| 4003 | + exp_ll_privacy_feature_changed(val, hdev, sk); | |
| 4004 | + | |
| 4005 | + return err; | |
| 4006 | + } | |
| 4007 | + | |
| 3847 | 4008 | return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, |
| 3848 | 4009 | MGMT_OP_SET_EXP_FEATURE, |
| 3849 | 4010 | MGMT_STATUS_NOT_SUPPORTED); |
| 3850 | 4011 | } |
| 3851 | 4012 | |
| 4013 | +#define SUPPORTED_DEVICE_FLAGS() ((1U << HCI_CONN_FLAG_MAX) - 1) | |
| 4014 | + | |
| 4015 | +static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 4016 | + u16 data_len) | |
| 4017 | +{ | |
| 4018 | + struct mgmt_cp_get_device_flags *cp = data; | |
| 4019 | + struct mgmt_rp_get_device_flags rp; | |
| 4020 | + struct bdaddr_list_with_flags *br_params; | |
| 4021 | + struct hci_conn_params *params; | |
| 4022 | + u32 supported_flags = SUPPORTED_DEVICE_FLAGS(); | |
| 4023 | + u32 current_flags = 0; | |
| 4024 | + u8 status = MGMT_STATUS_INVALID_PARAMS; | |
| 4025 | + | |
| 4026 | + bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", | |
| 4027 | + &cp->addr.bdaddr, cp->addr.type); | |
| 4028 | + | |
| 4029 | + hci_dev_lock(hdev); | |
| 4030 | + | |
| 4031 | + if (cp->addr.type == BDADDR_BREDR) { | |
| 4032 | + br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, | |
| 4033 | + &cp->addr.bdaddr, | |
| 4034 | + cp->addr.type); | |
| 4035 | + if (!br_params) | |
| 4036 | + goto done; | |
| 4037 | + | |
| 4038 | + current_flags = br_params->current_flags; | |
| 4039 | + } else { | |
| 4040 | + params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, | |
| 4041 | + le_addr_type(cp->addr.type)); | |
| 4042 | + | |
| 4043 | + if (!params) | |
| 4044 | + goto done; | |
| 4045 | + | |
| 4046 | + current_flags = params->current_flags; | |
| 4047 | + } | |
| 4048 | + | |
| 4049 | + bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr); | |
| 4050 | + rp.addr.type = cp->addr.type; | |
| 4051 | + rp.supported_flags = cpu_to_le32(supported_flags); | |
| 4052 | + rp.current_flags = cpu_to_le32(current_flags); | |
| 4053 | + | |
| 4054 | + status = MGMT_STATUS_SUCCESS; | |
| 4055 | + | |
| 4056 | +done: | |
| 4057 | + hci_dev_unlock(hdev); | |
| 4058 | + | |
| 4059 | + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, | |
| 4060 | + &rp, sizeof(rp)); | |
| 4061 | +} | |
| 4062 | + | |
| 4063 | +static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, | |
| 4064 | + bdaddr_t *bdaddr, u8 bdaddr_type, | |
| 4065 | + u32 supported_flags, u32 current_flags) | |
| 4066 | +{ | |
| 4067 | + struct mgmt_ev_device_flags_changed ev; | |
| 4068 | + | |
| 4069 | + bacpy(&ev.addr.bdaddr, bdaddr); | |
| 4070 | + ev.addr.type = bdaddr_type; | |
| 4071 | + ev.supported_flags = cpu_to_le32(supported_flags); | |
| 4072 | + ev.current_flags = cpu_to_le32(current_flags); | |
| 4073 | + | |
| 4074 | + mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); | |
| 4075 | +} | |
| 4076 | + | |
| 4077 | +static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 4078 | + u16 len) | |
| 4079 | +{ | |
| 4080 | + struct mgmt_cp_set_device_flags *cp = data; | |
| 4081 | + struct bdaddr_list_with_flags *br_params; | |
| 4082 | + struct hci_conn_params *params; | |
| 4083 | + u8 status = MGMT_STATUS_INVALID_PARAMS; | |
| 4084 | + u32 supported_flags = SUPPORTED_DEVICE_FLAGS(); | |
| 4085 | + u32 current_flags = __le32_to_cpu(cp->current_flags); | |
| 4086 | + | |
| 4087 | + bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", | |
| 4088 | + &cp->addr.bdaddr, cp->addr.type, | |
| 4089 | + __le32_to_cpu(current_flags)); | |
| 4090 | + | |
| 4091 | + if ((supported_flags | current_flags) != supported_flags) { | |
| 4092 | + bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", | |
| 4093 | + current_flags, supported_flags); | |
| 4094 | + goto done; | |
| 4095 | + } | |
| 4096 | + | |
| 4097 | + hci_dev_lock(hdev); | |
| 4098 | + | |
| 4099 | + if (cp->addr.type == BDADDR_BREDR) { | |
| 4100 | + br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, | |
| 4101 | + &cp->addr.bdaddr, | |
| 4102 | + cp->addr.type); | |
| 4103 | + | |
| 4104 | + if (br_params) { | |
| 4105 | + br_params->current_flags = current_flags; | |
| 4106 | + status = MGMT_STATUS_SUCCESS; | |
| 4107 | + } else { | |
| 4108 | + bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", | |
| 4109 | + &cp->addr.bdaddr, cp->addr.type); | |
| 4110 | + } | |
| 4111 | + } else { | |
| 4112 | + params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, | |
| 4113 | + le_addr_type(cp->addr.type)); | |
| 4114 | + if (params) { | |
| 4115 | + params->current_flags = current_flags; | |
| 4116 | + status = MGMT_STATUS_SUCCESS; | |
| 4117 | + } else { | |
| 4118 | + bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", | |
| 4119 | + &cp->addr.bdaddr, | |
| 4120 | + le_addr_type(cp->addr.type)); | |
| 4121 | + } | |
| 4122 | + } | |
| 4123 | + | |
| 4124 | +done: | |
| 4125 | + hci_dev_unlock(hdev); | |
| 4126 | + | |
| 4127 | + if (status == MGMT_STATUS_SUCCESS) | |
| 4128 | + device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, | |
| 4129 | + supported_flags, current_flags); | |
| 4130 | + | |
| 4131 | + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, | |
| 4132 | + &cp->addr, sizeof(cp->addr)); | |
| 4133 | +} | |
| 4134 | + | |
| 4135 | +static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, | |
| 4136 | + u16 handle) | |
| 4137 | +{ | |
| 4138 | + struct mgmt_ev_adv_monitor_added ev; | |
| 4139 | + | |
| 4140 | + ev.monitor_handle = cpu_to_le16(handle); | |
| 4141 | + | |
| 4142 | + mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); | |
| 4143 | +} | |
| 4144 | + | |
| 4145 | +static void mgmt_adv_monitor_removed(struct sock *sk, struct hci_dev *hdev, | |
| 4146 | + u16 handle) | |
| 4147 | +{ | |
| 4148 | + struct mgmt_ev_adv_monitor_added ev; | |
| 4149 | + | |
| 4150 | + ev.monitor_handle = cpu_to_le16(handle); | |
| 4151 | + | |
| 4152 | + mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk); | |
| 4153 | +} | |
| 4154 | + | |
| 4155 | +static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, | |
| 4156 | + void *data, u16 len) | |
| 4157 | +{ | |
| 4158 | + struct adv_monitor *monitor = NULL; | |
| 4159 | + struct mgmt_rp_read_adv_monitor_features *rp = NULL; | |
| 4160 | + int handle; | |
| 4161 | + size_t rp_size = 0; | |
| 4162 | + __u32 supported = 0; | |
| 4163 | + __u16 num_handles = 0; | |
| 4164 | + __u16 handles[HCI_MAX_ADV_MONITOR_NUM_HANDLES]; | |
| 4165 | + | |
| 4166 | + BT_DBG("request for %s", hdev->name); | |
| 4167 | + | |
| 4168 | + hci_dev_lock(hdev); | |
| 4169 | + | |
| 4170 | + if (msft_get_features(hdev) & MSFT_FEATURE_MASK_LE_ADV_MONITOR) | |
| 4171 | + supported |= MGMT_ADV_MONITOR_FEATURE_MASK_OR_PATTERNS; | |
| 4172 | + | |
| 4173 | + idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) { | |
| 4174 | + handles[num_handles++] = monitor->handle; | |
| 4175 | + } | |
| 4176 | + | |
| 4177 | + hci_dev_unlock(hdev); | |
| 4178 | + | |
| 4179 | + rp_size = sizeof(*rp) + (num_handles * sizeof(u16)); | |
| 4180 | + rp = kmalloc(rp_size, GFP_KERNEL); | |
| 4181 | + if (!rp) | |
| 4182 | + return -ENOMEM; | |
| 4183 | + | |
| 4184 | + /* Once controller-based monitoring is in place, the enabled_features | |
| 4185 | + * should reflect the use. | |
| 4186 | + */ | |
| 4187 | + rp->supported_features = cpu_to_le32(supported); | |
| 4188 | + rp->enabled_features = 0; | |
| 4189 | + rp->max_num_handles = cpu_to_le16(HCI_MAX_ADV_MONITOR_NUM_HANDLES); | |
| 4190 | + rp->max_num_patterns = HCI_MAX_ADV_MONITOR_NUM_PATTERNS; | |
| 4191 | + rp->num_handles = cpu_to_le16(num_handles); | |
| 4192 | + if (num_handles) | |
| 4193 | + memcpy(&rp->handles, &handles, (num_handles * sizeof(u16))); | |
| 4194 | + | |
| 4195 | + return mgmt_cmd_complete(sk, hdev->id, | |
| 4196 | + MGMT_OP_READ_ADV_MONITOR_FEATURES, | |
| 4197 | + MGMT_STATUS_SUCCESS, rp, rp_size); | |
| 4198 | +} | |
| 4199 | + | |
| 4200 | +static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, | |
| 4201 | + void *data, u16 len) | |
| 4202 | +{ | |
| 4203 | + struct mgmt_cp_add_adv_patterns_monitor *cp = data; | |
| 4204 | + struct mgmt_rp_add_adv_patterns_monitor rp; | |
| 4205 | + struct adv_monitor *m = NULL; | |
| 4206 | + struct adv_pattern *p = NULL; | |
| 4207 | + unsigned int mp_cnt = 0, prev_adv_monitors_cnt; | |
| 4208 | + __u8 cp_ofst = 0, cp_len = 0; | |
| 4209 | + int err, i; | |
| 4210 | + | |
| 4211 | + BT_DBG("request for %s", hdev->name); | |
| 4212 | + | |
| 4213 | + if (len <= sizeof(*cp) || cp->pattern_count == 0) { | |
| 4214 | + err = mgmt_cmd_status(sk, hdev->id, | |
| 4215 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4216 | + MGMT_STATUS_INVALID_PARAMS); | |
| 4217 | + goto failed; | |
| 4218 | + } | |
| 4219 | + | |
| 4220 | + m = kmalloc(sizeof(*m), GFP_KERNEL); | |
| 4221 | + if (!m) { | |
| 4222 | + err = -ENOMEM; | |
| 4223 | + goto failed; | |
| 4224 | + } | |
| 4225 | + | |
| 4226 | + INIT_LIST_HEAD(&m->patterns); | |
| 4227 | + m->active = false; | |
| 4228 | + | |
| 4229 | + for (i = 0; i < cp->pattern_count; i++) { | |
| 4230 | + if (++mp_cnt > HCI_MAX_ADV_MONITOR_NUM_PATTERNS) { | |
| 4231 | + err = mgmt_cmd_status(sk, hdev->id, | |
| 4232 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4233 | + MGMT_STATUS_INVALID_PARAMS); | |
| 4234 | + goto failed; | |
| 4235 | + } | |
| 4236 | + | |
| 4237 | + cp_ofst = cp->patterns[i].offset; | |
| 4238 | + cp_len = cp->patterns[i].length; | |
| 4239 | + if (cp_ofst >= HCI_MAX_AD_LENGTH || | |
| 4240 | + cp_len > HCI_MAX_AD_LENGTH || | |
| 4241 | + (cp_ofst + cp_len) > HCI_MAX_AD_LENGTH) { | |
| 4242 | + err = mgmt_cmd_status(sk, hdev->id, | |
| 4243 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4244 | + MGMT_STATUS_INVALID_PARAMS); | |
| 4245 | + goto failed; | |
| 4246 | + } | |
| 4247 | + | |
| 4248 | + p = kmalloc(sizeof(*p), GFP_KERNEL); | |
| 4249 | + if (!p) { | |
| 4250 | + err = -ENOMEM; | |
| 4251 | + goto failed; | |
| 4252 | + } | |
| 4253 | + | |
| 4254 | + p->ad_type = cp->patterns[i].ad_type; | |
| 4255 | + p->offset = cp->patterns[i].offset; | |
| 4256 | + p->length = cp->patterns[i].length; | |
| 4257 | + memcpy(p->value, cp->patterns[i].value, p->length); | |
| 4258 | + | |
| 4259 | + INIT_LIST_HEAD(&p->list); | |
| 4260 | + list_add(&p->list, &m->patterns); | |
| 4261 | + } | |
| 4262 | + | |
| 4263 | + if (mp_cnt != cp->pattern_count) { | |
| 4264 | + err = mgmt_cmd_status(sk, hdev->id, | |
| 4265 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4266 | + MGMT_STATUS_INVALID_PARAMS); | |
| 4267 | + goto failed; | |
| 4268 | + } | |
| 4269 | + | |
| 4270 | + hci_dev_lock(hdev); | |
| 4271 | + | |
| 4272 | + prev_adv_monitors_cnt = hdev->adv_monitors_cnt; | |
| 4273 | + | |
| 4274 | + err = hci_add_adv_monitor(hdev, m); | |
| 4275 | + if (err) { | |
| 4276 | + if (err == -ENOSPC) { | |
| 4277 | + mgmt_cmd_status(sk, hdev->id, | |
| 4278 | + MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4279 | + MGMT_STATUS_NO_RESOURCES); | |
| 4280 | + } | |
| 4281 | + goto unlock; | |
| 4282 | + } | |
| 4283 | + | |
| 4284 | + if (hdev->adv_monitors_cnt > prev_adv_monitors_cnt) | |
| 4285 | + mgmt_adv_monitor_added(sk, hdev, m->handle); | |
| 4286 | + | |
| 4287 | + hci_dev_unlock(hdev); | |
| 4288 | + | |
| 4289 | + rp.monitor_handle = cpu_to_le16(m->handle); | |
| 4290 | + | |
| 4291 | + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, | |
| 4292 | + MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); | |
| 4293 | + | |
| 4294 | +unlock: | |
| 4295 | + hci_dev_unlock(hdev); | |
| 4296 | + | |
| 4297 | +failed: | |
| 4298 | + hci_free_adv_monitor(m); | |
| 4299 | + return err; | |
| 4300 | +} | |
| 4301 | + | |
| 4302 | +static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, | |
| 4303 | + void *data, u16 len) | |
| 4304 | +{ | |
| 4305 | + struct mgmt_cp_remove_adv_monitor *cp = data; | |
| 4306 | + struct mgmt_rp_remove_adv_monitor rp; | |
| 4307 | + unsigned int prev_adv_monitors_cnt; | |
| 4308 | + u16 handle; | |
| 4309 | + int err; | |
| 4310 | + | |
| 4311 | + BT_DBG("request for %s", hdev->name); | |
| 4312 | + | |
| 4313 | + hci_dev_lock(hdev); | |
| 4314 | + | |
| 4315 | + handle = __le16_to_cpu(cp->monitor_handle); | |
| 4316 | + prev_adv_monitors_cnt = hdev->adv_monitors_cnt; | |
| 4317 | + | |
| 4318 | + err = hci_remove_adv_monitor(hdev, handle); | |
| 4319 | + if (err == -ENOENT) { | |
| 4320 | + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, | |
| 4321 | + MGMT_STATUS_INVALID_INDEX); | |
| 4322 | + goto unlock; | |
| 4323 | + } | |
| 4324 | + | |
| 4325 | + if (hdev->adv_monitors_cnt < prev_adv_monitors_cnt) | |
| 4326 | + mgmt_adv_monitor_removed(sk, hdev, handle); | |
| 4327 | + | |
| 4328 | + hci_dev_unlock(hdev); | |
| 4329 | + | |
| 4330 | + rp.monitor_handle = cp->monitor_handle; | |
| 4331 | + | |
| 4332 | + return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, | |
| 4333 | + MGMT_STATUS_SUCCESS, &rp, sizeof(rp)); | |
| 4334 | + | |
| 4335 | +unlock: | |
| 4336 | + hci_dev_unlock(hdev); | |
| 4337 | + return err; | |
| 4338 | +} | |
| 4339 | + | |
| 3852 | 4340 | static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status, |
| 3853 | 4341 | u16 opcode, struct sk_buff *skb) |
| 3854 | 4342 | { |
| @@ -4147,7 +4635,7 @@ static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, · 292 unmodified lines | ||
| 4147 | 4635 | *mgmt_status = mgmt_le_support(hdev); |
| 4148 | 4636 | if (*mgmt_status) |
| 4149 | 4637 | return false; |
| 4150 | − /* Intentional fall-through */ | |
| 4638 | + fallthrough; | |
| 4151 | 4639 | case DISCOV_TYPE_BREDR: |
| 4152 | 4640 | *mgmt_status = mgmt_bredr_support(hdev); |
| 4153 | 4641 | if (*mgmt_status) |
| @@ -4662,6 +5150,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, · 508 unmodified lines | ||
| 4662 | 5150 | return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, |
| 4663 | 5151 | status); |
| 4664 | 5152 | |
| 5153 | + /* Enabling the experimental LL Privay support disables support for | |
| 5154 | + * advertising. | |
| 5155 | + */ | |
| 5156 | + if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 5157 | + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, | |
| 5158 | + MGMT_STATUS_NOT_SUPPORTED); | |
| 5159 | + | |
| 4665 | 5160 | if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02) |
| 4666 | 5161 | return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, |
| 4667 | 5162 | MGMT_STATUS_INVALID_PARAMS); |
| @@ -4848,7 +5343,7 @@ static int set_scan_params(struct sock *sk, struct hci_dev *hdev, · 180 unmodified lines | ||
| 4848 | 5343 | |
| 4849 | 5344 | hci_req_init(&req, hdev); |
| 4850 | 5345 | |
| 4851 | − hci_req_add_le_scan_disable(&req); | |
| 5346 | + hci_req_add_le_scan_disable(&req, false); | |
| 4852 | 5347 | hci_req_add_le_passive_scan(&req); |
| 4853 | 5348 | |
| 4854 | 5349 | hci_req_run(&req, NULL); |
| @@ -5523,7 +6018,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, · 668 unmodified lines | ||
| 5523 | 6018 | case MGMT_LTK_P256_DEBUG: |
| 5524 | 6019 | authenticated = 0x00; |
| 5525 | 6020 | type = SMP_LTK_P256_DEBUG; |
| 5526 | − /* fall through */ | |
| 6021 | + fallthrough; | |
| 5527 | 6022 | default: |
| 5528 | 6023 | continue; |
| 5529 | 6024 | } |
| @@ -5966,7 +6461,9 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 436 unmodified lines | ||
| 5966 | 6461 | { |
| 5967 | 6462 | struct mgmt_cp_add_device *cp = data; |
| 5968 | 6463 | u8 auto_conn, addr_type; |
| 6464 | + struct hci_conn_params *params; | |
| 5969 | 6465 | int err; |
| 6466 | + u32 current_flags = 0; | |
| 5970 | 6467 | |
| 5971 | 6468 | bt_dev_dbg(hdev, "sock %p", sk); |
| 5972 | 6469 | |
| @@ -5993,8 +6490,9 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 20 unmodified lines | ||
| 5993 | 6490 | goto unlock; |
| 5994 | 6491 | } |
| 5995 | 6492 | |
| 5996 | − err = hci_bdaddr_list_add(&hdev->whitelist, &cp->addr.bdaddr, | |
| 5997 | − cp->addr.type); | |
| 6493 | + err = hci_bdaddr_list_add_with_flags(&hdev->whitelist, | |
| 6494 | + &cp->addr.bdaddr, | |
| 6495 | + cp->addr.type, 0); | |
| 5998 | 6496 | if (err) |
| 5999 | 6497 | goto unlock; |
| 6000 | 6498 | |
| @@ -6033,12 +6531,19 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 32 unmodified lines | ||
| 6033 | 6531 | MGMT_STATUS_FAILED, &cp->addr, |
| 6034 | 6532 | sizeof(cp->addr)); |
| 6035 | 6533 | goto unlock; |
| 6534 | + } else { | |
| 6535 | + params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, | |
| 6536 | + addr_type); | |
| 6537 | + if (params) | |
| 6538 | + current_flags = params->current_flags; | |
| 6036 | 6539 | } |
| 6037 | 6540 | |
| 6038 | 6541 | hci_update_background_scan(hdev); |
| 6039 | 6542 | |
| 6040 | 6543 | added: |
| 6041 | 6544 | device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); |
| 6545 | + device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, | |
| 6546 | + SUPPORTED_DEVICE_FLAGS(), current_flags); | |
| 6042 | 6547 | |
| 6043 | 6548 | err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, |
| 6044 | 6549 | MGMT_STATUS_SUCCESS, &cp->addr, |
| @@ -6724,6 +7229,13 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev, · 679 unmodified lines | ||
| 6724 | 7229 | return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, |
| 6725 | 7230 | MGMT_STATUS_REJECTED); |
| 6726 | 7231 | |
| 7232 | + /* Enabling the experimental LL Privay support disables support for | |
| 7233 | + * advertising. | |
| 7234 | + */ | |
| 7235 | + if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 7236 | + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, | |
| 7237 | + MGMT_STATUS_NOT_SUPPORTED); | |
| 7238 | + | |
| 6727 | 7239 | hci_dev_lock(hdev); |
| 6728 | 7240 | |
| 6729 | 7241 | rp_len = sizeof(*rp) + hdev->adv_instance_cnt; |
| @@ -6927,6 +7439,13 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, · 197 unmodified lines | ||
| 6927 | 7439 | return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, |
| 6928 | 7440 | status); |
| 6929 | 7441 | |
| 7442 | + /* Enabling the experimental LL Privay support disables support for | |
| 7443 | + * advertising. | |
| 7444 | + */ | |
| 7445 | + if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 7446 | + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, | |
| 7447 | + MGMT_STATUS_NOT_SUPPORTED); | |
| 7448 | + | |
| 6930 | 7449 | if (cp->instance < 1 || cp->instance > HCI_MAX_ADV_INSTANCES) |
| 6931 | 7450 | return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, |
| 6932 | 7451 | MGMT_STATUS_INVALID_PARAMS); |
| @@ -7091,6 +7610,13 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev, · 158 unmodified lines | ||
| 7091 | 7610 | |
| 7092 | 7611 | bt_dev_dbg(hdev, "sock %p", sk); |
| 7093 | 7612 | |
| 7613 | + /* Enabling the experimental LL Privay support disables support for | |
| 7614 | + * advertising. | |
| 7615 | + */ | |
| 7616 | + if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) | |
| 7617 | + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, | |
| 7618 | + MGMT_STATUS_NOT_SUPPORTED); | |
| 7619 | + | |
| 7094 | 7620 | hci_dev_lock(hdev); |
| 7095 | 7621 | |
| 7096 | 7622 | if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { |
| @@ -7116,6 +7642,12 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev, · 19 unmodified lines | ||
| 7116 | 7642 | |
| 7117 | 7643 | hci_req_init(&req, hdev); |
| 7118 | 7644 | |
| 7645 | + /* If we use extended advertising, instance is disabled and removed */ | |
| 7646 | + if (ext_adv_capable(hdev)) { | |
| 7647 | + __hci_req_disable_ext_adv_instance(&req, cp->instance); | |
| 7648 | + __hci_req_remove_ext_adv_instance(&req, cp->instance); | |
| 7649 | + } | |
| 7650 | + | |
| 7119 | 7651 | hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true); |
| 7120 | 7652 | |
| 7121 | 7653 | if (list_empty(&hdev->adv_instances)) |
| @@ -7297,6 +7829,20 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { · 175 unmodified lines | ||
| 7297 | 7829 | { set_exp_feature, MGMT_SET_EXP_FEATURE_SIZE, |
| 7298 | 7830 | HCI_MGMT_VAR_LEN | |
| 7299 | 7831 | HCI_MGMT_HDEV_OPTIONAL }, |
| 7832 | + { read_def_system_config, MGMT_READ_DEF_SYSTEM_CONFIG_SIZE, | |
| 7833 | + HCI_MGMT_UNTRUSTED }, | |
| 7834 | + { set_def_system_config, MGMT_SET_DEF_SYSTEM_CONFIG_SIZE, | |
| 7835 | + HCI_MGMT_VAR_LEN }, | |
| 7836 | + { read_def_runtime_config, MGMT_READ_DEF_RUNTIME_CONFIG_SIZE, | |
| 7837 | + HCI_MGMT_UNTRUSTED }, | |
| 7838 | + { set_def_runtime_config, MGMT_SET_DEF_RUNTIME_CONFIG_SIZE, | |
| 7839 | + HCI_MGMT_VAR_LEN }, | |
| 7840 | + { get_device_flags, MGMT_GET_DEVICE_FLAGS_SIZE }, | |
| 7841 | + { set_device_flags, MGMT_SET_DEVICE_FLAGS_SIZE }, | |
| 7842 | + { read_adv_mon_features, MGMT_READ_ADV_MONITOR_FEATURES_SIZE }, | |
| 7843 | + { add_adv_patterns_monitor,MGMT_ADD_ADV_PATTERNS_MONITOR_SIZE, | |
| 7844 | + HCI_MGMT_VAR_LEN }, | |
| 7845 | + { remove_adv_monitor, MGMT_REMOVE_ADV_MONITOR_SIZE }, | |
| 7300 | 7846 | }; |
| 7301 | 7847 | |
| 7302 | 7848 | void mgmt_index_added(struct hci_dev *hdev) |
| @@ -8216,8 +8762,11 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, · 913 unmodified lines | ||
| 8216 | 8762 | if (!hci_discovery_active(hdev)) { |
| 8217 | 8763 | if (link_type == ACL_LINK) |
| 8218 | 8764 | return; |
| 8219 | − if (link_type == LE_LINK && list_empty(&hdev->pend_le_reports)) | |
| 8765 | + if (link_type == LE_LINK && | |
| 8766 | + list_empty(&hdev->pend_le_reports) && | |
| 8767 | + !hci_is_adv_monitoring(hdev)) { | |
| 8220 | 8768 | return; |
| 8769 | + } | |
| 8221 | 8770 | } |
| 8222 | 8771 | |
| 8223 | 8772 | if (hdev->discovery.result_filtering) { |
| @@ -0,0 +1,283 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0-only | |
| 2 | + | |
| 3 | +/* | |
| 4 | + * Copyright (C) 2020 Google Corporation | |
| 5 | + */ | |
| 6 | + | |
| 7 | +#include <net/bluetooth/bluetooth.h> | |
| 8 | +#include <net/bluetooth/hci_core.h> | |
| 9 | +#include <net/bluetooth/mgmt.h> | |
| 10 | + | |
| 11 | +#include "mgmt_util.h" | |
| 12 | +#include "mgmt_config.h" | |
| 13 | + | |
| 14 | +#define HDEV_PARAM_U16(_param_code_, _param_name_) \ | |
| 15 | +{ \ | |
| 16 | + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ | |
| 17 | + { cpu_to_le16(hdev->_param_name_) } \ | |
| 18 | +} | |
| 19 | + | |
| 20 | +#define HDEV_PARAM_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \ | |
| 21 | +{ \ | |
| 22 | + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ | |
| 23 | + { cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) } \ | |
| 24 | +} | |
| 25 | + | |
| 26 | +int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 27 | + u16 data_len) | |
| 28 | +{ | |
| 29 | + struct { | |
| 30 | + struct mgmt_tlv entry; | |
| 31 | + union { | |
| 32 | + /* This is a simplification for now since all values | |
| 33 | + * are 16 bits. In the future, this code may need | |
| 34 | + * refactoring to account for variable length values | |
| 35 | + * and properly calculate the required buffer size. | |
| 36 | + */ | |
| 37 | + __le16 value; | |
| 38 | + }; | |
| 39 | + } __packed params[] = { | |
| 40 | + /* Please see mgmt-api.txt for documentation of these values */ | |
| 41 | + HDEV_PARAM_U16(0x0000, def_page_scan_type), | |
| 42 | + HDEV_PARAM_U16(0x0001, def_page_scan_int), | |
| 43 | + HDEV_PARAM_U16(0x0002, def_page_scan_window), | |
| 44 | + HDEV_PARAM_U16(0x0003, def_inq_scan_type), | |
| 45 | + HDEV_PARAM_U16(0x0004, def_inq_scan_int), | |
| 46 | + HDEV_PARAM_U16(0x0005, def_inq_scan_window), | |
| 47 | + HDEV_PARAM_U16(0x0006, def_br_lsto), | |
| 48 | + HDEV_PARAM_U16(0x0007, def_page_timeout), | |
| 49 | + HDEV_PARAM_U16(0x0008, sniff_min_interval), | |
| 50 | + HDEV_PARAM_U16(0x0009, sniff_max_interval), | |
| 51 | + HDEV_PARAM_U16(0x000a, le_adv_min_interval), | |
| 52 | + HDEV_PARAM_U16(0x000b, le_adv_max_interval), | |
| 53 | + HDEV_PARAM_U16(0x000c, def_multi_adv_rotation_duration), | |
| 54 | + HDEV_PARAM_U16(0x000d, le_scan_interval), | |
| 55 | + HDEV_PARAM_U16(0x000e, le_scan_window), | |
| 56 | + HDEV_PARAM_U16(0x000f, le_scan_int_suspend), | |
| 57 | + HDEV_PARAM_U16(0x0010, le_scan_window_suspend), | |
| 58 | + HDEV_PARAM_U16(0x0011, le_scan_int_discovery), | |
| 59 | + HDEV_PARAM_U16(0x0012, le_scan_window_discovery), | |
| 60 | + HDEV_PARAM_U16(0x0013, le_scan_int_adv_monitor), | |
| 61 | + HDEV_PARAM_U16(0x0014, le_scan_window_adv_monitor), | |
| 62 | + HDEV_PARAM_U16(0x0015, le_scan_int_connect), | |
| 63 | + HDEV_PARAM_U16(0x0016, le_scan_window_connect), | |
| 64 | + HDEV_PARAM_U16(0x0017, le_conn_min_interval), | |
| 65 | + HDEV_PARAM_U16(0x0018, le_conn_max_interval), | |
| 66 | + HDEV_PARAM_U16(0x0019, le_conn_latency), | |
| 67 | + HDEV_PARAM_U16(0x001a, le_supv_timeout), | |
| 68 | + HDEV_PARAM_U16_JIFFIES_TO_MSECS(0x001b, | |
| 69 | + def_le_autoconnect_timeout), | |
| 70 | + }; | |
| 71 | + struct mgmt_rp_read_def_system_config *rp = (void *)params; | |
| 72 | + | |
| 73 | + bt_dev_dbg(hdev, "sock %p", sk); | |
| 74 | + | |
| 75 | + return mgmt_cmd_complete(sk, hdev->id, | |
| 76 | + MGMT_OP_READ_DEF_SYSTEM_CONFIG, | |
| 77 | + 0, rp, sizeof(params)); | |
| 78 | +} | |
| 79 | + | |
| 80 | +#define TO_TLV(x) ((struct mgmt_tlv *)(x)) | |
| 81 | +#define TLV_GET_LE16(tlv) le16_to_cpu(*((__le16 *)(TO_TLV(tlv)->value))) | |
| 82 | + | |
| 83 | +int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 84 | + u16 data_len) | |
| 85 | +{ | |
| 86 | + u16 buffer_left = data_len; | |
| 87 | + u8 *buffer = data; | |
| 88 | + | |
| 89 | + if (buffer_left < sizeof(struct mgmt_tlv)) { | |
| 90 | + return mgmt_cmd_status(sk, hdev->id, | |
| 91 | + MGMT_OP_SET_DEF_SYSTEM_CONFIG, | |
| 92 | + MGMT_STATUS_INVALID_PARAMS); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /* First pass to validate the tlv */ | |
| 96 | + while (buffer_left >= sizeof(struct mgmt_tlv)) { | |
| 97 | + const u8 len = TO_TLV(buffer)->length; | |
| 98 | + const u16 exp_len = sizeof(struct mgmt_tlv) + | |
| 99 | + len; | |
| 100 | + const u16 type = le16_to_cpu(TO_TLV(buffer)->type); | |
| 101 | + | |
| 102 | + if (buffer_left < exp_len) { | |
| 103 | + bt_dev_warn(hdev, "invalid len left %d, exp >= %d", | |
| 104 | + buffer_left, exp_len); | |
| 105 | + | |
| 106 | + return mgmt_cmd_status(sk, hdev->id, | |
| 107 | + MGMT_OP_SET_DEF_SYSTEM_CONFIG, | |
| 108 | + MGMT_STATUS_INVALID_PARAMS); | |
| 109 | + } | |
| 110 | + | |
| 111 | + /* Please see mgmt-api.txt for documentation of these values */ | |
| 112 | + switch (type) { | |
| 113 | + case 0x0000: | |
| 114 | + case 0x0001: | |
| 115 | + case 0x0002: | |
| 116 | + case 0x0003: | |
| 117 | + case 0x0004: | |
| 118 | + case 0x0005: | |
| 119 | + case 0x0006: | |
| 120 | + case 0x0007: | |
| 121 | + case 0x0008: | |
| 122 | + case 0x0009: | |
| 123 | + case 0x000a: | |
| 124 | + case 0x000b: | |
| 125 | + case 0x000c: | |
| 126 | + case 0x000d: | |
| 127 | + case 0x000e: | |
| 128 | + case 0x000f: | |
| 129 | + case 0x0010: | |
| 130 | + case 0x0011: | |
| 131 | + case 0x0012: | |
| 132 | + case 0x0013: | |
| 133 | + case 0x0014: | |
| 134 | + case 0x0015: | |
| 135 | + case 0x0016: | |
| 136 | + case 0x0017: | |
| 137 | + case 0x0018: | |
| 138 | + case 0x0019: | |
| 139 | + case 0x001a: | |
| 140 | + case 0x001b: | |
| 141 | + if (len != sizeof(u16)) { | |
| 142 | + bt_dev_warn(hdev, "invalid length %d, exp %zu for type %d", | |
| 143 | + len, sizeof(u16), type); | |
| 144 | + | |
| 145 | + return mgmt_cmd_status(sk, hdev->id, | |
| 146 | + MGMT_OP_SET_DEF_SYSTEM_CONFIG, | |
| 147 | + MGMT_STATUS_INVALID_PARAMS); | |
| 148 | + } | |
| 149 | + break; | |
| 150 | + default: | |
| 151 | + bt_dev_warn(hdev, "unsupported parameter %u", type); | |
| 152 | + break; | |
| 153 | + } | |
| 154 | + | |
| 155 | + buffer_left -= exp_len; | |
| 156 | + buffer += exp_len; | |
| 157 | + } | |
| 158 | + | |
| 159 | + buffer_left = data_len; | |
| 160 | + buffer = data; | |
| 161 | + while (buffer_left >= sizeof(struct mgmt_tlv)) { | |
| 162 | + const u8 len = TO_TLV(buffer)->length; | |
| 163 | + const u16 exp_len = sizeof(struct mgmt_tlv) + | |
| 164 | + len; | |
| 165 | + const u16 type = le16_to_cpu(TO_TLV(buffer)->type); | |
| 166 | + | |
| 167 | + switch (type) { | |
| 168 | + case 0x0000: | |
| 169 | + hdev->def_page_scan_type = TLV_GET_LE16(buffer); | |
| 170 | + break; | |
| 171 | + case 0x0001: | |
| 172 | + hdev->def_page_scan_int = TLV_GET_LE16(buffer); | |
| 173 | + break; | |
| 174 | + case 0x0002: | |
| 175 | + hdev->def_page_scan_window = TLV_GET_LE16(buffer); | |
| 176 | + break; | |
| 177 | + case 0x0003: | |
| 178 | + hdev->def_inq_scan_type = TLV_GET_LE16(buffer); | |
| 179 | + break; | |
| 180 | + case 0x0004: | |
| 181 | + hdev->def_inq_scan_int = TLV_GET_LE16(buffer); | |
| 182 | + break; | |
| 183 | + case 0x0005: | |
| 184 | + hdev->def_inq_scan_window = TLV_GET_LE16(buffer); | |
| 185 | + break; | |
| 186 | + case 0x0006: | |
| 187 | + hdev->def_br_lsto = TLV_GET_LE16(buffer); | |
| 188 | + break; | |
| 189 | + case 0x0007: | |
| 190 | + hdev->def_page_timeout = TLV_GET_LE16(buffer); | |
| 191 | + break; | |
| 192 | + case 0x0008: | |
| 193 | + hdev->sniff_min_interval = TLV_GET_LE16(buffer); | |
| 194 | + break; | |
| 195 | + case 0x0009: | |
| 196 | + hdev->sniff_max_interval = TLV_GET_LE16(buffer); | |
| 197 | + break; | |
| 198 | + case 0x000a: | |
| 199 | + hdev->le_adv_min_interval = TLV_GET_LE16(buffer); | |
| 200 | + break; | |
| 201 | + case 0x000b: | |
| 202 | + hdev->le_adv_max_interval = TLV_GET_LE16(buffer); | |
| 203 | + break; | |
| 204 | + case 0x000c: | |
| 205 | + hdev->def_multi_adv_rotation_duration = | |
| 206 | + TLV_GET_LE16(buffer); | |
| 207 | + break; | |
| 208 | + case 0x000d: | |
| 209 | + hdev->le_scan_interval = TLV_GET_LE16(buffer); | |
| 210 | + break; | |
| 211 | + case 0x000e: | |
| 212 | + hdev->le_scan_window = TLV_GET_LE16(buffer); | |
| 213 | + break; | |
| 214 | + case 0x000f: | |
| 215 | + hdev->le_scan_int_suspend = TLV_GET_LE16(buffer); | |
| 216 | + break; | |
| 217 | + case 0x0010: | |
| 218 | + hdev->le_scan_window_suspend = TLV_GET_LE16(buffer); | |
| 219 | + break; | |
| 220 | + case 0x0011: | |
| 221 | + hdev->le_scan_int_discovery = TLV_GET_LE16(buffer); | |
| 222 | + break; | |
| 223 | + case 0x00012: | |
| 224 | + hdev->le_scan_window_discovery = TLV_GET_LE16(buffer); | |
| 225 | + break; | |
| 226 | + case 0x00013: | |
| 227 | + hdev->le_scan_int_adv_monitor = TLV_GET_LE16(buffer); | |
| 228 | + break; | |
| 229 | + case 0x00014: | |
| 230 | + hdev->le_scan_window_adv_monitor = TLV_GET_LE16(buffer); | |
| 231 | + break; | |
| 232 | + case 0x00015: | |
| 233 | + hdev->le_scan_int_connect = TLV_GET_LE16(buffer); | |
| 234 | + break; | |
| 235 | + case 0x00016: | |
| 236 | + hdev->le_scan_window_connect = TLV_GET_LE16(buffer); | |
| 237 | + break; | |
| 238 | + case 0x00017: | |
| 239 | + hdev->le_conn_min_interval = TLV_GET_LE16(buffer); | |
| 240 | + break; | |
| 241 | + case 0x00018: | |
| 242 | + hdev->le_conn_max_interval = TLV_GET_LE16(buffer); | |
| 243 | + break; | |
| 244 | + case 0x00019: | |
| 245 | + hdev->le_conn_latency = TLV_GET_LE16(buffer); | |
| 246 | + break; | |
| 247 | + case 0x0001a: | |
| 248 | + hdev->le_supv_timeout = TLV_GET_LE16(buffer); | |
| 249 | + break; | |
| 250 | + case 0x0001b: | |
| 251 | + hdev->def_le_autoconnect_timeout = | |
| 252 | + msecs_to_jiffies(TLV_GET_LE16(buffer)); | |
| 253 | + break; | |
| 254 | + default: | |
| 255 | + bt_dev_warn(hdev, "unsupported parameter %u", type); | |
| 256 | + break; | |
| 257 | + } | |
| 258 | + | |
| 259 | + buffer_left -= exp_len; | |
| 260 | + buffer += exp_len; | |
| 261 | + } | |
| 262 | + | |
| 263 | + return mgmt_cmd_complete(sk, hdev->id, | |
| 264 | + MGMT_OP_SET_DEF_SYSTEM_CONFIG, 0, NULL, 0); | |
| 265 | +} | |
| 266 | + | |
| 267 | +int read_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 268 | + u16 data_len) | |
| 269 | +{ | |
| 270 | + bt_dev_dbg(hdev, "sock %p", sk); | |
| 271 | + | |
| 272 | + return mgmt_cmd_complete(sk, hdev->id, | |
| 273 | + MGMT_OP_READ_DEF_RUNTIME_CONFIG, 0, NULL, 0); | |
| 274 | +} | |
| 275 | + | |
| 276 | +int set_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 277 | + u16 data_len) | |
| 278 | +{ | |
| 279 | + bt_dev_dbg(hdev, "sock %p", sk); | |
| 280 | + | |
| 281 | + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEF_SYSTEM_CONFIG, | |
| 282 | + MGMT_STATUS_INVALID_PARAMS); | |
| 283 | +} | |
| @@ -0,0 +1,17 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0-only | |
| 2 | + | |
| 3 | +/* | |
| 4 | + * Copyright (C) 2020 Google Corporation | |
| 5 | + */ | |
| 6 | + | |
| 7 | +int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 8 | + u16 data_len); | |
| 9 | + | |
| 10 | +int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 11 | + u16 data_len); | |
| 12 | + | |
| 13 | +int read_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 14 | + u16 data_len); | |
| 15 | + | |
| 16 | +int set_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, | |
| 17 | + u16 data_len); | |
| @@ -139,3 +139,10 @@ void msft_vendor_evt(struct hci_dev *hdev, struct sk_buff *skb) · 138 unmodified lines | ||
| 139 | 139 | |
| 140 | 140 | bt_dev_dbg(hdev, "MSFT vendor event %u", event); |
| 141 | 141 | } |
| 142 | + | |
| 143 | +__u64 msft_get_features(struct hci_dev *hdev) | |
| 144 | +{ | |
| 145 | + struct msft_data *msft = hdev->msft_data; | |
| 146 | + | |
| 147 | + return msft ? msft->features : 0; | |
| 148 | +} | |
| @@ -3,16 +3,25 @@ · 2 unmodified lines | ||
| 3 | 3 | * Copyright (C) 2020 Google Corporation |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | +#define MSFT_FEATURE_MASK_BREDR_RSSI_MONITOR BIT(0) | |
| 7 | +#define MSFT_FEATURE_MASK_LE_CONN_RSSI_MONITOR BIT(1) | |
| 8 | +#define MSFT_FEATURE_MASK_LE_ADV_RSSI_MONITOR BIT(2) | |
| 9 | +#define MSFT_FEATURE_MASK_LE_ADV_MONITOR BIT(3) | |
| 10 | +#define MSFT_FEATURE_MASK_CURVE_VALIDITY BIT(4) | |
| 11 | +#define MSFT_FEATURE_MASK_CONCURRENT_ADV_MONITOR BIT(5) | |
| 12 | + | |
| 6 | 13 | #if IS_ENABLED(CONFIG_BT_MSFTEXT) |
| 7 | 14 | |
| 8 | 15 | void msft_do_open(struct hci_dev *hdev); |
| 9 | 16 | void msft_do_close(struct hci_dev *hdev); |
| 10 | 17 | void msft_vendor_evt(struct hci_dev *hdev, struct sk_buff *skb); |
| 18 | +__u64 msft_get_features(struct hci_dev *hdev); | |
| 11 | 19 | |
| 12 | 20 | #else |
| 13 | 21 | |
| 14 | 22 | static inline void msft_do_open(struct hci_dev *hdev) {} |
| 15 | 23 | static inline void msft_do_close(struct hci_dev *hdev) {} |
| 16 | 24 | static inline void msft_vendor_evt(struct hci_dev *hdev, struct sk_buff *skb) {} |
| 25 | +static inline __u64 msft_get_features(struct hci_dev *hdev) { return 0; } | |
| 17 | 26 | |
| 18 | 27 | #endif |
| @@ -479,7 +479,7 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) · 478 unmodified lines | ||
| 479 | 479 | /* if closing a dlc in a session that hasn't been started, |
| 480 | 480 | * just close and unlink the dlc |
| 481 | 481 | */ |
| 482 | − /* fall through */ | |
| 482 | + fallthrough; | |
| 483 | 483 | |
| 484 | 484 | default: |
| 485 | 485 | rfcomm_dlc_clear_timer(d); |
| @@ -218,7 +218,7 @@ static void __rfcomm_sock_close(struct sock *sk) · 217 unmodified lines | ||
| 218 | 218 | case BT_CONFIG: |
| 219 | 219 | case BT_CONNECTED: |
| 220 | 220 | rfcomm_dlc_close(d, 0); |
| 221 | − /* fall through */ | |
| 221 | + fallthrough; | |
| 222 | 222 | |
| 223 | 223 | default: |
| 224 | 224 | sock_set_flag(sk, SOCK_ZAPPED); |
| @@ -66,6 +66,7 @@ struct sco_pinfo { · 65 unmodified lines | ||
| 66 | 66 | bdaddr_t dst; |
| 67 | 67 | __u32 flags; |
| 68 | 68 | __u16 setting; |
| 69 | + __u8 cmsg_mask; | |
| 69 | 70 | struct sco_conn *conn; |
| 70 | 71 | }; |
| 71 | 72 | |
| @@ -449,6 +450,15 @@ static void sco_sock_close(struct sock *sk) · 377 unmodified lines | ||
| 449 | 450 | sco_sock_kill(sk); |
| 450 | 451 | } |
| 451 | 452 | |
| 453 | +static void sco_skb_put_cmsg(struct sk_buff *skb, struct msghdr *msg, | |
| 454 | + struct sock *sk) | |
| 455 | +{ | |
| 456 | + if (sco_pi(sk)->cmsg_mask & SCO_CMSG_PKT_STATUS) | |
| 457 | + put_cmsg(msg, SOL_BLUETOOTH, BT_SCM_PKT_STATUS, | |
| 458 | + sizeof(bt_cb(skb)->sco.pkt_status), | |
| 459 | + &bt_cb(skb)->sco.pkt_status); | |
| 460 | +} | |
| 461 | + | |
| 452 | 462 | static void sco_sock_init(struct sock *sk, struct sock *parent) |
| 453 | 463 | { |
| 454 | 464 | BT_DBG("sk %p", sk); |
| @@ -457,6 +467,8 @@ static void sco_sock_init(struct sock *sk, struct sock *parent) · 2 unmodified lines | ||
| 457 | 467 | sk->sk_type = parent->sk_type; |
| 458 | 468 | bt_sk(sk)->flags = bt_sk(parent)->flags; |
| 459 | 469 | security_sk_clone(parent, sk); |
| 470 | + } else { | |
| 471 | + bt_sk(sk)->skb_put_cmsg = sco_skb_put_cmsg; | |
| 460 | 472 | } |
| 461 | 473 | } |
| 462 | 474 | |
| @@ -846,6 +858,18 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, · 383 unmodified lines | ||
| 846 | 858 | sco_pi(sk)->setting = voice.setting; |
| 847 | 859 | break; |
| 848 | 860 | |
| 861 | + case BT_PKT_STATUS: | |
| 862 | + if (get_user(opt, (u32 __user *)optval)) { | |
| 863 | + err = -EFAULT; | |
| 864 | + break; | |
| 865 | + } | |
| 866 | + | |
| 867 | + if (opt) | |
| 868 | + sco_pi(sk)->cmsg_mask |= SCO_CMSG_PKT_STATUS; | |
| 869 | + else | |
| 870 | + sco_pi(sk)->cmsg_mask &= SCO_CMSG_PKT_STATUS; | |
| 871 | + break; | |
| 872 | + | |
| 849 | 873 | default: |
| 850 | 874 | err = -ENOPROTOOPT; |
| 851 | 875 | break; |
| @@ -923,6 +947,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, · 71 unmodified lines | ||
| 923 | 947 | int len, err = 0; |
| 924 | 948 | struct bt_voice voice; |
| 925 | 949 | u32 phys; |
| 950 | + int pkt_status; | |
| 926 | 951 | |
| 927 | 952 | BT_DBG("sk %p", sk); |
| 928 | 953 | |
| @@ -969,6 +994,13 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, · 40 unmodified lines | ||
| 969 | 994 | err = -EFAULT; |
| 970 | 995 | break; |
| 971 | 996 | |
| 997 | + case BT_PKT_STATUS: | |
| 998 | + pkt_status = (sco_pi(sk)->cmsg_mask & SCO_CMSG_PKT_STATUS); | |
| 999 | + | |
| 1000 | + if (put_user(pkt_status, (int __user *)optval)) | |
| 1001 | + err = -EFAULT; | |
| 1002 | + break; | |
| 1003 | + | |
| 972 | 1004 | default: |
| 973 | 1005 | err = -ENOPROTOOPT; |
| 974 | 1006 | break; |
| @@ -205,7 +205,7 @@ static int __init test_ecdh(void) · 204 unmodified lines | ||
| 205 | 205 | |
| 206 | 206 | calltime = ktime_get(); |
| 207 | 207 | |
| 208 | − tfm = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0); | |
| 208 | + tfm = crypto_alloc_kpp("ecdh", 0, 0); | |
| 209 | 209 | if (IS_ERR(tfm)) { |
| 210 | 210 | BT_ERR("Unable to create ECDH crypto context"); |
| 211 | 211 | err = PTR_ERR(tfm); |
| @@ -1387,7 +1387,7 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) · 1386 unmodified lines | ||
| 1387 | 1387 | goto zfree_smp; |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | − smp->tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0); | |
| 1390 | + smp->tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); | |
| 1391 | 1391 | if (IS_ERR(smp->tfm_ecdh)) { |
| 1392 | 1392 | BT_ERR("Unable to create ECDH crypto context"); |
| 1393 | 1393 | goto free_shash; |
| @@ -1654,7 +1654,7 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey) · 260 unmodified lines | ||
| 1654 | 1654 | memset(smp->tk, 0, sizeof(smp->tk)); |
| 1655 | 1655 | BT_DBG("PassKey: %d", value); |
| 1656 | 1656 | put_unaligned_le32(value, smp->tk); |
| 1657 | − /* Fall Through */ | |
| 1657 | + fallthrough; | |
| 1658 | 1658 | case MGMT_OP_USER_CONFIRM_REPLY: |
| 1659 | 1659 | set_bit(SMP_FLAG_TK_VALID, &smp->flags); |
| 1660 | 1660 | break; |
| @@ -3282,7 +3282,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid) · 1621 unmodified lines | ||
| 3282 | 3282 | return ERR_CAST(tfm_cmac); |
| 3283 | 3283 | } |
| 3284 | 3284 | |
| 3285 | − tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0); | |
| 3285 | + tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); | |
| 3286 | 3286 | if (IS_ERR(tfm_ecdh)) { |
| 3287 | 3287 | BT_ERR("Unable to create ECDH crypto context"); |
| 3288 | 3288 | crypto_free_shash(tfm_cmac); |
| @@ -3847,7 +3847,7 @@ int __init bt_selftest_smp(void) · 558 unmodified lines | ||
| 3847 | 3847 | return PTR_ERR(tfm_cmac); |
| 3848 | 3848 | } |
| 3849 | 3849 | |
| 3850 | − tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0); | |
| 3850 | + tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0); | |
| 3851 | 3851 | if (IS_ERR(tfm_ecdh)) { |
| 3852 | 3852 | BT_ERR("Unable to create ECDH crypto context"); |
| 3853 | 3853 | crypto_free_shash(tfm_cmac); |