Bluetooth: Add BT_MODE socket option
Subsystems (2)
Luiz Augusto von Dentz
maintainerRFC 1/5 Bluetooth: Add BT_MODE socket option
From: Luiz Augusto von Dentz <[email protected]>
This adds BT_MODE socket option which can be used to set L2CAP modes, including modes only supported over LE which were not supported using the L2CAP_OPTIONS.
--- include/net/bluetooth/bluetooth.h | 2 + net/bluetooth/l2cap_sock.c | 64 ++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 13 deletions(-)
include/net/bluetooth/bluetooth.h +2 -0
@@ -139,6 +139,8 @@ struct bt_voice {#define BT_PHY_LE_CODED_TX 0x00002000#define BT_PHY_LE_CODED_RX 0x00004000 +#define BT_MODE 15 + __printf(1, 2)void bt_info (const char *fmt, ...);__printf (1 ,2 )
net/bluetooth/l2cap_sock.c +51 -13
88 lines not on this page · raw message
Signature · 1 line
2.21.1
Luiz Augusto von Dentz
maintainerRFC 2/5 Bluetooth: L2CAP: Add definitions for Enhanced Credit Based Mode
From: 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 | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
include/net/bluetooth/l2cap.h +39 -0
@@ -119,6 +119,10 @@ struct l2cap_conninfo {#define L2CAP_LE_CONN_REQ 0x14#define L2CAP_LE_CONN_RSP 0x15#define L2CAP_LE_CREDITS 0x16 +#define L2CAP_ECRED_CONN_REQ 0x17 +#define L2CAP_ECRED_CONN_RSP 0x18 +#define L2CAP_ECRED_RECONF_REQ 0x19 +#define L2CAP_ECRED_RECONF_RSP 0x1a/* L2CAP extended feature mask */ #define L2CAP_FEAT_FLOWCTL 0x00000001
@@ -359,6 +363,7 @@ struct l2cap_conf_rfc {* ever be used in the BR/EDR configuration phase. */ #define L2CAP_MODE_LE_FLOWCTL 0x80 +#define L2CAP_MODE_EXT_FLOWCTL 0x81struct l2cap_conf_efs {__u8 id;
@@ -483,6 +488,39 @@ struct l2cap_le_credits {__le16 credits; } __packed; +#define L2CAP_ECRED_MIN_MTU 64 +#define L2CAP_ECRED_MIN_MPS 64 + +struct l2cap_ecred_conn_req { +__le16 psm; +__le16 mtu; +__le16 mps; +__le16 credits; +__le16 scid[0 ]; +} __packed; + +struct l2cap_ecred_conn_rsp { +__le16 mtu; +__le16 mps; +__le16 credits; +__le16 result; +__le16 dcid[0 ]; +}; + +struct l2cap_ecred_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_ecred_reconf_rsp { +__le16 result; +} __packed; +/* ----- L2CAP channels and connections ----- */ struct l2cap_seq_list {__u16 head;
@@ -724,6 +762,7 @@ enum {FLAG_EFS_ENABLE ,FLAG_DEFER_SETUP ,FLAG_LE_CONN_REQ_SENT , +FLAG_ECRED_CONN_REQ_SENT ,FLAG_PENDING_SECURITY , FLAG_HOLD_HCI_CONN, };
Signature · 1 line
2.21.1
Luiz Augusto von Dentz
maintainerRFC 3/5 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 | 545 +++++++++++++++++++++++++++++++++- net/bluetooth/l2cap_sock.c | 26 +- 3 files changed, 554 insertions(+), 21 deletions(-)
include/net/bluetooth/l2cap.h +4 -0
@@ -294,6 +294,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
@@ -962,6 +964,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_ecred_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);
@@ -971,6 +974,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 +529 -16
674 lines not on this page · raw message
net/bluetooth/l2cap_sock.c +21 -5
@@ -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,7 +409,7 @@ 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 +/* LE sockets should use BT_SNDMTU/BT_RCVMTU/BT_MODE, but since * legacy ATT code depends on getsockopt for * L2CAP_OPTIONS we need to let this pass. */
@@ -427,6 +428,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 ;
@@ -655,6 +658,7 @@ static int l2cap_set_mode(struct l2cap_chan *chan, u8 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);
@@ -727,6 +731,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;
@@ -959,7 +965,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 ; }
@@ -969,7 +976,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 ;case BT_MODE :
@@ -1042,7 +1054,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_ecred_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.1
Luiz Augusto von Dentz
maintainerRFC 4/5 Bluetooth: L2CAP: Add module option to enable ECRED mode
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This should make it safe to have the code upstream without affecting stable systems since there are a few details not sort out with ECRED mode e.g: how to initiate multiple connections at once.
--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 15 +++++++++++++++ net/bluetooth/l2cap_sock.c | 8 ++++++++ 3 files changed, 24 insertions(+)
include/net/bluetooth/l2cap.h +1 -0
@@ -958,6 +958,7 @@ static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan) }extern bool disable_ertm; +extern bool enable_ecred;int l2cap_init_sockets (void );void l2cap_cleanup_sockets (void );
net/bluetooth/l2cap_core.c +15 -0
@@ -45,6 +45,7 @@#define LE_FLOWCTL_MAX_CREDITS 65535bool disable_ertm; +bool enable_ecred;static u32 l2cap_feat_mask =L2CAP_FEAT_FIXED_CHAN |L2CAP_FEAT_UCD ;
@@ -5849,6 +5850,9 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn,int i, num_scid;bool defer = false; +if (!enable_ecred) +return -EINVAL ; +if (cmd_len <sizeof (*req) || cmd_len -sizeof (*req) %sizeof (u16)) { result =L2CAP_CR_LE_INVALID_PARAMS ; goto response;
@@ -6092,6 +6096,9 @@ static inline int l2cap_ecred_reconf_req(struct l2cap_conn *conn,struct l2cap_chan *chan;int i, num_scid; +if (!enable_ecred) +return -EINVAL ; +if (cmd_len <sizeof (*req) || cmd_len -sizeof (*req) %sizeof (u16)) { result =L2CAP_CR_LE_INVALID_PARAMS ; goto respond;
@@ -7726,7 +7733,12 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,case L2CAP_MODE_BASIC :break ;case L2CAP_MODE_LE_FLOWCTL : +break ;case L2CAP_MODE_EXT_FLOWCTL : +if (!enable_ecred) { + err = -EOPNOTSUPP ; + goto done; + }break ;case L2CAP_MODE_ERTM :case L2CAP_MODE_STREAMING :
@@ -8304,3 +8316,6 @@ void l2cap_exit(void)module_param (disable_ertm, bool,0644 );MODULE_PARM_DESC (disable_ertm,"Disable enhanced retransmission mode" ); + +module_param (enable_ecred, bool,0644 ); +MODULE_PARM_DESC (enable_ecred,"Enable enhanced credit flow control mode" );
net/bluetooth/l2cap_sock.c +8 -0
@@ -273,7 +273,12 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)switch (chan->mode) {case L2CAP_MODE_BASIC :case L2CAP_MODE_LE_FLOWCTL : +break ;case L2CAP_MODE_EXT_FLOWCTL : +if (!enable_ecred) { + err = -EOPNOTSUPP ; + goto done; + }break ;case L2CAP_MODE_ERTM :case L2CAP_MODE_STREAMING :
@@ -658,7 +663,10 @@ static int l2cap_set_mode(struct l2cap_chan *chan, u8 mode) {switch (chan->mode) {case L2CAP_MODE_LE_FLOWCTL : +break ;case L2CAP_MODE_EXT_FLOWCTL : +if (!enable_ecred) +return -EINVAL ;break ;case L2CAP_MODE_BASIC :clear_bit (CONF_STATE2_DEVICE , &chan->conf_state);
Signature · 1 line
2.21.1
Luiz Augusto von Dentz
maintainerRFC 5/5 Bluetooth: L2CAP: Use DEFER_SETUP to group ECRED connections
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This uses the DEFER_SETUP flag to group channels with L2CAP_CREDIT_BASED_CONNECTION_REQ.
--- include/net/bluetooth/l2cap.h | 5 +++ net/bluetooth/l2cap_core.c | 81 ++++++++++++++++++++++++++++++----- net/bluetooth/l2cap_sock.c | 49 ++++++++++++++++++--- 3 files changed, 120 insertions(+), 15 deletions(-)
include/net/bluetooth/l2cap.h +5 -0
@@ -47,6 +47,7 @@#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF#define L2CAP_BREDR_MAX_PAYLOAD 1019/* 3-DH5 packet */ #define L2CAP_LE_MIN_MTU 23 +#define L2CAP_ECRED_CONN_SCID_MAX 5#define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100)#define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000)
@@ -660,6 +661,7 @@ struct l2cap_ops {void (*suspend) (struct l2cap_chan *chan);void (*set_shutdown) (struct l2cap_chan *chan);long (*get_sndtimeo) (struct l2cap_chan *chan); +struct pid *(*get_peer_pid) (struct l2cap_chan *chan);struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,unsigned long hdr_len,unsigned long len,int nb);
@@ -983,6 +985,9 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan);int l2cap_ertm_init (struct l2cap_chan *chan);void l2cap_chan_add (struct l2cap_conn *conn,struct l2cap_chan *chan);void __l2cap_chan_add (struct l2cap_conn *conn,struct l2cap_chan *chan); +void l2cap_chan_list (struct l2cap_conn *conn, +void (*func)(struct l2cap_chan *chan,void *data), +void *data);void l2cap_chan_del (struct l2cap_chan *chan,int err);void l2cap_send_conn_req (struct l2cap_chan *chan);void l2cap_move_start (struct l2cap_chan *chan);
net/bluetooth/l2cap_core.c +71 -10
106 lines not on this page · raw message
net/bluetooth/l2cap_sock.c +44 -5
79 lines not on this page · raw message
Signature · 1 line
2.21.1
Marcel Holtmann
maintainerHi Luiz,
Quoted 15 lines
This adds
BT_MODEsocket option which can be used to set L2CAP modes, including modes only supported over LE which were not supported using theL2CAP_OPTIONS.Signed-off-by Luiz Augusto von Dentz <[email protected]>---
include/net/bluetooth/bluetooth.h| 2 +net/bluetooth/l2cap_sock.c| 64 ++++++++++++++++++++++++-------2 files changed, 53 insertions(+), 13 deletions(-)include/net/bluetooth/bluetooth.h +0
-0
include/net/bluetooth/bluetooth.h struct bt_voice { · line 143
Quoted 5 lines
include/net/bluetooth/bluetooth.h +2
-0@@ -139,6 +139,8 @@ struct bt_voice {#define BT_PHY_LE_CODED_TX 0x00002000#define BT_PHY_LE_CODED_RX 0x00004000 +#define BT_MODE 15 +
can we postpone this change. I like to get your patches 2, 3 and 4 merged first. That way we can do some initial testing here.
Regards
Marcel
Luiz Augusto von Dentz
maintainerHi Marcel,
Quoted 21 lines · Marcel Holtmann
Hi Luiz,
Quoted 18 lines
This adds
BT_MODEsocket option which can be used to set L2CAP modes, including modes only supported over LE which were not supported using theL2CAP_OPTIONS.Signed-off-by Luiz Augusto von Dentz <[email protected]>---
include/net/bluetooth/bluetooth.h| 2 +net/bluetooth/l2cap_sock.c| 64 ++++++++++++++++++++++++-------2 files changed, 53 insertions(+), 13 deletions(-)include/net/bluetooth/bluetooth.h +0
-0@@ -139,6 +139,8 @@ struct bt_voice {#define BT_PHY_LE_CODED_TX 0x00002000#define BT_PHY_LE_CODED_RX 0x00004000
Quoted 4 lines
include/net/bluetooth/bluetooth.h struct bt_voice { · line 143
Quoted 2 lines
include/net/bluetooth/bluetooth.h +2
-0+#define BT_MODE 15 +can we postpone this change. I like to get your patches 2, 3 and 4 merged first. That way we can do some initial testing here.
Sure, but without this there is no way to use the new mode from userspace, I could perhaps make it condition to enabled_ecred, how about that?
Signature · 1 line
Luiz Augusto von Dentz
Marcel Holtmann
maintainerHi Luiz,
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
This adds
BT_MODEsocket option which can be used to set L2CAP modes, including modes only supported over LE which were not supported using theL2CAP_OPTIONS.Signed-off-by Luiz Augusto von Dentz <[email protected]>---
include/net/bluetooth/bluetooth.h| 2 +net/bluetooth/l2cap_sock.c| 64 ++++++++++++++++++++++++-------2 files changed, 53 insertions(+), 13 deletions(-)include/net/bluetooth/bluetooth.h +0
-0@@ -139,6 +139,8 @@ struct bt_voice {#define BT_PHY_LE_CODED_TX 0x00002000#define BT_PHY_LE_CODED_RX 0x00004000
Quoted 8 lines
Quoted 4 lines
include/net/bluetooth/bluetooth.h struct bt_voice { · line 143
Quoted 2 lines
include/net/bluetooth/bluetooth.h +2
-0+#define BT_MODE 15 +can we postpone this change. I like to get your patches 2, 3 and 4 merged first. That way we can do some initial testing here.
Sure, but without this there is no way to use the new mode from userspace, I could perhaps make it condition to
enabled_ecred, how about that?
that is what I am thinking. Use the module option to enable the mode for testing purposes.
Regards
Marcel