android: Initialize IPC with command and notification sockets
PATCH 1/10 android: Initialize IPC with command and notification sockets
Pass sockets after succesfully connected to HAL. This will allow to improve IPC helpers API.
--- android/ipc.c | 15 +++++++++++++++ android/ipc.h | 3 +++ android/main.c | 5 +++++ 3 files changed, 23 insertions(+)
android/ipc.c +15 -0
@@ -36,6 +36,21 @@#include "ipc.h" #include "log.h" +static int cmd_sk =-1 ; +static int notif_sk =-1 ; + +void ipc_init (int command_sk,int notification_sk) +{ + cmd_sk = command_sk; + notif_sk = notification_sk; +} + +void ipc_cleanup (void ) +{ + cmd_sk =-1 ; + notif_sk =-1 ; +} +void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd) {
android/ipc.h +3 -0
@@ -21,6 +21,9 @@* */ +void ipc_init (int command_sk,int notification_sk); +void ipc_cleanup (void ); +void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd);void ipc_send_rsp (int sk,uint8_t service_id,uint8_t opcode,uint8_t status);
android/main.c +5 -0
@@ -354,6 +354,9 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,g_io_add_watch (hal_cmd_io, cond, cmd_watch_cb,NULL ); +ipc_init (g_io_channel_unix_get_fd (hal_cmd_io), +g_io_channel_unix_get_fd (hal_notif_io)); +info ("Successfully connected to HAL" );return FALSE;
@@ -494,6 +497,8 @@ static void cleanup_hal_connection(void)g_io_channel_unref (hal_notif_io); hal_notif_io =NULL ; } + +ipc_cleanup (); }static bool set_capabilities (void )
Signature · 1 line
1.8.3.2
PATCH 2/10 android: Remove socket parameter from ipc_send_rsp
Use command socket provided to IPC on init.
--- android/a2dp.c | 2 +- android/bluetooth.c | 2 +- android/hidhost.c | 2 +- android/ipc.c | 6 +++--- android/ipc.h | 2 +- android/main.c | 17 ++++++----------- android/pan.c | 2 +- android/socket.c | 2 +- 8 files changed, 15 insertions(+), 20 deletions(-)
android/a2dp.c +1 -1
@@ -251,7 +251,7 @@ void bt_a2dp_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)break ; } -ipc_send_rsp (sk,HAL_SERVICE_ID_A2DP , opcode, status); +ipc_send_rsp (HAL_SERVICE_ID_A2DP , opcode, status); }static void connect_cb (GIOChannel *chan,GError *err,gpointer user_data)
android/bluetooth.c +1 -1
@@ -2269,7 +2269,7 @@ void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len) error:error ("Error handling command 0x%02x status %u" , opcode, status); -ipc_send_rsp (sk,HAL_SERVICE_ID_BLUETOOTH , opcode, status); +ipc_send_rsp (HAL_SERVICE_ID_BLUETOOTH , opcode, status); }bool bt_bluetooth_register (int sk)
android/hidhost.c +1 -1
@@ -1115,7 +1115,7 @@ void bt_hid_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)break ; } -ipc_send_rsp (sk,HAL_SERVICE_ID_HIDHOST , opcode, status); +ipc_send_rsp (HAL_SERVICE_ID_HIDHOST , opcode, status); }static void connect_cb (GIOChannel *chan,GError *err,gpointer user_data)
android/ipc.c +3 -3
@@ -96,16 +96,16 @@ void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len, } } -void ipc_send_rsp (int sk,uint8_t service_id,uint8_t opcode,uint8_t status) +void ipc_send_rsp (uint8_t service_id,uint8_t opcode,uint8_t status) {struct hal_status s;if (status ==HAL_STATUS_SUCCESS ) { -ipc_send (sk, service_id, opcode,0 ,NULL ,-1 ); +ipc_send (cmd_sk, service_id, opcode,0 ,NULL ,-1 );return ; } s.code = status; -ipc_send (sk, service_id,HAL_OP_STATUS ,sizeof (s), &s,-1 ); +ipc_send (cmd_sk, service_id,HAL_OP_STATUS ,sizeof (s), &s,-1 ); }
android/ipc.h +1 -1
@@ -26,4 +26,4 @@ void ipc_cleanup(void);void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd); -void ipc_send_rsp (int sk,uint8_t service_id,uint8_t opcode,uint8_t status); +void ipc_send_rsp (uint8_t service_id,uint8_t opcode,uint8_t status);
android/main.c +6 -11
@@ -121,9 +121,8 @@ static void service_register(void *buf, uint16_t len)info ("Service ID=%u registered" , m->service_id);return ; failed: -ipc_send_rsp (g_io_channel_unix_get_fd (hal_cmd_io), -HAL_SERVICE_ID_CORE ,HAL_OP_REGISTER_MODULE , -HAL_STATUS_FAILED ); +ipc_send_rsp (HAL_SERVICE_ID_CORE ,HAL_OP_REGISTER_MODULE , +HAL_STATUS_FAILED ); }static void service_unregister (void *buf,uint16_t len)
@@ -164,9 +163,8 @@ static void service_unregister(void *buf, uint16_t len)info ("Service ID=%u unregistered" , m->service_id);return ; failed: -ipc_send_rsp (g_io_channel_unix_get_fd (hal_cmd_io), -HAL_SERVICE_ID_CORE ,HAL_OP_UNREGISTER_MODULE , -HAL_STATUS_FAILED ); +ipc_send_rsp (HAL_SERVICE_ID_CORE ,HAL_OP_UNREGISTER_MODULE , +HAL_STATUS_FAILED ); }static void handle_service_core (uint8_t opcode,void *buf,uint16_t len)
@@ -179,9 +177,7 @@ static void handle_service_core(uint8_t opcode, void *buf, uint16_t len)service_unregister (buf, len);break ;default : -ipc_send_rsp (g_io_channel_unix_get_fd (hal_cmd_io), -HAL_SERVICE_ID_CORE , opcode, -HAL_STATUS_FAILED ); +ipc_send_rsp (HAL_SERVICE_ID_CORE , opcode,HAL_STATUS_FAILED );break ; } }
@@ -277,8 +273,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,bt_pan_handle_cmd (fd, msg->opcode, msg->payload, msg->len);break ;default : -ipc_send_rsp (fd, msg->service_id, msg->opcode, -HAL_STATUS_FAILED ); +ipc_send_rsp (msg->service_id, msg->opcode,HAL_STATUS_FAILED );break ; }
android/pan.c +1 -1
@@ -88,7 +88,7 @@ void bt_pan_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)break ; } -ipc_send_rsp (sk,HAL_SERVICE_ID_PAN , opcode, status); +ipc_send_rsp (HAL_SERVICE_ID_PAN , opcode, status); }bool bt_pan_register (int sk,const bdaddr_t *addr)
android/socket.c +1 -1
@@ -931,7 +931,7 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)break ; } -ipc_send_rsp (sk,HAL_SERVICE_ID_SOCK , opcode,HAL_STATUS_FAILED ); +ipc_send_rsp (HAL_SERVICE_ID_SOCK , opcode,HAL_STATUS_FAILED ); }bool bt_socket_register (int sk,const bdaddr_t *addr)
Signature · 1 line
1.8.3.2
PATCH 3/10 android: Use ipc_send_rsp helper for replying success
In reply to Szymon JancWhere applicable use helper as this make code easier to understand.
--- android/bluetooth.c | 2 +- android/main.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
android/bluetooth.c +1 -1
@@ -2263,7 +2263,7 @@ void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len) goto error; } -ipc_send (sk,HAL_SERVICE_ID_BLUETOOTH , opcode,0 ,NULL ,-1 ); +ipc_send_rsp (HAL_SERVICE_ID_BLUETOOTH , opcode,HAL_STATUS_SUCCESS );return ; error:
android/main.c +4 -4
@@ -115,8 +115,8 @@ static void service_register(void *buf, uint16_t len) services[m->service_id] = true; -ipc_send (g_io_channel_unix_get_fd (hal_cmd_io),HAL_SERVICE_ID_CORE , -HAL_OP_REGISTER_MODULE ,0 ,NULL ,-1 ); +ipc_send_rsp (HAL_SERVICE_ID_CORE ,HAL_OP_REGISTER_MODULE , +HAL_STATUS_SUCCESS );info ("Service ID=%u registered" , m->service_id);return ;
@@ -157,8 +157,8 @@ static void service_unregister(void *buf, uint16_t len) services[m->service_id] = false; -ipc_send (g_io_channel_unix_get_fd (hal_cmd_io),HAL_SERVICE_ID_CORE , -HAL_OP_UNREGISTER_MODULE ,0 ,NULL ,-1 ); +ipc_send_rsp (HAL_SERVICE_ID_CORE ,HAL_OP_UNREGISTER_MODULE , +HAL_STATUS_SUCCESS );info ("Service ID=%u unregistered" , m->service_id);return ;
Signature · 1 line
1.8.3.2
PATCH 4/10 android: Add IPC helper for sending notifications
In reply to Szymon JancThis will use notification socket passed on IPC init.
--- android/ipc.c | 9 +++++++++ android/ipc.h | 2 ++ 2 files changed, 11 insertions(+)
android/ipc.c +9 -0
@@ -109,3 +109,12 @@ void ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)ipc_send (cmd_sk, service_id,HAL_OP_STATUS ,sizeof (s), &s,-1 ); } + +void ipc_send_notif (uint8_t service_id,uint8_t opcode,uint16_t len, +void *param) +{ +if (notif_sk <0 ) +return ; + +ipc_send (notif_sk, service_id, opcode, len, param,-1 ); +}
android/ipc.h +2 -0
@@ -27,3 +27,5 @@ void ipc_cleanup(void);void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd);void ipc_send_rsp (uint8_t service_id,uint8_t opcode,uint8_t status); +void ipc_send_notif (uint8_t service_id,uint8_t opcode,uint16_t len, +void *param);
Signature · 1 line
1.8.3.2
PATCH 5/10 android: Use ipc_send_notif for sending notifications
In reply to Szymon Janc--- android/a2dp.c | 4 ++-- android/bluetooth.c | 63 ++++++++++++++++++++++++++--------------------------- android/hidhost.c | 20 ++++++++--------- 3 files changed, 43 insertions(+), 44 deletions(-)
android/a2dp.c +2 -2
@@ -112,8 +112,8 @@ static void bt_a2dp_notify_state(struct a2dp_device *dev, uint8_t state)bdaddr2android (&dev->dst, ev.bdaddr); ev.state = state; -ipc_send (notification_sk,HAL_SERVICE_ID_A2DP , -HAL_EV_A2DP_CONN_STATE ,sizeof (ev), &ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_A2DP ,HAL_EV_A2DP_CONN_STATE ,sizeof (ev), + &ev);if (state !=HAL_A2DP_STATE_DISCONNECTED )return ;
android/bluetooth.c +31 -32
159 lines not on this page · raw message
android/hidhost.c +10 -10
@@ -297,8 +297,8 @@ static void bt_hid_notify_state(struct hid_device *dev, uint8_t state)bdaddr2android (&dev->dst, ev.bdaddr); ev.state = state; -ipc_send (notification_sk,HAL_SERVICE_ID_HIDHOST , -HAL_EV_HIDHOST_CONN_STATE ,sizeof (ev), &ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_CONN_STATE , +sizeof (ev), &ev); } static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
@@ -356,8 +356,8 @@ static void bt_hid_notify_proto_mode(struct hid_device *dev, uint8_t *buf, ev.mode =HAL_HIDHOST_UNSUPPORTED_PROTOCOL ; } -ipc_send (notification_sk,HAL_SERVICE_ID_HIDHOST , -HAL_EV_HIDHOST_PROTO_MODE ,sizeof (ev), &ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_PROTO_MODE , +sizeof (ev), &ev); } static void bt_hid_notify_get_report(struct hid_device *dev, uint8_t *buf,
@@ -399,8 +399,8 @@ static void bt_hid_notify_get_report(struct hid_device *dev, uint8_t *buf, } send: -ipc_send (notification_sk,HAL_SERVICE_ID_HIDHOST , -HAL_EV_HIDHOST_GET_REPORT , ev_len, ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_GET_REPORT , + ev_len, ev);g_free (ev); }
@@ -424,8 +424,8 @@ static void bt_hid_notify_virtual_unplug(struct hid_device *dev, ev.status =HAL_HIDHOST_STATUS_OK ; } -ipc_send (notification_sk,HAL_SERVICE_ID_HIDHOST , -HAL_EV_HIDHOST_VIRTUAL_UNPLUG ,sizeof (ev), &ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_VIRTUAL_UNPLUG , +sizeof (ev), &ev); }
@@ -509,8 +509,8 @@ static void bt_hid_set_info(struct hid_device *dev)memset (ev.descr,0 ,sizeof (ev.descr));memcpy (ev.descr, dev->rd_data, ev.descr_len); -ipc_send (notification_sk,HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_INFO , -sizeof (ev), &ev,-1 ); +ipc_send_notif (HAL_SERVICE_ID_HIDHOST ,HAL_EV_HIDHOST_INFO ,sizeof (ev), + &ev); }static int uhid_create (struct hid_device *dev)
Signature · 1 line
1.8.3.2
PATCH 6/10 android: Add ipc_send_rsp_full IPC helper
In reply to Szymon JancThis will be used to send non-empty reply using command socket.
--- android/ipc.c | 6 ++++++ android/ipc.h | 2 ++ 2 files changed, 8 insertions(+)
android/ipc.c +6 -0
@@ -110,6 +110,12 @@ void ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)ipc_send (cmd_sk, service_id,HAL_OP_STATUS ,sizeof (s), &s,-1 ); } +void ipc_send_rsp_full (uint8_t service_id,uint8_t opcode,uint16_t len, +void *param,int fd) +{ +ipc_send (cmd_sk, service_id, opcode, len, param, fd); +} +void ipc_send_notif (uint8_t service_id,uint8_t opcode,uint16_t len,void *param) {
android/ipc.h +2 -0
@@ -27,5 +27,7 @@ void ipc_cleanup(void);void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd);void ipc_send_rsp (uint8_t service_id,uint8_t opcode,uint8_t status); +void ipc_send_rsp_full (uint8_t service_id,uint8_t opcode,uint16_t len, +void *param,int fd);void ipc_send_notif (uint8_t service_id,uint8_t opcode,uint16_t len,void *param);
Signature · 1 line
1.8.3.2
PATCH 7/10 android/socket: Use ipc_send_rsp_full IPC helper
In reply to Szymon JancUse command reply helper for sending reply with file descriptor.
--- android/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
android/socket.c +2 -2
@@ -909,7 +909,7 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)if (fd <0 )break ; -ipc_send (sk,HAL_SERVICE_ID_SOCK , opcode,0 ,NULL , fd); +ipc_send_rsp_full (HAL_SERVICE_ID_SOCK , opcode,0 ,NULL , fd);if (close (fd) <0 )error ("close() fd %d failed: %s" , fd,strerror (errno));
@@ -920,7 +920,7 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)if (fd <0 )break ; -ipc_send (sk,HAL_SERVICE_ID_SOCK , opcode,0 ,NULL , fd); +ipc_send_rsp_full (HAL_SERVICE_ID_SOCK , opcode,0 ,NULL , fd);if (close (fd) <0 )error ("close() fd %d failed: %s" , fd,strerror (errno));
Signature · 1 line
1.8.3.2
PATCH 8/10 android: Make ipc_send static
In reply to Szymon JancIt should not longer be used from outside of IPC code.
--- android/ipc.c | 2 +- android/ipc.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
android/ipc.c +1 -1
@@ -51,7 +51,7 @@ void ipc_cleanup(void) notif_sk =-1 ; } -void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len, +static void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd) {struct msghdr msg;
android/ipc.h +0 -2
@@ -24,8 +24,6 @@void ipc_init (int command_sk,int notification_sk);void ipc_cleanup (void ); -void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len, -void *param,int fd);void ipc_send_rsp (uint8_t service_id,uint8_t opcode,uint8_t status);void ipc_send_rsp_full (uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd);
Signature · 1 line
1.8.3.2
PATCH 9/10 android/bluetooth: Remove not needed notification_sk checks
In reply to Szymon JancThis is now checked inside ipc_send_notif helper.
--- android/bluetooth.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
android/bluetooth.c +2 -6
@@ -1185,9 +1185,7 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,mgmt_dev_class_changed_event (adapter.index, length, param,NULL ); -/* send notification only if bluetooth service is registered */ -if (notification_sk >=0 ) -get_uuids (); +get_uuids (); }static void remove_uuid (uint16_t uuid)
@@ -1213,9 +1211,7 @@ static void add_uuid_complete(uint8_t status, uint16_t length,mgmt_dev_class_changed_event (adapter.index, length, param,NULL ); -/* send notification only if bluetooth service is registered */ -if (notification_sk >=0 ) -get_uuids (); +get_uuids (); }static void add_uuid (uint8_t svc_hint,uint16_t uuid)
Signature · 1 line
1.8.3.2
PATCH 10/10 android: Don't pass notification socket on services register
In reply to Szymon JancIt is no longer needed as proper socket is use by IPC helpers.
--- android/a2dp.c | 13 +------------ android/a2dp.h | 2 +- android/bluetooth.c | 16 +--------------- android/bluetooth.h | 2 +- android/hidhost.c | 12 +----------- android/hidhost.h | 2 +- android/main.c | 13 +++++-------- android/pan.c | 14 +------------- android/pan.h | 2 +- android/socket.c | 4 +--- android/socket.h | 2 +- 11 files changed, 15 insertions(+), 67 deletions(-)
android/a2dp.c +1 -12
@@ -48,7 +48,6 @@#define L2CAP_PSM_AVDTP 0x19#define SVC_HINT_CAPTURING 0x08 -static int notification_sk =-1 ;static GIOChannel *server =NULL ;static GSList *devices =NULL ;static bdaddr_t adapter_addr;
@@ -350,16 +349,13 @@ static sdp_record_t *a2dp_record(void)return record; } -bool bt_a2dp_register (int sk,const bdaddr_t *addr) +bool bt_a2dp_register (const bdaddr_t *addr) {GError *err =NULL ;sdp_record_t *rec;DBG ("" ); -if (notification_sk >=0 ) -return false; -bacpy (&adapter_addr, addr); server = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
@@ -384,8 +380,6 @@ bool bt_a2dp_register(int sk, const bdaddr_t *addr) } record_id = rec->handle; - notification_sk = sk; -return true; }
@@ -400,14 +394,9 @@ void bt_a2dp_unregister(void) {DBG ("" ); -if (notification_sk <0 ) -return ; -g_slist_foreach (devices, a2dp_device_disconnected,NULL ); devices =NULL ; - notification_sk =-1 ; -bt_adapter_remove_record (record_id); record_id =0 ;
android/a2dp.h +1 -1
@@ -23,5 +23,5 @@void bt_a2dp_handle_cmd (int sk,uint8_t opcode,void *buf,uint16_t len); -bool bt_a2dp_register (int sk,const bdaddr_t *addr); +bool bt_a2dp_register (const bdaddr_t *addr);void bt_a2dp_unregister (void );
android/bluetooth.c +1 -15
@@ -60,8 +60,6 @@static uint16_t option_index =MGMT_INDEX_NONE ; -static int notification_sk =-1 ; -#define BASELEN_REMOTE_DEV_PROP (sizeof(struct hal_ev_remote_device_props) \ + sizeof(struct hal_property))/* This list contains addresses which are asked for records */
@@ -2267,24 +2265,12 @@ error:ipc_send_rsp (HAL_SERVICE_ID_BLUETOOTH , opcode, status); } -bool bt_bluetooth_register (int sk) +void bt_bluetooth_register (void ) {DBG ("" ); - -if (notification_sk >=0 ) -return false; - - notification_sk = sk; - -return true; }void bt_bluetooth_unregister (void ) {DBG ("" ); - -if (notification_sk <0 ) -return ; - - notification_sk =-1 ; }
android/bluetooth.h +1 -1
@@ -31,7 +31,7 @@ void bt_bluetooth_cleanup(void);void bt_bluetooth_handle_cmd (int sk,uint8_t opcode,void *buf,uint16_t len); -bool bt_bluetooth_register (int sk); +void bt_bluetooth_register (void );void bt_bluetooth_unregister (void );int bt_adapter_add_record (sdp_record_t *rec,uint8_t svc_hint);
android/hidhost.c +1 -11
@@ -78,7 +78,6 @@static bdaddr_t adapter_addr; -static int notification_sk =-1 ;static GIOChannel *ctrl_io =NULL ;static GIOChannel *intr_io =NULL ;static GSList *devices =NULL ;
@@ -1190,15 +1189,12 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data) } } -bool bt_hid_register (int sk,const bdaddr_t *addr) +bool bt_hid_register (const bdaddr_t *addr) {GError *err =NULL ;DBG ("" ); -if (notification_sk >=0 ) -return false; -bacpy (&adapter_addr, addr); ctrl_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
@@ -1224,8 +1220,6 @@ bool bt_hid_register(int sk, const bdaddr_t *addr)return false; } - notification_sk = sk; -return true; }
@@ -1241,12 +1235,8 @@ void bt_hid_unregister(void) {DBG ("" ); -if (notification_sk <0 ) -return ; -g_slist_foreach (devices, free_hid_devices,NULL ); devices =NULL ; - notification_sk =-1 ;if (ctrl_io) {g_io_channel_shutdown (ctrl_io, TRUE,NULL );
android/hidhost.h +1 -1
@@ -23,5 +23,5 @@void bt_hid_handle_cmd (int sk,uint8_t opcode,void *buf,uint16_t len); -bool bt_hid_register (int sk,const bdaddr_t *addr); +bool bt_hid_register (const bdaddr_t *addr);void bt_hid_unregister (void );
android/main.c +5 -8
@@ -77,34 +77,31 @@ static bool services[HAL_SERVICE_ID_MAX + 1] = { false };static void service_register (void *buf,uint16_t len) {struct hal_cmd_register_module *m = buf; -int sk =g_io_channel_unix_get_fd (hal_notif_io);if (m->service_id >HAL_SERVICE_ID_MAX || services[m->service_id]) goto failed;switch (m->service_id) {case HAL_SERVICE_ID_BLUETOOTH : -if (!bt_bluetooth_register (sk)) - goto failed; +bt_bluetooth_register ();break ;case HAL_SERVICE_ID_SOCK : -if (!bt_socket_register (sk, &adapter_bdaddr)) - goto failed; +bt_socket_register (&adapter_bdaddr);break ;case HAL_SERVICE_ID_HIDHOST : -if (!bt_hid_register (sk, &adapter_bdaddr)) +if (!bt_hid_register (&adapter_bdaddr)) goto failed;break ;case HAL_SERVICE_ID_A2DP : -if (!bt_a2dp_register (sk, &adapter_bdaddr)) +if (!bt_a2dp_register (&adapter_bdaddr)) goto failed;break ;case HAL_SERVICE_ID_PAN : -if (!bt_pan_register (sk, &adapter_bdaddr)) +if (!bt_pan_register (&adapter_bdaddr)) goto failed;break ;
android/pan.c +1 -13
@@ -35,8 +35,6 @@#include "hal-msg.h" #include "ipc.h" -static int notification_sk =-1 ; -static uint8_t bt_pan_enable (struct hal_cmd_pan_enable *cmd,uint16_t len) {DBG ("Not Implemented" );
@@ -91,24 +89,14 @@ void bt_pan_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)ipc_send_rsp (HAL_SERVICE_ID_PAN , opcode, status); } -bool bt_pan_register (int sk,const bdaddr_t *addr) +bool bt_pan_register (const bdaddr_t *addr) {DBG ("" ); -if (notification_sk >=0 ) -return false; - - notification_sk = sk; -return true; }void bt_pan_unregister (void ) {DBG ("" ); - -if (notification_sk <0 ) -return ; - - notification_sk =-1 ; }
android/pan.h +1 -1
@@ -23,5 +23,5 @@void bt_pan_handle_cmd (int sk,uint8_t opcode,void *buf,uint16_t len); -bool bt_pan_register (int sk,const bdaddr_t *addr); +bool bt_pan_register (const bdaddr_t *addr);void bt_pan_unregister (void );
android/socket.c +1 -3
@@ -934,13 +934,11 @@ void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)ipc_send_rsp (HAL_SERVICE_ID_SOCK , opcode,HAL_STATUS_FAILED ); } -bool bt_socket_register (int sk,const bdaddr_t *addr) +void bt_socket_register (const bdaddr_t *addr) {DBG ("" );bacpy (&adapter_addr, addr); - -return true; }void bt_socket_unregister (void )
android/socket.h +1 -1
@@ -30,5 +30,5 @@ struct hal_sock_connect_signal {void bt_sock_handle_cmd (int sk,uint8_t opcode,void *buf,uint16_t len); -bool bt_socket_register (int sk,const bdaddr_t *addr); +void bt_socket_register (const bdaddr_t *addr);void bt_socket_unregister (void );
Signature · 1 line
1.8.3.2
Hi Szymon,
Quoted 72 lines · Szymon Janc
Pass sockets after succesfully connected to HAL. This will allow to improve IPC helpers API.
--- android/ipc.c | 15 +++++++++++++++ android/ipc.h | 3 +++ android/main.c | 5 +++++ 3 files changed, 23 insertions(+)android/ipc.c +15
-0@@ -36,6 +36,21 @@#include "ipc.h" #include "log.h" +static int cmd_sk =-1 ; +static int notif_sk =-1 ; + +void ipc_init (int command_sk,int notification_sk) +{ + cmd_sk = command_sk; + notif_sk = notification_sk; +} + +void ipc_cleanup (void ) +{ + cmd_sk =-1 ; + notif_sk =-1 ; +} +void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd) {android/ipc.h +3
-0@@ -21,6 +21,9 @@* */ +void ipc_init (int command_sk,int notification_sk); +void ipc_cleanup (void ); +void ipc_send (int sk,uint8_t service_id,uint8_t opcode,uint16_t len,void *param,int fd);void ipc_send_rsp (int sk,uint8_t service_id,uint8_t opcode,uint8_t status);android/main.c +5
-1@@ -354,6 +354,9 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,g_io_add_watch (hal_cmd_io, cond, cmd_watch_cb,NULL ); +ipc_init (g_io_channel_unix_get_fd (hal_cmd_io), +g_io_channel_unix_get_fd (hal_notif_io)); +info ("Successfully connected to HAL" );return FALSE;@@ -494,6 +497,8 @@ static void cleanup_hal_connection(void)g_io_channel_unref (hal_notif_io); hal_notif_io =NULL ; } + +ipc_cleanup (); }static bool set_capabilities (void ) --
Quoted 1 line
1.8.3.2
Applied, thanks.
Signature · 1 line
Luiz Augusto von Dentz