* [PATCH 3/5] android/hal: Add support for handling bond state change event
From: Szymon Janc @ 2013-10-29 10:07 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041255-26549-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 5f6dcbe..067f420 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
}
+static void handle_bond_state_change(void *buf)
+{
+ struct hal_ev_bond_state_changed *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+
+ if (!bt_hal_cbacks->bond_state_changed_cb)
+ return;
+
+ bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -98,6 +109,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_ADAPTER_PROPS_CHANGED:
handle_adapter_props_changed(buf, len);
break;
+ case HAL_EV_BOND_STATE_CHANGED:
+ handle_bond_state_change(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* [PATCH 4/5] android/hal: Add support for handling pin request event
From: Szymon Janc @ 2013-10-29 10:07 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041255-26549-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 067f420..75dbc68 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -79,6 +79,17 @@ static void handle_bond_state_change(void *buf)
bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
}
+static void handle_pin_request(void *buf)
+{
+ struct hal_ev_pin_request *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+ bt_bdname_t *name = (bt_bdname_t *) ev->name;
+
+ if (!bt_hal_cbacks->pin_request_cb)
+
+ bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -112,6 +123,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
break;
+ case HAL_EV_PIN_REQUEST:
+ handle_pin_request(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* [PATCH 5/5] android/hal: Add support for handling SSP request event
From: Szymon Janc @ 2013-10-29 10:07 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041255-26549-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 75dbc68..c22de6f 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -90,6 +90,19 @@ static void handle_pin_request(void *buf)
bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
}
+static void handle_ssp_request(void *buf)
+{
+ struct hal_ev_ssp_request *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+ bt_bdname_t *name = (bt_bdname_t *) ev->name;
+
+ if (!bt_hal_cbacks->ssp_request_cb)
+ return;
+
+ bt_hal_cbacks->ssp_request_cb(addr, name, ev->class_of_dev,
+ ev->pairing_variant, ev->passkey);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -126,6 +139,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_PIN_REQUEST:
handle_pin_request(buf);
break;
+ case HAL_EV_SSP_REQUEST:
+ handle_ssp_request(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* Re: [PATCH 4/5] android/hal: Add support for handling pin request event
From: Szymon Janc @ 2013-10-29 10:13 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383041255-26549-4-git-send-email-szymon.janc@tieto.com>
On Tuesday 29 of October 2013 11:07:34 Szymon Janc wrote:
> ---
> android/hal-bluetooth.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index 067f420..75dbc68 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -79,6 +79,17 @@ static void handle_bond_state_change(void *buf)
> bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
> }
>
> +static void handle_pin_request(void *buf)
> +{
> + struct hal_ev_pin_request *ev = buf;
> + bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
> + bt_bdname_t *name = (bt_bdname_t *) ev->name;
> +
> + if (!bt_hal_cbacks->pin_request_cb)
> +
> + bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
will send v2 with this fixed.
> +}
> +
> void bt_thread_associate(void)
> {
> if (bt_hal_cbacks->thread_evt_cb)
> @@ -112,6 +123,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
> case HAL_EV_BOND_STATE_CHANGED:
> handle_bond_state_change(buf);
> break;
> + case HAL_EV_PIN_REQUEST:
> + handle_pin_request(buf);
> + break;
> default:
> DBG("Unhandled callback opcode=0x%x", opcode);
> break;
>
^ permalink raw reply
* [PATCH v2 1/5] android: Define class of device as four bytes in IPC doc
From: Szymon Janc @ 2013-10-29 10:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
For PIN and SSP requests callback define CoD as 4 bytes. This will
allow HAL library to pass CoD direclty to callback. Will also match
how CoD is passed as property.
---
android/hal-ipc-api.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index dc0d067..e7af8a3 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -354,13 +354,13 @@ Notifications:
Notification parameters: Remote address (6 octets)
Remote name (249 octets)
- Class of device (3 octets)
+ Class of device (4 octets)
Opcode 0x87 - SSP Request notification
Notification parameters: Remote address (6 octets)
Remote name (249 octets)
- Class of device (3 octets)
+ Class of device (4 octets)
Pairing variant (1 octet)
Passkey (4 octets)
--
1.8.4.1
^ permalink raw reply related
* [PATCH v2 2/5] android: Update IPC headers to match SSP and PIN requests events
From: Szymon Janc @ 2013-10-29 10:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041789-28360-1-git-send-email-szymon.janc@tieto.com>
Name should be 249 bytes so it is always NULL terminated string.
Class of device is send as uint32. This will allow to make simple
passing of data in HAL library without need of copying data.
---
android/hal-msg.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index a4eb2a8..80b47d6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -356,15 +356,15 @@ struct hal_ev_discovery_state_changed {
#define HAL_EV_PIN_REQUEST 0x86
struct hal_ev_pin_request {
uint8_t bdaddr[6];
- uint8_t name[249 - 1];
- uint8_t class_of_dev[3];
+ uint8_t name[249];
+ uint32_t class_of_dev;
} __attribute__((packed));
#define HAL_EV_SSP_REQUEST 0x87
struct hal_ev_ssp_request {
uint8_t bdaddr[6];
- uint8_t name[249 - 1];
- uint8_t class_of_dev[3];
+ uint8_t name[249];
+ uint32_t class_of_dev;
uint8_t pairing_variant;
uint32_t passkey;
} __attribute__((packed));
--
1.8.4.1
^ permalink raw reply related
* [PATCH v2 3/5] android/hal: Add support for handling bond state change event
From: Szymon Janc @ 2013-10-29 10:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041789-28360-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 5f6dcbe..067f420 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
}
+static void handle_bond_state_change(void *buf)
+{
+ struct hal_ev_bond_state_changed *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+
+ if (!bt_hal_cbacks->bond_state_changed_cb)
+ return;
+
+ bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -98,6 +109,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_ADAPTER_PROPS_CHANGED:
handle_adapter_props_changed(buf, len);
break;
+ case HAL_EV_BOND_STATE_CHANGED:
+ handle_bond_state_change(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* [PATCH v2 4/5] android/hal: Add support for handling pin request event
From: Szymon Janc @ 2013-10-29 10:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041789-28360-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 067f420..43db8cb 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -79,6 +79,16 @@ static void handle_bond_state_change(void *buf)
bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
}
+static void handle_pin_request(void *buf)
+{
+ struct hal_ev_pin_request *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+ bt_bdname_t *name = (bt_bdname_t *) ev->name;
+
+ if (bt_hal_cbacks->pin_request_cb)
+ bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -112,6 +122,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
break;
+ case HAL_EV_PIN_REQUEST:
+ handle_pin_request(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* [PATCH v2 5/5] android/hal: Add support for handling SSP request event
From: Szymon Janc @ 2013-10-29 10:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1383041789-28360-1-git-send-email-szymon.janc@tieto.com>
---
android/hal-bluetooth.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 43db8cb..0c9e8c8 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -89,6 +89,18 @@ static void handle_pin_request(void *buf)
bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
}
+static void handle_ssp_request(void *buf)
+{
+ struct hal_ev_ssp_request *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+ bt_bdname_t *name = (bt_bdname_t *) ev->name;
+
+ if (bt_hal_cbacks->ssp_request_cb)
+ bt_hal_cbacks->ssp_request_cb(addr, name, ev->class_of_dev,
+ ev->pairing_variant,
+ ev->passkey);
+}
+
void bt_thread_associate(void)
{
if (bt_hal_cbacks->thread_evt_cb)
@@ -125,6 +137,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_PIN_REQUEST:
handle_pin_request(buf);
break;
+ case HAL_EV_SSP_REQUEST:
+ handle_ssp_request(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.8.4.1
^ permalink raw reply related
* [PATCHv2 0/9] Improve logging for Android
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1382957047-31775-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Changes:
*v2: Added thread-safe helpers for printing properties, bdaddr, etc
after comments that simple printing is not thread-safe. The idea is to
use TLS (thread local storage) like bionic is doing for strerror for
example. More info can be found on manpage for pthread_key_create.
This patch series uses debug functions defined already for haltest and
allows to print very helpful logs on Android target like shown below:
...
hal-bluetooth.c:set_adapter_property() prop: type=BT_PROPERTY_ADAPTER_SCAN_MODE len=4 val=BT_SCAN_MODE_NONE
...
Andrei Emeltchenko (9):
android/haltest: Export print property
android/haltest: Fix compile error making function static
android/haltest: Use pointer as parameter for debug
android/hal: Print full property in debug
android/hal: Add extra logs
android/hal: Print adapter state
android/hal: Print adapter property in callback
android: Add thread-safe helpers
android: Use thread-safe helpers
android/client/if-bt.c | 112 +------------------------------------------
android/client/textconv.c | 115 +++++++++++++++++++++++++++++++++++++++++++++
android/client/textconv.h | 3 ++
android/hal-bluetooth.c | 28 ++++++-----
android/pthread-local.h | 58 +++++++++++++++++++++++
5 files changed, 194 insertions(+), 122 deletions(-)
create mode 100644 android/pthread-local.h
--
1.7.10.4
^ permalink raw reply
* [PATCHv2 1/9] android/haltest: Export print property
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Export property printing debug function.
---
android/client/if-bt.c | 110 ---------------------------------------------
android/client/textconv.c | 110 +++++++++++++++++++++++++++++++++++++++++++++
android/client/textconv.h | 3 ++
3 files changed, 113 insertions(+), 110 deletions(-)
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index a20a7c6..e9edec5 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -29,20 +29,6 @@ const bt_interface_t *if_bluetooth;
} \
} while (0)
-static char *bdaddr2str(const bt_bdaddr_t *bd_addr)
-{
- static char buf[MAX_ADDR_STR_LEN];
-
- return bt_bdaddr_t2str(bd_addr, buf);
-}
-
-static char *btuuid2str(const bt_uuid_t *uuid)
-{
- static char buf[MAX_UUID_STR_LEN];
-
- return bt_uuid_t2str(uuid, buf);
-}
-
static bt_scan_mode_t str2btscanmode(const char *str)
{
bt_scan_mode_t v = str2bt_scan_mode_t(str);
@@ -76,102 +62,6 @@ static bt_property_type_t str2btpropertytype(const char *str)
return (bt_property_type_t) atoi(str);
}
-static char *btproperty2str(bt_property_t property)
-{
- static char buf[4096];
- char *p;
-
- p = buf + sprintf(buf, "type=%s len=%d val=",
- bt_property_type_t2str(property.type),
- property.len);
-
- switch (property.type) {
- case BT_PROPERTY_BDNAME:
- case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
- sprintf(p, "%*s", property.len,
- ((bt_bdname_t *) property.val)->name);
- break;
-
- case BT_PROPERTY_BDADDR:
- sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
- break;
-
- case BT_PROPERTY_CLASS_OF_DEVICE:
- sprintf(p, "%06x", *((int *) property.val));
- break;
-
- case BT_PROPERTY_TYPE_OF_DEVICE:
- sprintf(p, "%s", bt_device_type_t2str(
- *((bt_device_type_t *) property.val)));
- break;
-
- case BT_PROPERTY_REMOTE_RSSI:
- sprintf(p, "%d", *((char *) property.val));
- break;
-
- case BT_PROPERTY_ADAPTER_SCAN_MODE:
- sprintf(p, "%s",
- bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
- break;
-
- case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
- sprintf(p, "%d", *((int *) property.val));
- break;
-
- case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
- {
- int count = property.len / sizeof(bt_bdaddr_t);
- char *ptr = property.val;
-
- strcat(p, "{");
-
- while (count--) {
- strcat(p, bdaddr2str((bt_bdaddr_t *) ptr));
- if (count)
- strcat(p, ", ");
- ptr += sizeof(bt_bdaddr_t);
- }
-
- strcat(p, "}");
-
- }
- break;
-
- case BT_PROPERTY_UUIDS:
- {
- int count = property.len / sizeof(bt_uuid_t);
- char *ptr = property.val;
-
- strcat(p, "{");
-
- while (count--) {
- strcat(p, btuuid2str((bt_uuid_t *) ptr));
- if (count)
- strcat(p, ", ");
- ptr += sizeof(bt_uuid_t);
- }
-
- strcat(p, "}");
-
- }
- break;
-
- case BT_PROPERTY_SERVICE_RECORD:
- {
- bt_service_record_t *rec = property.val;
-
- sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
- rec->channel, rec->name);
- }
- break;
-
- default:
- sprintf(p, "%p", property.val);
- }
-
- return buf;
-}
-
static void dump_properties(int num_properties, bt_property_t *properties)
{
int i;
diff --git a/android/client/textconv.c b/android/client/textconv.c
index 32b1cab..a3e10ee 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -226,3 +226,113 @@ const char *enum_one_string(void *v, int i)
return (i == 0) && (m[0] != 0) ? m : NULL;
}
+
+char *bdaddr2str(const bt_bdaddr_t *bd_addr)
+{
+ static char buf[MAX_ADDR_STR_LEN];
+
+ return bt_bdaddr_t2str(bd_addr, buf);
+}
+
+char *btuuid2str(const bt_uuid_t *uuid)
+{
+ static char buf[MAX_UUID_STR_LEN];
+
+ return bt_uuid_t2str(uuid, buf);
+}
+
+char *btproperty2str(bt_property_t property)
+{
+ static char buf[4096];
+ char *p;
+
+ p = buf + sprintf(buf, "type=%s len=%d val=",
+ bt_property_type_t2str(property.type),
+ property.len);
+
+ switch (property.type) {
+ case BT_PROPERTY_BDNAME:
+ case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
+ sprintf(p, "%*s", property.len,
+ ((bt_bdname_t *) property.val)->name);
+ break;
+
+ case BT_PROPERTY_BDADDR:
+ sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
+ break;
+
+ case BT_PROPERTY_CLASS_OF_DEVICE:
+ sprintf(p, "%06x", *((int *) property.val));
+ break;
+
+ case BT_PROPERTY_TYPE_OF_DEVICE:
+ sprintf(p, "%s", bt_device_type_t2str(
+ *((bt_device_type_t *) property.val)));
+ break;
+
+ case BT_PROPERTY_REMOTE_RSSI:
+ sprintf(p, "%d", *((char *) property.val));
+ break;
+
+ case BT_PROPERTY_ADAPTER_SCAN_MODE:
+ sprintf(p, "%s",
+ bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
+ break;
+
+ case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+ sprintf(p, "%d", *((int *) property.val));
+ break;
+
+ case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
+ {
+ int count = property.len / sizeof(bt_bdaddr_t);
+ char *ptr = property.val;
+
+ strcat(p, "{");
+
+ while (count--) {
+ strcat(p, bdaddr2str((bt_bdaddr_t *) ptr));
+ if (count)
+ strcat(p, ", ");
+ ptr += sizeof(bt_bdaddr_t);
+ }
+
+ strcat(p, "}");
+
+ }
+ break;
+
+ case BT_PROPERTY_UUIDS:
+ {
+ int count = property.len / sizeof(bt_uuid_t);
+ char *ptr = property.val;
+
+ strcat(p, "{");
+
+ while (count--) {
+ strcat(p, btuuid2str((bt_uuid_t *) ptr));
+ if (count)
+ strcat(p, ", ");
+ ptr += sizeof(bt_uuid_t);
+ }
+
+ strcat(p, "}");
+
+ }
+ break;
+
+ case BT_PROPERTY_SERVICE_RECORD:
+ {
+ bt_service_record_t *rec = property.val;
+
+ sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
+ rec->channel, rec->name);
+ }
+ break;
+
+ default:
+ sprintf(p, "%p", property.val);
+ }
+
+ return buf;
+}
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 085b141..89b29c6 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -107,6 +107,9 @@ void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
+char *btproperty2str(bt_property_t property);
+char *bdaddr2str(const bt_bdaddr_t *bd_addr);
+
DECINTMAP(bt_status_t);
DECINTMAP(bt_state_t);
DECINTMAP(bt_device_type_t);
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 2/9] android/haltest: Fix compile error making function static
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This fixes following error during compilation:
...
android/client/textconv.c:240: error: no previous declaration for ‘btuuid2str’
make[1]: *** [android/client/android_haltest-textconv.o] Error 1
...
---
android/client/textconv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/client/textconv.c b/android/client/textconv.c
index a3e10ee..8f27948 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -234,7 +234,7 @@ char *bdaddr2str(const bt_bdaddr_t *bd_addr)
return bt_bdaddr_t2str(bd_addr, buf);
}
-char *btuuid2str(const bt_uuid_t *uuid)
+static char *btuuid2str(const bt_uuid_t *uuid)
{
static char buf[MAX_UUID_STR_LEN];
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 3/9] android/haltest: Use pointer as parameter for debug
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Pass structure as pointer. This makes it consistent with the rest of
the code and helps to reuse this function in other parts.
---
android/client/if-bt.c | 2 +-
android/client/textconv.c | 36 ++++++++++++++++++------------------
android/client/textconv.h | 2 +-
3 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index e9edec5..cbb828b 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -74,7 +74,7 @@ static void dump_properties(int num_properties, bt_property_t *properties)
bt_property_t prop;
memcpy(&prop, properties + i, sizeof(prop));
- haltest_info("prop: %s\n", btproperty2str(prop));
+ haltest_info("prop: %s\n", btproperty2str(&prop));
}
}
diff --git a/android/client/textconv.c b/android/client/textconv.c
index 8f27948..1dc6ad0 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -241,52 +241,52 @@ static char *btuuid2str(const bt_uuid_t *uuid)
return bt_uuid_t2str(uuid, buf);
}
-char *btproperty2str(bt_property_t property)
+char *btproperty2str(const bt_property_t *property)
{
static char buf[4096];
char *p;
p = buf + sprintf(buf, "type=%s len=%d val=",
- bt_property_type_t2str(property.type),
- property.len);
+ bt_property_type_t2str(property->type),
+ property->len);
- switch (property.type) {
+ switch (property->type) {
case BT_PROPERTY_BDNAME:
case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
- sprintf(p, "%*s", property.len,
- ((bt_bdname_t *) property.val)->name);
+ sprintf(p, "%*s", property->len,
+ ((bt_bdname_t *) property->val)->name);
break;
case BT_PROPERTY_BDADDR:
- sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property.val));
+ sprintf(p, "%s", bdaddr2str((bt_bdaddr_t *) property->val));
break;
case BT_PROPERTY_CLASS_OF_DEVICE:
- sprintf(p, "%06x", *((int *) property.val));
+ sprintf(p, "%06x", *((int *) property->val));
break;
case BT_PROPERTY_TYPE_OF_DEVICE:
sprintf(p, "%s", bt_device_type_t2str(
- *((bt_device_type_t *) property.val)));
+ *((bt_device_type_t *) property->val)));
break;
case BT_PROPERTY_REMOTE_RSSI:
- sprintf(p, "%d", *((char *) property.val));
+ sprintf(p, "%d", *((char *) property->val));
break;
case BT_PROPERTY_ADAPTER_SCAN_MODE:
sprintf(p, "%s",
- bt_scan_mode_t2str(*((bt_scan_mode_t *) property.val)));
+ bt_scan_mode_t2str(*((bt_scan_mode_t *) property->val)));
break;
case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
- sprintf(p, "%d", *((int *) property.val));
+ sprintf(p, "%d", *((int *) property->val));
break;
case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
{
- int count = property.len / sizeof(bt_bdaddr_t);
- char *ptr = property.val;
+ int count = property->len / sizeof(bt_bdaddr_t);
+ char *ptr = property->val;
strcat(p, "{");
@@ -304,8 +304,8 @@ char *btproperty2str(bt_property_t property)
case BT_PROPERTY_UUIDS:
{
- int count = property.len / sizeof(bt_uuid_t);
- char *ptr = property.val;
+ int count = property->len / sizeof(bt_uuid_t);
+ char *ptr = property->val;
strcat(p, "{");
@@ -323,7 +323,7 @@ char *btproperty2str(bt_property_t property)
case BT_PROPERTY_SERVICE_RECORD:
{
- bt_service_record_t *rec = property.val;
+ bt_service_record_t *rec = property->val;
sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
rec->channel, rec->name);
@@ -331,7 +331,7 @@ char *btproperty2str(bt_property_t property)
break;
default:
- sprintf(p, "%p", property.val);
+ sprintf(p, "%p", property->val);
}
return buf;
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 89b29c6..1c848ef 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -107,7 +107,7 @@ void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
char *bt_uuid_t2str(const bt_uuid_t *uuid, char *buf);
void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
-char *btproperty2str(bt_property_t property);
+char *btproperty2str(const bt_property_t *property);
char *bdaddr2str(const bt_bdaddr_t *bd_addr);
DECINTMAP(bt_status_t);
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 4/9] android/hal: Print full property in debug
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Instead of printing property type print type and value. Use exported
function from hal test tool.
---
android/hal-bluetooth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 5929fff..da96202 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -226,7 +226,7 @@ static int set_adapter_property(const bt_property_t *property)
char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
- DBG("prop: %s", bt_property_type_t2str(property->type));
+ DBG("prop: %s", btproperty2str(property));
if (!interface_ready())
return BT_STATUS_NOT_READY;
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 5/9] android/hal: Add extra logs
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Add extra log prints for printing properties and bluetooth addresses.
---
android/hal-bluetooth.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index da96202..81e23cb 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -251,7 +251,7 @@ static int set_adapter_property(const bt_property_t *property)
static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
{
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(remote_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -262,7 +262,8 @@ static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
static int get_remote_device_property(bt_bdaddr_t *remote_addr,
bt_property_type_t type)
{
- DBG("");
+ DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
+ bt_property_type_t2str(type));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -273,7 +274,8 @@ static int get_remote_device_property(bt_bdaddr_t *remote_addr,
static int set_remote_device_property(bt_bdaddr_t *remote_addr,
const bt_property_t *property)
{
- DBG("");
+ DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
+ btproperty2str(property));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -283,7 +285,7 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
{
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(remote_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -293,7 +295,7 @@ static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
static int get_remote_services(bt_bdaddr_t *remote_addr)
{
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(remote_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -325,7 +327,7 @@ static int create_bond(const bt_bdaddr_t *bd_addr)
{
struct hal_cmd_create_bond cmd;
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -340,7 +342,7 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
{
struct hal_cmd_cancel_bond cmd;
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -355,7 +357,7 @@ static int remove_bond(const bt_bdaddr_t *bd_addr)
{
struct hal_cmd_remove_bond cmd;
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -371,7 +373,7 @@ static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
{
struct hal_cmd_pin_reply cmd;
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
@@ -390,7 +392,7 @@ static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
{
struct hal_cmd_ssp_reply cmd;
- DBG("");
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
if (!interface_ready())
return BT_STATUS_NOT_READY;
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 6/9] android/hal: Print adapter state
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/hal-bluetooth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 81e23cb..4dbfeec 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -33,6 +33,8 @@ static void handle_adapter_state_changed(void *buf)
{
struct hal_ev_adapter_state_changed *ev = buf;
+ DBG("state: %s", bt_state_t2str(ev->state));
+
if (bt_hal_cbacks->adapter_state_changed_cb)
bt_hal_cbacks->adapter_state_changed_cb(ev->state);
}
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 7/9] android/hal: Print adapter property in callback
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/hal-bluetooth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 4dbfeec..4fb6837 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -65,6 +65,8 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
p += sizeof(*hal_prop) + hal_prop->len;
hal_prop = p;
+
+ DBG("prop[%d]: %s", i, btproperty2str(&props[i]));
}
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 8/9] android: Add thread-safe helpers
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Add thread safe helpers to make HAL debug printing thread-safe. The code
is inherited from Android bionic and it is used for strerror, strsignal,
etc.
---
android/pthread-local.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 android/pthread-local.h
diff --git a/android/pthread-local.h b/android/pthread-local.h
new file mode 100644
index 0000000..bc3c0b3
--- /dev/null
+++ b/android/pthread-local.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2013 Intel Corp.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#define GLOBAL_INIT_THREAD_LOCAL_BUFFER(name) \
+ static pthread_key_t __tls_ ## name ## _key; \
+ static void __tls_ ## name ## _key_destroy(void *buffer) \
+ { \
+ free(buffer); \
+ } \
+ static void __attribute__((constructor)) __tls_ ## name ## _key_init() \
+ { \
+ pthread_key_create(&__tls_ ## name ## _key, \
+ __tls_ ## name ## _key_destroy); \
+ }
+
+/*
+ * Leaves "name_tls_buffer" and "name_tls_buffer_size" defined and initialized.
+ */
+#define LOCAL_INIT_THREAD_LOCAL_BUFFER(type, name, byte_count) \
+ const size_t name ## _tls_buffer_size \
+ __attribute__((unused)) = byte_count; \
+ type name ## _tls_buffer = \
+ (pthread_getspecific(__tls_ ## name ## _key)); \
+ if (name ## _tls_buffer == NULL) { \
+ name ## _tls_buffer = (calloc(1, byte_count)); \
+ pthread_setspecific(__tls_ ## name ## _key, \
+ name ## _tls_buffer); \
+ }
--
1.7.10.4
^ permalink raw reply related
* [PATCHv2 9/9] android: Use thread-safe helpers
From: Andrei Emeltchenko @ 2013-10-29 10:21 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Make use of thread-safe helpers.
---
android/client/textconv.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/android/client/textconv.c b/android/client/textconv.c
index 1dc6ad0..effd1b3 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -19,6 +19,8 @@
#include <stdio.h>
#include <hardware/bluetooth.h>
+#include "../pthread-local.h"
+
#include "textconv.h"
/*
@@ -227,11 +229,12 @@ const char *enum_one_string(void *v, int i)
return (i == 0) && (m[0] != 0) ? m : NULL;
}
+GLOBAL_INIT_THREAD_LOCAL_BUFFER(bdaddr);
char *bdaddr2str(const bt_bdaddr_t *bd_addr)
{
- static char buf[MAX_ADDR_STR_LEN];
+ LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, bdaddr, MAX_ADDR_STR_LEN);
- return bt_bdaddr_t2str(bd_addr, buf);
+ return bt_bdaddr_t2str(bd_addr, bdaddr_tls_buffer);
}
static char *btuuid2str(const bt_uuid_t *uuid)
@@ -241,12 +244,14 @@ static char *btuuid2str(const bt_uuid_t *uuid)
return bt_uuid_t2str(uuid, buf);
}
+GLOBAL_INIT_THREAD_LOCAL_BUFFER(property);
char *btproperty2str(const bt_property_t *property)
{
- static char buf[4096];
char *p;
+ LOCAL_INIT_THREAD_LOCAL_BUFFER(char*, property, 4096);
- p = buf + sprintf(buf, "type=%s len=%d val=",
+ p = property_tls_buffer + sprintf(property_tls_buffer,
+ "type=%s len=%d val=",
bt_property_type_t2str(property->type),
property->len);
@@ -334,5 +339,5 @@ char *btproperty2str(const bt_property_t *property)
sprintf(p, "%p", property->val);
}
- return buf;
+ return property_tls_buffer;
}
--
1.7.10.4
^ permalink raw reply related
* Re: [PATCH v2 3/5] android/hal: Add support for handling bond state change event
From: Andrei Emeltchenko @ 2013-10-29 10:27 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1383041789-28360-3-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Tue, Oct 29, 2013 at 11:16:27AM +0100, Szymon Janc wrote:
> ---
> android/hal-bluetooth.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index 5f6dcbe..067f420 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
> bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
> }
>
> +static void handle_bond_state_change(void *buf)
> +{
> + struct hal_ev_bond_state_changed *ev = buf;
> + bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
> +
> + if (!bt_hal_cbacks->bond_state_changed_cb)
> + return;
> +
> + bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
We shall use the same style like for other callbacks.
Best regards
Andrei Emeltchenko
> +}
> +
> void bt_thread_associate(void)
> {
> if (bt_hal_cbacks->thread_evt_cb)
> @@ -98,6 +109,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
> case HAL_EV_ADAPTER_PROPS_CHANGED:
> handle_adapter_props_changed(buf, len);
> break;
> + case HAL_EV_BOND_STATE_CHANGED:
> + handle_bond_state_change(buf);
> + break;
> default:
> DBG("Unhandled callback opcode=0x%x", opcode);
> break;
> --
> 1.8.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* Re: [PATCHv2 2/9] android/haltest: Fix compile error making function static
From: Andrei Emeltchenko @ 2013-10-29 10:31 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1383042118-21205-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
sorry forgot to merge this fix
On Tue, Oct 29, 2013 at 12:21:51PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> This fixes following error during compilation:
> ...
> android/client/textconv.c:240: error: no previous declaration for ‘btuuid2str’
> make[1]: *** [android/client/android_haltest-textconv.o] Error 1
> ...
> ---
> android/client/textconv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/android/client/textconv.c b/android/client/textconv.c
> index a3e10ee..8f27948 100644
> --- a/android/client/textconv.c
> +++ b/android/client/textconv.c
> @@ -234,7 +234,7 @@ char *bdaddr2str(const bt_bdaddr_t *bd_addr)
> return bt_bdaddr_t2str(bd_addr, buf);
> }
>
> -char *btuuid2str(const bt_uuid_t *uuid)
> +static char *btuuid2str(const bt_uuid_t *uuid)
> {
> static char buf[MAX_UUID_STR_LEN];
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* Re: [PATCH v2 3/5] android/hal: Add support for handling bond state change event
From: Szymon Janc @ 2013-10-29 10:32 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <20131029102722.GB27517@aemeltch-MOBL1>
Hi Andrei,
On Tuesday 29 of October 2013 12:27:24 Andrei Emeltchenko wrote:
> Hi Szymon,
>
> On Tue, Oct 29, 2013 at 11:16:27AM +0100, Szymon Janc wrote:
> > ---
> > android/hal-bluetooth.c | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
> > diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> > index 5f6dcbe..067f420 100644
> > --- a/android/hal-bluetooth.c
> > +++ b/android/hal-bluetooth.c
> > @@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
> > bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
> > }
> >
> > +static void handle_bond_state_change(void *buf)
> > +{
> > + struct hal_ev_bond_state_changed *ev = buf;
> > + bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
> > +
> > + if (!bt_hal_cbacks->bond_state_changed_cb)
> > + return;
> > +
> > + bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
>
> We shall use the same style like for other callbacks.
In that case reverting check allow to not break function call into 2 lines.
I find it more readable (and there will be reverted check for less trivial
callbacks e.g. with properties)
--
BR
Szymon Janc
^ permalink raw reply
* Re: [PATCH v2 3/5] android/hal: Add support for handling bond state change event
From: Andrei Emeltchenko @ 2013-10-29 10:38 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <32939690.A882f3Cjsu@uw000953>
On Tue, Oct 29, 2013 at 11:32:29AM +0100, Szymon Janc wrote:
> Hi Andrei,
>
> On Tuesday 29 of October 2013 12:27:24 Andrei Emeltchenko wrote:
> > Hi Szymon,
> >
> > On Tue, Oct 29, 2013 at 11:16:27AM +0100, Szymon Janc wrote:
> > > ---
> > > android/hal-bluetooth.c | 14 ++++++++++++++
> > > 1 file changed, 14 insertions(+)
> > >
> > > diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> > > index 5f6dcbe..067f420 100644
> > > --- a/android/hal-bluetooth.c
> > > +++ b/android/hal-bluetooth.c
> > > @@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
> > > bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
> > > }
> > >
> > > +static void handle_bond_state_change(void *buf)
> > > +{
> > > + struct hal_ev_bond_state_changed *ev = buf;
> > > + bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
> > > +
> > > + if (!bt_hal_cbacks->bond_state_changed_cb)
> > > + return;
> > > +
> > > + bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
> >
> > We shall use the same style like for other callbacks.
>
> In that case reverting check allow to not break function call into 2 lines.
> I find it more readable (and there will be reverted check for less trivial
> callbacks e.g. with properties)
Those checks at least need to be consistent. Your next patch use other
way. We shall agree about best way for this check, maybe some #define like
I have in my patches sent some time ago? We could also add debug traces
then.
Best regards
Andrei Emeltchenko
^ permalink raw reply
* Re: [PATCH v2 3/5] android/hal: Add support for handling bond state change event
From: Szymon Janc @ 2013-10-29 10:52 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <20131029103800.GD27517@aemeltch-MOBL1>
Hi Andrei,
> On Tue, Oct 29, 2013 at 11:32:29AM +0100, Szymon Janc wrote:
> > Hi Andrei,
> >
> > On Tuesday 29 of October 2013 12:27:24 Andrei Emeltchenko wrote:
> > > Hi Szymon,
> > >
> > > On Tue, Oct 29, 2013 at 11:16:27AM +0100, Szymon Janc wrote:
> > > > ---
> > > > android/hal-bluetooth.c | 14 ++++++++++++++
> > > > 1 file changed, 14 insertions(+)
> > > >
> > > > diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> > > > index 5f6dcbe..067f420 100644
> > > > --- a/android/hal-bluetooth.c
> > > > +++ b/android/hal-bluetooth.c
> > > > @@ -68,6 +68,17 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
> > > > bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
> > > > }
> > > >
> > > > +static void handle_bond_state_change(void *buf)
> > > > +{
> > > > + struct hal_ev_bond_state_changed *ev = buf;
> > > > + bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
> > > > +
> > > > + if (!bt_hal_cbacks->bond_state_changed_cb)
> > > > + return;
> > > > +
> > > > + bt_hal_cbacks->bond_state_changed_cb(ev->status, addr, ev->state);
> > >
> > > We shall use the same style like for other callbacks.
> >
> > In that case reverting check allow to not break function call into 2 lines.
> > I find it more readable (and there will be reverted check for less trivial
> > callbacks e.g. with properties)
>
> Those checks at least need to be consistent. Your next patch use other
> way. We shall agree about best way for this check, maybe some #define like
> I have in my patches sent some time ago? We could also add debug traces
> then.
In next patch reverting check wouldn't give any benefit as function call
doesn't fit 1 line. Not that this matter a lot since this is trivial callback
handler. I'll send v3 with this check changed if this really bothers you :)
As for macro, I would prefer to not have any as this makes code harder to
follow especially for non-trivial handlers (where you can return early in case
callback is null).
(I was even thinking about open-coding interface_ready() functions... )
--
BR
Szymon Janc
^ permalink raw reply
* Re: [PATCH_v3 1/2] android: Add initial HID connect implementation
From: Luiz Augusto von Dentz @ 2013-10-29 11:15 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1383040097-15475-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Tue, Oct 29, 2013 at 11:48 AM, Ravi kumar Veeramally
<ravikumar.veeramally@linux.intel.com> wrote:
> Implemented basic HID connect method. Host connects to
> bt device at L2CAP level.
> ---
> v3: Updated patches as per Luiz comments (remove unnecessary
> type cast and tabs)
>
> v2: Updated patches as per Luiz comments
>
> v1: Patchset adds hid connect and disconnect mechanisms at
> L2CAP level. It opens the control channel and interrupt
> channel and listens on io events. UHID, hid server and
> ---
> Makefile.android | 3 +-
> android/Android.mk | 1 +
> android/hid.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 248 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile.android b/Makefile.android
> index 2b57daa..22002be 100644
> --- a/Makefile.android
> +++ b/Makefile.android
> @@ -12,7 +12,8 @@ android_bluetoothd_SOURCES = android/main.c \
> android/adapter.h android/adapter.c \
> android/hid.h android/hid.c \
> android/ipc.h android/ipc.c \
> - android/socket.h android/socket.c
> + android/socket.h android/socket.c \
> + btio/btio.h btio/btio.c
>
> android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 22208e0..28ec465 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -28,6 +28,7 @@ LOCAL_SRC_FILES := \
> ../lib/sdp.c \
> ../lib/bluetooth.c \
> ../lib/hci.c \
> + ../btio/btio.c
>
> LOCAL_C_INCLUDES := \
> $(call include-path-for, glib) \
> diff --git a/android/hid.c b/android/hid.c
> index f2da0d3..913dab4 100644
> --- a/android/hid.c
> +++ b/android/hid.c
> @@ -23,16 +23,260 @@
>
> #include <stdint.h>
> #include <stdbool.h>
> +#include <errno.h>
> +#include <unistd.h>
> +#include <fcntl.h>
>
> #include <glib.h>
>
> +#include "btio/btio.h"
> #include "lib/bluetooth.h"
> +#include "src/shared/mgmt.h"
> +
> #include "log.h"
> #include "hal-msg.h"
> #include "ipc.h"
> #include "hid.h"
> +#include "adapter.h"
> +#include "utils.h"
> +
> +#define L2CAP_PSM_HIDP_CTRL 0x11
> +#define L2CAP_PSM_HIDP_INTR 0x13
> +#define MAX_READ_BUFFER 4096
>
> static GIOChannel *notification_io = NULL;
> +static GSList *devices = NULL;
> +
> +struct hid_device {
> + bdaddr_t dst;
> + GIOChannel *ctrl_io;
> + GIOChannel *intr_io;
> + guint ctrl_watch;
> + guint intr_watch;
> +};
> +
> +static int device_cmp(gconstpointer s, gconstpointer user_data)
> +{
> + const struct hid_device *hdev = s;
> + const bdaddr_t *dst = user_data;
> +
> + return bacmp(&hdev->dst, dst);
> +}
> +
> +static void hid_device_free(struct hid_device *hdev)
> +{
> + if (hdev->ctrl_watch > 0)
> + g_source_remove(hdev->ctrl_watch);
> +
> + if (hdev->intr_watch > 0)
> + g_source_remove(hdev->intr_watch);
> +
> + if (hdev->intr_io)
> + g_io_channel_unref(hdev->intr_io);
> +
> + if (hdev->ctrl_io)
> + g_io_channel_unref(hdev->ctrl_io);
> +
> + devices = g_slist_remove(devices, hdev);
> + g_free(hdev);
> +}
> +
> +static gboolean intr_io_watch_cb(GIOChannel *chan, gpointer data)
> +{
> + char buf[MAX_READ_BUFFER];
> + int fd, bread;
> +
> + 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;
> + }
> +
> + DBG("bytes read %d", bread);
> +
> + /* TODO: At this moment only baseband is connected, i.e. mouse
> + * movements keyboard events doesn't effect on UI. Have to send
> + * this data to uhid fd for profile connection. */
> +
> + return TRUE;
> +}
> +
> +static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
> + gpointer data)
> +{
> + struct hid_device *hdev = data;
> + char address[18];
> +
> + if (cond & G_IO_IN)
> + return intr_io_watch_cb(chan, data);
> +
> + ba2str(&hdev->dst, address);
> + DBG("Device %s disconnected", address);
> +
> + /* Checking for ctrl_watch avoids a double g_io_channel_shutdown since
> + * it's likely that ctrl_watch_cb has been queued for dispatching in
> + * this mainloop iteration */
> + if ((cond & (G_IO_HUP | G_IO_ERR)) && hdev->ctrl_watch)
> + g_io_channel_shutdown(chan, TRUE, NULL);
> +
> + hdev->intr_watch = 0;
> +
> + if (hdev->intr_io) {
> + g_io_channel_unref(hdev->intr_io);
> + hdev->intr_io = NULL;
> + }
> +
> + /* Close control channel */
> + if (hdev->ctrl_io && !(cond & G_IO_NVAL))
> + g_io_channel_shutdown(hdev->ctrl_io, TRUE, NULL);
> +
> + return FALSE;
> +}
> +
> +static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond,
> + gpointer data)
> +{
> + struct hid_device *hdev = data;
> + char address[18];
> +
> + ba2str(&hdev->dst, address);
> + DBG("Device %s disconnected", address);
> +
> + /* Checking for intr_watch avoids a double g_io_channel_shutdown since
> + * it's likely that intr_watch_cb has been queued for dispatching in
> + * this mainloop iteration */
> + if ((cond & (G_IO_HUP | G_IO_ERR)) && hdev->intr_watch)
> + g_io_channel_shutdown(chan, TRUE, NULL);
> +
> + hdev->ctrl_watch = 0;
> +
> + if (hdev->ctrl_io) {
> + g_io_channel_unref(hdev->ctrl_io);
> + hdev->ctrl_io = NULL;
> + }
> +
> + if (hdev->intr_io && !(cond & G_IO_NVAL))
> + g_io_channel_shutdown(hdev->intr_io, TRUE, NULL);
> +
> + return FALSE;
> +}
> +
> +static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
> + gpointer user_data)
> +{
> + struct hid_device *hdev = user_data;
> +
> + DBG("");
> +
> + if (conn_err)
> + goto failed;
> +
> + /*TODO: Get device details through SDP and create UHID fd and start
> + * listening on uhid events */
> + hdev->intr_watch = g_io_add_watch(hdev->intr_io,
> + G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
> + intr_watch_cb, hdev);
> +
> + return;
> +
> +failed:
> + /* So we guarantee the interrupt channel is closed before the
> + * control channel (if we only do unref GLib will close it only
> + * after returning control to the mainloop */
> + if (!conn_err)
> + g_io_channel_shutdown(hdev->intr_io, FALSE, NULL);
> +
> + g_io_channel_unref(hdev->intr_io);
> + hdev->intr_io = NULL;
> +
> + if (hdev->ctrl_io) {
> + g_io_channel_unref(hdev->ctrl_io);
> + hdev->ctrl_io = NULL;
> + }
> +}
> +
> +static void control_connect_cb(GIOChannel *chan, GError *conn_err,
> + gpointer user_data)
> +{
> + struct hid_device *hdev = user_data;
> + GError *err = NULL;
> + const bdaddr_t *src = bt_adapter_get_address();
> +
> + DBG("");
> +
> + if (conn_err) {
> + error("%s", conn_err->message);
> + goto failed;
> + }
> +
> + /* Connect to the HID interrupt channel */
> + hdev->intr_io = bt_io_connect(interrupt_connect_cb, hdev, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR, src,
> + BT_IO_OPT_DEST_BDADDR, &hdev->dst,
> + BT_IO_OPT_PSM, L2CAP_PSM_HIDP_INTR,
> + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
> + BT_IO_OPT_INVALID);
> + if (!hdev->intr_io) {
> + error("%s", err->message);
> + g_error_free(err);
> + goto failed;
> + }
> +
> + hdev->ctrl_watch = g_io_add_watch(hdev->ctrl_io,
> + G_IO_HUP | G_IO_ERR | G_IO_NVAL,
> + ctrl_watch_cb, hdev);
> +
> + return;
> +
> +failed:
> + g_io_channel_unref(hdev->ctrl_io);
> + hdev->ctrl_io = NULL;
> +}
> +
> +static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
> +{
> + struct hid_device *hdev;
> + char addr[18];
> + bdaddr_t dst;
> + GSList *l;
> + GError *err = NULL;
> + const bdaddr_t *src = bt_adapter_get_address();
> +
> + 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;
> +
> + hdev = g_new0(struct hid_device, 1);
> + android2bdaddr(&cmd->bdaddr, &hdev->dst);
> + ba2str(&hdev->dst, addr);
> +
> + DBG("connecting to %s", addr);
> +
> + hdev->ctrl_io = bt_io_connect(control_connect_cb, hdev, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR, src,
> + BT_IO_OPT_DEST_BDADDR, &hdev->dst,
> + BT_IO_OPT_PSM, L2CAP_PSM_HIDP_CTRL,
> + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
> + BT_IO_OPT_INVALID);
> + if (err) {
> + error("%s", err->message);
> + g_error_free(err);
> + hid_device_free(hdev);
> + return HAL_STATUS_FAILED;
> + }
> +
> + devices = g_slist_append(devices, hdev);
> +
> + return HAL_STATUS_SUCCESS;
> +}
>
> void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
> {
> @@ -40,6 +284,7 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
>
> switch (opcode) {
> case HAL_OP_HID_CONNECT:
> + status = bt_hid_connect(buf, len);
> break;
> case HAL_OP_HID_DISCONNECT:
> break;
> --
> 1.7.9.5
Pushed, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply
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