Skip to contentSkip to conversation

Bluetooth: Handle command complete event for HCI Read Stored Link Keys

PATCH Superseded Marcel Holtmann 2 participants 3 messages Jan 11, 2015 – Jan 12, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 2/5 Bluetooth: Handle command complete event for HCI Read Stored Link Keys

When the HCI Read Stored Link Keys command completes it gives useful information of the current stored keys and maximum keys a controller can actually store. So process this event and store these information in hci_dev structure.

---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_event.c        | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/net/bluetooth/hci_core.h +2 -0
index 89f4e3c8a097..1f21fe48b38e 100644
@@ -205,6 +205,8 @@ struct hci_dev {
 	__u16		lmp_subver;
 	__u16		voice_setting;
 	__u8		num_iac;
+	__u8		stored_max_keys;
+	__u8		stored_num_keys;
 	__u8		io_capability;
 	__s8		inq_tx_power;
 	__u16		page_scan_interval;
net/bluetooth/hci_event.c +22 -0
index 0881efd0ad2d..09dde59ddeec 100644
@@ -214,6 +214,24 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_bdaddr_list_clear(&hdev->le_white_list);
 }
 
+static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
+					struct sk_buff *skb)
+{
+	struct hci_rp_read_stored_link_key *rp = (void *)skb->data;
+	struct hci_cp_read_stored_link_key *sent;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+	sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
+	if (!sent)
+		return;
+
+	if (!rp->status && !bacmp(&sent->bdaddr, BDADDR_ANY)) {
+		hdev->stored_max_keys = rp->max_keys;
+		hdev->stored_num_keys = rp->num_keys;
+	}
+}
+
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	__u8 status = *((__u8 *) skb->data);
@@ -2714,6 +2732,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cc_reset(hdev, skb);
 		break;
 
+	case HCI_OP_READ_STORED_LINK_KEY:
+		hci_cc_read_stored_link_key(hdev, skb);
+		break;
+
 	case HCI_OP_WRITE_LOCAL_NAME:
 		hci_cc_write_local_name(hdev, skb);
 		break;
Signature · 1 line
2.1.0
#1 lore raw

Hi Marcel,

Quoted 6 lines · Marcel Holtmann
net/bluetooth/hci_event.c +6 -0
+static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
+					struct sk_buff *skb)
+{
+	struct hci_rp_read_stored_link_key *rp = (void *)skb->data;
+	struct hci_cp_read_stored_link_key *sent;
+

net/bluetooth/hci_event.c static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) · line 232

Quoted 10 lines
net/bluetooth/hci_event.c +10 -0
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+	sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
+	if (!sent)
+		return;
+
+	if (!rp->status && !bacmp(&sent->bdaddr, BDADDR_ANY)) {
+		hdev->stored_max_keys = rp->max_keys;
+		hdev->stored_num_keys = rp->num_keys;
+	}

This probably works fine, but strictly speaking I think you should be looking at the sent->read_all flag as that's the explicit indication that the all keys had been requested. In theory the sent->bdaddr value may be anything for read_all = 0x01 as the spec says that the bdaddr is simply ignored then.

Johan

author maintainer
#2 lore raw

Hi Johan,

Quoted 14 lines
Quoted 14 lines
net/bluetooth/hci_event.c +14 -0
+static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
+					struct sk_buff *skb)
+{
+	struct hci_rp_read_stored_link_key *rp = (void *)skb->data;
+	struct hci_cp_read_stored_link_key *sent;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+	sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
+	if (!sent)
+		return;
+
+	if (!rp->status && !bacmp(&sent->bdaddr, BDADDR_ANY)) {
+		hdev->stored_max_keys = rp->max_keys;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		hdev->stored_num_keys = rp->num_keys;
+	}

This probably works fine, but strictly speaking I think you should be looking at the sent->read_all flag as that's the explicit indication that the all keys had been requested. In theory the sent->bdaddr value may be anything for read_all = 0x01 as the spec says that the bdaddr is simply ignored then.

good catch actually. I will fix that.

Regards

Marcel