Skip to content

Commit

Permalink
Bluetooth: Add channel policy to getsockopt/setsockopt
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Mat Martineau authored and Gustavo F. Padovan committed Nov 7, 2011
1 parent d7c4d11 commit 2ea6648
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/net/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ struct l2cap_chan {
__u16 flush_to;
__u8 mode;
__u8 chan_type;
__u8 chan_policy;

__le16 sport;

Expand Down
35 changes: 35 additions & 0 deletions net/bluetooth/l2cap_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2ea6648

Please sign in to comment.