Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Include security level 4 in connections check
From: Marcel Holtmann @ 2014-02-01 19:32 UTC (permalink / raw)
  To: linux-bluetooth

This check is only used for RFCOMM connections and most likely no
RFCOMM based profile will require security level 4 secure connection
security policy. In case it ever does make sure that seucrity level 4
is treated as sufficient security level.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_conn.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7ef5bffb61aa..801820f12226 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -860,13 +860,17 @@ int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level)
 {
 	BT_DBG("hcon %p", conn);
 
-	if (sec_level != BT_SECURITY_HIGH)
-		return 1; /* Accept if non-secure is required */
+	/* Accept if non-secure or higher security level is required */
+	if (sec_level != BT_SECURITY_HIGH && sec_level != BT_SECURITY_FIPS)
+		return 1;
 
-	if (conn->sec_level == BT_SECURITY_HIGH)
+	/* Accept if secure or higher security level is already present */
+	if (conn->sec_level == BT_SECURITY_HIGH ||
+	    conn->sec_level == BT_SECURITY_FIPS)
 		return 1;
 
-	return 0; /* Reject not secure link */
+	/* Reject not secure link */
+	return 0;
 }
 EXPORT_SYMBOL(hci_conn_check_secure);
 
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH] Bluetooth: Add management command for Secure Connection Only Mode
From: Marcel Holtmann @ 2014-02-01 17:19 UTC (permalink / raw)
  To: linux-bluetooth

With support for Secure Connections it is possible to switch the
controller into a mode that is called Secure Connections Only. In
this mode only security level 4 connections are allowed (with the
exception of security level 0 approved services).

This patch just introduces the management command and setting of the
right internal flags to enable this mode. It does not yet enforce it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/mgmt.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 8c94841072a8..ce7ef339b1c4 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4043,7 +4043,7 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
 {
 	struct mgmt_mode *cp = data;
 	struct pending_cmd *cmd;
-	u8 status;
+	u8 val, status;
 	int err;
 
 	BT_DBG("request for %s", hdev->name);
@@ -4058,7 +4058,7 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
 		return cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
 				  MGMT_STATUS_NOT_SUPPORTED);
 
-	if (cp->val != 0x00 && cp->val != 0x01)
+	if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)
 		return cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
 				  MGMT_STATUS_INVALID_PARAMS);
 
@@ -4067,12 +4067,18 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
 	if (!hdev_is_powered(hdev)) {
 		bool changed;
 
-		if (cp->val)
+		if (cp->val) {
 			changed = !test_and_set_bit(HCI_SC_ENABLED,
 						    &hdev->dev_flags);
-		else
+			if (cp->val == 0x02)
+				set_bit(HCI_SC_ONLY, &hdev->dev_flags);
+			else
+				clear_bit(HCI_SC_ONLY, &hdev->dev_flags);
+		} else {
 			changed = test_and_clear_bit(HCI_SC_ENABLED,
 						     &hdev->dev_flags);
+			clear_bit(HCI_SC_ONLY, &hdev->dev_flags);
+		}
 
 		err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev);
 		if (err < 0)
@@ -4090,7 +4096,10 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
 		goto failed;
 	}
 
-	if (!!cp->val == test_bit(HCI_SC_ENABLED, &hdev->dev_flags)) {
+	val = !!cp->val;
+
+	if (val == test_bit(HCI_SC_ENABLED, &hdev->dev_flags) &&
+	    (cp->val == 0x02) == test_bit(HCI_SC_ONLY, &hdev->dev_flags)) {
 		err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev);
 		goto failed;
 	}
@@ -4101,12 +4110,17 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
 		goto failed;
 	}
 
-	err = hci_send_cmd(hdev, HCI_OP_WRITE_SC_SUPPORT, 1, &cp->val);
+	err = hci_send_cmd(hdev, HCI_OP_WRITE_SC_SUPPORT, 1, &val);
 	if (err < 0) {
 		mgmt_pending_remove(cmd);
 		goto failed;
 	}
 
+	if (cp->val == 0x02)
+		set_bit(HCI_SC_ONLY, &hdev->dev_flags);
+	else
+		clear_bit(HCI_SC_ONLY, &hdev->dev_flags);
+
 failed:
 	hci_dev_unlock(hdev);
 	return err;
@@ -5063,19 +5077,24 @@ void mgmt_sc_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
 	if (status) {
 		u8 mgmt_err = mgmt_status(status);
 
-		if (enable && test_and_clear_bit(HCI_SC_ENABLED,
-						 &hdev->dev_flags))
-			new_settings(hdev, NULL);
+		if (enable) {
+			if (test_and_clear_bit(HCI_SC_ENABLED,
+					       &hdev->dev_flags))
+				new_settings(hdev, NULL);
+			clear_bit(HCI_SC_ONLY, &hdev->dev_flags);
+		}
 
 		mgmt_pending_foreach(MGMT_OP_SET_SECURE_CONN, hdev,
 				     cmd_status_rsp, &mgmt_err);
 		return;
 	}
 
-	if (enable)
+	if (enable) {
 		changed = !test_and_set_bit(HCI_SC_ENABLED, &hdev->dev_flags);
-	else
+	} else {
 		changed = test_and_clear_bit(HCI_SC_ENABLED, &hdev->dev_flags);
+		clear_bit(HCI_SC_ONLY, &hdev->dev_flags);
+	}
 
 	mgmt_pending_foreach(MGMT_OP_SET_SECURE_CONN, hdev,
 			     settings_rsp, &match);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH] Bluetooth: Add constants for LTK key types
From: Marcel Holtmann @ 2014-02-01  3:02 UTC (permalink / raw)
  To: linux-bluetooth

The LTK key types available right now are unauthenticated and
authenticated ones. Provide two simple constants for it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 232c07804ca8..352d3d7d06bb 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -346,6 +346,10 @@ enum {
 #define HCI_SMP_LTK			0x82
 #define HCI_SMP_LTK_SLAVE		0x83
 
+/* Long Term Key types */
+#define HCI_LTK_UNAUTH			0x00
+#define HCI_LTK_AUTH			0x01
+
 /* ---- HCI Error Codes ---- */
 #define HCI_ERROR_AUTH_FAILURE		0x05
 #define HCI_ERROR_CONNECTION_TIMEOUT	0x08
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH] core: Rename authentication to key_type in mgmt_ltk_info
From: Marcel Holtmann @ 2014-02-01  2:46 UTC (permalink / raw)
  To: linux-bluetooth

---
 lib/mgmt.h    | 2 +-
 src/adapter.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 58a651c1b10e..afd4e8b29ea3 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -177,7 +177,7 @@ struct mgmt_cp_load_link_keys {
 
 struct mgmt_ltk_info {
 	struct mgmt_addr_info addr;
-	uint8_t authenticated;
+	uint8_t type;
 	uint8_t master;
 	uint8_t enc_size;
 	uint16_t ediv;
diff --git a/src/adapter.c b/src/adapter.c
index 649fc7a957cf..18601eaa13dd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2444,7 +2444,7 @@ static void load_ltks(struct btd_adapter *adapter, GSList *keys)
 		memcpy(key->val, info->val, sizeof(info->val));
 		memcpy(key->rand, info->rand, sizeof(info->rand));
 		memcpy(&key->ediv, &info->ediv, sizeof(key->ediv));
-		key->authenticated = info->authenticated;
+		key->type = info->authenticated;
 		key->master = info->master;
 		key->enc_size = info->enc_size;
 	}
@@ -5371,8 +5371,8 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
 
 	ba2str(&addr->bdaddr, dst);
 
-	DBG("hci%u new LTK for %s authenticated %u enc_size %u",
-		adapter->dev_id, dst, ev->key.authenticated, ev->key.enc_size);
+	DBG("hci%u new LTK for %s type %u enc_size %u",
+		adapter->dev_id, dst, ev->key.type, ev->key.enc_size);
 
 	device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type);
 	if (!device) {
@@ -5386,7 +5386,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
 
 		store_longtermkey(bdaddr, &key->addr.bdaddr,
 					key->addr.type, key->val, key->master,
-					key->authenticated, key->enc_size,
+					key->type, key->enc_size,
 					key->ediv, key->rand);
 
 		device_set_bonded(device, TRUE);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 3/3] Bluetooth: Remove __packed from struct smp_ltk
From: Marcel Holtmann @ 2014-02-01  2:42 UTC (permalink / raw)
  To: linux-bluetooth

The struct smp_ltk does not need to be packed and so remove __packed.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 6854384b1f25..4e878780fa01 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -101,7 +101,7 @@ struct smp_ltk {
 	__le16 ediv;
 	u8 rand[8];
 	u8 val[16];
-} __packed;
+};
 
 struct link_key {
 	struct list_head list;
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 2/3] Bluetooth: Rename authentication to key_type in mgmt_ltk_info
From: Marcel Holtmann @ 2014-02-01  2:42 UTC (permalink / raw)
  To: linux-bluetooth

The field is not a boolean, it is actually a field for a key type. So
name it properly.

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

diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index dfab094fab73..4303fa90b7c1 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -182,7 +182,7 @@ struct mgmt_cp_load_link_keys {
 
 struct mgmt_ltk_info {
 	struct mgmt_addr_info addr;
-	__u8	authenticated;
+	__u8	type;
 	__u8	master;
 	__u8	enc_size;
 	__le16	ediv;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 8030eeb44382..8c94841072a8 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4207,7 +4207,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
 			type = HCI_SMP_LTK_SLAVE;
 
 		hci_add_ltk(hdev, &key->addr.bdaddr, addr_type,
-			    type, 0, key->authenticated, key->val,
+			    type, 0, key->type, key->val,
 			    key->enc_size, key->ediv, key->rand);
 	}
 
@@ -4648,7 +4648,7 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent)
 	ev.store_hint = persistent;
 	bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
 	ev.key.addr.type = link_to_bdaddr(LE_LINK, key->bdaddr_type);
-	ev.key.authenticated = key->authenticated;
+	ev.key.type = key->authenticated;
 	ev.key.enc_size = key->enc_size;
 	ev.key.ediv = key->ediv;
 
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 1/3] Bluetooth: Remove check for valid LTK authenticated parameter
From: Marcel Holtmann @ 2014-02-01  2:42 UTC (permalink / raw)
  To: linux-bluetooth

The LTK authenticated parameter is the key type of the LTK and similar
to link keys there is no need to check the currently supported values.

For possible future improvements, the kernel will only use key types
it knows about and just ignore all the other ones.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/mgmt.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 70a3a7e917b7..8030eeb44382 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4146,8 +4146,6 @@ unlock:
 
 static bool ltk_is_valid(struct mgmt_ltk_info *key)
 {
-	if (key->authenticated != 0x00 && key->authenticated != 0x01)
-		return false;
 	if (key->master != 0x00 && key->master != 0x01)
 		return false;
 	if (!bdaddr_type_is_le(key->addr.type))
-- 
1.8.5.3


^ permalink raw reply related

* Re: [RFC v6 00/14] LE auto connection and connection parameters
From: Marcel Holtmann @ 2014-02-01  1:17 UTC (permalink / raw)
  To: Andre Guedes; +Cc: BlueZ development
In-Reply-To: <1391116937-28217-1-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

> This patch set implements the minor changes suggested by Johan on the
> previous version.
> 
> The changes are:
>    - Rename fail_conn_attempt() to le_conn_failed()
>    - Create create_le_conn_req() helper to avoid duplicated code
> 
> Regards,
> 
> Andre
> 
> 
> Andre Guedes (14):
>  Bluetooth: Save connection interval parameters in hci_conn
>  Bluetooth: Group list_head fields from strcut hci_dev together
>  Bluetooth: Introduce connection parameters list
>  Bluetooth: Use connection parameters if any
>  Bluetooth: Introduce le_conn_failed() helper
>  Bluetooth: Stop scanning on LE connection
>  Bluetooth: Remove unused function
>  Bluetooth: Introduce hdev->pend_le_conn list
>  Bluetooth: Introduce LE auto connection infrastructure
>  Bluetooth: Re-enable background scan in case of error
>  Bluetooth: Temporarily stop background scanning on discovery
>  Bluetooth: Auto connection and power on
>  Bleutooth: Add support for auto connect options
>  Bluetooth: Add le_auto_conn file on debugfs

I applied patch 1, 2 and 5 out of this series to make some progress and make the overall set of patches smaller.

Regards

Marcel


^ permalink raw reply

* Re: [RFC v6 03/14] Bluetooth: Introduce connection parameters list
From: Marcel Holtmann @ 2014-02-01  1:11 UTC (permalink / raw)
  To: Andre Guedes; +Cc: BlueZ development
In-Reply-To: <1391116937-28217-4-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

> This patch adds to hdev the connection parameters list (hdev->le_
> conn_params). The elements from this list (struct hci_conn_params)
> contains the connection parameters (for now, minimum and maximum
> connection interval) that should be used during the connection
> establishment.
> 
> The struct hci_conn_params also defines the 'auto_connect' field
> which will be used to implement the auto connection mechanism.
> 
> Moreover, this patch adds helper functions to manipulate hdev->le_
> conn_params list. Some of these functions are also declared in
> hci_core.h since they will be used outside hci_core.c in upcoming
> patches.
> 
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
> include/net/bluetooth/hci_core.h | 25 +++++++++++++
> net/bluetooth/hci_core.c         | 80 ++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 105 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 197413b..f757b3f 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -269,6 +269,7 @@ struct hci_dev {
> 	struct list_head	link_keys;
> 	struct list_head	long_term_keys;
> 	struct list_head	remote_oob_data;
> +	struct list_head	le_conn_params;
> 
> 	struct hci_dev_stats	stat;
> 
> @@ -373,6 +374,22 @@ struct hci_chan {
> 	__u8		state;
> };
> 
> +struct hci_conn_params {
> +	struct list_head list;
> +
> +	bdaddr_t addr;
> +	u8 addr_type;
> +
> +	enum {
> +		HCI_AUTO_CONN_DISABLED,
> +		HCI_AUTO_CONN_ALWAYS,
> +		HCI_AUTO_CONN_LINK_LOSS,
> +	} auto_connect;

actually I would not include the auto_connect mode in the this stage of the patch set. We could have made more progress with this patch set and get things applied if things are not intermixed. So lets leave this out and only introduce it once we need it.

> +
> +	u16 conn_min_interval;
> +	u16 conn_max_interval;
> +};
> 

Regards

Marcel


^ permalink raw reply

* [PATCH 2/2] Bluetooth: Track the AES-CCM encryption status of LE and BR/EDR links
From: Marcel Holtmann @ 2014-02-01  0:24 UTC (permalink / raw)
  To: linux-bluetooth

When encryption for LE links has been enabled, it will always be use
AES-CCM encryption. In case of BR/EDR Secure Connections, the link
will also use AES-CCM encryption. In both cases track the AES-CCM
status in the connection flags.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_event.c        | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 378e2f32cfa0..3dbf1a0872b4 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -449,6 +449,7 @@ enum {
 	HCI_CONN_MGMT_CONNECTED,
 	HCI_CONN_SSP_ENABLED,
 	HCI_CONN_SC_ENABLED,
+	HCI_CONN_AES_CCM,
 	HCI_CONN_POWER_SAVE,
 	HCI_CONN_REMOTE_OOB,
 	HCI_CONN_6LOWPAN,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 62aea2edc231..36c9a488ac56 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1997,8 +1997,14 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
 			conn->link_mode |= HCI_LM_AUTH;
 			conn->link_mode |= HCI_LM_ENCRYPT;
 			conn->sec_level = conn->pending_sec_level;
-		} else
+
+			if ((conn->type == ACL_LINK && ev->encrypt == 0x02) ||
+			    conn->type == LE_LINK)
+				set_bit(HCI_CONN_AES_CCM, &conn->flags);
+		} else {
 			conn->link_mode &= ~HCI_LM_ENCRYPT;
+			clear_bit(HCI_CONN_AES_CCM, &conn->flags);
+		}
 	}
 
 	clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Remove one level of indentation from hci_encrypt_change_evt
From: Marcel Holtmann @ 2014-02-01  0:24 UTC (permalink / raw)
  To: linux-bluetooth

The function already has an unlock label which means the one extra level
on indentation is not useful and just makes the code more complex. So
remove it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_event.c | 49 ++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 7bb8094a3ff2..62aea2edc231 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1988,35 +1988,36 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_dev_lock(hdev);
 
 	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
-	if (conn) {
-		if (!ev->status) {
-			if (ev->encrypt) {
-				/* Encryption implies authentication */
-				conn->link_mode |= HCI_LM_AUTH;
-				conn->link_mode |= HCI_LM_ENCRYPT;
-				conn->sec_level = conn->pending_sec_level;
-			} else
-				conn->link_mode &= ~HCI_LM_ENCRYPT;
-		}
-
-		clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
+	if (!conn)
+		goto unlock;
 
-		if (ev->status && conn->state == BT_CONNECTED) {
-			hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
-			hci_conn_drop(conn);
-			goto unlock;
-		}
+	if (!ev->status) {
+		if (ev->encrypt) {
+			/* Encryption implies authentication */
+			conn->link_mode |= HCI_LM_AUTH;
+			conn->link_mode |= HCI_LM_ENCRYPT;
+			conn->sec_level = conn->pending_sec_level;
+		} else
+			conn->link_mode &= ~HCI_LM_ENCRYPT;
+	}
 
-		if (conn->state == BT_CONFIG) {
-			if (!ev->status)
-				conn->state = BT_CONNECTED;
+	clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
 
-			hci_proto_connect_cfm(conn, ev->status);
-			hci_conn_drop(conn);
-		} else
-			hci_encrypt_cfm(conn, ev->status, ev->encrypt);
+	if (ev->status && conn->state == BT_CONNECTED) {
+		hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
+		hci_conn_drop(conn);
+		goto unlock;
 	}
 
+	if (conn->state == BT_CONFIG) {
+		if (!ev->status)
+			conn->state = BT_CONNECTED;
+
+		hci_proto_connect_cfm(conn, ev->status);
+		hci_conn_drop(conn);
+	} else
+		hci_encrypt_cfm(conn, ev->status, ev->encrypt);
+
 unlock:
 	hci_dev_unlock(hdev);
 }
-- 
1.8.5.3


^ permalink raw reply related

* Re: [PATCH 3/3] Bluetooth: Remove use_debug_keys debugfs entry
From: Marcel Holtmann @ 2014-01-31 21:39 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_NaPjDdZfNXbPu-z1OBkwq89hfvN-eg6_mDDpkOMswT1g@mail.gmail.com>

Hi Anderson,

>> Since the use of debug keys can not be identified from the current
>> settings information, this debugfs entry is no longer.
> 
> I believe you meant "debug keys can be identified..."  and "is no
> longer necessary.”

indeed I did.

Johan, in case you go ahead with applying this patch, please fix this up.

Regards

Marcel


^ permalink raw reply

* Re: [PATCH 3/3] Bluetooth: Remove use_debug_keys debugfs entry
From: Anderson Lizardo @ 2014-01-31 21:18 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <1391198123-55506-3-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Jan 31, 2014 at 3:55 PM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Since the use of debug keys can not be identified from the current
> settings information, this debugfs entry is no longer.

I believe you meant "debug keys can be identified..."  and "is no
longer necessary."

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

^ permalink raw reply

* [PATCH] doc: Describe the new debug keys command and setting
From: Marcel Holtmann @ 2014-01-31 20:19 UTC (permalink / raw)
  To: linux-bluetooth

---
 doc/mgmt-api.txt | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 44ff12676180..a32237ae26b3 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -212,6 +212,7 @@ Read Controller Information Command
 		10	Low Energy
 		11	Advertising
 		12	Secure Connections
+		13	Debug Keys
 
 	This command generates a Command Complete event on success or
 	a Command Status event on failure.
@@ -1423,6 +1424,28 @@ Set Secure Connections Command
 				Invalid Index
 
 
+Set Debug Keys Command
+======================
+
+	Command Code:		0x002E
+	Controller Index:	<controller id>
+	Command Parameters:	Debug_Keys (1 Octet)
+	Return Parameters:	Current_Settings (4 Octets)
+
+	This command is  used to tell the kernel whether to accept the
+	usage of debug keys or not. The allowed values for this parameter
+	are 0x00 and 0x01. All other values will return an Invalid Parameters
+	response.
+
+	This command generates a Command Complete event on success or
+	a Command Status event on failure.
+
+	Possible errors:	Busy
+				Not Supported
+				Invalid Parameters
+				Invalid Index
+
+
 Command Complete Event
 ======================
 
-- 
1.8.5.3


^ permalink raw reply related

* Re: [PATCH 2/4] android/hal-audio: Do not allocate memory if fd < 0
From: Luiz Augusto von Dentz @ 2014-01-31 20:11 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1391177929-31416-2-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Fri, Jan 31, 2014 at 6:18 AM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> 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

We should check if the fd is valid on audio_ipc_cmd.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH 3/3] Bluetooth: Remove use_debug_keys debugfs entry
From: Marcel Holtmann @ 2014-01-31 19:55 UTC (permalink / raw)
  To: linux-bluetooth

Since the use of debug keys can not be identified from the current
settings information, this debugfs entry is no longer.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d370b432aea6..7a44c8c1037a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -285,24 +285,6 @@ static const struct file_operations link_keys_fops = {
 	.release	= single_release,
 };
 
-static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
-				   size_t count, loff_t *ppos)
-{
-	struct hci_dev *hdev = file->private_data;
-	char buf[3];
-
-	buf[0] = test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) ? 'Y': 'N';
-	buf[1] = '\n';
-	buf[2] = '\0';
-	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
-}
-
-static const struct file_operations use_debug_keys_fops = {
-	.open		= simple_open,
-	.read		= use_debug_keys_read,
-	.llseek		= default_llseek,
-};
-
 static int dev_class_show(struct seq_file *f, void *ptr)
 {
 	struct hci_dev *hdev = f->private;
@@ -1494,8 +1476,6 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &inquiry_cache_fops);
 		debugfs_create_file("link_keys", 0400, hdev->debugfs,
 				    hdev, &link_keys_fops);
-		debugfs_create_file("use_debug_keys", 0444, hdev->debugfs,
-				    hdev, &use_debug_keys_fops);
 		debugfs_create_file("dev_class", 0444, hdev->debugfs,
 				    hdev, &dev_class_fops);
 		debugfs_create_file("voice_setting", 0444, hdev->debugfs,
-- 
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

* [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

* 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] 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

* [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 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 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 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 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


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