Skip to content

Commit

Permalink
Bluetooth: Add BTPROTO_ISO socket type
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vudentz authored and intel-lab-lkp committed May 5, 2022
1 parent aec1844 commit 9ab3ba7
Show file tree
Hide file tree
Showing 9 changed files with 1,623 additions and 7 deletions.
21 changes: 21 additions & 0 deletions include/net/bluetooth/bluetooth.h
Expand Up @@ -589,6 +589,27 @@ static inline void sco_exit(void)
}
#endif

#if IS_ENABLED(CONFIG_BT_LE)
int iso_init(void);
int iso_exit(void);
bool iso_enabled(void);
#else
static inline int iso_init(void)
{
return 0;
}

static inline int iso_exit(void)
{
return 0;
}

static inline bool iso_enabled(void)
{
return false;
}
#endif

int mgmt_init(void);
void mgmt_exit(void);

Expand Down
18 changes: 16 additions & 2 deletions include/net/bluetooth/hci_core.h
Expand Up @@ -834,6 +834,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 */
Expand Down Expand Up @@ -1632,8 +1647,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);
Expand Down
36 changes: 36 additions & 0 deletions include/net/bluetooth/iso.h
@@ -0,0 +1,36 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2020 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 */
1 change: 1 addition & 0 deletions net/bluetooth/Makefile
Expand Up @@ -18,6 +18,7 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
eir.o hci_sync.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_MSFTEXT) += msft.o
Expand Down
2 changes: 2 additions & 0 deletions net/bluetooth/af_bluetooth.c
Expand Up @@ -780,6 +780,8 @@ static void __exit bt_exit(void)
{
mgmt_exit();

iso_exit();

sco_exit();

l2cap_exit();
Expand Down
7 changes: 5 additions & 2 deletions net/bluetooth/hci_core.c
Expand Up @@ -3822,8 +3822,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);
}
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/hci_event.c
Expand Up @@ -3827,8 +3827,8 @@ static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data,

conn->handle = __le16_to_cpu(rp->handle[i++]);

BT_DBG("%p handle 0x%4.4x link %p state %u", conn, conn->handle,
conn->link, conn->link->state);
bt_dev_dbg(hdev, "%p handle 0x%4.4x link %p state %u", conn,
conn->handle, conn->link, conn->link->state);

/* Create CIS if LE is already connected */
if (conn->link->state == BT_CONNECTED)
Expand Down

0 comments on commit 9ab3ba7

Please sign in to comment.