Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCHv2 8/8] shared/hfp: Add function to get unquoted string
From: Marcin Kraglak @ 2014-02-27  9:40 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393494006-20363-1-git-send-email-marcin.kraglak@tieto.com>

---
 src/shared/hfp.c | 28 ++++++++++++++++++++++++++++
 src/shared/hfp.h |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 5239fcd..2bed006 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -335,6 +335,34 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf,
 	return true;
 }
 
+bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
+								uint8_t len)
+{
+	const char *data = result->data;
+	int i = 0;
+	char c;
+
+	skip_whitespace(result);
+
+	c = data[result->offset];
+	if (c == '"' || c == ')' || c == '(')
+		return false;
+
+	while (data[result->offset] != '\0' && data[result->offset] != ','
+					&& data[result->offset] != ')') {
+		if (i < len)
+			buf[i++] = data[result->offset];
+		result->offset++;
+	}
+
+	if (i < len)
+		buf[i++] = '\0';
+
+	next_field(result);
+
+	return true;
+}
+
 static bool call_prefix_handler(struct hfp_gw *hfp, const char *data)
 {
 	struct hfp_gw_result result;
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index 4a69486..5148253 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -117,3 +117,5 @@ bool hfp_gw_result_open_container(struct hfp_gw_result *result);
 bool hfp_gw_result_close_container(struct hfp_gw_result *result);
 bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf,
 								uint8_t len);
+bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
+								uint8_t len);
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCHv2 01/23] android/hal-gatt-api: Add missing opcodes in GATT Service
From: Szymon Janc @ 2014-02-27 11:23 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: Marcel Holtmann, Jakub Tyszkowski, linux-bluetooth
In-Reply-To: <CAF3PWx18FXpEN7wxn6v3hncD_8nYdHs1J0Fevd7pOhQr=YuNVw@mail.gmail.com>

Hi,

On Wednesday 26 of February 2014 12:34:29 Andrzej Kaczmarek wrote:
> Hi Marcel,
> 
> On 26 February 2014 09:51, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Jakub,
> >
> >> Add missing Listen and Set Advertising Data opcodes and reorder them as
> >> they appear in HAL's headers.
> >
> > I left this out originally since they are only useful for when we are a peripheral. Curious to know if Android APIs actually support this.
> 
> It does, but not as public API - internal apps can still use them but
> only if platform has config_bluetooth_le_peripheral_mode_supported
> flag set, so perhaps this is for some gadgets running Android.
> 
> > GATT client and server are valid for central role. And the connect/disconnect need to be turned into being one pair of commands. No point in duplicating them. There is really no difference between a GATT client and server connect. The central will connect to the peripheral. Unless Android got fully confused and uses the APIs wrongly.
> 
> These commands are separated for client and server since they have
> either client or server app id as parameter which is later used to
> dispatch callbacks to proper application. So using one pair of
> commands (and single notification) we can still figure out which
> callback to use in HAL as long as we have 'type' parameter for app id.

I'd keep our IPC as close to HAL API as possible and go with separate commands
and notifications. Especially since otherwise we need to add type field as
pointed by Andrzej.


-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* [PATCH 0/4] Bluetooth: Fix initiator/responder addresses for SMP
From: johan.hedberg @ 2014-02-27 12:05 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

I'm presenting this patch set as an alternative to the two patches from
Marcel. The main difference is that we trade some more complexity during
the connection creation phase with less complexity in looking up the
values in SMP when the time comes for calling the smp_c1 function.

One source of extra complexity is the attempt to handle the case of
whitelist initiated connections. Since we do not use those I'm not
completely sure it's worth to have code for it. If the handling is not
needed patch 3/4 gets a bit simpler and patch 2/4 can potentially be
dropped (I added that new function mainly to make 3/4 actually readable
with this extra whitelist handling logic).

Johan

----------------------------------------------------------------
Johan Hedberg (4):
      Bluetooth: Add tracking of advertising address type
      Bluetooth: Add hci_copy_identity_address convenience function
      Bluetooth: Track LE initiator and responder address information
      Bluetooth: Use hdev->init/resp_addr values for smp_c1 function

 include/net/bluetooth/hci_core.h |   7 +++
 net/bluetooth/hci_core.c         |  35 ++++++++---
 net/bluetooth/hci_event.c        | 114 ++++++++++++++++++++++++++++++-----
 net/bluetooth/smp.c              |  22 ++-----
 4 files changed, 136 insertions(+), 42 deletions(-)



^ permalink raw reply

* [PATCH 1/4] Bluetooth: Add tracking of advertising address type
From: johan.hedberg @ 2014-02-27 12:05 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393502743-9995-1-git-send-email-johan.hedberg@gmail.com>

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

To know the real source address for incoming connections (needed e.g.
for SMP) we should store the own_address_type parameter that was used
for the last HCI_LE_Write_Advertising_Parameters command. This patch
adds a proper command complete handler for the command and stores the
address type in a new adv_addr_type variable in the hci_dev struct.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_event.c        | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 79a75edc62d0..853376df4f99 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -156,6 +156,7 @@ struct hci_dev {
 	bdaddr_t	bdaddr;
 	bdaddr_t	random_addr;
 	bdaddr_t	static_addr;
+	__u8		adv_addr_type;
 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
 	__u8		eir[HCI_MAX_EIR_LENGTH];
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index cda92db2a9fc..f26e91f72930 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1078,6 +1078,25 @@ static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
 	}
 }
 
+static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_cp_le_set_adv_param *cp;
+	u8 status = *((u8 *) skb->data);
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+	if (status)
+		return;
+
+	cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM);
+	if (!cp)
+		return;
+
+	hci_dev_lock(hdev);
+	hdev->adv_addr_type = cp->own_address_type;
+	hci_dev_unlock(hdev);
+}
+
 static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
 					  struct sk_buff *skb)
 {
@@ -2367,6 +2386,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cc_write_le_host_supported(hdev, skb);
 		break;
 
+	case HCI_OP_LE_SET_ADV_PARAM:
+		hci_cc_set_adv_param(hdev, skb);
+		break;
+
 	case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
 		hci_cc_write_remote_amp_assoc(hdev, skb);
 		break;
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 2/4] Bluetooth: Add hci_copy_identity_address convenience function
From: johan.hedberg @ 2014-02-27 12:05 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393502743-9995-1-git-send-email-johan.hedberg@gmail.com>

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

The number of places needing the local Identity Address are starting to
grow so it's better to have a single place for the logic of determining
it. This patch adds a convenience function for getting the Identity
Address and updates the two current places needing this to use it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_core.c         | 35 +++++++++++++++++++++++++----------
 net/bluetooth/hci_event.c        | 17 +----------------
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 853376df4f99..093d05eeb3fa 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1292,6 +1292,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
 
 int hci_update_random_address(struct hci_request *req, bool require_privacy,
 			      u8 *own_addr_type);
+void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
+			       u8 *bdaddr_type);
 
 #define SCO_AIRMODE_MASK       0x0003
 #define SCO_AIRMODE_CVSD       0x0000
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bbd085d32d78..7113d4cc085f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -582,21 +582,14 @@ DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
 static int identity_show(struct seq_file *f, void *p)
 {
 	struct hci_dev *hdev = f->private;
-	bdaddr_t *addr;
+	bdaddr_t addr;
 	u8 addr_type;
 
 	hci_dev_lock(hdev);
 
-	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
-	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
-		addr = &hdev->static_addr;
-		addr_type = ADDR_LE_DEV_RANDOM;
-	} else {
-		addr = &hdev->bdaddr;
-		addr_type = ADDR_LE_DEV_PUBLIC;
-	}
+	hci_copy_identity_address(hdev, &addr, &addr_type);
 
-	seq_printf(f, "%pMR (type %u) %*phN %pMR\n", addr, addr_type,
+	seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
 		   16, hdev->irk, &hdev->rpa);
 
 	hci_dev_unlock(hdev);
@@ -3636,6 +3629,28 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
 	return 0;
 }
 
+/* Copy the Identity Address of the controller.
+ *
+ * If the controller has a public BD_ADDR, then by default use that one.
+ * If this is a LE only controller without a public address, default to
+ * the static random address.
+ *
+ * For debugging purposes it is possible to force controllers with a
+ * public address to use the static random address instead.
+ */
+void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
+			       u8 *bdaddr_type)
+{
+	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
+	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
+		bacpy(bdaddr, &hdev->static_addr);
+		*bdaddr_type = ADDR_LE_DEV_RANDOM;
+	} else {
+		bacpy(bdaddr, &hdev->bdaddr);
+		*bdaddr_type = ADDR_LE_DEV_PUBLIC;
+	}
+}
+
 /* Alloc HCI device */
 struct hci_dev *hci_alloc_dev(void)
 {
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index f26e91f72930..162235633bf5 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3665,23 +3665,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 
 	/* Ensure that the hci_conn contains the identity address type
 	 * regardless of which address the connection was made with.
-	 *
-	 * If the controller has a public BD_ADDR, then by default
-	 * use that one. If this is a LE only controller without
-	 * a public address, default to the static random address.
-	 *
-	 * For debugging purposes it is possible to force
-	 * controllers with a public address to use the static
-	 * random address instead.
 	 */
-	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
-	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
-		bacpy(&conn->src, &hdev->static_addr);
-		conn->src_type = ADDR_LE_DEV_RANDOM;
-	} else {
-		bacpy(&conn->src, &hdev->bdaddr);
-		conn->src_type = ADDR_LE_DEV_PUBLIC;
-	}
+	hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
 
 	/* Lookup the identity address from the stored connection
 	 * address and address type.
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 3/4] Bluetooth: Track LE initiator and responder address information
From: johan.hedberg @ 2014-02-27 12:05 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393502743-9995-1-git-send-email-johan.hedberg@gmail.com>

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

For SMP we need the local and remote addresses (and their types) that
were used to establish the connection. These may be different from the
Identity Addresses or even the current RPA. To guarantee that we have
this information available and it is correct track these values
separately from the very beginning of the connection.

For outgoing connections we set the values as soon as we get a
successful command status for HCI_LE_Create_Connection (for which the
patch adds a command status handler function) and for incoming
connections as soon as we get a LE Connection Complete HCI event.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  4 +++
 net/bluetooth/hci_event.c        | 74 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 093d05eeb3fa..f18f342bb120 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -331,6 +331,10 @@ struct hci_conn {
 	__u8		dst_type;
 	bdaddr_t	src;
 	__u8		src_type;
+	bdaddr_t	init_addr;
+	__u8		init_addr_type;
+	bdaddr_t	resp_addr;
+	__u8		resp_addr_type;
 	__u16		handle;
 	__u16		state;
 	__u8		mode;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 162235633bf5..203a4f1c32b1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1598,6 +1598,47 @@ static void hci_cs_accept_phylink(struct hci_dev *hdev, u8 status)
 	amp_write_remote_assoc(hdev, cp->phy_handle);
 }
 
+static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
+{
+	struct hci_cp_le_create_conn *cp;
+	struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+	/* All connection failure handling is taken care of by the
+	 * hci_le_conn_failed function which is triggered by the HCI
+	 * request completion callbacks used for connecting.
+	 */
+	if (status)
+		return;
+
+	cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
+	if (!cp)
+		return;
+
+	hci_dev_lock(hdev);
+
+	conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
+	if (!conn)
+		goto unlock;
+
+	/* Store the initiator and responder address information which
+	 * is needed for SMP. These values will not change during the
+	 * lifetime of the connection.
+	 */
+	conn->init_addr_type = cp->own_address_type;
+	if (cp->own_address_type == ADDR_LE_DEV_RANDOM)
+		bacpy(&conn->init_addr, &hdev->random_addr);
+	else
+		bacpy(&conn->init_addr, &hdev->bdaddr);
+
+	conn->resp_addr_type = cp->peer_addr_type;
+	bacpy(&conn->resp_addr, &cp->peer_addr);
+
+unlock:
+	hci_dev_unlock(hdev);
+}
+
 static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	__u8 status = *((__u8 *) skb->data);
@@ -2477,6 +2518,10 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cs_accept_phylink(hdev, ev->status);
 		break;
 
+	case HCI_OP_LE_CREATE_CONN:
+		hci_cs_le_create_conn(hdev, ev->status);
+		break;
+
 	default:
 		BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
 		break;
@@ -3661,6 +3706,35 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 			conn->out = true;
 			conn->link_mode |= HCI_LM_MASTER;
 		}
+
+		/* If we didn't have a hci_conn object previously
+		 * but we're in master role this must be something
+		 * initiated using a white list.
+		 */
+		if (conn->out) {
+			conn->resp_addr_type = ev->bdaddr_type;
+			bacpy(&conn->resp_addr, &ev->bdaddr);
+			if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) {
+				conn->init_addr_type = ADDR_LE_DEV_RANDOM;
+				bacpy(&conn->init_addr, &hdev->rpa);
+			} else {
+				hci_copy_identity_address(hdev,
+							  &conn->init_addr,
+							  &conn->init_addr_type);
+			}
+		} else {
+			/* Set the responder (our side) address type based on
+			 * the advertising address type.
+			 */
+			conn->resp_addr_type = hdev->adv_addr_type;
+			if (hdev->adv_addr_type == ADDR_LE_DEV_RANDOM)
+				bacpy(&conn->resp_addr, &hdev->random_addr);
+			else
+				bacpy(&conn->resp_addr, &hdev->bdaddr);
+
+			conn->init_addr_type = ev->bdaddr_type;
+			bacpy(&conn->init_addr, &ev->bdaddr);
+		}
 	}
 
 	/* Ensure that the hci_conn contains the identity address type
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 4/4] Bluetooth: Use hdev->init/resp_addr values for smp_c1 function
From: johan.hedberg @ 2014-02-27 12:05 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393502743-9995-1-git-send-email-johan.hedberg@gmail.com>

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

Now that we have nicely tracked values of the initiator and responder
address information we can pass that directly to the smp_c1 function
without worrying e.g. about who initiated the connection. This patch
updates the two places in smp.c to use the new variables.

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

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 52708f79545f..c7ba30dcb907 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -445,14 +445,9 @@ static void confirm_work(struct work_struct *work)
 	/* Prevent mutual access to hdev->tfm_aes */
 	hci_dev_lock(hdev);
 
-	if (conn->hcon->out)
-		ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
-			     conn->hcon->src_type, &conn->hcon->src,
-			     conn->hcon->dst_type, &conn->hcon->dst, res);
-	else
-		ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
-			     conn->hcon->dst_type, &conn->hcon->dst,
-			     conn->hcon->src_type, &conn->hcon->src, res);
+	ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp,
+		     conn->hcon->init_addr_type, &conn->hcon->init_addr,
+		     conn->hcon->resp_addr_type, &conn->hcon->resp_addr, res);
 
 	hci_dev_unlock(hdev);
 
@@ -492,14 +487,9 @@ static void random_work(struct work_struct *work)
 	/* Prevent mutual access to hdev->tfm_aes */
 	hci_dev_lock(hdev);
 
-	if (hcon->out)
-		ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
-			     hcon->src_type, &hcon->src,
-			     hcon->dst_type, &hcon->dst, res);
-	else
-		ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
-			     hcon->dst_type, &hcon->dst,
-			     hcon->src_type, &hcon->src, res);
+	ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp,
+		     hcon->init_addr_type, &hcon->init_addr,
+		     hcon->resp_addr_type, &hcon->resp_addr, res);
 
 	hci_dev_unlock(hdev);
 
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH v2 1/2] Bluetooth: Re-encrypt link after receiving an LTK
From: johan.hedberg @ 2014-02-27 12:35 UTC (permalink / raw)
  To: linux-bluetooth

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

It's not strictly speaking required to re-encrypt a link once we receive
an LTK since the connection is already encrypted with the STK. However,
re-encrypting with the LTK allows us to verify that we've received an
LTK that actually works.

This patch updates the SMP code to request encrypting with the LTK in
case we're in master role and waits until the key refresh complete event
before notifying user space of the distributed keys.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 23 ++++++++++++++++++-----
 net/bluetooth/smp.h |  3 ++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 0de98fe23330..f586728f6694 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -1174,6 +1174,7 @@ int smp_distribute_keys(struct l2cap_conn *conn)
 	struct smp_chan *smp = conn->smp_chan;
 	struct hci_conn *hcon = conn->hcon;
 	struct hci_dev *hdev = hcon->hdev;
+	bool ltk_encrypt;
 	__u8 *keydist;
 
 	BT_DBG("conn %p", conn);
@@ -1263,12 +1264,24 @@ int smp_distribute_keys(struct l2cap_conn *conn)
 	if ((smp->remote_key_dist & 0x07))
 		return 0;
 
-	clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags);
-	cancel_delayed_work_sync(&conn->security_timer);
-	set_bit(SMP_FLAG_COMPLETE, &smp->smp_flags);
-	smp_notify_keys(conn);
+	if (smp->ltk)
+		ltk_encrypt = !test_and_set_bit(SMP_FLAG_LTK_ENCRYPT,
+						&smp->smp_flags);
+	else
+		ltk_encrypt = false;
 
-	smp_chan_destroy(conn);
+	/* Re-encrypt the link with LTK if possible */
+	if (ltk_encrypt && hcon->out) {
+		struct smp_ltk *ltk = smp->ltk;
+		hci_le_start_enc(hcon, ltk->ediv, ltk->rand, ltk->val);
+		hcon->enc_key_size = ltk->enc_size;
+	} else {
+		clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags);
+		cancel_delayed_work_sync(&conn->security_timer);
+		set_bit(SMP_FLAG_COMPLETE, &smp->smp_flags);
+		smp_notify_keys(conn);
+		smp_chan_destroy(conn);
+	}
 
 	return 0;
 }
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index 1b8af35b292c..e079e8441682 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -118,7 +118,8 @@ struct smp_cmd_security_req {
 #define SMP_FLAG_TK_VALID	1
 #define SMP_FLAG_CFM_PENDING	2
 #define SMP_FLAG_MITM_AUTH	3
-#define SMP_FLAG_COMPLETE	4
+#define SMP_FLAG_LTK_ENCRYPT	4
+#define SMP_FLAG_COMPLETE	5
 
 struct smp_chan {
 	struct l2cap_conn *conn;
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH v2 2/2] Bluetooth: Fix disconnecting connections in non-connected states
From: johan.hedberg @ 2014-02-27 12:35 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393504512-21877-1-git-send-email-johan.hedberg@gmail.com>

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

When powering off and disconnecting devices we should also consider
connections which have not yet reached the BT_CONNECTED state. They may
not have a valid handle yet and simply sending a HCI_Disconnect will not
work.

This patch updates the code to either disconnect, cancel connection
creation or reject incoming connection creation based on the current
conn->state value as well as the link type in question.

When the power off procedure results in canceling connection attempts
instead of disconnecting connections we get a connection failed event
instead of a disconnection event. Therefore, we also need to have extra
code in the mgmt_connect_failed function to check if we should proceed
with the power off or not.

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

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4c4912e9a7c4..1e9747b60657 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1057,10 +1057,34 @@ static int clean_up_hci_state(struct hci_dev *hdev)
 
 	list_for_each_entry(conn, &hdev->conn_hash.list, list) {
 		struct hci_cp_disconnect dc;
-
-		dc.handle = cpu_to_le16(conn->handle);
-		dc.reason = 0x15; /* Terminated due to Power Off */
-		hci_req_add(&req, HCI_OP_DISCONNECT, sizeof(dc), &dc);
+		struct hci_cp_reject_conn_req rej;
+
+		switch (conn->state) {
+		case BT_CONNECTED:
+		case BT_CONFIG:
+			dc.handle = cpu_to_le16(conn->handle);
+			dc.reason = 0x15; /* Terminated due to Power Off */
+			hci_req_add(&req, HCI_OP_DISCONNECT, sizeof(dc), &dc);
+			break;
+		case BT_CONNECT:
+			if (conn->type == LE_LINK)
+				hci_req_add(&req, HCI_OP_LE_CREATE_CONN_CANCEL,
+					    0, NULL);
+			else if (conn->type == ACL_LINK)
+				hci_req_add(&req, HCI_OP_CREATE_CONN_CANCEL,
+					    6, &conn->dst);
+			break;
+		case BT_CONNECT2:
+			bacpy(&rej.bdaddr, &conn->dst);
+			rej.reason = 0x15; /* Terminated due to Power Off */
+			if (conn->type == ACL_LINK)
+				hci_req_add(&req, HCI_OP_REJECT_CONN_REQ,
+					    sizeof(rej), &rej);
+			else if (conn->type == SCO_LINK)
+				hci_req_add(&req, HCI_OP_REJECT_SYNC_CONN_REQ,
+					    sizeof(rej), &rej);
+			break;
+		}
 	}
 
 	return hci_req_run(&req, clean_up_hci_complete);
@@ -5182,6 +5206,18 @@ void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 			 u8 addr_type, u8 status)
 {
 	struct mgmt_ev_connect_failed ev;
+	struct pending_cmd *power_off;
+
+	power_off = mgmt_pending_find(MGMT_OP_SET_POWERED, hdev);
+	if (power_off) {
+		struct mgmt_mode *cp = power_off->param;
+
+		/* The connection is still in hci_conn_hash so test for 1
+		 * instead of 0 to know if this is the last one.
+		 */
+		if (!cp->val && hci_conn_count(hdev) == 1)
+			queue_work(hdev->req_workqueue, &hdev->power_off.work);
+	}
 
 	bacpy(&ev.addr.bdaddr, bdaddr);
 	ev.addr.type = link_to_bdaddr(link_type, addr_type);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 00/13] Android HAL GATT Server API Commands
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth

This serie of hal-gatt-api patches updates hal-ipc-api document and
hal-msg header in parallel. Should be applied on top of GATT client
patches.

Grzegorz Kolodziejczyk (13):
  android/hal-gatt-api: Add Server Register
  android/hal-gatt-api: Add Server Unregister
  android/hal-gatt-api: Add Server Connect
  android/hal-gatt-api: Add Server Disconnect
  android/hal-gatt-api: Add Server Service
  android/hal-gatt-api: Add Server Included Service
  android/hal-gatt-api: Add Server Characteristic
  android/hal-gatt-api: Add Server Descriptor
  android/hal-gatt-api: Add Server Start Service
  android/hal-gatt-api: Add Server Stop Service
  android/hal-gatt-api: Add Server Delete Service
  android/hal-gatt-api: Add Server Send Indication
  android/hal-gatt-api: Add Server Send Response

 android/hal-ipc-api.txt | 119 ++++++++++++++++++++++++++++++++++++++++++++++++
 android/hal-msg.h       |  93 +++++++++++++++++++++++++++++++++++++
 2 files changed, 212 insertions(+)

-- 
1.8.5.2


^ permalink raw reply

* [PATCH 01/13] android/hal-gatt-api: Add Server Register
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 6 ++++++
 android/hal-msg.h       | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 9b2c8ae..25428f0 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1661,6 +1661,12 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x17 - Register Server command/response
+
+		Command parameters: UUID (16 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x18 - Unregister Server command/response
 	Opcode 0x19 - Connect Peripheral command/response
 	Opcode 0x1a - Disconnect Peripheral command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index e128553..e0bfd87 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -702,6 +702,11 @@ struct hal_cmd_gatt_client_test_command {
 	struct hal_gatt_test_params params;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_REGISTER		0x17
+struct hal_cmd_gatt_server_register {
+	uint8_t uuid[16];
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 02/13] android/hal-gatt-api: Add Server Unregister
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 6 ++++++
 android/hal-msg.h       | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 25428f0..176f325 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1668,6 +1668,12 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x18 - Unregister Server command/response
+
+		Command parameters: Server (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x19 - Connect Peripheral command/response
 	Opcode 0x1a - Disconnect Peripheral command/response
 	Opcode 0x1b - Add Service command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index e0bfd87..f0fae01 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -707,6 +707,11 @@ struct hal_cmd_gatt_server_register {
 	uint8_t uuid[16];
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_UNREGISTER		0x18
+struct hal_cmd_gatt_server_unregister {
+	int32_t server_if;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 03/13] android/hal-gatt-api: Add Server Connect
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 8 ++++++++
 android/hal-msg.h       | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 176f325..f28ff8a 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1675,6 +1675,14 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x19 - Connect Peripheral command/response
+
+		Command parameters: Server (4 octets)
+		                    Remote address (6 octes)
+		                    Is Direct (1 octet)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1a - Disconnect Peripheral command/response
 	Opcode 0x1b - Add Service command/response
 	Opcode 0x1c - Add Included Service command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f0fae01..b423a94 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -712,6 +712,13 @@ struct hal_cmd_gatt_server_unregister {
 	int32_t server_if;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_CONNECT		0x19
+struct hal_cmd_gatt_server_connect {
+	int32_t server_if;
+	uint8_t bdaddr[6];
+	uint8_t is_direct;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 04/13] android/hal-gatt-api: Add Server Disconnect
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 8 ++++++++
 android/hal-msg.h       | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index f28ff8a..7c89e9c 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1684,6 +1684,14 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1a - Disconnect Peripheral command/response
+
+		Command parameters: Server (4 octets)
+		                    Remote address (6 octes)
+		                    Connection ID (1 octet)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1b - Add Service command/response
 	Opcode 0x1c - Add Included Service command/response
 	Opcode 0x1d - Add Characteristic command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index b423a94..983a017 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -719,6 +719,13 @@ struct hal_cmd_gatt_server_connect {
 	uint8_t is_direct;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_DISCONNECT		0x1a
+struct hal_cmd_gatt_server_disconnect {
+	int32_t server_if;
+	uint8_t bdaddr[6];
+	int32_t conn_id;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 05/13] android/hal-gatt-api: Add Server Service
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 14 ++++++++++++++
 android/hal-msg.h       |  7 +++++++
 2 files changed, 21 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 7c89e9c..9b1f8a6 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1693,6 +1693,20 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1b - Add Service command/response
+
+		Command parameters: Server (4 octets)
+		                    GATT Service ID (18 octets)
+		                    Number of Handles (4 octet)
+
+		Valid GATT Service ID: GATT ID (17 octets)
+		                       Is Primary (1 octet)
+
+		Valid GATT ID: UUID (16 octets)
+		               Instance ID (1 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1c - Add Included Service command/response
 	Opcode 0x1d - Add Characteristic command/response
 	Opcode 0x1e - Add Descriptor command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 983a017..cb93514 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -726,6 +726,13 @@ struct hal_cmd_gatt_server_disconnect {
 	int32_t conn_id;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_ADD_SERVICE		0x1b
+struct hal_cmd_gatt_server_add_service {
+	int32_t server_if;
+	struct hal_gatt_srvc_id srvc_id;
+	int32_t num_handles;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 06/13] android/hal-gatt-api: Add Server Included Service
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 8 ++++++++
 android/hal-msg.h       | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 9b1f8a6..c6b573a 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1708,6 +1708,14 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1c - Add Included Service command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		                    Included handle (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1d - Add Characteristic command/response
 	Opcode 0x1e - Add Descriptor command/response
 	Opcode 0x1f - Start Service command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index cb93514..4f0ae30 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -733,6 +733,13 @@ struct hal_cmd_gatt_server_add_service {
 	int32_t num_handles;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_ADD_INC_SERVICE	0x1c
+struct hal_cmd_gatt_server_add_inc_service {
+	int32_t server_if;
+	int32_t service_handle;
+	int32_t included_handle;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 07/13] android/hal-gatt-api: Add Server Characteristic
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 10 ++++++++++
 android/hal-msg.h       |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index c6b573a..b5175ca 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1717,6 +1717,16 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1d - Add Characteristic command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		                    UUID (16 octets)
+		                    Properties (4 octets)
+		                    Permissions (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1e - Add Descriptor command/response
 	Opcode 0x1f - Start Service command/response
 	Opcode 0x20 - Stop Service command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 4f0ae30..88228ad 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -740,6 +740,15 @@ struct hal_cmd_gatt_server_add_inc_service {
 	int32_t included_handle;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_ADD_CHARACTERISTIC	0x1d
+struct hal_cmd_gatt_server_add_characteristic {
+	int32_t server_if;
+	int32_t service_handle;
+	uint8_t uuid[16];
+	int32_t properties;
+	int32_t permissions;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 08/13] android/hal-gatt-api: Add Server Descriptor
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 9 +++++++++
 android/hal-msg.h       | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index b5175ca..24ff5de 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1728,6 +1728,15 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1e - Add Descriptor command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		                    UUID (16 octets)
+		                    Permissions (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x1f - Start Service command/response
 	Opcode 0x20 - Stop Service command/response
 	Opcode 0x21 - Delete Service command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 88228ad..e42b0a5 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -749,6 +749,14 @@ struct hal_cmd_gatt_server_add_characteristic {
 	int32_t permissions;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_ADD_DESCRIPTOR	0x1e
+struct hal_cmd_gatt_server_add_descriptor {
+	int32_t server_if;
+	int32_t service_handle;
+	uint8_t uuid[16];
+	int32_t permissions;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 09/13] android/hal-gatt-api: Add Server Start Service
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 8 ++++++++
 android/hal-msg.h       | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 24ff5de..812aac2 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1738,6 +1738,14 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x1f - Start Service command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		                    Transport (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x20 - Stop Service command/response
 	Opcode 0x21 - Delete Service command/response
 	Opcode 0x22 - Send Indication command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index e42b0a5..d632911 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -757,6 +757,13 @@ struct hal_cmd_gatt_server_add_descriptor {
 	int32_t permissions;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_START_SERVICE	0x1f
+struct hal_cmd_gatt_server_start_service {
+	int32_t server_if;
+	int32_t service_handle;
+	int32_t transport;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 10/13] android/hal-gatt-api: Add Server Stop Service
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 7 +++++++
 android/hal-msg.h       | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 812aac2..3104c06 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1747,6 +1747,13 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x20 - Stop Service command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x21 - Delete Service command/response
 	Opcode 0x22 - Send Indication command/response
 	Opcode 0x23 - Send Response command/response
diff --git a/android/hal-msg.h b/android/hal-msg.h
index d632911..0253f3a 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -764,6 +764,12 @@ struct hal_cmd_gatt_server_start_service {
 	int32_t transport;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_STOP_SERVICE		0x20
+struct hal_cmd_gatt_server_stop_service {
+	int32_t server_if;
+	int32_t service_handle;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 11/13] android/hal-gatt-api: Add Server Delete Service
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 7 +++++++
 android/hal-msg.h       | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 3104c06..fac614e 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1755,6 +1755,13 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x21 - Delete Service command/response
+
+		Command parameters: Server (4 octets)
+		                    Service handle (4 octets)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x22 - Send Indication command/response
 	Opcode 0x23 - Send Response command/response
 
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 0253f3a..6598996 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -770,6 +770,12 @@ struct hal_cmd_gatt_server_stop_service {
 	int32_t service_handle;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_DELETE_SERVICE	0x21
+struct hal_cmd_gatt_server_delete_service {
+	int32_t server_if;
+	int32_t service_handle;
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 12/13] android/hal-gatt-api: Add Server Send Indication
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 11 +++++++++++
 android/hal-msg.h       | 10 ++++++++++
 2 files changed, 21 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index fac614e..18bf7ed 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1763,6 +1763,17 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 		In case of an error, the error response will be returned.
 
 	Opcode 0x22 - Send Indication command/response
+
+		Command parameters: Server (4 octets)
+		                    Attribute handle (4 octets)
+		                    Connection ID (4 octets)
+		                    Length (4 octets)
+		                    Confirmation (4 octets)
+		                    Value (variable)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x23 - Send Response command/response
 
 	Opcode 0x81 - Register Client notification
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 6598996..fd67fa1 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -776,6 +776,16 @@ struct hal_cmd_gatt_server_delete_service {
 	int32_t service_handle;
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_SEND_INDICATION	0x22
+struct hal_cmd_gatt_server_send_indication {
+	int32_t server_if;
+	int32_t attribute_handle;
+	int32_t conn_id;
+	int32_t len;
+	int32_t confirm;
+	uint8_t value[0];
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 13/13] android/hal-gatt-api: Add Server Send Response
From: Grzegorz Kolodziejczyk @ 2014-02-27 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393507731-1974-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

---
 android/hal-ipc-api.txt | 17 +++++++++++++++++
 android/hal-msg.h       |  9 +++++++++
 2 files changed, 26 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 18bf7ed..f3d5fd1 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -1776,6 +1776,23 @@ Android HAL name: "gatt" (BT_PROFILE_GATT_ID)
 
 	Opcode 0x23 - Send Response command/response
 
+		Command parameters: Connection ID (4 octets)
+		                    Transaction ID (4 octets)
+		                    Status (4 octets)
+		                    GATT Response (4 octets)
+
+		Valid GATT Response: GATT Value (607 octets)
+		                     Handle (2 octets)
+
+		Valid GATT Value: Value (600 octets)
+		                  Handle (2 octets)
+		                  Offset (2 octets)
+		                  Length (2 octets)
+		                  Authentication Request (1 octet)
+		Response parameters: <none>
+
+		In case of an error, the error response will be returned.
+
 	Opcode 0x81 - Register Client notification
 	Opcode 0x82 - Scan Result notification
 	Opcode 0x83 - Connect Device notification
diff --git a/android/hal-msg.h b/android/hal-msg.h
index fd67fa1..100ba96 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -786,6 +786,15 @@ struct hal_cmd_gatt_server_send_indication {
 	uint8_t value[0];
 } __attribute__((packed));
 
+#define HAL_OP_GATT_SERVER_SEND_RESPONSE	0x23
+struct hal_cmd_gatt_server_send_response {
+	int32_t conn_id;
+	int32_t trans_id;
+	int32_t status;
+	uint8_t len;
+	uint8_t data[0];
+} __attribute__((packed));
+
 /* Notifications and confirmations */
 
 #define HAL_POWER_OFF			0x00
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 1/4] unit/avrcp: Add /TP/PAS/BV-02-C test
From: Andrei Emeltchenko @ 2014-02-27 13:35 UTC (permalink / raw)
  To: linux-bluetooth

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

Test verifies that the List Player Application Setting Attributes
response issued from the Target.
---
 unit/test-avrcp.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index c65f743..c4faca3 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -331,9 +331,23 @@ fail:
 	return AVC_CTYPE_REJECTED;
 }
 
+static uint8_t avrcp_handle_list_attributes(struct avrcp *session,
+				uint8_t transaction, uint16_t *params_len,
+				uint8_t *params, void *user_data)
+{
+	DBG("");
+
+	*params_len = 1;
+	params[0] = 0;
+
+	return AVC_CTYPE_STABLE;
+}
+
 static const struct avrcp_control_handler control_handlers[] = {
 		{ AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
 					avrcp_handle_get_capabilities },
+		{ AVRCP_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
+					avrcp_handle_list_attributes },
 		{ },
 };
 
@@ -462,5 +476,13 @@ int main(int argc, char *argv[])
 				0x00, 0x19, 0x58, 0x11, 0x00, 0x00,
 				0x00));
 
+	define_test("/TP/PAS/BV-02-C", test_server,
+			raw_pdu(0x00, 0x11, 0x0e, 0x01, 0x48, 0x00,
+				0x00, 0x19, 0x58, 0x11, 0x00, 0x00,
+				0x00),
+			raw_pdu(0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00,
+				0x00, 0x19, 0x58, 0x11, 0x00, 0x00,
+				0x01, 0x00));
+
 	return g_test_run();
 }
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 2/4] android/avrcp: Implement get player attributes text
From: Andrei Emeltchenko @ 2014-02-27 13:35 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1393508113-18628-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

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

---
 android/avrcp-lib.c | 9 +++++++++
 android/avrcp-lib.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 3db5bda..52074a7 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -312,3 +312,12 @@ int avrcp_list_player_attributes(struct avrcp *session, avctp_rsp_cb func,
 				AVRCP_LIST_PLAYER_ATTRIBUTES, NULL, 0,
 				func, user_data);
 }
+
+int avrcp_get_player_attribute_text(struct avrcp *session, uint8_t *attributes,
+					uint8_t attr_len, avctp_rsp_cb func,
+					void *user_data)
+{
+	return avrcp_send_req(session, AVC_CTYPE_STATUS, AVC_SUBUNIT_PANEL,
+				AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, attributes,
+				attr_len, func, user_data);
+}
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 7283203..da8c990 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -110,3 +110,6 @@ int avrcp_get_capabilities(struct avrcp *session, uint8_t param,
 					avctp_rsp_cb func, void *user_data);
 int avrcp_list_player_attributes(struct avrcp *session, avctp_rsp_cb func,
 							void *user_data);
+int avrcp_get_player_attribute_text(struct avrcp *session, uint8_t *attributes,
+					uint8_t attr_len, avctp_rsp_cb func,
+					void *user_data);
-- 
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