Skip to contentSkip to conversation

android/ipc: Add initial code for audio IPC

PATCH Superseded Luiz Augusto von Dentz 3 participants 14 messages Jan 2, 2014 – Jan 6, 2014 Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/10 android/ipc: Add initial code for audio IPC

From: Luiz Augusto von Dentz <[email protected]>

This add initial code for listen and accept connections on the abstract socket defined for the audio IPC.
---
v2: Split audio IPC services for HAL services and fix invalid messages or disconnections causing the daemon to exit. The audio HAL is independent of bluetooth and should only affect A2DP service.

 android/hal-msg.h |  1 +
 android/ipc.c     | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 android/ipc.h     |  3 +++
 3 files changed, 76 insertions(+), 6 deletions(-)
android/hal-msg.h +1 -0
index c351501..b14eced 100644
@@ -24,6 +24,7 @@
 #define BLUEZ_HAL_MTU 1024
 
 static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
+static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
 
 struct hal_hdr {
 	uint8_t  service_id;
android/ipc.c +72 -6

113 lines not on this page · raw message

android/ipc.h +3 -0
index 6cd102b..8e92811 100644
@@ -37,3 +37,6 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode,  uint16_t len,
 void ipc_register(uint8_t service, const struct ipc_handler *handlers,
 								uint8_t size);
 void ipc_unregister(uint8_t service);
+
+void audio_ipc_init(void);
+void audio_ipc_cleanup(void);
Signature · 1 line
1.8.4.2
author maintainer
#1 lore raw

PATCH v2 2/10 android/ipc: Add message handling for audio IPC

From: Luiz Augusto von Dentz <[email protected]>

This adds audio_ipc_register and audio_ipc_unregister and adapt ipc_handle_msg to be able to handle audio services messages.

---
 android/hal-msg.h |  4 +++
 android/ipc.c     | 78 +++++++++++++++++++++++++++++++++++--------------------
 android/ipc.h     |  4 +++
 3 files changed, 58 insertions(+), 28 deletions(-)
android/hal-msg.h +4 -0
index b14eced..267f9b2 100644
@@ -48,6 +48,10 @@ struct hal_hdr {
 
 #define HAL_SERVICE_ID_MAX HAL_SERVICE_ID_GATT
 
+#define AUDIO_SERVICE_ID_CORE		0
+
+#define AUDIO_SERVICE_ID_MAX AUDIO_SERVICE_ID_CORE
+
 /* Core Service */
 
 #define HAL_STATUS_SUCCESS		0x00
android/ipc.c +50 -28

144 lines not on this page · raw message

android/ipc.h +4 -0
index 8e92811..44d5a5d 100644
@@ -40,3 +40,7 @@ void ipc_unregister(uint8_t service);
 
 void audio_ipc_init(void);
 void audio_ipc_cleanup(void);
+
+void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
+								uint8_t size);
+void audio_ipc_unregister(uint8_t service);
Signature · 1 line
1.8.4.2
author maintainer
#2 lore raw

PATCH v2 3/10 android/ipc: Add audio_ipc_send_rsp and audio_ipc_send_rsp_full

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

These functions can be used to respond to commands recieved over audio IPC.

---
 android/ipc.c | 24 ++++++++++++++++++++++++
 android/ipc.h |  4 ++++
 2 files changed, 28 insertions(+)
android/ipc.c +24 -0
index f18e1eb..a116a20 100644
@@ -414,6 +414,30 @@ void audio_ipc_cleanup(void)
 	}
 }
 
+void audio_ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)
+{
+	struct hal_status s;
+	int sk;
+
+	sk = g_io_channel_unix_get_fd(audio_io);
+
+	if (status == HAL_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);
+}
+
+void audio_ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
+							void *param, int fd)
+{
+	ipc_send(g_io_channel_unix_get_fd(audio_io), service_id, opcode, len,
+								param, fd);
+}
+
 void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
 								uint8_t size)
 {
android/ipc.h +4 -0
index 44d5a5d..f224367 100644
@@ -41,6 +41,10 @@ void ipc_unregister(uint8_t service);
 void audio_ipc_init(void);
 void audio_ipc_cleanup(void);
 
+void audio_ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status);
+void audio_ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
+							void *param, int fd);
+
 void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
 								uint8_t size);
 void audio_ipc_unregister(uint8_t service);
Signature · 1 line
1.8.4.2
author maintainer
#3 lore raw

PATCH v2 4/10 android/A2DP: Add initial code to handle audio IPC commands

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds initial code to handle audio IPC commands.

---
 android/a2dp.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
android/a2dp.c +12 -1
index 581d094..7550644 100644
@@ -352,6 +352,9 @@ static sdp_record_t *a2dp_record(void)
 	return record;
 }
 
+static const struct ipc_handler audio_handlers[] = {
+};
+
 bool bt_a2dp_register(const bdaddr_t *addr)
 {
 	GError *err = NULL;
@@ -359,6 +362,8 @@ bool bt_a2dp_register(const bdaddr_t *addr)
 
 	DBG("");
 
+	audio_ipc_init();
+
 	bacpy(&adapter_addr, addr);
 
 	server = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
@@ -388,6 +393,9 @@ bool bt_a2dp_register(const bdaddr_t *addr)
 	ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
 						G_N_ELEMENTS(cmd_handlers));
 
+	audio_ipc_register(AUDIO_SERVICE_ID_CORE, audio_handlers,
+						G_N_ELEMENTS(audio_handlers));
+
 	return true;
 
 fail:
@@ -411,8 +419,9 @@ void bt_a2dp_unregister(void)
 	g_slist_foreach(devices, a2dp_device_disconnected, NULL);
 	devices = NULL;
 
-
 	ipc_unregister(HAL_SERVICE_ID_A2DP);
+	audio_ipc_unregister(AUDIO_SERVICE_ID_CORE);
+
 	bt_adapter_remove_record(record_id);
 	record_id = 0;
 
@@ -421,4 +430,6 @@ void bt_a2dp_unregister(void)
 		g_io_channel_unref(server);
 		server = NULL;
 	}
+
+	audio_ipc_cleanup();
 }
Signature · 1 line
1.8.4.2
author maintainer
#4 lore raw

PATCH v2 5/10 android/A2DP: Add audio open command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to audio open command and response.

---
 android/a2dp.c            | 10 ++++++++++
 android/audio-ipc-api.txt |  2 +-
 android/hal-msg.h         | 18 ++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
android/a2dp.c +10 -0
index 7550644..325c282 100644
@@ -352,7 +352,17 @@ static sdp_record_t *a2dp_record(void)
 	return record;
 }
 
+static void bt_audio_open(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_OPEN,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
+	/* AUDIO_OP_OPEN */
+	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/audio-ipc-api.txt +1 -1
index 1c42800..37a1569 100644
@@ -49,9 +49,9 @@ Identifier: "audio" (BT_AUDIO_ID)
 
 		Command parameters: Service UUID (16 octets)
 				    Codec ID (1 octet)
+				    Number of codec presets (1 octet)
 				    Codec capabilities length (1 octet)
 				    Codec capabilities (variable)
-				    Number of codec presets (1 octet)
 				    Codec preset # length (1 octet)
 				    Codec preset # configuration (variable)
 				    ...
android/hal-msg.h +18 -0
index 267f9b2..1036988 100644
@@ -570,3 +570,21 @@ struct hal_ev_a2dp_audio_state {
 	uint8_t state;
 	uint8_t bdaddr[6];
 } __attribute__((packed));
+
+#define AUDIO_OP_OPEN				0x01
+struct audio_preset {
+	uint8_t len;
+	uint8_t data[0];
+} __attribute__((packed));
+
+struct audio_cmd_open {
+	uint16_t uuid;
+	uint8_t codec;
+	uint8_t presets;
+	uint8_t len;
+	struct audio_preset preset[0];
+} __attribute__((packed));
+
+struct audio_rsp_open {
+	uint8_t id;
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
author maintainer
#5 lore raw

PATCH v2 6/10 android/A2DP: Add audio close command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to audio close command and response.

---
 android/a2dp.c    | 10 ++++++++++
 android/hal-msg.h |  5 +++++
 2 files changed, 15 insertions(+)
android/a2dp.c +10 -0
index 325c282..e3d58ca 100644
@@ -360,9 +360,19 @@ static void bt_audio_open(const void *buf, uint16_t len)
 							HAL_STATUS_FAILED);
 }
 
+static void bt_audio_close(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_CLOSE,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
+	/* AUDIO_OP_CLOSE */
+	{ bt_audio_close, false, sizeof(struct audio_cmd_close) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/hal-msg.h +5 -0
index 1036988..d1135df 100644
@@ -588,3 +588,8 @@ struct audio_cmd_open {
 struct audio_rsp_open {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_CLOSE				0x02
+struct audio_cmd_close {
+	uint8_t id;
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
author maintainer
#6 lore raw

PATCH v2 7/10 android/A2DP: Add stream open command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to stream open command and response.

---
 android/a2dp.c    | 10 ++++++++++
 android/hal-msg.h | 10 ++++++++++
 2 files changed, 20 insertions(+)
android/a2dp.c +10 -0
index e3d58ca..7709b15 100644
@@ -368,11 +368,21 @@ static void bt_audio_close(const void *buf, uint16_t len)
 							HAL_STATUS_FAILED);
 }
 
+static void bt_stream_open(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_OPEN_STREAM,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
 	/* AUDIO_OP_CLOSE */
 	{ bt_audio_close, false, sizeof(struct audio_cmd_close) },
+	/* AUDIO_OP_OPEN_STREAM */
+	{ bt_stream_open, false, sizeof(struct audio_cmd_open_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/hal-msg.h +10 -0
index d1135df..ff62de0 100644
@@ -593,3 +593,13 @@ struct audio_rsp_open {
 struct audio_cmd_close {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_OPEN_STREAM			0x03
+struct audio_cmd_open_stream {
+	uint8_t id;
+} __attribute__((packed));
+
+struct audio_rsp_open_stream {
+	uint8_t len;
+	uint8_t data[0];
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
author maintainer
#7 lore raw

PATCH v2 8/10 android/A2DP: Add stream close command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to stream close command and response.

---
 android/a2dp.c    | 10 ++++++++++
 android/hal-msg.h |  5 +++++
 2 files changed, 15 insertions(+)
android/a2dp.c +10 -0
index 7709b15..eac427d 100644
@@ -376,6 +376,14 @@ static void bt_stream_open(const void *buf, uint16_t len)
 							HAL_STATUS_FAILED);
 }
 
+static void bt_stream_close(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_CLOSE_STREAM,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
@@ -383,6 +391,8 @@ static const struct ipc_handler audio_handlers[] = {
 	{ bt_audio_close, false, sizeof(struct audio_cmd_close) },
 	/* AUDIO_OP_OPEN_STREAM */
 	{ bt_stream_open, false, sizeof(struct audio_cmd_open_stream) },
+	/* AUDIO_OP_CLOSE_STREAM */
+	{ bt_stream_close, false, sizeof(struct audio_cmd_close_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/hal-msg.h +5 -0
index ff62de0..a708157 100644
@@ -603,3 +603,8 @@ struct audio_rsp_open_stream {
 	uint8_t len;
 	uint8_t data[0];
 } __attribute__((packed));
+
+#define AUDIO_OP_CLOSE_STREAM			0x04
+struct audio_cmd_close_stream {
+	uint8_t id;
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
author maintainer
#8 lore raw

PATCH v2 9/10 android/A2DP: Add stream resume command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to stream resume command and response.

---
 android/a2dp.c    | 10 ++++++++++
 android/hal-msg.h |  5 +++++
 2 files changed, 15 insertions(+)
android/a2dp.c +10 -0
index eac427d..d3c02d6 100644
@@ -384,6 +384,14 @@ static void bt_stream_close(const void *buf, uint16_t len)
 							HAL_STATUS_FAILED);
 }
 
+static void bt_stream_resume(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_RESUME_STREAM,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
@@ -393,6 +401,8 @@ static const struct ipc_handler audio_handlers[] = {
 	{ bt_stream_open, false, sizeof(struct audio_cmd_open_stream) },
 	/* AUDIO_OP_CLOSE_STREAM */
 	{ bt_stream_close, false, sizeof(struct audio_cmd_close_stream) },
+	/* AUDIO_OP_RESUME_STREAM */
+	{ bt_stream_resume, false, sizeof(struct audio_cmd_resume_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/hal-msg.h +5 -0
index a708157..259b687 100644
@@ -608,3 +608,8 @@ struct audio_rsp_open_stream {
 struct audio_cmd_close_stream {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_RESUME_STREAM			0x05
+struct audio_cmd_resume_stream {
+	uint8_t id;
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
author maintainer
#9 lore raw

PATCH v2 10/10 android/A2DP: Add stream suspend command/response struct

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds the definitions to stream suspend command and response.

---
 android/a2dp.c    | 10 ++++++++++
 android/hal-msg.h |  5 +++++
 2 files changed, 15 insertions(+)
android/a2dp.c +10 -0
index d3c02d6..dc2890c 100644
@@ -392,6 +392,14 @@ static void bt_stream_resume(const void *buf, uint16_t len)
 							HAL_STATUS_FAILED);
 }
 
+static void bt_stream_suspend(const void *buf, uint16_t len)
+{
+	DBG("Not Implemented");
+
+	audio_ipc_send_rsp(AUDIO_SERVICE_ID_CORE, AUDIO_OP_SUSPEND_STREAM,
+							HAL_STATUS_FAILED);
+}
+
 static const struct ipc_handler audio_handlers[] = {
 	/* AUDIO_OP_OPEN */
 	{ bt_audio_open, true, sizeof(struct audio_cmd_open) },
@@ -403,6 +411,8 @@ static const struct ipc_handler audio_handlers[] = {
 	{ bt_stream_close, false, sizeof(struct audio_cmd_close_stream) },
 	/* AUDIO_OP_RESUME_STREAM */
 	{ bt_stream_resume, false, sizeof(struct audio_cmd_resume_stream) },
+	/* AUDIO_OP_SUSPEND_STREAM */
+	{ bt_stream_suspend, false, sizeof(struct audio_cmd_suspend_stream) },
 };
 
 bool bt_a2dp_register(const bdaddr_t *addr)
android/hal-msg.h +5 -0
index 259b687..6b2ec88 100644
@@ -613,3 +613,8 @@ struct audio_cmd_close_stream {
 struct audio_cmd_resume_stream {
 	uint8_t id;
 } __attribute__((packed));
+
+#define AUDIO_OP_SUSPEND_STREAM			0x06
+struct audio_cmd_suspend_stream {
+	uint8_t id;
+} __attribute__((packed));
Signature · 1 line
1.8.4.2
#10 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 39 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This add initial code for listen and accept connections on the abstract socket defined for the audio IPC.
---
v2: Split audio IPC services for HAL services and fix invalid messages or disconnections causing the daemon to exit. The audio HAL is independent of bluetooth and should only affect A2DP service.

 android/hal-msg.h |  1 +
 android/ipc.c     | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 android/ipc.h     |  3 +++
 3 files changed, 76 insertions(+), 6 deletions(-)
android/hal-msg.h +1 -0
index c351501..b14eced 100644
@@ -24,6 +24,7 @@
 #define BLUEZ_HAL_MTU 1024
 
 static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
+static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
 
 struct hal_hdr {
 	uint8_t  service_id;
android/ipc.c +1 -0
index 9e8ccc3..4c5a77e 100644
@@ -49,6 +49,7 @@ static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
 
 static GIOChannel *cmd_io = NULL;
 static GIOChannel *notif_io = NULL;
+static GIOChannel *audio_io = NULL;
 
 static void ipc_handle_msg(const void *buf, ssize_t len)
 {

android/ipc.c static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond, · line 151

Quoted 7 lines
android/ipc.c +2 -1
@@ -145,7 +146,8 @@ static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond,
 	return FALSE;
 }
 
-static GIOChannel *connect_hal(GIOFunc connect_cb)
+static GIOChannel *ipc_connect(const char *path, size_t size,
+							GIOFunc connect_cb)
 {

Does it make sense for better understanding to split patch to two parts:
one is changing connect_hal to ipc_connect and another adding audio ipc?

Best regards
Andrei Emeltchenko

Quoted 121 lines
android/ipc.c +69 -5
 	struct sockaddr_un addr;
 	GIOCondition cond;
@@ -167,11 +169,11 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
 	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 (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		error("IPC: failed to connect HAL socket: %d (%s)", errno,
-							strerror(errno));
+		error("IPC: failed to connect HAL socket %s: %d (%s)", &path[1],
+							errno, strerror(errno));
 		g_io_channel_unref(io);
 		return NULL;
 	}
@@ -218,7 +220,8 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
 		return FALSE;
 	}
 
-	notif_io = connect_hal(notif_connect_cb);
+	notif_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+							notif_connect_cb);
 	if (!notif_io)
 		raise(SIGTERM);
 
@@ -227,7 +230,8 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
 
 void ipc_init(void)
 {
-	cmd_io = connect_hal(cmd_connect_cb);
+	cmd_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+							cmd_connect_cb);
 	if (!cmd_io)
 		raise(SIGTERM);
 }
@@ -338,3 +342,65 @@ void ipc_unregister(uint8_t service)
 	services[service].handler = NULL;
 	services[service].size = 0;
 }
+
+static gboolean audio_watch_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	char buf[BLUEZ_HAL_MTU];
+	ssize_t ret;
+	int fd;
+
+	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;
+	}
+
+	return TRUE;
+
+fail:
+	audio_ipc_cleanup();
+	return FALSE;
+}
+
+static gboolean audio_connect_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		error("Audio IPC: socket connect failed");
+		audio_ipc_cleanup();
+		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, NULL);
+
+	info("Audio IPC: successfully connected");
+
+	return FALSE;
+}
+
+void audio_ipc_init(void)
+{
+	audio_io = ipc_connect(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
+							audio_connect_cb);
+}
+
+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;
+	}
+}
android/ipc.h +3 -0
index 6cd102b..8e92811 100644
@@ -37,3 +37,6 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode,  uint16_t len,
 void ipc_register(uint8_t service, const struct ipc_handler *handlers,
 								uint8_t size);
 void ipc_unregister(uint8_t service);
+
+void audio_ipc_init(void);
+void audio_ipc_cleanup(void);
Signature · 6 lines
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#11 lore raw

Hi Andrei,

Quoted 45 lines · Andrei Emeltchenko

Hi Luiz,

Quoted 42 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This add initial code for listen and accept connections on the abstract socket defined for the audio IPC.
---
v2: Split audio IPC services for HAL services and fix invalid messages or disconnections causing the daemon to exit. The audio HAL is independent of bluetooth and should only affect A2DP service.

 android/hal-msg.h |  1 +
 android/ipc.c     | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 android/ipc.h     |  3 +++
 3 files changed, 76 insertions(+), 6 deletions(-)
android/hal-msg.h +1 -0
index c351501..b14eced 100644
@@ -24,6 +24,7 @@
 #define BLUEZ_HAL_MTU 1024
 
 static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
+static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
 
 struct hal_hdr {
      uint8_t  service_id;
android/ipc.c +1 -0
index 9e8ccc3..4c5a77e 100644
@@ -49,6 +49,7 @@ static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
 
 static GIOChannel *cmd_io = NULL;
 static GIOChannel *notif_io = NULL;
+static GIOChannel *audio_io = NULL;
 
 static void ipc_handle_msg(const void *buf, ssize_t len)
 {
@@ -145,7 +146,8 @@ static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond,
      return FALSE;
 }
 
Quoted 7 lines

android/ipc.c static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond, · line 151

Quoted 4 lines
android/ipc.c +2 -1
-static GIOChannel *connect_hal(GIOFunc connect_cb)
+static GIOChannel *ipc_connect(const char *path, size_t size,
+                                                     GIOFunc connect_cb)
 {

Does it make sense for better understanding to split patch to two parts:
one is changing connect_hal to ipc_connect and another adding audio ipc?

Well, it is quite self contained and the functionality doesn't change much as Im just passing the path of the socket to function that is static instead of copying connect_hal so I considered it too trivial to have it separated. Note that sometimes we do bother to split even trivial changes when the patches get way too big and convoluted to be able to spot this minor details, this patch though has less than 100 lines changes.

Signature · 1 line
Luiz Augusto von Dentz
#12 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 8 lines · On Thursday 02 January 2014 13:58:25 Luiz Augusto von Dentz wrote:

From: Luiz Augusto von Dentz <[email protected]>

This add initial code for listen and accept connections on the abstract socket defined for the audio IPC.
---
v2: Split audio IPC services for HAL services and fix invalid messages or disconnections causing the daemon to exit. The audio HAL is independent of bluetooth and should only affect A2DP service.

What seems to be missing is some way to recover from Audio IPC error.

Quoted 155 lines
 android/hal-msg.h |  1 +
 android/ipc.c     | 78
++++++++++++++++++++++++++++++++++++++++++++++++++----- android/ipc.h     |
 3 +++
 3 files changed, 76 insertions(+), 6 deletions(-)
android/hal-msg.h +1 -0
index c351501..b14eced 100644
@@ -24,6 +24,7 @@
 #define BLUEZ_HAL_MTU 1024
 
 static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
+static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
 
 struct hal_hdr {
 	uint8_t  service_id;
android/ipc.c +11 -6
index 9e8ccc3..4c5a77e 100644
@@ -49,6 +49,7 @@ static struct service_handler services[HAL_SERVICE_ID_MAX
+ 1];
 
 static GIOChannel *cmd_io = NULL;
 static GIOChannel *notif_io = NULL;
+static GIOChannel *audio_io = NULL;
 
 static void ipc_handle_msg(const void *buf, ssize_t len)
 {
@@ -145,7 +146,8 @@ static gboolean notif_watch_cb(GIOChannel *io,
 GIOCondition cond, return FALSE;
 }
 
-static GIOChannel *connect_hal(GIOFunc connect_cb)
+static GIOChannel *ipc_connect(const char *path, size_t size,
+							GIOFunc connect_cb)
 {
 	struct sockaddr_un addr;
 	GIOCondition cond;
@@ -167,11 +169,11 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
 	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 (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		error("IPC: failed to connect HAL socket: %d (%s)", errno,
-							strerror(errno));
+		error("IPC: failed to connect HAL socket %s: %d (%s)", &path[1],
+							errno, strerror(errno));
 		g_io_channel_unref(io);
 		return NULL;
 	}
@@ -218,7 +220,8 @@ static gboolean cmd_connect_cb(GIOChannel *io,
 GIOCondition cond, return FALSE;
 	}
 
-	notif_io = connect_hal(notif_connect_cb);
+	notif_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+							notif_connect_cb);
 	if (!notif_io)
 		raise(SIGTERM);
 
@@ -227,7 +230,8 @@ static gboolean cmd_connect_cb(GIOChannel *io,
 GIOCondition cond,
 
 void ipc_init(void)
 {
-	cmd_io = connect_hal(cmd_connect_cb);
+	cmd_io = ipc_connect(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+							cmd_connect_cb);
 	if (!cmd_io)
 		raise(SIGTERM);

}

android/ipc.c +62 -0
@@ -338,3 +342,65 @@ void ipc_unregister(uint8_t service)
 	services[service].handler = NULL;
 	services[service].size = 0;
 }
+
+static gboolean audio_watch_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	char buf[BLUEZ_HAL_MTU];
+	ssize_t ret;
+	int fd;
+
+	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;
+	}
+
+	return TRUE;
+
+fail:
+	audio_ipc_cleanup();
+	return FALSE;
+}
+
+static gboolean audio_connect_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	DBG("");
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		error("Audio IPC: socket connect failed");
+		audio_ipc_cleanup();
+		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, NULL);
+
+	info("Audio IPC: successfully connected");
+
+	return FALSE;
+}
+
+void audio_ipc_init(void)
+{
+	audio_io = ipc_connect(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
+							audio_connect_cb);
+}
+
+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;
+	}
+}
android/ipc.h +0 -0
index 6cd102b..8e92811 100644
@@ -37,3 +37,6 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode, 

uint16_t len, void ipc_register(uint8_t service, const struct ipc_handler *handlers, uint8_t size);
void ipc_unregister(uint8_t service);

android/ipc.h +3 -0
+
+void audio_ipc_init(void);
+void audio_ipc_cleanup(void);
Signature · 2 lines
Szymon K. Janc
[email protected]
author maintainer
#13 lore raw

Hi Szymon,

Quoted 5 lines · Szymon Janc

Hi Luiz,

Quoted 2 lines · On Thursday 02 January 2014 13:58:25 Luiz Augusto von Dentz wrote:

From: Luiz Augusto von Dentz <[email protected]>

Quoted 8 lines
Quoted 6 lines

This add initial code for listen and accept connections on the abstract socket defined for the audio IPC.
---
v2: Split audio IPC services for HAL services and fix invalid messages or disconnections causing the daemon to exit. The audio HAL is independent of bluetooth and should only affect A2DP service.

What seems to be missing is some way to recover from Audio IPC error.

This has been discussed already with Lukasz, Audio HAL is a little bit different than Bluetooth HAL because it does not seems to be able to restart the service from the UI so the Audio IPC disconnecting are probably due to crashes, we will indeed need a way to recover from Audio IPC errors but it is not really a feature but more a error recover which we can be done in a separate set.

Luiz Augusto von Dentz