Linux bluetooth development
 help / color / mirror / Atom feed
* Re: BLE Peripheral on Ubuntu
From: Anderson Lizardo @ 2014-01-30 23:53 UTC (permalink / raw)
  To: Prashant R; +Cc: BlueZ development
In-Reply-To: <CAD-ALXKinmbiAaH3FMA-b4byXo0CMEm1H0Dfc=bCDBwONqsfTA@mail.gmail.com>

Hi,

On Thu, Jan 30, 2014 at 6:01 PM, Prashant R <ramapra@gmail.com> wrote:
> My goal is to be able to use a USB-BT adapter and make it behave like
> a BLE peripheral.
>
> So far I have been able to do LE advertising on it but would want to
> add GATT services for this device.
> I am unable to find documentation on how to control this as a BLE
> Peripheral.Can someone point me to this?

We are currently in the process of submitting patches upstream that
will allow applications to register GATT services using a D-Bus API.

> - Is there currently a tool (opposite of  gatttool) that I can use to
> publish services and characteristics ?

Once the API is upstream, you will be able to register your own
services using D-Bus. There will be example C code demonstrating the
API, and documentation in doc/gatt-api.txt.

> - My version of bluez is4.98-2ubuntu7 . I tried to upgrade to the
> latest but it complains about D-BUS version being <Ver 1.6. My version
> of DBUS  is  1.4.18
> My question is if the GATT server support is present at the user level
> using my version of 4.98-2ubuntu7?

Unfortunately, you will need to use a more recent BlueZ in order to
use the future API. You can build your own D-Bus library and BlueZ
from sources (make sure to install in a separate place , e.g.
/opt/bluez, instead of overwriting any files in /usr).

Current status of the upstreaming process:

- The internal C API for GATT service registration, as well as the
attribute database format, was rewritten. Therefore we need to migrate
existing internal profiles to this new API.

- We sent patches for GATT Service and Characteristic registration.
These initial patches do not export the services over the LE channel
yet (they are only available using a local UNIX socket). This
intermediary step is necessary in order to not break current supported
profiles.

- We will be able to export the services on the LE and BR/EDR channels
once the internal profiles are migrated to the new C API. I'm
currently working on this step.

Summary: the latest BlueZ does not support external GATT services yet,
but we hope to have basic support upstream (with an experimental API)
very soon.

Best Regards,
-- 
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil

^ permalink raw reply

* Re: [PATCH] Bluetooth: Remove Simultaneous LE & BR/EDR flags from AD
From: Marcel Holtmann @ 2014-01-31  3:12 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <1391109410-8595-1-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

> Starting with the 4.1 Core Specification these flags are no longer used
> and should always be cleared. From volume 3, part C, section 13.1.1:
> 
> "The 'Simultaneous LE and BR/EDR to Same Device Capable (Controller)'
> and ‘Simultaneous LE and BR/EDR to Same Device Capable (Host)’ bits in
> the Flags AD type shall be set to ‘0’."
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/mgmt.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* [PATCH 0/4] Bluetooth: SMP LTK fixes
From: johan.hedberg @ 2014-01-31  3:39 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

Now that my LTK key distribution patch is already applied I
unfortunately uncovered several bugs due to it. The main issue is that
the kernel code was not accounting for the possibility of there being
two LTKs for the same remote device in the hdev->long_term_keys list.

There are still fixes needed on the user space side which I haven't
completely sorted out yet (to pushable form - it's more or less working
already through). Right now the storage format doesn't allow storing two
LTKs for the same device.

----------------------------------------------------------------
Johan Hedberg (4):
      Bluetooth: Fix long_term_keys debugfs output
      Bluetooth: Make LTK key type check more readable
      Bluetooth: Remove unnecessary LTK type check from hci_add_ltk
      Bluetooth: Fix differentiating stored master vs slave LTK types

 include/net/bluetooth/hci_core.h |  5 +++--
 net/bluetooth/hci_core.c         | 31 +++++++++++++++++++++----------
 net/bluetooth/hci_event.c        |  2 +-
 net/bluetooth/smp.c              |  3 ++-
 4 files changed, 27 insertions(+), 14 deletions(-)


^ permalink raw reply

* [PATCH 1/4] Bluetooth: Fix long_term_keys debugfs output
From: johan.hedberg @ 2014-01-31  3:39 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391139600-15366-1-git-send-email-johan.hedberg@gmail.com>

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

The code was previously iterating the wrong list (and what's worse
casting entries to a type which they were not) and also missing a proper
line terminator when printing each entry. The code now also prints the
LTK type in hex for easier comparison with the kernel-defined values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 369d30750417..8094a41c9a26 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -620,9 +620,9 @@ static int long_term_keys_show(struct seq_file *f, void *ptr)
 	struct list_head *p, *n;
 
 	hci_dev_lock(hdev);
-	list_for_each_safe(p, n, &hdev->link_keys) {
+	list_for_each_safe(p, n, &hdev->long_term_keys) {
 		struct smp_ltk *ltk = list_entry(p, struct smp_ltk, list);
-		seq_printf(f, "%pMR (type %u) %u %u %u %.4x %*phN %*phN\\n",
+		seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %*phN %*phN\n",
 			   &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated,
 			   ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
 			   8, ltk->rand, 16, ltk->val);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 2/4] Bluetooth: Make LTK key type check more readable
From: johan.hedberg @ 2014-01-31  3:39 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391139600-15366-1-git-send-email-johan.hedberg@gmail.com>

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

Instead of magic bitwise operations simply compare with the two possible
type values that we are interested in.

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

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 8094a41c9a26..754a59079de9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2717,7 +2717,7 @@ int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
 	if (!new_key)
 		return 0;
 
-	if (type & HCI_SMP_LTK)
+	if (type == HCI_SMP_LTK || type == HCI_SMP_LTK_SLAVE)
 		mgmt_new_ltk(hdev, key, 1);
 
 	return 0;
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 3/4] Bluetooth: Remove unnecessary LTK type check from hci_add_ltk
From: johan.hedberg @ 2014-01-31  3:39 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391139600-15366-1-git-send-email-johan.hedberg@gmail.com>

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

All callers of hci_add_ltk pass a valid value to it. There are no places
where e.g. user space, the controller or the remote peer would be able
to cause invalid values to be passed. Therefore, just remove the
potentially confusing check from the beginning of the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_core.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 754a59079de9..180473d965f6 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2692,9 +2692,6 @@ int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
 {
 	struct smp_ltk *key, *old_key;
 
-	if (!(type & HCI_SMP_STK) && !(type & HCI_SMP_LTK))
-		return 0;
-
 	old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type);
 	if (old_key)
 		key = old_key;
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 4/4] Bluetooth: Fix differentiating stored master vs slave LTK types
From: johan.hedberg @ 2014-01-31  3:40 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391139600-15366-1-git-send-email-johan.hedberg@gmail.com>

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

If LTK distribution happens in both directions we will have two LTKs for
the same remote device: one which is used when we're connecting as
master and another when we're connecting as slave. When looking up LTKs
from the locally stored list we shouldn't blindly return the first match
but also consider which type of key is in question. If we do not do this
we may end up selecting an incorrect encryption key for a connection.

This patch fixes the issue by always specifying to the LTK lookup
functions whether we're looking for a master or a slave key.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  5 +++--
 net/bluetooth/hci_core.c         | 22 ++++++++++++++++++----
 net/bluetooth/hci_event.c        |  2 +-
 net/bluetooth/smp.c              |  3 ++-
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8d225e4ea2ce..378e2f32cfa0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -757,12 +757,13 @@ int hci_link_keys_clear(struct hci_dev *hdev);
 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
 		     bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
-struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
+struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8],
+			     bool master);
 int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
 		int new_key, u8 authenticated, u8 tk[16], u8 enc_size,
 		__le16 ediv, u8 rand[8]);
 struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
-				     u8 addr_type);
+				     u8 addr_type, bool master);
 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_smp_ltks_clear(struct hci_dev *hdev);
 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 180473d965f6..d370b432aea6 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2605,7 +2605,16 @@ static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
 	return false;
 }
 
-struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
+static bool ltk_type_master(u8 type)
+{
+	if (type == HCI_SMP_STK || type == HCI_SMP_LTK)
+		return true;
+
+	return false;
+}
+
+struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8],
+			     bool master)
 {
 	struct smp_ltk *k;
 
@@ -2614,6 +2623,9 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
 		    memcmp(rand, k->rand, sizeof(k->rand)))
 			continue;
 
+		if (ltk_type_master(k->type) != master)
+			continue;
+
 		return k;
 	}
 
@@ -2621,13 +2633,14 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
 }
 
 struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
-				     u8 addr_type)
+				     u8 addr_type, bool master)
 {
 	struct smp_ltk *k;
 
 	list_for_each_entry(k, &hdev->long_term_keys, list)
 		if (addr_type == k->bdaddr_type &&
-		    bacmp(bdaddr, &k->bdaddr) == 0)
+		    bacmp(bdaddr, &k->bdaddr) == 0 &&
+		    ltk_type_master(k->type) == master)
 			return k;
 
 	return NULL;
@@ -2691,8 +2704,9 @@ int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
 		ediv, u8 rand[8])
 {
 	struct smp_ltk *key, *old_key;
+	bool master = ltk_type_master(type);
 
-	old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type);
+	old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type, master);
 	if (old_key)
 		key = old_key;
 	else {
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8c44bbe19add..7bb8094a3ff2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3650,7 +3650,7 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	if (conn == NULL)
 		goto not_found;
 
-	ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
+	ltk = hci_find_ltk(hdev, ev->ediv, ev->random, conn->out);
 	if (ltk == NULL)
 		goto not_found;
 
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 9b1167007653..efe51ccdc615 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -699,7 +699,8 @@ static u8 smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
 	struct smp_ltk *key;
 	struct hci_conn *hcon = conn->hcon;
 
-	key = hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type);
+	key = hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type,
+				   hcon->out);
 	if (!key)
 		return 0;
 
-- 
1.8.5.3


^ permalink raw reply related

* Re: [PATCH 0/4] Bluetooth: SMP LTK fixes
From: Marcel Holtmann @ 2014-01-31  3:51 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: BlueZ development
In-Reply-To: <1391139600-15366-1-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

> Now that my LTK key distribution patch is already applied I
> unfortunately uncovered several bugs due to it. The main issue is that
> the kernel code was not accounting for the possibility of there being
> two LTKs for the same remote device in the hdev->long_term_keys list.
> 
> There are still fixes needed on the user space side which I haven't
> completely sorted out yet (to pushable form - it's more or less working
> already through). Right now the storage format doesn't allow storing two
> LTKs for the same device.
> 
> ----------------------------------------------------------------
> Johan Hedberg (4):
>      Bluetooth: Fix long_term_keys debugfs output
>      Bluetooth: Make LTK key type check more readable
>      Bluetooth: Remove unnecessary LTK type check from hci_add_ltk
>      Bluetooth: Fix differentiating stored master vs slave LTK types
> 
> include/net/bluetooth/hci_core.h |  5 +++--
> net/bluetooth/hci_core.c         | 31 +++++++++++++++++++++----------
> net/bluetooth/hci_event.c        |  2 +-
> net/bluetooth/smp.c              |  3 ++-
> 4 files changed, 27 insertions(+), 14 deletions(-)

all 4 patches have been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* Re: [PATCH BlueZ 4/4] audio/AVRCP: Fix coding style
From: Andrei Emeltchenko @ 2014-01-31  7:55 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1391123008-26767-4-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Thu, Jan 30, 2014 at 03:03:28PM -0800, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> ---
>  profiles/audio/avrcp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
> index ac861d2..4521bc4 100644
> --- a/profiles/audio/avrcp.c
> +++ b/profiles/audio/avrcp.c
> @@ -2161,7 +2161,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
>  		name[namelen] = '\0';
>  	}
>  
> -	item =  media_player_create_folder(mp, name, type, uid);
> +	item = media_player_create_folder(mp, name, type, uid);

what is the point creating this patch instead of merging with previous one
which introduced this style issue?

Best regards 
Andrei Emeltchenko 

>  	if (!item)
>  		return NULL;
>  
> -- 
> 1.8.4.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* [PATCH] avrcp: Fix wrong pointer check
From: Andrei Emeltchenko @ 2014-01-31  8:33 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

There is wrong assumption that handler might be NULL while it is a
pointer to a struct table so check instead for struct members. This
fixes accessing wrong memory.
---
 profiles/audio/avrcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index df88138..5030ce1 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1673,7 +1673,7 @@ static size_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
 			break;
 	}
 
-	if (!handler || handler->code != *code) {
+	if (!handler->code || handler->code != *code) {
 		pdu->params[0] = AVRCP_STATUS_INVALID_COMMAND;
 		goto err_metadata;
 	}
@@ -1737,7 +1737,7 @@ static size_t handle_browsing_pdu(struct avctp *conn,
 			break;
 	}
 
-	if (handler == NULL || handler->func == NULL)
+	if (!handler->func)
 		return avrcp_browsing_general_reject(operands);
 
 	session->transaction = transaction;
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH] android: Add avtest to debug builds
From: Sebastian Chlad @ 2014-01-31  9:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sebastian Chlad
In-Reply-To: <1390999219-15012-1-git-send-email-sebastianx.chlad@intel.com>

---
 android/Android.mk | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/android/Android.mk b/android/Android.mk
index 1d12da5..09ed32d 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -354,6 +354,28 @@ LOCAL_MODULE := l2ping
 include $(BUILD_EXECUTABLE)
 
 #
+# avtest
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+        bluez/tools/avtest.c \
+        bluez/lib/bluetooth.c \
+        bluez/lib/hci.c \
+
+LOCAL_C_INCLUDES := \
+        $(LOCAL_PATH)/bluez/lib \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := debug
+LOCAL_MODULE := avtest
+
+include $(BUILD_EXECUTABLE)
+
+#
 # libsbc
 #
 
-- 
1.8.3.2

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related

* [PATCH 1/2] avrcp: Fix printing incorrect order for avrcp control header
From: Andrei Emeltchenko @ 2014-01-31 12:36 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 profiles/audio/avrcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 5030ce1..bc5cab3 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1658,7 +1658,7 @@ static size_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
 	}
 
 	DBG("AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
-			pdu->pdu_id, company_id, pdu->params_len);
+			pdu->pdu_id, company_id, ntohs(pdu->params_len));
 
 	pdu->packet_type = 0;
 	pdu->rsvd = 0;
@@ -1755,7 +1755,7 @@ size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
 	pdu->params[0] = AVRCP_STATUS_INTERNAL_ERROR;
 
 	DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
-				pdu->pdu_id, company_id, pdu->params_len);
+			pdu->pdu_id, company_id, ntohs(pdu->params_len));
 
 	return AVRCP_HEADER_LENGTH + 1;
 }
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 2/2] avrcp: Fix printing order for browsing avrcp header
From: Andrei Emeltchenko @ 2014-01-31 12:36 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391171777-27512-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 profiles/audio/avrcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index bc5cab3..4ece4af 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1730,7 +1730,7 @@ static size_t handle_browsing_pdu(struct avctp *conn,
 	struct avrcp_browsing_header *pdu = (void *) operands;
 
 	DBG("AVRCP Browsing PDU 0x%02X, len 0x%04X", pdu->pdu_id,
-							pdu->param_len);
+							ntohs(pdu->param_len));
 
 	for (handler = browsing_handlers; handler->pdu_id; handler++) {
 		if (handler->pdu_id == pdu->pdu_id)
-- 
1.8.3.2


^ permalink raw reply related

* Re: [PATCH] android: Add avtest to debug builds
From: Szymon Janc @ 2014-01-31 13:43 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1391160672-9088-1-git-send-email-sebastianx.chlad@intel.com>

Hi Sebastian,

On Friday 31 of January 2014 11:31:12 Sebastian Chlad wrote:
> ---
>  android/Android.mk | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/android/Android.mk b/android/Android.mk
> index 1d12da5..09ed32d 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -354,6 +354,28 @@ LOCAL_MODULE := l2ping
>  include $(BUILD_EXECUTABLE)
> 
>  #
> +# avtest
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> +        bluez/tools/avtest.c \
> +        bluez/lib/bluetooth.c \
> +        bluez/lib/hci.c \
> +
> +LOCAL_C_INCLUDES := \
> +        $(LOCAL_PATH)/bluez/lib \
> +
> +LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
> +
> +LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
> +LOCAL_MODULE_TAGS := debug
> +LOCAL_MODULE := avtest
> +
> +include $(BUILD_EXECUTABLE)
> +
> +#
>  # libsbc
>  #

Applied, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply

* Re: [PATCH] android/pts: Add Android version to PTS tests
From: Szymon Janc @ 2014-01-31 13:44 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1391186602-18769-1-git-send-email-sebastianchlad@gmail.com>

Hi Sebastian,

On Friday 31 of January 2014 18:43:22 Sebastian Chlad wrote:
> This trivial patch adds Android version to the PTS test results.
> It helps tracking tests status.
> ---
>  android/pts-a2dp.txt  | 1 +
>  android/pts-avctp.txt | 1 +
>  android/pts-avrcp.txt | 1 +
>  android/pts-did.txt   | 1 +
>  android/pts-gap.txt   | 1 +
>  android/pts-l2cap.txt | 1 +
>  android/pts-opp.txt   | 1 +
>  android/pts-pbap.txt  | 1 +
>  8 files changed, 8 insertions(+)
> 
> diff --git a/android/pts-a2dp.txt b/android/pts-a2dp.txt
> index 3d1085e..301b1e7 100644
> --- a/android/pts-a2dp.txt
> +++ b/android/pts-a2dp.txt
> @@ -2,6 +2,7 @@ PTS test results for A2DP
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-avctp.txt b/android/pts-avctp.txt
> index a57ecee..4090ec0 100644
> --- a/android/pts-avctp.txt
> +++ b/android/pts-avctp.txt
> @@ -2,6 +2,7 @@ PTS test results for AVCTP
> 
>  PTS version: 5.0
>  Tested: 29.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-avrcp.txt b/android/pts-avrcp.txt
> index 454e26c..8bd0b4d 100644
> --- a/android/pts-avrcp.txt
> +++ b/android/pts-avrcp.txt
> @@ -2,6 +2,7 @@ PTS test results for AVRCP
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-did.txt b/android/pts-did.txt
> index d764f09..841b257 100644
> --- a/android/pts-did.txt
> +++ b/android/pts-did.txt
> @@ -2,6 +2,7 @@ PTS test results for DID
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-gap.txt b/android/pts-gap.txt
> index 1c0feec..7c88f1f 100644
> --- a/android/pts-gap.txt
> +++ b/android/pts-gap.txt
> @@ -2,6 +2,7 @@ PTS test results for GAP
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-l2cap.txt b/android/pts-l2cap.txt
> index 3e46309..f04c3e5 100644
> --- a/android/pts-l2cap.txt
> +++ b/android/pts-l2cap.txt
> @@ -2,6 +2,7 @@ PTS test results for L2CAP
> 
>  PTS version: 5.0
>  Tested: 29.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS   test passed
> diff --git a/android/pts-opp.txt b/android/pts-opp.txt
> index 3c4ab47..d5dfcf0 100644
> --- a/android/pts-opp.txt
> +++ b/android/pts-opp.txt
> @@ -2,6 +2,7 @@ PTS test results for OPP
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed
> diff --git a/android/pts-pbap.txt b/android/pts-pbap.txt
> index 4312921..41442c6 100644
> --- a/android/pts-pbap.txt
> +++ b/android/pts-pbap.txt
> @@ -2,6 +2,7 @@ PTS test results for PBAP
> 
>  PTS version: 5.0
>  Tested: 28.01.2014
> +Android version: 4.4.2
> 
>  Results:
>  PASS	test passed

Applied, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply

* Re: [PATCH] android/pts: Correct typo
From: Szymon Janc @ 2014-01-31 13:44 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1391186806-18925-1-git-send-email-sebastianchlad@gmail.com>

Hi Sebastian,

On Friday 31 of January 2014 18:46:46 Sebastian Chlad wrote:
> ---
>  android/pts-hid.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/android/pts-hid.txt b/android/pts-hid.txt
> index 7e9f986..c29c9dc 100644
> --- a/android/pts-hid.txt
> +++ b/android/pts-hid.txt
> @@ -1,4 +1,4 @@
> -PTS test results for DID
> +PTS test results for HID
> 
>  PTS version: 4.9
>  Tested: 14.11.2013

Pushed, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply

* [PATCH 1/4] android/hal-audio: Check calloc return value
From: Andrei Emeltchenko @ 2014-01-31 14:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

calloc() might return NULL and is usually checked for NULL in BlueZ.
---
 android/hal-audio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index b1323b0..35bafe7 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -313,6 +313,8 @@ static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
 	}
 
 	sbc_data = calloc(sizeof(struct sbc_data), 1);
+	if (!sbc_data)
+		return AUDIO_STATUS_FAILED;
 
 	memcpy(&sbc_data->sbc, preset->data, preset->len);
 
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 2/4] android/hal-audio: Do not allocate memory if fd < 0
From: Andrei Emeltchenko @ 2014-01-31 14:18 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391177929-31416-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Fixes memory leak when returning bad fd we still allocate memory which
is not freed in the caller function audio_open_output_stream().
---
 android/hal-audio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 35bafe7..4b80da8 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -713,8 +713,7 @@ static int ipc_open_stream_cmd(uint8_t endpoint_id, uint16_t *mtu, int *fd,
 
 	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
 				sizeof(cmd), &cmd, &rsp_len, rsp, fd);
-
-	if (result == AUDIO_STATUS_SUCCESS) {
+	if (result == AUDIO_STATUS_SUCCESS && *fd >= 0) {
 		size_t buf_len = sizeof(struct audio_preset) +
 					rsp->preset[0].len;
 		*mtu = rsp->mtu;
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 3/4] android/hal-audio: Fix memory leak
From: Andrei Emeltchenko @ 2014-01-31 14:18 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391177929-31416-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Free preset if set_blocking() fails.
---
 android/hal-audio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 4b80da8..dfe8b68 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -1176,8 +1176,10 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
 	if (!preset || fd < 0)
 		goto fail;
 
-	if (set_blocking(fd) < 0)
+	if (set_blocking(fd) < 0) {
+		free(preset);
 		goto fail;
+	}
 
 	out->ep->fd = fd;
 	codec = out->ep->codec;
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 4/4] android/hal-audio: Fix style issues
From: Andrei Emeltchenko @ 2014-01-31 14:18 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1391177929-31416-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 android/hal-audio.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index dfe8b68..f2d072e 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -136,7 +136,7 @@ struct sbc_data {
 };
 
 static inline void timespec_diff(struct timespec *a, struct timespec *b,
-					struct timespec *res)
+							struct timespec *res)
 {
 	res->tv_sec = a->tv_sec - b->tv_sec;
 	res->tv_nsec = a->tv_nsec - b->tv_nsec;
@@ -149,14 +149,14 @@ static inline void timespec_diff(struct timespec *a, struct timespec *b,
 
 static int sbc_get_presets(struct audio_preset *preset, size_t *len);
 static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
-				void **codec_data);
+							void **codec_data);
 static int sbc_cleanup(void *codec_data);
 static int sbc_get_config(void *codec_data, struct audio_input_config *config);
 static size_t sbc_get_buffer_size(void *codec_data);
 static size_t sbc_get_mediapacket_duration(void *codec_data);
 static void sbc_resume(void *codec_data);
 static ssize_t sbc_write_data(void *codec_data, const void *buffer,
-					size_t bytes, int fd);
+							size_t bytes, int fd);
 
 struct audio_codec {
 	uint8_t type;
@@ -172,7 +172,7 @@ struct audio_codec {
 	size_t (*get_mediapacket_duration) (void *codec_data);
 	void (*resume) (void *codec_data);
 	ssize_t (*write_data) (void *codec_data, const void *buffer,
-				size_t bytes, int fd);
+							size_t bytes, int fd);
 };
 
 static const struct audio_codec audio_codecs[] = {
@@ -299,7 +299,7 @@ static void sbc_init_encoder(struct sbc_data *sbc_data)
 }
 
 static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu,
-				void **codec_data)
+							void **codec_data)
 {
 	struct sbc_data *sbc_data;
 	size_t hdr_len = sizeof(struct media_packet);
@@ -443,7 +443,7 @@ static int write_media_packet(int fd, struct sbc_data *sbc_data,
 }
 
 static ssize_t sbc_write_data(void *codec_data, const void *buffer,
-				size_t bytes, int fd)
+							size_t bytes, int fd)
 {
 	struct sbc_data *sbc_data = (struct sbc_data *) codec_data;
 	size_t consumed = 0;
@@ -695,7 +695,7 @@ static int ipc_close_cmd(uint8_t endpoint_id)
 }
 
 static int ipc_open_stream_cmd(uint8_t endpoint_id, uint16_t *mtu, int *fd,
-					struct audio_preset **caps)
+						struct audio_preset **caps)
 {
 	char buf[BLUEZ_AUDIO_MTU];
 	struct audio_cmd_open_stream cmd;
@@ -736,7 +736,7 @@ static int ipc_close_stream_cmd(uint8_t endpoint_id)
 	cmd.id = endpoint_id;
 
 	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_CLOSE_STREAM,
-				sizeof(cmd), &cmd, NULL, NULL, NULL);
+					sizeof(cmd), &cmd, NULL, NULL, NULL);
 
 	return result;
 }
@@ -751,7 +751,7 @@ static int ipc_resume_stream_cmd(uint8_t endpoint_id)
 	cmd.id = endpoint_id;
 
 	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_RESUME_STREAM,
-				sizeof(cmd), &cmd, NULL, NULL, NULL);
+					sizeof(cmd), &cmd, NULL, NULL, NULL);
 
 	return result;
 }
@@ -766,7 +766,7 @@ static int ipc_suspend_stream_cmd(uint8_t endpoint_id)
 	cmd.id = endpoint_id;
 
 	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_SUSPEND_STREAM,
-				sizeof(cmd), &cmd, NULL, NULL, NULL);
+					sizeof(cmd), &cmd, NULL, NULL, NULL);
 
 	return result;
 }
@@ -834,7 +834,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
 	}
 
 	return out->ep->codec->write_data(out->ep->codec_data, buffer,
-						bytes, out->ep->fd);
+							bytes, out->ep->fd);
 }
 
 static uint32_t out_get_sample_rate(const struct audio_stream *stream)
@@ -1170,7 +1170,7 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
 	out->ep = &audio_endpoints[0];
 
 	if (ipc_open_stream_cmd(out->ep->id, &mtu, &fd, &preset) !=
-			AUDIO_STATUS_SUCCESS)
+							AUDIO_STATUS_SUCCESS)
 		goto fail;
 
 	if (!preset || fd < 0)
@@ -1188,7 +1188,7 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
 	codec->get_config(out->ep->codec_data, &out->cfg);
 
 	DBG("rate=%d channels=%d format=%d", out->cfg.rate,
-			out->cfg.channels, out->cfg.format);
+					out->cfg.channels, out->cfg.format);
 
 	free(preset);
 
@@ -1215,7 +1215,6 @@ static void audio_close_output_stream(struct audio_hw_device *dev,
 	DBG("");
 
 	ipc_close_stream_cmd(ep->id);
-
 	if (ep->fd >= 0) {
 		close(ep->fd);
 		ep->fd = -1;
@@ -1240,7 +1239,7 @@ static int audio_set_parameters(struct audio_hw_device *dev,
 		return 0;
 
 	return out->stream.common.set_parameters((struct audio_stream *) out,
-							kvpairs);
+								kvpairs);
 }
 
 static char *audio_get_parameters(const struct audio_hw_device *dev,
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH] android/pts: Add Android version to PTS tests
From: Sebastian Chlad @ 2014-01-31 16:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sebastian Chlad

This trivial patch adds Android version to the PTS test results.
It helps tracking tests status.
---
 android/pts-a2dp.txt  | 1 +
 android/pts-avctp.txt | 1 +
 android/pts-avrcp.txt | 1 +
 android/pts-did.txt   | 1 +
 android/pts-gap.txt   | 1 +
 android/pts-l2cap.txt | 1 +
 android/pts-opp.txt   | 1 +
 android/pts-pbap.txt  | 1 +
 8 files changed, 8 insertions(+)

diff --git a/android/pts-a2dp.txt b/android/pts-a2dp.txt
index 3d1085e..301b1e7 100644
--- a/android/pts-a2dp.txt
+++ b/android/pts-a2dp.txt
@@ -2,6 +2,7 @@ PTS test results for A2DP
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-avctp.txt b/android/pts-avctp.txt
index a57ecee..4090ec0 100644
--- a/android/pts-avctp.txt
+++ b/android/pts-avctp.txt
@@ -2,6 +2,7 @@ PTS test results for AVCTP
 
 PTS version: 5.0
 Tested: 29.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-avrcp.txt b/android/pts-avrcp.txt
index 454e26c..8bd0b4d 100644
--- a/android/pts-avrcp.txt
+++ b/android/pts-avrcp.txt
@@ -2,6 +2,7 @@ PTS test results for AVRCP
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-did.txt b/android/pts-did.txt
index d764f09..841b257 100644
--- a/android/pts-did.txt
+++ b/android/pts-did.txt
@@ -2,6 +2,7 @@ PTS test results for DID
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-gap.txt b/android/pts-gap.txt
index 1c0feec..7c88f1f 100644
--- a/android/pts-gap.txt
+++ b/android/pts-gap.txt
@@ -2,6 +2,7 @@ PTS test results for GAP
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-l2cap.txt b/android/pts-l2cap.txt
index 3e46309..f04c3e5 100644
--- a/android/pts-l2cap.txt
+++ b/android/pts-l2cap.txt
@@ -2,6 +2,7 @@ PTS test results for L2CAP
 
 PTS version: 5.0
 Tested: 29.01.2014
+Android version: 4.4.2
 
 Results:
 PASS   test passed
diff --git a/android/pts-opp.txt b/android/pts-opp.txt
index 3c4ab47..d5dfcf0 100644
--- a/android/pts-opp.txt
+++ b/android/pts-opp.txt
@@ -2,6 +2,7 @@ PTS test results for OPP
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
diff --git a/android/pts-pbap.txt b/android/pts-pbap.txt
index 4312921..41442c6 100644
--- a/android/pts-pbap.txt
+++ b/android/pts-pbap.txt
@@ -2,6 +2,7 @@ PTS test results for PBAP
 
 PTS version: 5.0
 Tested: 28.01.2014
+Android version: 4.4.2
 
 Results:
 PASS	test passed
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH] android/pts: Correct typo
From: Sebastian Chlad @ 2014-01-31 16:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sebastian Chlad

---
 android/pts-hid.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/pts-hid.txt b/android/pts-hid.txt
index 7e9f986..c29c9dc 100644
--- a/android/pts-hid.txt
+++ b/android/pts-hid.txt
@@ -1,4 +1,4 @@
-PTS test results for DID
+PTS test results for HID
 
 PTS version: 4.9
 Tested: 14.11.2013
-- 
1.8.5.3


^ permalink raw reply related

* Re: [PATCH BlueZ 4/4] audio/AVRCP: Fix coding style
From: Luiz Augusto von Dentz @ 2014-01-31 17:14 UTC (permalink / raw)
  To: Andrei Emeltchenko, Luiz Augusto von Dentz,
	linux-bluetooth@vger.kernel.org
In-Reply-To: <20140131075447.GB18867@aemeltch-MOBL1>

Hi Andrei,

On Thu, Jan 30, 2014 at 11:55 PM, Andrei Emeltchenko
<andrei.emeltchenko.news@gmail.com> wrote:
> Hi Luiz,
>
> On Thu, Jan 30, 2014 at 03:03:28PM -0800, Luiz Augusto von Dentz wrote:
>> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>
>> ---
>>  profiles/audio/avrcp.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
>> index ac861d2..4521bc4 100644
>> --- a/profiles/audio/avrcp.c
>> +++ b/profiles/audio/avrcp.c
>> @@ -2161,7 +2161,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
>>               name[namelen] = '\0';
>>       }
>>
>> -     item =  media_player_create_folder(mp, name, type, uid);
>> +     item = media_player_create_folder(mp, name, type, uid);
>
> what is the point creating this patch instead of merging with previous one
> which introduced this style issue?

Just a honest mistake, will fix it.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH 1/3] Bluetooth: Add management setting for use of debug keys
From: Marcel Holtmann @ 2014-01-31 19:55 UTC (permalink / raw)
  To: linux-bluetooth

When the controller has been enabled to allow usage of debug keys, then
clearly identify that in the current settings information.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/mgmt.h |  1 +
 net/bluetooth/mgmt.c         | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index e19049fb6c46..f87f5d784c3b 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -95,6 +95,7 @@ struct mgmt_rp_read_index_list {
 #define MGMT_SETTING_LE			0x00000200
 #define MGMT_SETTING_ADVERTISING	0x00000400
 #define MGMT_SETTING_SECURE_CONN	0x00000800
+#define MGMT_SETTING_DEBUG_KEYS		0x00001000
 
 #define MGMT_OP_READ_INFO		0x0004
 #define MGMT_READ_INFO_SIZE		0
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 111b1296a2b8..91ffecd1727e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -364,6 +364,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
 
 	settings |= MGMT_SETTING_POWERED;
 	settings |= MGMT_SETTING_PAIRABLE;
+	settings |= MGMT_SETTING_DEBUG_KEYS;
 
 	if (lmp_bredr_capable(hdev)) {
 		settings |= MGMT_SETTING_CONNECTABLE;
@@ -431,6 +432,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
 	if (test_bit(HCI_SC_ENABLED, &hdev->dev_flags))
 		settings |= MGMT_SETTING_SECURE_CONN;
 
+	if (test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags))
+		settings |= MGMT_SETTING_DEBUG_KEYS;
+
 	return settings;
 }
 
@@ -2207,6 +2211,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
 {
 	struct mgmt_cp_load_link_keys *cp = data;
 	u16 key_count, expected_len;
+	bool changed;
 	int i;
 
 	BT_DBG("request for %s", hdev->name);
@@ -2246,9 +2251,12 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
 	hci_link_keys_clear(hdev);
 
 	if (cp->debug_keys)
-		set_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
+		changed = !test_and_set_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
 	else
-		clear_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
+		changed = test_and_clear_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
+
+	if (changed)
+		new_settings(hdev, NULL);
 
 	for (i = 0; i < key_count; i++) {
 		struct mgmt_link_key_info *key = &cp->keys[i];
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 2/3] Bluetooth: Add management command to allow use of debug keys
From: Marcel Holtmann @ 2014-01-31 19:55 UTC (permalink / raw)
  To: linux-bluetooth

Originally allowing the use of debug keys was done via the Load Link
Keys management command. However this is BR/EDR specific and to be
flexible and allow extending this to LE as well, make this an independent
command.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/mgmt.h |  2 ++
 net/bluetooth/mgmt.c         | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index f87f5d784c3b..dfab094fab73 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -387,6 +387,8 @@ struct mgmt_cp_set_scan_params {
 
 #define MGMT_OP_SET_SECURE_CONN		0x002D
 
+#define MGMT_OP_SET_DEBUG_KEYS		0x002E
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16	opcode;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 91ffecd1727e..70a3a7e917b7 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -80,6 +80,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_SET_STATIC_ADDRESS,
 	MGMT_OP_SET_SCAN_PARAMS,
 	MGMT_OP_SET_SECURE_CONN,
+	MGMT_OP_SET_DEBUG_KEYS,
 };
 
 static const u16 mgmt_events[] = {
@@ -4111,6 +4112,38 @@ failed:
 	return err;
 }
 
+static int set_debug_keys(struct sock *sk, struct hci_dev *hdev,
+			  void *data, u16 len)
+{
+	struct mgmt_mode *cp = data;
+	bool changed;
+	int err;
+
+	BT_DBG("request for %s", hdev->name);
+
+	if (cp->val != 0x00 && cp->val != 0x01)
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS,
+				  MGMT_STATUS_INVALID_PARAMS);
+
+	hci_dev_lock(hdev);
+
+	if (cp->val)
+		changed = !test_and_set_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
+	else
+		changed = test_and_clear_bit(HCI_DEBUG_KEYS, &hdev->dev_flags);
+
+	err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev);
+	if (err < 0)
+		goto unlock;
+
+	if (changed)
+		err = new_settings(hdev, sk);
+
+unlock:
+	hci_dev_unlock(hdev);
+	return err;
+}
+
 static bool ltk_is_valid(struct mgmt_ltk_info *key)
 {
 	if (key->authenticated != 0x00 && key->authenticated != 0x01)
@@ -4240,6 +4273,7 @@ static const struct mgmt_handler {
 	{ set_static_address,     false, MGMT_SET_STATIC_ADDRESS_SIZE },
 	{ set_scan_params,        false, MGMT_SET_SCAN_PARAMS_SIZE },
 	{ set_secure_conn,        false, MGMT_SETTING_SIZE },
+	{ set_debug_keys,         false, MGMT_SETTING_SIZE },
 };
 
 
-- 
1.8.5.3


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox