History

Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next

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 ====================

David S. Miller committed 6 years ago

Commit 4bb540d2 parents bd69058 075f77344 files · +2149 −324Browse files

Unified · Split

44 files
  1. Documentation/devicetree/bindings/net/realtek-bluetooth.yaml +1 −1
  2. drivers/bluetooth/bcm203x.c +1 −1
  3. drivers/bluetooth/bluecard_cs.c +0 −2
  4. drivers/bluetooth/btintel.c +59 −0
  5. drivers/bluetooth/btintel.h +21 −0
  6. drivers/bluetooth/btmrvl_main.c +11 −0
  7. drivers/bluetooth/btmrvl_sdio.c +14 −7
  8. drivers/bluetooth/btmtksdio.c +15 −1
  9. drivers/bluetooth/btqca.c +27 −0
  10. drivers/bluetooth/btqca.h +2 −0
  11. drivers/bluetooth/btusb.c +211 −92
  12. drivers/bluetooth/hci_h5.c +1 −1
  13. drivers/bluetooth/hci_ll.c +1 −1
  14. drivers/bluetooth/hci_qca.c +83 −51
  15. drivers/bluetooth/hci_serdev.c +2 −1
  16. drivers/net/wireless/marvell/mwifiex/sdio.h +2 −2
  17. include/net/bluetooth/bluetooth.h +12 −0
  18. include/net/bluetooth/hci.h +26 −2
  19. include/net/bluetooth/hci_core.h +96 −11
  20. include/net/bluetooth/hci_sock.h +2 −2
  21. include/net/bluetooth/mgmt.h +95 −0
  22. include/net/bluetooth/sco.h +2 −0
  23. net/bluetooth/6lowpan.c +5 −0
  24. net/bluetooth/Kconfig +1 −1
  25. net/bluetooth/Makefile +1 −1
  26. net/bluetooth/af_bluetooth.c +3 −2
  27. net/bluetooth/hci_conn.c +36 −15
  28. net/bluetooth/hci_core.c +198 −14
  29. net/bluetooth/hci_event.c +48 −23
  30. net/bluetooth/hci_request.c +233 −53
  31. net/bluetooth/hci_request.h +4 −1
  32. net/bluetooth/hci_sock.c +3 −4
  33. net/bluetooth/l2cap_core.c +13 −12
  34. net/bluetooth/l2cap_sock.c +2 −2
  35. net/bluetooth/mgmt.c +563 −14
  36. net/bluetooth/mgmt_config.c +283 −0
  37. net/bluetooth/mgmt_config.h +17 −0
  38. net/bluetooth/msft.c +7 −0
  39. net/bluetooth/msft.h +9 −0
  40. net/bluetooth/rfcomm/core.c +1 −1
  41. net/bluetooth/rfcomm/sock.c +1 −1
  42. net/bluetooth/sco.c +32 −0
  43. net/bluetooth/selftest.c +1 −1
  44. net/bluetooth/smp.c +4 −4
Documentation/devicetree/bindings/net/realtek-bluetooth.yaml+1−1
@@ -44,7 +44,7 @@ examples: · 43 unmodified lines
4444 uart1 {
4545 pinctrl-names = "default";
4646 pinctrl-0 = <&uart1_pins>, <&uart1_rts_cts_pins>;
47− uart-has-rtscts = <1>;
47+ uart-has-rtscts;
4848
4949 bluetooth {
5050 compatible = "realtek,rtl8723bs-bt";
drivers/bluetooth/bcm203x.c+1−1
@@ -106,7 +106,7 @@ static void bcm203x_complete(struct urb *urb) · 105 unmodified lines
106106 }
107107
108108 data->state = BCM203X_LOAD_FIRMWARE;
109− /* fall through */
109+ fallthrough;
110110 case BCM203X_LOAD_FIRMWARE:
111111 if (data->fw_sent == data->fw_size) {
112112 usb_fill_int_urb(urb, udev, usb_rcvintpipe(udev, BCM203X_IN_EP),
drivers/bluetooth/bluecard_cs.c+0−2
@@ -295,7 +295,6 @@ static void bluecard_write_wakeup(struct bluecard_info *info) · 294 unmodified lines
295295 baud_reg = REG_CONTROL_BAUD_RATE_115200;
296296 break;
297297 case PKT_BAUD_RATE_57600:
298− /* Fall through... */
299298 default:
300299 baud_reg = REG_CONTROL_BAUD_RATE_57600;
301300 break;
@@ -585,7 +584,6 @@ static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud) · 283 unmodified lines
585584 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_115200;
586585 break;
587586 case 57600:
588− /* Fall through... */
589587 default:
590588 cmd[4] = 0x03;
591589 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_57600;
drivers/bluetooth/btintel.c+59−0
@@ -754,6 +754,65 @@ void btintel_reset_to_bootloader(struct hci_dev *hdev) · 753 unmodified lines
754754 }
755755 EXPORT_SYMBOL_GPL(btintel_reset_to_bootloader);
756756
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+
757816 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
758817 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
759818 MODULE_VERSION(VERSION);
drivers/bluetooth/btintel.h+21−0
@@ -62,6 +62,10 @@ struct intel_reset { · 61 unmodified lines
6262 __le32 boot_param;
6363 } __packed;
6464
65+struct intel_debug_features {
66+ __u8 page1[16];
67+} __packed;
68+
6569 #if IS_ENABLED(CONFIG_BT_INTEL)
6670
6771 int btintel_check_bdaddr(struct hci_dev *hdev);
@@ -88,6 +92,10 @@ int btintel_read_boot_params(struct hci_dev *hdev, · 20 unmodified lines
8892 int btintel_download_firmware(struct hci_dev *dev, const struct firmware *fw,
8993 u32 *boot_param);
9094 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);
9199 #else
92100
93101 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
186194 static inline void btintel_reset_to_bootloader(struct hci_dev *hdev)
187195 {
188196 }
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+
189210 #endif
drivers/bluetooth/btmrvl_main.c+11−0
@@ -587,6 +587,14 @@ static int btmrvl_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) · 586 unmodified lines
587587 return 0;
588588 }
589589
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+
590598 /*
591599 * This function handles the event generated by firmware, rx data
592600 * received from firmware, and tx data sent from kernel.
@@ -669,6 +677,7 @@ static int btmrvl_service_main_thread(void *data) · 76 unmodified lines
669677 int btmrvl_register_hdev(struct btmrvl_private *priv)
670678 {
671679 struct hci_dev *hdev = NULL;
680+ struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
672681 int ret;
673682
674683 hdev = hci_alloc_dev();
@@ -687,6 +696,8 @@ int btmrvl_register_hdev(struct btmrvl_private *priv) · 12 unmodified lines
687696 hdev->send = btmrvl_send_frame;
688697 hdev->setup = btmrvl_setup;
689698 hdev->set_bdaddr = btmrvl_set_bdaddr;
699+ hdev->prevent_wake = btmrvl_prevent_wake;
700+ SET_HCIDEV_DEV(hdev, &card->func->dev);
690701
691702 hdev->dev_type = priv->btmrvl_dev.dev_type;
692703
drivers/bluetooth/btmrvl_sdio.c+14−7
@@ -111,6 +111,9 @@ static int btmrvl_sdio_probe_of(struct device *dev, · 110 unmodified lines
111111 "Failed to request irq_bt %d (%d)\n",
112112 cfg->irq_bt, ret);
113113 }
114+
115+ /* Configure wakeup (enabled by default) */
116+ device_init_wakeup(dev, true);
114117 disable_irq(cfg->irq_bt);
115118 }
116119 }
@@ -328,7 +331,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = { · 211 unmodified lines
328331
329332 static const struct btmrvl_sdio_device btmrvl_sdio_sd8977 = {
330333 .helper = NULL,
331− .firmware = "mrvl/sd8977_uapsta.bin",
334+ .firmware = "mrvl/sdsd8977_combo_v2.bin",
332335 .reg = &btmrvl_reg_8977,
333336 .support_pscan_win_report = true,
334337 .sd_blksz_fw_dl = 256,
@@ -346,7 +349,7 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8987 = { · 11 unmodified lines
346349
347350 static const struct btmrvl_sdio_device btmrvl_sdio_sd8997 = {
348351 .helper = NULL,
349− .firmware = "mrvl/sd8997_uapsta.bin",
352+ .firmware = "mrvl/sdsd8997_combo_v4.bin",
350353 .reg = &btmrvl_reg_8997,
351354 .support_pscan_win_report = true,
352355 .sd_blksz_fw_dl = 256,
@@ -1654,6 +1657,7 @@ static void btmrvl_sdio_remove(struct sdio_func *func) · 1301 unmodified lines
16541657 MODULE_SHUTDOWN_REQ);
16551658 btmrvl_sdio_disable_host_int(card);
16561659 }
1660+
16571661 BT_DBG("unregister dev");
16581662 card->priv->surprise_removed = true;
16591663 btmrvl_sdio_unregister_dev(card);
@@ -1690,7 +1694,8 @@ static int btmrvl_sdio_suspend(struct device *dev) · 30 unmodified lines
16901694 }
16911695
16921696 /* 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)) {
16941699 card->plt_wake_cfg->wake_by_bt = false;
16951700 enable_irq(card->plt_wake_cfg->irq_bt);
16961701 enable_irq_wake(card->plt_wake_cfg->irq_bt);
@@ -1707,7 +1712,8 @@ static int btmrvl_sdio_suspend(struct device *dev) · 10 unmodified lines
17071712 BT_ERR("HS not activated, suspend failed!");
17081713 /* Disable platform specific wakeup interrupt */
17091714 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)) {
17111717 disable_irq_wake(card->plt_wake_cfg->irq_bt);
17121718 disable_irq(card->plt_wake_cfg->irq_bt);
17131719 }
@@ -1767,7 +1773,8 @@ static int btmrvl_sdio_resume(struct device *dev) · 53 unmodified lines
17671773 hci_resume_dev(hcidev);
17681774
17691775 /* 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)) {
17711778 disable_irq_wake(card->plt_wake_cfg->irq_bt);
17721779 disable_irq(card->plt_wake_cfg->irq_bt);
17731780 if (card->plt_wake_cfg->wake_by_bt)
@@ -1831,6 +1838,6 @@ MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); · 57 unmodified lines
18311838 MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");
18321839 MODULE_FIRMWARE("mrvl/sd8887_uapsta.bin");
18331840 MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin");
1834−MODULE_FIRMWARE("mrvl/sd8977_uapsta.bin");
1841+MODULE_FIRMWARE("mrvl/sdsd8977_combo_v2.bin");
18351842 MODULE_FIRMWARE("mrvl/sd8987_uapsta.bin");
1836−MODULE_FIRMWARE("mrvl/sd8997_uapsta.bin");
1843+MODULE_FIRMWARE("mrvl/sdsd8997_combo_v4.bin");
drivers/bluetooth/btmtksdio.c+15−1
@@ -685,7 +685,7 @@ static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 684 unmodified lines
685685 const u8 *fw_ptr;
686686 size_t fw_size;
687687 int err, dlen;
688− u8 flag;
688+ u8 flag, param;
689689
690690 err = request_firmware(&fw, fwname, &hdev->dev);
691691 if (err < 0) {
@@ -693,6 +693,20 @@ static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 1 unmodified line
693693 return err;
694694 }
695695
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 = &param;
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+
696710 fw_ptr = fw->data;
697711 fw_size = fw->size;
698712
drivers/bluetooth/btqca.c+27−0
@@ -400,6 +400,27 @@ out: · 399 unmodified lines
400400 return ret;
401401 }
402402
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+
403424 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
404425 {
405426 struct sk_buff *skb;
@@ -486,6 +507,12 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, · 80 unmodified lines
486507 return err;
487508 }
488509
510+ if (soc_type >= QCA_WCN3991) {
511+ err = qca_disable_soc_logging(hdev);
512+ if (err < 0)
513+ return err;
514+ }
515+
489516 /* Perform HCI reset */
490517 err = qca_send_reset(hdev);
491518 if (err < 0) {
drivers/bluetooth/btqca.h+2−0
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #define EDL_NVM_ACCESS_SET_REQ_CMD (0x01)
1515 #define MAX_SIZE_PER_TLV_SEGMENT (243)
1616 #define QCA_PRE_SHUTDOWN_CMD (0xFC08)
17+#define QCA_DISABLE_LOGGING (0xFC17)
1718
1819 #define EDL_CMD_REQ_RES_EVT (0x00)
1920 #define EDL_PATCH_VER_RES_EVT (0x19)
@@ -22,6 +23,7 @@ · 2 unmodified lines
2223 #define EDL_CMD_EXE_STATUS_EVT (0x00)
2324 #define EDL_SET_BAUDRATE_RSP_EVT (0x92)
2425 #define EDL_NVM_ACCESS_CODE_EVT (0x0B)
26+#define QCA_DISABLE_LOGGING_SUB_OP (0x14)
2527
2628 #define EDL_TAG_ID_HCI (17)
2729 #define EDL_TAG_ID_DEEP_SLEEP (27)
drivers/bluetooth/btusb.c+211−92
@@ -359,6 +359,10 @@ static const struct usb_device_id blacklist_table[] = { · 358 unmodified lines
359359 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
360360 .driver_info = BTUSB_IGNORE },
361361
362+ /* Realtek 8822CE Bluetooth devices */
363+ { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK |
364+ BTUSB_WIDEBAND_SPEECH },
365+
362366 /* Realtek Bluetooth devices */
363367 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
364368 .driver_info = BTUSB_REALTEK },
@@ -453,6 +457,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { · 88 unmodified lines
453457 #define BTUSB_HW_RESET_ACTIVE 12
454458 #define BTUSB_TX_WAIT_VND_EVT 13
455459 #define BTUSB_WAKEUP_DISABLE 14
460+#define BTUSB_USE_ALT1_FOR_WBS 15
456461
457462 struct btusb_data {
458463 struct hci_dev *hdev;
@@ -511,7 +516,6 @@ struct btusb_data { · 52 unmodified lines
511516 unsigned cmd_timeout_cnt;
512517 };
513518
514−
515519 static void btusb_intel_cmd_timeout(struct hci_dev *hdev)
516520 {
517521 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
573577 gpiod_set_value_cansleep(reset_gpio, 0);
574578 }
575579
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+
576597 static inline void btusb_free_frags(struct btusb_data *data)
577598 {
578599 unsigned long flags;
@@ -1666,14 +1687,15 @@ static void btusb_work(struct work_struct *work) · 1087 unmodified lines
16661687 new_alts = data->sco_num;
16671688 }
16681689 } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) {
1669−
1670− data->usb_alt6_packet_flow = true;
1671−
16721690 /* 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;
16741693 new_alts = 6;
1675− else
1694+ } else if (test_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags)) {
1695+ new_alts = 1;
1696+ } else {
16761697 bt_dev_err(hdev, "Device does not support ALT setting 6");
1698+ }
16771699 }
16781700
16791701 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
17201742 {
17211743 struct hci_rp_read_local_version *rp;
17221744 struct sk_buff *skb;
1745+ bool is_fake = false;
17231746
17241747 BT_DBG("%s", hdev->name);
17251748
@@ -1739,18 +1762,69 @@ static int btusb_setup_csr(struct hci_dev *hdev) · 13 unmodified lines
17391762
17401763 rp = (struct hci_rp_read_local_version *)skb->data;
17411764
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+ */
17431777 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+
17451823 /* Clear the reset quirk since this is not an actual
17461824 * early Bluetooth 1.1 device from CSR.
17471825 */
17481826 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);
17541828 }
17551829
17561830 kfree_skb(skb);
@@ -2262,45 +2336,25 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, · 505 unmodified lines
22622336 return true;
22632337 }
22642338
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)
22662342 {
2267− struct btusb_data *data = hci_get_drvdata(hdev);
2268− struct intel_version ver;
2269− struct intel_boot_params params;
22702343 const struct firmware *fw;
22712344 u32 boot_param;
22722345 char fwname[64];
2273− ktime_t calltime, delta, rettime;
2274− unsigned long long duration;
22752346 int err;
2347+ struct btusb_data *data = hci_get_drvdata(hdev);
22762348
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;
22972351
22982352 /* The hardware platform number has a fixed value of 0x37 and
22992353 * for now only accept this single value.
23002354 */
2301− if (ver.hw_platform != 0x37) {
2355+ if (ver->hw_platform != 0x37) {
23022356 bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
2303− ver.hw_platform);
2357+ ver->hw_platform);
23042358 return -EINVAL;
23052359 }
23062360
@@ -2310,7 +2364,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 3 unmodified lines
23102364 * This check has been put in place to ensure correct forward
23112365 * compatibility options when newer hardware variants come along.
23122366 */
2313− switch (ver.hw_variant) {
2367+ switch (ver->hw_variant) {
23142368 case 0x0b: /* SfP */
23152369 case 0x0c: /* WsP */
23162370 case 0x11: /* JfP */
@@ -2320,11 +2374,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 3 unmodified lines
23202374 break;
23212375 default:
23222376 bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
2323− ver.hw_variant);
2377+ ver->hw_variant);
23242378 return -EINVAL;
23252379 }
23262380
2327− btintel_version_info(hdev, &ver);
2381+ btintel_version_info(hdev, ver);
23282382
23292383 /* The firmware variant determines if the device is in bootloader
23302384 * 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
23392393 * It is not possible to use the Secure Boot Parameters in this
23402394 * case since that command is only available in bootloader mode.
23412395 */
2342− if (ver.fw_variant == 0x23) {
2396+ if (ver->fw_variant == 0x23) {
23432397 clear_bit(BTUSB_BOOTLOADER, &data->flags);
23442398 btintel_check_bdaddr(hdev);
2345− goto finish;
2399+ return 0;
23462400 }
23472401
23482402 /* If the device is not in bootloader mode, then the only possible
23492403 * choice is to return an error and abort the device initialization.
23502404 */
2351− if (ver.fw_variant != 0x06) {
2405+ if (ver->fw_variant != 0x06) {
23522406 bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)",
2353− ver.fw_variant);
2407+ ver->fw_variant);
23542408 return -ENODEV;
23552409 }
23562410
23572411 /* Read the secure boot parameters to identify the operating
23582412 * details of the bootloader.
23592413 */
2360− err = btintel_read_boot_params(hdev, &params);
2414+ err = btintel_read_boot_params(hdev, params);
23612415 if (err)
23622416 return err;
23632417
@@ -2365,16 +2419,16 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 1 unmodified line
23652419 * with a command complete event. If the boot parameters indicate
23662420 * that this bootloader does not send them, then abort the setup.
23672421 */
2368− if (params.limited_cce != 0x00) {
2422+ if (params->limited_cce != 0x00) {
23692423 bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
2370− params.limited_cce);
2424+ params->limited_cce);
23712425 return -EINVAL;
23722426 }
23732427
23742428 /* If the OTP has no valid Bluetooth device address, then there will
23752429 * also be no valid address for the operational firmware.
23762430 */
2377− if (!bacmp(&params.otp_bdaddr, BDADDR_ANY)) {
2431+ if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
23782432 bt_dev_info(hdev, "No device address configured");
23792433 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
23802434 }
@@ -2400,7 +2454,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 19 unmodified lines
24002454 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
24012455 *
24022456 */
2403− err = btusb_setup_intel_new_get_fw_name(&ver, &params, fwname,
2457+ err = btusb_setup_intel_new_get_fw_name(ver, params, fwname,
24042458 sizeof(fwname), "sfi");
24052459 if (!err) {
24062460 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
24152469
24162470 bt_dev_info(hdev, "Found device firmware: %s", fwname);
24172471
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, &params, fwname,
2422− sizeof(fwname), "ddc");
2423− if (!err) {
2424− bt_dev_err(hdev, "Unsupported Intel firmware naming");
2425− return -EINVAL;
2426− }
2427−
24282472 if (fw->size < 644) {
24292473 bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
24302474 fw->size);
@@ -2479,18 +2523,58 @@ static int btusb_setup_intel_new(struct hci_dev *hdev) · 48 unmodified lines
24792523 goto done;
24802524 }
24812525
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, &params);
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+
24822572 rettime = ktime_get();
24832573 delta = ktime_sub(rettime, calltime);
24842574 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
24852575
24862576 bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
24872577
2488−done:
2489− release_firmware(fw);
2490−
2491− if (err < 0)
2492− return err;
2493−
24942578 calltime = ktime_get();
24952579
24962580 set_bit(BTUSB_BOOTING, &data->flags);
@@ -2534,13 +2618,28 @@ done: · 37 unmodified lines
25342618
25352619 clear_bit(BTUSB_BOOTLOADER, &data->flags);
25362620
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, &params, 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.
25422638 */
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);
25442643
25452644 /* Read the Intel version information after loading the FW */
25462645 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
29253024 const u8 *fw_ptr;
29263025 size_t fw_size;
29273026 int err, dlen;
2928− u8 flag;
3027+ u8 flag, param;
29293028
29303029 err = request_firmware(&fw, fwname, &hdev->dev);
29313030 if (err < 0) {
@@ -2933,6 +3032,20 @@ static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) · 1 unmodified line
29333032 return err;
29343033 }
29353034
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 = &param;
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+
29363049 fw_ptr = fw->data;
29373050 fw_size = fw->size;
29383051
@@ -3704,6 +3817,9 @@ static bool btusb_prevent_wake(struct hci_dev *hdev) · 765 unmodified lines
37043817 {
37053818 struct btusb_data *data = hci_get_drvdata(hdev);
37063819
3820+ if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags))
3821+ return true;
3822+
37073823 return !device_may_wakeup(&data->udev->dev);
37083824 }
37093825
@@ -3941,10 +4057,20 @@ static int btusb_probe(struct usb_interface *intf, · 231 unmodified lines
39414057 if (id->driver_info & BTUSB_QCA_ROME) {
39424058 data->setup_on_usb = btusb_setup_qca;
39434059 hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
4060+ hdev->cmd_timeout = btusb_qca_cmd_timeout;
39444061 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
39454062 btusb_check_needs_reset_resume(intf);
39464063 }
39474064
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+
39484074 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
39494075 (id->driver_info & BTUSB_REALTEK)) {
39504076 hdev->setup = btrtl_setup_realtek;
@@ -3956,19 +4082,10 @@ static int btusb_probe(struct usb_interface *intf, · 5 unmodified lines
39564082 * (DEVICE_REMOTE_WAKEUP)
39574083 */
39584084 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");
39724089 }
39734090
39744091 if (!reset)
@@ -4001,11 +4118,13 @@ static int btusb_probe(struct usb_interface *intf, · 26 unmodified lines
40014118 if (bcdDevice < 0x117)
40024119 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
40034120
4121+ /* This must be set first in case we disable it for fakes */
4122+ set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
4123+
40044124 /* 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)
40064127 hdev->setup = btusb_setup_csr;
4007−
4008− set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
40094128 }
40104129
40114130 if (id->driver_info & BTUSB_SNIFFER) {
drivers/bluetooth/hci_h5.c+1−1
@@ -793,7 +793,7 @@ static int h5_serdev_probe(struct serdev_device *serdev) · 792 unmodified lines
793793 if (!h5)
794794 return -ENOMEM;
795795
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);
797797
798798 h5->hu = &h5->serdev_hu;
799799 h5->serdev_hu.serdev = serdev;
drivers/bluetooth/hci_ll.c+1−1
@@ -219,7 +219,7 @@ static void ll_device_want_to_wakeup(struct hci_uart *hu) · 218 unmodified lines
219219 * perfectly safe to always send one.
220220 */
221221 BT_DBG("dual wake-up-indication");
222− /* fall through */
222+ fallthrough;
223223 case HCILL_ASLEEP:
224224 /* acknowledge device wake up */
225225 if (send_hcill_cmd(HCILL_WAKE_UP_ACK, hu) < 0) {
drivers/bluetooth/hci_qca.c+83−51
@@ -46,7 +46,7 @@ · 45 unmodified lines
4646 #define HCI_MAX_IBS_SIZE 10
4747
4848 #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
5050 #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000
5151 #define CMD_TRANS_TIMEOUT_MS 100
5252 #define MEMDUMP_TIMEOUT_MS 8000
@@ -72,7 +72,8 @@ enum qca_flags { · 19 unmodified lines
7272 QCA_DROP_VENDOR_EVENT,
7373 QCA_SUSPENDING,
7474 QCA_MEMDUMP_COLLECTION,
75− QCA_HW_ERROR_EVENT
75+ QCA_HW_ERROR_EVENT,
76+ QCA_SSR_TRIGGERED
7677 };
7778
7879 enum qca_capabilities {
@@ -289,25 +290,21 @@ static void serial_clock_vote(unsigned long vote, struct hci_uart *hu) · 210 unmodified lines
289290 case HCI_IBS_TX_VOTE_CLOCK_ON:
290291 qca->tx_vote = true;
291292 qca->tx_votes_on++;
292− new_vote = true;
293293 break;
294294
295295 case HCI_IBS_RX_VOTE_CLOCK_ON:
296296 qca->rx_vote = true;
297297 qca->rx_votes_on++;
298− new_vote = true;
299298 break;
300299
301300 case HCI_IBS_TX_VOTE_CLOCK_OFF:
302301 qca->tx_vote = false;
303302 qca->tx_votes_off++;
304− new_vote = qca->rx_vote | qca->tx_vote;
305303 break;
306304
307305 case HCI_IBS_RX_VOTE_CLOCK_OFF:
308306 qca->rx_vote = false;
309307 qca->rx_votes_off++;
310− new_vote = qca->rx_vote | qca->tx_vote;
311308 break;
312309
313310 default:
@@ -315,6 +312,8 @@ static void serial_clock_vote(unsigned long vote, struct hci_uart *hu) · 1 unmodified line
315312 return;
316313 }
317314
315+ new_vote = qca->rx_vote | qca->tx_vote;
316+
318317 if (new_vote != old_vote) {
319318 if (new_vote)
320319 __serial_clock_on(hu->tty);
@@ -474,8 +473,6 @@ static void hci_ibs_tx_idle_timeout(struct timer_list *t) · 153 unmodified lines
474473
475474 case HCI_IBS_TX_ASLEEP:
476475 case HCI_IBS_TX_WAKING:
477− /* Fall through */
478−
479476 default:
480477 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
481478 break;
@@ -518,8 +515,6 @@ static void hci_ibs_wake_retrans_timeout(struct timer_list *t) · 36 unmodified lines
518515
519516 case HCI_IBS_TX_ASLEEP:
520517 case HCI_IBS_TX_AWAKE:
521− /* Fall through */
522−
523518 default:
524519 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
525520 break;
@@ -837,8 +832,6 @@ static void device_woke_up(struct hci_uart *hu) · 311 unmodified lines
837832 break;
838833
839834 case HCI_IBS_TX_ASLEEP:
840− /* Fall through */
841−
842835 default:
843836 BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d",
844837 qca->tx_ibs_state);
@@ -862,6 +855,13 @@ static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb) · 17 unmodified lines
862855 BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb,
863856 qca->tx_ibs_state);
864857
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+
865865 /* Prepend skb with frame type */
866866 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
867867
@@ -983,8 +983,11 @@ static void qca_controller_memdump(struct work_struct *work) · 115 unmodified lines
983983 while ((skb = skb_dequeue(&qca->rx_memdump_q))) {
984984
985985 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) {
988991 mutex_unlock(&qca->hci_memdump_lock);
989992 return;
990993 }
@@ -1128,6 +1131,7 @@ static int qca_controller_memdump_event(struct hci_dev *hdev, · 137 unmodified lines
11281131 struct hci_uart *hu = hci_get_drvdata(hdev);
11291132 struct qca_data *qca = hu->priv;
11301133
1134+ set_bit(QCA_SSR_TRIGGERED, &qca->flags);
11311135 skb_queue_tail(&qca->rx_memdump_q, skb);
11321136 queue_work(qca->workqueue, &qca->ctrl_memdump_evt);
11331137
@@ -1485,9 +1489,8 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) · 351 unmodified lines
14851489 {
14861490 struct hci_uart *hu = hci_get_drvdata(hdev);
14871491 struct qca_data *qca = hu->priv;
1488− struct qca_memdump_data *qca_memdump = qca->qca_memdump;
1489− char *memdump_buf = NULL;
14901492
1493+ set_bit(QCA_SSR_TRIGGERED, &qca->flags);
14911494 set_bit(QCA_HW_ERROR_EVENT, &qca->flags);
14921495 bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state);
14931496
@@ -1509,19 +1512,23 @@ static void qca_hw_error(struct hci_dev *hdev, u8 code) · 15 unmodified lines
15091512 qca_wait_for_dump_collection(hdev);
15101513 }
15111514
1515+ mutex_lock(&qca->hci_memdump_lock);
15121516 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) {
15131517 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+ }
15201523 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
15211524 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) {
15241530 cancel_work_sync(&qca->ctrl_memdump_evt);
1531+ skb_queue_purge(&qca->rx_memdump_q);
15251532 }
15261533
15271534 clear_bit(QCA_HW_ERROR_EVENT, &qca->flags);
@@ -1532,10 +1539,30 @@ static void qca_cmd_timeout(struct hci_dev *hdev) · 4 unmodified lines
15321539 struct hci_uart *hu = hci_get_drvdata(hdev);
15331540 struct qca_data *qca = hu->priv;
15341541
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);
15361545 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);
15391566 }
15401567
15411568 static int qca_wcn3990_init(struct hci_uart *hu)
@@ -1641,11 +1668,15 @@ static int qca_setup(struct hci_uart *hu) · 99 unmodified lines
16411668 bt_dev_info(hdev, "setting up %s",
16421669 qca_is_wcn399x(soc_type) ? "wcn399x" : "ROME/QCA6390");
16431670
1671+ qca->memdump_state = QCA_MEMDUMP_IDLE;
1672+
16441673 retry:
16451674 ret = qca_power_on(hdev);
16461675 if (ret)
16471676 return ret;
16481677
1678+ clear_bit(QCA_SSR_TRIGGERED, &qca->flags);
1679+
16491680 if (qca_is_wcn399x(soc_type)) {
16501681 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
16511682
@@ -1788,9 +1819,6 @@ static void qca_power_shutdown(struct hci_uart *hu) · 136 unmodified lines
17881819 qca_flush(hu);
17891820 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
17901821
1791− hu->hdev->hw_error = NULL;
1792− hu->hdev->cmd_timeout = NULL;
1793−
17941822 /* Non-serdev device usually is powered by external power
17951823 * and don't need additional action in driver for power down
17961824 */
@@ -1812,6 +1840,9 @@ static int qca_power_off(struct hci_dev *hdev) · 15 unmodified lines
18121840 struct qca_data *qca = hu->priv;
18131841 enum qca_btsoc_type soc_type = qca_soc_type(hu);
18141842
1843+ hu->hdev->hw_error = NULL;
1844+ hu->hdev->cmd_timeout = NULL;
1845+
18151846 /* Stop sending shutdown command if soc crashes. */
18161847 if (soc_type != QCA_ROME
18171848 && qca->memdump_state == QCA_MEMDUMP_IDLE) {
@@ -1819,7 +1850,6 @@ static int qca_power_off(struct hci_dev *hdev) · 1 unmodified line
18191850 usleep_range(8000, 10000);
18201851 }
18211852
1822− qca->memdump_state = QCA_MEMDUMP_IDLE;
18231853 qca_power_shutdown(hu);
18241854 return 0;
18251855 }
@@ -1962,17 +1992,17 @@ static int qca_serdev_probe(struct serdev_device *serdev) · 136 unmodified lines
19621992 }
19631993
19641994 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
1965− if (!qcadev->susclk) {
1995+ if (IS_ERR(qcadev->susclk)) {
19661996 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);
19751998 }
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;
19762006
19772007 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
19782008 if (err) {
@@ -2050,6 +2080,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 71 unmodified lines
20502080 struct hci_uart *hu = &qcadev->serdev_hu;
20512081 struct qca_data *qca = hu->priv;
20522082 unsigned long flags;
2083+ bool tx_pending = false;
20532084 int ret = 0;
20542085 u8 cmd;
20552086
@@ -2068,7 +2099,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 12 unmodified lines
20682099 switch (qca->tx_ibs_state) {
20692100 case HCI_IBS_TX_WAKING:
20702101 del_timer(&qca->wake_retrans_timer);
2071− /* Fall through */
2102+ fallthrough;
20722103 case HCI_IBS_TX_AWAKE:
20732104 del_timer(&qca->tx_idle_timer);
20742105
@@ -2083,8 +2114,7 @@ static int __maybe_unused qca_suspend(struct device *dev) · 8 unmodified lines
20832114
20842115 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
20852116 qca->ibs_sent_slps++;
2086−
2087− qca_wq_serial_tx_clock_vote_off(&qca->ws_tx_vote_off);
2117+ tx_pending = true;
20882118 break;
20892119
20902120 case HCI_IBS_TX_ASLEEP:
@@ -2101,22 +2131,24 @@ static int __maybe_unused qca_suspend(struct device *dev) · 10 unmodified lines
21012131 if (ret < 0)
21022132 goto error;
21032133
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+ }
21062139
21072140 /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going
21082141 * to sleep, so that the packet does not wake the system later.
21092142 */
2110−
21112143 ret = wait_event_interruptible_timeout(qca->suspend_wait_q,
21122144 qca->rx_ibs_state == HCI_IBS_RX_ASLEEP,
21132145 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) {
21192147 ret = -ETIMEDOUT;
2148+ goto error;
2149+ }
2150+
2151+ return 0;
21202152
21212153 error:
21222154 clear_bit(QCA_SUSPENDING, &qca->flags);
drivers/bluetooth/hci_serdev.c+2−1
@@ -355,7 +355,8 @@ void hci_uart_unregister_device(struct hci_uart *hu) · 354 unmodified lines
355355 struct hci_dev *hdev = hu->hdev;
356356
357357 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);
359360 hci_free_dev(hdev);
360361
361362 cancel_work_sync(&hu->write_work);
drivers/net/wireless/marvell/mwifiex/sdio.h+2−2
@@ -36,9 +36,9 @@ · 35 unmodified lines
3636 #define SD8897_DEFAULT_FW_NAME "mrvl/sd8897_uapsta.bin"
3737 #define SD8887_DEFAULT_FW_NAME "mrvl/sd8887_uapsta.bin"
3838 #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"
4040 #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"
4242
4343 #define BLOCK_MODE 1
4444 #define BYTE_MODE 0
include/net/bluetooth/bluetooth.h+12−0
@@ -41,6 +41,8 @@ · 40 unmodified lines
4141 #define BLUETOOTH_VER_1_1 1
4242 #define BLUETOOTH_VER_1_2 2
4343 #define BLUETOOTH_VER_2_0 3
44+#define BLUETOOTH_VER_2_1 4
45+#define BLUETOOTH_VER_4_0 6
4446
4547 /* Reserv for core and drivers use */
4648 #define BT_SKB_RESERVE 8
@@ -147,6 +149,10 @@ struct bt_voice { · 100 unmodified lines
147149 #define BT_MODE_LE_FLOWCTL 0x03
148150 #define BT_MODE_EXT_FLOWCTL 0x04
149151
152+#define BT_PKT_STATUS 16
153+
154+#define BT_SCM_PKT_STATUS 0x03
155+
150156 __printf(1, 2)
151157 void bt_info(const char *fmt, ...);
152158 __printf(1, 2)
@@ -286,6 +292,7 @@ struct bt_sock { · 133 unmodified lines
286292 struct sock *parent;
287293 unsigned long flags;
288294 void (*skb_msg_name)(struct sk_buff *, void *, int *);
295+ void (*skb_put_cmsg)(struct sk_buff *, struct msghdr *, struct sock *);
289296 };
290297
291298 enum {
@@ -335,6 +342,10 @@ struct l2cap_ctrl { · 43 unmodified lines
335342 struct l2cap_chan *chan;
336343 };
337344
345+struct sco_ctrl {
346+ u8 pkt_status;
347+};
348+
338349 struct hci_dev;
339350
340351 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
361372 u8 incoming:1;
362373 union {
363374 struct l2cap_ctrl l2cap;
375+ struct sco_ctrl sco;
364376 struct hci_ctrl hci;
365377 };
366378 };
include/net/bluetooth/hci.h+26−2
@@ -227,6 +227,17 @@ enum { · 226 unmodified lines
227227 * supported.
228228 */
229229 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,
230241 };
231242
232243 /* HCI device flags */
@@ -307,6 +318,7 @@ enum { · 74 unmodified lines
307318 HCI_FORCE_BREDR_SMP,
308319 HCI_FORCE_STATIC_ADDR,
309320 HCI_LL_RPA_RESOLUTION,
321+ HCI_ENABLE_LL_PRIVACY,
310322 HCI_CMD_PENDING,
311323 HCI_FORCE_NO_MITM,
312324
@@ -1637,6 +1649,8 @@ struct hci_rp_le_read_resolv_list_size { · 1324 unmodified lines
16371649
16381650 #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d
16391651
1652+#define HCI_OP_LE_SET_RPA_TIMEOUT 0x202e
1653+
16401654 #define HCI_OP_LE_READ_MAX_DATA_LEN 0x202f
16411655 struct hci_rp_le_read_max_data_len {
16421656 __u8 status;
@@ -2268,8 +2282,10 @@ struct hci_ev_le_conn_complete { · 625 unmodified lines
22682282 #define LE_EXT_ADV_SCAN_RSP 0x0008
22692283 #define LE_EXT_ADV_LEGACY_PDU 0x0010
22702284
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
22732289
22742290 #define HCI_EV_LE_ADVERTISING_REPORT 0x02
22752291 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
25162532 #define hci_iso_data_len(h) ((h) & 0x3fff)
25172533 #define hci_iso_data_flags(h) ((h) >> 14)
25182534
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+
25192543 #endif /* __HCI_H */
include/net/bluetooth/hci_core.h+96−11
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #ifndef __HCI_CORE_H
2626 #define __HCI_CORE_H
2727
28+#include <linux/idr.h>
2829 #include <linux/leds.h>
2930 #include <linux/rculist.h>
3031
@@ -136,6 +137,23 @@ struct bdaddr_list_with_irk { · 105 unmodified lines
136137 u8 local_irk[16];
137138 };
138139
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+
139157 struct bt_uuid {
140158 struct list_head list;
141159 u8 uuid[16];
@@ -220,6 +238,24 @@ struct adv_info { · 78 unmodified lines
220238 #define HCI_MAX_ADV_INSTANCES 5
221239 #define HCI_DEFAULT_ADV_DURATION 2
222240
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+
223259 #define HCI_MAX_SHORT_NAME_LENGTH 10
224260
225261 /* Min encryption key size to match with SMP */
@@ -295,6 +331,14 @@ struct hci_dev { · 69 unmodified lines
295331 __u8 le_scan_type;
296332 __u16 le_scan_interval;
297333 __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;
298342 __u16 le_conn_min_interval;
299343 __u16 le_conn_max_interval;
300344 __u16 le_conn_latency;
@@ -323,6 +367,17 @@ struct hci_dev { · 22 unmodified lines
323367 __u16 devid_product;
324368 __u16 devid_version;
325369
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+
326381 __u16 pkt_type;
327382 __u16 esco_type;
328383 __u16 link_policy;
@@ -438,7 +493,6 @@ struct hci_dev { · 109 unmodified lines
438493 struct list_head mgmt_pending;
439494 struct list_head blacklist;
440495 struct list_head whitelist;
441− struct list_head wakeable;
442496 struct list_head uuids;
443497 struct list_head link_keys;
444498 struct list_head long_term_keys;
@@ -477,6 +531,9 @@ struct hci_dev { · 32 unmodified lines
477531 __u16 adv_instance_timeout;
478532 struct delayed_work adv_instance_expire;
479533
534+ struct idr adv_monitors_idr;
535+ unsigned int adv_monitors_cnt;
536+
480537 __u8 irk[16];
481538 __u32 rpa_timeout;
482539 struct delayed_work rpa_expired;
@@ -508,6 +565,12 @@ struct hci_dev { · 25 unmodified lines
508565
509566 #define HCI_PHY_HANDLE(handle) (handle & 0xff)
510567
568+enum conn_reasons {
569+ CONN_REASON_PAIR_DEVICE,
570+ CONN_REASON_L2CAP_CHAN,
571+ CONN_REASON_SCO_CONNECT,
572+};
573+
511574 struct hci_conn {
512575 struct list_head list;
513576
@@ -559,6 +622,8 @@ struct hci_conn { · 45 unmodified lines
559622 __s8 max_tx_power;
560623 unsigned long flags;
561624
625+ enum conn_reasons conn_reason;
626+
562627 __u32 clock;
563628 __u16 clock_accuracy;
564629
@@ -626,7 +691,7 @@ struct hci_conn_params { · 61 unmodified lines
626691
627692 struct hci_conn *conn;
628693 bool explicit_connect;
629− bool wakeable;
694+ u32 current_flags;
630695 };
631696
632697 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
9841049
9851050 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
9861051 u8 dst_type, u8 sec_level,
987− u16 conn_timeout);
1052+ u16 conn_timeout,
1053+ enum conn_reasons conn_reason);
9881054 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
9891055 u8 dst_type, u8 sec_level, u16 conn_timeout,
9901056 u8 role, bdaddr_t *direct_rpa);
9911057 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);
9931060 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
9941061 __u16 setting);
9951062 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
11511218 struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
11521219 struct list_head *list, bdaddr_t *bdaddr,
11531220 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);
11541224 int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
11551225 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);
11571229 int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
11581230 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);
11601234 void hci_bdaddr_list_clear(struct list_head *list);
11611235
11621236 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
12171291 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
12181292 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
12191293
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+
12201300 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
12211301
12221302 void hci_init_sysfs(struct hci_dev *hdev);
@@ -1279,6 +1359,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn); · 56 unmodified lines
12791359 #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
12801360 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
12811361
1362+/* Use LL Privacy based address resolution if supported */
1363+#define use_ll_privacy(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1364+
12821365 /* Use ext scanning if set ext scan param and ext scan enable is supported */
12831366 #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
12841367 ((dev)->commands[37] & 0x40))
@@ -1387,7 +1470,7 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 102 unmodified lines
13871470 __u8 encrypt;
13881471
13891472 if (conn->state == BT_CONFIG) {
1390− if (status)
1473+ if (!status)
13911474 conn->state = BT_CONNECTED;
13921475
13931476 hci_connect_cfm(conn, status);
@@ -1402,11 +1485,13 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) · 8 unmodified lines
14021485 else
14031486 encrypt = 0x01;
14041487
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;
14071491
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+ }
14101495
14111496 mutex_lock(&hci_cb_list_lock);
14121497 list_for_each_entry(cb, &hci_cb_list, list) {
include/net/bluetooth/hci_sock.h+2−2
@@ -31,8 +31,8 @@ · 30 unmodified lines
3131 #define HCI_TIME_STAMP 3
3232
3333 /* 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
3636
3737 struct sockaddr_hci {
3838 sa_family_t hci_family;
include/net/bluetooth/mgmt.h+95−0
@@ -52,6 +52,12 @@ struct mgmt_hdr { · 51 unmodified lines
5252 __le16 len;
5353 } __packed;
5454
55+struct mgmt_tlv {
56+ __le16 type;
57+ __u8 length;
58+ __u8 value[];
59+} __packed;
60+
5561 struct mgmt_addr_info {
5662 bdaddr_t bdaddr;
5763 __u8 type;
@@ -702,6 +708,78 @@ struct mgmt_rp_set_exp_feature { · 644 unmodified lines
702708 __le32 flags;
703709 } __packed;
704710
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+
705783 #define MGMT_EV_CMD_COMPLETE 0x0001
706784 struct mgmt_ev_cmd_complete {
707785 __le16 opcode;
@@ -933,3 +1011,20 @@ struct mgmt_ev_exp_feature_changed { · 225 unmodified lines
9331011 __u8 uuid[16];
9341012 __le32 flags;
9351013 } __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;
include/net/bluetooth/sco.h+2−0
@@ -46,4 +46,6 @@ struct sco_conninfo { · 45 unmodified lines
4646 __u8 dev_class[3];
4747 };
4848
49+#define SCO_CMSG_PKT_STATUS 0x01
50+
4951 #endif /* __SCO_H */
net/bluetooth/6lowpan.c+5−0
@@ -50,6 +50,7 @@ static bool enable_6lowpan; · 49 unmodified lines
5050 /* We are listening incoming connections via this channel
5151 */
5252 static struct l2cap_chan *listen_chan;
53+static DEFINE_MUTEX(set_lock);
5354
5455 struct lowpan_peer {
5556 struct list_head list;
@@ -1078,12 +1079,14 @@ static void do_enable_set(struct work_struct *work) · 1022 unmodified lines
10781079
10791080 enable_6lowpan = set_enable->flag;
10801081
1082+ mutex_lock(&set_lock);
10811083 if (listen_chan) {
10821084 l2cap_chan_close(listen_chan, 0);
10831085 l2cap_chan_put(listen_chan);
10841086 }
10851087
10861088 listen_chan = bt_6lowpan_listen();
1089+ mutex_unlock(&set_lock);
10871090
10881091 kfree(set_enable);
10891092 }
@@ -1135,11 +1138,13 @@ static ssize_t lowpan_control_write(struct file *fp, · 45 unmodified lines
11351138 if (ret == -EINVAL)
11361139 return ret;
11371140
1141+ mutex_lock(&set_lock);
11381142 if (listen_chan) {
11391143 l2cap_chan_close(listen_chan, 0);
11401144 l2cap_chan_put(listen_chan);
11411145 listen_chan = NULL;
11421146 }
1147+ mutex_unlock(&set_lock);
11431148
11441149 if (conn) {
11451150 struct lowpan_peer *peer;
net/bluetooth/Kconfig+1−1
@@ -21,7 +21,7 @@ menuconfig BT · 20 unmodified lines
2121 It was designed as a replacement for cables and other short-range
2222 technologies like IrDA. Bluetooth operates in personal area range
2323 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/>.
2525
2626 Linux Bluetooth subsystem consist of several layers:
2727 Bluetooth Core
net/bluetooth/Makefile+1−1
@@ -14,7 +14,7 @@ bluetooth_6lowpan-y := 6lowpan.o · 13 unmodified lines
1414
1515 bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
1616 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
1818
1919 bluetooth-$(CONFIG_BT_BREDR) += sco.o
2020 bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o
net/bluetooth/af_bluetooth.c+3−2
@@ -286,6 +286,9 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, · 285 unmodified lines
286286 if (msg->msg_name && bt_sk(sk)->skb_msg_name)
287287 bt_sk(sk)->skb_msg_name(skb, msg->msg_name,
288288 &msg->msg_namelen);
289+
290+ if (bt_sk(sk)->skb_put_cmsg)
291+ bt_sk(sk)->skb_put_cmsg(skb, msg, sk);
289292 }
290293
291294 skb_free_datagram(sk, skb);
@@ -453,8 +456,6 @@ __poll_t bt_sock_poll(struct file *file, struct socket *sock, · 161 unmodified lines
453456 struct sock *sk = sock->sk;
454457 __poll_t mask = 0;
455458
456− BT_DBG("sock %p, sk %p", sock, sk);
457−
458459 poll_wait(file, sk_sleep(sk), wait);
459460
460461 if (sk->sk_state == BT_LISTEN)
net/bluetooth/hci_conn.c+36−15
@@ -789,11 +789,8 @@ static void set_ext_conn_params(struct hci_conn *conn, · 788 unmodified lines
789789
790790 memset(p, 0, sizeof(*p));
791791
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);
797794 p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
798795 p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
799796 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
875872
876873 memset(&cp, 0, sizeof(cp));
877874
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);
883877
884878 bacpy(&cp.peer_addr, &conn->dst);
885879 cp.peer_addr_type = conn->dst_type;
@@ -937,7 +931,7 @@ static void hci_req_directed_advertising(struct hci_request *req, · 51 unmodified lines
937931 * So it is required to remove adv set for handle 0x00. since we use
938932 * instance 0 for directed adv.
939933 */
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);
941935
942936 hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
943937
@@ -1009,6 +1003,11 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, · 65 unmodified lines
10091003 struct hci_request req;
10101004 int err;
10111005
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+
10121011 /* Let's make sure that le is enabled.*/
10131012 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
10141013 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
11091108 * state.
11101109 */
11111110 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);
11131112 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED);
11141113 }
11151114
@@ -1180,7 +1179,8 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev, · 64 unmodified lines
11801179 /* This function requires the caller holds hdev->lock */
11811180 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
11821181 u8 dst_type, u8 sec_level,
1183− u16 conn_timeout)
1182+ u16 conn_timeout,
1183+ enum conn_reasons conn_reason)
11841184 {
11851185 struct hci_conn *conn;
11861186
@@ -1225,6 +1225,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, · 38 unmodified lines
12251225 conn->sec_level = BT_SECURITY_LOW;
12261226 conn->pending_sec_level = sec_level;
12271227 conn->conn_timeout = conn_timeout;
1228+ conn->conn_reason = conn_reason;
12281229
12291230 hci_update_background_scan(hdev);
12301231
@@ -1234,7 +1235,8 @@ done: · 3 unmodified lines
12341235 }
12351236
12361237 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)
12381240 {
12391241 struct hci_conn *acl;
12401242
@@ -1254,6 +1256,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, · 13 unmodified lines
12541256
12551257 hci_conn_hold(acl);
12561258
1259+ acl->conn_reason = conn_reason;
12571260 if (acl->state == BT_OPEN || acl->state == BT_CLOSED) {
12581261 acl->sec_level = BT_SECURITY_LOW;
12591262 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
12701273 struct hci_conn *acl;
12711274 struct hci_conn *sco;
12721275
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);
12741278 if (IS_ERR(acl))
12751279 return acl;
12761280
@@ -1323,6 +1327,23 @@ int hci_conn_check_link_mode(struct hci_conn *conn) · 46 unmodified lines
13231327 return 0;
13241328 }
13251329
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+
13261347 if (hci_conn_ssp_enabled(conn) &&
13271348 !test_bit(HCI_CONN_ENCRYPT, &conn->flags))
13281349 return 0;
net/bluetooth/hci_core.c+198−14
@@ -26,7 +26,6 @@ · 25 unmodified lines
2626 /* Bluetooth HCI core. */
2727
2828 #include <linux/export.h>
29−#include <linux/idr.h>
3029 #include <linux/rfkill.h>
3130 #include <linux/debugfs.h>
3231 #include <linux/crypto.h>
@@ -606,7 +605,8 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) · 573 unmodified lines
606605 if (hdev->commands[8] & 0x01)
607606 hci_req_add(req, HCI_OP_READ_PAGE_SCAN_ACTIVITY, 0, NULL);
608607
609− if (hdev->commands[18] & 0x04)
608+ if (hdev->commands[18] & 0x04 &&
609+ !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks))
610610 hci_req_add(req, HCI_OP_READ_DEF_ERR_DATA_REPORTING, 0, NULL);
611611
612612 /* 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
763763 hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL);
764764 }
765765
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+
766774 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) {
767775 /* Read LE Maximum Data Length */
768776 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
851859 /* Set erroneous data reporting if supported to the wideband speech
852860 * setting value
853861 */
854− if (hdev->commands[18] & 0x08) {
862+ if (hdev->commands[18] & 0x08 &&
863+ !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) {
855864 bool enabled = hci_dev_test_flag(hdev,
856865 HCI_WIDEBAND_SPEECH_ENABLED);
857866
@@ -2982,7 +2991,7 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 2124 unmodified lines
29822991 adv_instance->remaining_time = timeout;
29832992
29842993 if (duration == 0)
2985− adv_instance->duration = HCI_DEFAULT_ADV_DURATION;
2994+ adv_instance->duration = hdev->def_multi_adv_rotation_duration;
29862995 else
29872996 adv_instance->duration = duration;
29882997
@@ -2996,6 +3005,94 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, · 7 unmodified lines
29963005 return 0;
29973006 }
29983007
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+
29993096 struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *bdaddr_list,
30003097 bdaddr_t *bdaddr, u8 type)
30013098 {
@@ -3023,6 +3120,20 @@ struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( · 21 unmodified lines
30233120 return NULL;
30243121 }
30253122
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+
30263137 void hci_bdaddr_list_clear(struct list_head *bdaddr_list)
30273138 {
30283139 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
30843195 return 0;
30853196 }
30863197
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+
30873222 int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type)
30883223 {
30893224 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
31233258 return 0;
31243259 }
31253260
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+
31263281 /* This function requires the caller holds hdev->lock */
31273282 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
31283283 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
31453300 {
31463301 struct hci_conn_params *param;
31473302
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+
31483312 list_for_each_entry(param, list, action) {
31493313 if (bacmp(&param->addr, addr) == 0 &&
31503314 param->addr_type == addr_type)
@@ -3289,10 +3453,10 @@ static int hci_suspend_wait_event(struct hci_dev *hdev) · 138 unmodified lines
32893453 WAKE_COND, SUSPEND_NOTIFIER_TIMEOUT);
32903454
32913455 if (ret == 0) {
3292− bt_dev_dbg(hdev, "Timed out waiting for suspend");
3456+ bt_dev_err(hdev, "Timed out waiting for suspend events");
32933457 for (i = 0; i < __SUSPEND_NUM_TASKS; ++i) {
32943458 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);
32963460 clear_bit(i, hdev->suspend_tasks);
32973461 }
32983462
@@ -3360,12 +3524,15 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action, · 61 unmodified lines
33603524 ret = hci_change_suspend_state(hdev, BT_RUNNING);
33613525 }
33623526
3363− /* If suspend failed, restore it to running */
3364− if (ret && action == PM_SUSPEND_PREPARE)
3365− hci_change_suspend_state(hdev, BT_RUNNING);
3366−
33673527 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;
33693536 }
33703537
33713538 /* Alloc HCI device */
@@ -3397,6 +3564,12 @@ struct hci_dev *hci_alloc_dev(void) · 25 unmodified lines
33973564 hdev->le_adv_max_interval = 0x0800;
33983565 hdev->le_scan_interval = 0x0060;
33993566 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;
34003573 hdev->le_conn_min_interval = 0x0018;
34013574 hdev->le_conn_max_interval = 0x0028;
34023575 hdev->le_conn_latency = 0x0000;
@@ -3412,6 +3585,8 @@ struct hci_dev *hci_alloc_dev(void) · 9 unmodified lines
34123585 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
34133586 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
34143587 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;
34153590
34163591 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
34173592 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
@@ -3420,13 +3595,17 @@ struct hci_dev *hci_alloc_dev(void) · 2 unmodified lines
34203595 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
34213596 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE;
34223597
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+
34233603 mutex_init(&hdev->lock);
34243604 mutex_init(&hdev->req_lock);
34253605
34263606 INIT_LIST_HEAD(&hdev->mgmt_pending);
34273607 INIT_LIST_HEAD(&hdev->blacklist);
34283608 INIT_LIST_HEAD(&hdev->whitelist);
3429− INIT_LIST_HEAD(&hdev->wakeable);
34303609 INIT_LIST_HEAD(&hdev->uuids);
34313610 INIT_LIST_HEAD(&hdev->link_keys);
34323611 INIT_LIST_HEAD(&hdev->long_term_keys);
@@ -3574,6 +3753,8 @@ int hci_register_dev(struct hci_dev *hdev) · 141 unmodified lines
35743753
35753754 queue_work(hdev->req_workqueue, &hdev->power_on);
35763755
3756+ idr_init(&hdev->adv_monitors_idr);
3757+
35773758 return id;
35783759
35793760 err_wqueue:
@@ -3603,9 +3784,10 @@ void hci_unregister_dev(struct hci_dev *hdev) · 23 unmodified lines
36033784
36043785 cancel_work_sync(&hdev->power_on);
36053786
3606− hci_dev_do_close(hdev);
3607−
36083787 unregister_pm_notifier(&hdev->suspend_notifier);
3788+ cancel_work_sync(&hdev->suspend_prepare);
3789+
3790+ hci_dev_do_close(hdev);
36093791
36103792 if (!test_bit(HCI_INIT, &hdev->flags) &&
36113793 !hci_dev_test_flag(hdev, HCI_SETUP) &&
@@ -3644,6 +3826,7 @@ void hci_unregister_dev(struct hci_dev *hdev) · 32 unmodified lines
36443826 hci_smp_irks_clear(hdev);
36453827 hci_remote_oob_data_clear(hdev);
36463828 hci_adv_instances_clear(hdev);
3829+ hci_adv_monitors_clear(hdev);
36473830 hci_bdaddr_list_clear(&hdev->le_white_list);
36483831 hci_bdaddr_list_clear(&hdev->le_resolv_list);
36493832 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
45514734
45524735 if (conn) {
45534736 /* Send to upper protocol */
4737+ bt_cb(skb)->sco.pkt_status = flags & 0x03;
45544738 sco_recv_scodata(conn, skb);
45554739 return;
45564740 } else {
net/bluetooth/hci_event.c+48−23
@@ -2296,6 +2296,22 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, · 2295 unmodified lines
22962296 if (!conn)
22972297 return;
22982298
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+
22992315 /* Store the initiator and responder address information which
23002316 * is needed for SMP. These values will not change during the
23012317 * 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
25172533
25182534 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
25192535
2520− if (!num_rsp)
2536+ if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1)
25212537 return;
25222538
25232539 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
26972713 */
26982714 if (hci_dev_test_flag(hdev, HCI_MGMT) &&
26992715 !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;
27042720 }
27052721
27062722 /* Connection accepted */
@@ -2825,7 +2841,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) · 118 unmodified lines
28252841 case HCI_AUTO_CONN_LINK_LOSS:
28262842 if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT)
28272843 break;
2828− /* Fall through */
2844+ fallthrough;
28292845
28302846 case HCI_AUTO_CONN_DIRECT:
28312847 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
30653081
30663082 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
30673083
3084+ /* Check link security requirements are met */
3085+ if (!hci_conn_check_link_mode(conn))
3086+ ev->status = HCI_ERROR_AUTH_FAILURE;
3087+
30683088 if (ev->status && conn->state == BT_CONNECTED) {
30693089 if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING)
30703090 set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags);
30713091
3092+ /* Notify upper layers so they can cleanup before
3093+ * disconnecting.
3094+ */
3095+ hci_encrypt_cfm(conn, ev->status);
30723096 hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
30733097 hci_conn_drop(conn);
30743098 goto unlock;
30753099 }
30763100
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−
30893101 /* Try reading the encryption key size for encrypted ACL links */
30903102 if (!ev->status && ev->encrypt && conn->type == ACL_LINK) {
30913103 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
41634175 struct inquiry_info_with_rssi_and_pscan_mode *info;
41644176 info = (void *) (skb->data + 1);
41654177
4178+ if (skb->len < num_rsp * sizeof(*info) + 1)
4179+ goto unlock;
4180+
41664181 for (; num_rsp; num_rsp--, info++) {
41674182 u32 flags;
41684183
@@ -4184,6 +4199,9 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 15 unmodified lines
41844199 } else {
41854200 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
41864201
4202+ if (skb->len < num_rsp * sizeof(*info) + 1)
4203+ goto unlock;
4204+
41874205 for (; num_rsp; num_rsp--, info++) {
41884206 u32 flags;
41894207
@@ -4204,6 +4222,7 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 14 unmodified lines
42044222 }
42054223 }
42064224
4225+unlock:
42074226 hci_dev_unlock(hdev);
42084227 }
42094228
@@ -4324,7 +4343,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, · 114 unmodified lines
43244343 if (hci_setup_sync(conn, conn->link->handle))
43254344 goto unlock;
43264345 }
4327− /* fall through */
4346+ fallthrough;
43284347
43294348 default:
43304349 conn->state = BT_CLOSED;
@@ -4379,7 +4398,7 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · 48 unmodified lines
43794398
43804399 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
43814400
4382− if (!num_rsp)
4401+ if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1)
43834402 return;
43844403
43854404 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
52095228 le16_to_cpu(ev->interval),
52105229 le16_to_cpu(ev->latency),
52115230 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);
52125236 }
52135237
52145238 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
53195343 }
53205344
53215345 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,
53235347 direct_rpa);
53245348 if (!IS_ERR(conn)) {
53255349 /* 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
54475471
54485472 /* Passive scanning shouldn't trigger any device found events,
54495473 * except for devices marked as CONN_REPORT for which we do send
5450− * device found events.
5474+ * device found events, or advertisement monitoring requested.
54515475 */
54525476 if (hdev->le_scan_type == LE_SCAN_PASSIVE) {
54535477 if (type == LE_ADV_DIRECT_IND)
54545478 return;
54555479
54565480 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))
54585483 return;
54595484
54605485 if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND)
net/bluetooth/hci_request.c+233−53
@@ -34,9 +34,6 @@ · 33 unmodified lines
3434 #define HCI_REQ_PEND 1
3535 #define HCI_REQ_CANCELED 2
3636
37−#define LE_SUSPEND_SCAN_WINDOW 0x0012
38−#define LE_SUSPEND_SCAN_INTERVAL 0x0400
39−
4037 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
4138 {
4239 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
366363 /* 160 msec page scan interval */
367364 acp.interval = cpu_to_le16(0x0100);
368365 } 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);
373368 }
374369
375− acp.window = cpu_to_le16(0x0012);
370+ acp.window = cpu_to_le16(hdev->def_page_scan_window);
376371
377372 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval ||
378373 __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
418413 */
419414 hci_discovery_filter_clear(hdev);
420415
416+ BT_DBG("%s ADV monitoring is %s", hdev->name,
417+ hci_is_adv_monitoring(hdev) ? "on" : "off");
418+
421419 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)) {
423422 /* 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.
426425 */
427426
428427 /* If controller is not scanning we are done. */
429428 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
430429 return;
431430
432− hci_req_add_le_scan_disable(req);
431+ hci_req_add_le_scan_disable(req, false);
433432
434433 BT_DBG("%s stopping background scanning", hdev->name);
435434 } else {
@@ -448,7 +447,7 @@ static void __hci_update_background_scan(struct hci_request *req) · 12 unmodified lines
448447 * don't miss any advertising (due to duplicates filter).
449448 */
450449 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);
452451
453452 hci_req_add_le_passive_scan(req);
454453
@@ -653,7 +652,7 @@ void __hci_req_update_eir(struct hci_request *req) · 198 unmodified lines
653652 hci_req_add(req, HCI_OP_WRITE_EIR, sizeof(cp), &cp);
654653 }
655654
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)
657656 {
658657 struct hci_dev *hdev = req->hdev;
659658
@@ -676,6 +675,15 @@ void hci_req_add_le_scan_disable(struct hci_request *req) · 16 unmodified lines
676675 cp.enable = LE_SCAN_DISABLE;
677676 hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
678677 }
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+ }
679687 }
680688
681689 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
689697 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from whitelist", &cp.bdaddr,
690698 cp.bdaddr_type);
691699 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+ }
692715 }
693716
694717 /* 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
709732 return -1;
710733
711734 /* White list can not be used with RPAs */
712− if (!allow_rpa &&
735+ if (!allow_rpa && !use_ll_privacy(hdev) &&
713736 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
714737 return -1;
715738 }
716739
717740 /* 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))
719743 return 0;
720744
721745 *num_entries += 1;
@@ -726,6 +750,28 @@ static int add_to_white_list(struct hci_request *req, · 4 unmodified lines
726750 cp.bdaddr_type);
727751 hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
728752
753+ if (use_ll_privacy(hdev)) {
754+ struct smp_irk *irk;
755+
756+ irk = hci_find_irk_by_addr(hdev, &params->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, &params->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+
729775 return 0;
730776 }
731777
@@ -766,7 +812,7 @@ static u8 update_white_list(struct hci_request *req) · 34 unmodified lines
766812 }
767813
768814 /* White list can not be used with RPAs */
769− if (!allow_rpa &&
815+ if (!allow_rpa && !use_ll_privacy(hdev) &&
770816 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) {
771817 return 0x00;
772818 }
@@ -798,6 +844,14 @@ static u8 update_white_list(struct hci_request *req) · 25 unmodified lines
798844 return 0x00;
799845 }
800846
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+
801855 /* Select filter policy to use white list */
802856 return 0x01;
803857 }
@@ -808,10 +862,24 @@ static bool scan_use_rpa(struct hci_dev *hdev) · 4 unmodified lines
808862 }
809863
810864 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)
812867 {
813868 struct hci_dev *hdev = req->hdev;
814869
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+
815883 /* Use ext scanning if set ext scan param and ext scan enable is
816884 * supported
817885 */
@@ -885,12 +953,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, · 67 unmodified lines
885953 }
886954 }
887955
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+ */
888981 void hci_req_add_le_passive_scan(struct hci_request *req)
889982 {
890983 struct hci_dev *hdev = req->hdev;
891984 u8 own_addr_type;
892985 u8 filter_policy;
893986 u16 window, interval;
987+ /* Background scanning should run with address resolution */
988+ bool addr_resolv = true;
894989
895990 if (hdev->scanning_paused) {
896991 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
9271022 filter_policy |= 0x02;
9281023
9291024 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;
9321030 } else {
9331031 window = hdev->le_scan_window;
9341032 interval = hdev->le_scan_interval;
@@ -936,7 +1034,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req) · 1 unmodified line
9361034
9371035 bt_dev_dbg(hdev, "LE passive scan with whitelist = %d", filter_policy);
9381036 hci_req_start_scan(req, LE_SCAN_PASSIVE, interval, window,
939− own_addr_type, filter_policy);
1037+ own_addr_type, filter_policy, addr_resolv);
9401038 }
9411039
9421040 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
9731071
9741072 static void hci_req_set_event_filter(struct hci_request *req)
9751073 {
976− struct bdaddr_list *b;
1074+ struct bdaddr_list_with_flags *b;
9771075 struct hci_cp_set_event_filter f;
9781076 struct hci_dev *hdev = req->hdev;
979− u8 scan;
1077+ u8 scan = SCAN_DISABLED;
9801078
9811079 /* Always clear event filter when starting */
9821080 hci_req_clear_event_filter(req);
9831081
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+
9851087 memset(&f, 0, sizeof(f));
9861088 bacpy(&f.addr_conn_flt.bdaddr, &b->bdaddr);
9871089 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
9901092
9911093 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr);
9921094 hci_req_add(req, HCI_OP_SET_EVENT_FLT, sizeof(f), &f);
1095+ scan = SCAN_PAGE;
9931096 }
9941097
995− scan = !list_empty(&hdev->wakeable) ? SCAN_PAGE : SCAN_DISABLED;
9961098 hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
9971099 }
9981100
9991101 static void hci_req_config_le_suspend_scan(struct hci_request *req)
10001102 {
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);
10031106
10041107 /* Configure params and enable scanning */
10051108 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
10651168 page_scan = SCAN_DISABLED;
10661169 hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE, 1, &page_scan);
10671170
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);
10701174
10711175 /* Mark task needing completion */
10721176 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
11601264 void __hci_req_disable_advertising(struct hci_request *req)
11611265 {
11621266 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);
11681268
1169− hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(cp), &cp);
11701269 } else {
11711270 u8 enable = 0x00;
11721271
@@ -1627,6 +1726,28 @@ int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) · 454 unmodified lines
16271726 return hci_req_run(&req, NULL);
16281727 }
16291728
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+
16301751 static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
16311752 {
16321753 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
17861907 int err;
17871908 struct adv_info *adv_instance;
17881909 bool secondary_adv;
1789− /* In ext adv set param interval is 3 octets */
1790− const u8 adv_interval[3] = { 0x00, 0x08, 0x00 };
17911910
17921911 if (instance > 0) {
17931912 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
18201939
18211940 memset(&cp, 0, sizeof(cp));
18221941
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);
18251945
18261946 secondary_adv = (flags & MGMT_ADV_FLAG_SEC_MASK);
18271947
@@ -1932,13 +2052,59 @@ int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance) · 104 unmodified lines
19322052 return 0;
19332053 }
19342054
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+
19352097 int __hci_req_start_ext_adv(struct hci_request *req, u8 instance)
19362098 {
19372099 struct hci_dev *hdev = req->hdev;
2100+ struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance);
19382101 int err;
19392102
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);
19422108
19432109 err = __hci_req_setup_ext_adv_instance(req, instance);
19442110 if (err < 0)
@@ -2086,7 +2252,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, · 141 unmodified lines
20862252 hci_dev_test_flag(hdev, HCI_ADVERTISING))
20872253 return;
20882254
2089− if (next_instance)
2255+ if (next_instance && !ext_adv_capable(hdev))
20902256 __hci_req_schedule_adv_instance(req, next_instance->instance,
20912257 false);
20922258 }
@@ -2128,7 +2294,13 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, · 35 unmodified lines
21282294 if (use_rpa) {
21292295 int to;
21302296
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;
21322304
21332305 if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) &&
21342306 !bacmp(&hdev->random_addr, &hdev->rpa))
@@ -2547,7 +2719,7 @@ static void bg_scan_update(struct work_struct *work) · 412 unmodified lines
25472719
25482720 static int le_scan_disable(struct hci_request *req, unsigned long opt)
25492721 {
2550− hci_req_add_le_scan_disable(req);
2722+ hci_req_add_le_scan_disable(req, false);
25512723 return 0;
25522724 }
25532725
@@ -2645,7 +2817,12 @@ static int le_scan_restart(struct hci_request *req, unsigned long opt) · 91 unmodified lines
26452817 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
26462818 return 0;
26472819
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);
26492826
26502827 if (use_ext_scan(hdev)) {
26512828 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
27252902 u8 own_addr_type;
27262903 /* White list is not used for discovery */
27272904 u8 filter_policy = 0x00;
2905+ /* Discovery doesn't require controller address resolution */
2906+ bool addr_resolv = false;
27282907 int err;
27292908
27302909 BT_DBG("%s", hdev->name);
@@ -2734,7 +2913,7 @@ static int active_scan(struct hci_request *req, unsigned long opt) · 3 unmodified lines
27342913 * discovery scanning parameters.
27352914 */
27362915 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);
27382917
27392918 /* All active scans will be done with either a resolvable private
27402919 * 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
27452924 if (err < 0)
27462925 own_addr_type = ADDR_LE_DEV_PUBLIC;
27472926
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);
27502930 return 0;
27512931 }
27522932
@@ -2793,18 +2973,18 @@ static void start_discovery(struct hci_dev *hdev, u8 *status) · 40 unmodified lines
27932973 * to do BR/EDR inquiry.
27942974 */
27952975 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,
27972977 status);
27982978 break;
27992979 }
28002980
28012981 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,
28032983 HCI_CMD_TIMEOUT, status);
28042984 break;
28052985 case DISCOV_TYPE_LE:
28062986 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,
28082988 HCI_CMD_TIMEOUT, status);
28092989 break;
28102990 default:
@@ -2848,14 +3028,14 @@ bool hci_req_stop_discovery(struct hci_request *req) · 37 unmodified lines
28483028
28493029 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
28503030 cancel_delayed_work(&hdev->le_scan_disable);
2851− hci_req_add_le_scan_disable(req);
3031+ hci_req_add_le_scan_disable(req, false);
28523032 }
28533033
28543034 ret = true;
28553035 } else {
28563036 /* Passive scanning */
28573037 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);
28593039 ret = true;
28603040 }
28613041 }
net/bluetooth/hci_request.h+4−1
@@ -65,11 +65,12 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable); · 64 unmodified lines
6565 void __hci_req_update_name(struct hci_request *req);
6666 void __hci_req_update_eir(struct hci_request *req);
6767
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);
6969 void hci_req_add_le_passive_scan(struct hci_request *req);
7070
7171 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);
7272
73+void hci_req_disable_address_resolution(struct hci_dev *hdev);
7374 void hci_req_reenable_advertising(struct hci_dev *hdev);
7475 void __hci_req_enable_advertising(struct hci_request *req);
7576 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
8687 int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance);
8788 int __hci_req_start_ext_adv(struct hci_request *req, u8 instance);
8889 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);
8992 void __hci_req_clear_ext_adv_sets(struct hci_request *req);
9093 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
9194 bool use_rpa, struct adv_info *adv_instance,
net/bluetooth/hci_sock.c+3−4
@@ -52,7 +52,7 @@ struct hci_pinfo { · 51 unmodified lines
5252 struct bt_sock bt;
5353 struct hci_dev *hdev;
5454 struct hci_filter filter;
55− __u32 cmsg_mask;
55+ __u8 cmsg_mask;
5656 unsigned short channel;
5757 unsigned long flags;
5858 __u32 cookie;
@@ -443,8 +443,7 @@ static struct sk_buff *create_monitor_event(struct hci_dev *hdev, int event) · 384 unmodified lines
443443 case HCI_DEV_SETUP:
444444 if (hdev->manufacturer == 0xffff)
445445 return NULL;
446−
447− /* fall through */
446+ fallthrough;
448447
449448 case HCI_DEV_UP:
450449 skb = bt_skb_alloc(HCI_MON_INDEX_INFO_SIZE, GFP_ATOMIC);
@@ -1399,7 +1398,7 @@ done: · 948 unmodified lines
13991398 static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg,
14001399 struct sk_buff *skb)
14011400 {
1402− __u32 mask = hci_pi(sk)->cmsg_mask;
1401+ __u8 mask = hci_pi(sk)->cmsg_mask;
14031402
14041403 if (mask & HCI_CMSG_DIR) {
14051404 int incoming = bt_cb(skb)->incoming;
net/bluetooth/l2cap_core.c+13−12
@@ -666,8 +666,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err) · 665 unmodified lines
666666
667667 l2cap_seq_list_free(&chan->srej_list);
668668 l2cap_seq_list_free(&chan->retrans_list);
669−
670− /* fall through */
669+ fallthrough;
671670
672671 case L2CAP_MODE_STREAMING:
673672 skb_queue_purge(&chan->tx_q);
@@ -872,7 +871,8 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) · 198 unmodified lines
872871 else
873872 return HCI_AT_NO_BONDING;
874873 }
875− /* fall through */
874+ fallthrough;
875+
876876 default:
877877 switch (chan->sec_level) {
878878 case BT_SECURITY_HIGH:
@@ -2983,8 +2983,7 @@ static void l2cap_tx_state_wait_f(struct l2cap_chan *chan, · 2104 unmodified lines
29832983 break;
29842984 case L2CAP_EV_RECV_REQSEQ_AND_FBIT:
29852985 l2cap_process_reqseq(chan, control->reqseq);
2986−
2987− /* Fall through */
2986+ fallthrough;
29882987
29892988 case L2CAP_EV_RECV_FBIT:
29902989 if (control && control->final) {
@@ -3311,7 +3310,7 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask) · 320 unmodified lines
33113310 case L2CAP_MODE_ERTM:
33123311 if (l2cap_mode_supported(mode, remote_feat_mask))
33133312 return mode;
3314− /* fall through */
3313+ fallthrough;
33153314 default:
33163315 return L2CAP_MODE_BASIC;
33173316 }
@@ -3447,7 +3446,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data, size_t data · 129 unmodified lines
34473446 if (__l2cap_efs_supported(chan->conn))
34483447 set_bit(FLAG_EFS_ENABLE, &chan->flags);
34493448
3450− /* fall through */
3449+ fallthrough;
34513450 default:
34523451 chan->mode = l2cap_select_mode(rfc.mode, chan->conn->feat_mask);
34533452 break;
@@ -4539,7 +4538,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, · 1085 unmodified lines
45394538 goto done;
45404539 break;
45414540 }
4542− /* fall through */
4541+ fallthrough;
45434542
45444543 default:
45454544 l2cap_chan_set_err(chan, ECONNRESET);
@@ -7719,7 +7718,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon) · 3173 unmodified lines
77197718 conn->mtu = hcon->hdev->le_mtu;
77207719 break;
77217720 }
7722− /* fall through */
7721+ fallthrough;
77237722 default:
77247723 conn->mtu = hcon->hdev->acl_mtu;
77257724 break;
@@ -7841,7 +7840,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, · 115 unmodified lines
78417840 case L2CAP_MODE_STREAMING:
78427841 if (!disable_ertm)
78437842 break;
7844− /* fall through */
7843+ fallthrough;
78457844 default:
78467845 err = -EOPNOTSUPP;
78477846 goto done;
@@ -7893,11 +7892,13 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, · 45 unmodified lines
78937892 else
78947893 hcon = hci_connect_le_scan(hdev, dst, dst_type,
78957894 chan->sec_level,
7896− HCI_LE_CONN_TIMEOUT);
7895+ HCI_LE_CONN_TIMEOUT,
7896+ CONN_REASON_L2CAP_CHAN);
78977897
78987898 } else {
78997899 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);
79017902 }
79027903
79037904 if (IS_ERR(hcon)) {
net/bluetooth/l2cap_sock.c+2−2
@@ -284,7 +284,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog) · 283 unmodified lines
284284 case L2CAP_MODE_STREAMING:
285285 if (!disable_ertm)
286286 break;
287− /* fall through */
287+ fallthrough;
288288 default:
289289 err = -EOPNOTSUPP;
290290 goto done;
@@ -760,7 +760,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, · 469 unmodified lines
760760 case L2CAP_MODE_STREAMING:
761761 if (!disable_ertm)
762762 break;
763− /* fall through */
763+ fallthrough;
764764 default:
765765 err = -EINVAL;
766766 break;
net/bluetooth/mgmt.c+563−14
@@ -36,9 +36,11 @@ · 35 unmodified lines
3636 #include "hci_request.h"
3737 #include "smp.h"
3838 #include "mgmt_util.h"
39+#include "mgmt_config.h"
40+#include "msft.h"
3941
4042 #define MGMT_VERSION 1
41−#define MGMT_REVISION 17
43+#define MGMT_REVISION 18
4244
4345 static const u16 mgmt_commands[] = {
4446 MGMT_OP_READ_INDEX_LIST,
@@ -111,6 +113,15 @@ static const u16 mgmt_commands[] = { · 66 unmodified lines
111113 MGMT_OP_READ_SECURITY_INFO,
112114 MGMT_OP_READ_EXP_FEATURES_INFO,
113115 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,
114125 };
115126
116127 static const u16 mgmt_events[] = {
@@ -151,6 +162,7 @@ static const u16 mgmt_events[] = { · 34 unmodified lines
151162 MGMT_EV_EXT_INFO_CHANGED,
152163 MGMT_EV_PHY_CONFIGURATION_CHANGED,
153164 MGMT_EV_EXP_FEATURE_CHANGED,
165+ MGMT_EV_DEVICE_FLAGS_CHANGED,
154166 };
155167
156168 static const u16 mgmt_untrusted_commands[] = {
@@ -162,6 +174,8 @@ static const u16 mgmt_untrusted_commands[] = { · 5 unmodified lines
162174 MGMT_OP_READ_EXT_INFO,
163175 MGMT_OP_READ_SECURITY_INFO,
164176 MGMT_OP_READ_EXP_FEATURES_INFO,
177+ MGMT_OP_READ_DEF_SYSTEM_CONFIG,
178+ MGMT_OP_READ_DEF_RUNTIME_CONFIG,
165179 };
166180
167181 static const u16 mgmt_untrusted_events[] = {
@@ -177,6 +191,8 @@ static const u16 mgmt_untrusted_events[] = { · 9 unmodified lines
177191 MGMT_EV_EXT_INDEX_REMOVED,
178192 MGMT_EV_EXT_INFO_CHANGED,
179193 MGMT_EV_EXP_FEATURE_CHANGED,
194+ MGMT_EV_ADV_MONITOR_ADDED,
195+ MGMT_EV_ADV_MONITOR_REMOVED,
180196 };
181197
182198 #define CACHE_TIMEOUT msecs_to_jiffies(2 * 1000)
@@ -779,10 +795,15 @@ static u32 get_supported_settings(struct hci_dev *hdev) · 596 unmodified lines
779795
780796 if (lmp_le_capable(hdev)) {
781797 settings |= MGMT_SETTING_LE;
782− settings |= MGMT_SETTING_ADVERTISING;
783798 settings |= MGMT_SETTING_SECURE_CONN;
784799 settings |= MGMT_SETTING_PRIVACY;
785800 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;
786807 }
787808
788809 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
29152936
29162937 if (cp->addr.type == BDADDR_BREDR) {
29172938 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level,
2918− auth_type);
2939+ auth_type, CONN_REASON_PAIR_DEVICE);
29192940 } else {
29202941 u8 addr_type = le_addr_type(cp->addr.type);
29212942 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
29342955 if (p->auto_connect == HCI_AUTO_CONN_EXPLICIT)
29352956 p->auto_connect = HCI_AUTO_CONN_DISABLED;
29362957
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);
29402961 }
29412962
29422963 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
30373058
30383059 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0,
30393060 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+
30403075 unlock:
30413076 hci_dev_unlock(hdev);
30423077 return err;
@@ -3723,12 +3758,25 @@ static const u8 debug_uuid[16] = { · 680 unmodified lines
37233758 };
37243759 #endif
37253760
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+
37263773 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
37273774 void *data, u16 data_len)
37283775 {
3729− char buf[42];
3776+ char buf[62]; /* Enough space for 3 features */
37303777 struct mgmt_rp_read_exp_features_info *rp = (void *)buf;
37313778 u16 idx = 0;
3779+ u32 flags;
37323780
37333781 bt_dev_dbg(hdev, "sock %p", sk);
37343782
@@ -3736,7 +3784,7 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, · 1 unmodified line
37363784
37373785 #ifdef CONFIG_BT_FEATURE_DEBUG
37383786 if (!hdev) {
3739− u32 flags = bt_dbg_get() ? BIT(0) : 0;
3787+ flags = bt_dbg_get() ? BIT(0) : 0;
37403788
37413789 memcpy(rp->features[idx].uuid, debug_uuid, 16);
37423790 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
37443792 }
37453793 #endif
37463794
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+
37473820 rp->feature_count = cpu_to_le16(idx);
37483821
37493822 /* 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
37563829 0, rp, sizeof(*rp) + (20 * idx));
37573830 }
37583831
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+
37593847 #ifdef CONFIG_BT_FEATURE_DEBUG
37603848 static int exp_debug_feature_changed(bool enabled, struct sock *skip)
37613849 {
@@ -3794,6 +3882,16 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, · 32 unmodified lines
37943882 }
37953883 #endif
37963884
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+
37973895 hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
37983896
37993897 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
38443942 }
38453943 #endif
38463944
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+
38474008 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE,
38484009 MGMT_OP_SET_EXP_FEATURE,
38494010 MGMT_STATUS_NOT_SUPPORTED);
38504011 }
38514012
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+
38524340 static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
38534341 u16 opcode, struct sk_buff *skb)
38544342 {
@@ -4147,7 +4635,7 @@ static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, · 292 unmodified lines
41474635 *mgmt_status = mgmt_le_support(hdev);
41484636 if (*mgmt_status)
41494637 return false;
4150− /* Intentional fall-through */
4638+ fallthrough;
41514639 case DISCOV_TYPE_BREDR:
41524640 *mgmt_status = mgmt_bredr_support(hdev);
41534641 if (*mgmt_status)
@@ -4662,6 +5150,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, · 508 unmodified lines
46625150 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
46635151 status);
46645152
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+
46655160 if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)
46665161 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING,
46675162 MGMT_STATUS_INVALID_PARAMS);
@@ -4848,7 +5343,7 @@ static int set_scan_params(struct sock *sk, struct hci_dev *hdev, · 180 unmodified lines
48485343
48495344 hci_req_init(&req, hdev);
48505345
4851− hci_req_add_le_scan_disable(&req);
5346+ hci_req_add_le_scan_disable(&req, false);
48525347 hci_req_add_le_passive_scan(&req);
48535348
48545349 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
55236018 case MGMT_LTK_P256_DEBUG:
55246019 authenticated = 0x00;
55256020 type = SMP_LTK_P256_DEBUG;
5526− /* fall through */
6021+ fallthrough;
55276022 default:
55286023 continue;
55296024 }
@@ -5966,7 +6461,9 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 436 unmodified lines
59666461 {
59676462 struct mgmt_cp_add_device *cp = data;
59686463 u8 auto_conn, addr_type;
6464+ struct hci_conn_params *params;
59696465 int err;
6466+ u32 current_flags = 0;
59706467
59716468 bt_dev_dbg(hdev, "sock %p", sk);
59726469
@@ -5993,8 +6490,9 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 20 unmodified lines
59936490 goto unlock;
59946491 }
59956492
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);
59986496 if (err)
59996497 goto unlock;
60006498
@@ -6033,12 +6531,19 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, · 32 unmodified lines
60336531 MGMT_STATUS_FAILED, &cp->addr,
60346532 sizeof(cp->addr));
60356533 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;
60366539 }
60376540
60386541 hci_update_background_scan(hdev);
60396542
60406543 added:
60416544 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);
60426547
60436548 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
60446549 MGMT_STATUS_SUCCESS, &cp->addr,
@@ -6724,6 +7229,13 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev, · 679 unmodified lines
67247229 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES,
67257230 MGMT_STATUS_REJECTED);
67267231
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+
67277239 hci_dev_lock(hdev);
67287240
67297241 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
69277439 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
69287440 status);
69297441
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+
69307449 if (cp->instance < 1 || cp->instance > HCI_MAX_ADV_INSTANCES)
69317450 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
69327451 MGMT_STATUS_INVALID_PARAMS);
@@ -7091,6 +7610,13 @@ static int remove_advertising(struct sock *sk, struct hci_dev *hdev, · 158 unmodified lines
70917610
70927611 bt_dev_dbg(hdev, "sock %p", sk);
70937612
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+
70947620 hci_dev_lock(hdev);
70957621
70967622 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
71167642
71177643 hci_req_init(&req, hdev);
71187644
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+
71197651 hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true);
71207652
71217653 if (list_empty(&hdev->adv_instances))
@@ -7297,6 +7829,20 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { · 175 unmodified lines
72977829 { set_exp_feature, MGMT_SET_EXP_FEATURE_SIZE,
72987830 HCI_MGMT_VAR_LEN |
72997831 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 },
73007846 };
73017847
73027848 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
82168762 if (!hci_discovery_active(hdev)) {
82178763 if (link_type == ACL_LINK)
82188764 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)) {
82208768 return;
8769+ }
82218770 }
82228771
82238772 if (hdev->discovery.result_filtering) {
net/bluetooth/mgmt_config.c+283−0
@@ -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+}
net/bluetooth/mgmt_config.h+17−0
@@ -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);
net/bluetooth/msft.c+7−0
@@ -139,3 +139,10 @@ void msft_vendor_evt(struct hci_dev *hdev, struct sk_buff *skb) · 138 unmodified lines
139139
140140 bt_dev_dbg(hdev, "MSFT vendor event %u", event);
141141 }
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+}
net/bluetooth/msft.h+9−0
@@ -3,16 +3,25 @@ · 2 unmodified lines
33 * Copyright (C) 2020 Google Corporation
44 */
55
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+
613 #if IS_ENABLED(CONFIG_BT_MSFTEXT)
714
815 void msft_do_open(struct hci_dev *hdev);
916 void msft_do_close(struct hci_dev *hdev);
1017 void msft_vendor_evt(struct hci_dev *hdev, struct sk_buff *skb);
18+__u64 msft_get_features(struct hci_dev *hdev);
1119
1220 #else
1321
1422 static inline void msft_do_open(struct hci_dev *hdev) {}
1523 static inline void msft_do_close(struct hci_dev *hdev) {}
1624 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; }
1726
1827 #endif
net/bluetooth/rfcomm/core.c+1−1
@@ -479,7 +479,7 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) · 478 unmodified lines
479479 /* if closing a dlc in a session that hasn't been started,
480480 * just close and unlink the dlc
481481 */
482− /* fall through */
482+ fallthrough;
483483
484484 default:
485485 rfcomm_dlc_clear_timer(d);
net/bluetooth/rfcomm/sock.c+1−1
@@ -218,7 +218,7 @@ static void __rfcomm_sock_close(struct sock *sk) · 217 unmodified lines
218218 case BT_CONFIG:
219219 case BT_CONNECTED:
220220 rfcomm_dlc_close(d, 0);
221− /* fall through */
221+ fallthrough;
222222
223223 default:
224224 sock_set_flag(sk, SOCK_ZAPPED);
net/bluetooth/sco.c+32−0
@@ -66,6 +66,7 @@ struct sco_pinfo { · 65 unmodified lines
6666 bdaddr_t dst;
6767 __u32 flags;
6868 __u16 setting;
69+ __u8 cmsg_mask;
6970 struct sco_conn *conn;
7071 };
7172
@@ -449,6 +450,15 @@ static void sco_sock_close(struct sock *sk) · 377 unmodified lines
449450 sco_sock_kill(sk);
450451 }
451452
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+
452462 static void sco_sock_init(struct sock *sk, struct sock *parent)
453463 {
454464 BT_DBG("sk %p", sk);
@@ -457,6 +467,8 @@ static void sco_sock_init(struct sock *sk, struct sock *parent) · 2 unmodified lines
457467 sk->sk_type = parent->sk_type;
458468 bt_sk(sk)->flags = bt_sk(parent)->flags;
459469 security_sk_clone(parent, sk);
470+ } else {
471+ bt_sk(sk)->skb_put_cmsg = sco_skb_put_cmsg;
460472 }
461473 }
462474
@@ -846,6 +858,18 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, · 383 unmodified lines
846858 sco_pi(sk)->setting = voice.setting;
847859 break;
848860
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+
849873 default:
850874 err = -ENOPROTOOPT;
851875 break;
@@ -923,6 +947,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, · 71 unmodified lines
923947 int len, err = 0;
924948 struct bt_voice voice;
925949 u32 phys;
950+ int pkt_status;
926951
927952 BT_DBG("sk %p", sk);
928953
@@ -969,6 +994,13 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, · 40 unmodified lines
969994 err = -EFAULT;
970995 break;
971996
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+
9721004 default:
9731005 err = -ENOPROTOOPT;
9741006 break;
net/bluetooth/selftest.c+1−1
@@ -205,7 +205,7 @@ static int __init test_ecdh(void) · 204 unmodified lines
205205
206206 calltime = ktime_get();
207207
208− tfm = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0);
208+ tfm = crypto_alloc_kpp("ecdh", 0, 0);
209209 if (IS_ERR(tfm)) {
210210 BT_ERR("Unable to create ECDH crypto context");
211211 err = PTR_ERR(tfm);
net/bluetooth/smp.c+4−4
@@ -1387,7 +1387,7 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) · 1386 unmodified lines
13871387 goto zfree_smp;
13881388 }
13891389
1390− smp->tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0);
1390+ smp->tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0);
13911391 if (IS_ERR(smp->tfm_ecdh)) {
13921392 BT_ERR("Unable to create ECDH crypto context");
13931393 goto free_shash;
@@ -1654,7 +1654,7 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey) · 260 unmodified lines
16541654 memset(smp->tk, 0, sizeof(smp->tk));
16551655 BT_DBG("PassKey: %d", value);
16561656 put_unaligned_le32(value, smp->tk);
1657− /* Fall Through */
1657+ fallthrough;
16581658 case MGMT_OP_USER_CONFIRM_REPLY:
16591659 set_bit(SMP_FLAG_TK_VALID, &smp->flags);
16601660 break;
@@ -3282,7 +3282,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid) · 1621 unmodified lines
32823282 return ERR_CAST(tfm_cmac);
32833283 }
32843284
3285− tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0);
3285+ tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0);
32863286 if (IS_ERR(tfm_ecdh)) {
32873287 BT_ERR("Unable to create ECDH crypto context");
32883288 crypto_free_shash(tfm_cmac);
@@ -3847,7 +3847,7 @@ int __init bt_selftest_smp(void) · 558 unmodified lines
38473847 return PTR_ERR(tfm_cmac);
38483848 }
38493849
3850− tfm_ecdh = crypto_alloc_kpp("ecdh", CRYPTO_ALG_INTERNAL, 0);
3850+ tfm_ecdh = crypto_alloc_kpp("ecdh", 0, 0);
38513851 if (IS_ERR(tfm_ecdh)) {
38523852 BT_ERR("Unable to create ECDH crypto context");
38533853 crypto_free_shash(tfm_cmac);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t