Bluetooth: Add initial implementation of CIS connections
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/2 Bluetooth: Add initial implementation of CIS connections
From: Luiz Augusto von Dentz <[email protected]>
This adds the initial implementation of CIS connections and introduces the ISO packets/links.
--- include/net/bluetooth/bluetooth.h | 21 +++ include/net/bluetooth/hci_core.h | 54 ++++++- include/net/bluetooth/hci_sock.h | 2 + net/bluetooth/Kconfig | 1 + net/bluetooth/af_bluetooth.c | 4 +- net/bluetooth/hci_conn.c | 169 +++++++++++++++++++++ net/bluetooth/hci_core.c | 240 ++++++++++++++++++++++++------ net/bluetooth/hci_event.c | 230 ++++++++++++++++++++++++++++ 8 files changed, 670 insertions(+), 51 deletions(-)
include/net/bluetooth/bluetooth.h +21 -0
@@ -53,6 +53,8 @@#define BTPROTO_CMTP 5#define BTPROTO_HIDP 6#define BTPROTO_AVDTP 7 +#define BTPROTO_ISO 8 +#define BTPROTO_LAST BTPROTO_ISO#define SOL_HCI 0#define SOL_L2CAP 6
@@ -122,6 +124,25 @@ struct bt_voice {#define BT_SNDMTU 12#define BT_RCVMTU 13 +#define BT_ISO_IN_QOS 15 +#define BT_ISO_OUT_QOS 16 +struct bt_iso_qos { +__u8 sca; +__u8 packing; +__u8 framing; +__u32 interval; +__u16 latency; +__u16 mtu; +__u8 phy; +__u8 rtn; +}; + +#define BT_ISO_PHY_1M 0x01 +#define BT_ISO_PHY_2M 0x02 +#define BT_ISO_PHY_CODED 0x04 +#define BT_ISO_PHY_ANY (BT_ISO_PHY_1M | BT_ISO_PHY_2M | \ + BT_ISO_PHY_CODED) + __printf(1, 2)void bt_info (const char *fmt, ...);__printf (1 ,2 )
include/net/bluetooth/hci_core.h +53 -1
139 lines not on this page · raw message
include/net/bluetooth/hci_sock.h +2 -0
@@ -124,6 +124,8 @@ struct hci_dev_info {__u16 acl_pkts;__u16 sco_mtu;__u16 sco_pkts; +__u16 iso_mtu; +__u16 iso_pkts;struct hci_dev_stats stat; };
net/bluetooth/Kconfig +1 -0
@@ -29,6 +29,7 @@ menuconfig BT SCO audio links L2CAP (Logical Link Control and Adaptation Protocol) SMP (Security Manager Protocol) on LE (Low Energy) links + ISO isochronous links HCI Device drivers (Interface to the hardware) RFCOMM Module (RFCOMM Protocol) BNEP Module (Bluetooth Network Encapsulation Protocol)
net/bluetooth/af_bluetooth.c +3 -1
@@ -38,7 +38,7 @@#include "selftest.h" /* Bluetooth sockets */ -#define BT_MAX_PROTO 8 +#define BT_MAX_PROTO BTPROTO_LAST + 1static const struct net_proto_family *bt_proto[BT_MAX_PROTO ];static DEFINE_RWLOCK (bt_proto_lock);
@@ -52,6 +52,7 @@ static const char *const bt_key_strings[BT_MAX_PROTO] = {"sk_lock-AF_BLUETOOTH-BTPROTO_CMTP" ,"sk_lock-AF_BLUETOOTH-BTPROTO_HIDP" ,"sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP" , + "sk_lock-AF_BLUETOOTH-BTPROTO_ISO", };static struct lock_class_key bt_slock_key[BT_MAX_PROTO ];
@@ -64,6 +65,7 @@ static const char *const bt_slock_key_strings[BT_MAX_PROTO] = {"slock-AF_BLUETOOTH-BTPROTO_CMTP" ,"slock-AF_BLUETOOTH-BTPROTO_HIDP" ,"slock-AF_BLUETOOTH-BTPROTO_AVDTP" , + "slock-AF_BLUETOOTH-BTPROTO_ISO", };void bt_sock_reclassify_lock (struct sock *sk,int proto)
net/bluetooth/hci_conn.c +169 -0
181 lines not on this page · raw message
net/bluetooth/hci_core.c +191 -49
327 lines not on this page · raw message
net/bluetooth/hci_event.c +230 -0
273 lines not on this page · raw message
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH 2/2 Bluetooth: Add BTPROTO_ISO socket type
From: Luiz Augusto von Dentz <[email protected]>
This introduces a new socket type BTPROTO_ISO which is used to transfer ISO packets between userspace and kernel similarly to how BTPROTO_SCO works.
--- include/net/bluetooth/bluetooth.h | 14 + include/net/bluetooth/hci_core.h | 18 +- include/net/bluetooth/iso.h | 36 + net/bluetooth/Makefile | 1 + net/bluetooth/af_bluetooth.c | 10 +- net/bluetooth/hci_core.c | 7 +- net/bluetooth/iso.c | 1393 +++++++++++++++++++++++++++++ 7 files changed, 1474 insertions(+), 5 deletions(-) create mode 100644 include/net/bluetooth/iso.h create mode 100644 net/bluetooth/iso.c
include/net/bluetooth/bluetooth.h +14 -0
@@ -431,6 +431,20 @@ static inline void sco_exit(void) }#endif +#if IS_ENABLED (CONFIG_BT_LE ) +int iso_init (void ); +void iso_exit (void ); +#else +static inline int iso_init (void ) +{ +return 0 ; +} + +static inline void iso_exit (void ) +{ +} +#endif +int mgmt_init (void );void mgmt_exit (void );
include/net/bluetooth/hci_core.h +16 -2
@@ -622,6 +622,21 @@ static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb) }#endif +#if IS_ENABLED (CONFIG_BT_LE ) +int iso_connect_ind (struct hci_dev *hdev,bdaddr_t *bdaddr,__u8 *flags); +void iso_recv (struct hci_conn *hcon,struct sk_buff *skb,u16 flags); +#else +static inline int iso_connect_ind (struct hci_dev *hdev,bdaddr_t *bdaddr, +__u8 *flags) +{ +return 0 ; +} +static inline void iso_recv (struct hci_conn *hcon,struct sk_buff *skb, +u16 flags) +{ +} +#endif +/* ----- Inquiry cache ----- */ #define INQUIRY_CACHE_AGE_MAX (HZ*30)/* 30 seconds */ #define INQUIRY_ENTRY_AGE_MAX (HZ*60)/* 60 seconds */
@@ -1289,8 +1304,7 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,return sco_connect_ind (hdev, bdaddr, flags);case ISO_LINK : -/* TODO: Handle connection indication */ -return -EINVAL ; +return iso_connect_ind (hdev, bdaddr, flags);default :BT_ERR ("unknown link type %d" , type);
include/net/bluetooth/iso.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +BlueZ - Bluetooth protocol stack for Linux +Copyright (C) 2019 Intel Corporation + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation; + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. +IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY +CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, +COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS +SOFTWARE IS DISCLAIMED. +*/ + +#ifndef __ISO_H +#define __ISO_H + +/* ISO defaults */ +#define ISO_DEFAULT_MTU 251 + +/* ISO socket address */ +struct sockaddr_iso { +sa_family_t iso_family; +bdaddr_t iso_bdaddr; +__u8 iso_bdaddr_type; +}; + +#endif /* __ISO_H */
net/bluetooth/Makefile +1 -0
@@ -17,6 +17,7 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ ecdh_helper.o hci_request.o mgmt_util.o bluetooth-$(CONFIG_BT_BREDR) += sco.o +bluetooth-$(CONFIG_BT_LE) += iso.o bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o bluetooth-$(CONFIG_BT_LEDS) += leds.o bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o
net/bluetooth/af_bluetooth.c +9 -1
@@ -757,12 +757,18 @@ static int __init bt_init(void)if (err) goto cleanup_cap; - err =mgmt_init (); + err =iso_init ();if (err) goto cleanup_sco; + err =mgmt_init (); +if (err) + goto cleanup_iso; +return 0 ; +cleanup_iso: +iso_exit (); cleanup_sco:sco_exit (); cleanup_cap:
@@ -780,6 +786,8 @@ static void __exit bt_exit(void) {mgmt_exit (); +iso_exit (); +sco_exit ();l2cap_exit ();
net/bluetooth/hci_core.c +5 -2
@@ -4539,8 +4539,11 @@ static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) conn =hci_conn_hash_lookup_handle (hdev, handle);hci_dev_unlock (hdev); -/* TODO: Send to upper protocol */ -if (!conn) { +if (conn) { +/* Send to upper protocol */ +iso_recv (conn, skb, flags); +return ; + }else {bt_dev_err (hdev,"ISO packet for unknown connection handle %d" , handle); }
net/bluetooth/iso.c new file +1393 -0
1,393 lines not on this page · raw message
Signature · 1 line
2.21.0
Marcel Holtmann
maintainerRe: [PATCH 2/2] Bluetooth: Add BTPROTO_ISO socket type
Hi Luiz,
Quoted 3 lines
This introduces a new socket type
BTPROTO_ISOwhich is used to transfer ISO packets between userspace and kernel similarly to howBTPROTO_SCOworks.
circling back to this now. What is the advantage of using a separate socket instead of the SCO socket type with a proper configured set of socket options.
I mean at some we can just rename BTPROTO_SCO into BTPROTO_AUDIO since all the Synchronous and Isochronous naming in the spec is not really helpful. Even if in theory it can be used for other data, it has been in 20+ years only used for audio data.
And actually it doesn’t need to be a socket at all. If we figure out a better interface for SCO/eSCO and ISO data when transported over HCI, I am ok with that as well.
The fact that we open a SCO socket to establish the underlying transport, but then the data goes somewhere else is also weird to some degree. So I wonder if the audio control part might be better done over mgmt and if we get audio data to transport, we just hand back an fd via mgmt event.
This is me just thinking out loud. If the separate ISO socket is in the end the best approach, we can also do it like that, but we should really evaluate the possible direction before we set this API in stone.
Regards
Marcel
Hi Luiz,
url: https://github.com/0day-ci/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-Add-initial-implementation-of-CIS-connections/20200118-034643 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
If you fix the issue, kindly add following tag
New smatch warnings:net/bluetooth/hci_event.c:3188 hci_cc_le_set_cig_params() warn: inconsistent returns 'hdev->lock'.
Old smatch warnings:net/bluetooth/hci_event.c:5567 hci_le_adv_report_evt() warn: potential spectre issue 'ev->data' [r] (local cap) net/bluetooth/hci_event.c:5569 hci_le_adv_report_evt() warn: possible spectre second half. 'rssi'
# https://github.com/0day-ci/linux/commit/88d6b37aa7d732b2392e953206c3231560035c3c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 88d6b37aa7d732b2392e953206c3231560035c3c
vim +3188 net/bluetooth/hci_event.c
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3150 static void hci_cc_le_set_cig_params(struct hci_dev *hdev, struct sk_buff *skb)
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3151 {
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3152 struct hci_rp_le_set_cig_params *rp = (void *) skb->data;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3153 struct hci_conn *conn;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3154 int i = 0;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3155
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3156 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3157
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3158 hci_dev_lock(hdev);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3159
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3160 rcu_read_lock();
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3161
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3162 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3163 if (conn->type != ISO_LINK || conn->handle ||
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3164 conn->state == BT_CONNECTED)
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3165 continue;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3166
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3167 if (rp->status) {
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3168 conn->state = BT_CLOSED;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3169 hci_connect_cfm(conn, rp->status);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3170 hci_conn_del(conn);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3171 return;
^^^^^^^goto unlock
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3172 }
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3173
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3174 conn->handle = __le16_to_cpu(rp->handle[i++]);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3175
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3176 BT_DBG("%p handle 0x%4.4x", conn, conn->handle);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3177
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3178 /* Create CIS if LE is already connected */
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3179 if (conn->link->state == BT_CONNECTED)
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3180 hci_le_create_cis(conn->link);
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3181
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3182 if (i == rp->num_handles)
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3183 break;
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3184 }
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3185
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3186 rcu_read_unlock();
88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3187 88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 @3188 hci_dev_unlock(hdev);88d6b37aa7d732 Luiz Augusto von Dentz 2020-01-16 3189 }
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation