]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
Bluetooth: btusb: Configure altsetting for HCI_USER_CHANNEL
authorHsin-chen Chuang <chharry@chromium.org>
Thu, 27 Feb 2025 17:14:10 +0000 (01:14 +0800)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 7 Mar 2025 17:43:27 +0000 (12:43 -0500)
Automatically configure the altsetting for HCI_USER_CHANNEL when a SCO
is connected.

The motivation is to enable the HCI_USER_CHANNEL user to send out SCO
data through USB Bluetooth chips, which is mainly used for bidirectional
audio transfer (voice call). This was not capable because:

- Per Bluetooth Core Spec v5, Vol 4, Part B, 2.1, the corresponding
  alternate setting should be set based on the air mode in order to
  transfer SCO data, but
- The Linux Bluetooth HCI_USER_CHANNEL exposes the Bluetooth Host
  Controller Interface to the user space, which is something above the
  USB layer. The user space is not able to configure the USB alt while
  keeping the channel open.

This patch intercepts the HCI_EV_SYNC_CONN_COMPLETE packets in btusb,
extracts the air mode, and configures the alt setting in btusb.

This patch is tested on ChromeOS devices. The USB Bluetooth models
(CVSD, TRANS alt3 and alt6) could work without a customized kernel.

Fixes: b16b327edb4d ("Bluetooth: btusb: add sysfs attribute to control USB alt setting")
Signed-off-by: Hsin-chen Chuang <chharry@chromium.org>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
drivers/bluetooth/Kconfig
drivers/bluetooth/btusb.c

index 4ab32abf0f48644715d4c27ec0d2fdaccef62b76..7771edf54fb3f1a7b9ddb5a2eae467e463f102ba 100644 (file)
@@ -56,6 +56,18 @@ config BT_HCIBTUSB_POLL_SYNC
          Say Y here to enable USB poll_sync for Bluetooth USB devices by
          default.
 
+config BT_HCIBTUSB_AUTO_ISOC_ALT
+       bool "Automatically adjust alternate setting for Isoc endpoints"
+       depends on BT_HCIBTUSB
+       default y if CHROME_PLATFORMS
+       help
+         Say Y here to automatically adjusting the alternate setting for
+         HCI_USER_CHANNEL whenever a SCO link is established.
+
+         When enabled, btusb intercepts the HCI_EV_SYNC_CONN_COMPLETE packets
+         and configures isoc endpoint alternate setting automatically when
+         HCI_USER_CHANNEL is in use.
+
 config BT_HCIBTUSB_BCM
        bool "Broadcom protocol support"
        depends on BT_HCIBTUSB
index 2a8d91963c63f5f216a380cf2cc32f3409acb835..a0fc465458b2f993a41af77b056d271f7b0938e9 100644 (file)
@@ -34,6 +34,7 @@ static bool force_scofix;
 static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND);
 static bool enable_poll_sync = IS_ENABLED(CONFIG_BT_HCIBTUSB_POLL_SYNC);
 static bool reset = true;
+static bool auto_isoc_alt = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTO_ISOC_ALT);
 
 static struct usb_driver btusb_driver;
 
@@ -1085,6 +1086,42 @@ static inline void btusb_free_frags(struct btusb_data *data)
        spin_unlock_irqrestore(&data->rxlock, flags);
 }
 
+static void btusb_sco_connected(struct btusb_data *data, struct sk_buff *skb)
+{
+       struct hci_event_hdr *hdr = (void *) skb->data;
+       struct hci_ev_sync_conn_complete *ev =
+               (void *) skb->data + sizeof(*hdr);
+       struct hci_dev *hdev = data->hdev;
+       unsigned int notify_air_mode;
+
+       if (hci_skb_pkt_type(skb) != HCI_EVENT_PKT)
+               return;
+
+       if (skb->len < sizeof(*hdr) || hdr->evt != HCI_EV_SYNC_CONN_COMPLETE)
+               return;
+
+       if (skb->len != sizeof(*hdr) + sizeof(*ev) || ev->status)
+               return;
+
+       switch (ev->air_mode) {
+       case BT_CODEC_CVSD:
+               notify_air_mode = HCI_NOTIFY_ENABLE_SCO_CVSD;
+               break;
+
+       case BT_CODEC_TRANSPARENT:
+               notify_air_mode = HCI_NOTIFY_ENABLE_SCO_TRANSP;
+               break;
+
+       default:
+               return;
+       }
+
+       bt_dev_info(hdev, "enabling SCO with air mode %u", ev->air_mode);
+       data->sco_num = 1;
+       data->air_mode = notify_air_mode;
+       schedule_work(&data->work);
+}
+
 static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
 {
        if (data->intr_interval) {
@@ -1092,6 +1129,10 @@ static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb)
                schedule_delayed_work(&data->rx_work, 0);
        }
 
+       /* Configure altsetting for HCI_USER_CHANNEL on SCO connected */
+       if (auto_isoc_alt && hci_dev_test_flag(data->hdev, HCI_USER_CHANNEL))
+               btusb_sco_connected(data, skb);
+
        return data->recv_event(data->hdev, skb);
 }