Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 3/3] android/hal: Use hidhost instead of hh in hidhost HAL
From: Szymon Janc @ 2013-11-07 16:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383841024-11965-1-git-send-email-szymon.janc@tieto.com>

Match functions names to HAL name. Where not needed hh prefix is
removed.
---
 android/hal-hidhost.c | 78 +++++++++++++++++++++++++--------------------------
 android/hal-ipc.c     |  2 +-
 android/hal.h         |  2 +-
 3 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index ed730cf..3c147e8 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -24,19 +24,19 @@
 #include "hal-msg.h"
 #include "hal-ipc.h"
 
-static const bthh_callbacks_t *bt_hh_cbacks;
+static const bthh_callbacks_t *cbacks;
 
 static bool interface_ready(void)
 {
-	return bt_hh_cbacks != NULL;
+	return cbacks != NULL;
 }
 
 static void handle_conn_state(void *buf)
 {
 	struct hal_ev_hidhost_conn_state *ev = buf;
 
-	if (bt_hh_cbacks->connection_state_cb)
-		bt_hh_cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
+	if (cbacks->connection_state_cb)
+		cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
 								ev->state);
 }
 
@@ -55,16 +55,16 @@ static void handle_info(void *buf)
 	info.dl_len = ev->descr_len;
 	memcpy(info.dsc_list, ev->descr, info.dl_len);
 
-	if (bt_hh_cbacks->hid_info_cb)
-		bt_hh_cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
+	if (cbacks->hid_info_cb)
+		cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
 }
 
 static void handle_proto_mode(void *buf)
 {
 	struct hal_ev_hidhost_proto_mode *ev = buf;
 
-	if (bt_hh_cbacks->protocol_mode_cb)
-		bt_hh_cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
+	if (cbacks->protocol_mode_cb)
+		cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
 							ev->status, ev->mode);
 }
 
@@ -72,13 +72,13 @@ static void handle_get_report(void *buf)
 {
 	struct hal_ev_hidhost_get_report *ev = buf;
 
-	if (bt_hh_cbacks->get_report_cb)
-		bt_hh_cbacks->get_report_cb((bt_bdaddr_t *) ev->bdaddr,
-						ev->status, ev->data, ev->len);
+	if (cbacks->get_report_cb)
+		cbacks->get_report_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
+							ev->data, ev->len);
 }
 
 /* will be called from notification thread context */
-void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
+void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len)
 {
 	if (!interface_ready())
 		return;
@@ -102,7 +102,7 @@ void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
 	}
 }
 
-static bt_status_t hh_connect(bt_bdaddr_t *bd_addr)
+static bt_status_t hidhost_connect(bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_hidhost_connect cmd;
 
@@ -120,7 +120,7 @@ static bt_status_t hh_connect(bt_bdaddr_t *bd_addr)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_disconnect(bt_bdaddr_t *bd_addr)
+static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_hidhost_disconnect cmd;
 
@@ -138,7 +138,7 @@ static bt_status_t hh_disconnect(bt_bdaddr_t *bd_addr)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_virtual_unplug(bt_bdaddr_t *bd_addr)
+static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
 {
 	struct hal_cmd_hidhost_vp cmd;
 
@@ -156,7 +156,7 @@ static bt_status_t hh_virtual_unplug(bt_bdaddr_t *bd_addr)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info)
+static bt_status_t set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info)
 {
 	struct hal_cmd_hidhost_set_info cmd;
 
@@ -182,7 +182,7 @@ static bt_status_t hh_set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_get_protocol(bt_bdaddr_t *bd_addr,
+static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
 					bthh_protocol_mode_t protocol_mode)
 {
 	struct hal_cmd_hidhost_get_protocol cmd;
@@ -213,7 +213,7 @@ static bt_status_t hh_get_protocol(bt_bdaddr_t *bd_addr,
 				sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_set_protocol(bt_bdaddr_t *bd_addr,
+static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
 					bthh_protocol_mode_t protocol_mode)
 {
 	struct hal_cmd_hidhost_set_protocol cmd;
@@ -244,7 +244,7 @@ static bt_status_t hh_set_protocol(bt_bdaddr_t *bd_addr,
 				sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_get_report(bt_bdaddr_t *bd_addr,
+static bt_status_t get_report(bt_bdaddr_t *bd_addr,
 						bthh_report_type_t report_type,
 						uint8_t report_id,
 						int buffer_size)
@@ -281,7 +281,7 @@ static bt_status_t hh_get_report(bt_bdaddr_t *bd_addr,
 			sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_set_report(bt_bdaddr_t *bd_addr,
+static bt_status_t set_report(bt_bdaddr_t *bd_addr,
 						bthh_report_type_t report_type,
 						char *report)
 {
@@ -317,7 +317,7 @@ static bt_status_t hh_set_report(bt_bdaddr_t *bd_addr,
 				sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_send_data(bt_bdaddr_t *bd_addr, char *data)
+static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
 {
 	struct hal_cmd_hidhost_send_data cmd;
 
@@ -335,14 +335,14 @@ static bt_status_t hh_send_data(bt_bdaddr_t *bd_addr, char *data)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bt_status_t hh_init(bthh_callbacks_t *callbacks)
+static bt_status_t init(bthh_callbacks_t *callbacks)
 {
 	struct hal_cmd_register_module cmd;
 
 	DBG("");
 
 	/* store reference to user callbacks */
-	bt_hh_cbacks = callbacks;
+	cbacks = callbacks;
 
 	cmd.service_id = HAL_SERVICE_ID_HIDHOST;
 
@@ -350,7 +350,7 @@ static bt_status_t hh_init(bthh_callbacks_t *callbacks)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static void hh_cleanup(void)
+static void cleanup(void)
 {
 	struct hal_cmd_unregister_module cmd;
 
@@ -359,7 +359,7 @@ static void hh_cleanup(void)
 	if (!interface_ready())
 		return;
 
-	bt_hh_cbacks = NULL;
+	cbacks = NULL;
 
 	cmd.service_id = HAL_SERVICE_ID_HIDHOST;
 
@@ -367,22 +367,22 @@ static void hh_cleanup(void)
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
-static bthh_interface_t hh_if = {
-	.size = sizeof(hh_if),
-	.init = hh_init,
-	.connect = hh_connect,
-	.disconnect = hh_disconnect,
-	.virtual_unplug = hh_virtual_unplug,
-	.set_info = hh_set_info,
-	.get_protocol = hh_get_protocol,
-	.set_protocol = hh_set_protocol,
-	.get_report = hh_get_report,
-	.set_report = hh_set_report,
-	.send_data = hh_send_data,
-	.cleanup = hh_cleanup
+static bthh_interface_t hidhost_if = {
+	.size = sizeof(hidhost_if),
+	.init = init,
+	.connect = hidhost_connect,
+	.disconnect = disconnect,
+	.virtual_unplug = virtual_unplug,
+	.set_info = set_info,
+	.get_protocol = get_protocol,
+	.set_protocol = set_protocol,
+	.get_report = get_report,
+	.set_report = set_report,
+	.send_data = send_data,
+	.cleanup = cleanup
 };
 
 bthh_interface_t *bt_get_hidhost_interface(void)
 {
-	return &hh_if;
+	return &hidhost_if;
 }
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index a34061d..e1c8dd7 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -50,7 +50,7 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
 		bt_notify_adapter(msg->opcode, msg->payload, msg->len);
 		break;
 	case HAL_SERVICE_ID_HIDHOST:
-		bt_notify_hh(msg->opcode, msg->payload, msg->len);
+		bt_notify_hidhost(msg->opcode, msg->payload, msg->len);
 		break;
 	case HAL_SERVICE_ID_A2DP:
 		bt_notify_a2dp(msg->opcode, msg->payload, msg->len);
diff --git a/android/hal.h b/android/hal.h
index f47ec2a..2ce7932 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -29,5 +29,5 @@ btav_interface_t *bt_get_a2dp_interface(void);
 void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
 void bt_thread_associate(void);
 void bt_thread_disassociate(void);
-void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len);
+void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len);
 void bt_notify_a2dp(uint16_t opcode, void *buf, uint16_t len);
-- 
1.8.4.2


^ permalink raw reply related

* Re: [PATCH v3] android: Add set/get for discovery timeout
From: Johan Hedberg @ 2013-11-07 16:44 UTC (permalink / raw)
  To: Lukasz Rymanowski; +Cc: linux-bluetooth, szymon.janc
In-Reply-To: <1383839864-5470-1-git-send-email-lukasz.rymanowski@tieto.com>

Hi Lukasz,

On Thu, Nov 07, 2013, Lukasz Rymanowski wrote:
> Android handles discoverable timeout in Settings app, however still
> expects BT stack to maintain this value so we should do it as well.
> Otherwise we will get some unexpected behaviour.
> For now we keep discovery_timeout only during runtime, but we need to move
> it to some local storage once we will have it.
> 
> Note: That since Android Settings up handles timer there is no reason to
> use discovery timer we have in kernel.
> ---
>  android/adapter.c | 38 +++++++++++++++++++++++++++++++++++---
>  1 file changed, 35 insertions(+), 3 deletions(-)

Applied, but I still had to tweak around the coding style a bit:

> +	memcpy(&ev->props[0].val, &adapter->discoverable_timeout,
> +						sizeof(uint32_t));

You can indent this second line more here. General rule is indent as
long as you stay under 80 characters.

> +	ipc_send(notification_sk, HAL_SERVICE_ID_BLUETOOTH,
> +				HAL_EV_ADAPTER_PROPS_CHANGED,
> +					sizeof(buf), ev, -1);

Here you're not only under-indented but the second continuation line
doesn't match the first continuation line (the coding style is to keep
lines 2-n with the same indentation).

Johan

^ permalink raw reply

* Re: [PATCH 1/3] android: Rename hidhost HAL related IPC API to match service name
From: Johan Hedberg @ 2013-11-07 16:47 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1383841024-11965-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Thu, Nov 07, 2013, Szymon Janc wrote:
> Use 'Android HAL name' string from IPC doc as base for names.
> ---
>  android/hal-hidhost.c | 72 +++++++++++++++++++++---------------------
>  android/hal-msg.h     | 80 +++++++++++++++++++++++------------------------
>  android/hid.c         | 86 ++++++++++++++++++++++++++-------------------------
>  3 files changed, 120 insertions(+), 118 deletions(-)

All three patches have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/2] android: Remove redundant command complete callback
From: Johan Hedberg @ 2013-11-07 19:51 UTC (permalink / raw)
  To: Jakub Tyszkowski; +Cc: linux-bluetooth
In-Reply-To: <1383816710-31059-1-git-send-email-jakub.tyszkowski@tieto.com>

Hi Jakub,

On Thu, Nov 07, 2013, Jakub Tyszkowski wrote:
> This patch removes command complete callback used only for verbose error
> reporting.
> 
> ---
>  android/adapter.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)

Both patches have been applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/2] Bluetooth: Remove unneeded check in hci_disconn_complete_evt()
From: Andre Guedes @ 2013-11-07 20:08 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <20131105080920.GA20765@x220.p-661hnu-f1>

Hi Johan,

On 05/11/13 05:09, Johan Hedberg wrote:
> Hi Andre,
>
> On Mon, Nov 04, 2013, Andre Guedes wrote:
>> According to b644ba336 (patch that introduced HCI_CONN_MGMT_CONNECTED
>> flag), the HCI_CONN_MGMT_CONNECTED flag tracks when mgmt has been
>> notified about the connection.
>>
>> That being said, there is no point in checking this flag in hci_
>> disconn_complete_evt() since neither mgmt_disconnect_failed() nor
>> mgmt_device_disconnected() depend on it. Below follows more details:
>>    * mgmt_disconnect_failed() removes pending MGMT_OP_DISCONNECT
>>      commands, it doesn't matter if that connection was notified or not.
>>    * mgmt_device_disconnected() sends the mgmt event only if the link
>>      type is ACL_LINK or LE_LINK. For those connection type, the flag is
>>      always set.
>>
>> So this patch removes the HCI_CONN_MGMT_CONNECTED check.
>>
>> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
>> ---
>>   net/bluetooth/hci_event.c | 16 +++++++---------
>>   1 file changed, 7 insertions(+), 9 deletions(-)
>>
>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
>> index 142aa61..560296d 100644
>> --- a/net/bluetooth/hci_event.c
>> +++ b/net/bluetooth/hci_event.c
>> @@ -1792,16 +1792,14 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
>>   	if (ev->status == 0)
>>   		conn->state = BT_CLOSED;
>>
>> -	if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
>> -		if (ev->status) {
>> -			mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
>> -					       conn->dst_type, ev->status);
>> -		} else {
>> -			u8 reason = hci_to_mgmt_reason(ev->reason);
>> +	if (ev->status) {
>> +		mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
>> +				       conn->dst_type, ev->status);
>> +	} else {
>> +		u8 reason = hci_to_mgmt_reason(ev->reason);
>>
>> -			mgmt_device_disconnected(hdev, &conn->dst, conn->type,
>> -						 conn->dst_type, reason);
>> -		}
>> +		mgmt_device_disconnected(hdev, &conn->dst, conn->type,
>> +					 conn->dst_type, reason);
>>   	}
>>
>>   	if (ev->status == 0) {
>
> It looks to me like this would cause an invalid mgmt_device_disconnected
> event to be sent of the ACL goes down before we notify over mgmt that
> it's connected. This could e.g. happen if the ACL disconnection happens
> before we complete the implicit name resolving (which is the main reason
> why this flag exists to begin with). Am I missing something here?

I guess you are right. I'll fix this patch by checking the flag before 
calling mgmt_device_disconnected().

Thanks for your review.

Andre

^ permalink raw reply

* [PATCH v2 1/2] Bluetooth: Remove unneeded check in hci_disconn_complete_evt()
From: Andre Guedes @ 2013-11-07 20:36 UTC (permalink / raw)
  To: linux-bluetooth

According to b644ba336 (patch that introduced HCI_CONN_MGMT_CONNECTED
flag), the HCI_CONN_MGMT_CONNECTED flag tracks when mgmt has been
notified about the connection.

That being said, there is no point in calling mgmt_disconnect_failed()
conditionally based on this flag. mgmt_disconnect_failed() removes
pending MGMT_OP_DISCONNECT commands, it doesn't matter if that
connection was notified or not.

Moreover, if the Disconnection Complete event has status then we have
nothing else to do but call mgmt_disconnect_failed() and return.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_event.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 142aa61..eb99a12 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1779,6 +1779,7 @@ static u8 hci_to_mgmt_reason(u8 err)
 static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_disconn_complete *ev = (void *) skb->data;
+	u8 reason = hci_to_mgmt_reason(ev->reason);
 	struct hci_conn *conn;
 
 	BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
@@ -1792,18 +1793,16 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	if (ev->status == 0)
 		conn->state = BT_CLOSED;
 
-	if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
-		if (ev->status) {
-			mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
-					       conn->dst_type, ev->status);
-		} else {
-			u8 reason = hci_to_mgmt_reason(ev->reason);
-
-			mgmt_device_disconnected(hdev, &conn->dst, conn->type,
-						 conn->dst_type, reason);
-		}
+	if (ev->status) {
+		mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
+				       conn->dst_type, ev->status);
+		goto unlock;
 	}
 
+	if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
+		mgmt_device_disconnected(hdev, &conn->dst, conn->type,
+					 conn->dst_type, reason);
+
 	if (ev->status == 0) {
 		u8 type = conn->type;
 
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 2/2] Bluetooth: Refactor hci_disconn_complete_evt
From: Andre Guedes @ 2013-11-07 20:36 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1383856570-30480-1-git-send-email-andre.guedes@openbossa.org>

hci_disconn_complete_evt() logic is more complicated than what it
should be, making it hard to follow and add new features.

So this patch does some code refactoring by handling the error cases
in the beginning of the function and by moving the main flow into the
first level of function scope. No change is done in the event handling
logic itself.

Besides organizing this messy code, this patch makes easier to add
code for handling LE auto connection (which will be added in a further
patch).

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_event.c | 43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index eb99a12..5fb3df6 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1781,6 +1781,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	struct hci_ev_disconn_complete *ev = (void *) skb->data;
 	u8 reason = hci_to_mgmt_reason(ev->reason);
 	struct hci_conn *conn;
+	u8 type;
 
 	BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
@@ -1790,40 +1791,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	if (!conn)
 		goto unlock;
 
-	if (ev->status == 0)
-		conn->state = BT_CLOSED;
-
 	if (ev->status) {
 		mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
 				       conn->dst_type, ev->status);
 		goto unlock;
 	}
 
+	conn->state = BT_CLOSED;
+
 	if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
 		mgmt_device_disconnected(hdev, &conn->dst, conn->type,
 					 conn->dst_type, reason);
 
-	if (ev->status == 0) {
-		u8 type = conn->type;
+	if (conn->type == ACL_LINK && conn->flush_key)
+		hci_remove_link_key(hdev, &conn->dst);
 
-		if (type == ACL_LINK && conn->flush_key)
-			hci_remove_link_key(hdev, &conn->dst);
-		hci_proto_disconn_cfm(conn, ev->reason);
-		hci_conn_del(conn);
+	type = conn->type;
 
-		/* Re-enable advertising if necessary, since it might
-		 * have been disabled by the connection. From the
-		 * HCI_LE_Set_Advertise_Enable command description in
-		 * the core specification (v4.0):
-		 * "The Controller shall continue advertising until the Host
-		 * issues an LE_Set_Advertise_Enable command with
-		 * Advertising_Enable set to 0x00 (Advertising is disabled)
-		 * or until a connection is created or until the Advertising
-		 * is timed out due to Directed Advertising."
-		 */
-		if (type == LE_LINK)
-			mgmt_reenable_advertising(hdev);
-	}
+	hci_proto_disconn_cfm(conn, ev->reason);
+	hci_conn_del(conn);
+
+	/* Re-enable advertising if necessary, since it might
+	 * have been disabled by the connection. From the
+	 * HCI_LE_Set_Advertise_Enable command description in
+	 * the core specification (v4.0):
+	 * "The Controller shall continue advertising until the Host
+	 * issues an LE_Set_Advertise_Enable command with
+	 * Advertising_Enable set to 0x00 (Advertising is disabled)
+	 * or until a connection is created or until the Advertising
+	 * is timed out due to Directed Advertising."
+	 */
+	if (type == LE_LINK)
+		mgmt_reenable_advertising(hdev);
 
 unlock:
 	hci_dev_unlock(hdev);
-- 
1.8.4


^ permalink raw reply related

* Re: [PATCH v2 1/2] Bluetooth: Remove unneeded check in hci_disconn_complete_evt()
From: Johan Hedberg @ 2013-11-07 21:56 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth
In-Reply-To: <1383856570-30480-1-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

On Thu, Nov 07, 2013, Andre Guedes wrote:
> According to b644ba336 (patch that introduced HCI_CONN_MGMT_CONNECTED
> flag), the HCI_CONN_MGMT_CONNECTED flag tracks when mgmt has been
> notified about the connection.
> 
> That being said, there is no point in calling mgmt_disconnect_failed()
> conditionally based on this flag. mgmt_disconnect_failed() removes
> pending MGMT_OP_DISCONNECT commands, it doesn't matter if that
> connection was notified or not.
> 
> Moreover, if the Disconnection Complete event has status then we have
> nothing else to do but call mgmt_disconnect_failed() and return.
> 
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
>  net/bluetooth/hci_event.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)

Acked-by: Johan Hedberg <johan.hedberg@intel.com>

Johan

^ permalink raw reply

* Re: [PATCH v2 2/2] Bluetooth: Refactor hci_disconn_complete_evt
From: Johan Hedberg @ 2013-11-07 21:59 UTC (permalink / raw)
  To: Andre Guedes; +Cc: linux-bluetooth
In-Reply-To: <1383856570-30480-2-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

On Thu, Nov 07, 2013, Andre Guedes wrote:
> hci_disconn_complete_evt() logic is more complicated than what it
> should be, making it hard to follow and add new features.
> 
> So this patch does some code refactoring by handling the error cases
> in the beginning of the function and by moving the main flow into the
> first level of function scope. No change is done in the event handling
> logic itself.
> 
> Besides organizing this messy code, this patch makes easier to add
> code for handling LE auto connection (which will be added in a further
> patch).
> 
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
>  net/bluetooth/hci_event.c | 43 +++++++++++++++++++++----------------------
>  1 file changed, 21 insertions(+), 22 deletions(-)

Acked-by: Johan Hedberg <johan.hedberg@intel.com>

Johan

^ permalink raw reply

* [PATCH_v2 00/11] Fix issues and implement virtual unplug and send data
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

v2: Fixed issues as per Johan's comments and suggestions.
    This patch adds missing hid ipc documentation, hal headers,
    renaming and virtual unplug notification in hid HAL.
    Set report and send data interfaces are receiving data in ascii format
    but it should be in hex format. Provided utility for this and fixed
    set report data preparation. Implemented virtual unplug and send data
    methods in daemon.

v1: This patch adds missing hid ipc documentation, hal headers,
    renaming and virtual unplug notification in hid HAL.
    send RFC for ascii2hex utility.
    Unsupported methods are virtual unplug and send data in daemon.

Ravi kumar Veeramally (11):
  android/hid: Remove fixed number of hid set report data length in ipc
    doc
  android/hid: Add a ascii2hex utility
  android/hid: Fix set report data format
  android/hid: Add missing hid send data parameters in ipc document
  android/hid: Add missing parameters in send data struct in HAL headers
  android/hid: Fill send data structure variables in hal-hidhost
  android/hid: Rename virtual unplug define and struct
  android/hid: Add hid event virtual unplug structure to HAL msg headers
  android/hid: Handle virtual unplug notification in hid hal
  android/hid: Add virtual unplug implemention in daemon
  android/hid: Add send data implemention in daemon

 android/Android.mk      |  1 +
 android/Makefile.am     |  2 +-
 android/hal-hidhost.c   | 64 ++++++++++++++++++++++++++--------
 android/hal-ipc-api.txt |  6 ++--
 android/hal-msg.h       | 16 ++++++---
 android/hidhost.c       | 91 ++++++++++++++++++++++++++++++++++++++++++++-----
 android/utils.c         | 41 ++++++++++++++++++++++
 android/utils.h         |  3 ++
 8 files changed, 193 insertions(+), 31 deletions(-)
 create mode 100644 android/utils.c

-- 
1.8.3.2


^ permalink raw reply

* [PATCH_v2 01/11] android/hid: Remove fixed number of hid set report data length in ipc doc
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

HAL receives data in ascii format but it should be in hex format. So remove
fixed size of report data length and depend on report length parameter.
---
 android/hal-ipc-api.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index c39cb0d..297f565 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -553,7 +553,7 @@ Commands and responses:
 		Command parameters: Remote address (6 octets)
 		                    Report type (1 octet)
 		                    Report length (2 octets)
-		                    Report data (670 octets)
+		                    Report data (Report length)
 
 		Response parameters: <none>
 
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 02/11] android/hid: Add a ascii2hex utility
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Data from few interfaces on HAL is in ascii format but it should be
in hex format. This conversion utility does that job.
---
 android/Android.mk  |  1 +
 android/Makefile.am |  2 +-
 android/utils.c     | 41 +++++++++++++++++++++++++++++++++++++++++
 android/utils.h     |  3 +++
 4 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 android/utils.c

diff --git a/android/Android.mk b/android/Android.mk
index 51037a7..628b2f9 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -27,6 +27,7 @@ LOCAL_SRC_FILES := \
 	ipc.c ipc.h \
 	a2dp.c \
 	pan.c \
+	utils.c \
 	../src/log.c \
 	../src/shared/mgmt.c \
 	../src/shared/util.c \
diff --git a/android/Makefile.am b/android/Makefile.am
index 073edc8..6063a3a 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -9,7 +9,7 @@ noinst_PROGRAMS += android/bluetoothd
 android_bluetoothd_SOURCES = android/main.c \
 				src/log.c \
 				android/hal-msg.h \
-				android/utils.h \
+				android/utils.h android/utils.c \
 				src/sdpd-database.c src/sdpd-server.c \
 				src/sdpd-service.c src/sdpd-request.c \
 				src/glib-helper.h src/glib-helper.c \
diff --git a/android/utils.c b/android/utils.c
new file mode 100644
index 0000000..48d6c38
--- /dev/null
+++ b/android/utils.c
@@ -0,0 +1,41 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2013  Intel Corporation. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "utils.h"
+
+void ascii2hex(const uint8_t *ascii, int ascii_len, uint8_t *hex)
+{
+	int i;
+
+	if (!ascii || !hex)
+		return;
+
+	for (i = 0; i < ascii_len / 2; i++)
+		sscanf((char *) &ascii[i * 2], "%02x",
+						(unsigned int *) &hex[i]);
+
+}
diff --git a/android/utils.h b/android/utils.h
index 5b009bc..d424968 100644
--- a/android/utils.h
+++ b/android/utils.h
@@ -21,6 +21,7 @@
  *
  */
 
+#include "lib/bluetooth.h"
 
 static inline void android2bdaddr(const void *buf, bdaddr_t *dst)
 {
@@ -31,3 +32,5 @@ static inline void bdaddr2android(const bdaddr_t *src, void *buf)
 {
 	baswap(buf, src);
 }
+
+void ascii2hex(const uint8_t *ascii, int ascii_len, uint8_t *hex);
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 03/11] android/hid: Fix set report data format
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Data is in ascii format from HAL. Convert it to hex and send it to
hid device.
---
 android/hal-hidhost.c | 29 ++++++++++++++++++++---------
 android/hal-msg.h     |  2 +-
 android/hidhost.c     |  8 +++++---
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 3c147e8..6fe4c52 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -18,6 +18,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "hal-log.h"
 #include "hal.h"
@@ -285,7 +286,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
 						bthh_report_type_t report_type,
 						char *report)
 {
-	struct hal_cmd_hidhost_set_report cmd;
+	struct hal_cmd_hidhost_set_report *cmd;
+	int cmd_len, status;
 
 	DBG("");
 
@@ -295,26 +297,35 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
 	if (!bd_addr || !report)
 		return BT_STATUS_PARM_INVALID;
 
-	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
-	cmd.len = strlen(report);
-	memcpy(cmd.data, report, cmd.len);
+	cmd_len = sizeof(*cmd) + sizeof(struct hal_cmd_hidhost_set_report)
+							+ 1 + strlen(report);
+
+	cmd = malloc(cmd_len);
+	memset(cmd, 0, cmd_len);
+	memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+	cmd->len = strlen(report);
+	memcpy(cmd->data, report, cmd->len);
 
 	switch (report_type) {
 	case BTHH_INPUT_REPORT:
-		cmd.type = HAL_HIDHOST_INPUT_REPORT;
+		cmd->type = HAL_HIDHOST_INPUT_REPORT;
 		break;
 	case BTHH_OUTPUT_REPORT:
-		cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
+		cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
 		break;
 	case BTHH_FEATURE_REPORT:
-		cmd.type = HAL_HIDHOST_FEATURE_REPORT;
+		cmd->type = HAL_HIDHOST_FEATURE_REPORT;
 		break;
 	default:
+		free(cmd);
 		return BT_STATUS_PARM_INVALID;
 	}
 
-	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
-				sizeof(cmd), &cmd, 0, NULL, NULL);
+	status = hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
+						cmd_len, cmd, 0, NULL, NULL);
+	free(cmd);
+
+	return status;
 }
 
 static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 7045c8c..08a159e 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -293,7 +293,7 @@ struct hal_cmd_hidhost_set_report {
 	uint8_t  bdaddr[6];
 	uint8_t  type;
 	uint16_t len;
-	uint8_t  data[670];
+	uint8_t  data[0];
 } __attribute__((packed));
 
 #define HAL_OP_HIDHOST_SEND_DATA		0x09
diff --git a/android/hidhost.c b/android/hidhost.c
index c7b4114..4b12318 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -900,18 +900,20 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
 		return HAL_STATUS_FAILED;
 
 	dev = l->data;
-	req_size = 1 + cmd->len;
+	/* Report data coming from HAL is in ascii format, so convert
+	 * it to hex and calculate length according to it. */
+	req_size = 1 + (cmd->len / 2);
 	req = g_try_malloc0(req_size);
 	if (!req)
 		return HAL_STATUS_NOMEM;
 
 	req[0] = HID_MSG_SET_REPORT | cmd->type;
-	memcpy(req + 1, cmd->data, req_size - 1);
+	ascii2hex(cmd->data, cmd->len, (req + 1));
 
 	fd = g_io_channel_unix_get_fd(dev->ctrl_io);
 
 	if (write(fd, req, req_size) < 0) {
-		error("error while querying device protocol");
+		error("error while sending report");
 		g_free(req);
 		return HAL_STATUS_FAILED;
 	}
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 04/11] android/hid: Add missing hid send data parameters in ipc document
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/hal-ipc-api.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 297f565..91ea280 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -566,7 +566,9 @@ Commands and responses:
 	Opcode 0x09 - Send Data command/response
 
 		Command parameters: Remote address (6 octets)
-		                    ...
+		                    Data length (2 octets)
+		                    Data (Data length)
+
 		Response parameters: <none>
 
 		In case of an error, the error response will be returned.
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 05/11] android/hid: Add missing parameters in send data struct in HAL headers
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/hal-msg.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 08a159e..05c9de0 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -298,7 +298,9 @@ struct hal_cmd_hidhost_set_report {
 
 #define HAL_OP_HIDHOST_SEND_DATA		0x09
 struct hal_cmd_hidhost_send_data {
-	uint8_t bdaddr[6];
+	uint8_t  bdaddr[6];
+	uint16_t len;
+	uint8_t  data[0];
 } __attribute__((packed));
 
 /* a2dp HAL API */
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 06/11] android/hid: Fill send data structure variables in hal-hidhost
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/hal-hidhost.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 6fe4c52..1617a16 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -330,7 +330,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
 
 static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
 {
-	struct hal_cmd_hidhost_send_data cmd;
+	struct hal_cmd_hidhost_send_data *cmd;
+	int cmd_len, status;
 
 	DBG("");
 
@@ -340,10 +341,19 @@ static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
 	if (!bd_addr || !data)
 		return BT_STATUS_PARM_INVALID;
 
-	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+	cmd_len = sizeof(*cmd) + sizeof(struct hal_cmd_hidhost_send_data)
+							+ 1 + strlen(data);
 
-	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
-					sizeof(cmd), &cmd, 0, NULL, NULL);
+	cmd = malloc(cmd_len);
+	memset(cmd, 0, cmd_len);
+	memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
+	cmd->len = strlen(data);
+	memcpy(cmd->data, data, cmd->len);
+
+	status = hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
+						cmd_len, cmd, 0, NULL, NULL);
+	free(cmd);
+	return status;
 }
 
 static bt_status_t init(bthh_callbacks_t *callbacks)
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 07/11] android/hid: Rename virtual unplug define and struct
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Renaming virtual unplug define and strcut name from VP to more
meaning full.
---
 android/hal-hidhost.c | 5 +++--
 android/hal-msg.h     | 4 ++--
 android/hidhost.c     | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 1617a16..dbdf176 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -141,7 +141,7 @@ static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
 
 static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
 {
-	struct hal_cmd_hidhost_vp cmd;
+	struct hal_cmd_hidhost_virtual_unplug cmd;
 
 	DBG("");
 
@@ -153,7 +153,8 @@ static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
 
 	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_VP,
+	return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
+					HAL_OP_HIDHOST_VIRTUAL_UNPLUG,
 					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 05c9de0..3ad9af6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -242,8 +242,8 @@ struct hal_cmd_hidhost_disconnect {
 	uint8_t bdaddr[6];
 } __attribute__((packed));
 
-#define HAL_OP_HIDHOST_VP			0x03
-struct hal_cmd_hidhost_vp {
+#define HAL_OP_HIDHOST_VIRTUAL_UNPLUG		0x03
+struct hal_cmd_hidhost_virtual_unplug {
 	uint8_t bdaddr[6];
 } __attribute__((packed));
 
diff --git a/android/hidhost.c b/android/hidhost.c
index 4b12318..b7ec6ff 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -741,7 +741,7 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hidhost_disconnect *cmd,
 	return HAL_STATUS_SUCCESS;
 }
 
-static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hidhost_vp *cmd,
+static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hidhost_virtual_unplug *cmd,
 								uint16_t len)
 {
 	DBG("Not Implemented");
@@ -942,7 +942,7 @@ void bt_hid_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
 	case HAL_OP_HIDHOST_DISCONNECT:
 		status = bt_hid_disconnect(buf, len);
 		break;
-	case HAL_OP_HIDHOST_VP:
+	case HAL_OP_HIDHOST_VIRTUAL_UNPLUG:
 		status = bt_hid_virtual_unplug(buf, len);
 		break;
 	case HAL_OP_HIDHOST_SET_INFO:
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 08/11] android/hid: Add hid event virtual unplug structure to HAL msg headers
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/hal-msg.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 3ad9af6..4c7d344 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -479,6 +479,12 @@ struct hal_ev_hidhost_get_report {
 	uint8_t  data[0];
 } __attribute__((packed));
 
+#define HAL_EV_HIDHOST_VIRTUAL_UNPLUG		0x86
+struct hal_ev_hidhost_virtual_unplug {
+	uint8_t  bdaddr[6];
+	uint8_t  status;
+} __attribute__((packed));
+
 #define HAL_EV_A2DP_CONNECTION_STATE	0x81
 struct hal_ev_a2dp_connection_state {
 	uint8_t state;
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 09/11] android/hid: Handle virtual unplug notification in hid hal
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

---
 android/hal-hidhost.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index dbdf176..db95e3e 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -78,6 +78,15 @@ static void handle_get_report(void *buf)
 							ev->data, ev->len);
 }
 
+static void handle_virtual_unplug(void *buf)
+{
+	struct hal_ev_hidhost_virtual_unplug *ev = buf;
+
+	if (cbacks->virtual_unplug_cb)
+		cbacks->virtual_unplug_cb((bt_bdaddr_t *) ev->bdaddr,
+								ev->status);
+}
+
 /* will be called from notification thread context */
 void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len)
 {
@@ -97,6 +106,9 @@ void bt_notify_hidhost(uint16_t opcode, void *buf, uint16_t len)
 	case HAL_EV_HIDHOST_GET_REPORT:
 		handle_get_report(buf);
 		break;
+	case HAL_EV_HIDHOST_VIRTUAL_UNPLUG:
+		handle_virtual_unplug(buf);
+		break;
 	default:
 		DBG("Unhandled callback opcode=0x%x", opcode);
 		break;
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 10/11] android/hid: Add virtual unplug implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Send virtual unplug command to hid device and disconnect and remove
hid device details.
---
 android/hidhost.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/android/hidhost.c b/android/hidhost.c
index b7ec6ff..4fc8963 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -55,6 +55,7 @@
 #define UHID_DEVICE_FILE	"/dev/uhid"
 
 /* HID message types */
+#define HID_MSG_CONTROL		0x10
 #define HID_MSG_GET_REPORT	0x40
 #define HID_MSG_SET_REPORT	0x50
 #define HID_MSG_GET_PROTOCOL	0x60
@@ -73,6 +74,9 @@
 /* HID GET REPORT Size Field */
 #define HID_GET_REPORT_SIZE_FIELD	0x08
 
+/* HID Virtual Cable Unplug */
+#define HID_VIRTUAL_CABLE_UNPLUG	0x05
+
 static int notification_sk = -1;
 static GIOChannel *ctrl_io = NULL;
 static GIOChannel *intr_io = NULL;
@@ -744,9 +748,42 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hidhost_disconnect *cmd,
 static uint8_t bt_hid_virtual_unplug(struct hal_cmd_hidhost_virtual_unplug *cmd,
 								uint16_t len)
 {
-	DBG("Not Implemented");
+	struct hid_device *dev;
+	GSList *l;
+	bdaddr_t dst;
+	uint8_t hdr;
+	int fd;
 
-	return HAL_STATUS_FAILED;
+	DBG("");
+
+	if (len < sizeof(*cmd))
+		return HAL_STATUS_INVALID;
+
+	android2bdaddr(&cmd->bdaddr, &dst);
+
+	l = g_slist_find_custom(devices, &dst, device_cmp);
+	if (!l)
+		return HAL_STATUS_FAILED;
+
+	dev = l->data;
+	hdr = HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG;
+	fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+	if (write(fd, &hdr, sizeof(hdr)) < 0) {
+		error("error while virtual unplug command");
+		return HAL_STATUS_FAILED;
+	}
+
+	/* Wait either channels to HUP */
+	if (dev->intr_io)
+		g_io_channel_shutdown(dev->intr_io, TRUE, NULL);
+
+	if (dev->ctrl_io)
+		g_io_channel_shutdown(dev->ctrl_io, TRUE, NULL);
+
+	bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTING);
+
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t bt_hid_info(struct hal_cmd_hidhost_set_info *cmd, uint16_t len)
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_v2 11/11] android/hid: Add send data implemention in daemon
From: Ravi kumar Veeramally @ 2013-11-07 22:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383862220-29968-1-git-send-email-ravikumar.veeramally@linux.intel.com>

Send data on interrupt channel on request from hid host.
---
 android/hidhost.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/android/hidhost.c b/android/hidhost.c
index 4fc8963..945a2dd 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -963,9 +963,43 @@ static uint8_t bt_hid_set_report(struct hal_cmd_hidhost_set_report *cmd,
 static uint8_t bt_hid_send_data(struct hal_cmd_hidhost_send_data *cmd,
 								uint16_t len)
 {
-	DBG("Not Implemented");
+	struct hid_device *dev;
+	GSList *l;
+	bdaddr_t dst;
+	int fd;
+	uint8_t *req;
+	uint8_t req_size;
 
-	return HAL_STATUS_FAILED;
+	DBG("");
+
+	if (len < sizeof(*cmd))
+		return HAL_STATUS_INVALID;
+
+	android2bdaddr(&cmd->bdaddr, &dst);
+
+	l = g_slist_find_custom(devices, &dst, device_cmp);
+	if (!l)
+		return HAL_STATUS_FAILED;
+
+	dev = l->data;
+	req_size = 1 + (cmd->len / 2);
+	req = g_try_malloc0(req_size);
+	if (!req)
+		return HAL_STATUS_NOMEM;
+
+	req[0] = HID_MSG_DATA | HID_DATA_TYPE_OUTPUT;
+	ascii2hex(cmd->data, cmd->len, (req + 1));
+
+	fd = g_io_channel_unix_get_fd(dev->intr_io);
+
+	if (write(fd, req, req_size) < 0) {
+		error("error while sending data to device");
+		g_free(req);
+		return HAL_STATUS_FAILED;
+	}
+
+	g_free(req);
+	return HAL_STATUS_SUCCESS;
 }
 
 void bt_hid_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH_Bluez] gitignore: Add tools/smp-tester to .gitignore
From: Ravi kumar Veeramally @ 2013-11-07 22:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ravi kumar Veeramally

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 4994958..339d37b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,6 +85,7 @@ monitor/btmon
 emulator/btvirt
 emulator/b1ee
 client/bluetoothctl
+tools/smp-tester
 
 src/bluetoothd.8
 src/bluetooth.service
-- 
1.8.3.2


^ permalink raw reply related

* Re: Intel 7260 bluetooth malfunction when it is connected to EHCI bus
From: Hui Wang @ 2013-11-08  1:43 UTC (permalink / raw)
  To: Stevie Trujillo; +Cc: marcel, tedd.an, linux-bluetooth
In-Reply-To: <20131107110719.445e8e6f@localhost>

On 11/07/2013 06:07 PM, Stevie Trujillo wrote:
> On Thu, 07 Nov 2013 11:45:53 +0800
> Hui Wang <hui.wang@canonical.com> wrote:
>
>> Do you know any tools can decode the log generated by usbmon?
> Hmm, I never actually used the usbmon program. I did "modprobe usbmon",
> then Wireshark shows usbmon{1..4} (one for each bus) as an interface
> like eth0 for ethernet. http://wiki.wireshark.org/CaptureSetup/USB
>
> If it's difficult to compare two captures in Wireshark (I don't know any
> other method than visual inspection), tshark (Wireshark's "command-line
> counter-part") is able to decode to stdout. Maybe one can run the diff
> program on that. The output seems a bit terse however.
>
> Please be aware: in my Wireshark (1.10.2) one of the of the SCO setup
> packets are decoded slightly wrong. It looks like Wireshark is missing
> a BDADDR in the beginning, so all the other fields get shifted.
>
>
Thanks for sharing this knowledge, i will have a try according to your 
instructions.

Regards,
Hui.

^ permalink raw reply

* Re: [PATCH_v2 02/11] android/hid: Add a ascii2hex utility
From: Jerzy Kasenberg @ 2013-11-08  6:44 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383862220-29968-3-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi

On 7 November 2013 23:10, Ravi kumar Veeramally
<ravikumar.veeramally@linux.intel.com> wrote:
> Data from few interfaces on HAL is in ascii format but it should be
> in hex format. This conversion utility does that job.
> ---
>  android/Android.mk  |  1 +
>  android/Makefile.am |  2 +-
>  android/utils.c     | 41 +++++++++++++++++++++++++++++++++++++++++
>  android/utils.h     |  3 +++
>  4 files changed, 46 insertions(+), 1 deletion(-)
>  create mode 100644 android/utils.c
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 51037a7..628b2f9 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -27,6 +27,7 @@ LOCAL_SRC_FILES := \
>         ipc.c ipc.h \
>         a2dp.c \
>         pan.c \
> +       utils.c \
>         ../src/log.c \
>         ../src/shared/mgmt.c \
>         ../src/shared/util.c \
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 073edc8..6063a3a 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -9,7 +9,7 @@ noinst_PROGRAMS += android/bluetoothd
>  android_bluetoothd_SOURCES = android/main.c \
>                                 src/log.c \
>                                 android/hal-msg.h \
> -                               android/utils.h \
> +                               android/utils.h android/utils.c \
>                                 src/sdpd-database.c src/sdpd-server.c \
>                                 src/sdpd-service.c src/sdpd-request.c \
>                                 src/glib-helper.h src/glib-helper.c \
> diff --git a/android/utils.c b/android/utils.c
> new file mode 100644
> index 0000000..48d6c38
> --- /dev/null
> +++ b/android/utils.c
> @@ -0,0 +1,41 @@
> +/*
> + *
> + *  BlueZ - Bluetooth protocol stack for Linux
> + *
> + *  Copyright (C) 2013  Intel Corporation. All rights reserved.
> + *
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include "utils.h"
> +
> +void ascii2hex(const uint8_t *ascii, int ascii_len, uint8_t *hex)
> +{
> +       int i;
> +
> +       if (!ascii || !hex)
> +               return;
> +
> +       for (i = 0; i < ascii_len / 2; i++)
> +               sscanf((char *) &ascii[i * 2], "%02x",
> +                                               (unsigned int *) &hex[i]);

Use hh in format instead of cast.

> +
> +}
> diff --git a/android/utils.h b/android/utils.h
> index 5b009bc..d424968 100644
> --- a/android/utils.h
> +++ b/android/utils.h
> @@ -21,6 +21,7 @@
>   *
>   */
>
> +#include "lib/bluetooth.h"
>
>  static inline void android2bdaddr(const void *buf, bdaddr_t *dst)
>  {
> @@ -31,3 +32,5 @@ static inline void bdaddr2android(const bdaddr_t *src, void *buf)
>  {
>         baswap(buf, src);
>  }
> +
> +void ascii2hex(const uint8_t *ascii, int ascii_len, uint8_t *hex);
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Jerzy

^ permalink raw reply

* Re: [PATCH_v2 02/11] android/hid: Add a ascii2hex utility
From: Johan Hedberg @ 2013-11-08  8:10 UTC (permalink / raw)
  To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1383862220-29968-3-git-send-email-ravikumar.veeramally@linux.intel.com>

Hi Ravi,

On Fri, Nov 08, 2013, Ravi kumar Veeramally wrote:
> +++ b/android/utils.c
> @@ -0,0 +1,41 @@
> +/*
> + *
> + *  BlueZ - Bluetooth protocol stack for Linux
> + *
> + *  Copyright (C) 2013  Intel Corporation. All rights reserved.
> + *
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include "utils.h"
> +
> +void ascii2hex(const uint8_t *ascii, int ascii_len, uint8_t *hex)
> +{
> +	int i;
> +
> +	if (!ascii || !hex)
> +		return;
> +
> +	for (i = 0; i < ascii_len / 2; i++)
> +		sscanf((char *) &ascii[i * 2], "%02x",
> +						(unsigned int *) &hex[i]);
> +
> +}

I'd just keep this static inside the HID HAL since that seems to be the
only user for it. Actually I'm not even convinced that it's worth to
have this as a separate function since you only have two users and
essentially the function is just two lines (the if-statement is
redundant). Also, the function name isn't quite right. You're converting
from hex to binary. Not from ascii to hex (hex notation is already using
the ascii character set). Also, do consider the point from Jerzy about
the format specifier.

Johan

^ permalink raw reply


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