* [PATCHv2 9/9] unit/avrcp: Add /TP/PAS/BV-11-C test
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that the set player application setting value command
issued from the Controller.
---
unit/test-avrcp.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 0206e19..76fcdaf 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -461,6 +461,16 @@ static void test_client(gconstpointer data)
sizeof(attributes), NULL, NULL);
}
+ if (g_str_equal(context->data->test_name, "/TP/PAS/BV-11-C")) {
+ uint8_t attributes[2] = { AVRCP_ATTRIBUTE_EQUALIZER,
+ AVRCP_ATTRIBUTE_REPEAT_MODE };
+ uint8_t values[] = { 0xaa, 0xff };
+
+ avrcp_set_player_value(context->session, attributes,
+ sizeof(attributes), values,
+ NULL, NULL);
+ }
+
execute_context(context);
}
@@ -628,5 +638,13 @@ int main(int argc, char *argv[])
AVRCP_ATTRIBUTE_EQUALIZER, 0x00,
AVRCP_ATTRIBUTE_REPEAT_MODE, 0x00));
+ define_test("/TP/PAS/BV-11-C", test_client,
+ raw_pdu(0x00, 0x11, 0x0e, 0x00, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_SET_PLAYER_VALUE,
+ 0x00, 0x00, 0x05, 0x02,
+ AVRCP_ATTRIBUTE_EQUALIZER, 0xaa,
+ AVRCP_ATTRIBUTE_REPEAT_MODE, 0xff));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 8/9] android/avrcp: Add avrcp_set_player_value() function
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/avrcp-lib.c | 18 ++++++++++++++++++
android/avrcp-lib.h | 3 +++
2 files changed, 21 insertions(+)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 053e9e1..41c354c 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -340,5 +340,23 @@ int avrcp_get_current_player_value(struct avrcp *session, uint8_t *attributes,
return avrcp_send_req(session, AVC_CTYPE_STATUS, AVC_SUBUNIT_PANEL,
AVRCP_GET_CURRENT_PLAYER_VALUE, buf,
attr_count + 1, func, user_data);
+}
+
+int avrcp_set_player_value(struct avrcp *session, uint8_t *attributes,
+ uint8_t attr_count, uint8_t *values,
+ avctp_rsp_cb func, void *user_data)
+{
+ uint8_t buf[2 * attr_count + 1];
+ int i;
+ buf[0] = attr_count;
+
+ for (i = 0; i < attr_count; i++) {
+ buf[i * 2 + 1] = attributes[i];
+ buf[i * 2 + 2] = values[i];
+ }
+
+ return avrcp_send_req(session, AVC_CTYPE_CONTROL, AVC_SUBUNIT_PANEL,
+ AVRCP_SET_PLAYER_VALUE, buf, 2 * attr_count + 1,
+ func, user_data);
}
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 1f7eab0..c6d61e4 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -124,3 +124,6 @@ int avrcp_get_player_attribute_text(struct avrcp *session, uint8_t *attributes,
int avrcp_get_current_player_value(struct avrcp *session, uint8_t *attributes,
uint8_t attr_count, avctp_rsp_cb func,
void *user_data);
+int avrcp_set_player_value(struct avrcp *session, uint8_t *attributes,
+ uint8_t attr_count, uint8_t *values,
+ avctp_rsp_cb func, void *user_data);
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 7/9] unit/avrcp: Add /TP/PAS/BV-10-C test
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that the get current player application setting value
response issued from the Target.
---
unit/test-avrcp.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index f297efd..0206e19 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -387,6 +387,28 @@ static uint8_t avrcp_handle_get_player_value_text(struct avrcp *session,
return AVC_CTYPE_STABLE;
}
+static uint8_t avrcp_handle_get_current_player_value(struct avrcp *session,
+ uint8_t transaction, uint16_t *params_len,
+ uint8_t *params, void *user_data)
+{
+ uint8_t *attributes;
+ int i;
+
+ DBG("num attributes %d", params[0]);
+
+ attributes = g_memdup(¶ms[1], params[0]);
+
+ for (i = 0; i < params[0]; i++) {
+ params[i * 2 + 1] = attributes[i];
+ params[i * 2 + 2] = 0; /* value */
+ }
+
+ params[0] = i;
+ *params_len = params[0] * 2 + 1;
+
+ return AVC_CTYPE_STABLE;
+}
+
static const struct avrcp_control_handler control_handlers[] = {
{ AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
avrcp_handle_get_capabilities },
@@ -396,6 +418,8 @@ static const struct avrcp_control_handler control_handlers[] = {
avrcp_handle_get_player_attr_text },
{ AVRCP_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
avrcp_handle_list_player_values },
+ { AVRCP_GET_CURRENT_PLAYER_VALUE, AVC_CTYPE_STATUS,
+ avrcp_handle_get_current_player_value },
{ AVRCP_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
avrcp_handle_get_player_value_text },
{ },
@@ -590,5 +614,19 @@ int main(int argc, char *argv[])
AVRCP_ATTRIBUTE_EQUALIZER,
AVRCP_ATTRIBUTE_REPEAT_MODE));
+ define_test("/TP/PAS/BV-10-C", test_server,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_GET_CURRENT_PLAYER_VALUE,
+ 0x00, 0x00, 0x03, 0x02,
+ AVRCP_ATTRIBUTE_EQUALIZER,
+ AVRCP_ATTRIBUTE_REPEAT_MODE),
+ raw_pdu(0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_GET_CURRENT_PLAYER_VALUE,
+ 0x00, 0x00, 0x05, 0x02,
+ AVRCP_ATTRIBUTE_EQUALIZER, 0x00,
+ AVRCP_ATTRIBUTE_REPEAT_MODE, 0x00));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 6/9] unit/avrcp: Add /TP/PAS/BV-09-C test
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that get current player application setting value command
issued from the Controller.
---
unit/test-avrcp.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index b469dfd..f297efd 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -429,6 +429,14 @@ static void test_client(gconstpointer data)
avrcp_get_player_attribute_text(context->session, NULL, 0,
NULL, NULL);
+ if (g_str_equal(context->data->test_name, "/TP/PAS/BV-09-C")) {
+ uint8_t attributes[2] = { AVRCP_ATTRIBUTE_EQUALIZER,
+ AVRCP_ATTRIBUTE_REPEAT_MODE };
+
+ avrcp_get_current_player_value(context->session, attributes,
+ sizeof(attributes), NULL, NULL);
+ }
+
execute_context(context);
}
@@ -574,5 +582,13 @@ int main(int argc, char *argv[])
AVRCP_GET_PLAYER_VALUE_TEXT,
0x00, 0x00, 0x01, 0x00));
+ define_test("/TP/PAS/BV-09-C", test_client,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_GET_CURRENT_PLAYER_VALUE,
+ 0x00, 0x00, 0x03, 0x02,
+ AVRCP_ATTRIBUTE_EQUALIZER,
+ AVRCP_ATTRIBUTE_REPEAT_MODE));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 5/9] android/avrcp: Add avrcp_get_current_player_value() function
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/avrcp-lib.c | 21 +++++++++++++++++++++
android/avrcp-lib.h | 11 +++++++++++
2 files changed, 32 insertions(+)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 52074a7..053e9e1 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -321,3 +321,24 @@ int avrcp_get_player_attribute_text(struct avrcp *session, uint8_t *attributes,
AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, attributes,
attr_len, func, user_data);
}
+
+int avrcp_get_current_player_value(struct avrcp *session, uint8_t *attributes,
+ uint8_t attr_count, avctp_rsp_cb func,
+ void *user_data)
+
+{
+ uint8_t buf[AVRCP_ATTRIBUTE_LAST + 1];
+
+ if (attr_count > AVRCP_ATTRIBUTE_LAST)
+ return -EINVAL;
+
+ if (attributes && attr_count) {
+ buf[0] = attr_count;
+ memcpy(buf + 1, attributes, attr_count);
+ }
+
+ return avrcp_send_req(session, AVC_CTYPE_STATUS, AVC_SUBUNIT_PANEL,
+ AVRCP_GET_CURRENT_PLAYER_VALUE, buf,
+ attr_count + 1, func, user_data);
+
+}
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index da8c990..1f7eab0 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -74,6 +74,14 @@
#define CAP_COMPANY_ID 0x02
#define CAP_EVENTS_SUPPORTED 0x03
+/* Player Attributes */
+#define AVRCP_ATTRIBUTE_ILEGAL 0x00
+#define AVRCP_ATTRIBUTE_EQUALIZER 0x01
+#define AVRCP_ATTRIBUTE_REPEAT_MODE 0x02
+#define AVRCP_ATTRIBUTE_SHUFFLE 0x03
+#define AVRCP_ATTRIBUTE_SCAN 0x04
+#define AVRCP_ATTRIBUTE_LAST AVRCP_ATTRIBUTE_SCAN
+
/* Company IDs for vendor dependent commands */
#define IEEEID_BTSIG 0x001958
@@ -113,3 +121,6 @@ int avrcp_list_player_attributes(struct avrcp *session, avctp_rsp_cb func,
int avrcp_get_player_attribute_text(struct avrcp *session, uint8_t *attributes,
uint8_t attr_len, avctp_rsp_cb func,
void *user_data);
+int avrcp_get_current_player_value(struct avrcp *session, uint8_t *attributes,
+ uint8_t attr_count, avctp_rsp_cb func,
+ void *user_data);
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 4/9] avrcp: Fix buffer size check
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Fix size check taking into account that attributes starts from 1 (0 is
illegal).
---
profiles/audio/avrcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index c0e5d07..48c3355 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1909,7 +1909,7 @@ static void avrcp_get_current_player_value(struct avrcp *session,
struct avrcp_header *pdu = (void *) buf;
uint16_t length = AVRCP_HEADER_LENGTH + count + 1;
- if (count > AVRCP_ATTRIBUTE_LAST + 1)
+ if (count > AVRCP_ATTRIBUTE_LAST)
return;
memset(buf, 0, sizeof(buf));
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 3/9] unit/avrcp: Add /TP/PAS/BV-08-C test
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that verify the get player application setting values
response issued from the Target.
---
unit/test-avrcp.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 51fe064..b469dfd 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -375,6 +375,18 @@ fail:
return AVC_CTYPE_REJECTED;
}
+static uint8_t avrcp_handle_get_player_value_text(struct avrcp *session,
+ uint8_t transaction, uint16_t *params_len,
+ uint8_t *params, void *user_data)
+{
+ DBG("");
+
+ *params_len = 1;
+ params[0] = 0;
+
+ return AVC_CTYPE_STABLE;
+}
+
static const struct avrcp_control_handler control_handlers[] = {
{ AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
avrcp_handle_get_capabilities },
@@ -384,6 +396,8 @@ static const struct avrcp_control_handler control_handlers[] = {
avrcp_handle_get_player_attr_text },
{ AVRCP_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
avrcp_handle_list_player_values },
+ { AVRCP_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
+ avrcp_handle_get_player_value_text },
{ },
};
@@ -550,5 +564,15 @@ int main(int argc, char *argv[])
AVRCP_LIST_PLAYER_VALUES,
0x00, 0x00, 0x01, 0x00));
+ define_test("/TP/PAS/BV-08-C", test_server,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_GET_PLAYER_VALUE_TEXT,
+ 0x00, 0x00, 0x01, 0x00),
+ raw_pdu(0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_GET_PLAYER_VALUE_TEXT,
+ 0x00, 0x00, 0x01, 0x00));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 2/9] doc: Update test coverage document
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393597125-18176-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Update AVRCP test numbers.
---
doc/test-coverage.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/test-coverage.txt b/doc/test-coverage.txt
index d37bcb8..805af68 100644
--- a/doc/test-coverage.txt
+++ b/doc/test-coverage.txt
@@ -18,7 +18,7 @@ test-ringbuf 3 Ring buffer functionality
test-queue 1 Queue handling functionality
test-avdtp 60 AVDTP qualification test cases
test-avctp 9 AVCTP qualification test cases
-test-avrcp 7 AVRCP qualification test cases
+test-avrcp 19 AVRCP qualification test cases
test-gobex 31 Generic OBEX functionality
test-gobex-packet 9 OBEX packet handling
test-gobex-header 28 OBEX header handling
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 1/9] unit/avrcp: Add /TP/PAS/BV-06-C test
From: Andrei Emeltchenko @ 2014-02-28 14:18 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that the list player application setting values response
issued from the Target.
---
unit/test-avrcp.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index db9cb92..51fe064 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -355,6 +355,26 @@ static uint8_t avrcp_handle_get_player_attr_text(struct avrcp *session,
return AVC_CTYPE_STABLE;
}
+static uint8_t avrcp_handle_list_player_values(struct avrcp *session,
+ uint8_t transaction, uint16_t *params_len,
+ uint8_t *params, void *user_data)
+{
+ DBG("params[0] %d params_len %d", params[0], *params_len);
+
+ if (*params_len != 1)
+ goto fail;
+
+ *params_len = 1;
+ params[0] = 0;
+ return AVC_CTYPE_STABLE;
+
+fail:
+ *params_len = 1;
+ params[0] = AVRCP_STATUS_INVALID_PARAM;
+
+ return AVC_CTYPE_REJECTED;
+}
+
static const struct avrcp_control_handler control_handlers[] = {
{ AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
avrcp_handle_get_capabilities },
@@ -362,6 +382,8 @@ static const struct avrcp_control_handler control_handlers[] = {
avrcp_handle_list_attributes },
{ AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
avrcp_handle_get_player_attr_text },
+ { AVRCP_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
+ avrcp_handle_list_player_values },
{ },
};
@@ -518,5 +540,15 @@ int main(int argc, char *argv[])
AVRCP_GET_PLAYER_ATTRIBUTE_TEXT,
0x00, 0x00, 0x01, 0x00));
+ define_test("/TP/PAS/BV-06-C", test_server,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_LIST_PLAYER_VALUES,
+ 0x00, 0x00, 0x01, 0x00),
+ raw_pdu(0x02, 0x11, 0x0e, 0x0c, 0x48, 0x00,
+ 0x00, 0x19, 0x58,
+ AVRCP_LIST_PLAYER_VALUES,
+ 0x00, 0x00, 0x01, 0x00));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH BlueZ] core: retry connect_dbus() several times
From: Luiz Augusto von Dentz @ 2014-02-28 14:10 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: Adam Lee, Marcel Holtmann, BlueZ development
In-Reply-To: <CAJdJm_OnnyvMvLmCtYuLGOvUL0igK22gOCAP1G5KBvcJseaayw@mail.gmail.com>
Hi Adam,
On Fri, Feb 28, 2014 at 1:22 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi Adam,
>
> On Fri, Feb 28, 2014 at 3:31 AM, Adam Lee <adam8157@gmail.com> wrote:
>> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
>> before executing bluetoothd workarounds it. I assume the firmware
>> patching slows down hardware initialization then fails to connect.
>>
>> Any other possibility? I'm not a D-Bus guru :)
>
> Please provide more details, e.g. the bluetoothd logs showing the
> problems, btmon output and which steps you are using to reproduce it.
> If you are using bluetoothctl, tell us which commands you are using.
My guess is that either your driver is not using .setup hook to do the
firmware patching or it is returning before it has fully initialize
the hardware, so please also add more information what is happening on
the driver side.
--
Luiz Augusto von Dentz
^ permalink raw reply
* [PATCH BlueZ 4/4] android/avrcp-lib: Embed response code into handler table
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393594953-4970-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes the handlers code simpler as they don't need to care about
the response or reject opcode.
---
android/avrcp-lib.c | 16 ++++++++++++----
android/avrcp-lib.h | 4 ++--
unit/test-avrcp.c | 41 +++++++++++++++++++++--------------------
3 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index ea36063..34498d3 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -174,14 +174,22 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
goto reject;
}
- ret = handler->func(session, transaction, code, params_len,
- pdu->params, session->control_data);
+ ret = handler->func(session, transaction, params_len, pdu->params,
+ session->control_data);
if (ret < 0) {
- if (ret == -EAGAIN)
+ switch (ret) {
+ case -EAGAIN:
return ret;
- goto reject;
+ case -EINVAL:
+ pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
+ goto reject;
+ default:
+ pdu->params[0] = AVRCP_STATUS_INTERNAL_ERROR;
+ goto reject;
+ }
}
+ *code = handler->rsp;
pdu->params_len = htons(ret);
return AVRCP_HEADER_LENGTH + ret;
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 5cb0065..6738703 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -82,9 +82,9 @@ struct avrcp;
struct avrcp_control_handler {
uint8_t id;
uint8_t code;
+ uint8_t rsp;
ssize_t (*func) (struct avrcp *session, uint8_t transaction,
- uint8_t *code, uint16_t params_len, uint8_t *params,
- void *user_data);
+ uint16_t params_len, uint8_t *params, void *user_data);
};
struct avrcp_passthrough_handler {
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 160f1ce..c3b4f39 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -31,6 +31,7 @@
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include <sys/socket.h>
#include <glib.h>
@@ -306,61 +307,61 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
};
static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
uint32_t id = 0x001958;
if (params_len != 1)
- goto fail;
+ return -EINVAL;
switch (params[0]) {
case CAP_COMPANY_ID:
params[1] = 1;
hton24(¶ms[2], id);
- *code = AVC_CTYPE_STABLE;
return 5;
}
-fail:
- params[0] = AVRCP_STATUS_INVALID_PARAM;
- *code = AVC_CTYPE_REJECTED;
- return 1;
+ return -EINVAL;
}
static ssize_t avrcp_handle_list_attributes(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
DBG("");
params[0] = 0;
- *code = AVC_CTYPE_STABLE;
return 1;
}
static ssize_t avrcp_handle_get_player_attr_text(struct avrcp *session,
- uint8_t transaction, uint8_t *code,
- uint16_t params_len, uint8_t *params,
- void *user_data)
+ uint8_t transaction,
+ uint16_t params_len,
+ uint8_t *params,
+ void *user_data)
{
DBG("");
params[0] = 0;
- *code = AVC_CTYPE_STABLE;
return 1;
}
static const struct avrcp_control_handler control_handlers[] = {
- { AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
+ { AVRCP_GET_CAPABILITIES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_get_capabilities },
- { AVRCP_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
+ { AVRCP_LIST_PLAYER_ATTRIBUTES,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_list_attributes },
- { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
+ { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT,
+ AVC_CTYPE_STATUS, AVC_CTYPE_STABLE,
avrcp_handle_get_player_attr_text },
{ },
};
--
1.8.5.3
^ permalink raw reply related
* [PATCH BlueZ 3/4] android/avrcp-lib: Rework handler callback parameters
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393594953-4970-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This rework handler callback parameters to make it able to return
proper error such as -EAGAIN to implement asynchronous responses.
---
android/avrcp-lib.c | 12 +++++++++---
android/avrcp-lib.h | 5 +++--
unit/test-avrcp.c | 42 +++++++++++++++++++++---------------------
3 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 88d8875..ea36063 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -139,6 +139,7 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
struct avrcp_header *pdu = (void *) operands;
uint32_t company_id = ntoh24(pdu->company_id);
uint16_t params_len = ntohs(pdu->params_len);
+ ssize_t ret;
if (company_id != IEEEID_BTSIG) {
*code = AVC_CTYPE_NOT_IMPLEMENTED;
@@ -173,12 +174,17 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
goto reject;
}
- *code = handler->func(session, transaction, ¶ms_len,
+ ret = handler->func(session, transaction, code, params_len,
pdu->params, session->control_data);
+ if (ret < 0) {
+ if (ret == -EAGAIN)
+ return ret;
+ goto reject;
+ }
- pdu->params_len = htons(params_len);
+ pdu->params_len = htons(ret);
- return AVRCP_HEADER_LENGTH + params_len;
+ return AVRCP_HEADER_LENGTH + ret;
reject:
pdu->params_len = htons(1);
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 86e07bc..5cb0065 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -82,8 +82,9 @@ struct avrcp;
struct avrcp_control_handler {
uint8_t id;
uint8_t code;
- uint8_t (*func) (struct avrcp *session, uint8_t transaction,
- uint16_t *params_len, uint8_t *params, void *user_data);
+ ssize_t (*func) (struct avrcp *session, uint8_t transaction,
+ uint8_t *code, uint16_t params_len, uint8_t *params,
+ void *user_data);
};
struct avrcp_passthrough_handler {
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index db9cb92..160f1ce 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -305,54 +305,54 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
{ },
};
-static uint8_t avrcp_handle_get_capabilities(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
uint32_t id = 0x001958;
- DBG("params[0] %d params_len %d", params[0], *params_len);
-
- if (*params_len != 1)
+ if (params_len != 1)
goto fail;
switch (params[0]) {
case CAP_COMPANY_ID:
- *params_len = 5;
params[1] = 1;
hton24(¶ms[2], id);
- return AVC_CTYPE_STABLE;
+ *code = AVC_CTYPE_STABLE;
+ return 5;
}
fail:
- *params_len = 1;
params[0] = AVRCP_STATUS_INVALID_PARAM;
-
- return AVC_CTYPE_REJECTED;
+ *code = AVC_CTYPE_REJECTED;
+ return 1;
}
-static uint8_t avrcp_handle_list_attributes(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_list_attributes(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
DBG("");
- *params_len = 1;
params[0] = 0;
+ *code = AVC_CTYPE_STABLE;
- return AVC_CTYPE_STABLE;
+ return 1;
}
-static uint8_t avrcp_handle_get_player_attr_text(struct avrcp *session,
- uint8_t transaction, uint16_t *params_len,
- uint8_t *params, void *user_data)
+static ssize_t avrcp_handle_get_player_attr_text(struct avrcp *session,
+ uint8_t transaction, uint8_t *code,
+ uint16_t params_len, uint8_t *params,
+ void *user_data)
{
DBG("");
- *params_len = 1;
params[0] = 0;
+ *code = AVC_CTYPE_STABLE;
- return AVC_CTYPE_STABLE;
+ return 1;
}
static const struct avrcp_control_handler control_handlers[] = {
--
1.8.5.3
^ permalink raw reply related
* [PATCH BlueZ 2/4] android/avctp: Make handler return ssize_t
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1393594953-4970-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes possible to return errors such as -EAGAIN to indicate the
request would block and a response will be sent asynchronously.
---
android/avctp.c | 17 ++++++++++++-----
android/avctp.h | 2 +-
android/avrcp-lib.c | 2 +-
unit/test-avctp.c | 2 +-
4 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/android/avctp.c b/android/avctp.c
index bc1bd80..aa5abc9 100644
--- a/android/avctp.c
+++ b/android/avctp.c
@@ -311,7 +311,7 @@ static gboolean auto_release(gpointer user_data)
return FALSE;
}
-static size_t handle_panel_passthrough(struct avctp *session,
+static ssize_t handle_panel_passthrough(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -402,7 +402,7 @@ done:
return operand_count;
}
-static size_t handle_unit_info(struct avctp *session,
+static ssize_t handle_unit_info(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -428,7 +428,7 @@ static size_t handle_unit_info(struct avctp *session,
return operand_count;
}
-static size_t handle_subunit_info(struct avctp *session,
+static ssize_t handle_subunit_info(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
@@ -849,8 +849,9 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
uint8_t *operands, code, subunit;
struct avctp_header *avctp;
struct avc_header *avc;
- int ret, packet_size, operand_count, sock;
+ int packet_size, operand_count, sock;
struct avctp_pdu_handler *handler;
+ ssize_t ret;
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
goto failed;
@@ -910,10 +911,16 @@ static gboolean session_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
code = avc->code;
subunit = avc->subunit_type;
- packet_size += handler->cb(session, avctp->transaction, &code,
+ ret = handler->cb(session, avctp->transaction, &code,
&subunit, operands, operand_count,
handler->user_data);
+ if (ret < 0) {
+ if (ret == -EAGAIN)
+ return TRUE;
+ goto failed;
+ }
+ packet_size += ret;
avc->code = code;
avc->subunit_type = subunit;
diff --git a/android/avctp.h b/android/avctp.h
index dfa0ca6..2f419a2 100644
--- a/android/avctp.h
+++ b/android/avctp.h
@@ -113,7 +113,7 @@ struct avctp;
typedef bool (*avctp_passthrough_cb) (struct avctp *session,
uint8_t op, bool pressed,
void *user_data);
-typedef size_t (*avctp_control_pdu_cb) (struct avctp *session,
+typedef ssize_t (*avctp_control_pdu_cb) (struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data);
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index b1085f2..88d8875 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -129,7 +129,7 @@ void avrcp_shutdown(struct avrcp *session)
g_free(session);
}
-static size_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
+static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
uint8_t *code, uint8_t *subunit,
uint8_t *operands, size_t operand_count,
void *user_data)
diff --git a/unit/test-avctp.c b/unit/test-avctp.c
index be1dfd7..0759731 100644
--- a/unit/test-avctp.c
+++ b/unit/test-avctp.c
@@ -227,7 +227,7 @@ static void execute_context(struct context *context)
destroy_context(context);
}
-static size_t handler(struct avctp *session,
+static ssize_t handler(struct avctp *session,
uint8_t transaction, uint8_t *code,
uint8_t *subunit, uint8_t *operands,
size_t operand_count, void *user_data)
--
1.8.5.3
^ permalink raw reply related
* [PATCH BlueZ 1/4] android/avrcp-lib: Add avrcp_send function
From: Luiz Augusto von Dentz @ 2014-02-28 13:42 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds avrcp_send function which can be used to response to
outstanding requests.
---
android/avrcp-lib.c | 27 +++++++++++++++++++++++++++
android/avrcp-lib.h | 4 +++-
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index e71f95c..b1085f2 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -267,6 +267,33 @@ int avrcp_init_uinput(struct avrcp *session, const char *name,
return avctp_init_uinput(session->conn, name, address);
}
+int avrcp_send(struct avrcp *session, uint8_t transaction, uint8_t code,
+ uint8_t subunit, uint8_t pdu_id,
+ uint8_t *params, size_t params_len)
+{
+ struct avrcp_header *pdu = (void *) session->tx_buf;
+ size_t len = sizeof(*pdu);
+
+ memset(pdu, 0, len);
+
+ hton24(pdu->company_id, IEEEID_BTSIG);
+ pdu->pdu_id = pdu_id;
+ pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;
+
+ if (params_len > 0) {
+ len += params_len;
+
+ if (len > session->tx_mtu)
+ return -ENOBUFS;
+
+ memcpy(pdu->params, params, params_len);
+ pdu->params_len = htons(params_len);
+ }
+
+ return avctp_send_vendordep(session->conn, transaction, code, subunit,
+ session->tx_buf, len);
+}
+
static int avrcp_send_req(struct avrcp *session, uint8_t code, uint8_t subunit,
uint8_t pdu_id, uint8_t *params,
size_t params_len, avctp_rsp_cb func,
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index da8c990..86e07bc 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -105,7 +105,9 @@ void avrcp_set_passthrough_handlers(struct avrcp *session,
void *user_data);
int avrcp_init_uinput(struct avrcp *session, const char *name,
const char *address);
-
+int avrcp_send(struct avrcp *session, uint8_t transaction, uint8_t code,
+ uint8_t subunit, uint8_t pdu_id,
+ uint8_t *params, size_t params_len);
int avrcp_get_capabilities(struct avrcp *session, uint8_t param,
avctp_rsp_cb func, void *user_data);
int avrcp_list_player_attributes(struct avrcp *session, avctp_rsp_cb func,
--
1.8.5.3
^ permalink raw reply related
* [PATCH 6/6] android: Create comon header for IPC
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1393592969-4451-1-git-send-email-szymon.janc@tieto.com>
This header contains IPC specific structures and code not related to
BT and audio HAL protocols. This allows to fully decouple IPC from
HAL messages.
This is first step to make HAL part of IPC unit-testable and reusable
between BT HAL and audio HAL.
---
android/a2dp.c | 1 +
android/audio-msg.h | 7 ++----
android/bluetooth.c | 7 +++---
android/hal-audio.c | 7 +++---
android/hal-avrcp.c | 39 +++++++++++++++++----------------
android/hal-bluetooth.c | 9 ++++----
android/hal-handsfree.c | 9 ++++----
android/hal-hidhost.c | 5 +++--
android/hal-ipc.c | 11 +++++-----
android/hal-msg.h | 16 ++------------
android/handsfree.c | 1 +
android/hidhost.c | 1 +
android/ipc-common.h | 38 ++++++++++++++++++++++++++++++++
android/ipc-tester.c | 58 +++++++++++++++++++++++++------------------------
android/ipc.c | 16 +++++++-------
android/main.c | 1 +
android/pan.c | 1 +
android/socket.c | 2 +-
android/test-ipc.c | 56 +++++++++++++++++++++++++----------------------
19 files changed, 163 insertions(+), 122 deletions(-)
create mode 100644 android/ipc-common.h
diff --git a/android/a2dp.c b/android/a2dp.c
index 8e27413..180d015 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -40,6 +40,7 @@
#include "profiles/audio/a2dp-codecs.h"
#include "src/log.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "a2dp.h"
#include "utils.h"
diff --git a/android/audio-msg.h b/android/audio-msg.h
index d4fc68a..5981355 100644
--- a/android/audio-msg.h
+++ b/android/audio-msg.h
@@ -28,13 +28,10 @@ static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
#define AUDIO_SERVICE_ID 0
#define AUDIO_SERVICE_ID_MAX AUDIO_SERVICE_ID
-#define AUDIO_STATUS_SUCCESS 0x00
+#define AUDIO_STATUS_SUCCESS IPC_STATUS_SUCCESS
#define AUDIO_STATUS_FAILED 0x01
-#define AUDIO_OP_STATUS 0x00
-struct audio_status {
- uint8_t code;
-} __attribute__((packed));
+#define AUDIO_OP_STATUS IPC_OP_STATUS
#define AUDIO_OP_OPEN 0x01
struct audio_preset {
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 26493f7..8ad7d5d 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -46,6 +46,7 @@
#include "src/sdpd.h"
#include "src/log.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "utils.h"
#include "bluetooth.h"
@@ -1062,7 +1063,7 @@ static bool rssi_above_threshold(int old, int new)
static void update_new_device(struct device *dev, int8_t rssi,
const struct eir_data *eir)
{
- uint8_t buf[BLUEZ_HAL_MTU];
+ uint8_t buf[IPC_MTU];
struct hal_ev_device_found *ev = (void*) buf;
bdaddr_t android_bdaddr;
uint8_t android_type;
@@ -1115,7 +1116,7 @@ static void update_new_device(struct device *dev, int8_t rssi,
static void update_device(struct device *dev, int8_t rssi,
const struct eir_data *eir)
{
- uint8_t buf[BLUEZ_HAL_MTU];
+ uint8_t buf[IPC_MTU];
struct hal_ev_remote_device_props *ev = (void *) buf;
int size;
@@ -1157,7 +1158,7 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
int8_t rssi, bool confirm,
const uint8_t *data, uint8_t data_len)
{
- uint8_t buf[BLUEZ_HAL_MTU];
+ uint8_t buf[IPC_MTU];
struct eir_data eir;
struct device *dev;
diff --git a/android/hal-audio.c b/android/hal-audio.c
index e72e097..e1f3f0d 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -33,6 +33,7 @@
#include <sbc/sbc.h>
#include "audio-msg.h"
+#include "ipc-common.h"
#include "hal-log.h"
#include "hal-msg.h"
#include "../profiles/audio/a2dp-codecs.h"
@@ -614,9 +615,9 @@ static int audio_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len,
ssize_t ret;
struct msghdr msg;
struct iovec iv[2];
- struct hal_hdr cmd;
+ struct ipc_hdr cmd;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
- struct hal_status s;
+ struct ipc_status s;
size_t s_len = sizeof(s);
pthread_mutex_lock(&sk_mutex);
@@ -708,7 +709,7 @@ static int audio_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len,
}
if (cmd.opcode == AUDIO_OP_STATUS) {
- struct hal_status *s = rsp;
+ struct ipc_status *s = rsp;
if (sizeof(*s) != cmd.len) {
error("audio: Invalid status length");
diff --git a/android/hal-avrcp.c b/android/hal-avrcp.c
index a11aaa3..46e25a0 100644
--- a/android/hal-avrcp.c
+++ b/android/hal-avrcp.c
@@ -23,6 +23,7 @@
#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "hal-ipc.h"
static const btrc_callbacks_t *cbs = NULL;
@@ -252,7 +253,7 @@ static bt_status_t get_play_status_rsp(btrc_play_status_t status,
static bt_status_t list_player_app_attr_rsp(int num_attr,
btrc_player_attr_t *p_attrs)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_list_player_attrs *cmd = (void *) buf;
size_t len;
@@ -265,7 +266,7 @@ static bt_status_t list_player_app_attr_rsp(int num_attr,
return BT_STATUS_PARM_INVALID;
len = sizeof(*cmd) + num_attr;
- if (len > BLUEZ_HAL_MTU)
+ if (len > IPC_MTU)
return BT_STATUS_PARM_INVALID;
cmd->number = num_attr;
@@ -278,7 +279,7 @@ static bt_status_t list_player_app_attr_rsp(int num_attr,
static bt_status_t list_player_app_value_rsp(int num_val, uint8_t *p_vals)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_list_player_values *cmd = (void *) buf;
size_t len;
@@ -292,7 +293,7 @@ static bt_status_t list_player_app_value_rsp(int num_val, uint8_t *p_vals)
len = sizeof(*cmd) + num_val;
- if (len > BLUEZ_HAL_MTU)
+ if (len > IPC_MTU)
return BT_STATUS_PARM_INVALID;
cmd->number = num_val;
@@ -305,7 +306,7 @@ static bt_status_t list_player_app_value_rsp(int num_val, uint8_t *p_vals)
static bt_status_t get_player_app_value_rsp(btrc_player_settings_t *p_vals)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_get_player_attrs *cmd = (void *) buf;
size_t len, attrs_len;
int i;
@@ -322,7 +323,7 @@ static bt_status_t get_player_app_value_rsp(btrc_player_settings_t *p_vals)
sizeof(struct hal_avrcp_player_attr_value);
len = sizeof(*cmd) + attrs_len;
- if (len > BLUEZ_HAL_MTU)
+ if (len > IPC_MTU)
return BT_STATUS_PARM_INVALID;
cmd->number = p_vals->num_attr;
@@ -342,7 +343,7 @@ static int write_text(uint8_t *ptr, uint8_t id, uint8_t *text, size_t *len)
struct hal_avrcp_player_setting_text *value = (void *) ptr;
size_t attr_len = sizeof(*value);
- if (attr_len + *len > BLUEZ_HAL_MTU)
+ if (attr_len + *len > IPC_MTU)
return 0;
value->id = id;
@@ -351,8 +352,8 @@ static int write_text(uint8_t *ptr, uint8_t id, uint8_t *text, size_t *len)
*len += attr_len;
ptr += attr_len;
- if (value->len + *len > BLUEZ_HAL_MTU)
- value->len = BLUEZ_HAL_MTU - *len;
+ if (value->len + *len > IPC_MTU)
+ value->len = IPC_MTU - *len;
memcpy(value->text, text, value->len);
@@ -367,7 +368,7 @@ static uint8_t write_player_setting_text(uint8_t *ptr, uint8_t num_attr,
{
int i;
- for (i = 0; i < num_attr && *len < BLUEZ_HAL_MTU; i++) {
+ for (i = 0; i < num_attr && *len < IPC_MTU; i++) {
int ret;
ret = write_text(ptr, p_attrs[i].id, p_attrs[i].text, len);
@@ -383,7 +384,7 @@ static uint8_t write_player_setting_text(uint8_t *ptr, uint8_t num_attr,
static bt_status_t get_player_app_attr_text_rsp(int num_attr,
btrc_player_setting_text_t *p_attrs)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_get_player_attrs_text *cmd = (void *) buf;
uint8_t *ptr;
size_t len;
@@ -408,7 +409,7 @@ static bt_status_t get_player_app_attr_text_rsp(int num_attr,
static bt_status_t get_player_app_value_text_rsp(int num_val,
btrc_player_setting_text_t *p_vals)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_get_player_values_text *cmd = (void *) buf;
uint8_t *ptr;
size_t len;
@@ -436,7 +437,7 @@ static uint8_t write_element_attr_text(uint8_t *ptr, uint8_t num_attr,
{
int i;
- for (i = 0; i < num_attr && *len < BLUEZ_HAL_MTU; i++) {
+ for (i = 0; i < num_attr && *len < IPC_MTU; i++) {
int ret;
ret = write_text(ptr, p_attrs[i].attr_id, p_attrs[i].text, len);
@@ -452,7 +453,7 @@ static uint8_t write_element_attr_text(uint8_t *ptr, uint8_t num_attr,
static bt_status_t get_element_attr_rsp(uint8_t num_attr,
btrc_element_attr_val_t *p_attrs)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_get_element_attrs_text *cmd = (void *) buf;
size_t len;
uint8_t *ptr;
@@ -490,7 +491,7 @@ static bt_status_t set_player_app_value_rsp(btrc_status_t rsp_status)
static bt_status_t play_status_changed_rsp(btrc_notification_type_t type,
btrc_play_status_t *play_status)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
size_t len;
@@ -509,7 +510,7 @@ static bt_status_t play_status_changed_rsp(btrc_notification_type_t type,
static bt_status_t track_change_rsp(btrc_notification_type_t type,
btrc_uid_t *track)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
size_t len;
@@ -554,7 +555,7 @@ static bt_status_t track_reached_start_rsp(btrc_notification_type_t type)
static bt_status_t play_pos_changed_rsp(btrc_notification_type_t type,
uint32_t *song_pos)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
size_t len;
@@ -573,7 +574,7 @@ static bt_status_t play_pos_changed_rsp(btrc_notification_type_t type,
static bt_status_t settings_changed_rsp(btrc_notification_type_t type,
btrc_player_settings_t *player_setting)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_avrcp_register_notification *cmd = (void *) buf;
struct hal_avrcp_player_attr_value *attrs;
size_t len, param_len;
@@ -582,7 +583,7 @@ static bt_status_t settings_changed_rsp(btrc_notification_type_t type,
param_len = player_setting->num_attr * sizeof(*attrs);
len = sizeof(*cmd) + param_len;
- if (len > BLUEZ_HAL_MTU)
+ if (len > IPC_MTU)
return BT_STATUS_PARM_INVALID;
cmd->event = BTRC_EVT_APP_SETTINGS_CHANGED;
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 3160d7b..6871f5d 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -25,6 +25,7 @@
#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "hal-ipc.h"
#include "hal-utils.h"
@@ -525,7 +526,7 @@ static int get_adapter_property(bt_property_type_t type)
static int set_adapter_property(const bt_property_t *property)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
size_t len;
@@ -582,7 +583,7 @@ 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)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_set_remote_device_prop *cmd = (void *) buf;
size_t len;
@@ -792,7 +793,7 @@ static int dut_mode_configure(uint8_t enable)
static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
{
- char cmd_buf[BLUEZ_HAL_MTU];
+ char cmd_buf[IPC_MTU];
struct hal_cmd_dut_mode_send *cmd = (void *) cmd_buf;
size_t len;
@@ -813,7 +814,7 @@ static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
{
- char cmd_buf[BLUEZ_HAL_MTU];
+ char cmd_buf[IPC_MTU];
struct hal_cmd_le_test_mode *cmd = (void *) cmd_buf;
size_t len;
diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index ab65d95..1b150c3 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -23,6 +23,7 @@
#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "hal-ipc.h"
static const bthf_callbacks_t *cbs = NULL;
@@ -360,7 +361,7 @@ static bt_status_t device_status_notification(bthf_network_state_t state,
static bt_status_t cops_response(const char *cops)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_handsfree_cops_response *cmd = (void *) buf;
size_t len;
@@ -408,7 +409,7 @@ static bt_status_t cind_response(int svc, int num_active, int num_held,
static bt_status_t formatted_at_response(const char *rsp)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_handsfree_formatted_at_response *cmd = (void *) buf;
size_t len;
@@ -454,7 +455,7 @@ static bt_status_t clcc_response(int index, bthf_call_direction_t dir,
const char *number,
bthf_call_addrtype_t type)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_handsfree_clcc_response *cmd = (void *) buf;
size_t len;
@@ -489,7 +490,7 @@ static bt_status_t phone_state_change(int num_active, int num_held,
const char *number,
bthf_call_addrtype_t type)
{
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
struct hal_cmd_handsfree_phone_state_change *cmd = (void *) buf;
size_t len;
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index dcaf996..c758d2a 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -23,6 +23,7 @@
#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "hal-ipc.h"
static const bthh_callbacks_t *cbacks;
@@ -293,7 +294,7 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
bthh_report_type_t report_type,
char *report)
{
- uint8_t buf[BLUEZ_HAL_MTU];
+ uint8_t buf[IPC_MTU];
struct hal_cmd_hidhost_set_report *cmd = (void *) buf;
DBG("");
@@ -317,7 +318,7 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
{
- uint8_t buf[BLUEZ_HAL_MTU];
+ uint8_t buf[IPC_MTU];
struct hal_cmd_hidhost_send_data *cmd = (void *) buf;
DBG("");
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 1ba03f5..fda3228 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -31,6 +31,7 @@
#include "hal.h"
#include "hal-msg.h"
#include "hal-log.h"
+#include "ipc-common.h"
#include "hal-ipc.h"
#define CONNECT_TIMEOUT (5 * 1000)
@@ -64,7 +65,7 @@ void hal_ipc_unregister(uint8_t service)
static void handle_msg(void *buf, ssize_t len)
{
- struct hal_hdr *msg = buf;
+ struct ipc_hdr *msg = buf;
const struct hal_ipc_handler *handler;
uint8_t opcode;
@@ -130,7 +131,7 @@ static void *notification_handler(void *data)
struct iovec iv;
struct cmsghdr *cmsg;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
ssize_t ret;
int fd;
@@ -320,9 +321,9 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
ssize_t ret;
struct msghdr msg;
struct iovec iv[2];
- struct hal_hdr cmd;
+ struct ipc_hdr cmd;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
- struct hal_status s;
+ struct ipc_status s;
size_t s_len = sizeof(s);
if (cmd_sk < 0) {
@@ -418,7 +419,7 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
}
if (cmd.opcode == HAL_OP_STATUS) {
- struct hal_status *s = rsp;
+ struct ipc_status *s = rsp;
if (sizeof(*s) != cmd.len) {
error("Invalid status length, aborting");
diff --git a/android/hal-msg.h b/android/hal-msg.h
index bde9717..1e12868 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -21,17 +21,8 @@
*
*/
-#define BLUEZ_HAL_MTU 1024
-
static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
-struct hal_hdr {
- uint8_t service_id;
- uint8_t opcode;
- uint16_t len;
- uint8_t payload[0];
-} __attribute__((packed));
-
#define HAL_MINIMUM_EVENT 0x81
#define HAL_SERVICE_ID_CORE 0
@@ -49,7 +40,7 @@ struct hal_hdr {
/* Core Service */
-#define HAL_STATUS_SUCCESS 0x00
+#define HAL_STATUS_SUCCESS IPC_STATUS_SUCCESS
#define HAL_STATUS_FAILED 0x01
#define HAL_STATUS_NOT_READY 0x02
#define HAL_STATUS_NOMEM 0x03
@@ -61,10 +52,7 @@ struct hal_hdr {
#define HAL_STATUS_AUTH_FAILURE 0x09
#define HAL_STATUS_REMOTE_DEVICE_DOWN 0x0a
-#define HAL_OP_STATUS 0x00
-struct hal_status {
- uint8_t code;
-} __attribute__((packed));
+#define HAL_OP_STATUS IPC_OP_STATUS
#define HAL_OP_REGISTER_MODULE 0x01
struct hal_cmd_register_module {
diff --git a/android/handsfree.c b/android/handsfree.c
index ef8c776..81ddcc7 100644
--- a/android/handsfree.c
+++ b/android/handsfree.c
@@ -39,6 +39,7 @@
#include "src/shared/hfp.h"
#include "btio/btio.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "handsfree.h"
#include "bluetooth.h"
diff --git a/android/hidhost.c b/android/hidhost.c
index 0c6eb7d..e469210 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -44,6 +44,7 @@
#include "src/log.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "hidhost.h"
#include "utils.h"
diff --git a/android/ipc-common.h b/android/ipc-common.h
new file mode 100644
index 0000000..27736e4
--- /dev/null
+++ b/android/ipc-common.h
@@ -0,0 +1,38 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#define IPC_MTU 1024
+
+#define IPC_STATUS_SUCCESS 0x00
+
+struct ipc_hdr {
+ uint8_t service_id;
+ uint8_t opcode;
+ uint16_t len;
+ uint8_t payload[0];
+} __attribute__((packed));
+
+#define IPC_OP_STATUS 0x00
+struct ipc_status {
+ uint8_t code;
+} __attribute__((packed));
diff --git a/android/ipc-tester.c b/android/ipc-tester.c
index eab8ea5..2378101 100644
--- a/android/ipc-tester.c
+++ b/android/ipc-tester.c
@@ -45,6 +45,8 @@
#include "src/shared/hciemu.h"
#include "hal-msg.h"
+#include "ipc-common.h"
+
#include <cutils/properties.h>
#define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
@@ -72,7 +74,7 @@ struct generic_data {
};
struct regmod_msg {
- struct hal_hdr header;
+ struct ipc_hdr header;
struct hal_cmd_register_module cmd;
} __attribute__((packed));
@@ -413,8 +415,8 @@ static gboolean check_for_daemon(gpointer user_data)
static bool setup_module(int service_id)
{
- struct hal_hdr response;
- struct hal_hdr expected_response;
+ struct ipc_hdr response;
+ struct ipc_hdr expected_response;
struct regmod_msg btmodule_msg = {
.header = {
@@ -564,7 +566,7 @@ static void ipc_send_tc(const void *data)
#define test_opcode_valid(_name, _service, _opcode, _len, _servicelist...) \
do { \
- static struct hal_hdr hdr = { \
+ static struct ipc_hdr hdr = { \
.service_id = _service, \
.opcode = _opcode, \
.len = _len, \
@@ -578,8 +580,8 @@ static void ipc_send_tc(const void *data)
} while (0)
struct vardata {
- struct hal_hdr hdr;
- uint8_t buf[BLUEZ_HAL_MTU];
+ struct ipc_hdr hdr;
+ uint8_t buf[IPC_MTU];
} __attribute__((packed));
#define test_datasize_valid(_name, _service, _opcode, _hlen, _addatasize, \
@@ -642,24 +644,24 @@ static struct malformed_data3_struct malformed_data3_msg = {
. redundant_data = 666,
};
-struct hal_hdr enable_unknown_service_hdr = {
+struct ipc_hdr enable_unknown_service_hdr = {
.service_id = HAL_SERVICE_ID_MAX + 1,
.opcode = HAL_OP_REGISTER_MODULE,
.len = 0,
};
-struct hal_hdr enable_bt_service_hdr = {
+struct ipc_hdr enable_bt_service_hdr = {
.service_id = HAL_SERVICE_ID_BLUETOOTH,
.opcode = HAL_OP_ENABLE,
.len = 0,
};
struct bt_set_adapter_prop_data {
- struct hal_hdr hdr;
+ struct ipc_hdr hdr;
struct hal_cmd_set_adapter_prop prop;
/* data placeholder for hal_cmd_set_adapter_prop.val[0] */
- uint8_t buf[BLUEZ_HAL_MTU - sizeof(struct hal_hdr) -
+ uint8_t buf[IPC_MTU - sizeof(struct ipc_hdr) -
sizeof(struct hal_cmd_set_adapter_prop)];
} __attribute__((packed));
@@ -692,11 +694,11 @@ static struct bt_set_adapter_prop_data bt_set_adapter_prop_data_unders = {
};
struct bt_set_remote_prop_data {
- struct hal_hdr hdr;
+ struct ipc_hdr hdr;
struct hal_cmd_set_remote_device_prop prop;
/* data placeholder for hal_cmd_set_remote_device_prop.val[0] */
- uint8_t buf[BLUEZ_HAL_MTU - sizeof(struct hal_hdr) -
+ uint8_t buf[IPC_MTU - sizeof(struct ipc_hdr) -
sizeof(struct hal_cmd_set_remote_device_prop)];
} __attribute__((packed));
@@ -727,11 +729,11 @@ static struct bt_set_remote_prop_data bt_set_remote_prop_data_unders = {
};
struct hidhost_set_info_data {
- struct hal_hdr hdr;
+ struct ipc_hdr hdr;
struct hal_cmd_hidhost_set_info info;
/* data placeholder for hal_cmd_hidhost_set_info.descr[0] field */
- uint8_t buf[BLUEZ_HAL_MTU - sizeof(struct hal_hdr) -
+ uint8_t buf[IPC_MTU - sizeof(struct ipc_hdr) -
sizeof(struct hal_cmd_hidhost_set_info)];
} __attribute__((packed));
@@ -762,11 +764,11 @@ static struct hidhost_set_info_data hidhost_set_info_data_unders = {
};
struct hidhost_set_report_data {
- struct hal_hdr hdr;
+ struct ipc_hdr hdr;
struct hal_cmd_hidhost_set_report report;
/* data placeholder for hal_cmd_hidhost_set_report.data[0] field */
- uint8_t buf[BLUEZ_HAL_MTU - sizeof(struct hal_hdr) -
+ uint8_t buf[IPC_MTU - sizeof(struct ipc_hdr) -
sizeof(struct hal_cmd_hidhost_set_report)];
} __attribute__((packed));
@@ -797,11 +799,11 @@ static struct hidhost_set_report_data hidhost_set_report_data_unders = {
};
struct hidhost_send_data_data {
- struct hal_hdr hdr;
+ struct ipc_hdr hdr;
struct hal_cmd_hidhost_send_data hiddata;
/* data placeholder for hal_cmd_hidhost_send_data.data[0] field */
- uint8_t buf[BLUEZ_HAL_MTU - sizeof(struct hal_hdr) -
+ uint8_t buf[IPC_MTU - sizeof(struct ipc_hdr) -
sizeof(struct hal_cmd_hidhost_send_data)];
} __attribute__((packed));
@@ -935,14 +937,14 @@ int main(int argc, char *argv[])
test_generic("Data size BT Set Adapter Prop Vardata+",
ipc_send_tc, setup, teardown,
&bt_set_adapter_prop_data_overs,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_set_adapter_prop) +
sizeof(set_name)),
HAL_SERVICE_ID_BLUETOOTH);
test_generic("Data size BT Set Adapter Prop Vardata+",
ipc_send_tc, setup, teardown,
&bt_set_adapter_prop_data_unders,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_set_adapter_prop) +
sizeof(set_name)),
HAL_SERVICE_ID_BLUETOOTH);
@@ -973,14 +975,14 @@ int main(int argc, char *argv[])
test_generic("Data size BT Set Remote Prop Vardata+",
ipc_send_tc, setup, teardown,
&bt_set_remote_prop_data_overs,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_set_remote_device_prop) +
sizeof(set_name)),
HAL_SERVICE_ID_BLUETOOTH);
test_generic("Data size BT Set Remote Prop Vardata-",
ipc_send_tc, setup, teardown,
&bt_set_remote_prop_data_unders,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_set_remote_device_prop) +
sizeof(set_name)),
HAL_SERVICE_ID_BLUETOOTH);
@@ -1127,14 +1129,14 @@ int main(int argc, char *argv[])
test_generic("Data size HIDHOST Set Info Vardata+",
ipc_send_tc, setup, teardown,
&hidhost_set_info_data_overs,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_set_info) +
sizeof(set_info_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
test_generic("Data size HIDHOST Set Info Vardata-",
ipc_send_tc, setup, teardown,
&hidhost_set_info_data_unders,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_set_info) +
sizeof(set_info_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
@@ -1173,14 +1175,14 @@ int main(int argc, char *argv[])
test_generic("Data size HIDHOST Set Report Vardata+",
ipc_send_tc, setup, teardown,
&hidhost_set_report_data_overs,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_set_report) +
sizeof(set_rep_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
test_generic("Data size HIDHOST Set Report Vardata-",
ipc_send_tc, setup, teardown,
&hidhost_set_report_data_unders,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_set_report) +
sizeof(set_rep_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
@@ -1195,14 +1197,14 @@ int main(int argc, char *argv[])
test_generic("Data size HIDHOST Send Vardata+",
ipc_send_tc, setup, teardown,
&hidhost_send_data_overs,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_send_data) +
sizeof(send_data_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
test_generic("Data size HIDHOST Send Vardata-",
ipc_send_tc, setup, teardown,
&hidhost_send_data_unders,
- (sizeof(struct hal_hdr) +
+ (sizeof(struct ipc_hdr) +
sizeof(struct hal_cmd_hidhost_send_data) +
sizeof(send_data_data)),
HAL_SERVICE_ID_BLUETOOTH, HAL_SERVICE_ID_HIDHOST);
diff --git a/android/ipc.c b/android/ipc.c
index 6b14bbe..8cd34ea 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -36,7 +36,7 @@
#include <unistd.h>
#include <glib.h>
-#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "src/log.h"
@@ -92,7 +92,7 @@ static void ipc_disconnect(struct ipc *ipc, bool in_cleanup)
static int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
const void *buf, ssize_t len)
{
- const struct hal_hdr *msg = buf;
+ const struct ipc_hdr *msg = buf;
const struct ipc_handler *handler;
if (len < (ssize_t) sizeof(*msg)) {
@@ -118,7 +118,7 @@ static int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
}
/* if opcode is valid */
- if (msg->opcode == HAL_OP_STATUS ||
+ if (msg->opcode == IPC_OP_STATUS ||
msg->opcode > handlers[msg->service_id].size) {
DBG("invalid opcode 0x%x for service 0x%x", msg->opcode,
msg->service_id);
@@ -146,7 +146,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
{
struct ipc *ipc = user_data;
- char buf[BLUEZ_HAL_MTU];
+ char buf[IPC_MTU];
ssize_t ret;
int fd, err;
@@ -329,7 +329,7 @@ static void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
{
struct msghdr msg;
struct iovec iv[2];
- struct hal_hdr m;
+ struct ipc_hdr m;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
struct cmsghdr *cmsg;
@@ -374,19 +374,19 @@ static void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
void ipc_send_rsp(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
uint8_t status)
{
- struct hal_status s;
+ struct ipc_status s;
int sk;
sk = g_io_channel_unix_get_fd(ipc->cmd_io);
- if (status == HAL_STATUS_SUCCESS) {
+ if (status == IPC_STATUS_SUCCESS) {
ipc_send(sk, service_id, opcode, 0, NULL, -1);
return;
}
s.code = status;
- ipc_send(sk, service_id, HAL_OP_STATUS, sizeof(s), &s, -1);
+ ipc_send(sk, service_id, IPC_OP_STATUS, sizeof(s), &s, -1);
}
void ipc_send_rsp_full(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
diff --git a/android/main.c b/android/main.c
index bd1bcb9..a6742ef 100644
--- a/android/main.c
+++ b/android/main.c
@@ -48,6 +48,7 @@
#include "lib/bluetooth.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "bluetooth.h"
#include "socket.h"
diff --git a/android/pan.c b/android/pan.c
index b4a3494..1e404ab 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -50,6 +50,7 @@
#include "src/log.h"
#include "hal-msg.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "utils.h"
#include "bluetooth.h"
diff --git a/android/socket.c b/android/socket.c
index d463255..ee98b54 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -39,7 +39,7 @@
#include "src/log.h"
#include "hal-msg.h"
-#include "hal-ipc.h"
+#include "ipc-common.h"
#include "ipc.h"
#include "utils.h"
#include "bluetooth.h"
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 6172991..bb7d15f 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -39,9 +39,13 @@
#include <glib.h>
#include "src/shared/util.h"
#include "src/log.h"
-#include "android/hal-msg.h"
+#include "android/ipc-common.h"
#include "android/ipc.h"
+static const char HAL_SK_PATH[] = "\0test_hal_socket";
+
+#define SERVICE_ID_MAX 10
+
struct test_data {
bool disconnect;
const void *cmd;
@@ -79,11 +83,11 @@ static gboolean cmd_watch(GIOChannel *io, GIOCondition cond,
{
struct context *context = user_data;
const struct test_data *test_data = context->data;
- const struct hal_hdr *sent_msg = test_data->cmd;
+ const struct ipc_hdr *sent_msg = test_data->cmd;
uint8_t buf[128];
int sk;
- struct hal_hdr success_resp = {
+ struct ipc_hdr success_resp = {
.service_id = sent_msg->service_id,
.opcode = sent_msg->opcode,
.len = 0,
@@ -98,8 +102,8 @@ static gboolean cmd_watch(GIOChannel *io, GIOCondition cond,
sk = g_io_channel_unix_get_fd(io);
- g_assert(read(sk, buf, sizeof(buf)) == sizeof(struct hal_hdr));
- g_assert(!memcmp(&success_resp, buf, sizeof(struct hal_hdr)));
+ g_assert(read(sk, buf, sizeof(buf)) == sizeof(struct ipc_hdr));
+ g_assert(!memcmp(&success_resp, buf, sizeof(struct ipc_hdr)));
context_quit(context);
@@ -180,7 +184,7 @@ static struct context *create_context(gconstpointer data)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
+ memcpy(addr.sun_path, HAL_SK_PATH, sizeof(HAL_SK_PATH));
ret = bind(sk, (struct sockaddr *) &addr, sizeof(addr));
g_assert(ret == 0);
@@ -236,8 +240,8 @@ static void test_init(gconstpointer data)
{
struct context *context = create_context(data);
- ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, true, NULL, NULL);
+ ipc = ipc_init(HAL_SK_PATH, sizeof(HAL_SK_PATH), SERVICE_ID_MAX,
+ true, NULL, NULL);
g_assert(ipc);
@@ -287,8 +291,8 @@ static void test_cmd(gconstpointer data)
{
struct context *context = create_context(data);
- ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, true, disconnected, context);
+ ipc = ipc_init(HAL_SK_PATH, sizeof(HAL_SK_PATH), SERVICE_ID_MAX,
+ true, disconnected, context);
g_assert(ipc);
@@ -305,8 +309,8 @@ static void test_cmd_reg(gconstpointer data)
struct context *context = create_context(data);
const struct test_data *test_data = context->data;
- ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, true, disconnected, context);
+ ipc = ipc_init(HAL_SK_PATH, sizeof(HAL_SK_PATH), SERVICE_ID_MAX,
+ true, disconnected, context);
g_assert(ipc);
@@ -325,8 +329,8 @@ static void test_cmd_reg_1(gconstpointer data)
{
struct context *context = create_context(data);
- ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, true, disconnected, context);
+ ipc = ipc_init(HAL_SK_PATH, sizeof(HAL_SK_PATH), SERVICE_ID_MAX,
+ true, disconnected, context);
g_assert(ipc);
@@ -357,13 +361,13 @@ static void test_cmd_handler_invalid(const void *buf, uint16_t len)
static const struct test_data test_init_1 = {};
-static const struct hal_hdr test_cmd_1_hdr = {
+static const struct ipc_hdr test_cmd_1_hdr = {
.service_id = 0,
.opcode = 1,
.len = 0
};
-static const struct hal_hdr test_cmd_2_hdr = {
+static const struct ipc_hdr test_cmd_2_hdr = {
.service_id = 0,
.opcode = 2,
.len = 0
@@ -443,8 +447,8 @@ static const struct test_data test_cmd_hdr_invalid = {
#define VARDATA_EX1 "some data example"
struct vardata {
- struct hal_hdr hdr;
- uint8_t data[BLUEZ_HAL_MTU - sizeof(struct hal_hdr)];
+ struct ipc_hdr hdr;
+ uint8_t data[IPC_MTU - sizeof(struct ipc_hdr)];
} __attribute__((packed));
static const struct vardata test_cmd_vardata = {
@@ -460,7 +464,7 @@ static const struct ipc_handler cmd_vardata_handlers[] = {
static const struct test_data test_cmd_vardata_valid = {
.cmd = &test_cmd_vardata,
- .cmd_size = sizeof(struct hal_hdr) + sizeof(VARDATA_EX1),
+ .cmd_size = sizeof(struct ipc_hdr) + sizeof(VARDATA_EX1),
.service = 0,
.handlers = cmd_vardata_handlers,
.handlers_size = 1,
@@ -472,7 +476,7 @@ static const struct ipc_handler cmd_vardata_handlers_valid2[] = {
static const struct test_data test_cmd_vardata_valid_2 = {
.cmd = &test_cmd_vardata,
- .cmd_size = sizeof(struct hal_hdr) + sizeof(VARDATA_EX1),
+ .cmd_size = sizeof(struct ipc_hdr) + sizeof(VARDATA_EX1),
.service = 0,
.handlers = cmd_vardata_handlers_valid2,
.handlers_size = 1,
@@ -480,22 +484,22 @@ static const struct test_data test_cmd_vardata_valid_2 = {
static const struct test_data test_cmd_vardata_invalid_1 = {
.cmd = &test_cmd_vardata,
- .cmd_size = sizeof(struct hal_hdr) + sizeof(VARDATA_EX1) - 1,
+ .cmd_size = sizeof(struct ipc_hdr) + sizeof(VARDATA_EX1) - 1,
.service = 0,
.handlers = cmd_vardata_handlers,
.handlers_size = 1,
.disconnect = true,
};
-static const struct hal_hdr test_cmd_service_offrange_hdr = {
- .service_id = HAL_SERVICE_ID_MAX + 1,
+static const struct ipc_hdr test_cmd_service_offrange_hdr = {
+ .service_id = SERVICE_ID_MAX + 1,
.opcode = 1,
.len = 0
};
static const struct test_data test_cmd_service_offrange = {
.cmd = &test_cmd_service_offrange_hdr,
- .cmd_size = sizeof(struct hal_hdr),
+ .cmd_size = sizeof(struct ipc_hdr),
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
@@ -511,7 +515,7 @@ static const struct vardata test_cmd_invalid_data_1 = {
static const struct test_data test_cmd_msg_invalid_1 = {
.cmd = &test_cmd_invalid_data_1,
- .cmd_size = sizeof(struct hal_hdr) + sizeof(VARDATA_EX1) - 1,
+ .cmd_size = sizeof(struct ipc_hdr) + sizeof(VARDATA_EX1) - 1,
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
@@ -527,7 +531,7 @@ static const struct vardata test_cmd_invalid_data_2 = {
static const struct test_data test_cmd_msg_invalid_2 = {
.cmd = &test_cmd_invalid_data_2,
- .cmd_size = sizeof(struct hal_hdr) + sizeof(VARDATA_EX1),
+ .cmd_size = sizeof(struct ipc_hdr) + sizeof(VARDATA_EX1),
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
--
1.8.3.2
^ permalink raw reply related
* [PATCH 5/6] android/a2dp: Use common IPC for audio socket
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1393592969-4451-1-git-send-email-szymon.janc@tieto.com>
This makes audio HAL to use same code for IPC as BT HAL.
---
android/Android.mk | 1 -
android/Makefile.am | 1 -
android/a2dp.c | 73 ++++++++++++++++---------
android/audio-ipc.c | 155 ----------------------------------------------------
android/audio-ipc.h | 31 -----------
android/audio-msg.h | 1 +
android/ipc.c | 8 +--
android/ipc.h | 7 ---
8 files changed, 52 insertions(+), 225 deletions(-)
delete mode 100644 android/audio-ipc.c
delete mode 100644 android/audio-ipc.h
diff --git a/android/Android.mk b/android/Android.mk
index 82c834b..56b86ba 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -35,7 +35,6 @@ LOCAL_SRC_FILES := \
bluez/android/hidhost.c \
bluez/android/socket.c \
bluez/android/ipc.c \
- bluez/android/audio-ipc.c \
bluez/android/avdtp.c \
bluez/android/a2dp.c \
bluez/android/avctp.c \
diff --git a/android/Makefile.am b/android/Makefile.am
index 232f3f3..05fe372 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -32,7 +32,6 @@ android_bluetoothd_SOURCES = android/main.c \
android/bluetooth.h android/bluetooth.c \
android/hidhost.h android/hidhost.c \
android/ipc.h android/ipc.c \
- android/audio-ipc.h android/audio-ipc.c \
android/avdtp.h android/avdtp.c \
android/a2dp.h android/a2dp.c \
android/avctp.h android/avctp.c \
diff --git a/android/a2dp.c b/android/a2dp.c
index b05d4bd..8e27413 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -47,7 +47,6 @@
#include "avdtp.h"
#include "avrcp.h"
#include "audio-msg.h"
-#include "audio-ipc.h"
#define L2CAP_PSM_AVDTP 0x19
#define SVC_HINT_CAPTURING 0x08
@@ -64,6 +63,7 @@ static guint audio_retry_id = 0;
static bool audio_retrying = false;
static struct ipc *hal_ipc = NULL;
+static struct ipc *audio_ipc = NULL;
struct a2dp_preset {
void *data;
@@ -1298,12 +1298,14 @@ static void bt_audio_open(const void *buf, uint16_t len)
g_slist_free(presets);
- audio_ipc_send_rsp_full(AUDIO_OP_OPEN, sizeof(rsp), &rsp, -1);
+ ipc_send_rsp_full(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_OPEN,
+ sizeof(rsp), &rsp, -1);
return;
failed:
- audio_ipc_send_rsp(AUDIO_OP_OPEN, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_OPEN,
+ AUDIO_STATUS_FAILED);
}
static struct a2dp_endpoint *find_endpoint(uint8_t id)
@@ -1330,14 +1332,16 @@ static void bt_audio_close(const void *buf, uint16_t len)
endpoint = find_endpoint(cmd->id);
if (!endpoint) {
error("Unable to find endpoint %u", cmd->id);
- audio_ipc_send_rsp(AUDIO_OP_CLOSE, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_CLOSE,
+ AUDIO_STATUS_FAILED);
return;
}
endpoints = g_slist_remove(endpoints, endpoint);
unregister_endpoint(endpoint);
- audio_ipc_send_rsp(AUDIO_OP_CLOSE, AUDIO_STATUS_SUCCESS);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_CLOSE,
+ AUDIO_STATUS_SUCCESS);
}
static void bt_stream_open(const void *buf, uint16_t len)
@@ -1353,14 +1357,16 @@ static void bt_stream_open(const void *buf, uint16_t len)
setup = find_setup(cmd->id);
if (!setup) {
error("Unable to find stream for endpoint %u", cmd->id);
- audio_ipc_send_rsp(AUDIO_OP_OPEN_STREAM, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
+ AUDIO_STATUS_FAILED);
return;
}
if (!avdtp_stream_get_transport(setup->stream, &fd, NULL, &omtu,
NULL)) {
error("avdtp_stream_get_transport: failed");
- audio_ipc_send_rsp(AUDIO_OP_OPEN_STREAM, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
+ AUDIO_STATUS_FAILED);
return;
}
@@ -1371,7 +1377,8 @@ static void bt_stream_open(const void *buf, uint16_t len)
rsp->preset->len = setup->preset->len;
memcpy(rsp->preset->data, setup->preset->data, setup->preset->len);
- audio_ipc_send_rsp_full(AUDIO_OP_OPEN_STREAM, len, rsp, fd);
+ ipc_send_rsp_full(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
+ len, rsp, fd);
g_free(rsp);
}
@@ -1396,12 +1403,14 @@ static void bt_stream_close(const void *buf, uint16_t len)
goto failed;
}
- audio_ipc_send_rsp(AUDIO_OP_CLOSE_STREAM, AUDIO_STATUS_SUCCESS);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_CLOSE_STREAM,
+ AUDIO_STATUS_SUCCESS);
return;
failed:
- audio_ipc_send_rsp(AUDIO_OP_CLOSE_STREAM, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_CLOSE_STREAM,
+ AUDIO_STATUS_FAILED);
}
static void bt_stream_resume(const void *buf, uint16_t len)
@@ -1426,12 +1435,14 @@ static void bt_stream_resume(const void *buf, uint16_t len)
}
}
- audio_ipc_send_rsp(AUDIO_OP_RESUME_STREAM, AUDIO_STATUS_SUCCESS);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_RESUME_STREAM,
+ AUDIO_STATUS_SUCCESS);
return;
failed:
- audio_ipc_send_rsp(AUDIO_OP_RESUME_STREAM, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_RESUME_STREAM,
+ AUDIO_STATUS_FAILED);
}
static void bt_stream_suspend(const void *buf, uint16_t len)
@@ -1454,12 +1465,14 @@ static void bt_stream_suspend(const void *buf, uint16_t len)
goto failed;
}
- audio_ipc_send_rsp(AUDIO_OP_SUSPEND_STREAM, AUDIO_STATUS_SUCCESS);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_SUSPEND_STREAM,
+ AUDIO_STATUS_SUCCESS);
return;
failed:
- audio_ipc_send_rsp(AUDIO_OP_SUSPEND_STREAM, AUDIO_STATUS_FAILED);
+ ipc_send_rsp(audio_ipc, AUDIO_SERVICE_ID, AUDIO_OP_SUSPEND_STREAM,
+ AUDIO_STATUS_FAILED);
}
static const struct ipc_handler audio_handlers[] = {
@@ -1490,26 +1503,33 @@ static void bt_audio_unregister(void)
g_slist_free_full(setups, setup_free);
setups = NULL;
- audio_ipc_cleanup();
+ ipc_cleanup(audio_ipc);
+ audio_ipc = NULL;
}
-static void bt_audio_register(GDestroyNotify destroy)
+static bool bt_audio_register(ipc_disconnect_cb disconnect)
{
DBG("");
- audio_ipc_init(destroy);
+ audio_ipc = ipc_init(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
+ AUDIO_SERVICE_ID_MAX, false, disconnect, NULL);
+ if (!audio_ipc)
+ return false;
+
+ ipc_register(audio_ipc, AUDIO_SERVICE_ID, audio_handlers,
+ G_N_ELEMENTS(audio_handlers));
- audio_ipc_register(audio_handlers, G_N_ELEMENTS(audio_handlers));
+ return true;
}
static gboolean audio_retry_register(void *data)
{
- GDestroyNotify destroy = data;
+ ipc_disconnect_cb cb = data;
audio_retry_id = 0;
audio_retrying = true;
- bt_audio_register(destroy);
+ bt_audio_register(cb);
return FALSE;
}
@@ -1581,9 +1601,8 @@ bool bt_a2dp_register(struct ipc *ipc, const bdaddr_t *addr)
ipc_register(hal_ipc, HAL_SERVICE_ID_A2DP, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
- bt_audio_register(audio_disconnected);
-
- return true;
+ if (bt_audio_register(audio_disconnected))
+ return true;
fail:
g_io_channel_shutdown(server, TRUE, NULL);
@@ -1608,8 +1627,6 @@ void bt_a2dp_unregister(void)
ipc_unregister(hal_ipc, HAL_SERVICE_ID_A2DP);
hal_ipc = NULL;
- audio_ipc_unregister();
-
bt_adapter_remove_record(record_id);
record_id = 0;
@@ -1619,5 +1636,9 @@ void bt_a2dp_unregister(void)
server = NULL;
}
- audio_ipc_cleanup();
+ if (audio_ipc) {
+ ipc_unregister(audio_ipc, AUDIO_SERVICE_ID);
+ ipc_cleanup(audio_ipc);
+ audio_ipc = NULL;
+ }
}
diff --git a/android/audio-ipc.c b/android/audio-ipc.c
deleted file mode 100644
index ce2d86d..0000000
--- a/android/audio-ipc.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stddef.h>
-#include <errno.h>
-#include <stdint.h>
-#include <string.h>
-#include <signal.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <glib.h>
-
-#include "src/log.h"
-#include "ipc.h"
-#include "audio-msg.h"
-#include "audio-ipc.h"
-
-static GIOChannel *audio_io = NULL;
-
-static struct service_handler service;
-
-static gboolean audio_watch_cb(GIOChannel *io, GIOCondition cond,
- gpointer user_data)
-{
- GDestroyNotify destroy = user_data;
- char buf[BLUEZ_AUDIO_MTU];
- ssize_t ret;
- int fd, err;
-
- if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
- info("Audio IPC: command socket closed");
- goto fail;
- }
-
- fd = g_io_channel_unix_get_fd(io);
-
- ret = read(fd, buf, sizeof(buf));
- if (ret < 0) {
- error("Audio IPC: command read failed (%s)", strerror(errno));
- goto fail;
- }
-
- err = ipc_handle_msg(&service, AUDIO_SERVICE_ID, buf, ret);
- if (err < 0) {
- error("Audio IPC: failed to handle message (%s)",
- strerror(-err));
- goto fail;
- }
-
- return TRUE;
-
-fail:
- audio_ipc_cleanup();
- if (destroy)
- destroy(NULL);
- return FALSE;
-}
-
-static gboolean audio_connect_cb(GIOChannel *io, GIOCondition cond,
- gpointer user_data)
-{
- GDestroyNotify destroy = user_data;
-
- DBG("");
-
- if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
- error("Audio IPC: socket connect failed");
- audio_ipc_cleanup();
- if (destroy)
- destroy(NULL);
- return FALSE;
- }
-
- cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-
- g_io_add_watch(audio_io, cond, audio_watch_cb, user_data);
-
- info("Audio IPC: successfully connected");
-
- return FALSE;
-}
-
-void audio_ipc_init(GDestroyNotify destroy)
-{
- audio_io = ipc_connect(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
- audio_connect_cb, destroy);
-}
-
-void audio_ipc_cleanup(void)
-{
- if (audio_io) {
- g_io_channel_shutdown(audio_io, TRUE, NULL);
- g_io_channel_unref(audio_io);
- audio_io = NULL;
- }
-}
-
-void audio_ipc_register(const struct ipc_handler *handlers, uint8_t size)
-{
- service.handler = handlers;
- service.size = size;
-}
-
-void audio_ipc_unregister(void)
-{
- service.handler = NULL;
- service.size = 0;
-}
-
-void audio_ipc_send_rsp(uint8_t opcode, uint8_t status)
-{
- struct audio_status s;
- int sk;
-
- sk = g_io_channel_unix_get_fd(audio_io);
-
- if (status == AUDIO_STATUS_SUCCESS) {
- ipc_send(sk, AUDIO_SERVICE_ID, opcode, 0, NULL, -1);
- return;
- }
-
- s.code = status;
-
- ipc_send(sk, AUDIO_SERVICE_ID, AUDIO_OP_STATUS, sizeof(s), &s, -1);
-}
-
-void audio_ipc_send_rsp_full(uint8_t opcode, uint16_t len, void *param, int fd)
-{
- ipc_send(g_io_channel_unix_get_fd(audio_io), AUDIO_SERVICE_ID, opcode,
- len, param, fd);
-}
diff --git a/android/audio-ipc.h b/android/audio-ipc.h
deleted file mode 100644
index 83207c8..0000000
--- a/android/audio-ipc.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-void audio_ipc_init(GDestroyNotify destroy);
-void audio_ipc_cleanup(void);
-
-void audio_ipc_register(const struct ipc_handler *handlers, uint8_t size);
-void audio_ipc_unregister(void);
-
-void audio_ipc_send_rsp(uint8_t opcode, uint8_t status);
-void audio_ipc_send_rsp_full(uint8_t opcode, uint16_t len, void *param, int fd);
diff --git a/android/audio-msg.h b/android/audio-msg.h
index 17cde09..d4fc68a 100644
--- a/android/audio-msg.h
+++ b/android/audio-msg.h
@@ -26,6 +26,7 @@
static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
#define AUDIO_SERVICE_ID 0
+#define AUDIO_SERVICE_ID_MAX AUDIO_SERVICE_ID
#define AUDIO_STATUS_SUCCESS 0x00
#define AUDIO_STATUS_FAILED 0x01
diff --git a/android/ipc.c b/android/ipc.c
index fa44e3f..6b14bbe 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -89,7 +89,7 @@ static void ipc_disconnect(struct ipc *ipc, bool in_cleanup)
ipc->disconnect_cb(ipc->disconnect_cb_data);
}
-int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
+static int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
const void *buf, ssize_t len)
{
const struct hal_hdr *msg = buf;
@@ -193,8 +193,8 @@ static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
-GIOChannel *ipc_connect(const char *path, size_t size, GIOFunc connect_cb,
- void *user_data)
+static GIOChannel *ipc_connect(const char *path, size_t size,
+ GIOFunc connect_cb, void *user_data)
{
struct sockaddr_un addr;
GIOCondition cond;
@@ -324,7 +324,7 @@ void ipc_cleanup(struct ipc *ipc)
g_free(ipc);
}
-void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
+static void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
void *param, int fd)
{
struct msghdr msg;
diff --git a/android/ipc.h b/android/ipc.h
index d46dbbf..cc4e92d 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -41,19 +41,12 @@ struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
ipc_disconnect_cb cb, void *cb_data);
void ipc_cleanup(struct ipc *ipc);
-GIOChannel *ipc_connect(const char *path, size_t size, GIOFunc connect_cb,
- void *user_data);
-int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
- const void *buf, ssize_t len);
-
void ipc_send_rsp(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
uint8_t status);
void ipc_send_rsp_full(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
uint16_t len, void *param, int fd);
void ipc_send_notif(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
uint16_t len, void *param);
-void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
- void *param, int fd);
void ipc_register(struct ipc *ipc, uint8_t service,
const struct ipc_handler *handlers, uint8_t size);
void ipc_unregister(struct ipc *ipc, uint8_t service);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 4/6] android: Add support for disabling notifications in IPC
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1393592969-4451-1-git-send-email-szymon.janc@tieto.com>
---
android/ipc.c | 29 ++++++++++++++++++++---------
android/ipc.h | 1 +
android/main.c | 3 ++-
android/test-ipc.c | 8 ++++----
4 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/android/ipc.c b/android/ipc.c
index a996935..fa44e3f 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -50,6 +50,7 @@ struct ipc {
GIOChannel *cmd_io;
guint cmd_watch;
+ bool notifications;
GIOChannel *notif_io;
guint notif_watch;
@@ -249,7 +250,7 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
ipc->cmd_watch = g_io_add_watch(ipc->cmd_io, cond, cmd_watch_cb, ipc);
- info("IPC: successfully connected");
+ info("IPC: successfully connected (with notifications)");
return FALSE;
}
@@ -263,23 +264,31 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
error("IPC: command socket connect failed");
- goto failed;
+ ipc_disconnect(ipc, false);
+
+ return FALSE;
}
- ipc->notif_io = ipc_connect(ipc->path, ipc->size, notif_connect_cb,
- ipc);
- if (!ipc->notif_io)
- goto failed;
+ if (ipc->notifications) {
+ ipc->notif_io = ipc_connect(ipc->path, ipc->size,
+ notif_connect_cb, ipc);
+ if (!ipc->notif_io)
+ ipc_disconnect(ipc, false);
- return FALSE;
+ return FALSE;
+ }
-failed:
- ipc_disconnect(ipc, false);
+ cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+
+ ipc->cmd_watch = g_io_add_watch(ipc->cmd_io, cond, cmd_watch_cb, ipc);
+
+ info("IPC: successfully connected (without notifications)");
return FALSE;
}
struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
+ bool notifications,
ipc_disconnect_cb cb, void *cb_data)
{
struct ipc *ipc;
@@ -292,6 +301,8 @@ struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
ipc->path = path;
ipc->size = size;
+ ipc->notifications = notifications;
+
ipc->cmd_io = ipc_connect(path, size, cmd_connect_cb, ipc);
if (!ipc->cmd_io) {
g_free(ipc->services);
diff --git a/android/ipc.h b/android/ipc.h
index 63b751d..d46dbbf 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -37,6 +37,7 @@ struct ipc;
typedef void (*ipc_disconnect_cb) (void *data);
struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
+ bool notifications,
ipc_disconnect_cb cb, void *cb_data);
void ipc_cleanup(struct ipc *ipc);
diff --git a/android/main.c b/android/main.c
index 01f0b92..bd1bcb9 100644
--- a/android/main.c
+++ b/android/main.c
@@ -250,7 +250,8 @@ static void adapter_ready(int err, const bdaddr_t *addr)
info("Adapter initialized");
hal_ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, ipc_disconnected, NULL);
+ HAL_SERVICE_ID_MAX, true,
+ ipc_disconnected, NULL);
if (!hal_ipc) {
error("Failed to initialize IPC");
exit(EXIT_FAILURE);
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 2f211fd..6172991 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -237,7 +237,7 @@ static void test_init(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, NULL, NULL);
+ HAL_SERVICE_ID_MAX, true, NULL, NULL);
g_assert(ipc);
@@ -288,7 +288,7 @@ static void test_cmd(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, disconnected, context);
+ HAL_SERVICE_ID_MAX, true, disconnected, context);
g_assert(ipc);
@@ -306,7 +306,7 @@ static void test_cmd_reg(gconstpointer data)
const struct test_data *test_data = context->data;
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, disconnected, context);
+ HAL_SERVICE_ID_MAX, true, disconnected, context);
g_assert(ipc);
@@ -326,7 +326,7 @@ static void test_cmd_reg_1(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, disconnected, context);
+ HAL_SERVICE_ID_MAX, true, disconnected, context);
g_assert(ipc);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 3/6] android/unit: Update test-ipc with disconnect handler support
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1393592969-4451-1-git-send-email-szymon.janc@tieto.com>
---
android/test-ipc.c | 117 ++++++++++++++++-------------------------------------
1 file changed, 34 insertions(+), 83 deletions(-)
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 9b736a2..2f211fd 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -35,7 +35,6 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
-#include <sys/signalfd.h>
#include <glib.h>
#include "src/shared/util.h"
@@ -43,10 +42,8 @@
#include "android/hal-msg.h"
#include "android/ipc.h"
-static struct ipc *ipc = NULL;
-
struct test_data {
- uint32_t expected_signal;
+ bool disconnect;
const void *cmd;
uint16_t cmd_size;
uint8_t service;
@@ -65,13 +62,13 @@ struct context {
GIOChannel *cmd_io;
GIOChannel *notif_io;
- GIOChannel *signal_io;
-
- guint signal_source;
const struct test_data *data;
};
+
+static struct ipc *ipc = NULL;
+
static void context_quit(struct context *context)
{
g_main_loop_quit(context->main_loop);
@@ -92,13 +89,13 @@ static gboolean cmd_watch(GIOChannel *io, GIOCondition cond,
.len = 0,
};
- g_assert(test_data->expected_signal == 0);
-
if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
- g_assert(FALSE);
+ g_assert(test_data->disconnect);
return FALSE;
}
+ g_assert(!test_data->disconnect);
+
sk = g_io_channel_unix_get_fd(io);
g_assert(read(sk, buf, sizeof(buf)) == sizeof(struct hal_hdr));
@@ -112,11 +109,16 @@ static gboolean cmd_watch(GIOChannel *io, GIOCondition cond,
static gboolean notif_watch(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
+ struct context *context = user_data;
+ const struct test_data *test_data = context->data;
+
if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
- g_assert(FALSE);
+ g_assert(test_data->disconnect);
return FALSE;
}
+ g_assert(!test_data->disconnect);
+
return TRUE;
}
@@ -162,62 +164,6 @@ static gboolean connect_handler(GIOChannel *io, GIOCondition cond,
return TRUE;
}
-static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
- gpointer user_data)
-{
- struct context *context = user_data;
- const struct test_data *test_data = context->data;
- struct signalfd_siginfo si;
- ssize_t result;
- int fd;
-
- if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
- return FALSE;
-
- fd = g_io_channel_unix_get_fd(channel);
-
- result = read(fd, &si, sizeof(si));
- if (result != sizeof(si))
- return FALSE;
-
- g_assert(test_data->expected_signal == si.ssi_signo);
- context_quit(context);
- return TRUE;
-}
-
-static guint setup_signalfd(gpointer user_data)
-{
- GIOChannel *channel;
- guint source;
- sigset_t mask;
- int ret;
- int fd;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
- sigaddset(&mask, SIGTERM);
-
- ret = sigprocmask(SIG_BLOCK, &mask, NULL);
- g_assert(ret == 0);
-
- fd = signalfd(-1, &mask, 0);
- g_assert(fd >= 0);
-
- channel = g_io_channel_unix_new(fd);
-
- g_io_channel_set_close_on_unref(channel, TRUE);
- g_io_channel_set_encoding(channel, NULL, NULL);
- g_io_channel_set_buffered(channel, FALSE);
-
- source = g_io_add_watch(channel,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
- signal_handler, user_data);
-
- g_io_channel_unref(channel);
-
- return source;
-}
-
static struct context *create_context(gconstpointer data)
{
struct context *context = g_new0(struct context, 1);
@@ -228,9 +174,6 @@ static struct context *create_context(gconstpointer data)
context->main_loop = g_main_loop_new(NULL, FALSE);
g_assert(context->main_loop);
- context->signal_source = setup_signalfd(context);
- g_assert(context->signal_source);
-
sk = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
g_assert(sk >= 0);
@@ -272,7 +215,6 @@ static void execute_context(struct context *context)
g_io_channel_unref(context->notif_io);
g_source_remove(context->notif_source);
- g_source_remove(context->signal_source);
g_source_remove(context->cmd_source);
g_source_remove(context->source);
@@ -281,6 +223,15 @@ static void execute_context(struct context *context)
g_free(context);
}
+static void disconnected(void *data)
+{
+ struct context *context = data;
+
+ g_assert(context->data->disconnect);
+
+ context_quit(context);
+}
+
static void test_init(gconstpointer data)
{
struct context *context = create_context(data);
@@ -337,7 +288,7 @@ static void test_cmd(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, NULL, NULL);
+ HAL_SERVICE_ID_MAX, disconnected, context);
g_assert(ipc);
@@ -355,7 +306,7 @@ static void test_cmd_reg(gconstpointer data)
const struct test_data *test_data = context->data;
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, NULL, NULL);
+ HAL_SERVICE_ID_MAX, disconnected, context);
g_assert(ipc);
@@ -375,7 +326,7 @@ static void test_cmd_reg_1(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX, NULL, NULL);
+ HAL_SERVICE_ID_MAX, disconnected, context);
g_assert(ipc);
@@ -401,7 +352,7 @@ static void test_cmd_handler_2(const void *buf, uint16_t len)
static void test_cmd_handler_invalid(const void *buf, uint16_t len)
{
- raise(SIGTERM);
+ g_assert(false);
}
static const struct test_data test_init_1 = {};
@@ -421,7 +372,7 @@ static const struct hal_hdr test_cmd_2_hdr = {
static const struct test_data test_cmd_service_invalid_1 = {
.cmd = &test_cmd_1_hdr,
.cmd_size = sizeof(test_cmd_1_hdr),
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct ipc_handler cmd_handlers[] = {
@@ -442,7 +393,7 @@ static const struct test_data test_cmd_service_invalid_2 = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct ipc_handler cmd_handlers_invalid_2[] = {
@@ -477,7 +428,7 @@ static const struct test_data test_cmd_opcode_invalid_1 = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct test_data test_cmd_hdr_invalid = {
@@ -486,7 +437,7 @@ static const struct test_data test_cmd_hdr_invalid = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
#define VARDATA_EX1 "some data example"
@@ -533,7 +484,7 @@ static const struct test_data test_cmd_vardata_invalid_1 = {
.service = 0,
.handlers = cmd_vardata_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct hal_hdr test_cmd_service_offrange_hdr = {
@@ -548,7 +499,7 @@ static const struct test_data test_cmd_service_offrange = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct vardata test_cmd_invalid_data_1 = {
@@ -564,7 +515,7 @@ static const struct test_data test_cmd_msg_invalid_1 = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
static const struct vardata test_cmd_invalid_data_2 = {
@@ -580,7 +531,7 @@ static const struct test_data test_cmd_msg_invalid_2 = {
.service = 0,
.handlers = cmd_handlers,
.handlers_size = 1,
- .expected_signal = SIGTERM
+ .disconnect = true,
};
int main(int argc, char *argv[])
--
1.8.3.2
^ permalink raw reply related
* [PATCH 2/6] android: Add support for registering disconnect callback in IPC
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1393592969-4451-1-git-send-email-szymon.janc@tieto.com>
Allow to register callback which is called in case of IPC failure
(eg malformed message) or disconnection. This makes caller responsible
for performing expected action in such case.
---
android/ipc.c | 106 ++++++++++++++++++++++++++++++++++-------------------
android/ipc.h | 5 ++-
android/main.c | 7 +++-
android/test-ipc.c | 8 ++--
4 files changed, 83 insertions(+), 43 deletions(-)
diff --git a/android/ipc.c b/android/ipc.c
index 3d6e2a3..a996935 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -52,8 +52,42 @@ struct ipc {
GIOChannel *notif_io;
guint notif_watch;
+
+ ipc_disconnect_cb disconnect_cb;
+ void *disconnect_cb_data;
};
+static void ipc_disconnect(struct ipc *ipc, bool in_cleanup)
+{
+ if (ipc->cmd_watch) {
+ g_source_remove(ipc->cmd_watch);
+ ipc->cmd_watch = 0;
+ }
+
+ if (ipc->cmd_io) {
+ g_io_channel_shutdown(ipc->cmd_io, TRUE, NULL);
+ g_io_channel_unref(ipc->cmd_io);
+ ipc->cmd_io = NULL;
+ }
+
+ if (ipc->notif_watch) {
+ g_source_remove(ipc->notif_watch);
+ ipc->notif_watch = 0;
+ }
+
+ if (ipc->notif_io) {
+ g_io_channel_shutdown(ipc->notif_io, TRUE, NULL);
+ g_io_channel_unref(ipc->notif_io);
+ ipc->notif_io = NULL;
+ }
+
+ if (in_cleanup)
+ return;
+
+ if (ipc->disconnect_cb)
+ ipc->disconnect_cb(ipc->disconnect_cb_data);
+}
+
int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
const void *buf, ssize_t len)
{
@@ -116,7 +150,9 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
int fd, err;
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
- info("IPC: command socket closed, terminating");
+ info("IPC: command socket closed");
+
+ ipc->cmd_watch = 0;
goto fail;
}
@@ -124,30 +160,34 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
ret = read(fd, buf, sizeof(buf));
if (ret < 0) {
- error("IPC: command read failed, terminating (%s)",
- strerror(errno));
+ error("IPC: command read failed (%s)", strerror(errno));
goto fail;
}
err = ipc_handle_msg(ipc->services, ipc->service_max, buf, ret);
if (err < 0) {
- error("IPC: failed to handle message, terminating (%s)",
- strerror(-err));
+ error("IPC: failed to handle message (%s)", strerror(-err));
goto fail;
}
return TRUE;
fail:
- raise(SIGTERM);
+ ipc_disconnect(ipc, false);
+
return FALSE;
}
static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
- info("IPC: notification socket closed, terminating");
- raise(SIGTERM);
+ struct ipc *ipc = user_data;
+
+ info("IPC: notification socket closed");
+
+ ipc->notif_watch = 0;
+
+ ipc_disconnect(ipc, false);
return FALSE;
}
@@ -194,8 +234,10 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
DBG("");
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
- error("IPC: notification socket connect failed, terminating");
- raise(SIGTERM);
+ error("IPC: notification socket connect failed");
+
+ ipc_disconnect(ipc, false);
+
return FALSE;
}
@@ -220,20 +262,25 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
DBG("");
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
- error("IPC: command socket connect failed, terminating");
- raise(SIGTERM);
- return FALSE;
+ error("IPC: command socket connect failed");
+ goto failed;
}
ipc->notif_io = ipc_connect(ipc->path, ipc->size, notif_connect_cb,
ipc);
if (!ipc->notif_io)
- raise(SIGTERM);
+ goto failed;
+
+ return FALSE;
+
+failed:
+ ipc_disconnect(ipc, false);
return FALSE;
}
-struct ipc *ipc_init(const char *path, size_t size, int max_service_id)
+struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
+ ipc_disconnect_cb cb, void *cb_data)
{
struct ipc *ipc;
@@ -252,32 +299,15 @@ struct ipc *ipc_init(const char *path, size_t size, int max_service_id)
return NULL;
}
+ ipc->disconnect_cb = cb;
+ ipc->disconnect_cb_data = cb_data;
+
return ipc;
}
void ipc_cleanup(struct ipc *ipc)
{
- if (ipc->cmd_watch) {
- g_source_remove(ipc->cmd_watch);
- ipc->cmd_watch = 0;
- }
-
- if (ipc->cmd_io) {
- g_io_channel_shutdown(ipc->cmd_io, TRUE, NULL);
- g_io_channel_unref(ipc->cmd_io);
- ipc->cmd_io = NULL;
- }
-
- if (ipc->notif_watch) {
- g_source_remove(ipc->notif_watch);
- ipc->notif_watch = 0;
- }
-
- if (ipc->notif_io) {
- g_io_channel_shutdown(ipc->notif_io, TRUE, NULL);
- g_io_channel_unref(ipc->notif_io);
- ipc->notif_io = NULL;
- }
+ ipc_disconnect(ipc, true);
g_free(ipc->services);
g_free(ipc);
@@ -323,7 +353,9 @@ void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
}
if (sendmsg(sk, &msg, 0) < 0) {
- error("IPC send failed, terminating :%s", strerror(errno));
+ error("IPC send failed :%s", strerror(errno));
+
+ /* TODO disconnect IPC here when this function becomes static */
raise(SIGTERM);
}
}
diff --git a/android/ipc.h b/android/ipc.h
index 601301c..63b751d 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -34,7 +34,10 @@ struct service_handler {
struct ipc;
-struct ipc *ipc_init(const char *path, size_t size, int max_service_id);
+typedef void (*ipc_disconnect_cb) (void *data);
+
+struct ipc *ipc_init(const char *path, size_t size, int max_service_id,
+ ipc_disconnect_cb cb, void *cb_data);
void ipc_cleanup(struct ipc *ipc);
GIOChannel *ipc_connect(const char *path, size_t size, GIOFunc connect_cb,
diff --git a/android/main.c b/android/main.c
index 9f22486..01f0b92 100644
--- a/android/main.c
+++ b/android/main.c
@@ -228,6 +228,11 @@ static void stop_bluetooth(void)
g_timeout_add_seconds(SHUTDOWN_GRACE_SECONDS, quit_eventloop, NULL);
}
+static void ipc_disconnected(void *data)
+{
+ stop_bluetooth();
+}
+
static void adapter_ready(int err, const bdaddr_t *addr)
{
if (err < 0) {
@@ -245,7 +250,7 @@ static void adapter_ready(int err, const bdaddr_t *addr)
info("Adapter initialized");
hal_ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX);
+ HAL_SERVICE_ID_MAX, ipc_disconnected, NULL);
if (!hal_ipc) {
error("Failed to initialize IPC");
exit(EXIT_FAILURE);
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 054af84..9b736a2 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -286,7 +286,7 @@ static void test_init(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX);
+ HAL_SERVICE_ID_MAX, NULL, NULL);
g_assert(ipc);
@@ -337,7 +337,7 @@ static void test_cmd(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX);
+ HAL_SERVICE_ID_MAX, NULL, NULL);
g_assert(ipc);
@@ -355,7 +355,7 @@ static void test_cmd_reg(gconstpointer data)
const struct test_data *test_data = context->data;
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX);
+ HAL_SERVICE_ID_MAX, NULL, NULL);
g_assert(ipc);
@@ -375,7 +375,7 @@ static void test_cmd_reg_1(gconstpointer data)
struct context *context = create_context(data);
ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- HAL_SERVICE_ID_MAX);
+ HAL_SERVICE_ID_MAX, NULL, NULL);
g_assert(ipc);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 1/6] android: Refactor IPC init
From: Szymon Janc @ 2014-02-28 13:09 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This allows to pass socket path and max service ID while initializaing
IPC. This is first step to allow use it both for BT and Audio HALs.
---
android/a2dp.c | 27 +++++++----
android/a2dp.h | 2 +-
android/avrcp.c | 52 +++++++++++----------
android/avrcp.h | 2 +-
android/bluetooth.c | 113 +++++++++++++++++++++++++-------------------
android/bluetooth.h | 2 +-
android/handsfree.c | 65 ++++++++++++++------------
android/handsfree.h | 2 +-
android/hidhost.c | 61 +++++++++++++-----------
android/hidhost.h | 2 +-
android/ipc.c | 132 +++++++++++++++++++++++++++++++++-------------------
android/ipc.h | 24 ++++++----
android/main.c | 41 +++++++++-------
android/pan.c | 32 +++++++------
android/pan.h | 2 +-
android/socket.c | 26 +++++++----
android/socket.h | 2 +-
android/test-ipc.c | 44 ++++++++++++------
18 files changed, 374 insertions(+), 257 deletions(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index 5d7dc78..b05d4bd 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -39,9 +39,9 @@
#include "lib/sdp_lib.h"
#include "profiles/audio/a2dp-codecs.h"
#include "src/log.h"
-#include "a2dp.h"
#include "hal-msg.h"
#include "ipc.h"
+#include "a2dp.h"
#include "utils.h"
#include "bluetooth.h"
#include "avdtp.h"
@@ -63,6 +63,8 @@ static uint32_t record_id = 0;
static guint audio_retry_id = 0;
static bool audio_retrying = false;
+static struct ipc *hal_ipc = NULL;
+
struct a2dp_preset {
void *data;
int8_t len;
@@ -226,8 +228,8 @@ static void bt_a2dp_notify_state(struct a2dp_device *dev, uint8_t state)
bdaddr2android(&dev->dst, ev.bdaddr);
ev.state = state;
- ipc_send_notif(HAL_SERVICE_ID_A2DP, HAL_EV_A2DP_CONN_STATE, sizeof(ev),
- &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_A2DP, HAL_EV_A2DP_CONN_STATE,
+ sizeof(ev), &ev);
if (state != HAL_A2DP_STATE_DISCONNECTED)
return;
@@ -253,8 +255,8 @@ static void bt_audio_notify_state(struct a2dp_setup *setup, uint8_t state)
bdaddr2android(&setup->dev->dst, ev.bdaddr);
ev.state = state;
- ipc_send_notif(HAL_SERVICE_ID_A2DP, HAL_EV_A2DP_AUDIO_STATE, sizeof(ev),
- &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_A2DP, HAL_EV_A2DP_AUDIO_STATE,
+ sizeof(ev), &ev);
}
static void disconnect_cb(void *user_data)
@@ -597,7 +599,7 @@ static void bt_a2dp_connect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_CONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_CONNECT, status);
}
static void bt_a2dp_disconnect(const void *buf, uint16_t len)
@@ -631,7 +633,8 @@ static void bt_a2dp_disconnect(const void *buf, uint16_t len)
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTING);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_DISCONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_DISCONNECT,
+ status);
}
static const struct ipc_handler cmd_handlers[] = {
@@ -1540,7 +1543,7 @@ retry:
audio_disconnected);
}
-bool bt_a2dp_register(const bdaddr_t *addr)
+bool bt_a2dp_register(struct ipc *ipc, const bdaddr_t *addr)
{
GError *err = NULL;
sdp_record_t *rec;
@@ -1573,7 +1576,9 @@ bool bt_a2dp_register(const bdaddr_t *addr)
}
record_id = rec->handle;
- ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
+ hal_ipc = ipc;
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_A2DP, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
bt_audio_register(audio_disconnected);
@@ -1600,7 +1605,9 @@ void bt_a2dp_unregister(void)
g_slist_free_full(devices, a2dp_device_free);
devices = NULL;
- ipc_unregister(HAL_SERVICE_ID_A2DP);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_A2DP);
+ hal_ipc = NULL;
+
audio_ipc_unregister();
bt_adapter_remove_record(record_id);
diff --git a/android/a2dp.h b/android/a2dp.h
index e626e41..b41a178 100644
--- a/android/a2dp.h
+++ b/android/a2dp.h
@@ -21,5 +21,5 @@
*
*/
-bool bt_a2dp_register(const bdaddr_t *addr);
+bool bt_a2dp_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_a2dp_unregister(void);
diff --git a/android/avrcp.c b/android/avrcp.c
index 8ff70b4..678c321 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -33,12 +33,12 @@
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "src/log.h"
-#include "bluetooth.h"
#include "avctp.h"
-#include "avrcp.h"
#include "avrcp-lib.h"
#include "hal-msg.h"
#include "ipc.h"
+#include "bluetooth.h"
+#include "avrcp.h"
#define L2CAP_PSM_AVCTP 0x17
@@ -51,6 +51,7 @@ static bdaddr_t adapter_addr;
static uint32_t record_id = 0;
static GSList *devices = NULL;
static GIOChannel *server = NULL;
+static struct ipc *hal_ipc = NULL;
struct avrcp_device {
bdaddr_t dst;
@@ -62,79 +63,79 @@ static void handle_get_play_status(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_PLAY_STATUS,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_GET_PLAY_STATUS, HAL_STATUS_FAILED);
}
static void handle_list_player_attrs(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_LIST_PLAYER_ATTRS,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_LIST_PLAYER_ATTRS, HAL_STATUS_FAILED);
}
static void handle_list_player_values(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_LIST_PLAYER_VALUES,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_LIST_PLAYER_VALUES, HAL_STATUS_FAILED);
}
static void handle_get_player_attrs(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_PLAYER_ATTRS,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_GET_PLAYER_ATTRS, HAL_STATUS_FAILED);
}
static void handle_get_player_attrs_text(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_PLAYER_ATTRS_TEXT,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_GET_PLAYER_ATTRS_TEXT, HAL_STATUS_FAILED);
}
static void handle_get_player_values_text(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_PLAYER_VALUES_TEXT,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_GET_PLAYER_VALUES_TEXT, HAL_STATUS_FAILED);
}
static void handle_get_element_attrs_text(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_GET_ELEMENT_ATTRS_TEXT,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_GET_ELEMENT_ATTRS_TEXT, HAL_STATUS_FAILED);
}
static void handle_set_player_attrs_value(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_SET_PLAYER_ATTRS_VALUE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_SET_PLAYER_ATTRS_VALUE, HAL_STATUS_FAILED);
}
static void handle_register_notification(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_REGISTER_NOTIFICATION,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP,
+ HAL_OP_AVRCP_REGISTER_NOTIFICATION, HAL_STATUS_FAILED);
}
static void handle_set_volume(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_SET_VOLUME,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_AVRCP, HAL_OP_AVRCP_SET_VOLUME,
HAL_STATUS_FAILED);
}
@@ -363,7 +364,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
DBG("%s connected", address);
}
-bool bt_avrcp_register(const bdaddr_t *addr)
+bool bt_avrcp_register(struct ipc *ipc, const bdaddr_t *addr)
{
GError *err = NULL;
sdp_record_t *rec;
@@ -396,7 +397,9 @@ bool bt_avrcp_register(const bdaddr_t *addr)
}
record_id = rec->handle;
- ipc_register(HAL_SERVICE_ID_AVRCP, cmd_handlers,
+ hal_ipc = ipc;
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_AVRCP, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
return true;
@@ -415,7 +418,8 @@ void bt_avrcp_unregister(void)
g_slist_free_full(devices, avrcp_device_free);
devices = NULL;
- ipc_unregister(HAL_SERVICE_ID_AVRCP);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_AVRCP);
+ hal_ipc = NULL;
bt_adapter_remove_record(record_id);
record_id = 0;
diff --git a/android/avrcp.h b/android/avrcp.h
index 1fcd953..3dcffeb 100644
--- a/android/avrcp.h
+++ b/android/avrcp.h
@@ -21,7 +21,7 @@
*
*/
-bool bt_avrcp_register(const bdaddr_t *addr);
+bool bt_avrcp_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_avrcp_unregister(void);
void bt_avrcp_connect(const bdaddr_t *dst);
diff --git a/android/bluetooth.c b/android/bluetooth.c
index ac4c213..26493f7 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -145,6 +145,8 @@ static GSList *cached_devices = NULL;
/* This list contains addresses which are asked for records */
static GSList *browse_reqs;
+static struct ipc *hal_ipc = NULL;
+
static void store_adapter_config(void)
{
GKeyFile *key_file;
@@ -390,8 +392,8 @@ static void send_adapter_property(uint8_t type, uint16_t len, const void *val)
ev->props[0].len = len;
memcpy(ev->props[0].val, val, len);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), buf);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), buf);
}
static void adapter_name_changed(const uint8_t *name)
@@ -440,8 +442,8 @@ static void powered_changed(void)
DBG("%u", ev.state);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_STATE_CHANGED,
- sizeof(ev), &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_STATE_CHANGED, sizeof(ev), &ev);
}
static uint8_t settings2scan_mode(void)
@@ -594,8 +596,8 @@ static void send_bond_state_change(const bdaddr_t *addr, uint8_t status,
ev.state = state;
bdaddr2android(addr, ev.bdaddr);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_BOND_STATE_CHANGED,
- sizeof(ev), &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_BOND_STATE_CHANGED, sizeof(ev), &ev);
}
static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
@@ -647,8 +649,8 @@ static void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
ev->props[0].len = len;
memcpy(ev->props[0].val, val, len);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_REMOTE_DEVICE_PROPS,
- sizeof(buf), buf);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_REMOTE_DEVICE_PROPS, sizeof(buf), buf);
}
static void send_device_uuids_notif(struct device *dev)
@@ -883,7 +885,7 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
hal_ev.class_of_dev = dev->class;
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_PIN_REQUEST,
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_PIN_REQUEST,
sizeof(hal_ev), &hal_ev);
}
@@ -901,7 +903,7 @@ static void send_ssp_request(const bdaddr_t *addr, uint8_t variant,
ev.pairing_variant = variant;
ev.passkey = passkey;
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_SSP_REQUEST,
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_SSP_REQUEST,
sizeof(ev), &ev);
}
@@ -1010,7 +1012,7 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
cp.state = HAL_DISCOVERY_STATE_STOPPED;
}
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH,
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
}
@@ -1106,8 +1108,8 @@ static void update_new_device(struct device *dev, int8_t rssi,
ev->num_props++;
}
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_DEVICE_FOUND, size,
- buf);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_EV_DEVICE_FOUND,
+ size, buf);
}
static void update_device(struct device *dev, int8_t rssi,
@@ -1147,7 +1149,7 @@ static void update_device(struct device *dev, int8_t rssi,
}
if (ev->num_props)
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH,
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
HAL_EV_REMOTE_DEVICE_PROPS, size, buf);
}
@@ -1259,8 +1261,8 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
hal_ev.state = HAL_ACL_STATE_CONNECTED;
bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ACL_STATE_CHANGED,
- sizeof(hal_ev), &hal_ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev);
}
static void mgmt_device_disconnected_event(uint16_t index, uint16_t length,
@@ -1279,8 +1281,8 @@ static void mgmt_device_disconnected_event(uint16_t index, uint16_t length,
hal_ev.state = HAL_ACL_STATE_DISCONNECTED;
bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ACL_STATE_CHANGED,
- sizeof(hal_ev), &hal_ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev);
}
static uint8_t status_mgmt2hal(uint8_t mgmt)
@@ -1502,8 +1504,8 @@ static uint8_t get_adapter_uuids(void)
p += sizeof(uint128_t);
}
- ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, HAL_EV_ADAPTER_PROPS_CHANGED,
- sizeof(buf), ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev);
return HAL_STATUS_SUCCESS;
}
@@ -2387,7 +2389,8 @@ static void handle_get_adapter_prop_cmd(const void *buf, uint16_t len)
error("Failed to get adapter property (type %u status %u)",
cmd->type, status);
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP,
+ status);
}
static void get_adapter_properties(void)
@@ -2538,7 +2541,8 @@ static void handle_set_adapter_prop_cmd(const void *buf, uint16_t len)
error("Failed to set adapter property (type %u status %u)",
cmd->type, status);
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
+ status);
}
static void pair_device_complete(uint8_t status, uint16_t length,
@@ -2579,7 +2583,8 @@ static void handle_create_bond_cmd(const void *buf, uint16_t len)
HAL_BOND_STATE_BONDING);
fail:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
+ status);
}
static void handle_cancel_bond_cmd(const void *buf, uint16_t len)
@@ -2597,7 +2602,8 @@ static void handle_cancel_bond_cmd(const void *buf, uint16_t len)
else
status = HAL_STATUS_FAILED;
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_BOND, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_BOND,
+ status);
}
static void unpair_device_complete(uint8_t status, uint16_t length,
@@ -2631,7 +2637,8 @@ static void handle_remove_bond_cmd(const void *buf, uint16_t len)
else
status = HAL_STATUS_FAILED;
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_REMOVE_BOND, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_REMOVE_BOND,
+ status);
}
static void handle_pin_reply_cmd(const void *buf, uint16_t len)
@@ -2682,7 +2689,8 @@ static void handle_pin_reply_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_PIN_REPLY, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_PIN_REPLY,
+ status);
}
static uint8_t user_confirm_reply(const bdaddr_t *bdaddr, bool accept)
@@ -2770,7 +2778,8 @@ static void handle_ssp_reply_cmd(const void *buf, uint16_t len)
break;
}
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SSP_REPLY, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SSP_REPLY,
+ status);
}
static void handle_get_remote_services_cmd(const void *buf, uint16_t len)
@@ -2783,8 +2792,8 @@ static void handle_get_remote_services_cmd(const void *buf, uint16_t len)
status = browse_remote_sdp(&addr);
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_SERVICES,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_GET_REMOTE_SERVICES, status);
}
static uint8_t get_device_uuids(struct device *dev)
@@ -2907,7 +2916,7 @@ static void handle_enable_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
reply:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_ENABLE, status);
}
static void handle_disable_cmd(const void *buf, uint16_t len)
@@ -2929,15 +2938,15 @@ static void handle_disable_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
reply:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DISABLE, status);
}
static void handle_get_adapter_props_cmd(const void *buf, uint16_t len)
{
get_adapter_properties();
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
- HAL_STATUS_SUCCESS);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_GET_ADAPTER_PROPS, HAL_STATUS_SUCCESS);
}
static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
@@ -2960,8 +2969,8 @@ static void handle_get_remote_device_props_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROPS,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_GET_REMOTE_DEVICE_PROPS, status);
}
static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
@@ -3017,8 +3026,8 @@ static void handle_get_remote_device_prop_cmd(const void *buf, uint16_t len)
cmd->type, status);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_DEVICE_PROP,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_GET_REMOTE_DEVICE_PROP, status);
}
static uint8_t set_device_friendly_name(struct device *dev, const uint8_t *val,
@@ -3088,8 +3097,8 @@ static void handle_set_remote_device_prop_cmd(const void *buf, uint16_t len)
cmd->type, status);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_REMOTE_DEVICE_PROP,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_SET_REMOTE_DEVICE_PROP, status);
}
static void handle_get_remote_service_rec_cmd(const void *buf, uint16_t len)
@@ -3098,8 +3107,8 @@ static void handle_get_remote_service_rec_cmd(const void *buf, uint16_t len)
error("get_remote_service_record not supported");
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_REMOTE_SERVICE_REC,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_GET_REMOTE_SERVICE_REC, HAL_STATUS_FAILED);
}
static void handle_start_discovery_cmd(const void *buf, uint16_t len)
@@ -3123,7 +3132,8 @@ static void handle_start_discovery_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
reply:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_START_DISCOVERY, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_START_DISCOVERY,
+ status);
}
static void handle_cancel_discovery_cmd(const void *buf, uint16_t len)
@@ -3148,7 +3158,8 @@ static void handle_cancel_discovery_cmd(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
reply:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_DISCOVERY, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_DISCOVERY,
+ status);
}
static void handle_dut_mode_conf_cmd(const void *buf, uint16_t len)
@@ -3181,7 +3192,8 @@ static void handle_dut_mode_conf_cmd(const void *buf, uint16_t len)
close(fd);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_CONF, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_CONF,
+ status);
}
static void handle_dut_mode_send_cmd(const void *buf, uint16_t len)
@@ -3198,7 +3210,7 @@ static void handle_dut_mode_send_cmd(const void *buf, uint16_t len)
/* TODO */
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_SEND,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_SEND,
HAL_STATUS_FAILED);
}
@@ -3216,7 +3228,7 @@ static void handle_le_test_mode_cmd(const void *buf, uint16_t len)
/* TODO */
- ipc_send_rsp(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_LE_TEST_MODE,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, HAL_OP_LE_TEST_MODE,
HAL_STATUS_FAILED);
}
@@ -3272,11 +3284,13 @@ static const struct ipc_handler cmd_handlers[] = {
{ handle_le_test_mode_cmd, true, sizeof(struct hal_cmd_le_test_mode) },
};
-void bt_bluetooth_register(void)
+void bt_bluetooth_register(struct ipc *ipc)
{
DBG("");
- ipc_register(HAL_SERVICE_ID_BLUETOOTH, cmd_handlers,
+ hal_ipc = ipc;
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
}
@@ -3290,5 +3304,6 @@ void bt_bluetooth_unregister(void)
g_slist_free_full(cached_devices, (GDestroyNotify) free_device);
cached_devices = NULL;
- ipc_unregister(HAL_SERVICE_ID_CORE);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE);
+ hal_ipc = NULL;
}
diff --git a/android/bluetooth.h b/android/bluetooth.h
index 8ab34f6..fbc850d 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -31,7 +31,7 @@ void bt_bluetooth_cleanup(void);
void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-void bt_bluetooth_register(void);
+void bt_bluetooth_register(struct ipc *ipc);
void bt_bluetooth_unregister(void);
int bt_adapter_add_record(sdp_record_t *rec, uint8_t svc_hint);
diff --git a/android/handsfree.c b/android/handsfree.c
index 60bff91..ef8c776 100644
--- a/android/handsfree.c
+++ b/android/handsfree.c
@@ -38,11 +38,11 @@
#include "src/uuid-helper.h"
#include "src/shared/hfp.h"
#include "btio/btio.h"
+#include "hal-msg.h"
+#include "ipc.h"
#include "handsfree.h"
#include "bluetooth.h"
#include "src/log.h"
-#include "hal-msg.h"
-#include "ipc.h"
#include "utils.h"
#define HFP_AG_CHANNEL 13
@@ -56,6 +56,7 @@ static struct {
static bdaddr_t adapter_addr;
static uint32_t record_id = 0;
+static struct ipc *hal_ipc = NULL;
static GIOChannel *server = NULL;
@@ -75,8 +76,8 @@ static void device_set_state(uint8_t state)
bdaddr2android(&device.bdaddr, ev.bdaddr);
ev.state = state;
- ipc_send_notif(HAL_SERVICE_ID_HANDSFREE, HAL_EV_HANDSFREE_CONN_STATE,
- sizeof(ev), &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_EV_HANDSFREE_CONN_STATE, sizeof(ev), &ev);
}
static void device_init(const bdaddr_t *bdaddr)
@@ -281,8 +282,8 @@ static void handle_connect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_CONNECT,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_CONNECT, status);
}
static void handle_disconnect(const void *buf, uint16_t len)
@@ -317,23 +318,23 @@ static void handle_disconnect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_DISCONNECT,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_DISCONNECT, status);
}
static void handle_connect_audio(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_CONNECT_AUDIO,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_CONNECT_AUDIO, HAL_STATUS_FAILED);
}
static void handle_disconnect_audio(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
HAL_OP_HANDSFREE_DISCONNECT_AUDIO, HAL_STATUS_FAILED);
}
@@ -341,31 +342,31 @@ static void handle_start_vr(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_START_VR,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_START_VR, HAL_STATUS_FAILED);
}
static void handle_stop_vr(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_STOP_VR,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_STOP_VR, HAL_STATUS_FAILED);
}
static void handle_volume_control(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_VOLUME_CONTROL,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_VOLUME_CONTROL, HAL_STATUS_FAILED);
}
static void handle_device_status_notif(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
HAL_OP_HANDSFREE_DEVICE_STATUS_NOTIF,
HAL_STATUS_FAILED);
}
@@ -374,23 +375,23 @@ static void handle_cops(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_COPS_RESPONSE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_COPS_RESPONSE, HAL_STATUS_FAILED);
}
static void handle_cind(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_CIND_RESPONSE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_CIND_RESPONSE, HAL_STATUS_FAILED);
}
static void handle_formatted_at_resp(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
HAL_OP_HANDSFREE_FORMATTED_AT_RESPONSE,
HAL_STATUS_FAILED);
}
@@ -399,23 +400,23 @@ static void handle_at_resp(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_AT_RESPONSE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_AT_RESPONSE, HAL_STATUS_FAILED);
}
static void handle_clcc_resp(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE, HAL_OP_HANDSFREE_CLCC_RESPONSE,
- HAL_STATUS_FAILED);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
+ HAL_OP_HANDSFREE_CLCC_RESPONSE, HAL_STATUS_FAILED);
}
static void handle_phone_state_change(const void *buf, uint16_t len)
{
DBG("");
- ipc_send_rsp(HAL_SERVICE_ID_HANDSFREE,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HANDSFREE,
HAL_OP_HANDSFREE_PHONE_STATE_CHANGE,
HAL_STATUS_FAILED);
}
@@ -530,7 +531,7 @@ static sdp_record_t *handsfree_ag_record(void)
return record;
}
-bool bt_handsfree_register(const bdaddr_t *addr)
+bool bt_handsfree_register(struct ipc *ipc, const bdaddr_t *addr)
{
sdp_record_t *rec;
GError *err = NULL;
@@ -563,7 +564,8 @@ bool bt_handsfree_register(const bdaddr_t *addr)
}
record_id = rec->handle;
- ipc_register(HAL_SERVICE_ID_HANDSFREE, cmd_handlers,
+ hal_ipc = ipc;
+ ipc_register(hal_ipc, HAL_SERVICE_ID_HANDSFREE, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
return true;
@@ -580,7 +582,8 @@ void bt_handsfree_unregister(void)
{
DBG("");
- ipc_unregister(HAL_SERVICE_ID_HANDSFREE);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_HANDSFREE);
+ hal_ipc = NULL;
if (server) {
g_io_channel_shutdown(server, TRUE, NULL);
diff --git a/android/handsfree.h b/android/handsfree.h
index e3fdd70..3ede819 100644
--- a/android/handsfree.h
+++ b/android/handsfree.h
@@ -21,5 +21,5 @@
*
*/
-bool bt_handsfree_register(const bdaddr_t *addr);
+bool bt_handsfree_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_handsfree_unregister(void);
diff --git a/android/hidhost.c b/android/hidhost.c
index fd5ea4d..0c6eb7d 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -81,6 +81,8 @@ static GIOChannel *ctrl_io = NULL;
static GIOChannel *intr_io = NULL;
static GSList *devices = NULL;
+static struct ipc *hal_ipc = NULL;
+
struct hid_device {
bdaddr_t dst;
uint8_t state;
@@ -303,8 +305,8 @@ static void bt_hid_notify_state(struct hid_device *dev, uint8_t state)
bdaddr2android(&dev->dst, ev.bdaddr);
ev.state = state;
- ipc_send_notif(HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_CONN_STATE,
- sizeof(ev), &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_CONN_STATE, sizeof(ev), &ev);
}
static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
@@ -362,8 +364,8 @@ static void bt_hid_notify_proto_mode(struct hid_device *dev, uint8_t *buf,
ev.mode = HAL_HIDHOST_UNSUPPORTED_PROTOCOL;
}
- ipc_send_notif(HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_PROTO_MODE,
- sizeof(ev), &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_PROTO_MODE, sizeof(ev), &ev);
}
static void bt_hid_notify_get_report(struct hid_device *dev, uint8_t *buf,
@@ -405,8 +407,8 @@ static void bt_hid_notify_get_report(struct hid_device *dev, uint8_t *buf,
}
send:
- ipc_send_notif(HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_GET_REPORT,
- ev_len, ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_GET_REPORT, ev_len, ev);
g_free(ev);
}
@@ -430,9 +432,8 @@ static void bt_hid_notify_virtual_unplug(struct hid_device *dev,
ev.status = HAL_HIDHOST_STATUS_OK;
}
- ipc_send_notif(HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_VIRTUAL_UNPLUG,
- sizeof(ev), &ev);
-
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_VIRTUAL_UNPLUG, sizeof(ev), &ev);
}
static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
@@ -515,8 +516,8 @@ static void bt_hid_set_info(struct hid_device *dev)
memset(ev.descr, 0, sizeof(ev.descr));
memcpy(ev.descr, dev->rd_data, ev.descr_len);
- ipc_send_notif(HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_INFO, sizeof(ev),
- &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_EV_HIDHOST_INFO,
+ sizeof(ev), &ev);
}
static int uhid_create(struct hid_device *dev)
@@ -806,7 +807,8 @@ static void bt_hid_connect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_CONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_CONNECT,
+ status);
}
static void bt_hid_disconnect(const void *buf, uint16_t len)
@@ -841,7 +843,8 @@ static void bt_hid_disconnect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_DISCONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_DISCONNECT,
+ status);
}
static void bt_hid_virtual_unplug(const void *buf, uint16_t len)
@@ -894,8 +897,8 @@ static void bt_hid_virtual_unplug(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_VIRTUAL_UNPLUG,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_OP_HIDHOST_VIRTUAL_UNPLUG, status);
}
static void bt_hid_info(const void *buf, uint16_t len)
@@ -914,7 +917,7 @@ static void bt_hid_info(const void *buf, uint16_t len)
* once device is created with HID internals. */
DBG("Not supported");
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_INFO,
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_INFO,
HAL_STATUS_UNSUPPORTED);
}
@@ -964,8 +967,8 @@ static void bt_hid_get_protocol(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_PROTOCOL,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_OP_HIDHOST_GET_PROTOCOL, status);
}
static void bt_hid_set_protocol(const void *buf, uint16_t len)
@@ -1014,8 +1017,8 @@ static void bt_hid_set_protocol(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_PROTOCOL,
- status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_OP_HIDHOST_SET_PROTOCOL, status);
}
static void bt_hid_get_report(const void *buf, uint16_t len)
@@ -1081,7 +1084,8 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT,
+ status);
}
static void bt_hid_set_report(const void *buf, uint16_t len)
@@ -1158,7 +1162,8 @@ static void bt_hid_set_report(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
+ status);
}
static void bt_hid_send_data(const void *buf, uint16_t len)
@@ -1224,7 +1229,8 @@ static void bt_hid_send_data(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
+ status);
}
static const struct ipc_handler cmd_handlers[] = {
@@ -1323,7 +1329,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
}
}
-bool bt_hid_register(const bdaddr_t *addr)
+bool bt_hid_register(struct ipc *ipc, const bdaddr_t *addr)
{
GError *err = NULL;
@@ -1358,7 +1364,9 @@ bool bt_hid_register(const bdaddr_t *addr)
return false;
}
- ipc_register(HAL_SERVICE_ID_HIDHOST, cmd_handlers,
+ hal_ipc = ipc;
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_HIDHOST, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
return true;
@@ -1383,5 +1391,6 @@ void bt_hid_unregister(void)
intr_io = NULL;
}
- ipc_unregister(HAL_SERVICE_ID_HIDHOST);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_HIDHOST);
+ hal_ipc = NULL;
}
diff --git a/android/hidhost.h b/android/hidhost.h
index 5c3c801..1017195 100644
--- a/android/hidhost.h
+++ b/android/hidhost.h
@@ -21,5 +21,5 @@
*
*/
-bool bt_hid_register(const bdaddr_t *addr);
+bool bt_hid_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_hid_unregister(void);
diff --git a/android/ipc.c b/android/ipc.c
index 4a3a60d..3d6e2a3 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -40,13 +40,19 @@
#include "ipc.h"
#include "src/log.h"
-static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
+struct ipc {
+ struct service_handler *services;
+ int service_max;
-static GIOChannel *cmd_io = NULL;
-static GIOChannel *notif_io = NULL;
+ const char *path;
+ size_t size;
-static guint cmd_watch = 0;
-static guint notif_watch = 0;
+ GIOChannel *cmd_io;
+ guint cmd_watch;
+
+ GIOChannel *notif_io;
+ guint notif_watch;
+};
int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
const void *buf, ssize_t len)
@@ -103,6 +109,8 @@ int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
+ struct ipc *ipc = user_data;
+
char buf[BLUEZ_HAL_MTU];
ssize_t ret;
int fd, err;
@@ -121,7 +129,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- err = ipc_handle_msg(services, HAL_SERVICE_ID_MAX, buf, ret);
+ err = ipc_handle_msg(ipc->services, ipc->service_max, buf, ret);
if (err < 0) {
error("IPC: failed to handle message, terminating (%s)",
strerror(-err));
@@ -181,6 +189,8 @@ GIOChannel *ipc_connect(const char *path, size_t size, GIOFunc connect_cb,
static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
+ struct ipc *ipc = user_data;
+
DBG("");
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
@@ -191,11 +201,11 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
cond = G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- notif_watch = g_io_add_watch(io, cond, notif_watch_cb, NULL);
+ ipc->notif_watch = g_io_add_watch(io, cond, notif_watch_cb, ipc);
cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- cmd_watch = g_io_add_watch(cmd_io, cond, cmd_watch_cb, NULL);
+ ipc->cmd_watch = g_io_add_watch(ipc->cmd_io, cond, cmd_watch_cb, ipc);
info("IPC: successfully connected");
@@ -205,6 +215,8 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
+ struct ipc *ipc = user_data;
+
DBG("");
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
@@ -213,45 +225,62 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
- notif_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- notif_connect_cb, NULL);
- if (!notif_io)
+ ipc->notif_io = ipc_connect(ipc->path, ipc->size, notif_connect_cb,
+ ipc);
+ if (!ipc->notif_io)
raise(SIGTERM);
return FALSE;
}
-void ipc_init(void)
+struct ipc *ipc_init(const char *path, size_t size, int max_service_id)
{
- cmd_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
- cmd_connect_cb, NULL);
- if (!cmd_io)
- raise(SIGTERM);
+ struct ipc *ipc;
+
+ ipc = g_new0(struct ipc, 1);
+
+ ipc->services = g_new0(struct service_handler, max_service_id + 1);
+ ipc->service_max = max_service_id;
+
+ ipc->path = path;
+ ipc->size = size;
+
+ ipc->cmd_io = ipc_connect(path, size, cmd_connect_cb, ipc);
+ if (!ipc->cmd_io) {
+ g_free(ipc->services);
+ g_free(ipc);
+ return NULL;
+ }
+
+ return ipc;
}
-void ipc_cleanup(void)
+void ipc_cleanup(struct ipc *ipc)
{
- if (cmd_watch) {
- g_source_remove(cmd_watch);
- cmd_watch = 0;
+ if (ipc->cmd_watch) {
+ g_source_remove(ipc->cmd_watch);
+ ipc->cmd_watch = 0;
}
- if (cmd_io) {
- g_io_channel_shutdown(cmd_io, TRUE, NULL);
- g_io_channel_unref(cmd_io);
- cmd_io = NULL;
+ if (ipc->cmd_io) {
+ g_io_channel_shutdown(ipc->cmd_io, TRUE, NULL);
+ g_io_channel_unref(ipc->cmd_io);
+ ipc->cmd_io = NULL;
}
- if (notif_watch) {
- g_source_remove(notif_watch);
- notif_watch = 0;
+ if (ipc->notif_watch) {
+ g_source_remove(ipc->notif_watch);
+ ipc->notif_watch = 0;
}
- if (notif_io) {
- g_io_channel_shutdown(notif_io, TRUE, NULL);
- g_io_channel_unref(notif_io);
- notif_io = NULL;
+ if (ipc->notif_io) {
+ g_io_channel_shutdown(ipc->notif_io, TRUE, NULL);
+ g_io_channel_unref(ipc->notif_io);
+ ipc->notif_io = NULL;
}
+
+ g_free(ipc->services);
+ g_free(ipc);
}
void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
@@ -299,12 +328,13 @@ void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
}
}
-void ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)
+void ipc_send_rsp(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint8_t status)
{
struct hal_status s;
int sk;
- sk = g_io_channel_unix_get_fd(cmd_io);
+ sk = g_io_channel_unix_get_fd(ipc->cmd_io);
if (status == HAL_STATUS_SUCCESS) {
ipc_send(sk, service_id, opcode, 0, NULL, -1);
@@ -316,32 +346,38 @@ void ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)
ipc_send(sk, service_id, HAL_OP_STATUS, sizeof(s), &s, -1);
}
-void ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
- void *param, int fd)
+void ipc_send_rsp_full(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint16_t len, void *param, int fd)
{
- ipc_send(g_io_channel_unix_get_fd(cmd_io), service_id, opcode, len,
+ ipc_send(g_io_channel_unix_get_fd(ipc->cmd_io), service_id, opcode, len,
param, fd);
}
-void ipc_send_notif(uint8_t service_id, uint8_t opcode, uint16_t len,
- void *param)
+void ipc_send_notif(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint16_t len, void *param)
{
- if (!notif_io)
+ if (!ipc || !ipc->notif_io)
return;
- ipc_send(g_io_channel_unix_get_fd(notif_io), service_id, opcode, len,
- param, -1);
+ ipc_send(g_io_channel_unix_get_fd(ipc->notif_io), service_id, opcode,
+ len, param, -1);
}
-void ipc_register(uint8_t service, const struct ipc_handler *handlers,
- uint8_t size)
+void ipc_register(struct ipc *ipc, uint8_t service,
+ const struct ipc_handler *handlers, uint8_t size)
{
- services[service].handler = handlers;
- services[service].size = size;
+ if (service > ipc->service_max)
+ return;
+
+ ipc->services[service].handler = handlers;
+ ipc->services[service].size = size;
}
-void ipc_unregister(uint8_t service)
+void ipc_unregister(struct ipc *ipc, uint8_t service)
{
- services[service].handler = NULL;
- services[service].size = 0;
+ if (service > ipc->service_max)
+ return;
+
+ ipc->services[service].handler = NULL;
+ ipc->services[service].size = 0;
}
diff --git a/android/ipc.h b/android/ipc.h
index cfa4018..601301c 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -32,20 +32,24 @@ struct service_handler {
uint8_t size;
};
-void ipc_init(void);
-void ipc_cleanup(void);
+struct ipc;
+
+struct ipc *ipc_init(const char *path, size_t size, int max_service_id);
+void ipc_cleanup(struct ipc *ipc);
+
GIOChannel *ipc_connect(const char *path, size_t size, GIOFunc connect_cb,
void *user_data);
int ipc_handle_msg(struct service_handler *handlers, size_t max_index,
const void *buf, ssize_t len);
-void ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status);
-void ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
- void *param, int fd);
-void ipc_send_notif(uint8_t service_id, uint8_t opcode, uint16_t len,
- void *param);
+void ipc_send_rsp(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint8_t status);
+void ipc_send_rsp_full(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint16_t len, void *param, int fd);
+void ipc_send_notif(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint16_t len, void *param);
void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
void *param, int fd);
-void ipc_register(uint8_t service, const struct ipc_handler *handlers,
- uint8_t size);
-void ipc_unregister(uint8_t service);
+void ipc_register(struct ipc *ipc, uint8_t service,
+ const struct ipc_handler *handlers, uint8_t size);
+void ipc_unregister(struct ipc *ipc, uint8_t service);
diff --git a/android/main.c b/android/main.c
index aca6351..9f22486 100644
--- a/android/main.c
+++ b/android/main.c
@@ -48,11 +48,11 @@
#include "lib/bluetooth.h"
+#include "ipc.h"
#include "bluetooth.h"
#include "socket.h"
#include "hidhost.h"
#include "hal-msg.h"
-#include "ipc.h"
#include "a2dp.h"
#include "pan.h"
#include "avrcp.h"
@@ -67,6 +67,8 @@ static bdaddr_t adapter_bdaddr;
static GMainLoop *event_loop;
+static struct ipc *hal_ipc = NULL;
+
static bool services[HAL_SERVICE_ID_MAX + 1] = { false };
static void service_register(const void *buf, uint16_t len)
@@ -81,43 +83,43 @@ static void service_register(const void *buf, uint16_t len)
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- bt_bluetooth_register();
+ bt_bluetooth_register(hal_ipc);
break;
case HAL_SERVICE_ID_SOCKET:
- bt_socket_register(&adapter_bdaddr);
+ bt_socket_register(hal_ipc, &adapter_bdaddr);
break;
case HAL_SERVICE_ID_HIDHOST:
- if (!bt_hid_register(&adapter_bdaddr)) {
+ if (!bt_hid_register(hal_ipc, &adapter_bdaddr)) {
status = HAL_STATUS_FAILED;
goto failed;
}
break;
case HAL_SERVICE_ID_A2DP:
- if (!bt_a2dp_register(&adapter_bdaddr)) {
+ if (!bt_a2dp_register(hal_ipc, &adapter_bdaddr)) {
status = HAL_STATUS_FAILED;
goto failed;
}
break;
case HAL_SERVICE_ID_PAN:
- if (!bt_pan_register(&adapter_bdaddr)) {
+ if (!bt_pan_register(hal_ipc, &adapter_bdaddr)) {
status = HAL_STATUS_FAILED;
goto failed;
}
break;
case HAL_SERVICE_ID_AVRCP:
- if (!bt_avrcp_register(&adapter_bdaddr)) {
+ if (!bt_avrcp_register(hal_ipc, &adapter_bdaddr)) {
status = HAL_STATUS_FAILED;
goto failed;
}
break;
case HAL_SERVICE_ID_HANDSFREE:
- if (!bt_handsfree_register(&adapter_bdaddr)) {
+ if (!bt_handsfree_register(hal_ipc, &adapter_bdaddr)) {
status = HAL_STATUS_FAILED;
goto failed;
}
@@ -136,7 +138,8 @@ static void service_register(const void *buf, uint16_t len)
info("Service ID=%u registered", m->service_id);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
+ status);
}
static void service_unregister(const void *buf, uint16_t len)
@@ -186,7 +189,8 @@ static void service_unregister(const void *buf, uint16_t len)
info("Service ID=%u unregistered", m->service_id);
failed:
- ipc_send_rsp(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
+ status);
}
static const struct ipc_handler cmd_handlers[] = {
@@ -240,7 +244,15 @@ static void adapter_ready(int err, const bdaddr_t *addr)
info("Adapter initialized");
- ipc_init();
+ hal_ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ HAL_SERVICE_ID_MAX);
+ if (!hal_ipc) {
+ error("Failed to initialize IPC");
+ exit(EXIT_FAILURE);
+ }
+
+ ipc_register(hal_ipc, HAL_SERVICE_ID_CORE, cmd_handlers,
+ G_N_ELEMENTS(cmd_handlers));
}
static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
@@ -464,9 +476,6 @@ int main(int argc, char *argv[])
/* Use params: mtu = 0, flags = 0 */
start_sdp_server(0, 0);
- ipc_register(HAL_SERVICE_ID_CORE, cmd_handlers,
- G_N_ELEMENTS(cmd_handlers));
-
DBG("Entering main loop");
event_loop = g_main_loop_new(NULL, FALSE);
@@ -480,12 +489,12 @@ int main(int argc, char *argv[])
cleanup_services();
- ipc_cleanup();
stop_sdp_server();
bt_bluetooth_cleanup();
g_main_loop_unref(event_loop);
- ipc_unregister(HAL_SERVICE_ID_CORE);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE);
+ ipc_cleanup(hal_ipc);
info("Exit");
diff --git a/android/pan.c b/android/pan.c
index cfc03bc..b4a3494 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -49,11 +49,11 @@
#include "profiles/network/bnep.h"
#include "src/log.h"
-#include "pan.h"
#include "hal-msg.h"
#include "ipc.h"
#include "utils.h"
#include "bluetooth.h"
+#include "pan.h"
#define SVC_HINT_NETWORKING 0x02
@@ -64,6 +64,7 @@
static bdaddr_t adapter_addr;
GSList *devices = NULL;
uint8_t local_role = HAL_PAN_ROLE_NONE;
+static struct ipc *hal_ipc = NULL;
struct pan_device {
char iface[16];
@@ -247,8 +248,8 @@ static void bt_pan_notify_conn_state(struct pan_device *dev, uint8_t state)
ev.remote_role = dev->role;
ev.status = HAL_STATUS_SUCCESS;
- ipc_send_notif(HAL_SERVICE_ID_PAN, HAL_EV_PAN_CONN_STATE, sizeof(ev),
- &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_PAN, HAL_EV_PAN_CONN_STATE,
+ sizeof(ev), &ev);
if (dev->conn_state == HAL_PAN_STATE_DISCONNECTED)
pan_device_remove(dev);
}
@@ -270,8 +271,8 @@ static void bt_pan_notify_ctrl_state(struct pan_device *dev, uint8_t state)
else
memcpy(ev.name, dev->iface, sizeof(dev->iface));
- ipc_send_notif(HAL_SERVICE_ID_PAN, HAL_EV_PAN_CTRL_STATE, sizeof(ev),
- &ev);
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_PAN, HAL_EV_PAN_CTRL_STATE,
+ sizeof(ev), &ev);
}
static void bnep_disconn_cb(void *data)
@@ -414,7 +415,7 @@ static void bt_pan_connect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_CONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_PAN, HAL_OP_PAN_CONNECT, status);
}
static void bt_pan_disconnect(const void *buf, uint16_t len)
@@ -444,7 +445,8 @@ static void bt_pan_disconnect(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_DISCONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_PAN, HAL_OP_PAN_DISCONNECT,
+ status);
}
static gboolean nap_watchdog_cb(GIOChannel *chan, GIOCondition cond,
@@ -676,7 +678,7 @@ static void bt_pan_enable(const void *buf, uint16_t len)
status = HAL_STATUS_SUCCESS;
reply:
- ipc_send_rsp(HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_PAN, HAL_OP_PAN_ENABLE, status);
}
static void bt_pan_get_role(const void *buf, uint16_t len)
@@ -686,8 +688,8 @@ static void bt_pan_get_role(const void *buf, uint16_t len)
DBG("");
rsp.local_role = local_role;
- ipc_send_rsp_full(HAL_SERVICE_ID_PAN, HAL_OP_PAN_GET_ROLE, sizeof(rsp),
- &rsp, -1);
+ ipc_send_rsp_full(hal_ipc, HAL_SERVICE_ID_PAN, HAL_OP_PAN_GET_ROLE,
+ sizeof(rsp), &rsp, -1);
}
static const struct ipc_handler cmd_handlers[] = {
@@ -776,7 +778,7 @@ static sdp_record_t *pan_record(void)
return record;
}
-bool bt_pan_register(const bdaddr_t *addr)
+bool bt_pan_register(struct ipc *ipc, const bdaddr_t *addr)
{
sdp_record_t *rec;
int err;
@@ -813,7 +815,9 @@ bool bt_pan_register(const bdaddr_t *addr)
}
nap_dev.record_id = rec->handle;
- ipc_register(HAL_SERVICE_ID_PAN, cmd_handlers,
+
+ hal_ipc = ipc;
+ ipc_register(hal_ipc, HAL_SERVICE_ID_PAN, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
return true;
@@ -829,7 +833,9 @@ void bt_pan_unregister(void)
bnep_cleanup();
- ipc_unregister(HAL_SERVICE_ID_PAN);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_PAN);
+ hal_ipc = NULL;
+
bt_adapter_remove_record(nap_dev.record_id);
nap_dev.record_id = 0;
destroy_nap_device();
diff --git a/android/pan.h b/android/pan.h
index 72a7eab..2045ac5 100644
--- a/android/pan.h
+++ b/android/pan.h
@@ -21,5 +21,5 @@
*
*/
-bool bt_pan_register(const bdaddr_t *addr);
+bool bt_pan_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_pan_unregister(void);
diff --git a/android/socket.c b/android/socket.c
index 655ee40..d463255 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -38,11 +38,11 @@
#include "src/sdpd.h"
#include "src/log.h"
-#include "bluetooth.h"
#include "hal-msg.h"
#include "hal-ipc.h"
#include "ipc.h"
#include "utils.h"
+#include "bluetooth.h"
#include "socket.h"
#define RFCOMM_CHANNEL_MAX 30
@@ -60,6 +60,7 @@
#define MAP_MSG_TYPE_SMS_CDMA 0x04
#define DEFAULT_MAS_MSG_TYPE (MAP_MSG_TYPE_SMS_GSM | MAP_MSG_TYPE_SMS_CDMA)
+static struct ipc *hal_ipc = NULL;
struct rfcomm_sock {
int channel; /* RFCOMM channel */
BtIOSecLevel sec_level;
@@ -862,13 +863,14 @@ static void handle_listen(const void *buf, uint16_t len)
if (status != HAL_STATUS_SUCCESS)
goto failed;
- ipc_send_rsp_full(HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_LISTEN, 0, NULL,
- hal_sock);
+ ipc_send_rsp_full(hal_ipc, HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_LISTEN,
+ 0, NULL, hal_sock);
close(hal_sock);
return ;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_LISTEN, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_LISTEN,
+ status);
}
static bool sock_send_connect(struct rfcomm_sock *rfsock, bdaddr_t *bdaddr)
@@ -1106,13 +1108,14 @@ static void handle_connect(const void *buf, uint16_t len)
if (status != HAL_STATUS_SUCCESS)
goto failed;
- ipc_send_rsp_full(HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_CONNECT, 0,
- NULL, hal_sock);
+ ipc_send_rsp_full(hal_ipc, HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_CONNECT,
+ 0, NULL, hal_sock);
close(hal_sock);
return;
failed:
- ipc_send_rsp(HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_CONNECT, status);
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_SOCKET, HAL_OP_SOCKET_CONNECT,
+ status);
}
@@ -1123,7 +1126,7 @@ static const struct ipc_handler cmd_handlers[] = {
{ handle_connect, false, sizeof(struct hal_cmd_socket_connect) },
};
-void bt_socket_register(const bdaddr_t *addr)
+void bt_socket_register(struct ipc *ipc, const bdaddr_t *addr)
{
size_t i;
@@ -1137,7 +1140,9 @@ void bt_socket_register(const bdaddr_t *addr)
servers[profiles[i].channel].reserved = true;
bacpy(&adapter_addr, addr);
- ipc_register(HAL_SERVICE_ID_SOCKET, cmd_handlers,
+
+ hal_ipc = ipc;
+ ipc_register(hal_ipc, HAL_SERVICE_ID_SOCKET, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
}
@@ -1155,5 +1160,6 @@ void bt_socket_unregister(void)
memset(servers, 0, sizeof(servers));
- ipc_unregister(HAL_SERVICE_ID_SOCKET);
+ ipc_unregister(hal_ipc, HAL_SERVICE_ID_SOCKET);
+ hal_ipc = NULL;
}
diff --git a/android/socket.h b/android/socket.h
index d41616f..d3ed9b4 100644
--- a/android/socket.h
+++ b/android/socket.h
@@ -30,5 +30,5 @@ struct hal_sock_connect_signal {
void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-void bt_socket_register(const bdaddr_t *addr);
+void bt_socket_register(struct ipc *ipc, const bdaddr_t *addr);
void bt_socket_unregister(void);
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 8dd53a1..054af84 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -43,6 +43,8 @@
#include "android/hal-msg.h"
#include "android/ipc.h"
+static struct ipc *ipc = NULL;
+
struct test_data {
uint32_t expected_signal;
const void *cmd;
@@ -283,11 +285,15 @@ static void test_init(gconstpointer data)
{
struct context *context = create_context(data);
- ipc_init();
+ ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ HAL_SERVICE_ID_MAX);
+
+ g_assert(ipc);
execute_context(context);
- ipc_cleanup();
+ ipc_cleanup(ipc);
+ ipc = NULL;
}
static gboolean send_cmd(gpointer user_data)
@@ -310,7 +316,7 @@ static gboolean register_service(gpointer user_data)
struct context *context = user_data;
const struct test_data *test_data = context->data;
- ipc_register(test_data->service, test_data->handlers,
+ ipc_register(ipc, test_data->service, test_data->handlers,
test_data->handlers_size);
return FALSE;
@@ -321,7 +327,7 @@ static gboolean unregister_service(gpointer user_data)
struct context *context = user_data;
const struct test_data *test_data = context->data;
- ipc_unregister(test_data->service);
+ ipc_unregister(ipc, test_data->service);
return FALSE;
}
@@ -330,13 +336,17 @@ static void test_cmd(gconstpointer data)
{
struct context *context = create_context(data);
- ipc_init();
+ ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ HAL_SERVICE_ID_MAX);
+
+ g_assert(ipc);
g_idle_add(send_cmd, context);
execute_context(context);
- ipc_cleanup();
+ ipc_cleanup(ipc);
+ ipc = NULL;
}
static void test_cmd_reg(gconstpointer data)
@@ -344,23 +354,30 @@ static void test_cmd_reg(gconstpointer data)
struct context *context = create_context(data);
const struct test_data *test_data = context->data;
- ipc_init();
+ ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ HAL_SERVICE_ID_MAX);
+
+ g_assert(ipc);
g_idle_add(register_service, context);
g_idle_add(send_cmd, context);
execute_context(context);
- ipc_unregister(test_data->service);
+ ipc_unregister(ipc, test_data->service);
- ipc_cleanup();
+ ipc_cleanup(ipc);
+ ipc = NULL;
}
static void test_cmd_reg_1(gconstpointer data)
{
struct context *context = create_context(data);
- ipc_init();
+ ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ HAL_SERVICE_ID_MAX);
+
+ g_assert(ipc);
g_idle_add(register_service, context);
g_idle_add(unregister_service, context);
@@ -368,17 +385,18 @@ static void test_cmd_reg_1(gconstpointer data)
execute_context(context);
- ipc_cleanup();
+ ipc_cleanup(ipc);
+ ipc = NULL;
}
static void test_cmd_handler_1(const void *buf, uint16_t len)
{
- ipc_send_rsp(0, 1, 0);
+ ipc_send_rsp(ipc, 0, 1, 0);
}
static void test_cmd_handler_2(const void *buf, uint16_t len)
{
- ipc_send_rsp(0, 2, 0);
+ ipc_send_rsp(ipc, 0, 2, 0);
}
static void test_cmd_handler_invalid(const void *buf, uint16_t len)
--
1.8.3.2
^ permalink raw reply related
* Passive scanning of iBeacons results in a "Data Buffer Overflow"
From: Adam Warski @ 2014-02-28 12:41 UTC (permalink / raw)
To: BlueZ development
Hello,
I’m trying to scan for Estimote iBeacons, using Bluez 5.15, a raspbian Linux with Kernel 3.10.26 (so on a Raspberry Pi), and a TP-LINK TL-WN725N dongle.
To test receiving of the advertisements, I’m using hcidump and hcitool lescan.
As I want to continuously receive the advertisements, I’m allowing duplicates (--duplicates). Also, I don’t want to send scan responses, so I’m running a passive scan (--passive; running an active scan quickly results in a hardware error).
So the commands I’m running:
1st terminal: hcidump
2nd terminal: hcitool lescan --duplicates --passive
Receiving the advertisements works fine for some time (30 seconds-2 minutes), resulting in advertisement events printed by hcidump:
> HCI Event: LE Meta Event (0x3e) plen 42
LE Advertising Report
ADV_IND - Connectable undirected advertising (0)
bdaddr FC:94:A8:6F:A8:10 (Random)
Flags: 0x06
Unknown type 0xff with 25 bytes data
RSSI: -65
These events come at a rate of up to a couple per second. The RSSI values oscillate between -70 and -55 as the beacon is close.
But then I get:
> HCI Event: LE Meta Event (0x3e) plen 42
LE Advertising Report
ADV_IND - Connectable undirected advertising (0)
bdaddr FC:94:A8:6F:A8:10 (Random)
Flags: 0x06
Unknown type 0xff with 25 bytes data
RSSI: -4
> HCI Event: QoS Violation (0x1e) plen 2
handle 1537
> HCI Event: Data Buffer Overflow (0x1a) plen 255
type Unknown
> HCI Event: code 0xa8 plen 148
> HCI Event: code 0xf8 plen 70
> HCI Event: Physical Link Complete (0x40) plen 127
status 0x30 phy handle 0xf5
Error: Parameter out of Mandatory Range
The first weird thing is the abnormally large RSSI (sometimes even positive), but that may be the result of the buffer overflow, which comes next. Of course later no more packets are received, just a lot of: http://pastie.org/private/ckvvdt3plhxv84fbydyxg
I tried decreasing the scan’s interval to 0x50 (keeping the window at 0x10), which results in fewer advertisements being received), but after some time I get the same buffer overflow.
Any ideas what can be wrong? Is it something in bluez? Something specific to the dongle?
Thanks,
Adam
--
Adam Warski
http://twitter.com/#!/adamwarski
http://www.softwaremill.com
http://www.warski.org
^ permalink raw reply
* Re: [PATCH BlueZ] core: retry connect_dbus() several times
From: Anderson Lizardo @ 2014-02-28 12:22 UTC (permalink / raw)
To: Adam Lee; +Cc: Marcel Holtmann, BlueZ development
In-Reply-To: <20140228073113.GA3771@adam-laptop>
Hi Adam,
On Fri, Feb 28, 2014 at 3:31 AM, Adam Lee <adam8157@gmail.com> wrote:
> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
> before executing bluetoothd workarounds it. I assume the firmware
> patching slows down hardware initialization then fails to connect.
>
> Any other possibility? I'm not a D-Bus guru :)
Please provide more details, e.g. the bluetoothd logs showing the
problems, btmon output and which steps you are using to reproduce it.
If you are using bluetoothctl, tell us which commands you are using.
Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil
^ permalink raw reply
* Re: [bluez-5.14] connect fails with 'org.bluez.Error.NotAvailable'
From: Anderson Lizardo @ 2014-02-28 12:16 UTC (permalink / raw)
To: Tobias Jakobi; +Cc: BlueZ development
In-Reply-To: <530FBB6B.8080300@gmx.net>
Hi Tobias,
On Thu, Feb 27, 2014 at 6:25 PM, Tobias Jakobi <liquid.acid@gmx.net> wrote:
> That's the server:
> [bluetooth]# info 00:02:72:C6:43:11
> Device 00:02:72:C6:43:11
> Name: chidori-bt
> Alias: chidori-bt
> Class: 0x020000
> Paired: yes
> Trusted: yes
> Blocked: no
> Connected: no
> LegacyPairing: no
> UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
> UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
> UUID: NAP (00001116-0000-1000-8000-00805f9b34fb)
> UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
> UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
> UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
> Modalias: usb:v1D6Bp0246d0509
Looks like you are missing a "power on" on the server side. Notice
that the client side shows "Powered: yes" on the info command.
Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil
^ permalink raw reply
* Re: [v2] android/pics: Add PICS and PIXIT for HFP
From: Szymon Janc @ 2014-02-28 12:12 UTC (permalink / raw)
To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1393338451-5761-1-git-send-email-sebastian.chlad@tieto.com>
Hi Sebastian,
On Tuesday 25 of February 2014 15:27:31 Sebastian Chlad wrote:
> ---
> android/Makefile.am | 2 +
> android/pics-hfp.txt | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++
> android/pixit-hfp.txt | 37 +++++++++
> 3 files changed, 256 insertions(+)
> create mode 100644 android/pics-hfp.txt
> create mode 100644 android/pixit-hfp.txt
>
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 58cfbae..b944ca9 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -189,6 +189,7 @@ EXTRA_DIST += android/Android.mk android/README \
> android/pics-avctp.txt \
> android/pics-avrcp.txt \
> android/pics-hsp.txt \
> + android/pics-hfp.txt \
> android/pixit-l2cap.txt \
> android/pixit-gap.txt \
> android/pixit-did.txt \
> @@ -201,6 +202,7 @@ EXTRA_DIST += android/Android.mk android/README \
> android/pixit-avctp.txt \
> android/pixit-avrcp.txt \
> android/pixit-hsp.txt \
> + android/pixit-hfp.txt \
> android/pts-l2cap.txt \
> android/pts-gap.txt \
> android/pts-did.txt \
> diff --git a/android/pics-hfp.txt b/android/pics-hfp.txt
> new file mode 100644
> index 0000000..ae6d33e
> --- /dev/null
> +++ b/android/pics-hfp.txt
> @@ -0,0 +1,217 @@
> +HFP PICS for the PTS tool.
> +
> +PTS version: 5.0
> +
> +* - different than PTS defaults
> +# - not yet implemented/supported
> +
> +M - mandatory
> +O - optional
> +
> + Version
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_0_1 False Version: Hands-Free Profile v1.5 (O.1)
> +TSPC_HFP_0_2 True (*) Version: Hands-Free Profile v1.6 (O.1)
> +-------------------------------------------------------------------------------
> +O.1: It is mandatory to support only one of the adopted versions.
> +-------------------------------------------------------------------------------
> +
> +
> + Roles
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_1_1 True (*) Role: Audio Gateway (AG) (O.1)
> +TSPC_HFP_1_2 False Role: Hands-Free (HF) (O.1)
> +-------------------------------------------------------------------------------
> +O.1: It is mandatory to support at least one of the defined roles.
> +-------------------------------------------------------------------------------
> +
> +
> + Audio Gateway Role
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_2_1 True Connection management (M)
> +TSPC_HFP_2_1a True (*) SLC initiation during active ongoing call (O)
> +TSPC_HFP_2_2 True Phone Status Information (M)
> +TSPC_HFP_2_3 True Audio connection handling (M)
> +TSPC_HFP_2_3a False Audio connection establishment independent of
> + call processing (O)
> +TSPC_HFP_2_3b True (*) eSCO support in Audio Connection (C.10)
> +TSPC_HFP_2_3c False Codec negotiation (C.7)
> +TSPC_HFP_2_4a False Accept an incoming voice call
> + (in-band ring) (C.1)
> +TSPC_HFP_2_4b True (*) Accept an incoming voice call
> + (no in-band ring) (C.1)
> +TSPC_HFP_2_4c False Capability to change the "in-band ring"
> + settings (O)
> +TSPC_HFP_2_5 True (*) Reject an incoming voice call (O)
> +TSPC_HFP_2_6 True Terminate a call (M)
> +TSPC_HFP_2_7 True Audio connection transfer during an ongoing
> + call (M)
> +TSPC_HFP_2_7a True (*) HF-initiated Audio transfer to AG during
> + ongoing call (O)
> +TSPC_HFP_2_8 True Place a call with a phone number supplied by
> + the HF (M)
> +TSPC_HFP_2_9 True Place a call using memory dialing (M)
> +TSPC_HFP_2_10 True Place a call to the last number dialed (M)
> +TSPC_HFP_2_11 True Call waiting notification (M)
> +TSPC_HFP_2_12 True (*) Three Way Calling (O)
> +TSPC_HFP_2_12a True (*) User Busy (AT+CHLD value 0) (C.3)
> +TSPC_HFP_2_12b True (*) Call Hold Handling (AT+CHLD value 1,2) (C.2)
> +TSPC_HFP_2_12c True (*) Three Way Call (AT+CHLD value 3) (C.3)
> +TSPC_HFP_2_12d False Explicit Call Transfer (AT+CHLD value 4) (C.3)
> +TSPC_HFP_2_13 True Calling Line Identification (CLI) (M)
> +TSPC_HFP_2_14 True (*) Echo canceling (EC) and Noise reduction (NR) (O)
> +TSPC_HFP_2_15 True (*) Voice recognition activation (O)
> +TSPC_HFP_2_15a False Initiate voice recognition from AG (C.6)
> +TSPC_HFP_2_15b False Autonomous voice deactivation (C.6)
> +TSPC_HFP_2_16 False Attach a phone number to a voice tag (O)
> +TSPC_HFP_2_17 True Ability to transmit DTMF codes (M)
> +TSPC_HFP_2_18a True (*) Remote audio volume control – speaker (O)
> +TSPC_HFP_2_18b False Remote audio volume control – microphone (O)
> +TSPC_HFP_2_18c True (*) Volume Level Synchronization – speaker and
> + microphone (C.5)
> +TSPC_HFP_2_19 False Response and hold (O)
> +TSPC_HFP_2_20 True Subscriber Number Information (M)
> +TSPC_HFP_2_21a True Enhanced Call Status (C.4)
> +TSPC_HFP_2_21b False Enhanced Call Control (C.3)
> +TSPC_HFP_2_21c True (*) Enhanced Call Status with limited network
> + notification (C.4)
> +TSPC_HFP_2_22 False Support for automatic link loss recovery (O)
> +TSPC_HFP_2_23 True (*) Individual Indicator Activation (C.9)
> +TSPC_HFP_2_24 False Wide Band Speech service (C.8)
> +TSPC_HFP_2_25 False Support roaming function (O)
> +-------------------------------------------------------------------------------
> +C.1: The AG must support one of item TSPC_HFP_2_4a or TSPC_HFP_2_4b
> +C.2: Mandatory if TSPC_HFP_2_12is TRUE; otherwise excluded
> +C.3: Optional if TSPC_HFP_2_12 is TRUE; otherwise excluded
> +C.4: The AG must support one of item TSPC_HFP_2_21a or TSPC_HFP_2_21c
> +C.5: Mandatory if TSPC_HFP_2_18a or TSPC_HFP_2_18b; otherwise optional
> +C.6: Optional if TSPC_HFP_2_15 is supported, otherwise excluded
> +C.7: Mandatory if TSPC_HFP_2_24 otherwise excluded
> +C.8: Excluded if TSPC_HFP_0_1 otherwise optional
> +C.9: Excluded if TSPC_HFP_0_1 otherwise mandatory
> +C.10: Mandatory if TSPC_HFP_2_24 otherwise optional
> +-------------------------------------------------------------------------------
> +
> +
> + Hands-Free Role
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_3_1 False (*) Connection Management (M)
> +TSPC_HFP_3_2a False (*) Phone Status Information ("service" and "call"
> + indicators) (M)
> +TSPC_HFP_3_2b False Phone Status Information ("callsetup"
> + indicators) (O)
> +TSPC_HFP_3_2c False Accept indicator of signal strength (O)
> +TSPC_HFP_3_2d False Accept indicator of roaming state ("roam:") (O)
> +TSPC_HFP_3_2e False Accept indicator of battery level ("battchg") (O)
> +TSPC_HFP_3_2f False Accept indicator of operator selection (O)
> +TSPC_HFP_3_3 False (*) Audio connection handling (M)
> +TSPC_HFP_3_3a False Audio connection establishment independent
> + of call processing (O)
> +TSPC_HFP_3_3b False eSCO support in Audio Connection (C.7)
> +TSPC_HFP_3_3c False Codec negotiation (C.5)
> +TSPC_HFP_3_4a False (*) Accept an incoming voice call (in-band ring) (M)
> +TSPC_HFP_3_4b False (*) Accept an incoming voice call (no in-band
> + ring) (M)
> +TSPC_HFP_3_4c False Accept an incoming voice call (in-band ring
> + muting) (O)
> +TSPC_HFP_3_5 False (*) Reject an incoming voice call (M)
> +TSPC_HFP_3_6 False (*) Terminate a call (M)
> +
> +TSPC_HFP_3_7 False (*) Audio connection transfer during an ongoing
> + call (M)
> +TSPC_HFP_3_7a False HF-initiated Audio transfer to AG during
> + ongoing call (O)
> +TSPC_HFP_3_8 False Place a call with a phone number supplied by
> + the HF (O)
> +TSPC_HFP_3_9 False Place a call using memory dialing (O)
> +TSPC_HFP_3_10 False Place a call to the last number dialed (O)
> +TSPC_HFP_3_11 False Call waiting notification (O)
> +TSPC_HFP_3_12 False Three Way Calling (O)
> +TSPC_HFP_3_12a False Three way calling (AT+CHLD values 0) (C.2)
> +TSPC_HFP_3_12b False Three way calling (AT+CHLD values 1 and 2) (C.1)
> +TSPC_HFP_3_12c False Three way calling (AT+CHLD value 3) (C.2)
> +TSPC_HFP_3_12d False Three way calling (AT+CHLD value 4) (C.2)
> +TSPC_HFP_3_12e False Originate new call with established call in
> + progress (C.2)
> +TSPC_HFP_3_13 False Calling Line Identification (CLI) (O)
> +TSPC_HFP_3_14 False Echo cancelling (EC) and Noise reduction (NR) (O)
> +TSPC_HFP_3_15 False Voice recognition activation/deactivation (O)
> +TSPC_HFP_3_16 False Attach a phone number to a voice tag (O)
> +TSPC_HFP_3_17 False Ability to transmit DTMF codes (O)
> +TSPC_HFP_3_18a False Remote audio volume control – speaker (O)
> +TSPC_HFP_3_18b False Remote audio volume control – microphone (O)
> +TSPC_HFP_3_18c False Volume Level Synchronization – speaker (C.3)
> +TSPC_HFP_3_18d False Volume Level Synchronization – microphone (C.4)
> +TSPC_HFP_3_18e False HF informs AG about local changes of audio
> + volume (O)
> +TSPC_HFP_3_18f False HF informs AG about local changes of
> + microphone gain (O)
> +TSPC_HFP_3_19 False Response and hold (O)
> +TSPC_HFP_3_20 False Subscriber Number Information (O)
> +TSPC_HFP_3_21a False Enhanced Call Status (O)
> +TSPC_HFP_3_21b False Enhanced Call Control (C.2)
> +TSPC_HFP_3_22 False Support for automatic link loss recovery (O)
> +TSPC_HFP_3_23 False Individual Indicator Activation (C.6)
> +TSPC_HFP_3_24 False Wide Band Speech service (C.6)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory if TSPC_HFP_3_12; otherwise excluded
> +C.2: Optional if TSPC_HFP_3_12; otherwise excluded
> +C.3: Mandatory if TSPC_HFP_3_18a or TSPC_HFP_3_18b, otherwise optional
> +C.4: Mandatory if TSPC_HFP_3_18a, otherwise optional
> +C.5: Mandatory if TSPC_HFP_3_24 otherwise excluded
> +C.6: Excluded if TSPC_HFP_0_1 otherwise optional
> +C.7: Mandatory if TSPC_HFP_3_24 otherwise optional
> +-------------------------------------------------------------------------------
> +
> +
> + Audio Coding Requirements
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_4_1 True CVSD audio coding over SCO (M)
> +TSPC_HFP_4_2 False mSBC audio coding over eSCO (C.1)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory if Wide band speech service is supported TSPC_HFP_2_24 or
> + TSPC_HFP_3_24, otherwise excluded
> +-------------------------------------------------------------------------------
> +
> +
> + Supplementary Interoperability Verification
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HFP_8_1 False Multiple audio transfers during call –
> + AG and HF initiated (C.1)
> +TSPC_HFP_8_2 False Audio transfer by SLC release during
> + an active call (C.1)
> +TSPC_HFP_8_3 False Audio transfer by powering ON HF (O)
> +TSPC_HFP_8_4 False SLC during SDP response (O)
> +TSPC_HFP_8_5 False Handle dynamic server channel number for HFP
> + service (O)
> +TSPC_HFP_8_6 False HF disallows connections in non-discoverable
> + mode (C.2)
> +TSPC_HFP_8_7 False HF connects to AG during incoming call (O)
> +TSPC_HFP_8_8 False Link loss during incoming call (C.3)
> +TSPC_HFP_8_9 False SLC release during incoming call (C.3)
> +TSPC_HFP_8_10 False Voice Recognition Activation (C.4)
> +TSPC_HFP_8_11 False Place outgoing call by dialing number on
> + the AG (O)
> +TSPC_HFP_8_12 False Active call termination – NO CARRIER signal
> + (C.5)
> +-------------------------------------------------------------------------------
> +C.1: Optional if TSPC_HFP_2_7a or TSPC_HFP_3_7a is supported,
> + otherwise excluded
> +C.2: Optional if TSPC_HFP_1_2 is supported, otherwise excluded
> +C.3: Optional if TSPC_HFP_1_1 is supported, otherwise excluded
> +C.4: Optional if TSPC_HFP_2_15 or TSPC_HFP_3_15 is supported,
> + otherwise excluded
> +C.5: Optional if TSPC_HFP_2_6 is supported, otherwise excluded
> +-------------------------------------------------------------------------------
> diff --git a/android/pixit-hfp.txt b/android/pixit-hfp.txt
> new file mode 100644
> index 0000000..c1b2503
> --- /dev/null
> +++ b/android/pixit-hfp.txt
> @@ -0,0 +1,37 @@
> +HFP PIXIT for the PTS tool.
> +
> +PTS version: 5.0
> +
> +* - different than PTS defaults
> +& - should be set to IUT Bluetooth address
> +# - should be set to the respective phone numbers
> +
> + Required PIXIT settings
> +-------------------------------------------------------------------------------
> +Parameter Name Value
> +-------------------------------------------------------------------------------
> +TSPX_security_enabled TRUE
> +TSPX_bd_addr_iut 012345678901 (*&)
> +TSPX_hf_class_of_device 200408
> +TSPX_ag_class_of_device 400204
> +TSPX_packet_type_sco 00A0
> +TSPX_phone_number 1234567 (#)
> +TSPX_second_phone_number 7654321 (#)
> +TSPX_phone_number_type 129
> +TSPX_second_phone_number_type 129
> +TSPX_phone_number_memory 1
> +TSPX_phone_number_memory_invalid_index 9999
> +TSPX_scan_all_memory_dial_locations FALSE
> +TSPX_pin_code 0000
> +TSPX_time_guard 300000
> +TSPX_use_implicit_send TRUE
> +TSPX_verbose_implicit_send FALSE
> +TSPX_delete_link_key FALSE
> +TSPX_server_channel_tester 01
> +TSPX_server_channel_iut 00
> +TSPX_verify_CLIP_information TRUE
> +TSPX_no_fail_verdict FALSE
> +TSPX_network_supports_correct_call_and_callstatus TRUE
> +TSPX_secure_simple_pairing_pass_key_confirmation FALSE
> +TSPX_AG_match_tester_BRSF_codec_negotiation_bit FALSE
> +-------------------------------------------------------------------------------
>
Applied, thanks.
--
Best regards,
Szymon Janc
^ permalink raw reply
* Re: [v2] android/pics: Add PICS and PIXIT for HSP
From: Szymon Janc @ 2014-02-28 12:11 UTC (permalink / raw)
To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1393330071-30103-1-git-send-email-sebastian.chlad@tieto.com>
Hi Sebastian,
On Tuesday 25 of February 2014 13:07:51 Sebastian Chlad wrote:
> Added PICS and PIXIT target Android 4.4
> ---
> android/Makefile.am | 2 +
> android/pics-hsp.txt | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
> android/pixit-hsp.txt | 30 +++++++++++++++
> 3 files changed, 135 insertions(+)
> create mode 100644 android/pics-hsp.txt
> create mode 100644 android/pixit-hsp.txt
>
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 50d0dc0..58cfbae 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -188,6 +188,7 @@ EXTRA_DIST += android/Android.mk android/README \
> android/pics-a2dp.txt \
> android/pics-avctp.txt \
> android/pics-avrcp.txt \
> + android/pics-hsp.txt \
> android/pixit-l2cap.txt \
> android/pixit-gap.txt \
> android/pixit-did.txt \
> @@ -199,6 +200,7 @@ EXTRA_DIST += android/Android.mk android/README \
> android/pixit-a2dp.txt \
> android/pixit-avctp.txt \
> android/pixit-avrcp.txt \
> + android/pixit-hsp.txt \
> android/pts-l2cap.txt \
> android/pts-gap.txt \
> android/pts-did.txt \
> diff --git a/android/pics-hsp.txt b/android/pics-hsp.txt
> new file mode 100644
> index 0000000..3e996ab
> --- /dev/null
> +++ b/android/pics-hsp.txt
> @@ -0,0 +1,103 @@
> +HSP PICS for the PTS tool.
> +
> +PTS version: 5.0
> +
> +* - different than PTS defaults
> +# - not yet implemented/supported
> +
> +M - mandatory
> +O - optional
> +
> + Version
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HSP_0_1 False Version: Headset Profile v1.1 (C.1)
> +TSPC_HSP_0_2 True (*) Version: Headset Profile v1.2 (C.1)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory to support one and only one of these versions.
> +-------------------------------------------------------------------------------
> +
> +
> + Roles
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HSP_1_1 True (*) Role: Audio Gateway (AG) (C.1)
> +TSPC_HSP_1_2 False Role: Headset (HS) (C.1)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory to support at least one of the defined roles.
> +-------------------------------------------------------------------------------
> +
> +
> + Audio Gateway Role
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HSP_2_1 True Incoming audio connection establishment (M)
> +TSPC_HSP_2_2 True (*) Ring (AT command) (C.3)
> +TSPC_HSP_2_3 False Inband ring tone (O)
> +TSPC_HSP_2_4 True (*) Outgoing audio connection establishment (O)
> +TSPC_HSP_2_5 True (*) Audio connection release from HS (C.5)
> +TSPC_HSP_2_6 True Audio connection release from AG (M)
> +TSPC_HSP_2_7 True Audio connection transfer: AG to HS (M)
> +TSPC_HSP_2_8 True Audio connection transfer: HS to AG (M)
> +TSPC_HSP_2_9 False Remote audio volume control (C.1)
> +TSPC_HSP_2_10 False HS informs AG about local changes of audio
> + volume (O)
> +TSPC_HSP_2_11 False Audio volume setting storage by HS (O)
> +TSPC_HSP_2_12 False Remote microphone gain control (C.2)
> +TSPC_HSP_2_13 False HS informs AG about local changes of microphone
> + gain (O)
> +TSPC_HSP_2_14 False Microphone gain setting storage by HS (O)
> +TSPC_HSP_2_15 True Connection handling with Detach/Page (M)
> +TSPC_HSP_2_16 False Connection handling with Park Mode (C.4)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory if TSPC_HSP_2_10 is supported, otherwise optional
> +C:2: Mandatory if TSPC_HSP_2_13 is supported, otherwise optional
> +C.3: Excluded if TSPC_HSP_2_3 and TSPC_HSP_4_1 ("Show that in-band
> + ringing and RING are mutually exclusive") are supported,
> + otherwise optional
> +C.4: Excluded if TSPC_HSP_0_2 is supported, otherwise optional
> +C.5: Mandatory if TSPC_HSP_0_1 is supported, otherwise optional
> +-------------------------------------------------------------------------------
> +
> +
> + Headset Application Features
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HSP_3_1 False (*) Incoming audio connection establishment (M)
> +TSPC_HSP_3_2 False (*) Ring (AT command) (M)
> +TSPC_HSP_3_3 False (*) Inband ring tone (M)
> +TSPC_HSP_3_4 False (*) Outgoing audio connection establishment (M)
> +TSPC_HSP_3_5 False (*) Audio connection release from HS (M)
> +TSPC_HSP_3_6 False (*) Audio connection release from AG (M)
> +TSPC_HSP_3_7 False (*) Audio connection transfer: AG to HS (M)
> +TSPC_HSP_3_8 False (*) Audio connection transfer: HS to AG (M)
> +TSPC_HSP_3_9 False Remote audio volume control (C.1)
> +TSPC_HSP_3_10 False HS informs AG about local changes of audio
> + volume (O)
> +TSPC_HSP_3_11 False Audio volume setting storage by HS (O)
> +TSPC_HSP_3_12 False Remote microphone gain control (C.2)
> +TSPC_HSP_3_13 False HS informs AG about local changes of microphone
> + gain (O)
> +TSPC_HSP_3_14 False (*) Microphone gain setting storage by HS (O)
> +TSPC_HSP_3_15 False Connection handling with Detach/Page (M)
> +TSPC_HSP_3_16 False Connection handling with Park Mode (C.3)
> +-------------------------------------------------------------------------------
> +C.1: Mandatory if TSPC_HSP_3_10 is supported, otherwise optional
> +C.2: Mandatory if TSPC_HSP_2_13 is supported, otherwise optional
> +C.3: Excluded if TSPC_HSP_0_2 is supported, otherwise optional
> +-------------------------------------------------------------------------------
> +
> +
> + Errata Service Releases
> +-------------------------------------------------------------------------------
> +Parameter Name Selected Description
> +-------------------------------------------------------------------------------
> +TSPC_HSP_4_1 False Show that in-band ringing and RING are
> + mutually exclusive (C.1)
> +-------------------------------------------------------------------------------
> +C.1: Excluded if TSPC_HSP_0_2 is supported, otherwise optional
> +-------------------------------------------------------------------------------
> diff --git a/android/pixit-hsp.txt b/android/pixit-hsp.txt
> new file mode 100644
> index 0000000..a2c1181
> --- /dev/null
> +++ b/android/pixit-hsp.txt
> @@ -0,0 +1,30 @@
> +HSP PIXIT for the PTS tool.
> +
> +PTS version: 5.0
> +
> +* - different than PTS defaults
> +& - should be set to IUT Bluetooth address
> +
> + Required PIXIT settings
> +-------------------------------------------------------------------------------
> +Parameter Name Value
> +-------------------------------------------------------------------------------
> +TSPX_security_enabled TRUE
> +TSPX_bd_addr_iut 012345678901 (*&)
> +TSPX_hs_class_of_device 200404
> +TSPX_ag_class_of_device 400204
> +TSPX_packet_type_sco 00A0
> +TSPX_pin_code 0000
> +TSPX_time_guard 20000000
> +TSPX_use_implicit_send TRUE
> +TSPX_verbose_implicit_send FALSE
> +TSPX_delete_link_key FALSE
> +TSPX_server_channel_tester 01
> +TSPX_server_channel_iut 00
> +TSPX_no_fail_verdict FALSE
> +TSPX_remote_audio_volume_control TRUE
> +TSPX_secure_simple_pairing_pass_key_confirmation FALSE
> +TSPX_inband_ring_only FALSE
> +TSPX_no_ring_or_inband_ring_tone FALSE
> +TSPX_iut_establish_audio_before_RING FALSE
> +-------------------------------------------------------------------------------
>
Applied, thanks.
--
Best regards,
Szymon Janc
^ 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