Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / net / bluetooth / hci_conn.c
index 99cd8d9..7a6f56b 100644 (file)
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 
+static void hci_le_connect(struct hci_conn *conn)
+{
+       struct hci_dev *hdev = conn->hdev;
+       struct hci_cp_le_create_conn cp;
+
+       conn->state = BT_CONNECT;
+       conn->out = 1;
+       conn->link_mode |= HCI_LM_MASTER;
+
+       memset(&cp, 0, sizeof(cp));
+       cp.scan_interval = cpu_to_le16(0x0004);
+       cp.scan_window = cpu_to_le16(0x0004);
+       bacpy(&cp.peer_addr, &conn->dst);
+       cp.conn_interval_min = cpu_to_le16(0x0008);
+       cp.conn_interval_max = cpu_to_le16(0x0100);
+       cp.supervision_timeout = cpu_to_le16(0x0064);
+       cp.min_ce_len = cpu_to_le16(0x0001);
+       cp.max_ce_len = cpu_to_le16(0x0001);
+
+       hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
+}
+
+static void hci_le_connect_cancel(struct hci_conn *conn)
+{
+       hci_send_cmd(conn->hdev, HCI_OP_LE_CREATE_CONN_CANCEL, 0, NULL);
+}
+
 void hci_acl_connect(struct hci_conn *conn)
 {
        struct hci_dev *hdev = conn->hdev;
@@ -156,6 +183,26 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
        hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp);
 }
 
+void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
+                                       u16 latency, u16 to_multiplier)
+{
+       struct hci_cp_le_conn_update cp;
+       struct hci_dev *hdev = conn->hdev;
+
+       memset(&cp, 0, sizeof(cp));
+
+       cp.handle               = cpu_to_le16(conn->handle);
+       cp.conn_interval_min    = cpu_to_le16(min);
+       cp.conn_interval_max    = cpu_to_le16(max);
+       cp.conn_latency         = cpu_to_le16(latency);
+       cp.supervision_timeout  = cpu_to_le16(to_multiplier);
+       cp.min_ce_len           = cpu_to_le16(0x0001);
+       cp.max_ce_len           = cpu_to_le16(0x0001);
+
+       hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp);
+}
+EXPORT_SYMBOL(hci_le_conn_update);
+
 /* Device _must_ be locked */
 void hci_sco_setup(struct hci_conn *conn, __u8 status)
 {
@@ -193,8 +240,12 @@ static void hci_conn_timeout(unsigned long arg)
        switch (conn->state) {
        case BT_CONNECT:
        case BT_CONNECT2:
-               if (conn->type == ACL_LINK && conn->out)
-                       hci_acl_connect_cancel(conn);
+               if (conn->out) {
+                       if (conn->type == ACL_LINK)
+                               hci_acl_connect_cancel(conn);
+                       else if (conn->type == LE_LINK)
+                               hci_le_connect_cancel(conn);
+               }
                break;
        case BT_CONFIG:
        case BT_CONNECTED:
@@ -234,6 +285,8 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
        conn->mode  = HCI_CM_ACTIVE;
        conn->state = BT_OPEN;
        conn->auth_type = HCI_AT_GENERAL_BONDING;
+       conn->io_capability = hdev->io_capability;
+       conn->remote_auth = 0xff;
 
        conn->power_save = 1;
        conn->disc_timeout = HCI_DISCONN_TIMEOUT;
@@ -295,6 +348,11 @@ int hci_conn_del(struct hci_conn *conn)
 
                /* Unacked frames */
                hdev->acl_cnt += conn->sent;
+       } else if (conn->type == LE_LINK) {
+               if (hdev->le_pkts)
+                       hdev->le_cnt += conn->sent;
+               else
+                       hdev->acl_cnt += conn->sent;
        } else {
                struct hci_conn *acl = conn->link;
                if (acl) {
@@ -360,15 +418,31 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
 }
 EXPORT_SYMBOL(hci_get_route);
 
-/* Create SCO or ACL connection.
+/* Create SCO, ACL or LE connection.
  * Device _must_ be locked */
 struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type)
 {
        struct hci_conn *acl;
        struct hci_conn *sco;
+       struct hci_conn *le;
 
        BT_DBG("%s dst %s", hdev->name, batostr(dst));
 
+       if (type == LE_LINK) {
+               le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
+               if (le)
+                       return ERR_PTR(-EBUSY);
+               le = hci_conn_add(hdev, LE_LINK, dst);
+               if (!le)
+                       return ERR_PTR(-ENOMEM);
+               if (le->state == BT_OPEN)
+                       hci_le_connect(le);
+
+               hci_conn_hold(le);
+
+               return le;
+       }
+
        acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
        if (!acl) {
                acl = hci_conn_add(hdev, ACL_LINK, dst);