Bluetooth: Add tracking of local and piconet clock values
authorJohan Hedberg <johan.hedberg@intel.com>
Sat, 28 Jun 2014 14:54:06 +0000 (17:54 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 3 Jul 2014 15:42:48 +0000 (17:42 +0200)
This patch adds support for storing the local and piconet clock values
from the HCI_Read_Clock command response to the hci_dev and hci_conn
structs. This will be later used in another patch to implement support
for the Get Clock Info mgmt command.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci.h
include/net/bluetooth/hci_core.h
net/bluetooth/hci_event.c

index 6933766e72157001ecddd97fd5cc4e072930ba9c..58c5930dea603987958406739776529bb73a769f 100644 (file)
@@ -1087,6 +1087,18 @@ struct hci_rp_read_rssi {
        __s8     rssi;
 } __packed;
 
+#define HCI_OP_READ_CLOCK              0x1407
+struct hci_cp_read_clock {
+       __le16   handle;
+       __u8     which;
+} __packed;
+struct hci_rp_read_clock {
+       __u8     status;
+       __le16   handle;
+       __le32   clock;
+       __le16   accuracy;
+} __packed;
+
 #define HCI_OP_READ_LOCAL_AMP_INFO     0x1409
 struct hci_rp_read_local_amp_info {
        __u8     status;
index ca2a99807615f8151d95237e79a4040c2f67e109..0906990dedd8e08476d965c3fa7739bb0ccf0d09 100644 (file)
@@ -207,6 +207,7 @@ struct hci_dev {
        __u16           conn_info_min_age;
        __u16           conn_info_max_age;
        __u8            ssp_debug_mode;
+       __u32           clock;
 
        __u16           devid_source;
        __u16           devid_vendor;
@@ -388,6 +389,9 @@ struct hci_conn {
        __s8            max_tx_power;
        unsigned long   flags;
 
+       __u32           clock;
+       __u16           clock_accuracy;
+
        unsigned long   conn_info_timestamp;
 
        __u8            remote_cap;
index 7a23324eac39acb64c17e1a1c49621a5235ce1b3..315d615ca3f9527f82dc476f028a849f341e0bbe 100644 (file)
@@ -721,6 +721,41 @@ static void hci_cc_read_data_block_size(struct hci_dev *hdev,
               hdev->block_cnt, hdev->block_len);
 }
 
+static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb)
+{
+       struct hci_rp_read_clock *rp = (void *) skb->data;
+       struct hci_cp_read_clock *cp;
+       struct hci_conn *conn;
+
+       BT_DBG("%s", hdev->name);
+
+       if (skb->len < sizeof(*rp))
+               return;
+
+       if (rp->status)
+               return;
+
+       hci_dev_lock(hdev);
+
+       cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
+       if (!cp)
+               goto unlock;
+
+       if (cp->which == 0x00) {
+               hdev->clock = le32_to_cpu(rp->clock);
+               goto unlock;
+       }
+
+       conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
+       if (conn) {
+               conn->clock = le32_to_cpu(rp->clock);
+               conn->clock_accuracy = le16_to_cpu(rp->accuracy);
+       }
+
+unlock:
+       hci_dev_unlock(hdev);
+}
+
 static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
                                       struct sk_buff *skb)
 {
@@ -2597,6 +2632,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
                hci_cc_read_local_amp_info(hdev, skb);
                break;
 
+       case HCI_OP_READ_CLOCK:
+               hci_cc_read_clock(hdev, skb);
+               break;
+
        case HCI_OP_READ_LOCAL_AMP_ASSOC:
                hci_cc_read_local_amp_assoc(hdev, skb);
                break;