android: Add initial code for audio IPC
Luiz Augusto von Dentz
maintainerRFC 1/9 android: 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.
--- android/hal-msg.h | 1 + android/ipc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ android/ipc.h | 3 +++ 3 files changed, 51 insertions(+), 6 deletions(-)
android/hal-msg.h +1 -0
@@ -24,6 +24,7 @@#define BLUEZ_HAL_MTU 1024static 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 +47 -6
88 lines not on this page · raw message
android/ipc.h +3 -0
@@ -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
Luiz Augusto von Dentz
maintainerRFC 2/9 android/A2DP: Add initial code to handle audio IPC commands
From: Luiz Augusto von Dentz <[email protected]>
This adds initial code to handle audio IPC commands and defines a new service id (10).
--- android/a2dp.c | 13 ++++++++++++- android/hal-msg.h | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-)
android/a2dp.c +12 -1
@@ -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)); +ipc_register (HAL_SERVICE_ID_AUDIO , 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 ); +ipc_unregister (HAL_SERVICE_ID_AUDIO ); +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 (); }
android/hal-msg.h +2 -1
@@ -45,8 +45,9 @@ struct hal_hdr {#define HAL_SERVICE_ID_HEALTH 7#define HAL_SERVICE_ID_AVRCP 8#define HAL_SERVICE_ID_GATT 9 +#define HAL_SERVICE_ID_AUDIO 10 -#define HAL_SERVICE_ID_MAX HAL_SERVICE_ID_GATT +#define HAL_SERVICE_ID_MAX HAL_SERVICE_ID_AUDIO/* Core Service */
Signature · 1 line
1.8.4.2
Luiz Augusto von Dentz
maintainerRFC 3/9 android: Add audio open command/response struct
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds the definitions to audio open command and response.
--- android/a2dp.c | 9 +++++++++ android/audio-ipc-api.txt | 2 +- android/hal-msg.h | 18 ++++++++++++++++++ android/ipc.c | 5 ++++- 4 files changed, 32 insertions(+), 2 deletions(-)
android/a2dp.c +9 -0
@@ -352,7 +352,16 @@ static sdp_record_t *a2dp_record(void)return record; } +static void bt_audio_open (const void *buf,uint16_t len) +{ +DBG ("Not Implemented" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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
@@ -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
@@ -567,3 +567,21 @@ struct hal_ev_a2dp_audio_state {uint8_t state;uint8_t bdaddr[6 ]; } __attribute__((packed)); + +#define AUDIO_OP_OPEN 0x01 +struct audio_cmd_open { +uint16_t uuid; +uint8_t codec; +uint8_t presets; +uint8_t len; +uint8_t data[0 ]; +} __attribute__((packed)); + +struct audio_preset { +uint8_t len; +uint8_t data[0 ]; +} __attribute__((packed)); + +struct audio_rsp_open { +uint8_t id; +} __attribute__((packed));
android/ipc.c +4 -1
@@ -301,7 +301,10 @@ void 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 (cmd_io); +if (service_id ==HAL_SERVICE_ID_AUDIO ) + sk =g_io_channel_unix_get_fd (audio_io); +else + sk =g_io_channel_unix_get_fd (cmd_io);if (status ==HAL_STATUS_SUCCESS ) {ipc_send (sk, service_id, opcode,0 ,NULL ,-1 );
Signature · 1 line
1.8.4.2
Re: [RFC BlueZ 3/9] android: Add audio open command/response struct
Hi Luiz,
Quoted 52 lines · On Monday 30 December 2013 14:34:09 Luiz Augusto von Dentz wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds the definitions to audio open command and response.
--- android/a2dp.c | 9 +++++++++ android/audio-ipc-api.txt | 2 +- android/hal-msg.h | 18 ++++++++++++++++++ android/ipc.c | 5 ++++- 4 files changed, 32 insertions(+), 2 deletions(-)android/a2dp.c +9
-0@@ -352,7 +352,16 @@ static sdp_record_t *a2dp_record(void)return record; } +static void bt_audio_open (const void *buf,uint16_t len) +{ +DBG ("Not Implemented" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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@@ -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 +0
-0@@ -567,3 +567,21 @@ struct hal_ev_a2dp_audio_state {uint8_t state;
android/hal-msg.h struct hal_ev_a2dp_audio_state { · line 577
Quoted 10 lines
android/hal-msg.h +8
-0uint8_t bdaddr[6 ]; } __attribute__((packed)); + +#define AUDIO_OP_OPEN 0x01 +struct audio_cmd_open { +uint16_t uuid; +uint8_t codec; +uint8_t presets; +uint8_t len; +uint8_t data[0 ];
Maybe this could be
struct audio_preset[0];
? (if that would make code cleaner)
Quoted 26 lines
android/hal-msg.h +10
-0+} __attribute__((packed)); + +struct audio_preset { +uint8_t len; +uint8_t data[0 ]; +} __attribute__((packed)); + +struct audio_rsp_open { +uint8_t id; +} __attribute__((packed));android/ipc.c +4
-1@@ -301,7 +301,10 @@ void 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 (cmd_io); +if (service_id ==HAL_SERVICE_ID_AUDIO ) + sk =g_io_channel_unix_get_fd (audio_io); +else + sk =g_io_channel_unix_get_fd (cmd_io);if (status ==HAL_STATUS_SUCCESS ) {ipc_send (sk, service_id, opcode,0 ,NULL ,-1 );
Signature · 2 lines
Szymon K. Janc [email protected]
Luiz Augusto von Dentz
maintainerRe: [RFC BlueZ 3/9] android: Add audio open command/response struct
Hi Szymon,
Quoted 61 lines · Szymon Janc
Hi Luiz,
Quoted 58 lines · On Monday 30 December 2013 14:34:09 Luiz Augusto von Dentz wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds the definitions to audio open command and response.
--- android/a2dp.c | 9 +++++++++ android/audio-ipc-api.txt | 2 +- android/hal-msg.h | 18 ++++++++++++++++++ android/ipc.c | 5 ++++- 4 files changed, 32 insertions(+), 2 deletions(-)android/a2dp.c +9
-0@@ -352,7 +352,16 @@ static sdp_record_t *a2dp_record(void)return record; } +static void bt_audio_open (const void *buf,uint16_t len) +{ +DBG ("Not Implemented" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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@@ -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 +4
-0@@ -567,3 +567,21 @@ struct hal_ev_a2dp_audio_state {uint8_t state;uint8_t bdaddr[6 ]; } __attribute__((packed)); + +#define AUDIO_OP_OPEN 0x01 +struct audio_cmd_open { +uint16_t uuid;
Quoted 8 lines
android/hal-msg.h struct hal_ev_a2dp_audio_state { · line 577
Quoted 4 lines
android/hal-msg.h +4
-0+uint8_t codec; +uint8_t presets; +uint8_t len; +uint8_t data[0 ];Maybe this could be
struct audio_preset[0];
? (if that would make code cleaner)
Indeed, will fix it.
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerRFC 4/9 android: Add audio close command/response struct
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds the definitions to audio close command and response.
--- android/a2dp.c | 9 +++++++++ android/hal-msg.h | 5 +++++ 2 files changed, 14 insertions(+)
android/a2dp.c +9 -0
@@ -359,9 +359,18 @@ static void bt_audio_open(const void *buf, uint16_t len)ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,AUDIO_OP_OPEN ,HAL_STATUS_FAILED ); } +static void bt_audio_close (const void *buf,uint16_t len) +{ +DBG ("Not Implemented" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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
@@ -585,3 +585,8 @@ struct audio_preset {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
Luiz Augusto von Dentz
maintainerRFC 5/9 android: Add stream open command/response struct
In reply to Luiz Augusto von DentzFrom: 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
@@ -366,11 +366,21 @@ static void bt_audio_close(const void *buf, uint16_t len)ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,AUDIO_OP_CLOSE ,HAL_STATUS_FAILED ); } +static void bt_stream_open (const void *buf,uint16_t len) +{ +DBG ("Not Implemented" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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
@@ -590,3 +590,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
Luiz Augusto von Dentz
maintainerRFC 6/9 android: Add stream close command/response struct
In reply to Luiz Augusto von DentzFrom: 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
@@ -374,6 +374,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" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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 ) },
@@ -381,6 +389,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
@@ -600,3 +600,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
Luiz Augusto von Dentz
maintainerRFC 7/9 android: Add stream resume command/response struct
In reply to Luiz Augusto von DentzFrom: 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
@@ -382,6 +382,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" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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 ) },
@@ -391,6 +399,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
@@ -605,3 +605,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
Luiz Augusto von Dentz
maintainerRFC 8/9 android: Add stream suspend command/response struct
In reply to Luiz Augusto von DentzFrom: 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
@@ -390,6 +390,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" ); + +ipc_send_rsp (HAL_SERVICE_ID_AUDIO ,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 ) },
@@ -401,6 +409,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
@@ -610,3 +610,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
Luiz Augusto von Dentz
maintainerRFC 9/9 android: Add hal_audio_ipc_init and hal_audio_ipc_cleanup
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
These function initialize the audio IPC in the HAL side.
--- android/hal-audio.c | 9 +++++++++ android/hal-ipc.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ android/hal-ipc.h | 3 +++ 3 files changed, 68 insertions(+)
android/hal-audio.c +9 -0
@@ -24,6 +24,7 @@#include <hardware/hardware.h> #include "hal-log.h" +#include "hal-ipc.h" static ssize_t out_write (struct audio_stream_out *stream,const void *buffer,size_t bytes)
@@ -374,6 +375,9 @@ static int audio_dump(const audio_hw_device_t *device, int fd)static int audio_close (hw_device_t *device) {DBG ("" ); + +hal_audio_ipc_cleanup (); +free (device);return 0 ; }
@@ -391,6 +395,11 @@ static int audio_open(const hw_module_t *module, const char *name,return -EINVAL ; } +if (!hal_audio_ipc_init ()) { +error ("Unable to initialize audio IPC" ); +return -ENOTCONN ; + } + audio =calloc (1 ,sizeof (struct audio_hw_device ));if (!audio)return -ENOMEM ;
android/hal-ipc.c +56 -0
65 lines not on this page · raw message
android/hal-ipc.h +3 -0
@@ -30,3 +30,6 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,void hal_ipc_register (uint8_t service,const struct hal_ipc_handler *handlers,uint8_t size);void hal_ipc_unregister (uint8_t service); + +bool hal_audio_ipc_init (void ); +void hal_audio_ipc_cleanup (void );
Signature · 1 line
1.8.4.2
Re: [RFC BlueZ 9/9] android: Add hal_audio_ipc_init and hal_audio_ipc_cleanup
Hi Luiz,
Quoted 77 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
These function initialize the audio IPC in the HAL side.
--- android/hal-audio.c | 9 +++++++++ android/hal-ipc.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ android/hal-ipc.h | 3 +++ 3 files changed, 68 insertions(+)android/hal-audio.c +9
-0@@ -24,6 +24,7 @@#include <hardware/hardware.h> #include "hal-log.h" +#include "hal-ipc.h" static ssize_t out_write (struct audio_stream_out *stream,const void *buffer,size_t bytes)@@ -374,6 +375,9 @@ static int audio_dump(const audio_hw_device_t *device, int fd)static int audio_close (hw_device_t *device) {DBG ("" ); + +hal_audio_ipc_cleanup (); +free (device);return 0 ; }@@ -391,6 +395,11 @@ static int audio_open(const hw_module_t *module, const char *name,return -EINVAL ; } +if (!hal_audio_ipc_init ()) { +error ("Unable to initialize audio IPC" ); +return -ENOTCONN ; + } + audio =calloc (1 ,sizeof (struct audio_hw_device ));if (!audio)return -ENOMEM ;android/hal-ipc.c +19
-0@@ -38,6 +38,7 @@static int cmd_sk =-1 ;static int notif_sk =-1 ; +static int audio_sk =-1 ;static pthread_mutex_t cmd_sk_mutex =PTHREAD_MUTEX_INITIALIZER ;@@ -449,3 +450,58 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,return BT_STATUS_SUCCESS ; } + +bool hal_audio_ipc_init (void ) +{ +struct sockaddr_un addr; +int sk; +int err; + + sk =socket (AF_LOCAL ,SOCK_SEQPACKET ,0 ); +if (sk <0 ) { + err = errno; +error ("Failed to create socket: %d (%s)" , err, +strerror (err)); +return false; + } + +memset (&addr,0 ,sizeof (addr)); + addr.sun_family =AF_UNIX ; +
android/hal-ipc.c int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param, · line 480
Quoted 10 lines
android/hal-ipc.c +10
-0+memcpy (addr.sun_path,BLUEZ_AUDIO_SK_PATH ,sizeof (BLUEZ_AUDIO_SK_PATH )); + +if (bind (sk, (struct sockaddr *) &addr,sizeof (addr)) <0 ) { + err = errno; +error ("Failed to bind socket: %d (%s)" , err,strerror (err)); +close (sk); +return false; + } + +if (listen (sk,2 ) <0 ) {
Backlog = 1 should be enough here.
android/hal-ipc.c int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param, · line 488
Quoted 8 lines
android/hal-ipc.c +8
-0+ err = errno; +error ("Failed to listen on socket: %d (%s)" , err, +strerror (err)); +close (sk); +return false; + } + + audio_sk =accept_connection (sk);
We can not block audio_open(), so as we discussed on IRC and as I proposed in my patches, we need to call hal_audio_ipc_init in thread.
Quoted 31 lines
android/hal-ipc.c +19
-0+if (audio_sk <0 ) { +close (sk); +return false; + } + +info ("audio connected" ); + +close (sk); + +return true; +} + +void hal_audio_ipc_cleanup (void ) +{ +close (audio_sk); + audio_sk =-1 ; + +shutdown (audio_sk,SHUT_RD ); +}android/hal-ipc.h +3
-1@@ -30,3 +30,6 @@ int hal_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len, void *param,void hal_ipc_register (uint8_t service,const struct hal_ipc_handler *handlers,uint8_t size);void hal_ipc_unregister (uint8_t service); + +bool hal_audio_ipc_init (void ); +void hal_audio_ipc_cleanup (void ); --
Quoted 2 lines
1.8.4.2
\Lukasz
Quoted 4 lines
--
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
Hi Luiz,
Quoted 84 lines · On Monday 30 December 2013 14:34:07 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.
--- android/hal-msg.h | 1 + android/ipc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ android/ipc.h | 3 +++ 3 files changed, 51 insertions(+), 6 deletions(-)android/hal-msg.h +1
-0@@ -24,6 +24,7 @@#define BLUEZ_HAL_MTU 1024static 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@@ -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 *connect_hal (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 =connect_hal (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 =connect_hal (BLUEZ_HAL_SK_PATH ,sizeof (BLUEZ_HAL_SK_PATH ), + cmd_connect_cb);if (!cmd_io)raise (SIGTERM );}
android/ipc.c +0
-0@@ -338,3 +342,40 @@ void ipc_unregister(uint8_t service) services[service].handler =NULL ;
android/ipc.c void ipc_unregister(uint8_t service) · line 352
Quoted 10 lines
android/ipc.c +8
-0services[service].size =0 ; } + +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, terminating" );
This message is misleading since we should raise(SIGTERM) to terminate.
But I wonder if we should really terminate on audio IPC failure... That is failing on IPC error is OK (since that is a bug in our code anyway), but on not being able to connect we could simply fail to register a2dp HAL. Same goes with socket being closed - in such case we could fail any request to a2dp HAL until connection is recovered.
Quoted 8 lines
android/ipc.c +8
-0+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, cmd_watch_cb,NULL ); +
android/ipc.c void ipc_unregister(uint8_t service) · line 370
Quoted 10 lines
android/ipc.c +10
-0+info ("Audio IPC: successfully connected" ); + +return FALSE; +} + +void audio_ipc_init (void ) +{ + audio_io =connect_hal (BLUEZ_AUDIO_SK_PATH ,sizeof (BLUEZ_AUDIO_SK_PATH ), + audio_connect_cb); +if (!cmd_io)
audio_io here?
Quoted 22 lines
android/ipc.c +11
-0+raise (SIGTERM ); +} + +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@@ -37,3 +37,6 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode,
uint16_tlen, voidipc_register(uint8_t service, const struct ipc_handler *handlers, uint8_t size);
voidipc_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]
Luiz Augusto von Dentz
maintainerHi Szymon,
Quoted 100 lines · Szymon Janc
Hi Luiz,
Quoted 84 lines · On Monday 30 December 2013 14:34:07 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.
--- android/hal-msg.h | 1 + android/ipc.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ android/ipc.h | 3 +++ 3 files changed, 51 insertions(+), 6 deletions(-)android/hal-msg.h +1
-0@@ -24,6 +24,7 @@#define BLUEZ_HAL_MTU 1024static 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@@ -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 *connect_hal (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 =connect_hal (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 =connect_hal (BLUEZ_HAL_SK_PATH ,sizeof (BLUEZ_HAL_SK_PATH ), + cmd_connect_cb);if (!cmd_io)raise (SIGTERM );}
android/ipc.c +0
-0@@ -338,3 +342,40 @@ void ipc_unregister(uint8_t service) services[service].handler =NULL ;android/ipc.c void ipc_unregister(uint8_t service) · line 352
Quoted 10 lines
android/ipc.c +8
-0services[service].size =0 ; } + +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, terminating" );This message is misleading since we should raise(SIGTERM) to terminate.
Quoted 5 lines
But I wonder if we should really terminate on audio IPC failure... That is failing on IPC error is OK (since that is a bug in our code anyway), but on not being able to connect we could simply fail to register a2dp HAL. Same goes with socket being closed - in such case we could fail any request to a2dp HAL until connection is recovered.
Yep, the terminating part of the message is misleading it should not really exit just fail to initialize a2dp.
Quoted 12 lines
Quoted 12 lines
android/ipc.c +12
-0+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, cmd_watch_cb,NULL ); + +info ("Audio IPC: successfully connected" ); + +return FALSE; +}
Quoted 8 lines
android/ipc.c void ipc_unregister(uint8_t service) · line 370
Quoted 6 lines
android/ipc.c +6
-0+ +void audio_ipc_init (void ) +{ + audio_io =connect_hal (BLUEZ_AUDIO_SK_PATH ,sizeof (BLUEZ_AUDIO_SK_PATH ), + audio_connect_cb); +if (!cmd_io)
audio_iohere?
Yep, that is a bug.
Signature · 1 line
Luiz Augusto von Dentz