Bluetooth: Store TX power level for connection
authorAndrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Fri, 9 May 2014 19:35:28 +0000 (21:35 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 9 May 2014 21:16:42 +0000 (14:16 -0700)
This patch adds support to store local TX power level for connection
when reply for HCI_Read_Transmit_Power_Level is received.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci.h
include/net/bluetooth/hci_core.h
net/bluetooth/hci_conn.c
net/bluetooth/hci_event.c

index ad2ecc92380ddfe461512d5730ee2bd7a2729338..16587dcd6a9181b74814f1a4d0865332aa1bd81d 100644 (file)
@@ -1054,6 +1054,17 @@ struct hci_cp_write_page_scan_activity {
        __le16   window;
 } __packed;
 
+#define HCI_OP_READ_TX_POWER           0x0c2d
+struct hci_cp_read_tx_power {
+       __le16   handle;
+       __u8     type;
+} __packed;
+struct hci_rp_read_tx_power {
+       __u8     status;
+       __le16   handle;
+       __s8     tx_power;
+} __packed;
+
 #define HCI_OP_READ_PAGE_SCAN_TYPE     0x0c46
 struct hci_rp_read_page_scan_type {
        __u8     status;
index 0318d5263837ccba3655fdc7df15d5fc90e72e97..211bad6a3366178b1dac83d738dba83b05ebd58c 100644 (file)
@@ -375,6 +375,7 @@ struct hci_conn {
        __u16           le_conn_min_interval;
        __u16           le_conn_max_interval;
        __s8            rssi;
+       __s8            tx_power;
        unsigned long   flags;
 
        __u8            remote_cap;
index 55a174317925949e0f00cc266112ecf6338b5158..74b368bfe1029b1924bbae6867383c6563b0e19b 100644 (file)
@@ -407,6 +407,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
        conn->io_capability = hdev->io_capability;
        conn->remote_auth = 0xff;
        conn->key_type = 0xff;
+       conn->tx_power = HCI_TX_POWER_INVALID;
 
        set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
        conn->disc_timeout = HCI_DISCONN_TIMEOUT;
index 2bb0053d4c458536d889ab3259c0a3c3c584a063..fa614e3430a73329b83edc61ebc8490f8f6d1324 100644 (file)
@@ -1264,6 +1264,30 @@ static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
        hci_dev_unlock(hdev);
 }
 
+static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
+{
+       struct hci_cp_read_tx_power *sent;
+       struct hci_rp_read_tx_power *rp = (void *) skb->data;
+       struct hci_conn *conn;
+
+       BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+       if (rp->status)
+               return;
+
+       sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
+       if (!sent)
+               return;
+
+       hci_dev_lock(hdev);
+
+       conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
+       if (conn && sent->type == 0x00)
+               conn->tx_power = rp->tx_power;
+
+       hci_dev_unlock(hdev);
+}
+
 static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
 {
        BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -2660,6 +2684,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
                hci_cc_read_rssi(hdev, skb);
                break;
 
+       case HCI_OP_READ_TX_POWER:
+               hci_cc_read_tx_power(hdev, skb);
+               break;
+
        default:
                BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
                break;