* [PATCH 2/2] android/client: Change adapter to bluetooth
From: Jerzy Kasenberg @ 2013-11-05 9:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1383645382-3372-1-git-send-email-jerzy.kasenberg@tieto.com>
This fixes all places where adapter should be changed to
bluetooth.
---
android/client/haltest.c | 6 +++---
android/client/if-main.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/android/client/haltest.c b/android/client/haltest.c
index bbe8693..f511025 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -141,9 +141,9 @@ static void help_p(int argc, const char **argv)
terminal_print("\nTo get help on methods for each interface type:\n");
terminal_print("\n\thelp <inerface>\n");
- terminal_print("\nBasic scenario:\n\tadapter init\n");
- terminal_print("\tadapter enable\n\tadapter start_discovery\n");
- terminal_print("\tadapter get_profile_interface handsfree\n");
+ terminal_print("\nBasic scenario:\n\tbluetooth init\n");
+ terminal_print("\tbluetooth enable\n\tbluetooth start_discovery\n");
+ terminal_print("\tbluetooth get_profile_interface handsfree\n");
terminal_print("\thandsfree init\n\n");
return;
}
diff --git a/android/client/if-main.h b/android/client/if-main.h
index 0c59054..f638b91 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -61,7 +61,7 @@ extern const btgatt_client_interface_t *if_gatt_client;
/*
* Structure defines top level interfaces that can be used in test tool
- * this will contain values as: adapter, av, gatt, sock, pan...
+ * this will contain values as: bluetooth, av, gatt, socket, pan...
*/
struct interface {
const char *name; /* interface name */
--
1.7.9.5
^ permalink raw reply related
* [PATCH] android/daemon: Save adapter name on complete event
From: Andrei Emeltchenko @ 2013-11-05 10:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <CABBYNZKJV-h82WQ5_J3z+ArC3=Gy00qTpKHhWSF7v+fFC7KTrA@mail.gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Saving adapter name was missing from set name complete event.
Refactor code to function and reuse it in both places where
name is changed.
---
android/adapter.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index b6f6096..6b0dc8b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -88,6 +88,17 @@ static void adapter_name_changed(const uint8_t *name)
HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
}
+static void adapter_set_name(const uint8_t *name)
+{
+ if (!g_strcmp0(adapter->name, (const char *) name))
+ return;
+
+ DBG("Cnage name: %s -> %s", adapter->name, name);
+
+ g_free(adapter->name);
+ adapter->name = g_strdup((const char *) name);
+}
+
static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
@@ -98,13 +109,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
return;
}
- if (!g_strcmp0(adapter->name, (const char *) rp->name))
- return;
-
- DBG("name: %s", rp->name);
-
- g_free(adapter->name);
- adapter->name = g_strdup((const char *) rp->name);
+ adapter_set_name(rp->name);
adapter_name_changed(rp->name);
}
@@ -879,6 +884,8 @@ static void set_adapter_name_complete(uint8_t status, uint16_t length,
return;
}
+ adapter_set_name(rp->name);
+
adapter_name_changed(rp->name);
}
--
1.7.10.4
^ permalink raw reply related
* Re: [PATCH] android: Add Android Makefile for btmon
From: Johan Hedberg @ 2013-11-05 10:31 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1383644812-24537-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Nov 05, 2013, Andrei Emeltchenko wrote:
> Build btmon for Android image. btmon requires fresh bionic to build.
> ---
> android/Android.mk | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 0/2] Style, typo and naming fixes
From: Johan Hedberg @ 2013-11-05 10:32 UTC (permalink / raw)
To: Jerzy Kasenberg; +Cc: linux-bluetooth
In-Reply-To: <1383645382-3372-1-git-send-email-jerzy.kasenberg@tieto.com>
Hi Jerzy,
On Tue, Nov 05, 2013, Jerzy Kasenberg wrote:
> This patchset fixes obvious spelling errors.
> It also changes adapter to bluetooth in help and comments.
> Few white space errors also were fixed.
>
> Jerzy Kasenberg (2):
> android/client: Fix style and typos
> android/client: Change adapter to bluetooth
>
> android/client/haltest.c | 6 +++---
> android/client/history.c | 3 +++
> android/client/if-main.h | 2 +-
> android/client/tabcompletion.c | 21 +++++++++++++--------
> android/client/terminal.c | 26 ++++++++++++++------------
> 5 files changed, 34 insertions(+), 24 deletions(-)
Both patches have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 1/6] android: Initial implementation of get_remote_services
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
This patch implements method to retrieve remote device sdp records.
Caching struct is implemented for adding fetched uuids to list.
sdp_req_list will contain list of devices which are asked for records.
Function get_remote_services will check if device is on list, and will
start sdp procedure.
---
android/adapter.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 102 insertions(+), 9 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 929e8cb..027af25 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -35,6 +35,10 @@
#include "src/shared/mgmt.h"
#include "src/glib-helper.h"
#include "src/eir.h"
+#include "lib/sdp.h"
+#include "lib/sdp_lib.h"
+#include "lib/uuid.h"
+#include "src/sdp-client.h"
#include "log.h"
#include "hal-msg.h"
#include "ipc.h"
@@ -45,6 +49,8 @@
#define DEFAULT_IO_CAPABILITY 0x01
static GIOChannel *notification_io = NULL;
+/* This list contains addresses which are asked for records */
+static GSList *sdp_req_list;
struct bt_adapter {
uint16_t index;
@@ -63,6 +69,20 @@ struct bt_adapter {
bool discovering;
};
+struct browse_req {
+ bdaddr_t bdaddr;
+ GSList *uuids;
+ int search_uuid;
+ int reconnect_attempt;
+};
+
+static const uint16_t uuid_list[] = {
+ L2CAP_UUID,
+ PNP_INFO_SVCLASS_ID,
+ PUBLIC_BROWSE_GROUP,
+ 0
+};
+
static struct bt_adapter *adapter;
static GSList *found_devices = NULL;
@@ -257,6 +277,79 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
HAL_EV_BOND_STATE_CHANGED, sizeof(ev), &ev, -1);
}
+static void browse_req_free(struct browse_req *req)
+{
+ g_slist_free_full(req->uuids, g_free);
+ g_free(req);
+}
+
+static void update_records(struct browse_req *req, sdp_list_t *recs)
+{
+ /* TODO cache found uuids */
+}
+
+static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
+{
+ struct browse_req *req = user_data;
+ uuid_t uuid;
+
+ /* If we have a valid response and req->search_uuid == 2, then L2CAP
+ * UUID & PNP searching was successful -- we are done */
+ if (err < 0 || req->search_uuid == 2) {
+ if (err == -ECONNRESET && req->reconnect_attempt < 1) {
+ req->search_uuid--;
+ req->reconnect_attempt++;
+ } else {
+ goto done;
+ }
+ }
+
+ update_records(req, recs);
+
+ /* Search for mandatory uuids */
+ if (uuid_list[req->search_uuid]) {
+ sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
+ bt_search_service(&adapter->bdaddr, &req->bdaddr, &uuid,
+ browse_cb, user_data, NULL);
+ return;
+ }
+
+done:
+ sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
+ browse_req_free(req);
+}
+
+static int bdaddr_cmp(gconstpointer a, gconstpointer b)
+{
+ const bdaddr_t *bda = a;
+ const bdaddr_t *bdb = b;
+
+ return bacmp(bdb, bda);
+}
+
+static bool fetch_remote_uuids(const bdaddr_t *addr)
+{
+ struct browse_req *req;
+ uuid_t uuid;
+
+ if (g_slist_find_custom(sdp_req_list, addr, bdaddr_cmp))
+ return false;
+
+ req = g_new0(struct browse_req, 1);
+ bacpy(&req->bdaddr, addr);
+ sdp_req_list = g_slist_append(sdp_req_list, &req->bdaddr);
+ sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
+
+ if (bt_search_service(&adapter->bdaddr,
+ &req->bdaddr, &uuid, browse_cb, req, NULL) < 0) {
+ sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
+ browse_req_free(req);
+ return false;
+ }
+
+ return true;
+}
+
static void new_link_key_callback(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
@@ -445,14 +538,6 @@ static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type)
error("Failed to send confirm name request");
}
-static int bdaddr_cmp(gconstpointer a, gconstpointer b)
-{
- const bdaddr_t *bda = a;
- const bdaddr_t *bdb = b;
-
- return bacmp(bdb, bda);
-}
-
static int fill_device_props(struct hal_property *prop, bdaddr_t *addr,
uint32_t cod, int8_t rssi, char *name)
{
@@ -1477,7 +1562,15 @@ static uint8_t ssp_reply(void *buf, uint16_t len)
static uint8_t get_remote_services(void *buf, uint16_t len)
{
- return HAL_STATUS_UNSUPPORTED;
+ struct hal_cmd_get_remote_services *cmd = buf;
+ bool ret;
+ bdaddr_t addr;
+
+ android2bdaddr(&cmd->bdaddr, &addr);
+
+ ret = fetch_remote_uuids(&addr);
+
+ return ret ? HAL_STATUS_SUCCESS : HAL_STATUS_FAILED;
}
void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
--
1.8.4.1
^ permalink raw reply related
* [PATCH 2/6] android: Fetch remote device uuids after pairing
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
Android framework expects list of bonded device's uuids.
Start sdp query after setting bond state to BOND_STATE_BONBED.
---
android/adapter.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 027af25..692ffe4 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -382,6 +382,8 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
send_bond_state_change(&addr->bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDED);
+
+ fetch_remote_uuids(&addr->bdaddr);
}
static void pin_code_request_callback(uint16_t index, uint16_t length,
--
1.8.4.1
^ permalink raw reply related
* [PATCH 3/6] android: Pass found uuids to remote_device_properties_cb
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
Send remote device's uuids in remote_device_properties_cb.
This patch will pack found uuids to buffer containing property
with list of uuids and send it to notification socket.
---
android/adapter.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 1 deletion(-)
diff --git a/android/adapter.c b/android/adapter.c
index 692ffe4..64f0192 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -283,9 +283,87 @@ static void browse_req_free(struct browse_req *req)
g_free(req);
}
+static void fill_uuids(GSList *list, void *buf)
+{
+ for (; list; list = g_slist_next(list)) {
+ memcpy(buf, list->data, sizeof(uint128_t));
+ buf += sizeof(uint128_t);
+ }
+}
+
+static void remote_uuids_callback(struct browse_req *req)
+{
+ struct hal_ev_remote_device_props *ev;
+ int len;
+
+ len = sizeof(*ev) + sizeof(struct hal_property) + (sizeof(uint128_t) *
+ g_slist_length(req->uuids));
+ ev = g_malloc(len);
+
+ ev->status = HAL_STATUS_SUCCESS;
+ bdaddr2android(&req->bdaddr, &ev->bdaddr);
+ ev->num_props = 1;
+ ev->props[0].type = HAL_PROP_DEVICE_UUIDS;
+ ev->props[0].len = sizeof(uint128_t) * g_slist_length(req->uuids);
+ fill_uuids(req->uuids, ev->props[0].val);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_REMOTE_DEVICE_PROPS, len, ev, -1);
+
+ g_free(ev);
+}
+
+static int uuid_128_cmp(gconstpointer a, gconstpointer b)
+{
+ return memcmp(a, b, sizeof(uint128_t));
+}
+
static void update_records(struct browse_req *req, sdp_list_t *recs)
{
- /* TODO cache found uuids */
+ for (; recs; recs = recs->next) {
+ sdp_record_t *rec = (sdp_record_t *) recs->data;
+ sdp_list_t *svcclass = NULL;
+ uuid_t uuid128;
+ uuid_t *tmp;
+ uint8_t *new_uuid;
+
+ if (!rec)
+ break;
+
+ if (sdp_get_service_classes(rec, &svcclass) < 0)
+ continue;
+
+ if (!svcclass)
+ continue;
+
+ tmp = svcclass->data;
+
+ switch (tmp->type) {
+ case SDP_UUID16:
+ sdp_uuid16_to_uuid128(&uuid128, tmp);
+ break;
+ case SDP_UUID32:
+ sdp_uuid32_to_uuid128(&uuid128, tmp);
+ break;
+ case SDP_UUID128:
+ memcpy(&uuid128, tmp, sizeof(uuid_t));
+ break;
+ default:
+ continue;
+ }
+
+ new_uuid = g_malloc(16);/* size of 128 bit uuid */
+ memcpy(new_uuid, &uuid128.value.uuid128,
+ sizeof(uuid128.value.uuid128));
+
+ /* Check if uuid is already added */
+ if (g_slist_find_custom(req->uuids, new_uuid, uuid_128_cmp))
+ g_free(new_uuid);
+ else
+ req->uuids = g_slist_append(req->uuids, new_uuid);
+
+ sdp_list_free(svcclass, free);
+ }
}
static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
@@ -315,6 +393,8 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
}
done:
+ remote_uuids_callback(req);
+
sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
browse_req_free(req);
}
--
1.8.4.1
^ permalink raw reply related
* [PATCH 4/6] android: Add supported uuids when adapter is initialized
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
It will set class of device with proper service hints.
We set it statically because we want to keep code simple.
---
android/adapter.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 64f0192..d791450 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -52,6 +52,29 @@ static GIOChannel *notification_io = NULL;
/* This list contains addresses which are asked for records */
static GSList *sdp_req_list;
+/*
+ * This is an array of supported uuids and service hints. We add them via mgmt
+ * interface when adapter is initialized. Uuids are in reverse orded.
+ */
+static const struct mgmt_cp_add_uuid supported_services[] = {
+ /* OBEX_OPP_UUID */
+ { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+ 0x00, 0x10, 0x00, 0x00, 0x05, 0x11, 0x00, 0x00 },
+ .svc_hint = 0x10 },
+ /* HFP_AG_UUID */
+ { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+ 0x00, 0x10, 0x00, 0x00, 0x1f, 0x11, 0x00, 0x00 },
+ .svc_hint = 0x40 },
+ /* ADVANCED_AUDIO_UUID */
+ { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+ 0x00, 0x10, 0x00, 0x00, 0x0d, 0x11, 0x00, 0x00 },
+ .svc_hint = 0x08 },
+ /* PANU_UUID */
+ { .uuid = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
+ 0x00, 0x10, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00 },
+ .svc_hint = 0x02 }
+};
+
struct bt_adapter {
uint16_t index;
struct mgmt *mgmt;
@@ -967,6 +990,39 @@ static void load_link_keys(GSList *keys)
}
}
+static void add_uuid_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ error("Failed to add UUID: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void add_uuids(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < NELEM(supported_services); i++)
+ mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID, adapter->index,
+ sizeof(supported_services[i]),
+ &supported_services[i], add_uuid_complete,
+ NULL, NULL);
+}
+
+static void clear_uuids(void)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ memset(&cp, 0, sizeof(cp));
+
+ mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID, adapter->index,
+ sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
static void set_mode_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -982,6 +1038,9 @@ static void set_mode_complete(uint8_t status, uint16_t length,
* event handling functions here.
*/
new_settings_callback(adapter->index, length, param, NULL);
+
+ clear_uuids();
+ add_uuids();
}
static bool set_mode(uint16_t opcode, uint8_t mode)
--
1.8.4.1
^ permalink raw reply related
* Re: [PATCH] android/daemon: Save adapter name on complete event
From: Johan Hedberg @ 2013-11-05 10:33 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1383646128-8077-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Nov 05, 2013, Andrei Emeltchenko wrote:
> Saving adapter name was missing from set name complete event.
> Refactor code to function and reuse it in both places where
> name is changed.
> ---
> android/adapter.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* [PATCH 5/6] android: Implement class of device property callback
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
This will send adapter property with class of device
to notification socket.
---
android/adapter.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index d791450..523209e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -185,6 +185,30 @@ static void scan_mode_changed(void)
g_free(ev);
}
+static void send_adapter_class(void)
+{
+ struct hal_ev_adapter_props_changed *ev;
+ int len;
+
+ len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(uint32_t);
+
+ ev = g_malloc(len);
+
+ ev->num_props = 1;
+ ev->status = HAL_STATUS_SUCCESS;
+
+ ev->props[0].type = HAL_PROP_ADAPTER_CLASS;
+ ev->props[0].len = sizeof(uint32_t);
+ memcpy(ev->props->val, &adapter->dev_class, sizeof(uint32_t));
+
+ DBG("Adapter class %u", adapter->dev_class);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+ g_free(ev);
+}
+
static void adapter_name_changed(const uint8_t *name)
{
struct hal_ev_adapter_props_changed *ev;
@@ -275,7 +299,7 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
adapter->dev_class = dev_class;
- /* TODO: Inform prop change: Class */
+ send_adapter_class();
/* TODO: Gatt attrib set*/
}
@@ -1265,11 +1289,11 @@ static bool get_uuids(void)
static bool get_class(void)
{
- DBG("Not implemented");
+ DBG("");
- /* TODO: Add implementation */
+ send_adapter_class();
- return false;
+ return true;
}
static bool get_type(void)
--
1.8.4.1
^ permalink raw reply related
* [PATCH 6/6] android: Add support for getting adapter uuids
From: Marcin Kraglak @ 2013-11-05 10:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
Implement get adapter uuids command. It will pack supported
uuids to structure and send it via notification socket
---
android/adapter.c | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 523209e..483bb1c 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1278,13 +1278,47 @@ static bool get_name(void)
return true;
}
+static void swap_uuid(const uint8_t *src, uint8_t *dst)
+{
+ int i;
+
+ for (i = 0; i < 16; i++)
+ dst[15 - i] = src[i];
+}
+
static bool get_uuids(void)
{
- DBG("Not implemented");
+ struct hal_ev_adapter_props_changed *ev;
+ unsigned int i;
+ int len;
+ uint8_t *p;
- /* TODO: Add implementation */
+ len = sizeof(*ev) + sizeof(struct hal_property) +
+ NELEM(supported_services) * sizeof(uint128_t);
- return false;
+ ev = g_malloc(len);
+
+ ev->num_props = 1;
+ ev->status = HAL_STATUS_SUCCESS;
+
+ ev->props[0].type = HAL_PROP_ADAPTER_UUIDS;
+ ev->props[0].len = sizeof(uint128_t) * NELEM(supported_services);
+ p = ev->props->val;
+
+ for (i = 0; i < NELEM(supported_services); i++) {
+ /* we have to swap supported uuids
+ * because hal expects them in reversed order
+ * than mgmt intrface */
+ swap_uuid(supported_services[i].uuid, p);
+ p += sizeof(uint128_t);
+ }
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+ g_free(ev);
+
+ return true;
}
static bool get_class(void)
--
1.8.4.1
^ permalink raw reply related
* [PATCH] android: Suppress compiler warnings not enabled by autotools build
From: Szymon Janc @ 2013-11-05 10:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
missing-field-initializers warning is not enabled on autotools build.
Current code rely on implicit fields intializations resulting in flood
of bogus compiler warnings while building for Android.
monitor/packet.c:348:2: warning: missing initializer
[-Wmissing-field-initializers]
monitor/packet.c:348:2: warning: (near initialization for
'error2str_table[64].error') [-Wmissing-field-initializers]
monitor/packet.c:542:2: warning: missing initializer
[-Wmissing-field-initializers]
monitor/packet.c:542:2: warning: (near initialization for
'svc_class_table[8].bit') [-Wmissing-field-initializers]
monitor/packet.c:557:2: warning: missing initializer
[-Wmissing-field-initializers]
monitor/packet.c:557:2: warning: (near initialization for
'major_class_computer_table[8].val') [-Wmissing-field-initializers]
---
android/Android.mk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/Android.mk b/android/Android.mk
index 86af7b6..d76dfaf 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -11,7 +11,7 @@ BLUEZ_COMMON_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\" \
-DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
# Disable warnings enabled by Android but not enabled in autotools build
-BLUEZ_COMMON_CFLAGS += -Wno-pointer-arith
+BLUEZ_COMMON_CFLAGS += -Wno-pointer-arith -Wno-missing-field-initializers
#
# Android BlueZ daemon (bluetoothd)
--
1.8.4.1
^ permalink raw reply related
* Re: [PATCH 1/6] android: Initial implementation of get_remote_services
From: Johan Hedberg @ 2013-11-05 10:57 UTC (permalink / raw)
To: Marcin Kraglak; +Cc: linux-bluetooth
In-Reply-To: <1383647613-14951-1-git-send-email-marcin.kraglak@tieto.com>
Hi Marcin,
On Tue, Nov 05, 2013, Marcin Kraglak wrote:
> +static int bdaddr_cmp(gconstpointer a, gconstpointer b)
> +{
> + const bdaddr_t *bda = a;
> + const bdaddr_t *bdb = b;
> +
> + return bacmp(bdb, bda);
> +}
> +
> +static bool fetch_remote_uuids(const bdaddr_t *addr)
> +{
> + struct browse_req *req;
> + uuid_t uuid;
> +
> + if (g_slist_find_custom(sdp_req_list, addr, bdaddr_cmp))
> + return false;
> +
> + req = g_new0(struct browse_req, 1);
> + bacpy(&req->bdaddr, addr);
> + sdp_req_list = g_slist_append(sdp_req_list, &req->bdaddr);
This is quite wild coding, having a list with pointers into the middle
of a struct instead of the struct itself. To avoid having to twist ones
brain around to figure out correctness, could you just store the request
pointers in this list and then modify your bdaddr_cmp function to
compare a struct browse_req against a bdaddr_t pointer instead of
comparing two bdaddr pointers. You'll probably want to rename it to
req_cmp or something similar then though.
> + sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
> +
> + if (bt_search_service(&adapter->bdaddr,
> + &req->bdaddr, &uuid, browse_cb, req, NULL) < 0) {
> + sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
> + browse_req_free(req);
Instead of having to do an extra g_slist_remove here why not just add
the entry to the sdp_req_list only after bt_search_service has been
successful?
Also, how about renaming sdp_req_list to browse_req_list to match the
name you've chosen for the context struct? Or maybe even simpler as
"browse_reqs"
> static uint8_t get_remote_services(void *buf, uint16_t len)
> {
> - return HAL_STATUS_UNSUPPORTED;
> + struct hal_cmd_get_remote_services *cmd = buf;
> + bool ret;
> + bdaddr_t addr;
> +
> + android2bdaddr(&cmd->bdaddr, &addr);
> +
> + ret = fetch_remote_uuids(&addr);
> +
> + return ret ? HAL_STATUS_SUCCESS : HAL_STATUS_FAILED;
> }
How about just making fetch_remote_uuids() return a proper HAL status
directly instead of this mapping of bool to HAL status? You could also
just consider merging the entire fetch_remote_uuids function (whose name
I don't really like btw) into this get_remote_services function,
especially if you don't foresee it having any other callers in the
future.
Johan
^ permalink raw reply
* Re: [PATCH] android: Suppress compiler warnings not enabled by autotools build
From: Johan Hedberg @ 2013-11-05 11:04 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1383648613-21352-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Tue, Nov 05, 2013, Szymon Janc wrote:
> missing-field-initializers warning is not enabled on autotools build.
> Current code rely on implicit fields intializations resulting in flood
> of bogus compiler warnings while building for Android.
>
> monitor/packet.c:348:2: warning: missing initializer
> [-Wmissing-field-initializers]
> monitor/packet.c:348:2: warning: (near initialization for
> 'error2str_table[64].error') [-Wmissing-field-initializers]
> monitor/packet.c:542:2: warning: missing initializer
> [-Wmissing-field-initializers]
> monitor/packet.c:542:2: warning: (near initialization for
> 'svc_class_table[8].bit') [-Wmissing-field-initializers]
> monitor/packet.c:557:2: warning: missing initializer
> [-Wmissing-field-initializers]
> monitor/packet.c:557:2: warning: (near initialization for
> 'major_class_computer_table[8].val') [-Wmissing-field-initializers]
> ---
> android/Android.mk | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH 1/6] android: Initial implementation of get_remote_services
From: Marcin Kraglak @ 2013-11-05 11:05 UTC (permalink / raw)
To: Marcin Kraglak, linux-bluetooth
In-Reply-To: <20131105105732.GA8164@x220.p-661hnu-f1>
Hi Johan,
On 5 November 2013 11:57, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Hi Marcin,
>
> On Tue, Nov 05, 2013, Marcin Kraglak wrote:
>> +static int bdaddr_cmp(gconstpointer a, gconstpointer b)
>> +{
>> + const bdaddr_t *bda = a;
>> + const bdaddr_t *bdb = b;
>> +
>> + return bacmp(bdb, bda);
>> +}
>> +
>> +static bool fetch_remote_uuids(const bdaddr_t *addr)
>> +{
>> + struct browse_req *req;
>> + uuid_t uuid;
>> +
>> + if (g_slist_find_custom(sdp_req_list, addr, bdaddr_cmp))
>> + return false;
>> +
>> + req = g_new0(struct browse_req, 1);
>> + bacpy(&req->bdaddr, addr);
>> + sdp_req_list = g_slist_append(sdp_req_list, &req->bdaddr);
>
> This is quite wild coding, having a list with pointers into the middle
> of a struct instead of the struct itself. To avoid having to twist ones
> brain around to figure out correctness, could you just store the request
> pointers in this list and then modify your bdaddr_cmp function to
> compare a struct browse_req against a bdaddr_t pointer instead of
> comparing two bdaddr pointers. You'll probably want to rename it to
> req_cmp or something similar then though.
Ok, I'll change it, it will be more readable.
>
>> + sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
>> +
>> + if (bt_search_service(&adapter->bdaddr,
>> + &req->bdaddr, &uuid, browse_cb, req, NULL) < 0) {
>> + sdp_req_list = g_slist_remove(sdp_req_list, &req->bdaddr);
>> + browse_req_free(req);
>
> Instead of having to do an extra g_slist_remove here why not just add
> the entry to the sdp_req_list only after bt_search_service has been
> successful?
>
> Also, how about renaming sdp_req_list to browse_req_list to match the
> name you've chosen for the context struct? Or maybe even simpler as
> "browse_reqs"
I agree.
>
>> static uint8_t get_remote_services(void *buf, uint16_t len)
>> {
>> - return HAL_STATUS_UNSUPPORTED;
>> + struct hal_cmd_get_remote_services *cmd = buf;
>> + bool ret;
>> + bdaddr_t addr;
>> +
>> + android2bdaddr(&cmd->bdaddr, &addr);
>> +
>> + ret = fetch_remote_uuids(&addr);
>> +
>> + return ret ? HAL_STATUS_SUCCESS : HAL_STATUS_FAILED;
>> }
>
> How about just making fetch_remote_uuids() return a proper HAL status
> directly instead of this mapping of bool to HAL status? You could also
> just consider merging the entire fetch_remote_uuids function (whose name
> I don't really like btw) into this get_remote_services function,
> especially if you don't foresee it having any other callers in the
> future.
I realized it in previous version, but fetch_remote_uuids will be called in
other places too (see next patches).
>
> Johan
BR
Marcin
^ permalink raw reply
* Re: Wireshark and new BlueZ BTSNOOP format
From: Michal Labedzki @ 2013-11-05 11:37 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <AF259BFC-2022-4280-9F98-D4679A280A84@holtmann.org>
On 4 November 2013 15:40, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Michal,
>
>> There is a need to add support for latest BTSNOOP format currently
>> used in BlueZ (5). I have two questions:
>>
>> 1. Is BlueZ btsnoop format official and stable? Or invented by BlueZ
>> team? (stable? safe?)
>
> the original btsnoop format was done by Symbian and adopted by Frontline.=
We started using that as well since it was better than what we had before.=
These are the ones with 1xxx link types.
> With BlueZ 5 and kernels 3.5 and newer we introduced a Bluetooth monitor =
to the kernel that can catch all controllers and can catch early messages a=
s well. Previous hcidump could only read one interface at a time and was no=
t able to catch early init frames.
>
> The link type 2001 is stable.
Regarding "all controllers and catch early messages" - if you use
Bluetooth USB dongle than this is not a problem, because
Wireshark/libpcap can live capture USB stream. There is ready HCI USB
transport described in Bluetooth Core specification. Try Wireshark >=3D
1.10 and filter by "hci_usb" . Only non-standard Bluetooth USB dongles
cannot work with it (however I have non-standard dongle "Broadcom
Corp. BCM20702A0 Bluetooth 4.0", but it seems to be standard dongle -
only it present itself as "vendor specific").
Quick Howto:
1. [Recommended] Latest Wireshark
2. [Recommended] Latest libpcap.
3. lsusb # to detect on which "Bus" Bluetooth dongle is connected
4. wireshark and select usbmonN, where N is "Bus" ID.
5. Filter "hci_usb" (useful if more devices connected to this Bus)
>> 2. Is there any documentation describes this format?
>
> It is documented inside the kernel as include/net/bluetooth/hci_mon.h and=
that is as close as it gets to documentation. btsnoop v2 takes the BTSnoop=
header and uses the 2001 link type and then encodes the opcode and index i=
nto the flags field. The frame data is always a raw HCI message similar to =
link type 1001.
Ok, I assume there is no real specification. This is not a problem for me.
>> In code I saw two new magic numbers:
>> 2001 Bluetooth monitor
>> 2002 Bluetooth simulator
>> Is Bluetooth simulator completed now?
>
> The simulator is a low-level Low Energy Link Layer simulator. And it is n=
ot completed and not stable yet.
Please let me know if will be completed or dropped. Or please create
feature request on Wireshark Bugzilla:
https://bugs.wireshark.org/bugzilla/buglist.cgi?resolution=3D---&query_form=
at=3Dadvanced&list_id=3D11093
>> For now Wireshark (>=3D 1.10, trunk is recommended) provide probably
>> full Bluetooth support, all protocols, colours, filtering,
>> reassembling. If you find a bug or need new feature please create a
>> bug at https://bugs.wireshark.org/bugzilla/buglist.cgi?resolution=3D---&=
query_format=3Dadvanced&list_id=3D11093
>
> What also would be interesting is an integration of Bluetooth monitor soc=
ket with libpcap so Wireshark can do live capture.
>
> Regards
>
> Marcel
>
For now Wireshark can support live capture on old kernel interface (if
you do not see Bluetooth interfaces than you need newer libpcap). Also
you can choose more than one interface to capture: for example
Bluetooth0, Bluetooth1 and usbmon1 (nice duplicated streams do you
see)
I will try to add support for new BTSNOOP format and libpcap support
for new kernel. I think Wireshark can be useful for BlueZ and Android
developers.
--=20
Pozdrawiam / Best regards
---------------------------------------------------------------------------=
----------------------------------
Micha=C5=82 =C5=81ab=C4=99dzki, Software Engineer
Tieto Corporation
Product Development Services
http://www.tieto.com / http://www.tieto.pl
---
ASCII: Michal Labedzki
location: Swobodna 1 Street, 50-088 Wroc=C5=82aw, Poland
room: 5.01 (desk next to 5.08)
---
Please note: The information contained in this message may be legally
privileged and confidential and protected from disclosure. If the
reader of this message is not the intended recipient, you are hereby
notified that any unauthorised use, distribution or copying of this
communication is strictly prohibited. If you have received this
communication in error, please notify us immediately by replying to
the message and deleting it from your computer. Thank You.
---
Please consider the environment before printing this e-mail.
---
Tieto Poland sp=C3=B3=C5=82ka z ograniczon=C4=85 odpowiedzialno=C5=9Bci=C4=
=85 z siedzib=C4=85 w
Szczecinie, ul. Malczewskiego 26. Zarejestrowana w S=C4=85dzie Rejonowym
Szczecin-Centrum w Szczecinie, XIII Wydzia=C5=82 Gospodarczy Krajowego
Rejestru S=C4=85dowego pod numerem 0000124858. NIP: 8542085557. REGON:
812023656. Kapita=C5=82 zak=C5=82adowy: 4 271500 PLN
^ permalink raw reply
* [PATCH_v2 00/13] Implemented hid interfaces in daemon and hal
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
v2: Fixed Johan's comments (splitting of patches, proper function and
struct names, update hal-msg.h and ipc document, alignment issues
removed pointer from ipc struct)
v1: This patch set implements get/set protocol and get/set report
interfaces and supported functionality in daemon. Sending notifications
and notification handling in hal. Few naming fixes and error handling.
And last handling of few uHID events.
Ravi kumar Veeramally (13):
android/hid: Add hid event proto mode structure to hal msg headers
android/hid: Implement hid get protocol in daemon
android/hid: Implement hid set protocol in daemon
android/hid: Handle protocol mode notification in hal
android/hid: Add hid event get report structure to hal msg headers
android/hid: Implement hid get report in daemon
android/hid: Add missing set report parameters to ipc document
android/hid: Implement hid set report in daemon
android/hid: Handle get report notification in hal
android/hid: Replace header checking magic number with defines
android/hid: Handle invalid parameters in hal
android/hid: Handle uhid events
android/hid: Align hal hid struct variables properly
android/hal-hidhost.c | 41 +++++-
android/hal-ipc-api.txt | 4 +-
android/hal-msg.h | 41 ++++--
android/hid.c | 329 ++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 385 insertions(+), 30 deletions(-)
--
1.8.1.2
^ permalink raw reply
* [PATCH_v2 01/13] android/hid: Add hid event proto mode structure to hal msg headers
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-msg.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index f381862..5faf852 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -442,6 +442,8 @@ struct hal_ev_hid_conn_state {
uint8_t state;
} __attribute__((packed));
+#define HAL_HID_STATUS_OK 0x00
+
#define HAL_EV_HID_INFO 0x82
struct hal_ev_hid_info {
uint8_t bdaddr[6];
@@ -456,6 +458,13 @@ struct hal_ev_hid_info {
uint8_t descr[884];
} __attribute__((packed));
+#define HAL_EV_HID_PROTO_MODE 0x83
+struct hal_ev_hid_proto_mode {
+ uint8_t bdaddr[6];
+ uint8_t status;
+ uint8_t mode;
+} __attribute__((packed));
+
#define HAL_EV_AV_CONNECTION_STATE 0x81
struct hal_ev_av_connection_state {
uint8_t state;
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 02/13] android/hid: Implement hid get protocol in daemon
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
This patch requests hid device protocol mode and reads reply
message and sends notification to hal.
---
android/hid.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 104 insertions(+), 4 deletions(-)
diff --git a/android/hid.c b/android/hid.c
index c0c9aeb..97835d9 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -54,6 +54,14 @@
#define L2CAP_PSM_HIDP_INTR 0x13
#define UHID_DEVICE_FILE "/dev/uhid"
+/* HID message types */
+#define HID_MSG_GET_PROTOCOL 0x60
+#define HID_MSG_DATA 0xa0
+
+/* HID protocol header parameters */
+#define HID_PROTO_BOOT 0x00
+#define HID_PROTO_REPORT 0x01
+
static GIOChannel *notification_io = NULL;
static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
@@ -76,6 +84,7 @@ struct hid_device {
guint intr_watch;
int uhid_fd;
guint uhid_watch_id;
+ int hid_msg;
};
static int device_cmp(gconstpointer s, gconstpointer user_data)
@@ -243,12 +252,74 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
return FALSE;
}
+static void bt_hid_notify_proto_mode(struct hid_device *dev, uint8_t *buf,
+ int len)
+{
+ struct hal_ev_hid_proto_mode ev;
+ char address[18];
+
+ ba2str(&dev->dst, address);
+ DBG("device %s", address);
+
+ memset(&ev, 0, sizeof(ev));
+ bdaddr2android(&dev->dst, ev.bdaddr);
+
+ if (buf[0] == HID_MSG_DATA) {
+ ev.status = HAL_HID_STATUS_OK;
+ if (buf[1] == HID_PROTO_REPORT)
+ ev.mode = HAL_HID_REPORT_PROTOCOL;
+ else if (buf[1] == HID_PROTO_BOOT)
+ ev.mode = HAL_HID_BOOT_PROTOCOL;
+ else
+ ev.mode = HAL_HID_UNSUPPORTED_PROTOCOL;
+
+ } else {
+ ev.status = buf[0];
+ ev.mode = HAL_HID_UNSUPPORTED_PROTOCOL;
+ }
+
+ ipc_send(notification_io, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HID_PROTO_MODE, sizeof(ev), &ev, -1);
+}
+
+static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
+{
+ struct hid_device *dev = data;
+ int fd, bread;
+ uint8_t buf[UHID_DATA_MAX];
+
+ DBG("");
+
+ fd = g_io_channel_unix_get_fd(chan);
+ bread = read(fd, buf, sizeof(buf));
+ if (bread < 0) {
+ error("read: %s(%d)", strerror(errno), -errno);
+ return TRUE;
+ }
+
+ switch (dev->hid_msg) {
+ case HID_MSG_GET_PROTOCOL:
+ bt_hid_notify_proto_mode(dev, buf, bread);
+ break;
+ default:
+ DBG("unhandled hid msg type 0x%02x", dev->hid_msg);
+ }
+
+ /* reset msg type request */
+ dev->hid_msg = -1;
+
+ return TRUE;
+}
+
static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
struct hid_device *dev = data;
char address[18];
+ if (cond & G_IO_IN)
+ return ctrl_io_watch_cb(chan, data);
+
ba2str(&dev->dst, address);
bt_hid_notify_state(dev, HAL_HID_STATE_DISCONNECTED);
@@ -395,8 +466,8 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
}
dev->ctrl_watch = g_io_add_watch(dev->ctrl_io,
- G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- ctrl_watch_cb, dev);
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ ctrl_watch_cb, dev);
return;
@@ -591,9 +662,38 @@ static uint8_t bt_hid_info(struct hal_cmd_hid_set_info *cmd, uint16_t len)
static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ int fd;
+ uint8_t hdr[1];
- 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;
+
+ if (dev->boot_dev)
+ return HAL_STATUS_UNSUPPORTED;
+
+ dev->hid_msg = HID_MSG_GET_PROTOCOL;
+ hdr[0] = HID_MSG_GET_PROTOCOL | cmd->mode;
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, hdr, sizeof(hdr)) < 0) {
+ error("error while querying device protocol");
+ return HAL_STATUS_FAILED;
+ }
+
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 03/13] android/hid: Implement hid set protocol in daemon
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
This patch requests hid device to set protocol mode and reads
reply message and sends notification to hal.
---
android/hid.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/android/hid.c b/android/hid.c
index 97835d9..d387d6d 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -56,6 +56,7 @@
/* HID message types */
#define HID_MSG_GET_PROTOCOL 0x60
+#define HID_MSG_SET_PROTOCOL 0x70
#define HID_MSG_DATA 0xa0
/* HID protocol header parameters */
@@ -299,6 +300,7 @@ static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
switch (dev->hid_msg) {
case HID_MSG_GET_PROTOCOL:
+ case HID_MSG_SET_PROTOCOL:
bt_hid_notify_proto_mode(dev, buf, bread);
break;
default:
@@ -699,9 +701,38 @@ static uint8_t bt_hid_get_protocol(struct hal_cmd_hid_get_protocol *cmd,
static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
uint16_t len)
{
- DBG("Not Implemented");
+ struct hid_device *dev;
+ GSList *l;
+ bdaddr_t dst;
+ int fd;
+ uint8_t hdr[1];
- 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;
+
+ if (dev->boot_dev)
+ return HAL_STATUS_UNSUPPORTED;
+
+ dev->hid_msg = HID_MSG_SET_PROTOCOL;
+ hdr[0] = HID_MSG_SET_PROTOCOL | cmd->mode;
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, hdr, sizeof(hdr)) < 0) {
+ error("error while setting device protocol");
+ return HAL_STATUS_FAILED;
+ }
+
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd,
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 04/13] android/hid: Handle protocol mode notification in hal
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-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 c20c785..13928e6 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -59,6 +59,15 @@ static void handle_info(void *buf)
bt_hh_cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
}
+static void handle_proto_mode(void *buf)
+{
+ struct hal_ev_hid_proto_mode *ev = buf;
+
+ if (bt_hh_cbacks->protocol_mode_cb)
+ bt_hh_cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
+ ev->status, ev->mode);
+}
+
/* will be called from notification thread context */
void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
{
@@ -72,6 +81,9 @@ void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_HID_INFO:
handle_info(buf);
break;
+ case HAL_EV_HID_PROTO_MODE:
+ handle_proto_mode(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 05/13] android/hid: Add hid event get report structure to hal msg headers
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
---
android/hal-msg.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 5faf852..bc7df6b 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -465,6 +465,14 @@ struct hal_ev_hid_proto_mode {
uint8_t mode;
} __attribute__((packed));
+#define HAL_EV_HID_GET_REPORT 0x85
+struct hal_ev_hid_get_report {
+ uint8_t bdaddr[6];
+ uint8_t status;
+ uint16_t len;
+ uint8_t data[0];
+} __attribute__((packed));
+
#define HAL_EV_AV_CONNECTION_STATE 0x81
struct hal_ev_av_connection_state {
uint8_t state;
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 06/13] android/hid: Implement hid get report in daemon
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
This patch requests hid device report and reads reply
message and sends notification to hal.
---
android/hal-hidhost.c | 1 +
android/hid.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 103 insertions(+), 2 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 13928e6..f554cb2 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -251,6 +251,7 @@ static bt_status_t hh_get_report(bt_bdaddr_t *bd_addr,
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
cmd.id = reportId;
+ cmd.buf = bufferSize;
switch (reportType) {
case BTHH_INPUT_REPORT:
diff --git a/android/hid.c b/android/hid.c
index d387d6d..f1bf9e8 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -55,14 +55,23 @@
#define UHID_DEVICE_FILE "/dev/uhid"
/* HID message types */
+#define HID_MSG_GET_REPORT 0x40
#define HID_MSG_GET_PROTOCOL 0x60
#define HID_MSG_SET_PROTOCOL 0x70
#define HID_MSG_DATA 0xa0
+/* HID data types */
+#define HID_DATA_TYPE_INPUT 0x01
+#define HID_DATA_TYPE_OUTPUT 0x02
+#define HID_DATA_TYPE_FEATURE 0x03
+
/* HID protocol header parameters */
#define HID_PROTO_BOOT 0x00
#define HID_PROTO_REPORT 0x01
+/* HID GET REPORT Size Field */
+#define HID_GET_REPORT_SIZE_FIELD 0x08
+
static GIOChannel *notification_io = NULL;
static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
@@ -283,6 +292,52 @@ static void bt_hid_notify_proto_mode(struct hid_device *dev, uint8_t *buf,
HAL_EV_HID_PROTO_MODE, sizeof(ev), &ev, -1);
}
+static void bt_hid_notify_get_report(struct hid_device *dev, uint8_t *buf,
+ int len)
+{
+ struct hal_ev_hid_get_report *ev;
+ int ev_len;
+ char address[18];
+
+ ba2str(&dev->dst, address);
+ DBG("device %s", address);
+
+ ev_len = sizeof(*ev) + sizeof(struct hal_ev_hid_get_report) + 1;
+
+ if (!((buf[0] == (HID_MSG_DATA | HID_DATA_TYPE_INPUT)) ||
+ (buf[0] == (HID_MSG_DATA | HID_DATA_TYPE_OUTPUT)) ||
+ (buf[0] == (HID_MSG_DATA | HID_DATA_TYPE_FEATURE)))) {
+ ev = g_malloc(len);
+ memset(ev, 0, ev_len);
+ ev->status = buf[0];
+ bdaddr2android(&dev->dst, ev->bdaddr);
+ goto send;
+ }
+
+ /* Report porotocol mode reply contains id after hdr, in boot
+ * protocol mode id doesn't exist */
+ ev_len += (dev->boot_dev) ? (len - 1) : (len - 2);
+ ev = g_malloc(ev_len);
+ memset(ev, 0, ev_len);
+ ev->status = HAL_HID_STATUS_OK;
+ bdaddr2android(&dev->dst, ev->bdaddr);
+
+ /* Report porotocol mode reply contains id after hdr, in boot
+ * protocol mode id doesn't exist */
+ if (dev->boot_dev) {
+ ev->len = len - 1;
+ memcpy(ev->data, buf + 1, ev->len);
+ } else {
+ ev->len = len - 2;
+ memcpy(ev->data, buf + 2, ev->len);
+ }
+
+send:
+ ipc_send(notification_io, HAL_SERVICE_ID_HIDHOST, HAL_EV_HID_GET_REPORT,
+ ev_len, ev, -1);
+ g_free(ev);
+}
+
static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
{
struct hid_device *dev = data;
@@ -303,6 +358,9 @@ static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
case HID_MSG_SET_PROTOCOL:
bt_hid_notify_proto_mode(dev, buf, bread);
break;
+ case HID_MSG_GET_REPORT:
+ bt_hid_notify_get_report(dev, buf, bread);
+ break;
default:
DBG("unhandled hid msg type 0x%02x", dev->hid_msg);
}
@@ -738,9 +796,51 @@ static uint8_t bt_hid_set_protocol(struct hal_cmd_hid_set_protocol *cmd,
static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *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;
+ dev->hid_msg = HID_MSG_GET_REPORT;
+ req_size = (cmd->buf > 0) ? 4 : 2;
+ req = g_try_malloc0(req_size);
+ if (!req)
+ return HAL_STATUS_NOMEM;
+
+ req[0] = HID_MSG_GET_REPORT | cmd->type;
+
+ if (cmd->buf > 0)
+ req[0] = req[0] | HID_GET_REPORT_SIZE_FIELD;
+
+ req[1] = cmd->id;
+
+ if (cmd->buf > 0)
+ bt_put_le16(cmd->buf, (req + 2));
+
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, req, req_size) < 0) {
+ error("error while querying device protocol");
+ g_free(req);
+ return HAL_STATUS_FAILED;
+ }
+
+ g_free(req);
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *cmd,
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 07/13] android/hid: Add missing set report parameters to ipc document
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-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 6b11684..48bcc45 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -552,7 +552,9 @@ Commands and responses:
Command parameters: Remote address (6 octets)
Report type (1 octet)
- ...
+ Report length (2 octet)
+ Report data (670 octet) L2CAP default MTU
+
Response parameters: <none>
Valid report types: 0x01 = Input
--
1.8.1.2
^ permalink raw reply related
* [PATCH_v2 08/13] android/hid: Implement hid set report in daemon
From: Ravi kumar Veeramally @ 2013-11-05 11:38 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
In-Reply-To: <1383651495-12434-1-git-send-email-ravikumar.veeramally@linux.intel.com>
This patch requests hid device to set report.
---
android/hal-hidhost.c | 2 ++
android/hal-msg.h | 6 ++++--
android/hid.c | 40 ++++++++++++++++++++++++++++++++++++++--
3 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index f554cb2..29e3ee0 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -284,6 +284,8 @@ static bt_status_t hh_set_report(bt_bdaddr_t *bd_addr,
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+ cmd.len = strlen(report);
+ memcpy(cmd.data, report, cmd.len);
switch (reportType) {
case BTHH_INPUT_REPORT:
diff --git a/android/hal-msg.h b/android/hal-msg.h
index bc7df6b..2c3067f 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -290,8 +290,10 @@ struct hal_cmd_hid_get_report {
#define HAL_OP_HID_SET_REPORT 0x08
struct hal_cmd_hid_set_report {
- uint8_t bdaddr[6];
- uint8_t type;
+ uint8_t bdaddr[6];
+ uint8_t type;
+ uint16_t len;
+ uint8_t data[670];
} __attribute__((packed));
#define HAL_OP_HID_SEND_DATA 0x09
diff --git a/android/hid.c b/android/hid.c
index f1bf9e8..25e33fa 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -56,6 +56,7 @@
/* HID message types */
#define HID_MSG_GET_REPORT 0x40
+#define HID_MSG_SET_REPORT 0x50
#define HID_MSG_GET_PROTOCOL 0x60
#define HID_MSG_SET_PROTOCOL 0x70
#define HID_MSG_DATA 0xa0
@@ -846,9 +847,44 @@ static uint8_t bt_hid_get_report(struct hal_cmd_hid_get_report *cmd,
static uint8_t bt_hid_set_report(struct hal_cmd_hid_set_report *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;
+ dev->hid_msg = HID_MSG_SET_REPORT;
+ req_size = 1 + cmd->len;
+ 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);
+
+ fd = g_io_channel_unix_get_fd(dev->ctrl_io);
+
+ if (write(fd, req, req_size) < 0) {
+ error("error while querying device protocol");
+ g_free(req);
+ return HAL_STATUS_FAILED;
+ }
+
+ g_free(req);
+ return HAL_STATUS_SUCCESS;
}
static uint8_t bt_hid_send_data(struct hal_cmd_hid_send_data *cmd,
--
1.8.1.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox