[PATCH 0/2] Add support fo BT LE Connection Parameters
This patch series adds support for calling setsockopt() on a l2cap socket to set connection parameters prior to calling connect(). The motivation for setting the paremeters prior to connect is to: 1) Reduce the issues caused with BT and WiFi hardware radios that share the same antenna. During the connection, typically the WiFi portion of the radio is blocked. Setting the connection parameters such as the window and interval allow the userspace app to tune and compromise. 2) Eliminate the need to call HCI connection update when the paremeters are known ahead of time. Kyle Manna (2): bluetooth: Pass HCI LE connection parameters bluetooth: Add l2cap sockopt for LE conn params include/net/bluetooth/bluetooth.h | 2 ++ include/net/bluetooth/hci_core.h | 5 +++-- include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/hci_conn.c | 33 ++--- net/bluetooth/l2cap_core.c| 13 +++-- net/bluetooth/l2cap_sock.c| 25 + net/bluetooth/mgmt.c | 4 ++-- net/bluetooth/sco.c | 2 +- 8 files changed, 60 insertions(+), 26 deletions(-) -- 1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/2] bluetooth: Pass HCI LE connection parameters
* Move hard coded values in hci_le_create_connection() for Bluetooth LE connections to the channel defaults so that they can be overriden by a patch to follow. * Add an argument to hci_connect() so that special connections can pass additional connection parameters. Update existing function calls to pass NULL and not change the functionality. Signed-off-by: Kyle Manna --- include/net/bluetooth/hci_core.h | 5 +++-- include/net/bluetooth/l2cap.h| 2 ++ net/bluetooth/hci_conn.c | 33 ++--- net/bluetooth/l2cap_core.c | 13 +++-- net/bluetooth/l2cap_sock.c | 2 ++ net/bluetooth/mgmt.c | 4 ++-- net/bluetooth/sco.c | 2 +- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 7cb6d36..5169ec6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -591,8 +591,9 @@ void hci_chan_del(struct hci_chan *chan); void hci_chan_list_flush(struct hci_conn *conn); struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); -struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, -__u8 dst_type, __u8 sec_level, __u8 auth_type); +struct hci_conn *hci_connect(struct hci_dev *hdev, int type, void *cp, +bdaddr_t *dst, __u8 dst_type, +__u8 sec_level, __u8 auth_type); int hci_conn_check_link_mode(struct hci_conn *conn); int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index fb94cf1..7ebbf56 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -438,6 +438,8 @@ struct l2cap_chan { struct l2cap_conn *conn; struct hci_conn *hs_hcon; struct hci_chan *hs_hchan; + struct hci_cp_le_create_conn cp_le; + struct kref kref; __u8state; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 6c7f363..9894e2b 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -31,28 +31,20 @@ #include #include -static void hci_le_create_connection(struct hci_conn *conn) +static void hci_le_create_connection(struct hci_conn *conn, +struct hci_cp_le_create_conn *cp) { struct hci_dev *hdev = conn->hdev; - struct hci_cp_le_create_conn cp; conn->state = BT_CONNECT; conn->out = true; conn->link_mode |= HCI_LM_MASTER; conn->sec_level = BT_SECURITY_LOW; - memset(, 0, sizeof(cp)); - cp.scan_interval = __constant_cpu_to_le16(0x0060); - cp.scan_window = __constant_cpu_to_le16(0x0030); - bacpy(_addr, >dst); - cp.peer_addr_type = conn->dst_type; - cp.conn_interval_min = __constant_cpu_to_le16(0x0028); - cp.conn_interval_max = __constant_cpu_to_le16(0x0038); - cp.supervision_timeout = __constant_cpu_to_le16(0x002a); - cp.min_ce_len = __constant_cpu_to_le16(0x); - cp.max_ce_len = __constant_cpu_to_le16(0x); - - hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), ); + bacpy(>peer_addr, >dst); + cp->peer_addr_type = conn->dst_type; + + hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(*cp), cp); } static void hci_le_create_connection_cancel(struct hci_conn *conn) @@ -507,7 +499,8 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) EXPORT_SYMBOL(hci_get_route); static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, - u8 dst_type, u8 sec_level, u8 auth_type) + u8 dst_type, u8 sec_level, u8 auth_type, + struct hci_cp_le_create_conn *cp) { struct hci_conn *le; @@ -525,7 +518,7 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, return ERR_PTR(-ENOMEM); le->dst_type = bdaddr_to_le(dst_type); - hci_le_create_connection(le); + hci_le_create_connection(le, cp); } le->pending_sec_level = sec_level; @@ -602,14 +595,16 @@ static struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, } /* Create SCO, ACL or LE connection. */ -struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, -__u8 dst_type, __u8 sec_level, __u8 auth_type) +struct hci_conn *hci_connect(struct hci_dev *hdev, int type, void *cp, +bdaddr_t *dst, __u8 dst_type, +__u8 sec_level, __u8 auth_type) { BT_DBG("%s dst %pMR type 0x%x", hdev->name
[PATCH 2/2] bluetooth: Add l2cap sockopt for LE conn params
* Userspace can now specify connection parameters to override the defaults prior to connecting to the device. * The intention is that setsockopt() will be called before connect() is called in userspace apps and BlueZ libraries. * It is critical to set these parameters prior to connect() to avoid issues with hardware that must arbitrate the antenna access between Bluetooth LE and things like WiFi. Aggressive connect (and scan) window and interval values result in significant WiFi degradation. * Reduces the need to call the hci LE Connection Update Command to override the "defaults" when the desired values are known ahead of time. * Add BT_LE_CONN_PARAM socket option. Signed-off-by: Kyle Manna --- include/net/bluetooth/bluetooth.h | 2 ++ net/bluetooth/l2cap_sock.c| 23 +++ 2 files changed, 25 insertions(+) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 10eb9b3..36e9242 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -82,6 +82,8 @@ struct bt_power { #define BT_CHANNEL_POLICY 10 +#define BT_LE_CONN_PARAM 11 + /* BR/EDR only (default policy) * AMP controllers cannot be used. * Channel move requests from the remote device are denied. diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 2c7917e..17b6e2b 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -454,6 +454,15 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, err = -EFAULT; break; + case BT_LE_CONN_PARAM: + + len = min_t(unsigned int, len, + sizeof(struct hci_cp_le_create_conn)); + if (copy_to_user(optval, (char *) >cp_le, len)) + err = -EFAULT; + + break; + default: err = -ENOPROTOOPT; break; @@ -749,6 +758,20 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; + case BT_LE_CONN_PARAM: + + if (sizeof(struct hci_cp_le_create_conn) != optlen) { + err = -EINVAL; + break; + } + + if (copy_from_user((char *) >cp_le, optval, optlen)) { + err = -EFAULT; + break; + } + + break; + default: err = -ENOPROTOOPT; break; -- 1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/2] bluetooth: Add l2cap sockopt for LE conn params
* Userspace can now specify connection parameters to override the defaults prior to connecting to the device. * The intention is that setsockopt() will be called before connect() is called in userspace apps and BlueZ libraries. * It is critical to set these parameters prior to connect() to avoid issues with hardware that must arbitrate the antenna access between Bluetooth LE and things like WiFi. Aggressive connect (and scan) window and interval values result in significant WiFi degradation. * Reduces the need to call the hci LE Connection Update Command to override the defaults when the desired values are known ahead of time. * Add BT_LE_CONN_PARAM socket option. Signed-off-by: Kyle Manna k...@kylemanna.com --- include/net/bluetooth/bluetooth.h | 2 ++ net/bluetooth/l2cap_sock.c| 23 +++ 2 files changed, 25 insertions(+) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 10eb9b3..36e9242 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -82,6 +82,8 @@ struct bt_power { #define BT_CHANNEL_POLICY 10 +#define BT_LE_CONN_PARAM 11 + /* BR/EDR only (default policy) * AMP controllers cannot be used. * Channel move requests from the remote device are denied. diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 2c7917e..17b6e2b 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -454,6 +454,15 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, err = -EFAULT; break; + case BT_LE_CONN_PARAM: + + len = min_t(unsigned int, len, + sizeof(struct hci_cp_le_create_conn)); + if (copy_to_user(optval, (char *) chan-cp_le, len)) + err = -EFAULT; + + break; + default: err = -ENOPROTOOPT; break; @@ -749,6 +758,20 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, break; + case BT_LE_CONN_PARAM: + + if (sizeof(struct hci_cp_le_create_conn) != optlen) { + err = -EINVAL; + break; + } + + if (copy_from_user((char *) chan-cp_le, optval, optlen)) { + err = -EFAULT; + break; + } + + break; + default: err = -ENOPROTOOPT; break; -- 1.8.1.2 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/2] bluetooth: Pass HCI LE connection parameters
* Move hard coded values in hci_le_create_connection() for Bluetooth LE connections to the channel defaults so that they can be overriden by a patch to follow. * Add an argument to hci_connect() so that special connections can pass additional connection parameters. Update existing function calls to pass NULL and not change the functionality. Signed-off-by: Kyle Manna k...@kylemanna.com --- include/net/bluetooth/hci_core.h | 5 +++-- include/net/bluetooth/l2cap.h| 2 ++ net/bluetooth/hci_conn.c | 33 ++--- net/bluetooth/l2cap_core.c | 13 +++-- net/bluetooth/l2cap_sock.c | 2 ++ net/bluetooth/mgmt.c | 4 ++-- net/bluetooth/sco.c | 2 +- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 7cb6d36..5169ec6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -591,8 +591,9 @@ void hci_chan_del(struct hci_chan *chan); void hci_chan_list_flush(struct hci_conn *conn); struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); -struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, -__u8 dst_type, __u8 sec_level, __u8 auth_type); +struct hci_conn *hci_connect(struct hci_dev *hdev, int type, void *cp, +bdaddr_t *dst, __u8 dst_type, +__u8 sec_level, __u8 auth_type); int hci_conn_check_link_mode(struct hci_conn *conn); int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index fb94cf1..7ebbf56 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -438,6 +438,8 @@ struct l2cap_chan { struct l2cap_conn *conn; struct hci_conn *hs_hcon; struct hci_chan *hs_hchan; + struct hci_cp_le_create_conn cp_le; + struct kref kref; __u8state; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 6c7f363..9894e2b 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -31,28 +31,20 @@ #include net/bluetooth/a2mp.h #include net/bluetooth/smp.h -static void hci_le_create_connection(struct hci_conn *conn) +static void hci_le_create_connection(struct hci_conn *conn, +struct hci_cp_le_create_conn *cp) { struct hci_dev *hdev = conn-hdev; - struct hci_cp_le_create_conn cp; conn-state = BT_CONNECT; conn-out = true; conn-link_mode |= HCI_LM_MASTER; conn-sec_level = BT_SECURITY_LOW; - memset(cp, 0, sizeof(cp)); - cp.scan_interval = __constant_cpu_to_le16(0x0060); - cp.scan_window = __constant_cpu_to_le16(0x0030); - bacpy(cp.peer_addr, conn-dst); - cp.peer_addr_type = conn-dst_type; - cp.conn_interval_min = __constant_cpu_to_le16(0x0028); - cp.conn_interval_max = __constant_cpu_to_le16(0x0038); - cp.supervision_timeout = __constant_cpu_to_le16(0x002a); - cp.min_ce_len = __constant_cpu_to_le16(0x); - cp.max_ce_len = __constant_cpu_to_le16(0x); - - hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), cp); + bacpy(cp-peer_addr, conn-dst); + cp-peer_addr_type = conn-dst_type; + + hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(*cp), cp); } static void hci_le_create_connection_cancel(struct hci_conn *conn) @@ -507,7 +499,8 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src) EXPORT_SYMBOL(hci_get_route); static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, - u8 dst_type, u8 sec_level, u8 auth_type) + u8 dst_type, u8 sec_level, u8 auth_type, + struct hci_cp_le_create_conn *cp) { struct hci_conn *le; @@ -525,7 +518,7 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, return ERR_PTR(-ENOMEM); le-dst_type = bdaddr_to_le(dst_type); - hci_le_create_connection(le); + hci_le_create_connection(le, cp); } le-pending_sec_level = sec_level; @@ -602,14 +595,16 @@ static struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, } /* Create SCO, ACL or LE connection. */ -struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, -__u8 dst_type, __u8 sec_level, __u8 auth_type) +struct hci_conn *hci_connect(struct hci_dev *hdev, int type, void *cp, +bdaddr_t *dst, __u8 dst_type, +__u8 sec_level, __u8 auth_type) { BT_DBG(%s dst %pMR type 0x
[PATCH 0/2] Add support fo BT LE Connection Parameters
This patch series adds support for calling setsockopt() on a l2cap socket to set connection parameters prior to calling connect(). The motivation for setting the paremeters prior to connect is to: 1) Reduce the issues caused with BT and WiFi hardware radios that share the same antenna. During the connection, typically the WiFi portion of the radio is blocked. Setting the connection parameters such as the window and interval allow the userspace app to tune and compromise. 2) Eliminate the need to call HCI connection update when the paremeters are known ahead of time. Kyle Manna (2): bluetooth: Pass HCI LE connection parameters bluetooth: Add l2cap sockopt for LE conn params include/net/bluetooth/bluetooth.h | 2 ++ include/net/bluetooth/hci_core.h | 5 +++-- include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/hci_conn.c | 33 ++--- net/bluetooth/l2cap_core.c| 13 +++-- net/bluetooth/l2cap_sock.c| 25 + net/bluetooth/mgmt.c | 4 ++-- net/bluetooth/sco.c | 2 +- 8 files changed, 60 insertions(+), 26 deletions(-) -- 1.8.1.2 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/