Skip to contentSkip to conversation

Bluetooth: Perform Class of Device changes through hdev->req_workqueue

PATCH New Johan Hedberg 1 participant 1 message Nov 24, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 5/7 Bluetooth: Perform Class of Device changes through hdev->req_workqueue

From: Johan Hedberg <[email protected]>

The Class of Device needs to be changed e.g. for limited discoverable mode. In preparation of moving the discoverable mode to hci_request.c and hdev->req_workqueue, move the Class of Device helpers there first.

---
 net/bluetooth/hci_request.c | 40 +++++++++++++++++++++++++++++++++
 net/bluetooth/hci_request.h |  2 ++
 net/bluetooth/mgmt.c        | 54 ++++++---------------------------------------
 3 files changed, 49 insertions(+), 47 deletions(-)
net/bluetooth/hci_request.c +40 -0
index 167c90644b4b..e5e827b762b9 100644
@@ -1311,6 +1311,46 @@ static void connectable_update_work(struct work_struct *work)
 	mgmt_set_connectable_complete(hdev, status);
 }
 
+static u8 get_service_classes(struct hci_dev *hdev)
+{
+	struct bt_uuid *uuid;
+	u8 val = 0;
+
+	list_for_each_entry(uuid, &hdev->uuids, list)
+		val |= uuid->svc_hint;
+
+	return val;
+}
+
+void __hci_req_update_class(struct hci_request *req)
+{
+	struct hci_dev *hdev = req->hdev;
+	u8 cod[3];
+
+	BT_DBG("%s", hdev->name);
+
+	if (!hdev_is_powered(hdev))
+		return;
+
+	if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
+		return;
+
+	if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE))
+		return;
+
+	cod[0] = hdev->minor_class;
+	cod[1] = hdev->major_class;
+	cod[2] = get_service_classes(hdev);
+
+	if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE))
+		cod[1] |= 0x20;
+
+	if (memcmp(cod, hdev->dev_class, 3) == 0)
+		return;
+
+	hci_req_add(req, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
+}
+
 void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
 		      u8 reason)
 {
net/bluetooth/hci_request.h +2 -0
index 5358b1b12ca0..41920348d68b 100644
@@ -72,6 +72,8 @@ int __hci_req_schedule_adv_instance(struct hci_request *req, u8 instance,
 void hci_req_clear_adv_instance(struct hci_dev *hdev, struct hci_request *req,
 				u8 instance, bool force);
 
+void __hci_req_update_class(struct hci_request *req);
+
 /* Returns true if HCI commands were queued */
 bool hci_req_stop_discovery(struct hci_request *req);
 
net/bluetooth/mgmt.c +7 -47

102 lines not on this page · raw message

Signature · 1 line
2.5.0