]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
Bluetooth: Add BT_POWER L2CAP socket option.
authorJaikumar Ganesh <jaikumar@google.com>
Tue, 24 May 2011 01:06:04 +0000 (18:06 -0700)
committerGustavo F. Padovan <padovan@profusion.mobi>
Wed, 8 Jun 2011 19:58:19 +0000 (16:58 -0300)
Add BT_POWER socket option used to control the power
characteristics of the underlying ACL link. When the remote end
has put the link in sniff mode and the host stack wants to send
data we need need to explicitly exit sniff mode to work well with
certain devices (For example, A2DP on Plantronics Voyager 855).
However, this causes problems with HID devices.

Hence, moving into active mode when sending data, irrespective
of who set the sniff mode has been made as a socket option. By
default, we will move into active mode. HID devices can set the
L2CAP socket option to prevent this from happening.

Currently, this has been implemented for L2CAP sockets. This has been
tested with incoming and outgoing L2CAP sockets for HID and A2DP.

Based on discussions on linux-bluetooth and patches submitted by
Andrei Emeltchenko.

Signed-off-by: Jaikumar Ganesh <jaikumar@google.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/bluetooth.h
include/net/bluetooth/hci_core.h
include/net/bluetooth/l2cap.h
net/bluetooth/hci_conn.c
net/bluetooth/hci_core.c
net/bluetooth/l2cap_core.c
net/bluetooth/l2cap_sock.c

index 43750439c52181fffdaecb795c1cdbe1b9bd05be..af930a3a66beae7dce911a484f99f0f71ca9792b 100644 (file)
@@ -69,6 +69,13 @@ struct bt_security {
 #define BT_FLUSHABLE_OFF       0
 #define BT_FLUSHABLE_ON                1
 
+#define BT_POWER       9
+struct bt_power {
+       __u8 force_active;
+};
+#define BT_POWER_FORCE_ACTIVE_OFF 0
+#define BT_POWER_FORCE_ACTIVE_ON  1
+
 #define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg)
 #define BT_ERR(fmt, arg...)  printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg)
 #define BT_DBG(fmt, arg...)  pr_debug("%s: " fmt "\n" , __func__ , ## arg)
@@ -150,6 +157,7 @@ struct bt_skb_cb {
        __u8 retries;
        __u8 sar;
        unsigned short channel;
+       __u8 force_active;
 };
 #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
 
index 5be1502295747b3074f08fd3ef45f6b6f1dacb2c..818eadbc3f7fcc5724a6a6b3c3c9f812d69e76e7 100644 (file)
@@ -438,7 +438,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
 int hci_conn_change_link_key(struct hci_conn *conn);
 int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
 
-void hci_conn_enter_active_mode(struct hci_conn *conn);
+void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
 void hci_conn_enter_sniff_mode(struct hci_conn *conn);
 
 void hci_conn_hold_device(struct hci_conn *conn);
index a2dcbfff1c51fb8b4ac01d80e7d765c03b6e54b5..0529d278e068932284babf880b62777fdadf4a5b 100644 (file)
@@ -303,6 +303,7 @@ struct l2cap_chan {
        __u8            role_switch;
        __u8            force_reliable;
        __u8            flushable;
+       __u8            force_active;
 
        __u8            ident;
 
index ce67d0ff486ff696ab87cddf007632442557ba1a..0408a93570d63eede23c46911656f75cd90d7eb2 100644 (file)
@@ -507,7 +507,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
        if (acl->state == BT_CONNECTED &&
                        (sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
                acl->power_save = 1;
-               hci_conn_enter_active_mode(acl);
+               hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON);
 
                if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->pend)) {
                        /* defer SCO setup until mode change completed */
@@ -688,7 +688,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role)
 EXPORT_SYMBOL(hci_conn_switch_role);
 
 /* Enter active mode */
-void hci_conn_enter_active_mode(struct hci_conn *conn)
+void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)
 {
        struct hci_dev *hdev = conn->hdev;
 
@@ -697,7 +697,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn)
        if (test_bit(HCI_RAW, &hdev->flags))
                return;
 
-       if (conn->mode != HCI_CM_SNIFF || !conn->power_save)
+       if (conn->mode != HCI_CM_SNIFF)
+               goto timer;
+
+       if (!conn->power_save && !force_active)
                goto timer;
 
        if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
index ff6b784c58c5343b59f13433d8be6e64fa63da51..e14e8a1cb04e68a0a52ae0616baf41525bbbae7b 100644 (file)
@@ -1969,7 +1969,7 @@ static inline void hci_sched_acl(struct hci_dev *hdev)
                while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
                        BT_DBG("skb %p len %d", skb, skb->len);
 
-                       hci_conn_enter_active_mode(conn);
+                       hci_conn_enter_active_mode(conn, bt_cb(skb)->force_active);
 
                        hci_send_frame(skb);
                        hdev->acl_last_tx = jiffies;
@@ -2108,7 +2108,7 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
        if (conn) {
                register struct hci_proto *hp;
 
-               hci_conn_enter_active_mode(conn);
+               hci_conn_enter_active_mode(conn, bt_cb(skb)->force_active);
 
                /* Send to upper protocol */
                hp = hci_proto[HCI_PROTO_L2CAP];
index bb6be6377891ca331a49644f7a9acb6424bf0bf5..6908a835a7a3f0110efc77e31380b376b32d4c96 100644 (file)
@@ -537,6 +537,8 @@ static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
        else
                flags = ACL_START;
 
+       bt_cb(skb)->force_active = BT_POWER_FORCE_ACTIVE_ON;
+
        hci_send_acl(conn->hcon, skb, flags);
 }
 
@@ -590,6 +592,8 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
        else
                flags = ACL_START;
 
+       bt_cb(skb)->force_active = chan->force_active;
+
        hci_send_acl(chan->conn->hcon, skb, flags);
 }
 
@@ -1215,6 +1219,7 @@ void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)
        else
                flags = ACL_START;
 
+       bt_cb(skb)->force_active = chan->force_active;
        hci_send_acl(hcon, skb, flags);
 }
 
index b79fb7561836026a56a8117615c4b7a1312053c3..bec3e043b254a02758ed5b6147f94aff2989a9a3 100644 (file)
@@ -390,6 +390,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
        struct sock *sk = sock->sk;
        struct l2cap_chan *chan = l2cap_pi(sk)->chan;
        struct bt_security sec;
+       struct bt_power pwr;
        int len, err = 0;
 
        BT_DBG("sk %p", sk);
@@ -438,6 +439,21 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
 
                break;
 
+       case BT_POWER:
+               if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM
+                               && sk->sk_type != SOCK_RAW) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               pwr.force_active = chan->force_active;
+
+               len = min_t(unsigned int, len, sizeof(pwr));
+               if (copy_to_user(optval, (char *) &pwr, len))
+                       err = -EFAULT;
+
+               break;
+
        default:
                err = -ENOPROTOOPT;
                break;
@@ -538,6 +554,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
        struct sock *sk = sock->sk;
        struct l2cap_chan *chan = l2cap_pi(sk)->chan;
        struct bt_security sec;
+       struct bt_power pwr;
        int len, err = 0;
        u32 opt;
 
@@ -614,6 +631,23 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
                chan->flushable = opt;
                break;
 
+       case BT_POWER:
+               if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED &&
+                                       chan->chan_type != L2CAP_CHAN_RAW) {
+                       err = -EINVAL;
+                       break;
+               }
+
+               pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
+
+               len = min_t(unsigned int, sizeof(pwr), optlen);
+               if (copy_from_user((char *) &pwr, optval, len)) {
+                       err = -EFAULT;
+                       break;
+               }
+               chan->force_active = pwr.force_active;
+               break;
+
        default:
                err = -ENOPROTOOPT;
                break;
@@ -771,6 +805,7 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent)
                chan->role_switch = pchan->role_switch;
                chan->force_reliable = pchan->force_reliable;
                chan->flushable = pchan->flushable;
+               chan->force_active = pchan->force_active;
        } else {
 
                switch (sk->sk_type) {
@@ -801,6 +836,7 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent)
                chan->role_switch = 0;
                chan->force_reliable = 0;
                chan->flushable = BT_FLUSHABLE_OFF;
+               chan->force_active = BT_POWER_FORCE_ACTIVE_ON;
        }
 
        /* Default config options */