Linux bluetooth development
 help / color / mirror / Atom feed
From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 06/15] Bluetooth: Add skeleton for Set Privacy command
Date: Sat, 22 Feb 2014 19:06:36 +0200	[thread overview]
Message-ID: <1393088805-28658-7-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1393088805-28658-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds the basic skeleton for handing the Set Privacy mgmt
command, including copying the value to hdev->irk and toggling the
HCI_PRIVACY flag. The patch does not yet add any kind of RPA generation
and HCI command sending.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 301b18a1c6a0..145254f84975 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -81,6 +81,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_SET_SCAN_PARAMS,
 	MGMT_OP_SET_SECURE_CONN,
 	MGMT_OP_SET_DEBUG_KEYS,
+	MGMT_OP_SET_PRIVACY,
 	MGMT_OP_LOAD_IRKS,
 };
 
@@ -4187,6 +4188,45 @@ unlock:
 	return err;
 }
 
+static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data,
+		       u16 len)
+{
+	struct mgmt_cp_set_privacy *cp = cp_data;
+	bool changed;
+	int err;
+
+	BT_DBG("request for %s", hdev->name);
+
+	if (!lmp_le_capable(hdev))
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY,
+				  MGMT_STATUS_NOT_SUPPORTED);
+
+	if (cp->privacy != 0x00 && cp->privacy != 0x01)
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS,
+				  MGMT_STATUS_INVALID_PARAMS);
+
+	hci_dev_lock(hdev);
+
+	if (cp->privacy) {
+		changed = !test_and_set_bit(HCI_PRIVACY, &hdev->dev_flags);
+		memcpy(hdev->irk, cp->irk, sizeof(hdev->irk));
+	} else {
+		changed = test_and_clear_bit(HCI_PRIVACY, &hdev->dev_flags);
+		memset(hdev->irk, 0, sizeof(hdev->irk));
+	}
+
+	err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev);
+	if (err < 0)
+		goto unlock;
+
+	if (changed)
+		err = new_settings(hdev, sk);
+
+unlock:
+	hci_dev_unlock(hdev);
+	return err;
+}
+
 static bool irk_is_valid(struct mgmt_irk_info *irk)
 {
 	switch (irk->addr.type) {
@@ -4401,7 +4441,7 @@ static const struct mgmt_handler {
 	{ set_scan_params,        false, MGMT_SET_SCAN_PARAMS_SIZE },
 	{ set_secure_conn,        false, MGMT_SETTING_SIZE },
 	{ set_debug_keys,         false, MGMT_SETTING_SIZE },
-	{ },
+	{ set_privacy,            false, MGMT_SET_PRIVACY_SIZE },
 	{ load_irks,              true,  MGMT_LOAD_IRKS_SIZE },
 };
 
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-22 17:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-22 17:06 [PATCH 00/15] Bluetooth: LE Privacy support johan.hedberg
2014-02-22 17:06 ` [PATCH 01/15] Bluetooth: Add helper variables to smp_distribute_keys() johan.hedberg
2014-02-22 17:06 ` [PATCH 02/15] Bluetooth: Add initial code for distributing local IRK johan.hedberg
2014-02-22 17:06 ` [PATCH 03/15] Bluetooth: Move enable/disable_advertising higher up in mgmt.c johan.hedberg
2014-02-22 17:06 ` [PATCH 04/15] Bluetooth: Add mgmt defines for privacy johan.hedberg
2014-02-22 17:06 ` [PATCH 05/15] Bluetooth: Add Privacy lag to mgmt supported/current settings johan.hedberg
2014-02-22 17:06 ` johan.hedberg [this message]
2014-02-22 17:56   ` [PATCH 06/15] Bluetooth: Add skeleton for Set Privacy command Marcel Holtmann
2014-02-22 17:06 ` [PATCH 07/15] Bluetooth: Add SMP function for generating RPAs johan.hedberg
2014-02-22 18:00   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 08/15] Bluetooth: Don't write static address when privacy is enabled johan.hedberg
2014-02-22 18:03   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 09/15] Bluetooth: Fix hdev->own_addr_type value when privacy is set johan.hedberg
2014-02-22 18:06   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 10/15] Bluetooth: Add mechanism for updating the local RPA johan.hedberg
2014-02-22 18:10   ` Marcel Holtmann
2014-02-22 18:37     ` Johan Hedberg
2014-02-22 18:40       ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 11/15] Bluetooth: Update local RPA if necessary when connecting LE johan.hedberg
2014-02-22 18:12   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 12/15] Bluetooth: Update local RPA if necessary before enabling advertising johan.hedberg
2014-02-22 18:17   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 13/15] Bluetooth: Update local RPA if necessary before starting LE scan johan.hedberg
2014-02-22 18:13   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 14/15] Bluetooth: Add debugfs entry for RPA regeneration timeout johan.hedberg
2014-02-22 18:15   ` Marcel Holtmann
2014-02-22 17:06 ` [PATCH 15/15] Bluetooth: Add full support for updating privacy state johan.hedberg
2014-02-22 18:16   ` Marcel Holtmann
2014-02-22 18:00 ` [PATCH 00/15] Bluetooth: LE Privacy support Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393088805-28658-7-git-send-email-johan.hedberg@gmail.com \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox