* [PATCH 00/10] Some HAL IPC work
@ 2014-06-11 14:32 Szymon Janc
2014-06-11 14:32 ` [PATCH 01/10] android/ipc: Make struct service_handler private Szymon Janc
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Hi,
Those patches are cleanups and fixes for HAL part of IPC. Those are
first step to making HAL IPC library like so that it can be reused
by audio and sco HALs.
Eventually this should also allow for better recovery in case of IPC
error i.e. not calling exit() directly but custom destroy callback.
But this is not implemented yet.
Last two patches add FD passing in notification (as of now this is
needed only for health HAL).
BR
Szymon Janc
Szymon Janc (10):
android/ipc: Make struct service_handler private
android/hal-ipc: Allow to pass custom path to IPC
android/hal-ipc: Fix missing mutex unlock
android/hal-ipc: Move exit calls outside of handle_msg
android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd
android/hal-ipc: Move exit calls under label in notification_handler
android/hal-ipc: Split IPC init and accept to separate functions
android/hal-ipc: Move daemon starting to bluetooth HAL
android/hal-ipc: Pass FD to notification handlers
android/ipc: Add support for sending FD in notifications
android/hal-a2dp.c | 4 +-
android/hal-avrcp.c | 24 +++----
android/hal-bluetooth.c | 40 +++++++----
android/hal-gatt.c | 62 ++++++++--------
android/hal-handsfree.c | 32 ++++-----
android/hal-health.c | 2 +-
android/hal-hidhost.c | 12 ++--
android/hal-ipc.c | 186 ++++++++++++++++++++++++++----------------------
android/hal-ipc.h | 5 +-
android/hal-pan.c | 4 +-
android/ipc.c | 13 +++-
android/ipc.h | 8 +--
12 files changed, 214 insertions(+), 178 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 01/10] android/ipc: Make struct service_handler private
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 02/10] android/hal-ipc: Allow to pass custom path to IPC Szymon Janc
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/ipc.c | 5 +++++
android/ipc.h | 5 -----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/android/ipc.c b/android/ipc.c
index 8cd34ea..fc58a1c 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -40,6 +40,11 @@
#include "ipc.h"
#include "src/log.h"
+struct service_handler {
+ const struct ipc_handler *handler;
+ uint8_t size;
+};
+
struct ipc {
struct service_handler *services;
int service_max;
diff --git a/android/ipc.h b/android/ipc.h
index cc4e92d..e97f0e6 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -27,11 +27,6 @@ struct ipc_handler {
size_t data_len;
};
-struct service_handler {
- const struct ipc_handler *handler;
- uint8_t size;
-};
-
struct ipc;
typedef void (*ipc_disconnect_cb) (void *data);
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/10] android/hal-ipc: Allow to pass custom path to IPC
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
2014-06-11 14:32 ` [PATCH 01/10] android/ipc: Make struct service_handler private Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 03/10] android/hal-ipc: Fix missing mutex unlock Szymon Janc
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/hal-bluetooth.c | 2 +-
android/hal-ipc.c | 4 ++--
android/hal-ipc.h | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index e9a677a..c2a1085 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -420,7 +420,7 @@ static int init(bt_callbacks_t *callbacks)
hal_ipc_register(HAL_SERVICE_ID_BLUETOOTH, ev_handlers,
sizeof(ev_handlers)/sizeof(ev_handlers[0]));
- if (!hal_ipc_init()) {
+ if (!hal_ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH))) {
bt_hal_cbacks = NULL;
return BT_STATUS_FAIL;
}
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 8f5babe..81d3a1b 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -229,7 +229,7 @@ static int accept_connection(int sk)
return new_sk;
}
-bool hal_ipc_init(void)
+bool hal_ipc_init(const char *path, size_t size)
{
struct sockaddr_un addr;
int sk;
@@ -246,7 +246,7 @@ bool hal_ipc_init(void)
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, path, size);
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
err = errno;
diff --git a/android/hal-ipc.h b/android/hal-ipc.h
index 2fbf30f..0d16cdb 100644
--- a/android/hal-ipc.h
+++ b/android/hal-ipc.h
@@ -21,7 +21,7 @@ struct hal_ipc_handler {
size_t data_len;
};
-bool hal_ipc_init(void);
+bool hal_ipc_init(const char *path, size_t size);
void hal_ipc_cleanup(void);
int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/10] android/hal-ipc: Fix missing mutex unlock
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
2014-06-11 14:32 ` [PATCH 01/10] android/ipc: Make struct service_handler private Szymon Janc
2014-06-11 14:32 ` [PATCH 02/10] android/hal-ipc: Allow to pass custom path to IPC Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 04/10] android/hal-ipc: Move exit calls outside of handle_msg Szymon Janc
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This is a preparation for destroy callback.
---
android/hal-ipc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 81d3a1b..ee3a04c 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -366,6 +366,7 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
/* socket was shutdown */
if (ret == 0) {
error("Command socket closed, aborting");
+ pthread_mutex_unlock(&cmd_sk_mutex);
exit(EXIT_FAILURE);
}
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/10] android/hal-ipc: Move exit calls outside of handle_msg
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (2 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 03/10] android/hal-ipc: Fix missing mutex unlock Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 05/10] android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd Szymon Janc
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This reduce number of exit points in preparation for destroy callback.
---
android/hal-ipc.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index ee3a04c..abb3b4b 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -62,41 +62,39 @@ void hal_ipc_unregister(uint8_t service)
services[service].size = 0;
}
-static void handle_msg(void *buf, ssize_t len)
+static bool handle_msg(void *buf, ssize_t len)
{
struct ipc_hdr *msg = buf;
const struct hal_ipc_handler *handler;
uint8_t opcode;
if (len < (ssize_t) sizeof(*msg)) {
- error("IPC: message too small (%zd bytes), aborting", len);
- exit(EXIT_FAILURE);
+ error("IPC: message too small (%zd bytes)", len);
+ return false;
}
if (len != (ssize_t) (sizeof(*msg) + msg->len)) {
- error("IPC: message malformed (%zd bytes), aborting", len);
- exit(EXIT_FAILURE);
+ error("IPC: message malformed (%zd bytes)", len);
+ return false;
}
/* if service is valid */
if (msg->service_id > HAL_SERVICE_ID_MAX) {
- error("IPC: unknown service (0x%x), aborting",
- msg->service_id);
- exit(EXIT_FAILURE);
+ error("IPC: unknown service (0x%x)", msg->service_id);
+ return false;
}
/* if service is registered */
if (!services[msg->service_id].handler) {
- error("IPC: unregistered service (0x%x), aborting",
- msg->service_id);
- exit(EXIT_FAILURE);
+ error("IPC: unregistered service (0x%x)", msg->service_id);
+ return false;
}
/* if opcode fit valid range */
if (msg->opcode < HAL_MINIMUM_EVENT) {
- error("IPC: invalid opcode for service 0x%x (0x%x), aborting",
+ error("IPC: invalid opcode for service 0x%x (0x%x)",
msg->service_id, msg->opcode);
- exit(EXIT_FAILURE);
+ return false;
}
/*
@@ -107,9 +105,9 @@ static void handle_msg(void *buf, ssize_t len)
/* if opcode is valid */
if (opcode >= services[msg->service_id].size) {
- error("IPC: invalid opcode for service 0x%x (0x%x), aborting",
+ error("IPC: invalid opcode for service 0x%x (0x%x)",
msg->service_id, msg->opcode);
- exit(EXIT_FAILURE);
+ return false;
}
handler = &services[msg->service_id].handler[opcode];
@@ -118,12 +116,14 @@ static void handle_msg(void *buf, ssize_t len)
if ((handler->var_len && handler->data_len > msg->len) ||
(!handler->var_len && handler->data_len != msg->len)) {
error("IPC: message size invalid for service 0x%x opcode 0x%x "
- "(%u bytes), aborting",
+ "(%u bytes)",
msg->service_id, msg->opcode, msg->len);
- exit(EXIT_FAILURE);
+ return false;
}
handler->handler(msg->payload, msg->len);
+
+ return true;
}
static void *notification_handler(void *data)
@@ -184,7 +184,8 @@ static void *notification_handler(void *data)
}
}
- handle_msg(buf, ret);
+ if (!handle_msg(buf, ret))
+ exit(EXIT_FAILURE);
}
close(notif_sk);
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/10] android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (3 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 04/10] android/hal-ipc: Move exit calls outside of handle_msg Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 06/10] android/hal-ipc: Move exit calls under label in notification_handler Szymon Janc
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This reduce number of exit points in preparation for destroy callback.
---
android/hal-ipc.c | 49 ++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index abb3b4b..2cc6eda 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -329,8 +329,8 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
size_t s_len = sizeof(s);
if (cmd_sk < 0) {
- error("Invalid cmd socket passed to hal_ipc_cmd, aborting");
- exit(EXIT_FAILURE);
+ error("Invalid cmd socket passed to hal_ipc_cmd");
+ goto failed;
}
if (!rsp || !rsp_len) {
@@ -359,16 +359,16 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
ret = sendmsg(cmd_sk, &msg, 0);
if (ret < 0) {
- error("Sending command failed, aborting :%s", strerror(errno));
+ error("Sending command failed:%s", strerror(errno));
pthread_mutex_unlock(&cmd_sk_mutex);
- exit(EXIT_FAILURE);
+ goto failed;
}
/* socket was shutdown */
if (ret == 0) {
- error("Command socket closed, aborting");
+ error("Command socket closed");
pthread_mutex_unlock(&cmd_sk_mutex);
- exit(EXIT_FAILURE);
+ goto failed;
}
memset(&msg, 0, sizeof(msg));
@@ -390,48 +390,48 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
}
ret = recvmsg(cmd_sk, &msg, 0);
+
+ pthread_mutex_unlock(&cmd_sk_mutex);
+
if (ret < 0) {
- error("Receiving command response failed, aborting :%s",
- strerror(errno));
- pthread_mutex_unlock(&cmd_sk_mutex);
- exit(EXIT_FAILURE);
+ error("Receiving command response failed: %s", strerror(errno));
+ goto failed;
}
- pthread_mutex_unlock(&cmd_sk_mutex);
if (ret < (ssize_t) sizeof(cmd)) {
- error("Too small response received(%zd bytes), aborting", ret);
- exit(EXIT_FAILURE);
+ error("Too small response received(%zd bytes)", ret);
+ goto failed;
}
if (cmd.service_id != service_id) {
- error("Invalid service id (0x%x vs 0x%x), aborting",
+ error("Invalid service id (0x%x vs 0x%x)",
cmd.service_id, service_id);
- exit(EXIT_FAILURE);
+ goto failed;
}
if (ret != (ssize_t) (sizeof(cmd) + cmd.len)) {
- error("Malformed response received(%zd bytes), aborting", ret);
- exit(EXIT_FAILURE);
+ error("Malformed response received(%zd bytes)", ret);
+ goto failed;
}
if (cmd.opcode != opcode && cmd.opcode != HAL_OP_STATUS) {
- error("Invalid opcode received (0x%x vs 0x%x), aborting",
+ error("Invalid opcode received (0x%x vs 0x%x)",
cmd.opcode, opcode);
- exit(EXIT_FAILURE);
+ goto failed;
}
if (cmd.opcode == HAL_OP_STATUS) {
struct ipc_status *s = rsp;
if (sizeof(*s) != cmd.len) {
- error("Invalid status length, aborting");
- exit(EXIT_FAILURE);
+ error("Invalid status length");
+ goto failed;
}
if (s->code == HAL_STATUS_SUCCESS) {
- error("Invalid success status response, aborting");
- exit(EXIT_FAILURE);
+ error("Invalid success status response");
+ goto failed;
}
return s->code;
@@ -457,4 +457,7 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
*rsp_len = cmd.len;
return BT_STATUS_SUCCESS;
+
+failed:
+ exit(EXIT_FAILURE);
}
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 06/10] android/hal-ipc: Move exit calls under label in notification_handler
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (4 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 05/10] android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 07/10] android/hal-ipc: Split IPC init and accept to separate functions Szymon Janc
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This reduce number of exit points in preparation for destroy callback.
---
android/hal-ipc.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 2cc6eda..59bc3dc 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -154,9 +154,9 @@ static void *notification_handler(void *data)
ret = recvmsg(notif_sk, &msg, 0);
if (ret < 0) {
- error("Receiving notifications failed, aborting :%s",
+ error("Receiving notifications failed: %s",
strerror(errno));
- exit(EXIT_FAILURE);
+ goto failed;
}
/* socket was shutdown */
@@ -168,8 +168,8 @@ static void *notification_handler(void *data)
}
pthread_mutex_unlock(&cmd_sk_mutex);
- error("Notification socket closed, aborting");
- exit(EXIT_FAILURE);
+ error("Notification socket closed");
+ goto failed;
}
fd = -1;
@@ -185,7 +185,7 @@ static void *notification_handler(void *data)
}
if (!handle_msg(buf, ret))
- exit(EXIT_FAILURE);
+ goto failed;
}
close(notif_sk);
@@ -196,6 +196,9 @@ static void *notification_handler(void *data)
DBG("exit");
return NULL;
+
+failed:
+ exit(EXIT_FAILURE);
}
static int accept_connection(int sk)
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/10] android/hal-ipc: Split IPC init and accept to separate functions
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (5 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 06/10] android/hal-ipc: Move exit calls under label in notification_handler Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 08/10] android/hal-ipc: Move daemon starting to bluetooth HAL Szymon Janc
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This allows to perform custom action between listening and accepting
eg starting bluetoothd.
---
android/hal-bluetooth.c | 10 ++++--
android/hal-ipc.c | 88 ++++++++++++++++++++++++++++---------------------
android/hal-ipc.h | 1 +
3 files changed, 58 insertions(+), 41 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index c2a1085..a220328 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -415,12 +415,16 @@ static int init(bt_callbacks_t *callbacks)
if (interface_ready())
return BT_STATUS_DONE;
- bt_hal_cbacks = callbacks;
-
hal_ipc_register(HAL_SERVICE_ID_BLUETOOTH, ev_handlers,
sizeof(ev_handlers)/sizeof(ev_handlers[0]));
- if (!hal_ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH))) {
+ if (!hal_ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH)))
+ return BT_STATUS_FAIL;
+
+ bt_hal_cbacks = callbacks;
+
+ if (!hal_ipc_accept()) {
+ hal_ipc_cleanup();
bt_hal_cbacks = NULL;
return BT_STATUS_FAIL;
}
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 59bc3dc..b1b85b0 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -35,6 +35,7 @@
#define CONNECT_TIMEOUT (10 * 1000)
+static int listen_sk = -1;
static int cmd_sk = -1;
static int notif_sk = -1;
@@ -233,6 +234,44 @@ static int accept_connection(int sk)
return new_sk;
}
+bool hal_ipc_accept(void)
+{
+ int err;
+
+ /* Start Android Bluetooth daemon service */
+ if (property_set("bluetooth.start", "daemon") < 0) {
+ error("Failed to set bluetooth.start=daemon");
+ return false;
+ }
+
+ cmd_sk = accept_connection(listen_sk);
+ if (cmd_sk < 0)
+ return false;
+
+ notif_sk = accept_connection(listen_sk);
+ if (notif_sk < 0) {
+ close(cmd_sk);
+ cmd_sk = -1;
+ return false;
+ }
+
+ err = pthread_create(¬if_th, NULL, notification_handler, NULL);
+ if (err) {
+ notif_th = 0;
+ error("Failed to start notification thread: %d (%s)", err,
+ strerror(err));
+ close(cmd_sk);
+ cmd_sk = -1;
+ close(notif_sk);
+ notif_sk = -1;
+ return false;
+ }
+
+ info("IPC connected");
+
+ return true;
+}
+
bool hal_ipc_init(const char *path, size_t size)
{
struct sockaddr_un addr;
@@ -267,53 +306,26 @@ bool hal_ipc_init(const char *path, size_t size)
return false;
}
- /* Start Android Bluetooth daemon service */
- if (property_set("bluetooth.start", "daemon") < 0) {
- error("Failed to set bluetooth.start=daemon");
- close(sk);
- return false;
- }
-
- cmd_sk = accept_connection(sk);
- if (cmd_sk < 0) {
- close(sk);
- return false;
- }
-
- notif_sk = accept_connection(sk);
- if (notif_sk < 0) {
- close(sk);
- close(cmd_sk);
- cmd_sk = -1;
- return false;
- }
-
- info("bluetoothd connected");
-
- close(sk);
-
- err = pthread_create(¬if_th, NULL, notification_handler, NULL);
- if (err) {
- notif_th = 0;
- error("Failed to start notification thread: %d (%s)", err,
- strerror(err));
- close(cmd_sk);
- cmd_sk = -1;
- close(notif_sk);
- notif_sk = -1;
- return false;
- }
+ listen_sk = sk;
return true;
}
void hal_ipc_cleanup(void)
{
+ close(listen_sk);
+ listen_sk = -1;
+
pthread_mutex_lock(&cmd_sk_mutex);
- close(cmd_sk);
- cmd_sk = -1;
+ if (cmd_sk >= 0) {
+ close(cmd_sk);
+ cmd_sk = -1;
+ }
pthread_mutex_unlock(&cmd_sk_mutex);
+ if (notif_sk < 0)
+ return;
+
shutdown(notif_sk, SHUT_RD);
pthread_join(notif_th, NULL);
diff --git a/android/hal-ipc.h b/android/hal-ipc.h
index 0d16cdb..b61d557 100644
--- a/android/hal-ipc.h
+++ b/android/hal-ipc.h
@@ -22,6 +22,7 @@ struct hal_ipc_handler {
};
bool hal_ipc_init(const char *path, size_t size);
+bool hal_ipc_accept(void);
void hal_ipc_cleanup(void);
int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/10] android/hal-ipc: Move daemon starting to bluetooth HAL
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (6 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 07/10] android/hal-ipc: Split IPC init and accept to separate functions Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 09/10] android/hal-ipc: Pass FD to notification handlers Szymon Janc
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/hal-bluetooth.c | 8 ++++++++
android/hal-ipc.c | 6 ------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a220328..b8eae69 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -423,6 +423,14 @@ static int init(bt_callbacks_t *callbacks)
bt_hal_cbacks = callbacks;
+ /* Start Android Bluetooth daemon service */
+ if (property_set("bluetooth.start", "daemon") < 0) {
+ error("Failed to set bluetooth.start=daemon");
+ hal_ipc_cleanup();
+ bt_hal_cbacks = NULL;
+ return BT_STATUS_FAIL;
+ }
+
if (!hal_ipc_accept()) {
hal_ipc_cleanup();
bt_hal_cbacks = NULL;
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index b1b85b0..7dd6870 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -238,12 +238,6 @@ bool hal_ipc_accept(void)
{
int err;
- /* Start Android Bluetooth daemon service */
- if (property_set("bluetooth.start", "daemon") < 0) {
- error("Failed to set bluetooth.start=daemon");
- return false;
- }
-
cmd_sk = accept_connection(listen_sk);
if (cmd_sk < 0)
return false;
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/10] android/hal-ipc: Pass FD to notification handlers
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (7 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 08/10] android/hal-ipc: Move daemon starting to bluetooth HAL Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-11 14:32 ` [PATCH 10/10] android/ipc: Add support for sending FD in notifications Szymon Janc
2014-06-12 11:07 ` [PATCH 00/10] Some HAL IPC work Szymon Janc
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/hal-a2dp.c | 4 ++--
android/hal-avrcp.c | 24 +++++++++----------
android/hal-bluetooth.c | 22 +++++++++---------
android/hal-gatt.c | 62 ++++++++++++++++++++++++-------------------------
android/hal-handsfree.c | 32 ++++++++++++-------------
android/hal-health.c | 2 +-
android/hal-hidhost.c | 12 +++++-----
android/hal-ipc.c | 6 ++---
android/hal-ipc.h | 2 +-
android/hal-pan.c | 4 ++--
10 files changed, 85 insertions(+), 85 deletions(-)
diff --git a/android/hal-a2dp.c b/android/hal-a2dp.c
index d43c873..87aebde 100644
--- a/android/hal-a2dp.c
+++ b/android/hal-a2dp.c
@@ -31,7 +31,7 @@ static bool interface_ready(void)
return cbs != NULL;
}
-static void handle_conn_state(void *buf, uint16_t len)
+static void handle_conn_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_a2dp_conn_state *ev = buf;
@@ -40,7 +40,7 @@ static void handle_conn_state(void *buf, uint16_t len)
(bt_bdaddr_t *) (ev->bdaddr));
}
-static void handle_audio_state(void *buf, uint16_t len)
+static void handle_audio_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_a2dp_audio_state *ev = buf;
diff --git a/android/hal-avrcp.c b/android/hal-avrcp.c
index 5e07366..09f5463 100644
--- a/android/hal-avrcp.c
+++ b/android/hal-avrcp.c
@@ -33,7 +33,7 @@ static bool interface_ready(void)
return cbs != NULL;
}
-static void handle_remote_features(void *buf, uint16_t len)
+static void handle_remote_features(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_remote_features *ev = buf;
@@ -42,19 +42,19 @@ static void handle_remote_features(void *buf, uint16_t len)
ev->features);
}
-static void handle_get_play_status(void *buf, uint16_t len)
+static void handle_get_play_status(void *buf, uint16_t len, int fd)
{
if (cbs->get_play_status_cb)
cbs->get_play_status_cb();
}
-static void handle_list_player_attrs(void *buf, uint16_t len)
+static void handle_list_player_attrs(void *buf, uint16_t len, int fd)
{
if (cbs->list_player_app_attr_cb)
cbs->list_player_app_attr_cb();
}
-static void handle_list_player_values(void *buf, uint16_t len)
+static void handle_list_player_values(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_list_player_values *ev = buf;
@@ -62,7 +62,7 @@ static void handle_list_player_values(void *buf, uint16_t len)
cbs->list_player_app_values_cb(ev->attr);
}
-static void handle_get_player_values(void *buf, uint16_t len)
+static void handle_get_player_values(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_get_player_values *ev = buf;
btrc_player_attr_t attrs[4];
@@ -78,7 +78,7 @@ static void handle_get_player_values(void *buf, uint16_t len)
cbs->get_player_app_value_cb(ev->number, attrs);
}
-static void handle_get_player_attrs_text(void *buf, uint16_t len)
+static void handle_get_player_attrs_text(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_get_player_attrs_text *ev = buf;
btrc_player_attr_t attrs[4];
@@ -94,7 +94,7 @@ static void handle_get_player_attrs_text(void *buf, uint16_t len)
cbs->get_player_app_attrs_text_cb(ev->number, attrs);
}
-static void handle_get_player_values_text(void *buf, uint16_t len)
+static void handle_get_player_values_text(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_get_player_values_text *ev = buf;
@@ -103,7 +103,7 @@ static void handle_get_player_values_text(void *buf, uint16_t len)
ev->values);
}
-static void handle_set_player_value(void *buf, uint16_t len)
+static void handle_set_player_value(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_set_player_values *ev = buf;
struct hal_avrcp_player_attr_value *attrs;
@@ -125,7 +125,7 @@ static void handle_set_player_value(void *buf, uint16_t len)
cbs->set_player_app_value_cb(&values);
}
-static void handle_get_element_attrs(void *buf, uint16_t len)
+static void handle_get_element_attrs(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_get_element_attrs *ev = buf;
btrc_media_attr_t attrs[BTRC_MAX_APP_SETTINGS];
@@ -141,7 +141,7 @@ static void handle_get_element_attrs(void *buf, uint16_t len)
cbs->get_element_attr_cb(ev->number, attrs);
}
-static void handle_register_notification(void *buf, uint16_t len)
+static void handle_register_notification(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_register_notification *ev = buf;
@@ -149,7 +149,7 @@ static void handle_register_notification(void *buf, uint16_t len)
cbs->register_notification_cb(ev->event, ev->param);
}
-static void handle_volume_changed(void *buf, uint16_t len)
+static void handle_volume_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_volume_changed *ev = buf;
@@ -157,7 +157,7 @@ static void handle_volume_changed(void *buf, uint16_t len)
cbs->volume_change_cb(ev->volume, ev->type);
}
-static void handle_passthrough_cmd(void *buf, uint16_t len)
+static void handle_passthrough_cmd(void *buf, uint16_t len, int fd)
{
struct hal_ev_avrcp_passthrough_cmd *ev = buf;
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index b8eae69..4291430 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -52,7 +52,7 @@ static const bt_callbacks_t *bt_hal_cbacks = NULL;
*hal_len = 1; \
} while (0)
-static void handle_adapter_state_changed(void *buf, uint16_t len)
+static void handle_adapter_state_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_adapter_state_changed *ev = buf;
@@ -197,7 +197,7 @@ static void device_props_to_hal(bt_property_t *send_props,
exit(EXIT_FAILURE);
}
-static void handle_adapter_props_changed(void *buf, uint16_t len)
+static void handle_adapter_props_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_adapter_props_changed *ev = buf;
bt_property_t props[ev->num_props];
@@ -213,7 +213,7 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
}
-static void handle_bond_state_change(void *buf, uint16_t len)
+static void handle_bond_state_change(void *buf, uint16_t len, int fd)
{
struct hal_ev_bond_state_changed *ev = buf;
bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
@@ -225,7 +225,7 @@ static void handle_bond_state_change(void *buf, uint16_t len)
ev->state);
}
-static void handle_pin_request(void *buf, uint16_t len)
+static void handle_pin_request(void *buf, uint16_t len, int fd)
{
struct hal_ev_pin_request *ev = buf;
/* Those are declared as packed, so it's safe to assign pointers */
@@ -238,7 +238,7 @@ static void handle_pin_request(void *buf, uint16_t len)
bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
}
-static void handle_ssp_request(void *buf, uint16_t len)
+static void handle_ssp_request(void *buf, uint16_t len, int fd)
{
struct hal_ev_ssp_request *ev = buf;
/* Those are declared as packed, so it's safe to assign pointers */
@@ -270,7 +270,7 @@ static bool interface_ready(void)
return bt_hal_cbacks != NULL;
}
-static void handle_discovery_state_changed(void *buf, uint16_t len)
+static void handle_discovery_state_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_discovery_state_changed *ev = buf;
@@ -280,7 +280,7 @@ static void handle_discovery_state_changed(void *buf, uint16_t len)
bt_hal_cbacks->discovery_state_changed_cb(ev->state);
}
-static void handle_device_found(void *buf, uint16_t len)
+static void handle_device_found(void *buf, uint16_t len, int fd)
{
struct hal_ev_device_found *ev = buf;
bt_property_t props[ev->num_props];
@@ -296,7 +296,7 @@ static void handle_device_found(void *buf, uint16_t len)
bt_hal_cbacks->device_found_cb(ev->num_props, props);
}
-static void handle_device_state_changed(void *buf, uint16_t len)
+static void handle_device_state_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_remote_device_props *ev = buf;
bt_property_t props[ev->num_props];
@@ -314,7 +314,7 @@ static void handle_device_state_changed(void *buf, uint16_t len)
ev->num_props, props);
}
-static void handle_acl_state_changed(void *buf, uint16_t len)
+static void handle_acl_state_changed(void *buf, uint16_t len, int fd)
{
struct hal_ev_acl_state_changed *ev = buf;
bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
@@ -326,7 +326,7 @@ static void handle_acl_state_changed(void *buf, uint16_t len)
ev->state);
}
-static void handle_dut_mode_receive(void *buf, uint16_t len)
+static void handle_dut_mode_receive(void *buf, uint16_t len, int fd)
{
struct hal_ev_dut_mode_receive *ev = buf;
@@ -341,7 +341,7 @@ static void handle_dut_mode_receive(void *buf, uint16_t len)
bt_hal_cbacks->dut_mode_recv_cb(ev->opcode, ev->data, ev->len);
}
-static void handle_le_test_mode(void *buf, uint16_t len)
+static void handle_le_test_mode(void *buf, uint16_t len, int fd)
{
struct hal_ev_le_test_mode *ev = buf;
diff --git a/android/hal-gatt.c b/android/hal-gatt.c
index 6f0d2c5..d0a8a70 100644
--- a/android/hal-gatt.c
+++ b/android/hal-gatt.c
@@ -63,7 +63,7 @@ static void srvc_id_to_hal(struct hal_gatt_srvc_id *to, btgatt_srvc_id_t *from)
/* Client Event Handlers */
-static void handle_register_client(void *buf, uint16_t len)
+static void handle_register_client(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_register_client *ev = buf;
@@ -72,7 +72,7 @@ static void handle_register_client(void *buf, uint16_t len)
(bt_uuid_t *) ev->app_uuid);
}
-static void handle_scan_result(void *buf, uint16_t len)
+static void handle_scan_result(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_scan_result *ev = buf;
uint8_t ad[62];
@@ -91,7 +91,7 @@ static void handle_scan_result(void *buf, uint16_t len)
ad);
}
-static void handle_connect(void *buf, uint16_t len)
+static void handle_connect(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_connect *ev = buf;
@@ -100,7 +100,7 @@ static void handle_connect(void *buf, uint16_t len)
(bt_bdaddr_t *) ev->bda);
}
-static void handle_disconnect(void *buf, uint16_t len)
+static void handle_disconnect(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_disconnect *ev = buf;
@@ -109,7 +109,7 @@ static void handle_disconnect(void *buf, uint16_t len)
(bt_bdaddr_t *) ev->bda);
}
-static void handle_search_complete(void *buf, uint16_t len)
+static void handle_search_complete(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_search_complete *ev = buf;
@@ -117,7 +117,7 @@ static void handle_search_complete(void *buf, uint16_t len)
cbs->client->search_complete_cb(ev->conn_id, ev->status);
}
-static void handle_search_result(void *buf, uint16_t len)
+static void handle_search_result(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_search_result *ev = buf;
btgatt_srvc_id_t srvc_id;
@@ -128,7 +128,7 @@ static void handle_search_result(void *buf, uint16_t len)
cbs->client->search_result_cb(ev->conn_id, &srvc_id);
}
-static void handle_get_characteristic(void *buf, uint16_t len)
+static void handle_get_characteristic(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_get_characteristic *ev = buf;
btgatt_gatt_id_t char_id;
@@ -143,7 +143,7 @@ static void handle_get_characteristic(void *buf, uint16_t len)
ev->char_prop);
}
-static void handle_get_descriptor(void *buf, uint16_t len)
+static void handle_get_descriptor(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_get_descriptor *ev = buf;
btgatt_gatt_id_t descr_id;
@@ -159,7 +159,7 @@ static void handle_get_descriptor(void *buf, uint16_t len)
&srvc_id, &char_id, &descr_id);
}
-static void handle_get_included_service(void *buf, uint16_t len)
+static void handle_get_included_service(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_get_inc_service *ev = buf;
btgatt_srvc_id_t srvc_id;
@@ -174,7 +174,7 @@ static void handle_get_included_service(void *buf, uint16_t len)
&incl_srvc_id);
}
-static void handle_register_for_notification(void *buf, uint16_t len)
+static void handle_register_for_notification(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_reg_for_notif *ev = buf;
btgatt_gatt_id_t char_id;
@@ -191,7 +191,7 @@ static void handle_register_for_notification(void *buf, uint16_t len)
&char_id);
}
-static void handle_notify(void *buf, uint16_t len)
+static void handle_notify(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_notify *ev = buf;
btgatt_notify_params_t params;
@@ -215,7 +215,7 @@ static void handle_notify(void *buf, uint16_t len)
cbs->client->notify_cb(ev->conn_id, ¶ms);
}
-static void handle_read_characteristic(void *buf, uint16_t len)
+static void handle_read_characteristic(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_read_characteristic *ev = buf;
btgatt_read_params_t params;
@@ -242,7 +242,7 @@ static void handle_read_characteristic(void *buf, uint16_t len)
¶ms);
}
-static void handle_write_characteristic(void *buf, uint16_t len)
+static void handle_write_characteristic(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_write_characteristic *ev = buf;
btgatt_write_params_t params;
@@ -260,7 +260,7 @@ static void handle_write_characteristic(void *buf, uint16_t len)
¶ms);
}
-static void handle_read_descriptor(void *buf, uint16_t len)
+static void handle_read_descriptor(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_read_descriptor *ev = buf;
btgatt_read_params_t params;
@@ -287,7 +287,7 @@ static void handle_read_descriptor(void *buf, uint16_t len)
¶ms);
}
-static void handle_write_descriptor(void *buf, uint16_t len)
+static void handle_write_descriptor(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_write_descriptor *ev = buf;
btgatt_write_params_t params;
@@ -305,7 +305,7 @@ static void handle_write_descriptor(void *buf, uint16_t len)
¶ms);
}
-static void handle_execute_write(void *buf, uint16_t len)
+static void handle_execute_write(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_exec_write *ev = buf;
@@ -313,7 +313,7 @@ static void handle_execute_write(void *buf, uint16_t len)
cbs->client->execute_write_cb(ev->conn_id, ev->status);
}
-static void handle_read_remote_rssi(void *buf, uint16_t len)
+static void handle_read_remote_rssi(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_read_remote_rssi *ev = buf;
@@ -323,7 +323,7 @@ static void handle_read_remote_rssi(void *buf, uint16_t len)
ev->rssi, ev->status);
}
-static void handle_listen(void *buf, uint16_t len)
+static void handle_listen(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_client_listen *ev = buf;
@@ -333,7 +333,7 @@ static void handle_listen(void *buf, uint16_t len)
/* Server Event Handlers */
-static void handle_register_server(void *buf, uint16_t len)
+static void handle_register_server(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_register *ev = buf;
@@ -342,7 +342,7 @@ static void handle_register_server(void *buf, uint16_t len)
(bt_uuid_t *) &ev->uuid);
}
-static void handle_connection(void *buf, uint16_t len)
+static void handle_connection(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_connection *ev = buf;
@@ -352,7 +352,7 @@ static void handle_connection(void *buf, uint16_t len)
(bt_bdaddr_t *) &ev->bdaddr);
}
-static void handle_service_added(void *buf, uint16_t len)
+static void handle_service_added(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_service_added *ev = buf;
btgatt_srvc_id_t srvc_id;
@@ -364,7 +364,7 @@ static void handle_service_added(void *buf, uint16_t len)
&srvc_id, ev->srvc_handle);
}
-static void handle_included_service_added(void *buf, uint16_t len)
+static void handle_included_service_added(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_inc_srvc_added *ev = buf;
@@ -375,7 +375,7 @@ static void handle_included_service_added(void *buf, uint16_t len)
ev->incl_srvc_handle);
}
-static void handle_characteristic_added(void *buf, uint16_t len)
+static void handle_characteristic_added(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_characteristic_added *ev = buf;
@@ -386,7 +386,7 @@ static void handle_characteristic_added(void *buf, uint16_t len)
ev->char_handle);
}
-static void handle_descriptor_added(void *buf, uint16_t len)
+static void handle_descriptor_added(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_descriptor_added *ev = buf;
@@ -397,7 +397,7 @@ static void handle_descriptor_added(void *buf, uint16_t len)
ev->descr_handle);
}
-static void handle_service_started(void *buf, uint16_t len)
+static void handle_service_started(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_service_started *ev = buf;
@@ -406,7 +406,7 @@ static void handle_service_started(void *buf, uint16_t len)
ev->srvc_handle);
}
-static void handle_service_stopped(void *buf, uint16_t len)
+static void handle_service_stopped(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_service_stopped *ev = buf;
@@ -415,7 +415,7 @@ static void handle_service_stopped(void *buf, uint16_t len)
ev->srvc_handle);
}
-static void handle_service_deleted(void *buf, uint16_t len)
+static void handle_service_deleted(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_service_deleted *ev = buf;
@@ -424,7 +424,7 @@ static void handle_service_deleted(void *buf, uint16_t len)
ev->srvc_handle);
}
-static void handle_request_read(void *buf, uint16_t len)
+static void handle_request_read(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_request_read *ev = buf;
@@ -435,7 +435,7 @@ static void handle_request_read(void *buf, uint16_t len)
ev->is_long);
}
-static void handle_request_write(void *buf, uint16_t len)
+static void handle_request_write(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_request_write *ev = buf;
@@ -452,7 +452,7 @@ static void handle_request_write(void *buf, uint16_t len)
ev->is_prep, ev->value);
}
-static void handle_request_exec_write(void *buf, uint16_t len)
+static void handle_request_exec_write(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_request_exec_write *ev = buf;
@@ -462,7 +462,7 @@ static void handle_request_exec_write(void *buf, uint16_t len)
ev->exec_write);
}
-static void handle_response_confirmation(void *buf, uint16_t len)
+static void handle_response_confirmation(void *buf, uint16_t len, int fd)
{
struct hal_ev_gatt_server_rsp_confirmation *ev = buf;
diff --git a/android/hal-handsfree.c b/android/hal-handsfree.c
index d992506..1d9a1a2 100644
--- a/android/hal-handsfree.c
+++ b/android/hal-handsfree.c
@@ -37,7 +37,7 @@ static bool interface_ready(void)
return cbs != NULL;
}
-static void handle_conn_state(void *buf, uint16_t len)
+static void handle_conn_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_conn_state *ev = buf;
@@ -46,7 +46,7 @@ static void handle_conn_state(void *buf, uint16_t len)
(bt_bdaddr_t *) (ev->bdaddr));
}
-static void handle_audio_state(void *buf, uint16_t len)
+static void handle_audio_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_audio_state *ev = buf;
@@ -54,7 +54,7 @@ static void handle_audio_state(void *buf, uint16_t len)
cbs->audio_state_cb(ev->state, (bt_bdaddr_t *) (ev->bdaddr));
}
-static void handle_vr_state(void *buf, uint16_t len)
+static void handle_vr_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_vr_state *ev = buf;
@@ -62,19 +62,19 @@ static void handle_vr_state(void *buf, uint16_t len)
cbs->vr_cmd_cb(ev->state);
}
-static void handle_answer(void *buf, uint16_t len)
+static void handle_answer(void *buf, uint16_t len, int fd)
{
if (cbs->answer_call_cmd_cb)
cbs->answer_call_cmd_cb();
}
-static void handle_hangup(void *buf, uint16_t len)
+static void handle_hangup(void *buf, uint16_t len, int fd)
{
if (cbs->hangup_call_cmd_cb)
cbs->hangup_call_cmd_cb();
}
-static void handle_volume(void *buf, uint16_t len)
+static void handle_volume(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_volume *ev = buf;
@@ -82,7 +82,7 @@ static void handle_volume(void *buf, uint16_t len)
cbs->volume_cmd_cb(ev->type, ev->volume);
}
-static void handle_dial(void *buf, uint16_t len)
+static void handle_dial(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_dial *ev = buf;
uint16_t num_len = ev->number_len;
@@ -102,7 +102,7 @@ static void handle_dial(void *buf, uint16_t len)
cbs->dial_call_cmd_cb(NULL);
}
-static void handle_dtmf(void *buf, uint16_t len)
+static void handle_dtmf(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_dtmf *ev = buf;
@@ -110,7 +110,7 @@ static void handle_dtmf(void *buf, uint16_t len)
cbs->dtmf_cmd_cb(ev->tone);
}
-static void handle_nrec(void *buf, uint16_t len)
+static void handle_nrec(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_nrec *ev = buf;
@@ -118,7 +118,7 @@ static void handle_nrec(void *buf, uint16_t len)
cbs->nrec_cmd_cb(ev->nrec);
}
-static void handle_chld(void *buf, uint16_t len)
+static void handle_chld(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_chld *ev = buf;
@@ -126,31 +126,31 @@ static void handle_chld(void *buf, uint16_t len)
cbs->chld_cmd_cb(ev->chld);
}
-static void handle_cnum(void *buf, uint16_t len)
+static void handle_cnum(void *buf, uint16_t len, int fd)
{
if (cbs->cnum_cmd_cb)
cbs->cnum_cmd_cb();
}
-static void handle_cind(void *buf, uint16_t len)
+static void handle_cind(void *buf, uint16_t len, int fd)
{
if (cbs->cind_cmd_cb)
cbs->cind_cmd_cb();
}
-static void handle_cops(void *buf, uint16_t len)
+static void handle_cops(void *buf, uint16_t len, int fd)
{
if (cbs->cops_cmd_cb)
cbs->cops_cmd_cb();
}
-static void handle_clcc(void *buf, uint16_t len)
+static void handle_clcc(void *buf, uint16_t len, int fd)
{
if (cbs->clcc_cmd_cb)
cbs->clcc_cmd_cb();
}
-static void handle_unknown_at(void *buf, uint16_t len)
+static void handle_unknown_at(void *buf, uint16_t len, int fd)
{
struct hal_ev_handsfree_unknown_at *ev = buf;
@@ -164,7 +164,7 @@ static void handle_unknown_at(void *buf, uint16_t len)
cbs->unknown_at_cmd_cb((char *) ev->buf);
}
-static void handle_hsp_key_press(void *buf, uint16_t len)
+static void handle_hsp_key_press(void *buf, uint16_t len, int fd)
{
if (cbs->key_pressed_cmd_cb)
cbs->key_pressed_cmd_cb();
diff --git a/android/hal-health.c b/android/hal-health.c
index e7326d7..0ef6afc 100644
--- a/android/hal-health.c
+++ b/android/hal-health.c
@@ -33,7 +33,7 @@ static bool interface_ready(void)
return cbacks != NULL;
}
-static void handle_app_registration_state(void *buf, uint16_t len)
+static void handle_app_registration_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_health_app_reg_state *ev = buf;
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index ce93af8..949e2a0 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -33,7 +33,7 @@ static bool interface_ready(void)
return cbacks != NULL;
}
-static void handle_conn_state(void *buf, uint16_t len)
+static void handle_conn_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_conn_state *ev = buf;
@@ -42,7 +42,7 @@ static void handle_conn_state(void *buf, uint16_t len)
ev->state);
}
-static void handle_info(void *buf, uint16_t len)
+static void handle_info(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_info *ev = buf;
bthh_hid_info_t info;
@@ -61,7 +61,7 @@ static void handle_info(void *buf, uint16_t len)
cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
}
-static void handle_proto_mode(void *buf, uint16_t len)
+static void handle_proto_mode(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_proto_mode *ev = buf;
@@ -70,7 +70,7 @@ static void handle_proto_mode(void *buf, uint16_t len)
ev->status, ev->mode);
}
-static void handle_idle_time(void *buf, uint16_t len)
+static void handle_idle_time(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_idle_time *ev = buf;
@@ -79,7 +79,7 @@ static void handle_idle_time(void *buf, uint16_t len)
ev->idle_rate);
}
-static void handle_get_report(void *buf, uint16_t len)
+static void handle_get_report(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_get_report *ev = buf;
@@ -93,7 +93,7 @@ static void handle_get_report(void *buf, uint16_t len)
ev->data, ev->len);
}
-static void handle_virtual_unplug(void *buf, uint16_t len)
+static void handle_virtual_unplug(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_virtual_unplug *ev = buf;
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 7dd6870..494ba85 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -63,7 +63,7 @@ void hal_ipc_unregister(uint8_t service)
services[service].size = 0;
}
-static bool handle_msg(void *buf, ssize_t len)
+static bool handle_msg(void *buf, ssize_t len, int fd)
{
struct ipc_hdr *msg = buf;
const struct hal_ipc_handler *handler;
@@ -122,7 +122,7 @@ static bool handle_msg(void *buf, ssize_t len)
return false;
}
- handler->handler(msg->payload, msg->len);
+ handler->handler(msg->payload, msg->len, fd);
return true;
}
@@ -185,7 +185,7 @@ static void *notification_handler(void *data)
}
}
- if (!handle_msg(buf, ret))
+ if (!handle_msg(buf, ret, fd))
goto failed;
}
diff --git a/android/hal-ipc.h b/android/hal-ipc.h
index b61d557..08ed7cc 100644
--- a/android/hal-ipc.h
+++ b/android/hal-ipc.h
@@ -16,7 +16,7 @@
*/
struct hal_ipc_handler {
- void (*handler) (void *buf, uint16_t len);
+ void (*handler) (void *buf, uint16_t len, int fd);
bool var_len;
size_t data_len;
};
diff --git a/android/hal-pan.c b/android/hal-pan.c
index e2bc02e..d3f93ff 100644
--- a/android/hal-pan.c
+++ b/android/hal-pan.c
@@ -31,7 +31,7 @@ static bool interface_ready(void)
return cbs != NULL;
}
-static void handle_conn_state(void *buf, uint16_t len)
+static void handle_conn_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_pan_conn_state *ev = buf;
@@ -41,7 +41,7 @@ static void handle_conn_state(void *buf, uint16_t len)
ev->local_role, ev->remote_role);
}
-static void handle_ctrl_state(void *buf, uint16_t len)
+static void handle_ctrl_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_pan_ctrl_state *ev = buf;
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/10] android/ipc: Add support for sending FD in notifications
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (8 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 09/10] android/hal-ipc: Pass FD to notification handlers Szymon Janc
@ 2014-06-11 14:32 ` Szymon Janc
2014-06-12 11:07 ` [PATCH 00/10] Some HAL IPC work Szymon Janc
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-11 14:32 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/ipc.c | 8 +++++++-
android/ipc.h | 3 +++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/android/ipc.c b/android/ipc.c
index fc58a1c..2e67428 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -404,11 +404,17 @@ void ipc_send_rsp_full(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
void ipc_send_notif(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
uint16_t len, void *param)
{
+ return ipc_send_notif_with_fd(ipc, service_id, opcode, len, param, -1);
+}
+
+void ipc_send_notif_with_fd(struct ipc *ipc, uint8_t service_id, uint8_t opcode,
+ uint16_t len, void *param, int fd)
+{
if (!ipc || !ipc->notif_io)
return;
ipc_send(g_io_channel_unix_get_fd(ipc->notif_io), service_id, opcode,
- len, param, -1);
+ len, param, fd);
}
void ipc_register(struct ipc *ipc, uint8_t service,
diff --git a/android/ipc.h b/android/ipc.h
index e97f0e6..fd2b985 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -42,6 +42,9 @@ 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_notif_with_fd(struct ipc *ipc, 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.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 00/10] Some HAL IPC work
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
` (9 preceding siblings ...)
2014-06-11 14:32 ` [PATCH 10/10] android/ipc: Add support for sending FD in notifications Szymon Janc
@ 2014-06-12 11:07 ` Szymon Janc
10 siblings, 0 replies; 12+ messages in thread
From: Szymon Janc @ 2014-06-12 11:07 UTC (permalink / raw)
To: linux-bluetooth
On Wednesday 11 of June 2014 16:32:42 Szymon Janc wrote:
> Hi,
>
> Those patches are cleanups and fixes for HAL part of IPC. Those are
> first step to making HAL IPC library like so that it can be reused
> by audio and sco HALs.
>
> Eventually this should also allow for better recovery in case of IPC
> error i.e. not calling exit() directly but custom destroy callback.
> But this is not implemented yet.
>
> Last two patches add FD passing in notification (as of now this is
> needed only for health HAL).
>
> BR
> Szymon Janc
>
> Szymon Janc (10):
> android/ipc: Make struct service_handler private
> android/hal-ipc: Allow to pass custom path to IPC
> android/hal-ipc: Fix missing mutex unlock
> android/hal-ipc: Move exit calls outside of handle_msg
> android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd
> android/hal-ipc: Move exit calls under label in notification_handler
> android/hal-ipc: Split IPC init and accept to separate functions
> android/hal-ipc: Move daemon starting to bluetooth HAL
> android/hal-ipc: Pass FD to notification handlers
> android/ipc: Add support for sending FD in notifications
>
> android/hal-a2dp.c | 4 +-
> android/hal-avrcp.c | 24 +++----
> android/hal-bluetooth.c | 40 +++++++----
> android/hal-gatt.c | 62 ++++++++--------
> android/hal-handsfree.c | 32 ++++-----
> android/hal-health.c | 2 +-
> android/hal-hidhost.c | 12 ++--
> android/hal-ipc.c | 186 ++++++++++++++++++++++++++----------------------
> android/hal-ipc.h | 5 +-
> android/hal-pan.c | 4 +-
> android/ipc.c | 13 +++-
> android/ipc.h | 8 +--
> 12 files changed, 214 insertions(+), 178 deletions(-)
>
>
Pushed.
--
Best regards,
Szymon Janc
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-06-12 11:07 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-11 14:32 [PATCH 00/10] Some HAL IPC work Szymon Janc
2014-06-11 14:32 ` [PATCH 01/10] android/ipc: Make struct service_handler private Szymon Janc
2014-06-11 14:32 ` [PATCH 02/10] android/hal-ipc: Allow to pass custom path to IPC Szymon Janc
2014-06-11 14:32 ` [PATCH 03/10] android/hal-ipc: Fix missing mutex unlock Szymon Janc
2014-06-11 14:32 ` [PATCH 04/10] android/hal-ipc: Move exit calls outside of handle_msg Szymon Janc
2014-06-11 14:32 ` [PATCH 05/10] android/hal-ipc: Move exit calls under failed label in hal_ipc_cmd Szymon Janc
2014-06-11 14:32 ` [PATCH 06/10] android/hal-ipc: Move exit calls under label in notification_handler Szymon Janc
2014-06-11 14:32 ` [PATCH 07/10] android/hal-ipc: Split IPC init and accept to separate functions Szymon Janc
2014-06-11 14:32 ` [PATCH 08/10] android/hal-ipc: Move daemon starting to bluetooth HAL Szymon Janc
2014-06-11 14:32 ` [PATCH 09/10] android/hal-ipc: Pass FD to notification handlers Szymon Janc
2014-06-11 14:32 ` [PATCH 10/10] android/ipc: Add support for sending FD in notifications Szymon Janc
2014-06-12 11:07 ` [PATCH 00/10] Some HAL IPC work Szymon Janc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox