Bluetooth: Add channel policy to getsockopt/setsockopt
authorMat Martineau <mathewm@codeaurora.org>
Wed, 2 Nov 2011 23:18:30 +0000 (16:18 -0700)
committerGustavo F. Padovan <padovan@profusion.mobi>
Mon, 7 Nov 2011 19:25:00 +0000 (17:25 -0200)
Each channel has a policy to require BR/EDR (the default),
prefer BR/EDR, or prefer AMP.

Check for valid policy value and L2CAP mode.

Signed-off-by: Mat Martineau <mathewm@codeaurora.org>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Acked-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/l2cap.h
net/bluetooth/l2cap_sock.c

index 1a62573dbd67abff1c58f491a9bbf625831d0c5a..9c7d06e6b98747eef6ce7656efdebc2cd6053e5e 100644 (file)
@@ -367,6 +367,7 @@ struct l2cap_chan {
        __u16           flush_to;
        __u8            mode;
        __u8            chan_type;
+       __u8            chan_policy;
 
        __le16          sport;
 
index 9ed6501d90f64d457d9ce000c6842dcb7eb64bc0..664762e89ecf0271f2f3dc26d08ca5e29cd96753 100644 (file)
@@ -467,6 +467,16 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
 
                break;
 
+       case BT_CHANNEL_POLICY:
+               if (!enable_hs) {
+                       err = -ENOPROTOOPT;
+                       break;
+               }
+
+               if (put_user(chan->chan_policy, (u32 __user *) optval))
+                       err = -EFAULT;
+               break;
+
        default:
                err = -ENOPROTOOPT;
                break;
@@ -690,6 +700,31 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
                        clear_bit(FLAG_FORCE_ACTIVE, &chan->flags);
                break;
 
+       case BT_CHANNEL_POLICY:
+               if (!enable_hs) {
+                       err = -ENOPROTOOPT;
+                       break;
+               }
+
+               if (get_user(opt, (u32 __user *) optval)) {
+                       err = -EFAULT;
+                       break;
+               }
+
+               if (opt > BT_CHANNEL_POLICY_AMP_PREFERRED) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               if (chan->mode != L2CAP_MODE_ERTM &&
+                               chan->mode != L2CAP_MODE_STREAMING) {
+                       err = -EOPNOTSUPP;
+                       break;
+               }
+
+               chan->chan_policy = (u8) opt;
+               break;
+
        default:
                err = -ENOPROTOOPT;
                break;