diff mbox

[2/2] bluetooth: Add l2cap sockopt for LE conn params

Message ID 1372980303-3007-3-git-send-email-kyle@kylemanna.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Kyle Manna July 4, 2013, 11:25 p.m. UTC
* 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 <kyle@kylemanna.com>
---
 include/net/bluetooth/bluetooth.h |  2 ++
 net/bluetooth/l2cap_sock.c        | 23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+)
diff mbox

Patch

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;