Bluetooth 5.2 initial support
Subsystems (2)
Luiz Augusto von Dentz
maintainerv4 cover Bluetooth 5.2 initial support
From: Luiz Augusto von Dentz <[email protected]>
This introduces the initial support for Bluetooth 5.2 features:
* ISO channels:
+ CIS/Unicast support
+ ISO socket family with QoS support
- BIS/Broadcast not yet supported
* L2CAP Enhanced Credit Based Flow Control Mode
+ Support all new procedures
+ New L2CAP socket mode
- Initiating multiple connections at once does not map to any existing socket APIs
* Monitor:
+ ISO packets support
* Drivers:
+ H4,H5,sdio ISO packets support
* Emulator:
+ CIS/Unicast emulation support
- BIS/Broadcast emulation not yet supported
* Userspace support to follow once Kernel changes are merged.
Bluetooth 5.2 spec:
https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=478726
ChangeLog:
- v2: Only attempt to fix up packet type when an ISO connection exists, remove L2CAP_ECRED_MASK.
- v3: Dropped USB changes since that has not clear way to support ISO packets with existing endpoints. Renamed ECRED to EXT_FLOWCTL.
- v4: Fix not using __le16 for HCI PDU definitions, renamed FLAG_LE_CONN_REQ_SENT to FLAG_LE_FLOWCTL_CONN_REQ_SENT.
Luiz Augusto von Dentz (11):
Bluetooth: Add definitions for CIS connections
Bluetooth: Add initial implementation of CIS connections
Bluetooth: L2CAP: Add definitions for Enhanced Credit Based Mode
Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode
Bluetooth: L2CAP: Rename FLAG_LE_CONN_REQ_SENT to
FLAG_LE_FLOWCTL_CONN_REQ_SENT
Bluetooth: hci_vhci: Add support for ISO packets
Bluetooth: monitor: Add support for ISO packets
Bluetooth: Make use of __check_timeout on hci_sched_le
Bluetooth: hci_h4: Add support for ISO packets
Bluetooth: hci_h5: Add support for ISO packets
Bluetooth: btsdio: Check for valid packet type
drivers/bluetooth/btsdio.c | 19 +- drivers/bluetooth/hci_h4.c | 1 + drivers/bluetooth/hci_h5.c | 3 + drivers/bluetooth/hci_uart.h | 7 + drivers/bluetooth/hci_vhci.c | 1 + include/net/bluetooth/bluetooth.h | 35 + include/net/bluetooth/hci.h | 159 +++- include/net/bluetooth/hci_core.h | 68 +- include/net/bluetooth/hci_mon.h | 2 + include/net/bluetooth/hci_sock.h | 2 + include/net/bluetooth/iso.h | 36 + include/net/bluetooth/l2cap.h | 47 +- net/bluetooth/Kconfig | 1 + net/bluetooth/Makefile | 1 + net/bluetooth/af_bluetooth.c | 12 +- net/bluetooth/hci_conn.c | 169 ++++ net/bluetooth/hci_core.c | 254 ++++-- net/bluetooth/hci_event.c | 230 +++++ net/bluetooth/hci_sock.c | 6 + net/bluetooth/iso.c | 1393 +++++++++++++++++++++++++++++ net/bluetooth/l2cap_core.c | 514 ++++++++++- net/bluetooth/l2cap_sock.c | 39 +- 22 files changed, 2898 insertions(+), 101 deletions(-) create mode 100644 include/net/bluetooth/iso.h create mode 100644 net/bluetooth/iso.c
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 1/11 Bluetooth: Add definitions for CIS connections
From: Luiz Augusto von Dentz <[email protected]>
These adds the HCI definitions for handling CIS connections along with ISO data packets.
--- include/net/bluetooth/hci.h | 159 +++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-)
include/net/bluetooth/hci.h +158 -1
@@ -27,6 +27,7 @@#define HCI_MAX_ACL_SIZE 1024#define HCI_MAX_SCO_SIZE 255 +#define HCI_MAX_ISO_SIZE 251#define HCI_MAX_EVENT_SIZE 260#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4)
@@ -303,6 +304,7 @@ enum {#define HCI_ACLDATA_PKT 0x02#define HCI_SCODATA_PKT 0x03#define HCI_EVENT_PKT 0x04 +#define HCI_ISODATA_PKT 0x05#define HCI_DIAG_PKT 0xf0#define HCI_VENDOR_PKT 0xff
@@ -352,6 +354,15 @@ enum {#define ACL_ACTIVE_BCAST 0x04#define ACL_PICO_BCAST 0x08 +/* ISO PB flags */ +#define ISO_START 0x00 +#define ISO_CONT 0x01 +#define ISO_SINGLE 0x02 +#define ISO_END 0x03 + +/* ISO TS flags */ +#define ISO_TS 0x01 +/* Baseband links */ #define SCO_LINK 0x00#define ACL_LINK 0x01
@@ -359,6 +370,7 @@ enum {/* Low Energy links do not have defined link type. Use invented one */ #define LE_LINK 0x80#define AMP_LINK 0x81 +#define ISO_LINK 0x82#define INVALID_LINK 0xff/* LMP features */
@@ -440,6 +452,8 @@ enum {#define HCI_LE_PHY_2M 0x01#define HCI_LE_PHY_CODED 0x08#define HCI_LE_CHAN_SEL_ALG2 0x40 +#define HCI_LE_CIS_MASTER 0x10 +#define HCI_LE_CIS_SLAVE 0x20/* Connection modes */ #define HCI_CM_ACTIVE 0x0000
@@ -1718,6 +1732,86 @@ struct hci_cp_le_set_adv_set_rand_addr {bdaddr_t bdaddr; } __packed; +#define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060 +struct hci_rp_le_read_buffer_size_v2 { +__u8 status; +__le16 acl_mtu; +__u8 acl_max_pkt; +__le16 iso_mtu; +__u8 iso_max_pkt; +} __attribute__ ((packed)); + +#define HCI_OP_LE_READ_ISO_TX_SYNC 0x2061 +struct hci_cp_le_read_iso_tx_sync { +__le16 handle; +} __attribute__ ((packed)); + +struct hci_rp_le_read_iso_tx_sync { +__u8 status; +__le16 handle; +__le16 seq; +__u32 timestamp; +__u8 offset[3 ]; +} __attribute__ ((packed)); + +#define HCI_OP_LE_SET_CIG_PARAMS 0x2062 +struct hci_cis_params { +__u8 cis_id; +__le16 m_sdu; +__le16 s_sdu; +__u8 m_phy; +__u8 s_phy; +__u8 m_rtn; +__u8 s_rtn; +} __packed; + +struct hci_cp_le_set_cig_params { +__u8 cig_id; +__u8 m_interval[3 ]; +__u8 s_interval[3 ]; +__u8 sca; +__u8 packing; +__u8 framing; +__le16 m_latency; +__le16 s_latency; +__u8 num_cis; +struct hci_cis_params cis[0 ]; +} __packed; + +struct hci_rp_le_set_cig_params { +__u8 status; +__u8 cig_id; +__u8 num_handles; +__le16 handle[0 ]; +} __packed; + +#define HCI_OP_LE_CREATE_CIS 0x2064 +struct hci_cis { +__le16 cis_handle; +__le16 acl_handle; +} __packed; + +struct hci_cp_le_create_cis { +__u8 num_cis; +struct hci_cis cis[0 ]; +} __packed; + +#define HCI_OP_LE_REMOVE_CIG 0x2065 +struct hci_cp_le_remove_cig { +__u8 cig_id; +} __packed; + +#define HCI_OP_LE_ACCEPT_CIS 0x2066 +struct hci_cp_le_accept_cis { +__le16 handle; +} __packed; + +#define HCI_OP_LE_REJECT_CIS 0x2067 +struct hci_cp_le_reject_cis { +__le16 handle; +__u8 reason; +} __packed; +/* ---- HCI Events ---- */ #define HCI_EV_INQUIRY_COMPLETE 0x01
@@ -2189,7 +2283,7 @@ struct hci_ev_le_direct_adv_info {#define HCI_EV_LE_PHY_UPDATE_COMPLETE 0x0cstruct hci_ev_le_phy_update_complete {__u8 status; -__u16 handle; +__le16 handle;__u8 tx_phy;__u8 rx_phy; } __packed;
@@ -2234,6 +2328,34 @@ struct hci_evt_le_ext_adv_set_term {__u8 num_evts; } __packed; +#define HCI_EVT_LE_CIS_ESTABLISHED 0x19 +struct hci_evt_le_cis_established { +__u8 status; +__le16 handle; +__u8 cig_sync_delay[3 ]; +__u8 cis_sync_delay[3 ]; +__u8 m_latency[3 ]; +__u8 s_latency[3 ]; +__u8 m_phy; +__u8 s_phy; +__u8 nse; +__u8 m_bn; +__u8 s_bn; +__u8 m_ft; +__u8 s_ft; +__le16 m_mtu; +__le16 s_mtu; +__le16 interval; +} __packed; + +#define HCI_EVT_LE_CIS_REQ 0x1a +struct hci_evt_le_cis_req { +__le16 acl_handle; +__le16 cis_handle; +__u8 cig_id; +__u8 cis_id; +} __packed; +#define HCI_EV_VENDOR 0xff/* Internal events generated by Bluetooth stack */
@@ -2262,6 +2384,7 @@ struct hci_ev_si_security {#define HCI_EVENT_HDR_SIZE 2#define HCI_ACL_HDR_SIZE 4#define HCI_SCO_HDR_SIZE 3 +#define HCI_ISO_HDR_SIZE 4struct hci_command_hdr {__le16 opcode;/* OCF & OGF */
@@ -2283,6 +2406,30 @@ struct hci_sco_hdr {__u8 dlen; } __packed; +struct hci_iso_hdr { +__le16 handle; +__le16 dlen; +__u8 data[0 ]; +} __packed; + +/* ISO data packet status flags */ +#define HCI_ISO_STATUS_VALID 0x00 +#define HCI_ISO_STATUS_INVALID 0x01 +#define HCI_ISO_STATUS_NOP 0x02 + +#define HCI_ISO_DATA_HDR_SIZE 4 +struct hci_iso_data_hdr { +__le16 sn; +__le16 slen; +}; + +#define HCI_ISO_TS_DATA_HDR_SIZE 8 +struct hci_iso_ts_data_hdr { +__le32 ts; +__le16 sn; +__le16 slen; +}; +static inline struct hci_event_hdr *hci_event_hdr (const struct sk_buff *skb) {return (struct hci_event_hdr *) skb->data;
@@ -2308,4 +2455,14 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)#define hci_handle (h) (h & 0x0fff)#define hci_flags (h) (h >> 12) +/* ISO handle and flags pack/unpack */ +#define hci_iso_flags_pb (f) (f & 0x0003) +#define hci_iso_flags_ts (f) ((f >> 2) & 0x0001) +#define hci_iso_flags_pack (pb, ts) ((pb & 0x03) | ((ts & 0x01) << 2)) + +/* ISO data length and flags pack/unpack */ +#define hci_iso_data_len_pack (h, f) ((__u16) ((h) | ((f) << 14))) +#define hci_iso_data_len (h) ((h) & 0x3fff) +#define hci_iso_data_flags (h) ((h) >> 14) +#endif /* __HCI_H */
Signature · 1 line
2.21.0
Marcel Holtmann
maintainerRe: [PATCH v4 01/11] Bluetooth: Add definitions for CIS connections
Hi Luiz,
Quoted 63 lines
These adds the HCI definitions for handling CIS connections along with ISO data packets.
Signed-off-by Luiz Augusto von Dentz <[email protected]>---
include/net/bluetooth/hci.h| 159 +++++++++++++++++++++++++++++++++++-1 file changed, 158 insertions(+), 1 deletion(-)include/net/bluetooth/hci.h +14
-0@@ -27,6 +27,7 @@#define HCI_MAX_ACL_SIZE 1024#define HCI_MAX_SCO_SIZE 255 +#define HCI_MAX_ISO_SIZE 251#define HCI_MAX_EVENT_SIZE 260#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4)@@ -303,6 +304,7 @@ enum {#define HCI_ACLDATA_PKT 0x02#define HCI_SCODATA_PKT 0x03#define HCI_EVENT_PKT 0x04 +#define HCI_ISODATA_PKT 0x05#define HCI_DIAG_PKT 0xf0#define HCI_VENDOR_PKT 0xff@@ -352,6 +354,15 @@ enum {#define ACL_ACTIVE_BCAST 0x04#define ACL_PICO_BCAST 0x08 +/* ISO PB flags */ +#define ISO_START 0x00 +#define ISO_CONT 0x01 +#define ISO_SINGLE 0x02 +#define ISO_END 0x03 + +/* ISO TS flags */ +#define ISO_TS 0x01 +/* Baseband links */ #define SCO_LINK 0x00#define ACL_LINK 0x01@@ -359,6 +370,7 @@ enum {/* Low Energy links do not have defined link type. Use invented one */ #define LE_LINK 0x80#define AMP_LINK 0x81 +#define ISO_LINK 0x82#define INVALID_LINK 0xff/* LMP features */ @@ -440,6 +452,8 @@ enum {#define HCI_LE_PHY_2M 0x01#define HCI_LE_PHY_CODED 0x08#define HCI_LE_CHAN_SEL_ALG2 0x40 +#define HCI_LE_CIS_MASTER 0x10 +#define HCI_LE_CIS_SLAVE 0x20/* Connection modes */ #define HCI_CM_ACTIVE 0x0000@@ -1718,6 +1732,86 @@ struct hci_cp_le_set_adv_set_rand_addr {bdaddr_t bdaddr;
include/net/bluetooth/hci.h struct hci_cp_le_set_adv_set_rand_addr { · line 1742
Quoted 10 lines
include/net/bluetooth/hci.h +8
-0} __packed; +#define HCI_OP_LE_READ_BUFFER_SIZE_V2 0x2060 +struct hci_rp_le_read_buffer_size_v2 { +__u8 status; +__le16 acl_mtu; +__u8 acl_max_pkt; +__le16 iso_mtu; +__u8 iso_max_pkt; +} __attribute__ ((packed));
please continue the whitespace spacing between the type and variable name as we do it for all the others.
And actually the kernel used __packed. I missed that the first times around.
Regards
Marcel
Luiz Augusto von Dentz
maintainerPATCH v4 2/11 Bluetooth: Add initial implementation of CIS connections
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds the initial implementation of CIS connections along with a new socket type BTPROTO_ISO to make use of it.
--- include/net/bluetooth/bluetooth.h | 35 + include/net/bluetooth/hci_core.h | 68 +- include/net/bluetooth/hci_sock.h | 2 + include/net/bluetooth/iso.h | 36 + net/bluetooth/Kconfig | 1 + net/bluetooth/Makefile | 1 + net/bluetooth/af_bluetooth.c | 12 +- net/bluetooth/hci_conn.c | 169 ++++ net/bluetooth/hci_core.c | 243 ++++- net/bluetooth/hci_event.c | 230 +++++ net/bluetooth/iso.c | 1393 +++++++++++++++++++++++++++++ 11 files changed, 2138 insertions(+), 52 deletions(-) create mode 100644 include/net/bluetooth/iso.h create mode 100644 net/bluetooth/iso.c
include/net/bluetooth/bluetooth.h +35 -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 )
@@ -410,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 +67 -1
159 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; };
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/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/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 +10 -2
@@ -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)
@@ -755,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:
net/bluetooth/hci_conn.c +169 -0
181 lines not on this page · raw message
net/bluetooth/hci_core.c +194 -49
330 lines not on this page · raw message
net/bluetooth/hci_event.c +230 -0
273 lines not on this page · raw message
net/bluetooth/iso.c new file +1393 -0
1,393 lines not on this page · raw message
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 3/11 Bluetooth: L2CAP: Add definitions for Enhanced Credit Based Mode
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This introduces the definitions for the new L2CAP mode called Enhanced Credit Based Mode.
--- include/net/bluetooth/l2cap.h | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
include/net/bluetooth/l2cap.h +41 -0
@@ -119,6 +119,11 @@ struct l2cap_conninfo {#define L2CAP_LE_CONN_REQ 0x14#define L2CAP_LE_CONN_RSP 0x15#define L2CAP_LE_CREDITS 0x16 +#define L2CAP_EXT_FLOWCTL_CONN_REQ 0x17 +#define L2CAP_EXT_FLOWCTL_CONN_RSP 0x18 +#define L2CAP_EXT_FLOWCTL_RECONF_REQ 0x19 +#define L2CAP_EXT_FLOWCTL_RECONF_RSP 0x1a +/* L2CAP extended feature mask */ #define L2CAP_FEAT_FLOWCTL 0x00000001
@@ -360,6 +365,8 @@ struct l2cap_conf_rfc {*/ #define L2CAP_MODE_LE_FLOWCTL 0x80 +#define L2CAP_MODE_EXT_FLOWCTL 0x81 +struct l2cap_conf_efs {__u8 id;__u8 stype;
@@ -483,6 +490,39 @@ struct l2cap_le_credits {__le16 credits; } __packed; +#define L2CAP_EXT_FLOWCTL_MIN_MTU 64 +#define L2CAP_EXT_FLOWCTL_MIN_MPS 64 + +struct l2cap_ext_flowctl_conn_req { +__le16 psm; +__le16 mtu; +__le16 mps; +__le16 credits; +__le16 scid[0 ]; +} __packed; + +struct l2cap_ext_flowctl_conn_rsp { +__le16 mtu; +__le16 mps; +__le16 credits; +__le16 result; +__le16 dcid[0 ]; +}; + +struct l2cap_ext_flowctl_reconf_req { +__le16 mtu; +__le16 mps; +__le16 scid[0 ]; +} __packed; + +#define L2CAP_RECONF_SUCCESS 0x0000 +#define L2CAP_RECONF_INVALID_MTU 0x0001 +#define L2CAP_RECONF_INVALID_MPS 0x0002 + +struct l2cap_ext_flowctl_reconf_rsp { +__le16 result; +} __packed; +/* ----- L2CAP channels and connections ----- */ struct l2cap_seq_list {__u16 head;
@@ -724,6 +764,7 @@ enum {FLAG_EFS_ENABLE ,FLAG_DEFER_SETUP ,FLAG_LE_CONN_REQ_SENT , +FLAG_EXT_FLOWCTL_CONN_REQ_SENT ,FLAG_PENDING_SECURITY , FLAG_HOLD_HCI_CONN, };
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 4/11 Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds the initial code for Enhanced Credit Based Mode which introduces a new socket mode called L2CAP_MODE_EXT_FLOWCTL, which for the most part work the same as L2CAP_MODE_LE_FLOWCTL but uses different PDUs to setup the connections and also works over BR/EDR.
--- include/net/bluetooth/l2cap.h | 4 + net/bluetooth/l2cap_core.c | 510 +++++++++++++++++++++++++++++++++- net/bluetooth/l2cap_sock.c | 39 +-- 3 files changed, 521 insertions(+), 32 deletions(-)
include/net/bluetooth/l2cap.h +4 -0
@@ -295,6 +295,8 @@ struct l2cap_conn_rsp {#define L2CAP_CR_LE_ENCRYPTION 0x0008#define L2CAP_CR_LE_INVALID_SCID 0x0009#define L2CAP_CR_LE_SCID_IN_USE 0X000A +#define L2CAP_CR_LE_UNACCEPT_PARAMS 0X000B +#define L2CAP_CR_LE_INVALID_PARAMS 0X000C/* connect/create channel status */ #define L2CAP_CS_NO_INFO 0x0000
@@ -964,6 +966,7 @@ void l2cap_cleanup_sockets(void);bool l2cap_is_socket (struct socket *sock);void __l2cap_le_connect_rsp_defer (struct l2cap_chan *chan); +void __l2cap_ext_flowctl_conn_rsp_defer (struct l2cap_chan *chan);void __l2cap_connect_rsp_defer (struct l2cap_chan *chan);int l2cap_add_psm (struct l2cap_chan *chan,bdaddr_t *src,__le16 psm);
@@ -973,6 +976,7 @@ struct l2cap_chan *l2cap_chan_create(void);void l2cap_chan_close (struct l2cap_chan *chan,int reason);int l2cap_chan_connect (struct l2cap_chan *chan,__le16 psm,u16 cid,bdaddr_t *dst,u8 dst_type); +int l2cap_chan_reconfigure (struct l2cap_chan *chan,__u16 mtu);int l2cap_chan_send (struct l2cap_chan *chan,struct msghdr *msg,size_t len);void l2cap_chan_busy (struct l2cap_chan *chan,int busy);int l2cap_chan_check_security (struct l2cap_chan *chan,bool initiator);
net/bluetooth/l2cap_core.c +497 -13
633 lines not on this page · raw message
net/bluetooth/l2cap_sock.c +20 -19
@@ -232,7 +232,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,return -EINVAL ; } -if (chan->psm &&bdaddr_type_is_le (chan->src_type)) +if (chan->psm &&bdaddr_type_is_le (chan->src_type) && !chan->mode) chan->mode =L2CAP_MODE_LE_FLOWCTL ; err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
@@ -273,6 +273,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)switch (chan->mode) {case L2CAP_MODE_BASIC :case L2CAP_MODE_LE_FLOWCTL : +case L2CAP_MODE_EXT_FLOWCTL :break ;case L2CAP_MODE_ERTM :case L2CAP_MODE_STREAMING :
@@ -408,16 +409,6 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,switch (optname) {case L2CAP_OPTIONS : -/* LE sockets should use BT_SNDMTU/BT_RCVMTU, but since -* legacy ATT code depends on getsockopt for -* L2CAP_OPTIONS we need to let this pass. -*/ -if (bdaddr_type_is_le (chan->src_type) && - chan->scid !=L2CAP_CID_ATT ) { - err = -EINVAL ; -break ; - } -memset (&opts,0 ,sizeof (opts)); opts.imtu = chan->imtu; opts.omtu = chan->omtu;
@@ -427,6 +418,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, opts.max_tx = chan->max_tx; opts.txwin_size = chan->tx_win; +BT_DBG ("mode 0x%2.2x" , chan->mode); + len = min_t(unsigned int, len, sizeof(opts));if (copy_to_user (optval, (char *) &opts, len)) err = -EFAULT ;
@@ -643,11 +636,6 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,switch (optname) {case L2CAP_OPTIONS : -if (bdaddr_type_is_le (chan->src_type)) { - err = -EINVAL ; -break ; - } -if (sk->sk_state ==BT_CONNECTED ) { err = -EINVAL ;break ;
@@ -680,6 +668,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, chan->mode = opts.mode;switch (chan->mode) {case L2CAP_MODE_LE_FLOWCTL : +case L2CAP_MODE_EXT_FLOWCTL :break ;case L2CAP_MODE_BASIC :clear_bit (CONF_STATE2_DEVICE , &chan->conf_state);
@@ -694,6 +683,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,break ; } +BT_DBG ("mode 0x%2.2x" , chan->mode); + chan->imtu = opts.imtu; chan->omtu = opts.omtu; chan->fcs = opts.fcs;
@@ -926,7 +917,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,break ; } -if (sk->sk_state ==BT_CONNECTED ) { +if (chan->mode ==L2CAP_MODE_LE_FLOWCTL && + sk->sk_state ==BT_CONNECTED ) { err = -EISCONN ;break ; }
@@ -936,7 +928,12 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,break ; } - chan->imtu = opt; +if (chan->mode ==L2CAP_MODE_EXT_FLOWCTL && + sk->sk_state ==BT_CONNECTED ) + err =l2cap_chan_reconfigure (chan, opt); +else + chan->imtu = opt; +break ;default :
@@ -991,7 +988,11 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg,if (sk->sk_state ==BT_CONNECT2 &&test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags)) { -if (bdaddr_type_is_le (pi->chan->src_type)) { +if (pi->chan->mode ==L2CAP_MODE_EXT_FLOWCTL ) { + sk->sk_state =BT_CONNECTED ; + pi->chan->state =BT_CONNECTED ; +__l2cap_ext_flowctl_conn_rsp_defer (pi->chan); + }if (bdaddr_type_is_le (pi->chan->src_type)) { sk->sk_state =BT_CONNECTED ; pi->chan->state =BT_CONNECTED ;__l2cap_le_connect_rsp_defer (pi->chan);
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v3 5/8 Bluetooth: hci_vhci: Add support for ISO packets
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make virtual controllers to pass ISO packets around.
--- drivers/bluetooth/hci_vhci.c | 1 + 1 file changed, 1 insertion(+)
drivers/bluetooth/hci_vhci.c +1 -0
@@ -178,6 +178,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,case HCI_EVENT_PKT :case HCI_ACLDATA_PKT :case HCI_SCODATA_PKT : +case HCI_ISODATA_PKT :if (!data->hdev) {kfree_skb (skb);return -ENODEV ;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 5/11 Bluetooth: L2CAP: Rename FLAG_LE_CONN_REQ_SENT to FLAG_LE_FLOWCTL_CONN_REQ_SENT
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This renames FLAG_LE_CONN_REQ_SENT to FLAG_LE_FLOWCTL_CONN_REQ_SENT so it is consistent with the naming scheme used for enhanced flow control.
--- include/net/bluetooth/l2cap.h | 2 +- net/bluetooth/l2cap_core.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/bluetooth/l2cap.h +1 -1
@@ -765,7 +765,7 @@ enum {FLAG_EXT_CTRL ,FLAG_EFS_ENABLE ,FLAG_DEFER_SETUP , -FLAG_LE_CONN_REQ_SENT , +FLAG_LE_FLOWCTL_CONN_REQ_SENT ,FLAG_EXT_FLOWCTL_CONN_REQ_SENT ,FLAG_PENDING_SECURITY , FLAG_HOLD_HCI_CONN,
net/bluetooth/l2cap_core.c +2 -2
@@ -1309,7 +1309,7 @@ static void l2cap_le_connect(struct l2cap_chan *chan)struct l2cap_conn *conn = chan->conn;struct l2cap_le_conn_req req; -if (test_and_set_bit (FLAG_LE_CONN_REQ_SENT , &chan->flags)) +if (test_and_set_bit (FLAG_LE_FLOWCTL_CONN_REQ_SENT , &chan->flags))return ;if (!chan->imtu)
@@ -5534,7 +5534,7 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn, chan->sec_level = sec_level;/* We'll need to send a new Connect Request */ -clear_bit (FLAG_LE_CONN_REQ_SENT , &chan->flags); +clear_bit (FLAG_LE_FLOWCTL_CONN_REQ_SENT , &chan->flags);smp_conn_security (hcon, chan->sec_level);break ;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 6/11 Bluetooth: hci_vhci: Add support for ISO packets
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make virtual controllers to pass ISO packets around.
--- drivers/bluetooth/hci_vhci.c | 1 + 1 file changed, 1 insertion(+)
drivers/bluetooth/hci_vhci.c +1 -0
@@ -178,6 +178,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,case HCI_EVENT_PKT :case HCI_ACLDATA_PKT :case HCI_SCODATA_PKT : +case HCI_ISODATA_PKT :if (!data->hdev) {kfree_skb (skb);return -ENODEV ;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v3 6/8 Bluetooth: monitor: Add support for ISO packets
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enables passing ISO packets to the monitor socket.
--- include/net/bluetooth/hci_mon.h | 2 ++ net/bluetooth/hci_sock.c | 6 ++++++ 2 files changed, 8 insertions(+)
include/net/bluetooth/hci_mon.h +2 -0
@@ -49,6 +49,8 @@ struct hci_mon_hdr {#define HCI_MON_CTRL_CLOSE 15#define HCI_MON_CTRL_COMMAND 16#define HCI_MON_CTRL_EVENT 17 +#define HCI_MON_ISO_TX_PKT 18 +#define HCI_MON_ISO_RX_PKT 19struct hci_mon_new_index {__u8 type;
net/bluetooth/hci_sock.c +6 -0
@@ -324,6 +324,12 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)else opcode =cpu_to_le16 (HCI_MON_SCO_TX_PKT );break ; +case HCI_ISODATA_PKT : +if (bt_cb (skb)->incoming) + opcode =cpu_to_le16 (HCI_MON_ISO_RX_PKT ); +else + opcode =cpu_to_le16 (HCI_MON_ISO_TX_PKT ); +break ;case HCI_DIAG_PKT : opcode =cpu_to_le16 (HCI_MON_VENDOR_DIAG );break ;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v3 7/8 Bluetooth: Make use of __check_timeout on hci_sched_le
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This reuse __check_timeout on hci_sched_le following the same logic used hci_sched_acl.
--- net/bluetooth/hci_core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
net/bluetooth/hci_core.c +3 -8
@@ -4298,15 +4298,10 @@ static void hci_sched_le(struct hci_dev *hdev)if (!hci_conn_num (hdev,LE_LINK ))return ; -if (!hci_dev_test_flag (hdev,HCI_UNCONFIGURED )) { -/* LE tx timeout must be longer than maximum -* link supervision timeout (40.9 seconds) */ -if (!hdev->le_cnt && hdev->le_pkts && -time_after (jiffies, hdev->le_last_tx +HZ *45 )) -hci_link_tx_to (hdev,LE_LINK ); - } - cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; + +__check_timeout (hdev, cnt); + tmp = cnt;while (cnt && (chan =hci_chan_sent (hdev,LE_LINK , "e))) {u32 priority = (skb_peek (&chan->data_q))->priority;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v4 7/11 Bluetooth: monitor: Add support for ISO packets
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enables passing ISO packets to the monitor socket.
--- include/net/bluetooth/hci_mon.h | 2 ++ net/bluetooth/hci_sock.c | 6 ++++++ 2 files changed, 8 insertions(+)
include/net/bluetooth/hci_mon.h +2 -0
@@ -49,6 +49,8 @@ struct hci_mon_hdr {#define HCI_MON_CTRL_CLOSE 15#define HCI_MON_CTRL_COMMAND 16#define HCI_MON_CTRL_EVENT 17 +#define HCI_MON_ISO_TX_PKT 18 +#define HCI_MON_ISO_RX_PKT 19struct hci_mon_new_index {__u8 type;
net/bluetooth/hci_sock.c +6 -0
@@ -324,6 +324,12 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)else opcode =cpu_to_le16 (HCI_MON_SCO_TX_PKT );break ; +case HCI_ISODATA_PKT : +if (bt_cb (skb)->incoming) + opcode =cpu_to_le16 (HCI_MON_ISO_RX_PKT ); +else + opcode =cpu_to_le16 (HCI_MON_ISO_TX_PKT ); +break ;case HCI_DIAG_PKT : opcode =cpu_to_le16 (HCI_MON_VENDOR_DIAG );break ;
Signature · 1 line
2.21.0
Luiz Augusto von Dentz
maintainerPATCH v3 8/8 Bluetooth: hci_h4: Add support for ISO packets
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This enabled H4 driver to properly handle ISO packets.
--- drivers/bluetooth/hci_h4.c | 1 + drivers/bluetooth/hci_uart.h | 7 +++++++ 2 files changed, 8 insertions(+)
drivers/bluetooth/hci_h4.c +1 -0
@@ -103,6 +103,7 @@ static const struct h4_recv_pkt h4_recv_pkts[] = { { H4_RECV_ACL, .recv = hci_recv_frame }, { H4_RECV_SCO, .recv = hci_recv_frame }, { H4_RECV_EVENT, .recv = hci_recv_frame }, + { H4_RECV_ISO, .recv = hci_recv_frame }, };/* Recv data */
drivers/bluetooth/hci_uart.h +7 -0
@@ -143,6 +143,13 @@ struct h4_recv_pkt { .lsize = 1, \ .maxlen = HCI_MAX_EVENT_SIZE +#define H4_RECV_ISO \ + .type = HCI_ISODATA_PKT, \ + .hlen = HCI_ISO_HDR_SIZE, \ + .loff = 2, \ + .lsize = 2, \ + .maxlen = HCI_MAX_FRAME_SIZE \ +struct sk_buff *h4_recv_buf (struct hci_dev *hdev,struct sk_buff *skb,const unsigned char *buffer,int count,const struct h4_recv_pkt *pkts,int pkts_count);
Signature · 1 line
2.21.0