Skip to content

Commit ccf74f2

Browse files
committed
Bluetooth: Add BTPROTO_ISO socket type
This introduces a new socket type BTPROTO_ISO which can be enabled with use of ISO Socket experiemental UUID, it can used to initiate/accept connections and transfer packets between userspace and kernel similarly to how BTPROTO_SCO works: Central -> uses connect with address set to destination bdaddr: > tools/isotest -s 00:AA:01:00:00:00 Peripheral -> uses listen: > tools/isotest -d Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 26afbd8 commit ccf74f2

File tree

8 files changed

+1636
-5
lines changed

8 files changed

+1636
-5
lines changed

include/net/bluetooth/bluetooth.h

+21
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,27 @@ static inline void sco_exit(void)
590590
}
591591
#endif
592592

593+
#if IS_ENABLED(CONFIG_BT_LE)
594+
int iso_init(void);
595+
int iso_exit(void);
596+
bool iso_enabled(void);
597+
#else
598+
static inline int iso_init(void)
599+
{
600+
return 0;
601+
}
602+
603+
static inline int iso_exit(void)
604+
{
605+
return 0;
606+
}
607+
608+
static inline bool iso_enabled(void)
609+
{
610+
return false;
611+
}
612+
#endif
613+
593614
int mgmt_init(void);
594615
void mgmt_exit(void);
595616

include/net/bluetooth/hci_core.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,21 @@ static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
843843
}
844844
#endif
845845

846+
#if IS_ENABLED(CONFIG_BT_LE)
847+
int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
848+
void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
849+
#else
850+
static inline int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
851+
__u8 *flags)
852+
{
853+
return 0;
854+
}
855+
static inline void iso_recv(struct hci_conn *hcon, struct sk_buff *skb,
856+
u16 flags)
857+
{
858+
}
859+
#endif
860+
846861
/* ----- Inquiry cache ----- */
847862
#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
848863
#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
@@ -1640,8 +1655,7 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
16401655
return sco_connect_ind(hdev, bdaddr, flags);
16411656

16421657
case ISO_LINK:
1643-
/* TODO: Handle connection indication */
1644-
return -EINVAL;
1658+
return iso_connect_ind(hdev, bdaddr, flags);
16451659

16461660
default:
16471661
BT_ERR("unknown link type %d", type);

include/net/bluetooth/iso.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* BlueZ - Bluetooth protocol stack for Linux
4+
*
5+
* Copyright (C) 2022 Intel Corporation
6+
*/
7+
8+
#ifndef __ISO_H
9+
#define __ISO_H
10+
11+
/* ISO defaults */
12+
#define ISO_DEFAULT_MTU 251
13+
14+
/* ISO socket address */
15+
struct sockaddr_iso {
16+
sa_family_t iso_family;
17+
bdaddr_t iso_bdaddr;
18+
__u8 iso_bdaddr_type;
19+
};
20+
21+
#endif /* __ISO_H */

net/bluetooth/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
1818
eir.o hci_sync.o
1919

2020
bluetooth-$(CONFIG_BT_BREDR) += sco.o
21+
bluetooth-$(CONFIG_BT_LE) += iso.o
2122
bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o
2223
bluetooth-$(CONFIG_BT_LEDS) += leds.o
2324
bluetooth-$(CONFIG_BT_MSFTEXT) += msft.o

net/bluetooth/af_bluetooth.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "selftest.h"
3939

4040
/* Bluetooth sockets */
41-
#define BT_MAX_PROTO 8
41+
#define BT_MAX_PROTO (BTPROTO_LAST + 1)
4242
static const struct net_proto_family *bt_proto[BT_MAX_PROTO];
4343
static DEFINE_RWLOCK(bt_proto_lock);
4444

@@ -52,6 +52,7 @@ static const char *const bt_key_strings[BT_MAX_PROTO] = {
5252
"sk_lock-AF_BLUETOOTH-BTPROTO_CMTP",
5353
"sk_lock-AF_BLUETOOTH-BTPROTO_HIDP",
5454
"sk_lock-AF_BLUETOOTH-BTPROTO_AVDTP",
55+
"sk_lock-AF_BLUETOOTH-BTPROTO_ISO",
5556
};
5657

5758
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] = {
6465
"slock-AF_BLUETOOTH-BTPROTO_CMTP",
6566
"slock-AF_BLUETOOTH-BTPROTO_HIDP",
6667
"slock-AF_BLUETOOTH-BTPROTO_AVDTP",
68+
"slock-AF_BLUETOOTH-BTPROTO_ISO",
6769
};
6870

6971
void bt_sock_reclassify_lock(struct sock *sk, int proto)

net/bluetooth/hci_core.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -3822,12 +3822,16 @@ static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
38223822
conn = hci_conn_hash_lookup_handle(hdev, handle);
38233823
hci_dev_unlock(hdev);
38243824

3825-
/* TODO: Send to upper protocol */
38263825
if (!conn) {
38273826
bt_dev_err(hdev, "ISO packet for unknown connection handle %d",
38283827
handle);
3828+
goto drop;
38293829
}
38303830

3831+
/* Send to upper protocol */
3832+
iso_recv(conn, skb, flags);
3833+
return;
3834+
38313835
drop:
38323836
kfree_skb(skb);
38333837
}

0 commit comments

Comments
 (0)